Re: [PATCH v3 2/5] block: Add bdev_supports_dax() for dax mount checks

From: Toshi Kani
Date: Mon May 09 2016 - 14:21:49 EST


On Sun, 2016-05-08 at 12:14 -0700, Dan Williams wrote:
> On Thu, May 5, 2016 at 5:29 PM, Toshi Kani <toshi.kani@xxxxxxx> wrote:
Â:
> > +int bdev_supports_dax(struct super_block *sb, int blocksize)
> > +{
> > +ÂÂÂÂÂÂÂstruct blk_dax_ctl dax = {
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ.sector = 0,
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ.size = PAGE_SIZE,
> > +ÂÂÂÂÂÂÂ};
> > +ÂÂÂÂÂÂÂint err;
> > +
> > +ÂÂÂÂÂÂÂif (blocksize != PAGE_SIZE) {
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂvfs_msg(sb, KERN_ERR, "error: unsupported blocksize for
> > dax");
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂreturn -EINVAL;
> > +ÂÂÂÂÂÂÂ}
> > +
> > +ÂÂÂÂÂÂÂerr = bdev_direct_access(sb->s_bdev, &dax);
> > +ÂÂÂÂÂÂÂif (err < 0) {
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂswitch (err) {
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂcase -EOPNOTSUPP:
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂvfs_msg(sb, KERN_ERR,
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ"error: device does not support dax");
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂbreak;
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂcase -EINVAL:
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂvfs_msg(sb, KERN_ERR,
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ"error: unaligned partition for dax");
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂbreak;
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂdefault:
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂvfs_msg(sb, KERN_ERR,
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ"error: dax access failed (%d)", err);
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ}
> > +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂreturn err;
> > +ÂÂÂÂÂÂÂ}
> > +
> > +ÂÂÂÂÂÂÂreturn 0;
> > +}
> > +EXPORT_SYMBOL_GPL(bdev_supports_dax);
>
> This patch should replace blkdev_dax_capable(), or just reuse that
> existing routine, or am I missing something?

Good question. Âbdev_supports_dax() is a helper function tailored for the
filesystem's mount -o dax case. ÂWhile blkdev_dax_capable() is similar, it
does not need error messages like "device does not support dax" since it
implicitly enables dax when capable. ÂSo, I think we can keep
blkdev_dax_capable(), but change it to callÂbdev_direct_access() so that
actual check is performed in a single place.

Thanks,
-Toshi