ksmbd: refactor smb2_notify() to a blocking wait
Subsystems (2)
ChenXiaoSong
reviewerv5 cover ksmbd: refactor smb2_notify() to a blocking wait
From: ChenXiaoSong <[email protected]>
v4->v5: Rebased on ksmbd-for-next branch.
v4: https://lore.kernel.org/linux-cifs/[email protected]/
ChenXiaoSong (1):
smb/server: support compound fid in notify requests
Gael Blivet (2):
ksmbd: temporarily remove interim-work change notify handling
ksmbd: refactor smb2_notify() to a blocking wait
fs/smb/server/ksmbd_work.c | 3 - fs/smb/server/ksmbd_work.h | 5 +- fs/smb/server/smb2pdu.c | 349 +++++++------------------------------ fs/smb/server/vfs_cache.c | 48 ----- fs/smb/server/vfs_cache.h | 6 - 5 files changed, 65 insertions(+), 346 deletions(-)
Signature · 1 line
2.55.0
ChenXiaoSong
reviewerPATCH v5 1/3 smb/server: support compound fid in notify requests
From: ChenXiaoSong <[email protected]>
A Windows client can send a compound request containing:
Create Request, File: <share>; Notify Request
The Notify Request uses FFFF...FFFF as the compound FID.
--- fs/smb/server/smb2pdu.c | 41 ----------------------------------------- 1 file changed, 41 deletions(-)
fs/smb/server/smb2pdu.c +0 -41
@@ -11818,47 +11818,6 @@ int smb2_notify(struct ksmbd_work *work)return -EIO ; } -/* -* 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. Respond STATUS_PENDING + STATUS_NOTIFY_CLEANUP immediately; -* without this, backupd aborts Time Machine setup on STATUS_FILE_CLOSED. -*/ -if (req->VolatileFileId ==SMB2_NO_FID && - req->PersistentFileId ==SMB2_NO_FID ) { - in_work =ksmbd_alloc_work_struct (); -if (!in_work ||allocate_interim_rsp_buf (in_work)) { -if (in_work) -ksmbd_free_work_struct (in_work); - rsp->hdr.Status =STATUS_INSUFFICIENT_RESOURCES ; -smb2_set_err_rsp (work); -return 0 ; - } -if (setup_async_work (work,NULL ,NULL )) { -ksmbd_free_work_struct (in_work); - rsp->hdr.Status =STATUS_INSUFFICIENT_RESOURCES ; -smb2_set_err_rsp (work); -return 0 ; - } -smb2_send_interim_resp (work,STATUS_PENDING ); - in_work->conn = work->conn; - in_hdr =smb_get_msg (in_work->response_buf); -memcpy (in_hdr,ksmbd_resp_buf_next (work), - __SMB2_HEADER_STRUCTURE_SIZE); - in_hdr->Flags |=SMB2_FLAGS_ASYNC_COMMAND ; - in_hdr->Id.AsyncId =cpu_to_le64 (work->async_id); -smb2_set_err_rsp (in_work); - in_hdr->Status =STATUS_NOTIFY_CLEANUP ; - in_work->async_id = work->async_id; - work->async_id =0 ; -release_async_work (work); -if (smb2_send_interim_work (in_work, work, false)) -ksmbd_debug (SMB ,"failed to send notify cleanup\n" ); -ksmbd_free_work_struct (in_work); - work->send_no_response =1 ; -return 0 ; - } -/* * KSMBD does not implement a real change-notification backend. * Genuine SMB2 servers (and macOS smbfs) never complete a
Signature · 1 line
2.55.0
ChenXiaoSong
reviewerPATCH v5 2/3 ksmbd: temporarily remove interim-work change notify handling
In reply to ChenXiaoSongFrom: Gael Blivet <[email protected]>
Prepare for the next patch. Split the removal of the old implementation into this separate patch to make the next patch easier to review.
The current change notify path keeps a synthetic ksmbd_work, named in_work, after the original request has returned. It also needs a per-file notify_pendings list and special close, cancel, and connection lifetime handling to complete and free that work.
Next patch replaces this design with a blocking wait in smb2_notify().
This patch reverts the following patches (or parts of them):
- Revert part of 2a0e037648da ("ksmbd: encrypt interim responses to encrypted requests")
- Revert 4818df5aaac0 ("ksmbd: wait for deferred notify cancellation")
- Revert part of a47634cd729b ("ksmbd: expire SMB sessions when Kerberos tickets expire")
- Revert f495154703cb ("ksmbd: retain connection for pending notify work")
- Revert part of 528af7cf69f3 ("smb/server: avoid registering async requests during connection close")
- Revert 152036e875e8 ("ksmbd: defer CHANGE_NOTIFY completion instead of STATUS_NOT_IMPLEMENTED")
--- fs/smb/server/ksmbd_work.c | 3 - fs/smb/server/ksmbd_work.h | 4 - fs/smb/server/smb2pdu.c | 271 +------------------------------------ fs/smb/server/vfs_cache.c | 48 ------- fs/smb/server/vfs_cache.h | 6 - 5 files changed, 4 insertions(+), 328 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 +0 -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; bool session_setup_reauth:1;
@@ -116,8 +114,6 @@ struct ksmbd_work {/* List head at conn->async_requests */ struct list_head async_request_entry;struct list_head fp_entry; -/* List head at ksmbd_file->notify_pendings */ -struct list_head notify_entry; };/**
fs/smb/server/smb2pdu.c +4 -267
311 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
@@ -162,12 +162,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,
Signature · 1 line
2.55.0
ChenXiaoSong
reviewerPATCH v5 3/3 ksmbd: refactor smb2_notify() to a blocking wait
In reply to ChenXiaoSongFrom: 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.
--- fs/smb/server/ksmbd_work.h | 1 + fs/smb/server/smb2pdu.c | 93 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 89 insertions(+), 5 deletions(-)
fs/smb/server/ksmbd_work.h +1 -0
@@ -113,6 +113,7 @@ 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; };
fs/smb/server/smb2pdu.c +88 -5
113 lines not on this page · raw message
Signature · 1 line
2.55.0
Namjae Jeon
maintainerQuoted 5 lines · ChenXiaoSong
From: ChenXiaoSong <[email protected]>
v4->v5: Rebased on ksmbd-for-next branch.
Quoted 8 lines
v4: https://lore.kernel.org/linux-cifs/[email protected]/
ChenXiaoSong (1):
smb/server: support compound fid in notify requestsGael Blivet (2):
ksmbd: temporarily remove interim-work change notify handling
ksmbd: refactorsmb2_notify()to a blocking wait
The smbtorture failure was caused by 0002 patch removing the signing path in smb2_send_notify_cancelled(). I combined patches 0002, 0003 and the signing path into a single patch.
And I will apply them to #ksmbd-for-next.
Thanks!