Recent refactor series (commits below) created a conflict with this virsh split series. This patch also renames virshCommandOptTimeoutToMs to vshCommandOptTimeoutToMs and moves it to vsh.c Commits causing conflict: 6da3b694 - faa14391 --- tools/virsh-domain.c | 150 ++++++++++++++++++++++++++------------------------ tools/virsh-network.c | 2 +- tools/virsh.c | 33 ----------- tools/virsh.h | 1 - tools/vsh.c | 35 ++++++++++++ tools/vsh.h | 1 + 6 files changed, 115 insertions(+), 107 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 1788ac8..283d475 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -1718,9 +1718,9 @@ static void virshCatchInt(int sig ATTRIBUTE_UNUSED, } -typedef struct _vshBlockJobWaitData vshBlockJobWaitData; -typedef vshBlockJobWaitData *vshBlockJobWaitDataPtr; -struct _vshBlockJobWaitData { +typedef struct _virshBlockJobWaitData virshBlockJobWaitData; +typedef virshBlockJobWaitData *virshBlockJobWaitDataPtr; +struct _virshBlockJobWaitData { vshControl *ctl; virDomainPtr dom; const char *dev; @@ -1737,14 +1737,14 @@ struct _vshBlockJobWaitData { static void -vshBlockJobStatusHandler(virConnectPtr conn ATTRIBUTE_UNUSED, - virDomainPtr dom ATTRIBUTE_UNUSED, - const char *disk, - int type ATTRIBUTE_UNUSED, - int status, - void *opaque) +virshBlockJobStatusHandler(virConnectPtr conn ATTRIBUTE_UNUSED, + virDomainPtr dom ATTRIBUTE_UNUSED, + const char *disk, + int type ATTRIBUTE_UNUSED, + int status, + void *opaque) { - vshBlockJobWaitDataPtr data = opaque; + virshBlockJobWaitDataPtr data = opaque; if (STREQ_NULLABLE(disk, data->dev)) data->status = status; @@ -1752,7 +1752,7 @@ vshBlockJobStatusHandler(virConnectPtr conn ATTRIBUTE_UNUSED, /** - * vshBlockJobWaitInit: + * virshBlockJobWaitInit: * @ctl: vsh control structure * @dom: domain object * @dev: block device name to wait for @@ -1763,23 +1763,24 @@ vshBlockJobStatusHandler(virConnectPtr conn ATTRIBUTE_UNUSED, * * Prepares virsh for waiting for completion of a block job. This function * registers event handlers for block job events and prepares the data structures - * for them. A call to vshBlockJobWait then waits for completion of the given + * for them. A call to virshBlockJobWait then waits for completion of the given * block job. This function should be tolerant to different versions of daemon * and the reporting capabilities of those. * * Returns the data structure that holds data needed for block job waiting or * NULL in case of error. */ -static vshBlockJobWaitDataPtr -vshBlockJobWaitInit(vshControl *ctl, - virDomainPtr dom, - const char *dev, - const char *job_name, - bool verbose, - unsigned int timeout, - bool async_abort) +static virshBlockJobWaitDataPtr +virshBlockJobWaitInit(vshControl *ctl, + virDomainPtr dom, + const char *dev, + const char *job_name, + bool verbose, + unsigned int timeout, + bool async_abort) { - vshBlockJobWaitDataPtr ret; + virshBlockJobWaitDataPtr ret; + virshControlPtr priv = ctl->privData; if (VIR_ALLOC(ret) < 0) return NULL; @@ -1796,14 +1797,14 @@ vshBlockJobWaitInit(vshControl *ctl, ret->status = -1; virConnectDomainEventGenericCallback cb = - VIR_DOMAIN_EVENT_CALLBACK(vshBlockJobStatusHandler); + VIR_DOMAIN_EVENT_CALLBACK(virshBlockJobStatusHandler); - if ((ret->cb_id = virConnectDomainEventRegisterAny(ctl->conn, dom, + if ((ret->cb_id = virConnectDomainEventRegisterAny(priv->conn, dom, VIR_DOMAIN_EVENT_ID_BLOCK_JOB, cb, ret, NULL)) < 0) vshResetLibvirtError(); - if ((ret->cb_id2 = virConnectDomainEventRegisterAny(ctl->conn, dom, + if ((ret->cb_id2 = virConnectDomainEventRegisterAny(priv->conn, dom, VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2, cb, ret, NULL)) < 0) vshResetLibvirtError(); @@ -1813,23 +1814,26 @@ vshBlockJobWaitInit(vshControl *ctl, static void -vshBlockJobWaitFree(vshBlockJobWaitDataPtr data) +virshBlockJobWaitFree(virshBlockJobWaitDataPtr data) { + virshControlPtr priv = NULL; + if (!data) return; + priv = data->ctl->privData; if (data->cb_id >= 0) - virConnectDomainEventDeregisterAny(data->ctl->conn, data->cb_id); + virConnectDomainEventDeregisterAny(priv->conn, data->cb_id); if (data->cb_id2 >= 0) - virConnectDomainEventDeregisterAny(data->ctl->conn, data->cb_id2); + virConnectDomainEventDeregisterAny(priv->conn, data->cb_id2); VIR_FREE(data); } /** - * vshBlockJobWait: - * @data: private data initialized by vshBlockJobWaitInit + * virshBlockJobWait: + * @data: private data initialized by virshBlockJobWaitInit * * Waits for the block job to complete. This function prefers to get an event * from libvirt but still has fallback means if the device name can't be matched @@ -1841,7 +1845,7 @@ vshBlockJobWaitFree(vshBlockJobWaitDataPtr data) * VIR_DOMAIN_BLOCK_JOB_READY. */ static int -vshBlockJobWait(vshBlockJobWaitDataPtr data) +virshBlockJobWait(virshBlockJobWaitDataPtr data) { /* For two phase jobs like active commit or block copy, the marker reaches * 100% and an event fires. In case where virsh would not be able to match @@ -1871,7 +1875,7 @@ vshBlockJobWait(vshBlockJobWaitDataPtr data) sigaddset(&sigmask, SIGINT); intCaught = 0; - sig_action.sa_sigaction = vshCatchInt; + sig_action.sa_sigaction = virshCatchInt; sig_action.sa_flags = SA_SIGINFO; sigemptyset(&sig_action.sa_mask); sigaction(SIGINT, &sig_action, &old_sig_action); @@ -1913,7 +1917,8 @@ vshBlockJobWait(vshBlockJobWaitDataPtr data) } if (data->verbose) - vshPrintJobProgress(data->job_name, info.end - info.cur, info.end); + virshPrintJobProgress(data->job_name, info.end - info.cur, + info.end); if (data->timeout && virTimeMillisNow(&curr) < 0) { vshSaveLibvirtError(); @@ -1941,7 +1946,7 @@ vshBlockJobWait(vshBlockJobWaitDataPtr data) if (data->verbose && (ret == VIR_DOMAIN_BLOCK_JOB_COMPLETED || ret == VIR_DOMAIN_BLOCK_JOB_READY)) - vshPrintJobProgress(data->job_name, 0, 1); + virshPrintJobProgress(data->job_name, 0, 1); sigaction(SIGINT, &old_sig_action, NULL); return ret; @@ -2046,7 +2051,7 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd) int abort_flags = 0; unsigned int flags = 0; unsigned long bandwidth = 0; - vshBlockJobWaitDataPtr bjWait = NULL; + virshBlockJobWaitDataPtr bjWait = NULL; VSH_EXCLUSIVE_OPTIONS("pivot", "keep-overlay"); @@ -2097,12 +2102,12 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd) if (async) abort_flags |= VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC; - if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) + if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) return false; if (blocking && - !(bjWait = vshBlockJobWaitInit(ctl, dom, path, _("Block commit"), - verbose, timeout, async))) + !(bjWait = virshBlockJobWaitInit(ctl, dom, path, _("Block commit"), + verbose, timeout, async))) goto cleanup; if (virDomainBlockCommit(dom, path, base, top, bandwidth, flags) < 0) @@ -2119,7 +2124,7 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd) } /* Execution continues here only if --wait or friends were specified */ - switch (vshBlockJobWait(bjWait)) { + switch (virshBlockJobWait(bjWait)) { case -1: goto cleanup; @@ -2164,7 +2169,7 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd) ret = true; cleanup: virDomainFree(dom); - vshBlockJobWaitFree(bjWait); + virshBlockJobWaitFree(bjWait); return ret; } @@ -2282,7 +2287,7 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd) const char *xml = NULL; char *xmlstr = NULL; virTypedParameterPtr params = NULL; - vshBlockJobWaitDataPtr bjWait = NULL; + virshBlockJobWaitDataPtr bjWait = NULL; int nparams = 0; if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0) @@ -2346,8 +2351,8 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd) goto cleanup; if (blocking && - !(bjWait = vshBlockJobWaitInit(ctl, dom, path, _("Block Copy"), verbose, - timeout, async))) + !(bjWait = virshBlockJobWaitInit(ctl, dom, path, _("Block Copy"), + verbose, timeout, async))) goto cleanup; if (xml) { @@ -2425,7 +2430,7 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd) } /* Execution continues here only if --wait or friends were specified */ - switch (vshBlockJobWait(bjWait)) { + switch (virshBlockJobWait(bjWait)) { case -1: goto cleanup; @@ -2469,7 +2474,7 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd) VIR_FREE(xmlstr); virTypedParamsFree(params, nparams); virDomainFree(dom); - vshBlockJobWaitFree(bjWait); + virshBlockJobWaitFree(bjWait); return ret; } @@ -2546,13 +2551,14 @@ virshDomainBlockJobToString(int type) static bool -vshBlockJobInfo(vshControl *ctl, - virDomainPtr dom, - const char *path, - bool raw, - bool bytes) +virshBlockJobInfo(vshControl *ctl, + virDomainPtr dom, + const char *path, + bool raw, + bool bytes) { virDomainBlockJobInfo info; + virshControlPtr priv = ctl->privData; unsigned long long speed; unsigned int flags = 0; bool ret = false; @@ -2630,10 +2636,10 @@ vshBlockJobInfo(vshControl *ctl, static bool -vshBlockJobSetSpeed(vshControl *ctl, - const vshCmd *cmd, - virDomainPtr dom, - const char *path) +virshBlockJobSetSpeed(vshControl *ctl, + const vshCmd *cmd, + virDomainPtr dom, + const char *path) { unsigned long bandwidth; @@ -2648,10 +2654,10 @@ vshBlockJobSetSpeed(vshControl *ctl, static bool -vshBlockJobAbort(virDomainPtr dom, - const char *path, - bool pivot, - bool async) +virshBlockJobAbort(virDomainPtr dom, + const char *path, + bool pivot, + bool async) { unsigned int flags = 0; @@ -2697,7 +2703,7 @@ cmdBlockJob(vshControl *ctl, const vshCmd *cmd) /* XXX also support --bytes with bandwidth mode */ VSH_EXCLUSIVE_OPTIONS_VAR(bytes, bandwidth); - if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) + if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) goto cleanup; /* XXX Allow path to be optional to list info on all devices at once */ @@ -2705,11 +2711,11 @@ cmdBlockJob(vshControl *ctl, const vshCmd *cmd) goto cleanup; if (bandwidth) - ret = vshBlockJobSetSpeed(ctl, cmd, dom, path); + ret = virshBlockJobSetSpeed(ctl, cmd, dom, path); else if (abortMode || pivot || async) - ret = vshBlockJobAbort(dom, path, pivot, async); + ret = virshBlockJobAbort(dom, path, pivot, async); else - ret = vshBlockJobInfo(ctl, dom, path, raw, bytes); + ret = virshBlockJobInfo(ctl, dom, path, raw, bytes); cleanup: if (dom) @@ -2785,7 +2791,7 @@ cmdBlockPull(vshControl *ctl, const vshCmd *cmd) const char *base = NULL; unsigned long bandwidth = 0; unsigned int flags = 0; - vshBlockJobWaitDataPtr bjWait = NULL; + virshBlockJobWaitDataPtr bjWait = NULL; VSH_REQUIRE_OPTION("verbose", "wait"); VSH_REQUIRE_OPTION("async", "wait"); @@ -2805,12 +2811,12 @@ cmdBlockPull(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "keep-relative")) flags |= VIR_DOMAIN_BLOCK_REBASE_RELATIVE; - if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) + if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) return false; if (blocking && - !(bjWait = vshBlockJobWaitInit(ctl, dom, path, _("Block Pull"), verbose, - timeout, async))) + !(bjWait = virshBlockJobWaitInit(ctl, dom, path, _("Block Pull"), + verbose, timeout, async))) goto cleanup; if (base || flags) { @@ -2828,7 +2834,7 @@ cmdBlockPull(vshControl *ctl, const vshCmd *cmd) } /* Execution continues here only if --wait or friends were specified */ - switch (vshBlockJobWait(bjWait)) { + switch (virshBlockJobWait(bjWait)) { case -1: goto cleanup; @@ -2852,7 +2858,7 @@ cmdBlockPull(vshControl *ctl, const vshCmd *cmd) cleanup: virDomainFree(dom); - vshBlockJobWaitFree(bjWait); + virshBlockJobWaitFree(bjWait); return ret; } @@ -5383,7 +5389,7 @@ static const vshCmdOptDef opts_screenshot[] = { * Generate string: '<domain name>-<timestamp>[<extension>]' */ static char * -vshGenFileName(vshControl *ctl, virDomainPtr dom, const char *mime) +virshGenFileName(vshControl *ctl, virDomainPtr dom, const char *mime) { char timestr[100]; time_t cur_time; @@ -5450,7 +5456,7 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd) } if (!file) { - if (!(file = vshGenFileName(ctl, dom, mime))) + if (!(file = virshGenFileName(ctl, dom, mime))) goto cleanup; generated = true; } @@ -9188,7 +9194,7 @@ cmdQemuMonitorEvent(vshControl *ctl, const vshCmd *cmd) data.loop = vshCommandOptBool(cmd, "loop"); data.pretty = vshCommandOptBool(cmd, "pretty"); data.count = 0; - if (virshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) + if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) return false; if (vshCommandOptString(ctl, cmd, "event", &event) < 0) return false; @@ -10174,7 +10180,7 @@ cmdMigrate(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "live")) live_flag = true; - if (virshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) { + if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) { goto cleanup; } else if (timeout > 0 && !live_flag) { vshError(ctl, "%s", @@ -12453,7 +12459,7 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd) data[0].cb = &vshEventCallbacks[event]; data[0].id = -1; } - if (virshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) + if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) goto cleanup; if (vshCommandOptBool(cmd, "domain")) diff --git a/tools/virsh-network.c b/tools/virsh-network.c index 00a50ef..a0f7707 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -1276,7 +1276,7 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd) data.ctl = ctl; data.loop = vshCommandOptBool(cmd, "loop"); data.count = 0; - if (virshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) + if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0) return false; if (vshCommandOptBool(cmd, "network")) diff --git a/tools/virsh.c b/tools/virsh.c index 97294c5..9f9e1d3 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -536,39 +536,6 @@ cmdQuit(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) * --------------- */ -/* - * virshCommandOptTimeoutToMs: - * @ctl virsh control structure - * @cmd command reference - * @timeout result - * - * Parse an optional --timeout parameter in seconds, but store the - * value of the timeout in milliseconds. - * See vshCommandOptInt() - */ -int -virshCommandOptTimeoutToMs(vshControl *ctl, const vshCmd *cmd, int *timeout) -{ - int ret; - unsigned int utimeout; - - if ((ret = vshCommandOptUInt(ctl, cmd, "timeout", &utimeout)) <= 0) - return ret; - - /* Ensure that the timeout is not zero and that we can convert - * it from seconds to milliseconds without overflowing. */ - if (utimeout == 0 || utimeout > INT_MAX / 1000) { - vshError(ctl, - _("Numeric value '%u' for <%s> option is malformed or out of range"), - utimeout, - "timeout"); - ret = -1; - } else { - *timeout = ((int) utimeout) * 1000; - } - - return ret; -} static bool virshConnectionUsability(vshControl *ctl, virConnectPtr conn) diff --git a/tools/virsh.h b/tools/virsh.h index 6c4159a..3402408 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -102,7 +102,6 @@ typedef enum { } virshLookupByFlags; virConnectPtr virshConnect(vshControl *ctl, const char *uri, bool readonly); -int virshCommandOptTimeoutToMs(vshControl *ctl, const vshCmd *cmd, int *timeout); int virshDomainState(vshControl *ctl, virDomainPtr dom, int *reason); int virshStreamSink(virStreamPtr st, const char *bytes, size_t nbytes, diff --git a/tools/vsh.c b/tools/vsh.c index f4c342b..62f57ca 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -1574,6 +1574,41 @@ vshCommandStringParse(vshControl *ctl, char *cmdstr) return vshCommandParse(ctl, &parser); } +/** + * virshCommandOptTimeoutToMs: + * @ctl virsh control structure + * @cmd command reference + * @timeout result + * + * Parse an optional --timeout parameter in seconds, but store the + * value of the timeout in milliseconds. + * See vshCommandOptInt() + */ +int +vshCommandOptTimeoutToMs(vshControl *ctl, const vshCmd *cmd, int *timeout) +{ + int ret; + unsigned int utimeout; + + if ((ret = vshCommandOptUInt(ctl, cmd, "timeout", &utimeout)) <= 0) + return ret; + + /* Ensure that the timeout is not zero and that we can convert + * it from seconds to milliseconds without overflowing. */ + if (utimeout == 0 || utimeout > INT_MAX / 1000) { + vshError(ctl, + _("Numeric value '%u' for <%s> option is malformed or out of range"), + utimeout, + "timeout"); + ret = -1; + } else { + *timeout = ((int) utimeout) * 1000; + } + + return ret; +} + + /* --------------- * Misc utils * --------------- diff --git a/tools/vsh.h b/tools/vsh.h index 66c9c3b..ecf52e9 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -295,6 +295,7 @@ bool vshCommandStringParse(vshControl *ctl, char *cmdstr); const vshCmdOpt *vshCommandOptArgv(vshControl *ctl, const vshCmd *cmd, const vshCmdOpt *opt); bool vshCommandArgvParse(vshControl *ctl, int nargs, char **argv); +int vshCommandOptTimeoutToMs(vshControl *ctl, const vshCmd *cmd, int *timeout); void vshPrintExtra(vshControl *ctl, const char *format, ...) ATTRIBUTE_FMT_PRINTF(2, 3); -- 2.4.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list