mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-04-26 15:14:42 +00:00
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.
This commit is contained in:
parent
b5d63e997b
commit
834c5720e4
2
cfg.mk
2
cfg.mk
@ -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
|
|||||||
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
|
|||||||
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;
|
|||||||
virStringSplitCount;
|
virStringSplitCount;
|
||||||
virStringStripControlChars;
|
virStringStripControlChars;
|
||||||
virStringStripIPv6Brackets;
|
virStringStripIPv6Brackets;
|
||||||
|
virStringToUpper;
|
||||||
virStrncpy;
|
virStrncpy;
|
||||||
virStrndup;
|
virStrndup;
|
||||||
virStrToDouble;
|
virStrToDouble;
|
||||||
|
@ -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);
|
|||||||
|
|
||||||
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 = \
|
|||||||
$(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,
|
|||||||
|
|
||||||
|
|
||||||
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)
|
|||||||
|
|
||||||
|
|
||||||
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,
|
|||||||
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 @@
|
|||||||
|
|
||||||
# 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 */
|
||||||
|
|
||||||
|
@ -40,24 +40,24 @@
|
|||||||
#include "virxml.h"
|
#include "virxml.h"
|
||||||
#include "virstring.h"
|
#include "virstring.h"
|
||||||
|
|
||||||
VIR_ENUM_DECL(vshDomainIOError)
|
VIR_ENUM_DECL(virshDomainIOError)
|
||||||
VIR_ENUM_IMPL(vshDomainIOError,
|
VIR_ENUM_IMPL(virshDomainIOError,
|
||||||
VIR_DOMAIN_DISK_ERROR_LAST,
|
VIR_DOMAIN_DISK_ERROR_LAST,
|
||||||
N_("no error"),
|
N_("no error"),
|
||||||
N_("unspecified error"),
|
N_("unspecified error"),
|
||||||
N_("no space"))
|
N_("no space"))
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
vshDomainIOErrorToString(int error)
|
virshDomainIOErrorToString(int error)
|
||||||
{
|
{
|
||||||
const char *str = vshDomainIOErrorTypeToString(error);
|
const char *str = virshDomainIOErrorTypeToString(error);
|
||||||
return str ? _(str) : _("unknown error");
|
return str ? _(str) : _("unknown error");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* extract description or title from domain xml */
|
/* extract description or title from domain xml */
|
||||||
char *
|
char *
|
||||||
vshGetDomainDescription(vshControl *ctl, virDomainPtr dom, bool title,
|
virshGetDomainDescription(vshControl *ctl, virDomainPtr dom, bool title,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
char *desc = NULL;
|
char *desc = NULL;
|
||||||
char *domxml = NULL;
|
char *domxml = NULL;
|
||||||
@ -113,8 +113,8 @@ vshGetDomainDescription(vshControl *ctl, virDomainPtr dom, bool title,
|
|||||||
return desc;
|
return desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_ENUM_DECL(vshDomainControlState)
|
VIR_ENUM_DECL(virshDomainControlState)
|
||||||
VIR_ENUM_IMPL(vshDomainControlState,
|
VIR_ENUM_IMPL(virshDomainControlState,
|
||||||
VIR_DOMAIN_CONTROL_LAST,
|
VIR_DOMAIN_CONTROL_LAST,
|
||||||
N_("ok"),
|
N_("ok"),
|
||||||
N_("background job"),
|
N_("background job"),
|
||||||
@ -122,14 +122,14 @@ VIR_ENUM_IMPL(vshDomainControlState,
|
|||||||
N_("error"))
|
N_("error"))
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
vshDomainControlStateToString(int state)
|
virshDomainControlStateToString(int state)
|
||||||
{
|
{
|
||||||
const char *str = vshDomainControlStateTypeToString(state);
|
const char *str = virshDomainControlStateTypeToString(state);
|
||||||
return str ? _(str) : _("unknown");
|
return str ? _(str) : _("unknown");
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_ENUM_DECL(vshDomainControlErrorReason)
|
VIR_ENUM_DECL(virshDomainControlErrorReason)
|
||||||
VIR_ENUM_IMPL(vshDomainControlErrorReason,
|
VIR_ENUM_IMPL(virshDomainControlErrorReason,
|
||||||
VIR_DOMAIN_CONTROL_ERROR_REASON_LAST,
|
VIR_DOMAIN_CONTROL_ERROR_REASON_LAST,
|
||||||
"",
|
"",
|
||||||
N_("unknown"),
|
N_("unknown"),
|
||||||
@ -137,14 +137,14 @@ VIR_ENUM_IMPL(vshDomainControlErrorReason,
|
|||||||
N_("internal (locking) error"))
|
N_("internal (locking) error"))
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
vshDomainControlErrorReasonToString(int reason)
|
virshDomainControlErrorReasonToString(int reason)
|
||||||
{
|
{
|
||||||
const char *ret = vshDomainControlErrorReasonTypeToString(reason);
|
const char *ret = virshDomainControlErrorReasonTypeToString(reason);
|
||||||
return ret ? _(ret) : _("unknown");
|
return ret ? _(ret) : _("unknown");
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_ENUM_DECL(vshDomainState)
|
VIR_ENUM_DECL(virshDomainState)
|
||||||
VIR_ENUM_IMPL(vshDomainState,
|
VIR_ENUM_IMPL(virshDomainState,
|
||||||
VIR_DOMAIN_LAST,
|
VIR_DOMAIN_LAST,
|
||||||
N_("no state"),
|
N_("no state"),
|
||||||
N_("running"),
|
N_("running"),
|
||||||
@ -156,19 +156,19 @@ VIR_ENUM_IMPL(vshDomainState,
|
|||||||
N_("pmsuspended"))
|
N_("pmsuspended"))
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
vshDomainStateToString(int state)
|
virshDomainStateToString(int state)
|
||||||
{
|
{
|
||||||
const char *str = vshDomainStateTypeToString(state);
|
const char *str = virshDomainStateTypeToString(state);
|
||||||
return str ? _(str) : _("no state");
|
return str ? _(str) : _("no state");
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_ENUM_DECL(vshDomainNostateReason)
|
VIR_ENUM_DECL(virshDomainNostateReason)
|
||||||
VIR_ENUM_IMPL(vshDomainNostateReason,
|
VIR_ENUM_IMPL(virshDomainNostateReason,
|
||||||
VIR_DOMAIN_NOSTATE_LAST,
|
VIR_DOMAIN_NOSTATE_LAST,
|
||||||
N_("unknown"))
|
N_("unknown"))
|
||||||
|
|
||||||
VIR_ENUM_DECL(vshDomainRunningReason)
|
VIR_ENUM_DECL(virshDomainRunningReason)
|
||||||
VIR_ENUM_IMPL(vshDomainRunningReason,
|
VIR_ENUM_IMPL(virshDomainRunningReason,
|
||||||
VIR_DOMAIN_RUNNING_LAST,
|
VIR_DOMAIN_RUNNING_LAST,
|
||||||
N_("unknown"),
|
N_("unknown"),
|
||||||
N_("booted"),
|
N_("booted"),
|
||||||
@ -181,13 +181,13 @@ VIR_ENUM_IMPL(vshDomainRunningReason,
|
|||||||
N_("event wakeup"),
|
N_("event wakeup"),
|
||||||
N_("crashed"))
|
N_("crashed"))
|
||||||
|
|
||||||
VIR_ENUM_DECL(vshDomainBlockedReason)
|
VIR_ENUM_DECL(virshDomainBlockedReason)
|
||||||
VIR_ENUM_IMPL(vshDomainBlockedReason,
|
VIR_ENUM_IMPL(virshDomainBlockedReason,
|
||||||
VIR_DOMAIN_BLOCKED_LAST,
|
VIR_DOMAIN_BLOCKED_LAST,
|
||||||
N_("unknown"))
|
N_("unknown"))
|
||||||
|
|
||||||
VIR_ENUM_DECL(vshDomainPausedReason)
|
VIR_ENUM_DECL(virshDomainPausedReason)
|
||||||
VIR_ENUM_IMPL(vshDomainPausedReason,
|
VIR_ENUM_IMPL(virshDomainPausedReason,
|
||||||
VIR_DOMAIN_PAUSED_LAST,
|
VIR_DOMAIN_PAUSED_LAST,
|
||||||
N_("unknown"),
|
N_("unknown"),
|
||||||
N_("user"),
|
N_("user"),
|
||||||
@ -202,14 +202,14 @@ VIR_ENUM_IMPL(vshDomainPausedReason,
|
|||||||
N_("crashed"),
|
N_("crashed"),
|
||||||
N_("starting up"))
|
N_("starting up"))
|
||||||
|
|
||||||
VIR_ENUM_DECL(vshDomainShutdownReason)
|
VIR_ENUM_DECL(virshDomainShutdownReason)
|
||||||
VIR_ENUM_IMPL(vshDomainShutdownReason,
|
VIR_ENUM_IMPL(virshDomainShutdownReason,
|
||||||
VIR_DOMAIN_SHUTDOWN_LAST,
|
VIR_DOMAIN_SHUTDOWN_LAST,
|
||||||
N_("unknown"),
|
N_("unknown"),
|
||||||
N_("user"))
|
N_("user"))
|
||||||
|
|
||||||
VIR_ENUM_DECL(vshDomainShutoffReason)
|
VIR_ENUM_DECL(virshDomainShutoffReason)
|
||||||
VIR_ENUM_IMPL(vshDomainShutoffReason,
|
VIR_ENUM_IMPL(virshDomainShutoffReason,
|
||||||
VIR_DOMAIN_SHUTOFF_LAST,
|
VIR_DOMAIN_SHUTOFF_LAST,
|
||||||
N_("unknown"),
|
N_("unknown"),
|
||||||
N_("shutdown"),
|
N_("shutdown"),
|
||||||
@ -220,45 +220,45 @@ VIR_ENUM_IMPL(vshDomainShutoffReason,
|
|||||||
N_("failed"),
|
N_("failed"),
|
||||||
N_("from snapshot"))
|
N_("from snapshot"))
|
||||||
|
|
||||||
VIR_ENUM_DECL(vshDomainCrashedReason)
|
VIR_ENUM_DECL(virshDomainCrashedReason)
|
||||||
VIR_ENUM_IMPL(vshDomainCrashedReason,
|
VIR_ENUM_IMPL(virshDomainCrashedReason,
|
||||||
VIR_DOMAIN_CRASHED_LAST,
|
VIR_DOMAIN_CRASHED_LAST,
|
||||||
N_("unknown"),
|
N_("unknown"),
|
||||||
N_("panicked"))
|
N_("panicked"))
|
||||||
|
|
||||||
VIR_ENUM_DECL(vshDomainPMSuspendedReason)
|
VIR_ENUM_DECL(virshDomainPMSuspendedReason)
|
||||||
VIR_ENUM_IMPL(vshDomainPMSuspendedReason,
|
VIR_ENUM_IMPL(virshDomainPMSuspendedReason,
|
||||||
VIR_DOMAIN_PMSUSPENDED_LAST,
|
VIR_DOMAIN_PMSUSPENDED_LAST,
|
||||||
N_("unknown"))
|
N_("unknown"))
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
vshDomainStateReasonToString(int state, int reason)
|
virshDomainStateReasonToString(int state, int reason)
|
||||||
{
|
{
|
||||||
const char *str = NULL;
|
const char *str = NULL;
|
||||||
switch ((virDomainState) state) {
|
switch ((virDomainState) state) {
|
||||||
case VIR_DOMAIN_NOSTATE:
|
case VIR_DOMAIN_NOSTATE:
|
||||||
str = vshDomainNostateReasonTypeToString(reason);
|
str = virshDomainNostateReasonTypeToString(reason);
|
||||||
break;
|
break;
|
||||||
case VIR_DOMAIN_RUNNING:
|
case VIR_DOMAIN_RUNNING:
|
||||||
str = vshDomainRunningReasonTypeToString(reason);
|
str = virshDomainRunningReasonTypeToString(reason);
|
||||||
break;
|
break;
|
||||||
case VIR_DOMAIN_BLOCKED:
|
case VIR_DOMAIN_BLOCKED:
|
||||||
str = vshDomainBlockedReasonTypeToString(reason);
|
str = virshDomainBlockedReasonTypeToString(reason);
|
||||||
break;
|
break;
|
||||||
case VIR_DOMAIN_PAUSED:
|
case VIR_DOMAIN_PAUSED:
|
||||||
str = vshDomainPausedReasonTypeToString(reason);
|
str = virshDomainPausedReasonTypeToString(reason);
|
||||||
break;
|
break;
|
||||||
case VIR_DOMAIN_SHUTDOWN:
|
case VIR_DOMAIN_SHUTDOWN:
|
||||||
str = vshDomainShutdownReasonTypeToString(reason);
|
str = virshDomainShutdownReasonTypeToString(reason);
|
||||||
break;
|
break;
|
||||||
case VIR_DOMAIN_SHUTOFF:
|
case VIR_DOMAIN_SHUTOFF:
|
||||||
str = vshDomainShutoffReasonTypeToString(reason);
|
str = virshDomainShutoffReasonTypeToString(reason);
|
||||||
break;
|
break;
|
||||||
case VIR_DOMAIN_CRASHED:
|
case VIR_DOMAIN_CRASHED:
|
||||||
str = vshDomainCrashedReasonTypeToString(reason);
|
str = virshDomainCrashedReasonTypeToString(reason);
|
||||||
break;
|
break;
|
||||||
case VIR_DOMAIN_PMSUSPENDED:
|
case VIR_DOMAIN_PMSUSPENDED:
|
||||||
str = vshDomainPMSuspendedReasonTypeToString(reason);
|
str = virshDomainPMSuspendedReasonTypeToString(reason);
|
||||||
break;
|
break;
|
||||||
case VIR_DOMAIN_LAST:
|
case VIR_DOMAIN_LAST:
|
||||||
;
|
;
|
||||||
@ -329,7 +329,7 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (live)
|
if (live)
|
||||||
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
||||||
|
|
||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
if (!(dom = virshCommandOptDomain(ctl, cmd, &name)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* If none of the options were specified and we're active
|
/* If none of the options were specified and we're active
|
||||||
@ -423,7 +423,7 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd)
|
|||||||
bool ret = false;
|
bool ret = false;
|
||||||
const char *device = NULL;
|
const char *device = NULL;
|
||||||
|
|
||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "device", &device) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "device", &device) < 0)
|
||||||
@ -492,7 +492,7 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd)
|
|||||||
|
|
||||||
details = vshCommandOptBool(cmd, "details");
|
details = vshCommandOptBool(cmd, "details");
|
||||||
|
|
||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
xml = virDomainGetXMLDesc(dom, flags);
|
xml = virDomainGetXMLDesc(dom, flags);
|
||||||
@ -608,7 +608,7 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (vshCommandOptBool(cmd, "inactive"))
|
if (vshCommandOptBool(cmd, "inactive"))
|
||||||
flags |= VIR_DOMAIN_XML_INACTIVE;
|
flags |= VIR_DOMAIN_XML_INACTIVE;
|
||||||
|
|
||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
xml = virDomainGetXMLDesc(dom, flags);
|
xml = virDomainGetXMLDesc(dom, flags);
|
||||||
@ -726,7 +726,7 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (vshCommandOptStringReq(ctl, cmd, "interface", &iface) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "interface", &iface) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (vshCommandOptBool(cmd, "config"))
|
if (vshCommandOptBool(cmd, "config"))
|
||||||
@ -815,7 +815,7 @@ cmdDomControl(vshControl *ctl, const vshCmd *cmd)
|
|||||||
bool ret = true;
|
bool ret = true;
|
||||||
virDomainControlInfo info;
|
virDomainControlInfo info;
|
||||||
|
|
||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (virDomainGetControlInfo(dom, &info, 0) < 0) {
|
if (virDomainGetControlInfo(dom, &info, 0) < 0) {
|
||||||
@ -826,15 +826,15 @@ cmdDomControl(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (info.state != VIR_DOMAIN_CONTROL_OK &&
|
if (info.state != VIR_DOMAIN_CONTROL_OK &&
|
||||||
info.state != VIR_DOMAIN_CONTROL_ERROR) {
|
info.state != VIR_DOMAIN_CONTROL_ERROR) {
|
||||||
vshPrint(ctl, "%s (%0.3fs)\n",
|
vshPrint(ctl, "%s (%0.3fs)\n",
|
||||||
vshDomainControlStateToString(info.state),
|
virshDomainControlStateToString(info.state),
|
||||||
info.stateTime / 1000.0);
|
info.stateTime / 1000.0);
|
||||||
} else if (info.state == VIR_DOMAIN_CONTROL_ERROR && info.details > 0) {
|
} else if (info.state == VIR_DOMAIN_CONTROL_ERROR && info.details > 0) {
|
||||||
vshPrint(ctl, "%s: %s\n",
|
vshPrint(ctl, "%s: %s\n",
|
||||||
vshDomainControlStateToString(info.state),
|
virshDomainControlStateToString(info.state),
|
||||||
vshDomainControlErrorReasonToString(info.details));
|
virshDomainControlErrorReasonToString(info.details));
|
||||||
} else {
|
} else {
|
||||||
vshPrint(ctl, "%s\n",
|
vshPrint(ctl, "%s\n",
|
||||||
vshDomainControlStateToString(info.state));
|
virshDomainControlStateToString(info.state));
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
@ -927,7 +927,7 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd)
|
|||||||
bool ret = false;
|
bool ret = false;
|
||||||
bool human = vshCommandOptBool(cmd, "human"); /* human readable output */
|
bool human = vshCommandOptBool(cmd, "human"); /* human readable output */
|
||||||
|
|
||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
if (!(dom = virshCommandOptDomain(ctl, cmd, &name)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* device argument is optional now. if it's missing, supply empty
|
/* device argument is optional now. if it's missing, supply empty
|
||||||
@ -1068,7 +1068,7 @@ cmdDomIfstat(vshControl *ctl, const vshCmd *cmd)
|
|||||||
virDomainInterfaceStatsStruct stats;
|
virDomainInterfaceStatsStruct stats;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
if (!(dom = virshCommandOptDomain(ctl, cmd, &name)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "interface", &device) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "interface", &device) < 0)
|
||||||
@ -1142,7 +1142,7 @@ cmdDomBlkError(vshControl *ctl, const vshCmd *cmd)
|
|||||||
int count;
|
int count;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ((count = virDomainGetDiskErrors(dom, NULL, 0, 0)) < 0)
|
if ((count = virDomainGetDiskErrors(dom, NULL, 0, 0)) < 0)
|
||||||
@ -1163,7 +1163,7 @@ cmdDomBlkError(vshControl *ctl, const vshCmd *cmd)
|
|||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
vshPrint(ctl, "%s: %s\n",
|
vshPrint(ctl, "%s: %s\n",
|
||||||
disks[i].disk,
|
disks[i].disk,
|
||||||
vshDomainIOErrorToString(disks[i].error));
|
virshDomainIOErrorToString(disks[i].error));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1210,8 +1210,9 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd)
|
|||||||
unsigned int id;
|
unsigned int id;
|
||||||
char *str, uuid[VIR_UUID_STRING_BUFLEN];
|
char *str, uuid[VIR_UUID_STRING_BUFLEN];
|
||||||
int has_managed_save = 0;
|
int has_managed_save = 0;
|
||||||
|
virshControlPtr priv = ctl->privData;
|
||||||
|
|
||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
id = virDomainGetID(dom);
|
id = virDomainGetID(dom);
|
||||||
@ -1231,7 +1232,7 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd)
|
|||||||
|
|
||||||
if (virDomainGetInfo(dom, &info) == 0) {
|
if (virDomainGetInfo(dom, &info) == 0) {
|
||||||
vshPrint(ctl, "%-15s %s\n", _("State:"),
|
vshPrint(ctl, "%-15s %s\n", _("State:"),
|
||||||
vshDomainStateToString(info.state));
|
virshDomainStateToString(info.state));
|
||||||
|
|
||||||
vshPrint(ctl, "%-15s %d\n", _("CPU(s):"), info.nrVirtCpu);
|
vshPrint(ctl, "%-15s %d\n", _("CPU(s):"), info.nrVirtCpu);
|
||||||
|
|
||||||
@ -1281,7 +1282,7 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd)
|
|||||||
|
|
||||||
/* Security model and label information */
|
/* Security model and label information */
|
||||||
memset(&secmodel, 0, sizeof(secmodel));
|
memset(&secmodel, 0, sizeof(secmodel));
|
||||||
if (virNodeGetSecurityModel(ctl->conn, &secmodel) == -1) {
|
if (virNodeGetSecurityModel(priv->conn, &secmodel) == -1) {
|
||||||
if (last_error->code != VIR_ERR_NO_SUPPORT) {
|
if (last_error->code != VIR_ERR_NO_SUPPORT) {
|
||||||
virDomainFree(dom);
|
virDomainFree(dom);
|
||||||
return false;
|
return false;
|
||||||
@ -1351,21 +1352,21 @@ cmdDomstate(vshControl *ctl, const vshCmd *cmd)
|
|||||||
bool showReason = vshCommandOptBool(cmd, "reason");
|
bool showReason = vshCommandOptBool(cmd, "reason");
|
||||||
int state, reason;
|
int state, reason;
|
||||||
|
|
||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ((state = vshDomainState(ctl, dom, &reason)) < 0) {
|
if ((state = virshDomainState(ctl, dom, &reason)) < 0) {
|
||||||
ret = false;
|
ret = false;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showReason) {
|
if (showReason) {
|
||||||
vshPrint(ctl, "%s (%s)\n",
|
vshPrint(ctl, "%s (%s)\n",
|
||||||
vshDomainStateToString(state),
|
virshDomainStateToString(state),
|
||||||
vshDomainStateReasonToString(state, reason));
|
virshDomainStateReasonToString(state, reason));
|
||||||
} else {
|
} else {
|
||||||
vshPrint(ctl, "%s\n",
|
vshPrint(ctl, "%s\n",
|
||||||
vshDomainStateToString(state));
|
virshDomainStateToString(state));
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
@ -1429,7 +1430,7 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd)
|
|||||||
VSH_EXCLUSIVE_OPTIONS("time", "sync");
|
VSH_EXCLUSIVE_OPTIONS("time", "sync");
|
||||||
VSH_EXCLUSIVE_OPTIONS("now", "sync");
|
VSH_EXCLUSIVE_OPTIONS("now", "sync");
|
||||||
|
|
||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
rv = vshCommandOptLongLong(ctl, cmd, "time", &seconds);
|
rv = vshCommandOptLongLong(ctl, cmd, "time", &seconds);
|
||||||
@ -1496,7 +1497,7 @@ static const vshCmdInfo info_list[] = {
|
|||||||
|
|
||||||
/* compare domains, pack NULLed ones at the end*/
|
/* compare domains, pack NULLed ones at the end*/
|
||||||
static int
|
static int
|
||||||
vshDomainSorter(const void *a, const void *b)
|
virshDomainSorter(const void *a, const void *b)
|
||||||
{
|
{
|
||||||
virDomainPtr *da = (virDomainPtr *) a;
|
virDomainPtr *da = (virDomainPtr *) a;
|
||||||
virDomainPtr *db = (virDomainPtr *) b;
|
virDomainPtr *db = (virDomainPtr *) b;
|
||||||
@ -1529,14 +1530,14 @@ vshDomainSorter(const void *a, const void *b)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct vshDomainList {
|
struct virshDomainList {
|
||||||
virDomainPtr *domains;
|
virDomainPtr *domains;
|
||||||
size_t ndomains;
|
size_t ndomains;
|
||||||
};
|
};
|
||||||
typedef struct vshDomainList *vshDomainListPtr;
|
typedef struct virshDomainList *virshDomainListPtr;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
vshDomainListFree(vshDomainListPtr domlist)
|
virshDomainListFree(virshDomainListPtr domlist)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
@ -1550,10 +1551,10 @@ vshDomainListFree(vshDomainListPtr domlist)
|
|||||||
VIR_FREE(domlist);
|
VIR_FREE(domlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
static vshDomainListPtr
|
static virshDomainListPtr
|
||||||
vshDomainListCollect(vshControl *ctl, unsigned int flags)
|
virshDomainListCollect(vshControl *ctl, unsigned int flags)
|
||||||
{
|
{
|
||||||
vshDomainListPtr list = vshMalloc(ctl, sizeof(*list));
|
virshDomainListPtr list = vshMalloc(ctl, sizeof(*list));
|
||||||
size_t i;
|
size_t i;
|
||||||
int ret;
|
int ret;
|
||||||
int *ids = NULL;
|
int *ids = NULL;
|
||||||
@ -1568,9 +1569,10 @@ vshDomainListCollect(vshControl *ctl, unsigned int flags)
|
|||||||
int state;
|
int state;
|
||||||
int nsnap;
|
int nsnap;
|
||||||
int mansave;
|
int mansave;
|
||||||
|
virshControlPtr priv = ctl->privData;
|
||||||
|
|
||||||
/* try the list with flags support (0.9.13 and later) */
|
/* try the list with flags support (0.9.13 and later) */
|
||||||
if ((ret = virConnectListAllDomains(ctl->conn, &list->domains,
|
if ((ret = virConnectListAllDomains(priv->conn, &list->domains,
|
||||||
flags)) >= 0) {
|
flags)) >= 0) {
|
||||||
list->ndomains = ret;
|
list->ndomains = ret;
|
||||||
goto finished;
|
goto finished;
|
||||||
@ -1588,7 +1590,7 @@ vshDomainListCollect(vshControl *ctl, unsigned int flags)
|
|||||||
VIR_CONNECT_LIST_DOMAINS_INACTIVE);
|
VIR_CONNECT_LIST_DOMAINS_INACTIVE);
|
||||||
|
|
||||||
vshResetLibvirtError();
|
vshResetLibvirtError();
|
||||||
if ((ret = virConnectListAllDomains(ctl->conn, &list->domains,
|
if ((ret = virConnectListAllDomains(priv->conn, &list->domains,
|
||||||
newflags)) >= 0) {
|
newflags)) >= 0) {
|
||||||
list->ndomains = ret;
|
list->ndomains = ret;
|
||||||
goto filter;
|
goto filter;
|
||||||
@ -1607,7 +1609,7 @@ vshDomainListCollect(vshControl *ctl, unsigned int flags)
|
|||||||
/* list active domains, if necessary */
|
/* list active domains, if necessary */
|
||||||
if (!VSH_MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE) ||
|
if (!VSH_MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE) ||
|
||||||
VSH_MATCH(VIR_CONNECT_LIST_DOMAINS_ACTIVE)) {
|
VSH_MATCH(VIR_CONNECT_LIST_DOMAINS_ACTIVE)) {
|
||||||
if ((nids = virConnectNumOfDomains(ctl->conn)) < 0) {
|
if ((nids = virConnectNumOfDomains(priv->conn)) < 0) {
|
||||||
vshError(ctl, "%s", _("Failed to list active domains"));
|
vshError(ctl, "%s", _("Failed to list active domains"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -1615,7 +1617,7 @@ vshDomainListCollect(vshControl *ctl, unsigned int flags)
|
|||||||
if (nids) {
|
if (nids) {
|
||||||
ids = vshMalloc(ctl, sizeof(int) * nids);
|
ids = vshMalloc(ctl, sizeof(int) * nids);
|
||||||
|
|
||||||
if ((nids = virConnectListDomains(ctl->conn, ids, nids)) < 0) {
|
if ((nids = virConnectListDomains(priv->conn, ids, nids)) < 0) {
|
||||||
vshError(ctl, "%s", _("Failed to list active domains"));
|
vshError(ctl, "%s", _("Failed to list active domains"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -1624,7 +1626,7 @@ vshDomainListCollect(vshControl *ctl, unsigned int flags)
|
|||||||
|
|
||||||
if (!VSH_MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE) ||
|
if (!VSH_MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE) ||
|
||||||
VSH_MATCH(VIR_CONNECT_LIST_DOMAINS_INACTIVE)) {
|
VSH_MATCH(VIR_CONNECT_LIST_DOMAINS_INACTIVE)) {
|
||||||
if ((nnames = virConnectNumOfDefinedDomains(ctl->conn)) < 0) {
|
if ((nnames = virConnectNumOfDefinedDomains(priv->conn)) < 0) {
|
||||||
vshError(ctl, "%s", _("Failed to list inactive domains"));
|
vshError(ctl, "%s", _("Failed to list inactive domains"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -1632,7 +1634,7 @@ vshDomainListCollect(vshControl *ctl, unsigned int flags)
|
|||||||
if (nnames) {
|
if (nnames) {
|
||||||
names = vshMalloc(ctl, sizeof(char *) * nnames);
|
names = vshMalloc(ctl, sizeof(char *) * nnames);
|
||||||
|
|
||||||
if ((nnames = virConnectListDefinedDomains(ctl->conn, names,
|
if ((nnames = virConnectListDefinedDomains(priv->conn, names,
|
||||||
nnames)) < 0) {
|
nnames)) < 0) {
|
||||||
vshError(ctl, "%s", _("Failed to list inactive domains"));
|
vshError(ctl, "%s", _("Failed to list inactive domains"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1645,14 +1647,14 @@ vshDomainListCollect(vshControl *ctl, unsigned int flags)
|
|||||||
|
|
||||||
/* get active domains */
|
/* get active domains */
|
||||||
for (i = 0; i < nids; i++) {
|
for (i = 0; i < nids; i++) {
|
||||||
if (!(dom = virDomainLookupByID(ctl->conn, ids[i])))
|
if (!(dom = virDomainLookupByID(priv->conn, ids[i])))
|
||||||
continue;
|
continue;
|
||||||
list->domains[list->ndomains++] = dom;
|
list->domains[list->ndomains++] = dom;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get inactive domains */
|
/* get inactive domains */
|
||||||
for (i = 0; i < nnames; i++) {
|
for (i = 0; i < nnames; i++) {
|
||||||
if (!(dom = virDomainLookupByName(ctl->conn, names[i])))
|
if (!(dom = virDomainLookupByName(priv->conn, names[i])))
|
||||||
continue;
|
continue;
|
||||||
list->domains[list->ndomains++] = dom;
|
list->domains[list->ndomains++] = dom;
|
||||||
}
|
}
|
||||||
@ -1747,7 +1749,7 @@ vshDomainListCollect(vshControl *ctl, unsigned int flags)
|
|||||||
/* sort the list */
|
/* sort the list */
|
||||||
if (list->domains && list->ndomains)
|
if (list->domains && list->ndomains)
|
||||||
qsort(list->domains, list->ndomains, sizeof(*list->domains),
|
qsort(list->domains, list->ndomains, sizeof(*list->domains),
|
||||||
vshDomainSorter);
|
virshDomainSorter);
|
||||||
|
|
||||||
/* truncate the list if filter simulation deleted entries */
|
/* truncate the list if filter simulation deleted entries */
|
||||||
if (deleted)
|
if (deleted)
|
||||||
@ -1760,7 +1762,7 @@ vshDomainListCollect(vshControl *ctl, unsigned int flags)
|
|||||||
VIR_FREE(names[i]);
|
VIR_FREE(names[i]);
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
vshDomainListFree(list);
|
virshDomainListFree(list);
|
||||||
list = NULL;
|
list = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1865,7 +1867,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
|
|||||||
char uuid[VIR_UUID_STRING_BUFLEN];
|
char uuid[VIR_UUID_STRING_BUFLEN];
|
||||||
int state;
|
int state;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
vshDomainListPtr list = NULL;
|
virshDomainListPtr list = NULL;
|
||||||
virDomainPtr dom;
|
virDomainPtr dom;
|
||||||
char id_buf[INT_BUFSIZE_BOUND(unsigned int)];
|
char id_buf[INT_BUFSIZE_BOUND(unsigned int)];
|
||||||
unsigned int id;
|
unsigned int id;
|
||||||
@ -1906,7 +1908,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (!optUUID && !optName)
|
if (!optUUID && !optName)
|
||||||
optTable = true;
|
optTable = true;
|
||||||
|
|
||||||
if (!(list = vshDomainListCollect(ctl, flags)))
|
if (!(list = virshDomainListCollect(ctl, flags)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
/* print table header in legacy mode */
|
/* print table header in legacy mode */
|
||||||
@ -1931,7 +1933,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
|
|||||||
else
|
else
|
||||||
ignore_value(virStrcpyStatic(id_buf, "-"));
|
ignore_value(virStrcpyStatic(id_buf, "-"));
|
||||||
|
|
||||||
state = vshDomainState(ctl, dom, NULL);
|
state = virshDomainState(ctl, dom, NULL);
|
||||||
|
|
||||||
/* Domain could've been removed in the meantime */
|
/* Domain could've been removed in the meantime */
|
||||||
if (state < 0)
|
if (state < 0)
|
||||||
@ -1943,19 +1945,21 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
|
|||||||
|
|
||||||
if (optTable) {
|
if (optTable) {
|
||||||
if (optTitle) {
|
if (optTitle) {
|
||||||
if (!(title = vshGetDomainDescription(ctl, dom, true, 0)))
|
if (!(title = virshGetDomainDescription(ctl, dom, true, 0)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
vshPrint(ctl, " %-5s %-30s %-10s %-20s\n", id_buf,
|
vshPrint(ctl, " %-5s %-30s %-10s %-20s\n", id_buf,
|
||||||
virDomainGetName(dom),
|
virDomainGetName(dom),
|
||||||
state == -2 ? _("saved") : vshDomainStateToString(state),
|
state == -2 ? _("saved")
|
||||||
|
: virshDomainStateToString(state),
|
||||||
title);
|
title);
|
||||||
|
|
||||||
VIR_FREE(title);
|
VIR_FREE(title);
|
||||||
} else {
|
} else {
|
||||||
vshPrint(ctl, " %-5s %-30s %s\n", id_buf,
|
vshPrint(ctl, " %-5s %-30s %s\n", id_buf,
|
||||||
virDomainGetName(dom),
|
virDomainGetName(dom),
|
||||||
state == -2 ? _("saved") : vshDomainStateToString(state));
|
state == -2 ? _("saved")
|
||||||
|
: virshDomainStateToString(state));
|
||||||
}
|
}
|
||||||
} else if (optUUID) {
|
} else if (optUUID) {
|
||||||
if (virDomainGetUUIDString(dom, uuid) < 0) {
|
if (virDomainGetUUIDString(dom, uuid) < 0) {
|
||||||
@ -1970,7 +1974,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
|
|||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
cleanup:
|
cleanup:
|
||||||
vshDomainListFree(list);
|
virshDomainListFree(list);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#undef FILTER
|
#undef FILTER
|
||||||
@ -2067,9 +2071,9 @@ static const vshCmdOptDef opts_domstats[] = {
|
|||||||
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
vshDomainStatsPrintRecord(vshControl *ctl ATTRIBUTE_UNUSED,
|
virshDomainStatsPrintRecord(vshControl *ctl ATTRIBUTE_UNUSED,
|
||||||
virDomainStatsRecordPtr record,
|
virDomainStatsRecordPtr record,
|
||||||
bool raw ATTRIBUTE_UNUSED)
|
bool raw ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
char *param;
|
char *param;
|
||||||
size_t i;
|
size_t i;
|
||||||
@ -2104,6 +2108,7 @@ cmdDomstats(vshControl *ctl, const vshCmd *cmd)
|
|||||||
int flags = 0;
|
int flags = 0;
|
||||||
const vshCmdOpt *opt = NULL;
|
const vshCmdOpt *opt = NULL;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
virshControlPtr priv = ctl->privData;
|
||||||
|
|
||||||
if (vshCommandOptBool(cmd, "state"))
|
if (vshCommandOptBool(cmd, "state"))
|
||||||
stats |= VIR_DOMAIN_STATS_STATE;
|
stats |= VIR_DOMAIN_STATS_STATE;
|
||||||
@ -2159,8 +2164,9 @@ cmdDomstats(vshControl *ctl, const vshCmd *cmd)
|
|||||||
ndoms = 1;
|
ndoms = 1;
|
||||||
|
|
||||||
while ((opt = vshCommandOptArgv(ctl, cmd, opt))) {
|
while ((opt = vshCommandOptArgv(ctl, cmd, opt))) {
|
||||||
if (!(dom = vshLookupDomainBy(ctl, opt->data,
|
if (!(dom = virshLookupDomainBy(ctl, opt->data,
|
||||||
VSH_BYID | VSH_BYUUID | VSH_BYNAME)))
|
VIRSH_BYID |
|
||||||
|
VIRSH_BYUUID | VIRSH_BYNAME)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (VIR_INSERT_ELEMENT(domlist, ndoms - 1, ndoms, dom) < 0)
|
if (VIR_INSERT_ELEMENT(domlist, ndoms - 1, ndoms, dom) < 0)
|
||||||
@ -2173,7 +2179,7 @@ cmdDomstats(vshControl *ctl, const vshCmd *cmd)
|
|||||||
flags) < 0)
|
flags) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
} else {
|
} else {
|
||||||
if ((virConnectGetAllDomainStats(ctl->conn,
|
if ((virConnectGetAllDomainStats(priv->conn,
|
||||||
stats,
|
stats,
|
||||||
&records,
|
&records,
|
||||||
flags)) < 0)
|
flags)) < 0)
|
||||||
@ -2181,7 +2187,7 @@ cmdDomstats(vshControl *ctl, const vshCmd *cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (next = records; *next; next++) {
|
for (next = records; *next; next++) {
|
||||||
if (!vshDomainStatsPrintRecord(ctl, *next, raw))
|
if (!virshDomainStatsPrintRecord(ctl, *next, raw))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2234,7 +2240,7 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd)
|
|||||||
const char *sourcestr = NULL;
|
const char *sourcestr = NULL;
|
||||||
int source = VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE;
|
int source = VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE;
|
||||||
|
|
||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (vshCommandOptString(ctl, cmd, "interface", &ifacestr) < 0)
|
if (vshCommandOptString(ctl, cmd, "interface", &ifacestr) < 0)
|
||||||
|
@ -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[];
|
||||||
|
1128
tools/virsh-domain.c
1128
tools/virsh-domain.c
File diff suppressed because it is too large
Load Diff
@ -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
|
|||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
}
|
}
|
||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
}
|
}
|
||||||
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)
|
|||||||
|
|
||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
}
|
}
|
||||||
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)
|
|||||||
{
|
{
|
||||||
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
|
|||||||
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)
|
|||||||
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[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
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,
|
|||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
|||||||
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)
|
|||||||
|
|
||||||
/* 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)
|
|||||||
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)
|
|||||||
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
|
|||||||
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
|
|||||||
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
|
|||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
}
|
}
|
||||||
|
|
||||||
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)
|
|||||||
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)
|
|||||||
|
|
||||||
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)
|
|||||||
|
|
||||||
/* 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)
|
|||||||
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 @@
|
|||||||
#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,
|
|||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
}
|
}
|
||||||
|
|
||||||
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)
|
|||||||
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)
|
|||||||
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,
|
|||||||
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,
|
|||||||
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,
|
|||||||
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,
|
|||||||
}
|
}
|
||||||
|
|
||||||
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,
|
|||||||
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,
|
|||||||
|
|
||||||
/* 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,
|
|||||||
|
|
||||||
/* 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,
|
|||||||
/* 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,
|
|||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
virInterfaceGetMACString(iface));
|
virInterfaceGetMACString(iface));
|
||||||
}
|
}
|
||||||
|
|
||||||
vshInterfaceListFree(list);
|
virshInterfaceListFree(list);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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)
|
|||||||
{
|
{
|
||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
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[] = {
|
|||||||
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[] = {
|
|||||||
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[] = {
|
|||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
/* 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)
|
|||||||
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)
|
|||||||
|
|
||||||
/* 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 @@
|
|||||||
|
|
||||||
# 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 @@
|
|||||||
#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,
|
|||||||
*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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
}
|
}
|
||||||
|
|
||||||
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)
|
|||||||
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)
|
|||||||
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,
|
|||||||
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,
|
|||||||
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,
|
|||||||
/* 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,
|
|||||||
/* 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,
|
|||||||
/* 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,
|
|||||||
/* 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,
|
|||||||
|
|
||||||
/* 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,
|
|||||||
/* 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,
|
|||||||
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[] = {
|
|||||||
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)
|
|||||||
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)
|
|||||||
|
|
||||||
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)
|
|||||||
{
|
{
|
||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
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[] = {
|
|||||||
{.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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
/*
|
/*
|
||||||
* "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,
|
|||||||
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,
|
|||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
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[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
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)
|
|||||||
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)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 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 @@
|
|||||||
# 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[];
|
||||||
|
|
||||||
|
@ -65,6 +65,7 @@ cmdNodeDeviceCreate(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;
|
||||||
@ -72,7 +73,7 @@ cmdNodeDeviceCreate(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;
|
||||||
|
|
||||||
dev = virNodeDeviceCreateXML(ctl->conn, buffer, 0);
|
dev = virNodeDeviceCreateXML(priv->conn, buffer, 0);
|
||||||
VIR_FREE(buffer);
|
VIR_FREE(buffer);
|
||||||
|
|
||||||
if (dev != NULL) {
|
if (dev != NULL) {
|
||||||
@ -123,6 +124,7 @@ cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd)
|
|||||||
const char *device_value = NULL;
|
const char *device_value = NULL;
|
||||||
char **arr = NULL;
|
char **arr = NULL;
|
||||||
int narr;
|
int narr;
|
||||||
|
virshControlPtr priv = ctl->privData;
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0)
|
||||||
return false;
|
return false;
|
||||||
@ -137,9 +139,9 @@ cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (!virValidateWWN(arr[0]) || !virValidateWWN(arr[1]))
|
if (!virValidateWWN(arr[0]) || !virValidateWWN(arr[1]))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
dev = virNodeDeviceLookupSCSIHostByWWN(ctl->conn, arr[0], arr[1], 0);
|
dev = virNodeDeviceLookupSCSIHostByWWN(priv->conn, arr[0], arr[1], 0);
|
||||||
} else {
|
} else {
|
||||||
dev = virNodeDeviceLookupByName(ctl->conn, device_value);
|
dev = virNodeDeviceLookupByName(priv->conn, device_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dev) {
|
if (!dev) {
|
||||||
@ -162,22 +164,22 @@ cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct vshNodeList {
|
struct virshNodeList {
|
||||||
char **names;
|
char **names;
|
||||||
char **parents;
|
char **parents;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
vshNodeListLookup(int devid, bool parent, void *opaque)
|
virshNodeListLookup(int devid, bool parent, void *opaque)
|
||||||
{
|
{
|
||||||
struct vshNodeList *arrays = opaque;
|
struct virshNodeList *arrays = opaque;
|
||||||
if (parent)
|
if (parent)
|
||||||
return arrays->parents[devid];
|
return arrays->parents[devid];
|
||||||
return arrays->names[devid];
|
return arrays->names[devid];
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
vshNodeDeviceSorter(const void *a, const void *b)
|
virshNodeDeviceSorter(const void *a, const void *b)
|
||||||
{
|
{
|
||||||
virNodeDevicePtr *na = (virNodeDevicePtr *) a;
|
virNodeDevicePtr *na = (virNodeDevicePtr *) a;
|
||||||
virNodeDevicePtr *nb = (virNodeDevicePtr *) b;
|
virNodeDevicePtr *nb = (virNodeDevicePtr *) b;
|
||||||
@ -192,14 +194,14 @@ vshNodeDeviceSorter(const void *a, const void *b)
|
|||||||
virNodeDeviceGetName(*nb));
|
virNodeDeviceGetName(*nb));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct vshNodeDeviceList {
|
struct virshNodeDeviceList {
|
||||||
virNodeDevicePtr *devices;
|
virNodeDevicePtr *devices;
|
||||||
size_t ndevices;
|
size_t ndevices;
|
||||||
};
|
};
|
||||||
typedef struct vshNodeDeviceList *vshNodeDeviceListPtr;
|
typedef struct virshNodeDeviceList *virshNodeDeviceListPtr;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
vshNodeDeviceListFree(vshNodeDeviceListPtr list)
|
virshNodeDeviceListFree(virshNodeDeviceListPtr list)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
@ -213,13 +215,13 @@ vshNodeDeviceListFree(vshNodeDeviceListPtr list)
|
|||||||
VIR_FREE(list);
|
VIR_FREE(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
static vshNodeDeviceListPtr
|
static virshNodeDeviceListPtr
|
||||||
vshNodeDeviceListCollect(vshControl *ctl,
|
virshNodeDeviceListCollect(vshControl *ctl,
|
||||||
char **capnames,
|
char **capnames,
|
||||||
int ncapnames,
|
int ncapnames,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
vshNodeDeviceListPtr list = vshMalloc(ctl, sizeof(*list));
|
virshNodeDeviceListPtr list = vshMalloc(ctl, sizeof(*list));
|
||||||
size_t i;
|
size_t i;
|
||||||
int ret;
|
int ret;
|
||||||
virNodeDevicePtr device;
|
virNodeDevicePtr device;
|
||||||
@ -227,9 +229,10 @@ vshNodeDeviceListCollect(vshControl *ctl,
|
|||||||
size_t deleted = 0;
|
size_t deleted = 0;
|
||||||
int ndevices = 0;
|
int ndevices = 0;
|
||||||
char **names = NULL;
|
char **names = NULL;
|
||||||
|
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 = virConnectListAllNodeDevices(ctl->conn,
|
if ((ret = virConnectListAllNodeDevices(priv->conn,
|
||||||
&list->devices,
|
&list->devices,
|
||||||
flags)) >= 0) {
|
flags)) >= 0) {
|
||||||
list->ndevices = ret;
|
list->ndevices = ret;
|
||||||
@ -249,7 +252,7 @@ vshNodeDeviceListCollect(vshControl *ctl,
|
|||||||
/* fall back to old method (0.10.1 and older) */
|
/* fall back to old method (0.10.1 and older) */
|
||||||
vshResetLibvirtError();
|
vshResetLibvirtError();
|
||||||
|
|
||||||
ndevices = virNodeNumOfDevices(ctl->conn, NULL, 0);
|
ndevices = virNodeNumOfDevices(priv->conn, NULL, 0);
|
||||||
if (ndevices < 0) {
|
if (ndevices < 0) {
|
||||||
vshError(ctl, "%s", _("Failed to count node devices"));
|
vshError(ctl, "%s", _("Failed to count node devices"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -260,7 +263,7 @@ vshNodeDeviceListCollect(vshControl *ctl,
|
|||||||
|
|
||||||
names = vshMalloc(ctl, sizeof(char *) * ndevices);
|
names = vshMalloc(ctl, sizeof(char *) * ndevices);
|
||||||
|
|
||||||
ndevices = virNodeListDevices(ctl->conn, NULL, names, ndevices, 0);
|
ndevices = virNodeListDevices(priv->conn, NULL, names, ndevices, 0);
|
||||||
if (ndevices < 0) {
|
if (ndevices < 0) {
|
||||||
vshError(ctl, "%s", _("Failed to list node devices"));
|
vshError(ctl, "%s", _("Failed to list node devices"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -271,7 +274,7 @@ vshNodeDeviceListCollect(vshControl *ctl,
|
|||||||
|
|
||||||
/* get the node devices */
|
/* get the node devices */
|
||||||
for (i = 0; i < ndevices; i++) {
|
for (i = 0; i < ndevices; i++) {
|
||||||
if (!(device = virNodeDeviceLookupByName(ctl->conn, names[i])))
|
if (!(device = virNodeDeviceLookupByName(priv->conn, names[i])))
|
||||||
continue;
|
continue;
|
||||||
list->devices[list->ndevices++] = device;
|
list->devices[list->ndevices++] = device;
|
||||||
}
|
}
|
||||||
@ -336,7 +339,7 @@ vshNodeDeviceListCollect(vshControl *ctl,
|
|||||||
/* sort the list */
|
/* sort the list */
|
||||||
if (list->devices && list->ndevices)
|
if (list->devices && list->ndevices)
|
||||||
qsort(list->devices, list->ndevices,
|
qsort(list->devices, list->ndevices,
|
||||||
sizeof(*list->devices), vshNodeDeviceSorter);
|
sizeof(*list->devices), virshNodeDeviceSorter);
|
||||||
|
|
||||||
/* truncate the list if filter simulation deleted entries */
|
/* truncate the list if filter simulation deleted entries */
|
||||||
if (deleted)
|
if (deleted)
|
||||||
@ -350,7 +353,7 @@ vshNodeDeviceListCollect(vshControl *ctl,
|
|||||||
VIR_FREE(names);
|
VIR_FREE(names);
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
vshNodeDeviceListFree(list);
|
virshNodeDeviceListFree(list);
|
||||||
list = NULL;
|
list = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,7 +395,7 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
|||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
char **caps = NULL;
|
char **caps = NULL;
|
||||||
int ncaps = 0;
|
int ncaps = 0;
|
||||||
vshNodeDeviceListPtr list = NULL;
|
virshNodeDeviceListPtr list = NULL;
|
||||||
int cap_type = -1;
|
int cap_type = -1;
|
||||||
|
|
||||||
ignore_value(vshCommandOptString(ctl, cmd, "cap", &cap_str));
|
ignore_value(vshCommandOptString(ctl, cmd, "cap", &cap_str));
|
||||||
@ -455,7 +458,7 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(list = vshNodeDeviceListCollect(ctl, caps, ncaps, flags))) {
|
if (!(list = virshNodeDeviceListCollect(ctl, caps, ncaps, flags))) {
|
||||||
ret = false;
|
ret = false;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -463,7 +466,7 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
|||||||
if (tree) {
|
if (tree) {
|
||||||
char **parents = vshMalloc(ctl, sizeof(char *) * list->ndevices);
|
char **parents = vshMalloc(ctl, sizeof(char *) * list->ndevices);
|
||||||
char **names = vshMalloc(ctl, sizeof(char *) * list->ndevices);
|
char **names = vshMalloc(ctl, sizeof(char *) * list->ndevices);
|
||||||
struct vshNodeList arrays = { names, parents };
|
struct virshNodeList arrays = { names, parents };
|
||||||
|
|
||||||
for (i = 0; i < list->ndevices; i++)
|
for (i = 0; i < list->ndevices; i++)
|
||||||
names[i] = vshStrdup(ctl, virNodeDeviceGetName(list->devices[i]));
|
names[i] = vshStrdup(ctl, virNodeDeviceGetName(list->devices[i]));
|
||||||
@ -480,7 +483,7 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
|||||||
|
|
||||||
for (i = 0; i < list->ndevices; i++) {
|
for (i = 0; i < list->ndevices; i++) {
|
||||||
if (parents[i] == NULL &&
|
if (parents[i] == NULL &&
|
||||||
vshTreePrint(ctl, vshNodeListLookup, &arrays,
|
vshTreePrint(ctl, virshNodeListLookup, &arrays,
|
||||||
list->ndevices, i) < 0)
|
list->ndevices, i) < 0)
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
@ -498,7 +501,7 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virStringFreeList(caps);
|
virStringFreeList(caps);
|
||||||
vshNodeDeviceListFree(list);
|
virshNodeDeviceListFree(list);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -534,6 +537,7 @@ cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cmd)
|
|||||||
char **arr = NULL;
|
char **arr = NULL;
|
||||||
int narr;
|
int narr;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
virshControlPtr priv = ctl->privData;
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "device", &device_value) < 0)
|
||||||
return false;
|
return false;
|
||||||
@ -548,9 +552,9 @@ cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (!virValidateWWN(arr[0]) || !virValidateWWN(arr[1]))
|
if (!virValidateWWN(arr[0]) || !virValidateWWN(arr[1]))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
device = virNodeDeviceLookupSCSIHostByWWN(ctl->conn, arr[0], arr[1], 0);
|
device = virNodeDeviceLookupSCSIHostByWWN(priv->conn, arr[0], arr[1], 0);
|
||||||
} else {
|
} else {
|
||||||
device = virNodeDeviceLookupByName(ctl->conn, device_value);
|
device = virNodeDeviceLookupByName(priv->conn, device_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!device) {
|
if (!device) {
|
||||||
@ -606,13 +610,14 @@ cmdNodeDeviceDetach(vshControl *ctl, const vshCmd *cmd)
|
|||||||
const char *driverName = NULL;
|
const char *driverName = NULL;
|
||||||
virNodeDevicePtr device;
|
virNodeDevicePtr device;
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
|
virshControlPtr priv = ctl->privData;
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ignore_value(vshCommandOptString(ctl, cmd, "driver", &driverName));
|
ignore_value(vshCommandOptString(ctl, cmd, "driver", &driverName));
|
||||||
|
|
||||||
if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) {
|
if (!(device = virNodeDeviceLookupByName(priv->conn, name))) {
|
||||||
vshError(ctl, _("Could not find matching device '%s'"), name);
|
vshError(ctl, _("Could not find matching device '%s'"), name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -666,11 +671,12 @@ cmdNodeDeviceReAttach(vshControl *ctl, const vshCmd *cmd)
|
|||||||
const char *name = NULL;
|
const char *name = NULL;
|
||||||
virNodeDevicePtr device;
|
virNodeDevicePtr device;
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
|
virshControlPtr priv = ctl->privData;
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) {
|
if (!(device = virNodeDeviceLookupByName(priv->conn, name))) {
|
||||||
vshError(ctl, _("Could not find matching device '%s'"), name);
|
vshError(ctl, _("Could not find matching device '%s'"), name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -715,11 +721,12 @@ cmdNodeDeviceReset(vshControl *ctl, const vshCmd *cmd)
|
|||||||
const char *name = NULL;
|
const char *name = NULL;
|
||||||
virNodeDevicePtr device;
|
virNodeDevicePtr device;
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
|
virshControlPtr priv = ctl->privData;
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "device", &name) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) {
|
if (!(device = virNodeDeviceLookupByName(priv->conn, name))) {
|
||||||
vshError(ctl, _("Could not find matching device '%s'"), name);
|
vshError(ctl, _("Could not find matching device '%s'"), name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -33,13 +33,15 @@
|
|||||||
#include "virutil.h"
|
#include "virutil.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)
|
||||||
{
|
{
|
||||||
virNWFilterPtr nwfilter = NULL;
|
virNWFilterPtr nwfilter = NULL;
|
||||||
const char *n = NULL;
|
const char *n = NULL;
|
||||||
const char *optname = "nwfilter";
|
const char *optname = "nwfilter";
|
||||||
virCheckFlags(VSH_BYUUID | VSH_BYNAME, NULL);
|
virshControlPtr priv = ctl->privData;
|
||||||
|
|
||||||
|
virCheckFlags(VIRSH_BYUUID | VIRSH_BYNAME, NULL);
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, optname, &n) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, optname, &n) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -51,16 +53,16 @@ vshCommandOptNWFilterBy(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 nwfilter UUID\n",
|
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as nwfilter UUID\n",
|
||||||
cmd->def->name, optname);
|
cmd->def->name, optname);
|
||||||
nwfilter = virNWFilterLookupByUUIDString(ctl->conn, n);
|
nwfilter = virNWFilterLookupByUUIDString(priv->conn, n);
|
||||||
}
|
}
|
||||||
/* try it by NAME */
|
/* try it by NAME */
|
||||||
if (!nwfilter && (flags & VSH_BYNAME)) {
|
if (!nwfilter && (flags & VIRSH_BYNAME)) {
|
||||||
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as nwfilter NAME\n",
|
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as nwfilter NAME\n",
|
||||||
cmd->def->name, optname);
|
cmd->def->name, optname);
|
||||||
nwfilter = virNWFilterLookupByName(ctl->conn, n);
|
nwfilter = virNWFilterLookupByName(priv->conn, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nwfilter)
|
if (!nwfilter)
|
||||||
@ -98,6 +100,7 @@ cmdNWFilterDefine(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;
|
||||||
@ -105,7 +108,7 @@ cmdNWFilterDefine(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;
|
||||||
|
|
||||||
nwfilter = virNWFilterDefineXML(ctl->conn, buffer);
|
nwfilter = virNWFilterDefineXML(priv->conn, buffer);
|
||||||
VIR_FREE(buffer);
|
VIR_FREE(buffer);
|
||||||
|
|
||||||
if (nwfilter != NULL) {
|
if (nwfilter != NULL) {
|
||||||
@ -148,7 +151,7 @@ cmdNWFilterUndefine(vshControl *ctl, const vshCmd *cmd)
|
|||||||
bool ret = true;
|
bool ret = true;
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
if (!(nwfilter = vshCommandOptNWFilter(ctl, cmd, &name)))
|
if (!(nwfilter = virshCommandOptNWFilter(ctl, cmd, &name)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (virNWFilterUndefine(nwfilter) == 0) {
|
if (virNWFilterUndefine(nwfilter) == 0) {
|
||||||
@ -191,7 +194,7 @@ cmdNWFilterDumpXML(vshControl *ctl, const vshCmd *cmd)
|
|||||||
bool ret = true;
|
bool ret = true;
|
||||||
char *dump;
|
char *dump;
|
||||||
|
|
||||||
if (!(nwfilter = vshCommandOptNWFilter(ctl, cmd, NULL)))
|
if (!(nwfilter = virshCommandOptNWFilter(ctl, cmd, NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
dump = virNWFilterGetXMLDesc(nwfilter, 0);
|
dump = virNWFilterGetXMLDesc(nwfilter, 0);
|
||||||
@ -207,7 +210,7 @@ cmdNWFilterDumpXML(vshControl *ctl, const vshCmd *cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
vshNWFilterSorter(const void *a, const void *b)
|
virshNWFilterSorter(const void *a, const void *b)
|
||||||
{
|
{
|
||||||
virNWFilterPtr *fa = (virNWFilterPtr *) a;
|
virNWFilterPtr *fa = (virNWFilterPtr *) a;
|
||||||
virNWFilterPtr *fb = (virNWFilterPtr *) b;
|
virNWFilterPtr *fb = (virNWFilterPtr *) b;
|
||||||
@ -222,14 +225,14 @@ vshNWFilterSorter(const void *a, const void *b)
|
|||||||
virNWFilterGetName(*fb));
|
virNWFilterGetName(*fb));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct vshNWFilterList {
|
struct virshNWFilterList {
|
||||||
virNWFilterPtr *filters;
|
virNWFilterPtr *filters;
|
||||||
size_t nfilters;
|
size_t nfilters;
|
||||||
};
|
};
|
||||||
typedef struct vshNWFilterList *vshNWFilterListPtr;
|
typedef struct virshNWFilterList *virshNWFilterListPtr;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
vshNWFilterListFree(vshNWFilterListPtr list)
|
virshNWFilterListFree(virshNWFilterListPtr list)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
@ -243,11 +246,11 @@ vshNWFilterListFree(vshNWFilterListPtr list)
|
|||||||
VIR_FREE(list);
|
VIR_FREE(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
static vshNWFilterListPtr
|
static virshNWFilterListPtr
|
||||||
vshNWFilterListCollect(vshControl *ctl,
|
virshNWFilterListCollect(vshControl *ctl,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
vshNWFilterListPtr list = vshMalloc(ctl, sizeof(*list));
|
virshNWFilterListPtr list = vshMalloc(ctl, sizeof(*list));
|
||||||
size_t i;
|
size_t i;
|
||||||
int ret;
|
int ret;
|
||||||
virNWFilterPtr filter;
|
virNWFilterPtr filter;
|
||||||
@ -255,9 +258,10 @@ vshNWFilterListCollect(vshControl *ctl,
|
|||||||
size_t deleted = 0;
|
size_t deleted = 0;
|
||||||
int nfilters = 0;
|
int nfilters = 0;
|
||||||
char **names = NULL;
|
char **names = NULL;
|
||||||
|
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 = virConnectListAllNWFilters(ctl->conn,
|
if ((ret = virConnectListAllNWFilters(priv->conn,
|
||||||
&list->filters,
|
&list->filters,
|
||||||
flags)) >= 0) {
|
flags)) >= 0) {
|
||||||
list->nfilters = ret;
|
list->nfilters = ret;
|
||||||
@ -279,7 +283,7 @@ vshNWFilterListCollect(vshControl *ctl,
|
|||||||
/* fall back to old method (0.9.13 and older) */
|
/* fall back to old method (0.9.13 and older) */
|
||||||
vshResetLibvirtError();
|
vshResetLibvirtError();
|
||||||
|
|
||||||
nfilters = virConnectNumOfNWFilters(ctl->conn);
|
nfilters = virConnectNumOfNWFilters(priv->conn);
|
||||||
if (nfilters < 0) {
|
if (nfilters < 0) {
|
||||||
vshError(ctl, "%s", _("Failed to count network filters"));
|
vshError(ctl, "%s", _("Failed to count network filters"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -290,7 +294,7 @@ vshNWFilterListCollect(vshControl *ctl,
|
|||||||
|
|
||||||
names = vshMalloc(ctl, sizeof(char *) * nfilters);
|
names = vshMalloc(ctl, sizeof(char *) * nfilters);
|
||||||
|
|
||||||
nfilters = virConnectListNWFilters(ctl->conn, names, nfilters);
|
nfilters = virConnectListNWFilters(priv->conn, names, nfilters);
|
||||||
if (nfilters < 0) {
|
if (nfilters < 0) {
|
||||||
vshError(ctl, "%s", _("Failed to list network filters"));
|
vshError(ctl, "%s", _("Failed to list network filters"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -301,7 +305,7 @@ vshNWFilterListCollect(vshControl *ctl,
|
|||||||
|
|
||||||
/* get the network filters */
|
/* get the network filters */
|
||||||
for (i = 0; i < nfilters; i++) {
|
for (i = 0; i < nfilters; i++) {
|
||||||
if (!(filter = virNWFilterLookupByName(ctl->conn, names[i])))
|
if (!(filter = virNWFilterLookupByName(priv->conn, names[i])))
|
||||||
continue;
|
continue;
|
||||||
list->filters[list->nfilters++] = filter;
|
list->filters[list->nfilters++] = filter;
|
||||||
}
|
}
|
||||||
@ -313,7 +317,7 @@ vshNWFilterListCollect(vshControl *ctl,
|
|||||||
/* sort the list */
|
/* sort the list */
|
||||||
if (list->filters && list->nfilters)
|
if (list->filters && list->nfilters)
|
||||||
qsort(list->filters, list->nfilters,
|
qsort(list->filters, list->nfilters,
|
||||||
sizeof(*list->filters), vshNWFilterSorter);
|
sizeof(*list->filters), virshNWFilterSorter);
|
||||||
|
|
||||||
/* truncate the list for not found filter objects */
|
/* truncate the list for not found filter objects */
|
||||||
if (deleted)
|
if (deleted)
|
||||||
@ -327,7 +331,7 @@ vshNWFilterListCollect(vshControl *ctl,
|
|||||||
VIR_FREE(names);
|
VIR_FREE(names);
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
vshNWFilterListFree(list);
|
virshNWFilterListFree(list);
|
||||||
list = NULL;
|
list = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -356,9 +360,9 @@ cmdNWFilterList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
|||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
char uuid[VIR_UUID_STRING_BUFLEN];
|
char uuid[VIR_UUID_STRING_BUFLEN];
|
||||||
vshNWFilterListPtr list = NULL;
|
virshNWFilterListPtr list = NULL;
|
||||||
|
|
||||||
if (!(list = vshNWFilterListCollect(ctl, 0)))
|
if (!(list = virshNWFilterListCollect(ctl, 0)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
vshPrintExtra(ctl, " %-36s %-20s \n", _("UUID"), _("Name"));
|
vshPrintExtra(ctl, " %-36s %-20s \n", _("UUID"), _("Name"));
|
||||||
@ -374,7 +378,7 @@ cmdNWFilterList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
|||||||
virNWFilterGetName(nwfilter));
|
virNWFilterGetName(nwfilter));
|
||||||
}
|
}
|
||||||
|
|
||||||
vshNWFilterListFree(list);
|
virshNWFilterListFree(list);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -406,8 +410,9 @@ cmdNWFilterEdit(vshControl *ctl, const vshCmd *cmd)
|
|||||||
bool ret = false;
|
bool ret = false;
|
||||||
virNWFilterPtr nwfilter = NULL;
|
virNWFilterPtr nwfilter = NULL;
|
||||||
virNWFilterPtr nwfilter_edited = NULL;
|
virNWFilterPtr nwfilter_edited = NULL;
|
||||||
|
virshControlPtr priv = ctl->privData;
|
||||||
|
|
||||||
nwfilter = vshCommandOptNWFilter(ctl, cmd, NULL);
|
nwfilter = virshCommandOptNWFilter(ctl, cmd, NULL);
|
||||||
if (nwfilter == NULL)
|
if (nwfilter == NULL)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
@ -421,7 +426,7 @@ cmdNWFilterEdit(vshControl *ctl, const vshCmd *cmd)
|
|||||||
goto edit_cleanup; \
|
goto edit_cleanup; \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define EDIT_DEFINE \
|
#define EDIT_DEFINE \
|
||||||
(nwfilter_edited = virNWFilterDefineXML(ctl->conn, doc_edited))
|
(nwfilter_edited = virNWFilterDefineXML(priv->conn, doc_edited))
|
||||||
#include "virsh-edit.c"
|
#include "virsh-edit.c"
|
||||||
|
|
||||||
vshPrint(ctl, _("Network filter %s XML configuration edited.\n"),
|
vshPrint(ctl, _("Network filter %s XML configuration edited.\n"),
|
||||||
|
@ -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[];
|
||||||
|
|
||||||
|
@ -34,12 +34,14 @@
|
|||||||
#include "virstring.h"
|
#include "virstring.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)
|
||||||
{
|
{
|
||||||
virStoragePoolPtr pool = NULL;
|
virStoragePoolPtr pool = NULL;
|
||||||
const char *n = NULL;
|
const char *n = NULL;
|
||||||
virCheckFlags(VSH_BYUUID | VSH_BYNAME, NULL);
|
virshControlPtr priv = ctl->privData;
|
||||||
|
|
||||||
|
virCheckFlags(VIRSH_BYUUID | VIRSH_BYNAME, NULL);
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, optname, &n) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, optname, &n) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -51,16 +53,16 @@ vshCommandOptPoolBy(vshControl *ctl, const vshCmd *cmd, const char *optname,
|
|||||||
*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 pool UUID\n",
|
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as pool UUID\n",
|
||||||
cmd->def->name, optname);
|
cmd->def->name, optname);
|
||||||
pool = virStoragePoolLookupByUUIDString(ctl->conn, n);
|
pool = virStoragePoolLookupByUUIDString(priv->conn, n);
|
||||||
}
|
}
|
||||||
/* try it by NAME */
|
/* try it by NAME */
|
||||||
if (!pool && (flags & VSH_BYNAME)) {
|
if (!pool && (flags & VIRSH_BYNAME)) {
|
||||||
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as pool NAME\n",
|
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as pool NAME\n",
|
||||||
cmd->def->name, optname);
|
cmd->def->name, optname);
|
||||||
pool = virStoragePoolLookupByName(ctl->conn, n);
|
pool = virStoragePoolLookupByName(priv->conn, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pool)
|
if (!pool)
|
||||||
@ -102,7 +104,7 @@ cmdPoolAutostart(vshControl *ctl, const vshCmd *cmd)
|
|||||||
const char *name;
|
const char *name;
|
||||||
int autostart;
|
int autostart;
|
||||||
|
|
||||||
if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name)))
|
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", &name)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
autostart = !vshCommandOptBool(cmd, "disable");
|
autostart = !vshCommandOptBool(cmd, "disable");
|
||||||
@ -154,6 +156,7 @@ cmdPoolCreate(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;
|
||||||
@ -161,7 +164,7 @@ cmdPoolCreate(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;
|
||||||
|
|
||||||
pool = virStoragePoolCreateXML(ctl->conn, buffer, 0);
|
pool = virStoragePoolCreateXML(priv->conn, buffer, 0);
|
||||||
VIR_FREE(buffer);
|
VIR_FREE(buffer);
|
||||||
|
|
||||||
if (pool != NULL) {
|
if (pool != NULL) {
|
||||||
@ -249,10 +252,10 @@ static const vshCmdOptDef opts_pool_X_as[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
vshBuildPoolXML(vshControl *ctl,
|
virshBuildPoolXML(vshControl *ctl,
|
||||||
const vshCmd *cmd,
|
const vshCmd *cmd,
|
||||||
const char **retname,
|
const char **retname,
|
||||||
char **xml)
|
char **xml)
|
||||||
{
|
{
|
||||||
const char *name = NULL, *type = NULL, *srcHost = NULL, *srcPath = NULL,
|
const char *name = NULL, *type = NULL, *srcHost = NULL, *srcPath = NULL,
|
||||||
*srcDev = NULL, *srcName = NULL, *srcFormat = NULL,
|
*srcDev = NULL, *srcName = NULL, *srcFormat = NULL,
|
||||||
@ -365,15 +368,16 @@ cmdPoolCreateAs(vshControl *ctl, const vshCmd *cmd)
|
|||||||
const char *name;
|
const char *name;
|
||||||
char *xml;
|
char *xml;
|
||||||
bool printXML = vshCommandOptBool(cmd, "print-xml");
|
bool printXML = vshCommandOptBool(cmd, "print-xml");
|
||||||
|
virshControlPtr priv = ctl->privData;
|
||||||
|
|
||||||
if (!vshBuildPoolXML(ctl, cmd, &name, &xml))
|
if (!virshBuildPoolXML(ctl, cmd, &name, &xml))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (printXML) {
|
if (printXML) {
|
||||||
vshPrint(ctl, "%s", xml);
|
vshPrint(ctl, "%s", xml);
|
||||||
VIR_FREE(xml);
|
VIR_FREE(xml);
|
||||||
} else {
|
} else {
|
||||||
pool = virStoragePoolCreateXML(ctl->conn, xml, 0);
|
pool = virStoragePoolCreateXML(priv->conn, xml, 0);
|
||||||
VIR_FREE(xml);
|
VIR_FREE(xml);
|
||||||
|
|
||||||
if (pool != NULL) {
|
if (pool != NULL) {
|
||||||
@ -417,6 +421,7 @@ cmdPoolDefine(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;
|
||||||
@ -424,7 +429,7 @@ cmdPoolDefine(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;
|
||||||
|
|
||||||
pool = virStoragePoolDefineXML(ctl->conn, buffer, 0);
|
pool = virStoragePoolDefineXML(priv->conn, buffer, 0);
|
||||||
VIR_FREE(buffer);
|
VIR_FREE(buffer);
|
||||||
|
|
||||||
if (pool != NULL) {
|
if (pool != NULL) {
|
||||||
@ -458,15 +463,16 @@ cmdPoolDefineAs(vshControl *ctl, const vshCmd *cmd)
|
|||||||
const char *name;
|
const char *name;
|
||||||
char *xml;
|
char *xml;
|
||||||
bool printXML = vshCommandOptBool(cmd, "print-xml");
|
bool printXML = vshCommandOptBool(cmd, "print-xml");
|
||||||
|
virshControlPtr priv = ctl->privData;
|
||||||
|
|
||||||
if (!vshBuildPoolXML(ctl, cmd, &name, &xml))
|
if (!virshBuildPoolXML(ctl, cmd, &name, &xml))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (printXML) {
|
if (printXML) {
|
||||||
vshPrint(ctl, "%s", xml);
|
vshPrint(ctl, "%s", xml);
|
||||||
VIR_FREE(xml);
|
VIR_FREE(xml);
|
||||||
} else {
|
} else {
|
||||||
pool = virStoragePoolDefineXML(ctl->conn, xml, 0);
|
pool = virStoragePoolDefineXML(priv->conn, xml, 0);
|
||||||
VIR_FREE(xml);
|
VIR_FREE(xml);
|
||||||
|
|
||||||
if (pool != NULL) {
|
if (pool != NULL) {
|
||||||
@ -518,7 +524,7 @@ cmdPoolBuild(vshControl *ctl, const vshCmd *cmd)
|
|||||||
const char *name;
|
const char *name;
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
|
|
||||||
if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name)))
|
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", &name)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (vshCommandOptBool(cmd, "no-overwrite"))
|
if (vshCommandOptBool(cmd, "no-overwrite"))
|
||||||
@ -568,7 +574,7 @@ cmdPoolDestroy(vshControl *ctl, const vshCmd *cmd)
|
|||||||
bool ret = true;
|
bool ret = true;
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name)))
|
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", &name)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (virStoragePoolDestroy(pool) == 0) {
|
if (virStoragePoolDestroy(pool) == 0) {
|
||||||
@ -611,7 +617,7 @@ cmdPoolDelete(vshControl *ctl, const vshCmd *cmd)
|
|||||||
bool ret = true;
|
bool ret = true;
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name)))
|
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", &name)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (virStoragePoolDelete(pool, 0) == 0) {
|
if (virStoragePoolDelete(pool, 0) == 0) {
|
||||||
@ -654,7 +660,7 @@ cmdPoolRefresh(vshControl *ctl, const vshCmd *cmd)
|
|||||||
bool ret = true;
|
bool ret = true;
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name)))
|
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", &name)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (virStoragePoolRefresh(pool, 0) == 0) {
|
if (virStoragePoolRefresh(pool, 0) == 0) {
|
||||||
@ -706,7 +712,7 @@ cmdPoolDumpXML(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (inactive)
|
if (inactive)
|
||||||
flags |= VIR_STORAGE_XML_INACTIVE;
|
flags |= VIR_STORAGE_XML_INACTIVE;
|
||||||
|
|
||||||
if (!(pool = vshCommandOptPool(ctl, cmd, "pool", NULL)))
|
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
dump = virStoragePoolGetXMLDesc(pool, flags);
|
dump = virStoragePoolGetXMLDesc(pool, flags);
|
||||||
@ -722,7 +728,7 @@ cmdPoolDumpXML(vshControl *ctl, const vshCmd *cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
vshStoragePoolSorter(const void *a, const void *b)
|
virshStoragePoolSorter(const void *a, const void *b)
|
||||||
{
|
{
|
||||||
virStoragePoolPtr *pa = (virStoragePoolPtr *) a;
|
virStoragePoolPtr *pa = (virStoragePoolPtr *) a;
|
||||||
virStoragePoolPtr *pb = (virStoragePoolPtr *) b;
|
virStoragePoolPtr *pb = (virStoragePoolPtr *) b;
|
||||||
@ -737,14 +743,14 @@ vshStoragePoolSorter(const void *a, const void *b)
|
|||||||
virStoragePoolGetName(*pb));
|
virStoragePoolGetName(*pb));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct vshStoragePoolList {
|
struct virshStoragePoolList {
|
||||||
virStoragePoolPtr *pools;
|
virStoragePoolPtr *pools;
|
||||||
size_t npools;
|
size_t npools;
|
||||||
};
|
};
|
||||||
typedef struct vshStoragePoolList *vshStoragePoolListPtr;
|
typedef struct virshStoragePoolList *virshStoragePoolListPtr;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
vshStoragePoolListFree(vshStoragePoolListPtr list)
|
virshStoragePoolListFree(virshStoragePoolListPtr list)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
@ -758,11 +764,11 @@ vshStoragePoolListFree(vshStoragePoolListPtr list)
|
|||||||
VIR_FREE(list);
|
VIR_FREE(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
static vshStoragePoolListPtr
|
static virshStoragePoolListPtr
|
||||||
vshStoragePoolListCollect(vshControl *ctl,
|
virshStoragePoolListCollect(vshControl *ctl,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
vshStoragePoolListPtr list = vshMalloc(ctl, sizeof(*list));
|
virshStoragePoolListPtr list = vshMalloc(ctl, sizeof(*list));
|
||||||
size_t i;
|
size_t i;
|
||||||
int ret;
|
int ret;
|
||||||
char **names = NULL;
|
char **names = NULL;
|
||||||
@ -774,9 +780,10 @@ vshStoragePoolListCollect(vshControl *ctl,
|
|||||||
int nActivePools = 0;
|
int nActivePools = 0;
|
||||||
int nInactivePools = 0;
|
int nInactivePools = 0;
|
||||||
int nAllPools = 0;
|
int nAllPools = 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 = virConnectListAllStoragePools(ctl->conn,
|
if ((ret = virConnectListAllStoragePools(priv->conn,
|
||||||
&list->pools,
|
&list->pools,
|
||||||
flags)) >= 0) {
|
flags)) >= 0) {
|
||||||
list->npools = ret;
|
list->npools = ret;
|
||||||
@ -792,7 +799,7 @@ vshStoragePoolListCollect(vshControl *ctl,
|
|||||||
unsigned int newflags = flags & (VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE |
|
unsigned int newflags = flags & (VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE |
|
||||||
VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE);
|
VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE);
|
||||||
vshResetLibvirtError();
|
vshResetLibvirtError();
|
||||||
if ((ret = virConnectListAllStoragePools(ctl->conn, &list->pools,
|
if ((ret = virConnectListAllStoragePools(priv->conn, &list->pools,
|
||||||
newflags)) >= 0) {
|
newflags)) >= 0) {
|
||||||
list->npools = ret;
|
list->npools = ret;
|
||||||
goto filter;
|
goto filter;
|
||||||
@ -818,7 +825,7 @@ vshStoragePoolListCollect(vshControl *ctl,
|
|||||||
/* Get the number of active pools */
|
/* Get the number of active pools */
|
||||||
if (!VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ACTIVE) ||
|
if (!VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ACTIVE) ||
|
||||||
VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE)) {
|
VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE)) {
|
||||||
if ((nActivePools = virConnectNumOfStoragePools(ctl->conn)) < 0) {
|
if ((nActivePools = virConnectNumOfStoragePools(priv->conn)) < 0) {
|
||||||
vshError(ctl, "%s", _("Failed to get the number of active pools "));
|
vshError(ctl, "%s", _("Failed to get the number of active pools "));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -827,7 +834,7 @@ vshStoragePoolListCollect(vshControl *ctl,
|
|||||||
/* Get the number of inactive pools */
|
/* Get the number of inactive pools */
|
||||||
if (!VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ACTIVE) ||
|
if (!VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ACTIVE) ||
|
||||||
VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE)) {
|
VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE)) {
|
||||||
if ((nInactivePools = virConnectNumOfDefinedStoragePools(ctl->conn)) < 0) {
|
if ((nInactivePools = virConnectNumOfDefinedStoragePools(priv->conn)) < 0) {
|
||||||
vshError(ctl, "%s", _("Failed to get the number of inactive pools"));
|
vshError(ctl, "%s", _("Failed to get the number of inactive pools"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -843,7 +850,7 @@ vshStoragePoolListCollect(vshControl *ctl,
|
|||||||
/* Retrieve a list of active storage pool names */
|
/* Retrieve a list of active storage pool names */
|
||||||
if (!VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ACTIVE) ||
|
if (!VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ACTIVE) ||
|
||||||
VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE)) {
|
VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE)) {
|
||||||
if (virConnectListStoragePools(ctl->conn,
|
if (virConnectListStoragePools(priv->conn,
|
||||||
names, nActivePools) < 0) {
|
names, nActivePools) < 0) {
|
||||||
vshError(ctl, "%s", _("Failed to list active pools"));
|
vshError(ctl, "%s", _("Failed to list active pools"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -853,7 +860,7 @@ vshStoragePoolListCollect(vshControl *ctl,
|
|||||||
/* Add the inactive storage pools to the end of the name list */
|
/* Add the inactive storage pools to the end of the name list */
|
||||||
if (!VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ACTIVE) ||
|
if (!VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ACTIVE) ||
|
||||||
VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE)) {
|
VSH_MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE)) {
|
||||||
if (virConnectListDefinedStoragePools(ctl->conn,
|
if (virConnectListDefinedStoragePools(priv->conn,
|
||||||
&names[nActivePools],
|
&names[nActivePools],
|
||||||
nInactivePools) < 0) {
|
nInactivePools) < 0) {
|
||||||
vshError(ctl, "%s", _("Failed to list inactive pools"));
|
vshError(ctl, "%s", _("Failed to list inactive pools"));
|
||||||
@ -866,14 +873,14 @@ vshStoragePoolListCollect(vshControl *ctl,
|
|||||||
|
|
||||||
/* get active pools */
|
/* get active pools */
|
||||||
for (i = 0; i < nActivePools; i++) {
|
for (i = 0; i < nActivePools; i++) {
|
||||||
if (!(pool = virStoragePoolLookupByName(ctl->conn, names[i])))
|
if (!(pool = virStoragePoolLookupByName(priv->conn, names[i])))
|
||||||
continue;
|
continue;
|
||||||
list->pools[list->npools++] = pool;
|
list->pools[list->npools++] = pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get inactive pools */
|
/* get inactive pools */
|
||||||
for (i = 0; i < nInactivePools; i++) {
|
for (i = 0; i < nInactivePools; i++) {
|
||||||
if (!(pool = virStoragePoolLookupByName(ctl->conn, names[i])))
|
if (!(pool = virStoragePoolLookupByName(priv->conn, names[i])))
|
||||||
continue;
|
continue;
|
||||||
list->pools[list->npools++] = pool;
|
list->pools[list->npools++] = pool;
|
||||||
}
|
}
|
||||||
@ -924,7 +931,7 @@ vshStoragePoolListCollect(vshControl *ctl,
|
|||||||
/* sort the list */
|
/* sort the list */
|
||||||
if (list->pools && list->npools)
|
if (list->pools && list->npools)
|
||||||
qsort(list->pools, list->npools,
|
qsort(list->pools, list->npools,
|
||||||
sizeof(*list->pools), vshStoragePoolSorter);
|
sizeof(*list->pools), virshStoragePoolSorter);
|
||||||
|
|
||||||
/* truncate the list if filter simulation deleted entries */
|
/* truncate the list if filter simulation deleted entries */
|
||||||
if (deleted)
|
if (deleted)
|
||||||
@ -937,7 +944,7 @@ vshStoragePoolListCollect(vshControl *ctl,
|
|||||||
VIR_FREE(names[i]);
|
VIR_FREE(names[i]);
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
vshStoragePoolListFree(list);
|
virshStoragePoolListFree(list);
|
||||||
list = NULL;
|
list = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -946,8 +953,8 @@ vshStoragePoolListCollect(vshControl *ctl,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VIR_ENUM_DECL(vshStoragePoolState)
|
VIR_ENUM_DECL(virshStoragePoolState)
|
||||||
VIR_ENUM_IMPL(vshStoragePoolState,
|
VIR_ENUM_IMPL(virshStoragePoolState,
|
||||||
VIR_STORAGE_POOL_STATE_LAST,
|
VIR_STORAGE_POOL_STATE_LAST,
|
||||||
N_("inactive"),
|
N_("inactive"),
|
||||||
N_("building"),
|
N_("building"),
|
||||||
@ -956,9 +963,9 @@ VIR_ENUM_IMPL(vshStoragePoolState,
|
|||||||
N_("inaccessible"))
|
N_("inaccessible"))
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
vshStoragePoolStateToString(int state)
|
virshStoragePoolStateToString(int state)
|
||||||
{
|
{
|
||||||
const char *str = vshStoragePoolStateTypeToString(state);
|
const char *str = virshStoragePoolStateTypeToString(state);
|
||||||
return str ? _(str) : _("unknown");
|
return str ? _(str) : _("unknown");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1032,7 +1039,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
|||||||
};
|
};
|
||||||
struct poolInfoText *poolInfoTexts = NULL;
|
struct poolInfoText *poolInfoTexts = NULL;
|
||||||
unsigned int flags = VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE;
|
unsigned int flags = VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE;
|
||||||
vshStoragePoolListPtr list = NULL;
|
virshStoragePoolListPtr list = NULL;
|
||||||
const char *type = NULL;
|
const char *type = NULL;
|
||||||
bool details = vshCommandOptBool(cmd, "details");
|
bool details = vshCommandOptBool(cmd, "details");
|
||||||
bool inactive, all;
|
bool inactive, all;
|
||||||
@ -1122,7 +1129,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
|||||||
virStringFreeList(poolTypes);
|
virStringFreeList(poolTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(list = vshStoragePoolListCollect(ctl, flags)))
|
if (!(list = virshStoragePoolListCollect(ctl, flags)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
poolInfoTexts = vshCalloc(ctl, list->npools, sizeof(*poolInfoTexts));
|
poolInfoTexts = vshCalloc(ctl, list->npools, sizeof(*poolInfoTexts));
|
||||||
@ -1168,7 +1175,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
|||||||
} else {
|
} else {
|
||||||
/* Decide which state string to display */
|
/* Decide which state string to display */
|
||||||
if (details) {
|
if (details) {
|
||||||
const char *state = vshStoragePoolStateToString(info.state);
|
const char *state = virshStoragePoolStateToString(info.state);
|
||||||
|
|
||||||
poolInfoTexts[i].state = vshStrdup(ctl, state);
|
poolInfoTexts[i].state = vshStrdup(ctl, state);
|
||||||
|
|
||||||
@ -1371,7 +1378,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
|||||||
}
|
}
|
||||||
VIR_FREE(poolInfoTexts);
|
VIR_FREE(poolInfoTexts);
|
||||||
|
|
||||||
vshStoragePoolListFree(list);
|
virshStoragePoolListFree(list);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1416,6 +1423,7 @@ cmdPoolDiscoverSourcesAs(vshControl * ctl, const vshCmd * cmd ATTRIBUTE_UNUSED)
|
|||||||
char *srcSpec = NULL;
|
char *srcSpec = NULL;
|
||||||
char *srcList;
|
char *srcList;
|
||||||
const char *initiator = NULL;
|
const char *initiator = NULL;
|
||||||
|
virshControlPtr priv = ctl->privData;
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0 ||
|
if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0 ||
|
||||||
vshCommandOptStringReq(ctl, cmd, "host", &host) < 0 ||
|
vshCommandOptStringReq(ctl, cmd, "host", &host) < 0 ||
|
||||||
@ -1453,7 +1461,7 @@ cmdPoolDiscoverSourcesAs(vshControl * ctl, const vshCmd * cmd ATTRIBUTE_UNUSED)
|
|||||||
srcSpec = virBufferContentAndReset(&buf);
|
srcSpec = virBufferContentAndReset(&buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
srcList = virConnectFindStoragePoolSources(ctl->conn, type, srcSpec, 0);
|
srcList = virConnectFindStoragePoolSources(priv->conn, type, srcSpec, 0);
|
||||||
VIR_FREE(srcSpec);
|
VIR_FREE(srcSpec);
|
||||||
if (srcList == NULL) {
|
if (srcList == NULL) {
|
||||||
vshError(ctl, _("Failed to find any %s pool sources"), type);
|
vshError(ctl, _("Failed to find any %s pool sources"), type);
|
||||||
@ -1496,6 +1504,7 @@ cmdPoolDiscoverSources(vshControl * ctl, const vshCmd * cmd ATTRIBUTE_UNUSED)
|
|||||||
{
|
{
|
||||||
const char *type = NULL, *srcSpecFile = NULL;
|
const char *type = NULL, *srcSpecFile = NULL;
|
||||||
char *srcSpec = NULL, *srcList;
|
char *srcSpec = NULL, *srcList;
|
||||||
|
virshControlPtr priv = ctl->privData;
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0)
|
||||||
return false;
|
return false;
|
||||||
@ -1507,7 +1516,7 @@ cmdPoolDiscoverSources(vshControl * ctl, const vshCmd * cmd ATTRIBUTE_UNUSED)
|
|||||||
&srcSpec) < 0)
|
&srcSpec) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
srcList = virConnectFindStoragePoolSources(ctl->conn, type, srcSpec, 0);
|
srcList = virConnectFindStoragePoolSources(priv->conn, type, srcSpec, 0);
|
||||||
VIR_FREE(srcSpec);
|
VIR_FREE(srcSpec);
|
||||||
if (srcList == NULL) {
|
if (srcList == NULL) {
|
||||||
vshError(ctl, _("Failed to find any %s pool sources"), type);
|
vshError(ctl, _("Failed to find any %s pool sources"), type);
|
||||||
@ -1551,7 +1560,7 @@ cmdPoolInfo(vshControl *ctl, const vshCmd *cmd)
|
|||||||
bool ret = true;
|
bool ret = true;
|
||||||
char uuid[VIR_UUID_STRING_BUFLEN];
|
char uuid[VIR_UUID_STRING_BUFLEN];
|
||||||
|
|
||||||
if (!(pool = vshCommandOptPool(ctl, cmd, "pool", NULL)))
|
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
vshPrint(ctl, "%-15s %s\n", _("Name:"), virStoragePoolGetName(pool));
|
vshPrint(ctl, "%-15s %s\n", _("Name:"), virStoragePoolGetName(pool));
|
||||||
@ -1563,7 +1572,7 @@ cmdPoolInfo(vshControl *ctl, const vshCmd *cmd)
|
|||||||
double val;
|
double val;
|
||||||
const char *unit;
|
const char *unit;
|
||||||
vshPrint(ctl, "%-15s %s\n", _("State:"),
|
vshPrint(ctl, "%-15s %s\n", _("State:"),
|
||||||
vshStoragePoolStateToString(info.state));
|
virshStoragePoolStateToString(info.state));
|
||||||
|
|
||||||
/* Check and display whether the pool is persistent or not */
|
/* Check and display whether the pool is persistent or not */
|
||||||
persistent = virStoragePoolIsPersistent(pool);
|
persistent = virStoragePoolIsPersistent(pool);
|
||||||
@ -1626,8 +1635,7 @@ cmdPoolName(vshControl *ctl, const vshCmd *cmd)
|
|||||||
{
|
{
|
||||||
virStoragePoolPtr pool;
|
virStoragePoolPtr pool;
|
||||||
|
|
||||||
if (!(pool = vshCommandOptPoolBy(ctl, cmd, "pool", NULL,
|
if (!(pool = virshCommandOptPoolBy(ctl, cmd, "pool", NULL, VIRSH_BYUUID)))
|
||||||
VSH_BYUUID)))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
vshPrint(ctl, "%s\n", virStoragePoolGetName(pool));
|
vshPrint(ctl, "%s\n", virStoragePoolGetName(pool));
|
||||||
@ -1664,7 +1672,7 @@ cmdPoolStart(vshControl *ctl, const vshCmd *cmd)
|
|||||||
bool ret = true;
|
bool ret = true;
|
||||||
const char *name = NULL;
|
const char *name = NULL;
|
||||||
|
|
||||||
if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name)))
|
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", &name)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (virStoragePoolCreate(pool, 0) == 0) {
|
if (virStoragePoolCreate(pool, 0) == 0) {
|
||||||
@ -1707,7 +1715,7 @@ cmdPoolUndefine(vshControl *ctl, const vshCmd *cmd)
|
|||||||
bool ret = true;
|
bool ret = true;
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name)))
|
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", &name)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (virStoragePoolUndefine(pool) == 0) {
|
if (virStoragePoolUndefine(pool) == 0) {
|
||||||
@ -1749,8 +1757,7 @@ cmdPoolUuid(vshControl *ctl, const vshCmd *cmd)
|
|||||||
virStoragePoolPtr pool;
|
virStoragePoolPtr pool;
|
||||||
char uuid[VIR_UUID_STRING_BUFLEN];
|
char uuid[VIR_UUID_STRING_BUFLEN];
|
||||||
|
|
||||||
if (!(pool = vshCommandOptPoolBy(ctl, cmd, "pool", NULL,
|
if (!(pool = virshCommandOptPoolBy(ctl, cmd, "pool", NULL, VIRSH_BYNAME)))
|
||||||
VSH_BYNAME)))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (virStoragePoolGetUUIDString(pool, uuid) != -1)
|
if (virStoragePoolGetUUIDString(pool, uuid) != -1)
|
||||||
@ -1792,8 +1799,9 @@ cmdPoolEdit(vshControl *ctl, const vshCmd *cmd)
|
|||||||
virStoragePoolPtr pool_edited = NULL;
|
virStoragePoolPtr pool_edited = NULL;
|
||||||
unsigned int flags = VIR_STORAGE_XML_INACTIVE;
|
unsigned int flags = VIR_STORAGE_XML_INACTIVE;
|
||||||
char *tmp_desc = NULL;
|
char *tmp_desc = NULL;
|
||||||
|
virshControlPtr priv = ctl->privData;
|
||||||
|
|
||||||
pool = vshCommandOptPool(ctl, cmd, "pool", NULL);
|
pool = virshCommandOptPool(ctl, cmd, "pool", NULL);
|
||||||
if (pool == NULL)
|
if (pool == NULL)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
@ -1818,7 +1826,7 @@ cmdPoolEdit(vshControl *ctl, const vshCmd *cmd)
|
|||||||
goto edit_cleanup; \
|
goto edit_cleanup; \
|
||||||
} while (0)
|
} while (0)
|
||||||
#define EDIT_DEFINE \
|
#define EDIT_DEFINE \
|
||||||
(pool_edited = virStoragePoolDefineXML(ctl->conn, doc_edited, 0))
|
(pool_edited = virStoragePoolDefineXML(priv->conn, doc_edited, 0))
|
||||||
#include "virsh-edit.c"
|
#include "virsh-edit.c"
|
||||||
|
|
||||||
vshPrint(ctl, _("Pool %s XML configuration edited.\n"),
|
vshPrint(ctl, _("Pool %s XML configuration edited.\n"),
|
||||||
|
@ -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[];
|
||||||
|
|
||||||
|
@ -35,11 +35,12 @@
|
|||||||
#include "conf/secret_conf.h"
|
#include "conf/secret_conf.h"
|
||||||
|
|
||||||
static virSecretPtr
|
static virSecretPtr
|
||||||
vshCommandOptSecret(vshControl *ctl, const vshCmd *cmd, const char **name)
|
virshCommandOptSecret(vshControl *ctl, const vshCmd *cmd, const char **name)
|
||||||
{
|
{
|
||||||
virSecretPtr secret = NULL;
|
virSecretPtr secret = NULL;
|
||||||
const char *n = NULL;
|
const char *n = NULL;
|
||||||
const char *optname = "secret";
|
const char *optname = "secret";
|
||||||
|
virshControlPtr priv = ctl->privData;
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, optname, &n) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, optname, &n) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -50,7 +51,7 @@ vshCommandOptSecret(vshControl *ctl, const vshCmd *cmd, const char **name)
|
|||||||
if (name != NULL)
|
if (name != NULL)
|
||||||
*name = n;
|
*name = n;
|
||||||
|
|
||||||
secret = virSecretLookupByUUIDString(ctl->conn, n);
|
secret = virSecretLookupByUUIDString(priv->conn, n);
|
||||||
|
|
||||||
if (secret == NULL)
|
if (secret == NULL)
|
||||||
vshError(ctl, _("failed to get secret '%s'"), n);
|
vshError(ctl, _("failed to get secret '%s'"), n);
|
||||||
@ -88,6 +89,7 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd)
|
|||||||
virSecretPtr res;
|
virSecretPtr res;
|
||||||
char uuid[VIR_UUID_STRING_BUFLEN];
|
char uuid[VIR_UUID_STRING_BUFLEN];
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
virshControlPtr priv = ctl->privData;
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
|
||||||
return false;
|
return false;
|
||||||
@ -95,7 +97,7 @@ cmdSecretDefine(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;
|
||||||
|
|
||||||
if (!(res = virSecretDefineXML(ctl->conn, buffer, 0))) {
|
if (!(res = virSecretDefineXML(priv->conn, buffer, 0))) {
|
||||||
vshError(ctl, _("Failed to set attributes from %s"), from);
|
vshError(ctl, _("Failed to set attributes from %s"), from);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -144,7 +146,7 @@ cmdSecretDumpXML(vshControl *ctl, const vshCmd *cmd)
|
|||||||
bool ret = false;
|
bool ret = false;
|
||||||
char *xml;
|
char *xml;
|
||||||
|
|
||||||
secret = vshCommandOptSecret(ctl, cmd, NULL);
|
secret = virshCommandOptSecret(ctl, cmd, NULL);
|
||||||
if (secret == NULL)
|
if (secret == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -197,7 +199,7 @@ cmdSecretSetValue(vshControl *ctl, const vshCmd *cmd)
|
|||||||
int res;
|
int res;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
if (!(secret = vshCommandOptSecret(ctl, cmd, NULL)))
|
if (!(secret = virshCommandOptSecret(ctl, cmd, NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "base64", &base64) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "base64", &base64) < 0)
|
||||||
@ -259,7 +261,7 @@ cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd)
|
|||||||
size_t value_size;
|
size_t value_size;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
secret = vshCommandOptSecret(ctl, cmd, NULL);
|
secret = virshCommandOptSecret(ctl, cmd, NULL);
|
||||||
if (secret == NULL)
|
if (secret == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -314,7 +316,7 @@ cmdSecretUndefine(vshControl *ctl, const vshCmd *cmd)
|
|||||||
bool ret = false;
|
bool ret = false;
|
||||||
const char *uuid;
|
const char *uuid;
|
||||||
|
|
||||||
secret = vshCommandOptSecret(ctl, cmd, &uuid);
|
secret = virshCommandOptSecret(ctl, cmd, &uuid);
|
||||||
if (secret == NULL)
|
if (secret == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -331,7 +333,7 @@ cmdSecretUndefine(vshControl *ctl, const vshCmd *cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
vshSecretSorter(const void *a, const void *b)
|
virshSecretSorter(const void *a, const void *b)
|
||||||
{
|
{
|
||||||
virSecretPtr *sa = (virSecretPtr *) a;
|
virSecretPtr *sa = (virSecretPtr *) a;
|
||||||
virSecretPtr *sb = (virSecretPtr *) b;
|
virSecretPtr *sb = (virSecretPtr *) b;
|
||||||
@ -350,14 +352,14 @@ vshSecretSorter(const void *a, const void *b)
|
|||||||
return vshStrcasecmp(uuid_sa, uuid_sb);
|
return vshStrcasecmp(uuid_sa, uuid_sb);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct vshSecretList {
|
struct virshSecretList {
|
||||||
virSecretPtr *secrets;
|
virSecretPtr *secrets;
|
||||||
size_t nsecrets;
|
size_t nsecrets;
|
||||||
};
|
};
|
||||||
typedef struct vshSecretList *vshSecretListPtr;
|
typedef struct virshSecretList *virshSecretListPtr;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
vshSecretListFree(vshSecretListPtr list)
|
virshSecretListFree(virshSecretListPtr list)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
@ -371,11 +373,11 @@ vshSecretListFree(vshSecretListPtr list)
|
|||||||
VIR_FREE(list);
|
VIR_FREE(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
static vshSecretListPtr
|
static virshSecretListPtr
|
||||||
vshSecretListCollect(vshControl *ctl,
|
virshSecretListCollect(vshControl *ctl,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
vshSecretListPtr list = vshMalloc(ctl, sizeof(*list));
|
virshSecretListPtr list = vshMalloc(ctl, sizeof(*list));
|
||||||
size_t i;
|
size_t i;
|
||||||
int ret;
|
int ret;
|
||||||
virSecretPtr secret;
|
virSecretPtr secret;
|
||||||
@ -383,9 +385,10 @@ vshSecretListCollect(vshControl *ctl,
|
|||||||
size_t deleted = 0;
|
size_t deleted = 0;
|
||||||
int nsecrets = 0;
|
int nsecrets = 0;
|
||||||
char **uuids = NULL;
|
char **uuids = NULL;
|
||||||
|
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 = virConnectListAllSecrets(ctl->conn,
|
if ((ret = virConnectListAllSecrets(priv->conn,
|
||||||
&list->secrets,
|
&list->secrets,
|
||||||
flags)) >= 0) {
|
flags)) >= 0) {
|
||||||
list->nsecrets = ret;
|
list->nsecrets = ret;
|
||||||
@ -410,7 +413,7 @@ vshSecretListCollect(vshControl *ctl,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsecrets = virConnectNumOfSecrets(ctl->conn);
|
nsecrets = virConnectNumOfSecrets(priv->conn);
|
||||||
if (nsecrets < 0) {
|
if (nsecrets < 0) {
|
||||||
vshError(ctl, "%s", _("Failed to count secrets"));
|
vshError(ctl, "%s", _("Failed to count secrets"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -421,7 +424,7 @@ vshSecretListCollect(vshControl *ctl,
|
|||||||
|
|
||||||
uuids = vshMalloc(ctl, sizeof(char *) * nsecrets);
|
uuids = vshMalloc(ctl, sizeof(char *) * nsecrets);
|
||||||
|
|
||||||
nsecrets = virConnectListSecrets(ctl->conn, uuids, nsecrets);
|
nsecrets = virConnectListSecrets(priv->conn, uuids, nsecrets);
|
||||||
if (nsecrets < 0) {
|
if (nsecrets < 0) {
|
||||||
vshError(ctl, "%s", _("Failed to list secrets"));
|
vshError(ctl, "%s", _("Failed to list secrets"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -432,7 +435,7 @@ vshSecretListCollect(vshControl *ctl,
|
|||||||
|
|
||||||
/* get the secrets */
|
/* get the secrets */
|
||||||
for (i = 0; i < nsecrets; i++) {
|
for (i = 0; i < nsecrets; i++) {
|
||||||
if (!(secret = virSecretLookupByUUIDString(ctl->conn, uuids[i])))
|
if (!(secret = virSecretLookupByUUIDString(priv->conn, uuids[i])))
|
||||||
continue;
|
continue;
|
||||||
list->secrets[list->nsecrets++] = secret;
|
list->secrets[list->nsecrets++] = secret;
|
||||||
}
|
}
|
||||||
@ -444,7 +447,7 @@ vshSecretListCollect(vshControl *ctl,
|
|||||||
/* sort the list */
|
/* sort the list */
|
||||||
if (list->secrets && list->nsecrets)
|
if (list->secrets && list->nsecrets)
|
||||||
qsort(list->secrets, list->nsecrets,
|
qsort(list->secrets, list->nsecrets,
|
||||||
sizeof(*list->secrets), vshSecretSorter);
|
sizeof(*list->secrets), virshSecretSorter);
|
||||||
|
|
||||||
/* truncate the list for not found secret objects */
|
/* truncate the list for not found secret objects */
|
||||||
if (deleted)
|
if (deleted)
|
||||||
@ -460,7 +463,7 @@ vshSecretListCollect(vshControl *ctl,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
vshSecretListFree(list);
|
virshSecretListFree(list);
|
||||||
list = NULL;
|
list = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -504,7 +507,7 @@ static bool
|
|||||||
cmdSecretList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
cmdSecretList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
vshSecretListPtr list = NULL;
|
virshSecretListPtr list = NULL;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
|
|
||||||
@ -520,7 +523,7 @@ cmdSecretList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
|||||||
if (vshCommandOptBool(cmd, "no-private"))
|
if (vshCommandOptBool(cmd, "no-private"))
|
||||||
flags |= VIR_CONNECT_LIST_SECRETS_NO_PRIVATE;
|
flags |= VIR_CONNECT_LIST_SECRETS_NO_PRIVATE;
|
||||||
|
|
||||||
if (!(list = vshSecretListCollect(ctl, flags)))
|
if (!(list = virshSecretListCollect(ctl, flags)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
vshPrintExtra(ctl, " %-36s %s\n", _("UUID"), _("Usage"));
|
vshPrintExtra(ctl, " %-36s %s\n", _("UUID"), _("Usage"));
|
||||||
@ -551,7 +554,7 @@ cmdSecretList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
|||||||
ret = true;
|
ret = true;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
vshSecretListFree(list);
|
virshSecretListFree(list);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,8 +44,8 @@
|
|||||||
|
|
||||||
/* Helper for snapshot-create and snapshot-create-as */
|
/* Helper for snapshot-create and snapshot-create-as */
|
||||||
static bool
|
static bool
|
||||||
vshSnapshotCreate(vshControl *ctl, virDomainPtr dom, const char *buffer,
|
virshSnapshotCreate(vshControl *ctl, virDomainPtr dom, const char *buffer,
|
||||||
unsigned int flags, const char *from)
|
unsigned int flags, const char *from)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
virDomainSnapshotPtr snapshot;
|
virDomainSnapshotPtr snapshot;
|
||||||
@ -199,7 +199,7 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (vshCommandOptBool(cmd, "live"))
|
if (vshCommandOptBool(cmd, "live"))
|
||||||
flags |= VIR_DOMAIN_SNAPSHOT_CREATE_LIVE;
|
flags |= VIR_DOMAIN_SNAPSHOT_CREATE_LIVE;
|
||||||
|
|
||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "xmlfile", &from) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "xmlfile", &from) < 0)
|
||||||
@ -213,7 +213,7 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = vshSnapshotCreate(ctl, dom, buffer, flags, from);
|
ret = virshSnapshotCreate(ctl, dom, buffer, flags, from);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(buffer);
|
VIR_FREE(buffer);
|
||||||
@ -227,7 +227,7 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd)
|
|||||||
* "snapshot-create-as" command
|
* "snapshot-create-as" command
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
vshParseSnapshotMemspec(vshControl *ctl, virBufferPtr buf, const char *str)
|
virshParseSnapshotMemspec(vshControl *ctl, virBufferPtr buf, const char *str)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
const char *snapshot = NULL;
|
const char *snapshot = NULL;
|
||||||
@ -267,7 +267,7 @@ vshParseSnapshotMemspec(vshControl *ctl, virBufferPtr buf, const char *str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
vshParseSnapshotDiskspec(vshControl *ctl, virBufferPtr buf, const char *str)
|
virshParseSnapshotDiskspec(vshControl *ctl, virBufferPtr buf, const char *str)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
const char *name = NULL;
|
const char *name = NULL;
|
||||||
@ -419,7 +419,7 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (vshCommandOptBool(cmd, "live"))
|
if (vshCommandOptBool(cmd, "live"))
|
||||||
flags |= VIR_DOMAIN_SNAPSHOT_CREATE_LIVE;
|
flags |= VIR_DOMAIN_SNAPSHOT_CREATE_LIVE;
|
||||||
|
|
||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0 ||
|
if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0 ||
|
||||||
@ -434,14 +434,14 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (vshCommandOptStringReq(ctl, cmd, "memspec", &memspec) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "memspec", &memspec) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (memspec && vshParseSnapshotMemspec(ctl, &buf, memspec) < 0)
|
if (memspec && virshParseSnapshotMemspec(ctl, &buf, memspec) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (vshCommandOptBool(cmd, "diskspec")) {
|
if (vshCommandOptBool(cmd, "diskspec")) {
|
||||||
virBufferAddLit(&buf, "<disks>\n");
|
virBufferAddLit(&buf, "<disks>\n");
|
||||||
virBufferAdjustIndent(&buf, 2);
|
virBufferAdjustIndent(&buf, 2);
|
||||||
while ((opt = vshCommandOptArgv(ctl, cmd, opt))) {
|
while ((opt = vshCommandOptArgv(ctl, cmd, opt))) {
|
||||||
if (vshParseSnapshotDiskspec(ctl, &buf, opt->data) < 0)
|
if (virshParseSnapshotDiskspec(ctl, &buf, opt->data) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
virBufferAdjustIndent(&buf, -2);
|
virBufferAdjustIndent(&buf, -2);
|
||||||
@ -463,7 +463,7 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = vshSnapshotCreate(ctl, dom, buffer, flags, NULL);
|
ret = virshSnapshotCreate(ctl, dom, buffer, flags, NULL);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virBufferFreeAndReset(&buf);
|
virBufferFreeAndReset(&buf);
|
||||||
@ -478,9 +478,9 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd)
|
|||||||
* present. On success, populate *SNAP and *NAME, before returning 0.
|
* present. On success, populate *SNAP and *NAME, before returning 0.
|
||||||
* On failure, return -1 after issuing an error message. */
|
* On failure, return -1 after issuing an error message. */
|
||||||
static int
|
static int
|
||||||
vshLookupSnapshot(vshControl *ctl, const vshCmd *cmd,
|
virshLookupSnapshot(vshControl *ctl, const vshCmd *cmd,
|
||||||
const char *arg, bool exclusive, virDomainPtr dom,
|
const char *arg, bool exclusive, virDomainPtr dom,
|
||||||
virDomainSnapshotPtr *snap, const char **name)
|
virDomainSnapshotPtr *snap, const char **name)
|
||||||
{
|
{
|
||||||
bool current = vshCommandOptBool(cmd, "current");
|
bool current = vshCommandOptBool(cmd, "current");
|
||||||
const char *snapname = NULL;
|
const char *snapname = NULL;
|
||||||
@ -568,11 +568,11 @@ cmdSnapshotEdit(vshControl *ctl, const vshCmd *cmd)
|
|||||||
vshCommandOptBool(cmd, "snapshotname"))
|
vshCommandOptBool(cmd, "snapshotname"))
|
||||||
define_flags |= VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT;
|
define_flags |= VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT;
|
||||||
|
|
||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (vshLookupSnapshot(ctl, cmd, "snapshotname", false, dom,
|
if (virshLookupSnapshot(ctl, cmd, "snapshotname", false, dom,
|
||||||
&snapshot, &name) < 0)
|
&snapshot, &name) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
#define EDIT_GET_XML \
|
#define EDIT_GET_XML \
|
||||||
@ -682,7 +682,7 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd)
|
|||||||
|
|
||||||
VSH_EXCLUSIVE_OPTIONS("name", "snapshotname");
|
VSH_EXCLUSIVE_OPTIONS("name", "snapshotname");
|
||||||
|
|
||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, &domname)))
|
if (!(dom = virshCommandOptDomain(ctl, cmd, &domname)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "snapshotname", &snapshotname) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "snapshotname", &snapshotname) < 0)
|
||||||
@ -755,19 +755,20 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd)
|
|||||||
* proven no parent exists), and -1 on failure with error reported
|
* proven no parent exists), and -1 on failure with error reported
|
||||||
* (such as no snapshot support or domain deleted in meantime). */
|
* (such as no snapshot support or domain deleted in meantime). */
|
||||||
static int
|
static int
|
||||||
vshGetSnapshotParent(vshControl *ctl, virDomainSnapshotPtr snapshot,
|
virshGetSnapshotParent(vshControl *ctl, virDomainSnapshotPtr snapshot,
|
||||||
char **parent_name)
|
char **parent_name)
|
||||||
{
|
{
|
||||||
virDomainSnapshotPtr parent = NULL;
|
virDomainSnapshotPtr parent = NULL;
|
||||||
char *xml = NULL;
|
char *xml = NULL;
|
||||||
xmlDocPtr xmldoc = NULL;
|
xmlDocPtr xmldoc = NULL;
|
||||||
xmlXPathContextPtr ctxt = NULL;
|
xmlXPathContextPtr ctxt = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
virshControlPtr priv = ctl->privData;
|
||||||
|
|
||||||
*parent_name = NULL;
|
*parent_name = NULL;
|
||||||
|
|
||||||
/* Try new API, since it is faster. */
|
/* Try new API, since it is faster. */
|
||||||
if (!ctl->useSnapshotOld) {
|
if (!priv->useSnapshotOld) {
|
||||||
parent = virDomainSnapshotGetParent(snapshot, 0);
|
parent = virDomainSnapshotGetParent(snapshot, 0);
|
||||||
if (parent) {
|
if (parent) {
|
||||||
/* API works, and virDomainSnapshotGetName will succeed */
|
/* API works, and virDomainSnapshotGetName will succeed */
|
||||||
@ -781,7 +782,7 @@ vshGetSnapshotParent(vshControl *ctl, virDomainSnapshotPtr snapshot,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
/* API didn't work, fall back to XML scraping. */
|
/* API didn't work, fall back to XML scraping. */
|
||||||
ctl->useSnapshotOld = true;
|
priv->useSnapshotOld = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
xml = virDomainSnapshotGetXMLDesc(snapshot, 0);
|
xml = virDomainSnapshotGetXMLDesc(snapshot, 0);
|
||||||
@ -815,8 +816,8 @@ vshGetSnapshotParent(vshControl *ctl, virDomainSnapshotPtr snapshot,
|
|||||||
* 1 if snapshot is okay (or if snapshot is already NULL), and -1 on
|
* 1 if snapshot is okay (or if snapshot is already NULL), and -1 on
|
||||||
* failure, with error already reported. */
|
* failure, with error already reported. */
|
||||||
static int
|
static int
|
||||||
vshSnapshotFilter(vshControl *ctl, virDomainSnapshotPtr snapshot,
|
virshSnapshotFilter(vshControl *ctl, virDomainSnapshotPtr snapshot,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
char *xml = NULL;
|
char *xml = NULL;
|
||||||
xmlDocPtr xmldoc = NULL;
|
xmlDocPtr xmldoc = NULL;
|
||||||
@ -914,13 +915,14 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd)
|
|||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
int current;
|
int current;
|
||||||
int metadata;
|
int metadata;
|
||||||
|
virshControlPtr priv = ctl->privData;
|
||||||
|
|
||||||
dom = vshCommandOptDomain(ctl, cmd, NULL);
|
dom = virshCommandOptDomain(ctl, cmd, NULL);
|
||||||
if (dom == NULL)
|
if (dom == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (vshLookupSnapshot(ctl, cmd, "snapshotname", true, dom,
|
if (virshLookupSnapshot(ctl, cmd, "snapshotname", true, dom,
|
||||||
&snapshot, &name) < 0)
|
&snapshot, &name) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
vshPrint(ctl, "%-15s %s\n", _("Name:"), name);
|
vshPrint(ctl, "%-15s %s\n", _("Name:"), name);
|
||||||
@ -996,7 +998,7 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd)
|
|||||||
/* Children, Descendants. After this point, the fallback to
|
/* Children, Descendants. After this point, the fallback to
|
||||||
* compute children is too expensive, so we gracefully quit if the
|
* compute children is too expensive, so we gracefully quit if the
|
||||||
* APIs don't exist. */
|
* APIs don't exist. */
|
||||||
if (ctl->useSnapshotOld) {
|
if (priv->useSnapshotOld) {
|
||||||
ret = true;
|
ret = true;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -1043,18 +1045,18 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Helpers for collecting a list of snapshots. */
|
/* Helpers for collecting a list of snapshots. */
|
||||||
struct vshSnap {
|
struct virshSnap {
|
||||||
virDomainSnapshotPtr snap;
|
virDomainSnapshotPtr snap;
|
||||||
char *parent;
|
char *parent;
|
||||||
};
|
};
|
||||||
struct vshSnapshotList {
|
struct virshSnapshotList {
|
||||||
struct vshSnap *snaps;
|
struct virshSnap *snaps;
|
||||||
int nsnaps;
|
int nsnaps;
|
||||||
};
|
};
|
||||||
typedef struct vshSnapshotList *vshSnapshotListPtr;
|
typedef struct virshSnapshotList *virshSnapshotListPtr;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
vshSnapshotListFree(vshSnapshotListPtr snaplist)
|
virshSnapshotListFree(virshSnapshotListPtr snaplist)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
@ -1072,10 +1074,10 @@ vshSnapshotListFree(vshSnapshotListPtr snaplist)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
vshSnapSorter(const void *a, const void *b)
|
virshSnapSorter(const void *a, const void *b)
|
||||||
{
|
{
|
||||||
const struct vshSnap *sa = a;
|
const struct virshSnap *sa = a;
|
||||||
const struct vshSnap *sb = b;
|
const struct virshSnap *sb = b;
|
||||||
|
|
||||||
if (sa->snap && !sb->snap)
|
if (sa->snap && !sb->snap)
|
||||||
return -1;
|
return -1;
|
||||||
@ -1090,10 +1092,10 @@ vshSnapSorter(const void *a, const void *b)
|
|||||||
* list is limited to descendants of the given snapshot. If FLAGS is
|
* list is limited to descendants of the given snapshot. If FLAGS is
|
||||||
* given, the list is filtered. If TREE is specified, then all but
|
* given, the list is filtered. If TREE is specified, then all but
|
||||||
* FROM or the roots will also have parent information. */
|
* FROM or the roots will also have parent information. */
|
||||||
static vshSnapshotListPtr
|
static virshSnapshotListPtr
|
||||||
vshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
|
virshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
|
||||||
virDomainSnapshotPtr from,
|
virDomainSnapshotPtr from,
|
||||||
unsigned int orig_flags, bool tree)
|
unsigned int orig_flags, bool tree)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
char **names = NULL;
|
char **names = NULL;
|
||||||
@ -1101,16 +1103,17 @@ vshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
|
|||||||
bool descendants = false;
|
bool descendants = false;
|
||||||
bool roots = false;
|
bool roots = false;
|
||||||
virDomainSnapshotPtr *snaps;
|
virDomainSnapshotPtr *snaps;
|
||||||
vshSnapshotListPtr snaplist = vshMalloc(ctl, sizeof(*snaplist));
|
virshSnapshotListPtr snaplist = vshMalloc(ctl, sizeof(*snaplist));
|
||||||
vshSnapshotListPtr ret = NULL;
|
virshSnapshotListPtr ret = NULL;
|
||||||
const char *fromname = NULL;
|
const char *fromname = NULL;
|
||||||
int start_index = -1;
|
int start_index = -1;
|
||||||
int deleted = 0;
|
int deleted = 0;
|
||||||
bool filter_fallback = false;
|
bool filter_fallback = false;
|
||||||
unsigned int flags = orig_flags;
|
unsigned int flags = orig_flags;
|
||||||
|
virshControlPtr priv = ctl->privData;
|
||||||
|
|
||||||
/* Try the interface available in 0.9.13 and newer. */
|
/* Try the interface available in 0.9.13 and newer. */
|
||||||
if (!ctl->useSnapshotOld) {
|
if (!priv->useSnapshotOld) {
|
||||||
if (from)
|
if (from)
|
||||||
count = virDomainSnapshotListAllChildren(from, &snaps, flags);
|
count = virDomainSnapshotListAllChildren(from, &snaps, flags);
|
||||||
else
|
else
|
||||||
@ -1141,8 +1144,8 @@ vshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
|
|||||||
VIR_FREE(snaps);
|
VIR_FREE(snaps);
|
||||||
if (tree) {
|
if (tree) {
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
if (vshGetSnapshotParent(ctl, snaplist->snaps[i].snap,
|
if (virshGetSnapshotParent(ctl, snaplist->snaps[i].snap,
|
||||||
&snaplist->snaps[i].parent) < 0)
|
&snaplist->snaps[i].parent) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (from) {
|
if (from) {
|
||||||
@ -1212,13 +1215,13 @@ vshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
|
|||||||
flags |= VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS;
|
flags |= VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS;
|
||||||
|
|
||||||
/* Determine if we can use the new child listing API. */
|
/* Determine if we can use the new child listing API. */
|
||||||
if (ctl->useSnapshotOld ||
|
if (priv->useSnapshotOld ||
|
||||||
((count = virDomainSnapshotNumChildren(from, flags)) < 0 &&
|
((count = virDomainSnapshotNumChildren(from, flags)) < 0 &&
|
||||||
last_error->code == VIR_ERR_NO_SUPPORT)) {
|
last_error->code == VIR_ERR_NO_SUPPORT)) {
|
||||||
/* We can emulate --from. */
|
/* We can emulate --from. */
|
||||||
/* XXX can we also emulate --leaves? */
|
/* XXX can we also emulate --leaves? */
|
||||||
vshResetLibvirtError();
|
vshResetLibvirtError();
|
||||||
ctl->useSnapshotOld = true;
|
priv->useSnapshotOld = true;
|
||||||
flags &= ~VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS;
|
flags &= ~VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS;
|
||||||
goto global;
|
goto global;
|
||||||
}
|
}
|
||||||
@ -1253,7 +1256,7 @@ vshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
|
|||||||
names = vshCalloc(ctl, sizeof(*names), count);
|
names = vshCalloc(ctl, sizeof(*names), count);
|
||||||
|
|
||||||
/* Now that we have a count, collect the list. */
|
/* Now that we have a count, collect the list. */
|
||||||
if (from && !ctl->useSnapshotOld) {
|
if (from && !priv->useSnapshotOld) {
|
||||||
if (tree) {
|
if (tree) {
|
||||||
if (count)
|
if (count)
|
||||||
count = virDomainSnapshotListChildrenNames(from, names + 1,
|
count = virDomainSnapshotListChildrenNames(from, names + 1,
|
||||||
@ -1285,15 +1288,15 @@ vshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
|
|||||||
* --from together put from as the first element without a parent;
|
* --from together put from as the first element without a parent;
|
||||||
* with the old API we still need to do a post-process filtering
|
* with the old API we still need to do a post-process filtering
|
||||||
* based on all parent information. */
|
* based on all parent information. */
|
||||||
if (tree || (from && ctl->useSnapshotOld) || roots) {
|
if (tree || (from && priv->useSnapshotOld) || roots) {
|
||||||
for (i = (from && !ctl->useSnapshotOld); i < count; i++) {
|
for (i = (from && !priv->useSnapshotOld); i < count; i++) {
|
||||||
if (from && ctl->useSnapshotOld && STREQ(names[i], fromname)) {
|
if (from && priv->useSnapshotOld && STREQ(names[i], fromname)) {
|
||||||
start_index = i;
|
start_index = i;
|
||||||
if (tree)
|
if (tree)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (vshGetSnapshotParent(ctl, snaplist->snaps[i].snap,
|
if (virshGetSnapshotParent(ctl, snaplist->snaps[i].snap,
|
||||||
&snaplist->snaps[i].parent) < 0)
|
&snaplist->snaps[i].parent) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if ((from && ((tree && !snaplist->snaps[i].parent) ||
|
if ((from && ((tree && !snaplist->snaps[i].parent) ||
|
||||||
(!descendants &&
|
(!descendants &&
|
||||||
@ -1310,7 +1313,7 @@ vshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
|
|||||||
if (tree)
|
if (tree)
|
||||||
goto success;
|
goto success;
|
||||||
|
|
||||||
if (ctl->useSnapshotOld && descendants) {
|
if (priv->useSnapshotOld && descendants) {
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
bool remaining = false;
|
bool remaining = false;
|
||||||
|
|
||||||
@ -1384,8 +1387,8 @@ vshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
|
|||||||
if (!(orig_flags & VIR_DOMAIN_SNAPSHOT_FILTERS_LOCATION))
|
if (!(orig_flags & VIR_DOMAIN_SNAPSHOT_FILTERS_LOCATION))
|
||||||
orig_flags |= VIR_DOMAIN_SNAPSHOT_FILTERS_LOCATION;
|
orig_flags |= VIR_DOMAIN_SNAPSHOT_FILTERS_LOCATION;
|
||||||
for (i = 0; i < snaplist->nsnaps; i++) {
|
for (i = 0; i < snaplist->nsnaps; i++) {
|
||||||
switch (vshSnapshotFilter(ctl, snaplist->snaps[i].snap,
|
switch (virshSnapshotFilter(ctl, snaplist->snaps[i].snap,
|
||||||
orig_flags)) {
|
orig_flags)) {
|
||||||
case 1:
|
case 1:
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
@ -1400,14 +1403,14 @@ vshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
qsort(snaplist->snaps, snaplist->nsnaps, sizeof(*snaplist->snaps),
|
qsort(snaplist->snaps, snaplist->nsnaps, sizeof(*snaplist->snaps),
|
||||||
vshSnapSorter);
|
virshSnapSorter);
|
||||||
snaplist->nsnaps -= deleted;
|
snaplist->nsnaps -= deleted;
|
||||||
|
|
||||||
ret = snaplist;
|
ret = snaplist;
|
||||||
snaplist = NULL;
|
snaplist = NULL;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
vshSnapshotListFree(snaplist);
|
virshSnapshotListFree(snaplist);
|
||||||
if (names && count > 0)
|
if (names && count > 0)
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
VIR_FREE(names[i]);
|
VIR_FREE(names[i]);
|
||||||
@ -1416,9 +1419,9 @@ vshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
vshSnapshotListLookup(int id, bool parent, void *opaque)
|
virshSnapshotListLookup(int id, bool parent, void *opaque)
|
||||||
{
|
{
|
||||||
vshSnapshotListPtr snaplist = opaque;
|
virshSnapshotListPtr snaplist = opaque;
|
||||||
if (parent)
|
if (parent)
|
||||||
return snaplist->snaps[id].parent;
|
return snaplist->snaps[id].parent;
|
||||||
return virDomainSnapshotGetName(snaplist->snaps[id].snap);
|
return virDomainSnapshotGetName(snaplist->snaps[id].snap);
|
||||||
@ -1536,7 +1539,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
|
|||||||
const char *from_snap = NULL;
|
const char *from_snap = NULL;
|
||||||
char *parent_snap = NULL;
|
char *parent_snap = NULL;
|
||||||
virDomainSnapshotPtr start = NULL;
|
virDomainSnapshotPtr start = NULL;
|
||||||
vshSnapshotListPtr snaplist = NULL;
|
virshSnapshotListPtr snaplist = NULL;
|
||||||
|
|
||||||
VSH_EXCLUSIVE_OPTIONS_VAR(tree, name);
|
VSH_EXCLUSIVE_OPTIONS_VAR(tree, name);
|
||||||
VSH_EXCLUSIVE_OPTIONS_VAR(parent, roots);
|
VSH_EXCLUSIVE_OPTIONS_VAR(parent, roots);
|
||||||
@ -1585,14 +1588,14 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
|
|||||||
flags |= VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS;
|
flags |= VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ((from || current) &&
|
if ((from || current) &&
|
||||||
vshLookupSnapshot(ctl, cmd, "from", true, dom, &start, &from_snap) < 0)
|
virshLookupSnapshot(ctl, cmd, "from", true, dom, &start, &from_snap) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(snaplist = vshSnapshotListCollect(ctl, dom, start, flags, tree)))
|
if (!(snaplist = virshSnapshotListCollect(ctl, dom, start, flags, tree)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!tree && !name) {
|
if (!tree && !name) {
|
||||||
@ -1611,7 +1614,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (tree) {
|
if (tree) {
|
||||||
for (i = 0; i < snaplist->nsnaps; i++) {
|
for (i = 0; i < snaplist->nsnaps; i++) {
|
||||||
if (!snaplist->snaps[i].parent &&
|
if (!snaplist->snaps[i].parent &&
|
||||||
vshTreePrint(ctl, vshSnapshotListLookup, snaplist,
|
vshTreePrint(ctl, virshSnapshotListLookup, snaplist,
|
||||||
snaplist->nsnaps, i) < 0)
|
snaplist->nsnaps, i) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -1675,7 +1678,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
/* this frees up memory from the last iteration of the loop */
|
/* this frees up memory from the last iteration of the loop */
|
||||||
vshSnapshotListFree(snaplist);
|
virshSnapshotListFree(snaplist);
|
||||||
VIR_FREE(parent_snap);
|
VIR_FREE(parent_snap);
|
||||||
VIR_FREE(state);
|
VIR_FREE(state);
|
||||||
if (start)
|
if (start)
|
||||||
@ -1735,7 +1738,7 @@ cmdSnapshotDumpXML(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (vshCommandOptStringReq(ctl, cmd, "snapshotname", &name) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "snapshotname", &name) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!(snapshot = virDomainSnapshotLookupByName(dom, name, 0)))
|
if (!(snapshot = virDomainSnapshotLookupByName(dom, name, 0)))
|
||||||
@ -1795,15 +1798,15 @@ cmdSnapshotParent(vshControl *ctl, const vshCmd *cmd)
|
|||||||
virDomainSnapshotPtr snapshot = NULL;
|
virDomainSnapshotPtr snapshot = NULL;
|
||||||
char *parent = NULL;
|
char *parent = NULL;
|
||||||
|
|
||||||
dom = vshCommandOptDomain(ctl, cmd, NULL);
|
dom = virshCommandOptDomain(ctl, cmd, NULL);
|
||||||
if (dom == NULL)
|
if (dom == NULL)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (vshLookupSnapshot(ctl, cmd, "snapshotname", true, dom,
|
if (virshLookupSnapshot(ctl, cmd, "snapshotname", true, dom,
|
||||||
&snapshot, &name) < 0)
|
&snapshot, &name) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (vshGetSnapshotParent(ctl, snapshot, &parent) < 0)
|
if (virshGetSnapshotParent(ctl, snapshot, &parent) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if (!parent) {
|
if (!parent) {
|
||||||
vshError(ctl, _("snapshot '%s' has no parent"), name);
|
vshError(ctl, _("snapshot '%s' has no parent"), name);
|
||||||
@ -1888,12 +1891,12 @@ cmdDomainSnapshotRevert(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (vshCommandOptBool(cmd, "force"))
|
if (vshCommandOptBool(cmd, "force"))
|
||||||
force = true;
|
force = true;
|
||||||
|
|
||||||
dom = vshCommandOptDomain(ctl, cmd, NULL);
|
dom = virshCommandOptDomain(ctl, cmd, NULL);
|
||||||
if (dom == NULL)
|
if (dom == NULL)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (vshLookupSnapshot(ctl, cmd, "snapshotname", true, dom,
|
if (virshLookupSnapshot(ctl, cmd, "snapshotname", true, dom,
|
||||||
&snapshot, &name) < 0)
|
&snapshot, &name) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
result = virDomainRevertToSnapshot(snapshot, flags);
|
result = virDomainRevertToSnapshot(snapshot, flags);
|
||||||
@ -1968,12 +1971,12 @@ cmdSnapshotDelete(vshControl *ctl, const vshCmd *cmd)
|
|||||||
virDomainSnapshotPtr snapshot = NULL;
|
virDomainSnapshotPtr snapshot = NULL;
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
|
|
||||||
dom = vshCommandOptDomain(ctl, cmd, NULL);
|
dom = virshCommandOptDomain(ctl, cmd, NULL);
|
||||||
if (dom == NULL)
|
if (dom == NULL)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (vshLookupSnapshot(ctl, cmd, "snapshotname", true, dom,
|
if (virshLookupSnapshot(ctl, cmd, "snapshotname", true, dom,
|
||||||
&snapshot, &name) < 0)
|
&snapshot, &name) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (vshCommandOptBool(cmd, "children"))
|
if (vshCommandOptBool(cmd, "children"))
|
||||||
|
@ -43,15 +43,17 @@
|
|||||||
#include "virstring.h"
|
#include "virstring.h"
|
||||||
|
|
||||||
virStorageVolPtr
|
virStorageVolPtr
|
||||||
vshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd,
|
virshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd,
|
||||||
const char *optname,
|
const char *optname,
|
||||||
const char *pooloptname,
|
const char *pooloptname,
|
||||||
const char **name, unsigned int flags)
|
const char **name, unsigned int flags)
|
||||||
{
|
{
|
||||||
virStorageVolPtr vol = NULL;
|
virStorageVolPtr vol = NULL;
|
||||||
virStoragePoolPtr pool = NULL;
|
virStoragePoolPtr pool = NULL;
|
||||||
const char *n = NULL, *p = NULL;
|
const char *n = NULL, *p = NULL;
|
||||||
virCheckFlags(VSH_BYUUID | VSH_BYNAME, NULL);
|
virshControlPtr priv = ctl->privData;
|
||||||
|
|
||||||
|
virCheckFlags(VIRSH_BYUUID | VIRSH_BYNAME, NULL);
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, optname, &n) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, optname, &n) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -61,7 +63,7 @@ vshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd,
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (p) {
|
if (p) {
|
||||||
if (!(pool = vshCommandOptPoolBy(ctl, cmd, pooloptname, name, flags)))
|
if (!(pool = virshCommandOptPoolBy(ctl, cmd, pooloptname, name, flags)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (virStoragePoolIsActive(pool) != 1) {
|
if (virStoragePoolIsActive(pool) != 1) {
|
||||||
@ -78,22 +80,22 @@ vshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd,
|
|||||||
*name = n;
|
*name = n;
|
||||||
|
|
||||||
/* try it by name */
|
/* try it by name */
|
||||||
if (pool && (flags & VSH_BYNAME)) {
|
if (pool && (flags & VIRSH_BYNAME)) {
|
||||||
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as vol name\n",
|
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as vol name\n",
|
||||||
cmd->def->name, optname);
|
cmd->def->name, optname);
|
||||||
vol = virStorageVolLookupByName(pool, n);
|
vol = virStorageVolLookupByName(pool, n);
|
||||||
}
|
}
|
||||||
/* try it by key */
|
/* try it by key */
|
||||||
if (!vol && (flags & VSH_BYUUID)) {
|
if (!vol && (flags & VIRSH_BYUUID)) {
|
||||||
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as vol key\n",
|
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as vol key\n",
|
||||||
cmd->def->name, optname);
|
cmd->def->name, optname);
|
||||||
vol = virStorageVolLookupByKey(ctl->conn, n);
|
vol = virStorageVolLookupByKey(priv->conn, n);
|
||||||
}
|
}
|
||||||
/* try it by path */
|
/* try it by path */
|
||||||
if (!vol && (flags & VSH_BYUUID)) {
|
if (!vol && (flags & VIRSH_BYUUID)) {
|
||||||
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as vol path\n",
|
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as vol path\n",
|
||||||
cmd->def->name, optname);
|
cmd->def->name, optname);
|
||||||
vol = virStorageVolLookupByPath(ctl->conn, n);
|
vol = virStorageVolLookupByPath(priv->conn, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!vol) {
|
if (!vol) {
|
||||||
@ -182,7 +184,7 @@ static const vshCmdOptDef opts_vol_create_as[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
vshVolSize(const char *data, unsigned long long *val)
|
virshVolSize(const char *data, unsigned long long *val)
|
||||||
{
|
{
|
||||||
char *end;
|
char *end;
|
||||||
if (virStrToLong_ull(data, &end, 10, val) < 0)
|
if (virStrToLong_ull(data, &end, 10, val) < 0)
|
||||||
@ -201,11 +203,12 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
|
|||||||
unsigned long long capacity, allocation = 0;
|
unsigned long long capacity, allocation = 0;
|
||||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||||
unsigned long flags = 0;
|
unsigned long flags = 0;
|
||||||
|
virshControlPtr priv = ctl->privData;
|
||||||
|
|
||||||
if (vshCommandOptBool(cmd, "prealloc-metadata"))
|
if (vshCommandOptBool(cmd, "prealloc-metadata"))
|
||||||
flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA;
|
flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA;
|
||||||
|
|
||||||
if (!(pool = vshCommandOptPool(ctl, cmd, "pool", NULL)))
|
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0)
|
||||||
@ -214,13 +217,13 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (vshCommandOptStringReq(ctl, cmd, "capacity", &capacityStr) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "capacity", &capacityStr) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (vshVolSize(capacityStr, &capacity) < 0) {
|
if (virshVolSize(capacityStr, &capacity) < 0) {
|
||||||
vshError(ctl, _("Malformed size %s"), capacityStr);
|
vshError(ctl, _("Malformed size %s"), capacityStr);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vshCommandOptString(ctl, cmd, "allocation", &allocationStr) > 0 &&
|
if (vshCommandOptString(ctl, cmd, "allocation", &allocationStr) > 0 &&
|
||||||
vshVolSize(allocationStr, &allocation) < 0) {
|
virshVolSize(allocationStr, &allocation) < 0) {
|
||||||
vshError(ctl, _("Malformed size %s"), allocationStr);
|
vshError(ctl, _("Malformed size %s"), allocationStr);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -265,7 +268,7 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
|
|||||||
vshDebug(ctl, VSH_ERR_DEBUG,
|
vshDebug(ctl, VSH_ERR_DEBUG,
|
||||||
"%s: Look up backing store volume '%s' as key\n",
|
"%s: Look up backing store volume '%s' as key\n",
|
||||||
cmd->def->name, snapshotStrVol);
|
cmd->def->name, snapshotStrVol);
|
||||||
snapVol = virStorageVolLookupByKey(ctl->conn, snapshotStrVol);
|
snapVol = virStorageVolLookupByKey(priv->conn, snapshotStrVol);
|
||||||
if (snapVol)
|
if (snapVol)
|
||||||
vshDebug(ctl, VSH_ERR_DEBUG,
|
vshDebug(ctl, VSH_ERR_DEBUG,
|
||||||
"%s: Backing store volume found using '%s' as key\n",
|
"%s: Backing store volume found using '%s' as key\n",
|
||||||
@ -277,7 +280,7 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
|
|||||||
vshDebug(ctl, VSH_ERR_DEBUG,
|
vshDebug(ctl, VSH_ERR_DEBUG,
|
||||||
"%s: Look up backing store volume '%s' as path\n",
|
"%s: Look up backing store volume '%s' as path\n",
|
||||||
cmd->def->name, snapshotStrVol);
|
cmd->def->name, snapshotStrVol);
|
||||||
snapVol = virStorageVolLookupByPath(ctl->conn, snapshotStrVol);
|
snapVol = virStorageVolLookupByPath(priv->conn, snapshotStrVol);
|
||||||
if (snapVol)
|
if (snapVol)
|
||||||
vshDebug(ctl, VSH_ERR_DEBUG,
|
vshDebug(ctl, VSH_ERR_DEBUG,
|
||||||
"%s: Backing store volume found using '%s' as path\n",
|
"%s: Backing store volume found using '%s' as path\n",
|
||||||
@ -380,7 +383,7 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (vshCommandOptBool(cmd, "prealloc-metadata"))
|
if (vshCommandOptBool(cmd, "prealloc-metadata"))
|
||||||
flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA;
|
flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA;
|
||||||
|
|
||||||
if (!(pool = vshCommandOptPool(ctl, cmd, "pool", NULL)))
|
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
|
||||||
@ -460,7 +463,7 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd)
|
|||||||
char *buffer = NULL;
|
char *buffer = NULL;
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
|
|
||||||
if (!(pool = vshCommandOptPool(ctl, cmd, "pool", NULL)))
|
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", NULL)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (vshCommandOptBool(cmd, "prealloc-metadata"))
|
if (vshCommandOptBool(cmd, "prealloc-metadata"))
|
||||||
@ -472,7 +475,7 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(inputvol = vshCommandOptVol(ctl, cmd, "vol", "inputpool", NULL)))
|
if (!(inputvol = virshCommandOptVol(ctl, cmd, "vol", "inputpool", NULL)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
|
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
|
||||||
@ -503,7 +506,7 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static xmlChar *
|
static xmlChar *
|
||||||
vshMakeCloneXML(const char *origxml, const char *newname)
|
virshMakeCloneXML(const char *origxml, const char *newname)
|
||||||
{
|
{
|
||||||
|
|
||||||
xmlDocPtr doc = NULL;
|
xmlDocPtr doc = NULL;
|
||||||
@ -581,7 +584,7 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd)
|
|||||||
bool ret = false;
|
bool ret = false;
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
|
|
||||||
if (!(origvol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL)))
|
if (!(origvol = virshCommandOptVol(ctl, cmd, "vol", "pool", NULL)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (vshCommandOptBool(cmd, "prealloc-metadata"))
|
if (vshCommandOptBool(cmd, "prealloc-metadata"))
|
||||||
@ -603,7 +606,7 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (!origxml)
|
if (!origxml)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
newxml = vshMakeCloneXML(origxml, name);
|
newxml = virshMakeCloneXML(origxml, name);
|
||||||
if (!newxml) {
|
if (!newxml) {
|
||||||
vshPrint(ctl, "%s", _("Failed to allocate XML buffer"));
|
vshPrint(ctl, "%s", _("Failed to allocate XML buffer"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -692,6 +695,7 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd)
|
|||||||
virStreamPtr st = NULL;
|
virStreamPtr st = NULL;
|
||||||
const char *name = NULL;
|
const char *name = NULL;
|
||||||
unsigned long long offset = 0, length = 0;
|
unsigned long long offset = 0, length = 0;
|
||||||
|
virshControlPtr priv = ctl->privData;
|
||||||
|
|
||||||
if (vshCommandOptULongLong(ctl, cmd, "offset", &offset) < 0)
|
if (vshCommandOptULongLong(ctl, cmd, "offset", &offset) < 0)
|
||||||
return false;
|
return false;
|
||||||
@ -699,7 +703,7 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (vshCommandOptULongLongWrap(ctl, cmd, "length", &length) < 0)
|
if (vshCommandOptULongLongWrap(ctl, cmd, "length", &length) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", &name)))
|
if (!(vol = virshCommandOptVol(ctl, cmd, "vol", "pool", &name)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "file", &file) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "file", &file) < 0)
|
||||||
@ -710,7 +714,7 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(st = virStreamNew(ctl->conn, 0))) {
|
if (!(st = virStreamNew(priv->conn, 0))) {
|
||||||
vshError(ctl, _("cannot create a new stream"));
|
vshError(ctl, _("cannot create a new stream"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -797,6 +801,7 @@ cmdVolDownload(vshControl *ctl, const vshCmd *cmd)
|
|||||||
const char *name = NULL;
|
const char *name = NULL;
|
||||||
unsigned long long offset = 0, length = 0;
|
unsigned long long offset = 0, length = 0;
|
||||||
bool created = false;
|
bool created = false;
|
||||||
|
virshControlPtr priv = ctl->privData;
|
||||||
|
|
||||||
if (vshCommandOptULongLong(ctl, cmd, "offset", &offset) < 0)
|
if (vshCommandOptULongLong(ctl, cmd, "offset", &offset) < 0)
|
||||||
return false;
|
return false;
|
||||||
@ -804,7 +809,7 @@ cmdVolDownload(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (vshCommandOptULongLongWrap(ctl, cmd, "length", &length) < 0)
|
if (vshCommandOptULongLongWrap(ctl, cmd, "length", &length) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", &name)))
|
if (!(vol = virshCommandOptVol(ctl, cmd, "vol", "pool", &name)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "file", &file) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "file", &file) < 0)
|
||||||
@ -820,7 +825,7 @@ cmdVolDownload(vshControl *ctl, const vshCmd *cmd)
|
|||||||
created = true;
|
created = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(st = virStreamNew(ctl->conn, 0))) {
|
if (!(st = virStreamNew(priv->conn, 0))) {
|
||||||
vshError(ctl, _("cannot create a new stream"));
|
vshError(ctl, _("cannot create a new stream"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -830,7 +835,7 @@ cmdVolDownload(vshControl *ctl, const vshCmd *cmd)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virStreamRecvAll(st, vshStreamSink, &fd) < 0) {
|
if (virStreamRecvAll(st, virshStreamSink, &fd) < 0) {
|
||||||
vshError(ctl, _("cannot receive data from volume %s"), name);
|
vshError(ctl, _("cannot receive data from volume %s"), name);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -892,7 +897,7 @@ cmdVolDelete(vshControl *ctl, const vshCmd *cmd)
|
|||||||
bool ret = true;
|
bool ret = true;
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", &name)))
|
if (!(vol = virshCommandOptVol(ctl, cmd, "vol", "pool", &name)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (virStorageVolDelete(vol, 0) == 0) {
|
if (virStorageVolDelete(vol, 0) == 0) {
|
||||||
@ -951,7 +956,7 @@ cmdVolWipe(vshControl *ctl, const vshCmd *cmd)
|
|||||||
int algorithm = VIR_STORAGE_VOL_WIPE_ALG_ZERO;
|
int algorithm = VIR_STORAGE_VOL_WIPE_ALG_ZERO;
|
||||||
int funcRet;
|
int funcRet;
|
||||||
|
|
||||||
if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", &name)))
|
if (!(vol = virshCommandOptVol(ctl, cmd, "vol", "pool", &name)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "algorithm", &algorithm_str) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "algorithm", &algorithm_str) < 0)
|
||||||
@ -982,8 +987,8 @@ cmdVolWipe(vshControl *ctl, const vshCmd *cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VIR_ENUM_DECL(vshStorageVol)
|
VIR_ENUM_DECL(virshStorageVol)
|
||||||
VIR_ENUM_IMPL(vshStorageVol,
|
VIR_ENUM_IMPL(virshStorageVol,
|
||||||
VIR_STORAGE_VOL_LAST,
|
VIR_STORAGE_VOL_LAST,
|
||||||
N_("file"),
|
N_("file"),
|
||||||
N_("block"),
|
N_("block"),
|
||||||
@ -992,9 +997,9 @@ VIR_ENUM_IMPL(vshStorageVol,
|
|||||||
N_("netdir"))
|
N_("netdir"))
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
vshVolumeTypeToString(int type)
|
virshVolumeTypeToString(int type)
|
||||||
{
|
{
|
||||||
const char *str = vshStorageVolTypeToString(type);
|
const char *str = virshStorageVolTypeToString(type);
|
||||||
return str ? _(str) : _("unknown");
|
return str ? _(str) : _("unknown");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1032,7 +1037,7 @@ cmdVolInfo(vshControl *ctl, const vshCmd *cmd)
|
|||||||
virStorageVolPtr vol;
|
virStorageVolPtr vol;
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
|
|
||||||
if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL)))
|
if (!(vol = virshCommandOptVol(ctl, cmd, "vol", "pool", NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
vshPrint(ctl, "%-15s %s\n", _("Name:"), virStorageVolGetName(vol));
|
vshPrint(ctl, "%-15s %s\n", _("Name:"), virStorageVolGetName(vol));
|
||||||
@ -1042,7 +1047,7 @@ cmdVolInfo(vshControl *ctl, const vshCmd *cmd)
|
|||||||
const char *unit;
|
const char *unit;
|
||||||
|
|
||||||
vshPrint(ctl, "%-15s %s\n", _("Type:"),
|
vshPrint(ctl, "%-15s %s\n", _("Type:"),
|
||||||
vshVolumeTypeToString(info.type));
|
virshVolumeTypeToString(info.type));
|
||||||
|
|
||||||
val = vshPrettyCapacity(info.capacity, &unit);
|
val = vshPrettyCapacity(info.capacity, &unit);
|
||||||
vshPrint(ctl, "%-15s %2.2lf %s\n", _("Capacity:"), val, unit);
|
vshPrint(ctl, "%-15s %2.2lf %s\n", _("Capacity:"), val, unit);
|
||||||
@ -1115,7 +1120,7 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (vshCommandOptBool(cmd, "shrink"))
|
if (vshCommandOptBool(cmd, "shrink"))
|
||||||
flags |= VIR_STORAGE_VOL_RESIZE_SHRINK;
|
flags |= VIR_STORAGE_VOL_RESIZE_SHRINK;
|
||||||
|
|
||||||
if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL)))
|
if (!(vol = virshCommandOptVol(ctl, cmd, "vol", "pool", NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "capacity", &capacityStr) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "capacity", &capacityStr) < 0)
|
||||||
@ -1137,7 +1142,7 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (delta)
|
if (delta)
|
||||||
flags |= VIR_STORAGE_VOL_RESIZE_DELTA;
|
flags |= VIR_STORAGE_VOL_RESIZE_DELTA;
|
||||||
|
|
||||||
if (vshVolSize(capacityStr, &capacity) < 0) {
|
if (virshVolSize(capacityStr, &capacity) < 0) {
|
||||||
vshError(ctl, _("Malformed size %s"), capacityStr);
|
vshError(ctl, _("Malformed size %s"), capacityStr);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -1194,7 +1199,7 @@ cmdVolDumpXML(vshControl *ctl, const vshCmd *cmd)
|
|||||||
bool ret = true;
|
bool ret = true;
|
||||||
char *dump;
|
char *dump;
|
||||||
|
|
||||||
if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL)))
|
if (!(vol = virshCommandOptVol(ctl, cmd, "vol", "pool", NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
dump = virStorageVolGetXMLDesc(vol, 0);
|
dump = virStorageVolGetXMLDesc(vol, 0);
|
||||||
@ -1210,7 +1215,7 @@ cmdVolDumpXML(vshControl *ctl, const vshCmd *cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
vshStorageVolSorter(const void *a, const void *b)
|
virshStorageVolSorter(const void *a, const void *b)
|
||||||
{
|
{
|
||||||
virStorageVolPtr *va = (virStorageVolPtr *) a;
|
virStorageVolPtr *va = (virStorageVolPtr *) a;
|
||||||
virStorageVolPtr *vb = (virStorageVolPtr *) b;
|
virStorageVolPtr *vb = (virStorageVolPtr *) b;
|
||||||
@ -1225,14 +1230,14 @@ vshStorageVolSorter(const void *a, const void *b)
|
|||||||
virStorageVolGetName(*vb));
|
virStorageVolGetName(*vb));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct vshStorageVolList {
|
struct virshStorageVolList {
|
||||||
virStorageVolPtr *vols;
|
virStorageVolPtr *vols;
|
||||||
size_t nvols;
|
size_t nvols;
|
||||||
};
|
};
|
||||||
typedef struct vshStorageVolList *vshStorageVolListPtr;
|
typedef struct virshStorageVolList *virshStorageVolListPtr;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
vshStorageVolListFree(vshStorageVolListPtr list)
|
virshStorageVolListFree(virshStorageVolListPtr list)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
@ -1246,12 +1251,12 @@ vshStorageVolListFree(vshStorageVolListPtr list)
|
|||||||
VIR_FREE(list);
|
VIR_FREE(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
static vshStorageVolListPtr
|
static virshStorageVolListPtr
|
||||||
vshStorageVolListCollect(vshControl *ctl,
|
virshStorageVolListCollect(vshControl *ctl,
|
||||||
virStoragePoolPtr pool,
|
virStoragePoolPtr pool,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
vshStorageVolListPtr list = vshMalloc(ctl, sizeof(*list));
|
virshStorageVolListPtr list = vshMalloc(ctl, sizeof(*list));
|
||||||
size_t i;
|
size_t i;
|
||||||
char **names = NULL;
|
char **names = NULL;
|
||||||
virStorageVolPtr vol = NULL;
|
virStorageVolPtr vol = NULL;
|
||||||
@ -1314,7 +1319,7 @@ vshStorageVolListCollect(vshControl *ctl,
|
|||||||
finished:
|
finished:
|
||||||
/* sort the list */
|
/* sort the list */
|
||||||
if (list->vols && list->nvols)
|
if (list->vols && list->nvols)
|
||||||
qsort(list->vols, list->nvols, sizeof(*list->vols), vshStorageVolSorter);
|
qsort(list->vols, list->nvols, sizeof(*list->vols), virshStorageVolSorter);
|
||||||
|
|
||||||
if (deleted)
|
if (deleted)
|
||||||
VIR_SHRINK_N(list->vols, list->nvols, deleted);
|
VIR_SHRINK_N(list->vols, list->nvols, deleted);
|
||||||
@ -1328,7 +1333,7 @@ vshStorageVolListCollect(vshControl *ctl,
|
|||||||
VIR_FREE(names);
|
VIR_FREE(names);
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
vshStorageVolListFree(list);
|
virshStorageVolListFree(list);
|
||||||
list = NULL;
|
list = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1383,13 +1388,13 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
|||||||
char *type;
|
char *type;
|
||||||
};
|
};
|
||||||
struct volInfoText *volInfoTexts = NULL;
|
struct volInfoText *volInfoTexts = NULL;
|
||||||
vshStorageVolListPtr list = NULL;
|
virshStorageVolListPtr list = NULL;
|
||||||
|
|
||||||
/* Look up the pool information given to us by the user */
|
/* Look up the pool information given to us by the user */
|
||||||
if (!(pool = vshCommandOptPool(ctl, cmd, "pool", NULL)))
|
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!(list = vshStorageVolListCollect(ctl, pool, 0)))
|
if (!(list = virshStorageVolListCollect(ctl, pool, 0)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (list->nvols > 0)
|
if (list->nvols > 0)
|
||||||
@ -1418,7 +1423,7 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
|||||||
|
|
||||||
/* Volume type */
|
/* Volume type */
|
||||||
volInfoTexts[i].type = vshStrdup(ctl,
|
volInfoTexts[i].type = vshStrdup(ctl,
|
||||||
vshVolumeTypeToString(volumeInfo.type));
|
virshVolumeTypeToString(volumeInfo.type));
|
||||||
|
|
||||||
val = vshPrettyCapacity(volumeInfo.capacity, &unit);
|
val = vshPrettyCapacity(volumeInfo.capacity, &unit);
|
||||||
if (virAsprintf(&volInfoTexts[i].capacity,
|
if (virAsprintf(&volInfoTexts[i].capacity,
|
||||||
@ -1571,7 +1576,7 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
|||||||
VIR_FREE(outputStr);
|
VIR_FREE(outputStr);
|
||||||
VIR_FREE(volInfoTexts);
|
VIR_FREE(volInfoTexts);
|
||||||
virStoragePoolFree(pool);
|
virStoragePoolFree(pool);
|
||||||
vshStorageVolListFree(list);
|
virshStorageVolListFree(list);
|
||||||
|
|
||||||
/* Return the desired value */
|
/* Return the desired value */
|
||||||
return ret;
|
return ret;
|
||||||
@ -1604,8 +1609,8 @@ cmdVolName(vshControl *ctl, const vshCmd *cmd)
|
|||||||
{
|
{
|
||||||
virStorageVolPtr vol;
|
virStorageVolPtr vol;
|
||||||
|
|
||||||
if (!(vol = vshCommandOptVolBy(ctl, cmd, "vol", NULL, NULL,
|
if (!(vol = virshCommandOptVolBy(ctl, cmd, "vol", NULL, NULL,
|
||||||
VSH_BYUUID)))
|
VIRSH_BYUUID)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
vshPrint(ctl, "%s\n", virStorageVolGetName(vol));
|
vshPrint(ctl, "%s\n", virStorageVolGetName(vol));
|
||||||
@ -1647,8 +1652,8 @@ cmdVolPool(vshControl *ctl, const vshCmd *cmd)
|
|||||||
char uuid[VIR_UUID_STRING_BUFLEN];
|
char uuid[VIR_UUID_STRING_BUFLEN];
|
||||||
|
|
||||||
/* Use the supplied string to locate the volume */
|
/* Use the supplied string to locate the volume */
|
||||||
if (!(vol = vshCommandOptVolBy(ctl, cmd, "vol", NULL, NULL,
|
if (!(vol = virshCommandOptVolBy(ctl, cmd, "vol", NULL, NULL,
|
||||||
VSH_BYUUID))) {
|
VIRSH_BYUUID))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1707,7 +1712,7 @@ cmdVolKey(vshControl *ctl, const vshCmd *cmd)
|
|||||||
{
|
{
|
||||||
virStorageVolPtr vol;
|
virStorageVolPtr vol;
|
||||||
|
|
||||||
if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL)))
|
if (!(vol = virshCommandOptVol(ctl, cmd, "vol", "pool", NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
vshPrint(ctl, "%s\n", virStorageVolGetKey(vol));
|
vshPrint(ctl, "%s\n", virStorageVolGetKey(vol));
|
||||||
@ -1747,7 +1752,7 @@ cmdVolPath(vshControl *ctl, const vshCmd *cmd)
|
|||||||
virStorageVolPtr vol;
|
virStorageVolPtr vol;
|
||||||
char * StorageVolPath;
|
char * StorageVolPath;
|
||||||
|
|
||||||
if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL)))
|
if (!(vol = virshCommandOptVol(ctl, cmd, "vol", "pool", NULL)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ((StorageVolPath = virStorageVolGetPath(vol)) == NULL) {
|
if ((StorageVolPath = virStorageVolGetPath(vol)) == NULL) {
|
||||||
|
@ -28,15 +28,15 @@
|
|||||||
|
|
||||||
# include "virsh.h"
|
# include "virsh.h"
|
||||||
|
|
||||||
virStorageVolPtr vshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd,
|
virStorageVolPtr virshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd,
|
||||||
const char *optname,
|
const char *optname,
|
||||||
const char *pooloptname,
|
const char *pooloptname,
|
||||||
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 vshCommandOptVol(_ctl, _cmd, _optname, _pooloptname, _name) \
|
# define virshCommandOptVol(_ctl, _cmd, _optname, _pooloptname, _name) \
|
||||||
vshCommandOptVolBy(_ctl, _cmd, _optname, _pooloptname, _name, \
|
virshCommandOptVolBy(_ctl, _cmd, _optname, _pooloptname, _name, \
|
||||||
VSH_BYUUID|VSH_BYNAME)
|
VIRSH_BYUUID | VIRSH_BYNAME)
|
||||||
|
|
||||||
extern const vshCmdDef storageVolCmds[];
|
extern const vshCmdDef storageVolCmds[];
|
||||||
|
|
||||||
|
3130
tools/virsh.c
3130
tools/virsh.c
File diff suppressed because it is too large
Load Diff
479
tools/virsh.h
479
tools/virsh.h
@ -36,492 +36,75 @@
|
|||||||
# include "internal.h"
|
# include "internal.h"
|
||||||
# include "virerror.h"
|
# include "virerror.h"
|
||||||
# include "virthread.h"
|
# include "virthread.h"
|
||||||
|
# include "vsh.h"
|
||||||
|
|
||||||
# define VSH_MAX_XML_FILE (10*1024*1024)
|
# define VIRSH_PROMPT_RW "virsh # "
|
||||||
|
# define VIRSH_PROMPT_RO "virsh > "
|
||||||
# define VSH_PROMPT_RW "virsh # "
|
|
||||||
# define VSH_PROMPT_RO "virsh > "
|
|
||||||
|
|
||||||
# define VIR_FROM_THIS VIR_FROM_NONE
|
# define VIR_FROM_THIS VIR_FROM_NONE
|
||||||
|
|
||||||
# define GETTIMEOFDAY(T) gettimeofday(T, NULL)
|
|
||||||
|
|
||||||
# define VSH_MATCH(FLAG) (flags & (FLAG))
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The log configuration
|
|
||||||
*/
|
|
||||||
# define MSG_BUFFER 4096
|
|
||||||
# define SIGN_NAME "virsh"
|
|
||||||
# define DIR_MODE (S_IWUSR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) /* 0755 */
|
|
||||||
# define FILE_MODE (S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH) /* 0644 */
|
|
||||||
# define LOCK_MODE (S_IWUSR | S_IRUSR) /* 0600 */
|
|
||||||
# define LVL_DEBUG "DEBUG"
|
|
||||||
# define LVL_INFO "INFO"
|
|
||||||
# define LVL_NOTICE "NOTICE"
|
|
||||||
# define LVL_WARNING "WARNING"
|
|
||||||
# define LVL_ERROR "ERROR"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* vshErrorLevel:
|
|
||||||
*
|
|
||||||
* Indicates the level of a log message
|
|
||||||
*/
|
|
||||||
typedef enum {
|
|
||||||
VSH_ERR_DEBUG = 0,
|
|
||||||
VSH_ERR_INFO,
|
|
||||||
VSH_ERR_NOTICE,
|
|
||||||
VSH_ERR_WARNING,
|
|
||||||
VSH_ERR_ERROR
|
|
||||||
} vshErrorLevel;
|
|
||||||
|
|
||||||
# define VSH_DEBUG_DEFAULT VSH_ERR_ERROR
|
|
||||||
|
|
||||||
/*
|
|
||||||
* virsh command line grammar:
|
|
||||||
*
|
|
||||||
* command_line = <command>\n | <command>; <command>; ...
|
|
||||||
*
|
|
||||||
* command = <keyword> <option> [--] <data>
|
|
||||||
*
|
|
||||||
* option = <bool_option> | <int_option> | <string_option>
|
|
||||||
* data = <string>
|
|
||||||
*
|
|
||||||
* bool_option = --optionname
|
|
||||||
* int_option = --optionname <number> | --optionname=<number>
|
|
||||||
* string_option = --optionname <string> | --optionname=<string>
|
|
||||||
*
|
|
||||||
* keyword = [a-zA-Z][a-zA-Z-]*
|
|
||||||
* number = [0-9]+
|
|
||||||
* string = ('[^']*'|"([^\\"]|\\.)*"|([^ \t\n\\'"]|\\.))+
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* vshCmdOptType - command option type
|
|
||||||
*/
|
|
||||||
typedef enum {
|
|
||||||
VSH_OT_BOOL, /* optional boolean option */
|
|
||||||
VSH_OT_STRING, /* optional string option */
|
|
||||||
VSH_OT_INT, /* optional or mandatory int option */
|
|
||||||
VSH_OT_DATA, /* string data (as non-option) */
|
|
||||||
VSH_OT_ARGV, /* remaining arguments */
|
|
||||||
VSH_OT_ALIAS, /* alternate spelling for a later argument */
|
|
||||||
} vshCmdOptType;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Command group types
|
* Command group types
|
||||||
*/
|
*/
|
||||||
# define VSH_CMD_GRP_DOM_MANAGEMENT "Domain Management"
|
# define VIRSH_CMD_GRP_DOM_MANAGEMENT "Domain Management"
|
||||||
# define VSH_CMD_GRP_DOM_MONITORING "Domain Monitoring"
|
# define VIRSH_CMD_GRP_DOM_MONITORING "Domain Monitoring"
|
||||||
# define VSH_CMD_GRP_STORAGE_POOL "Storage Pool"
|
# define VIRSH_CMD_GRP_STORAGE_POOL "Storage Pool"
|
||||||
# define VSH_CMD_GRP_STORAGE_VOL "Storage Volume"
|
# define VIRSH_CMD_GRP_STORAGE_VOL "Storage Volume"
|
||||||
# define VSH_CMD_GRP_NETWORK "Networking"
|
# define VIRSH_CMD_GRP_NETWORK "Networking"
|
||||||
# define VSH_CMD_GRP_NODEDEV "Node Device"
|
# define VIRSH_CMD_GRP_NODEDEV "Node Device"
|
||||||
# define VSH_CMD_GRP_IFACE "Interface"
|
# define VIRSH_CMD_GRP_IFACE "Interface"
|
||||||
# define VSH_CMD_GRP_NWFILTER "Network Filter"
|
# define VIRSH_CMD_GRP_NWFILTER "Network Filter"
|
||||||
# define VSH_CMD_GRP_SECRET "Secret"
|
# define VIRSH_CMD_GRP_SECRET "Secret"
|
||||||
# define VSH_CMD_GRP_SNAPSHOT "Snapshot"
|
# define VIRSH_CMD_GRP_SNAPSHOT "Snapshot"
|
||||||
# define VSH_CMD_GRP_HOST_AND_HV "Host and Hypervisor"
|
# define VIRSH_CMD_GRP_HOST_AND_HV "Host and Hypervisor"
|
||||||
# define VSH_CMD_GRP_VIRSH "Virsh itself"
|
# define VIRSH_CMD_GRP_VIRSH "Virsh itself"
|
||||||
|
|
||||||
/*
|
typedef struct _virshControl virshControl;
|
||||||
* Command Option Flags
|
typedef virshControl *virshControlPtr;
|
||||||
*/
|
|
||||||
enum {
|
|
||||||
VSH_OFLAG_NONE = 0, /* without flags */
|
|
||||||
VSH_OFLAG_REQ = (1 << 0), /* option required */
|
|
||||||
VSH_OFLAG_EMPTY_OK = (1 << 1), /* empty string option allowed */
|
|
||||||
VSH_OFLAG_REQ_OPT = (1 << 2), /* --optionname required */
|
|
||||||
};
|
|
||||||
|
|
||||||
/* forward declarations */
|
typedef struct _virshCtrlData virshCtrlData;
|
||||||
typedef struct _vshCmd vshCmd;
|
|
||||||
typedef struct _vshCmdDef vshCmdDef;
|
|
||||||
typedef struct _vshCmdGrp vshCmdGrp;
|
|
||||||
typedef struct _vshCmdInfo vshCmdInfo;
|
|
||||||
typedef struct _vshCmdOpt vshCmdOpt;
|
|
||||||
typedef struct _vshCmdOptDef vshCmdOptDef;
|
|
||||||
typedef struct _vshControl vshControl;
|
|
||||||
typedef struct _vshCtrlData vshCtrlData;
|
|
||||||
|
|
||||||
typedef char **(*vshCompleter)(unsigned int flags);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* vshCmdInfo -- name/value pair for information about command
|
|
||||||
*
|
|
||||||
* Commands should have at least the following names:
|
|
||||||
* "help" - short description of command
|
|
||||||
* "desc" - description of command, or empty string
|
|
||||||
*/
|
|
||||||
struct _vshCmdInfo {
|
|
||||||
const char *name; /* name of information, or NULL for list end */
|
|
||||||
const char *data; /* non-NULL information */
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* vshCmdOptDef - command option definition
|
|
||||||
*/
|
|
||||||
struct _vshCmdOptDef {
|
|
||||||
const char *name; /* the name of option, or NULL for list end */
|
|
||||||
vshCmdOptType type; /* option type */
|
|
||||||
unsigned int flags; /* flags */
|
|
||||||
const char *help; /* non-NULL help string; or for VSH_OT_ALIAS
|
|
||||||
* the name of a later public option */
|
|
||||||
vshCompleter completer; /* option completer */
|
|
||||||
unsigned int completer_flags; /* option completer flags */
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* vshCmdOpt - command options
|
|
||||||
*
|
|
||||||
* After parsing a command, all arguments to the command have been
|
|
||||||
* collected into a list of these objects.
|
|
||||||
*/
|
|
||||||
struct _vshCmdOpt {
|
|
||||||
const vshCmdOptDef *def; /* non-NULL pointer to option definition */
|
|
||||||
char *data; /* allocated data, or NULL for bool option */
|
|
||||||
vshCmdOpt *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Command Usage Flags
|
|
||||||
*/
|
|
||||||
enum {
|
|
||||||
VSH_CMD_FLAG_NOCONNECT = (1 << 0), /* no prior connection needed */
|
|
||||||
VSH_CMD_FLAG_ALIAS = (1 << 1), /* command is an alias */
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* vshCmdDef - command definition
|
|
||||||
*/
|
|
||||||
struct _vshCmdDef {
|
|
||||||
const char *name; /* name of command, or NULL for list end */
|
|
||||||
bool (*handler) (vshControl *, const vshCmd *); /* command handler */
|
|
||||||
const vshCmdOptDef *opts; /* definition of command options */
|
|
||||||
const vshCmdInfo *info; /* details about command */
|
|
||||||
unsigned int flags; /* bitwise OR of VSH_CMD_FLAG */
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* vshCmd - parsed command
|
|
||||||
*/
|
|
||||||
struct _vshCmd {
|
|
||||||
const vshCmdDef *def; /* command definition */
|
|
||||||
vshCmdOpt *opts; /* list of command arguments */
|
|
||||||
vshCmd *next; /* next command */
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vshControl
|
* vshControl
|
||||||
*/
|
*/
|
||||||
struct _vshControl {
|
struct _virshControl {
|
||||||
char *name; /* connection name */
|
|
||||||
virConnectPtr conn; /* connection to hypervisor (MAY BE NULL) */
|
virConnectPtr conn; /* connection to hypervisor (MAY BE NULL) */
|
||||||
vshCmd *cmd; /* the current command */
|
|
||||||
char *cmdstr; /* string with command */
|
|
||||||
bool imode; /* interactive mode? */
|
|
||||||
bool quiet; /* quiet mode */
|
|
||||||
int debug; /* print debug messages? */
|
|
||||||
bool timing; /* print timing info? */
|
|
||||||
bool readonly; /* connect readonly (first time only, not
|
bool readonly; /* connect readonly (first time only, not
|
||||||
* during explicit connect command)
|
* during explicit connect command)
|
||||||
*/
|
*/
|
||||||
char *logfile; /* log file name */
|
|
||||||
int log_fd; /* log file descriptor */
|
|
||||||
char *historydir; /* readline history directory name */
|
|
||||||
char *historyfile; /* readline history file name */
|
|
||||||
bool useGetInfo; /* must use virDomainGetInfo, since
|
bool useGetInfo; /* must use virDomainGetInfo, since
|
||||||
virDomainGetState is not supported */
|
virDomainGetState is not supported */
|
||||||
bool useSnapshotOld; /* cannot use virDomainSnapshotGetParent or
|
bool useSnapshotOld; /* cannot use virDomainSnapshotGetParent or
|
||||||
virDomainSnapshotNumChildren */
|
virDomainSnapshotNumChildren */
|
||||||
bool blockJobNoBytes; /* true if _BANDWIDTH_BYTE blockjob flags
|
bool blockJobNoBytes; /* true if _BANDWIDTH_BYTE blockjob flags
|
||||||
are missing */
|
are missing */
|
||||||
virThread eventLoop;
|
|
||||||
virMutex lock;
|
|
||||||
bool eventLoopStarted;
|
|
||||||
bool quit;
|
|
||||||
int eventPipe[2]; /* Write-to-self pipe to end waiting for an
|
|
||||||
* event to occur */
|
|
||||||
int eventTimerId; /* id of event loop timeout registration */
|
|
||||||
|
|
||||||
const char *escapeChar; /* String representation of
|
const char *escapeChar; /* String representation of
|
||||||
console escape character */
|
console escape character */
|
||||||
|
|
||||||
int keepalive_interval; /* Client keepalive interval */
|
|
||||||
int keepalive_count; /* Client keepalive count */
|
|
||||||
|
|
||||||
# ifndef WIN32
|
|
||||||
struct termios termattr; /* settings of the tty terminal */
|
|
||||||
# endif
|
|
||||||
bool istty; /* is the terminal a tty */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _vshCmdGrp {
|
|
||||||
const char *name; /* name of group, or NULL for list end */
|
|
||||||
const char *keyword; /* help keyword */
|
|
||||||
const vshCmdDef *commands;
|
|
||||||
};
|
|
||||||
|
|
||||||
void vshError(vshControl *ctl, const char *format, ...)
|
|
||||||
ATTRIBUTE_FMT_PRINTF(2, 3);
|
|
||||||
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);
|
|
||||||
|
|
||||||
virConnectPtr vshConnect(vshControl *ctl, const char *uri, bool readonly);
|
|
||||||
|
|
||||||
const char *vshCmddefGetInfo(const vshCmdDef *cmd, const char *info);
|
|
||||||
const vshCmdDef *vshCmddefSearch(const char *cmdname);
|
|
||||||
bool vshCmddefHelp(vshControl *ctl, const char *name);
|
|
||||||
const vshCmdGrp *vshCmdGrpSearch(const char *grpname);
|
|
||||||
bool vshCmdGrpHelp(vshControl *ctl, const char *name);
|
|
||||||
|
|
||||||
int vshCommandOptInt(vshControl *ctl, const vshCmd *cmd,
|
|
||||||
const char *name, int *value)
|
|
||||||
ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK;
|
|
||||||
int vshCommandOptUInt(vshControl *ctl, const vshCmd *cmd,
|
|
||||||
const char *name, unsigned int *value)
|
|
||||||
ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK;
|
|
||||||
int vshCommandOptUIntWrap(vshControl *ctl, const vshCmd *cmd,
|
|
||||||
const char *name, unsigned int *value)
|
|
||||||
ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK;
|
|
||||||
int vshCommandOptUL(vshControl *ctl, const vshCmd *cmd,
|
|
||||||
const char *name, unsigned long *value)
|
|
||||||
ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK;
|
|
||||||
int vshCommandOptULWrap(vshControl *ctl, const vshCmd *cmd,
|
|
||||||
const char *name, unsigned long *value)
|
|
||||||
ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK;
|
|
||||||
int vshCommandOptString(vshControl *ctl, const vshCmd *cmd,
|
|
||||||
const char *name, const char **value)
|
|
||||||
ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK;
|
|
||||||
int vshCommandOptStringReq(vshControl *ctl, const vshCmd *cmd,
|
|
||||||
const char *name, const char **value)
|
|
||||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
|
|
||||||
ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK;
|
|
||||||
int vshCommandOptLongLong(vshControl *ctl, const vshCmd *cmd,
|
|
||||||
const char *name, long long *value)
|
|
||||||
ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK;
|
|
||||||
int vshCommandOptULongLong(vshControl *ctl, const vshCmd *cmd,
|
|
||||||
const char *name, unsigned long long *value)
|
|
||||||
ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK;
|
|
||||||
int vshCommandOptULongLongWrap(vshControl *ctl, const vshCmd *cmd,
|
|
||||||
const char *name, unsigned long long *value)
|
|
||||||
ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK;
|
|
||||||
int vshCommandOptScaledInt(vshControl *ctl, const vshCmd *cmd,
|
|
||||||
const char *name, unsigned long long *value,
|
|
||||||
int scale, unsigned long long max)
|
|
||||||
ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK;
|
|
||||||
bool vshCommandOptBool(const vshCmd *cmd, const char *name);
|
|
||||||
const vshCmdOpt *vshCommandOptArgv(vshControl *ctl, const vshCmd *cmd,
|
|
||||||
const vshCmdOpt *opt);
|
|
||||||
int vshCommandOptTimeoutToMs(vshControl *ctl, const vshCmd *cmd, int *timeout);
|
|
||||||
|
|
||||||
/* Filter flags for various vshCommandOpt*By() functions */
|
|
||||||
typedef enum {
|
|
||||||
VSH_BYID = (1 << 1),
|
|
||||||
VSH_BYUUID = (1 << 2),
|
|
||||||
VSH_BYNAME = (1 << 3),
|
|
||||||
VSH_BYMAC = (1 << 4),
|
|
||||||
} vshLookupByFlags;
|
|
||||||
|
|
||||||
/* Given an index, return either the name of that device (non-NULL) or
|
|
||||||
* of its parent (NULL if a root). */
|
|
||||||
typedef const char * (*vshTreeLookup)(int devid, bool parent, void *opaque);
|
|
||||||
int vshTreePrint(vshControl *ctl, vshTreeLookup lookup, void *opaque,
|
|
||||||
int num_devices, int devid);
|
|
||||||
|
|
||||||
void vshPrintExtra(vshControl *ctl, const char *format, ...)
|
|
||||||
ATTRIBUTE_FMT_PRINTF(2, 3);
|
|
||||||
void vshDebug(vshControl *ctl, int level, const char *format, ...)
|
|
||||||
ATTRIBUTE_FMT_PRINTF(3, 4);
|
|
||||||
|
|
||||||
/* XXX: add batch support */
|
|
||||||
# define vshPrint(_ctl, ...) vshPrintExtra(NULL, __VA_ARGS__)
|
|
||||||
|
|
||||||
/* User visible sort, so we want locale-specific case comparison. */
|
|
||||||
# define vshStrcasecmp(S1, S2) strcasecmp(S1, S2)
|
|
||||||
int vshNameSorter(const void *a, const void *b);
|
|
||||||
|
|
||||||
int vshDomainState(vshControl *ctl, virDomainPtr dom, int *reason);
|
|
||||||
virTypedParameterPtr vshFindTypedParamByName(const char *name,
|
|
||||||
virTypedParameterPtr list,
|
|
||||||
int count);
|
|
||||||
char *vshGetTypedParamValue(vshControl *ctl, virTypedParameterPtr item)
|
|
||||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
|
||||||
|
|
||||||
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, bool relax_avail);
|
|
||||||
int vshStreamSink(virStreamPtr st, const char *bytes, size_t nbytes,
|
|
||||||
void *opaque);
|
|
||||||
double vshPrettyCapacity(unsigned long long val, const char **unit);
|
|
||||||
int vshStringToArray(const char *str, char ***array);
|
|
||||||
|
|
||||||
/* Typedefs, function prototypes for job progress reporting.
|
/* Typedefs, function prototypes for job progress reporting.
|
||||||
* There are used by some long lingering commands like
|
* There are used by some long lingering commands like
|
||||||
* migrate, dump, save, managedsave.
|
* migrate, dump, save, managedsave.
|
||||||
*/
|
*/
|
||||||
struct _vshCtrlData {
|
struct _virshCtrlData {
|
||||||
vshControl *ctl;
|
vshControl *ctl;
|
||||||
const vshCmd *cmd;
|
const vshCmd *cmd;
|
||||||
int writefd;
|
int writefd;
|
||||||
virConnectPtr dconn;
|
virConnectPtr dconn;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* error handling */
|
/* Filter flags for various vshCommandOpt*By() functions */
|
||||||
extern virErrorPtr last_error;
|
typedef enum {
|
||||||
void vshReportError(vshControl *ctl);
|
VIRSH_BYID = (1 << 1),
|
||||||
void vshResetLibvirtError(void);
|
VIRSH_BYUUID = (1 << 2),
|
||||||
void vshSaveLibvirtError(void);
|
VIRSH_BYNAME = (1 << 3),
|
||||||
|
VIRSH_BYMAC = (1 << 4),
|
||||||
|
} virshLookupByFlags;
|
||||||
|
|
||||||
/* terminal modifications */
|
virConnectPtr virshConnect(vshControl *ctl, const char *uri, bool readonly);
|
||||||
bool vshTTYIsInterruptCharacter(vshControl *ctl, const char chr);
|
int virshDomainState(vshControl *ctl, virDomainPtr dom, int *reason);
|
||||||
int vshTTYDisableInterrupt(vshControl *ctl);
|
|
||||||
int vshTTYRestore(vshControl *ctl);
|
|
||||||
int vshTTYMakeRaw(vshControl *ctl, bool report_errors);
|
|
||||||
bool vshTTYAvailable(vshControl *ctl);
|
|
||||||
|
|
||||||
/* waiting for events */
|
int virshStreamSink(virStreamPtr st, const char *bytes, size_t nbytes,
|
||||||
enum {
|
void *opaque);
|
||||||
VSH_EVENT_INTERRUPT,
|
|
||||||
VSH_EVENT_TIMEOUT,
|
|
||||||
VSH_EVENT_DONE,
|
|
||||||
};
|
|
||||||
int vshEventStart(vshControl *ctl, int timeout_ms);
|
|
||||||
void vshEventDone(vshControl *ctl);
|
|
||||||
int vshEventWait(vshControl *ctl);
|
|
||||||
void vshEventCleanup(vshControl *ctl);
|
|
||||||
|
|
||||||
/* allocation wrappers */
|
|
||||||
void *_vshMalloc(vshControl *ctl, size_t sz, const char *filename, int line);
|
|
||||||
# define vshMalloc(_ctl, _sz) _vshMalloc(_ctl, _sz, __FILE__, __LINE__)
|
|
||||||
|
|
||||||
void *_vshCalloc(vshControl *ctl, size_t nmemb, size_t sz,
|
|
||||||
const char *filename, int line);
|
|
||||||
# define vshCalloc(_ctl, _nmemb, _sz) \
|
|
||||||
_vshCalloc(_ctl, _nmemb, _sz, __FILE__, __LINE__)
|
|
||||||
|
|
||||||
char *_vshStrdup(vshControl *ctl, const char *s, const char *filename,
|
|
||||||
int line);
|
|
||||||
# define vshStrdup(_ctl, _s) _vshStrdup(_ctl, _s, __FILE__, __LINE__)
|
|
||||||
|
|
||||||
/* Poison the raw allocating identifiers in favor of our vsh variants. */
|
|
||||||
# undef malloc
|
|
||||||
# undef calloc
|
|
||||||
# undef realloc
|
|
||||||
# undef strdup
|
|
||||||
# define malloc use_vshMalloc_instead_of_malloc
|
|
||||||
# define calloc use_vshCalloc_instead_of_calloc
|
|
||||||
# define realloc use_vshRealloc_instead_of_realloc
|
|
||||||
# define strdup use_vshStrdup_instead_of_strdup
|
|
||||||
|
|
||||||
/* Macros to help dealing with mutually exclusive options. */
|
|
||||||
|
|
||||||
/* VSH_EXCLUSIVE_OPTIONS_EXPR:
|
|
||||||
*
|
|
||||||
* @NAME1: String containing the name of the option.
|
|
||||||
* @EXPR1: Expression to validate the variable (boolean variable)
|
|
||||||
* @NAME2: String containing the name of the option.
|
|
||||||
* @EXPR2: Expression to validate the variable (boolean variable)
|
|
||||||
*
|
|
||||||
* Reject mutually exclusive command options in virsh. Use the
|
|
||||||
* provided expression to check the variables.
|
|
||||||
*
|
|
||||||
* This helper does an early return and therefore it has to be called
|
|
||||||
* before anything that would require cleanup.
|
|
||||||
*/
|
|
||||||
# define VSH_EXCLUSIVE_OPTIONS_EXPR(NAME1, EXPR1, NAME2, EXPR2) \
|
|
||||||
if ((EXPR1) && (EXPR2)) { \
|
|
||||||
vshError(ctl, _("Options --%s and --%s are mutually exclusive"), \
|
|
||||||
NAME1, NAME2); \
|
|
||||||
return false; \
|
|
||||||
}
|
|
||||||
|
|
||||||
/* VSH_EXCLUSIVE_OPTIONS:
|
|
||||||
*
|
|
||||||
* @NAME1: String containing the name of the option.
|
|
||||||
* @NAME2: String containing the name of the option.
|
|
||||||
*
|
|
||||||
* Reject mutually exclusive command options in virsh. Use the
|
|
||||||
* vshCommandOptBool call to request them.
|
|
||||||
*
|
|
||||||
* This helper does an early return and therefore it has to be called
|
|
||||||
* before anything that would require cleanup.
|
|
||||||
*/
|
|
||||||
# define VSH_EXCLUSIVE_OPTIONS(NAME1, NAME2) \
|
|
||||||
VSH_EXCLUSIVE_OPTIONS_EXPR(NAME1, vshCommandOptBool(cmd, NAME1), \
|
|
||||||
NAME2, vshCommandOptBool(cmd, NAME2))
|
|
||||||
|
|
||||||
/* VSH_EXCLUSIVE_OPTIONS_VAR:
|
|
||||||
*
|
|
||||||
* @VARNAME1: Boolean variable containing the value of the option of same name
|
|
||||||
* @VARNAME2: Boolean variable containing the value of the option of same name
|
|
||||||
*
|
|
||||||
* Reject mutually exclusive command options in virsh. Check in variables that
|
|
||||||
* contain the value and have same name as the option.
|
|
||||||
*
|
|
||||||
* This helper does an early return and therefore it has to be called
|
|
||||||
* before anything that would require cleanup.
|
|
||||||
*/
|
|
||||||
# define VSH_EXCLUSIVE_OPTIONS_VAR(VARNAME1, VARNAME2) \
|
|
||||||
VSH_EXCLUSIVE_OPTIONS_EXPR(#VARNAME1, VARNAME1, #VARNAME2, VARNAME2)
|
|
||||||
|
|
||||||
/* Macros to help dealing with required options. */
|
|
||||||
|
|
||||||
/* VSH_REQUIRE_OPTION_EXPR:
|
|
||||||
*
|
|
||||||
* @NAME1: String containing the name of the option.
|
|
||||||
* @EXPR1: Expression to validate the variable (boolean variable).
|
|
||||||
* @NAME2: String containing the name of required option.
|
|
||||||
* @EXPR2: Expression to validate the variable (boolean variable).
|
|
||||||
*
|
|
||||||
* Check if required command options in virsh was set. Use the
|
|
||||||
* provided expression to check the variables.
|
|
||||||
*
|
|
||||||
* This helper does an early return and therefore it has to be called
|
|
||||||
* before anything that would require cleanup.
|
|
||||||
*/
|
|
||||||
# define VSH_REQUIRE_OPTION_EXPR(NAME1, EXPR1, NAME2, EXPR2) \
|
|
||||||
do { \
|
|
||||||
if ((EXPR1) && !(EXPR2)) { \
|
|
||||||
vshError(ctl, _("Option --%s is required by option --%s"), \
|
|
||||||
NAME2, NAME1); \
|
|
||||||
return false; \
|
|
||||||
} \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
/* VSH_REQUIRE_OPTION:
|
|
||||||
*
|
|
||||||
* @NAME1: String containing the name of the option.
|
|
||||||
* @NAME2: String containing the name of required option.
|
|
||||||
*
|
|
||||||
* Check if required command options in virsh was set. Use the
|
|
||||||
* vshCommandOptBool call to request them.
|
|
||||||
*
|
|
||||||
* This helper does an early return and therefore it has to be called
|
|
||||||
* before anything that would require cleanup.
|
|
||||||
*/
|
|
||||||
# define VSH_REQUIRE_OPTION(NAME1, NAME2) \
|
|
||||||
VSH_REQUIRE_OPTION_EXPR(NAME1, vshCommandOptBool(cmd, NAME1), \
|
|
||||||
NAME2, vshCommandOptBool(cmd, NAME2))
|
|
||||||
|
|
||||||
/* VSH_REQUIRE_OPTION_VAR:
|
|
||||||
*
|
|
||||||
* @VARNAME1: Boolean variable containing the value of the option of same name.
|
|
||||||
* @VARNAME2: Boolean variable containing the value of required option of
|
|
||||||
* same name.
|
|
||||||
*
|
|
||||||
* Check if required command options in virsh was set. Check in variables
|
|
||||||
* that contain the value and have same name as the option.
|
|
||||||
*
|
|
||||||
* This helper does an early return and therefore it has to be called
|
|
||||||
* before anything that would require cleanup.
|
|
||||||
*/
|
|
||||||
# define VSH_REQUIRE_OPTION_VAR(VARNAME1, VARNAME2) \
|
|
||||||
VSH_REQUIRE_OPTION_EXPR(#VARNAME1, VARNAME1, #VARNAME2, VARNAME2)
|
|
||||||
|
|
||||||
#endif /* VIRSH_H */
|
#endif /* VIRSH_H */
|
||||||
|
2995
tools/vsh.c
Normal file
2995
tools/vsh.c
Normal file
File diff suppressed because it is too large
Load Diff
568
tools/vsh.h
Normal file
568
tools/vsh.h
Normal file
@ -0,0 +1,568 @@
|
|||||||
|
/*
|
||||||
|
* vsh.h: common data to be used by clients to exercise the libvirt API
|
||||||
|
*
|
||||||
|
* Copyright (C) 2005, 2007-2015 Red Hat, Inc.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Daniel Veillard <veillard@redhat.com>
|
||||||
|
* Karel Zak <kzak@redhat.com>
|
||||||
|
* Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef VSH_H
|
||||||
|
# define VSH_H
|
||||||
|
|
||||||
|
# include <stdio.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
# include <string.h>
|
||||||
|
# include <stdarg.h>
|
||||||
|
# include <unistd.h>
|
||||||
|
# include <sys/stat.h>
|
||||||
|
# include <termios.h>
|
||||||
|
|
||||||
|
# include "internal.h"
|
||||||
|
# include "virerror.h"
|
||||||
|
# include "virthread.h"
|
||||||
|
|
||||||
|
# define VIR_FROM_THIS VIR_FROM_NONE
|
||||||
|
|
||||||
|
# define GETTIMEOFDAY(T) gettimeofday(T, NULL)
|
||||||
|
# define VSH_MAX_XML_FILE (10*1024*1024)
|
||||||
|
# define VSH_MATCH(FLAG) (flags & (FLAG))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The log configuration
|
||||||
|
*/
|
||||||
|
# define MSG_BUFFER 4096
|
||||||
|
# define DIR_MODE (S_IWUSR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) /* 0755 */
|
||||||
|
# define FILE_MODE (S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH) /* 0644 */
|
||||||
|
# define LOCK_MODE (S_IWUSR | S_IRUSR) /* 0600 */
|
||||||
|
# define LVL_DEBUG "DEBUG"
|
||||||
|
# define LVL_INFO "INFO"
|
||||||
|
# define LVL_NOTICE "NOTICE"
|
||||||
|
# define LVL_WARNING "WARNING"
|
||||||
|
# define LVL_ERROR "ERROR"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* vshErrorLevel:
|
||||||
|
*
|
||||||
|
* Indicates the level of a log message
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
VSH_ERR_DEBUG = 0,
|
||||||
|
VSH_ERR_INFO,
|
||||||
|
VSH_ERR_NOTICE,
|
||||||
|
VSH_ERR_WARNING,
|
||||||
|
VSH_ERR_ERROR
|
||||||
|
} vshErrorLevel;
|
||||||
|
|
||||||
|
# define VSH_DEBUG_DEFAULT VSH_ERR_ERROR
|
||||||
|
|
||||||
|
/*
|
||||||
|
* virsh command line grammar:
|
||||||
|
*
|
||||||
|
* command_line = <command>\n | <command>; <command>; ...
|
||||||
|
*
|
||||||
|
* command = <keyword> <option> [--] <data>
|
||||||
|
*
|
||||||
|
* option = <bool_option> | <int_option> | <string_option>
|
||||||
|
* data = <string>
|
||||||
|
*
|
||||||
|
* bool_option = --optionname
|
||||||
|
* int_option = --optionname <number> | --optionname=<number>
|
||||||
|
* string_option = --optionname <string> | --optionname=<string>
|
||||||
|
*
|
||||||
|
* keyword = [a-zA-Z][a-zA-Z-]*
|
||||||
|
* number = [0-9]+
|
||||||
|
* string = ('[^']*'|"([^\\"]|\\.)*"|([^ \t\n\\'"]|\\.))+
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* vshCmdOptType - command option type
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
VSH_OT_BOOL, /* optional boolean option */
|
||||||
|
VSH_OT_STRING, /* optional string option */
|
||||||
|
VSH_OT_INT, /* optional or mandatory int option */
|
||||||
|
VSH_OT_DATA, /* string data (as non-option) */
|
||||||
|
VSH_OT_ARGV, /* remaining arguments */
|
||||||
|
VSH_OT_ALIAS, /* alternate spelling for a later argument */
|
||||||
|
} vshCmdOptType;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Command Option Flags
|
||||||
|
*/
|
||||||
|
enum {
|
||||||
|
VSH_OFLAG_NONE = 0, /* without flags */
|
||||||
|
VSH_OFLAG_REQ = (1 << 0), /* option required */
|
||||||
|
VSH_OFLAG_EMPTY_OK = (1 << 1), /* empty string option allowed */
|
||||||
|
VSH_OFLAG_REQ_OPT = (1 << 2), /* --optionname required */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* forward declarations */
|
||||||
|
typedef struct _vshClientHooks vshClientHooks;
|
||||||
|
typedef struct _vshCmd vshCmd;
|
||||||
|
typedef struct _vshCmdDef vshCmdDef;
|
||||||
|
typedef struct _vshCmdGrp vshCmdGrp;
|
||||||
|
typedef struct _vshCmdInfo vshCmdInfo;
|
||||||
|
typedef struct _vshCmdOpt vshCmdOpt;
|
||||||
|
typedef struct _vshCmdOptDef vshCmdOptDef;
|
||||||
|
typedef struct _vshControl vshControl;
|
||||||
|
|
||||||
|
typedef char **(*vshCompleter)(unsigned int flags);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* vshCmdInfo -- name/value pair for information about command
|
||||||
|
*
|
||||||
|
* Commands should have at least the following names:
|
||||||
|
* "help" - short description of command
|
||||||
|
* "desc" - description of command, or empty string
|
||||||
|
*/
|
||||||
|
struct _vshCmdInfo {
|
||||||
|
const char *name; /* name of information, or NULL for list end */
|
||||||
|
const char *data; /* non-NULL information */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* vshCmdOptDef - command option definition
|
||||||
|
*/
|
||||||
|
struct _vshCmdOptDef {
|
||||||
|
const char *name; /* the name of option, or NULL for list end */
|
||||||
|
vshCmdOptType type; /* option type */
|
||||||
|
unsigned int flags; /* flags */
|
||||||
|
const char *help; /* non-NULL help string; or for VSH_OT_ALIAS
|
||||||
|
* the name of a later public option */
|
||||||
|
vshCompleter completer; /* option completer */
|
||||||
|
unsigned int completer_flags; /* option completer flags */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* vshCmdOpt - command options
|
||||||
|
*
|
||||||
|
* After parsing a command, all arguments to the command have been
|
||||||
|
* collected into a list of these objects.
|
||||||
|
*/
|
||||||
|
struct _vshCmdOpt {
|
||||||
|
const vshCmdOptDef *def; /* non-NULL pointer to option definition */
|
||||||
|
char *data; /* allocated data, or NULL for bool option */
|
||||||
|
vshCmdOpt *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Command Usage Flags
|
||||||
|
*/
|
||||||
|
enum {
|
||||||
|
VSH_CMD_FLAG_NOCONNECT = (1 << 0), /* no prior connection needed */
|
||||||
|
VSH_CMD_FLAG_ALIAS = (1 << 1), /* command is an alias */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* vshCmdDef - command definition
|
||||||
|
*/
|
||||||
|
struct _vshCmdDef {
|
||||||
|
const char *name; /* name of command, or NULL for list end */
|
||||||
|
bool (*handler) (vshControl *, const vshCmd *); /* command handler */
|
||||||
|
const vshCmdOptDef *opts; /* definition of command options */
|
||||||
|
const vshCmdInfo *info; /* details about command */
|
||||||
|
unsigned int flags; /* bitwise OR of VSH_CMD_FLAG */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* vshCmd - parsed command
|
||||||
|
*/
|
||||||
|
struct _vshCmd {
|
||||||
|
const vshCmdDef *def; /* command definition */
|
||||||
|
vshCmdOpt *opts; /* list of command arguments */
|
||||||
|
vshCmd *next; /* next command */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* vshControl
|
||||||
|
*/
|
||||||
|
struct _vshControl {
|
||||||
|
const char *name; /* hardcoded name of the binary that cannot
|
||||||
|
* be changed without recompilation compared
|
||||||
|
* to program name */
|
||||||
|
char *connname; /* connection name */
|
||||||
|
char *progname; /* program name */
|
||||||
|
vshCmd *cmd; /* the current command */
|
||||||
|
char *cmdstr; /* string with command */
|
||||||
|
bool imode; /* interactive mode? */
|
||||||
|
bool quiet; /* quiet mode */
|
||||||
|
bool timing; /* print timing info? */
|
||||||
|
int debug; /* print debug messages? */
|
||||||
|
char *logfile; /* log file name */
|
||||||
|
int log_fd; /* log file descriptor */
|
||||||
|
char *historydir; /* readline history directory name */
|
||||||
|
char *historyfile; /* readline history file name */
|
||||||
|
virThread eventLoop;
|
||||||
|
virMutex lock;
|
||||||
|
bool eventLoopStarted;
|
||||||
|
bool quit;
|
||||||
|
int eventPipe[2]; /* Write-to-self pipe to end waiting for an
|
||||||
|
* event to occur */
|
||||||
|
int eventTimerId; /* id of event loop timeout registration */
|
||||||
|
|
||||||
|
int keepalive_interval; /* Client keepalive interval */
|
||||||
|
int keepalive_count; /* Client keepalive count */
|
||||||
|
|
||||||
|
# ifndef WIN32
|
||||||
|
struct termios termattr; /* settings of the tty terminal */
|
||||||
|
# endif
|
||||||
|
bool istty; /* is the terminal a tty */
|
||||||
|
|
||||||
|
const vshClientHooks *hooks;/* mandatory client specific hooks */
|
||||||
|
void *privData; /* client specific data */
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef void *
|
||||||
|
(*vshConnectionHook)(vshControl *ctl);
|
||||||
|
|
||||||
|
struct _vshClientHooks {
|
||||||
|
vshConnectionHook connHandler;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _vshCmdGrp {
|
||||||
|
const char *name; /* name of group, or NULL for list end */
|
||||||
|
const char *keyword; /* help keyword */
|
||||||
|
const vshCmdDef *commands;
|
||||||
|
};
|
||||||
|
|
||||||
|
void vshError(vshControl *ctl, const char *format, ...)
|
||||||
|
ATTRIBUTE_FMT_PRINTF(2, 3);
|
||||||
|
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);
|
||||||
|
|
||||||
|
const char *vshCmddefGetInfo(const vshCmdDef *cmd, const char *info);
|
||||||
|
const vshCmdDef *vshCmddefSearch(const char *cmdname);
|
||||||
|
bool vshCmddefHelp(vshControl *ctl, const char *name);
|
||||||
|
const vshCmdGrp *vshCmdGrpSearch(const char *grpname);
|
||||||
|
bool vshCmdGrpHelp(vshControl *ctl, const char *name);
|
||||||
|
|
||||||
|
int vshCommandOptInt(vshControl *ctl, const vshCmd *cmd,
|
||||||
|
const char *name, int *value)
|
||||||
|
ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
int vshCommandOptUInt(vshControl *ctl, const vshCmd *cmd,
|
||||||
|
const char *name, unsigned int *value)
|
||||||
|
ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
int vshCommandOptUIntWrap(vshControl *ctl, const vshCmd *cmd,
|
||||||
|
const char *name, unsigned int *value)
|
||||||
|
ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
int vshCommandOptUL(vshControl *ctl, const vshCmd *cmd,
|
||||||
|
const char *name, unsigned long *value)
|
||||||
|
ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
int vshCommandOptULWrap(vshControl *ctl, const vshCmd *cmd,
|
||||||
|
const char *name, unsigned long *value)
|
||||||
|
ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
int vshCommandOptString(vshControl *ctl, const vshCmd *cmd,
|
||||||
|
const char *name, const char **value)
|
||||||
|
ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
int vshCommandOptStringReq(vshControl *ctl, const vshCmd *cmd,
|
||||||
|
const char *name, const char **value)
|
||||||
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
|
||||||
|
ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
int vshCommandOptLongLong(vshControl *ctl, const vshCmd *cmd,
|
||||||
|
const char *name, long long *value)
|
||||||
|
ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
int vshCommandOptULongLong(vshControl *ctl, const vshCmd *cmd,
|
||||||
|
const char *name, unsigned long long *value)
|
||||||
|
ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
int vshCommandOptULongLongWrap(vshControl *ctl, const vshCmd *cmd,
|
||||||
|
const char *name, unsigned long long *value)
|
||||||
|
ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
int vshCommandOptScaledInt(vshControl *ctl, const vshCmd *cmd,
|
||||||
|
const char *name, unsigned long long *value,
|
||||||
|
int scale, unsigned long long max)
|
||||||
|
ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
bool vshCommandOptBool(const vshCmd *cmd, const char *name);
|
||||||
|
bool vshCommandRun(vshControl *ctl, const vshCmd *cmd);
|
||||||
|
bool vshCommandStringParse(vshControl *ctl, char *cmdstr);
|
||||||
|
|
||||||
|
const vshCmdOpt *vshCommandOptArgv(vshControl *ctl, const vshCmd *cmd,
|
||||||
|
const vshCmdOpt *opt);
|
||||||
|
bool vshCommandArgvParse(vshControl *ctl, int nargs, char **argv);
|
||||||
|
int vshCommandOptTimeoutToMs(vshControl *ctl, const vshCmd *cmd, int *timeout);
|
||||||
|
|
||||||
|
void vshPrintExtra(vshControl *ctl, const char *format, ...)
|
||||||
|
ATTRIBUTE_FMT_PRINTF(2, 3);
|
||||||
|
int vshInit(vshControl *ctl, const vshCmdGrp *groups, const vshCmdDef *set);
|
||||||
|
void vshDeinit(vshControl *ctl);
|
||||||
|
void vshInitDebug(vshControl *ctl);
|
||||||
|
void vshDebug(vshControl *ctl, int level, const char *format, ...)
|
||||||
|
ATTRIBUTE_FMT_PRINTF(3, 4);
|
||||||
|
|
||||||
|
/* XXX: add batch support */
|
||||||
|
# define vshPrint(_ctl, ...) vshPrintExtra(NULL, __VA_ARGS__)
|
||||||
|
|
||||||
|
/* User visible sort, so we want locale-specific case comparison. */
|
||||||
|
# define vshStrcasecmp(S1, S2) strcasecmp(S1, S2)
|
||||||
|
int vshNameSorter(const void *a, const void *b);
|
||||||
|
|
||||||
|
virTypedParameterPtr vshFindTypedParamByName(const char *name,
|
||||||
|
virTypedParameterPtr list,
|
||||||
|
int count);
|
||||||
|
char *vshGetTypedParamValue(vshControl *ctl, virTypedParameterPtr item)
|
||||||
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
||||||
|
|
||||||
|
double vshPrettyCapacity(unsigned long long val, const char **unit);
|
||||||
|
int vshStringToArray(const char *str, char ***array);
|
||||||
|
|
||||||
|
/* Given an index, return either the name of that device (non-NULL) or
|
||||||
|
* of its parent (NULL if a root). */
|
||||||
|
typedef const char * (*vshTreeLookup)(int devid, bool parent, void *opaque);
|
||||||
|
int vshTreePrint(vshControl *ctl, vshTreeLookup lookup, void *opaque,
|
||||||
|
int num_devices, int devid);
|
||||||
|
|
||||||
|
/* error handling */
|
||||||
|
extern virErrorPtr last_error;
|
||||||
|
void vshErrorHandler(void *opaque, virErrorPtr error);
|
||||||
|
void vshReportError(vshControl *ctl);
|
||||||
|
void vshResetLibvirtError(void);
|
||||||
|
void vshSaveLibvirtError(void);
|
||||||
|
|
||||||
|
/* file handling */
|
||||||
|
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, bool relax_avail);
|
||||||
|
|
||||||
|
/* terminal modifications */
|
||||||
|
bool vshTTYIsInterruptCharacter(vshControl *ctl, const char chr);
|
||||||
|
int vshTTYDisableInterrupt(vshControl *ctl);
|
||||||
|
int vshTTYRestore(vshControl *ctl);
|
||||||
|
int vshTTYMakeRaw(vshControl *ctl, bool report_errors);
|
||||||
|
bool vshTTYAvailable(vshControl *ctl);
|
||||||
|
|
||||||
|
/* waiting for events */
|
||||||
|
enum {
|
||||||
|
VSH_EVENT_INTERRUPT,
|
||||||
|
VSH_EVENT_TIMEOUT,
|
||||||
|
VSH_EVENT_DONE,
|
||||||
|
};
|
||||||
|
void vshEventCleanup(vshControl *ctl);
|
||||||
|
void vshEventDone(vshControl *ctl);
|
||||||
|
void vshEventLoop(void *opaque);
|
||||||
|
int vshEventStart(vshControl *ctl, int timeout_ms);
|
||||||
|
void vshEventTimeout(int timer, void *opaque);
|
||||||
|
int vshEventWait(vshControl *ctl);
|
||||||
|
|
||||||
|
/* generic commands */
|
||||||
|
extern const vshCmdOptDef opts_help[];
|
||||||
|
extern const vshCmdInfo info_help[];
|
||||||
|
extern const vshCmdOptDef opts_cd[];
|
||||||
|
extern const vshCmdInfo info_cd[];
|
||||||
|
extern const vshCmdOptDef opts_echo[];
|
||||||
|
extern const vshCmdInfo info_echo[];
|
||||||
|
extern const vshCmdInfo info_pwd[];
|
||||||
|
extern const vshCmdInfo info_quit[];
|
||||||
|
|
||||||
|
bool cmdHelp(vshControl *ctl, const vshCmd *cmd);
|
||||||
|
bool cmdCd(vshControl *ctl, const vshCmd *cmd);
|
||||||
|
bool cmdEcho(vshControl *ctl, const vshCmd *cmd);
|
||||||
|
bool cmdPwd(vshControl *ctl, const vshCmd *cmd);
|
||||||
|
bool cmdQuit(vshControl *ctl, const vshCmd *cmd);
|
||||||
|
|
||||||
|
# define VSH_CMD_CD \
|
||||||
|
{ \
|
||||||
|
.name = "cd", \
|
||||||
|
.handler = cmdCd, \
|
||||||
|
.opts = opts_cd, \
|
||||||
|
.info = info_cd, \
|
||||||
|
.flags = VSH_CMD_FLAG_NOCONNECT \
|
||||||
|
}
|
||||||
|
|
||||||
|
# define VSH_CMD_ECHO \
|
||||||
|
{ \
|
||||||
|
.name = "echo", \
|
||||||
|
.handler = cmdEcho, \
|
||||||
|
.opts = opts_echo, \
|
||||||
|
.info = info_echo, \
|
||||||
|
.flags = VSH_CMD_FLAG_NOCONNECT \
|
||||||
|
}
|
||||||
|
|
||||||
|
# define VSH_CMD_EXIT \
|
||||||
|
{ \
|
||||||
|
.name = "exit", \
|
||||||
|
.handler = cmdQuit, \
|
||||||
|
.opts = NULL, \
|
||||||
|
.info = info_quit, \
|
||||||
|
.flags = VSH_CMD_FLAG_NOCONNECT \
|
||||||
|
}
|
||||||
|
|
||||||
|
# define VSH_CMD_HELP \
|
||||||
|
{ \
|
||||||
|
.name = "help", \
|
||||||
|
.handler = cmdHelp, \
|
||||||
|
.opts = opts_help, \
|
||||||
|
.info = info_help, \
|
||||||
|
.flags = VSH_CMD_FLAG_NOCONNECT \
|
||||||
|
}
|
||||||
|
|
||||||
|
# define VSH_CMD_PWD \
|
||||||
|
{ \
|
||||||
|
.name = "pwd", \
|
||||||
|
.handler = cmdPwd, \
|
||||||
|
.opts = NULL, \
|
||||||
|
.info = info_pwd, \
|
||||||
|
.flags = VSH_CMD_FLAG_NOCONNECT \
|
||||||
|
}
|
||||||
|
|
||||||
|
# define VSH_CMD_QUIT \
|
||||||
|
{ \
|
||||||
|
.name = "quit", \
|
||||||
|
.handler = cmdQuit, \
|
||||||
|
.opts = NULL, \
|
||||||
|
.info = info_quit, \
|
||||||
|
.flags = VSH_CMD_FLAG_NOCONNECT \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* readline */
|
||||||
|
char * vshReadline(vshControl *ctl, const char *prompt);
|
||||||
|
|
||||||
|
/* allocation wrappers */
|
||||||
|
void *_vshMalloc(vshControl *ctl, size_t sz, const char *filename, int line);
|
||||||
|
# define vshMalloc(_ctl, _sz) _vshMalloc(_ctl, _sz, __FILE__, __LINE__)
|
||||||
|
|
||||||
|
void *_vshCalloc(vshControl *ctl, size_t nmemb, size_t sz,
|
||||||
|
const char *filename, int line);
|
||||||
|
# define vshCalloc(_ctl, _nmemb, _sz) \
|
||||||
|
_vshCalloc(_ctl, _nmemb, _sz, __FILE__, __LINE__)
|
||||||
|
|
||||||
|
char *_vshStrdup(vshControl *ctl, const char *s, const char *filename,
|
||||||
|
int line);
|
||||||
|
# define vshStrdup(_ctl, _s) _vshStrdup(_ctl, _s, __FILE__, __LINE__)
|
||||||
|
|
||||||
|
/* Poison the raw allocating identifiers in favor of our vsh variants. */
|
||||||
|
# undef malloc
|
||||||
|
# undef calloc
|
||||||
|
# undef realloc
|
||||||
|
# undef strdup
|
||||||
|
# define malloc use_vshMalloc_instead_of_malloc
|
||||||
|
# define calloc use_vshCalloc_instead_of_calloc
|
||||||
|
# define realloc use_vshRealloc_instead_of_realloc
|
||||||
|
# define strdup use_vshStrdup_instead_of_strdup
|
||||||
|
|
||||||
|
/* Macros to help dealing with mutually exclusive options. */
|
||||||
|
|
||||||
|
/* VSH_EXCLUSIVE_OPTIONS_EXPR:
|
||||||
|
*
|
||||||
|
* @NAME1: String containing the name of the option.
|
||||||
|
* @EXPR1: Expression to validate the variable (boolean variable)
|
||||||
|
* @NAME2: String containing the name of the option.
|
||||||
|
* @EXPR2: Expression to validate the variable (boolean variable)
|
||||||
|
*
|
||||||
|
* Reject mutually exclusive command options in virsh. Use the
|
||||||
|
* provided expression to check the variables.
|
||||||
|
*
|
||||||
|
* This helper does an early return and therefore it has to be called
|
||||||
|
* before anything that would require cleanup.
|
||||||
|
*/
|
||||||
|
# define VSH_EXCLUSIVE_OPTIONS_EXPR(NAME1, EXPR1, NAME2, EXPR2) \
|
||||||
|
if ((EXPR1) && (EXPR2)) { \
|
||||||
|
vshError(ctl, _("Options --%s and --%s are mutually exclusive"), \
|
||||||
|
NAME1, NAME2); \
|
||||||
|
return false; \
|
||||||
|
}
|
||||||
|
|
||||||
|
/* VSH_EXCLUSIVE_OPTIONS:
|
||||||
|
*
|
||||||
|
* @NAME1: String containing the name of the option.
|
||||||
|
* @NAME2: String containing the name of the option.
|
||||||
|
*
|
||||||
|
* Reject mutually exclusive command options in virsh. Use the
|
||||||
|
* vshCommandOptBool call to request them.
|
||||||
|
*
|
||||||
|
* This helper does an early return and therefore it has to be called
|
||||||
|
* before anything that would require cleanup.
|
||||||
|
*/
|
||||||
|
# define VSH_EXCLUSIVE_OPTIONS(NAME1, NAME2) \
|
||||||
|
VSH_EXCLUSIVE_OPTIONS_EXPR(NAME1, vshCommandOptBool(cmd, NAME1), \
|
||||||
|
NAME2, vshCommandOptBool(cmd, NAME2))
|
||||||
|
|
||||||
|
/* VSH_EXCLUSIVE_OPTIONS_VAR:
|
||||||
|
*
|
||||||
|
* @VARNAME1: Boolean variable containing the value of the option of same name
|
||||||
|
* @VARNAME2: Boolean variable containing the value of the option of same name
|
||||||
|
*
|
||||||
|
* Reject mutually exclusive command options in virsh. Check in variables that
|
||||||
|
* contain the value and have same name as the option.
|
||||||
|
*
|
||||||
|
* This helper does an early return and therefore it has to be called
|
||||||
|
* before anything that would require cleanup.
|
||||||
|
*/
|
||||||
|
# define VSH_EXCLUSIVE_OPTIONS_VAR(VARNAME1, VARNAME2) \
|
||||||
|
VSH_EXCLUSIVE_OPTIONS_EXPR(#VARNAME1, VARNAME1, #VARNAME2, VARNAME2)
|
||||||
|
|
||||||
|
/* Macros to help dealing with required options. */
|
||||||
|
|
||||||
|
/* VSH_REQUIRE_OPTION_EXPR:
|
||||||
|
*
|
||||||
|
* @NAME1: String containing the name of the option.
|
||||||
|
* @EXPR1: Expression to validate the variable (boolean variable).
|
||||||
|
* @NAME2: String containing the name of required option.
|
||||||
|
* @EXPR2: Expression to validate the variable (boolean variable).
|
||||||
|
*
|
||||||
|
* Check if required command options in virsh was set. Use the
|
||||||
|
* provided expression to check the variables.
|
||||||
|
*
|
||||||
|
* This helper does an early return and therefore it has to be called
|
||||||
|
* before anything that would require cleanup.
|
||||||
|
*/
|
||||||
|
# define VSH_REQUIRE_OPTION_EXPR(NAME1, EXPR1, NAME2, EXPR2) \
|
||||||
|
do { \
|
||||||
|
if ((EXPR1) && !(EXPR2)) { \
|
||||||
|
vshError(ctl, _("Option --%s is required by option --%s"), \
|
||||||
|
NAME2, NAME1); \
|
||||||
|
return false; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/* VSH_REQUIRE_OPTION:
|
||||||
|
*
|
||||||
|
* @NAME1: String containing the name of the option.
|
||||||
|
* @NAME2: String containing the name of required option.
|
||||||
|
*
|
||||||
|
* Check if required command options in virsh was set. Use the
|
||||||
|
* vshCommandOptBool call to request them.
|
||||||
|
*
|
||||||
|
* This helper does an early return and therefore it has to be called
|
||||||
|
* before anything that would require cleanup.
|
||||||
|
*/
|
||||||
|
# define VSH_REQUIRE_OPTION(NAME1, NAME2) \
|
||||||
|
VSH_REQUIRE_OPTION_EXPR(NAME1, vshCommandOptBool(cmd, NAME1), \
|
||||||
|
NAME2, vshCommandOptBool(cmd, NAME2))
|
||||||
|
|
||||||
|
/* VSH_REQUIRE_OPTION_VAR:
|
||||||
|
*
|
||||||
|
* @VARNAME1: Boolean variable containing the value of the option of same name.
|
||||||
|
* @VARNAME2: Boolean variable containing the value of required option of
|
||||||
|
* same name.
|
||||||
|
*
|
||||||
|
* Check if required command options in virsh was set. Check in variables
|
||||||
|
* that contain the value and have same name as the option.
|
||||||
|
*
|
||||||
|
* This helper does an early return and therefore it has to be called
|
||||||
|
* before anything that would require cleanup.
|
||||||
|
*/
|
||||||
|
# define VSH_REQUIRE_OPTION_VAR(VARNAME1, VARNAME2) \
|
||||||
|
VSH_REQUIRE_OPTION_EXPR(#VARNAME1, VARNAME1, #VARNAME2, VARNAME2)
|
||||||
|
|
||||||
|
#endif /* VSH_H */
|
Loading…
x
Reference in New Issue
Block a user