5.15.154-rc1 review
Subsystems (8)
Greg Kroah-Hartman
maintainerPATCH 215/690 fanotify: introduce group flag FAN_REPORT_TARGET_FID
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit d61fd650e9d206a71fda789f02a1ced4b19944c4 ]
FAN_REPORT_FID is ambiguous in that it reports the fid of the child for some events and the fid of the parent for create/delete/move events.
The new FAN_REPORT_TARGET_FID flag is an implicit request to report the fid of the target object of the operation (a.k.a the child inode) also in create/delete/move events in addition to the fid of the parent and the name of the child.
To reduce the test matrix for uninteresting use cases, the new FAN_REPORT_TARGET_FID flag requires both FAN_REPORT_NAME and FAN_REPORT_FID. The convenience macro FAN_REPORT_DFID_NAME_TARGET combines FAN_REPORT_TARGET_FID with all the required flags.
--- fs/notify/fanotify/fanotify.c | 48 ++++++++++++++++++++++-------- fs/notify/fanotify/fanotify_user.c | 11 ++++++- include/linux/fanotify.h | 2 +- include/uapi/linux/fanotify.h | 4 +++ 4 files changed, 51 insertions(+), 14 deletions(-)
fs/notify/fanotify/fanotify.c +36 -12
@@ -458,17 +458,41 @@ static int fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode, }/* -* The inode to use as identifier when reporting fid depends on the event. -* Report the modified directory inode on dirent modification events. -* Report the "victim" inode otherwise. +* FAN_REPORT_FID is ambiguous in that it reports the fid of the child for +* some events and the fid of the parent for create/delete/move events. +* +* With the FAN_REPORT_TARGET_FID flag, the fid of the child is reported +* also in create/delete/move events in addition to the fid of the parent +* and the name of the child. +*/ +static inline bool fanotify_report_child_fid (unsigned int fid_mode,u32 mask) +{ +if (mask &ALL_FSNOTIFY_DIRENT_EVENTS ) +return (fid_mode &FAN_REPORT_TARGET_FID ); + +return (fid_mode &FAN_REPORT_FID ) && !(mask &FAN_ONDIR ); +} + +/* +* The inode to use as identifier when reporting fid depends on the event +* and the group flags. +* +* With the group flag FAN_REPORT_TARGET_FID, always report the child fid. +* +* Without the group flag FAN_REPORT_TARGET_FID, report the modified directory +* fid on dirent events and the child fid otherwise. +* * For example: -* FS_ATTRIB reports the child inode even if reported on a watched parent. -* FS_CREATE reports the modified dir inode and not the created inode. +* FS_ATTRIB reports the child fid even if reported on a watched parent. +* FS_CREATE reports the modified dir fid without FAN_REPORT_TARGET_FID. +* and reports the created child fid with FAN_REPORT_TARGET_FID. */ static struct inode *fanotify_fid_inode (u32 event_mask,const void *data, -int data_type,struct inode *dir) +int data_type,struct inode *dir, +unsigned int fid_mode) { -if (event_mask &ALL_FSNOTIFY_DIRENT_EVENTS ) +if ((event_mask &ALL_FSNOTIFY_DIRENT_EVENTS ) && + !(fid_mode &FAN_REPORT_TARGET_FID ))return dir;return fsnotify_data_inode (data, data_type);
@@ -647,10 +671,11 @@ static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, {struct fanotify_event *event =NULL ;gfp_t gfp =GFP_KERNEL_ACCOUNT ; -struct inode *id =fanotify_fid_inode (mask, data, data_type, dir); +unsigned int fid_mode =FAN_GROUP_FLAG (group,FANOTIFY_FID_BITS ); +struct inode *id =fanotify_fid_inode (mask, data, data_type, dir, + fid_mode);struct inode *dirid =fanotify_dfid_inode (mask, data, data_type, dir);const struct path *path =fsnotify_data_path (data, data_type); -unsigned int fid_mode =FAN_GROUP_FLAG (group,FANOTIFY_FID_BITS );struct mem_cgroup *old_memcg;struct inode *child =NULL ;bool name_event = false;
@@ -660,11 +685,10 @@ static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group,if ((fid_mode &FAN_REPORT_DIR_FID ) && dirid) {/* -* With both flags FAN_REPORT_DIR_FID and FAN_REPORT_FID, we -* report the child fid for events reported on a non-dir child +* For certain events and group flags, report the child fid * in addition to reporting the parent fid and maybe child name. */ -if ((fid_mode &FAN_REPORT_FID ) && id != dirid && !ondir) +if (fanotify_report_child_fid (fid_mode, mask) && id != dirid) child = id; id = dirid;
fs/notify/fanotify/fanotify_user.c +10 -1
@@ -1275,6 +1275,15 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)if ((fid_mode &FAN_REPORT_NAME ) && !(fid_mode &FAN_REPORT_DIR_FID ))return -EINVAL ; +/* +* FAN_REPORT_TARGET_FID requires FAN_REPORT_NAME and FAN_REPORT_FID +* and is used as an indication to report both dir and child fid on all +* dirent events. +*/ +if ((fid_mode &FAN_REPORT_TARGET_FID ) && + (!(fid_mode &FAN_REPORT_NAME ) || !(fid_mode &FAN_REPORT_FID ))) +return -EINVAL ; + f_flags =O_RDWR |FMODE_NONOTIFY ;if (flags &FAN_CLOEXEC ) f_flags |=O_CLOEXEC ;
@@ -1685,7 +1694,7 @@ static int __init fanotify_user_setup(void) FANOTIFY_DEFAULT_MAX_USER_MARKS);BUILD_BUG_ON (FANOTIFY_INIT_FLAGS &FANOTIFY_INTERNAL_GROUP_FLAGS ); -BUILD_BUG_ON (HWEIGHT32 (FANOTIFY_INIT_FLAGS ) !=11 ); +BUILD_BUG_ON (HWEIGHT32 (FANOTIFY_INIT_FLAGS ) !=12 );BUILD_BUG_ON (HWEIGHT32 (FANOTIFY_MARK_FLAGS ) !=9 ); fanotify_mark_cache = KMEM_CACHE(fsnotify_mark,
include/linux/fanotify.h +1 -1
@@ -25,7 +25,7 @@ extern struct ctl_table fanotify_table[]; /* for sysctl */#define FANOTIFY_CLASS_BITS (FAN_CLASS_NOTIF | FANOTIFY_PERM_CLASSES) -#define FANOTIFY_FID_BITS (FAN_REPORT_FID | FAN_REPORT_DFID_NAME) +#define FANOTIFY_FID_BITS (FAN_REPORT_DFID_NAME_TARGET)#define FANOTIFY_INFO_MODES (FANOTIFY_FID_BITS | FAN_REPORT_PIDFD)
include/uapi/linux/fanotify.h +4 -0
@@ -57,9 +57,13 @@#define FAN_REPORT_FID 0x00000200/* Report unique file id */ #define FAN_REPORT_DIR_FID 0x00000400/* Report unique directory id */ #define FAN_REPORT_NAME 0x00000800/* Report events with name */ +#define FAN_REPORT_TARGET_FID 0x00001000/* Report dirent target id */ /* Convenience macro - FAN_REPORT_NAME requires FAN_REPORT_DIR_FID */ #define FAN_REPORT_DFID_NAME (FAN_REPORT_DIR_FID | FAN_REPORT_NAME) +/* Convenience macro - FAN_REPORT_TARGET_FID requires all other FID flags */ +#define FAN_REPORT_DFID_NAME_TARGET (FAN_REPORT_DFID_NAME | \ + FAN_REPORT_FID | FAN_REPORT_TARGET_FID)/* Deprecated - do not use this in programs and do not add new flags here! */ #define FAN_ALL_INIT_FLAGS (FAN_CLOEXEC | FAN_NONBLOCK | \
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 216/690 fsnotify: generate FS_RENAME event with rich information
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit e54183fa7047c15819bc155f4c58501d9a9a3489 ]
The dnotify FS_DN_RENAME event is used to request notification about a move within the same parent directory and was always coupled with the FS_MOVED_FROM event.
Rename the FS_DN_RENAME event flag to FS_RENAME, decouple it from FS_MOVED_FROM and report it with the moved dentry instead of the moved inode, so it has the information about both old and new parent and name.
Generate the FS_RENAME event regardless of same parent dir and apply the "same parent" rule in the generic fsnotify_handle_event() helper that is used to call backends with ->handle_inode_event() method (i.e. dnotify). The ->handle_inode_event() method is not rich enough to report both old and new parent and name anyway.
The enriched event is reported to fanotify over the ->handle_event() method with the old and new dir inode marks in marks array slots for ITER_TYPE_INODE and a new iter type slot ITER_TYPE_INODE2.
The enriched event will be used for reporting old and new parent+name to fanotify groups with FAN_RENAME events.
--- fs/notify/dnotify/dnotify.c | 2 +- fs/notify/fsnotify.c | 37 +++++++++++++++++++++++++------- include/linux/dnotify.h | 2 +- include/linux/fsnotify.h | 9 +++++--- include/linux/fsnotify_backend.h | 7 +++--- 5 files changed, 41 insertions(+), 16 deletions(-)
fs/notify/dnotify/dnotify.c +1 -1
@@ -196,7 +196,7 @@ static __u32 convert_arg(unsigned long arg)if (arg &DN_ATTRIB ) new_mask |=FS_ATTRIB ;if (arg &DN_RENAME ) - new_mask |=FS_DN_RENAME ; + new_mask |=FS_RENAME ;if (arg &DN_CREATE ) new_mask |= (FS_CREATE |FS_MOVED_TO );
fs/notify/fsnotify.c +29 -8
@@ -279,6 +279,18 @@ static int fsnotify_handle_event(struct fsnotify_group *group, __u32 mask, WARN_ON_ONCE(fsnotify_iter_vfsmount_mark(iter_info)))return 0 ; +/* +* For FS_RENAME, 'dir' is old dir and 'data' is new dentry. +* The only ->handle_inode_event() backend that supports FS_RENAME is +* dnotify, where it means file was renamed within same parent. +*/ +if (mask &FS_RENAME ) { +struct dentry *moved =fsnotify_data_dentry (data, data_type); + +if (dir != moved->d_parent->d_inode) +return 0 ; + } +if (parent_mark) {/* * parent_mark indicates that the parent inode is watching
@@ -469,7 +481,9 @@ int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir,struct super_block *sb =fsnotify_data_sb (data, data_type);struct fsnotify_iter_info iter_info = {};struct mount *mnt =NULL ; -struct inode *parent =NULL ; +struct inode *inode2 =NULL ; +struct dentry *moved; +int inode2_type;int ret =0 ;__u32 test_mask, marks_mask;
@@ -479,12 +493,19 @@ int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir,if (!inode) {/* Dirent event - report on TYPE_INODE to dir */ inode = dir; +/* For FS_RENAME, inode is old_dir and inode2 is new_dir */ +if (mask &FS_RENAME ) { + moved =fsnotify_data_dentry (data, data_type); + inode2 = moved->d_parent->d_inode; + inode2_type =FSNOTIFY_ITER_TYPE_INODE2 ; + } }else if (mask &FS_EVENT_ON_CHILD ) {/* * Event on child - report on TYPE_PARENT to dir if it is * watching children and on TYPE_INODE to child. */ - parent = dir; + inode2 = dir; + inode2_type =FSNOTIFY_ITER_TYPE_PARENT ; }/*
@@ -497,7 +518,7 @@ int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir,if (!sb->s_fsnotify_marks && (!mnt || !mnt->mnt_fsnotify_marks) && (!inode || !inode->i_fsnotify_marks) && - (!parent || !parent->i_fsnotify_marks)) + (!inode2 || !inode2->i_fsnotify_marks))return 0 ; marks_mask = sb->s_fsnotify_mask;
@@ -505,8 +526,8 @@ int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir, marks_mask |= mnt->mnt_fsnotify_mask;if (inode) marks_mask |= inode->i_fsnotify_mask; -if (parent) - marks_mask |= parent->i_fsnotify_mask; +if (inode2) + marks_mask |= inode2->i_fsnotify_mask;/*
@@ -529,9 +550,9 @@ int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir, iter_info.marks[FSNOTIFY_ITER_TYPE_INODE ] =fsnotify_first_mark (&inode->i_fsnotify_marks); } -if (parent) { - iter_info.marks[FSNOTIFY_ITER_TYPE_PARENT ] = -fsnotify_first_mark (&parent->i_fsnotify_marks); +if (inode2) { + iter_info.marks[inode2_type] = +fsnotify_first_mark (&inode2->i_fsnotify_marks); }/*
include/linux/dnotify.h +1 -1
@@ -26,7 +26,7 @@ struct dnotify_struct {FS_MODIFY |FS_MODIFY_CHILD |\FS_ACCESS |FS_ACCESS_CHILD |\FS_ATTRIB |FS_ATTRIB_CHILD |\ -FS_CREATE |FS_DN_RENAME |\ +FS_CREATE |FS_RENAME |\ FS_MOVED_FROM | FS_MOVED_TO) extern int dir_notify_enable;
include/linux/fsnotify.h +6 -3
@@ -144,16 +144,19 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,u32 fs_cookie =fsnotify_get_cookie ();__u32 old_dir_mask =FS_MOVED_FROM ;__u32 new_dir_mask =FS_MOVED_TO ; +__u32 rename_mask =FS_RENAME ;const struct qstr *new_name = &moved->d_name; -if (old_dir == new_dir) - old_dir_mask |=FS_DN_RENAME ; -if (isdir) { old_dir_mask |=FS_ISDIR ; new_dir_mask |=FS_ISDIR ; + rename_mask |=FS_ISDIR ; } +/* Event with information about both old and new parent+name */ +fsnotify_name (rename_mask, moved,FSNOTIFY_EVENT_DENTRY , + old_dir, old_name,0 ); +fsnotify_name (old_dir_mask, source,FSNOTIFY_EVENT_INODE , old_dir, old_name, fs_cookie); fsnotify_name(new_dir_mask, source, FSNOTIFY_EVENT_INODE,
include/linux/fsnotify_backend.h +4 -3
@@ -63,7 +63,7 @@*/ #define FS_EVENT_ON_CHILD 0x08000000 -#define FS_DN_RENAME 0x10000000/* file renamed */ +#define FS_RENAME 0x10000000/* File was renamed */ #define FS_DN_MULTISHOT 0x20000000/* dnotify multishot */ #define FS_ISDIR 0x40000000/* event occurred against dir */ #define FS_IN_ONESHOT 0x80000000/* only send event once */
@@ -76,7 +76,7 @@* The watching parent may get an FS_ATTRIB|FS_EVENT_ON_CHILD event * when a directory entry inside a child subdir changes. */ -#define ALL_FSNOTIFY_DIRENT_EVENTS (FS_CREATE | FS_DELETE | FS_MOVE) +#define ALL_FSNOTIFY_DIRENT_EVENTS (FS_CREATE | FS_DELETE | FS_MOVE | FS_RENAME)#define ALL_FSNOTIFY_PERM_EVENTS (FS_OPEN_PERM | FS_ACCESS_PERM | \ FS_OPEN_EXEC_PERM)
@@ -101,7 +101,7 @@/* Events that can be reported to backends */ #define ALL_FSNOTIFY_EVENTS (ALL_FSNOTIFY_DIRENT_EVENTS | \ FS_EVENTS_POSS_ON_CHILD | \ - FS_DELETE_SELF | FS_MOVE_SELF | FS_DN_RENAME | \ + FS_DELETE_SELF | FS_MOVE_SELF | \ FS_UNMOUNT | FS_Q_OVERFLOW | FS_IN_IGNORED | \ FS_ERROR)
@@ -349,6 +349,7 @@ enum fsnotify_iter_type {FSNOTIFY_ITER_TYPE_VFSMOUNT ,FSNOTIFY_ITER_TYPE_SB ,FSNOTIFY_ITER_TYPE_PARENT , +FSNOTIFY_ITER_TYPE_INODE2 , FSNOTIFY_ITER_TYPE_COUNT };
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 217/690 fanotify: use macros to get the offset to fanotify_info buffer
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit 2d9374f095136206a02eb0b6cd9ef94632c1e9f7 ]
The fanotify_info buffer contains up to two file handles and a name. Use macros to simplify the code that access the different items within the buffer.
Add assertions to verify that stored fh len and name len do not overflow the u8 stored value in fanotify_info header.
Remove the unused fanotify_info_len() helper.
--- fs/notify/fanotify/fanotify.c | 2 +- fs/notify/fanotify/fanotify.h | 41 +++++++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 12 deletions(-)
fs/notify/fanotify/fanotify.c +1 -1
@@ -411,7 +411,7 @@ static int fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode,* be zero in that case if encoding fh len failed. */ err = -ENOENT ; -if (fh_len <4 ||WARN_ON_ONCE (fh_len %4 )) +if (fh_len <4 ||WARN_ON_ONCE (fh_len %4 ) || fh_len >MAX_HANDLE_SZ ) goto out_err;/* No external buffer in a variable size allocated fh */
fs/notify/fanotify/fanotify.h +30 -11
75 lines not on this page · raw message
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 218/690 fanotify: use helpers to parcel fanotify_info buffer
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit 1a9515ac9e55e68d733bab81bd408463ab1e25b1 ]
fanotify_info buffer is parceled into variable sized records, so the records must be written in order: dir_fh, file_fh, name.
Use helpers to assert that order and make fanotify_alloc_name_event() a bit more generic to allow empty dir_fh record and to allow expanding to more records (i.e. name2) soon.
--- fs/notify/fanotify/fanotify.c | 35 +++++++++++++++++++---------------- fs/notify/fanotify/fanotify.h | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+), 16 deletions(-)
fs/notify/fanotify/fanotify.c +19 -16
@@ -576,7 +576,7 @@ static struct fanotify_event *fanotify_alloc_fid_event(struct inode *id,return &ffe->fae; } -static struct fanotify_event *fanotify_alloc_name_event(struct inode *id, +static struct fanotify_event *fanotify_alloc_name_event(struct inode *dir, __kernel_fsid_t *fsid, const struct qstr *name, struct inode *child,
@@ -586,15 +586,17 @@ static struct fanotify_event *fanotify_alloc_name_event(struct inode *id,struct fanotify_name_event *fne;struct fanotify_info *info;struct fanotify_fh *dfh, *ffh; -unsigned int dir_fh_len =fanotify_encode_fh_len (id); +unsigned int dir_fh_len =fanotify_encode_fh_len (dir);unsigned int child_fh_len =fanotify_encode_fh_len (child); -unsigned int size; +unsigned long name_len = name ? name->len :0 ; +unsigned int len, size; - size =sizeof (*fne) +FANOTIFY_FH_HDR_LEN + dir_fh_len; +/* Reserve terminating null byte even for empty name */ + size =sizeof (*fne) + name_len +1 ; +if (dir_fh_len) + size +=FANOTIFY_FH_HDR_LEN + dir_fh_len;if (child_fh_len) size +=FANOTIFY_FH_HDR_LEN + child_fh_len; -if (name) - size += name->len +1 ; fne =kmalloc (size, gfp);if (!fne)return NULL ;
@@ -604,22 +606,23 @@ static struct fanotify_event *fanotify_alloc_name_event(struct inode *id, *hash ^=fanotify_hash_fsid (fsid); info = &fne->info;fanotify_info_init (info); - dfh =fanotify_info_dir_fh (info); - info->dir_fh_totlen =fanotify_encode_fh (dfh, id, dir_fh_len, hash,0 ); +if (dir_fh_len) { + dfh =fanotify_info_dir_fh (info); + len =fanotify_encode_fh (dfh, dir, dir_fh_len, hash,0 ); +fanotify_info_set_dir_fh (info, len); + }if (child_fh_len) { ffh =fanotify_info_file_fh (info); - info->file_fh_totlen =fanotify_encode_fh (ffh, child, - child_fh_len, hash,0 ); + len =fanotify_encode_fh (ffh, child, child_fh_len, hash,0 ); +fanotify_info_set_file_fh (info, len); } -if (name) { -long salt = name->len; - +if (name_len) {fanotify_info_copy_name (info, name); - *hash ^=full_name_hash ((void *)salt, name->name, name->len); + *hash ^=full_name_hash ((void *)name_len, name->name, name_len); } -pr_debug ("%s: ino=%lu size=%u dir_fh_len=%u child_fh_len=%u name_len=%u name='%.*s'\n" , - __func__, id->i_ino, size, dir_fh_len, child_fh_len, +pr_debug ("%s: size=%u dir_fh_len=%u child_fh_len=%u name_len=%u name='%.*s'\n" , + __func__, size, dir_fh_len, child_fh_len, info->name_len, info->name_len,fanotify_info_name (info));return &fne->fae;
fs/notify/fanotify/fanotify.h +20 -0
@@ -138,6 +138,26 @@ static inline void fanotify_info_init(struct fanotify_info *info) info->name_len =0 ; } +/* These set/copy helpers MUST be called by order */ +static inline void fanotify_info_set_dir_fh (struct fanotify_info *info, +unsigned int totlen) +{ +if (WARN_ON_ONCE (info->file_fh_totlen >0 ) || +WARN_ON_ONCE (info->name_len >0 )) +return ; + + info->dir_fh_totlen = totlen; +} + +static inline void fanotify_info_set_file_fh (struct fanotify_info *info, +unsigned int totlen) +{ +if (WARN_ON_ONCE (info->name_len >0 )) +return ; + + info->file_fh_totlen = totlen; +} +static inline void fanotify_info_copy_name (struct fanotify_info *info,const struct qstr *name) {
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 219/690 fanotify: support secondary dir fh and name in fanotify_info
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit 3cf984e950c1c3f41d407ed31db33beb996be132 ]
Allow storing a secondary dir fh and name tupple in fanotify_info. This will be used to store the new parent and name information in FAN_RENAME event.
--- fs/notify/fanotify/fanotify.c | 20 ++++++-- fs/notify/fanotify/fanotify.h | 79 +++++++++++++++++++++++++++--- fs/notify/fanotify/fanotify_user.c | 3 +- 3 files changed, 88 insertions(+), 14 deletions(-)
fs/notify/fanotify/fanotify.c +16 -4
@@ -76,8 +76,10 @@ static bool fanotify_info_equal(struct fanotify_info *info1, struct fanotify_info *info2) {if (info1->dir_fh_totlen != info2->dir_fh_totlen || + info1->dir2_fh_totlen != info2->dir2_fh_totlen || info1->file_fh_totlen != info2->file_fh_totlen || - info1->name_len != info2->name_len) + info1->name_len != info2->name_len || + info1->name2_len != info2->name2_len)return false; if (info1->dir_fh_totlen &&
@@ -85,14 +87,24 @@ static bool fanotify_info_equal(struct fanotify_info *info1, fanotify_info_dir_fh(info2)))return false; +if (info1->dir2_fh_totlen && + !fanotify_fh_equal (fanotify_info_dir2_fh (info1), +fanotify_info_dir2_fh (info2))) +return false; +if (info1->file_fh_totlen && !fanotify_fh_equal (fanotify_info_file_fh (info1),fanotify_info_file_fh (info2)))return false; -return !info1->name_len || - !memcmp (fanotify_info_name (info1),fanotify_info_name (info2), - info1->name_len); +if (info1->name_len && +memcmp (fanotify_info_name (info1),fanotify_info_name (info2), + info1->name_len)) +return false; + +return !info1->name2_len || + !memcmp (fanotify_info_name2 (info1),fanotify_info_name2 (info2), + info1->name2_len); } static bool fanotify_name_event_equal(struct fanotify_name_event *fne1,
fs/notify/fanotify/fanotify.h +71 -8
152 lines not on this page · raw message
fs/notify/fanotify/fanotify_user.c +1 -2
@@ -332,11 +332,10 @@ static int process_access_response(struct fsnotify_group *group,static size_t copy_error_info_to_user (struct fanotify_event *event,char __user *buf,int count) { -struct fanotify_event_info_error info; +struct fanotify_event_info_error info = { };struct fanotify_error_event *fee =FANOTIFY_EE (event); info.hdr.info_type =FAN_EVENT_INFO_TYPE_ERROR ; - info.hdr.pad =0 ; info.hdr.len =FANOTIFY_ERROR_INFO_LEN ;if (WARN_ON (count < info.hdr.len))
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 220/690 fanotify: record old and new parent and name in FAN_RENAME event
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit 3982534ba5ce45e890b2f5ef5e7372c1accd14c7 ]
In the special case of FAN_RENAME event, we record both the old and new parent and name.
--- fs/notify/fanotify/fanotify.c | 42 +++++++++++++++++++++++++++++++---- include/uapi/linux/fanotify.h | 2 ++ 2 files changed, 40 insertions(+), 4 deletions(-)
fs/notify/fanotify/fanotify.c +38 -4
@@ -592,21 +592,28 @@ static struct fanotify_event *fanotify_alloc_name_event(struct inode *dir,__kernel_fsid_t *fsid, const struct qstr *name, struct inode *child, + struct dentry *moved, unsigned int *hash, gfp_t gfp) { struct fanotify_name_event *fne;struct fanotify_info *info;struct fanotify_fh *dfh, *ffh; +struct inode *dir2 = moved ?d_inode (moved->d_parent) :NULL ; +const struct qstr *name2 = moved ? &moved->d_name :NULL ;unsigned int dir_fh_len =fanotify_encode_fh_len (dir); +unsigned int dir2_fh_len =fanotify_encode_fh_len (dir2);unsigned int child_fh_len =fanotify_encode_fh_len (child);unsigned long name_len = name ? name->len :0 ; +unsigned long name2_len = name2 ? name2->len :0 ;unsigned int len, size;/* Reserve terminating null byte even for empty name */ - size =sizeof (*fne) + name_len +1 ; + size =sizeof (*fne) + name_len + name2_len +2 ;if (dir_fh_len) size +=FANOTIFY_FH_HDR_LEN + dir_fh_len; +if (dir2_fh_len) + size +=FANOTIFY_FH_HDR_LEN + dir2_fh_len;if (child_fh_len) size +=FANOTIFY_FH_HDR_LEN + child_fh_len; fne =kmalloc (size, gfp);
@@ -623,6 +630,11 @@ static struct fanotify_event *fanotify_alloc_name_event(struct inode *dir, len =fanotify_encode_fh (dfh, dir, dir_fh_len, hash,0 );fanotify_info_set_dir_fh (info, len); } +if (dir2_fh_len) { + dfh =fanotify_info_dir2_fh (info); + len =fanotify_encode_fh (dfh, dir2, dir2_fh_len, hash,0 ); +fanotify_info_set_dir2_fh (info, len); + }if (child_fh_len) { ffh =fanotify_info_file_fh (info); len =fanotify_encode_fh (ffh, child, child_fh_len, hash,0 );
@@ -632,11 +644,22 @@ static struct fanotify_event *fanotify_alloc_name_event(struct inode *dir,fanotify_info_copy_name (info, name); *hash ^=full_name_hash ((void *)name_len, name->name, name_len); } +if (name2_len) { +fanotify_info_copy_name2 (info, name2); + *hash ^=full_name_hash ((void *)name2_len, name2->name, + name2_len); + }pr_debug ("%s: size=%u dir_fh_len=%u child_fh_len=%u name_len=%u name='%.*s'\n" , __func__, size, dir_fh_len, child_fh_len, info->name_len, info->name_len,fanotify_info_name (info)); +if (dir2_fh_len) { +pr_debug ("%s: dir2_fh_len=%u name2_len=%u name2='%.*s'\n" , + __func__, dir2_fh_len, info->name2_len, + info->name2_len,fanotify_info_name2 (info)); + } +return &fne->fae; }
@@ -692,6 +715,7 @@ static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group,struct inode *dirid =fanotify_dfid_inode (mask, data, data_type, dir);const struct path *path =fsnotify_data_path (data, data_type);struct mem_cgroup *old_memcg; +struct dentry *moved =NULL ;struct inode *child =NULL ;bool name_event = false;unsigned int hash =0 ;
@@ -727,6 +751,15 @@ static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, }else if ((mask &ALL_FSNOTIFY_DIRENT_EVENTS ) || !ondir) { name_event = true; } + +/* +* In the special case of FAN_RENAME event, we record both +* old and new parent+name. +* 'dirid' and 'file_name' are the old parent+name and +* 'moved' has the new parent+name. +*/ +if (mask &FAN_RENAME ) + moved =fsnotify_data_dentry (data, data_type); }/*
@@ -748,9 +781,9 @@ static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, }else if (fanotify_is_error_event (mask)) { event =fanotify_alloc_error_event (group, fsid, data, data_type, &hash); - }else if (name_event && (file_name || child)) { - event =fanotify_alloc_name_event (id, fsid, file_name, child, - &hash, gfp); + }else if (name_event && (file_name || moved || child)) { + event =fanotify_alloc_name_event (dirid, fsid, file_name, child, + moved, &hash, gfp); }else if (fid_mode) { event =fanotify_alloc_fid_event (id, fsid, &hash, gfp); }else {
@@ -860,6 +893,7 @@ static int fanotify_handle_event(struct fsnotify_group *group, u32 mask,BUILD_BUG_ON (FAN_OPEN_EXEC !=FS_OPEN_EXEC );BUILD_BUG_ON (FAN_OPEN_EXEC_PERM !=FS_OPEN_EXEC_PERM );BUILD_BUG_ON (FAN_FS_ERROR !=FS_ERROR ); +BUILD_BUG_ON (FAN_RENAME !=FS_RENAME );BUILD_BUG_ON (HWEIGHT32 (ALL_FANOTIFY_EVENT_BITS ) !=20 );
include/uapi/linux/fanotify.h +2 -0
@@ -28,6 +28,8 @@#define FAN_EVENT_ON_CHILD 0x08000000/* Interested in child events */ +#define FAN_RENAME 0x10000000/* File was renamed */ +#define FAN_ONDIR 0x40000000/* Event occurred against dir */ /* helper events */
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 221/690 fanotify: record either old name new name or both for FAN_RENAME
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit 2bfbcccde6e7a787feabad4645f628f963fe0663 ]
We do not want to report the dirfid+name of a directory whose inode/sb are not watched, because watcher may not have permissions to see the directory content.
Use an internal iter_info to indicate to fanotify_alloc_event() which marks of this group are watching FAN_RENAME, so it can decide if we need to record only the old parent+name, new parent+name or both.
[JK: Modified code to pass around only mask of mark types matching generated event]
--- fs/notify/fanotify/fanotify.c | 59 ++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 15 deletions(-)
fs/notify/fanotify/fanotify.c +44 -15
@@ -284,8 +284,9 @@ static int fanotify_get_response(struct fsnotify_group *group,*/ static u32 fanotify_group_event_mask (struct fsnotify_group *group,struct fsnotify_iter_info *iter_info, -u32 event_mask,const void *data, -int data_type,struct inode *dir) +u32 *match_mask,u32 event_mask, +const void *data,int data_type, +struct inode *dir) {__u32 marks_mask =0 , marks_ignored_mask =0 ; __u32 test_mask, user_mask = FANOTIFY_OUTGOING_EVENTS |
@@ -335,6 +336,9 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group,continue ; marks_mask |= mark->mask; + +/* Record the mark types of this group that matched the event */ + *match_mask |=1U << type; } test_mask = event_mask & marks_mask & ~marks_ignored_mask;
@@ -701,11 +705,11 @@ static struct fanotify_event *fanotify_alloc_error_event(return &fee->fae; } -static struct fanotify_event *fanotify_alloc_event (struct fsnotify_group *group, -u32 mask,const void *data, -int data_type,struct inode *dir, -const struct qstr *file_name, -__kernel_fsid_t *fsid) +static struct fanotify_event *fanotify_alloc_event ( +struct fsnotify_group *group, +u32 mask,const void *data,int data_type, +struct inode *dir,const struct qstr *file_name, +__kernel_fsid_t *fsid,u32 match_mask) {struct fanotify_event *event =NULL ;gfp_t gfp =GFP_KERNEL_ACCOUNT ;
@@ -753,13 +757,36 @@ static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, }/* -* In the special case of FAN_RENAME event, we record both -* old and new parent+name. +* In the special case of FAN_RENAME event, use the match_mask +* to determine if we need to report only the old parent+name, +* only the new parent+name or both. * 'dirid' and 'file_name' are the old parent+name and * 'moved' has the new parent+name. */ -if (mask &FAN_RENAME ) - moved =fsnotify_data_dentry (data, data_type); +if (mask &FAN_RENAME ) { +bool report_old, report_new; + +if (WARN_ON_ONCE (!match_mask)) +return NULL ; + +/* Report both old and new parent+name if sb watching */ + report_old = report_new = + match_mask & (1U <<FSNOTIFY_ITER_TYPE_SB ); + report_old |= + match_mask & (1U <<FSNOTIFY_ITER_TYPE_INODE ); + report_new |= + match_mask & (1U <<FSNOTIFY_ITER_TYPE_INODE2 ); + +if (!report_old) { +/* Do not report old parent+name */ + dirid =NULL ; + file_name =NULL ; + } +if (report_new) { +/* Report new parent+name */ + moved =fsnotify_data_dentry (data, data_type); + } + } }/*
@@ -872,6 +899,7 @@ static int fanotify_handle_event(struct fsnotify_group *group, u32 mask,struct fanotify_event *event;struct fsnotify_event *fsn_event;__kernel_fsid_t fsid = {}; +u32 match_mask =0 ;BUILD_BUG_ON (FAN_ACCESS !=FS_ACCESS );BUILD_BUG_ON (FAN_MODIFY !=FS_MODIFY );
@@ -897,12 +925,13 @@ static int fanotify_handle_event(struct fsnotify_group *group, u32 mask,BUILD_BUG_ON (HWEIGHT32 (ALL_FANOTIFY_EVENT_BITS ) !=20 ); - mask =fanotify_group_event_mask (group, iter_info, mask, data, - data_type, dir); + mask =fanotify_group_event_mask (group, iter_info, &match_mask, + mask, data, data_type, dir);if (!mask)return 0 ; -pr_debug ("%s: group=%p mask=%x\n" , __func__, group, mask); +pr_debug ("%s: group=%p mask=%x report_mask=%x\n" , __func__, + group, mask, match_mask);if (fanotify_is_perm_event (mask)) {/*
@@ -921,7 +950,7 @@ static int fanotify_handle_event(struct fsnotify_group *group, u32 mask, } event =fanotify_alloc_event (group, mask, data, data_type, dir, - file_name, &fsid); + file_name, &fsid, match_mask); ret = -ENOMEM ;if (unlikely (!event)) {/*
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 222/690 fanotify: report old and/or new parent+name in FAN_RENAME event
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit 7326e382c21e9c23c89c88369afdc90b82a14da8 ]
In the special case of FAN_RENAME event, we report old or new or both old and new parent+name.
A single info record will be reported if either the old or new dir is watched and two records will be reported if both old and new dir (or their filesystem) are watched.
The old and new parent+name are reported using new info record types FAN_EVENT_INFO_TYPE_{OLD,NEW}_DFID_NAME, so if a single info record is reported, it is clear to the application, to which dir entry the fid+name info is referring to.
--- fs/notify/fanotify/fanotify.c | 7 ++++ fs/notify/fanotify/fanotify.h | 18 +++++++++++ fs/notify/fanotify/fanotify_user.c | 52 +++++++++++++++++++++++++++--- include/uapi/linux/fanotify.h | 6 ++++ 4 files changed, 78 insertions(+), 5 deletions(-)
fs/notify/fanotify/fanotify.c +7 -0
@@ -153,6 +153,13 @@ static bool fanotify_should_merge(struct fanotify_event *old,if ((old->mask &FS_ISDIR ) != (new->mask &FS_ISDIR ))return false; +/* +* FAN_RENAME event is reported with special info record types, +* so we cannot merge it with other events. +*/ +if ((old->mask &FAN_RENAME ) != (new->mask &FAN_RENAME )) +return false; +switch (old->type) {case FANOTIFY_EVENT_TYPE_PATH : return fanotify_path_equal(fanotify_event_path(old),
fs/notify/fanotify/fanotify.h +18 -0
@@ -373,6 +373,13 @@ static inline int fanotify_event_dir_fh_len(struct fanotify_event *event)return info ?fanotify_info_dir_fh_len (info) :0 ; } +static inline int fanotify_event_dir2_fh_len (struct fanotify_event *event) +{ +struct fanotify_info *info =fanotify_event_info (event); + +return info ?fanotify_info_dir2_fh_len (info) :0 ; +} +static inline bool fanotify_event_has_object_fh (struct fanotify_event *event) {/* For error events, even zeroed fh are reported. */
@@ -386,6 +393,17 @@ static inline bool fanotify_event_has_dir_fh(struct fanotify_event *event)return fanotify_event_dir_fh_len (event) >0 ; } +static inline bool fanotify_event_has_dir2_fh (struct fanotify_event *event) +{ +return fanotify_event_dir2_fh_len (event) >0 ; +} + +static inline bool fanotify_event_has_any_dir_fh (struct fanotify_event *event) +{ +return fanotify_event_has_dir_fh (event) || +fanotify_event_has_dir2_fh (event); +} +struct fanotify_path_event {struct fanotify_event fae;struct path path;
fs/notify/fanotify/fanotify_user.c +47 -5
91 lines not on this page · raw message
include/uapi/linux/fanotify.h +6 -0
@@ -134,6 +134,12 @@ struct fanotify_event_metadata {#define FAN_EVENT_INFO_TYPE_PIDFD 4#define FAN_EVENT_INFO_TYPE_ERROR 5 +/* Special info types for FAN_RENAME */ +#define FAN_EVENT_INFO_TYPE_OLD_DFID_NAME 10 +/* Reserved for FAN_EVENT_INFO_TYPE_OLD_DFID 11 */ +#define FAN_EVENT_INFO_TYPE_NEW_DFID_NAME 12 +/* Reserved for FAN_EVENT_INFO_TYPE_NEW_DFID 13 */ +/* Variable length info record following event metadata */ struct fanotify_event_info_header {__u8 info_type;
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 223/690 fanotify: wire up FAN_RENAME event
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit 8cc3b1ccd930fe6971e1527f0c4f1bdc8cb56026 ]
FAN_RENAME is the successor of FAN_MOVED_FROM and FAN_MOVED_TO and can be used to get the old and new parent+name information in a single event.
FAN_MOVED_FROM and FAN_MOVED_TO are still supported for backward compatibility, but it makes little sense to use them together with FAN_RENAME in the same group.
FAN_RENAME uses special info type records to report the old and new parent+name, so reporting only old and new parent id is less useful and was not implemented.
Therefore, FAN_REANAME requires a group with flag FAN_REPORT_NAME.
--- fs/notify/fanotify/fanotify.c | 2 +- fs/notify/fanotify/fanotify_user.c | 8 ++++++++ include/linux/fanotify.h | 3 ++- 3 files changed, 11 insertions(+), 2 deletions(-)
fs/notify/fanotify/fanotify.c +1 -1
@@ -930,7 +930,7 @@ static int fanotify_handle_event(struct fsnotify_group *group, u32 mask,BUILD_BUG_ON (FAN_FS_ERROR !=FS_ERROR );BUILD_BUG_ON (FAN_RENAME !=FS_RENAME ); -BUILD_BUG_ON (HWEIGHT32 (ALL_FANOTIFY_EVENT_BITS ) !=20 ); +BUILD_BUG_ON (HWEIGHT32 (ALL_FANOTIFY_EVENT_BITS ) !=21 ); mask =fanotify_group_event_mask (group, iter_info, &match_mask, mask, data, data_type, dir);
fs/notify/fanotify/fanotify_user.c +8 -0
@@ -1604,6 +1604,14 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, (!fid_mode || mark_type == FAN_MARK_MOUNT)) goto fput_and_out; +/* +* FAN_RENAME uses special info type records to report the old and +* new parent+name. Reporting only old and new parent id is less +* useful and was not implemented. +*/ +if (mask &FAN_RENAME && !(fid_mode &FAN_REPORT_NAME )) + goto fput_and_out; +if (flags &FAN_MARK_FLUSH ) { ret =0 ;if (mark_type ==FAN_MARK_MOUNT )
include/linux/fanotify.h +2 -1
@@ -82,7 +82,8 @@ extern struct ctl_table fanotify_table[]; /* for sysctl */* Directory entry modification events - reported only to directory * where entry is modified and not to a watching parent. */ -#define FANOTIFY_DIRENT_EVENTS (FAN_MOVE | FAN_CREATE | FAN_DELETE) +#define FANOTIFY_DIRENT_EVENTS (FAN_MOVE | FAN_CREATE | FAN_DELETE | \ + FAN_RENAME)/* Events that can be reported with event->fd */ #define FANOTIFY_FD_EVENTS (FANOTIFY_PATH_EVENTS | FANOTIFY_PERM_EVENTS)
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 224/690 exit: Implement kthread_exit
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric W. Biederman <[email protected]>
[ Upstream commit bbda86e988d4c124e4cfa816291cbd583ae8bfb1 ]
The way the per task_struct exit_code is used by kernel threads is not quite compatible how it is used by userspace applications. The low byte of the userspace exit_code value encodes the exit signal. While kthreads just use the value as an int holding ordinary kernel function exit status like -EPERM.
Add kthread_exit to clearly separate the two kinds of uses.
Stable-dep-of: ca3574bd653a ("exit: Rename module_put_and_exit to module_put_and_kthread_exit")
--- include/linux/kthread.h | 1 + kernel/kthread.c | 23 +++++++++++++++++++---- tools/objtool/check.c | 1 + 3 files changed, 21 insertions(+), 4 deletions(-)
include/linux/kthread.h +1 -0
@@ -95,6 +95,7 @@ void *kthread_probe_data(struct task_struct *k);int kthread_park (struct task_struct *k);void kthread_unpark (struct task_struct *k);void kthread_parkme (void ); +void kthread_exit (long result)__noreturn ;int kthreadd (void *unused);extern struct task_struct *kthreadd_task;
kernel/kthread.c +19 -4
@@ -268,6 +268,21 @@ void kthread_parkme(void) }EXPORT_SYMBOL_GPL (kthread_parkme); +/** +* kthread_exit - Cause the current kthread return @result to kthread_stop(). +* @result: The integer value to return to kthread_stop(). +* +* While kthread_exit can be called directly, it exists so that +* functions which do some additional work in non-modular code such as +* module_put_and_kthread_exit can be implemented. +* +* Does not return. +*/ +void __noreturn kthread_exit (long result) +{ +do_exit (result); +} +static int kthread (void *_create) {/* Copy data: it's on kthread's stack */
@@ -285,13 +300,13 @@ static int kthread(void *_create) done =xchg (&create->done,NULL );if (!done) {kfree (create); -do_exit (-EINTR ); +kthread_exit (-EINTR ); }if (!self) { create->result =ERR_PTR (-ENOMEM );complete (done); -do_exit (-ENOMEM ); +kthread_exit (-ENOMEM ); } self->threadfn = threadfn;
@@ -318,7 +333,7 @@ static int kthread(void *_create)__kthread_parkme (self); ret =threadfn (data); } -do_exit (ret); +kthread_exit (ret); }/* called from kernel_clone() to get node information for about to be created task */
@@ -628,7 +643,7 @@ EXPORT_SYMBOL_GPL(kthread_park);* instead of calling wake_up_process(): the thread will exit without * calling threadfn(). * -* If threadfn() may call do_exit() itself, the caller must ensure +* If threadfn() may call kthread_exit() itself, the caller must ensure * task_struct can't go away. * * Returns the result of threadfn(), or %-EINTR if wake_up_process()
tools/objtool/check.c +1 -0
@@ -169,6 +169,7 @@ static bool __dead_end_function(struct objtool_file *file, struct symbol *func,"panic" ,"do_exit" ,"do_task_dead" , +"kthread_exit" ,"make_task_dead" ,"__module_put_and_exit" , "complete_and_exit",
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 225/690 exit: Rename module_put_and_exit to module_put_and_kthread_exit
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric W. Biederman <[email protected]>
[ Upstream commit ca3574bd653aba234a4b31955f2778947403be16 ]
Update module_put_and_exit to call kthread_exit instead of do_exit.
Change the name to reflect this change in functionality. All of the users of module_put_and_exit are causing the current kthread to exit so this change makes it clear what is happening. There is no functional change.
--- crypto/algboss.c | 4 ++-- fs/cifs/connect.c | 2 +- fs/nfs/callback.c | 4 ++-- fs/nfs/nfs4state.c | 2 +- fs/nfsd/nfssvc.c | 2 +- include/linux/module.h | 6 +++--- kernel/module.c | 6 +++--- net/bluetooth/bnep/core.c | 2 +- net/bluetooth/cmtp/core.c | 2 +- net/bluetooth/hidp/core.c | 2 +- tools/objtool/check.c | 2 +- 11 files changed, 17 insertions(+), 17 deletions(-)
crypto/algboss.c +2 -2
@@ -67,7 +67,7 @@ static int cryptomgr_probe(void *data)complete_all (¶m->larval->completion);crypto_alg_put (¶m->larval->alg);kfree (param); -module_put_and_exit (0 ); +module_put_and_kthread_exit (0 ); }static int cryptomgr_schedule_probe (struct crypto_larval *larval)
@@ -190,7 +190,7 @@ static int cryptomgr_test(void *data)crypto_alg_tested (param->driver, err);kfree (param); -module_put_and_exit (0 ); +module_put_and_kthread_exit (0 ); }static int cryptomgr_schedule_test (struct crypto_alg *alg)
fs/cifs/connect.c +1 -1
@@ -1145,7 +1145,7 @@ cifs_demultiplex_thread(void *p) }memalloc_noreclaim_restore (noreclaim_flag); -module_put_and_exit (0 ); +module_put_and_kthread_exit (0 ); }/*
fs/nfs/callback.c +2 -2
@@ -93,7 +93,7 @@ nfs4_callback_svc(void *vrqstp)svc_process (rqstp); }svc_exit_thread (rqstp); -module_put_and_exit (0 ); +module_put_and_kthread_exit (0 );return 0 ; }
@@ -137,7 +137,7 @@ nfs41_callback_svc(void *vrqstp) } }svc_exit_thread (rqstp); -module_put_and_exit (0 ); +module_put_and_kthread_exit (0 );return 0 ; }
fs/nfs/nfs4state.c +1 -1
@@ -2766,6 +2766,6 @@ static int nfs4_run_state_manager(void *ptr) goto again;nfs_put_client (clp); -module_put_and_exit (0 ); +module_put_and_kthread_exit (0 );return 0 ; }
fs/nfsd/nfssvc.c +1 -1
@@ -986,7 +986,7 @@ nfsd(void *vrqstp)/* Release module */ mutex_unlock (&nfsd_mutex); -module_put_and_exit (0 ); +module_put_and_kthread_exit (0 );return 0 ; }
include/linux/module.h +3 -3
@@ -595,9 +595,9 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,/* Look for this name: can be of form module:name. */ unsigned long module_kallsyms_lookup_name (const char *name); -extern void __noreturn __module_put_and_exit (struct module *mod, +extern void __noreturn __module_put_and_kthread_exit (struct module *mod,long code); -#define module_put_and_exit (code) __module_put_and_exit(THIS_MODULE, code) +#define module_put_and_kthread_exit (code) __module_put_and_kthread_exit(THIS_MODULE, code)#ifdef CONFIG_MODULE_UNLOAD int module_refcount (struct module *mod);
@@ -790,7 +790,7 @@ static inline int unregister_module_notifier(struct notifier_block *nb)return 0 ; } -#define module_put_and_exit (code) do_exit(code) +#define module_put_and_kthread_exit (code) kthread_exit(code)static inline void print_modules (void ) {
kernel/module.c +3 -3
@@ -337,12 +337,12 @@ static inline void add_taint_module(struct module *mod, unsigned flag,* A thread that wants to hold a reference to a module only while it * is running can call this to safely exit. nfsd and lockd use this. */ -void __noreturn __module_put_and_exit (struct module *mod,long code) +void __noreturn __module_put_and_kthread_exit (struct module *mod,long code) {module_put (mod); -do_exit (code); +kthread_exit (code); } -EXPORT_SYMBOL (__module_put_and_exit); +EXPORT_SYMBOL (__module_put_and_kthread_exit);/* Find a module section: 0 means not found. */ static unsigned int find_sec (const struct load_info *info,const char *name)
net/bluetooth/bnep/core.c +1 -1
@@ -535,7 +535,7 @@ static int bnep_session(void *arg)up_write (&bnep_session_sem);free_netdev (dev); -module_put_and_exit (0 ); +module_put_and_kthread_exit (0 );return 0 ; }
net/bluetooth/cmtp/core.c +1 -1
@@ -323,7 +323,7 @@ static int cmtp_session(void *arg)up_write (&cmtp_session_sem);kfree (session); -module_put_and_exit (0 ); +module_put_and_kthread_exit (0 );return 0 ; }
net/bluetooth/hidp/core.c +1 -1
@@ -1305,7 +1305,7 @@ static int hidp_session_thread(void *arg)l2cap_unregister_user (session->conn, &session->user);hidp_session_put (session); -module_put_and_exit (0 ); +module_put_and_kthread_exit (0 );return 0 ; }
tools/objtool/check.c +1 -1
@@ -171,7 +171,7 @@ static bool __dead_end_function(struct objtool_file *file, struct symbol *func,"do_task_dead" ,"kthread_exit" ,"make_task_dead" , -"__module_put_and_exit" , +"__module_put_and_kthread_exit" ,"complete_and_exit" ,"__reiserfs_panic" , "lbug_with_loc",
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 226/690 NFSD: handle errors better in write_ports_addfd()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: NeilBrown <[email protected]>
[ Upstream commit 89b24336f03a8ba560e96b0c47a8434a7fa48e3c ]
If write_ports_add() fails, we shouldn't destroy the serv, unless we had only just created it. So if there are any permanent sockets already attached, leave the serv in place.
--- fs/nfsd/nfsctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfsd/nfsctl.c +1 -1
@@ -742,7 +742,7 @@ static ssize_t __write_ports_addfd(char *buf, struct net *net, const struct credreturn err; err =svc_addsock (nn->nfsd_serv, fd, buf,SIMPLE_TRANSACTION_LIMIT , cred); -if (err <0 ) { +if (err <0 &&list_empty (&nn->nfsd_serv->sv_permsocks)) {nfsd_destroy (net);return err; }
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 227/690 SUNRPC: change svc_get() to return the svc.
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: NeilBrown <[email protected]>
[ Upstream commit df5e49c880ea0776806b8a9f8ab95e035272cf6f ]
It is common for 'get' functions to return the object that was 'got', and there are a couple of places where users of svc_get() would be a little simpler if svc_get() did that.
Make it so.
--- fs/lockd/svc.c | 6 ++---- fs/nfs/callback.c | 6 ++---- include/linux/sunrpc/svc.h | 3 ++- 3 files changed, 6 insertions(+), 9 deletions(-)
fs/lockd/svc.c +2 -4
@@ -430,14 +430,12 @@ static struct svc_serv *lockd_create_svc(void)/* * Check whether we're already up and running. */ -if (nlmsvc_rqst) { +if (nlmsvc_rqst)/* * Note: increase service usage, because later in case of error * svc_destroy() will be called. */ -svc_get (nlmsvc_rqst->rq_server); -return nlmsvc_rqst->rq_server; - } +return svc_get (nlmsvc_rqst->rq_server);/* * Sanity check: if there's no pid,
fs/nfs/callback.c +2 -4
@@ -266,14 +266,12 @@ static struct svc_serv *nfs_callback_create_svc(int minorversion)/* * Check whether we're already up and running. */ -if (cb_info->serv) { +if (cb_info->serv)/* * Note: increase service usage, because later in case of error * svc_destroy() will be called. */ -svc_get (cb_info->serv); -return cb_info->serv; - } +return svc_get (cb_info->serv);switch (minorversion) {case 0 :
include/linux/sunrpc/svc.h +2 -1
@@ -120,9 +120,10 @@ struct svc_serv {* change the number of threads. Horrible, but there it is. * Should be called with the "service mutex" held. */ -static inline void svc_get (struct svc_serv *serv) +static inline struct svc_serv *svc_get (struct svc_serv *serv) { serv->sv_nrthreads++; +return serv; }/*
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 228/690 SUNRPC/NFSD: clean up get/put functions.
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: NeilBrown <[email protected]>
[ Upstream commit 8c62d12740a1450d2e8456d5747f440e10db281a ]
svc_destroy() is poorly named - it doesn't necessarily destroy the svc, it might just reduce the ref count.nfsd_destroy() is poorly named for the same reason.
This patch:
- removes the refcount functionality from svc_destroy(), moving it to a new svc_put(). Almost all previous callers of svc_destroy() now call svc_put().
- renames nfsd_destroy() to nfsd_put() and improves the code, using the new svc_destroy() rather than svc_put()
- removes a few comments that explain the important for balanced get/put calls. This should be obvious.
The only non-trivial part of this is that svc_destroy() would call svc_sock_update() on a non-final decrement. It can no longer do that, and svc_put() isn't really a good place of it. This call is now made from svc_exit_thread() which seems like a good place. This makes the call *before* sv_nrthreads is decremented rather than after. This is not particularly important as the call just sets a flag which causes sv_nrthreads set be checked later. A subsequent patch will improve the ordering.
--- fs/lockd/svc.c | 6 +----- fs/nfs/callback.c | 14 ++------------ fs/nfsd/nfsctl.c | 4 ++-- fs/nfsd/nfsd.h | 2 +- fs/nfsd/nfssvc.c | 30 ++++++++++++++++-------------- include/linux/sunrpc/svc.h | 26 +++++++++++++++++++++++--- net/sunrpc/svc.c | 19 +++++-------------- 7 files changed, 50 insertions(+), 51 deletions(-)
fs/lockd/svc.c +1 -5
@@ -431,10 +431,6 @@ static struct svc_serv *lockd_create_svc(void)* Check whether we're already up and running. */ if (nlmsvc_rqst) -/* -* Note: increase service usage, because later in case of error -* svc_destroy() will be called. -*/ return svc_get (nlmsvc_rqst->rq_server);/*
@@ -495,7 +491,7 @@ int lockd_up(struct net *net, const struct cred *cred)* so we exit through here on both success and failure. */ err_put: -svc_destroy (serv); +svc_put (serv); err_create:mutex_unlock (&nlmsvc_mutex);return error;
fs/nfs/callback.c +2 -12
@@ -267,10 +267,6 @@ static struct svc_serv *nfs_callback_create_svc(int minorversion)* Check whether we're already up and running. */ if (cb_info->serv) -/* -* Note: increase service usage, because later in case of error -* svc_destroy() will be called. -*/ return svc_get (cb_info->serv);switch (minorversion) {
@@ -333,16 +329,10 @@ int nfs_callback_up(u32 minorversion, struct rpc_xprt *xprt) goto err_start; cb_info->users++; -/* -* svc_create creates the svc_serv with sv_nrthreads == 1, and then -* svc_prepare_thread increments that. So we need to call svc_destroy -* on both success and failure so that the refcount is 1 when the -* thread exits. -*/ err_net:if (!cb_info->users) cb_info->serv =NULL ; -svc_destroy (serv); +svc_put (serv); err_create:mutex_unlock (&nfs_callback_mutex);return ret;
@@ -368,7 +358,7 @@ void nfs_callback_down(int minorversion, struct net *net)if (cb_info->users ==0 ) {svc_get (serv); serv->sv_ops->svo_setup (serv,NULL ,0 ); -svc_destroy (serv); +svc_put (serv);dprintk ("nfs_callback_down: service destroyed\n" ); cb_info->serv =NULL ; }
fs/nfsd/nfsctl.c +2 -2
@@ -743,7 +743,7 @@ static ssize_t __write_ports_addfd(char *buf, struct net *net, const struct cred err =svc_addsock (nn->nfsd_serv, fd, buf,SIMPLE_TRANSACTION_LIMIT , cred);if (err <0 &&list_empty (&nn->nfsd_serv->sv_permsocks)) { -nfsd_destroy (net); +nfsd_put (net);return err; }
@@ -796,7 +796,7 @@ static ssize_t __write_ports_addxprt(char *buf, struct net *net, const struct crif (!list_empty (&nn->nfsd_serv->sv_permsocks)) nn->nfsd_serv->sv_nrthreads--;else -nfsd_destroy (net); +nfsd_put (net);return err; }
fs/nfsd/nfsd.h +1 -1
@@ -97,7 +97,7 @@ int nfsd_pool_stats_open(struct inode *, struct file *);int nfsd_pool_stats_release (struct inode *,struct file *);void nfsd_shutdown_threads (struct net *net); -void nfsd_destroy (struct net *net); +void nfsd_put (struct net *net);bool i_am_nfsd (void );
fs/nfsd/nfssvc.c +16 -14
@@ -623,7 +623,7 @@ void nfsd_shutdown_threads(struct net *net)svc_get (serv);/* Kill outstanding nfsd threads */ serv->sv_ops->svo_setup (serv,NULL ,0 ); -nfsd_destroy (net); +nfsd_put (net);mutex_unlock (&nfsd_mutex);/* Wait for shutdown of nfsd_serv to complete */ wait_for_completion (&nn->nfsd_shutdown_complete);
@@ -656,7 +656,10 @@ int nfsd_create_serv(struct net *net) nn->nfsd_serv->sv_maxconn = nn->max_connections; error =svc_bind (nn->nfsd_serv, net);if (error <0 ) { -svc_destroy (nn->nfsd_serv); +/* NOT nfsd_put() as notifiers (see below) haven't +* been set up yet. +*/ +svc_put (nn->nfsd_serv);nfsd_complete_shutdown (net);return error; }
@@ -697,16 +700,16 @@ int nfsd_get_nrthreads(int n, int *nthreads, struct net *net)return 0 ; } -void nfsd_destroy (struct net *net) +void nfsd_put (struct net *net) {struct nfsd_net *nn =net_generic (net, nfsd_net_id); -int destroy = (nn->nfsd_serv->sv_nrthreads ==1 ); -if (destroy) + nn->nfsd_serv->sv_nrthreads -=1 ; +if (nn->nfsd_serv->sv_nrthreads ==0 ) {svc_shutdown_net (nn->nfsd_serv, net); -svc_destroy (nn->nfsd_serv); -if (destroy) +svc_destroy (nn->nfsd_serv);nfsd_complete_shutdown (net); + } }int nfsd_set_nrthreads (int n,int *nthreads,struct net *net)
@@ -758,7 +761,7 @@ int nfsd_set_nrthreads(int n, int *nthreads, struct net *net)if (err)break ; } -nfsd_destroy (net); +nfsd_put (net);return err; }
@@ -795,7 +798,7 @@ nfsd_svc(int nrservs, struct net *net, const struct cred *cred) error =nfsd_startup_net (net, cred);if (error) - goto out_destroy; + goto out_put; error = nn->nfsd_serv->sv_ops->svo_setup (nn->nfsd_serv,NULL , nrservs);if (error)
@@ -808,8 +811,8 @@ nfsd_svc(int nrservs, struct net *net, const struct cred *cred) out_shutdown:if (error <0 && !nfsd_up_before)nfsd_shutdown_net (net); -out_destroy: -nfsd_destroy (net);/* Release server */ +out_put: +nfsd_put (net); out:mutex_unlock (&nfsd_mutex);return error;
@@ -982,7 +985,7 @@ nfsd(void *vrqstp)/* Release the thread */ svc_exit_thread (rqstp); -nfsd_destroy (net); +nfsd_put (net);/* Release module */ mutex_unlock (&nfsd_mutex);
@@ -1109,8 +1112,7 @@ int nfsd_pool_stats_release(struct inode *inode, struct file *file)struct net *net = inode->i_sb->s_fs_info;mutex_lock (&nfsd_mutex); -/* this function really, really should have been called svc_put() */ -nfsd_destroy (net); +nfsd_put (net);mutex_unlock (&nfsd_mutex);return ret; }
include/linux/sunrpc/svc.h +23 -3
@@ -114,8 +114,13 @@ struct svc_serv {#endif /* CONFIG_SUNRPC_BACKCHANNEL */ }; -/* -* We use sv_nrthreads as a reference count. svc_destroy() drops +/** +* svc_get() - increment reference count on a SUNRPC serv +* @serv: the svc_serv to have count incremented +* +* Returns: the svc_serv that was passed in. +* +* We use sv_nrthreads as a reference count. svc_put() drops * this refcount, so we need to bump it up around operations that * change the number of threads. Horrible, but there it is. * Should be called with the "service mutex" held.
@@ -126,6 +131,22 @@ static inline struct svc_serv *svc_get(struct svc_serv *serv)return serv; } +void svc_destroy (struct svc_serv *serv); + +/** +* svc_put - decrement reference count on a SUNRPC serv +* @serv: the svc_serv to have count decremented +* +* When the reference count reaches zero, svc_destroy() +* is called to clean up and free the serv. +*/ +static inline void svc_put (struct svc_serv *serv) +{ + serv->sv_nrthreads -=1 ; +if (serv->sv_nrthreads ==0 ) +svc_destroy (serv); +} +/* * Maximum payload size supported by a kernel RPC server. * This is use to determine the max number of pages nfsd is
@@ -517,7 +538,6 @@ struct svc_serv * svc_create_pooled(struct svc_program *, unsigned int,int svc_set_num_threads (struct svc_serv *,struct svc_pool *,int );int svc_set_num_threads_sync (struct svc_serv *,struct svc_pool *,int );int svc_pool_stats_open (struct svc_serv *serv,struct file *file); -void svc_destroy (struct svc_serv *);void svc_shutdown_net (struct svc_serv *,struct net *);int svc_process (struct svc_rqst *); int bc_svc_process(struct svc_serv *, struct rpc_rqst *,
net/sunrpc/svc.c +5 -14
@@ -528,17 +528,7 @@ EXPORT_SYMBOL_GPL(svc_shutdown_net);void svc_destroy (struct svc_serv *serv) { -dprintk ("svc: svc_destroy(%s, %d)\n" , - serv->sv_program->pg_name, - serv->sv_nrthreads); - -if (serv->sv_nrthreads) { -if (--(serv->sv_nrthreads) !=0 ) { -svc_sock_update_bufs (serv); -return ; - } - }else -printk ("svc_destroy: no threads for serv=%p!\n" , serv); +dprintk ("svc: svc_destroy(%s)\n" , serv->sv_program->pg_name);del_timer_sync (&serv->sv_temptimer);
@@ -896,9 +886,10 @@ svc_exit_thread(struct svc_rqst *rqstp)svc_rqst_free (rqstp); -/* Release the server */ -if (serv) -svc_destroy (serv); +if (!serv) +return ; +svc_sock_update_bufs (serv); +svc_destroy (serv); }EXPORT_SYMBOL_GPL (svc_exit_thread);
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 229/690 SUNRPC: stop using ->sv_nrthreads as a refcount
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: NeilBrown <[email protected]>
[ Upstream commit ec52361df99b490f6af412b046df9799b92c1050 ]
The use of sv_nrthreads as a general refcount results in clumsy code, as is seen by various comments needed to explain the situation.
This patch introduces a 'struct kref' and uses that for reference counting, leaving sv_nrthreads to be a pure count of threads. The kref is managed particularly in svc_get() and svc_put(), and also nfsd_put();
svc_destroy() now takes a pointer to the embedded kref, rather than to the serv.
nfsd allows the svc_serv to exist with ->sv_nrhtreads being zero. This happens when a transport is created before the first thread is started. To support this, a 'keep_active' flag is introduced which holds a ref on the svc_serv. This is set when any listening socket is successfully added (unless there are running threads), and cleared when the number of threads is set. So when the last thread exits, the nfs_serv will be destroyed.
The use of 'keep_active' replaces previous code which checked if there were any permanent sockets.
We no longer clear ->rq_server when nfsd() exits. This was done to prevent svc_exit_thread() from calling svc_destroy(). Instead we take an extra reference to the svc_serv to prevent svc_destroy() from being called.
--- fs/lockd/svc.c | 4 ---- fs/nfs/callback.c | 2 +- fs/nfsd/netns.h | 7 +++++++ fs/nfsd/nfsctl.c | 22 +++++++++----------- fs/nfsd/nfssvc.c | 42 +++++++++++++++++++++++--------------- include/linux/sunrpc/svc.h | 14 ++++--------- net/sunrpc/svc.c | 22 ++++++++++---------- 7 files changed, 59 insertions(+), 54 deletions(-)
fs/lockd/svc.c +0 -4
@@ -486,10 +486,6 @@ int lockd_up(struct net *net, const struct cred *cred) goto err_put; } nlmsvc_users++; -/* -* Note: svc_serv structures have an initial use count of 1, -* so we exit through here on both success and failure. -*/ err_put:svc_put (serv); err_create:
fs/nfs/callback.c +1 -1
@@ -169,7 +169,7 @@ static int nfs_callback_start_svc(int minorversion, struct rpc_xprt *xprt,if (nrservs <NFS4_MIN_NR_CALLBACK_THREADS ) nrservs =NFS4_MIN_NR_CALLBACK_THREADS ; -if (serv->sv_nrthreads-1 == nrservs) +if (serv->sv_nrthreads == nrservs)return 0 ; ret = serv->sv_ops->svo_setup (serv,NULL , nrservs);
fs/nfsd/netns.h +7 -0
@@ -123,6 +123,13 @@ struct nfsd_net {u32 clverifier_counter;struct svc_serv *nfsd_serv; +/* When a listening socket is added to nfsd, keep_active is set +* and this justifies a reference on nfsd_serv. This stops +* nfsd_serv from being freed. When the number of threads is +* set, keep_active is cleared and the reference is dropped. So +* when the last thread exits, the service will be destroyed. +*/ +int keep_active;wait_queue_head_t ntf_wq;atomic_t ntf_refcnt;
fs/nfsd/nfsctl.c +10 -12
@@ -742,13 +742,12 @@ static ssize_t __write_ports_addfd(char *buf, struct net *net, const struct credreturn err; err =svc_addsock (nn->nfsd_serv, fd, buf,SIMPLE_TRANSACTION_LIMIT , cred); -if (err <0 &&list_empty (&nn->nfsd_serv->sv_permsocks)) { -nfsd_put (net); -return err; - } -/* Decrease the count, but don't shut down the service */ - nn->nfsd_serv->sv_nrthreads--; +if (err >=0 && + !nn->nfsd_serv->sv_nrthreads && !xchg (&nn->keep_active,1 )) +svc_get (nn->nfsd_serv); + +nfsd_put (net);return err; }
@@ -783,8 +782,10 @@ static ssize_t __write_ports_addxprt(char *buf, struct net *net, const struct crif (err <0 && err != -EAFNOSUPPORT ) goto out_close; -/* Decrease the count, but don't shut down the service */ - nn->nfsd_serv->sv_nrthreads--; +if (!nn->nfsd_serv->sv_nrthreads && !xchg (&nn->keep_active,1 )) +svc_get (nn->nfsd_serv); + +nfsd_put (net);return 0 ; out_close: xprt =svc_find_xprt (nn->nfsd_serv, transport, net,PF_INET , port);
@@ -793,10 +794,7 @@ static ssize_t __write_ports_addxprt(char *buf, struct net *net, const struct crsvc_xprt_put (xprt); } out_err: -if (!list_empty (&nn->nfsd_serv->sv_permsocks)) - nn->nfsd_serv->sv_nrthreads--; -else -nfsd_put (net); +nfsd_put (net);return err; }
fs/nfsd/nfssvc.c +26 -16
86 lines not on this page · raw message
include/linux/sunrpc/svc.h +4 -10
@@ -85,6 +85,7 @@ struct svc_serv {struct svc_program * sv_program;/* RPC program */ struct svc_stat * sv_stats;/* RPC statistics */ spinlock_t sv_lock; +struct kref sv_refcnt;unsigned int sv_nrthreads;/* # of server threads */ unsigned int sv_maxconn;/* max connections allowed or * '0' causing max to be based
@@ -119,19 +120,14 @@ struct svc_serv {* @serv: the svc_serv to have count incremented * * Returns: the svc_serv that was passed in. -* -* We use sv_nrthreads as a reference count. svc_put() drops -* this refcount, so we need to bump it up around operations that -* change the number of threads. Horrible, but there it is. -* Should be called with the "service mutex" held. */ static inline struct svc_serv *svc_get (struct svc_serv *serv) { - serv->sv_nrthreads++; +kref_get (&serv->sv_refcnt);return serv; } -void svc_destroy (struct svc_serv *serv); +void svc_destroy (struct kref *);/** * svc_put - decrement reference count on a SUNRPC serv
@@ -142,9 +138,7 @@ void svc_destroy(struct svc_serv *serv);*/ static inline void svc_put (struct svc_serv *serv) { - serv->sv_nrthreads -=1 ; -if (serv->sv_nrthreads ==0 ) -svc_destroy (serv); +kref_put (&serv->sv_refcnt, svc_destroy); }/*
net/sunrpc/svc.c +11 -11
@@ -435,7 +435,7 @@ __svc_create(struct svc_program *prog, unsigned int bufsize, int npools,return NULL ; serv->sv_name = prog->pg_name; serv->sv_program = prog; - serv->sv_nrthreads =1 ; +kref_init (&serv->sv_refcnt); serv->sv_stats = prog->pg_stats;if (bufsize >RPCSVC_MAXPAYLOAD ) bufsize =RPCSVC_MAXPAYLOAD ;
@@ -526,10 +526,11 @@ EXPORT_SYMBOL_GPL(svc_shutdown_net);* protect the sv_nrthreads, sv_permsocks and sv_tempsocks. */ void -svc_destroy (struct svc_serv *serv) +svc_destroy (struct kref *ref) { -dprintk ("svc: svc_destroy(%s)\n" , serv->sv_program->pg_name); + struct svc_serv *serv = container_of(ref, struct svc_serv, sv_refcnt); +dprintk ("svc: svc_destroy(%s)\n" , serv->sv_program->pg_name);del_timer_sync (&serv->sv_temptimer);/*
@@ -637,6 +638,7 @@ svc_prepare_thread(struct svc_serv *serv, struct svc_pool *pool, int node)if (!rqstp)return ERR_PTR (-ENOMEM ); +svc_get (serv); serv->sv_nrthreads++;spin_lock_bh (&pool->sp_lock); pool->sp_nrthreads++;
@@ -776,8 +778,7 @@ int svc_set_num_threads(struct svc_serv *serv, struct svc_pool *pool, int nrservs) { if (pool == NULL) { -/* The -1 assumes caller has done a svc_get() */ - nrservs -= (serv->sv_nrthreads-1); + nrservs -= serv->sv_nrthreads; } else {spin_lock_bh (&pool->sp_lock); nrservs -= pool->sp_nrthreads;
@@ -818,8 +819,7 @@ int svc_set_num_threads_sync(struct svc_serv *serv, struct svc_pool *pool, int nrservs) { if (pool == NULL) { -/* The -1 assumes caller has done a svc_get() */ - nrservs -= (serv->sv_nrthreads-1); + nrservs -= serv->sv_nrthreads; } else {spin_lock_bh (&pool->sp_lock); nrservs -= pool->sp_nrthreads;
@@ -884,12 +884,12 @@ svc_exit_thread(struct svc_rqst *rqstp)list_del_rcu (&rqstp->rq_all);spin_unlock_bh (&pool->sp_lock); + serv->sv_nrthreads -=1 ; +svc_sock_update_bufs (serv); +svc_rqst_free (rqstp); -if (!serv) -return ; -svc_sock_update_bufs (serv); -svc_destroy (serv); +svc_put (serv); }EXPORT_SYMBOL_GPL (svc_exit_thread);
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 230/690 nfsd: make nfsd_stats.th_cnt atomic_t
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: NeilBrown <[email protected]>
[ Upstream commit 9b6c8c9bebccd5fb785c306b948c08874a88874d ]
This allows us to move the updates for th_cnt out of the mutex. This is a step towards reducing mutex coverage in nfsd().
--- fs/nfsd/nfssvc.c | 6 +++--- fs/nfsd/stats.c | 2 +- fs/nfsd/stats.h | 4 +--- 3 files changed, 5 insertions(+), 7 deletions(-)
fs/nfsd/nfssvc.c +3 -3
@@ -57,7 +57,7 @@ static __be32 nfsd_init_request(struct svc_rqst *,/* * nfsd_mutex protects nn->nfsd_serv -- both the pointer itself and the members * of the svc_serv struct. In particular, ->sv_nrthreads but also to some -* extent ->sv_temp_socks and ->sv_permsocks. It also protects nfsdstats.th_cnt +* extent ->sv_temp_socks and ->sv_permsocks. * * If (out side the lock) nn->nfsd_serv is non-NULL, then it must point to a * properly initialised 'struct svc_serv' with ->sv_nrthreads > 0 (unless
@@ -955,8 +955,8 @@ nfsd(void *vrqstp)allow_signal (SIGINT );allow_signal (SIGQUIT ); - nfsdstats.th_cnt++;mutex_unlock (&nfsd_mutex); +atomic_inc (&nfsdstats.th_cnt);set_freezable ();
@@ -983,8 +983,8 @@ nfsd(void *vrqstp)/* Clear signals before calling svc_exit_thread() */ flush_signals (current); +atomic_dec (&nfsdstats.th_cnt);mutex_lock (&nfsd_mutex); - nfsdstats.th_cnt --; out:/* Take an extra ref so that the svc_put in svc_exit_thread()
fs/nfsd/stats.c +1 -1
@@ -45,7 +45,7 @@ static int nfsd_proc_show(struct seq_file *seq, void *v) percpu_counter_sum_positive(&nfsdstats.counter[NFSD_STATS_IO_WRITE]));/* thread usage: */ -seq_printf (seq,"th %u 0" , nfsdstats.th_cnt); +seq_printf (seq,"th %u 0" ,atomic_read (&nfsdstats.th_cnt));/* deprecated thread usage histogram stats */ for (i =0 ; i <10 ; i++)
fs/nfsd/stats.h +1 -3
@@ -29,11 +29,9 @@ enum {struct nfsd_stats {struct percpu_counter counter[NFSD_STATS_COUNTERS_NUM ]; -/* Protected by nfsd_mutex */ -unsigned int th_cnt;/* number of available threads */ +atomic_t th_cnt;/* number of available threads */ }; -extern struct nfsd_stats nfsdstats;extern struct svc_stat nfsd_svcstats;
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 231/690 SUNRPC: use sv_lock to protect updates to sv_nrthreads.
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: NeilBrown <[email protected]>
[ Upstream commit 2a36395fac3b72771f87c3ee4387e3a96d85a7cc ]
Using sv_lock means we don't need to hold the service mutex over these updates.
In particular, svc_exit_thread() no longer requires synchronisation, so threads can exit asynchronously.
Note that we could use an atomic_t, but as there are many more read sites than writes, that would add unnecessary noise to the code. Some reads are already racy, and there is no need for them to not be.
--- fs/nfsd/nfssvc.c | 5 ++--- net/sunrpc/svc.c | 9 +++++++-- 2 files changed, 9 insertions(+), 5 deletions(-)
fs/nfsd/nfssvc.c +2 -3
@@ -55,9 +55,8 @@ static __be32 nfsd_init_request(struct svc_rqst *, struct svc_process_info *);/* -* nfsd_mutex protects nn->nfsd_serv -- both the pointer itself and the members -* of the svc_serv struct. In particular, ->sv_nrthreads but also to some -* extent ->sv_temp_socks and ->sv_permsocks. +* nfsd_mutex protects nn->nfsd_serv -- both the pointer itself and some members +* of the svc_serv struct such as ->sv_temp_socks and ->sv_permsocks. * * If (out side the lock) nn->nfsd_serv is non-NULL, then it must point to a * properly initialised 'struct svc_serv' with ->sv_nrthreads > 0 (unless
net/sunrpc/svc.c +7 -2
@@ -523,7 +523,7 @@ EXPORT_SYMBOL_GPL(svc_shutdown_net);/* * Destroy an RPC service. Should be called with appropriate locking to -* protect the sv_nrthreads, sv_permsocks and sv_tempsocks. +* protect sv_permsocks and sv_tempsocks. */ void svc_destroy (struct kref *ref)
@@ -639,7 +639,10 @@ svc_prepare_thread(struct svc_serv *serv, struct svc_pool *pool, int node)return ERR_PTR (-ENOMEM );svc_get (serv); - serv->sv_nrthreads++; +spin_lock_bh (&serv->sv_lock); + serv->sv_nrthreads +=1 ; +spin_unlock_bh (&serv->sv_lock); +spin_lock_bh (&pool->sp_lock); pool->sp_nrthreads++;list_add_rcu (&rqstp->rq_all, &pool->sp_all_threads);
@@ -884,7 +887,9 @@ svc_exit_thread(struct svc_rqst *rqstp)list_del_rcu (&rqstp->rq_all);spin_unlock_bh (&pool->sp_lock); +spin_lock_bh (&serv->sv_lock); serv->sv_nrthreads -=1 ; +spin_unlock_bh (&serv->sv_lock);svc_sock_update_bufs (serv);svc_rqst_free (rqstp);
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 232/690 NFSD: narrow nfsd_mutex protection in nfsd thread
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: NeilBrown <[email protected]>
[ Upstream commit 9d3792aefdcda71d20c2b1ecc589c17ae71eb523 ]
There is nothing happening in the start of nfsd() that requires protection by the mutex, so don't take it until shutting down the thread
- which does still require protection - but only for nfsd_put().
--- fs/nfsd/nfssvc.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
fs/nfsd/nfssvc.c +2 -6
@@ -932,9 +932,6 @@ nfsd(void *vrqstp)struct nfsd_net *nn =net_generic (net, nfsd_net_id);int err; -/* Lock module and set up kernel thread */ -mutex_lock (&nfsd_mutex); -/* At this point, the thread shares current->fs * with the init process. We need to create files with the * umask as defined by the client instead of init's umask. */
@@ -954,7 +951,6 @@ nfsd(void *vrqstp)allow_signal (SIGINT );allow_signal (SIGQUIT ); -mutex_unlock (&nfsd_mutex);atomic_inc (&nfsdstats.th_cnt);set_freezable ();
@@ -983,7 +979,6 @@ nfsd(void *vrqstp)flush_signals (current);atomic_dec (&nfsdstats.th_cnt); -mutex_lock (&nfsd_mutex); out:/* Take an extra ref so that the svc_put in svc_exit_thread()
@@ -995,10 +990,11 @@ nfsd(void *vrqstp)svc_exit_thread (rqstp);/* Now if needed we call svc_destroy in appropriate context */ +mutex_lock (&nfsd_mutex);nfsd_put (net); +mutex_unlock (&nfsd_mutex);/* Release module */ -mutex_unlock (&nfsd_mutex);module_put_and_kthread_exit (0 );return 0 ; }
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 233/690 NFSD: Make it possible to use svc_set_num_threads_sync
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: NeilBrown <[email protected]>
[ Upstream commit 3409e4f1e8f239f0ed81be0b068ecf4e73e2e826 ]
nfsd cannot currently use svc_set_num_threads_sync. It instead uses svc_set_num_threads which does *not* wait for threads to all exit, and has a separate mechanism (nfsd_shutdown_complete) to wait for completion.
The reason that nfsd is unlike other services is that nfsd threads can exit separately from svc_set_num_threads being called - they die on receipt of SIGKILL. Also, when the last thread exits, the service must be shut down (sockets closed).
For this, the nfsd_mutex needs to be taken, and as that mutex needs to be held while svc_set_num_threads is called, the one cannot wait for the other.
This patch changes the nfsd thread so that it can drop the ref on the service without blocking on nfsd_mutex, so that svc_set_num_threads_sync can be used:
- if it can drop a non-last reference, it does that. This does not trigger shutdown and does not require a mutex. This will likely happen for all but the last thread signalled, and for all threads being shut down by nfsd_shutdown_threads()
- if it can get the mutex without blocking (trylock), it does that and then drops the reference. This will likely happen for the last thread killed by SIGKILL
- Otherwise there might be an unrelated task holding the mutex, possibly in another network namespace, or nfsd_shutdown_threads() might be just about to get a reference on the service, after which we can drop ours safely.
We cannot conveniently get wakeup notifications on these events, and we are unlikely to need to, so we sleep briefly and check again.
With this we can discard nfsd_shutdown_complete and nfsd_complete_shutdown(), and switch to svc_set_num_threads_sync.
--- fs/nfsd/netns.h | 3 --- fs/nfsd/nfssvc.c | 41 +++++++++++++++++++------------------- include/linux/sunrpc/svc.h | 13 ++++++++++++ 3 files changed, 33 insertions(+), 24 deletions(-)
fs/nfsd/netns.h +0 -3
@@ -134,9 +134,6 @@ struct nfsd_net {wait_queue_head_t ntf_wq;atomic_t ntf_refcnt; -/* Allow umount to wait for nfsd state cleanup */ -struct completion nfsd_shutdown_complete; -/* * clientid and stateid data for construction of net unique COPY * stateids.
fs/nfsd/nfssvc.c +20 -21
86 lines not on this page · raw message
include/linux/sunrpc/svc.h +13 -0
@@ -141,6 +141,19 @@ static inline void svc_put(struct svc_serv *serv)kref_put (&serv->sv_refcnt, svc_destroy); } +/** +* svc_put_not_last - decrement non-final reference count on SUNRPC serv +* @serv: the svc_serv to have count decremented +* +* Returns: %true is refcount was decremented. +* +* If the refcount is 1, it is not decremented and instead failure is reported. +*/ +static inline bool svc_put_not_last (struct svc_serv *serv) +{ +return refcount_dec_not_one (&serv->sv_refcnt.refcount); +} +/* * Maximum payload size supported by a kernel RPC server. * This is use to determine the max number of pages nfsd is
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 234/690 SUNRPC: discard svo_setup and rename svc_set_num_threads_sync()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: NeilBrown <[email protected]>
[ Upstream commit 3ebdbe5203a874614819700d3f470724cb803709 ]
The ->svo_setup callback serves no purpose. It is always called from within the same module that chooses which callback is needed. So discard it and call the relevant function directly.
Now that svc_set_num_threads() is no longer used remove it and rename svc_set_num_threads_sync() to remove the "_sync" suffix.
--- fs/nfs/callback.c | 8 +++---- fs/nfsd/nfssvc.c | 11 ++++----- include/linux/sunrpc/svc.h | 4 ---- net/sunrpc/svc.c | 49 ++------------------------------------ 4 files changed, 10 insertions(+), 62 deletions(-)
fs/nfs/callback.c +3 -5
@@ -172,9 +172,9 @@ static int nfs_callback_start_svc(int minorversion, struct rpc_xprt *xprt,if (serv->sv_nrthreads == nrservs)return 0 ; - ret = serv->sv_ops->svo_setup (serv,NULL , nrservs); + ret =svc_set_num_threads (serv,NULL , nrservs);if (ret) { - serv->sv_ops->svo_setup (serv,NULL ,0 ); +svc_set_num_threads (serv,NULL ,0 );return ret; }dprintk ("nfs_callback_up: service started\n" );
@@ -235,14 +235,12 @@ static int nfs_callback_up_net(int minorversion, struct svc_serv *serv,static const struct svc_serv_ops nfs40_cb_sv_ops = { .svo_function = nfs4_callback_svc, .svo_enqueue_xprt = svc_xprt_do_enqueue, - .svo_setup = svc_set_num_threads_sync, .svo_module =THIS_MODULE , };#if defined(CONFIG_NFS_V4_1 )static const struct svc_serv_ops nfs41_cb_sv_ops = { .svo_function = nfs41_callback_svc, .svo_enqueue_xprt = svc_xprt_do_enqueue, - .svo_setup = svc_set_num_threads_sync, .svo_module =THIS_MODULE , };
@@ -357,7 +355,7 @@ void nfs_callback_down(int minorversion, struct net *net) cb_info->users--;if (cb_info->users ==0 ) {svc_get (serv); - serv->sv_ops->svo_setup (serv,NULL ,0 ); +svc_set_num_threads (serv,NULL ,0 );svc_put (serv);dprintk ("nfs_callback_down: service destroyed\n" ); cb_info->serv =NULL ;
fs/nfsd/nfssvc.c +5 -6
@@ -593,7 +593,6 @@ static const struct svc_serv_ops nfsd_thread_sv_ops = { .svo_shutdown = nfsd_last_thread, .svo_function = nfsd, .svo_enqueue_xprt = svc_xprt_do_enqueue, - .svo_setup = svc_set_num_threads_sync, .svo_module = THIS_MODULE, };
@@ -611,7 +610,7 @@ void nfsd_shutdown_threads(struct net *net)svc_get (serv);/* Kill outstanding nfsd threads */ - serv->sv_ops->svo_setup (serv,NULL ,0 ); +svc_set_num_threads (serv,NULL ,0 );nfsd_put (net);mutex_unlock (&nfsd_mutex); }
@@ -750,8 +749,9 @@ int nfsd_set_nrthreads(int n, int *nthreads, struct net *net)/* apply the new numbers */ svc_get (nn->nfsd_serv);for (i =0 ; i < n; i++) { - err = nn->nfsd_serv->sv_ops->svo_setup (nn->nfsd_serv, - &nn->nfsd_serv->sv_pools[i], nthreads[i]); + err =svc_set_num_threads (nn->nfsd_serv, + &nn->nfsd_serv->sv_pools[i], + nthreads[i]);if (err)break ; }
@@ -793,8 +793,7 @@ nfsd_svc(int nrservs, struct net *net, const struct cred *cred) error =nfsd_startup_net (net, cred);if (error) goto out_put; - error = nn->nfsd_serv->sv_ops->svo_setup (nn->nfsd_serv, -NULL , nrservs); + error =svc_set_num_threads (nn->nfsd_serv,NULL , nrservs);if (error) goto out_shutdown; error = nn->nfsd_serv->sv_nrthreads;
include/linux/sunrpc/svc.h +0 -4
@@ -64,9 +64,6 @@ struct svc_serv_ops {/* queue up a transport for servicing */ void (*svo_enqueue_xprt)(struct svc_xprt *); -/* set up thread (or whatever) execution context */ -int (*svo_setup)(struct svc_serv *,struct svc_pool *,int ); -/* optional module to count when adding threads (pooled svcs only) */ struct module *svo_module; };
@@ -543,7 +540,6 @@ void svc_pool_map_put(void);struct svc_serv *svc_create_pooled (struct svc_program *,unsigned int ,const struct svc_serv_ops *);int svc_set_num_threads (struct svc_serv *,struct svc_pool *,int ); -int svc_set_num_threads_sync (struct svc_serv *,struct svc_pool *,int );int svc_pool_stats_open (struct svc_serv *serv,struct file *file);void svc_shutdown_net (struct svc_serv *,struct net *);int svc_process (struct svc_rqst *);
net/sunrpc/svc.c +2 -47
74 lines not on this page · raw message
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 235/690 NFSD: simplify locking for network notifier.
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: NeilBrown <[email protected]>
[ Upstream commit d057cfec4940ce6eeffa22b4a71dec203b06cd55 ]
nfsd currently maintains an open-coded read/write semaphore (refcount and wait queue) for each network namespace to ensure the nfs service isn't shut down while the notifier is running.
This is excessive. As there is unlikely to be contention between notifiers and they run without sleeping, a single spinlock is sufficient to avoid problems.
--- fs/nfsd/netns.h | 3 --- fs/nfsd/nfsctl.c | 2 -- fs/nfsd/nfssvc.c | 38 ++++++++++++++++++++------------------ 3 files changed, 20 insertions(+), 23 deletions(-)
fs/nfsd/netns.h +0 -3
@@ -131,9 +131,6 @@ struct nfsd_net {*/ int keep_active; -wait_queue_head_t ntf_wq; -atomic_t ntf_refcnt; -/* * clientid and stateid data for construction of net unique COPY * stateids.
fs/nfsd/nfsctl.c +0 -2
@@ -1484,8 +1484,6 @@ static __net_init int nfsd_init_net(struct net *net) nn->clientid_counter = nn->clientid_base +1 ; nn->s2s_cp_cl_id = nn->clientid_counter++; -atomic_set (&nn->ntf_refcnt,0 ); -init_waitqueue_head (&nn->ntf_wq);seqlock_init (&nn->boot_lock);return 0 ;
fs/nfsd/nfssvc.c +20 -18
@@ -434,6 +434,7 @@ static void nfsd_shutdown_net(struct net *net)nfsd_shutdown_generic (); } +static DEFINE_SPINLOCK (nfsd_notifier_lock);static int nfsd_inetaddr_event (struct notifier_block *this,unsigned long event,void *ptr) {
@@ -443,18 +444,17 @@ static int nfsd_inetaddr_event(struct notifier_block *this, unsigned long event,struct nfsd_net *nn =net_generic (net, nfsd_net_id);struct sockaddr_in sin; -if ((event !=NETDEV_DOWN ) || - !atomic_inc_not_zero (&nn->ntf_refcnt)) +if (event !=NETDEV_DOWN || !nn->nfsd_serv) goto out; +spin_lock (&nfsd_notifier_lock);if (nn->nfsd_serv) {dprintk ("nfsd_inetaddr_event: removed %pI4\n" , &ifa->ifa_local); sin.sin_family =AF_INET ; sin.sin_addr.s_addr = ifa->ifa_local;svc_age_temp_xprts_now (nn->nfsd_serv, (struct sockaddr *)&sin); } -atomic_dec (&nn->ntf_refcnt); -wake_up (&nn->ntf_wq); +spin_unlock (&nfsd_notifier_lock); out:return NOTIFY_DONE ;
@@ -474,10 +474,10 @@ static int nfsd_inet6addr_event(struct notifier_block *this,struct nfsd_net *nn =net_generic (net, nfsd_net_id);struct sockaddr_in6 sin6; -if ((event !=NETDEV_DOWN ) || - !atomic_inc_not_zero (&nn->ntf_refcnt)) +if (event !=NETDEV_DOWN || !nn->nfsd_serv) goto out; +spin_lock (&nfsd_notifier_lock);if (nn->nfsd_serv) {dprintk ("nfsd_inet6addr_event: removed %pI6\n" , &ifa->addr); sin6.sin6_family =AF_INET6 ;
@@ -486,8 +486,8 @@ static int nfsd_inet6addr_event(struct notifier_block *this, sin6.sin6_scope_id = ifa->idev->dev->ifindex;svc_age_temp_xprts_now (nn->nfsd_serv, (struct sockaddr *)&sin6); } -atomic_dec (&nn->ntf_refcnt); -wake_up (&nn->ntf_wq); +spin_unlock (&nfsd_notifier_lock); + out:return NOTIFY_DONE ; }
@@ -504,7 +504,6 @@ static void nfsd_last_thread(struct svc_serv *serv, struct net *net) {struct nfsd_net *nn =net_generic (net, nfsd_net_id); -atomic_dec (&nn->ntf_refcnt);/* check if the notifier still has clients */ if (atomic_dec_return (&nfsd_notifier_refcount) ==0 ) {unregister_inetaddr_notifier (&nfsd_inetaddr_notifier);
@@ -512,7 +511,6 @@ static void nfsd_last_thread(struct svc_serv *serv, struct net *net)unregister_inet6addr_notifier (&nfsd_inet6addr_notifier);#endif } -wait_event (nn->ntf_wq,atomic_read (&nn->ntf_refcnt) ==0 );/* * write_ports can create the server without actually starting
@@ -624,6 +622,7 @@ int nfsd_create_serv(struct net *net) {int error;struct nfsd_net *nn =net_generic (net, nfsd_net_id); +struct svc_serv *serv;WARN_ON (!mutex_is_locked (&nfsd_mutex));if (nn->nfsd_serv) {
@@ -633,21 +632,23 @@ int nfsd_create_serv(struct net *net)if (nfsd_max_blksize ==0 ) nfsd_max_blksize =nfsd_get_default_max_blksize ();nfsd_reset_versions (nn); - nn->nfsd_serv =svc_create_pooled (&nfsd_program, nfsd_max_blksize, - &nfsd_thread_sv_ops); -if (nn->nfsd_serv ==NULL ) + serv =svc_create_pooled (&nfsd_program, nfsd_max_blksize, + &nfsd_thread_sv_ops); +if (serv ==NULL )return -ENOMEM ; - nn->nfsd_serv->sv_maxconn = nn->max_connections; - error =svc_bind (nn->nfsd_serv, net); + serv->sv_maxconn = nn->max_connections; + error =svc_bind (serv, net);if (error <0 ) {/* NOT nfsd_put() as notifiers (see below) haven't * been set up yet. */ -svc_put (nn->nfsd_serv); - nn->nfsd_serv =NULL ; +svc_put (serv);return error; } +spin_lock (&nfsd_notifier_lock); + nn->nfsd_serv = serv; +spin_unlock (&nfsd_notifier_lock);set_max_drc ();/* check if the notifier is already set */
@@ -657,7 +658,6 @@ int nfsd_create_serv(struct net *net)register_inet6addr_notifier (&nfsd_inet6addr_notifier);#endif } -atomic_inc (&nn->ntf_refcnt);nfsd_reset_boot_verifier (nn);return 0 ; }
@@ -701,7 +701,9 @@ void nfsd_put(struct net *net)if (kref_put (&nn->nfsd_serv->sv_refcnt, nfsd_noop)) {svc_shutdown_net (nn->nfsd_serv, net);svc_destroy (&nn->nfsd_serv->sv_refcnt); +spin_lock (&nfsd_notifier_lock); nn->nfsd_serv =NULL ; +spin_unlock (&nfsd_notifier_lock); } }
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 236/690 lockd: introduce nlmsvc_serv
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: NeilBrown <[email protected]>
[ Upstream commit 2840fe864c91a0fe822169b1fbfddbcac9aeac43 ]
lockd has two globals - nlmsvc_task and nlmsvc_rqst - but mostly it wants the 'struct svc_serv', and when it doesn't want it exactly it can get to what it wants from the serv.
This patch is a first step to removing nlmsvc_task and nlmsvc_rqst. It introduces nlmsvc_serv to store the 'struct svc_serv*'. This is set as soon as the serv is created, and cleared only when it is destroyed.
--- fs/lockd/svc.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-)
fs/lockd/svc.c +20 -16
@@ -54,6 +54,7 @@ EXPORT_SYMBOL_GPL(nlmsvc_ops);static DEFINE_MUTEX (nlmsvc_mutex);static unsigned int nlmsvc_users; +static struct svc_serv *nlmsvc_serv;static struct task_struct *nlmsvc_task;static struct svc_rqst *nlmsvc_rqst;unsigned long nlmsvc_timeout;
@@ -306,13 +307,12 @@ static int lockd_inetaddr_event(struct notifier_block *this, !atomic_inc_not_zero(&nlm_ntf_refcnt)) goto out; -if (nlmsvc_rqst) { +if (nlmsvc_serv) {dprintk ("lockd_inetaddr_event: removed %pI4\n" , &ifa->ifa_local); sin.sin_family =AF_INET ; sin.sin_addr.s_addr = ifa->ifa_local; -svc_age_temp_xprts_now (nlmsvc_rqst->rq_server, - (struct sockaddr *)&sin); +svc_age_temp_xprts_now (nlmsvc_serv, (struct sockaddr *)&sin); }atomic_dec (&nlm_ntf_refcnt);wake_up (&nlm_ntf_wq);
@@ -336,14 +336,13 @@ static int lockd_inet6addr_event(struct notifier_block *this, !atomic_inc_not_zero(&nlm_ntf_refcnt)) goto out; -if (nlmsvc_rqst) { +if (nlmsvc_serv) {dprintk ("lockd_inet6addr_event: removed %pI6\n" , &ifa->addr); sin6.sin6_family =AF_INET6 ; sin6.sin6_addr = ifa->addr;if (ipv6_addr_type (&sin6.sin6_addr) &IPV6_ADDR_LINKLOCAL ) sin6.sin6_scope_id = ifa->idev->dev->ifindex; -svc_age_temp_xprts_now (nlmsvc_rqst->rq_server, - (struct sockaddr *)&sin6); +svc_age_temp_xprts_now (nlmsvc_serv, (struct sockaddr *)&sin6); }atomic_dec (&nlm_ntf_refcnt);wake_up (&nlm_ntf_wq);
@@ -423,15 +422,17 @@ static const struct svc_serv_ops lockd_sv_ops = { .svo_enqueue_xprt = svc_xprt_do_enqueue, }; -static struct svc_serv *lockd_create_svc (void ) +static int lockd_create_svc (void ) {struct svc_serv *serv;/* * Check whether we're already up and running. */ -if (nlmsvc_rqst) -return svc_get (nlmsvc_rqst->rq_server); +if (nlmsvc_serv) { +svc_get (nlmsvc_serv); +return 0 ; + }/* * Sanity check: if there's no pid,
@@ -448,14 +449,15 @@ static struct svc_serv *lockd_create_svc(void) serv =svc_create (&nlmsvc_program,LOCKD_BUFSIZE , &lockd_sv_ops);if (!serv) {printk (KERN_WARNING "lockd_up: create service failed\n" ); -return ERR_PTR (-ENOMEM ); +return -ENOMEM ; } + nlmsvc_serv = serv;register_inetaddr_notifier (&lockd_inetaddr_notifier);#if IS_ENABLED (CONFIG_IPV6 )register_inet6addr_notifier (&lockd_inet6addr_notifier);#endif dprintk ("lockd_up: service created\n" ); -return serv; +return 0 ; }/*
@@ -468,11 +470,10 @@ int lockd_up(struct net *net, const struct cred *cred)mutex_lock (&nlmsvc_mutex); - serv =lockd_create_svc (); -if (IS_ERR (serv)) { - error =PTR_ERR (serv); + error =lockd_create_svc (); +if (error) goto err_create; - } + serv = nlmsvc_serv; error =lockd_up_net (serv, net, cred);if (error <0 ) {
@@ -487,6 +488,8 @@ int lockd_up(struct net *net, const struct cred *cred) } nlmsvc_users++; err_put: +if (nlmsvc_users ==0 ) + nlmsvc_serv =NULL ;svc_put (serv); err_create:mutex_unlock (&nlmsvc_mutex);
@@ -501,7 +504,7 @@ void lockd_down(struct net *net) {mutex_lock (&nlmsvc_mutex); -lockd_down_net (nlmsvc_rqst->rq_server, net); +lockd_down_net (nlmsvc_serv, net);if (nlmsvc_users) {if (--nlmsvc_users) goto out;
@@ -519,6 +522,7 @@ lockd_down(struct net *net)dprintk ("lockd_down: service stopped\n" );lockd_svc_exit_thread ();dprintk ("lockd_down: service destroyed\n" ); + nlmsvc_serv =NULL ; nlmsvc_task =NULL ; nlmsvc_rqst =NULL ; out:
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 237/690 lockd: simplify management of network status notifiers
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: NeilBrown <[email protected]>
[ Upstream commit 5a8a7ff57421b7de3ae72019938ffb5daaee36e7 ]
Now that the network status notifiers use nlmsvc_serv rather then nlmsvc_rqst the management can be simplified.
Notifier unregistration synchronises with any pending notifications so providing we unregister before nlm_serv is freed no further interlock is required.
So we move the unregister call to just before the thread is killed (which destroys the service) and just before the service is destroyed in the failure-path of lockd_up().
Then nlm_ntf_refcnt and nlm_ntf_wq can be removed.
--- fs/lockd/svc.c | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-)
fs/lockd/svc.c +9 -26
@@ -59,9 +59,6 @@ static struct task_struct *nlmsvc_task;static struct svc_rqst *nlmsvc_rqst;unsigned long nlmsvc_timeout; -static atomic_t nlm_ntf_refcnt =ATOMIC_INIT (0 ); -static DECLARE_WAIT_QUEUE_HEAD (nlm_ntf_wq); -unsigned int lockd_net_id;/*
@@ -303,8 +300,7 @@ static int lockd_inetaddr_event(struct notifier_block *this,struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;struct sockaddr_in sin; -if ((event !=NETDEV_DOWN ) || - !atomic_inc_not_zero (&nlm_ntf_refcnt)) +if (event !=NETDEV_DOWN ) goto out;if (nlmsvc_serv) {
@@ -314,8 +310,6 @@ static int lockd_inetaddr_event(struct notifier_block *this, sin.sin_addr.s_addr = ifa->ifa_local;svc_age_temp_xprts_now (nlmsvc_serv, (struct sockaddr *)&sin); } -atomic_dec (&nlm_ntf_refcnt); -wake_up (&nlm_ntf_wq); out:return NOTIFY_DONE ;
@@ -332,8 +326,7 @@ static int lockd_inet6addr_event(struct notifier_block *this,struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;struct sockaddr_in6 sin6; -if ((event !=NETDEV_DOWN ) || - !atomic_inc_not_zero (&nlm_ntf_refcnt)) +if (event !=NETDEV_DOWN ) goto out;if (nlmsvc_serv) {
@@ -344,8 +337,6 @@ static int lockd_inet6addr_event(struct notifier_block *this, sin6.sin6_scope_id = ifa->idev->dev->ifindex;svc_age_temp_xprts_now (nlmsvc_serv, (struct sockaddr *)&sin6); } -atomic_dec (&nlm_ntf_refcnt); -wake_up (&nlm_ntf_wq); out:return NOTIFY_DONE ;
@@ -362,14 +353,6 @@ static void lockd_unregister_notifiers(void)#if IS_ENABLED (CONFIG_IPV6 )unregister_inet6addr_notifier (&lockd_inet6addr_notifier);#endif -wait_event (nlm_ntf_wq,atomic_read (&nlm_ntf_refcnt) ==0 ); -} - -static void lockd_svc_exit_thread (void ) -{ -atomic_dec (&nlm_ntf_refcnt); -lockd_unregister_notifiers (); -svc_exit_thread (nlmsvc_rqst); }static int lockd_start_svc (struct svc_serv *serv)
@@ -388,11 +371,9 @@ static int lockd_start_svc(struct svc_serv *serv)printk (KERN_WARNING "lockd_up: svc_rqst allocation failed, error=%d\n" , error); -lockd_unregister_notifiers (); goto out_rqst; } -atomic_inc (&nlm_ntf_refcnt);svc_sock_update_bufs (serv); serv->sv_maxconn = nlm_max_connections;
@@ -410,7 +391,7 @@ static int lockd_start_svc(struct svc_serv *serv)return 0 ; out_task: -lockd_svc_exit_thread (); +svc_exit_thread (nlmsvc_rqst); nlmsvc_task =NULL ; out_rqst: nlmsvc_rqst =NULL ;
@@ -477,7 +458,6 @@ int lockd_up(struct net *net, const struct cred *cred) error =lockd_up_net (serv, net, cred);if (error <0 ) { -lockd_unregister_notifiers (); goto err_put; }
@@ -488,8 +468,10 @@ int lockd_up(struct net *net, const struct cred *cred) } nlmsvc_users++; err_put: -if (nlmsvc_users ==0 ) +if (nlmsvc_users ==0 ) { +lockd_unregister_notifiers (); nlmsvc_serv =NULL ; + }svc_put (serv); err_create:mutex_unlock (&nlmsvc_mutex);
@@ -518,13 +500,14 @@ lockd_down(struct net *net)printk (KERN_ERR "lockd_down: no lockd running.\n" );BUG (); } +lockd_unregister_notifiers ();kthread_stop (nlmsvc_task);dprintk ("lockd_down: service stopped\n" ); -lockd_svc_exit_thread (); +svc_exit_thread (nlmsvc_rqst); + nlmsvc_rqst =NULL ;dprintk ("lockd_down: service destroyed\n" ); nlmsvc_serv =NULL ; nlmsvc_task =NULL ; - nlmsvc_rqst =NULL ; out:mutex_unlock (&nlmsvc_mutex); }
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 238/690 lockd: move lockd_start_svc() call into lockd_create_svc()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: NeilBrown <[email protected]>
[ Upstream commit b73a2972041bee70eb0cbbb25fa77828c63c916b ]
lockd_start_svc() only needs to be called once, just after the svc is created. If the start fails, the svc is discarded too.
It thus makes sense to call lockd_start_svc() from lockd_create_svc(). This allows us to remove the test against nlmsvc_rqst at the start of lockd_start_svc() - it must always be NULL.
lockd_up() only held an extra reference on the svc until a thread was created - then it dropped it. The thread - and thus the extra reference
- will remain until kthread_stop() is called.
Now that the thread is created in lockd_create_svc(), the extra reference can be dropped there. So the 'serv' variable is no longer needed in lockd_up().
--- fs/lockd/svc.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
fs/lockd/svc.c +10 -12
@@ -359,9 +359,6 @@ static int lockd_start_svc(struct svc_serv *serv) {int error; -if (nlmsvc_rqst) -return 0 ; -/* * Create the kernel thread and wait for it to start. */
@@ -406,6 +403,7 @@ static const struct svc_serv_ops lockd_sv_ops = {static int lockd_create_svc (void ) {struct svc_serv *serv; +int error;/* * Check whether we're already up and running.
@@ -432,6 +430,13 @@ static int lockd_create_svc(void)printk (KERN_WARNING "lockd_up: create service failed\n" );return -ENOMEM ; } + + error =lockd_start_svc (serv); +/* The thread now holds the only reference */ +svc_put (serv); +if (error <0 ) +return error; + nlmsvc_serv = serv;register_inetaddr_notifier (&lockd_inetaddr_notifier);#if IS_ENABLED (CONFIG_IPV6 )
@@ -446,7 +451,6 @@ static int lockd_create_svc(void)*/ int lockd_up (struct net *net,const struct cred *cred) { -struct svc_serv *serv;int error;mutex_lock (&nlmsvc_mutex);
@@ -454,25 +458,19 @@ int lockd_up(struct net *net, const struct cred *cred) error =lockd_create_svc ();if (error) goto err_create; - serv = nlmsvc_serv; - error =lockd_up_net (serv, net, cred); + error =lockd_up_net (nlmsvc_serv, net, cred);if (error <0 ) { goto err_put; } - error =lockd_start_svc (serv); -if (error <0 ) { -lockd_down_net (serv, net); - goto err_put; - } nlmsvc_users++; err_put:if (nlmsvc_users ==0 ) {lockd_unregister_notifiers (); +kthread_stop (nlmsvc_task); nlmsvc_serv =NULL ; } -svc_put (serv); err_create:mutex_unlock (&nlmsvc_mutex);return error;
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 239/690 lockd: move svc_exit_thread() into the thread
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: NeilBrown <[email protected]>
[ Upstream commit 6a4e2527a63620a820c4ebf3596b57176da26fb3 ]
The normal place to call svc_exit_thread() is from the thread itself just before it exists.
Do this for lockd.
This means that nlmsvc_rqst is not used out side of lockd_start_svc(), so it can be made local to that function, and renamed to 'rqst'.
--- fs/lockd/svc.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
fs/lockd/svc.c +12 -11
@@ -56,7 +56,6 @@ static DEFINE_MUTEX(nlmsvc_mutex);static unsigned int nlmsvc_users;static struct svc_serv *nlmsvc_serv;static struct task_struct *nlmsvc_task; -static struct svc_rqst *nlmsvc_rqst;unsigned long nlmsvc_timeout;unsigned int lockd_net_id;
@@ -182,6 +181,11 @@ lockd(void *vrqstp)nlm_shutdown_hosts ();cancel_delayed_work_sync (&ln->grace_period_end);locks_end_grace (&ln->lockd_manager); + +dprintk ("lockd_down: service stopped\n" ); + +svc_exit_thread (rqstp); +return 0 ; }
@@ -358,13 +362,14 @@ static void lockd_unregister_notifiers(void)static int lockd_start_svc (struct svc_serv *serv) {int error; +struct svc_rqst *rqst;/* * Create the kernel thread and wait for it to start. */ - nlmsvc_rqst =svc_prepare_thread (serv, &serv->sv_pools[0 ],NUMA_NO_NODE ); -if (IS_ERR (nlmsvc_rqst)) { - error =PTR_ERR (nlmsvc_rqst); + rqst =svc_prepare_thread (serv, &serv->sv_pools[0 ],NUMA_NO_NODE ); +if (IS_ERR (rqst)) { + error =PTR_ERR (rqst);printk (KERN_WARNING "lockd_up: svc_rqst allocation failed, error=%d\n" , error);
@@ -374,24 +379,23 @@ static int lockd_start_svc(struct svc_serv *serv)svc_sock_update_bufs (serv); serv->sv_maxconn = nlm_max_connections; - nlmsvc_task =kthread_create (lockd, nlmsvc_rqst,"%s" , serv->sv_name); + nlmsvc_task =kthread_create (lockd, rqst,"%s" , serv->sv_name);if (IS_ERR (nlmsvc_task)) { error =PTR_ERR (nlmsvc_task);printk (KERN_WARNING "lockd_up: kthread_run failed, error=%d\n" , error); goto out_task; } - nlmsvc_rqst->rq_task = nlmsvc_task; + rqst->rq_task = nlmsvc_task;wake_up_process (nlmsvc_task);dprintk ("lockd_up: service started\n" );return 0 ; out_task: -svc_exit_thread (nlmsvc_rqst); +svc_exit_thread (rqst); nlmsvc_task =NULL ; out_rqst: - nlmsvc_rqst =NULL ;return error; }
@@ -500,9 +504,6 @@ lockd_down(struct net *net) }lockd_unregister_notifiers ();kthread_stop (nlmsvc_task); -dprintk ("lockd_down: service stopped\n" ); -svc_exit_thread (nlmsvc_rqst); - nlmsvc_rqst =NULL ;dprintk ("lockd_down: service destroyed\n" ); nlmsvc_serv =NULL ; nlmsvc_task =NULL ;
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 240/690 lockd: introduce lockd_put()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: NeilBrown <[email protected]>
[ Upstream commit 865b674069e05e5779fcf8cf7a166d2acb7e930b ]
There is some cleanup that is duplicated in lockd_down() and the failure path of lockd_up().
Factor these out into a new lockd_put() and call it from both places.
lockd_put() does *not* take the mutex - that must be held by the caller. It decrements nlmsvc_users and if that reaches zero, it cleans up.
--- fs/lockd/svc.c | 64 +++++++++++++++++++++----------------------------- 1 file changed, 27 insertions(+), 37 deletions(-)
fs/lockd/svc.c +27 -37
@@ -351,14 +351,6 @@ static struct notifier_block lockd_inet6addr_notifier = { };#endif -static void lockd_unregister_notifiers (void ) -{ -unregister_inetaddr_notifier (&lockd_inetaddr_notifier); -#if IS_ENABLED (CONFIG_IPV6 ) -unregister_inet6addr_notifier (&lockd_inet6addr_notifier); -#endif -} -static int lockd_start_svc (struct svc_serv *serv) {int error;
@@ -450,6 +442,27 @@ static int lockd_create_svc(void)return 0 ; } +static void lockd_put (void ) +{ +if (WARN (nlmsvc_users <=0 ,"lockd_down: no users!\n" )) +return ; +if (--nlmsvc_users) +return ; + +unregister_inetaddr_notifier (&lockd_inetaddr_notifier); +#if IS_ENABLED (CONFIG_IPV6 ) +unregister_inet6addr_notifier (&lockd_inet6addr_notifier); +#endif + +if (nlmsvc_task) { +kthread_stop (nlmsvc_task); +dprintk ("lockd_down: service stopped\n" ); + nlmsvc_task =NULL ; + } + nlmsvc_serv =NULL ; +dprintk ("lockd_down: service destroyed\n" ); +} +/* * Bring up the lockd process if it's not already up. */
@@ -461,21 +474,16 @@ int lockd_up(struct net *net, const struct cred *cred) error =lockd_create_svc ();if (error) - goto err_create; + goto err; + nlmsvc_users++; error =lockd_up_net (nlmsvc_serv, net, cred);if (error <0 ) { - goto err_put; +lockd_put (); + goto err; } - nlmsvc_users++; -err_put: -if (nlmsvc_users ==0 ) { -lockd_unregister_notifiers (); -kthread_stop (nlmsvc_task); - nlmsvc_serv =NULL ; - } -err_create: +err:mutex_unlock (&nlmsvc_mutex);return error; }
@@ -489,25 +497,7 @@ lockd_down(struct net *net) {mutex_lock (&nlmsvc_mutex);lockd_down_net (nlmsvc_serv, net); -if (nlmsvc_users) { -if (--nlmsvc_users) - goto out; - }else { -printk (KERN_ERR "lockd_down: no users! task=%p\n" , - nlmsvc_task); -BUG (); - } - -if (!nlmsvc_task) { -printk (KERN_ERR "lockd_down: no lockd running.\n" ); -BUG (); - } -lockd_unregister_notifiers (); -kthread_stop (nlmsvc_task); -dprintk ("lockd_down: service destroyed\n" ); - nlmsvc_serv =NULL ; - nlmsvc_task =NULL ; -out: +lockd_put ();mutex_unlock (&nlmsvc_mutex); }EXPORT_SYMBOL_GPL (lockd_down);
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 241/690 lockd: rename lockd_create_svc() to lockd_get()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: NeilBrown <[email protected]>
[ Upstream commit ecd3ad68d2c6d3ae178a63a2d9a02c392904fd36 ]
lockd_create_svc() already does an svc_get() if the service already exists, so it is more like a "get" than a "create".
So:
- Move the increment of nlmsvc_users into the function as well
- rename to lockd_get().
It is now the inverse of lockd_put().
--- fs/lockd/svc.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
fs/lockd/svc.c +4 -6
@@ -396,16 +396,14 @@ static const struct svc_serv_ops lockd_sv_ops = { .svo_enqueue_xprt = svc_xprt_do_enqueue, }; -static int lockd_create_svc (void ) +static int lockd_get (void ) {struct svc_serv *serv;int error; -/* -* Check whether we're already up and running. -*/ if (nlmsvc_serv) {svc_get (nlmsvc_serv); + nlmsvc_users++;return 0 ; }
@@ -439,6 +437,7 @@ static int lockd_create_svc(void)register_inet6addr_notifier (&lockd_inet6addr_notifier);#endif dprintk ("lockd_up: service created\n" ); + nlmsvc_users++;return 0 ; }
@@ -472,10 +471,9 @@ int lockd_up(struct net *net, const struct cred *cred)mutex_lock (&nlmsvc_mutex); - error =lockd_create_svc (); + error =lockd_get ();if (error) goto err; - nlmsvc_users++; error =lockd_up_net (nlmsvc_serv, net, cred);if (error <0 ) {
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 242/690 SUNRPC: move the pool_map definitions (back) into svc.c
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: NeilBrown <[email protected]>
[ Upstream commit cf0e124e0a489944d08fcc3c694d2b234d2cc658 ]
These definitions are not used outside of svc.c, and there is no evidence that they ever have been. So move them into svc.c and make the declarations 'static'.
--- include/linux/sunrpc/svc.h | 25 ------------------------- net/sunrpc/svc.c | 31 +++++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 31 deletions(-)
include/linux/sunrpc/svc.h +0 -25
@@ -496,29 +496,6 @@ struct svc_procedure {const char * pc_name;/* for display */ }; -/* -* Mode for mapping cpus to pools. -*/ -enum { -SVC_POOL_AUTO =-1 ,/* choose one of the others */ -SVC_POOL_GLOBAL ,/* no mapping, just a single global pool -* (legacy & UP mode) */ -SVC_POOL_PERCPU ,/* one pool per cpu */ -SVC_POOL_PERNODE /* one pool per numa node */ -}; - -struct svc_pool_map { -int count;/* How many svc_servs use us */ -int mode;/* Note: int not enum to avoid -* warnings about "enumeration value -* not handled in switch" */ -unsigned int npools; -unsigned int *pool_to;/* maps pool id to cpu or node */ -unsigned int *to_pool;/* maps cpu or node to pool id */ -}; - -extern struct svc_pool_map svc_pool_map; -/* * Function prototypes. */
@@ -535,8 +512,6 @@ void svc_rqst_replace_page(struct svc_rqst *rqstp, struct page *page);void svc_rqst_free (struct svc_rqst *);void svc_exit_thread (struct svc_rqst *); -unsigned int svc_pool_map_get (void ); -void svc_pool_map_put (void );struct svc_serv *svc_create_pooled (struct svc_program *,unsigned int ,const struct svc_serv_ops *);int svc_set_num_threads (struct svc_serv *,struct svc_pool *,int );
net/sunrpc/svc.c +25 -6
@@ -41,14 +41,35 @@ static void svc_unregister(const struct svc_serv *serv, struct net *net);#define SVC_POOL_DEFAULT SVC_POOL_GLOBAL +/* +* Mode for mapping cpus to pools. +*/ +enum { +SVC_POOL_AUTO =-1 ,/* choose one of the others */ +SVC_POOL_GLOBAL ,/* no mapping, just a single global pool +* (legacy & UP mode) */ +SVC_POOL_PERCPU ,/* one pool per cpu */ +SVC_POOL_PERNODE /* one pool per numa node */ +}; +/* * Structure for mapping cpus to pools and vice versa. * Setup once during sunrpc initialisation. */ -struct svc_pool_map svc_pool_map = { + +struct svc_pool_map { +int count;/* How many svc_servs use us */ +int mode;/* Note: int not enum to avoid +* warnings about "enumeration value +* not handled in switch" */ +unsigned int npools; +unsigned int *pool_to;/* maps pool id to cpu or node */ +unsigned int *to_pool;/* maps cpu or node to pool id */ +}; + +static struct svc_pool_map svc_pool_map = { .mode =SVC_POOL_DEFAULT }; -EXPORT_SYMBOL_GPL (svc_pool_map);static DEFINE_MUTEX (svc_pool_map_mutex);/* protects svc_pool_map.count only */
@@ -222,7 +243,7 @@ svc_pool_map_init_pernode(struct svc_pool_map *m)* vice versa). Initialise the map if we're the first user. * Returns the number of pools. */ -unsigned int +static unsigned int svc_pool_map_get (void ) {struct svc_pool_map *m = &svc_pool_map;
@@ -257,7 +278,6 @@ svc_pool_map_get(void)mutex_unlock (&svc_pool_map_mutex);return m->npools; } -EXPORT_SYMBOL_GPL (svc_pool_map_get);/* * Drop a reference to the global map of cpus to pools.
@@ -266,7 +286,7 @@ EXPORT_SYMBOL_GPL(svc_pool_map_get);* mode using the pool_mode module option without * rebooting or re-loading sunrpc.ko. */ -void +static void svc_pool_map_put (void ) {struct svc_pool_map *m = &svc_pool_map;
@@ -283,7 +303,6 @@ svc_pool_map_put(void)mutex_unlock (&svc_pool_map_mutex); } -EXPORT_SYMBOL_GPL (svc_pool_map_put);static int svc_pool_map_get_node (unsigned int pidx) {
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 243/690 SUNRPC: always treat sv_nrpools==1 as "not pooled"
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: NeilBrown <[email protected]>
[ Upstream commit 93aa619eb0b42eec2f3a9b4d9db41f5095390aec ]
Currently 'pooled' services hold a reference on the pool_map, and 'unpooled' services do not.svc_destroy() uses the presence of ->svo_function (via svc_serv_is_pooled()) to determine if the reference should be dropped. There is no direct correlation between being pooled and the use of svo_function, though in practice, lockd is the only non-pooled service, and the only one not to use svo_function.
This is untidy and would cause problems if we changed lockd to use svc_set_num_threads(), which requires the use of ->svo_function.
So change the test for "is the service pooled" to "is sv_nrpools > 1".
This means that when svc_pool_map_get() returns 1, it must NOT take a reference to the pool.
We discard svc_serv_is_pooled(), and test sv_nrpools directly.
--- net/sunrpc/svc.c | 54 ++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 25 deletions(-)
net/sunrpc/svc.c +29 -25
@@ -37,8 +37,6 @@static void svc_unregister (const struct svc_serv *serv,struct net *net); -#define svc_serv_is_pooled (serv) ((serv)->sv_ops->svo_function) -#define SVC_POOL_DEFAULT SVC_POOL_GLOBAL/*
@@ -240,8 +238,10 @@ svc_pool_map_init_pernode(struct svc_pool_map *m)/* * Add a reference to the global map of cpus to pools (and -* vice versa). Initialise the map if we're the first user. -* Returns the number of pools. +* vice versa) if pools are in use. +* Initialise the map if we're the first user. +* Returns the number of pools. If this is '1', no reference +* was taken. */ static unsigned int svc_pool_map_get (void )
@@ -253,6 +253,7 @@ svc_pool_map_get(void)if (m->count++) {mutex_unlock (&svc_pool_map_mutex); +WARN_ON_ONCE (m->npools <=1 );return m->npools; }
@@ -268,29 +269,36 @@ svc_pool_map_get(void)break ; } -if (npools <0 ) { +if (npools <=0 ) {/* default, or memory allocation failure */ npools =1 ; m->mode =SVC_POOL_GLOBAL ; } m->npools = npools; +if (npools ==1 ) +/* service is unpooled, so doesn't hold a reference */ + m->count--; +mutex_unlock (&svc_pool_map_mutex); -return m->npools; +return npools; }/* -* Drop a reference to the global map of cpus to pools. +* Drop a reference to the global map of cpus to pools, if +* pools were in use, i.e. if npools > 1. * When the last reference is dropped, the map data is * freed; this allows the sysadmin to change the pool * mode using the pool_mode module option without * rebooting or re-loading sunrpc.ko. */ static void -svc_pool_map_put (void ) +svc_pool_map_put (int npools) {struct svc_pool_map *m = &svc_pool_map; +if (npools <=1 ) +return ;mutex_lock (&svc_pool_map_mutex);if (!--m->count) {
@@ -359,21 +367,18 @@ svc_pool_for_cpu(struct svc_serv *serv, int cpu)struct svc_pool_map *m = &svc_pool_map;unsigned int pidx =0 ; -/* -* An uninitialised map happens in a pure client when -* lockd is brought up, so silently treat it the -* same as SVC_POOL_GLOBAL. -*/ -if (svc_serv_is_pooled (serv)) { -switch (m->mode) { -case SVC_POOL_PERCPU : - pidx = m->to_pool[cpu]; -break ; -case SVC_POOL_PERNODE : - pidx = m->to_pool[cpu_to_node (cpu)]; -break ; - } +if (serv->sv_nrpools <=1 ) +return serv->sv_pools; + +switch (m->mode) { +case SVC_POOL_PERCPU : + pidx = m->to_pool[cpu]; +break ; +case SVC_POOL_PERNODE : + pidx = m->to_pool[cpu_to_node (cpu)]; +break ; } +return &serv->sv_pools[pidx % serv->sv_nrpools]; }
@@ -526,7 +531,7 @@ svc_create_pooled(struct svc_program *prog, unsigned int bufsize, goto out_err;return serv; out_err: -svc_pool_map_put (); +svc_pool_map_put (npools);return NULL ; }EXPORT_SYMBOL_GPL (svc_create_pooled);
@@ -561,8 +566,7 @@ svc_destroy(struct kref *ref)cache_clean_deferred (serv); -if (svc_serv_is_pooled (serv)) -svc_pool_map_put (); +svc_pool_map_put (serv->sv_nrpools);kfree (serv->sv_pools);kfree (serv);
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 244/690 lockd: use svc_set_num_threads() for thread start and stop
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: NeilBrown <[email protected]>
[ Upstream commit 6b044fbaab02292fedb17565dbb3f2528083b169 ]
svc_set_num_threads() does everything that lockd_start_svc() does, except set sv_maxconn. It also (when passed 0) finds the threads and stops them with kthread_stop().
So move the setting for sv_maxconn, and use svc_set_num_thread()
We now don't need nlmsvc_task.
Now that we use svc_set_num_threads() it makes sense to set svo_module. This request that the thread exists with module_put_and_exit(). Also fix the documentation for svo_module to make this explicit.
svc_prepare_thread is now only used where it is defined, so it can be made static.
--- fs/lockd/svc.c | 58 ++++++-------------------------------- include/linux/sunrpc/svc.h | 6 ++-- net/sunrpc/svc.c | 3 +- 3 files changed, 12 insertions(+), 55 deletions(-)
fs/lockd/svc.c +8 -50
@@ -55,7 +55,6 @@ EXPORT_SYMBOL_GPL(nlmsvc_ops);static DEFINE_MUTEX (nlmsvc_mutex);static unsigned int nlmsvc_users;static struct svc_serv *nlmsvc_serv; -static struct task_struct *nlmsvc_task;unsigned long nlmsvc_timeout;unsigned int lockd_net_id;
@@ -186,7 +185,7 @@ lockd(void *vrqstp)svc_exit_thread (rqstp); -return 0 ; +module_put_and_kthread_exit (0 ); } static int create_lockd_listener(struct svc_serv *serv, const char *name,
@@ -292,8 +291,8 @@ static void lockd_down_net(struct svc_serv *serv, struct net *net) __func__, net->ns.inum); } }else { -pr_err ("%s: no users! task=%p, net=%x\n" , - __func__, nlmsvc_task, net->ns.inum); +pr_err ("%s: no users! net=%x\n" , + __func__, net->ns.inum);BUG (); } }
@@ -351,49 +350,11 @@ static struct notifier_block lockd_inet6addr_notifier = { };#endif -static int lockd_start_svc (struct svc_serv *serv) -{ -int error; -struct svc_rqst *rqst; - -/* -* Create the kernel thread and wait for it to start. -*/ - rqst =svc_prepare_thread (serv, &serv->sv_pools[0 ],NUMA_NO_NODE ); -if (IS_ERR (rqst)) { - error =PTR_ERR (rqst); -printk (KERN_WARNING -"lockd_up: svc_rqst allocation failed, error=%d\n" , - error); - goto out_rqst; - } - -svc_sock_update_bufs (serv); - serv->sv_maxconn = nlm_max_connections; - - nlmsvc_task =kthread_create (lockd, rqst,"%s" , serv->sv_name); -if (IS_ERR (nlmsvc_task)) { - error =PTR_ERR (nlmsvc_task); -printk (KERN_WARNING -"lockd_up: kthread_run failed, error=%d\n" , error); - goto out_task; - } - rqst->rq_task = nlmsvc_task; -wake_up_process (nlmsvc_task); - -dprintk ("lockd_up: service started\n" ); -return 0 ; - -out_task: -svc_exit_thread (rqst); - nlmsvc_task =NULL ; -out_rqst: -return error; -} -static const struct svc_serv_ops lockd_sv_ops = { .svo_shutdown = svc_rpcb_cleanup, + .svo_function = lockd, .svo_enqueue_xprt = svc_xprt_do_enqueue, + .svo_module =THIS_MODULE , };static int lockd_get (void )
@@ -425,7 +386,8 @@ static int lockd_get(void)return -ENOMEM ; } - error =lockd_start_svc (serv); + serv->sv_maxconn = nlm_max_connections; + error =svc_set_num_threads (serv,NULL ,1 );/* The thread now holds the only reference */ svc_put (serv);if (error <0 )
@@ -453,11 +415,7 @@ static void lockd_put(void)unregister_inet6addr_notifier (&lockd_inet6addr_notifier);#endif -if (nlmsvc_task) { -kthread_stop (nlmsvc_task); -dprintk ("lockd_down: service stopped\n" ); - nlmsvc_task =NULL ; - } +svc_set_num_threads (nlmsvc_serv,NULL ,0 ); nlmsvc_serv =NULL ;dprintk ("lockd_down: service destroyed\n" ); }
include/linux/sunrpc/svc.h +3 -3
@@ -64,7 +64,9 @@ struct svc_serv_ops {/* queue up a transport for servicing */ void (*svo_enqueue_xprt)(struct svc_xprt *); -/* optional module to count when adding threads (pooled svcs only) */ +/* optional module to count when adding threads. +* Thread function must call module_put_and_kthread_exit() to exit. +*/ struct module *svo_module; };
@@ -506,8 +508,6 @@ struct svc_serv *svc_create(struct svc_program *, unsigned int, const struct svc_serv_ops *);struct svc_rqst *svc_rqst_alloc (struct svc_serv *serv,struct svc_pool *pool,int node); -struct svc_rqst *svc_prepare_thread (struct svc_serv *serv, -struct svc_pool *pool,int node);void svc_rqst_replace_page (struct svc_rqst *rqstp,struct page *page);void svc_rqst_free (struct svc_rqst *);
net/sunrpc/svc.c +1 -2
@@ -652,7 +652,7 @@ svc_rqst_alloc(struct svc_serv *serv, struct svc_pool *pool, int node) }EXPORT_SYMBOL_GPL (svc_rqst_alloc); -struct svc_rqst * +static struct svc_rqst *svc_prepare_thread (struct svc_serv *serv,struct svc_pool *pool,int node) {struct svc_rqst *rqstp;
@@ -672,7 +672,6 @@ svc_prepare_thread(struct svc_serv *serv, struct svc_pool *pool, int node)spin_unlock_bh (&pool->sp_lock);return rqstp; } -EXPORT_SYMBOL_GPL (svc_prepare_thread);/* * Choose a pool in which to create a new thread, for svc_set_num_threads
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 245/690 NFS: switch the callback service back to non-pooled.
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: NeilBrown <[email protected]>
[ Upstream commit 23a1a573c61ccb5e7829c1f5472d3e025293a031 ]
Now that thread management is consistent there is no need for nfs-callback to use svc_create_pooled() as introduced in Commit df807fffaabd ("NFSv4.x/callback: Create the callback service through svc_create_pooled"). So switch back to svc_create().
If service pools were configured, but the number of threads were left at '1', nfs callback may not work reliably when svc_create_pooled() is used.
--- fs/nfs/callback.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/callback.c +1 -1
@@ -286,7 +286,7 @@ static struct svc_serv *nfs_callback_create_svc(int minorversion)printk (KERN_WARNING "nfs_callback_create_svc: no kthread, %d users??\n" , cb_info->users); - serv =svc_create_pooled (&nfs4_callback_program,NFS4_CALLBACK_BUFSIZE , sv_ops); + serv =svc_create (&nfs4_callback_program,NFS4_CALLBACK_BUFSIZE , sv_ops);if (!serv) {printk (KERN_ERR "nfs_callback_create_svc: create service failed\n" );return ERR_PTR (-ENOMEM );
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 246/690 NFSD: Remove be32_to_cpu() from DRC hash function
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 7578b2f628db27281d3165af0aa862311883a858 ]
Commit 7142b98d9fd7 ("nfsd: Clean up drc cache in preparation for global spinlock elimination"), billed as a clean-up, added be32_to_cpu() to the DRC hash function without explanation. That commit removed two comments that state that byte-swapping in the hash function is unnecessary without explaining whether there was a need for that change.
On some Intel CPUs, the swab32 instruction is known to cause a CPU pipeline stall. be32_to_cpu() does not add extra randomness, since the hash multiplication is done /before/ shifting to the high-order bits of the result.
As a micro-optimization, remove the unnecessary transform from the DRC hash function.
--- fs/nfsd/nfscache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfsd/nfscache.c +1 -1
@@ -87,7 +87,7 @@ nfsd_hashsize(unsigned int limit)static u32 nfsd_cache_hash (__be32 xid,struct nfsd_net *nn) { -return hash_32 (be32_to_cpu (xid), nn->maskbits); +return hash_32 ((__force u32 )xid, nn->maskbits); } static struct svc_cacherep *
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 247/690 NFSD: Fix inconsistent indenting
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiapeng Chong <[email protected]>
[ Upstream commit 1e37d0e5bda45881eea1bec4b812def72c7d4aea ]
Eliminate the follow smatch warning:
fs/nfsd/nfs4xdr.c:4766 nfsd4_encode_read_plus_hole() warn: inconsistent indenting.
--- fs/nfsd/nfs4xdr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/nfsd/nfs4xdr.c +2 -2
@@ -4807,8 +4807,8 @@ nfsd4_encode_read_plus_hole(struct nfsd4_compoundres *resp,return nfserr_resource; *p++ =htonl (NFS4_CONTENT_HOLE ); - p =xdr_encode_hyper (p, read->rd_offset); - p =xdr_encode_hyper (p, count); + p =xdr_encode_hyper (p, read->rd_offset); + p =xdr_encode_hyper (p, count); *eof = (read->rd_offset + count) >= f_size; *maxcount = min_t(unsigned long, count, *maxcount);
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 248/690 NFSD: simplify per-net file cache management
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: NeilBrown <[email protected]>
[ Upstream commit 1463b38e7cf34d4cc60f41daff459ad807b2e408 ]
We currently have a 'laundrette' for closing cached files - a different work-item for each network-namespace.
These 'laundrettes' (aka struct nfsd_fcache_disposal) are currently on a list, and are freed using rcu.
The list is not necessary as we have a per-namespace structure (struct nfsd_net) which can hold a link to the nfsd_fcache_disposal. The use of kfree_rcu is also unnecessary as the cache is cleaned of all files associated with a given namespace, and no new files can be added, before the nfsd_fcache_disposal is freed.
So add a '->fcache_disposal' link to nfsd_net, and discard the list management and rcu usage.
--- fs/nfsd/filecache.c | 76 +++++++++------------------------------------ fs/nfsd/netns.h | 2 ++ 2 files changed, 17 insertions(+), 61 deletions(-)
fs/nfsd/filecache.c +15 -61
@@ -44,12 +44,9 @@ struct nfsd_fcache_bucket { static DEFINE_PER_CPU(unsigned long, nfsd_file_cache_hits);struct nfsd_fcache_disposal { -struct list_head list;struct work_struct work; -struct net *net;spinlock_t lock;struct list_head freeme; -struct rcu_head rcu; };static struct workqueue_struct *nfsd_filecache_wq__read_mostly ;
@@ -62,8 +59,6 @@ static long nfsd_file_lru_flags;static struct fsnotify_group *nfsd_file_fsnotify_group;static atomic_long_t nfsd_filecache_count;static struct delayed_work nfsd_filecache_laundrette; -static DEFINE_SPINLOCK (laundrette_lock); -static LIST_HEAD (laundrettes);static void nfsd_file_gc (void );
@@ -360,19 +355,13 @@ nfsd_file_list_remove_disposal(struct list_head *dst,static void nfsd_file_list_add_disposal (struct list_head *files,struct net *net) { -struct nfsd_fcache_disposal *l; +struct nfsd_net *nn =net_generic (net, nfsd_net_id); +struct nfsd_fcache_disposal *l = nn->fcache_disposal; -rcu_read_lock (); -list_for_each_entry_rcu (l, &laundrettes, list) { -if (l->net == net) { -spin_lock (&l->lock); -list_splice_tail_init (files, &l->freeme); -spin_unlock (&l->lock); -queue_work (nfsd_filecache_wq, &l->work); -break ; - } - } -rcu_read_unlock (); +spin_lock (&l->lock); +list_splice_tail_init (files, &l->freeme); +spin_unlock (&l->lock); +queue_work (nfsd_filecache_wq, &l->work); } static void
@@ -748,7 +737,7 @@ nfsd_file_cache_purge(struct net *net) }static struct nfsd_fcache_disposal * -nfsd_alloc_fcache_disposal (struct net *net) +nfsd_alloc_fcache_disposal (void ) {struct nfsd_fcache_disposal *l;
@@ -756,7 +745,6 @@ nfsd_alloc_fcache_disposal(struct net *net)if (!l)return NULL ;INIT_WORK (&l->work, nfsd_file_delayed_close); - l->net = net;spin_lock_init (&l->lock);INIT_LIST_HEAD (&l->freeme);return l;
@@ -765,61 +753,27 @@ nfsd_alloc_fcache_disposal(struct net *net)static void nfsd_free_fcache_disposal (struct nfsd_fcache_disposal *l) { -rcu_assign_pointer (l->net,NULL );cancel_work_sync (&l->work);nfsd_file_dispose_list (&l->freeme); -kfree_rcu (l, rcu); -} - -static void -nfsd_add_fcache_disposal (struct nfsd_fcache_disposal *l) -{ -spin_lock (&laundrette_lock); -list_add_tail_rcu (&l->list, &laundrettes); -spin_unlock (&laundrette_lock); -} - -static void -nfsd_del_fcache_disposal (struct nfsd_fcache_disposal *l) -{ -spin_lock (&laundrette_lock); -list_del_rcu (&l->list); -spin_unlock (&laundrette_lock); -} - -static int -nfsd_alloc_fcache_disposal_net (struct net *net) -{ -struct nfsd_fcache_disposal *l; - - l =nfsd_alloc_fcache_disposal (net); -if (!l) -return -ENOMEM ; -nfsd_add_fcache_disposal (l); -return 0 ; +kfree (l); }static void nfsd_free_fcache_disposal_net (struct net *net) { -struct nfsd_fcache_disposal *l; +struct nfsd_net *nn =net_generic (net, nfsd_net_id); +struct nfsd_fcache_disposal *l = nn->fcache_disposal; -rcu_read_lock (); -list_for_each_entry_rcu (l, &laundrettes, list) { -if (l->net != net) -continue ; -nfsd_del_fcache_disposal (l); -rcu_read_unlock (); -nfsd_free_fcache_disposal (l); -return ; - } -rcu_read_unlock (); +nfsd_free_fcache_disposal (l); }int nfsd_file_cache_start_net (struct net *net) { -return nfsd_alloc_fcache_disposal_net (net); +struct nfsd_net *nn =net_generic (net, nfsd_net_id); + + nn->fcache_disposal =nfsd_alloc_fcache_disposal (); +return nn->fcache_disposal ?0 : -ENOMEM ; }void
fs/nfsd/netns.h +2 -0
@@ -185,6 +185,8 @@ struct nfsd_net {/* utsname taken from the process that starts the server */ char nfsd_name[UNX_MAXNODENAME +1 ]; + +struct nfsd_fcache_disposal *fcache_disposal; };/* Simple check to find out if a given net was properly initialized */
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 249/690 NFSD: Combine XDR error tracepoints
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 70e94d757b3e1f46486d573729d84c8955c81dce ]
Clean up: The garbage_args and cant_encode tracepoints report the same information as each other, so combine them into a single tracepoint class to reduce code duplication and slightly reduce the size of trace.o.
--- fs/nfsd/trace.h | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-)
fs/nfsd/trace.h +7 -21
@@ -47,7 +47,7 @@ rqstp->rq_xprt->xpt_remotelen); \ }while (0 ); -TRACE_EVENT(nfsd_garbage_args_err, +DECLARE_EVENT_CLASS(nfsd_xdr_err_class, TP_PROTO( const struct svc_rqst *rqstp ),
@@ -69,27 +69,13 @@ TRACE_EVENT(nfsd_garbage_args_err, ) ); -TRACE_EVENT (nfsd_cant_encode_err, -TP_PROTO ( - const struct svc_rqst *rqstp - ), -TP_ARGS (rqstp), -TP_STRUCT__entry ( - NFSD_TRACE_PROC_ARG_FIELDS +#define DEFINE_NFSD_XDR_ERR_EVENT (name) \ +DEFINE_EVENT(nfsd_xdr_err_class, nfsd_##name##_err, \ + TP_PROTO(const struct svc_rqst *rqstp), \ + TP_ARGS(rqstp)) - __field(u32, vers) -__field (u32, proc) - ), -TP_fast_assign ( -NFSD_TRACE_PROC_ARG_ASSIGNMENTS - - __entry->vers = rqstp->rq_vers; - __entry->proc = rqstp->rq_proc; - ), -TP_printk ("xid=0x%08x vers=%u proc=%u" , - __entry->xid, __entry->vers, __entry->proc - ) -); +DEFINE_NFSD_XDR_ERR_EVENT (garbage_args); +DEFINE_NFSD_XDR_ERR_EVENT (cant_encode);#define show_nfsd_may_flags (x) \ __print_flags(x, "|", \
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 250/690 nfsd: improve stateid access bitmask documentation
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: J. Bruce Fields <[email protected]>
[ Upstream commit 3dcd1d8aab00c5d3a0a3725253c86440b1a0f5a7 ]
The use of the bitmaps is confusing. Add a cross-reference to make it easier to find the existing comment. Add an updated reference with URL to make it quicker to look up. And a bit more editorializing about the value of this.
--- fs/nfsd/nfs4state.c | 14 ++++++++++---- fs/nfsd/state.h | 4 ++++ 2 files changed, 14 insertions(+), 4 deletions(-)
fs/nfsd/nfs4state.c +10 -4
@@ -360,11 +360,13 @@ static const struct nfsd4_callback_ops nfsd4_cb_notify_lock_ops = {* st_{access,deny}_bmap field of the stateid, in order to track not * only what share bits are currently in force, but also what * combinations of share bits previous opens have used. This allows us -* to enforce the recommendation of rfc 3530 14.2.19 that the server -* return an error if the client attempt to downgrade to a combination -* of share bits not explicable by closing some of its previous opens. +* to enforce the recommendation in +* https://datatracker.ietf.org/doc/html/rfc7530#section-16.19.4 that +* the server return an error if the client attempt to downgrade to a +* combination of share bits not explicable by closing some of its +* previous opens. * -* XXX: This enforcement is actually incomplete, since we don't keep +* This enforcement is arguably incomplete, since we don't keep * track of access/deny bit combinations; so, e.g., we allow: * * OPEN allow read, deny write
@@ -372,6 +374,10 @@ static const struct nfsd4_callback_ops nfsd4_cb_notify_lock_ops = {* DOWNGRADE allow read, deny none * * which we should reject. +* +* But you could also argue that our current code is already overkill, +* since it only exists to return NFS4ERR_INVAL on incorrect client +* behavior. */ static unsigned int bmap_to_share_mode (unsigned long bmap)
fs/nfsd/state.h +4 -0
@@ -568,6 +568,10 @@ struct nfs4_ol_stateid {struct list_head st_locks;struct nfs4_stateowner *st_stateowner;struct nfs4_clnt_odstate *st_clnt_odstate; +/* +* These bitmasks use 3 separate bits for READ, ALLOW, and BOTH; see the +* comment above bmap_to_share_mode() for explanation: +*/ unsigned char st_access_bmap;unsigned char st_deny_bmap;struct nfs4_ol_stateid *st_openstp;
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 251/690 NFSD: De-duplicate nfsd4_decode_bitmap4()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit cd2e999c7c394ae916d8be741418b3c6c1dddea8 ]
Clean up. Trond points out that xdr_stream_decode_uint32_array() does the same thing as nfsd4_decode_bitmap4().
--- fs/nfsd/nfs4xdr.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-)
fs/nfsd/nfs4xdr.c +3 -14
@@ -277,21 +277,10 @@ nfsd4_decode_verifier4(struct nfsd4_compoundargs *argp, nfs4_verifier *verf)static __be32 nfsd4_decode_bitmap4 (struct nfsd4_compoundargs *argp,u32 *bmval,u32 bmlen) { -u32 i, count; -__be32 *p; - -if (xdr_stream_decode_u32 (argp->xdr, &count) <0 ) -return nfserr_bad_xdr; -/* request sanity */ -if (count >1000 ) -return nfserr_bad_xdr; - p =xdr_inline_decode (argp->xdr, count <<2 ); -if (!p) -return nfserr_bad_xdr; -for (i =0 ; i < bmlen; i++) - bmval[i] = (i < count) ?be32_to_cpup (p++) :0 ; +ssize_t status; -return nfs_ok; + status =xdr_stream_decode_uint32_array (argp->xdr, bmval, bmlen); +return status == -EBADMSG ? nfserr_bad_xdr : nfs_ok; } static __be32
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 252/690 nfs: block notification on fs with its own ->lock
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: J. Bruce Fields <[email protected]>
[ Upstream commit 40595cdc93edf4110c0f0c0b06f8d82008f23929 ]
NFSv4.1 supports an optional lock notification feature which notifies the client when a lock comes available. (Normally NFSv4 clients just poll for locks if necessary.) To make that work, we need to request a blocking lock from the filesystem.
We turned that off for NFS in commit f657f8eef3ff ("nfs: don't atempt blocking locks on nfs reexports") [sic] because it actually blocks the nfsd thread while waiting for the lock.
Thanks to Vasily Averin for pointing out that NFS isn't the only filesystem with that problem.
Any filesystem that leaves ->lock NULL will use posix_lock_file(), which does the right thing. Simplest is just to assume that any filesystem that defines its own ->lock is not safe to request a blocking lock from.
So, this patch mostly reverts commit f657f8eef3ff ("nfs: don't atempt blocking locks on nfs reexports") [sic] and commit b840be2f00c0 ("lockd:
don't attempt blocking locks on nfs reexports"), and instead uses a check of ->lock (Vasily's suggestion) to decide whether to support blocking lock notifications on a given filesystem. Also add a little documentation.
Perhaps someday we could add back an export flag later to allow filesystems with "good" ->lock methods to support blocking lock notifications.
--- fs/lockd/svclock.c | 6 ++++-- fs/nfs/export.c | 2 +- fs/nfsd/nfs4state.c | 18 ++++++++++++------ include/linux/exportfs.h | 2 -- include/linux/lockd/lockd.h | 9 +++++++-- 5 files changed, 24 insertions(+), 13 deletions(-)
fs/lockd/svclock.c +4 -2
@@ -470,8 +470,10 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file, struct nlm_host *host, struct nlm_lock *lock, int wait, struct nlm_cookie *cookie, int reclaim) { - struct nlm_block *block = NULL; +#if IS_ENABLED(CONFIG_SUNRPC_DEBUG) struct inode *inode = nlmsvc_file_inode(file); +#endif +struct nlm_block *block =NULL ;int error;int mode;int async_block =0 ;
@@ -484,7 +486,7 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file, (long long )lock->fl.fl_end, wait); -if (inode->i_sb->s_export_op->flags &EXPORT_OP_SYNC_LOCKS ) { +if (nlmsvc_file_file (file)->f_op->lock) { async_block = wait; wait =0 ; }
fs/nfs/export.c +1 -1
@@ -180,5 +180,5 @@ const struct export_operations nfs_export_ops = { .fetch_iversion = nfs_fetch_iversion, .flags =EXPORT_OP_NOWCC |EXPORT_OP_NOSUBTREECHK |EXPORT_OP_CLOSE_BEFORE_UNLINK |EXPORT_OP_REMOTE_FS | - EXPORT_OP_NOATOMIC_ATTR|EXPORT_OP_SYNC_LOCKS, + EXPORT_OP_NOATOMIC_ATTR, };
fs/nfsd/nfs4state.c +12 -6
@@ -6874,7 +6874,6 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,struct nfsd4_blocked_lock *nbl =NULL ;struct file_lock *file_lock =NULL ;struct file_lock *conflock =NULL ; -struct super_block *sb;__be32 status =0 ;int lkflg;int err;
@@ -6896,7 +6895,6 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,dprintk ("NFSD: nfsd4_lock: permission denied!\n" );return status; } - sb = cstate->current_fh.fh_dentry->d_sb;if (lock->lk_is_new) {if (nfsd4_has_session (cstate))
@@ -6948,8 +6946,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, fp = lock_stp->st_stid.sc_file;switch (lock->lk_type) {case NFS4_READW_LT : -if (nfsd4_has_session (cstate) && - !(sb->s_export_op->flags &EXPORT_OP_SYNC_LOCKS )) +if (nfsd4_has_session (cstate)) fl_flags |=FL_SLEEP ; fallthrough;case NFS4_READ_LT :
@@ -6961,8 +6958,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, fl_type =F_RDLCK ;break ;case NFS4_WRITEW_LT : -if (nfsd4_has_session (cstate) && - !(sb->s_export_op->flags &EXPORT_OP_SYNC_LOCKS )) +if (nfsd4_has_session (cstate)) fl_flags |=FL_SLEEP ; fallthrough;case NFS4_WRITE_LT :
@@ -6983,6 +6979,16 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, goto out; } +/* +* Most filesystems with their own ->lock operations will block +* the nfsd thread waiting to acquire the lock. That leads to +* deadlocks (we don't want every nfsd thread tied up waiting +* for file locks), so don't attempt blocking lock notifications +* on those filesystems: +*/ +if (nf->nf_file->f_op->lock) + fl_flags &= ~FL_SLEEP ; + nbl =find_or_allocate_block (lock_sop, &fp->fi_fhandle, nn);if (!nbl) {dprintk ("NFSD: %s: unable to allocate block!\n" , __func__);
include/linux/exportfs.h +0 -2
@@ -221,8 +221,6 @@ struct export_operations {#define EXPORT_OP_NOATOMIC_ATTR (0x10)/* Filesystem cannot supply atomic attribute updates */ -#define EXPORT_OP_SYNC_LOCKS (0x20)/* Filesystem can't do -asychronous blocking locks */ unsigned long flags; };
include/linux/lockd/lockd.h +7 -2
@@ -303,10 +303,15 @@ void nlmsvc_invalidate_all(void);int nlmsvc_unlock_all_by_sb (struct super_block *sb);int nlmsvc_unlock_all_by_ip (struct sockaddr *server_addr); +static inline struct file *nlmsvc_file_file (struct nlm_file *file) +{ +return file->f_file[O_RDONLY ] ? + file->f_file[O_RDONLY ] : file->f_file[O_WRONLY ]; +} +static inline struct inode *nlmsvc_file_inode (struct nlm_file *file) { -return locks_inode (file->f_file[O_RDONLY ] ? - file->f_file[O_RDONLY ] : file->f_file[O_WRONLY ]); +return locks_inode (nlmsvc_file_file (file)); }static inline int __nlm_privileged_request4 (const struct sockaddr *sap)
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 253/690 nfsd4: add refcount for nfsd4_blocked_lock
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vasily Averin <[email protected]>
[ Upstream commit 47446d74f1707049067fee038507cdffda805631 ]
nbl allocated in nfsd4_lock can be released by a several ways:
directly in nfsd4_lock(), via nfs4_laundromat(), via another nfs command RELEASE_LOCKOWNER or via nfsd4_callback.
This structure should be refcounted to be used and released correctly in all these cases.
Refcount is initialized to 1 during allocation and is incremented when nbl is added into nbl_list/nbl_lru lists.
Usually nbl is linked into both lists together, so only one refcount is used for both lists.
However nfsd4_lock() should keep in mind that nbl can be present in one of lists only. This can happen if nbl was handled already by nfs4_laundromat/nfsd4_callback/etc.
Refcount is decremented if vfs_lock_file() returns FILE_LOCK_DEFERRED, because nbl can be handled already by nfs4_laundromat/nfsd4_callback/etc.
Refcount is not changed in find_blocked_lock() because of it reuses counter released after removing nbl from lists.
--- fs/nfsd/nfs4state.c | 25 ++++++++++++++++++++++--- fs/nfsd/state.h | 1 + 2 files changed, 23 insertions(+), 3 deletions(-)
fs/nfsd/nfs4state.c +22 -3
@@ -246,6 +246,7 @@ find_blocked_lock(struct nfs4_lockowner *lo, struct knfsd_fh *fh,list_for_each_entry (cur, &lo->lo_blocked, nbl_list) {if (fh_match (fh, &cur->nbl_fh)) {list_del_init (&cur->nbl_list); +WARN_ON (list_empty (&cur->nbl_lru));list_del_init (&cur->nbl_lru); found = cur;break ;
@@ -271,6 +272,7 @@ find_or_allocate_block(struct nfs4_lockowner *lo, struct knfsd_fh *fh,INIT_LIST_HEAD (&nbl->nbl_lru);fh_copy_shallow (&nbl->nbl_fh, fh);locks_init_lock (&nbl->nbl_lock); +kref_init (&nbl->nbl_kref);nfsd4_init_cb (&nbl->nbl_cb, lo->lo_owner.so_client, &nfsd4_cb_notify_lock_ops,NFSPROC4_CLNT_CB_NOTIFY_LOCK );
@@ -279,12 +281,21 @@ find_or_allocate_block(struct nfs4_lockowner *lo, struct knfsd_fh *fh,return nbl; } +static void +free_nbl (struct kref *kref) +{ +struct nfsd4_blocked_lock *nbl; + + nbl = container_of(kref, struct nfsd4_blocked_lock, nbl_kref); +kfree (nbl); +} +static void free_blocked_lock (struct nfsd4_blocked_lock *nbl) {locks_delete_block (&nbl->nbl_lock);locks_release_private (&nbl->nbl_lock); -kfree (nbl); +kref_put (&nbl->nbl_kref, free_nbl); } static void
@@ -302,6 +313,7 @@ remove_blocked_locks(struct nfs4_lockowner *lo) struct nfsd4_blocked_lock, nbl_list);list_del_init (&nbl->nbl_list); +WARN_ON (list_empty (&nbl->nbl_lru));list_move (&nbl->nbl_lru, &reaplist); }spin_unlock (&nn->blocked_locks_lock);
@@ -7019,6 +7031,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,spin_lock (&nn->blocked_locks_lock);list_add_tail (&nbl->nbl_list, &lock_sop->lo_blocked);list_add_tail (&nbl->nbl_lru, &nn->blocked_locks_lru); +kref_get (&nbl->nbl_kref);spin_unlock (&nn->blocked_locks_lock); }
@@ -7031,6 +7044,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, nn->somebody_reclaimed = true;break ;case FILE_LOCK_DEFERRED : +kref_put (&nbl->nbl_kref, free_nbl); nbl =NULL ; fallthrough;case -EAGAIN :/* conflock holds conflicting lock */
@@ -7051,8 +7065,13 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,/* dequeue it if we queued it before */ if (fl_flags &FL_SLEEP ) {spin_lock (&nn->blocked_locks_lock); -list_del_init (&nbl->nbl_list); -list_del_init (&nbl->nbl_lru); +if (!list_empty (&nbl->nbl_list) && + !list_empty (&nbl->nbl_lru)) { +list_del_init (&nbl->nbl_list); +list_del_init (&nbl->nbl_lru); +kref_put (&nbl->nbl_kref, free_nbl); + } +/* nbl can use one of lists to be linked to reaplist */ spin_unlock (&nn->blocked_locks_lock); }free_blocked_lock (nbl);
fs/nfsd/state.h +1 -0
@@ -633,6 +633,7 @@ struct nfsd4_blocked_lock {struct file_lock nbl_lock;struct knfsd_fh nbl_fh;struct nfsd4_callback nbl_cb; +struct kref nbl_kref; };struct nfsd4_compound_state ;
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 254/690 nfsd: map EBADF
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peng Tao <[email protected]>
[ Upstream commit b3d0db706c77d02055910fcfe2f6eb5155ff9d5e ]
Now that we have open file cache, it is possible that another client deletes the file and DP will not know about it. Then IO to MDS would fail with BADSTATEID and knfsd would start state recovery, which should fail as well and then nfs read/write will fail with EBADF. And it triggers a WARN() in nfserrno().
-----------[ cut here ]------------
WARNING: CPU: 0 PID: 13529 at fs/nfsd/nfsproc.c:758 nfserrno+0x58/0x70 [nfsd]() nfsd: non-standard errno: -9 modules linked in: nfsv3 nfs_layout_flexfiles rpcsec_gss_krb5 nfsv4 dns_resolver nfs fscache ip6t_rpfilter ip6t_REJECT nf_reject_ipv6 xt_connt pata_acpi floppy CPU: 0 PID: 13529 Comm: nfsd Tainted: G W 4.1.5-00307-g6e6579b #7 Hardware name: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 09/30/2014 0000000000000000 00000000464e6c9c ffff88079085fba8 ffffffff81789936 0000000000000000 ffff88079085fc00 ffff88079085fbe8 ffffffff810a08ea ffff88079085fbe8 ffff88080f45c900 ffff88080f627d50 ffff880790c46a48 all Trace: [<ffffffff81789936>] dump_stack+0x45/0x57 [<ffffffff810a08ea>] warn_slowpath_common+0x8a/0xc0 [<ffffffff810a0975>] warn_slowpath_fmt+0x55/0x70 [<ffffffff81252908>] ? splice_direct_to_actor+0x148/0x230 [<ffffffffa02fb8c0>] ? fsid_source+0x60/0x60 [nfsd] [<ffffffffa02f9918>] nfserrno+0x58/0x70 [nfsd] [<ffffffffa02fba57>] nfsd_finish_read+0x97/0xb0 [nfsd] [<ffffffffa02fc7a6>] nfsd_splice_read+0x76/0xa0 [nfsd] [<ffffffffa02fcca1>] nfsd_read+0xc1/0xd0 [nfsd] [<ffffffffa0233af2>] ? svc_tcp_adjust_wspace+0x12/0x30 [sunrpc] [<ffffffffa03073da>] nfsd3_proc_read+0xba/0x150 [nfsd] [<ffffffffa02f7a03>] nfsd_dispatch+0xc3/0x210 [nfsd] [<ffffffffa0233af2>] ? svc_tcp_adjust_wspace+0x12/0x30 [sunrpc] [<ffffffffa0232913>] svc_process_common+0x453/0x6f0 [sunrpc] [<ffffffffa0232cc3>] svc_process+0x113/0x1b0 [sunrpc] [<ffffffffa02f740f>] nfsd+0xff/0x170 [nfsd] [<ffffffffa02f7310>] ? nfsd_destroy+0x80/0x80 [nfsd] [<ffffffff810bf3a8>] kthread+0xd8/0xf0 [<ffffffff810bf2d0>] ? kthread_create_on_node+0x1b0/0x1b0 [<ffffffff817912a2>] ret_from_fork+0x42/0x70 [<ffffffff810bf2d0>] ? kthread_create_on_node+0x1b0/0x1b0
--- fs/nfsd/nfsproc.c | 1 + 1 file changed, 1 insertion(+)
fs/nfsd/nfsproc.c +1 -0
@@ -845,6 +845,7 @@ nfserrno (int errno) { nfserr_io, -EIO }, { nfserr_nxio, -ENXIO }, { nfserr_fbig, -E2BIG }, + { nfserr_stale, -EBADF }, { nfserr_acces, -EACCES }, { nfserr_exist, -EEXIST }, { nfserr_xdev, -EXDEV },
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 255/690 nfsd: Add errno mapping for EREMOTEIO
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeff Layton <[email protected]>
[ Upstream commit a2694e51f60c5a18c7e43d1a9feaa46d7f153e65 ]
The NFS client can occasionally return EREMOTEIO when signalling issues with the server. ...map to NFSERR_IO.
--- fs/nfsd/nfsproc.c | 1 + 1 file changed, 1 insertion(+)
fs/nfsd/nfsproc.c +1 -0
@@ -874,6 +874,7 @@ nfserrno (int errno) { nfserr_toosmall, -ETOOSMALL }, { nfserr_serverfault, -ESERVERFAULT }, { nfserr_serverfault, -ENFILE }, + { nfserr_io, -EREMOTEIO }, { nfserr_io, -EUCLEAN }, { nfserr_perm, -ENOKEY }, { nfserr_no_grace, -ENOGRACE},
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 256/690 nfsd: Retry once in nfsd_open on an -EOPENSTALE return
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeff Layton <[email protected]>
[ Upstream commit 12bcbd40fd931472c7fc9cf3bfe66799ece93ed8 ]
If we get back -EOPENSTALE from an NFSv4 open, then we either got some unhandled error or the inode we got back was not the same as the one associated with the dentry.
We really have no recourse in that situation other than to retry the open, and if it fails to just return nfserr_stale back to the client.
--- fs/nfsd/nfsproc.c | 1 + fs/nfsd/vfs.c | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-)
fs/nfsd/nfsproc.c +1 -0
@@ -875,6 +875,7 @@ nfserrno (int errno) { nfserr_serverfault, -ESERVERFAULT }, { nfserr_serverfault, -ENFILE }, { nfserr_io, -EREMOTEIO }, + { nfserr_stale, -EOPENSTALE }, { nfserr_io, -EUCLEAN }, { nfserr_perm, -ENOKEY }, { nfserr_no_grace, -ENOGRACE},
fs/nfsd/vfs.c +9 -1
@@ -791,6 +791,7 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type, int may_flags, struct file **filp) { __be32 err; +bool retried = false;validate_process_creds ();/*
@@ -806,9 +807,16 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, umode_t type,*/ if (type ==S_IFREG ) may_flags |=NFSD_MAY_OWNER_OVERRIDE ; +retry: err =fh_verify (rqstp, fhp, type, may_flags); -if (!err) +if (!err) { err =__nfsd_open (rqstp, fhp, type, may_flags, filp); +if (err == nfserr_stale && !retried) { + retried = true; +fh_put (fhp); + goto retry; + } + }validate_process_creds ();return err; }
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 257/690 NFSD: Clean up nfsd_vfs_write()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 33388b3aefefd4d83764dab8038cb54068161a44 ]
The RWF_SYNC and !RWF_SYNC arms are now exactly alike except that the RWF_SYNC arm resets the boot verifier twice in a row. Fix that redundancy and de-duplicate the code.
--- fs/nfsd/vfs.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-)
fs/nfsd/vfs.c +5 -16
@@ -1009,22 +1009,11 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf,iov_iter_kvec (&iter,WRITE , vec, vlen, *cnt); since =READ_ONCE (file->f_wb_err); -if (flags &RWF_SYNC ) { -if (verf) -nfsd_copy_boot_verifier (verf, -net_generic (SVC_NET (rqstp), - nfsd_net_id)); - host_err =vfs_iter_write (file, &iter, &pos, flags); -if (host_err <0 ) -nfsd_reset_boot_verifier (net_generic (SVC_NET (rqstp), - nfsd_net_id)); - }else { -if (verf) -nfsd_copy_boot_verifier (verf, -net_generic (SVC_NET (rqstp), - nfsd_net_id)); - host_err =vfs_iter_write (file, &iter, &pos, flags); - } +if (verf) +nfsd_copy_boot_verifier (verf, +net_generic (SVC_NET (rqstp), + nfsd_net_id)); + host_err =vfs_iter_write (file, &iter, &pos, flags);if (host_err <0 ) {nfsd_reset_boot_verifier (net_generic (SVC_NET (rqstp), nfsd_net_id));
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 258/690 NFSD: De-duplicate net_generic(SVC_NET(rqstp), nfsd_net_id)
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit fb7622c2dbd1aa41133a8c73e1137b833c074519 ]
Since this pointer is used repeatedly, move it to a stack variable.
--- fs/nfsd/vfs.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
fs/nfsd/vfs.c +4 -7
@@ -966,6 +966,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf, unsigned long *cnt, int stable, __be32 *verf) { + struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);struct file *file = nf->nf_file;struct super_block *sb =file_inode (file)->i_sb;struct svc_export *exp;
@@ -1010,13 +1011,10 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf,iov_iter_kvec (&iter,WRITE , vec, vlen, *cnt); since =READ_ONCE (file->f_wb_err);if (verf) -nfsd_copy_boot_verifier (verf, -net_generic (SVC_NET (rqstp), - nfsd_net_id)); +nfsd_copy_boot_verifier (verf, nn); host_err =vfs_iter_write (file, &iter, &pos, flags);if (host_err <0 ) { -nfsd_reset_boot_verifier (net_generic (SVC_NET (rqstp), - nfsd_net_id)); +nfsd_reset_boot_verifier (nn); goto out_nfserr; } *cnt = host_err;
@@ -1029,8 +1027,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf,if (stable && use_wgather) { host_err =wait_for_concurrent_writes (file);if (host_err <0 ) -nfsd_reset_boot_verifier (net_generic (SVC_NET (rqstp), - nfsd_net_id)); +nfsd_reset_boot_verifier (nn); } out_nfserr:
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 259/690 nfsd: Add a tracepoint for errors in nfsd4_clone_file_range()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Trond Myklebust <[email protected]>
[ Upstream commit a2f4c3fa4db94ba44d32a72201927cfd132a8e82 ]
Since a clone error commit can cause the boot verifier to change, we should trace those errors.
--- fs/nfsd/nfs4proc.c | 2 +- fs/nfsd/trace.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++ fs/nfsd/vfs.c | 18 +++++++++++++++-- fs/nfsd/vfs.h | 3 ++- 4 files changed, 69 insertions(+), 4 deletions(-)
fs/nfsd/nfs4proc.c +1 -1
@@ -1108,7 +1108,7 @@ nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,if (status) goto out; - status =nfsd4_clone_file_range (src, clone->cl_src_pos, + status =nfsd4_clone_file_range (rqstp, src, clone->cl_src_pos, dst, clone->cl_dst_pos, clone->cl_count,EX_ISSYNC (cstate->current_fh.fh_export));
fs/nfsd/trace.h +50 -0
56 lines not on this page · raw message
fs/nfsd/vfs.c +16 -2
@@ -40,6 +40,7 @@#include "../internal.h" #include "acl.h" #include "idmap.h" +#include "xdr4.h" #endif /* CONFIG_NFSD_V4 */ #include "nfsd.h"
@@ -523,8 +524,15 @@ __be32 nfsd4_set_nfs4_label(struct svc_rqst *rqstp, struct svc_fh *fhp, }#endif -__be32 nfsd4_clone_file_range (struct nfsd_file *nf_src,u64 src_pos, -struct nfsd_file *nf_dst,u64 dst_pos,u64 count,bool sync) +static struct nfsd4_compound_state *nfsd4_get_cstate (struct svc_rqst *rqstp) +{ +return &((struct nfsd4_compoundres *)rqstp->rq_resp)->cstate; +} + +__be32 nfsd4_clone_file_range (struct svc_rqst *rqstp, +struct nfsd_file *nf_src,u64 src_pos, +struct nfsd_file *nf_dst,u64 dst_pos, +u64 count,bool sync) {struct file *src = nf_src->nf_file;struct file *dst = nf_dst->nf_file;
@@ -551,6 +559,12 @@ __be32 nfsd4_clone_file_range(struct nfsd_file *nf_src, u64 src_pos,if (!status) status =commit_inode_metadata (file_inode (src));if (status <0 ) { +trace_nfsd_clone_file_range_err (rqstp, + &nfsd4_get_cstate (rqstp)->save_fh, + src_pos, + &nfsd4_get_cstate (rqstp)->current_fh, + dst_pos, + count, status);nfsd_reset_boot_verifier (net_generic (nf_dst->nf_net, nfsd_net_id)); ret =nfserrno (status);
fs/nfsd/vfs.h +2 -1
@@ -57,7 +57,8 @@ __be32 nfsd4_set_nfs4_label(struct svc_rqst *, struct svc_fh *, struct xdr_netobj *);__be32 nfsd4_vfs_fallocate (struct svc_rqst *,struct svc_fh *,struct file *,loff_t ,loff_t ,int ); -__be32 nfsd4_clone_file_range (struct nfsd_file *nf_src,u64 src_pos, +__be32 nfsd4_clone_file_range (struct svc_rqst *rqstp, +struct nfsd_file *nf_src,u64 src_pos,struct nfsd_file *nf_dst,u64 dst_pos,u64 count,bool sync);#endif /* CONFIG_NFSD_V4 */
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 260/690 NFSD: Write verifier might go backwards
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit cdc556600c0133575487cc69fb3128440b3c3e92 ]
When vfs_iter_write() starts to fail because a file system is full, a bunch of writes can fail at once with ENOSPC. These writes repeatedly invoke nfsd_reset_boot_verifier() in quick succession.
Ensure that the time it grabs doesn't go backwards due to an ntp adjustment going on at the same time.
--- fs/nfsd/nfssvc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfsd/nfssvc.c +1 -1
@@ -363,7 +363,7 @@ void nfsd_copy_boot_verifier(__be32 verf[2], struct nfsd_net *nn)static void nfsd_reset_boot_verifier_locked (struct nfsd_net *nn) { -ktime_get_real_ts64 (&nn->nfssvc_boot); +ktime_get_raw_ts64 (&nn->nfssvc_boot); }void nfsd_reset_boot_verifier (struct nfsd_net *nn)
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 261/690 NFSD: Clean up the nfsd_net::nfssvc_boot field
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 91d2e9b56cf5c80f9efc530d494968369a8a0e0d ]
There are two boot-time fields in struct nfsd_net: one called boot_time and one called nfssvc_boot. The latter is used only to form write verifiers, but its documenting comment declares:
/* Time of server startup */
Since commit 27c438f53e79 ("nfsd: Support the server resetting the boot verifier"), this field can be reset at any time; it's no longer tied to server restart. So that comment is stale.
Also, according to pahole, struct timespec64 is 16 bytes long on x86_64. The nfssvc_boot field is used only to form a write verifier, which is 8 bytes long.
Let's clarify this situation by manufacturing an 8-byte verifier in nfs_reset_boot_verifier() and storing only that in struct nfsd_net.
We're grabbing 128 bits of time, so compress all of those into a 64-bit verifier instead of throwing out the high-order bits. In the future, the siphash_key can be re-used for other hashed objects per-nfsd_net.
--- fs/nfsd/netns.h | 8 +++++--- fs/nfsd/nfsctl.c | 3 ++- fs/nfsd/nfssvc.c | 51 ++++++++++++++++++++++++++++++++++++------------ 3 files changed, 45 insertions(+), 17 deletions(-)
fs/nfsd/netns.h +5 -3
@@ -11,6 +11,7 @@#include <net/net_namespace.h> #include <net/netns/generic.h> #include <linux/percpu_counter.h> +#include <linux/siphash.h> /* Hash tables for nfs4_clientid state */ #define CLIENT_HASH_BITS 4
@@ -108,9 +109,8 @@ struct nfsd_net {bool nfsd_net_up;bool lockd_up; -/* Time of server startup */ -struct timespec64 nfssvc_boot; -seqlock_t boot_lock; +seqlock_t writeverf_lock; +unsigned char writeverf[8 ];/* * Max number of connections this nfsd container will allow. Defaults
@@ -187,6 +187,8 @@ struct nfsd_net {char nfsd_name[UNX_MAXNODENAME +1 ];struct nfsd_fcache_disposal *fcache_disposal; + +siphash_key_t siphash_key; };/* Simple check to find out if a given net was properly initialized */
fs/nfsd/nfsctl.c +2 -1
@@ -1484,7 +1484,8 @@ static __net_init int nfsd_init_net(struct net *net) nn->clientid_counter = nn->clientid_base +1 ; nn->s2s_cp_cl_id = nn->clientid_counter++; -seqlock_init (&nn->boot_lock); +get_random_bytes (&nn->siphash_key,sizeof (nn->siphash_key)); +seqlock_init (&nn->writeverf_lock);return 0 ;
fs/nfsd/nfssvc.c +38 -13
77 lines not on this page · raw message
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 262/690 NFSD: Rename boot verifier functions
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 3988a57885eeac05ef89f0ab4d7e47b52fbcf630 ]
Clean up: These functions handle what the specs call a write verifier, which in the Linux NFS server implementation is now divorced from the server's boot instance
--- fs/nfsd/filecache.c | 2 +- fs/nfsd/netns.h | 4 ++-- fs/nfsd/nfs4proc.c | 2 +- fs/nfsd/nfssvc.c | 16 ++++++++-------- fs/nfsd/vfs.c | 16 ++++++++-------- 5 files changed, 20 insertions(+), 20 deletions(-)
fs/nfsd/filecache.c +1 -1
@@ -237,7 +237,7 @@ nfsd_file_do_unhash(struct nfsd_file *nf)trace_nfsd_file_unhash (nf);if (nfsd_file_check_write_error (nf)) -nfsd_reset_boot_verifier (net_generic (nf->nf_net, nfsd_net_id)); +nfsd_reset_write_verifier (net_generic (nf->nf_net, nfsd_net_id)); --nfsd_file_hashtbl[nf->nf_hashval].nfb_count;hlist_del_rcu (&nf->nf_node);atomic_long_dec (&nfsd_filecache_count);
fs/nfsd/netns.h +2 -2
@@ -198,6 +198,6 @@ extern void nfsd_netns_free_versions(struct nfsd_net *nn);extern unsigned int nfsd_net_id; -void nfsd_copy_boot_verifier (__be32 verf[2 ],struct nfsd_net *nn); -void nfsd_reset_boot_verifier (struct nfsd_net *nn); +void nfsd_copy_write_verifier (__be32 verf[2 ],struct nfsd_net *nn); +void nfsd_reset_write_verifier (struct nfsd_net *nn);#endif /* __NFSD_NETNS_H__ */
fs/nfsd/nfs4proc.c +1 -1
@@ -598,7 +598,7 @@ static void gen_boot_verifier(nfs4_verifier *verifier, struct net *net)BUILD_BUG_ON (2 *sizeof (*verf) !=sizeof (verifier->data)); -nfsd_copy_boot_verifier (verf,net_generic (net, nfsd_net_id)); +nfsd_copy_write_verifier (verf,net_generic (net, nfsd_net_id)); } static __be32
fs/nfsd/nfssvc.c +8 -8
@@ -346,14 +346,14 @@ static bool nfsd_needs_lockd(struct nfsd_net *nn) }/** -* nfsd_copy_boot_verifier - Atomically copy a write verifier +* nfsd_copy_write_verifier - Atomically copy a write verifier * @verf: buffer in which to receive the verifier cookie * @nn: NFS net namespace * * This function provides a wait-free mechanism for copying the -* namespace's boot verifier without tearing it. +* namespace's write verifier without tearing it. */ -void nfsd_copy_boot_verifier (__be32 verf[2 ],struct nfsd_net *nn) +void nfsd_copy_write_verifier (__be32 verf[2 ],struct nfsd_net *nn) {int seq =0 ;
@@ -364,7 +364,7 @@ void nfsd_copy_boot_verifier(__be32 verf[2], struct nfsd_net *nn)done_seqretry (&nn->writeverf_lock, seq); } -static void nfsd_reset_boot_verifier_locked (struct nfsd_net *nn) +static void nfsd_reset_write_verifier_locked (struct nfsd_net *nn) {struct timespec64 now;u64 verf;
@@ -379,7 +379,7 @@ static void nfsd_reset_boot_verifier_locked(struct nfsd_net *nn) }/** -* nfsd_reset_boot_verifier - Generate a new boot verifier +* nfsd_reset_write_verifier - Generate a new write verifier * @nn: NFS net namespace * * This function updates the ->writeverf field of @nn. This field
@@ -391,10 +391,10 @@ static void nfsd_reset_boot_verifier_locked(struct nfsd_net *nn)* server and MUST be unique between instances of the NFSv4.1 * server." */ -void nfsd_reset_boot_verifier (struct nfsd_net *nn) +void nfsd_reset_write_verifier (struct nfsd_net *nn) {write_seqlock (&nn->writeverf_lock); -nfsd_reset_boot_verifier_locked (nn); +nfsd_reset_write_verifier_locked (nn);write_sequnlock (&nn->writeverf_lock); }
@@ -683,7 +683,7 @@ int nfsd_create_serv(struct net *net)register_inet6addr_notifier (&nfsd_inet6addr_notifier);#endif } -nfsd_reset_boot_verifier (nn); +nfsd_reset_write_verifier (nn);return 0 ; }
fs/nfsd/vfs.c +8 -8
@@ -565,8 +565,8 @@ __be32 nfsd4_clone_file_range(struct svc_rqst *rqstp, &nfsd4_get_cstate (rqstp)->current_fh, dst_pos, count, status); -nfsd_reset_boot_verifier (net_generic (nf_dst->nf_net, - nfsd_net_id)); +nfsd_reset_write_verifier (net_generic (nf_dst->nf_net, + nfsd_net_id)); ret =nfserrno (status); } }
@@ -1025,10 +1025,10 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf,iov_iter_kvec (&iter,WRITE , vec, vlen, *cnt); since =READ_ONCE (file->f_wb_err);if (verf) -nfsd_copy_boot_verifier (verf, nn); +nfsd_copy_write_verifier (verf, nn); host_err =vfs_iter_write (file, &iter, &pos, flags);if (host_err <0 ) { -nfsd_reset_boot_verifier (nn); +nfsd_reset_write_verifier (nn); goto out_nfserr; } *cnt = host_err;
@@ -1041,7 +1041,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf,if (stable && use_wgather) { host_err =wait_for_concurrent_writes (file);if (host_err <0 ) -nfsd_reset_boot_verifier (nn); +nfsd_reset_write_verifier (nn); } out_nfserr:
@@ -1173,7 +1173,7 @@ nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp, u64 offset, err2 =vfs_fsync_range (nf->nf_file, start, end,0 );switch (err2) {case 0 : -nfsd_copy_boot_verifier (verf, nn); +nfsd_copy_write_verifier (verf, nn); err2 =filemap_check_wb_err (nf->nf_file->f_mapping, since); err =nfserrno (err2);
@@ -1182,11 +1182,11 @@ nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp, u64 offset, err = nfserr_notsupp;break ;default : -nfsd_reset_boot_verifier (nn); +nfsd_reset_write_verifier (nn); err =nfserrno (err2); } }else -nfsd_copy_boot_verifier (verf, nn); +nfsd_copy_write_verifier (verf, nn);nfsd_file_put (nf); out:
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 263/690 NFSD: Trace boot verifier resets
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 75acacb6583df0b9328dc701d8eeea05af49b8b5 ]
According to commit bbf2f098838a ("nfsd: Reset the boot verifier on all write I/O errors"), the Linux NFS server forces all clients to resend pending unstable writes if any server-side write or commit operation encounters an error (say, ENOSPC). This is a rare and quite exceptional event that could require administrative recovery action, so it should be made trace-able. Example trace event:
nfsd-938 [002] 7174.945558: nfsd_writeverf_reset: boot_time= 61cc920d xid=0xdcd62036 error=-28 new verifier=0x08aecc6142515904
--- fs/nfsd/trace.h | 28 ++++++++++++++++++++++++++++ fs/nfsd/vfs.c | 13 ++++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-)
fs/nfsd/trace.h +28 -0
@@ -574,6 +574,34 @@ DEFINE_EVENT(nfsd_net_class, nfsd_##name, \DEFINE_NET_EVENT (grace_start);DEFINE_NET_EVENT (grace_complete); +TRACE_EVENT (nfsd_writeverf_reset, +TP_PROTO ( + const struct nfsd_net *nn, + const struct svc_rqst *rqstp, + int error + ), +TP_ARGS (nn, rqstp, error), +TP_STRUCT__entry ( + __field(unsigned long long, boot_time) + __field(u32, xid) + __field(int, error) + __array(unsigned char, verifier, NFS4_VERIFIER_SIZE) + ), +TP_fast_assign ( + __entry->boot_time = nn->boot_time; + __entry->xid = be32_to_cpu(rqstp->rq_xid); + __entry->error = error; + +/* avoid seqlock inside TP_fast_assign */ +memcpy (__entry->verifier, nn->writeverf, + NFS4_VERIFIER_SIZE); + ), +TP_printk ("boot_time=%16llx xid=0x%08x error=%d new verifier=0x%s" , + __entry->boot_time, __entry->xid, __entry->error, +__print_hex_str (__entry->verifier,NFS4_VERIFIER_SIZE ) + ) +); + TRACE_EVENT(nfsd_clid_cred_mismatch, TP_PROTO( const struct nfs4_client *clp,
fs/nfsd/vfs.c +10 -3
@@ -559,14 +559,17 @@ __be32 nfsd4_clone_file_range(struct svc_rqst *rqstp,if (!status) status =commit_inode_metadata (file_inode (src));if (status <0 ) { +struct nfsd_net *nn =net_generic (nf_dst->nf_net, + nfsd_net_id); +trace_nfsd_clone_file_range_err (rqstp, &nfsd4_get_cstate (rqstp)->save_fh, src_pos, &nfsd4_get_cstate (rqstp)->current_fh, dst_pos, count, status); -nfsd_reset_write_verifier (net_generic (nf_dst->nf_net, - nfsd_net_id)); +nfsd_reset_write_verifier (nn); +trace_nfsd_writeverf_reset (nn, rqstp, status); ret =nfserrno (status); } }
@@ -1029,6 +1032,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf, host_err =vfs_iter_write (file, &iter, &pos, flags);if (host_err <0 ) {nfsd_reset_write_verifier (nn); +trace_nfsd_writeverf_reset (nn, rqstp, host_err); goto out_nfserr; } *cnt = host_err;
@@ -1040,8 +1044,10 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfsd_file *nf,if (stable && use_wgather) { host_err =wait_for_concurrent_writes (file); -if (host_err <0 ) +if (host_err <0 ) {nfsd_reset_write_verifier (nn); +trace_nfsd_writeverf_reset (nn, rqstp, host_err); + } } out_nfserr:
@@ -1183,6 +1189,7 @@ nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp, u64 offset,break ;default :nfsd_reset_write_verifier (nn); +trace_nfsd_writeverf_reset (nn, rqstp, err2); err =nfserrno (err2); } }else
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 264/690 NFSD: Move fill_pre_wcc() and fill_post_wcc()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit fcb5e3fa012351f3b96024c07bc44834c2478213 ]
These functions are related to file handle processing and have nothing to do with XDR encoding or decoding. Also they are no longer NFSv3-specific. As a clean-up, move their definitions to a more appropriate location. WCC is also an NFSv3-specific term, so rename them as general-purpose helpers.
--- fs/nfsd/nfs3xdr.c | 55 -------------------------------------- fs/nfsd/nfs4proc.c | 2 +- fs/nfsd/nfsfh.c | 66 +++++++++++++++++++++++++++++++++++++++++++++- fs/nfsd/nfsfh.h | 40 ++++++++++++++++++---------- fs/nfsd/vfs.c | 8 +++--- 5 files changed, 96 insertions(+), 75 deletions(-)
fs/nfsd/nfs3xdr.c +0 -55
@@ -487,61 +487,6 @@ svcxdr_encode_wcc_data(struct svc_rqst *rqstp, struct xdr_stream *xdr,return true; } -/* -* Fill in the pre_op attr for the wcc data -*/ -void fill_pre_wcc (struct svc_fh *fhp) -{ -struct inode *inode; -struct kstat stat; -bool v4 = (fhp->fh_maxsize ==NFS4_FHSIZE ); -__be32 err; - -if (fhp->fh_no_wcc || fhp->fh_pre_saved) -return ; - inode =d_inode (fhp->fh_dentry); - err =fh_getattr (fhp, &stat); -if (err) { -/* Grab the times from inode anyway */ - stat.mtime = inode->i_mtime; - stat.ctime = inode->i_ctime; - stat.size = inode->i_size; - } -if (v4) - fhp->fh_pre_change =nfsd4_change_attribute (&stat, inode); - - fhp->fh_pre_mtime = stat.mtime; - fhp->fh_pre_ctime = stat.ctime; - fhp->fh_pre_size = stat.size; - fhp->fh_pre_saved = true; -} - -/* -* Fill in the post_op attr for the wcc data -*/ -void fill_post_wcc (struct svc_fh *fhp) -{ -bool v4 = (fhp->fh_maxsize ==NFS4_FHSIZE ); -struct inode *inode =d_inode (fhp->fh_dentry); -__be32 err; - -if (fhp->fh_no_wcc) -return ; - -if (fhp->fh_post_saved) -printk ("nfsd: inode locked twice during operation.\n" ); - - err =fh_getattr (fhp, &fhp->fh_post_attr); -if (err) { - fhp->fh_post_saved = false; - fhp->fh_post_attr.ctime = inode->i_ctime; - }else - fhp->fh_post_saved = true; -if (v4) - fhp->fh_post_change = -nfsd4_change_attribute (&fhp->fh_post_attr, inode); -} -/* * XDR decode functions */
fs/nfsd/nfs4proc.c +1 -1
@@ -2536,7 +2536,7 @@ nfsd4_proc_compound(struct svc_rqst *rqstp) goto encode_op; } -fh_clear_wcc (current_fh); +fh_clear_pre_post_attrs (current_fh);/* If op is non-idempotent */ if (op->opdesc->op_flags &OP_MODIFIES_SOMETHING ) {
fs/nfsd/nfsfh.c +65 -1
78 lines not on this page · raw message
fs/nfsd/nfsfh.h +26 -14
@@ -284,12 +284,13 @@ static inline u32 knfsd_fh_hash(const struct knfsd_fh *fh)#endif #ifdef CONFIG_NFSD_V3 -/* -* The wcc data stored in current_fh should be cleared -* between compound ops. + +/** +* fh_clear_pre_post_attrs - Reset pre/post attributes +* @fhp: file handle to be updated +* */ -static inline void -fh_clear_wcc (struct svc_fh *fhp) +static inline void fh_clear_pre_post_attrs (struct svc_fh *fhp) { fhp->fh_post_saved = false; fhp->fh_pre_saved = false;
@@ -323,13 +324,24 @@ static inline u64 nfsd4_change_attribute(struct kstat *stat, return time_to_chattr(&stat->ctime); } -extern void fill_pre_wcc (struct svc_fh *fhp); -extern void fill_post_wcc (struct svc_fh *fhp); -#else -#define fh_clear_wcc (ignored) -#define fill_pre_wcc (ignored) -#define fill_post_wcc (notused) -#endif /* CONFIG_NFSD_V3 */ +extern void fh_fill_pre_attrs (struct svc_fh *fhp); +extern void fh_fill_post_attrs (struct svc_fh *fhp); + +#else /* !CONFIG_NFSD_V3 */ + +static inline void fh_clear_pre_post_attrs (struct svc_fh *fhp) +{ +} + +static inline void fh_fill_pre_attrs (struct svc_fh *fhp) +{ +} + +static inline void fh_fill_post_attrs (struct svc_fh *fhp) +{ +} + +#endif /* !CONFIG_NFSD_V3 */ /*
@@ -355,7 +367,7 @@ fh_lock_nested(struct svc_fh *fhp, unsigned int subclass) inode =d_inode (dentry);inode_lock_nested (inode, subclass); -fill_pre_wcc (fhp); +fh_fill_pre_attrs (fhp); fhp->fh_locked = true; }
@@ -372,7 +384,7 @@ static inline void fh_unlock(struct svc_fh *fhp) {if (fhp->fh_locked) { -fill_post_wcc (fhp); +fh_fill_post_attrs (fhp);inode_unlock (d_inode (fhp->fh_dentry)); fhp->fh_locked = false; }
fs/nfsd/vfs.c +4 -4
@@ -1793,8 +1793,8 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,* so do it by hand */ trap =lock_rename (tdentry, fdentry); ffhp->fh_locked = tfhp->fh_locked = true; -fill_pre_wcc (ffhp); -fill_pre_wcc (tfhp); +fh_fill_pre_attrs (ffhp); +fh_fill_pre_attrs (tfhp); odentry =lookup_one_len (fname, fdentry, flen); host_err =PTR_ERR (odentry);
@@ -1848,8 +1848,8 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,* were the same, so again we do it by hand. */ if (!close_cached) { -fill_post_wcc (ffhp); -fill_post_wcc (tfhp); +fh_fill_post_attrs (ffhp); +fh_fill_post_attrs (tfhp); }unlock_rename (tdentry, fdentry); ffhp->fh_locked = tfhp->fh_locked = false;
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 265/690 fsnotify: invalidate dcache before IN_DELETE event
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit a37d9a17f099072fe4d3a9048b0321978707a918 ]
Apparently, there are some applications that use IN_DELETE event as an invalidation mechanism and expect that if they try to open a file with the name reported with the delete event, that it should not contain the content of the deleted file.
Commit 49246466a989 ("fsnotify: move fsnotify_nameremove() hook out of d_delete()") moved the fsnotify delete hook before d_delete() so fsnotify will have access to a positive dentry.
This allowed a race where opening the deleted file via cached dentry is now possible after receiving the IN_DELETE event.
To fix the regression, create a new hook fsnotify_delete() that takes the unlinked inode as an argument and use a helper d_delete_notify() to pin the inode, so we can pass it to fsnotify_delete() after d_delete().
Backporting hint: this regression is from v5.3. Although patch will apply with only trivial conflicts to v5.4 and v5.10, it won't build, because fsnotify_delete() implementation is different in each of those versions (see fsnotify_link()).
A follow up patch will fix the fsnotify_unlink/rmdir() calls in pseudo filesystem that do not need to call d_delete().
--- include/linux/fsnotify.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/fsnotify.h +2 -1
@@ -240,7 +240,8 @@ static inline void fsnotify_delete(struct inode *dir, struct inode *inode,if (S_ISDIR (inode->i_mode)) mask |=FS_ISDIR ; -fsnotify_name (dir, mask, inode, &dentry->d_name,0 ); +fsnotify_name (mask, inode,FSNOTIFY_EVENT_INODE , dir, &dentry->d_name, +0 ); }/**
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 266/690 NFSD: Deprecate NFS_OFFSET_MAX
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit c306d737691ef84305d4ed0d302c63db2932f0bb ]
NFS_OFFSET_MAX was introduced way back in Linux v2.3.y before there was a kernel-wide OFFSET_MAX value. As a clean up, replace the last few uses of it with its generic equivalent, and get rid of it.
--- fs/nfsd/nfs3xdr.c | 2 +- fs/nfsd/nfs4xdr.c | 2 +- include/linux/nfs.h | 8 -------- 3 files changed, 2 insertions(+), 10 deletions(-)
fs/nfsd/nfs3xdr.c +1 -1
@@ -1060,7 +1060,7 @@ svcxdr_encode_entry3_common(struct nfsd3_readdirres *resp, const char *name,return false;/* cookie */ resp->cookie_offset = dirlist->len; -if (xdr_stream_encode_u64 (xdr,NFS_OFFSET_MAX ) <0 ) +if (xdr_stream_encode_u64 (xdr,OFFSET_MAX ) <0 )return false;return true;
fs/nfsd/nfs4xdr.c +1 -1
@@ -3492,7 +3492,7 @@ nfsd4_encode_dirent(void *ccdv, const char *name, int namlen, p =xdr_reserve_space (xdr,3 *4 + namlen);if (!p) goto fail; - p =xdr_encode_hyper (p,NFS_OFFSET_MAX );/* offset of next entry */ + p =xdr_encode_hyper (p,OFFSET_MAX );/* offset of next entry */ p =xdr_encode_array (p, name, namlen);/* name length & name */ nfserr =nfsd4_encode_dirent_fattr (xdr, cd, name, namlen);
include/linux/nfs.h +0 -8
@@ -36,14 +36,6 @@ static inline void nfs_copy_fh(struct nfs_fh *target, const struct nfs_fh *sourcmemcpy (target->data, source->data, source->size); } - -/* -* This is really a general kernel constant, but since nothing like -* this is defined in the kernel headers, I have to do it here. -*/ -#define NFS_OFFSET_MAX ((__s64)((~(__u64)0) >> 1)) - -enum nfs3_stable_how {NFS_UNSTABLE =0 ,NFS_DATA_SYNC =1 ,
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 267/690 nfsd: Add support for the birth time attribute
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ondrej Valousek <[email protected]>
[ Upstream commit e377a3e698fb56cb63f6bddbebe7da76dc37e316 ]
For filesystems that supports "btime" timestamp (i.e. most modern filesystems do) we share it via kernel nfsd. Btime support for NFS client has already been added by Trond recently.
--- fs/nfsd/nfs4xdr.c | 10 ++++++++++ fs/nfsd/nfsd.h | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-)
fs/nfsd/nfs4xdr.c +10 -0
@@ -2851,6 +2851,9 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, err =vfs_getattr (&path, &stat,STATX_BASIC_STATS ,AT_STATX_SYNC_AS_STAT );if (err) goto out_nfserr; +if (!(stat.result_mask &STATX_BTIME )) +/* underlying FS does not offer btime so we can't share it */ + bmval1 &= ~FATTR4_WORD1_TIME_CREATE ; if ((bmval0 & (FATTR4_WORD0_FILES_AVAIL | FATTR4_WORD0_FILES_FREE | FATTR4_WORD0_FILES_TOTAL | FATTR4_WORD0_MAXNAME)) || (bmval1 & (FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE |
@@ -3251,6 +3254,13 @@ nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, p =xdr_encode_hyper (p, (s64 )stat.mtime.tv_sec); *p++ =cpu_to_be32 (stat.mtime.tv_nsec); } +if (bmval1 &FATTR4_WORD1_TIME_CREATE ) { + p =xdr_reserve_space (xdr,12 ); +if (!p) + goto out_resource; + p =xdr_encode_hyper (p, (s64 )stat.btime.tv_sec); + *p++ =cpu_to_be32 (stat.btime.tv_nsec); + }if (bmval1 &FATTR4_WORD1_MOUNTED_ON_FILEID ) {struct kstat parent_stat;u64 ino = stat.ino;
fs/nfsd/nfsd.h +1 -1
@@ -364,7 +364,7 @@ void nfsd_lockd_shutdown(void); | FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP | FATTR4_WORD1_RAWDEV \ | FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE | FATTR4_WORD1_SPACE_TOTAL \ | FATTR4_WORD1_SPACE_USED | FATTR4_WORD1_TIME_ACCESS | FATTR4_WORD1_TIME_ACCESS_SET \ - | FATTR4_WORD1_TIME_DELTA | FATTR4_WORD1_TIME_METADATA \ + | FATTR4_WORD1_TIME_DELTA | FATTR4_WORD1_TIME_METADATA | FATTR4_WORD1_TIME_CREATE \ | FATTR4_WORD1_TIME_MODIFY | FATTR4_WORD1_TIME_MODIFY_SET | FATTR4_WORD1_MOUNTED_ON_FILEID)#define NFSD4_SUPPORTED_ATTRS_WORD2 0
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 268/690 orDate: Thu Sep 30 19:19:57 2021 -0400
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
NFSD: De-duplicate hash bucket indexing
[ Upstream commit 378a6109dd142a678f629b740f558365150f60f9 ]
Clean up: The details of finding the right hash bucket are exactly the same in both nfsd_cache_lookup() and nfsd_cache_update().
--- fs/nfsd/nfscache.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
fs/nfsd/nfscache.c +10 -12
@@ -84,12 +84,6 @@ nfsd_hashsize(unsigned int limit)return roundup_pow_of_two (limit /TARGET_BUCKET_SIZE ); } -static u32 -nfsd_cache_hash (__be32 xid,struct nfsd_net *nn) -{ -return hash_32 ((__force u32 )xid, nn->maskbits); -} -static struct svc_cacherep *nfsd_reply_cache_alloc (struct svc_rqst *rqstp,__wsum csum,struct nfsd_net *nn)
@@ -241,6 +235,14 @@ lru_put_end(struct nfsd_drc_bucket *b, struct svc_cacherep *rp)list_move_tail (&rp->c_lru, &b->lru_head); } +static noinline struct nfsd_drc_bucket * +nfsd_cache_bucket_find (__be32 xid,struct nfsd_net *nn) +{ +unsigned int hash =hash_32 ((__force u32 )xid, nn->maskbits); + +return &nn->drc_hashtbl[hash]; +} +static long prune_bucket (struct nfsd_drc_bucket *b,struct nfsd_net *nn,unsigned int max) {
@@ -421,10 +423,8 @@ int nfsd_cache_lookup(struct svc_rqst *rqstp) {struct nfsd_net *nn =net_generic (SVC_NET (rqstp), nfsd_net_id);struct svc_cacherep *rp, *found; -__be32 xid = rqstp->rq_xid;__wsum csum; -u32 hash =nfsd_cache_hash (xid, nn); -struct nfsd_drc_bucket *b = &nn->drc_hashtbl[hash]; +struct nfsd_drc_bucket *b =nfsd_cache_bucket_find (rqstp->rq_xid, nn);int type = rqstp->rq_cachetype;int rtn =RC_DOIT ;
@@ -528,7 +528,6 @@ void nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)struct nfsd_net *nn =net_generic (SVC_NET (rqstp), nfsd_net_id);struct svc_cacherep *rp = rqstp->rq_cacherep;struct kvec *resv = &rqstp->rq_res.head[0 ], *cachv; -u32 hash;struct nfsd_drc_bucket *b;int len;size_t bufsize =0 ;
@@ -536,8 +535,7 @@ void nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)if (!rp)return ; - hash =nfsd_cache_hash (rp->c_key.k_xid, nn); - b = &nn->drc_hashtbl[hash]; + b =nfsd_cache_bucket_find (rp->c_key.k_xid, nn); len = resv->iov_len - ((char *)statp - (char *)resv->iov_base); len >>=2 ;
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 269/690 NFSD: Skip extra computation for RC_NOCACHE case
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 0f29ce32fbc56cfdb304eec8a4deb920ccfd89c3 ]
Force the compiler to skip unneeded initialization for cases that don't need those values. For example, NFSv4 COMPOUND operations are RC_NOCACHE.
--- fs/nfsd/nfscache.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/nfsd/nfscache.c +4 -2
@@ -421,10 +421,10 @@ nfsd_cache_insert(struct nfsd_drc_bucket *b, struct svc_cacherep *key,*/ int nfsd_cache_lookup (struct svc_rqst *rqstp) { -struct nfsd_net *nn =net_generic (SVC_NET (rqstp), nfsd_net_id); +struct nfsd_net *nn;struct svc_cacherep *rp, *found;__wsum csum; -struct nfsd_drc_bucket *b =nfsd_cache_bucket_find (rqstp->rq_xid, nn); +struct nfsd_drc_bucket *b;int type = rqstp->rq_cachetype;int rtn =RC_DOIT ;
@@ -440,10 +440,12 @@ int nfsd_cache_lookup(struct svc_rqst *rqstp)* Since the common case is a cache miss followed by an insert, * preallocate an entry. */ + nn =net_generic (SVC_NET (rqstp), nfsd_net_id); rp =nfsd_reply_cache_alloc (rqstp, csum, nn);if (!rp) goto out; + b =nfsd_cache_bucket_find (rqstp->rq_xid, nn);spin_lock (&b->cache_lock); found =nfsd_cache_insert (b, rp, nn);if (found != rp) {
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 270/690 NFSD: Streamline the rare "found" case
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit add1511c38166cf1036765f8c4aa939f0275a799 ]
Move a rarely called function call site out of the hot path.
This is an exceptionally small improvement because the compiler inlines most of the functions that nfsd_cache_lookup() calls.
--- fs/nfsd/nfscache.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
fs/nfsd/nfscache.c +3 -4
@@ -448,11 +448,8 @@ int nfsd_cache_lookup(struct svc_rqst *rqstp) b =nfsd_cache_bucket_find (rqstp->rq_xid, nn);spin_lock (&b->cache_lock); found =nfsd_cache_insert (b, rp, nn); -if (found != rp) { -nfsd_reply_cache_free_locked (NULL , rp, nn); - rp = found; +if (found != rp) goto found_entry; - }nfsd_stats_rc_misses_inc (); rqstp->rq_cacherep = rp;
@@ -470,8 +467,10 @@ int nfsd_cache_lookup(struct svc_rqst *rqstp) found_entry:/* We found a matching entry which is either in progress or done. */ +nfsd_reply_cache_free_locked (NULL , rp, nn);nfsd_stats_rc_hits_inc (); rtn =RC_DROPIT ; + rp = found;/* Request being processed */ if (rp->c_state ==RC_INPROG )
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 271/690 NFSD: Remove NFSD_PROC_ARGS_* macros
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit c1a3f2ce66c80cd9f2a4376fa35a5c8d05441c73 ]
Clean up.
The PROC_ARGS macros were added when I thought that NFSD tracepoints would be reporting endpoint information. However, tracepoints in the RPC server now report transport endpoint information, so in general there's no need for the upper layers to do that any more, and these macros can be retired.
--- fs/nfsd/trace.h | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-)
fs/nfsd/trace.h +9 -19
@@ -13,22 +13,6 @@#include "export.h" #include "nfsfh.h" -#define NFSD_TRACE_PROC_ARG_FIELDS \ - __field(unsigned int, netns_ino) \ - __field(u32, xid) \ - __array(unsigned char, server, sizeof(struct sockaddr_in6)) \ - __array(unsigned char, client, sizeof(struct sockaddr_in6)) - -#define NFSD_TRACE_PROC_ARG_ASSIGNMENTS \ - do { \ - __entry->netns_ino = SVC_NET(rqstp)->ns.inum; \ - __entry->xid = be32_to_cpu(rqstp->rq_xid); \ - memcpy(__entry->server, &rqstp->rq_xprt->xpt_local, \ - rqstp->rq_xprt->xpt_locallen); \ - memcpy(__entry->client, &rqstp->rq_xprt->xpt_remote, \ - rqstp->rq_xprt->xpt_remotelen); \ - } while (0); -#define NFSD_TRACE_PROC_RES_FIELDS \ __field(unsigned int, netns_ino) \ __field(u32, xid) \
@@ -53,16 +37,22 @@ DECLARE_EVENT_CLASS(nfsd_xdr_err_class, ),TP_ARGS (rqstp), TP_STRUCT__entry( -NFSD_TRACE_PROC_ARG_FIELDS - + __field(unsigned int, netns_ino) + __field(u32, xid) __field(u32, vers) __field(u32, proc) + __sockaddr(server, rqstp->rq_xprt->xpt_locallen) + __sockaddr(client, rqstp->rq_xprt->xpt_remotelen) ),TP_fast_assign ( - NFSD_TRACE_PROC_ARG_ASSIGNMENTS + const struct svc_xprt *xprt = rqstp->rq_xprt; + __entry->netns_ino = xprt->xpt_net->ns.inum; + __entry->xid =be32_to_cpu (rqstp->rq_xid); __entry->vers = rqstp->rq_vers; __entry->proc = rqstp->rq_proc; +__assign_sockaddr (server, &xprt->xpt_local, xprt->xpt_locallen); +__assign_sockaddr (client, &xprt->xpt_remote, xprt->xpt_remotelen); ),TP_printk ("xid=0x%08x vers=%u proc=%u" , __entry->xid, __entry->vers, __entry->proc
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 272/690 SUNRPC: Remove the .svo_enqueue_xprt method
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit a9ff2e99e9fa501ec965da03c18a5422b37a2f44 ]
We have never been able to track down and address the underlying cause of the performance issues with workqueue-based service support. svo_enqueue_xprt is called multiple times per RPC, so it adds instruction path length, but always ends up at the same
function: svc_xprt_do_enqueue(). We do not anticipate needing this flexibility for dynamic nfsd thread management support.
As a micro-optimization, remove .svo_enqueue_xprt because Spectre/Meltdown makes virtual function calls more costly.
This change essentially reverts commit b9e13cdfac70 ("nfsd/sunrpc:
turn enqueueing a svc_xprt into a svc_serv operation").
--- fs/lockd/svc.c | 1 - fs/nfs/callback.c | 2 -- fs/nfsd/nfssvc.c | 1 - include/linux/sunrpc/svc.h | 3 --- include/linux/sunrpc/svc_xprt.h | 1 - net/sunrpc/svc_xprt.c | 10 +++++----- 6 files changed, 5 insertions(+), 13 deletions(-)
fs/lockd/svc.c +0 -1
@@ -353,7 +353,6 @@ static struct notifier_block lockd_inet6addr_notifier = {static const struct svc_serv_ops lockd_sv_ops = { .svo_shutdown = svc_rpcb_cleanup, .svo_function = lockd, - .svo_enqueue_xprt = svc_xprt_do_enqueue, .svo_module =THIS_MODULE , };
fs/nfs/callback.c +0 -2
@@ -234,13 +234,11 @@ static int nfs_callback_up_net(int minorversion, struct svc_serv *serv,static const struct svc_serv_ops nfs40_cb_sv_ops = { .svo_function = nfs4_callback_svc, - .svo_enqueue_xprt = svc_xprt_do_enqueue, .svo_module =THIS_MODULE , };#if defined(CONFIG_NFS_V4_1 )static const struct svc_serv_ops nfs41_cb_sv_ops = { .svo_function = nfs41_callback_svc, - .svo_enqueue_xprt = svc_xprt_do_enqueue, .svo_module =THIS_MODULE , };
fs/nfsd/nfssvc.c +0 -1
@@ -615,7 +615,6 @@ static int nfsd_get_default_max_blksize(void)static const struct svc_serv_ops nfsd_thread_sv_ops = { .svo_shutdown = nfsd_last_thread, .svo_function = nfsd, - .svo_enqueue_xprt = svc_xprt_do_enqueue, .svo_module =THIS_MODULE , };
include/linux/sunrpc/svc.h +0 -3
@@ -61,9 +61,6 @@ struct svc_serv_ops {/* function for service threads to run */ int (*svo_function)(void *); -/* queue up a transport for servicing */ -void (*svo_enqueue_xprt)(struct svc_xprt *); -/* optional module to count when adding threads. * Thread function must call module_put_and_kthread_exit() to exit. */
include/linux/sunrpc/svc_xprt.h +0 -1
@@ -131,7 +131,6 @@ int svc_create_xprt(struct svc_serv *, const char *, struct net *, const int, const unsigned short, int, const struct cred *);void svc_xprt_received (struct svc_xprt *xprt); -void svc_xprt_do_enqueue (struct svc_xprt *xprt);void svc_xprt_enqueue (struct svc_xprt *xprt);void svc_xprt_put (struct svc_xprt *xprt);void svc_xprt_copy_addrs (struct svc_rqst *rqstp,struct svc_xprt *xprt);
net/sunrpc/svc_xprt.c +5 -5
@@ -31,6 +31,7 @@ static int svc_deferred_recv(struct svc_rqst *rqstp);static struct cache_deferred_req *svc_defer (struct cache_req *req);static void svc_age_temp_xprts (struct timer_list *t);static void svc_delete_xprt (struct svc_xprt *xprt); +static void svc_xprt_do_enqueue (struct svc_xprt *xprt);/* apparently the "standard" is that clients close * idle connections after 5 minutes, servers after
@@ -267,12 +268,12 @@ void svc_xprt_received(struct svc_xprt *xprt)trace_svc_xprt_received (xprt);/* As soon as we clear busy, the xprt could be closed and -* 'put', so we need a reference to call svc_enqueue_xprt with: +* 'put', so we need a reference to call svc_xprt_do_enqueue with: */ svc_xprt_get (xprt);smp_mb__before_atomic ();clear_bit (XPT_BUSY , &xprt->xpt_flags); - xprt->xpt_server->sv_ops->svo_enqueue_xprt (xprt); +svc_xprt_do_enqueue (xprt);svc_xprt_put (xprt); }EXPORT_SYMBOL_GPL (svc_xprt_received);
@@ -424,7 +425,7 @@ static bool svc_xprt_ready(struct svc_xprt *xprt)return false; } -void svc_xprt_do_enqueue (struct svc_xprt *xprt) +static void svc_xprt_do_enqueue (struct svc_xprt *xprt) {struct svc_pool *pool;struct svc_rqst *rqstp =NULL ;
@@ -468,7 +469,6 @@ void svc_xprt_do_enqueue(struct svc_xprt *xprt)put_cpu ();trace_svc_xprt_do_enqueue (xprt, rqstp); } -EXPORT_SYMBOL_GPL (svc_xprt_do_enqueue);/* * Queue up a transport with data pending. If there are idle nfsd
@@ -479,7 +479,7 @@ void svc_xprt_enqueue(struct svc_xprt *xprt) {if (test_bit (XPT_BUSY , &xprt->xpt_flags))return ; - xprt->xpt_server->sv_ops->svo_enqueue_xprt (xprt); +svc_xprt_do_enqueue (xprt); }EXPORT_SYMBOL_GPL (svc_xprt_enqueue);
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 273/690 SUNRPC: Merge svc_do_enqueue_xprt() into svc_enqueue_xprt()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit c0219c499799c1e92bd570c15a47e6257a27bb15 ]
Neil says:
"These functions were separated in commit 0971374e2818 ("SUNRPC:
Reduce contention in svc_xprt_enqueue()") so that the XPT_BUSY check happened before taking any spinlocks.
We have since moved or removed the spinlocks so the extra test is fairly pointless."
I've made this a separate patch in case the XPT_BUSY change has unexpected consequences and needs to be reverted.
--- net/sunrpc/svc_xprt.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-)
net/sunrpc/svc_xprt.c +10 -16
@@ -31,7 +31,6 @@ static int svc_deferred_recv(struct svc_rqst *rqstp);static struct cache_deferred_req *svc_defer (struct cache_req *req);static void svc_age_temp_xprts (struct timer_list *t);static void svc_delete_xprt (struct svc_xprt *xprt); -static void svc_xprt_do_enqueue (struct svc_xprt *xprt);/* apparently the "standard" is that clients close * idle connections after 5 minutes, servers after
@@ -268,12 +267,12 @@ void svc_xprt_received(struct svc_xprt *xprt)trace_svc_xprt_received (xprt);/* As soon as we clear busy, the xprt could be closed and -* 'put', so we need a reference to call svc_xprt_do_enqueue with: +* 'put', so we need a reference to call svc_xprt_enqueue with: */ svc_xprt_get (xprt);smp_mb__before_atomic ();clear_bit (XPT_BUSY , &xprt->xpt_flags); -svc_xprt_do_enqueue (xprt); +svc_xprt_enqueue (xprt);svc_xprt_put (xprt); }EXPORT_SYMBOL_GPL (svc_xprt_received);
@@ -413,6 +412,8 @@ static bool svc_xprt_ready(struct svc_xprt *xprt)smp_rmb (); xpt_flags =READ_ONCE (xprt->xpt_flags); +if (xpt_flags &BIT (XPT_BUSY )) +return false;if (xpt_flags & (BIT (XPT_CONN ) |BIT (XPT_CLOSE )))return true;if (xpt_flags & (BIT (XPT_DATA ) |BIT (XPT_DEFERRED ))) {
@@ -425,7 +426,12 @@ static bool svc_xprt_ready(struct svc_xprt *xprt)return false; } -static void svc_xprt_do_enqueue (struct svc_xprt *xprt) +/** +* svc_xprt_enqueue - Queue a transport on an idle nfsd thread +* @xprt: transport with data pending +* +*/ +void svc_xprt_enqueue (struct svc_xprt *xprt) {struct svc_pool *pool;struct svc_rqst *rqstp =NULL ;
@@ -469,18 +475,6 @@ static void svc_xprt_do_enqueue(struct svc_xprt *xprt)put_cpu ();trace_svc_xprt_do_enqueue (xprt, rqstp); } - -/* -* Queue up a transport with data pending. If there are idle nfsd -* processes, wake 'em up. -* -*/ -void svc_xprt_enqueue (struct svc_xprt *xprt) -{ -if (test_bit (XPT_BUSY , &xprt->xpt_flags)) -return ; -svc_xprt_do_enqueue (xprt); -}EXPORT_SYMBOL_GPL (svc_xprt_enqueue);/*
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 274/690 SUNRPC: Remove svo_shutdown method
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 87cdd8641c8a1ec6afd2468265e20840a57fd888 ]
Clean up. Neil observed that "any code that calls svc_shutdown_net() knows what the shutdown function should be, and so can call it directly."
--- fs/lockd/svc.c | 5 ++--- fs/nfsd/nfssvc.c | 2 +- include/linux/sunrpc/svc.h | 3 --- net/sunrpc/svc.c | 3 --- 4 files changed, 3 insertions(+), 10 deletions(-)
fs/lockd/svc.c +2 -3
@@ -249,6 +249,7 @@ static int make_socks(struct svc_serv *serv, struct net *net,printk (KERN_WARNING "lockd_up: makesock failed, error=%d\n" , err);svc_shutdown_net (serv, net); +svc_rpcb_cleanup (serv, net);return err; }
@@ -287,8 +288,7 @@ static void lockd_down_net(struct svc_serv *serv, struct net *net)cancel_delayed_work_sync (&ln->grace_period_end);locks_end_grace (&ln->lockd_manager);svc_shutdown_net (serv, net); -dprintk ("%s: per-net data destroyed; net=%x\n" , - __func__, net->ns.inum); +svc_rpcb_cleanup (serv, net); } }else { pr_err("%s: no users! net=%x\n",
@@ -351,7 +351,6 @@ static struct notifier_block lockd_inet6addr_notifier = {#endif static const struct svc_serv_ops lockd_sv_ops = { - .svo_shutdown = svc_rpcb_cleanup, .svo_function = lockd, .svo_module =THIS_MODULE , };
fs/nfsd/nfssvc.c +1 -1
@@ -613,7 +613,6 @@ static int nfsd_get_default_max_blksize(void) }static const struct svc_serv_ops nfsd_thread_sv_ops = { - .svo_shutdown = nfsd_last_thread, .svo_function = nfsd, .svo_module =THIS_MODULE , };
@@ -724,6 +723,7 @@ void nfsd_put(struct net *net)if (kref_put (&nn->nfsd_serv->sv_refcnt, nfsd_noop)) {svc_shutdown_net (nn->nfsd_serv, net); +nfsd_last_thread (nn->nfsd_serv, net);svc_destroy (&nn->nfsd_serv->sv_refcnt);spin_lock (&nfsd_notifier_lock); nn->nfsd_serv =NULL ;
include/linux/sunrpc/svc.h +0 -3
@@ -55,9 +55,6 @@ struct svc_pool {struct svc_serv ;struct svc_serv_ops { -/* Callback to use when last thread exits. */ -void (*svo_shutdown)(struct svc_serv *,struct net *); -/* function for service threads to run */ int (*svo_function)(void *);
net/sunrpc/svc.c +0 -3
@@ -539,9 +539,6 @@ EXPORT_SYMBOL_GPL(svc_create_pooled);void svc_shutdown_net (struct svc_serv *serv,struct net *net) {svc_close_net (serv, net); - -if (serv->sv_ops->svo_shutdown) - serv->sv_ops->svo_shutdown (serv, net); }EXPORT_SYMBOL_GPL (svc_shutdown_net);
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 275/690 SUNRPC: Rename svc_create_xprt()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 352ad31448fecc78a2e9b78da64eea5d63b8d0ce ]
Clean up: Use the "svc_xprt_<task>" function naming convention as is used for other external APIs.
--- fs/lockd/svc.c | 4 ++-- fs/nfs/callback.c | 12 ++++++------ fs/nfsd/nfsctl.c | 8 ++++---- fs/nfsd/nfssvc.c | 8 ++++---- include/linux/sunrpc/svc_xprt.h | 7 ++++--- net/sunrpc/svc_xprt.c | 24 +++++++++++++++++++----- 6 files changed, 39 insertions(+), 24 deletions(-)
fs/lockd/svc.c +2 -2
@@ -197,8 +197,8 @@ static int create_lockd_listener(struct svc_serv *serv, const char *name, xprt =svc_find_xprt (serv, name, net, family,0 );if (xprt ==NULL ) -return svc_create_xprt (serv, name, net, family, port, -SVC_SOCK_DEFAULTS , cred); +return svc_xprt_create (serv, name, net, family, port, +SVC_SOCK_DEFAULTS , cred);svc_xprt_put (xprt);return 0 ; }
fs/nfs/callback.c +6 -6
@@ -45,18 +45,18 @@ static int nfs4_callback_up_net(struct svc_serv *serv, struct net *net)int ret;struct nfs_net *nn =net_generic (net, nfs_net_id); - ret =svc_create_xprt (serv,"tcp" , net,PF_INET , - nfs_callback_set_tcpport,SVC_SOCK_ANONYMOUS , - cred); + ret =svc_xprt_create (serv,"tcp" , net,PF_INET , + nfs_callback_set_tcpport,SVC_SOCK_ANONYMOUS , + cred);if (ret <=0 ) goto out_err; nn->nfs_callback_tcpport = ret;dprintk ("NFS: Callback listener port = %u (af %u, net %x)\n" , nn->nfs_callback_tcpport,PF_INET , net->ns.inum); - ret =svc_create_xprt (serv,"tcp" , net,PF_INET6 , - nfs_callback_set_tcpport,SVC_SOCK_ANONYMOUS , - cred); + ret =svc_xprt_create (serv,"tcp" , net,PF_INET6 , + nfs_callback_set_tcpport,SVC_SOCK_ANONYMOUS , + cred);if (ret >0 ) { nn->nfs_callback_tcpport6 = ret; dprintk("NFS: Callback listener port = %u (af %u, net %x)\n",
fs/nfsd/nfsctl.c +4 -4
@@ -772,13 +772,13 @@ static ssize_t __write_ports_addxprt(char *buf, struct net *net, const struct crif (err !=0 )return err; - err =svc_create_xprt (nn->nfsd_serv, transport, net, -PF_INET , port,SVC_SOCK_ANONYMOUS , cred); + err =svc_xprt_create (nn->nfsd_serv, transport, net, +PF_INET , port,SVC_SOCK_ANONYMOUS , cred);if (err <0 ) goto out_err; - err =svc_create_xprt (nn->nfsd_serv, transport, net, -PF_INET6 , port,SVC_SOCK_ANONYMOUS , cred); + err =svc_xprt_create (nn->nfsd_serv, transport, net, +PF_INET6 , port,SVC_SOCK_ANONYMOUS , cred);if (err <0 && err != -EAFNOSUPPORT ) goto out_close;
fs/nfsd/nfssvc.c +4 -4
@@ -293,13 +293,13 @@ static int nfsd_init_socks(struct net *net, const struct cred *cred)if (!list_empty (&nn->nfsd_serv->sv_permsocks))return 0 ; - error =svc_create_xprt (nn->nfsd_serv,"udp" , net,PF_INET ,NFS_PORT , -SVC_SOCK_DEFAULTS , cred); + error =svc_xprt_create (nn->nfsd_serv,"udp" , net,PF_INET ,NFS_PORT , +SVC_SOCK_DEFAULTS , cred);if (error <0 )return error; - error =svc_create_xprt (nn->nfsd_serv,"tcp" , net,PF_INET ,NFS_PORT , -SVC_SOCK_DEFAULTS , cred); + error =svc_xprt_create (nn->nfsd_serv,"tcp" , net,PF_INET ,NFS_PORT , +SVC_SOCK_DEFAULTS , cred);if (error <0 )return error;
include/linux/sunrpc/svc_xprt.h +4 -3
@@ -127,9 +127,10 @@ int svc_reg_xprt_class(struct svc_xprt_class *);void svc_unreg_xprt_class (struct svc_xprt_class *);void svc_xprt_init (struct net *,struct svc_xprt_class *,struct svc_xprt *,struct svc_serv *); -int svc_create_xprt (struct svc_serv *,const char *,struct net *, -const int ,const unsigned short ,int , -const struct cred *); +int svc_xprt_create (struct svc_serv *serv,const char *xprt_name, +struct net *net,const int family, +const unsigned short port,int flags, +const struct cred *cred);void svc_xprt_received (struct svc_xprt *xprt);void svc_xprt_enqueue (struct svc_xprt *xprt);void svc_xprt_put (struct svc_xprt *xprt);
net/sunrpc/svc_xprt.c +19 -5
@@ -286,7 +286,7 @@ void svc_add_new_perm_xprt(struct svc_serv *serv, struct svc_xprt *new)svc_xprt_received (new); } -static int _svc_create_xprt (struct svc_serv *serv,const char *xprt_name, +static int _svc_xprt_create (struct svc_serv *serv,const char *xprt_name,struct net *net,const int family,const unsigned short port,int flags,const struct cred *cred)
@@ -322,21 +322,35 @@ static int _svc_create_xprt(struct svc_serv *serv, const char *xprt_name,return -EPROTONOSUPPORT ; } -int svc_create_xprt (struct svc_serv *serv,const char *xprt_name, +/** +* svc_xprt_create - Add a new listener to @serv +* @serv: target RPC service +* @xprt_name: transport class name +* @net: network namespace +* @family: network address family +* @port: listener port +* @flags: SVC_SOCK flags +* @cred: credential to bind to this transport +* +* Return values: +* %0: New listener added successfully +* %-EPROTONOSUPPORT: Requested transport type not supported +*/ +int svc_xprt_create (struct svc_serv *serv,const char *xprt_name,struct net *net,const int family,const unsigned short port,int flags,const struct cred *cred) {int err; - err =_svc_create_xprt (serv, xprt_name, net, family, port, flags, cred); + err =_svc_xprt_create (serv, xprt_name, net, family, port, flags, cred);if (err == -EPROTONOSUPPORT ) {request_module ("svc%s" , xprt_name); - err =_svc_create_xprt (serv, xprt_name, net, family, port, flags, cred); + err =_svc_xprt_create (serv, xprt_name, net, family, port, flags, cred); }return err; } -EXPORT_SYMBOL_GPL (svc_create_xprt); +EXPORT_SYMBOL_GPL (svc_xprt_create);/* * Copy the local and remote xprt addresses to the rqstp structure
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 276/690 SUNRPC: Rename svc_close_xprt()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 4355d767a21b9445958fc11bce9a9701f76529d3 ]
Clean up: Use the "svc_xprt_<task>" function naming convention as is used for other external APIs.
--- fs/nfsd/nfsctl.c | 2 +- include/linux/sunrpc/svc_xprt.h | 2 +- net/sunrpc/svc.c | 2 +- net/sunrpc/svc_xprt.c | 9 +++++++-- net/sunrpc/xprtrdma/svc_rdma_backchannel.c | 2 +- 5 files changed, 11 insertions(+), 6 deletions(-)
fs/nfsd/nfsctl.c +1 -1
@@ -790,7 +790,7 @@ static ssize_t __write_ports_addxprt(char *buf, struct net *net, const struct cr out_close: xprt =svc_find_xprt (nn->nfsd_serv, transport, net,PF_INET , port);if (xprt !=NULL ) { -svc_close_xprt (xprt); +svc_xprt_close (xprt);svc_xprt_put (xprt); } out_err:
include/linux/sunrpc/svc_xprt.h +1 -1
@@ -135,7 +135,7 @@ void svc_xprt_received(struct svc_xprt *xprt);void svc_xprt_enqueue (struct svc_xprt *xprt);void svc_xprt_put (struct svc_xprt *xprt);void svc_xprt_copy_addrs (struct svc_rqst *rqstp,struct svc_xprt *xprt); -void svc_close_xprt (struct svc_xprt *xprt); +void svc_xprt_close (struct svc_xprt *xprt);int svc_port_is_privileged (struct sockaddr *sin);int svc_print_xprts (char *buf,int maxlen); struct svc_xprt *svc_find_xprt(struct svc_serv *serv, const char *xcl_name,
net/sunrpc/svc.c +1 -1
@@ -1408,7 +1408,7 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)svc_authorise (rqstp); close_xprt:if (rqstp->rq_xprt &&test_bit (XPT_TEMP , &rqstp->rq_xprt->xpt_flags)) -svc_close_xprt (rqstp->rq_xprt); +svc_xprt_close (rqstp->rq_xprt);dprintk ("svc: svc_process close\n" );return 0 ;
net/sunrpc/svc_xprt.c +7 -2
@@ -1078,7 +1078,12 @@ static void svc_delete_xprt(struct svc_xprt *xprt)svc_xprt_put (xprt); } -void svc_close_xprt (struct svc_xprt *xprt) +/** +* svc_xprt_close - Close a client connection +* @xprt: transport to disconnect +* +*/ +void svc_xprt_close (struct svc_xprt *xprt) {trace_svc_xprt_close (xprt);set_bit (XPT_CLOSE , &xprt->xpt_flags);
@@ -1093,7 +1098,7 @@ void svc_close_xprt(struct svc_xprt *xprt)*/ svc_delete_xprt (xprt); } -EXPORT_SYMBOL_GPL (svc_close_xprt); +EXPORT_SYMBOL_GPL (svc_xprt_close);static int svc_close_list (struct svc_serv *serv,struct list_head *xprt_list,struct net *net) {
net/sunrpc/xprtrdma/svc_rdma_backchannel.c +1 -1
@@ -198,7 +198,7 @@ static int xprt_rdma_bc_send_request(struct rpc_rqst *rqst) ret =rpcrdma_bc_send_request (rdma, rqst);if (ret == -ENOTCONN ) -svc_close_xprt (sxprt); +svc_xprt_close (sxprt);return ret; }
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 277/690 SUNRPC: Remove svc_shutdown_net()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit c7d7ec8f043e53ad16e30f5ebb8b9df415ec0f2b ]
Clean up: svc_shutdown_net() now does nothing but call svc_close_net(). Replace all external call sites.
svc_close_net() is renamed to be the inverse of svc_xprt_create().
--- fs/lockd/svc.c | 4 ++-- fs/nfs/callback.c | 2 +- fs/nfsd/nfssvc.c | 2 +- include/linux/sunrpc/svc.h | 1 - include/linux/sunrpc/svc_xprt.h | 1 + net/sunrpc/svc.c | 6 ------ net/sunrpc/svc_xprt.c | 9 +++++++-- 7 files changed, 12 insertions(+), 13 deletions(-)
fs/lockd/svc.c +2 -2
@@ -248,7 +248,7 @@ static int make_socks(struct svc_serv *serv, struct net *net,if (warned++ ==0 )printk (KERN_WARNING "lockd_up: makesock failed, error=%d\n" , err); -svc_shutdown_net (serv, net); +svc_xprt_destroy_all (serv, net);svc_rpcb_cleanup (serv, net);return err; }
@@ -287,7 +287,7 @@ static void lockd_down_net(struct svc_serv *serv, struct net *net)nlm_shutdown_hosts_net (net);cancel_delayed_work_sync (&ln->grace_period_end);locks_end_grace (&ln->lockd_manager); -svc_shutdown_net (serv, net); +svc_xprt_destroy_all (serv, net);svc_rpcb_cleanup (serv, net); } }else {
fs/nfs/callback.c +1 -1
@@ -189,7 +189,7 @@ static void nfs_callback_down_net(u32 minorversion, struct svc_serv *serv, strucreturn ;dprintk ("NFS: destroy per-net callback data; net=%x\n" , net->ns.inum); -svc_shutdown_net (serv, net); +svc_xprt_destroy_all (serv, net); } static int nfs_callback_up_net(int minorversion, struct svc_serv *serv,
fs/nfsd/nfssvc.c +1 -1
@@ -722,7 +722,7 @@ void nfsd_put(struct net *net)struct nfsd_net *nn =net_generic (net, nfsd_net_id);if (kref_put (&nn->nfsd_serv->sv_refcnt, nfsd_noop)) { -svc_shutdown_net (nn->nfsd_serv, net); +svc_xprt_destroy_all (nn->nfsd_serv, net);nfsd_last_thread (nn->nfsd_serv, net);svc_destroy (&nn->nfsd_serv->sv_refcnt);spin_lock (&nfsd_notifier_lock);
include/linux/sunrpc/svc.h +0 -1
@@ -510,7 +510,6 @@ struct svc_serv * svc_create_pooled(struct svc_program *, unsigned int, const struct svc_serv_ops *); int svc_set_num_threads(struct svc_serv *, struct svc_pool *, int);int svc_pool_stats_open (struct svc_serv *serv,struct file *file); -void svc_shutdown_net (struct svc_serv *,struct net *);int svc_process (struct svc_rqst *);int bc_svc_process (struct svc_serv *,struct rpc_rqst *,struct svc_rqst *);
include/linux/sunrpc/svc_xprt.h +1 -0
@@ -131,6 +131,7 @@ int svc_xprt_create(struct svc_serv *serv, const char *xprt_name, struct net *net, const int family, const unsigned short port, int flags, const struct cred *cred); +void svc_xprt_destroy_all (struct svc_serv *serv,struct net *net);void svc_xprt_received (struct svc_xprt *xprt);void svc_xprt_enqueue (struct svc_xprt *xprt);void svc_xprt_put (struct svc_xprt *xprt);
net/sunrpc/svc.c +0 -6
@@ -536,12 +536,6 @@ svc_create_pooled(struct svc_program *prog, unsigned int bufsize, }EXPORT_SYMBOL_GPL (svc_create_pooled); -void svc_shutdown_net (struct svc_serv *serv,struct net *net) -{ -svc_close_net (serv, net); -} -EXPORT_SYMBOL_GPL (svc_shutdown_net); -/* * Destroy an RPC service. Should be called with appropriate locking to * protect sv_permsocks and sv_tempsocks.
net/sunrpc/svc_xprt.c +7 -2
@@ -1150,7 +1150,11 @@ static void svc_clean_up_xprts(struct svc_serv *serv, struct net *net) } } -/* +/** +* svc_xprt_destroy_all - Destroy transports associated with @serv +* @serv: RPC service to be shut down +* @net: target network namespace +* * Server threads may still be running (especially in the case where the * service is still running in other network namespaces). *
@@ -1162,7 +1166,7 @@ static void svc_clean_up_xprts(struct svc_serv *serv, struct net *net)* threads, we may need to wait a little while and then check again to * see if they're done. */ -void svc_close_net (struct svc_serv *serv,struct net *net) +void svc_xprt_destroy_all (struct svc_serv *serv,struct net *net) {int delay =0 ;
@@ -1173,6 +1177,7 @@ void svc_close_net(struct svc_serv *serv, struct net *net)msleep (delay++); } } +EXPORT_SYMBOL_GPL (svc_xprt_destroy_all);/* * Handle defer and revisit of requests
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 278/690 NFSD: Remove svc_serv_ops::svo_module
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit f49169c97fceb21ad6a0aaf671c50b0f520f15a5 ]
struct svc_serv_ops is about to be removed.
Neil Brown says:
Quoted 2 lines
I suspect
svo_modulecan go as well - I don't think the thread is ever the thing that primarily keeps a module active.
A random sample of kthread_create() callers shows sunrpc is the only one that manages module reference count in this way.
--- fs/lockd/svc.c | 4 +--- fs/nfs/callback.c | 7 ++----- fs/nfs/nfs4state.c | 1 - fs/nfsd/nfssvc.c | 3 --- include/linux/sunrpc/svc.h | 5 ----- kernel/module.c | 2 +- net/sunrpc/svc.c | 2 -- 7 files changed, 4 insertions(+), 20 deletions(-)
fs/lockd/svc.c +1 -3
@@ -184,8 +184,7 @@ lockd(void *vrqstp)dprintk ("lockd_down: service stopped\n" );svc_exit_thread (rqstp); - -module_put_and_kthread_exit (0 ); +return 0 ; } static int create_lockd_listener(struct svc_serv *serv, const char *name,
@@ -352,7 +351,6 @@ static struct notifier_block lockd_inet6addr_notifier = {static const struct svc_serv_ops lockd_sv_ops = { .svo_function = lockd, - .svo_module =THIS_MODULE , };static int lockd_get (void )
fs/nfs/callback.c +2 -5
@@ -17,7 +17,6 @@#include <linux/errno.h> #include <linux/mutex.h> #include <linux/freezer.h> -#include <linux/kthread.h> #include <linux/sunrpc/svcauth_gss.h> #include <linux/sunrpc/bc_xprt.h>
@@ -92,8 +91,8 @@ nfs4_callback_svc(void *vrqstp)continue ;svc_process (rqstp); } +svc_exit_thread (rqstp); -module_put_and_kthread_exit (0 );return 0 ; }
@@ -136,8 +135,8 @@ nfs41_callback_svc(void *vrqstp)finish_wait (&serv->sv_cb_waitq, &wq); } } +svc_exit_thread (rqstp); -module_put_and_kthread_exit (0 );return 0 ; }
@@ -234,12 +233,10 @@ static int nfs_callback_up_net(int minorversion, struct svc_serv *serv,static const struct svc_serv_ops nfs40_cb_sv_ops = { .svo_function = nfs4_callback_svc, - .svo_module =THIS_MODULE , };#if defined(CONFIG_NFS_V4_1 )static const struct svc_serv_ops nfs41_cb_sv_ops = { .svo_function = nfs41_callback_svc, - .svo_module =THIS_MODULE , }; static const struct svc_serv_ops *nfs4_cb_sv_ops[] = {
fs/nfs/nfs4state.c +0 -1
@@ -2766,6 +2766,5 @@ static int nfs4_run_state_manager(void *ptr) goto again;nfs_put_client (clp); -module_put_and_kthread_exit (0 );return 0 ; }
fs/nfsd/nfssvc.c +0 -3
@@ -614,7 +614,6 @@ static int nfsd_get_default_max_blksize(void)static const struct svc_serv_ops nfsd_thread_sv_ops = { .svo_function = nfsd, - .svo_module =THIS_MODULE , };void nfsd_shutdown_threads (struct net *net)
@@ -1018,8 +1017,6 @@ nfsd(void *vrqstp)msleep (20 ); } -/* Release module */ -module_put_and_kthread_exit (0 );return 0 ; }
include/linux/sunrpc/svc.h +0 -5
@@ -57,11 +57,6 @@ struct svc_serv;struct svc_serv_ops {/* function for service threads to run */ int (*svo_function)(void *); - -/* optional module to count when adding threads. -* Thread function must call module_put_and_kthread_exit() to exit. -*/ -struct module *svo_module; };/*
kernel/module.c +1 -1
@@ -335,7 +335,7 @@ static inline void add_taint_module(struct module *mod, unsigned flag,/* * A thread that wants to hold a reference to a module only while it -* is running can call this to safely exit. nfsd and lockd use this. +* is running can call this to safely exit. */ void __noreturn __module_put_and_kthread_exit (struct module *mod,long code) {
net/sunrpc/svc.c +0 -2
@@ -736,11 +736,9 @@ svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)if (IS_ERR (rqstp))return PTR_ERR (rqstp); -__module_get (serv->sv_ops->svo_module); task =kthread_create_on_node (serv->sv_ops->svo_function, rqstp, node,"%s" , serv->sv_name);if (IS_ERR (task)) { -module_put (serv->sv_ops->svo_module);svc_exit_thread (rqstp);return PTR_ERR (task); }
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 279/690 NFSD: Move svc_serv_ops::svo_function into struct svc_serv
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 37902c6313090235c847af89c5515591261ee338 ]
Hoist svo_function back into svc_serv and remove struct svc_serv_ops, since the struct is now devoid of fields.
--- fs/lockd/svc.c | 6 +----- fs/nfs/callback.c | 43 ++++++++++---------------------------- fs/nfsd/nfssvc.c | 7 +------ include/linux/sunrpc/svc.h | 14 ++++--------- net/sunrpc/svc.c | 37 ++++++++++++++++++++++---------- 5 files changed, 43 insertions(+), 64 deletions(-)
fs/lockd/svc.c +1 -5
@@ -349,10 +349,6 @@ static struct notifier_block lockd_inet6addr_notifier = { };#endif -static const struct svc_serv_ops lockd_sv_ops = { - .svo_function = lockd, -}; -static int lockd_get (void ) {struct svc_serv *serv;
@@ -376,7 +372,7 @@ static int lockd_get(void) nlm_timeout =LOCKD_DFLT_TIMEO ; nlmsvc_timeout = nlm_timeout *HZ ; - serv =svc_create (&nlmsvc_program,LOCKD_BUFSIZE , &lockd_sv_ops); + serv =svc_create (&nlmsvc_program,LOCKD_BUFSIZE , lockd);if (!serv) {printk (KERN_WARNING "lockd_up: create service failed\n" );return -ENOMEM ;
fs/nfs/callback.c +11 -32
64 lines not on this page · raw message
fs/nfsd/nfssvc.c +1 -6
@@ -612,10 +612,6 @@ static int nfsd_get_default_max_blksize(void)return ret; } -static const struct svc_serv_ops nfsd_thread_sv_ops = { - .svo_function = nfsd, -}; -void nfsd_shutdown_threads (struct net *net) {struct nfsd_net *nn =net_generic (net, nfsd_net_id);
@@ -654,8 +650,7 @@ int nfsd_create_serv(struct net *net)if (nfsd_max_blksize ==0 ) nfsd_max_blksize =nfsd_get_default_max_blksize ();nfsd_reset_versions (nn); - serv =svc_create_pooled (&nfsd_program, nfsd_max_blksize, - &nfsd_thread_sv_ops); + serv =svc_create_pooled (&nfsd_program, nfsd_max_blksize, nfsd);if (serv ==NULL )return -ENOMEM ;
include/linux/sunrpc/svc.h +4 -10
@@ -52,13 +52,6 @@ struct svc_pool {unsigned long sp_flags; }____cacheline_aligned_in_smp ; -struct svc_serv ; - -struct svc_serv_ops { -/* function for service threads to run */ -int (*svo_function)(void *); -}; -/* * RPC service. *
@@ -91,7 +84,8 @@ struct svc_serv {unsigned int sv_nrpools;/* number of thread pools */ struct svc_pool * sv_pools;/* array of thread pools */ -const struct svc_serv_ops *sv_ops;/* server operations */ +int (*sv_threadfn)(void *data); +#if defined(CONFIG_SUNRPC_BACKCHANNEL )struct list_head sv_cb_list;/* queue for callback requests * that arrive over the same
@@ -494,7 +488,7 @@ int svc_rpcb_setup(struct svc_serv *serv, struct net *net);void svc_rpcb_cleanup (struct svc_serv *serv,struct net *net);int svc_bind (struct svc_serv *serv,struct net *net);struct svc_serv *svc_create (struct svc_program *,unsigned int , -const struct svc_serv_ops *); +int (*threadfn)(void *data));struct svc_rqst *svc_rqst_alloc (struct svc_serv *serv,struct svc_pool *pool,int node); void svc_rqst_replace_page(struct svc_rqst *rqstp,
@@ -502,7 +496,7 @@ void svc_rqst_replace_page(struct svc_rqst *rqstp,void svc_rqst_free (struct svc_rqst *);void svc_exit_thread (struct svc_rqst *);struct svc_serv *svc_create_pooled (struct svc_program *,unsigned int , -const struct svc_serv_ops *); +int (*threadfn)(void *data));int svc_set_num_threads (struct svc_serv *,struct svc_pool *,int );int svc_pool_stats_open (struct svc_serv *serv,struct file *file);int svc_process (struct svc_rqst *);
net/sunrpc/svc.c +26 -11
@@ -448,7 +448,7 @@ __svc_init_bc(struct svc_serv *serv)*/ static struct svc_serv *__svc_create (struct svc_program *prog,unsigned int bufsize,int npools, -const struct svc_serv_ops *ops) +int (*threadfn)(void *data)) {struct svc_serv *serv;unsigned int vers;
@@ -465,7 +465,7 @@ __svc_create(struct svc_program *prog, unsigned int bufsize, int npools, bufsize =RPCSVC_MAXPAYLOAD ; serv->sv_max_payload = bufsize? bufsize :4096 ; serv->sv_max_mesg =roundup (serv->sv_max_payload +PAGE_SIZE ,PAGE_SIZE ); - serv->sv_ops = ops; + serv->sv_threadfn = threadfn; xdrsize =0 ;while (prog) { prog->pg_lovers = prog->pg_nvers-1 ;
@@ -511,22 +511,37 @@ __svc_create(struct svc_program *prog, unsigned int bufsize, int npools,return serv; } -struct svc_serv * -svc_create (struct svc_program *prog,unsigned int bufsize, -const struct svc_serv_ops *ops) +/** +* svc_create - Create an RPC service +* @prog: the RPC program the new service will handle +* @bufsize: maximum message size for @prog +* @threadfn: a function to service RPC requests for @prog +* +* Returns an instantiated struct svc_serv object or NULL. +*/ +struct svc_serv *svc_create (struct svc_program *prog,unsigned int bufsize, +int (*threadfn)(void *data)) { -return __svc_create (prog, bufsize,/*npools*/ 1 , ops); +return __svc_create (prog, bufsize,1 , threadfn); }EXPORT_SYMBOL_GPL (svc_create); -struct svc_serv * -svc_create_pooled (struct svc_program *prog,unsigned int bufsize, -const struct svc_serv_ops *ops) +/** +* svc_create_pooled - Create an RPC service with pooled threads +* @prog: the RPC program the new service will handle +* @bufsize: maximum message size for @prog +* @threadfn: a function to service RPC requests for @prog +* +* Returns an instantiated struct svc_serv object or NULL. +*/ +struct svc_serv *svc_create_pooled (struct svc_program *prog, +unsigned int bufsize, +int (*threadfn)(void *data)) {struct svc_serv *serv;unsigned int npools =svc_pool_map_get (); - serv =__svc_create (prog, bufsize, npools, ops); + serv =__svc_create (prog, bufsize, npools, threadfn);if (!serv) goto out_err;return serv;
@@ -736,7 +751,7 @@ svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)if (IS_ERR (rqstp))return PTR_ERR (rqstp); - task =kthread_create_on_node (serv->sv_ops->svo_function, rqstp, + task =kthread_create_on_node (serv->sv_threadfn, rqstp, node,"%s" , serv->sv_name);if (IS_ERR (task)) {svc_exit_thread (rqstp);
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 280/690 NFSD: Remove CONFIG_NFSD_V3
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 5f9a62ff7d2808c7b56c0ec90f3b7eae5872afe6 ]
Eventually support for NFSv2 in the Linux NFS server is to be deprecated and then removed.
However, NFSv2 is the "always supported" version that is available as soon as CONFIG_NFSD is set. Before NFSv2 support can be removed, we need to choose a different "always supported" version.
This patch removes CONFIG_NFSD_V3 so that NFSv3 is always supported, as NFSv2 is today. When NFSv2 support is removed, NFSv3 will become the only "always supported" NFS version.
The defconfigs still need to be updated to remove CONFIG_NFSD_V3=y.
--- fs/Kconfig | 2 +- fs/nfsd/Kconfig | 12 +----------- fs/nfsd/Makefile | 3 +-- fs/nfsd/nfsfh.c | 4 ---- fs/nfsd/nfsfh.h | 20 -------------------- fs/nfsd/nfssvc.c | 2 -- fs/nfsd/vfs.c | 9 --------- fs/nfsd/vfs.h | 2 -- 8 files changed, 3 insertions(+), 51 deletions(-)
fs/Kconfig +1 -1
@@ -344,7 +344,7 @@ config LOCKD config LOCKD_V4 bool - depends on NFSD_V3 || NFS_V3 + depends on NFSD || NFS_V3 depends on FILE_LOCKING default y
fs/nfsd/Kconfig +1 -11
@@ -35,18 +35,9 @@ config NFSD_V2_ACL bool depends on NFSD -config NFSD_V3 - bool "NFS server support for NFS version 3" - depends on NFSD - help - This option enables support in your system's NFS server for - version 3 of the NFS protocol (RFC 1813). - - If unsure, say Y. - config NFSD_V3_ACL bool "NFS server support for the NFSv3 ACL protocol extension" - depends on NFSD_V3 + depends on NFSD select NFSD_V2_ACL help Solaris NFS servers support an auxiliary NFSv3 ACL protocol that
@@ -70,7 +61,6 @@ config NFSD_V3_ACL config NFSD_V4 bool "NFS server support for NFS version 4" depends on NFSD && PROC_FS - select NFSD_V3 select FS_POSIX_ACL select SUNRPC_GSS select CRYPTO
fs/nfsd/Makefile +1 -2
@@ -12,9 +12,8 @@ nfsd-y += trace.o nfsd-y += nfssvc.o nfsctl.o nfsproc.o nfsfh.o vfs.o \ export.o auth.o lockd.o nfscache.o nfsxdr.o \ - stats.o filecache.o + stats.o filecache.o nfs3proc.o nfs3xdr.o nfsd-$(CONFIG_NFSD_V2_ACL) += nfs2acl.o -nfsd-$(CONFIG_NFSD_V3) += nfs3proc.o nfs3xdr.o nfsd-$(CONFIG_NFSD_V3_ACL) += nfs3acl.o nfsd-$(CONFIG_NFSD_V4) += nfs4proc.o nfs4xdr.o nfs4state.o nfs4idmap.o \ nfs4acl.o nfs4callback.o nfs4recover.o
fs/nfsd/nfsfh.c +0 -4
@@ -611,8 +611,6 @@ fh_update(struct svc_fh *fhp)return nfserr_serverfault; } -#ifdef CONFIG_NFSD_V3 -/** * fh_fill_pre_attrs - Fill in pre-op attributes * @fhp: file handle to be updated
@@ -673,8 +671,6 @@ void fh_fill_post_attrs(struct svc_fh *fhp)nfsd4_change_attribute (&fhp->fh_post_attr, inode); } -#endif /* CONFIG_NFSD_V3 */ -/* * Release a file handle. */
fs/nfsd/nfsfh.h +0 -20
@@ -90,7 +90,6 @@ typedef struct svc_fh {* operation */ int fh_flags;/* FH flags */ -#ifdef CONFIG_NFSD_V3 bool fh_post_saved;/* post-op attrs saved */ bool fh_pre_saved;/* pre-op attrs saved */
@@ -107,7 +106,6 @@ typedef struct svc_fh {/* Post-op attributes saved in fh_unlock */ struct kstat fh_post_attr;/* full attrs after operation */ u64 fh_post_change;/* nfsv4 change; see above */ -#endif /* CONFIG_NFSD_V3 */ } svc_fh;#define NFSD4_FH_FOREIGN (1<<0)#define SET_FH_FLAG (c, f) ((c)->fh_flags |= (f))
@@ -283,8 +281,6 @@ static inline u32 knfsd_fh_hash(const struct knfsd_fh *fh) }#endif -#ifdef CONFIG_NFSD_V3 -/** * fh_clear_pre_post_attrs - Reset pre/post attributes * @fhp: file handle to be updated
@@ -327,22 +323,6 @@ static inline u64 nfsd4_change_attribute(struct kstat *stat,extern void fh_fill_pre_attrs (struct svc_fh *fhp);extern void fh_fill_post_attrs (struct svc_fh *fhp); -#else /* !CONFIG_NFSD_V3 */ - -static inline void fh_clear_pre_post_attrs (struct svc_fh *fhp) -{ -} - -static inline void fh_fill_pre_attrs (struct svc_fh *fhp) -{ -} - -static inline void fh_fill_post_attrs (struct svc_fh *fhp) -{ -} - -#endif /* !CONFIG_NFSD_V3 */ -/* * Lock a file handle/inode
fs/nfsd/nfssvc.c +0 -2
@@ -117,9 +117,7 @@ static struct svc_stat nfsd_acl_svcstats = {static const struct svc_version *nfsd_version[] = { [2 ] = &nfsd_version2, -#if defined(CONFIG_NFSD_V3) [3 ] = &nfsd_version3, -#endif #if defined(CONFIG_NFSD_V4) [4 ] = &nfsd_version4, #endif
fs/nfsd/vfs.c +0 -9
@@ -32,9 +32,7 @@#include <linux/writeback.h> #include <linux/security.h> -#ifdef CONFIG_NFSD_V3 #include "xdr3.h" -#endif /* CONFIG_NFSD_V3 */ #ifdef CONFIG_NFSD_V4 #include "../internal.h"
@@ -616,7 +614,6 @@ __be32 nfsd4_vfs_fallocate(struct svc_rqst *rqstp, struct svc_fh *fhp, }#endif /* defined(CONFIG_NFSD_V4) */ -#ifdef CONFIG_NFSD_V3 /* * Check server access rights to a file system object */
@@ -728,7 +725,6 @@ nfsd_access(struct svc_rqst *rqstp, struct svc_fh *fhp, u32 *access, u32 *suppor out:return error; } -#endif /* CONFIG_NFSD_V3 */ int nfsd_open_break_lease (struct inode *inode,int access) {
@@ -1121,7 +1117,6 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, loff_t offset,return err; } -#ifdef CONFIG_NFSD_V3 /** * nfsd_commit - Commit pending writes to stable storage * @rqstp: RPC request being processed
@@ -1199,7 +1194,6 @@ nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp, u64 offset, out:return err; } -#endif /* CONFIG_NFSD_V3 */ static __be32 nfsd_create_setattr(struct svc_rqst *rqstp, struct svc_fh *resfhp,
@@ -1389,8 +1383,6 @@ nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp, rdev, resfhp); } -#ifdef CONFIG_NFSD_V3 -/* * NFSv3 and NFSv4 version of nfsd_create */
@@ -1556,7 +1548,6 @@ do_nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp, err =nfserrno (host_err); goto out; } -#endif /* CONFIG_NFSD_V3 */ /* * Read a symlink. On entry, *lenp must contain the maximum path length that
fs/nfsd/vfs.h +0 -2
@@ -68,7 +68,6 @@ __be32 nfsd_create_locked(struct svc_rqst *, struct svc_fh *,__be32 nfsd_create (struct svc_rqst *,struct svc_fh *,char *name,int len,struct iattr *attrs,int type,dev_t rdev,struct svc_fh *res); -#ifdef CONFIG_NFSD_V3 __be32 nfsd_access (struct svc_rqst *,struct svc_fh *,u32 *,u32 *); __be32 do_nfsd_create(struct svc_rqst *, struct svc_fh *, char *name, int len, struct iattr *attrs,
@@ -76,7 +75,6 @@ __be32 do_nfsd_create(struct svc_rqst *, struct svc_fh *, u32 *verifier, bool *truncp, bool *created);__be32 nfsd_commit (struct svc_rqst *rqst,struct svc_fh *fhp,u64 offset,u32 count,__be32 *verf); -#endif /* CONFIG_NFSD_V3 */ #ifdef CONFIG_NFSD_V4 __be32 nfsd_getxattr (struct svc_rqst *rqstp,struct svc_fh *fhp,char *name,void **bufp,int *lenp);
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 281/690 NFSD: Clean up _lm_ operation names
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 35aff0678f99b0623bb72d50112de9e163a19559 ]
The common practice is to name function instances the same as the method names, but with a uniquifying prefix. Commit aef9583b234a ("NFSD: Get reference of lockowner when coping file_lock") missed this -- the new function names should both have been of the form "nfsd4_lm_*".
Before more lock manager operations are added in NFSD, rename these two functions for consistency.
--- fs/nfsd/nfs4state.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/nfsd/nfs4state.c +4 -4
@@ -6552,7 +6552,7 @@ nfs4_transform_lock_offset(struct file_lock *lock) }static fl_owner_t -nfsd4_fl_get_owner (fl_owner_t owner) +nfsd4_lm_get_owner (fl_owner_t owner) {struct nfs4_lockowner *lo = (struct nfs4_lockowner *)owner;
@@ -6561,7 +6561,7 @@ nfsd4_fl_get_owner(fl_owner_t owner) }static void -nfsd4_fl_put_owner (fl_owner_t owner) +nfsd4_lm_put_owner (fl_owner_t owner) {struct nfs4_lockowner *lo = (struct nfs4_lockowner *)owner;
@@ -6596,8 +6596,8 @@ nfsd4_lm_notify(struct file_lock *fl)static const struct lock_manager_operations nfsd_posix_mng_ops = { .lm_notify = nfsd4_lm_notify, - .lm_get_owner = nfsd4_fl_get_owner, - .lm_put_owner = nfsd4_fl_put_owner, + .lm_get_owner = nfsd4_lm_get_owner, + .lm_put_owner = nfsd4_lm_put_owner, }; static inline void
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 282/690 nfsd: fix using the correct variable for sizeof()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakob Koschel <[email protected]>
[ Upstream commit 4fc5f5346592cdc91689455d83885b0af65d71b8 ]
While the original code is valid, it is not the obvious choice for the sizeof() call and in preparation to limit the scope of the list iterator variable the sizeof should be changed to the size of the destination.
--- fs/nfsd/nfs4layouts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfsd/nfs4layouts.c +1 -1
@@ -421,7 +421,7 @@ nfsd4_insert_layout(struct nfsd4_layoutget *lgp, struct nfs4_layout_stateid *ls) new =kmem_cache_alloc (nfs4_layout_cache,GFP_KERNEL );if (!new)return nfserr_jukebox; -memcpy (&new->lo_seg, seg,sizeof (lp->lo_seg)); +memcpy (&new->lo_seg, seg,sizeof (new->lo_seg)); new->lo_state = ls;spin_lock (&fp->fi_lock);
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 283/690 fsnotify: fix merge with parents ignored mask
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit 4f0b903ded728c505850daf2914bfc08841f0ae6 ]
fsnotify_parent() does not consider the parent's mark at all unless the parent inode shows interest in events on children and in the specific event.
So unless parent added an event to both its mark mask and ignored mask, the event will not be ignored.
Fix this by declaring the interest of an object in an event when the event is in either a mark mask or ignored mask.
--- fs/notify/fanotify/fanotify_user.c | 17 +++++++++-------- fs/notify/mark.c | 4 ++-- include/linux/fsnotify_backend.h | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 10 deletions(-)
fs/notify/fanotify/fanotify_user.c +9 -8
@@ -999,17 +999,18 @@ static __u32 fanotify_mark_remove_from_mask(struct fsnotify_mark *fsn_mark, __u32 mask, unsigned int flags, __u32 umask, int *destroy) { - __u32 oldmask = 0; + __u32 oldmask, newmask;/* umask bits cannot be removed by user */ mask &= ~umask;spin_lock (&fsn_mark->lock); + oldmask =fsnotify_calc_mask (fsn_mark);if (!(flags &FAN_MARK_IGNORED_MASK )) { - oldmask = fsn_mark->mask; fsn_mark->mask &= ~mask; }else { fsn_mark->ignored_mask &= ~mask; } + newmask =fsnotify_calc_mask (fsn_mark);/* * We need to keep the mark around even if remaining mask cannot * result in any events (e.g. mask == FAN_ONDIR) to support incremenal
@@ -1019,7 +1020,7 @@ static __u32 fanotify_mark_remove_from_mask(struct fsnotify_mark *fsn_mark, *destroy = !((fsn_mark->mask | fsn_mark->ignored_mask) & ~umask);spin_unlock (&fsn_mark->lock); -return mask & oldmask; +return oldmask & ~newmask; } static int fanotify_remove_mark(struct fsnotify_group *group,
@@ -1077,23 +1078,23 @@ static int fanotify_remove_inode_mark(struct fsnotify_group *group, }static __u32 fanotify_mark_add_to_mask (struct fsnotify_mark *fsn_mark, -__u32 mask, -unsigned int flags) +__u32 mask,unsigned int flags) { -__u32 oldmask =-1 ; +__u32 oldmask, newmask;spin_lock (&fsn_mark->lock); + oldmask =fsnotify_calc_mask (fsn_mark);if (!(flags &FAN_MARK_IGNORED_MASK )) { - oldmask = fsn_mark->mask; fsn_mark->mask |= mask; }else { fsn_mark->ignored_mask |= mask;if (flags &FAN_MARK_IGNORED_SURV_MODIFY ) fsn_mark->flags |=FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY ; } + newmask =fsnotify_calc_mask (fsn_mark);spin_unlock (&fsn_mark->lock); -return mask & ~oldmask; +return newmask & ~oldmask; } static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group,
fs/notify/mark.c +2 -2
@@ -127,7 +127,7 @@ static void __fsnotify_recalc_mask(struct fsnotify_mark_connector *conn)return ;hlist_for_each_entry (mark, &conn->list, obj_list) {if (mark->flags &FSNOTIFY_MARK_FLAG_ATTACHED ) - new_mask |= mark->mask; + new_mask |=fsnotify_calc_mask (mark); } *fsnotify_conn_mask_p (conn) = new_mask; }
@@ -692,7 +692,7 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark,if (ret) goto err; -if (mark->mask) +if (mark->mask || mark->ignored_mask)fsnotify_recalc_mask (mark->connector);return ret;
include/linux/fsnotify_backend.h +15 -0
@@ -601,6 +601,21 @@ extern void fsnotify_remove_queued_event(struct fsnotify_group *group,/* functions used to manipulate the marks attached to inodes */ +/* Get mask for calculating object interest taking ignored mask into account */ +static inline __u32 fsnotify_calc_mask (struct fsnotify_mark *mark) +{ +__u32 mask = mark->mask; + +if (!mark->ignored_mask) +return mask; + +/* +* If mark is interested in ignoring events on children, the object must +* show interest in those events for fsnotify_parent() to notice it. +*/ +return mask | (mark->ignored_mask &ALL_FSNOTIFY_EVENTS ); +} +/* Get mask of events for a list of marks */ extern __u32 fsnotify_conn_mask (struct fsnotify_mark_connector *conn);/* Calculate mask of events for a list of marks */
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 284/690 fsnotify: optimize FS_MODIFY events with no ignored masks
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit 04e317ba72d07901b03399b3d1525e83424df5b3 ]
fsnotify() treats FS_MODIFY events specially - it does not skip them even if the FS_MODIFY event does not apear in the object's fsnotify mask. This is because send_to_group() checks if FS_MODIFY needs to clear ignored mask of marks.
The common case is that an object does not have any mark with ignored mask and in particular, that it does not have a mark with ignored mask and without the FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY flag.
Set FS_MODIFY in object's fsnotify mask during fsnotify_recalc_mask() if object has a mark with an ignored mask and without the FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY flag and remove the special treatment of FS_MODIFY in fsnotify(), so that FS_MODIFY events could be optimized in the common case.
Call fsnotify_recalc_mask() from fanotify after adding or removing an ignored mask from a mark without FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY or when adding the FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY flag to a mark with ignored mask (the flag cannot be removed by fanotify uapi).
Performance results for doing 10000000 write(2)s to tmpfs:
vanilla patched
without notification mark 25.486+-1.054 24.965+-0.244
with notification mark 30.111+-0.139 26.891+-1.355
So we can see the overhead of notification subsystem has been drastically reduced.
--- fs/notify/fanotify/fanotify_user.c | 32 +++++++++++++++++++++++------- fs/notify/fsnotify.c | 8 +++++--- include/linux/fsnotify_backend.h | 4 ++++ 3 files changed, 34 insertions(+), 10 deletions(-)
fs/notify/fanotify/fanotify_user.c +25 -7
@@ -1077,8 +1077,28 @@ static int fanotify_remove_inode_mark(struct fsnotify_group *group, flags, umask); } +static void fanotify_mark_add_ignored_mask (struct fsnotify_mark *fsn_mark, +__u32 mask,unsigned int flags, +__u32 *removed) +{ + fsn_mark->ignored_mask |= mask; + +/* +* Setting FAN_MARK_IGNORED_SURV_MODIFY for the first time may lead to +* the removal of the FS_MODIFY bit in calculated mask if it was set +* because of an ignored mask that is now going to survive FS_MODIFY. +*/ +if ((flags &FAN_MARK_IGNORED_SURV_MODIFY ) && + !(fsn_mark->flags &FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY )) { + fsn_mark->flags |=FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY ; +if (!(fsn_mark->mask &FS_MODIFY )) + *removed =FS_MODIFY ; + } +} +static __u32 fanotify_mark_add_to_mask (struct fsnotify_mark *fsn_mark, -__u32 mask,unsigned int flags) +__u32 mask,unsigned int flags, +__u32 *removed) {__u32 oldmask, newmask;
@@ -1087,9 +1107,7 @@ static __u32 fanotify_mark_add_to_mask(struct fsnotify_mark *fsn_mark,if (!(flags &FAN_MARK_IGNORED_MASK )) { fsn_mark->mask |= mask; }else { - fsn_mark->ignored_mask |= mask; -if (flags &FAN_MARK_IGNORED_SURV_MODIFY ) - fsn_mark->flags |=FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY ; +fanotify_mark_add_ignored_mask (fsn_mark, mask, flags, removed); } newmask =fsnotify_calc_mask (fsn_mark);spin_unlock (&fsn_mark->lock);
@@ -1152,7 +1170,7 @@ static int fanotify_add_mark(struct fsnotify_group *group, __kernel_fsid_t *fsid) {struct fsnotify_mark *fsn_mark; -__u32 added; +__u32 added, removed =0 ;int ret =0 ;mutex_lock (&group->mark_mutex);
@@ -1175,8 +1193,8 @@ static int fanotify_add_mark(struct fsnotify_group *group, goto out; } - added =fanotify_mark_add_to_mask (fsn_mark, mask, flags); -if (added & ~fsnotify_conn_mask (fsn_mark->connector)) + added =fanotify_mark_add_to_mask (fsn_mark, mask, flags, &removed); +if (removed || (added & ~fsnotify_conn_mask (fsn_mark->connector)))fsnotify_recalc_mask (fsn_mark->connector); out:
fs/notify/fsnotify.c +5 -3
@@ -531,11 +531,13 @@ int fsnotify(__u32 mask, const void *data, int data_type, struct inode *dir,/* -* if this is a modify event we may need to clear the ignored masks -* otherwise return if none of the marks care about this type of event. +* If this is a modify event we may need to clear some ignored masks. +* In that case, the object with ignored masks will have the FS_MODIFY +* event in its mask. +* Otherwise, return if none of the marks care about this type of event. */ test_mask = (mask &ALL_FSNOTIFY_EVENTS ); -if (!(mask &FS_MODIFY ) && !(test_mask & marks_mask)) +if (!(test_mask & marks_mask))return 0 ; iter_info.srcu_idx =srcu_read_lock (&fsnotify_mark_srcu);
include/linux/fsnotify_backend.h +4 -0
@@ -609,6 +609,10 @@ static inline __u32 fsnotify_calc_mask(struct fsnotify_mark *mark)if (!mark->ignored_mask)return mask; +/* Interest in FS_MODIFY may be needed for clearing ignored mask */ +if (!(mark->flags &FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY )) + mask |=FS_MODIFY ; +/* * If mark is interested in ignoring events on children, the object must * show interest in those events for fsnotify_parent() to notice it.
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 285/690 fsnotify: remove redundant parameter judgment
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bang Li <[email protected]>
[ Upstream commit f92ca72b0263d601807bbd23ed25cbe6f4da89f4 ]
iput() has already judged the incoming parameter, so there is no need to repeat the judgment here.
--- fs/notify/fsnotify.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
fs/notify/fsnotify.c +2 -4
@@ -70,8 +70,7 @@ static void fsnotify_unmount_inodes(struct super_block *sb)spin_unlock (&inode->i_lock);spin_unlock (&sb->s_inode_list_lock); -if (iput_inode) -iput (iput_inode); +iput (iput_inode);/* for each watch, send FS_UNMOUNT and then remove it */ fsnotify_inode (inode,FS_UNMOUNT );
@@ -85,8 +84,7 @@ static void fsnotify_unmount_inodes(struct super_block *sb) }spin_unlock (&sb->s_inode_list_lock); -if (iput_inode) -iput (iput_inode); +iput (iput_inode); }void fsnotify_sb_delete (struct super_block *sb)
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 286/690 nfsd: Fix a write performance regression
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Trond Myklebust <[email protected]>
[ Upstream commit 6b8a94332ee4f7d9a8ae0cbac7609f79c212f06c ]
The call to filemap_flush() in nfsd_file_put() is there to ensure that we clear out any writes belonging to a NFSv3 client relatively quickly and avoid situations where the file can't be evicted by the garbage collector. It also ensures that we detect write errors quickly.
The problem is this causes a regression in performance for some workloads.
So try to improve matters by deferring writeback until we're ready to close the file, and need to detect errors so that we can force the client to resend.
--- fs/nfsd/filecache.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
fs/nfsd/filecache.c +15 -3
@@ -229,6 +229,13 @@ nfsd_file_check_write_error(struct nfsd_file *nf)return filemap_check_wb_err (file->f_mapping,READ_ONCE (file->f_wb_err)); } +static void +nfsd_file_flush (struct nfsd_file *nf) +{ +if (nf->nf_file &&vfs_fsync (nf->nf_file,1 ) !=0 ) +nfsd_reset_write_verifier (net_generic (nf->nf_net, nfsd_net_id)); +} +static void nfsd_file_do_unhash (struct nfsd_file *nf) {
@@ -296,11 +303,14 @@ nfsd_file_put(struct nfsd_file *nf)return ; } -filemap_flush (nf->nf_file->f_mapping); is_hashed =test_bit (NFSD_FILE_HASHED , &nf->nf_flags) !=0 ; -nfsd_file_put_noref (nf); -if (is_hashed) +if (!is_hashed) { +nfsd_file_flush (nf); +nfsd_file_put_noref (nf); + }else { +nfsd_file_put_noref (nf);nfsd_file_schedule_laundrette (); + }if (atomic_long_read (&nfsd_filecache_count) >=NFSD_FILE_LRU_LIMIT )nfsd_file_gc (); }
@@ -321,6 +331,7 @@ nfsd_file_dispose_list(struct list_head *dispose)while (!list_empty (dispose)) { nf = list_first_entry(dispose, struct nfsd_file, nf_lru);list_del (&nf->nf_lru); +nfsd_file_flush (nf);nfsd_file_put_noref (nf); } }
@@ -334,6 +345,7 @@ nfsd_file_dispose_list_sync(struct list_head *dispose)while (!list_empty (dispose)) { nf = list_first_entry(dispose, struct nfsd_file, nf_lru);list_del (&nf->nf_lru); +nfsd_file_flush (nf);if (!refcount_dec_and_test (&nf->nf_ref))continue ;if (nfsd_file_free (nf))
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 287/690 nfsd: Clean up nfsd_file_put()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Trond Myklebust <[email protected]>
[ Upstream commit 999397926ab3f78c7d1235cc4ca6e3c89d2769bf ]
Make it a little less racy, by removing the refcount_read() test. Then remove the redundant 'is_hashed' variable.
--- fs/nfsd/filecache.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
fs/nfsd/filecache.c +3 -10
@@ -295,21 +295,14 @@ nfsd_file_put_noref(struct nfsd_file *nf)void nfsd_file_put (struct nfsd_file *nf) { -bool is_hashed; -set_bit (NFSD_FILE_REFERENCED , &nf->nf_flags); -if (refcount_read (&nf->nf_ref) >2 || !nf->nf_file) { -nfsd_file_put_noref (nf); -return ; - } - - is_hashed =test_bit (NFSD_FILE_HASHED , &nf->nf_flags) !=0 ; -if (!is_hashed) { +if (test_bit (NFSD_FILE_HASHED , &nf->nf_flags) ==0 ) {nfsd_file_flush (nf);nfsd_file_put_noref (nf); }else {nfsd_file_put_noref (nf); -nfsd_file_schedule_laundrette (); +if (nf->nf_file) +nfsd_file_schedule_laundrette (); }if (atomic_long_read (&nfsd_filecache_count) >=NFSD_FILE_LRU_LIMIT )nfsd_file_gc ();
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 288/690 fanotify: do not allow setting dirent events in mask of non-dir
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit ceaf69f8eadcafb323392be88e7a5248c415d423 ]
Dirent events (create/delete/move) are only reported on watched directory inodes, but in fanotify as well as in legacy inotify, it was always allowed to set them on non-dir inode, which does not result in any meaningful outcome.
Until kernel v5.17, dirent events in fanotify also differed from events "on child" (e.g. FAN_OPEN) in the information provided in the event. For example, FAN_OPEN could be set in the mask of a non-dir or the mask of its parent and event would report the fid of the child regardless of the marked object.
By contrast, FAN_DELETE is not reported if the child is marked and the child fid was not reported in the events.
Since kernel v5.17, with fanotify group flag FAN_REPORT_TARGET_FID, the fid of the child is reported with dirent events, like events "on child", which may create confusion for users expecting the same behavior as events "on child" when setting events in the mask on a child.
The desired semantics of setting dirent events in the mask of a child are not clear, so for now, deny this action for a group initialized with flag FAN_REPORT_TARGET_FID and for the new event FAN_RENAME. We may relax this restriction in the future if we decide on the semantics and implement them.
--- fs/notify/fanotify/fanotify_user.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
fs/notify/fanotify/fanotify_user.c +13 -0
@@ -1671,6 +1671,19 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask,else mnt = path.mnt; +/* +* FAN_RENAME is not allowed on non-dir (for now). +* We shouldn't have allowed setting any dirent events in mask of +* non-dir, but because we always allowed it, error only if group +* was initialized with the new flag FAN_REPORT_TARGET_FID. +*/ + ret = -ENOTDIR ; +if (inode && !S_ISDIR (inode->i_mode) && + ((mask &FAN_RENAME ) || + ((mask &FANOTIFY_DIRENT_EVENTS ) && +FAN_GROUP_FLAG (group,FAN_REPORT_TARGET_FID )))) + goto path_put_and_out; +/* Mask out FAN_EVENT_ON_CHILD flag for sb/mount/non-dir marks */ if (mnt || !S_ISDIR (inode->i_mode)) { mask &= ~FAN_EVENT_ON_CHILD ;
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 289/690 fs/lock: documentation cleanup. Replace inode->i_lock with flc_lock.
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dai Ngo <[email protected]>
[ Upstream commit 9d6647762b9c6b555bc83d97d7c93be6057a990f ]
Update lock usage of lock_manager_operations' functions to reflect the changes in commit 6109c85037e5 ("locks: add a dedicated spinlock to protect i_flctx lists").
--- Documentation/filesystems/locking.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Documentation/filesystems/locking.rst +3 -3
@@ -446,13 +446,13 @@ prototypes:: locking rules: ====================== ============= ================= ========= -ops inode->i_lock blocked_lock_lock may block +ops flc_lock blocked_lock_lock may block ====================== ============= ================= ========= -lm_notify: yes yes no +lm_notify: no yes no lm_grant: no no no lm_break: yes no no lm_change yes no no -lm_breaker_owns_lease: no no no +lm_breaker_owns_lease: yes no no ====================== ============= ================= ========= buffer_head
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 290/690 inotify: move control flags from mask to mark flags
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit 38035c04f5865c4ef9597d6beed6a7178f90f64a ]
The inotify control flags in the mark mask (e.g. FS_IN_ONE_SHOT) are not relevant to object interest mask, so move them to the mark flags.
This frees up some bits in the object interest mask.
--- fs/notify/fsnotify.c | 4 +-- fs/notify/inotify/inotify.h | 11 ++++++-- fs/notify/inotify/inotify_fsnotify.c | 2 +- fs/notify/inotify/inotify_user.c | 38 ++++++++++++++++++---------- include/linux/fsnotify_backend.h | 16 +++++++----- 5 files changed, 45 insertions(+), 26 deletions(-)
fs/notify/fsnotify.c +2 -2
@@ -253,7 +253,7 @@ static int fsnotify_handle_inode_event(struct fsnotify_group *group,if (WARN_ON_ONCE (!inode && !dir))return 0 ; -if ((inode_mark->mask &FS_EXCL_UNLINK ) && +if ((inode_mark->flags &FSNOTIFY_MARK_FLAG_EXCL_UNLINK ) && path &&d_unlinked (path->dentry))return 0 ;
@@ -581,7 +581,7 @@ static __init int fsnotify_init(void) {int ret; -BUILD_BUG_ON (HWEIGHT32 (ALL_FSNOTIFY_BITS ) !=25 ); +BUILD_BUG_ON (HWEIGHT32 (ALL_FSNOTIFY_BITS ) !=23 ); ret =init_srcu_struct (&fsnotify_mark_srcu);if (ret)
fs/notify/inotify/inotify.h +9 -2
@@ -27,11 +27,18 @@ static inline struct inotify_event_info *INOTIFY_E(struct fsnotify_event *fse)* userspace. There is at least one bit (FS_EVENT_ON_CHILD) which is * used only internally to the kernel. */ -#define INOTIFY_USER_MASK (IN_ALL_EVENTS | IN_ONESHOT | IN_EXCL_UNLINK) +#define INOTIFY_USER_MASK (IN_ALL_EVENTS)static inline __u32 inotify_mark_user_mask (struct fsnotify_mark *fsn_mark) { -return fsn_mark->mask &INOTIFY_USER_MASK ; +__u32 mask = fsn_mark->mask &INOTIFY_USER_MASK ; + +if (fsn_mark->flags &FSNOTIFY_MARK_FLAG_EXCL_UNLINK ) + mask |=IN_EXCL_UNLINK ; +if (fsn_mark->flags &FSNOTIFY_MARK_FLAG_IN_ONESHOT ) + mask |=IN_ONESHOT ; + +return mask; } extern void inotify_ignored_and_remove_idr(struct fsnotify_mark *fsn_mark,
fs/notify/inotify/inotify_fsnotify.c +1 -1
@@ -129,7 +129,7 @@ int inotify_handle_inode_event(struct fsnotify_mark *inode_mark, u32 mask,fsnotify_destroy_event (group, fsn_event); } -if (inode_mark->mask &IN_ONESHOT ) +if (inode_mark->flags &FSNOTIFY_MARK_FLAG_IN_ONESHOT )fsnotify_destroy_mark (inode_mark, group);return 0 ;
fs/notify/inotify/inotify_user.c +24 -14
@@ -107,6 +107,21 @@ static inline __u32 inotify_arg_to_mask(struct inode *inode, u32 arg)return mask; } +#define INOTIFY_MARK_FLAGS \ + (FSNOTIFY_MARK_FLAG_EXCL_UNLINK | FSNOTIFY_MARK_FLAG_IN_ONESHOT) + +static inline unsigned int inotify_arg_to_flags (u32 arg) +{ +unsigned int flags =0 ; + +if (arg &IN_EXCL_UNLINK ) + flags |=FSNOTIFY_MARK_FLAG_EXCL_UNLINK ; +if (arg &IN_ONESHOT ) + flags |=FSNOTIFY_MARK_FLAG_IN_ONESHOT ; + +return flags; +} +static inline u32 inotify_mask_to_arg (__u32 mask) { return mask & (IN_ALL_EVENTS | IN_ISDIR | IN_UNMOUNT | IN_IGNORED |
@@ -518,13 +533,10 @@ static int inotify_update_existing_watch(struct fsnotify_group *group,struct fsnotify_mark *fsn_mark;struct inotify_inode_mark *i_mark;__u32 old_mask, new_mask; -__u32 mask; -int add = (arg &IN_MASK_ADD ); +int replace = !(arg &IN_MASK_ADD );int create = (arg &IN_MASK_CREATE );int ret; - mask =inotify_arg_to_mask (inode, arg); - fsn_mark =fsnotify_find_mark (&inode->i_fsnotify_marks, group);if (!fsn_mark)return -ENOENT ;
@@ -537,10 +549,12 @@ static int inotify_update_existing_watch(struct fsnotify_group *group,spin_lock (&fsn_mark->lock); old_mask = fsn_mark->mask; -if (add) - fsn_mark->mask |= mask; -else - fsn_mark->mask = mask; +if (replace) { + fsn_mark->mask =0 ; + fsn_mark->flags &= ~INOTIFY_MARK_FLAGS ; + } + fsn_mark->mask |=inotify_arg_to_mask (inode, arg); + fsn_mark->flags |=inotify_arg_to_flags (arg); new_mask = fsn_mark->mask;spin_unlock (&fsn_mark->lock);
@@ -571,19 +585,17 @@ static int inotify_new_watch(struct fsnotify_group *group, u32 arg) {struct inotify_inode_mark *tmp_i_mark; -__u32 mask;int ret;struct idr *idr = &group->inotify_data.idr;spinlock_t *idr_lock = &group->inotify_data.idr_lock; - mask =inotify_arg_to_mask (inode, arg); - tmp_i_mark =kmem_cache_alloc (inotify_inode_mark_cachep,GFP_KERNEL );if (unlikely (!tmp_i_mark))return -ENOMEM ;fsnotify_init_mark (&tmp_i_mark->fsn_mark, group); - tmp_i_mark->fsn_mark.mask = mask; + tmp_i_mark->fsn_mark.mask =inotify_arg_to_mask (inode, arg); + tmp_i_mark->fsn_mark.flags =inotify_arg_to_flags (arg); tmp_i_mark->wd =-1 ; ret =inotify_add_to_idr (idr, idr_lock, tmp_i_mark);
@@ -837,9 +849,7 @@ static int __init inotify_user_setup(void)BUILD_BUG_ON (IN_UNMOUNT !=FS_UNMOUNT );BUILD_BUG_ON (IN_Q_OVERFLOW !=FS_Q_OVERFLOW );BUILD_BUG_ON (IN_IGNORED !=FS_IN_IGNORED ); -BUILD_BUG_ON (IN_EXCL_UNLINK !=FS_EXCL_UNLINK );BUILD_BUG_ON (IN_ISDIR !=FS_ISDIR ); -BUILD_BUG_ON (IN_ONESHOT !=FS_IN_ONESHOT );BUILD_BUG_ON (HWEIGHT32 (ALL_INOTIFY_BITS ) !=22 );
include/linux/fsnotify_backend.h +9 -7
@@ -55,7 +55,6 @@#define FS_ACCESS_PERM 0x00020000/* access event in a permissions hook */ #define FS_OPEN_EXEC_PERM 0x00040000/* open/exec event in a permission hook */ -#define FS_EXCL_UNLINK 0x04000000/* do not send events if object is unlinked */ /* * Set on inode mark that cares about things that happen to its children. * Always set for dnotify and inotify.
@@ -66,7 +65,6 @@#define FS_RENAME 0x10000000/* File was renamed */ #define FS_DN_MULTISHOT 0x20000000/* dnotify multishot */ #define FS_ISDIR 0x40000000/* event occurred against dir */ -#define FS_IN_ONESHOT 0x80000000/* only send event once */ #define FS_MOVE (FS_MOVED_FROM | FS_MOVED_TO)
@@ -106,8 +104,7 @@ FS_ERROR)/* Extra flags that may be reported with event or control handling of events */ -#define ALL_FSNOTIFY_FLAGS (FS_EXCL_UNLINK | FS_ISDIR | FS_IN_ONESHOT | \ - FS_DN_MULTISHOT | FS_EVENT_ON_CHILD) +#define ALL_FSNOTIFY_FLAGS (FS_ISDIR | FS_EVENT_ON_CHILD | FS_DN_MULTISHOT)#define ALL_FSNOTIFY_BITS (ALL_FSNOTIFY_EVENTS | ALL_FSNOTIFY_FLAGS)
@@ -473,9 +470,14 @@ struct fsnotify_mark {struct fsnotify_mark_connector *connector;/* Events types to ignore [mark->lock, group->mark_mutex] */ __u32 ignored_mask; -#define FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY 0x01 -#define FSNOTIFY_MARK_FLAG_ALIVE 0x02 -#define FSNOTIFY_MARK_FLAG_ATTACHED 0x04 +/* General fsnotify mark flags */ +#define FSNOTIFY_MARK_FLAG_ALIVE 0x0001 +#define FSNOTIFY_MARK_FLAG_ATTACHED 0x0002 +/* inotify mark flags */ +#define FSNOTIFY_MARK_FLAG_EXCL_UNLINK 0x0010 +#define FSNOTIFY_MARK_FLAG_IN_ONESHOT 0x0020 +/* fanotify mark flags */ +#define FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY 0x0100unsigned int flags;/* flags [mark->lock] */ };
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 291/690 fsnotify: pass flags argument to fsnotify_alloc_group()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit 867a448d587e7fa845bceaf4ee1c632448f2a9fa ]
Add flags argument to fsnotify_alloc_group(), define and use the flag FSNOTIFY_GROUP_USER in inotify and fanotify instead of the helper fsnotify_alloc_user_group() to indicate user allocation.
Although the flag FSNOTIFY_GROUP_USER is currently not used after group allocation, we store the flags argument in the group struct for future use of other group flags.
--- fs/nfsd/filecache.c | 3 ++- fs/notify/dnotify/dnotify.c | 2 +- fs/notify/fanotify/fanotify_user.c | 3 ++- fs/notify/group.c | 21 +++++++++------------ fs/notify/inotify/inotify_user.c | 3 ++- include/linux/fsnotify_backend.h | 8 ++++++-- kernel/audit_fsnotify.c | 3 ++- kernel/audit_tree.c | 2 +- kernel/audit_watch.c | 2 +- 9 files changed, 26 insertions(+), 21 deletions(-)
fs/nfsd/filecache.c +2 -1
@@ -671,7 +671,8 @@ nfsd_file_cache_init(void) goto out_shrinker; } - nfsd_file_fsnotify_group =fsnotify_alloc_group (&nfsd_file_fsnotify_ops); + nfsd_file_fsnotify_group =fsnotify_alloc_group (&nfsd_file_fsnotify_ops, +0 );if (IS_ERR (nfsd_file_fsnotify_group)) {pr_err ("nfsd: unable to create fsnotify group: %ld\n" ,PTR_ERR (nfsd_file_fsnotify_group));
fs/notify/dnotify/dnotify.c +1 -1
@@ -383,7 +383,7 @@ static int __init dnotify_init(void) SLAB_PANIC|SLAB_ACCOUNT); dnotify_mark_cache =KMEM_CACHE (dnotify_mark,SLAB_PANIC |SLAB_ACCOUNT ); - dnotify_group =fsnotify_alloc_group (&dnotify_fsnotify_ops); + dnotify_group =fsnotify_alloc_group (&dnotify_fsnotify_ops,0 );if (IS_ERR (dnotify_group))panic ("unable to allocate fsnotify group for dnotify\n" );return 0 ;
fs/notify/fanotify/fanotify_user.c +2 -1
@@ -1351,7 +1351,8 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) f_flags |=O_NONBLOCK ;/* fsnotify_alloc_group takes a ref. Dropped in fanotify_release */ - group =fsnotify_alloc_user_group (&fanotify_fsnotify_ops); + group =fsnotify_alloc_group (&fanotify_fsnotify_ops, +FSNOTIFY_GROUP_USER );if (IS_ERR (group)) {return PTR_ERR (group); }
fs/notify/group.c +9 -12
@@ -112,7 +112,8 @@ void fsnotify_put_group(struct fsnotify_group *group)EXPORT_SYMBOL_GPL (fsnotify_put_group);static struct fsnotify_group *__fsnotify_alloc_group ( -const struct fsnotify_ops *ops,gfp_t gfp) +const struct fsnotify_ops *ops, +int flags,gfp_t gfp) {struct fsnotify_group *group;
@@ -133,6 +134,7 @@ static struct fsnotify_group *__fsnotify_alloc_group(INIT_LIST_HEAD (&group->marks_list); group->ops = ops; + group->flags = flags;return group; }
@@ -140,20 +142,15 @@ static struct fsnotify_group *__fsnotify_alloc_group(/* * Create a new fsnotify_group and hold a reference for the group returned. */ -struct fsnotify_group *fsnotify_alloc_group (const struct fsnotify_ops *ops) +struct fsnotify_group *fsnotify_alloc_group (const struct fsnotify_ops *ops, +int flags) { -return __fsnotify_alloc_group (ops,GFP_KERNEL ); -} -EXPORT_SYMBOL_GPL (fsnotify_alloc_group); +gfp_t gfp = (flags &FSNOTIFY_GROUP_USER ) ?GFP_KERNEL_ACCOUNT : +GFP_KERNEL ; -/* -* Create a new fsnotify_group and hold a reference for the group returned. -*/ -struct fsnotify_group *fsnotify_alloc_user_group (const struct fsnotify_ops *ops) -{ -return __fsnotify_alloc_group (ops,GFP_KERNEL_ACCOUNT ); +return __fsnotify_alloc_group (ops, flags, gfp); } -EXPORT_SYMBOL_GPL (fsnotify_alloc_user_group); +EXPORT_SYMBOL_GPL (fsnotify_alloc_group);int fsnotify_fasync (int fd,struct file *file,int on) {
fs/notify/inotify/inotify_user.c +2 -1
@@ -648,7 +648,8 @@ static struct fsnotify_group *inotify_new_group(unsigned int max_events)struct fsnotify_group *group;struct inotify_event_info *oevent; - group =fsnotify_alloc_user_group (&inotify_fsnotify_ops); + group =fsnotify_alloc_group (&inotify_fsnotify_ops, +FSNOTIFY_GROUP_USER );if (IS_ERR (group))return group;
include/linux/fsnotify_backend.h +6 -2
@@ -210,6 +210,9 @@ struct fsnotify_group {unsigned int priority;bool shutdown;/* group is being shut down, don't queue more events */ +#define FSNOTIFY_GROUP_USER 0x01/* user allocated group */ +int flags; +/* stores all fastpath marks assoc with this group so they can be cleaned on unregister */ struct mutex mark_mutex;/* protect marks_list */ atomic_t user_waits;/* Number of tasks waiting for user
@@ -543,8 +546,9 @@ static inline void fsnotify_update_flags(struct dentry *dentry)/* called from fsnotify listeners, such as fanotify or dnotify */ /* create a new group */ -extern struct fsnotify_group *fsnotify_alloc_group (const struct fsnotify_ops *ops); -extern struct fsnotify_group *fsnotify_alloc_user_group (const struct fsnotify_ops *ops); +extern struct fsnotify_group *fsnotify_alloc_group ( +const struct fsnotify_ops *ops, +int flags);/* get reference to a group */ extern void fsnotify_get_group (struct fsnotify_group *group);/* drop reference on a group from fsnotify_alloc_group */
kernel/audit_fsnotify.c +2 -1
@@ -182,7 +182,8 @@ static const struct fsnotify_ops audit_mark_fsnotify_ops = {static int __init audit_fsnotify_init (void ) { - audit_fsnotify_group =fsnotify_alloc_group (&audit_mark_fsnotify_ops); + audit_fsnotify_group =fsnotify_alloc_group (&audit_mark_fsnotify_ops, +0 );if (IS_ERR (audit_fsnotify_group)) { audit_fsnotify_group =NULL ;audit_panic ("cannot create audit fsnotify group" );
kernel/audit_tree.c +1 -1
@@ -1073,7 +1073,7 @@ static int __init audit_tree_init(void) audit_tree_mark_cachep =KMEM_CACHE (audit_tree_mark,SLAB_PANIC ); - audit_tree_group =fsnotify_alloc_group (&audit_tree_ops); + audit_tree_group =fsnotify_alloc_group (&audit_tree_ops,0 );if (IS_ERR (audit_tree_group))audit_panic ("cannot initialize fsnotify group for rectree watches" );
kernel/audit_watch.c +1 -1
@@ -492,7 +492,7 @@ static const struct fsnotify_ops audit_watch_fsnotify_ops = {static int __init audit_watch_init (void ) { - audit_watch_group =fsnotify_alloc_group (&audit_watch_fsnotify_ops); + audit_watch_group =fsnotify_alloc_group (&audit_watch_fsnotify_ops,0 );if (IS_ERR (audit_watch_group)) { audit_watch_group =NULL ;audit_panic ("cannot create audit fsnotify group" );
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 292/690 fsnotify: make allow_dups a property of the group
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit f3010343d9e119da35ee864b3a28993bb5c78ed7 ]
Instead of passing the allow_dups argument to fsnotify_add_mark() as an argument, define the group flag FSNOTIFY_GROUP_DUPS to express the allow_dups behavior and set this behavior at group creation time for all calls of fsnotify_add_mark().
Rename the allow_dups argument to generic add_flags argument for future use.
--- fs/notify/mark.c | 12 ++++++------ include/linux/fsnotify_backend.h | 13 +++++++------ kernel/audit_fsnotify.c | 4 ++-- 3 files changed, 15 insertions(+), 14 deletions(-)
fs/notify/mark.c +6 -6
@@ -574,7 +574,7 @@ static struct fsnotify_mark_connector *fsnotify_grab_connector(static int fsnotify_add_mark_list (struct fsnotify_mark *mark,fsnotify_connp_t *connp,unsigned int obj_type, -int allow_dups,__kernel_fsid_t *fsid) +int add_flags,__kernel_fsid_t *fsid) {struct fsnotify_mark *lmark, *last =NULL ;struct fsnotify_mark_connector *conn;
@@ -633,7 +633,7 @@ static int fsnotify_add_mark_list(struct fsnotify_mark *mark,if ((lmark->group == mark->group) && (lmark->flags &FSNOTIFY_MARK_FLAG_ATTACHED ) && - !allow_dups) { + !(mark->group->flags &FSNOTIFY_GROUP_DUPS )) { err = -EEXIST ; goto out_err; }
@@ -668,7 +668,7 @@ static int fsnotify_add_mark_list(struct fsnotify_mark *mark,*/ int fsnotify_add_mark_locked (struct fsnotify_mark *mark,fsnotify_connp_t *connp,unsigned int obj_type, -int allow_dups,__kernel_fsid_t *fsid) +int add_flags,__kernel_fsid_t *fsid) {struct fsnotify_group *group = mark->group;int ret =0 ;
@@ -688,7 +688,7 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark,fsnotify_get_mark (mark);/* for g_list */ spin_unlock (&mark->lock); - ret =fsnotify_add_mark_list (mark, connp, obj_type, allow_dups, fsid); + ret =fsnotify_add_mark_list (mark, connp, obj_type, add_flags, fsid);if (ret) goto err;
@@ -708,14 +708,14 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark, }int fsnotify_add_mark (struct fsnotify_mark *mark,fsnotify_connp_t *connp, -unsigned int obj_type,int allow_dups, +unsigned int obj_type,int add_flags,__kernel_fsid_t *fsid) {int ret;struct fsnotify_group *group = mark->group;mutex_lock (&group->mark_mutex); - ret =fsnotify_add_mark_locked (mark, connp, obj_type, allow_dups, fsid); + ret =fsnotify_add_mark_locked (mark, connp, obj_type, add_flags, fsid);mutex_unlock (&group->mark_mutex);return ret; }
include/linux/fsnotify_backend.h +7 -6
@@ -211,6 +211,7 @@ struct fsnotify_group {bool shutdown;/* group is being shut down, don't queue more events */ #define FSNOTIFY_GROUP_USER 0x01/* user allocated group */ +#define FSNOTIFY_GROUP_DUPS 0x02/* allow multiple marks per object */ int flags;/* stores all fastpath marks assoc with this group so they can be cleaned on unregister */
@@ -641,26 +642,26 @@ extern int fsnotify_get_conn_fsid(const struct fsnotify_mark_connector *conn,/* attach the mark to the object */ extern int fsnotify_add_mark (struct fsnotify_mark *mark,fsnotify_connp_t *connp,unsigned int obj_type, -int allow_dups,__kernel_fsid_t *fsid); +int add_flags,__kernel_fsid_t *fsid);extern int fsnotify_add_mark_locked (struct fsnotify_mark *mark,fsnotify_connp_t *connp, -unsigned int obj_type,int allow_dups, +unsigned int obj_type,int add_flags,__kernel_fsid_t *fsid);/* attach the mark to the inode */ static inline int fsnotify_add_inode_mark (struct fsnotify_mark *mark,struct inode *inode, -int allow_dups) +int add_flags) {return fsnotify_add_mark (mark, &inode->i_fsnotify_marks, -FSNOTIFY_OBJ_TYPE_INODE , allow_dups,NULL ); +FSNOTIFY_OBJ_TYPE_INODE , add_flags,NULL ); }static inline int fsnotify_add_inode_mark_locked (struct fsnotify_mark *mark,struct inode *inode, -int allow_dups) +int add_flags) {return fsnotify_add_mark_locked (mark, &inode->i_fsnotify_marks, -FSNOTIFY_OBJ_TYPE_INODE , allow_dups, +FSNOTIFY_OBJ_TYPE_INODE , add_flags,NULL ); }
kernel/audit_fsnotify.c +2 -2
@@ -100,7 +100,7 @@ struct audit_fsnotify_mark *audit_alloc_mark(struct audit_krule *krule, char *paaudit_update_mark (audit_mark, dentry->d_inode); audit_mark->rule = krule; - ret =fsnotify_add_inode_mark (&audit_mark->mark, inode, true); + ret =fsnotify_add_inode_mark (&audit_mark->mark, inode,0 );if (ret <0 ) { audit_mark->path =NULL ;fsnotify_put_mark (&audit_mark->mark);
@@ -183,7 +183,7 @@ static const struct fsnotify_ops audit_mark_fsnotify_ops = {static int __init audit_fsnotify_init (void ) { audit_fsnotify_group =fsnotify_alloc_group (&audit_mark_fsnotify_ops, -0 ); +FSNOTIFY_GROUP_DUPS );if (IS_ERR (audit_fsnotify_group)) { audit_fsnotify_group =NULL ;audit_panic ("cannot create audit fsnotify group" );
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 293/690 fsnotify: create helpers for group mark_mutex lock
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit 43b245a788e2d8f1bb742668a9bdace02fcb3e96 ]
Create helpers to take and release the group mark_mutex lock.
Define a flag FSNOTIFY_GROUP_NOFS in fsnotify_group that determines if the mark_mutex lock is fs reclaim safe or not. If not safe, the lock helpers take the lock and disable direct fs reclaim.
In that case we annotate the mutex with a different lockdep class to express to lockdep that an allocation of mark of an fs reclaim safe group may take the group lock of another "NOFS" group to evict inodes.
For now, converted only the callers in common code and no backend defines the NOFS flag. It is intended to be set by fanotify for evictable marks support.
--- fs/notify/fdinfo.c | 4 ++-- fs/notify/group.c | 11 +++++++++++ fs/notify/mark.c | 24 +++++++++++------------- include/linux/fsnotify_backend.h | 28 ++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 15 deletions(-)
fs/notify/fdinfo.c +2 -2
@@ -28,13 +28,13 @@ static void show_fdinfo(struct seq_file *m, struct file *f,struct fsnotify_group *group = f->private_data;struct fsnotify_mark *mark; -mutex_lock (&group->mark_mutex); +fsnotify_group_lock (group);list_for_each_entry (mark, &group->marks_list, g_list) {show (m, mark);if (seq_has_overflowed (m))break ; } -mutex_unlock (&group->mark_mutex); +fsnotify_group_unlock (group); }#if defined(CONFIG_EXPORTFS )
fs/notify/group.c +11 -0
@@ -115,6 +115,7 @@ static struct fsnotify_group *__fsnotify_alloc_group(const struct fsnotify_ops *ops, int flags, gfp_t gfp) { + static struct lock_class_key nofs_marks_lock;struct fsnotify_group *group; group =kzalloc (sizeof (struct fsnotify_group ), gfp);
@@ -135,6 +136,16 @@ static struct fsnotify_group *__fsnotify_alloc_group( group->ops = ops; group->flags = flags; +/* +* For most backends, eviction of inode with a mark is not expected, +* because marks hold a refcount on the inode against eviction. +* +* Use a different lockdep class for groups that support evictable +* inode marks, because with evictable marks, mark_mutex is NOT +* fs-reclaim safe - the mutex is taken when evicting inodes. +*/ +if (flags &FSNOTIFY_GROUP_NOFS ) +lockdep_set_class (&group->mark_mutex, &nofs_marks_lock);return group; }
fs/notify/mark.c +11 -13
@@ -398,9 +398,7 @@ void fsnotify_finish_user_wait(struct fsnotify_iter_info *iter_info)*/ void fsnotify_detach_mark (struct fsnotify_mark *mark) { -struct fsnotify_group *group = mark->group; - -WARN_ON_ONCE (!mutex_is_locked (&group->mark_mutex)); +fsnotify_group_assert_locked (mark->group);WARN_ON_ONCE (!srcu_read_lock_held (&fsnotify_mark_srcu) &&refcount_read (&mark->refcnt) <1 + !!(mark->flags &FSNOTIFY_MARK_FLAG_ATTACHED ));
@@ -452,9 +450,9 @@ void fsnotify_free_mark(struct fsnotify_mark *mark)void fsnotify_destroy_mark (struct fsnotify_mark *mark,struct fsnotify_group *group) { -mutex_lock (&group->mark_mutex); +fsnotify_group_lock (group);fsnotify_detach_mark (mark); -mutex_unlock (&group->mark_mutex); +fsnotify_group_unlock (group);fsnotify_free_mark (mark); }EXPORT_SYMBOL_GPL (fsnotify_destroy_mark);
@@ -673,7 +671,7 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark,struct fsnotify_group *group = mark->group;int ret =0 ; -BUG_ON (!mutex_is_locked (&group->mark_mutex)); +fsnotify_group_assert_locked (group);/* * LOCKING ORDER!!!!
@@ -714,9 +712,9 @@ int fsnotify_add_mark(struct fsnotify_mark *mark, fsnotify_connp_t *connp,int ret;struct fsnotify_group *group = mark->group; -mutex_lock (&group->mark_mutex); +fsnotify_group_lock (group); ret =fsnotify_add_mark_locked (mark, connp, obj_type, add_flags, fsid); -mutex_unlock (&group->mark_mutex); +fsnotify_group_unlock (group);return ret; }EXPORT_SYMBOL_GPL (fsnotify_add_mark);
@@ -770,24 +768,24 @@ void fsnotify_clear_marks_by_group(struct fsnotify_group *group,* move marks to free to to_free list in one go and then free marks in * to_free list one by one. */ -mutex_lock (&group->mark_mutex); +fsnotify_group_lock (group);list_for_each_entry_safe (mark, lmark, &group->marks_list, g_list) {if (mark->connector->type == obj_type)list_move (&mark->g_list, &to_free); } -mutex_unlock (&group->mark_mutex); +fsnotify_group_unlock (group); clear:while (1 ) { -mutex_lock (&group->mark_mutex); +fsnotify_group_lock (group);if (list_empty (head)) { -mutex_unlock (&group->mark_mutex); +fsnotify_group_unlock (group);break ; } mark = list_first_entry(head, struct fsnotify_mark, g_list);fsnotify_get_mark (mark);fsnotify_detach_mark (mark); -mutex_unlock (&group->mark_mutex); +fsnotify_group_unlock (group);fsnotify_free_mark (mark);fsnotify_put_mark (mark); }
include/linux/fsnotify_backend.h +28 -0
@@ -20,6 +20,7 @@#include <linux/user_namespace.h> #include <linux/refcount.h> #include <linux/mempool.h> +#include <linux/sched/mm.h> /* * IN_* from inotfy.h lines up EXACTLY with FS_*, this is so we can easily
@@ -212,7 +213,9 @@ struct fsnotify_group {#define FSNOTIFY_GROUP_USER 0x01/* user allocated group */ #define FSNOTIFY_GROUP_DUPS 0x02/* allow multiple marks per object */ +#define FSNOTIFY_GROUP_NOFS 0x04/* group lock is not direct reclaim safe */ int flags; +unsigned int owner_flags;/* stored flags of mark_mutex owner */ /* stores all fastpath marks assoc with this group so they can be cleaned on unregister */ struct mutex mark_mutex;/* protect marks_list */
@@ -254,6 +257,31 @@ struct fsnotify_group { }; }; +/* +* These helpers are used to prevent deadlock when reclaiming inodes with +* evictable marks of the same group that is allocating a new mark. +*/ +static inline void fsnotify_group_lock (struct fsnotify_group *group) +{ +mutex_lock (&group->mark_mutex); +if (group->flags &FSNOTIFY_GROUP_NOFS ) + group->owner_flags =memalloc_nofs_save (); +} + +static inline void fsnotify_group_unlock (struct fsnotify_group *group) +{ +if (group->flags &FSNOTIFY_GROUP_NOFS ) +memalloc_nofs_restore (group->owner_flags); +mutex_unlock (&group->mark_mutex); +} + +static inline void fsnotify_group_assert_locked (struct fsnotify_group *group) +{ +WARN_ON_ONCE (!mutex_is_locked (&group->mark_mutex)); +if (group->flags &FSNOTIFY_GROUP_NOFS ) +WARN_ON_ONCE (!(current->flags &PF_MEMALLOC_NOFS )); +} +/* When calling fsnotify tell it if the data is a path or inode */ enum fsnotify_data_type {FSNOTIFY_EVENT_NONE ,
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 294/690 inotify: use fsnotify group lock helpers
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit 642054b87058019be36033f73c3e48ffff1915aa ]
inotify inode marks pin the inode so there is no need to set the FSNOTIFY_GROUP_NOFS flag.
--- fs/notify/inotify/inotify_user.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/notify/inotify/inotify_user.c +2 -2
@@ -632,13 +632,13 @@ static int inotify_update_watch(struct fsnotify_group *group, struct inode *inod {int ret =0 ; -mutex_lock (&group->mark_mutex); +fsnotify_group_lock (group);/* try to update and existing watch with the new arg */ ret =inotify_update_existing_watch (group, inode, arg);/* no mark present, try to add a new one */ if (ret == -ENOENT ) ret =inotify_new_watch (group, inode, arg); -mutex_unlock (&group->mark_mutex); +fsnotify_group_unlock (group);return ret; }
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 295/690 nfsd: use fsnotify group lock helpers
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit b8962a9d8cc2d8c93362e2f684091c79f702f6f3 ]
Before commit 9542e6a643fc6 ("nfsd: Containerise filecache laundrette") nfsd would close open files in direct reclaim context and that could cause a deadlock when fsnotify mark allocation went into direct reclaim and nfsd shrinker tried to free existing fsnotify marks.
To avoid issues like this in future code, set the FSNOTIFY_GROUP_NOFS flag on nfsd fsnotify group to prevent going into direct reclaim from fsnotify_add_inode_mark().
--- fs/nfsd/filecache.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
fs/nfsd/filecache.c +7 -6
@@ -118,14 +118,14 @@ nfsd_file_mark_find_or_create(struct nfsd_file *nf)struct inode *inode = nf->nf_inode; do { - mutex_lock(&nfsd_file_fsnotify_group->mark_mutex); + fsnotify_group_lock(nfsd_file_fsnotify_group); mark = fsnotify_find_mark(&inode->i_fsnotify_marks, - nfsd_file_fsnotify_group); + nfsd_file_fsnotify_group); if (mark) { nfm = nfsd_file_mark_get(container_of(mark, struct nfsd_file_mark, nfm_mark)); - mutex_unlock(&nfsd_file_fsnotify_group->mark_mutex); + fsnotify_group_unlock(nfsd_file_fsnotify_group); if (nfm) { fsnotify_put_mark(mark); break;
@@ -133,8 +133,9 @@ nfsd_file_mark_find_or_create(struct nfsd_file *nf)/* Avoid soft lockup race with nfsd_file_mark_put() */ fsnotify_destroy_mark (mark, nfsd_file_fsnotify_group);fsnotify_put_mark (mark); - }else -mutex_unlock (&nfsd_file_fsnotify_group->mark_mutex); + }else { +fsnotify_group_unlock (nfsd_file_fsnotify_group); + }/* allocate a new nfm */ new =kmem_cache_alloc (nfsd_file_mark_slab,GFP_KERNEL );
@@ -672,7 +673,7 @@ nfsd_file_cache_init(void) } nfsd_file_fsnotify_group =fsnotify_alloc_group (&nfsd_file_fsnotify_ops, -0 ); +FSNOTIFY_GROUP_NOFS );if (IS_ERR (nfsd_file_fsnotify_group)) {pr_err ("nfsd: unable to create fsnotify group: %ld\n" ,PTR_ERR (nfsd_file_fsnotify_group));
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 296/690 dnotify: use fsnotify group lock helpers
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit aabb45fdcb31f00f1e7cae2bce83e83474a87c03 ]
Before commit 9542e6a643fc6 ("nfsd: Containerise filecache laundrette") nfsd would close open files in direct reclaim context. There is no guarantee that others memory shrinkers don't do the same and no guarantee that future shrinkers won't do that.
For example, if overlayfs implements inode cache of fscache would keep open files to cached objects, inode shrinkers could end up closing open files to underlying fs.
Direct reclaim from dnotify mark allocation context may try to close open files that have dnotify marks of the same group and hit a deadlock on mark_mutex.
Set the FSNOTIFY_GROUP_NOFS flag to prevent going into direct reclaim from allocations under dnotify group lock and use the safe group lock helpers.
--- fs/notify/dnotify/dnotify.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
fs/notify/dnotify/dnotify.c +7 -6
@@ -150,7 +150,7 @@ void dnotify_flush(struct file *filp, fl_owner_t id)return ; dn_mark = container_of(fsn_mark, struct dnotify_mark, fsn_mark); -mutex_lock (&dnotify_group->mark_mutex); +fsnotify_group_lock (dnotify_group);spin_lock (&fsn_mark->lock); prev = &dn_mark->dn;
@@ -173,7 +173,7 @@ void dnotify_flush(struct file *filp, fl_owner_t id) free = true; } -mutex_unlock (&dnotify_group->mark_mutex); +fsnotify_group_unlock (dnotify_group);if (free)fsnotify_free_mark (fsn_mark);
@@ -306,7 +306,7 @@ int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg) new_dn_mark->dn =NULL ;/* this is needed to prevent the fcntl/close race described below */ -mutex_lock (&dnotify_group->mark_mutex); +fsnotify_group_lock (dnotify_group);/* add the new_fsn_mark or find an old one. */ fsn_mark =fsnotify_find_mark (&inode->i_fsnotify_marks, dnotify_group);
@@ -316,7 +316,7 @@ int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg) }else { error =fsnotify_add_inode_mark_locked (new_fsn_mark, inode,0 );if (error) { -mutex_unlock (&dnotify_group->mark_mutex); +fsnotify_group_unlock (dnotify_group); goto out_err; }spin_lock (&new_fsn_mark->lock);
@@ -365,7 +365,7 @@ int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg)if (destroy)fsnotify_detach_mark (fsn_mark); -mutex_unlock (&dnotify_group->mark_mutex); +fsnotify_group_unlock (dnotify_group);if (destroy)fsnotify_free_mark (fsn_mark);fsnotify_put_mark (fsn_mark);
@@ -383,7 +383,8 @@ static int __init dnotify_init(void) SLAB_PANIC|SLAB_ACCOUNT); dnotify_mark_cache =KMEM_CACHE (dnotify_mark,SLAB_PANIC |SLAB_ACCOUNT ); - dnotify_group =fsnotify_alloc_group (&dnotify_fsnotify_ops,0 ); + dnotify_group =fsnotify_alloc_group (&dnotify_fsnotify_ops, +FSNOTIFY_GROUP_NOFS );if (IS_ERR (dnotify_group))panic ("unable to allocate fsnotify group for dnotify\n" );return 0 ;
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 297/690 fsnotify: allow adding an inode mark without pinning inode
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit c3638b5b13740fa31762d414bbce8b7a694e582a ]
fsnotify_add_mark() and variants implicitly take a reference on inode when attaching a mark to an inode.
Make that behavior opt-out with the mark flag FSNOTIFY_MARK_FLAG_NO_IREF.
Instead of taking the inode reference when attaching connector to inode and dropping the inode reference when detaching connector from inode, take the inode reference on attach of the first mark that wants to hold an inode reference and drop the inode reference on detach of the last mark that wants to hold an inode reference.
Backends can "upgrade" an existing mark to take an inode reference, but cannot "downgrade" a mark with inode reference to release the refernce.
This leaves the choice to the backend whether or not to pin the inode when adding an inode mark.
This is intended to be used when adding a mark with ignored mask that is used for optimization in cases where group can afford getting unneeded events and reinstate the mark with ignored mask when inode is accessed again after being evicted.
--- fs/notify/mark.c | 76 +++++++++++++++++++++++--------- include/linux/fsnotify_backend.h | 2 + 2 files changed, 58 insertions(+), 20 deletions(-)
fs/notify/mark.c +56 -20
@@ -116,20 +116,64 @@ __u32 fsnotify_conn_mask(struct fsnotify_mark_connector *conn)return *fsnotify_conn_mask_p (conn); } -static void __fsnotify_recalc_mask (struct fsnotify_mark_connector *conn) +static void fsnotify_get_inode_ref (struct inode *inode) +{ +ihold (inode); +atomic_long_inc (&inode->i_sb->s_fsnotify_connectors); +} + +/* +* Grab or drop inode reference for the connector if needed. +* +* When it's time to drop the reference, we only clear the HAS_IREF flag and +* return the inode object. fsnotify_drop_object() will be resonsible for doing +* iput() outside of spinlocks. This happens when last mark that wanted iref is +* detached. +*/ +static struct inode *fsnotify_update_iref (struct fsnotify_mark_connector *conn, +bool want_iref) +{ +bool has_iref = conn->flags &FSNOTIFY_CONN_FLAG_HAS_IREF ; +struct inode *inode =NULL ; + +if (conn->type !=FSNOTIFY_OBJ_TYPE_INODE || + want_iref == has_iref) +return NULL ; + +if (want_iref) { +/* Pin inode if any mark wants inode refcount held */ +fsnotify_get_inode_ref (fsnotify_conn_inode (conn)); + conn->flags |=FSNOTIFY_CONN_FLAG_HAS_IREF ; + }else { +/* Unpin inode after detach of last mark that wanted iref */ + inode =fsnotify_conn_inode (conn); + conn->flags &= ~FSNOTIFY_CONN_FLAG_HAS_IREF ; + } + +return inode; +} + +static void *__fsnotify_recalc_mask (struct fsnotify_mark_connector *conn) {u32 new_mask =0 ; +bool want_iref = false;struct fsnotify_mark *mark;assert_spin_locked (&conn->lock);/* We can get detached connector here when inode is getting unlinked. */ if (!fsnotify_valid_obj_type (conn->type)) -return ; +return NULL ;hlist_for_each_entry (mark, &conn->list, obj_list) { -if (mark->flags &FSNOTIFY_MARK_FLAG_ATTACHED ) - new_mask |=fsnotify_calc_mask (mark); +if (!(mark->flags &FSNOTIFY_MARK_FLAG_ATTACHED )) +continue ; + new_mask |=fsnotify_calc_mask (mark); +if (conn->type ==FSNOTIFY_OBJ_TYPE_INODE && + !(mark->flags &FSNOTIFY_MARK_FLAG_NO_IREF )) + want_iref = true; } *fsnotify_conn_mask_p (conn) = new_mask; + +return fsnotify_update_iref (conn, want_iref); }/*
@@ -169,12 +213,6 @@ static void fsnotify_connector_destroy_workfn(struct work_struct *work) } } -static void fsnotify_get_inode_ref (struct inode *inode) -{ -ihold (inode); -atomic_long_inc (&inode->i_sb->s_fsnotify_connectors); -} -static void fsnotify_put_inode_ref (struct inode *inode) {struct super_block *sb = inode->i_sb;
@@ -213,6 +251,10 @@ static void *fsnotify_detach_connector_from_object(if (conn->type ==FSNOTIFY_OBJ_TYPE_INODE ) { inode =fsnotify_conn_inode (conn); inode->i_fsnotify_mask =0 ; + +/* Unpin inode when detaching from connector */ +if (!(conn->flags &FSNOTIFY_CONN_FLAG_HAS_IREF )) + inode =NULL ; }else if (conn->type ==FSNOTIFY_OBJ_TYPE_VFSMOUNT ) {fsnotify_conn_mount (conn)->mnt_fsnotify_mask =0 ; }else if (conn->type ==FSNOTIFY_OBJ_TYPE_SB ) {
@@ -274,7 +316,8 @@ void fsnotify_put_mark(struct fsnotify_mark *mark) objp =fsnotify_detach_connector_from_object (conn, &type); free_conn = true; }else { -__fsnotify_recalc_mask (conn); + objp =__fsnotify_recalc_mask (conn); + type = conn->type; }WRITE_ONCE (mark->connector,NULL );spin_unlock (&conn->lock);
@@ -497,7 +540,6 @@ static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp,unsigned int obj_type, __kernel_fsid_t *fsid) { - struct inode *inode = NULL; struct fsnotify_mark_connector *conn; conn =kmem_cache_alloc (fsnotify_mark_connector_cachep,GFP_KERNEL );
@@ -505,6 +547,7 @@ static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp,return -ENOMEM ;spin_lock_init (&conn->lock);INIT_HLIST_HEAD (&conn->list); + conn->flags =0 ; conn->type = obj_type; conn->obj = connp;/* Cache fsid of filesystem containing the object */
@@ -515,10 +558,6 @@ static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp, conn->fsid.val[0 ] = conn->fsid.val[1 ] =0 ; conn->flags =0 ; } -if (conn->type ==FSNOTIFY_OBJ_TYPE_INODE ) { - inode =fsnotify_conn_inode (conn); -fsnotify_get_inode_ref (inode); - }fsnotify_get_sb_connectors (conn);/*
@@ -527,8 +566,6 @@ static int fsnotify_attach_connector_to_object(fsnotify_connp_t *connp,*/ if (cmpxchg (connp,NULL , conn)) {/* Someone else created list structure for us */ -if (inode) -fsnotify_put_inode_ref (inode);fsnotify_put_sb_connectors (conn);kmem_cache_free (fsnotify_mark_connector_cachep, conn); }
@@ -690,8 +727,7 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark,if (ret) goto err; -if (mark->mask || mark->ignored_mask) -fsnotify_recalc_mask (mark->connector); +fsnotify_recalc_mask (mark->connector);return ret; err:
include/linux/fsnotify_backend.h +2 -0
@@ -456,6 +456,7 @@ struct fsnotify_mark_connector {spinlock_t lock;unsigned short type;/* Type of object [lock] */ #define FSNOTIFY_CONN_FLAG_HAS_FSID 0x01 +#define FSNOTIFY_CONN_FLAG_HAS_IREF 0x02unsigned short flags;/* flags [lock] */ __kernel_fsid_t fsid;/* fsid of filesystem containing object */ union {
@@ -510,6 +511,7 @@ struct fsnotify_mark {#define FSNOTIFY_MARK_FLAG_IN_ONESHOT 0x0020/* fanotify mark flags */ #define FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY 0x0100 +#define FSNOTIFY_MARK_FLAG_NO_IREF 0x0200unsigned int flags;/* flags [mark->lock] */ };
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 298/690 fanotify: create helper fanotify_mark_user_flags()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit 4adce25ccfff215939ee465b8c0aa70526d5c352 ]
To translate from fsnotify mark flags to user visible flags.
--- fs/notify/fanotify/fanotify.h | 10 ++++++++++ fs/notify/fdinfo.c | 6 ++---- 2 files changed, 12 insertions(+), 4 deletions(-)
fs/notify/fanotify/fanotify.h +10 -0
@@ -490,3 +490,13 @@ static inline unsigned int fanotify_event_hash_bucket( {return event->hash &FANOTIFY_HTABLE_MASK ; } + +static inline unsigned int fanotify_mark_user_flags (struct fsnotify_mark *mark) +{ +unsigned int mflags =0 ; + +if (mark->flags &FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY ) + mflags |=FAN_MARK_IGNORED_SURV_MODIFY ; + +return mflags; +}
fs/notify/fdinfo.c +2 -4
@@ -14,6 +14,7 @@#include <linux/exportfs.h> #include "inotify/inotify.h" +#include "fanotify/fanotify.h" #include "fdinfo.h" #include "fsnotify.h"
@@ -103,12 +104,9 @@ void inotify_show_fdinfo(struct seq_file *m, struct file *f)static void fanotify_fdinfo (struct seq_file *m,struct fsnotify_mark *mark) { -unsigned int mflags =0 ; +unsigned int mflags =fanotify_mark_user_flags (mark);struct inode *inode; -if (mark->flags &FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY ) - mflags |=FAN_MARK_IGNORED_SURV_MODIFY ; -if (mark->connector->type ==FSNOTIFY_OBJ_TYPE_INODE ) { inode =igrab (fsnotify_conn_inode (mark->connector));if (!inode)
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 299/690 fanotify: factor out helper fanotify_mark_update_flags()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit 8998d110835e3781ccd3f1ae061a590b4aaba911 ]
Handle FAN_MARK_IGNORED_SURV_MODIFY flag change in a helper that is called after updating the mark mask.
Replace the added and removed return values and help variables with bool recalc return values and help variable, which makes the code a bit easier to follow.
Rename flags argument to fan_flags to emphasize the difference from mark->flags.
--- fs/notify/fanotify/fanotify_user.c | 47 ++++++++++++++++-------------- 1 file changed, 25 insertions(+), 22 deletions(-)
fs/notify/fanotify/fanotify_user.c +25 -22
@@ -1077,42 +1077,45 @@ static int fanotify_remove_inode_mark(struct fsnotify_group *group, flags, umask); } -static void fanotify_mark_add_ignored_mask (struct fsnotify_mark *fsn_mark, -__u32 mask,unsigned int flags, -__u32 *removed) +static bool fanotify_mark_update_flags (struct fsnotify_mark *fsn_mark, +unsigned int fan_flags) { - fsn_mark->ignored_mask |= mask; +bool recalc = false;/* * Setting FAN_MARK_IGNORED_SURV_MODIFY for the first time may lead to * the removal of the FS_MODIFY bit in calculated mask if it was set * because of an ignored mask that is now going to survive FS_MODIFY. */ -if ((flags &FAN_MARK_IGNORED_SURV_MODIFY ) && +if ((fan_flags &FAN_MARK_IGNORED_MASK ) && + (fan_flags &FAN_MARK_IGNORED_SURV_MODIFY ) && !(fsn_mark->flags &FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY )) { fsn_mark->flags |=FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY ;if (!(fsn_mark->mask &FS_MODIFY )) - *removed =FS_MODIFY ; + recalc = true; } + +return recalc; } -static __u32 fanotify_mark_add_to_mask (struct fsnotify_mark *fsn_mark, -__u32 mask,unsigned int flags, -__u32 *removed) +static bool fanotify_mark_add_to_mask (struct fsnotify_mark *fsn_mark, +__u32 mask,unsigned int fan_flags) { -__u32 oldmask, newmask; +bool recalc;spin_lock (&fsn_mark->lock); - oldmask =fsnotify_calc_mask (fsn_mark); -if (!(flags &FAN_MARK_IGNORED_MASK )) { +if (!(fan_flags &FAN_MARK_IGNORED_MASK )) fsn_mark->mask |= mask; - }else { -fanotify_mark_add_ignored_mask (fsn_mark, mask, flags, removed); - } - newmask =fsnotify_calc_mask (fsn_mark); +else + fsn_mark->ignored_mask |= mask; + + recalc =fsnotify_calc_mask (fsn_mark) & + ~fsnotify_conn_mask (fsn_mark->connector); + + recalc |=fanotify_mark_update_flags (fsn_mark, fan_flags);spin_unlock (&fsn_mark->lock); -return newmask & ~oldmask; +return recalc; } static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group,
@@ -1166,11 +1169,11 @@ static int fanotify_group_init_error_pool(struct fsnotify_group *group)static int fanotify_add_mark (struct fsnotify_group *group,fsnotify_connp_t *connp,unsigned int obj_type, -__u32 mask,unsigned int flags, +__u32 mask,unsigned int fan_flags,__kernel_fsid_t *fsid) {struct fsnotify_mark *fsn_mark; -__u32 added, removed =0 ; +bool recalc;int ret =0 ;mutex_lock (&group->mark_mutex);
@@ -1187,14 +1190,14 @@ static int fanotify_add_mark(struct fsnotify_group *group,* Error events are pre-allocated per group, only if strictly * needed (i.e. FAN_FS_ERROR was requested). */ -if (!(flags &FAN_MARK_IGNORED_MASK ) && (mask &FAN_FS_ERROR )) { +if (!(fan_flags &FAN_MARK_IGNORED_MASK ) && (mask &FAN_FS_ERROR )) { ret =fanotify_group_init_error_pool (group);if (ret) goto out; } - added =fanotify_mark_add_to_mask (fsn_mark, mask, flags, &removed); -if (removed || (added & ~fsnotify_conn_mask (fsn_mark->connector))) + recalc =fanotify_mark_add_to_mask (fsn_mark, mask, fan_flags); +if (recalc)fsnotify_recalc_mask (fsn_mark->connector); out:
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 300/690 fanotify: implement "evictable" inode marks
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit 7d5e005d982527e4029b0139823d179986e34cdc ]
When an inode mark is created with flag FAN_MARK_EVICTABLE, it will not pin the marked inode to inode cache, so when inode is evicted from cache due to memory pressure, the mark will be lost.
When an inode mark with flag FAN_MARK_EVICATBLE is updated without using this flag, the marked inode is pinned to inode cache.
When an inode mark is updated with flag FAN_MARK_EVICTABLE but an existing mark already has the inode pinned, the mark update fails with error EEXIST.
Evictable inode marks can be used to setup inode marks with ignored mask to suppress events from uninteresting files or directories in a lazy manner, upon receiving the first event, without having to iterate all the uninteresting files or directories before hand.
The evictbale inode mark feature allows performing this lazy marks setup without exhausting the system memory with pinned inodes.
This change does not enable the feature yet.
--- fs/notify/fanotify/fanotify.h | 2 ++ fs/notify/fanotify/fanotify_user.c | 38 ++++++++++++++++++++++++++++-- include/uapi/linux/fanotify.h | 1 + 3 files changed, 39 insertions(+), 2 deletions(-)
fs/notify/fanotify/fanotify.h +2 -0
@@ -497,6 +497,8 @@ static inline unsigned int fanotify_mark_user_flags(struct fsnotify_mark *mark)if (mark->flags &FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY ) mflags |=FAN_MARK_IGNORED_SURV_MODIFY ; +if (mark->flags &FSNOTIFY_MARK_FLAG_NO_IREF ) + mflags |=FAN_MARK_EVICTABLE ;return mflags; }
fs/notify/fanotify/fanotify_user.c +36 -2
@@ -1080,6 +1080,7 @@ static int fanotify_remove_inode_mark(struct fsnotify_group *group,static bool fanotify_mark_update_flags (struct fsnotify_mark *fsn_mark,unsigned int fan_flags) { +bool want_iref = !(fan_flags &FAN_MARK_EVICTABLE );bool recalc = false;/*
@@ -1095,7 +1096,18 @@ static bool fanotify_mark_update_flags(struct fsnotify_mark *fsn_mark, recalc = true; } -return recalc; +if (fsn_mark->connector->type !=FSNOTIFY_OBJ_TYPE_INODE || + want_iref == !(fsn_mark->flags &FSNOTIFY_MARK_FLAG_NO_IREF )) +return recalc; + +/* +* NO_IREF may be removed from a mark, but not added. +* When removed, fsnotify_recalc_mask() will take the inode ref. +*/ +WARN_ON_ONCE (!want_iref); + fsn_mark->flags &= ~FSNOTIFY_MARK_FLAG_NO_IREF ; + +return true; } static bool fanotify_mark_add_to_mask(struct fsnotify_mark *fsn_mark,
@@ -1121,6 +1133,7 @@ static bool fanotify_mark_add_to_mask(struct fsnotify_mark *fsn_mark,static struct fsnotify_mark *fanotify_add_new_mark (struct fsnotify_group *group,fsnotify_connp_t *connp,unsigned int obj_type, +unsigned int fan_flags,__kernel_fsid_t *fsid) {struct ucounts *ucounts = group->fanotify_data.ucounts;
@@ -1143,6 +1156,9 @@ static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group, }fsnotify_init_mark (mark, group); +if (fan_flags &FAN_MARK_EVICTABLE ) + mark->flags |=FSNOTIFY_MARK_FLAG_NO_IREF ; + ret =fsnotify_add_mark_locked (mark, connp, obj_type,0 , fsid);if (ret) {fsnotify_put_mark (mark);
@@ -1179,13 +1195,23 @@ static int fanotify_add_mark(struct fsnotify_group *group,mutex_lock (&group->mark_mutex); fsn_mark =fsnotify_find_mark (connp, group);if (!fsn_mark) { - fsn_mark =fanotify_add_new_mark (group, connp, obj_type, fsid); + fsn_mark =fanotify_add_new_mark (group, connp, obj_type, + fan_flags, fsid);if (IS_ERR (fsn_mark)) {mutex_unlock (&group->mark_mutex);return PTR_ERR (fsn_mark); } } +/* +* Non evictable mark cannot be downgraded to evictable mark. +*/ +if (fan_flags &FAN_MARK_EVICTABLE && + !(fsn_mark->flags &FSNOTIFY_MARK_FLAG_NO_IREF )) { + ret = -EEXIST ; + goto out; + } +/* * Error events are pre-allocated per group, only if strictly * needed (i.e. FAN_FS_ERROR was requested).
@@ -1615,6 +1641,14 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, mark_type != FAN_MARK_FILESYSTEM) goto fput_and_out; +/* +* Evictable is only relevant for inode marks, because only inode object +* can be evicted on memory pressure. +*/ +if (flags &FAN_MARK_EVICTABLE && + mark_type !=FAN_MARK_INODE ) + goto fput_and_out; +/* * Events that do not carry enough information to report * event->fd require a group that supports reporting fid. Those
include/uapi/linux/fanotify.h +1 -0
@@ -82,6 +82,7 @@#define FAN_MARK_IGNORED_SURV_MODIFY 0x00000040#define FAN_MARK_FLUSH 0x00000080/* FAN_MARK_FILESYSTEM is 0x00000100 */ +#define FAN_MARK_EVICTABLE 0x00000200/* These are NOT bitwise flags. Both bits can be used togther. */ #define FAN_MARK_INODE 0x00000000
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 301/690 fanotify: use fsnotify group lock helpers
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit e79719a2ca5c61912c0493bc1367db52759cf6fd ]
Direct reclaim from fanotify mark allocation context may try to evict inodes with evictable marks of the same group and hit this deadlock:
[<0>] fsnotify_destroy_mark+0x1f/0x3a [<0>] fsnotify_destroy_marks+0x71/0xd9 [<0>] __destroy_inode+0x24/0x7e [<0>] destroy_inode+0x2c/0x67 [<0>] dispose_list+0x49/0x68 [<0>] prune_icache_sb+0x5b/0x79 [<0>] super_cache_scan+0x11c/0x16f [<0>] shrink_slab.constprop.0+0x23e/0x40f [<0>] shrink_node+0x218/0x3e7 [<0>] do_try_to_free_pages+0x12a/0x2d2 [<0>] try_to_free_pages+0x166/0x242 [<0>] __alloc_pages_slowpath.constprop.0+0x30c/0x903 [<0>] __alloc_pages+0xeb/0x1c7 [<0>] cache_grow_begin+0x6f/0x31e [<0>] fallback_alloc+0xe0/0x12d [<0>] ____cache_alloc_node+0x15a/0x17e [<0>] kmem_cache_alloc_trace+0xa1/0x143 [<0>] fanotify_add_mark+0xd5/0x2b2 [<0>] do_fanotify_mark+0x566/0x5eb [<0>] __x64_sys_fanotify_mark+0x21/0x24 [<0>] do_syscall_64+0x6d/0x80 [<0>] entry_SYSCALL_64_after_hwframe+0x44/0xae
Set the FSNOTIFY_GROUP_NOFS flag to prevent going into direct reclaim from allocations under fanotify group lock and use the safe group lock helpers.
--- fs/notify/fanotify/fanotify_user.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
fs/notify/fanotify/fanotify_user.c +7 -7
@@ -1031,10 +1031,10 @@ static int fanotify_remove_mark(struct fsnotify_group *group,__u32 removed;int destroy_mark; -mutex_lock (&group->mark_mutex); +fsnotify_group_lock (group); fsn_mark =fsnotify_find_mark (connp, group);if (!fsn_mark) { -mutex_unlock (&group->mark_mutex); +fsnotify_group_unlock (group);return -ENOENT ; }
@@ -1044,7 +1044,7 @@ static int fanotify_remove_mark(struct fsnotify_group *group,fsnotify_recalc_mask (fsn_mark->connector);if (destroy_mark)fsnotify_detach_mark (fsn_mark); -mutex_unlock (&group->mark_mutex); +fsnotify_group_unlock (group);if (destroy_mark)fsnotify_free_mark (fsn_mark);
@@ -1192,13 +1192,13 @@ static int fanotify_add_mark(struct fsnotify_group *group,bool recalc;int ret =0 ; -mutex_lock (&group->mark_mutex); +fsnotify_group_lock (group); fsn_mark =fsnotify_find_mark (connp, group);if (!fsn_mark) { fsn_mark =fanotify_add_new_mark (group, connp, obj_type, fan_flags, fsid);if (IS_ERR (fsn_mark)) { -mutex_unlock (&group->mark_mutex); +fsnotify_group_unlock (group);return PTR_ERR (fsn_mark); } }
@@ -1227,7 +1227,7 @@ static int fanotify_add_mark(struct fsnotify_group *group,fsnotify_recalc_mask (fsn_mark->connector); out: -mutex_unlock (&group->mark_mutex); +fsnotify_group_unlock (group);fsnotify_put_mark (fsn_mark);return ret;
@@ -1381,7 +1381,7 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)/* fsnotify_alloc_group takes a ref. Dropped in fanotify_release */ group =fsnotify_alloc_group (&fanotify_fsnotify_ops, -FSNOTIFY_GROUP_USER ); +FSNOTIFY_GROUP_USER |FSNOTIFY_GROUP_NOFS );if (IS_ERR (group)) {return PTR_ERR (group); }
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 302/690 fanotify: enable "evictable" inode marks
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit 5f9d3bd520261fd7a850818c71809fd580e0f30c ]
Now that the direct reclaim path is handled we can enable evictable inode marks.
--- fs/notify/fanotify/fanotify_user.c | 2 +- include/linux/fanotify.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
fs/notify/fanotify/fanotify_user.c +1 -1
@@ -1814,7 +1814,7 @@ static int __init fanotify_user_setup(void)BUILD_BUG_ON (FANOTIFY_INIT_FLAGS &FANOTIFY_INTERNAL_GROUP_FLAGS );BUILD_BUG_ON (HWEIGHT32 (FANOTIFY_INIT_FLAGS ) !=12 ); -BUILD_BUG_ON (HWEIGHT32 (FANOTIFY_MARK_FLAGS ) !=9 ); +BUILD_BUG_ON (HWEIGHT32 (FANOTIFY_MARK_FLAGS ) !=10 ); fanotify_mark_cache =KMEM_CACHE (fsnotify_mark,SLAB_PANIC |SLAB_ACCOUNT );
include/linux/fanotify.h +1 -0
@@ -68,6 +68,7 @@ extern struct ctl_table fanotify_table[]; /* for sysctl */FAN_MARK_ONLYDIR | \FAN_MARK_IGNORED_MASK | \FAN_MARK_IGNORED_SURV_MODIFY | \ +FAN_MARK_EVICTABLE | \ FAN_MARK_FLUSH)/*
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 303/690 fsnotify: introduce mark type iterator
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit 14362a2541797cf9df0e86fb12dcd7950baf566e ]
fsnotify_foreach_iter_mark_type() is used to reduce boilerplate code of iterating all marks of a specific group interested in an event by consulting the iterator report_mask.
Use an open coded version of that iterator in fsnotify_iter_next() that collects all marks of the current iteration group without consulting the iterator report_mask.
At the moment, the two iterator variants are the same, but this decoupling will allow us to exclude some of the group's marks from reporting the event, for example for event on child and inode marks on parent did not request to watch events on children.
--- fs/notify/fanotify/fanotify.c | 14 +++------ fs/notify/fsnotify.c | 53 ++++++++++++++++---------------- include/linux/fsnotify_backend.h | 31 ++++++++++++++----- 3 files changed, 54 insertions(+), 44 deletions(-)
fs/notify/fanotify/fanotify.c +4 -10
@@ -319,11 +319,7 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group,return 0 ; } -fsnotify_foreach_iter_type (type) { -if (!fsnotify_iter_should_report_type (iter_info, type)) -continue ; - mark = iter_info->marks[type]; - + fsnotify_foreach_iter_mark_type(iter_info, mark, type) {/* Apply ignore mask regardless of ISDIR and ON_CHILD flags */ marks_ignored_mask |= mark->ignored_mask;
@@ -849,16 +845,14 @@ static struct fanotify_event *fanotify_alloc_event(*/ static __kernel_fsid_t fanotify_get_fsid (struct fsnotify_iter_info *iter_info) { +struct fsnotify_mark *mark;int type;__kernel_fsid_t fsid = {}; -fsnotify_foreach_iter_type (type) { + fsnotify_foreach_iter_mark_type(iter_info, mark, type) {struct fsnotify_mark_connector *conn; -if (!fsnotify_iter_should_report_type (iter_info, type)) -continue ; - - conn =READ_ONCE (iter_info->marks[type]->connector); + conn =READ_ONCE (mark->connector);/* Mark is just getting destroyed or created? */ if (!conn)continue ;
fs/notify/fsnotify.c +26 -27
98 lines not on this page · raw message
include/linux/fsnotify_backend.h +24 -7
@@ -399,6 +399,7 @@ static inline bool fsnotify_valid_obj_type(unsigned int obj_type)struct fsnotify_iter_info {struct fsnotify_mark *marks[FSNOTIFY_ITER_TYPE_COUNT ]; +struct fsnotify_group *current_group;unsigned int report_mask;int srcu_idx; };
@@ -415,20 +416,31 @@ static inline void fsnotify_iter_set_report_type( iter_info->report_mask |= (1U << iter_type); } -static inline void fsnotify_iter_set_report_type_mark ( -struct fsnotify_iter_info *iter_info,int iter_type, -struct fsnotify_mark *mark) +static inline struct fsnotify_mark *fsnotify_iter_mark ( +struct fsnotify_iter_info *iter_info,int iter_type) { - iter_info->marks[iter_type] = mark; - iter_info->report_mask |= (1U << iter_type); +if (fsnotify_iter_should_report_type (iter_info, iter_type)) +return iter_info->marks[iter_type]; +return NULL ; +} + +static inline int fsnotify_iter_step (struct fsnotify_iter_info *iter,int type, +struct fsnotify_mark **markp) +{ +while (type <FSNOTIFY_ITER_TYPE_COUNT ) { + *markp =fsnotify_iter_mark (iter, type); +if (*markp) +break ; + type++; + } +return type; }#define FSNOTIFY_ITER_FUNCS (name,NAME ) \ static inline struct fsnotify_mark *fsnotify_iter_##name##_mark( \ struct fsnotify_iter_info *iter_info) \ { \ - return (iter_info->report_mask & (1U << FSNOTIFY_ITER_TYPE_##NAME)) ? \ - iter_info->marks[FSNOTIFY_ITER_TYPE_##NAME] : NULL; \ + return fsnotify_iter_mark(iter_info, FSNOTIFY_ITER_TYPE_##NAME); \ }FSNOTIFY_ITER_FUNCS (inode,INODE )
@@ -438,6 +450,11 @@ FSNOTIFY_ITER_FUNCS(sb, SB)#define fsnotify_foreach_iter_type (type) \ for (type = 0; type < FSNOTIFY_ITER_TYPE_COUNT; type++) +#define fsnotify_foreach_iter_mark_type (iter, mark, type) \ + for (type = 0; \ + type = fsnotify_iter_step(iter, type, &mark), \ + type < FSNOTIFY_ITER_TYPE_COUNT; \ + type++)/* * fsnotify_connp_t is what we embed in objects which connector can be attached
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 304/690 fsnotify: consistent behavior for parent not watching children
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit e730558adffb88a52e562db089e969ee9510184a ]
The logic for handling events on child in groups that have a mark on the parent inode, but without FS_EVENT_ON_CHILD flag in the mask is duplicated in several places and inconsistent.
Move the logic into the preparation of mark type iterator, so that the parent mark type will be excluded from all mark type iterations in that case.
This results in several subtle changes of behavior, hopefully all desired changes of behavior, for example:
- Group A has a mount mark with FS_MODIFY in mask
- Group A has a mark with ignore mask that does not survive FS_MODIFY and does not watch children on directory D.
- Group B has a mark with FS_MODIFY in mask that does watch children on directory D.
- FS_MODIFY event on file D/foo should not clear the ignore mask of group A, but before this change it does
And if group A ignore mask was set to survive FS_MODIFY:
- FS_MODIFY event on file D/foo should be reported to group A on account of the mount mark, but before this change it is wrongly ignored
--- fs/notify/fanotify/fanotify.c | 10 +--------- fs/notify/fsnotify.c | 34 +++++++++++++++++++--------------- 2 files changed, 20 insertions(+), 24 deletions(-)
fs/notify/fanotify/fanotify.c +1 -9
@@ -320,7 +320,7 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group, } fsnotify_foreach_iter_mark_type(iter_info, mark, type) { -/* Apply ignore mask regardless of ISDIR and ON_CHILD flags */ +/* Apply ignore mask regardless of mark's ISDIR flag */ marks_ignored_mask |= mark->ignored_mask;/*
@@ -330,14 +330,6 @@ static u32 fanotify_group_event_mask(struct fsnotify_group *group,if (event_mask &FS_ISDIR && !(mark->mask &FS_ISDIR ))continue ; -/* -* If the event is on a child and this mark is on a parent not -* watching children, don't send it! -*/ -if (type ==FSNOTIFY_ITER_TYPE_PARENT && - !(mark->mask &FS_EVENT_ON_CHILD )) -continue ; - marks_mask |= mark->mask;/* Record the mark types of this group that matched the event */
fs/notify/fsnotify.c +19 -15
@@ -290,22 +290,15 @@ static int fsnotify_handle_event(struct fsnotify_group *group, __u32 mask, }if (parent_mark) { -/* -* parent_mark indicates that the parent inode is watching -* children and interested in this event, which is an event -* possible on child. But is *this mark* watching children and -* interested in this event? -*/ -if (parent_mark->mask &FS_EVENT_ON_CHILD ) { - ret =fsnotify_handle_inode_event (group, parent_mark, mask, - data, data_type, dir, name,0 ); -if (ret) -return ret; - } -if (!inode_mark) -return 0 ; + ret =fsnotify_handle_inode_event (group, parent_mark, mask, + data, data_type, dir, name,0 ); +if (ret) +return ret; } +if (!inode_mark) +return 0 ; +if (mask &FS_EVENT_ON_CHILD ) {/* * Some events can be sent on both parent dir and child marks
@@ -422,8 +415,19 @@ static bool fsnotify_iter_select_report_types( iter_info->report_mask =0 ;fsnotify_foreach_iter_type (type) { mark = iter_info->marks[type]; -if (mark && mark->group == iter_info->current_group) +if (mark && mark->group == iter_info->current_group) { +/* +* FSNOTIFY_ITER_TYPE_PARENT indicates that this inode +* is watching children and interested in this event, +* which is an event possible on child. +* But is *this mark* watching children? +*/ +if (type ==FSNOTIFY_ITER_TYPE_PARENT && + !(mark->mask &FS_EVENT_ON_CHILD )) +continue ; +fsnotify_iter_set_report_type (iter_info, type); + } }return true;
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 305/690 fanotify: fix incorrect fmode_t casts
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vasily Averin <[email protected]>
[ Upstream commit dccd855771b37820b6d976a99729c88259549f85 ]
Fixes sparce warnings:fs/notify/fanotify/fanotify_user.c:267:63: sparse:
warning: restricted fmode_t degrades to integerfs/notify/fanotify/fanotify_user.c:1351:28: sparse:
warning: restricted fmode_t degrades to integer
FMODE_NONTIFY have bitwise fmode_t type and requires __force attribute for any casts.
--- fs/notify/fanotify/fanotify_user.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/notify/fanotify/fanotify_user.c +2 -2
@@ -260,7 +260,7 @@ static int create_fd(struct fsnotify_group *group, struct path *path,* originally opened O_WRONLY. */ new_file =dentry_open (path, - group->fanotify_data.f_flags |FMODE_NONOTIFY , + group->fanotify_data.f_flags | __FMODE_NONOTIFY,current_cred ());if (IS_ERR (new_file)) {/*
@@ -1373,7 +1373,7 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) (!(fid_mode & FAN_REPORT_NAME) || !(fid_mode & FAN_REPORT_FID)))return -EINVAL ; - f_flags =O_RDWR |FMODE_NONOTIFY ; + f_flags =O_RDWR | __FMODE_NONOTIFY;if (flags &FAN_CLOEXEC ) f_flags |=O_CLOEXEC ;if (flags &FAN_NONBLOCK )
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 306/690 NFSD: Clean up nfsd_splice_actor()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 91e23b1c39820bfed642119ff6b6ef9f43cf09ce ]
nfsd_splice_actor() checks that the page being spliced does not match the previous element in the svc_rqst::rq_pages array. We believe this is to prevent a double put_page() in cases where the READ payload is partially contained in the xdr_buf's head buffer.
However, the NFSD READ proc functions no longer place any part of the READ payload in the head buffer, in order to properly support NFS/RDMA READ with Write chunks. Therefore, simplify the logic in nfsd_splice_actor() to remove this unnecessary check.
--- fs/nfsd/vfs.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
fs/nfsd/vfs.c +2 -8
@@ -856,17 +856,11 @@ nfsd_splice_actor(struct pipe_inode_info *pipe, struct pipe_buffer *buf, struct splice_desc *sd) {struct svc_rqst *rqstp = sd->u.data; -struct page **pp = rqstp->rq_next_page; -struct page *page = buf->page; -if (rqstp->rq_res.page_len ==0 ) { -svc_rqst_replace_page (rqstp, page); +svc_rqst_replace_page (rqstp, buf->page); +if (rqstp->rq_res.page_len ==0 ) rqstp->rq_res.page_base = buf->offset; - }else if (page != pp[-1 ]) { -svc_rqst_replace_page (rqstp, page); - } rqstp->rq_res.page_len += sd->len; -return sd->len; }
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 307/690 NFSD: add courteous server support for thread with only delegation
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dai Ngo <[email protected]>
[ Upstream commit 66af25799940b26efd41ea6e648f75c41a48a2c2 ]
This patch provides courteous server support for delegation only. Only expired client with delegation but no conflict and no open or lock state is allowed to be in COURTESY state.
Delegation conflict with COURTESY/EXPIRABLE client is resolved by setting it to EXPIRABLE, queue work for the laundromat and return delay to the caller. Conflict is resolved when the laudromat runs and expires the EXIRABLE client while the NFS client retries the OPEN request. Local thread request that gets conflict is doing the retry in _break_lease.
Client in COURTESY or EXPIRABLE state is allowed to reconnect and continues to have access to its state. Access to the nfs4_client by the reconnecting thread and the laundromat is serialized via the client_lock.
--- fs/nfsd/nfs4state.c | 82 ++++++++++++++++++++++++++++++++++++--------- fs/nfsd/nfsd.h | 1 + fs/nfsd/state.h | 31 +++++++++++++++++ 3 files changed, 99 insertions(+), 15 deletions(-)
fs/nfsd/nfs4state.c +67 -15
@@ -125,6 +125,8 @@ static void free_session(struct nfsd4_session *);static const struct nfsd4_callback_ops nfsd4_cb_recall_ops;static const struct nfsd4_callback_ops nfsd4_cb_notify_lock_ops; +static struct workqueue_struct *laundry_wq; +static bool is_session_dead (struct nfsd4_session *ses) {return ses->se_flags &NFS4_SESSION_DEAD ;
@@ -152,6 +154,7 @@ static __be32 get_client_locked(struct nfs4_client *clp)if (is_client_expired (clp))return nfserr_expired;atomic_inc (&clp->cl_rpc_users); + clp->cl_state =NFSD4_ACTIVE ;return nfs_ok; }
@@ -172,6 +175,7 @@ renew_client_locked(struct nfs4_client *clp)list_move_tail (&clp->cl_lru, &nn->client_lru); clp->cl_time =ktime_get_boottime_seconds (); + clp->cl_state =NFSD4_ACTIVE ; }static void put_client_renew_locked (struct nfs4_client *clp)
@@ -1102,6 +1106,7 @@ alloc_init_deleg(struct nfs4_client *clp, struct nfs4_file *fp,get_clnt_odstate (odstate); dp->dl_type =NFS4_OPEN_DELEGATE_READ ; dp->dl_retries =1 ; + dp->dl_recalled = false;nfsd4_init_cb (&dp->dl_recall, dp->dl_stid.sc_client, &nfsd4_cb_recall_ops,NFSPROC4_CLNT_CB_RECALL );get_nfs4_file (fp);
@@ -2017,6 +2022,8 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)idr_init (&clp->cl_stateids);atomic_set (&clp->cl_rpc_users,0 ); clp->cl_cb_state =NFSD4_CB_UNKNOWN ; + clp->cl_state =NFSD4_ACTIVE ; +atomic_set (&clp->cl_delegs_in_recall,0 );INIT_LIST_HEAD (&clp->cl_idhash);INIT_LIST_HEAD (&clp->cl_openowners);INIT_LIST_HEAD (&clp->cl_delegations);
@@ -4711,9 +4718,18 @@ nfsd_break_deleg_cb(struct file_lock *fl)bool ret = false;struct nfs4_delegation *dp = (struct nfs4_delegation *)fl->fl_owner;struct nfs4_file *fp = dp->dl_stid.sc_file; +struct nfs4_client *clp = dp->dl_stid.sc_client; +struct nfsd_net *nn;trace_nfsd_cb_recall (&dp->dl_stid); + dp->dl_recalled = true; +atomic_inc (&clp->cl_delegs_in_recall); +if (try_to_expire_client (clp)) { + nn =net_generic (clp->net, nfsd_net_id); +mod_delayed_work (laundry_wq, &nn->laundromat_work,0 ); + } +/* * We don't want the locks code to timeout the lease for us; * we'll remove it ourself if a delegation isn't returned
@@ -4756,9 +4772,14 @@ static int nfsd_change_deleg_cb(struct file_lock *onlist, int arg, struct list_head *dispose) { - if (arg & F_UNLCK) + struct nfs4_delegation *dp = (struct nfs4_delegation *)onlist->fl_owner; +struct nfs4_client *clp = dp->dl_stid.sc_client; + +if (arg &F_UNLCK ) { +if (dp->dl_recalled) +atomic_dec (&clp->cl_delegs_in_recall);return lease_modify (onlist, arg, dispose); - else + }else return -EAGAIN ; }
@@ -5622,6 +5643,49 @@ static void nfsd4_ssc_expire_umount(struct nfsd_net *nn) }#endif +/* +* place holder for now, no check for lock blockers yet +*/ +static bool +nfs4_anylock_blockers (struct nfs4_client *clp) +{ +if (atomic_read (&clp->cl_delegs_in_recall) || +client_has_openowners (clp) || + !list_empty (&clp->async_copies)) +return true; +return false; +} + +static void +nfs4_get_client_reaplist (struct nfsd_net *nn,struct list_head *reaplist, +struct laundry_time *lt) +{ +struct list_head *pos, *next; +struct nfs4_client *clp; + +INIT_LIST_HEAD (reaplist); +spin_lock (&nn->client_lock); +list_for_each_safe (pos, next, &nn->client_lru) { + clp = list_entry(pos, struct nfs4_client, cl_lru); +if (clp->cl_state ==NFSD4_EXPIRABLE ) + goto exp_client; +if (!state_expired (lt, clp->cl_time)) +break ; +if (!atomic_read (&clp->cl_rpc_users)) + clp->cl_state =NFSD4_COURTESY ; +if (!client_has_state (clp) || +ktime_get_boottime_seconds () >= + (clp->cl_time +NFSD_COURTESY_CLIENT_TIMEOUT )) + goto exp_client; +if (nfs4_anylock_blockers (clp)) { +exp_client: +if (!mark_client_expired_locked (clp)) +list_add (&clp->cl_lru, reaplist); + } + } +spin_unlock (&nn->client_lock); +} +static time64_t nfs4_laundromat (struct nfsd_net *nn) {
@@ -5644,7 +5708,6 @@ nfs4_laundromat(struct nfsd_net *nn) goto out; }nfsd4_end_grace (nn); -INIT_LIST_HEAD (&reaplist);spin_lock (&nn->s2s_cp_lock);idr_for_each_entry (&nn->s2s_cp_stateids, cps_t, i) {
@@ -5654,17 +5717,7 @@ nfs4_laundromat(struct nfsd_net *nn)_free_cpntf_state_locked (nn, cps); }spin_unlock (&nn->s2s_cp_lock); - -spin_lock (&nn->client_lock); -list_for_each_safe (pos, next, &nn->client_lru) { - clp = list_entry(pos, struct nfs4_client, cl_lru); -if (!state_expired (<, clp->cl_time)) -break ; -if (mark_client_expired_locked (clp)) -continue ; -list_add (&clp->cl_lru, &reaplist); - } -spin_unlock (&nn->client_lock); +nfs4_get_client_reaplist (nn, &reaplist, <);list_for_each_safe (pos, next, &reaplist) { clp = list_entry(pos, struct nfs4_client, cl_lru);trace_nfsd_clid_purged (&clp->cl_clientid);
@@ -5739,7 +5792,6 @@ nfs4_laundromat(struct nfsd_net *nn)return max_t (time64_t, lt.new_timeo,NFSD_LAUNDROMAT_MINTIMEOUT ); } -static struct workqueue_struct *laundry_wq;static void laundromat_main (struct work_struct *); static void
fs/nfsd/nfsd.h +1 -0
@@ -336,6 +336,7 @@ void nfsd_lockd_shutdown(void);#define COMPOUND_ERR_SLACK_SPACE 16/* OP_SETATTR */ #define NFSD_LAUNDROMAT_MINTIMEOUT 1/* seconds */ +#define NFSD_COURTESY_CLIENT_TIMEOUT (24 * 60 * 60)/* seconds */ /* * The following attributes are currently not supported by the NFSv4 server:
fs/nfsd/state.h +31 -0
@@ -149,6 +149,7 @@ struct nfs4_delegation {/* For recall: */ int dl_retries;struct nfsd4_callback dl_recall; +bool dl_recalled; };#define cb_to_delegation (cb) \
@@ -282,6 +283,28 @@ struct nfsd4_sessionid {#define HEXDIR_LEN 33/* hex version of 16 byte md5 of cl_name plus '\0' */ +/* +* State Meaning Where set +* -------------------------------------------------------------------------- +* | NFSD4_ACTIVE | Confirmed, active | Default | +* |------------------- ----------------------------------------------------| +* | NFSD4_COURTESY | Courtesy state. | nfs4_get_client_reaplist | +* | | Lease/lock/share | | +* | | reservation conflict | | +* | | can cause Courtesy | | +* | | client to be expired | | +* |------------------------------------------------------------------------| +* | NFSD4_EXPIRABLE | Courtesy client to be| nfs4_laundromat | +* | | expired by Laundromat| try_to_expire_client | +* | | due to conflict | | +* |------------------------------------------------------------------------| +*/ +enum { +NFSD4_ACTIVE =0 , +NFSD4_COURTESY , +NFSD4_EXPIRABLE , +}; +/* * struct nfs4_client - one per client. Clientids live here. *
@@ -385,6 +408,9 @@ struct nfs4_client {struct list_head async_copies;/* list of async copies */ spinlock_t async_lock;/* lock for async copies */ atomic_t cl_cb_inflight;/* Outstanding callbacks */ + +unsigned int cl_state; +atomic_t cl_delegs_in_recall; };/* struct nfs4_client_reset
@@ -702,4 +728,9 @@ extern void nfsd4_client_record_remove(struct nfs4_client *clp);extern int nfsd4_client_record_check (struct nfs4_client *clp);extern void nfsd4_record_grace_done (struct nfsd_net *nn); +static inline bool try_to_expire_client (struct nfs4_client *clp) +{ +cmpxchg (&clp->cl_state,NFSD4_COURTESY ,NFSD4_EXPIRABLE ); +return clp->cl_state ==NFSD4_EXPIRABLE ; +}#endif /* NFSD4_STATE_H */
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 308/690 NFSD: add support for share reservation conflict to courteous server
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dai Ngo <[email protected]>
[ Upstream commit 3d69427151806656abf129342028f3f4e5e1fee0 ]
This patch allows expired client with open state to be in COURTESY state. Share/access conflict with COURTESY client is resolved by setting COURTESY client to EXPIRABLE state, schedule laundromat to run and returning nfserr_jukebox to the request client.
--- fs/nfsd/nfs4state.c | 109 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 101 insertions(+), 8 deletions(-)
fs/nfsd/nfs4state.c +101 -8
@@ -705,6 +705,57 @@ static unsigned int file_hashval(struct svc_fh *fh)static struct hlist_head file_hashtbl[FILE_HASH_SIZE ]; +/* +* Check if courtesy clients have conflicting access and resolve it if possible +* +* access: is op_share_access if share_access is true. +* Check if access mode, op_share_access, would conflict with +* the current deny mode of the file 'fp'. +* access: is op_share_deny if share_access is false. +* Check if the deny mode, op_share_deny, would conflict with +* current access of the file 'fp'. +* stp: skip checking this entry. +* new_stp: normal open, not open upgrade. +* +* Function returns: +* false - access/deny mode conflict with normal client. +* true - no conflict or conflict with courtesy client(s) is resolved. +*/ +static bool +nfs4_resolve_deny_conflicts_locked (struct nfs4_file *fp,bool new_stp, +struct nfs4_ol_stateid *stp,u32 access,bool share_access) +{ +struct nfs4_ol_stateid *st; +bool resolvable = true; +unsigned char bmap; +struct nfsd_net *nn; +struct nfs4_client *clp; + +lockdep_assert_held (&fp->fi_lock); +list_for_each_entry (st, &fp->fi_stateids, st_perfile) { +/* ignore lock stateid */ +if (st->st_openstp) +continue ; +if (st == stp && new_stp) +continue ; +/* check file access against deny mode or vice versa */ + bmap = share_access ? st->st_deny_bmap : st->st_access_bmap; +if (!(access &bmap_to_share_mode (bmap))) +continue ; + clp = st->st_stid.sc_client; +if (try_to_expire_client (clp)) +continue ; + resolvable = false; +break ; + } +if (resolvable) { + clp = stp->st_stid.sc_client; + nn =net_generic (clp->net, nfsd_net_id); +mod_delayed_work (laundry_wq, &nn->laundromat_work,0 ); + } +return resolvable; +} +static void __nfs4_file_get_access (struct nfs4_file *fp,u32 access) {
@@ -4985,7 +5036,7 @@ nfsd4_truncate(struct svc_rqst *rqstp, struct svc_fh *fh,static __be32 nfs4_get_vfs_file (struct svc_rqst *rqstp,struct nfs4_file *fp,struct svc_fh *cur_fh,struct nfs4_ol_stateid *stp, -struct nfsd4_open *open) +struct nfsd4_open *open,bool new_stp) {struct nfsd_file *nf =NULL ;__be32 status;
@@ -5001,6 +5052,13 @@ static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp,*/ status =nfs4_file_check_deny (fp, open->op_share_deny);if (status != nfs_ok) { +if (status != nfserr_share_denied) { +spin_unlock (&fp->fi_lock); + goto out; + } +if (nfs4_resolve_deny_conflicts_locked (fp, new_stp, + stp, open->op_share_deny, false)) + status = nfserr_jukebox;spin_unlock (&fp->fi_lock); goto out; }
@@ -5008,6 +5066,13 @@ static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp,/* set access to the file */ status =nfs4_file_get_access (fp, open->op_share_access);if (status != nfs_ok) { +if (status != nfserr_share_denied) { +spin_unlock (&fp->fi_lock); + goto out; + } +if (nfs4_resolve_deny_conflicts_locked (fp, new_stp, + stp, open->op_share_access, true)) + status = nfserr_jukebox;spin_unlock (&fp->fi_lock); goto out; }
@@ -5054,21 +5119,29 @@ static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp, }static __be32 -nfs4_upgrade_open (struct svc_rqst *rqstp,struct nfs4_file *fp,struct svc_fh *cur_fh,struct nfs4_ol_stateid *stp,struct nfsd4_open *open) +nfs4_upgrade_open (struct svc_rqst *rqstp,struct nfs4_file *fp, +struct svc_fh *cur_fh,struct nfs4_ol_stateid *stp, +struct nfsd4_open *open) {__be32 status;unsigned char old_deny_bmap = stp->st_deny_bmap;if (!test_access (open->op_share_access, stp)) -return nfs4_get_vfs_file (rqstp, fp, cur_fh, stp, open); +return nfs4_get_vfs_file (rqstp, fp, cur_fh, stp, open, false);/* test and set deny mode */ spin_lock (&fp->fi_lock); status =nfs4_file_check_deny (fp, open->op_share_deny);if (status == nfs_ok) { -set_deny (open->op_share_deny, stp); - fp->fi_share_deny |= +if (status != nfserr_share_denied) { +set_deny (open->op_share_deny, stp); + fp->fi_share_deny |= (open->op_share_deny &NFS4_SHARE_DENY_BOTH ); + }else { +if (nfs4_resolve_deny_conflicts_locked (fp, false, + stp, open->op_share_deny, false)) + status = nfserr_jukebox; + } }spin_unlock (&fp->fi_lock);
@@ -5409,7 +5482,7 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf goto out; } }else { - status =nfs4_get_vfs_file (rqstp, fp, current_fh, stp, open); + status =nfs4_get_vfs_file (rqstp, fp, current_fh, stp, open, true);if (status) { stp->st_stid.sc_type =NFS4_CLOSED_STID ;release_open_stateid (stp);
@@ -5643,6 +5716,26 @@ static void nfsd4_ssc_expire_umount(struct nfsd_net *nn) }#endif +static bool +nfs4_has_any_locks (struct nfs4_client *clp) +{ +int i; +struct nfs4_stateowner *so; + +spin_lock (&clp->cl_lock); +for (i =0 ; i <OWNER_HASH_SIZE ; i++) { +list_for_each_entry (so, &clp->cl_ownerstr_hashtbl[i], + so_strhash) { +if (so->so_is_open_owner) +continue ; +spin_unlock (&clp->cl_lock); +return true; + } + } +spin_unlock (&clp->cl_lock); +return false; +} +/* * place holder for now, no check for lock blockers yet */
@@ -5650,8 +5743,8 @@ static bool nfs4_anylock_blockers(struct nfs4_client *clp) {if (atomic_read (&clp->cl_delegs_in_recall) || -client_has_openowners (clp) || - !list_empty (&clp->async_copies)) + !list_empty (&clp->async_copies) || +nfs4_has_any_locks (clp))return true;return false; }
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 309/690 NFSD: move create/destroy of laundry_wq to init_nfsd and exit_nfsd
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dai Ngo <[email protected]>
[ Upstream commit d76cc46b37e123e8d245cc3490978dbda56f979d ]
This patch moves create/destroy of laundry_wq from nfs4_state_start and nfs4_state_shutdown_net to init_nfsd and exit_nfsd to prevent the laundromat from being freed while a thread is processing a conflicting lock.
--- fs/nfsd/nfs4state.c | 28 ++++++++++++++++------------ fs/nfsd/nfsctl.c | 4 ++++ fs/nfsd/nfsd.h | 4 ++++ 3 files changed, 24 insertions(+), 12 deletions(-)
fs/nfsd/nfs4state.c +16 -12
@@ -127,6 +127,21 @@ static const struct nfsd4_callback_ops nfsd4_cb_notify_lock_ops;static struct workqueue_struct *laundry_wq; +int nfsd4_create_laundry_wq (void ) +{ +int rc =0 ; + + laundry_wq =alloc_workqueue ("%s" ,WQ_UNBOUND ,0 ,"nfsd4" ); +if (laundry_wq ==NULL ) + rc = -ENOMEM ; +return rc; +} + +void nfsd4_destroy_laundry_wq (void ) +{ +destroy_workqueue (laundry_wq); +} +static bool is_session_dead (struct nfsd4_session *ses) {return ses->se_flags &NFS4_SESSION_DEAD ;
@@ -7761,22 +7776,12 @@ nfs4_state_start(void) {int ret; - laundry_wq =alloc_workqueue ("%s" ,WQ_UNBOUND ,0 ,"nfsd4" ); -if (laundry_wq ==NULL ) { - ret = -ENOMEM ; - goto out; - } ret =nfsd4_create_callback_queue ();if (ret) - goto out_free_laundry; +return ret;set_max_delegations ();return 0 ; - -out_free_laundry: -destroy_workqueue (laundry_wq); -out: -return ret; }void
@@ -7813,7 +7818,6 @@ nfs4_state_shutdown_net(struct net *net)void nfs4_state_shutdown (void ) { -destroy_workqueue (laundry_wq);nfsd4_destroy_callback_queue (); }
fs/nfsd/nfsctl.c +4 -0
@@ -1542,6 +1542,9 @@ static int __init init_nfsd(void)if (retval <0 ) goto out_free_filesystem; retval =register_cld_notifier (); +if (retval) + goto out_free_all; + retval =nfsd4_create_laundry_wq ();if (retval) goto out_free_all;return 0 ;
@@ -1566,6 +1569,7 @@ static int __init init_nfsd(void) static void __exit exit_nfsd(void) { +nfsd4_destroy_laundry_wq ();unregister_cld_notifier ();unregister_pernet_subsys (&nfsd_net_ops);nfsd_drc_slab_free ();
fs/nfsd/nfsd.h +4 -0
@@ -162,6 +162,8 @@ void nfs4_state_shutdown_net(struct net *net);int nfs4_reset_recoverydir (char *recdir);char *nfs4_recoverydir (void );bool nfsd4_spo_must_allow (struct svc_rqst *rqstp); +int nfsd4_create_laundry_wq (void ); +void nfsd4_destroy_laundry_wq (void );#else static inline int nfsd4_init_slabs (void ) {return 0 ; }static inline void nfsd4_free_slabs (void ) { }
@@ -175,6 +177,8 @@ static inline bool nfsd4_spo_must_allow(struct svc_rqst *rqstp) {return false; } +static inline int nfsd4_create_laundry_wq (void ) {return 0 ; }; +static inline void nfsd4_destroy_laundry_wq (void ) {};#endif /*
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 310/690 fs/lock: add helper locks_owner_has_blockers to check for blockers
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dai Ngo <[email protected]>
[ Upstream commit 591502c5cb325b1c6ec59ab161927d606b918aa0 ]
Add helper locks_owner_has_blockers to check if there is any blockers for a given lockowner.
--- fs/locks.c | 28 ++++++++++++++++++++++++++++ include/linux/fs.h | 7 +++++++ 2 files changed, 35 insertions(+)
fs/locks.c +28 -0
@@ -376,6 +376,34 @@ void locks_release_private(struct file_lock *fl) }EXPORT_SYMBOL_GPL (locks_release_private); +/** +* locks_owner_has_blockers - Check for blocking lock requests +* @flctx: file lock context +* @owner: lock owner +* +* Return values: +* %true: @owner has at least one blocker +* %false: @owner has no blockers +*/ +bool locks_owner_has_blockers (struct file_lock_context *flctx, +fl_owner_t owner) +{ +struct file_lock *fl; + +spin_lock (&flctx->flc_lock); +list_for_each_entry (fl, &flctx->flc_posix, fl_list) { +if (fl->fl_owner != owner) +continue ; +if (!list_empty (&fl->fl_blocked_requests)) { +spin_unlock (&flctx->flc_lock); +return true; + } + } +spin_unlock (&flctx->flc_lock); +return false; +} +EXPORT_SYMBOL_GPL (locks_owner_has_blockers); +/* Free a lock which is not in use. */ void locks_free_lock (struct file_lock *fl) {
include/linux/fs.h +7 -0
@@ -1212,6 +1212,8 @@ extern void lease_unregister_notifier(struct notifier_block *);struct files_struct ;extern void show_fd_locks (struct seq_file *f,struct file *filp,struct files_struct *files); +extern bool locks_owner_has_blockers (struct file_lock_context *flctx, +fl_owner_t owner);#else /* !CONFIG_FILE_LOCKING */ static inline int fcntl_getlk (struct file *file,unsigned int cmd,struct flock __user *user)
@@ -1352,6 +1354,11 @@ static inline int lease_modify(struct file_lock *fl, int arg,struct files_struct ;static inline void show_fd_locks (struct seq_file *f,struct file *filp,struct files_struct *files) {} +static inline bool locks_owner_has_blockers (struct file_lock_context *flctx, +fl_owner_t owner) +{ +return false; +}#endif /* !CONFIG_FILE_LOCKING */ static inline struct inode *file_inode (const struct file *f)
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 311/690 fs/lock: add 2 callbacks to lock_manager_operations to resolve conflict
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dai Ngo <[email protected]>
[ Upstream commit 2443da2259e97688f93d64d17ab69b15f466078a ]
Add 2 new callbacks, lm_lock_expirable and lm_expire_lock, to lock_manager_operations to allow the lock manager to take appropriate action to resolve the lock conflict if possible.
A new field, lm_mod_owner, is also added to lock_manager_operations. The lm_mod_owner is used by the fs/lock code to make sure the lock manager module such as nfsd, is not freed while lock conflict is being resolved.
lm_lock_expirable checks and returns true to indicate that the lock conflict can be resolved else return false. This callback must be called with the flc_lock held so it can not block.
lm_expire_lock is called to resolve the lock conflict if the returned value from lm_lock_expirable is true. This callback is called without the flc_lock held since it's allowed to block. Upon returning from this callback, the lock conflict should be resolved and the caller is expected to restart the conflict check from the beginnning of the list.
Lock manager, such as NFSv4 courteous server, uses this callback to resolve conflict by destroying lock owner, or the NFSv4 courtesy client (client that has expired but allowed to maintains its states) that owns the lock.
--- Documentation/filesystems/locking.rst | 4 ++++ fs/locks.c | 33 ++++++++++++++++++++++++--- include/linux/fs.h | 3 +++ 3 files changed, 37 insertions(+), 3 deletions(-)
Documentation/filesystems/locking.rst +4 -0
@@ -442,6 +442,8 @@ prototypes:: void (*lm_break)(struct file_lock *); /* break_lease callback */ int (*lm_change)(struct file_lock **, int); bool (*lm_breaker_owns_lease)(struct file_lock *); + bool (*lm_lock_expirable)(struct file_lock *); + void (*lm_expire_lock)(void); locking rules:
@@ -453,6 +455,8 @@ lm_grant: no no no lm_break: yes no no lm_change yes no no lm_breaker_owns_lease: yes no no +lm_lock_expirable yes no no +lm_expire_lock no no yes ====================== ============= ================= ========= buffer_head
fs/locks.c +30 -3
@@ -982,6 +982,8 @@ posix_test_lock(struct file *filp, struct file_lock *fl)struct file_lock *cfl;struct file_lock_context *ctx;struct inode *inode =locks_inode (filp); +void *owner; +void (*func)(void ); ctx =smp_load_acquire (&inode->i_flctx);if (!ctx ||list_empty_careful (&ctx->flc_posix)) {
@@ -989,12 +991,23 @@ posix_test_lock(struct file *filp, struct file_lock *fl)return ; } +retry:spin_lock (&ctx->flc_lock);list_for_each_entry (cfl, &ctx->flc_posix, fl_list) { -if (posix_locks_conflict (fl, cfl)) { -locks_copy_conflock (fl, cfl); - goto out; +if (!posix_locks_conflict (fl, cfl)) +continue ; +if (cfl->fl_lmops && cfl->fl_lmops->lm_lock_expirable + && (*cfl->fl_lmops->lm_lock_expirable)(cfl)) { + owner = cfl->fl_lmops->lm_mod_owner; + func = cfl->fl_lmops->lm_expire_lock; +__module_get (owner); +spin_unlock (&ctx->flc_lock); + (*func)(); +module_put (owner); + goto retry; } +locks_copy_conflock (fl, cfl); + goto out; } fl->fl_type =F_UNLCK ; out:
@@ -1168,6 +1181,8 @@ static int posix_lock_inode(struct inode *inode, struct file_lock *request,int error;bool added = false;LIST_HEAD (dispose); +void *owner; +void (*func)(void ); ctx =locks_get_lock_context (inode, request->fl_type);if (!ctx)
@@ -1186,6 +1201,7 @@ static int posix_lock_inode(struct inode *inode, struct file_lock *request, new_fl2 =locks_alloc_lock (); } +retry:percpu_down_read (&file_rwsem);spin_lock (&ctx->flc_lock);/*
@@ -1197,6 +1213,17 @@ static int posix_lock_inode(struct inode *inode, struct file_lock *request,list_for_each_entry (fl, &ctx->flc_posix, fl_list) {if (!posix_locks_conflict (request, fl))continue ; +if (fl->fl_lmops && fl->fl_lmops->lm_lock_expirable + && (*fl->fl_lmops->lm_lock_expirable)(fl)) { + owner = fl->fl_lmops->lm_mod_owner; + func = fl->fl_lmops->lm_expire_lock; +__module_get (owner); +spin_unlock (&ctx->flc_lock); +percpu_up_read (&file_rwsem); + (*func)(); +module_put (owner); + goto retry; + }if (conflock)locks_copy_conflock (conflock, fl); error = -EAGAIN ;
include/linux/fs.h +3 -0
@@ -1066,6 +1066,7 @@ struct file_lock_operations { };struct lock_manager_operations { +void *lm_mod_owner;fl_owner_t (*lm_get_owner)(fl_owner_t );void (*lm_put_owner)(fl_owner_t );void (*lm_notify)(struct file_lock *);/* unblock callback */
@@ -1074,6 +1075,8 @@ struct lock_manager_operations {int (*lm_change)(struct file_lock *,int ,struct list_head *);void (*lm_setup)(struct file_lock *,void **);bool (*lm_breaker_owns_lease)(struct file_lock *); +bool (*lm_lock_expirable)(struct file_lock *cfl); +void (*lm_expire_lock)(void ); };struct lock_manager {
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 312/690 NFSD: add support for lock conflict to courteous server
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dai Ngo <[email protected]>
[ Upstream commit 27431affb0dbc259ac6ffe6071243a576c8f38f1 ]
This patch allows expired client with lock state to be in COURTESY state. Lock conflict with COURTESY client is resolved by the fs/lock code using the lm_lock_expirable and lm_expire_lock callback in the struct lock_manager_operations.
If conflict client is in COURTESY state, set it to EXPIRABLE and schedule the laundromat to run immediately to expire the client. The callback lm_expire_lock waits for the laundromat to flush its work queue before returning to caller.
--- fs/nfsd/nfs4state.c | 70 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 16 deletions(-)
fs/nfsd/nfs4state.c +54 -16
@@ -5731,39 +5731,51 @@ static void nfsd4_ssc_expire_umount(struct nfsd_net *nn) }#endif +/* Check if any lock belonging to this lockowner has any blockers */ static bool -nfs4_has_any_locks (struct nfs4_client *clp) +nfs4_lockowner_has_blockers (struct nfs4_lockowner *lo) +{ +struct file_lock_context *ctx; +struct nfs4_ol_stateid *stp; +struct nfs4_file *nf; + +list_for_each_entry (stp, &lo->lo_owner.so_stateids, st_perstateowner) { + nf = stp->st_stid.sc_file; + ctx = nf->fi_inode->i_flctx; +if (!ctx) +continue ; +if (locks_owner_has_blockers (ctx, lo)) +return true; + } +return false; +} + +static bool +nfs4_anylock_blockers (struct nfs4_client *clp) {int i;struct nfs4_stateowner *so; +struct nfs4_lockowner *lo; +if (atomic_read (&clp->cl_delegs_in_recall)) +return true;spin_lock (&clp->cl_lock);for (i =0 ; i <OWNER_HASH_SIZE ; i++) {list_for_each_entry (so, &clp->cl_ownerstr_hashtbl[i], so_strhash) {if (so->so_is_open_owner)continue ; -spin_unlock (&clp->cl_lock); -return true; + lo =lockowner (so); +if (nfs4_lockowner_has_blockers (lo)) { +spin_unlock (&clp->cl_lock); +return true; + } } }spin_unlock (&clp->cl_lock);return false; } -/* -* place holder for now, no check for lock blockers yet -*/ -static bool -nfs4_anylock_blockers (struct nfs4_client *clp) -{ -if (atomic_read (&clp->cl_delegs_in_recall) || - !list_empty (&clp->async_copies) || -nfs4_has_any_locks (clp)) -return true; -return false; -} -static void nfs4_get_client_reaplist (struct nfsd_net *nn,struct list_head *reaplist,struct laundry_time *lt)
@@ -6729,6 +6741,29 @@ nfsd4_lm_put_owner(fl_owner_t owner)nfs4_put_stateowner (&lo->lo_owner); } +/* return pointer to struct nfs4_client if client is expirable */ +static bool +nfsd4_lm_lock_expirable (struct file_lock *cfl) +{ +struct nfs4_lockowner *lo = (struct nfs4_lockowner *)cfl->fl_owner; +struct nfs4_client *clp = lo->lo_owner.so_client; +struct nfsd_net *nn; + +if (try_to_expire_client (clp)) { + nn =net_generic (clp->net, nfsd_net_id); +mod_delayed_work (laundry_wq, &nn->laundromat_work,0 ); +return true; + } +return false; +} + +/* schedule laundromat to run immediately and wait for it to complete */ +static void +nfsd4_lm_expire_lock (void ) +{ +flush_workqueue (laundry_wq); +} +static void nfsd4_lm_notify (struct file_lock *fl) {
@@ -6755,9 +6790,12 @@ nfsd4_lm_notify(struct file_lock *fl) }static const struct lock_manager_operations nfsd_posix_mng_ops = { + .lm_mod_owner =THIS_MODULE , .lm_notify = nfsd4_lm_notify, .lm_get_owner = nfsd4_lm_get_owner, .lm_put_owner = nfsd4_lm_put_owner, + .lm_lock_expirable = nfsd4_lm_lock_expirable, + .lm_expire_lock = nfsd4_lm_expire_lock, }; static inline void
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 313/690 NFSD: Show state of courtesy client in client info
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dai Ngo <[email protected]>
[ Upstream commit e9488d5ae13c0a72223c507e2508dc2ac66cad4f ]
Update client_info_show to show state of courtesy client and seconds since last renew.
--- fs/nfsd/nfs4state.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
fs/nfsd/nfs4state.c +8 -1
@@ -2494,10 +2494,17 @@ static int client_info_show(struct seq_file *m, void *v)memcpy (&clid, &clp->cl_clientid,sizeof (clid));seq_printf (m,"clientid: 0x%llx\n" , clid);seq_printf (m,"address: \"%pISpc\"\n" , (struct sockaddr *)&clp->cl_addr); -if (test_bit (NFSD4_CLIENT_CONFIRMED , &clp->cl_flags)) + +if (clp->cl_state ==NFSD4_COURTESY ) +seq_puts (m,"status: courtesy\n" ); +else if (clp->cl_state ==NFSD4_EXPIRABLE ) +seq_puts (m,"status: expirable\n" ); +else if (test_bit (NFSD4_CLIENT_CONFIRMED , &clp->cl_flags))seq_puts (m,"status: confirmed\n" );else seq_puts (m,"status: unconfirmed\n" ); +seq_printf (m,"seconds from last renew: %lld\n" , +ktime_get_boottime_seconds () - clp->cl_time);seq_printf (m,"name: " );seq_quote_mem (m, clp->cl_name.data, clp->cl_name.len);seq_printf (m,"\nminor version: %d\n" , clp->cl_minorversion);
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 314/690 NFSD: Clean up nfsd3_proc_create()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit e61568599c9ad638fdaba150fee07d7065e31851 ]
As near as I can tell, mode bit masking and setting S_IFREG is already done by do_nfsd_create() and vfs_create(). The NFSv4 path (do_open_lookup), for example, does not bother with this special processing.
--- fs/nfsd/nfs3proc.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-)
fs/nfsd/nfs3proc.c +2 -14
@@ -229,8 +229,7 @@ nfsd3_proc_create(struct svc_rqst *rqstp) {struct nfsd3_createargs *argp = rqstp->rq_argp;struct nfsd3_diropres *resp = rqstp->rq_resp; -svc_fh *dirfhp, *newfhp =NULL ; -struct iattr *attr; +svc_fh *dirfhp, *newfhp; dprintk("nfsd: CREATE(3) %s %.*s\n", SVCFH_fmt(&argp->fh),
@@ -239,20 +238,9 @@ nfsd3_proc_create(struct svc_rqst *rqstp) dirfhp =fh_copy (&resp->dirfh, &argp->fh); newfhp =fh_init (&resp->fh,NFS3_FHSIZE ); - attr = &argp->attrs; - -/* Unfudge the mode bits */ - attr->ia_mode &= ~S_IFMT ; -if (!(attr->ia_valid &ATTR_MODE )) { - attr->ia_valid |=ATTR_MODE ; - attr->ia_mode =S_IFREG ; - }else { - attr->ia_mode = (attr->ia_mode & ~S_IFMT ) |S_IFREG ; - } -/* Now create the file and set attributes */ resp->status =do_nfsd_create (rqstp, dirfhp, argp->name, argp->len, - attr, newfhp, argp->createmode, + &argp->attrs, newfhp, argp->createmode, (u32 *)argp->verf,NULL ,NULL );return rpc_success; }
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 315/690 NFSD: Avoid calling fh_drop_write() twice in do_nfsd_create()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 14ee45b70dd0d9ae76fb066cd8c0652d657353f6 ]
Clean up: The "out" label already invokes fh_drop_write().
Note that fh_drop_write() is already careful not to invoke mnt_drop_write() if either it has already been done or there is nothing to drop. Therefore no change in behavior is expected.
--- fs/nfsd/vfs.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
fs/nfsd/vfs.c +1 -4
@@ -1487,7 +1487,6 @@ do_nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,case NFS3_CREATE_GUARDED : err = nfserr_exist; } -fh_drop_write (fhp); goto out; }
@@ -1495,10 +1494,8 @@ do_nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp, iap->ia_mode &= ~current_umask (); host_err =vfs_create (&init_user_ns, dirp, dchild, iap->ia_mode, true); -if (host_err <0 ) { -fh_drop_write (fhp); +if (host_err <0 ) goto out_nfserr; - }if (created) *created = true;
Signature · 1 line
2.43.0
Greg Kroah-Hartman
maintainerPATCH 316/690 NFSD: Refactor nfsd_create_setattr()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 5f46e950c395b9c14c282b53ba78c5fd46d6c256 ]
I'd like to move do_nfsd_create() out of vfs.c. Therefore nfsd_create_setattr() needs to be made publicly visible.
Note that both call sites in vfs.c commit both the new object and its parent directory, so just combine those common metadata commits into nfsd_create_setattr().
--- fs/nfsd/vfs.c | 79 +++++++++++++++++++++++++++------------------------ fs/nfsd/vfs.h | 2 ++ 2 files changed, 44 insertions(+), 37 deletions(-)
fs/nfsd/vfs.c +42 -37
@@ -1189,14 +1189,26 @@ nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp, u64 offset,return err; } -static __be32 -nfsd_create_setattr (struct svc_rqst *rqstp,struct svc_fh *resfhp, -struct iattr *iap) +/** +* nfsd_create_setattr - Set a created file's attributes +* @rqstp: RPC transaction being executed +* @fhp: NFS filehandle of parent directory +* @resfhp: NFS filehandle of new object +* @iap: requested attributes of new object +* +* Returns nfs_ok on success, or an nfsstat in network byte order. +*/ +__be32 +nfsd_create_setattr (struct svc_rqst *rqstp,struct svc_fh *fhp, +struct svc_fh *resfhp,struct iattr *iap) { +__be32 status; +/* -* Mode has already been set earlier in create: +* Mode has already been set by file creation. */ iap->ia_valid &= ~ATTR_MODE ; +/* * Setting uid/gid works only for root. Irix appears to * send along the gid on create when it tries to implement
@@ -1204,10 +1216,31 @@ nfsd_create_setattr(struct svc_rqst *rqstp, struct svc_fh *resfhp,*/ if (!uid_eq (current_fsuid (),GLOBAL_ROOT_UID )) iap->ia_valid &= ~(ATTR_UID |ATTR_GID ); + +/* +* Callers expect new file metadata to be committed even +* if the attributes have not changed. +*/ if (iap->ia_valid) -return nfsd_setattr (rqstp, resfhp, iap,0 , (time64_t )0 ); -/* Callers expect file metadata to be committed here */ -return nfserrno (commit_metadata (resfhp)); + status =nfsd_setattr (rqstp, resfhp, iap,0 , (time64_t )0 ); +else + status =nfserrno (commit_metadata (resfhp)); + +/* +* Transactional filesystems had a chance to commit changes +* for both parent and child simultaneously making the +* following commit_metadata a noop in many cases. +*/ +if (!status) + status =nfserrno (commit_metadata (fhp)); + +/* +* Update the new filehandle to pick up the new attributes. +*/ +if (!status) + status =fh_update (resfhp); + +return status; }/* HPUX client sometimes creates a file in mode 000, and sets size to 0.
@@ -1234,7 +1267,6 @@ nfsd_create_locked(struct svc_rqst *rqstp, struct svc_fh *fhp,struct dentry *dentry, *dchild;struct inode *dirp;__be32 err; -__be32 err2;int host_err; dentry = fhp->fh_dentry;
@@ -1307,22 +1339,8 @@ nfsd_create_locked(struct svc_rqst *rqstp, struct svc_fh *fhp,if (host_err <0 ) goto out_nfserr; - err =nfsd_create_setattr (rqstp, resfhp, iap); + err =nfsd_create_setattr (rqstp, fhp, resfhp, iap); -/* -* nfsd_create_setattr already committed the child. Transactional -* filesystems had a chance to commit changes for both parent and -* child simultaneously making the following commit_metadata a -* noop. -*/ - err2 =nfserrno (commit_metadata (fhp)); -if (err2) - err = err2; -/* -* Update the file handle to get the new inode info. -*/ -if (!err) - err =fh_update (resfhp); out:dput (dchild);return err;
@@ -1513,20 +1531,7 @@ do_nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp, } set_attr: - err =nfsd_create_setattr (rqstp, resfhp, iap); - -/* -* nfsd_create_setattr already committed the child -* (and possibly also the parent). -*/ -if (!err) - err =nfserrno (commit_metadata (fhp)); - -/* -* Update the filehandle to get the new inode info. -*/ -if (!err) - err =fh_update (resfhp); + err =nfsd_create_setattr (rqstp, fhp, resfhp, iap); out:fh_unlock (fhp);
fs/nfsd/vfs.h +2 -0
@@ -69,6 +69,8 @@ __be32 nfsd_create(struct svc_rqst *, struct svc_fh *, char *name, int len, struct iattr *attrs, int type, dev_t rdev, struct svc_fh *res);__be32 nfsd_access (struct svc_rqst *,struct svc_fh *,u32 *,u32 *); +__be32 nfsd_create_setattr (struct svc_rqst *rqstp,struct svc_fh *fhp, +struct svc_fh *resfhp,struct iattr *iap); __be32 do_nfsd_create(struct svc_rqst *, struct svc_fh *, char *name, int len, struct iattr *attrs, struct svc_fh *res, int createmode,
Signature · 1 line
2.43.0