2 * Copyright (C) 2008 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** The state of snapshot creation. */
9 /** We are ready to take the next snapshot. */
11 /** The pre-creation hook has been started. */
13 /** The pre-creation hook exited successfully. */
15 /** The rsync process is running. */
17 /** The rsync process exited successfully. */
19 /** The rsync process needs to be restarted. */
20 SCS_RSYNC_NEEDS_RESTART,
21 /** The post-create hook has been started. */
22 SCS_POST_HOOK_RUNNING,
25 /** The state of snapshot removal. */
27 /** No snapshot is currently being removed. */
29 /** The pre-removal hook has been started. */
31 /** The pre-remove hook failed, we're waiting to execute it again. */
33 /** The rm command is currently executing. */
35 /** The post-remove hook ist running. */
36 SRS_POST_HOOK_RUNNING,
40 * The status of a snapshot.
42 * The snapshot directories come in four different flavours, depending
43 * on how the two staus flags are set. Examples:
45 * Complete, not being deleted: 1204565370-1204565371.Sun_Mar_02_2008_14_33-Sun_Mar_02_2008_14_43.
46 * Complete, being deleted: 1204565370-1204565371.being_deleted.
47 * Incomplete, not being deleted: 1204565370-incomplete.
48 * incomplete, being deleted: 1204565370-incomplete.being_deleted.
50 enum snapshot_status_flags {
51 /** The rsync process terminated successfully. */
53 /** The rm process is running to remove this snapshot. */
57 /** Describes one snapshot. */
59 /** The name of the directory, relative to the destination dir. */
61 /** Seconds after the epoch when this snapshot was created. */
62 int64_t creation_time;
64 * Seconds after the epoch when creation of this snapshot completed.
65 * Only meaningful if the SS_COMPLTE bit is set.
67 int64_t completion_time;
68 /** See \ref snapshot_status_flags. */
69 enum snapshot_status_flags flags;
70 /** The interval this snapshot belongs to. */
74 struct snapshot_list {
76 unsigned num_snapshots;
78 struct snapshot **snapshots;
80 * Array of size num_intervals + 1
82 * It contains the number of snapshots in each interval. interval_count[num_intervals]
83 * is the number of snapshots which belong to any interval greater than num_intervals.
85 unsigned *interval_count;
88 /** Iterate over all snapshots in a snapshot list. */
89 #define FOR_EACH_SNAPSHOT(s, i, sl) \
90 for ((i) = 0; (i) < (sl)->num_snapshots && ((s) = (sl)->snapshots[(i)]); (i)++)
92 /** Iterate backwards over all snapshots in a snapshot list. */
93 #define FOR_EACH_SNAPSHOT_REVERSE(s, i, sl) \
94 for ((i) = (sl)->num_snapshots; (i) > 0 && ((s) = (sl)->snapshots[(i - 1)]); (i)--)
97 unsigned desired_number_of_snapshots(int interval_num, int num_intervals);
98 void get_snapshot_list(struct snapshot_list *sl, int unit_interval,
100 void free_snapshot_list(struct snapshot_list *sl);
101 __malloc char *incomplete_name(int64_t start);
102 __malloc char *being_deleted_name(struct snapshot *s);
103 int complete_name(int64_t start, int64_t end, char **result);
104 __malloc char *name_of_newest_complete_snapshot(struct snapshot_list *sl);
107 * Get the oldest snapshot in a snapshot list.
109 _static_inline_ struct snapshot *get_oldest_snapshot(struct snapshot_list *sl)
111 if (!sl->num_snapshots)
113 return sl->snapshots[0];