From: ChenXiaoSong <chenxiaosong@chenxiaosong.com>
To: linkinjeon@kernel.org, tom@talpey.com, senozhatsky@chromium.org,
chenxiaosong@chenxiaosong.com
Cc: linux-cifs@vger.kernel.org, ChenXiaoSong <chenxiaosong@kylinos.cn>
Subject: [PATCH 09/12] smb/server: match rename notify events
Date: Sat, 26 Sep 2026 09:05:15 +0000 [thread overview]
Message-ID: <20260926090518.78547-10-chenxiaosong@chenxiaosong.com> (raw)
In-Reply-To: <20260926090518.78547-1-chenxiaosong@chenxiaosong.com>
From: ChenXiaoSong <chenxiaosong@kylinos.cn>
Match old and new rename names by cookie. Save both names as events.
Example:
1. client: smbinfo notify /mnt
2. server: ksmbd.control --debug=notify
3. server: touch /export/file1
4. server: mv /export/file1 /export/file2
server debug log:
ksmbd: fid 5:5, notify event: mask=0x00000040 inode=2 name=file1 cookie=974
ksmbd: Saved moved from, mask 0x40, name file1, cookie 974
ksmbd: fid 5:5, notify event: mask=0x00000080 inode=2 name=file2 cookie=974
ksmbd: Matched rename file1 to file2, cookie 974
ksmbd: Queueing notify event, action 4, name file1
ksmbd: Queueing notify event, action 5, name file2
Signed-off-by: ChenXiaoSong <chenxiaosong@kylinos.cn>
---
fs/smb/server/notify.c | 71 +++++++++++++++++++++++++++++++++++++++---
1 file changed, 67 insertions(+), 4 deletions(-)
diff --git a/fs/smb/server/notify.c b/fs/smb/server/notify.c
index ab1867033f26..6b5312b46e39 100644
--- a/fs/smb/server/notify.c
+++ b/fs/smb/server/notify.c
@@ -236,6 +236,67 @@ static void ksmbd_notify_save_moved_from(struct ksmbd_notify *notify,
msecs_to_jiffies(KSMBD_NOTIFY_MOVED_FROM_MSECS));
}
+static bool
+ksmbd_notify_handle_rename(struct ksmbd_notify *notify, u32 mask,
+ u32 cookie, const struct qstr *file_name)
+{
+ struct ksmbd_notify_event *from, *to;
+ u32 from_mask;
+
+ to = ksmbd_notify_alloc_event(FILE_ACTION_RENAMED_NEW_NAME, file_name,
+ KSMBD_DEFAULT_GFP);
+ if (!to)
+ return false;
+
+ spin_lock(¬ify->lock);
+ if (!notify->moved_from_event ||
+ notify->moved_from_cookie != cookie) {
+ spin_unlock(¬ify->lock);
+ kfree(to);
+ ksmbd_debug(NOTIFY,
+ "No rename source for destination %.*s, cookie %u\n",
+ file_name ? file_name->len : 0,
+ file_name ? (const char *)file_name->name : "",
+ cookie);
+ return false;
+ }
+ from = notify->moved_from_event;
+ from_mask = notify->moved_from_mask;
+ notify->moved_from_event = NULL;
+ notify->moved_from_mask = 0;
+ notify->moved_from_cookie = 0;
+ cancel_delayed_work(¬ify->moved_from_work);
+ spin_unlock(¬ify->lock);
+
+ from->action = FILE_ACTION_RENAMED_OLD_NAME;
+ ksmbd_debug(NOTIFY, "Matched rename %.*s to %.*s, cookie %u\n",
+ (int)from->name_len, from->name,
+ file_name ? file_name->len : 0,
+ file_name ? (const char *)file_name->name : "", cookie);
+
+ if (!ksmbd_notify_filter_match(notify, from_mask)) {
+ ksmbd_debug(NOTIFY, "Filtered rename source %.*s\n",
+ (int)from->name_len, from->name);
+ kfree(from);
+ from = NULL;
+ }
+
+ if (!ksmbd_notify_filter_match(notify, mask)) {
+ ksmbd_debug(NOTIFY, "Filtered rename destination %.*s\n",
+ file_name ? file_name->len : 0,
+ file_name ? (const char *)file_name->name : "");
+ kfree(to);
+ to = NULL;
+ }
+
+ if (from)
+ ksmbd_notify_queue_event(notify, from);
+ if (to)
+ ksmbd_notify_queue_event(notify, to);
+
+ return true;
+}
+
static int ksmbd_notify_handle_inode_event(struct ksmbd_notify *notify,
u32 mask, struct inode *inode,
struct inode *dir,
@@ -266,10 +327,12 @@ static int ksmbd_notify_handle_inode_event(struct ksmbd_notify *notify,
return 0;
}
- if (mask & FS_MOVED_TO)
- return 0;
-
- if (mask & FS_CREATE) {
+ if (mask & FS_MOVED_TO) {
+ if (ksmbd_notify_handle_rename(notify, mask, cookie,
+ file_name))
+ return 0;
+ action = FILE_ACTION_ADDED;
+ } else if (mask & FS_CREATE) {
action = FILE_ACTION_ADDED;
} else if (mask & FS_DELETE) {
action = FILE_ACTION_REMOVED;
--
2.55.0
next prev parent reply other threads:[~2026-09-26 9:07 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-26 9:05 [PATCH 00/12] smb/server: change notify support ChenXiaoSong
2026-09-26 9:05 ` [PATCH 01/12] smb/server: move change notify handling into notify.c ChenXiaoSong
2026-09-26 9:05 ` [PATCH 02/12] smb/server: add more validation for change notify requests ChenXiaoSong
2026-09-26 9:05 ` [PATCH 03/12] smb/server: add debug type for change notify ChenXiaoSong
2026-09-26 9:05 ` [PATCH 04/12] smb/server: support non-recursive directory change watches ChenXiaoSong
2026-09-27 10:51 ` Namjae Jeon
2026-09-28 0:38 ` ChenXiaoSong
2026-09-26 9:05 ` [PATCH 05/12] smb/server: support recursive " ChenXiaoSong
2026-09-26 9:05 ` [PATCH 06/12] smb/server: keep notify watches on file handles ChenXiaoSong
2026-09-26 9:05 ` [PATCH 07/12] smb/server: save simple notify events ChenXiaoSong
2026-09-27 10:31 ` Namjae Jeon
2026-09-28 1:27 ` ChenXiaoSong
2026-09-26 9:05 ` [PATCH 08/12] smb/server: save old names for rename " ChenXiaoSong
2026-09-26 9:05 ` ChenXiaoSong [this message]
2026-09-26 9:05 ` [PATCH 10/12] smb/server: encode " ChenXiaoSong
2026-09-26 9:05 ` [PATCH 11/12] smb/server: send notify events to the client ChenXiaoSong
2026-09-26 9:05 ` [PATCH 12/12] smb/server: break directory leases before sending notify events ChenXiaoSong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260926090518.78547-10-chenxiaosong@chenxiaosong.com \
--to=chenxiaosong@chenxiaosong.com \
--cc=chenxiaosong@kylinos.cn \
--cc=linkinjeon@kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=senozhatsky@chromium.org \
--cc=tom@talpey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox