Skip to content

Commit

Permalink
dog: a new option of interval during VDI deletion
Browse files Browse the repository at this point in the history
Signed-off-by: Hitoshi Mitake <mitake.hitoshi@lab.ntt.co.jp>
  • Loading branch information
mitake committed Feb 21, 2017
1 parent 95e4036 commit 2a81e0a
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions dog/vdi.c
Expand Up @@ -48,6 +48,8 @@ static struct sd_option vdi_options[] = {
"working VDI doesn't have its own objects"},
{'B', "nr-batched-reclamation", true, "specify a number of batched"
"reclamation during VDI deletion"},
{'I', "reclamation-interval", true, "specify how long (unti: second)"
"in reclamation loop during VDI deletion"},
{ 0, NULL, false, NULL },
};

Expand All @@ -71,6 +73,7 @@ static struct vdi_cmd_data {
bool exist;
bool reduce_identical_snapshots;
int nr_batched_reclamation;
int reclamation_interval;
} vdi_cmd_data = { ~0, };

struct get_vdi_info {
Expand Down Expand Up @@ -997,7 +1000,7 @@ static int vdi_resize(int argc, char **argv)
}

static int do_vdi_delete(const char *vdiname, int snap_id, const char *snap_tag,
int nr_batched_reclamation)
int nr_batched_reclamation, int reclamation_interval)
{
int ret, nr_objs;
struct sd_req hdr;
Expand Down Expand Up @@ -1058,6 +1061,9 @@ static int do_vdi_delete(const char *vdiname, int snap_id, const char *snap_tag,
ret = EXIT_FAILURE;
goto out;
}

if (i < nr_objs && reclamation_interval)
sleep(reclamation_interval);
}

sd_init_req(&hdr, SD_OP_DEL_VDI);
Expand Down Expand Up @@ -1095,7 +1101,8 @@ static int vdi_delete(int argc, char **argv)

return do_vdi_delete(vdiname, vdi_cmd_data.snapshot_id,
vdi_cmd_data.snapshot_tag,
vdi_cmd_data.nr_batched_reclamation);
vdi_cmd_data.nr_batched_reclamation,
vdi_cmd_data.reclamation_interval);
}

static int vdi_rollback(int argc, char **argv)
Expand All @@ -1122,7 +1129,8 @@ static int vdi_rollback(int argc, char **argv)
" previous\nsnapshot was taken. Continue? [yes/no]: ");

ret = do_vdi_delete(vdiname, 0, NULL,
vdi_cmd_data.nr_batched_reclamation);
vdi_cmd_data.nr_batched_reclamation,
vdi_cmd_data.reclamation_interval);
if (ret != SD_RES_SUCCESS) {
sd_err("Failed to delete the current state");
return EXIT_FAILURE;
Expand Down Expand Up @@ -2551,7 +2559,8 @@ static uint32_t do_restore(const char *vdiname, int snapid, const char *tag)
if (ret != SD_RES_SUCCESS) {
sd_err("failed to restore backup");
do_vdi_delete(vdiname, 0, NULL,
vdi_cmd_data.nr_batched_reclamation);
vdi_cmd_data.nr_batched_reclamation,
vdi_cmd_data.reclamation_interval);
ret = EXIT_FAILURE;
break;
}
Expand Down Expand Up @@ -2614,7 +2623,8 @@ static int vdi_restore(int argc, char **argv)
}

ret = do_vdi_delete(vdiname, 0, NULL,
vdi_cmd_data.nr_batched_reclamation);
vdi_cmd_data.nr_batched_reclamation,
vdi_cmd_data.reclamation_interval);
if (ret != EXIT_SUCCESS) {
sd_err("Failed to delete the current state");
goto out;
Expand Down Expand Up @@ -2969,10 +2979,10 @@ static struct subcommand vdi_cmd[] = {
{"clone", "<src vdi> <dst vdi>", "sPnaphrvT", "clone an image",
NULL, CMD_NEED_ROOT|CMD_NEED_ARG,
vdi_clone, vdi_options},
{"delete", "<vdiname>", "saphTB", "delete an image",
{"delete", "<vdiname>", "saphTBI", "delete an image",
NULL, CMD_NEED_ROOT|CMD_NEED_ARG,
vdi_delete, vdi_options},
{"rollback", "<vdiname>", "saphfrvTB", "rollback to a snapshot",
{"rollback", "<vdiname>", "saphfrvTBI", "rollback to a snapshot",
NULL, CMD_NEED_ROOT|CMD_NEED_ARG,
vdi_rollback, vdi_options},
{"list", "[vdiname]", "aprhoT", "list images",
Expand Down Expand Up @@ -3010,7 +3020,7 @@ static struct subcommand vdi_cmd[] = {
"create an incremental backup between two snapshots and outputs to STDOUT",
NULL, CMD_NEED_ROOT|CMD_NEED_NODELIST|CMD_NEED_ARG,
vdi_backup, vdi_options},
{"restore", "<vdiname>", "saphTB",
{"restore", "<vdiname>", "saphTBI",
"restore snapshot images from a backup provided in STDIN",
NULL, CMD_NEED_ROOT|CMD_NEED_NODELIST|CMD_NEED_ARG,
vdi_restore, vdi_options},
Expand Down Expand Up @@ -3138,6 +3148,18 @@ static int vdi_parser(int ch, const char *opt)
"positive integer");
exit(EXIT_FAILURE);
}
case 'I':
vdi_cmd_data.reclamation_interval = strtol(opt, &p, 10);
if (opt == p) {
sd_err("The interval of batched reclamation is"
" invalid: %s", opt);
exit(EXIT_FAILURE);
}
if (vdi_cmd_data.reclamation_interval <= 0) {
sd_err("The interval of batched reclamation must be"
"positive integer");
exit(EXIT_FAILURE);
}
}

return 0;
Expand Down

0 comments on commit 2a81e0a

Please sign in to comment.