2 * Copyright (C) 2008-2010 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
8 /** The possible states for snapshot creation/removal. */
9 #define HOOK_STATUS_ARRAY \
10 HSA_ITEM(HS_READY, "ready for action"), \
11 HSA_ITEM(HS_PRE_RUNNING, "pre-hook running"), \
12 HSA_ITEM(HS_PRE_SUCCESS, "pre-hook completed successfully"), \
13 HSA_ITEM(HS_RUNNING, "in progress"), \
14 HSA_ITEM(HS_SUCCESS, "process terminated successfully"), \
15 HSA_ITEM(HS_NEEDS_RESTART, "restart needed"), \
16 HSA_ITEM(HS_POST_RUNNING, "post-hook running")
19 #define HSA_ITEM(x, y) x
20 enum hook_status {HOOK_STATUS_ARRAY};
22 #define HSA_ITEM(x, y) y
26 * The status of a snapshot.
28 * The snapshot directories come in four different flavours, depending
29 * on how the two status flags are set. Examples:
31 * Complete, not being deleted: 1204565370-1204565371.Sun_Mar_02_2008_14_33-Sun_Mar_02_2008_14_43.
32 * Complete, being deleted: 1204565370-1204565371.being_deleted.
33 * Incomplete, not being deleted: 1204565370-incomplete.
34 * incomplete, being deleted: 1204565370-incomplete.being_deleted.
36 enum snapshot_status_flags {
37 /** The rsync process terminated successfully. */
39 /** The rm process is running to remove this snapshot. */
43 /** Describes one snapshot. */
45 /** The name of the directory, relative to the destination dir. */
47 /** Seconds after the epoch when this snapshot was created. */
48 int64_t creation_time;
50 * Seconds after the epoch when creation of this snapshot completed.
51 * Only meaningful if the SS_COMPLETE bit is set.
53 int64_t completion_time;
54 /** See \ref snapshot_status_flags. */
55 enum snapshot_status_flags flags;
56 /** The interval this snapshot belongs to. */
60 struct snapshot_list {
62 unsigned num_snapshots;
64 struct snapshot **snapshots;
66 * Array of size num_intervals + 1
68 * It contains the number of snapshots in each interval. interval_count[num_intervals]
69 * is the number of snapshots which belong to any interval greater than num_intervals.
71 unsigned *interval_count;
74 /** Iterate over all snapshots in a snapshot list. */
75 #define FOR_EACH_SNAPSHOT(s, i, sl) \
76 for ((i) = 0; (i) < (sl)->num_snapshots && ((s) = (sl)->snapshots[(i)]); (i)++)
78 /** Iterate backwards over all snapshots in a snapshot list. */
79 #define FOR_EACH_SNAPSHOT_REVERSE(s, i, sl) \
80 for ((i) = (sl)->num_snapshots; (i) > 0 && ((s) = (sl)->snapshots[(i - 1)]); (i)--)
83 unsigned desired_number_of_snapshots(int interval_num, int num_intervals);
84 void get_snapshot_list(struct snapshot_list *sl, int unit_interval,
86 void free_snapshot_list(struct snapshot_list *sl);
87 __malloc char *incomplete_name(int64_t start);
88 __malloc char *being_deleted_name(struct snapshot *s);
89 int complete_name(int64_t start, int64_t end, char **result);
90 __malloc char *name_of_newest_complete_snapshot(struct snapshot_list *sl);
93 * Get the newest snapshot in a snapshot list.
95 _static_inline_ struct snapshot *get_newest_snapshot(struct snapshot_list *sl)
97 if (!sl->num_snapshots)
99 return sl->snapshots[sl->num_snapshots - 1];