Skip to contentSkip to conversation

ksmbd: refactor smb2_notify() to a blocking wait

PATCH Superseded ChenXiaoSong 1 participant 4 messages Aug 8

Subsystems (2)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

ChenXiaoSong

author reviewer
#0 lore raw

v3 cover ksmbd: refactor smb2_notify() to a blocking wait

From: ChenXiaoSong <[email protected]>

v2->v3:
- Add patch #01.
- Patch #02 #03:
- Rebase on ksmbd-for-next-next branch.
- Split Gaël's patch into two patches for easier review.

The next version of my complete notify implementation may still take some time to modify, so merging Gael's patch sooner would help avoid repeated rebasing.

Gael's v2: https://lore.kernel.org/linux-cifs/[email protected]/
Gael's v1: 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    | 305 ++++++-------------------------------
 fs/smb/server/vfs_cache.c  |  48 ------
 fs/smb/server/vfs_cache.h  |   6 -
 5 files changed, 47 insertions(+), 320 deletions(-)
Signature · 1 line
2.54.0
author reviewer
#1 lore raw

PATCH v3 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 | 40 ----------------------------------------
 1 file changed, 40 deletions(-)
fs/smb/server/smb2pdu.c +0 -40
index 80f5791c687b..f729ee102a5b 100644
@@ -11142,46 +11142,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);
-		ksmbd_conn_write(in_work);
-		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.54.0
author reviewer
#2 lore raw

PATCH v3 2/3 ksmbd: temporarily remove interim-work change notify handling

In reply to ChenXiaoSong

From: 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 "ksmbd: expire SMB sessions when Kerberos tickets expire"
- Revert "ksmbd: retain connection for pending notify work"
- Revert part of "smb/server: avoid registering async requests during connection close"
- Revert "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    | 258 +------------------------------------
 fs/smb/server/vfs_cache.c  |  48 -------
 fs/smb/server/vfs_cache.h  |   6 -
 5 files changed, 4 insertions(+), 315 deletions(-)
fs/smb/server/ksmbd_work.c +0 -3
index f35335307670..097de59f807c 100644
@@ -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
index 5f1d3ebab4fb..0b55ad457cd3 100644
@@ -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 -254

298 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
index 5cac022b540b..7c5a874adecc 100644
@@ -158,12 +158,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.54.0
author reviewer
#3 lore raw

PATCH v3 3/3 ksmbd: refactor smb2_notify() to a blocking wait

In reply to ChenXiaoSong

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.

---
 fs/smb/server/ksmbd_work.h |  1 +
 fs/smb/server/smb2pdu.c    | 83 ++++++++++++++++++++++++++++++++++++--
 2 files changed, 81 insertions(+), 3 deletions(-)
fs/smb/server/ksmbd_work.h +1 -0
index 0b55ad457cd3..4c0b7b2535b9 100644
@@ -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 +80 -3

101 lines not on this page · raw message

Signature · 1 line
2.54.0