Re: [libvirt] [PATCH] vbox: fix VIR_STRDUP value check

2013-05-21 Thread Ján Tomko
On 05/20/2013 05:08 PM, Michal Privoznik wrote:
> On 20.05.2013 11:59, Ján Tomko wrote:
>> In my review of 31532ca I missed the fact that VIR_STRDUP
>> now returns 1 on success, and 0 if the source was NULL.
>>
>> (This still doesn't add proper OOM error handling.)
>> ---
>>  src/vbox/vbox_tmpl.c | 12 ++--
>>  1 file changed, 6 insertions(+), 6 deletions(-)
>>
>> diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
>> index eb8ac63..163aeff 100644
>> --- a/src/vbox/vbox_tmpl.c
>> +++ b/src/vbox/vbox_tmpl.c
>> @@ -2688,9 +2688,9 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, 
>> unsigned int flags) {
>>  
>>  if (hddType == HardDiskType_Immutable)
>>  def->disks[hddNum]->readonly = true;
>> -if (VIR_STRDUP_QUIET(def->disks[hddNum]->src, hddlocation) 
>> == 0 &&
>> -VIR_STRDUP_QUIET(def->disks[hddNum]->dst, "hdd") == 0)
>> -hddNum++;
>> +ignore_value(VIR_STRDUP(def->disks[hddNum]->src, 
>> hddlocation));
>> +ignore_value(VIR_STRDUP(def->disks[hddNum]->dst, "hdd"));
>> +hddNum++;
>>  
>>  VBOX_UTF8_FREE(hddlocation);
>>  VBOX_UTF16_FREE(hddlocationUtf16);
>> @@ -7507,7 +7507,7 @@ static int vboxConnectListNetworks(virConnectPtr conn, 
>> char **const names, int n
>>  VBOX_UTF16_TO_UTF8(nameUtf16, &nameUtf8);
>>  
>>  VIR_DEBUG("nnames[%d]: %s", ret, nameUtf8);
>> -if (VIR_STRDUP(names[ret], nameUtf8) == 0)
>> +if (VIR_STRDUP(names[ret], nameUtf8) >= 0)
>>  ret++;
>>  
>>  VBOX_UTF8_FREE(nameUtf8);
>> @@ -7585,7 +7585,7 @@ static int 
>> vboxConnectListDefinedNetworks(virConnectPtr conn, char **const names
>>  VBOX_UTF16_TO_UTF8(nameUtf16, &nameUtf8);
>>  
>>  VIR_DEBUG("nnames[%d]: %s", ret, nameUtf8);
>> -if (VIR_STRDUP(names[ret], nameUtf8) == 0)
>> +if (VIR_STRDUP(names[ret], nameUtf8) >= 0)
>>  ret++;
>>  
>>  VBOX_UTF8_FREE(nameUtf8);
>> @@ -8087,7 +8087,7 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr 
>> network,
>>  networkInterface->vtbl->GetInterfaceType(networkInterface, 
>> &interfaceType);
>>  
>>  if (interfaceType == HostNetworkInterfaceType_HostOnly) {
>> -if (VIR_STRDUP(def->name, network->name) == 0) {
>> +if (VIR_STRDUP(def->name, network->name) >= 0) {
>>  PRUnichar *networkNameUtf16 = NULL;
>>  IDHCPServer *dhcpServer = NULL;
>>  vboxIID vboxnet0IID = VBOX_IID_INITIALIZER;
>>
> 
> ACK
> 
> Michal
> 

Thanks, pushed now.

Jan

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


Re: [libvirt] [PATCH 0/3 v4] add 'sharePolicy' attribute for qemu vnc sharing policy

2013-05-21 Thread Ján Tomko
On 05/21/2013 04:31 PM, Guannan Ren wrote:
> 
> v3->v4
>   add missing .args, .xml files
>   (I raw it in git Untracked files this morning and
>thought about it for a while, then git-cleaned them...)
>   rebase work.
> 
> v2->v3
>   rebase work.
> 
> v1->v2:
>   changed attribute name from 'policy' to 'sharePolicy'
>   renamed caps flag name: QEMU_CAPS_VNC_SHARE_POLICY
>   fixed issues pointed out in v1 review
>   have to keep hard-coded version probe after checking qemu -help and qmp 
> command.
> 
> As there were some vnc patches recently, I chose do rebase work a little 
> later.
> 
> These patches try to add a new attribute 'sharePolicy' to element graphics of
> vnc type. This attribute has three values:
> allow-exclusive,force-shared and ignore.
> 

ACK series.

Jan

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


Re: [libvirt] [PATCH 31/31] syntax-check: Add the rule to forbid whitespace before "; "

2013-05-21 Thread Osier Yang

On 21/05/13 23:40, Eric Blake wrote:

On 05/21/2013 04:01 AM, Osier Yang wrote:

Only a few cases are allowed:

1) The expression is empty for "for" loop, E.g.

   for (i = 0; ; i++)

2) An empty statement

   while (write(statuswrite, &status, 1) == -1 &&
  errno == EINTR)
   ; /* empty */

3) ";" is inside double-quote, I.e, as part of const string. E.g.

   vshPrint(ctl, "a ; b ; cd;\n");

The "for" loop in src/rpc/virnettlscontext.c is the special case,
1) applies for it, so change it together in this patch.
---
  build-aux/bracket-spacing.pl | 18 ++
  src/rpc/virnettlscontext.c   |  2 +-
  2 files changed, 19 insertions(+), 1 deletion(-)

ACK.



Pushed.

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


Re: [libvirt] [PATCH 30/31] nwfitler: Change the comment style

2013-05-21 Thread Osier Yang

On 21/05/13 23:41, Ján Tomko wrote:

s/nwfitler/nwfilter/ in the subject




Thanks, pushed with the fix.

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


[libvirt] [PATCH 1/3] Fix the syntax-check failure

2013-05-21 Thread Osier Yang
Introduced by commit 7ac2c4fe624, pushed under build-breaker rule.
---
 src/conf/interface_conf.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/conf/interface_conf.h b/src/conf/interface_conf.h
index ae93811..ed6986c 100644
--- a/src/conf/interface_conf.h
+++ b/src/conf/interface_conf.h
@@ -211,7 +211,7 @@ char *virInterfaceDefFormat(const virInterfaceDefPtr def);
 void virInterfaceObjLock(virInterfaceObjPtr obj);
 void virInterfaceObjUnlock(virInterfaceObjPtr obj);
 
-#define VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE   \
+# define VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE   \
 (VIR_CONNECT_LIST_INTERFACES_ACTIVE | \
  VIR_CONNECT_LIST_INTERFACES_INACTIVE)
 
-- 
1.8.1.4

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


[libvirt] [PATCH 1/2] util: add virGetGroupList

2013-05-21 Thread Eric Blake
Since neither getpwuid_r() nor initgroups() are safe to call in
between fork and exec (they obtain a mutex, but if some other
thread in the parent also held the mutex at the time of the fork,
the child will deadlock), we have to split out the functionality
that is unsafe.  This patch adds a nice wrapper around
getgrouplist, which does the lookup by uid instead of name and
which mallocs the result; at least glibc's initgroups() uses
getgrouplist under the hood.

* configure.ac (AC_CHECK_FUNCS_ONCE): Check for getgrouplist.
* src/util/virutil.h (virGetGroupList): New declaration.
* src/util/virutil.c (virGetGroupList): New function.
* src/libvirt_private.syms (virutil.h): Export it.

Signed-off-by: Eric Blake 
---
 configure.ac |  4 +--
 src/libvirt_private.syms |  1 +
 src/util/virutil.c   | 93 
 src/util/virutil.h   |  2 ++
 4 files changed, 98 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 2055637..d20b90e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -205,8 +205,8 @@ AC_CHECK_SIZEOF([long])

 dnl Availability of various common functions (non-fatal if missing),
 dnl and various less common threadsafe functions
-AC_CHECK_FUNCS_ONCE([cfmakeraw geteuid getgid getgrnam_r getmntent_r \
-  getpwuid_r getuid initgroups kill mmap newlocale posix_fallocate \
+AC_CHECK_FUNCS_ONCE([cfmakeraw geteuid getgid getgrnam_r getgrouplist \
+  getmntent_r getpwuid_r getuid initgroups kill mmap newlocale posix_fallocate 
\
   posix_memalign prlimit regexec sched_getaffinity setns setrlimit symlink])

 dnl Availability of pthread functions (if missing, win32 threading is
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index a81a865..3d9d89f 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1933,6 +1933,7 @@ virGetDeviceID;
 virGetDeviceUnprivSGIO;
 virGetFCHostNameByWWN;
 virGetGroupID;
+virGetGroupList;
 virGetGroupName;
 virGetHostname;
 virGetUnprivSGIOSysfsPath;
diff --git a/src/util/virutil.c b/src/util/virutil.c
index 239fba8..a3cb64f 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -993,6 +993,99 @@ virGetGroupID(const char *group, gid_t *gid)
 return 0;
 }

+
+/* Compute the list of supplementary groups associated with @uid, and
+ * including @gid in the list (unless it is -1), storing a malloc'd
+ * result into @list.  Return the size of the list on success, or -1
+ * on failure with error reported and errno set. May not be called
+ * between fork and exec. */
+int
+virGetGroupList(uid_t uid, gid_t gid, gid_t **list)
+{
+char *buf = NULL;
+gid_t *groups = NULL;
+int ngroups = 0;
+int ret = -1;
+
+*list = NULL;
+if (uid == (uid_t)-1)
+return 0;
+
+# ifdef HAVE_GETGROUPLIST
+{
+struct passwd pwd, *pwd_result;
+size_t bufsize;
+int rc;
+
+bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
+if (bufsize == -1)
+bufsize = 16384;
+
+if (VIR_ALLOC_N(buf, bufsize) < 0) {
+virReportOOMError();
+goto error;
+}
+while ((rc = getpwuid_r(uid, &pwd, buf, bufsize,
+&pwd_result)) == ERANGE) {
+if (VIR_RESIZE_N(buf, bufsize, bufsize, bufsize) < 0) {
+virReportOOMError();
+goto error;
+}
+}
+
+if (rc) {
+virReportSystemError(rc, _("cannot getpwuid_r(%u)"),
+ (unsigned int) uid);
+goto error;
+}
+
+if (!pwd_result) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("getpwuid_r failed to retrieve data "
+ "for uid '%u'"),
+   (unsigned int) uid);
+goto error;
+}
+
+if (gid == (gid_t)-1)
+gid = pwd.pw_gid;
+
+/* Figure out what size list to expect */
+getgrouplist(pwd.pw_name, gid, groups, &ngroups);
+
+if (VIR_ALLOC_N(groups, ngroups) < 0) {
+virReportOOMError();
+goto error;
+}
+
+if (getgrouplist(pwd.pw_name, gid, groups, &ngroups) < 0) {
+virReportSystemError(errno,
+ _("cannot getgrouplist(\"%s\", %d)"),
+ pwd.pw_name, (unsigned int) gid);
+goto error;
+}
+}
+# endif
+
+if (!ngroups && gid != (gid_t)-1) {
+if (VIR_ALLOC_N(groups, 1) < 0) {
+virReportOOMError();
+goto error;
+}
+groups[ngroups++] = gid;
+}
+
+*list = groups;
+groups = NULL;
+ret = ngroups;
+
+error:
+VIR_FREE(buf);
+VIR_FREE(groups);
+return ret;
+}
+
+
 /* Set the real and effective uid and gid to the given values, and call
  * initgroups so that the process has all the assumed group membership of
  * that uid. return 0 on success, -1 on failure (the origin

[libvirt] [PATCH 2/2] util: make virSetUIDGID async-signal-safe

2013-05-21 Thread Eric Blake
https://bugzilla.redhat.com/show_bug.cgi?id=964358

POSIX states that multi-threaded apps should not use functions
that are not async-signal-safe between fork and exec, yet we
were using getpwuid_r and initgroups.  Although rare, it is
possible to hit deadlock in the child, when it tries to grab
a mutex that was already held by another thread in the parent.
I actually hit this deadlock when testing multiple domains
being started in parallel with a command hook, with the following
backtrace in the child:

 Thread 1 (Thread 0x7fd56bbf2700 (LWP 3212)):
 #0  __lll_lock_wait ()
 at ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:136
 #1  0x7fd5761e7388 in _L_lock_854 () from /lib64/libpthread.so.0
 #2  0x7fd5761e7257 in __pthread_mutex_lock (mutex=0x7fd56be00360)
 at pthread_mutex_lock.c:61
 #3  0x7fd56bbf9fc5 in _nss_files_getpwuid_r (uid=0, result=0x7fd56bbf0c70,
 buffer=0x7fd55c2a65f0 "", buflen=1024, errnop=0x7fd56bbf25b8)
 at nss_files/files-pwd.c:40
 #4  0x7fd575aeff1d in __getpwuid_r (uid=0, resbuf=0x7fd56bbf0c70,
 buffer=0x7fd55c2a65f0 "", buflen=1024, result=0x7fd56bbf0cb0)
 at ../nss/getXXbyYY_r.c:253
 #5  0x7fd578aebafc in virSetUIDGID (uid=0, gid=0) at util/virutil.c:1031
 #6  0x7fd578aebf43 in virSetUIDGIDWithCaps (uid=0, gid=0, capBits=0,
 clearExistingCaps=true) at util/virutil.c:1388
 #7  0x7fd578a9a20b in virExec (cmd=0x7fd55c231f10) at util/vircommand.c:654
 #8  0x7fd578a9dfa2 in virCommandRunAsync (cmd=0x7fd55c231f10, pid=0x0)
 at util/vircommand.c:2247
 #9  0x7fd578a9d74e in virCommandRun (cmd=0x7fd55c231f10, exitstatus=0x0)
 at util/vircommand.c:2100
 #10 0x7fd56326fde5 in qemuProcessStart (conn=0x7fd53c000df0,
 driver=0x7fd55c0dc4f0, vm=0x7fd54800b100, migrateFrom=0x0, stdin_fd=-1,
 stdin_path=0x0, snapshot=0x0, vmop=VIR_NETDEV_VPORT_PROFILE_OP_CREATE,
 flags=1) at qemu/qemu_process.c:3694
 ...

The solution is to split the work of getpwuid_r/initgroups into the
unsafe portions (getgrouplist, called pre-fork) and safe portions
(setgroups, called post-fork).

* src/util/virutil.h (virSetUIDGID, virSetUIDGIDWithCaps): Adjust
signature.
* src/util/virutil.c (virSetUIDGID): Add parameters.
(virSetUIDGIDWithCaps): Adjust clients.
* src/util/vircommand.c (virExec): Likewise.
* src/util/virfile.c (virFileAccessibleAs, virFileOpenForked)
(virDirCreate): Likewise.
* src/security/security_dac.c (virSecurityDACSetProcessLabel):
Likewise.
* configure.ac (AC_CHECK_FUNCS_ONCE): Check for setgroups, not
initgroups.

Signed-off-by: Eric Blake 
---
 configure.ac|   5 +-
 src/security/security_dac.c |  16 +--
 src/util/vircommand.c   |  10 +++-
 src/util/virfile.c  |  30 ++--
 src/util/virutil.c  | 108 
 src/util/virutil.h  |   5 +-
 6 files changed, 84 insertions(+), 90 deletions(-)

diff --git a/configure.ac b/configure.ac
index d20b90e..26deac7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -206,8 +206,9 @@ AC_CHECK_SIZEOF([long])
 dnl Availability of various common functions (non-fatal if missing),
 dnl and various less common threadsafe functions
 AC_CHECK_FUNCS_ONCE([cfmakeraw geteuid getgid getgrnam_r getgrouplist \
-  getmntent_r getpwuid_r getuid initgroups kill mmap newlocale posix_fallocate 
\
-  posix_memalign prlimit regexec sched_getaffinity setns setrlimit symlink])
+  getmntent_r getpwuid_r getuid kill mmap newlocale posix_fallocate \
+  posix_memalign prlimit regexec sched_getaffinity setgroups setns \
+  setrlimit symlink])

 dnl Availability of pthread functions (if missing, win32 threading is
 dnl assumed).  Because of $LIB_PTHREAD, we cannot use AC_CHECK_FUNCS_ONCE.
diff --git a/src/security/security_dac.c b/src/security/security_dac.c
index d922ad2..907dbd5 100644
--- a/src/security/security_dac.c
+++ b/src/security/security_dac.c
@@ -1000,17 +1000,25 @@ virSecurityDACSetProcessLabel(virSecurityManagerPtr mgr,
 uid_t user;
 gid_t group;
 virSecurityDACDataPtr priv = virSecurityManagerGetPrivateData(mgr);
+gid_t *groups;
+int ngroups;
+int ret = -1;

 if (virSecurityDACGetIds(def, priv, &user, &group))
 return -1;
+ngroups = virGetGroupList(user, group, &groups);
+if (ngroups < 0)
+return -1;

 VIR_DEBUG("Dropping privileges of DEF to %u:%u",
   (unsigned int) user, (unsigned int) group);

-if (virSetUIDGID(user, group) < 0)
-return -1;
-
-return 0;
+if (virSetUIDGID(user, group, groups, ngroups) < 0)
+goto cleanup;
+ret = 0;
+cleanup:
+VIR_FREE(groups);
+return ret;
 }


diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 665f549..ba03802 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -402,6 +402,8 @@ virExec(virCommandPtr cmd)
 const char *binary = NULL;
 int forkRet, ret;
 struct sigaction waxon, waxoff;
+gid_t *groups = NULL;
+int ngr

[libvirt] [PATCH 0/2] avoid getpwuid_r deadlock

2013-05-21 Thread Eric Blake
https://bugzilla.redhat.com/show_bug.cgi?id=964358

Posting now to get reviews started.  I'd especially like to get
feedback that it doesn't break LXC, and that it works with root-squash
NFS when using qemu:qemu instead of root:root in /etc/libvirt/qemu.conf.
I hope to do more testing myself, and also see if I can try writing an
LD_PRELOAD shim as part of 'make check' to make it easier to test that
the right system calls are made during the sequence.

Eric Blake (2):
  util: add virGetGroupList
  util: make virSetUIDGID async-signal-safe

 configure.ac|   7 +--
 src/libvirt_private.syms|   1 +
 src/security/security_dac.c |  16 --
 src/util/vircommand.c   |  10 +++-
 src/util/virfile.c  |  30 +--
 src/util/virutil.c  | 123 ++--
 src/util/virutil.h  |   7 ++-
 7 files changed, 142 insertions(+), 52 deletions(-)

-- 
1.8.1.4

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


[libvirt] Remove OPTION section in output of 'virsh help command' if no option exists.

2013-05-21 Thread Zhang Xiaohe
Don't print 'OPTION' if there's no options. Just behaves as DESCRIPTION 
does.

This mostly affects 'interface' command group.

Signed-off-by: Zhang Xiaohe 
Reported-by: Li Yang 
---
 tools/virsh.c |4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index ecb7bd4..7c60800 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -1270,7 +1270,9 @@ vshCmddefHelp(vshControl *ctl, const char *cmdname)

 if (def->opts) {
 const vshCmdOptDef *opt;
-fputs(_("\n  OPTIONS\n"), stdout);
+/* Print the option only if there are options */
+if (def->opts->name)
+fputs(_("\n  OPTIONS\n"), stdout);
 for (opt = def->opts; opt->name; opt++) {
 switch (opt->type) {
 case VSH_OT_BOOL:
--
1.7.1

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


Re: [libvirt] [PATCH v2] interface: list all interfaces with flags == 0

2013-05-21 Thread Guannan Ren

On 05/21/2013 10:51 PM, Eric Blake wrote:

On 05/21/2013 07:29 AM, Guannan Ren wrote:

virConnectListAllInterfaces should support to list all of
interfaces when the value of flags is 0. The behaviour is
consistent with other virConnectListAll* APIs
---
  src/conf/interface_conf.h   |  4 
  src/interface/interface_backend_netcf.c | 29 +++--
  src/interface/interface_backend_udev.c  | 25 -
  3 files changed, 31 insertions(+), 27 deletions(-)

ACK.



   Thanks, pushed.

   Guannan

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


Re: [libvirt] [Qemu-devel] [qemu-devel] Default machine type setting for ppc64

2013-05-21 Thread Anthony Liguori
"Daniel P. Berrange"  writes:

> On Tue, May 21, 2013 at 11:12:26AM -0600, Eric Blake wrote:
>> I have also argued in the past that it would be useful for libvirt to
>> support the idea of a template, where you can specify a domain XML that
>> inherits defaults from the template.  We've already done things like
>> this for networking, nwfilter, and even secret management (in domain
>> XML, you declare that you are using a named network object, and that
>> network object serves as the template instead of you having to hard-code
>> all the elements into your domain XML), so we have a design to base it
>> on.  But until someone adds such a feature for libvirt, then OpenStack
>> should be passing explicit XML to libvirt, and tracking defaults at the
>> OpenStack layer.
>
> I don't think the idea of a template belongs in libvirt.

This is fine.  But the conversation started with a statement that it's
QEMU's job to define reasonable defaults and libvirt just exposes
those.

But in QEMU, we punt this problem by letting a user globally override
this default.  libvirt hides this ability from the end user.

So either it's libvirt's problem to solve, or you should expose the
ability to set the global setting within QEMU.  We can't just point our
fingers at each other and hope the problem goes away :-)

Regards,

Anthony Liguori

> Creating basic
> XML structure with relevant defaults pre-filled for a particular usecase
> is something that the libvirt-designer library is aiming to take care of
> for applications.
>
> 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] [Qemu-devel] [qemu-devel] Default machine type setting for ppc64

2013-05-21 Thread Daniel P. Berrange
On Tue, May 21, 2013 at 11:12:26AM -0600, Eric Blake wrote:
> On 05/21/2013 10:42 AM, Anthony Liguori wrote:
> > Perhaps the right thing to do for OpenStack is to allow for a user
> > specified configuration file to select things like the default hardware
> > models/machine types?  Then this could become node configuration instead
> > of dynamic configuration.
> > 
> > I think it could be useful for general users too.  Every domain requires
> > a lot of the same boiler plate bits.  I think a lot of configurations
> > would benefit from being able to set global domain options.
> 
> I have also argued in the past that it would be useful for libvirt to
> support the idea of a template, where you can specify a domain XML that
> inherits defaults from the template.  We've already done things like
> this for networking, nwfilter, and even secret management (in domain
> XML, you declare that you are using a named network object, and that
> network object serves as the template instead of you having to hard-code
> all the elements into your domain XML), so we have a design to base it
> on.  But until someone adds such a feature for libvirt, then OpenStack
> should be passing explicit XML to libvirt, and tracking defaults at the
> OpenStack layer.

I don't think the idea of a template belongs in libvirt. Creating basic
XML structure with relevant defaults pre-filled for a particular usecase
is something that the libvirt-designer library is aiming to take care of
for applications.

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 v4 01/13] Adapt to VIR_STRDUP and VIR_STRNDUP in src/conf/*

2013-05-21 Thread Eric Blake
On 05/21/2013 03:14 AM, Michal Privoznik wrote:
>>> @@ -392,17 +392,14 @@ virCapabilitiesAddGuest(virCapsPtr caps,
>>>  if (VIR_ALLOC(guest) < 0)
>>>  goto no_memory;
>>>  
>>> -if ((guest->ostype = strdup(ostype)) == NULL)
>>> +if (VIR_STRDUP(guest->ostype, ostype) < 0)
>>>  goto no_memory;
>>
>> Local double-oom.  You might want to clean this one up now.
> 
> You mean s/no_memory/error/ ? Because even if the label is called
> no_memory not every label does call virReportOOMError(), like in this case.

Ah, now that I look at the label, you're right!

Yes, s/no_memory/error/ would avoid my confusion (generally, I've been
assuming that a no_memory label implied an OOM report).

-- 
Eric Blake   eblake redhat com+1-919-301-3266
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] cgroup: be robust against cgroup movement races

2013-05-21 Thread Eric Blake
On 05/21/2013 03:43 AM, Daniel P. Berrange wrote:
> On Mon, May 20, 2013 at 09:07:17PM -0600, Eric Blake wrote:
>> https://bugzilla.redhat.com/show_bug.cgi?id=965169 documents a
>> problem starting domains when cgroups are enabled; I was able
>> to reliably reproduce the race about 5% of the time when I added
>> hooks to domain startup by 3 seconds (as that seemed to be about
>> the length of time that qemu created and then closed a temporary
>> thread, probably related to aio handling of initially opening
>> a disk image).
>>

>> * src/util/vircgroup.c (virCgroupAddTaskStrController): Ignore
>> ESRCH, because a thread ended between read and write attempts.
>> (virCgroupMoveTask): Loop until all threads have moved.
>>
> 
> ACK, this looks like the best we can do here.

Thanks; pushed.  I'm also in the process of backporting it to various
maint branches (at least v0.10.2-maint, since the mentioned BZ was
tagged against Fedora 18) - problem was introduced in 0.10.0, in commit
9102829.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
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] [Qemu-devel] [qemu-devel] Default machine type setting for ppc64

2013-05-21 Thread Eric Blake
On 05/21/2013 10:42 AM, Anthony Liguori wrote:
> Perhaps the right thing to do for OpenStack is to allow for a user
> specified configuration file to select things like the default hardware
> models/machine types?  Then this could become node configuration instead
> of dynamic configuration.
> 
> I think it could be useful for general users too.  Every domain requires
> a lot of the same boiler plate bits.  I think a lot of configurations
> would benefit from being able to set global domain options.

I have also argued in the past that it would be useful for libvirt to
support the idea of a template, where you can specify a domain XML that
inherits defaults from the template.  We've already done things like
this for networking, nwfilter, and even secret management (in domain
XML, you declare that you are using a named network object, and that
network object serves as the template instead of you having to hard-code
all the elements into your domain XML), so we have a design to base it
on.  But until someone adds such a feature for libvirt, then OpenStack
should be passing explicit XML to libvirt, and tracking defaults at the
OpenStack layer.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
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] [PATCHv4 4/4] qemu: Enable multiqueue network

2013-05-21 Thread Laine Stump
On 05/21/2013 10:18 AM, Michal Privoznik wrote:
> ---
>  src/qemu/qemu_command.c | 36 
>  src/qemu/qemu_hotplug.c | 37 ++---
>  2 files changed, 54 insertions(+), 19 deletions(-)
>
> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index 7059b08..0474670 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -6503,14 +6503,28 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
>  if (!bootindex)
>  bootindex = net->info.bootIndex;
>  
> +/* Currently nothing else then TAP devices supports multiqueue. */


s/nothing else/nothing besides/   (or "nothing other than")


> +if (net->driver.virtio.queues &&
> +!(actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
> +  actualType == VIR_DOMAIN_NET_TYPE_BRIDGE)) {
> +virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> +   _("Multiqueue network is not supported for: %s"),
> +   virDomainNetTypeToString(actualType));
> +return -1;

You probably want to check for queues > 1 rather than != 0.

(I would *almost* suggest logging this error anytime tapfdSize came back
from the subordinate function(s) smaller than net->driver.virtio.queues;
that way would wouldn't have to have top change stuff about non-support
in multiple places when macvtap gets the support later. However, if you
did the error reporting that way, you wouldn't be able to give as many
specifics about the reasoning.)

> +}
> +
>  if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
>  actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) {
> -if (VIR_ALLOC(tapfd) < 0 || VIR_ALLOC(tapfdName) < 0) {
> +tapfdSize = net->driver.virtio.queues;
> +if (!tapfdSize)
> +tapfdSize = 1;
> +
> +if (VIR_ALLOC_N(tapfd, tapfdSize) < 0 ||
> +VIR_ALLOC_N(tapfdName, tapfdSize) < 0) {
>  virReportOOMError();
>  goto cleanup;
>  }
>  
> -tapfdSize = 1;
>  if (qemuNetworkIfaceConnect(def, conn, driver, net,
>  qemuCaps, tapfd, &tapfdSize) < 0)
>  goto cleanup;
> @@ -6532,11 +6546,15 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
>  actualType == VIR_DOMAIN_NET_TYPE_DIRECT) {
>  /* Attempt to use vhost-net mode for these types of
> network device */
> -if (VIR_ALLOC(vhostfd) < 0 || VIR_ALLOC(vhostfdName)) {
> +vhostfdSize = net->driver.virtio.queues;
> +if (!vhostfdSize)
> +vhostfdSize = 1;
> +
> +if (VIR_ALLOC_N(vhostfd, vhostfdSize) < 0 ||
> +VIR_ALLOC_N(vhostfdName, vhostfdSize)) {
>  virReportOOMError();
>  goto cleanup;
>  }
> -vhostfdSize = 1;
>  
>  if (qemuOpenVhostNet(def, net, qemuCaps, vhostfd, &vhostfdSize) < 0)
>  goto cleanup;
> @@ -6600,15 +6618,17 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
>  cleanup:
>  if (ret < 0)
>  virDomainConfNWFilterTeardown(net);
> -for (i = 0; i < tapfdSize; i++) {
> +for (i = 0; tapfd && i < tapfdSize; i++) {
>  if (ret < 0)
>  VIR_FORCE_CLOSE(tapfd[i]);
> -VIR_FREE(tapfdName[i]);
> +if (tapfdName)
> +VIR_FREE(tapfdName[i]);
>  }
> -for (i = 0; i < vhostfdSize; i++) {
> +for (i = 0; vhostfd && i < vhostfdSize; i++) {
>  if (ret < 0)
>  VIR_FORCE_CLOSE(vhostfd[i]);
> -VIR_FREE(vhostfdName[i]);
> +if (vhostfdName)
> +VIR_FREE(vhostfdName[i]);
>  }
>  VIR_FREE(tapfd);
>  VIR_FREE(vhostfd);
> diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
> index 7e50592..e7d200f 100644
> --- a/src/qemu/qemu_hotplug.c
> +++ b/src/qemu/qemu_hotplug.c
> @@ -740,13 +740,26 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
>  goto cleanup;
>  }
>  
> +/* Currently nothing else then TAP devices supports multiqueue. */
> +if (net->driver.virtio.queues &&
> +!(actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
> +  actualType == VIR_DOMAIN_NET_TYPE_BRIDGE)) {
> +virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> +   _("Multiqueue network is not supported for: %s"),
> +   virDomainNetTypeToString(actualType));
> +return -1;
> +}
> +
>  if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE ||
>  actualType == VIR_DOMAIN_NET_TYPE_NETWORK) {
> -if (VIR_ALLOC(tapfd) < 0 || VIR_ALLOC(vhostfd) < 0) {
> +tapfdSize = vhostfdSize = net->driver.virtio.queues;
> +if (!tapfdSize)
> +tapfdSize = vhostfdSize = 1;
> +if (VIR_ALLOC_N(tapfd, tapfdSize) < 0 ||
> +VIR_ALLOC_N(vhostfd, vhostfdSize) < 0) {
>  virReportOOMError();
>  goto cleanup;
>  }
> -tapfdSize = vhostfdSize = 1;
>  if (qemuNetworkIfaceCo

Re: [libvirt] [Qemu-devel] [qemu-devel] Default machine type setting for ppc64

2013-05-21 Thread Anthony Liguori
"Daniel P. Berrange"  writes:

> On Tue, May 21, 2013 at 07:55:27PM +1000, Paul Mackerras wrote:
>> On Tue, May 21, 2013 at 09:39:53AM +0100, Daniel P. Berrange wrote:
>> I think libvirt needs some more sensible way to ask qemu what its
>> capabilities are.  Currently it has no way to ask qemu "what machines
>> can you emulate with kvm acceleration?"  If the user has asked for a
>> KVM domain then the default machine should be one that can be provided
>> by KVM.  At present it isn't, on PowerPC.
>
> If QEMU can provide more intelligent info in this respect, then
> libvirt can use it. We're doing the best we can with picking
> defaults given the info QEMU currently provides us.

Thinking about this a little more.

OpenStack pushes a lot of configuration to the nodes themselves instead
of making things dynamic and exposing APIs (think host network
configuration).

QEMU actually does allow a user to change the default machine type via
the global config file so in theory you could do this with OpenStack.

However, since libvirt uses -nouserconfig, this doesn't work in
practice.

Perhaps the right thing to do for OpenStack is to allow for a user
specified configuration file to select things like the default hardware
models/machine types?  Then this could become node configuration instead
of dynamic configuration.

I think it could be useful for general users too.  Every domain requires
a lot of the same boiler plate bits.  I think a lot of configurations
would benefit from being able to set global domain options.

Regards,

Anthony Liguori

>
>
> 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] [PATCHv4 3/4] qemu: Adapt qemuBuildInterfaceCommandLine to to multiqueue net

2013-05-21 Thread Laine Stump
On 05/21/2013 10:18 AM, Michal Privoznik wrote:
> In order to learn libvirt multiqueue several things must be done:
>
> 1) The '/dev/net/tun' device needs to be opened multiple times with
> IFF_MULTI_QUEUE flag passed to ioctl(fd, TUNSETIFF, &ifr);
>
> 2) Similar, the '/dev/vhost-net' must be opened as many times as in 1)

s/Similar, the/Similarly,/

> in order to keep 1:1 ratio recommended by qemu and kernel folks.
>
> 3) The command line construction code needs to switch from 'fd=X' to
> 'fds=X:Y:...:Z' and from 'vhostfd=X' to 'vhostfds=X:Y:...:Z'.
>
> 4) The monitor handling code needs to learn to pass multiple FDs.
> ---
>  src/network/bridge_driver.c |   2 +-
>  src/qemu/qemu_command.c | 260 
> ++--
>  src/qemu/qemu_command.h |  13 ++-
>  src/qemu/qemu_hotplug.c |  98 -
>  src/qemu/qemu_monitor.c |  78 +++--
>  src/qemu/qemu_monitor.h |   8 +-
>  src/uml/uml_conf.c  |   5 +-
>  src/util/virnetdevtap.c | 113 ++-
>  src/util/virnetdevtap.h |   2 +
>  9 files changed, 378 insertions(+), 201 deletions(-)
>
> diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
> index 6c6ce6d..ad4ab00 100644
> --- a/src/network/bridge_driver.c
> +++ b/src/network/bridge_driver.c
> @@ -2495,7 +2495,7 @@ networkStartNetworkVirtual(struct network_driver 
> *driver,
>  /* Keep tun fd open and interface up to allow for IPv6 DAD to happen 
> */
>  if (virNetDevTapCreateInBridgePort(network->def->bridge,
> &macTapIfName, &network->def->mac,
> -   NULL, &tapfd, NULL, NULL,
> +   NULL, &tapfd, 1, NULL, NULL,
> 
> VIR_NETDEV_TAP_CREATE_USE_MAC_FOR_BRIDGE |
> VIR_NETDEV_TAP_CREATE_IFUP |
> VIR_NETDEV_TAP_CREATE_PERSIST) < 
> 0) {
> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index 6f4028e..7059b08 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -281,11 +281,12 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
>  virConnectPtr conn,
>  virQEMUDriverPtr driver,
>  virDomainNetDefPtr net,
> -virQEMUCapsPtr qemuCaps)
> +virQEMUCapsPtr qemuCaps,
> +int *tapfd,
> +int *tapfdSize)
>  {
>  char *brname = NULL;
> -int err;
> -int tapfd = -1;
> +int ret = -1;
>  unsigned int tap_create_flags = VIR_NETDEV_TAP_CREATE_IFUP;
>  bool template_ifname = false;
>  int actualType = virDomainNetGetActualType(net);
> @@ -297,7 +298,7 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
>  virNetworkPtr network = virNetworkLookupByName(conn,
> 
> net->data.network.name);
>  if (!network)
> -return -1;
> +return ret;
>  
>  active = virNetworkIsActive(network);
>  if (active != 1) {
> @@ -322,18 +323,18 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
>  virFreeError(errobj);
>  
>  if (fail)
> -return -1;
> +return ret;
>  
>  } else if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) {
>  if (!(brname = strdup(virDomainNetGetActualBridgeName(net {
>  virReportOOMError();
> -return -1;
> +return ret;
>  }
>  } else {
>  virReportError(VIR_ERR_INTERNAL_ERROR,
> _("Network type %d is not supported"),
> virDomainNetGetActualType(net));
> -return -1;
> +return ret;
>  }
>  
>  if (!net->ifname ||
> @@ -353,69 +354,95 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
>  tap_create_flags |= VIR_NETDEV_TAP_CREATE_VNET_HDR;
>  }
>  
> -if (cfg->privileged)
> -err = virNetDevTapCreateInBridgePort(brname, &net->ifname, &net->mac,
> - def->uuid, &tapfd,
> - 
> virDomainNetGetActualVirtPortProfile(net),
> - virDomainNetGetActualVlan(net),
> - tap_create_flags);
> -else
> -err = qemuCreateInBridgePortWithHelper(cfg, brname,
> -   &net->ifname,
> -   &tapfd, tap_create_flags);
> -
> -virDomainAuditNetDevice(def, net, "/dev/net/tun", tapfd >= 0);
> -if (err < 0) {
> -if (template_ifname)
> -VIR_FREE(net->ifname);
> -tapfd = -1;
> +if (cfg->privileged) {
> +if (virNetDevTapCreateInBridgePort(brname, &net->ifname, &n

Re: [libvirt] [PATCH] libvirt writes an mcs translation file to /run/setrans directory

2013-05-21 Thread Daniel P. Berrange
On Tue, May 21, 2013 at 09:12:49AM -0400, dwa...@redhat.com wrote:
> From: Dan Walsh 
> 
> mcstransd is a translation tool that can translate MCS Labels into human
> understandable code.  I have patched it to watch for translation files in the
> /run/setrans directory.  This allows us to run commands like ps -eZ and see
> system_u:system_r:svirt_t:Fedora18 rather then 
> system_u:system_r:svirt_t:s0:c1,c2.
> When used with containers it would make an easy way to list all processes 
> within
> a container using ps -eZ | grep Fedora18
> 
> Pass in privileged field into Security Manager so this is only attempted on 
> privileged
> machines

Did you actually test this patch, because it doesn't work at all ?

An LXC guest fails to start:

  2013-05-21 16:26:30.894+: 1: error : virSecuritySELinuxAddMCSFile:107 : 
unable to create MCS file /var/run/setrans/busy: No such file or directory

If I create that directory inside the container, it at least starts,
but doesn't have any effect because you're trying to write to /var/run
directory inside the container, rather than in the host.

With a QEMU guest this does nothing at all, because the QEMU driver
uses virSecurityManagerSetChildProcessLabel instead of
virSecurityManagerSetProcessLabel so this new code simply never
runs.


Trying todo this from the virSecurityManagerSetProcessLabel method
is just wrong. As I said last time, virSecurityManagerGenProcessLabel
is a better place IMHO.

> diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
> index 5d108b9..c41 100644
> --- a/src/security/security_selinux.c
> +++ b/src/security/security_selinux.c
> @@ -83,6 +83,57 @@ 
> virSecuritySELinuxRestoreSecurityTPMFileLabelInt(virSecurityManagerPtr mgr,
>   virDomainTPMDefPtr tpm);
>  
>  
> +static int
> +virSecuritySELinuxAddMCSFile(const char *name,
> + const char *label)
> +{
> +int ret = -1;
> +char *tmp = NULL;
> +context_t con = NULL;
> +
> +if (virAsprintf(&tmp, "%s/%s", SELINUX_TRANS_DIR, name) < 0) {

SELINUX_TRANS_DIR doesn't appear to exist in any libselinux package
prior to Fedora 19, so this breaks the build on all RHEL distros
and Fedora < 18. This code needs to be made conditional on this
constant existing in the headers.

> +virReportOOMError();
> +return -1;
> +}
> +if (!(con = context_new(label))) {
> +virReportSystemError(errno, "%s",
> + _("unable to allocate security context"));
> +goto cleanup;
> +}
> +if (virFileWriteStr(tmp, context_range_get(con),  S_IRUSR|S_IWUSR) < 0) {
> +virReportSystemError(errno,
> + _("unable to create MCS file %s"), tmp);
> +goto cleanup;
> +}
> +ret = 0;
> +
> +cleanup:
> +VIR_FREE(tmp);
> +context_free(con);
> +return ret;
> +}
> +
> +static int
> +virSecuritySELinuxRemoveMCSFile(const char *name)
> +{
> +char *tmp = NULL;
> +int ret = -1;
> +if (virAsprintf(&tmp, "%s/%s", SELINUX_TRANS_DIR, name) < 0) {
> +virReportOOMError();
> +return -1;
> +}
> +if (unlink(tmp) < 0 && errno != ENOENT) {
> +virReportSystemError(errno,
> + _("Unable to remove MCS file %s"), tmp);
> +goto cleanup;
> +}
> +ret = 0;
> +
> +cleanup:
> +VIR_FREE(tmp);
> +return ret;
> +}
> +
>  /*
>   * Returns 0 on success, 1 if already reserved, or -1 on fatal error
>   */
> @@ -1953,7 +2004,7 @@ 
> virSecuritySELinuxReleaseSecurityLabel(virSecurityManagerPtr mgr,
>  }
>  VIR_FREE(secdef->imagelabel);
>  
> -return 0;
> +return virSecuritySELinuxRemoveMCSFile(def->name);
>  }
>  
>  
> @@ -2047,10 +2098,14 @@ 
> virSecuritySELinuxSetSecurityProcessLabel(virSecurityManagerPtr mgr 
> ATTRIBUTE_UN
>  return -1;
>  }
>  
> +if (virSecurityManagerGetPrivileged(mgr) && 
> (virSecuritySELinuxAddMCSFile(def->name, secdef->label) < 0))
> +return -1;

As I said last time, failure to create the MCS file should not be treated
as a fatal error IMHO.

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] interface: list all interfaces with flags == 0

2013-05-21 Thread Guan Nan Ren

Impressive. :)

- Original Message -
From: "Eric Blake" 
To: "Guannan Ren" 
Cc: libvir-list@redhat.com
Sent: Tuesday, May 21, 2013 10:49:57 PM
Subject: Re: [libvirt] [PATCH] interface: list all interfaces with flags == 0

On 05/21/2013 06:49 AM, Guannan Ren wrote:

Guannan's logic says when to drop:

>>> +if (MATCH(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE) &&
>>> +!((MATCH(VIR_CONNECT_LIST_INTERFACES_ACTIVE) &&
>>> +   (status & NETCF_IFACE_ACTIVE)) ||
>>> +  (MATCH(VIR_CONNECT_LIST_INTERFACES_INACTIVE) &&
>>> +   (status & NETCF_IFACE_INACTIVE
>>> +continue;

Jirka's logic says when to keep; so it would need a ! around the overall
expression if we want to turn it into the condition that represents when
to drop.

>>  if (!MATCH(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE) ||
>>  (MATCH(VIR_CONNECT_LIST_INTERFACES_ACTIVE) &&
>>   (status & NETCF_IFACE_ACTIVE)) ||
>>  (MATCH(VIR_CONNECT_LIST_INTERFACES_INACTIVE) &&
>>   (status & NETCF_IFACE_INACTIVE)))

> yes, currently, there are only one group of flags with two
> values(active/inactive),
> the way of yours is better to read.
> if in future, there are more than one group of flags which are
> going to support,
> the way of my version will be better.

Let's compare what happens for all four combinations of the two flags
[active is flag 1, inactive is flag 2]:

flags  status Guannan's [0 means keep] Jirka's [1 means keep]
0  active 0&&!(0||0)=keep  !0||0||0=keep
0  inactive   0&&!(0||0)=keep  !0||0||0=keep
1  active 1&&!(1||0)=keep  !1||1||0=keep
1  inactive   1&&!(0||0)=drop  !1||0||0=drop
2  active 1&&!(0||0)=drop  !1||0||0=drop
2  inactive   1&&!(0||1)=keep  !1||0||1=keep
3  active 1&&!(1||0)=keep  !1||1||0=keep
3  inactive   1&&!(0||1)=keep  !1||0||1=keep

Ultimately, the two expressions are equivalent (you can use deMorgan's
law to prove the equivalence), but I find Jirka's positive logic a bit
easier to reason with than Guannan's negative logic, even if Guannan's
style copied from how we did it on other API.  I do agree that for
purposes of adding future filter groups, as well as minimizing nested
conditionals, that the logic looks better in terms of drop checks:

foreach item:
if (filter group 1 drops)
continue;
if (filter group 2 drops)
continue;
item was kept by all filters, add it to return

rather than logic in terms of keep checks:

foreach item:
if (filter group 1 keeps)
if (filter group 2 keeps)
add it to return

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org

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


Re: [libvirt] two hostdev devices problem

2013-05-21 Thread Laine Stump
On 05/21/2013 11:34 AM, Daniel P. Berrange wrote:
> On Tue, May 21, 2013 at 11:29:26AM -0400, Laine Stump wrote:
>> On 05/21/2013 07:44 AM, Ján Tomko wrote:
>>> On 05/21/2013 01:37 PM, Laine Stump wrote:
 On 05/21/2013 04:03 AM, Ján Tomko wrote:
> On 05/21/2013 09:32 AM, Dominik Mostowiec wrote:
>> hi,
>> I try to add 2 VF by "hostdev".
>> Networks (vnet0, vnet1) with:
>>  
>> 
>> .
>>
>> Domain: 
>> 
>>  
>> 
>> 
>>  
>> 
>>
>> virsh create error:
>> "error: internal error process exited while connecting to monitor: kvm:
>> -device 
>> pci-assign,configfd=25,host=01:10.1,id=hostdev0,bus=pci.0,addr=0x4:
>> Duplicate ID 'hostdev0' for device"
>>
> Hi,
>
> it seems we have been assigning the same id to all network hostdevs until 
> this
> recent commit (not yet released):
>
> http://libvirt.org/git/?p=libvirt.git;a=commitdiff;h=6597cc25
 If that patch has such an effect, it's purely accidental. Have you
 tested this? (I plan to test a before and after as soon as I've had
 breakfast)

>>> I haven't tested it and looking at the code again, I might've been wrong :(
>>>
>>> Sorry about that.
>> Nothing to be sorry about even if you weren't right. And as it turns out
>> you *were* right!
>>
>> I was curious why, so I tested with a 1.0.4 build running under gdb. The
>> reason for the failure was that the person who wrote the code in
>> qemuBuildCommandLine that called qemuAssignDeviceHostdevAlias() (as well
>> as the person who reviewed that code, which would be me :-/) missed a
>> detail of qemuAssignDeviceHostdevAlias() - it only searches for a free
>> alias index if you send -1 as the index, otherwise it just uses the
>> index you send. This is what was being called:
>>
>>   qemuAssignDeviceHostdevAlias(def, hostdev, (def->nhostdevs-1))
>>
>> So the first time def->nhostdevs-1 == -1, and a search would be made in
>> the (empty) hostdevs array, resulting in an index of 0 being used. The
>> second time it's called, def->nhostdevs-1 == 0, so it would just use 0
>> without even checking for a conflict.
>>
>> My patch for VFIO (the one Jan pointed out as being a fix) completely
>> removed this code from qemuBuildCommandLine(), relying instead on the
>> alias being assigned with all other aliases in
>> qemuAssignDeviceAliases(). (I didn't do this on purpose to fix this bug
>> though; I did it because the old code had become redundant).
>>
>> Anyway, thanks for being so observant. I otherwise would have wasted
>> investigation time wondering why it wasn't broken for me.
> So the fact that we missed this suggests we have a gap in our XML->ARGV
> test coverage for host device assignment, right ?


It seems you're on a mission today :-)


Yes. The problem with network commandlines has been that the setup of
the tap devices has always been depply intertwined with the commandline
generation, making it impossible to test from make check. It's been an
annoyance to me for a long time, but finally got to my conscious brain
last month when I put in the vfio patches. (this was the side topic I
opened when Osier sent his patches that add a callback object to the
qemuBuildCommandLine() args).

This is also a problem with generic legacy hostdev devices (generic vfio
host devices don't seem to have a problem), but their only need is a bit
of sysfs.

I would actually prefer the network device host-side setup to be handled
completely outside of qemuBuildCommandLine() in
qemuNetworkPrepareDevices() (as is done for usb and pci passthrough
devices) rather than in a callback, but that would require sending an
array of file descriptors into qemuBuildCommandLine(), and there's no
convenient place to do that. (Note that the arg "vmop" is also only
needed for network device host-side setup, and so moving that setup
outside of qemuBuildCommandline() would eliminate the need for that arg).

You've said that you're against adding hidden driver specific state
information to the virDomainDef (which makes sense. although I will
point out that there is already both driver-specific (everything in
) and state data (the  subelement which isn't
driver-specific, but describes what type of network device was actually
assigned to the guest) in the virDomainDef), so we're left with either:

 1) moving the network device "preparation" into qemuNetworkPrepareDevices,
then replacing "vmop" with a "networkData" arg (or maybe "deviceData",
so that it can easily have similar stuff for other devices added to it)
that contains all the fd's for the tap and vhost-net devices.

or

 2) moving the network device preparation into a callback that's called
from qemuBuildCommandLine(), and keeping vmop simply to pass it into
this callback.

(unless someone else has a better idea). My opinion is that option (1)
is better, because it puts all the netdev setup in a si

Re: [libvirt] [PATCH 08/31] src/phyp: Remove the whitespace before '; '

2013-05-21 Thread Osier Yang

On 21/05/13 23:37, Eric Blake wrote:

On 05/21/2013 04:00 AM, Osier Yang wrote:

---
  src/phyp/phyp_driver.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)

ACK for being mechanical.  However...


diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index 4594cbf..70d3adb 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -1008,7 +1008,7 @@ connected:
  libssh2_session_set_blocking(session, 0);
  
  while ((rc = libssh2_session_startup(session, sock)) ==

-   LIBSSH2_ERROR_EAGAIN) ;
+   LIBSSH2_ERROR_EAGAIN);

My review of patch 30/31 made me revisit this patch.  It has an empty
while loop.  Should we enforce a particular style where all empty-bodied
loops should use a more obvious style to prove that we knew what we were
doing?  For example:

while ((rc = libssh2_session_startup(session, sock)) ==
LIBSSH2_ERROR_EAGAIN)
 ; /* empty */

or

while ((rc = libssh2_session_startup(session, sock)) ==
LIBSSH2_ERROR_EAGAIN) {
 /* empty */
}


Either of above 2 is better than the original one. It's more clear to know
the loop has an empty body. But not sure if it's overladen forcing.

Osier

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


Re: [libvirt] [PATCH 31/31] syntax-check: Add the rule to forbid whitespace before "; "

2013-05-21 Thread Eric Blake
On 05/21/2013 04:01 AM, Osier Yang wrote:
> Only a few cases are allowed:
> 
> 1) The expression is empty for "for" loop, E.g.
> 
>   for (i = 0; ; i++)
> 
> 2) An empty statement
> 
>   while (write(statuswrite, &status, 1) == -1 &&
>  errno == EINTR)
>   ; /* empty */
> 
> 3) ";" is inside double-quote, I.e, as part of const string. E.g.
> 
>   vshPrint(ctl, "a ; b ; cd;\n");
> 
> The "for" loop in src/rpc/virnettlscontext.c is the special case,
> 1) applies for it, so change it together in this patch.
> ---
>  build-aux/bracket-spacing.pl | 18 ++
>  src/rpc/virnettlscontext.c   |  2 +-
>  2 files changed, 19 insertions(+), 1 deletion(-)

ACK.

> 
> diff --git a/build-aux/bracket-spacing.pl b/build-aux/bracket-spacing.pl
> index d3a916f..0d5d2ed 100755
> --- a/build-aux/bracket-spacing.pl
> +++ b/build-aux/bracket-spacing.pl
> @@ -109,6 +109,24 @@ foreach my $file (@ARGV) {
>  $ret = 1;
>  last;
>  }
> +
> +# Forbid whitespace before ";". Things like below are allowed:
> +#
> +# for (i = 0; ; i++)
> +#
> +# while (write(statuswrite, &status, 1) == -1 &&
> +#errno == EINTR)
> +# ;
> +#
> +# printf("%s", "a ; b\n");
> +while ($data =~ /[^;\s]\s+;/) {
> +# Inside the double-quote
> +if ($data !~ /"[^"]*\s;/) {

False negative on:
  for (str = "foo" ; *str; str++)
but I don't think we are likely to iterate over bytes of a string
literal, so I'm not too worried about it.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
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] [PATCHv4 2/4] qemu: Move interface cmd line construction into a separate function

2013-05-21 Thread Laine Stump
On 05/21/2013 10:18 AM, Michal Privoznik wrote:
> Currently, we have one huge function to construct qemu command line.
> This is very ineffective esp. if there's a fault somewhere.
> ---
>  src/qemu/qemu_command.c | 224 
> +---
>  1 file changed, 117 insertions(+), 107 deletions(-)
>
> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index 33a1910..6f4028e 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -6406,6 +6406,117 @@ qemuBuildGraphicsCommandLine(virQEMUDriverConfigPtr 
> cfg,
>  return 0;
>  }
>  
> +static int
> +qemuBuildInterfaceCommandLine(virCommandPtr cmd,
> +  virQEMUDriverPtr driver,
> +  virConnectPtr conn,
> +  virDomainDefPtr def,
> +  virDomainNetDefPtr net,
> +  virQEMUCapsPtr qemuCaps,
> +  int vlan,
> +  int bootindex,
> +  enum virNetDevVPortProfileOp vmop)
> +{
> +int ret = -1;
> +int tapfd = -1;
> +int vhostfd = -1;
> +char *nic = NULL, *host = NULL;
> +char *tapfdName = NULL;
> +char *vhostfdName = NULL;
> +int actualType = virDomainNetGetActualType(net);
> +
> +if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
> +/* NET_TYPE_HOSTDEV devices are really hostdev devices, so
> + * their commandlines are constructed with other hostdevs.
> + */
> +return 0;
> +}
> +
> +if (!bootindex)
> +bootindex = net->info.bootIndex;
> +
> +if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
> +actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) {
> +tapfd = qemuNetworkIfaceConnect(def, conn, driver, net, qemuCaps);
> +if (tapfd < 0)
> +goto cleanup;
> +} else if (actualType == VIR_DOMAIN_NET_TYPE_DIRECT) {
> +tapfd = qemuPhysIfaceConnect(def, driver, net, qemuCaps, vmop);
> +if (tapfd < 0)
> +goto cleanup;
> +}
> +
> +if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
> +actualType == VIR_DOMAIN_NET_TYPE_BRIDGE ||
> +actualType == VIR_DOMAIN_NET_TYPE_ETHERNET ||
> +actualType == VIR_DOMAIN_NET_TYPE_DIRECT) {
> +/* Attempt to use vhost-net mode for these types of
> +   network device */
> +if (qemuOpenVhostNet(def, net, qemuCaps, &vhostfd) < 0)
> +goto cleanup;
> +}
> +
> +if (tapfd >= 0) {
> +virCommandTransferFD(cmd, tapfd);
> +if (virAsprintf(&tapfdName, "%d", tapfd) < 0) {
> +virReportOOMError();
> +goto cleanup;
> +}
> +}
> +
> +if (vhostfd >= 0) {
> +virCommandTransferFD(cmd, vhostfd);
> +if (virAsprintf(&vhostfdName, "%d", vhostfd) < 0) {
> +virReportOOMError();
> +goto cleanup;
> +}
> +}
> +
> +/* Possible combinations:
> + *
> + *  1. Old way:   -net nic,model=e1000,vlan=1 -net tap,vlan=1
> + *  2. Semi-new:  -device e1000,vlan=1-net tap,vlan=1
> + *  3. Best way:  -netdev type=tap,id=netdev1 -device e1000,id=netdev1
> + *
> + * NB, no support for -netdev without use of -device
> + */
> +if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NETDEV) &&
> +virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) {
> +if (!(host = qemuBuildHostNetStr(net, driver,
> + ',', vlan, tapfdName,
> + vhostfdName)))
> +goto cleanup;
> +virCommandAddArgList(cmd, "-netdev", host, NULL);
> +}
> +if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) {
> +if (!(nic = qemuBuildNicDevStr(net, vlan, bootindex, qemuCaps)))
> +goto cleanup;
> +virCommandAddArgList(cmd, "-device", nic, NULL);
> +} else {
> +if (!(nic = qemuBuildNicStr(net, "nic,", vlan)))
> +goto cleanup;
> +virCommandAddArgList(cmd, "-net", nic, NULL);
> +}
> +if (!(virQEMUCapsGet(qemuCaps, QEMU_CAPS_NETDEV) &&
> +  virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE))) {
> +if (!(host = qemuBuildHostNetStr(net, driver,
> + ',', vlan, tapfdName,
> + vhostfdName)))
> +goto cleanup;
> +virCommandAddArgList(cmd, "-net", host, NULL);
> +}
> +
> +ret = 0;
> +cleanup:
> +if (ret < 0)
> +virDomainConfNWFilterTeardown(net);
> +VIR_FREE(nic);
> +VIR_FREE(host);
> +VIR_FREE(tapfdName);
> +VIR_FREE(vhostfdName);
> +return ret;
> +}
> +
>  qemuBuildCommandLineCallbacks buildCommandLineCallbacks = {
>  .qemuGetSCSIDeviceSgName = virSCSIDeviceGetSgName,
>  };
> @@ -7344,118 +7455,17 @@ qemuBuildCommandLine(virConnectPtr conn,
>  
>  for (i = 0 ; i < def->nnets ; i++) {
>

Re: [libvirt] two hostdev devices problem

2013-05-21 Thread Laine Stump
On 05/21/2013 07:44 AM, Ján Tomko wrote:
> On 05/21/2013 01:37 PM, Laine Stump wrote:
>> On 05/21/2013 04:03 AM, Ján Tomko wrote:
>>> On 05/21/2013 09:32 AM, Dominik Mostowiec wrote:
 hi,
 I try to add 2 VF by "hostdev".
 Networks (vnet0, vnet1) with:
  
 
 .

 Domain: 
 
  
 
 
  
 

 virsh create error:
 "error: internal error process exited while connecting to monitor: kvm:
 -device pci-assign,configfd=25,host=01:10.1,id=hostdev0,bus=pci.0,addr=0x4:
 Duplicate ID 'hostdev0' for device"

>>> Hi,
>>>
>>> it seems we have been assigning the same id to all network hostdevs until 
>>> this
>>> recent commit (not yet released):
>>>
>>> http://libvirt.org/git/?p=libvirt.git;a=commitdiff;h=6597cc25
>>
>> If that patch has such an effect, it's purely accidental. Have you
>> tested this? (I plan to test a before and after as soon as I've had
>> breakfast)
>>
> I haven't tested it and looking at the code again, I might've been wrong :(
>
> Sorry about that.

Nothing to be sorry about even if you weren't right. And as it turns out
you *were* right!

I was curious why, so I tested with a 1.0.4 build running under gdb. The
reason for the failure was that the person who wrote the code in
qemuBuildCommandLine that called qemuAssignDeviceHostdevAlias() (as well
as the person who reviewed that code, which would be me :-/) missed a
detail of qemuAssignDeviceHostdevAlias() - it only searches for a free
alias index if you send -1 as the index, otherwise it just uses the
index you send. This is what was being called:

  qemuAssignDeviceHostdevAlias(def, hostdev, (def->nhostdevs-1))

So the first time def->nhostdevs-1 == -1, and a search would be made in
the (empty) hostdevs array, resulting in an index of 0 being used. The
second time it's called, def->nhostdevs-1 == 0, so it would just use 0
without even checking for a conflict.

My patch for VFIO (the one Jan pointed out as being a fix) completely
removed this code from qemuBuildCommandLine(), relying instead on the
alias being assigned with all other aliases in
qemuAssignDeviceAliases(). (I didn't do this on purpose to fix this bug
though; I did it because the old code had become redundant).

Anyway, thanks for being so observant. I otherwise would have wasted
investigation time wondering why it wasn't broken for me.

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


Re: [libvirt] [PATCHv4 1/4] Introduce /domain/devices/interface/driver/@queues attribute

2013-05-21 Thread Laine Stump
On 05/21/2013 10:18 AM, Michal Privoznik wrote:
> This attribute is going to represent number of queues for
> multique vhost network interface. This commit implements XML
> extension part of the feature and add one test as well. For now,
> we can only do xml2xml test as qemu command line generation code
> is not adapted yet.
> ---
>  docs/formatdomain.html.in  | 12 -
>  docs/schemas/domaincommon.rng  |  5 +++
>  src/conf/domain_conf.c | 15 +++
>  src/conf/domain_conf.h |  1 +
>  .../qemuxml2argvdata/qemuxml2argv-vhost_queues.xml | 51 
> ++
>  tests/qemuxml2xmltest.c|  1 +
>  6 files changed, 84 insertions(+), 1 deletion(-)
>  create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-vhost_queues.xml


ACK.

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


Re: [libvirt] [PATCH 30/31] nwfitler: Change the comment style

2013-05-21 Thread Eric Blake
On 05/21/2013 04:01 AM, Osier Yang wrote:
> The more common habit is to add the comment after the statements.
> ---
>  src/nwfilter/nwfilter_dhcpsnoop.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c 
> b/src/nwfilter/nwfilter_dhcpsnoop.c
> index b9921e5..451c783 100644
> --- a/src/nwfilter/nwfilter_dhcpsnoop.c
> +++ b/src/nwfilter/nwfilter_dhcpsnoop.c
> @@ -369,7 +369,7 @@ virNWFilterSnoopListAdd(virNWFilterSnoopIPLeasePtr plnew,
>  
>  for (pl = *end; pl && plnew->timeout < pl->timeout;
>   pl = pl->prev)
> -/* empty */ ;
> +; /* empty */

How did you determine which style was more common?  Do you have 'git
grep | wc' numbers to back your claim?  I guess putting the comment
after makes it easier to avoid false positives in patch 31?

I did notice a couple of empty while loops in earlier patches (let me
search for them again...)

found it: patch 8/31.  Reply coming up there, soon.

ACK to all patches up to 30 where I didn't explicitly reply.

Weak ack to this one (I don't care if it goes in, but I also don't mind
if it gets omitted).

-- 
Eric Blake   eblake redhat com+1-919-301-3266
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 30/31] nwfitler: Change the comment style

2013-05-21 Thread Ján Tomko
s/nwfitler/nwfilter/ in the subject

Jan

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


Re: [libvirt] [PATCH 08/31] src/phyp: Remove the whitespace before '; '

2013-05-21 Thread Eric Blake
On 05/21/2013 04:00 AM, Osier Yang wrote:
> ---
>  src/phyp/phyp_driver.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

ACK for being mechanical.  However...

> 
> diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
> index 4594cbf..70d3adb 100644
> --- a/src/phyp/phyp_driver.c
> +++ b/src/phyp/phyp_driver.c
> @@ -1008,7 +1008,7 @@ connected:
>  libssh2_session_set_blocking(session, 0);
>  
>  while ((rc = libssh2_session_startup(session, sock)) ==
> -   LIBSSH2_ERROR_EAGAIN) ;
> +   LIBSSH2_ERROR_EAGAIN);

My review of patch 30/31 made me revisit this patch.  It has an empty
while loop.  Should we enforce a particular style where all empty-bodied
loops should use a more obvious style to prove that we knew what we were
doing?  For example:

while ((rc = libssh2_session_startup(session, sock)) ==
   LIBSSH2_ERROR_EAGAIN)
; /* empty */

or

while ((rc = libssh2_session_startup(session, sock)) ==
   LIBSSH2_ERROR_EAGAIN) {
/* empty */
}

If so, how would we enforce such a style?

-- 
Eric Blake   eblake redhat com+1-919-301-3266
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 01/31] src/network: Remove the whitespace before '; '

2013-05-21 Thread Eric Blake
On 05/21/2013 04:00 AM, Osier Yang wrote:
> ---
>  src/network/bridge_driver.c | 22 +++---
>  1 file changed, 11 insertions(+), 11 deletions(-)

ACK.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
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 30/31] nwfitler: Change the comment style

2013-05-21 Thread Osier Yang

On 21/05/13 23:35, Eric Blake wrote:

On 05/21/2013 04:01 AM, Osier Yang wrote:

The more common habit is to add the comment after the statements.
---
  src/nwfilter/nwfilter_dhcpsnoop.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c 
b/src/nwfilter/nwfilter_dhcpsnoop.c
index b9921e5..451c783 100644
--- a/src/nwfilter/nwfilter_dhcpsnoop.c
+++ b/src/nwfilter/nwfilter_dhcpsnoop.c
@@ -369,7 +369,7 @@ virNWFilterSnoopListAdd(virNWFilterSnoopIPLeasePtr plnew,
  
  for (pl = *end; pl && plnew->timeout < pl->timeout;

   pl = pl->prev)
-/* empty */ ;
+; /* empty */

How did you determine which style was more common?  Do you have 'git
grep | wc' numbers to back your claim?  I guess putting the comment
after makes it easier to avoid false positives in patch 31?


Yes, you are right. :-)

As far I saw when writing the script to exclude the empty statements,
all other comments for an empty statements are after ";"



I did notice a couple of empty while loops in earlier patches (let me
search for them again...)

found it: patch 8/31.  Reply coming up there, soon.

ACK to all patches up to 30 where I didn't explicitly reply.


Pushed 1 to 30. Thanks.



Weak ack to this one (I don't care if it goes in, but I also don't mind
if it gets omitted).


I leave this one for more opinion, if there is no more opinion till
tomorrow, will push it.

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


Re: [libvirt] two hostdev devices problem

2013-05-21 Thread Daniel P. Berrange
On Tue, May 21, 2013 at 11:29:26AM -0400, Laine Stump wrote:
> On 05/21/2013 07:44 AM, Ján Tomko wrote:
> > On 05/21/2013 01:37 PM, Laine Stump wrote:
> >> On 05/21/2013 04:03 AM, Ján Tomko wrote:
> >>> On 05/21/2013 09:32 AM, Dominik Mostowiec wrote:
>  hi,
>  I try to add 2 VF by "hostdev".
>  Networks (vnet0, vnet1) with:
>   
>  
>  .
> 
>  Domain: 
>  
>   
>  
>  
>   
>  
> 
>  virsh create error:
>  "error: internal error process exited while connecting to monitor: kvm:
>  -device 
>  pci-assign,configfd=25,host=01:10.1,id=hostdev0,bus=pci.0,addr=0x4:
>  Duplicate ID 'hostdev0' for device"
> 
> >>> Hi,
> >>>
> >>> it seems we have been assigning the same id to all network hostdevs until 
> >>> this
> >>> recent commit (not yet released):
> >>>
> >>> http://libvirt.org/git/?p=libvirt.git;a=commitdiff;h=6597cc25
> >>
> >> If that patch has such an effect, it's purely accidental. Have you
> >> tested this? (I plan to test a before and after as soon as I've had
> >> breakfast)
> >>
> > I haven't tested it and looking at the code again, I might've been wrong :(
> >
> > Sorry about that.
> 
> Nothing to be sorry about even if you weren't right. And as it turns out
> you *were* right!
> 
> I was curious why, so I tested with a 1.0.4 build running under gdb. The
> reason for the failure was that the person who wrote the code in
> qemuBuildCommandLine that called qemuAssignDeviceHostdevAlias() (as well
> as the person who reviewed that code, which would be me :-/) missed a
> detail of qemuAssignDeviceHostdevAlias() - it only searches for a free
> alias index if you send -1 as the index, otherwise it just uses the
> index you send. This is what was being called:
> 
>   qemuAssignDeviceHostdevAlias(def, hostdev, (def->nhostdevs-1))
> 
> So the first time def->nhostdevs-1 == -1, and a search would be made in
> the (empty) hostdevs array, resulting in an index of 0 being used. The
> second time it's called, def->nhostdevs-1 == 0, so it would just use 0
> without even checking for a conflict.
> 
> My patch for VFIO (the one Jan pointed out as being a fix) completely
> removed this code from qemuBuildCommandLine(), relying instead on the
> alias being assigned with all other aliases in
> qemuAssignDeviceAliases(). (I didn't do this on purpose to fix this bug
> though; I did it because the old code had become redundant).
> 
> Anyway, thanks for being so observant. I otherwise would have wasted
> investigation time wondering why it wasn't broken for me.

So the fact that we missed this suggests we have a gap in our XML->ARGV
test coverage for host device assignment, right ?


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] qemu: Don't remove the "return 0"

2013-05-21 Thread Osier Yang

On 21/05/13 23:07, Eric Blake wrote:

On 05/21/2013 09:04 AM, Osier Yang wrote:

Commit f60a50c7957 intended to remove the warning only, but not with
the "return 0" together.
---
  src/qemu/qemu_cgroup.c | 2 ++
  1 file changed, 2 insertions(+)

ACK.

Pushed, thanks.

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


Re: [libvirt] [Qemu-devel] [qemu-devel] Default machine type setting for ppc64

2013-05-21 Thread Li Zhang

On 2013年05月21日 17:55, Paul Mackerras wrote:

On Tue, May 21, 2013 at 09:39:53AM +0100, Daniel P. Berrange wrote:

On Tue, May 21, 2013 at 09:31:26AM +0100, Peter Maydell wrote:

On 21 May 2013 09:19, Li Zhang  wrote:

We encounter this problem in openstack which always use
default machine type. Currently, QEMU sets mac99 as default
setting for ppc64 but it doesn't work on our platform at all.

I tried to fix this in libvirt which it is not acceptable because
libvirt only considers to get default setting from QEMU.

This will need to be fixed for ARM -- the whole idea of there
being a sensible "default machine type" and it being the one
QEMU starts by default is pretty x86-centric. libvirt needs
to have support for specifying which machine to use.

Libvirt has always had support for specifying what machine type to use.
This discussion is simply about what machine type to default to, if the
user hasn't explicitly asked for one.

So, the situation is that the XML in question has hvm,
in the  section.  Does that say anything about what type of
machine is being requested?  Why is the machine type in the 
section rather than the  section?


QEMU has the notion of a default machine for each target, and that is
what libvirt uses if the user hasn't specified a machine.  It is not
libvirt's job to override QEMU's notion of the default machine here,
so if the 'mac99' machine type isn't suitable as the default either
QEMU needs to change that for the ppc target, or the user needs to
explicitly specify their desired machine type.

We are getting the default changed to 'pseries', at least for cases
where pseries support is compiled in, which isn't necessarily
always.  That will of course not satisfy the Freescale guys.


You are right. This default setting can't satisfy every platform.
So it will needs management tool to add one machine type option,
if it wants to support different machine types for ppc64.

Thanks. :)


I think libvirt needs some more sensible way to ask qemu what its
capabilities are.  Currently it has no way to ask qemu "what machines
can you emulate with kvm acceleration?"  If the user has asked for a
KVM domain then the default machine should be one that can be provided
by KVM.  At present it isn't, on PowerPC.

Paul.



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

Re: [libvirt] [PATCH 03/31] src/conf: Remove the whitespace before '; '

2013-05-21 Thread Eric Blake
On 05/21/2013 04:00 AM, Osier Yang wrote:
> ---
>  src/conf/capabilities.c |  50 +-
>  src/conf/cpu_conf.c |  14 +--
>  src/conf/domain_audit.c |  10 +-
>  src/conf/domain_conf.c  | 230 
> ++--
>  src/conf/domain_event.c |  32 +++---
>  src/conf/interface_conf.c   |   8 +-
>  src/conf/network_conf.c |  28 +++---
>  src/conf/node_device_conf.c |  12 +--
>  src/conf/nwfilter_conf.c|   8 +-
>  src/conf/storage_conf.c |   8 +-
>  10 files changed, 200 insertions(+), 200 deletions(-)
> 

Longer, but still mechanical :)

ACK.

This is getting long; I'll do a bulk reply after reading through the
next few patches.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
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] qemu: Don't remove the "return 0"

2013-05-21 Thread Daniel P. Berrange
On Tue, May 21, 2013 at 11:04:36PM +0800, Osier Yang wrote:
> Commit f60a50c7957 intended to remove the warning only, but not with
> the "return 0" together.
> ---
>  src/qemu/qemu_cgroup.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
> index ff9a075..fb88802 100644
> --- a/src/qemu/qemu_cgroup.c
> +++ b/src/qemu/qemu_cgroup.c
> @@ -471,6 +471,8 @@ qemuSetupMemoryCgroup(virDomainObjPtr vm)
>  virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
> _("Memory cgroup is not available on this host"));
>  return -1;
> +} else {
> +return 0;
>  }
>  }
>  

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


Re: [libvirt] [PATCH 02/31] src/libxl: Remove the whitespace before '; '

2013-05-21 Thread Eric Blake
On 05/21/2013 04:00 AM, Osier Yang wrote:
> ---
>  src/libxl/libxl_conf.c   | 4 ++--
>  src/libxl/libxl_driver.c | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)

ACK.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
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] qemu: Don't remove the "return 0"

2013-05-21 Thread Eric Blake
On 05/21/2013 09:04 AM, Osier Yang wrote:
> Commit f60a50c7957 intended to remove the warning only, but not with
> the "return 0" together.
> ---
>  src/qemu/qemu_cgroup.c | 2 ++
>  1 file changed, 2 insertions(+)

ACK.

> 
> diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
> index ff9a075..fb88802 100644
> --- a/src/qemu/qemu_cgroup.c
> +++ b/src/qemu/qemu_cgroup.c
> @@ -471,6 +471,8 @@ qemuSetupMemoryCgroup(virDomainObjPtr vm)
>  virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
> _("Memory cgroup is not available on this host"));
>  return -1;
> +} else {
> +return 0;
>  }
>  }
>  
> 

-- 
Eric Blake   eblake redhat com+1-919-301-3266
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] qemu: Don't remove the "return 0"

2013-05-21 Thread Osier Yang
Commit f60a50c7957 intended to remove the warning only, but not with
the "return 0" together.
---
 src/qemu/qemu_cgroup.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index ff9a075..fb88802 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -471,6 +471,8 @@ qemuSetupMemoryCgroup(virDomainObjPtr vm)
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Memory cgroup is not available on this host"));
 return -1;
+} else {
+return 0;
 }
 }
 
-- 
1.8.1.4

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


Re: [libvirt] [Qemu-devel] [qemu-devel] Default machine type setting for ppc64

2013-05-21 Thread Li Zhang

On 2013年05月21日 17:25, Daniel P. Berrange wrote:

On Tue, May 21, 2013 at 05:02:51PM +0800, Li Zhang wrote:

On 2013年05月21日 16:45, Peter Maydell wrote:

On 21 May 2013 09:39, Daniel P. Berrange  wrote:

Libvirt has always had support for specifying what machine type to use.
This discussion is simply about what machine type to default to, if the
user hasn't explicitly asked for one.

QEMU has the notion of a default machine for each target, and that is
what libvirt uses if the user hasn't specified a machine.  It is not
libvirt's job to override QEMU's notion of the default machine here,

Agreed; thanks for the clarification.


so if the 'mac99' machine type isn't suitable as the default either
QEMU needs to change that for the ppc target, or the user needs to
explicitly specify their desired machine type.

OK, that makes sense. So is the problem here just configuration
or is it the next layer above libvirt not being configurable?

Currently, the next layer above libvirt is not configurable.
It is dependent on this default setting. Users also expect
to start one VM successfully by default.

What is the application above libvirt you are using ? It clearly
needs to be fixed if it is to use non-x86 archs successfully.


Sorry for replying late. The applications are openstack and ovirt.

Thanks.
-- Li



Daniel


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

Re: [libvirt] [PATCH 2/7] qemu: Abstract code for memory controller setting into a helper

2013-05-21 Thread Daniel P. Berrange
On Tue, May 21, 2013 at 04:56:37PM +0200, Viktor Mihajlovski wrote:
> On 05/20/2013 01:35 PM, Osier Yang wrote:
> >>>(!virCgroupHasController(priv->cgroup,VIR_CGROUP_CONTROLLER_MEMORY)) {
> >>>+if (vm->def->mem.hard_limit != 0 ||
> >>>+vm->def->mem.soft_limit != 0 ||
> >>>+vm->def->mem.swap_hard_limit != 0) {
> >>>+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
> >>>+   _("Memory cgroup is not available on this
> >>>host"));
> >>>+return -1;
> >>>+} else {
> >>>+VIR_WARN("Could not autoset a RSS limit for domain %s",
> >>>vm->def->name);
> >>>+return 0;
> >>>+}
> >>Not sure why we need this VIR_WARN at all. If no limits are set in the
> >>XML,
> >>then we should not warn about a missing feature that we don't actually
> >>need.
> >
> >Agreed. Having a warning for no XML config is confused. I removed it.
> 
> We may not need the warning, but the return 0 must stay. I can't start
> guests on my system with no memory controller after this commit.

Yes, absolutely. I only suggested killing the warning, the 'return 0'
must remain for sure.


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/7] qemu: Abstract code for memory controller setting into a helper

2013-05-21 Thread Osier Yang

On 21/05/13 22:56, Viktor Mihajlovski wrote:

On 05/20/2013 01:35 PM, Osier Yang wrote:

(!virCgroupHasController(priv->cgroup,VIR_CGROUP_CONTROLLER_MEMORY)) {
+if (vm->def->mem.hard_limit != 0 ||
+vm->def->mem.soft_limit != 0 ||
+vm->def->mem.swap_hard_limit != 0) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("Memory cgroup is not available on this
host"));
+return -1;
+} else {
+VIR_WARN("Could not autoset a RSS limit for domain %s",
vm->def->name);
+return 0;
+}

Not sure why we need this VIR_WARN at all. If no limits are set in the
XML,
then we should not warn about a missing feature that we don't actually
need.


Agreed. Having a warning for no XML config is confused. I removed it.


We may not need the warning, but the return 0 must stay. I can't start
guests on my system with no memory controller after this commit.


oops, I blindly removed it. Will fix soon.

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


Re: [libvirt] [Qemu-devel] [qemu-devel] Default machine type setting for ppc64

2013-05-21 Thread Christian Borntraeger
On 21/05/13 14:04, Anthony Liguori wrote:
> "Daniel P. Berrange"  writes:
> 
>> On Tue, May 21, 2013 at 07:55:27PM +1000, Paul Mackerras wrote:
>>> On Tue, May 21, 2013 at 09:39:53AM +0100, Daniel P. Berrange wrote:
 QEMU has the notion of a default machine for each target, and that is
 what libvirt uses if the user hasn't specified a machine.  It is not
 libvirt's job to override QEMU's notion of the default machine here,
 so if the 'mac99' machine type isn't suitable as the default either
 QEMU needs to change that for the ppc target, or the user needs to
 explicitly specify their desired machine type.
>>>
>>> We are getting the default changed to 'pseries', at least for cases
>>> where pseries support is compiled in, which isn't necessarily
>>> always.  That will of course not satisfy the Freescale guys.
>>>
>>> I think libvirt needs some more sensible way to ask qemu what its
>>> capabilities are.  Currently it has no way to ask qemu "what machines
>>> can you emulate with kvm acceleration?"  If the user has asked for a
>>> KVM domain then the default machine should be one that can be provided
>>> by KVM.  At present it isn't, on PowerPC.
>>
>> If QEMU can provide more intelligent info in this respect, then
>> libvirt can use it. We're doing the best we can with picking
>> defaults given the info QEMU currently provides us.
> 
> We've talked in the past about having an accelerator specific machine
> default.  I think this is a perfectly reasonable thing to do and would
> solve the problem for ARM and for PPC.

If we get such thing, then virtio-ccw might also be the right default for kvm 
on s390.

Christian

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


Re: [libvirt] [PATCH 2/7] qemu: Abstract code for memory controller setting into a helper

2013-05-21 Thread Viktor Mihajlovski

On 05/20/2013 01:35 PM, Osier Yang wrote:

(!virCgroupHasController(priv->cgroup,VIR_CGROUP_CONTROLLER_MEMORY)) {
+if (vm->def->mem.hard_limit != 0 ||
+vm->def->mem.soft_limit != 0 ||
+vm->def->mem.swap_hard_limit != 0) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("Memory cgroup is not available on this
host"));
+return -1;
+} else {
+VIR_WARN("Could not autoset a RSS limit for domain %s",
vm->def->name);
+return 0;
+}

Not sure why we need this VIR_WARN at all. If no limits are set in the
XML,
then we should not warn about a missing feature that we don't actually
need.


Agreed. Having a warning for no XML config is confused. I removed it.


We may not need the warning, but the return 0 must stay. I can't start
guests on my system with no memory controller after this commit.

--

Mit freundlichen Grüßen/Kind Regards
   Viktor Mihajlovski

IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martina Köderitz
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294

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


Re: [libvirt] [PATCH v2] interface: list all interfaces with flags == 0

2013-05-21 Thread Eric Blake
On 05/21/2013 07:29 AM, Guannan Ren wrote:
> virConnectListAllInterfaces should support to list all of
> interfaces when the value of flags is 0. The behaviour is
> consistent with other virConnectListAll* APIs
> ---
>  src/conf/interface_conf.h   |  4 
>  src/interface/interface_backend_netcf.c | 29 +++--
>  src/interface/interface_backend_udev.c  | 25 -
>  3 files changed, 31 insertions(+), 27 deletions(-)

ACK.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
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] interface: list all interfaces with flags == 0

2013-05-21 Thread Eric Blake
On 05/21/2013 06:49 AM, Guannan Ren wrote:

Guannan's logic says when to drop:

>>> +if (MATCH(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE) &&
>>> +!((MATCH(VIR_CONNECT_LIST_INTERFACES_ACTIVE) &&
>>> +   (status & NETCF_IFACE_ACTIVE)) ||
>>> +  (MATCH(VIR_CONNECT_LIST_INTERFACES_INACTIVE) &&
>>> +   (status & NETCF_IFACE_INACTIVE
>>> +continue;

Jirka's logic says when to keep; so it would need a ! around the overall
expression if we want to turn it into the condition that represents when
to drop.

>>  if (!MATCH(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE) ||
>>  (MATCH(VIR_CONNECT_LIST_INTERFACES_ACTIVE) &&
>>   (status & NETCF_IFACE_ACTIVE)) ||
>>  (MATCH(VIR_CONNECT_LIST_INTERFACES_INACTIVE) &&
>>   (status & NETCF_IFACE_INACTIVE)))

> yes, currently, there are only one group of flags with two
> values(active/inactive),
> the way of yours is better to read.
> if in future, there are more than one group of flags which are
> going to support,
> the way of my version will be better.

Let's compare what happens for all four combinations of the two flags
[active is flag 1, inactive is flag 2]:

flags  status Guannan's [0 means keep] Jirka's [1 means keep]
0  active 0&&!(0||0)=keep  !0||0||0=keep
0  inactive   0&&!(0||0)=keep  !0||0||0=keep
1  active 1&&!(1||0)=keep  !1||1||0=keep
1  inactive   1&&!(0||0)=drop  !1||0||0=drop
2  active 1&&!(0||0)=drop  !1||0||0=drop
2  inactive   1&&!(0||1)=keep  !1||0||1=keep
3  active 1&&!(1||0)=keep  !1||1||0=keep
3  inactive   1&&!(0||1)=keep  !1||0||1=keep

Ultimately, the two expressions are equivalent (you can use deMorgan's
law to prove the equivalence), but I find Jirka's positive logic a bit
easier to reason with than Guannan's negative logic, even if Guannan's
style copied from how we did it on other API.  I do agree that for
purposes of adding future filter groups, as well as minimizing nested
conditionals, that the logic looks better in terms of drop checks:

foreach item:
if (filter group 1 drops)
continue;
if (filter group 2 drops)
continue;
item was kept by all filters, add it to return

rather than logic in terms of keep checks:

foreach item:
if (filter group 1 keeps)
if (filter group 2 keeps)
add it to return

-- 
Eric Blake   eblake redhat com+1-919-301-3266
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 2/3 v4] conf: add 'sharePolicy' attribute to graphics element for vnc

2013-05-21 Thread Guannan Ren
 -vnc :5900,share=allow-exclusive
allows clients to ask for exclusive access which is
implemented by dropping other connections Connecting
multiple clients in parallel requires all clients asking
for a shared session (vncviewer: -shared switch)

 -vnc :5900,share=force-shared
disables exclusive client access.  Useful for shared
desktop sessions, where you don't want someone forgetting
specify -shared disconnect everybody else.

 -vnc :5900,share=ignore
completely ignores the shared flag and allows everybody
connect unconditionally
---
 docs/formatdomain.html.in | 13 +++--
 docs/schemas/domaincommon.rng |  9 +
 src/conf/domain_conf.c| 28 
 src/conf/domain_conf.h| 11 +++
 src/libvirt_private.syms  |  2 ++
 5 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index d9814dd..8c12690 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -3621,7 +3621,7 @@ qemu-kvm -net nic,model=? /dev/null
   ...
   
 
-
+
   
 
 
@@ -3664,7 +3664,16 @@ qemu-kvm -net nic,model=? /dev/null
 allows control of connected client during password changes.
 VNC accepts keep value only.
 since 0.9.3
-NB, this may not be supported by all hypervisors.  
+NB, this may not be supported by all hypervisors.
+The optional sharePolicy attribute specifies vnc 
server
+display sharing policy. "allow-exclusive" allows clients to ask
+for exclusive access by dropping other connections. Connecting
+multiple clients in parallel requires all clients asking for a
+shared session (vncviewer: -Shared switch). This is the default
+value. "force-shared" disables exclusive client access, every
+connection has to specify -Shared switch for vncviewer. "ignore"
+welcomes every connection unconditionally
+since 1.0.6.  
 Rather than using listen/port, QEMU supports a
 socket attribute for listening on a unix
 domain socket path.Since 0.8.8
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index b53099b..939654f 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2135,6 +2135,15 @@
   
 
   
+  
+
+  
+allow-exclusive
+force-shared
+ignore
+  
+
+  
 
 
   
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index e7a0381..812a0d6 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -515,6 +515,13 @@ VIR_ENUM_IMPL(virDomainGraphicsAuthConnected,
   "disconnect",
   "keep")
 
+VIR_ENUM_IMPL(virDomainGraphicsVNCSharePolicy,
+  VIR_DOMAIN_GRAPHICS_VNC_SHARE_LAST,
+  "default",
+  "allow-exclusive",
+  "force-shared",
+  "ignore")
+
 VIR_ENUM_IMPL(virDomainGraphicsSpiceChannelName,
   VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_LAST,
   "main",
@@ -7703,6 +7710,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
 if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
 char *port = virXMLPropString(node, "port");
 char *websocket = virXMLPropString(node, "websocket");
+char *sharePolicy = virXMLPropString(node, "sharePolicy");
 char *autoport;
 
 if (port) {
@@ -7745,6 +7753,21 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
 VIR_FREE(websocket);
 }
 
+if (sharePolicy) {
+int policy =
+   virDomainGraphicsVNCSharePolicyTypeFromString(sharePolicy);
+
+if (policy < 0) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("unknown vnc display sharing policy '%s'"), 
sharePolicy);
+VIR_FREE(sharePolicy);
+goto error;
+} else {
+def->data.vnc.sharePolicy = policy;
+}
+VIR_FREE(sharePolicy);
+}
+
 def->data.vnc.socket = virXMLPropString(node, "socket");
 def->data.vnc.keymap = virXMLPropString(node, "keymap");
 
@@ -15280,6 +15303,11 @@ virDomainGraphicsDefFormat(virBufferPtr buf,
 virBufferEscapeString(buf, " keymap='%s'",
   def->data.vnc.keymap);
 
+if (def->data.vnc.sharePolicy)
+virBufferAsprintf(buf, " sharePolicy='%s'",
+  

[libvirt] [PATCH 1/3 v4] qemu: new vnc display sharing policy caps flag

2013-05-21 Thread Guannan Ren
QEMU_CAPS_VNC_SHARE_POLICY (qemu >= 1.1)
---
 src/qemu/qemu_capabilities.c | 7 ++-
 src/qemu/qemu_capabilities.h | 1 +
 tests/qemuhelptest.c | 9 ++---
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 82129a2..b13a5ab 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -231,6 +231,8 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
   "vnc-websocket",
   "drive-discard",
   "mlock",
+
+  "vnc-share-policy", /* 150 */
 );
 
 struct _virQEMUCaps {
@@ -1188,8 +1190,10 @@ virQEMUCapsComputeCmdFlags(const char *help,
 if (version >= 11000)
 virQEMUCapsSet(qemuCaps, QEMU_CAPS_CPU_HOST);
 
-if (version >= 1001000)
+if (version >= 1001000) {
 virQEMUCapsSet(qemuCaps, QEMU_CAPS_IPV6_MIGRATION);
+virQEMUCapsSet(qemuCaps, QEMU_CAPS_VNC_SHARE_POLICY);
+}
 
 if (version >= 1002000)
 virQEMUCapsSet(qemuCaps, QEMU_CAPS_DEVICE_VIDEO_PRIMARY);
@@ -2433,6 +2437,7 @@ virQEMUCapsInitQMPBasic(virQEMUCapsPtr qemuCaps)
 virQEMUCapsSet(qemuCaps, QEMU_CAPS_IPV6_MIGRATION);
 virQEMUCapsSet(qemuCaps, QEMU_CAPS_MACHINE_OPT);
 virQEMUCapsSet(qemuCaps, QEMU_CAPS_DUMP_GUEST_CORE);
+virQEMUCapsSet(qemuCaps, QEMU_CAPS_VNC_SHARE_POLICY);
 }
 
 /* Capabilities that are architecture depending
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 117bf8a..90d08c6 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -188,6 +188,7 @@ enum virQEMUCapsFlags {
 QEMU_CAPS_VNC_WEBSOCKET  = 147, /* -vnc x:y,websocket */
 QEMU_CAPS_DRIVE_DISCARD  = 148, /* -drive 
discard=off(ignore)|on(unmap) */
 QEMU_CAPS_MLOCK  = 149, /* -realtime mlock=on|off */
+QEMU_CAPS_VNC_SHARE_POLICY   = 150, /* set display sharing policy */
 
 QEMU_CAPS_LAST,   /* this must always be the last item */
 };
diff --git a/tests/qemuhelptest.c b/tests/qemuhelptest.c
index f7f88d0..f6bf7dd 100644
--- a/tests/qemuhelptest.c
+++ b/tests/qemuhelptest.c
@@ -827,7 +827,8 @@ mymain(void)
 QEMU_CAPS_IPV6_MIGRATION,
 QEMU_CAPS_DEVICE_PCI_BRIDGE,
 QEMU_CAPS_DEVICE_SCSI_GENERIC,
-QEMU_CAPS_DEVICE_SCSI_GENERIC_BOOTINDEX);
+QEMU_CAPS_DEVICE_SCSI_GENERIC_BOOTINDEX,
+QEMU_CAPS_VNC_SHARE_POLICY);
 DO_TEST("qemu-1.2.0", 1002000, 0, 0,
 QEMU_CAPS_VNC_COLON,
 QEMU_CAPS_NO_REBOOT,
@@ -933,7 +934,8 @@ mymain(void)
 QEMU_CAPS_IPV6_MIGRATION,
 QEMU_CAPS_DEVICE_PCI_BRIDGE,
 QEMU_CAPS_DEVICE_SCSI_GENERIC,
-QEMU_CAPS_DEVICE_SCSI_GENERIC_BOOTINDEX);
+QEMU_CAPS_DEVICE_SCSI_GENERIC_BOOTINDEX,
+QEMU_CAPS_VNC_SHARE_POLICY);
 DO_TEST("qemu-kvm-1.2.0", 1002000, 1, 0,
 QEMU_CAPS_VNC_COLON,
 QEMU_CAPS_NO_REBOOT,
@@ -1044,7 +1046,8 @@ mymain(void)
 QEMU_CAPS_IPV6_MIGRATION,
 QEMU_CAPS_DEVICE_PCI_BRIDGE,
 QEMU_CAPS_DEVICE_SCSI_GENERIC,
-QEMU_CAPS_DEVICE_SCSI_GENERIC_BOOTINDEX);
+QEMU_CAPS_DEVICE_SCSI_GENERIC_BOOTINDEX,
+QEMU_CAPS_VNC_SHARE_POLICY);
 
 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
-- 
1.8.1.4

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


[libvirt] [PATCHv4 2/4] qemu: Move interface cmd line construction into a separate function

2013-05-21 Thread Michal Privoznik
Currently, we have one huge function to construct qemu command line.
This is very ineffective esp. if there's a fault somewhere.
---
 src/qemu/qemu_command.c | 224 +---
 1 file changed, 117 insertions(+), 107 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 33a1910..6f4028e 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -6406,6 +6406,117 @@ qemuBuildGraphicsCommandLine(virQEMUDriverConfigPtr cfg,
 return 0;
 }
 
+static int
+qemuBuildInterfaceCommandLine(virCommandPtr cmd,
+  virQEMUDriverPtr driver,
+  virConnectPtr conn,
+  virDomainDefPtr def,
+  virDomainNetDefPtr net,
+  virQEMUCapsPtr qemuCaps,
+  int vlan,
+  int bootindex,
+  enum virNetDevVPortProfileOp vmop)
+{
+int ret = -1;
+int tapfd = -1;
+int vhostfd = -1;
+char *nic = NULL, *host = NULL;
+char *tapfdName = NULL;
+char *vhostfdName = NULL;
+int actualType = virDomainNetGetActualType(net);
+
+if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
+/* NET_TYPE_HOSTDEV devices are really hostdev devices, so
+ * their commandlines are constructed with other hostdevs.
+ */
+return 0;
+}
+
+if (!bootindex)
+bootindex = net->info.bootIndex;
+
+if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
+actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) {
+tapfd = qemuNetworkIfaceConnect(def, conn, driver, net, qemuCaps);
+if (tapfd < 0)
+goto cleanup;
+} else if (actualType == VIR_DOMAIN_NET_TYPE_DIRECT) {
+tapfd = qemuPhysIfaceConnect(def, driver, net, qemuCaps, vmop);
+if (tapfd < 0)
+goto cleanup;
+}
+
+if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
+actualType == VIR_DOMAIN_NET_TYPE_BRIDGE ||
+actualType == VIR_DOMAIN_NET_TYPE_ETHERNET ||
+actualType == VIR_DOMAIN_NET_TYPE_DIRECT) {
+/* Attempt to use vhost-net mode for these types of
+   network device */
+if (qemuOpenVhostNet(def, net, qemuCaps, &vhostfd) < 0)
+goto cleanup;
+}
+
+if (tapfd >= 0) {
+virCommandTransferFD(cmd, tapfd);
+if (virAsprintf(&tapfdName, "%d", tapfd) < 0) {
+virReportOOMError();
+goto cleanup;
+}
+}
+
+if (vhostfd >= 0) {
+virCommandTransferFD(cmd, vhostfd);
+if (virAsprintf(&vhostfdName, "%d", vhostfd) < 0) {
+virReportOOMError();
+goto cleanup;
+}
+}
+
+/* Possible combinations:
+ *
+ *  1. Old way:   -net nic,model=e1000,vlan=1 -net tap,vlan=1
+ *  2. Semi-new:  -device e1000,vlan=1-net tap,vlan=1
+ *  3. Best way:  -netdev type=tap,id=netdev1 -device e1000,id=netdev1
+ *
+ * NB, no support for -netdev without use of -device
+ */
+if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NETDEV) &&
+virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) {
+if (!(host = qemuBuildHostNetStr(net, driver,
+ ',', vlan, tapfdName,
+ vhostfdName)))
+goto cleanup;
+virCommandAddArgList(cmd, "-netdev", host, NULL);
+}
+if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) {
+if (!(nic = qemuBuildNicDevStr(net, vlan, bootindex, qemuCaps)))
+goto cleanup;
+virCommandAddArgList(cmd, "-device", nic, NULL);
+} else {
+if (!(nic = qemuBuildNicStr(net, "nic,", vlan)))
+goto cleanup;
+virCommandAddArgList(cmd, "-net", nic, NULL);
+}
+if (!(virQEMUCapsGet(qemuCaps, QEMU_CAPS_NETDEV) &&
+  virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE))) {
+if (!(host = qemuBuildHostNetStr(net, driver,
+ ',', vlan, tapfdName,
+ vhostfdName)))
+goto cleanup;
+virCommandAddArgList(cmd, "-net", host, NULL);
+}
+
+ret = 0;
+cleanup:
+if (ret < 0)
+virDomainConfNWFilterTeardown(net);
+VIR_FREE(nic);
+VIR_FREE(host);
+VIR_FREE(tapfdName);
+VIR_FREE(vhostfdName);
+return ret;
+}
+
 qemuBuildCommandLineCallbacks buildCommandLineCallbacks = {
 .qemuGetSCSIDeviceSgName = virSCSIDeviceGetSgName,
 };
@@ -7344,118 +7455,17 @@ qemuBuildCommandLine(virConnectPtr conn,
 
 for (i = 0 ; i < def->nnets ; i++) {
 virDomainNetDefPtr net = def->nets[i];
-char *nic, *host;
-char tapfd_name[50] = "";
-char vhostfd_name[50] = "";
-int vlan;
-int bootindex = bootNet;
-int actualType = virDomainNetGetActualType(net);
-
-if (actualType == VIR_DOMAI

[libvirt] [PATCH 3/3 v4] qemu: add ', share=' to qemu commandline

2013-05-21 Thread Guannan Ren
example: qemu ${otherargs} \
 -vnc 127.0.0.1:0,share=allow-exclusive
---
 src/qemu/qemu_command.c| 36 ++
 tests/qemuargv2xmltest.c   |  1 +
 .../qemuxml2argv-graphics-vnc-policy.args  |  4 +++
 .../qemuxml2argv-graphics-vnc-policy.xml   | 35 +
 tests/qemuxml2argvtest.c   |  1 +
 5 files changed, 77 insertions(+)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-policy.args
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-policy.xml

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 33a1910..1f7e717 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -6099,6 +6099,19 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr 
cfg,
 virBufferAsprintf(&opt, ",websocket=%d", 
graphics->data.vnc.websocket);
 }
 
+if (graphics->data.vnc.sharePolicy) {
+if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VNC_SHARE_POLICY)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("vnc display sharing policy is not "
+ "supported with this QEMU"));
+goto error;
+}
+
+virBufferAsprintf(&opt, ",share=%s",
+  virDomainGraphicsVNCSharePolicyTypeToString(
+  graphics->data.vnc.sharePolicy));
+}
+
 if (graphics->data.vnc.auth.passwd || cfg->vncPassword)
 virBufferAddLit(&opt, ",password");
 
@@ -10030,6 +10043,29 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr 
qemuCaps,
 vnc->data.vnc.websocket =
 vnc->data.vnc.port + 5700;
 }
+} else if (STRPREFIX(opts, "share=")) {
+char *sharePolicy = opts + strlen("share=");
+if (sharePolicy && *sharePolicy) {
+int policy =
+
virDomainGraphicsVNCSharePolicyTypeFromString(sharePolicy);
+
+if (policy < 0) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("unknown vnc display 
sharing policy '%s'"),
+ sharePolicy);
+virDomainGraphicsDefFree(vnc);
+VIR_FREE(orig_opts);
+goto error;
+} else {
+vnc->data.vnc.sharePolicy = policy;
+}
+} else {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("missing vnc sharing 
policy"));
+virDomainGraphicsDefFree(vnc);
+VIR_FREE(orig_opts);
+goto error;
+}
 }
 
 opts = nextopt;
diff --git a/tests/qemuargv2xmltest.c b/tests/qemuargv2xmltest.c
index 58fabdb..652cd09 100644
--- a/tests/qemuargv2xmltest.c
+++ b/tests/qemuargv2xmltest.c
@@ -201,6 +201,7 @@ mymain(void)
 DO_TEST("graphics-vnc");
 DO_TEST("graphics-vnc-socket");
 DO_TEST("graphics-vnc-websocket");
+DO_TEST("graphics-vnc-policy");
 
 DO_TEST("graphics-vnc-sasl");
 DO_TEST("graphics-vnc-tls");
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-policy.args 
b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-policy.args
new file mode 100644
index 000..1b61fcf
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-policy.args
@@ -0,0 +1,4 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
+/usr/bin/qemu -S -M pc -m 214 -smp 1 -monitor 
unix:/tmp/test-monitor,server,nowait \
+-no-acpi -boot c -usb -hda /dev/HostVG/QEMUGuest1 \
+-net none -serial none -parallel none -vnc 127.0.0.1:0,share=allow-exclusive
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-policy.xml 
b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-policy.xml
new file mode 100644
index 000..6c95c8a
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-policy.xml
@@ -0,0 +1,35 @@
+
+  QEMUGuest1
+  c7a5fdbd-edaf-9455-926a-d65c16db1809
+  219100
+  219100
+  1
+  
+hvm
+
+  
+  
+  destroy
+  restart
+  destroy
+  
+/usr/bin/qemu
+
+  
+  
+  
+  
+
+
+
+
+
+
+  
+
+
+  
+
+
+  
+
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index fb61017..b18436b 100644
--- a/tests/qemuxml2argvtest.c
+++ b/te

[libvirt] [PATCH 0/3 v4] add 'sharePolicy' attribute for qemu vnc sharing policy

2013-05-21 Thread Guannan Ren

v3->v4
  add missing .args, .xml files
  (I raw it in git Untracked files this morning and
   thought about it for a while, then git-cleaned them...)
  rebase work.

v2->v3
  rebase work.

v1->v2:
  changed attribute name from 'policy' to 'sharePolicy'
  renamed caps flag name: QEMU_CAPS_VNC_SHARE_POLICY
  fixed issues pointed out in v1 review
  have to keep hard-coded version probe after checking qemu -help and qmp 
command.

As there were some vnc patches recently, I chose do rebase work a little later.

These patches try to add a new attribute 'sharePolicy' to element graphics of
vnc type. This attribute has three values:
allow-exclusive,force-shared and ignore.

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


Re: [libvirt] [PATCH] udev: should not list bridge devices

2013-05-21 Thread Guannan Ren

On 05/21/2013 10:09 PM, Laine Stump wrote:

On 05/21/2013 09:28 AM, Guannan Ren wrote:

When using udev backend, virsh iface-list outputs bridge devices
like:
  Name State  MAC Address
  
  em1  active e8:39:35:58:d5:94
  lo   active 00:00:00:00:00:00
  virbr0   active fe:54:00:a5:f6:42

The patch filters out bridge devices.

---
  src/interface/interface_backend_udev.c | 3 +++
  1 file changed, 3 insertions(+)

diff --git a/src/interface/interface_backend_udev.c 
b/src/interface/interface_backend_udev.c
index 1fd7d46..92648e8 100644
--- a/src/interface/interface_backend_udev.c
+++ b/src/interface/interface_backend_udev.c
@@ -78,6 +78,9 @@ udevGetDevices(struct udev *udev, virUdevStatus status)
  /* Ignore devices that are part of a bridge */
  udev_enumerate_add_nomatch_sysattr(enumerate, "brport/state", NULL);
  
+/* Ignore bridge devices */

+udev_enumerate_add_nomatch_sysattr(enumerate, "bridge/bridge_id", NULL);
+

NACK. It should list bridge devices. What shouldn't be listed is
*transient* interfaces (such as the bridge devices created by libvirt).

This is a problem inherent in the design of the udev driver. It's
examining the current state of the network system, while the original
intent of libvirt's interface driver was really to examine/modify the
persistent system config.



Get it, if so, netcf does a right work.
Thanks for this explanation.



I pointed this out to Doug at the time he
added the udev driver, and he acknowledged the problem but couldn't
think of a simple way to eliminate it, and it didn't seem serious enough
to delay adding in the driver.

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


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


[libvirt] [PATCHv4 3/4] qemu: Adapt qemuBuildInterfaceCommandLine to to multiqueue net

2013-05-21 Thread Michal Privoznik
In order to learn libvirt multiqueue several things must be done:

1) The '/dev/net/tun' device needs to be opened multiple times with
IFF_MULTI_QUEUE flag passed to ioctl(fd, TUNSETIFF, &ifr);

2) Similar, the '/dev/vhost-net' must be opened as many times as in 1)
in order to keep 1:1 ratio recommended by qemu and kernel folks.

3) The command line construction code needs to switch from 'fd=X' to
'fds=X:Y:...:Z' and from 'vhostfd=X' to 'vhostfds=X:Y:...:Z'.

4) The monitor handling code needs to learn to pass multiple FDs.
---
 src/network/bridge_driver.c |   2 +-
 src/qemu/qemu_command.c | 260 ++--
 src/qemu/qemu_command.h |  13 ++-
 src/qemu/qemu_hotplug.c |  98 -
 src/qemu/qemu_monitor.c |  78 +++--
 src/qemu/qemu_monitor.h |   8 +-
 src/uml/uml_conf.c  |   5 +-
 src/util/virnetdevtap.c | 113 ++-
 src/util/virnetdevtap.h |   2 +
 9 files changed, 378 insertions(+), 201 deletions(-)

diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 6c6ce6d..ad4ab00 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -2495,7 +2495,7 @@ networkStartNetworkVirtual(struct network_driver *driver,
 /* Keep tun fd open and interface up to allow for IPv6 DAD to happen */
 if (virNetDevTapCreateInBridgePort(network->def->bridge,
&macTapIfName, &network->def->mac,
-   NULL, &tapfd, NULL, NULL,
+   NULL, &tapfd, 1, NULL, NULL,

VIR_NETDEV_TAP_CREATE_USE_MAC_FOR_BRIDGE |
VIR_NETDEV_TAP_CREATE_IFUP |
VIR_NETDEV_TAP_CREATE_PERSIST) < 0) 
{
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 6f4028e..7059b08 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -281,11 +281,12 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
 virConnectPtr conn,
 virQEMUDriverPtr driver,
 virDomainNetDefPtr net,
-virQEMUCapsPtr qemuCaps)
+virQEMUCapsPtr qemuCaps,
+int *tapfd,
+int *tapfdSize)
 {
 char *brname = NULL;
-int err;
-int tapfd = -1;
+int ret = -1;
 unsigned int tap_create_flags = VIR_NETDEV_TAP_CREATE_IFUP;
 bool template_ifname = false;
 int actualType = virDomainNetGetActualType(net);
@@ -297,7 +298,7 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
 virNetworkPtr network = virNetworkLookupByName(conn,
net->data.network.name);
 if (!network)
-return -1;
+return ret;
 
 active = virNetworkIsActive(network);
 if (active != 1) {
@@ -322,18 +323,18 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
 virFreeError(errobj);
 
 if (fail)
-return -1;
+return ret;
 
 } else if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) {
 if (!(brname = strdup(virDomainNetGetActualBridgeName(net {
 virReportOOMError();
-return -1;
+return ret;
 }
 } else {
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("Network type %d is not supported"),
virDomainNetGetActualType(net));
-return -1;
+return ret;
 }
 
 if (!net->ifname ||
@@ -353,69 +354,95 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
 tap_create_flags |= VIR_NETDEV_TAP_CREATE_VNET_HDR;
 }
 
-if (cfg->privileged)
-err = virNetDevTapCreateInBridgePort(brname, &net->ifname, &net->mac,
- def->uuid, &tapfd,
- 
virDomainNetGetActualVirtPortProfile(net),
- virDomainNetGetActualVlan(net),
- tap_create_flags);
-else
-err = qemuCreateInBridgePortWithHelper(cfg, brname,
-   &net->ifname,
-   &tapfd, tap_create_flags);
-
-virDomainAuditNetDevice(def, net, "/dev/net/tun", tapfd >= 0);
-if (err < 0) {
-if (template_ifname)
-VIR_FREE(net->ifname);
-tapfd = -1;
+if (cfg->privileged) {
+if (virNetDevTapCreateInBridgePort(brname, &net->ifname, &net->mac,
+   def->uuid, tapfd, *tapfdSize,
+   
virDomainNetGetActualVirtPortProfile(net),
+   virDomainNetGetActualVlan(net),
+   tap_create_flags) <

Re: [libvirt] [PATCH] udev: should not list bridge devices

2013-05-21 Thread Laine Stump
On 05/21/2013 09:28 AM, Guannan Ren wrote:
> When using udev backend, virsh iface-list outputs bridge devices
> like:
>  Name State  MAC Address
>  
>  em1  active e8:39:35:58:d5:94
>  lo   active 00:00:00:00:00:00
>  virbr0   active fe:54:00:a5:f6:42
>
> The patch filters out bridge devices.
>
> ---
>  src/interface/interface_backend_udev.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/src/interface/interface_backend_udev.c 
> b/src/interface/interface_backend_udev.c
> index 1fd7d46..92648e8 100644
> --- a/src/interface/interface_backend_udev.c
> +++ b/src/interface/interface_backend_udev.c
> @@ -78,6 +78,9 @@ udevGetDevices(struct udev *udev, virUdevStatus status)
>  /* Ignore devices that are part of a bridge */
>  udev_enumerate_add_nomatch_sysattr(enumerate, "brport/state", NULL);
>  
> +/* Ignore bridge devices */
> +udev_enumerate_add_nomatch_sysattr(enumerate, "bridge/bridge_id", NULL);
> +

NACK. It should list bridge devices. What shouldn't be listed is
*transient* interfaces (such as the bridge devices created by libvirt).

This is a problem inherent in the design of the udev driver. It's
examining the current state of the network system, while the original
intent of libvirt's interface driver was really to examine/modify the
persistent system config. I pointed this out to Doug at the time he
added the udev driver, and he acknowledged the problem but couldn't
think of a simple way to eliminate it, and it didn't seem serious enough
to delay adding in the driver.

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


[libvirt] [PATCHv4 4/4] qemu: Enable multiqueue network

2013-05-21 Thread Michal Privoznik
---
 src/qemu/qemu_command.c | 36 
 src/qemu/qemu_hotplug.c | 37 ++---
 2 files changed, 54 insertions(+), 19 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 7059b08..0474670 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -6503,14 +6503,28 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
 if (!bootindex)
 bootindex = net->info.bootIndex;
 
+/* Currently nothing else then TAP devices supports multiqueue. */
+if (net->driver.virtio.queues &&
+!(actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
+  actualType == VIR_DOMAIN_NET_TYPE_BRIDGE)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("Multiqueue network is not supported for: %s"),
+   virDomainNetTypeToString(actualType));
+return -1;
+}
+
 if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
 actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) {
-if (VIR_ALLOC(tapfd) < 0 || VIR_ALLOC(tapfdName) < 0) {
+tapfdSize = net->driver.virtio.queues;
+if (!tapfdSize)
+tapfdSize = 1;
+
+if (VIR_ALLOC_N(tapfd, tapfdSize) < 0 ||
+VIR_ALLOC_N(tapfdName, tapfdSize) < 0) {
 virReportOOMError();
 goto cleanup;
 }
 
-tapfdSize = 1;
 if (qemuNetworkIfaceConnect(def, conn, driver, net,
 qemuCaps, tapfd, &tapfdSize) < 0)
 goto cleanup;
@@ -6532,11 +6546,15 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
 actualType == VIR_DOMAIN_NET_TYPE_DIRECT) {
 /* Attempt to use vhost-net mode for these types of
network device */
-if (VIR_ALLOC(vhostfd) < 0 || VIR_ALLOC(vhostfdName)) {
+vhostfdSize = net->driver.virtio.queues;
+if (!vhostfdSize)
+vhostfdSize = 1;
+
+if (VIR_ALLOC_N(vhostfd, vhostfdSize) < 0 ||
+VIR_ALLOC_N(vhostfdName, vhostfdSize)) {
 virReportOOMError();
 goto cleanup;
 }
-vhostfdSize = 1;
 
 if (qemuOpenVhostNet(def, net, qemuCaps, vhostfd, &vhostfdSize) < 0)
 goto cleanup;
@@ -6600,15 +6618,17 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
 cleanup:
 if (ret < 0)
 virDomainConfNWFilterTeardown(net);
-for (i = 0; i < tapfdSize; i++) {
+for (i = 0; tapfd && i < tapfdSize; i++) {
 if (ret < 0)
 VIR_FORCE_CLOSE(tapfd[i]);
-VIR_FREE(tapfdName[i]);
+if (tapfdName)
+VIR_FREE(tapfdName[i]);
 }
-for (i = 0; i < vhostfdSize; i++) {
+for (i = 0; vhostfd && i < vhostfdSize; i++) {
 if (ret < 0)
 VIR_FORCE_CLOSE(vhostfd[i]);
-VIR_FREE(vhostfdName[i]);
+if (vhostfdName)
+VIR_FREE(vhostfdName[i]);
 }
 VIR_FREE(tapfd);
 VIR_FREE(vhostfd);
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 7e50592..e7d200f 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -740,13 +740,26 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
 goto cleanup;
 }
 
+/* Currently nothing else then TAP devices supports multiqueue. */
+if (net->driver.virtio.queues &&
+!(actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
+  actualType == VIR_DOMAIN_NET_TYPE_BRIDGE)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("Multiqueue network is not supported for: %s"),
+   virDomainNetTypeToString(actualType));
+return -1;
+}
+
 if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE ||
 actualType == VIR_DOMAIN_NET_TYPE_NETWORK) {
-if (VIR_ALLOC(tapfd) < 0 || VIR_ALLOC(vhostfd) < 0) {
+tapfdSize = vhostfdSize = net->driver.virtio.queues;
+if (!tapfdSize)
+tapfdSize = vhostfdSize = 1;
+if (VIR_ALLOC_N(tapfd, tapfdSize) < 0 ||
+VIR_ALLOC_N(vhostfd, vhostfdSize) < 0) {
 virReportOOMError();
 goto cleanup;
 }
-tapfdSize = vhostfdSize = 1;
 if (qemuNetworkIfaceConnect(vm->def, conn, driver, net,
 priv->qemuCaps, tapfd, &tapfdSize) < 0)
 goto cleanup;
@@ -754,11 +767,11 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
 if (qemuOpenVhostNet(vm->def, net, priv->qemuCaps, vhostfd, 
&vhostfdSize) < 0)
 goto cleanup;
 } else if (actualType == VIR_DOMAIN_NET_TYPE_DIRECT) {
+tapfdSize = vhostfdSize = 1;
 if (VIR_ALLOC(tapfd) < 0 || VIR_ALLOC(vhostfd) < 0) {
 virReportOOMError();
 goto cleanup;
 }
-tapfdSize = vhostfdSize = 1;
 if ((tapfd[0] = qemuPhysIfaceConnect(vm->def, driver, net,
  priv->qemuCaps,
  
VIR_NETDEV_VPOR

[libvirt] [PATCHv4 1/4] Introduce /domain/devices/interface/driver/@queues attribute

2013-05-21 Thread Michal Privoznik
This attribute is going to represent number of queues for
multique vhost network interface. This commit implements XML
extension part of the feature and add one test as well. For now,
we can only do xml2xml test as qemu command line generation code
is not adapted yet.
---
 docs/formatdomain.html.in  | 12 -
 docs/schemas/domaincommon.rng  |  5 +++
 src/conf/domain_conf.c | 15 +++
 src/conf/domain_conf.h |  1 +
 .../qemuxml2argvdata/qemuxml2argv-vhost_queues.xml | 51 ++
 tests/qemuxml2xmltest.c|  1 +
 6 files changed, 84 insertions(+), 1 deletion(-)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-vhost_queues.xml

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index d9814dd..128e5b3 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -3265,7 +3265,7 @@ qemu-kvm -net nic,model=? /dev/null
   
   
   
-  
+  
 
   
   ...
@@ -3359,6 +3359,16 @@ qemu-kvm -net nic,model=? /dev/null
 In general you should leave this option alone, unless you
 are very certain you know what you are doing.
   
+  queues
+  
+The optional queues attribute controls the number of
+queues to be used for thehttp://www.linux-kvm.org/page/Multiqueue";>
+Multiqueue virtio-net feature. If the interface has , multiple packet processing queues can be
+created; each queue will potentially be handled by a different
+processor, resulting in much higher throughput.
+Since 1.0.6 (QEMU and KVM only)
+  
 
 
 Overriding the target 
element
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index b53099b..2190877 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2013,6 +2013,11 @@
 
   
   
+
+  
+
+  
+  
 
   
 iothread
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index e7a0381..17abbe5 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5970,6 +5970,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
 char *txmode = NULL;
 char *ioeventfd = NULL;
 char *event_idx = NULL;
+char *queues = NULL;
 char *filter = NULL;
 char *internal = NULL;
 char *devaddr = NULL;
@@ -6081,6 +6082,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
 txmode = virXMLPropString(cur, "txmode");
 ioeventfd = virXMLPropString(cur, "ioeventfd");
 event_idx = virXMLPropString(cur, "event_idx");
+queues = virXMLPropString(cur, "queues");
 } else if (xmlStrEqual(cur->name, BAD_CAST "filterref")) {
 if (filter) {
 virReportError(VIR_ERR_XML_ERROR, "%s",
@@ -6371,6 +6373,16 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
 }
 def->driver.virtio.event_idx = idx;
 }
+if (queues) {
+unsigned int q;
+if (virStrToLong_ui(queues, NULL, 10, &q) < 0) {
+virReportError(VIR_ERR_XML_DETAIL,
+   _("'queues' attribute must be positive number: 
%s"),
+   queues);
+goto error;
+}
+def->driver.virtio.queues = q;
+}
 }
 
 def->linkstate = VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DEFAULT;
@@ -6424,6 +6436,7 @@ cleanup:
 VIR_FREE(txmode);
 VIR_FREE(ioeventfd);
 VIR_FREE(event_idx);
+VIR_FREE(queues);
 VIR_FREE(filter);
 VIR_FREE(type);
 VIR_FREE(internal);
@@ -14450,6 +14463,8 @@ virDomainNetDefFormat(virBufferPtr buf,
 virBufferAsprintf(buf, " event_idx='%s'",
   
virDomainVirtioEventIdxTypeToString(def->driver.virtio.event_idx));
 }
+if (def->driver.virtio.queues)
+virBufferAsprintf(buf, " queues='%u'", 
def->driver.virtio.queues);
 virBufferAddLit(buf, "/>\n");
 }
 }
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index e74da1c..167831c 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -934,6 +934,7 @@ struct _virDomainNetDef {
 enum virDomainNetVirtioTxModeType txmode;
 enum virDomainIoEventFd ioeventfd;
 enum virDomainVirtioEventIdx event_idx;
+unsigned int queues; /* Multiqueue virtio-net */
 } 

[libvirt] [PATCHv4 0/4] Multiple TX queue support

2013-05-21 Thread Michal Privoznik
Fixed version with Laine's comments worked in [1]. Moreover, most of the
patches joined together.

Patches 2, 3 and 5 has been ACKed already. BTW, patch 4 is really a different
to patch 3. The only thing they share is a commit message body.

Kernel and subsequently QEMU learned multiple transmit queues a while ago. The
feature has a nice advantage, it allows a single guest to transmit multiple
flows of network data using multiple CPUs simultaneously which increase traffic
bandwidth. A lot.

The documentation how to use this is available at [2] or [3].

1: https://www.redhat.com/archives/libvir-list/2013-May/msg01196.html

2: 
https://git.kernel.org/cgit/linux/kernel/git/davem/net-next.git/tree/Documentation/networking/tuntap.txt

3: http://git.qemu.org/?p=qemu.git;a=blob;f=qemu-options.hx;hb=HEAD#l1363


Michal Privoznik (4):
  Introduce /domain/devices/interface/driver/@queues attribute
  qemu: Move interface cmd line construction into a separate function
  qemu: Adapt qemuBuildInterfaceCommandLine to to multiqueue net
  qemu: Enable multiqueue network

 docs/formatdomain.html.in  |  12 +-
 docs/schemas/domaincommon.rng  |   5 +
 src/conf/domain_conf.c |  15 +
 src/conf/domain_conf.h |   1 +
 src/network/bridge_driver.c|   2 +-
 src/qemu/qemu_command.c| 462 +
 src/qemu/qemu_command.h|  13 +-
 src/qemu/qemu_hotplug.c| 113 +++--
 src/qemu/qemu_monitor.c|  78 ++--
 src/qemu/qemu_monitor.h|   8 +-
 src/uml/uml_conf.c |   5 +-
 src/util/virnetdevtap.c| 113 ++---
 src/util/virnetdevtap.h|   2 +
 .../qemuxml2argvdata/qemuxml2argv-vhost_queues.xml |  51 +++
 tests/qemuxml2xmltest.c|   1 +
 15 files changed, 593 insertions(+), 288 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-vhost_queues.xml

-- 
1.8.2.1

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


[libvirt] [PATCH] libvirt writes an mcs translation file to /run/setrans directory

2013-05-21 Thread dwalsh
From: Dan Walsh 

mcstransd is a translation tool that can translate MCS Labels into human
understandable code.  I have patched it to watch for translation files in the
/run/setrans directory.  This allows us to run commands like ps -eZ and see
system_u:system_r:svirt_t:Fedora18 rather then 
system_u:system_r:svirt_t:s0:c1,c2.
When used with containers it would make an easy way to list all processes within
a container using ps -eZ | grep Fedora18

Pass in privileged field into Security Manager so this is only attempted on 
privileged
machines
---
 src/lxc/lxc_container.c |  8 +++---
 src/lxc/lxc_controller.c|  2 +-
 src/lxc/lxc_driver.c|  3 ++-
 src/qemu/qemu_conf.c|  2 ++
 src/qemu/qemu_conf.h|  1 +
 src/qemu/qemu_driver.c  |  9 ---
 src/security/security_manager.c | 29 +++--
 src/security/security_manager.h |  7 +++--
 src/security/security_selinux.c | 57 -
 9 files changed, 98 insertions(+), 20 deletions(-)

diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 48ccc09..cb6ae6a 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -1829,6 +1829,10 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr 
vmDef,
 if (lxcContainerPopulateDevices(ttyPaths, nttyPaths) < 0)
 goto cleanup;
 
+VIR_DEBUG("Setting up security labeling");
+if (virSecurityManagerSetProcessLabel(securityDriver, vmDef) < 0)
+goto cleanup;
+
 /* Sets up any non-root mounts from guest config */
 if (lxcContainerMountAllFS(vmDef, sec_mount_options) < 0)
 goto cleanup;
@@ -2027,10 +2031,6 @@ static int lxcContainerChild(void *data)
 goto cleanup;
 }
 
-VIR_DEBUG("Setting up security labeling");
-if (virSecurityManagerSetProcessLabel(argv->securityDriver, vmDef) < 0)
-goto cleanup;
-
 if (lxcContainerSetStdio(argv->monitor, ttyfd, argv->handshakefd) < 0) {
 goto cleanup;
 }
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 730236e..5a4c809 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -1732,7 +1732,7 @@ int main(int argc, char *argv[])
 
 if (!(ctrl->securityManager = virSecurityManagerNew(securityDriver,
 LXC_DRIVER_NAME,
-false, false, false)))
+false, false, false, 
true)))
 goto cleanup;
 
 if (ctrl->def->seclabels) {
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 997f81d..a80cc9b 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -1358,7 +1358,8 @@ lxcSecurityInit(virLXCDriverPtr driver)
   LXC_DRIVER_NAME,
   false,
   
driver->securityDefaultConfined,
-  
driver->securityRequireConfined);
+  
driver->securityRequireConfined, 
+  true);
 if (!mgr)
 goto error;
 
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 098e49c..b92a27b 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -250,6 +250,7 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool 
privileged)
 
 cfg->securityDefaultConfined = true;
 cfg->securityRequireConfined = false;
+cfg->securityPrivileged = privileged;
 
 cfg->keepAliveInterval = 5;
 cfg->keepAliveCount = 5;
@@ -399,6 +400,7 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
 
 GET_VALUE_BOOL("security_default_confined", cfg->securityDefaultConfined);
 GET_VALUE_BOOL("security_require_confined", cfg->securityRequireConfined);
+GET_VALUE_BOOL("security_privileged", cfg->securityPrivileged);
 
 GET_VALUE_BOOL("spice_tls", cfg->spiceTLS);
 GET_VALUE_STR("spice_tls_x509_cert_dir", cfg->spiceTLSx509certdir);
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index df0791e..06824ae 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -138,6 +138,7 @@ struct _virQEMUDriverConfig {
 char **securityDriverNames;
 bool securityDefaultConfined;
 bool securityRequireConfined;
+bool securityPrivileged;
 
 char *saveImageFormat;
 char *dumpImageFormat;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 203cc6d..7a68e8a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -322,7 +322,8 @@ qemuSecurityInit(virQEMUDriverPtr driver)
   QEMU_DRIVER_NAME,
   cfg->allowDiskFormatProbing,
   cfg->securityDefaultConfined,
-

[libvirt] This patch fixes up a previous patch to work in containers

2013-05-21 Thread dwalsh
It also adds the ability to pass in privileged field into Security Manager so 
that writing to /run/setrans only attempted on privileged machines

[PATCH] libvirt writes an mcs translation file to /run/setrans

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


Re: [libvirt] [PATCH 3/3 v3] qemu: add ', share=' to qemu commandline

2013-05-21 Thread Ján Tomko
On 05/16/2013 03:00 PM, Guannan Ren wrote:
> example: qemu ${otherargs} \
>  -vnc 127.0.0.1:0,share=allow-exclusive
> ---
>  src/qemu/qemu_command.c  | 36 
>  tests/qemuargv2xmltest.c |  1 +
>  tests/qemuxml2argvtest.c |  1 +

You forgot to add the .args and .xml files.

>  3 files changed, 38 insertions(+)
> 
> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index 5b95c07..a462153 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -6098,6 +6098,19 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr 
> cfg,
>  virBufferAsprintf(&opt, ",websocket=%d", 
> graphics->data.vnc.websocket);
>  }
>  
> +if (graphics->data.vnc.sharePolicy) {
> +if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VNC_SHARE_POLICY)) {
> +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
> +   _("vnc display sharing policy is not "
> + "supported with this QEMU"));
> +goto error;
> +}
> +
> +virBufferAsprintf(&opt, ",share=%s",
> +  virDomainGraphicsVNCSharePolicyTypeToString(
> +  graphics->data.vnc.sharePolicy));
> +}
> +
>  if (graphics->data.vnc.auth.passwd || cfg->vncPassword)
>  virBufferAddLit(&opt, ",password");
>  
> @@ -10013,6 +10026,29 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr 
> qemuCaps,
>  vnc->data.vnc.websocket =
>  vnc->data.vnc.port + 5700;
>  }
> +} else if (STRPREFIX(opts, "share=")) {
> +char *sharePolicy = opts + strlen("share=");
> +if (sharePolicy && *sharePolicy) {

sharePolicy is definitely non-NULL here.

> +int policy =
> +
> virDomainGraphicsVNCSharePolicyTypeFromString(sharePolicy);
> +
> +if (policy < 0) {
> +virReportError(VIR_ERR_INTERNAL_ERROR,
> +   _("unknown vnc display 
> sharing policy '%s'"),
> + sharePolicy);
> +virDomainGraphicsDefFree(vnc);
> +VIR_FREE(orig_opts);
> +goto error;
> +} else {
> +vnc->data.vnc.sharePolicy = policy;
> +}
> +} else {
> +virReportError(VIR_ERR_INTERNAL_ERROR,

missing "%s" breaks syntax-check

> +   _("missing vnc sharing 
> policy"));
> +virDomainGraphicsDefFree(vnc);
> +VIR_FREE(orig_opts);
> +goto error;
> +}
>  }
>  
>  opts = nextopt;

Jan

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


Re: [libvirt] [PATCH 0/3] Resolve Coverity found issues

2013-05-21 Thread John Ferlan
On 05/16/2013 10:01 AM, John Ferlan wrote:
> Upgraded to Coverity 6.5.3 which uncovered a few code paths with issues.
> 
> John Ferlan (3):
>   lxc_process: Resolve Coverity NULL_RETURNS error
>   xencapstest: Resolve Coverity CHECKED_RETURN error
>   shunloadtest: Resolve Coverity CHECKED_RETURN error
> 
>  src/lxc/lxc_process.c  |  4 ++--
>  tests/shunloadhelper.c | 12 
>  tests/shunloadtest.c   | 26 +-
>  tests/xencapstest.c|  3 ++-
>  4 files changed, 29 insertions(+), 16 deletions(-)
> 

patches 2/3 and 3/3 were pushed, I'm reworking 1/3 to store the
virConnectPtr

John

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


[libvirt] [PATCH v2] interface: list all interfaces with flags == 0

2013-05-21 Thread Guannan Ren
virConnectListAllInterfaces should support to list all of
interfaces when the value of flags is 0. The behaviour is
consistent with other virConnectListAll* APIs
---
 src/conf/interface_conf.h   |  4 
 src/interface/interface_backend_netcf.c | 29 +++--
 src/interface/interface_backend_udev.c  | 25 -
 3 files changed, 31 insertions(+), 27 deletions(-)

diff --git a/src/conf/interface_conf.h b/src/conf/interface_conf.h
index e636c35..ae93811 100644
--- a/src/conf/interface_conf.h
+++ b/src/conf/interface_conf.h
@@ -211,4 +211,8 @@ char *virInterfaceDefFormat(const virInterfaceDefPtr def);
 void virInterfaceObjLock(virInterfaceObjPtr obj);
 void virInterfaceObjUnlock(virInterfaceObjPtr obj);
 
+#define VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE   \
+(VIR_CONNECT_LIST_INTERFACES_ACTIVE | \
+ VIR_CONNECT_LIST_INTERFACES_INACTIVE)
+
 #endif /* __INTERFACE_CONF_H__ */
diff --git a/src/interface/interface_backend_netcf.c 
b/src/interface/interface_backend_netcf.c
index cbba4fd..d626017 100644
--- a/src/interface/interface_backend_netcf.c
+++ b/src/interface/interface_backend_netcf.c
@@ -260,6 +260,7 @@ static int netcfConnectListDefinedInterfaces(virConnectPtr 
conn, char **const na
 
 }
 
+#define MATCH(FLAG) (flags & (FLAG))
 static int
 netcfConnectListAllInterfaces(virConnectPtr conn,
   virInterfacePtr **ifaces,
@@ -276,8 +277,7 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
 int ret = -1;
 char **names = NULL;
 
-virCheckFlags(VIR_CONNECT_LIST_INTERFACES_ACTIVE |
-  VIR_CONNECT_LIST_INTERFACES_INACTIVE, -1);
+virCheckFlags(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE, -1);
 
 interfaceDriverLock(driver);
 
@@ -293,7 +293,6 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
_("failed to get number of host interfaces: %s%s%s"),
errmsg, details ? " - " : "",
details ? details : "");
-ret = -1;
 goto cleanup;
 }
 
@@ -304,7 +303,6 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
 
 if (VIR_ALLOC_N(names, count) < 0) {
 virReportOOMError();
-ret = -1;
 goto cleanup;
 }
 
@@ -361,16 +359,19 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
 /* XXX: Filter the result, need to be splitted once new filter flags
  * except active|inactive are supported.
  */
-if (((status & NETCF_IFACE_ACTIVE) &&
- (flags & VIR_CONNECT_LIST_INTERFACES_ACTIVE)) ||
-((status & NETCF_IFACE_INACTIVE) &&
- (flags & VIR_CONNECT_LIST_INTERFACES_INACTIVE))) {
-if (ifaces) {
-iface_obj = virGetInterface(conn, ncf_if_name(iface),
-ncf_if_mac_string(iface));
-tmp_iface_objs[niface_objs] = iface_obj;
-}
-niface_objs++;
+if (MATCH(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE) &&
+!((MATCH(VIR_CONNECT_LIST_INTERFACES_ACTIVE) &&
+   (status & NETCF_IFACE_ACTIVE)) ||
+  (MATCH(VIR_CONNECT_LIST_INTERFACES_INACTIVE) &&
+   (status & NETCF_IFACE_INACTIVE {
+ncf_if_free(iface);
+continue;
+}
+
+if (ifaces) {
+iface_obj = virGetInterface(conn, ncf_if_name(iface),
+ncf_if_mac_string(iface));
+tmp_iface_objs[niface_objs++] = iface_obj;
 }
 
 ncf_if_free(iface);
diff --git a/src/interface/interface_backend_udev.c 
b/src/interface/interface_backend_udev.c
index 1fd7d46..428adc8 100644
--- a/src/interface/interface_backend_udev.c
+++ b/src/interface/interface_backend_udev.c
@@ -282,6 +282,7 @@ udevConnectListDefinedInterfaces(virConnectPtr conn,
   VIR_UDEV_IFACE_INACTIVE);
 }
 
+#define MATCH(FLAG) (flags & (FLAG))
 static int
 udevConnectListAllInterfaces(virConnectPtr conn,
  virInterfacePtr **ifaces,
@@ -299,8 +300,7 @@ udevConnectListAllInterfaces(virConnectPtr conn,
 int status = 0;
 int ret;
 
-virCheckFlags(VIR_CONNECT_LIST_INTERFACES_ACTIVE |
-  VIR_CONNECT_LIST_INTERFACES_INACTIVE, -1);
+virCheckFlags(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE, -1);
 
 /* Grab a udev reference */
 udev = udev_ref(driverState->udev);
@@ -354,7 +354,6 @@ udevConnectListAllInterfaces(virConnectPtr conn,
 const char *path;
 const char *name;
 const char *macaddr;
-int add_to_list = 0;
 
 path = udev_list_entry_get_name(dev_entry);
 dev = udev_device_new_from_syspath(udev, path);
@@ -363,18 +362,17 @@ udevConnectListAllInterfaces(virConnectPtr conn,
 status = STREQ(udev_device_get_sysattr_value(dev, "operstate"), "up");
 
 /* Filter the results */
-if (stat

[libvirt] [PATCH] udev: should not list bridge devices

2013-05-21 Thread Guannan Ren
When using udev backend, virsh iface-list outputs bridge devices
like:
 Name State  MAC Address
 
 em1  active e8:39:35:58:d5:94
 lo   active 00:00:00:00:00:00
 virbr0   active fe:54:00:a5:f6:42

The patch filters out bridge devices.

---
 src/interface/interface_backend_udev.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/interface/interface_backend_udev.c 
b/src/interface/interface_backend_udev.c
index 1fd7d46..92648e8 100644
--- a/src/interface/interface_backend_udev.c
+++ b/src/interface/interface_backend_udev.c
@@ -78,6 +78,9 @@ udevGetDevices(struct udev *udev, virUdevStatus status)
 /* Ignore devices that are part of a bridge */
 udev_enumerate_add_nomatch_sysattr(enumerate, "brport/state", NULL);
 
+/* Ignore bridge devices */
+udev_enumerate_add_nomatch_sysattr(enumerate, "bridge/bridge_id", NULL);
+
 /* State of the device */
 switch (status) {
 case VIR_UDEV_IFACE_ACTIVE:
-- 
1.8.1.4

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


Re: [libvirt] two hostdev devices problem

2013-05-21 Thread Dominik Mostowiec
Hmm,
It seems to be working (after only simple tests).

--
Dominik


2013/5/21 Ján Tomko 

> On 05/21/2013 01:37 PM, Laine Stump wrote:
> > On 05/21/2013 04:03 AM, Ján Tomko wrote:
> >> On 05/21/2013 09:32 AM, Dominik Mostowiec wrote:
> >>> hi,
> >>> I try to add 2 VF by "hostdev".
> >>> Networks (vnet0, vnet1) with:
> >>>  
> >>> 
> >>> .
> >>>
> >>> Domain:
> >>> 
> >>>  
> >>> 
> >>> 
> >>>  
> >>> 
> >>>
> >>> virsh create error:
> >>> "error: internal error process exited while connecting to monitor: kvm:
> >>> -device
> pci-assign,configfd=25,host=01:10.1,id=hostdev0,bus=pci.0,addr=0x4:
> >>> Duplicate ID 'hostdev0' for device"
> >>>
> >> Hi,
> >>
> >> it seems we have been assigning the same id to all network hostdevs
> until this
> >> recent commit (not yet released):
> >>
> >> http://libvirt.org/git/?p=libvirt.git;a=commitdiff;h=6597cc25
> >
> >
> > If that patch has such an effect, it's purely accidental. Have you
> > tested this? (I plan to test a before and after as soon as I've had
> > breakfast)
> >
>
> I haven't tested it and looking at the code again, I might've been wrong :(
>
> Sorry about that.
>
> Jan
>
>
>
>


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

Re: [libvirt] [PATCH 06/11] Convert Xen domain VCPU driver methods to use virDomainDefPtr

2013-05-21 Thread Daniel P. Berrange
On Mon, May 20, 2013 at 12:14:04PM -0600, Jim Fehlig wrote:
> Daniel P. Berrange wrote:
> > From: "Daniel P. Berrange" 
> >
> > Introduce use of a virDomainDefPtr in the domain VCPU
> > APIs to simplify introduction of ACL security checks.
> > The virDomainPtr cannot be safely used, since the app
> > may have supplied mis-matching name/uuid/id fields. eg
> > the name points to domain X, while the uuid points to
> > domain Y. Resolving the virDomainPtr to a virDomainDefPtr
> > ensures a consistent name/uuid/id set.
> >
> > Signed-off-by: Daniel P. Berrange 
> > ---
> >  src/xen/xen_driver.c | 84 
> > 
> >  src/xen/xen_hypervisor.c | 42 
> >  src/xen/xen_hypervisor.h |  9 --
> >  src/xen/xend_internal.c  | 81 
> > ++
> >  src/xen/xend_internal.h  | 17 ++
> >  src/xen/xm_internal.c| 30 +
> >  src/xen/xm_internal.h| 19 ---
> >  7 files changed, 187 insertions(+), 95 deletions(-)
> >
> > diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
> > index 8b7dec9..04cb69d 100644
> > --- a/src/xen/xen_driver.c
> > +++ b/src/xen/xen_driver.c
> > @@ -647,11 +647,30 @@ xenUnifiedConnectNumOfDomains(virConnectPtr conn)
> >  
> >  static virDomainPtr
> >  xenUnifiedDomainCreateXML(virConnectPtr conn,
> > -  const char *xmlDesc, unsigned int flags)
> > +  const char *xml,
> > +  unsigned int flags)
> >  {
> > +xenUnifiedPrivatePtr priv = conn->privateData;
> > +virDomainDefPtr def = NULL;
> > +virDomainPtr ret = NULL;
> > +
> >  virCheckFlags(0, NULL);
> >  
> > -return xenDaemonCreateXML(conn, xmlDesc);
> > +if (!(def = virDomainDefParseString(xml, priv->caps, priv->xmlopt,
> > +1 << VIR_DOMAIN_VIRT_XEN,
> > +VIR_DOMAIN_XML_INACTIVE)))
> > +goto cleanup;
> > +
> > +if (xenDaemonCreateXML(conn, def) < 0)
> > +goto cleanup;
> > +
> > +ret = virGetDomain(conn, def->name, def->uuid);
> > +if (ret)
> > +ret->id = def->id;
> > +
> > +cleanup:
> > +virDomainDefFree(def);
> > +return ret;
> >  }
> >   
> 
> Should this hunk be in patch 2? Or perhaps it was meant for patch 5?

Hmm, actually, yes, it should be in the previous patch.

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/11] Convert Xen domain start/migration APIs to use virDomainDefPtr

2013-05-21 Thread Daniel P. Berrange
On Mon, May 20, 2013 at 11:40:34AM -0600, Jim Fehlig wrote:
> I finally have some time to continue reviewing this series...
> 
> Daniel P. Berrange wrote:
> > From: "Daniel P. Berrange" 
> >
> > Introduce use of a virDomainDefPtr in the domain migrate &
> > start APIs to simplify introduction of ACL security checks.
> >   
> 
> Not really the 'start' API, but GetXMLDesc, Define, and Undefine. Should
> those be part of the lifecycle changes made in patch 2?

Opps bad description. I tried to make each patch as small as
possible. So where I grouped several methods together, I only
did it because they were mutually dependent wrt the refactoring.
Will fix the description of this commit.


> > @@ -44,7 +44,8 @@ int xenXMDomainGetState(virConnectPtr conn,
> >  virDomainDefPtr def,
> >  int *state,
> >  int *reason);
> > -char *xenXMDomainGetXMLDesc(virDomainPtr domain, unsigned int flags);
> > +virDomainDefPtr xenXMDomainGetXMLDesc(virConnectPtr conn,
> > +  virDomainDefPtr def);
> >   
> 
> This still squeezes into one line too.

As you've probably seen by now, I've preferred to split the lines
when there are > 1 parameter in the method, even if it would
technically fit on one line.


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] interface: list all interfaces with flags == 0

2013-05-21 Thread Guannan Ren

On 05/21/2013 08:15 PM, Jiri Denemark wrote:

On Tue, May 21, 2013 at 17:05:09 +0800, Guan Nan Ren wrote:

virConnectListAllInterfaces should support to list all of
interfaces when the value of flags is 0. The behaviour is
consistent with other virConnectListAll* APIs
---
diff --git a/src/interface/interface_backend_netcf.c 
b/src/interface/interface_backend_netcf.c
index cbba4fd..c6e069a 100644
--- a/src/interface/interface_backend_netcf.c
+++ b/src/interface/interface_backend_netcf.c

...

@@ -361,16 +359,17 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
  /* XXX: Filter the result, need to be splitted once new filter flags
   * except active|inactive are supported.
   */
-if (((status & NETCF_IFACE_ACTIVE) &&
- (flags & VIR_CONNECT_LIST_INTERFACES_ACTIVE)) ||
-((status & NETCF_IFACE_INACTIVE) &&
- (flags & VIR_CONNECT_LIST_INTERFACES_INACTIVE))) {
-if (ifaces) {
-iface_obj = virGetInterface(conn, ncf_if_name(iface),
-ncf_if_mac_string(iface));
-tmp_iface_objs[niface_objs] = iface_obj;
-}
-niface_objs++;
+if (MATCH(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE) &&
+!((MATCH(VIR_CONNECT_LIST_INTERFACES_ACTIVE) &&
+   (status & NETCF_IFACE_ACTIVE)) ||
+  (MATCH(VIR_CONNECT_LIST_INTERFACES_INACTIVE) &&
+   (status & NETCF_IFACE_INACTIVE
+continue;

IMHO this is much harder to read. I'd just rewrite the original
condition as (i.e., !MATCH(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE)
is the part that was missing):

 if (!MATCH(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE) ||
 (MATCH(VIR_CONNECT_LIST_INTERFACES_ACTIVE) &&
  (status & NETCF_IFACE_ACTIVE)) ||
 (MATCH(VIR_CONNECT_LIST_INTERFACES_INACTIVE) &&
  (status & NETCF_IFACE_INACTIVE)))

Moreover, your version is wrong as it skips ncf_if_free(iface) in case
iface should be skipped.


yes, currently, there are only one group of flags with two 
values(active/inactive),

the way of yours is better to read.
if in future, there are more than one group of flags which are 
going to support,
the way of my version will be better. virConnectListAllDomains 
use this way to

filter list of domains.

Guannan

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


Re: [libvirt] [PATCH] interface: list all interfaces with flags == 0

2013-05-21 Thread Jiri Denemark
On Tue, May 21, 2013 at 17:05:09 +0800, Guan Nan Ren wrote:
> virConnectListAllInterfaces should support to list all of
> interfaces when the value of flags is 0. The behaviour is
> consistent with other virConnectListAll* APIs
> ---
> diff --git a/src/interface/interface_backend_netcf.c 
> b/src/interface/interface_backend_netcf.c
> index cbba4fd..c6e069a 100644
> --- a/src/interface/interface_backend_netcf.c
> +++ b/src/interface/interface_backend_netcf.c
...
> @@ -361,16 +359,17 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
>  /* XXX: Filter the result, need to be splitted once new filter flags
>   * except active|inactive are supported.
>   */
> -if (((status & NETCF_IFACE_ACTIVE) &&
> - (flags & VIR_CONNECT_LIST_INTERFACES_ACTIVE)) ||
> -((status & NETCF_IFACE_INACTIVE) &&
> - (flags & VIR_CONNECT_LIST_INTERFACES_INACTIVE))) {
> -if (ifaces) {
> -iface_obj = virGetInterface(conn, ncf_if_name(iface),
> -ncf_if_mac_string(iface));
> -tmp_iface_objs[niface_objs] = iface_obj;
> -}
> -niface_objs++;
> +if (MATCH(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE) &&
> +!((MATCH(VIR_CONNECT_LIST_INTERFACES_ACTIVE) &&
> +   (status & NETCF_IFACE_ACTIVE)) ||
> +  (MATCH(VIR_CONNECT_LIST_INTERFACES_INACTIVE) &&
> +   (status & NETCF_IFACE_INACTIVE
> +continue;

IMHO this is much harder to read. I'd just rewrite the original
condition as (i.e., !MATCH(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE)
is the part that was missing):

if (!MATCH(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE) ||
(MATCH(VIR_CONNECT_LIST_INTERFACES_ACTIVE) &&
 (status & NETCF_IFACE_ACTIVE)) ||
(MATCH(VIR_CONNECT_LIST_INTERFACES_INACTIVE) &&
 (status & NETCF_IFACE_INACTIVE)))

Moreover, your version is wrong as it skips ncf_if_free(iface) in case
iface should be skipped.

> +
> +if (ifaces) {
> +iface_obj = virGetInterface(conn, ncf_if_name(iface),
> +ncf_if_mac_string(iface));
> +tmp_iface_objs[niface_objs++] = iface_obj;
>  }
>  
>  ncf_if_free(iface);
> diff --git a/src/interface/interface_backend_udev.c 
> b/src/interface/interface_backend_udev.c
> index 1fd7d46..242fc15 100644
> --- a/src/interface/interface_backend_udev.c
> +++ b/src/interface/interface_backend_udev.c
...
> @@ -363,18 +362,15 @@ udevConnectListAllInterfaces(virConnectPtr conn,
>  status = STREQ(udev_device_get_sysattr_value(dev, "operstate"), 
> "up");
>  
>  /* Filter the results */
> -if (status && (flags & VIR_CONNECT_LIST_INTERFACES_ACTIVE))
> -add_to_list = 1;
> -else if (!status && (flags & VIR_CONNECT_LIST_INTERFACES_INACTIVE))
> -add_to_list = 1;
> +if (MATCH(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE) &&
> +!((MATCH(VIR_CONNECT_LIST_INTERFACES_ACTIVE) && status) ||
> +  (MATCH(VIR_CONNECT_LIST_INTERFACES_INACTIVE) && !status)))
> +continue;

Same bug in skipping udev_device_unref(dev). And similarly hard to read
test :-)

>  
>  /* If we matched a filter, then add it */
> -if (add_to_list) {
> -if (ifaces) {
> -iface_obj = virGetInterface(conn, name, macaddr);
> -ifaces_list[count] = iface_obj;
> -}
> -count++;
> +if (ifaces) {
> +iface_obj = virGetInterface(conn, name, macaddr);
> +ifaces_list[count++] = iface_obj;
>  }
>  udev_device_unref(dev);
>  }

Jirka

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


Re: [libvirt] [Qemu-devel] [qemu-devel] Default machine type setting for ppc64

2013-05-21 Thread Peter Maydell
On 21 May 2013 13:04, Anthony Liguori  wrote:
> We've talked in the past about having an accelerator specific machine
> default.  I think this is a perfectly reasonable thing to do and would
> solve the problem for ARM and for PPC.

For ARM I would prefer not to have a default at all, and make
the next level up specify it. It's reasonable to have a default
machine choice for when you create a VM configuration; it's
not so sensible to have a default that's picked every time
you run the VM. The thing I think is most likely to be the
useful choice for KVM/ARM isn't even in the tree yet...

There's no user level difference between "pick whether you
wanted a model of a versatile-PB or a zaurus" and "pick
whether you wanted a model of an x86-PC or an ARM zaurus".
At the moment we require the user to specify the latter choice
(by having them in separate executables) but try to guess
the former.

> That said, why is mac99 the default?

Presumably because it was a sensible choice when it was originally
put in, and once you have a default you can't change it without
breaking peoples' command lines.

thanks
-- PMM

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


Re: [libvirt] [Qemu-devel] [qemu-devel] Default machine type setting for ppc64

2013-05-21 Thread Anthony Liguori
"Daniel P. Berrange"  writes:

> On Tue, May 21, 2013 at 07:55:27PM +1000, Paul Mackerras wrote:
>> On Tue, May 21, 2013 at 09:39:53AM +0100, Daniel P. Berrange wrote:
>> > QEMU has the notion of a default machine for each target, and that is
>> > what libvirt uses if the user hasn't specified a machine.  It is not
>> > libvirt's job to override QEMU's notion of the default machine here,
>> > so if the 'mac99' machine type isn't suitable as the default either
>> > QEMU needs to change that for the ppc target, or the user needs to
>> > explicitly specify their desired machine type.
>> 
>> We are getting the default changed to 'pseries', at least for cases
>> where pseries support is compiled in, which isn't necessarily
>> always.  That will of course not satisfy the Freescale guys.
>> 
>> I think libvirt needs some more sensible way to ask qemu what its
>> capabilities are.  Currently it has no way to ask qemu "what machines
>> can you emulate with kvm acceleration?"  If the user has asked for a
>> KVM domain then the default machine should be one that can be provided
>> by KVM.  At present it isn't, on PowerPC.
>
> If QEMU can provide more intelligent info in this respect, then
> libvirt can use it. We're doing the best we can with picking
> defaults given the info QEMU currently provides us.

We've talked in the past about having an accelerator specific machine
default.  I think this is a perfectly reasonable thing to do and would
solve the problem for ARM and for PPC.

That said, why is mac99 the default?  It doesn't seem to work at all for
me.  Even with TCG, I've had more luck with -M pseries.

While adding an accelerator specific default, if mac99 is the wrong
default for TCG, then we should change it.

Regards,

Anthony Liguori

>
>
> 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] two hostdev devices problem

2013-05-21 Thread Ján Tomko
On 05/21/2013 01:37 PM, Laine Stump wrote:
> On 05/21/2013 04:03 AM, Ján Tomko wrote:
>> On 05/21/2013 09:32 AM, Dominik Mostowiec wrote:
>>> hi,
>>> I try to add 2 VF by "hostdev".
>>> Networks (vnet0, vnet1) with:
>>>  
>>> 
>>> .
>>>
>>> Domain: 
>>> 
>>>  
>>> 
>>> 
>>>  
>>> 
>>>
>>> virsh create error:
>>> "error: internal error process exited while connecting to monitor: kvm:
>>> -device pci-assign,configfd=25,host=01:10.1,id=hostdev0,bus=pci.0,addr=0x4:
>>> Duplicate ID 'hostdev0' for device"
>>>
>> Hi,
>>
>> it seems we have been assigning the same id to all network hostdevs until 
>> this
>> recent commit (not yet released):
>>
>> http://libvirt.org/git/?p=libvirt.git;a=commitdiff;h=6597cc25
> 
> 
> If that patch has such an effect, it's purely accidental. Have you
> tested this? (I plan to test a before and after as soon as I've had
> breakfast)
> 

I haven't tested it and looking at the code again, I might've been wrong :(

Sorry about that.

Jan



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


Re: [libvirt] two hostdev devices problem

2013-05-21 Thread Laine Stump
On 05/21/2013 04:03 AM, Ján Tomko wrote:
> On 05/21/2013 09:32 AM, Dominik Mostowiec wrote:
>> hi,
>> I try to add 2 VF by "hostdev".
>> Networks (vnet0, vnet1) with:
>>  
>> 
>> .
>>
>> Domain: 
>> 
>>  
>> 
>> 
>>  
>> 
>>
>> virsh create error:
>> "error: internal error process exited while connecting to monitor: kvm:
>> -device pci-assign,configfd=25,host=01:10.1,id=hostdev0,bus=pci.0,addr=0x4:
>> Duplicate ID 'hostdev0' for device"
>>
> Hi,
>
> it seems we have been assigning the same id to all network hostdevs until this
> recent commit (not yet released):
>
> http://libvirt.org/git/?p=libvirt.git;a=commitdiff;h=6597cc25


If that patch has such an effect, it's purely accidental. Have you
tested this? (I plan to test a before and after as soon as I've had
breakfast)

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


Re: [libvirt] [PATCH] qemu: fix a typo in qemuAddSharedDevice

2013-05-21 Thread Daniel P. Berrange
On Tue, May 21, 2013 at 06:40:34PM +0800, Guannan Ren wrote:
> ---
>  src/qemu/qemu_conf.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
> index 41fe0b9..7266d3b 100644
> --- a/src/qemu/qemu_conf.c
> +++ b/src/qemu/qemu_conf.c
> @@ -1184,7 +1184,7 @@ qemuAddSharedDevice(virQEMUDriverPtr driver,
>  if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
>  disk = dev->data.disk;
>  
> -if (disk->shared ||
> +if (!disk->shared ||
>  !disk->src ||
>  (disk->type != VIR_DOMAIN_DISK_TYPE_BLOCK &&
>   !(disk->type == VIR_DOMAIN_DISK_TYPE_VOLUME &&


This code is a good candidate for creation of unit tests to validate
the qemuAddSharedDevice / qemuRemoveSharedDevice operation with
various different configs.


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] qemu: fix a typo in qemuAddSharedDevice

2013-05-21 Thread Osier Yang

On 21/05/13 18:40, Guannan Ren wrote:

---
  src/qemu/qemu_conf.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 41fe0b9..7266d3b 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1184,7 +1184,7 @@ qemuAddSharedDevice(virQEMUDriverPtr driver,
  if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
  disk = dev->data.disk;
  
-if (disk->shared ||

+if (!disk->shared ||
  !disk->src ||
  (disk->type != VIR_DOMAIN_DISK_TYPE_BLOCK &&
   !(disk->type == VIR_DOMAIN_DISK_TYPE_VOLUME &&


ACK.

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


[libvirt] [PATCH] qemu: fix a typo in qemuAddSharedDevice

2013-05-21 Thread Guannan Ren
---
 src/qemu/qemu_conf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 41fe0b9..7266d3b 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1184,7 +1184,7 @@ qemuAddSharedDevice(virQEMUDriverPtr driver,
 if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
 disk = dev->data.disk;
 
-if (disk->shared ||
+if (!disk->shared ||
 !disk->src ||
 (disk->type != VIR_DOMAIN_DISK_TYPE_BLOCK &&
  !(disk->type == VIR_DOMAIN_DISK_TYPE_VOLUME &&
-- 
1.8.1.4

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


Re: [libvirt] [Qemu-devel] [qemu-devel] Default machine type setting for ppc64

2013-05-21 Thread Peter Maydell
On 21 May 2013 11:01, Daniel P. Berrange  wrote:
> On Tue, May 21, 2013 at 07:55:27PM +1000, Paul Mackerras wrote:
>> I think libvirt needs some more sensible way to ask qemu what its
>> capabilities are.  Currently it has no way to ask qemu "what machines
>> can you emulate with kvm acceleration?"  If the user has asked for a
>> KVM domain then the default machine should be one that can be provided
>> by KVM.  At present it isn't, on PowerPC.
>
> If QEMU can provide more intelligent info in this respect, then
> libvirt can use it.

I think this would make sense. Currently for ARM to get KVM
acceleration you have to use a specific guest CPU (A15), and
so you have to use a machine which supports that CPU (currently
just vexpress-a15). But we don't expose any way for libvirt to
tell that it needs an A15 or which machine models support which
CPUs. In fact we don't even give a sensible error message if
you try to use a wrong CPU, we'll just blithely push ahead
and behave very weirdly.

thanks
-- PMM

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


[libvirt] [PATCH 24/31] src/remote: Remove the whitespace before "; "

2013-05-21 Thread Osier Yang
---
 src/remote/remote_driver.c | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 13212d0..229a188 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -524,7 +524,7 @@ doRemoteOpen(virConnectPtr conn,
 int i;
 
 if (conn->uri) {
-for (i = 0; i < conn->uri->paramsCount ; i++) {
+for (i = 0; i < conn->uri->paramsCount; i++) {
 virURIParamPtr var = &conn->uri->params[i];
 EXTRACT_URI_ARG_STR("name", name);
 EXTRACT_URI_ARG_STR("command", command);
@@ -1335,7 +1335,7 @@ remoteNodeGetCellsFreeMemory(virConnectPtr conn,
  (xdrproc_t) xdr_remote_node_get_cells_free_memory_ret, (char 
*)&ret) == -1)
 goto done;
 
-for (i = 0 ; i < ret.cells.cells_len ; i++)
+for (i = 0; i < ret.cells.cells_len; i++)
 freeMems[i] = ret.cells.cells_val[i];
 
 xdr_free((xdrproc_t) xdr_remote_node_get_cells_free_memory_ret, (char *) 
&ret);
@@ -3540,7 +3540,7 @@ remoteAuthenticate(virConnectPtr conn, struct 
private_data *priv,
_("unknown authentication type %s"), authtype);
 return -1;
 }
-for (i = 0 ; i < ret.types.types_len ; i++) {
+for (i = 0; i < ret.types.types_len; i++) {
 if (ret.types.types_val[i] == want)
 type = want;
 }
@@ -3683,7 +3683,7 @@ static sasl_callback_t *remoteAuthMakeCallbacks(int 
*credtype, int ncredtype)
 return NULL;
 }
 
-for (i = 0, n = 0 ; i < ncredtype ; i++) {
+for (i = 0, n = 0; i < ncredtype; i++) {
 int id = remoteAuthCredVir2SASL(credtype[i]);
 if (id != 0)
 cbs[n++].id = id;
@@ -3712,7 +3712,7 @@ static int remoteAuthMakeCredentials(sasl_interact_t 
*interact,
 if (!cred)
 return -1;
 
-for (ninteract = 0, *ncred = 0 ; interact[ninteract].id != 0 ; 
ninteract++) {
+for (ninteract = 0, *ncred = 0; interact[ninteract].id != 0; ninteract++) {
 if (interact[ninteract].result)
 continue;
 (*ncred)++;
@@ -3721,7 +3721,7 @@ static int remoteAuthMakeCredentials(sasl_interact_t 
*interact,
 if (VIR_ALLOC_N(*cred, *ncred) < 0)
 return -1;
 
-for (ninteract = 0, *ncred = 0 ; interact[ninteract].id != 0 ; 
ninteract++) {
+for (ninteract = 0, *ncred = 0; interact[ninteract].id != 0; ninteract++) {
 if (interact[ninteract].result)
 continue;
 
@@ -3756,7 +3756,7 @@ static void 
remoteAuthFillInteract(virConnectCredentialPtr cred,
sasl_interact_t *interact)
 {
 int ninteract, ncred;
-for (ninteract = 0, ncred = 0 ; interact[ninteract].id != 0 ; ninteract++) 
{
+for (ninteract = 0, ncred = 0; interact[ninteract].id != 0; ninteract++) {
 if (interact[ninteract].result)
 continue;
 interact[ninteract].result = cred[ncred].result;
@@ -3796,7 +3796,7 @@ static int remoteAuthFillFromConfig(virConnectPtr conn,
 goto cleanup;
 }
 
-for (ninteract = 0 ; state->interact[ninteract].id != 0 ; ninteract++) {
+for (ninteract = 0; state->interact[ninteract].id != 0; ninteract++) {
 const char *value = NULL;
 
 switch (state->interact[ninteract].id) {
@@ -3846,7 +3846,7 @@ static void remoteAuthInteractStateClear(struct 
remoteAuthInteractState *state,
 if (!state)
 return;
 
-for (i = 0 ; i < state->ncred ; i++)
+for (i = 0; i < state->ncred; i++)
 VIR_FREE(state->cred[i].result);
 VIR_FREE(state->cred);
 state->ncred = 0;
@@ -4189,7 +4189,7 @@ remoteAuthPolkit(virConnectPtr conn, struct private_data 
*priv,
 /* Auth failed.  Ask client to obtain it and check again. */
 if (auth && auth->cb) {
 /* Check if the necessary credential type for PolicyKit is supported */
-for (i = 0 ; i < auth->ncredtype ; i++) {
+for (i = 0; i < auth->ncredtype; i++) {
 if (auth->credtype[i] == VIR_CRED_EXTERNAL)
 allowcb = 1;
 }
@@ -4488,7 +4488,7 @@ remoteDomainBuildEventGraphics(virNetClientProgramPtr 
prog ATTRIBUTE_UNUSED,
 if (VIR_ALLOC_N(subject->identities, msg->subject.subject_len) < 0)
 goto no_memory;
 subject->nidentity = msg->subject.subject_len;
-for (i = 0 ; i < subject->nidentity ; i++) {
+for (i = 0; i < subject->nidentity; i++) {
 if (!(subject->identities[i].type = 
strdup(msg->subject.subject_val[i].type)) ||
 !(subject->identities[i].name = 
strdup(msg->subject.subject_val[i].name)))
 goto no_memory;
@@ -4518,7 +4518,7 @@ no_memory:
 VIR_FREE(remoteAddr);
 }
 if (subject) {
-for (i = 0 ; i < subject->nidentity ; i++) {
+for (i = 0; i < subject->nidentity; i++) {
 VIR_FREE(subject->identities[i].type);
 VIR_FREE(subject->identities[i].name);
  

Re: [libvirt] [Qemu-devel] [qemu-devel] Default machine type setting for ppc64

2013-05-21 Thread Daniel P. Berrange
On Tue, May 21, 2013 at 07:55:27PM +1000, Paul Mackerras wrote:
> On Tue, May 21, 2013 at 09:39:53AM +0100, Daniel P. Berrange wrote:
> > On Tue, May 21, 2013 at 09:31:26AM +0100, Peter Maydell wrote:
> > > On 21 May 2013 09:19, Li Zhang  wrote:
> > > > We encounter this problem in openstack which always use
> > > > default machine type. Currently, QEMU sets mac99 as default
> > > > setting for ppc64 but it doesn't work on our platform at all.
> > > >
> > > > I tried to fix this in libvirt which it is not acceptable because
> > > > libvirt only considers to get default setting from QEMU.
> > > 
> > > This will need to be fixed for ARM -- the whole idea of there
> > > being a sensible "default machine type" and it being the one
> > > QEMU starts by default is pretty x86-centric. libvirt needs
> > > to have support for specifying which machine to use.
> > 
> > Libvirt has always had support for specifying what machine type to use.
> > This discussion is simply about what machine type to default to, if the
> > user hasn't explicitly asked for one.
> 
> So, the situation is that the XML in question has hvm,
> in the  section.  Does that say anything about what type of
> machine is being requested?

Obviously not, since you've not specified any machine type and
thus you'll get the default. If you don't like that, change your
app to request a specific machine type.

>  Why is the machine type in the 
> section rather than the  section?

That's just the way it was chosen to be represented when first
implemented. In hindsight that may be sub-optimal, but libvirt
will not change existing XML schema design since that breaks
back compatibilty which is worse.

> > QEMU has the notion of a default machine for each target, and that is
> > what libvirt uses if the user hasn't specified a machine.  It is not
> > libvirt's job to override QEMU's notion of the default machine here,
> > so if the 'mac99' machine type isn't suitable as the default either
> > QEMU needs to change that for the ppc target, or the user needs to
> > explicitly specify their desired machine type.
> 
> We are getting the default changed to 'pseries', at least for cases
> where pseries support is compiled in, which isn't necessarily
> always.  That will of course not satisfy the Freescale guys.
> 
> I think libvirt needs some more sensible way to ask qemu what its
> capabilities are.  Currently it has no way to ask qemu "what machines
> can you emulate with kvm acceleration?"  If the user has asked for a
> KVM domain then the default machine should be one that can be provided
> by KVM.  At present it isn't, on PowerPC.

If QEMU can provide more intelligent info in this respect, then
libvirt can use it. We're doing the best we can with picking
defaults given the info QEMU currently provides us.


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 22/31] src/utils: Remove the whitespace before "; "

2013-05-21 Thread Osier Yang
---
 src/util/virarch.c  |  2 +-
 src/util/virauth.c  |  2 +-
 src/util/vircgroup.c| 38 +++---
 src/util/vircommand.c   | 12 ++--
 src/util/vireventpoll.c | 22 +++---
 src/util/virhash.c  |  6 +++---
 src/util/viridentity.c  |  4 ++--
 src/util/virjson.c  | 16 
 src/util/virlockspace.c | 10 +-
 src/util/virportallocator.c |  2 +-
 src/util/virprocess.c   | 14 +++---
 src/util/virstoragefile.c   |  4 ++--
 src/util/virstring.c|  2 +-
 src/util/virthreadwin32.c   |  4 ++--
 src/util/viruri.c   |  2 +-
 src/util/virutil.c  |  2 +-
 16 files changed, 71 insertions(+), 71 deletions(-)

diff --git a/src/util/virarch.c b/src/util/virarch.c
index 8585a78..81558e5 100644
--- a/src/util/virarch.c
+++ b/src/util/virarch.c
@@ -128,7 +128,7 @@ const char *virArchToString(virArch arch)
 virArch virArchFromString(const char *archstr)
 {
 size_t i;
-for (i = 1 ; i < VIR_ARCH_LAST ; i++) {
+for (i = 1; i < VIR_ARCH_LAST; i++) {
 if (STREQ(virArchData[i].name, archstr))
 return i;
 }
diff --git a/src/util/virauth.c b/src/util/virauth.c
index fdcefe1..fd53097 100644
--- a/src/util/virauth.c
+++ b/src/util/virauth.c
@@ -57,7 +57,7 @@ int virAuthGetConfigFilePath(virConnectPtr conn,
 }
 
 if (conn && conn->uri) {
-for (i = 0 ; i < conn->uri->paramsCount ; i++) {
+for (i = 0; i < conn->uri->paramsCount; i++) {
 if (STREQ_NULLABLE(conn->uri->params[i].name, "authfile") &&
 conn->uri->params[i].value) {
 VIR_DEBUG("Using path from URI '%s'",
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 07ea2c3..329d84b 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -79,7 +79,7 @@ void virCgroupFree(virCgroupPtr *group)
 if (*group == NULL)
 return;
 
-for (i = 0 ; i < VIR_CGROUP_CONTROLLER_LAST ; i++) {
+for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
 VIR_FREE((*group)->controllers[i].mountPoint);
 VIR_FREE((*group)->controllers[i].linkPoint);
 VIR_FREE((*group)->controllers[i].placement);
@@ -112,7 +112,7 @@ static int virCgroupCopyMounts(virCgroupPtr group,
virCgroupPtr parent)
 {
 int i;
-for (i = 0 ; i < VIR_CGROUP_CONTROLLER_LAST ; i++) {
+for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
 if (!parent->controllers[i].mountPoint)
 continue;
 
@@ -154,7 +154,7 @@ static int virCgroupDetectMounts(virCgroupPtr group)
 if (STRNEQ(entry.mnt_type, "cgroup"))
 continue;
 
-for (i = 0 ; i < VIR_CGROUP_CONTROLLER_LAST ; i++) {
+for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
 const char *typestr = virCgroupControllerTypeToString(i);
 int typelen = strlen(typestr);
 char *tmp = entry.mnt_opts;
@@ -234,7 +234,7 @@ static int virCgroupCopyPlacement(virCgroupPtr group,
   virCgroupPtr parent)
 {
 int i;
-for (i = 0 ; i < VIR_CGROUP_CONTROLLER_LAST ; i++) {
+for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
 if (!group->controllers[i].mountPoint)
 continue;
 
@@ -311,7 +311,7 @@ static int virCgroupDetectPlacement(virCgroupPtr group,
 controllers++;
 selfpath++;
 
-for (i = 0 ; i < VIR_CGROUP_CONTROLLER_LAST ; i++) {
+for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
 const char *typestr = virCgroupControllerTypeToString(i);
 int typelen = strlen(typestr);
 char *tmp = controllers;
@@ -376,7 +376,7 @@ static int virCgroupDetect(virCgroupPtr group,
 
 if (controllers >= 0) {
 VIR_DEBUG("Validating controllers %d", controllers);
-for (i = 0 ; i < VIR_CGROUP_CONTROLLER_LAST ; i++) {
+for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
 VIR_DEBUG("Controller '%s' wanted=%s, mount='%s'",
   virCgroupControllerTypeToString(i),
   (1 << i) & controllers ? "yes" : "no",
@@ -391,7 +391,7 @@ static int virCgroupDetect(virCgroupPtr group,
 } else {
 /* Check whether a request to disable a controller
  * clashes with co-mounting of controllers */
-for (j = 0 ; j < VIR_CGROUP_CONTROLLER_LAST ; j++) {
+for (j = 0; j < VIR_CGROUP_CONTROLLER_LAST; j++) {
 if (j == i)
 continue;
 if (!((1 << j) & controllers))
@@ -411,7 +411,7 @@ static int virCgroupDetect(virCgroupPtr group,
 } else {
 VIR_DEBUG("Auto-detecting controllers");
 controllers = 0;
-for (i = 0 ; i < VIR_CGROUP_CONTROLLER_LAST ; i++) {
+for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
 VIR_DEBUG("Controller '%s' present=%s",
 

[libvirt] [PATCH 21/31] tests/: Remove the whitespace before ";"

2013-05-21 Thread Osier Yang
---
 tests/commandhelper.c|  6 +++---
 tests/eventtest.c| 18 +-
 tests/fdstreamtest.c | 14 +++---
 tests/libvirtdconftest.c |  2 +-
 tests/nodeinfotest.c |  2 +-
 tests/qemuhelptest.c |  2 +-
 tests/qemumonitortestutils.c |  2 +-
 tests/qemuxml2argvtest.c |  4 ++--
 tests/securityselinuxlabeltest.c | 12 ++--
 tests/ssh.c  |  4 ++--
 tests/testutils.c| 16 
 tests/vircgrouptest.c|  2 +-
 tests/virnetsockettest.c | 10 +-
 tests/viruritest.c   |  2 +-
 14 files changed, 48 insertions(+), 48 deletions(-)

diff --git a/tests/commandhelper.c b/tests/commandhelper.c
index d0b9718..e4cc5d2 100644
--- a/tests/commandhelper.c
+++ b/tests/commandhelper.c
@@ -65,7 +65,7 @@ int main(int argc, char **argv) {
 if (!log)
 goto error;
 
-for (i = 1 ; i < argc ; i++) {
+for (i = 1; i < argc; i++) {
 fprintf(log, "ARG:%s\n", argv[i]);
 }
 
@@ -88,14 +88,14 @@ int main(int argc, char **argv) {
 }
 qsort(newenv, n, sizeof(newenv[0]), envsort);
 
-for (i = 0 ; i < n ; i++) {
+for (i = 0; i < n; i++) {
 /* Ignore the variables used to instruct the loader into
  * behaving differently, as they could throw the tests off. */
 if (!STRPREFIX(newenv[i], "LD_"))
 fprintf(log, "ENV:%s\n", newenv[i]);
 }
 
-for (i = 0 ; i < sysconf(_SC_OPEN_MAX) ; i++) {
+for (i = 0; i < sysconf(_SC_OPEN_MAX); i++) {
 int f;
 int closed;
 if (i == fileno(log))
diff --git a/tests/eventtest.c b/tests/eventtest.c
index 700ea08..97d805a 100644
--- a/tests/eventtest.c
+++ b/tests/eventtest.c
@@ -144,7 +144,7 @@ verifyFired(const char *name, int handle, int timer)
 int handleFired = 0;
 int timerFired = 0;
 int i;
-for (i = 0 ; i < NUM_FDS ; i++) {
+for (i = 0; i < NUM_FDS; i++) {
 if (handles[i].fired) {
 if (i != handle) {
 virtTestResult(name, 1,
@@ -177,7 +177,7 @@ verifyFired(const char *name, int handle, int timer)
 }
 
 
-for (i = 0 ; i < NUM_TIME ; i++) {
+for (i = 0; i < NUM_TIME; i++) {
 if (timers[i].fired) {
 if (i != timer) {
 virtTestResult(name, 1,
@@ -248,11 +248,11 @@ static void
 resetAll(void)
 {
 int i;
-for (i = 0 ; i < NUM_FDS ; i++) {
+for (i = 0; i < NUM_FDS; i++) {
 handles[i].fired = 0;
 handles[i].error = EV_ERROR_NONE;
 }
-for (i = 0 ; i < NUM_TIME ; i++) {
+for (i = 0; i < NUM_TIME; i++) {
 timers[i].fired = 0;
 timers[i].error = EV_ERROR_NONE;
 }
@@ -265,7 +265,7 @@ mymain(void)
 pthread_t eventThread;
 char one = '1';
 
-for (i = 0 ; i < NUM_FDS ; i++) {
+for (i = 0; i < NUM_FDS; i++) {
 if (pipe(handles[i].pipeFD) < 0) {
 fprintf(stderr, "Cannot create pipe: %d", errno);
 return EXIT_FAILURE;
@@ -282,7 +282,7 @@ mymain(void)
 
 virEventPollInit();
 
-for (i = 0 ; i < NUM_FDS ; i++) {
+for (i = 0; i < NUM_FDS; i++) {
 handles[i].delete = -1;
 handles[i].watch =
 virEventPollAddHandle(handles[i].pipeFD[0],
@@ -291,7 +291,7 @@ mymain(void)
   &handles[i], NULL);
 }
 
-for (i = 0 ; i < NUM_TIME ; i++) {
+for (i = 0; i < NUM_TIME; i++) {
 timers[i].delete = -1;
 timers[i].timeout = -1;
 timers[i].timer =
@@ -432,9 +432,9 @@ mymain(void)
 if (finishJob("Deleted during dispatch", -1, 2) != EXIT_SUCCESS)
 return EXIT_FAILURE;
 
-for (i = 0 ; i < NUM_FDS - 1 ; i++)
+for (i = 0; i < NUM_FDS - 1; i++)
 virEventPollRemoveHandle(handles[i].watch);
-for (i = 0 ; i < NUM_TIME - 1 ; i++)
+for (i = 0; i < NUM_TIME - 1; i++)
 virEventPollRemoveTimeout(timers[i].timer);
 
 resetAll();
diff --git a/tests/fdstreamtest.c b/tests/fdstreamtest.c
index 9f780c9..a5aed14 100644
--- a/tests/fdstreamtest.c
+++ b/tests/fdstreamtest.c
@@ -60,7 +60,7 @@ static int testFDStreamReadCommon(const char *scratchdir, 
bool blocking)
 VIR_ALLOC_N(buf, PATTERN_LEN) < 0)
 goto cleanup;
 
-for (i = 0 ; i < PATTERN_LEN ; i++)
+for (i = 0; i < PATTERN_LEN; i++)
 pattern[i] = i;
 
 if (virAsprintf(&file, "%s/input.data", scratchdir) < 0)
@@ -69,7 +69,7 @@ static int testFDStreamReadCommon(const char *scratchdir, 
bool blocking)
 if ((fd = open(file, O_CREAT|O_WRONLY|O_EXCL, 0600)) < 0)
 goto cleanup;
 
-for (i = 0 ; i < 10 ; i++) {
+for (i = 0; i < 10; i++) {
 if (safewrite(fd, pattern, PATTERN_LEN) != PATTERN_LEN)
 goto cleanup;
 }
@@ -88,7 +88,7 @@ static int testFDStreamReadCommon(const char *scratchdir, 
bool blocking)
 O_RDONLY) < 0)
 goto cleanup;
 
-for (i = 0 ; i < 

[libvirt] [PATCH 27/31] python: Remove the whitespace before ";"

2013-05-21 Thread Osier Yang
---
 python/libvirt-lxc-override.c |  4 ++--
 python/libvirt-override.c | 16 
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/python/libvirt-lxc-override.c b/python/libvirt-lxc-override.c
index ead175f..c69affc 100644
--- a/python/libvirt-lxc-override.c
+++ b/python/libvirt-lxc-override.c
@@ -81,7 +81,7 @@ libvirt_lxc_virDomainLxcOpenNamespace(PyObject *self 
ATTRIBUTE_UNUSED,
 return VIR_PY_NONE;
 
 py_retval = PyList_New(c_retval);
-for (i = 0 ; i < c_retval ; i++) {
+for (i = 0; i < c_retval; i++) {
 PyObject *item = NULL;
 
 if ((item = PyInt_FromLong(fdlist[i])) == NULL)
@@ -95,7 +95,7 @@ libvirt_lxc_virDomainLxcOpenNamespace(PyObject *self 
ATTRIBUTE_UNUSED,
 return py_retval;
 
 error:
-for (i = 0 ; i < c_retval ; i++) {
+for (i = 0; i < c_retval; i++) {
 VIR_FORCE_CLOSE(fdlist[i]);
 }
 VIR_FREE(fdlist);
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index fd9ebb8..6ed2624 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -81,7 +81,7 @@ getPyVirTypedParameter(const virTypedParameterPtr params, int 
nparams)
 if ((info = PyDict_New()) == NULL)
 return NULL;
 
-for (i = 0 ; i < nparams ; i++) {
+for (i = 0; i < nparams; i++) {
 switch (params[i].type) {
 case VIR_TYPED_PARAM_INT:
 val = PyInt_FromLong(params[i].value.i);
@@ -1409,7 +1409,7 @@ libvirt_virDomainGetVcpus(PyObject *self ATTRIBUTE_UNUSED,
 if ((pycpumap = PyList_New(dominfo.nrVirtCpu)) == NULL)
 goto cleanup;
 
-for (i = 0 ; i < dominfo.nrVirtCpu ; i++) {
+for (i = 0; i < dominfo.nrVirtCpu; i++) {
 PyObject *info = PyTuple_New(4);
 PyObject *item = NULL;
 
@@ -1441,12 +1441,12 @@ libvirt_virDomainGetVcpus(PyObject *self 
ATTRIBUTE_UNUSED,
 Py_XDECREF(item);
 goto cleanup;
 }
-for (i = 0 ; i < dominfo.nrVirtCpu ; i++) {
+for (i = 0; i < dominfo.nrVirtCpu; i++) {
 PyObject *info = PyTuple_New(cpunum);
 int j;
 if (info == NULL)
 goto cleanup;
-for (j = 0 ; j < cpunum ; j++) {
+for (j = 0; j < cpunum; j++) {
 PyObject *item = NULL;
 if ((item = PyBool_FromLong(VIR_CPU_USABLE(cpumap, cpumaplen, i, 
j))) == NULL ||
 PyTuple_SetItem(info, j, item) < 0) {
@@ -1950,7 +1950,7 @@ static int 
virConnectCredCallbackWrapper(virConnectCredentialPtr cred,
 
 list = PyTuple_New(2);
 pycred = PyTuple_New(ncred);
-for (i = 0 ; i < ncred ; i++) {
+for (i = 0; i < ncred; i++) {
 PyObject *pycreditem;
 pycreditem = PyList_New(5);
 Py_INCREF(Py_None);
@@ -1985,7 +1985,7 @@ static int 
virConnectCredCallbackWrapper(virConnectCredentialPtr cred,
 
 ret = PyLong_AsLong(pyret);
 if (ret == 0) {
-for (i = 0 ; i < ncred ; i++) {
+for (i = 0; i < ncred; i++) {
 PyObject *pycreditem;
 PyObject *pyresult;
 char *result = NULL;
@@ -2036,7 +2036,7 @@ libvirt_virConnectOpenAuth(PyObject *self 
ATTRIBUTE_UNUSED, PyObject *args) {
 int i;
 if (VIR_ALLOC_N(auth.credtype, auth.ncredtype) < 0)
 return VIR_PY_NONE;
-for (i = 0 ; i < auth.ncredtype ; i++) {
+for (i = 0; i < auth.ncredtype; i++) {
 PyObject *val;
 val = PyList_GetItem(pycredtype, i);
 auth.credtype[i] = (int)PyLong_AsLong(val);
@@ -5655,7 +5655,7 @@ 
libvirt_virConnectDomainEventGraphicsCallback(virConnectPtr conn ATTRIBUTE_UNUSE
libvirt_constcharPtrWrap(remote->service));
 
 pyobj_subject = PyList_New(subject->nidentity);
-for (i = 0 ; i < subject->nidentity ; i++) {
+for (i = 0; i < subject->nidentity; i++) {
 PyObject *pair = PyTuple_New(2);
 PyTuple_SetItem(pair, 0, 
libvirt_constcharPtrWrap(subject->identities[i].type));
 PyTuple_SetItem(pair, 1, 
libvirt_constcharPtrWrap(subject->identities[i].name));
-- 
1.8.1.4

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


[libvirt] [PATCH 30/31] nwfitler: Change the comment style

2013-05-21 Thread Osier Yang
The more common habit is to add the comment after the statements.
---
 src/nwfilter/nwfilter_dhcpsnoop.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c 
b/src/nwfilter/nwfilter_dhcpsnoop.c
index b9921e5..451c783 100644
--- a/src/nwfilter/nwfilter_dhcpsnoop.c
+++ b/src/nwfilter/nwfilter_dhcpsnoop.c
@@ -369,7 +369,7 @@ virNWFilterSnoopListAdd(virNWFilterSnoopIPLeasePtr plnew,
 
 for (pl = *end; pl && plnew->timeout < pl->timeout;
  pl = pl->prev)
-/* empty */ ;
+; /* empty */
 
 if (!pl) {
 plnew->next = *start;
@@ -526,7 +526,7 @@ virNWFilterSnoopIPLeaseGetByIP(virNWFilterSnoopIPLeasePtr 
start,
 for (pl = start;
  pl && !virSocketAddrEqual(&pl->ipAddress, ipaddr);
  pl = pl->next)
-/* empty */ ;
+; /* empty */
 return pl;
 }
 
-- 
1.8.1.4

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


[libvirt] [PATCH 29/31] src/*.[ch]: Remove the whitespace before "; "

2013-05-21 Thread Osier Yang
---
 src/libvirt-lxc.c |  2 +-
 src/libvirt.c | 10 +-
 src/nodeinfo.c| 18 +-
 3 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/libvirt-lxc.c b/src/libvirt-lxc.c
index 6b4e995..f30b6c3 100644
--- a/src/libvirt-lxc.c
+++ b/src/libvirt-lxc.c
@@ -151,7 +151,7 @@ virDomainLxcEnterNamespace(virDomainPtr domain,
 
 if (virProcessSetNamespaces(nfdlist, fdlist) < 0) {
 if (oldfdlist && noldfdlist) {
-for (i = 0 ; i < *noldfdlist ; i++) {
+for (i = 0; i < *noldfdlist; i++) {
 VIR_FORCE_CLOSE((*oldfdlist)[i]);
 }
 VIR_FREE(*oldfdlist);
diff --git a/src/libvirt.c b/src/libvirt.c
index 4c018ec..b129611 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -150,7 +150,7 @@ static int 
virConnectAuthCallbackDefault(virConnectCredentialPtr cred,
  void *cbdata ATTRIBUTE_UNUSED) {
 int i;
 
-for (i = 0 ; i < ncred ; i++) {
+for (i = 0; i < ncred; i++) {
 char buf[1024];
 char *bufptr = buf;
 size_t len;
@@ -820,7 +820,7 @@ int virStateInitialize(bool privileged,
 if (virInitialize() < 0)
 return -1;
 
-for (i = 0 ; i < virStateDriverTabCount ; i++) {
+for (i = 0; i < virStateDriverTabCount; i++) {
 if (virStateDriverTab[i]->stateInitialize) {
 VIR_DEBUG("Running global init for %s state driver",
   virStateDriverTab[i]->name);
@@ -846,7 +846,7 @@ int virStateInitialize(bool privileged,
 int virStateCleanup(void) {
 int i, ret = 0;
 
-for (i = 0 ; i < virStateDriverTabCount ; i++) {
+for (i = 0; i < virStateDriverTabCount; i++) {
 if (virStateDriverTab[i]->stateCleanup &&
 virStateDriverTab[i]->stateCleanup() < 0)
 ret = -1;
@@ -864,7 +864,7 @@ int virStateCleanup(void) {
 int virStateReload(void) {
 int i, ret = 0;
 
-for (i = 0 ; i < virStateDriverTabCount ; i++) {
+for (i = 0; i < virStateDriverTabCount; i++) {
 if (virStateDriverTab[i]->stateReload &&
 virStateDriverTab[i]->stateReload() < 0)
 ret = -1;
@@ -882,7 +882,7 @@ int virStateReload(void) {
 int virStateStop(void) {
 int i, ret = 0;
 
-for (i = 0 ; i < virStateDriverTabCount ; i++) {
+for (i = 0; i < virStateDriverTabCount; i++) {
 if (virStateDriverTab[i]->stateStop &&
 virStateDriverTab[i]->stateStop())
 ret = 1;
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index 7118a0f..d8375ab 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -1478,9 +1478,9 @@ nodeCapsInitNUMAFake(virCapsPtr caps ATTRIBUTE_UNUSED)
 }
 
 id = 0;
-for (s = 0 ; s < nodeinfo.sockets ; s++) {
-for (c = 0 ; c < nodeinfo.cores ; c++) {
-for (t = 0 ; t < nodeinfo.threads ; t++) {
+for (s = 0; s < nodeinfo.sockets; s++) {
+for (c = 0; c < nodeinfo.cores; c++) {
+for (t = 0; t < nodeinfo.threads; t++) {
 cpus[id].id = id;
 cpus[id].socket_id = s;
 cpus[id].core_id = c;
@@ -1502,7 +1502,7 @@ nodeCapsInitNUMAFake(virCapsPtr caps ATTRIBUTE_UNUSED)
 return 0;
 
  error:
-for (; id >= 0 ; id--)
+for (; id >= 0; id--)
 virBitmapFree(cpus[id].siblings);
 VIR_FREE(cpus);
 return -1;
@@ -1637,7 +1637,7 @@ nodeCapsInitNUMA(virCapsPtr caps)
 goto cleanup;
 memset(allonesmask, 0xff, mask_n_bytes);
 
-for (n = 0 ; n <= numa_max_node() ; n++) {
+for (n = 0; n <= numa_max_node(); n++) {
 int i;
 /* The first time this returns -1, ENOENT if node doesn't exist... */
 if (numa_node_to_cpus(n, mask, mask_n_bytes) < 0) {
@@ -1655,14 +1655,14 @@ nodeCapsInitNUMA(virCapsPtr caps)
 /* Detect the amount of memory in the numa cell */
 memory = nodeGetCellMemory(n);
 
-for (ncpus = 0, i = 0 ; i < max_n_cpus ; i++)
+for (ncpus = 0, i = 0; i < max_n_cpus; i++)
 if (MASK_CPU_ISSET(mask, i))
 ncpus++;
 
 if (VIR_ALLOC_N(cpus, ncpus) < 0)
 goto cleanup;
 
-for (ncpus = 0, i = 0 ; i < max_n_cpus ; i++) {
+for (ncpus = 0, i = 0; i < max_n_cpus; i++) {
 if (MASK_CPU_ISSET(mask, i)) {
 if (virNodeCapsFillCPUInfo(i, cpus + ncpus++) < 0) {
 topology_failed = true;
@@ -1714,7 +1714,7 @@ nodeGetCellsFreeMemory(unsigned long long *freeMems,
 if (lastCell > maxCell)
 lastCell = maxCell;
 
-for (numCells = 0, n = startCell ; n <= lastCell ; n++) {
+for (numCells = 0, n = startCell; n <= lastCell; n++) {
 long long mem;
 if (numa_node_size64(n, &mem) < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -1740,7 +1740,7 @@ nodeGetFreeMemory(void)
 return nodeGetFreeMemoryFake();
 
 
-for (n = 0 ; n <= numa_max_node() ; n++) {
+for (n = 0; n <= numa_max_node(); n++) {
 long l

[libvirt] [PATCH 19/31] tools: Remove the whitespace before ";"

2013-05-21 Thread Osier Yang
---
 tools/virsh-domain.c   | 6 +++---
 tools/virsh-nodedev.c  | 6 +++---
 tools/virsh-nwfilter.c | 2 +-
 tools/virsh-secret.c   | 2 +-
 tools/virsh.c  | 4 ++--
 5 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index bb94ac1..bc42408 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -5295,7 +5295,7 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
 if ((ncpus = virDomainGetVcpus(dom,
cpuinfo, info.nrVirtCpu,
cpumaps, cpumaplen)) >= 0) {
-for (n = 0 ; n < ncpus ; n++) {
+for (n = 0; n < ncpus; n++) {
 vshPrint(ctl, "%-15s %d\n", _("VCPU:"), n);
 vshPrint(ctl, "%-15s %d\n", _("CPU:"), cpuinfo[n].cpu);
 vshPrint(ctl, "%-15s %s\n", _("State:"),
@@ -6819,7 +6819,7 @@ static int getSignalNumber(vshControl *ctl, const char 
*signame)
 char *lower = vshStrdup(ctl, signame);
 char *tmp = lower;
 
-for (i = 0 ; signame[i] ; i++)
+for (i = 0; signame[i]; i++)
 lower[i] = c_tolower(signame[i]);
 
 if (virStrToLong_i(lower, NULL, 10, &signum) >= 0)
@@ -7808,7 +7808,7 @@ cmdLxcEnterNamespace(vshControl *ctl, const vshCmd *cmd)
 }
 _exit(0);
 } else {
-for (i = 0 ; i < nfdlist ; i++)
+for (i = 0; i < nfdlist; i++)
 VIR_FORCE_CLOSE(fdlist[i]);
 VIR_FREE(fdlist);
 if (virProcessWait(pid, NULL) < 0)
diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c
index 592fa44..3657c5f 100644
--- a/tools/virsh-nodedev.c
+++ b/tools/virsh-nodedev.c
@@ -277,7 +277,7 @@ fallback:
 list->ndevices = 0;
 
 /* get the node devices */
-for (i = 0; i < ndevices ; i++) {
+for (i = 0; i < ndevices; i++) {
 if (!(device = virNodeDeviceLookupByName(ctl->conn, names[i])))
 continue;
 list->devices[list->ndevices++] = device;
@@ -481,14 +481,14 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd 
ATTRIBUTE_UNUSED)
 }
 }
 
-for (i = 0 ; i < list->ndevices; i++) {
+for (i = 0; i < list->ndevices; i++) {
 if (parents[i] == NULL &&
 vshTreePrint(ctl, vshNodeListLookup, &arrays,
  list->ndevices, i) < 0)
 ret = false;
 }
 
-for (i = 0 ; i < list->ndevices; i++)
+for (i = 0; i < list->ndevices; i++)
 VIR_FREE(parents[i]);
 VIR_FREE(parents);
 for (i = 0; i < list->ndevices; i++)
diff --git a/tools/virsh-nwfilter.c b/tools/virsh-nwfilter.c
index 5a360c2..c7a259a 100644
--- a/tools/virsh-nwfilter.c
+++ b/tools/virsh-nwfilter.c
@@ -309,7 +309,7 @@ fallback:
 list->nfilters = 0;
 
 /* get the network filters */
-for (i = 0; i < nfilters ; i++) {
+for (i = 0; i < nfilters; i++) {
 if (!(filter = virNWFilterLookupByName(ctl->conn, names[i])))
 continue;
 list->filters[list->nfilters++] = filter;
diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c
index 044629d..fb10119 100644
--- a/tools/virsh-secret.c
+++ b/tools/virsh-secret.c
@@ -439,7 +439,7 @@ fallback:
 list->nsecrets = 0;
 
 /* get the secrets */
-for (i = 0; i < nsecrets ; i++) {
+for (i = 0; i < nsecrets; i++) {
 if (!(secret = virSecretLookupByUUIDString(ctl->conn, uuids[i])))
 continue;
 list->secrets[list->nsecrets++] = secret;
diff --git a/tools/virsh.c b/tools/virsh.c
index bb79245..ecb7bd4 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -610,7 +610,7 @@ vshTreePrintInternal(vshControl *ctl,
 }
 
 /* Determine the index of the last child device */
-for (i = 0 ; i < num_devices ; i++) {
+for (i = 0; i < num_devices; i++) {
 const char *parent = (lookup)(i, true, opaque);
 
 if (parent && STREQ(parent, dev))
@@ -625,7 +625,7 @@ vshTreePrintInternal(vshControl *ctl,
 virBufferAddLit(indent, "  ");
 if (virBufferError(indent))
 goto cleanup;
-for (i = 0 ; i < num_devices ; i++) {
+for (i = 0; i < num_devices; i++) {
 const char *parent = (lookup)(i, true, opaque);
 
 if (parent && STREQ(parent, dev) &&
-- 
1.8.1.4

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


[libvirt] [PATCH 16/31] src/xen: Remove the whitespace before ';'

2013-05-21 Thread Osier Yang
---
 src/xen/xen_driver.c |  6 +++---
 src/xen/xen_driver.h |  2 +-
 src/xen/xen_hypervisor.c |  4 ++--
 src/xen/xen_inotify.c|  4 ++--
 src/xen/xm_internal.c|  4 ++--
 src/xen/xs_internal.c| 12 ++--
 6 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index cc54f7a..d9d8cd0 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -162,8 +162,8 @@ xenDomainUsedCpus(virDomainPtr dom)
 
 if ((ncpus = xenUnifiedDomainGetVcpus(dom, cpuinfo, nb_vcpu,
   cpumap, cpumaplen)) >= 0) {
-for (n = 0 ; n < ncpus ; n++) {
-for (m = 0 ; m < priv->nbNodeCpus; m++) {
+for (n = 0; n < ncpus; n++) {
+for (m = 0; m < priv->nbNodeCpus; m++) {
 bool used;
 ignore_value(virBitmapGetBit(cpulist, m, &used));
 if ((!used) &&
@@ -2201,7 +2201,7 @@ xenUnifiedRemoveDomainInfo(xenUnifiedDomainInfoListPtr 
list,
unsigned char *uuid)
 {
 int i;
-for (i = 0 ; i < list->count ; i++) {
+for (i = 0; i < list->count; i++) {
 if (list->doms[i]->id == id &&
 STREQ(list->doms[i]->name, name) &&
 !memcmp(list->doms[i]->uuid, uuid, VIR_UUID_BUFLEN)) {
diff --git a/src/xen/xen_driver.h b/src/xen/xen_driver.h
index e33610d..3c7a8cd 100644
--- a/src/xen/xen_driver.h
+++ b/src/xen/xen_driver.h
@@ -172,7 +172,7 @@ struct _xenUnifiedPrivate {
 int inotifyFD;
 int inotifyWatch;
 
-int  useXenConfigCache ;
+int  useXenConfigCache;
 xenUnifiedDomainInfoListPtr configInfoList;
 # endif
 
diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c
index 68a3ef4..1df0945 100644
--- a/src/xen/xen_hypervisor.c
+++ b/src/xen/xen_hypervisor.c
@@ -2384,7 +2384,7 @@ xenHypervisorMakeCapabilitiesInternal(virConnectPtr conn,
 }
 
 /* Search for existing matching (model,hvm) tuple */
-for (i = 0 ; i < nr_guest_archs ; i++) {
+for (i = 0; i < nr_guest_archs; i++) {
 if (guest_archs[i].arch == arch &&
 guest_archs[i].hvm == hvm) {
 break;
@@ -2631,7 +2631,7 @@ xenHypervisorLookupDomainByUUID(virConnectPtr conn, const 
unsigned char *uuid)
 }
 
 id = -1;
-for (i = 0 ; i < nids ; i++) {
+for (i = 0; i < nids; i++) {
 if (memcmp(XEN_GETDOMAININFOLIST_UUID(dominfos, i), uuid, 
VIR_UUID_BUFLEN) == 0) {
 id = XEN_GETDOMAININFOLIST_DOMAIN(dominfos, i);
 break;
diff --git a/src/xen/xen_inotify.c b/src/xen/xen_inotify.c
index e13c572..caed574 100644
--- a/src/xen/xen_inotify.c
+++ b/src/xen/xen_inotify.c
@@ -101,7 +101,7 @@ xenInotifyXendDomainsDirLookup(virConnectPtr conn,
 /* If we are here, the domain has gone away.
search for, and create a domain from the stored
list info */
-for (i = 0 ; i < priv->configInfoList->count ; i++) {
+for (i = 0; i < priv->configInfoList->count; i++) {
 if (!memcmp(rawuuid, priv->configInfoList->doms[i]->uuid, 
VIR_UUID_BUFLEN)) {
 *name = strdup(priv->configInfoList->doms[i]->name);
 if (!*name) {
@@ -175,7 +175,7 @@ xenInotifyXendDomainsDirRemoveEntry(virConnectPtr conn, 
const char *fname)
 }
 
 /* match and remove on uuid */
-for (i = 0 ; i < priv->configInfoList->count ; i++) {
+for (i = 0; i < priv->configInfoList->count; i++) {
 if (!memcmp(uuid, priv->configInfoList->doms[i]->uuid, 
VIR_UUID_BUFLEN)) {
 VIR_FREE(priv->configInfoList->doms[i]->name);
 VIR_FREE(priv->configInfoList->doms[i]);
diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c
index 66a6c4c..964be81 100644
--- a/src/xen/xm_internal.c
+++ b/src/xen/xm_internal.c
@@ -1357,7 +1357,7 @@ xenXMDomainDetachDeviceFlags(virDomainPtr domain,
 switch (dev->type) {
 case VIR_DOMAIN_DEVICE_DISK:
 {
-for (i = 0 ; i < def->ndisks ; i++) {
+for (i = 0; i < def->ndisks; i++) {
 if (def->disks[i]->dst &&
 dev->data.disk->dst &&
 STREQ(def->disks[i]->dst, dev->data.disk->dst)) {
@@ -1376,7 +1376,7 @@ xenXMDomainDetachDeviceFlags(virDomainPtr domain,
 
 case VIR_DOMAIN_DEVICE_NET:
 {
-for (i = 0 ; i < def->nnets ; i++) {
+for (i = 0; i < def->nnets; i++) {
 if (!virMacAddrCmp(&def->nets[i]->mac, &dev->data.net->mac)) {
 virDomainNetDefFree(def->nets[i]);
 if (i < (def->nnets - 1))
diff --git a/src/xen/xs_internal.c b/src/xen/xs_internal.c
index 496c30b..712ee82 100644
--- a/src/xen/xs_internal.c
+++ b/src/xen/xs_internal.c
@@ -718,7 +718,7 @@ xenStoreRemoveWatch(virConnectPtr conn, const char *path, 
const char *token)
 if (!list)
 return -1;
 
-for (i = 0 ; i < list->count ; i++) {
+for (i = 0; i < l

[libvirt] [PATCH 11/31] src/uml: Remove the whitespace before ';'

2013-05-21 Thread Osier Yang
---
 src/uml/uml_conf.c   | 12 ++--
 src/uml/uml_driver.c | 14 +++---
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/src/uml/uml_conf.c b/src/uml/uml_conf.c
index 52b705c..6e0725c 100644
--- a/src/uml/uml_conf.c
+++ b/src/uml/uml_conf.c
@@ -407,7 +407,7 @@ virCommandPtr umlBuildCommandLine(virConnectPtr conn,
 if (vm->def->os.root)
 virCommandAddArgPair(cmd, "root", vm->def->os.root);
 
-for (i = 0 ; i < vm->def->ndisks ; i++) {
+for (i = 0; i < vm->def->ndisks; i++) {
 virDomainDiskDefPtr disk = vm->def->disks[i];
 
 if (!STRPREFIX(disk->dst, "ubd")) {
@@ -419,7 +419,7 @@ virCommandPtr umlBuildCommandLine(virConnectPtr conn,
 virCommandAddArgPair(cmd, disk->dst, disk->src);
 }
 
-for (i = 0 ; i < vm->def->nnets ; i++) {
+for (i = 0; i < vm->def->nnets; i++) {
 char *ret = umlBuildCommandLineNet(conn, vm->def, vm->def->nets[i], i);
 if (!ret)
 goto error;
@@ -427,10 +427,10 @@ virCommandPtr umlBuildCommandLine(virConnectPtr conn,
 VIR_FREE(ret);
 }
 
-for (i = 0 ; i < UML_MAX_CHAR_DEVICE ; i++) {
+for (i = 0; i < UML_MAX_CHAR_DEVICE; i++) {
 virDomainChrDefPtr chr = NULL;
 char *ret = NULL;
-for (j = 0 ; j < vm->def->nconsoles ; j++)
+for (j = 0; j < vm->def->nconsoles; j++)
 if (vm->def->consoles[j]->target.port == i)
 chr = vm->def->consoles[j];
 if (chr)
@@ -442,10 +442,10 @@ virCommandPtr umlBuildCommandLine(virConnectPtr conn,
 VIR_FREE(ret);
 }
 
-for (i = 0 ; i < UML_MAX_CHAR_DEVICE ; i++) {
+for (i = 0; i < UML_MAX_CHAR_DEVICE; i++) {
 virDomainChrDefPtr chr = NULL;
 char *ret = NULL;
-for (j = 0 ; j < vm->def->nserials ; j++)
+for (j = 0; j < vm->def->nserials; j++)
 if (vm->def->serials[j]->target.port == i)
 chr = vm->def->serials[j];
 if (chr)
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index 321be0f..b238b0f 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -276,13 +276,13 @@ umlIdentifyChrPTY(struct uml_driver *driver,
 {
 int i;
 
-for (i = 0 ; i < dom->def->nconsoles; i++)
+for (i = 0; i < dom->def->nconsoles; i++)
 if (dom->def->consoles[i]->source.type == VIR_DOMAIN_CHR_TYPE_PTY)
 if (umlIdentifyOneChrPTY(driver, dom,
  dom->def->consoles[i], "con") < 0)
 return -1;
 
-for (i = 0 ; i < dom->def->nserials; i++)
+for (i = 0; i < dom->def->nserials; i++)
 if (dom->def->serials[i]->source.type == VIR_DOMAIN_CHR_TYPE_PTY &&
 umlIdentifyOneChrPTY(driver, dom,
  dom->def->serials[i], "ssl") < 0)
@@ -1004,7 +1004,7 @@ error:
 static void umlCleanupTapDevices(virDomainObjPtr vm) {
 int i;
 
-for (i = 0 ; i < vm->def->nnets ; i++) {
+for (i = 0; i < vm->def->nnets; i++) {
 virDomainNetDefPtr def = vm->def->nets[i];
 
 if (def->type != VIR_DOMAIN_NET_TYPE_BRIDGE &&
@@ -1092,7 +1092,7 @@ static int umlStartVMDaemon(virConnectPtr conn,
 if (!(cmd = umlBuildCommandLine(conn, driver, vm)))
 goto cleanup;
 
-for (i = 0 ; i < vm->def->nconsoles ; i++) {
+for (i = 0; i < vm->def->nconsoles; i++) {
 VIR_FREE(vm->def->consoles[i]->info.alias);
 if (virAsprintf(&vm->def->consoles[i]->info.alias, "console%zu", i) < 
0) {
 virReportOOMError();
@@ -2037,7 +2037,7 @@ static int umlDomainAttachUmlDisk(struct uml_driver 
*driver,
 char *cmd = NULL;
 char *reply = NULL;
 
-for (i = 0 ; i < vm->def->ndisks ; i++) {
+for (i = 0; i < vm->def->ndisks; i++) {
 if (STREQ(vm->def->disks[i]->dst, disk->dst)) {
 virReportError(VIR_ERR_OPERATION_FAILED,
_("target %s already exists"), disk->dst);
@@ -2163,7 +2163,7 @@ static int umlDomainDetachUmlDisk(struct uml_driver 
*driver,
 char *cmd;
 char *reply;
 
-for (i = 0 ; i < vm->def->ndisks ; i++) {
+for (i = 0; i < vm->def->ndisks; i++) {
 if (STREQ(vm->def->disks[i]->dst, dev->data.disk->dst)) {
 break;
 }
@@ -2456,7 +2456,7 @@ umlDomainOpenConsole(virDomainPtr dom,
 }
 
 if (dev_name) {
-for (i = 0 ; i < vm->def->nconsoles ; i++) {
+for (i = 0; i < vm->def->nconsoles; i++) {
 if (vm->def->consoles[i]->info.alias &&
 STREQ(vm->def->consoles[i]->info.alias, dev_name)) {
 chr = vm->def->consoles[i];
-- 
1.8.1.4

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


[libvirt] [PATCH 31/31] syntax-check: Add the rule to forbid whitespace before "; "

2013-05-21 Thread Osier Yang
Only a few cases are allowed:

1) The expression is empty for "for" loop, E.g.

  for (i = 0; ; i++)

2) An empty statement

  while (write(statuswrite, &status, 1) == -1 &&
 errno == EINTR)
  ; /* empty */

3) ";" is inside double-quote, I.e, as part of const string. E.g.

  vshPrint(ctl, "a ; b ; cd;\n");

The "for" loop in src/rpc/virnettlscontext.c is the special case,
1) applies for it, so change it together in this patch.
---
 build-aux/bracket-spacing.pl | 18 ++
 src/rpc/virnettlscontext.c   |  2 +-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/build-aux/bracket-spacing.pl b/build-aux/bracket-spacing.pl
index d3a916f..0d5d2ed 100755
--- a/build-aux/bracket-spacing.pl
+++ b/build-aux/bracket-spacing.pl
@@ -109,6 +109,24 @@ foreach my $file (@ARGV) {
 $ret = 1;
 last;
 }
+
+# Forbid whitespace before ";". Things like below are allowed:
+#
+# for (i = 0; ; i++)
+#
+# while (write(statuswrite, &status, 1) == -1 &&
+#errno == EINTR)
+# ;
+#
+# printf("%s", "a ; b\n");
+while ($data =~ /[^;\s]\s+;/) {
+# Inside the double-quote
+if ($data !~ /"[^"]*\s;/) {
+print "$file:$.: $line";
+$ret = 1;
+}
+last;
+}
 }
 close FILE;
 }
diff --git a/src/rpc/virnettlscontext.c b/src/rpc/virnettlscontext.c
index 1a7ccb8..305eee9 100644
--- a/src/rpc/virnettlscontext.c
+++ b/src/rpc/virnettlscontext.c
@@ -292,7 +292,7 @@ static int 
virNetTLSContextCheckCertKeyPurpose(gnutls_x509_crt_t cert,
 bool allowClient = false, allowServer = false;
 
 critical = 0;
-for (i = 0 ; ; i++) {
+for (i = 0; ; i++) {
 size = 0;
 status = gnutls_x509_crt_get_key_purpose_oid(cert, i, buffer, &size, 
NULL);
 
-- 
1.8.1.4

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


[libvirt] [PATCH 09/31] src/node_device: Remove the whitespace before '; '

2013-05-21 Thread Osier Yang
---
 src/node_device/node_device_udev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/node_device/node_device_udev.c 
b/src/node_device/node_device_udev.c
index 4aeaed5..620cd58 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -338,7 +338,7 @@ static int udevGenerateDeviceName(struct udev_device 
*device,
 
 def->name = virBufferContentAndReset(&buf);
 
-for (i = 0; i < strlen(def->name) ; i++) {
+for (i = 0; i < strlen(def->name); i++) {
 if (!(c_isalnum(*(def->name + i {
 *(def->name + i) = '_';
 }
-- 
1.8.1.4

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


[libvirt] [PATCH 06/31] src/xenxs: Remove the whitespace before '; '

2013-05-21 Thread Osier Yang
---
 src/xenxs/xen_sxpr.c | 20 ++--
 src/xenxs/xen_xm.c   | 16 
 2 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c
index 9a76d04..16737a0 100644
--- a/src/xenxs/xen_sxpr.c
+++ b/src/xenxs/xen_sxpr.c
@@ -676,7 +676,7 @@ xenParseSxprSound(virDomainDefPtr def,
 goto no_memory;
 
 
-for (i = 0 ; i < (VIR_DOMAIN_SOUND_MODEL_ES1370 + 1) ; i++) {
+for (i = 0; i < (VIR_DOMAIN_SOUND_MODEL_ES1370 + 1); i++) {
 virDomainSoundDefPtr sound;
 if (VIR_ALLOC(sound) < 0)
 goto no_memory;
@@ -1387,7 +1387,7 @@ xenParseSxpr(const struct sexpr *root,
 if (hvm) {
 const char *const fds[] = { "fda", "fdb" };
 int i;
-for (i = 0 ; i < ARRAY_CARDINALITY(fds) ; i++) {
+for (i = 0; i < ARRAY_CARDINALITY(fds); i++) {
 tmp = sexpr_fmt_node(root, "domain/image/hvm/%s", fds[i]);
 if ((tmp != NULL) && (tmp[0] != 0)) {
 virDomainDiskDefPtr disk;
@@ -2101,7 +2101,7 @@ xenFormatSxprAllPCI(virDomainDefPtr def,
 int hasPCI = 0;
 int i;
 
-for (i = 0 ; i < def->nhostdevs ; i++)
+for (i = 0; i < def->nhostdevs; i++)
 if (def->hostdevs[i]->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
 def->hostdevs[i]->source.subsys.type == 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
 hasPCI = 1;
@@ -2124,7 +2124,7 @@ xenFormatSxprAllPCI(virDomainDefPtr def,
  */
 
 virBufferAddLit(buf, "(device (pci ");
-for (i = 0 ; i < def->nhostdevs ; i++) {
+for (i = 0; i < def->nhostdevs; i++) {
 if (def->hostdevs[i]->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
 def->hostdevs[i]->source.subsys.type == 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) {
 if (def->hostdevs[i]->managed) {
@@ -2158,7 +2158,7 @@ xenFormatSxprSound(virDomainDefPtr def,
 const char *str;
 int i;
 
-for (i = 0 ; i < def->nsounds ; i++) {
+for (i = 0; i < def->nsounds; i++) {
 if (!(str = virDomainSoundModelTypeToString(def->sounds[i]->model))) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected sound model %d"),
@@ -2333,7 +2333,7 @@ xenFormatSxpr(virConnectPtr conn,
 virBufferAsprintf(&buf, "(vcpu_avail %lu)",
   (1UL << def->vcpus) - 1);
 
-for (i = 0 ; i < def->os.nBootDevs ; i++) {
+for (i = 0; i < def->os.nBootDevs; i++) {
 switch (def->os.bootDevs[i]) {
 case VIR_DOMAIN_BOOT_FLOPPY:
 bootorder[i] = 'a';
@@ -2359,7 +2359,7 @@ xenFormatSxpr(virConnectPtr conn,
 virBufferAsprintf(&buf, "(boot %s)", bootorder);
 
 /* some disk devices are defined here */
-for (i = 0 ; i < def->ndisks ; i++) {
+for (i = 0; i < def->ndisks; i++) {
 switch (def->disks[i]->device) {
 case VIR_DOMAIN_DISK_DEVICE_CDROM:
 /* Only xend <= 3.0.2 wants cdrom config here */
@@ -2397,7 +2397,7 @@ xenFormatSxpr(virConnectPtr conn,
 
 virBufferAddLit(&buf, "(usb 1)");
 
-for (i = 0 ; i < def->ninputs ; i++)
+for (i = 0; i < def->ninputs; i++)
 if (xenFormatSxprInput(def->inputs[i], &buf) < 0)
 goto error;
 
@@ -2571,12 +2571,12 @@ xenFormatSxpr(virConnectPtr conn,
 virBufferAsprintf(&buf, "(localtime %d)", vmlocaltime);
 
 
-for (i = 0 ; i < def->ndisks ; i++)
+for (i = 0; i < def->ndisks; i++)
 if (xenFormatSxprDisk(def->disks[i],
   &buf, hvm, xendConfigVersion, 0) < 0)
 goto error;
 
-for (i = 0 ; i < def->nnets ; i++)
+for (i = 0; i < def->nnets; i++)
 if (xenFormatSxprNet(conn, def->nets[i],
  &buf, hvm, xendConfigVersion, 0) < 0)
 goto error;
diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
index 57ce2e7..11c02c1 100644
--- a/src/xenxs/xen_xm.c
+++ b/src/xenxs/xen_xm.c
@@ -319,7 +319,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
 if (xenXMConfigGetString(conf, "boot", &boot, "c") < 0)
 goto cleanup;
 
-for (i = 0 ; i < VIR_DOMAIN_BOOT_LAST && boot[i] ; i++) {
+for (i = 0; i < VIR_DOMAIN_BOOT_LAST && boot[i]; i++) {
 switch (*boot) {
 case 'a':
 def->os.bootDevs[i] = VIR_DOMAIN_BOOT_FLOPPY;
@@ -1448,7 +1448,7 @@ xenFormatXMPCI(virConfPtr conf,
 int hasPCI = 0;
 int i;
 
-for (i = 0 ; i < def->nhostdevs ; i++)
+for (i = 0; i < def->nhostdevs; i++)
 if (def->hostdevs[i]->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
 def->hostdevs[i]->source.subsys.type == 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
 hasPCI = 1;
@@ -1464,7 +1464,7 @@ xenFormatXMPCI(virConfPtr conf,
 pciVal->type = VIR_CONF_LIST;
 pciVal->list = NULL;
 

[libvirt] [PATCH 04/31] src/test: Remove the whitespace before '; '

2013-05-21 Thread Osier Yang
---
 src/test/test_driver.c | 80 +-
 1 file changed, 40 insertions(+), 40 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index d0d7832..f1cdd92 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -192,7 +192,7 @@ testBuildCapabilities(virConnectPtr conn) {
 goto no_memory;
 }
 
-for (i = 0; i < ARRAY_CARDINALITY(guest_types) ; i++) {
+for (i = 0; i < ARRAY_CARDINALITY(guest_types); i++) {
 if ((guest = virCapabilitiesAddGuest(caps,
  guest_types[i],
  VIR_ARCH_I686,
@@ -343,7 +343,7 @@ testDomainGenerateIfname(virDomainDefPtr domdef) {
 }
 
 /* Generate network interface names */
-for (i = 0 ; i < domdef->nnets ; i++) {
+for (i = 0; i < domdef->nnets; i++) {
 if (domdef->nets[i]->ifname &&
 STREQ(domdef->nets[i]->ifname, ifname)) {
 found = 1;
@@ -559,7 +559,7 @@ static int testOpenDefault(virConnectPtr conn) {
 privconn->cells[u].numCpus = 8;
 privconn->cells[u].mem = (u + 1) * 2048 * 1024;
 }
-for (u = 0 ; u < 16 ; u++) {
+for (u = 0; u < 16; u++) {
 virBitmapPtr siblings = virBitmapNew(16);
 if (!siblings) {
 virReportOOMError();
@@ -721,7 +721,7 @@ static int testOpenVolumesForPool(xmlDocPtr xml,
 goto error;
 }
 
-for (i = 0 ; i < ret ; i++) {
+for (i = 0; i < ret; i++) {
 char *relFile = virXMLPropString(vols[i], "file");
 if (relFile != NULL) {
 char *absFile = testBuildFilename(file, relFile);
@@ -911,7 +911,7 @@ static int testOpenFromFile(virConnectPtr conn,
 goto error;
 }
 
-for (i = 0 ; i < ret ; i++) {
+for (i = 0; i < ret; i++) {
 virDomainDefPtr def;
 char *relFile = virXMLPropString(domains[i], "file");
 if (relFile != NULL) {
@@ -960,7 +960,7 @@ static int testOpenFromFile(virConnectPtr conn,
 if (ret < 0) {
 goto error;
 }
-for (i = 0 ; i < ret ; i++) {
+for (i = 0; i < ret; i++) {
 virNetworkDefPtr def;
 char *relFile = virXMLPropString(networks[i], "file");
 if (relFile != NULL) {
@@ -995,7 +995,7 @@ static int testOpenFromFile(virConnectPtr conn,
 if (ret < 0) {
 goto error;
 }
-for (i = 0 ; i < ret ; i++) {
+for (i = 0; i < ret; i++) {
 virInterfaceDefPtr def;
 char *relFile = virXMLPropString(ifaces[i], "file");
 if (relFile != NULL) {
@@ -1031,7 +1031,7 @@ static int testOpenFromFile(virConnectPtr conn,
 if (ret < 0) {
 goto error;
 }
-for (i = 0 ; i < ret ; i++) {
+for (i = 0; i < ret; i++) {
 virStoragePoolDefPtr def;
 virStoragePoolObjPtr pool;
 char *relFile = virXMLPropString(pools[i], "file");
@@ -1081,7 +1081,7 @@ static int testOpenFromFile(virConnectPtr conn,
 if (ret < 0) {
 goto error;
 }
-for (i = 0 ; i < ret ; i++) {
+for (i = 0; i < ret; i++) {
 virNodeDeviceDefPtr def;
 virNodeDeviceObjPtr dev;
 char *relFile = virXMLPropString(devs[i], "file");
@@ -1408,7 +1408,7 @@ static virDomainPtr testDomainLookupByUUID(virConnectPtr 
conn,
 {
 testConnPtr privconn = conn->privateData;
 virDomainPtr ret = NULL;
-virDomainObjPtr dom ;
+virDomainObjPtr dom;
 
 testDriverLock(privconn);
 dom = virDomainObjListFindByUUID(privconn->domains, uuid);
@@ -2347,7 +2347,7 @@ static int testDomainGetVcpus(virDomainPtr domain,
 if (info != NULL) {
 memset(info, 0, sizeof(*info) * maxinfo);
 
-for (i = 0 ; i < maxinfo ; i++) {
+for (i = 0; i < maxinfo; i++) {
 virVcpuInfo privinfo = privdomdata->vcpu_infos[i];
 
 info[i].number = privinfo.number;
@@ -2364,10 +2364,10 @@ static int testDomainGetVcpus(virDomainPtr domain,
 int privmaplen = VIR_CPU_MAPLEN(hostcpus);
 memset(cpumaps, 0, maplen * maxinfo);
 
-for (v = 0 ; v < maxinfo ; v++) {
+for (v = 0; v < maxinfo; v++) {
 unsigned char *cpumap = VIR_GET_CPUMAP(cpumaps, maplen, v);
 
-for (i = 0 ; i < maxcpu ; i++) {
+for (i = 0; i < maxcpu; i++) {
 if (VIR_CPU_USABLE(privdomdata->cpumaps, privmaplen, v, i)) {
 VIR_USE_CPU(cpumap, i);
 }
@@ -2426,7 +2426,7 @@ static int testDomainPinVcpu(virDomainPtr domain,
 privcpumap = VIR_GET_CPUMAP(privdomdata->cpumaps, privmaplen, vcpu);
 memset(privcpumap, 0, privmaplen);
 
-for (i = 0 ; i < maxcpu ; i++) {
+for (i = 0; i < maxcpu; i++) {
 if (VIR_CPU_USABLE(cpumap, maplen, 0, i)) {
 VIR_USE_CPU(privcpumap, i);
 }
@@ -2558,7 +2558,7 @@ static int testNodeGetCellsFreeMemory(virConnectPtr conn,
 }
 
 for (i = startCell, j = 0;
- (i < priv

[libvirt] [PATCH 18/31] src/storage: Remove the whitespace before '; '

2013-05-21 Thread Osier Yang
---
 src/storage/storage_backend.c | 14 +++---
 src/storage/storage_backend_disk.c|  2 +-
 src/storage/storage_backend_iscsi.c   | 10 +-
 src/storage/storage_backend_logical.c |  6 +++---
 src/storage/storage_driver.c  | 26 +-
 5 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 01a404e..66b3ff7 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -1485,14 +1485,14 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
 return -1;
 }
 
-for (i = 0 ; i < nregex ; i++) {
+for (i = 0; i < nregex; i++) {
 err = regcomp(®[i], regex[i], REG_EXTENDED);
 if (err != 0) {
 char error[100];
 regerror(err, ®[i], error, sizeof(error));
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to compile regex %s"), error);
-for (j = 0 ; j <= i ; j++)
+for (j = 0; j <= i; j++)
 regfree(®[j]);
 VIR_FREE(reg);
 return -1;
@@ -1538,7 +1538,7 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
 if (!p)
 p = line;
 
-for (i = 0 ; i <= maxReg && i < nregex ; i++) {
+for (i = 0; i <= maxReg && i < nregex; i++) {
 if (regexec(®[i], p, nvars[i]+1, vars, 0) == 0) {
 maxReg++;
 
@@ -1546,7 +1546,7 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
 ngroup = 0;
 
 /* NULL terminate each captured group in the line */
-for (j = 0 ; j < nvars[i] ; j++) {
+for (j = 0; j < nvars[i]; j++) {
 /* NB vars[0] is the full pattern, so we offset j by 1 */
 p[vars[j+1].rm_eo] = '\0';
 if (VIR_STRDUP(groups[ngroup++], p + vars[j+1].rm_so) < 0)
@@ -1559,7 +1559,7 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
 goto cleanup;
 
 /* Release matches & restart to matching the first regex */
-for (j = 0 ; j < totgroups ; j++)
+for (j = 0; j < totgroups; j++)
 VIR_FREE(groups[j]);
 maxReg = 0;
 ngroup = 0;
@@ -1571,13 +1571,13 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
 ret = virCommandWait(cmd, NULL);
 cleanup:
 if (groups) {
-for (j = 0 ; j < totgroups ; j++)
+for (j = 0; j < totgroups; j++)
 VIR_FREE(groups[j]);
 VIR_FREE(groups);
 }
 VIR_FREE(vars);
 
-for (i = 0 ; i < nregex ; i++)
+for (i = 0; i < nregex; i++)
 regfree(®[i]);
 
 VIR_FREE(reg);
diff --git a/src/storage/storage_backend_disk.c 
b/src/storage/storage_backend_disk.c
index 09c2d2c..d0b91f9 100644
--- a/src/storage/storage_backend_disk.c
+++ b/src/storage/storage_backend_disk.c
@@ -553,7 +553,7 @@ virStorageBackendDiskPartBoundries(virStoragePoolObjPtr 
pool,
aligned to the cylinder boundary */
 extraBytes = cylinderSize - (allocation % cylinderSize);
 
-for (i = 0 ; i < dev->nfreeExtent ; i++) {
+for (i = 0; i < dev->nfreeExtent; i++) {
  unsigned long long size =
  dev->freeExtents[i].end -
  dev->freeExtents[i].start;
diff --git a/src/storage/storage_backend_iscsi.c 
b/src/storage/storage_backend_iscsi.c
index a74f343..ad38ab2 100644
--- a/src/storage/storage_backend_iscsi.c
+++ b/src/storage/storage_backend_iscsi.c
@@ -562,7 +562,7 @@ virStorageBackendISCSIScanTargets(const char *portal,
   &list, NULL) < 0)
 goto cleanup;
 
-for (i = 0 ; i < list.ntargets ; i++) {
+for (i = 0; i < list.ntargets; i++) {
 /* We have to ignore failure, because we can't undo
  * the results of 'sendtargets', unless we go scrubbing
  * around in the dirt in /var/lib/iscsi.
@@ -578,7 +578,7 @@ virStorageBackendISCSIScanTargets(const char *portal,
 *ntargetsret = list.ntargets;
 *targetsret = list.targets;
 } else {
-for (i = 0 ; i < list.ntargets ; i++) {
+for (i = 0; i < list.ntargets; i++) {
 VIR_FREE(list.targets[i]);
 }
 VIR_FREE(list.targets);
@@ -640,7 +640,7 @@ virStorageBackendISCSIFindPoolSources(virConnectPtr conn 
ATTRIBUTE_UNUSED,
 goto cleanup;
 }
 
-for (i = 0 ; i < ntargets ; i++) {
+for (i = 0; i < ntargets; i++) {
 if (VIR_ALLOC_N(list.sources[i].devices, 1) < 0 ||
 VIR_ALLOC_N(list.sources[i].hosts, 1) < 0) {
 virReportOOMError();
@@ -661,13 +661,13 @@ virStorageBackendISCSIFindPoolSources(virConnectPtr conn 
ATTRIBUTE_UNUSED,
 
 cleanup:
 if (list.sources) {
-for (i = 0 ; i < ntargets ; i++) {
+for (i = 0; i < ntargets; i++) {
 VIR_FREE(list.

[libvirt] [PATCH 23/31] src/rpc: Remove the whitespace before ";"

2013-05-21 Thread Osier Yang
---
 src/rpc/virnetclient.c| 12 ++--
 src/rpc/virnetclientprogram.c | 12 ++--
 src/rpc/virnetmessage.c   |  6 +++---
 src/rpc/virnetserver.c| 26 +-
 src/rpc/virnetserverclient.c  |  4 ++--
 src/rpc/virnetserverprogram.c |  2 +-
 src/rpc/virnetserverservice.c | 14 +++---
 src/rpc/virnetsocket.c|  2 +-
 8 files changed, 39 insertions(+), 39 deletions(-)

diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
index 1d228f0..d87c7e3 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -602,7 +602,7 @@ void virNetClientDispose(void *obj)
 if (client->closeFf)
 client->closeFf(client->closeOpaque);
 
-for (i = 0 ; i < client->nprograms ; i++)
+for (i = 0; i < client->nprograms; i++)
 virObjectUnref(client->programs[i]);
 VIR_FREE(client->programs);
 
@@ -916,7 +916,7 @@ void virNetClientRemoveStream(virNetClientPtr client,
 {
 virObjectLock(client);
 size_t i;
-for (i = 0 ; i < client->nstreams ; i++) {
+for (i = 0; i < client->nstreams; i++) {
 if (client->streams[i] == st)
 break;
 }
@@ -1008,7 +1008,7 @@ static int 
virNetClientCallDispatchMessage(virNetClientPtr client)
 size_t i;
 virNetClientProgramPtr prog = NULL;
 
-for (i = 0 ; i < client->nprograms ; i++) {
+for (i = 0; i < client->nprograms; i++) {
 if (virNetClientProgramMatches(client->programs[i],
&client->msg)) {
 prog = client->programs[i];
@@ -1033,7 +1033,7 @@ static int virNetClientCallDispatchStream(virNetClientPtr 
client)
 virNetClientCallPtr thecall;
 
 /* First identify what stream this packet is directed at */
-for (i = 0 ; i < client->nstreams ; i++) {
+for (i = 0; i < client->nstreams; i++) {
 if (virNetClientStreamMatches(client->streams[i],
   &client->msg)) {
 st = client->streams[i];
@@ -1175,7 +1175,7 @@ virNetClientIOWriteMessage(virNetClientPtr client,
 
 if (thecall->msg->bufferOffset == thecall->msg->bufferLength) {
 size_t i;
-for (i = thecall->msg->donefds ; i < thecall->msg->nfds ; i++) {
+for (i = thecall->msg->donefds; i < thecall->msg->nfds; i++) {
 int rv;
 if ((rv = virNetSocketSendFD(client->sock, thecall->msg->fds[i])) 
< 0)
 return -1;
@@ -1297,7 +1297,7 @@ virNetClientIOHandleInput(virNetClientPtr client)
 virNetMessageDecodeNumFDs(&client->msg) < 0)
 return -1;
 
-for (i = client->msg.donefds ; i < client->msg.nfds ; i++) 
{
+for (i = client->msg.donefds; i < client->msg.nfds; i++) {
 int rv;
 if ((rv = virNetSocketRecvFD(client->sock, 
&(client->msg.fds[i]))) < 0)
 return -1;
diff --git a/src/rpc/virnetclientprogram.c b/src/rpc/virnetclientprogram.c
index 2e6e4f6..1016f55 100644
--- a/src/rpc/virnetclientprogram.c
+++ b/src/rpc/virnetclientprogram.c
@@ -197,7 +197,7 @@ static virNetClientProgramEventPtr 
virNetClientProgramGetEvent(virNetClientProgr
 {
 int i;
 
-for (i = 0 ; i < prog->nevents ; i++) {
+for (i = 0; i < prog->nevents; i++) {
 if (prog->events[i].proc == procedure)
 return &prog->events[i];
 }
@@ -301,9 +301,9 @@ int virNetClientProgramCall(virNetClientProgramPtr prog,
 virReportOOMError();
 goto error;
 }
-for (i = 0 ; i < msg->nfds ; i++)
+for (i = 0; i < msg->nfds; i++)
 msg->fds[i] = -1;
-for (i = 0 ; i < msg->nfds ; i++) {
+for (i = 0; i < msg->nfds; i++) {
 if ((msg->fds[i] = dup(outfds[i])) < 0) {
 virReportSystemError(errno,
  _("Cannot duplicate FD %d"),
@@ -362,9 +362,9 @@ int virNetClientProgramCall(virNetClientProgramPtr prog,
 virReportOOMError();
 goto error;
 }
-for (i = 0 ; i < *ninfds ; i++)
+for (i = 0; i < *ninfds; i++)
 (*infds)[i] = -1;
-for (i = 0 ; i < *ninfds ; i++) {
+for (i = 0; i < *ninfds; i++) {
 if (((*infds)[i] = dup(msg->fds[i])) < 0) {
 virReportSystemError(errno,
  _("Cannot duplicate FD %d"),
@@ -401,7 +401,7 @@ int virNetClientProgramCall(virNetClientProgramPtr prog,
 error:
 virNetMessageFree(msg);
 if (infds && ninfds) {
-for (i = 0 ; i < *ninfds ; i++)
+for (i = 0; i < *ninfds; i++)
 VIR_FORCE_CLOSE((*infds)[i]);
 }
 return -1;
diff --git a/src/rpc/virnetmessage.c b/src/rpc/virnetmessage.c
index b2c6e5b..85c831d 100644
--- a/src/rpc/virnetmessage.c
+++ b/src/rpc/virnetmessage.c
@@ -55,7 +55,7 @@ void virNetMessageClear(virNetMessagePtr msg)
 
 VIR_DEBUG("msg=%p nfd

[libvirt] [PATCH 25/31] src/lxc: Remove the whitespace before ";"

2013-05-21 Thread Osier Yang
---
 src/lxc/lxc_cgroup.c |  4 ++--
 src/lxc/lxc_container.c  | 24 
 src/lxc/lxc_controller.c | 28 ++--
 src/lxc/lxc_driver.c |  4 ++--
 src/lxc/lxc_hostdev.c|  4 ++--
 src/lxc/lxc_process.c| 18 +-
 6 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c
index de6b53b..5c8acb3 100644
--- a/src/lxc/lxc_cgroup.c
+++ b/src/lxc/lxc_cgroup.c
@@ -427,7 +427,7 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,
 }
 }
 
-for (i = 0 ; i < def->ndisks ; i++) {
+for (i = 0; i < def->ndisks; i++) {
 if (def->disks[i]->type != VIR_DOMAIN_DISK_TYPE_BLOCK)
 continue;
 
@@ -445,7 +445,7 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,
 }
 }
 
-for (i = 0 ; i < def->nfss ; i++) {
+for (i = 0; i < def->nfss; i++) {
 if (def->fss[i]->type != VIR_DOMAIN_FS_TYPE_BLOCK)
 continue;
 
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index b4be4cd..c74e3ca 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -353,7 +353,7 @@ static int lxcContainerRenameAndEnableInterfaces(bool 
privNet,
 size_t i;
 char *newname = NULL;
 
-for (i = 0 ; i < nveths ; i++) {
+for (i = 0; i < nveths; i++) {
 if (virAsprintf(&newname, "eth%zu", i) < 0) {
 virReportOOMError();
 rc = -1;
@@ -475,7 +475,7 @@ static int lxcContainerUnmountSubtree(const char *prefix,
 
 if (lxcContainerGetSubtree(prefix, &mounts, &nmounts) < 0)
 goto cleanup;
-for (i = 0 ; i < nmounts ; i++) {
+for (i = 0; i < nmounts; i++) {
 VIR_DEBUG("Umount %s", mounts[i]);
 if (umount(mounts[i]) < 0) {
 char ebuf[1024];
@@ -509,7 +509,7 @@ static int lxcContainerUnmountSubtree(const char *prefix,
 ret = 0;
 
 cleanup:
-for (i = 0 ; i < nmounts ; i++)
+for (i = 0; i < nmounts; i++)
 VIR_FREE(mounts[i]);
 VIR_FREE(mounts);
 
@@ -689,7 +689,7 @@ static int lxcContainerMountBasicFS(char *sec_mount_options)
 
 VIR_DEBUG("Mounting basic filesystems sec_mount_options=%s", 
sec_mount_options);
 
-for (i = 0 ; i < ARRAY_CARDINALITY(mnts) ; i++) {
+for (i = 0; i < ARRAY_CARDINALITY(mnts); i++) {
 const char *srcpath = NULL;
 
 VIR_DEBUG("Processing %s -> %s",
@@ -849,7 +849,7 @@ static int lxcContainerPopulateDevices(char **ttyPaths, 
size_t nttyPaths)
 };
 
 /* Populate /dev/ with a few important bits */
-for (i = 0 ; i < ARRAY_CARDINALITY(devs) ; i++) {
+for (i = 0; i < ARRAY_CARDINALITY(devs); i++) {
 dev_t dev = makedev(devs[i].maj, devs[i].min);
 if (mknod(devs[i].path, S_IFCHR, dev) < 0 ||
 chmod(devs[i].path, devs[i].mode)) {
@@ -860,7 +860,7 @@ static int lxcContainerPopulateDevices(char **ttyPaths, 
size_t nttyPaths)
 }
 }
 
-for (i = 0 ; i < ARRAY_CARDINALITY(links) ; i++) {
+for (i = 0; i < ARRAY_CARDINALITY(links); i++) {
 if (symlink(links[i].src, links[i].dst) < 0) {
 virReportSystemError(errno,
  _("Failed to symlink device %s to %s"),
@@ -890,7 +890,7 @@ static int lxcContainerPopulateDevices(char **ttyPaths, 
size_t nttyPaths)
 }
 }
 
-for (i = 0 ; i < nttyPaths ; i++) {
+for (i = 0; i < nttyPaths; i++) {
 char *tty;
 if (virAsprintf(&tty, "/dev/tty%zu", i+1) < 0) {
 virReportOOMError();
@@ -1356,7 +1356,7 @@ static int lxcContainerMountAllFS(virDomainDefPtr vmDef,
 VIR_DEBUG("Mounting all non-root filesystems");
 
 /* Pull in rest of container's mounts */
-for (i = 0 ; i < vmDef->nfss ; i++) {
+for (i = 0; i < vmDef->nfss; i++) {
 if (STREQ(vmDef->fss[i]->dst, "/"))
 continue;
 
@@ -1460,7 +1460,7 @@ static int lxcContainerSetupAllDisks(virDomainDefPtr 
vmDef,
 size_t i;
 VIR_DEBUG("Setting up disks");
 
-for (i = 0 ; i < vmDef->ndisks ; i++) {
+for (i = 0; i < vmDef->ndisks; i++) {
 if (lxcContainerSetupDisk(vmDef, vmDef->disks[i],
   securityDriver) < 0)
 return -1;
@@ -1702,7 +1702,7 @@ static int lxcContainerSetupAllHostdevs(virDomainDefPtr 
vmDef,
 size_t i;
 VIR_DEBUG("Setting up hostdevs");
 
-for (i = 0 ; i < vmDef->nhostdevs ; i++) {
+for (i = 0; i < vmDef->nhostdevs; i++) {
 virDomainHostdevDefPtr def = vmDef->hostdevs[i];
 switch (def->mode) {
 case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
@@ -1840,7 +1840,7 @@ static int lxcContainerResolveSymlinks(virDomainDefPtr 
vmDef)
 char *newroot;
 size_t i;
 
-for (i = 0 ; i < vmDef->nfss ; i++) {
+for (i = 0; i < vmDef->nfss; i++) {
 virDomainFSDefPtr fs = vmDef->fss[i];
 if (!fs->src)
 continue;
@@ -2070,7 +2070,7 @@ lxcNeedNetworkNamespace(virDomainDefPtr def)
 return t

[libvirt] [PATCH 17/31] src/security: Remove the whitespace before '; '

2013-05-21 Thread Osier Yang
---
 src/security/security_dac.c | 8 
 src/security/security_driver.c  | 2 +-
 src/security/security_selinux.c | 8 
 src/security/virt-aa-helper.c   | 4 ++--
 4 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/security/security_dac.c b/src/security/security_dac.c
index 6e6fcad..d922ad2 100644
--- a/src/security/security_dac.c
+++ b/src/security/security_dac.c
@@ -847,14 +847,14 @@ 
virSecurityDACRestoreSecurityAllLabel(virSecurityManagerPtr mgr,
 VIR_DEBUG("Restoring security label on %s migrated=%d",
   def->name, migrated);
 
-for (i = 0 ; i < def->nhostdevs ; i++) {
+for (i = 0; i < def->nhostdevs; i++) {
 if (virSecurityDACRestoreSecurityHostdevLabel(mgr,
   def,
   def->hostdevs[i],
   NULL) < 0)
 rc = -1;
 }
-for (i = 0 ; i < def->ndisks ; i++) {
+for (i = 0; i < def->ndisks; i++) {
 if (virSecurityDACRestoreSecurityImageLabelInt(mgr,
def,
def->disks[i],
@@ -914,7 +914,7 @@ virSecurityDACSetSecurityAllLabel(virSecurityManagerPtr mgr,
 if (!priv->dynamicOwnership)
 return 0;
 
-for (i = 0 ; i < def->ndisks ; i++) {
+for (i = 0; i < def->ndisks; i++) {
 /* XXX fixme - we need to recursively label the entire tree :-( */
 if (def->disks[i]->type == VIR_DOMAIN_DISK_TYPE_DIR)
 continue;
@@ -923,7 +923,7 @@ virSecurityDACSetSecurityAllLabel(virSecurityManagerPtr mgr,
 def->disks[i]) < 0)
 return -1;
 }
-for (i = 0 ; i < def->nhostdevs ; i++) {
+for (i = 0; i < def->nhostdevs; i++) {
 if (virSecurityDACSetSecurityHostdevLabel(mgr,
   def,
   def->hostdevs[i],
diff --git a/src/security/security_driver.c b/src/security/security_driver.c
index 319b86f..7920b93 100644
--- a/src/security/security_driver.c
+++ b/src/security/security_driver.c
@@ -57,7 +57,7 @@ virSecurityDriverPtr virSecurityDriverLookup(const char *name,
 
 VIR_DEBUG("name=%s", NULLSTR(name));
 
-for (i = 0; i < ARRAY_CARDINALITY(security_drivers) && !drv ; i++) {
+for (i = 0; i < ARRAY_CARDINALITY(security_drivers) && !drv; i++) {
 virSecurityDriverPtr tmp = security_drivers[i];
 
 if (name &&
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index 5d108b9..1781c86 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -1887,14 +1887,14 @@ 
virSecuritySELinuxRestoreSecurityAllLabel(virSecurityManagerPtr mgr,
 rc = -1;
 }
 
-for (i = 0 ; i < def->nhostdevs ; i++) {
+for (i = 0; i < def->nhostdevs; i++) {
 if (virSecuritySELinuxRestoreSecurityHostdevLabel(mgr,
   def,
   def->hostdevs[i],
   NULL) < 0)
 rc = -1;
 }
-for (i = 0 ; i < def->ndisks ; i++) {
+for (i = 0; i < def->ndisks; i++) {
 if (virSecuritySELinuxRestoreSecurityImageLabelInt(mgr,
def,
def->disks[i],
@@ -2281,7 +2281,7 @@ 
virSecuritySELinuxSetSecurityAllLabel(virSecurityManagerPtr mgr,
 if (secdef->norelabel || data->skipAllLabel)
 return 0;
 
-for (i = 0 ; i < def->ndisks ; i++) {
+for (i = 0; i < def->ndisks; i++) {
 /* XXX fixme - we need to recursively label the entire tree :-( */
 if (def->disks[i]->type == VIR_DOMAIN_DISK_TYPE_DIR) {
 VIR_WARN("Unable to relabel directory tree %s for disk %s",
@@ -2294,7 +2294,7 @@ 
virSecuritySELinuxSetSecurityAllLabel(virSecurityManagerPtr mgr,
 }
 /* XXX fixme process  def->fss if relabel == true */
 
-for (i = 0 ; i < def->nhostdevs ; i++) {
+for (i = 0; i < def->nhostdevs; i++) {
 if (virSecuritySELinuxSetSecurityHostdevLabel(mgr,
   def,
   def->hostdevs[i],
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
index 5d48850..6f63c37 100644
--- a/src/security/virt-aa-helper.c
+++ b/src/security/virt-aa-helper.c
@@ -952,7 +952,7 @@ get_files(vahControl * ctl)
  ctl->def->consoles[i]->source.data.file.path, 
"rw") != 0)
 goto cleanup;
 
-for (i = 0 ; i < ctl->def->nparallels; i++)
+for (i = 0; i < ctl->def->nparallels; i++)
 if (ctl->def->parallels[i] &&
 (ctl-

[libvirt] [PATCH 26/31] examples: Remove the whitespace before '; '

2013-05-21 Thread Osier Yang
---
 examples/domain-events/events-c/event-test.c | 2 +-
 examples/openauth/openauth.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/examples/domain-events/events-c/event-test.c 
b/examples/domain-events/events-c/event-test.c
index 301caad..eeff50f 100644
--- a/examples/domain-events/events-c/event-test.c
+++ b/examples/domain-events/events-c/event-test.c
@@ -332,7 +332,7 @@ static int myDomainEventGraphicsCallback(virConnectPtr conn 
ATTRIBUTE_UNUSED,
remote->family, remote->node, remote->service);
 
 printf("auth: %s ", authScheme);
-for (i = 0 ; i < subject->nidentity ; i++) {
+for (i = 0; i < subject->nidentity; i++) {
 printf(" identity: %s=%s",
subject->identities[i].type,
subject->identities[i].name);
diff --git a/examples/openauth/openauth.c b/examples/openauth/openauth.c
index 4f01cdb..628451c 100644
--- a/examples/openauth/openauth.c
+++ b/examples/openauth/openauth.c
@@ -135,7 +135,7 @@ showDomains(virConnectPtr conn)
 printf("Inactive domains:\n");
 }
 
-for (i = 0 ; i < numNames ; i++) {
+for (i = 0; i < numNames; i++) {
 printf("  %s\n", *(nameList + i));
 /* The API documentation doesn't say so, but the names
  * returned by virConnectListDefinedDomains are strdup'd and
@@ -175,7 +175,7 @@ authCallback(virConnectCredentialPtr cred, unsigned int 
ncred, void *cbdata)
  * For example the ESX driver passes the hostname of the ESX or vCenter
  * server as challenge. This allows a auth callback to return the
  * proper credentials. */
-for (i = 0; i < ncred ; ++i) {
+for (i = 0; i < ncred; ++i) {
 switch (cred[i].type) {
 case VIR_CRED_AUTHNAME:
 cred[i].result = strdup(authData->username);
-- 
1.8.1.4

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


[libvirt] [PATCH 20/31] daemon: Remove the whitespace before ";"

2013-05-21 Thread Osier Yang
---
 daemon/libvirtd-config.c |  2 +-
 daemon/remote.c  | 12 ++--
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/daemon/libvirtd-config.c b/daemon/libvirtd-config.c
index 1c57475..66dfb4a 100644
--- a/daemon/libvirtd-config.c
+++ b/daemon/libvirtd-config.c
@@ -88,7 +88,7 @@ remoteConfigGetStringList(virConfPtr conf, const char *key, 
char ***list_arg,
 }
 if (VIR_STRDUP(list[i], pp->str) < 0) {
 int j;
-for (j = 0 ; j < i ; j++)
+for (j = 0; j < i; j++)
 VIR_FREE(list[j]);
 VIR_FREE(list);
 return -1;
diff --git a/daemon/remote.c b/daemon/remote.c
index af89e60..0e253bf 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -315,7 +315,7 @@ static int remoteRelayDomainEventGraphics(virConnectPtr 
conn ATTRIBUTE_UNUSED,
   authScheme);
 
 VIR_DEBUG("Subject %d", subject->nidentity);
-for (i = 0 ; i < subject->nidentity ; i++) {
+for (i = 0; i < subject->nidentity; i++) {
 VIR_DEBUG("  %s=%s", subject->identities[i].type, 
subject->identities[i].name);
 }
 
@@ -337,7 +337,7 @@ static int remoteRelayDomainEventGraphics(virConnectPtr 
conn ATTRIBUTE_UNUSED,
 goto error;
 }
 
-for (i = 0 ; i < data.subject.subject_len ; i++) {
+for (i = 0; i < data.subject.subject_len; i++) {
 if (VIR_STRDUP(data.subject.subject_val[i].type, 
subject->identities[i].type) < 0 ||
 VIR_STRDUP(data.subject.subject_val[i].name, 
subject->identities[i].name) < 0)
 goto error;
@@ -357,7 +357,7 @@ error:
 VIR_FREE(data.remote.node);
 VIR_FREE(data.remote.service);
 if (data.subject.subject_val != NULL) {
-for (i = 0 ; i < data.subject.subject_len ; i++) {
+for (i = 0; i < data.subject.subject_len; i++) {
 VIR_FREE(data.subject.subject_val[i].type);
 VIR_FREE(data.subject.subject_val[i].name);
 }
@@ -640,7 +640,7 @@ void remoteClientFreeFunc(void *data)
 if (priv->conn) {
 int i;
 
-for (i = 0 ; i < VIR_DOMAIN_EVENT_ID_LAST ; i++) {
+for (i = 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++) {
 if (priv->domainEventCallbackID[i] != -1) {
 VIR_DEBUG("Deregistering to relay remote events %d", i);
 virConnectDomainEventDeregisterAny(priv->conn,
@@ -681,7 +681,7 @@ void *remoteClientInitHook(virNetServerClientPtr client,
 return NULL;
 }
 
-for (i = 0 ; i < VIR_DOMAIN_EVENT_ID_LAST ; i++)
+for (i = 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++)
 priv->domainEventCallbackID[i] = -1;
 
 virNetServerClientSetCloseHook(client, remoteClientCloseFunc);
@@ -4616,7 +4616,7 @@ lxcDispatchDomainOpenNamespace(virNetServerPtr server 
ATTRIBUTE_UNUSED,
  * but in case they're playing games with us, prevent
  * a resource leak
  */
-for (i = 0 ; i < msg->nfds ; i++)
+for (i = 0; i < msg->nfds; i++)
 VIR_FORCE_CLOSE(msg->fds[i]);
 VIR_FREE(msg->fds);
 msg->nfds = 0;
-- 
1.8.1.4

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


[libvirt] [PATCH 28/31] src/locking: Remove the whitespace before "; "

2013-05-21 Thread Osier Yang
---
 src/locking/domain_lock.c |  4 ++--
 src/locking/lock_daemon.c |  4 ++--
 src/locking/lock_driver_lockd.c   | 12 ++--
 src/locking/lock_driver_sanlock.c |  6 +++---
 src/locking/lock_manager.c|  2 +-
 5 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/src/locking/domain_lock.c b/src/locking/domain_lock.c
index 6191e9b..d79aeac 100644
--- a/src/locking/domain_lock.c
+++ b/src/locking/domain_lock.c
@@ -138,12 +138,12 @@ static virLockManagerPtr 
virDomainLockManagerNew(virLockManagerPluginPtr plugin,
 
 if (withResources) {
 VIR_DEBUG("Adding leases");
-for (i = 0 ; i < dom->def->nleases ; i++)
+for (i = 0; i < dom->def->nleases; i++)
 if (virDomainLockManagerAddLease(lock, dom->def->leases[i]) < 0)
 goto error;
 
 VIR_DEBUG("Adding disks");
-for (i = 0 ; i < dom->def->ndisks ; i++)
+for (i = 0; i < dom->def->ndisks; i++)
 if (virDomainLockManagerAddDisk(lock, dom->def->disks[i]) < 0)
 goto error;
 }
diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c
index e1653b1..23a119f 100644
--- a/src/locking/lock_daemon.c
+++ b/src/locking/lock_daemon.c
@@ -215,7 +215,7 @@ virLockDaemonNewPostExecRestart(virJSONValuePtr object, 
bool privileged)
 goto error;
 }
 
-for (i = 0 ; i < n ; i++) {
+for (i = 0; i < n; i++) {
 virLockSpacePtr lockspace;
 
 child = virJSONValueArrayGet(lockspaces, i);
@@ -749,7 +749,7 @@ virLockDaemonClientFree(void *opaque)
  * closed the connection, we must kill it off
  * to make sure it doesn't do nasty stuff */
 if (data.gotError || data.hadSomeLeases) {
-for (i = 0 ; i < 15 ; i++) {
+for (i = 0; i < 15; i++) {
 int signum;
 if (i == 0)
 signum = SIGTERM;
diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lockd.c
index afe9e94..cc3b6b1 100644
--- a/src/locking/lock_driver_lockd.c
+++ b/src/locking/lock_driver_lockd.c
@@ -428,7 +428,7 @@ static void virLockManagerLockDaemonFree(virLockManagerPtr 
lock)
 
 lock->privateData = NULL;
 
-for (i = 0 ; i < priv->nresources ; i++) {
+for (i = 0; i < priv->nresources; i++) {
 VIR_FREE(priv->resources[i].lockspace);
 VIR_FREE(priv->resources[i].name);
 }
@@ -459,7 +459,7 @@ static int virLockManagerLockDaemonNew(virLockManagerPtr 
lock,
 
 switch (type) {
 case VIR_LOCK_MANAGER_OBJECT_TYPE_DOMAIN:
-for (i = 0 ; i < nparams ; i++) {
+for (i = 0; i < nparams; i++) {
 if (STREQ(params[i].key, "uuid")) {
 memcpy(priv->uuid, params[i].value.uuid, VIR_UUID_BUFLEN);
 } else if (STREQ(params[i].key, "name")) {
@@ -530,7 +530,7 @@ static char *virLockManagerLockDaemonDiskLeaseName(const 
char *path)
 return NULL;
 }
 
-for (i = 0 ; i < SHA256_DIGEST_SIZE ; i++) {
+for (i = 0; i < SHA256_DIGEST_SIZE; i++) {
 ret[i*2] = hex[(buf[i] >> 4) & 0xf];
 ret[(i*2)+1] = hex[buf[i] & 0xf];
 }
@@ -629,7 +629,7 @@ static int 
virLockManagerLockDaemonAddResource(virLockManagerPtr lock,
 size_t i;
 char *path = NULL;
 char *lockspace = NULL;
-for (i = 0 ; i < nparams ; i++) {
+for (i = 0; i < nparams; i++) {
 if (STREQ(params[i].key, "offset")) {
 if (params[i].value.ul != 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -725,7 +725,7 @@ static int 
virLockManagerLockDaemonAcquire(virLockManagerPtr lock,
 
 if (!(flags & VIR_LOCK_MANAGER_ACQUIRE_REGISTER_ONLY)) {
 size_t i;
-for (i = 0 ; i < priv->nresources ; i++) {
+for (i = 0; i < priv->nresources; i++) {
 virLockSpaceProtocolAcquireResourceArgs args;
 
 memset(&args, 0, sizeof(args));
@@ -781,7 +781,7 @@ static int 
virLockManagerLockDaemonRelease(virLockManagerPtr lock,
 if (!(client = virLockManagerLockDaemonConnect(lock, &program, &counter)))
 goto cleanup;
 
-for (i = 0 ; i < priv->nresources ; i++) {
+for (i = 0; i < priv->nresources; i++) {
 virLockSpaceProtocolReleaseResourceArgs args;
 
 memset(&args, 0, sizeof(args));
diff --git a/src/locking/lock_driver_sanlock.c 
b/src/locking/lock_driver_sanlock.c
index eb15e29..de14725 100644
--- a/src/locking/lock_driver_sanlock.c
+++ b/src/locking/lock_driver_sanlock.c
@@ -540,7 +540,7 @@ static int virLockManagerSanlockDiskLeaseName(const char 
*path,
 return -1;
 }
 
-for (i = 0 ; i < MD5_DIGEST_SIZE ; i++) {
+for (i = 0; i < MD5_DIGEST_SIZE; i++) {
 str[i*2] = hex[(buf[i] >> 4) & 0xf];
 str[(i*2)+1] = hex[buf[i] & 0xf];
 }
@@ -1020,7 +1020,7 @@ static int virLockManagerSanlockAcquire(virLockManagerPtr 
lock,
 VIR_DEBUG("Acquire completed fd=%d", sock);
 
 if (res_free) {
-fo

[libvirt] [PATCH 05/31] src/vbox: Remove the whitespace before '; '

2013-05-21 Thread Osier Yang
---
 src/vbox/vbox_tmpl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 5a5b429..36d1e7f 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -3478,7 +3478,7 @@ static int vboxConnectListDefinedDomains(virConnectPtr 
conn, char ** const names
 if (VIR_STRDUP(names[j], machineName) < 0) {
 VBOX_UTF16_FREE(machineNameUtf16);
 VBOX_UTF8_FREE(machineName);
-for (; j >= 0 ; j--)
+for (; j >= 0; j--)
 VIR_FREE(names[j]);
 ret = -1;
 goto cleanup;
-- 
1.8.1.4

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


[libvirt] [PATCH 07/31] src/nwfilter: Remove the whitespace before '; '

2013-05-21 Thread Osier Yang
---
 src/nwfilter/nwfilter_dhcpsnoop.c | 6 +++---
 src/nwfilter/nwfilter_driver.c| 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c 
b/src/nwfilter/nwfilter_dhcpsnoop.c
index 328f90e..b9921e5 100644
--- a/src/nwfilter/nwfilter_dhcpsnoop.c
+++ b/src/nwfilter/nwfilter_dhcpsnoop.c
@@ -29,13 +29,13 @@
 /*
  * Note about testing:
  *   On the host run in a shell:
- *  while :; do kill -SIGHUP `pidof libvirtd` ; echo "HUP $RANDOM"; sleep 
20; done
+ *  while :; do kill -SIGHUP `pidof libvirtd`; echo "HUP $RANDOM"; sleep 
20; done
  *
  *   Inside a couple of VMs that for example use the 'clean-traffic' filter:
- *  while :; do kill -SIGTERM `pidof dhclient`; dhclient eth0 ; ifconfig 
eth0; done
+ *  while :; do kill -SIGTERM `pidof dhclient`; dhclient eth0; ifconfig 
eth0; done
  *
  *   On the host check the lease file and that it's periodically shortened:
- *  cat /var/run/libvirt/network/nwfilter.leases ; date +%s
+ *  cat /var/run/libvirt/network/nwfilter.leases; date +%s
  *
  *   On the host also check that the ebtables rules 'look' ok:
  *  ebtables -t nat -L
diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c
index 64ea251..19febfc 100644
--- a/src/nwfilter/nwfilter_driver.c
+++ b/src/nwfilter/nwfilter_driver.c
@@ -452,7 +452,7 @@ nwfilterConnectListNWFilters(virConnectPtr conn,
 int got = 0, i;
 
 nwfilterDriverLock(driver);
-for (i = 0 ; i < driver->nwfilters.count && got < nnames ; i++) {
+for (i = 0; i < driver->nwfilters.count && got < nnames; i++) {
 virNWFilterObjLock(driver->nwfilters.objs[i]);
 if (VIR_STRDUP(names[got], driver->nwfilters.objs[i]->def->name) < 0) {
  virNWFilterObjUnlock(driver->nwfilters.objs[i]);
@@ -466,7 +466,7 @@ nwfilterConnectListNWFilters(virConnectPtr conn,
 
  cleanup:
 nwfilterDriverUnlock(driver);
-for (i = 0 ; i < got ; i++)
+for (i = 0; i < got; i++)
 VIR_FREE(names[i]);
 memset(names, 0, nnames * sizeof(*names));
 return -1;
@@ -499,7 +499,7 @@ nwfilterConnectListAllNWFilters(virConnectPtr conn,
 goto cleanup;
 }
 
-for (i = 0 ; i < driver->nwfilters.count; i++) {
+for (i = 0; i < driver->nwfilters.count; i++) {
 obj = driver->nwfilters.objs[i];
 virNWFilterObjLock(obj);
 if (!(filter = virGetNWFilter(conn, obj->def->name,
-- 
1.8.1.4

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


[libvirt] [PATCH 13/31] src/interface: Remove the whitespace before '; '

2013-05-21 Thread Osier Yang
---
 src/interface/interface_backend_udev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/interface/interface_backend_udev.c 
b/src/interface/interface_backend_udev.c
index 1fd7d46..6e27e83 100644
--- a/src/interface/interface_backend_udev.c
+++ b/src/interface/interface_backend_udev.c
@@ -42,7 +42,7 @@ typedef enum {
 VIR_UDEV_IFACE_ACTIVE,
 VIR_UDEV_IFACE_INACTIVE,
 VIR_UDEV_IFACE_ALL
-} virUdevStatus ;
+} virUdevStatus;
 
 static virInterfaceDef *udevGetIfaceDef(struct udev *udev, const char *name);
 
-- 
1.8.1.4

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


  1   2   >