Skip to contentSkip to conversation

Clean code by VBD_SHOW macro in xenbus.c

PATCH New Satoshi Uchida 1 participant 1 message Jun 30, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Clean code by VBD_SHOW macro in xenbus.c

This patch is cleaning code in xenbus.c by VBD_SHOW macro.

VBD_SHOW macro can be applied show functions with corresponded to 'physical_devices' and 'mode' attributes.
And corresponding 'device_create_file' and 'device_remove_file' function can be inserted into 'xenvbd_sysfs_addif' and 'xenvbd_sysfs_delif functions' too.

So, this patch transfer code based on above reasons. Thereby, code will be clear.

Thanks,
Satoshi UCHIDA

# HG changeset patch
# User Satoshi UCHIDA <[email protected]>
# Node ID a5bed4c2cfa4434db7fa92bc64e419d539791235 # Parent ef33b7a4b49dddfc5b03df9021580b77f135bc4f [BLKBACK]Simplfy and Clean program code by VBD_SHOW macro.

VBD_SHOW can use for 'physical_device' and 'mode' attributes in xenbus.c and so is applied at each location.
And, move device_create_file and device_remove_file function into xenvbd_sysfs_addif and xenvbd_sysfs_delif respectively.

linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c +24 -32
diff -r ef33b7a4b49d -r a5bed4c2cfa4 linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c
@@ -115,50 +115,46 @@ static struct attribute_group vbdstat_gr
 	.attrs = vbdstat_attrs,
 };
 
+
+VBD_SHOW(physical_device, "%x:%x\n", be->major, be->minor);
+VBD_SHOW(mode, "%s\n", be->mode);
+
 int xenvbd_sysfs_addif(struct xenbus_device *dev)
 {
 	int error = 0;
 	
-	error = sysfs_create_group(&dev->dev.kobj,
-				   &vbdstat_group);
+	error = device_create_file(&dev->dev, &dev_attr_physical_device);
 	if (error)
-		goto fail;
+		goto fail1;
+
+	error = device_create_file(&dev->dev, &dev_attr_mode);
+	if (error)
+		goto fail2;
+
+	error = sysfs_create_group(&dev->dev.kobj, &vbdstat_group);
+	if (error)
+		goto fail3;
 	
 	return 0;
 	
-fail:
-	sysfs_remove_group(&dev->dev.kobj,
-			   &vbdstat_group);
+fail3:
+	sysfs_remove_group(&dev->dev.kobj, &vbdstat_group);
+fail2:
+	device_remove_file(&dev->dev, &dev_attr_mode);
+fail1:
+	device_remove_file(&dev->dev, &dev_attr_physical_device);
+
 	return error;
 }
 
 void xenvbd_sysfs_delif(struct xenbus_device *dev)
 {
-       	sysfs_remove_group(&dev->dev.kobj,
-			   &vbdstat_group);
+       	sysfs_remove_group(&dev->dev.kobj, &vbdstat_group);
+	device_remove_file(&dev->dev, &dev_attr_mode);
+	device_remove_file(&dev->dev, &dev_attr_physical_device);
 }
 
 #endif /* CONFIG_SYSFS */
-
-static ssize_t show_physical_device(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, "%x:%x\n", be->major, be->minor);
-}
-DEVICE_ATTR(physical_device, S_IRUSR | S_IRGRP | S_IROTH,
-	    show_physical_device, NULL);
-
-
-static ssize_t show_mode(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, "%s\n", be->mode);
-}
-DEVICE_ATTR(mode, S_IRUSR | S_IRGRP | S_IROTH, show_mode, NULL);
 
 
 static int blkback_remove(struct xenbus_device *dev)
@@ -179,8 +175,6 @@ static int blkback_remove(struct xenbus_
 		be->blkif = NULL;
 	}
 
-	device_remove_file(&dev->dev, &dev_attr_physical_device);
-	device_remove_file(&dev->dev, &dev_attr_mode);
 	xenvbd_sysfs_delif(dev);
 
 	kfree(be);
@@ -302,8 +296,6 @@ static void backend_changed(struct xenbu
 			return;
 		}
 
-		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 */

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