2 /** The state of snapshot creation. */
4 /** We are ready to take the next snapshot. */
6 /** The pre-creation hook has been started. */
8 /** The pre-creation hook exited successfully. */
10 /** The rsync process is running. */
12 /** The rsync process exited successfully. */
14 /** The post-create hook has been started. */
15 SCS_POST_HOOK_RUNNING,
19 * The status of a snapshot.
21 * The snapshot directories come in four different flavours, depending
22 * on how the two staus flags are set. Examples:
24 * Complete, not being deleted: 1204565370-1204565371.Sun_Mar_02_2008_14_33-Sun_Mar_02_2008_14_43.
25 * Complete, being deleted: 1204565370-1204565371.being_deleted.
26 * Incomplete, not being deleted: 1204565370-incomplete.
27 * incomplete, being deleted: 1204565370-incomplete.being_deleted.
29 enum snapshot_status_flags {
30 /** The rsync process terminated successfully. */
32 /** The rm process is running to remove this snapshot. */
36 /** Desribes one snapshot */
38 /** The name of the directory, relative to the destination dir. */
40 /** Seconds after the epoch when this snapshot was created. */
41 int64_t creation_time;
43 * Seconds after the epoch when creation of this snapshot completed.
44 * Only meaningful if the SS_COMPLTE bit is set.
46 int64_t completion_time;
47 /** See \ref snapshot_status_flags. */
48 enum snapshot_status_flags flags;
49 /** The interval this snapshot belongs to. */
53 struct snapshot_list {
55 unsigned num_snapshots;
57 struct snapshot **snapshots;
59 * Array of size num_intervals + 1
61 * It contains the number of snapshots in each interval. interval_count[num_intervals]
62 * is the number of snapshots which belong to any interval greater than num_intervals.
64 unsigned *interval_count;
67 /** Iterate over all snapshots in a snapshot list. */
68 #define FOR_EACH_SNAPSHOT(s, i, sl) \
69 for ((i) = 0; (i) < (sl)->num_snapshots && ((s) = (sl)->snapshots[(i)]); (i)++)
71 /** Iterate backwards over all snapshots in a snapshot list. */
72 #define FOR_EACH_SNAPSHOT_REVERSE(s, i, sl) \
73 for ((i) = (sl)->num_snapshots; (i) > 0 && ((s) = (sl)->snapshots[(i - 1)]); (i)--)
76 unsigned desired_number_of_snapshots(int interval_num, int num_intervals);
77 void get_snapshot_list(struct snapshot_list *sl, int unit_interval,
79 void free_snapshot_list(struct snapshot_list *sl);
80 __malloc char *incomplete_name(int64_t start);
81 __malloc char *being_deleted_name(struct snapshot *s);
82 int complete_name(int64_t start, int64_t end, char **result);
83 __malloc char *name_of_newest_complete_snapshot(struct snapshot_list *sl);
86 * Get the oldest snapshot in a snapshot list.
88 _static_inline_ struct snapshot *get_oldest_snapshot(struct snapshot_list *sl)
90 if (!sl->num_snapshots)
92 return sl->snapshots[0];