Skip to content

Commit

Permalink
Allow automount of snapdir over NFS
Browse files Browse the repository at this point in the history
This commit allows the NFS server to automount ZFS snapdirs.
  • Loading branch information
anodos325 committed Feb 11, 2025
1 parent cce2e7b commit 9f81fd4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
22 changes: 21 additions & 1 deletion fs/nfsd/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ nfserrno (int errno)
return nfserr_io;
}

static int
is_zfs_snapdir(struct dentry *dentry)
{
#define ZFSCTL_INO_SNAPDIR 0x0000FFFFFFFFFFFDULL

struct inode *inode = d_inode(dentry);
if (inode == NULL)
return 0;

return (inode->i_ino == ZFSCTL_INO_SNAPDIR);
}

/*
* Called from nfsd_lookup and encode_dirent. Check if we have crossed
* a mount point.
Expand All @@ -127,11 +139,17 @@ nfsd_cross_mnt(struct svc_rqst *rqstp, struct dentry **dpp,
struct path path = {.mnt = mntget(exp->ex_path.mnt),
.dentry = dget(dentry)};
unsigned int follow_flags = 0;
int is_snapdir = 0;
int err = 0;

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;
}

err = follow_down(&path, follow_flags);
if (err < 0)
goto out;
Expand All @@ -157,7 +175,8 @@ nfsd_cross_mnt(struct svc_rqst *rqstp, struct dentry **dpp,
path_put(&path);
goto out;
}
if (nfsd_v4client(rqstp) ||

if (nfsd_v4client(rqstp) || is_snapdir ||
(exp->ex_flags & NFSEXP_CROSSMOUNT) || EX_NOHIDE(exp2)) {
/* successfully crossed mount point */
/*
Expand All @@ -171,6 +190,7 @@ nfsd_cross_mnt(struct svc_rqst *rqstp, struct dentry **dpp,
*expp = exp2;
exp2 = exp;
}

path_put(&path);
exp_put(exp2);
out:
Expand Down
3 changes: 2 additions & 1 deletion include/uapi/linux/nfsd/export.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@
*/
#define NFSEXP_V4ROOT 0x10000
#define NFSEXP_PNFS 0x20000
#define NFSEXP_SNAPDIR 0x40000 /* Expose the ZFS snapshot directory over NFS */

/* All flags that we claim to support. (Note we don't support NOACL.) */
#define NFSEXP_ALLFLAGS 0x3FEFF
#define NFSEXP_ALLFLAGS 0x7FEFF

/* The flags that may vary depending on security flavor: */
#define NFSEXP_SECINFO_FLAGS (NFSEXP_READONLY | NFSEXP_ROOTSQUASH \
Expand Down

0 comments on commit 9f81fd4

Please sign in to comment.