aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/dm.c
diff options
context:
space:
mode:
authorMilan Broz <mbroz@redhat.com>2009-01-05 22:05:12 -0500
committerAlasdair G Kergon <agk@redhat.com>2009-01-05 22:05:12 -0500
commit784aae735d9b0bba3f8b9faef4c8b30df3bf0128 (patch)
tree7e2e956c395b27f63569d7a6adc1098f116cc3a4 /drivers/md/dm.c
parentd58168763f74d1edbc296d7038c60efe6493fdd4 (diff)
dm: add name and uuid to sysfs
Implement simple read-only sysfs entry for device-mapper block device. This patch adds a simple sysfs directory named "dm" under block device properties and implements - name attribute (string containing mapped device name) - uuid attribute (string containing UUID, or empty 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 which is done by a new function dm_get_from_kobj, which returns the md associated with kobject and increases the usage count. Each 'show attribute' function is responsible for its own locking. Signed-off-by: Milan Broz <mbroz@redhat.com> Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Diffstat (limited to 'drivers/md/dm.c')
-rw-r--r--drivers/md/dm.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 9f9aa64f7336..51ba1db4b3e7 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (C) 2001, 2002 Sistina Software (UK) Limited. 2 * Copyright (C) 2001, 2002 Sistina Software (UK) Limited.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. 3 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
4 * 4 *
5 * This file is released under the GPL. 5 * This file is released under the GPL.
6 */ 6 */
@@ -167,6 +167,9 @@ struct mapped_device {
167 167
168 /* forced geometry settings */ 168 /* forced geometry settings */
169 struct hd_geometry geometry; 169 struct hd_geometry geometry;
170
171 /* sysfs handle */
172 struct kobject kobj;
170}; 173};
171 174
172#define MIN_IOS 256 175#define MIN_IOS 256
@@ -1285,6 +1288,8 @@ int dm_create(int minor, struct mapped_device **result)
1285 if (!md) 1288 if (!md)
1286 return -ENXIO; 1289 return -ENXIO;
1287 1290
1291 dm_sysfs_init(md);
1292
1288 *result = md; 1293 *result = md;
1289 return 0; 1294 return 0;
1290} 1295}
@@ -1360,6 +1365,7 @@ void dm_put(struct mapped_device *md)
1360 dm_table_presuspend_targets(map); 1365 dm_table_presuspend_targets(map);
1361 dm_table_postsuspend_targets(map); 1366 dm_table_postsuspend_targets(map);
1362 } 1367 }
1368 dm_sysfs_exit(md);
1363 dm_table_put(map); 1369 dm_table_put(map);
1364 __unbind(md); 1370 __unbind(md);
1365 free_dev(md); 1371 free_dev(md);
@@ -1699,6 +1705,27 @@ struct gendisk *dm_disk(struct mapped_device *md)
1699 return md->disk; 1705 return md->disk;
1700} 1706}
1701 1707
1708struct kobject *dm_kobject(struct mapped_device *md)
1709{
1710 return &md->kobj;
1711}
1712
1713/*
1714 * struct mapped_device should not be exported outside of dm.c
1715 * so use this check to verify that kobj is part of md structure
1716 */
1717struct mapped_device *dm_get_from_kobject(struct kobject *kobj)
1718{
1719 struct mapped_device *md;
1720
1721 md = container_of(kobj, struct mapped_device, kobj);
1722 if (&md->kobj != kobj)
1723 return NULL;
1724
1725 dm_get(md);
1726 return md;
1727}
1728
1702int dm_suspended(struct mapped_device *md) 1729int dm_suspended(struct mapped_device *md)
1703{ 1730{
1704 return test_bit(DMF_SUSPENDED, &md->flags); 1731 return test_bit(DMF_SUSPENDED, &md->flags);