1 /* SPDX-License-Identifier: GPL-2.0 */
3 /** The possible states for snapshot creation/removal. */
4 #define HOOK_STATUS_ARRAY \
5 HSA_ITEM(HS_READY, "ready for action"), \
6 HSA_ITEM(HS_PRE_RUNNING, "pre-hook running"), \
7 HSA_ITEM(HS_PRE_SUCCESS, "pre-hook completed successfully"), \
8 HSA_ITEM(HS_RUNNING, "in progress"), \
9 HSA_ITEM(HS_SUCCESS, "process terminated successfully"), \
10 HSA_ITEM(HS_NEEDS_RESTART, "restart needed"), \
11 HSA_ITEM(HS_POST_RUNNING, "post-hook running")
14 #define HSA_ITEM(x, y) x
15 enum hook_status {HOOK_STATUS_ARRAY};
17 #define HSA_ITEM(x, y) y
21 * The status of a snapshot.
23 * The snapshot directories come in four different flavours, depending
24 * on how the two status flags are set. Examples:
26 * Complete, not being deleted: 1204565370-1204565371.Sun_Mar_02_2008_14_33-Sun_Mar_02_2008_14_43.
27 * Complete, being deleted: 1204565370-1204565371.being_deleted.
28 * Incomplete, not being deleted: 1204565370-incomplete.
29 * incomplete, being deleted: 1204565370-incomplete.being_deleted.
31 enum snapshot_status_flags {
32 /** The rsync process terminated successfully. */
34 /** The rm process is running to remove this snapshot. */
38 /** Describes one snapshot. */
40 /** The name of the directory, relative to the destination dir. */
42 /** Seconds after the epoch when this snapshot was created. */
43 int64_t creation_time;
45 * Seconds after the epoch when creation of this snapshot completed.
46 * Only meaningful if the SS_COMPLETE bit is set.
48 int64_t completion_time;
49 /** See \ref snapshot_status_flags. */
50 enum snapshot_status_flags flags;
51 /** The interval this snapshot belongs to. */
55 struct snapshot_list {
57 unsigned num_snapshots;
59 struct snapshot **snapshots;
61 * Array of size num_intervals + 1
63 * It contains the number of snapshots in each interval. interval_count[num_intervals]
64 * is the number of snapshots which belong to any interval greater than num_intervals.
66 unsigned *interval_count;
69 /** Iterate over all snapshots in a snapshot list. */
70 #define FOR_EACH_SNAPSHOT(s, i, sl) \
71 for ((i) = 0; (i) < (sl)->num_snapshots && ((s) = (sl)->snapshots[(i)]); (i)++)
73 /** Iterate backwards over all snapshots in a snapshot list. */
74 #define FOR_EACH_SNAPSHOT_REVERSE(s, i, sl) \
75 for ((i) = (sl)->num_snapshots; (i) > 0 && ((s) = (sl)->snapshots[(i - 1)]); (i)--)
78 unsigned desired_number_of_snapshots(int interval_num, int num_intervals);
79 void get_snapshot_list(struct snapshot_list *sl, int unit_interval,
81 void free_snapshot_list(struct snapshot_list *sl);
82 __malloc char *incomplete_name(int64_t start);
83 __malloc char *being_deleted_name(struct snapshot *s);
84 int complete_name(int64_t start, int64_t end, char **result);
85 __malloc char *name_of_newest_complete_snapshot(struct snapshot_list *sl);
86 int num_complete_snapshots(struct snapshot_list *sl);
89 * Get the newest snapshot in a snapshot list.
91 static inline struct snapshot *get_newest_snapshot(struct snapshot_list *sl)
93 if (!sl->num_snapshots)
95 return sl->snapshots[sl->num_snapshots - 1];