[libvirt] [PATCH] fix MinGW compilation(200808)

2008-08-05 Thread Atsushi SAKAI
Hi,

Currently, compilation for MinGW is broken.
Here is the patch.
But configure script option for MinGW is changed from previous posting.
https://www.redhat.com/archives/libvir-list/2008-June/msg00145.html

Currently, it should do
# ./configure --without-xen --without-qemu --without-sasl --without-lxc 
--without-openvz --without-libvirtd --without-test

currently following 3 make works,
make
make install
make check
I do not know why syntax-check is not exist on Makefile on MinGW.

 src/domain_conf.c|2 ++
 src/network_conf.c   |2 ++
 src/virsh.c  |8 
 tests/testutilsxen.c |2 ++
 4 files changed, 14 insertions(+)

Thanks
Atsushi SAKAI



fix_compilation_for_mingw.patch
Description: Binary data
--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] fix MinGW compilation(200808)

2008-08-05 Thread Daniel Veillard
On Tue, Aug 05, 2008 at 04:24:08PM +0900, Atsushi SAKAI wrote:
 Hi,
 
 Currently, compilation for MinGW is broken.
 Here is the patch.
 But configure script option for MinGW is changed from previous posting.
 https://www.redhat.com/archives/libvir-list/2008-June/msg00145.html
 
 Currently, it should do
 # ./configure --without-xen --without-qemu --without-sasl --without-lxc 
 --without-openvz --without-libvirtd --without-test

  yes I made compilation with lxc and openvz default now, so changing this
is normal.

 currently following 3 make works,
 make
 make install
 make check
 I do not know why syntax-check is not exist on Makefile on MinGW.

  I would expect most development to still be done on Linux/Unix, so
that's not a big deal IMHO

  src/domain_conf.c|2 ++
  src/network_conf.c   |2 ++

  basically the changes remove compilations from the XML parsing code.
On one end I understand why it's not needed (currently) but I wonder why
this need to be defined out. Seems to me the code should compile on WIN32
and that's an important point if we ever want to get some native hypervisor
support there.
  So what miscompiled there ? Can we fix it ? in the interim having the code
compiled out as the patch does is fine, but I would like to understand.

  src/virsh.c  |8 

  edit on windows will be nasty, vi or $EDITOR is unixy

  tests/testutilsxen.c |2 ++

  okay

  4 files changed, 14 insertions(+)

  I think the patch is fine for now, but I would like to understand why
the conf files compile need to be supressed.

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard  | virtualization library  http://libvirt.org/
[EMAIL PROTECTED]  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/

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


Re: [libvirt] [PATCH] fix MinGW compilation(200808)

2008-08-05 Thread Daniel P. Berrange
On Tue, Aug 05, 2008 at 04:03:41AM -0400, Daniel Veillard wrote:
 On Tue, Aug 05, 2008 at 04:24:08PM +0900, Atsushi SAKAI wrote:
  Hi,
  
  Currently, compilation for MinGW is broken.
  Here is the patch.
  But configure script option for MinGW is changed from previous posting.
  https://www.redhat.com/archives/libvir-list/2008-June/msg00145.html
  
  Currently, it should do
  # ./configure --without-xen --without-qemu --without-sasl --without-lxc 
  --without-openvz --without-libvirtd --without-test
 
   yes I made compilation with lxc and openvz default now, so changing this
 is normal.
 
  currently following 3 make works,
  make
  make install
  make check
  I do not know why syntax-check is not exist on Makefile on MinGW.
 
   I would expect most development to still be done on Linux/Unix, so
 that's not a big deal IMHO
 
   src/domain_conf.c|2 ++
   src/network_conf.c   |2 ++
 
   basically the changes remove compilations from the XML parsing code.
 On one end I understand why it's not needed (currently) but I wonder why
 this need to be defined out. Seems to me the code should compile on WIN32
 and that's an important point if we ever want to get some native hypervisor
 support there.
   So what miscompiled there ? Can we fix it ? in the interim having the code
 compiled out as the patch does is fine, but I would like to understand.

Yes, this is completely wrong. The test driver and all the generic network,
and domain  XML code should all work on Windows. The only stuff we should
be disabling is hypervisor drivers, and Linux specific bits of code.

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

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


Re: [libvirt] [PATCH] make distclean: remove generated source files

2008-08-05 Thread Jim Meyering
Richard W.M. Jones [EMAIL PROTECTED] wrote:
 On Mon, Aug 04, 2008 at 04:24:55PM +0200, Jim Meyering wrote:
 --- a/src/Makefile.am
 +++ b/src/Makefile.am
 @@ -189,3 +189,4 @@ install-exec-local:
  $(MKDIR_P) $(DESTDIR)$(localstatedir)/cache/libvirt

  CLEANFILES = *.gcov .libs/*.gcda .libs/*.gcno *.gcno *.gcda
 +DISTCLEANFILES = $(BUILT_SOURCES)

 Ooops, that'd be my fault then.

Nah.  blame the reviewer (me) ;-)

I've committed the fix.

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


[libvirt] [PATCH]: Rework xenLinuxDomainDeviceID to support more devices

2008-08-05 Thread Chris Lalancette
Recently upstream Xen added support for having xvd devices  16.  For the most
part, this doesn't really concern libvirt, since for things like attach and
detach we just pass it through and let xend worry about whether it is supported
or not.  The one place this breaks down is in the stats collecting code, where
we need to figure out the device number so we can go digging in /sys for the
statistics.

To remedy this, I've re-written xenLinuxDomainDeviceID() to use regular
expressions to figure out the device number from the name.  The major advantage
is that now xenLinuxDomainDeviceID() looks fairly identical to
tools/python/xen/util/blkif.py (in the Xen sources), so that adding additional
devices in the future should be much easier.  It also reduces the size of the
code, and, in my opinion, the code complexity.

With this patch in place, I was able to get block statistics both on older style
devices (/dev/xvda) and on the new, expanded devices (/dev/xvdaa).

Signed-off-by: Chris Lalancette [EMAIL PROTECTED]
Index: src/stats_linux.c
===
RCS file: /data/cvs/libvirt/src/stats_linux.c,v
retrieving revision 1.15
diff -u -r1.15 stats_linux.c
--- a/src/stats_linux.c	23 May 2008 08:24:44 -	1.15
+++ b/src/stats_linux.c	5 Aug 2008 10:11:57 -
@@ -18,6 +18,7 @@
 #include fcntl.h
 #include string.h
 #include unistd.h
+#include regex.h
 #include c-ctype.h
 
 #ifdef WITH_XEN
@@ -28,6 +29,7 @@
 #include util.h
 #include xen_unified.h
 #include stats_linux.h
+#include memory.h
 
 /**
  * statsErrorFunc:
@@ -224,132 +226,114 @@
 return 0;
 }
 
+static int
+disk_re_match(const char *regex, const char *path, int *part)
+{
+regex_t myreg;
+int err;
+int retval;
+regmatch_t pmatch[2];
+
+retval = 0;
+
+err = regcomp(myreg, regex, REG_EXTENDED);
+if (err != 0)
+return 0;
+
+err = regexec(myreg, path, 2, pmatch, 0);
+
+if (err == 0) {
+/* OK, we have a match; see if we have a partition */
+*part = 0;
+if (pmatch[1].rm_so != -1)
+*part = strtol(path + pmatch[1].rm_so, NULL, 10);
+retval = 1;
+}
+
+regfree(myreg);
+
+return retval;
+}
+
 int
 xenLinuxDomainDeviceID(virConnectPtr conn, int domid, const char *path)
 {
-int disk, part = 0;
-
-/* Strip leading path if any */
-if (strlen(path)  5 
-STRPREFIX(path, /dev/))
-path += 5;
+int major, minor;
+int part;
+int retval;
+char *mod_path;
+
+int scsi_majors[] = { SCSI_DISK0_MAJOR, SCSI_DISK1_MAJOR,
+  SCSI_DISK2_MAJOR, SCSI_DISK3_MAJOR,
+  SCSI_DISK4_MAJOR, SCSI_DISK5_MAJOR,
+  SCSI_DISK6_MAJOR, SCSI_DISK7_MAJOR,
+  SCSI_DISK8_MAJOR, SCSI_DISK9_MAJOR,
+  SCSI_DISK10_MAJOR, SCSI_DISK11_MAJOR,
+  SCSI_DISK12_MAJOR, SCSI_DISK13_MAJOR,
+  SCSI_DISK14_MAJOR, SCSI_DISK15_MAJOR };
+int ide_majors[] = { IDE0_MAJOR, IDE1_MAJOR, IDE2_MAJOR, IDE3_MAJOR,
+ IDE4_MAJOR, IDE5_MAJOR, IDE6_MAJOR, IDE7_MAJOR,
+ IDE8_MAJOR, IDE9_MAJOR };
 
 /*
  * Possible block device majors  partition ranges. This
  * matches the ranges supported in Xend xen/util/blkif.py
  *
- * hdNM:  N=a-t, M=1-63,  major={IDE0_MAJOR - IDE9_MAJOR}
- * sdNM:  N=a-z,aa-iv, M=1-15,  major={SCSI_DISK0_MAJOR - SCSI_DISK15_MAJOR}
- * xvdNM: N=a-p, M=1-15,  major=XENVBD_MAJOR
- *
- * NB, the SCSI major isn't technically correct, as XenD only knows
- * about major=8. We cope with all SCSI majors in anticipation of
- * XenD perhaps being fixed one day
+ * hdNM:  N=a-t, M=1-63, major={IDE0_MAJOR - IDE9_MAJOR}
+ * sdNM:  N=a-z,aa-iv, M=1-15, major={SCSI_DISK0_MAJOR - SCSI_DISK15_MAJOR}
+ * xvdNM: N=a-p M=1-15, major=XENVBD_MAJOR
+ * xvdNM: N=q-z,aa-iz M=1-15, major=(128)
  *
  * The path for statistics will be
  *
  * /sys/devices/xen-backend/(vbd|tap)-{domid}-{devid}/statistics/{...}
  */
 
-if (strlen (path) = 4 
-STRPREFIX (path, xvd)) {
-/* Xen paravirt device handling */
-disk = (path[3] - 'a');
-if (disk  0 || disk  15) {
-statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
-invalid path, device names must be in range xvda - xvdp,
-domid);
-return -1;
-}
-
-if (path[4] != '\0') {
-if (!c_isdigit(path[4]) || path[4] == '0' ||
-virStrToLong_i(path+4, NULL, 10, part)  0 ||
-part  1 || part  15) {
-statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
-invalid path, partition numbers for xvdN must be in range 1 - 15,
-domid);
-return -1;
-

[libvirt] [PATCH] Save uuid when define/create domain

2008-08-05 Thread Evgeniy Sokolov

Hi,

There was bug.
UUID defined in XML or generated during define/create was not saved to 
config. Then it was regenerated in virDrvStateInitialize.


Attached patch fix bug.
Index: src/openvz_conf.c
===
RCS file: /data/cvs/libvirt/src/openvz_conf.c,v
retrieving revision 1.32
diff -u -p -r1.32 openvz_conf.c
--- src/openvz_conf.c	29 Jul 2008 08:42:56 -	1.32
+++ src/openvz_conf.c	5 Aug 2008 09:51:49 -
@@ -736,13 +736,14 @@ openvzGetVPSUUID(int vpsid, char *uuidst
 /* Do actual checking for UUID presence in conf file,
  * assign if not present.
  */
-
-static int
-openvzSetUUID(int vpsid)
+int
+openvzSetDefinedUUID(int vpsid, unsigned char *uuid)
 {
 char conf_file[PATH_MAX];
 char uuidstr[VIR_UUID_STRING_BUFLEN];
-unsigned char uuid[VIR_UUID_BUFLEN];
+
+if (uuid == NULL)
+return -1;
 
if (openvzLocateConfFile(vpsid, conf_file, PATH_MAX)0)
return -1;
@@ -755,7 +756,6 @@ openvzSetUUID(int vpsid)
 if (fp == NULL)
   return -1;
 
-virUUIDGenerate(uuid);
 virUUIDFormat(uuid, uuidstr);
 
 /* Record failure if fprintf or fclose fails,
@@ -768,6 +768,15 @@ openvzSetUUID(int vpsid)
 return 0;
 }
 
+static int
+openvzSetUUID(int vpsid){
+unsigned char uuid[VIR_UUID_BUFLEN];
+
+virUUIDGenerate(uuid);
+
+return openvzSetDefinedUUID(vpsid, uuid);
+}
+
 /*
  * Scan VPS config files and see if they have a UUID.
  * If not, assign one. Just append one to the config
Index: src/openvz_conf.h
===
RCS file: /data/cvs/libvirt/src/openvz_conf.h,v
retrieving revision 1.10
diff -u -p -r1.10 openvz_conf.h
--- src/openvz_conf.h	28 Jul 2008 14:06:54 -	1.10
+++ src/openvz_conf.h	5 Aug 2008 09:51:49 -
@@ -119,5 +119,6 @@ void openvzFreeVMDef(struct openvz_vm_de
 int strtoI(const char *str);
 int openvzCheckEmptyMac(const unsigned char *mac);
 char *openvzMacToString(const unsigned char *mac);
+int openvzSetDefinedUUID(int vpsid, unsigned char *uuid);
 
 #endif /* OPENVZ_CONF_H */
Index: src/openvz_driver.c
===
RCS file: /data/cvs/libvirt/src/openvz_driver.c,v
retrieving revision 1.36
diff -u -p -r1.36 openvz_driver.c
--- src/openvz_driver.c	28 Jul 2008 14:06:54 -	1.36
+++ src/openvz_driver.c	5 Aug 2008 09:51:49 -
@@ -459,6 +459,12 @@ openvzDomainDefineXML(virConnectPtr conn
 goto exit;
 }
 
+if (openvzSetDefinedUUID(strtoI(vmdef-name), vmdef-uuid)  0) {
+openvzError(conn, VIR_ERR_INTERNAL_ERROR,
+   _(Could not set UUID));
+goto exit;
+}
+
 dom = virGetDomain(conn, vm-vmdef-name, vm-vmdef-uuid);
 if (dom)
 dom-id = vm-vpsid;
@@ -514,6 +520,12 @@ openvzDomainCreateLinux(virConnectPtr co
 goto exit;
 }
 
+if (openvzSetDefinedUUID(strtoI(vmdef-name), vmdef-uuid)  0) {
+openvzError(conn, VIR_ERR_INTERNAL_ERROR,
+   _(Could not set UUID));
+goto exit;
+}
+
 if (openvzDomainSetNetwork(conn, vmdef-name, vmdef-net)  0) {
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
   _(Could not configure network));
--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH]: Rework xenLinuxDomainDeviceID to support more devices

2008-08-05 Thread Daniel P. Berrange
On Tue, Aug 05, 2008 at 12:12:21PM +0200, Chris Lalancette wrote:
 Recently upstream Xen added support for having xvd devices  16.  For the most
 part, this doesn't really concern libvirt, since for things like attach and
 detach we just pass it through and let xend worry about whether it is 
 supported
 or not.  The one place this breaks down is in the stats collecting code, where
 we need to figure out the device number so we can go digging in /sys for the
 statistics.
 
 To remedy this, I've re-written xenLinuxDomainDeviceID() to use regular
 expressions to figure out the device number from the name.  The major 
 advantage
 is that now xenLinuxDomainDeviceID() looks fairly identical to
 tools/python/xen/util/blkif.py (in the Xen sources), so that adding additional
 devices in the future should be much easier.  It also reduces the size of the
 code, and, in my opinion, the code complexity.
 
 With this patch in place, I was able to get block statistics both on older 
 style
 devices (/dev/xvda) and on the new, expanded devices (/dev/xvdaa).

This patch breaks the test suite for disk name - device ID conversion.
The test suite also needs to have more  tests added to cover the new 
interesting boundary conditions for xvdXXX naming.

  
 -if (strlen (path) = 4 
 -STRPREFIX (path, xvd)) {
 -/* Xen paravirt device handling */
 -disk = (path[3] - 'a');
 -if (disk  0 || disk  15) {
 -statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
 -invalid path, device names must be in range 
 xvda - xvdp,
 -domid);
 -return -1;
 -}

I don't like the fact that for 'out of range' values this patch is removing
this accurate and helpful error message.

 -return (majors[disk/2] * 256) + ((disk % 2) * 63) + part;
 +if (disk_re_match(/dev/sd[a-z]([1-9]|1[0-5])?$, mod_path, part)) {
 +major = scsi_majors[(mod_path[7] - 'a') / 16];
 +minor = ((mod_path[7] - 'a') % 16) * 16 + part;
 +retval = major * 256 + minor;
  }
 +else if (disk_re_match(/dev/sd[a-i][a-z]([1-9]|1[0-5])?$,
 +   mod_path, part)) {
 +major = scsi_majors[((mod_path[7] - 'a' + 1) * 26 + (mod_path[8] - 
 'a')) / 16];
 +minor = (((mod_path[7] -'a' + 1) * 26 + (mod_path[8] - 'a')) % 16)
 +* 16 + part;
 +retval = major * 256 + minor;
 +}
 +else if (disk_re_match(/dev/hd[a-t]([1-9]|[1-5][0-9]|6[0-3])?,
 +   mod_path, part)) {
 +major = ide_majors[(mod_path[7] - 'a') / 2];
 +minor = ((mod_path[7] - 'a') % 2) * 64 + part;
 +retval = major * 256 + minor;
 +}
 +else if (disk_re_match(/dev/xvd[a-p]([1-9]|1[0-5])?$, mod_path, part))
 +retval = (202  8) + ((mod_path[8] - 'a')  4) + part;
 +else if (disk_re_match(/dev/xvd[q-z]([1-9]|1[0-5])?$, mod_path, part))
 +retval = (1  28) + ((mod_path[8] - 'a')  8) + part;
 +else if (disk_re_match(/dev/xvd[a-i][a-z]([1-9]|1[0-5])?$,
 +   mod_path, part))
 +retval = (1  28) + (((mod_path[8] - 'a' + 1) * 26 + (mod_path[9] - 
 'a'))  8) + part;
 +else
 +statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
 +unsupported path, use xvdN, hdN, or sdN, domid);

...and replacing it with this unhelpful  misleading one. 

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

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


Re: [libvirt] [PATCH]: Rework xenLinuxDomainDeviceID to support more devices

2008-08-05 Thread Daniel Veillard
On Tue, Aug 05, 2008 at 12:12:21PM +0200, Chris Lalancette wrote:
 Recently upstream Xen added support for having xvd devices  16.  For the most
 part, this doesn't really concern libvirt, since for things like attach and
 detach we just pass it through and let xend worry about whether it is 
 supported
 or not.  The one place this breaks down is in the stats collecting code, where
 we need to figure out the device number so we can go digging in /sys for the
 statistics.
 
 To remedy this, I've re-written xenLinuxDomainDeviceID() to use regular
 expressions to figure out the device number from the name.  The major 
 advantage
 is that now xenLinuxDomainDeviceID() looks fairly identical to
 tools/python/xen/util/blkif.py (in the Xen sources), so that adding additional
 devices in the future should be much easier.  It also reduces the size of the
 code, and, in my opinion, the code complexity.
 
 With this patch in place, I was able to get block statistics both on older 
 style
 devices (/dev/xvda) and on the new, expanded devices (/dev/xvdaa).

  Sounds good to me even if I don't grasp all the naming convention.

 Signed-off-by: Chris Lalancette [EMAIL PROTECTED]
[...]
 +/* OK, we have a match; see if we have a partition */
 +*part = 0;
 +if (pmatch[1].rm_so != -1)
 +*part = strtol(path + pmatch[1].rm_so, NULL, 10);

 let's use __virStrToLong_i internally

I think it makes that code a bit more readable too, +1

 thanks

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard  | virtualization library  http://libvirt.org/
[EMAIL PROTECTED]  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/

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


Re: [libvirt] [PATCH] Save uuid when define/create domain

2008-08-05 Thread Daniel Veillard
On Tue, Aug 05, 2008 at 02:14:16PM +0400, Evgeniy Sokolov wrote:
 Hi,
 
 There was bug.
 UUID defined in XML or generated during define/create was not saved to 
 config. Then it was regenerated in virDrvStateInitialize.

  That sounds fine, and the patch looks good too,

applied and commited, thanks !

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard  | virtualization library  http://libvirt.org/
[EMAIL PROTECTED]  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/

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


Re: [libvirt] [PATCH]: Rework xenLinuxDomainDeviceID to support more devices

2008-08-05 Thread Daniel P. Berrange
On Tue, Aug 05, 2008 at 06:47:34AM -0400, Daniel Veillard wrote:
 On Tue, Aug 05, 2008 at 12:12:21PM +0200, Chris Lalancette wrote:
  Recently upstream Xen added support for having xvd devices  16.  For the 
  most
  part, this doesn't really concern libvirt, since for things like attach and
  detach we just pass it through and let xend worry about whether it is 
  supported
  or not.  The one place this breaks down is in the stats collecting code, 
  where
  we need to figure out the device number so we can go digging in /sys for the
  statistics.
  
  To remedy this, I've re-written xenLinuxDomainDeviceID() to use regular
  expressions to figure out the device number from the name.  The major 
  advantage
  is that now xenLinuxDomainDeviceID() looks fairly identical to
  tools/python/xen/util/blkif.py (in the Xen sources), so that adding 
  additional
  devices in the future should be much easier.  It also reduces the size of 
  the
  code, and, in my opinion, the code complexity.
  
  With this patch in place, I was able to get block statistics both on older 
  style
  devices (/dev/xvda) and on the new, expanded devices (/dev/xvdaa).
 
   Sounds good to me even if I don't grasp all the naming convention.
 
  Signed-off-by: Chris Lalancette [EMAIL PROTECTED]
 [...]
  +/* OK, we have a match; see if we have a partition */
  +*part = 0;
  +if (pmatch[1].rm_so != -1)
  +*part = strtol(path + pmatch[1].rm_so, NULL, 10);
 
  let's use __virStrToLong_i internally
 
 I think it makes that code a bit more readable too, +1

It is more readable because it doesn't give as detailed error
reporting to the caller. I don't consider that a positive thing

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

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


Re: [libvirt] libvirt-java storage support and refactoring

2008-08-05 Thread Tóth István
Daniel Veillard wrote:
 On Mon, Aug 04, 2008 at 11:59:38PM +0200, Toth Istvan wrote:
   
 Here's a new take on the patch (It's against current CVS)

 The changes from the previous patch:

 - I've changed the generic functions to macros, so now they are as
 typesafe as JNI lets them be.

 - I've converted all applicable functions to the new macros
 
   the comments seems to indicate we still have leaks, any idea  why seems
 all converted strings get released now, or did i miss things ?
   
I've just forgotten to delete them.
I believe that there still some java object leaks in the more complex
functions, but those are not String related.
I'll have to re-check JNI memory mamagement, to make sure that every
temporary object that we create is garbage collectible,
as I've glossed over these details previously :-).
Also, some compley JNI functions could be reduced as about a third of
their size,
if we created appropiate java constructors/helpers for them, instead of
filling them field-by field from the JNI code.
   Okay, I was wondering about that. Thanks for double-checking !
 I'm applying the patch to CVS, i will just do a few space/tab cleanups
 and also upgrading the required version in configure.in to 0.4.1.

   Probably worth pushing a new version soon too,

 thanks a million !
   
You are welcome!

 Daniel

   

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


Re: [libvirt] libvirt-java storage support and refactoring

2008-08-05 Thread Daniel Veillard
On Mon, Aug 04, 2008 at 11:59:38PM +0200, Toth Istvan wrote:
 Here's a new take on the patch (It's against current CVS)
 
 The changes from the previous patch:
 
 - I've changed the generic functions to macros, so now they are as
 typesafe as JNI lets them be.
 
 - I've converted all applicable functions to the new macros

  indeed a big cleanup, the reduction in size and readability improvement is
notable :-)

 - Fixed more GetStringUTF... leaks

  the comments seems to indicate we still have leaks, any idea  why seems
all converted strings get released now, or did i miss things ?

 - Added SerialVersionUID to make Java happy

  ah, yeah got that warning :-)

 - Supressed warning about unused java method

  ah, that's the reason of the @SuppressWarnings

 This patch contains all outstanding major work that I had planned to do
 short-term.
 
 I think that all 0.4.1 functionality is in, and the Peek functions are
 the only ones that remain from 0.4.4. I have plans to implement that as
 well, but it may take a while, as they are not that interesting or
 usable from java-land.

  yeah, we don't have Python bindings either ATM.

 I've decided not to take the suggested script-generated route, because
 at this point it seemed more trouble than it was worth. (The easy
 methods are added in 3 minutes each as it is, and it won't help with the
 complex ones. Also, the JNI workflow of .java-.class-.h-.c makes
 auto-generation too hairy for my tastes.)

  agreed,

 I've also re-evaluated the usage of jlong for pointers, but I still
 think that it is solid. Realistically, the code will run either 32 or 64
 bit architecture. On 64 bit the size is the same, and while there is a
 signed-ness difference, the java code does no arithmetic on the values,
 so it should be safe. If we run on 32 bits, then the JNI C code will
 cast the received 32 bit pointer to 64 bit, which java will store as 64
 bit signed, and then the reverse cast will convert it back to a 32 bit
 pointer, the upper 32 bits are zeroed out all the way, so again, no data
 is lost or corrupted.

  Okay, I was wondering about that. Thanks for double-checking !
I'm applying the patch to CVS, i will just do a few space/tab cleanups
and also upgrading the required version in configure.in to 0.4.1.

  Probably worth pushing a new version soon too,

thanks a million !

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard  | virtualization library  http://libvirt.org/
[EMAIL PROTECTED]  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/

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


Re: [libvirt] [PATCH] fix MinGW compilation(200808)

2008-08-05 Thread Richard W.M. Jones
On Tue, Aug 05, 2008 at 04:24:08PM +0900, Atsushi SAKAI wrote:
  src/virsh.c  |8 

Is it possible to get edit working on Windows?  My MinGW system has a
program which looks like 'vi' ...

Rich.

-- 
Richard Jones, Emerging Technologies, Red Hat  http://et.redhat.com/~rjones
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top

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


[libvirt] [PATCH]: Fix virsh attach-disk and virsh attach-interface

2008-08-05 Thread Chris Lalancette
With the recent refactoring of the domain code, plus the changes with the Xend
code, a couple of bugs were introduced into the attach-disk and attach-interface
functionality.  This patch fixes 3 bugs:

1)  In xenDaemonAttachDevice(), there is a switch statement to determine which
of the xenDaemonFormatSxpr{Disk,Net} functions to call.  Unfortunately, the case
statements are all missing the corresponding break, so we always fall-through
to the default error case.  This patch just adds the appropriate break 
statements.

2)  (minor) In xenDaemonDomainDefineXML (that's a mouthful!), there is a stray
fprintf.  This is now converted to a proper virXendError().

3)  xenDaemonFormatSxpr{Disk,Net} were adding an extra (device to the front of
the sexpr expressions that xend did not expect (this is Xend on RHEL 5.2).
Because of this, the attaches would fail.  The patch fixes this by removing the
(device from the front, which makes attach-disk and attach-interface work again.

Signed-off-by: Chris Lalancette [EMAIL PROTECTED]
Index: src/xend_internal.c
===
RCS file: /data/cvs/libvirt/src/xend_internal.c,v
retrieving revision 1.207
diff -u -r1.207 xend_internal.c
--- a/src/xend_internal.c	4 Aug 2008 06:33:25 -	1.207
+++ b/src/xend_internal.c	5 Aug 2008 09:59:57 -
@@ -3900,6 +3900,7 @@
 STREQ(def-os.type, hvm) ? 1 : 0,
 priv-xendConfigVersion)  0)
 goto cleanup;
+break;
 
 case VIR_DOMAIN_DEVICE_NET:
 if (xenDaemonFormatSxprNet(domain-conn,
@@ -3908,6 +3909,7 @@
STREQ(def-os.type, hvm) ? 1 : 0,
priv-xendConfigVersion)  0)
 goto cleanup;
+break;
 
 default:
 virXendError(domain-conn, VIR_ERR_NO_SUPPORT, %s,
@@ -4292,7 +4294,8 @@
 ret = xend_op(conn, , op, new, config, sexpr, NULL);
 VIR_FREE(sexpr);
 if (ret != 0) {
-fprintf(stderr, _(Failed to create inactive domain %s\n), name);
+virXendError(conn, VIR_ERR_XEN_CALL,
+ _(Failed to create inactive domain %s\n), name);
 goto error;
 }
 
@@ -5029,7 +5032,6 @@
 xendConfigVersion == 1)
 return 0;
 
-virBufferAddLit(buf, (device );
 /* Normally disks are in a (device (vbd ...)) block
  * but blktap disks ended up in a differently named
  * (device (tap )) block */
@@ -5083,7 +5085,7 @@
 else
 virBufferAddLit(buf, (mode 'w'));
 
-virBufferAddLit(buf, )));
+virBufferAddLit(buf, ));
 
 return 0;
 }
@@ -5117,7 +5119,7 @@
 return -1;
 }
 
-virBufferAddLit(buf, (device (vif );
+virBufferAddLit(buf, (vif );
 
 virBufferVSprintf(buf,
   (mac '%02x:%02x:%02x:%02x:%02x:%02x'),
@@ -5177,7 +5179,7 @@
 if ((hvm)  (xendConfigVersion  4))
 virBufferAddLit(buf, (type ioemu));
 
-virBufferAddLit(buf, )));
+virBufferAddLit(buf, ));
 
 return 0;
 }
--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] fix MinGW compilation(200808)

2008-08-05 Thread Atsushi SAKAI
Hi, Dan and Daniel

Thank you for commenting this.
I am digging into the problem domain_conf.c, network_conf.c and test driver.

Just for network_conf.c outputs following message.

 gcc -DHAVE_CONFIG_H -I. -I.. -I../gnulib/lib -I../gnulib/lib -I../include 
-I../include -I../qemud -Ic:/MinGW/lib/GTK/include/libxml2 
-DBINDIR=\/usr/local/libexec\ -DSBINDIR=\/usr/local/sbin\ 
-DSYSCONF_DIR=\/usr/local/etc\ -DLOCALEBASEDIR=\/usr/local/share/locale\ 
-DLOCAL_STATE_DIR=\/usr/local/var\ -DGETTEXT_PACKAGE=\libvirt\ -Wall 
-Wformat -Wformat-security -Wmissing-prototypes -Wnested-externs 
-Wpointer-arith -Wextra -Wshadow -Wcast-align -Wwrite-strings 
-Waggregate-return -Wstrict-prototypes -Winline -Wredundant-decls 
-Wno-sign-compare -Wp,-D_FORTIFY_SOURCE=2 -fexceptions 
-fasynchronous-unwind-tables -DWITH_REMOTE -DIN_LIBVIRT -g -O2 -MT 
libvirt_la-network_conf.lo -MD -MP -MF .deps/libvirt_la-network_conf.Tpo -c 
network_conf.c  -DDLL_EXPORT -DPIC -o .libs/libvirt_la-network_conf.o
In file included from ../gnulib/lib/arpa/inet.h:24,
 from network_conf.c:29:
../gnulib/lib/sys/socket.h:109: warning: declaration of 'socket' shadows a 
global declaration
c:/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/winsock2.h:553: 
warning: shadowed declaration is here
network_conf.c: In function `virNetworkDefParseXML':
network_conf.c:290: warning: implicit declaration of function `inet_aton'
network_conf.c:290: warning: nested extern declaration of `inet_aton'
network_conf.c: In function `virNetworkSaveConfig':
network_conf.c:598: error: `S_IRUSR' undeclared (first use in this function)
network_conf.c:598: error: (Each undeclared identifier is reported only once
network_conf.c:598: error: for each function it appears in.)
network_conf.c:598: error: `S_IWUSR' undeclared (first use in this function)
make[3]: *** [libvirt_la-network_conf.lo] Error 1
make[3]: Leaving directory `/home/Administrator/work/libvirt-0.4.4/src'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/home/Administrator/work/libvirt-0.4.4/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/Administrator/work/libvirt-0.4.4'
make: *** [all] Error 2
=

Thanks
Atsushi SAKAI


Daniel P. Berrange [EMAIL PROTECTED] wrote:

 On Tue, Aug 05, 2008 at 04:03:41AM -0400, Daniel Veillard wrote:
  On Tue, Aug 05, 2008 at 04:24:08PM +0900, Atsushi SAKAI wrote:
   Hi,
   
   Currently, compilation for MinGW is broken.
   Here is the patch.
   But configure script option for MinGW is changed from previous posting.
   https://www.redhat.com/archives/libvir-list/2008-June/msg00145.html
   
   Currently, it should do
   # ./configure --without-xen --without-qemu --without-sasl --without-lxc 
   --without-openvz --without-libvirtd --without-test
  
yes I made compilation with lxc and openvz default now, so changing this
  is normal.
  
   currently following 3 make works,
   make
   make install
   make check
   I do not know why syntax-check is not exist on Makefile on MinGW.
  
I would expect most development to still be done on Linux/Unix, so
  that's not a big deal IMHO
  
src/domain_conf.c|2 ++
src/network_conf.c   |2 ++
  
basically the changes remove compilations from the XML parsing code.
  On one end I understand why it's not needed (currently) but I wonder why
  this need to be defined out. Seems to me the code should compile on WIN32
  and that's an important point if we ever want to get some native hypervisor
  support there.
So what miscompiled there ? Can we fix it ? in the interim having the code
  compiled out as the patch does is fine, but I would like to understand.
 
 Yes, this is completely wrong. The test driver and all the generic network,
 and domain  XML code should all work on Windows. The only stuff we should
 be disabling is hypervisor drivers, and Linux specific bits of code.
 
 Daniel
 -- 
 |: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
 |: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
 |: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
 |: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|


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


Re: [libvirt] [PATCH]: Fix virsh attach-disk and virsh attach-interface

2008-08-05 Thread Daniel Veillard
On Tue, Aug 05, 2008 at 12:02:47PM +0200, Chris Lalancette wrote:
 With the recent refactoring of the domain code, plus the changes with the Xend
 code, a couple of bugs were introduced into the attach-disk and 
 attach-interface
 functionality.  This patch fixes 3 bugs:
 
 1)  In xenDaemonAttachDevice(), there is a switch statement to determine which
 of the xenDaemonFormatSxpr{Disk,Net} functions to call.  Unfortunately, the 
 case
 statements are all missing the corresponding break, so we always 
 fall-through
 to the default error case.  This patch just adds the appropriate break 
 statements.
 
 2)  (minor) In xenDaemonDomainDefineXML (that's a mouthful!), there is a stray
 fprintf.  This is now converted to a proper virXendError().
 
 3)  xenDaemonFormatSxpr{Disk,Net} were adding an extra (device to the front of
 the sexpr expressions that xend did not expect (this is Xend on RHEL 5.2).
 Because of this, the attaches would fail.  The patch fixes this by removing 
 the
 (device from the front, which makes attach-disk and attach-interface work 
 again.
 
 Signed-off-by: Chris Lalancette [EMAIL PROTECTED]


  1/ and 2/ are obvious errors, for 3/ I guess it's not dependent on the
Xen version so I think it's fine.

  +1

thanks !

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard  | virtualization library  http://libvirt.org/
[EMAIL PROTECTED]  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/

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


Re: [libvirt] [PATCH] fix MinGW compilation(200808)

2008-08-05 Thread Jim Meyering
Atsushi SAKAI [EMAIL PROTECTED] wrote:
...
 network_conf.c:290: warning: implicit declaration of function `inet_aton'
 network_conf.c:290: warning: nested extern declaration of `inet_aton'

We can/should use inet_pton instead.  Then, not only do we use what seems
to be the preferred interface, but there is a gnulib module by the same
name that can come into play if it too is missing.

 network_conf.c:598: error: `S_IRUSR' undeclared (first use in this function)

The remaining problems should be easy to resolve:
Add this line to network_conf.c:

#include sys/stat.h

 network_conf.c:598: error: (Each undeclared identifier is reported only once
 network_conf.c:598: error: for each function it appears in.)
 network_conf.c:598: error: `S_IWUSR' undeclared (first use in this function)

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


Re: [libvirt] [PATCH] fix MinGW compilation(200808)

2008-08-05 Thread Daniel P. Berrange
On Tue, Aug 05, 2008 at 01:52:58PM +0200, Jim Meyering wrote:
 Atsushi SAKAI [EMAIL PROTECTED] wrote:
 ...
  network_conf.c:290: warning: implicit declaration of function `inet_aton'
  network_conf.c:290: warning: nested extern declaration of `inet_aton'
 
 We can/should use inet_pton instead.  Then, not only do we use what seems
 to be the preferred interface, but there is a gnulib module by the same
 name that can come into play if it too is missing.

Even better would be to use  getaddrinfo() with AI_NUMERIC, since we
already require getaddrinfo() to work on Windows for the remote driver

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

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


Re: [libvirt] [PATCH]: Rework xenLinuxDomainDeviceID to support more devices

2008-08-05 Thread Chris Lalancette
Daniel P. Berrange wrote:
 On Tue, Aug 05, 2008 at 12:12:21PM +0200, Chris Lalancette wrote:
 Recently upstream Xen added support for having xvd devices  16.  For the 
 most
 part, this doesn't really concern libvirt, since for things like attach and
 detach we just pass it through and let xend worry about whether it is 
 supported
 or not.  The one place this breaks down is in the stats collecting code, 
 where
 we need to figure out the device number so we can go digging in /sys for the
 statistics.

 To remedy this, I've re-written xenLinuxDomainDeviceID() to use regular
 expressions to figure out the device number from the name.  The major 
 advantage
 is that now xenLinuxDomainDeviceID() looks fairly identical to
 tools/python/xen/util/blkif.py (in the Xen sources), so that adding 
 additional
 devices in the future should be much easier.  It also reduces the size of the
 code, and, in my opinion, the code complexity.

 With this patch in place, I was able to get block statistics both on older 
 style
 devices (/dev/xvda) and on the new, expanded devices (/dev/xvdaa).
 
 This patch breaks the test suite for disk name - device ID conversion.
 The test suite also needs to have more  tests added to cover the new 
 interesting boundary conditions for xvdXXX naming.

OK.  Well, there were 3 different problems with the test suite:

1)  A number of tests were actually wrong.  For instance, there is a
DO_TEST(/dev/hdt, 23359); but Xen actually uses the encoding major*256 +
minor + part.  So in this case, the major is 91, and the minor is 64 (according
to http://www.lanana.org/docs/device-list/devices.txt), so that would be 23360.
 I've fixed the wrong tests now, and I'll re-submit it with the updated patch.

2)  In the hda0 and hda64 case, the upstream Xen regex isn't tight enough.  I've
tightened it up in the libvirt patch, so these now pass.

3)  The upstream Xen regex's allows /dev/sdi{w,x,y,z}, although they aren't
legal devices.  I've fixed up my regex to handle this.

Attached is an updated patch with the above fixes both to my code and to the
test suite.  As far as the error reporting goes, I won't argue that my patch
gives slightly less information.  However, that being said, I have to believe
that the most likely use of block statistics is something like:

virsh dumpxml dom
...see what devices are listed there
virsh domblkstats dom device

In which case the slightly less verbose error reporting won't matter a whole 
lot.

Chris Lalancette
Index: tests/statstest.c
===
RCS file: /data/cvs/libvirt/tests/statstest.c,v
retrieving revision 1.7
diff -u -r1.7 statstest.c
--- a/tests/statstest.c	29 May 2008 15:31:49 -	1.7
+++ b/tests/statstest.c	5 Aug 2008 12:08:27 -
@@ -74,18 +74,28 @@
 DO_TEST(xvda, 51712);
 DO_TEST(xvda1, 51713);
 DO_TEST(xvda15, 51727);
-/* Last valid disk */
+/* Last non-extended disk */
 DO_TEST(xvdp, 51952);
 DO_TEST(xvdp1, 51953);
 DO_TEST(xvdp15, 51967);
 
-/* Disk letter to large */
-DO_TEST(xvdq, -1);
+/* First extended disk */
+DO_TEST(xvdq, 268439552);
+DO_TEST(xvdq1, 268439553);
+DO_TEST(xvdq15, 268439567);
+/* Last extended disk */
+DO_TEST(xvdiz, 268501760);
+DO_TEST(xvdiz1, 268501761);
+DO_TEST(xvdiz15, 268501775);
+
+/* Disk letter too large */
+DO_TEST(xvdja, -1);
+
 /* missing disk letter */
 DO_TEST(xvd1, -1);
-/* partition to large */
+/* partition too large */
 DO_TEST(xvda16, -1);
-/* partition to small */
+/* partition too small */
 DO_TEST(xvda0, -1);
 /* leading zeros */
 DO_TEST(xvda01, -1);
@@ -98,26 +108,34 @@
  * IDE disks
  /
 
-/* odd numbered disk */
+/* first numbered disk */
 DO_TEST(hda, 768);
 DO_TEST(hda1, 769);
 DO_TEST(hda63, 831);
-/* even number disk */
-DO_TEST(hdd, 5695);
-DO_TEST(hdd1, 5696);
-DO_TEST(hdd63, 5758);
+/* second numbered disk */
+DO_TEST(hdb, 832);
+DO_TEST(hdb1, 833);
+DO_TEST(hdb63, 895);
+/* third numbered disk */
+DO_TEST(hdc, 5632);
+DO_TEST(hdc1, 5633);
+DO_TEST(hdc63, 5695);
+/* fourth number disk */
+DO_TEST(hdd, 5696);
+DO_TEST(hdd1, 5697);
+DO_TEST(hdd63, 5759);
 /* last valid disk */
-DO_TEST(hdt, 23359);
-DO_TEST(hdt1, 23360);
-DO_TEST(hdt63, 23422);
+DO_TEST(hdt, 23360);
+DO_TEST(hdt1, 23361);
+DO_TEST(hdt63, 23423);
 
 /* Disk letter to large */
 DO_TEST(hdu, -1);
 /* missing disk letter */
 DO_TEST(hd1, -1);
-/* partition to large */
+/* partition too large */
 DO_TEST(hda64, -1);
-/* partition to small */
+/* partition too small */
 DO_TEST(hda0, -1);
 
 
@@ -159,13 +177,13 @@
 DO_TEST(sdiv1, 34801);
 DO_TEST(sdiv15, 34815);
 
-/* Disk letter to large */
+/* Disk letter too large */
 DO_TEST(sdix, -1);
 /* missing 

Re: [libvirt] [PATCH]: Rework xenLinuxDomainDeviceID to support more devices

2008-08-05 Thread Daniel P. Berrange
On Tue, Aug 05, 2008 at 02:08:24PM +0200, Chris Lalancette wrote:
 Daniel P. Berrange wrote:
  On Tue, Aug 05, 2008 at 12:12:21PM +0200, Chris Lalancette wrote:
  Recently upstream Xen added support for having xvd devices  16.  For the 
  most
  part, this doesn't really concern libvirt, since for things like attach and
  detach we just pass it through and let xend worry about whether it is 
  supported
  or not.  The one place this breaks down is in the stats collecting code, 
  where
  we need to figure out the device number so we can go digging in /sys for 
  the
  statistics.
 
  To remedy this, I've re-written xenLinuxDomainDeviceID() to use regular
  expressions to figure out the device number from the name.  The major 
  advantage
  is that now xenLinuxDomainDeviceID() looks fairly identical to
  tools/python/xen/util/blkif.py (in the Xen sources), so that adding 
  additional
  devices in the future should be much easier.  It also reduces the size of 
  the
  code, and, in my opinion, the code complexity.
 
  With this patch in place, I was able to get block statistics both on older 
  style
  devices (/dev/xvda) and on the new, expanded devices (/dev/xvdaa).
  
  This patch breaks the test suite for disk name - device ID conversion.
  The test suite also needs to have more  tests added to cover the new 
  interesting boundary conditions for xvdXXX naming.
 
 OK.  Well, there were 3 different problems with the test suite:
 
 1)  A number of tests were actually wrong.  For instance, there is a
 DO_TEST(/dev/hdt, 23359); but Xen actually uses the encoding major*256 +
 minor + part.  So in this case, the major is 91, and the minor is 64 
 (according
 to http://www.lanana.org/docs/device-list/devices.txt), so that would be 
 23360.
  I've fixed the wrong tests now, and I'll re-submit it with the updated patch.
 
 2)  In the hda0 and hda64 case, the upstream Xen regex isn't tight enough.  
 I've
 tightened it up in the libvirt patch, so these now pass.
 
 3)  The upstream Xen regex's allows /dev/sdi{w,x,y,z}, although they aren't
 legal devices.  I've fixed up my regex to handle this.
 
 Attached is an updated patch with the above fixes both to my code and to the
 test suite.  As far as the error reporting goes, I won't argue that my patch
 gives slightly less information.  However, that being said, I have to believe
 that the most likely use of block statistics is something like:

I'd like to see a patch which does an hybrid of the existing vs regex
approach. ie, use a single regex to split the string into disk prefix, 
disk number, and partition number. Then do validation on the ranges 
and report errors accordingly.

 virsh dumpxml dom
 ...see what devices are listed there
 virsh domblkstats dom device
 
 In which case the slightly less verbose error reporting won't matter a whole 
 lot.

Error reporting shouldn't be done based on the based on a particular
usage scenario. Any API call should aim to give error messages that
are detailed enough to understand the actual problem without needing
further context.

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

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


Re: [libvirt] [PATCH]: Rework xenLinuxDomainDeviceID to support more devices

2008-08-05 Thread Jim Meyering
Chris Lalancette [EMAIL PROTECTED] wrote:
...
 test suite.  As far as the error reporting goes, I won't argue that my patch
 gives slightly less information.  However, that being said, I have to believe
 that the most likely use of block statistics is something like:

 virsh dumpxml dom
 ...see what devices are listed there
 virsh domblkstats dom device

 In which case the slightly less verbose error reporting won't matter a whole 
 lot.

Hi Chris,

...
 Index: src/stats_linux.c
 ===
...
 +static int
 +disk_re_match(const char *regex, const char *path, int *part)
 +{
 +regex_t myreg;
 +int err;
 +int retval;
 +regmatch_t pmatch[2];
 +
 +retval = 0;
 +
 +err = regcomp(myreg, regex, REG_EXTENDED);
 +if (err != 0)
 +return 0;
 +
 +err = regexec(myreg, path, 2, pmatch, 0);
 +
 +if (err == 0) {
 +/* OK, we have a match; see if we have a partition */
 +*part = 0;
 +if (pmatch[1].rm_so != -1) {
 +if (virStrToLong_i(path + pmatch[1].rm_so, NULL, 10, part)  0)
 +retval = 0;
 +else
 +retval = 1;
 +}
 +else
 +retval = 1;
 +}

How about dropping both else blocks and initializing retval=1 above:

   if (err == 0) {
   /* OK, we have a match; see if we have a partition */
   *part = 0;
   retval = 1;
   if (pmatch[1].rm_so != -1) {
   if (virStrToLong_i(path + pmatch[1].rm_so, NULL, 10, part)  0)
   retval = 0;
   }
   }

You could even reduce the retval-setting part to a single statement:

if (err == 0) {
/* OK, we have a match; see if we have a partition */
*part = 0;
retval = (pmatch[1].rm_so == -1
  || virStrToLong_i(path + pmatch[1].rm_so,
NULL, 10, part) == 0);
}

  int
  xenLinuxDomainDeviceID(virConnectPtr conn, int domid, const char *path)
  {
 -int disk, part = 0;
 -
 -/* Strip leading path if any */
 -if (strlen(path)  5 
 -STRPREFIX(path, /dev/))
 -path += 5;
 +int major, minor;
 +int part;
 +int retval;
 +char *mod_path;
 +
 +int scsi_majors[] = { SCSI_DISK0_MAJOR, SCSI_DISK1_MAJOR,

I know you just moved these, but they can be const:

   int const scsi_majors[] = {...

...
 +int ide_majors[] = { IDE0_MAJOR, IDE1_MAJOR, IDE2_MAJOR, IDE3_MAJOR,

   int const ide_majors[] = { ...

...
 +if (strlen(path)  5  STRPREFIX(path, /dev/))

Maybe use = 5, so that this code will preserve /dev/,
rather than turn it into /dev//dev/ ?

 +retval = asprintf(mod_path, %s, path);
 +else
 +retval = asprintf(mod_path, /dev/%s, path);
...
 +if (disk_re_match(/dev/sd[a-z]([1-9]|1[0-5])?$, mod_path, part)) {
 +major = scsi_majors[(mod_path[7] - 'a') / 16];
 +minor = ((mod_path[7] - 'a') % 16) * 16 + part;
 +retval = major * 256 + minor;
 +}
 +else if (disk_re_match(/dev/sd[a-h][a-z]([1-9]|1[0-5])?$,
 +   mod_path, part) ||
 + disk_re_match(/dev/sdi[a-v]([1-9]|1[0-5])?$,
 +   mod_path, part)) {
 +major = scsi_majors[((mod_path[7] - 'a' + 1) * 26 + (mod_path[8] - 
 'a')) / 16];
 +minor = (((mod_path[7] - 'a' + 1) * 26 + (mod_path[8] - 'a')) % 16)
 +* 16 + part;
 +retval = major * 256 + minor;
 +}
 +else if (disk_re_match(/dev/hd[a-t]([1-9]|[1-5][0-9]|6[0-3])?$,
 +   mod_path, part)) {
 +major = ide_majors[(mod_path[7] - 'a') / 2];
 +minor = ((mod_path[7] - 'a') % 2) * 64 + part;
 +retval = major * 256 + minor;
  }
 +else if (disk_re_match(/dev/xvd[a-p]([1-9]|1[0-5])?$, mod_path, part))
 +retval = (202  8) + ((mod_path[8] - 'a')  4) + part;
 +else if (disk_re_match(/dev/xvd[q-z]([1-9]|1[0-5])?$, mod_path, part))
 +retval = (1  28) + ((mod_path[8] - 'a')  8) + part;
 +else if (disk_re_match(/dev/xvd[a-i][a-z]([1-9]|1[0-5])?$,
 +   mod_path, part))
 +retval = (1  28) + (((mod_path[8] - 'a' + 1) * 26 + (mod_path[9] - 
 'a'))  8) + part;

To retain the diagnostic Dan mentioned, you should be able to
insert something like this just before the final else:

else if (disk_re_match(/dev/sd[a-z]([0-9])+$, mod_path, part)) {

 +else
 +statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
 +unsupported path, use xvdN, hdN, or sdN, domid);

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


Re: [libvirt] [PATCH]: Rework xenLinuxDomainDeviceID to support more devices

2008-08-05 Thread Chris Lalancette
Jim Meyering wrote:
 To retain the diagnostic Dan mentioned, you should be able to
 insert something like this just before the final else:
 
 else if (disk_re_match(/dev/sd[a-z]([0-9])+$, mod_path, part)) {
 
 +else
 +statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
 +unsupported path, use xvdN, hdN, or sdN, domid);

OK, another go, with all of Jim's concerns addressed.  I did something like this
last point (thanks for the idea Jim), except that I didn't use regex's but basic
STRPREFIX() to get better error messages.  Dan, is this better?

Chris Lalancette
Index: src/stats_linux.c
===
RCS file: /data/cvs/libvirt/src/stats_linux.c,v
retrieving revision 1.15
diff -u -r1.15 stats_linux.c
--- a/src/stats_linux.c	23 May 2008 08:24:44 -	1.15
+++ b/src/stats_linux.c	5 Aug 2008 13:42:11 -
@@ -18,6 +18,7 @@
 #include fcntl.h
 #include string.h
 #include unistd.h
+#include regex.h
 #include c-ctype.h
 
 #ifdef WITH_XEN
@@ -28,6 +29,7 @@
 #include util.h
 #include xen_unified.h
 #include stats_linux.h
+#include memory.h
 
 /**
  * statsErrorFunc:
@@ -224,132 +226,134 @@
 return 0;
 }
 
+static int
+disk_re_match(const char *regex, const char *path, int *part)
+{
+regex_t myreg;
+int err;
+int retval;
+regmatch_t pmatch[3];
+
+retval = 0;
+
+err = regcomp(myreg, regex, REG_EXTENDED);
+if (err != 0)
+return 0;
+
+err = regexec(myreg, path, 3, pmatch, 0);
+
+if (err == 0) {
+/* OK, we have a match; see if we have a partition */
+*part = 0;
+retval = 1;
+if (pmatch[1].rm_so != -1) {
+if (virStrToLong_i(path + pmatch[1].rm_so, NULL, 10, part)  0)
+retval = 0;
+}
+}
+
+regfree(myreg);
+
+return retval;
+}
+
 int
 xenLinuxDomainDeviceID(virConnectPtr conn, int domid, const char *path)
 {
-int disk, part = 0;
-
-/* Strip leading path if any */
-if (strlen(path)  5 
-STRPREFIX(path, /dev/))
-path += 5;
+int major, minor;
+int part;
+int retval;
+char *mod_path;
+
+int const scsi_majors[] = { SCSI_DISK0_MAJOR, SCSI_DISK1_MAJOR,
+SCSI_DISK2_MAJOR, SCSI_DISK3_MAJOR,
+SCSI_DISK4_MAJOR, SCSI_DISK5_MAJOR,
+SCSI_DISK6_MAJOR, SCSI_DISK7_MAJOR,
+SCSI_DISK8_MAJOR, SCSI_DISK9_MAJOR,
+SCSI_DISK10_MAJOR, SCSI_DISK11_MAJOR,
+SCSI_DISK12_MAJOR, SCSI_DISK13_MAJOR,
+SCSI_DISK14_MAJOR, SCSI_DISK15_MAJOR };
+int const ide_majors[] = { IDE0_MAJOR, IDE1_MAJOR, IDE2_MAJOR, IDE3_MAJOR,
+   IDE4_MAJOR, IDE5_MAJOR, IDE6_MAJOR, IDE7_MAJOR,
+   IDE8_MAJOR, IDE9_MAJOR };
 
 /*
  * Possible block device majors  partition ranges. This
  * matches the ranges supported in Xend xen/util/blkif.py
  *
- * hdNM:  N=a-t, M=1-63,  major={IDE0_MAJOR - IDE9_MAJOR}
- * sdNM:  N=a-z,aa-iv, M=1-15,  major={SCSI_DISK0_MAJOR - SCSI_DISK15_MAJOR}
- * xvdNM: N=a-p, M=1-15,  major=XENVBD_MAJOR
- *
- * NB, the SCSI major isn't technically correct, as XenD only knows
- * about major=8. We cope with all SCSI majors in anticipation of
- * XenD perhaps being fixed one day
+ * hdNM:  N=a-t, M=1-63, major={IDE0_MAJOR - IDE9_MAJOR}
+ * sdNM:  N=a-z,aa-iv, M=1-15, major={SCSI_DISK0_MAJOR - SCSI_DISK15_MAJOR}
+ * xvdNM: N=a-p M=1-15, major=XENVBD_MAJOR
+ * xvdNM: N=q-z,aa-iz M=1-15, major=(128)
  *
  * The path for statistics will be
  *
  * /sys/devices/xen-backend/(vbd|tap)-{domid}-{devid}/statistics/{...}
  */
 
-if (strlen (path) = 4 
-STRPREFIX (path, xvd)) {
-/* Xen paravirt device handling */
-disk = (path[3] - 'a');
-if (disk  0 || disk  15) {
-statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
-invalid path, device names must be in range xvda - xvdp,
-domid);
-return -1;
-}
-
-if (path[4] != '\0') {
-if (!c_isdigit(path[4]) || path[4] == '0' ||
-virStrToLong_i(path+4, NULL, 10, part)  0 ||
-part  1 || part  15) {
-statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
-invalid path, partition numbers for xvdN must be in range 1 - 15,
-domid);
-return -1;
-}
-}
-
-return (XENVBD_MAJOR * 256) + (disk * 16) + part;
-} else if (strlen (path) = 3 
-   STRPREFIX (path, sd)) {
-/* SCSI device handling */
-int majors[] = { SCSI_DISK0_MAJOR, SCSI_DISK1_MAJOR, SCSI_DISK2_MAJOR,
-

Re: [libvirt] [PATCH]: Rework xenLinuxDomainDeviceID to support more devices

2008-08-05 Thread Daniel P. Berrange
On Tue, Aug 05, 2008 at 03:45:40PM +0200, Chris Lalancette wrote:
 Jim Meyering wrote:
  To retain the diagnostic Dan mentioned, you should be able to
  insert something like this just before the final else:
  
  else if (disk_re_match(/dev/sd[a-z]([0-9])+$, mod_path, part)) {
  
  +else
  +statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
  +unsupported path, use xvdN, hdN, or sdN, domid);
 
 OK, another go, with all of Jim's concerns addressed.  I did something like 
 this
 last point (thanks for the idea Jim), except that I didn't use regex's but 
 basic
 STRPREFIX() to get better error messages.  Dan, is this better?

ACK, this gets my vote now.

Regards,
Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

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


Re: [libvirt] [PATCH]: Fix virsh attach-disk and virsh attach-interface

2008-08-05 Thread Daniel P. Berrange
On Tue, Aug 05, 2008 at 12:02:47PM +0200, Chris Lalancette wrote:
 With the recent refactoring of the domain code, plus the changes with the Xend
 code, a couple of bugs were introduced into the attach-disk and 
 attach-interface
 functionality.  This patch fixes 3 bugs:
 
 1)  In xenDaemonAttachDevice(), there is a switch statement to determine which
 of the xenDaemonFormatSxpr{Disk,Net} functions to call.  Unfortunately, the 
 case
 statements are all missing the corresponding break, so we always 
 fall-through
 to the default error case.  This patch just adds the appropriate break 
 statements.

ACK

 2)  (minor) In xenDaemonDomainDefineXML (that's a mouthful!), there is a stray
 fprintf.  This is now converted to a proper virXendError().

ACK

 3)  xenDaemonFormatSxpr{Disk,Net} were adding an extra (device to the front of
 the sexpr expressions that xend did not expect (this is Xend on RHEL 5.2).
 Because of this, the attaches would fail.  The patch fixes this by removing 
 the
 (device from the front, which makes attach-disk and attach-interface work 
 again.

This isn't entirely correct. The previous code was in fact inconsistent in this
area. Taking libvirt 0.4.4 as an example

  - xenDaemonAttachDevice  calls into
  - virParseXMLDevice  returns the SEXPR by calling into
  - virDomainParseXMLDiskDesc or virDomainParseXMLIfDesc

The DiskDesc method returns an SEXPR with a '(device ' prefix. THe IfDesc method
returns a SEXPR without a '(device ' prefix. I'm pretty sure I've used the disk
hotplug in RHEL5, which implies it does accept a (device prefix. I've never 
tried
network hotplug, so can't say whether that worked or not. In any case I think 
this
needs some more investigation of behaviour on Xen 3.0.3, vs  3.1.0 and 3.2.0 
before
we change the SEXPR again

Regards,
Daniel

 Index: src/xend_internal.c
 ===
 RCS file: /data/cvs/libvirt/src/xend_internal.c,v
 retrieving revision 1.207
 diff -u -r1.207 xend_internal.c
 --- a/src/xend_internal.c 4 Aug 2008 06:33:25 -   1.207
 +++ b/src/xend_internal.c 5 Aug 2008 09:59:57 -
 @@ -3900,6 +3900,7 @@
  STREQ(def-os.type, hvm) ? 1 : 0,
  priv-xendConfigVersion)  0)
  goto cleanup;
 +break;
  
  case VIR_DOMAIN_DEVICE_NET:
  if (xenDaemonFormatSxprNet(domain-conn,
 @@ -3908,6 +3909,7 @@
 STREQ(def-os.type, hvm) ? 1 : 0,
 priv-xendConfigVersion)  0)
  goto cleanup;
 +break;
  
  default:
  virXendError(domain-conn, VIR_ERR_NO_SUPPORT, %s,
 @@ -4292,7 +4294,8 @@
  ret = xend_op(conn, , op, new, config, sexpr, NULL);
  VIR_FREE(sexpr);
  if (ret != 0) {
 -fprintf(stderr, _(Failed to create inactive domain %s\n), name);
 +virXendError(conn, VIR_ERR_XEN_CALL,
 + _(Failed to create inactive domain %s\n), name);
  goto error;
  }
  
 @@ -5029,7 +5032,6 @@
  xendConfigVersion == 1)
  return 0;
  
 -virBufferAddLit(buf, (device );
  /* Normally disks are in a (device (vbd ...)) block
   * but blktap disks ended up in a differently named
   * (device (tap )) block */
 @@ -5083,7 +5085,7 @@
  else
  virBufferAddLit(buf, (mode 'w'));
  
 -virBufferAddLit(buf, )));
 +virBufferAddLit(buf, ));
  
  return 0;
  }
 @@ -5117,7 +5119,7 @@
  return -1;
  }
  
 -virBufferAddLit(buf, (device (vif );
 +virBufferAddLit(buf, (vif );
  
  virBufferVSprintf(buf,
(mac '%02x:%02x:%02x:%02x:%02x:%02x'),
 @@ -5177,7 +5179,7 @@
  if ((hvm)  (xendConfigVersion  4))
  virBufferAddLit(buf, (type ioemu));
  
 -virBufferAddLit(buf, )));
 +virBufferAddLit(buf, ));
  
  return 0;
  }

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


-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

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


[libvirt] PATCH: 0/7: Re-factor LXC driver

2008-08-05 Thread Daniel P. Berrange
This is a long overdue followup to my previous set of patches to make the
LXC driver use the new domain XML apis. Getting this merged is a blocker
for the new libvirt release, now we've turned on LXC by default. Likewise
we need to get OpenVZ fully ported to new XML before release too.

The previous posting was here:

  http://www.redhat.com/archives/libvir-list/2008-July/msg00182.html

Regards,
Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

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


Re: [libvirt] PATCH: 1/7: Removing state from lxc_vm_t

2008-08-05 Thread Daniel P. Berrange
This patch does some simple re-factoring of the way the TTYs and
control socket are handled to reduce the amount of state stored
in the lxc_vm_t structure, in preparation for the switchover to
the generic domain handling APIs.

 lxc_conf.c  |1 
 lxc_conf.h  |   12 ---
 lxc_container.c |   60 +++
 lxc_container.h |   14 +++
 lxc_driver.c|  213 
 5 files changed, 104 insertions(+), 196 deletions(-)

Daniel

diff -r 63b8398c302e src/lxc_conf.c
--- a/src/lxc_conf.cMon Jul 14 12:18:23 2008 +0100
+++ b/src/lxc_conf.cTue Jul 15 11:55:48 2008 +0100
@@ -1041,7 +1041,6 @@
 void lxcFreeVM(lxc_vm_t *vm)
 {
 lxcFreeVMDef(vm-def);
-VIR_FREE(vm-containerTty);
 VIR_FREE(vm);
 }
 
diff -r 63b8398c302e src/lxc_conf.h
--- a/src/lxc_conf.hMon Jul 14 12:18:23 2008 +0100
+++ b/src/lxc_conf.hTue Jul 15 11:55:48 2008 +0100
@@ -35,12 +35,6 @@
 #define LXC_MAX_XML_LENGTH 16384
 #define LXC_MAX_ERROR_LEN 1024
 #define LXC_DOMAIN_TYPE lxc
-#define LXC_PARENT_SOCKET 0
-#define LXC_CONTAINER_SOCKET 1
-
-/* messages between parent and container */
-typedef char lxc_message_t;
-#define LXC_CONTINUE_MSG 'c'
 
 /* types of networks for containers */
 enum lxc_net_type {
@@ -98,12 +92,6 @@
 char configFileBase[PATH_MAX];
 
 char ttyPidFile[PATH_MAX];
-
-int parentTty;
-int containerTtyFd;
-char *containerTty;
-
-int sockpair[2];
 
 lxc_vm_def_t *def;
 
diff -r 63b8398c302e src/lxc_container.c
--- a/src/lxc_container.c   Mon Jul 14 12:18:23 2008 +0100
+++ b/src/lxc_container.c   Tue Jul 15 11:55:48 2008 +0100
@@ -33,7 +33,6 @@
 #include unistd.h
 
 #include lxc_container.h
-#include lxc_conf.h
 #include util.h
 #include memory.h
 #include veth.h
@@ -83,10 +82,11 @@
  *
  * Returns 0 on success or -1 in case of error
  */
-static int lxcSetContainerStdio(const char *ttyName)
+static int lxcSetContainerStdio(const char *ttyPath)
 {
 int rc = -1;
 int ttyfd;
+int open_max, i;
 
 if (setsid()  0) {
 lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
@@ -94,10 +94,10 @@
 goto error_out;
 }
 
-ttyfd = open(ttyName, O_RDWR|O_NOCTTY);
+ttyfd = open(ttyPath, O_RDWR|O_NOCTTY);
 if (ttyfd  0) {
 lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _(open(%s) failed: %s), ttyName, strerror(errno));
+ _(open(%s) failed: %s), ttyPath, strerror(errno));
 goto error_out;
 }
 
@@ -107,7 +107,12 @@
 goto cleanup;
 }
 
-close(0); close(1); close(2);
+/* Just in case someone forget to set FD_CLOEXEC, explicitly
+ * close all FDs before executing the container */
+open_max = sysconf (_SC_OPEN_MAX);
+for (i = 0; i  open_max; i++)
+if (i != ttyfd)
+close(i);
 
 if (dup2(ttyfd, 0)  0) {
 lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
@@ -144,12 +149,11 @@
  *
  * Returns 0 on success or -1 in case of error
  */
-static int lxcExecWithTty(lxc_vm_t *vm)
+static int lxcExecWithTty(lxc_vm_def_t *vmDef, char *ttyPath)
 {
 int rc = -1;
-lxc_vm_def_t *vmDef = vm-def;
 
-if(lxcSetContainerStdio(vm-containerTty)  0) {
+if(lxcSetContainerStdio(ttyPath)  0) {
 goto exit_with_error;
 }
 
@@ -161,7 +165,7 @@
 
 /**
  * lxcWaitForContinue:
- * @vm: Pointer to vm structure
+ * @monitor: monitor FD from parent
  *
  * This function will wait for the container continue message from the
  * parent process.  It will send this message on the socket pair stored in
@@ -169,31 +173,23 @@
  *
  * Returns 0 on success or -1 in case of error
  */
-static int lxcWaitForContinue(lxc_vm_t *vm)
+static int lxcWaitForContinue(int monitor)
 {
-int rc = -1;
 lxc_message_t msg;
 int readLen;
 
-readLen = saferead(vm-sockpair[LXC_CONTAINER_SOCKET], msg, sizeof(msg));
-if (readLen != sizeof(msg)) {
+readLen = saferead(monitor, msg, sizeof(msg));
+if (readLen != sizeof(msg) ||
+msg != LXC_CONTINUE_MSG) {
 lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
  _(Failed to read the container continue message: %s),
  strerror(errno));
-goto error_out;
+return -1;
 }
 
 DEBUG0(Received container continue message);
 
-close(vm-sockpair[LXC_PARENT_SOCKET]);
-vm-sockpair[LXC_PARENT_SOCKET] = -1;
-close(vm-sockpair[LXC_CONTAINER_SOCKET]);
-vm-sockpair[LXC_CONTAINER_SOCKET] = -1;
-
-rc = 0;
-
-error_out:
-return rc;
+return 0;
 }
 
 /**
@@ -204,12 +200,12 @@
  *
  * Returns 0 on success or nonzero in case of error
  */
-static int lxcEnableInterfaces(const lxc_vm_t *vm)
+static int lxcEnableInterfaces(const lxc_vm_def_t *def)
 {
 int rc = 0;
 const lxc_net_def_t *net;
 
-for (net = vm-def-nets; net; net = net-next) {
+for (net = def-nets; net; net = net-next) {
 DEBUG(Enabling %s, net-containerVeth);
 rc =  

Re: [libvirt] PATCH: 2/7: Re-arrange methods acros LXC source files

2008-08-05 Thread Daniel P. Berrange
The lxc_driver.c file contains quite a large amount of code,
serving two reasonably well separated purposes. First there
is the direct implemntation of each of the libvirt driver
APIs. Second there is the code to spawn a container and a
controller for forwarding I/O to/from the PTYs. This patch
attempts to re-arrange the code across files to better reflect
the split in functionality. The general idea is thus:

 - lxc_driver.c: implementation of the libvirt driver APIs
 - lxc_container.c: code for creating containers
 - lxc_controller.c: code for managing an active container

So this entails the following re-arrangement:

 - All calls to clone() move into  lxc_container.c. In
   particular there is a lxcContainerAvailable() method
   to querying capabilities of current kernel, and the
   lxcContainerStart() method for actually starting a
   new container.

 - The I/O forwarding code moves into lxc_controller.c
   with a lxcControllerMain() function containing the
   epoll() event loop.

The container code previously would pass the 'init' string path
for the container's init program to /bin/sh for execution.
This is bad because it assumes /bin/sh exists in the container's
root, and more seriously does no escaping, so allows arbitrary
shell code to run. So this also switches to passing the 'init'
string directly to execve(). If we want to support passing args
to the container startup program, we need explicit representation
of the args in the XML, so we can safely pass them to execve()
via the argv[]  array.

Aside from that, this patch should have no functional change to
the way containers run.

 b/src/lxc_controller.c |  205 +
 b/src/lxc_controller.h |   33 
 src/Makefile.am|1 
 src/lxc_container.c|  220 +++
 src/lxc_container.h|   19 +-
 src/lxc_driver.c   |  345 ++---
 6 files changed, 434 insertions(+), 389 deletions(-)

Daniel

diff -r 6a666b5713b4 src/Makefile.am
--- a/src/Makefile.am   Tue Aug 05 16:50:40 2008 +0100
+++ b/src/Makefile.am   Tue Aug 05 16:50:43 2008 +0100
@@ -64,6 +64,7 @@
openvz_conf.c openvz_conf.h \
openvz_driver.c openvz_driver.h \
lxc_driver.c lxc_driver.h   \
+   lxc_controller.c lxc_controller.h   \
lxc_conf.c lxc_conf.h   \
lxc_container.c lxc_container.h \
veth.c veth.h   \
diff -r 6a666b5713b4 src/lxc_container.c
--- a/src/lxc_container.c   Tue Aug 05 16:50:40 2008 +0100
+++ b/src/lxc_container.c   Tue Aug 05 16:50:43 2008 +0100
@@ -30,6 +30,7 @@
 #include stdlib.h
 #include sys/ioctl.h
 #include sys/mount.h
+#include sys/wait.h
 #include unistd.h
 
 #include lxc_container.h
@@ -40,49 +41,69 @@
 #define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt, __VA_ARGS__)
 #define DEBUG0(msg) VIR_DEBUG(__FILE__, %s, msg)
 
+/*
+ * GLibc headers are behind the kernel, so we define these
+ * constants if they're not present already.
+ */
+
+#ifndef CLONE_NEWPID
+#define CLONE_NEWPID  0x2000
+#endif
+#ifndef CLONE_NEWUTS
+#define CLONE_NEWUTS  0x0400
+#endif
+#ifndef CLONE_NEWUSER
+#define CLONE_NEWUSER 0x1000
+#endif
+#ifndef CLONE_NEWIPC
+#define CLONE_NEWIPC  0x0800
+#endif
+#ifndef CLONE_NEWNET
+#define CLONE_NEWNET  0x4000 /* New network namespace */
+#endif
+
+/* messages between parent and container */
+typedef char lxc_message_t;
+#define LXC_CONTINUE_MSG 'c'
+
+typedef struct __lxc_child_argv lxc_child_argv_t;
+struct __lxc_child_argv {
+lxc_vm_def_t *config;
+int monitor;
+char *ttyPath;
+};
+
+
 /**
- * lxcExecContainerInit:
+ * lxcContainerExecInit:
  * @vmDef: Ptr to vm definition structure
  *
- * Exec the container init string.  The container init will replace then
+ * Exec the container init string. The container init will replace then
  * be running in the current process
  *
- * Returns 0 on success or -1 in case of error
+ * Does not return
  */
-static int lxcExecContainerInit(const lxc_vm_def_t *vmDef)
+static int lxcContainerExecInit(const lxc_vm_def_t *vmDef)
 {
-int rc = -1;
-char* execString;
-size_t execStringLen = strlen(vmDef-init) + 1 + 5;
+const char *const argv[] = {
+vmDef-init,
+NULL,
+};
 
-if (VIR_ALLOC_N(execString, execStringLen)  0) {
-lxcError(NULL, NULL, VIR_ERR_NO_MEMORY,
- _(failed to calloc memory for init string: %s),
- strerror(errno));
-goto error_out;
-}
-
-strcpy(execString, exec );
-strcat(execString, vmDef-init);
-
-execl(/bin/sh, sh, -c, execString, (char*)NULL);
-lxcError(NULL, NULL, VIR_ERR_NO_MEMORY,
- _(execl failed to exec init: %s), strerror(errno));
-
-error_out:
-exit(rc);
+return execve(argv[0], (char **)argv, NULL);
 

Re: [libvirt] PATCH: 3/7:

2008-08-05 Thread Daniel P. Berrange
Every LXC container has 2 processes, the leader of the actual container
and a helper process to do the I/O forwarding. The LXC driver is written
to allow libvirtd to be restarted without needing to shutdown the active
containers. For this it uses a PID file in /var/run/libvirt/lxc/NAME.pid
The driver also uses  SIGCHLD to detect when a container has terminated.

Here-in lies the problem - if you restart libvirtd, the container process
gets re-parented to init, and so libvirtd will never get any further
SIGCHLD signals for it.

This patch attempts to address this problem by changing the relationship
between libvirtd and the container processes. Instad of there being two
processes which are siblings, the I/O process becomes the parent of the
actual container.

So the general idea is:

  - libvirtd LXC driver spawns a 'controller' process - this immediately
double-forks itself into the background, making itself process leader,
changing its root directory to /, and redirecting its stdin to /dev/null
and its stdout/err to /var/log/libvirt/lxc/NAME.log.

  - The 'controller' process inherits a UNIX domain socket from libvirtd
which has had bind() called against /var/run/libvirt/lxc/NAME.sock

  - Once it has backgrounded itself, the controller calls accept() on
the socket, blocking until a client connects. If this fails for any
reason the controller exits.

  - THe 'controller' also writes a file to /var/run/libvirt/lxc/NAME.pid
containing its PID.

  - Immediately after forking the 'controller' process, the libvirtd LXC
driver, calls connect() on /var/run/libvirt/lxc/NAME.sock. And does
a blocking read of sizeof(pid_t)  bytes.

  - They now do a handshake, consisting of simply sending  receving
a single byte. This basically is to ensure the libvirt driver blocks
until the controller has finished writing its PID file

At this point in time, the libvirtd LXC driver knows what the controller
process' PID is. This becomes the 'ID' of the virDomain object associated
with this. If anything goes wrong from here-on, the libvirtd LXC driver
also now knows what PID it has to kill off. The UNIX socket to the controller
process is kept open, and registered with the libvirtd event loop for POLLHUP
events. This means the LXC driver can get notification when the controller
terminates, without needing to rely on SIGCHLD events.

  - Now the 'controller' has told libvirtd what its PID is, it goes ahead
and starts the real 'container' process.

  - When the 'container' is up and running, the controller goes into the
event loop where it handles I/O from the PTYs. It also keeps an eye
out for SIGHUP on the client socket to the libvirtd daemon.

  - If the client goes away, it'll know it needs to accept() a new client
(ie the libvirtd daemon starting up again). Upon a new client connecting
it'll do the PID handshake again, so that libvirtd knows what the container
ID is again.

  - When libvirtd starts up, it reads the container configs from 
/etc/libvirt/lxc
and for each one, tries to connect to /var/run/libvirt/lxc/NAME.sock, and
read the PID file. This lets it figure out which containers are running.

Notice that throughout this, libvirtd's LXC driver doesn't need to know the
PID of the actual container process - only that of the controller process.
Think of the controller as serving the equivalent role of QEMU in context of
KVM. QEMU provides the backend device model for KVM. When QEMU dies, the guest
domain goes away. Well the controller provides the 'backend' device model for
the container. - though in this case it really only the text console backend.
When the controller dies, the container goes away.

So architecturally the LXC driver is now very closely aligned with the QEMU
driver. The main differences are that LXC can handle libvirtd restarts, and
that the LXC driver simply forks() the controller. One could imagine these
distinctions going away - the QEMU driver can get a restart capability in
much the same way as the LXC restart works. We may want to make the controller
process a proper standalone binary which can be directly exec'd, rather than
just forked off from libvirtd.

 lxc_conf.c   |  195 
 lxc_conf.h   |   12 
 lxc_container.c  |   39 +--
 lxc_container.h  |8 
 lxc_controller.c |  349 +++-
 lxc_controller.h |   12 
 lxc_driver.c |  662 ++-
 util.c   |  158 +
 util.h   |   13 +
 9 files changed, 870 insertions(+), 578 deletions(-)


Daniel

diff -r 8093fb566748 src/lxc_conf.c
--- a/src/lxc_conf.cFri Aug 01 14:47:33 2008 +0100
+++ b/src/lxc_conf.cTue Aug 05 12:13:24 2008 +0100
@@ -833,25 +833,24 @@
 strncpy(vm-configFileBase, file, PATH_MAX);
 vm-configFile[PATH_MAX-1] = '\0';
 
-if (lxcLoadTtyPid(driver, vm)  0) {
-DEBUG0(failed to load tty pid);
-}
-
 return vm;
 }
 

Re: [libvirt] PATCH: 4/7: Convert LXC to new domain APIs

2008-08-05 Thread Daniel P. Berrange
The re-architecting of the LXC controller/container process relationship
in the previous patch removed the last obstacle to switching over to the
generic domain XML routines. So this patch switches the driver over.

First the vast majority of lxc_conf.h/c is simply deleted - this is all
redundant when using the domain_conf.h APIs. Then, all references to lxc_vm_t
are changed to virDomainObj, and lxc_vm_def_t switches to virDomainDef.
Finally the LXC driver registers its capabilities data. For this I have
chosen an OS type of 'exe', since the 'operating system' we're running
in the container is just any plain executable process.


 lxc_conf.c   | 1052 +--
 lxc_conf.h   |  121 --
 lxc_container.c  |   23 -
 lxc_container.h  |2 
 lxc_controller.c |4 
 lxc_controller.h |2 
 lxc_driver.c |  289 ---
 7 files changed, 215 insertions(+), 1278 deletions(-)

Daniel

diff -r 72ff3545be62 src/lxc_conf.c
--- a/src/lxc_conf.cTue Aug 05 16:50:44 2008 +0100
+++ b/src/lxc_conf.cTue Aug 05 16:50:49 2008 +0100
@@ -27,22 +27,8 @@
 
 #ifdef WITH_LXC
 
-#include dirent.h
-#include errno.h
-#include fcntl.h
-#include string.h
-#include unistd.h
+#include sys/utsname.h
 
-#include libxml/parser.h
-#include libxml/tree.h
-#include libxml/uri.h
-#include libxml/xpath.h
-
-#include buf.h
-#include util.h
-#include uuid.h
-#include xml.h
-#include memory.h
 #include lxc_conf.h
 
 /* debug macros */
@@ -54,12 +40,12 @@
   const char *fmt, ...)
 {
 va_list args;
-char errorMessage[LXC_MAX_ERROR_LEN];
+char errorMessage[1024];
 const char *codeErrorMessage;
 
 if (fmt) {
 va_start(args, fmt);
-vsnprintf(errorMessage, LXC_MAX_ERROR_LEN-1, fmt, args);
+vsnprintf(errorMessage, sizeof(errorMessage)-1, fmt, args);
 va_end(args);
 } else {
 errorMessage[0] = '\0';
@@ -71,769 +57,40 @@
 codeErrorMessage, errorMessage);
 }
 
-/**
- * lxcParseInterfaceXML:
- * @conn: pointer to connection
- * @nodePtr: pointer to xml node structure
- * @vm: pointer to net definition structure to fill in
- *
- * Parses the XML for a network interface and places the configuration
- * in the given structure.
- *
- * Returns 0 on success or -1 in case of error
- */
-static int lxcParseInterfaceXML(virConnectPtr conn, xmlNodePtr nodePtr,
-lxc_net_def_t *netDef)
+virCapsPtr lxcCapsInit(void)
 {
-int rc = -1;
-xmlNodePtr cur;
-xmlChar *type = NULL;
-xmlChar *parentIfName = NULL;
-xmlChar *network = NULL;
-xmlChar *bridge = NULL;
-xmlChar *macaddr = NULL;
+struct utsname utsname;
+virCapsPtr caps;
+virCapsGuestPtr guest;
 
-netDef-type = LXC_NET_NETWORK;
+uname(utsname);
 
-type = xmlGetProp(nodePtr, BAD_CAST type);
-if (type != NULL) {
-if (xmlStrEqual(type, BAD_CAST network)) {
-netDef-type = LXC_NET_NETWORK;
-}
-else if (xmlStrEqual(type, BAD_CAST bridge)) {
-netDef-type = LXC_NET_BRIDGE;
-}
-else {
-lxcError(conn, NULL, VIR_ERR_XML_ERROR,
- _(invalid interface type: %s), type);
-goto error_out;
-}
-}
+if ((caps = virCapabilitiesNew(utsname.machine,
+   0, 0)) == NULL)
+goto no_memory;
 
-cur = nodePtr-children;
-for (cur = nodePtr-children; cur != NULL; cur = cur-next) {
-if (cur-type == XML_ELEMENT_NODE) {
-DEBUG(cur-name: %s, (char*)(cur-name));
-if ((macaddr == NULL) 
-(xmlStrEqual(cur-name, BAD_CAST mac))) {
-macaddr = xmlGetProp(cur, BAD_CAST address);
-} else if ((network == NULL) 
-   (netDef-type == LXC_NET_NETWORK) 
-   (xmlStrEqual(cur-name, BAD_CAST source))) {
-network = xmlGetProp(cur, BAD_CAST network);
-parentIfName = xmlGetProp(cur, BAD_CAST dev);
-} else if ((bridge == NULL) 
-   (netDef-type == LXC_NET_BRIDGE) 
-   (xmlStrEqual(cur-name, BAD_CAST source))) {
-bridge = xmlGetProp(cur, BAD_CAST bridge);
-} else if ((parentIfName == NULL) 
-   (xmlStrEqual(cur-name, BAD_CAST target))) {
-parentIfName = xmlGetProp(cur, BAD_CAST dev);
-}
-}
-}
+if ((guest = virCapabilitiesAddGuest(caps,
+ exe,
+ utsname.machine,
+ sizeof(int) == 4 ? 32 : 8,
+ NULL,
+ NULL,
+ 0,
+ NULL)) == NULL)
+goto no_memory;
 
-if (netDef-type == 

Re: [libvirt] PATCH: 5/7: Remove paths from virDomainObjPtr

2008-08-05 Thread Daniel P. Berrange
This patch removes the configDir and autostartLink paths from the internal
virDomainObjPtr struct. Instead they can calculated at time of use. This
is to facilitate a following patch, where we want to write a config to an
alternative location at some points. This also makes the LXC  QEMU drivers
correctly set/use the 'persistent' property.

 domain_conf.c |   99 +-
 domain_conf.h |8 +---
 lxc_driver.c  |   40 ++-
 qemu_driver.c |   71 ++---
 4 files changed, 138 insertions(+), 80 deletions(-)

Daniel

diff -r a204a9425afd src/domain_conf.c
--- a/src/domain_conf.c Tue Aug 05 16:50:49 2008 +0100
+++ b/src/domain_conf.c Tue Aug 05 16:50:51 2008 +0100
@@ -399,8 +399,6 @@
 virDomainDefFree(dom-newDef);
 
 VIR_FREE(dom-vcpupids);
-VIR_FREE(dom-configFile);
-VIR_FREE(dom-autostartLink);
 
 VIR_FREE(dom);
 }
@@ -2952,31 +2950,23 @@
 
 int virDomainSaveConfig(virConnectPtr conn,
 const char *configDir,
-const char *autostartDir,
-virDomainObjPtr dom)
+virDomainDefPtr def)
 {
 char *xml;
+char *configFile = NULL;
 int fd = -1, ret = -1;
 size_t towrite;
 int err;
 
-if (!dom-configFile 
-asprintf(dom-configFile, %s/%s.xml,
- configDir, dom-def-name)  0) {
-dom-configFile = NULL;
-virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL);
-goto cleanup;
-}
-if (!dom-autostartLink 
-asprintf(dom-autostartLink, %s/%s.xml,
- autostartDir, dom-def-name)  0) {
-dom-autostartLink = NULL;
+if (asprintf(configFile, %s/%s.xml,
+ configDir, def-name)  0) {
+configFile = NULL;
 virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL);
 goto cleanup;
 }
 
 if (!(xml = virDomainDefFormat(conn,
-   dom-newDef ? dom-newDef : dom-def,
+   def,
VIR_DOMAIN_XML_SECURE)))
 goto cleanup;
 
@@ -2987,34 +2977,27 @@
 goto cleanup;
 }
 
-if ((err = virFileMakePath(autostartDir))) {
-virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _(cannot create autostart directory %s: %s),
- autostartDir, strerror(err));
-goto cleanup;
-}
-
-if ((fd = open(dom-configFile,
+if ((fd = open(configFile,
O_WRONLY | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR ))  0) {
 virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
-  _(cannot create config file %s: %s),
-  dom-configFile, strerror(errno));
+ _(cannot create config file %s: %s),
+ configFile, strerror(errno));
 goto cleanup;
 }
 
 towrite = strlen(xml);
 if (safewrite(fd, xml, towrite)  0) {
 virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
-  _(cannot write config file %s: %s),
-  dom-configFile, strerror(errno));
+ _(cannot write config file %s: %s),
+ configFile, strerror(errno));
 goto cleanup;
 }
 
 if (close(fd)  0) {
 virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
-  _(cannot save config file %s: %s),
-  dom-configFile, strerror(errno));
+ _(cannot save config file %s: %s),
+ configFile, strerror(errno));
 goto cleanup;
 }
 
@@ -3072,8 +3055,6 @@
 goto error;
 
 dom-state = VIR_DOMAIN_SHUTOFF;
-dom-configFile = configFile;
-dom-autostartLink = autostartLink;
 dom-autostart = autostart;
 
 return dom;
@@ -3104,6 +3085,8 @@
 }
 
 while ((entry = readdir(dir))) {
+virDomainObjPtr dom;
+
 if (entry-d_name[0] == '.')
 continue;
 
@@ -3112,12 +3095,14 @@
 
 /* NB: ignoring errors, so one malformed config doesn't
kill the whole process */
-virDomainLoadConfig(conn,
-caps,
-doms,
-configDir,
-autostartDir,
-entry-d_name);
+dom = virDomainLoadConfig(conn,
+  caps,
+  doms,
+  configDir,
+  autostartDir,
+  entry-d_name);
+if (dom)
+dom-persistent = 1;
 }
 
 closedir(dir);
@@ -3126,25 +3111,43 @@
 }
 
 int virDomainDeleteConfig(virConnectPtr conn,
-   

Re: [libvirt] PATCH: 6/7: Persist live domain config across restarts

2008-08-05 Thread Daniel P. Berrange
Internally the drivers track the current live configuration, and the new
inactive config for running domains. When the libvirtd process is restarted
though, this data is lost for any active LXC domains. This patch makes the
LXC driver persist the live config to /var/run/libvirt/lxc/NAME.xml so it
can be tracked across restarts

It required a small change to the domain XML APis to make the autostart
symlink processing optional when deleting a config file

 domain_conf.c |   24 
 lxc_driver.c  |   27 +++
 2 files changed, 39 insertions(+), 12 deletions(-)


Daniel

diff -r cf1cf3a1d4d6 src/domain_conf.c
--- a/src/domain_conf.c Tue Aug 05 16:50:51 2008 +0100
+++ b/src/domain_conf.c Tue Aug 05 16:50:59 2008 +0100
@@ -1087,13 +1087,11 @@
 break;
 
 case VIR_DOMAIN_CHR_TYPE_PTY:
-/* @path attribute is an output only property - pty is auto-allocted */
-break;
-
 case VIR_DOMAIN_CHR_TYPE_DEV:
 case VIR_DOMAIN_CHR_TYPE_FILE:
 case VIR_DOMAIN_CHR_TYPE_PIPE:
-if (path == NULL) {
+if (path == NULL 
+def-type != VIR_DOMAIN_CHR_TYPE_PTY) {
 virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
  %s, _(Missing source path attribute for 
char device));
 goto error;
@@ -3124,15 +3122,17 @@
 virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL);
 goto cleanup;
 }
-if (asprintf(autostartLink, %s/%s,
- autostartDir, dom-def-name)  0) {
-autostartLink = NULL;
-virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL);
-goto cleanup;
+if (autostartDir) {
+if (asprintf(autostartLink, %s/%s,
+ autostartDir, dom-def-name)  0) {
+autostartLink = NULL;
+virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL);
+goto cleanup;
+}
+
+/* Not fatal if this doesn't work */
+unlink(autostartLink);
 }
-
-/* Not fatal if this doesn't work */
-unlink(autostartLink);
 
 if (unlink(configFile)  0 
 errno != ENOENT) {
diff -r cf1cf3a1d4d6 src/lxc_driver.c
--- a/src/lxc_driver.c  Tue Aug 05 16:50:51 2008 +0100
+++ b/src/lxc_driver.c  Tue Aug 05 16:50:59 2008 +0100
@@ -399,6 +399,7 @@
 close(vm-monitor);
 
 virFileDeletePid(driver-stateDir, vm-def-name);
+virDomainDeleteConfig(conn, driver-stateDir, NULL, vm);
 
 vm-state = VIR_DOMAIN_SHUTOFF;
 vm-pid = -1;
@@ -615,6 +616,12 @@
 if (signum == 0)
 signum = SIGINT;
 
+if (vm-pid = 0) {
+lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
+ _(invalid PID %d for container), vm-pid);
+return -1;
+}
+
 if (kill(vm-pid, signum)  0) {
 if (errno != ESRCH) {
 lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
@@ -741,6 +748,12 @@
 lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
  _(Failed to read pid file %s/%s.pid: %s),
  driver-stateDir, vm-def-name, strerror(errno));
+rc = -1;
+goto cleanup;
+}
+
+/* Persist the live configuration */
+if (virDomainSaveConfig(conn, driver-stateDir, vm-def)  0) {
 rc = -1;
 goto cleanup;
 }
@@ -960,6 +973,8 @@
 
 vm = lxc_driver-domains;
 while (vm) {
+char *config = NULL;
+virDomainDefPtr tmp;
 int rc;
 if ((vm-monitor = lxcMonitorClient(NULL, lxc_driver, vm))  0) {
 vm = vm-next;
@@ -972,6 +987,18 @@
 vm-monitor = -1;
 vm = vm-next;
 continue;
+}
+
+if (asprintf(config, %s/%s.xml,
+ lxc_driver-stateDir, vm-def-name)  0)
+continue;
+
+/* Try and load the live config */
+tmp = virDomainDefParseFile(NULL, lxc_driver-caps, config);
+VIR_FREE(config);
+if (tmp) {
+vm-newDef = vm-def;
+vm-def = tmp;
 }
 
 if (vm-pid != 0) {

-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

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


Re: [libvirt] PATCH: 7/7: Allow replacing root filesystem

2008-08-05 Thread Daniel P. Berrange
The LXC driver currently allows custom mount points to be setup inside the
container. This only works for non-root mount points. You cannot replace 
the entire root filesystem. This patch adds support for replacing the entire
root filesystem, thus allowing the use of LXC containers as a 'better chroot
than chroot'. Well, with one minor flaw - the Linux kernel currently has no
device namespace virtualization, so the admin inside the container can just
do a 'mknod' and access the real devices of the host. So for now this patch
doesn't make LXC containers secure, but a future kernel release will enable
it to be secure.

 lxc_container.c |  253 
 util.c  |   12 +-
 2 files changed, 226 insertions(+), 39 deletions(-)

Daniel

diff -r eaa42985aed4 src/lxc_container.c
--- a/src/lxc_container.c   Tue Aug 05 16:50:59 2008 +0100
+++ b/src/lxc_container.c   Tue Aug 05 16:51:14 2008 +0100
@@ -1,10 +1,12 @@
 /*
  * Copyright IBM Corp. 2008
+ * Copyright Red Hat 2008
  *
  * lxc_container.c: file description
  *
  * Authors:
  *  David L. Leskovec dlesko at linux.vnet.ibm.com
+ *  Daniel P. Berrange [EMAIL PROTECTED]
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -28,10 +30,18 @@
 #include fcntl.h
 #include limits.h
 #include stdlib.h
+#include stdio.h
 #include sys/ioctl.h
 #include sys/mount.h
 #include sys/wait.h
 #include unistd.h
+#include mntent.h
+
+/* Yes, we want linux private one, for _syscall2() macro */
+#include linux/unistd.h
+
+/* For MS_MOVE */
+#include linux/fs.h
 
 #include lxc_container.h
 #include util.h
@@ -105,23 +115,15 @@
  *
  * Returns 0 on success or -1 in case of error
  */
-static int lxcContainerSetStdio(int control, const char *ttyPath)
+static int lxcContainerSetStdio(int control, int ttyfd)
 {
 int rc = -1;
-int ttyfd;
 int open_max, i;
 
 if (setsid()  0) {
 lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
  _(setsid failed: %s), strerror(errno));
-goto error_out;
-}
-
-ttyfd = open(ttyPath, O_RDWR|O_NOCTTY);
-if (ttyfd  0) {
-lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
- _(open(%s) failed: %s), ttyPath, strerror(errno));
-goto error_out;
+goto cleanup;
 }
 
 if (ioctl(ttyfd, TIOCSCTTY, NULL)  0) {
@@ -159,8 +161,6 @@
 
 cleanup:
 close(ttyfd);
-
-error_out:
 return rc;
 }
 
@@ -223,6 +223,7 @@
 return 0;
 }
 
+
 /**
  * lxcEnableInterfaces:
  * @vm: Pointer to vm structure
@@ -252,6 +253,20 @@
 return rc;
 }
 
+
+//_syscall2(int, pivot_root, char *, newroot, const char *, oldroot)
+extern int pivot_root(const char * new_root,const char * put_old);
+
+static int lxcContainerChildMountSort(const void *a, const void *b)
+{
+  const char **sa = (const char**)a;
+  const char **sb = (const char**)b;
+
+  /* Delibrately reversed args - we need to unmount deepest
+ children first */
+  return strcmp(*sb, *sa);
+}
+
 /**
  * lxcChild:
  * @argv: Pointer to container arguments
@@ -269,8 +284,8 @@
 int rc = -1;
 lxc_child_argv_t *argv = data;
 virDomainDefPtr vmDef = argv-config;
-virDomainFSDefPtr curMount;
-int i;
+virDomainFSDefPtr tmp, root = NULL;
+int ttyfd, i;
 
 if (NULL == vmDef) {
 lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
@@ -278,36 +293,210 @@
 return -1;
 }
 
+#if 0
+ttyfd = open(argv-ttyPath, O_RDWR|O_NOCTTY);
+if (ttyfd  0) {
+lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ _(open(%s) failed: %s), argv-ttyPath, strerror(errno));
+return -1;
+}
+#endif
+
 /* handle the bind mounts first before doing anything else that may */
 /* then access those mounted dirs */
-curMount = vmDef-fss;
-for (i = 0; curMount; curMount = curMount-next) {
-// XXX fix
-if (curMount-type != VIR_DOMAIN_FS_TYPE_MOUNT)
+for (tmp = vmDef-fss; tmp  !root; tmp = tmp-next) {
+if (tmp-type != VIR_DOMAIN_FS_TYPE_MOUNT)
 continue;
-rc = mount(curMount-src,
-   curMount-dst,
-   NULL,
-   MS_BIND,
-   NULL);
-if (0 != rc) {
+if (STREQ(tmp-dst, /))
+root = tmp;
+}
+
+if (root) {
+char *oldroot;
+struct mntent *mntent;
+char **mounts = NULL;
+int nmounts = 0;
+FILE *procmnt;
+struct {
+int maj;
+int min;
+const char *path;
+} devs[] = {
+{ 1, 3, /dev/null },
+{ 1, 5, /dev/zero },
+{ 1, 7, /dev/full },
+{ 5, 1, /dev/console },
+};
+
+/* Got a FS mapped to /, we're going the pivot_root
+   approach to do a better-chroot-than-chroot */
+
+/* this is based on this thread http://lkml.org/lkml/2008/3/5/29 */
+
+

Re: [libvirt] [PATCH]: Rework xenLinuxDomainDeviceID to support more devices

2008-08-05 Thread Chris Lalancette
Chris Lalancette wrote:
 Jim Meyering wrote:
 To retain the diagnostic Dan mentioned, you should be able to
 insert something like this just before the final else:

 else if (disk_re_match(/dev/sd[a-z]([0-9])+$, mod_path, part)) {

 +else
 +statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
 +unsupported path, use xvdN, hdN, or sdN, domid);
 
 OK, another go, with all of Jim's concerns addressed.  I did something like 
 this
 last point (thanks for the idea Jim), except that I didn't use regex's but 
 basic
 STRPREFIX() to get better error messages.  Dan, is this better?

Committed this version.

Chris Lalancette

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


Re: [libvirt] [PATCH]: Fix virsh attach-disk and virsh attach-interface

2008-08-05 Thread Chris Lalancette
Daniel P. Berrange wrote:
 
 Ok, I've found the original xenDaemonAttachDevice() had this hack to make
 them consistent:
 
 if (!memcmp(sexpr, (device , 8)) {
 conf = sexpr + 8;
 *(conf + strlen(conf) -1) = 0; /* suppress final ) */
 }
 else
 conf = sexpr;
 
 Which is just gross. 

Ah, ug, that is gross.  Thanks for checking it out for me; I've committed this
patch now.

Chris Lalancette

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


Re: [libvirt] PATCH: 0/7: Re-factor LXC driver

2008-08-05 Thread Daniel P. Berrange
On Tue, Aug 05, 2008 at 09:04:34PM +0400, Evgeniy V. Sokolov wrote:
 
 This is a long overdue followup to my previous set of patches to make the
 LXC driver use the new domain XML apis. Getting this merged is a blocker
 for the new libvirt release, now we've turned on LXC by default. Likewise
 we need to get OpenVZ fully ported to new XML before release too.
 Daniel, do you plan to finish port of OpenVZ ? or I will do it.

I'm happy todo the work to at least port the code, but I don't have a 
OpenVZ enabled machine, so would neeed someone else to actually test
if its works :-)  Ideally I think we should aim todo a release next
week, so I'll look at whatever the state of the OpenVZ code is this
coming weekend, and work from that.

Regards,
Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

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


Re: [libvirt] PATCH: 0/7: Re-factor LXC driver

2008-08-05 Thread Evgeniy Sokolov



On Tue, Aug 05, 2008 at 09:04:34PM +0400, Evgeniy V. Sokolov wrote:

This is a long overdue followup to my previous set of patches to make the
LXC driver use the new domain XML apis. Getting this merged is a blocker
for the new libvirt release, now we've turned on LXC by default. Likewise
we need to get OpenVZ fully ported to new XML before release too.

Daniel, do you plan to finish port of OpenVZ ? or I will do it.


I'm happy todo the work to at least port the code, but I don't have a 
OpenVZ enabled machine, so would neeed someone else to actually test

if its works :-)  Ideally I think we should aim todo a release next
week, so I'll look at whatever the state of the OpenVZ code is this
coming weekend, and work from that.

Ok. I will be glad to help you with testing and other questions.


Regards,
Daniel


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


Re: [libvirt] PATCH: 0/7: Re-factor LXC driver

2008-08-05 Thread Dan Smith
DB This is a long overdue followup to my previous set of patches to
DB make the LXC driver use the new domain XML apis.

Have you been able to test this with NET_NS support enabled yet?

I am hitting the same issue I was before.  On starting an LXC domain
with a network interface, the daemon finishes the action and reports
a good status to virsh.  The domain fails to start, with the following
in the per-domain log file:

  DEBUG: lxc_container.c: lxcContainerStart (clone() returned, 8082)
  libvir: Linux Container error : internal error read of fd 6 failed: 
Input/output error 
  DEBUG: veth.c: vethDelete (veth: veth2)

However, now, the daemon crashes well after leaving the LXC driver's
domain startup process.  From the timing, I'd guess it's in some event
(or SIGCHLD) handler, but I can't reproduce it in gdb to get more
information.

This looks to be identical in root cause to what I was seeing with the
previous set of patches, and was unable to figure out why file
descriptor 6 was getting prematurely closed.  I'll get started on
debugging it again tomorrow, but it might be good if you can reproduce
it as well :)

-- 
Dan Smith
IBM Linux Technology Center
Open Hypervisor Team
email: [EMAIL PROTECTED]


pgpBRrWujhOF2.pgp
Description: PGP signature
--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] fix MinGW compilation(200808)

2008-08-05 Thread Atsushi SAKAI
Hi, Rich

I think possible.
But It needs time
I will consider it.

Thanks
Atsushi SAKAI

Richard W.M. Jones [EMAIL PROTECTED] wrote:

 On Tue, Aug 05, 2008 at 04:24:08PM +0900, Atsushi SAKAI wrote:
   src/virsh.c  |8 
 
 Is it possible to get edit working on Windows?  My MinGW system has a
 program which looks like 'vi' ...
 
 Rich.
 
 -- 
 Richard Jones, Emerging Technologies, Red Hat  http://et.redhat.com/~rjones
 virt-top is 'top' for virtual machines.  Tiny program with many
 powerful monitoring features, net stats, disk stats, logging, etc.
 http://et.redhat.com/~rjones/virt-top


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


Re: [libvirt] [PATCH] fix MinGW compilation(200808)

2008-08-05 Thread Atsushi SAKAI
Hi, Jim

Thank you for commenting this.
I am wondered how to replace inet_aton.
Your suggestion is very helpful.

Thanks
Atsushi SAKAI

Jim Meyering [EMAIL PROTECTED] wrote:

 Atsushi SAKAI [EMAIL PROTECTED] wrote:
 ...
  network_conf.c:290: warning: implicit declaration of function `inet_aton'
  network_conf.c:290: warning: nested extern declaration of `inet_aton'
 
 We can/should use inet_pton instead.  Then, not only do we use what seems
 to be the preferred interface, but there is a gnulib module by the same
 name that can come into play if it too is missing.
 
  network_conf.c:598: error: `S_IRUSR' undeclared (first use in this function)
 
 The remaining problems should be easy to resolve:
 Add this line to network_conf.c:
 
 #include sys/stat.h
 
  network_conf.c:598: error: (Each undeclared identifier is reported only once
  network_conf.c:598: error: for each function it appears in.)
  network_conf.c:598: error: `S_IWUSR' undeclared (first use in this function)


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