Commit ba2e19b0 authored by Mikulas Patocka's avatar Mikulas Patocka Committed by Alasdair G Kergon

dm ioctl: introduce __get_dev_cell

Move logic to find device based on major/minor number to a separate
function __get_dev_cell (similar to __get_uuid_cell and __get_name_cell).
This makes the function __find_device_hash_cell more straightforward.
Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
Signed-off-by: default avatarAlasdair G Kergon <agk@redhat.com>
parent 0ddf9644
...@@ -128,6 +128,24 @@ static struct hash_cell *__get_uuid_cell(const char *str) ...@@ -128,6 +128,24 @@ static struct hash_cell *__get_uuid_cell(const char *str)
return NULL; return NULL;
} }
static struct hash_cell *__get_dev_cell(uint64_t dev)
{
struct mapped_device *md;
struct hash_cell *hc;
md = dm_get_md(huge_decode_dev(dev));
if (!md)
return NULL;
hc = dm_get_mdptr(md);
if (!hc) {
dm_put(md);
return NULL;
}
return hc;
}
/*----------------------------------------------------------------- /*-----------------------------------------------------------------
* Inserting, removing and renaming a device. * Inserting, removing and renaming a device.
*---------------------------------------------------------------*/ *---------------------------------------------------------------*/
...@@ -718,34 +736,23 @@ static int dev_create(struct dm_ioctl *param, size_t param_size) ...@@ -718,34 +736,23 @@ static int dev_create(struct dm_ioctl *param, size_t param_size)
*/ */
static struct hash_cell *__find_device_hash_cell(struct dm_ioctl *param) static struct hash_cell *__find_device_hash_cell(struct dm_ioctl *param)
{ {
struct mapped_device *md;
struct hash_cell *hc = NULL; struct hash_cell *hc = NULL;
if (*param->uuid) { if (*param->uuid) {
hc = __get_uuid_cell(param->uuid); hc = __get_uuid_cell(param->uuid);
if (!hc) if (!hc)
return NULL; return NULL;
goto fill_params; } else if (*param->name) {
}
if (*param->name) {
hc = __get_name_cell(param->name); hc = __get_name_cell(param->name);
if (!hc) if (!hc)
return NULL; return NULL;
goto fill_params; } else if (param->dev) {
} hc = __get_dev_cell(param->dev);
if (!hc)
md = dm_get_md(huge_decode_dev(param->dev)); return NULL;
if (!md) } else
return NULL;
hc = dm_get_mdptr(md);
if (!hc) {
dm_put(md);
return NULL; return NULL;
}
fill_params:
/* /*
* Sneakily write in both the name and the uuid * Sneakily write in both the name and the uuid
* while we have the cell. * while we have the cell.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment