dm: Implement simple read-only sysfs entry for device-mapper block device.
Subsystems (2)
PATCH 1/1 dm: Implement simple read-only sysfs entry for device-mapper block device.
Implement simple read-only sysfs entry for device-mapper block device.
Sometime is using dm-ioctl too complicated, for example for checking UUID and mapped device name.
This patch adds simple sysfs directory named "dm" under block device properties and implements
- name attribute (string containing mapped device name)
- uuid attribute (string containing UUID, or emty string if not set)
The kobject is embedded in mapped_device struct, so no additional memory allocation is needed for initializing sysfs entry.
During the processing of sysfs attribute we need to lock mapped device, it is done by new function dm_get_from_kobj, which returns md associated with kobject and increase use count.
Every show attribute procedure is the responsible for locking of any thing it need.
--- drivers/md/Makefile | 2 +- drivers/md/dm-sysfs.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++ drivers/md/dm.c | 29 ++++++++++++++- drivers/md/dm.h | 8 ++++ 4 files changed, 136 insertions(+), 2 deletions(-)
drivers/md/Makefile +1 -1
@@ -3,7 +3,7 @@ # dm-mod-objs := dm.o dm-table.o dm-target.o dm-linear.o dm-stripe.o \ - dm-ioctl.o dm-io.o dm-kcopyd.o + dm-ioctl.o dm-io.o dm-kcopyd.o dm-sysfs.o dm-multipath-objs := dm-path-selector.o dm-mpath.o dm-snapshot-objs := dm-snap.o dm-exception-store.o dm-snap-transient.o \ dm-snap-persistent.o
drivers/md/dm-sysfs.c new file +99 -0
99 lines not on this page · raw message
drivers/md/dm.c +28 -1
@@ -1,6 +1,6 @@/* * Copyright (C) 2001, 2002 Sistina Software (UK) Limited. -* Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. +* Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved. * * This file is released under the GPL. */
@@ -164,6 +164,9 @@ struct mapped_device {/* forced geometry settings */ struct hd_geometry geometry; + +/* sysfs handle */ +struct kobject kobj; };#define MIN_IOS 256
@@ -1298,6 +1301,8 @@ int dm_create(int minor, struct mapped_device **result)if (!md)return -ENXIO ; +dm_sysfs_init (md); + *result = md;return 0 ; }
@@ -1373,6 +1378,7 @@ void dm_put(struct mapped_device *md)dm_table_presuspend_targets (map);dm_table_postsuspend_targets (map); } +dm_sysfs_exit (md);dm_table_put (map);__unbind (md);free_dev (md);
@@ -1712,6 +1718,27 @@ struct gendisk *dm_disk(struct mapped_device *md)return md->disk; } +struct kobject *dm_kobject (struct mapped_device *md) +{ +return &md->kobj; +} + +/* +* struct mapped_device should not be exported outside of dm.c +* so use this check to verify that kobj is part of md structure +*/ +struct mapped_device *dm_get_from_kobject (struct kobject *kobj) +{ +struct mapped_device *md; + + md = container_of(kobj, struct mapped_device, kobj); +if (&md->kobj != kobj) +return NULL ; + +dm_get (md); +return md; +} +int dm_suspended (struct mapped_device *md) {return test_bit (DMF_SUSPENDED , &md->flags);
drivers/md/dm.h +8 -0
@@ -74,6 +74,14 @@ int dm_interface_init(void);void dm_interface_exit (void );/* +* sysfs interface +*/ +int dm_sysfs_init (struct mapped_device *md); +void dm_sysfs_exit (struct mapped_device *md); +struct kobject *dm_kobject (struct mapped_device *md); +struct mapped_device *dm_get_from_kobject (struct kobject *kobj); + +/* * Targets for linear and striped mappings */ int dm_linear_init (void );