Define three new virsh commands:
* blockpull: Perform incremental block pull
* blockpull: Start/stop full device block pull
* blockpullinfo: Retrieve progress info for full device block pull
Share print_job_progress() with the migration code.
* tools/virsh.c: implement the new commands
Signed-off-by: Adam Litke <agl(a)us.ibm.com>
---
tools/virsh.c | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 130 insertions(+), 4 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c
index 2b16714..e04de60 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -3818,7 +3818,8 @@ out_sig:
}
static void
-print_job_progress(unsigned long long remaining, unsigned long long total)
+print_job_progress(const char *label, unsigned long long remaining,
+ unsigned long long total)
{
int progress;
@@ -3838,7 +3839,7 @@ print_job_progress(unsigned long long remaining, unsigned long long
total)
}
}
- fprintf(stderr, "\rMigration: [%3d %%]", progress);
+ fprintf(stderr, "\r%s: [%3d %%]", label, progress);
}
static bool
@@ -3925,7 +3926,7 @@ repoll:
functionReturn = true;
if (verbose) {
/* print [100 %] */
- print_job_progress(0, 1);
+ print_job_progress("Migration", 0, 1);
}
} else
functionReturn = false;
@@ -3964,7 +3965,8 @@ repoll:
pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL);
#endif
if (ret == 0)
- print_job_progress(jobinfo.dataRemaining, jobinfo.dataTotal);
+ print_job_progress("Migration", jobinfo.dataRemaining,
+ jobinfo.dataTotal);
}
}
@@ -4023,6 +4025,127 @@ done:
return ret;
}
+typedef enum {
+ VSH_CMD_BLOCK_PULL_ONE = 0,
+ VSH_CMD_BLOCK_PULL_ALL = 1,
+ VSH_CMD_BLOCK_PULL_ABORT = 2,
+ VSH_CMD_BLOCK_PULL_INFO = 3
+} VSH_CMD_BLOCK_PULL_MODE;
+
+static int
+blockPullImpl(vshControl *ctl, const vshCmd *cmd,
+ virDomainBlockPullInfoPtr info, int mode)
+{
+ virDomainPtr dom;
+ const char *name, *path;
+ int ret = -1;
+
+ if (!vshConnectionUsability(ctl, ctl->conn))
+ return false;
+
+ if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
+ return false;
+
+ if (vshCommandOptString(cmd, "path", &path) < 0)
+ return false;
+
+ if (mode == VSH_CMD_BLOCK_PULL_ONE)
+ ret = virDomainBlockPull(dom, path, info, 0);
+ else if (mode == VSH_CMD_BLOCK_PULL_ALL)
+ ret = virDomainBlockPullAll(dom, path, 0);
+ else if (mode == VSH_CMD_BLOCK_PULL_ABORT)
+ ret = virDomainBlockPullAbort(dom, path, 0);
+ else if (mode == VSH_CMD_BLOCK_PULL_INFO)
+ ret = virDomainGetBlockPullInfo(dom, path, info, 0);
+
+ virDomainFree(dom);
+ return ret;
+}
+
+/*
+ * "blockpull" command
+ */
+static const vshCmdInfo info_block_pull[] = {
+ {"help", N_("Iteratively populate a disk from its backing
image.")},
+ {"desc", N_("Iteratively populate a disk from its backing
image.")},
+ {NULL, NULL}
+};
+
+static const vshCmdOptDef opts_block_pull[] = {
+ {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or
uuid")},
+ {"path", VSH_OT_DATA, VSH_OFLAG_REQ, N_("Fully-qualified path of
disk")},
+ {NULL, 0, 0, NULL}
+};
+
+static bool
+cmdBlockPull(vshControl *ctl, const vshCmd *cmd)
+{
+ virDomainBlockPullInfo info;
+
+ if (blockPullImpl(ctl, cmd, &info, VSH_CMD_BLOCK_PULL_ONE) != 0)
+ return false;
+ print_job_progress("Block pull", info.end - info.cur, info.end);
+ return true;
+}
+
+/*
+ * "blockpullall" command
+ */
+static const vshCmdInfo info_block_pull_all[] = {
+ {"help", N_("Start or stop populating a disk from its backing
image.")},
+ {"desc", N_("Start or stop populating a disk from its backing
image.")},
+ {NULL, NULL}
+};
+
+static const vshCmdOptDef opts_block_pull_all[] = {
+ {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or
uuid")},
+ {"path", VSH_OT_DATA, VSH_OFLAG_REQ, N_("Fully-qualified path of
disk")},
+ {"abort", VSH_OT_BOOL, VSH_OFLAG_NONE, N_("Abort the current
operation")},
+ {NULL, 0, 0, NULL}
+};
+
+static bool
+cmdBlockPullAll(vshControl *ctl, const vshCmd *cmd)
+{
+ int mode;
+
+ if (vshCommandOptBool (cmd, "abort"))
+ mode = VSH_CMD_BLOCK_PULL_ABORT;
+ else
+ mode = VSH_CMD_BLOCK_PULL_ALL;
+
+ if (blockPullImpl(ctl, cmd, NULL, mode) != 0)
+ return false;
+ return true;
+}
+
+/*
+ * "blockpullinfo" command
+ */
+static const vshCmdInfo info_block_pull_info[] = {
+ {"help", N_("Check progress of an active block pull
operation.")},
+ {"desc", N_("Check progress of an active block pull
operation.")},
+ {NULL, NULL}
+};
+
+static const vshCmdOptDef opts_block_pull_info[] = {
+ {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or
uuid")},
+ {"path", VSH_OT_DATA, VSH_OFLAG_REQ, N_("Fully-qualified path of
disk")},
+ {NULL, 0, 0, NULL}
+};
+
+static bool
+cmdBlockPullInfo(vshControl *ctl, const vshCmd *cmd)
+{
+ virDomainBlockPullInfo info;
+
+ if (blockPullImpl(ctl, cmd, &info, VSH_CMD_BLOCK_PULL_INFO) != 0)
+ return false;
+ print_job_progress("Block pull", info.end - info.cur, info.end);
+ return true;
+}
+
+
/*
* "net-autostart" command
*/
@@ -10685,6 +10808,9 @@ static const vshCmdDef domManagementCmds[] = {
{"attach-interface", cmdAttachInterface, opts_attach_interface,
info_attach_interface},
{"autostart", cmdAutostart, opts_autostart, info_autostart},
{"blkiotune", cmdBlkiotune, opts_blkiotune, info_blkiotune},
+ {"blockpull", cmdBlockPull, opts_block_pull, info_block_pull},
+ {"blockpullall", cmdBlockPullAll, opts_block_pull_all,
info_block_pull_all},
+ {"blockpullinfo", cmdBlockPullInfo, opts_block_pull_info,
info_block_pull_info},
#ifndef WIN32
{"console", cmdConsole, opts_console, info_console},
#endif
--
1.7.3