# HG changeset patch # User Satoshi UCHIDA # Node ID 7b69444493c10e0ee7fbdd787cb28517a75c77f8 # Parent 161473836da3ccf922f44e910f8b5c01c709d1e6 Output VBD request information into sysfs. Add group "statistics" and output each information into its group. Output information are oo_req, rd_req, and wr_req. Signed-off-by: Satoshi UCHIDA diff -r 161473836da3 -r 7b69444493c1 linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c --- a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c Wed Jun 14 22:15:13 2006 +0100 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c Fri Jun 23 20:18:11 2006 +0900 @@ -40,6 +40,7 @@ #include #include #include +#include #include "common.h" /* @@ -191,7 +192,7 @@ static void fast_flush_area(pending_req_ static void print_stats(blkif_t *blkif) { - printk(KERN_DEBUG "%s: oo %3d | rd %4d | wr %4d\n", + printk(KERN_DEBUG "%s: oo %3lu | rd %4lu | wr %4lu\n", current->comm, blkif->st_oo_req, blkif->st_rd_req, blkif->st_wr_req); blkif->st_print = jiffies + msecs_to_jiffies(10 * 1000); @@ -463,6 +464,54 @@ static void dispatch_rw_block_io(blkif_t free_req(pending_req); } + + +/**************************************************************** + * sysfs interface for VBD I/O requests + */ + +#ifdef CONFIG_SYSFS + +VBD_SHOW(oo_req, fmt_ulong, be->blkif->st_oo_req); +VBD_SHOW(rd_req, fmt_ulong, be->blkif->st_rd_req); +VBD_SHOW(wr_req, fmt_ulong, be->blkif->st_wr_req); + +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 */ /****************************************************************** diff -r 161473836da3 -r 7b69444493c1 linux-2.6-xen-sparse/drivers/xen/blkback/common.h --- a/linux-2.6-xen-sparse/drivers/xen/blkback/common.h Wed Jun 14 22:15:13 2006 +0100 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/common.h Fri Jun 23 20:18:11 2006 +0900 @@ -44,6 +44,7 @@ #include #include #include +#include #define DPRINTK(_f, _a...) \ pr_debug("(file=%s, line=%d) " _f, \ @@ -84,15 +85,25 @@ typedef struct blkif_st { /* statistics */ unsigned long st_print; - int st_rd_req; - int st_wr_req; - int st_oo_req; + unsigned long st_rd_req; + unsigned long st_wr_req; + unsigned long st_oo_req; wait_queue_head_t waiting_to_free; grant_handle_t shmem_handle; grant_ref_t shmem_ref; } blkif_t; + +struct backend_info +{ + struct xenbus_device *dev; + blkif_t *blkif; + struct xenbus_watch backend_watch; + unsigned major; + unsigned minor; + char *mode; +}; blkif_t *blkif_alloc(domid_t domid); void blkif_free(blkif_t *blkif); @@ -130,4 +141,31 @@ irqreturn_t blkif_be_int(int irq, void * irqreturn_t blkif_be_int(int irq, void *dev_id, struct pt_regs *regs); int blkif_schedule(void *arg); + +#ifdef CONFIG_SYSFS + +struct xenbus_device; +int xenvbd_sysfs_addif(struct xenbus_device *dev); +void xenvbd_sysfs_delif(struct xenbus_device *dev); + +static const char fmt_ulong[] = "%lu\n"; + +#define VBD_SHOW(name, format, args...) \ +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, ##args); \ +} \ +DEVICE_ATTR(name, S_IRUGO, show_##name, NULL); + +#else + +#define xenvbd_sysfs_addif(dev) do { } while(0) +#define xenvbd_sysfs_delif(dev) do { } while(0) + +#endif + #endif /* __BLKIF__BACKEND__COMMON_H__ */ diff -r 161473836da3 -r 7b69444493c1 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 Fri Jun 23 20:18:11 2006 +0900 @@ -27,16 +27,6 @@ #define DPRINTK(fmt, args...) \ pr_debug("blkback/xenbus (%s:%d) " fmt ".\n", \ __FUNCTION__, __LINE__, ##args) - -struct backend_info -{ - struct xenbus_device *dev; - blkif_t *blkif; - struct xenbus_watch backend_watch; - unsigned major; - unsigned minor; - char *mode; -}; static void connect(struct backend_info *); static int connect_ring(struct backend_info *); @@ -114,7 +104,8 @@ 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; return 0; @@ -236,6 +227,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);