[PATCH 4/4] fs: factor out get_fs_pwd_pool_locked() for lock-held callers
From: Christian Brauner
Date: Thu Mar 05 2026 - 16:13:23 EST
Extract the inner pool borrow logic from get_fs_pwd_pool() into
get_fs_pwd_pool_locked() for callers that already hold fs->seq.
Use it in copy_fs_struct() which open-coded the same pool borrow
pattern under an existing lock hold.
Signed-off-by: Christian Brauner <brauner@xxxxxxxxxx>
---
fs/fs_struct.c | 6 +-----
include/linux/fs_struct.h | 16 +++++++++++-----
2 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/fs/fs_struct.c b/fs/fs_struct.c
index 0a72fb3ea427..e1487ca6256d 100644
--- a/fs/fs_struct.c
+++ b/fs/fs_struct.c
@@ -140,11 +140,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
read_seqlock_excl(&old->seq);
fs->root = old->root;
path_get(&fs->root);
- fs->pwd = old->pwd;
- if (old->pwd_refs)
- old->pwd_refs--;
- else
- path_get(&fs->pwd);
+ get_fs_pwd_pool_locked(old, &fs->pwd);
read_sequnlock_excl(&old->seq);
}
return fs;
diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
index e67d92f88605..b63003cec25f 100644
--- a/include/linux/fs_struct.h
+++ b/include/linux/fs_struct.h
@@ -42,6 +42,16 @@ static inline void get_fs_pwd(struct fs_struct *fs, struct path *pwd)
read_sequnlock_excl(&fs->seq);
}
+/* Borrow a pwd reference from the pool. Caller must hold fs->seq. */
+static inline void get_fs_pwd_pool_locked(struct fs_struct *fs, struct path *pwd)
+{
+ *pwd = fs->pwd;
+ if (fs->pwd_refs)
+ fs->pwd_refs--;
+ else
+ path_get(pwd);
+}
+
/*
* Acquire a pwd reference from the pwd_refs pool, if available.
*
@@ -54,11 +64,7 @@ static inline void get_fs_pwd(struct fs_struct *fs, struct path *pwd)
static inline void get_fs_pwd_pool(struct fs_struct *fs, struct path *pwd)
{
read_seqlock_excl(&fs->seq);
- *pwd = fs->pwd;
- if (fs->pwd_refs)
- fs->pwd_refs--;
- else
- path_get(pwd);
+ get_fs_pwd_pool_locked(fs, pwd);
read_sequnlock_excl(&fs->seq);
}
--
2.47.3
--jqlkhartfnby3ev3--