Skip to content

Commit

Permalink
Fix snapdir check and add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
anodos325 committed Feb 12, 2025
1 parent 9f81fd4 commit eabb644
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions fs/nfsd/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,38 @@ nfserrno (int errno)
return nfserr_io;
}

/*
* Called from nfsd_cross_mnt and is used to determine
* whether we need to set LOOKUP_AUTOMOUNT flag.
*
* ZFSCTL_INO_SNAPDIR is defined in sys/zfs_ctldir.h
* and is unlikely to change. This is a hard-coded inode
* number for ./zfs/snapshot directory in the ZFS ctldir.
*
* If we know the parent inode number is the snapdir then
* we also know that the curent dentry is for an auto-
* mounted snapshot.
*/
static int
is_zfs_snapdir(struct dentry *dentry)
is_in_zfs_snapdir(struct dentry *dentry)
{
#define ZFSCTL_INO_SNAPDIR 0x0000FFFFFFFFFFFDULL
#define ZFSCTL_INO_SNAPDIR 0x0000FFFFFFFFFFFDULL

struct inode *inode = d_inode(dentry);
struct dentry *dp = dentry->d_parent;
struct inode *inode = NULL;

if (dp == NULL)
return 0;

inode = d_inode(dp);
if (inode == NULL)
return 0;

// Currently only ZFS has large xattr support enabled.
if (!IS_LARGE_XATTR(inode))
return 0;

// The ZFS snapdir has a hard-coded inode value
return (inode->i_ino == ZFSCTL_INO_SNAPDIR);
}

Expand All @@ -145,9 +168,11 @@ nfsd_cross_mnt(struct svc_rqst *rqstp, struct dentry **dpp,
if (exp->ex_flags & NFSEXP_CROSSMOUNT)
follow_flags = LOOKUP_AUTOMOUNT;

if ((exp->ex_flags & NFSEXP_SNAPDIR) && is_zfs_snapdir(dentry)) {
follow_flags = LOOKUP_AUTOMOUNT;
is_snapdir = 1;
// ZFS ctldir specific handling
if (exp->ex_flags & NFSEXP_SNAPDIR) {
is_snapdir = is_in_zfs_snapdir(dentry);
if (is_snapdir)
follow_flags = LOOKUP_AUTOMOUNT;
}

err = follow_down(&path, follow_flags);
Expand Down

0 comments on commit eabb644

Please sign in to comment.