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

[Xen-changelog] [linux-2.6.18-xen] xenbus: xenbus_gather()/xenbus_scanf() usage adjustments



# HG changeset patch
# User Jan Beulcih <jbeulich@xxxxxxxxxx>
# Date 1308823996 -3600
# Node ID 53ca64bc2072c0ca300439ba0bd99f33b843f0e7
# Parent  82548feeaf8e3f74e308c74054c26992e6b6bbdd
xenbus: xenbus_gather()/xenbus_scanf() usage adjustments

- don't use xenbus_gather() for just a single, non-string item (as it
  doesn't do format checking on its inputs)
- grant references don't need to be parsed as "long", since
  grant_ref_t
  is a typedef of uint32_t
- in the frontend protocol determination logic in blkback and blktap,
  don't parse into a local buffer - use the allocated string directly

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxxxx>
---


diff -r 82548feeaf8e -r 53ca64bc2072 drivers/xen/blkback/xenbus.c
--- a/drivers/xen/blkback/xenbus.c      Thu Jun 23 11:12:32 2011 +0100
+++ b/drivers/xen/blkback/xenbus.c      Thu Jun 23 11:13:16 2011 +0100
@@ -485,14 +485,13 @@
 static int connect_ring(struct backend_info *be)
 {
        struct xenbus_device *dev = be->dev;
-       unsigned long ring_ref;
-       unsigned int evtchn;
-       char protocol[64] = "";
+       unsigned int ring_ref, evtchn;
+       char *protocol;
        int err;
 
        DPRINTK("%s", dev->otherend);
 
-       err = xenbus_gather(XBT_NIL, dev->otherend, "ring-ref", "%lu", 
&ring_ref,
+       err = xenbus_gather(XBT_NIL, dev->otherend, "ring-ref", "%u", &ring_ref,
                            "event-channel", "%u", &evtchn, NULL);
        if (err) {
                xenbus_dev_fatal(dev, err,
@@ -503,9 +502,9 @@
 
        be->blkif->blk_protocol = BLKIF_PROTOCOL_NATIVE;
        err = xenbus_gather(XBT_NIL, dev->otherend, "protocol",
-                           "%63s", protocol, NULL);
+                           NULL, &protocol, NULL);
        if (err)
-               strcpy(protocol, "unspecified, assuming native");
+               protocol = NULL;
        else if (0 == strcmp(protocol, XEN_IO_PROTO_ABI_NATIVE))
                be->blkif->blk_protocol = BLKIF_PROTOCOL_NATIVE;
        else if (0 == strcmp(protocol, XEN_IO_PROTO_ABI_X86_32))
@@ -514,16 +513,19 @@
                be->blkif->blk_protocol = BLKIF_PROTOCOL_X86_64;
        else {
                xenbus_dev_fatal(dev, err, "unknown fe protocol %s", protocol);
+               kfree(protocol);
                return -1;
        }
        printk(KERN_INFO
-              "blkback: ring-ref %ld, event-channel %d, protocol %d (%s)\n",
-              ring_ref, evtchn, be->blkif->blk_protocol, protocol);
+              "blkback: ring-ref %u, event-channel %u, protocol %d (%s)\n",
+              ring_ref, evtchn, be->blkif->blk_protocol,
+              protocol ?: "unspecified, assuming native");
+       kfree(protocol);
 
        /* Map the shared frame, irq etc. */
        err = blkif_map(be->blkif, ring_ref, evtchn);
        if (err) {
-               xenbus_dev_fatal(dev, err, "mapping ring-ref %lu port %u",
+               xenbus_dev_fatal(dev, err, "mapping ring-ref %u port %u",
                                 ring_ref, evtchn);
                return err;
        }
diff -r 82548feeaf8e -r 53ca64bc2072 drivers/xen/blkfront/blkfront.c
--- a/drivers/xen/blkfront/blkfront.c   Thu Jun 23 11:12:32 2011 +0100
+++ b/drivers/xen/blkfront/blkfront.c   Thu Jun 23 11:13:16 2011 +0100
@@ -334,7 +334,7 @@
                 */
                err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
                                   "sectors", "%Lu", &sectors);
-               if (XENBUS_EXIST_ERR(err))
+               if (err != 1)
                        return;
                printk(KERN_INFO "Setting capacity to %Lu\n",
                       sectors);
@@ -359,10 +359,9 @@
                return;
        }
 
-       err = xenbus_gather(XBT_NIL, info->xbdev->otherend,
-                           "feature-barrier", "%d", &info->feature_barrier,
-                           NULL);
-       if (err)
+       err = xenbus_scanf(XBT_NIL, info->xbdev->otherend,
+                          "feature-barrier", "%d", &info->feature_barrier);
+       if (err <= 0)
                info->feature_barrier = 0;
 
        err = xlvbd_add(sectors, info->vdevice, binfo, sector_size, info);
diff -r 82548feeaf8e -r 53ca64bc2072 drivers/xen/blktap/xenbus.c
--- a/drivers/xen/blktap/xenbus.c       Thu Jun 23 11:12:32 2011 +0100
+++ b/drivers/xen/blktap/xenbus.c       Thu Jun 23 11:13:16 2011 +0100
@@ -319,7 +319,7 @@
         * and disk info to xenstore
         */
        err = xenbus_gather(XBT_NIL, dev->nodename, "info", "%lu", &info, 
-                           NULL);
+                           "sectors", "%Lu", &be->blkif->sectors, NULL);
        if (XENBUS_EXIST_ERR(err))
                return;
        if (err) {
@@ -329,9 +329,6 @@
 
        DPRINTK("Userspace update on disk info, %lu\n",info);
 
-       err = xenbus_gather(XBT_NIL, dev->nodename, "sectors", "%llu", 
-                           &be->blkif->sectors, NULL);
-
        /* Associate tap dev with domid*/
        be->blkif->dev_num = dom_to_devid(be->blkif->domid, be->xenbus_id, 
                                          be->blkif);
@@ -436,14 +433,13 @@
 static int connect_ring(struct backend_info *be)
 {
        struct xenbus_device *dev = be->dev;
-       unsigned long ring_ref;
-       unsigned int evtchn;
-       char protocol[64];
+       unsigned int ring_ref, evtchn;
+       char *protocol;
        int err;
 
        DPRINTK("%s\n", dev->otherend);
 
-       err = xenbus_gather(XBT_NIL, dev->otherend, "ring-ref", "%lu", 
+       err = xenbus_gather(XBT_NIL, dev->otherend, "ring-ref", "%u",
                            &ring_ref, "event-channel", "%u", &evtchn, NULL);
        if (err) {
                xenbus_dev_fatal(dev, err,
@@ -454,9 +450,9 @@
 
        be->blkif->blk_protocol = BLKIF_PROTOCOL_NATIVE;
        err = xenbus_gather(XBT_NIL, dev->otherend, "protocol",
-                           "%63s", protocol, NULL);
+                           NULL, &protocol, NULL);
        if (err)
-               strcpy(protocol, "unspecified, assuming native");
+               protocol = NULL;
        else if (0 == strcmp(protocol, XEN_IO_PROTO_ABI_NATIVE))
                be->blkif->blk_protocol = BLKIF_PROTOCOL_NATIVE;
        else if (0 == strcmp(protocol, XEN_IO_PROTO_ABI_X86_32))
@@ -465,16 +461,19 @@
                be->blkif->blk_protocol = BLKIF_PROTOCOL_X86_64;
        else {
                xenbus_dev_fatal(dev, err, "unknown fe protocol %s", protocol);
+               kfree(protocol);
                return -1;
        }
        printk(KERN_INFO
-              "blktap: ring-ref %ld, event-channel %d, protocol %d (%s)\n",
-              ring_ref, evtchn, be->blkif->blk_protocol, protocol);
+              "blktap: ring-ref %u, event-channel %u, protocol %d (%s)\n",
+              ring_ref, evtchn, be->blkif->blk_protocol,
+              protocol ?: "unspecified, assuming native");
+       kfree(protocol);
 
        /* Map the shared frame, irq etc. */
        err = tap_blkif_map(be->blkif, dev, ring_ref, evtchn);
        if (err) {
-               xenbus_dev_fatal(dev, err, "mapping ring-ref %lu port %u",
+               xenbus_dev_fatal(dev, err, "mapping ring-ref %u port %u",
                                 ring_ref, evtchn);
                return err;
        } 
diff -r 82548feeaf8e -r 53ca64bc2072 drivers/xen/core/reboot.c
--- a/drivers/xen/core/reboot.c Thu Jun 23 11:12:32 2011 +0100
+++ b/drivers/xen/core/reboot.c Thu Jun 23 11:13:16 2011 +0100
@@ -215,7 +215,7 @@
        err = xenbus_transaction_start(&xbt);
        if (err)
                return;
-       if (!xenbus_scanf(xbt, "control", "sysrq", "%c", &sysrq_key)) {
+       if (xenbus_scanf(xbt, "control", "sysrq", "%c", &sysrq_key) <= 0) {
                printk(KERN_ERR "Unable to read sysrq code in "
                       "control/sysrq\n");
                xenbus_transaction_end(xbt, 1);
diff -r 82548feeaf8e -r 53ca64bc2072 drivers/xen/netback/xenbus.c
--- a/drivers/xen/netback/xenbus.c      Thu Jun 23 11:12:32 2011 +0100
+++ b/drivers/xen/netback/xenbus.c      Thu Jun 23 11:13:16 2011 +0100
@@ -358,7 +358,7 @@
 {
        netif_t *netif = be->netif;
        struct xenbus_device *dev = be->dev;
-       unsigned long tx_ring_ref, rx_ring_ref;
+       unsigned int tx_ring_ref, rx_ring_ref;
        unsigned int evtchn, rx_copy;
        int err;
        int val;
@@ -366,8 +366,8 @@
        DPRINTK("");
 
        err = xenbus_gather(XBT_NIL, dev->otherend,
-                           "tx-ring-ref", "%lu", &tx_ring_ref,
-                           "rx-ring-ref", "%lu", &rx_ring_ref,
+                           "tx-ring-ref", "%u", &tx_ring_ref,
+                           "rx-ring-ref", "%u", &rx_ring_ref,
                            "event-channel", "%u", &evtchn, NULL);
        if (err) {
                xenbus_dev_fatal(dev, err,
@@ -421,7 +421,7 @@
        err = netif_map(be, tx_ring_ref, rx_ring_ref, evtchn);
        if (err) {
                xenbus_dev_fatal(dev, err,
-                                "mapping shared-frames %lu/%lu port %u",
+                                "mapping shared-frames %u/%u port %u",
                                 tx_ring_ref, rx_ring_ref, evtchn);
                return err;
        }
diff -r 82548feeaf8e -r 53ca64bc2072 drivers/xen/scsiback/xenbus.c
--- a/drivers/xen/scsiback/xenbus.c     Thu Jun 23 11:12:32 2011 +0100
+++ b/drivers/xen/scsiback/xenbus.c     Thu Jun 23 11:13:16 2011 +0100
@@ -60,13 +60,12 @@
 static int scsiback_map(struct backend_info *be)
 {
        struct xenbus_device *dev = be->dev;
-       unsigned long ring_ref;
-       unsigned int evtchn;
+       unsigned int ring_ref, evtchn;
        int err;
        char name[TASK_COMM_LEN];
 
        err = xenbus_gather(XBT_NIL, dev->otherend,
-                       "ring-ref", "%lu", &ring_ref,
+                       "ring-ref", "%u", &ring_ref,
                        "event-channel", "%u", &evtchn, NULL);
        if (err) {
                xenbus_dev_fatal(dev, err, "reading %s ring", dev->otherend);
diff -r 82548feeaf8e -r 53ca64bc2072 drivers/xen/tpmback/xenbus.c
--- a/drivers/xen/tpmback/xenbus.c      Thu Jun 23 11:12:32 2011 +0100
+++ b/drivers/xen/tpmback/xenbus.c      Thu Jun 23 11:13:16 2011 +0100
@@ -210,12 +210,11 @@
 static int connect_ring(struct backend_info *be)
 {
        struct xenbus_device *dev = be->dev;
-       unsigned long ring_ref;
-       unsigned int evtchn;
+       unsigned int ring_ref, evtchn;
        int err;
 
        err = xenbus_gather(XBT_NIL, dev->otherend,
-                           "ring-ref", "%lu", &ring_ref,
+                           "ring-ref", "%u", &ring_ref,
                            "event-channel", "%u", &evtchn, NULL);
        if (err) {
                xenbus_dev_error(dev, err,
@@ -238,7 +237,7 @@
                err = tpmif_map(be->tpmif, ring_ref, evtchn);
                if (err) {
                        xenbus_dev_error(dev, err,
-                                        "mapping shared-frame %lu port %u",
+                                        "mapping shared-frame %u port %u",
                                         ring_ref, evtchn);
                        return err;
                }
diff -r 82548feeaf8e -r 53ca64bc2072 drivers/xen/usbback/xenbus.c
--- a/drivers/xen/usbback/xenbus.c      Thu Jun 23 11:12:32 2011 +0100
+++ b/drivers/xen/usbback/xenbus.c      Thu Jun 23 11:13:16 2011 +0100
@@ -226,14 +226,12 @@
 static int connect_rings(usbif_t *usbif)
 {
        struct xenbus_device *dev = usbif->xbdev;
-       unsigned long urb_ring_ref;
-       unsigned long conn_ring_ref;
-       unsigned int evtchn;
+       unsigned int urb_ring_ref, conn_ring_ref, evtchn;
        int err;
 
        err = xenbus_gather(XBT_NIL, dev->otherend,
-                           "urb-ring-ref", "%lu", &urb_ring_ref,
-                           "conn-ring-ref", "%lu", &conn_ring_ref,
+                           "urb-ring-ref", "%u", &urb_ring_ref,
+                           "conn-ring-ref", "%u", &conn_ring_ref,
                            "event-channel", "%u", &evtchn, NULL);
        if (err) {
                xenbus_dev_fatal(dev, err,
@@ -242,13 +240,14 @@
                return err;
        }
 
-       printk("usbback: urb-ring-ref %ld, conn-ring-ref %ld, event-channel 
%d\n",
+       printk("usbback: urb-ring-ref %u, conn-ring-ref %u,"
+              " event-channel %u\n",
               urb_ring_ref, conn_ring_ref, evtchn);
 
        err = usbif_map(usbif, urb_ring_ref, conn_ring_ref, evtchn);
        if (err) {
                xenbus_dev_fatal(dev, err,
-                               "mapping urb-ring-ref %lu conn-ring-ref %lu 
port %u",
+                               "mapping urb-ring-ref %u conn-ring-ref %u port 
%u",
                                urb_ring_ref, conn_ring_ref, evtchn);
                return err;
        }
diff -r 82548feeaf8e -r 53ca64bc2072 drivers/xen/xenbus/xenbus_client.c
--- a/drivers/xen/xenbus/xenbus_client.c        Thu Jun 23 11:12:32 2011 +0100
+++ b/drivers/xen/xenbus/xenbus_client.c        Thu Jun 23 11:13:16 2011 +0100
@@ -276,9 +276,9 @@
 
 enum xenbus_state xenbus_read_driver_state(const char *path)
 {
-       enum xenbus_state result;
-       int err = xenbus_gather(XBT_NIL, path, "state", "%d", &result, NULL);
-       if (err)
+       int result;
+
+       if (xenbus_scanf(XBT_NIL, path, "state", "%d", &result) != 1)
                result = XenbusStateUnknown;
 
        return result;
diff -r 82548feeaf8e -r 53ca64bc2072 drivers/xen/xenbus/xenbus_probe.c
--- a/drivers/xen/xenbus/xenbus_probe.c Thu Jun 23 11:12:32 2011 +0100
+++ b/drivers/xen/xenbus/xenbus_probe.c Thu Jun 23 11:13:16 2011 +0100
@@ -865,7 +865,8 @@
 
 static void xenbus_reset_state_changed(struct xenbus_watch *w, const char **v, 
unsigned int l)
 {
-       xenbus_scanf(XBT_NIL, v[XS_WATCH_PATH], "", "%i", &be_state);
+       if (xenbus_scanf(XBT_NIL, v[XS_WATCH_PATH], "", "%i", &be_state) != 1)
+               be_state = XenbusStateUnknown;
        printk(KERN_INFO "XENBUS: %s %s\n", v[XS_WATCH_PATH], 
xenbus_strstate(be_state));
        wake_up(&be_state_wq);
 }

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

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