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 post-create hook has been started. */
20 SCS_POST_HOOK_RUNNING,
24 * The status of a snapshot.
26 * The snapshot directories come in four different flavours, depending
27 * on how the two staus flags are set. Examples:
29 * Complete, not being deleted: 1204565370-1204565371.Sun_Mar_02_2008_14_33-Sun_Mar_02_2008_14_43.
30 * Complete, being deleted: 1204565370-1204565371.being_deleted.
31 * Incomplete, not being deleted: 1204565370-incomplete.
32 * incomplete, being deleted: 1204565370-incomplete.being_deleted.
34 enum snapshot_status_flags {
35 /** The rsync process terminated successfully. */
37 /** The rm process is running to remove this snapshot. */
41 /** Desribes one snapshot */
43 /** The name of the directory, relative to the destination dir. */
45 /** Seconds after the epoch when this snapshot was created. */
46 int64_t creation_time;
48 * Seconds after the epoch when creation of this snapshot completed.
49 * Only meaningful if the SS_COMPLTE bit is set.
51 int64_t completion_time;
52 /** See \ref snapshot_status_flags. */
53 enum snapshot_status_flags flags;
54 /** The interval this snapshot belongs to. */
58 struct snapshot_list {
60 unsigned num_snapshots;
62 struct snapshot **snapshots;
64 * Array of size num_intervals + 1
66 * It contains the number of snapshots in each interval. interval_count[num_intervals]
67 * is the number of snapshots which belong to any interval greater than num_intervals.
69 unsigned *interval_count;
72 /** Iterate over all snapshots in a snapshot list. */
73 #define FOR_EACH_SNAPSHOT(s, i, sl) \
74 for ((i) = 0; (i) < (sl)->num_snapshots && ((s) = (sl)->snapshots[(i)]); (i)++)
76 /** Iterate backwards over all snapshots in a snapshot list. */
77 #define FOR_EACH_SNAPSHOT_REVERSE(s, i, sl) \
78 for ((i) = (sl)->num_snapshots; (i) > 0 && ((s) = (sl)->snapshots[(i - 1)]); (i)--)
81 unsigned desired_number_of_snapshots(int interval_num, int num_intervals);
82 void get_snapshot_list(struct snapshot_list *sl, int unit_interval,
84 void free_snapshot_list(struct snapshot_list *sl);
85 __malloc char *incomplete_name(int64_t start);
86 __malloc char *being_deleted_name(struct snapshot *s);
87 int complete_name(int64_t start, int64_t end, char **result);
88 __malloc char *name_of_newest_complete_snapshot(struct snapshot_list *sl);
91 * Get the oldest snapshot in a snapshot list.
93 _static_inline_ struct snapshot *get_oldest_snapshot(struct snapshot_list *sl)
95 if (!sl->num_snapshots)
97 return sl->snapshots[0];