diff options
author | Milan Broz <mbroz@redhat.com> | 2009-01-06 04:05:12 +0100 |
---|---|---|
committer | Alasdair G Kergon <agk@redhat.com> | 2009-01-06 04:05:12 +0100 |
commit | 784aae735d9b0bba3f8b9faef4c8b30df3bf0128 (patch) | |
tree | 7e2e956c395b27f63569d7a6adc1098f116cc3a4 /drivers/md/dm.c | |
parent | dm table: rework reference counting (diff) | |
download | linux-784aae735d9b0bba3f8b9faef4c8b30df3bf0128.tar.xz linux-784aae735d9b0bba3f8b9faef4c8b30df3bf0128.zip |
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.c | 29 |
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 @@ /* * 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. */ @@ -167,6 +167,9 @@ struct mapped_device { /* forced geometry settings */ struct hd_geometry geometry; + + /* sysfs handle */ + struct kobject kobj; }; #define MIN_IOS 256 @@ -1285,6 +1288,8 @@ int dm_create(int minor, struct mapped_device **result) if (!md) return -ENXIO; + dm_sysfs_init(md); + *result = md; return 0; } @@ -1360,6 +1365,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); @@ -1699,6 +1705,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); |