diff options
author | Tejun Heo <tj@kernel.org> | 2013-02-27 20:04:26 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-02-27 22:10:17 -0500 |
commit | c9d76be696bbb76ba1081d2b0fc0086f449788da (patch) | |
tree | 67040374b1c276b0be5b2c5373e4af74f6e2f08d /drivers/md/dm.c | |
parent | 80f22b4430cd5c108a4676803439ecb0c5cfeca1 (diff) |
dm: convert to idr_alloc()
Convert to the much saner new idr interface.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Alasdair Kergon <agk@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/md/dm.c')
-rw-r--r-- | drivers/md/dm.c | 54 |
1 files changed, 15 insertions, 39 deletions
diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 9ffa7467d270..e67a4be0080d 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c | |||
@@ -1755,62 +1755,38 @@ static void free_minor(int minor) | |||
1755 | */ | 1755 | */ |
1756 | static int specific_minor(int minor) | 1756 | static int specific_minor(int minor) |
1757 | { | 1757 | { |
1758 | int r, m; | 1758 | int r; |
1759 | 1759 | ||
1760 | if (minor >= (1 << MINORBITS)) | 1760 | if (minor >= (1 << MINORBITS)) |
1761 | return -EINVAL; | 1761 | return -EINVAL; |
1762 | 1762 | ||
1763 | r = idr_pre_get(&_minor_idr, GFP_KERNEL); | 1763 | idr_preload(GFP_KERNEL); |
1764 | if (!r) | ||
1765 | return -ENOMEM; | ||
1766 | |||
1767 | spin_lock(&_minor_lock); | 1764 | spin_lock(&_minor_lock); |
1768 | 1765 | ||
1769 | if (idr_find(&_minor_idr, minor)) { | 1766 | r = idr_alloc(&_minor_idr, MINOR_ALLOCED, minor, minor + 1, GFP_NOWAIT); |
1770 | r = -EBUSY; | ||
1771 | goto out; | ||
1772 | } | ||
1773 | |||
1774 | r = idr_get_new_above(&_minor_idr, MINOR_ALLOCED, minor, &m); | ||
1775 | if (r) | ||
1776 | goto out; | ||
1777 | 1767 | ||
1778 | if (m != minor) { | ||
1779 | idr_remove(&_minor_idr, m); | ||
1780 | r = -EBUSY; | ||
1781 | goto out; | ||
1782 | } | ||
1783 | |||
1784 | out: | ||
1785 | spin_unlock(&_minor_lock); | 1768 | spin_unlock(&_minor_lock); |
1786 | return r; | 1769 | idr_preload_end(); |
1770 | if (r < 0) | ||
1771 | return r == -ENOSPC ? -EBUSY : r; | ||
1772 | return 0; | ||
1787 | } | 1773 | } |
1788 | 1774 | ||
1789 | static int next_free_minor(int *minor) | 1775 | static int next_free_minor(int *minor) |
1790 | { | 1776 | { |
1791 | int r, m; | 1777 | int r; |
1792 | |||
1793 | r = idr_pre_get(&_minor_idr, GFP_KERNEL); | ||
1794 | if (!r) | ||
1795 | return -ENOMEM; | ||
1796 | 1778 | ||
1779 | idr_preload(GFP_KERNEL); | ||
1797 | spin_lock(&_minor_lock); | 1780 | spin_lock(&_minor_lock); |
1798 | 1781 | ||
1799 | r = idr_get_new(&_minor_idr, MINOR_ALLOCED, &m); | 1782 | r = idr_alloc(&_minor_idr, MINOR_ALLOCED, 0, 1 << MINORBITS, GFP_NOWAIT); |
1800 | if (r) | ||
1801 | goto out; | ||
1802 | |||
1803 | if (m >= (1 << MINORBITS)) { | ||
1804 | idr_remove(&_minor_idr, m); | ||
1805 | r = -ENOSPC; | ||
1806 | goto out; | ||
1807 | } | ||
1808 | |||
1809 | *minor = m; | ||
1810 | 1783 | ||
1811 | out: | ||
1812 | spin_unlock(&_minor_lock); | 1784 | spin_unlock(&_minor_lock); |
1813 | return r; | 1785 | idr_preload_end(); |
1786 | if (r < 0) | ||
1787 | return r; | ||
1788 | *minor = r; | ||
1789 | return 0; | ||
1814 | } | 1790 | } |
1815 | 1791 | ||
1816 | static const struct block_device_operations dm_blk_dops; | 1792 | static const struct block_device_operations dm_blk_dops; |