All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs
@ 2011-09-30 13:33 Ian Campbell
  2011-09-30 13:33 ` [PATCH 01 of 23] libxl: remove hard tabs from non-generated *.[ch] Ian Campbell
                   ` (24 more replies)
  0 siblings, 25 replies; 55+ messages in thread
From: Ian Campbell @ 2011-09-30 13:33 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig, Mike McClurg, Dave Scott, Jonathan Ludlam

The following series overhauls the libxl_device_* APIs in an attempt
to make them more consistent across the types of devices and move
towards something we can support as a stable API longterm.

This is broadly speaking the changes I discussed in [0]

One of the early patches adds a big comment describing the API. It
would be useful if this got a particularly close eye with a view to
supporting it long term -- especially from actual and potential
consumers of the API (of who I've CC a few who sprang to mind).

Along the way I filed some rough edges of the internal implementation
of this stuff but my primary concern is to make the public facing API
one that we can commit to keeping stable.

One aspect which is missing is the ability to do asynchronous
add/remove etc. This requires the overhaul of the libxl event system
which Ian Jackson described at [1]. I did bear this in mind so
hopefully I have provided the majority of the necessary moving parts
internally.

[0] http://www.gossamer-threads.com/lists/xen/devel/204668
[1] http://www.gossamer-threads.com/lists/xen/devel/212580
 &  http://www.gossamer-threads.com/lists/xen/devel/212578
 &  http://www.gossamer-threads.com/lists/xen/devel/212579
 &  http://www.gossamer-threads.com/lists/xen/devel/212581

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 01 of 23] libxl: remove hard tabs from non-generated *.[ch]
  2011-09-30 13:33 [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Ian Campbell
@ 2011-09-30 13:33 ` Ian Campbell
  2011-10-06 16:34   ` Ian Jackson
  2011-09-30 13:33 ` [PATCH 02 of 23] libxl: add a comment describing the device interfaces Ian Campbell
                   ` (23 subsequent siblings)
  24 siblings, 1 reply; 55+ messages in thread
From: Ian Campbell @ 2011-09-30 13:33 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig, Mike McClurg, Dave Scott, Jonathan Ludlam

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1317389247 -3600
# Node ID 42dee7039d911db8b82e9f857fcad92a689d0318
# Parent  de01831eb2a92600dac56c9791dfaa9445777f03
libxl: remove hard tabs from non-generated *.[ch]

The vast majority of this code uses four spaces and the tabs make my subsequent
patches look funny...

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r de01831eb2a9 -r 42dee7039d91 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl.c	Fri Sep 30 14:27:27 2011 +0100
@@ -696,13 +696,13 @@ int libxl_event_get_disk_eject_info(libx
     sscanf(backend,
             "/local/domain/%d/backend/%" TOSTRING(BACKEND_STRING_SIZE) "[a-z]/%*d/%*d",
             &disk->backend_domid, backend_type);
-	if (!strcmp(backend_type, "tap") || !strcmp(backend_type, "vbd")) {
-		disk->backend = LIBXL_DISK_BACKEND_TAP;
-	} else if (!strcmp(backend_type, "qdisk")) {
-		disk->backend = LIBXL_DISK_BACKEND_QDISK;
-	} else {
-		disk->backend = LIBXL_DISK_BACKEND_UNKNOWN;
-	}
+    if (!strcmp(backend_type, "tap") || !strcmp(backend_type, "vbd")) {
+        disk->backend = LIBXL_DISK_BACKEND_TAP;
+    } else if (!strcmp(backend_type, "qdisk")) {
+        disk->backend = LIBXL_DISK_BACKEND_QDISK;
+    } else {
+        disk->backend = LIBXL_DISK_BACKEND_UNKNOWN;
+    }
 
     disk->pdev_path = strdup("");
     disk->format = LIBXL_DISK_FORMAT_EMPTY;
diff -r de01831eb2a9 -r 42dee7039d91 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl.h	Fri Sep 30 14:27:27 2011 +0100
@@ -420,7 +420,7 @@ int libxl_cpuid_parse_config_xend(libxl_
                                   const char* str);
 void libxl_cpuid_apply_policy(libxl_ctx *ctx, uint32_t domid);
 void libxl_cpuid_set(libxl_ctx *ctx, uint32_t domid,
-		     libxl_cpuid_policy_list cpuid);
+                     libxl_cpuid_policy_list cpuid);
 
 /*
  * Functions for allowing users of libxl to store private data
diff -r de01831eb2a9 -r 42dee7039d91 tools/libxl/libxl_bootloader.c
--- a/tools/libxl/libxl_bootloader.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl_bootloader.c	Fri Sep 30 14:27:27 2011 +0100
@@ -81,14 +81,14 @@ static int open_xenconsoled_pty(int *mas
 
     ret = openpty(master, slave, NULL, NULL, NULL);
     if (ret < 0)
-	    return -1;
+        return -1;
 
     ret = ttyname_r(*slave, slave_path, slave_path_len);
     if (ret == -1) {
-	    close(*master);
-	    close(*slave);
-	    *master = *slave = -1;
-	    return -1;
+        close(*master);
+        close(*slave);
+        *master = *slave = -1;
+        return -1;
     }
 
     /*
diff -r de01831eb2a9 -r 42dee7039d91 tools/libxl/libxl_cpuid.c
--- a/tools/libxl/libxl_cpuid.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl_cpuid.c	Fri Sep 30 14:27:27 2011 +0100
@@ -317,7 +317,7 @@ void libxl_cpuid_apply_policy(libxl_ctx 
 }
 
 void libxl_cpuid_set(libxl_ctx *ctx, uint32_t domid,
-		     libxl_cpuid_policy_list cpuid)
+                     libxl_cpuid_policy_list cpuid)
 {
     int i;
     char *cpuid_res[4];
diff -r de01831eb2a9 -r 42dee7039d91 tools/libxl/libxl_internal.c
--- a/tools/libxl/libxl_internal.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl_internal.c	Fri Sep 30 14:27:27 2011 +0100
@@ -228,53 +228,53 @@ char *libxl__abs_path(libxl__gc *gc, con
 
 int libxl__file_reference_map(libxl_file_reference *f)
 {
-	struct stat st_buf;
-	int ret, fd;
-	void *data;
+    struct stat st_buf;
+    int ret, fd;
+    void *data;
 
-	if (f->mapped)
-		return 0;
+    if (f->mapped)
+        return 0;
 
-	fd = open(f->path, O_RDONLY);
-	if (f < 0)
-		return ERROR_FAIL;
+    fd = open(f->path, O_RDONLY);
+    if (f < 0)
+        return ERROR_FAIL;
 
-	ret = fstat(fd, &st_buf);
-	if (ret < 0)
-		goto out;
+    ret = fstat(fd, &st_buf);
+    if (ret < 0)
+        goto out;
 
-	ret = -1;
-	data = mmap(NULL, st_buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
-	if (data == NULL)
-		goto out;
+    ret = -1;
+    data = mmap(NULL, st_buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+    if (data == NULL)
+        goto out;
 
-	f->mapped = 1;
-	f->data = data;
-	f->size = st_buf.st_size;
+    f->mapped = 1;
+    f->data = data;
+    f->size = st_buf.st_size;
 
-	ret = 0;
+    ret = 0;
 out:
-	close(fd);
+    close(fd);
 
-	return ret == 0 ? 0 : ERROR_FAIL;
+    return ret == 0 ? 0 : ERROR_FAIL;
 }
 
 int libxl__file_reference_unmap(libxl_file_reference *f)
 {
-	int ret;
+    int ret;
 
-	if (!f->mapped)
-		return 0;
+    if (!f->mapped)
+        return 0;
 
-	ret = munmap(f->data, f->size);
-	if (ret == 0) {
-		f->mapped = 0;
-		f->data = NULL;
-		f->size = 0;
-		return 0;
-	}
+    ret = munmap(f->data, f->size);
+    if (ret == 0) {
+        f->mapped = 0;
+        f->data = NULL;
+        f->size = 0;
+        return 0;
+    }
 
-	return ERROR_FAIL;
+    return ERROR_FAIL;
 }
 
 _hidden int libxl__parse_mac(const char *s, libxl_mac mac)
diff -r de01831eb2a9 -r 42dee7039d91 tools/libxl/libxl_nocpuid.c
--- a/tools/libxl/libxl_nocpuid.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl_nocpuid.c	Fri Sep 30 14:27:27 2011 +0100
@@ -32,6 +32,6 @@ void libxl_cpuid_apply_policy(libxl_ctx 
 }
 
 void libxl_cpuid_set(libxl_ctx *ctx, uint32_t domid,
-		     libxl_cpuid_policy_list cpuid)
+                     libxl_cpuid_policy_list cpuid)
 {
 }
diff -r de01831eb2a9 -r 42dee7039d91 tools/libxl/libxl_pci.c
--- a/tools/libxl/libxl_pci.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl_pci.c	Fri Sep 30 14:27:27 2011 +0100
@@ -1114,7 +1114,7 @@ static int e820_sanitize(libxl_ctx *ctx,
         if ((src[i].type == E820_RAM) ||
             (src[i].type == E820_UNUSABLE) ||
             (src[i].type == 0))
-		continue;
+            continue;
 
         start = src[i].addr < start ? src[i].addr : start;
         last = src[i].addr + src[i].size > last ?
@@ -1159,14 +1159,14 @@ static int e820_sanitize(libxl_ctx *ctx,
      * to E820_UNUSED. We also need to move some of the E820_RAM regions if
      * the overlap with ram_end. */
     for (i = 0; i < nr; i++) {
-	uint64_t end = src[i].addr + src[i].size;
+        uint64_t end = src[i].addr + src[i].size;
 
-	/* We don't care about E820_UNUSABLE, but we need to
+        /* We don't care about E820_UNUSABLE, but we need to
          * change the type to zero b/c the loop after this
          * sticks E820_UNUSABLE on the guest's E820 but ignores
          * the ones with type zero. */
         if ((src[i].type == E820_UNUSABLE) ||
-	    /* Any region that is within the "RAM region" can
+            /* Any region that is within the "RAM region" can
              * be safely ditched. */
             (end < ram_end)) {
                 src[i].type = 0;
@@ -1174,15 +1174,15 @@ static int e820_sanitize(libxl_ctx *ctx,
         }
 
         /* Look only at RAM regions. */
-	if (src[i].type != E820_RAM)
+        if (src[i].type != E820_RAM)
             continue;
 
         /* We only care about RAM regions below 4GB. */
         if (src[i].addr >= (1ULL<<32))
             continue;
 
-	/* E820_RAM overlaps with our RAM region. Move it */
-	if (src[i].addr < ram_end) {
+        /* E820_RAM overlaps with our RAM region. Move it */
+        if (src[i].addr < ram_end) {
             uint64_t delta;
 
             src[i].type = E820_UNUSABLE;
@@ -1236,8 +1236,8 @@ static int e820_sanitize(libxl_ctx *ctx,
     /* Almost done: copy them over, ignoring the undesireable ones */
     for (i = 0; i < nr; i++) {
         if ((src[i].type == E820_RAM) ||
-	    (src[i].type == 0))
-	    continue;
+            (src[i].type == 0))
+            continue;
 
         e820[idx].type = src[i].type;
         e820[idx].addr = src[i].addr;
diff -r de01831eb2a9 -r 42dee7039d91 tools/libxl/libxl_utils.c
--- a/tools/libxl/libxl_utils.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl_utils.c	Fri Sep 30 14:27:27 2011 +0100
@@ -457,7 +457,7 @@ int libxl_mac_to_device_nic(libxl_ctx *c
 
     rc = libxl__parse_mac(mac, mac_n);
     if (rc)
-	    return rc;
+        return rc;
 
     nics = libxl_list_nics(ctx, domid, &nb);
     if (!nics)
@@ -509,7 +509,7 @@ int libxl_devid_to_device_nic(libxl_ctx 
     val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/mac", nic_path_fe));
     rc = libxl__parse_mac(val, nic->mac);
     if (rc)
-	    goto out;
+        goto out;
 
     nic->script = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, "%s/script", nic_path_be), NULL);
     rc = 0;
diff -r de01831eb2a9 -r 42dee7039d91 tools/libxl/libxlutil.h
--- a/tools/libxl/libxlutil.h	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxlutil.h	Fri Sep 30 14:27:27 2011 +0100
@@ -64,7 +64,7 @@ const char *xlu_cfg_get_listitem(const X
  */
 
 int xlu_disk_parse(XLU_Config *cfg, int nspecs, const char *const *specs,
-		   libxl_device_disk *disk);
+                   libxl_device_disk *disk);
   /* disk must have been initialised.
    *
    * On error, returns errno value.  Bad strings cause EINVAL and
diff -r de01831eb2a9 -r 42dee7039d91 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/xl_cmdimpl.c	Fri Sep 30 14:27:27 2011 +0100
@@ -557,15 +557,15 @@ static void parse_disk_config_multistrin
     memset(disk, 0, sizeof(*disk));
 
     if (!*config) {
-	*config = xlu_cfg_init(stderr, "command line");
-	if (!*config) { perror("xlu_cfg_init"); exit(-1); }
+        *config = xlu_cfg_init(stderr, "command line");
+        if (!*config) { perror("xlu_cfg_init"); exit(-1); }
     }
 
     e = xlu_disk_parse(*config, nspecs, specs, disk);
     if (e == EINVAL) exit(-1);
     if (e) {
-	fprintf(stderr,"xlu_disk_parse failed: %s\n",strerror(errno));
-	exit(-1);
+        fprintf(stderr,"xlu_disk_parse failed: %s\n",strerror(errno));
+        exit(-1);
     }
 }

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 02 of 23] libxl: add a comment describing the device interfaces
  2011-09-30 13:33 [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Ian Campbell
  2011-09-30 13:33 ` [PATCH 01 of 23] libxl: remove hard tabs from non-generated *.[ch] Ian Campbell
@ 2011-09-30 13:33 ` Ian Campbell
  2011-10-04  8:53   ` Dave Scott
  2011-09-30 13:33 ` [PATCH 03 of 23] libxl: various fixes to libxl_device_disk_list (and internals) Ian Campbell
                   ` (22 subsequent siblings)
  24 siblings, 1 reply; 55+ messages in thread
From: Ian Campbell @ 2011-09-30 13:33 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig, Mike McClurg, Dave Scott, Jonathan Ludlam

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1317389247 -3600
# Node ID 7c845e974def74de73f67123f39d6fd2769082e9
# Parent  42dee7039d911db8b82e9f857fcad92a689d0318
libxl: add a comment describing the device interfaces.

Subsequent patches will endevour to make reality match this defined
interface.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 42dee7039d91 -r 7c845e974def tools/libxl/libxl.h
--- a/tools/libxl/libxl.h	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl.h	Fri Sep 30 14:27:27 2011 +0100
@@ -379,6 +379,78 @@ libxl_dominfo * libxl_list_domain(libxl_
 libxl_cpupoolinfo * libxl_list_cpupool(libxl_ctx*, int *nb_pool);
 libxl_vminfo * libxl_list_vm(libxl_ctx *ctx, int *nb_vm);
 
+/*
+ * Devices
+ * =======
+ *
+ * Each device is represented by a libxl_device_<TYPE> data structure
+ * which is defined via the IDL. In addition some devices have an
+ * additional data type libxl_device_<TYPE>_getinfo which contains
+ * further runtime information about the device.
+ *
+ * A common set of methods are available for each device type. These
+ * are described below.
+ *
+ * Querying
+ * --------
+ *
+ * libxl_device_<type>_list(ctx, domid, nr):
+ *
+ *   Returns an array of libxl_device_<type> length nr representing
+ *   the devices attached to the specified domain.
+ *
+ * libxl_device_<type>_getinfo(ctx, domid, device, info):
+ *
+ *   Initialises info with details of the given device which must be
+ *   attached to the specified domain.
+ *
+ * Creation / Control
+ * ------------------
+ *
+ * libxl_device_<type>_init(ctx, device):
+ *
+ *    Initalises device to a default configuration.
+ *
+ * libxl_device_<type>_add(ctx, domid, device):
+ *
+ *   Adds the given device to the specified domain. This can be called
+ *   while the guest is running (hotplug) or before boot (coldplug).
+ *
+ *   This function only sets up the device but does not wait for the
+ *   domain to connect to the device and therefore cannot block on the
+ *   guest.
+ *
+ *   XXX do we need a way to wait? e.g. wait_for_connect function?
+ *   XXX perhaps an optional way to generate an event on connect?
+ *   needs event system overhaul.
+ *
+ * libxl_device_<type>_remove(ctx, domid, device):
+ *
+ *   Removes the given device from the specified domain by performing
+ *   an orderly unplug with guest co-operation. This requires that the
+ *   guest is running.
+ *
+ *   This method is currently synchronous and therefore can block
+ *   while interacting with the guest.
+ *
+ *   XXX should provide an async version. needs event system overhaul.
+ *
+ * libxl_device_<type>_force_remove(ctx, domid, device):
+ *
+ *   Removes the given device from the specified domain without guest
+ *   co-operation. It is guest specific what affect this will have on
+ *   a running guest.
+ *
+ *   This function does not interact with the guest and therefore
+ *   cannot block on the guest.
+ *
+ * Note
+ * ----
+ *
+ * The function libxl_device_<type>_destroy is defined by the IDL and
+ * is used to free the members of the libxl_device_<type> data
+ * type. It has no impact on the devices attached to any domain.
+ */
 int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk);
 int libxl_device_disk_del(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk, int wait);
 libxl_device_disk *libxl_device_disk_list(libxl_ctx *ctx, uint32_t domid, int *num);

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 03 of 23] libxl: various fixes to libxl_device_disk_list (and internals)
  2011-09-30 13:33 [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Ian Campbell
  2011-09-30 13:33 ` [PATCH 01 of 23] libxl: remove hard tabs from non-generated *.[ch] Ian Campbell
  2011-09-30 13:33 ` [PATCH 02 of 23] libxl: add a comment describing the device interfaces Ian Campbell
@ 2011-09-30 13:33 ` Ian Campbell
  2011-09-30 13:33 ` [PATCH 04 of 23] libxl: refactor code to construct disk from xenstore backend Ian Campbell
                   ` (21 subsequent siblings)
  24 siblings, 0 replies; 55+ messages in thread
From: Ian Campbell @ 2011-09-30 13:33 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig, Mike McClurg, Dave Scott, Jonathan Ludlam

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1317389247 -3600
# Node ID 9fdae058b42c9a8981599d96e1de3131997e7b64
# Parent  7c845e974def74de73f67123f39d6fd2769082e9
libxl: various fixes to libxl_device_disk_list (and internals)

- handle realloc errors
- remove redundancy of libxl__append_disk_list_of_type return value
  and ndisks paramter.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 7c845e974def -r 9fdae058b42c tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl.c	Fri Sep 30 14:27:27 2011 +0100
@@ -1502,11 +1502,11 @@ int libxl_device_vkb_hard_shutdown(libxl
     return ERROR_NI;
 }
 
-static unsigned int libxl__append_disk_list_of_type(libxl__gc *gc,
-                                                    uint32_t domid,
-                                                    const char *type,
-                                                    libxl_device_disk **disks,
-                                                    unsigned int *ndisks)
+static int libxl__append_disk_list_of_type(libxl__gc *gc,
+                                           uint32_t domid,
+                                           const char *type,
+                                           libxl_device_disk **disks,
+                                           int *ndisks)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
     char *be_path = NULL;
@@ -1520,11 +1520,16 @@ static unsigned int libxl__append_disk_l
     dir = libxl__xs_directory(gc, XBT_NULL, be_path, &n);
     if (dir) {
         char *removable;
-        *disks = realloc(*disks, sizeof (libxl_device_disk) * (*ndisks + n));
+        libxl_device_disk *tmp;
+        tmp = realloc(*disks, sizeof (libxl_device_disk) * (*ndisks + n));
+        if (tmp == NULL)
+            return ERROR_NOMEM;
+        *disks = tmp;
         pdisk = *disks + *ndisks;
         *ndisks += n;
         pdisk_end = *disks + *ndisks;
         for (; pdisk < pdisk_end; pdisk++, dir++) {
+            memset(pdisk, 0, sizeof(*pdisk));
             pdisk->backend_domid = 0;
             physpath_tmp = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(gc, "%s/%s/params", be_path, *dir), &len);
             if (physpath_tmp && strchr(physpath_tmp, ':')) {
@@ -1552,22 +1557,37 @@ static unsigned int libxl__append_disk_l
             pdisk->format = LIBXL_DISK_FORMAT_UNKNOWN;
         }
     }
-
-    return n;
+    return 0;
 }
 
 libxl_device_disk *libxl_device_disk_list(libxl_ctx *ctx, uint32_t domid, int *num)
 {
     libxl__gc gc = LIBXL_INIT_GC(ctx);
     libxl_device_disk *disks = NULL;
-    unsigned int ndisks = 0;
-
-    *num = libxl__append_disk_list_of_type(&gc, domid, "vbd", &disks, &ndisks);
-    *num += libxl__append_disk_list_of_type(&gc, domid, "tap", &disks, &ndisks);
-    *num += libxl__append_disk_list_of_type(&gc, domid, "qdisk", &disks, &ndisks);
+    int rc;
+
+    *num = 0;
+
+    rc = libxl__append_disk_list_of_type(&gc, domid, "vbd", &disks, num);
+    if (rc) goto out_err;
+
+    rc = libxl__append_disk_list_of_type(&gc, domid, "tap", &disks, num);
+    if (rc) goto out_err;
+
+    rc = libxl__append_disk_list_of_type(&gc, domid, "qdisk", &disks, num);
+    if (rc) goto out_err;
 
     libxl__free_all(&gc);
     return disks;
+
+out_err:
+    LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Unable to list disks");
+    while (disks && *num) {
+        (*num)--;
+        libxl_device_disk_destroy(&disks[*num]);
+    }
+    free(disks);
+    return NULL;
 }
 
 int libxl_device_disk_getinfo(libxl_ctx *ctx, uint32_t domid,

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 04 of 23] libxl: refactor code to construct disk from xenstore backend
  2011-09-30 13:33 [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Ian Campbell
                   ` (2 preceding siblings ...)
  2011-09-30 13:33 ` [PATCH 03 of 23] libxl: various fixes to libxl_device_disk_list (and internals) Ian Campbell
@ 2011-09-30 13:33 ` Ian Campbell
  2011-09-30 13:33 ` [PATCH 05 of 23] libxl: do not read f.e. xenstore dir in disk list function Ian Campbell
                   ` (20 subsequent siblings)
  24 siblings, 0 replies; 55+ messages in thread
From: Ian Campbell @ 2011-09-30 13:33 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig, Mike McClurg, Dave Scott, Jonathan Ludlam

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1317389247 -3600
# Node ID 8645a81f04282ca4e3c51141b1c177ad9a8d5943
# Parent  9fdae058b42c9a8981599d96e1de3131997e7b64
libxl: refactor code to construct disk from xenstore backend

Temporarily retain unsafe behaviour of reading f.e. directory.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 9fdae058b42c -r 8645a81f0428 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl.c	Fri Sep 30 14:27:27 2011 +0100
@@ -1502,24 +1502,69 @@ int libxl_device_vkb_hard_shutdown(libxl
     return ERROR_NI;
 }
 
+static void libxl__device_disk_from_xs_be(libxl__gc *gc,
+                                          const char *be_path,
+                                          libxl_device_disk *disk)
+{
+    libxl_ctx *ctx = libxl__gc_owner(gc);
+    unsigned int len;
+    char *tmp;
+    const char *fe_path; /* XXX unsafe */
+
+    memset(disk, 0, sizeof(*disk));
+
+    tmp = xs_read(ctx->xsh, XBT_NULL,
+                  libxl__sprintf(gc, "%s/params", be_path), &len);
+    if (tmp && strchr(tmp, ':')) {
+        disk->pdev_path = strdup(strchr(tmp, ':') + 1);
+        free(tmp);
+    } else {
+        disk->pdev_path = tmp;
+    }
+    libxl_string_to_backend(ctx,
+                        libxl__xs_read(gc, XBT_NULL,
+                                       libxl__sprintf(gc, "%s/type", be_path)),
+                        &(disk->backend));
+    disk->vdev = xs_read(ctx->xsh, XBT_NULL,
+                         libxl__sprintf(gc, "%s/dev", be_path), &len);
+    tmp = libxl__xs_read(gc, XBT_NULL, libxl__sprintf
+                         (gc, "%s/removable", be_path));
+
+    if (tmp)
+        disk->removable = atoi(tmp);
+    else
+        disk->removable = 0;
+
+    tmp = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/mode", be_path));
+    if (!strcmp(tmp, "w"))
+        disk->readwrite = 1;
+    else
+        disk->readwrite = 0;
+
+    fe_path = libxl__xs_read(gc, XBT_NULL,
+                             libxl__sprintf(gc, "%s/frontend", be_path));
+    tmp = libxl__xs_read(gc, XBT_NULL,
+                         libxl__sprintf(gc, "%s/device-type", fe_path));
+    disk->is_cdrom = !strcmp(tmp, "cdrom");
+
+    disk->format = LIBXL_DISK_FORMAT_UNKNOWN;
+}
+
 static int libxl__append_disk_list_of_type(libxl__gc *gc,
                                            uint32_t domid,
                                            const char *type,
                                            libxl_device_disk **disks,
                                            int *ndisks)
 {
-    libxl_ctx *ctx = libxl__gc_owner(gc);
     char *be_path = NULL;
     char **dir = NULL;
-    unsigned int n = 0, len = 0;
+    unsigned int n = 0;
     libxl_device_disk *pdisk = NULL, *pdisk_end = NULL;
-    char *physpath_tmp = NULL;
 
     be_path = libxl__sprintf(gc, "%s/backend/%s/%d",
                              libxl__xs_get_dompath(gc, 0), type, domid);
     dir = libxl__xs_directory(gc, XBT_NULL, be_path, &n);
     if (dir) {
-        char *removable;
         libxl_device_disk *tmp;
         tmp = realloc(*disks, sizeof (libxl_device_disk) * (*ndisks + n));
         if (tmp == NULL)
@@ -1529,32 +1574,10 @@ static int libxl__append_disk_list_of_ty
         *ndisks += n;
         pdisk_end = *disks + *ndisks;
         for (; pdisk < pdisk_end; pdisk++, dir++) {
-            memset(pdisk, 0, sizeof(*pdisk));
+            const char *p;
+            p = libxl__sprintf(gc, "%s/%s", be_path, *dir);
+            libxl__device_disk_from_xs_be(gc, p, pdisk);
             pdisk->backend_domid = 0;
-            physpath_tmp = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(gc, "%s/%s/params", be_path, *dir), &len);
-            if (physpath_tmp && strchr(physpath_tmp, ':')) {
-                pdisk->pdev_path = strdup(strchr(physpath_tmp, ':') + 1);
-                free(physpath_tmp);
-            } else {
-                pdisk->pdev_path = physpath_tmp;
-            }
-            libxl_string_to_backend(ctx, libxl__xs_read(gc, XBT_NULL,
-                libxl__sprintf(gc, "%s/%s/type", be_path, *dir)),
-                &(pdisk->backend));
-            pdisk->vdev = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(gc, "%s/%s/dev", be_path, *dir), &len);
-            removable = libxl__xs_read(gc, XBT_NULL, libxl__sprintf
-                                       (gc, "%s/%s/removable", be_path, *dir));
-            if (removable)
-                pdisk->removable = atoi(removable);
-            else
-                pdisk->removable = 0;
-            if (!strcmp(libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/%s/mode", be_path, *dir)), "w"))
-                pdisk->readwrite = 1;
-            else
-                pdisk->readwrite = 0;
-            type = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/device-type", libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/%s/frontend", be_path, *dir))));
-            pdisk->is_cdrom = !strcmp(type, "cdrom");
-            pdisk->format = LIBXL_DISK_FORMAT_UNKNOWN;
         }
     }
     return 0;

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 05 of 23] libxl: do not read f.e. xenstore dir in disk list function
  2011-09-30 13:33 [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Ian Campbell
                   ` (3 preceding siblings ...)
  2011-09-30 13:33 ` [PATCH 04 of 23] libxl: refactor code to construct disk from xenstore backend Ian Campbell
@ 2011-09-30 13:33 ` Ian Campbell
  2011-09-30 13:33 ` [PATCH 06 of 23] libxl: update nic list API to use common device API style Ian Campbell
                   ` (19 subsequent siblings)
  24 siblings, 0 replies; 55+ messages in thread
From: Ian Campbell @ 2011-09-30 13:33 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig, Mike McClurg, Dave Scott, Jonathan Ludlam

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1317389247 -3600
# Node ID 4e640cbed20e8ef533f8eb27a82dcdac2be2e8ab
# Parent  8645a81f04282ca4e3c51141b1c177ad9a8d5943
libxl: do not read f.e. xenstore dir in disk list function

Instead store a duplicate of the "device-type" node in the backend dir
and use that instead.

This maintains the invariant that the list function is always "safe".

XXX I'm not sure this is an actual issue. The entries in the frontend device
XXX area are writeable by the guest but maybe the solution is to restrict that?

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 8645a81f0428 -r 4e640cbed20e tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl.c	Fri Sep 30 14:27:27 2011 +0100
@@ -1015,6 +1015,8 @@ int libxl_device_disk_add(libxl_ctx *ctx
     flexarray_append(back, libxl__device_disk_string_of_backend(disk->backend));
     flexarray_append(back, "mode");
     flexarray_append(back, disk->readwrite ? "w" : "r");
+    flexarray_append(back, "device-type");
+    flexarray_append(back, disk->is_cdrom ? "cdrom" : "disk");
 
     flexarray_append(front, "backend-id");
     flexarray_append(front, libxl__sprintf(&gc, "%d", disk->backend_domid));
@@ -1509,7 +1511,6 @@ static void libxl__device_disk_from_xs_b
     libxl_ctx *ctx = libxl__gc_owner(gc);
     unsigned int len;
     char *tmp;
-    const char *fe_path; /* XXX unsafe */
 
     memset(disk, 0, sizeof(*disk));
 
@@ -1541,10 +1542,8 @@ static void libxl__device_disk_from_xs_b
     else
         disk->readwrite = 0;
 
-    fe_path = libxl__xs_read(gc, XBT_NULL,
-                             libxl__sprintf(gc, "%s/frontend", be_path));
     tmp = libxl__xs_read(gc, XBT_NULL,
-                         libxl__sprintf(gc, "%s/device-type", fe_path));
+                         libxl__sprintf(gc, "%s/device-type", be_path));
     disk->is_cdrom = !strcmp(tmp, "cdrom");
 
     disk->format = LIBXL_DISK_FORMAT_UNKNOWN;

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 06 of 23] libxl: update nic list API to use common device API style
  2011-09-30 13:33 [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Ian Campbell
                   ` (4 preceding siblings ...)
  2011-09-30 13:33 ` [PATCH 05 of 23] libxl: do not read f.e. xenstore dir in disk list function Ian Campbell
@ 2011-09-30 13:33 ` Ian Campbell
  2011-10-05 12:48   ` [PATCH] " Roger Pau Monne
  2011-09-30 13:33 ` [PATCH 07 of 23] libxl: reimplement devid->nic in terms of from_xs_be function Ian Campbell
                   ` (18 subsequent siblings)
  24 siblings, 1 reply; 55+ messages in thread
From: Ian Campbell @ 2011-09-30 13:33 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig, Mike McClurg, Dave Scott, Jonathan Ludlam

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1317389247 -3600
# Node ID cafd8b3f9e0c8bbf5c30cfcd512c1486661ca4d9
# Parent  4e640cbed20e8ef533f8eb27a82dcdac2be2e8ab
libxl: update nic list API to use common device API style

libxl_device_nic_list returns an array of libxl_device_nic and
libxl_device_nic_getinfo retrieves further information.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 4e640cbed20e -r cafd8b3f9e0c tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl.c	Fri Sep 30 14:27:27 2011 +0100
@@ -1288,60 +1288,138 @@ int libxl_device_nic_del(libxl_ctx *ctx,
     return rc;
 }
 
-libxl_nicinfo *libxl_list_nics(libxl_ctx *ctx, uint32_t domid, unsigned int *nb)
+static void libxl__device_nic_from_xs_be(libxl__gc *gc,
+                                         const char *be_path,
+                                         libxl_device_nic *nic)
+{
+    libxl_ctx *ctx = libxl__gc_owner(gc);
+    unsigned int len;
+    char *tmp;
+    int rc;
+
+    memset(nic, 0, sizeof(*nic));
+
+    tmp = xs_read(ctx->xsh, XBT_NULL,
+                  libxl__sprintf(gc, "%s/handle", be_path), &len);
+    if ( tmp )
+        nic->devid = atoi(tmp);
+    else
+        nic->devid = 0;
+
+    /* nic->mtu = */
+
+    tmp = xs_read(ctx->xsh, XBT_NULL,
+                  libxl__sprintf(gc, "%s/mac", be_path), &len);
+    rc = libxl__parse_mac(tmp, nic->mac);
+    if (rc)
+            memset(nic->mac, 0, sizeof(nic->mac));
+
+    nic->ip = xs_read(ctx->xsh, XBT_NULL,
+                      libxl__sprintf(gc, "%s/ip", be_path), &len);
+
+    nic->bridge = xs_read(ctx->xsh, XBT_NULL,
+                      libxl__sprintf(gc, "%s/bridge", be_path), &len);
+
+    nic->script = xs_read(ctx->xsh, XBT_NULL,
+                      libxl__sprintf(gc, "%s/script", be_path), &len);
+
+    /* XXX ioemu nics are not in xenstore at all? */
+    nic->nictype = LIBXL_NIC_TYPE_VIF;
+    nic->model = NULL; /* XXX Only for TYPE_IOEMU */
+    nic->ifname = NULL; /* XXX Only for TYPE_IOEMU */
+}
+
+static int libxl__append_nic_list_of_type(libxl__gc *gc,
+                                           uint32_t domid,
+                                           const char *type,
+                                           libxl_device_nic **nics,
+                                           int *nnics)
+{
+    char *be_path = NULL;
+    char **dir = NULL;
+    unsigned int n = 0;
+    libxl_device_nic *pnic = NULL, *pnic_end = NULL;
+
+    be_path = libxl__sprintf(gc, "%s/backend/%s/%d",
+                             libxl__xs_get_dompath(gc, 0), type, domid);
+    dir = libxl__xs_directory(gc, XBT_NULL, be_path, &n);
+    if (dir) {
+        libxl_device_nic *tmp;
+        tmp = realloc(*nics, sizeof (libxl_device_nic) * (*nnics + n));
+        if (tmp == NULL)
+            return ERROR_NOMEM;
+        *nics = tmp;
+        pnic = *nics + *nnics;
+        *nnics += n;
+        pnic_end = *nics + *nnics;
+        for (; pnic < pnic_end; pnic++, dir++) {
+            const char *p;
+            p = libxl__sprintf(gc, "%s/%s", be_path, *dir);
+            libxl__device_nic_from_xs_be(gc, p, pnic);
+            pnic->backend_domid = 0;
+        }
+    }
+    return 0;
+}
+
+libxl_device_nic *libxl_device_nic_list(libxl_ctx *ctx, uint32_t domid, int *num)
 {
     libxl__gc gc = LIBXL_INIT_GC(ctx);
-    char *dompath, *nic_path_fe;
-    char **l, **list;
-    char *val, *tok;
-    unsigned int nb_nics, i;
-    libxl_nicinfo *res, *nics;
+    libxl_device_nic *nics = NULL;
+    int rc;
+
+    *num = 0;
+
+    rc = libxl__append_nic_list_of_type(&gc, domid, "vif", &nics, num);
+    if (rc) goto out_err;
+
+    libxl__free_all(&gc);
+    return nics;
+
+out_err:
+    LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Unable to list nics");
+    while (*num) {
+        (*num)--;
+        libxl_device_nic_destroy(&nics[*num]);
+    }
+    free(nics);
+    return NULL;
+}
+
+int libxl_device_nic_getinfo(libxl_ctx *ctx, uint32_t domid,
+                              libxl_device_nic *nic, libxl_nicinfo *nicinfo)
+{
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
+    char *dompath, *nicpath;
+    char *val;
 
     dompath = libxl__xs_get_dompath(&gc, domid);
-    if (!dompath)
-        goto err;
-    list = l = libxl__xs_directory(&gc, XBT_NULL,
-                           libxl__sprintf(&gc, "%s/device/vif", dompath), &nb_nics);
-    if (!l)
-        goto err;
-    nics = res = calloc(nb_nics, sizeof (libxl_nicinfo));
-    if (!res)
-        goto err;
-    for (*nb = nb_nics; nb_nics > 0; --nb_nics, ++l, ++nics) {
-        nic_path_fe = libxl__sprintf(&gc, "%s/device/vif/%s", dompath, *l);
-
-        nics->backend = xs_read(ctx->xsh, XBT_NULL,
-                                libxl__sprintf(&gc, "%s/backend", nic_path_fe), NULL);
-        val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/backend-id", nic_path_fe));
-        nics->backend_id = val ? strtoul(val, NULL, 10) : -1;
-
-        nics->devid = strtoul(*l, NULL, 10);
-        val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/state", nic_path_fe));
-        nics->state = val ? strtoul(val, NULL, 10) : -1;
-        val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/mac", nic_path_fe));
-        for (i = 0, tok = strtok(val, ":"); tok && (i < 6);
-             ++i, tok = strtok(NULL, ":")) {
-            nics->mac[i] = strtoul(tok, NULL, 16);
-        }
-        val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/event-channel", nic_path_fe));
-        nics->evtch = val ? strtol(val, NULL, 10) : -1;
-        val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/tx-ring-ref", nic_path_fe));
-        nics->rref_tx = val ? strtol(val, NULL, 10) : -1;
-        val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/rx-ring-ref", nic_path_fe));
-        nics->rref_rx = val ? strtol(val, NULL, 10) : -1;
-        nics->frontend = xs_read(ctx->xsh, XBT_NULL,
-                                 libxl__sprintf(&gc, "%s/frontend", nics->backend), NULL);
-        val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/frontend-id", nics->backend));
-        nics->frontend_id = val ? strtoul(val, NULL, 10) : -1;
-        nics->script = xs_read(ctx->xsh, XBT_NULL,
-                               libxl__sprintf(&gc, "%s/script", nics->backend), NULL);
+    nicinfo->devid = nic->devid;
+
+    nicpath = libxl__sprintf(&gc, "%s/device/vif/%d", dompath, nicinfo->devid);
+    nicinfo->backend = xs_read(ctx->xsh, XBT_NULL,
+                                libxl__sprintf(&gc, "%s/backend", nicpath), NULL);
+    if (!nicinfo->backend) {
+        libxl__free_all(&gc);
+        return ERROR_FAIL;
     }
+    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/backend-id", nicpath));
+    nicinfo->backend_id = val ? strtoul(val, NULL, 10) : -1;
+    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/state", nicpath));
+    nicinfo->state = val ? strtoul(val, NULL, 10) : -1;
+    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/event-channel", nicpath));
+    nicinfo->evtch = val ? strtoul(val, NULL, 10) : -1;
+    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/tx-ring-ref", nicpath));
+    nicinfo->rref_tx = val ? strtoul(val, NULL, 10) : -1;
+    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/rx-ring-ref", nicpath));
+    nicinfo->rref_rx = val ? strtoul(val, NULL, 10) : -1;
+    nicinfo->frontend = xs_read(ctx->xsh, XBT_NULL,
+                                 libxl__sprintf(&gc, "%s/frontend", nicinfo->backend), NULL);
+    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/frontend-id", nicinfo->backend));
+    nicinfo->frontend_id = val ? strtoul(val, NULL, 10) : -1;
 
     libxl__free_all(&gc);
-    return res;
-err:
-    libxl__free_all(&gc);
-    return NULL;
+    return 0;
 }
 
 /******************************************************************************/
diff -r 4e640cbed20e -r cafd8b3f9e0c tools/libxl/libxl.h
--- a/tools/libxl/libxl.h	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl.h	Fri Sep 30 14:27:27 2011 +0100
@@ -467,7 +467,9 @@ int libxl_device_disk_local_detach(libxl
 int libxl_device_nic_init(libxl_device_nic *nic, int dev_num);
 int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic);
 int libxl_device_nic_del(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic, int wait);
-libxl_nicinfo *libxl_list_nics(libxl_ctx *ctx, uint32_t domid, unsigned int *nb);
+libxl_device_nic *libxl_device_nic_list(libxl_ctx *ctx, uint32_t domid, int *num);
+int libxl_device_nic_getinfo(libxl_ctx *ctx, uint32_t domid,
+                              libxl_device_nic *nic, libxl_nicinfo *nicinfo);
 
 int libxl_device_console_add(libxl_ctx *ctx, uint32_t domid, libxl_device_console *console);
 
diff -r 4e640cbed20e -r cafd8b3f9e0c tools/libxl/libxl_types.idl
--- a/tools/libxl/libxl_types.idl	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl_types.idl	Fri Sep 30 14:27:27 2011 +0100
@@ -330,8 +330,6 @@ libxl_nicinfo = Struct("nicinfo", [
     ("frontend_id", uint32),
     ("devid", integer),
     ("state", integer),
-    ("script", string),
-    ("mac", libxl_mac),
     ("evtch", integer),
     ("rref_tx", integer),
     ("rref_rx", integer),
diff -r 4e640cbed20e -r cafd8b3f9e0c tools/libxl/libxl_utils.c
--- a/tools/libxl/libxl_utils.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl_utils.c	Fri Sep 30 14:27:27 2011 +0100
@@ -451,15 +451,15 @@ int libxl_pipe(libxl_ctx *ctx, int pipes
 int libxl_mac_to_device_nic(libxl_ctx *ctx, uint32_t domid,
                             const char *mac, libxl_device_nic *nic)
 {
-    libxl_nicinfo *nics;
-    unsigned int nb, rc, i;
+    libxl_device_nic *nics;
+    int nb, rc, i;
     libxl_mac mac_n;
 
     rc = libxl__parse_mac(mac, mac_n);
     if (rc)
         return rc;
 
-    nics = libxl_list_nics(ctx, domid, &nb);
+    nics = libxl_device_nic_list(ctx, domid, &nb);
     if (!nics)
         return ERROR_FAIL;
 
@@ -468,17 +468,17 @@ int libxl_mac_to_device_nic(libxl_ctx *c
     rc = ERROR_INVAL;
     for (i = 0; i < nb; ++i) {
         if (!libxl__compare_macs(&mac_n, &nics[i].mac)) {
-            nic->backend_domid = nics[i].backend_id;
-            nic->devid = nics[i].devid;
-            memcpy(nic->mac, nics[i].mac, sizeof (nic->mac));
-            nic->script = strdup(nics[i].script);
+            *nic = nics[i];
             rc = 0;
+            i++; /* Do not destroy this NIC on exit path */
             break;
         }
+        libxl_device_nic_destroy(&nics[i]);
     }
 
-    for (i=0; i<nb; i++)
-        libxl_nicinfo_destroy(&nics[i]);
+    for (; i<nb; i++)
+        libxl_device_nic_destroy(&nics[i]);
+
     free(nics);
     return rc;
 }
diff -r 4e640cbed20e -r cafd8b3f9e0c tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/xl_cmdimpl.c	Fri Sep 30 14:27:27 2011 +0100
@@ -4085,8 +4085,9 @@ int main_networkattach(int argc, char **
 int main_networklist(int argc, char **argv)
 {
     int opt;
-    libxl_nicinfo *nics;
-    unsigned int nb, i;
+    libxl_device_nic *nics;
+    libxl_nicinfo nicinfo;
+    int nb, i;
 
     if ((opt = def_getopt(argc, argv, "", "network-list", 1)) != -1)
         return opt;
@@ -4099,19 +4100,23 @@ int main_networklist(int argc, char **ar
             fprintf(stderr, "%s is an invalid domain identifier\n", *argv);
             continue;
         }
-        if (!(nics = libxl_list_nics(ctx, domid, &nb))) {
+        nics = libxl_device_nic_list(ctx, domid, &nb);
+        if (!nics) {
             continue;
         }
         for (i = 0; i < nb; ++i) {
-            /* Idx BE */
-            printf("%-3d %-2d ", nics[i].devid, nics[i].backend_id);
-            /* MAC */
-            printf(LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nics[i].mac));
-            /* Hdl  Sta  evch txr/rxr  BE-path */
-            printf("%6d %5d %6d %5d/%-11d %-30s\n",
-                   nics[i].devid, nics[i].state, nics[i].evtch,
-                   nics[i].rref_tx, nics[i].rref_rx, nics[i].backend);
-            libxl_nicinfo_destroy(&nics[i]);
+            if (!libxl_device_nic_getinfo(ctx, domid, &nics[i], &nicinfo)) {
+                /* Idx BE */
+                printf("%-3d %-2d ", nicinfo.devid, nicinfo.backend_id);
+                /* MAC */
+                printf(LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nics[i].mac));
+                /* Hdl  Sta  evch txr/rxr  BE-path */
+                printf("%6d %5d %6d %5d/%-11d %-30s\n",
+                       nicinfo.devid, nicinfo.state, nicinfo.evtch,
+                       nicinfo.rref_tx, nicinfo.rref_rx, nicinfo.backend);
+                libxl_nicinfo_destroy(&nicinfo);
+            }
+            libxl_device_nic_destroy(&nics[i]);
         }
         free(nics);
     }

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 07 of 23] libxl: reimplement devid->nic in terms of from_xs_be function
  2011-09-30 13:33 [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Ian Campbell
                   ` (5 preceding siblings ...)
  2011-09-30 13:33 ` [PATCH 06 of 23] libxl: update nic list API to use common device API style Ian Campbell
@ 2011-09-30 13:33 ` Ian Campbell
  2011-09-30 13:33 ` [PATCH 08 of 23] libxl: reimplement devid->disk " Ian Campbell
                   ` (17 subsequent siblings)
  24 siblings, 0 replies; 55+ messages in thread
From: Ian Campbell @ 2011-09-30 13:33 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig, Mike McClurg, Dave Scott, Jonathan Ludlam

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1317389247 -3600
# Node ID e65e18b230493e7886654d30838ce74407c36168
# Parent  cafd8b3f9e0c8bbf5c30cfcd512c1486661ca4d9
libxl: reimplement devid->nic in terms of from_xs_be function.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r cafd8b3f9e0c -r e65e18b23049 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl.c	Fri Sep 30 14:27:27 2011 +0100
@@ -1312,7 +1312,7 @@ static void libxl__device_nic_from_xs_be
                   libxl__sprintf(gc, "%s/mac", be_path), &len);
     rc = libxl__parse_mac(tmp, nic->mac);
     if (rc)
-            memset(nic->mac, 0, sizeof(nic->mac));
+        memset(nic->mac, 0, sizeof(nic->mac));
 
     nic->ip = xs_read(ctx->xsh, XBT_NULL,
                       libxl__sprintf(gc, "%s/ip", be_path), &len);
@@ -1329,6 +1329,32 @@ static void libxl__device_nic_from_xs_be
     nic->ifname = NULL; /* XXX Only for TYPE_IOEMU */
 }
 
+int libxl_devid_to_device_nic(libxl_ctx *ctx, uint32_t domid,
+                              const char *devid, libxl_device_nic *nic)
+{
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
+    char *dompath, *path;
+    int rc = ERROR_FAIL;
+
+    memset(nic, 0, sizeof (libxl_device_nic));
+    dompath = libxl__xs_get_dompath(&gc, domid);
+    if (!dompath)
+        goto out;
+
+    path = libxl__xs_read(&gc, XBT_NULL,
+                          libxl__sprintf(&gc, "%s/device/vif/%s/backend",
+                                         dompath, devid));
+    if (!path)
+        goto out;
+
+    libxl__device_nic_from_xs_be(&gc, path, nic);
+
+    rc = 0;
+out:
+    libxl__free_all(&gc);
+    return rc;
+}
+
 static int libxl__append_nic_list_of_type(libxl__gc *gc,
                                            uint32_t domid,
                                            const char *type,
diff -r cafd8b3f9e0c -r e65e18b23049 tools/libxl/libxl_utils.c
--- a/tools/libxl/libxl_utils.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl_utils.c	Fri Sep 30 14:27:27 2011 +0100
@@ -483,41 +483,6 @@ int libxl_mac_to_device_nic(libxl_ctx *c
     return rc;
 }
 
-int libxl_devid_to_device_nic(libxl_ctx *ctx, uint32_t domid,
-                              const char *devid, libxl_device_nic *nic)
-{
-    libxl__gc gc = LIBXL_INIT_GC(ctx);
-    char *val;
-    char *dompath, *nic_path_fe, *nic_path_be;
-    int rc = ERROR_FAIL;
-
-    memset(nic, 0, sizeof (libxl_device_nic));
-    dompath = libxl__xs_get_dompath(&gc, domid);
-    if (!dompath) {
-        goto out;
-    }
-    nic_path_fe = libxl__sprintf(&gc, "%s/device/vif/%s", dompath, devid);
-    nic_path_be = libxl__xs_read(&gc, XBT_NULL,
-                                libxl__sprintf(&gc, "%s/backend", nic_path_fe));
-    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/backend-id", nic_path_fe));
-    if ( NULL == val ) {
-        goto out;
-    }
-    nic->backend_domid = strtoul(val, NULL, 10);
-    nic->devid = strtoul(devid, NULL, 10);
-
-    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/mac", nic_path_fe));
-    rc = libxl__parse_mac(val, nic->mac);
-    if (rc)
-        goto out;
-
-    nic->script = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, "%s/script", nic_path_be), NULL);
-    rc = 0;
-out:
-    libxl__free_all(&gc);
-    return rc;
-}
-
 int libxl_devid_to_device_disk(libxl_ctx *ctx, uint32_t domid,
                                const char *devid, libxl_device_disk *disk)
 {

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 08 of 23] libxl: reimplement devid->disk in terms of from_xs_be function
  2011-09-30 13:33 [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Ian Campbell
                   ` (6 preceding siblings ...)
  2011-09-30 13:33 ` [PATCH 07 of 23] libxl: reimplement devid->nic in terms of from_xs_be function Ian Campbell
@ 2011-09-30 13:33 ` Ian Campbell
  2011-09-30 13:33 ` [PATCH 09 of 23] libxl: libxl_devid_to_* should take an integer device id Ian Campbell
                   ` (16 subsequent siblings)
  24 siblings, 0 replies; 55+ messages in thread
From: Ian Campbell @ 2011-09-30 13:33 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig, Mike McClurg, Dave Scott, Jonathan Ludlam

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1317389247 -3600
# Node ID d78f45247f1c0a0c879e166010df5cdff2b16988
# Parent  e65e18b230493e7886654d30838ce74407c36168
libxl: reimplement devid->disk in terms of from_xs_be function.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r e65e18b23049 -r d78f45247f1c tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl.c	Fri Sep 30 14:27:27 2011 +0100
@@ -1653,6 +1653,33 @@ static void libxl__device_disk_from_xs_b
     disk->format = LIBXL_DISK_FORMAT_UNKNOWN;
 }
 
+int libxl_devid_to_device_disk(libxl_ctx *ctx, uint32_t domid,
+                               const char *devid, libxl_device_disk *disk)
+{
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
+    char *dompath, *path;
+    int rc = ERROR_FAIL;
+
+    memset(disk, 0, sizeof (libxl_device_disk));
+    dompath = libxl__xs_get_dompath(&gc, domid);
+    if (!dompath) {
+        goto out;
+    }
+    path = libxl__xs_read(&gc, XBT_NULL,
+                          libxl__sprintf(&gc, "%s/device/vbd/%s/backend",
+                                         dompath, devid));
+    if (!path)
+        goto out;
+
+    libxl__device_disk_from_xs_be(&gc, path, disk);
+
+    rc = 0;
+out:
+    libxl__free_all(&gc);
+    return rc;
+}
+
+
 static int libxl__append_disk_list_of_type(libxl__gc *gc,
                                            uint32_t domid,
                                            const char *type,
diff -r e65e18b23049 -r d78f45247f1c tools/libxl/libxl_utils.c
--- a/tools/libxl/libxl_utils.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl_utils.c	Fri Sep 30 14:27:27 2011 +0100
@@ -483,50 +483,6 @@ int libxl_mac_to_device_nic(libxl_ctx *c
     return rc;
 }
 
-int libxl_devid_to_device_disk(libxl_ctx *ctx, uint32_t domid,
-                               const char *devid, libxl_device_disk *disk)
-{
-    libxl__gc gc = LIBXL_INIT_GC(ctx);
-    char *val;
-    char *dompath, *diskpath, *be_path;
-    unsigned int devid_n;
-    int rc = ERROR_INVAL;
-
-    devid_n = libxl__device_disk_dev_number(devid, NULL, NULL);
-    if (devid_n < 0) {
-        goto out;
-    }
-    rc = ERROR_FAIL;
-    dompath = libxl__xs_get_dompath(&gc, domid);
-    diskpath = libxl__sprintf(&gc, "%s/device/vbd/%d", dompath, devid_n);
-    if (!diskpath) {
-        goto out;
-    }
-
-    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/backend-id", diskpath));
-    if (!val)
-        goto out;
-    disk->backend_domid = strtoul(val, NULL, 10);
-    be_path = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/backend", diskpath));
-    disk->pdev_path = xs_read(ctx->xsh, XBT_NULL,
-                              libxl__sprintf(&gc, "%s/params", be_path), NULL);
-    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/type", be_path));
-    libxl_string_to_backend(ctx, val, &(disk->backend));
-    disk->vdev = xs_read(ctx->xsh, XBT_NULL,
-                         libxl__sprintf(&gc, "%s/dev", be_path), NULL);
-    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/removable", be_path));
-    disk->removable = !strcmp(val, "1");
-    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/mode", be_path));
-    disk->readwrite = !!strcmp(val, "w");
-    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/device-type", diskpath));
-    disk->is_cdrom = !strcmp(val, "cdrom");
-    rc = 0;
-
-out:
-    libxl__free_all(&gc);
-    return rc;
-}
-
 int libxl_cpumap_alloc(libxl_ctx *ctx, libxl_cpumap *cpumap)
 {
     int max_cpus;

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 09 of 23] libxl: libxl_devid_to_* should take an integer device id
  2011-09-30 13:33 [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Ian Campbell
                   ` (7 preceding siblings ...)
  2011-09-30 13:33 ` [PATCH 08 of 23] libxl: reimplement devid->disk " Ian Campbell
@ 2011-09-30 13:33 ` Ian Campbell
  2011-09-30 13:33 ` [PATCH 10 of 23] libxl: separate forced and non-forced device remove Ian Campbell
                   ` (15 subsequent siblings)
  24 siblings, 0 replies; 55+ messages in thread
From: Ian Campbell @ 2011-09-30 13:33 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig, Mike McClurg, Dave Scott, Jonathan Ludlam

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1317389247 -3600
# Node ID cefb64e94c5e47858ebe2d76d2448da3d9caa7fb
# Parent  d78f45247f1c0a0c879e166010df5cdff2b16988
libxl: libxl_devid_to_* should take an integer device id

Currently takes a string.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r d78f45247f1c -r cefb64e94c5e tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl.c	Fri Sep 30 14:27:27 2011 +0100
@@ -1330,7 +1330,7 @@ static void libxl__device_nic_from_xs_be
 }
 
 int libxl_devid_to_device_nic(libxl_ctx *ctx, uint32_t domid,
-                              const char *devid, libxl_device_nic *nic)
+                              int devid, libxl_device_nic *nic)
 {
     libxl__gc gc = LIBXL_INIT_GC(ctx);
     char *dompath, *path;
@@ -1342,7 +1342,7 @@ int libxl_devid_to_device_nic(libxl_ctx 
         goto out;
 
     path = libxl__xs_read(&gc, XBT_NULL,
-                          libxl__sprintf(&gc, "%s/device/vif/%s/backend",
+                          libxl__sprintf(&gc, "%s/device/vif/%d/backend",
                                          dompath, devid));
     if (!path)
         goto out;
@@ -1654,7 +1654,7 @@ static void libxl__device_disk_from_xs_b
 }
 
 int libxl_devid_to_device_disk(libxl_ctx *ctx, uint32_t domid,
-                               const char *devid, libxl_device_disk *disk)
+                               int devid, libxl_device_disk *disk)
 {
     libxl__gc gc = LIBXL_INIT_GC(ctx);
     char *dompath, *path;
@@ -1666,7 +1666,7 @@ int libxl_devid_to_device_disk(libxl_ctx
         goto out;
     }
     path = libxl__xs_read(&gc, XBT_NULL,
-                          libxl__sprintf(&gc, "%s/device/vbd/%s/backend",
+                          libxl__sprintf(&gc, "%s/device/vbd/%d/backend",
                                          dompath, devid));
     if (!path)
         goto out;
diff -r d78f45247f1c -r cefb64e94c5e tools/libxl/libxl_utils.h
--- a/tools/libxl/libxl_utils.h	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl_utils.h	Fri Sep 30 14:27:27 2011 +0100
@@ -60,11 +60,11 @@ void libxl_report_child_exitstatus(libxl
 
 int libxl_mac_to_device_nic(libxl_ctx *ctx, uint32_t domid,
                             const char *mac, libxl_device_nic *nic);
-int libxl_devid_to_device_nic(libxl_ctx *ctx, uint32_t domid,
-                              const char *devid, libxl_device_nic *nic);
+int libxl_devid_to_device_nic(libxl_ctx *ctx, uint32_t domid, int devid,
+                              libxl_device_nic *nic);
 
-int libxl_devid_to_device_disk(libxl_ctx *ctx, uint32_t domid,
-                               const char *devid, libxl_device_disk *disk);
+int libxl_devid_to_device_disk(libxl_ctx *ctx, uint32_t domid, int devid,
+                               libxl_device_disk *disk);
 
 int libxl_cpumap_alloc(libxl_ctx *ctx, libxl_cpumap *cpumap);
 int libxl_cpumap_test(libxl_cpumap *cpumap, int cpu);
diff -r d78f45247f1c -r cefb64e94c5e tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/xl_cmdimpl.c	Fri Sep 30 14:27:27 2011 +0100
@@ -4137,7 +4137,7 @@ int main_networkdetach(int argc, char **
     }
 
     if (!strchr(argv[optind+1], ':')) {
-        if (libxl_devid_to_device_nic(ctx, domid, argv[optind+1], &nic)) {
+        if (libxl_devid_to_device_nic(ctx, domid, atoi(argv[optind+1]), &nic)) {
             fprintf(stderr, "Unknown device %s.\n", argv[optind+1]);
             return 1;
         }
@@ -4238,7 +4238,7 @@ int main_blockdetach(int argc, char **ar
         fprintf(stderr, "%s is an invalid domain identifier\n", argv[optind]);
         return 1;
     }
-    if (libxl_devid_to_device_disk(ctx, domid, argv[optind+1], &disk)) {
+    if (libxl_devid_to_device_disk(ctx, domid, atoi(argv[optind+1]), &disk)) {
         fprintf(stderr, "Error: Device %s not connected.\n", argv[optind+1]);
         return 1;
     }

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 10 of 23] libxl: separate forced and non-forced device remove
  2011-09-30 13:33 [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Ian Campbell
                   ` (8 preceding siblings ...)
  2011-09-30 13:33 ` [PATCH 09 of 23] libxl: libxl_devid_to_* should take an integer device id Ian Campbell
@ 2011-09-30 13:33 ` Ian Campbell
  2011-10-06 16:38   ` Ian Jackson
  2011-09-30 13:33 ` [PATCH 11 of 23] libxl: split forced and non-forced uses of libxl__device_del Ian Campbell
                   ` (14 subsequent siblings)
  24 siblings, 1 reply; 55+ messages in thread
From: Ian Campbell @ 2011-09-30 13:33 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig, Mike McClurg, Dave Scott, Jonathan Ludlam

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1317389247 -3600
# Node ID dd195d45be273cf85ef0a614ac69b4498bac6d10
# Parent  cefb64e94c5e47858ebe2d76d2448da3d9caa7fb
libxl: separate forced and non-forced device remove.

The function libxl__device_destroy currently takes a force parameter however:

  * in the forced case we initiate a graceful shutdown and then immediately
    nuke the backend directory, quite likely before anyone got a chance to react.
  * the callers all have a "wait" variable and pass in "!wait" as the force
    argument which is confusing since not waiting is not really the same thing
    as forcing the destroy.
  * the term "destroy" is normally used in libxl for data-type destructors.

Therefore split the function into libxl__device_remove and
libxl__device_force_remove. The latter simply nukes the backend directory.

This makes some of the callers look a bit odd but that should fall out as I
continue to pull this piece of string.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r cefb64e94c5e -r dd195d45be27 tools/libxl/libxl_device.c
--- a/tools/libxl/libxl_device.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl_device.c	Fri Sep 30 14:27:27 2011 +0100
@@ -365,7 +365,7 @@ int libxl__device_disk_dev_number(const 
     return -1;
 }
 
-int libxl__device_destroy(libxl__gc *gc, char *be_path, int force)
+int libxl__device_remove(libxl__gc *gc, char *be_path)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
     xs_transaction_t t;
@@ -393,17 +393,22 @@ retry_transaction:
             goto out;
         }
     }
-    if (!force) {
-        xs_watch(ctx->xsh, state_path, be_path);
-        rc = 1;
-    } else {
-        xs_rm(ctx->xsh, XBT_NULL, be_path);
-    }
+
+    xs_watch(ctx->xsh, state_path, be_path);
     libxl__device_destroy_tapdisk(gc, be_path);
+    rc = 1;
 out:
     return rc;
 }
 
+int libxl__device_force_remove(libxl__gc *gc, char *be_path)
+{
+    libxl_ctx *ctx = libxl__gc_owner(gc);
+    xs_rm(ctx->xsh, XBT_NULL, be_path);
+    libxl__device_destroy_tapdisk(gc, be_path);
+    return 0;
+}
+
 static int wait_for_dev_destroy(libxl__gc *gc, struct timeval *tv)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
@@ -461,7 +466,9 @@ int libxl__devices_destroy(libxl__gc *gc
             fe_path = libxl__sprintf(gc, "/local/domain/%d/device/%s/%s", domid, l1[i], l2[j]);
             be_path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/backend", fe_path));
             if (be_path != NULL) {
-                if (libxl__device_destroy(gc, be_path, force) > 0)
+                int rc = force ? libxl__device_force_remove(gc, be_path)
+                               : libxl__device_remove(gc, be_path);
+                if (rc > 0)
                     n_watches++;
             } else {
                 xs_rm(ctx->xsh, XBT_NULL, path);
@@ -473,7 +480,9 @@ int libxl__devices_destroy(libxl__gc *gc
     fe_path = libxl__sprintf(gc, "/local/domain/%d/console", domid);
     be_path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/backend", fe_path));
     if (be_path && strcmp(be_path, "")) {
-        if (libxl__device_destroy(gc, be_path, force) > 0)
+        int rc = force ? libxl__device_force_remove(gc, be_path)
+                       : libxl__device_remove(gc, be_path);
+        if (rc > 0)
             n_watches++;
     }
 
@@ -506,7 +515,10 @@ int libxl__device_del(libxl__gc *gc, lib
 
     backend_path = libxl__device_backend_path(gc, dev);
 
-    rc = libxl__device_destroy(gc, backend_path, !wait);
+    if (wait)
+        rc = libxl__device_remove(gc, backend_path);
+    else
+        rc = libxl__device_force_remove(gc, backend_path);
     if (rc == -1) {
         rc = ERROR_FAIL;
         goto out;
diff -r cefb64e94c5e -r dd195d45be27 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl_internal.h	Fri Sep 30 14:27:27 2011 +0100
@@ -253,7 +253,8 @@ _hidden int libxl__device_generic_add(li
 _hidden char *libxl__device_backend_path(libxl__gc *gc, libxl__device *device);
 _hidden char *libxl__device_frontend_path(libxl__gc *gc, libxl__device *device);
 _hidden int libxl__device_del(libxl__gc *gc, libxl__device *dev, int wait);
-_hidden int libxl__device_destroy(libxl__gc *gc, char *be_path, int force);
+_hidden int libxl__device_remove(libxl__gc *gc, char *be_path);
+_hidden int libxl__device_force_remove(libxl__gc *gc, char *be_path);
 _hidden int libxl__devices_destroy(libxl__gc *gc, uint32_t domid, int force);
 _hidden int libxl__wait_for_backend(libxl__gc *gc, char *be_path, char *state);
 
diff -r cefb64e94c5e -r dd195d45be27 tools/libxl/libxl_pci.c
--- a/tools/libxl/libxl_pci.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl_pci.c	Fri Sep 30 14:27:27 2011 +0100
@@ -411,8 +411,7 @@ retry_transaction2:
 
     if (num == 1) {
         char *fe_path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/frontend", be_path));
-        libxl__device_destroy(gc, be_path, 1);
-        xs_rm(ctx->xsh, XBT_NULL, be_path);
+        libxl__device_force_remove(gc, be_path);
         xs_rm(ctx->xsh, XBT_NULL, fe_path);
         return 0;
     }

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 11 of 23] libxl: split forced and non-forced uses of libxl__device_del
  2011-09-30 13:33 [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Ian Campbell
                   ` (9 preceding siblings ...)
  2011-09-30 13:33 ` [PATCH 10 of 23] libxl: separate forced and non-forced device remove Ian Campbell
@ 2011-09-30 13:33 ` Ian Campbell
  2011-09-30 13:33 ` [PATCH 12 of 23] libxl: use IDL to define device front- and back-end kinds Ian Campbell
                   ` (13 subsequent siblings)
  24 siblings, 0 replies; 55+ messages in thread
From: Ian Campbell @ 2011-09-30 13:33 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig, Mike McClurg, Dave Scott, Jonathan Ludlam

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1317389247 -3600
# Node ID ed800095162c2d459ba6bdd651ef6f246858c458
# Parent  dd195d45be273cf85ef0a614ac69b4498bac6d10
libxl: split forced and non-forced uses of libxl__device_del

Most forced users can now simply call libxl__device_force_remove directly.

libxl__devices_destroy is something of a special case, it is really just
iterating over an opaque set of xenstore directories and removing them. Until
this can be refactored just do the force-remove case manually, doing otherwise
led to too much entanglement with the other callers of
libxl__device_force_remove which do know about specific device types.

For the time being do the same in libxl__device_pci_remove_xenstore.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r dd195d45be27 -r ed800095162c tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl.c	Fri Sep 30 14:27:27 2011 +0100
@@ -1071,7 +1071,10 @@ int libxl_device_disk_del(libxl_ctx *ctx
     device.domid            = domid;
     device.devid            = devid;
     device.kind             = DEVICE_VBD;
-    rc = libxl__device_del(&gc, &device, wait);
+    if (wait)
+        rc = libxl__device_del(&gc, &device);
+    else
+        rc = libxl__device_force_remove(&gc, &device);
 out_free:
     libxl__free_all(&gc);
     return rc;
@@ -1283,7 +1286,11 @@ int libxl_device_nic_del(libxl_ctx *ctx,
     device.domid            = domid;
     device.kind             = DEVICE_VIF;
 
-    rc = libxl__device_del(&gc, &device, wait);
+    if (wait)
+        rc = libxl__device_del(&gc, &device);
+    else
+        rc = libxl__device_force_remove(&gc, &device);
+
     libxl__free_all(&gc);
     return rc;
 }
diff -r dd195d45be27 -r ed800095162c tools/libxl/libxl_device.c
--- a/tools/libxl/libxl_device.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl_device.c	Fri Sep 30 14:27:27 2011 +0100
@@ -401,11 +401,17 @@ out:
     return rc;
 }
 
-int libxl__device_force_remove(libxl__gc *gc, char *be_path)
+int libxl__device_force_remove(libxl__gc *gc, libxl__device *dev)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
+    char *be_path = libxl__device_backend_path(gc, dev);
+    char *fe_path = libxl__device_frontend_path(gc, dev);
+
     xs_rm(ctx->xsh, XBT_NULL, be_path);
+    xs_rm(ctx->xsh, XBT_NULL, fe_path);
+
     libxl__device_destroy_tapdisk(gc, be_path);
+
     return 0;
 }
 
@@ -466,10 +472,14 @@ int libxl__devices_destroy(libxl__gc *gc
             fe_path = libxl__sprintf(gc, "/local/domain/%d/device/%s/%s", domid, l1[i], l2[j]);
             be_path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/backend", fe_path));
             if (be_path != NULL) {
-                int rc = force ? libxl__device_force_remove(gc, be_path)
-                               : libxl__device_remove(gc, be_path);
-                if (rc > 0)
-                    n_watches++;
+                if (force) {
+                    xs_rm(ctx->xsh, XBT_NULL, be_path);
+                    xs_rm(ctx->xsh, XBT_NULL, fe_path);
+                    libxl__device_destroy_tapdisk(gc, be_path);
+                } else {
+                    if (libxl__device_remove(gc, be_path) > 0)
+                        n_watches++;
+                }
             } else {
                 xs_rm(ctx->xsh, XBT_NULL, path);
             }
@@ -480,10 +490,13 @@ int libxl__devices_destroy(libxl__gc *gc
     fe_path = libxl__sprintf(gc, "/local/domain/%d/console", domid);
     be_path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/backend", fe_path));
     if (be_path && strcmp(be_path, "")) {
-        int rc = force ? libxl__device_force_remove(gc, be_path)
-                       : libxl__device_remove(gc, be_path);
-        if (rc > 0)
-            n_watches++;
+        if (force) {
+            xs_rm(ctx->xsh, XBT_NULL, be_path);
+            xs_rm(ctx->xsh, XBT_NULL, fe_path);
+        } else {
+            if (libxl__device_remove(gc, be_path) > 0)
+                n_watches++;
+        }
     }
 
     if (!force) {
@@ -507,29 +520,24 @@ out:
     return 0;
 }
 
-int libxl__device_del(libxl__gc *gc, libxl__device *dev, int wait)
+int libxl__device_del(libxl__gc *gc, libxl__device *dev)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
+    struct timeval tv;
     char *backend_path;
     int rc;
 
     backend_path = libxl__device_backend_path(gc, dev);
 
-    if (wait)
-        rc = libxl__device_remove(gc, backend_path);
-    else
-        rc = libxl__device_force_remove(gc, backend_path);
+    rc = libxl__device_remove(gc, backend_path);
     if (rc == -1) {
         rc = ERROR_FAIL;
         goto out;
     }
 
-    if (wait) {
-        struct timeval tv;
-        tv.tv_sec = LIBXL_DESTROY_TIMEOUT;
-        tv.tv_usec = 0;
-        (void)wait_for_dev_destroy(gc, &tv);
-    }
+    tv.tv_sec = LIBXL_DESTROY_TIMEOUT;
+    tv.tv_usec = 0;
+    (void)wait_for_dev_destroy(gc, &tv);
 
     xs_rm(ctx->xsh, XBT_NULL, libxl__device_frontend_path(gc, dev));
     rc = 0;
diff -r dd195d45be27 -r ed800095162c tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl_internal.h	Fri Sep 30 14:27:27 2011 +0100
@@ -252,9 +252,9 @@ _hidden int libxl__device_generic_add(li
                              char **bents, char **fents);
 _hidden char *libxl__device_backend_path(libxl__gc *gc, libxl__device *device);
 _hidden char *libxl__device_frontend_path(libxl__gc *gc, libxl__device *device);
-_hidden int libxl__device_del(libxl__gc *gc, libxl__device *dev, int wait);
+_hidden int libxl__device_del(libxl__gc *gc, libxl__device *dev);
 _hidden int libxl__device_remove(libxl__gc *gc, char *be_path);
-_hidden int libxl__device_force_remove(libxl__gc *gc, char *be_path);
+_hidden int libxl__device_force_remove(libxl__gc *gc, libxl__device *dev);
 _hidden int libxl__devices_destroy(libxl__gc *gc, uint32_t domid, int force);
 _hidden int libxl__wait_for_backend(libxl__gc *gc, char *be_path, char *state);
 
diff -r dd195d45be27 -r ed800095162c tools/libxl/libxl_pci.c
--- a/tools/libxl/libxl_pci.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl_pci.c	Fri Sep 30 14:27:27 2011 +0100
@@ -411,7 +411,7 @@ retry_transaction2:
 
     if (num == 1) {
         char *fe_path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/frontend", be_path));
-        libxl__device_force_remove(gc, be_path);
+        xs_rm(ctx->xsh, XBT_NULL, be_path);
         xs_rm(ctx->xsh, XBT_NULL, fe_path);
         return 0;
     }

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 12 of 23] libxl: use IDL to define device front- and back-end kinds
  2011-09-30 13:33 [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Ian Campbell
                   ` (10 preceding siblings ...)
  2011-09-30 13:33 ` [PATCH 11 of 23] libxl: split forced and non-forced uses of libxl__device_del Ian Campbell
@ 2011-09-30 13:33 ` Ian Campbell
  2011-09-30 13:33 ` [PATCH 13 of 23] libxl: do not remove unidentified frontend paths in libxl__devices_destroy Ian Campbell
                   ` (12 subsequent siblings)
  24 siblings, 0 replies; 55+ messages in thread
From: Ian Campbell @ 2011-09-30 13:33 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig, Mike McClurg, Dave Scott, Jonathan Ludlam

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1317389248 -3600
# Node ID e8cff01ad4b5519be66e726db124cbdfab4f1e04
# Parent  ed800095162c2d459ba6bdd651ef6f246858c458
libxl: use IDL to define device front- and back-end kinds

I'd like to use the from_string functionality...

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r ed800095162c -r e8cff01ad4b5 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl.c	Fri Sep 30 14:27:28 2011 +0100
@@ -959,7 +959,7 @@ int libxl_device_disk_add(libxl_ctx *ctx
     device.backend_domid = disk->backend_domid;
     device.devid = devid;
     device.domid = domid;
-    device.kind = DEVICE_VBD;
+    device.kind = LIBXL__DEVICE_KIND_VBD;
 
     switch (disk->backend) {
         case LIBXL_DISK_BACKEND_PHY:
@@ -972,7 +972,7 @@ int libxl_device_disk_add(libxl_ctx *ctx
             flexarray_append(back, "params");
             flexarray_append(back, dev);
 
-            device.backend_kind = DEVICE_VBD;
+            device.backend_kind = LIBXL__DEVICE_KIND_VBD;
             break;
         case LIBXL_DISK_BACKEND_TAP:
             dev = libxl__blktap_devpath(&gc, disk->pdev_path, disk->format);
@@ -991,7 +991,7 @@ int libxl_device_disk_add(libxl_ctx *ctx
             flexarray_append(back, "params");
             flexarray_append(back, libxl__sprintf(&gc, "%s:%s",
                           libxl__device_disk_string_of_format(disk->format), disk->pdev_path));
-            device.backend_kind = DEVICE_QDISK;
+            device.backend_kind = LIBXL__DEVICE_KIND_QDISK;
             break;
         default:
             LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk backend type: %d\n", disk->backend);
@@ -1054,13 +1054,13 @@ int libxl_device_disk_del(libxl_ctx *ctx
 
     switch (disk->backend) {
         case LIBXL_DISK_BACKEND_PHY:
-            device.backend_kind = DEVICE_VBD;
+            device.backend_kind = LIBXL__DEVICE_KIND_VBD;
             break;
         case LIBXL_DISK_BACKEND_TAP:
-            device.backend_kind = DEVICE_VBD;
+            device.backend_kind = LIBXL__DEVICE_KIND_VBD;
             break;
         case LIBXL_DISK_BACKEND_QDISK:
-            device.backend_kind = DEVICE_QDISK;
+            device.backend_kind = LIBXL__DEVICE_KIND_QDISK;
             break;
         default:
             LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk backend type: %d\n",
@@ -1070,7 +1070,7 @@ int libxl_device_disk_del(libxl_ctx *ctx
     }
     device.domid            = domid;
     device.devid            = devid;
-    device.kind             = DEVICE_VBD;
+    device.kind             = LIBXL__DEVICE_KIND_VBD;
     if (wait)
         rc = libxl__device_del(&gc, &device);
     else
@@ -1218,10 +1218,10 @@ int libxl_device_nic_add(libxl_ctx *ctx,
 
     device.backend_devid = nic->devid;
     device.backend_domid = nic->backend_domid;
-    device.backend_kind = DEVICE_VIF;
+    device.backend_kind = LIBXL__DEVICE_KIND_VIF;
     device.devid = nic->devid;
     device.domid = domid;
-    device.kind = DEVICE_VIF;
+    device.kind = LIBXL__DEVICE_KIND_VIF;
 
     flexarray_append(back, "frontend-id");
     flexarray_append(back, libxl__sprintf(&gc, "%d", domid));
@@ -1281,10 +1281,10 @@ int libxl_device_nic_del(libxl_ctx *ctx,
 
     device.backend_devid    = nic->devid;
     device.backend_domid    = nic->backend_domid;
-    device.backend_kind     = DEVICE_VIF;
+    device.backend_kind     = LIBXL__DEVICE_KIND_VIF;
     device.devid            = nic->devid;
     device.domid            = domid;
-    device.kind             = DEVICE_VIF;
+    device.kind             = LIBXL__DEVICE_KIND_VIF;
 
     if (wait)
         rc = libxl__device_del(&gc, &device);
@@ -1483,10 +1483,10 @@ int libxl__device_console_add(libxl__gc 
 
     device.backend_devid = console->devid;
     device.backend_domid = console->backend_domid;
-    device.backend_kind = DEVICE_CONSOLE;
+    device.backend_kind = LIBXL__DEVICE_KIND_CONSOLE;
     device.devid = console->devid;
     device.domid = domid;
-    device.kind = DEVICE_CONSOLE;
+    device.kind = LIBXL__DEVICE_KIND_CONSOLE;
 
     flexarray_append(back, "frontend-id");
     flexarray_append(back, libxl__sprintf(gc, "%d", domid));
@@ -1574,10 +1574,10 @@ int libxl_device_vkb_add(libxl_ctx *ctx,
 
     device.backend_devid = vkb->devid;
     device.backend_domid = vkb->backend_domid;
-    device.backend_kind = DEVICE_VKBD;
+    device.backend_kind = LIBXL__DEVICE_KIND_VKBD;
     device.devid = vkb->devid;
     device.domid = domid;
-    device.kind = DEVICE_VKBD;
+    device.kind = LIBXL__DEVICE_KIND_VKBD;
 
     flexarray_append(back, "frontend-id");
     flexarray_append(back, libxl__sprintf(&gc, "%d", domid));
@@ -1861,10 +1861,10 @@ int libxl_device_vfb_add(libxl_ctx *ctx,
 
     device.backend_devid = vfb->devid;
     device.backend_domid = vfb->backend_domid;
-    device.backend_kind = DEVICE_VFB;
+    device.backend_kind = LIBXL__DEVICE_KIND_VFB;
     device.devid = vfb->devid;
     device.domid = domid;
-    device.kind = DEVICE_VFB;
+    device.kind = LIBXL__DEVICE_KIND_VFB;
 
     flexarray_append_pair(back, "frontend-id", libxl__sprintf(&gc, "%d", domid));
     flexarray_append_pair(back, "online", "1");
diff -r ed800095162c -r e8cff01ad4b5 tools/libxl/libxl_device.c
--- a/tools/libxl/libxl_device.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl_device.c	Fri Sep 30 14:27:28 2011 +0100
@@ -24,30 +24,20 @@
 #include <unistd.h>
 #include <fcntl.h>
 
-
 #include "libxl.h"
 #include "libxl_internal.h"
 
-static const char *string_of_kinds[] = {
-    [DEVICE_VIF] = "vif",
-    [DEVICE_VBD] = "vbd",
-    [DEVICE_QDISK] = "qdisk",
-    [DEVICE_PCI] = "pci",
-    [DEVICE_VFB] = "vfb",
-    [DEVICE_VKBD] = "vkbd",
-    [DEVICE_CONSOLE] = "console",
-};
-
 char *libxl__device_frontend_path(libxl__gc *gc, libxl__device *device)
 {
     char *dom_path = libxl__xs_get_dompath(gc, device->domid);
 
     /* Console 0 is a special case */
-    if (device->kind == DEVICE_CONSOLE && device->devid == 0)
+    if (device->kind == LIBXL__DEVICE_KIND_CONSOLE && device->devid == 0)
         return libxl__sprintf(gc, "%s/console", dom_path);
 
     return libxl__sprintf(gc, "%s/device/%s/%d", dom_path,
-                          string_of_kinds[device->kind], device->devid);
+                          libxl__device_kind_to_string(device->kind),
+                          device->devid);
 }
 
 char *libxl__device_backend_path(libxl__gc *gc, libxl__device *device)
@@ -55,7 +45,7 @@ char *libxl__device_backend_path(libxl__
     char *dom_path = libxl__xs_get_dompath(gc, device->backend_domid);
 
     return libxl__sprintf(gc, "%s/backend/%s/%u/%d", dom_path,
-                          string_of_kinds[device->backend_kind],
+                          libxl__device_kind_to_string(device->backend_kind),
                           device->domid, device->devid);
 }
 
@@ -67,12 +57,6 @@ int libxl__device_generic_add(libxl__gc 
     xs_transaction_t t;
     struct xs_permissions frontend_perms[2];
     struct xs_permissions backend_perms[2];
-    int rc;
-
-    if (!is_valid_device_kind(device->backend_kind) || !is_valid_device_kind(device->kind)) {
-        rc = ERROR_INVAL;
-        goto out;
-    }
 
     frontend_path = libxl__device_frontend_path(gc, device);
     backend_path = libxl__device_backend_path(gc, device);
@@ -113,9 +97,8 @@ retry_transaction:
         else
             LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xs transaction failed");
     }
-    rc = 0;
-out:
-    return rc;
+
+    return 0;
 }
 
 typedef struct {
diff -r ed800095162c -r e8cff01ad4b5 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl_internal.h	Fri Sep 30 14:27:28 2011 +0100
@@ -97,25 +97,13 @@ struct libxl__ctx {
     libxl_version_info version_info;
 };
 
-typedef enum {
-    DEVICE_VIF = 1,
-    DEVICE_VBD,
-    DEVICE_QDISK,
-    DEVICE_PCI,
-    DEVICE_VFB,
-    DEVICE_VKBD,
-    DEVICE_CONSOLE,
-} libxl__device_kinds;
-
-#define is_valid_device_kind(kind) (((kind) >= DEVICE_VIF) && ((kind) <= DEVICE_CONSOLE))
-
 typedef struct {
     uint32_t backend_devid;
     uint32_t backend_domid;
     uint32_t devid;
     uint32_t domid;
-    libxl__device_kinds backend_kind;
-    libxl__device_kinds kind;
+    libxl__device_kind backend_kind;
+    libxl__device_kind kind;
 } libxl__device;
 
 #define XC_PCI_BDF             "0x%x, 0x%x, 0x%x, 0x%x"
diff -r ed800095162c -r e8cff01ad4b5 tools/libxl/libxl_pci.c
--- a/tools/libxl/libxl_pci.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl_pci.c	Fri Sep 30 14:27:28 2011 +0100
@@ -244,10 +244,10 @@ int libxl__create_pci_backend(libxl__gc 
     /* add pci device */
     device.backend_devid = 0;
     device.backend_domid = 0;
-    device.backend_kind = DEVICE_PCI;
+    device.backend_kind = LIBXL__DEVICE_KIND_PCI;
     device.devid = 0;
     device.domid = domid;
-    device.kind = DEVICE_PCI;
+    device.kind = LIBXL__DEVICE_KIND_PCI;
 
     flexarray_append_pair(back, "frontend-id", libxl__sprintf(gc, "%d", domid));
     flexarray_append_pair(back, "online", "1");
diff -r ed800095162c -r e8cff01ad4b5 tools/libxl/libxl_types_internal.idl
--- a/tools/libxl/libxl_types_internal.idl	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl_types_internal.idl	Fri Sep 30 14:27:28 2011 +0100
@@ -1,9 +1,19 @@
 namespace("libxl__")
 
-libxl__qmp_message_type  = Enumeration("qmp_message_type", [
+libxl__qmp_message_type = Enumeration("qmp_message_type", [
     (1, "QMP"),
     (2, "return"),
     (3, "error"),
     (4, "event"),
     (5, "invalid"),
     ])
+
+libxl__device_kind = Enumeration("device_kind", [
+    (1, "VIF"),
+    (2, "VBD"),
+    (3, "QDISK"),
+    (4, "PCI"),
+    (5, "VFB"),
+    (6, "VKBD"),
+    (7, "CONSOLE"),
+    ])

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 13 of 23] libxl: do not remove unidentified frontend paths in libxl__devices_destroy
  2011-09-30 13:33 [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Ian Campbell
                   ` (11 preceding siblings ...)
  2011-09-30 13:33 ` [PATCH 12 of 23] libxl: use IDL to define device front- and back-end kinds Ian Campbell
@ 2011-09-30 13:33 ` Ian Campbell
  2011-09-30 13:33 ` [PATCH 14 of 23] libxl: use libxl__device in libxl_devices_destroy and libxl__device_pci_remove_xenstore Ian Campbell
                   ` (11 subsequent siblings)
  24 siblings, 0 replies; 55+ messages in thread
From: Ian Campbell @ 2011-09-30 13:33 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig, Mike McClurg, Dave Scott, Jonathan Ludlam

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1317389248 -3600
# Node ID e5a70a3b61a1acfa7d73db548a591486024d01b7
# Parent  e8cff01ad4b5519be66e726db124cbdfab4f1e04
libxl: do not remove unidentified frontend paths in libxl__devices_destroy

Currently this appears to only include "/local/domain/<domid>/device/suspend".
Ultimately the caller will nuke the whole guest directory anyway but not having
this function remove things which don't look like devices seems less
surprising.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r e8cff01ad4b5 -r e5a70a3b61a1 tools/libxl/libxl_device.c
--- a/tools/libxl/libxl_device.c	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/libxl_device.c	Fri Sep 30 14:27:28 2011 +0100
@@ -463,8 +463,6 @@ int libxl__devices_destroy(libxl__gc *gc
                     if (libxl__device_remove(gc, be_path) > 0)
                         n_watches++;
                 }
-            } else {
-                xs_rm(ctx->xsh, XBT_NULL, path);
             }
         }
     }

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 14 of 23] libxl: use libxl__device in libxl_devices_destroy and libxl__device_pci_remove_xenstore
  2011-09-30 13:33 [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Ian Campbell
                   ` (12 preceding siblings ...)
  2011-09-30 13:33 ` [PATCH 13 of 23] libxl: do not remove unidentified frontend paths in libxl__devices_destroy Ian Campbell
@ 2011-09-30 13:33 ` Ian Campbell
  2011-10-07 12:18   ` Roger Pau Monné
  2011-09-30 13:33 ` [PATCH 15 of 23] libxl: merge libxl__device_del into libxl__device_remove Ian Campbell
                   ` (10 subsequent siblings)
  24 siblings, 1 reply; 55+ messages in thread
From: Ian Campbell @ 2011-09-30 13:33 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig, Mike McClurg, Dave Scott, Jonathan Ludlam

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1317389248 -3600
# Node ID ec28ee6dace513c3d009d498341f9537a19b2d98
# Parent  e5a70a3b61a1acfa7d73db548a591486024d01b7
libxl: use libxl__device in libxl_devices_destroy and libxl__device_pci_remove_xenstore

Doing this allows us to use the common functions for removing devices.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r e5a70a3b61a1 -r ec28ee6dace5 tools/libxl/libxl_device.c
--- a/tools/libxl/libxl_device.c	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/libxl_device.c	Fri Sep 30 14:27:28 2011 +0100
@@ -49,6 +49,25 @@ char *libxl__device_backend_path(libxl__
                           device->domid, device->devid);
 }
 
+int libxl__parse_backend_path(libxl__gc *gc,
+                              const char *path,
+                              libxl__device *dev)
+{
+    /* /local/domain/<domid>/backend/<kind>/<domid>/<devid> */
+    char strkind[16]; /* Longest is actually "console" */
+    uint32_t domain;
+    int rc = sscanf(path, "/local/domain/%d/backend/%15[^/]/%d/%d",
+                    &dev->backend_domid,
+                    strkind,
+                    &domain,
+                    &dev->backend_devid);
+
+    if (rc != 4)
+        return ERROR_FAIL;
+
+    return libxl__device_kind_from_string(strkind, &dev->backend_kind);
+}
+
 int libxl__device_generic_add(libxl__gc *gc, libxl__device *device,
                              char **bents, char **fents)
 {
@@ -348,10 +367,11 @@ int libxl__device_disk_dev_number(const 
     return -1;
 }
 
-int libxl__device_remove(libxl__gc *gc, char *be_path)
+int libxl__device_remove(libxl__gc *gc, libxl__device *dev)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
     xs_transaction_t t;
+    char *be_path = libxl__device_backend_path(gc, dev);
     char *state_path = libxl__sprintf(gc, "%s/state", be_path);
     char *state = libxl__xs_read(gc, XBT_NULL, state_path);
     int rc = 0;
@@ -429,10 +449,12 @@ static int wait_for_dev_destroy(libxl__g
 int libxl__devices_destroy(libxl__gc *gc, uint32_t domid, int force)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
-    char *path, *be_path, *fe_path;
+    char *path;
     unsigned int num1, num2;
     char **l1 = NULL, **l2 = NULL;
     int i, j, n_watches = 0;
+    libxl__device dev;
+    libxl__device_kind kind;
 
     path = libxl__sprintf(gc, "/local/domain/%d/device", domid);
     l1 = libxl__xs_directory(gc, XBT_NULL, path, &num1);
@@ -445,22 +467,27 @@ int libxl__devices_destroy(libxl__gc *gc
         num1 = 0;
     }
     for (i = 0; i < num1; i++) {
-        if (!strcmp("vfs", l1[i]))
+        if (libxl__device_kind_from_string(l1[i], &kind))
+            continue;
+        if (kind == LIBXL__DEVICE_KIND_VBD)
             continue;
         path = libxl__sprintf(gc, "/local/domain/%d/device/%s", domid, l1[i]);
         l2 = libxl__xs_directory(gc, XBT_NULL, path, &num2);
         if (!l2)
             continue;
         for (j = 0; j < num2; j++) {
-            fe_path = libxl__sprintf(gc, "/local/domain/%d/device/%s/%s", domid, l1[i], l2[j]);
-            be_path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/backend", fe_path));
-            if (be_path != NULL) {
+            path = libxl__sprintf(gc, "/local/domain/%d/device/%s/%s/backend",
+                                  domid, l1[i], l2[j]);
+            path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, path));
+            if (path && libxl__parse_backend_path(gc, path, &dev) == 0) {
+                dev.domid = domid;
+                dev.kind = kind;
+                dev.devid = atoi(l2[j]);
+
                 if (force) {
-                    xs_rm(ctx->xsh, XBT_NULL, be_path);
-                    xs_rm(ctx->xsh, XBT_NULL, fe_path);
-                    libxl__device_destroy_tapdisk(gc, be_path);
+                    libxl__device_force_remove(gc, &dev);
                 } else {
-                    if (libxl__device_remove(gc, be_path) > 0)
+                    if (libxl__device_remove(gc, &dev) > 0)
                         n_watches++;
                 }
             }
@@ -468,14 +495,18 @@ int libxl__devices_destroy(libxl__gc *gc
     }
 
     /* console 0 frontend directory is not under /local/domain/<domid>/device */
-    fe_path = libxl__sprintf(gc, "/local/domain/%d/console", domid);
-    be_path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/backend", fe_path));
-    if (be_path && strcmp(be_path, "")) {
+    path = libxl__sprintf(gc, "/local/domain/%d/console/backend", domid);
+    path = libxl__xs_read(gc, XBT_NULL, path);
+    if (path && strcmp(path, "") &&
+        libxl__parse_backend_path(gc, path, &dev) == 0) {
+        dev.domid = domid;
+        dev.kind = LIBXL__DEVICE_KIND_CONSOLE;
+        dev.devid = 0;
+
         if (force) {
-            xs_rm(ctx->xsh, XBT_NULL, be_path);
-            xs_rm(ctx->xsh, XBT_NULL, fe_path);
+            libxl__device_force_remove(gc, &dev);
         } else {
-            if (libxl__device_remove(gc, be_path) > 0)
+            if (libxl__device_remove(gc, &dev) > 0)
                 n_watches++;
         }
     }
@@ -505,12 +536,9 @@ int libxl__device_del(libxl__gc *gc, lib
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
     struct timeval tv;
-    char *backend_path;
     int rc;
 
-    backend_path = libxl__device_backend_path(gc, dev);
-
-    rc = libxl__device_remove(gc, backend_path);
+    rc = libxl__device_remove(gc, dev);
     if (rc == -1) {
         rc = ERROR_FAIL;
         goto out;
diff -r e5a70a3b61a1 -r ec28ee6dace5 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/libxl_internal.h	Fri Sep 30 14:27:28 2011 +0100
@@ -240,8 +240,10 @@ _hidden int libxl__device_generic_add(li
                              char **bents, char **fents);
 _hidden char *libxl__device_backend_path(libxl__gc *gc, libxl__device *device);
 _hidden char *libxl__device_frontend_path(libxl__gc *gc, libxl__device *device);
+_hidden int libxl__parse_backend_path(libxl__gc *gc, const char *path,
+                                      libxl__device *dev);
 _hidden int libxl__device_del(libxl__gc *gc, libxl__device *dev);
-_hidden int libxl__device_remove(libxl__gc *gc, char *be_path);
+_hidden int libxl__device_remove(libxl__gc *gc, libxl__device *dev);
 _hidden int libxl__device_force_remove(libxl__gc *gc, libxl__device *dev);
 _hidden int libxl__devices_destroy(libxl__gc *gc, uint32_t domid, int force);
 _hidden int libxl__wait_for_backend(libxl__gc *gc, char *be_path, char *state);
diff -r e5a70a3b61a1 -r ec28ee6dace5 tools/libxl/libxl_pci.c
--- a/tools/libxl/libxl_pci.c	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/libxl_pci.c	Fri Sep 30 14:27:28 2011 +0100
@@ -410,9 +410,15 @@ retry_transaction2:
             goto retry_transaction2;
 
     if (num == 1) {
-        char *fe_path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/frontend", be_path));
-        xs_rm(ctx->xsh, XBT_NULL, be_path);
-        xs_rm(ctx->xsh, XBT_NULL, fe_path);
+        libxl__device dev;
+        if (libxl__parse_backend_path(gc, be_path, &dev) != 0)
+            return ERROR_FAIL;
+
+        dev.domid = domid;
+        dev.kind = LIBXL__DEVICE_KIND_PCI;
+        dev.devid = 0;
+
+        libxl__device_force_remove(gc, &dev);
         return 0;
     }

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 15 of 23] libxl: merge libxl__device_del into libxl__device_remove
  2011-09-30 13:33 [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Ian Campbell
                   ` (13 preceding siblings ...)
  2011-09-30 13:33 ` [PATCH 14 of 23] libxl: use libxl__device in libxl_devices_destroy and libxl__device_pci_remove_xenstore Ian Campbell
@ 2011-09-30 13:33 ` Ian Campbell
  2011-09-30 13:33 ` [PATCH 16 of 23] libxl: use more descriptive variable names in libxl__devices_destroy Ian Campbell
                   ` (9 subsequent siblings)
  24 siblings, 0 replies; 55+ messages in thread
From: Ian Campbell @ 2011-09-30 13:33 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig, Mike McClurg, Dave Scott, Jonathan Ludlam

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1317389248 -3600
# Node ID 7a8cd032b63cf91d3fe04501997405d53cf5d8b3
# Parent  ec28ee6dace513c3d009d498341f9537a19b2d98
libxl: merge libxl__device_del into libxl__device_remove

Note that the "wait" parameter added to libxl_device_remove is different to the
wait paramter previously used by similar functions. In the past not-wait meant
forced whereas now in means wait for a graceful shutdown, as opposed to setting
off a graceful shutdown but not waiting.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r ec28ee6dace5 -r 7a8cd032b63c tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/libxl.c	Fri Sep 30 14:27:28 2011 +0100
@@ -1072,7 +1072,7 @@ int libxl_device_disk_del(libxl_ctx *ctx
     device.devid            = devid;
     device.kind             = LIBXL__DEVICE_KIND_VBD;
     if (wait)
-        rc = libxl__device_del(&gc, &device);
+        rc = libxl__device_remove(&gc, &device, wait);
     else
         rc = libxl__device_force_remove(&gc, &device);
 out_free:
@@ -1287,7 +1287,7 @@ int libxl_device_nic_del(libxl_ctx *ctx,
     device.kind             = LIBXL__DEVICE_KIND_VIF;
 
     if (wait)
-        rc = libxl__device_del(&gc, &device);
+        rc = libxl__device_remove(&gc, &device, wait);
     else
         rc = libxl__device_force_remove(&gc, &device);
 
diff -r ec28ee6dace5 -r 7a8cd032b63c tools/libxl/libxl_device.c
--- a/tools/libxl/libxl_device.c	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/libxl_device.c	Fri Sep 30 14:27:28 2011 +0100
@@ -367,57 +367,6 @@ int libxl__device_disk_dev_number(const 
     return -1;
 }
 
-int libxl__device_remove(libxl__gc *gc, libxl__device *dev)
-{
-    libxl_ctx *ctx = libxl__gc_owner(gc);
-    xs_transaction_t t;
-    char *be_path = libxl__device_backend_path(gc, dev);
-    char *state_path = libxl__sprintf(gc, "%s/state", be_path);
-    char *state = libxl__xs_read(gc, XBT_NULL, state_path);
-    int rc = 0;
-
-    if (!state)
-        goto out;
-    if (atoi(state) != 4) {
-        libxl__device_destroy_tapdisk(gc, be_path);
-        xs_rm(ctx->xsh, XBT_NULL, be_path);
-        goto out;
-    }
-
-retry_transaction:
-    t = xs_transaction_start(ctx->xsh);
-    xs_write(ctx->xsh, t, libxl__sprintf(gc, "%s/online", be_path), "0", strlen("0"));
-    xs_write(ctx->xsh, t, state_path, "5", strlen("5"));
-    if (!xs_transaction_end(ctx->xsh, t, 0)) {
-        if (errno == EAGAIN)
-            goto retry_transaction;
-        else {
-            rc = -1;
-            goto out;
-        }
-    }
-
-    xs_watch(ctx->xsh, state_path, be_path);
-    libxl__device_destroy_tapdisk(gc, be_path);
-    rc = 1;
-out:
-    return rc;
-}
-
-int libxl__device_force_remove(libxl__gc *gc, libxl__device *dev)
-{
-    libxl_ctx *ctx = libxl__gc_owner(gc);
-    char *be_path = libxl__device_backend_path(gc, dev);
-    char *fe_path = libxl__device_frontend_path(gc, dev);
-
-    xs_rm(ctx->xsh, XBT_NULL, be_path);
-    xs_rm(ctx->xsh, XBT_NULL, fe_path);
-
-    libxl__device_destroy_tapdisk(gc, be_path);
-
-    return 0;
-}
-
 static int wait_for_dev_destroy(libxl__gc *gc, struct timeval *tv)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
@@ -446,6 +395,67 @@ static int wait_for_dev_destroy(libxl__g
     return rc;
 }
 
+/* Returns 0 on success, ERROR_* on fail */
+int libxl__device_remove(libxl__gc *gc, libxl__device *dev, int wait)
+{
+    libxl_ctx *ctx = libxl__gc_owner(gc);
+    xs_transaction_t t;
+    char *be_path = libxl__device_backend_path(gc, dev);
+    char *state_path = libxl__sprintf(gc, "%s/state", be_path);
+    char *state = libxl__xs_read(gc, XBT_NULL, state_path);
+    int rc = 0;
+
+    if (!state)
+        goto out;
+    if (atoi(state) != 4) {
+        libxl__device_destroy_tapdisk(gc, be_path);
+        xs_rm(ctx->xsh, XBT_NULL, be_path);
+        goto out;
+    }
+
+retry_transaction:
+    t = xs_transaction_start(ctx->xsh);
+    xs_write(ctx->xsh, t, libxl__sprintf(gc, "%s/online", be_path), "0", strlen("0"));
+    xs_write(ctx->xsh, t, state_path, "5", strlen("5"));
+    if (!xs_transaction_end(ctx->xsh, t, 0)) {
+        if (errno == EAGAIN)
+            goto retry_transaction;
+        else {
+            rc = ERROR_FAIL;
+            goto out;
+        }
+    }
+
+    xs_watch(ctx->xsh, state_path, be_path);
+    libxl__device_destroy_tapdisk(gc, be_path);
+
+    if (wait) {
+        struct timeval tv;
+        tv.tv_sec = LIBXL_DESTROY_TIMEOUT;
+        tv.tv_usec = 0;
+        (void)wait_for_dev_destroy(gc, &tv);
+        xs_rm(ctx->xsh, XBT_NULL, libxl__device_frontend_path(gc, dev));
+    }
+
+    rc = 0;
+out:
+    return rc;
+}
+
+int libxl__device_force_remove(libxl__gc *gc, libxl__device *dev)
+{
+    libxl_ctx *ctx = libxl__gc_owner(gc);
+    char *be_path = libxl__device_backend_path(gc, dev);
+    char *fe_path = libxl__device_frontend_path(gc, dev);
+
+    xs_rm(ctx->xsh, XBT_NULL, be_path);
+    xs_rm(ctx->xsh, XBT_NULL, fe_path);
+
+    libxl__device_destroy_tapdisk(gc, be_path);
+
+    return 0;
+}
+
 int libxl__devices_destroy(libxl__gc *gc, uint32_t domid, int force)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
@@ -487,7 +497,7 @@ int libxl__devices_destroy(libxl__gc *gc
                 if (force) {
                     libxl__device_force_remove(gc, &dev);
                 } else {
-                    if (libxl__device_remove(gc, &dev) > 0)
+                    if (libxl__device_remove(gc, &dev, 0) == 0)
                         n_watches++;
                 }
             }
@@ -506,7 +516,7 @@ int libxl__devices_destroy(libxl__gc *gc
         if (force) {
             libxl__device_force_remove(gc, &dev);
         } else {
-            if (libxl__device_remove(gc, &dev) > 0)
+            if (libxl__device_remove(gc, &dev, 0) == 0)
                 n_watches++;
         }
     }
@@ -532,29 +542,6 @@ out:
     return 0;
 }
 
-int libxl__device_del(libxl__gc *gc, libxl__device *dev)
-{
-    libxl_ctx *ctx = libxl__gc_owner(gc);
-    struct timeval tv;
-    int rc;
-
-    rc = libxl__device_remove(gc, dev);
-    if (rc == -1) {
-        rc = ERROR_FAIL;
-        goto out;
-    }
-
-    tv.tv_sec = LIBXL_DESTROY_TIMEOUT;
-    tv.tv_usec = 0;
-    (void)wait_for_dev_destroy(gc, &tv);
-
-    xs_rm(ctx->xsh, XBT_NULL, libxl__device_frontend_path(gc, dev));
-    rc = 0;
-
-out:
-    return rc;
-}
-
 int libxl__wait_for_device_model(libxl__gc *gc,
                                  uint32_t domid, char *state,
                                  libxl__spawn_starting *spawning,
diff -r ec28ee6dace5 -r 7a8cd032b63c tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/libxl_internal.h	Fri Sep 30 14:27:28 2011 +0100
@@ -242,8 +242,7 @@ _hidden char *libxl__device_backend_path
 _hidden char *libxl__device_frontend_path(libxl__gc *gc, libxl__device *device);
 _hidden int libxl__parse_backend_path(libxl__gc *gc, const char *path,
                                       libxl__device *dev);
-_hidden int libxl__device_del(libxl__gc *gc, libxl__device *dev);
-_hidden int libxl__device_remove(libxl__gc *gc, libxl__device *dev);
+_hidden int libxl__device_remove(libxl__gc *gc, libxl__device *dev, int wait);
 _hidden int libxl__device_force_remove(libxl__gc *gc, libxl__device *dev);
 _hidden int libxl__devices_destroy(libxl__gc *gc, uint32_t domid, int force);
 _hidden int libxl__wait_for_backend(libxl__gc *gc, char *be_path, char *state);

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 16 of 23] libxl: use more descriptive variable names in libxl__devices_destroy
  2011-09-30 13:33 [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Ian Campbell
                   ` (14 preceding siblings ...)
  2011-09-30 13:33 ` [PATCH 15 of 23] libxl: merge libxl__device_del into libxl__device_remove Ian Campbell
@ 2011-09-30 13:33 ` Ian Campbell
  2011-09-30 13:33 ` [PATCH 17 of 23] libxl: convert disk handling to device API Ian Campbell
                   ` (8 subsequent siblings)
  24 siblings, 0 replies; 55+ messages in thread
From: Ian Campbell @ 2011-09-30 13:33 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig, Mike McClurg, Dave Scott, Jonathan Ludlam

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1317389248 -3600
# Node ID b3e80fe9f014f03700ca4846dde58d3473236223
# Parent  7a8cd032b63cf91d3fe04501997405d53cf5d8b3
libxl: use more descriptive variable names in libxl__devices_destroy.

It's not immediately clear that "l1" iterates over device types and "l2"
iterates over individual devices. Name things in a way which makes this more
obvious.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 7a8cd032b63c -r b3e80fe9f014 tools/libxl/libxl_device.c
--- a/tools/libxl/libxl_device.c	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/libxl_device.c	Fri Sep 30 14:27:28 2011 +0100
@@ -460,39 +460,40 @@ int libxl__devices_destroy(libxl__gc *gc
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
     char *path;
-    unsigned int num1, num2;
-    char **l1 = NULL, **l2 = NULL;
+    unsigned int num_kinds, num_devs;
+    char **kinds = NULL, **devs = NULL;
     int i, j, n_watches = 0;
     libxl__device dev;
     libxl__device_kind kind;
 
     path = libxl__sprintf(gc, "/local/domain/%d/device", domid);
-    l1 = libxl__xs_directory(gc, XBT_NULL, path, &num1);
-    if (!l1) {
+    kinds = libxl__xs_directory(gc, XBT_NULL, path, &num_kinds);
+    if (!kinds) {
         if (errno != ENOENT) {
             LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "unable to get xenstore"
                              " device listing %s", path);
             goto out;
         }
-        num1 = 0;
+        num_kinds = 0;
     }
-    for (i = 0; i < num1; i++) {
-        if (libxl__device_kind_from_string(l1[i], &kind))
+    for (i = 0; i < num_kinds; i++) {
+        if (libxl__device_kind_from_string(kinds[i], &kind))
             continue;
         if (kind == LIBXL__DEVICE_KIND_VBD)
             continue;
-        path = libxl__sprintf(gc, "/local/domain/%d/device/%s", domid, l1[i]);
-        l2 = libxl__xs_directory(gc, XBT_NULL, path, &num2);
-        if (!l2)
+
+        path = libxl__sprintf(gc, "/local/domain/%d/device/%s", domid, kinds[i]);
+        devs = libxl__xs_directory(gc, XBT_NULL, path, &num_devs);
+        if (!devs)
             continue;
-        for (j = 0; j < num2; j++) {
+        for (j = 0; j < num_devs; j++) {
             path = libxl__sprintf(gc, "/local/domain/%d/device/%s/%s/backend",
-                                  domid, l1[i], l2[j]);
+                                  domid, kinds[i], devs[j]);
             path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, path));
             if (path && libxl__parse_backend_path(gc, path, &dev) == 0) {
                 dev.domid = domid;
                 dev.kind = kind;
-                dev.devid = atoi(l2[j]);
+                dev.devid = atoi(devs[j]);
 
                 if (force) {
                     libxl__device_force_remove(gc, &dev);

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 17 of 23] libxl: convert disk handling to device API
  2011-09-30 13:33 [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Ian Campbell
                   ` (15 preceding siblings ...)
  2011-09-30 13:33 ` [PATCH 16 of 23] libxl: use more descriptive variable names in libxl__devices_destroy Ian Campbell
@ 2011-09-30 13:33 ` Ian Campbell
  2011-09-30 13:33 ` [PATCH 18 of 23] libxl: convert NIC " Ian Campbell
                   ` (7 subsequent siblings)
  24 siblings, 0 replies; 55+ messages in thread
From: Ian Campbell @ 2011-09-30 13:33 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig, Mike McClurg, Dave Scott, Jonathan Ludlam

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1317389248 -3600
# Node ID 1892dad72518f5253af2282db650cdd70c56a218
# Parent  b3e80fe9f014f03700ca4846dde58d3473236223
libxl: convert disk handling to device API

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r b3e80fe9f014 -r 1892dad72518 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/libxl.c	Fri Sep 30 14:27:28 2011 +0100
@@ -916,13 +916,58 @@ int libxl_vncviewer_exec(libxl_ctx *ctx,
 
 /******************************************************************************/
 
+int libxl_device_disk_init(libxl_ctx *ctx, libxl_device_disk *disk)
+{
+    memset(disk, 0x00, sizeof(libxl_device_disk));
+    return 0;
+}
+
+static int libxl__device_from_disk(libxl__gc *gc, uint32_t domid,
+                                   libxl_device_disk *disk,
+                                   libxl__device *device)
+{
+    libxl_ctx *ctx = libxl__gc_owner(gc);
+    int devid;
+
+    devid = libxl__device_disk_dev_number(disk->vdev, NULL, NULL);
+    if (devid==-1) {
+        LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Invalid or unsupported"
+               " virtual disk identifier %s", disk->vdev);
+        return ERROR_INVAL;
+    }
+
+    device->backend_domid = disk->backend_domid;
+    device->backend_devid = devid;
+
+    switch (disk->backend) {
+        case LIBXL_DISK_BACKEND_PHY:
+            device->backend_kind = LIBXL__DEVICE_KIND_VBD;
+            break;
+        case LIBXL_DISK_BACKEND_TAP:
+            device->backend_kind = LIBXL__DEVICE_KIND_VBD;
+            break;
+        case LIBXL_DISK_BACKEND_QDISK:
+            device->backend_kind = LIBXL__DEVICE_KIND_QDISK;
+            break;
+        default:
+            LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk backend type: %d\n",
+                       disk->backend);
+            return ERROR_INVAL;
+    }
+
+    device->domid = domid;
+    device->devid = devid;
+    device->kind  = LIBXL__DEVICE_KIND_VBD;
+
+    return 0;
+}
+
 int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk)
 {
     libxl__gc gc = LIBXL_INIT_GC(ctx);
     flexarray_t *front;
     flexarray_t *back;
     char *dev;
-    int devid;
     libxl__device device;
     int major, minor, rc;
 
@@ -947,20 +992,13 @@ int libxl_device_disk_add(libxl_ctx *ctx
         goto out_free;
     }
 
-    devid = libxl__device_disk_dev_number(disk->vdev, NULL, NULL);
-    if (devid==-1) {
+    rc = libxl__device_from_disk(&gc, domid, disk, &device);
+    if (rc != 0) {
         LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Invalid or unsupported"
                " virtual disk identifier %s", disk->vdev);
-        rc = ERROR_INVAL;
         goto out_free;
     }
 
-    device.backend_devid = devid;
-    device.backend_domid = disk->backend_domid;
-    device.devid = devid;
-    device.domid = domid;
-    device.kind = LIBXL__DEVICE_KIND_VBD;
-
     switch (disk->backend) {
         case LIBXL_DISK_BACKEND_PHY:
             dev = disk->pdev_path;
@@ -972,7 +1010,7 @@ int libxl_device_disk_add(libxl_ctx *ctx
             flexarray_append(back, "params");
             flexarray_append(back, dev);
 
-            device.backend_kind = LIBXL__DEVICE_KIND_VBD;
+            assert(device.backend_kind == LIBXL__DEVICE_KIND_VBD);
             break;
         case LIBXL_DISK_BACKEND_TAP:
             dev = libxl__blktap_devpath(&gc, disk->pdev_path, disk->format);
@@ -991,7 +1029,7 @@ int libxl_device_disk_add(libxl_ctx *ctx
             flexarray_append(back, "params");
             flexarray_append(back, libxl__sprintf(&gc, "%s:%s",
                           libxl__device_disk_string_of_format(disk->format), disk->pdev_path));
-            device.backend_kind = LIBXL__DEVICE_KIND_QDISK;
+            assert(device.backend_kind == LIBXL__DEVICE_KIND_QDISK);
             break;
         default:
             LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk backend type: %d\n", disk->backend);
@@ -1023,7 +1061,7 @@ int libxl_device_disk_add(libxl_ctx *ctx
     flexarray_append(front, "state");
     flexarray_append(front, libxl__sprintf(&gc, "%d", 1));
     flexarray_append(front, "virtual-device");
-    flexarray_append(front, libxl__sprintf(&gc, "%d", devid));
+    flexarray_append(front, libxl__sprintf(&gc, "%d", device.devid));
     flexarray_append(front, "device-type");
     flexarray_append(front, disk->is_cdrom ? "cdrom" : "disk");
 
@@ -1041,45 +1079,37 @@ out:
     return rc;
 }
 
-int libxl_device_disk_del(libxl_ctx *ctx, uint32_t domid,
-                          libxl_device_disk *disk, int wait)
+int libxl_device_disk_remove(libxl_ctx *ctx, uint32_t domid,
+                             libxl_device_disk *disk)
 {
     libxl__gc gc = LIBXL_INIT_GC(ctx);
     libxl__device device;
-    int devid, rc;
-
-    devid = libxl__device_disk_dev_number(disk->vdev, NULL, NULL);
-    device.backend_domid    = disk->backend_domid;
-    device.backend_devid    = devid;
-
-    switch (disk->backend) {
-        case LIBXL_DISK_BACKEND_PHY:
-            device.backend_kind = LIBXL__DEVICE_KIND_VBD;
-            break;
-        case LIBXL_DISK_BACKEND_TAP:
-            device.backend_kind = LIBXL__DEVICE_KIND_VBD;
-            break;
-        case LIBXL_DISK_BACKEND_QDISK:
-            device.backend_kind = LIBXL__DEVICE_KIND_QDISK;
-            break;
-        default:
-            LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk backend type: %d\n",
-                       disk->backend);
-            rc = ERROR_INVAL;
-            goto out_free;
-    }
-    device.domid            = domid;
-    device.devid            = devid;
-    device.kind             = LIBXL__DEVICE_KIND_VBD;
-    if (wait)
-        rc = libxl__device_remove(&gc, &device, wait);
-    else
-        rc = libxl__device_force_remove(&gc, &device);
-out_free:
+    int rc;
+
+    rc = libxl__device_from_disk(&gc, domid, disk, &device);
+    if (rc != 0) goto out;
+
+    rc = libxl__device_remove(&gc, &device, 1);
+out:
     libxl__free_all(&gc);
     return rc;
 }
 
+int libxl_device_disk_force_remove(libxl_ctx *ctx, uint32_t domid,
+                                   libxl_device_disk *disk)
+{
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
+    libxl__device device;
+    int rc;
+
+    rc = libxl__device_from_disk(&gc, domid, disk, &device);
+    if (rc != 0) goto out;
+
+    rc = libxl__device_force_remove(&gc, &device);
+out:
+    libxl__free_all(&gc);
+    return rc;
+}
 char * libxl_device_disk_local_attach(libxl_ctx *ctx, libxl_device_disk *disk)
 {
     libxl__gc gc = LIBXL_INIT_GC(ctx);
@@ -1623,7 +1653,7 @@ static void libxl__device_disk_from_xs_b
     unsigned int len;
     char *tmp;
 
-    memset(disk, 0, sizeof(*disk));
+    libxl_device_disk_init(ctx, disk);
 
     tmp = xs_read(ctx->xsh, XBT_NULL,
                   libxl__sprintf(gc, "%s/params", be_path), &len);
@@ -1667,7 +1697,8 @@ int libxl_devid_to_device_disk(libxl_ctx
     char *dompath, *path;
     int rc = ERROR_FAIL;
 
-    memset(disk, 0, sizeof (libxl_device_disk));
+    libxl_device_disk_init(ctx, disk);
+
     dompath = libxl__xs_get_dompath(&gc, domid);
     if (!dompath) {
         goto out;
@@ -1809,11 +1840,11 @@ int libxl_cdrom_insert(libxl_ctx *ctx, u
 
     ret = 0;
 
-    libxl_device_disk_del(ctx, domid, disks + i, 1);
+    libxl_device_disk_remove(ctx, domid, disks + i);
     libxl_device_disk_add(ctx, domid, disk);
     stubdomid = libxl_get_stubdom_id(ctx, domid);
     if (stubdomid) {
-        libxl_device_disk_del(ctx, stubdomid, disks + i, 1);
+        libxl_device_disk_remove(ctx, stubdomid, disks + i);
         libxl_device_disk_add(ctx, stubdomid, disk);
     }
 out:
diff -r b3e80fe9f014 -r 1892dad72518 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/libxl.h	Fri Sep 30 14:27:28 2011 +0100
@@ -451,15 +451,27 @@ libxl_vminfo * libxl_list_vm(libxl_ctx *
  * is used to free the members of the libxl_device_<type> data
  * type. It has no impact on the devices attached to any domain.
  */
+
+/* Disks */
+int libxl_device_disk_init(libxl_ctx *ctx, libxl_device_disk *disk);
 int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk);
-int libxl_device_disk_del(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk, int wait);
+int libxl_device_disk_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk);
+int libxl_device_disk_force_remove(libxl_ctx *ctx, uint32_t domid,
+                                   libxl_device_disk *disk);
+
 libxl_device_disk *libxl_device_disk_list(libxl_ctx *ctx, uint32_t domid, int *num);
 int libxl_device_disk_getinfo(libxl_ctx *ctx, uint32_t domid,
                               libxl_device_disk *disk, libxl_diskinfo *diskinfo);
+
+/*
+ * Insert a CD-ROM device. A device corresponding to disk must already
+ * be attached to the guest.
+ */
 int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk);
 
 /*
- * Make a disk available in this domain. Returns path to a device.
+ * Make a disk available in this (the control) domain. Returns path to
+ * a device.
  */
 char * libxl_device_disk_local_attach(libxl_ctx *ctx, libxl_device_disk *disk);
 int libxl_device_disk_local_detach(libxl_ctx *ctx, libxl_device_disk *disk);
diff -r b3e80fe9f014 -r 1892dad72518 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/xl_cmdimpl.c	Fri Sep 30 14:27:28 2011 +0100
@@ -554,7 +554,7 @@ static void parse_disk_config_multistrin
 {
     int e;
 
-    memset(disk, 0, sizeof(*disk));
+    libxl_device_disk_init(ctx, disk);
 
     if (!*config) {
         *config = xlu_cfg_init(stderr, "command line");
@@ -1953,6 +1953,8 @@ static void cd_insert(const char *dom, c
     disk.backend_domid = 0;
 
     libxl_cdrom_insert(ctx, domid, &disk);
+
+    libxl_device_disk_destroy(&disk);
     free(buf);
 }
 
@@ -4242,8 +4244,8 @@ int main_blockdetach(int argc, char **ar
         fprintf(stderr, "Error: Device %s not connected.\n", argv[optind+1]);
         return 1;
     }
-    if (libxl_device_disk_del(ctx, domid, &disk, 1)) {
-        fprintf(stderr, "libxl_device_disk_del failed.\n");
+    if (libxl_device_disk_remove(ctx, domid, &disk)) {
+        fprintf(stderr, "libxl_device_disk_remove failed.\n");
     }
     return 0;
 }

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 18 of 23] libxl: convert NIC handling to device API
  2011-09-30 13:33 [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Ian Campbell
                   ` (16 preceding siblings ...)
  2011-09-30 13:33 ` [PATCH 17 of 23] libxl: convert disk handling to device API Ian Campbell
@ 2011-09-30 13:33 ` Ian Campbell
  2011-09-30 13:33 ` [PATCH 19 of 23] libxl: remove libxl_device_console_add Ian Campbell
                   ` (6 subsequent siblings)
  24 siblings, 0 replies; 55+ messages in thread
From: Ian Campbell @ 2011-09-30 13:33 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig, Mike McClurg, Dave Scott, Jonathan Ludlam

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1317389248 -3600
# Node ID 9b58180714357f9879f7ff88a267e7d1f5dfdbb2
# Parent  1892dad72518f5253af2282db650cdd70c56a218
libxl: convert NIC handling to device API

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 1892dad72518 -r 9b5818071435 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/libxl.c	Fri Sep 30 14:27:28 2011 +0100
@@ -1184,32 +1184,46 @@ int libxl_device_disk_local_detach(libxl
 }
 
 /******************************************************************************/
-int libxl_device_nic_init(libxl_device_nic *nic_info, int devnum)
+int libxl_device_nic_init(libxl_ctx *ctx, libxl_device_nic *nic)
 {
     const uint8_t *r;
     libxl_uuid uuid;
 
     libxl_uuid_generate(&uuid);
     r = libxl_uuid_bytearray(&uuid);
-    memset(nic_info, '\0', sizeof(*nic_info));
-
-    nic_info->backend_domid = 0;
-    nic_info->devid = devnum;
-    nic_info->mtu = 1492;
-    nic_info->model = strdup("rtl8139");
-    nic_info->mac[0] = 0x00;
-    nic_info->mac[1] = 0x16;
-    nic_info->mac[2] = 0x3e;
-    nic_info->mac[3] = r[0] & 0x7f;
-    nic_info->mac[4] = r[1];
-    nic_info->mac[5] = r[2];
-    nic_info->ifname = NULL;
-    nic_info->bridge = strdup("xenbr0");
-    nic_info->ip = NULL;
-    if ( asprintf(&nic_info->script, "%s/vif-bridge",
+    memset(nic, '\0', sizeof(*nic));
+
+    nic->backend_domid = 0;
+    nic->devid = -1;
+    nic->mtu = 1492;
+    nic->model = strdup("rtl8139");
+    nic->mac[0] = 0x00;
+    nic->mac[1] = 0x16;
+    nic->mac[2] = 0x3e;
+    nic->mac[3] = r[0] & 0x7f;
+    nic->mac[4] = r[1];
+    nic->mac[5] = r[2];
+    nic->ifname = NULL;
+    nic->bridge = strdup("xenbr0");
+    nic->ip = NULL;
+    if ( asprintf(&nic->script, "%s/vif-bridge",
                libxl_xen_script_dir_path()) < 0 )
         return ERROR_FAIL;
-    nic_info->nictype = LIBXL_NIC_TYPE_IOEMU;
+    nic->nictype = LIBXL_NIC_TYPE_IOEMU;
+    return 0;
+}
+
+static int libxl__device_from_nic(libxl__gc *gc, uint32_t domid,
+                                  libxl_device_nic *nic,
+                                  libxl__device *device)
+{
+    device->backend_devid    = nic->devid;
+    device->backend_domid    = nic->backend_domid;
+    device->backend_kind     = LIBXL__DEVICE_KIND_VIF;
+    device->devid            = nic->devid;
+    device->domid            = domid;
+    device->kind             = LIBXL__DEVICE_KIND_VIF;
+
     return 0;
 }
 
@@ -1246,12 +1260,8 @@ int libxl_device_nic_add(libxl_ctx *ctx,
         }
     }
 
-    device.backend_devid = nic->devid;
-    device.backend_domid = nic->backend_domid;
-    device.backend_kind = LIBXL__DEVICE_KIND_VIF;
-    device.devid = nic->devid;
-    device.domid = domid;
-    device.kind = LIBXL__DEVICE_KIND_VIF;
+    rc = libxl__device_from_nic(&gc, domid, nic, &device);
+    if ( rc != 0 ) goto out_free;
 
     flexarray_append(back, "frontend-id");
     flexarray_append(back, libxl__sprintf(&gc, "%d", domid));
@@ -1302,29 +1312,37 @@ out:
     return rc;
 }
 
-int libxl_device_nic_del(libxl_ctx *ctx, uint32_t domid,
-                         libxl_device_nic *nic, int wait)
+int libxl_device_nic_remove(libxl_ctx *ctx, uint32_t domid,
+                            libxl_device_nic *nic)
 {
     libxl__gc gc = LIBXL_INIT_GC(ctx);
     libxl__device device;
     int rc;
 
-    device.backend_devid    = nic->devid;
-    device.backend_domid    = nic->backend_domid;
-    device.backend_kind     = LIBXL__DEVICE_KIND_VIF;
-    device.devid            = nic->devid;
-    device.domid            = domid;
-    device.kind             = LIBXL__DEVICE_KIND_VIF;
-
-    if (wait)
-        rc = libxl__device_remove(&gc, &device, wait);
-    else
-        rc = libxl__device_force_remove(&gc, &device);
-
+    rc = libxl__device_from_nic(&gc, domid, nic, &device);
+    if (rc != 0) goto out;
+
+    rc = libxl__device_remove(&gc, &device, 1);
+out:
     libxl__free_all(&gc);
     return rc;
 }
 
+int libxl_device_nic_force_remove(libxl_ctx *ctx, uint32_t domid,
+                                  libxl_device_nic *nic)
+{
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
+    libxl__device device;
+    int rc;
+
+    rc = libxl__device_from_nic(&gc, domid, nic, &device);
+    if (rc != 0) goto out;
+
+    rc = libxl__device_force_remove(&gc, &device);
+out:
+    libxl__free_all(&gc);
+    return rc;
+}
 static void libxl__device_nic_from_xs_be(libxl__gc *gc,
                                          const char *be_path,
                                          libxl_device_nic *nic)
diff -r 1892dad72518 -r 9b5818071435 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/libxl.h	Fri Sep 30 14:27:28 2011 +0100
@@ -476,9 +476,12 @@ int libxl_cdrom_insert(libxl_ctx *ctx, u
 char * libxl_device_disk_local_attach(libxl_ctx *ctx, libxl_device_disk *disk);
 int libxl_device_disk_local_detach(libxl_ctx *ctx, libxl_device_disk *disk);
 
-int libxl_device_nic_init(libxl_device_nic *nic, int dev_num);
+/* Network Interfaces */
+int libxl_device_nic_init(libxl_ctx *ctx, libxl_device_nic *nic);
 int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic);
-int libxl_device_nic_del(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic, int wait);
+int libxl_device_nic_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic);
+int libxl_device_nic_force_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic);
+
 libxl_device_nic *libxl_device_nic_list(libxl_ctx *ctx, uint32_t domid, int *num);
 int libxl_device_nic_getinfo(libxl_ctx *ctx, uint32_t domid,
                               libxl_device_nic *nic, libxl_nicinfo *nicinfo);
diff -r 1892dad72518 -r 9b5818071435 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/xl_cmdimpl.c	Fri Sep 30 14:27:28 2011 +0100
@@ -822,7 +822,8 @@ static void parse_config_data(const char
 
             d_config->vifs = (libxl_device_nic *) realloc(d_config->vifs, sizeof (libxl_device_nic) * (d_config->num_vifs+1));
             nic = d_config->vifs + d_config->num_vifs;
-            CHK_ERRNO( libxl_device_nic_init(nic, d_config->num_vifs) );
+            CHK_ERRNO( libxl_device_nic_init(ctx, nic) );
+            nic->devid = d_config->num_vifs;
 
             if (default_vifscript) {
                 free(nic->script);
@@ -4032,7 +4033,7 @@ int main_networkattach(int argc, char **
         fprintf(stderr, "%s is an invalid domain identifier\n", argv[optind]);
         return 1;
     }
-    libxl_device_nic_init(&nic, -1);
+    libxl_device_nic_init(ctx, &nic);
     for (argv += optind+1, argc -= optind+1; argc > 0; ++argv, --argc) {
         if (MATCH_OPTION("type", *argv, oparg)) {
             if (!strcmp("vif", oparg)) {
@@ -4149,7 +4150,7 @@ int main_networkdetach(int argc, char **
             return 1;
         }
     }
-    if (libxl_device_nic_del(ctx, domid, &nic, 1)) {
+    if (libxl_device_nic_remove(ctx, domid, &nic)) {
         fprintf(stderr, "libxl_device_nic_del failed.\n");
         return 1;
     }

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 19 of 23] libxl: remove libxl_device_console_add
  2011-09-30 13:33 [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Ian Campbell
                   ` (17 preceding siblings ...)
  2011-09-30 13:33 ` [PATCH 18 of 23] libxl: convert NIC " Ian Campbell
@ 2011-09-30 13:33 ` Ian Campbell
  2011-09-30 13:33 ` [PATCH 20 of 23] libxl: convert VKB handling to device API Ian Campbell
                   ` (5 subsequent siblings)
  24 siblings, 0 replies; 55+ messages in thread
From: Ian Campbell @ 2011-09-30 13:33 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig, Mike McClurg, Dave Scott, Jonathan Ludlam

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1317389248 -3600
# Node ID 51dd4ee904718c59b7a05620a4e42e9f531adf81
# Parent  9b58180714357f9879f7ff88a267e7d1f5dfdbb2
libxl: remove libxl_device_console_add.

It has no callers, the only code which adds consoles in internal to libxl and
uses libxl__device_console_add directly.

Rather than worrying about what the public API should look like in this case
simply remove it, adding new APIs is much easier than fixing broken ones...

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 9b5818071435 -r 51dd4ee90471 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/libxl.c	Fri Sep 30 14:27:28 2011 +0100
@@ -1582,18 +1582,6 @@ out:
     return rc;
 }
 
-int libxl_device_console_add(libxl_ctx *ctx, uint32_t domid,
-                              libxl_device_console *console)
-{
-    libxl__gc gc = LIBXL_INIT_GC(ctx);
-    int rc = ERROR_INVAL;
-
-    rc = libxl__device_console_add(&gc, domid, console, NULL);
-
-    libxl__free_all(&gc);
-    return rc;
-}
-
 /******************************************************************************/
 void libxl_device_vkb_init(libxl_device_vkb *vkb, int dev_num)
 {
diff -r 9b5818071435 -r 51dd4ee90471 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/libxl.h	Fri Sep 30 14:27:28 2011 +0100
@@ -486,8 +486,6 @@ libxl_device_nic *libxl_device_nic_list(
 int libxl_device_nic_getinfo(libxl_ctx *ctx, uint32_t domid,
                               libxl_device_nic *nic, libxl_nicinfo *nicinfo);
 
-int libxl_device_console_add(libxl_ctx *ctx, uint32_t domid, libxl_device_console *console);
-
 void libxl_device_vkb_init(libxl_device_vkb *vkb, int dev_num);
 int libxl_device_vkb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb);
 int libxl_device_vkb_clean_shutdown(libxl_ctx *ctx, uint32_t domid);

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 20 of 23] libxl: convert VKB handling to device API
  2011-09-30 13:33 [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Ian Campbell
                   ` (18 preceding siblings ...)
  2011-09-30 13:33 ` [PATCH 19 of 23] libxl: remove libxl_device_console_add Ian Campbell
@ 2011-09-30 13:33 ` Ian Campbell
  2011-09-30 13:33 ` [PATCH 21 " Ian Campbell
                   ` (4 subsequent siblings)
  24 siblings, 0 replies; 55+ messages in thread
From: Ian Campbell @ 2011-09-30 13:33 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig, Mike McClurg, Dave Scott, Jonathan Ludlam

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1317389248 -3600
# Node ID afe568282807e64005da85453153c89a64e3b8cd
# Parent  51dd4ee904718c59b7a05620a4e42e9f531adf81
libxl: convert VKB handling to device API

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 51dd4ee90471 -r afe568282807 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/libxl.c	Fri Sep 30 14:27:28 2011 +0100
@@ -1583,10 +1583,24 @@ out:
 }
 
 /******************************************************************************/
-void libxl_device_vkb_init(libxl_device_vkb *vkb, int dev_num)
+int libxl_device_vkb_init(libxl_ctx *ctx, libxl_device_vkb *vkb)
 {
     memset(vkb, 0x00, sizeof(libxl_device_vkb));
-    vkb->devid = dev_num;
+    return 0;
+}
+
+static int libxl__device_from_vkb(libxl__gc *gc, uint32_t domid,
+                                  libxl_device_vkb *vkb,
+                                  libxl__device *device)
+{
+    device->backend_devid = vkb->devid;
+    device->backend_domid = vkb->backend_domid;
+    device->backend_kind = LIBXL__DEVICE_KIND_VKBD;
+    device->devid = vkb->devid;
+    device->domid = domid;
+    device->kind = LIBXL__DEVICE_KIND_VKBD;
+
+    return 0;
 }
 
 int libxl_device_vkb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb)
@@ -1608,12 +1622,8 @@ int libxl_device_vkb_add(libxl_ctx *ctx,
         goto out_free;
     }
 
-    device.backend_devid = vkb->devid;
-    device.backend_domid = vkb->backend_domid;
-    device.backend_kind = LIBXL__DEVICE_KIND_VKBD;
-    device.devid = vkb->devid;
-    device.domid = domid;
-    device.kind = LIBXL__DEVICE_KIND_VKBD;
+    rc = libxl__device_from_vkb(&gc, domid, vkb, &device);
+    if (rc != 0) goto out_free;
 
     flexarray_append(back, "frontend-id");
     flexarray_append(back, libxl__sprintf(&gc, "%d", domid));
@@ -1641,14 +1651,36 @@ out:
     return rc;
 }
 
-int libxl_device_vkb_clean_shutdown(libxl_ctx *ctx, uint32_t domid)
+int libxl_device_vkb_remove(libxl_ctx *ctx, uint32_t domid,
+                            libxl_device_vkb *vkb)
 {
-    return ERROR_NI;
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
+    libxl__device device;
+    int rc;
+
+    rc = libxl__device_from_vkb(&gc, domid, vkb, &device);
+    if (rc != 0) goto out;
+
+    rc = libxl__device_remove(&gc, &device, 1);
+out:
+    libxl__free_all(&gc);
+    return rc;
 }
 
-int libxl_device_vkb_hard_shutdown(libxl_ctx *ctx, uint32_t domid)
+int libxl_device_vkb_force_remove(libxl_ctx *ctx, uint32_t domid,
+                                  libxl_device_vkb *vkb)
 {
-    return ERROR_NI;
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
+    libxl__device device;
+    int rc;
+
+    rc = libxl__device_from_vkb(&gc, domid, vkb, &device);
+    if (rc != 0) goto out;
+
+    rc = libxl__device_force_remove(&gc, &device);
+out:
+    libxl__free_all(&gc);
+    return rc;
 }
 
 static void libxl__device_disk_from_xs_be(libxl__gc *gc,
@@ -1936,16 +1968,6 @@ out:
     return rc;
 }
 
-int libxl_device_vfb_clean_shutdown(libxl_ctx *ctx, uint32_t domid)
-{
-    return ERROR_NI;
-}
-
-int libxl_device_vfb_hard_shutdown(libxl_ctx *ctx, uint32_t domid)
-{
-    return ERROR_NI;
-}
-
 /******************************************************************************/
 
 int libxl_domain_setmaxmem(libxl_ctx *ctx, uint32_t domid, uint32_t max_memkb)
diff -r 51dd4ee90471 -r afe568282807 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/libxl.h	Fri Sep 30 14:27:28 2011 +0100
@@ -486,10 +486,11 @@ libxl_device_nic *libxl_device_nic_list(
 int libxl_device_nic_getinfo(libxl_ctx *ctx, uint32_t domid,
                               libxl_device_nic *nic, libxl_nicinfo *nicinfo);
 
-void libxl_device_vkb_init(libxl_device_vkb *vkb, int dev_num);
+/* Keyboard */
+int libxl_device_vkb_init(libxl_ctx *ctx, libxl_device_vkb *vkb);
 int libxl_device_vkb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb);
-int libxl_device_vkb_clean_shutdown(libxl_ctx *ctx, uint32_t domid);
-int libxl_device_vkb_hard_shutdown(libxl_ctx *ctx, uint32_t domid);
+int libxl_device_vkb_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb);
+int libxl_device_vkb_force_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb);
 
 void libxl_device_vfb_init(libxl_device_vfb *vfb, int dev_num);
 int libxl_device_vfb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb);
diff -r 51dd4ee90471 -r afe568282807 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/xl_cmdimpl.c	Fri Sep 30 14:27:28 2011 +0100
@@ -917,7 +917,8 @@ skip:
 
             d_config->vkbs = (libxl_device_vkb *) realloc(d_config->vkbs, sizeof(libxl_device_vkb) * (d_config->num_vkbs + 1));
             vkb = d_config->vkbs + d_config->num_vkbs;
-            libxl_device_vkb_init(vkb, d_config->num_vkbs);
+            libxl_device_vkb_init(ctx, vkb);
+            vkb->devid = d_config->num_vkbs;
 
             p = strtok(buf2, ",");
             if (!p)

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 21 of 23] libxl: convert VKB handling to device API
  2011-09-30 13:33 [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Ian Campbell
                   ` (19 preceding siblings ...)
  2011-09-30 13:33 ` [PATCH 20 of 23] libxl: convert VKB handling to device API Ian Campbell
@ 2011-09-30 13:33 ` Ian Campbell
  2011-09-30 13:33 ` [PATCH 22 of 23] libxl: reorder device functions to put functions for each device together Ian Campbell
                   ` (3 subsequent siblings)
  24 siblings, 0 replies; 55+ messages in thread
From: Ian Campbell @ 2011-09-30 13:33 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig, Mike McClurg, Dave Scott, Jonathan Ludlam

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1317389248 -3600
# Node ID 73c7b1d5d8cee5fd32ca5c60dc8830dbff23eaef
# Parent  afe568282807e64005da85453153c89a64e3b8cd
libxl: convert VKB handling to device API

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r afe568282807 -r 73c7b1d5d8ce tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/libxl.c	Fri Sep 30 14:27:28 2011 +0100
@@ -1893,10 +1893,9 @@ out:
 }
 
 /******************************************************************************/
-void libxl_device_vfb_init(libxl_device_vfb *vfb, int dev_num)
+int libxl_device_vfb_init(libxl_ctx *ctx, libxl_device_vfb *vfb)
 {
     memset(vfb, 0x00, sizeof(libxl_device_vfb));
-    vfb->devid = dev_num;
     vfb->display = NULL;
     vfb->xauthority = NULL;
     vfb->vnc = 1;
@@ -1907,6 +1906,20 @@ void libxl_device_vfb_init(libxl_device_
     vfb->keymap = NULL;
     vfb->sdl = 0;
     vfb->opengl = 0;
+    return 0;
+}
+
+static int libxl__device_from_vfb(libxl__gc *gc, uint32_t domid,
+                                  libxl_device_vfb *vfb,
+                                  libxl__device *device)
+{
+    device->backend_devid = vfb->devid;
+    device->backend_domid = vfb->backend_domid;
+    device->backend_kind = LIBXL__DEVICE_KIND_VFB;
+    device->devid = vfb->devid;
+    device->domid = domid;
+    device->kind = LIBXL__DEVICE_KIND_VFB;
+    return 0;
 }
 
 int libxl_device_vfb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb)
@@ -1928,12 +1941,8 @@ int libxl_device_vfb_add(libxl_ctx *ctx,
         goto out_free;
     }
 
-    device.backend_devid = vfb->devid;
-    device.backend_domid = vfb->backend_domid;
-    device.backend_kind = LIBXL__DEVICE_KIND_VFB;
-    device.devid = vfb->devid;
-    device.domid = domid;
-    device.kind = LIBXL__DEVICE_KIND_VFB;
+    rc = libxl__device_from_vfb(&gc, domid, vfb, &device);
+    if (rc != 0) goto out_free;
 
     flexarray_append_pair(back, "frontend-id", libxl__sprintf(&gc, "%d", domid));
     flexarray_append_pair(back, "online", "1");
@@ -1968,6 +1977,38 @@ out:
     return rc;
 }
 
+int libxl_device_vfb_remove(libxl_ctx *ctx, uint32_t domid,
+                            libxl_device_vfb *vfb)
+{
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
+    libxl__device device;
+    int rc;
+
+    rc = libxl__device_from_vfb(&gc, domid, vfb, &device);
+    if (rc != 0) goto out;
+
+    rc = libxl__device_remove(&gc, &device, 1);
+out:
+    libxl__free_all(&gc);
+    return rc;
+}
+
+int libxl_device_vfb_force_remove(libxl_ctx *ctx, uint32_t domid,
+                                  libxl_device_vfb *vfb)
+{
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
+    libxl__device device;
+    int rc;
+
+    rc = libxl__device_from_vfb(&gc, domid, vfb, &device);
+    if (rc != 0) goto out;
+
+    rc = libxl__device_force_remove(&gc, &device);
+out:
+    libxl__free_all(&gc);
+    return rc;
+}
+
 /******************************************************************************/
 
 int libxl_domain_setmaxmem(libxl_ctx *ctx, uint32_t domid, uint32_t max_memkb)
diff -r afe568282807 -r 73c7b1d5d8ce tools/libxl/libxl.h
--- a/tools/libxl/libxl.h	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/libxl.h	Fri Sep 30 14:27:28 2011 +0100
@@ -492,10 +492,11 @@ int libxl_device_vkb_add(libxl_ctx *ctx,
 int libxl_device_vkb_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb);
 int libxl_device_vkb_force_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb);
 
-void libxl_device_vfb_init(libxl_device_vfb *vfb, int dev_num);
+/* Framebuffer */
+int libxl_device_vfb_init(libxl_ctx *ctx, libxl_device_vfb *vfb);
 int libxl_device_vfb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb);
-int libxl_device_vfb_clean_shutdown(libxl_ctx *ctx, uint32_t domid);
-int libxl_device_vfb_hard_shutdown(libxl_ctx *ctx, uint32_t domid);
+int libxl_device_vfb_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb);
+int libxl_device_vfb_force_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb);
 
 int libxl_device_pci_add(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev);
 int libxl_device_pci_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev, int force);
diff -r afe568282807 -r 73c7b1d5d8ce tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/xl_cmdimpl.c	Fri Sep 30 14:27:28 2011 +0100
@@ -913,7 +913,8 @@ skip:
 
             d_config->vfbs = (libxl_device_vfb *) realloc(d_config->vfbs, sizeof(libxl_device_vfb) * (d_config->num_vfbs + 1));
             vfb = d_config->vfbs + d_config->num_vfbs;
-            libxl_device_vfb_init(vfb, d_config->num_vfbs);
+            libxl_device_vfb_init(ctx, vfb);
+            vfb->devid = d_config->num_vfbs;
 
             d_config->vkbs = (libxl_device_vkb *) realloc(d_config->vkbs, sizeof(libxl_device_vkb) * (d_config->num_vkbs + 1));
             vkb = d_config->vkbs + d_config->num_vkbs;

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 22 of 23] libxl: reorder device functions to put functions for each device together
  2011-09-30 13:33 [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Ian Campbell
                   ` (20 preceding siblings ...)
  2011-09-30 13:33 ` [PATCH 21 " Ian Campbell
@ 2011-09-30 13:33 ` Ian Campbell
  2011-09-30 13:33 ` [PATCH 23 of 23] libxl: convert PCI device handling to device API Ian Campbell
                   ` (2 subsequent siblings)
  24 siblings, 0 replies; 55+ messages in thread
From: Ian Campbell @ 2011-09-30 13:33 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig, Mike McClurg, Dave Scott, Jonathan Ludlam

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1317389248 -3600
# Node ID dc967a4691d5a7e05eac3522ab78c573a084b63c
# Parent  73c7b1d5d8cee5fd32ca5c60dc8830dbff23eaef
libxl: reorder device functions to put functions for each device together.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 73c7b1d5d8ce -r dc967a4691d5 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/libxl.c	Fri Sep 30 14:27:28 2011 +0100
@@ -1110,6 +1110,216 @@ out:
     libxl__free_all(&gc);
     return rc;
 }
+
+static void libxl__device_disk_from_xs_be(libxl__gc *gc,
+                                          const char *be_path,
+                                          libxl_device_disk *disk)
+{
+    libxl_ctx *ctx = libxl__gc_owner(gc);
+    unsigned int len;
+    char *tmp;
+
+    libxl_device_disk_init(ctx, disk);
+
+    tmp = xs_read(ctx->xsh, XBT_NULL,
+                  libxl__sprintf(gc, "%s/params", be_path), &len);
+    if (tmp && strchr(tmp, ':')) {
+        disk->pdev_path = strdup(strchr(tmp, ':') + 1);
+        free(tmp);
+    } else {
+        disk->pdev_path = tmp;
+    }
+    libxl_string_to_backend(ctx,
+                        libxl__xs_read(gc, XBT_NULL,
+                                       libxl__sprintf(gc, "%s/type", be_path)),
+                        &(disk->backend));
+    disk->vdev = xs_read(ctx->xsh, XBT_NULL,
+                         libxl__sprintf(gc, "%s/dev", be_path), &len);
+    tmp = libxl__xs_read(gc, XBT_NULL, libxl__sprintf
+                         (gc, "%s/removable", be_path));
+
+    if (tmp)
+        disk->removable = atoi(tmp);
+    else
+        disk->removable = 0;
+
+    tmp = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/mode", be_path));
+    if (!strcmp(tmp, "w"))
+        disk->readwrite = 1;
+    else
+        disk->readwrite = 0;
+
+    tmp = libxl__xs_read(gc, XBT_NULL,
+                         libxl__sprintf(gc, "%s/device-type", be_path));
+    disk->is_cdrom = !strcmp(tmp, "cdrom");
+
+    disk->format = LIBXL_DISK_FORMAT_UNKNOWN;
+}
+
+int libxl_devid_to_device_disk(libxl_ctx *ctx, uint32_t domid,
+                               int devid, libxl_device_disk *disk)
+{
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
+    char *dompath, *path;
+    int rc = ERROR_FAIL;
+
+    libxl_device_disk_init(ctx, disk);
+
+    dompath = libxl__xs_get_dompath(&gc, domid);
+    if (!dompath) {
+        goto out;
+    }
+    path = libxl__xs_read(&gc, XBT_NULL,
+                          libxl__sprintf(&gc, "%s/device/vbd/%d/backend",
+                                         dompath, devid));
+    if (!path)
+        goto out;
+
+    libxl__device_disk_from_xs_be(&gc, path, disk);
+
+    rc = 0;
+out:
+    libxl__free_all(&gc);
+    return rc;
+}
+
+
+static int libxl__append_disk_list_of_type(libxl__gc *gc,
+                                           uint32_t domid,
+                                           const char *type,
+                                           libxl_device_disk **disks,
+                                           int *ndisks)
+{
+    char *be_path = NULL;
+    char **dir = NULL;
+    unsigned int n = 0;
+    libxl_device_disk *pdisk = NULL, *pdisk_end = NULL;
+
+    be_path = libxl__sprintf(gc, "%s/backend/%s/%d",
+                             libxl__xs_get_dompath(gc, 0), type, domid);
+    dir = libxl__xs_directory(gc, XBT_NULL, be_path, &n);
+    if (dir) {
+        libxl_device_disk *tmp;
+        tmp = realloc(*disks, sizeof (libxl_device_disk) * (*ndisks + n));
+        if (tmp == NULL)
+            return ERROR_NOMEM;
+        *disks = tmp;
+        pdisk = *disks + *ndisks;
+        *ndisks += n;
+        pdisk_end = *disks + *ndisks;
+        for (; pdisk < pdisk_end; pdisk++, dir++) {
+            const char *p;
+            p = libxl__sprintf(gc, "%s/%s", be_path, *dir);
+            libxl__device_disk_from_xs_be(gc, p, pdisk);
+            pdisk->backend_domid = 0;
+        }
+    }
+    return 0;
+}
+
+libxl_device_disk *libxl_device_disk_list(libxl_ctx *ctx, uint32_t domid, int *num)
+{
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
+    libxl_device_disk *disks = NULL;
+    int rc;
+
+    *num = 0;
+
+    rc = libxl__append_disk_list_of_type(&gc, domid, "vbd", &disks, num);
+    if (rc) goto out_err;
+
+    rc = libxl__append_disk_list_of_type(&gc, domid, "tap", &disks, num);
+    if (rc) goto out_err;
+
+    rc = libxl__append_disk_list_of_type(&gc, domid, "qdisk", &disks, num);
+    if (rc) goto out_err;
+
+    libxl__free_all(&gc);
+    return disks;
+
+out_err:
+    LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Unable to list disks");
+    while (disks && *num) {
+        (*num)--;
+        libxl_device_disk_destroy(&disks[*num]);
+    }
+    free(disks);
+    return NULL;
+}
+
+int libxl_device_disk_getinfo(libxl_ctx *ctx, uint32_t domid,
+                              libxl_device_disk *disk, libxl_diskinfo *diskinfo)
+{
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
+    char *dompath, *diskpath;
+    char *val;
+
+    dompath = libxl__xs_get_dompath(&gc, domid);
+    diskinfo->devid = libxl__device_disk_dev_number(disk->vdev, NULL, NULL);
+
+    /* tap devices entries in xenstore are written as vbd devices. */
+    diskpath = libxl__sprintf(&gc, "%s/device/vbd/%d", dompath, diskinfo->devid);
+    diskinfo->backend = xs_read(ctx->xsh, XBT_NULL,
+                                libxl__sprintf(&gc, "%s/backend", diskpath), NULL);
+    if (!diskinfo->backend) {
+        libxl__free_all(&gc);
+        return ERROR_FAIL;
+    }
+    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/backend-id", diskpath));
+    diskinfo->backend_id = val ? strtoul(val, NULL, 10) : -1;
+    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/state", diskpath));
+    diskinfo->state = val ? strtoul(val, NULL, 10) : -1;
+    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/event-channel", diskpath));
+    diskinfo->evtch = val ? strtoul(val, NULL, 10) : -1;
+    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/ring-ref", diskpath));
+    diskinfo->rref = val ? strtoul(val, NULL, 10) : -1;
+    diskinfo->frontend = xs_read(ctx->xsh, XBT_NULL,
+                                 libxl__sprintf(&gc, "%s/frontend", diskinfo->backend), NULL);
+    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/frontend-id", diskinfo->backend));
+    diskinfo->frontend_id = val ? strtoul(val, NULL, 10) : -1;
+
+    libxl__free_all(&gc);
+    return 0;
+}
+
+int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk)
+{
+    int num, i;
+    uint32_t stubdomid;
+    libxl_device_disk *disks;
+    int ret = ERROR_FAIL;
+
+    if (!disk->pdev_path) {
+        disk->pdev_path = strdup("");
+        disk->format = LIBXL_DISK_FORMAT_EMPTY;
+    }
+    disks = libxl_device_disk_list(ctx, domid, &num);
+    for (i = 0; i < num; i++) {
+        if (disks[i].is_cdrom && !strcmp(disk->vdev, disks[i].vdev))
+            /* found */
+            break;
+    }
+    if (i == num) {
+        LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Virtual device not found");
+        goto out;
+    }
+
+    ret = 0;
+
+    libxl_device_disk_remove(ctx, domid, disks + i);
+    libxl_device_disk_add(ctx, domid, disk);
+    stubdomid = libxl_get_stubdom_id(ctx, domid);
+    if (stubdomid) {
+        libxl_device_disk_remove(ctx, stubdomid, disks + i);
+        libxl_device_disk_add(ctx, stubdomid, disk);
+    }
+out:
+    for (i = 0; i < num; i++)
+        libxl_device_disk_destroy(&disks[i]);
+    free(disks);
+    return ret;
+}
+
 char * libxl_device_disk_local_attach(libxl_ctx *ctx, libxl_device_disk *disk)
 {
     libxl__gc gc = LIBXL_INIT_GC(ctx);
@@ -1343,6 +1553,7 @@ out:
     libxl__free_all(&gc);
     return rc;
 }
+
 static void libxl__device_nic_from_xs_be(libxl__gc *gc,
                                          const char *be_path,
                                          libxl_device_nic *nic)
@@ -1683,215 +1894,6 @@ out:
     return rc;
 }
 
-static void libxl__device_disk_from_xs_be(libxl__gc *gc,
-                                          const char *be_path,
-                                          libxl_device_disk *disk)
-{
-    libxl_ctx *ctx = libxl__gc_owner(gc);
-    unsigned int len;
-    char *tmp;
-
-    libxl_device_disk_init(ctx, disk);
-
-    tmp = xs_read(ctx->xsh, XBT_NULL,
-                  libxl__sprintf(gc, "%s/params", be_path), &len);
-    if (tmp && strchr(tmp, ':')) {
-        disk->pdev_path = strdup(strchr(tmp, ':') + 1);
-        free(tmp);
-    } else {
-        disk->pdev_path = tmp;
-    }
-    libxl_string_to_backend(ctx,
-                        libxl__xs_read(gc, XBT_NULL,
-                                       libxl__sprintf(gc, "%s/type", be_path)),
-                        &(disk->backend));
-    disk->vdev = xs_read(ctx->xsh, XBT_NULL,
-                         libxl__sprintf(gc, "%s/dev", be_path), &len);
-    tmp = libxl__xs_read(gc, XBT_NULL, libxl__sprintf
-                         (gc, "%s/removable", be_path));
-
-    if (tmp)
-        disk->removable = atoi(tmp);
-    else
-        disk->removable = 0;
-
-    tmp = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/mode", be_path));
-    if (!strcmp(tmp, "w"))
-        disk->readwrite = 1;
-    else
-        disk->readwrite = 0;
-
-    tmp = libxl__xs_read(gc, XBT_NULL,
-                         libxl__sprintf(gc, "%s/device-type", be_path));
-    disk->is_cdrom = !strcmp(tmp, "cdrom");
-
-    disk->format = LIBXL_DISK_FORMAT_UNKNOWN;
-}
-
-int libxl_devid_to_device_disk(libxl_ctx *ctx, uint32_t domid,
-                               int devid, libxl_device_disk *disk)
-{
-    libxl__gc gc = LIBXL_INIT_GC(ctx);
-    char *dompath, *path;
-    int rc = ERROR_FAIL;
-
-    libxl_device_disk_init(ctx, disk);
-
-    dompath = libxl__xs_get_dompath(&gc, domid);
-    if (!dompath) {
-        goto out;
-    }
-    path = libxl__xs_read(&gc, XBT_NULL,
-                          libxl__sprintf(&gc, "%s/device/vbd/%d/backend",
-                                         dompath, devid));
-    if (!path)
-        goto out;
-
-    libxl__device_disk_from_xs_be(&gc, path, disk);
-
-    rc = 0;
-out:
-    libxl__free_all(&gc);
-    return rc;
-}
-
-
-static int libxl__append_disk_list_of_type(libxl__gc *gc,
-                                           uint32_t domid,
-                                           const char *type,
-                                           libxl_device_disk **disks,
-                                           int *ndisks)
-{
-    char *be_path = NULL;
-    char **dir = NULL;
-    unsigned int n = 0;
-    libxl_device_disk *pdisk = NULL, *pdisk_end = NULL;
-
-    be_path = libxl__sprintf(gc, "%s/backend/%s/%d",
-                             libxl__xs_get_dompath(gc, 0), type, domid);
-    dir = libxl__xs_directory(gc, XBT_NULL, be_path, &n);
-    if (dir) {
-        libxl_device_disk *tmp;
-        tmp = realloc(*disks, sizeof (libxl_device_disk) * (*ndisks + n));
-        if (tmp == NULL)
-            return ERROR_NOMEM;
-        *disks = tmp;
-        pdisk = *disks + *ndisks;
-        *ndisks += n;
-        pdisk_end = *disks + *ndisks;
-        for (; pdisk < pdisk_end; pdisk++, dir++) {
-            const char *p;
-            p = libxl__sprintf(gc, "%s/%s", be_path, *dir);
-            libxl__device_disk_from_xs_be(gc, p, pdisk);
-            pdisk->backend_domid = 0;
-        }
-    }
-    return 0;
-}
-
-libxl_device_disk *libxl_device_disk_list(libxl_ctx *ctx, uint32_t domid, int *num)
-{
-    libxl__gc gc = LIBXL_INIT_GC(ctx);
-    libxl_device_disk *disks = NULL;
-    int rc;
-
-    *num = 0;
-
-    rc = libxl__append_disk_list_of_type(&gc, domid, "vbd", &disks, num);
-    if (rc) goto out_err;
-
-    rc = libxl__append_disk_list_of_type(&gc, domid, "tap", &disks, num);
-    if (rc) goto out_err;
-
-    rc = libxl__append_disk_list_of_type(&gc, domid, "qdisk", &disks, num);
-    if (rc) goto out_err;
-
-    libxl__free_all(&gc);
-    return disks;
-
-out_err:
-    LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Unable to list disks");
-    while (disks && *num) {
-        (*num)--;
-        libxl_device_disk_destroy(&disks[*num]);
-    }
-    free(disks);
-    return NULL;
-}
-
-int libxl_device_disk_getinfo(libxl_ctx *ctx, uint32_t domid,
-                              libxl_device_disk *disk, libxl_diskinfo *diskinfo)
-{
-    libxl__gc gc = LIBXL_INIT_GC(ctx);
-    char *dompath, *diskpath;
-    char *val;
-
-    dompath = libxl__xs_get_dompath(&gc, domid);
-    diskinfo->devid = libxl__device_disk_dev_number(disk->vdev, NULL, NULL);
-
-    /* tap devices entries in xenstore are written as vbd devices. */
-    diskpath = libxl__sprintf(&gc, "%s/device/vbd/%d", dompath, diskinfo->devid);
-    diskinfo->backend = xs_read(ctx->xsh, XBT_NULL,
-                                libxl__sprintf(&gc, "%s/backend", diskpath), NULL);
-    if (!diskinfo->backend) {
-        libxl__free_all(&gc);
-        return ERROR_FAIL;
-    }
-    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/backend-id", diskpath));
-    diskinfo->backend_id = val ? strtoul(val, NULL, 10) : -1;
-    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/state", diskpath));
-    diskinfo->state = val ? strtoul(val, NULL, 10) : -1;
-    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/event-channel", diskpath));
-    diskinfo->evtch = val ? strtoul(val, NULL, 10) : -1;
-    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/ring-ref", diskpath));
-    diskinfo->rref = val ? strtoul(val, NULL, 10) : -1;
-    diskinfo->frontend = xs_read(ctx->xsh, XBT_NULL,
-                                 libxl__sprintf(&gc, "%s/frontend", diskinfo->backend), NULL);
-    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/frontend-id", diskinfo->backend));
-    diskinfo->frontend_id = val ? strtoul(val, NULL, 10) : -1;
-
-    libxl__free_all(&gc);
-    return 0;
-}
-
-int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk)
-{
-    int num, i;
-    uint32_t stubdomid;
-    libxl_device_disk *disks;
-    int ret = ERROR_FAIL;
-
-    if (!disk->pdev_path) {
-        disk->pdev_path = strdup("");
-        disk->format = LIBXL_DISK_FORMAT_EMPTY;
-    }
-    disks = libxl_device_disk_list(ctx, domid, &num);
-    for (i = 0; i < num; i++) {
-        if (disks[i].is_cdrom && !strcmp(disk->vdev, disks[i].vdev))
-            /* found */
-            break;
-    }
-    if (i == num) {
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Virtual device not found");
-        goto out;
-    }
-
-    ret = 0;
-
-    libxl_device_disk_remove(ctx, domid, disks + i);
-    libxl_device_disk_add(ctx, domid, disk);
-    stubdomid = libxl_get_stubdom_id(ctx, domid);
-    if (stubdomid) {
-        libxl_device_disk_remove(ctx, stubdomid, disks + i);
-        libxl_device_disk_add(ctx, stubdomid, disk);
-    }
-out:
-    for (i = 0; i < num; i++)
-        libxl_device_disk_destroy(&disks[i]);
-    free(disks);
-    return ret;
-}
-
 /******************************************************************************/
 int libxl_device_vfb_init(libxl_ctx *ctx, libxl_device_vfb *vfb)
 {

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 23 of 23] libxl: convert PCI device handling to device API
  2011-09-30 13:33 [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Ian Campbell
                   ` (21 preceding siblings ...)
  2011-09-30 13:33 ` [PATCH 22 of 23] libxl: reorder device functions to put functions for each device together Ian Campbell
@ 2011-09-30 13:33 ` Ian Campbell
  2011-10-04  7:32 ` [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Roger Pau Monné
  2011-10-06 16:43 ` Ian Jackson
  24 siblings, 0 replies; 55+ messages in thread
From: Ian Campbell @ 2011-09-30 13:33 UTC (permalink / raw)
  To: xen-devel; +Cc: Jim Fehlig, Mike McClurg, Dave Scott, Jonathan Ludlam

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1317389278 -3600
# Node ID f0ab7f2102b37968da2181825ac492b14bc4b449
# Parent  dc967a4691d5a7e05eac3522ab78c573a084b63c
libxl: convert PCI device handling to device API

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r dc967a4691d5 -r f0ab7f2102b3 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/libxl.c	Fri Sep 30 14:27:58 2011 +0100
@@ -754,7 +754,7 @@ int libxl_domain_destroy(libxl_ctx *ctx,
         goto out;
     }
 
-    if (libxl_device_pci_shutdown(ctx, domid) < 0)
+    if (libxl__device_pci_force_remove_all(&gc, domid) < 0)
         LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "pci shutdown failed for domid %d", domid);
     rc = xc_domain_pause(ctx->xch, domid);
     if (rc < 0) {
diff -r dc967a4691d5 -r f0ab7f2102b3 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/libxl.h	Fri Sep 30 14:27:58 2011 +0100
@@ -498,12 +498,28 @@ int libxl_device_vfb_add(libxl_ctx *ctx,
 int libxl_device_vfb_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb);
 int libxl_device_vfb_force_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb *vfb);
 
+/* PCI Passthrough */
+int libxl_device_pci_init(libxl_ctx *ctx, libxl_device_pci *pci);
 int libxl_device_pci_add(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev);
-int libxl_device_pci_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev, int force);
-int libxl_device_pci_shutdown(libxl_ctx *ctx, uint32_t domid);
-int libxl_device_pci_list_assigned(libxl_ctx *ctx, libxl_device_pci **list, uint32_t domid, int *num);
-int libxl_device_pci_list_assignable(libxl_ctx *ctx, libxl_device_pci **list, int *num);
-int libxl_device_pci_parse_bdf(libxl_ctx *ctx, libxl_device_pci *pcidev, const char *str);
+int libxl_device_pci_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev);
+int libxl_device_pci_force_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev);
+libxl_device_pci *libxl_device_pci_list(libxl_ctx *ctx, uint32_t domid, int *num);
+
+/*
+ * Parse a PCI BDF into a PCI device structure.
+ */
+int libxl_device_pci_parse_bdf(libxl_ctx *ctx,
+                               libxl_device_pci *pcidev,
+                               const char *str);
+
+/*
+ * Similar to libxl_device_pci_list but returns all devices which
+ * could be assigned to a domain (i.e. are bound to the backend
+ * driver) but are not currently.
+ */
+libxl_device_pci *libxl_device_pci_list_assignable(libxl_ctx *ctx, int *num);
+
+/* CPUID handling */
 int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, const char* str);
 int libxl_cpuid_parse_config_xend(libxl_cpuid_policy_list *cpuid,
                                   const char* str);
diff -r dc967a4691d5 -r f0ab7f2102b3 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/libxl_internal.h	Fri Sep 30 14:27:58 2011 +0100
@@ -252,6 +252,7 @@ _hidden int libxl__wait_for_backend(libx
 _hidden int libxl__device_pci_add(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, int starting);
 _hidden int libxl__create_pci_backend(libxl__gc *gc, uint32_t domid,
                                       libxl_device_pci *pcidev, int num);
+_hidden int libxl__device_pci_force_remove_all(libxl__gc *gc, uint32_t domid);
 
 /* xl_exec */
 
diff -r dc967a4691d5 -r f0ab7f2102b3 tools/libxl/libxl_pci.c
--- a/tools/libxl/libxl_pci.c	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/libxl_pci.c	Fri Sep 30 14:27:58 2011 +0100
@@ -486,7 +486,7 @@ static int is_assigned(libxl_device_pci 
     return 0;
 }
 
-int libxl_device_pci_list_assignable(libxl_ctx *ctx, libxl_device_pci **list, int *num)
+libxl_device_pci *libxl_device_pci_list_assignable(libxl_ctx *ctx, int *num)
 {
     libxl__gc gc = LIBXL_INIT_GC(ctx);
     libxl_device_pci *pcidevs = NULL, *new, *assigned;
@@ -495,13 +495,10 @@ int libxl_device_pci_list_assignable(lib
     int rc, num_assigned;
 
     *num = 0;
-    *list = NULL;
 
     rc = get_all_assigned_devices(&gc, &assigned, &num_assigned);
-    if ( rc ) {
-        libxl__free_all(&gc);
-        return rc;
-    }
+    if ( rc )
+        goto out;
 
     dir = opendir(SYSFS_PCIBACK_DRIVER);
     if ( NULL == dir ) {
@@ -510,8 +507,7 @@ int libxl_device_pci_list_assignable(lib
         }else{
             LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "Couldn't open %s", SYSFS_PCIBACK_DRIVER);
         }
-        libxl__free_all(&gc);
-        return ERROR_FAIL;
+        goto out_closedir;
     }
 
     while( (de = readdir(dir)) ) {
@@ -534,10 +530,11 @@ int libxl_device_pci_list_assignable(lib
         (*num)++;
     }
 
+out_closedir:
     closedir(dir);
-    *list = pcidevs;
+out:
     libxl__free_all(&gc);
-    return 0;
+    return pcidevs;
 }
 
 /*
@@ -846,21 +843,25 @@ static int do_pci_remove(libxl__gc *gc, 
     int hvm = 0, rc, num;
     int stubdomid = 0;
 
-    if ( !libxl_device_pci_list_assigned(ctx, &assigned, domid, &num) ) {
-        if ( !is_assigned(assigned, num, pcidev->domain,
-                         pcidev->bus, pcidev->dev, pcidev->func) ) {
-            LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "PCI device not attached to this domain");
-            return ERROR_INVAL;
-        }
+    assigned = libxl_device_pci_list(ctx, domid, &num);
+    if ( assigned == NULL )
+        return ERROR_FAIL;
+
+    rc = ERROR_INVAL;
+    if ( !is_assigned(assigned, num, pcidev->domain,
+                      pcidev->bus, pcidev->dev, pcidev->func) ) {
+        LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "PCI device not attached to this domain");
+        goto out_fail;
     }
 
+    rc = ERROR_FAIL;
     switch (libxl__domain_type(gc, domid)) {
     case LIBXL_DOMAIN_TYPE_HVM:
         hvm = 1;
         if (libxl__wait_for_device_model(gc, domid, "running",
-                                         NULL, NULL, NULL) < 0) {
-            return ERROR_FAIL;
-        }
+                                         NULL, NULL, NULL) < 0)
+            goto out_fail;
+
         path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/state", domid);
         state = libxl__xs_read(gc, XBT_NULL, path);
         path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/parameter", domid);
@@ -879,7 +880,7 @@ static int do_pci_remove(libxl__gc *gc, 
                  * SCI, if it doesn't respond in time then we may wish to
                  * force the removal.
                  */
-                return ERROR_FAIL;
+                goto out_fail;
             }
         }
         path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/state", domid);
@@ -955,25 +956,31 @@ out:
     stubdomid = libxl_get_stubdom_id(ctx, domid);
     if (stubdomid != 0) {
         libxl_device_pci pcidev_s = *pcidev;
-        libxl_device_pci_remove(ctx, stubdomid, &pcidev_s, force);
+        if (force)
+                libxl_device_pci_force_remove(ctx, stubdomid, &pcidev_s);
+        else
+                libxl_device_pci_remove(ctx, stubdomid, &pcidev_s);
     }
 
     libxl__device_pci_remove_xenstore(gc, domid, pcidev);
 
-    return 0;
+    rc = 0;
+out_fail:
+    free(assigned);
+    return rc;
+
 }
 
-int libxl_device_pci_remove(libxl_ctx *ctx, uint32_t domid,
-                            libxl_device_pci *pcidev, int force)
+static int libxl__device_pci_remove_common(libxl__gc *gc, uint32_t domid,
+                                           libxl_device_pci *pcidev, int force)
 {
-    libxl__gc gc = LIBXL_INIT_GC(ctx);
     unsigned int orig_vdev, pfunc_mask;
     int i, rc;
 
     orig_vdev = pcidev->vdevfn & ~7U;
 
     if ( pcidev->vfunc_mask == LIBXL_PCI_FUNC_ALL ) {
-        if ( pci_multifunction_check(&gc, pcidev, &pfunc_mask) ) {
+        if ( pci_multifunction_check(gc, pcidev, &pfunc_mask) ) {
             rc = ERROR_FAIL;
             goto out;
         }
@@ -990,81 +997,118 @@ int libxl_device_pci_remove(libxl_ctx *c
             }else{
                 pcidev->vdevfn = orig_vdev;
             }
-            if ( do_pci_remove(&gc, domid, pcidev, force) )
+            if ( do_pci_remove(gc, domid, pcidev, force) )
                 rc = ERROR_FAIL;
         }
     }
 
 out:
+    return rc;
+}
+
+int libxl_device_pci_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev)
+{
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
+    int rc;
+
+    rc = libxl__device_pci_remove_common(&gc, domid, pcidev, 0);
+
     libxl__free_all(&gc);
     return rc;
 }
 
-int libxl_device_pci_list_assigned(libxl_ctx *ctx, libxl_device_pci **list, uint32_t domid, int *num)
+int libxl_device_pci_force_remove(libxl_ctx *ctx, uint32_t domid,
+                                  libxl_device_pci *pcidev)
 {
     libxl__gc gc = LIBXL_INIT_GC(ctx);
-    char *be_path, *num_devs, *xsdev, *xsvdevfn, *xsopts;
+    int rc;
+
+    rc = libxl__device_pci_remove_common(&gc, domid, pcidev, 1);
+
+    libxl__free_all(&gc);
+    return rc;
+}
+
+static void libxl__device_pci_from_xs_be(libxl__gc *gc,
+                                         const char *be_path,
+                                         libxl_device_pci *pci,
+                                         int nr)
+{
+    char *s;
+    unsigned int domain = 0, bus = 0, dev = 0, func = 0, vdevfn = 0;
+
+    s = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/dev-%d", be_path, nr));
+    sscanf(s, PCI_BDF, &domain, &bus, &dev, &func);
+
+    s = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/vdevfn-%d", be_path, nr));
+    if (s)
+        vdevfn = strtol(s, (char **) NULL, 16);
+
+    pcidev_init(pci, domain, bus, dev, func, vdevfn);
+
+    s = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/opts-%d", be_path, nr));
+    if (s) {
+        char *saveptr;
+        char *p = strtok_r(s, ",=", &saveptr);
+        do {
+            while (*p == ' ')
+                p++;
+            if (!strcmp(p, "msitranslate")) {
+                p = strtok_r(NULL, ",=", &saveptr);
+                pci->msitranslate = atoi(p);
+            } else if (!strcmp(p, "power_mgmt")) {
+                p = strtok_r(NULL, ",=", &saveptr);
+                pci->power_mgmt = atoi(p);
+            }
+        } while ((p = strtok_r(NULL, ",=", &saveptr)) != NULL);
+    }
+}
+
+libxl_device_pci *libxl_device_pci_list(libxl_ctx *ctx, uint32_t domid, int *num)
+{
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
+    char *be_path, *num_devs;
     int n, i;
-    unsigned int domain = 0, bus = 0, dev = 0, func = 0, vdevfn = 0;
-    libxl_device_pci *pcidevs;
+    libxl_device_pci *pcidevs = NULL;
+
+    *num = 0;
 
     be_path = libxl__sprintf(&gc, "%s/backend/pci/%d/0", libxl__xs_get_dompath(&gc, 0), domid);
     num_devs = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/num_devs", be_path));
-    if (!num_devs) {
-        *num = 0;
-        *list = NULL;
-        libxl__free_all(&gc);
-        return 0;
-    }
+    if (!num_devs)
+        goto out;
+
     n = atoi(num_devs);
     pcidevs = calloc(n, sizeof(libxl_device_pci));
+
+    for (i = 0; i < n; i++)
+        libxl__device_pci_from_xs_be(&gc, be_path, pcidevs + i, i);
+
     *num = n;
-
-    for (i = 0; i < n; i++) {
-        xsdev = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/dev-%d", be_path, i));
-        sscanf(xsdev, PCI_BDF, &domain, &bus, &dev, &func);
-        xsvdevfn = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/vdevfn-%d", be_path, i));
-        if (xsvdevfn)
-            vdevfn = strtol(xsvdevfn, (char **) NULL, 16);
-        pcidev_init(pcidevs + i, domain, bus, dev, func, vdevfn);
-        xsopts = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/opts-%d", be_path, i));
-        if (xsopts) {
-            char *saveptr;
-            char *p = strtok_r(xsopts, ",=", &saveptr);
-            do {
-                while (*p == ' ')
-                    p++;
-                if (!strcmp(p, "msitranslate")) {
-                    p = strtok_r(NULL, ",=", &saveptr);
-                    pcidevs[i].msitranslate = atoi(p);
-                } else if (!strcmp(p, "power_mgmt")) {
-                    p = strtok_r(NULL, ",=", &saveptr);
-                    pcidevs[i].power_mgmt = atoi(p);
-                }
-            } while ((p = strtok_r(NULL, ",=", &saveptr)) != NULL);
-        }
-    }
-    *list = pcidevs;
+out:
     libxl__free_all(&gc);
-    return 0;
+    return pcidevs;
 }
 
-int libxl_device_pci_shutdown(libxl_ctx *ctx, uint32_t domid)
+int libxl__device_pci_force_remove_all(libxl__gc *gc, uint32_t domid)
 {
+    libxl_ctx *ctx = libxl__gc_owner(gc);
     libxl_device_pci *pcidevs;
-    int num, i, rc;
+    int num, i, rc = 0;
 
-    rc = libxl_device_pci_list_assigned(ctx, &pcidevs, domid, &num);
-    if ( rc )
-        return rc;
+    pcidevs = libxl_device_pci_list(ctx, domid, &num);
+    if ( pcidevs == NULL )
+        return ERROR_FAIL;
+
     for (i = 0; i < num; i++) {
         /* Force remove on shutdown since, on HVM, qemu will not always
          * respond to SCI interrupt because the guest kernel has shut down the
          * devices by the time we even get here!
          */
-        if (libxl_device_pci_remove(ctx, domid, pcidevs + i, 1) < 0)
-            return ERROR_FAIL;
+        if (libxl_device_pci_force_remove(ctx, domid, pcidevs + i) < 0)
+            rc = ERROR_FAIL;
     }
+
     free(pcidevs);
     return 0;
 }
diff -r dc967a4691d5 -r f0ab7f2102b3 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/xl_cmdimpl.c	Fri Sep 30 14:27:58 2011 +0100
@@ -2078,11 +2078,14 @@ static void pcilist_assignable(void)
     libxl_device_pci *pcidevs;
     int num, i;
 
-    if ( libxl_device_pci_list_assignable(ctx, &pcidevs, &num) )
+    pcidevs = libxl_device_pci_list_assignable(ctx, &num);
+
+    if ( pcidevs == NULL )
         return;
     for (i = 0; i < num; i++) {
         printf("%04x:%02x:%02x.%01x\n",
-                pcidevs[i].domain, pcidevs[i].bus, pcidevs[i].dev, pcidevs[i].func);
+               pcidevs[i].domain, pcidevs[i].bus, pcidevs[i].dev, pcidevs[i].func);
+        libxl_device_pci_destroy(&pcidevs[i]);
     }
     free(pcidevs);
 }
@@ -2105,7 +2108,8 @@ static void pcilist(const char *dom)
 
     find_domain(dom);
 
-    if (libxl_device_pci_list_assigned(ctx, &pcidevs, domid, &num))
+    pcidevs = libxl_device_pci_list(ctx, domid, &num);
+    if (pcidevs == NULL)
         return;
     printf("Vdev Device\n");
     for (i = 0; i < num; i++) {
@@ -2142,7 +2146,10 @@ static void pcidetach(const char *dom, c
         fprintf(stderr, "pci-detach: malformed BDF specification \"%s\"\n", bdf);
         exit(2);
     }
-    libxl_device_pci_remove(ctx, domid, &pcidev, force);
+    if (force)
+        libxl_device_pci_force_remove(ctx, domid, &pcidev);
+    else
+        libxl_device_pci_remove(ctx, domid, &pcidev);
     libxl_device_pci_destroy(&pcidev);
 }
 
diff -r dc967a4691d5 -r f0ab7f2102b3 tools/python/xen/lowlevel/xl/xl.c
--- a/tools/python/xen/lowlevel/xl/xl.c	Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/python/xen/lowlevel/xl/xl.c	Fri Sep 30 14:27:58 2011 +0100
@@ -521,9 +521,16 @@ static PyObject *pyxl_pci_del(XlObject *
         return NULL;
     }
     pci = (Py_device_pci *)obj;
-    if ( libxl_device_pci_remove(self->ctx, domid, &pci->obj, force) ) {
-        PyErr_SetString(xl_error_obj, "cannot remove pci device");
-        return NULL;
+    if ( force ) {
+        if ( libxl_device_pci_force_remove(self->ctx, domid, &pci->obj) ) {
+            PyErr_SetString(xl_error_obj, "cannot remove pci device");
+            return NULL;
+        }
+    } else {
+        if ( libxl_device_pci_remove(self->ctx, domid, &pci->obj) ) {
+            PyErr_SetString(xl_error_obj, "cannot remove pci device");
+            return NULL;
+        }
     }
     Py_INCREF(Py_None);
     return Py_None;
@@ -558,7 +565,8 @@ static PyObject *pyxl_pci_list_assignabl
     PyObject *list;
     int nr_dev, i;
 
-    if ( libxl_device_pci_list_assignable(self->ctx, &dev, &nr_dev) ) {
+    dev = libxl_device_pci_list_assignable(self->ctx, &nr_dev);
+    if ( dev == NULL ) {
         PyErr_SetString(xl_error_obj, "Cannot list assignable devices");
         return NULL;
     }
@@ -594,7 +602,8 @@ static PyObject *pyxl_pci_list(XlObject 
     if ( !PyArg_ParseTuple(args, "i", &domid) )
         return NULL;
 
-    if ( libxl_device_pci_list_assigned(self->ctx, &dev, domid, &nr_dev) ) {
+    dev = libxl_device_pci_list(self->ctx, domid, &nr_dev);
+    if ( dev == NULL ) {
         PyErr_SetString(xl_error_obj, "Cannot list assignable devices");
         return NULL;
     }

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs
  2011-09-30 13:33 [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Ian Campbell
                   ` (22 preceding siblings ...)
  2011-09-30 13:33 ` [PATCH 23 of 23] libxl: convert PCI device handling to device API Ian Campbell
@ 2011-10-04  7:32 ` Roger Pau Monné
  2011-10-04  8:12   ` Ian Campbell
  2011-10-06 16:43 ` Ian Jackson
  24 siblings, 1 reply; 55+ messages in thread
From: Roger Pau Monné @ 2011-10-04  7:32 UTC (permalink / raw)
  To: Ian Campbell
  Cc: Jonathan Ludlam, Jim Fehlig, xen-devel, Mike McClurg, Dave Scott

I hope this patches will be applied to unstable soon, so I can rewrite
the NetBSD file disk backend with the new features introduced in the
series.

Great work, regards Roger.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs
  2011-10-04  7:32 ` [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Roger Pau Monné
@ 2011-10-04  8:12   ` Ian Campbell
  2011-10-04  8:32     ` Ian Campbell
  0 siblings, 1 reply; 55+ messages in thread
From: Ian Campbell @ 2011-10-04  8:12 UTC (permalink / raw)
  To: Roger Pau Monné
  Cc: Jonathan Ludlam, Jim Fehlig, xen-devel, Mike McClurg, Dave Scott

On Tue, 2011-10-04 at 08:32 +0100, Roger Pau Monné wrote:
> I hope this patches will be applied to unstable soon, so I can rewrite
> the NetBSD file disk backend with the new features introduced in the
> series.

What I tend to do in these cases is to import the other persons series
into the head of my own patch queue (using the mq extension) and switch
it out as new revisions are posted etc.

Ian.

> 
> Great work, regards Roger.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs
  2011-10-04  8:12   ` Ian Campbell
@ 2011-10-04  8:32     ` Ian Campbell
  2011-10-05  9:04       ` Roger Pau Monné
  0 siblings, 1 reply; 55+ messages in thread
From: Ian Campbell @ 2011-10-04  8:32 UTC (permalink / raw)
  To: Roger Pau Monné
  Cc: Jim Fehlig, xen-devel, Scott, Mike McClurg, Jonathan Ludlam

On Tue, 2011-10-04 at 09:12 +0100, Ian Campbell wrote:
> On Tue, 2011-10-04 at 08:32 +0100, Roger Pau Monné wrote:
> > I hope this patches will be applied to unstable soon, so I can rewrite
> > the NetBSD file disk backend with the new features introduced in the
> > series.
> 
> What I tend to do in these cases is to import the other persons series
> into the head of my own patch queue (using the mq extension) and switch
> it out as new revisions are posted etc.

BTW the mbox extension (http://mercurial.selenic.com/wiki/MboxExtension)
can make this a bit easier for larger series, since you can save all the
messages to an mbox and import that in one go.

I think Chris Masons mseries extension is similar too
http://oss.oracle.com/~mason/mseries/

Ian.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* RE: [PATCH 02 of 23] libxl: add a comment describing the device interfaces
  2011-09-30 13:33 ` [PATCH 02 of 23] libxl: add a comment describing the device interfaces Ian Campbell
@ 2011-10-04  8:53   ` Dave Scott
  2011-10-04  9:38     ` Ian Campbell
  0 siblings, 1 reply; 55+ messages in thread
From: Dave Scott @ 2011-10-04  8:53 UTC (permalink / raw)
  To: Ian Campbell, xen-devel; +Cc: Jim Fehlig, Mike McClurg, Jonathan Ludlam

Hi Ian,

I think the shape of this interface looks sensible.

[ snip ]
> + * libxl_device_<type>_add(ctx, domid, device):
> + *
> + *   Adds the given device to the specified domain. This can be called
> + *   while the guest is running (hotplug) or before boot (coldplug).
> + *
> + *   This function only sets up the device but does not wait for the
> + *   domain to connect to the device and therefore cannot block on the
> + *   guest.
> + *
> + *   XXX do we need a way to wait? e.g. wait_for_connect function?

I don't know about other users but xapi doesn't currently care whether a domain
has actually connected to the device (in the sense of xenstore state = 4). 
Xapi only cares about whether the device has been connected to the domain
from the host's PoV; i.e. the "virtual cable" has been plugged in and the domain
can use the device if it chooses to.

BTW Xapi's disk hotplug command will block until it gets a completion signal
from a backend udev script. While the command is in progress it holds a lock
which prevents an old xenstore watch being processed which might cause xapi
to think a async unplug has just occurred (more below)

> + *   XXX perhaps an optional way to generate an event on connect?
> + *   needs event system overhaul.
> + *
> + * libxl_device_<type>_remove(ctx, domid, device):
> + *
> + *   Removes the given device from the specified domain by performing
> + *   an orderly unplug with guest co-operation. This requires that the
> + *   guest is running.
> + *
> + *   This method is currently synchronous and therefore can block
> + *   while interacting with the guest.
> + *
> + *   XXX should provide an async version. needs event system overhaul.

Xapi normally performs a synchronous unplug, waiting for completion signaled
via a backend udev script. However if the disk is mounted inside the domain
and the blkfront signals an error ("02 - refusing to close" ISTR) then xapi
stops waiting and the synchronous unplug fails. Later when the admin inside the
guest unmounts the disk and the unplug completes, xapi's xenstore watch fires,
it grabs a lock, checks the state of xenstore and if necessary marks the disk
as unplugged.

BTW I've always thought this behaviour a little weird and I'm not attached to
it :) IMHO it would be nice to have a failed unplug request cause the whole
operation to be aborted, and not to have the device unplug later by itself.

Cheers,
Dave

^ permalink raw reply	[flat|nested] 55+ messages in thread

* RE: [PATCH 02 of 23] libxl: add a comment describing the device interfaces
  2011-10-04  8:53   ` Dave Scott
@ 2011-10-04  9:38     ` Ian Campbell
  2011-10-11 12:59       ` Roger Pau Monné
  0 siblings, 1 reply; 55+ messages in thread
From: Ian Campbell @ 2011-10-04  9:38 UTC (permalink / raw)
  To: Dave Scott; +Cc: Mike McClurg, Jim Fehlig, xen-devel, Jonathan Ludlam

On Tue, 2011-10-04 at 09:53 +0100, Dave Scott wrote:
> Hi Ian,
> 
> I think the shape of this interface looks sensible.

Thanks for taking a look.

> [ snip ]
> > + * libxl_device_<type>_add(ctx, domid, device):
> > + *
> > + *   Adds the given device to the specified domain. This can be called
> > + *   while the guest is running (hotplug) or before boot (coldplug).
> > + *
> > + *   This function only sets up the device but does not wait for the
> > + *   domain to connect to the device and therefore cannot block on the
> > + *   guest.
> > + *
> > + *   XXX do we need a way to wait? e.g. wait_for_connect function?
> 
> I don't know about other users but xapi doesn't currently care whether a domain
> has actually connected to the device (in the sense of xenstore state = 4). 
> Xapi only cares about whether the device has been connected to the domain
> from the host's PoV; i.e. the "virtual cable" has been plugged in and the domain
> can use the device if it chooses to.

That's what I was thinking too but I expressed it badly, i.e.
wait_for_backend_setup() might be a better name / concept.

> BTW Xapi's disk hotplug command will block until it gets a completion signal
> from a backend udev script. While the command is in progress it holds a lock
> which prevents an old xenstore watch being processed which might cause xapi
> to think a async unplug has just occurred (more below)
> 
> > + *   XXX perhaps an optional way to generate an event on connect?
> > + *   needs event system overhaul.
> > + *
> > + * libxl_device_<type>_remove(ctx, domid, device):
> > + *
> > + *   Removes the given device from the specified domain by performing
> > + *   an orderly unplug with guest co-operation. This requires that the
> > + *   guest is running.
> > + *
> > + *   This method is currently synchronous and therefore can block
> > + *   while interacting with the guest.
> > + *
> > + *   XXX should provide an async version. needs event system overhaul.
> 
> Xapi normally performs a synchronous unplug, waiting for completion signaled
> via a backend udev script. However if the disk is mounted inside the domain
> and the blkfront signals an error ("02 - refusing to close" ISTR) then xapi
> stops waiting and the synchronous unplug fails. Later when the admin inside the
> guest unmounts the disk and the unplug completes, xapi's xenstore watch fires,
> it grabs a lock, checks the state of xenstore and if necessary marks the disk
> as unplugged.

Is this roughly the same as doing an async unplug followed by an event
triggered by the udev script? The only difference is whether the event
happens sooner or much later? Possibly we could have a separate "unplug
deferred" style event which triggers when we notice that the guest is
refusing to unplug, so the toolstack can at least report that fact?

> 
> BTW I've always thought this behaviour a little weird and I'm not attached to
> it :) IMHO it would be nice to have a failed unplug request cause the whole
> operation to be aborted, and not to have the device unplug later by itself.

We may find our hands tied by the existing backend/frontend
implementations here, but we can see what we can do.

Ian.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs
  2011-10-04  8:32     ` Ian Campbell
@ 2011-10-05  9:04       ` Roger Pau Monné
  2011-10-05  9:33         ` Ian Campbell
  0 siblings, 1 reply; 55+ messages in thread
From: Roger Pau Monné @ 2011-10-05  9:04 UTC (permalink / raw)
  To: Ian Campbell
  Cc: Mike McClurg, Jim Fehlig, xen-devel, Jonathan Ludlam, Dave Scott

> BTW the mbox extension (http://mercurial.selenic.com/wiki/MboxExtension)
> can make this a bit easier for larger series, since you can save all the
> messages to an mbox and import that in one go.

Thanks for the suggestion, the mbox extension helps a lot to import
large series. I'm having trouble applying your patches to tip, your
libxl_utils.c seems to be different from the one present in the
xen-unstable repository, should I apply some other patches before
yours?

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs
  2011-10-05  9:04       ` Roger Pau Monné
@ 2011-10-05  9:33         ` Ian Campbell
  2011-10-05 11:59           ` Roger Pau Monné
  0 siblings, 1 reply; 55+ messages in thread
From: Ian Campbell @ 2011-10-05  9:33 UTC (permalink / raw)
  To: Roger Pau Monné
  Cc: Jim Fehlig, xen-devel, Scott, Mike McClurg, Jonathan Ludlam

On Wed, 2011-10-05 at 10:04 +0100, Roger Pau Monné wrote:
> > BTW the mbox extension (http://mercurial.selenic.com/wiki/MboxExtension)
> > can make this a bit easier for larger series, since you can save all the
> > messages to an mbox and import that in one go.
> 
> Thanks for the suggestion, the mbox extension helps a lot to import
> large series. I'm having trouble applying your patches to tip, your
> libxl_utils.c seems to be different from the one present in the
> xen-unstable repository, should I apply some other patches before
> yours?

Looks like I had two precursor patches which I thought I'd posted but
apparently I had not. I'll dig them out...

Ian.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs
  2011-10-05  9:33         ` Ian Campbell
@ 2011-10-05 11:59           ` Roger Pau Monné
  2011-10-05 13:08             ` Ian Campbell
  0 siblings, 1 reply; 55+ messages in thread
From: Roger Pau Monné @ 2011-10-05 11:59 UTC (permalink / raw)
  To: Ian Campbell
  Cc: Mike McClurg, Jim Fehlig, xen-devel, Jonathan Ludlam, Dave Scott

Hello (again),

After importing the series I realized that something is broken in
xl_cmdimpl.c, I get the following errors:

gcc -L/usr/xen42/lib   -o xl xl.o xl_cmdimpl.o xl_cmdtable.o
libxlutil.so -L/root/xen-04102011/tools/libxl/../../tools/libxl
-Wl,-rpath-link=/root/xen-04102011/tools/libxl/../../tools/libxc
-Wl,-rpath-link=/root/xen-04102011/tools/libxl/../../tools/xenstore
-lxenlight -L/root/xen-04102011/tools/libxl/../../tools/libxc
-lxenctrl
xl_cmdimpl.o: In function `parse_disk_config_multistring':
/root/xen-04102011/tools/libxl/xl_cmdimpl.c:497: undefined reference
to `libxl_device_disk_init'
xl_cmdimpl.o: In function `main_blockdetach':
/root/xen-04102011/tools/libxl/xl_cmdimpl.c:4202: undefined reference
to `libxl_device_disk_remove'
xl_cmdimpl.o: In function `main_networkdetach':
/root/xen-04102011/tools/libxl/xl_cmdimpl.c:4099: undefined reference
to `libxl_device_nic_remove'
xl_cmdimpl.o: In function `main_networklist':
/root/xen-04102011/tools/libxl/xl_cmdimpl.c:4052: undefined reference
to `libxl_device_nic_list'
/root/xen-04102011/tools/libxl/xl_cmdimpl.c:4057: undefined reference
to `libxl_device_nic_getinfo'
xl_cmdimpl.o: In function `pcidetach':
/root/xen-04102011/tools/libxl/xl_cmdimpl.c:2087: undefined reference
to `libxl_device_pci_force_remove'
xl_cmdimpl.o: In function `pcilist':
/root/xen-04102011/tools/libxl/xl_cmdimpl.c:2048: undefined reference
to `libxl_device_pci_list'
gmake: *** [xl] Error 1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH] libxl: update nic list API to use common device API style
  2011-09-30 13:33 ` [PATCH 06 of 23] libxl: update nic list API to use common device API style Ian Campbell
@ 2011-10-05 12:48   ` Roger Pau Monne
  2011-10-05 13:10     ` Ian Campbell
  0 siblings, 1 reply; 55+ messages in thread
From: Roger Pau Monne @ 2011-10-05 12:48 UTC (permalink / raw)
  To: xen-devel

libxl_device_nic_list returns an array of libxl_device_nic and
libxl_device_nic_getinfo retrieves further information.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Roger Pau Monne <roger.pau@entel.upc.edu>

diff -r 25db0629e338 -r e94763a6bd34 tools/libxl/Makefile
--- a/tools/libxl/Makefile	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/Makefile	Fri Sep 30 14:27:27 2011 +0100
@@ -119,7 +119,7 @@ libxlutil.a: $(LIBXLU_OBJS)
 	$(AR) rcs libxlutil.a $^
 
 xl: $(XL_OBJS) libxlutil.so libxenlight.so
-	$(CC) $(LDFLAGS) -o $@ $(XL_OBJS) libxlutil.so $(LDLIBS_libxenlight) $(LDLIBS_libxenctrl)
+	$(CC) $(LDFLAGS) -o $@ $(XL_OBJS) libxlutil.so libxenlight.so $(LDLIBS_libxenlight) $(LDLIBS_libxenctrl)
 
 testidl: testidl.o libxlutil.so libxenlight.so
 	$(CC) $(LDFLAGS) -o $@ testidl.o libxlutil.so $(LDLIBS_libxenlight) $(LDLIBS_libxenctrl)
diff -r 25db0629e338 -r e94763a6bd34 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl.c	Fri Sep 30 14:27:27 2011 +0100
@@ -1285,60 +1285,138 @@ int libxl_device_nic_del(libxl_ctx *ctx,
     return rc;
 }
 
-libxl_nicinfo *libxl_list_nics(libxl_ctx *ctx, uint32_t domid, unsigned int *nb)
+static void libxl__device_nic_from_xs_be(libxl__gc *gc,
+                                         const char *be_path,
+                                         libxl_device_nic *nic)
+{
+    libxl_ctx *ctx = libxl__gc_owner(gc);
+    unsigned int len;
+    char *tmp;
+    int rc;
+
+    memset(nic, 0, sizeof(*nic));
+
+    tmp = xs_read(ctx->xsh, XBT_NULL,
+                  libxl__sprintf(gc, "%s/handle", be_path), &len);
+    if ( tmp )
+        nic->devid = atoi(tmp);
+    else
+        nic->devid = 0;
+
+    /* nic->mtu = */
+
+    tmp = xs_read(ctx->xsh, XBT_NULL,
+                  libxl__sprintf(gc, "%s/mac", be_path), &len);
+    rc = libxl__parse_mac(tmp, nic->mac);
+    if (rc)
+            memset(nic->mac, 0, sizeof(nic->mac));
+
+    nic->ip = xs_read(ctx->xsh, XBT_NULL,
+                      libxl__sprintf(gc, "%s/ip", be_path), &len);
+
+    nic->bridge = xs_read(ctx->xsh, XBT_NULL,
+                      libxl__sprintf(gc, "%s/bridge", be_path), &len);
+
+    nic->script = xs_read(ctx->xsh, XBT_NULL,
+                      libxl__sprintf(gc, "%s/script", be_path), &len);
+
+    /* XXX ioemu nics are not in xenstore at all? */
+    nic->nictype = LIBXL_NIC_TYPE_VIF;
+    nic->model = NULL; /* XXX Only for TYPE_IOEMU */
+    nic->ifname = NULL; /* XXX Only for TYPE_IOEMU */
+}
+
+static int libxl__append_nic_list_of_type(libxl__gc *gc,
+                                           uint32_t domid,
+                                           const char *type,
+                                           libxl_device_nic **nics,
+                                           int *nnics)
+{
+    char *be_path = NULL;
+    char **dir = NULL;
+    unsigned int n = 0;
+    libxl_device_nic *pnic = NULL, *pnic_end = NULL;
+
+    be_path = libxl__sprintf(gc, "%s/backend/%s/%d",
+                             libxl__xs_get_dompath(gc, 0), type, domid);
+    dir = libxl__xs_directory(gc, XBT_NULL, be_path, &n);
+    if (dir) {
+        libxl_device_nic *tmp;
+        tmp = realloc(*nics, sizeof (libxl_device_nic) * (*nnics + n));
+        if (tmp == NULL)
+            return ERROR_NOMEM;
+        *nics = tmp;
+        pnic = *nics + *nnics;
+        *nnics += n;
+        pnic_end = *nics + *nnics;
+        for (; pnic < pnic_end; pnic++, dir++) {
+            const char *p;
+            p = libxl__sprintf(gc, "%s/%s", be_path, *dir);
+            libxl__device_nic_from_xs_be(gc, p, pnic);
+            pnic->backend_domid = 0;
+        }
+    }
+    return 0;
+}
+
+libxl_device_nic *libxl_device_nic_list(libxl_ctx *ctx, uint32_t domid, int *num)
 {
     libxl__gc gc = LIBXL_INIT_GC(ctx);
-    char *dompath, *nic_path_fe;
-    char **l, **list;
-    char *val, *tok;
-    unsigned int nb_nics, i;
-    libxl_nicinfo *res, *nics;
+    libxl_device_nic *nics = NULL;
+    int rc;
+
+    *num = 0;
+
+    rc = libxl__append_nic_list_of_type(&gc, domid, "vif", &nics, num);
+    if (rc) goto out_err;
+
+    libxl__free_all(&gc);
+    return nics;
+
+out_err:
+    LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Unable to list nics");
+    while (*num) {
+        (*num)--;
+        libxl_device_nic_destroy(&nics[*num]);
+    }
+    free(nics);
+    return NULL;
+}
+
+int libxl_device_nic_getinfo(libxl_ctx *ctx, uint32_t domid,
+                              libxl_device_nic *nic, libxl_nicinfo *nicinfo)
+{
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
+    char *dompath, *nicpath;
+    char *val;
 
     dompath = libxl__xs_get_dompath(&gc, domid);
-    if (!dompath)
-        goto err;
-    list = l = libxl__xs_directory(&gc, XBT_NULL,
-                           libxl__sprintf(&gc, "%s/device/vif", dompath), &nb_nics);
-    if (!l)
-        goto err;
-    nics = res = calloc(nb_nics, sizeof (libxl_nicinfo));
-    if (!res)
-        goto err;
-    for (*nb = nb_nics; nb_nics > 0; --nb_nics, ++l, ++nics) {
-        nic_path_fe = libxl__sprintf(&gc, "%s/device/vif/%s", dompath, *l);
-
-        nics->backend = xs_read(ctx->xsh, XBT_NULL,
-                                libxl__sprintf(&gc, "%s/backend", nic_path_fe), NULL);
-        val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/backend-id", nic_path_fe));
-        nics->backend_id = val ? strtoul(val, NULL, 10) : -1;
-
-        nics->devid = strtoul(*l, NULL, 10);
-        val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/state", nic_path_fe));
-        nics->state = val ? strtoul(val, NULL, 10) : -1;
-        val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/mac", nic_path_fe));
-        for (i = 0, tok = strtok(val, ":"); tok && (i < 6);
-             ++i, tok = strtok(NULL, ":")) {
-            nics->mac[i] = strtoul(tok, NULL, 16);
-        }
-        val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/event-channel", nic_path_fe));
-        nics->evtch = val ? strtol(val, NULL, 10) : -1;
-        val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/tx-ring-ref", nic_path_fe));
-        nics->rref_tx = val ? strtol(val, NULL, 10) : -1;
-        val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/rx-ring-ref", nic_path_fe));
-        nics->rref_rx = val ? strtol(val, NULL, 10) : -1;
-        nics->frontend = xs_read(ctx->xsh, XBT_NULL,
-                                 libxl__sprintf(&gc, "%s/frontend", nics->backend), NULL);
-        val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/frontend-id", nics->backend));
-        nics->frontend_id = val ? strtoul(val, NULL, 10) : -1;
-        nics->script = xs_read(ctx->xsh, XBT_NULL,
-                               libxl__sprintf(&gc, "%s/script", nics->backend), NULL);
+    nicinfo->devid = nic->devid;
+
+    nicpath = libxl__sprintf(&gc, "%s/device/vif/%d", dompath, nicinfo->devid);
+    nicinfo->backend = xs_read(ctx->xsh, XBT_NULL,
+                                libxl__sprintf(&gc, "%s/backend", nicpath), NULL);
+    if (!nicinfo->backend) {
+        libxl__free_all(&gc);
+        return ERROR_FAIL;
     }
+    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/backend-id", nicpath));
+    nicinfo->backend_id = val ? strtoul(val, NULL, 10) : -1;
+    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/state", nicpath));
+    nicinfo->state = val ? strtoul(val, NULL, 10) : -1;
+    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/event-channel", nicpath));
+    nicinfo->evtch = val ? strtoul(val, NULL, 10) : -1;
+    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/tx-ring-ref", nicpath));
+    nicinfo->rref_tx = val ? strtoul(val, NULL, 10) : -1;
+    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/rx-ring-ref", nicpath));
+    nicinfo->rref_rx = val ? strtoul(val, NULL, 10) : -1;
+    nicinfo->frontend = xs_read(ctx->xsh, XBT_NULL,
+                                 libxl__sprintf(&gc, "%s/frontend", nicinfo->backend), NULL);
+    val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/frontend-id", nicinfo->backend));
+    nicinfo->frontend_id = val ? strtoul(val, NULL, 10) : -1;
 
     libxl__free_all(&gc);
-    return res;
-err:
-    libxl__free_all(&gc);
-    return NULL;
+    return 0;
 }
 
 /******************************************************************************/
diff -r 25db0629e338 -r e94763a6bd34 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl.h	Fri Sep 30 14:27:27 2011 +0100
@@ -467,7 +467,9 @@ int libxl_device_disk_local_detach(libxl
 int libxl_device_nic_init(libxl_device_nic *nic, int dev_num);
 int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic);
 int libxl_device_nic_del(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic, int wait);
-libxl_nicinfo *libxl_list_nics(libxl_ctx *ctx, uint32_t domid, unsigned int *nb);
+libxl_device_nic *libxl_device_nic_list(libxl_ctx *ctx, uint32_t domid, int *num);
+int libxl_device_nic_getinfo(libxl_ctx *ctx, uint32_t domid,
+                              libxl_device_nic *nic, libxl_nicinfo *nicinfo);
 
 int libxl_device_console_add(libxl_ctx *ctx, uint32_t domid, libxl_device_console *console);
 
diff -r 25db0629e338 -r e94763a6bd34 tools/libxl/libxl_types.idl
--- a/tools/libxl/libxl_types.idl	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl_types.idl	Fri Sep 30 14:27:27 2011 +0100
@@ -330,8 +330,6 @@ libxl_nicinfo = Struct("nicinfo", [
     ("frontend_id", uint32),
     ("devid", integer),
     ("state", integer),
-    ("script", string),
-    ("mac", libxl_mac),
     ("evtch", integer),
     ("rref_tx", integer),
     ("rref_rx", integer),
diff -r 25db0629e338 -r e94763a6bd34 tools/libxl/libxl_utils.c
--- a/tools/libxl/libxl_utils.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/libxl_utils.c	Fri Sep 30 14:27:27 2011 +0100
@@ -451,15 +451,15 @@ int libxl_pipe(libxl_ctx *ctx, int pipes
 int libxl_mac_to_device_nic(libxl_ctx *ctx, uint32_t domid,
                             const char *mac, libxl_device_nic *nic)
 {
-    libxl_nicinfo *nics;
-    unsigned int nb, rc, i;
+    libxl_device_nic *nics;
+    int nb, rc, i;
     libxl_mac mac_n;
 
     rc = libxl__parse_mac(mac, mac_n);
     if (rc)
         return rc;
 
-    nics = libxl_list_nics(ctx, domid, &nb);
+    nics = libxl_device_nic_list(ctx, domid, &nb);
     if (!nics)
         return ERROR_FAIL;
 
@@ -468,17 +468,17 @@ int libxl_mac_to_device_nic(libxl_ctx *c
     rc = ERROR_INVAL;
     for (i = 0; i < nb; ++i) {
         if (!libxl__compare_macs(&mac_n, &nics[i].mac)) {
-            nic->backend_domid = nics[i].backend_id;
-            nic->devid = nics[i].devid;
-            memcpy(nic->mac, nics[i].mac, sizeof (nic->mac));
-            nic->script = strdup(nics[i].script);
+            *nic = nics[i];
             rc = 0;
+            i++; /* Do not destroy this NIC on exit path */
             break;
         }
+        libxl_device_nic_destroy(&nics[i]);
     }
 
-    for (i=0; i<nb; i++)
-        libxl_nicinfo_destroy(&nics[i]);
+    for (; i<nb; i++)
+        libxl_device_nic_destroy(&nics[i]);
+
     free(nics);
     return rc;
 }
diff -r 25db0629e338 -r e94763a6bd34 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c	Fri Sep 30 14:27:27 2011 +0100
+++ b/tools/libxl/xl_cmdimpl.c	Fri Sep 30 14:27:27 2011 +0100
@@ -4022,8 +4022,9 @@ int main_networkattach(int argc, char **
 int main_networklist(int argc, char **argv)
 {
     int opt;
-    libxl_nicinfo *nics;
-    unsigned int nb, i;
+    libxl_device_nic *nics;
+    libxl_nicinfo nicinfo;
+    int nb, i;
 
     if ((opt = def_getopt(argc, argv, "", "network-list", 1)) != -1)
         return opt;
@@ -4036,19 +4037,23 @@ int main_networklist(int argc, char **ar
             fprintf(stderr, "%s is an invalid domain identifier\n", *argv);
             continue;
         }
-        if (!(nics = libxl_list_nics(ctx, domid, &nb))) {
+        nics = libxl_device_nic_list(ctx, domid, &nb);
+        if (!nics) {
             continue;
         }
         for (i = 0; i < nb; ++i) {
-            /* Idx BE */
-            printf("%-3d %-2d ", nics[i].devid, nics[i].backend_id);
-            /* MAC */
-            printf(LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nics[i].mac));
-            /* Hdl  Sta  evch txr/rxr  BE-path */
-            printf("%6d %5d %6d %5d/%-11d %-30s\n",
-                   nics[i].devid, nics[i].state, nics[i].evtch,
-                   nics[i].rref_tx, nics[i].rref_rx, nics[i].backend);
-            libxl_nicinfo_destroy(&nics[i]);
+            if (!libxl_device_nic_getinfo(ctx, domid, &nics[i], &nicinfo)) {
+                /* Idx BE */
+                printf("%-3d %-2d ", nicinfo.devid, nicinfo.backend_id);
+                /* MAC */
+                printf(LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nics[i].mac));
+                /* Hdl  Sta  evch txr/rxr  BE-path */
+                printf("%6d %5d %6d %5d/%-11d %-30s\n",
+                       nicinfo.devid, nicinfo.state, nicinfo.evtch,
+                       nicinfo.rref_tx, nicinfo.rref_rx, nicinfo.backend);
+                libxl_nicinfo_destroy(&nicinfo);
+            }
+            libxl_device_nic_destroy(&nics[i]);
         }
         free(nics);
     }

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs
  2011-10-05 11:59           ` Roger Pau Monné
@ 2011-10-05 13:08             ` Ian Campbell
  2011-10-05 13:15               ` Roger Pau Monné
  0 siblings, 1 reply; 55+ messages in thread
From: Ian Campbell @ 2011-10-05 13:08 UTC (permalink / raw)
  To: Roger Pau Monné
  Cc: Jim Fehlig, xen-devel, Scott, Mike McClurg, Jonathan Ludlam

On Wed, 2011-10-05 at 12:59 +0100, Roger Pau Monné wrote:
> Hello (again),
> 
> After importing the series I realized that something is broken in
> xl_cmdimpl.c, I get the following errors:
> 
> gcc -L/usr/xen42/lib   -o xl xl.o xl_cmdimpl.o xl_cmdtable.o
> libxlutil.so -L/root/xen-04102011/tools/libxl/../../tools/libxl
> -Wl,-rpath-link=/root/xen-04102011/tools/libxl/../../tools/libxc
> -Wl,-rpath-link=/root/xen-04102011/tools/libxl/../../tools/xenstore
> -lxenlight -L/root/xen-04102011/tools/libxl/../../tools/libxc
> -lxenctrl
> xl_cmdimpl.o: In function `parse_disk_config_multistring':
> /root/xen-04102011/tools/libxl/xl_cmdimpl.c:497: undefined reference
> to `libxl_device_disk_init'

This function was added by "libxl: convert disk handling to device
API" (patch #17/23). The others were generally added by the "convert XXX
handling to ..." patches.

I suspect that the -L/usr/xen42/lib in your link line has caused it to
try and link against the installed libxenlight.so and not the just built
one. My link line does not include this, it is just:
gcc    -o xl xl.o xl_cmdimpl.o xl_cmdtable.o libxlutil.so
-L/local/scratch/ianc/devel/xen-unstable.hg/tools/libxl/../../tools/libxl -Wl,-rpath-link=/local/scratch/ianc/devel/xen-unstable.hg/tools/libxl/../../tools/libxc -Wl,-rpath-link=/local/scratch/ianc/devel/xen-unstable.hg/tools/libxl/../../tools/xenstore -Wl,-rpath-link=/local/scratch/ianc/devel/xen-unstable.hg/tools/libxl/../../tools/blktap2/control -lxenlight -L/local/scratch/ianc/devel/xen-unstable.hg/tools/libxl/../../tools/libxc -lxenctrl

SO I guess you have LDFLAGS=-L/usr/xen42/lib -- what is that for? It
should not be necessary when building Xen itself.

> xl_cmdimpl.o: In function `main_blockdetach':
> /root/xen-04102011/tools/libxl/xl_cmdimpl.c:4202: undefined reference
> to `libxl_device_disk_remove'
> xl_cmdimpl.o: In function `main_networkdetach':
> /root/xen-04102011/tools/libxl/xl_cmdimpl.c:4099: undefined reference
> to `libxl_device_nic_remove'
> xl_cmdimpl.o: In function `main_networklist':
> /root/xen-04102011/tools/libxl/xl_cmdimpl.c:4052: undefined reference
> to `libxl_device_nic_list'
> /root/xen-04102011/tools/libxl/xl_cmdimpl.c:4057: undefined reference
> to `libxl_device_nic_getinfo'
> xl_cmdimpl.o: In function `pcidetach':
> /root/xen-04102011/tools/libxl/xl_cmdimpl.c:2087: undefined reference
> to `libxl_device_pci_force_remove'
> xl_cmdimpl.o: In function `pcilist':
> /root/xen-04102011/tools/libxl/xl_cmdimpl.c:2048: undefined reference
> to `libxl_device_pci_list'
> gmake: *** [xl] Error 1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH] libxl: update nic list API to use common device API style
  2011-10-05 12:48   ` [PATCH] " Roger Pau Monne
@ 2011-10-05 13:10     ` Ian Campbell
  2011-10-05 13:22       ` Roger Pau Monné
  0 siblings, 1 reply; 55+ messages in thread
From: Ian Campbell @ 2011-10-05 13:10 UTC (permalink / raw)
  To: Roger Pau Monne; +Cc: xen-devel

(I assume everything but the following hunk was a mistake)

> diff -r 25db0629e338 -r e94763a6bd34 tools/libxl/Makefile
> --- a/tools/libxl/Makefile      Fri Sep 30 14:27:27 2011 +0100
> +++ b/tools/libxl/Makefile      Fri Sep 30 14:27:27 2011 +0100
> @@ -119,7 +119,7 @@ libxlutil.a: $(LIBXLU_OBJS)
>         $(AR) rcs libxlutil.a $^
> 
>  xl: $(XL_OBJS) libxlutil.so libxenlight.so
> -       $(CC) $(LDFLAGS) -o $@ $(XL_OBJS) libxlutil.so $(LDLIBS_libxenlight) $(LDLIBS_libxenctrl)
> +       $(CC) $(LDFLAGS) -o $@ $(XL_OBJS) libxlutil.so libxenlight.so $(LDLIBS_libxenlight) $(LDLIBS_libxenctrl)
> 
>  testidl: testidl.o libxlutil.so libxenlight.so
>         $(CC) $(LDFLAGS) -o $@ testidl.o libxlutil.so $(LDLIBS_libxenlight) $(LDLIBS_libxenctrl)

LDLIBS_libxenlight already has -lxenlight in it. I guess this changes
works around you local addition LDFLAGS=-L/usr/xen42/lib?

I'm not sure what the right answer is here.

Ian.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs
  2011-10-05 13:08             ` Ian Campbell
@ 2011-10-05 13:15               ` Roger Pau Monné
  0 siblings, 0 replies; 55+ messages in thread
From: Roger Pau Monné @ 2011-10-05 13:15 UTC (permalink / raw)
  To: Ian Campbell
  Cc: Mike McClurg, Jim Fehlig, xen-devel, Jonathan Ludlam, Dave Scott

>> gcc -L/usr/xen42/lib   -o xl xl.o xl_cmdimpl.o xl_cmdtable.o
>> libxlutil.so -L/root/xen-04102011/tools/libxl/../../tools/libxl
>> -Wl,-rpath-link=/root/xen-04102011/tools/libxl/../../tools/libxc
>> -Wl,-rpath-link=/root/xen-04102011/tools/libxl/../../tools/xenstore
>> -lxenlight -L/root/xen-04102011/tools/libxl/../../tools/libxc
>> -lxenctrl
>> xl_cmdimpl.o: In function `parse_disk_config_multistring':
>> /root/xen-04102011/tools/libxl/xl_cmdimpl.c:497: undefined reference
>> to `libxl_device_disk_init'
>
> This function was added by "libxl: convert disk handling to device
> API" (patch #17/23). The others were generally added by the "convert XXX
> handling to ..." patches.
>
> I suspect that the -L/usr/xen42/lib in your link line has caused it to
> try and link against the installed libxenlight.so and not the just built
> one. My link line does not include this, it is just:
> gcc    -o xl xl.o xl_cmdimpl.o xl_cmdtable.o libxlutil.so
> -L/local/scratch/ianc/devel/xen-unstable.hg/tools/libxl/../../tools/libxl -Wl,-rpath-link=/local/scratch/ianc/devel/xen-unstable.hg/tools/libxl/../../tools/libxc -Wl,-rpath-link=/local/scratch/ianc/devel/xen-unstable.hg/tools/libxl/../../tools/xenstore -Wl,-rpath-link=/local/scratch/ianc/devel/xen-unstable.hg/tools/libxl/../../tools/blktap2/control -lxenlight -L/local/scratch/ianc/devel/xen-unstable.hg/tools/libxl/../../tools/libxc -lxenctrl
>
> SO I guess you have LDFLAGS=-L/usr/xen42/lib -- what is that for? It
> should not be necessary when building Xen itself.

The -L/usr/xen42/lib is for yajl, the problem was that it was missing
libxenlight.so, so it could not link to the proper functions (or it
was trying to use the old library from /usr/xen42/lib instead of the
new one). I've modified a patch in your series to include
libxenligh.so when compiling xl.

Now I have a similar problem, and I think it's because Xen is trying
to use the old header files and libraries in /usr/xen42/ instead of
the new ones.

gcc -O2 -g -DHAVE_DB_185_H -I/usr/include -I/usr/pkg/include
-I/usr/xen42/include -O1 -fno-omit-frame-pointer -m64 -g
-fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes
-Wno-unused-value -Wdeclaration-after-statement -O1
-fno-omit-frame-pointer -m64 -g -fno-strict-aliasing -std=gnu99 -Wall
-Wstrict-prototypes -Wno-unused-value -Wdeclaration-after-statement
-O1 -fno-omit-frame-pointer -m64 -g -fno-strict-aliasing -std=gnu99
-Wall -Wstrict-prototypes -Wno-unused-value
-Wdeclaration-after-statement -D__XEN_TOOLS__ -MMD -MF
.subdirs-install.d -fno-optimize-sibling-calls -O1
-fno-omit-frame-pointer -m64 -g -fno-strict-aliasing -std=gnu99 -Wall
-Wstrict-prototypes -Wno-unused-value -Wdeclaration-after-statement
-D__XEN_TOOLS__ -MMD -MF .subdir-install-python.d
-fno-optimize-sibling-calls -O1 -fno-omit-frame-pointer -m64 -g
-fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes
-Wno-unused-value -Wdeclaration-after-statement -D__XEN_TOOLS__ -MMD
-MF .build.d -fno-optimize-sibling-calls -fPIC -I../../tools/include
-I../../tools/libxl -I../../tools/libxc -Ixen/lowlevel/xl
-I/usr/pkg/include/python2.6 -c xen/lowlevel/xl/xl.c -o
build/temp.netbsd-5.99.52-amd64-2.6-pydebug/xen/lowlevel/xl/xl.o
-fno-strict-aliasing -Werror
cc1: warnings being treated as errors
xen/lowlevel/xl/xl.c: In function 'pyxl_pci_del':
xen/lowlevel/xl/xl.c:525: warning: implicit declaration of function
'libxl_device_pci_force_remove'
xen/lowlevel/xl/xl.c:530: error: too few arguments to function
'libxl_device_pci_remove'
xen/lowlevel/xl/xl.c: In function 'pyxl_pci_list_assignable':
xen/lowlevel/xl/xl.c:568: warning: passing argument 2 of
'libxl_device_pci_list_assignable' from incompatible pointer type
xen/lowlevel/xl/xl.c:568: error: too few arguments to function
'libxl_device_pci_list_assignable'
xen/lowlevel/xl/xl.c: In function 'pyxl_pci_list':
xen/lowlevel/xl/xl.c:605: warning: implicit declaration of function
'libxl_device_pci_list'
xen/lowlevel/xl/xl.c:605: warning: assignment makes pointer from
integer without a cast
error: command 'gcc' failed with exit status 1

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH] libxl: update nic list API to use common device API style
  2011-10-05 13:10     ` Ian Campbell
@ 2011-10-05 13:22       ` Roger Pau Monné
  2011-10-05 13:42         ` Ian Campbell
  0 siblings, 1 reply; 55+ messages in thread
From: Roger Pau Monné @ 2011-10-05 13:22 UTC (permalink / raw)
  To: Ian Campbell; +Cc: xen-devel

2011/10/5 Ian Campbell <Ian.Campbell@citrix.com>:
> (I assume everything but the following hunk was a mistake)

I modified your patch and resubmitted it (sorry if that's not ok),
since this is the first place where new functions are added to libxl.

>
>> diff -r 25db0629e338 -r e94763a6bd34 tools/libxl/Makefile
>> --- a/tools/libxl/Makefile      Fri Sep 30 14:27:27 2011 +0100
>> +++ b/tools/libxl/Makefile      Fri Sep 30 14:27:27 2011 +0100
>> @@ -119,7 +119,7 @@ libxlutil.a: $(LIBXLU_OBJS)
>>         $(AR) rcs libxlutil.a $^
>>
>>  xl: $(XL_OBJS) libxlutil.so libxenlight.so
>> -       $(CC) $(LDFLAGS) -o $@ $(XL_OBJS) libxlutil.so $(LDLIBS_libxenlight) $(LDLIBS_libxenctrl)
>> +       $(CC) $(LDFLAGS) -o $@ $(XL_OBJS) libxlutil.so libxenlight.so $(LDLIBS_libxenlight) $(LDLIBS_libxenctrl)
>>
>>  testidl: testidl.o libxlutil.so libxenlight.so
>>         $(CC) $(LDFLAGS) -o $@ testidl.o libxlutil.so $(LDLIBS_libxenlight) $(LDLIBS_libxenctrl)
>
> LDLIBS_libxenlight already has -lxenlight in it. I guess this changes
> works around you local addition LDFLAGS=-L/usr/xen42/lib?
>
> I'm not sure what the right answer is here.

Neither do I, I'm not an expert on build processes, but if I need to
append CFLAGS and LDFLAGS to the build process to find my yajl library
libxl should not try to use the libxenligh.so and libxenutil.so from
the CFLAGS/LDFLAGS folder, because they are outdated. If not, the only
option left is to clean my LDFLAGS and CFLAGS folders from previous
Xen versions and compile the new version, but that's risky.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH] libxl: update nic list API to use common device API style
  2011-10-05 13:22       ` Roger Pau Monné
@ 2011-10-05 13:42         ` Ian Campbell
  0 siblings, 0 replies; 55+ messages in thread
From: Ian Campbell @ 2011-10-05 13:42 UTC (permalink / raw)
  To: Roger Pau Monné; +Cc: xen-devel

On Wed, 2011-10-05 at 14:22 +0100, Roger Pau Monné wrote:
> 2011/10/5 Ian Campbell <Ian.Campbell@citrix.com>:
> > (I assume everything but the following hunk was a mistake)
> 
> I modified your patch and resubmitted it (sorry if that's not ok),
> since this is the first place where new functions are added to libxl.

It is usually better to submit fixes separately, they can always be
merged in later if necessary. In this case the bug is preexisting, it
just happened to be this patch which exposed it for your particular
case.

> >> diff -r 25db0629e338 -r e94763a6bd34 tools/libxl/Makefile
> >> --- a/tools/libxl/Makefile      Fri Sep 30 14:27:27 2011 +0100
> >> +++ b/tools/libxl/Makefile      Fri Sep 30 14:27:27 2011 +0100
> >> @@ -119,7 +119,7 @@ libxlutil.a: $(LIBXLU_OBJS)
> >>         $(AR) rcs libxlutil.a $^
> >>
> >>  xl: $(XL_OBJS) libxlutil.so libxenlight.so
> >> -       $(CC) $(LDFLAGS) -o $@ $(XL_OBJS) libxlutil.so $(LDLIBS_libxenlight) $(LDLIBS_libxenctrl)
> >> +       $(CC) $(LDFLAGS) -o $@ $(XL_OBJS) libxlutil.so libxenlight.so $(LDLIBS_libxenlight) $(LDLIBS_libxenctrl)
> >>
> >>  testidl: testidl.o libxlutil.so libxenlight.so
> >>         $(CC) $(LDFLAGS) -o $@ testidl.o libxlutil.so $(LDLIBS_libxenlight) $(LDLIBS_libxenctrl)
> >
> > LDLIBS_libxenlight already has -lxenlight in it. I guess this changes
> > works around you local addition LDFLAGS=-L/usr/xen42/lib?
> >
> > I'm not sure what the right answer is here.
> 
> Neither do I, I'm not an expert on build processes, but if I need to
> append CFLAGS and LDFLAGS to the build process to find my yajl library
> libxl should not try to use the libxenligh.so and libxenutil.so from
> the CFLAGS/LDFLAGS folder, because they are outdated. If not, the only
> option left is to clean my LDFLAGS and CFLAGS folders from previous
> Xen versions and compile the new version, but that's risky.

Hmm yes. Other options might be to move LDFLAGS to the end of the link
line (or introduce LDLIBS at the end?) or perhaps add an explicit -L.
somewhere. I'm really not sure though.

Whatever the solution is it applies to the other binary linked in this
directory (testidl) as well.

Ian.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 01 of 23] libxl: remove hard tabs from non-generated *.[ch]
  2011-09-30 13:33 ` [PATCH 01 of 23] libxl: remove hard tabs from non-generated *.[ch] Ian Campbell
@ 2011-10-06 16:34   ` Ian Jackson
  2011-10-07  8:37     ` Ian Campbell
  2011-10-07 14:08     ` [PATCH 0 of 3] libxl: fixup hard tabs and indentation Ian Campbell
  0 siblings, 2 replies; 55+ messages in thread
From: Ian Jackson @ 2011-10-06 16:34 UTC (permalink / raw)
  To: Ian Campbell
  Cc: Jonathan Ludlam, Jim Fehlig, xen-devel, Mike McClurg, Dave Scott

Ian Campbell writes ("[Xen-devel] [PATCH 01 of 23] libxl: remove hard tabs from non-generated *.[ch]"):
> libxl: remove hard tabs from non-generated *.[ch]

This didn't apply any more (obviously...)

Did you use some rune involving "expand" perhaps ?  If you were to
give me the rune as well as the effects, I could apply it to whatever
the tree happened to look like.

Ian.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 10 of 23] libxl: separate forced and non-forced device remove
  2011-09-30 13:33 ` [PATCH 10 of 23] libxl: separate forced and non-forced device remove Ian Campbell
@ 2011-10-06 16:38   ` Ian Jackson
  2011-10-07  8:44     ` Ian Campbell
  0 siblings, 1 reply; 55+ messages in thread
From: Ian Jackson @ 2011-10-06 16:38 UTC (permalink / raw)
  To: Ian Campbell
  Cc: Jonathan Ludlam, Jim Fehlig, xen-devel, Mike McClurg, Dave Scott

Ian Campbell writes ("[Xen-devel] [PATCH 10 of 23] libxl: separate forced and non-forced device remove"):
> libxl: separate forced and non-forced device remove.
...
>   * the term "destroy" is normally used in libxl for data-type destructors.

I've always thought this was odd.  Perhaps we should rename all of
those "free" and then we could use "destroy" just for domain
destruction and other kinds of violent activity.

Ian.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs
  2011-09-30 13:33 [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Ian Campbell
                   ` (23 preceding siblings ...)
  2011-10-04  7:32 ` [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Roger Pau Monné
@ 2011-10-06 16:43 ` Ian Jackson
  24 siblings, 0 replies; 55+ messages in thread
From: Ian Jackson @ 2011-10-06 16:43 UTC (permalink / raw)
  To: Ian Campbell
  Cc: Jonathan Ludlam, Jim Fehlig, xen-devel, Mike McClurg, Dave Scott

Ian Campbell writes ("[Xen-devel] [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs"):
> The following series overhauls the libxl_device_* APIs in an attempt
> to make them more consistent across the types of devices and move
> towards something we can support as a stable API longterm.

This all looks reasonably sensible although I by no means read every
line of changed code.

> One of the early patches adds a big comment describing the API. It
> would be useful if this got a particularly close eye with a view to
> supporting it long term -- especially from actual and potential
> consumers of the API (of who I've CC a few who sprang to mind).

The API comment looks good.

I'll give it a bit longer for people to have comments.

Thanks,
Ian.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 01 of 23] libxl: remove hard tabs from non-generated *.[ch]
  2011-10-06 16:34   ` Ian Jackson
@ 2011-10-07  8:37     ` Ian Campbell
  2011-10-07 14:08     ` [PATCH 0 of 3] libxl: fixup hard tabs and indentation Ian Campbell
  1 sibling, 0 replies; 55+ messages in thread
From: Ian Campbell @ 2011-10-07  8:37 UTC (permalink / raw)
  To: Ian Jackson
  Cc: Jonathan Ludlam, Jim Fehlig, xen-devel, Mike McClurg, Dave Scott

On Thu, 2011-10-06 at 17:34 +0100, Ian Jackson wrote:
> Ian Campbell writes ("[Xen-devel] [PATCH 01 of 23] libxl: remove hard tabs from non-generated *.[ch]"):
> > libxl: remove hard tabs from non-generated *.[ch]
> 
> This didn't apply any more (obviously...)
> 
> Did you use some rune involving "expand" perhaps ?  If you were to
> give me the rune as well as the effects, I could apply it to whatever
> the tree happened to look like.

I used search and replace +/- emacs reindent functionality.

You can either apply just whatever isn't rejected and I'll repost what
gets left out (and iterate until none) or I can coordinate a time with
you for me to regenerate and post while you aren't applying stuff.

Ian.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 10 of 23] libxl: separate forced and non-forced device remove
  2011-10-06 16:38   ` Ian Jackson
@ 2011-10-07  8:44     ` Ian Campbell
  2011-10-07 13:08       ` Ian Jackson
  0 siblings, 1 reply; 55+ messages in thread
From: Ian Campbell @ 2011-10-07  8:44 UTC (permalink / raw)
  To: Ian Jackson
  Cc: Jonathan Ludlam, Jim Fehlig, xen-devel, Mike McClurg, Dave Scott

On Thu, 2011-10-06 at 17:38 +0100, Ian Jackson wrote:
> Ian Campbell writes ("[Xen-devel] [PATCH 10 of 23] libxl: separate forced and non-forced device remove"):
> > libxl: separate forced and non-forced device remove.
> ...
> >   * the term "destroy" is normally used in libxl for data-type destructors.
> 
> I've always thought this was odd.  Perhaps we should rename all of
> those "free" and then we could use "destroy" just for domain
> destruction and other kinds of violent activity.

The original rationale for the name was that the libxl_TYPE_destroy
functions only free the content of the datastructure but not the
datastructure itself and that calling such a function free() would be
potentially confusing.

On the other hand not being able to use "destroy" as a term for things
related domain destruction is a pain too.

Thesaurus.com suggests various things for destroy and/or free which we
could use for the type destructors. There's lots of fun sounding ones
("bollix up", "enfranchise") but "release" perhaps?

Ian.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 14 of 23] libxl: use libxl__device in libxl_devices_destroy and libxl__device_pci_remove_xenstore
  2011-09-30 13:33 ` [PATCH 14 of 23] libxl: use libxl__device in libxl_devices_destroy and libxl__device_pci_remove_xenstore Ian Campbell
@ 2011-10-07 12:18   ` Roger Pau Monné
  2011-10-07 12:24     ` Ian Campbell
  0 siblings, 1 reply; 55+ messages in thread
From: Roger Pau Monné @ 2011-10-07 12:18 UTC (permalink / raw)
  To: Ian Campbell
  Cc: Jonathan Ludlam, Jim Fehlig, xen-devel, Mike McClurg, Dave Scott

2011/9/30 Ian Campbell <ian.campbell@citrix.com>:
> # HG changeset patch
> # User Ian Campbell <ian.campbell@citrix.com>
> # Date 1317389248 -3600
> # Node ID ec28ee6dace513c3d009d498341f9537a19b2d98
> # Parent  e5a70a3b61a1acfa7d73db548a591486024d01b7
> libxl: use libxl__device in libxl_devices_destroy and libxl__device_pci_remove_xenstore
>
> Doing this allows us to use the common functions for removing devices.
>
> Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
>
> diff -r e5a70a3b61a1 -r ec28ee6dace5 tools/libxl/libxl_device.c
> --- a/tools/libxl/libxl_device.c        Fri Sep 30 14:27:28 2011 +0100
> +++ b/tools/libxl/libxl_device.c        Fri Sep 30 14:27:28 2011 +0100
> @@ -49,6 +49,25 @@ char *libxl__device_backend_path(libxl__
>                           device->domid, device->devid);
>  }
>
> +int libxl__parse_backend_path(libxl__gc *gc,
> +                              const char *path,
> +                              libxl__device *dev)
> +{
> +    /* /local/domain/<domid>/backend/<kind>/<domid>/<devid> */
> +    char strkind[16]; /* Longest is actually "console" */
> +    uint32_t domain;
> +    int rc = sscanf(path, "/local/domain/%d/backend/%15[^/]/%d/%d",
> +                    &dev->backend_domid,
> +                    strkind,
> +                    &domain,
> +                    &dev->backend_devid);
> +
> +    if (rc != 4)
> +        return ERROR_FAIL;
> +
> +    return libxl__device_kind_from_string(strkind, &dev->backend_kind);
> +}
> +
>  int libxl__device_generic_add(libxl__gc *gc, libxl__device *device,
>                              char **bents, char **fents)
>  {
> @@ -348,10 +367,11 @@ int libxl__device_disk_dev_number(const
>     return -1;
>  }
>
> -int libxl__device_remove(libxl__gc *gc, char *be_path)
> +int libxl__device_remove(libxl__gc *gc, libxl__device *dev)
>  {
>     libxl_ctx *ctx = libxl__gc_owner(gc);
>     xs_transaction_t t;
> +    char *be_path = libxl__device_backend_path(gc, dev);
>     char *state_path = libxl__sprintf(gc, "%s/state", be_path);
>     char *state = libxl__xs_read(gc, XBT_NULL, state_path);
>     int rc = 0;
> @@ -429,10 +449,12 @@ static int wait_for_dev_destroy(libxl__g
>  int libxl__devices_destroy(libxl__gc *gc, uint32_t domid, int force)
>  {
>     libxl_ctx *ctx = libxl__gc_owner(gc);
> -    char *path, *be_path, *fe_path;
> +    char *path;
>     unsigned int num1, num2;
>     char **l1 = NULL, **l2 = NULL;
>     int i, j, n_watches = 0;
> +    libxl__device dev;
> +    libxl__device_kind kind;
>
>     path = libxl__sprintf(gc, "/local/domain/%d/device", domid);
>     l1 = libxl__xs_directory(gc, XBT_NULL, path, &num1);
> @@ -445,22 +467,27 @@ int libxl__devices_destroy(libxl__gc *gc
>         num1 = 0;
>     }
>     for (i = 0; i < num1; i++) {
> -        if (!strcmp("vfs", l1[i]))
> +        if (libxl__device_kind_from_string(l1[i], &kind))
> +            continue;
> +        if (kind == LIBXL__DEVICE_KIND_VBD)
>             continue;

This should not be there, or hotplug scripts for VBD device types are
not called. I know Linux doesn't need to call hotplug scripts for VBD,
but NetBSD does. Should we add some kind of helper function or ifdef,
or is it safe to remove this and handle VBD devices normally?

>         path = libxl__sprintf(gc, "/local/domain/%d/device/%s", domid, l1[i]);
>         l2 = libxl__xs_directory(gc, XBT_NULL, path, &num2);
>         if (!l2)
>             continue;
>         for (j = 0; j < num2; j++) {
> -            fe_path = libxl__sprintf(gc, "/local/domain/%d/device/%s/%s", domid, l1[i], l2[j]);
> -            be_path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/backend", fe_path));
> -            if (be_path != NULL) {
> +            path = libxl__sprintf(gc, "/local/domain/%d/device/%s/%s/backend",
> +                                  domid, l1[i], l2[j]);
> +            path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, path));
> +            if (path && libxl__parse_backend_path(gc, path, &dev) == 0) {
> +                dev.domid = domid;
> +                dev.kind = kind;
> +                dev.devid = atoi(l2[j]);
> +
>                 if (force) {
> -                    xs_rm(ctx->xsh, XBT_NULL, be_path);
> -                    xs_rm(ctx->xsh, XBT_NULL, fe_path);
> -                    libxl__device_destroy_tapdisk(gc, be_path);
> +                    libxl__device_force_remove(gc, &dev);
>                 } else {
> -                    if (libxl__device_remove(gc, be_path) > 0)
> +                    if (libxl__device_remove(gc, &dev) > 0)
>                         n_watches++;
>                 }
>             }
> @@ -468,14 +495,18 @@ int libxl__devices_destroy(libxl__gc *gc
>     }
>
>     /* console 0 frontend directory is not under /local/domain/<domid>/device */
> -    fe_path = libxl__sprintf(gc, "/local/domain/%d/console", domid);
> -    be_path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/backend", fe_path));
> -    if (be_path && strcmp(be_path, "")) {
> +    path = libxl__sprintf(gc, "/local/domain/%d/console/backend", domid);
> +    path = libxl__xs_read(gc, XBT_NULL, path);
> +    if (path && strcmp(path, "") &&
> +        libxl__parse_backend_path(gc, path, &dev) == 0) {
> +        dev.domid = domid;
> +        dev.kind = LIBXL__DEVICE_KIND_CONSOLE;
> +        dev.devid = 0;
> +
>         if (force) {
> -            xs_rm(ctx->xsh, XBT_NULL, be_path);
> -            xs_rm(ctx->xsh, XBT_NULL, fe_path);
> +            libxl__device_force_remove(gc, &dev);
>         } else {
> -            if (libxl__device_remove(gc, be_path) > 0)
> +            if (libxl__device_remove(gc, &dev) > 0)
>                 n_watches++;
>         }
>     }
> @@ -505,12 +536,9 @@ int libxl__device_del(libxl__gc *gc, lib
>  {
>     libxl_ctx *ctx = libxl__gc_owner(gc);
>     struct timeval tv;
> -    char *backend_path;
>     int rc;
>
> -    backend_path = libxl__device_backend_path(gc, dev);
> -
> -    rc = libxl__device_remove(gc, backend_path);
> +    rc = libxl__device_remove(gc, dev);
>     if (rc == -1) {
>         rc = ERROR_FAIL;
>         goto out;
> diff -r e5a70a3b61a1 -r ec28ee6dace5 tools/libxl/libxl_internal.h
> --- a/tools/libxl/libxl_internal.h      Fri Sep 30 14:27:28 2011 +0100
> +++ b/tools/libxl/libxl_internal.h      Fri Sep 30 14:27:28 2011 +0100
> @@ -240,8 +240,10 @@ _hidden int libxl__device_generic_add(li
>                              char **bents, char **fents);
>  _hidden char *libxl__device_backend_path(libxl__gc *gc, libxl__device *device);
>  _hidden char *libxl__device_frontend_path(libxl__gc *gc, libxl__device *device);
> +_hidden int libxl__parse_backend_path(libxl__gc *gc, const char *path,
> +                                      libxl__device *dev);
>  _hidden int libxl__device_del(libxl__gc *gc, libxl__device *dev);
> -_hidden int libxl__device_remove(libxl__gc *gc, char *be_path);
> +_hidden int libxl__device_remove(libxl__gc *gc, libxl__device *dev);
>  _hidden int libxl__device_force_remove(libxl__gc *gc, libxl__device *dev);
>  _hidden int libxl__devices_destroy(libxl__gc *gc, uint32_t domid, int force);
>  _hidden int libxl__wait_for_backend(libxl__gc *gc, char *be_path, char *state);
> diff -r e5a70a3b61a1 -r ec28ee6dace5 tools/libxl/libxl_pci.c
> --- a/tools/libxl/libxl_pci.c   Fri Sep 30 14:27:28 2011 +0100
> +++ b/tools/libxl/libxl_pci.c   Fri Sep 30 14:27:28 2011 +0100
> @@ -410,9 +410,15 @@ retry_transaction2:
>             goto retry_transaction2;
>
>     if (num == 1) {
> -        char *fe_path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/frontend", be_path));
> -        xs_rm(ctx->xsh, XBT_NULL, be_path);
> -        xs_rm(ctx->xsh, XBT_NULL, fe_path);
> +        libxl__device dev;
> +        if (libxl__parse_backend_path(gc, be_path, &dev) != 0)
> +            return ERROR_FAIL;
> +
> +        dev.domid = domid;
> +        dev.kind = LIBXL__DEVICE_KIND_PCI;
> +        dev.devid = 0;
> +
> +        libxl__device_force_remove(gc, &dev);
>         return 0;
>     }
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xensource.com
> http://lists.xensource.com/xen-devel
>

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 14 of 23] libxl: use libxl__device in libxl_devices_destroy and libxl__device_pci_remove_xenstore
  2011-10-07 12:18   ` Roger Pau Monné
@ 2011-10-07 12:24     ` Ian Campbell
  2011-10-07 12:26       ` Ian Campbell
  0 siblings, 1 reply; 55+ messages in thread
From: Ian Campbell @ 2011-10-07 12:24 UTC (permalink / raw)
  To: Roger Pau Monné
  Cc: Jonathan Ludlam, Jim Fehlig, xen-devel, Mike McClurg, Dave Scott

On Fri, 2011-10-07 at 13:18 +0100, Roger Pau Monné wrote:
> 2011/9/30 Ian Campbell <ian.campbell@citrix.com>:

> > @@ -445,22 +467,27 @@ int libxl__devices_destroy(libxl__gc *gc
> >         num1 = 0;
> >     }
> >     for (i = 0; i < num1; i++) {
> > -        if (!strcmp("vfs", l1[i]))
> > +        if (libxl__device_kind_from_string(l1[i], &kind))
> > +            continue;
> > +        if (kind == LIBXL__DEVICE_KIND_VBD)
> >             continue;
> 
> This should not be there, or hotplug scripts for VBD device types are
> not called. I know Linux doesn't need to call hotplug scripts for VBD,
> but NetBSD does. Should we add some kind of helper function or ifdef,
> or is it safe to remove this and handle VBD devices normally?

This is a bug -- I removed a check for "vfs" and replaced it with one
for "vbd" which is not the same!

"vfs" was the fs-backend thing which was remove by 22716:3c78729b6f06 so
I think the check can just be removed and I will do so in the next
posting.


Ian
> 
> >         path = libxl__sprintf(gc, "/local/domain/%d/device/%s", domid, l1[i]);
> >         l2 = libxl__xs_directory(gc, XBT_NULL, path, &num2);
> >         if (!l2)
> >             continue;
> >         for (j = 0; j < num2; j++) {
> > -            fe_path = libxl__sprintf(gc, "/local/domain/%d/device/%s/%s", domid, l1[i], l2[j]);
> > -            be_path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/backend", fe_path));
> > -            if (be_path != NULL) {
> > +            path = libxl__sprintf(gc, "/local/domain/%d/device/%s/%s/backend",
> > +                                  domid, l1[i], l2[j]);
> > +            path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, path));
> > +            if (path && libxl__parse_backend_path(gc, path, &dev) == 0) {
> > +                dev.domid = domid;
> > +                dev.kind = kind;
> > +                dev.devid = atoi(l2[j]);
> > +
> >                 if (force) {
> > -                    xs_rm(ctx->xsh, XBT_NULL, be_path);
> > -                    xs_rm(ctx->xsh, XBT_NULL, fe_path);
> > -                    libxl__device_destroy_tapdisk(gc, be_path);
> > +                    libxl__device_force_remove(gc, &dev);
> >                 } else {
> > -                    if (libxl__device_remove(gc, be_path) > 0)
> > +                    if (libxl__device_remove(gc, &dev) > 0)
> >                         n_watches++;
> >                 }
> >             }
> > @@ -468,14 +495,18 @@ int libxl__devices_destroy(libxl__gc *gc
> >     }
> >
> >     /* console 0 frontend directory is not under /local/domain/<domid>/device */
> > -    fe_path = libxl__sprintf(gc, "/local/domain/%d/console", domid);
> > -    be_path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/backend", fe_path));
> > -    if (be_path && strcmp(be_path, "")) {
> > +    path = libxl__sprintf(gc, "/local/domain/%d/console/backend", domid);
> > +    path = libxl__xs_read(gc, XBT_NULL, path);
> > +    if (path && strcmp(path, "") &&
> > +        libxl__parse_backend_path(gc, path, &dev) == 0) {
> > +        dev.domid = domid;
> > +        dev.kind = LIBXL__DEVICE_KIND_CONSOLE;
> > +        dev.devid = 0;
> > +
> >         if (force) {
> > -            xs_rm(ctx->xsh, XBT_NULL, be_path);
> > -            xs_rm(ctx->xsh, XBT_NULL, fe_path);
> > +            libxl__device_force_remove(gc, &dev);
> >         } else {
> > -            if (libxl__device_remove(gc, be_path) > 0)
> > +            if (libxl__device_remove(gc, &dev) > 0)
> >                 n_watches++;
> >         }
> >     }
> > @@ -505,12 +536,9 @@ int libxl__device_del(libxl__gc *gc, lib
> >  {
> >     libxl_ctx *ctx = libxl__gc_owner(gc);
> >     struct timeval tv;
> > -    char *backend_path;
> >     int rc;
> >
> > -    backend_path = libxl__device_backend_path(gc, dev);
> > -
> > -    rc = libxl__device_remove(gc, backend_path);
> > +    rc = libxl__device_remove(gc, dev);
> >     if (rc == -1) {
> >         rc = ERROR_FAIL;
> >         goto out;
> > diff -r e5a70a3b61a1 -r ec28ee6dace5 tools/libxl/libxl_internal.h
> > --- a/tools/libxl/libxl_internal.h      Fri Sep 30 14:27:28 2011 +0100
> > +++ b/tools/libxl/libxl_internal.h      Fri Sep 30 14:27:28 2011 +0100
> > @@ -240,8 +240,10 @@ _hidden int libxl__device_generic_add(li
> >                              char **bents, char **fents);
> >  _hidden char *libxl__device_backend_path(libxl__gc *gc, libxl__device *device);
> >  _hidden char *libxl__device_frontend_path(libxl__gc *gc, libxl__device *device);
> > +_hidden int libxl__parse_backend_path(libxl__gc *gc, const char *path,
> > +                                      libxl__device *dev);
> >  _hidden int libxl__device_del(libxl__gc *gc, libxl__device *dev);
> > -_hidden int libxl__device_remove(libxl__gc *gc, char *be_path);
> > +_hidden int libxl__device_remove(libxl__gc *gc, libxl__device *dev);
> >  _hidden int libxl__device_force_remove(libxl__gc *gc, libxl__device *dev);
> >  _hidden int libxl__devices_destroy(libxl__gc *gc, uint32_t domid, int force);
> >  _hidden int libxl__wait_for_backend(libxl__gc *gc, char *be_path, char *state);
> > diff -r e5a70a3b61a1 -r ec28ee6dace5 tools/libxl/libxl_pci.c
> > --- a/tools/libxl/libxl_pci.c   Fri Sep 30 14:27:28 2011 +0100
> > +++ b/tools/libxl/libxl_pci.c   Fri Sep 30 14:27:28 2011 +0100
> > @@ -410,9 +410,15 @@ retry_transaction2:
> >             goto retry_transaction2;
> >
> >     if (num == 1) {
> > -        char *fe_path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/frontend", be_path));
> > -        xs_rm(ctx->xsh, XBT_NULL, be_path);
> > -        xs_rm(ctx->xsh, XBT_NULL, fe_path);
> > +        libxl__device dev;
> > +        if (libxl__parse_backend_path(gc, be_path, &dev) != 0)
> > +            return ERROR_FAIL;
> > +
> > +        dev.domid = domid;
> > +        dev.kind = LIBXL__DEVICE_KIND_PCI;
> > +        dev.devid = 0;
> > +
> > +        libxl__device_force_remove(gc, &dev);
> >         return 0;
> >     }
> >
> >
> > _______________________________________________
> > Xen-devel mailing list
> > Xen-devel@lists.xensource.com
> > http://lists.xensource.com/xen-devel
> >

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 14 of 23] libxl: use libxl__device in libxl_devices_destroy and libxl__device_pci_remove_xenstore
  2011-10-07 12:24     ` Ian Campbell
@ 2011-10-07 12:26       ` Ian Campbell
  0 siblings, 0 replies; 55+ messages in thread
From: Ian Campbell @ 2011-10-07 12:26 UTC (permalink / raw)
  To: Roger Pau Monné
  Cc: Jim Fehlig, xen-devel, Scott, Mike McClurg, Jonathan Ludlam

On Fri, 2011-10-07 at 13:24 +0100, Ian Campbell wrote:
> On Fri, 2011-10-07 at 13:18 +0100, Roger Pau Monné wrote:
> > 2011/9/30 Ian Campbell <ian.campbell@citrix.com>:
> 
> > > @@ -445,22 +467,27 @@ int libxl__devices_destroy(libxl__gc *gc
> > >         num1 = 0;
> > >     }
> > >     for (i = 0; i < num1; i++) {
> > > -        if (!strcmp("vfs", l1[i]))
> > > +        if (libxl__device_kind_from_string(l1[i], &kind))
> > > +            continue;
> > > +        if (kind == LIBXL__DEVICE_KIND_VBD)
> > >             continue;
> > 
> > This should not be there, or hotplug scripts for VBD device types are
> > not called. I know Linux doesn't need to call hotplug scripts for VBD,
> > but NetBSD does. Should we add some kind of helper function or ifdef,
> > or is it safe to remove this and handle VBD devices normally?
> 
> This is a bug -- I removed a check for "vfs" and replaced it with one
> for "vbd" which is not the same!
> 
> "vfs" was the fs-backend thing which was remove by 22716:3c78729b6f06 so
> I think the check can just be removed and I will do so in the next
> posting

incremental version:

diff -r 2bf50dc113d4 tools/libxl/libxl_device.c
--- a/tools/libxl/libxl_device.c	Fri Oct 07 13:24:45 2011 +0100
+++ b/tools/libxl/libxl_device.c	Fri Oct 07 13:25:28 2011 +0100
@@ -469,8 +469,6 @@ int libxl__devices_destroy(libxl__gc *gc
     for (i = 0; i < num1; i++) {
         if (libxl__device_kind_from_string(l1[i], &kind))
             continue;
-        if (kind == LIBXL__DEVICE_KIND_VBD)
-            continue;
         path = libxl__sprintf(gc, "/local/domain/%d/device/%s", domid, l1[i]);
         l2 = libxl__xs_directory(gc, XBT_NULL, path, &num2);
         if (!l2)

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 10 of 23] libxl: separate forced and non-forced device remove
  2011-10-07  8:44     ` Ian Campbell
@ 2011-10-07 13:08       ` Ian Jackson
  0 siblings, 0 replies; 55+ messages in thread
From: Ian Jackson @ 2011-10-07 13:08 UTC (permalink / raw)
  To: Ian Campbell
  Cc: Jonathan Ludlam, Jim Fehlig, xen-devel, Mike McClurg, Dave Scott

Ian Campbell writes ("Re: [Xen-devel] [PATCH 10 of 23] libxl: separate forced and non-forced	device remove"):
> The original rationale for the name was that the libxl_TYPE_destroy
> functions only free the content of the datastructure but not the
> datastructure itself and that calling such a function free() would be
> potentially confusing.

Hmmm.

> On the other hand not being able to use "destroy" as a term for things
> related domain destruction is a pain too.

Yes.

> Thesaurus.com suggests various things for destroy and/or free which we
> could use for the type destructors. There's lots of fun sounding ones
> ("bollix up", "enfranchise") but "release" perhaps?

"dispose" ?  "discard" ?  "dealloc[ate]" ?  "abandon" ?

"Release" sounds like it refers to some kind of lock or reservation.

Ian.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 0 of 3] libxl: fixup hard tabs and indentation
  2011-10-06 16:34   ` Ian Jackson
  2011-10-07  8:37     ` Ian Campbell
@ 2011-10-07 14:08     ` Ian Campbell
  2011-10-07 14:08       ` [PATCH 1 of 3] libxl: expand hard tabs stops Ian Campbell
                         ` (2 more replies)
  1 sibling, 3 replies; 55+ messages in thread
From: Ian Campbell @ 2011-10-07 14:08 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian Jackson

This is the whitespace cleanup bit of my "libxl: rationalise
libxl_device_* APIs" series.

As requested I have used the expand utility to automatically fixup the
majority of hard tabs and then fixed up the places which were actually
just wrongly indented to start with by hand.

I added some emacs local-variable runes to stop this happening.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 1 of 3] libxl: expand hard tabs stops
  2011-10-07 14:08     ` [PATCH 0 of 3] libxl: fixup hard tabs and indentation Ian Campbell
@ 2011-10-07 14:08       ` Ian Campbell
  2011-10-07 14:08       ` [PATCH 2 of 3] libxl: fixup incorrect indentation Ian Campbell
  2011-10-07 14:08       ` [PATCH 3 of 3] libxl: add emacs local variables block to turn on four space indentation Ian Campbell
  2 siblings, 0 replies; 55+ messages in thread
From: Ian Campbell @ 2011-10-07 14:08 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian Jackson

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1317995956 -3600
# Node ID a440b0ad413b88ef7814f407b2fc3b412d586e9b
# Parent  197e3be90f3245fb8f66281bf2759327bf051a9d
libxl: expand hard tabs stops

I ran the following and committed the result. ^I is an actual hard tab

for i in $(grep -l --exclude=*_[ly].\[ch\] '^I' tools/libxl/*.[ch]) ; do
     cat $i | expand | sponge $i
done

There are some actually wrong indentations too, I'll fix thos up manually

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 197e3be90f32 -r a440b0ad413b tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Fri Oct 07 13:24:44 2011 +0100
+++ b/tools/libxl/libxl.c	Fri Oct 07 14:59:16 2011 +0100
@@ -696,13 +696,13 @@ int libxl_event_get_disk_eject_info(libx
     sscanf(backend,
             "/local/domain/%d/backend/%" TOSTRING(BACKEND_STRING_SIZE) "[a-z]/%*d/%*d",
             &disk->backend_domid, backend_type);
-	if (!strcmp(backend_type, "tap") || !strcmp(backend_type, "vbd")) {
-		disk->backend = LIBXL_DISK_BACKEND_TAP;
-	} else if (!strcmp(backend_type, "qdisk")) {
-		disk->backend = LIBXL_DISK_BACKEND_QDISK;
-	} else {
-		disk->backend = LIBXL_DISK_BACKEND_UNKNOWN;
-	}
+        if (!strcmp(backend_type, "tap") || !strcmp(backend_type, "vbd")) {
+                disk->backend = LIBXL_DISK_BACKEND_TAP;
+        } else if (!strcmp(backend_type, "qdisk")) {
+                disk->backend = LIBXL_DISK_BACKEND_QDISK;
+        } else {
+                disk->backend = LIBXL_DISK_BACKEND_UNKNOWN;
+        }
 
     disk->pdev_path = strdup("");
     disk->format = LIBXL_DISK_FORMAT_EMPTY;
diff -r 197e3be90f32 -r a440b0ad413b tools/libxl/libxl.h
--- a/tools/libxl/libxl.h	Fri Oct 07 13:24:44 2011 +0100
+++ b/tools/libxl/libxl.h	Fri Oct 07 14:59:16 2011 +0100
@@ -420,7 +420,7 @@ int libxl_cpuid_parse_config_xend(libxl_
                                   const char* str);
 void libxl_cpuid_apply_policy(libxl_ctx *ctx, uint32_t domid);
 void libxl_cpuid_set(libxl_ctx *ctx, uint32_t domid,
-		     libxl_cpuid_policy_list cpuid);
+                     libxl_cpuid_policy_list cpuid);
 
 /*
  * Functions for allowing users of libxl to store private data
diff -r 197e3be90f32 -r a440b0ad413b tools/libxl/libxl_bootloader.c
--- a/tools/libxl/libxl_bootloader.c	Fri Oct 07 13:24:44 2011 +0100
+++ b/tools/libxl/libxl_bootloader.c	Fri Oct 07 14:59:16 2011 +0100
@@ -81,14 +81,14 @@ static int open_xenconsoled_pty(int *mas
 
     ret = openpty(master, slave, NULL, NULL, NULL);
     if (ret < 0)
-	    return -1;
+            return -1;
 
     ret = ttyname_r(*slave, slave_path, slave_path_len);
     if (ret == -1) {
-	    close(*master);
-	    close(*slave);
-	    *master = *slave = -1;
-	    return -1;
+            close(*master);
+            close(*slave);
+            *master = *slave = -1;
+            return -1;
     }
 
     /*
diff -r 197e3be90f32 -r a440b0ad413b tools/libxl/libxl_cpuid.c
--- a/tools/libxl/libxl_cpuid.c	Fri Oct 07 13:24:44 2011 +0100
+++ b/tools/libxl/libxl_cpuid.c	Fri Oct 07 14:59:16 2011 +0100
@@ -317,7 +317,7 @@ void libxl_cpuid_apply_policy(libxl_ctx 
 }
 
 void libxl_cpuid_set(libxl_ctx *ctx, uint32_t domid,
-		     libxl_cpuid_policy_list cpuid)
+                     libxl_cpuid_policy_list cpuid)
 {
     int i;
     char *cpuid_res[4];
diff -r 197e3be90f32 -r a440b0ad413b tools/libxl/libxl_internal.c
--- a/tools/libxl/libxl_internal.c	Fri Oct 07 13:24:44 2011 +0100
+++ b/tools/libxl/libxl_internal.c	Fri Oct 07 14:59:16 2011 +0100
@@ -228,53 +228,53 @@ char *libxl__abs_path(libxl__gc *gc, con
 
 int libxl__file_reference_map(libxl_file_reference *f)
 {
-	struct stat st_buf;
-	int ret, fd;
-	void *data;
+        struct stat st_buf;
+        int ret, fd;
+        void *data;
 
-	if (f->mapped)
-		return 0;
+        if (f->mapped)
+                return 0;
 
-	fd = open(f->path, O_RDONLY);
-	if (f < 0)
-		return ERROR_FAIL;
+        fd = open(f->path, O_RDONLY);
+        if (f < 0)
+                return ERROR_FAIL;
 
-	ret = fstat(fd, &st_buf);
-	if (ret < 0)
-		goto out;
+        ret = fstat(fd, &st_buf);
+        if (ret < 0)
+                goto out;
 
-	ret = -1;
-	data = mmap(NULL, st_buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
-	if (data == NULL)
-		goto out;
+        ret = -1;
+        data = mmap(NULL, st_buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+        if (data == NULL)
+                goto out;
 
-	f->mapped = 1;
-	f->data = data;
-	f->size = st_buf.st_size;
+        f->mapped = 1;
+        f->data = data;
+        f->size = st_buf.st_size;
 
-	ret = 0;
+        ret = 0;
 out:
-	close(fd);
+        close(fd);
 
-	return ret == 0 ? 0 : ERROR_FAIL;
+        return ret == 0 ? 0 : ERROR_FAIL;
 }
 
 int libxl__file_reference_unmap(libxl_file_reference *f)
 {
-	int ret;
+        int ret;
 
-	if (!f->mapped)
-		return 0;
+        if (!f->mapped)
+                return 0;
 
-	ret = munmap(f->data, f->size);
-	if (ret == 0) {
-		f->mapped = 0;
-		f->data = NULL;
-		f->size = 0;
-		return 0;
-	}
+        ret = munmap(f->data, f->size);
+        if (ret == 0) {
+                f->mapped = 0;
+                f->data = NULL;
+                f->size = 0;
+                return 0;
+        }
 
-	return ERROR_FAIL;
+        return ERROR_FAIL;
 }
 
 _hidden int libxl__parse_mac(const char *s, libxl_mac mac)
diff -r 197e3be90f32 -r a440b0ad413b tools/libxl/libxl_nocpuid.c
--- a/tools/libxl/libxl_nocpuid.c	Fri Oct 07 13:24:44 2011 +0100
+++ b/tools/libxl/libxl_nocpuid.c	Fri Oct 07 14:59:16 2011 +0100
@@ -32,6 +32,6 @@ void libxl_cpuid_apply_policy(libxl_ctx 
 }
 
 void libxl_cpuid_set(libxl_ctx *ctx, uint32_t domid,
-		     libxl_cpuid_policy_list cpuid)
+                     libxl_cpuid_policy_list cpuid)
 {
 }
diff -r 197e3be90f32 -r a440b0ad413b tools/libxl/libxl_pci.c
--- a/tools/libxl/libxl_pci.c	Fri Oct 07 13:24:44 2011 +0100
+++ b/tools/libxl/libxl_pci.c	Fri Oct 07 14:59:16 2011 +0100
@@ -1114,7 +1114,7 @@ static int e820_sanitize(libxl_ctx *ctx,
         if ((src[i].type == E820_RAM) ||
             (src[i].type == E820_UNUSABLE) ||
             (src[i].type == 0))
-		continue;
+                continue;
 
         start = src[i].addr < start ? src[i].addr : start;
         last = src[i].addr + src[i].size > last ?
@@ -1159,14 +1159,14 @@ static int e820_sanitize(libxl_ctx *ctx,
      * to E820_UNUSED. We also need to move some of the E820_RAM regions if
      * the overlap with ram_end. */
     for (i = 0; i < nr; i++) {
-	uint64_t end = src[i].addr + src[i].size;
+        uint64_t end = src[i].addr + src[i].size;
 
-	/* We don't care about E820_UNUSABLE, but we need to
+        /* We don't care about E820_UNUSABLE, but we need to
          * change the type to zero b/c the loop after this
          * sticks E820_UNUSABLE on the guest's E820 but ignores
          * the ones with type zero. */
         if ((src[i].type == E820_UNUSABLE) ||
-	    /* Any region that is within the "RAM region" can
+            /* Any region that is within the "RAM region" can
              * be safely ditched. */
             (end < ram_end)) {
                 src[i].type = 0;
@@ -1174,15 +1174,15 @@ static int e820_sanitize(libxl_ctx *ctx,
         }
 
         /* Look only at RAM regions. */
-	if (src[i].type != E820_RAM)
+        if (src[i].type != E820_RAM)
             continue;
 
         /* We only care about RAM regions below 4GB. */
         if (src[i].addr >= (1ULL<<32))
             continue;
 
-	/* E820_RAM overlaps with our RAM region. Move it */
-	if (src[i].addr < ram_end) {
+        /* E820_RAM overlaps with our RAM region. Move it */
+        if (src[i].addr < ram_end) {
             uint64_t delta;
 
             src[i].type = E820_UNUSABLE;
@@ -1236,8 +1236,8 @@ static int e820_sanitize(libxl_ctx *ctx,
     /* Almost done: copy them over, ignoring the undesireable ones */
     for (i = 0; i < nr; i++) {
         if ((src[i].type == E820_RAM) ||
-	    (src[i].type == 0))
-	    continue;
+            (src[i].type == 0))
+            continue;
 
         e820[idx].type = src[i].type;
         e820[idx].addr = src[i].addr;
diff -r 197e3be90f32 -r a440b0ad413b tools/libxl/libxl_utils.c
--- a/tools/libxl/libxl_utils.c	Fri Oct 07 13:24:44 2011 +0100
+++ b/tools/libxl/libxl_utils.c	Fri Oct 07 14:59:16 2011 +0100
@@ -457,7 +457,7 @@ int libxl_mac_to_device_nic(libxl_ctx *c
 
     rc = libxl__parse_mac(mac, mac_n);
     if (rc)
-	    return rc;
+            return rc;
 
     nics = libxl_list_nics(ctx, domid, &nb);
     if (!nics)
@@ -509,7 +509,7 @@ int libxl_devid_to_device_nic(libxl_ctx 
     val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/mac", nic_path_fe));
     rc = libxl__parse_mac(val, nic->mac);
     if (rc)
-	    goto out;
+            goto out;
 
     nic->script = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, "%s/script", nic_path_be), NULL);
     rc = 0;
diff -r 197e3be90f32 -r a440b0ad413b tools/libxl/libxlutil.h
--- a/tools/libxl/libxlutil.h	Fri Oct 07 13:24:44 2011 +0100
+++ b/tools/libxl/libxlutil.h	Fri Oct 07 14:59:16 2011 +0100
@@ -64,7 +64,7 @@ const char *xlu_cfg_get_listitem(const X
  */
 
 int xlu_disk_parse(XLU_Config *cfg, int nspecs, const char *const *specs,
-		   libxl_device_disk *disk);
+                   libxl_device_disk *disk);
   /* disk must have been initialised.
    *
    * On error, returns errno value.  Bad strings cause EINVAL and
diff -r 197e3be90f32 -r a440b0ad413b tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c	Fri Oct 07 13:24:44 2011 +0100
+++ b/tools/libxl/xl_cmdimpl.c	Fri Oct 07 14:59:16 2011 +0100
@@ -557,15 +557,15 @@ static void parse_disk_config_multistrin
     memset(disk, 0, sizeof(*disk));
 
     if (!*config) {
-	*config = xlu_cfg_init(stderr, "command line");
-	if (!*config) { perror("xlu_cfg_init"); exit(-1); }
+        *config = xlu_cfg_init(stderr, "command line");
+        if (!*config) { perror("xlu_cfg_init"); exit(-1); }
     }
 
     e = xlu_disk_parse(*config, nspecs, specs, disk);
     if (e == EINVAL) exit(-1);
     if (e) {
-	fprintf(stderr,"xlu_disk_parse failed: %s\n",strerror(errno));
-	exit(-1);
+        fprintf(stderr,"xlu_disk_parse failed: %s\n",strerror(errno));
+        exit(-1);
     }
 }

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 2 of 3] libxl: fixup incorrect indentation
  2011-10-07 14:08     ` [PATCH 0 of 3] libxl: fixup hard tabs and indentation Ian Campbell
  2011-10-07 14:08       ` [PATCH 1 of 3] libxl: expand hard tabs stops Ian Campbell
@ 2011-10-07 14:08       ` Ian Campbell
  2011-10-12 15:23         ` Ian Jackson
  2011-10-07 14:08       ` [PATCH 3 of 3] libxl: add emacs local variables block to turn on four space indentation Ian Campbell
  2 siblings, 1 reply; 55+ messages in thread
From: Ian Campbell @ 2011-10-07 14:08 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian Jackson

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1317996269 -3600
# Node ID ea75a1765a4a8da26089f42c68a1a1f15182a11f
# Parent  a440b0ad413b88ef7814f407b2fc3b412d586e9b
libxl: fixup incorrect indentation

Several places which were previsously indented using hard tabs are now
incorrectly indented. Fix them up.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r a440b0ad413b -r ea75a1765a4a tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Fri Oct 07 14:59:16 2011 +0100
+++ b/tools/libxl/libxl.c	Fri Oct 07 15:04:29 2011 +0100
@@ -696,13 +696,13 @@ int libxl_event_get_disk_eject_info(libx
     sscanf(backend,
             "/local/domain/%d/backend/%" TOSTRING(BACKEND_STRING_SIZE) "[a-z]/%*d/%*d",
             &disk->backend_domid, backend_type);
-        if (!strcmp(backend_type, "tap") || !strcmp(backend_type, "vbd")) {
-                disk->backend = LIBXL_DISK_BACKEND_TAP;
-        } else if (!strcmp(backend_type, "qdisk")) {
-                disk->backend = LIBXL_DISK_BACKEND_QDISK;
-        } else {
-                disk->backend = LIBXL_DISK_BACKEND_UNKNOWN;
-        }
+    if (!strcmp(backend_type, "tap") || !strcmp(backend_type, "vbd")) {
+        disk->backend = LIBXL_DISK_BACKEND_TAP;
+    } else if (!strcmp(backend_type, "qdisk")) {
+        disk->backend = LIBXL_DISK_BACKEND_QDISK;
+    } else {
+        disk->backend = LIBXL_DISK_BACKEND_UNKNOWN;
+    }
 
     disk->pdev_path = strdup("");
     disk->format = LIBXL_DISK_FORMAT_EMPTY;
diff -r a440b0ad413b -r ea75a1765a4a tools/libxl/libxl_bootloader.c
--- a/tools/libxl/libxl_bootloader.c	Fri Oct 07 14:59:16 2011 +0100
+++ b/tools/libxl/libxl_bootloader.c	Fri Oct 07 15:04:29 2011 +0100
@@ -81,14 +81,14 @@ static int open_xenconsoled_pty(int *mas
 
     ret = openpty(master, slave, NULL, NULL, NULL);
     if (ret < 0)
-            return -1;
+        return -1;
 
     ret = ttyname_r(*slave, slave_path, slave_path_len);
     if (ret == -1) {
-            close(*master);
-            close(*slave);
-            *master = *slave = -1;
-            return -1;
+        close(*master);
+        close(*slave);
+        *master = *slave = -1;
+        return -1;
     }
 
     /*
diff -r a440b0ad413b -r ea75a1765a4a tools/libxl/libxl_internal.c
--- a/tools/libxl/libxl_internal.c	Fri Oct 07 14:59:16 2011 +0100
+++ b/tools/libxl/libxl_internal.c	Fri Oct 07 15:04:29 2011 +0100
@@ -228,53 +228,53 @@ char *libxl__abs_path(libxl__gc *gc, con
 
 int libxl__file_reference_map(libxl_file_reference *f)
 {
-        struct stat st_buf;
-        int ret, fd;
-        void *data;
+    struct stat st_buf;
+    int ret, fd;
+    void *data;
 
-        if (f->mapped)
-                return 0;
+    if (f->mapped)
+        return 0;
 
-        fd = open(f->path, O_RDONLY);
-        if (f < 0)
-                return ERROR_FAIL;
+    fd = open(f->path, O_RDONLY);
+    if (f < 0)
+        return ERROR_FAIL;
 
-        ret = fstat(fd, &st_buf);
-        if (ret < 0)
-                goto out;
+    ret = fstat(fd, &st_buf);
+    if (ret < 0)
+        goto out;
 
-        ret = -1;
-        data = mmap(NULL, st_buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
-        if (data == NULL)
-                goto out;
+    ret = -1;
+    data = mmap(NULL, st_buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+    if (data == NULL)
+        goto out;
 
-        f->mapped = 1;
-        f->data = data;
-        f->size = st_buf.st_size;
+    f->mapped = 1;
+    f->data = data;
+    f->size = st_buf.st_size;
 
-        ret = 0;
+    ret = 0;
 out:
-        close(fd);
+    close(fd);
 
-        return ret == 0 ? 0 : ERROR_FAIL;
+    return ret == 0 ? 0 : ERROR_FAIL;
 }
 
 int libxl__file_reference_unmap(libxl_file_reference *f)
 {
-        int ret;
+    int ret;
 
-        if (!f->mapped)
-                return 0;
+    if (!f->mapped)
+        return 0;
 
-        ret = munmap(f->data, f->size);
-        if (ret == 0) {
-                f->mapped = 0;
-                f->data = NULL;
-                f->size = 0;
-                return 0;
-        }
+    ret = munmap(f->data, f->size);
+    if (ret == 0) {
+        f->mapped = 0;
+        f->data = NULL;
+        f->size = 0;
+        return 0;
+    }
 
-        return ERROR_FAIL;
+    return ERROR_FAIL;
 }
 
 _hidden int libxl__parse_mac(const char *s, libxl_mac mac)
diff -r a440b0ad413b -r ea75a1765a4a tools/libxl/libxl_pci.c
--- a/tools/libxl/libxl_pci.c	Fri Oct 07 14:59:16 2011 +0100
+++ b/tools/libxl/libxl_pci.c	Fri Oct 07 15:04:29 2011 +0100
@@ -1114,7 +1114,7 @@ static int e820_sanitize(libxl_ctx *ctx,
         if ((src[i].type == E820_RAM) ||
             (src[i].type == E820_UNUSABLE) ||
             (src[i].type == 0))
-                continue;
+            continue;
 
         start = src[i].addr < start ? src[i].addr : start;
         last = src[i].addr + src[i].size > last ?
diff -r a440b0ad413b -r ea75a1765a4a tools/libxl/libxl_utils.c
--- a/tools/libxl/libxl_utils.c	Fri Oct 07 14:59:16 2011 +0100
+++ b/tools/libxl/libxl_utils.c	Fri Oct 07 15:04:29 2011 +0100
@@ -457,7 +457,7 @@ int libxl_mac_to_device_nic(libxl_ctx *c
 
     rc = libxl__parse_mac(mac, mac_n);
     if (rc)
-            return rc;
+        return rc;
 
     nics = libxl_list_nics(ctx, domid, &nb);
     if (!nics)
@@ -509,7 +509,7 @@ int libxl_devid_to_device_nic(libxl_ctx 
     val = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/mac", nic_path_fe));
     rc = libxl__parse_mac(val, nic->mac);
     if (rc)
-            goto out;
+        goto out;
 
     nic->script = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, "%s/script", nic_path_be), NULL);
     rc = 0;

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH 3 of 3] libxl: add emacs local variables block to turn on four space indentation
  2011-10-07 14:08     ` [PATCH 0 of 3] libxl: fixup hard tabs and indentation Ian Campbell
  2011-10-07 14:08       ` [PATCH 1 of 3] libxl: expand hard tabs stops Ian Campbell
  2011-10-07 14:08       ` [PATCH 2 of 3] libxl: fixup incorrect indentation Ian Campbell
@ 2011-10-07 14:08       ` Ian Campbell
  2011-10-10 11:09         ` Ian Jackson
  2 siblings, 1 reply; 55+ messages in thread
From: Ian Campbell @ 2011-10-07 14:08 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian Jackson

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1317996290 -3600
# Node ID 0925bc3120d1f6474f235eea2ba9539009c47bd5
# Parent  ea75a1765a4a8da26089f42c68a1a1f15182a11f
libxl: add emacs local variables block to turn on four space indentation

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/flexarray.c
--- a/tools/libxl/flexarray.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/flexarray.c	Fri Oct 07 15:04:50 2011 +0100
@@ -107,3 +107,11 @@ void **flexarray_contents(flexarray_t *a
     free(array);
     return data;
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/flexarray.h
--- a/tools/libxl/flexarray.h	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/flexarray.h	Fri Oct 07 15:04:50 2011 +0100
@@ -35,3 +35,11 @@ _hidden int flexarray_get(flexarray_t *a
 _hidden void **flexarray_contents(flexarray_t *array);
 
 #endif
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxl.c	Fri Oct 07 15:04:50 2011 +0100
@@ -3044,3 +3044,11 @@ int libxl_cpupool_movedomain(libxl_ctx *
     libxl__free_all(&gc);
     return 0;
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxl.h	Fri Oct 07 15:04:50 2011 +0100
@@ -541,3 +541,10 @@ const char *libxl_run_dir_path(void);
 
 #endif /* LIBXL_H */
 
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxl_blktap2.c
--- a/tools/libxl/libxl_blktap2.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxl_blktap2.c	Fri Oct 07 15:04:50 2011 +0100
@@ -77,3 +77,11 @@ void libxl__device_destroy_tapdisk(libxl
 
     tap_ctl_destroy(tap.id, tap.minor);
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxl_bootloader.c
--- a/tools/libxl/libxl_bootloader.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxl_bootloader.c	Fri Oct 07 15:04:50 2011 +0100
@@ -450,3 +450,10 @@ out:
     return rc;
 }
 
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxl_cpuid.c
--- a/tools/libxl/libxl_cpuid.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxl_cpuid.c	Fri Oct 07 15:04:50 2011 +0100
@@ -326,3 +326,11 @@ void libxl_cpuid_set(libxl_ctx *ctx, uin
         xc_cpuid_set(ctx->xch, domid, cpuid[i].input,
                      (const char**)(cpuid[i].policy), cpuid_res);
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxl_create.c
--- a/tools/libxl/libxl_create.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxl_create.c	Fri Oct 07 15:04:50 2011 +0100
@@ -643,3 +643,11 @@ int libxl_domain_create_restore(libxl_ct
     libxl__free_all(&gc);
     return rc;
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxl_device.c
--- a/tools/libxl/libxl_device.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxl_device.c	Fri Oct 07 15:04:50 2011 +0100
@@ -654,3 +654,10 @@ out:
     return rc;
 }
 
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxl_dm.c
--- a/tools/libxl/libxl_dm.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxl_dm.c	Fri Oct 07 15:04:50 2011 +0100
@@ -1047,3 +1047,11 @@ int libxl__create_xenpv_qemu(libxl__gc *
     libxl__create_device_model(gc, info, NULL, 0, NULL, 0, starting_r);
     return 0;
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxl_dom.c
--- a/tools/libxl/libxl_dom.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxl_dom.c	Fri Oct 07 15:04:50 2011 +0100
@@ -813,3 +813,11 @@ out:
     libxl__free_all(&gc);
     return rc;
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxl_exec.c
--- a/tools/libxl/libxl_exec.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxl_exec.c	Fri Oct 07 15:04:50 2011 +0100
@@ -308,3 +308,11 @@ int libxl__spawn_check(libxl__gc *gc, vo
     for_spawn->intermediate = 0;
     return ERROR_FAIL;
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxl_flask.c
--- a/tools/libxl/libxl_flask.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxl_flask.c	Fri Oct 07 15:04:50 2011 +0100
@@ -69,3 +69,11 @@ int libxl_flask_loadpolicy(libxl_ctx *ct
 
     return rc;
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxl_internal.c
--- a/tools/libxl/libxl_internal.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxl_internal.c	Fri Oct 07 15:04:50 2011 +0100
@@ -318,3 +318,11 @@ int libxl__fd_set_cloexec(int fd)
     }
     return fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxl_internal.h	Fri Oct 07 15:04:50 2011 +0100
@@ -555,3 +555,11 @@ _hidden void libxl__json_object_free(lib
 _hidden libxl__json_object *libxl__json_parse(libxl__gc *gc, const char *s);
 
 #endif
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxl_json.c
--- a/tools/libxl/libxl_json.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxl_json.c	Fri Oct 07 15:04:50 2011 +0100
@@ -834,3 +834,11 @@ out:
 
     return ret;
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxl_json.h
--- a/tools/libxl/libxl_json.h	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxl_json.h	Fri Oct 07 15:04:50 2011 +0100
@@ -21,3 +21,11 @@
 #include <_libxl_types_internal_json.h>
 
 #endif /* LIBXL_JSON_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxl_noblktap2.c
--- a/tools/libxl/libxl_noblktap2.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxl_noblktap2.c	Fri Oct 07 15:04:50 2011 +0100
@@ -31,3 +31,11 @@ char *libxl__blktap_devpath(libxl__gc *g
 void libxl__device_destroy_tapdisk(libxl__gc *gc, char *be_path)
 {
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxl_nocpuid.c
--- a/tools/libxl/libxl_nocpuid.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxl_nocpuid.c	Fri Oct 07 15:04:50 2011 +0100
@@ -35,3 +35,11 @@ void libxl_cpuid_set(libxl_ctx *ctx, uin
                      libxl_cpuid_policy_list cpuid)
 {
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxl_osdeps.h
--- a/tools/libxl/libxl_osdeps.h	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxl_osdeps.h	Fri Oct 07 15:04:50 2011 +0100
@@ -39,3 +39,11 @@ int vasprintf(char **buffer, const char 
 #endif /*NEED_OWN_ASPRINTF*/
 
 #endif
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxl_paths.c
--- a/tools/libxl/libxl_paths.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxl_paths.c	Fri Oct 07 15:04:50 2011 +0100
@@ -69,3 +69,11 @@ const char *libxl_run_dir_path(void)
 {
     return XEN_RUN_DIR;
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxl_pci.c
--- a/tools/libxl/libxl_pci.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxl_pci.c	Fri Oct 07 15:04:50 2011 +0100
@@ -1305,3 +1305,11 @@ int libxl__e820_alloc(libxl__gc *gc, uin
     }
     return 0;
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxl_qmp.c
--- a/tools/libxl/libxl_qmp.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxl_qmp.c	Fri Oct 07 15:04:50 2011 +0100
@@ -594,3 +594,11 @@ int libxl__qmp_initializations(libxl_ctx
     libxl__qmp_close(qmp);
     return ret;
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxl_utils.c
--- a/tools/libxl/libxl_utils.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxl_utils.c	Fri Oct 07 15:04:50 2011 +0100
@@ -647,3 +647,11 @@ int libxl__enum_from_string(const libxl_
     }
     return ERROR_FAIL;
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxl_utils.h
--- a/tools/libxl/libxl_utils.h	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxl_utils.h	Fri Oct 07 15:04:50 2011 +0100
@@ -80,3 +80,10 @@ static inline uint32_t libxl__sizekb_to_
 
 #endif
 
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxl_uuid.c
--- a/tools/libxl/libxl_uuid.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxl_uuid.c	Fri Oct 07 15:04:50 2011 +0100
@@ -103,3 +103,11 @@ uint8_t *libxl_uuid_bytearray(libxl_uuid
 #error "Please update libxl_uuid.c for your OS"
 
 #endif
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxl_uuid.h
--- a/tools/libxl/libxl_uuid.h	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxl_uuid.h	Fri Oct 07 15:04:50 2011 +0100
@@ -62,3 +62,11 @@ int libxl_uuid_compare(libxl_uuid *uuid1
 uint8_t *libxl_uuid_bytearray(libxl_uuid *uuid);
 
 #endif /* __LIBXL_UUID_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxl_xshelp.c
--- a/tools/libxl/libxl_xshelp.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxl_xshelp.c	Fri Oct 07 15:04:50 2011 +0100
@@ -121,3 +121,11 @@ char **libxl__xs_directory(libxl__gc *gc
     libxl__ptr_add(gc, ret);
     return ret;
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxlu_cfg.c
--- a/tools/libxl/libxlu_cfg.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxlu_cfg.c	Fri Oct 07 15:04:50 2011 +0100
@@ -433,3 +433,11 @@ void xlu__cfg_yyerror(YYLTYPE *loc, CfgP
             msg);
     if (!ctx->err) ctx->err= EINVAL;
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxlu_cfg_i.h
--- a/tools/libxl/libxlu_cfg_i.h	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxlu_cfg_i.h	Fri Oct 07 15:04:50 2011 +0100
@@ -42,3 +42,11 @@ int xlu__cfg_yyparse(CfgParseContext *ct
 
 
 #endif /*LIBXLU_CFG_I_H*/
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxlu_cfg_l.c
--- a/tools/libxl/libxlu_cfg_l.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxlu_cfg_l.c	Fri Oct 07 15:04:50 2011 +0100
@@ -2122,3 +2122,11 @@ void xlu__cfg_yyfree (void * ptr , yysca
 #define YYTABLES_NAME "yytables"
 
 #line 104 "libxlu_cfg_l.l"
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxlu_cfg_l.h
--- a/tools/libxl/libxlu_cfg_l.h	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxlu_cfg_l.h	Fri Oct 07 15:04:50 2011 +0100
@@ -355,3 +355,11 @@ extern int xlu__cfg_yylex \
 #line 356 "libxlu_cfg_l.h"
 #undef xlu__cfg_yyIN_HEADER
 #endif /* xlu__cfg_yyHEADER_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxlu_cfg_y.c
--- a/tools/libxl/libxlu_cfg_y.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxlu_cfg_y.c	Fri Oct 07 15:04:50 2011 +0100
@@ -1689,3 +1689,11 @@ yyreturn:
 
 
 
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxlu_cfg_y.h
--- a/tools/libxl/libxlu_cfg_y.h	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxlu_cfg_y.h	Fri Oct 07 15:04:50 2011 +0100
@@ -85,3 +85,11 @@ typedef struct YYLTYPE
 #endif
 
 
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxlu_disk.c
--- a/tools/libxl/libxlu_disk.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxlu_disk.c	Fri Oct 07 15:04:50 2011 +0100
@@ -91,3 +91,10 @@ int xlu_disk_parse(XLU_Config *cfg,
     return dpc.err;
 }
 
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxlu_disk_i.h
--- a/tools/libxl/libxlu_disk_i.h	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxlu_disk_i.h	Fri Oct 07 15:04:50 2011 +0100
@@ -19,3 +19,11 @@ void xlu__disk_err(DiskParseContext *dpc
 
 
 #endif /*LIBXLU_DISK_I_H*/
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxlu_disk_l.c
--- a/tools/libxl/libxlu_disk_l.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxlu_disk_l.c	Fri Oct 07 15:04:50 2011 +0100
@@ -2515,3 +2515,11 @@ void xlu__disk_yyfree (void * ptr , yysc
 #define YYTABLES_NAME "yytables"
 
 #line 227 "libxlu_disk_l.l"
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxlu_disk_l.h
--- a/tools/libxl/libxlu_disk_l.h	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxlu_disk_l.h	Fri Oct 07 15:04:50 2011 +0100
@@ -345,3 +345,11 @@ extern int xlu__disk_yylex (yyscan_t yys
 #line 346 "libxlu_disk_l.h"
 #undef xlu__disk_yyIN_HEADER
 #endif /* xlu__disk_yyHEADER_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxlu_internal.h
--- a/tools/libxl/libxlu_internal.h	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxlu_internal.h	Fri Oct 07 15:04:50 2011 +0100
@@ -50,3 +50,11 @@ typedef struct {
 #define TOSTRING(x) STRINGIFY(x)
 
 #endif /*LIBXLU_INTERNAL_H*/
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/libxlutil.h
--- a/tools/libxl/libxlutil.h	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/libxlutil.h	Fri Oct 07 15:04:50 2011 +0100
@@ -82,3 +82,11 @@ int xlu_disk_parse(XLU_Config *cfg, int 
 
 
 #endif /* LIBXLUTIL_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/osdeps.c
--- a/tools/libxl/osdeps.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/osdeps.c	Fri Oct 07 15:04:50 2011 +0100
@@ -66,3 +66,11 @@ int asprintf(char **buffer, char *fmt, .
 }
 
 #endif
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/xl.c
--- a/tools/libxl/xl.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/xl.c	Fri Oct 07 15:04:50 2011 +0100
@@ -162,3 +162,11 @@ int main(int argc, char **argv)
     xtl_logger_destroy((xentoollog_logger*)logger);
     return ret;
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/xl.h
--- a/tools/libxl/xl.h	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/xl.h	Fri Oct 07 15:04:50 2011 +0100
@@ -109,3 +109,11 @@ extern char *lockfile;
 extern char *default_vifscript;
 
 #endif /* XL_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/xl_cmdimpl.c	Fri Oct 07 15:04:50 2011 +0100
@@ -5413,3 +5413,11 @@ done:
 
     return ret;
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff -r ea75a1765a4a -r 0925bc3120d1 tools/libxl/xl_cmdtable.c
--- a/tools/libxl/xl_cmdtable.c	Fri Oct 07 15:04:29 2011 +0100
+++ b/tools/libxl/xl_cmdtable.c	Fri Oct 07 15:04:50 2011 +0100
@@ -407,3 +407,11 @@ struct cmd_spec *cmdtable_lookup(const c
     }
     return (count == 1) ? cmd : NULL;
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 3 of 3] libxl: add emacs local variables block to turn on four space indentation
  2011-10-07 14:08       ` [PATCH 3 of 3] libxl: add emacs local variables block to turn on four space indentation Ian Campbell
@ 2011-10-10 11:09         ` Ian Jackson
  0 siblings, 0 replies; 55+ messages in thread
From: Ian Jackson @ 2011-10-10 11:09 UTC (permalink / raw)
  To: Ian Campbell; +Cc: xen-devel

Ian Campbell writes ("[Xen-devel] [PATCH 3 of 3] libxl: add emacs local variables block to turn on four space indentation"):
> libxl: add emacs local variables block to turn on four space indentation

FYI Emacs 23 has a new ".dir-locals.el" feature, but I think we should
wait a while before starting to use it.

The rest of this series looks OK to me.  I'll see if I can apply the
other things in the libxl queue first though.

Ian.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: RE: [PATCH 02 of 23] libxl: add a comment describing the device interfaces
  2011-10-04  9:38     ` Ian Campbell
@ 2011-10-11 12:59       ` Roger Pau Monné
  2011-10-12 15:27         ` Ian Campbell
  0 siblings, 1 reply; 55+ messages in thread
From: Roger Pau Monné @ 2011-10-11 12:59 UTC (permalink / raw)
  To: Ian Campbell
  Cc: Mike McClurg, xen-devel, Dave Scott, Jim Fehlig, Jonathan Ludlam

Hello,

I've applied this patches to my tree and modified my NetBSD hotplug
and phy backend patches to conform to the new API. From what I can see
the patches work ok, except for the small bugs that I've commented on
some individual patches.

Should I wait for this patches to be committed to the Xen repository
before sending my own, or is it fine to post them for review now?

Regards, Roger.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH 2 of 3] libxl: fixup incorrect indentation
  2011-10-07 14:08       ` [PATCH 2 of 3] libxl: fixup incorrect indentation Ian Campbell
@ 2011-10-12 15:23         ` Ian Jackson
  0 siblings, 0 replies; 55+ messages in thread
From: Ian Jackson @ 2011-10-12 15:23 UTC (permalink / raw)
  To: Ian Campbell; +Cc: xen-devel

Ian Campbell writes ("[Xen-devel] [PATCH 2 of 3] libxl: fixup incorrect indentation"):
> libxl: fixup incorrect indentation

Applied all 3.  3/3 contained a change to libxl_json.h which seems to
have gone missing, but it builds fine without.

Ian.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: RE: [PATCH 02 of 23] libxl: add a comment describing the device interfaces
  2011-10-11 12:59       ` Roger Pau Monné
@ 2011-10-12 15:27         ` Ian Campbell
  0 siblings, 0 replies; 55+ messages in thread
From: Ian Campbell @ 2011-10-12 15:27 UTC (permalink / raw)
  To: Roger Pau Monné
  Cc: Mike McClurg, xen-devel, Dave Scott, Jim Fehlig, Jonathan Ludlam

On Tue, 2011-10-11 at 13:59 +0100, Roger Pau Monné wrote:
> Hello,
> 
> I've applied this patches to my tree and modified my NetBSD hotplug
> and phy backend patches to conform to the new API. From what I can see
> the patches work ok, except for the small bugs that I've commented on
> some individual patches.
> 
> Should I wait for this patches to be committed to the Xen repository
> before sending my own, or is it fine to post them for review now?

I would post them for review. I do have a second revision which I'm
about to post, which is mainly a change to the IDL type destructors to
"dispose" instead of "destroy" and  "s/force_remove/destroy/" but that
needn't stop us reviewing your changes.

Ian.

^ permalink raw reply	[flat|nested] 55+ messages in thread

end of thread, other threads:[~2011-10-12 15:27 UTC | newest]

Thread overview: 55+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-30 13:33 [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Ian Campbell
2011-09-30 13:33 ` [PATCH 01 of 23] libxl: remove hard tabs from non-generated *.[ch] Ian Campbell
2011-10-06 16:34   ` Ian Jackson
2011-10-07  8:37     ` Ian Campbell
2011-10-07 14:08     ` [PATCH 0 of 3] libxl: fixup hard tabs and indentation Ian Campbell
2011-10-07 14:08       ` [PATCH 1 of 3] libxl: expand hard tabs stops Ian Campbell
2011-10-07 14:08       ` [PATCH 2 of 3] libxl: fixup incorrect indentation Ian Campbell
2011-10-12 15:23         ` Ian Jackson
2011-10-07 14:08       ` [PATCH 3 of 3] libxl: add emacs local variables block to turn on four space indentation Ian Campbell
2011-10-10 11:09         ` Ian Jackson
2011-09-30 13:33 ` [PATCH 02 of 23] libxl: add a comment describing the device interfaces Ian Campbell
2011-10-04  8:53   ` Dave Scott
2011-10-04  9:38     ` Ian Campbell
2011-10-11 12:59       ` Roger Pau Monné
2011-10-12 15:27         ` Ian Campbell
2011-09-30 13:33 ` [PATCH 03 of 23] libxl: various fixes to libxl_device_disk_list (and internals) Ian Campbell
2011-09-30 13:33 ` [PATCH 04 of 23] libxl: refactor code to construct disk from xenstore backend Ian Campbell
2011-09-30 13:33 ` [PATCH 05 of 23] libxl: do not read f.e. xenstore dir in disk list function Ian Campbell
2011-09-30 13:33 ` [PATCH 06 of 23] libxl: update nic list API to use common device API style Ian Campbell
2011-10-05 12:48   ` [PATCH] " Roger Pau Monne
2011-10-05 13:10     ` Ian Campbell
2011-10-05 13:22       ` Roger Pau Monné
2011-10-05 13:42         ` Ian Campbell
2011-09-30 13:33 ` [PATCH 07 of 23] libxl: reimplement devid->nic in terms of from_xs_be function Ian Campbell
2011-09-30 13:33 ` [PATCH 08 of 23] libxl: reimplement devid->disk " Ian Campbell
2011-09-30 13:33 ` [PATCH 09 of 23] libxl: libxl_devid_to_* should take an integer device id Ian Campbell
2011-09-30 13:33 ` [PATCH 10 of 23] libxl: separate forced and non-forced device remove Ian Campbell
2011-10-06 16:38   ` Ian Jackson
2011-10-07  8:44     ` Ian Campbell
2011-10-07 13:08       ` Ian Jackson
2011-09-30 13:33 ` [PATCH 11 of 23] libxl: split forced and non-forced uses of libxl__device_del Ian Campbell
2011-09-30 13:33 ` [PATCH 12 of 23] libxl: use IDL to define device front- and back-end kinds Ian Campbell
2011-09-30 13:33 ` [PATCH 13 of 23] libxl: do not remove unidentified frontend paths in libxl__devices_destroy Ian Campbell
2011-09-30 13:33 ` [PATCH 14 of 23] libxl: use libxl__device in libxl_devices_destroy and libxl__device_pci_remove_xenstore Ian Campbell
2011-10-07 12:18   ` Roger Pau Monné
2011-10-07 12:24     ` Ian Campbell
2011-10-07 12:26       ` Ian Campbell
2011-09-30 13:33 ` [PATCH 15 of 23] libxl: merge libxl__device_del into libxl__device_remove Ian Campbell
2011-09-30 13:33 ` [PATCH 16 of 23] libxl: use more descriptive variable names in libxl__devices_destroy Ian Campbell
2011-09-30 13:33 ` [PATCH 17 of 23] libxl: convert disk handling to device API Ian Campbell
2011-09-30 13:33 ` [PATCH 18 of 23] libxl: convert NIC " Ian Campbell
2011-09-30 13:33 ` [PATCH 19 of 23] libxl: remove libxl_device_console_add Ian Campbell
2011-09-30 13:33 ` [PATCH 20 of 23] libxl: convert VKB handling to device API Ian Campbell
2011-09-30 13:33 ` [PATCH 21 " Ian Campbell
2011-09-30 13:33 ` [PATCH 22 of 23] libxl: reorder device functions to put functions for each device together Ian Campbell
2011-09-30 13:33 ` [PATCH 23 of 23] libxl: convert PCI device handling to device API Ian Campbell
2011-10-04  7:32 ` [PATCH 00 of 23] libxl: rationalise libxl_device_* APIs Roger Pau Monné
2011-10-04  8:12   ` Ian Campbell
2011-10-04  8:32     ` Ian Campbell
2011-10-05  9:04       ` Roger Pau Monné
2011-10-05  9:33         ` Ian Campbell
2011-10-05 11:59           ` Roger Pau Monné
2011-10-05 13:08             ` Ian Campbell
2011-10-05 13:15               ` Roger Pau Monné
2011-10-06 16:43 ` Ian Jackson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.