Skip to content

Commit

Permalink
dm ioctl: introduce __get_dev_cell
Browse files Browse the repository at this point in the history
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: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
  • Loading branch information
Mikulas Patocka authored and Alasdair G Kergon committed Aug 2, 2011
1 parent 0ddf964 commit ba2e19b
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions drivers/md/dm-ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,24 @@ static struct hash_cell *__get_uuid_cell(const char *str)
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.
*---------------------------------------------------------------*/
Expand Down Expand Up @@ -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)
{
struct mapped_device *md;
struct hash_cell *hc = NULL;

if (*param->uuid) {
hc = __get_uuid_cell(param->uuid);
if (!hc)
return NULL;
goto fill_params;
}

if (*param->name) {
} else if (*param->name) {
hc = __get_name_cell(param->name);
if (!hc)
return NULL;
goto fill_params;
}

md = dm_get_md(huge_decode_dev(param->dev));
if (!md)
return NULL;

hc = dm_get_mdptr(md);
if (!hc) {
dm_put(md);
} else if (param->dev) {
hc = __get_dev_cell(param->dev);
if (!hc)
return NULL;
} else
return NULL;
}

fill_params:
/*
* Sneakily write in both the name and the uuid
* while we have the cell.
Expand Down

0 comments on commit ba2e19b

Please sign in to comment.