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

[Xen-devel] [PATCH v3] libxl: postpone backend name resolution



This adds a backend_name field in addition to the backend_domid field in
libxl devices, allowing either a domid or a domain name to be specified.
The domain name is resolved into a domain ID in the _setdefault function
when adding the device.  This change allows the backend of the block
devices to be specified (which previously required passing the libxl_ctx
down into the block device parser), and should simplify users of libxl
that wish to use backend domains.

Signed-off-by: Daniel De Graaf <dgdegra@xxxxxxxxxxxxx>
Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Cc: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>

---

This patch does not include the changes to tools/libxl/libxlu_disk_l.c
and tools/libxl/libxlu_disk_l.h because the diffs contain unrelated
changes due to different generator versions.
---
 docs/misc/xl-disk-configuration.txt | 12 +++++++++
 tools/libxl/libxl.c                 | 49 ++++++++++++++++++++++++++++++++++++-
 tools/libxl/libxl_types.idl         |  5 ++++
 tools/libxl/libxlu_disk_l.l         |  1 +
 tools/libxl/xl_cmdimpl.c            | 36 ++++++---------------------
 5 files changed, 73 insertions(+), 30 deletions(-)

diff --git a/docs/misc/xl-disk-configuration.txt 
b/docs/misc/xl-disk-configuration.txt
index 86c16be..5bd456d 100644
--- a/docs/misc/xl-disk-configuration.txt
+++ b/docs/misc/xl-disk-configuration.txt
@@ -139,6 +139,18 @@ cdrom
 Convenience alias for "devtype=cdrom".
 
 
+backend=<domain-name>
+---------------------
+
+Description:           Designates a backend domain for the device
+Supported values:      Valid domain names
+Mandatory:             No
+
+Specifies the backend domain which this device should attach to. This
+defaults to domain 0. Specifying another domain requires setting up a
+driver domain which is outside the scope of this document.
+
+
 backendtype=<backend-type>
 --------------------------
 
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 6c4455e..a04b435 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -1710,12 +1710,35 @@ out:
     return;
 }
 
+/* backend domain name-to-domid conversion utility */
+static int libxl__resolve_domain(libxl__gc *gc, const char *name)
+{
+    int i, rv;
+    uint32_t domid;
+    for (i=0; name[i]; i++) {
+        if (!isdigit(name[i])) {
+            rv = libxl_name_to_domid(libxl__gc_owner(gc), name, &domid);
+            if (rv)
+                return rv;
+            return domid;
+        }
+    }
+    return atoi(name);
+}
+
 
/******************************************************************************/
 int libxl__device_vtpm_setdefault(libxl__gc *gc, libxl_device_vtpm *vtpm)
 {
+   int rc;
    if(libxl_uuid_is_nil(&vtpm->uuid)) {
       libxl_uuid_generate(&vtpm->uuid);
    }
+   if (vtpm->backend_domname) {
+       rc = libxl__resolve_domain(gc, vtpm->backend_domname);
+       if (rc < 0)
+           return rc;
+       vtpm->backend_domid = rc;
+   }
    return 0;
 }
 
@@ -1956,7 +1979,13 @@ int libxl__device_disk_setdefault(libxl__gc *gc, 
libxl_device_disk *disk)
     rc = libxl__device_disk_set_backend(gc, disk);
     if (rc) return rc;
 
-    return rc;
+    if (disk->backend_domname) {
+        rc = libxl__resolve_domain(gc, disk->backend_domname);
+        if (rc < 0)
+            return rc;
+        disk->backend_domid = rc;
+    }
+    return 0;
 }
 
 int libxl__device_from_disk(libxl__gc *gc, uint32_t domid,
@@ -2784,6 +2813,12 @@ int libxl__device_nic_setdefault(libxl__gc *gc, 
libxl_device_nic *nic,
         abort();
     }
 
+    if (nic->backend_domname) {
+        int rc = libxl__resolve_domain(gc, nic->backend_domname);
+        if (rc < 0)
+            return rc;
+        nic->backend_domid = rc;
+    }
     return 0;
 }
 
@@ -3144,6 +3179,12 @@ out:
 
 int libxl__device_vkb_setdefault(libxl__gc *gc, libxl_device_vkb *vkb)
 {
+    if (vkb->backend_domname) {
+        int rc = libxl__resolve_domain(gc, vkb->backend_domname);
+        if (rc < 0)
+            return rc;
+        vkb->backend_domid = rc;
+    }
     return 0;
 }
 
@@ -3236,6 +3277,12 @@ int libxl__device_vfb_setdefault(libxl__gc *gc, 
libxl_device_vfb *vfb)
     libxl_defbool_setdefault(&vfb->sdl.enable, false);
     libxl_defbool_setdefault(&vfb->sdl.opengl, false);
 
+    if (vfb->backend_domname) {
+        int rc = libxl__resolve_domain(gc, vfb->backend_domname);
+        if (rc < 0)
+            return rc;
+        vfb->backend_domid = rc;
+    }
     return 0;
 }
 
diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
index 93524f0..131332a 100644
--- a/tools/libxl/libxl_types.idl
+++ b/tools/libxl/libxl_types.idl
@@ -345,6 +345,7 @@ libxl_domain_build_info = Struct("domain_build_info",[
 
 libxl_device_vfb = Struct("device_vfb", [
     ("backend_domid", libxl_domid),
+    ("backend_domname",string),
     ("devid",         libxl_devid),
     ("vnc",           libxl_vnc_info),
     ("sdl",           libxl_sdl_info),
@@ -354,11 +355,13 @@ libxl_device_vfb = Struct("device_vfb", [
 
 libxl_device_vkb = Struct("device_vkb", [
     ("backend_domid", libxl_domid),
+    ("backend_domname", string),
     ("devid", libxl_devid),
     ])
 
 libxl_device_disk = Struct("device_disk", [
     ("backend_domid", libxl_domid),
+    ("backend_domname", string),
     ("pdev_path", string),
     ("vdev", string),
     ("backend", libxl_disk_backend),
@@ -371,6 +374,7 @@ libxl_device_disk = Struct("device_disk", [
 
 libxl_device_nic = Struct("device_nic", [
     ("backend_domid", libxl_domid),
+    ("backend_domname", string),
     ("devid", libxl_devid),
     ("mtu", integer),
     ("model", string),
@@ -398,6 +402,7 @@ libxl_device_pci = Struct("device_pci", [
 
 libxl_device_vtpm = Struct("device_vtpm", [
     ("backend_domid",    libxl_domid),
+    ("backend_domname",  string),
     ("devid",            libxl_devid),
     ("uuid",             libxl_uuid),
 ])
diff --git a/tools/libxl/libxlu_disk_l.l b/tools/libxl/libxlu_disk_l.l
index bee16a1..7c4e7f1 100644
--- a/tools/libxl/libxlu_disk_l.l
+++ b/tools/libxl/libxlu_disk_l.l
@@ -168,6 +168,7 @@ devtype=disk,?      { DPC->disk->is_cdrom = 0; }
 devtype=[^,]*,?        { xlu__disk_err(DPC,yytext,"unknown value for type"); }
 
 access=[^,]*,? { STRIP(','); setaccess(DPC, FROMEQUALS); }
+backend=[^,]*,? { STRIP(','); SAVESTRING("backend", backend_domname, 
FROMEQUALS); }
 backendtype=[^,]*,? { STRIP(','); setbackendtype(DPC,FROMEQUALS); }
 
 vdev=[^,]*,?   { STRIP(','); SAVESTRING("vdev", vdev, FROMEQUALS); }
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index e964bf1..103e344 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -1090,12 +1090,7 @@ static void parse_config_data(const char *config_source,
                      break;
                   *p2 = '\0';
                   if (!strcmp(p, "backend")) {
-                     if(domain_qualifier_to_domid(p2 + 1, 
&(vtpm->backend_domid), 0))
-                     {
-                        fprintf(stderr,
-                              "Specified vtpm backend domain `%s' does not 
exist!\n", p2 + 1);
-                        exit(1);
-                     }
+                     vtpm->backend_domname = strdup(p2 + 1);
                      got_backend = true;
                   } else if(!strcmp(p, "uuid")) {
                      if( libxl_uuid_from_string(&vtpm->uuid, p2 + 1) ) {
@@ -1190,11 +1185,8 @@ static void parse_config_data(const char *config_source,
                     free(nic->ifname);
                     nic->ifname = strdup(p2 + 1);
                 } else if (!strcmp(p, "backend")) {
-                    if(libxl_name_to_domid(ctx, (p2 + 1), 
&(nic->backend_domid))) {
-                        fprintf(stderr, "Specified backend domain does not 
exist, defaulting to Dom0\n");
-                        nic->backend_domid = 0;
-                    }
-                    if (nic->backend_domid != 0 && run_hotplug_scripts) {
+                    nic->backend_domname = strdup(p2 + 1);
+                    if (run_hotplug_scripts) {
                         fprintf(stderr, "ERROR: the vif 'backend=' option "
                                 "cannot be used in conjunction with "
                                 "run_hotplug_scripts, please set "
@@ -2431,8 +2423,6 @@ static void cd_insert(uint32_t domid, const char 
*virtdev, char *phys)
 
     parse_disk_config(&config, buf, &disk);
 
-    disk.backend_domid = 0;
-
     libxl_cdrom_insert(ctx, domid, &disk, NULL);
 
     libxl_device_disk_dispose(&disk);
@@ -5516,11 +5506,7 @@ int main_networkattach(int argc, char **argv)
         } else if (MATCH_OPTION("script", *argv, oparg)) {
             replace_string(&nic.script, oparg);
         } else if (MATCH_OPTION("backend", *argv, oparg)) {
-            if(libxl_name_to_domid(ctx, oparg, &val)) {
-                fprintf(stderr, "Specified backend domain does not exist, 
defaulting to Dom0\n");
-                val = 0;
-            }
-            nic.backend_domid = val;
+            replace_string(&nic.backend_domname, oparg);
         } else if (MATCH_OPTION("vifname", *argv, oparg)) {
             replace_string(&nic.ifname, oparg);
         } else if (MATCH_OPTION("model", *argv, oparg)) {
@@ -5623,8 +5609,8 @@ int main_networkdetach(int argc, char **argv)
 int main_blockattach(int argc, char **argv)
 {
     int opt;
-    uint32_t fe_domid, be_domid = 0;
-    libxl_device_disk disk = { 0 };
+    uint32_t fe_domid;
+    libxl_device_disk disk;
     XLU_Config *config = 0;
 
     if ((opt = def_getopt(argc, argv, "", "block-attach", 2)) != -1)
@@ -5639,8 +5625,6 @@ int main_blockattach(int argc, char **argv)
     parse_disk_config_multistring
         (&config, argc-optind, (const char* const*)argv + optind, &disk);
 
-    disk.backend_domid = be_domid;
-
     if (dryrun_only) {
         char *json = libxl_device_disk_to_json(ctx, &disk);
         printf("disk: %s\n", json);
@@ -5720,7 +5704,6 @@ int main_vtpmattach(int argc, char **argv)
     int opt;
     libxl_device_vtpm vtpm;
     char *oparg;
-    unsigned int val;
     uint32_t domid;
 
     if ((opt = def_getopt(argc, argv, "", "vtpm-attach", 1)) != -1)
@@ -5740,12 +5723,7 @@ int main_vtpmattach(int argc, char **argv)
                 return 1;
             }
         } else if (MATCH_OPTION("backend", *argv, oparg)) {
-            if(domain_qualifier_to_domid(oparg, &val, 0)) {
-                fprintf(stderr,
-                      "Specified backend domain does not exist, defaulting to 
Dom0\n");
-                val = 0;
-            }
-            vtpm.backend_domid = val;
+            replace_string(&vtpm.backend_domname, oparg);
         } else {
             fprintf(stderr, "unrecognized argument `%s'\n", *argv);
             return 1;
-- 
1.7.11.7


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