tmp.tv_sec = x;
tmp.tv_usec = 0;
ret = tv_diff(&unit_interval, &tmp, &diff); /* total sleep time per unit interval */
- gettimeofday(&now, NULL);
- if (ret < 0 || !s)
+ if (ret < 0 || !s) /* unit_interval < tmp or no snapshot */
goto min_sleep;
tv_divide(wanted, &diff, &tmp); /* sleep time betweeen two snapshots */
- diff.tv_sec = s->completion_time;
+ diff.tv_sec = s->completion_time; /* completion time of the the latest snaphot */
diff.tv_usec = 0;
tv_add(&diff, &tmp, &next_snapshot_time);
+ gettimeofday(&now, NULL);
if (tv_diff(&now, &next_snapshot_time, NULL) < 0)
goto out;
min_sleep:
}
-static int remove_snapshot(struct snapshot *s)
+static int remove_snapshot(struct snapshot *s, char *why)
{
int fds[3] = {0, 0, 0};
assert(!rm_pid);
if (ret < 0)
goto out;
- DSS_NOTICE_LOG("removing %s (interval = %i)\n", s->name, s->interval);
+ DSS_NOTICE_LOG("removing %s snapshot %s (interval = %i)\n",
+ why, s->name, s->interval);
ret = dss_exec(&rm_pid, argv[0], argv, fds);
out:
free(new_name);
return ret;
}
+static int snapshot_is_being_created(struct snapshot *s)
+{
+ return s->creation_time == current_snapshot_creation_time;
+}
+
/*
* return: 0: no redundant snapshots, 1: rm process started, negative: error
*/
FOR_EACH_SNAPSHOT(s, i, sl) {
int64_t this_score;
+ if (snapshot_is_being_created(s))
+ continue;
//DSS_DEBUG_LOG("checking %s\n", s->name);
if (s->interval > interval) {
prev = s;
victim->name, victim->interval);
continue;
}
- ret = remove_snapshot(victim);
+ ret = remove_snapshot(victim, "redundant");
return ret < 0? ret : 1;
}
return 0;
DSS_DEBUG_LOG("looking for snapshots belonging to intervals greater than %d\n",
conf.num_intervals_arg);
FOR_EACH_SNAPSHOT(s, i, sl) {
+ if (snapshot_is_being_created(s))
+ continue;
if (s->interval <= conf.num_intervals_arg)
continue;
if (conf.dry_run_given) {
s->name, s->interval);
continue;
}
- ret = remove_snapshot(s);
+ ret = remove_snapshot(s, "outdated");
if (ret < 0)
return ret;
return 1;
if (!s) /* no snapshot found */
return 0;
DSS_INFO_LOG("oldest snapshot: %s\n", s->name);
- if (s->creation_time == current_snapshot_creation_time)
- return 0; /* do not remove the snapshot currently being created */
- return remove_snapshot(s);
+ if (snapshot_is_being_created(s))
+ return 0;
+ return remove_snapshot(s, "oldest");
}
static int rename_incomplete_snapshot(int64_t start)
.check_ambiguity = 0,
.print_errors = 1
};
+ if (override) { /* invalidate all rsync options */
+ int i;
+
+ for (i = 0; i < conf.rsync_option_given; i++) {
+ free(conf.rsync_option_arg[i]);
+ conf.rsync_option_arg[i] = NULL;
+ }
+ conf.rsync_option_given = 0;
+ }
cmdline_parser_config_file(config_file, &conf, ¶ms);
}
ret = check_config();