History

libnvdimm: add dax_dev sync flag

This patch adds 'DAXDEV_SYNC' flag which is set for nd_region doing synchronous flush. This later is used to disable MAP_SYNC functionality for ext4 & xfs filesystem for devices don't support synchronous flush.

Pankaj Gupta committed 7 years ago

Commit fefc1d91 parent 6e842008 files · +56 −7Browse files

Unified · Split

8 files
  1. drivers/dax/bus.c +1 −1
  2. drivers/dax/super.c +18 −1
  3. drivers/md/dm.c +2 −1
  4. drivers/nvdimm/pmem.c +4 −1
  5. drivers/nvdimm/region_devs.c +7 −0
  6. drivers/s390/block/dcssblk.c +1 −1
  7. include/linux/dax.h +22 −2
  8. include/linux/libnvdimm.h +1 −0
drivers/dax/bus.c+1−1
@@ -388,7 +388,7 @@ struct dev_dax *__devm_create_dev_dax(struct dax_region *dax_region, int id, · 387 unmodified lines
388388 * No 'host' or dax_operations since there is no access to this
389389 * device outside of mmap of the resulting character device.
390390 */
391− dax_dev = alloc_dax(dev_dax, NULL, NULL);
391+ dax_dev = alloc_dax(dev_dax, NULL, NULL, DAXDEV_F_SYNC);
392392 if (!dax_dev)
393393 goto err;
394394
drivers/dax/super.c+18−1
@@ -195,6 +195,8 @@ enum dax_device_flags { · 194 unmodified lines
195195 DAXDEV_ALIVE,
196196 /* gate whether dax_flush() calls the low level flush routine */
197197 DAXDEV_WRITE_CACHE,
198+ /* flag to check if device supports synchronous flush */
199+ DAXDEV_SYNC,
198200 };
199201
200202 /**
@@ -372,6 +374,18 @@ bool dax_write_cache_enabled(struct dax_device *dax_dev) · 171 unmodified lines
372374 }
373375 EXPORT_SYMBOL_GPL(dax_write_cache_enabled);
374376
377+bool __dax_synchronous(struct dax_device *dax_dev)
378+{
379+ return test_bit(DAXDEV_SYNC, &dax_dev->flags);
380+}
381+EXPORT_SYMBOL_GPL(__dax_synchronous);
382+
383+void __set_dax_synchronous(struct dax_device *dax_dev)
384+{
385+ set_bit(DAXDEV_SYNC, &dax_dev->flags);
386+}
387+EXPORT_SYMBOL_GPL(__set_dax_synchronous);
388+
375389 bool dax_alive(struct dax_device *dax_dev)
376390 {
377391 lockdep_assert_held(&dax_srcu);
@@ -526,7 +540,7 @@ static void dax_add_host(struct dax_device *dax_dev, const char *host) · 148 unmodified lines
526540 }
527541
528542 struct dax_device *alloc_dax(void *private, const char *__host,
529− const struct dax_operations *ops)
543+ const struct dax_operations *ops, unsigned long flags)
530544 {
531545 struct dax_device *dax_dev;
532546 const char *host;
@@ -549,6 +563,9 @@ struct dax_device *alloc_dax(void *private, const char *__host, · 16 unmodified lines
549563 dax_add_host(dax_dev, host);
550564 dax_dev->ops = ops;
551565 dax_dev->private = private;
566+ if (flags & DAXDEV_F_SYNC)
567+ set_dax_synchronous(dax_dev);
568+
552569 return dax_dev;
553570
554571 err_dev:
drivers/md/dm.c+2−1
@@ -1991,7 +1991,8 @@ static struct mapped_device *alloc_dev(int minor) · 1990 unmodified lines
19911991 sprintf(md->disk->disk_name, "dm-%d", minor);
19921992
19931993 if (IS_ENABLED(CONFIG_DAX_DRIVER)) {
1994− md->dax_dev = alloc_dax(md, md->disk->disk_name, &dm_dax_ops);
1994+ md->dax_dev = alloc_dax(md, md->disk->disk_name,
1995+ &dm_dax_ops, 0);
19951996 if (!md->dax_dev)
19961997 goto bad;
19971998 }
drivers/nvdimm/pmem.c+4−1
@@ -376,6 +376,7 @@ static int pmem_attach_disk(struct device *dev, · 375 unmodified lines
376376 struct gendisk *disk;
377377 void *addr;
378378 int rc;
379+ unsigned long flags = 0UL;
379380
380381 pmem = devm_kzalloc(dev, sizeof(*pmem), GFP_KERNEL);
381382 if (!pmem)
@@ -474,7 +475,9 @@ static int pmem_attach_disk(struct device *dev, · 92 unmodified lines
474475 nvdimm_badblocks_populate(nd_region, &pmem->bb, &bb_res);
475476 disk->bb = &pmem->bb;
476477
477− dax_dev = alloc_dax(pmem, disk->disk_name, &pmem_dax_ops);
478+ if (is_nvdimm_sync(nd_region))
479+ flags = DAXDEV_F_SYNC;
480+ dax_dev = alloc_dax(pmem, disk->disk_name, &pmem_dax_ops, flags);
478481 if (!dax_dev) {
479482 put_disk(disk);
480483 return -ENOMEM;
drivers/nvdimm/region_devs.c+7−0
@@ -1211,6 +1211,13 @@ int nvdimm_has_cache(struct nd_region *nd_region) · 1210 unmodified lines
12111211 }
12121212 EXPORT_SYMBOL_GPL(nvdimm_has_cache);
12131213
1214+bool is_nvdimm_sync(struct nd_region *nd_region)
1215+{
1216+ return is_nd_pmem(&nd_region->dev) &&
1217+ !test_bit(ND_REGION_ASYNC, &nd_region->flags);
1218+}
1219+EXPORT_SYMBOL_GPL(is_nvdimm_sync);
1220+
12141221 struct conflict_context {
12151222 struct nd_region *nd_region;
12161223 resource_size_t start, size;
drivers/s390/block/dcssblk.c+1−1
@@ -679,7 +679,7 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char · 678 unmodified lines
679679 goto put_dev;
680680
681681 dev_info->dax_dev = alloc_dax(dev_info, dev_info->gd->disk_name,
682− &dcssblk_dax_ops);
682+ &dcssblk_dax_ops, DAXDEV_F_SYNC);
683683 if (!dev_info->dax_dev) {
684684 rc = -ENOMEM;
685685 goto put_dev;
include/linux/dax.h+22−2
@@ -7,6 +7,9 @@ · 6 unmodified lines
77 #include <linux/radix-tree.h>
88 #include <asm/pgtable.h>
99
10+/* Flag for synchronous flush */
11+#define DAXDEV_F_SYNC (1UL << 0)
12+
1013 typedef unsigned long dax_entry_t;
1114
1215 struct iomap_ops;
@@ -38,18 +41,28 @@ extern struct attribute_group dax_attribute_group; · 25 unmodified lines
3841 #if IS_ENABLED(CONFIG_DAX)
3942 struct dax_device *dax_get_by_host(const char *host);
4043 struct dax_device *alloc_dax(void *private, const char *host,
41− const struct dax_operations *ops);
44+ const struct dax_operations *ops, unsigned long flags);
4245 void put_dax(struct dax_device *dax_dev);
4346 void kill_dax(struct dax_device *dax_dev);
4447 void dax_write_cache(struct dax_device *dax_dev, bool wc);
4548 bool dax_write_cache_enabled(struct dax_device *dax_dev);
49+bool __dax_synchronous(struct dax_device *dax_dev);
50+static inline bool dax_synchronous(struct dax_device *dax_dev)
51+{
52+ return __dax_synchronous(dax_dev);
53+}
54+void __set_dax_synchronous(struct dax_device *dax_dev);
55+static inline void set_dax_synchronous(struct dax_device *dax_dev)
56+{
57+ __set_dax_synchronous(dax_dev);
58+}
4659 #else
4760 static inline struct dax_device *dax_get_by_host(const char *host)
4861 {
4962 return NULL;
5063 }
5164 static inline struct dax_device *alloc_dax(void *private, const char *host,
52− const struct dax_operations *ops)
65+ const struct dax_operations *ops, unsigned long flags)
5366 {
5467 /*
5568 * Callers should check IS_ENABLED(CONFIG_DAX) to know if this
@@ -70,6 +83,13 @@ static inline bool dax_write_cache_enabled(struct dax_device *dax_dev) · 14 unmodified lines
7083 {
7184 return false;
7285 }
86+static inline bool dax_synchronous(struct dax_device *dax_dev)
87+{
88+ return true;
89+}
90+static inline void set_dax_synchronous(struct dax_device *dax_dev)
91+{
92+}
7393 #endif
7494
7595 struct writeback_control;
include/linux/libnvdimm.h+1−0
@@ -263,6 +263,7 @@ int generic_nvdimm_flush(struct nd_region *nd_region); · 262 unmodified lines
263263 int nvdimm_has_flush(struct nd_region *nd_region);
264264 int nvdimm_has_cache(struct nd_region *nd_region);
265265 int nvdimm_in_overwrite(struct nvdimm *nvdimm);
266+bool is_nvdimm_sync(struct nd_region *nd_region);
266267
267268 static inline int nvdimm_ctl(struct nvdimm *nvdimm, unsigned int cmd, void *buf,
268269 unsigned int buf_len, int *cmd_rc)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t