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

[Xen-devel] [PATCH 16/17] support blktap remus in xl



With this patch, we can use blktap remus like this:
disk = [ 
'format=raw,devtype=disk,access=w,vdev=hda,backendtype=tap,filter=remus,filter-params=192.168.3.1:9000,target=filename'
 ]

Signed-off-by: Wen Congyang <wency@xxxxxxxxxxxxxx>
Cc: Shriram Rajagopalan <rshriram@xxxxxxxxx>
---
 tools/libxl/libxl.c           | 25 +++++++++++++++++++++++--
 tools/libxl/libxl_blktap2.c   | 38 +++++++++++++++++++++++++++++++++-----
 tools/libxl/libxl_device.c    | 35 ++++++++++++++++++++++++++++++++++-
 tools/libxl/libxl_dm.c        |  4 +++-
 tools/libxl/libxl_internal.h  |  8 ++++++--
 tools/libxl/libxl_noblktap2.c |  8 ++++++--
 tools/libxl/libxl_types.idl   |  2 ++
 tools/libxl/libxlu_disk_l.l   |  2 ++
 8 files changed, 109 insertions(+), 13 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index efc3ca6..f96c73b 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -2394,7 +2394,8 @@ static void device_disk_add(libxl__egc *egc, uint32_t 
domid,
             case LIBXL_DISK_BACKEND_TAP:
                 if (dev == NULL) {
                     dev = libxl__blktap_devpath(gc, disk->pdev_path,
-                                                disk->format);
+                                                disk->format, disk->filter,
+                                                disk->filter_params);
                     if (!dev) {
                         LOG(ERROR, "failed to get blktap devpath for %p\n",
                             disk->pdev_path);
@@ -2406,6 +2407,11 @@ static void device_disk_add(libxl__egc *egc, uint32_t 
domid,
                 flexarray_append(back, libxl__sprintf(gc, "%s:%s",
                     libxl_disk_format_to_string(disk->format),
                     disk->pdev_path));
+                if (disk->filter) {
+                    flexarray_append(back, "filter-params");
+                    flexarray_append(back, libxl__sprintf(gc, "%s:%s",
+                        disk->filter, disk->filter_params));
+                }
 
                 /* tap backends with scripts are rejected by
                  * libxl__device_disk_set_backend */
@@ -2607,6 +2613,20 @@ static int libxl__device_disk_from_xs_be(libxl__gc *gc,
          * phy in type(see device_disk_add())
          */
         disk->backend = LIBXL_DISK_BACKEND_TAP;
+
+        rc = read_params(gc, GCSPRINTF("%s/filter-params", be_path),
+                         &tmp, &disk->filter_params);
+        if (rc)
+            goto cleanup;
+        if (!tmp) {
+            LOG(ERROR, "corrupted filter-params: %s", disk->filter_params);
+            goto cleanup;
+        }
+        disk->filter = strdup(tmp);
+        if (!disk->filter) {
+            LOGE(ERROR, "no memory to store filter");
+            goto cleanup;
+        }
     } else {
         /* "params" may not be present; but everything else must be. */
         rc = read_params(gc, GCSPRINTF("%s/params", be_path),
@@ -3059,7 +3079,8 @@ void libxl__device_disk_local_initiate_attach(libxl__egc 
*egc,
                 break;
             case LIBXL_DISK_FORMAT_VHD:
                 dev = libxl__blktap_devpath(gc, disk->pdev_path,
-                                            disk->format);
+                                            disk->format, disk->filter,
+                                            disk->filter_params);
                 break;
             case LIBXL_DISK_FORMAT_QCOW:
             case LIBXL_DISK_FORMAT_QCOW2:
diff --git a/tools/libxl/libxl_blktap2.c b/tools/libxl/libxl_blktap2.c
index 7656fe4..ebe0271 100644
--- a/tools/libxl/libxl_blktap2.c
+++ b/tools/libxl/libxl_blktap2.c
@@ -25,22 +25,33 @@ int libxl__blktap_enabled(libxl__gc *gc)
 
 char *libxl__blktap_devpath(libxl__gc *gc,
                             const char *disk,
-                            libxl_disk_format format)
+                            libxl_disk_format format,
+                            const char *filter,
+                            const char *filter_params)
 {
-    const char *type;
+    const char *type, *disk_params;
     char *params, *devname = NULL;
     tap_list_t tap;
     int err;
 
     type = libxl__device_disk_string_of_format(format);
-    err = tap_ctl_find(type, disk, &tap);
+    if (!type)
+        return NULL;
+
+    if (filter) {
+        disk_params = libxl__sprintf(gc, "%s|%s:%s", filter_params, type, 
disk);
+        type = filter;
+    } else {
+        disk_params = disk;
+    }
+    err = tap_ctl_find(type, disk_params, &tap);
     if (err == 0) {
         devname = libxl__sprintf(gc, "/dev/xen/blktap-2/tapdev%d", tap.minor);
         if (devname)
             return devname;
     }
 
-    params = libxl__sprintf(gc, "%s:%s", type, disk);
+    params = libxl__sprintf(gc, "%s:%s", type, disk_params);
     err = tap_ctl_create(params, &devname);
     if (!err) {
         libxl__ptr_add(gc, devname);
@@ -51,7 +62,9 @@ char *libxl__blktap_devpath(libxl__gc *gc,
 }
 
 
-int libxl__device_destroy_tapdisk(libxl__gc *gc, const char *params)
+int libxl__device_destroy_tapdisk(libxl__gc *gc,
+                                  const char *params,
+                                  const char *filter_params)
 {
     char *type, *disk;
     int err, rc;
@@ -77,6 +90,21 @@ int libxl__device_destroy_tapdisk(libxl__gc *gc, const char 
*params)
 
     type = libxl__device_disk_string_of_format(format);
 
+    if (filter_params) {
+        char *tmp;
+        char *tmp_type = type, *tmp_disk = disk;
+
+        type = libxl__strdup(gc, filter_params);
+        tmp = strchr(type, ':');
+
+        if (!tmp) {
+            LOG(ERROR, "Unable to parse filter-params %s", filter_params);
+            return ERROR_FAIL;
+        }
+        *tmp++ = '\0';
+        disk = libxl__sprintf(gc, "%s|%s:%s", tmp, tmp_type, tmp_disk);
+    }
+
     err = tap_ctl_find(type, disk, &tap);
     if (err < 0) {
         /* returns -errno */
diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
index 4b51ded..0b2a68d 100644
--- a/tools/libxl/libxl_device.c
+++ b/tools/libxl/libxl_device.c
@@ -196,6 +196,9 @@ static int disk_try_backend(disk_try_backend_args *a,
             goto bad_format;
         }
 
+        if (a->disk->filter) goto bad_filter;
+        if (a->disk->filter_params) goto bad_filter_params;
+
         if (a->disk->backend_domid != LIBXL_TOOLSTACK_DOMID) {
             LOG(DEBUG, "Disk vdev=%s, is using a storage driver domain, "
                        "skipping physical device check", a->disk->vdev);
@@ -232,10 +235,25 @@ static int disk_try_backend(disk_try_backend_args *a,
               a->disk->format == LIBXL_DISK_FORMAT_VHD)) {
             goto bad_format;
         }
+
+        if (a->disk->filter && !a->disk->filter_params) {
+            LOG(DEBUG, "Disk vdev=%s, backend tap unsuitable due to missing "
+                "filter_params=...", a->disk->vdev);
+            return 0;
+        }
+
+        if (!a->disk->filter && a->disk->filter_params) {
+            LOG(DEBUG, "Disk vdev=%s, backend tap unsuitable due to missing "
+                "filter=...", a->disk->vdev);
+            return 0;
+        }
+
         return backend;
 
     case LIBXL_DISK_BACKEND_QDISK:
         if (a->disk->script) goto bad_script;
+        if (a->disk->filter) goto bad_filter;
+        if (a->disk->filter_params) goto bad_filter_params;
         return backend;
 
     default:
@@ -256,6 +274,16 @@ static int disk_try_backend(disk_try_backend_args *a,
     LOG(DEBUG, "Disk vdev=%s, backend %s not compatible with script=...",
         a->disk->vdev, libxl_disk_backend_to_string(backend));
     return 0;
+
+ bad_filter:
+    LOG(DEBUG, "Disk vdev=%s, backend %s not compatible with filter=...",
+        a->disk->vdev, libxl_disk_backend_to_string(backend));
+    return 0;
+
+ bad_filter_params:
+    LOG(DEBUG, "Disk vdev=%s, backend %s not compatible with 
filter-params=...",
+        a->disk->vdev, libxl_disk_backend_to_string(backend));
+    return 0;
 }
 
 int libxl__device_disk_set_backend(libxl__gc *gc, libxl_device_disk *disk) {
@@ -572,6 +600,8 @@ int libxl__device_destroy(libxl__gc *gc, libxl__device *dev)
     const char *fe_path = libxl__device_frontend_path(gc, dev);
     const char *tapdisk_path = GCSPRINTF("%s/%s", be_path, "tapdisk-params");
     const char *tapdisk_params;
+    const char *filter_path = GCSPRINTF("%s/%s", be_path, "filter-params");
+    const char *filter_params;
     xs_transaction_t t = 0;
     int rc;
     uint32_t domid;
@@ -587,6 +617,9 @@ int libxl__device_destroy(libxl__gc *gc, libxl__device *dev)
         rc = libxl__xs_read_checked(gc, t, tapdisk_path, &tapdisk_params);
         if (rc) goto out;
 
+        rc = libxl__xs_read_checked(gc, t, filter_path, &filter_params);
+        if (rc) goto out;
+
         if (domid == LIBXL_TOOLSTACK_DOMID) {
             /*
              * The toolstack domain is in charge for removing both the
@@ -608,7 +641,7 @@ int libxl__device_destroy(libxl__gc *gc, libxl__device *dev)
     }
 
     if (tapdisk_params)
-        rc = libxl__device_destroy_tapdisk(gc, tapdisk_params);
+        rc = libxl__device_destroy_tapdisk(gc, tapdisk_params, filter_params);
 
 out:
     libxl__xs_transaction_abort(gc, &t);
diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index d8992bb..a39d46c 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -750,7 +750,9 @@ static char ** libxl__build_device_model_args_new(libxl__gc 
*gc,
 
                 if (disks[i].backend == LIBXL_DISK_BACKEND_TAP)
                     pdev_path = libxl__blktap_devpath(gc, disks[i].pdev_path,
-                                                      disks[i].format);
+                                                      disks[i].format,
+                                                      disks[i].filter,
+                                                      disks[i].filter_params);
                 else
                     pdev_path = disks[i].pdev_path;
 
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 83bef59..282b03f 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1541,14 +1541,18 @@ _hidden int libxl__blktap_enabled(libxl__gc *gc);
  */
 _hidden char *libxl__blktap_devpath(libxl__gc *gc,
                                     const char *disk,
-                                    libxl_disk_format format);
+                                    libxl_disk_format format,
+                                    const char *filter,
+                                    const char *filter_params);
 
 /* libxl__device_destroy_tapdisk:
  *   Destroys any tapdisk process associated with the backend represented
  *   by be_path.
  *   Always logs on failure.
  */
-_hidden int libxl__device_destroy_tapdisk(libxl__gc *gc, const char *params);
+_hidden int libxl__device_destroy_tapdisk(libxl__gc *gc,
+                                          const char *params,
+                                          const char *filter_params);
 
 _hidden int libxl__device_from_disk(libxl__gc *gc, uint32_t domid,
                                    libxl_device_disk *disk,
diff --git a/tools/libxl/libxl_noblktap2.c b/tools/libxl/libxl_noblktap2.c
index 5a86ed1..ba3120b 100644
--- a/tools/libxl/libxl_noblktap2.c
+++ b/tools/libxl/libxl_noblktap2.c
@@ -23,12 +23,16 @@ int libxl__blktap_enabled(libxl__gc *gc)
 
 char *libxl__blktap_devpath(libxl__gc *gc,
                             const char *disk,
-                            libxl_disk_format format)
+                            libxl_disk_format format,
+                            const char *filter,
+                            const char *filter_params)
 {
     return NULL;
 }
 
-int libxl__device_destroy_tapdisk(libxl__gc *gc, const char *params)
+int libxl__device_destroy_tapdisk(libxl__gc *gc,
+                                  const char *params,
+                                  const char *filter_params)
 {
     return 0;
 }
diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
index bbb03e2..275be93 100644
--- a/tools/libxl/libxl_types.idl
+++ b/tools/libxl/libxl_types.idl
@@ -465,6 +465,8 @@ libxl_device_disk = Struct("device_disk", [
     ("is_cdrom", integer),
     ("direct_io_safe", bool),
     ("discard_enable", libxl_defbool),
+    ("filter", string),
+    ("filter_params", string),
     ])
 
 libxl_device_nic = Struct("device_nic", [
diff --git a/tools/libxl/libxlu_disk_l.l b/tools/libxl/libxlu_disk_l.l
index 1a5deb5..cfd2e3f 100644
--- a/tools/libxl/libxlu_disk_l.l
+++ b/tools/libxl/libxlu_disk_l.l
@@ -176,6 +176,8 @@ script=[^,]*,?      { STRIP(','); SAVESTRING("script", 
script, FROMEQUALS); }
 direct-io-safe,? { DPC->disk->direct_io_safe = 1; }
 discard,?      { libxl_defbool_set(&DPC->disk->discard_enable, true); }
 no-discard,?   { libxl_defbool_set(&DPC->disk->discard_enable, false); }
+filter=[^,]*,? { STRIP(','); SAVESTRING("filter", filter, FROMEQUALS); }
+filter-params=[^,]*,?  { STRIP(','); SAVESTRING("filter-params", 
filter_params, FROMEQUALS); }
 
  /* the target magic parameter, eats the rest of the string */
 
-- 
1.9.3


_______________________________________________
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®.