提交 2eba5c56 编写于 作者: J John Ferlan

virsh: Add --delete-snapshots flag for undefine and vol-delete

https://bugzilla.redhat.com/show_bug.cgi?id=1281710

Commit id '3c7590e0' added the flag to the rbd backend, but provided
no means via virsh to use the flag.  This patch adds a '--delete-snapshots'
option to both the "undefine" and "vol-delete" commands.

For "undefine", the flag is combined with the "--remove-all-storage" flag
in order to add the appropriate flag for the virStorageVolDelete call;
whereas, for the "vol-delete" command, just the flag is sufficient since
it's only operating on one volume.

Currently only supported for rbd backends.
上级 7d792b99
......@@ -3674,6 +3674,11 @@ static const vshCmdOptDef opts_undefine[] = {
.type = VSH_OT_BOOL,
.help = N_("remove all associated storage volumes (use with caution)")
},
{.name = "delete-snapshots",
.type = VSH_OT_BOOL,
.help = N_("delete snapshots associated with volume(s), requires "
"--remove-all-storage (must be supported by storage driver)")
},
{.name = "wipe-storage",
.type = VSH_OT_BOOL,
.help = N_("wipe data on the removed volumes")
......@@ -3703,11 +3708,13 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
const char *name = NULL;
/* Flags to attempt. */
unsigned int flags = 0;
unsigned int vol_flags = 0;
/* User-requested actions. */
bool managed_save = vshCommandOptBool(cmd, "managed-save");
bool snapshots_metadata = vshCommandOptBool(cmd, "snapshots-metadata");
bool wipe_storage = vshCommandOptBool(cmd, "wipe-storage");
bool remove_all_storage = vshCommandOptBool(cmd, "remove-all-storage");
bool delete_snapshots = vshCommandOptBool(cmd, "delete-snapshots");
bool nvram = vshCommandOptBool(cmd, "nvram");
/* Positive if these items exist. */
int has_managed_save = 0;
......@@ -3736,6 +3743,8 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
size_t j;
virshControlPtr priv = ctl->privData;
VSH_REQUIRE_OPTION("delete-snapshots", "remove-all-storage");
ignore_value(vshCommandOptStringQuiet(ctl, cmd, "storage", &vol_string));
if (!(vol_string || remove_all_storage) && wipe_storage) {
......@@ -3745,6 +3754,9 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
return false;
}
if (delete_snapshots)
vol_flags |= VIR_STORAGE_VOL_DELETE_WITH_SNAPSHOTS;
if (managed_save) {
flags |= VIR_DOMAIN_UNDEFINE_MANAGED_SAVE;
managed_save_safe = true;
......@@ -4011,7 +4023,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
}
/* delete the volume */
if (virStorageVolDelete(vols[i].vol, 0) < 0) {
if (virStorageVolDelete(vols[i].vol, vol_flags) < 0) {
vshError(ctl, _("Failed to remove storage volume '%s'(%s)"),
vols[i].target, vols[i].source);
ret = false;
......
......@@ -887,6 +887,11 @@ static const vshCmdOptDef opts_vol_delete[] = {
.type = VSH_OT_STRING,
.help = N_("pool name or uuid")
},
{.name = "delete-snapshots",
.type = VSH_OT_BOOL,
.help = N_("delete snapshots associated with volume (must be "
"supported by storage driver)")
},
{.name = NULL}
};
......@@ -896,11 +901,16 @@ cmdVolDelete(vshControl *ctl, const vshCmd *cmd)
virStorageVolPtr vol;
bool ret = true;
const char *name;
bool delete_snapshots = vshCommandOptBool(cmd, "delete-snapshots");
unsigned int flags = 0;
if (!(vol = virshCommandOptVol(ctl, cmd, "vol", "pool", &name)))
return false;
if (virStorageVolDelete(vol, 0) == 0) {
if (delete_snapshots)
flags |= VIR_STORAGE_VOL_DELETE_WITH_SNAPSHOTS;
if (virStorageVolDelete(vol, flags) == 0) {
vshPrint(ctl, _("Vol %s deleted\n"), name);
} else {
vshError(ctl, _("Failed to delete vol %s"), name);
......
......@@ -2295,7 +2295,9 @@ Output the device used for the TTY console of the domain. If the information
is not available the processes will provide an exit code of 1.
=item B<undefine> I<domain> [I<--managed-save>] [I<--snapshots-metadata>]
[I<--nvram>] [ {I<--storage> B<volumes> | I<--remove-all-storage>} I<--wipe-storage>]
[I<--nvram>]
[ {I<--storage> B<volumes> | I<--remove-all-storage> [I<--delete-snapshots>]}
I<--wipe-storage>]
Undefine a domain. If the domain is running, this converts it to a
transient domain, without stopping it. If the domain is inactive,
......@@ -2330,6 +2332,11 @@ Example: --storage vda,/path/to/storage.img
The I<--remove-all-storage> flag specifies that all of the domain's storage
volumes should be deleted.
The I<--delete-snapshots> flag specifies that any snapshots associated with
the storage volume should be deleted as well. Requires the
I<--remove-all-storage> flag to be provided. Not all storage drivers
support this option, presently only rbd.
The flag I<--wipe-storage> specifies that the storage volumes should be
wiped before removal.
......@@ -3461,12 +3468,17 @@ where the data blocks are copied only when modified.
If this is not possible, the copy fails.
=item B<vol-delete> [I<--pool> I<pool-or-uuid>] I<vol-name-or-key-or-path>
[I<--delete-snapshots>]
Delete a given volume.
I<--pool> I<pool-or-uuid> is the name or UUID of the storage pool the volume
is in.
I<vol-name-or-key-or-path> is the name or key or path of the volume to delete.
The I<--delete-snapshots> flag specifies that any snapshots associated with
the storage volume should be deleted as well. Not all storage drivers
support this option, presently only rbd.
=item B<vol-upload> [I<--pool> I<pool-or-uuid>] [I<--offset> I<bytes>]
[I<--length> I<bytes>] I<vol-name-or-key-or-path> I<local-file>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册