static pid_t create_pid;
/** Whether the pre-create-hook/rsync/post-create-hook is currently stopped. */
static int create_process_stopped;
-/** Process id of current rm process. */
-static pid_t rm_pid;
+/** Process id of current pre-remove/rm/post-remove process. */
+static pid_t remove_pid;
/** When the next snapshot is due. */
static struct timeval next_snapshot_time;
/** Creation time of the snapshot currently being created. */
static int remove_snapshot(struct snapshot *s, char *why)
{
int fds[3] = {0, 0, 0};
- assert(!rm_pid);
+ assert(!remove_pid);
char *new_name = being_deleted_name(s);
int ret = dss_rename(s->name, new_name);
char *argv[] = {"rm", "-rf", new_name, NULL};
goto out;
DSS_NOTICE_LOG("removing %s snapshot %s (interval = %i)\n",
why, s->name, s->interval);
- ret = dss_exec(&rm_pid, argv[0], argv, fds);
+ ret = dss_exec(&remove_pid, argv[0], argv, fds);
out:
free(new_name);
return ret;
snapshot_creation_status = SCS_PRE_HOOK_SUCCESS;
return 0;
}
- DSS_NOTICE_LOG("executing %s\n", conf.pre_create_hook_arg);
+ DSS_DEBUG_LOG("executing %s\n", conf.pre_create_hook_arg);
ret = dss_exec_cmdline_pid(&create_pid,
conf.pre_create_hook_arg, fds);
if (ret < 0)
static int handle_rm_exit(int status)
{
- rm_pid = 0;
+ remove_pid = 0;
if (!WIFEXITED(status))
return -E_INVOLUNTARY_EXIT;
if (WEXITSTATUS(status))
static int wait_for_rm_process(void)
{
- int status, ret = wait_for_process(rm_pid, &status);
+ int status, ret = wait_for_process(remove_pid, &status);
if (ret < 0)
return ret;
static int handle_pre_create_hook_exit(int status)
{
int es, ret;
+ static int warn_count;
if (!WIFEXITED(status)) {
snapshot_creation_status = SCS_READY;
}
es = WEXITSTATUS(status);
if (es) {
+ if (!warn_count--) {
+ DSS_NOTICE_LOG("pre_create_hook %s returned %d\n",
+ conf.pre_create_hook_arg, es);
+ DSS_NOTICE_LOG("deferring snapshot creation...\n");
+ warn_count = 60; /* warn only once per hour */
+ }
snapshot_creation_status = SCS_READY;
compute_next_snapshot_time();
- ret = -E_BAD_EXIT_CODE;
+ ret = 0;
goto out;
}
+ warn_count = 0;
snapshot_creation_status = SCS_PRE_HOOK_SUCCESS;
ret = 1;
out:
return -E_BUG;
}
}
- if (pid == rm_pid)
+ if (pid == remove_pid)
return handle_rm_exit(status);
DSS_EMERG_LOG("BUG: unknown process %d died\n", (int)pid);
return -E_BUG;
case SIGTERM:
restart_create_process();
kill_process(create_pid);
- kill_process(rm_pid);
+ kill_process(remove_pid);
ret = -E_SIGNAL;
break;
case SIGHUP:
int low_disk_space;
struct timeval now, *tvp;
- if (rm_pid)
+ if (remove_pid)
tvp = NULL; /* sleep until rm process dies */
else { /* sleep one minute */
tv.tv_sec = 60;
if (ret < 0)
goto out;
}
- if (rm_pid)
+ if (remove_pid)
continue;
ret = disk_space_low();
if (ret < 0)
ret = try_to_free_disk_space(low_disk_space);
if (ret < 0)
goto out;
- if (rm_pid) {
+ if (remove_pid) {
stop_create_process();
continue;
}
if (ret < 0)
return ret;
ret = handle_pre_create_hook_exit(status);
- if (ret < 0)
+ if (ret <= 0) /* error, or pre-create failed */
return ret;
}
create_rsync_argv(&rsync_argv, ¤t_snapshot_creation_time);