ksmbd: refactor smb2_notify() to a blocking wait
Subsystems (2)
ChenXiaoSong
reviewerv4 cover ksmbd: refactor smb2_notify() to a blocking wait
From: ChenXiaoSong <[email protected]>
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.
v3->v4:
- Patch #03:
- Rename: ksmbd_notify_wait -> ksmbd_notify_req.
- Return the error code instead of 0 when an error occurs in smb2_notify().
v3: 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 | 335 +++++++------------------------------ fs/smb/server/vfs_cache.c | 48 ------ fs/smb/server/vfs_cache.h | 6 - 5 files changed, 65 insertions(+), 332 deletions(-)
Signature · 1 line
2.54.0
ChenXiaoSong
reviewerPATCH v4 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
@@ -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
ChenXiaoSong
reviewerPATCH v4 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 "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
@@ -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 -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
@@ -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
ChenXiaoSong
reviewerPATCH v4 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.54.0
Namjae Jeon
maintainerQuoted 5 lines · ChenXiaoSong
From: ChenXiaoSong <[email protected]>
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.
Can you check two smbtorture failures from this patch-set ?
$ ./bin/smbtorture //ksmbd.test/cifsd-test3/ [email protected]%1234 --use-kerberos=required smb2.session.expire2s
smbtorture 4.18.0
Using seed 1786452357
time: 2026-08-11 12:45:57.628809
test: expire2s
time: 2026-08-11 12:45:57.629426
query info => OK
lock => OK
1st notify => PENDING
sleep 10 seconds
query info => EXPIRED
set info => EXPIRED
flush => EXPIRED
read => EXPIRED
write => EXPIRED
ioctl => EXPIRED
oplock ack => EXPIRED
lease ack => EXPIRED
query directory => EXPIRED
1st notify => CANCEL
2nd notify => EXPIRED
time: 2026-08-11 12:46:07.761775
failure: expire2s [ ../../source4/torture/smb2/session.c:1482: status was NT_STATUS_ACCESS_DENIED, expected NT_STATUS_NETWORK_SESSION_EXPIRED:smb2_notify returned unexpected status
]
$ ./bin/smbtorture //ksmbd.test/cifsd-test3/ [email protected]%1234 --use-kerberos=required smb2.session.expire2e
smbtorture 4.18.0
Using seed 1786452388
time: 2026-08-11 12:46:28.839654
test: expire2e
time: 2026-08-11 12:46:28.840279
query info => OK
lock => OK
1st notify => PENDING
sleep 10 seconds
query info => EXPIRED
set info => EXPIRED
flush => EXPIRED
read => EXPIRED
write => EXPIRED
ioctl => EXPIRED
oplock ack => EXPIRED
lease ack => EXPIRED
query directory => EXPIRED
1st notify => CANCEL
2nd notify => EXPIRED
time: 2026-08-11 12:46:38.954222
failure: expire2e [ ../../source4/torture/smb2/session.c:1482: status was NT_STATUS_ACCESS_DENIED, expected NT_STATUS_NETWORK_SESSION_EXPIRED:smb2_notify returned unexpected status
]
ChenXiaoSong
reviewerI am trying to setup kerberos test environment. If you have any better related documentation, that would be very helpful to me.
Quoted 1 line · Namjae Jeon
Can you check two smbtorture failures from this patch-set ?
Signature · 3 lines
ChenXiaoSong <[email protected]> Chinese Homepage: https://chenxiaosong.com English Homepage: https://chenxiaosong.com/en
Namjae Jeon
maintainerQuoted 3 lines · ChenXiaoSong
I am trying to setup kerberos test environment. If you have any better related documentation, that would be very helpful to me.
================================================================================
ksmbd Kerberos v5 Setup & Test Guide
================================================================================
1. Kernel & Build Requirements
--------------------------------------------------------------------------------
1. Ensure your Linux kernel is compiled with Kerberos v5 support enabled:
CONFIG_SMB_SERVER_KERBEROS5=y
2. Build ksmbd-tools (ksmbd.mountd) with Kerberos 5 support (--enable-krb5):
$ sudo apt update
$ sudo apt install libkrb5-dev glib-2.0-dev libnl-3-dev libnl-genl-3-dev $ ./autogen.sh
$ ./configure --enable-krb5
$ make
$ sudo make installVerify Kerberos library linkage:
$ ldd $(which ksmbd.mountd) | grep -i krb
2. KDC Setup & Principal/Keytab Generation
--------------------------------------------------------------------------------
Install KDC packages:
$ sudo apt update $ sudo apt install krb5-kdc krb5-admin-server
Create principals and keytab using kadmin.local:
$ sudo kadmin.local
Inside kadmin.local:
addprinc [email protected]
addprinc -randkey cifs/[email protected] ktadd -k /etc/ksmbd/ksmbd.keytab cifs/[email protected] quit
Verify the generated keytab:
$ sudo klist -kte /etc/ksmbd/ksmbd.keytab
3. ksmbd.conf Configuration
--------------------------------------------------------------------------------
Add Kerberos settings under the [global] section in /etc/ksmbd/ksmbd.conf:
[global]
kerberos support = yes
kerberos keytab file = /etc/ksmbd/ksmbd.keytab kerberos service name = cifs/[email protected] workgroup = KSMBD
4. Service Restart Procedure
--------------------------------------------------------------------------------
Restart services and reload kernel module:
$ sudo ksmbd.control --shutdown $ sudo modprobe -r ksmbd $ sudo modprobe ksmbd $ sudo ksmbd.mountd
5. Kerberos Authentication Verification
--------------------------------------------------------------------------------
Verify Kerberos ticket acquisition independently of SMB:
$ kdestroy $ kinit [email protected] $ kvno cifs/[email protected] $ klist -e
6. SMB Test Execution
--------------------------------------------------------------------------------
Run smbtorture with strict Kerberos authentication and FQDN:
$ ./bin/smbtorture //ksmbd.test/cifsd-test3/ [email protected]%1234 --use-kerberos=required smb2.session.expire2e ================================================================================
ChenXiaoSong
reviewerHi Namjae,
Before this patchset, the two test cases also failed. I would like to know your test results before this patchset. I am not sure whether there is something wrong with my krb5 environment. But I tested the smb2.session.expire1s and smb2.session.expire1e test cases, and they passed.
failure: expire2s [../../source4/torture/smb2/session.c:1611: status was NT_STATUS_IO_TIMEOUT, expected NT_STATUS_NETWORK_SESSION_EXPIRED: smb2_find returned unexpected ss ]
failure: expire2e [../../source4/torture/smb2/session.c:1611: status was NT_STATUS_IO_TIMEOUT, expected NT_STATUS_NETWORK_SESSION_EXPIRED: smb2_find returned unexpected ss ]
Quoted 21 lines · Namjae Jeon
Can you check two smbtorture failures from this patch-set ?
$ ./bin/smbtorture //ksmbd.test/cifsd-test3/ [email protected]%1234 --use-kerberos=required smb2.session.expire2s ... failure: expire2s [ ../../source4/torture/smb2/session.c:1482: status was NT_STATUS_ACCESS_DENIED, expected NT_STATUS_NETWORK_SESSION_EXPIRED: smb2_notify returned unexpected status ]$ ./bin/smbtorture //ksmbd.test/cifsd-test3/ [email protected]%1234 --use-kerberos=required smb2.session.expire2e ... failure: expire2e [ ../../source4/torture/smb2/session.c:1482: status was NT_STATUS_ACCESS_DENIED, expected NT_STATUS_NETWORK_SESSION_EXPIRED: smb2_notify returned unexpected status ]
Signature · 3 lines
ChenXiaoSong <[email protected]> Chinese Homepage: https://chenxiaosong.com English Homepage: https://chenxiaosong.com/en
Namjae Jeon
maintainerQuoted 8 lines · ChenXiaoSong
Hi Namjae,
Before this patchset, the two test cases also failed. I would like to know your test results before this patchset. I am not sure whether there is something wrong with my krb5 environment. But I tested the
smb2.session.expire1sandsmb2.session.expire1etest cases, and they passed.
Can you check if smb2.session.expire1s/1e tests are passed after applying these patches ?
ChenXiaoSong
reviewerAfter this patchset, smb2.session.expire1s/1e are passed.
Quoted 2 lines · Namjae Jeon
Can you check if smb2.session.expire1s/1e tests are passed after applying these patches ?
Signature · 3 lines
ChenXiaoSong <[email protected]> Chinese Homepage: https://chenxiaosong.com English Homepage: https://chenxiaosong.com/en
ChenXiaoSong
reviewerFor ksmbd-tools, I am using your github repository instead of the cifsd-team repository:
https://github.com/namjaejeon/ksmbd-tools.git
Quoted 6 lines · ChenXiaoSong
After this patchset,
smb2.session.expire1s/1eare passed.Quoted 2 lines · Namjae Jeon
Can you check if smb2.session.expire1s/1e tests are passed after applying these patches ?
Signature · 3 lines
ChenXiaoSong <[email protected]> Chinese Homepage: https://chenxiaosong.com English Homepage: https://chenxiaosong.com/en
Namjae Jeon
maintainerQuoted 6 lines · ChenXiaoSong
After this patchset,
smb2.session.expire1s/1eare passed.Quoted 2 lines · Namjae Jeon
Can you check if smb2.session.expire1s/1e tests are passed after applying these patches ?
I tried to check again, but your patch set isn't applying to #ksmbd-for-next. If you could send the patch again, I will check it.
ChenXiaoSong
reviewerI will send the rebased v4 patchset soon.
Quoted 2 lines · Namjae Jeon
I tried to check again, but your patch set isn't applying to #ksmbd-for-next. If you could send the patch again, I will check it.
Signature · 3 lines
ChenXiaoSong <[email protected]> Chinese Homepage: https://chenxiaosong.com English Homepage: https://chenxiaosong.com/en