提交 834c5720 编写于 作者: E Erik Skultety

tools: Introduce new client generic module vsh

In order to share as much virsh' logic as possible with upcomming
virt-admin client we need to split virsh logic into virsh specific and
client generic features.

Since majority of virsh methods should be generic enough to be used by
other clients, it's much easier to rename virsh specific data to virshX
than doing this vice versa. It moved generic virsh commands (including info
and opts structures) to generic module vsh.c.

Besides renaming methods and structures, this patch also involves introduction
of a client specific control structure being referenced as private data in the
original control structure, introduction of a new global vsh Initializer,
which currently doesn't do much, but there is a potential for added
functionality in the future.
Lastly it introduced client hooks which are especially necessary during
client connecting phase.
上级 b5d63e99
...@@ -1086,7 +1086,7 @@ $(srcdir)/src/admin/admin_client.h: $(srcdir)/src/admin/admin_protocol.x ...@@ -1086,7 +1086,7 @@ $(srcdir)/src/admin/admin_client.h: $(srcdir)/src/admin/admin_protocol.x
$(MAKE) -C src admin/admin_client.h $(MAKE) -C src admin/admin_client.h
# List all syntax-check exemptions: # List all syntax-check exemptions:
exclude_file_name_regexp--sc_avoid_strcase = ^tools/virsh\.h$$ exclude_file_name_regexp--sc_avoid_strcase = ^tools/vsh\.h$$
_src1=libvirt-stream|fdstream|qemu/qemu_monitor|util/(vircommand|virfile)|xen/xend_internal|rpc/virnetsocket|lxc/lxc_controller|locking/lock_daemon _src1=libvirt-stream|fdstream|qemu/qemu_monitor|util/(vircommand|virfile)|xen/xend_internal|rpc/virnetsocket|lxc/lxc_controller|locking/lock_daemon
_test1=shunloadtest|virnettlscontexttest|virnettlssessiontest|vircgroupmock _test1=shunloadtest|virnettlscontexttest|virnettlssessiontest|vircgroupmock
......
...@@ -258,7 +258,6 @@ src/xenconfig/xen_xm.c ...@@ -258,7 +258,6 @@ src/xenconfig/xen_xm.c
tests/virpolkittest.c tests/virpolkittest.c
tools/libvirt-guests.sh.in tools/libvirt-guests.sh.in
tools/virsh.c tools/virsh.c
tools/virsh.h
tools/virsh-console.c tools/virsh-console.c
tools/virsh-domain-monitor.c tools/virsh-domain-monitor.c
tools/virsh-domain.c tools/virsh-domain.c
...@@ -277,3 +276,5 @@ tools/virt-host-validate-lxc.c ...@@ -277,3 +276,5 @@ tools/virt-host-validate-lxc.c
tools/virt-host-validate-qemu.c tools/virt-host-validate-qemu.c
tools/virt-host-validate.c tools/virt-host-validate.c
tools/virt-login-shell.c tools/virt-login-shell.c
tools/vsh.c
tools/vsh.h
...@@ -2189,6 +2189,7 @@ virStringSplit; ...@@ -2189,6 +2189,7 @@ virStringSplit;
virStringSplitCount; virStringSplitCount;
virStringStripControlChars; virStringStripControlChars;
virStringStripIPv6Brackets; virStringStripIPv6Brackets;
virStringToUpper;
virStrncpy; virStrncpy;
virStrndup; virStrndup;
virStrToDouble; virStrToDouble;
......
...@@ -1020,3 +1020,35 @@ virStringStripControlChars(char *str) ...@@ -1020,3 +1020,35 @@ virStringStripControlChars(char *str)
} }
str[j] = '\0'; str[j] = '\0';
} }
/**
* virStringToUpper:
* @str: string to capitalize
* @dst: where to store the new capitalized string
*
* Capitalize the string with replacement of all '-' characters for '_'
* characters. Caller frees the result.
*
* Returns 0 if src is NULL, 1 if capitalization was successfull, -1 on failure.
*/
int
virStringToUpper(char **dst, const char *src)
{
char *cap = NULL;
size_t i;
if (!src)
return 0;
if (VIR_ALLOC_N(cap, strlen(src) + 1) < 0)
return -1;
for (i = 0; src[i]; i++) {
cap[i] = c_toupper(src[i]);
if (cap[i] == '-')
cap[i] = '_';
}
*dst = cap;
return 1;
}
...@@ -258,6 +258,7 @@ size_t virStringListLength(char **strings); ...@@ -258,6 +258,7 @@ size_t virStringListLength(char **strings);
int virStringSortCompare(const void *a, const void *b); int virStringSortCompare(const void *a, const void *b);
int virStringSortRevCompare(const void *a, const void *b); int virStringSortRevCompare(const void *a, const void *b);
int virStringToUpper(char **dst, const char *src);
ssize_t virStringSearch(const char *str, ssize_t virStringSearch(const char *str,
const char *regexp, const char *regexp,
......
...@@ -179,7 +179,11 @@ virt_login_shell_CFLAGS = \ ...@@ -179,7 +179,11 @@ virt_login_shell_CFLAGS = \
$(PIE_CFLAGS) \ $(PIE_CFLAGS) \
$(COVERAGE_CFLAGS) $(COVERAGE_CFLAGS)
virt_shell_SOURCES = \
vsh.c vsh.h
virsh_SOURCES = \ virsh_SOURCES = \
$(virt_shell_SOURCES) \
virsh.c virsh.h \ virsh.c virsh.h \
virsh-console.c virsh-console.h \ virsh-console.c virsh-console.h \
virsh-domain.c virsh-domain.h \ virsh-domain.c virsh-domain.h \
......
...@@ -295,7 +295,7 @@ virConsoleEventOnStdout(int watch ATTRIBUTE_UNUSED, ...@@ -295,7 +295,7 @@ virConsoleEventOnStdout(int watch ATTRIBUTE_UNUSED,
static char static char
vshGetEscapeChar(const char *s) virshGetEscapeChar(const char *s)
{ {
if (*s == '^') if (*s == '^')
return CONTROL(c_toupper(s[1])); return CONTROL(c_toupper(s[1]));
...@@ -305,12 +305,13 @@ vshGetEscapeChar(const char *s) ...@@ -305,12 +305,13 @@ vshGetEscapeChar(const char *s)
int int
vshRunConsole(vshControl *ctl, virshRunConsole(vshControl *ctl,
virDomainPtr dom, virDomainPtr dom,
const char *dev_name, const char *dev_name,
unsigned int flags) unsigned int flags)
{ {
virConsolePtr con = NULL; virConsolePtr con = NULL;
virshControlPtr priv = ctl->privData;
int ret = -1; int ret = -1;
struct sigaction old_sigquit; struct sigaction old_sigquit;
...@@ -341,7 +342,7 @@ vshRunConsole(vshControl *ctl, ...@@ -341,7 +342,7 @@ vshRunConsole(vshControl *ctl,
if (VIR_ALLOC(con) < 0) if (VIR_ALLOC(con) < 0)
goto cleanup; goto cleanup;
con->escapeChar = vshGetEscapeChar(ctl->escapeChar); con->escapeChar = virshGetEscapeChar(priv->escapeChar);
con->st = virStreamNew(virDomainGetConnect(dom), con->st = virStreamNew(virDomainGetConnect(dom),
VIR_STREAM_NONBLOCK); VIR_STREAM_NONBLOCK);
if (!con->st) if (!con->st)
......
...@@ -28,10 +28,10 @@ ...@@ -28,10 +28,10 @@
# include <virsh.h> # include <virsh.h>
int vshRunConsole(vshControl *ctl, int virshRunConsole(vshControl *ctl,
virDomainPtr dom, virDomainPtr dom,
const char *dev_name, const char *dev_name,
unsigned int flags); unsigned int flags);
# endif /* !WIN32 */ # endif /* !WIN32 */
......
此差异已折叠。
...@@ -28,8 +28,8 @@ ...@@ -28,8 +28,8 @@
# include "virsh.h" # include "virsh.h"
char *vshGetDomainDescription(vshControl *ctl, virDomainPtr dom, char *virshGetDomainDescription(vshControl *ctl, virDomainPtr dom,
bool title, unsigned int flags) bool title, unsigned int flags)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
extern const vshCmdDef domMonitoringCmds[]; extern const vshCmdDef domMonitoringCmds[];
......
此差异已折叠。
...@@ -28,16 +28,17 @@ ...@@ -28,16 +28,17 @@
# include "virsh.h" # include "virsh.h"
virDomainPtr vshLookupDomainBy(vshControl *ctl, virDomainPtr virshLookupDomainBy(vshControl *ctl,
const char *name, const char *name,
unsigned int flags); unsigned int flags);
virDomainPtr vshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd, virDomainPtr virshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd,
const char **name, unsigned int flags); const char **name, unsigned int flags);
/* default is lookup by Id, Name and UUID */ /* default is lookup by Id, Name and UUID */
# define vshCommandOptDomain(_ctl, _cmd, _name) \ # define virshCommandOptDomain(_ctl, _cmd, _name) \
vshCommandOptDomainBy(_ctl, _cmd, _name, VSH_BYID|VSH_BYUUID|VSH_BYNAME) virshCommandOptDomainBy(_ctl, _cmd, _name, \
VIRSH_BYID | VIRSH_BYUUID | VIRSH_BYNAME)
extern const vshCmdDef domManagementCmds[]; extern const vshCmdDef domManagementCmds[];
......
...@@ -57,8 +57,9 @@ static bool ...@@ -57,8 +57,9 @@ static bool
cmdCapabilities(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) cmdCapabilities(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{ {
char *caps; char *caps;
virshControlPtr priv = ctl->privData;
if ((caps = virConnectGetCapabilities(ctl->conn)) == NULL) { if ((caps = virConnectGetCapabilities(priv->conn)) == NULL) {
vshError(ctl, "%s", _("failed to get capabilities")); vshError(ctl, "%s", _("failed to get capabilities"));
return false; return false;
} }
...@@ -111,6 +112,7 @@ cmdDomCapabilities(vshControl *ctl, const vshCmd *cmd) ...@@ -111,6 +112,7 @@ cmdDomCapabilities(vshControl *ctl, const vshCmd *cmd)
const char *arch = NULL; const char *arch = NULL;
const char *machine = NULL; const char *machine = NULL;
const unsigned int flags = 0; /* No flags so far */ const unsigned int flags = 0; /* No flags so far */
virshControlPtr priv = ctl->privData;
if (vshCommandOptStringReq(ctl, cmd, "virttype", &virttype) < 0 || if (vshCommandOptStringReq(ctl, cmd, "virttype", &virttype) < 0 ||
vshCommandOptStringReq(ctl, cmd, "emulatorbin", &emulatorbin) < 0 || vshCommandOptStringReq(ctl, cmd, "emulatorbin", &emulatorbin) < 0 ||
...@@ -118,7 +120,7 @@ cmdDomCapabilities(vshControl *ctl, const vshCmd *cmd) ...@@ -118,7 +120,7 @@ cmdDomCapabilities(vshControl *ctl, const vshCmd *cmd)
vshCommandOptStringReq(ctl, cmd, "machine", &machine) < 0) vshCommandOptStringReq(ctl, cmd, "machine", &machine) < 0)
return ret; return ret;
caps = virConnectGetDomainCapabilities(ctl->conn, emulatorbin, caps = virConnectGetDomainCapabilities(priv->conn, emulatorbin,
arch, machine, virttype, flags); arch, machine, virttype, flags);
if (!caps) { if (!caps) {
vshError(ctl, "%s", _("failed to get emulator capabilities")); vshError(ctl, "%s", _("failed to get emulator capabilities"));
...@@ -173,6 +175,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) ...@@ -173,6 +175,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
char *cap_xml = NULL; char *cap_xml = NULL;
xmlDocPtr xml = NULL; xmlDocPtr xml = NULL;
xmlXPathContextPtr ctxt = NULL; xmlXPathContextPtr ctxt = NULL;
virshControlPtr priv = ctl->privData;
VSH_EXCLUSIVE_OPTIONS_VAR(all, cellno); VSH_EXCLUSIVE_OPTIONS_VAR(all, cellno);
...@@ -180,7 +183,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) ...@@ -180,7 +183,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
return false; return false;
if (all) { if (all) {
if (!(cap_xml = virConnectGetCapabilities(ctl->conn))) { if (!(cap_xml = virConnectGetCapabilities(priv->conn))) {
vshError(ctl, "%s", _("unable to get node capabilities")); vshError(ctl, "%s", _("unable to get node capabilities"));
goto cleanup; goto cleanup;
} }
...@@ -213,7 +216,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) ...@@ -213,7 +216,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
} }
VIR_FREE(val); VIR_FREE(val);
nodes_id[i] = id; nodes_id[i] = id;
if (virNodeGetCellsFreeMemory(ctl->conn, &(nodes_free[i]), if (virNodeGetCellsFreeMemory(priv->conn, &(nodes_free[i]),
id, 1) != 1) { id, 1) != 1) {
vshError(ctl, _("failed to get free memory for NUMA node " vshError(ctl, _("failed to get free memory for NUMA node "
"number: %lu"), id); "number: %lu"), id);
...@@ -231,12 +234,12 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) ...@@ -231,12 +234,12 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
vshPrintExtra(ctl, "%5s: %10llu KiB\n", _("Total"), memory/1024); vshPrintExtra(ctl, "%5s: %10llu KiB\n", _("Total"), memory/1024);
} else { } else {
if (cellno) { if (cellno) {
if (virNodeGetCellsFreeMemory(ctl->conn, &memory, cell, 1) != 1) if (virNodeGetCellsFreeMemory(priv->conn, &memory, cell, 1) != 1)
goto cleanup; goto cleanup;
vshPrint(ctl, "%d: %llu KiB\n", cell, (memory/1024)); vshPrint(ctl, "%d: %llu KiB\n", cell, (memory/1024));
} else { } else {
if ((memory = virNodeGetFreeMemory(ctl->conn)) == 0) if ((memory = virNodeGetFreeMemory(priv->conn)) == 0)
goto cleanup; goto cleanup;
vshPrint(ctl, "%s: %llu KiB\n", _("Total"), (memory/1024)); vshPrint(ctl, "%s: %llu KiB\n", _("Total"), (memory/1024));
...@@ -313,6 +316,7 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) ...@@ -313,6 +316,7 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd)
bool all = vshCommandOptBool(cmd, "all"); bool all = vshCommandOptBool(cmd, "all");
bool cellno = vshCommandOptBool(cmd, "cellno"); bool cellno = vshCommandOptBool(cmd, "cellno");
bool pagesz = vshCommandOptBool(cmd, "pagesize"); bool pagesz = vshCommandOptBool(cmd, "pagesize");
virshControlPtr priv = ctl->privData;
VSH_EXCLUSIVE_OPTIONS_VAR(all, cellno); VSH_EXCLUSIVE_OPTIONS_VAR(all, cellno);
...@@ -321,7 +325,7 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) ...@@ -321,7 +325,7 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd)
kibibytes = VIR_DIV_UP(bytes, 1024); kibibytes = VIR_DIV_UP(bytes, 1024);
if (all) { if (all) {
if (!(cap_xml = virConnectGetCapabilities(ctl->conn))) { if (!(cap_xml = virConnectGetCapabilities(priv->conn))) {
vshError(ctl, "%s", _("unable to get node capabilities")); vshError(ctl, "%s", _("unable to get node capabilities"));
goto cleanup; goto cleanup;
} }
...@@ -398,7 +402,7 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) ...@@ -398,7 +402,7 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd)
} }
VIR_FREE(val); VIR_FREE(val);
if (virNodeGetFreePages(ctl->conn, npages, pagesize, if (virNodeGetFreePages(priv->conn, npages, pagesize,
cell, 1, counts, 0) < 0) cell, 1, counts, 0) < 0)
goto cleanup; goto cleanup;
...@@ -434,7 +438,8 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) ...@@ -434,7 +438,8 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd)
counts = vshMalloc(ctl, sizeof(*counts)); counts = vshMalloc(ctl, sizeof(*counts));
if (virNodeGetFreePages(ctl->conn, 1, pagesize, cell, 1, counts, 0) < 0) if (virNodeGetFreePages(priv->conn, 1, pagesize,
cell, 1, counts, 0) < 0)
goto cleanup; goto cleanup;
vshPrint(ctl, "%uKiB: %lld\n", *pagesize, counts[0]); vshPrint(ctl, "%uKiB: %lld\n", *pagesize, counts[0]);
...@@ -506,6 +511,7 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) ...@@ -506,6 +511,7 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd)
xmlDocPtr xml = NULL; xmlDocPtr xml = NULL;
xmlXPathContextPtr ctxt = NULL; xmlXPathContextPtr ctxt = NULL;
xmlNodePtr *nodes = NULL; xmlNodePtr *nodes = NULL;
virshControlPtr priv = ctl->privData;
VSH_EXCLUSIVE_OPTIONS_VAR(all, cellno); VSH_EXCLUSIVE_OPTIONS_VAR(all, cellno);
...@@ -525,7 +531,7 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) ...@@ -525,7 +531,7 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd)
unsigned long nodes_cnt; unsigned long nodes_cnt;
size_t i; size_t i;
if (!(cap_xml = virConnectGetCapabilities(ctl->conn))) { if (!(cap_xml = virConnectGetCapabilities(priv->conn))) {
vshError(ctl, "%s", _("unable to get node capabilities")); vshError(ctl, "%s", _("unable to get node capabilities"));
goto cleanup; goto cleanup;
} }
...@@ -555,12 +561,12 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) ...@@ -555,12 +561,12 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd)
} }
VIR_FREE(val); VIR_FREE(val);
if (virNodeAllocPages(ctl->conn, 1, pageSizes, if (virNodeAllocPages(priv->conn, 1, pageSizes,
pageCounts, id, 1, flags) < 0) pageCounts, id, 1, flags) < 0)
goto cleanup; goto cleanup;
} }
} else { } else {
if (virNodeAllocPages(ctl->conn, 1, pageSizes, pageCounts, if (virNodeAllocPages(priv->conn, 1, pageSizes, pageCounts,
startCell, cellCount, flags) < 0) startCell, cellCount, flags) < 0)
goto cleanup; goto cleanup;
} }
...@@ -601,11 +607,12 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd) ...@@ -601,11 +607,12 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd)
{ {
const char *type = NULL; const char *type = NULL;
int vcpus; int vcpus;
virshControlPtr priv = ctl->privData;
if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0) if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0)
return false; return false;
if ((vcpus = virConnectGetMaxVcpus(ctl->conn, type)) < 0) if ((vcpus = virConnectGetMaxVcpus(priv->conn, type)) < 0)
return false; return false;
vshPrint(ctl, "%d\n", vcpus); vshPrint(ctl, "%d\n", vcpus);
...@@ -630,8 +637,9 @@ static bool ...@@ -630,8 +637,9 @@ static bool
cmdNodeinfo(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) cmdNodeinfo(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{ {
virNodeInfo info; virNodeInfo info;
virshControlPtr priv = ctl->privData;
if (virNodeGetInfo(ctl->conn, &info) < 0) { if (virNodeGetInfo(priv->conn, &info) < 0) {
vshError(ctl, "%s", _("failed to get node information")); vshError(ctl, "%s", _("failed to get node information"));
return false; return false;
} }
...@@ -678,8 +686,9 @@ cmdNodeCpuMap(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) ...@@ -678,8 +686,9 @@ cmdNodeCpuMap(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
unsigned int online; unsigned int online;
bool pretty = vshCommandOptBool(cmd, "pretty"); bool pretty = vshCommandOptBool(cmd, "pretty");
bool ret = false; bool ret = false;
virshControlPtr priv = ctl->privData;
cpunum = virNodeGetCPUMap(ctl->conn, &cpumap, &online, 0); cpunum = virNodeGetCPUMap(priv->conn, &cpumap, &online, 0);
if (cpunum < 0) { if (cpunum < 0) {
vshError(ctl, "%s", _("Unable to get cpu map")); vshError(ctl, "%s", _("Unable to get cpu map"));
goto cleanup; goto cleanup;
...@@ -735,17 +744,17 @@ static const vshCmdOptDef opts_node_cpustats[] = { ...@@ -735,17 +744,17 @@ static const vshCmdOptDef opts_node_cpustats[] = {
}; };
typedef enum { typedef enum {
VSH_CPU_USER, VIRSH_CPU_USER,
VSH_CPU_SYSTEM, VIRSH_CPU_SYSTEM,
VSH_CPU_IDLE, VIRSH_CPU_IDLE,
VSH_CPU_IOWAIT, VIRSH_CPU_IOWAIT,
VSH_CPU_INTR, VIRSH_CPU_INTR,
VSH_CPU_USAGE, VIRSH_CPU_USAGE,
VSH_CPU_LAST VIRSH_CPU_LAST
} vshCPUStats; } virshCPUStats;
VIR_ENUM_DECL(vshCPUStats); VIR_ENUM_DECL(virshCPUStats);
VIR_ENUM_IMPL(vshCPUStats, VSH_CPU_LAST, VIR_ENUM_IMPL(virshCPUStats, VIRSH_CPU_LAST,
VIR_NODE_CPU_STATS_USER, VIR_NODE_CPU_STATS_USER,
VIR_NODE_CPU_STATS_KERNEL, VIR_NODE_CPU_STATS_KERNEL,
VIR_NODE_CPU_STATS_IDLE, VIR_NODE_CPU_STATS_IDLE,
...@@ -753,7 +762,7 @@ VIR_ENUM_IMPL(vshCPUStats, VSH_CPU_LAST, ...@@ -753,7 +762,7 @@ VIR_ENUM_IMPL(vshCPUStats, VSH_CPU_LAST,
VIR_NODE_CPU_STATS_INTR, VIR_NODE_CPU_STATS_INTR,
VIR_NODE_CPU_STATS_UTILIZATION); VIR_NODE_CPU_STATS_UTILIZATION);
const char *vshCPUOutput[] = { const char *virshCPUOutput[] = {
N_("user:"), N_("user:"),
N_("system:"), N_("system:"),
N_("idle:"), N_("idle:"),
...@@ -771,13 +780,14 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd) ...@@ -771,13 +780,14 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd)
virNodeCPUStatsPtr params; virNodeCPUStatsPtr params;
int nparams = 0; int nparams = 0;
bool ret = false; bool ret = false;
unsigned long long cpu_stats[VSH_CPU_LAST] = { 0 }; unsigned long long cpu_stats[VIRSH_CPU_LAST] = { 0 };
bool present[VSH_CPU_LAST] = { false }; bool present[VIRSH_CPU_LAST] = { false };
virshControlPtr priv = ctl->privData;
if (vshCommandOptInt(ctl, cmd, "cpu", &cpuNum) < 0) if (vshCommandOptInt(ctl, cmd, "cpu", &cpuNum) < 0)
return false; return false;
if (virNodeGetCPUStats(ctl->conn, cpuNum, NULL, &nparams, 0) != 0) { if (virNodeGetCPUStats(priv->conn, cpuNum, NULL, &nparams, 0) != 0) {
vshError(ctl, "%s", vshError(ctl, "%s",
_("Unable to get number of cpu stats")); _("Unable to get number of cpu stats"));
return false; return false;
...@@ -791,13 +801,13 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd) ...@@ -791,13 +801,13 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd)
params = vshCalloc(ctl, nparams, sizeof(*params)); params = vshCalloc(ctl, nparams, sizeof(*params));
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
if (virNodeGetCPUStats(ctl->conn, cpuNum, params, &nparams, 0) != 0) { if (virNodeGetCPUStats(priv->conn, cpuNum, params, &nparams, 0) != 0) {
vshError(ctl, "%s", _("Unable to get node cpu stats")); vshError(ctl, "%s", _("Unable to get node cpu stats"));
goto cleanup; goto cleanup;
} }
for (j = 0; j < nparams; j++) { for (j = 0; j < nparams; j++) {
int field = vshCPUStatsTypeFromString(params[j].field); int field = virshCPUStatsTypeFromString(params[j].field);
if (field < 0) if (field < 0)
continue; continue;
...@@ -810,34 +820,37 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd) ...@@ -810,34 +820,37 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd)
} }
} }
if (present[VSH_CPU_USAGE] || !flag_percent) if (present[VIRSH_CPU_USAGE] || !flag_percent)
break; break;
sleep(1); sleep(1);
} }
if (!flag_percent) { if (!flag_percent) {
for (i = 0; i < VSH_CPU_USAGE; i++) { for (i = 0; i < VIRSH_CPU_USAGE; i++) {
if (present[i]) { if (present[i]) {
vshPrint(ctl, "%-15s %20llu\n", _(vshCPUOutput[i]), vshPrint(ctl, "%-15s %20llu\n", _(virshCPUOutput[i]),
cpu_stats[i]); cpu_stats[i]);
} }
} }
} else { } else {
if (present[VSH_CPU_USAGE]) { if (present[VIRSH_CPU_USAGE]) {
vshPrint(ctl, "%-15s %5.1llu%%\n", _("usage:"), cpu_stats[VSH_CPU_USAGE]); vshPrint(ctl, "%-15s %5.1llu%%\n",
vshPrint(ctl, "%-15s %5.1llu%%\n", _("idle:"), 100 - cpu_stats[VSH_CPU_USAGE]); _("usage:"), cpu_stats[VIRSH_CPU_USAGE]);
vshPrint(ctl, "%-15s %5.1llu%%\n",
_("idle:"), 100 - cpu_stats[VIRSH_CPU_USAGE]);
} else { } else {
double usage, total_time = 0; double usage, total_time = 0;
for (i = 0; i < VSH_CPU_USAGE; i++) for (i = 0; i < VIRSH_CPU_USAGE; i++)
total_time += cpu_stats[i]; total_time += cpu_stats[i];
usage = (cpu_stats[VSH_CPU_USER] + cpu_stats[VSH_CPU_SYSTEM]) / total_time * 100; usage = (cpu_stats[VIRSH_CPU_USER] + cpu_stats[VIRSH_CPU_SYSTEM])
/ total_time * 100;
vshPrint(ctl, "%-15s %5.1lf%%\n", _("usage:"), usage); vshPrint(ctl, "%-15s %5.1lf%%\n", _("usage:"), usage);
for (i = 0; i < VSH_CPU_USAGE; i++) { for (i = 0; i < VIRSH_CPU_USAGE; i++) {
if (present[i]) { if (present[i]) {
vshPrint(ctl, "%-15s %5.1lf%%\n", _(vshCPUOutput[i]), vshPrint(ctl, "%-15s %5.1lf%%\n", _(virshCPUOutput[i]),
cpu_stats[i] / total_time * 100); cpu_stats[i] / total_time * 100);
} }
} }
...@@ -880,12 +893,13 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd) ...@@ -880,12 +893,13 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd)
int cellNum = VIR_NODE_MEMORY_STATS_ALL_CELLS; int cellNum = VIR_NODE_MEMORY_STATS_ALL_CELLS;
virNodeMemoryStatsPtr params = NULL; virNodeMemoryStatsPtr params = NULL;
bool ret = false; bool ret = false;
virshControlPtr priv = ctl->privData;
if (vshCommandOptInt(ctl, cmd, "cell", &cellNum) < 0) if (vshCommandOptInt(ctl, cmd, "cell", &cellNum) < 0)
return false; return false;
/* get the number of memory parameters */ /* get the number of memory parameters */
if (virNodeGetMemoryStats(ctl->conn, cellNum, NULL, &nparams, 0) != 0) { if (virNodeGetMemoryStats(priv->conn, cellNum, NULL, &nparams, 0) != 0) {
vshError(ctl, "%s", vshError(ctl, "%s",
_("Unable to get number of memory stats")); _("Unable to get number of memory stats"));
goto cleanup; goto cleanup;
...@@ -899,7 +913,7 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd) ...@@ -899,7 +913,7 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd)
/* now go get all the memory parameters */ /* now go get all the memory parameters */
params = vshCalloc(ctl, nparams, sizeof(*params)); params = vshCalloc(ctl, nparams, sizeof(*params));
if (virNodeGetMemoryStats(ctl->conn, cellNum, params, &nparams, 0) != 0) { if (virNodeGetMemoryStats(priv->conn, cellNum, params, &nparams, 0) != 0) {
vshError(ctl, "%s", _("Unable to get memory stats")); vshError(ctl, "%s", _("Unable to get memory stats"));
goto cleanup; goto cleanup;
} }
...@@ -949,6 +963,7 @@ cmdNodeSuspend(vshControl *ctl, const vshCmd *cmd) ...@@ -949,6 +963,7 @@ cmdNodeSuspend(vshControl *ctl, const vshCmd *cmd)
const char *target = NULL; const char *target = NULL;
unsigned int suspendTarget; unsigned int suspendTarget;
long long duration; long long duration;
virshControlPtr priv = ctl->privData;
if (vshCommandOptStringReq(ctl, cmd, "target", &target) < 0) if (vshCommandOptStringReq(ctl, cmd, "target", &target) < 0)
return false; return false;
...@@ -972,7 +987,7 @@ cmdNodeSuspend(vshControl *ctl, const vshCmd *cmd) ...@@ -972,7 +987,7 @@ cmdNodeSuspend(vshControl *ctl, const vshCmd *cmd)
return false; return false;
} }
if (virNodeSuspendForDuration(ctl->conn, suspendTarget, duration, 0) < 0) { if (virNodeSuspendForDuration(priv->conn, suspendTarget, duration, 0) < 0) {
vshError(ctl, "%s", _("The host was not suspended")); vshError(ctl, "%s", _("The host was not suspended"));
return false; return false;
} }
...@@ -996,8 +1011,9 @@ static bool ...@@ -996,8 +1011,9 @@ static bool
cmdSysinfo(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) cmdSysinfo(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{ {
char *sysinfo; char *sysinfo;
virshControlPtr priv = ctl->privData;
sysinfo = virConnectGetSysinfo(ctl->conn, 0); sysinfo = virConnectGetSysinfo(priv->conn, 0);
if (sysinfo == NULL) { if (sysinfo == NULL) {
vshError(ctl, "%s", _("failed to get sysinfo")); vshError(ctl, "%s", _("failed to get sysinfo"));
return false; return false;
...@@ -1026,8 +1042,9 @@ static bool ...@@ -1026,8 +1042,9 @@ static bool
cmdHostname(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) cmdHostname(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{ {
char *hostname; char *hostname;
virshControlPtr priv = ctl->privData;
hostname = virConnectGetHostname(ctl->conn); hostname = virConnectGetHostname(priv->conn);
if (hostname == NULL) { if (hostname == NULL) {
vshError(ctl, "%s", _("failed to get hostname")); vshError(ctl, "%s", _("failed to get hostname"));
return false; return false;
...@@ -1056,8 +1073,9 @@ static bool ...@@ -1056,8 +1073,9 @@ static bool
cmdURI(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) cmdURI(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{ {
char *uri; char *uri;
virshControlPtr priv = ctl->privData;
uri = virConnectGetURI(ctl->conn); uri = virConnectGetURI(priv->conn);
if (uri == NULL) { if (uri == NULL) {
vshError(ctl, "%s", _("failed to get URI")); vshError(ctl, "%s", _("failed to get URI"));
return false; return false;
...@@ -1098,11 +1116,12 @@ cmdCPUModelNames(vshControl *ctl, const vshCmd *cmd) ...@@ -1098,11 +1116,12 @@ cmdCPUModelNames(vshControl *ctl, const vshCmd *cmd)
size_t i; size_t i;
int nmodels; int nmodels;
const char *arch = NULL; const char *arch = NULL;
virshControlPtr priv = ctl->privData;
if (vshCommandOptStringReq(ctl, cmd, "arch", &arch) < 0) if (vshCommandOptStringReq(ctl, cmd, "arch", &arch) < 0)
return false; return false;
nmodels = virConnectGetCPUModelNames(ctl->conn, arch, &models, 0); nmodels = virConnectGetCPUModelNames(priv->conn, arch, &models, 0);
if (nmodels < 0) { if (nmodels < 0) {
vshError(ctl, "%s", _("failed to get CPU model names")); vshError(ctl, "%s", _("failed to get CPU model names"));
return false; return false;
...@@ -1151,8 +1170,9 @@ cmdVersion(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) ...@@ -1151,8 +1170,9 @@ cmdVersion(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
unsigned int major; unsigned int major;
unsigned int minor; unsigned int minor;
unsigned int rel; unsigned int rel;
virshControlPtr priv = ctl->privData;
hvType = virConnectGetType(ctl->conn); hvType = virConnectGetType(priv->conn);
if (hvType == NULL) { if (hvType == NULL) {
vshError(ctl, "%s", _("failed to get hypervisor type")); vshError(ctl, "%s", _("failed to get hypervisor type"));
return false; return false;
...@@ -1185,7 +1205,7 @@ cmdVersion(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) ...@@ -1185,7 +1205,7 @@ cmdVersion(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
vshPrint(ctl, _("Using API: %s %d.%d.%d\n"), hvType, vshPrint(ctl, _("Using API: %s %d.%d.%d\n"), hvType,
major, minor, rel); major, minor, rel);
ret = virConnectGetVersion(ctl->conn, &hvVersion); ret = virConnectGetVersion(priv->conn, &hvVersion);
if (ret < 0) { if (ret < 0) {
vshError(ctl, "%s", _("failed to get the hypervisor version")); vshError(ctl, "%s", _("failed to get the hypervisor version"));
return false; return false;
...@@ -1204,7 +1224,7 @@ cmdVersion(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) ...@@ -1204,7 +1224,7 @@ cmdVersion(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
} }
if (vshCommandOptBool(cmd, "daemon")) { if (vshCommandOptBool(cmd, "daemon")) {
ret = virConnectGetLibVersion(ctl->conn, &daemonVersion); ret = virConnectGetLibVersion(priv->conn, &daemonVersion);
if (ret < 0) { if (ret < 0) {
vshError(ctl, "%s", _("failed to get the daemon version")); vshError(ctl, "%s", _("failed to get the daemon version"));
} else { } else {
...@@ -1257,6 +1277,7 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd) ...@@ -1257,6 +1277,7 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd)
bool ret = false; bool ret = false;
int rc = -1; int rc = -1;
size_t i; size_t i;
virshControlPtr priv = ctl->privData;
if ((rc = vshCommandOptUInt(ctl, cmd, "shm-pages-to-scan", &value)) < 0) { if ((rc = vshCommandOptUInt(ctl, cmd, "shm-pages-to-scan", &value)) < 0) {
goto cleanup; goto cleanup;
...@@ -1287,7 +1308,7 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd) ...@@ -1287,7 +1308,7 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd)
if (nparams == 0) { if (nparams == 0) {
/* Get the number of memory parameters */ /* Get the number of memory parameters */
if (virNodeGetMemoryParameters(ctl->conn, NULL, &nparams, flags) != 0) { if (virNodeGetMemoryParameters(priv->conn, NULL, &nparams, flags) != 0) {
vshError(ctl, "%s", vshError(ctl, "%s",
_("Unable to get number of memory parameters")); _("Unable to get number of memory parameters"));
goto cleanup; goto cleanup;
...@@ -1300,7 +1321,7 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd) ...@@ -1300,7 +1321,7 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd)
/* Now go get all the memory parameters */ /* Now go get all the memory parameters */
params = vshCalloc(ctl, nparams, sizeof(*params)); params = vshCalloc(ctl, nparams, sizeof(*params));
if (virNodeGetMemoryParameters(ctl->conn, params, &nparams, flags) != 0) { if (virNodeGetMemoryParameters(priv->conn, params, &nparams, flags) != 0) {
vshError(ctl, "%s", _("Unable to get memory parameters")); vshError(ctl, "%s", _("Unable to get memory parameters"));
goto cleanup; goto cleanup;
} }
...@@ -1315,7 +1336,7 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd) ...@@ -1315,7 +1336,7 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd)
VIR_FREE(str); VIR_FREE(str);
} }
} else { } else {
if (virNodeSetMemoryParameters(ctl->conn, params, nparams, flags) != 0) if (virNodeSetMemoryParameters(priv->conn, params, nparams, flags) != 0)
goto error; goto error;
} }
......
...@@ -41,15 +41,16 @@ ...@@ -41,15 +41,16 @@
#include "virstring.h" #include "virstring.h"
virInterfacePtr virInterfacePtr
vshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd, virshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd,
const char *optname, const char *optname,
const char **name, unsigned int flags) const char **name, unsigned int flags)
{ {
virInterfacePtr iface = NULL; virInterfacePtr iface = NULL;
const char *n = NULL; const char *n = NULL;
bool is_mac = false; bool is_mac = false;
virMacAddr dummy; virMacAddr dummy;
virCheckFlags(VSH_BYNAME | VSH_BYMAC, NULL); virCheckFlags(VIRSH_BYNAME | VIRSH_BYMAC, NULL);
virshControlPtr priv = ctl->privData;
if (!optname) if (!optname)
optname = "interface"; optname = "interface";
...@@ -67,16 +68,16 @@ vshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd, ...@@ -67,16 +68,16 @@ vshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd,
is_mac = true; is_mac = true;
/* try it by NAME */ /* try it by NAME */
if (!is_mac && (flags & VSH_BYNAME)) { if (!is_mac && (flags & VIRSH_BYNAME)) {
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as interface NAME\n", vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as interface NAME\n",
cmd->def->name, optname); cmd->def->name, optname);
iface = virInterfaceLookupByName(ctl->conn, n); iface = virInterfaceLookupByName(priv->conn, n);
/* try it by MAC */ /* try it by MAC */
} else if (is_mac && (flags & VSH_BYMAC)) { } else if (is_mac && (flags & VIRSH_BYMAC)) {
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as interface MAC\n", vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as interface MAC\n",
cmd->def->name, optname); cmd->def->name, optname);
iface = virInterfaceLookupByMACString(ctl->conn, n); iface = virInterfaceLookupByMACString(priv->conn, n);
} }
if (!iface) if (!iface)
...@@ -114,8 +115,9 @@ cmdInterfaceEdit(vshControl *ctl, const vshCmd *cmd) ...@@ -114,8 +115,9 @@ cmdInterfaceEdit(vshControl *ctl, const vshCmd *cmd)
virInterfacePtr iface = NULL; virInterfacePtr iface = NULL;
virInterfacePtr iface_edited = NULL; virInterfacePtr iface_edited = NULL;
unsigned int flags = VIR_INTERFACE_XML_INACTIVE; unsigned int flags = VIR_INTERFACE_XML_INACTIVE;
virshControlPtr priv = ctl->privData;
iface = vshCommandOptInterface(ctl, cmd, NULL); iface = virshCommandOptInterface(ctl, cmd, NULL);
if (iface == NULL) if (iface == NULL)
goto cleanup; goto cleanup;
...@@ -128,7 +130,7 @@ cmdInterfaceEdit(vshControl *ctl, const vshCmd *cmd) ...@@ -128,7 +130,7 @@ cmdInterfaceEdit(vshControl *ctl, const vshCmd *cmd)
goto edit_cleanup; \ goto edit_cleanup; \
} while (0) } while (0)
#define EDIT_DEFINE \ #define EDIT_DEFINE \
(iface_edited = virInterfaceDefineXML(ctl->conn, doc_edited, 0)) (iface_edited = virInterfaceDefineXML(priv->conn, doc_edited, 0))
#include "virsh-edit.c" #include "virsh-edit.c"
vshPrint(ctl, _("Interface %s XML configuration edited.\n"), vshPrint(ctl, _("Interface %s XML configuration edited.\n"),
...@@ -146,7 +148,7 @@ cmdInterfaceEdit(vshControl *ctl, const vshCmd *cmd) ...@@ -146,7 +148,7 @@ cmdInterfaceEdit(vshControl *ctl, const vshCmd *cmd)
} }
static int static int
vshInterfaceSorter(const void *a, const void *b) virshInterfaceSorter(const void *a, const void *b)
{ {
virInterfacePtr *ia = (virInterfacePtr *) a; virInterfacePtr *ia = (virInterfacePtr *) a;
virInterfacePtr *ib = (virInterfacePtr *) b; virInterfacePtr *ib = (virInterfacePtr *) b;
...@@ -161,14 +163,14 @@ vshInterfaceSorter(const void *a, const void *b) ...@@ -161,14 +163,14 @@ vshInterfaceSorter(const void *a, const void *b)
virInterfaceGetName(*ib)); virInterfaceGetName(*ib));
} }
struct vshInterfaceList { struct virshInterfaceList {
virInterfacePtr *ifaces; virInterfacePtr *ifaces;
size_t nifaces; size_t nifaces;
}; };
typedef struct vshInterfaceList *vshInterfaceListPtr; typedef struct virshInterfaceList *virshInterfaceListPtr;
static void static void
vshInterfaceListFree(vshInterfaceListPtr list) virshInterfaceListFree(virshInterfaceListPtr list)
{ {
size_t i; size_t i;
...@@ -182,11 +184,11 @@ vshInterfaceListFree(vshInterfaceListPtr list) ...@@ -182,11 +184,11 @@ vshInterfaceListFree(vshInterfaceListPtr list)
VIR_FREE(list); VIR_FREE(list);
} }
static vshInterfaceListPtr static virshInterfaceListPtr
vshInterfaceListCollect(vshControl *ctl, virshInterfaceListCollect(vshControl *ctl,
unsigned int flags) unsigned int flags)
{ {
vshInterfaceListPtr list = vshMalloc(ctl, sizeof(*list)); virshInterfaceListPtr list = vshMalloc(ctl, sizeof(*list));
size_t i; size_t i;
int ret; int ret;
char **activeNames = NULL; char **activeNames = NULL;
...@@ -197,9 +199,10 @@ vshInterfaceListCollect(vshControl *ctl, ...@@ -197,9 +199,10 @@ vshInterfaceListCollect(vshControl *ctl,
int nActiveIfaces = 0; int nActiveIfaces = 0;
int nInactiveIfaces = 0; int nInactiveIfaces = 0;
int nAllIfaces = 0; int nAllIfaces = 0;
virshControlPtr priv = ctl->privData;
/* try the list with flags support (0.10.2 and later) */ /* try the list with flags support (0.10.2 and later) */
if ((ret = virConnectListAllInterfaces(ctl->conn, if ((ret = virConnectListAllInterfaces(priv->conn,
&list->ifaces, &list->ifaces,
flags)) >= 0) { flags)) >= 0) {
list->nifaces = ret; list->nifaces = ret;
...@@ -220,7 +223,7 @@ vshInterfaceListCollect(vshControl *ctl, ...@@ -220,7 +223,7 @@ vshInterfaceListCollect(vshControl *ctl,
vshResetLibvirtError(); vshResetLibvirtError();
if (flags & VIR_CONNECT_LIST_INTERFACES_ACTIVE) { if (flags & VIR_CONNECT_LIST_INTERFACES_ACTIVE) {
nActiveIfaces = virConnectNumOfInterfaces(ctl->conn); nActiveIfaces = virConnectNumOfInterfaces(priv->conn);
if (nActiveIfaces < 0) { if (nActiveIfaces < 0) {
vshError(ctl, "%s", _("Failed to list active interfaces")); vshError(ctl, "%s", _("Failed to list active interfaces"));
goto cleanup; goto cleanup;
...@@ -228,7 +231,7 @@ vshInterfaceListCollect(vshControl *ctl, ...@@ -228,7 +231,7 @@ vshInterfaceListCollect(vshControl *ctl,
if (nActiveIfaces) { if (nActiveIfaces) {
activeNames = vshMalloc(ctl, sizeof(char *) * nActiveIfaces); activeNames = vshMalloc(ctl, sizeof(char *) * nActiveIfaces);
if ((nActiveIfaces = virConnectListInterfaces(ctl->conn, activeNames, if ((nActiveIfaces = virConnectListInterfaces(priv->conn, activeNames,
nActiveIfaces)) < 0) { nActiveIfaces)) < 0) {
vshError(ctl, "%s", _("Failed to list active interfaces")); vshError(ctl, "%s", _("Failed to list active interfaces"));
goto cleanup; goto cleanup;
...@@ -237,7 +240,7 @@ vshInterfaceListCollect(vshControl *ctl, ...@@ -237,7 +240,7 @@ vshInterfaceListCollect(vshControl *ctl,
} }
if (flags & VIR_CONNECT_LIST_INTERFACES_INACTIVE) { if (flags & VIR_CONNECT_LIST_INTERFACES_INACTIVE) {
nInactiveIfaces = virConnectNumOfDefinedInterfaces(ctl->conn); nInactiveIfaces = virConnectNumOfDefinedInterfaces(priv->conn);
if (nInactiveIfaces < 0) { if (nInactiveIfaces < 0) {
vshError(ctl, "%s", _("Failed to list inactive interfaces")); vshError(ctl, "%s", _("Failed to list inactive interfaces"));
goto cleanup; goto cleanup;
...@@ -246,7 +249,7 @@ vshInterfaceListCollect(vshControl *ctl, ...@@ -246,7 +249,7 @@ vshInterfaceListCollect(vshControl *ctl,
inactiveNames = vshMalloc(ctl, sizeof(char *) * nInactiveIfaces); inactiveNames = vshMalloc(ctl, sizeof(char *) * nInactiveIfaces);
if ((nInactiveIfaces = if ((nInactiveIfaces =
virConnectListDefinedInterfaces(ctl->conn, inactiveNames, virConnectListDefinedInterfaces(priv->conn, inactiveNames,
nInactiveIfaces)) < 0) { nInactiveIfaces)) < 0) {
vshError(ctl, "%s", _("Failed to list inactive interfaces")); vshError(ctl, "%s", _("Failed to list inactive interfaces"));
goto cleanup; goto cleanup;
...@@ -266,7 +269,7 @@ vshInterfaceListCollect(vshControl *ctl, ...@@ -266,7 +269,7 @@ vshInterfaceListCollect(vshControl *ctl,
/* get active interfaces */ /* get active interfaces */
for (i = 0; i < nActiveIfaces; i++) { for (i = 0; i < nActiveIfaces; i++) {
if (!(iface = virInterfaceLookupByName(ctl->conn, activeNames[i]))) { if (!(iface = virInterfaceLookupByName(priv->conn, activeNames[i]))) {
vshResetLibvirtError(); vshResetLibvirtError();
continue; continue;
} }
...@@ -275,7 +278,7 @@ vshInterfaceListCollect(vshControl *ctl, ...@@ -275,7 +278,7 @@ vshInterfaceListCollect(vshControl *ctl,
/* get inactive interfaces */ /* get inactive interfaces */
for (i = 0; i < nInactiveIfaces; i++) { for (i = 0; i < nInactiveIfaces; i++) {
if (!(iface = virInterfaceLookupByName(ctl->conn, inactiveNames[i]))) { if (!(iface = virInterfaceLookupByName(priv->conn, inactiveNames[i]))) {
vshResetLibvirtError(); vshResetLibvirtError();
continue; continue;
} }
...@@ -289,7 +292,7 @@ vshInterfaceListCollect(vshControl *ctl, ...@@ -289,7 +292,7 @@ vshInterfaceListCollect(vshControl *ctl,
/* sort the list */ /* sort the list */
if (list->ifaces && list->nifaces) if (list->ifaces && list->nifaces)
qsort(list->ifaces, list->nifaces, qsort(list->ifaces, list->nifaces,
sizeof(*list->ifaces), vshInterfaceSorter); sizeof(*list->ifaces), virshInterfaceSorter);
/* truncate the list if filter simulation deleted entries */ /* truncate the list if filter simulation deleted entries */
if (deleted) if (deleted)
...@@ -308,7 +311,7 @@ vshInterfaceListCollect(vshControl *ctl, ...@@ -308,7 +311,7 @@ vshInterfaceListCollect(vshControl *ctl,
VIR_FREE(inactiveNames); VIR_FREE(inactiveNames);
if (!success) { if (!success) {
vshInterfaceListFree(list); virshInterfaceListFree(list);
list = NULL; list = NULL;
} }
...@@ -346,7 +349,7 @@ cmdInterfaceList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) ...@@ -346,7 +349,7 @@ cmdInterfaceList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
bool inactive = vshCommandOptBool(cmd, "inactive"); bool inactive = vshCommandOptBool(cmd, "inactive");
bool all = vshCommandOptBool(cmd, "all"); bool all = vshCommandOptBool(cmd, "all");
unsigned int flags = VIR_CONNECT_LIST_INTERFACES_ACTIVE; unsigned int flags = VIR_CONNECT_LIST_INTERFACES_ACTIVE;
vshInterfaceListPtr list = NULL; virshInterfaceListPtr list = NULL;
size_t i; size_t i;
if (inactive) if (inactive)
...@@ -355,7 +358,7 @@ cmdInterfaceList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) ...@@ -355,7 +358,7 @@ cmdInterfaceList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
flags = VIR_CONNECT_LIST_INTERFACES_INACTIVE | flags = VIR_CONNECT_LIST_INTERFACES_INACTIVE |
VIR_CONNECT_LIST_INTERFACES_ACTIVE; VIR_CONNECT_LIST_INTERFACES_ACTIVE;
if (!(list = vshInterfaceListCollect(ctl, flags))) if (!(list = virshInterfaceListCollect(ctl, flags)))
return false; return false;
vshPrintExtra(ctl, " %-20s %-10s %s\n", _("Name"), _("State"), vshPrintExtra(ctl, " %-20s %-10s %s\n", _("Name"), _("State"),
...@@ -371,7 +374,7 @@ cmdInterfaceList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) ...@@ -371,7 +374,7 @@ cmdInterfaceList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
virInterfaceGetMACString(iface)); virInterfaceGetMACString(iface));
} }
vshInterfaceListFree(list); virshInterfaceListFree(list);
return true; return true;
} }
...@@ -402,8 +405,8 @@ cmdInterfaceName(vshControl *ctl, const vshCmd *cmd) ...@@ -402,8 +405,8 @@ cmdInterfaceName(vshControl *ctl, const vshCmd *cmd)
{ {
virInterfacePtr iface; virInterfacePtr iface;
if (!(iface = vshCommandOptInterfaceBy(ctl, cmd, NULL, NULL, if (!(iface = virshCommandOptInterfaceBy(ctl, cmd, NULL, NULL,
VSH_BYMAC))) VIRSH_BYMAC)))
return false; return false;
vshPrint(ctl, "%s\n", virInterfaceGetName(iface)); vshPrint(ctl, "%s\n", virInterfaceGetName(iface));
...@@ -438,8 +441,8 @@ cmdInterfaceMAC(vshControl *ctl, const vshCmd *cmd) ...@@ -438,8 +441,8 @@ cmdInterfaceMAC(vshControl *ctl, const vshCmd *cmd)
{ {
virInterfacePtr iface; virInterfacePtr iface;
if (!(iface = vshCommandOptInterfaceBy(ctl, cmd, NULL, NULL, if (!(iface = virshCommandOptInterfaceBy(ctl, cmd, NULL, NULL,
VSH_BYNAME))) VIRSH_BYNAME)))
return false; return false;
vshPrint(ctl, "%s\n", virInterfaceGetMACString(iface)); vshPrint(ctl, "%s\n", virInterfaceGetMACString(iface));
...@@ -485,7 +488,7 @@ cmdInterfaceDumpXML(vshControl *ctl, const vshCmd *cmd) ...@@ -485,7 +488,7 @@ cmdInterfaceDumpXML(vshControl *ctl, const vshCmd *cmd)
if (inactive) if (inactive)
flags |= VIR_INTERFACE_XML_INACTIVE; flags |= VIR_INTERFACE_XML_INACTIVE;
if (!(iface = vshCommandOptInterface(ctl, cmd, NULL))) if (!(iface = virshCommandOptInterface(ctl, cmd, NULL)))
return false; return false;
dump = virInterfaceGetXMLDesc(iface, flags); dump = virInterfaceGetXMLDesc(iface, flags);
...@@ -530,6 +533,7 @@ cmdInterfaceDefine(vshControl *ctl, const vshCmd *cmd) ...@@ -530,6 +533,7 @@ cmdInterfaceDefine(vshControl *ctl, const vshCmd *cmd)
const char *from = NULL; const char *from = NULL;
bool ret = true; bool ret = true;
char *buffer; char *buffer;
virshControlPtr priv = ctl->privData;
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
return false; return false;
...@@ -537,7 +541,7 @@ cmdInterfaceDefine(vshControl *ctl, const vshCmd *cmd) ...@@ -537,7 +541,7 @@ cmdInterfaceDefine(vshControl *ctl, const vshCmd *cmd)
if (virFileReadAll(from, VSH_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(priv->conn, buffer, 0);
VIR_FREE(buffer); VIR_FREE(buffer);
if (iface != NULL) { if (iface != NULL) {
...@@ -580,7 +584,7 @@ cmdInterfaceUndefine(vshControl *ctl, const vshCmd *cmd) ...@@ -580,7 +584,7 @@ cmdInterfaceUndefine(vshControl *ctl, const vshCmd *cmd)
bool ret = true; bool ret = true;
const char *name; const char *name;
if (!(iface = vshCommandOptInterface(ctl, cmd, &name))) if (!(iface = virshCommandOptInterface(ctl, cmd, &name)))
return false; return false;
if (virInterfaceUndefine(iface) == 0) { if (virInterfaceUndefine(iface) == 0) {
...@@ -623,7 +627,7 @@ cmdInterfaceStart(vshControl *ctl, const vshCmd *cmd) ...@@ -623,7 +627,7 @@ cmdInterfaceStart(vshControl *ctl, const vshCmd *cmd)
bool ret = true; bool ret = true;
const char *name; const char *name;
if (!(iface = vshCommandOptInterface(ctl, cmd, &name))) if (!(iface = virshCommandOptInterface(ctl, cmd, &name)))
return false; return false;
if (virInterfaceCreate(iface, 0) == 0) { if (virInterfaceCreate(iface, 0) == 0) {
...@@ -666,7 +670,7 @@ cmdInterfaceDestroy(vshControl *ctl, const vshCmd *cmd) ...@@ -666,7 +670,7 @@ cmdInterfaceDestroy(vshControl *ctl, const vshCmd *cmd)
bool ret = true; bool ret = true;
const char *name; const char *name;
if (!(iface = vshCommandOptInterface(ctl, cmd, &name))) if (!(iface = virshCommandOptInterface(ctl, cmd, &name)))
return false; return false;
if (virInterfaceDestroy(iface, 0) == 0) { if (virInterfaceDestroy(iface, 0) == 0) {
...@@ -702,7 +706,9 @@ static const vshCmdOptDef opts_interface_begin[] = { ...@@ -702,7 +706,9 @@ static const vshCmdOptDef opts_interface_begin[] = {
static bool static bool
cmdInterfaceBegin(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) cmdInterfaceBegin(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{ {
if (virInterfaceChangeBegin(ctl->conn, 0) < 0) { virshControlPtr priv = ctl->privData;
if (virInterfaceChangeBegin(priv->conn, 0) < 0) {
vshError(ctl, "%s", _("Failed to begin network config change transaction")); vshError(ctl, "%s", _("Failed to begin network config change transaction"));
return false; return false;
} }
...@@ -731,7 +737,9 @@ static const vshCmdOptDef opts_interface_commit[] = { ...@@ -731,7 +737,9 @@ static const vshCmdOptDef opts_interface_commit[] = {
static bool static bool
cmdInterfaceCommit(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) cmdInterfaceCommit(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{ {
if (virInterfaceChangeCommit(ctl->conn, 0) < 0) { virshControlPtr priv = ctl->privData;
if (virInterfaceChangeCommit(priv->conn, 0) < 0) {
vshError(ctl, "%s", _("Failed to commit network config change transaction")); vshError(ctl, "%s", _("Failed to commit network config change transaction"));
return false; return false;
} }
...@@ -760,7 +768,9 @@ static const vshCmdOptDef opts_interface_rollback[] = { ...@@ -760,7 +768,9 @@ static const vshCmdOptDef opts_interface_rollback[] = {
static bool static bool
cmdInterfaceRollback(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) cmdInterfaceRollback(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{ {
if (virInterfaceChangeRollback(ctl->conn, 0) < 0) { virshControlPtr priv = ctl->privData;
if (virInterfaceChangeRollback(priv->conn, 0) < 0) {
vshError(ctl, "%s", _("Failed to rollback network config change transaction")); vshError(ctl, "%s", _("Failed to rollback network config change transaction"));
return false; return false;
} }
...@@ -823,10 +833,11 @@ cmdInterfaceBridge(vshControl *ctl, const vshCmd *cmd) ...@@ -823,10 +833,11 @@ cmdInterfaceBridge(vshControl *ctl, const vshCmd *cmd)
xmlDocPtr xml_doc = NULL; xmlDocPtr xml_doc = NULL;
xmlXPathContextPtr ctxt = NULL; xmlXPathContextPtr ctxt = NULL;
xmlNodePtr top_node, br_node, if_node, cur; xmlNodePtr top_node, br_node, if_node, cur;
virshControlPtr priv = ctl->privData;
/* Get a handle to the original device */ /* Get a handle to the original device */
if (!(if_handle = vshCommandOptInterfaceBy(ctl, cmd, "interface", if (!(if_handle = virshCommandOptInterfaceBy(ctl, cmd, "interface",
&if_name, VSH_BYNAME))) { &if_name, VIRSH_BYNAME))) {
goto cleanup; goto cleanup;
} }
...@@ -835,7 +846,7 @@ cmdInterfaceBridge(vshControl *ctl, const vshCmd *cmd) ...@@ -835,7 +846,7 @@ cmdInterfaceBridge(vshControl *ctl, const vshCmd *cmd)
goto cleanup; goto cleanup;
/* make sure "new" device doesn't already exist */ /* make sure "new" device doesn't already exist */
if ((br_handle = virInterfaceLookupByName(ctl->conn, br_name))) { if ((br_handle = virInterfaceLookupByName(priv->conn, br_name))) {
vshError(ctl, _("Network device %s already exists"), br_name); vshError(ctl, _("Network device %s already exists"), br_name);
goto cleanup; goto cleanup;
} }
...@@ -969,7 +980,7 @@ cmdInterfaceBridge(vshControl *ctl, const vshCmd *cmd) ...@@ -969,7 +980,7 @@ cmdInterfaceBridge(vshControl *ctl, const vshCmd *cmd)
/* br_xml is the new interface to define. It will automatically undefine the /* br_xml is the new interface to define. It will automatically undefine the
* independent original interface. * independent original interface.
*/ */
if (!(br_handle = virInterfaceDefineXML(ctl->conn, (char *) br_xml, 0))) { if (!(br_handle = virInterfaceDefineXML(priv->conn, (char *) br_xml, 0))) {
vshError(ctl, _("Failed to define new bridge interface %s"), vshError(ctl, _("Failed to define new bridge interface %s"),
br_name); br_name);
goto cleanup; goto cleanup;
...@@ -1043,10 +1054,11 @@ cmdInterfaceUnbridge(vshControl *ctl, const vshCmd *cmd) ...@@ -1043,10 +1054,11 @@ cmdInterfaceUnbridge(vshControl *ctl, const vshCmd *cmd)
xmlDocPtr xml_doc = NULL; xmlDocPtr xml_doc = NULL;
xmlXPathContextPtr ctxt = NULL; xmlXPathContextPtr ctxt = NULL;
xmlNodePtr top_node, if_node, cur; xmlNodePtr top_node, if_node, cur;
virshControlPtr priv = ctl->privData;
/* Get a handle to the original device */ /* Get a handle to the original device */
if (!(br_handle = vshCommandOptInterfaceBy(ctl, cmd, "bridge", if (!(br_handle = virshCommandOptInterfaceBy(ctl, cmd, "bridge",
&br_name, VSH_BYNAME))) { &br_name, VIRSH_BYNAME))) {
goto cleanup; goto cleanup;
} }
...@@ -1170,7 +1182,7 @@ cmdInterfaceUnbridge(vshControl *ctl, const vshCmd *cmd) ...@@ -1170,7 +1182,7 @@ cmdInterfaceUnbridge(vshControl *ctl, const vshCmd *cmd)
/* if_xml is the new interface to define. /* if_xml is the new interface to define.
*/ */
if (!(if_handle = virInterfaceDefineXML(ctl->conn, (char *) if_xml, 0))) { if (!(if_handle = virInterfaceDefineXML(priv->conn, (char *) if_xml, 0))) {
vshError(ctl, _("Failed to define new interface %s"), if_name); vshError(ctl, _("Failed to define new interface %s"), if_name);
goto cleanup; goto cleanup;
} }
......
...@@ -28,14 +28,14 @@ ...@@ -28,14 +28,14 @@
# include "virsh.h" # include "virsh.h"
virInterfacePtr vshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd, virInterfacePtr virshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd,
const char *optname, const char *optname,
const char **name, unsigned int flags); const char **name, unsigned int flags);
/* default is lookup by Name and MAC */ /* default is lookup by Name and MAC */
# define vshCommandOptInterface(_ctl, _cmd, _name) \ # define virshCommandOptInterface(_ctl, _cmd, _name) \
vshCommandOptInterfaceBy(_ctl, _cmd, NULL, _name, \ virshCommandOptInterfaceBy(_ctl, _cmd, NULL, _name, \
VSH_BYMAC|VSH_BYNAME) VIRSH_BYMAC | VIRSH_BYNAME)
extern const vshCmdDef ifaceCmds[]; extern const vshCmdDef ifaceCmds[];
......
...@@ -34,13 +34,14 @@ ...@@ -34,13 +34,14 @@
#include "conf/network_conf.h" #include "conf/network_conf.h"
virNetworkPtr virNetworkPtr
vshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd, virshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd,
const char **name, unsigned int flags) const char **name, unsigned int flags)
{ {
virNetworkPtr network = NULL; virNetworkPtr network = NULL;
const char *n = NULL; const char *n = NULL;
const char *optname = "network"; const char *optname = "network";
virCheckFlags(VSH_BYUUID | VSH_BYNAME, NULL); virCheckFlags(VIRSH_BYUUID | VIRSH_BYNAME, NULL);
virshControlPtr priv = ctl->privData;
if (vshCommandOptStringReq(ctl, cmd, optname, &n) < 0) if (vshCommandOptStringReq(ctl, cmd, optname, &n) < 0)
return NULL; return NULL;
...@@ -52,16 +53,16 @@ vshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd, ...@@ -52,16 +53,16 @@ vshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd,
*name = n; *name = n;
/* try it by UUID */ /* try it by UUID */
if ((flags & VSH_BYUUID) && strlen(n) == VIR_UUID_STRING_BUFLEN-1) { if ((flags & VIRSH_BYUUID) && strlen(n) == VIR_UUID_STRING_BUFLEN-1) {
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as network UUID\n", vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as network UUID\n",
cmd->def->name, optname); cmd->def->name, optname);
network = virNetworkLookupByUUIDString(ctl->conn, n); network = virNetworkLookupByUUIDString(priv->conn, n);
} }
/* try it by NAME */ /* try it by NAME */
if (!network && (flags & VSH_BYNAME)) { if (!network && (flags & VIRSH_BYNAME)) {
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as network NAME\n", vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as network NAME\n",
cmd->def->name, optname); cmd->def->name, optname);
network = virNetworkLookupByName(ctl->conn, n); network = virNetworkLookupByName(priv->conn, n);
} }
if (!network) if (!network)
...@@ -103,7 +104,7 @@ cmdNetworkAutostart(vshControl *ctl, const vshCmd *cmd) ...@@ -103,7 +104,7 @@ cmdNetworkAutostart(vshControl *ctl, const vshCmd *cmd)
const char *name; const char *name;
int autostart; int autostart;
if (!(network = vshCommandOptNetwork(ctl, cmd, &name))) if (!(network = virshCommandOptNetwork(ctl, cmd, &name)))
return false; return false;
autostart = !vshCommandOptBool(cmd, "disable"); autostart = !vshCommandOptBool(cmd, "disable");
...@@ -155,6 +156,7 @@ cmdNetworkCreate(vshControl *ctl, const vshCmd *cmd) ...@@ -155,6 +156,7 @@ cmdNetworkCreate(vshControl *ctl, const vshCmd *cmd)
const char *from = NULL; const char *from = NULL;
bool ret = true; bool ret = true;
char *buffer; char *buffer;
virshControlPtr priv = ctl->privData;
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
return false; return false;
...@@ -162,7 +164,7 @@ cmdNetworkCreate(vshControl *ctl, const vshCmd *cmd) ...@@ -162,7 +164,7 @@ cmdNetworkCreate(vshControl *ctl, const vshCmd *cmd)
if (virFileReadAll(from, VSH_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(priv->conn, buffer);
VIR_FREE(buffer); VIR_FREE(buffer);
if (network != NULL) { if (network != NULL) {
...@@ -206,6 +208,7 @@ cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd) ...@@ -206,6 +208,7 @@ cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd)
const char *from = NULL; const char *from = NULL;
bool ret = true; bool ret = true;
char *buffer; char *buffer;
virshControlPtr priv = ctl->privData;
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
return false; return false;
...@@ -213,7 +216,7 @@ cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd) ...@@ -213,7 +216,7 @@ cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd)
if (virFileReadAll(from, VSH_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(priv->conn, buffer);
VIR_FREE(buffer); VIR_FREE(buffer);
if (network != NULL) { if (network != NULL) {
...@@ -256,7 +259,7 @@ cmdNetworkDestroy(vshControl *ctl, const vshCmd *cmd) ...@@ -256,7 +259,7 @@ cmdNetworkDestroy(vshControl *ctl, const vshCmd *cmd)
bool ret = true; bool ret = true;
const char *name; const char *name;
if (!(network = vshCommandOptNetwork(ctl, cmd, &name))) if (!(network = virshCommandOptNetwork(ctl, cmd, &name)))
return false; return false;
if (virNetworkDestroy(network) == 0) { if (virNetworkDestroy(network) == 0) {
...@@ -305,7 +308,7 @@ cmdNetworkDumpXML(vshControl *ctl, const vshCmd *cmd) ...@@ -305,7 +308,7 @@ cmdNetworkDumpXML(vshControl *ctl, const vshCmd *cmd)
unsigned int flags = 0; unsigned int flags = 0;
int inactive; int inactive;
if (!(network = vshCommandOptNetwork(ctl, cmd, NULL))) if (!(network = virshCommandOptNetwork(ctl, cmd, NULL)))
return false; return false;
inactive = vshCommandOptBool(cmd, "inactive"); inactive = vshCommandOptBool(cmd, "inactive");
...@@ -357,7 +360,7 @@ cmdNetworkInfo(vshControl *ctl, const vshCmd *cmd) ...@@ -357,7 +360,7 @@ cmdNetworkInfo(vshControl *ctl, const vshCmd *cmd)
int active = -1; int active = -1;
char *bridge = NULL; char *bridge = NULL;
if (!(network = vshCommandOptNetwork(ctl, cmd, NULL))) if (!(network = virshCommandOptNetwork(ctl, cmd, NULL)))
return false; return false;
vshPrint(ctl, "%-15s %s\n", _("Name:"), virNetworkGetName(network)); vshPrint(ctl, "%-15s %s\n", _("Name:"), virNetworkGetName(network));
...@@ -390,7 +393,7 @@ cmdNetworkInfo(vshControl *ctl, const vshCmd *cmd) ...@@ -390,7 +393,7 @@ cmdNetworkInfo(vshControl *ctl, const vshCmd *cmd)
} }
static int static int
vshNetworkSorter(const void *a, const void *b) virshNetworkSorter(const void *a, const void *b)
{ {
virNetworkPtr *na = (virNetworkPtr *) a; virNetworkPtr *na = (virNetworkPtr *) a;
virNetworkPtr *nb = (virNetworkPtr *) b; virNetworkPtr *nb = (virNetworkPtr *) b;
...@@ -405,14 +408,14 @@ vshNetworkSorter(const void *a, const void *b) ...@@ -405,14 +408,14 @@ vshNetworkSorter(const void *a, const void *b)
virNetworkGetName(*nb)); virNetworkGetName(*nb));
} }
struct vshNetworkList { struct virshNetworkList {
virNetworkPtr *nets; virNetworkPtr *nets;
size_t nnets; size_t nnets;
}; };
typedef struct vshNetworkList *vshNetworkListPtr; typedef struct virshNetworkList *virshNetworkListPtr;
static void static void
vshNetworkListFree(vshNetworkListPtr list) virshNetworkListFree(virshNetworkListPtr list)
{ {
size_t i; size_t i;
...@@ -426,11 +429,11 @@ vshNetworkListFree(vshNetworkListPtr list) ...@@ -426,11 +429,11 @@ vshNetworkListFree(vshNetworkListPtr list)
VIR_FREE(list); VIR_FREE(list);
} }
static vshNetworkListPtr static virshNetworkListPtr
vshNetworkListCollect(vshControl *ctl, virshNetworkListCollect(vshControl *ctl,
unsigned int flags) unsigned int flags)
{ {
vshNetworkListPtr list = vshMalloc(ctl, sizeof(*list)); virshNetworkListPtr list = vshMalloc(ctl, sizeof(*list));
size_t i; size_t i;
int ret; int ret;
char **names = NULL; char **names = NULL;
...@@ -442,9 +445,10 @@ vshNetworkListCollect(vshControl *ctl, ...@@ -442,9 +445,10 @@ vshNetworkListCollect(vshControl *ctl,
int nActiveNets = 0; int nActiveNets = 0;
int nInactiveNets = 0; int nInactiveNets = 0;
int nAllNets = 0; int nAllNets = 0;
virshControlPtr priv = ctl->privData;
/* try the list with flags support (0.10.2 and later) */ /* try the list with flags support (0.10.2 and later) */
if ((ret = virConnectListAllNetworks(ctl->conn, if ((ret = virConnectListAllNetworks(priv->conn,
&list->nets, &list->nets,
flags)) >= 0) { flags)) >= 0) {
list->nnets = ret; list->nnets = ret;
...@@ -461,7 +465,7 @@ vshNetworkListCollect(vshControl *ctl, ...@@ -461,7 +465,7 @@ vshNetworkListCollect(vshControl *ctl,
VIR_CONNECT_LIST_NETWORKS_INACTIVE); VIR_CONNECT_LIST_NETWORKS_INACTIVE);
vshResetLibvirtError(); vshResetLibvirtError();
if ((ret = virConnectListAllNetworks(ctl->conn, &list->nets, if ((ret = virConnectListAllNetworks(priv->conn, &list->nets,
newflags)) >= 0) { newflags)) >= 0) {
list->nnets = ret; list->nnets = ret;
goto filter; goto filter;
...@@ -480,7 +484,7 @@ vshNetworkListCollect(vshControl *ctl, ...@@ -480,7 +484,7 @@ vshNetworkListCollect(vshControl *ctl,
/* Get the number of active networks */ /* Get the number of active networks */
if (!VSH_MATCH(VIR_CONNECT_LIST_NETWORKS_FILTERS_ACTIVE) || if (!VSH_MATCH(VIR_CONNECT_LIST_NETWORKS_FILTERS_ACTIVE) ||
VSH_MATCH(VIR_CONNECT_LIST_NETWORKS_ACTIVE)) { VSH_MATCH(VIR_CONNECT_LIST_NETWORKS_ACTIVE)) {
if ((nActiveNets = virConnectNumOfNetworks(ctl->conn)) < 0) { if ((nActiveNets = virConnectNumOfNetworks(priv->conn)) < 0) {
vshError(ctl, "%s", _("Failed to get the number of active networks")); vshError(ctl, "%s", _("Failed to get the number of active networks"));
goto cleanup; goto cleanup;
} }
...@@ -489,7 +493,7 @@ vshNetworkListCollect(vshControl *ctl, ...@@ -489,7 +493,7 @@ vshNetworkListCollect(vshControl *ctl,
/* Get the number of inactive networks */ /* Get the number of inactive networks */
if (!VSH_MATCH(VIR_CONNECT_LIST_NETWORKS_FILTERS_ACTIVE) || if (!VSH_MATCH(VIR_CONNECT_LIST_NETWORKS_FILTERS_ACTIVE) ||
VSH_MATCH(VIR_CONNECT_LIST_NETWORKS_INACTIVE)) { VSH_MATCH(VIR_CONNECT_LIST_NETWORKS_INACTIVE)) {
if ((nInactiveNets = virConnectNumOfDefinedNetworks(ctl->conn)) < 0) { if ((nInactiveNets = virConnectNumOfDefinedNetworks(priv->conn)) < 0) {
vshError(ctl, "%s", _("Failed to get the number of inactive networks")); vshError(ctl, "%s", _("Failed to get the number of inactive networks"));
goto cleanup; goto cleanup;
} }
...@@ -505,7 +509,7 @@ vshNetworkListCollect(vshControl *ctl, ...@@ -505,7 +509,7 @@ vshNetworkListCollect(vshControl *ctl,
/* Retrieve a list of active network names */ /* Retrieve a list of active network names */
if (!VSH_MATCH(VIR_CONNECT_LIST_NETWORKS_FILTERS_ACTIVE) || if (!VSH_MATCH(VIR_CONNECT_LIST_NETWORKS_FILTERS_ACTIVE) ||
VSH_MATCH(VIR_CONNECT_LIST_NETWORKS_ACTIVE)) { VSH_MATCH(VIR_CONNECT_LIST_NETWORKS_ACTIVE)) {
if (virConnectListNetworks(ctl->conn, if (virConnectListNetworks(priv->conn,
names, nActiveNets) < 0) { names, nActiveNets) < 0) {
vshError(ctl, "%s", _("Failed to list active networks")); vshError(ctl, "%s", _("Failed to list active networks"));
goto cleanup; goto cleanup;
...@@ -515,7 +519,7 @@ vshNetworkListCollect(vshControl *ctl, ...@@ -515,7 +519,7 @@ vshNetworkListCollect(vshControl *ctl,
/* Add the inactive networks to the end of the name list */ /* Add the inactive networks to the end of the name list */
if (!VSH_MATCH(VIR_CONNECT_LIST_NETWORKS_FILTERS_ACTIVE) || if (!VSH_MATCH(VIR_CONNECT_LIST_NETWORKS_FILTERS_ACTIVE) ||
VSH_MATCH(VIR_CONNECT_LIST_NETWORKS_ACTIVE)) { VSH_MATCH(VIR_CONNECT_LIST_NETWORKS_ACTIVE)) {
if (virConnectListDefinedNetworks(ctl->conn, if (virConnectListDefinedNetworks(priv->conn,
&names[nActiveNets], &names[nActiveNets],
nInactiveNets) < 0) { nInactiveNets) < 0) {
vshError(ctl, "%s", _("Failed to list inactive networks")); vshError(ctl, "%s", _("Failed to list inactive networks"));
...@@ -528,14 +532,14 @@ vshNetworkListCollect(vshControl *ctl, ...@@ -528,14 +532,14 @@ vshNetworkListCollect(vshControl *ctl,
/* get active networks */ /* get active networks */
for (i = 0; i < nActiveNets; i++) { for (i = 0; i < nActiveNets; i++) {
if (!(net = virNetworkLookupByName(ctl->conn, names[i]))) if (!(net = virNetworkLookupByName(priv->conn, names[i])))
continue; continue;
list->nets[list->nnets++] = net; list->nets[list->nnets++] = net;
} }
/* get inactive networks */ /* get inactive networks */
for (i = 0; i < nInactiveNets; i++) { for (i = 0; i < nInactiveNets; i++) {
if (!(net = virNetworkLookupByName(ctl->conn, names[i]))) if (!(net = virNetworkLookupByName(priv->conn, names[i])))
continue; continue;
list->nets[list->nnets++] = net; list->nets[list->nnets++] = net;
} }
...@@ -585,7 +589,7 @@ vshNetworkListCollect(vshControl *ctl, ...@@ -585,7 +589,7 @@ vshNetworkListCollect(vshControl *ctl,
/* sort the list */ /* sort the list */
if (list->nets && list->nnets) if (list->nets && list->nnets)
qsort(list->nets, list->nnets, qsort(list->nets, list->nnets,
sizeof(*list->nets), vshNetworkSorter); sizeof(*list->nets), virshNetworkSorter);
/* truncate the list if filter simulation deleted entries */ /* truncate the list if filter simulation deleted entries */
if (deleted) if (deleted)
...@@ -599,7 +603,7 @@ vshNetworkListCollect(vshControl *ctl, ...@@ -599,7 +603,7 @@ vshNetworkListCollect(vshControl *ctl,
VIR_FREE(names); VIR_FREE(names);
if (!success) { if (!success) {
vshNetworkListFree(list); virshNetworkListFree(list);
list = NULL; list = NULL;
} }
...@@ -665,7 +669,7 @@ static const vshCmdOptDef opts_network_list[] = { ...@@ -665,7 +669,7 @@ static const vshCmdOptDef opts_network_list[] = {
static bool static bool
cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{ {
vshNetworkListPtr list = NULL; virshNetworkListPtr list = NULL;
size_t i; size_t i;
bool ret = false; bool ret = false;
bool optName = vshCommandOptBool(cmd, "name"); bool optName = vshCommandOptBool(cmd, "name");
...@@ -697,7 +701,7 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) ...@@ -697,7 +701,7 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
if (!optUUID && !optName) if (!optUUID && !optName)
optTable = true; optTable = true;
if (!(list = vshNetworkListCollect(ctl, flags))) if (!(list = virshNetworkListCollect(ctl, flags)))
return false; return false;
if (optTable) { if (optTable) {
...@@ -736,7 +740,7 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) ...@@ -736,7 +740,7 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
ret = true; ret = true;
cleanup: cleanup:
vshNetworkListFree(list); virshNetworkListFree(list);
return ret; return ret;
} }
#undef FILTER #undef FILTER
...@@ -768,8 +772,8 @@ cmdNetworkName(vshControl *ctl, const vshCmd *cmd) ...@@ -768,8 +772,8 @@ cmdNetworkName(vshControl *ctl, const vshCmd *cmd)
{ {
virNetworkPtr network; virNetworkPtr network;
if (!(network = vshCommandOptNetworkBy(ctl, cmd, NULL, if (!(network = virshCommandOptNetworkBy(ctl, cmd, NULL,
VSH_BYUUID))) VIRSH_BYUUID)))
return false; return false;
vshPrint(ctl, "%s\n", virNetworkGetName(network)); vshPrint(ctl, "%s\n", virNetworkGetName(network));
...@@ -806,7 +810,7 @@ cmdNetworkStart(vshControl *ctl, const vshCmd *cmd) ...@@ -806,7 +810,7 @@ cmdNetworkStart(vshControl *ctl, const vshCmd *cmd)
bool ret = true; bool ret = true;
const char *name = NULL; const char *name = NULL;
if (!(network = vshCommandOptNetwork(ctl, cmd, &name))) if (!(network = virshCommandOptNetwork(ctl, cmd, &name)))
return false; return false;
if (virNetworkCreate(network) == 0) { if (virNetworkCreate(network) == 0) {
...@@ -848,7 +852,7 @@ cmdNetworkUndefine(vshControl *ctl, const vshCmd *cmd) ...@@ -848,7 +852,7 @@ cmdNetworkUndefine(vshControl *ctl, const vshCmd *cmd)
bool ret = true; bool ret = true;
const char *name; const char *name;
if (!(network = vshCommandOptNetwork(ctl, cmd, &name))) if (!(network = virshCommandOptNetwork(ctl, cmd, &name)))
return false; return false;
if (virNetworkUndefine(network) == 0) { if (virNetworkUndefine(network) == 0) {
...@@ -943,7 +947,7 @@ cmdNetworkUpdate(vshControl *ctl, const vshCmd *cmd) ...@@ -943,7 +947,7 @@ cmdNetworkUpdate(vshControl *ctl, const vshCmd *cmd)
unsigned int flags = 0; unsigned int flags = 0;
const char *affected; const char *affected;
if (!(network = vshCommandOptNetwork(ctl, cmd, NULL))) if (!(network = virshCommandOptNetwork(ctl, cmd, NULL)))
return false; return false;
if (vshCommandOptStringReq(ctl, cmd, "command", &commandStr) < 0) if (vshCommandOptStringReq(ctl, cmd, "command", &commandStr) < 0)
...@@ -1066,8 +1070,8 @@ cmdNetworkUuid(vshControl *ctl, const vshCmd *cmd) ...@@ -1066,8 +1070,8 @@ cmdNetworkUuid(vshControl *ctl, const vshCmd *cmd)
virNetworkPtr network; virNetworkPtr network;
char uuid[VIR_UUID_STRING_BUFLEN]; char uuid[VIR_UUID_STRING_BUFLEN];
if (!(network = vshCommandOptNetworkBy(ctl, cmd, NULL, if (!(network = virshCommandOptNetworkBy(ctl, cmd, NULL,
VSH_BYNAME))) VIRSH_BYNAME)))
return false; return false;
if (virNetworkGetUUIDString(network, uuid) != -1) if (virNetworkGetUUIDString(network, uuid) != -1)
...@@ -1101,7 +1105,7 @@ static const vshCmdOptDef opts_network_edit[] = { ...@@ -1101,7 +1105,7 @@ static const vshCmdOptDef opts_network_edit[] = {
{.name = NULL} {.name = NULL}
}; };
static char *vshNetworkGetXMLDesc(virNetworkPtr network) static char *virshNetworkGetXMLDesc(virNetworkPtr network)
{ {
unsigned int flags = VIR_NETWORK_XML_INACTIVE; unsigned int flags = VIR_NETWORK_XML_INACTIVE;
char *doc = virNetworkGetXMLDesc(network, flags); char *doc = virNetworkGetXMLDesc(network, flags);
...@@ -1123,12 +1127,13 @@ cmdNetworkEdit(vshControl *ctl, const vshCmd *cmd) ...@@ -1123,12 +1127,13 @@ cmdNetworkEdit(vshControl *ctl, const vshCmd *cmd)
bool ret = false; bool ret = false;
virNetworkPtr network = NULL; virNetworkPtr network = NULL;
virNetworkPtr network_edited = NULL; virNetworkPtr network_edited = NULL;
virshControlPtr priv = ctl->privData;
network = vshCommandOptNetwork(ctl, cmd, NULL); network = virshCommandOptNetwork(ctl, cmd, NULL);
if (network == NULL) if (network == NULL)
goto cleanup; goto cleanup;
#define EDIT_GET_XML vshNetworkGetXMLDesc(network) #define EDIT_GET_XML virshNetworkGetXMLDesc(network)
#define EDIT_NOT_CHANGED \ #define EDIT_NOT_CHANGED \
do { \ do { \
vshPrint(ctl, _("Network %s XML configuration not changed.\n"), \ vshPrint(ctl, _("Network %s XML configuration not changed.\n"), \
...@@ -1137,7 +1142,7 @@ cmdNetworkEdit(vshControl *ctl, const vshCmd *cmd) ...@@ -1137,7 +1142,7 @@ cmdNetworkEdit(vshControl *ctl, const vshCmd *cmd)
goto edit_cleanup; \ goto edit_cleanup; \
} while (0) } while (0)
#define EDIT_DEFINE \ #define EDIT_DEFINE \
(network_edited = virNetworkDefineXML(ctl->conn, doc_edited)) (network_edited = virNetworkDefineXML(priv->conn, doc_edited))
#include "virsh-edit.c" #include "virsh-edit.c"
vshPrint(ctl, _("Network %s XML configuration edited.\n"), vshPrint(ctl, _("Network %s XML configuration edited.\n"),
...@@ -1158,8 +1163,8 @@ cmdNetworkEdit(vshControl *ctl, const vshCmd *cmd) ...@@ -1158,8 +1163,8 @@ cmdNetworkEdit(vshControl *ctl, const vshCmd *cmd)
/* /*
* "net-event" command * "net-event" command
*/ */
VIR_ENUM_DECL(vshNetworkEvent) VIR_ENUM_DECL(virshNetworkEvent)
VIR_ENUM_IMPL(vshNetworkEvent, VIR_ENUM_IMPL(virshNetworkEvent,
VIR_NETWORK_EVENT_LAST, VIR_NETWORK_EVENT_LAST,
N_("Defined"), N_("Defined"),
N_("Undefined"), N_("Undefined"),
...@@ -1167,21 +1172,21 @@ VIR_ENUM_IMPL(vshNetworkEvent, ...@@ -1167,21 +1172,21 @@ VIR_ENUM_IMPL(vshNetworkEvent,
N_("Stopped")) N_("Stopped"))
static const char * static const char *
vshNetworkEventToString(int event) virshNetworkEventToString(int event)
{ {
const char *str = vshNetworkEventTypeToString(event); const char *str = virshNetworkEventTypeToString(event);
return str ? _(str) : _("unknown"); return str ? _(str) : _("unknown");
} }
struct vshNetEventData { struct virshNetEventData {
vshControl *ctl; vshControl *ctl;
bool loop; bool loop;
int count; int count;
}; };
typedef struct vshNetEventData vshNetEventData; typedef struct virshNetEventData virshNetEventData;
VIR_ENUM_DECL(vshNetworkEventId) VIR_ENUM_DECL(virshNetworkEventId)
VIR_ENUM_IMPL(vshNetworkEventId, VIR_ENUM_IMPL(virshNetworkEventId,
VIR_NETWORK_EVENT_ID_LAST, VIR_NETWORK_EVENT_ID_LAST,
"lifecycle") "lifecycle")
...@@ -1192,12 +1197,12 @@ vshEventLifecyclePrint(virConnectPtr conn ATTRIBUTE_UNUSED, ...@@ -1192,12 +1197,12 @@ vshEventLifecyclePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
int detail ATTRIBUTE_UNUSED, int detail ATTRIBUTE_UNUSED,
void *opaque) void *opaque)
{ {
vshNetEventData *data = opaque; virshNetEventData *data = opaque;
if (!data->loop && data->count) if (!data->loop && data->count)
return; return;
vshPrint(data->ctl, _("event 'lifecycle' for network %s: %s\n"), vshPrint(data->ctl, _("event 'lifecycle' for network %s: %s\n"),
virNetworkGetName(net), vshNetworkEventToString(event)); virNetworkGetName(net), virshNetworkEventToString(event));
data->count++; data->count++;
if (!data->loop) if (!data->loop)
vshEventDone(data->ctl); vshEventDone(data->ctl);
...@@ -1244,15 +1249,16 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd) ...@@ -1244,15 +1249,16 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd)
bool ret = false; bool ret = false;
int eventId = -1; int eventId = -1;
int timeout = 0; int timeout = 0;
vshNetEventData data; virshNetEventData data;
const char *eventName = NULL; const char *eventName = NULL;
int event; int event;
virshControlPtr priv = ctl->privData;
if (vshCommandOptBool(cmd, "list")) { if (vshCommandOptBool(cmd, "list")) {
size_t i; size_t i;
for (i = 0; i < VIR_NETWORK_EVENT_ID_LAST; i++) for (i = 0; i < VIR_NETWORK_EVENT_ID_LAST; i++)
vshPrint(ctl, "%s\n", vshNetworkEventIdTypeToString(i)); vshPrint(ctl, "%s\n", virshNetworkEventIdTypeToString(i));
return true; return true;
} }
...@@ -1262,7 +1268,7 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd) ...@@ -1262,7 +1268,7 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd)
vshError(ctl, "%s", _("either --list or event type is required")); vshError(ctl, "%s", _("either --list or event type is required"));
return false; return false;
} }
if ((event = vshNetworkEventIdTypeFromString(eventName)) < 0) { if ((event = virshNetworkEventIdTypeFromString(eventName)) < 0) {
vshError(ctl, _("unknown event type %s"), eventName); vshError(ctl, _("unknown event type %s"), eventName);
return false; return false;
} }
...@@ -1274,11 +1280,11 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd) ...@@ -1274,11 +1280,11 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd)
return false; return false;
if (vshCommandOptBool(cmd, "network")) if (vshCommandOptBool(cmd, "network"))
net = vshCommandOptNetwork(ctl, cmd, NULL); net = virshCommandOptNetwork(ctl, cmd, NULL);
if (vshEventStart(ctl, timeout) < 0) if (vshEventStart(ctl, timeout) < 0)
goto cleanup; goto cleanup;
if ((eventId = virConnectNetworkEventRegisterAny(ctl->conn, net, event, if ((eventId = virConnectNetworkEventRegisterAny(priv->conn, net, event,
VIR_NETWORK_EVENT_CALLBACK(vshEventLifecyclePrint), VIR_NETWORK_EVENT_CALLBACK(vshEventLifecyclePrint),
&data, NULL)) < 0) &data, NULL)) < 0)
goto cleanup; goto cleanup;
...@@ -1301,7 +1307,7 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd) ...@@ -1301,7 +1307,7 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd)
cleanup: cleanup:
vshEventCleanup(ctl); vshEventCleanup(ctl);
if (eventId >= 0 && if (eventId >= 0 &&
virConnectNetworkEventDeregisterAny(ctl->conn, eventId) < 0) virConnectNetworkEventDeregisterAny(priv->conn, eventId) < 0)
ret = false; ret = false;
if (net) if (net)
virNetworkFree(net); virNetworkFree(net);
...@@ -1337,7 +1343,7 @@ static const vshCmdOptDef opts_network_dhcp_leases[] = { ...@@ -1337,7 +1343,7 @@ static const vshCmdOptDef opts_network_dhcp_leases[] = {
}; };
static int static int
vshNetworkDHCPLeaseSorter(const void *a, const void *b) virshNetworkDHCPLeaseSorter(const void *a, const void *b)
{ {
int rv = -1; int rv = -1;
...@@ -1369,7 +1375,7 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd *cmd) ...@@ -1369,7 +1375,7 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptString(ctl, cmd, "mac", &mac) < 0) if (vshCommandOptString(ctl, cmd, "mac", &mac) < 0)
return false; return false;
if (!(network = vshCommandOptNetwork(ctl, cmd, &name))) if (!(network = virshCommandOptNetwork(ctl, cmd, &name)))
return false; return false;
if ((nleases = virNetworkGetDHCPLeases(network, mac, &leases, flags)) < 0) { if ((nleases = virNetworkGetDHCPLeases(network, mac, &leases, flags)) < 0) {
...@@ -1378,7 +1384,7 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd *cmd) ...@@ -1378,7 +1384,7 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd *cmd)
} }
/* Sort the list according to MAC Address/IAID */ /* Sort the list according to MAC Address/IAID */
qsort(leases, nleases, sizeof(*leases), vshNetworkDHCPLeaseSorter); qsort(leases, nleases, sizeof(*leases), virshNetworkDHCPLeaseSorter);
vshPrintExtra(ctl, " %-20s %-18s %-9s %-25s %-15s %s\n%s%s\n", vshPrintExtra(ctl, " %-20s %-18s %-9s %-25s %-15s %s\n%s%s\n",
_("Expiry Time"), _("MAC address"), _("Protocol"), _("Expiry Time"), _("MAC address"), _("Protocol"),
......
...@@ -29,13 +29,13 @@ ...@@ -29,13 +29,13 @@
# include "virsh.h" # include "virsh.h"
virNetworkPtr virNetworkPtr
vshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd, virshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd,
const char **name, unsigned int flags); const char **name, unsigned int flags);
/* default is lookup by Name and UUID */ /* default is lookup by Name and UUID */
# define vshCommandOptNetwork(_ctl, _cmd, _name) \ # define virshCommandOptNetwork(_ctl, _cmd, _name) \
vshCommandOptNetworkBy(_ctl, _cmd, _name, \ virshCommandOptNetworkBy(_ctl, _cmd, _name, \
VSH_BYUUID|VSH_BYNAME) VIRSH_BYUUID | VIRSH_BYNAME)
extern const vshCmdDef networkCmds[]; extern const vshCmdDef networkCmds[];
......
此差异已折叠。
此差异已折叠。
...@@ -29,13 +29,13 @@ ...@@ -29,13 +29,13 @@
# include "virsh.h" # include "virsh.h"
virNWFilterPtr virNWFilterPtr
vshCommandOptNWFilterBy(vshControl *ctl, const vshCmd *cmd, virshCommandOptNWFilterBy(vshControl *ctl, const vshCmd *cmd,
const char **name, unsigned int flags); const char **name, unsigned int flags);
/* default is lookup by Name and UUID */ /* default is lookup by Name and UUID */
# define vshCommandOptNWFilter(_ctl, _cmd, _name) \ # define virshCommandOptNWFilter(_ctl, _cmd, _name) \
vshCommandOptNWFilterBy(_ctl, _cmd, _name, \ virshCommandOptNWFilterBy(_ctl, _cmd, _name, \
VSH_BYUUID|VSH_BYNAME) VIRSH_BYUUID | VIRSH_BYNAME)
extern const vshCmdDef nwfilterCmds[]; extern const vshCmdDef nwfilterCmds[];
......
此差异已折叠。
...@@ -29,13 +29,13 @@ ...@@ -29,13 +29,13 @@
# include "virsh.h" # include "virsh.h"
virStoragePoolPtr virStoragePoolPtr
vshCommandOptPoolBy(vshControl *ctl, const vshCmd *cmd, const char *optname, virshCommandOptPoolBy(vshControl *ctl, const vshCmd *cmd, const char *optname,
const char **name, unsigned int flags); const char **name, unsigned int flags);
/* default is lookup by Name and UUID */ /* default is lookup by Name and UUID */
# define vshCommandOptPool(_ctl, _cmd, _optname, _name) \ # define virshCommandOptPool(_ctl, _cmd, _optname, _name) \
vshCommandOptPoolBy(_ctl, _cmd, _optname, _name, \ virshCommandOptPoolBy(_ctl, _cmd, _optname, _name, \
VSH_BYUUID|VSH_BYNAME) VIRSH_BYUUID | VIRSH_BYNAME)
extern const vshCmdDef storagePoolCmds[]; extern const vshCmdDef storagePoolCmds[];
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册