Skip to contentSkip to conversation

libxl: change libxl__xs_write() to libxl__xs_printf()

PATCH In review Paul Durrant 2 participants 10 messages Dec 1, 2015 – Dec 15, 2015

lore
Share & tools
lore
#1 lore raw

PATCH 1/2 libxl: re-name libxl__xs_write() to libxl__xs_printf()...

In reply to Paul Durrant

...to denote what it actually does.

The name libxl__xs_write() suggests something taking a buffer and length, akin to write(2), whereas the semantics of the function are actually more akin to printf(3).

This patch is a textual substitution of libxl__xs_write with libxl__xs_printf with some associated formatting fixes.

---
 tools/libxl/libxl.c            | 47 +++++++++++++++++++++---------------------
 tools/libxl/libxl_bootloader.c |  4 ++--
 tools/libxl/libxl_create.c     |  4 ++--
 tools/libxl/libxl_dm.c         | 36 ++++++++++++++++----------------
 tools/libxl/libxl_dom.c        | 23 +++++++++++----------
 tools/libxl/libxl_exec.c       |  2 +-
 tools/libxl/libxl_genid.c      |  6 +++---
 tools/libxl/libxl_internal.h   |  4 ++--
 tools/libxl/libxl_pci.c        | 22 ++++++++++----------
 tools/libxl/libxl_qmp.c        |  4 ++--
 tools/libxl/libxl_xshelp.c     |  4 ++--
 11 files changed, 79 insertions(+), 77 deletions(-)
tools/libxl/libxl.c +24 -23
index bd3aac8..bd604ac 100644
@@ -1136,7 +1136,7 @@ int libxl__domain_pvcontrol_write(libxl__gc *gc, xs_transaction_t t,
     if (!shutdown_path)
         return ERROR_FAIL;
 
-    return libxl__xs_write(gc, t, shutdown_path, "%s", cmd);
+    return libxl__xs_printf(gc, t, shutdown_path, "%s", cmd);
 }
 
 static int libxl__domain_pvcontrol(libxl__gc *gc, uint32_t domid,
@@ -1364,7 +1364,7 @@ static void disk_eject_xswatch_callback(libxl__egc *egc, libxl__ev_xswatch *w,
     if (!value || strcmp(value,  "eject"))
         return;
 
-    if (libxl__xs_write(gc, XBT_NULL, wpath, "")) {
+    if (libxl__xs_printf(gc, XBT_NULL, wpath, "")) {
         LIBXL__EVENT_DISASTER(egc, "xs_write failed acknowledging eject",
                               errno, LIBXL_EVENT_TYPE_DISK_EJECT);
         return;
@@ -4696,13 +4696,13 @@ retry_transaction:
         goto out;
 
     if (target == NULL) {
-        libxl__xs_write(gc, t, target_path, "%"PRIu32,
-                (uint32_t) info.current_memkb);
+        libxl__xs_printf(gc, t, target_path, "%"PRIu32,
+                         (uint32_t) info.current_memkb);
         *target_memkb = (uint32_t) info.current_memkb;
     }
     if (staticmax == NULL) {
-        libxl__xs_write(gc, t, max_path, "%"PRIu32,
-                        (uint32_t) info.max_memkb);
+        libxl__xs_printf(gc, t, max_path, "%"PRIu32,
+                         (uint32_t) info.max_memkb);
         *max_memkb = (uint32_t) info.max_memkb;
     }
 
@@ -4839,8 +4839,8 @@ retry_transaction:
         goto out;
     }
 
-    libxl__xs_write(gc, t, GCSPRINTF("%s/memory/target",
-                dompath), "%"PRIu32, new_target_memkb);
+    libxl__xs_printf(gc, t, GCSPRINTF("%s/memory/target", dompath),
+                     "%"PRIu32, new_target_memkb);
     rc = xc_domain_getinfolist(ctx->xch, domid, 1, &info);
     if (rc != 1 || info.domain != domid) {
         abort_transaction = 1;
@@ -4850,8 +4850,8 @@ retry_transaction:
     libxl_dominfo_init(&ptr);
     xcinfo2xlinfo(ctx, &info, &ptr);
     uuid = libxl__uuid2string(gc, ptr.uuid);
-    libxl__xs_write(gc, t, GCSPRINTF("/vm/%s/memory", uuid),
-            "%"PRIu32, new_target_memkb / 1024);
+    libxl__xs_printf(gc, t, GCSPRINTF("/vm/%s/memory", uuid),
+                     "%"PRIu32, new_target_memkb / 1024);
     libxl_dominfo_dispose(&ptr);
 
 out:
@@ -5486,9 +5486,9 @@ static int libxl__set_vcpuonline_xenstore(libxl__gc *gc, uint32_t domid,
 retry_transaction:
     t = xs_transaction_start(CTX->xsh);
     for (i = 0; i <= info->vcpu_max_id; i++)
-        libxl__xs_write(gc, t,
-                       GCSPRINTF("%s/cpu/%u/availability", dompath, i),
-                       "%s", libxl_bitmap_test(cpumap, i) ? "online" : "offline");
+        libxl__xs_printf(gc, t,
+                         GCSPRINTF("%s/cpu/%u/availability", dompath, i),
+                         "%s", libxl_bitmap_test(cpumap, i) ? "online" : "offline");
     if (!xs_transaction_end(CTX->xsh, t, 0)) {
         if (errno == EAGAIN)
             goto retry_transaction;
@@ -5984,7 +5984,8 @@ int libxl_send_sysrq(libxl_ctx *ctx, uint32_t domid, char sysrq)
     GC_INIT(ctx);
     char *dompath = libxl__xs_get_dompath(gc, domid);
 
-    libxl__xs_write(gc, XBT_NULL, GCSPRINTF("%s/control/sysrq", dompath), "%c", sysrq);
+    libxl__xs_printf(gc, XBT_NULL, GCSPRINTF("%s/control/sysrq", dompath),
+                     "%c", sysrq);
 
     GC_FREE;
     return 0;
@@ -6262,12 +6263,12 @@ int libxl_cpupool_create(libxl_ctx *ctx, const char *name,
         t = xs_transaction_start(ctx->xsh);
 
         xs_mkdir(ctx->xsh, t, GCSPRINTF("/local/pool/%d", *poolid));
-        libxl__xs_write(gc, t,
-                        GCSPRINTF("/local/pool/%d/uuid", *poolid),
-                        "%s", uuid_string);
-        libxl__xs_write(gc, t,
-                        GCSPRINTF("/local/pool/%d/name", *poolid),
-                        "%s", name);
+        libxl__xs_printf(gc, t,
+                         GCSPRINTF("/local/pool/%d/uuid", *poolid),
+                         "%s", uuid_string);
+        libxl__xs_printf(gc, t,
+                         GCSPRINTF("/local/pool/%d/name", *poolid),
+                         "%s", name);
 
         if (xs_transaction_end(ctx->xsh, t, 0) || (errno != EAGAIN)) {
             GC_FREE;
@@ -6358,9 +6359,9 @@ int libxl_cpupool_rename(libxl_ctx *ctx, const char *name, uint32_t poolid)
     for (;;) {
         t = xs_transaction_start(ctx->xsh);
 
-        libxl__xs_write(gc, t,
-                        GCSPRINTF("/local/pool/%d/name", poolid),
-                        "%s", name);
+        libxl__xs_printf(gc, t,
+                         GCSPRINTF("/local/pool/%d/name", poolid),
+                         "%s", name);
 
         if (xs_transaction_end(ctx->xsh, t, 0))
             break;
tools/libxl/libxl_bootloader.c +2 -2
index 343fc30..0ae074a 100644
@@ -485,8 +485,8 @@ static void bootloader_gotptys(libxl__egc *egc, libxl__openpty_state *op)
 
     dom_console_xs_path = GCSPRINTF("%s/console/tty", dompath);
 
-    rc = libxl__xs_write(gc, XBT_NULL, dom_console_xs_path, "%s",
-                         dom_console_slave_tty_path);
+    rc = libxl__xs_printf(gc, XBT_NULL, dom_console_xs_path, "%s",
+                          dom_console_slave_tty_path);
     if (rc) {
         LOGE(ERROR,"xs write console path %s := %s failed",
              dom_console_xs_path, dom_console_slave_tty_path);
tools/libxl/libxl_create.c +2 -2
index 673e537..01ab831 100644
@@ -678,8 +678,8 @@ static int store_libxl_entry(libxl__gc *gc, uint32_t domid,
 
     path = libxl__xs_libxl_path(gc, domid);
     path = GCSPRINTF("%s/dm-version", path);
-    return libxl__xs_write(gc, XBT_NULL, path, "%s",
-        libxl_device_model_version_to_string(b_info->device_model_version));
+    return libxl__xs_printf(gc, XBT_NULL, path, "%s",
+                            libxl_device_model_version_to_string(b_info->device_model_version));
 }
 
 /*----- remus asynchronous checkpoint callback -----*/
tools/libxl/libxl_dm.c +18 -18
index a4934df..2de0273 100644
@@ -1535,14 +1535,14 @@ void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state *sdss)
     }
 
     libxl__write_stub_dmargs(gc, dm_domid, guest_domid, args);
-    libxl__xs_write(gc, XBT_NULL,
-                   GCSPRINTF("%s/image/device-model-domid",
-                                  libxl__xs_get_dompath(gc, guest_domid)),
-                   "%d", dm_domid);
-    libxl__xs_write(gc, XBT_NULL,
-                   GCSPRINTF("%s/target",
-                                  libxl__xs_get_dompath(gc, dm_domid)),
-                   "%d", guest_domid);
+    libxl__xs_printf(gc, XBT_NULL,
+                     GCSPRINTF("%s/image/device-model-domid",
+                               libxl__xs_get_dompath(gc, guest_domid)),
+                     "%d", dm_domid);
+    libxl__xs_printf(gc, XBT_NULL,
+                     GCSPRINTF("%s/target",
+                               libxl__xs_get_dompath(gc, dm_domid)),
+                     "%d", guest_domid);
     ret = xc_domain_set_target(ctx->xch, dm_domid, guest_domid);
     if (ret<0) {
         LOGE(ERROR, "setting target domain %d -> %d", dm_domid, guest_domid);
@@ -1816,17 +1816,17 @@ void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state *dmss)
 
     if (b_info->type == LIBXL_DOMAIN_TYPE_HVM) {
         path = xs_get_domain_path(ctx->xsh, domid);
-        libxl__xs_write(gc, XBT_NULL,
-                        GCSPRINTF("%s/hvmloader/bios", path),
-                        "%s", libxl_bios_type_to_string(b_info->u.hvm.bios));
+        libxl__xs_printf(gc, XBT_NULL,
+                         GCSPRINTF("%s/hvmloader/bios", path),
+                         "%s", libxl_bios_type_to_string(b_info->u.hvm.bios));
         /* Disable relocating memory to make the MMIO hole larger
          * unless we're running qemu-traditional and vNUMA is not
          * configured. */
-        libxl__xs_write(gc, XBT_NULL,
-                        GCSPRINTF("%s/hvmloader/allow-memory-relocate", path),
-                        "%d",
-                        b_info->device_model_version==LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL &&
-                        !libxl__vnuma_configured(b_info));
+        libxl__xs_printf(gc, XBT_NULL,
+                         GCSPRINTF("%s/hvmloader/allow-memory-relocate", path),
+                         "%d",
+                         b_info->device_model_version==LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL &&
+                         !libxl__vnuma_configured(b_info));
         free(path);
     }
 
@@ -1836,8 +1836,8 @@ void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state *dmss)
     if (b_info->type == LIBXL_DOMAIN_TYPE_HVM &&
         b_info->device_model_version
         == LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL)
-        libxl__xs_write(gc, XBT_NULL, GCSPRINTF("%s/disable_pf", path),
-                    "%d", !libxl_defbool_val(b_info->u.hvm.xen_platform_pci));
+        libxl__xs_printf(gc, XBT_NULL, GCSPRINTF("%s/disable_pf", path),
+                         "%d", !libxl_defbool_val(b_info->u.hvm.xen_platform_pci));
 
     logfile_w = libxl__create_qemu_logfile(gc, GCSPRINTF("qemu-dm-%s",
                                                          c_info->name));
tools/libxl/libxl_dom.c +12 -11
index 44d481b..517e838 100644
@@ -825,15 +825,15 @@ static int hvm_build_set_xs_values(libxl__gc *gc,
     if (dom->smbios_module.guest_addr_out) {
         path = GCSPRINTF("/local/domain/%d/"HVM_XS_SMBIOS_PT_ADDRESS, domid);
 
-        ret = libxl__xs_write(gc, XBT_NULL, path, "0x%"PRIx64,
-                              dom->smbios_module.guest_addr_out);
+        ret = libxl__xs_printf(gc, XBT_NULL, path, "0x%"PRIx64,
+                               dom->smbios_module.guest_addr_out);
         if (ret)
             goto err;
 
         path = GCSPRINTF("/local/domain/%d/"HVM_XS_SMBIOS_PT_LENGTH, domid);
 
-        ret = libxl__xs_write(gc, XBT_NULL, path, "0x%x",
-                              dom->smbios_module.length);
+        ret = libxl__xs_printf(gc, XBT_NULL, path, "0x%x",
+                               dom->smbios_module.length);
         if (ret)
             goto err;
     }
@@ -841,15 +841,15 @@ static int hvm_build_set_xs_values(libxl__gc *gc,
     if (dom->acpi_module.guest_addr_out) {
         path = GCSPRINTF("/local/domain/%d/"HVM_XS_ACPI_PT_ADDRESS, domid);
 
-        ret = libxl__xs_write(gc, XBT_NULL, path, "0x%"PRIx64,
-                              dom->acpi_module.guest_addr_out);
+        ret = libxl__xs_printf(gc, XBT_NULL, path, "0x%"PRIx64,
+                               dom->acpi_module.guest_addr_out);
         if (ret)
             goto err;
 
         path = GCSPRINTF("/local/domain/%d/"HVM_XS_ACPI_PT_LENGTH, domid);
 
-        ret = libxl__xs_write(gc, XBT_NULL, path, "0x%x",
-                              dom->acpi_module.length);
+        ret = libxl__xs_printf(gc, XBT_NULL, path, "0x%x",
+                               dom->acpi_module.length);
         if (ret)
             goto err;
     }
@@ -1074,7 +1074,7 @@ int libxl__qemu_traditional_cmd(libxl__gc *gc, uint32_t domid,
     char *path = NULL;
     uint32_t dm_domid = libxl_get_stubdom_id(CTX, domid);
     path = libxl__device_model_xs_path(gc, dm_domid, domid, "/command");
-    return libxl__xs_write(gc, XBT_NULL, path, "%s", cmd);
+    return libxl__xs_printf(gc, XBT_NULL, path, "%s", cmd);
 }
 
 /*
@@ -1137,8 +1137,9 @@ int libxl__restore_emulator_xenstore_data(libxl__domain_create_state *dcs,
             goto out;
         }
 
-        libxl__xs_write(gc, XBT_NULL,
-                        GCSPRINTF("%s/%s", xs_root, key), "%s", val);
+        libxl__xs_printf(gc, XBT_NULL,
+                         GCSPRINTF("%s/%s", xs_root, key),
+                         "%s", val);
     }
 
     rc = 0;
tools/libxl/libxl_exec.c +1 -1
index df4aead..02e6c91 100644
@@ -144,7 +144,7 @@ int libxl__spawn_record_pid(libxl__gc *gc, libxl__spawn_state *spawn, pid_t pid)
     rc = libxl__ev_child_xenstore_reopen(gc, spawn->what);
     if (rc) goto out;
 
-    r = libxl__xs_write(gc, XBT_NULL, spawn->pidpath, "%d", pid);
+    r = libxl__xs_printf(gc, XBT_NULL, spawn->pidpath, "%d", pid);
     if (r) {
         LOGE(ERROR,
              "write %s = %d: xenstore write failed", spawn->pidpath, pid);
tools/libxl/libxl_genid.c +3 -3
index 4e2f013..f1c4eb7 100644
@@ -77,9 +77,9 @@ int libxl__ms_vm_genid_set(libxl__gc *gc, uint32_t domid,
         rc = ERROR_FAIL;
         goto out;
     }
-    rc = libxl__xs_write(gc, XBT_NULL,
-                         GCSPRINTF("%s/platform/generation-id", dom_path),
-                         "%"PRIu64 ":%" PRIu64, genid[0], genid[1]);
+    rc = libxl__xs_printf(gc, XBT_NULL,
+			  GCSPRINTF("%s/platform/generation-id", dom_path),
+			  "%"PRIu64 ":%" PRIu64, genid[0], genid[1]);
     if (rc < 0)
         goto out;
 
tools/libxl/libxl_internal.h +2 -2
index 1b99cd5..12b2b30 100644
@@ -667,7 +667,7 @@ _hidden int libxl__xs_writev_perms(libxl__gc *gc, xs_transaction_t t,
 _hidden int libxl__xs_writev_atonce(libxl__gc *gc,
                              const char *dir, char **kvs);
 
-_hidden int libxl__xs_write(libxl__gc *gc, xs_transaction_t t,
+_hidden int libxl__xs_printf(libxl__gc *gc, xs_transaction_t t,
                const char *path, const char *fmt, ...) PRINTF_ATTRIBUTE(4, 5);
    /* Each fn returns 0 on success.
     * On error: returns -1, sets errno (no logging) */
@@ -702,7 +702,7 @@ int libxl__xs_read_checked(libxl__gc *gc, xs_transaction_t t,
 
 /* Does not include a trailing null.
  * May usefully be combined with GCSPRINTF if the format string
- * behaviour of libxl__xs_write is desirable. */
+ * behaviour of libxl__xs_printf is desirable. */
 int libxl__xs_write_checked(libxl__gc *gc, xs_transaction_t t,
                             const char *path, const char *string);
 
tools/libxl/libxl_pci.c +11 -11
index 206b300..dc10cb7 100644
@@ -254,7 +254,7 @@ retry_transaction2:
     xs_rm(ctx->xsh, t, GCSPRINTF("%s/vdev-%d", be_path, i));
     xs_rm(ctx->xsh, t, GCSPRINTF("%s/opts-%d", be_path, i));
     xs_rm(ctx->xsh, t, GCSPRINTF("%s/vdevfn-%d", be_path, i));
-    libxl__xs_write(gc, t, num_devs_path, "%d", num - 1);
+    libxl__xs_printf(gc, t, num_devs_path, "%d", num - 1);
     for (j = i + 1; j < num; j++) {
         tmppath = GCSPRINTF("%s/state-%d", be_path, j);
         tmp = libxl__xs_read(gc, t, tmppath);
@@ -733,7 +733,7 @@ static void pci_assignable_driver_path_write(libxl__gc *gc,
                      pcidev->bus,
                      pcidev->dev,
                      pcidev->func);
-    if ( libxl__xs_write(gc, XBT_NULL, path, "%s", driver_path) < 0 ) {
+    if ( libxl__xs_printf(gc, XBT_NULL, path, "%s", driver_path) < 0 ) {
         LOGE(WARN, "Write of %s to node %s failed.", driver_path, path);
     }
 }
@@ -971,14 +971,14 @@ static int qemu_pci_add_xenstore(libxl__gc *gc, uint32_t domid,
     state = libxl__xs_read(gc, XBT_NULL, path);
     path = libxl__device_model_xs_path(gc, dm_domid, domid, "/parameter");
     if (pcidev->vdevfn) {
-        libxl__xs_write(gc, XBT_NULL, path, PCI_BDF_VDEVFN","PCI_OPTIONS,
-                        pcidev->domain, pcidev->bus, pcidev->dev,
-                        pcidev->func, pcidev->vdevfn, pcidev->msitranslate,
-                        pcidev->power_mgmt);
+        libxl__xs_printf(gc, XBT_NULL, path, PCI_BDF_VDEVFN","PCI_OPTIONS,
+                         pcidev->domain, pcidev->bus, pcidev->dev,
+                         pcidev->func, pcidev->vdevfn, pcidev->msitranslate,
+                         pcidev->power_mgmt);
     } else {
-        libxl__xs_write(gc, XBT_NULL, path, PCI_BDF","PCI_OPTIONS,
-                        pcidev->domain,  pcidev->bus, pcidev->dev,
-                        pcidev->func, pcidev->msitranslate, pcidev->power_mgmt);
+        libxl__xs_printf(gc, XBT_NULL, path, PCI_BDF","PCI_OPTIONS,
+                         pcidev->domain,  pcidev->bus, pcidev->dev,
+                         pcidev->func, pcidev->msitranslate, pcidev->power_mgmt);
     }
 
     libxl__qemu_traditional_cmd(gc, domid, "pci-ins");
@@ -1310,8 +1310,8 @@ static int qemu_pci_remove_xenstore(libxl__gc *gc, uint32_t domid,
     path = libxl__device_model_xs_path(gc, dm_domid, domid, "/state");
     state = libxl__xs_read(gc, XBT_NULL, path);
     path = libxl__device_model_xs_path(gc, dm_domid, domid, "/parameter");
-    libxl__xs_write(gc, XBT_NULL, path, PCI_BDF, pcidev->domain,
-                    pcidev->bus, pcidev->dev, pcidev->func);
+    libxl__xs_printf(gc, XBT_NULL, path, PCI_BDF, pcidev->domain,
+                     pcidev->bus, pcidev->dev, pcidev->func);
 
     /* Remove all functions at once atomically by only signalling
      * device-model for function 0 */
tools/libxl/libxl_qmp.c +2 -2
index f798de7..714038b 100644
@@ -103,7 +103,7 @@ static int store_serial_port_info(libxl__qmp_handler *qmp,
     path = libxl__xs_get_dompath(gc, qmp->domid);
     path = GCSPRINTF("%s/serial/%d/tty", path, port);
 
-    ret = libxl__xs_write(gc, XBT_NULL, path, "%s", chardev + 4);
+    ret = libxl__xs_printf(gc, XBT_NULL, path, "%s", chardev + 4);
 
     GC_FREE;
     return ret;
@@ -162,7 +162,7 @@ static int qmp_write_domain_console_item(libxl__gc *gc, int domid,
     path = libxl__xs_get_dompath(gc, domid);
     path = GCSPRINTF("%s/console/%s", path, item);
 
-    return libxl__xs_write(gc, XBT_NULL, path, "%s", value);
+    return libxl__xs_printf(gc, XBT_NULL, path, "%s", value);
 }
 
 static int qmp_register_vnc_callback(libxl__qmp_handler *qmp,
tools/libxl/libxl_xshelp.c +2 -2
index 46c6d6c..912a1f2 100644
@@ -96,8 +96,8 @@ out:
 
 }
 
-int libxl__xs_write(libxl__gc *gc, xs_transaction_t t,
-                    const char *path, const char *fmt, ...)
+int libxl__xs_printf(libxl__gc *gc, xs_transaction_t t,
+                     const char *path, const char *fmt, ...)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
     char *s;
Signature · 1 line
2.1.4
#2 lore raw

PATCH 2/2 libxl: re-implement libxl__xs_printf()

In reply to Paul Durrant

This patch adds a new libxl__xs_vprintf() which actually checks the success of the underlying call to xs_write() (logging if it fails) and then re-implements libxl__xs_printf() using this (and replacing the call to vasprintf() with a call to libxl__vsprintf()).

libxl__xs_vprintf() is added to the 'checked' section of libxl_internal.h and, since it now underpins libxl__xs_printf(), that declaration is moved into the same section.

Looking at call sites of libxl__xs_printf() it seems as though several of them expected a failure if the underlying xs_write() failed, so this patch should actually fulfil the semantic that was intended all along.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
---
 tools/libxl/libxl_internal.h |  8 +++++---
 tools/libxl/libxl_xshelp.c   | 32 ++++++++++++++++++++++----------
 2 files changed, 27 insertions(+), 13 deletions(-)
tools/libxl/libxl_internal.h +5 -3
index 12b2b30..e5000cf 100644
@@ -666,9 +666,6 @@ _hidden int libxl__xs_writev_perms(libxl__gc *gc, xs_transaction_t t,
 /* _atonce creates a transaction and writes all keys at once */
 _hidden int libxl__xs_writev_atonce(libxl__gc *gc,
                              const char *dir, char **kvs);
-
-_hidden int libxl__xs_printf(libxl__gc *gc, xs_transaction_t t,
-               const char *path, const char *fmt, ...) PRINTF_ATTRIBUTE(4, 5);
    /* Each fn returns 0 on success.
     * On error: returns -1, sets errno (no logging) */
 
@@ -688,6 +685,11 @@ _hidden char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid);
  * fails it logs and returns ERROR_FAIL.
  */
 
+int libxl__xs_vprintf(libxl__gc *gc, xs_transaction_t t,
+                      const char *path, const char *fmt, va_list ap);
+int libxl__xs_printf(libxl__gc *gc, xs_transaction_t t,
+                     const char *path, const char *fmt, ...) PRINTF_ATTRIBUTE(4, 5);
+
 /* On success, path will exist and will be empty */
 int libxl__xs_mknod(libxl__gc *gc, xs_transaction_t t,
                     const char *path, struct xs_permissions *perms,
tools/libxl/libxl_xshelp.c +22 -10
index 912a1f2..930b458 100644
@@ -96,23 +96,35 @@ out:
 
 }
 
-int libxl__xs_printf(libxl__gc *gc, xs_transaction_t t,
-                     const char *path, const char *fmt, ...)
+int libxl__xs_vprintf(libxl__gc *gc, xs_transaction_t t,
+                      const char *path, const char *fmt, va_list ap)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
     char *s;
+    bool ok;
+
+    s = libxl__vsprintf(gc, fmt, ap);
+
+    ok = xs_write(ctx->xsh, t, path, s, strlen(s));
+    if (!ok) {
+        LOGE(ERROR, "xenstore write failed: `%s' = `%s'", path, s);
+        return ERROR_FAIL;
+    }
+
+    return 0;
+}
+
+int libxl__xs_printf(libxl__gc *gc, xs_transaction_t t,
+                     const char *path, const char *fmt, ...)
+{
     va_list ap;
-    int ret;
+    int rc;
+
     va_start(ap, fmt);
-    ret = vasprintf(&s, fmt, ap);
+    rc = libxl__xs_vprintf(gc, t, path, fmt, ap);
     va_end(ap);
 
-    if (ret == -1) {
-        return -1;
-    }
-    xs_write(ctx->xsh, t, path, s, ret);
-    free(s);
-    return 0;
+    return rc;
 }
 
 char * libxl__xs_read(libxl__gc *gc, xs_transaction_t t, const char *path)
Signature · 1 line
2.1.4
#0 lore raw

cover libxl: change libxl__xs_write() to libxl__xs_printf()

This is a re-post as I'd forgottent to add Cc-s for maintainers on patch #1

Patch #1 is purely a search and replace
Patch #2 changes the underlying implementation

#3 lore raw

Re: [PATCH v1 2/2] libxl: re-implement libxl__xs_printf()

In reply to Paul Durrant
Quoted 4 lines · Paul Durrant

This patch adds a new libxl__xs_vprintf() which actually checks the success of the underlying call to xs_write() (logging if it fails) and then re-implements libxl__xs_printf() using this (and replacing the call to vasprintf() with a call to libxl__vsprintf()).

Is the addition of libxl__xs_vprintf() an end in itself (i.e. do you have an upcoming use for it) or just an artefact of how you decided to fix libxl__xs_printf()?

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#4 lore raw

Re: [PATCH v1 2/2] libxl: re-implement libxl__xs_printf()

Quoted 8 lines

-----Original Message-----
From: Ian Campbell [mailto:[email protected]]
Sent: 02 December 2015 15:21
To: Paul Durrant; [email protected]
Cc: Ian Jackson; Stefano Stabellini; Wei Liu
Subject: Re: [PATCH v1 2/2] libxl: re-implement libxl__xs_printf()

On Tue, 2015-12-01 at 13:55 +0000, Paul Durrant wrote:

Quoted 9 lines
Quoted 4 lines

This patch adds a new libxl__xs_vprintf() which actually checks the success of the underlying call to xs_write() (logging if it fails) and then re-implements libxl__xs_printf() using this (and replacing the call to vasprintf() with a call to libxl__vsprintf()).

Is the addition of libxl__xs_vprintf() an end in itself (i.e. do you have an upcoming use for it) or just an artefact of how you decided to fix libxl__xs_printf()?

It's an artefact but seemed sufficiently useful to expose.

Paul

Quoted 1 line

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Acked-by
#5 lore raw

Re: [PATCH v1 2/2] libxl: re-implement libxl__xs_printf()

Quoted 14 lines · Paul Durrant
Quoted 14 lines

-----Original Message-----
From: Ian Campbell [mailto:[email protected]]
Sent: 02 December 2015 15:21
To: Paul Durrant; [email protected]
Cc: Ian Jackson; Stefano Stabellini; Wei Liu
Subject: Re: [PATCH v1 2/2] libxl: re-implement libxl__xs_printf()

Quoted 5 lines · Paul Durrant

This patch adds a new libxl__xs_vprintf() which actually checks the success of the underlying call to xs_write() (logging if it fails) and
then re-implements libxl__xs_printf() using this (and replacing the call to vasprintf() with a call to libxl__vsprintf()).

Quoted 7 lines
Quoted 5 lines

Is the addition of libxl__xs_vprintf() an end in itself (i.e. do you have
an upcoming use for it) or just an artefact of how you decided to fix libxl__xs_printf()?

It's an artefact but seemed sufficiently useful to expose.

Thanks:

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#7 lore raw

Re: [PATCH v1 2/2] libxl: re-implement libxl__xs_printf()

In reply to Ian Campbell
Quoted 32 lines · Ian Campbell
Quoted 26 lines · Ian Campbell
Quoted 25 lines · Paul Durrant
Quoted 24 lines

-----Original Message-----
From: Ian Campbell [mailto:[email protected]]
Sent: 02 December 2015 15:21
To: Paul Durrant; [email protected]
Cc: Ian Jackson; Stefano Stabellini; Wei Liu
Subject: Re: [PATCH v1 2/2] libxl: re-implement libxl__xs_printf()

Quoted 8 lines · Paul Durrant

This patch adds a new libxl__xs_vprintf() which actually checks the
success of the underlying call to xs_write() (logging if it fails)
and
then re-implements libxl__xs_printf() using this (and replacing the
call to vasprintf() with a call to libxl__vsprintf()).

Is the addition of libxl__xs_vprintf() an end in itself (i.e. do you
have
an upcoming use for it) or just an artefact of how you decided to fix
libxl__xs_printf()?

Quoted 4 lines
Quoted 1 line

It's an artefact but seemed sufficiently useful to expose.

Thanks:

Quoted 8 lines

And now applied, sorry for the delay.

The comment on libxl__xs_mknod in the context was different but I resolved
that, hopefully correctly!

Did you have any other of these updates available? IIRC there were two series and both are now in, but there might be a third?

Specifically I have "[PATCH v2 0/3] libxl: xenstore related cleanup" and a precursor, but I think all of that has subsequently ended up as the two other series which already got applied, is that right?

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#6 lore raw

Re: [PATCH v1 2/2] libxl: re-implement libxl__xs_printf()

In reply to Ian Campbell
Quoted 21 lines · Ian Campbell
Quoted 20 lines · Paul Durrant
Quoted 19 lines

-----Original Message-----
From: Ian Campbell [mailto:[email protected]]
Sent: 02 December 2015 15:21
To: Paul Durrant; [email protected]
Cc: Ian Jackson; Stefano Stabellini; Wei Liu
Subject: Re: [PATCH v1 2/2] libxl: re-implement libxl__xs_printf()

Quoted 5 lines · Paul Durrant

This patch adds a new libxl__xs_vprintf() which actually checks the success of the underlying call to xs_write() (logging if it fails) and
then re-implements libxl__xs_printf() using this (and replacing the call to vasprintf() with a call to libxl__vsprintf()).

Is the addition of libxl__xs_vprintf() an end in itself (i.e. do you have
an upcoming use for it) or just an artefact of how you decided to fix libxl__xs_printf()?

Quoted 4 lines
Quoted 1 line

It's an artefact but seemed sufficiently useful to expose.

Thanks:

And now applied, sorry for the delay.

The comment on libxl__xs_mknod in the context was different but I resolved that, hopefully correctly!

Did you have any other of these updates available? IIRC there were two series and both are now in, but there might be a third?

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#9 lore raw

Re: [PATCH v1 2/2] libxl: re-implement libxl__xs_printf()

In reply to Paul Durrant
Quoted 6 lines · Paul Durrant
Quoted 3 lines

Specifically I have "[PATCH v2 0/3] libxl: xenstore related cleanup" and a precursor, but I think all of that has subsequently ended up as the two other series which already got applied, is that right?

That's right. The 'xenstore related cleanup' series was superseded by the others.

Thanks, that's another raft of mails cleaned out of my queue folder ;-)

Ian.

#8 lore raw

Re: [PATCH v1 2/2] libxl: re-implement libxl__xs_printf()

In reply to Ian Campbell
Quoted 46 lines

-----Original Message-----
From: Ian Campbell [mailto:[email protected]]
Sent: 15 December 2015 12:31
To: Paul Durrant; [email protected]
Cc: Ian Jackson; Stefano Stabellini; Wei Liu
Subject: Re: [Xen-devel] [PATCH v1 2/2] libxl: re-implement libxl__xs_printf()

Quoted 38 lines · Ian Campbell
Quoted 26 lines · Ian Campbell
Quoted 25 lines · Paul Durrant
Quoted 24 lines

-----Original Message-----
From: Ian Campbell [mailto:[email protected]]
Sent: 02 December 2015 15:21
To: Paul Durrant; [email protected]
Cc: Ian Jackson; Stefano Stabellini; Wei Liu
Subject: Re: [PATCH v1 2/2] libxl: re-implement libxl__xs_printf()

Quoted 8 lines · Paul Durrant

This patch adds a new libxl__xs_vprintf() which actually checks the
success of the underlying call to xs_write() (logging if it fails)
and
then re-implements libxl__xs_printf() using this (and replacing the
call to vasprintf() with a call to libxl__vsprintf()).

Is the addition of libxl__xs_vprintf() an end in itself (i.e. do you
have
an upcoming use for it) or just an artefact of how you decided to fix
libxl__xs_printf()?

Quoted 4 lines
Quoted 1 line

It's an artefact but seemed sufficiently useful to expose.

Thanks:

And now applied, sorry for the delay.

The comment on libxl__xs_mknod in the context was different but I resolved
that, hopefully correctly!

Quoted 6 lines
Quoted 2 lines

Did you have any other of these updates available? IIRC there were two series and both are now in, but there might be a third?

Specifically I have "[PATCH v2 0/3] libxl: xenstore related cleanup" and a precursor, but I think all of that has subsequently ended up as the two other series which already got applied, is that right?

That's right. The 'xenstore related cleanup' series was superseded by the others.

Paul
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel