提交 2b06cfff 编写于 作者: A Alasdair G Kergon 提交者: Linus Torvalds

[PATCH] dm: consolidate creation functions

Merge dm_create() and dm_create_with_minor() by introducing the special value
DM_ANY_MINOR to request the allocation of the next available minor number.
Signed-off-by: NAlasdair G Kergon <agk@redhat.com>
Signed-off-by: NAndrew Morton <akpm@osdl.org>
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 814d6862
/* /*
* Copyright (C) 2001, 2002 Sistina Software (UK) Limited. * Copyright (C) 2001, 2002 Sistina Software (UK) Limited.
* Copyright (C) 2004 - 2005 Red Hat, Inc. All rights reserved. * Copyright (C) 2004 - 2006 Red Hat, Inc. All rights reserved.
* *
* This file is released under the GPL. * This file is released under the GPL.
*/ */
...@@ -578,7 +578,7 @@ static int __dev_status(struct mapped_device *md, struct dm_ioctl *param) ...@@ -578,7 +578,7 @@ static int __dev_status(struct mapped_device *md, struct dm_ioctl *param)
static int dev_create(struct dm_ioctl *param, size_t param_size) static int dev_create(struct dm_ioctl *param, size_t param_size)
{ {
int r; int r, m = DM_ANY_MINOR;
struct mapped_device *md; struct mapped_device *md;
r = check_name(param->name); r = check_name(param->name);
...@@ -586,10 +586,9 @@ static int dev_create(struct dm_ioctl *param, size_t param_size) ...@@ -586,10 +586,9 @@ static int dev_create(struct dm_ioctl *param, size_t param_size)
return r; return r;
if (param->flags & DM_PERSISTENT_DEV_FLAG) if (param->flags & DM_PERSISTENT_DEV_FLAG)
r = dm_create_with_minor(MINOR(huge_decode_dev(param->dev)), &md); m = MINOR(huge_decode_dev(param->dev));
else
r = dm_create(&md);
r = dm_create(m, &md);
if (r) if (r)
return r; return r;
......
/* /*
* Copyright (C) 2001, 2002 Sistina Software (UK) Limited. * Copyright (C) 2001, 2002 Sistina Software (UK) Limited.
* Copyright (C) 2004 Red Hat, Inc. All rights reserved. * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
* *
* This file is released under the GPL. * This file is released under the GPL.
*/ */
...@@ -764,7 +764,7 @@ static int dm_any_congested(void *congested_data, int bdi_bits) ...@@ -764,7 +764,7 @@ static int dm_any_congested(void *congested_data, int bdi_bits)
*---------------------------------------------------------------*/ *---------------------------------------------------------------*/
static DEFINE_IDR(_minor_idr); static DEFINE_IDR(_minor_idr);
static void free_minor(unsigned int minor) static void free_minor(int minor)
{ {
spin_lock(&_minor_lock); spin_lock(&_minor_lock);
idr_remove(&_minor_idr, minor); idr_remove(&_minor_idr, minor);
...@@ -774,7 +774,7 @@ static void free_minor(unsigned int minor) ...@@ -774,7 +774,7 @@ static void free_minor(unsigned int minor)
/* /*
* See if the device with a specific minor # is free. * See if the device with a specific minor # is free.
*/ */
static int specific_minor(struct mapped_device *md, unsigned int minor) static int specific_minor(struct mapped_device *md, int minor)
{ {
int r, m; int r, m;
...@@ -807,10 +807,9 @@ static int specific_minor(struct mapped_device *md, unsigned int minor) ...@@ -807,10 +807,9 @@ static int specific_minor(struct mapped_device *md, unsigned int minor)
return r; return r;
} }
static int next_free_minor(struct mapped_device *md, unsigned int *minor) static int next_free_minor(struct mapped_device *md, int *minor)
{ {
int r; int r, m;
unsigned int m;
r = idr_pre_get(&_minor_idr, GFP_KERNEL); r = idr_pre_get(&_minor_idr, GFP_KERNEL);
if (!r) if (!r)
...@@ -841,7 +840,7 @@ static struct block_device_operations dm_blk_dops; ...@@ -841,7 +840,7 @@ static struct block_device_operations dm_blk_dops;
/* /*
* Allocate and initialise a blank device with a given minor. * Allocate and initialise a blank device with a given minor.
*/ */
static struct mapped_device *alloc_dev(unsigned int minor, int persistent) static struct mapped_device *alloc_dev(int minor)
{ {
int r; int r;
struct mapped_device *md = kmalloc(sizeof(*md), GFP_KERNEL); struct mapped_device *md = kmalloc(sizeof(*md), GFP_KERNEL);
...@@ -856,7 +855,10 @@ static struct mapped_device *alloc_dev(unsigned int minor, int persistent) ...@@ -856,7 +855,10 @@ static struct mapped_device *alloc_dev(unsigned int minor, int persistent)
goto bad0; goto bad0;
/* get a minor number for the dev */ /* get a minor number for the dev */
r = persistent ? specific_minor(md, minor) : next_free_minor(md, &minor); if (minor == DM_ANY_MINOR)
r = next_free_minor(md, &minor);
else
r = specific_minor(md, minor);
if (r < 0) if (r < 0)
goto bad1; goto bad1;
...@@ -929,7 +931,7 @@ static struct mapped_device *alloc_dev(unsigned int minor, int persistent) ...@@ -929,7 +931,7 @@ static struct mapped_device *alloc_dev(unsigned int minor, int persistent)
static void free_dev(struct mapped_device *md) static void free_dev(struct mapped_device *md)
{ {
unsigned int minor = md->disk->first_minor; int minor = md->disk->first_minor;
if (md->suspended_bdev) { if (md->suspended_bdev) {
thaw_bdev(md->suspended_bdev, NULL); thaw_bdev(md->suspended_bdev, NULL);
...@@ -1015,12 +1017,11 @@ static void __unbind(struct mapped_device *md) ...@@ -1015,12 +1017,11 @@ static void __unbind(struct mapped_device *md)
/* /*
* Constructor for a new device. * Constructor for a new device.
*/ */
static int create_aux(unsigned int minor, int persistent, int dm_create(int minor, struct mapped_device **result)
struct mapped_device **result)
{ {
struct mapped_device *md; struct mapped_device *md;
md = alloc_dev(minor, persistent); md = alloc_dev(minor);
if (!md) if (!md)
return -ENXIO; return -ENXIO;
...@@ -1028,16 +1029,6 @@ static int create_aux(unsigned int minor, int persistent, ...@@ -1028,16 +1029,6 @@ static int create_aux(unsigned int minor, int persistent,
return 0; return 0;
} }
int dm_create(struct mapped_device **result)
{
return create_aux(0, 0, result);
}
int dm_create_with_minor(unsigned int minor, struct mapped_device **result)
{
return create_aux(minor, 1, result);
}
static struct mapped_device *dm_find_md(dev_t dev) static struct mapped_device *dm_find_md(dev_t dev)
{ {
struct mapped_device *md; struct mapped_device *md;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Internal header file for device mapper * Internal header file for device mapper
* *
* Copyright (C) 2001, 2002 Sistina Software * Copyright (C) 2001, 2002 Sistina Software
* Copyright (C) 2004 Red Hat, Inc. All rights reserved. * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
* *
* This file is released under the LGPL. * This file is released under the LGPL.
*/ */
...@@ -45,16 +45,21 @@ struct mapped_device; ...@@ -45,16 +45,21 @@ struct mapped_device;
* Functions for manipulating a struct mapped_device. * Functions for manipulating a struct mapped_device.
* Drop the reference with dm_put when you finish with the object. * Drop the reference with dm_put when you finish with the object.
*---------------------------------------------------------------*/ *---------------------------------------------------------------*/
int dm_create(struct mapped_device **md);
int dm_create_with_minor(unsigned int minor, struct mapped_device **md); /*
* DM_ANY_MINOR allocates any available minor number.
*/
#define DM_ANY_MINOR (-1)
int dm_create(int minor, struct mapped_device **md);
void dm_set_mdptr(struct mapped_device *md, void *ptr); void dm_set_mdptr(struct mapped_device *md, void *ptr);
void *dm_get_mdptr(struct mapped_device *md); void *dm_get_mdptr(struct mapped_device *md);
struct mapped_device *dm_get_md(dev_t dev);
/* /*
* Reference counting for md. * Reference counting for md.
*/ */
void dm_get(struct mapped_device *md); void dm_get(struct mapped_device *md);
struct mapped_device *dm_get_md(dev_t dev);
void dm_put(struct mapped_device *md); void dm_put(struct mapped_device *md);
/* /*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册