Skip to content

Commit 4287af3

Browse files
committed
Merge tag 'libnvdimm-for-5.16' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm
Pull libnvdimm update from Dan Williams: "A single cleanup that precedes some deeper PMEM/DAX reworks that did not settle in time for v5.16: - Continue the cleanup of the dax api in preparation for a dax-device block-device divorce" * tag 'libnvdimm-for-5.16' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm: nvdimm/pmem: move dax_attribute_group from dax to pmem
2 parents 89d714a + e765f13 commit 4287af3

File tree

3 files changed

+61
-84
lines changed

3 files changed

+61
-84
lines changed

drivers/dax/super.c

Lines changed: 18 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,24 @@ static int dax_host_hash(const char *host)
6363
return hashlen_hash(hashlen_string("DAX", host)) % DAX_HASH_SIZE;
6464
}
6565

66+
#ifdef CONFIG_BLOCK
67+
#include <linux/blkdev.h>
68+
69+
int bdev_dax_pgoff(struct block_device *bdev, sector_t sector, size_t size,
70+
pgoff_t *pgoff)
71+
{
72+
sector_t start_sect = bdev ? get_start_sect(bdev) : 0;
73+
phys_addr_t phys_off = (start_sect + sector) * 512;
74+
75+
if (pgoff)
76+
*pgoff = PHYS_PFN(phys_off);
77+
if (phys_off % PAGE_SIZE || size % PAGE_SIZE)
78+
return -EINVAL;
79+
return 0;
80+
}
81+
EXPORT_SYMBOL(bdev_dax_pgoff);
82+
83+
#if IS_ENABLED(CONFIG_FS_DAX)
6684
/**
6785
* dax_get_by_host() - temporary lookup mechanism for filesystem-dax
6886
* @host: alternate name for the device registered by a dax driver
@@ -94,24 +112,6 @@ static struct dax_device *dax_get_by_host(const char *host)
94112
return found;
95113
}
96114

97-
#ifdef CONFIG_BLOCK
98-
#include <linux/blkdev.h>
99-
100-
int bdev_dax_pgoff(struct block_device *bdev, sector_t sector, size_t size,
101-
pgoff_t *pgoff)
102-
{
103-
sector_t start_sect = bdev ? get_start_sect(bdev) : 0;
104-
phys_addr_t phys_off = (start_sect + sector) * 512;
105-
106-
if (pgoff)
107-
*pgoff = PHYS_PFN(phys_off);
108-
if (phys_off % PAGE_SIZE || size % PAGE_SIZE)
109-
return -EINVAL;
110-
return 0;
111-
}
112-
EXPORT_SYMBOL(bdev_dax_pgoff);
113-
114-
#if IS_ENABLED(CONFIG_FS_DAX)
115115
struct dax_device *fs_dax_get_by_bdev(struct block_device *bdev)
116116
{
117117
if (!blk_queue_dax(bdev->bd_disk->queue))
@@ -231,70 +231,6 @@ enum dax_device_flags {
231231
DAXDEV_SYNC,
232232
};
233233

234-
static ssize_t write_cache_show(struct device *dev,
235-
struct device_attribute *attr, char *buf)
236-
{
237-
struct dax_device *dax_dev = dax_get_by_host(dev_name(dev));
238-
ssize_t rc;
239-
240-
WARN_ON_ONCE(!dax_dev);
241-
if (!dax_dev)
242-
return -ENXIO;
243-
244-
rc = sprintf(buf, "%d\n", !!dax_write_cache_enabled(dax_dev));
245-
put_dax(dax_dev);
246-
return rc;
247-
}
248-
249-
static ssize_t write_cache_store(struct device *dev,
250-
struct device_attribute *attr, const char *buf, size_t len)
251-
{
252-
bool write_cache;
253-
int rc = strtobool(buf, &write_cache);
254-
struct dax_device *dax_dev = dax_get_by_host(dev_name(dev));
255-
256-
WARN_ON_ONCE(!dax_dev);
257-
if (!dax_dev)
258-
return -ENXIO;
259-
260-
if (rc)
261-
len = rc;
262-
else
263-
dax_write_cache(dax_dev, write_cache);
264-
265-
put_dax(dax_dev);
266-
return len;
267-
}
268-
static DEVICE_ATTR_RW(write_cache);
269-
270-
static umode_t dax_visible(struct kobject *kobj, struct attribute *a, int n)
271-
{
272-
struct device *dev = container_of(kobj, typeof(*dev), kobj);
273-
struct dax_device *dax_dev = dax_get_by_host(dev_name(dev));
274-
275-
WARN_ON_ONCE(!dax_dev);
276-
if (!dax_dev)
277-
return 0;
278-
279-
#ifndef CONFIG_ARCH_HAS_PMEM_API
280-
if (a == &dev_attr_write_cache.attr)
281-
return 0;
282-
#endif
283-
return a->mode;
284-
}
285-
286-
static struct attribute *dax_attributes[] = {
287-
&dev_attr_write_cache.attr,
288-
NULL,
289-
};
290-
291-
struct attribute_group dax_attribute_group = {
292-
.name = "dax",
293-
.attrs = dax_attributes,
294-
.is_visible = dax_visible,
295-
};
296-
EXPORT_SYMBOL_GPL(dax_attribute_group);
297-
298234
/**
299235
* dax_direct_access() - translate a device pgoff to an absolute pfn
300236
* @dax_dev: a dax_device instance representing the logical memory range

drivers/nvdimm/pmem.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,49 @@ static const struct dax_operations pmem_dax_ops = {
327327
.zero_page_range = pmem_dax_zero_page_range,
328328
};
329329

330+
static ssize_t write_cache_show(struct device *dev,
331+
struct device_attribute *attr, char *buf)
332+
{
333+
struct pmem_device *pmem = dev_to_disk(dev)->private_data;
334+
335+
return sprintf(buf, "%d\n", !!dax_write_cache_enabled(pmem->dax_dev));
336+
}
337+
338+
static ssize_t write_cache_store(struct device *dev,
339+
struct device_attribute *attr, const char *buf, size_t len)
340+
{
341+
struct pmem_device *pmem = dev_to_disk(dev)->private_data;
342+
bool write_cache;
343+
int rc;
344+
345+
rc = strtobool(buf, &write_cache);
346+
if (rc)
347+
return rc;
348+
dax_write_cache(pmem->dax_dev, write_cache);
349+
return len;
350+
}
351+
static DEVICE_ATTR_RW(write_cache);
352+
353+
static umode_t dax_visible(struct kobject *kobj, struct attribute *a, int n)
354+
{
355+
#ifndef CONFIG_ARCH_HAS_PMEM_API
356+
if (a == &dev_attr_write_cache.attr)
357+
return 0;
358+
#endif
359+
return a->mode;
360+
}
361+
362+
static struct attribute *dax_attributes[] = {
363+
&dev_attr_write_cache.attr,
364+
NULL,
365+
};
366+
367+
static const struct attribute_group dax_attribute_group = {
368+
.name = "dax",
369+
.attrs = dax_attributes,
370+
.is_visible = dax_visible,
371+
};
372+
330373
static const struct attribute_group *pmem_attribute_groups[] = {
331374
&dax_attribute_group,
332375
NULL,

include/linux/dax.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ struct dax_operations {
3838
int (*zero_page_range)(struct dax_device *, pgoff_t, size_t);
3939
};
4040

41-
extern struct attribute_group dax_attribute_group;
42-
4341
#if IS_ENABLED(CONFIG_DAX)
4442
struct dax_device *alloc_dax(void *private, const char *host,
4543
const struct dax_operations *ops, unsigned long flags);

0 commit comments

Comments
 (0)