[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH v2 3/3] libxl: switch NetBSD file backend to Qemu if filesystem is not local



This forces libxl to use Qemu when a raw image file hosted on a
remote filesystem is used as a disk backend. NetBSD currently only
supports qemu-traditional, so
device_model_version="qemu-xen-traditional" has to be added to the
config file when using image files.

To detect if the filesystem is local the statvfs(2) function is used,
as recommended by Greg Troxel.

Signed-off-by: Roger Pau Monnà <roger.pau@xxxxxxxxxx>
---
 tools/libxl/libxl_device.c   |    8 +++++++-
 tools/libxl/libxl_internal.h |    4 +++-
 tools/libxl/libxl_linux.c    |    2 +-
 tools/libxl/libxl_netbsd.c   |   12 ++++++++++--
 4 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
index 51dd06e..eca2ec2 100644
--- a/tools/libxl/libxl_device.c
+++ b/tools/libxl/libxl_device.c
@@ -144,6 +144,7 @@ typedef struct {
     libxl__gc *gc;
     libxl_device_disk *disk;
     struct stat stab;
+    struct statvfs stvfs;
 } disk_try_backend_args;
 
 static int disk_try_backend(disk_try_backend_args *a,
@@ -167,7 +168,7 @@ static int disk_try_backend(disk_try_backend_args *a,
             return backend;
         }
 
-        if (libxl__try_phy_backend(a->stab.st_mode))
+        if (libxl__try_phy_backend(a->stab.st_mode, a->stvfs.f_flag))
             return backend;
 
         LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Disk vdev=%s, backend phy"
@@ -250,6 +251,11 @@ int libxl__device_disk_set_backend(libxl__gc *gc, 
libxl_device_disk *disk) {
                              disk->vdev, disk->pdev_path);
             return ERROR_INVAL;
         }
+        if (statvfs(disk->pdev_path, &a.stvfs)) {
+            LOGE(ERROR, "Disk vdev=%s failed to stat: %s",
+                 disk->vdev, disk->pdev_path);
+            return ERROR_INVAL;
+        }
     }
 
     if (disk->backend != LIBXL_DISK_BACKEND_UNKNOWN) {
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 0b38e3e..98666bd 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -43,6 +43,7 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <sys/socket.h>
+#include <sys/statvfs.h>
 
 #include <xenstore.h>
 #include <xenctrl.h>
@@ -1040,10 +1041,11 @@ static inline void 
libxl__domaindeathcheck_stop(libxl__gc *gc,
  * libxl__try_phy_backend - Check if there's support for the passed
  * type of file using the PHY backend
  * st_mode: mode_t of the file, as returned by stat function
+ * f_flag: flag as returned by statvfs(2) function
  *
  * Returns 1 on success, and 0 if not suitable for phy backend.
  */
-_hidden int libxl__try_phy_backend(mode_t st_mode);
+_hidden int libxl__try_phy_backend(mode_t st_mode, unsigned long f_flag);
 
 
 _hidden char *libxl__devid_to_localdev(libxl__gc *gc, int devid);
diff --git a/tools/libxl/libxl_linux.c b/tools/libxl/libxl_linux.c
index 1fed3cd..4e11eeb 100644
--- a/tools/libxl/libxl_linux.c
+++ b/tools/libxl/libxl_linux.c
@@ -17,7 +17,7 @@
 
 #include "libxl_internal.h"
  
-int libxl__try_phy_backend(mode_t st_mode)
+int libxl__try_phy_backend(mode_t st_mode, unsigned long f_flag)
 {
     if (!S_ISBLK(st_mode)) {
         return 0;
diff --git a/tools/libxl/libxl_netbsd.c b/tools/libxl/libxl_netbsd.c
index 9587833..aa7e0a9 100644
--- a/tools/libxl/libxl_netbsd.c
+++ b/tools/libxl/libxl_netbsd.c
@@ -17,9 +17,17 @@
 
 #include "libxl_internal.h"
 
-int libxl__try_phy_backend(mode_t st_mode)
+int libxl__try_phy_backend(mode_t st_mode, unsigned long f_flag)
 {
-    if (S_ISREG(st_mode) || S_ISBLK(st_mode))
+    if (S_ISBLK(st_mode))
+        /* File is a block device, always handled by xbdback */
+        return 1;
+
+    if (S_ISREG(st_mode) && (ST_LOCAL & f_flag))
+        /*
+         * File is a regular file, and the filesystem is local,
+         * attach using vnd(4).
+         */
         return 1;
 
     return 0;
-- 
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.