* [PATCH 1/6] kobject_add_dir
2006-03-04 0:45 [PATCH 0/6] dm/md sysfs dependency tree (rev.3) Jun'ichi Nomura
@ 2006-03-04 0:57 ` Jun'ichi Nomura
2006-03-04 0:57 ` [PATCH 2/6] add holders/slaves subdirectory to /sys/block Jun'ichi Nomura
` (4 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Jun'ichi Nomura @ 2006-03-04 0:57 UTC (permalink / raw)
To: Alasdair Kergon, Neil Brown, Greg KH, linux-kernel
Cc: Lars Marowsky-Bree, akpm, device-mapper development
[-- Attachment #1: Type: text/plain, Size: 199 bytes --]
This patch is part of dm/md sysfs dependency tree.
This adds kobject_add_dir() function which creates a subdirectory
for a given kobject.
Thanks,
--
Jun'ichi Nomura, NEC Solutions (America), Inc.
[-- Attachment #2: 01-kobject_add_dir.patch --]
[-- Type: text/x-patch, Size: 1753 bytes --]
Adding kobject_add_dir() function which creates a subdirectory
for a given kobject.
Signed-off-by: Jun'ichi Nomura <j-nomura@ce.jp.nec.com>
include/linux/kobject.h | 2 ++
lib/kobject.c | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+)
--- linux-2.6.16-rc5.orig/include/linux/kobject.h 2006-02-27 00:09:35.000000000 -0500
+++ linux-2.6.16-rc5/include/linux/kobject.h 2006-03-02 14:26:26.000000000 -0500
@@ -80,6 +80,8 @@ extern void kobject_unregister(struct ko
extern struct kobject * kobject_get(struct kobject *);
extern void kobject_put(struct kobject *);
+extern struct kobject * kobject_add_dir(struct kobject *, const char *);
+
extern char * kobject_get_path(struct kobject *, gfp_t);
struct kobj_type {
--- linux-2.6.16-rc5.orig/lib/kobject.c 2006-02-27 00:09:35.000000000 -0500
+++ linux-2.6.16-rc5/lib/kobject.c 2006-03-02 14:26:26.000000000 -0500
@@ -379,6 +379,43 @@ void kobject_put(struct kobject * kobj)
}
+static void dir_release(struct kobject *kobj)
+{
+ kfree(kobj);
+}
+
+static struct kobj_type dir_ktype = {
+ .release = dir_release,
+ .sysfs_ops = NULL,
+ .default_attrs = NULL,
+};
+
+/**
+ * kobject_add_dir - add sub directory of object.
+ * @parent: object in which a directory is created.
+ * @name: directory name.
+ *
+ * Add a plain directory object as child of given object.
+ */
+struct kobject *kobject_add_dir(struct kobject *parent, const char *name)
+{
+ struct kobject *k;
+
+ if (!parent)
+ return NULL;
+
+ k = kzalloc(sizeof(*k), GFP_KERNEL);
+ if (!k)
+ return NULL;
+
+ k->parent = parent;
+ k->ktype = &dir_ktype;
+ kobject_set_name(k, name);
+ kobject_register(k);
+
+ return k;
+}
+
/**
* kset_init - initialize a kset for use
* @k: kset
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/6] add holders/slaves subdirectory to /sys/block
2006-03-04 0:45 [PATCH 0/6] dm/md sysfs dependency tree (rev.3) Jun'ichi Nomura
2006-03-04 0:57 ` [PATCH 1/6] kobject_add_dir Jun'ichi Nomura
@ 2006-03-04 0:57 ` Jun'ichi Nomura
2006-03-04 0:57 ` [PATCH 3/6] bd_claim_by_kobject Jun'ichi Nomura
` (3 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Jun'ichi Nomura @ 2006-03-04 0:57 UTC (permalink / raw)
To: Alasdair Kergon, Neil Brown, Greg KH, linux-kernel
Cc: Lars Marowsky-Bree, akpm, device-mapper development
[-- Attachment #1: Type: text/plain, Size: 266 bytes --]
This patch is part of dm/md sysfs dependency tree.
With this patch, "slaves" and "holders" directories are
created in /sys/block/<disk> and
"holders" directory is created in /sys/block/<disk>/<partition>.
Thanks,
--
Jun'ichi Nomura, NEC Solutions (America), Inc.
[-- Attachment #2: 02-add_subdirs.patch --]
[-- Type: text/x-patch, Size: 2824 bytes --]
Creating "slaves" and "holders" directories in /sys/block/<disk> and
creating "holders" directory under /sys/block/<disk>/<partition>
Signed-off-by: Jun'ichi Nomura <j-nomura@ce.jp.nec.com>
fs/partitions/check.c | 27 +++++++++++++++++++++++++++
include/linux/genhd.h | 3 +++
2 files changed, 30 insertions(+)
--- linux-2.6.16-rc5.orig/include/linux/genhd.h 2006-02-27 00:09:35.000000000 -0500
+++ linux-2.6.16-rc5/include/linux/genhd.h 2006-03-02 10:29:55.000000000 -0500
@@ -78,6 +78,7 @@ struct hd_struct {
sector_t start_sect;
sector_t nr_sects;
struct kobject kobj;
+ struct kobject *holder_dir;
unsigned ios[2], sectors[2]; /* READs and WRITEs */
int policy, partno;
};
@@ -114,6 +115,8 @@ struct gendisk {
int number; /* more of the same */
struct device *driverfs_dev;
struct kobject kobj;
+ struct kobject *holder_dir;
+ struct kobject *slave_dir;
struct timer_rand_state *random;
int policy;
--- linux-2.6.16-rc5.orig/fs/partitions/check.c 2006-02-27 00:09:35.000000000 -0500
+++ linux-2.6.16-rc5/fs/partitions/check.c 2006-03-02 10:29:55.000000000 -0500
@@ -297,6 +297,25 @@ struct kobj_type ktype_part = {
.sysfs_ops = &part_sysfs_ops,
};
+static inline void partition_sysfs_add_subdir(struct hd_struct *p)
+{
+ struct kobject *k;
+
+ k = kobject_get(&p->kobj);
+ p->holder_dir = kobject_add_dir(k, "holders");
+ kobject_put(k);
+}
+
+static inline void disk_sysfs_add_subdirs(struct gendisk *disk)
+{
+ struct kobject *k;
+
+ k = kobject_get(&disk->kobj);
+ disk->holder_dir = kobject_add_dir(k, "holders");
+ disk->slave_dir = kobject_add_dir(k, "slaves");
+ kobject_put(k);
+}
+
void delete_partition(struct gendisk *disk, int part)
{
struct hd_struct *p = disk->part[part-1];
@@ -310,6 +329,8 @@ void delete_partition(struct gendisk *di
p->ios[0] = p->ios[1] = 0;
p->sectors[0] = p->sectors[1] = 0;
devfs_remove("%s/part%d", disk->devfs_name, part);
+ if (p->holder_dir)
+ kobject_unregister(p->holder_dir);
kobject_unregister(&p->kobj);
}
@@ -337,6 +358,7 @@ void add_partition(struct gendisk *disk,
p->kobj.parent = &disk->kobj;
p->kobj.ktype = &ktype_part;
kobject_register(&p->kobj);
+ partition_sysfs_add_subdir(p);
disk->part[part-1] = p;
}
@@ -383,6 +405,7 @@ void register_disk(struct gendisk *disk)
if ((err = kobject_add(&disk->kobj)))
return;
disk_sysfs_symlinks(disk);
+ disk_sysfs_add_subdirs(disk);
kobject_uevent(&disk->kobj, KOBJ_ADD);
/* No minors to use for partitions */
@@ -483,6 +506,10 @@ void del_gendisk(struct gendisk *disk)
devfs_remove_disk(disk);
+ if (disk->holder_dir)
+ kobject_unregister(disk->holder_dir);
+ if (disk->holder_dir)
+ kobject_unregister(disk->slave_dir);
if (disk->driverfs_dev) {
char *disk_name = make_block_name(disk);
sysfs_remove_link(&disk->kobj, "device");
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 3/6] bd_claim_by_kobject
2006-03-04 0:45 [PATCH 0/6] dm/md sysfs dependency tree (rev.3) Jun'ichi Nomura
2006-03-04 0:57 ` [PATCH 1/6] kobject_add_dir Jun'ichi Nomura
2006-03-04 0:57 ` [PATCH 2/6] add holders/slaves subdirectory to /sys/block Jun'ichi Nomura
@ 2006-03-04 0:57 ` Jun'ichi Nomura
2006-03-04 0:57 ` [PATCH 4/6] bd_claim_by_disk Jun'ichi Nomura
` (2 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Jun'ichi Nomura @ 2006-03-04 0:57 UTC (permalink / raw)
To: Alasdair Kergon, Neil Brown, Greg KH, linux-kernel
Cc: Lars Marowsky-Bree, akpm, device-mapper development
[-- Attachment #1: Type: text/plain, Size: 351 bytes --]
This patch is part of dm/md sysfs dependency tree.
This adds bd_claim_by_kobject() function which takes kobject as
additional signature of holder device and creates sysfs symlinks
between holder device and claimed device.
bd_release_from_kobject() is a counter part of bd_claim_by_kobject.
Thanks,
--
Jun'ichi Nomura, NEC Solutions (America), Inc.
[-- Attachment #2: 03-bd_claim_by_kobj.patch --]
[-- Type: text/x-patch, Size: 7290 bytes --]
Adding bd_claim_by_kobject() function which takes kobject as
additional signature of holder device and creates sysfs symlinks
between holder device and claimed device.
bd_release_from_kobject() is a counter part of bd_claim_by_kobject.
Signed-off-by: Jun'ichi Nomura <j-nomura@ce.jp.nec.com>
fs/block_dev.c | 196 +++++++++++++++++++++++++++++++++++++++++++++++++++-
include/linux/fs.h | 3
2 files changed, 197 insertions(+), 2 deletions(-)
--- linux-2.6.16-rc5.orig/include/linux/fs.h 2006-02-27 00:09:35.000000000 -0500
+++ linux-2.6.16-rc5/include/linux/fs.h 2006-03-02 10:29:55.000000000 -0500
@@ -401,6 +401,7 @@ struct block_device {
struct list_head bd_inodes;
void * bd_holder;
int bd_holders;
+ struct list_head bd_holder_list;
struct block_device * bd_contains;
unsigned bd_block_size;
struct hd_struct * bd_part;
@@ -1380,6 +1381,8 @@ extern int blkdev_get(struct block_devic
extern int blkdev_put(struct block_device *);
extern int bd_claim(struct block_device *, void *);
extern void bd_release(struct block_device *);
+extern int bd_claim_by_kobject(struct block_device *, void *, struct kobject *);
+extern void bd_release_from_kobject(struct block_device *, struct kobject *);
/* fs/char_dev.c */
extern int alloc_chrdev_region(dev_t *, unsigned, unsigned, const char *);
--- linux-2.6.16-rc5.orig/fs/block_dev.c 2006-02-27 00:09:35.000000000 -0500
+++ linux-2.6.16-rc5/fs/block_dev.c 2006-03-02 10:29:55.000000000 -0500
@@ -269,6 +269,7 @@ static void init_once(void * foo, kmem_c
sema_init(&bdev->bd_mount_sem, 1);
INIT_LIST_HEAD(&bdev->bd_inodes);
INIT_LIST_HEAD(&bdev->bd_list);
+ INIT_LIST_HEAD(&bdev->bd_holder_list);
inode_init_once(&ei->vfs_inode);
}
}
@@ -443,7 +444,179 @@ void bd_forget(struct inode *inode)
spin_unlock(&bdev_lock);
}
-int bd_claim(struct block_device *bdev, void *holder)
+/*
+ * Functions for bd_claim_by_kobject / bd_release_from_kobject
+ *
+ * If a kobject is passed to bd_claim_by_kobject()
+ * and the kobject has a parent directory,
+ * following symlinks are created:
+ * o from the kobject to the claimed bdev
+ * o from "holders" directory of the bdev to the parent of the kobject
+ * bd_release_from_kobject() removes these symlinks.
+ *
+ * Example:
+ * If /dev/dm-0 maps to /dev/sda, kobject corresponding to
+ * /sys/block/dm-0/slaves is passed to bd_claim_by_kobject(), then:
+ * /sys/block/dm-0/slaves/sda --> /sys/block/sda
+ * /sys/block/sda/holders/dm-0 --> /sys/block/dm-0
+ */
+
+static inline struct kobject * bdev_get_kobj(struct block_device *bdev)
+{
+ if (!bdev)
+ return NULL;
+ else if (bdev->bd_contains != bdev)
+ return kobject_get(&bdev->bd_part->kobj);
+ else
+ return kobject_get(&bdev->bd_disk->kobj);
+}
+
+static inline struct kobject * bdev_get_holder(struct block_device *bdev)
+{
+ if (!bdev)
+ return NULL;
+ else if (bdev->bd_contains != bdev)
+ return kobject_get(bdev->bd_part->holder_dir);
+ else
+ return kobject_get(bdev->bd_disk->holder_dir);
+}
+
+static inline void add_symlink(struct kobject *from, struct kobject *to)
+{
+ if (!from || !to)
+ return;
+ kobject_get(from);
+ kobject_get(to);
+ sysfs_create_link(from, to, kobject_name(to));
+}
+
+static inline void del_symlink(struct kobject *from, struct kobject *to)
+{
+ if (!from || !to)
+ return;
+ sysfs_remove_link(from, kobject_name(to));
+ kobject_put(from);
+ kobject_put(to);
+}
+
+static inline int bd_claim_grab_dirs(struct block_device *bdev,
+ struct kobject *holder,
+ struct kobject **sdir, struct kobject **sdev,
+ struct kobject **hdir, struct kobject **hdev)
+{
+ *sdir = kobject_get(holder);
+ if (!*sdir)
+ return 0;
+
+ *hdev = kobject_get((*sdir)->parent);
+ if (!*hdev)
+ goto fail_put_sdir;
+
+ *sdev = bdev_get_kobj(bdev);
+ if (!*sdev)
+ goto fail_put_hdev;
+
+ *hdir = bdev_get_holder(bdev);
+ if (!*hdir)
+ goto fail_put_sdev;
+
+ return 1;
+
+fail_put_sdev:
+ kobject_put(*sdev);
+fail_put_hdev:
+ kobject_put(*hdev);
+fail_put_sdir:
+ kobject_put(*sdir);
+
+ return 0;
+}
+
+static inline void bd_claim_release_dirs(
+ struct kobject *sdir, struct kobject *sdev,
+ struct kobject *hdir, struct kobject *hdev)
+{
+ kobject_put(hdir);
+ kobject_put(sdev);
+ kobject_put(hdev);
+ kobject_put(sdir);
+}
+
+static void link_bd_holder(struct block_device *bdev, struct kobject *holder)
+{
+ struct kobject *sdir, *sdev, *hdir, *hdev;
+
+ if (bd_claim_grab_dirs(bdev, holder, &sdir, &sdev, &hdir, &hdev)) {
+ add_symlink(sdir, sdev);
+ add_symlink(hdir, hdev);
+ bd_claim_release_dirs(sdir, sdev, hdir, hdev);
+ }
+
+ return;
+}
+
+static void unlink_bd_holder(struct block_device *bdev, struct kobject *holder)
+{
+ struct kobject *sdir, *sdev, *hdir, *hdev;
+
+ if (bd_claim_grab_dirs(bdev, holder, &sdir, &sdev, &hdir, &hdev)) {
+ del_symlink(sdir, sdev);
+ del_symlink(hdir, hdev);
+ bd_claim_release_dirs(sdir, sdev, hdir, hdev);
+ }
+}
+
+/* bd_holder_list is protected by bdev_lock */
+struct bd_holder {
+ struct list_head list; /* chain of holders of the bdev */
+ int count; /* references from the holder */
+ struct kobject *kobj; /* holder kobject */
+};
+
+static int add_bd_holder(struct block_device *bdev, struct kobject *kobj)
+{
+ struct bd_holder *bo;
+
+ list_for_each_entry(bo, &bdev->bd_holder_list, list) {
+ if (bo->kobj == kobj) {
+ bo->count++;
+ return 0;
+ }
+ }
+
+ bo = kmalloc(sizeof(*bo), GFP_KERNEL);
+ if (!bo)
+ return -ENOMEM;
+
+ bo->count = 1;
+ bo->kobj = kobj;
+ list_add_tail(&bo->list, &bdev->bd_holder_list);
+ link_bd_holder(bdev, kobj);
+
+ return 0;
+}
+
+static int del_bd_holder(struct block_device *bdev, struct kobject *kobj)
+{
+ struct bd_holder *bo;
+
+ list_for_each_entry(bo, &bdev->bd_holder_list, list) {
+ if (bo->kobj == kobj) {
+ bo->count--;
+ BUG_ON(bo->count < 0);
+ if (!bo->count) {
+ unlink_bd_holder(bdev, kobj);
+ list_del(&bo->list);
+ kfree(bo);
+ }
+ break;
+ }
+ }
+
+ return 0;
+}
+
+int bd_claim_by_kobject(struct block_device *bdev, void *holder, struct kobject *kobj)
{
int res;
spin_lock(&bdev_lock);
@@ -464,6 +637,9 @@ int bd_claim(struct block_device *bdev,
res = 0; /* is a partition of an un-held device */
/* now impose change */
+ if (res == 0 && kobj)
+ res = add_bd_holder(bdev, kobj);
+
if (res==0) {
/* note that for a whole device bd_holders
* will be incremented twice, and bd_holder will
@@ -478,11 +654,20 @@ int bd_claim(struct block_device *bdev,
return res;
}
+EXPORT_SYMBOL(bd_claim_by_kobject);
+
+int bd_claim(struct block_device *bdev, void *holder)
+{
+ return bd_claim_by_kobject(bdev, holder, NULL);
+}
+
EXPORT_SYMBOL(bd_claim);
-void bd_release(struct block_device *bdev)
+void bd_release_from_kobject(struct block_device *bdev, struct kobject *kobj)
{
spin_lock(&bdev_lock);
+ if (kobj)
+ del_bd_holder(bdev, kobj);
if (!--bdev->bd_contains->bd_holders)
bdev->bd_contains->bd_holder = NULL;
if (!--bdev->bd_holders)
@@ -490,6 +675,13 @@ void bd_release(struct block_device *bde
spin_unlock(&bdev_lock);
}
+EXPORT_SYMBOL(bd_release_from_kobject);
+
+void bd_release(struct block_device *bdev)
+{
+ bd_release_from_kobject(bdev, NULL);
+}
+
EXPORT_SYMBOL(bd_release);
/*
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 4/6] bd_claim_by_disk
2006-03-04 0:45 [PATCH 0/6] dm/md sysfs dependency tree (rev.3) Jun'ichi Nomura
` (2 preceding siblings ...)
2006-03-04 0:57 ` [PATCH 3/6] bd_claim_by_kobject Jun'ichi Nomura
@ 2006-03-04 0:57 ` Jun'ichi Nomura
2006-03-04 0:58 ` [PATCH 5/6] md to use bd_claim_by_disk Jun'ichi Nomura
2006-03-04 0:58 ` [PATCH 6/6] dm " Jun'ichi Nomura
5 siblings, 0 replies; 9+ messages in thread
From: Jun'ichi Nomura @ 2006-03-04 0:57 UTC (permalink / raw)
To: Alasdair Kergon, Neil Brown, Greg KH, linux-kernel
Cc: Lars Marowsky-Bree, akpm, device-mapper development
[-- Attachment #1: Type: text/plain, Size: 240 bytes --]
This patch is part of dm/md sysfs dependency tree.
This adds variants of bd_claim_by_kobject which takes gendisk instead
of kobject and do kobject_{get,put}(&gendisk->slave_dir).
Thanks,
--
Jun'ichi Nomura, NEC Solutions (America), Inc.
[-- Attachment #2: 04-bd_claim_by_disk.patch --]
[-- Type: text/x-patch, Size: 940 bytes --]
Variants of bd_claim_by_kobject which takes gendisk instead
of kobject and do kobject_{get,put}(&gendisk->slave_dir).
Signed-off-by: Jun'ichi Nomura <j-nomura@ce.jp.nec.com>
include/linux/genhd.h | 13 +++++++++++++
1 files changed, 13 insertions(+)
--- linux-2.6.16-rc5.orig/include/linux/genhd.h 2006-02-27 00:09:35.000000000 -0500
+++ linux-2.6.16-rc5/include/linux/genhd.h 2006-03-02 10:29:55.000000000 -0500
@@ -421,6 +424,19 @@ static inline struct block_device *bdget
return bdget(MKDEV(disk->major, disk->first_minor) + index);
}
+static inline int bd_claim_by_disk(struct block_device *bdev,
+ void *holder, struct gendisk *disk)
+{
+ return bd_claim_by_kobject(bdev, holder, kobject_get(disk->slave_dir));
+}
+
+static inline void bd_release_from_disk(struct block_device *bdev,
+ struct gendisk *disk)
+{
+ bd_release_from_kobject(bdev, disk->slave_dir);
+ kobject_put(disk->slave_dir);
+}
+
#endif
#endif
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 5/6] md to use bd_claim_by_disk
2006-03-04 0:45 [PATCH 0/6] dm/md sysfs dependency tree (rev.3) Jun'ichi Nomura
` (3 preceding siblings ...)
2006-03-04 0:57 ` [PATCH 4/6] bd_claim_by_disk Jun'ichi Nomura
@ 2006-03-04 0:58 ` Jun'ichi Nomura
2006-03-04 0:58 ` [PATCH 6/6] dm " Jun'ichi Nomura
5 siblings, 0 replies; 9+ messages in thread
From: Jun'ichi Nomura @ 2006-03-04 0:58 UTC (permalink / raw)
To: Alasdair Kergon, Neil Brown, Greg KH, linux-kernel
Cc: Lars Marowsky-Bree, akpm, device-mapper development
[-- Attachment #1: Type: text/plain, Size: 366 bytes --]
This patch is part of dm/md sysfs dependency tree.
Following symlinks are created if md0 is built from sda and sdb
/sys/block/md0/slaves/sda --> /sys/block/sda
/sys/block/md0/slaves/sdb --> /sys/block/sdb
/sys/block/sda/holders/md0 --> /sys/block/md0
/sys/block/sdb/holders/md0 --> /sys/block/md0
Thanks,
--
Jun'ichi Nomura, NEC Solutions (America), Inc.
[-- Attachment #2: 05-md_deptree.patch --]
[-- Type: text/x-patch, Size: 1041 bytes --]
Use bd_claim_by_disk.
Following symlinks are created if md0 is built from sda and sdb
/sys/block/md0/slaves/sda --> /sys/block/sda
/sys/block/md0/slaves/sdb --> /sys/block/sdb
/sys/block/sda/holders/md0 --> /sys/block/md0
/sys/block/sdb/holders/md0 --> /sys/block/md0
Signed-off-by: Jun'ichi Nomura <j-nomura@ce.jp.nec.com>
drivers/md/md.c | 2 ++
1 files changed, 2 insertions(+)
--- linux-2.6.16-rc5.orig/drivers/md/md.c 2006-02-27 00:09:35.000000000 -0500
+++ linux-2.6.16-rc5/drivers/md/md.c 2006-03-02 14:57:05.000000000 -0500
@@ -1298,6 +1298,7 @@ static int bind_rdev_to_array(mdk_rdev_t
else
ko = &rdev->bdev->bd_disk->kobj;
sysfs_create_link(&rdev->kobj, ko, "block");
+ bd_claim_by_disk(rdev->bdev, rdev, mddev->gendisk);
return 0;
}
@@ -1308,6 +1309,7 @@ static void unbind_rdev_from_array(mdk_r
MD_BUG();
return;
}
+ bd_release_from_disk(rdev->bdev, rdev->mddev->gendisk);
list_del_init(&rdev->same_set);
printk(KERN_INFO "md: unbind<%s>\n", bdevname(rdev->bdev,b));
rdev->mddev = NULL;
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 6/6] dm to use bd_claim_by_disk
2006-03-04 0:45 [PATCH 0/6] dm/md sysfs dependency tree (rev.3) Jun'ichi Nomura
` (4 preceding siblings ...)
2006-03-04 0:58 ` [PATCH 5/6] md to use bd_claim_by_disk Jun'ichi Nomura
@ 2006-03-04 0:58 ` Jun'ichi Nomura
2006-03-06 15:56 ` Alasdair G Kergon
5 siblings, 1 reply; 9+ messages in thread
From: Jun'ichi Nomura @ 2006-03-04 0:58 UTC (permalink / raw)
To: Alasdair Kergon, Neil Brown, Greg KH, linux-kernel
Cc: Lars Marowsky-Bree, akpm, device-mapper development
[-- Attachment #1: Type: text/plain, Size: 383 bytes --]
This patch is part of dm/md sysfs dependency tree.
Following symlinks are created if dm-0 maps to sda:
/sys/block/dm-0/slaves/sda --> /sys/block/sda
/sys/block/sda/holders/dm-0 --> /sys/block/dm-0
This patch depends on dm-table-store-md.patch in
http://www.kernel.org/pub/linux/kernel/people/agk/patches/2.6/editing/
Thanks,
--
Jun'ichi Nomura, NEC Solutions (America), Inc.
[-- Attachment #2: 06-dm_deptree.patch --]
[-- Type: text/x-patch, Size: 2904 bytes --]
Use bd_claim_by_disk.
Following symlinks are created if dm-0 maps to sda:
/sys/block/dm-0/slaves/sda --> /sys/block/sda
/sys/block/sda/holders/dm-0 --> /sys/block/dm-0
This patch depends on dm-table-store-md.patch in
http://www.kernel.org/pub/linux/kernel/people/agk/patches/2.6/editing/
Signed-off-by: Jun'ichi Nomura <j-nomura@ce.jp.nec.com>
drivers/md/dm-table.c | 20 ++++++++++----------
1 files changed, 10 insertions(+), 10 deletions(-)
--- linux-2.6.16-rc5.orig/drivers/md/dm-table.c 2006-03-02 14:55:14.000000000 -0500
+++ linux-2.6.16-rc5/drivers/md/dm-table.c 2006-03-02 14:57:01.000000000 -0500
@@ -348,7 +348,7 @@ static struct dm_dev *find_device(struct
/*
* Open a device so we can use it as a map destination.
*/
-static int open_dev(struct dm_dev *d, dev_t dev)
+static int open_dev(struct dm_dev *d, dev_t dev, struct gendisk *holder)
{
static char *_claim_ptr = "I belong to device-mapper";
struct block_device *bdev;
@@ -361,7 +361,7 @@ static int open_dev(struct dm_dev *d, de
bdev = open_by_devnum(dev, d->mode);
if (IS_ERR(bdev))
return PTR_ERR(bdev);
- r = bd_claim(bdev, _claim_ptr);
+ r = bd_claim_by_disk(bdev, _claim_ptr, holder);
if (r)
blkdev_put(bdev);
else
@@ -372,12 +372,12 @@ static int open_dev(struct dm_dev *d, de
/*
* Close a device that we've been using.
*/
-static void close_dev(struct dm_dev *d)
+static void close_dev(struct dm_dev *d, struct gendisk *holder)
{
if (!d->bdev)
return;
- bd_release(d->bdev);
+ bd_release_from_disk(d->bdev, holder);
blkdev_put(d->bdev);
d->bdev = NULL;
}
@@ -398,7 +398,7 @@ static int check_device_area(struct dm_d
* careful to leave things as they were if we fail to reopen the
* device.
*/
-static int upgrade_mode(struct dm_dev *dd, int new_mode)
+static int upgrade_mode(struct dm_dev *dd, int new_mode, struct gendisk *holder)
{
int r;
struct dm_dev dd_copy;
@@ -408,9 +408,9 @@ static int upgrade_mode(struct dm_dev *d
dd->mode |= new_mode;
dd->bdev = NULL;
- r = open_dev(dd, dev);
+ r = open_dev(dd, dev, holder);
if (!r)
- close_dev(&dd_copy);
+ close_dev(&dd_copy, holder);
else
*dd = dd_copy;
@@ -453,7 +453,7 @@ static int __table_get_device(struct dm_
dd->mode = mode;
dd->bdev = NULL;
- if ((r = open_dev(dd, dev))) {
+ if ((r = open_dev(dd, dev, dm_disk(t->md)))) {
kfree(dd);
return r;
}
@@ -464,7 +464,7 @@ static int __table_get_device(struct dm_
list_add(&dd->list, &t->devices);
} else if (dd->mode != (mode | dd->mode)) {
- r = upgrade_mode(dd, mode);
+ r = upgrade_mode(dd, mode, dm_disk(t->md));
if (r)
return r;
}
@@ -539,7 +539,7 @@ int dm_get_device(struct dm_target *ti,
void dm_put_device(struct dm_target *ti, struct dm_dev *dd)
{
if (atomic_dec_and_test(&dd->count)) {
- close_dev(dd);
+ close_dev(dd, dm_disk(ti->table->md));
list_del(&dd->list);
kfree(dd);
}
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 6/6] dm to use bd_claim_by_disk
2006-03-04 0:58 ` [PATCH 6/6] dm " Jun'ichi Nomura
@ 2006-03-06 15:56 ` Alasdair G Kergon
2006-03-06 17:00 ` Jun'ichi Nomura
0 siblings, 1 reply; 9+ messages in thread
From: Alasdair G Kergon @ 2006-03-06 15:56 UTC (permalink / raw)
To: Jun'ichi Nomura; +Cc: linux-kernel, akpm, device-mapper development
On Fri, Mar 03, 2006 at 07:58:32PM -0500, Jun'ichi Nomura wrote:
> This patch is part of dm/md sysfs dependency tree.
> +static int open_dev(struct dm_dev *d, dev_t dev, struct gendisk *holder)
> +static int upgrade_mode(struct dm_dev *dd, int new_mode, struct gendisk *holder)
> +static void close_dev(struct dm_dev *d, struct gendisk *holder)
Please pass the dm structure, struct mapped_device, around between dm functions
internally where you can, instead of struct gendisk. (Every time the new
parameter is passed it's wrapped with dm_disk(), so move the dm_disk() inside.)
Alasdair
--
agk@redhat.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 6/6] dm to use bd_claim_by_disk
2006-03-06 15:56 ` Alasdair G Kergon
@ 2006-03-06 17:00 ` Jun'ichi Nomura
0 siblings, 0 replies; 9+ messages in thread
From: Jun'ichi Nomura @ 2006-03-06 17:00 UTC (permalink / raw)
To: Alasdair G Kergon; +Cc: linux-kernel, akpm, device-mapper development
[-- Attachment #1: Type: text/plain, Size: 697 bytes --]
Hi Alasdair,
Alasdair G Kergon wrote:
>>+static int open_dev(struct dm_dev *d, dev_t dev, struct gendisk *holder)
>>+static int upgrade_mode(struct dm_dev *dd, int new_mode, struct gendisk *holder)
>>+static void close_dev(struct dm_dev *d, struct gendisk *holder)
>
> Please pass the dm structure, struct mapped_device, around between dm functions
> internally where you can, instead of struct gendisk. (Every time the new
> parameter is passed it's wrapped with dm_disk(), so move the dm_disk() inside.)
Thank you for the comment. I changed them and updated the patch.
Could you check whether there is any other wrong thing?
Thanks,
--
Jun'ichi Nomura, NEC Solutions (America), Inc.
[-- Attachment #2: 06-dm_deptree-2.patch --]
[-- Type: text/x-patch, Size: 2886 bytes --]
Use bd_claim_by_disk.
Following symlinks are created if dm-0 maps to sda:
/sys/block/dm-0/slaves/sda --> /sys/block/sda
/sys/block/sda/holders/dm-0 --> /sys/block/dm-0
This patch depends on dm-table-store-md.patch in
http://www.kernel.org/pub/linux/kernel/people/agk/patches/2.6/editing/
Signed-off-by: Jun'ichi Nomura <j-nomura@ce.jp.nec.com>
drivers/md/dm-table.c | 20 ++++++++++----------
1 files changed, 10 insertions(+), 10 deletions(-)
--- linux-2.6.16-rc5.orig/drivers/md/dm-table.c 2006-03-02 14:55:14.000000000 -0500
+++ linux-2.6.16-rc5/drivers/md/dm-table.c 2006-03-06 11:00:23.000000000 -0500
@@ -348,7 +348,7 @@ static struct dm_dev *find_device(struct
/*
* Open a device so we can use it as a map destination.
*/
-static int open_dev(struct dm_dev *d, dev_t dev)
+static int open_dev(struct dm_dev *d, dev_t dev, struct mapped_device *md)
{
static char *_claim_ptr = "I belong to device-mapper";
struct block_device *bdev;
@@ -361,7 +361,7 @@ static int open_dev(struct dm_dev *d, de
bdev = open_by_devnum(dev, d->mode);
if (IS_ERR(bdev))
return PTR_ERR(bdev);
- r = bd_claim(bdev, _claim_ptr);
+ r = bd_claim_by_disk(bdev, _claim_ptr, dm_disk(md));
if (r)
blkdev_put(bdev);
else
@@ -372,12 +372,12 @@ static int open_dev(struct dm_dev *d, de
/*
* Close a device that we've been using.
*/
-static void close_dev(struct dm_dev *d)
+static void close_dev(struct dm_dev *d, struct mapped_device *md)
{
if (!d->bdev)
return;
- bd_release(d->bdev);
+ bd_release_from_disk(d->bdev, dm_disk(md));
blkdev_put(d->bdev);
d->bdev = NULL;
}
@@ -398,7 +398,7 @@ static int check_device_area(struct dm_d
* careful to leave things as they were if we fail to reopen the
* device.
*/
-static int upgrade_mode(struct dm_dev *dd, int new_mode)
+static int upgrade_mode(struct dm_dev *dd, int new_mode, struct mapped_device *md)
{
int r;
struct dm_dev dd_copy;
@@ -408,9 +408,9 @@ static int upgrade_mode(struct dm_dev *d
dd->mode |= new_mode;
dd->bdev = NULL;
- r = open_dev(dd, dev);
+ r = open_dev(dd, dev, md);
if (!r)
- close_dev(&dd_copy);
+ close_dev(&dd_copy, md);
else
*dd = dd_copy;
@@ -453,7 +453,7 @@ static int __table_get_device(struct dm_
dd->mode = mode;
dd->bdev = NULL;
- if ((r = open_dev(dd, dev))) {
+ if ((r = open_dev(dd, dev, t->md))) {
kfree(dd);
return r;
}
@@ -464,7 +464,7 @@ static int __table_get_device(struct dm_
list_add(&dd->list, &t->devices);
} else if (dd->mode != (mode | dd->mode)) {
- r = upgrade_mode(dd, mode);
+ r = upgrade_mode(dd, mode, t->md);
if (r)
return r;
}
@@ -539,7 +539,7 @@ int dm_get_device(struct dm_target *ti,
void dm_put_device(struct dm_target *ti, struct dm_dev *dd)
{
if (atomic_dec_and_test(&dd->count)) {
- close_dev(dd);
+ close_dev(dd, ti->table->md);
list_del(&dd->list);
kfree(dd);
}
^ permalink raw reply [flat|nested] 9+ messages in thread