ksmbd: refactor smb2_notify() to a blocking wait, matching smb2_lock()
Subsystems (2)
PATCH v2 1/1 ksmbd: refactor smb2_notify() to a blocking wait, matching smb2_lock()
From: Gael Blivet <[email protected]>
The previous design registered a synthetic work struct (in_work) directly on conn->async_requests and deferred the response to a workqueue -- a bespoke async/cancel implementation duplicating what setup_async_work(), release_async_work(), and smb2_send_interim_resp() already provide for smb2_lock()'s pending byte-range lock.
Replace it with that same pattern: setup_async_work() on the calling work itself, registered on fp->blocked_works, woken by cancel or by the handle closing via the existing set_close_state_blocked_works(). This removes the synthetic work struct, the notify_pendings list and its close-time drain, and the deferred workqueue send, leaving smb2_notify() sharing the same async/cancel machinery as smb2_lock() instead of its own separate copy.
The worker now blocks on ksmbd_wq for as long as the watch stays open, instead of returning immediately. This also makes the skeleton ready for a future event-delivery implementation on the same blocking wait.
---
v1 -> v2:
- Shortened the smb2_notify() kerneldoc to @work/Return only.
- FileId sentinel path: use smb2_set_err_rsp() + STATUS_INVALID_PARAMETER instead of STATUS_PENDING/STATUS_NOTIFY_CLEANUP.
- Removed dead owns_conn_ref field from struct ksmbd_work.
- Removed the CHANGE_NOTIFY-wake comment in __ksmbd_close_fd().
fs/smb/server/ksmbd_work.c | 3 - fs/smb/server/ksmbd_work.h | 5 +- fs/smb/server/smb2pdu.c | 242 ++++++++----------------------------- fs/smb/server/vfs_cache.c | 48 -------- fs/smb/server/vfs_cache.h | 6 - 5 files changed, 51 insertions(+), 253 deletions(-)
fs/smb/server/ksmbd_work.c +0 -3
@@ -57,7 +57,6 @@ struct ksmbd_work *ksmbd_alloc_work_struct(void)INIT_LIST_HEAD (&work->request_entry);INIT_LIST_HEAD (&work->async_request_entry);INIT_LIST_HEAD (&work->fp_entry); -INIT_LIST_HEAD (&work->notify_entry);INIT_LIST_HEAD (&work->aux_read_list); work->iov_alloc_cnt =ARRAY_SIZE (work->iov_inline); work->iov = work->iov_inline;
@@ -87,8 +86,6 @@ void ksmbd_free_work_struct(struct ksmbd_work *work)if (work->async_id)ksmbd_release_id (&work->conn->async_ida, work->async_id); -if (work->owns_conn_ref) -ksmbd_conn_put (work->conn);ksmbd_fd_put (work, work->request_open);kmem_cache_free (work_cache, work); }
fs/smb/server/ksmbd_work.h +1 -4
@@ -91,8 +91,6 @@ struct ksmbd_work { bool compress_response:1;/* Is this SYNC or ASYNC ksmbd_work */ bool asynchronous:1; -/* Work owns a reference to @conn. */ - bool owns_conn_ref:1; bool need_invalidate_rkey:1; bool request_open_chseq_tracked:1;
@@ -114,9 +112,8 @@ struct ksmbd_work {struct list_head request_entry;/* List head at conn->async_requests */ struct list_head async_request_entry; +/* List head at ksmbd_file->blocked_works */ struct list_head fp_entry; -/* List head at ksmbd_file->notify_pendings */ -struct list_head notify_entry; };/**
fs/smb/server/smb2pdu.c +50 -192
297 lines not on this page · raw message
fs/smb/server/vfs_cache.c +0 -48
66 lines not on this page · raw message
fs/smb/server/vfs_cache.h +0 -6
@@ -157,12 +157,6 @@ struct ksmbd_file {unsigned int outstanding_requests;unsigned int outstanding_pre_requests;struct ksmbd_lock_sequence lock_seq[KSMBD_LOCK_SEQ_ARRAY_SIZE ]; - -/* -* Pending CHANGE_NOTIFY completions for this handle, sent with -* STATUS_NOTIFY_CLEANUP when the handle is closed. -*/ -struct list_head notify_pendings; }; static inline void set_ctx_actor(struct dir_context *ctx,
base-commit: e3ebfe6d5045a2365caae7f8cb988b1d087bbbef
Signature · 1 line
2.43.0
ChenXiaoSong
reviewerWhen Windows is used as the client, this check must be removed because Windows sends a compound request:
CREATE dir; CHANGE_NOTIFY, fid = compound fid (FFFF...FFFF)
However, I am not yet sure whether skipping this check could cause any issues when macOS is used as the client. I will test it with a macOS client tomorrow.
Review int smb2_notify(struct ksmbd_work *work) · line 10908
Quoted 2 lines · Gaël Blivet-Bailly
(quoted diff) +0
-0@@ -10967,56 +10908,17 @@ int smb2_notify(struct ksmbd_work *work) }
...> + * macOS backupd sends CHANGE_NOTIFY with FileId=FFFF...FFFF
fs/smb/server/smb2pdu.c int smb2_notify(struct ksmbd_work *work) · line 10916
Quoted 5 lines
fs/smb/server/smb2pdu.c +2
-0+* (share-root sentinel) to watch for changes on the share root +* without holding an open handle. */ if (req->VolatileFileId ==SMB2_NO_FID && req->PersistentFileId ==SMB2_NO_FID ) {
...> + rsp->hdr.Status = STATUS_INVALID_PARAMETER;
Quoted 3 lines
fs/smb/server/smb2pdu.c +1
-0+smb2_set_err_rsp (work);return 0 ; }
Signature · 3 lines
ChenXiaoSong <[email protected]> Chinese Homepage: https://chenxiaosong.com English Homepage: https://chenxiaosong.com/en
ChenXiaoSong
reviewerHi Gaël,
Would you mind if I include your patch in my new version of the change notify feature patchset? I may make some changes to this patch, but I will ask for your approval on the final version.
Quoted 21 lines · ChenXiaoSong
When Windows is used as the client, this check must be removed because Windows sends a compound request:
CREATE dir;CHANGE_NOTIFY, fid = compound fid (FFFF...FFFF)However, I am not yet sure whether skipping this check could cause any issues when macOS is used as the client. I will test it with a macOS client tomorrow.
Quoted 14 lines · Gaël Blivet-Bailly
fs/smb/server/smb2pdu.c +3
-0@@ -10967,56 +10908,17 @@ int smb2_notify(struct ksmbd_work *work) } + * macOS backupd sends CHANGE_NOTIFY with FileId=FFFF...FFFF + * (share-root sentinel) to watch for changes on the share root + * without holding an open handle.*/
if (req->VolatileFileId==SMB2_NO_FID&&req->PersistentFileId==SMB2_NO_FID) {
...
+rsp->hdr.Status=STATUS_INVALID_PARAMETER; +smb2_set_err_rsp(work);
return 0;
}
Signature · 3 lines
ChenXiaoSong <[email protected]> Chinese Homepage: https://chenxiaosong.com English Homepage: https://chenxiaosong.com/en
ChenXiaoSong
reviewerHi Gaël,
I tested the macOS client, and it seems that this check is not needed either. What issue did you add this check to fix?
Quoted 21 lines · ChenXiaoSong
When Windows is used as the client, this check must be removed because Windows sends a compound request:
CREATE dir;CHANGE_NOTIFY, fid = compound fid (FFFF...FFFF)However, I am not yet sure whether skipping this check could cause any issues when macOS is used as the client. I will test it with a macOS client tomorrow.
Quoted 14 lines · Gaël Blivet-Bailly
fs/smb/server/smb2pdu.c +3
-0@@ -10967,56 +10908,17 @@ int smb2_notify(struct ksmbd_work *work) } + * macOS backupd sends CHANGE_NOTIFY with FileId=FFFF...FFFF + * (share-root sentinel) to watch for changes on the share root + * without holding an open handle.*/
if (req->VolatileFileId==SMB2_NO_FID&&req->PersistentFileId==SMB2_NO_FID) {
...
+rsp->hdr.Status=STATUS_INVALID_PARAMETER; +smb2_set_err_rsp(work);
return 0;
}
Signature · 3 lines
ChenXiaoSong <[email protected]> Chinese Homepage: https://chenxiaosong.com English Homepage: https://chenxiaosong.com/en
Hello ChenXiaoSong,
Good catch. I also confirmed after testing that it is not needed. The initial analysis was based on packet capture and I mistook it as a macOS requirement. My apologies for the noise. Could you remove it in your new version of the patch, or do you want me to update it?
Quoted 5 lines · ChenXiaoSong
Hi Gaël,
I tested the macOS client, and it seems that this check is not needed either. What issue did you add this check to fix?
ChenXiaoSong
reviewerI will update it.
Quoted 1 line · Gaël Blivet
Good catch. I also confirmed after testing that it is not needed. The initial analysis was based on packet capture and I mistook it as a macOS requirement. My apologies for the noise. Could you remove it in your new version of the patch, or do you want me to update it?
Signature · 3 lines
ChenXiaoSong <[email protected]> Chinese Homepage: https://chenxiaosong.com English Homepage: https://chenxiaosong.com/en