mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06: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:
@@ -40,24 +40,24 @@
|
||||
#include "virxml.h"
|
||||
#include "virstring.h"
|
||||
|
||||
VIR_ENUM_DECL(vshDomainIOError)
|
||||
VIR_ENUM_IMPL(vshDomainIOError,
|
||||
VIR_ENUM_DECL(virshDomainIOError)
|
||||
VIR_ENUM_IMPL(virshDomainIOError,
|
||||
VIR_DOMAIN_DISK_ERROR_LAST,
|
||||
N_("no error"),
|
||||
N_("unspecified error"),
|
||||
N_("no space"))
|
||||
|
||||
static const char *
|
||||
vshDomainIOErrorToString(int error)
|
||||
virshDomainIOErrorToString(int error)
|
||||
{
|
||||
const char *str = vshDomainIOErrorTypeToString(error);
|
||||
const char *str = virshDomainIOErrorTypeToString(error);
|
||||
return str ? _(str) : _("unknown error");
|
||||
}
|
||||
|
||||
/* extract description or title from domain xml */
|
||||
char *
|
||||
vshGetDomainDescription(vshControl *ctl, virDomainPtr dom, bool title,
|
||||
unsigned int flags)
|
||||
virshGetDomainDescription(vshControl *ctl, virDomainPtr dom, bool title,
|
||||
unsigned int flags)
|
||||
{
|
||||
char *desc = NULL;
|
||||
char *domxml = NULL;
|
||||
@@ -113,8 +113,8 @@ vshGetDomainDescription(vshControl *ctl, virDomainPtr dom, bool title,
|
||||
return desc;
|
||||
}
|
||||
|
||||
VIR_ENUM_DECL(vshDomainControlState)
|
||||
VIR_ENUM_IMPL(vshDomainControlState,
|
||||
VIR_ENUM_DECL(virshDomainControlState)
|
||||
VIR_ENUM_IMPL(virshDomainControlState,
|
||||
VIR_DOMAIN_CONTROL_LAST,
|
||||
N_("ok"),
|
||||
N_("background job"),
|
||||
@@ -122,14 +122,14 @@ VIR_ENUM_IMPL(vshDomainControlState,
|
||||
N_("error"))
|
||||
|
||||
static const char *
|
||||
vshDomainControlStateToString(int state)
|
||||
virshDomainControlStateToString(int state)
|
||||
{
|
||||
const char *str = vshDomainControlStateTypeToString(state);
|
||||
const char *str = virshDomainControlStateTypeToString(state);
|
||||
return str ? _(str) : _("unknown");
|
||||
}
|
||||
|
||||
VIR_ENUM_DECL(vshDomainControlErrorReason)
|
||||
VIR_ENUM_IMPL(vshDomainControlErrorReason,
|
||||
VIR_ENUM_DECL(virshDomainControlErrorReason)
|
||||
VIR_ENUM_IMPL(virshDomainControlErrorReason,
|
||||
VIR_DOMAIN_CONTROL_ERROR_REASON_LAST,
|
||||
"",
|
||||
N_("unknown"),
|
||||
@@ -137,14 +137,14 @@ VIR_ENUM_IMPL(vshDomainControlErrorReason,
|
||||
N_("internal (locking) error"))
|
||||
|
||||
static const char *
|
||||
vshDomainControlErrorReasonToString(int reason)
|
||||
virshDomainControlErrorReasonToString(int reason)
|
||||
{
|
||||
const char *ret = vshDomainControlErrorReasonTypeToString(reason);
|
||||
const char *ret = virshDomainControlErrorReasonTypeToString(reason);
|
||||
return ret ? _(ret) : _("unknown");
|
||||
}
|
||||
|
||||
VIR_ENUM_DECL(vshDomainState)
|
||||
VIR_ENUM_IMPL(vshDomainState,
|
||||
VIR_ENUM_DECL(virshDomainState)
|
||||
VIR_ENUM_IMPL(virshDomainState,
|
||||
VIR_DOMAIN_LAST,
|
||||
N_("no state"),
|
||||
N_("running"),
|
||||
@@ -156,19 +156,19 @@ VIR_ENUM_IMPL(vshDomainState,
|
||||
N_("pmsuspended"))
|
||||
|
||||
static const char *
|
||||
vshDomainStateToString(int state)
|
||||
virshDomainStateToString(int state)
|
||||
{
|
||||
const char *str = vshDomainStateTypeToString(state);
|
||||
const char *str = virshDomainStateTypeToString(state);
|
||||
return str ? _(str) : _("no state");
|
||||
}
|
||||
|
||||
VIR_ENUM_DECL(vshDomainNostateReason)
|
||||
VIR_ENUM_IMPL(vshDomainNostateReason,
|
||||
VIR_ENUM_DECL(virshDomainNostateReason)
|
||||
VIR_ENUM_IMPL(virshDomainNostateReason,
|
||||
VIR_DOMAIN_NOSTATE_LAST,
|
||||
N_("unknown"))
|
||||
|
||||
VIR_ENUM_DECL(vshDomainRunningReason)
|
||||
VIR_ENUM_IMPL(vshDomainRunningReason,
|
||||
VIR_ENUM_DECL(virshDomainRunningReason)
|
||||
VIR_ENUM_IMPL(virshDomainRunningReason,
|
||||
VIR_DOMAIN_RUNNING_LAST,
|
||||
N_("unknown"),
|
||||
N_("booted"),
|
||||
@@ -181,13 +181,13 @@ VIR_ENUM_IMPL(vshDomainRunningReason,
|
||||
N_("event wakeup"),
|
||||
N_("crashed"))
|
||||
|
||||
VIR_ENUM_DECL(vshDomainBlockedReason)
|
||||
VIR_ENUM_IMPL(vshDomainBlockedReason,
|
||||
VIR_ENUM_DECL(virshDomainBlockedReason)
|
||||
VIR_ENUM_IMPL(virshDomainBlockedReason,
|
||||
VIR_DOMAIN_BLOCKED_LAST,
|
||||
N_("unknown"))
|
||||
|
||||
VIR_ENUM_DECL(vshDomainPausedReason)
|
||||
VIR_ENUM_IMPL(vshDomainPausedReason,
|
||||
VIR_ENUM_DECL(virshDomainPausedReason)
|
||||
VIR_ENUM_IMPL(virshDomainPausedReason,
|
||||
VIR_DOMAIN_PAUSED_LAST,
|
||||
N_("unknown"),
|
||||
N_("user"),
|
||||
@@ -202,14 +202,14 @@ VIR_ENUM_IMPL(vshDomainPausedReason,
|
||||
N_("crashed"),
|
||||
N_("starting up"))
|
||||
|
||||
VIR_ENUM_DECL(vshDomainShutdownReason)
|
||||
VIR_ENUM_IMPL(vshDomainShutdownReason,
|
||||
VIR_ENUM_DECL(virshDomainShutdownReason)
|
||||
VIR_ENUM_IMPL(virshDomainShutdownReason,
|
||||
VIR_DOMAIN_SHUTDOWN_LAST,
|
||||
N_("unknown"),
|
||||
N_("user"))
|
||||
|
||||
VIR_ENUM_DECL(vshDomainShutoffReason)
|
||||
VIR_ENUM_IMPL(vshDomainShutoffReason,
|
||||
VIR_ENUM_DECL(virshDomainShutoffReason)
|
||||
VIR_ENUM_IMPL(virshDomainShutoffReason,
|
||||
VIR_DOMAIN_SHUTOFF_LAST,
|
||||
N_("unknown"),
|
||||
N_("shutdown"),
|
||||
@@ -220,45 +220,45 @@ VIR_ENUM_IMPL(vshDomainShutoffReason,
|
||||
N_("failed"),
|
||||
N_("from snapshot"))
|
||||
|
||||
VIR_ENUM_DECL(vshDomainCrashedReason)
|
||||
VIR_ENUM_IMPL(vshDomainCrashedReason,
|
||||
VIR_ENUM_DECL(virshDomainCrashedReason)
|
||||
VIR_ENUM_IMPL(virshDomainCrashedReason,
|
||||
VIR_DOMAIN_CRASHED_LAST,
|
||||
N_("unknown"),
|
||||
N_("panicked"))
|
||||
|
||||
VIR_ENUM_DECL(vshDomainPMSuspendedReason)
|
||||
VIR_ENUM_IMPL(vshDomainPMSuspendedReason,
|
||||
VIR_ENUM_DECL(virshDomainPMSuspendedReason)
|
||||
VIR_ENUM_IMPL(virshDomainPMSuspendedReason,
|
||||
VIR_DOMAIN_PMSUSPENDED_LAST,
|
||||
N_("unknown"))
|
||||
|
||||
static const char *
|
||||
vshDomainStateReasonToString(int state, int reason)
|
||||
virshDomainStateReasonToString(int state, int reason)
|
||||
{
|
||||
const char *str = NULL;
|
||||
switch ((virDomainState) state) {
|
||||
case VIR_DOMAIN_NOSTATE:
|
||||
str = vshDomainNostateReasonTypeToString(reason);
|
||||
str = virshDomainNostateReasonTypeToString(reason);
|
||||
break;
|
||||
case VIR_DOMAIN_RUNNING:
|
||||
str = vshDomainRunningReasonTypeToString(reason);
|
||||
str = virshDomainRunningReasonTypeToString(reason);
|
||||
break;
|
||||
case VIR_DOMAIN_BLOCKED:
|
||||
str = vshDomainBlockedReasonTypeToString(reason);
|
||||
str = virshDomainBlockedReasonTypeToString(reason);
|
||||
break;
|
||||
case VIR_DOMAIN_PAUSED:
|
||||
str = vshDomainPausedReasonTypeToString(reason);
|
||||
str = virshDomainPausedReasonTypeToString(reason);
|
||||
break;
|
||||
case VIR_DOMAIN_SHUTDOWN:
|
||||
str = vshDomainShutdownReasonTypeToString(reason);
|
||||
str = virshDomainShutdownReasonTypeToString(reason);
|
||||
break;
|
||||
case VIR_DOMAIN_SHUTOFF:
|
||||
str = vshDomainShutoffReasonTypeToString(reason);
|
||||
str = virshDomainShutoffReasonTypeToString(reason);
|
||||
break;
|
||||
case VIR_DOMAIN_CRASHED:
|
||||
str = vshDomainCrashedReasonTypeToString(reason);
|
||||
str = virshDomainCrashedReasonTypeToString(reason);
|
||||
break;
|
||||
case VIR_DOMAIN_PMSUSPENDED:
|
||||
str = vshDomainPMSuspendedReasonTypeToString(reason);
|
||||
str = virshDomainPMSuspendedReasonTypeToString(reason);
|
||||
break;
|
||||
case VIR_DOMAIN_LAST:
|
||||
;
|
||||
@@ -329,7 +329,7 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd)
|
||||
if (live)
|
||||
flags |= VIR_DOMAIN_AFFECT_LIVE;
|
||||
|
||||
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
||||
if (!(dom = virshCommandOptDomain(ctl, cmd, &name)))
|
||||
return false;
|
||||
|
||||
/* If none of the options were specified and we're active
|
||||
@@ -423,7 +423,7 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd)
|
||||
bool ret = false;
|
||||
const char *device = NULL;
|
||||
|
||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
||||
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||
return false;
|
||||
|
||||
if (vshCommandOptStringReq(ctl, cmd, "device", &device) < 0)
|
||||
@@ -492,7 +492,7 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd)
|
||||
|
||||
details = vshCommandOptBool(cmd, "details");
|
||||
|
||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
||||
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||
return false;
|
||||
|
||||
xml = virDomainGetXMLDesc(dom, flags);
|
||||
@@ -608,7 +608,7 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd)
|
||||
if (vshCommandOptBool(cmd, "inactive"))
|
||||
flags |= VIR_DOMAIN_XML_INACTIVE;
|
||||
|
||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
||||
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||
return false;
|
||||
|
||||
xml = virDomainGetXMLDesc(dom, flags);
|
||||
@@ -726,7 +726,7 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd)
|
||||
if (vshCommandOptStringReq(ctl, cmd, "interface", &iface) < 0)
|
||||
return false;
|
||||
|
||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
||||
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||
return false;
|
||||
|
||||
if (vshCommandOptBool(cmd, "config"))
|
||||
@@ -815,7 +815,7 @@ cmdDomControl(vshControl *ctl, const vshCmd *cmd)
|
||||
bool ret = true;
|
||||
virDomainControlInfo info;
|
||||
|
||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
||||
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||
return false;
|
||||
|
||||
if (virDomainGetControlInfo(dom, &info, 0) < 0) {
|
||||
@@ -826,15 +826,15 @@ cmdDomControl(vshControl *ctl, const vshCmd *cmd)
|
||||
if (info.state != VIR_DOMAIN_CONTROL_OK &&
|
||||
info.state != VIR_DOMAIN_CONTROL_ERROR) {
|
||||
vshPrint(ctl, "%s (%0.3fs)\n",
|
||||
vshDomainControlStateToString(info.state),
|
||||
virshDomainControlStateToString(info.state),
|
||||
info.stateTime / 1000.0);
|
||||
} else if (info.state == VIR_DOMAIN_CONTROL_ERROR && info.details > 0) {
|
||||
vshPrint(ctl, "%s: %s\n",
|
||||
vshDomainControlStateToString(info.state),
|
||||
vshDomainControlErrorReasonToString(info.details));
|
||||
virshDomainControlStateToString(info.state),
|
||||
virshDomainControlErrorReasonToString(info.details));
|
||||
} else {
|
||||
vshPrint(ctl, "%s\n",
|
||||
vshDomainControlStateToString(info.state));
|
||||
virshDomainControlStateToString(info.state));
|
||||
}
|
||||
|
||||
cleanup:
|
||||
@@ -927,7 +927,7 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd)
|
||||
bool ret = false;
|
||||
bool human = vshCommandOptBool(cmd, "human"); /* human readable output */
|
||||
|
||||
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
||||
if (!(dom = virshCommandOptDomain(ctl, cmd, &name)))
|
||||
return false;
|
||||
|
||||
/* device argument is optional now. if it's missing, supply empty
|
||||
@@ -1068,7 +1068,7 @@ cmdDomIfstat(vshControl *ctl, const vshCmd *cmd)
|
||||
virDomainInterfaceStatsStruct stats;
|
||||
bool ret = false;
|
||||
|
||||
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
|
||||
if (!(dom = virshCommandOptDomain(ctl, cmd, &name)))
|
||||
return false;
|
||||
|
||||
if (vshCommandOptStringReq(ctl, cmd, "interface", &device) < 0)
|
||||
@@ -1142,7 +1142,7 @@ cmdDomBlkError(vshControl *ctl, const vshCmd *cmd)
|
||||
int count;
|
||||
bool ret = false;
|
||||
|
||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
||||
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||
return false;
|
||||
|
||||
if ((count = virDomainGetDiskErrors(dom, NULL, 0, 0)) < 0)
|
||||
@@ -1163,7 +1163,7 @@ cmdDomBlkError(vshControl *ctl, const vshCmd *cmd)
|
||||
for (i = 0; i < count; i++) {
|
||||
vshPrint(ctl, "%s: %s\n",
|
||||
disks[i].disk,
|
||||
vshDomainIOErrorToString(disks[i].error));
|
||||
virshDomainIOErrorToString(disks[i].error));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1210,8 +1210,9 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd)
|
||||
unsigned int id;
|
||||
char *str, uuid[VIR_UUID_STRING_BUFLEN];
|
||||
int has_managed_save = 0;
|
||||
virshControlPtr priv = ctl->privData;
|
||||
|
||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
||||
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||
return false;
|
||||
|
||||
id = virDomainGetID(dom);
|
||||
@@ -1231,7 +1232,7 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd)
|
||||
|
||||
if (virDomainGetInfo(dom, &info) == 0) {
|
||||
vshPrint(ctl, "%-15s %s\n", _("State:"),
|
||||
vshDomainStateToString(info.state));
|
||||
virshDomainStateToString(info.state));
|
||||
|
||||
vshPrint(ctl, "%-15s %d\n", _("CPU(s):"), info.nrVirtCpu);
|
||||
|
||||
@@ -1281,7 +1282,7 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd)
|
||||
|
||||
/* Security model and label information */
|
||||
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) {
|
||||
virDomainFree(dom);
|
||||
return false;
|
||||
@@ -1351,21 +1352,21 @@ cmdDomstate(vshControl *ctl, const vshCmd *cmd)
|
||||
bool showReason = vshCommandOptBool(cmd, "reason");
|
||||
int state, reason;
|
||||
|
||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
||||
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||
return false;
|
||||
|
||||
if ((state = vshDomainState(ctl, dom, &reason)) < 0) {
|
||||
if ((state = virshDomainState(ctl, dom, &reason)) < 0) {
|
||||
ret = false;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (showReason) {
|
||||
vshPrint(ctl, "%s (%s)\n",
|
||||
vshDomainStateToString(state),
|
||||
vshDomainStateReasonToString(state, reason));
|
||||
virshDomainStateToString(state),
|
||||
virshDomainStateReasonToString(state, reason));
|
||||
} else {
|
||||
vshPrint(ctl, "%s\n",
|
||||
vshDomainStateToString(state));
|
||||
virshDomainStateToString(state));
|
||||
}
|
||||
|
||||
cleanup:
|
||||
@@ -1429,7 +1430,7 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd)
|
||||
VSH_EXCLUSIVE_OPTIONS("time", "sync");
|
||||
VSH_EXCLUSIVE_OPTIONS("now", "sync");
|
||||
|
||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
||||
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||
return false;
|
||||
|
||||
rv = vshCommandOptLongLong(ctl, cmd, "time", &seconds);
|
||||
@@ -1496,7 +1497,7 @@ static const vshCmdInfo info_list[] = {
|
||||
|
||||
/* compare domains, pack NULLed ones at the end*/
|
||||
static int
|
||||
vshDomainSorter(const void *a, const void *b)
|
||||
virshDomainSorter(const void *a, const void *b)
|
||||
{
|
||||
virDomainPtr *da = (virDomainPtr *) a;
|
||||
virDomainPtr *db = (virDomainPtr *) b;
|
||||
@@ -1529,14 +1530,14 @@ vshDomainSorter(const void *a, const void *b)
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct vshDomainList {
|
||||
struct virshDomainList {
|
||||
virDomainPtr *domains;
|
||||
size_t ndomains;
|
||||
};
|
||||
typedef struct vshDomainList *vshDomainListPtr;
|
||||
typedef struct virshDomainList *virshDomainListPtr;
|
||||
|
||||
static void
|
||||
vshDomainListFree(vshDomainListPtr domlist)
|
||||
virshDomainListFree(virshDomainListPtr domlist)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@@ -1550,10 +1551,10 @@ vshDomainListFree(vshDomainListPtr domlist)
|
||||
VIR_FREE(domlist);
|
||||
}
|
||||
|
||||
static vshDomainListPtr
|
||||
vshDomainListCollect(vshControl *ctl, unsigned int flags)
|
||||
static virshDomainListPtr
|
||||
virshDomainListCollect(vshControl *ctl, unsigned int flags)
|
||||
{
|
||||
vshDomainListPtr list = vshMalloc(ctl, sizeof(*list));
|
||||
virshDomainListPtr list = vshMalloc(ctl, sizeof(*list));
|
||||
size_t i;
|
||||
int ret;
|
||||
int *ids = NULL;
|
||||
@@ -1568,9 +1569,10 @@ vshDomainListCollect(vshControl *ctl, unsigned int flags)
|
||||
int state;
|
||||
int nsnap;
|
||||
int mansave;
|
||||
virshControlPtr priv = ctl->privData;
|
||||
|
||||
/* 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) {
|
||||
list->ndomains = ret;
|
||||
goto finished;
|
||||
@@ -1588,7 +1590,7 @@ vshDomainListCollect(vshControl *ctl, unsigned int flags)
|
||||
VIR_CONNECT_LIST_DOMAINS_INACTIVE);
|
||||
|
||||
vshResetLibvirtError();
|
||||
if ((ret = virConnectListAllDomains(ctl->conn, &list->domains,
|
||||
if ((ret = virConnectListAllDomains(priv->conn, &list->domains,
|
||||
newflags)) >= 0) {
|
||||
list->ndomains = ret;
|
||||
goto filter;
|
||||
@@ -1607,7 +1609,7 @@ vshDomainListCollect(vshControl *ctl, unsigned int flags)
|
||||
/* list active domains, if necessary */
|
||||
if (!VSH_MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_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"));
|
||||
goto cleanup;
|
||||
}
|
||||
@@ -1615,7 +1617,7 @@ vshDomainListCollect(vshControl *ctl, unsigned int flags)
|
||||
if (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"));
|
||||
goto cleanup;
|
||||
}
|
||||
@@ -1624,7 +1626,7 @@ vshDomainListCollect(vshControl *ctl, unsigned int flags)
|
||||
|
||||
if (!VSH_MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE) ||
|
||||
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"));
|
||||
goto cleanup;
|
||||
}
|
||||
@@ -1632,7 +1634,7 @@ vshDomainListCollect(vshControl *ctl, unsigned int flags)
|
||||
if (nnames) {
|
||||
names = vshMalloc(ctl, sizeof(char *) * nnames);
|
||||
|
||||
if ((nnames = virConnectListDefinedDomains(ctl->conn, names,
|
||||
if ((nnames = virConnectListDefinedDomains(priv->conn, names,
|
||||
nnames)) < 0) {
|
||||
vshError(ctl, "%s", _("Failed to list inactive domains"));
|
||||
goto cleanup;
|
||||
@@ -1645,14 +1647,14 @@ vshDomainListCollect(vshControl *ctl, unsigned int flags)
|
||||
|
||||
/* get active domains */
|
||||
for (i = 0; i < nids; i++) {
|
||||
if (!(dom = virDomainLookupByID(ctl->conn, ids[i])))
|
||||
if (!(dom = virDomainLookupByID(priv->conn, ids[i])))
|
||||
continue;
|
||||
list->domains[list->ndomains++] = dom;
|
||||
}
|
||||
|
||||
/* get inactive domains */
|
||||
for (i = 0; i < nnames; i++) {
|
||||
if (!(dom = virDomainLookupByName(ctl->conn, names[i])))
|
||||
if (!(dom = virDomainLookupByName(priv->conn, names[i])))
|
||||
continue;
|
||||
list->domains[list->ndomains++] = dom;
|
||||
}
|
||||
@@ -1747,7 +1749,7 @@ vshDomainListCollect(vshControl *ctl, unsigned int flags)
|
||||
/* sort the list */
|
||||
if (list->domains && list->ndomains)
|
||||
qsort(list->domains, list->ndomains, sizeof(*list->domains),
|
||||
vshDomainSorter);
|
||||
virshDomainSorter);
|
||||
|
||||
/* truncate the list if filter simulation deleted entries */
|
||||
if (deleted)
|
||||
@@ -1760,7 +1762,7 @@ vshDomainListCollect(vshControl *ctl, unsigned int flags)
|
||||
VIR_FREE(names[i]);
|
||||
|
||||
if (!success) {
|
||||
vshDomainListFree(list);
|
||||
virshDomainListFree(list);
|
||||
list = NULL;
|
||||
}
|
||||
|
||||
@@ -1865,7 +1867,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
|
||||
char uuid[VIR_UUID_STRING_BUFLEN];
|
||||
int state;
|
||||
bool ret = false;
|
||||
vshDomainListPtr list = NULL;
|
||||
virshDomainListPtr list = NULL;
|
||||
virDomainPtr dom;
|
||||
char id_buf[INT_BUFSIZE_BOUND(unsigned int)];
|
||||
unsigned int id;
|
||||
@@ -1906,7 +1908,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
|
||||
if (!optUUID && !optName)
|
||||
optTable = true;
|
||||
|
||||
if (!(list = vshDomainListCollect(ctl, flags)))
|
||||
if (!(list = virshDomainListCollect(ctl, flags)))
|
||||
goto cleanup;
|
||||
|
||||
/* print table header in legacy mode */
|
||||
@@ -1931,7 +1933,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
|
||||
else
|
||||
ignore_value(virStrcpyStatic(id_buf, "-"));
|
||||
|
||||
state = vshDomainState(ctl, dom, NULL);
|
||||
state = virshDomainState(ctl, dom, NULL);
|
||||
|
||||
/* Domain could've been removed in the meantime */
|
||||
if (state < 0)
|
||||
@@ -1943,19 +1945,21 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
|
||||
|
||||
if (optTable) {
|
||||
if (optTitle) {
|
||||
if (!(title = vshGetDomainDescription(ctl, dom, true, 0)))
|
||||
if (!(title = virshGetDomainDescription(ctl, dom, true, 0)))
|
||||
goto cleanup;
|
||||
|
||||
vshPrint(ctl, " %-5s %-30s %-10s %-20s\n", id_buf,
|
||||
virDomainGetName(dom),
|
||||
state == -2 ? _("saved") : vshDomainStateToString(state),
|
||||
state == -2 ? _("saved")
|
||||
: virshDomainStateToString(state),
|
||||
title);
|
||||
|
||||
VIR_FREE(title);
|
||||
} else {
|
||||
vshPrint(ctl, " %-5s %-30s %s\n", id_buf,
|
||||
virDomainGetName(dom),
|
||||
state == -2 ? _("saved") : vshDomainStateToString(state));
|
||||
state == -2 ? _("saved")
|
||||
: virshDomainStateToString(state));
|
||||
}
|
||||
} else if (optUUID) {
|
||||
if (virDomainGetUUIDString(dom, uuid) < 0) {
|
||||
@@ -1970,7 +1974,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
|
||||
|
||||
ret = true;
|
||||
cleanup:
|
||||
vshDomainListFree(list);
|
||||
virshDomainListFree(list);
|
||||
return ret;
|
||||
}
|
||||
#undef FILTER
|
||||
@@ -2067,9 +2071,9 @@ static const vshCmdOptDef opts_domstats[] = {
|
||||
|
||||
|
||||
static bool
|
||||
vshDomainStatsPrintRecord(vshControl *ctl ATTRIBUTE_UNUSED,
|
||||
virDomainStatsRecordPtr record,
|
||||
bool raw ATTRIBUTE_UNUSED)
|
||||
virshDomainStatsPrintRecord(vshControl *ctl ATTRIBUTE_UNUSED,
|
||||
virDomainStatsRecordPtr record,
|
||||
bool raw ATTRIBUTE_UNUSED)
|
||||
{
|
||||
char *param;
|
||||
size_t i;
|
||||
@@ -2104,6 +2108,7 @@ cmdDomstats(vshControl *ctl, const vshCmd *cmd)
|
||||
int flags = 0;
|
||||
const vshCmdOpt *opt = NULL;
|
||||
bool ret = false;
|
||||
virshControlPtr priv = ctl->privData;
|
||||
|
||||
if (vshCommandOptBool(cmd, "state"))
|
||||
stats |= VIR_DOMAIN_STATS_STATE;
|
||||
@@ -2159,8 +2164,9 @@ cmdDomstats(vshControl *ctl, const vshCmd *cmd)
|
||||
ndoms = 1;
|
||||
|
||||
while ((opt = vshCommandOptArgv(ctl, cmd, opt))) {
|
||||
if (!(dom = vshLookupDomainBy(ctl, opt->data,
|
||||
VSH_BYID | VSH_BYUUID | VSH_BYNAME)))
|
||||
if (!(dom = virshLookupDomainBy(ctl, opt->data,
|
||||
VIRSH_BYID |
|
||||
VIRSH_BYUUID | VIRSH_BYNAME)))
|
||||
goto cleanup;
|
||||
|
||||
if (VIR_INSERT_ELEMENT(domlist, ndoms - 1, ndoms, dom) < 0)
|
||||
@@ -2173,7 +2179,7 @@ cmdDomstats(vshControl *ctl, const vshCmd *cmd)
|
||||
flags) < 0)
|
||||
goto cleanup;
|
||||
} else {
|
||||
if ((virConnectGetAllDomainStats(ctl->conn,
|
||||
if ((virConnectGetAllDomainStats(priv->conn,
|
||||
stats,
|
||||
&records,
|
||||
flags)) < 0)
|
||||
@@ -2181,7 +2187,7 @@ cmdDomstats(vshControl *ctl, const vshCmd *cmd)
|
||||
}
|
||||
|
||||
for (next = records; *next; next++) {
|
||||
if (!vshDomainStatsPrintRecord(ctl, *next, raw))
|
||||
if (!virshDomainStatsPrintRecord(ctl, *next, raw))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@@ -2234,7 +2240,7 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd)
|
||||
const char *sourcestr = NULL;
|
||||
int source = VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE;
|
||||
|
||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
||||
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||
return false;
|
||||
|
||||
if (vshCommandOptString(ctl, cmd, "interface", &ifacestr) < 0)
|
||||
|
||||
Reference in New Issue
Block a user