On 18/04/13 16:29, harryxiyou@xxxxxxxxx wrote:
From: Harry Wei <harryxiyou@xxxxxxxxx>
Vol-rename is a convenience function, requiring when
one wanna rename a volume name.
NACK. It should use the upcoming rename APIs for the *-rename virsh
commands instead .
Signed-off-by: Harry Wei <harryxiyou@xxxxxxxxx>
---
tools/virsh-volume.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 103 insertions(+)
diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c
index 0ca295f..8757d54 100644
--- a/tools/virsh-volume.c
+++ b/tools/virsh-volume.c
@@ -490,6 +490,103 @@ cleanup:
}
/*
+ * "vol-rename" command
+ */
+static const vshCmdInfo info_vol_rename[] = {
+ {.name = "help",
+ .data = N_("rename a volume.")
+ },
+ {.name = "desc",
+ .data = N_("Rename an existing volume.")
+ },
+ {.name = NULL}
+};
+
+static const vshCmdOptDef opts_vol_rename[] = {
+ {.name = "vol",
+ .type = VSH_OT_DATA,
+ .flags = VSH_OFLAG_REQ,
+ .help = N_("orig vol name or key")
+ },
+ {.name = "newname",
+ .type = VSH_OT_DATA,
+ .flags = VSH_OFLAG_REQ,
+ .help = N_("new name")
+ },
+ {.name = "pool",
+ .type = VSH_OT_STRING,
+ .help = N_("pool name or uuid")
+ },
+ {.name = NULL}
+};
+
+static bool
+cmdVolRename(vshControl *ctl, const vshCmd *cmd)
+{
+ virStoragePoolPtr origpool = NULL;
+ virStorageVolPtr origvol = NULL, newvol = NULL;
+ const char *origname = NULL;
+ const char *name = NULL;
+ char *origxml = NULL;
+ xmlChar *newxml = NULL;
+ bool ret = false;
+ unsigned int flags = 0;
+
+ if (!(origvol = vshCommandOptVol(ctl, cmd, "vol", "pool", &origname)))
+ goto cleanup;
+
+ origpool = virStoragePoolLookupByVolume(origvol);
+ if (!origpool) {
+ vshError(ctl, "%s", _("failed to get parent pool"));
+ goto cleanup;
+ }
+
+ if (vshCommandOptStringReq(ctl, cmd, "newname", &name) < 0)
+ goto cleanup;
+
+ origxml = virStorageVolGetXMLDesc(origvol, 0);
+ if (!origxml)
+ goto cleanup;
+
+ newxml = vshMakeCloneXML(origxml, name);
+ if (!newxml) {
+ vshPrint(ctl, "%s", _("Failed to allocate XML buffer"));
+ goto cleanup;
+ }
+
+ newvol = virStorageVolCreateXMLFrom(origpool, (char *) newxml, origvol, flags);
+
+ if (newvol != NULL) {
+ vshPrint(ctl, _("Vol %s cloned from %s\n"),
+ virStorageVolGetName(newvol), virStorageVolGetName(origvol));
+ } else {
+ vshError(ctl, _("Failed to clone vol from %s"),
+ virStorageVolGetName(origvol));
+ goto cleanup;
+ }
+
+ if (virStorageVolDelete(origvol, 0) == 0) {
Indention problem..
+ vshPrint(ctl, _("Vol %s deleted\n"), origname);
+ } else {
+ vshError(ctl, _("Failed to delete vol %s"), origname);
+ goto cleanup;
+ }
+
+ ret = true;
+
+cleanup:
+ VIR_FREE(origxml);
+ xmlFree(newxml);
+ if (origvol)
+ virStorageVolFree(origvol);
+ if (newvol)
+ virStorageVolFree(newvol);
+ if (origpool)
+ virStoragePoolFree(origpool);
+ return ret;
+}
+
+/*
* "vol-clone" command
*/
static const vshCmdInfo info_vol_clone[] = {
@@ -1752,6 +1849,12 @@ cmdVolPath(vshControl *ctl, const vshCmd *cmd)
}
const vshCmdDef storageVolCmds[] = {
+ {.name = "vol-rename",
+ .handler = cmdVolRename,
+ .opts = opts_vol_rename,
+ .info = info_vol_rename,
+ .flags = 0
+ },
{.name = "vol-clone",
.handler = cmdVolClone,
.opts = opts_vol_clone,
--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list