Skip to content

vfs, nfsd: implement directory delegations

Jeff Layton ecryptfs linux-cifs linux-doc linux-fsdevel linux-nfs linux-trace-kernel linux-unionfs linux-xfs lkml netfs oe-kbuild-all 3 versions – In review

Get series with b4
b4 am [email protected] change-id 20240215-dir-deleg-e212210ba9d4

Versions newest first

  1. v3 Latest38 patches 17 repliesIn review
  2. v2 RFC28 patches 5 repliesSuperseded
  3. v1 RFC24 patches 22 repliesSuperseded

Changes in v3 from the cover letter

- Rework to do minimal work in fsnotify callbacks
- Add support for sending attributes in CB_NOTIFY calls
- Add support for dir attr change notifications
- Link to v2: https://lore.kernel.org/r/[email protected]

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/38filelock: push the S_ISREG check down to ->setlease handlersfs/fuse/dir.c fs/locks.c fs/nfs/nfs4file.c +1 more+9 -20 replies
2/38filelock: add a lm_may_setlease lease_manager callbackfs/locks.c include/linux/filelock.h+19 -00 replies
3/38vfs: add try_break_deleg calls for parents to vfs_{link,rename,unlink}fs/namei.c+14 -11 reply
4/38vfs: allow mkdir to wait for delegation break on parentdrivers/base/devtmpfs.c fs/cachefiles/namei.c fs/ecryptfs/inode.c +8 more+28 -162 replies
5/38vfs: allow rmdir to wait for delegation break on parentfs/namei.c+34 -171 reply
6/38vfs: break parent dir delegations in open(..., O_CREAT) codepathfs/namei.c+18 -41 reply
7/38vfs: make vfs_create break delegations on parent directoryfs/namei.c+36 -193 replies
8/38vfs: make vfs_mknod break delegations on parent directoryfs/namei.c+35 -222 replies
9/38filelock: lift the ban on directory leases in generic_setleasefs/locks.c+3 -10 replies
10/38nfsd: allow filecache to hold S_IFDIR filesfs/nfsd/filecache.c fs/nfsd/filecache.h fs/nfsd/vfs.c +1 more+44 -150 replies
11/38nfsd: allow DELEGRETURN on directoriesfs/nfsd/nfs4state.c+2 -10 replies
12/38nfsd: check for delegation conflicts vs. the same clientfs/nfsd/nfs4state.c+28 -10 replies
13/38nfsd: wire up GET_DIR_DELEGATION handlingfs/nfsd/nfs4proc.c fs/nfsd/nfs4state.c fs/nfsd/state.h+107 -10 replies
14/38filelock: rework the __break_lease API to use flagsfs/locks.c include/linux/filelock.h+56 -260 replies
15/38filelock: add struct delegated_inodefs/attr.c fs/namei.c fs/open.c +6 more+116 -810 replies
16/38filelock: add support for ignoring deleg breaks for dir change eventsfs/locks.c include/linux/filelock.h include/trace/events/filelock.h+67 -230 replies
17/38filelock: add a tracepoint to start of break_lease()fs/locks.c include/trace/events/filelock.h+35 -00 replies
18/38filelock: add an inode_lease_ignore_mask helperfs/locks.c include/linux/filelock.h+33 -00 replies
19/38nfsd: add protocol support for CB_NOTIFYDocumentation/sunrpc/xdr/nfs4_1.x fs/nfsd/nfs4xdr_gen.c fs/nfsd/nfs4xdr_gen.h +4 more+1061 -1410 replies
20/38nfs_common: add new NOTIFY4_* flags proposed in RFC8881bisDocumentation/sunrpc/xdr/nfs4_1.x fs/nfsd/nfs4xdr_gen.c fs/nfsd/nfs4xdr_gen.h +1 more+29 -40 replies
21/38nfsd: allow nfsd to get a dir lease with an ignore maskfs/nfsd/nfs4state.c+21 -60 replies
22/38vfs: add fsnotify_modify_mark_mask()fs/notify/mark.c include/linux/fsnotify_backend.h+30 -01 reply
23/38nfsd: update the fsnotify mark when setting or removing a dir delegationfs/nfsd/nfs4state.c+35 -10 replies
24/38nfsd: make nfsd4_callback_ops->prepare operation bool returnfs/nfsd/nfs4callback.c fs/nfsd/nfs4layouts.c fs/nfsd/nfs4state.c +1 more+13 -70 replies
25/38nfsd: add callback encoding and decoding linkages for CB_NOTIFYfs/nfsd/nfs4callback.c fs/nfsd/state.h fs/nfsd/xdr4cb.h+66 -00 replies
26/38nfsd: add data structures for handling CB_NOTIFY to directory delegationfs/nfsd/nfs4state.c fs/nfsd/state.h+149 -160 replies
27/38nfsd: add notification handlers for dir eventsfs/nfsd/filecache.c fs/nfsd/nfs4callback.c fs/nfsd/nfs4state.c +3 more+337 -171 reply
28/38nfsd: add tracepoint to dir_event handlerfs/nfsd/nfs4state.c fs/nfsd/trace.h+22 -00 replies
29/38nfsd: apply the notify mask to the delegation when requestedfs/nfsd/nfs4proc.c+12 -00 replies
30/38nfsd: add helper to marshal a fattr4 from completed argsfs/nfsd/nfs4xdr.c+26 -200 replies
31/38nfsd: allow nfsd4_encode_fattr4_change() to work with no exportfs/nfsd/nfs4xdr.c+1 -10 replies
32/38nfsd: send basic file attributes in CB_NOTIFYfs/nfsd/nfs4xdr.c+45 -00 replies
33/38nfsd: allow encoding a filehandle into fattr4 without a svc_fhfs/nfsd/nfs4xdr.c+20 -150 replies
34/38nfsd: add a fi_connectable flag to struct nfs4_filefs/nfsd/nfs4state.c fs/nfsd/state.h+2 -00 replies
35/38nfsd: add the filehandle to returned attributes in CB_NOTIFYfs/nfsd/nfs4xdr.c+36 -00 replies
36/38nfsd: properly track requested child attributesfs/nfsd/nfs4proc.c fs/nfsd/nfs4state.c fs/nfsd/nfs4xdr.c +1 more+29 -90 replies
37/38nfsd: track requested dir attributesfs/nfsd/nfs4proc.c fs/nfsd/nfs4state.c fs/nfsd/state.h+19 -40 replies
38/38nfsd: add support to CB_NOTIFY for dir attribute changesfs/nfsd/nfs4state.c fs/nfsd/nfs4xdr.c fs/nfsd/xdr4.h+75 -110 replies

Reviews trailers per patch

6 of 38 patches have a Reviewed-by or Acked-by.

PatchJan Kara
1/38
2/38
3/38R-b
4/38R-b
5/38
6/38R-b
7/38R-b R-b
8/38R-b
9/38
10/38
11/38
12/38
13/38
14/38
15/38
16/38
17/38
18/38
19/38
20/38
21/38
22/38A-b
23/38
24/38
25/38
26/38
27/38
28/38
29/38
30/38
31/38
32/38
33/38
34/38
35/38
36/38
37/38
38/38

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 00/38] vfs, nfsd: implement directory delegations

This patchset is an update to a patchset that I posted in early June this year [1]. This version should be basically feature-complete, with a few caveats.

NFSv4.1 adds a GET_DIR_DELEGATION operation, to allow clients to request a delegation on a directory. If the client holds a directory delegation, then it knows that nothing will change the dentries in it until it has been recalled (modulo the case where the client requests notifications of directory changes).

In 2023, Rick Macklem gave a talk at the NFS Bakeathon on his implementation of directory delegations for FreeBSD [2], and showed that it can greatly improve LOOKUP-heavy workloads. There is also some earlier work by CITI [3] that showed similar results. The SMB protocol also has a similar sort of construct, and they have also seen large performance improvements on certain workloads.

This version also starts with support for trivial directory delegations that support no notifications. From there it adds VFS support for ignoring certain break_lease() events in directories. It then adds support for basic CB_NOTIFY calls (with names only). Next, support for sending attributes in the notifications is added.

I think that this version should be getting close to merge ready. Anna has graciously agreed to work on the client-side pieces for this. I've mostly been testing using pynfs tests (which I will submit soon).

The main limitation at this point is that callback requests are currently limited to a single page, so we can't send very many in a single CB_NOTIFY call. This will make it easy to "get into the weeds" if you're changing a directory quickly. The server will just recall the delegation in that case, so it's harmless even though it's not ideal.

If this approach looks acceptable I'll see if we can increase that limitation (it seems doable).

If anyone wishes to try this out, it's in the "dir-deleg" branch in my tree at kernel.org [4].

[1]: https://lore.kernel.org/linux-nfs/[email protected]/
[2]: https://www.youtube.com/watch?v=DdFyH3BN5pI
[3]: https://linux-nfs.org/wiki/index.php/CITI_Experience_with_Directory_Delegations
[4]: https://git.kernel.org/pub/scm/linux/kernel/git/jlayton/linux.git/

---
Changes in v3:
- Rework to do minimal work in fsnotify callbacks
- Add support for sending attributes in CB_NOTIFY calls
- Add support for dir attr change notifications
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- add support for ignoring certain break_lease() events
- basic support for CB_NOTIFY
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Jeff Layton (38):
filelock: push the S_ISREG check down to ->setlease handlers
filelock: add a lm_may_setlease lease_manager callback
vfs: add try_break_deleg calls for parents to vfs_{link,rename,unlink}
vfs: allow mkdir to wait for delegation break on parent
vfs: allow rmdir to wait for delegation break on parent
vfs: break parent dir delegations in open(..., O_CREAT) codepath
vfs: make vfs_create break delegations on parent directory
vfs: make vfs_mknod break delegations on parent directory
filelock: lift the ban on directory leases in generic_setlease
nfsd: allow filecache to hold S_IFDIR files
nfsd: allow DELEGRETURN on directories
nfsd: check for delegation conflicts vs. the same client
nfsd: wire up GET_DIR_DELEGATION handling
filelock: rework the __break_lease API to use flags
filelock: add struct delegated_inode
filelock: add support for ignoring deleg breaks for dir change events
filelock: add a tracepoint to start of break_lease()
filelock: add an inode_lease_ignore_mask helper
nfsd: add protocol support for CB_NOTIFY
nfs_common: add new NOTIFY4_* flags proposed in RFC8881bis
nfsd: allow nfsd to get a dir lease with an ignore mask
vfs: add fsnotify_modify_mark_mask()
nfsd: update the fsnotify mark when setting or removing a dir delegation
nfsd: make nfsd4_callback_ops->prepare operation bool return
nfsd: add callback encoding and decoding linkages for CB_NOTIFY
nfsd: add data structures for handling CB_NOTIFY to directory delegation
nfsd: add notification handlers for dir events
nfsd: add tracepoint to dir_event handler
nfsd: apply the notify mask to the delegation when requested
nfsd: add helper to marshal a fattr4 from completed args
nfsd: allow nfsd4_encode_fattr4_change() to work with no export
nfsd: send basic file attributes in CB_NOTIFY
nfsd: allow encoding a filehandle into fattr4 without a svc_fh
nfsd: add a fi_connectable flag to struct nfs4_file
nfsd: add the filehandle to returned attributes in CB_NOTIFY
nfsd: properly track requested child attributes
nfsd: track requested dir attributes
nfsd: add support to CB_NOTIFY for dir attribute changes

 Documentation/sunrpc/xdr/nfs4_1.x    | 267 +++++++++++++++++-
 drivers/base/devtmpfs.c              |   2 +-
 fs/attr.c                            |   4 +-
 fs/cachefiles/namei.c                |   2 +-
 fs/ecryptfs/inode.c                  |   2 +-
 fs/fuse/dir.c                        |   1 +
 fs/init.c                            |   2 +-
 fs/locks.c                           | 122 ++++++--
 fs/namei.c                           | 253 +++++++++++------
 fs/nfs/nfs4file.c                    |   2 +
 fs/nfsd/filecache.c                  | 101 +++++--
 fs/nfsd/filecache.h                  |   2 +
 fs/nfsd/nfs4callback.c               |  60 +++-
 fs/nfsd/nfs4layouts.c                |   3 +-
 fs/nfsd/nfs4proc.c                   |  36 ++-
 fs/nfsd/nfs4recover.c                |   2 +-
 fs/nfsd/nfs4state.c                  | 531 +++++++++++++++++++++++++++++++++--
 fs/nfsd/nfs4xdr.c                    | 298 +++++++++++++++++---
 fs/nfsd/nfs4xdr_gen.c                | 506 ++++++++++++++++++++++++++++++++-
 fs/nfsd/nfs4xdr_gen.h                |  20 +-
 fs/nfsd/state.h                      |  73 ++++-
 fs/nfsd/trace.h                      |  21 ++
 fs/nfsd/vfs.c                        |   7 +-
 fs/nfsd/vfs.h                        |   2 +-
 fs/nfsd/xdr4.h                       |   3 +
 fs/nfsd/xdr4cb.h                     |  12 +
 fs/notify/mark.c                     |  29 ++
 fs/open.c                            |   8 +-
 fs/overlayfs/overlayfs.h             |   2 +-
 fs/posix_acl.c                       |  12 +-
 fs/smb/client/cifsfs.c               |   3 +
 fs/smb/server/vfs.c                  |   2 +-
 fs/utimes.c                          |   4 +-
 fs/xattr.c                           |  16 +-
 fs/xfs/scrub/orphanage.c             |   2 +-
 include/linux/filelock.h             | 143 +++++++---
 include/linux/fs.h                   |  11 +-
 include/linux/fsnotify_backend.h     |   1 +
 include/linux/nfs4.h                 | 127 ---------
 include/linux/sunrpc/xdrgen/nfs4_1.h | 304 +++++++++++++++++++-
 include/linux/xattr.h                |   4 +-
 include/trace/events/filelock.h      |  38 ++-
 include/uapi/linux/nfs4.h            |   2 -
 43 files changed, 2636 insertions(+), 406 deletions(-)

---
base-commit: 36c204d169319562eed170f266c58460d5dad635
change-id: 20240215-dir-deleg-e212210ba9d4

Best regards,

Signature · 1 line
Jeff Layton <[email protected]>