+static int allocate_data_structures(
+ rrd_t *rrd, char ***updvals, rrd_value_t **pdp_temp, const char *tmplt,
+ long **tmpl_idx, unsigned long *tmpl_cnt, unsigned long **rra_step_cnt,
+ unsigned long **skip_update, rrd_value_t **pdp_new);
+
+static int parse_template(rrd_t *rrd, const char *tmplt,
+ unsigned long *tmpl_cnt, long *tmpl_idx);
+
+static int process_arg(
+ char *step_start,
+ rrd_t *rrd,
+ rrd_file_t *rrd_file,
+ unsigned long rra_begin,
+ unsigned long *rra_current,
+ time_t *current_time,
+ unsigned long *current_time_usec,
+ rrd_value_t *pdp_temp,
+ rrd_value_t *pdp_new,
+ unsigned long *rra_step_cnt,
+ char **updvals,
+ long *tmpl_idx,
+ unsigned long tmpl_cnt,
+ info_t **pcdp_summary,
+ int version,
+ unsigned long *skip_update,
+ int *schedule_smooth);
+
+static int parse_ds(rrd_t *rrd, char **updvals, long *tmpl_idx, char *input,
+ unsigned long tmpl_cnt, time_t *current_time, unsigned long *current_time_usec,
+ int version);
+
+static int get_time_from_reading(rrd_t *rrd, char timesyntax, char **updvals,
+ time_t *current_time, unsigned long *current_time_usec, int version);
+
+static int update_pdp_prep(rrd_t *rrd, char **updvals,
+ rrd_value_t *pdp_new, double interval);
+
+static int calculate_elapsed_steps(rrd_t *rrd,
+ unsigned long current_time, unsigned long current_time_usec,
+ double interval, double *pre_int, double *post_int,
+ unsigned long *proc_pdp_cnt);
+
+static void simple_update(rrd_t *rrd, double interval, rrd_value_t *pdp_new);
+
+static int process_all_pdp_st(rrd_t *rrd, double interval,
+ double pre_int, double post_int, unsigned long elapsed_pdp_st,
+ rrd_value_t *pdp_new, rrd_value_t *pdp_temp);
+
+static int process_pdp_st(rrd_t *rrd, unsigned long ds_idx, double interval,
+ double pre_int, double post_int, long diff_pdp_st, rrd_value_t *pdp_new,
+ rrd_value_t *pdp_temp);
+
+static int update_all_cdp_prep(
+ rrd_t *rrd, unsigned long *rra_step_cnt, unsigned long rra_begin,
+ rrd_file_t *rrd_file, unsigned long elapsed_pdp_st, unsigned long proc_pdp_cnt,
+ rrd_value_t **last_seasonal_coef, rrd_value_t **seasonal_coef,
+ rrd_value_t *pdp_temp, unsigned long *rra_current,
+ unsigned long *skip_update, int *schedule_smooth);
+
+static int do_schedule_smooth(rrd_t *rrd, unsigned long rra_idx,
+ unsigned long elapsed_pdp_st);
+
+static int update_cdp_prep(rrd_t *rrd, unsigned long elapsed_pdp_st,
+ unsigned long start_pdp_offset, unsigned long *rra_step_cnt,
+ int rra_idx, rrd_value_t *pdp_temp, rrd_value_t *last_seasonal_coef,
+ rrd_value_t *seasonal_coef, int current_cf);
+
+static void update_cdp(unival *scratch, int current_cf,
+ rrd_value_t pdp_temp_val, unsigned long rra_step_cnt,
+ unsigned long elapsed_pdp_st, unsigned long start_pdp_offset,
+ unsigned long pdp_cnt, rrd_value_t xff, int i, int ii);
+
+static void initialize_cdp_val(unival *scratch, int current_cf,
+ rrd_value_t pdp_temp_val, unsigned long elapsed_pdp_st,
+ unsigned long start_pdp_offset, unsigned long pdp_cnt);
+
+static void reset_cdp(rrd_t *rrd, unsigned long elapsed_pdp_st,
+ rrd_value_t *pdp_temp, rrd_value_t *last_seasonal_coef,
+ rrd_value_t *seasonal_coef,
+ int rra_idx, int ds_idx, int cdp_idx, enum cf_en current_cf);
+
+static rrd_value_t initialize_average_carry_over(rrd_value_t pdp_temp_val,
+ unsigned long elapsed_pdp_st, unsigned long start_pdp_offset,
+ unsigned long pdp_cnt);
+
+static rrd_value_t calculate_cdp_val(
+ rrd_value_t cdp_val, rrd_value_t pdp_temp_val,
+ unsigned long elapsed_pdp_st, int current_cf, int i, int ii);
+
+static int update_aberrant_cdps(rrd_t *rrd, rrd_file_t *rrd_file,
+ unsigned long rra_begin, unsigned long *rra_current,
+ unsigned long elapsed_pdp_st, rrd_value_t *pdp_temp, rrd_value_t **seasonal_coef);
+
+static int write_to_rras(rrd_t *rrd, rrd_file_t *rrd_file,
+ unsigned long *rra_step_cnt, unsigned long rra_begin,
+ unsigned long *rra_current, time_t current_time,
+ unsigned long *skip_update, info_t **pcdp_summary);
+
+static int write_RRA_row(rrd_file_t *rrd_file, rrd_t *rrd, unsigned long rra_idx,
+ unsigned long *rra_current, unsigned short CDP_scratch_idx, info_t **pcdp_summary,
+ time_t rra_time);
+
+static int smooth_all_rras(rrd_t *rrd, rrd_file_t *rrd_file,
+ unsigned long rra_begin);
+
+#ifndef HAVE_MMAP
+static int write_changes_to_disk(rrd_t *rrd, rrd_file_t *rrd_file,
+ int version);
+#endif
+
+/*
+ * normalize time as returned by gettimeofday. usec part must
+ * be always >= 0
+ */
+static inline void normalize_time(
+ struct timeval *t)
+{
+ if (t->tv_usec < 0) {
+ t->tv_sec--;
+ t->tv_usec += 1e6L;
+ }
+}
+
+/*
+ * Sets current_time and current_time_usec based on the current time.
+ * current_time_usec is set to 0 if the version number is 1 or 2.
+ */
+static inline void initialize_time(
+ time_t *current_time, unsigned long *current_time_usec,
+ int version)
+{
+ struct timeval tmp_time; /* used for time conversion */
+
+ gettimeofday(&tmp_time, 0);
+ normalize_time(&tmp_time);
+ *current_time = tmp_time.tv_sec;
+ if (version >= 3) {
+ *current_time_usec = tmp_time.tv_usec;
+ } else {
+ *current_time_usec = 0;
+ }
+}