virsh: use common namespacing

Convert the exported items in virsh.h to use a common 'vsh' prefix.

* tools/virsh.h (VIRSH_MAX_XML_FILE): 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.
This commit is contained in:
Eric Blake
2012-08-18 22:10:17 -06:00
parent 5435f17ed6
commit e68ee5e765
12 changed files with 98 additions and 105 deletions

View File

@@ -105,8 +105,8 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd)
return false; return false;
} }
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) { if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
virshReportError(ctl); vshReportError(ctl);
virDomainFree(dom); virDomainFree(dom);
return false; return false;
} }
@@ -2544,7 +2544,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
goto cleanup; goto cleanup;
} }
if (virDomainManagedSaveRemove(dom, 0) < 0) { if (virDomainManagedSaveRemove(dom, 0) < 0) {
virshReportError(ctl); vshReportError(ctl);
goto cleanup; goto cleanup;
} }
} }
@@ -2618,7 +2618,7 @@ cleanup:
return ret; return ret;
error: error:
virshReportError(ctl); vshReportError(ctl);
goto cleanup; goto cleanup;
} }
@@ -2687,7 +2687,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd)
goto started; goto started;
if (last_error->code != VIR_ERR_NO_SUPPORT && if (last_error->code != VIR_ERR_NO_SUPPORT &&
last_error->code != VIR_ERR_INVALID_ARG) { last_error->code != VIR_ERR_INVALID_ARG) {
virshReportError(ctl); vshReportError(ctl);
goto cleanup; goto cleanup;
} }
vshResetLibvirtError(); vshResetLibvirtError();
@@ -2697,7 +2697,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd)
vshResetLibvirtError(); vshResetLibvirtError();
} else if (rc > 0) { } else if (rc > 0) {
if (virDomainManagedSaveRemove(dom, 0) < 0) { if (virDomainManagedSaveRemove(dom, 0) < 0) {
virshReportError(ctl); vshReportError(ctl);
goto cleanup; goto cleanup;
} }
} }
@@ -2809,6 +2809,9 @@ out_sig:
ignore_value(safewrite(data->writefd, &ret, sizeof(ret))); ignore_value(safewrite(data->writefd, &ret, sizeof(ret)));
} }
typedef void (*jobWatchTimeoutFunc) (vshControl *ctl, virDomainPtr dom,
void *opaque);
static bool static bool
vshWatchJob(vshControl *ctl, vshWatchJob(vshControl *ctl,
virDomainPtr dom, virDomainPtr dom,
@@ -4088,27 +4091,27 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd)
if (info.type == VIR_DOMAIN_JOB_BOUNDED) if (info.type == VIR_DOMAIN_JOB_BOUNDED)
vshPrint(ctl, "%-17s %-12llu ms\n", _("Time remaining:"), info.timeRemaining); vshPrint(ctl, "%-17s %-12llu ms\n", _("Time remaining:"), info.timeRemaining);
if (info.dataTotal || info.dataRemaining || info.dataProcessed) { 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); 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); 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); vshPrint(ctl, "%-17s %-.3lf %s\n", _("Data total:"), val, unit);
} }
if (info.memTotal || info.memRemaining || info.memProcessed) { 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); 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); 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); vshPrint(ctl, "%-17s %-.3lf %s\n", _("Memory total:"), val, unit);
} }
if (info.fileTotal || info.fileRemaining || info.fileProcessed) { 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); 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); 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); vshPrint(ctl, "%-17s %-.3lf %s\n", _("File total:"), val, unit);
} }
} else { } else {
@@ -4275,7 +4278,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd)
count = virDomainGetVcpusFlags(dom, count = virDomainGetVcpusFlags(dom,
maximum ? VIR_DOMAIN_VCPU_MAXIMUM : 0); maximum ? VIR_DOMAIN_VCPU_MAXIMUM : 0);
if (count < 0) { if (count < 0) {
virshReportError(ctl); vshReportError(ctl);
ret = false; ret = false;
} else { } else {
vshPrint(ctl, "%d\n", count); vshPrint(ctl, "%d\n", count);
@@ -4299,7 +4302,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd)
} }
if (count < 0) { if (count < 0) {
virshReportError(ctl); vshReportError(ctl);
ret = false; ret = false;
} else if (all) { } else if (all) {
vshPrint(ctl, "%-12s %-12s %3d\n", _("maximum"), _("config"), vshPrint(ctl, "%-12s %-12s %3d\n", _("maximum"), _("config"),
@@ -4319,7 +4322,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd)
} }
if (count < 0) { if (count < 0) {
virshReportError(ctl); vshReportError(ctl);
ret = false; ret = false;
} else if (all) { } else if (all) {
vshPrint(ctl, "%-12s %-12s %3d\n", _("maximum"), _("live"), vshPrint(ctl, "%-12s %-12s %3d\n", _("maximum"), _("live"),
@@ -4355,7 +4358,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd)
} }
if (count < 0) { if (count < 0) {
virshReportError(ctl); vshReportError(ctl);
ret = false; ret = false;
} else if (all) { } else if (all) {
vshPrint(ctl, "%-12s %-12s %3d\n", _("current"), _("config"), vshPrint(ctl, "%-12s %-12s %3d\n", _("current"), _("config"),
@@ -4376,7 +4379,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd)
} }
if (count < 0) { if (count < 0) {
virshReportError(ctl); vshReportError(ctl);
ret = false; ret = false;
} else if (all) { } else if (all) {
vshPrint(ctl, "%-12s %-12s %3d\n", _("current"), _("live"), vshPrint(ctl, "%-12s %-12s %3d\n", _("current"), _("live"),
@@ -4869,7 +4872,7 @@ cmdCPUCompare(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptString(cmd, "file", &from) <= 0) if (vshCommandOptString(cmd, "file", &from) <= 0)
return false; 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"), vshError(ctl, _("Failed to read file '%s' to compare"),
from); from);
return false; return false;
@@ -4972,7 +4975,7 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptString(cmd, "file", &from) <= 0) if (vshCommandOptString(cmd, "file", &from) <= 0)
return false; return false;
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false; return false;
/* add a separate container around the xml */ /* add a separate container around the xml */
@@ -5234,7 +5237,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptString(cmd, "file", &from) <= 0) if (vshCommandOptString(cmd, "file", &from) <= 0)
return false; return false;
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false; return false;
if (vshCommandOptBool(cmd, "paused")) if (vshCommandOptBool(cmd, "paused"))
@@ -5288,7 +5291,7 @@ cmdDefine(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptString(cmd, "file", &from) <= 0) if (vshCommandOptString(cmd, "file", &from) <= 0)
return false; return false;
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false; return false;
dom = virDomainDefineXML(ctl->conn, buffer); dom = virDomainDefineXML(ctl->conn, buffer);
@@ -5448,15 +5451,15 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
if (edit) { if (edit) {
/* Create and open the temporary file. */ /* Create and open the temporary file. */
if (!(tmp = editWriteToTempFile(ctl, desc))) if (!(tmp = vshEditWriteToTempFile(ctl, desc)))
goto cleanup; goto cleanup;
/* Start the editor. */ /* Start the editor. */
if (editFile(ctl, tmp) == -1) if (vshEditFile(ctl, tmp) == -1)
goto cleanup; goto cleanup;
/* Read back the edited file. */ /* Read back the edited file. */
if (!(desc_edited = editReadBackFile(ctl, tmp))) if (!(desc_edited = vshEditReadBackFile(ctl, tmp)))
goto cleanup; goto cleanup;
/* strip a possible newline at the end of file; some /* 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) if (vshCommandOptString(cmd, "file", &from) <= 0)
goto cleanup; goto cleanup;
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) { if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
virshReportError(ctl); vshReportError(ctl);
goto cleanup; goto cleanup;
} }
@@ -7434,8 +7437,8 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd)
return false; return false;
} }
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) { if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
virshReportError(ctl); vshReportError(ctl);
virDomainFree(dom); virDomainFree(dom);
return false; return false;
} }

View File

@@ -75,17 +75,17 @@ do {
goto edit_cleanup; goto edit_cleanup;
/* Create and open the temporary file. */ /* Create and open the temporary file. */
tmp = editWriteToTempFile(ctl, doc); tmp = vshEditWriteToTempFile(ctl, doc);
if (!tmp) if (!tmp)
goto edit_cleanup; goto edit_cleanup;
reedit: reedit:
/* Start the editor. */ /* Start the editor. */
if (editFile(ctl, tmp) == -1) if (vshEditFile(ctl, tmp) == -1)
goto edit_cleanup; goto edit_cleanup;
/* Read back the edited file. */ /* Read back the edited file. */
doc_edited = editReadBackFile(ctl, tmp); doc_edited = vshEditReadBackFile(ctl, tmp);
if (!doc_edited) if (!doc_edited)
goto edit_cleanup; goto edit_cleanup;

View File

@@ -369,7 +369,7 @@ cmdInterfaceDefine(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptString(cmd, "file", &from) <= 0) if (vshCommandOptString(cmd, "file", &from) <= 0)
return false; return false;
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false; return false;
iface = virInterfaceDefineXML(ctl->conn, buffer, 0); iface = virInterfaceDefineXML(ctl->conn, buffer, 0);

View File

@@ -143,7 +143,7 @@ cmdNetworkCreate(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptString(cmd, "file", &from) <= 0) if (vshCommandOptString(cmd, "file", &from) <= 0)
return false; return false;
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false; return false;
network = virNetworkCreateXML(ctl->conn, buffer); network = virNetworkCreateXML(ctl->conn, buffer);
@@ -188,7 +188,7 @@ cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptString(cmd, "file", &from) <= 0) if (vshCommandOptString(cmd, "file", &from) <= 0)
return false; return false;
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false; return false;
network = virNetworkDefineXML(ctl->conn, buffer); network = virNetworkDefineXML(ctl->conn, buffer);

View File

@@ -55,7 +55,7 @@ cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptString(cmd, "file", &from) <= 0) if (vshCommandOptString(cmd, "file", &from) <= 0)
return false; return false;
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false; return false;
dev = virNodeDeviceCreateXML(ctl->conn, buffer, 0); dev = virNodeDeviceCreateXML(ctl->conn, buffer, 0);

View File

@@ -94,7 +94,7 @@ cmdNWFilterDefine(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptString(cmd, "file", &from) <= 0) if (vshCommandOptString(cmd, "file", &from) <= 0)
return false; return false;
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false; return false;
nwfilter = virNWFilterDefineXML(ctl->conn, buffer); nwfilter = virNWFilterDefineXML(ctl->conn, buffer);

View File

@@ -141,7 +141,7 @@ cmdPoolCreate(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptString(cmd, "file", &from) <= 0) if (vshCommandOptString(cmd, "file", &from) <= 0)
return false; return false;
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false; return false;
pool = virStoragePoolCreateXML(ctl->conn, buffer, 0); pool = virStoragePoolCreateXML(ctl->conn, buffer, 0);
@@ -303,7 +303,7 @@ cmdPoolDefine(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptString(cmd, "file", &from) <= 0) if (vshCommandOptString(cmd, "file", &from) <= 0)
return false; return false;
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false; return false;
pool = virStoragePoolDefineXML(ctl->conn, buffer, 0); pool = virStoragePoolDefineXML(ctl->conn, buffer, 0);
@@ -748,7 +748,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
const char *unit; const char *unit;
/* Create the capacity output string */ /* Create the capacity output string */
val = prettyCapacity(info.capacity, &unit); val = vshPrettyCapacity(info.capacity, &unit);
ret = virAsprintf(&poolInfoTexts[i].capacity, ret = virAsprintf(&poolInfoTexts[i].capacity,
"%.2lf %s", val, unit); "%.2lf %s", val, unit);
if (ret < 0) { if (ret < 0) {
@@ -757,7 +757,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
} }
/* Create the allocation output string */ /* Create the allocation output string */
val = prettyCapacity(info.allocation, &unit); val = vshPrettyCapacity(info.allocation, &unit);
ret = virAsprintf(&poolInfoTexts[i].allocation, ret = virAsprintf(&poolInfoTexts[i].allocation,
"%.2lf %s", val, unit); "%.2lf %s", val, unit);
if (ret < 0) { if (ret < 0) {
@@ -766,7 +766,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
} }
/* Create the available space output string */ /* Create the available space output string */
val = prettyCapacity(info.available, &unit); val = vshPrettyCapacity(info.available, &unit);
ret = virAsprintf(&poolInfoTexts[i].available, ret = virAsprintf(&poolInfoTexts[i].available,
"%.2lf %s", val, unit); "%.2lf %s", val, unit);
if (ret < 0) { if (ret < 0) {
@@ -1090,7 +1090,8 @@ cmdPoolDiscoverSources(vshControl * ctl, const vshCmd * cmd ATTRIBUTE_UNUSED)
if (!vshConnectionUsability(ctl, ctl->conn)) if (!vshConnectionUsability(ctl, ctl->conn))
return false; return false;
if (srcSpecFile && virFileReadAll(srcSpecFile, VIRSH_MAX_XML_FILE, &srcSpec) < 0) if (srcSpecFile && virFileReadAll(srcSpecFile, VSH_MAX_XML_FILE,
&srcSpec) < 0)
return false; return false;
srcList = virConnectFindStoragePoolSources(ctl->conn, type, srcSpec, 0); srcList = virConnectFindStoragePoolSources(ctl->conn, type, srcSpec, 0);
@@ -1186,13 +1187,13 @@ cmdPoolInfo(vshControl *ctl, const vshCmd *cmd)
if (info.state == VIR_STORAGE_POOL_RUNNING || if (info.state == VIR_STORAGE_POOL_RUNNING ||
info.state == VIR_STORAGE_POOL_DEGRADED) { 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); 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); 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); vshPrint(ctl, "%-15s %2.2lf %s\n", _("Available:"), val, unit);
} }
} else { } else {

View File

@@ -78,7 +78,7 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptString(cmd, "file", &from) <= 0) if (vshCommandOptString(cmd, "file", &from) <= 0)
return false; return false;
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false; return false;
res = virSecretDefineXML(ctl->conn, buffer, 0); res = virSecretDefineXML(ctl->conn, buffer, 0);

View File

@@ -46,7 +46,7 @@ vshSnapshotCreate(vshControl *ctl, virDomainPtr dom, const char *buffer,
vshResetLibvirtError(); vshResetLibvirtError();
persistent = virDomainIsPersistent(dom); persistent = virDomainIsPersistent(dom);
if (persistent < 0) { if (persistent < 0) {
virshReportError(ctl); vshReportError(ctl);
goto cleanup; goto cleanup;
} }
if (!persistent) { if (!persistent) {
@@ -64,7 +64,7 @@ vshSnapshotCreate(vshControl *ctl, virDomainPtr dom, const char *buffer,
goto cleanup; goto cleanup;
if (halt && virDomainDestroy(dom) < 0) { if (halt && virDomainDestroy(dom) < 0) {
virshReportError(ctl); vshReportError(ctl);
goto cleanup; goto cleanup;
} }
@@ -149,12 +149,12 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptString(cmd, "xmlfile", &from) <= 0) if (vshCommandOptString(cmd, "xmlfile", &from) <= 0)
buffer = vshStrdup(ctl, "<domainsnapshot/>"); buffer = vshStrdup(ctl, "<domainsnapshot/>");
else { 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 have to report the error here because during cleanup
* we'll run through virDomainFree(), which loses the * we'll run through virDomainFree(), which loses the
* last error * last error
*/ */
virshReportError(ctl); vshReportError(ctl);
goto cleanup; goto cleanup;
} }
} }
@@ -362,7 +362,7 @@ vshLookupSnapshot(vshControl *ctl, const vshCmd *cmd,
return -1; return -1;
} }
if (!*snap) { if (!*snap) {
virshReportError(ctl); vshReportError(ctl);
return -1; return -1;
} }
@@ -455,7 +455,7 @@ cmdSnapshotEdit(vshControl *ctl, const vshCmd *cmd)
delete_flags = VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY; delete_flags = VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY;
if (virDomainSnapshotDelete(rename_okay ? snapshot : edited, if (virDomainSnapshotDelete(rename_okay ? snapshot : edited,
delete_flags) < 0) { delete_flags) < 0) {
virshReportError(ctl); vshReportError(ctl);
vshError(ctl, _("Failed to clean up %s"), vshError(ctl, _("Failed to clean up %s"),
rename_okay ? name : edited_name); rename_okay ? name : edited_name);
goto cleanup; goto cleanup;
@@ -583,7 +583,7 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd)
cleanup: cleanup:
if (!ret) if (!ret)
virshReportError(ctl); vshReportError(ctl);
VIR_FREE(xml); VIR_FREE(xml);
if (snapshot) if (snapshot)
virDomainSnapshotFree(snapshot); virDomainSnapshotFree(snapshot);
@@ -640,7 +640,7 @@ vshGetSnapshotParent(vshControl *ctl, virDomainSnapshotPtr snapshot,
cleanup: cleanup:
if (ret < 0) { if (ret < 0) {
virshReportError(ctl); vshReportError(ctl);
vshError(ctl, "%s", _("unable to determine if snapshot has parent")); vshError(ctl, "%s", _("unable to determine if snapshot has parent"));
} else { } else {
vshResetLibvirtError(); vshResetLibvirtError();

View File

@@ -300,8 +300,8 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd)
return false; return false;
} }
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) { if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
virshReportError(ctl); vshReportError(ctl);
virStoragePoolFree(pool); virStoragePoolFree(pool);
return false; return false;
} }
@@ -360,8 +360,8 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd)
if (!(inputvol = vshCommandOptVol(ctl, cmd, "vol", "inputpool", NULL))) if (!(inputvol = vshCommandOptVol(ctl, cmd, "vol", "inputpool", NULL)))
goto cleanup; goto cleanup;
if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) { if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
virshReportError(ctl); vshReportError(ctl);
goto cleanup; goto cleanup;
} }
@@ -847,10 +847,10 @@ cmdVolInfo(vshControl *ctl, const vshCmd *cmd)
vshPrint(ctl, "%-15s %s\n", _("Type:"), _("unknown")); 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); 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); vshPrint(ctl, "%-15s %2.2lf %s\n", _("Allocation:"), val, unit);
} else { } else {
ret = false; ret = false;
@@ -1098,7 +1098,7 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
} }
/* Create the capacity output string */ /* Create the capacity output string */
val = prettyCapacity(volumeInfo.capacity, &unit); val = vshPrettyCapacity(volumeInfo.capacity, &unit);
ret = virAsprintf(&volInfoTexts[i].capacity, ret = virAsprintf(&volInfoTexts[i].capacity,
"%.2lf %s", val, unit); "%.2lf %s", val, unit);
if (ret < 0) { if (ret < 0) {
@@ -1107,7 +1107,7 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
} }
/* Create the allocation output string */ /* Create the allocation output string */
val = prettyCapacity(volumeInfo.allocation, &unit); val = vshPrettyCapacity(volumeInfo.allocation, &unit);
ret = virAsprintf(&volInfoTexts[i].allocation, ret = virAsprintf(&volInfoTexts[i].allocation,
"%.2lf %s", val, unit); "%.2lf %s", val, unit);
if (ret < 0) { if (ret < 0) {

View File

@@ -140,7 +140,7 @@ vshNameSorter(const void *a, const void *b)
} }
double double
prettyCapacity(unsigned long long val, const char **unit) vshPrettyCapacity(unsigned long long val, const char **unit)
{ {
if (val < 1024) { if (val < 1024) {
*unit = ""; *unit = "";
@@ -194,7 +194,7 @@ vshResetLibvirtError(void)
* and it's IMHO a bug that libvirt does that sometimes. * and it's IMHO a bug that libvirt does that sometimes.
*/ */
void void
virshReportError(vshControl *ctl) vshReportError(vshControl *ctl)
{ {
if (last_error == NULL) { if (last_error == NULL) {
/* Calling directly into libvirt util functions won't trigger the /* Calling directly into libvirt util functions won't trigger the
@@ -312,7 +312,7 @@ vshAskReedit(vshControl *ctl, const char *msg)
if (!isatty(STDIN_FILENO)) if (!isatty(STDIN_FILENO))
return -1; return -1;
virshReportError(ctl); vshReportError(ctl);
if (vshMakeStdinRaw(&ttyattr, false) < 0) if (vshMakeStdinRaw(&ttyattr, false) < 0)
return -1; 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. */ /* Common code for the edit / net-edit / pool-edit functions which follow. */
char * char *
editWriteToTempFile(vshControl *ctl, const char *doc) vshEditWriteToTempFile(vshControl *ctl, const char *doc)
{ {
char *ret; char *ret;
const char *tmpdir; const char *tmpdir;
@@ -554,7 +554,7 @@ editWriteToTempFile(vshControl *ctl, const char *doc)
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-/_.:@" "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-/_.:@"
int int
editFile(vshControl *ctl, const char *filename) vshEditFile(vshControl *ctl, const char *filename)
{ {
const char *editor; const char *editor;
virCommandPtr cmd; virCommandPtr cmd;
@@ -595,7 +595,7 @@ editFile(vshControl *ctl, const char *filename)
virCommandSetErrorFD(cmd, &errfd); virCommandSetErrorFD(cmd, &errfd);
if (virCommandRunAsync(cmd, NULL) < 0 || if (virCommandRunAsync(cmd, NULL) < 0 ||
virCommandWait(cmd, NULL) < 0) { virCommandWait(cmd, NULL) < 0) {
virshReportError(ctl); vshReportError(ctl);
goto cleanup; goto cleanup;
} }
ret = 0; ret = 0;
@@ -606,11 +606,11 @@ cleanup:
} }
char * char *
editReadBackFile(vshControl *ctl, const char *filename) vshEditReadBackFile(vshControl *ctl, const char *filename)
{ {
char *ret; char *ret;
if (virFileReadAll(filename, VIRSH_MAX_XML_FILE, &ret) == -1) { if (virFileReadAll(filename, VSH_MAX_XML_FILE, &ret) == -1) {
vshError(ctl, vshError(ctl,
_("%s: failed to read temporary file: %s"), _("%s: failed to read temporary file: %s"),
filename, strerror(errno)); filename, strerror(errno));
@@ -1551,7 +1551,7 @@ vshCommandRun(vshControl *ctl, const vshCmd *cmd)
disconnected++; disconnected++;
if (!ret) if (!ret)
virshReportError(ctl); vshReportError(ctl);
if (!ret && disconnected != 0) if (!ret && disconnected != 0)
vshReconnect(ctl); vshReconnect(ctl);
@@ -1559,11 +1559,14 @@ vshCommandRun(vshControl *ctl, const vshCmd *cmd)
if (STREQ(cmd->def->name, "quit")) /* hack ... */ if (STREQ(cmd->def->name, "quit")) /* hack ... */
return ret; return ret;
if (enable_timing) if (enable_timing) {
vshPrint(ctl, _("\n(Time: %.3f ms)\n\n"), double diff_ms = (((after.tv_sec - before.tv_sec) * 1000000.0) +
DIFF_MSEC(&after, &before)); ((after.tv_usec - before.tv_usec) / 1000.0));
else
vshPrint(ctl, _("\n(Time: %.3f ms)\n\n"), diff_ms);
} else {
vshPrintExtra(ctl, "\n"); vshPrintExtra(ctl, "\n");
}
cmd = cmd->next; cmd = cmd->next;
} }
return ret; return ret;
@@ -2100,7 +2103,7 @@ vshEventLoop(void *opaque)
break; break;
if (virEventRunDefaultImpl() < 0) if (virEventRunDefaultImpl() < 0)
virshReportError(ctl); vshReportError(ctl);
} }
} }
@@ -2108,7 +2111,7 @@ vshEventLoop(void *opaque)
/* /*
* Initialize connection. * Initialize connection.
*/ */
bool static bool
vshInit(vshControl *ctl) vshInit(vshControl *ctl)
{ {
char *debugEnv; char *debugEnv;
@@ -2163,7 +2166,7 @@ vshInit(vshControl *ctl)
* connection). * connection).
*/ */
if (!ctl->conn) { if (!ctl->conn) {
virshReportError(ctl); vshReportError(ctl);
vshError(ctl, "%s", _("failed to connect to the hypervisor")); vshError(ctl, "%s", _("failed to connect to the hypervisor"));
return false; return false;
} }
@@ -2544,7 +2547,7 @@ vshDeinitTimer(int timer ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED)
/* /*
* Deinitialize virsh * Deinitialize virsh
*/ */
bool static bool
vshDeinit(vshControl *ctl) vshDeinit(vshControl *ctl)
{ {
vshReadlineDeinit(ctl); vshReadlineDeinit(ctl);
@@ -2583,7 +2586,7 @@ vshDeinit(vshControl *ctl)
/* /*
* Print usage * Print usage
*/ */
void static void
vshUsage(void) vshUsage(void)
{ {
const vshCmdGrp *grp; const vshCmdGrp *grp;
@@ -2774,7 +2777,7 @@ vshAllowedEscapeChar(char c)
* argv[]: virsh [options] [command] * argv[]: virsh [options] [command]
* *
*/ */
bool static bool
vshParseArgv(vshControl *ctl, int argc, char **argv) vshParseArgv(vshControl *ctl, int argc, char **argv)
{ {
int arg, len, debug; int arg, len, debug;
@@ -2915,7 +2918,7 @@ main(int argc, char **argv)
ctl->imode = true; /* default is interactive mode */ ctl->imode = true; /* default is interactive mode */
ctl->log_fd = -1; /* Initialize log file descriptor */ ctl->log_fd = -1; /* Initialize log file descriptor */
ctl->debug = VSH_DEBUG_DEFAULT; ctl->debug = VSH_DEBUG_DEFAULT;
ctl->escapeChar = CTRL_CLOSE_BRACKET; ctl->escapeChar = "^]"; /* Same default as telnet */
if (!setlocale(LC_ALL, "")) { if (!setlocale(LC_ALL, "")) {

View File

@@ -38,7 +38,7 @@
# include "threads.h" # include "threads.h"
# include "virnetdevbandwidth.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_RW "virsh # "
# define VSH_PROMPT_RO "virsh > " # define VSH_PROMPT_RO "virsh > "
@@ -46,12 +46,6 @@
# define VIR_FROM_THIS VIR_FROM_NONE # define VIR_FROM_THIS VIR_FROM_NONE
# define GETTIMEOFDAY(T) gettimeofday(T, NULL) # 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 * The log configuration
@@ -253,17 +247,12 @@ struct _vshCmdGrp {
void vshError(vshControl *ctl, const char *format, ...) void vshError(vshControl *ctl, const char *format, ...)
ATTRIBUTE_FMT_PRINTF(2, 3); ATTRIBUTE_FMT_PRINTF(2, 3);
bool vshInit(vshControl *ctl);
bool vshDeinit(vshControl *ctl);
void vshUsage(void);
void vshOpenLogFile(vshControl *ctl); void vshOpenLogFile(vshControl *ctl);
void vshOutputLogFile(vshControl *ctl, int log_level, const char *format, void vshOutputLogFile(vshControl *ctl, int log_level, const char *format,
va_list ap) va_list ap)
ATTRIBUTE_FMT_PRINTF(3, 0); ATTRIBUTE_FMT_PRINTF(3, 0);
void vshCloseLogFile(vshControl *ctl); void vshCloseLogFile(vshControl *ctl);
bool vshParseArgv(vshControl *ctl, int argc, char **argv);
const char *vshCmddefGetInfo(const vshCmdDef *cmd, const char *info); const char *vshCmddefGetInfo(const vshCmdDef *cmd, const char *info);
const vshCmdDef *vshCmddefSearch(const char *cmdname); const vshCmdDef *vshCmddefSearch(const char *cmdname);
bool vshCmddefHelp(vshControl *ctl, const char *name); bool vshCmddefHelp(vshControl *ctl, const char *name);
@@ -332,13 +321,13 @@ virTypedParameterPtr vshFindTypedParamByName(const char *name,
char *vshGetTypedParamValue(vshControl *ctl, virTypedParameterPtr item) char *vshGetTypedParamValue(vshControl *ctl, virTypedParameterPtr item)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
char *editWriteToTempFile(vshControl *ctl, const char *doc); char *vshEditWriteToTempFile(vshControl *ctl, const char *doc);
int editFile(vshControl *ctl, const char *filename); int vshEditFile(vshControl *ctl, const char *filename);
char *editReadBackFile(vshControl *ctl, const char *filename); char *vshEditReadBackFile(vshControl *ctl, const char *filename);
int vshAskReedit(vshControl *ctl, const char *msg); int vshAskReedit(vshControl *ctl, const char *msg);
int vshStreamSink(virStreamPtr st, const char *bytes, size_t nbytes, int vshStreamSink(virStreamPtr st, const char *bytes, size_t nbytes,
void *opaque); 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. /* Typedefs, function prototypes for job progress reporting.
* There are used by some long lingering commands like * There are used by some long lingering commands like
@@ -350,12 +339,9 @@ struct _vshCtrlData {
int writefd; int writefd;
}; };
typedef void (*jobWatchTimeoutFunc) (vshControl *ctl, virDomainPtr dom,
void *opaque);
/* error handling */ /* error handling */
extern virErrorPtr last_error; extern virErrorPtr last_error;
void virshReportError(vshControl *ctl); void vshReportError(vshControl *ctl);
void vshResetLibvirtError(void); void vshResetLibvirtError(void);
/* allocation wrappers */ /* allocation wrappers */