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

Configure Feed

Select the types of activity you want to include in your feed.

dax: Add fs_dax_get() func to prepare dax for fs-dax usage

The fs_dax_get() function should be called by fs-dax file systems after
opening a fsdev dax device. This adds holder_operations, which provides
a memory failure callback path and effects exclusivity between callers
of fs_dax_get().

fs_dax_get() is specific to fsdev_dax, so it checks the driver type
(which required touching bus.[ch]). fs_dax_get() fails if fsdev_dax is
not bound to the memory.

This function serves the same role as fs_dax_get_by_bdev(), which dax
file systems call after opening the pmem block device.

This can't be located in fsdev.c because struct dax_device is opaque
there.

This will be called by fs/fuse/famfs.c in a subsequent commit.

Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: John Groves <john@groves.net>
Link: https://patch.msgid.link/0100019d311d8750-75395c22-031b-4d5f-aebe-790dca656b87-000000@email.amazonses.com
Signed-off-by: Ira Weiny <ira.weiny@intel.com>

authored by

John Groves and committed by
Ira Weiny
eec38f5d 700ecbc1

+79 -7
-2
drivers/dax/bus.c
··· 39 39 return add_uevent_var(env, "MODALIAS=" DAX_DEVICE_MODALIAS_FMT, 0); 40 40 } 41 41 42 - #define to_dax_drv(__drv) container_of_const(__drv, struct dax_device_driver, drv) 43 - 44 42 static struct dax_id *__dax_match_id(const struct dax_device_driver *dax_drv, 45 43 const char *dev_name) 46 44 {
+2
drivers/dax/bus.h
··· 42 42 void (*remove)(struct dev_dax *dev); 43 43 }; 44 44 45 + #define to_dax_drv(__drv) container_of_const(__drv, struct dax_device_driver, drv) 46 + 45 47 int __dax_driver_register(struct dax_device_driver *dax_drv, 46 48 struct module *module, const char *mod_name); 47 49 #define dax_driver_register(driver) \
+65 -1
drivers/dax/super.c
··· 14 14 #include <linux/fs.h> 15 15 #include <linux/cacheinfo.h> 16 16 #include "dax-private.h" 17 + #include "bus.h" 17 18 18 19 /** 19 20 * struct dax_device - anchor object for dax services ··· 112 111 } 113 112 EXPORT_SYMBOL_GPL(fs_dax_get_by_bdev); 114 113 114 + #endif /* CONFIG_BLOCK && CONFIG_FS_DAX */ 115 + 116 + #if IS_ENABLED(CONFIG_FS_DAX) 117 + 115 118 void fs_put_dax(struct dax_device *dax_dev, void *holder) 116 119 { 117 120 if (dax_dev && holder && ··· 124 119 put_dax(dax_dev); 125 120 } 126 121 EXPORT_SYMBOL_GPL(fs_put_dax); 127 - #endif /* CONFIG_BLOCK && CONFIG_FS_DAX */ 122 + 123 + /** 124 + * fs_dax_get() - get ownership of a devdax via holder/holder_ops 125 + * 126 + * fs-dax file systems call this function to prepare to use a devdax device for 127 + * fsdax. This is like fs_dax_get_by_bdev(), but the caller already has struct 128 + * dev_dax (and there is no bdev). The holder makes this exclusive. 129 + * 130 + * @dax_dev: dev to be prepared for fs-dax usage 131 + * @holder: filesystem or mapped device inside the dax_device 132 + * @hops: operations for the inner holder 133 + * 134 + * Returns: 0 on success, <0 on failure 135 + */ 136 + int fs_dax_get(struct dax_device *dax_dev, void *holder, 137 + const struct dax_holder_operations *hops) 138 + { 139 + struct dev_dax *dev_dax; 140 + struct dax_device_driver *dax_drv; 141 + int id; 142 + 143 + id = dax_read_lock(); 144 + if (!dax_dev || !dax_alive(dax_dev) || !igrab(&dax_dev->inode)) { 145 + dax_read_unlock(id); 146 + return -ENODEV; 147 + } 148 + dax_read_unlock(id); 149 + 150 + /* Verify the device is bound to fsdev_dax driver */ 151 + dev_dax = dax_get_private(dax_dev); 152 + if (!dev_dax) { 153 + iput(&dax_dev->inode); 154 + return -ENODEV; 155 + } 156 + 157 + device_lock(&dev_dax->dev); 158 + if (!dev_dax->dev.driver) { 159 + device_unlock(&dev_dax->dev); 160 + iput(&dax_dev->inode); 161 + return -ENODEV; 162 + } 163 + dax_drv = to_dax_drv(dev_dax->dev.driver); 164 + if (dax_drv->type != DAXDRV_FSDEV_TYPE) { 165 + device_unlock(&dev_dax->dev); 166 + iput(&dax_dev->inode); 167 + return -EOPNOTSUPP; 168 + } 169 + device_unlock(&dev_dax->dev); 170 + 171 + if (cmpxchg(&dax_dev->holder_data, NULL, holder)) { 172 + iput(&dax_dev->inode); 173 + return -EBUSY; 174 + } 175 + 176 + dax_dev->holder_ops = hops; 177 + 178 + return 0; 179 + } 180 + EXPORT_SYMBOL_GPL(fs_dax_get); 181 + #endif /* CONFIG_FS_DAX */ 128 182 129 183 enum dax_device_flags { 130 184 /* !alive + rcu grace period == no new operations / mappings */
+12 -4
include/linux/dax.h
··· 130 130 void dax_remove_host(struct gendisk *disk); 131 131 struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev, u64 *start_off, 132 132 void *holder, const struct dax_holder_operations *ops); 133 - void fs_put_dax(struct dax_device *dax_dev, void *holder); 134 133 #else 135 134 static inline int dax_add_host(struct dax_device *dax_dev, struct gendisk *disk) 136 135 { ··· 144 145 { 145 146 return NULL; 146 147 } 147 - static inline void fs_put_dax(struct dax_device *dax_dev, void *holder) 148 - { 149 - } 150 148 #endif /* CONFIG_BLOCK && CONFIG_FS_DAX */ 151 149 152 150 #if IS_ENABLED(CONFIG_FS_DAX) 151 + void fs_put_dax(struct dax_device *dax_dev, void *holder); 152 + int fs_dax_get(struct dax_device *dax_dev, void *holder, 153 + const struct dax_holder_operations *hops); 153 154 int dax_writeback_mapping_range(struct address_space *mapping, 154 155 struct dax_device *dax_dev, struct writeback_control *wbc); 155 156 int dax_folio_reset_order(struct folio *folio); ··· 163 164 void dax_unlock_mapping_entry(struct address_space *mapping, 164 165 unsigned long index, dax_entry_t cookie); 165 166 #else 167 + static inline void fs_put_dax(struct dax_device *dax_dev, void *holder) 168 + { 169 + } 170 + 171 + static inline int fs_dax_get(struct dax_device *dax_dev, void *holder, 172 + const struct dax_holder_operations *hops) 173 + { 174 + return -EOPNOTSUPP; 175 + } 166 176 static inline struct page *dax_layout_busy_page(struct address_space *mapping) 167 177 { 168 178 return NULL;