Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[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>

authored by

Alasdair G Kergon and committed by
Linus Torvalds
2b06cfff 814d6862

+26 -31
+4 -5
drivers/md/dm-ioctl.c
··· 1 1 /* 2 2 * Copyright (C) 2001, 2002 Sistina Software (UK) Limited. 3 - * Copyright (C) 2004 - 2005 Red Hat, Inc. All rights reserved. 3 + * Copyright (C) 2004 - 2006 Red Hat, Inc. All rights reserved. 4 4 * 5 5 * This file is released under the GPL. 6 6 */ ··· 578 578 579 579 static int dev_create(struct dm_ioctl *param, size_t param_size) 580 580 { 581 - int r; 581 + int r, m = DM_ANY_MINOR; 582 582 struct mapped_device *md; 583 583 584 584 r = check_name(param->name); ··· 586 586 return r; 587 587 588 588 if (param->flags & DM_PERSISTENT_DEV_FLAG) 589 - r = dm_create_with_minor(MINOR(huge_decode_dev(param->dev)), &md); 590 - else 591 - r = dm_create(&md); 589 + m = MINOR(huge_decode_dev(param->dev)); 592 590 591 + r = dm_create(m, &md); 593 592 if (r) 594 593 return r; 595 594
+13 -22
drivers/md/dm.c
··· 1 1 /* 2 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 5 * This file is released under the GPL. 6 6 */ ··· 764 764 *---------------------------------------------------------------*/ 765 765 static DEFINE_IDR(_minor_idr); 766 766 767 - static void free_minor(unsigned int minor) 767 + static void free_minor(int minor) 768 768 { 769 769 spin_lock(&_minor_lock); 770 770 idr_remove(&_minor_idr, minor); ··· 774 774 /* 775 775 * See if the device with a specific minor # is free. 776 776 */ 777 - static int specific_minor(struct mapped_device *md, unsigned int minor) 777 + static int specific_minor(struct mapped_device *md, int minor) 778 778 { 779 779 int r, m; 780 780 ··· 807 807 return r; 808 808 } 809 809 810 - static int next_free_minor(struct mapped_device *md, unsigned int *minor) 810 + static int next_free_minor(struct mapped_device *md, int *minor) 811 811 { 812 - int r; 813 - unsigned int m; 812 + int r, m; 814 813 815 814 r = idr_pre_get(&_minor_idr, GFP_KERNEL); 816 815 if (!r) ··· 840 841 /* 841 842 * Allocate and initialise a blank device with a given minor. 842 843 */ 843 - static struct mapped_device *alloc_dev(unsigned int minor, int persistent) 844 + static struct mapped_device *alloc_dev(int minor) 844 845 { 845 846 int r; 846 847 struct mapped_device *md = kmalloc(sizeof(*md), GFP_KERNEL); ··· 855 856 goto bad0; 856 857 857 858 /* get a minor number for the dev */ 858 - r = persistent ? specific_minor(md, minor) : next_free_minor(md, &minor); 859 + if (minor == DM_ANY_MINOR) 860 + r = next_free_minor(md, &minor); 861 + else 862 + r = specific_minor(md, minor); 859 863 if (r < 0) 860 864 goto bad1; 861 865 ··· 931 929 932 930 static void free_dev(struct mapped_device *md) 933 931 { 934 - unsigned int minor = md->disk->first_minor; 932 + int minor = md->disk->first_minor; 935 933 936 934 if (md->suspended_bdev) { 937 935 thaw_bdev(md->suspended_bdev, NULL); ··· 1017 1015 /* 1018 1016 * Constructor for a new device. 1019 1017 */ 1020 - static int create_aux(unsigned int minor, int persistent, 1021 - struct mapped_device **result) 1018 + int dm_create(int minor, struct mapped_device **result) 1022 1019 { 1023 1020 struct mapped_device *md; 1024 1021 1025 - md = alloc_dev(minor, persistent); 1022 + md = alloc_dev(minor); 1026 1023 if (!md) 1027 1024 return -ENXIO; 1028 1025 1029 1026 *result = md; 1030 1027 return 0; 1031 - } 1032 - 1033 - int dm_create(struct mapped_device **result) 1034 - { 1035 - return create_aux(0, 0, result); 1036 - } 1037 - 1038 - int dm_create_with_minor(unsigned int minor, struct mapped_device **result) 1039 - { 1040 - return create_aux(minor, 1, result); 1041 1028 } 1042 1029 1043 1030 static struct mapped_device *dm_find_md(dev_t dev)
+9 -4
drivers/md/dm.h
··· 2 2 * Internal header file for device mapper 3 3 * 4 4 * Copyright (C) 2001, 2002 Sistina Software 5 - * Copyright (C) 2004 Red Hat, Inc. All rights reserved. 5 + * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. 6 6 * 7 7 * This file is released under the LGPL. 8 8 */ ··· 45 45 * Functions for manipulating a struct mapped_device. 46 46 * Drop the reference with dm_put when you finish with the object. 47 47 *---------------------------------------------------------------*/ 48 - int dm_create(struct mapped_device **md); 49 - int dm_create_with_minor(unsigned int minor, struct mapped_device **md); 48 + 49 + /* 50 + * DM_ANY_MINOR allocates any available minor number. 51 + */ 52 + #define DM_ANY_MINOR (-1) 53 + int dm_create(int minor, struct mapped_device **md); 54 + 50 55 void dm_set_mdptr(struct mapped_device *md, void *ptr); 51 56 void *dm_get_mdptr(struct mapped_device *md); 52 - struct mapped_device *dm_get_md(dev_t dev); 53 57 54 58 /* 55 59 * Reference counting for md. 56 60 */ 57 61 void dm_get(struct mapped_device *md); 62 + struct mapped_device *dm_get_md(dev_t dev); 58 63 void dm_put(struct mapped_device *md); 59 64 60 65 /*