Re: [libvirt] [PATCH V2] Do not drop kernel cmdline for xen pv domains

2011-07-08 Thread Matthias Bolte
2011/7/8 Jim Fehlig jfeh...@novell.com:
 Kernel cmdline args can be passed to xen pv domains even when a
 bootloader is specified.  The current config-to-sxpr mapping
 ignores cmdline when bootloader is present.

 Since the xend sub-driver is used with many xen toolstack versions,
 this patch takes conservative approach of adding an else block to
 existing !def-os.bootloader, and only appends sxpr if def-os.cmdline
 is non-NULL.

 V2: Fix existing testcase broken by this patch and add new testcases
 ---

 +++ b/tests/sexpr2xmldata/sexpr2xml-pv-bootloader-cmdline.xml
 @@ -0,0 +1,27 @@
 +domain type='xen' id='6'
 +  namepvtest/name
 +  uuid596a5d21-71f4-8fb2-e068-e2386a5c413e/uuid
 +  memory430080/memory
 +  currentMemory430080/currentMemory
 +  vcpu2/vcpu
 +  bootloader/usr/bin/pygrub/bootloader
 +  bootloader_args-q/bootloader_args
 +  os
 +    typelinux/type
 +    cmdline xenfb.video=8,1280,1024 /cmdline

Are the leading and trailing spaces essential? If not I'd suggest to
remove them.

-- 
Matthias Bolte
http://photron.blogspot.com

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH] qemu: Don't chown files on NFS share if dynamic_ownership is off

2011-07-08 Thread Michal Privoznik
On 07.07.2011 20:12, Laine Stump wrote:
 On 07/07/2011 12:00 PM, Michal Privoznik wrote:
 On 07.07.2011 17:52, Eric Blake wrote:
 On 07/07/2011 09:33 AM, Michal Privoznik wrote:
 When dynamic ownership is disabled we don't want to chown any files,
 not just local.
 Is there more details on a scenario where this was causing an issue?
 Either a BZ number or a set of steps to reproduce the problem.

 ---
   src/qemu/qemu_driver.c |5 ++---
   1 files changed, 2 insertions(+), 3 deletions(-)

 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
 index 52b7dfd..968865f 100644
 --- a/src/qemu/qemu_driver.c
 +++ b/src/qemu/qemu_driver.c
 @@ -2163,11 +2163,10 @@ static int qemudDomainSaveFlag(struct
 qemud_driver *driver, virDomainPtr dom,
   is_reg = true;
   } else {
   is_reg = !!S_ISREG(sb.st_mode);
 -/* If the path is regular local file which exists
 +/* If the path is regular file which exists
* already and dynamic_ownership is off, we don't
* want to change it's ownership, just open it as-is */
 -if (is_reg  !driver-dynamicOwnership
 -virStorageFileIsSharedFS(path) == 0) {
 +if (is_reg  !driver-dynamicOwnership) {
 The code change looks fine, but without a pointer to a reproducer case
 proving that it is a bug fix, I'm not sure if this would have unintended
 consequences.

 Sure, https://bugzilla.redhat.com/show_bug.cgi?id=716478
 
 
 And I can't think of any reason why it *should* check for local (if
 anything, we should do *less* changing of ownership on remote
 filesystems, not more). Oh, and this is fairly recent code, so there
 won't be anybody relying on the old behavior. So ACK.

Thanks, pushed.

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] Add domain type checking

2011-07-08 Thread Matthias Bolte
The drivers were accepting domain configs without checking if those
were actually meant for them. For example the LXC driver happily
accepts configs with type QEMU.

For convenience add an optional check for the domain type for the
virDomainDefParse* functions. It's optional because in some places
virDomainDefParse* is used to parse a config without caring about
it's type. Also the QEMU driver has to accept 4 different types and
does this checking own it's own.
---
 src/conf/domain_conf.c|   48 ++--
 src/conf/domain_conf.h|5 
 src/esx/esx_driver.c  |5 ++-
 src/libxl/libxl_driver.c  |   14 ++-
 src/lxc/lxc_controller.c  |2 +-
 src/lxc/lxc_driver.c  |   13 ++-
 src/openvz/openvz_driver.c|2 +
 src/phyp/phyp_driver.c|1 +
 src/qemu/qemu_domain.c|   26 -
 src/qemu/qemu_domain.h|8 +-
 src/qemu/qemu_driver.c|   34 
 src/qemu/qemu_migration.c |   12 +-
 src/security/virt-aa-helper.c |2 +-
 src/test/test_driver.c|   11 ++--
 src/uml/uml_driver.c  |8 +++---
 src/vbox/vbox_tmpl.c  |2 +-
 src/vmware/vmware_driver.c|2 +
 src/xen/xen_driver.c  |5 +--
 src/xen/xend_internal.c   |5 ++-
 src/xen/xm_internal.c |2 +-
 src/xenapi/xenapi_driver.c|7 -
 tests/define-dev-segfault |2 +-
 tests/qemuxml2argvtest.c  |   11 -
 tests/qemuxml2xmltest.c   |   13 +-
 tests/xmconfigtest.c  |2 +-
 tests/xml2sexprtest.c |2 +-
 tests/xml2vmxtest.c   |3 +-
 27 files changed, 176 insertions(+), 71 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 7bcdcaf..69200ee 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1257,7 +1257,7 @@ virDomainObjSetDefTransient(virCapsPtr caps,
 if (!(xml = virDomainDefFormat(domain-def, VIR_DOMAIN_XML_WRITE_FLAGS)))
 goto out;
 
-if (!(newDef = virDomainDefParseString(caps, xml,
+if (!(newDef = virDomainDefParseString(caps, xml, -1,
VIR_DOMAIN_XML_READ_FLAGS)))
 goto out;
 
@@ -5760,7 +5760,8 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr 
caps,
 xmlDocPtr xml,
 xmlNodePtr root,
 xmlXPathContextPtr ctxt,
-int flags)
+int expectedVirtType,
+unsigned int flags)
 {
 xmlNodePtr *nodes = NULL, node = NULL;
 char *tmp = NULL;
@@ -5796,6 +5797,14 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr 
caps,
 }
 VIR_FREE(tmp);
 
+if (expectedVirtType = 0  def-virtType != expectedVirtType) {
+virDomainReportError(VIR_ERR_INTERNAL_ERROR,
+ _(unexpected domain type %s, should be %s),
+ virDomainVirtTypeToString(def-virtType),
+ virDomainVirtTypeToString(expectedVirtType));
+goto error;
+}
+
 /* Extract domain name */
 if (!(def-name = virXPathString(string(./name[1]), ctxt))) {
 virDomainReportError(VIR_ERR_NO_NAME, NULL);
@@ -6704,6 +6713,7 @@ no_memory:
 static virDomainObjPtr virDomainObjParseXML(virCapsPtr caps,
 xmlDocPtr xml,
 xmlXPathContextPtr ctxt,
+int expectedVirtType,
 unsigned int flags)
 {
 char *tmp = NULL;
@@ -6727,7 +6737,8 @@ static virDomainObjPtr virDomainObjParseXML(virCapsPtr 
caps,
 
 oldnode = ctxt-node;
 ctxt-node = config;
-obj-def = virDomainDefParseXML(caps, xml, config, ctxt, flags);
+obj-def = virDomainDefParseXML(caps, xml, config, ctxt, expectedVirtType,
+flags);
 ctxt-node = oldnode;
 if (!obj-def)
 goto error;
@@ -6801,13 +6812,15 @@ static virDomainDefPtr
 virDomainDefParse(const char *xmlStr,
   const char *filename,
   virCapsPtr caps,
+  int expectedVirtType,
   int flags)
 {
 xmlDocPtr xml;
 virDomainDefPtr def = NULL;
 
 if ((xml = virXMLParse(filename, xmlStr, domain.xml))) {
-def = virDomainDefParseNode(caps, xml, xmlDocGetRootElement(xml), 
flags);
+def = virDomainDefParseNode(caps, xml, xmlDocGetRootElement(xml),
+expectedVirtType, flags);
 xmlFreeDoc(xml);
 }
 
@@ -6816,22 +6829,25 @@ virDomainDefParse(const char *xmlStr,
 
 virDomainDefPtr virDomainDefParseString(virCapsPtr caps,
  

Re: [libvirt] RFC: API additions for enhanced snapshot support

2011-07-08 Thread Stefan Hajnoczi
On Thu, Jul 7, 2011 at 8:34 PM, Eric Blake ebl...@redhat.com wrote:
 On 07/07/2011 03:13 AM, Stefan Hajnoczi wrote:
 On Wed, Jul 6, 2011 at 3:03 PM, Eric Blake ebl...@redhat.com wrote:
 In other words, it looks like we are stuck with updating XML to track
 new file names any time we take a snapshot.

 Yes, but QEMU's snapshot_blkdev command takes a filename argument so
 at least you get to specify that new filename.

 Well, the best thing (from libvirt's point of view) would be if
 snapshot_blkdev took a single string argument, which is either a
 /path/to/filename (and qemu does open()) or fd:name notation (to refer
 to a previously-named fd passed via the getfd monitor command, so that
 libvirt does open()).  This would make SELinux integration easier, as
 one of the sVirt goals is to get to the point where we can use SELinux
 to forbid qemu from open()ing files on NFS shares, while still
 permitting all other operations on already-open fds passed in from libvirt.

Today QEMU supports /path/to/filename.  An fd argument to
snapshot_blkdev requires a little bit of work since the QEMU block
layer .bdrv_create() interface takes a filename and tries to create
it.

Jes: Is the fd argument to snapshot_blkdev in your plans?

Stefan

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] Fix mistaken order of server cert/key parameters in constructor

2011-07-08 Thread Daniel P. Berrange
From: Daniel P. Berrange berra...@redhat.com

The virNetTLSContextNew was being passed key/cert parameters in
the wrong order. This wasn't immediately visible because if
virNetTLSContextNewPath was used, a second bug reversed the order
of those parameters again.

Only if the paths were manually specified in /etc/libvirt/libvirtd.conf
did the bug appear

* src/rpc/virnettlscontext.c: Fix order of params passed to
  virNetTLSContextNew
---
 src/rpc/virnettlscontext.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/rpc/virnettlscontext.c b/src/rpc/virnettlscontext.c
index ad8e2dc..1120e1e 100644
--- a/src/rpc/virnettlscontext.c
+++ b/src/rpc/virnettlscontext.c
@@ -396,10 +396,10 @@ static virNetTLSContextPtr virNetTLSContextNewPath(const 
char *pkipath,
 virNetTLSContextPtr ctxt = NULL;
 
 if (virNetTLSContextLocateCredentials(pkipath, tryUserPkiPath, isServer,
-  cacert, cacrl, key, cert)  0)
+  cacert, cacrl, cert, key)  0)
 return NULL;
 
-ctxt = virNetTLSContextNew(cacert, cacrl, key, cert,
+ctxt = virNetTLSContextNew(cacert, cacrl, cert, key,
x509dnWhitelist, requireValidCert, isServer);
 
 VIR_FREE(cacert);
@@ -435,7 +435,7 @@ virNetTLSContextPtr virNetTLSContextNewServer(const char 
*cacert,
   const char 
*const*x509dnWhitelist,
   bool requireValidCert)
 {
-return virNetTLSContextNew(cacert, cacrl, key, cert,
+return virNetTLSContextNew(cacert, cacrl, cert, key,
x509dnWhitelist, requireValidCert, true);
 }
 
-- 
1.7.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] sanlock: avoid lockspace setup when auto_disk_lease is off

2011-07-08 Thread Federico Simoncelli
When auto_disk_lease is off we should avoid the automatic lockspace
creation.

Signed-off-by: Federico Simoncelli fsimo...@redhat.com
---
 src/locking/lock_driver_sanlock.c |6 --
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/locking/lock_driver_sanlock.c 
b/src/locking/lock_driver_sanlock.c
index cd2bbb5..29d4176 100644
--- a/src/locking/lock_driver_sanlock.c
+++ b/src/locking/lock_driver_sanlock.c
@@ -294,8 +294,10 @@ static int virLockManagerSanlockInit(unsigned int version,
 goto error;
 }
 
-if (virLockManagerSanlockSetupLockspace()  0)
-goto error;
+if (driver-autoDiskLease) {
+if (virLockManagerSanlockSetupLockspace()  0)
+goto error;
+}
 
 return 0;
 
-- 
1.7.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 2/5] Fix leak of 'msg' object in client stream code

2011-07-08 Thread Daniel P. Berrange
From: Daniel P. Berrange berra...@redhat.com

In one exit path we forgot to free the virNetMessage object causing
a large memory leak for streams which send alot of data. Some other
paths were calling VIR_FREE directly instead of virNetMessageFree
although this was (currently) harmless.

* src/rpc/virnetclientstream.c: Fix leak of msg object
* src/rpc/virnetclientprogram.c: Call virNetMessageFree instead
  of VIR_FREE
---
 src/rpc/virnetclientprogram.c |4 ++--
 src/rpc/virnetclientstream.c  |3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/rpc/virnetclientprogram.c b/src/rpc/virnetclientprogram.c
index 8414ad8..c39520a 100644
--- a/src/rpc/virnetclientprogram.c
+++ b/src/rpc/virnetclientprogram.c
@@ -329,11 +329,11 @@ int virNetClientProgramCall(virNetClientProgramPtr prog,
 goto error;
 }
 
-VIR_FREE(msg);
+virNetMessageFree(msg);
 
 return 0;
 
 error:
-VIR_FREE(msg);
+virNetMessageFree(msg);
 return -1;
 }
diff --git a/src/rpc/virnetclientstream.c b/src/rpc/virnetclientstream.c
index d5efab1..fe15acd 100644
--- a/src/rpc/virnetclientstream.c
+++ b/src/rpc/virnetclientstream.c
@@ -361,11 +361,12 @@ int virNetClientStreamSendPacket(virNetClientStreamPtr st,
 if (virNetClientSend(client, msg, wantReply)  0)
 goto error;
 
+virNetMessageFree(msg);
 
 return nbytes;
 
 error:
-VIR_FREE(msg);
+virNetMessageFree(msg);
 return -1;
 }
 
-- 
1.7.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 5/5] Fix sending of reply to final RPC message

2011-07-08 Thread Daniel P. Berrange
From: Daniel P. Berrange berra...@redhat.com

The dispatch for the CLOSE RPC call was invoking the method
virNetServerClientClose(). This caused the client connection
to be immediately terminated. This meant the reply to the
final RPC message was never sent. Prior to the RPC rewrite
we merely flagged the connection for closing, and actually
closed it when the next RPC call dispatch had completed.

* daemon/remote.c: Flag connection for a delayed close
* daemon/stream.c: Update to use new API for closing
  failed connection
* src/rpc/virnetserverclient.c, src/rpc/virnetserverclient.h:
  Add support for a delayed connection close. Rename the
  virNetServerClientMarkClose method to virNetServerClientImmediateClose
  to clarify its semantics
---
 daemon/remote.c  |4 ++--
 daemon/stream.c  |6 +++---
 src/rpc/virnetserverclient.c |   13 -
 src/rpc/virnetserverclient.h |5 +++--
 4 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index 2889908..a2e79ef 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -483,11 +483,11 @@ cleanup:
 
 static int
 remoteDispatchClose(virNetServerPtr server ATTRIBUTE_UNUSED,
-virNetServerClientPtr client,
+virNetServerClientPtr client ATTRIBUTE_UNUSED,
 virNetMessageHeaderPtr hdr ATTRIBUTE_UNUSED,
 virNetMessageErrorPtr rerr ATTRIBUTE_UNUSED)
 {
-virNetServerClientClose(client);
+virNetServerClientDelayedClose(client);
 return 0;
 }
 
diff --git a/daemon/stream.c b/daemon/stream.c
index 28f6c32..4a8f1ee 100644
--- a/daemon/stream.c
+++ b/daemon/stream.c
@@ -338,7 +338,7 @@ int daemonFreeClientStream(virNetServerClientPtr client,
 memset(msg, 0, sizeof(*msg));
 msg-header.type = VIR_NET_REPLY;
 if (virNetServerClientSendMessage(client, msg)  0) {
-virNetServerClientMarkClose(client);
+virNetServerClientImmediateClose(client);
 virNetMessageFree(msg);
 ret = -1;
 }
@@ -608,7 +608,7 @@ daemonStreamHandleWrite(virNetServerClientPtr client,
 virNetMessageQueueServe(stream-rx);
 if (ret  0) {
 virNetMessageFree(msg);
-virNetServerClientMarkClose(client);
+virNetServerClientImmediateClose(client);
 return -1;
 }
 
@@ -623,7 +623,7 @@ daemonStreamHandleWrite(virNetServerClientPtr client,
 msg-header.type = VIR_NET_REPLY;
 if (virNetServerClientSendMessage(client, msg)  0) {
 virNetMessageFree(msg);
-virNetServerClientMarkClose(client);
+virNetServerClientImmediateClose(client);
 return -1;
 }
 }
diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c
index 6aeb3a4..742c3a4 100644
--- a/src/rpc/virnetserverclient.c
+++ b/src/rpc/virnetserverclient.c
@@ -61,6 +61,7 @@ struct _virNetServerClient
 {
 int refs;
 bool wantClose;
+bool delayedClose;
 virMutex lock;
 virNetSocketPtr sock;
 int auth;
@@ -587,7 +588,14 @@ bool virNetServerClientIsClosed(virNetServerClientPtr 
client)
 return closed;
 }
 
-void virNetServerClientMarkClose(virNetServerClientPtr client)
+void virNetServerClientDelayedClose(virNetServerClientPtr client)
+{
+virNetServerClientLock(client);
+client-delayedClose = true;
+virNetServerClientUnlock(client);
+}
+
+void virNetServerClientImmediateClose(virNetServerClientPtr client)
 {
 virNetServerClientLock(client);
 client-wantClose = true;
@@ -852,6 +860,9 @@ virNetServerClientDispatchWrite(virNetServerClientPtr 
client)
 virNetMessageFree(msg);
 
 virNetServerClientUpdateEvent(client);
+
+if (client-delayedClose)
+client-wantClose = true;
  }
 }
 }
diff --git a/src/rpc/virnetserverclient.h b/src/rpc/virnetserverclient.h
index 66510c3..3d2e1fb 100644
--- a/src/rpc/virnetserverclient.h
+++ b/src/rpc/virnetserverclient.h
@@ -86,9 +86,10 @@ void virNetServerClientSetDispatcher(virNetServerClientPtr 
client,
  virNetServerClientDispatchFunc func,
  void *opaque);
 void virNetServerClientClose(virNetServerClientPtr client);
-
 bool virNetServerClientIsClosed(virNetServerClientPtr client);
-void virNetServerClientMarkClose(virNetServerClientPtr client);
+
+void virNetServerClientDelayedClose(virNetServerClientPtr client);
+void virNetServerClientImmediateClose(virNetServerClientPtr client);
 bool virNetServerClientWantClose(virNetServerClientPtr client);
 
 int virNetServerClientInit(virNetServerClientPtr client);
-- 
1.7.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 4/5] Fix leak of remote driver if final 'CLOSE' RPC call fails

2011-07-08 Thread Daniel P. Berrange
From: Daniel P. Berrange berra...@redhat.com

When closing a remote connection we issue a (fairly pointless)
'CLOSE' RPC call to the daemon. If this fails we skip all the
cleanup of private data, but the virConnectPtr object still
gets released as normal. This causes a memory leak. Since the
CLOSE RPC call is pretty pointless, just carry on freeing the
remote driver if it fails.

* src/remote/remote_driver.c: Ignore failure to issue CLOSE
  RPC call
---
 src/remote/remote_driver.c |6 --
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 4eea3a4..da04a93 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -824,10 +824,12 @@ get_transport_from_scheme (char *scheme)
 static int
 doRemoteClose (virConnectPtr conn, struct private_data *priv)
 {
+int ret = 0;
+
 if (call (conn, priv, 0, REMOTE_PROC_CLOSE,
   (xdrproc_t) xdr_void, (char *) NULL,
   (xdrproc_t) xdr_void, (char *) NULL) == -1)
-return -1;
+ret = -1;
 
 virNetTLSContextFree(priv-tls);
 priv-tls = NULL;
@@ -846,7 +848,7 @@ doRemoteClose (virConnectPtr conn, struct private_data 
*priv)
 virDomainEventStateFree(priv-domainEventState);
 priv-domainEventState = NULL;
 
-return 0;
+return ret;
 }
 
 static int
-- 
1.7.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 1/8] Define a QEMU specific API to attach to a running QEMU process

2011-07-08 Thread Daniel P. Berrange
On Tue, Jul 05, 2011 at 12:54:32PM +0200, Matthias Bolte wrote:
 2011/7/4 Daniel P. Berrange berra...@redhat.com:
  Introduce a new API in libvirt-qemu.so
 
   virDomainPtr virDomainQemuAttach(virConnectPtr domain,
                                   unsigned long long pid,
                                   unsigned int flags);
 
  This allows libvirtd to attach to an existing, externally
  launched QEMU process. This is useful for QEMU developers who
  prefer to launch QEMU themselves for debugging/devel reasons,
  but still want the benefit of libvirt based tools like
  virt-top, virt-viewer, etc
 
  * include/libvirt/libvirt-qemu.h: Define virDomainQemuAttach
  * src/driver.h, src/libvirt-qemu.c, src/libvirt_qemu.syms:
   Driver glue for virDomainQemuAttach
  ---
   include/libvirt/libvirt-qemu.h |    4 +++
   src/driver.h                   |    6 +
   src/libvirt-qemu.c             |   41 
  
   src/libvirt_qemu.syms          |    5 
   4 files changed, 56 insertions(+), 0 deletions(-)
 
  +virDomainPtr
  +virDomainQemuAttach(virConnectPtr conn,
  +                    unsigned long long pid,
  +                    unsigned int flags)
  +{
  +    VIR_DEBUG(conn=%p, pid=%llu, flags=%u, conn, pid, flags);
 
 Shouldn't this function have documentation? Hm,
 virDomainQemuMonitorCommand isn't documented either.
 
  diff --git a/src/libvirt_qemu.syms b/src/libvirt_qemu.syms
  index 5702d36..1bb8b62 100644
  --- a/src/libvirt_qemu.syms
  +++ b/src/libvirt_qemu.syms
  @@ -14,3 +14,8 @@ LIBVIRT_QEMU_0.8.3 {
      global:
          virDomainQemuMonitorCommand;
   };
  +
  +LIBVIRT_QEMU_0.9.3 {
  +    global:
  +        virDomainQemuAttach;
  +} LIBVIRT_QEMU_0.8.3;
 
 0.9.3 was released in the meantime, needs to be 0.9.4 now.

Fixed this  added some docs.


Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH] Define remote wire protocol impls for virDomainQemuAttach

2011-07-08 Thread Daniel P. Berrange
From: Daniel P. Berrange berra...@redhat.com

This tweaks the RPC generator to cope with some naming
conventions used for the QEMU specific APIs

* daemon/remote.c: Server side dispatcher
* src/remote/remote_driver.c: Client side dispatcher
* src/remote/qemu_protocol.x: Wire protocol definition
* src/rpc/gendispatch.pl: Use '$structprefix' in method
  names, fix QEMU flags and fix dispatcher method names
---
 src/remote/qemu_protocol.x |   13 -
 src/remote/remote_driver.c |1 +
 src/rpc/gendispatch.pl |   11 +--
 3 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/src/remote/qemu_protocol.x b/src/remote/qemu_protocol.x
index fa453f4..c6a5648 100644
--- a/src/remote/qemu_protocol.x
+++ b/src/remote/qemu_protocol.x
@@ -37,6 +37,16 @@ struct qemu_monitor_command_ret {
 remote_nonnull_string result;
 };
 
+
+struct qemu_domain_attach_args {
+unsigned hyper pid;
+unsigned int flags;
+};
+
+struct qemu_domain_attach_ret {
+remote_nonnull_domain dom;
+};
+
 /* Define the program number, protocol version and procedure numbers here. */
 const QEMU_PROGRAM = 0x20008087;
 const QEMU_PROTOCOL_VERSION = 1;
@@ -45,5 +55,6 @@ enum qemu_procedure {
 /* Each function must have a two-word comment.  The first word is
  * whether remote_generator.pl handles daemon, the second whether
  * it handles src/remote.  */
-QEMU_PROC_MONITOR_COMMAND = 1 /* skipgen skipgen */
+QEMU_PROC_MONITOR_COMMAND = 1, /* skipgen skipgen */
+QEMU_PROC_DOMAIN_ATTACH = 2 /* autogen autogen */
 };
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index f318740..4eea3a4 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -4222,6 +4222,7 @@ static virDriver remote_driver = {
 .domainRevertToSnapshot = remoteDomainRevertToSnapshot, /* 0.8.0 */
 .domainSnapshotDelete = remoteDomainSnapshotDelete, /* 0.8.0 */
 .qemuDomainMonitorCommand = remoteQemuDomainMonitorCommand, /* 0.8.3 */
+.qemuDomainAttach = qemuDomainAttach, /* 0.9.4 */
 .domainOpenConsole = remoteDomainOpenConsole, /* 0.8.6 */
 .domainInjectNMI = remoteDomainInjectNMI, /* 0.9.2 */
 .domainMigrateBegin3 = remoteDomainMigrateBegin3, /* 0.9.2 */
diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
index 027560c..56841c8 100755
--- a/src/rpc/gendispatch.pl
+++ b/src/rpc/gendispatch.pl
@@ -821,6 +821,8 @@ elsif ($opt_b) {
 $proc_name = ConnectBaselineCPU
 } elsif ($call-{ProcName} eq CPUCompare) {
 $proc_name = ConnectCompareCPU
+} elsif ($structprefix eq qemu  $call-{ProcName} =~ 
/^Domain/) {
+$proc_name =~ s/^(Domain)/${1}Qemu/;
 }
 
 if ($single_ret_as_list) {
@@ -1323,7 +1325,7 @@ elsif ($opt_k) {
 # print function
 print \n;
 print static $single_ret_type\n;
-print remote$call-{ProcName}(;
+print $structprefix$call-{ProcName}(;
 
 print join(, , @args_list);
 
@@ -1417,8 +1419,13 @@ elsif ($opt_k) {
 print memset(ret, 0, sizeof ret);\n;
 }
 
+my $callflags = 0;
+if ($structprefix eq qemu) {
+$callflags = REMOTE_CALL_QEMU;
+}
+
 print \n;
-print if (call($priv_src, priv, 0, 
${procprefix}_PROC_$call-{UC_NAME},\n;
+print if (call($priv_src, priv, $callflags, 
${procprefix}_PROC_$call-{UC_NAME},\n;
 print  (xdrproc_t)xdr_$argtype, (char *)$call_args,\n;
 print  (xdrproc_t)xdr_$rettype, (char *)$call_ret) == -1) 
{\n;
 
-- 
1.7.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 8/8] Implement code to attach to external QEMU instances.

2011-07-08 Thread Daniel P. Berrange
On Tue, Jul 05, 2011 at 03:09:23PM +0200, Matthias Bolte wrote:
 2011/7/4 Daniel P. Berrange berra...@redhat.com:
  Given a PID, the QEMU driver reads /proc/$PID/cmdline and
  /proc/$PID/environ to get the configuration. This is fed
  into the ARGV-XML convertor to build an XML configuration
  for the process.
 
  /proc/$PID/exe is resolved to identify the full command
  binary path
 
  After checking for name/uuid uniqueness, an attempt is
  made to connect to the monitor socket. If successful
  then 'info status' and 'info kvm' are issued to determine
  whether the CPUs are running and if KVM is enabled.
 
  * src/qemu/qemu_driver.c: Implement virDomainQemuAttach
  * src/qemu/qemu_process.h, src/qemu/qemu_process.c: Add
   qemuProcessAttach to connect to the monitor of an
   existing QEMU process
  ---
   src/conf/domain_conf.c  |    3 +-
   src/conf/domain_conf.h  |    1 +
   src/qemu/qemu_command.c |    2 +
   src/qemu/qemu_driver.c  |   91 +++-
   src/qemu/qemu_process.c |  218 
  ---
   src/qemu/qemu_process.h |    8 ++
   6 files changed, 308 insertions(+), 15 deletions(-)
 
   static int
   qemuDomainOpenConsole(virDomainPtr dom,
                        const char *devname,
  @@ -8539,6 +8625,7 @@ static virDriver qemuDriver = {
      .domainRevertToSnapshot = qemuDomainRevertToSnapshot, /* 0.8.0 */
      .domainSnapshotDelete = qemuDomainSnapshotDelete, /* 0.8.0 */
      .qemuDomainMonitorCommand = qemuDomainMonitorCommand, /* 0.8.3 */
  +    .qemuDomainAttach = qemuDomainAttach, /* 0.9.3 */
 
 s/0.9.3/0.9.4/
 
  +int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED,
  +                      struct qemud_driver *driver,
  +                      virDomainObjPtr vm,
  +                      int pid,
  +                      const char *pidfile,
  +                      virDomainChrSourceDefPtr monConfig,
  +                      bool monJSON)
  +{
  +    char ebuf[1024];
  +    int logfile = -1;
  +    char *timestamp;
  +    qemuDomainObjPrivatePtr priv = vm-privateData;
  +    bool running = true;
  +    virSecurityLabelPtr seclabel = NULL;
  +
  +    VIR_DEBUG(Beginning VM attach process);
  +
  +    if (virDomainObjIsActive(vm)) {
  +        qemuReportError(VIR_ERR_OPERATION_INVALID,
  +                        %s, _(VM is already active));
  +        return -1;
  +    }
  +
  +    /* Do this upfront, so any part of the startup process can add
  +     * runtime state to vm-def that won't be persisted. This let's us
  +     * report implicit runtime defaults in the XML, like vnc listen/socket
  +     */
  +    VIR_DEBUG(Setting current domain def as transient);
  +    if (virDomainObjSetDefTransient(driver-caps, vm, true)  0)
  +        goto cleanup;
  +
  +    vm-def-id = driver-nextvmid++;
  +
  +    if (virFileMakePath(driver-logDir) != 0) {
  +        virReportSystemError(errno,
  +                             _(cannot create log directory %s),
  +                             driver-logDir);
  +        goto cleanup;
  +    }
 
 This doesn't work as virFileMakePath doesn't set errno for all errors,
 but returns an errno value. Needs to be something like this
 
 int err;
 if ((err = virFileMakePath(driver-logDir)) != 0) {
 virReportSystemError(err,
  _(cannot create log directory %s),
  driver-logDir);
 goto cleanup;
 }
 
 Also grep'ing for virFileMakePath shows that there are many instances
 that use virFileMakePath in the wrong way.

THis has since been fixed.

  +    if (VIR_ALLOC(priv-monConfig)  0) {
  +        virReportOOMError();
  +        goto cleanup;
  +    }
  +
  +    VIR_DEBUG(Preparing monitor state);
  +    priv-monConfig = monConfig;
 
 Allocating and overwriting priv-monConfig leaks memory here.

Fixed that too

Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 2/8] Define remote wire protocol impls for virDomainQemuAttach

2011-07-08 Thread Daniel P. Berrange
On Tue, Jul 05, 2011 at 01:07:45PM +0200, Matthias Bolte wrote:
 2011/7/4 Daniel P. Berrange berra...@redhat.com:
  * daemon/remote.c: Server side dispatcher
  * src/remote/remote_driver.c: Client side dispatcher
  * src/remote/qemu_protocol.x: Wire protocol definition
  ---
   daemon/remote.c            |   41 +
   src/remote/qemu_protocol.x |   13 -
   src/remote/remote_driver.c |   30 ++
   3 files changed, 83 insertions(+), 1 deletions(-)
 
  diff --git a/daemon/remote.c b/daemon/remote.c
  index 2889908..85fc978 100644
  --- a/daemon/remote.c
  +++ b/daemon/remote.c
  @@ -2645,6 +2645,47 @@ cleanup:
 
 
   static int
  +qemuDispatchDomainAttach(virNetServerPtr server ATTRIBUTE_UNUSED,
  +                         virNetServerClientPtr client ATTRIBUTE_UNUSED,
  +                         virNetMessageHeaderPtr hdr ATTRIBUTE_UNUSED,
  +                         virNetMessageErrorPtr rerr,
  +                         qemu_domain_attach_args *args,
  +                         qemu_domain_attach_ret *ret)
  +{
  +    virDomainPtr dom = NULL;
  +    int rv = -1;
  +    struct daemonClientPrivate *priv =
  +        virNetServerClientGetPrivateData(client);
  +
  +    if (!priv-conn) {
  +        virNetError(VIR_ERR_INTERNAL_ERROR, %s, _(connection not 
  open));
  +        goto cleanup;
  +    }
  +
  +    if (!(dom = virDomainQemuAttach(priv-conn,
  +                                    args-pid,
  +                                    args-flags)))
  +        goto cleanup;
  +
  +    make_nonnull_domain(ret-dom, dom);
  +
  +    rv = 0;
  +
  +cleanup:
  +    if (rv  0)
  +        virNetMessageSaveError(rerr);
  +    if (dom)
  +        virDomainFree(dom);
  +    return rv;
  +}
 
 The generator should be able to deal with this, did you try?

I couldn't, but it turns out the changes were fairly easy.

  +#include remote_dispatch_bodies.h
  +#include qemu_dispatch_bodies.h
  +
  +
  + Define remote wire protocol  impls for virDomainQemuAttach
 
 The includes and this line looks bogus, probably a rebase problem.

Yep, totally bogus line.

 
  +static virDomainPtr
  +remoteQemuDomainAttach(virConnectPtr conn, unsigned long long pid, 
  unsigned int flags)
  +{
  +    virDomainPtr rv = NULL;
  +    struct private_data *priv = conn-privateData;
  +    qemu_domain_attach_args args;
  +    qemu_domain_attach_ret ret;
  +
  +    remoteDriverLock(priv);
  +
  +    args.pid = pid;
  +    args.flags = flags;
  +
  +    memset(ret, 0, sizeof ret);
  +
  +    if (call(conn, priv, REMOTE_CALL_QEMU, QEMU_PROC_DOMAIN_ATTACH,
  +             (xdrproc_t)xdr_qemu_domain_attach_args, (char *)args,
  +             (xdrproc_t)xdr_qemu_domain_attach_ret, (char *)ret) == -1)
  +        goto done;
  +
  +    rv = get_nonnull_domain(conn, ret.dom);
  +    xdr_free((xdrproc_t)xdr_qemu_domain_attach_ret, (char *)ret);
  +
  +done:
  +    remoteDriverUnlock(priv);
  +    return rv;
  +}
 
 The generator should also be able to deal with this one.

It did after some changes


I'm reposting this one patch since its the only one that needed
non-trivial fixups

Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 05/10] conf: put virtPortProfile struct / functions in a common location

2011-07-08 Thread Daniel P. Berrange
On Tue, Jul 05, 2011 at 03:45:53AM -0400, Laine Stump wrote:
 virtPortProfiles are currently only used in the domain XML, but will
 soon also be used in the network XML. To prepare for that change, this
 patch moves the structure definition into util/network.h and the parse
 and format functions into util/network.c (I decided that this was a
 better choice than macvtap.h/c for something that needed to always be
 available on all platforms).
 
 Additionally, the virtPortProfile in the domain interface struct is
 now a separately allocated object rather *pointed to by* (rather than
 contained in) the main virDomainNetDef object. This is done to make is
 easier to figure out when a virtualPortProfile has/hasn't been
 specified in a particular config.
 ---
  src/conf/domain_conf.c|  208 
 +++--
  src/conf/domain_conf.h|2 +-
  src/libvirt_private.syms  |2 +
  src/qemu/qemu_command.c   |4 +-
  src/qemu/qemu_hotplug.c   |2 +-
  src/qemu/qemu_migration.c |4 +-
  src/qemu/qemu_process.c   |2 +-
  src/util/macvtap.c|6 +-
  src/util/macvtap.h|   36 +
  src/util/network.c|  196 ++
  src/util/network.h|   47 ++
  11 files changed, 271 insertions(+), 238 deletions(-)


ACK, a little disappointing that we have to put this in src/util
instead of a common file in src/conf/, but it looks like we have
a compile time dep to macvtap forcing us to put it in util.

Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 3/5] Fix release of outgoing stream confirmation/abort message

2011-07-08 Thread Daniel P. Berrange
From: Daniel P. Berrange berra...@redhat.com

When sending back the final OK or ERROR message on completion
of a stream, we were not decrementing the 'nrequests' tracker
on the client. With the default requests limit of '5', this
meant once a client had created 5 streams, they are unable to
process any further RPC calls.  There was also a bug when
handling an error from decoding a message length header, which
meant a client connection would not immediately be closed.

* src/rpc/virnetserverclient.c: Fix release of request after
  stream completion  mark client for close on error
---
 src/rpc/virnetserverclient.c |8 ++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c
index 30d7fcb..6aeb3a4 100644
--- a/src/rpc/virnetserverclient.c
+++ b/src/rpc/virnetserverclient.c
@@ -700,8 +700,10 @@ readmore:
 
 /* Either done with length word header */
 if (client-rx-bufferLength == VIR_NET_MESSAGE_LEN_MAX) {
-if (virNetMessageDecodeLength(client-rx)  0)
+if (virNetMessageDecodeLength(client-rx)  0) {
+client-wantClose = true;
 return;
+}
 
 virNetServerClientUpdateEvent(client);
 
@@ -831,7 +833,9 @@ virNetServerClientDispatchWrite(virNetServerClientPtr 
client)
 /* Get finished msg from head of tx queue */
 msg = virNetMessageQueueServe(client-tx);
 
-if (msg-header.type == VIR_NET_REPLY) {
+if (msg-header.type == VIR_NET_REPLY ||
+(msg-header.type == VIR_NET_STREAM 
+ msg-header.status != VIR_NET_CONTINUE)) {
 client-nrequests--;
 /* See if the recv queue is currently throttled */
 if (!client-rx 
-- 
1.7.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 1/5] Fix potential crash in libvirtd with active streams

2011-07-08 Thread Daniel P. Berrange
From: Daniel P. Berrange berra...@redhat.com

If a client disconnects while it has a stream active, there is
a race condition which could see libvirtd crash. This is because
the client struct may be freed before the last stream event has
triggered. THis is trivially solved by holding an extra reference
on the client for the stream callbak

* daemon/stream.c: Acquire reference on client when adding the
  stream callback
---
 daemon/stream.c |   13 -
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/daemon/stream.c b/daemon/stream.c
index 56d79c2..28f6c32 100644
--- a/daemon/stream.c
+++ b/daemon/stream.c
@@ -104,6 +104,15 @@ daemonStreamMessageFinished(virNetMessagePtr msg,
 daemonStreamUpdateEvents(stream);
 }
 
+
+static void
+daemonStreamEventFreeFunc(void *opaque)
+{
+virNetServerClientPtr client = opaque;
+
+virNetServerClientFree(client);
+}
+
 /*
  * Callback that gets invoked when a stream becomes writable/readable
  */
@@ -361,9 +370,11 @@ int daemonAddClientStream(virNetServerClientPtr client,
 }
 
 if (virStreamEventAddCallback(stream-st, 0,
-  daemonStreamEvent, client, NULL)  0)
+  daemonStreamEvent, client,
+  daemonStreamEventFreeFunc)  0)
 return -1;
 
+virNetServerClientRef(client);
 if ((stream-filterID = virNetServerClientAddFilter(client,
 daemonStreamFilter,
 stream))  0) {
-- 
1.7.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 06/10] network: RNG changes for virtual switch

2011-07-08 Thread Daniel P. Berrange
On Tue, Jul 05, 2011 at 03:45:54AM -0400, Laine Stump wrote:
 This adds virtualportprofile and portgroup (which itself can
 contain a portgroup) to network, adds several new options to
 forward mode, and adds an optional pool of interfaces to forward.
 
 Since virtualPortProfile is now used in both the domain and network
 RNG, its definition was moved into a separate file that is included by
 both.
 ---
  docs/schemas/Makefile.am   |1 +
  docs/schemas/domain.rng|   54 ++-
  docs/schemas/network.rng   |   29 +
  docs/schemas/networkcommon.rng |   50 +
  libvirt.spec.in|1 +
  5 files changed, 90 insertions(+), 45 deletions(-)
  create mode 100644 docs/schemas/networkcommon.rng

ACK,

Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 0/5] Fix misc problems in the RPC code

2011-07-08 Thread Daniel P. Berrange
This series of patches fixes a couple of memory leaks, one crash
and a missing reply to the final RPC message on a connection
being closed

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 07/10] network: new XML to support virtual switch functionality

2011-07-08 Thread Daniel P. Berrange
On Tue, Jul 05, 2011 at 03:45:55AM -0400, Laine Stump wrote:
 This implements the changes to network and domain interface XML that
 were earlier specified in the RNG.
 
 Each virDomainNetDef now also potentially has a virDomainActualNetDef
 which is a private object (never exported/imported via the public API,
 and not defined in the RNG) that is used to maintain information about
 the physical device that was actually used for a NetDef that was of
 type VIR_DOMAIN_NET_TYPE_NETWORK.
 
 The virDomainActualNetDef will only be parsed/formatted if the
 parse/format function is called with the VIR_DOMAIN_XML_ACTUAL_NET
 flags set (which is only needed when saving/loading a running domain's
 state info to the stateDir). To prevent this flag bit from
 accidentally being used in the public API, a RESERVED placeholder
 was put into the public flags enum (at the same time, I noticed there
 was another private flag that hadn't been reserved, so I added that
 one, making both of these flags #defined from the public RESERVED
 flags, and since it was also only used in domain_conf.c, I unpolluted
 domain_conf.h, putting both #defines in domain_conf.c.
 
 A small change is also made to two functions in bridge_driver.c, to
 prevent a bridge device name and mac address from being automatically
 added to a network definition when it is of one of the new forward
 types (none of which use bridge devices managed by libvirt).
 ---
  include/libvirt/libvirt.h.in |2 +
  src/conf/domain_conf.c   |  276 +++-
  src/conf/domain_conf.h   |   46 ++-
  src/conf/network_conf.c  |  321 
 +-
  src/conf/network_conf.h  |   34 -
  src/libvirt_private.syms |8 +-
  src/network/bridge_driver.c  |   28 +++-
  7 files changed, 657 insertions(+), 58 deletions(-)

I think it would be worth doing a little change in patch split for
this and the previous patch. Instead of splitting between schema
and impl, split between domain  network.

So I think we should have one patch which pulls the common domain.rng
conf schema pieces out, and also modifies domain_conf.h/c at
the same time.

Then a second patch, which pulls the common vport bits into
network.rng and also modifies  network_conf.h/.c

Also, each of those patches ought to have at least one new
data file added to their corresponding XML test case at the
same time, so that each patch contains the full self-contained
modifications.

 
 diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
 index 8e20f75..b88c96e 100644
 --- a/include/libvirt/libvirt.h.in
 +++ b/include/libvirt/libvirt.h.in
 @@ -1112,6 +1112,8 @@ typedef enum {
  VIR_DOMAIN_XML_SECURE   = (1  0), /* dump security sensitive 
 information too */
  VIR_DOMAIN_XML_INACTIVE = (1  1), /* dump inactive domain 
 information */
  VIR_DOMAIN_XML_UPDATE_CPU   = (1  2), /* update guest CPU requirements 
 according to host CPU */
 +VIR_DOMAIN_XML_RESERVED1= (1  30), /* reserved for internal used */
 +VIR_DOMAIN_XML_RESERVED2= (1  31), /* reserved for internal used */
  } virDomainXMLFlags;

[snip]

 +/* these flags are only used internally */
 +/* dump internal domain status information */
 +#define VIR_DOMAIN_XML_INTERNAL_STATUS VIR_DOMAIN_XML_RESERVED1
 +/* dump virDomainActualNetDef contents */
 +#define VIR_DOMAIN_XML_ACTUAL_NET VIR_DOMAIN_XML_RESERVED2

Ewww, I really don't like this idea.  If we need to pass special
internal only flags to the parser/formating methods, then I think
that should be done as a separate parameter from the public
flags parameter.  Either a 'unsigned int internalFlags' or
one or more 'bool someOption' parameters.

  static void
  virDomainObjListDataFree(void *payload, const void *name ATTRIBUTE_UNUSED)
 @@ -714,6 +719,25 @@ void virDomainFSDefFree(virDomainFSDefPtr def)
  VIR_FREE(def);
  }
  
 +void
 +virDomainActualNetDefFree(virDomainActualNetDefPtr def)
 +{
 +if (!def)
 +return;
 +
 +switch (def-type) {
 +case VIR_DOMAIN_NET_TYPE_BRIDGE:
 +VIR_FREE(def-data.bridge.brname);
 +break;
 +case VIR_DOMAIN_NET_TYPE_DIRECT:
 +VIR_FREE(def-data.direct.linkdev);
 +VIR_FREE(def-data.direct.virtPortProfile);
 +break;
 +default:
 +break;
 +}
 +}
 +
  void virDomainNetDefFree(virDomainNetDefPtr def)
  {
  if (!def)
 @@ -736,6 +760,9 @@ void virDomainNetDefFree(virDomainNetDefPtr def)
  
  case VIR_DOMAIN_NET_TYPE_NETWORK:
  VIR_FREE(def-data.network.name);
 +VIR_FREE(def-data.network.portgroup);
 +VIR_FREE(def-data.network.virtPortProfile);
 +virDomainActualNetDefFree(def-data.network.actual);
  break;
  
  case VIR_DOMAIN_NET_TYPE_BRIDGE:
 @@ -2566,6 +2593,85 @@ cleanup:
  goto cleanup;
  }
  
 +static int
 +virDomainActualNetDefParseXML(xmlNodePtr node,
 +  xmlXPathContextPtr ctxt,
 +   

Re: [libvirt] [PATCH] Define remote wire protocol impls for virDomainQemuAttach

2011-07-08 Thread Matthias Bolte
2011/7/8 Daniel P. Berrange berra...@redhat.com:
 From: Daniel P. Berrange berra...@redhat.com

 This tweaks the RPC generator to cope with some naming
 conventions used for the QEMU specific APIs

 * daemon/remote.c: Server side dispatcher
 * src/remote/remote_driver.c: Client side dispatcher
 * src/remote/qemu_protocol.x: Wire protocol definition
 * src/rpc/gendispatch.pl: Use '$structprefix' in method
  names, fix QEMU flags and fix dispatcher method names
 ---
  src/remote/qemu_protocol.x |   13 -
  src/remote/remote_driver.c |    1 +
  src/rpc/gendispatch.pl     |   11 +--
  3 files changed, 22 insertions(+), 3 deletions(-)


ACK.

-- 
Matthias Bolte
http://photron.blogspot.com

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH] util: Don't try to fchown files opened as non-root

2011-07-08 Thread Jiri Denemark
When virFileOpenAs is called with VIR_FILE_OPEN_AS_UID flag and uid/gid
different from root/root while libvirtd is running as root, we fork a
new child, change its effective UID/GID to uid/gid and run
virFileOpenAsNoFork. It doesn't make any sense to fchown() the opened
file in this case since we already know that uid/gid can access the file
when open succeeds and one of the following situations may happen:

- the file is already owned by uid/gid and we skip fchown even before
  this patch
- the file is owned by uid but not gid because it was created in a
  directory with SETGID set, in which case it is desirable not to change
  the group
- the file may be owned by a completely different user and/or group
  because it was created on a root-squashed or even all-squashed NFS
  filesystem, in which case fchown would most likely fail anyway
---
 src/util/util.c |   31 +++
 1 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/src/util/util.c b/src/util/util.c
index 3d0ceea..8ff25da 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -652,7 +652,6 @@ virFileOpenAsNoFork(const char *path, int openflags, mode_t 
mode,
 {
 int fd = -1;
 int ret = 0;
-struct stat st;
 
 if ((fd = open(path, openflags, mode))  0) {
 ret = -errno;
@@ -660,18 +659,25 @@ virFileOpenAsNoFork(const char *path, int openflags, 
mode_t mode,
  path);
 goto error;
 }
-if (fstat(fd, st) == -1) {
-ret = -errno;
-virReportSystemError(errno, _(stat of '%s' failed), path);
-goto error;
-}
-if (((st.st_uid != uid) || (st.st_gid != gid))
- (fchown(fd, uid, gid)  0)) {
-ret = -errno;
-virReportSystemError(errno, _(cannot chown '%s' to (%u, %u)),
- path, (unsigned int) uid, (unsigned int) gid);
-goto error;
+
+/* VIR_FILE_OPEN_AS_UID in flags means we are running in a child process
+ * owned by uid and gid */
+if (!(flags  VIR_FILE_OPEN_AS_UID)) {
+struct stat st;
+if (fstat(fd, st) == -1) {
+ret = -errno;
+virReportSystemError(errno, _(stat of '%s' failed), path);
+goto error;
+}
+if (((st.st_uid != uid) || (st.st_gid != gid))
+ (fchown(fd, uid, gid)  0)) {
+ret = -errno;
+virReportSystemError(errno, _(cannot chown '%s' to (%u, %u)),
+ path, (unsigned int) uid, (unsigned int) gid);
+goto error;
+}
 }
+
 if ((flags  VIR_FILE_OPEN_FORCE_PERMS)
  (fchmod(fd, mode)  0)) {
 ret = -errno;
@@ -757,6 +763,7 @@ virFileOpenAs(const char *path, int openflags, mode_t mode,
 if ((!(flags  VIR_FILE_OPEN_AS_UID))
 || (getuid() != 0)
 || ((uid == 0)  (gid == 0))) {
+flags = ~VIR_FILE_OPEN_AS_UID;
 return virFileOpenAsNoFork(path, openflags, mode, uid, gid, flags);
 }
 
-- 
1.7.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 08/10] network: separate Start/Shutdown functions for new network types

2011-07-08 Thread Daniel P. Berrange
On Tue, Jul 05, 2011 at 03:45:56AM -0400, Laine Stump wrote:
 Previously all networks were composed of bridge devices created and
 managed by libvirt, and the same operations needed to be done for all
 of them when they were started and stopped (create and start the
 bridge device, configure its MAC address and IP address, add iptables
 rules). The new network types are (for now at least) managed outside
 of libvirt, and the network object is used only to contain information
 about the network, which is then used as each individual guest
 connects itself.
 
 This means that when starting/stopping one of these new networks, we
 really want to do nothing, aside from marking the network as
 active/inactive.
 
 This has been setup as toplevel Start/Shutdown functions that do the
 small bit of common stuff, then have a switch statement to execute
 network type-specific start/shutdown code, then do a bit more common
 code. The type-specific functions called for the new host bridge and
 macvtap based types are currently empty.
 
 In the future these functions may actually do something, and we will
 surely add more functions that are similarly patterned. Once
 everything has settled, we can make a table of sub-driver function
 pointers for each network type, and store a pointer to that table in
 the network object, then we can replace the switch statements with
 calls to functions in the table.
 
 The final step in this will be to add a new table (and corresponding
 new functions) for new network types as they are added.
 ---
  src/network/bridge_driver.c |  188 
 +++
  1 files changed, 138 insertions(+), 50 deletions(-)

ACK, there is pretty much no functional change for existing
network types.

 +
 +VIR_INFO(Starting up network '%s', network-def-name);
 +network-active = 1;

...

  network-active = 0;

We could take this opportunity to change to using a bool and
true/false


Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] RFC: API additions for enhanced snapshot support

2011-07-08 Thread Jes Sorensen
On 07/08/11 10:58, Stefan Hajnoczi wrote:
 On Thu, Jul 7, 2011 at 8:34 PM, Eric Blake ebl...@redhat.com wrote:
 Well, the best thing (from libvirt's point of view) would be if
 snapshot_blkdev took a single string argument, which is either a
 /path/to/filename (and qemu does open()) or fd:name notation (to refer
 to a previously-named fd passed via the getfd monitor command, so that
 libvirt does open()).  This would make SELinux integration easier, as
 one of the sVirt goals is to get to the point where we can use SELinux
 to forbid qemu from open()ing files on NFS shares, while still
 permitting all other operations on already-open fds passed in from libvirt.
 
 Today QEMU supports /path/to/filename.  An fd argument to
 snapshot_blkdev requires a little bit of work since the QEMU block
 layer .bdrv_create() interface takes a filename and tries to create
 it.
 
 Jes: Is the fd argument to snapshot_blkdev in your plans?

I only ever heard suggestions for taking fd arguments yesterday, so I
cannot say it really is in my plans. If I get a good justification I
might be convinced :)

Cheers,
Jes

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] Add domain type checking

2011-07-08 Thread Eric Blake
On 07/08/2011 02:13 AM, Matthias Bolte wrote:
 The drivers were accepting domain configs without checking if those
 were actually meant for them. For example the LXC driver happily
 accepts configs with type QEMU.
 
 For convenience add an optional check for the domain type for the
 virDomainDefParse* functions. It's optional because in some places
 virDomainDefParse* is used to parse a config without caring about
 it's type. Also the QEMU driver has to accept 4 different types and
 does this checking own it's own.

Can we factor the 4 QEMU types back into the common method?  Do this by
treating expectedType as a bitmask:

 +++ b/src/conf/domain_conf.c
 @@ -1257,7 +1257,7 @@ virDomainObjSetDefTransient(virCapsPtr caps,
  if (!(xml = virDomainDefFormat(domain-def, VIR_DOMAIN_XML_WRITE_FLAGS)))
  goto out;
  
 -if (!(newDef = virDomainDefParseString(caps, xml,
 +if (!(newDef = virDomainDefParseString(caps, xml, -1,
 VIR_DOMAIN_XML_READ_FLAGS)))

-1 being the bitmask to accept all possible types,

 @@ -5796,6 +5797,14 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr 
 caps,
  }
  VIR_FREE(tmp);
  
 +if (expectedVirtType = 0  def-virtType != expectedVirtType) {

here, change the logic to:

if (((1  def-virtType)  expectedVirtTypes) == 0) {

 +virDomainReportError(VIR_ERR_INTERNAL_ERROR,
 + _(unexpected domain type %s, should be %s),
 + virDomainVirtTypeToString(def-virtType),
 + virDomainVirtTypeToString(expectedVirtType));
 +goto error;
 +}
 +
  /* Extract domain name */
  if (!(def-name = virXPathString(string(./name[1]), ctxt))) {
  virDomainReportError(VIR_ERR_NO_NAME, NULL);
 @@ -6704,6 +6713,7 @@ no_memory:
  static virDomainObjPtr virDomainObjParseXML(virCapsPtr caps,
  xmlDocPtr xml,
  xmlXPathContextPtr ctxt,
 +int expectedVirtType,

make this plural expectedVirtTypes, to reflect that it is a bitmask,

 +++ b/src/esx/esx_driver.c
 @@ -2855,7 +2855,8 @@ esxDomainXMLToNative(virConnectPtr conn, const char 
 *nativeFormat,
  return NULL;
  }
  
 -def = virDomainDefParseString(priv-caps, domainXml, 0);
 +def = virDomainDefParseString(priv-caps, domainXml,
 +  VIR_DOMAIN_VIRT_VMWARE, 0);

here, pass (1  VIR_DOMAIN_VIRT_VMWARE) instead of VIR_DOMAIN_VIRT_VMWARE

 +++ b/src/qemu/qemu_domain.c
 @@ -700,10 +700,32 @@ void qemuDomainObjExitRemoteWithDriver(struct 
 qemud_driver *driver,
  ignore_value(virDomainObjUnref(obj));
  }
  
 +virDomainDefPtr qemuDomainDefParseXML(struct qemud_driver *driver,
 +  const char *xml,
 +  unsigned int flags)
 +{
 +virDomainDefPtr def;
 +
 +if (!(def = virDomainDefParseString(driver-caps, xml, -1, flags)))
 +return NULL;
 +
 +if (def-virtType != VIR_DOMAIN_VIRT_QEMU 
 +def-virtType != VIR_DOMAIN_VIRT_KQEMU 
 +def-virtType != VIR_DOMAIN_VIRT_KVM 
 +def-virtType != VIR_DOMAIN_VIRT_XEN) {

Then here, instead of having qemu parse things, you instead pass:

((1  VIR_DOMAIN_VIRT_QEMU) |
 (1  VIR_DOMAIN_VIRT_KQEMU) |
 (1  VIR_DOMAIN_VIRT_KVM) |
 (1  VIR_DOMAIN_VIRT_XEN))

as the expectedVirtTypes.

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH] Define remote wire protocol impls for virDomainQemuAttach

2011-07-08 Thread Eric Blake
On 07/08/2011 06:20 AM, Daniel P. Berrange wrote:
 From: Daniel P. Berrange berra...@redhat.com
 
 This tweaks the RPC generator to cope with some naming
 conventions used for the QEMU specific APIs
 
 * daemon/remote.c: Server side dispatcher
 * src/remote/remote_driver.c: Client side dispatcher
 * src/remote/qemu_protocol.x: Wire protocol definition
 * src/rpc/gendispatch.pl: Use '$structprefix' in method
   names, fix QEMU flags and fix dispatcher method names
 ---
  src/remote/qemu_protocol.x |   13 -
  src/remote/remote_driver.c |1 +
  src/rpc/gendispatch.pl |   11 +--
  3 files changed, 22 insertions(+), 3 deletions(-)

Hmm.  We have src/remote_protocol-structs to catch any incompatible
on-the-wire changes to remote_protocol.x, but nothing to track changes
to qemu_protocol.x.  Is this something that needs fixing to help us
avoid unintended wire breakage?

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH] util: Don't try to fchown files opened as non-root

2011-07-08 Thread Eric Blake
On 07/08/2011 07:30 AM, Jiri Denemark wrote:
 When virFileOpenAs is called with VIR_FILE_OPEN_AS_UID flag and uid/gid
 different from root/root while libvirtd is running as root, we fork a
 new child, change its effective UID/GID to uid/gid and run
 virFileOpenAsNoFork. It doesn't make any sense to fchown() the opened
 file in this case since we already know that uid/gid can access the file
 when open succeeds and one of the following situations may happen:
 
 - the file is already owned by uid/gid and we skip fchown even before
   this patch
 - the file is owned by uid but not gid because it was created in a
   directory with SETGID set, in which case it is desirable not to change
   the group
 - the file may be owned by a completely different user and/or group
   because it was created on a root-squashed or even all-squashed NFS
   filesystem, in which case fchown would most likely fail anyway
 ---
  src/util/util.c |   31 +++
  1 files changed, 19 insertions(+), 12 deletions(-)

ACK.

 +/* VIR_FILE_OPEN_AS_UID in flags means we are running in a child process
 + * owned by uid and gid */
 +if (!(flags  VIR_FILE_OPEN_AS_UID)) {
 +struct stat st;
 +if (fstat(fd, st) == -1) {

Style nit - add a newline between the declaration of st and the first
statement (the nested if).

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] RFC: API additions for enhanced snapshot support

2011-07-08 Thread Eric Blake
On 07/08/2011 07:35 AM, Jes Sorensen wrote:
 On 07/08/11 10:58, Stefan Hajnoczi wrote:
 On Thu, Jul 7, 2011 at 8:34 PM, Eric Blake ebl...@redhat.com wrote:
 Well, the best thing (from libvirt's point of view) would be if
 snapshot_blkdev took a single string argument, which is either a
 /path/to/filename (and qemu does open()) or fd:name notation (to refer
 to a previously-named fd passed via the getfd monitor command, so that
 libvirt does open()).  This would make SELinux integration easier, as
 one of the sVirt goals is to get to the point where we can use SELinux
 to forbid qemu from open()ing files on NFS shares, while still
 permitting all other operations on already-open fds passed in from libvirt.

 Today QEMU supports /path/to/filename.  An fd argument to
 snapshot_blkdev requires a little bit of work since the QEMU block
 layer .bdrv_create() interface takes a filename and tries to create
 it.

 Jes: Is the fd argument to snapshot_blkdev in your plans?
 
 I only ever heard suggestions for taking fd arguments yesterday, so I
 cannot say it really is in my plans. If I get a good justification I
 might be convinced :)

I already gave the justification - SELinux.

For a disk mounted over NFS, the current SELinux bool virt_use_nfs is a
bit broad (it gives all-or-nothing access to qemu to be able to open()
arbitrary files on NFS).  The way to tighten it is to instead have
libvirt in charge of opening any file on NFS, then pass that fd to qemu
- in which case SELinux policy can give qemu carte-blanche to do
anything on an existing NFS fd, but not to open() a new one.  Then sVirt
has gained an additional layer of protection where qemu cannot blindly
stomp on another VM's storage merely because both VMs happened to store
their disk images on the same NFS server.  But this requires that _all_
places in qemu that currently open() a file also be given an alternative
to get the fd via command-line or getfd inheritance.

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH v3] bios: Add support for SGA

2011-07-08 Thread Michal Privoznik
This patch creates new bios element which, at this time has the only
attribute useserial='yes|no'. This attribute allow users to use
Serial Graphics Adapter and see BIOS messages from the very first moment
domain boots up. Therefore, users can choose boot medium, set PXE, etc.
---
diff to v2:
-move from serial to bios
-include Eric's and Dan's suggestions

diff to v1:
-move from video to serial as Dan suggested:
https://www.redhat.com/archives/libvir-list/2011-July/msg00134.html

 docs/formatdomain.html.in |9 ++
 docs/schemas/domain.rng   |   14 +
 src/conf/domain_conf.c|   27 -
 src/conf/domain_conf.h|   13 
 src/qemu/qemu_capabilities.c  |3 ++
 src/qemu/qemu_capabilities.h  |1 +
 src/qemu/qemu_command.c   |   20 +
 tests/qemuxml2argvdata/qemuxml2argv-bios.args |6 
 tests/qemuxml2argvdata/qemuxml2argv-bios.xml  |   39 +
 tests/qemuxml2argvtest.c  |1 +
 10 files changed, 131 insertions(+), 2 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-bios.args
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-bios.xml

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 10d87a9..9cc0bca 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -86,6 +86,7 @@
 lt;boot dev='cdrom'/gt;
 lt;bootmenu enable='yes'/gt;
 lt;smbios mode='sysinfo'/gt;
+lt;bios useserial='yes'/gt;
   lt;/osgt;
   .../pre
 
@@ -137,6 +138,14 @@
   specified, the hypervisor default is used. span class=since
   Since 0.8.7/span
   /dd
+  dtcodebios/code/dt
+  ddThis element has attribute codeuseserial/code with possible
+values codeyes/code or codeno/code. It enables or disables
+Serial Graphics Adapter which allows users to see BIOS messages
+on a serial port. Therefore, one need to have
+a href=#elementCharSerialserial port/a defined.
+span class=sinceSince 0.9.4/span
+  /dd
 /dl
 
 h4a name=elementsOSBootloaderHost bootloader/a/h4
diff --git a/docs/schemas/domain.rng b/docs/schemas/domain.rng
index 3c8414e..2d3b3cd 100644
--- a/docs/schemas/domain.rng
+++ b/docs/schemas/domain.rng
@@ -151,6 +151,9 @@
 optional
   ref name=smbios/
 /optional
+optional
+  ref name=bios/
+/optional
   /interleave
 /element
   /define
@@ -2261,6 +2264,17 @@
 /element
   /define
 
+  define name=bios
+element name=bios
+  attribute name=useserial
+choice
+  valueyes/value
+  valueno/value
+/choice
+  /attribute
+/element
+  /define
+
   define name=address
 element name=address
   choice
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 2275d3a..eaafa15 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5628,9 +5628,9 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt,
 {
 xmlNodePtr *nodes = NULL;
 int i, n;
-char *bootstr;
+char *bootstr, *useserial;
 int ret = -1;
-unsigned long deviceBoot;
+unsigned long deviceBoot, serialPorts;
 
 if (virXPathULong(count(./devices/disk[boot]
   |./devices/interface[boot]
@@ -5684,6 +5684,22 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt,
 VIR_FREE(bootstr);
 }
 
+useserial = virXPathString(string(./os/bios[1]/@useserial), ctxt);
+if (useserial) {
+if (STREQ(useserial, yes)) {
+if (virXPathULong(count(./devices/serial),
+  ctxt, serialPorts)  0) {
+virDomainReportError(VIR_ERR_CONFIG_UNSUPPORTED, %s,
+ _(need at least one serial port 
+   for useserial));
+goto cleanup;
+}
+def-os.bios.useserial = VIR_DOMAIN_BIOS_USESERIAL_YES;
+} else {
+def-os.bios.useserial = VIR_DOMAIN_BIOS_USESERIAL_NO;
+}
+}
+
 *bootCount = deviceBoot;
 ret = 0;
 
@@ -9720,6 +9736,13 @@ char *virDomainDefFormat(virDomainDefPtr def,
 : no);
 virBufferAsprintf(buf, bootmenu enable='%s'/\n, enabled);
 }
+
+if (def-os.bios.useserial) {
+const char *useserial = (def-os.bios.useserial ==
+ VIR_DOMAIN_BIOS_USESERIAL_YES ? yes
+   : no);
+virBufferAsprintf(buf, bios useserial='%s'/\n, useserial);
+}
 }
 
 if (def-os.smbios_mode) {
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index ddfe18e..71cb145 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -923,6 

[libvirt] Exposing qemu support for SDL via capabilities

2011-07-08 Thread Adam Litke
Hi all,

In order to nicely support domains that use qemu's SDL support,
libvirt-cim is looking for a way to confirm if the underlying qemu
emulator can support SDL.  Libvirt already knows this information
internally.  It seems to me that the best way to provide this
information is by reporting it as a guest feature via the capabilities
API call.  I was thinking the node '/capabilities/guest/features/sdl'
could be added when qemu supports SDL.

Is this a good idea?

-- 
Adam Litke
IBM Linux Technology Center

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] Don't exist if the libvirtd config does not exist

2011-07-08 Thread Matthias Bolte
2011/7/8 Daniel P. Berrange berra...@redhat.com:
 From: Daniel P. Berrange berra...@redhat.com

 It is common for the $HOME/.libvirt/libvirtd.conf file to not
 exist. Treat this situation as non-fatal since we can carry
 on with our default settings just fine.

 * daemon/libvirtd.c: Treat ENOENT as non-fatal when loading
  config
 ---
  daemon/libvirtd.c |    4 
  1 files changed, 4 insertions(+), 0 deletions(-)

 diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
 index 06d2077..fe0fa27 100644
 --- a/daemon/libvirtd.c
 +++ b/daemon/libvirtd.c
 @@ -1028,6 +1028,10 @@ daemonConfigLoad(struct daemonConfig *data,
  {
     virConfPtr conf;

 +    if (access(filename, R_OK) == -1 
 +        errno == ENOENT)
 +        return 0;
 +
     conf = virConfReadFile (filename, 0);
     if (!conf)
         return -1;

s/Don't exist/Don't exit/ typo in subject.

ACK, qemu:///session is working again.

-- 
Matthias Bolte
http://photron.blogspot.com

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH] Fix mistaken order of server cert/key parameters in constructor

2011-07-08 Thread Jiri Denemark
On Fri, Jul 08, 2011 at 11:16:03 +0100, Daniel P. Berrange wrote:
 From: Daniel P. Berrange berra...@redhat.com
 
 The virNetTLSContextNew was being passed key/cert parameters in
 the wrong order. This wasn't immediately visible because if
 virNetTLSContextNewPath was used, a second bug reversed the order
 of those parameters again.
 
 Only if the paths were manually specified in /etc/libvirt/libvirtd.conf
 did the bug appear
 
 * src/rpc/virnettlscontext.c: Fix order of params passed to
   virNetTLSContextNew
 ---
  src/rpc/virnettlscontext.c |6 +++---
  1 files changed, 3 insertions(+), 3 deletions(-)

ACK

Jirka

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 1/5] Fix potential crash in libvirtd with active streams

2011-07-08 Thread Eric Blake
On 07/08/2011 05:57 AM, Daniel P. Berrange wrote:
 From: Daniel P. Berrange berra...@redhat.com
 
 If a client disconnects while it has a stream active, there is
 a race condition which could see libvirtd crash. This is because
 the client struct may be freed before the last stream event has
 triggered. THis is trivially solved by holding an extra reference

s/THis/This/

 on the client for the stream callbak
 
 * daemon/stream.c: Acquire reference on client when adding the
   stream callback
 ---
  daemon/stream.c |   13 -
  1 files changed, 12 insertions(+), 1 deletions(-)
 

ACK.

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 2/5] Fix leak of 'msg' object in client stream code

2011-07-08 Thread Eric Blake
On 07/08/2011 05:57 AM, Daniel P. Berrange wrote:
 From: Daniel P. Berrange berra...@redhat.com
 
 In one exit path we forgot to free the virNetMessage object causing
 a large memory leak for streams which send alot of data. Some other

s/alot/a lot/

 paths were calling VIR_FREE directly instead of virNetMessageFree
 although this was (currently) harmless.
 
 * src/rpc/virnetclientstream.c: Fix leak of msg object
 * src/rpc/virnetclientprogram.c: Call virNetMessageFree instead
   of VIR_FREE
 ---
  src/rpc/virnetclientprogram.c |4 ++--
  src/rpc/virnetclientstream.c  |3 ++-
  2 files changed, 4 insertions(+), 3 deletions(-)

ACK.

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 3/5] Fix release of outgoing stream confirmation/abort message

2011-07-08 Thread Eric Blake
On 07/08/2011 05:57 AM, Daniel P. Berrange wrote:
 From: Daniel P. Berrange berra...@redhat.com
 
 When sending back the final OK or ERROR message on completion
 of a stream, we were not decrementing the 'nrequests' tracker
 on the client. With the default requests limit of '5', this
 meant once a client had created 5 streams, they are unable to
 process any further RPC calls.  There was also a bug when
 handling an error from decoding a message length header, which
 meant a client connection would not immediately be closed.
 
 * src/rpc/virnetserverclient.c: Fix release of request after
   stream completion  mark client for close on error
 ---
  src/rpc/virnetserverclient.c |8 ++--
  1 files changed, 6 insertions(+), 2 deletions(-)

ACK.

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 4/5] Fix leak of remote driver if final 'CLOSE' RPC call fails

2011-07-08 Thread Eric Blake
On 07/08/2011 05:57 AM, Daniel P. Berrange wrote:
 From: Daniel P. Berrange berra...@redhat.com
 
 When closing a remote connection we issue a (fairly pointless)
 'CLOSE' RPC call to the daemon. If this fails we skip all the
 cleanup of private data, but the virConnectPtr object still
 gets released as normal. This causes a memory leak. Since the
 CLOSE RPC call is pretty pointless, just carry on freeing the
 remote driver if it fails.
 
 * src/remote/remote_driver.c: Ignore failure to issue CLOSE
   RPC call
 ---
  src/remote/remote_driver.c |6 --
  1 files changed, 4 insertions(+), 2 deletions(-)

ACK.

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 5/5] Fix sending of reply to final RPC message

2011-07-08 Thread Eric Blake
On 07/08/2011 05:57 AM, Daniel P. Berrange wrote:
 From: Daniel P. Berrange berra...@redhat.com
 
 The dispatch for the CLOSE RPC call was invoking the method
 virNetServerClientClose(). This caused the client connection
 to be immediately terminated. This meant the reply to the
 final RPC message was never sent. Prior to the RPC rewrite
 we merely flagged the connection for closing, and actually
 closed it when the next RPC call dispatch had completed.
 
 * daemon/remote.c: Flag connection for a delayed close
 * daemon/stream.c: Update to use new API for closing
   failed connection
 * src/rpc/virnetserverclient.c, src/rpc/virnetserverclient.h:
   Add support for a delayed connection close. Rename the
   virNetServerClientMarkClose method to virNetServerClientImmediateClose
   to clarify its semantics
 ---
  daemon/remote.c  |4 ++--
  daemon/stream.c  |6 +++---
  src/rpc/virnetserverclient.c |   13 -
  src/rpc/virnetserverclient.h |5 +++--
  4 files changed, 20 insertions(+), 8 deletions(-)
 

ACK.

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH v4] graphics: add support for action_if_connected in qemu

2011-07-08 Thread Michal Privoznik

On 07.07.2011 20:25, Eric Blake wrote:

On 07/07/2011 02:59 AM, Michal Privoznik wrote:

On 06.07.2011 00:34, Eric Blake wrote:


This patch changes the .xml, but not the corresponding .args file, which
to me says it is probably incomplete.  We covered the case of changing
the attribute affecting qemu_hotplug:



No. This is purely QMP thing. qemu -spice does not have any option for
setting this (the current git version at least). That .xml vs .args
change: I've changed .xml so we can test RNG scheme. There is nothing to
add to .args.


Ah, that makes sense now.  This is not a qemu attribute associated with
the spice device, rather it is a feature of the hotplug command (when
hotplugging, what action to take in this condition).  As such, I think
you are right that there is no change to any .args file, so ACK to this
patch as-is.

That said, Jirka's proposed patch for introducing a monitor-proxy[1]
sounds like it would be an awesome way to enhance our testsuite
coverage.  It would be nice to write up a test-stub proxy that pretends
to be an active qemu monitor, but which functions even without running a
real qemu process.  In that way, we could get further exposure that the
monitor commands that we are generating match our expectations.

[1] https://www.redhat.com/archives/libvir-list/2011-July/msg00028.html



Thanks, pushed.

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 1/2] qemu: return error condition

2011-07-08 Thread Michael Santos
---
 src/qemu/qemu_bridge_filter.c |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/src/qemu/qemu_bridge_filter.c b/src/qemu/qemu_bridge_filter.c
index f700631..03ed284 100644
--- a/src/qemu/qemu_bridge_filter.c
+++ b/src/qemu/qemu_bridge_filter.c
@@ -78,6 +78,7 @@ networkAllowMacOnPort(struct qemud_driver *driver,
 virReportSystemError(err,
  _(failed to add ebtables rule to allow routing to '%s'),
  ifname);
+return err;
 }
 
 return 0;
@@ -99,6 +100,7 @@ networkDisallowMacOnPort(struct qemud_driver *driver,
 virReportSystemError(err,
  _(failed to add ebtables rule to allow routing to '%s'),
  ifname);
+return err;
 }
 
 return 0;
-- 
1.7.0.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 2/2] qemu: clean up OOM checks

2011-07-08 Thread Michael Santos
---
 src/qemu/qemu_command.c |   40 
 1 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 6e4480e..19151ce 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5712,6 +5712,9 @@ qemuParseCommandLineCPU(virDomainDefPtr dom,
 else
 feature = strdup(p);
 
+if (!feature)
+goto no_memory;
+
 ret = virCPUDefAddFeature(cpu, feature, policy);
 VIR_FREE(feature);
 if (ret  0)
@@ -6028,6 +6031,8 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr caps,
 if (STREQ(arg, -cdrom)) {
 disk-device = VIR_DOMAIN_DISK_DEVICE_CDROM;
 disk-dst = strdup(hdc);
+if (!disk-dst)
+goto no_memory;
 disk-readonly = 1;
 } else {
 if (STRPREFIX(arg, -fd)) {
@@ -6041,8 +6046,12 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr caps,
 disk-bus = VIR_DOMAIN_DISK_BUS_SCSI;
 }
 disk-dst = strdup(arg + 1);
+if (!disk-dst)
+goto no_memory;
 }
 disk-src = strdup(val);
+if (!disk-src)
+goto no_memory;
 
 if (disk-type == VIR_DOMAIN_DISK_TYPE_NETWORK) {
 char *host, *port;
@@ -6058,17 +6067,14 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr caps,
 goto error;
 }
 *port++ = '\0';
-if (VIR_ALLOC(disk-hosts)  0) {
-virReportOOMError();
-goto error;
-}
+if (VIR_ALLOC(disk-hosts)  0)
+goto no_memory;
 disk-nhosts = 1;
 disk-hosts-name = host;
 disk-hosts-port = strdup(port);
-if (!disk-hosts-port) {
-virReportOOMError();
-goto error;
-}
+if (!disk-hosts-port)
+goto no_memory;
+VIR_FREE(disk-src);
 disk-src = NULL;
 break;
 case VIR_DOMAIN_DISK_PROTOCOL_RBD:
@@ -6088,22 +6094,16 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr caps,
 goto error;
 }
 *vdi++ = '\0';
-if (VIR_ALLOC(disk-hosts)  0) {
-virReportOOMError();
-goto error;
-}
+if (VIR_ALLOC(disk-hosts)  0)
+goto no_memory;
 disk-nhosts = 1;
 disk-hosts-name = disk-src;
 disk-hosts-port = strdup(port);
-if (!disk-hosts-port) {
-virReportOOMError();
-goto error;
-}
+if (!disk-hosts-port)
+goto no_memory;
 disk-src = strdup(vdi);
-if (!disk-src) {
-virReportOOMError();
-goto error;
-}
+if (!disk-src)
+goto no_memory;
 }
 break;
 }
-- 
1.7.0.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] Exposing qemu support for SDL via capabilities

2011-07-08 Thread Richard W.M. Jones
On Fri, Jul 08, 2011 at 09:19:46AM -0500, Adam Litke wrote:
 Hi all,
 
 In order to nicely support domains that use qemu's SDL support,
 libvirt-cim is looking for a way to confirm if the underlying qemu
 emulator can support SDL.  Libvirt already knows this information
 internally.  It seems to me that the best way to provide this
 information is by reporting it as a guest feature via the capabilities
 API call.  I was thinking the node '/capabilities/guest/features/sdl'
 could be added when qemu supports SDL.
 
 Is this a good idea?

Seems like clearly a good idea to me.  (Although I don't have
to code it :-)

Would it be worth having a separate graphics element underneath
features, so the path would be /capabilities/guest/features/graphics/sdl ?

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] testsuite formatting bugs [was: [PATCH] Skip some xen tests if xend is not running]

2011-07-08 Thread Eric Blake
On 07/07/2011 04:21 PM, Eric Blake wrote:
 Oh, and our testsuite has a cosmetic bug.  After applying your patch, I
 see this during 'make check':
 
 TEST: xencapstest
   ..   10  OK
 PASS: xencapstest
 SKIP: reconnect
 TEST: statstest
0   FAIL
 SKIP: statstest
 
 Bonus points for fixing up that output to say SKIP instead of FAIL and
 to align it correctly (but that can be a separate patch).

As long as we're investigating formatting errors, this one is also annoying:

TEST: virsh-all
   40
   80
   120
  ... 159 OK
PASS: virsh-all

We're obviously getting the logic wrong when there are 0 or when
tests%40 == 39.

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] Exposing qemu support for SDL via capabilities

2011-07-08 Thread Adam Litke


On 07/08/2011 10:14 AM, Richard W.M. Jones wrote:
 On Fri, Jul 08, 2011 at 09:19:46AM -0500, Adam Litke wrote:
 Hi all,

 In order to nicely support domains that use qemu's SDL support,
 libvirt-cim is looking for a way to confirm if the underlying qemu
 emulator can support SDL.  Libvirt already knows this information
 internally.  It seems to me that the best way to provide this
 information is by reporting it as a guest feature via the capabilities
 API call.  I was thinking the node '/capabilities/guest/features/sdl'
 could be added when qemu supports SDL.

 Is this a good idea?
 
 Seems like clearly a good idea to me.  (Although I don't have
 to code it :-)

Don't worry :)  I think we have a motivated party.

 Would it be worth having a separate graphics element underneath
 features, so the path would be /capabilities/guest/features/graphics/sdl ?

I only think this would be needed if we are going to add other
graphics-related features.  Can you think of other features that would
fit?  I think libvirt always assumes some form of vnc support so there
may not be a need to enumerate graphics types.  We might want to
advertise spice support, but that wouldn't fit strictly under graphics
because spice affects much more than the graphics device.

Is there a desire to eventually add support for enumerating the
different models of devices that qemu can emulate?  For example,
[ne2k_pci, i82551, i82557b, i82559er, rtl8139, e1000, pcnet, virtio] for
network models?  If so, we may want to place this information in a more
structured hierarchy /capabilities/guest/devices/net/models/.  Either
way, SDL support isn't part of the device model so it would probably
make sense to place it directly under 'features' IMO.

-- 
Adam Litke
IBM Linux Technology Center

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] Don't exist if the libvirtd config does not exist

2011-07-08 Thread Eric Blake
On 07/08/2011 08:28 AM, Daniel P. Berrange wrote:
 From: Daniel P. Berrange berra...@redhat.com
 
 It is common for the $HOME/.libvirt/libvirtd.conf file to not
 exist. Treat this situation as non-fatal since we can carry
 on with our default settings just fine.
 
 * daemon/libvirtd.c: Treat ENOENT as non-fatal when loading
   config
 ---
  daemon/libvirtd.c |4 
  1 files changed, 4 insertions(+), 0 deletions(-)
 
 diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
 index 06d2077..fe0fa27 100644
 --- a/daemon/libvirtd.c
 +++ b/daemon/libvirtd.c
 @@ -1028,6 +1028,10 @@ daemonConfigLoad(struct daemonConfig *data,
  {
  virConfPtr conf;
  
 +if (access(filename, R_OK) == -1 
 +errno == ENOENT)
 +return 0;
 +

This patch breaks 'make check' - tests/libvirtd-fail is now reporting
failure.

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH] Don't exist if the libvirtd config does not exist

2011-07-08 Thread Eric Blake
On 07/08/2011 10:07 AM, Eric Blake wrote:
 On 07/08/2011 08:28 AM, Daniel P. Berrange wrote:
 From: Daniel P. Berrange berra...@redhat.com

 It is common for the $HOME/.libvirt/libvirtd.conf file to not
 exist. Treat this situation as non-fatal since we can carry
 on with our default settings just fine.


  
 +if (access(filename, R_OK) == -1 
 +errno == ENOENT)
 +return 0;
 +
 
 This patch breaks 'make check' - tests/libvirtd-fail is now reporting
 failure.

That test is checking that an explicit libvirtd --config=no-such-conf
reports failure.

I think the solution to this is to also pass around a bool stating
whether the conf file name was generated by default (ENOENT is okay) or
explicitly passed in (ENOENT must fail).

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH] libvirtd: diagnose explicitly requested but missing conf file

2011-07-08 Thread Eric Blake
Fixes test regression introduced in commit 8e2e4780.

* daemon/libvirtd.c (daemonConfigLoad): Add argument.
(main): Update caller.
---

Pushing under the build-breaker rule, since it is detected by 'make check'.

 daemon/libvirtd.c |   19 ---
 1 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index fe0fa27..a4198d9 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -1024,11 +1024,13 @@ daemonConfigFree(struct daemonConfig *data)
  */
 static int
 daemonConfigLoad(struct daemonConfig *data,
- const char *filename)
+ const char *filename,
+ bool allow_missing)
 {
 virConfPtr conf;

-if (access(filename, R_OK) == -1 
+if (allow_missing 
+access(filename, R_OK) == -1 
 errno == ENOENT)
 return 0;

@@ -1282,6 +1284,7 @@ int main(int argc, char **argv) {
 int ipsock = 0;
 struct daemonConfig *config;
 bool privileged = geteuid() == 0 ? true : false;
+bool implicit_conf = false;

 struct option opts[] = {
 { verbose, no_argument, verbose, 1},
@@ -1367,14 +1370,16 @@ int main(int argc, char **argv) {
 exit(EXIT_FAILURE);

 /* No explicit config, so try and find a default one */
-if (remote_config_file == NULL 
-daemonConfigFilePath(privileged,
- remote_config_file)  0)
-exit(EXIT_FAILURE);
+if (remote_config_file == NULL) {
+implicit_conf = true;
+if (daemonConfigFilePath(privileged,
+ remote_config_file)  0)
+exit(EXIT_FAILURE);
+}

 /* Read the config file if it exists*/
 if (remote_config_file 
-daemonConfigLoad(config, remote_config_file)  0)
+daemonConfigLoad(config, remote_config_file, implicit_conf)  0)
 exit(EXIT_FAILURE);

 if (config-host_uuid 
-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCHv2 01/27] maint: exclude more files from syntax check

2011-07-08 Thread Eric Blake
* cfg.mk (VC_LIST_ALWAYS_EXCLUDE_REGEX): Exempt
docs/api_extension/*.patch.
(exclude_file_name_regexp--sc_prohibit_always_true_header_tests)
(exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF)
(exclude_file_name_regexp--sc_prohibit_fork_wrappers)
(exclude_file_name_regexp--sc_trailing_blank): Simplify.
(exclude_file_name_regexp--sc_prohibit_gettext_noop): Delete.
(exclude_file_name_regexp--sc_prohibit_close)
(exclude_file_name_regexp--sc_prohibit_nonreentrant)
(exclude_file_name_regexp--sc_prohibit_sprintf): Tighten.
---

v2: new patch

 cfg.mk |   19 +--
 1 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/cfg.mk b/cfg.mk
index b00cda3..f266bb0 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -74,7 +74,8 @@ local-checks-to-skip =\
   sc_useless_cpp_parens

 # Files that should never cause syntax check failures.
-VC_LIST_ALWAYS_EXCLUDE_REGEX = (^(HACKING|docs/news\.html\.in)|\.po)$$
+VC_LIST_ALWAYS_EXCLUDE_REGEX = \
+  (^(HACKING|docs/(news\.html\.in|.*\.patch))|\.po)$$

 # Functions like free() that are no-ops on NULL arguments.
 useless_free_options = \
@@ -633,36 +634,34 @@ exclude_file_name_regexp--sc_prohibit_VIR_ERR_NO_MEMORY = 
\
 exclude_file_name_regexp--sc_prohibit_access_xok = ^src/util/util\.c$$

 exclude_file_name_regexp--sc_prohibit_always_true_header_tests = \
-  (^docs|^python/(libvirt-override|typewrappers)\.c$$)
+  ^python/(libvirt-override|typewrappers)\.c$$

 exclude_file_name_regexp--sc_prohibit_asprintf = \
   
^(bootstrap.conf$$|src/util/util\.c$$|examples/domain-events/events-c/event-test\.c$$)

 exclude_file_name_regexp--sc_prohibit_close = \
-  (\.p[yl]$$|^docs/|(src/util/files\.c|src/libvirt\.c)$$)
+  (\.p[yl]$$|^docs/|^(src/util/files\.c|src/libvirt\.c)$$)

 exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF = \
-  (^docs/api_extension/|^tests/qemuhelpdata/|\.(gif|ico|png)$$)
+  (^tests/qemuhelpdata/|\.(gif|ico|png)$$)

 _src2=src/(util/command|libvirt|lxc/lxc_controller)
 exclude_file_name_regexp--sc_prohibit_fork_wrappers = \
-  (^docs|^($(_src2)|tests/testutils|daemon/libvirtd)\.c$$)
+  (^($(_src2)|tests/testutils|daemon/libvirtd)\.c$$)

 exclude_file_name_regexp--sc_prohibit_gethostname = ^src/util/util\.c$$

-exclude_file_name_regexp--sc_prohibit_gettext_noop = ^docs/
-
 exclude_file_name_regexp--sc_prohibit_newline_at_end_of_diagnostic = \
   ^src/rpc/gendispatch\.pl$$

 exclude_file_name_regexp--sc_prohibit_nonreentrant = \
-  ^((po|docs|tests)/|tools/(virsh|console)\.c$$)
+  ^((po|tests)/|docs/.*py$$|tools/(virsh|console)\.c$$)

 exclude_file_name_regexp--sc_prohibit_readlink = ^src/util/util\.c$$

 exclude_file_name_regexp--sc_prohibit_setuid = ^src/util/util\.c$$

-exclude_file_name_regexp--sc_prohibit_sprintf = ^(docs/|HACKING$$)
+exclude_file_name_regexp--sc_prohibit_sprintf = ^docs/hacking\.html\.in$$

 exclude_file_name_regexp--sc_prohibit_strncpy = \
   ^(src/util/util|tools/virsh)\.c$$
@@ -673,7 +672,7 @@ exclude_file_name_regexp--sc_require_config_h = ^examples/

 exclude_file_name_regexp--sc_require_config_h_first = ^examples/

-exclude_file_name_regexp--sc_trailing_blank = (^docs/|\.(fig|gif|ico|png)$$)
+exclude_file_name_regexp--sc_trailing_blank = \.(fig|gif|ico|png)$$

 exclude_file_name_regexp--sc_unmarked_diagnostics = \
   ^(docs/apibuild.py|tests/virt-aa-helper-test)$$
-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCHv2 04/27] libvirt-qemu: use unsigned flags

2011-07-08 Thread Eric Blake
Like commit 1740c381, but for libvirt-qemu.

* src/remote/qemu_protocol.x (qemu_monitor_command_args): Adjust
type to match API.
* src/qemu_protocol-structs: Update accordingly.
---

v2: new patch

 src/qemu_protocol-structs  |2 +-
 src/remote/qemu_protocol.x |4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/qemu_protocol-structs b/src/qemu_protocol-structs
index e93e8bf..b124dfa 100644
--- a/src/qemu_protocol-structs
+++ b/src/qemu_protocol-structs
@@ -7,7 +7,7 @@ struct remote_nonnull_domain {
 struct qemu_monitor_command_args {
 remote_nonnull_domain  dom;
 remote_nonnull_string  cmd;
-intflags;
+u_int  flags;
 };
 struct qemu_monitor_command_ret {
 remote_nonnull_string  result;
diff --git a/src/remote/qemu_protocol.x b/src/remote/qemu_protocol.x
index fa453f4..7539e42 100644
--- a/src/remote/qemu_protocol.x
+++ b/src/remote/qemu_protocol.x
@@ -3,7 +3,7 @@
  *   remote_internal driver and libvirtd.  This protocol is
  *   internal and may change at any time.
  *
- * Copyright (C) 2010 Red Hat, Inc.
+ * Copyright (C) 2010-2011 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -30,7 +30,7 @@
 struct qemu_monitor_command_args {
 remote_nonnull_domain dom;
 remote_nonnull_string cmd;
-int flags;
+unsigned int flags;
 };

 struct qemu_monitor_command_ret {
-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCHv2 00/27] flags cleanup

2011-07-08 Thread Eric Blake
Addressing my review comments from round 1, and introducing a few
more goodies along the way.  I've added some syntax checks to
make it easier to stick with this style in the future.

v1 was at https://www.redhat.com/archives/libvir-list/2011-July/msg00264.html,
with patches 1-5 already applied, and patches 6-20 of that series revamped
in this series as 5-19. Patches 1-4 and 20-27 in this series are new.

Eric Blake (27):
  maint: exclude more files from syntax check
  maint: print flags in hex during debug
  build: also check qemu_protocol for on-the-wire stability
  libvirt-qemu: use unsigned flags
  util: reject unknown flags, and prefer unsigned flags
  node_device: reject unknown flags
  storage: reject unknown flags
  esx: reject unknown flags
  libxl: reject unknown flags
  lxc: reject unknown flags
  openvz: reject unknown flags
  phyp: reject unknown flags
  qemu: reject unknown flags
  test: reject unknown flags
  uml: reject unknown flags
  vbox: reject unknown flags
  vmware: reject unknown flags
  xen: reject unknown flags
  xenapi: reject unknown flags
  virsh, daemon: prefer unsigned flags
  node_device: avoid implicit int
  python: prefer unsigned flags
  conf: prefer unsigned flags
  build: don't hand-roll cloexec code
  conf: delete unused flags arguments
  remote: prefer unsigned flags
  build: add syntax check for proper flags use

 cfg.mk|   49 +---
 daemon/remote.c   |2 +-
 python/libvirt-override.c |6 +-
 src/Makefile.am   |   20 +++--
 src/conf/cpu_conf.c   |6 +-
 src/conf/cpu_conf.h   |6 +-
 src/conf/domain_conf.c|   24 ++
 src/conf/node_device_conf.h   |   58 +++---
 src/conf/storage_conf.c   |4 +-
 src/datatypes.h   |4 +-
 src/esx/esx_device_monitor.c  |4 +-
 src/esx/esx_driver.c  |   28 +--
 src/esx/esx_interface_driver.c|4 +-
 src/esx/esx_network_driver.c  |4 +-
 src/esx/esx_nwfilter_driver.c |4 +-
 src/esx/esx_secret_driver.c   |4 +-
 src/esx/esx_storage_driver.c  |4 +-
 src/fdstream.c|   28 +++---
 src/fdstream.h|6 +-
 src/interface/netcf_driver.c  |   16 +++-
 src/libvirt-qemu.c|5 +-
 src/libxl/libxl_driver.c  |   18 +++-
 src/locking/lock_driver_nop.c |   13 ++--
 src/locking/lock_driver_sanlock.c |3 +-
 src/locking/lock_manager.c|   18 +++--
 src/lxc/lxc_container.c   |4 +-
 src/lxc/lxc_driver.c  |   12 ++-
 src/network/bridge_driver.c   |9 ++-
 src/node_device/node_device_driver.c  |   18 +++-
 src/node_device/node_device_hal.c |4 +-
 src/node_device/node_device_udev.c|4 +-
 src/nodeinfo.h|6 +-
 src/nwfilter/nwfilter_driver.c|4 +-
 src/openvz/openvz_driver.c|9 ++-
 src/phyp/phyp_driver.c|   12 ++-
 src/qemu/qemu_domain.c|   21 +++---
 src/qemu/qemu_domain.h|4 +-
 src/qemu/qemu_driver.c|   30 +--
 src/qemu/qemu_migration.c |   32 
 src/qemu/qemu_monitor.c   |   10 +-
 src/qemu_protocol-structs |   14 +++
 src/remote/qemu_protocol.x|4 +-
 src/remote/remote_driver.c|6 +-
 src/rpc/virnetserverclient.c  |2 +-
 src/secret/secret_driver.c|   17 +++-
 src/storage/storage_backend.c |   12 ++-
 src/storage/storage_backend_disk.c|   10 ++-
 src/storage/storage_backend_fs.c  |   26 +--
 src/storage/storage_backend_iscsi.c   |4 +-
 src/storage/storage_backend_logical.c |   18 +++-
 src/storage/storage_driver.c  |   45 --
 src/test/test_driver.c|  144 +---
 src/uml/uml_driver.c  |   33 +++-
 src/util/bridge.c |   19 +---
 src/util/command.c|   18 ++--
 src/util/iohelper.c   |   18 ++--
 src/util/logging.c|   13 +++-
 src/util/logging.h|8 +-
 src/util/util.c   |   14 ++--
 src/vbox/vbox_driver.c|5 +-
 src/vbox/vbox_tmpl.c  |   44 --
 src/vmware/vmware_driver.c|   17 +++-
 src/xen/xen_driver.c  |   12 ++-
 src/xen/xen_hypervisor.c  |8 ++-
 src/xen/xen_inotify.c |4 +-
 src/xen/xend_internal.c   |   23 --
 src/xen/xend_internal.h   |3 +-
 src/xen/xm_internal.c |   11 ++-
 src/xen/xm_internal.h |2 +-
 src/xen/xs_internal.c |   12 ++-
 src/xenapi/xenapi_driver.c|   

[libvirt] [PATCHv2 08/27] esx: reject unknown flags

2011-07-08 Thread Eric Blake
Silently ignored flags get in the way of new features that
use those flags.

* src/esx/esx_device_monitor.c (esxDeviceOpen): Reject unknown
flags.
* src/esx/esx_driver.c (esxOpen, esxDomainReboot)
(esxDomainXMLFromNative, esxDomainXMLToNative)
(esxDomainMigratePrepare, esxDomainMigratePerform)
(esxDomainMigrateFinish): Likewise.
* src/esx/esx_interface_driver.c (esxInterfaceOpen): Likewise.
* src/esx/esx_network_driver.c (esxNetworkOpen): Likewise.
* src/esx/esx_nwfilter_driver.c (esxNWFilterOpen): Likewise.
* src/esx/esx_secret_driver.c (esxSecretOpen): Likewise.
* src/esx/esx_storage_driver.c (esxStorageOpen): Likewise.
---
 src/esx/esx_device_monitor.c   |4 +++-
 src/esx/esx_driver.c   |   28 +---
 src/esx/esx_interface_driver.c |4 +++-
 src/esx/esx_network_driver.c   |4 +++-
 src/esx/esx_nwfilter_driver.c  |4 +++-
 src/esx/esx_secret_driver.c|4 +++-
 src/esx/esx_storage_driver.c   |4 +++-
 7 files changed, 39 insertions(+), 13 deletions(-)

diff --git a/src/esx/esx_device_monitor.c b/src/esx/esx_device_monitor.c
index 51b2413..2eba2b0 100644
--- a/src/esx/esx_device_monitor.c
+++ b/src/esx/esx_device_monitor.c
@@ -42,8 +42,10 @@
 static virDrvOpenStatus
 esxDeviceOpen(virConnectPtr conn,
   virConnectAuthPtr auth ATTRIBUTE_UNUSED,
-  unsigned int flags ATTRIBUTE_UNUSED)
+  unsigned int flags)
 {
+virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
+
 if (conn-driver-no != VIR_DRV_ESX) {
 return VIR_DRV_OPEN_DECLINED;
 }
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index f68ede0..86dc250 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -935,13 +935,15 @@ esxConnectToVCenter(esxPrivate *priv, virConnectAuthPtr 
auth,
  */
 static virDrvOpenStatus
 esxOpen(virConnectPtr conn, virConnectAuthPtr auth,
-unsigned int flags ATTRIBUTE_UNUSED)
+unsigned int flags)
 {
 virDrvOpenStatus result = VIR_DRV_OPEN_ERROR;
 esxPrivate *priv = NULL;
 char *potentialVCenterIpAddress = NULL;
 char vCenterIpAddress[NI_MAXHOST] = ;

+virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
+
 /* Decline if the URI is NULL or the scheme is not one of {vpx|esx|gsx} */
 if (conn-uri == NULL || conn-uri-scheme == NULL ||
 (STRCASENEQ(conn-uri-scheme, vpx) 
@@ -1890,7 +1892,7 @@ esxDomainShutdown(virDomainPtr domain)


 static int
-esxDomainReboot(virDomainPtr domain, unsigned int flags ATTRIBUTE_UNUSED)
+esxDomainReboot(virDomainPtr domain, unsigned int flags)
 {
 int result = -1;
 esxPrivate *priv = domain-conn-privateData;
@@ -1898,6 +1900,8 @@ esxDomainReboot(virDomainPtr domain, unsigned int flags 
ATTRIBUTE_UNUSED)
 esxVI_String *propertyNameList = NULL;
 esxVI_VirtualMachinePowerState powerState;

+virCheckFlags(0, -1);
+
 if (esxVI_EnsureSession(priv-primary)  0) {
 return -1;
 }
@@ -2796,7 +2800,7 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int 
flags)
 static char *
 esxDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat,
const char *nativeConfig,
-   unsigned int flags ATTRIBUTE_UNUSED)
+   unsigned int flags)
 {
 esxPrivate *priv = conn-privateData;
 virVMXContext ctx;
@@ -2804,6 +2808,8 @@ esxDomainXMLFromNative(virConnectPtr conn, const char 
*nativeFormat,
 virDomainDefPtr def = NULL;
 char *xml = NULL;

+virCheckFlags(0, NULL);
+
 if (STRNEQ(nativeFormat, vmware-vmx)) {
 ESX_ERROR(VIR_ERR_INVALID_ARG,
   _(Unsupported config format '%s'), nativeFormat);
@@ -2834,7 +2840,7 @@ esxDomainXMLFromNative(virConnectPtr conn, const char 
*nativeFormat,
 static char *
 esxDomainXMLToNative(virConnectPtr conn, const char *nativeFormat,
  const char *domainXml,
- unsigned int flags ATTRIBUTE_UNUSED)
+ unsigned int flags)
 {
 esxPrivate *priv = conn-privateData;
 int virtualHW_version;
@@ -2843,6 +2849,8 @@ esxDomainXMLToNative(virConnectPtr conn, const char 
*nativeFormat,
 virDomainDefPtr def = NULL;
 char *vmx = NULL;

+virCheckFlags(0, NULL);
+
 if (STRNEQ(nativeFormat, vmware-vmx)) {
 ESX_ERROR(VIR_ERR_INVALID_ARG,
   _(Unsupported config format '%s'), nativeFormat);
@@ -3829,12 +3837,14 @@ esxDomainMigratePrepare(virConnectPtr dconn,
 int *cookielen ATTRIBUTE_UNUSED,
 const char *uri_in ATTRIBUTE_UNUSED,
 char **uri_out,
-unsigned long flags ATTRIBUTE_UNUSED,
+unsigned long flags,
 const char *dname ATTRIBUTE_UNUSED,
 unsigned long resource ATTRIBUTE_UNUSED)
 {
 esxPrivate *priv = dconn-privateData;

+virCheckFlags(0, -1);
+
 if (uri_in == NULL) {
 if (virAsprintf(uri_out, 

[libvirt] [PATCHv2 02/27] maint: print flags in hex during debug

2011-07-08 Thread Eric Blake
Continuation of commit 313ac7fd, and enforce things with a syntax
check.

Technically, virNetServerClientCalculateHandleMode is not printing
a mode_t, but rather a collection of VIR_EVENT_HANDLE_* bits;
however, these bits are  8, so there is no different in the
output, and that was the easiest way to silence the new syntax check.

* cfg.mk (sc_flags_debug): New syntax check.
(exclude_file_name_regexp--sc_flags_debug): Add exemptions.
* src/fdstream.c (virFDStreamOpenFileInternal): Print flags in
hex, mode_t in octal.
* src/libvirt-qemu.c (virDomainQemuMonitorCommand): Likewise.
* src/locking/lock_driver_nop.c (virLockManagerNopInit): Likewise.
* src/locking/lock_driver_sanlock.c (virLockManagerSanlockInit):
Likewise.
* src/locking/lock_manager.c: Likewise.
* src/qemu/qemu_migration.c: Likewise.
* src/qemu/qemu_monitor.c: Likewise.
* src/rpc/virnetserverclient.c
(virNetServerClientCalculateHandleMode): Print mode with %o.
---

v2: new patch, first new syntax check

 cfg.mk|   11 +++
 src/fdstream.c|2 +-
 src/libvirt-qemu.c|5 +++--
 src/locking/lock_driver_nop.c |3 ++-
 src/locking/lock_driver_sanlock.c |3 ++-
 src/locking/lock_manager.c|   11 ++-
 src/qemu/qemu_migration.c |   16 
 src/qemu/qemu_monitor.c   |   10 +-
 src/rpc/virnetserverclient.c  |2 +-
 9 files changed, 39 insertions(+), 24 deletions(-)

diff --git a/cfg.mk b/cfg.mk
index f266bb0..24539b1 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -269,6 +269,15 @@ sc_avoid_write:
halt='consider using safewrite instead of write'\
  $(_sc_search_regexp)

+# In debug statements, print flags as bitmask and mode_t as octal.
+sc_flags_debug:
+   @prohibit='\mode=%[0-9.]*[diux]'   \
+   halt='debug mode_t values with %o'  \
+ $(_sc_search_regexp)
+   @prohibit='\flags=%[0-9.]*l*[diou]'\
+   halt='debug flag values with %x'\
+ $(_sc_search_regexp)
+
 # Avoid functions that can lead to double-close bugs.
 sc_prohibit_close:
@prohibit='([^.]|^)\[fp]?close *\('   \
@@ -623,6 +632,8 @@ exclude_file_name_regexp--sc_avoid_write = \

 exclude_file_name_regexp--sc_bindtextdomain = ^(tests|examples)/

+exclude_file_name_regexp--sc_flags_debug = ^docs/
+
 exclude_file_name_regexp--sc_libvirt_unmarked_diagnostics = \
   ^src/rpc/gendispatch\.pl$$

diff --git a/src/fdstream.c b/src/fdstream.c
index 54f8198..c9fe2f3 100644
--- a/src/fdstream.c
+++ b/src/fdstream.c
@@ -516,7 +516,7 @@ virFDStreamOpenFileInternal(virStreamPtr st,
 int errfd = -1;
 pid_t pid = 0;

-VIR_DEBUG(st=%p path=%s flags=%d offset=%llu length=%llu mode=%d 
delete=%d,
+VIR_DEBUG(st=%p path=%s flags=%x offset=%llu length=%llu mode=%o 
delete=%d,
   st, path, flags, offset, length, mode, delete);

 if (flags  O_CREAT)
diff --git a/src/libvirt-qemu.c b/src/libvirt-qemu.c
index 46727c8..f03f804 100644
--- a/src/libvirt-qemu.c
+++ b/src/libvirt-qemu.c
@@ -2,7 +2,7 @@
  * libvirt-qemu.c: Interfaces for the libvirt library to handle qemu-specific
  * APIs.
  *
- * Copyright (C) 2010 Red Hat, Inc.
+ * Copyright (C) 2010-2011 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -42,7 +42,8 @@ virDomainQemuMonitorCommand(virDomainPtr domain, const char 
*cmd,
 {
 virConnectPtr conn;

-VIR_DEBUG(domain=%p, cmd=%s, result=%p, flags=%u, domain, cmd, result, 
flags);
+VIR_DEBUG(domain=%p, cmd=%s, result=%p, flags=%x,
+  domain, cmd, result, flags);

 virResetLastError();

diff --git a/src/locking/lock_driver_nop.c b/src/locking/lock_driver_nop.c
index 0fab54c..0dcd794 100644
--- a/src/locking/lock_driver_nop.c
+++ b/src/locking/lock_driver_nop.c
@@ -31,7 +31,8 @@ static int virLockManagerNopInit(unsigned int version,
  const char *configFile,
  unsigned int flags)
 {
-VIR_DEBUG(version=%u configFile=%s flags=%u, version, 
NULLSTR(configFile), flags);
+VIR_DEBUG(version=%u configFile=%s flags=%x,
+  version, NULLSTR(configFile), flags);

 return 0;
 }
diff --git a/src/locking/lock_driver_sanlock.c 
b/src/locking/lock_driver_sanlock.c
index cd2bbb5..e6b2f1b 100644
--- a/src/locking/lock_driver_sanlock.c
+++ b/src/locking/lock_driver_sanlock.c
@@ -265,7 +265,8 @@ static int virLockManagerSanlockInit(unsigned int version,
  const char *configFile,
  unsigned int flags)
 {
-VIR_DEBUG(version=%u configFile=%s flags=%u, version, 
NULLSTR(configFile), flags);
+VIR_DEBUG(version=%u configFile=%s flags=%x,
+  version, 

[libvirt] [PATCHv2 07/27] storage: reject unknown flags

2011-07-08 Thread Eric Blake
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(virStorageBackendCreateQemuImg)
(virStorageBackendCreateQcowCreate): Reject unknown flags.
* src/storage/storage_backend_disk.c (virStorageBackendDiskBuildPool)
(virStorageBackendDiskDeleteVol): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemNetFindPoolSources)
(virStorageBackendFileSystemBuild)
(virStorageBackendFileSystemDelete, createFileDir)
(virStorageBackendFileSystemVolBuildFrom)
(virStorageBackendFileSystemVolDelete): Likewise.
* src/storage/storage_backend_iscsi.c
(virStorageBackendISCSIFindPoolSources): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalFindPoolSources)
(virStorageBackendLogicalBuildPool)
(virStorageBackendLogicalDeletePool)
(virStorageBackendLogicalDeleteVol): Likewise.
* src/storage/storage_driver.c (storageOpen, storagePoolCreate)
(storagePoolDefine, storagePoolRefresh, storagePoolGetXMLDesc)
(storageVolumeCreateXML, storageVolumeCreateXMLFrom)
(storageVolumeGetXMLDesc): Likewise.
---
 src/storage/storage_backend.c |   12 ++--
 src/storage/storage_backend_disk.c|   10 +--
 src/storage/storage_backend_fs.c  |   26 ++
 src/storage/storage_backend_iscsi.c   |4 ++-
 src/storage/storage_backend_logical.c |   18 +---
 src/storage/storage_driver.c  |   45 ++--
 6 files changed, 88 insertions(+), 27 deletions(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 671b88e..f632edd 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -233,7 +233,7 @@ virStorageBackendCreateBlockFrom(virConnectPtr conn 
ATTRIBUTE_UNUSED,
  virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
  virStorageVolDefPtr vol,
  virStorageVolDefPtr inputvol,
- unsigned int flags ATTRIBUTE_UNUSED)
+ unsigned int flags)
 {
 int fd = -1;
 int ret = -1;
@@ -242,6 +242,8 @@ virStorageBackendCreateBlockFrom(virConnectPtr conn 
ATTRIBUTE_UNUSED,
 gid_t gid;
 uid_t uid;

+virCheckFlags(0, -1);
+
 if ((fd = open(vol-target.path, O_RDWR))  0) {
 virReportSystemError(errno,
  _(cannot create path '%s'),
@@ -643,7 +645,7 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
virStoragePoolObjPtr pool,
virStorageVolDefPtr vol,
virStorageVolDefPtr inputvol,
-   unsigned int flags ATTRIBUTE_UNUSED)
+   unsigned int flags)
 {
 int ret = -1;
 char *create_tool;
@@ -652,6 +654,8 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
 bool do_encryption = (vol-target.encryption != NULL);
 unsigned long long int size_arg;

+virCheckFlags(0, -1);
+
 const char *type = virStorageFileFormatTypeToString(vol-target.format);
 const char *backingType = vol-backingStore.path ?
 virStorageFileFormatTypeToString(vol-backingStore.format) : NULL;
@@ -847,12 +851,14 @@ virStorageBackendCreateQcowCreate(virConnectPtr conn 
ATTRIBUTE_UNUSED,
   virStoragePoolObjPtr pool,
   virStorageVolDefPtr vol,
   virStorageVolDefPtr inputvol,
-  unsigned int flags ATTRIBUTE_UNUSED)
+  unsigned int flags)
 {
 int ret;
 char *size;
 virCommandPtr cmd;

+virCheckFlags(0, -1);
+
 if (inputvol) {
 virStorageReportError(VIR_ERR_INTERNAL_ERROR, %s,
   _(cannot copy from volume with qcow-create));
diff --git a/src/storage/storage_backend_disk.c 
b/src/storage/storage_backend_disk.c
index 0b10d36..82b41ef 100644
--- a/src/storage/storage_backend_disk.c
+++ b/src/storage/storage_backend_disk.c
@@ -1,7 +1,7 @@
 /*
  * storage_backend_disk.c: storage backend for disk handling
  *
- * Copyright (C) 2007-2008, 2010 Red Hat, Inc.
+ * Copyright (C) 2007-2008, 2010-2011 Red Hat, Inc.
  * Copyright (C) 2007-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -334,7 +334,7 @@ virStorageBackendDiskRefreshPool(virConnectPtr conn 
ATTRIBUTE_UNUSED,
 static int
 virStorageBackendDiskBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool,
-   unsigned int flags ATTRIBUTE_UNUSED)
+   unsigned int flags)
 {
 /* eg parted /dev/sda mklabel msdos */
 const char *prog[] = {
@@ -347,6 +347,8 @@ virStorageBackendDiskBuildPool(virConnectPtr conn 
ATTRIBUTE_UNUSED,
 NULL,
 };

+virCheckFlags(0, -1);
+
 if (virRun(prog, NULL)  0)
 return -1;

@@ 

[libvirt] [PATCHv2 10/27] lxc: reject unknown flags

2011-07-08 Thread Eric Blake
* src/lxc/lxc_driver.c (lxcOpen, lxcDomainSetMemoryParameters)
(lxcDomainGetMemoryParameters): Reject unknown flags.
* src/lxc/lxc_container.c (lxcContainerStart): Use unsigned flags.
---
 src/lxc/lxc_container.c |4 ++--
 src/lxc/lxc_driver.c|   12 +---
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index ef8469c..ffa2f34 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008-2010 Red Hat, Inc.
+ * Copyright (C) 2008-2011 Red Hat, Inc.
  * Copyright (C) 2008 IBM Corp.
  *
  * lxc_container.c: file description
@@ -889,7 +889,7 @@ int lxcContainerStart(virDomainDefPtr def,
   char *ttyPath)
 {
 pid_t pid;
-int flags;
+unsigned int flags;
 int stacksize = getpagesize() * 4;
 char *stack, *stacktop;
 lxc_child_argv_t args = { def, nveths, veths, control, ttyPath,
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 799a5e7..4624e21 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -110,8 +110,10 @@ static void lxcDomainEventQueue(lxc_driver_t *driver,

 static virDrvOpenStatus lxcOpen(virConnectPtr conn,
 virConnectAuthPtr auth ATTRIBUTE_UNUSED,
-unsigned int flags ATTRIBUTE_UNUSED)
+unsigned int flags)
 {
+virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
+
 /* Verify uri was specified */
 if (conn-uri == NULL) {
 if (lxc_driver == NULL)
@@ -746,7 +748,7 @@ cleanup:
 static int lxcDomainSetMemoryParameters(virDomainPtr dom,
 virTypedParameterPtr params,
 int nparams,
-unsigned int flags ATTRIBUTE_UNUSED)
+unsigned int flags)
 {
 lxc_driver_t *driver = dom-conn-privateData;
 int i;
@@ -754,6 +756,8 @@ static int lxcDomainSetMemoryParameters(virDomainPtr dom,
 virDomainObjPtr vm = NULL;
 int ret = -1;

+virCheckFlags(0, -1);
+
 lxcDriverLock(driver);
 vm = virDomainFindByUUID(driver-domains, dom-uuid);

@@ -843,7 +847,7 @@ cleanup:
 static int lxcDomainGetMemoryParameters(virDomainPtr dom,
 virTypedParameterPtr params,
 int *nparams,
-unsigned int flags ATTRIBUTE_UNUSED)
+unsigned int flags)
 {
 lxc_driver_t *driver = dom-conn-privateData;
 int i;
@@ -853,6 +857,8 @@ static int lxcDomainGetMemoryParameters(virDomainPtr dom,
 int ret = -1;
 int rc;

+virCheckFlags(0, -1);
+
 lxcDriverLock(driver);
 vm = virDomainFindByUUID(driver-domains, dom-uuid);

-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCHv2 12/27] phyp: reject unknown flags

2011-07-08 Thread Eric Blake
* src/phyp/phyp_driver.c (phypOpen, phypDomainReboot)
(phypVIOSDriverOpen): Reject unknown flags.
---
 src/phyp/phyp_driver.c |   12 +---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index d1ab5b4..dd5ab85 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -1128,7 +1128,7 @@ exit:

 static virDrvOpenStatus
 phypOpen(virConnectPtr conn,
- virConnectAuthPtr auth, unsigned int flags ATTRIBUTE_UNUSED)
+ virConnectAuthPtr auth, unsigned int flags)
 {
 LIBSSH2_SESSION *session = NULL;
 ConnectionData *connection_data = NULL;
@@ -1138,6 +1138,8 @@ phypOpen(virConnectPtr conn,
 char *char_ptr;
 char *managed_system = NULL;

+virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
+
 if (!conn || !conn-uri)
 return VIR_DRV_OPEN_DECLINED;

@@ -3389,7 +3391,7 @@ cleanup:
 }

 static int
-phypDomainReboot(virDomainPtr dom, unsigned int flags ATTRIBUTE_UNUSED)
+phypDomainReboot(virDomainPtr dom, unsigned int flags)
 {
 int result = -1;
 ConnectionData *connection_data = dom-conn-networkPrivateData;
@@ -3402,6 +3404,8 @@ phypDomainReboot(virDomainPtr dom, unsigned int flags 
ATTRIBUTE_UNUSED)
 char *ret = NULL;
 virBuffer buf = VIR_BUFFER_INITIALIZER;

+virCheckFlags(0, -1);
+
 virBufferAddLit(buf, chsysstate);
 if (system_type == HMC)
 virBufferAsprintf(buf,  -m %s, managed_system);
@@ -3725,8 +3729,10 @@ phypDomainSetCPU(virDomainPtr dom, unsigned int nvcpus)
 static virDrvOpenStatus
 phypVIOSDriverOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
-   unsigned int flags ATTRIBUTE_UNUSED)
+   unsigned int flags)
 {
+virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
+
 if (conn-driver-no != VIR_DRV_PHYP)
 return VIR_DRV_OPEN_DECLINED;

-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCHv2 05/27] util: reject unknown flags, and prefer unsigned flags

2011-07-08 Thread Eric Blake
Silently ignored flags get in the way of new features that
use those flags.  Also, an upcoming syntax check will favor
unsigned flags.

* src/nodeinfo.h (nodeGetCPUStats, nodeGetMemoryStats): Drop
unused attribute.
* src/interface/netcf_driver.c (interfaceOpenInterface)
(interfaceDefineXML, interfaceCreate, interfaceDestroy): Reject
unknown flags.
* src/network/bridge_driver.c (networkOpenNetwork)
(networkGetXMLDesc): Likewise.
* src/nwfilter/nwfilter_driver.c (nwfilterOpen): Likewise.
* src/secret/secret_driver.c (secretOpen, secretDefineXML)
(secretGetXMLDesc, secretSetValue): Likewise.
* src/util/logging.c (virLogDefineFilter, virLogDefineOutput)
(virLogMessage): Likewise; also use unsigned flags.
* src/util/logging.h (virLogDefineFilter, virLogDefineOutput)
(virLogMessage): Change signature.
* src/util/command.c (virExecWithHook): Likewise.
---

v2: rebase, fix driver open bug, and add in a few more instances
(same goes for next 15 or so patches)

 src/interface/netcf_driver.c   |   16 
 src/network/bridge_driver.c|9 +++--
 src/nodeinfo.h |6 +++---
 src/nwfilter/nwfilter_driver.c |4 +++-
 src/secret/secret_driver.c |   17 +
 src/util/command.c |   16 
 src/util/logging.c |   13 ++---
 src/util/logging.h |8 +---
 8 files changed, 61 insertions(+), 28 deletions(-)

diff --git a/src/interface/netcf_driver.c b/src/interface/netcf_driver.c
index 8900722..855b5a3 100644
--- a/src/interface/netcf_driver.c
+++ b/src/interface/netcf_driver.c
@@ -121,10 +121,12 @@ static struct netcf_if *interfaceDriverGetNetcfIF(struct 
netcf *ncf, virInterfac

 static virDrvOpenStatus interfaceOpenInterface(virConnectPtr conn,
virConnectAuthPtr auth 
ATTRIBUTE_UNUSED,
-   unsigned int flags 
ATTRIBUTE_UNUSED)
+   unsigned int flags)
 {
 struct interface_driver *driverState;

+virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
+
 if (VIR_ALLOC(driverState)  0)
 {
 virReportOOMError();
@@ -387,7 +389,7 @@ cleanup:

 static virInterfacePtr interfaceDefineXML(virConnectPtr conn,
   const char *xml,
-  unsigned int flags ATTRIBUTE_UNUSED)
+  unsigned int flags)
 {
 struct interface_driver *driver = conn-interfacePrivateData;
 struct netcf_if *iface = NULL;
@@ -395,6 +397,8 @@ static virInterfacePtr interfaceDefineXML(virConnectPtr 
conn,
 virInterfaceDefPtr ifacedef = NULL;
 virInterfacePtr ret = NULL;

+virCheckFlags(0, NULL);
+
 interfaceDriverLock(driver);

 ifacedef = virInterfaceDefParseString(xml);
@@ -461,12 +465,14 @@ cleanup:
 }

 static int interfaceCreate(virInterfacePtr ifinfo,
-   unsigned int flags ATTRIBUTE_UNUSED)
+   unsigned int flags)
 {
 struct interface_driver *driver = ifinfo-conn-interfacePrivateData;
 struct netcf_if *iface = NULL;
 int ret = -1;

+virCheckFlags(0, -1);
+
 interfaceDriverLock(driver);

 iface = interfaceDriverGetNetcfIF(driver-netcf, ifinfo);
@@ -493,12 +499,14 @@ cleanup:
 }

 static int interfaceDestroy(virInterfacePtr ifinfo,
-unsigned int flags ATTRIBUTE_UNUSED)
+unsigned int flags)
 {
 struct interface_driver *driver = ifinfo-conn-interfacePrivateData;
 struct netcf_if *iface = NULL;
 int ret = -1;

+virCheckFlags(0, -1);
+
 interfaceDriverLock(driver);

 iface = interfaceDriverGetNetcfIF(driver-netcf, ifinfo);
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 554a8ac..0a12bc0 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -2010,7 +2010,10 @@ cleanup:

 static virDrvOpenStatus networkOpenNetwork(virConnectPtr conn,
virConnectAuthPtr auth 
ATTRIBUTE_UNUSED,
-   unsigned int flags 
ATTRIBUTE_UNUSED) {
+   unsigned int flags)
+{
+virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
+
 if (!driverState)
 return VIR_DRV_OPEN_DECLINED;

@@ -2416,12 +2419,14 @@ cleanup:
 }

 static char *networkGetXMLDesc(virNetworkPtr net,
-   unsigned int flags ATTRIBUTE_UNUSED)
+   unsigned int flags)
 {
 struct network_driver *driver = net-conn-networkPrivateData;
 virNetworkObjPtr network;
 char *ret = NULL;

+virCheckFlags(0, NULL);
+
 networkDriverLock(driver);
 network = virNetworkFindByUUID(driver-networks, net-uuid);
 networkDriverUnlock(driver);
diff --git a/src/nodeinfo.h b/src/nodeinfo.h
index 9b2658f..e5ac1e0 100644
--- 

[libvirt] [PATCHv2 17/27] vmware: reject unknown flags

2011-07-08 Thread Eric Blake
* src/vmware/vmware_driver.c (vmwareOpen, vmwareDomainReboot)
(vmwareDomainCreateXML, vmwareDomainCreateWithFlags): Reject
unknown flags.
---
 src/vmware/vmware_driver.c |   17 -
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c
index 3f0cfae..55694ef 100644
--- a/src/vmware/vmware_driver.c
+++ b/src/vmware/vmware_driver.c
@@ -74,11 +74,13 @@ vmwareDataFreeFunc(void *data)
 static virDrvOpenStatus
 vmwareOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
-   unsigned int flags ATTRIBUTE_UNUSED)
+   unsigned int flags)
 {
 struct vmware_driver *driver;
 char * vmrun = NULL;

+virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
+
 if (conn-uri == NULL) {
 /* @TODO accept */
 return VIR_DRV_OPEN_DECLINED;
@@ -446,11 +448,10 @@ vmwareDomainResume(virDomainPtr dom)
 }

 static int
-vmwareDomainReboot(virDomainPtr dom, unsigned int flags ATTRIBUTE_UNUSED)
+vmwareDomainReboot(virDomainPtr dom, unsigned int flags)
 {
 struct vmware_driver *driver = dom-conn-privateData;
 const char * vmxPath = NULL;
-
 virDomainObjPtr vm;
 const char *cmd[] = {
 VMRUN, -T, PROGRAM_SENTINAL,
@@ -458,6 +459,8 @@ vmwareDomainReboot(virDomainPtr dom, unsigned int flags 
ATTRIBUTE_UNUSED)
 };
 int ret = -1;

+virCheckFlags(0, -1);
+
 vmwareDriverLock(driver);
 vm = virDomainFindByUUID(driver-domains, dom-uuid);
 vmwareDriverUnlock(driver);
@@ -492,7 +495,7 @@ vmwareDomainReboot(virDomainPtr dom, unsigned int flags 
ATTRIBUTE_UNUSED)

 static virDomainPtr
 vmwareDomainCreateXML(virConnectPtr conn, const char *xml,
-  unsigned int flags ATTRIBUTE_UNUSED)
+  unsigned int flags)
 {
 struct vmware_driver *driver = conn-privateData;
 virDomainDefPtr vmdef = NULL;
@@ -503,6 +506,8 @@ vmwareDomainCreateXML(virConnectPtr conn, const char *xml,
 vmwareDomainPtr pDomain = NULL;
 virVMXContext ctx;

+virCheckFlags(0, NULL);
+
 ctx.formatFileName = vmwareCopyVMXFileName;

 vmwareDriverLock(driver);
@@ -562,12 +567,14 @@ cleanup:

 static int
 vmwareDomainCreateWithFlags(virDomainPtr dom,
-unsigned int flags ATTRIBUTE_UNUSED)
+unsigned int flags)
 {
 struct vmware_driver *driver = dom-conn-privateData;
 virDomainObjPtr vm;
 int ret = -1;

+virCheckFlags(0, -1);
+
 vmwareDriverLock(driver);
 vm = virDomainFindByUUID(driver-domains, dom-uuid);
 if (!vm) {
-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCHv2 15/27] uml: reject unknown flags

2011-07-08 Thread Eric Blake
* src/uml/uml_driver.c (umlOpen, umlDomainGetXMLDesc)
(umlDomainBlockPeek): Reject unknown flags.
---
 src/uml/uml_driver.c |   14 +++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index 6a396e4..9f66aee 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -946,7 +946,10 @@ static void umlShutdownVMDaemon(virConnectPtr conn 
ATTRIBUTE_UNUSED,

 static virDrvOpenStatus umlOpen(virConnectPtr conn,
 virConnectAuthPtr auth ATTRIBUTE_UNUSED,
-unsigned int flags ATTRIBUTE_UNUSED) {
+unsigned int flags)
+{
+virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
+
 if (conn-uri == NULL) {
 if (uml_driver == NULL)
 return VIR_DRV_OPEN_DECLINED;
@@ -1559,11 +1562,14 @@ cleanup:


 static char *umlDomainGetXMLDesc(virDomainPtr dom,
- unsigned int flags ATTRIBUTE_UNUSED) {
+ unsigned int flags)
+{
 struct uml_driver *driver = dom-conn-privateData;
 virDomainObjPtr vm;
 char *ret = NULL;

+virCheckFlags(0, NULL);
+
 umlDriverLock(driver);
 vm = virDomainFindByUUID(driver-domains, dom-uuid);
 umlDriverUnlock(driver);
@@ -2045,12 +2051,14 @@ umlDomainBlockPeek(virDomainPtr dom,
const char *path,
unsigned long long offset, size_t size,
void *buffer,
-   unsigned int flags ATTRIBUTE_UNUSED)
+   unsigned int flags)
 {
 struct uml_driver *driver = dom-conn-privateData;
 virDomainObjPtr vm;
 int fd = -1, ret = -1, i;

+virCheckFlags(0, -1);
+
 umlDriverLock(driver);
 vm = virDomainFindByUUID(driver-domains, dom-uuid);
 umlDriverUnlock(driver);
-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCHv2 06/27] node_device: reject unknown flags

2011-07-08 Thread Eric Blake
* src/node_device/node_device_driver.c (nodeNumOfDevices)
(nodeListDevices, nodeDeviceGetXMLDesc, nodeDeviceCreateXML):
Reject unknown flags.
* src/node_device/node_device_hal.c (halNodeDrvOpen): Likewise.
* src/node_device/node_device_udev.c (udevNodeDrvOpen): Likewise.
---
 src/node_device/node_device_driver.c |   18 +-
 src/node_device/node_device_hal.c|4 +++-
 src/node_device/node_device_udev.c   |4 +++-
 3 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/src/node_device/node_device_driver.c 
b/src/node_device/node_device_driver.c
index 842f903..681655e 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -1,7 +1,7 @@
 /*
  * node_device.c: node device enumeration
  *
- * Copyright (C) 2010 Red Hat, Inc.
+ * Copyright (C) 2010-2011 Red Hat, Inc.
  * Copyright (C) 2008 Virtual Iron Software, Inc.
  * Copyright (C) 2008 David F. Lively
  *
@@ -125,12 +125,14 @@ void nodeDeviceUnlock(virDeviceMonitorStatePtr driver)
 int
 nodeNumOfDevices(virConnectPtr conn,
  const char *cap,
- unsigned int flags ATTRIBUTE_UNUSED)
+ unsigned int flags)
 {
 virDeviceMonitorStatePtr driver = conn-devMonPrivateData;
 int ndevs = 0;
 unsigned int i;

+virCheckFlags(0, -1);
+
 nodeDeviceLock(driver);
 for (i = 0; i  driver-devs.count; i++) {
 virNodeDeviceObjLock(driver-devs.objs[i]);
@@ -148,12 +150,14 @@ int
 nodeListDevices(virConnectPtr conn,
 const char *cap,
 char **const names, int maxnames,
-unsigned int flags ATTRIBUTE_UNUSED)
+unsigned int flags)
 {
 virDeviceMonitorStatePtr driver = conn-devMonPrivateData;
 int ndevs = 0;
 unsigned int i;

+virCheckFlags(0, -1);
+
 nodeDeviceLock(driver);
 for (i = 0; i  driver-devs.count  ndevs  maxnames; i++) {
 virNodeDeviceObjLock(driver-devs.objs[i]);
@@ -254,12 +258,14 @@ out:

 char *
 nodeDeviceGetXMLDesc(virNodeDevicePtr dev,
- unsigned int flags ATTRIBUTE_UNUSED)
+ unsigned int flags)
 {
 virDeviceMonitorStatePtr driver = dev-conn-devMonPrivateData;
 virNodeDeviceObjPtr obj;
 char *ret = NULL;

+virCheckFlags(0, NULL);
+
 nodeDeviceLock(driver);
 obj = virNodeDeviceFindByName(driver-devs, dev-name);
 nodeDeviceUnlock(driver);
@@ -545,7 +551,7 @@ find_new_device(virConnectPtr conn, const char *wwnn, const 
char *wwpn)
 virNodeDevicePtr
 nodeDeviceCreateXML(virConnectPtr conn,
 const char *xmlDesc,
-unsigned int flags ATTRIBUTE_UNUSED)
+unsigned int flags)
 {
 virDeviceMonitorStatePtr driver = conn-devMonPrivateData;
 virNodeDeviceDefPtr def = NULL;
@@ -553,6 +559,8 @@ nodeDeviceCreateXML(virConnectPtr conn,
 int parent_host = -1;
 virNodeDevicePtr dev = NULL;

+virCheckFlags(0, NULL);
+
 nodeDeviceLock(driver);

 def = virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE);
diff --git a/src/node_device/node_device_hal.c 
b/src/node_device/node_device_hal.c
index d1dedfe..421f5ad 100644
--- a/src/node_device/node_device_hal.c
+++ b/src/node_device/node_device_hal.c
@@ -862,8 +862,10 @@ static int halDeviceMonitorActive(void)

 static virDrvOpenStatus halNodeDrvOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
-   unsigned int flags ATTRIBUTE_UNUSED)
+   unsigned int flags)
 {
+virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
+
 if (driverState == NULL)
 return VIR_DRV_OPEN_DECLINED;

diff --git a/src/node_device/node_device_udev.c 
b/src/node_device/node_device_udev.c
index db26c6b..a6b5b2e 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -1721,8 +1721,10 @@ static int udevDeviceMonitorActive(void)

 static virDrvOpenStatus udevNodeDrvOpen(virConnectPtr conn,
 virConnectAuthPtr auth 
ATTRIBUTE_UNUSED,
-unsigned int flags ATTRIBUTE_UNUSED)
+unsigned int flags)
 {
+virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
+
 if (driverState == NULL) {
 return VIR_DRV_OPEN_DECLINED;
 }
-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCHv2 18/27] xen: reject unknown flags

2011-07-08 Thread Eric Blake
* src/xen/xen_driver.c (xenUnifiedDomainXMLFromNative)
(xenUnifiedDomainXMLToNative, xenUnifiedDomainBlockPeek): Reject
unknown flags.
* src/xen/xen_hypervisor.c (xenHypervisorOpen)
(xenHypervisorGetDomainState): Likewise.
* src/xen/xen_inotify.c (xenInotifyOpen): Likewise.
* src/xen/xs_internal.c (xenStoreOpen, xenStoreDomainGetState)
(xenStoreDomainReboot): Likewise.
* src/xen/xend_internal.c (xenDaemonOpen, xenDaemonDomainReboot)
(xenDaemonDomainCoreDump, xenDaemonDomainGetState)
(xenDaemonDomainMigratePrepare): Likewise.
(xenDaemonDomainGetXMLDesc): Prefer unsigned flags.
* src/xen/xend_internal.h (xenDaemonDomainGetXMLDesc): Likewise.
* src/xen/xm_internal.h (xenXMDomainGetXMLDesc): Likewise.
* src/xen/xm_internal.c (xenXMDomainGetXMLDesc): Likewise.
(xenXMOpen, xenXMDomainGetState): Reject unknown flags.
---
 src/xen/xen_driver.c |   12 +---
 src/xen/xen_hypervisor.c |8 ++--
 src/xen/xen_inotify.c|4 +++-
 src/xen/xend_internal.c  |   23 +--
 src/xen/xend_internal.h  |3 ++-
 src/xen/xm_internal.c|   11 ---
 src/xen/xm_internal.h|2 +-
 src/xen/xs_internal.c|   12 +---
 8 files changed, 55 insertions(+), 20 deletions(-)

diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 0f66395..2cdb6c4 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -1261,7 +1261,7 @@ static char *
 xenUnifiedDomainXMLFromNative(virConnectPtr conn,
   const char *format,
   const char *config,
-  unsigned int flags ATTRIBUTE_UNUSED)
+  unsigned int flags)
 {
 virDomainDefPtr def = NULL;
 char *ret = NULL;
@@ -1271,6 +1271,8 @@ xenUnifiedDomainXMLFromNative(virConnectPtr conn,
 int vncport;
 GET_PRIVATE(conn);

+virCheckFlags(0, NULL);
+
 if (STRNEQ(format, XEN_CONFIG_FORMAT_XM) 
 STRNEQ(format, XEN_CONFIG_FORMAT_SEXPR)) {
 xenUnifiedError(VIR_ERR_INVALID_ARG,
@@ -1311,13 +1313,15 @@ static char *
 xenUnifiedDomainXMLToNative(virConnectPtr conn,
 const char *format,
 const char *xmlData,
-unsigned int flags ATTRIBUTE_UNUSED)
+unsigned int flags)
 {
 virDomainDefPtr def = NULL;
 char *ret = NULL;
 virConfPtr conf = NULL;
 GET_PRIVATE(conn);

+virCheckFlags(0, NULL);
+
 if (STRNEQ(format, XEN_CONFIG_FORMAT_XM) 
 STRNEQ(format, XEN_CONFIG_FORMAT_SEXPR)) {
 xenUnifiedError(VIR_ERR_INVALID_ARG,
@@ -1766,11 +1770,13 @@ xenUnifiedDomainInterfaceStats (virDomainPtr dom, const 
char *path,
 static int
 xenUnifiedDomainBlockPeek (virDomainPtr dom, const char *path,
unsigned long long offset, size_t size,
-   void *buffer, unsigned int flags ATTRIBUTE_UNUSED)
+   void *buffer, unsigned int flags)
 {
 int r;
 GET_PRIVATE (dom-conn);

+virCheckFlags(0, -1);
+
 if (priv-opened[XEN_UNIFIED_XEND_OFFSET]) {
 r = xenDaemonDomainBlockPeek (dom, path, offset, size, buffer);
 if (r != -2) return r;
diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c
index a92b743..543dfb1 100644
--- a/src/xen/xen_hypervisor.c
+++ b/src/xen/xen_hypervisor.c
@@ -2201,11 +2201,13 @@ xenHypervisorInit(void)
 virDrvOpenStatus
 xenHypervisorOpen(virConnectPtr conn,
   virConnectAuthPtr auth ATTRIBUTE_UNUSED,
-  unsigned int flags ATTRIBUTE_UNUSED)
+  unsigned int flags)
 {
 int ret;
 xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn-privateData;

+virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
+
 if (initialized == 0)
 if (xenHypervisorInit() == -1)
 return -1;
@@ -3272,11 +3274,13 @@ int
 xenHypervisorGetDomainState(virDomainPtr domain,
 int *state,
 int *reason,
-unsigned int flags ATTRIBUTE_UNUSED)
+unsigned int flags)
 {
 xenUnifiedPrivatePtr priv = domain-conn-privateData;
 virDomainInfo info;

+virCheckFlags(0, -1);
+
 if (domain-conn == NULL)
 return -1;

diff --git a/src/xen/xen_inotify.c b/src/xen/xen_inotify.c
index 2d7207c..241dbc7 100644
--- a/src/xen/xen_inotify.c
+++ b/src/xen/xen_inotify.c
@@ -383,13 +383,15 @@ cleanup:
 virDrvOpenStatus
 xenInotifyOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
-   unsigned int flags ATTRIBUTE_UNUSED)
+   unsigned int flags)
 {
 DIR *dh;
 struct dirent *ent;
 char *path;
 xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn-privateData;

+virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
+
 if (priv-configDir) {
 priv-useXenConfigCache = 1;
 } else {
diff --git 

[libvirt] [PATCHv2 09/27] libxl: reject unknown flags

2011-07-08 Thread Eric Blake
* src/libxl/libxl_driver.c (libxlOpen, libxlDomainReboot)
(libxlDomainXMLFromNative, libxlDomainXMLToNative)
(libxlDomainCreateWithFlags): Reject unknown flags.
---
 src/libxl/libxl_driver.c |   18 +-
 1 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 586d562..57497cb 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -1059,8 +1059,10 @@ libxlActive(void)
 static virDrvOpenStatus
 libxlOpen(virConnectPtr conn,
   virConnectAuthPtr auth ATTRIBUTE_UNUSED,
-  unsigned int flags ATTRIBUTE_UNUSED)
+  unsigned int flags)
 {
+virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
+
 if (conn-uri == NULL) {
 if (libxl_driver == NULL)
 return VIR_DRV_OPEN_DECLINED;
@@ -1477,13 +1479,15 @@ cleanup:
 }

 static int
-libxlDomainReboot(virDomainPtr dom, unsigned int flags ATTRIBUTE_UNUSED)
+libxlDomainReboot(virDomainPtr dom, unsigned int flags)
 {
 libxlDriverPrivatePtr driver = dom-conn-privateData;
 virDomainObjPtr vm;
 int ret = -1;
 libxlDomainObjPrivatePtr priv;

+virCheckFlags(0, -1);
+
 libxlDriverLock(driver);
 vm = virDomainFindByUUID(driver-domains, dom-uuid);
 if (!vm) {
@@ -2506,7 +2510,7 @@ libxlDomainGetXMLDesc(virDomainPtr dom, unsigned int 
flags)
 static char *
 libxlDomainXMLFromNative(virConnectPtr conn, const char * nativeFormat,
  const char * nativeConfig,
- unsigned int flags ATTRIBUTE_UNUSED)
+ unsigned int flags)
 {
 libxlDriverPrivatePtr driver = conn-privateData;
 const libxl_version_info *ver_info;
@@ -2514,6 +2518,8 @@ libxlDomainXMLFromNative(virConnectPtr conn, const char * 
nativeFormat,
 virConfPtr conf = NULL;
 char *xml = NULL;

+virCheckFlags(0, NULL);
+
 if (STRNEQ(nativeFormat, LIBXL_CONFIG_FORMAT_XM)) {
 libxlError(VIR_ERR_INVALID_ARG,
_(unsupported config type %s), nativeFormat);
@@ -2546,7 +2552,7 @@ cleanup:
 static char *
 libxlDomainXMLToNative(virConnectPtr conn, const char * nativeFormat,
const char * domainXml,
-   unsigned int flags ATTRIBUTE_UNUSED)
+   unsigned int flags)
 {
 libxlDriverPrivatePtr driver = conn-privateData;
 const libxl_version_info *ver_info;
@@ -2555,6 +2561,8 @@ libxlDomainXMLToNative(virConnectPtr conn, const char * 
nativeFormat,
 int len = MAX_CONFIG_SIZE;
 char *ret = NULL;

+virCheckFlags(0, NULL);
+
 if (STRNEQ(nativeFormat, LIBXL_CONFIG_FORMAT_XM)) {
 libxlError(VIR_ERR_INVALID_ARG,
_(unsupported config type %s), nativeFormat);
@@ -2617,7 +2625,7 @@ libxlNumDefinedDomains(virConnectPtr conn)

 static int
 libxlDomainCreateWithFlags(virDomainPtr dom,
-   unsigned int flags ATTRIBUTE_UNUSED)
+   unsigned int flags)
 {
 libxlDriverPrivatePtr driver = dom-conn-privateData;
 virDomainObjPtr vm;
-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCHv2 19/27] xenapi: reject unknown flags

2011-07-08 Thread Eric Blake
* src/xenapi/xenapi_driver.c (xenapiOpen, xenapiDomainReboot)
(xenapiDomainGetXMLDesc): Reject unknown flags.
---
 src/xenapi/xenapi_driver.c |   13 ++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c
index 1c06f75..ba993f2 100644
--- a/src/xenapi/xenapi_driver.c
+++ b/src/xenapi/xenapi_driver.c
@@ -92,12 +92,14 @@ getCapsObject (void)
  */
 static virDrvOpenStatus
 xenapiOpen (virConnectPtr conn, virConnectAuthPtr auth,
-unsigned int flags ATTRIBUTE_UNUSED)
+unsigned int flags)
 {
 char *username = NULL;
 char *password = NULL;
 struct _xenapiPrivate *privP = NULL;

+virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
+
 if (conn-uri == NULL || conn-uri-scheme == NULL ||
 STRCASENEQ(conn-uri-scheme, XenAPI)) {
 return VIR_DRV_OPEN_DECLINED;
@@ -802,12 +804,15 @@ xenapiDomainShutdown (virDomainPtr dom)
  * Returns 0 on success or -1 in case of error
  */
 static int
-xenapiDomainReboot (virDomainPtr dom, unsigned int flags ATTRIBUTE_UNUSED)
+xenapiDomainReboot (virDomainPtr dom, unsigned int flags)
 {
 /* vm.clean_reboot */
 xen_vm vm;
 struct xen_vm_set *vms;
 xen_session *session = ((struct _xenapiPrivate 
*)(dom-conn-privateData))-session;
+
+virCheckFlags(0, -1);
+
 if (xen_vm_get_by_name_label(session, vms, dom-name)  vms-size  0) {
 if (vms-size != 1) {
 xenapiSessionErrorHandler(dom-conn, VIR_ERR_INTERNAL_ERROR,
@@ -1295,7 +1300,7 @@ xenapiDomainGetMaxVcpus (virDomainPtr dom)
  * Returns XML string of the domain configuration on success or -1 in case of 
error
  */
 static char *
-xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags ATTRIBUTE_UNUSED)
+xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
 {
 xen_vm vm=NULL;
 xen_vm_set *vms;
@@ -1309,6 +1314,8 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int 
flags ATTRIBUTE_UNUSED)
 struct xen_vif_set *vif_set = NULL;
 char *xml;

+virCheckFlags(0, NULL);
+
 if (!xen_vm_get_by_name_label(session, vms, dom-name)) return NULL;
 if (vms-size != 1) {
 xenapiSessionErrorHandler(dom-conn, VIR_ERR_INTERNAL_ERROR,
-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCHv2 21/27] node_device: avoid implicit int

2011-07-08 Thread Eric Blake
'unsigned a' and 'unsigned int a' are synonyms, but we generally
always spell out the 'int' in that case.  Fixing this will avoid
a false positive in the next syntax-check commit.

* src/conf/node_device_conf.h (pci_config_address)
(_virNodeDevCapsDef): Prefer 'unsigned int' over 'unsigned'.
---

v2: new patch.
I didn't add a syntax check for implicit int, though, as we have a
lot of other cases of that.  Rather, this was the only hit when
grepping for 'unsigned flags'.

 src/conf/node_device_conf.h |   58 +-
 1 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h
index e90bdc5..cef86d4 100644
--- a/src/conf/node_device_conf.h
+++ b/src/conf/node_device_conf.h
@@ -83,10 +83,10 @@ enum virNodeDevPCICapFlags {
 };

 struct pci_config_address {
-unsigned domain;
-unsigned bus;
-unsigned slot;
-unsigned function;
+unsigned int domain;
+unsigned int bus;
+unsigned int slot;
+unsigned int function;
 };

 typedef struct _virNodeDevCapsDef virNodeDevCapsDef;
@@ -109,55 +109,55 @@ struct _virNodeDevCapsDef {
 } firmware;
 } system;
 struct {
-unsigned domain;
-unsigned bus;
-unsigned slot;
-unsigned function;
-unsigned product;
-unsigned vendor;
-unsigned class;
+unsigned int domain;
+unsigned int bus;
+unsigned int slot;
+unsigned int function;
+unsigned int product;
+unsigned int vendor;
+unsigned int class;
 char *product_name;
 char *vendor_name;
 struct pci_config_address *physical_function;
 struct pci_config_address **virtual_functions;
-unsigned num_virtual_functions;
-unsigned flags;
+unsigned int num_virtual_functions;
+unsigned int flags;
 } pci_dev;
 struct {
-unsigned bus;
-unsigned device;
-unsigned product;
-unsigned vendor;
+unsigned int bus;
+unsigned int device;
+unsigned int product;
+unsigned int vendor;
 char *product_name;
 char *vendor_name;
 } usb_dev;
 struct {
-unsigned number;
-unsigned _class;   /* class is reserved in C */
-unsigned subclass;
-unsigned protocol;
+unsigned int number;
+unsigned int _class;   /* class is reserved in C */
+unsigned int subclass;
+unsigned int protocol;
 char *description;
 } usb_if;
 struct {
 char *address;
-unsigned address_len;
+unsigned int address_len;
 char *ifname;
 enum virNodeDevNetCapType subtype;  /* LAST - no subtype */
 } net;
 struct {
-unsigned host;
+unsigned int host;
 char *wwnn;
 char *wwpn;
-unsigned flags;
+unsigned int flags;
 } scsi_host;
 struct {
 char *name;
 } scsi_target;
 struct {
-unsigned host;
-unsigned bus;
-unsigned target;
-unsigned lun;
+unsigned int host;
+unsigned int bus;
+unsigned int target;
+unsigned int lun;
 char *type;
 } scsi;
 struct {
@@ -172,7 +172,7 @@ struct _virNodeDevCapsDef {
 char *vendor;
 char *serial;
 char *media_label;
-unsigned flags;/* virNodeDevStorageCapFlags bits */
+unsigned int flags;/* virNodeDevStorageCapFlags bits */
 } storage;
 } data;
 virNodeDevCapsDefPtr next;  /* next capability */
-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCHv2 26/27] remote: prefer unsigned flags

2011-07-08 Thread Eric Blake
* src/remote/remote_driver.c (call, remoteOpenSecondaryDriver):
Prefer unsigned flags.
---

v2: new patch

 src/remote/remote_driver.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 8dff6a8..2bfb15b 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -104,7 +104,7 @@ static void remoteDriverUnlock(struct private_data *driver)
 }

 static int call (virConnectPtr conn, struct private_data *priv,
- int flags, int proc_nr,
+ unsigned int flags, int proc_nr,
  xdrproc_t args_filter, char *args,
  xdrproc_t ret_filter, char *ret);
 static int remoteAuthenticate (virConnectPtr conn, struct private_data *priv,
@@ -714,7 +714,7 @@ remoteAllocPrivateData(void)
 static int
 remoteOpenSecondaryDriver(virConnectPtr conn,
   virConnectAuthPtr auth,
-  int flags,
+  unsigned int flags,
   struct private_data **priv)
 {
 int ret;
@@ -3914,7 +3914,7 @@ done:
 static int
 call (virConnectPtr conn ATTRIBUTE_UNUSED,
   struct private_data *priv,
-  int flags,
+  unsigned int flags,
   int proc_nr,
   xdrproc_t args_filter, char *args,
   xdrproc_t ret_filter, char *ret)
-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCHv2 16/27] vbox: reject unknown flags

2011-07-08 Thread Eric Blake
* src/vbox/vbox_driver.c (vboxOpenDummy): Reject unknown flags.
* src/vbox/vbox_tmpl.c (vboxOpen, vboxDomainReboot)
(vboxNetworkOpen, vboxNetworkGetXMLDesc, vboxStorageOpen)
(vboxStorageVolCreateXML, vboxStorageVolDelete)
(vboxStorageVolGetXMLDesc, vboxDomainScreenshot): Likewise.
---
 src/vbox/vbox_driver.c |5 -
 src/vbox/vbox_tmpl.c   |   44 +++-
 2 files changed, 39 insertions(+), 10 deletions(-)

diff --git a/src/vbox/vbox_driver.c b/src/vbox/vbox_driver.c
index b20998a..430ab40 100644
--- a/src/vbox/vbox_driver.c
+++ b/src/vbox/vbox_driver.c
@@ -142,9 +142,12 @@ int vboxRegister(void) {

 static virDrvOpenStatus vboxOpenDummy(virConnectPtr conn,
   virConnectAuthPtr auth ATTRIBUTE_UNUSED,
-  unsigned int flags ATTRIBUTE_UNUSED) {
+  unsigned int flags)
+{
 uid_t uid = getuid();

+virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
+
 if (conn-uri == NULL ||
 conn-uri-scheme == NULL ||
 STRNEQ (conn-uri-scheme, vbox) ||
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 4a0858f..6bf0950 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -961,10 +961,13 @@ static void vboxUninitialize(vboxGlobalData *data) {

 static virDrvOpenStatus vboxOpen(virConnectPtr conn,
  virConnectAuthPtr auth ATTRIBUTE_UNUSED,
- unsigned int flags ATTRIBUTE_UNUSED) {
+ unsigned int flags)
+{
 vboxGlobalData *data = NULL;
 uid_t uid = getuid();

+virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
+
 if (conn-uri == NULL) {
 conn-uri = xmlParseURI(uid ? vbox:///session : vbox:///system);
 if (conn-uri == NULL) {
@@ -1637,7 +1640,8 @@ cleanup:
 return ret;
 }

-static int vboxDomainReboot(virDomainPtr dom, unsigned int flags 
ATTRIBUTE_UNUSED) {
+static int vboxDomainReboot(virDomainPtr dom, unsigned int flags)
+{
 VBOX_OBJECT_CHECK(dom-conn, int, -1);
 IMachine *machine= NULL;
 vboxIID iid = VBOX_IID_INITIALIZER;
@@ -1646,6 +1650,8 @@ static int vboxDomainReboot(virDomainPtr dom, unsigned 
int flags ATTRIBUTE_UNUSE
 PRBool isAccessible  = PR_FALSE;
 nsresult rc;

+virCheckFlags(0, -1);
+
 vboxIIDFromUUID(iid, dom-uuid);
 rc = VBOX_OBJECT_GET_MACHINE(iid.value, machine);
 if (NS_FAILED(rc)) {
@@ -6938,9 +6944,12 @@ static int vboxDomainEventDeregisterAny(virConnectPtr 
conn,
  */
 static virDrvOpenStatus vboxNetworkOpen(virConnectPtr conn,
 virConnectAuthPtr auth 
ATTRIBUTE_UNUSED,
-unsigned int flags ATTRIBUTE_UNUSED) {
+unsigned int flags)
+{
 vboxGlobalData *data = conn-privateData;

+virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
+
 if (STRNEQ(conn-driver-name, VBOX))
 goto cleanup;

@@ -7575,7 +7584,8 @@ static int vboxNetworkDestroy(virNetworkPtr network) {
 }

 static char *vboxNetworkGetXMLDesc(virNetworkPtr network,
-   unsigned int flags ATTRIBUTE_UNUSED) {
+   unsigned int flags)
+{
 VBOX_OBJECT_HOST_CHECK(network-conn, char *, NULL);
 virNetworkDefPtr def  = NULL;
 virNetworkIpDefPtr ipdef = NULL;
@@ -7583,6 +7593,8 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network,
 PRUnichar *networkInterfaceNameUtf16= NULL;
 IHostNetworkInterface *networkInterface = NULL;

+virCheckFlags(0, NULL);
+
 if (VIR_ALLOC(def)  0) {
 virReportOOMError();
 goto cleanup;
@@ -7750,9 +7762,12 @@ cleanup:

 static virDrvOpenStatus vboxStorageOpen (virConnectPtr conn,
  virConnectAuthPtr auth 
ATTRIBUTE_UNUSED,
- unsigned int flags ATTRIBUTE_UNUSED) {
+ unsigned int flags)
+{
 vboxGlobalData *data = conn-privateData;

+virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
+
 if (STRNEQ(conn-driver-name, VBOX))
 goto cleanup;

@@ -8098,7 +8113,8 @@ static virStorageVolPtr 
vboxStorageVolLookupByPath(virConnectPtr conn, const cha

 static virStorageVolPtr vboxStorageVolCreateXML(virStoragePoolPtr pool,
 const char *xml,
-unsigned int flags 
ATTRIBUTE_UNUSED) {
+unsigned int flags)
+{
 VBOX_OBJECT_CHECK(pool-conn, virStorageVolPtr, NULL);
 virStorageVolDefPtr  def  = NULL;
 PRUnichar *hddFormatUtf16 = NULL;
@@ -8106,6 +8122,8 @@ static virStorageVolPtr 
vboxStorageVolCreateXML(virStoragePoolPtr pool,
 virStoragePoolDef poolDef;
 nsresult rc;

+virCheckFlags(0, NULL);
+
 /* since there is currently one default 

[libvirt] [PATCHv2 20/27] virsh, daemon: prefer unsigned flags

2011-07-08 Thread Eric Blake
* tools/virsh.c (vshCmdDef): Change flags type.
* daemon/remote.c (remoteDispatchOpen): Likewise.
---

v2: new patch

 daemon/remote.c |2 +-
 tools/virsh.c   |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index a2e79ef..1ade187 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -442,7 +442,7 @@ remoteDispatchOpen(virNetServerPtr server ATTRIBUTE_UNUSED,
struct remote_open_args *args)
 {
 const char *name;
-int flags;
+unsigned int flags;
 struct daemonClientPrivate *priv = 
virNetServerClientGetPrivateData(client);
 int rv = -1;

diff --git a/tools/virsh.c b/tools/virsh.c
index 3cdf043..9c375a4 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -201,7 +201,7 @@ typedef struct {
 bool (*handler) (vshControl *, const vshCmd *);/* command handler */
 const vshCmdOptDef *opts;   /* definition of command options */
 const vshCmdInfo *info; /* details about command */
-int flags;  /* bitwise OR of VSH_CMD_FLAG */
+unsigned int flags; /* bitwise OR of VSH_CMD_FLAG */
 } vshCmdDef;

 /*
-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCHv2 24/27] build: don't hand-roll cloexec code

2011-07-08 Thread Eric Blake
No need to repeat common code.

* src/util/bridge.c (brInit): Use virSetCloseExec.
(brSetInterfaceUp): Prefer unsigned flags.
* src/uml/uml_driver.c (umlSetCloseExec): Delete.
(umlStartVMDaemon): Use util version instead.
---

v2: new patch

 src/uml/uml_driver.c |   19 +++
 src/util/bridge.c|   19 +--
 2 files changed, 8 insertions(+), 30 deletions(-)

diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index 9f66aee..801015a 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -113,19 +113,6 @@ static int umlOpenMonitor(struct uml_driver *driver,
 static int umlReadPidFile(struct uml_driver *driver,
   virDomainObjPtr vm);

-static int umlSetCloseExec(int fd) {
-int flags;
-if ((flags = fcntl(fd, F_GETFD))  0)
-goto error;
-flags |= FD_CLOEXEC;
-if ((fcntl(fd, F_SETFD, flags))  0)
-goto error;
-return 0;
- error:
-VIR_ERROR(_(Failed to set close-on-exec file descriptor flag));
-return -1;
-}
-
 static int umlStartVMDaemon(virConnectPtr conn,
 struct uml_driver *driver,
 virDomainObjPtr vm);
@@ -862,9 +849,9 @@ static int umlStartVMDaemon(virConnectPtr conn,
 }
 VIR_FREE(logfile);

-if (umlSetCloseExec(logfd)  0) {
-virReportSystemError(errno,
- %s, _(Unable to set VM logfile close-on-exec 
flag));
+if (virSetCloseExec(logfd)  0) {
+virReportSystemError(errno, %s,
+ _(Unable to set VM logfile close-on-exec flag));
 VIR_FORCE_CLOSE(logfd);
 return -1;
 }
diff --git a/src/util/bridge.c b/src/util/bridge.c
index 7204e64..a6b5768 100644
--- a/src/util/bridge.c
+++ b/src/util/bridge.c
@@ -72,25 +72,16 @@ int
 brInit(brControl **ctlp)
 {
 int fd;
-int flags;

 if (!ctlp || *ctlp)
 return EINVAL;

 fd = socket(AF_INET, SOCK_STREAM, 0);
-if (fd  0)
-return errno;
-
-if ((flags = fcntl(fd, F_GETFD))  0 ||
-fcntl(fd, F_SETFD, flags | FD_CLOEXEC)  0) {
-int err = errno;
-VIR_FORCE_CLOSE(fd);
-return err;
-}
-
-if (VIR_ALLOC(*ctlp)  0) {
+if (fd  0 ||
+virSetCloseExec(fd)  0 ||
+VIR_ALLOC(*ctlp)  0) {
 VIR_FORCE_CLOSE(fd);
-return ENOMEM;
+return errno;
 }

 (*ctlp)-fd = fd;
@@ -599,7 +590,7 @@ brSetInterfaceUp(brControl *ctl,
  int up)
 {
 struct ifreq ifr;
-int flags;
+unsigned int flags;

 if (!ctl || !ifname)
 return EINVAL;
-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCHv2 25/27] conf: delete unused flags arguments

2011-07-08 Thread Eric Blake
For static functions not used as callbacks, there's no need to
keep an unused parameter.

* src/conf/domain_conf.c (virDomainChrDefParseTargetXML)
(virDomainTimerDefParseXML, virDomainHostdevSubsysUsbDefParseXML)
(virDomainVcpuPinDefParseXML): Drop unused parameter.
(virDomainChrDefParseXML, virDomainDefParseXML)
(virDomainHostdevDefParseXML): Update callers.
(virDomainNetDefParseXML): Mark flags used.
---

v2: new patch

 src/conf/domain_conf.c |   24 +---
 1 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a680b11..6f20060 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2727,7 +2727,7 @@ virDomainNetDefParseXML(virCapsPtr caps,
 xmlNodePtr node,
 xmlXPathContextPtr ctxt,
 virBitmapPtr bootMap,
-unsigned int flags ATTRIBUTE_UNUSED)
+unsigned int flags)
 {
 virDomainNetDefPtr def;
 xmlNodePtr cur;
@@ -3179,8 +3179,7 @@ out:
 static int
 virDomainChrDefParseTargetXML(virCapsPtr caps,
   virDomainChrDefPtr def,
-  xmlNodePtr cur,
-  unsigned int flags ATTRIBUTE_UNUSED)
+  xmlNodePtr cur)
 {
 int ret = -1;
 unsigned int port;
@@ -3562,8 +3561,7 @@ virDomainChrDefParseXML(virCapsPtr caps,
 while (cur != NULL) {
 if (cur-type == XML_ELEMENT_NODE) {
 if (xmlStrEqual(cur-name, BAD_CAST target)) {
-if (virDomainChrDefParseTargetXML(caps, def, cur,
-  flags)  0) {
+if (virDomainChrDefParseTargetXML(caps, def, cur)  0) {
 goto error;
 }
 }
@@ -3819,8 +3817,7 @@ error:
 /* Parse the XML definition for a clock timer */
 static virDomainTimerDefPtr
 virDomainTimerDefParseXML(const xmlNodePtr node,
-  xmlXPathContextPtr ctxt,
-  unsigned int flags ATTRIBUTE_UNUSED)
+  xmlXPathContextPtr ctxt)
 {
 char *name = NULL;
 char *present = NULL;
@@ -4791,8 +4788,7 @@ error:

 static int
 virDomainHostdevSubsysUsbDefParseXML(const xmlNodePtr node,
- virDomainHostdevDefPtr def,
- unsigned int flags ATTRIBUTE_UNUSED)
+ virDomainHostdevDefPtr def)
 {

 int ret = -1;
@@ -5012,7 +5008,7 @@ virDomainHostdevDefParseXML(const xmlNodePtr node,
 if (xmlStrEqual(cur-name, BAD_CAST source)) {
 if (def-mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS 
 def-source.subsys.type == 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) {
-if (virDomainHostdevSubsysUsbDefParseXML(cur, def, 
flags)  0)
+if (virDomainHostdevSubsysUsbDefParseXML(cur, def)  0)
 goto error;
 }
 if (def-mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS 
@@ -5730,8 +5726,7 @@ cleanup:
 static virDomainVcpuPinDefPtr
 virDomainVcpuPinDefParseXML(const xmlNodePtr node,
 xmlXPathContextPtr ctxt,
-int maxvcpus,
-unsigned int flags ATTRIBUTE_UNUSED)
+int maxvcpus)
 {
 virDomainVcpuPinDefPtr def;
 xmlNodePtr oldnode = ctxt-node;
@@ -5976,7 +5971,7 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr 
caps,

 for (i = 0 ; i  n ; i++) {
 virDomainVcpuPinDefPtr vcpupin = NULL;
-vcpupin = virDomainVcpuPinDefParseXML(nodes[i], ctxt, def-maxvcpus, 
0);
+vcpupin = virDomainVcpuPinDefParseXML(nodes[i], ctxt, def-maxvcpus);

 if (!vcpupin)
 goto error;
@@ -6106,8 +6101,7 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr 
caps,
 goto no_memory;
 for (i = 0 ; i  n ; i++) {
 virDomainTimerDefPtr timer = virDomainTimerDefParseXML(nodes[i],
-   ctxt,
-   flags);
+   ctxt);
 if (!timer)
 goto error;

-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCHv2 27/27] build: add syntax check for proper flags use

2011-07-08 Thread Eric Blake
Enforce the recent flags cleanups - we want to use 'unsigned int flags'
in any of our APIs (except where backwards compatibility is important,
in the public migration APIs), and that all flags are checked for
validity (except when there are stub functions that completely
ignore the flags argument).

There are a few minor tweaks done here to avoid false positives:
signed arguments passed to open() are renamed oflags, and flags
arguments that are legitimately ignored are renamed flags_unused.

* cfg.mk (sc_flags_usage): New rule.
(exclude_file_name_regexp--sc_flags_usage): And a few exemptions.
* src/util/iohelper.c (runIO, main): Rename variable.
* src/util/util.c (virSetInherit): Likewise.
* src/fdstream.h (virFDStreamOpenFile, virFDStreamCreateFile):
Likewise.
* src/fdstream.c (virFDStreamOpenFileInternal)
(virFDStreamOpenFile, virFDStreamCreateFile): Likewise.
* src/util/command.c (virExecWithHook) [WIN32]: Likewise.
* src/util/util.c (virFileOpenAs, virDirCreate) [WIN32]: Likewise.
* src/locking/lock_manager.c (virLockManagerPluginNew)
[!HAVE_DLFCN_H]: Likewise.
* src/locking/lock_driver_nop.c (virLockManagerNopNew)
(virLockManagerNopAddResource, virLockManagerNopAcquire)
(virLockManagerNopRelease, virLockManagerNopInquire): Likewise.
---
 cfg.mk|   21 -
 src/fdstream.c|   28 ++--
 src/fdstream.h|6 +++---
 src/locking/lock_driver_nop.c |   10 +-
 src/locking/lock_manager.c|7 ---
 src/util/command.c|2 +-
 src/util/iohelper.c   |   18 +-
 src/util/util.c   |   14 +++---
 8 files changed, 63 insertions(+), 43 deletions(-)

diff --git a/cfg.mk b/cfg.mk
index 24539b1..a9ee9ea 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -278,6 +278,25 @@ sc_flags_debug:
halt='debug flag values with %x'\
  $(_sc_search_regexp)

+# Prefer 'unsigned int flags', along with checks for unknown flags.
+# For historical reasons, we are stuck with 'unsigned long flags' in
+# migration and in a few other places.
+# Three tests in this check: a fixed number of non-int flags in public
+# API, no flags marked unused, and 'unsigned' should appear before any
+# declaration of a flags variable (hence the prohibit line of [^d]).
+# The existence of long long makes the third test slightly harder.
+sc_flags_usage:
+   @test $$(grep -c 'long flags'  \
+ $(srcdir)/include/libvirt/libvirt.h.in) != 4   \
+ { echo '$(ME): new API should use unsigned int flags' 12; \
+   exit 1; } || :
+   @prohibit=' flags ''ATTRIBUTE_UNUSED'   \
+   halt='flags should be checked with virCheckFlags'   \
+ $(_sc_search_regexp)
+   @prohibit='^[^@]*([^d] (int|long long)|[^dg] long) flags[;,)]'  \
+   halt='flags should be unsigned' \
+ $(_sc_search_regexp)
+
 # Avoid functions that can lead to double-close bugs.
 sc_prohibit_close:
@prohibit='([^.]|^)\[fp]?close *\('   \
@@ -632,7 +651,7 @@ exclude_file_name_regexp--sc_avoid_write = \

 exclude_file_name_regexp--sc_bindtextdomain = ^(tests|examples)/

-exclude_file_name_regexp--sc_flags_debug = ^docs/
+exclude_file_name_regexp--sc_flags_usage = ^docs/

 exclude_file_name_regexp--sc_libvirt_unmarked_diagnostics = \
   ^src/rpc/gendispatch\.pl$$
diff --git a/src/fdstream.c b/src/fdstream.c
index c9fe2f3..73545c7 100644
--- a/src/fdstream.c
+++ b/src/fdstream.c
@@ -505,7 +505,7 @@ virFDStreamOpenFileInternal(virStreamPtr st,
 const char *path,
 unsigned long long offset,
 unsigned long long length,
-int flags,
+int oflags,
 int mode,
 bool delete)
 {
@@ -516,13 +516,13 @@ virFDStreamOpenFileInternal(virStreamPtr st,
 int errfd = -1;
 pid_t pid = 0;

-VIR_DEBUG(st=%p path=%s flags=%x offset=%llu length=%llu mode=%o 
delete=%d,
-  st, path, flags, offset, length, mode, delete);
+VIR_DEBUG(st=%p path=%s oflags=%x offset=%llu length=%llu mode=%o 
delete=%d,
+  st, path, oflags, offset, length, mode, delete);

-if (flags  O_CREAT)
-fd = open(path, flags, mode);
+if (oflags  O_CREAT)
+fd = open(path, oflags, mode);
 else
-fd = open(path, flags);
+fd = open(path, oflags);
 if (fd  0) {
 virReportSystemError(errno,
  _(Unable to open stream for '%s'),
@@ -547,7 +547,7 @@ virFDStreamOpenFileInternal(virStreamPtr st,
  !S_ISFIFO(sb.st_mode))) {
 int childfd;

-if ((flags  O_RDWR) == O_RDWR) {
+if ((oflags  O_RDWR) == O_RDWR) {
 

Re: [libvirt] [PATCH 07/10] network: new XML to support virtual switch functionality

2011-07-08 Thread Eric Blake
On 07/05/2011 01:45 AM, Laine Stump wrote:
 This implements the changes to network and domain interface XML that
 were earlier specified in the RNG.
 
 +++ b/include/libvirt/libvirt.h.in
 @@ -1112,6 +1112,8 @@ typedef enum {
  VIR_DOMAIN_XML_SECURE   = (1  0), /* dump security sensitive 
 information too */
  VIR_DOMAIN_XML_INACTIVE = (1  1), /* dump inactive domain 
 information */
  VIR_DOMAIN_XML_UPDATE_CPU   = (1  2), /* update guest CPU requirements 
 according to host CPU */
 +VIR_DOMAIN_XML_RESERVED1= (1  30), /* reserved for internal used */
 +VIR_DOMAIN_XML_RESERVED2= (1  31), /* reserved for internal used */

If we keep this, then s/used/use/

However, I agree with Dan that we don't want to list this in the public
header.  And even if you can convince me that we need to consume bits
from the public flags, I don't see any code in either daemon/remote.c or
src/libvirt.c that explicitly rejects any attempts to invoke an API with
one of these reserved bits set (that is, if you do merge the internal
flags onto a public field, then you had better make sure that no one
externally can abuse those flags; whereas if you use a second
internalFlags or bool arguments, you have isolated internal flags to be
completely independent of the public API).

 +
 +type = virXMLPropString(node, type);
 +if (!type) {
 +virDomainReportError(VIR_ERR_INTERNAL_ERROR, %s,
 + _(missing type attribute in interface's 
 actual element));
 +goto error;
 +}
 +if ((int)((*actual)-type = virDomainNetTypeFromString(type))  0) {

Why is this cast needed?  Oh, because struct _virDomainNetDef used 'enum
virDomainNetType type;' instead of the more typical 'int type; /* enum
virDomainNetType */'

 +virDomainReportError(VIR_ERR_INTERNAL_ERROR,
 + _(unknown type '%s' in interface's actual 
 element), type);
 +goto error;
 +}
 +if ((*actual)-type != VIR_DOMAIN_NET_TYPE_BRIDGE 
 +(*actual)-type != VIR_DOMAIN_NET_TYPE_DIRECT) {

This is a lot of dereferencing through *actual.  It might be easier to
delay the dereferencing to the very end, by writing:

static int
virDomainActualNetDefParseXML(xmlNodePtr node,
  xmlXPathContextPtr ctxt,
  virDomainActualNetDefPtr *actual)
{
virDomainActualNetDefPtr def = NULL;

if (VIR_ALLOC(def)  0) {
virReportOOMError();
goto cleanup;
}

...
if (def-type != VIR_DOMAIN_NET_TYPE_BRIDGE  

cleanup:
...
if (ret  0) {
virDomainActualNetDefPtrFree(def);
def = NULL;
}
*actual = def;
return ret;
}

 +
 +if ((*actual)-type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
 +
 +(*actual)-data.bridge.brname = 
 virXPathString(string(./source[1]/@bridge),
 +   ctxt);
 +
 +} else if ((*actual)-type == VIR_DOMAIN_NET_TYPE_DIRECT) {

Nit: those two blank lines don't quite match style elsewhere in the file.

 @@ -9871,7 +10063,9 @@ int virDomainSaveStatus(virCapsPtr caps,
  const char *statusDir,
  virDomainObjPtr obj)
  {
 -int flags = VIR_DOMAIN_XML_SECURE|VIR_DOMAIN_XML_INTERNAL_STATUS;
 +int flags = VIR_DOMAIN_XML_SECURE |
 +   VIR_DOMAIN_XML_INTERNAL_STATUS |
 +   VIR_DOMAIN_XML_ACTUAL_NET;

This indentation looks unusual (7 spaces, but no prior hanging '(' to be
flush with).  I tend to write expressions like this as:

int flags = (VIR_DOMAIN_XML_SECURE |
 VIR_DOMAIN_XML_INTERNAL_STATUS |
 VIR_DOMAIN_XML_ACTUAL_NET);

Also, there may be some merge conflicts if my patch series for cleaning
up flags usage goes in first.

 +++ b/src/conf/domain_conf.h
 @@ -1,3 +1,4 @@
 +
  /*

Why the spurious addition of a blank leading line?

 +case VIR_NETWORK_FORWARD_PASSTHROUGH:
 +if (def-bridge) {
 +virNetworkReportError(VIR_ERR_XML_ERROR,
 +  _(bridge name not allowed in %s mode 
 (network '%s'),
 +  
 virNetworkForwardTypeToString(def-forwardType),
 +  def-name);
 +goto error;
 +}
 +/* Fall through to next case */

I'm not sure whether Coverity will recognize that spelling, so here's
hoping.  A quick 'git grep -iC2 fall.\\?thr' found existing spellings
that Coverity appears to honor:

/* fallthrough */
/* fall through */
/* Fallthrough */

but I'd have to actually check Coverity source to see what the canonical
list is.

 +/* Duplicate the first interface from the pool into forward
 + * dev=xxx for convenience.

Missing the paired  in the comment.

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--

Re: [libvirt] [PATCH 09/10] qemu: use virDomainNetGetActual*() functions where appropriate

2011-07-08 Thread Eric Blake
On 07/05/2011 01:45 AM, Laine Stump wrote:
 The qemu driver accesses fields in the virDomainNetDef directly, but
 with the advent of the virDomainActualNetDef, some pieces of
 information may be found in a different place (the ActualNetDef) if
 the network connection is of type='network' and that network is of
 forward type='bridge|private|vepa|passthrough'. The previous patch
 added functions to mask this difference from callers - they hide the
 decision making process and just pick the value from the proper place.
 
 This patch uses those functions in the qemu driver as a first step in
 making qemu work with the new network types. At this point, it's
 assumed that the virDomainActualNetDef is already properly initialized
 (it isn't yet).

Is this going to bite anyone during bisection of this patch series?
Hopefully not, so I'm not sure how much you want to rework this while
rebasing, which means you can probably keep the code as-is.  But my
approach would have been:

patch 1 - introduce wrapper functions that make no semantic change,
while updating all callers to use wrapper functions.  Something like:

int
virDomainNetGetActualType(virDomainNetDefPtr iface)
{
return iface-type;
}

and replace all uses of iface-type with virDomainNetGetActualType().


patch 2 - enhance wrapper functions to actually look into
virDomainActualNetDef, preferably while guaranteeing that it is
initialized correctly

at this stage, you fix the body of virDomainNetGetActualType to:

if (iface-type != VIR_DOMAIN_NET_TYPE_NETWORK ||
!iface-data.network.actual)
return iface-type;
return iface-data.network.actual-type;

 +++ b/src/qemu/qemu_driver.c
 @@ -3935,9 +3935,35 @@ static char *qemuDomainXMLToNative(virConnectPtr conn,
  for (i = 0 ; i  def-nnets ; i++) {
  virDomainNetDefPtr net = def-nets[i];
  int bootIndex = net-bootIndex;
 -if (net-type == VIR_DOMAIN_NET_TYPE_NETWORK ||
 -net-type == VIR_DOMAIN_NET_TYPE_DIRECT) {
 +if (net-type == VIR_DOMAIN_NET_TYPE_NETWORK) {
 +int actualType = virDomainNetGetActualType(net);
  VIR_FREE(net-data.network.name);
 +VIR_FREE(net-data.network.portgroup);
 +if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) {

And here is an instance where you are refactoring existing code
(converting net-type to virDomainNetGetActualType(net)) as well as
adding new code (taking action if actualType is TYPE_BRIDGE).
Separating the refactoring from the introduction of new features can
make review a bit easier.

 +char *brname = strdup(virDomainNetGetActualBridgeName(net));
 +virDomainActualNetDefFree(net-data.network.actual);
 +
 +memset(net, 0, sizeof *net);
 +
 +net-type = VIR_DOMAIN_NET_TYPE_ETHERNET;
 +net-data.ethernet.dev = brname;

Need to check for strdup failure, rather than setting dev to NULL.

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 10/10] network: internal API functions to manage assignment of physdev to guest

2011-07-08 Thread Eric Blake
On 07/05/2011 01:45 AM, Laine Stump wrote:
 The network driver needs to assign physical devices for use by modes
 that use macvtap, keeping track of which physical devices are in use
 (and how many instances, when the devices can be shared). Three calls
 are added:
 
 networkAllocateActualDevice - finds a physical device for use by the
 domain, and sets up the virDomainActualNetDef accordingly.
 
 networkNotifyActualDevice - assumes that the domain was already
 running, but libvirtd was restarted, and needs to be notified by each
 already-running domain about what interfaces they are using.
 
 networkReleaseActualDevice - decrements the usage count of the
 allocated physical device, and frees the virDomainActualNetDef to
 avoid later accidentally using the device.
 
 bridge_driver.[hc] - the new APIs
 
 qemu_(command|driver|hotplug|process).c - add calls to the above APIs
 in the appropriate places.
 
 tests/Makefile.am - need to include libvirt_driver_network.la whenever
 libvirt_driver_qemu.la is linked, to avoid unreferenced symbols
 (in functions that are never called by the test programs...)
 ---
  src/network/bridge_driver.c |  398 
 +++
  src/network/bridge_driver.h |6 +
  src/qemu/qemu_command.c |   11 ++
  src/qemu/qemu_hotplug.c |   41 +++--
  src/qemu/qemu_process.c |   26 +++-
  tests/Makefile.am   |   12 +-
  6 files changed, 476 insertions(+), 18 deletions(-)

 +
 +/* Find the most specific virtportprofile and copy it */
 +if (iface-data.network.virtPortProfile) {
 +virtport = iface-data.network.virtPortProfile;
 +} else {
 +virPortGroupDefPtr portgroup
 +   = virPortGroupFindByName(netdef, 
 iface-data.network.portgroup);
 +if (portgroup)
 +virtport = portgroup-virtPortProfile;

Nit: Indentation looks interesting there - the line starting with = has
one less space.  Perhaps something to do with how your preferred editor
splits assignments.  My editor uses 4 spaces instead of 3 in that instance.

 +if (!netdef-forwardDev) {
 +networkReportError(VIR_ERR_INTERNAL_ERROR,
 +   _(network '%s' uses a direct mode, but 
 has no forward dev and no interface pool),
 +   netdef-name);
 +goto cleanup;
 +}
 +iface-data.network.actual-data.direct.linkdev
 += strdup(netdef-forwardDev);

And here you used a multiple of four spaces.

 +int
 +networkNotifyActualDevice(virDomainNetDefPtr iface)
 +{

 +
 +/* PASSTHROUGH mode, and PRIVATE Mode + 802.1Qbh both require
 + * exclusive access to a device, so current usageCount must be
 + * 0 in those cases.
 + */
 +if ((dev-usageCount  0) 
 +((netdef-forwardType == VIR_NETWORK_FORWARD_PASSTHROUGH) ||
 + ((netdef-forwardType == VIR_NETWORK_FORWARD_PRIVATE) 
 +  iface-data.network.actual-data.direct.virtPortProfile 
 +  
 (iface-data.network.actual-data.direct.virtPortProfile-virtPortType
 +   == VIR_VIRTUALPORT_8021QBH {
 +networkReportError(VIR_ERR_INTERNAL_ERROR,
 +   _(network '%s' claims dev='%s' is already in 
 use by a different domain),

Do we have a data race here?

Suppose that libvirtd is restarted while one VM is already using device
0.  Is there any chance that if I'm fast enough, I can cause the
creation of a second domain, and that second domain will go to pick from
the interface pool before the notification pass of the libvirtd restart
has completed, and mistakenly claim device 0?

That is, I think we need to somehow guarantee (if we don't already) that
no new domains can be created until after all existing domains have been
reloaded on a libvirtd restart.

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH v3] bios: Add support for SGA

2011-07-08 Thread Eric Blake
On 07/08/2011 07:48 AM, Michal Privoznik wrote:
 This patch creates new bios element which, at this time has the only

s/the only/only the/

 attribute useserial='yes|no'. This attribute allow users to use
 Serial Graphics Adapter and see BIOS messages from the very first moment
 domain boots up. Therefore, users can choose boot medium, set PXE, etc.
 ---
 diff to v2:
 -move from serial to bios
 -include Eric's and Dan's suggestions
 
 diff to v1:
 -move from video to serial as Dan suggested:
 https://www.redhat.com/archives/libvir-list/2011-July/msg00134.html
 
  docs/formatdomain.html.in |9 ++
  docs/schemas/domain.rng   |   14 +
  src/conf/domain_conf.c|   27 -
  src/conf/domain_conf.h|   13 
  src/qemu/qemu_capabilities.c  |3 ++
  src/qemu/qemu_capabilities.h  |1 +
  src/qemu/qemu_command.c   |   20 +
  tests/qemuxml2argvdata/qemuxml2argv-bios.args |6 
  tests/qemuxml2argvdata/qemuxml2argv-bios.xml  |   39 
 +
  tests/qemuxml2argvtest.c  |1 +
  10 files changed, 131 insertions(+), 2 deletions(-)
  create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-bios.args
  create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-bios.xml
 
 diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
 index 10d87a9..9cc0bca 100644
 --- a/docs/formatdomain.html.in
 +++ b/docs/formatdomain.html.in
 @@ -86,6 +86,7 @@
  lt;boot dev='cdrom'/gt;
  lt;bootmenu enable='yes'/gt;
  lt;smbios mode='sysinfo'/gt;
 +lt;bios useserial='yes'/gt;
lt;/osgt;
.../pre
  
 @@ -137,6 +138,14 @@
specified, the hypervisor default is used. span class=since
Since 0.8.7/span
/dd
 +  dtcodebios/code/dt
 +  ddThis element has attribute codeuseserial/code with possible
 +values codeyes/code or codeno/code. It enables or disables
 +Serial Graphics Adapter which allows users to see BIOS messages
 +on a serial port. Therefore, one need to have

s/need to have/needs to have a/

 +a href=#elementCharSerialserial port/a defined.
 +span class=sinceSince 0.9.4/span
 +  /dd
  /dl
  

 +++ b/src/conf/domain_conf.h
 @@ -923,6 +923,18 @@ enum virDomainLifecycleCrashAction {
  VIR_DOMAIN_LIFECYCLE_CRASH_LAST
  };
  
 +enum virDomainBIOSUseserial {
 +VIR_DOMAIN_BIOS_USESERIAL_DEFAULT = 0,
 +VIR_DOMAIN_BIOS_USESERIAL_YES,
 +VIR_DOMAIN_BIOS_USESERIAL_NO
 +};
 +
 +typedef struct _virDomainBIOSDef virDomainBIOSDef;
 +typedef virDomainBIOSDef *virDomainBIOSDefPtr;
 +struct _virDomainBIOSDef {
 +int useserial;
 +};
 +
  /* Operating system configuration data  machine / arch */
  typedef struct _virDomainOSDef virDomainOSDef;
  typedef virDomainOSDef *virDomainOSDefPtr;
 @@ -942,6 +954,7 @@ struct _virDomainOSDef {
  char *bootloader;
  char *bootloaderArgs;
  int smbios_mode;
 +virDomainBIOSDef bios;

I'm wondering if we could just have done 'int bios_serial' here, instead
of creating the intermediate type _virDomainBIOSDef.  I guess if we ever
add more attributes or subelements to bios, then the struct will be
nice, but until then it seems a bit heavyweight.  But what you have is
not wrong, so no change necessary.

ACK.

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH] Define remote wire protocol impls for virDomainQemuAttach

2011-07-08 Thread Eric Blake
On 07/08/2011 07:40 AM, Eric Blake wrote:
 On 07/08/2011 06:20 AM, Daniel P. Berrange wrote:
 From: Daniel P. Berrange berra...@redhat.com

 This tweaks the RPC generator to cope with some naming
 conventions used for the QEMU specific APIs

 * daemon/remote.c: Server side dispatcher
 * src/remote/remote_driver.c: Client side dispatcher
 * src/remote/qemu_protocol.x: Wire protocol definition
 * src/rpc/gendispatch.pl: Use '$structprefix' in method
   names, fix QEMU flags and fix dispatcher method names
 ---
  src/remote/qemu_protocol.x |   13 -
  src/remote/remote_driver.c |1 +
  src/rpc/gendispatch.pl |   11 +--
  3 files changed, 22 insertions(+), 3 deletions(-)
 
 Hmm.  We have src/remote_protocol-structs to catch any incompatible
 on-the-wire changes to remote_protocol.x, but nothing to track changes
 to qemu_protocol.x.  Is this something that needs fixing to help us
 avoid unintended wire breakage?

Answering my own question:
https://www.redhat.com/archives/libvir-list/2011-July/msg00463.html

We'll have a merge commit for whichever of these two patches goes in
second :)

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 1/8] Define a QEMU specific API to attach to a running QEMU process

2011-07-08 Thread Eric Blake
On 07/04/2011 04:28 AM, Daniel P. Berrange wrote:
 Introduce a new API in libvirt-qemu.so
 
  virDomainPtr virDomainQemuAttach(virConnectPtr domain,
   unsigned long long pid,

We already assert elsewhere in our code base that pid_t will always fit
in int.  For example, see _virDomainObj in domain_conf.h.  Passing a ull
here seems like it might be overkill.

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PROPOSED PATCH] Change the creation of the TAP interface for generic ethernet interfaces

2011-07-08 Thread Eric Blake
On 07/07/2011 06:49 PM, Tyler Coumbes wrote:
 The code changes it so that the TAP interface is created by libvirt
 and then the file descriptor is passed to qemu. Much like what is done
 when using bridged networking. This is done using fd= instead of
 ifname= just like with the bridged networking.

And in general this agrees with our overall desire to use fd passing
instead of filename passing, so I'm all for seeing this patch polished
against the latest libvirt.git.

 Option 1:
 
 Proposed change would be that if there is no script parameter it is
 assumed that fd= is used instead of ifname= and if script= is present
 then use ifname=
 
 Would use fd= after the patch.
 interface type='ethernet'
 target dev='tap0'/
 /interface
 
 Would use ifname= after patch since it has a script= parameter. If a
 script parameter is needed the work around would still need to be in
 place.
 interface type='ethernet'
 target dev='tap0'/
 script path='/etc/qemu-ifup'/
 /interface

I prefer this.  Libvirt is allowed to use the optimal interface under
the hood - the only reason to expose to the user which interface libvirt
is using is if there is ever a reason to suspect that using an fd is not
always optimal, and that a user would want to choose an alternate method
to experiment if the alternate method really is better in their case.

 
 I like option 1 unless anyone sees an issue with that method.

Good to here, since I liked it too!

Looking forward to patches.

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [RFC] exporting KVM host power saving capabilities through libvirt

2011-07-08 Thread Dave Allan
On Mon, Jul 04, 2011 at 10:05:21PM +0530, Vaidyanathan Srinivasan wrote:
 * Dave Allan dal...@redhat.com [2011-07-01 16:56:29]:
 
  
   libvirt has virConnectGetCapabilities() that would export an XML file
   describing the capabilities of the host platform and guest features.
   
   KVM hypervisor's capability to support S3 can be exported as a host
   feature in the XML as follows:
   
   host
   uuid94a3492f-2635-2491-8c87-8de976fad119/uuid
   cpu
 archx86_64/arch
 features=== New host feature fields
   S3/
   S4/
 /features
  
  Just my $.02, but calling it features seems to be confusingly close
  to the existing feature tag.  Maybe power_management ?
 
 Yes, I am open to naming the tag power_management.  Any other similar
 attributes that could be included here in future? Would calling it
 power_management be very restrictive?

Urgh, busy week, sorry to be slow responding; I'd expect there will be
other features you'd want to describe, but they can have their own
tags.

Dave

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [RFC] exporting KVM host power saving capabilities through libvirt

2011-07-08 Thread Dave Allan
On Mon, Jul 04, 2011 at 10:00:20PM +0530, Vaidyanathan Srinivasan wrote:
 * Dave Allan dal...@redhat.com [2011-07-01 17:19:06]:
 
  On Fri, Jul 01, 2011 at 04:56:29PM -0400, Dave Allan wrote:
   On Tue, Jun 28, 2011 at 08:55:31PM +0530, Vaidyanathan Srinivasan wrote:
Hi,

Linux host systems running KVM support various power management
capabilities.  Most of the features like DVFS and sleep states can be
independently exploited by the host system itself based on system
utilisation subject to policies set by the administrator.

However, system-wide low power states like S3 and S4 would require
external communication and interaction with the systems management
stack in order to be used.  The first steps in this direction would be
to allow systems management stack to discover host power saving
capabilities like S3 and S4 along with various other host CPU
capabilities.

Libvirt seems to be the main glue layer between the platform and the
systems-management stack.  Adding host power savings capabilities as
part of libvirt host discovery mechanism seems to be one possible
approach without addition of any new APIs or agents.
   
   Can you provide the use cases you're looking to address with this
   work?
  
  BTW, I'm intrigued by what you might be doing here, but I don't feel
  like I have enough information at this point to know quite what to
  think of it.
 
 Hi Dave,
 
 Thanks for taking a look.  There are several advantages for using S3
 or S4 state for the host system instead power 'off' and 'on' for
 starting new guest instances.  The main advantage of discovering the
 capability through the systems management stack is to get the
 capability reported after checking against all policies and software
 compatibilities.  The overall idea is to allow high level systems
 management software that work through libvirt to discover and exploit
 these capabilities wherever possible.
 
 Discovery of available power savings features is only the first step
 and I am looking for ideas to export these capabilities through
 libvirt.  I would expect the management stack that collects host
 capabilities would be keep these feature list and could use them to
 make various optimization decisions.

That certainly sounds useful to me.

Dave

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] rpc: Fix whitespace problem in generated code

2011-07-08 Thread Matthias Bolte
Add missing line break and fix indention level.

Reported by Cole Robinson.
---

Pushing this under the trivial rule.

 src/rpc/gendispatch.pl |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
index 027560c..c69c5a2 100755
--- a/src/rpc/gendispatch.pl
+++ b/src/rpc/gendispatch.pl
@@ -1350,11 +1350,11 @@ elsif ($opt_k) {
 if ($call-{streamflag} ne none) {
 print \n;
 print if (!(netst = 
virNetClientStreamNew(priv-remoteProgram, REMOTE_PROC_$call-{UC_NAME}, 
priv-counter)))\n;
-printgoto done;\n;
+print goto done;\n;
 print \n;
-print if (virNetClientAddStream(priv-client, netst)  0) {;
-printvirNetClientStreamFree(netst);\n;
-printgoto done;\n;
+print if (virNetClientAddStream(priv-client, netst)  0) 
{\n;
+print virNetClientStreamFree(netst);\n;
+print goto done;\n;
 print };
 print \n;
 print st-driver = remoteStreamDrv;\n;
-- 
1.7.4.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 01/14] Remove unused virNetServerProgramErrorHander typedef

2011-07-08 Thread Eric Blake
On 07/07/2011 08:17 AM, Daniel P. Berrange wrote:
 From: Daniel P. Berrange berra...@redhat.com
 
 * src/rpc/virnetserverprogram.h: Remove unused typedef for
   virNetServerProgramErrorHander function callback
 * daemon/remote.h: Remove decl for non-existant variables
 ---
  daemon/remote.h   |2 --
  src/rpc/virnetserverprogram.h |3 ---
  2 files changed, 0 insertions(+), 5 deletions(-)

ACK.  Pure deletion patches are always fun :)

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] 2/3 testsuite formatting bugs [was: [PATCH] Skip some xen tests if xend is not running]

2011-07-08 Thread Eric Blake
On 07/08/2011 05:28 PM, Matthias Bolte wrote:
 
 From a1508239af921289cd6e357e8521ff42faf535bd Mon Sep 17 00:00:00 2001
 From: Matthias Bolte matthias.bo...@googlemail.com
 Date: Sat, 9 Jul 2011 01:24:16 +0200
 Subject: [PATCH] tests: Add the logic to skip the statstest to the right place
 
 ---
  tests/statstest.c |   31 ---
  1 files changed, 20 insertions(+), 11 deletions(-)
 
  
 -VIRT_TEST_MAIN(mymain)
 +/* Skipping the test in mymain is too late, it results in broken output.
 + * Therefore, expand VIRT_TEST_MAIN here manually to be able to skip at
 + * the right place. */
 +int main(int argc, char **argv)

This seems fishy.  Why did tests/reconnect.c not need the same
treatment?  Oh, because it didn't use VIRT_TEST_MAIN.

Wouldn't it be better to teach VIRT_TEST_MAIN to behave better on a skip?

diff --git i/tests/testutils.c w/tests/testutils.c
index b433204..f732fdd 100644
--- i/tests/testutils.c
+++ w/tests/testutils.c
@@ -688,7 +688,7 @@ cleanup:
 if (abs_srcdir_cleanup)
 VIR_FREE(abs_srcdir);
 virResetLastError();
-if (!virTestGetVerbose()) {
+if (!virTestGetVerbose()  ret != EXIT_AM_SKIP) {
 int i;
 for (i = (testCounter % 40) ; i  0  i  40 ; i++)
 fprintf(stderr,  );


-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] testsuite formatting bugs [was: [PATCH] Skip some xen tests if xend is not running]

2011-07-08 Thread Eric Blake
On 07/08/2011 05:28 PM, Matthias Bolte wrote:
 TEST: virsh-all
   40
   80
   120
  ... 159 OK
 PASS: virsh-all

 We're obviously getting the logic wrong when there are 0 or when
 tests%40 == 39.
 
 Here are two patches for this, plus one to use EXIT_AM_SKIP more.

An even better patch for the SKIP logic.  Why do a for loop of
one space at a time, when printf can do it for us?

From fbaee4f7df0bd04520948228de125ce0c6112130 Mon Sep 17 00:00:00 2001
From: Eric Blake ebl...@redhat.com
Date: Fri, 8 Jul 2011 19:55:02 -0600
Subject: [PATCH] tests: handle skipped tests better

Without this, running statstest withtout xen wasn't formatted well:

TEST: statstest
   0   FAIL
SKIP: statstest

* tests/testutils.c (virtTestMain): Special case skipped test.
---
 tests/testutils.c |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/tests/testutils.c b/tests/testutils.c
index b433204..fe04caa 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -689,10 +689,10 @@ cleanup:
 VIR_FREE(abs_srcdir);
 virResetLastError();
 if (!virTestGetVerbose()) {
-int i;
-for (i = (testCounter % 40) ; i  0  i  40 ; i++)
-fprintf(stderr,  );
-fprintf(stderr,  %-3d %s\n, testCounter, ret == 0 ? OK :
FAIL);
+if (testCounter == 0 || testCounter % 40)
+fprintf(stderr, %*s, 40 - (testCounter % 40), );
+fprintf(stderr,  %-3d %s\n, testCounter,
+ret == 0 ? OK : ret == EXIT_AM_SKIP ? SKIP : FAIL);
 }
 return ret;
 }
-- 
1.7.4.4



-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] 1/3 testsuite formatting bugs [was: [PATCH] Skip some xen tests if xend is not running]

2011-07-08 Thread Eric Blake
On 07/08/2011 07:40 PM, Eric Blake wrote:

 Instead count from 0 to 39 to fix this.
 ---
  tests/test-lib.sh |6 +++---
  1 files changed, 3 insertions(+), 3 deletions(-)

 diff --git a/tests/test-lib.sh b/tests/test-lib.sh
 index 768f96b..9eb6864 100644
 --- a/tests/test-lib.sh
 +++ b/tests/test-lib.sh
 @@ -54,9 +54,9 @@ test_final()
status=$2
  
if test $verbose = 0 ; then
 -mod=`expr \( $counter + 1 \) % 40`
 -if test $mod != 0  test $mod != 1 ; then
 -  for i in `seq $mod 40`
 +mod=`expr $counter % 40`
 +if test $mod != 0 ; then
 +  for i in `seq $mod 39`
 
 seq is a GNU-ism, but this is no less portable than what it was before.
  (To be portable to platforms that lack seq, this should really be
 written as:
 
 for i in 0 1 2 3 4 ... 39

Why iterate in the first place?

+if test $mod != 0 ; then
+  for i in `seq $mod 39`
   do
 printf  

can portably be replaced by:

printf %${len}s 

with len computed via expr.

-- 
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list