On 2012年08月19日 12:10, Eric Blake wrote:
Convert the exported items in virsh.h to use a common 'vsh' prefix.
* tools/virsh.h (VIRSH_MAX_XML_FILE, GETTIMEOFDAY): Rename... (VSH_MAX_XML_FILE): ...and parenthesize. (DIFF_MSEC, CTRL_CLOSE_BRACKET): Delete. (vshUsage, vshInit, vshDeinit, vshParseArgv): Remove prototype. (editWriteToTempFile, editFile, editReadBackFile, prettyCapacity) (virshReportError): Rename... (vshEditWriteToTempFile, vshEditFile, vshEditReadBackFile) (vshPrettyCapacity, vshReportError): ...into vsh namespace. (jobWatchTimeoutFunc): Move to virsh-domain.c. * tools/virsh.c (vshCommandRun): Inline former DIFF_MSEC. (main): Inline former CTRL_CLOSE_BRACKET. (vshUsage, vshInit, vshDeinit, vshParseArgv): Make static. (prettyCapacity, virshReportError, editWriteToTempFile, editFile): Fix naming, and adjust usage. (vshAskReedit, vshCommandRun, vshEventLoop, vshInit): Adjust usage. * tools/virsh-domain.c (cmdAttachDevice, cmdCPUCompare) (cmdCPUBaseline, cmdCreate, cmdDefine, cmdDetachDevice) (cmdUpdateDevice, cmdDesc, cmdUndefine, cmdStart, cmdVcpucount) (cmdAttachDevice, cmdDomjobinfo): Likewise. * tools/virsh-edit.c (do): Likewise. * tools/virsh-interface.c (cmdInterfaceDefine): Likewise. * tools/virsh-network.c (cmdNetworkCreate, cmdNetworkDefine): Likewise. * tools/virsh-nodedev.c (cmdNodeDeviceCreate): Likewise. * tools/virsh-nwfilter.c (cmdNWFilterDefine): Likewise. * tools/virsh-pool.c (cmdPoolCreate, cmdPoolDefine) (cmdPoolDiscoverSources, cmdPoolList): Likewise. * tools/virsh-secret.c (cmdSecretDefine): Likewise. * tools/virsh-snapshot.c (cmdSnapshotCreate, vshSnapshotCreate) (vshLookupSnapshot, cmdSnapshotEdit, cmdSnapshotCurrent) (vshGetSnapshotParent): Likewise. * tools/virsh-volume.c (cmdVolCreate, cmdVolCreateFrom) (cmdVolInfo, cmdVolList): Likewise. --- tools/virsh-domain.c | 65 ++++++++++++++++++++++++++----------------------- tools/virsh-edit.c | 6 ++--- tools/virsh-interface.c | 2 +- tools/virsh-network.c | 4 +-- tools/virsh-nodedev.c | 2 +- tools/virsh-nwfilter.c | 2 +- tools/virsh-pool.c | 19 ++++++++------- tools/virsh-secret.c | 2 +- tools/virsh-snapshot.c | 16 ++++++------ tools/virsh-volume.c | 16 ++++++------ tools/virsh.c | 43 +++++++++++++++++--------------- tools/virsh.h | 26 +++++--------------- 12 files changed, 98 insertions(+), 105 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index edbda91..d102378 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -105,8 +105,8 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd) return false; }
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) { - virshReportError(ctl); + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) { + vshReportError(ctl); virDomainFree(dom); return false; } @@ -2544,7 +2544,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) goto cleanup; } if (virDomainManagedSaveRemove(dom, 0)< 0) { - virshReportError(ctl); + vshReportError(ctl); goto cleanup; } } @@ -2618,7 +2618,7 @@ cleanup: return ret;
error: - virshReportError(ctl); + vshReportError(ctl); goto cleanup; }
@@ -2687,7 +2687,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) goto started; if (last_error->code != VIR_ERR_NO_SUPPORT&& last_error->code != VIR_ERR_INVALID_ARG) { - virshReportError(ctl); + vshReportError(ctl); goto cleanup; } vshResetLibvirtError(); @@ -2697,7 +2697,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) vshResetLibvirtError(); } else if (rc> 0) { if (virDomainManagedSaveRemove(dom, 0)< 0) { - virshReportError(ctl); + vshReportError(ctl); goto cleanup; } } @@ -2809,6 +2809,9 @@ out_sig: ignore_value(safewrite(data->writefd,&ret, sizeof(ret))); }
+typedef void (*jobWatchTimeoutFunc) (vshControl *ctl, virDomainPtr dom, + void *opaque); + static bool vshWatchJob(vshControl *ctl, virDomainPtr dom, @@ -4088,27 +4091,27 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd) if (info.type == VIR_DOMAIN_JOB_BOUNDED) vshPrint(ctl, "%-17s %-12llu ms\n", _("Time remaining:"), info.timeRemaining); if (info.dataTotal || info.dataRemaining || info.dataProcessed) { - val = prettyCapacity(info.dataProcessed,&unit); + val = vshPrettyCapacity(info.dataProcessed,&unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("Data processed:"), val, unit); - val = prettyCapacity(info.dataRemaining,&unit); + val = vshPrettyCapacity(info.dataRemaining,&unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("Data remaining:"), val, unit); - val = prettyCapacity(info.dataTotal,&unit); + val = vshPrettyCapacity(info.dataTotal,&unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("Data total:"), val, unit); } if (info.memTotal || info.memRemaining || info.memProcessed) { - val = prettyCapacity(info.memProcessed,&unit); + val = vshPrettyCapacity(info.memProcessed,&unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("Memory processed:"), val, unit); - val = prettyCapacity(info.memRemaining,&unit); + val = vshPrettyCapacity(info.memRemaining,&unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("Memory remaining:"), val, unit); - val = prettyCapacity(info.memTotal,&unit); + val = vshPrettyCapacity(info.memTotal,&unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("Memory total:"), val, unit); } if (info.fileTotal || info.fileRemaining || info.fileProcessed) { - val = prettyCapacity(info.fileProcessed,&unit); + val = vshPrettyCapacity(info.fileProcessed,&unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("File processed:"), val, unit); - val = prettyCapacity(info.fileRemaining,&unit); + val = vshPrettyCapacity(info.fileRemaining,&unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("File remaining:"), val, unit); - val = prettyCapacity(info.fileTotal,&unit); + val = vshPrettyCapacity(info.fileTotal,&unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("File total:"), val, unit); } } else { @@ -4275,7 +4278,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd) count = virDomainGetVcpusFlags(dom, maximum ? VIR_DOMAIN_VCPU_MAXIMUM : 0); if (count< 0) { - virshReportError(ctl); + vshReportError(ctl); ret = false; } else { vshPrint(ctl, "%d\n", count); @@ -4299,7 +4302,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd) }
if (count< 0) { - virshReportError(ctl); + vshReportError(ctl); ret = false; } else if (all) { vshPrint(ctl, "%-12s %-12s %3d\n", _("maximum"), _("config"), @@ -4319,7 +4322,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd) }
if (count< 0) { - virshReportError(ctl); + vshReportError(ctl); ret = false; } else if (all) { vshPrint(ctl, "%-12s %-12s %3d\n", _("maximum"), _("live"), @@ -4355,7 +4358,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd) }
if (count< 0) { - virshReportError(ctl); + vshReportError(ctl); ret = false; } else if (all) { vshPrint(ctl, "%-12s %-12s %3d\n", _("current"), _("config"), @@ -4376,7 +4379,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd) }
if (count< 0) { - virshReportError(ctl); + vshReportError(ctl); ret = false; } else if (all) { vshPrint(ctl, "%-12s %-12s %3d\n", _("current"), _("live"), @@ -4869,7 +4872,7 @@ cmdCPUCompare(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file",&from)<= 0) return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) { + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) { vshError(ctl, _("Failed to read file '%s' to compare"), from); return false; @@ -4972,7 +4975,7 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file",&from)<= 0) return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) return false;
/* add a separate container around the xml */ @@ -5234,7 +5237,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file",&from)<= 0) return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) return false;
if (vshCommandOptBool(cmd, "paused")) @@ -5288,7 +5291,7 @@ cmdDefine(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file",&from)<= 0) return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) return false;
dom = virDomainDefineXML(ctl->conn, buffer); @@ -5448,15 +5451,15 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
if (edit) { /* Create and open the temporary file. */ - if (!(tmp = editWriteToTempFile(ctl, desc))) + if (!(tmp = vshEditWriteToTempFile(ctl, desc))) goto cleanup;
/* Start the editor. */ - if (editFile(ctl, tmp) == -1) + if (vshEditFile(ctl, tmp) == -1) goto cleanup;
/* Read back the edited file. */ - if (!(desc_edited = editReadBackFile(ctl, tmp))) + if (!(desc_edited = vshEditReadBackFile(ctl, tmp))) goto cleanup;
/* strip a possible newline at the end of file; some @@ -7368,8 +7371,8 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file",&from)<= 0) goto cleanup;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) { - virshReportError(ctl); + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) { + vshReportError(ctl); goto cleanup; }
@@ -7434,8 +7437,8 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd) return false; }
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) { - virshReportError(ctl); + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) { + vshReportError(ctl); virDomainFree(dom); return false; } diff --git a/tools/virsh-edit.c b/tools/virsh-edit.c index 4dea4b8..512ac0d 100644 --- a/tools/virsh-edit.c +++ b/tools/virsh-edit.c @@ -75,17 +75,17 @@ do { goto edit_cleanup;
/* Create and open the temporary file. */ - tmp = editWriteToTempFile(ctl, doc); + tmp = vshEditWriteToTempFile(ctl, doc); if (!tmp) goto edit_cleanup;
reedit: /* Start the editor. */ - if (editFile(ctl, tmp) == -1) + if (vshEditFile(ctl, tmp) == -1) goto edit_cleanup;
/* Read back the edited file. */ - doc_edited = editReadBackFile(ctl, tmp); + doc_edited = vshEditReadBackFile(ctl, tmp); if (!doc_edited) goto edit_cleanup;
diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c index 12019b4..ad080a1 100644 --- a/tools/virsh-interface.c +++ b/tools/virsh-interface.c @@ -369,7 +369,7 @@ cmdInterfaceDefine(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file",&from)<= 0) return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) return false;
iface = virInterfaceDefineXML(ctl->conn, buffer, 0); diff --git a/tools/virsh-network.c b/tools/virsh-network.c index 49ec34f..b33e2d6 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -143,7 +143,7 @@ cmdNetworkCreate(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file",&from)<= 0) return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) return false;
network = virNetworkCreateXML(ctl->conn, buffer); @@ -188,7 +188,7 @@ cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file",&from)<= 0) return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) return false;
network = virNetworkDefineXML(ctl->conn, buffer); diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 5a0987d..1398fbd 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -55,7 +55,7 @@ cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file",&from)<= 0) return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) return false;
dev = virNodeDeviceCreateXML(ctl->conn, buffer, 0); diff --git a/tools/virsh-nwfilter.c b/tools/virsh-nwfilter.c index e937b63..501e20d 100644 --- a/tools/virsh-nwfilter.c +++ b/tools/virsh-nwfilter.c @@ -94,7 +94,7 @@ cmdNWFilterDefine(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file",&from)<= 0) return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) return false;
nwfilter = virNWFilterDefineXML(ctl->conn, buffer); diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index af80427..e015547 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -141,7 +141,7 @@ cmdPoolCreate(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file",&from)<= 0) return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) return false;
pool = virStoragePoolCreateXML(ctl->conn, buffer, 0); @@ -303,7 +303,7 @@ cmdPoolDefine(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file",&from)<= 0) return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) return false;
pool = virStoragePoolDefineXML(ctl->conn, buffer, 0); @@ -748,7 +748,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) const char *unit;
/* Create the capacity output string */ - val = prettyCapacity(info.capacity,&unit); + val = vshPrettyCapacity(info.capacity,&unit); ret = virAsprintf(&poolInfoTexts[i].capacity, "%.2lf %s", val, unit); if (ret< 0) { @@ -757,7 +757,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) }
/* Create the allocation output string */ - val = prettyCapacity(info.allocation,&unit); + val = vshPrettyCapacity(info.allocation,&unit); ret = virAsprintf(&poolInfoTexts[i].allocation, "%.2lf %s", val, unit); if (ret< 0) { @@ -766,7 +766,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) }
/* Create the available space output string */ - val = prettyCapacity(info.available,&unit); + val = vshPrettyCapacity(info.available,&unit); ret = virAsprintf(&poolInfoTexts[i].available, "%.2lf %s", val, unit); if (ret< 0) { @@ -1090,7 +1090,8 @@ cmdPoolDiscoverSources(vshControl * ctl, const vshCmd * cmd ATTRIBUTE_UNUSED) if (!vshConnectionUsability(ctl, ctl->conn)) return false;
- if (srcSpecFile&& virFileReadAll(srcSpecFile, VIRSH_MAX_XML_FILE,&srcSpec)< 0) + if (srcSpecFile&& virFileReadAll(srcSpecFile, VSH_MAX_XML_FILE, +&srcSpec)< 0) return false;
srcList = virConnectFindStoragePoolSources(ctl->conn, type, srcSpec, 0); @@ -1186,13 +1187,13 @@ cmdPoolInfo(vshControl *ctl, const vshCmd *cmd)
if (info.state == VIR_STORAGE_POOL_RUNNING || info.state == VIR_STORAGE_POOL_DEGRADED) { - val = prettyCapacity(info.capacity,&unit); + val = vshPrettyCapacity(info.capacity,&unit); vshPrint(ctl, "%-15s %2.2lf %s\n", _("Capacity:"), val, unit);
- val = prettyCapacity(info.allocation,&unit); + val = vshPrettyCapacity(info.allocation,&unit); vshPrint(ctl, "%-15s %2.2lf %s\n", _("Allocation:"), val, unit);
- val = prettyCapacity(info.available,&unit); + val = vshPrettyCapacity(info.available,&unit); vshPrint(ctl, "%-15s %2.2lf %s\n", _("Available:"), val, unit); } } else { diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index e6c2ece..049ead5 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -78,7 +78,7 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file",&from)<= 0) return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) return false;
res = virSecretDefineXML(ctl->conn, buffer, 0); diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index 24e44b0..c480d1b 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -46,7 +46,7 @@ vshSnapshotCreate(vshControl *ctl, virDomainPtr dom, const char *buffer, vshResetLibvirtError(); persistent = virDomainIsPersistent(dom); if (persistent< 0) { - virshReportError(ctl); + vshReportError(ctl); goto cleanup; } if (!persistent) { @@ -64,7 +64,7 @@ vshSnapshotCreate(vshControl *ctl, virDomainPtr dom, const char *buffer, goto cleanup;
if (halt&& virDomainDestroy(dom)< 0) { - virshReportError(ctl); + vshReportError(ctl); goto cleanup; }
@@ -149,12 +149,12 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "xmlfile",&from)<= 0) buffer = vshStrdup(ctl, "<domainsnapshot/>"); else { - if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) { + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) { /* we have to report the error here because during cleanup * we'll run through virDomainFree(), which loses the * last error */ - virshReportError(ctl); + vshReportError(ctl); goto cleanup; } } @@ -362,7 +362,7 @@ vshLookupSnapshot(vshControl *ctl, const vshCmd *cmd, return -1; } if (!*snap) { - virshReportError(ctl); + vshReportError(ctl); return -1; }
@@ -455,7 +455,7 @@ cmdSnapshotEdit(vshControl *ctl, const vshCmd *cmd) delete_flags = VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY; if (virDomainSnapshotDelete(rename_okay ? snapshot : edited, delete_flags)< 0) { - virshReportError(ctl); + vshReportError(ctl); vshError(ctl, _("Failed to clean up %s"), rename_okay ? name : edited_name); goto cleanup; @@ -583,7 +583,7 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd)
cleanup: if (!ret) - virshReportError(ctl); + vshReportError(ctl); VIR_FREE(xml); if (snapshot) virDomainSnapshotFree(snapshot); @@ -640,7 +640,7 @@ vshGetSnapshotParent(vshControl *ctl, virDomainSnapshotPtr snapshot,
cleanup: if (ret< 0) { - virshReportError(ctl); + vshReportError(ctl); vshError(ctl, "%s", _("unable to determine if snapshot has parent")); } else { vshResetLibvirtError(); diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 5e5d925..d8ff920 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -300,8 +300,8 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd) return false; }
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) { - virshReportError(ctl); + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) { + vshReportError(ctl); virStoragePoolFree(pool); return false; } @@ -360,8 +360,8 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd) if (!(inputvol = vshCommandOptVol(ctl, cmd, "vol", "inputpool", NULL))) goto cleanup;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) { - virshReportError(ctl); + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) { + vshReportError(ctl); goto cleanup; }
@@ -847,10 +847,10 @@ cmdVolInfo(vshControl *ctl, const vshCmd *cmd) vshPrint(ctl, "%-15s %s\n", _("Type:"), _("unknown")); }
- val = prettyCapacity(info.capacity,&unit); + val = vshPrettyCapacity(info.capacity,&unit); vshPrint(ctl, "%-15s %2.2lf %s\n", _("Capacity:"), val, unit);
- val = prettyCapacity(info.allocation,&unit); + val = vshPrettyCapacity(info.allocation,&unit); vshPrint(ctl, "%-15s %2.2lf %s\n", _("Allocation:"), val, unit); } else { ret = false; @@ -1098,7 +1098,7 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) }
/* Create the capacity output string */ - val = prettyCapacity(volumeInfo.capacity,&unit); + val = vshPrettyCapacity(volumeInfo.capacity,&unit); ret = virAsprintf(&volInfoTexts[i].capacity, "%.2lf %s", val, unit); if (ret< 0) { @@ -1107,7 +1107,7 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) }
/* Create the allocation output string */ - val = prettyCapacity(volumeInfo.allocation,&unit); + val = vshPrettyCapacity(volumeInfo.allocation,&unit); ret = virAsprintf(&volInfoTexts[i].allocation, "%.2lf %s", val, unit); if (ret< 0) { diff --git a/tools/virsh.c b/tools/virsh.c index ecb27df..14d7cae 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -140,7 +140,7 @@ vshNameSorter(const void *a, const void *b) }
double -prettyCapacity(unsigned long long val, const char **unit) +vshPrettyCapacity(unsigned long long val, const char **unit) { if (val< 1024) { *unit = ""; @@ -194,7 +194,7 @@ vshResetLibvirtError(void) * and it's IMHO a bug that libvirt does that sometimes. */ void -virshReportError(vshControl *ctl) +vshReportError(vshControl *ctl) { if (last_error == NULL) { /* Calling directly into libvirt util functions won't trigger the @@ -312,7 +312,7 @@ vshAskReedit(vshControl *ctl, const char *msg) if (!isatty(STDIN_FILENO)) return -1;
- virshReportError(ctl); + vshReportError(ctl);
if (vshMakeStdinRaw(&ttyattr, false)< 0) return -1; @@ -509,7 +509,7 @@ vshTreePrint(vshControl *ctl, vshTreeLookup lookup, void *opaque,
/* Common code for the edit / net-edit / pool-edit functions which follow. */ char * -editWriteToTempFile(vshControl *ctl, const char *doc) +vshEditWriteToTempFile(vshControl *ctl, const char *doc) { char *ret; const char *tmpdir; @@ -554,7 +554,7 @@ editWriteToTempFile(vshControl *ctl, const char *doc) "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-/_.:@"
int -editFile(vshControl *ctl, const char *filename) +vshEditFile(vshControl *ctl, const char *filename) { const char *editor; virCommandPtr cmd; @@ -595,7 +595,7 @@ editFile(vshControl *ctl, const char *filename) virCommandSetErrorFD(cmd,&errfd); if (virCommandRunAsync(cmd, NULL)< 0 || virCommandWait(cmd, NULL)< 0) { - virshReportError(ctl); + vshReportError(ctl); goto cleanup; } ret = 0; @@ -606,11 +606,11 @@ cleanup: }
char * -editReadBackFile(vshControl *ctl, const char *filename) +vshEditReadBackFile(vshControl *ctl, const char *filename) { char *ret;
- if (virFileReadAll(filename, VIRSH_MAX_XML_FILE,&ret) == -1) { + if (virFileReadAll(filename, VSH_MAX_XML_FILE,&ret) == -1) { vshError(ctl, _("%s: failed to read temporary file: %s"), filename, strerror(errno)); @@ -1551,7 +1551,7 @@ vshCommandRun(vshControl *ctl, const vshCmd *cmd) disconnected++;
if (!ret) - virshReportError(ctl); + vshReportError(ctl);
if (!ret&& disconnected != 0) vshReconnect(ctl); @@ -1559,11 +1559,14 @@ vshCommandRun(vshControl *ctl, const vshCmd *cmd) if (STREQ(cmd->def->name, "quit")) /* hack ... */ return ret;
- if (enable_timing) - vshPrint(ctl, _("\n(Time: %.3f ms)\n\n"), - DIFF_MSEC(&after,&before)); - else + if (enable_timing) { + double diff_ms = (((after.tv_sec - before.tv_sec) * 1000000.0) + + ((after.tv_usec - before.tv_usec) / 1000.0)); + + vshPrint(ctl, _("\n(Time: %.3f ms)\n\n"), diff_ms); + } else { vshPrintExtra(ctl, "\n"); + } cmd = cmd->next; } return ret; @@ -2100,7 +2103,7 @@ vshEventLoop(void *opaque) break;
if (virEventRunDefaultImpl()< 0) - virshReportError(ctl); + vshReportError(ctl); } }
@@ -2108,7 +2111,7 @@ vshEventLoop(void *opaque) /* * Initialize connection. */ -bool +static bool vshInit(vshControl *ctl) { char *debugEnv; @@ -2163,7 +2166,7 @@ vshInit(vshControl *ctl) * connection). */ if (!ctl->conn) { - virshReportError(ctl); + vshReportError(ctl); vshError(ctl, "%s", _("failed to connect to the hypervisor")); return false; } @@ -2544,7 +2547,7 @@ vshDeinitTimer(int timer ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED) /* * Deinitialize virsh */ -bool +static bool vshDeinit(vshControl *ctl) { vshReadlineDeinit(ctl); @@ -2583,7 +2586,7 @@ vshDeinit(vshControl *ctl) /* * Print usage */ -void +static void vshUsage(void) { const vshCmdGrp *grp; @@ -2774,7 +2777,7 @@ vshAllowedEscapeChar(char c) * argv[]: virsh [options] [command] * */ -bool +static bool vshParseArgv(vshControl *ctl, int argc, char **argv) { int arg, len, debug; @@ -2915,7 +2918,7 @@ main(int argc, char **argv) ctl->imode = true; /* default is interactive mode */ ctl->log_fd = -1; /* Initialize log file descriptor */ ctl->debug = VSH_DEBUG_DEFAULT; - ctl->escapeChar = CTRL_CLOSE_BRACKET; + ctl->escapeChar = "^]"; /* Same default as telnet */
if (!setlocale(LC_ALL, "")) { diff --git a/tools/virsh.h b/tools/virsh.h index 0b1f123..764369e 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -38,7 +38,7 @@ # include "threads.h" # include "virnetdevbandwidth.h"
-# define VIRSH_MAX_XML_FILE 10*1024*1024 +# define VSH_MAX_XML_FILE (10*1024*1024)
# define VSH_PROMPT_RW "virsh # " # define VSH_PROMPT_RO "virsh> " @@ -46,12 +46,6 @@ # define VIR_FROM_THIS VIR_FROM_NONE
# define GETTIMEOFDAY(T) gettimeofday(T, NULL) -# define DIFF_MSEC(T, U) \ - ((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \ - ((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0) - -/* Default escape char Ctrl-] as per telnet */ -# define CTRL_CLOSE_BRACKET "^]"
/** * The log configuration @@ -253,17 +247,12 @@ struct _vshCmdGrp {
void vshError(vshControl *ctl, const char *format, ...) ATTRIBUTE_FMT_PRINTF(2, 3); -bool vshInit(vshControl *ctl); -bool vshDeinit(vshControl *ctl); -void vshUsage(void); void vshOpenLogFile(vshControl *ctl); void vshOutputLogFile(vshControl *ctl, int log_level, const char *format, va_list ap) ATTRIBUTE_FMT_PRINTF(3, 0); void vshCloseLogFile(vshControl *ctl);
-bool vshParseArgv(vshControl *ctl, int argc, char **argv); - const char *vshCmddefGetInfo(const vshCmdDef *cmd, const char *info); const vshCmdDef *vshCmddefSearch(const char *cmdname); bool vshCmddefHelp(vshControl *ctl, const char *name); @@ -332,13 +321,13 @@ virTypedParameterPtr vshFindTypedParamByName(const char *name, char *vshGetTypedParamValue(vshControl *ctl, virTypedParameterPtr item) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
-char *editWriteToTempFile(vshControl *ctl, const char *doc); -int editFile(vshControl *ctl, const char *filename); -char *editReadBackFile(vshControl *ctl, const char *filename); +char *vshEditWriteToTempFile(vshControl *ctl, const char *doc); +int vshEditFile(vshControl *ctl, const char *filename); +char *vshEditReadBackFile(vshControl *ctl, const char *filename); int vshAskReedit(vshControl *ctl, const char *msg); int vshStreamSink(virStreamPtr st, const char *bytes, size_t nbytes, void *opaque); -double prettyCapacity(unsigned long long val, const char **unit); +double vshPrettyCapacity(unsigned long long val, const char **unit);
/* Typedefs, function prototypes for job progress reporting. * There are used by some long lingering commands like @@ -350,12 +339,9 @@ struct _vshCtrlData { int writefd; };
-typedef void (*jobWatchTimeoutFunc) (vshControl *ctl, virDomainPtr dom, - void *opaque); - /* error handling */ extern virErrorPtr last_error; -void virshReportError(vshControl *ctl); +void vshReportError(vshControl *ctl); void vshResetLibvirtError(void);
/* allocation wrappers */
ACK.