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;
}
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;
}

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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 {

View File

@ -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);

View File

@ -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();

View File

@ -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) {

View File

@ -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, "")) {

View File

@ -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 */