aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/nvme-core.c
diff options
context:
space:
mode:
authorMatthew Wilcox <willy@linux.intel.com>2013-12-09 12:58:46 -0500
committerMatthew Wilcox <matthew.r.wilcox@intel.com>2014-01-27 20:11:29 -0500
commit469071a37afc8a627b6b2ddf29db0a097d864845 (patch)
treeb94dbe764d10b981e995da1dbe01f433b414611d /drivers/block/nvme-core.c
parent4d115420707afcabe77d2535e092356df6664b70 (diff)
NVMe: Dynamically allocate partition numbers
Some users need more than 64 partitions per device. Rather than simply increasing the number of partitions, switch to the dynamic partition allocation scheme. This means that minor numbers are not stable across boots, but since major numbers aren't either, I cannot see this being a significant problem. Tested-by: Matias Bjørling <m@bjorling.me> Signed-off-by: Matthew Wilcox <matthew.r.wilcox@intel.com>
Diffstat (limited to 'drivers/block/nvme-core.c')
-rw-r--r--drivers/block/nvme-core.c36
1 files changed, 3 insertions, 33 deletions
diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
index 1c8a82fbbc37..7b615a063e92 100644
--- a/drivers/block/nvme-core.c
+++ b/drivers/block/nvme-core.c
@@ -46,7 +46,6 @@
46#define NVME_Q_DEPTH 1024 46#define NVME_Q_DEPTH 1024
47#define SQ_SIZE(depth) (depth * sizeof(struct nvme_command)) 47#define SQ_SIZE(depth) (depth * sizeof(struct nvme_command))
48#define CQ_SIZE(depth) (depth * sizeof(struct nvme_completion)) 48#define CQ_SIZE(depth) (depth * sizeof(struct nvme_completion))
49#define NVME_MINORS 64
50#define ADMIN_TIMEOUT (60 * HZ) 49#define ADMIN_TIMEOUT (60 * HZ)
51 50
52static int nvme_major; 51static int nvme_major;
@@ -1780,33 +1779,6 @@ static int nvme_kthread(void *data)
1780 return 0; 1779 return 0;
1781} 1780}
1782 1781
1783static DEFINE_IDA(nvme_index_ida);
1784
1785static int nvme_get_ns_idx(void)
1786{
1787 int index, error;
1788
1789 do {
1790 if (!ida_pre_get(&nvme_index_ida, GFP_KERNEL))
1791 return -1;
1792
1793 spin_lock(&dev_list_lock);
1794 error = ida_get_new(&nvme_index_ida, &index);
1795 spin_unlock(&dev_list_lock);
1796 } while (error == -EAGAIN);
1797
1798 if (error)
1799 index = -1;
1800 return index;
1801}
1802
1803static void nvme_put_ns_idx(int index)
1804{
1805 spin_lock(&dev_list_lock);
1806 ida_remove(&nvme_index_ida, index);
1807 spin_unlock(&dev_list_lock);
1808}
1809
1810static void nvme_config_discard(struct nvme_ns *ns) 1782static void nvme_config_discard(struct nvme_ns *ns)
1811{ 1783{
1812 u32 logical_block_size = queue_logical_block_size(ns->queue); 1784 u32 logical_block_size = queue_logical_block_size(ns->queue);
@@ -1840,7 +1812,7 @@ static struct nvme_ns *nvme_alloc_ns(struct nvme_dev *dev, unsigned nsid,
1840 ns->dev = dev; 1812 ns->dev = dev;
1841 ns->queue->queuedata = ns; 1813 ns->queue->queuedata = ns;
1842 1814
1843 disk = alloc_disk(NVME_MINORS); 1815 disk = alloc_disk(0);
1844 if (!disk) 1816 if (!disk)
1845 goto out_free_queue; 1817 goto out_free_queue;
1846 ns->ns_id = nsid; 1818 ns->ns_id = nsid;
@@ -1853,12 +1825,12 @@ static struct nvme_ns *nvme_alloc_ns(struct nvme_dev *dev, unsigned nsid,
1853 blk_queue_max_hw_sectors(ns->queue, dev->max_hw_sectors); 1825 blk_queue_max_hw_sectors(ns->queue, dev->max_hw_sectors);
1854 1826
1855 disk->major = nvme_major; 1827 disk->major = nvme_major;
1856 disk->minors = NVME_MINORS; 1828 disk->first_minor = 0;
1857 disk->first_minor = NVME_MINORS * nvme_get_ns_idx();
1858 disk->fops = &nvme_fops; 1829 disk->fops = &nvme_fops;
1859 disk->private_data = ns; 1830 disk->private_data = ns;
1860 disk->queue = ns->queue; 1831 disk->queue = ns->queue;
1861 disk->driverfs_dev = &dev->pci_dev->dev; 1832 disk->driverfs_dev = &dev->pci_dev->dev;
1833 disk->flags = GENHD_FL_EXT_DEVT;
1862 sprintf(disk->disk_name, "nvme%dn%d", dev->instance, nsid); 1834 sprintf(disk->disk_name, "nvme%dn%d", dev->instance, nsid);
1863 set_capacity(disk, le64_to_cpup(&id->nsze) << (ns->lba_shift - 9)); 1835 set_capacity(disk, le64_to_cpup(&id->nsze) << (ns->lba_shift - 9));
1864 1836
@@ -1876,9 +1848,7 @@ static struct nvme_ns *nvme_alloc_ns(struct nvme_dev *dev, unsigned nsid,
1876 1848
1877static void nvme_ns_free(struct nvme_ns *ns) 1849static void nvme_ns_free(struct nvme_ns *ns)
1878{ 1850{
1879 int index = ns->disk->first_minor / NVME_MINORS;
1880 put_disk(ns->disk); 1851 put_disk(ns->disk);
1881 nvme_put_ns_idx(index);
1882 blk_cleanup_queue(ns->queue); 1852 blk_cleanup_queue(ns->queue);
1883 kfree(ns); 1853 kfree(ns);
1884} 1854}