int64_t x = 0, now = get_current_time(), unit_interval
= 24 * 3600 * conf.unit_interval_arg, ret;
unsigned wanted = desired_number_of_snapshots(0, conf.num_intervals_arg),
- num_complete_snapshots = 0;
+ num_complete = 0;
int i;
struct snapshot *s = NULL;
struct snapshot_list sl;
FOR_EACH_SNAPSHOT(s, i, &sl) {
if (!(s->flags & SS_COMPLETE))
continue;
- num_complete_snapshots++;
+ num_complete++;
x += s->completion_time - s->creation_time;
}
assert(x >= 0);
ret = now;
- if (num_complete_snapshots == 0)
+ if (num_complete == 0)
goto out;
- x /= num_complete_snapshots; /* avg time to create one snapshot */
+ x /= num_complete; /* avg time to create one snapshot */
if (unit_interval < x * wanted) /* oops, no sleep at all */
goto out;
ret = s->completion_time + unit_interval / wanted - x;
*/
dss_get_snapshot_list(&sl);
ret = 0;
- if (!low_disk_space && sl.num_snapshots <= 1)
+ /*
+ * Don't remove anything if there is free space and we have fewer
+ * snapshots than configured, plus one. This way there is always one
+ * snapshot that can be recycled.
+ */
+ if (!low_disk_space && sl.num_snapshots <= 1 << conf.num_intervals_arg)
goto out;
why = "outdated";
victim = find_outdated_snapshot(&sl);
victim = find_redundant_snapshot(&sl);
if (victim)
goto remove;
- /* try harder only if disk space is low */
- if (!low_disk_space)
- goto out;
why = "orphaned";
victim = find_orphaned_snapshot(&sl);
if (victim)
goto remove;
+ /* try harder only if disk space is low */
+ if (!low_disk_space)
+ goto out;
DSS_WARNING_LOG(("disk space low and nothing obvious to remove\n"));
victim = find_oldest_removable_snapshot(&sl);
if (victim)
if (es != 0 && es != 24) {
DSS_WARNING_LOG(("rsync exit code %d, error count %d\n",
es, ++num_consecutive_rsync_errors));
+ if (conf.create_given) {
+ ret = -E_BAD_EXIT_CODE;
+ goto out;
+ }
if (num_consecutive_rsync_errors > conf.max_rsync_errors_arg) {
ret = -E_TOO_MANY_RSYNC_ERRORS;
snapshot_creation_status = HS_READY;
return install_sighandler(SIGCHLD);
}
-/**
- * The main function of dss.
- *
- * \param argc Usual argument count.
- * \param argv Usual argument vector.
- */
int main(int argc, char **argv)
{
int ret;