[libvirt] [PATCH] Fix __sun conditional
by john.levon@sun.com
# HG changeset patch
# User john.levon(a)sun.com
# Date 1229369745 28800
# Node ID 9e1a44b5c166b73e36d3cffc5398af0bec39ddc7
# Parent 2bee618a0557131c383b124b2b88bd407b462df4
Fix __sun conditional
It's __sun not __sun__.
Signed-off-by: John Levon <john.levon(a)sun.com>
diff --git a/src/xen_internal.c b/src/xen_internal.c
--- a/src/xen_internal.c
+++ b/src/xen_internal.c
@@ -76,7 +76,7 @@ typedef struct v1_hypercall_struct
#define XEN_V1_IOCTL_HYPERCALL_CMD \
_IOC(_IOC_NONE, 'P', 0, sizeof(v1_hypercall_t))
typedef v1_hypercall_t hypercall_t;
-#elif defined(__sun__)
+#elif defined(__sun)
typedef privcmd_hypercall_t hypercall_t;
#else
#error "unsupported platform"
@@ -663,7 +663,7 @@ typedef struct xen_op_v2_dom xen_op_v2_d
#define XEN_HYPERVISOR_SOCKET "/proc/xen/privcmd"
#define HYPERVISOR_CAPABILITIES "/sys/hypervisor/properties/capabilities"
#define CPUINFO "/proc/cpuinfo"
-#elif defined(__sun__)
+#elif defined(__sun)
#define XEN_HYPERVISOR_SOCKET "/dev/xen/privcmd"
#define HYPERVISOR_CAPABILITIES ""
#define CPUINFO "/dev/cpu/self/cpuid"
@@ -1906,7 +1906,7 @@ xenHypervisorInit(void)
goto detect_v2;
}
-#ifndef __sun__
+#ifndef __sun
/*
* check if the old hypercall are actually working
*/
diff --git a/src/xen_unified.c b/src/xen_unified.c
--- a/src/xen_unified.c
+++ b/src/xen_unified.c
@@ -213,7 +213,7 @@ xenUnifiedProbe (void)
if (virFileExists("/proc/xen"))
return 1;
#endif
-#ifdef __sun__
+#ifdef __sun
FILE *fh;
if (fh = fopen("/dev/xen/domcaps", "r")) {
diff --git a/src/xs_internal.c b/src/xs_internal.c
--- a/src/xs_internal.c
+++ b/src/xs_internal.c
@@ -39,7 +39,7 @@
#ifdef __linux__
#define XEN_HYPERVISOR_SOCKET "/proc/xen/privcmd"
-#elif defined(__sun__)
+#elif defined(__sun)
#define XEN_HYPERVISOR_SOCKET "/dev/xen/privcmd"
#else
#error "unsupported platform"
15 years, 10 months
[libvirt] [PATCH] Fix statement not reached compiler error
by john.levon@sun.com
# HG changeset patch
# User john.levon(a)sun.com
# Date 1229369745 28800
# Node ID 2bee618a0557131c383b124b2b88bd407b462df4
# Parent 16ceb6f2e00c4639e97440723e57ec0be6d12cd9
Fix statement not reached compiler error
Signed-off-by: John Levon <john.levon(a)sun.com>
diff --git a/src/remote_internal.c b/src/remote_internal.c
--- a/src/remote_internal.c
+++ b/src/remote_internal.c
@@ -5091,25 +5091,23 @@ really_read_buf (virConnectPtr conn, str
return -1;
}
return err;
- } else {
- reread:
- err = recv (priv->sock, bytes, len, 0);
- if (err == -1) {
- if (errno == EINTR)
- goto reread;
- error (in_open ? NULL : conn,
- VIR_ERR_SYSTEM_ERROR, strerror (errno));
- return -1;
- }
- if (err == 0) {
- error (in_open ? NULL : conn,
- VIR_ERR_RPC, _("socket closed unexpectedly"));
- return -1;
- }
- return err;
- }
-
- return 0;
+ }
+
+reread:
+ err = recv (priv->sock, bytes, len, 0);
+ if (err == -1) {
+ if (errno == EINTR)
+ goto reread;
+ error (in_open ? NULL : conn,
+ VIR_ERR_SYSTEM_ERROR, strerror (errno));
+ return -1;
+ }
+ if (err == 0) {
+ error (in_open ? NULL : conn,
+ VIR_ERR_RPC, _("socket closed unexpectedly"));
+ return -1;
+ }
+ return err;
}
static int
15 years, 10 months
[libvirt] [PATCH] Fix initialization mismatch
by john.levon@sun.com
# HG changeset patch
# User john.levon(a)sun.com
# Date 1229369743 28800
# Node ID 16ceb6f2e00c4639e97440723e57ec0be6d12cd9
# Parent ead0d1c1d3adacf478db05ee8d6abe270c96c5da
Fix initialization mismatch
Make driver open routines correctly declare their return type.
Signed-off-by: John Levon <john.levon(a)sun.com>
diff --git a/src/proxy_internal.c b/src/proxy_internal.c
--- a/src/proxy_internal.c
+++ b/src/proxy_internal.c
@@ -36,7 +36,7 @@ static int debug = 0;
static int debug = 0;
static int xenProxyClose(virConnectPtr conn);
-static int xenProxyOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags);
+static virDrvOpenStatus xenProxyOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags);
static int xenProxyGetVersion(virConnectPtr conn, unsigned long *hvVer);
static int xenProxyNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info);
static char *xenProxyGetCapabilities(virConnectPtr conn);
@@ -477,7 +477,7 @@ retry:
*
* Returns 0 in case of success, and -1 in case of failure
*/
-int
+virDrvOpenStatus
xenProxyOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
int flags)
diff --git a/src/remote_internal.c b/src/remote_internal.c
--- a/src/remote_internal.c
+++ b/src/remote_internal.c
@@ -851,7 +851,7 @@ doRemoteOpen (virConnectPtr conn,
goto cleanup;
}
-static int
+static virDrvOpenStatus
remoteOpen (virConnectPtr conn,
virConnectAuthPtr auth,
int flags)
@@ -2633,7 +2633,7 @@ remoteDomainMemoryPeek (virDomainPtr dom
/*----------------------------------------------------------------------*/
-static int
+static virDrvOpenStatus
remoteNetworkOpen (virConnectPtr conn,
virConnectAuthPtr auth,
int flags)
@@ -3033,7 +3033,7 @@ remoteNetworkSetAutostart (virNetworkPtr
/*----------------------------------------------------------------------*/
-static int
+static virDrvOpenStatus
remoteStorageOpen (virConnectPtr conn,
virConnectAuthPtr auth,
int flags)
diff --git a/src/test.c b/src/test.c
--- a/src/test.c
+++ b/src/test.c
@@ -634,7 +634,7 @@ static int testOpenFromFile(virConnectPt
}
-static int testOpen(virConnectPtr conn,
+static virDrvOpenStatus testOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
int flags ATTRIBUTE_UNUSED)
{
diff --git a/src/xen_inotify.c b/src/xen_inotify.c
--- a/src/xen_inotify.c
+++ b/src/xen_inotify.c
@@ -347,7 +347,7 @@ reread:
*
* Returns 0 or -1 in case of error.
*/
-int
+virDrvOpenStatus
xenInotifyOpen(virConnectPtr conn ATTRIBUTE_UNUSED,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
int flags ATTRIBUTE_UNUSED)
diff --git a/src/xen_inotify.h b/src/xen_inotify.h
--- a/src/xen_inotify.h
+++ b/src/xen_inotify.h
@@ -21,10 +21,13 @@
*/
#ifndef __VIR_XEN_INOTIFY_H__
#define __VIR_XEN_INOTIFY_H__
+
#include "internal.h"
+#include "driver.h"
+
extern struct xenUnifiedDriver xenInotifyDriver;
-int xenInotifyOpen (virConnectPtr conn,
+virDrvOpenStatus xenInotifyOpen (virConnectPtr conn,
virConnectAuthPtr auth,
int flags);
int xenInotifyClose (virConnectPtr conn);
diff --git a/src/xen_internal.c b/src/xen_internal.c
--- a/src/xen_internal.c
+++ b/src/xen_internal.c
@@ -2031,7 +2031,7 @@ xenHypervisorInit(void)
*
* Returns 0 or -1 in case of error.
*/
-int
+virDrvOpenStatus
xenHypervisorOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
int flags ATTRIBUTE_UNUSED)
diff --git a/src/xen_internal.h b/src/xen_internal.h
--- a/src/xen_internal.h
+++ b/src/xen_internal.h
@@ -15,6 +15,7 @@
#include "internal.h"
#include "capabilities.h"
+#include "driver.h"
extern struct xenUnifiedDriver xenHypervisorDriver;
int xenHypervisorInit (void);
@@ -32,7 +33,8 @@ char *
char *
xenHypervisorDomainGetOSType (virDomainPtr dom);
-int xenHypervisorOpen (virConnectPtr conn,
+virDrvOpenStatus
+ xenHypervisorOpen (virConnectPtr conn,
virConnectAuthPtr auth,
int flags);
int xenHypervisorClose (virConnectPtr conn);
diff --git a/src/xen_unified.c b/src/xen_unified.c
--- a/src/xen_unified.c
+++ b/src/xen_unified.c
@@ -224,7 +224,7 @@ xenUnifiedProbe (void)
return 0;
}
-static int
+static virDrvOpenStatus
xenUnifiedOpen (virConnectPtr conn, virConnectAuthPtr auth, int flags)
{
int i, ret = VIR_DRV_OPEN_DECLINED;
diff --git a/src/xend_internal.c b/src/xend_internal.c
--- a/src/xend_internal.c
+++ b/src/xend_internal.c
@@ -2704,7 +2704,7 @@ error:
*
* Returns 0 in case of success, -1 in case of error.
*/
-int
+virDrvOpenStatus
xenDaemonOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
int flags ATTRIBUTE_UNUSED)
diff --git a/src/xend_internal.h b/src/xend_internal.h
--- a/src/xend_internal.h
+++ b/src/xend_internal.h
@@ -24,6 +24,7 @@
#include "internal.h"
#include "capabilities.h"
#include "domain_conf.h"
+#include "driver.h"
#include "buf.h"
int
@@ -129,7 +130,7 @@ xenDaemonFormatSxpr(virConnectPtr conn,
/* refactored ones */
-int xenDaemonOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags);
+virDrvOpenStatus xenDaemonOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags);
int xenDaemonClose(virConnectPtr conn);
int xenDaemonGetVersion(virConnectPtr conn, unsigned long *hvVer);
int xenDaemonNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info);
diff --git a/src/xm_internal.c b/src/xm_internal.c
--- a/src/xm_internal.c
+++ b/src/xm_internal.c
@@ -581,7 +581,7 @@ int xenXMConfigCacheRefresh (virConnectP
* We only support a single directory, so repeated calls
* to open all end up using the same cache of files
*/
-int
+virDrvOpenStatus
xenXMOpen (virConnectPtr conn ATTRIBUTE_UNUSED,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
int flags ATTRIBUTE_UNUSED)
diff --git a/src/xm_internal.h b/src/xm_internal.h
--- a/src/xm_internal.h
+++ b/src/xm_internal.h
@@ -26,6 +26,7 @@
#define _LIBVIRT_XM_INTERNAL_H_
#include "internal.h"
+#include "driver.h"
#include "conf.h"
#include "domain_conf.h"
@@ -38,7 +39,7 @@ int xenXMConfigCacheAddFile(virConnectPt
int xenXMConfigCacheAddFile(virConnectPtr conn, const char *filename);
int xenXMConfigCacheRemoveFile(virConnectPtr conn, const char *filename);
-int xenXMOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags);
+virDrvOpenStatus xenXMOpen(virConnectPtr conn, virConnectAuthPtr auth, int flags);
int xenXMClose(virConnectPtr conn);
const char *xenXMGetType(virConnectPtr conn);
int xenXMDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info);
diff --git a/src/xs_internal.c b/src/xs_internal.c
--- a/src/xs_internal.c
+++ b/src/xs_internal.c
@@ -281,7 +281,7 @@ virDomainGetVMInfo(virDomainPtr domain,
*
* Returns 0 or -1 in case of error.
*/
-int
+virDrvOpenStatus
xenStoreOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
int flags ATTRIBUTE_UNUSED)
diff --git a/src/xs_internal.h b/src/xs_internal.h
--- a/src/xs_internal.h
+++ b/src/xs_internal.h
@@ -12,11 +12,12 @@
#define __VIR_XS_INTERNAL_H__
#include "internal.h"
+#include "driver.h"
extern struct xenUnifiedDriver xenStoreDriver;
int xenStoreInit (void);
-int xenStoreOpen (virConnectPtr conn,
+virDrvOpenStatus xenStoreOpen (virConnectPtr conn,
virConnectAuthPtr auth,
int flags);
int xenStoreClose (virConnectPtr conn);
15 years, 10 months
[libvirt] [PATCH] Cast callbacks to the correct type
by john.levon@sun.com
# HG changeset patch
# User john.levon(a)sun.com
# Date 1229367890 28800
# Node ID 728f90c86f2cd950463923c80fc57754d6e762eb
# Parent 6a8e82d7d2e166880fed8d7ad860a3e2e93d62be
Cast callbacks to the correct type
Avoid compiler warnings by performing the correct casts.
Signed-off-by: John Levon <john.levon(a)sun.com>
diff --git a/src/libvirt.c b/src/libvirt.c
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -5806,7 +5806,8 @@ virConnectDomainEventRegister(virConnect
}
if ((conn->driver) && (conn->driver->domainEventRegister))
- return conn->driver->domainEventRegister (conn, cb, opaque, freecb);
+ return conn->driver->domainEventRegister (conn, (void *)cb,
+ opaque, freecb);
return -1;
}
@@ -5835,9 +5836,9 @@ virConnectDomainEventDeregister(virConne
return (-1);
}
if ((conn->driver) && (conn->driver->domainEventDeregister))
- return conn->driver->domainEventDeregister (conn, cb);
-
- return -1;
-}
-
-
+ return conn->driver->domainEventDeregister (conn, (void *)cb);
+
+ return -1;
+}
+
+
diff --git a/src/remote_internal.c b/src/remote_internal.c
--- a/src/remote_internal.c
+++ b/src/remote_internal.c
@@ -4735,7 +4735,7 @@ static int remoteDomainEventRegister (vi
return -1;
}
if (virDomainEventCallbackListAdd(conn, priv->callbackList,
- callback, opaque, freecb) < 0) {
+ (virConnectDomainEventCallback)callback, opaque, freecb) < 0) {
error (conn, VIR_ERR_RPC, _("adding cb to list"));
return -1;
}
@@ -4757,7 +4757,7 @@ static int remoteDomainEventDeregister (
struct private_data *priv = conn->privateData;
if (virDomainEventCallbackListRemove(conn, priv->callbackList,
- callback) < 0) {
+ (virConnectDomainEventCallback)callback) < 0) {
error (conn, VIR_ERR_RPC, _("removing cb fron list"));
return -1;
}
diff --git a/src/xen_unified.c b/src/xen_unified.c
--- a/src/xen_unified.c
+++ b/src/xen_unified.c
@@ -1372,7 +1372,7 @@ xenUnifiedDomainEventRegister (virConnec
conn->refs++;
return virDomainEventCallbackListAdd(conn, priv->domainEventCallbacks,
- callback, opaque, freefunc);
+ (virConnectDomainEventCallback)callback, opaque, freefunc);
}
static int
@@ -1387,7 +1387,7 @@ xenUnifiedDomainEventDeregister (virConn
}
ret = virDomainEventCallbackListRemove(conn, priv->domainEventCallbacks,
- callback);
+ (virConnectDomainEventCallback)callback);
virUnrefConnect(conn);
return ret;
}
15 years, 10 months
[libvirt] [PATCH] Remove _PATH_DEVNULL usage
by john.levon@sun.com
# HG changeset patch
# User john.levon(a)sun.com
# Date 1229367890 28800
# Node ID c324c231c6a50be9f970f0f6c6d1629a7c09ab3b
# Parent 63174fd9f33749cb68431fd5d1ff6133ba48863b
Remove _PATH_DEVNULL usage
_PATH_DEVNULL provides no apparent advantage, and isn't available on
Solaris: replace with the string literal.
Signed-off-by: John Levon <john.levon(a)sun.com>
diff --git a/qemud/qemud.c b/qemud/qemud.c
--- a/qemud/qemud.c
+++ b/qemud/qemud.c
@@ -397,9 +397,9 @@ static int qemudGoDaemon(void) {
int stdoutfd = -1;
int nextpid;
- if ((stdinfd = open(_PATH_DEVNULL, O_RDONLY)) < 0)
+ if ((stdinfd = open("/dev/null", O_RDONLY)) < 0)
goto cleanup;
- if ((stdoutfd = open(_PATH_DEVNULL, O_WRONLY)) < 0)
+ if ((stdoutfd = open("/dev/null", O_WRONLY)) < 0)
goto cleanup;
if (dup2(stdinfd, STDIN_FILENO) != STDIN_FILENO)
goto cleanup;
diff --git a/src/util.c b/src/util.c
--- a/src/util.c
+++ b/src/util.c
@@ -205,10 +205,10 @@ __virExec(virConnectPtr conn,
return -1;
}
- if ((null = open(_PATH_DEVNULL, O_RDONLY)) < 0) {
+ if ((null = open("/dev/null", O_RDONLY)) < 0) {
ReportError(conn, VIR_ERR_INTERNAL_ERROR,
_("cannot open %s: %s"),
- _PATH_DEVNULL, strerror(errno));
+ "/dev/null", strerror(errno));
goto cleanup;
}
diff --git a/tests/testutils.c b/tests/testutils.c
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -35,10 +35,6 @@
#ifdef HAVE_PATHS_H
#include <paths.h>
-#endif
-
-#ifndef _PATH_DEVNULL
-#define _PATH_DEVNULL "/dev/null"
#endif
#define GETTIMEOFDAY(T) gettimeofday(T, NULL)
@@ -157,9 +153,9 @@ void virtTestCaptureProgramExecChild(con
NULL
};
- if ((stdinfd = open(_PATH_DEVNULL, O_RDONLY)) < 0)
- goto cleanup;
- if ((stderrfd = open(_PATH_DEVNULL, O_WRONLY)) < 0)
+ if ((stdinfd = open("/dev/null", O_RDONLY)) < 0)
+ goto cleanup;
+ if ((stderrfd = open("/dev/null", O_WRONLY)) < 0)
goto cleanup;
open_max = sysconf (_SC_OPEN_MAX);
15 years, 10 months
[libvirt] [PATCH] Remove non-existent symbols from the version script
by john.levon@sun.com
# HG changeset patch
# User john.levon(a)sun.com
# Date 1229369745 28800
# Node ID d3e5c2e138bd794ab711cc2548c45112ba603ea2
# Parent 56d77e29bf90057791feebfa47506fc0933cd690
Remove non-existent symbols from the version script
The Solaris linker rightfully complains if a non-existent symbol is
referenced. Since these symbols don't exist in the current source, they
can have no purpose in a version script, so remove them.
Signed-off-by: John Levon <john.levon(a)sun.com>
diff --git a/src/libvirt_sym.version.in b/src/libvirt_sym.version.in
--- a/src/libvirt_sym.version.in
+++ b/src/libvirt_sym.version.in
@@ -62,7 +62,6 @@ LIBVIRT_0.1.0 {
virCopyLastError;
virConnSetErrorFunc;
virResetLastError;
- virErrorFunc;
virResetError;
virConnGetLastError;
virGetLastError;
@@ -199,8 +198,6 @@ LIBVIRT_0.4.1 {
virStoragePoolNumOfVolumes;
virStoragePoolListVolumes;
- virConnectNumOfStorageVolumes;
- virConnectListStorageVolumes;
virStorageVolGetConnect;
virStorageVolLookupByName;
virStorageVolLookupByKey;
@@ -235,13 +232,9 @@ LIBVIRT_0.5.0 {
virNodeNumOfDevices;
virNodeListDevices;
- virNodeNumOfDevicesByCap;
- virNodeListDevicesByCap;
virNodeDeviceLookupByName;
virNodeDeviceFree;
virNodeDeviceGetXMLDesc;
- virNodeDeviceCreate;
- virNodeDeviceDestroy;
virNodeDeviceGetName;
virNodeDeviceGetParent;
virNodeDeviceNumOfCaps;
@@ -441,7 +434,6 @@ LIBVIRT_PRIVATE_@VERSION@ {
virStateCleanup;
virStateReload;
virStateActive;
- virStateSigDispatcher;
virDrvSupportsFeature;
virDomainMigratePrepare;
virDomainMigratePerform;
@@ -506,10 +498,6 @@ LIBVIRT_PRIVATE_@VERSION@ {
# storage_backend.h
virStorageBackendForType;
- virStorageBackendFromString;
- virStorageBackendPartTableTypeFromString;
- virStorageBackendPartTableTypeToString;
- virStorageBackendRegister;
virStorageBackendRunProgNul;
virStorageBackendRunProgRegex;
virStorageBackendStablePath;
@@ -518,7 +506,6 @@ LIBVIRT_PRIVATE_@VERSION@ {
# storage_conf.h
- virStorageBackendPoolOptionsForType;
virStoragePoolDefFormat;
virStoragePoolDefFree;
virStoragePoolDefParse;
15 years, 10 months
[libvirt] virsh save produces "unknown migration protocol: stdio"
by Richard W.M. Jones
I just want to forward this comment on from #virt so that we don't
lose it. It appears to be an incompatibility between libvirt 0.5.0
and recent KVM.
<knowinters> Hi, I'm using libvirt 0.5.0 with kvm-79, when I do virsh
save kvm replies with "unknown migration protocol: stdio". A state
file is created, but it's only 4K and when restored the vm boots from
scratch instead of starting where it was when i saved. I googled but
couldn't find a resolution. Is this a known issue?
<knowinters> nm i think i see what's happening.. it
<knowinters> 's using the exec: migration method to call dd to move
the state from stdio to a file
<knowinters> exec: isn't in kvm-79 i don't think, but i see it in git
so ill try that
Rich.
--
Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones
Read my OCaml programming blog: http://camltastic.blogspot.com/
Fedora now supports 68 OCaml packages (the OPEN alternative to F#)
http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora
15 years, 10 months
[libvirt] PATCH: Fix deadlock upon config file reload
by Daniel P. Berrange
Turned out there was a small locking bug when reloading domain config
files after SIGHUP. I committed the following patch to add in the missing
unlock call. This was one of the files I'm unable to do static analysis
on, hence why it was missed.
Daniel
Index: domain_conf.c
===================================================================
RCS file: /data/cvs/libvirt/src/domain_conf.c,v
retrieving revision 1.45
diff -u -p -r1.45 domain_conf.c
--- domain_conf.c 11 Dec 2008 11:44:30 -0000 1.45
+++ domain_conf.c 15 Dec 2008 10:51:11 -0000
@@ -3330,8 +3330,11 @@ virDomainObjPtr virDomainLoadConfig(virC
VIR_DOMAIN_XML_INACTIVE)))
goto error;
- if (virDomainFindByName(doms, def->name))
+ if ((dom = virDomainFindByName(doms, def->name))) {
+ virDomainObjUnlock(dom);
+ dom = NULL;
newVM = 0;
+ }
if (!(dom = virDomainAssignDef(conn, doms, def)))
goto error;
--
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
15 years, 10 months
[libvirt] [PATCH] remove redundant optname arguments
by Jim Meyering
>From a5c76721c22cf51b47059a91317f87a9f47c6868 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Tue, 9 Dec 2008 22:22:08 +0100
Subject: [PATCH] remove redundant optname arguments
This is the second part of the change mentioned here:
http://thread.gmane.org/gmane.comp.emulators.libvirt/10331
It removes the essentially redundant "optname" parameter
from each of the vshCommandOptNetworkBy and vshCommandOptDomainBy
functions as well as the correspond macros (without "By" suffix).
Now, instead of always passing the optname, "domain", to
vshCommandOptDomainBy, that function requires that its command
argument refer to an opts array containing a "domain" option.
This normalization makes one more help-related change:
it renames the net-start "name" argument to the more
sensible and consistent "network".
* src/virsh.c (VSH_BYNAME, vshCommandOptDomain)
(cmd_has_option): New function, used in vshCommandOptDomainBy
and vshCommandOptNetworkBy.
(vshCommandOptDomainBy, vshCommandOptNetworkBy): Remove the optname
parameter, it's always "domain" ("network"). Update all callers.
Call cmd_has_option.
(vshCommandOptNetwork, cmdAutostart, cmdConsole, cmdDomstate)
(cmdDomblkstat, cmdDomIfstat, cmdSuspend, cmdUndefine, cmdStart)
(cmdSave, cmdSchedinfo, cmdDump, cmdResume, cmdShutdown)
(cmdReboot, cmdDestroy, cmdDominfo, cmdVcpuinfo, cmdVcpupin)
(cmdSetvcpus, cmdSetmem, cmdSetmaxmem, cmdDumpXML, cmdDomname)
(cmdDomid, cmdDomuuid, cmdMigrate, cmdNetworkAutostart)
(cmdNetworkDestroy, cmdNetworkDumpXML, cmdNetworkName)
(opts_network_start, cmdNetworkStart, cmdNetworkUndefine)
(cmdNetworkUuid, cmdVNCDisplay, cmdTTYConsole, cmdAttachDevice)
(cmdDetachDevice, cmdAttachInterface, cmdDetachInterface)
(cmdAttachDisk, cmdDetachDisk, cmdEdit)
* src/Makefile.am (virsh-pool-edit.c): This code is generated
from cmdEdit, and cmdEdit uses the vshCommandOptDomain macro which
now, with the changes above, has only 3 (was 4) arguments, yet the
macro use is mapped to vshCommandOptPool, which still requires 4
arguments. So this change adjusts the sed code to reinsert the
just-removed argument -- we're not changing pool-related code right
now, because it's not as straight-forward.
---
src/Makefile.am | 1 +
src/virsh.c | 132 +++++++++++++++++++++++++++++++++----------------------
2 files changed, 81 insertions(+), 52 deletions(-)
diff --git a/src/Makefile.am b/src/Makefile.am
index c32a1d4..2053528 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -461,6 +461,7 @@ virsh-pool-edit.c: virsh.c Makefile.am
| sed -e 's/domain/pool/g' \
-e 's/vshCommandOptDomain/vshCommandOptPool/g' \
-e 's/Domain %s/Pool %s/g' \
+ -e 's/(ctl, cmd, NULL);/(ctl, cmd, "pool", NULL);/' \
-e 's/Domain/StoragePool/g' \
-e 's/cmdEdit/cmdPoolEdit/g' \
-e 's/\(virStoragePoolDefineXML.*\));/\1, 0);/' \
diff --git a/src/virsh.c b/src/virsh.c
index f4a57f4..7828272 100644
--- a/src/virsh.c
+++ b/src/virsh.c
@@ -246,19 +246,18 @@ static int vshCommandOptBool(const vshCmd *cmd, const char *name);
#define VSH_BYNAME (1 << 3)
static virDomainPtr vshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd,
- const char *optname, char **name, int flag);
+ char **name, int flag);
/* default is lookup by Id, Name and UUID */
-#define vshCommandOptDomain(_ctl, _cmd, _optname, _name) \
- vshCommandOptDomainBy(_ctl, _cmd, _optname, _name, \
- VSH_BYID|VSH_BYUUID|VSH_BYNAME)
+#define vshCommandOptDomain(_ctl, _cmd, _name) \
+ vshCommandOptDomainBy(_ctl, _cmd, _name, VSH_BYID|VSH_BYUUID|VSH_BYNAME)
static virNetworkPtr vshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd,
- const char *optname, char **name, int flag);
+ char **name, int flag);
/* default is lookup by Name and UUID */
-#define vshCommandOptNetwork(_ctl, _cmd, _optname, _name) \
- vshCommandOptNetworkBy(_ctl, _cmd, _optname, _name, \
+#define vshCommandOptNetwork(_ctl, _cmd, _name) \
+ vshCommandOptNetworkBy(_ctl, _cmd, _name, \
VSH_BYUUID|VSH_BYNAME)
static virStoragePoolPtr vshCommandOptPoolBy(vshControl *ctl, const vshCmd *cmd,
@@ -386,7 +385,7 @@ cmdAutostart(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
return FALSE;
autostart = !vshCommandOptBool(cmd, "disable");
@@ -488,7 +487,7 @@ cmdConsole(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
doc = virDomainGetXMLDesc(dom, 0);
@@ -675,7 +674,7 @@ cmdDomstate(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
if (virDomainGetInfo(dom, &info) == 0)
@@ -712,7 +711,7 @@ cmdDomblkstat (vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability (ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain (ctl, cmd, "domain", &name)))
+ if (!(dom = vshCommandOptDomain (ctl, cmd, &name)))
return FALSE;
if (!(device = vshCommandOptString (cmd, "device", NULL)))
@@ -768,7 +767,7 @@ cmdDomIfstat (vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability (ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain (ctl, cmd, "domain", &name)))
+ if (!(dom = vshCommandOptDomain (ctl, cmd, &name)))
return FALSE;
if (!(device = vshCommandOptString (cmd, "interface", NULL)))
@@ -833,7 +832,7 @@ cmdSuspend(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
return FALSE;
if (virDomainSuspend(dom) == 0) {
@@ -979,7 +978,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
virDomainFree(dom);
return FALSE;
}
- if (!(dom = vshCommandOptDomainBy(ctl, cmd, "domain", &name,
+ if (!(dom = vshCommandOptDomainBy(ctl, cmd, &name,
VSH_BYNAME|VSH_BYUUID)))
return FALSE;
@@ -1018,7 +1017,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomainBy(ctl, cmd, "domain", NULL, VSH_BYNAME)))
+ if (!(dom = vshCommandOptDomainBy(ctl, cmd, NULL, VSH_BYNAME)))
return FALSE;
if (virDomainGetID(dom) != (unsigned int)-1) {
@@ -1068,7 +1067,7 @@ cmdSave(vshControl *ctl, const vshCmd *cmd)
if (!(to = vshCommandOptString(cmd, "file", NULL)))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
return FALSE;
if (virDomainSave(dom, to) == 0) {
@@ -1124,7 +1123,7 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
/* Deprecated Xen-only options */
@@ -1330,7 +1329,7 @@ cmdDump(vshControl *ctl, const vshCmd *cmd)
if (!(to = vshCommandOptString(cmd, "file", NULL)))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
return FALSE;
if (virDomainCoreDump(dom, to, 0) == 0) {
@@ -1369,7 +1368,7 @@ cmdResume(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
return FALSE;
if (virDomainResume(dom) == 0) {
@@ -1407,7 +1406,7 @@ cmdShutdown(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
return FALSE;
if (virDomainShutdown(dom) == 0) {
@@ -1445,7 +1444,7 @@ cmdReboot(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
return FALSE;
if (virDomainReboot(dom, 0) == 0) {
@@ -1483,7 +1482,7 @@ cmdDestroy(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
return FALSE;
if (virDomainDestroy(dom) == 0) {
@@ -1523,7 +1522,7 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
id = virDomainGetID(dom);
@@ -1648,7 +1647,7 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
if (virNodeGetInfo(ctl->conn, &nodeinfo) != 0) {
@@ -1739,7 +1738,7 @@ cmdVcpupin(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
vcpu = vshCommandOptInt(cmd, "vcpu", &vcpufound);
@@ -1864,7 +1863,7 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
count = vshCommandOptInt(cmd, "count", &count);
@@ -1920,7 +1919,7 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
kilobytes = vshCommandOptInt(cmd, "kilobytes", &kilobytes);
@@ -1976,7 +1975,7 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
kilobytes = vshCommandOptInt(cmd, "kilobytes", &kilobytes);
@@ -2093,7 +2092,7 @@ cmdDumpXML(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
dump = virDomainGetXMLDesc(dom, 0);
@@ -2129,7 +2128,7 @@ cmdDomname(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomainBy(ctl, cmd, "domain", NULL,
+ if (!(dom = vshCommandOptDomainBy(ctl, cmd, NULL,
VSH_BYID|VSH_BYUUID)))
return FALSE;
@@ -2160,7 +2159,7 @@ cmdDomid(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomainBy(ctl, cmd, "domain", NULL,
+ if (!(dom = vshCommandOptDomainBy(ctl, cmd, NULL,
VSH_BYNAME|VSH_BYUUID)))
return FALSE;
@@ -2195,7 +2194,7 @@ cmdDomuuid(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomainBy(ctl, cmd, "domain", NULL,
+ if (!(dom = vshCommandOptDomainBy(ctl, cmd, NULL,
VSH_BYNAME|VSH_BYID)))
return FALSE;
@@ -2240,7 +2239,7 @@ cmdMigrate (vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability (ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain (ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain (ctl, cmd, NULL)))
return FALSE;
desturi = vshCommandOptString (cmd, "desturi", &found);
@@ -2301,7 +2300,7 @@ cmdNetworkAutostart(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(network = vshCommandOptNetwork(ctl, cmd, "network", &name)))
+ if (!(network = vshCommandOptNetwork(ctl, cmd, &name)))
return FALSE;
autostart = !vshCommandOptBool(cmd, "disable");
@@ -2443,7 +2442,7 @@ cmdNetworkDestroy(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(network = vshCommandOptNetwork(ctl, cmd, "network", &name)))
+ if (!(network = vshCommandOptNetwork(ctl, cmd, &name)))
return FALSE;
if (virNetworkDestroy(network) == 0) {
@@ -2482,7 +2481,7 @@ cmdNetworkDumpXML(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(network = vshCommandOptNetwork(ctl, cmd, "network", NULL)))
+ if (!(network = vshCommandOptNetwork(ctl, cmd, NULL)))
return FALSE;
dump = virNetworkGetXMLDesc(network, 0);
@@ -2642,7 +2641,7 @@ cmdNetworkName(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(network = vshCommandOptNetworkBy(ctl, cmd, "network", NULL,
+ if (!(network = vshCommandOptNetworkBy(ctl, cmd, NULL,
VSH_BYUUID)))
return FALSE;
@@ -2662,7 +2661,7 @@ static const vshCmdInfo info_network_start[] = {
};
static const vshCmdOptDef opts_network_start[] = {
- {"name", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("name of the inactive network")},
+ {"network", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("name of the inactive network")},
{NULL, 0, 0, NULL}
};
@@ -2675,7 +2674,7 @@ cmdNetworkStart(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(network = vshCommandOptNetworkBy(ctl, cmd, "name", NULL, VSH_BYNAME)))
+ if (!(network = vshCommandOptNetworkBy(ctl, cmd, NULL, VSH_BYNAME)))
return FALSE;
if (virNetworkCreate(network) == 0) {
@@ -2714,7 +2713,7 @@ cmdNetworkUndefine(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(network = vshCommandOptNetwork(ctl, cmd, "network", &name)))
+ if (!(network = vshCommandOptNetwork(ctl, cmd, &name)))
return FALSE;
if (virNetworkUndefine(network) == 0) {
@@ -2751,7 +2750,7 @@ cmdNetworkUuid(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(network = vshCommandOptNetworkBy(ctl, cmd, "network", NULL,
+ if (!(network = vshCommandOptNetworkBy(ctl, cmd, NULL,
VSH_BYNAME)))
return FALSE;
@@ -4527,7 +4526,7 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
doc = virDomainGetXMLDesc(dom, 0);
@@ -4601,7 +4600,7 @@ cmdTTYConsole(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
doc = virDomainGetXMLDesc(dom, 0);
@@ -4661,7 +4660,7 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
from = vshCommandOptString(cmd, "file", &found);
@@ -4719,7 +4718,7 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return FALSE;
from = vshCommandOptString(cmd, "file", &found);
@@ -4780,7 +4779,7 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
goto cleanup;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
goto cleanup;
if (!(type = vshCommandOptString(cmd, "type", NULL)))
@@ -4899,7 +4898,7 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
goto cleanup;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
goto cleanup;
if (!(type = vshCommandOptString(cmd, "type", NULL)))
@@ -5017,7 +5016,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
goto cleanup;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
goto cleanup;
if (!(source = vshCommandOptString(cmd, "source", NULL)))
@@ -5181,7 +5180,7 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
goto cleanup;
- if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", NULL)))
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
goto cleanup;
if (!(target = vshCommandOptString(cmd, "target", NULL)))
@@ -5410,7 +5409,7 @@ cmdEdit (vshControl *ctl, const vshCmd *cmd)
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
goto cleanup;
- dom = vshCommandOptDomain (ctl, cmd, "domain", NULL);
+ dom = vshCommandOptDomain (ctl, cmd, NULL);
if (dom == NULL)
goto cleanup;
@@ -5912,14 +5911,40 @@ vshCommandOptBool(const vshCmd *cmd, const char *name)
return vshCommandOpt(cmd, name) ? TRUE : FALSE;
}
+/* Determine whether CMD->opts includes an option with name OPTNAME.
+ If not, give a diagnostic and return false.
+ If so, return true. */
+static bool
+cmd_has_option (vshControl *ctl, const vshCmd *cmd, const char *optname)
+{
+ /* Iterate through cmd->opts, to ensure that there is an entry
+ with name OPTNAME and type VSH_OT_DATA. */
+ bool found = false;
+ const vshCmdOpt *opt;
+ for (opt = cmd->opts; opt; opt = opt->next) {
+ if (STREQ (opt->def->name, optname) && opt->def->type == VSH_OT_DATA) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found)
+ vshError(ctl, FALSE,
+ _("internal error: virsh %s: no %s VSH_OT_DATA option"),
+ cmd->def->name, optname);
+ return found;
+}
static virDomainPtr
-vshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd, const char *optname,
+vshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd,
char **name, int flag)
{
virDomainPtr dom = NULL;
char *n;
int id;
+ const char *optname = "domain";
+ if (!cmd_has_option (ctl, cmd, optname))
+ return NULL;
if (!(n = vshCommandOptString(cmd, optname, NULL))) {
vshError(ctl, FALSE, "%s", _("undefined domain name or id"));
@@ -5960,11 +5985,14 @@ vshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd, const char *optname,
}
static virNetworkPtr
-vshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd, const char *optname,
+vshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd,
char **name, int flag)
{
virNetworkPtr network = NULL;
char *n;
+ const char *optname = "network";
+ if (!cmd_has_option (ctl, cmd, optname))
+ return NULL;
if (!(n = vshCommandOptString(cmd, optname, NULL))) {
vshError(ctl, FALSE, "%s", _("undefined network name"));
--
1.6.0.4.1044.g77718
15 years, 10 months