# HG changeset patch # User root@mercury.spf.cl.nec.co.jp # Node ID 1a29b07abc6303f016d828070a8e4327fe8f53e9 # Parent 161473836da3ccf922f44e910f8b5c01c709d1e6 Output VBD requests information into sysfs. Add group "statistics" under /sys/device/xen-backed/vbd-x-xxxx and output VBD statistics information -- oo_req, rd_req, and wr_req -- into its group. Signed-off-by: Satoshi UCHIDA diff -r 161473836da3 -r 1a29b07abc63 linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c --- a/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c Wed Jun 14 22:15:13 2006 +0100 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c Wed Jun 28 16:04:50 2006 +0900 @@ -43,6 +43,13 @@ static void backend_changed(struct xenbu static void backend_changed(struct xenbus_watch *, const char **, unsigned int); +#ifdef CONFIG_SYSFS +int xenvbd_sysfs_addif(struct xenbus_device *dev); +void xenvbd_sysfs_delif(struct xenbus_device *dev); +#else +#define xenvbd_sysfs_addif(dev) (0) +#define xenvbd_sysfs_delif(dev) do { } while(0) +#endif static void update_blkif_status(blkif_t *blkif) { @@ -73,6 +80,66 @@ static void update_blkif_status(blkif_t } + +/**************************************************************** + * sysfs interface for VBD I/O requests + */ + +#ifdef CONFIG_SYSFS + +#define VBD_SHOW(name, field, format_string) \ + static ssize_t show_##name(struct device *_dev, \ + struct device_attribute *attr, \ + char *buf) \ + { \ + struct xenbus_device *dev = to_xenbus_device(_dev); \ + struct backend_info *be = dev->dev.driver_data; \ + \ + return sprintf(buf, format_string, be->field); \ + } \ + DEVICE_ATTR(name, S_IRUGO, show_##name, NULL); + +VBD_SHOW(oo_req, blkif->st_oo_req, "%d\n"); +VBD_SHOW(rd_req, blkif->st_rd_req, "%d\n"); +VBD_SHOW(wr_req, blkif->st_wr_req, "%d\n"); + +static struct attribute *vbdstat_attrs[] = { + &dev_attr_oo_req.attr, + &dev_attr_rd_req.attr, + &dev_attr_wr_req.attr, + NULL +}; + +static struct attribute_group vbdstat_group = { + .name = "statistics", + .attrs = vbdstat_attrs, +}; + +int xenvbd_sysfs_addif(struct xenbus_device *dev) +{ + int error = 0; + + error = sysfs_create_group(&dev->dev.kobj, + &vbdstat_group); + if (error) + goto fail; + + return 0; + +fail: + sysfs_remove_group(&dev->dev.kobj, + &vbdstat_group); + return error; +} + +void xenvbd_sysfs_delif(struct xenbus_device *dev) +{ + sysfs_remove_group(&dev->dev.kobj, + &vbdstat_group); +} + +#endif /* CONFIG_SYSFS */ + static ssize_t show_physical_device(struct device *_dev, struct device_attribute *attr, char *buf) { @@ -114,6 +181,7 @@ static int blkback_remove(struct xenbus_ device_remove_file(&dev->dev, &dev_attr_physical_device); device_remove_file(&dev->dev, &dev_attr_mode); + xenvbd_sysfs_delif(dev); kfree(be); dev->dev.driver_data = NULL; @@ -236,6 +304,7 @@ static void backend_changed(struct xenbu device_create_file(&dev->dev, &dev_attr_physical_device); device_create_file(&dev->dev, &dev_attr_mode); + xenvbd_sysfs_addif(dev); /* We're potentially connected now */ update_blkif_status(be->blkif);