提交 67f83cd4 编写于 作者: P Peter Krempa

virsh: remove unneeded usage of vshConnectionUsability()

Now that vshCommandRun() checks for the connection automaticaly, remove
all of the redundant checks in the code.

vshConnectionUsability() no longer needs to be exported and this patch
marks it static.
上级 70e60891
......@@ -306,9 +306,6 @@ cmdDomMemStat(vshControl *ctl, const vshCmd *cmd)
struct _virDomainMemoryStat stats[VIR_DOMAIN_MEMORY_STAT_NR];
unsigned int nr_stats, i;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
return false;
......@@ -365,9 +362,6 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd)
bool ret = true;
const char *device = NULL;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return false;
......@@ -426,9 +420,6 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd)
details = vshCommandOptBool(cmd, "details");
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return false;
......@@ -530,9 +521,6 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptBool(cmd, "inactive"))
flags |= VIR_DOMAIN_XML_INACTIVE;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return false;
......@@ -632,9 +620,6 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd)
xmlNodePtr cur = NULL;
xmlXPathObjectPtr obj = NULL;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return false;
......@@ -747,9 +732,6 @@ cmdDomControl(vshControl *ctl, const vshCmd *cmd)
bool ret = true;
virDomainControlInfo info;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return false;
......@@ -843,9 +825,6 @@ cmdDomblkstat(vshControl *ctl, const vshCmd *cmd)
bool ret = false;
bool human = vshCommandOptBool(cmd, "human"); /* human readable output */
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
return false;
......@@ -968,9 +947,6 @@ cmdDomIfstat(vshControl *ctl, const vshCmd *cmd)
const char *name = NULL, *device = NULL;
struct _virDomainInterfaceStats stats;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
return false;
......@@ -1037,9 +1013,6 @@ cmdDomBlkError(vshControl *ctl, const vshCmd *cmd)
int count;
bool ret = false;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return false;
......@@ -1101,9 +1074,6 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd)
char *str, uuid[VIR_UUID_STRING_BUFLEN];
int has_managed_save = 0;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return false;
......@@ -1233,9 +1203,6 @@ cmdDomstate(vshControl *ctl, const vshCmd *cmd)
bool showReason = vshCommandOptBool(cmd, "reason");
int state, reason;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return false;
......@@ -1630,9 +1597,6 @@ cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
if (!optUUID && !optName)
optTable = true;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(list = vshDomainListCollect(ctl, flags)))
goto cleanup;
......
此差异已折叠。
......@@ -52,9 +52,6 @@ cmdCapabilities(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{
char *caps;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if ((caps = virConnectGetCapabilities(ctl->conn)) == NULL) {
vshError(ctl, "%s", _("failed to get capabilities"));
return false;
......@@ -149,10 +146,6 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
xmlDocPtr xml = NULL;
xmlXPathContextPtr ctxt = NULL;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if ( (cell_given = vshCommandOptInt(cmd, "cellno", &cell)) < 0) {
vshError(ctl, "%s", _("cell number has to be a number"));
goto cleanup;
......@@ -259,9 +252,6 @@ cmdNodeinfo(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{
virNodeInfo info;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (virNodeGetInfo(ctl->conn, &info) < 0) {
vshError(ctl, "%s", _("failed to get node information"));
return false;
......@@ -313,9 +303,6 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd)
double user_time, sys_time, idle_time, iowait_time, total_time;
double usage;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (vshCommandOptInt(cmd, "cpu", &cpuNum) < 0) {
vshError(ctl, "%s", _("Invalid value of cpuNum"));
return false;
......@@ -429,9 +416,6 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd)
virNodeMemoryStatsPtr params = NULL;
bool ret = false;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (vshCommandOptInt(cmd, "cell", &cellNum) < 0) {
vshError(ctl, "%s", _("Invalid value of cellNum"));
return false;
......@@ -493,9 +477,6 @@ cmdNodeSuspend(vshControl *ctl, const vshCmd *cmd)
long long duration;
unsigned int flags = 0;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (vshCommandOptString(cmd, "target", &target) < 0) {
vshError(ctl, _("Invalid target argument"));
return false;
......@@ -563,9 +544,6 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd)
virBuffer buf = VIR_BUFFER_INITIALIZER;
bool pad = false;
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
dom = vshCommandOptDomain(ctl, cmd, NULL);
if (dom == NULL)
goto cleanup;
......@@ -623,9 +601,6 @@ cmdQemuAttach(vshControl *ctl, const vshCmd *cmd)
unsigned int flags = 0;
unsigned int pid_value; /* API uses unsigned int, not pid_t */
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
if (vshCommandOptUInt(cmd, "pid", &pid_value) <= 0) {
vshError(ctl, "%s", _("missing pid value"));
goto cleanup;
......@@ -679,9 +654,6 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *cmd)
virBuffer buf = VIR_BUFFER_INITIALIZER;
bool pad = false;
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
dom = vshCommandOptDomain(ctl, cmd, NULL);
if (dom == NULL)
goto cleanup;
......@@ -752,9 +724,6 @@ cmdSysinfo(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{
char *sysinfo;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
sysinfo = virConnectGetSysinfo(ctl->conn, 0);
if (sysinfo == NULL) {
vshError(ctl, "%s", _("failed to get sysinfo"));
......@@ -781,9 +750,6 @@ cmdHostname(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{
char *hostname;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
hostname = virConnectGetHostname(ctl->conn);
if (hostname == NULL) {
vshError(ctl, "%s", _("failed to get hostname"));
......@@ -810,9 +776,6 @@ cmdURI(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{
char *uri;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
uri = virConnectGetURI(ctl->conn);
if (uri == NULL) {
vshError(ctl, "%s", _("failed to get URI"));
......@@ -853,9 +816,6 @@ cmdVersion(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
unsigned int minor;
unsigned int rel;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
hvType = virConnectGetType(ctl->conn);
if (hvType == NULL) {
vshError(ctl, "%s", _("failed to get hypervisor type"));
......
......@@ -101,9 +101,6 @@ cmdInterfaceEdit(vshControl *ctl, const vshCmd *cmd)
virInterfacePtr iface_edited = NULL;
unsigned int flags = VIR_INTERFACE_XML_INACTIVE;
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
iface = vshCommandOptInterface(ctl, cmd, NULL);
if (iface == NULL)
goto cleanup;
......@@ -158,9 +155,6 @@ cmdInterfaceList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
char **activeNames = NULL, **inactiveNames = NULL;
inactive |= all;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (active) {
maxactive = virConnectNumOfInterfaces(ctl->conn);
if (maxactive < 0) {
......@@ -265,8 +259,6 @@ cmdInterfaceName(vshControl *ctl, const vshCmd *cmd)
{
virInterfacePtr iface;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(iface = vshCommandOptInterfaceBy(ctl, cmd, NULL, NULL,
VSH_BYMAC)))
return false;
......@@ -295,8 +287,6 @@ cmdInterfaceMAC(vshControl *ctl, const vshCmd *cmd)
{
virInterfacePtr iface;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(iface = vshCommandOptInterfaceBy(ctl, cmd, NULL, NULL,
VSH_BYNAME)))
return false;
......@@ -333,9 +323,6 @@ cmdInterfaceDumpXML(vshControl *ctl, const vshCmd *cmd)
if (inactive)
flags |= VIR_INTERFACE_XML_INACTIVE;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(iface = vshCommandOptInterface(ctl, cmd, NULL)))
return false;
......@@ -373,9 +360,6 @@ cmdInterfaceDefine(vshControl *ctl, const vshCmd *cmd)
bool ret = true;
char *buffer;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (vshCommandOptString(cmd, "file", &from) <= 0)
return false;
......@@ -417,9 +401,6 @@ cmdInterfaceUndefine(vshControl *ctl, const vshCmd *cmd)
bool ret = true;
const char *name;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(iface = vshCommandOptInterface(ctl, cmd, &name)))
return false;
......@@ -455,9 +436,6 @@ cmdInterfaceStart(vshControl *ctl, const vshCmd *cmd)
bool ret = true;
const char *name;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(iface = vshCommandOptInterface(ctl, cmd, &name)))
return false;
......@@ -493,9 +471,6 @@ cmdInterfaceDestroy(vshControl *ctl, const vshCmd *cmd)
bool ret = true;
const char *name;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(iface = vshCommandOptInterface(ctl, cmd, &name)))
return false;
......@@ -528,9 +503,6 @@ static const vshCmdOptDef opts_interface_begin[] = {
static bool
cmdInterfaceBegin(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (virInterfaceChangeBegin(ctl->conn, 0) < 0) {
vshError(ctl, "%s", _("Failed to begin network config change transaction"));
return false;
......@@ -556,9 +528,6 @@ static const vshCmdOptDef opts_interface_commit[] = {
static bool
cmdInterfaceCommit(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (virInterfaceChangeCommit(ctl->conn, 0) < 0) {
vshError(ctl, "%s", _("Failed to commit network config change transaction"));
return false;
......@@ -584,9 +553,6 @@ static const vshCmdOptDef opts_interface_rollback[] = {
static bool
cmdInterfaceRollback(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (virInterfaceChangeRollback(ctl->conn, 0) < 0) {
vshError(ctl, "%s", _("Failed to rollback network config change transaction"));
return false;
......@@ -631,9 +597,6 @@ cmdInterfaceBridge(vshControl *ctl, const vshCmd *cmd)
xmlXPathContextPtr ctxt = NULL;
xmlNodePtr top_node, br_node, if_node, cur;
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
/* Get a handle to the original device */
if (!(if_handle = vshCommandOptInterfaceBy(ctl, cmd, "interface",
&if_name, VSH_BYNAME))) {
......@@ -848,9 +811,6 @@ cmdInterfaceUnbridge(vshControl *ctl, const vshCmd *cmd)
xmlXPathContextPtr ctxt = NULL;
xmlNodePtr top_node, br_node, if_node, cur;
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
/* Get a handle to the original device */
if (!(br_handle = vshCommandOptInterfaceBy(ctl, cmd, "bridge",
&br_name, VSH_BYNAME))) {
......
......@@ -100,9 +100,6 @@ cmdNetworkAutostart(vshControl *ctl, const vshCmd *cmd)
const char *name;
int autostart;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(network = vshCommandOptNetwork(ctl, cmd, &name)))
return false;
......@@ -148,9 +145,6 @@ cmdNetworkCreate(vshControl *ctl, const vshCmd *cmd)
bool ret = true;
char *buffer;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (vshCommandOptString(cmd, "file", &from) <= 0)
return false;
......@@ -193,9 +187,6 @@ cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd)
bool ret = true;
char *buffer;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (vshCommandOptString(cmd, "file", &from) <= 0)
return false;
......@@ -237,9 +228,6 @@ cmdNetworkDestroy(vshControl *ctl, const vshCmd *cmd)
bool ret = true;
const char *name;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(network = vshCommandOptNetwork(ctl, cmd, &name)))
return false;
......@@ -278,9 +266,6 @@ cmdNetworkDumpXML(vshControl *ctl, const vshCmd *cmd)
unsigned int flags = 0;
int inactive;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(network = vshCommandOptNetwork(ctl, cmd, NULL)))
return false;
......@@ -325,9 +310,6 @@ cmdNetworkInfo(vshControl *ctl, const vshCmd *cmd)
int active = -1;
char *bridge = NULL;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(network = vshCommandOptNetwork(ctl, cmd, NULL)))
return false;
......@@ -385,9 +367,6 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
char **activeNames = NULL, **inactiveNames = NULL;
inactive |= all;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (active) {
maxactive = virConnectNumOfNetworks(ctl->conn);
if (maxactive < 0) {
......@@ -505,8 +484,6 @@ cmdNetworkName(vshControl *ctl, const vshCmd *cmd)
{
virNetworkPtr network;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(network = vshCommandOptNetworkBy(ctl, cmd, NULL,
VSH_BYUUID)))
return false;
......@@ -537,9 +514,6 @@ cmdNetworkStart(vshControl *ctl, const vshCmd *cmd)
bool ret = true;
const char *name = NULL;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(network = vshCommandOptNetwork(ctl, cmd, &name)))
return false;
......@@ -574,9 +548,6 @@ cmdNetworkUndefine(vshControl *ctl, const vshCmd *cmd)
bool ret = true;
const char *name;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(network = vshCommandOptNetwork(ctl, cmd, &name)))
return false;
......@@ -611,9 +582,6 @@ cmdNetworkUuid(vshControl *ctl, const vshCmd *cmd)
virNetworkPtr network;
char uuid[VIR_UUID_STRING_BUFLEN];
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(network = vshCommandOptNetworkBy(ctl, cmd, NULL,
VSH_BYNAME)))
return false;
......@@ -664,9 +632,6 @@ cmdNetworkEdit(vshControl *ctl, const vshCmd *cmd)
virNetworkPtr network = NULL;
virNetworkPtr network_edited = NULL;
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
network = vshCommandOptNetwork(ctl, cmd, NULL);
if (network == NULL)
goto cleanup;
......
......@@ -63,9 +63,6 @@ cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd)
bool ret = true;
char *buffer;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (vshCommandOptString(cmd, "file", &from) <= 0)
return false;
......@@ -111,10 +108,6 @@ cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd)
bool ret = true;
const char *name = NULL;
if (!vshConnectionUsability(ctl, ctl->conn)) {
return false;
}
if (vshCommandOptString(cmd, "name", &name) <= 0)
return false;
......@@ -169,9 +162,6 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
bool tree = vshCommandOptBool(cmd, "tree");
bool ret = true;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (vshCommandOptString(cmd, "cap", &cap) <= 0)
cap = NULL;
......@@ -249,8 +239,6 @@ cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cmd)
virNodeDevicePtr device;
char *xml;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (vshCommandOptString(cmd, "device", &name) <= 0)
return false;
if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) {
......@@ -292,8 +280,6 @@ cmdNodeDeviceDetach(vshControl *ctl, const vshCmd *cmd)
virNodeDevicePtr device;
bool ret = true;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (vshCommandOptString(cmd, "device", &name) <= 0)
return false;
if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) {
......@@ -335,8 +321,6 @@ cmdNodeDeviceReAttach(vshControl *ctl, const vshCmd *cmd)
virNodeDevicePtr device;
bool ret = true;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (vshCommandOptString(cmd, "device", &name) <= 0)
return false;
if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) {
......@@ -376,8 +360,6 @@ cmdNodeDeviceReset(vshControl *ctl, const vshCmd *cmd)
virNodeDevicePtr device;
bool ret = true;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (vshCommandOptString(cmd, "device", &name) <= 0)
return false;
if (!(device = virNodeDeviceLookupByName(ctl->conn, name))) {
......
......@@ -99,9 +99,6 @@ cmdNWFilterDefine(vshControl *ctl, const vshCmd *cmd)
bool ret = true;
char *buffer;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (vshCommandOptString(cmd, "file", &from) <= 0)
return false;
......@@ -143,9 +140,6 @@ cmdNWFilterUndefine(vshControl *ctl, const vshCmd *cmd)
bool ret = true;
const char *name;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(nwfilter = vshCommandOptNWFilter(ctl, cmd, &name)))
return false;
......@@ -181,9 +175,6 @@ cmdNWFilterDumpXML(vshControl *ctl, const vshCmd *cmd)
bool ret = true;
char *dump;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(nwfilter = vshCommandOptNWFilter(ctl, cmd, NULL)))
return false;
......@@ -219,9 +210,6 @@ cmdNWFilterList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
char **names;
char uuid[VIR_UUID_STRING_BUFLEN];
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
numfilters = virConnectNumOfNWFilters(ctl->conn);
if (numfilters < 0) {
vshError(ctl, "%s", _("Failed to list network filters"));
......@@ -286,9 +274,6 @@ cmdNWFilterEdit(vshControl *ctl, const vshCmd *cmd)
virNWFilterPtr nwfilter = NULL;
virNWFilterPtr nwfilter_edited = NULL;
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
nwfilter = vshCommandOptNWFilter(ctl, cmd, NULL);
if (nwfilter == NULL)
goto cleanup;
......
......@@ -96,9 +96,6 @@ cmdPoolAutostart(vshControl *ctl, const vshCmd *cmd)
const char *name;
int autostart;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name)))
return false;
......@@ -145,9 +142,6 @@ cmdPoolCreate(vshControl *ctl, const vshCmd *cmd)
bool ret = true;
char *buffer;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (vshCommandOptString(cmd, "file", &from) <= 0)
return false;
......@@ -261,9 +255,6 @@ cmdPoolCreateAs(vshControl *ctl, const vshCmd *cmd)
char *xml;
bool printXML = vshCommandOptBool(cmd, "print-xml");
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!buildPoolXML(cmd, &name, &xml))
return false;
......@@ -307,9 +298,6 @@ cmdPoolDefine(vshControl *ctl, const vshCmd *cmd)
bool ret = true;
char *buffer;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (vshCommandOptString(cmd, "file", &from) <= 0)
return false;
......@@ -347,9 +335,6 @@ cmdPoolDefineAs(vshControl *ctl, const vshCmd *cmd)
char *xml;
bool printXML = vshCommandOptBool(cmd, "print-xml");
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!buildPoolXML(cmd, &name, &xml))
return false;
......@@ -395,9 +380,6 @@ cmdPoolBuild(vshControl *ctl, const vshCmd *cmd)
const char *name;
unsigned int flags = 0;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name)))
return false;
......@@ -443,9 +425,6 @@ cmdPoolDestroy(vshControl *ctl, const vshCmd *cmd)
bool ret = true;
const char *name;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name)))
return false;
......@@ -481,9 +460,6 @@ cmdPoolDelete(vshControl *ctl, const vshCmd *cmd)
bool ret = true;
const char *name;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name)))
return false;
......@@ -519,9 +495,6 @@ cmdPoolRefresh(vshControl *ctl, const vshCmd *cmd)
bool ret = true;
const char *name;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name)))
return false;
......@@ -563,9 +536,6 @@ cmdPoolDumpXML(vshControl *ctl, const vshCmd *cmd)
if (inactive)
flags |= VIR_STORAGE_XML_INACTIVE;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(pool = vshCommandOptPool(ctl, cmd, "pool", NULL)))
return false;
......@@ -626,10 +596,6 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
bool active = !inactive || all;
inactive |= all;
/* Check the connection to libvirtd daemon is still working */
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
/* Retrieve the number of active storage pools */
if (active) {
numActivePools = virConnectNumOfStoragePools(ctl->conn);
......@@ -1024,9 +990,6 @@ cmdPoolDiscoverSourcesAs(vshControl * ctl, const vshCmd * cmd ATTRIBUTE_UNUSED)
return false;
}
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (host) {
const char *port = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
......@@ -1097,9 +1060,6 @@ cmdPoolDiscoverSources(vshControl * ctl, const vshCmd * cmd ATTRIBUTE_UNUSED)
return false;
}
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (srcSpecFile && virFileReadAll(srcSpecFile, VSH_MAX_XML_FILE,
&srcSpec) < 0)
return false;
......@@ -1140,9 +1100,6 @@ cmdPoolInfo(vshControl *ctl, const vshCmd *cmd)
bool ret = true;
char uuid[VIR_UUID_STRING_BUFLEN];
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(pool = vshCommandOptPool(ctl, cmd, "pool", NULL)))
return false;
......@@ -1233,8 +1190,6 @@ cmdPoolName(vshControl *ctl, const vshCmd *cmd)
{
virStoragePoolPtr pool;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(pool = vshCommandOptPoolBy(ctl, cmd, "pool", NULL,
VSH_BYUUID)))
return false;
......@@ -1265,9 +1220,6 @@ cmdPoolStart(vshControl *ctl, const vshCmd *cmd)
bool ret = true;
const char *name = NULL;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name)))
return false;
......@@ -1303,9 +1255,6 @@ cmdPoolUndefine(vshControl *ctl, const vshCmd *cmd)
bool ret = true;
const char *name;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(pool = vshCommandOptPool(ctl, cmd, "pool", &name)))
return false;
......@@ -1340,9 +1289,6 @@ cmdPoolUuid(vshControl *ctl, const vshCmd *cmd)
virStoragePoolPtr pool;
char uuid[VIR_UUID_STRING_BUFLEN];
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(pool = vshCommandOptPoolBy(ctl, cmd, "pool", NULL,
VSH_BYNAME)))
return false;
......@@ -1379,9 +1325,6 @@ cmdPoolEdit(vshControl *ctl, const vshCmd *cmd)
unsigned int flags = VIR_STORAGE_XML_INACTIVE;
char *tmp_desc = NULL;
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
pool = vshCommandOptPool(ctl, cmd, "pool", NULL);
if (pool == NULL)
goto cleanup;
......
......@@ -87,9 +87,6 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd)
virSecretPtr res;
char uuid[VIR_UUID_STRING_BUFLEN];
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (vshCommandOptString(cmd, "file", &from) <= 0)
return false;
......@@ -134,9 +131,6 @@ cmdSecretDumpXML(vshControl *ctl, const vshCmd *cmd)
bool ret = false;
char *xml;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
secret = vshCommandOptSecret(ctl, cmd, NULL);
if (secret == NULL)
return false;
......@@ -178,9 +172,6 @@ cmdSecretSetValue(vshControl *ctl, const vshCmd *cmd)
int res;
bool ret = false;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
secret = vshCommandOptSecret(ctl, cmd, NULL);
if (secret == NULL)
return false;
......@@ -236,9 +227,6 @@ cmdSecretGetValue(vshControl *ctl, const vshCmd *cmd)
size_t value_size;
bool ret = false;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
secret = vshCommandOptSecret(ctl, cmd, NULL);
if (secret == NULL)
return false;
......@@ -286,9 +274,6 @@ cmdSecretUndefine(vshControl *ctl, const vshCmd *cmd)
bool ret = false;
const char *uuid;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
secret = vshCommandOptSecret(ctl, cmd, &uuid);
if (secret == NULL)
return false;
......@@ -320,9 +305,6 @@ cmdSecretList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
int maxuuids = 0, i;
char **uuids = NULL;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
maxuuids = virConnectNumOfSecrets(ctl->conn);
if (maxuuids < 0) {
vshError(ctl, "%s", _("Failed to list secrets"));
......
......@@ -156,9 +156,6 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptBool(cmd, "atomic"))
flags |= VIR_DOMAIN_SNAPSHOT_CREATE_ATOMIC;
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
dom = vshCommandOptDomain(ctl, cmd, NULL);
if (dom == NULL)
goto cleanup;
......@@ -296,9 +293,6 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptBool(cmd, "atomic"))
flags |= VIR_DOMAIN_SNAPSHOT_CREATE_ATOMIC;
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
dom = vshCommandOptDomain(ctl, cmd, NULL);
if (dom == NULL)
goto cleanup;
......@@ -429,9 +423,6 @@ cmdSnapshotEdit(vshControl *ctl, const vshCmd *cmd)
vshCommandOptBool(cmd, "snapshotname"))
define_flags |= VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
dom = vshCommandOptDomain(ctl, cmd, NULL);
if (dom == NULL)
goto cleanup;
......@@ -532,9 +523,6 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptBool(cmd, "security-info"))
flags |= VIR_DOMAIN_XML_SECURE;
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
dom = vshCommandOptDomain(ctl, cmd, &domname);
if (dom == NULL)
goto cleanup;
......@@ -701,9 +689,6 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd)
int current;
int metadata;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
dom = vshCommandOptDomain(ctl, cmd, NULL);
if (dom == NULL)
return false;
......@@ -1183,9 +1168,6 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
virDomainSnapshotPtr start = NULL;
vshSnapshotListPtr snaplist = NULL;
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
dom = vshCommandOptDomain(ctl, cmd, NULL);
if (dom == NULL)
goto cleanup;
......@@ -1381,9 +1363,6 @@ cmdSnapshotDumpXML(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptBool(cmd, "security-info"))
flags |= VIR_DOMAIN_XML_SECURE;
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
dom = vshCommandOptDomain(ctl, cmd, NULL);
if (dom == NULL)
goto cleanup;
......@@ -1438,9 +1417,6 @@ cmdSnapshotParent(vshControl *ctl, const vshCmd *cmd)
virDomainSnapshotPtr snapshot = NULL;
char *parent = NULL;
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
dom = vshCommandOptDomain(ctl, cmd, NULL);
if (dom == NULL)
goto cleanup;
......@@ -1511,9 +1487,6 @@ cmdDomainSnapshotRevert(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptBool(cmd, "force"))
force = true;
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
dom = vshCommandOptDomain(ctl, cmd, NULL);
if (dom == NULL)
goto cleanup;
......@@ -1572,9 +1545,6 @@ cmdSnapshotDelete(vshControl *ctl, const vshCmd *cmd)
virDomainSnapshotPtr snapshot = NULL;
unsigned int flags = 0;
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
dom = vshCommandOptDomain(ctl, cmd, NULL);
if (dom == NULL)
goto cleanup;
......
......@@ -147,9 +147,6 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
unsigned long long capacity, allocation = 0;
virBuffer buf = VIR_BUFFER_INITIALIZER;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(pool = vshCommandOptPoolBy(ctl, cmd, "pool", NULL,
VSH_BYNAME)))
return false;
......@@ -302,9 +299,6 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd)
bool ret = true;
char *buffer;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(pool = vshCommandOptPoolBy(ctl, cmd, "pool", NULL,
VSH_BYNAME)))
return false;
......@@ -361,9 +355,6 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd)
bool ret = false;
char *buffer = NULL;
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
if (!(pool = vshCommandOptPool(ctl, cmd, "pool", NULL)))
goto cleanup;
......@@ -456,9 +447,6 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd)
xmlChar *newxml = NULL;
bool ret = false;
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
if (!(origvol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL)))
goto cleanup;
......@@ -544,9 +532,6 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd)
const char *name = NULL;
unsigned long long offset = 0, length = 0;
if (!vshConnectionUsability(ctl, ctl->conn))
goto cleanup;
if (vshCommandOptULongLong(cmd, "offset", &offset) < 0) {
vshError(ctl, _("Unable to parse integer"));
return false;
......@@ -634,9 +619,6 @@ cmdVolDownload(vshControl *ctl, const vshCmd *cmd)
unsigned long long offset = 0, length = 0;
bool created = false;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (vshCommandOptULongLong(cmd, "offset", &offset) < 0) {
vshError(ctl, _("Unable to parse integer"));
return false;
......@@ -722,9 +704,6 @@ cmdVolDelete(vshControl *ctl, const vshCmd *cmd)
bool ret = true;
const char *name;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", &name))) {
return false;
}
......@@ -771,9 +750,6 @@ cmdVolWipe(vshControl *ctl, const vshCmd *cmd)
int algorithm = VIR_STORAGE_VOL_WIPE_ALG_ZERO;
int funcRet;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", &name))) {
return false;
}
......@@ -829,9 +805,6 @@ cmdVolInfo(vshControl *ctl, const vshCmd *cmd)
virStorageVolPtr vol;
bool ret = true;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL)))
return false;
......@@ -915,9 +888,6 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptBool(cmd, "shrink"))
flags |= VIR_STORAGE_VOL_RESIZE_SHRINK;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL)))
return false;
......@@ -981,9 +951,6 @@ cmdVolDumpXML(vshControl *ctl, const vshCmd *cmd)
bool ret = true;
char *dump;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL)))
return false;
......@@ -1039,10 +1006,6 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
};
struct volInfoText *volInfoTexts = NULL;
/* Check the connection to libvirtd daemon is still working */
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
/* Look up the pool information given to us by the user */
if (!(pool = vshCommandOptPool(ctl, cmd, "pool", NULL)))
return false;
......@@ -1315,9 +1278,6 @@ cmdVolName(vshControl *ctl, const vshCmd *cmd)
{
virStorageVolPtr vol;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(vol = vshCommandOptVolBy(ctl, cmd, "vol", NULL, NULL,
VSH_BYUUID)))
return false;
......@@ -1349,10 +1309,6 @@ cmdVolPool(vshControl *ctl, const vshCmd *cmd)
virStorageVolPtr vol;
char uuid[VIR_UUID_STRING_BUFLEN];
/* Check the connection to libvirtd daemon is still working */
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
/* Use the supplied string to locate the volume */
if (!(vol = vshCommandOptVolBy(ctl, cmd, "vol", NULL, NULL,
VSH_BYUUID))) {
......@@ -1403,9 +1359,6 @@ cmdVolKey(vshControl *ctl, const vshCmd *cmd)
{
virStorageVolPtr vol;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL)))
return false;
......@@ -1435,9 +1388,6 @@ cmdVolPath(vshControl *ctl, const vshCmd *cmd)
virStorageVolPtr vol;
char * StorageVolPath;
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
if (!(vol = vshCommandOptVol(ctl, cmd, "vol", "pool", NULL))) {
return false;
}
......
......@@ -1465,6 +1465,23 @@ vshCmdHasOption(vshControl *ctl, const vshCmd *cmd, const char *optname)
return found;
}
static bool
vshConnectionUsability(vshControl *ctl, virConnectPtr conn)
{
if (!conn ||
virConnectIsAlive(conn) == 0) {
vshError(ctl, "%s", _("no valid connection"));
return false;
}
/* The connection is considered dead only if
* virConnectIsAlive() successfuly says so.
*/
vshResetLibvirtError();
return true;
}
/*
* Executes command(s) and returns return code from last command
*/
......@@ -1951,23 +1968,6 @@ vshFindTypedParamByName(const char *name, virTypedParameterPtr list, int count)
return NULL;
}
bool
vshConnectionUsability(vshControl *ctl, virConnectPtr conn)
{
if (!conn ||
virConnectIsAlive(conn) == 0) {
vshError(ctl, "%s", _("no valid connection"));
return false;
}
/* The connection is considered dead only if
* virConnectIsAlive() successfuly says so.
*/
vshResetLibvirtError();
return true;
}
void
vshDebug(vshControl *ctl, int level, const char *format, ...)
{
......
......@@ -315,7 +315,6 @@ void vshDebug(vshControl *ctl, int level, const char *format, ...)
int vshNameSorter(const void *a, const void *b);
int vshDomainState(vshControl *ctl, virDomainPtr dom, int *reason);
bool vshConnectionUsability(vshControl *ctl, virConnectPtr conn);
virTypedParameterPtr vshFindTypedParamByName(const char *name,
virTypedParameterPtr list,
int count);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册