提交 ef56cc43 编写于 作者: P Peter Krempa

virsh: domain: Fix undefine with storage of 'volume' disks

The undefine code that removes the storage along with the VM didn't take
into account the existence of 'volume' type disks. Add the functionality.
上级 878b8fa4
...@@ -2939,6 +2939,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) ...@@ -2939,6 +2939,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
int nvol_nodes; int nvol_nodes;
char *source = NULL; char *source = NULL;
char *target = NULL; char *target = NULL;
char *pool = NULL;
size_t i; size_t i;
size_t j; size_t j;
...@@ -3048,6 +3049,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) ...@@ -3048,6 +3049,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
vshUndefineVolume vol; vshUndefineVolume vol;
VIR_FREE(source); VIR_FREE(source);
VIR_FREE(target); VIR_FREE(target);
VIR_FREE(pool);
/* get volume source and target paths */ /* get volume source and target paths */
if (!(target = virXPathString("string(./target/@dev)", ctxt))) if (!(target = virXPathString("string(./target/@dev)", ctxt)))
...@@ -3057,9 +3059,12 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) ...@@ -3057,9 +3059,12 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
"./source/@file|" "./source/@file|"
"./source/@dir|" "./source/@dir|"
"./source/@name|" "./source/@name|"
"./source/@dev)", ctxt))) "./source/@dev|"
"./source/@volume)", ctxt)))
continue; continue;
pool = virXPathString("string(./source/@pool)", ctxt);
/* lookup if volume was selected by user */ /* lookup if volume was selected by user */
if (vol_list) { if (vol_list) {
bool found = false; bool found = false;
...@@ -3075,7 +3080,33 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) ...@@ -3075,7 +3080,33 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
continue; continue;
} }
if (!(vol.vol = virStorageVolLookupByPath(ctl->conn, source))) { if (pool) {
virStoragePoolPtr storagepool = NULL;
if (!source) {
vshPrint(ctl,
_("Missing storage volume name for disk '%s'"),
target);
continue;
}
if (!(storagepool = virStoragePoolLookupByName(ctl->conn,
pool))) {
vshPrint(ctl,
_("Storage pool '%s' for volume '%s' not found."),
pool, target);
vshResetLibvirtError();
continue;
}
vol.vol = virStorageVolLookupByName(storagepool, source);
virStoragePoolFree(storagepool);
} else {
vol.vol = virStorageVolLookupByPath(ctl->conn, source);
}
if (!vol.vol) {
vshPrint(ctl, vshPrint(ctl,
_("Storage volume '%s'(%s) is not managed by libvirt. " _("Storage volume '%s'(%s) is not managed by libvirt. "
"Remove it manually.\n"), target, source); "Remove it manually.\n"), target, source);
...@@ -3190,6 +3221,7 @@ out: ...@@ -3190,6 +3221,7 @@ out:
cleanup: cleanup:
VIR_FREE(source); VIR_FREE(source);
VIR_FREE(target); VIR_FREE(target);
VIR_FREE(pool);
for (i = 0; i < nvols; i++) { for (i = 0; i < nvols; i++) {
VIR_FREE(vols[i].source); VIR_FREE(vols[i].source);
VIR_FREE(vols[i].target); VIR_FREE(vols[i].target);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册