diff --git a/dog/vdi.c b/dog/vdi.c index 2a37f493f..8ec243aa2 100644 --- a/dog/vdi.c +++ b/dog/vdi.c @@ -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 }, }; @@ -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 { @@ -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; @@ -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); @@ -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) @@ -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; @@ -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; } @@ -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; @@ -2969,10 +2979,10 @@ static struct subcommand vdi_cmd[] = { {"clone", " ", "sPnaphrvT", "clone an image", NULL, CMD_NEED_ROOT|CMD_NEED_ARG, vdi_clone, vdi_options}, - {"delete", "", "saphTB", "delete an image", + {"delete", "", "saphTBI", "delete an image", NULL, CMD_NEED_ROOT|CMD_NEED_ARG, vdi_delete, vdi_options}, - {"rollback", "", "saphfrvTB", "rollback to a snapshot", + {"rollback", "", "saphfrvTBI", "rollback to a snapshot", NULL, CMD_NEED_ROOT|CMD_NEED_ARG, vdi_rollback, vdi_options}, {"list", "[vdiname]", "aprhoT", "list images", @@ -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", "", "saphTB", + {"restore", "", "saphTBI", "restore snapshot images from a backup provided in STDIN", NULL, CMD_NEED_ROOT|CMD_NEED_NODELIST|CMD_NEED_ARG, vdi_restore, vdi_options}, @@ -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;