dax: add fsdev_dax_from_file()

If the file is a fsdev_dax open, take the dax_dev from the device inode's
i_cdev.  Return with a reference grabbed on the private dax inode.

Make dax_dev_get() static again (internal to super.c for alloc_dax), export
fsdev_dax_from_file() instead.

This fix is in response to a Sashiko review, and some subsequent analysis.

About the 'fixes' tag: this removes the export of dax_dev_get(), which was
flawed, and replaces it with fsdev_dax_from_file(). It feels like the fixes
tag makes sense for correcting an ABI error.

Fixes: 2ae624d5a5 ("dax: export dax_dev_get()")
Originally-by: John Groves <john@groves.net>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Gregory Price (Meta) <gourry@gourry.net>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
This commit is contained in:
Miklos Szeredi 2026-10-19 14:56:11 +02:00
parent bf4ccbaad8
commit c87dd99b6d
3 changed files with 26 additions and 3 deletions

View File

@ -234,6 +234,29 @@ static const struct file_operations fsdev_fops = {
.release = fsdev_release,
};
/**
* fsdev_dax_from_file - get dax_device from an open file
* @file: open device file
*
* Returns a dax_device pointer if @file refers to a fsdev_dax device.
* Otherwise return NULL.
*
* Caller must put_dax() the returned device when done.
*/
struct dax_device *fsdev_dax_from_file(struct file *file)
{
struct dax_device *dax_dev;
if (file->f_op != &fsdev_fops)
return NULL;
dax_dev = inode_dax(file_inode(file));
ihold(dax_inode(dax_dev));
return dax_dev;
}
EXPORT_SYMBOL_GPL(fsdev_dax_from_file);
/*
* Acquire the dev_pagemap for probe: the static (pre-populated) one if
* present, or a devm-allocated one for the dynamic case. Note that

View File

@ -565,7 +565,7 @@ static int dax_set(struct inode *inode, void *data)
return 0;
}
struct dax_device *dax_dev_get(dev_t devt)
static struct dax_device *dax_dev_get(dev_t devt)
{
struct dax_device *dax_dev;
struct inode *inode;
@ -588,7 +588,6 @@ struct dax_device *dax_dev_get(dev_t devt)
return dax_dev;
}
EXPORT_SYMBOL_GPL(dax_dev_get);
struct dax_device *alloc_dax(void *private, const struct dax_operations *ops)
{

View File

@ -54,7 +54,6 @@ struct dax_device *alloc_dax(void *private, const struct dax_operations *ops);
void *dax_holder(struct dax_device *dax_dev);
void put_dax(struct dax_device *dax_dev);
void kill_dax(struct dax_device *dax_dev);
struct dax_device *dax_dev_get(dev_t devt);
void dax_write_cache(struct dax_device *dax_dev, bool wc);
bool dax_write_cache_enabled(struct dax_device *dax_dev);
bool dax_synchronous(struct dax_device *dax_dev);
@ -323,3 +322,5 @@ typedef int (*walk_hmem_fn)(struct device *dev, int target_nid,
const struct resource *res);
int walk_hmem_resources(struct device *dev, walk_hmem_fn fn);
#endif
struct dax_device *fsdev_dax_from_file(struct file *file);