direct-io.hg

changeset 10554:5fc6d83f43f7

[BLK] back: Clean up sysfs-interfacing code to use VBD_SHOW macro where possible.
Signed-off-by: Satoshi UCHIDA <s-uchida@ap.jp.nec.com>
author kaf24@firebug.cl.cam.ac.uk
date Fri Jun 30 09:43:08 2006 +0100 (2006-06-30)
parents 85b092b4567d
children 88dc1ae16d2b
files linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c	Fri Jun 30 09:25:42 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c	Fri Jun 30 09:43:08 2006 +0100
     1.3 @@ -76,8 +76,6 @@ static void update_blkif_status(blkif_t 
     1.4   *  sysfs interface for VBD I/O requests
     1.5   */
     1.6  
     1.7 -#ifdef CONFIG_SYSFS
     1.8 -
     1.9  #define VBD_SHOW(name, format, args...)					\
    1.10  	static ssize_t show_##name(struct device *_dev,			\
    1.11  				   struct device_attribute *attr,	\
    1.12 @@ -106,57 +104,40 @@ static struct attribute_group vbdstat_gr
    1.13  	.attrs = vbdstat_attrs,
    1.14  };
    1.15  
    1.16 +VBD_SHOW(physical_device, "%x:%x\n", be->major, be->minor);
    1.17 +VBD_SHOW(mode, "%s\n", be->mode);
    1.18 +
    1.19  int xenvbd_sysfs_addif(struct xenbus_device *dev)
    1.20  {
    1.21  	int error = 0;
    1.22  	
    1.23 -	error = sysfs_create_group(&dev->dev.kobj,
    1.24 -				   &vbdstat_group);
    1.25 +	error = device_create_file(&dev->dev, &dev_attr_physical_device);
    1.26 + 	if (error)
    1.27 +		goto fail1;
    1.28 +
    1.29 +	error = device_create_file(&dev->dev, &dev_attr_mode);
    1.30  	if (error)
    1.31 -		goto fail;
    1.32 -	
    1.33 +		goto fail2;
    1.34 +
    1.35 +	error = sysfs_create_group(&dev->dev.kobj, &vbdstat_group);
    1.36 +	if (error)
    1.37 +		goto fail3;
    1.38 +
    1.39  	return 0;
    1.40 -	
    1.41 -fail:
    1.42 -	sysfs_remove_group(&dev->dev.kobj,
    1.43 -			   &vbdstat_group);
    1.44 +
    1.45 +fail3:	sysfs_remove_group(&dev->dev.kobj, &vbdstat_group);
    1.46 +fail2:	device_remove_file(&dev->dev, &dev_attr_mode);
    1.47 +fail1:	device_remove_file(&dev->dev, &dev_attr_physical_device);
    1.48  	return error;
    1.49  }
    1.50  
    1.51  void xenvbd_sysfs_delif(struct xenbus_device *dev)
    1.52  {
    1.53 -	sysfs_remove_group(&dev->dev.kobj,
    1.54 -			   &vbdstat_group);
    1.55 +	sysfs_remove_group(&dev->dev.kobj, &vbdstat_group);
    1.56 +	device_remove_file(&dev->dev, &dev_attr_mode);
    1.57 +	device_remove_file(&dev->dev, &dev_attr_physical_device);
    1.58  }
    1.59  
    1.60 -#else
    1.61 -
    1.62 -#define xenvbd_sysfs_addif(dev) (0)
    1.63 -#define xenvbd_sysfs_delif(dev) ((void)0)
    1.64 -
    1.65 -#endif /* CONFIG_SYSFS */
    1.66 -
    1.67 -static ssize_t show_physical_device(struct device *_dev,
    1.68 -				    struct device_attribute *attr, char *buf)
    1.69 -{
    1.70 -	struct xenbus_device *dev = to_xenbus_device(_dev);
    1.71 -	struct backend_info *be = dev->dev.driver_data;
    1.72 -	return sprintf(buf, "%x:%x\n", be->major, be->minor);
    1.73 -}
    1.74 -DEVICE_ATTR(physical_device, S_IRUSR | S_IRGRP | S_IROTH,
    1.75 -	    show_physical_device, NULL);
    1.76 -
    1.77 -
    1.78 -static ssize_t show_mode(struct device *_dev, struct device_attribute *attr,
    1.79 -			 char *buf)
    1.80 -{
    1.81 -	struct xenbus_device *dev = to_xenbus_device(_dev);
    1.82 -	struct backend_info *be = dev->dev.driver_data;
    1.83 -	return sprintf(buf, "%s\n", be->mode);
    1.84 -}
    1.85 -DEVICE_ATTR(mode, S_IRUSR | S_IRGRP | S_IROTH, show_mode, NULL);
    1.86 -
    1.87 -
    1.88  static int blkback_remove(struct xenbus_device *dev)
    1.89  {
    1.90  	struct backend_info *be = dev->dev.driver_data;
    1.91 @@ -176,8 +157,6 @@ static int blkback_remove(struct xenbus_
    1.92  		be->blkif = NULL;
    1.93  	}
    1.94  
    1.95 -	device_remove_file(&dev->dev, &dev_attr_physical_device);
    1.96 -	device_remove_file(&dev->dev, &dev_attr_mode);
    1.97  	xenvbd_sysfs_delif(dev);
    1.98  
    1.99  	kfree(be);
   1.100 @@ -299,8 +278,6 @@ static void backend_changed(struct xenbu
   1.101  			return;
   1.102  		}
   1.103  
   1.104 -		device_create_file(&dev->dev, &dev_attr_physical_device);
   1.105 -		device_create_file(&dev->dev, &dev_attr_mode);
   1.106  		xenvbd_sysfs_addif(dev);
   1.107  
   1.108  		/* We're potentially connected now */