[libvirt] PATCH: Latest MinGW patches

Daniel P. Berrange berrange at redhat.com
Wed Sep 3 12:35:27 UTC 2008


I've got a MinGW build environment setup on Fedora 10 now, so just checked
out what the latest state of libvirt CVS is.

With the attached patch, I can run configure with:

  ./configure  \
      --build=i686-pc-linux-gnu \
      --host=i686-pc-mingw32 \
      --prefix=/usr/i686-pc-mingw32/sys-root/mingw \
      --without-libvirtd \
      --without-xen \
      --without-qemu \
      --without-sasl \
      --without-lxc \
      --without-openvz \
      --without-python

So, basically only the 'test' and 'remote' drivers are turned on. And do
a build which produces a libvirt-0.dll and a virsh.exe which is I can 
run under Wine successfully.

The changes:

 - The src/Makefile.am was conditionally turning off individual storage
   driver backends, based on the WITH_LIBVIRTD conditional. THis gave
   confusing diagnositics, since the configure summary said they were
   turned on.

   So, now configure itself turns off the storage drivers if libvirtd
   is disabled.

 - The storage_backend.c file is used by storage_Conf.c, so we need
   to compile this even if all storage backends are disabled. So we
   tweak src/Makefile.am to achieve this, and add a few more bits of
   conditional logic inside storage_backend.c to cope with the base
   directory pool driver not being available.

 - Mingw is missing regex.h and sys/wait.h, which are used in the 
   generic storage_backend.c file. We check for those in configure
   and conditionalize their inclusion. Furthermore we disable the
   virStorageBackendRunProgRegex and virStorageBackendRunProgNul
   functions on Windows, since they're not required and not compilable
   without regex.h / sys/wait.h

 - Mingw is mising getuid() and getgid() which are used in the storage_conf
   XML parser. We check for and optionally disable them and initialize 
   uid/gid to 0 if missing.

 - The virExec() stub routine for Mingw didn't have its signature updated
   when i did the recent virExe changes. THis fixes that.

 configure.in            |   18 +++++++++++++---
 qemud/remote_protocol.c |    1 
 qemud/remote_protocol.h |    1 
 qemud/remote_protocol.x |    1 
 src/Makefile.am         |    6 ++---
 src/storage_backend.c   |   53 +++++++++++++++++++++++++++++++++++++++++++-----
 src/storage_conf.c      |   22 +++++++++++++++++--
 src/util.c              |   17 +++------------
 8 files changed, 92 insertions(+), 27 deletions(-)

Daniel

diff -r 74dd97c354cc configure.in
--- a/configure.in	Tue Sep 02 10:49:53 2008 -0400
+++ b/configure.in	Wed Sep 03 08:24:04 2008 -0400
@@ -65,10 +65,10 @@
 AC_SYS_LARGEFILE
 
 dnl Availability of various common functions (non-fatal if missing).
-AC_CHECK_FUNCS([cfmakeraw regexec uname sched_getaffinity])
+AC_CHECK_FUNCS([cfmakeraw regexec uname sched_getaffinity getuid getgid])
 
 dnl Availability of various common headers (non-fatal if missing).
-AC_CHECK_HEADERS([pwd.h paths.h sys/syslimits.h sys/utsname.h sys/wait.h winsock2.h sched.h termios.h])
+AC_CHECK_HEADERS([pwd.h paths.h regex.h sys/syslimits.h sys/utsname.h sys/wait.h winsock2.h sched.h termios.h])
 
 dnl Where are the XDR functions?
 dnl If portablexdr is installed, prefer that.
@@ -648,6 +648,18 @@
 [  --with-storage-iscsi        with iSCSI backend for the storage driver (on)],[],[with_storage_iscsi=check])
 AC_ARG_WITH([storage-disk],
 [  --with-storage-disk         with GPartd Disk backend for the storage driver (on)],[],[with_storage_disk=check])
+
+with_storage_dir=yes
+if test "$with_libvirtd" = "no"; then
+  with_storage_dir=no
+  with_storage_fs=no
+  with_storage_lvm=no
+  with_storage_iscsi=no
+  with_storage_disk=no
+fi
+
+AM_CONDITIONAL([WITH_STORAGE_DIR], [test "$with_storage_dir" = "yes"])
+
 
 if test "$with_storage_fs" = "yes" -o "$with_storage_fs" = "check"; then
   AC_PATH_PROG([MOUNT], [mount], [], [$PATH:/sbin:/usr/sbin])
@@ -1053,7 +1065,7 @@
 AC_MSG_NOTICE([])
 AC_MSG_NOTICE([Storage Drivers])
 AC_MSG_NOTICE([])
-AC_MSG_NOTICE([     Dir: yes])
+AC_MSG_NOTICE([     Dir: $with_storage_dir])
 AC_MSG_NOTICE([      FS: $with_storage_fs])
 AC_MSG_NOTICE([   NetFS: $with_storage_fs])
 AC_MSG_NOTICE([     LVM: $with_storage_lvm])
diff -r 74dd97c354cc qemud/remote_protocol.c
--- a/qemud/remote_protocol.c	Tue Sep 02 10:49:53 2008 -0400
+++ b/qemud/remote_protocol.c	Wed Sep 03 08:24:04 2008 -0400
@@ -6,6 +6,7 @@
 #include "remote_protocol.h"
 #include <config.h>
 #include "internal.h"
+#include "socketcompat.h"
 
 bool_t
 xdr_remote_nonnull_string (XDR *xdrs, remote_nonnull_string *objp)
diff -r 74dd97c354cc qemud/remote_protocol.h
--- a/qemud/remote_protocol.h	Tue Sep 02 10:49:53 2008 -0400
+++ b/qemud/remote_protocol.h	Wed Sep 03 08:24:04 2008 -0400
@@ -15,6 +15,7 @@
 
 #include <config.h>
 #include "internal.h"
+#include "socketcompat.h"
 #define REMOTE_MESSAGE_MAX 262144
 #define REMOTE_STRING_MAX 65536
 
diff -r 74dd97c354cc qemud/remote_protocol.x
--- a/qemud/remote_protocol.x	Tue Sep 02 10:49:53 2008 -0400
+++ b/qemud/remote_protocol.x	Wed Sep 03 08:24:04 2008 -0400
@@ -38,6 +38,7 @@
 
 %#include <config.h>
 %#include "internal.h"
+%#include "socketcompat.h"
 
 /*----- Data types. -----*/
 
diff -r 74dd97c354cc src/Makefile.am
--- a/src/Makefile.am	Tue Sep 02 10:49:53 2008 -0400
+++ b/src/Makefile.am	Wed Sep 03 08:24:04 2008 -0400
@@ -58,7 +58,8 @@
 
 # Storage driver generic impl APIs
 STORAGE_CONF_SOURCES =						\
-		storage_conf.h storage_conf.c
+		storage_conf.h storage_conf.c			\
+		storage_backend.h storage_backend.c
 
 
 # The remote RPC driver, covering domains, storage, networks, etc
@@ -109,8 +110,7 @@
 
 # And finally storage backend specific impls
 STORAGE_DRIVER_SOURCES =					\
-		storage_driver.h storage_driver.c		\
-		storage_backend.h storage_backend.c
+		storage_driver.h storage_driver.c
 
 STORAGE_DRIVER_FS_SOURCES =					\
 		storage_backend_fs.h storage_backend_fs.c
diff -r 74dd97c354cc src/storage_backend.c
--- a/src/storage_backend.c	Tue Sep 02 10:49:53 2008 -0400
+++ b/src/storage_backend.c	Wed Sep 03 08:24:04 2008 -0400
@@ -24,9 +24,13 @@
 #include <config.h>
 
 #include <string.h>
+#if HAVE_REGEX_H
 #include <regex.h>
+#endif
 #include <sys/types.h>
+#if HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif
 #include <unistd.h>
 #include <fcntl.h>
 #include <stdint.h>
@@ -38,6 +42,10 @@
 #endif
 
 #include "internal.h"
+#include "util.h"
+#include "memory.h"
+
+#include "storage_backend.h"
 
 #if WITH_STORAGE_LVM
 #include "storage_backend_logical.h"
@@ -48,15 +56,14 @@
 #if WITH_STORAGE_DISK
 #include "storage_backend_disk.h"
 #endif
-
-#include "util.h"
-#include "memory.h"
-
-#include "storage_backend.h"
+#if WITH_STORAGE_DIR
 #include "storage_backend_fs.h"
+#endif
 
 static virStorageBackendPtr backends[] = {
+#if WITH_STORAGE_DIR
     &virStorageBackendDirectory,
+#endif
 #if WITH_STORAGE_FS
     &virStorageBackendFileSystem,
     &virStorageBackendNetFileSystem,
@@ -209,8 +216,12 @@
         return -2;
 
     if (S_ISREG(sb.st_mode)) {
+#ifndef __MINGW32__
         vol->allocation = (unsigned long long)sb.st_blocks *
             (unsigned long long)sb.st_blksize;
+#else
+        vol->allocation = sb.st_size;
+#endif
         /* Regular files may be sparse, so logical size (capacity) is not same
          * as actual allocation above
          */
@@ -337,6 +348,8 @@
     return devpath;
 }
 
+
+#ifndef __MINGW32__
 /*
  * Run an external program.
  *
@@ -620,3 +633,33 @@
 
     return 0;
 }
+
+#else
+
+int
+virStorageBackendRunProgRegex(virConnectPtr conn,
+                              virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
+                              const char *const*prog ATTRIBUTE_UNUSED,
+                              int nregex ATTRIBUTE_UNUSED,
+                              const char **regex ATTRIBUTE_UNUSED,
+                              int *nvars ATTRIBUTE_UNUSED,
+                              virStorageBackendListVolRegexFunc func ATTRIBUTE_UNUSED,
+                              void *data ATTRIBUTE_UNUSED,
+                              int *outexit ATTRIBUTE_UNUSED)
+{
+    virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s no implemented on Win32", __FUNCTION__);
+    return -1;
+}
+
+int
+virStorageBackendRunProgNul(virConnectPtr conn,
+                            virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
+                            const char **prog ATTRIBUTE_UNUSED,
+                            size_t n_columns ATTRIBUTE_UNUSED,
+                            virStorageBackendListVolNulFunc func ATTRIBUTE_UNUSED,
+                            void *data ATTRIBUTE_UNUSED)
+{
+    virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s no implemented on Win32", __FUNCTION__);
+    return -1;
+}
+#endif
diff -r 74dd97c354cc src/storage_conf.c
--- a/src/storage_conf.c	Tue Sep 02 10:49:53 2008 -0400
+++ b/src/storage_conf.c	Wed Sep 03 08:24:04 2008 -0400
@@ -188,7 +188,11 @@
     }
 
     if (virXPathNode(conn, "/pool/permissions/owner", ctxt) == NULL) {
+#if HAVE_GETUID
         perms->uid = getuid();
+#else
+        perms->uid = 0;
+#endif
     } else {
         if (virXPathLong(conn, "number(/pool/permissions/owner)", ctxt, &v) < 0) {
             virStorageReportError(conn, VIR_ERR_XML_ERROR,
@@ -199,7 +203,11 @@
     }
 
     if (virXPathNode(conn, "/pool/permissions/group", ctxt) == NULL) {
-        perms->uid = getgid();
+#if HAVE_GETGID
+        perms->gid = getgid();
+#else
+        perms->gid = 0;
+#endif
     } else {
         if (virXPathLong(conn, "number(/pool/permissions/group)", ctxt, &v) < 0) {
             virStorageReportError(conn, VIR_ERR_XML_ERROR,
@@ -407,7 +415,7 @@
     if (!xml) {
         if (conn && conn->err.code == VIR_ERR_NONE)
               virStorageReportError(conn, VIR_ERR_XML_ERROR,
-                                    _("failed to parse xml document"));
+                                    "%s",_("failed to parse xml document"));
         goto cleanup;
     }
 
@@ -569,7 +577,11 @@
     }
 
     if (virXPathNode(conn, "/volume/permissions/owner", ctxt) == NULL) {
+#if HAVE_GETUID
         perms->uid = getuid();
+#else
+        perms->uid = 0;
+#endif
     } else {
         if (virXPathLong(conn, "number(/volume/permissions/owner)", ctxt, &v) < 0) {
             virStorageReportError(conn, VIR_ERR_XML_ERROR,
@@ -579,7 +591,11 @@
         perms->uid = (int)v;
     }
     if (virXPathNode(conn, "/volume/permissions/group", ctxt) == NULL) {
+#if HAVE_GETGID
         perms->gid = getgid();
+#else
+        perms->gid = 0;
+#endif
     } else {
         if (virXPathLong(conn, "number(/volume/permissions/group)", ctxt, &v) < 0) {
             virStorageReportError(conn, VIR_ERR_XML_ERROR,
@@ -778,7 +794,7 @@
     if (!xml) {
         if (conn && conn->err.code == VIR_ERR_NONE)
               virStorageReportError(conn, VIR_ERR_XML_ERROR,
-                                    _("failed to parse xml document"));
+                                    "%s", _("failed to parse xml document"));
         goto cleanup;
     }
 
diff -r 74dd97c354cc src/util.c
--- a/src/util.c	Tue Sep 02 10:49:53 2008 -0400
+++ b/src/util.c	Wed Sep 03 08:24:04 2008 -0400
@@ -440,22 +440,13 @@
 int
 virExec(virConnectPtr conn,
         const char *const*argv ATTRIBUTE_UNUSED,
+        const char *const*envp ATTRIBUTE_UNUSED,
+        const fd_set *keepfd ATTRIBUTE_UNUSED,
         int *retpid ATTRIBUTE_UNUSED,
         int infd ATTRIBUTE_UNUSED,
         int *outfd ATTRIBUTE_UNUSED,
-        int *errfd ATTRIBUTE_UNUSED)
-{
-    ReportError (conn, VIR_ERR_INTERNAL_ERROR, __FUNCTION__);
-    return -1;
-}
-
-int
-virExecNonBlock(virConnectPtr conn,
-                const char *const*argv ATTRIBUTE_UNUSED,
-                int *retpid ATTRIBUTE_UNUSED,
-                int infd ATTRIBUTE_UNUSED,
-                int *outfd ATTRIBUTE_UNUSED,
-                int *errfd ATTRIBUTE_UNUSED)
+        int *errfd ATTRIBUTE_UNUSED,
+        int flags ATTRIBUTE_UNUSED)
 {
     ReportError (conn, VIR_ERR_INTERNAL_ERROR, __FUNCTION__);
     return -1;


-- 
|: 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 :|




More information about the libvir-list mailing list