Ioctl interface accepts refs by device number, not just name or uuid. --- diff/drivers/md/dm-ioctl.c 2004-09-28 19:49:52.000000000 +0100 +++ source/drivers/md/dm-ioctl.c 2004-09-30 15:05:53.000000000 +0100 @@ -224,6 +224,7 @@ } register_with_devfs(cell); dm_get(md); + dm_set_mdptr(md, cell); up_write(&_hash_lock); return 0; @@ -240,6 +241,7 @@ list_del(&hc->uuid_list); list_del(&hc->name_list); unregister_with_devfs(hc); + dm_set_mdptr(hc->md, NULL); dm_put(hc->md); if (hc->new_map) dm_table_put(hc->new_map); @@ -579,12 +581,16 @@ } /* - * Always use UUID for lookups if it's present, otherwise use name. + * Always use UUID for lookups if it's present, otherwise use name or dev. */ static inline struct hash_cell *__find_device_hash_cell(struct dm_ioctl *param) { - return *param->uuid ? - __get_uuid_cell(param->uuid) : __get_name_cell(param->name); + if (*param->uuid) + return __get_uuid_cell(param->uuid); + else if (*param->name) + return __get_name_cell(param->name); + else + return dm_get_mdptr(huge_decode_dev(param->dev)); } static inline struct mapped_device *find_device(struct dm_ioctl *param) @@ -596,6 +602,7 @@ hc = __find_device_hash_cell(param); if (hc) { md = hc->md; + dm_get(md); /* * Sneakily write in both the name and the uuid @@ -611,8 +618,6 @@ param->flags |= DM_INACTIVE_PRESENT_FLAG; else param->flags &= ~DM_INACTIVE_PRESENT_FLAG; - - dm_get(md); } up_read(&_hash_lock); @@ -1265,14 +1270,14 @@ cmd == DM_LIST_VERSIONS_CMD) return 0; - /* Unless creating, either name or uuid but not both */ - if (cmd != DM_DEV_CREATE_CMD) { - if ((!*param->uuid && !*param->name) || - (*param->uuid && *param->name)) { - DMWARN("one of name or uuid must be supplied, cmd(%u)", - cmd); + if ((cmd == DM_DEV_CREATE_CMD)) { + if (!*param->name) { + DMWARN("name not supplied when creating device"); return -EINVAL; } + } else if ((*param->uuid && *param->name)) { + DMWARN("only supply one of name or uuid, cmd(%u)", cmd); + return -EINVAL; } /* Ensure strings are terminated */ --- diff/drivers/md/dm.c 2004-09-28 22:48:07.000000000 +0100 +++ source/drivers/md/dm.c 2004-09-30 15:03:00.000000000 +0100 @@ -59,6 +59,8 @@ request_queue_t *queue; struct gendisk *disk; + void *interface_ptr; + /* * A list of ios that arrived while we were suspended. */ @@ -888,28 +890,30 @@ atomic_inc(&md->holders); } -struct mapped_device *dm_get_by_dev(unsigned minor) +void *dm_get_mdptr(dev_t dev) { struct mapped_device *md; + void *mdptr = NULL; + unsigned minor = MINOR(dev); - if (minor >= (1 << MINORBITS)) + if (MAJOR(dev) != _major || minor >= (1 << MINORBITS)) return NULL; down(&_minor_lock); + md = idr_find(&_minor_idr, minor); - up(&_minor_lock); - if (!md) - return NULL; + if (md && (dm_disk(md)->first_minor == minor)) + mdptr = md->interface_ptr; - dm_get(md); + up(&_minor_lock); - if (dm_disk(md)->first_minor == minor) { - dm_put(md); - md = NULL; - } + return mdptr; +} - return md; +void dm_set_mdptr(struct mapped_device *md, void *ptr) +{ + md->interface_ptr = ptr; } void dm_put(struct mapped_device *md) --- diff/drivers/md/dm.h 2004-09-28 22:47:52.000000000 +0100 +++ source/drivers/md/dm.h 2004-09-30 15:03:06.000000000 +0100 @@ -54,6 +54,8 @@ *---------------------------------------------------------------*/ int dm_create(struct mapped_device **md); int dm_create_with_minor(unsigned int minor, struct mapped_device **md); +void dm_set_mdptr(struct mapped_device *md, void *ptr); +void *dm_get_mdptr(dev_t dev); /* * Reference counting for md.