[PATCH 04/29] dax: simplify the dax_device <-> gendisk association
Replace the dax_host_hash with an xarray indexed by the pointer value of the gendisk, and require explicitly calls from the block drivers that want to associate their gendisk with a dax_device. Signed-off-by: Christoph Hellwig Acked-by: Mike Snitzer --- drivers/dax/bus.c| 6 +- drivers/dax/super.c | 109 +-- drivers/md/dm.c | 6 +- drivers/nvdimm/pmem.c| 10 +++- drivers/s390/block/dcssblk.c | 11 +++- fs/fuse/virtio_fs.c | 2 +- include/linux/dax.h | 19 -- 7 files changed, 66 insertions(+), 97 deletions(-) diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c index 6cc4da4c713d9..bd7af2f7c5b0a 100644 --- a/drivers/dax/bus.c +++ b/drivers/dax/bus.c @@ -1323,10 +1323,10 @@ struct dev_dax *devm_create_dev_dax(struct dev_dax_data *data) } /* -* No 'host' or dax_operations since there is no access to this -* device outside of mmap of the resulting character device. +* No dax_operations since there is no access to this device outside of +* mmap of the resulting character device. */ - dax_dev = alloc_dax(dev_dax, NULL, NULL, DAXDEV_F_SYNC); + dax_dev = alloc_dax(dev_dax, NULL, DAXDEV_F_SYNC); if (IS_ERR(dax_dev)) { rc = PTR_ERR(dax_dev); goto err_alloc_dax; diff --git a/drivers/dax/super.c b/drivers/dax/super.c index e20d0cef10a18..bf77c3da5d56d 100644 --- a/drivers/dax/super.c +++ b/drivers/dax/super.c @@ -7,10 +7,8 @@ #include #include #include -#include #include #include -#include #include #include #include @@ -21,15 +19,12 @@ * struct dax_device - anchor object for dax services * @inode: core vfs * @cdev: optional character interface for "device dax" - * @host: optional name for lookups where the device path is not available * @private: dax driver private data * @flags: state and boolean properties */ struct dax_device { - struct hlist_node list; struct inode inode; struct cdev cdev; - const char *host; void *private; unsigned long flags; const struct dax_operations *ops; @@ -42,10 +37,6 @@ static DEFINE_IDA(dax_minor_ida); static struct kmem_cache *dax_cache __read_mostly; static struct super_block *dax_superblock __read_mostly; -#define DAX_HASH_SIZE (PAGE_SIZE / sizeof(struct hlist_head)) -static struct hlist_head dax_host_list[DAX_HASH_SIZE]; -static DEFINE_SPINLOCK(dax_host_lock); - int dax_read_lock(void) { return srcu_read_lock(_srcu); @@ -58,13 +49,22 @@ void dax_read_unlock(int id) } EXPORT_SYMBOL_GPL(dax_read_unlock); -static int dax_host_hash(const char *host) +#if defined(CONFIG_BLOCK) && defined(CONFIG_FS_DAX) +#include + +static DEFINE_XARRAY(dax_hosts); + +int dax_add_host(struct dax_device *dax_dev, struct gendisk *disk) { - return hashlen_hash(hashlen_string("DAX", host)) % DAX_HASH_SIZE; + return xa_insert(_hosts, (unsigned long)disk, dax_dev, GFP_KERNEL); } +EXPORT_SYMBOL_GPL(dax_add_host); -#if defined(CONFIG_BLOCK) && defined(CONFIG_FS_DAX) -#include +void dax_remove_host(struct gendisk *disk) +{ + xa_erase(_hosts, (unsigned long)disk); +} +EXPORT_SYMBOL_GPL(dax_remove_host); int bdev_dax_pgoff(struct block_device *bdev, sector_t sector, size_t size, pgoff_t *pgoff) @@ -81,41 +81,24 @@ int bdev_dax_pgoff(struct block_device *bdev, sector_t sector, size_t size, EXPORT_SYMBOL(bdev_dax_pgoff); /** - * dax_get_by_host() - temporary lookup mechanism for filesystem-dax - * @host: alternate name for the device registered by a dax driver + * fs_dax_get_by_bdev() - temporary lookup mechanism for filesystem-dax + * @bdev: block device to find a dax_device for */ -static struct dax_device *dax_get_by_host(const char *host) +struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev) { - struct dax_device *dax_dev, *found = NULL; - int hash, id; + struct dax_device *dax_dev; + int id; - if (!host) + if (!blk_queue_dax(bdev->bd_disk->queue)) return NULL; - hash = dax_host_hash(host); - id = dax_read_lock(); - spin_lock(_host_lock); - hlist_for_each_entry(dax_dev, _host_list[hash], list) { - if (!dax_alive(dax_dev) - || strcmp(host, dax_dev->host) != 0) - continue; - - if (igrab(_dev->inode)) - found = dax_dev; - break; - } - spin_unlock(_host_lock); + dax_dev = xa_load(_hosts, (unsigned long)bdev->bd_disk); + if (!dax_dev || !dax_alive(dax_dev) || !igrab(_dev->inode)) + dax_dev = NULL; dax_read_unlock(id); - return found; -} - -struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev) -{ - if (!blk_queue_dax(bdev->bd_disk->queue)) - return NULL; -
Re: [PATCH 04/29] dax: simplify the dax_device <-> gendisk association
On Mon, Nov 22, 2021 at 9:58 PM Christoph Hellwig wrote: > > On Mon, Nov 22, 2021 at 07:33:06PM -0800, Dan Williams wrote: > > Is it time to add a "DAX" symbol namespace? > > What would be the benefit? Just the small benefit of identifying DAX core users with a common grep line, and to indicate that DAX exports are more intertwined than standalone exports, but yeah those are minor. ___ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH 04/29] dax: simplify the dax_device <-> gendisk association
On Mon, Nov 22, 2021 at 07:33:06PM -0800, Dan Williams wrote: > Is it time to add a "DAX" symbol namespace? What would be the benefit? ___ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH 04/29] dax: simplify the dax_device <-> gendisk association
On Tue, Nov 9, 2021 at 12:33 AM Christoph Hellwig wrote: > > Replace the dax_host_hash with an xarray indexed by the pointer value > of the gendisk, and require explicitly calls from the block drivers that > want to associate their gendisk with a dax_device. > > Signed-off-by: Christoph Hellwig > Acked-by: Mike Snitzer > --- > drivers/dax/bus.c| 6 +- > drivers/dax/super.c | 106 +-- > drivers/md/dm.c | 6 +- > drivers/nvdimm/pmem.c| 8 ++- > drivers/s390/block/dcssblk.c | 11 +++- > fs/fuse/virtio_fs.c | 2 +- > include/linux/dax.h | 19 +-- > 7 files changed, 62 insertions(+), 96 deletions(-) > > diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c > index 6cc4da4c713d9..bd7af2f7c5b0a 100644 > --- a/drivers/dax/bus.c > +++ b/drivers/dax/bus.c > @@ -1323,10 +1323,10 @@ struct dev_dax *devm_create_dev_dax(struct > dev_dax_data *data) > } > > /* > -* No 'host' or dax_operations since there is no access to this > -* device outside of mmap of the resulting character device. > +* No dax_operations since there is no access to this device outside > of > +* mmap of the resulting character device. > */ > - dax_dev = alloc_dax(dev_dax, NULL, NULL, DAXDEV_F_SYNC); > + dax_dev = alloc_dax(dev_dax, NULL, DAXDEV_F_SYNC); > if (IS_ERR(dax_dev)) { > rc = PTR_ERR(dax_dev); > goto err_alloc_dax; > diff --git a/drivers/dax/super.c b/drivers/dax/super.c > index e20d0cef10a18..9383c11b21853 100644 > --- a/drivers/dax/super.c > +++ b/drivers/dax/super.c > @@ -7,10 +7,8 @@ > #include > #include > #include > -#include > #include > #include > -#include > #include > #include > #include > @@ -26,10 +24,8 @@ > * @flags: state and boolean properties > */ > struct dax_device { > - struct hlist_node list; > struct inode inode; > struct cdev cdev; > - const char *host; > void *private; > unsigned long flags; > const struct dax_operations *ops; > @@ -42,10 +38,6 @@ static DEFINE_IDA(dax_minor_ida); > static struct kmem_cache *dax_cache __read_mostly; > static struct super_block *dax_superblock __read_mostly; > > -#define DAX_HASH_SIZE (PAGE_SIZE / sizeof(struct hlist_head)) > -static struct hlist_head dax_host_list[DAX_HASH_SIZE]; > -static DEFINE_SPINLOCK(dax_host_lock); > - > int dax_read_lock(void) > { > return srcu_read_lock(_srcu); > @@ -58,13 +50,22 @@ void dax_read_unlock(int id) > } > EXPORT_SYMBOL_GPL(dax_read_unlock); > > -static int dax_host_hash(const char *host) > +#if defined(CONFIG_BLOCK) && defined(CONFIG_FS_DAX) > +#include > + > +static DEFINE_XARRAY(dax_hosts); > + > +int dax_add_host(struct dax_device *dax_dev, struct gendisk *disk) > { > - return hashlen_hash(hashlen_string("DAX", host)) % DAX_HASH_SIZE; > + return xa_insert(_hosts, (unsigned long)disk, dax_dev, > GFP_KERNEL); > } > +EXPORT_SYMBOL_GPL(dax_add_host); Is it time to add a "DAX" symbol namespace? > > -#if defined(CONFIG_BLOCK) && defined(CONFIG_FS_DAX) > -#include > +void dax_remove_host(struct gendisk *disk) > +{ > + xa_erase(_hosts, (unsigned long)disk); > +} > +EXPORT_SYMBOL_GPL(dax_remove_host); > > int bdev_dax_pgoff(struct block_device *bdev, sector_t sector, size_t size, > pgoff_t *pgoff) > @@ -82,40 +83,23 @@ EXPORT_SYMBOL(bdev_dax_pgoff); > > /** > * dax_get_by_host() - temporary lookup mechanism for filesystem-dax > - * @host: alternate name for the device registered by a dax driver > + * @bdev: block device to find a dax_device for > */ > -static struct dax_device *dax_get_by_host(const char *host) > +struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev) > { > - struct dax_device *dax_dev, *found = NULL; > - int hash, id; > + struct dax_device *dax_dev; > + int id; > > - if (!host) > + if (!blk_queue_dax(bdev->bd_disk->queue)) > return NULL; > > - hash = dax_host_hash(host); > - > id = dax_read_lock(); > - spin_lock(_host_lock); > - hlist_for_each_entry(dax_dev, _host_list[hash], list) { > - if (!dax_alive(dax_dev) > - || strcmp(host, dax_dev->host) != 0) > - continue; > - > - if (igrab(_dev->inode)) > - found = dax_dev; > - break; > - } > - spin_unlock(_host_lock); > + dax_dev = xa_load(_hosts, (unsigned long)bdev->bd_disk); > + if (!dax_dev || !dax_alive(dax_dev) || !igrab(_dev->inode)) > + dax_dev = NULL; > dax_read_unlock(id); > > - return found; > -} > - > -struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev) > -{ > - if (!blk_queue_dax(bdev->bd_disk->queue)) > - return NULL; > - return
[PATCH 04/29] dax: simplify the dax_device <-> gendisk association
Replace the dax_host_hash with an xarray indexed by the pointer value of the gendisk, and require explicitly calls from the block drivers that want to associate their gendisk with a dax_device. Signed-off-by: Christoph Hellwig Acked-by: Mike Snitzer --- drivers/dax/bus.c| 6 +- drivers/dax/super.c | 106 +-- drivers/md/dm.c | 6 +- drivers/nvdimm/pmem.c| 8 ++- drivers/s390/block/dcssblk.c | 11 +++- fs/fuse/virtio_fs.c | 2 +- include/linux/dax.h | 19 +-- 7 files changed, 62 insertions(+), 96 deletions(-) diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c index 6cc4da4c713d9..bd7af2f7c5b0a 100644 --- a/drivers/dax/bus.c +++ b/drivers/dax/bus.c @@ -1323,10 +1323,10 @@ struct dev_dax *devm_create_dev_dax(struct dev_dax_data *data) } /* -* No 'host' or dax_operations since there is no access to this -* device outside of mmap of the resulting character device. +* No dax_operations since there is no access to this device outside of +* mmap of the resulting character device. */ - dax_dev = alloc_dax(dev_dax, NULL, NULL, DAXDEV_F_SYNC); + dax_dev = alloc_dax(dev_dax, NULL, DAXDEV_F_SYNC); if (IS_ERR(dax_dev)) { rc = PTR_ERR(dax_dev); goto err_alloc_dax; diff --git a/drivers/dax/super.c b/drivers/dax/super.c index e20d0cef10a18..9383c11b21853 100644 --- a/drivers/dax/super.c +++ b/drivers/dax/super.c @@ -7,10 +7,8 @@ #include #include #include -#include #include #include -#include #include #include #include @@ -26,10 +24,8 @@ * @flags: state and boolean properties */ struct dax_device { - struct hlist_node list; struct inode inode; struct cdev cdev; - const char *host; void *private; unsigned long flags; const struct dax_operations *ops; @@ -42,10 +38,6 @@ static DEFINE_IDA(dax_minor_ida); static struct kmem_cache *dax_cache __read_mostly; static struct super_block *dax_superblock __read_mostly; -#define DAX_HASH_SIZE (PAGE_SIZE / sizeof(struct hlist_head)) -static struct hlist_head dax_host_list[DAX_HASH_SIZE]; -static DEFINE_SPINLOCK(dax_host_lock); - int dax_read_lock(void) { return srcu_read_lock(_srcu); @@ -58,13 +50,22 @@ void dax_read_unlock(int id) } EXPORT_SYMBOL_GPL(dax_read_unlock); -static int dax_host_hash(const char *host) +#if defined(CONFIG_BLOCK) && defined(CONFIG_FS_DAX) +#include + +static DEFINE_XARRAY(dax_hosts); + +int dax_add_host(struct dax_device *dax_dev, struct gendisk *disk) { - return hashlen_hash(hashlen_string("DAX", host)) % DAX_HASH_SIZE; + return xa_insert(_hosts, (unsigned long)disk, dax_dev, GFP_KERNEL); } +EXPORT_SYMBOL_GPL(dax_add_host); -#if defined(CONFIG_BLOCK) && defined(CONFIG_FS_DAX) -#include +void dax_remove_host(struct gendisk *disk) +{ + xa_erase(_hosts, (unsigned long)disk); +} +EXPORT_SYMBOL_GPL(dax_remove_host); int bdev_dax_pgoff(struct block_device *bdev, sector_t sector, size_t size, pgoff_t *pgoff) @@ -82,40 +83,23 @@ EXPORT_SYMBOL(bdev_dax_pgoff); /** * dax_get_by_host() - temporary lookup mechanism for filesystem-dax - * @host: alternate name for the device registered by a dax driver + * @bdev: block device to find a dax_device for */ -static struct dax_device *dax_get_by_host(const char *host) +struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev) { - struct dax_device *dax_dev, *found = NULL; - int hash, id; + struct dax_device *dax_dev; + int id; - if (!host) + if (!blk_queue_dax(bdev->bd_disk->queue)) return NULL; - hash = dax_host_hash(host); - id = dax_read_lock(); - spin_lock(_host_lock); - hlist_for_each_entry(dax_dev, _host_list[hash], list) { - if (!dax_alive(dax_dev) - || strcmp(host, dax_dev->host) != 0) - continue; - - if (igrab(_dev->inode)) - found = dax_dev; - break; - } - spin_unlock(_host_lock); + dax_dev = xa_load(_hosts, (unsigned long)bdev->bd_disk); + if (!dax_dev || !dax_alive(dax_dev) || !igrab(_dev->inode)) + dax_dev = NULL; dax_read_unlock(id); - return found; -} - -struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev) -{ - if (!blk_queue_dax(bdev->bd_disk->queue)) - return NULL; - return dax_get_by_host(bdev->bd_disk->disk_name); + return dax_dev; } EXPORT_SYMBOL_GPL(fs_dax_get_by_bdev); @@ -361,12 +345,7 @@ void kill_dax(struct dax_device *dax_dev) return; clear_bit(DAXDEV_ALIVE, _dev->flags); - synchronize_srcu(_srcu); - - spin_lock(_host_lock); - hlist_del_init(_dev->list); - spin_unlock(_host_lock); }