aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/dm.c
diff options
context:
space:
mode:
authorAlasdair G Kergon <agk@redhat.com>2006-06-26 03:27:32 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-06-26 12:58:36 -0400
commit2b06cfff12f0f87c4bc4d4c4dd76997e72c360ba (patch)
tree68e9085593ef64b78a60daec94898e620bf716c3 /drivers/md/dm.c
parent814d68629b40e863997fa0eea459be4cc99a06cc (diff)
[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: Alasdair G Kergon <agk@redhat.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/md/dm.c')
-rw-r--r--drivers/md/dm.c35
1 files changed, 13 insertions, 22 deletions
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index dfd037858902..59bf797de9a5 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (C) 2001, 2002 Sistina Software (UK) Limited. 2 * Copyright (C) 2001, 2002 Sistina Software (UK) Limited.
3 * Copyright (C) 2004 Red Hat, Inc. All rights reserved. 3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
4 * 4 *
5 * This file is released under the GPL. 5 * This file is released under the GPL.
6 */ 6 */
@@ -764,7 +764,7 @@ static int dm_any_congested(void *congested_data, int bdi_bits)
764 *---------------------------------------------------------------*/ 764 *---------------------------------------------------------------*/
765static DEFINE_IDR(_minor_idr); 765static DEFINE_IDR(_minor_idr);
766 766
767static void free_minor(unsigned int minor) 767static void free_minor(int minor)
768{ 768{
769 spin_lock(&_minor_lock); 769 spin_lock(&_minor_lock);
770 idr_remove(&_minor_idr, minor); 770 idr_remove(&_minor_idr, minor);
@@ -774,7 +774,7 @@ static void free_minor(unsigned int minor)
774/* 774/*
775 * See if the device with a specific minor # is free. 775 * See if the device with a specific minor # is free.
776 */ 776 */
777static int specific_minor(struct mapped_device *md, unsigned int minor) 777static int specific_minor(struct mapped_device *md, int minor)
778{ 778{
779 int r, m; 779 int r, m;
780 780
@@ -807,10 +807,9 @@ out:
807 return r; 807 return r;
808} 808}
809 809
810static int next_free_minor(struct mapped_device *md, unsigned int *minor) 810static int next_free_minor(struct mapped_device *md, int *minor)
811{ 811{
812 int r; 812 int r, m;
813 unsigned int m;
814 813
815 r = idr_pre_get(&_minor_idr, GFP_KERNEL); 814 r = idr_pre_get(&_minor_idr, GFP_KERNEL);
816 if (!r) 815 if (!r)
@@ -841,7 +840,7 @@ static struct block_device_operations dm_blk_dops;
841/* 840/*
842 * Allocate and initialise a blank device with a given minor. 841 * Allocate and initialise a blank device with a given minor.
843 */ 842 */
844static struct mapped_device *alloc_dev(unsigned int minor, int persistent) 843static struct mapped_device *alloc_dev(int minor)
845{ 844{
846 int r; 845 int r;
847 struct mapped_device *md = kmalloc(sizeof(*md), GFP_KERNEL); 846 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 goto bad0; 855 goto bad0;
857 856
858 /* get a minor number for the dev */ 857 /* get a minor number for the dev */
859 r = persistent ? specific_minor(md, minor) : next_free_minor(md, &minor); 858 if (minor == DM_ANY_MINOR)
859 r = next_free_minor(md, &minor);
860 else
861 r = specific_minor(md, minor);
860 if (r < 0) 862 if (r < 0)
861 goto bad1; 863 goto bad1;
862 864
@@ -929,7 +931,7 @@ static struct mapped_device *alloc_dev(unsigned int minor, int persistent)
929 931
930static void free_dev(struct mapped_device *md) 932static void free_dev(struct mapped_device *md)
931{ 933{
932 unsigned int minor = md->disk->first_minor; 934 int minor = md->disk->first_minor;
933 935
934 if (md->suspended_bdev) { 936 if (md->suspended_bdev) {
935 thaw_bdev(md->suspended_bdev, NULL); 937 thaw_bdev(md->suspended_bdev, NULL);
@@ -1015,12 +1017,11 @@ static void __unbind(struct mapped_device *md)
1015/* 1017/*
1016 * Constructor for a new device. 1018 * Constructor for a new device.
1017 */ 1019 */
1018static int create_aux(unsigned int minor, int persistent, 1020int dm_create(int minor, struct mapped_device **result)
1019 struct mapped_device **result)
1020{ 1021{
1021 struct mapped_device *md; 1022 struct mapped_device *md;
1022 1023
1023 md = alloc_dev(minor, persistent); 1024 md = alloc_dev(minor);
1024 if (!md) 1025 if (!md)
1025 return -ENXIO; 1026 return -ENXIO;
1026 1027
@@ -1028,16 +1029,6 @@ static int create_aux(unsigned int minor, int persistent,
1028 return 0; 1029 return 0;
1029} 1030}
1030 1031
1031int dm_create(struct mapped_device **result)
1032{
1033 return create_aux(0, 0, result);
1034}
1035
1036int dm_create_with_minor(unsigned int minor, struct mapped_device **result)
1037{
1038 return create_aux(minor, 1, result);
1039}
1040
1041static struct mapped_device *dm_find_md(dev_t dev) 1032static struct mapped_device *dm_find_md(dev_t dev)
1042{ 1033{
1043 struct mapped_device *md; 1034 struct mapped_device *md;