staging: assorted lustre clean-up
cover staging: assorted lustre clean-up
Following are assorted patches which clean up parts of lustre. One or two tiny buglets are fixed, but mostly the patches just make the code more readable, often by removing distractions.
The first several patches remove content from libcfs, completely removing 3 files.
There are some list_for_each improvements in ptlrpc, and some code simplification in fid.
Finally a small simplification in socklnd.
(lnd ?? Lustre Networking Domain??)
Thanks,
NeilBrown
---
NeilBrown (21):
staging: lustre: replace all CFS_CAP_* macros with CAP_*
staging: lustre: opencode cfs_cap_{raise,lower,raised}
staging: lustre: remove linux-curproc.c
staging: lustre: remove unnecessary cfs_block_allsigs() calls
staging: lustre: lnet: remove cfs_block_allsigs calls.
staging: lustre: simplify linux-prim.c
staging: lustre: improve API and implementation of blocking signals.
staging: lustre: make signal-blocking functions inline
staging: lustre: discard libcfs_kvzalloc_cpt()
staging: lustre: discard lu_buf allocation library.
staging: lustre: improve some libcfs_kvzalloc calls.
staging: lustre: discard libcfs_kvzalloc and linux-mem.c
staging: lustre: remove phantom struct cfs_crypto_hash_desc
staging: lustre: fix assorted checkpatch errors
staging: lustre: ptlrpc: list_for_each improvements.
staging: lustre: fid: convert lcs_mutex to a spinlock
staging: lustre: fid: use wait_event_cmd()
staging: lustre: fid: remove seq_fid_alloc_fini() and simplify
staging: lustre: fid: fix up debugfs access to ->lcs_space
staging: lustre: fid: perform sanity checks before commiting
staging: lustre: socklnd: simplify ksnc_rx_iov_space
.../staging/lustre/include/linux/libcfs/curproc.h | 37 ++----- .../staging/lustre/include/linux/libcfs/libcfs.h | 27 +++-- .../lustre/include/linux/libcfs/libcfs_crypto.h | 11 +- drivers/staging/lustre/include/linux/lnet/api.h | 1 .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c | 6 - .../staging/lustre/lnet/klnds/socklnd/socklnd.h | 11 -- .../staging/lustre/lnet/klnds/socklnd/socklnd_cb.c | 10 -- .../lustre/lnet/klnds/socklnd/socklnd_lib.c | 2 drivers/staging/lustre/lnet/libcfs/Makefile | 4 - .../staging/lustre/lnet/libcfs/linux/linux-cpu.c | 2 .../lustre/lnet/libcfs/linux/linux-crypto.c | 29 ++--- .../lustre/lnet/libcfs/linux/linux-curproc.c | 108 ------------------- .../staging/lustre/lnet/libcfs/linux/linux-mem.c | 51 --------- .../staging/lustre/lnet/libcfs/linux/linux-prim.c | 113 -------------------- drivers/staging/lustre/lnet/lnet/acceptor.c | 2 drivers/staging/lustre/lnet/lnet/api-ni.c | 15 +-- drivers/staging/lustre/lnet/lnet/lib-eq.c | 10 +- drivers/staging/lustre/lnet/lnet/router.c | 2 drivers/staging/lustre/lnet/selftest/timer.c | 2 drivers/staging/lustre/lustre/fid/fid_request.c | 106 ++++++------------- drivers/staging/lustre/lustre/fid/lproc_fid.c | 44 +++++--- drivers/staging/lustre/lustre/include/lu_object.h | 7 - drivers/staging/lustre/lustre/include/lustre_fid.h | 2 drivers/staging/lustre/lustre/include/lustre_lib.h | 18 ++- drivers/staging/lustre/lustre/include/lustre_sec.h | 3 - drivers/staging/lustre/lustre/include/obd_class.h | 8 + .../staging/lustre/lustre/include/obd_support.h | 2 drivers/staging/lustre/lustre/llite/dcache.c | 2 drivers/staging/lustre/lustre/llite/dir.c | 10 +- drivers/staging/lustre/lustre/llite/file.c | 12 +- drivers/staging/lustre/lustre/llite/llite_lib.c | 8 + drivers/staging/lustre/lustre/llite/llite_mmap.c | 8 + drivers/staging/lustre/lustre/llite/xattr.c | 2 drivers/staging/lustre/lustre/lmv/lmv_obd.c | 4 - drivers/staging/lustre/lustre/lov/lov_ea.c | 2 drivers/staging/lustre/lustre/lov/lov_io.c | 2 drivers/staging/lustre/lustre/lov/lov_lock.c | 2 drivers/staging/lustre/lustre/lov/lov_object.c | 4 - drivers/staging/lustre/lustre/lov/lov_pack.c | 2 drivers/staging/lustre/lustre/lov/lov_request.c | 2 drivers/staging/lustre/lustre/mdc/mdc_locks.c | 2 drivers/staging/lustre/lustre/mdc/mdc_request.c | 6 + drivers/staging/lustre/lustre/obdclass/linkea.c | 16 ++- .../lustre/lustre/obdclass/linux/linux-module.c | 4 - drivers/staging/lustre/lustre/obdclass/llog.c | 22 ++-- drivers/staging/lustre/lustre/obdclass/lu_object.c | 70 ------------ .../lustre/lustre/obdclass/lustre_handles.c | 4 - .../staging/lustre/lustre/obdecho/echo_client.c | 8 + drivers/staging/lustre/lustre/osc/osc_cache.c | 4 - drivers/staging/lustre/lustre/osc/osc_page.c | 2 drivers/staging/lustre/lustre/osc/osc_request.c | 2 drivers/staging/lustre/lustre/ptlrpc/client.c | 93 +++++----------- drivers/staging/lustre/lustre/ptlrpc/import.c | 34 ++---- drivers/staging/lustre/lustre/ptlrpc/layout.c | 2 drivers/staging/lustre/lustre/ptlrpc/pinger.c | 8 - drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c | 15 +-- drivers/staging/lustre/lustre/ptlrpc/recover.c | 28 ++--- drivers/staging/lustre/lustre/ptlrpc/sec.c | 4 - drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c | 4 - drivers/staging/lustre/lustre/ptlrpc/sec_null.c | 8 + drivers/staging/lustre/lustre/ptlrpc/sec_plain.c | 8 + drivers/staging/lustre/lustre/ptlrpc/service.c | 27 ++--- 62 files changed, 295 insertions(+), 769 deletions(-) delete mode 100644 drivers/staging/lustre/lnet/libcfs/linux/linux-curproc.c delete mode 100644 drivers/staging/lustre/lnet/libcfs/linux/linux-mem.c delete mode 100644 drivers/staging/lustre/lnet/libcfs/linux/linux-prim.c
--
Signature
PATCH 1/21 staging: lustre: replace all CFS_CAP_* macros with CAP_*
Lustre defines a few CFS_CAP_* macros which are exactly the same as the corresponding CAP_* macro, with one exception.
CFS_CAP_SYS_BOOT is 23CAP_SYS_BOOT is 22.
CFS_CAP_SYS_BOOT is only used through CFS_CAP_FS_MASK and causes capability 23 (CAP_SYS_NICE) to be dropped in certain circumstances.
It is probable that the intention was to drop CAP_SYS_BOOT, and this is what is now done.
CFS_CAP_CHOWN_MASK and CFS_CAP_SYS_RESOURCE_MASK are never used, so they have been removed.
--- .../staging/lustre/include/linux/libcfs/curproc.h | 28 ++++++-------------- drivers/staging/lustre/lustre/include/lustre_sec.h | 3 -- drivers/staging/lustre/lustre/llite/dir.c | 8 +++--- drivers/staging/lustre/lustre/llite/file.c | 6 ++-- drivers/staging/lustre/lustre/llite/llite_lib.c | 4 +-- drivers/staging/lustre/lustre/llite/xattr.c | 2 + .../lustre/lustre/obdclass/linux/linux-module.c | 2 + drivers/staging/lustre/lustre/obdclass/llog.c | 6 ++-- .../staging/lustre/lustre/obdecho/echo_client.c | 8 +++--- drivers/staging/lustre/lustre/osc/osc_cache.c | 4 +-- drivers/staging/lustre/lustre/osc/osc_page.c | 2 + 11 files changed, 30 insertions(+), 43 deletions(-)
drivers/staging/lustre/include/linux/libcfs/curproc.h +9 -19
@@ -56,25 +56,15 @@typedef u32 cfs_cap_t ; -#define CFS_CAP_CHOWN 0 -#define CFS_CAP_DAC_OVERRIDE 1 -#define CFS_CAP_DAC_READ_SEARCH 2 -#define CFS_CAP_FOWNER 3 -#define CFS_CAP_FSETID 4 -#define CFS_CAP_LINUX_IMMUTABLE 9 -#define CFS_CAP_SYS_ADMIN 21 -#define CFS_CAP_SYS_BOOT 23 -#define CFS_CAP_SYS_RESOURCE 24 - -#define CFS_CAP_FS_MASK (BIT(CFS_CAP_CHOWN) | \ - BIT(CFS_CAP_DAC_OVERRIDE) | \ - BIT(CFS_CAP_DAC_READ_SEARCH) | \ - BIT(CFS_CAP_FOWNER) | \ - BIT(CFS_CAP_FSETID) | \ - BIT(CFS_CAP_LINUX_IMMUTABLE) | \ - BIT(CFS_CAP_SYS_ADMIN) | \ - BIT(CFS_CAP_SYS_BOOT) | \ - BIT(CFS_CAP_SYS_RESOURCE)) +#define CFS_CAP_FS_MASK (BIT(CAP_CHOWN) | \ + BIT(CAP_DAC_OVERRIDE) | \ + BIT(CAP_DAC_READ_SEARCH) | \ + BIT(CAP_FOWNER) | \ + BIT(CAP_FSETID) | \ + BIT(CAP_LINUX_IMMUTABLE) | \ + BIT(CAP_SYS_ADMIN) | \ + BIT(CAP_SYS_BOOT) | \ + BIT(CAP_SYS_RESOURCE))void cfs_cap_raise (cfs_cap_t cap);void cfs_cap_lower (cfs_cap_t cap);
drivers/staging/lustre/lustre/include/lustre_sec.h +0 -3
@@ -1058,9 +1058,6 @@ int sptlrpc_current_user_desc_size(void);int sptlrpc_pack_user_desc (struct lustre_msg *msg,int offset);int sptlrpc_unpack_user_desc (struct lustre_msg *req,int offset,int swabbed); -#define CFS_CAP_CHOWN_MASK (1 << CFS_CAP_CHOWN) -#define CFS_CAP_SYS_RESOURCE_MASK (1 << CFS_CAP_SYS_RESOURCE) -enum {LUSTRE_SEC_NONE =0 ,LUSTRE_SEC_REMOTE =1 ,
drivers/staging/lustre/lustre/llite/dir.c +4 -4
@@ -885,7 +885,7 @@ static int quotactl_ioctl(struct ll_sb_info *sbi, struct if_quotactl *qctl)switch (cmd) {case Q_SETQUOTA :case Q_SETINFO : -if (!capable (CFS_CAP_SYS_ADMIN )) +if (!capable (CAP_SYS_ADMIN ))return -EPERM ;break ;case Q_GETQUOTA :
@@ -893,7 +893,7 @@ static int quotactl_ioctl(struct ll_sb_info *sbi, struct if_quotactl *qctl) !uid_eq(current_euid(), make_kuid(&init_user_ns, id))) || (type ==GRPQUOTA && !in_egroup_p(make_kgid(&init_user_ns, id)))) && - !capable(CFS_CAP_SYS_ADMIN)) + !capable(CAP_SYS_ADMIN)) return -EPERM;break ;case Q_GETINFO :
@@ -1452,7 +1452,7 @@ static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg) }case OBD_IOC_CHANGELOG_SEND :case OBD_IOC_CHANGELOG_CLEAR : -if (!capable (CFS_CAP_SYS_ADMIN )) +if (!capable (CAP_SYS_ADMIN ))return -EPERM ; rc = copy_and_ioctl(cmd, sbi->ll_md_exp, (void __user *)arg,
@@ -1556,7 +1556,7 @@ static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)return rc; }case LL_IOC_HSM_CT_START : -if (!capable (CFS_CAP_SYS_ADMIN )) +if (!capable (CAP_SYS_ADMIN ))return -EPERM ; rc = copy_and_ioctl(cmd, sbi->ll_md_exp, (void __user *)arg,
drivers/staging/lustre/lustre/llite/file.c +3 -3
@@ -1315,7 +1315,7 @@ static int ll_lov_setea(struct inode *inode, struct file *file,sizeof (struct lov_user_ost_data );int rc; -if (!capable (CFS_CAP_SYS_ADMIN )) +if (!capable (CAP_SYS_ADMIN ))return -EPERM ; lump =libcfs_kvzalloc (lum_size,GFP_NOFS );
@@ -1570,7 +1570,7 @@ int ll_fid2path(struct inode *inode, void __user *arg)size_t outsize;int rc; -if (!capable (CFS_CAP_DAC_READ_SEARCH ) && +if (!capable (CAP_DAC_READ_SEARCH ) && !(ll_i2sbi (inode)->ll_flags &LL_SBI_USER_FID2PATH ))return -EPERM ;
@@ -1840,7 +1840,7 @@ int ll_hsm_state_set(struct inode *inode, struct hsm_state_set *hss)* NOT defined in HSM_USER_MASK. */ if (((hss->hss_setmask | hss->hss_clearmask) & ~HSM_USER_MASK ) && - !capable (CFS_CAP_SYS_ADMIN )) + !capable (CAP_SYS_ADMIN ))return -EPERM ;/* Detect out-of range archive id */
drivers/staging/lustre/lustre/llite/llite_lib.c +2 -2
@@ -1450,7 +1450,7 @@ int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import)/* POSIX: check before ATTR_*TIME_SET set (from setattr_prepare) */ if (attr->ia_valid &TIMES_SET_FLAGS ) {if ((!uid_eq (current_fsuid (), inode->i_uid)) && - !capable (CFS_CAP_FOWNER )) + !capable (CAP_FOWNER ))return -EPERM ; }
@@ -2597,7 +2597,7 @@ int ll_getparent(struct file *file, struct getparent __user *arg)u32 linkno;int rc; -if (!capable (CFS_CAP_DAC_READ_SEARCH ) && +if (!capable (CAP_DAC_READ_SEARCH ) && !(ll_i2sbi (inode)->ll_flags &LL_SBI_USER_FID2PATH ))return -EPERM ;
drivers/staging/lustre/lustre/llite/xattr.c +1 -1
@@ -75,7 +75,7 @@ static int xattr_type_filter(struct ll_sb_info *sbi,return -EOPNOTSUPP ;if (handler->flags ==XATTR_TRUSTED_T && - !capable (CFS_CAP_SYS_ADMIN )) + !capable (CAP_SYS_ADMIN ))return -EPERM ;return 0 ;
drivers/staging/lustre/lustre/obdclass/linux/linux-module.c +1 -1
@@ -251,7 +251,7 @@ static long obd_class_ioctl(struct file *filp, unsigned int cmd,int err =0 ;/* Allow non-root access for OBD_IOC_PING_TARGET - used by lfs check */ -if (!capable (CFS_CAP_SYS_ADMIN ) && (cmd !=OBD_IOC_PING_TARGET )) +if (!capable (CAP_SYS_ADMIN ) && (cmd !=OBD_IOC_PING_TARGET ))return err = -EACCES ;if ((cmd &0xffffff00 ) == ((int )'T' ) <<8 )/* ignore all tty ioctls */ return err = -ENOTTY ;
drivers/staging/lustre/lustre/obdclass/llog.c +3 -3
@@ -483,12 +483,12 @@ int llog_open(const struct lu_env *env, struct llog_ctxt *ctxt, (*lgh)->lgh_ctxt = ctxt; (*lgh)->lgh_logops = ctxt->loc_logops; - raised =cfs_cap_raised (CFS_CAP_SYS_RESOURCE ); + raised =cfs_cap_raised (CAP_SYS_RESOURCE );if (!raised) -cfs_cap_raise (CFS_CAP_SYS_RESOURCE ); +cfs_cap_raise (CAP_SYS_RESOURCE ); rc = ctxt->loc_logops->lop_open (env, *lgh, logid, name, open_param);if (!raised) -cfs_cap_lower (CFS_CAP_SYS_RESOURCE ); +cfs_cap_lower (CAP_SYS_RESOURCE );if (rc) {llog_free_handle (*lgh); *lgh =NULL ;
drivers/staging/lustre/lustre/obdecho/echo_client.c +4 -4
@@ -1502,7 +1502,7 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,switch (cmd) {case OBD_IOC_CREATE :/* may create echo object */ -if (!capable (CFS_CAP_SYS_ADMIN )) { +if (!capable (CAP_SYS_ADMIN )) { rc = -EPERM ; goto out; }
@@ -1511,7 +1511,7 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len, goto out;case OBD_IOC_DESTROY : -if (!capable (CFS_CAP_SYS_ADMIN )) { +if (!capable (CAP_SYS_ADMIN )) { rc = -EPERM ; goto out; }
@@ -1534,7 +1534,7 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len, goto out;case OBD_IOC_SETATTR : -if (!capable (CFS_CAP_SYS_ADMIN )) { +if (!capable (CAP_SYS_ADMIN )) { rc = -EPERM ; goto out; }
@@ -1547,7 +1547,7 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len, goto out;case OBD_IOC_BRW_WRITE : -if (!capable (CFS_CAP_SYS_ADMIN )) { +if (!capable (CAP_SYS_ADMIN )) { rc = -EPERM ; goto out; }
drivers/staging/lustre/lustre/osc/osc_cache.c +2 -2
@@ -2345,7 +2345,7 @@ int osc_prep_async_page(struct osc_object *osc, struct osc_page *ops, oap->oap_obj_off = offset;LASSERT (!(offset & ~PAGE_MASK )); -if (capable (CFS_CAP_SYS_RESOURCE )) +if (capable (CAP_SYS_RESOURCE )) oap->oap_brw_flags =OBD_BRW_NOQUOTA ;INIT_LIST_HEAD (&oap->oap_pending_item);
@@ -2384,7 +2384,7 @@ int osc_queue_async_io(const struct lu_env *env, struct cl_io *io,/* Set the OBD_BRW_SRVLOCK before the page is queued. */ brw_flags |= ops->ops_srvlock ?OBD_BRW_SRVLOCK :0 ; -if (capable (CFS_CAP_SYS_RESOURCE )) { +if (capable (CAP_SYS_RESOURCE )) { brw_flags |=OBD_BRW_NOQUOTA ; cmd |=OBD_BRW_NOQUOTA ; }
drivers/staging/lustre/lustre/osc/osc_page.c +1 -1
@@ -307,7 +307,7 @@ void osc_page_submit(const struct lu_env *env, struct osc_page *opg, oap->oap_count = opg->ops_to - opg->ops_from; oap->oap_brw_flags = brw_flags |OBD_BRW_SYNC ; -if (capable (CFS_CAP_SYS_RESOURCE )) { +if (capable (CAP_SYS_RESOURCE )) { oap->oap_brw_flags |=OBD_BRW_NOQUOTA ; oap->oap_cmd |=OBD_BRW_NOQUOTA ; }
PATCH 2/21 staging: lustre: opencode cfs_cap_{raise, lower, raised}
In reply to NeilBrownEach of these functions is used precisely once, so having a separate exported function seems like overkill.
cfs_cap_raised() is trivial - one line. cfs_cap_raise() and cfs_cap_lower() are used as a pair which is more effectively implemented with override_cred() / revert_creds().
--- .../staging/lustre/include/linux/libcfs/curproc.h | 3 -- .../lustre/lnet/libcfs/linux/linux-curproc.c | 30 -------------------- drivers/staging/lustre/lustre/obdclass/llog.c | 18 ++++++++---- 3 files changed, 12 insertions(+), 39 deletions(-)
drivers/staging/lustre/include/linux/libcfs/curproc.h +0 -3
@@ -66,9 +66,6 @@ typedef u32 cfs_cap_t; BIT(CAP_SYS_BOOT) | \ BIT(CAP_SYS_RESOURCE)) -void cfs_cap_raise (cfs_cap_t cap); -void cfs_cap_lower (cfs_cap_t cap); -int cfs_cap_raised (cfs_cap_t cap);cfs_cap_t cfs_curproc_cap_pack (void );/* __LIBCFS_CURPROC_H__ */
drivers/staging/lustre/lnet/libcfs/linux/linux-curproc.c +0 -30
@@ -52,36 +52,6 @@* for Linux kernel. */ -void cfs_cap_raise (cfs_cap_t cap) -{ -struct cred *cred; - - cred =prepare_creds (); -if (cred) { -cap_raise (cred->cap_effective, cap); -commit_creds (cred); - } -} -EXPORT_SYMBOL (cfs_cap_raise); - -void cfs_cap_lower (cfs_cap_t cap) -{ -struct cred *cred; - - cred =prepare_creds (); -if (cred) { -cap_lower (cred->cap_effective, cap); -commit_creds (cred); - } -} -EXPORT_SYMBOL (cfs_cap_lower); - -int cfs_cap_raised (cfs_cap_t cap) -{ -return cap_raised (current_cap (), cap); -} -EXPORT_SYMBOL (cfs_cap_raised); -static void cfs_kernel_cap_pack (kernel_cap_t kcap,cfs_cap_t *cap) {/* XXX lost high byte */
drivers/staging/lustre/lustre/obdclass/llog.c +12 -6
@@ -466,7 +466,7 @@ int llog_open(const struct lu_env *env, struct llog_ctxt *ctxt, struct llog_handle **lgh, struct llog_logid *logid, char *name, enum llog_open_param open_param) { - int raised; + const struct cred *old_cred = NULL;int rc;LASSERT (ctxt);
@@ -483,12 +483,18 @@ int llog_open(const struct lu_env *env, struct llog_ctxt *ctxt, (*lgh)->lgh_ctxt = ctxt; (*lgh)->lgh_logops = ctxt->loc_logops; - raised =cfs_cap_raised (CAP_SYS_RESOURCE ); -if (!raised) -cfs_cap_raise (CAP_SYS_RESOURCE ); +if (cap_raised (current_cap (),CAP_SYS_RESOURCE )) { +struct cred *cred =prepare_creds (); + +if (cred) { +cap_raise (cred->cap_effective,CAP_SYS_RESOURCE ); + old_cred =override_creds (cred); + } + } rc = ctxt->loc_logops->lop_open (env, *lgh, logid, name, open_param); -if (!raised) -cfs_cap_lower (CAP_SYS_RESOURCE ); +if (old_cred) +revert_creds (old_cred); +if (rc) {llog_free_handle (*lgh); *lgh =NULL ;
PATCH 3/21 staging: lustre: remove linux-curproc.c
In reply to NeilBrownThe only functionality remaining here iscfs_curproc_cap_pack(),
and it can be trivially implemented as an inline
in curproc.h.
So do that and remove the file.
--- .../staging/lustre/include/linux/libcfs/curproc.h | 6 +- drivers/staging/lustre/lnet/libcfs/Makefile | 1 .../lustre/lnet/libcfs/linux/linux-curproc.c | 78 -------------------- 3 files changed, 5 insertions(+), 80 deletions(-) delete mode 100644 drivers/staging/lustre/lnet/libcfs/linux/linux-curproc.c
drivers/staging/lustre/include/linux/libcfs/curproc.h +5 -1
@@ -66,7 +66,11 @@ typedef u32 cfs_cap_t; BIT(CAP_SYS_BOOT) | \ BIT(CAP_SYS_RESOURCE)) -cfs_cap_t cfs_curproc_cap_pack (void ); +static inline cfs_cap_t cfs_curproc_cap_pack (void ) +{ +/* cfs_cap_t is only the first word of kernel_cap_t */ +return (cfs_cap_t)(current_cap ().cap[0 ]); +}/* __LIBCFS_CURPROC_H__ */ #endif
drivers/staging/lustre/lnet/libcfs/Makefile +0 -1
@@ -6,7 +6,6 @@ obj-$(CONFIG_LNET) += libcfs.o libcfs-linux-objs := linux-tracefile.o linux-debug.o libcfs-linux-objs += linux-prim.o linux-cpu.o -libcfs-linux-objs += linux-curproc.o libcfs-linux-objs += linux-module.o libcfs-linux-objs += linux-crypto.o libcfs-linux-objs += linux-crypto-adler.o
drivers/staging/lustre/lnet/libcfs/linux/linux-curproc.c deleted +0 -78
78 lines not on this page · raw message
PATCH 4/21 staging: lustre: remove unnecessary cfs_block_allsigs() calls
In reply to NeilBrownThreads started by kthread_run() ignore all signals, as kthreadd() calls ignore_signals(), and this is inherited by all children.
So there is no need to call cfs_block_allsigs() in functions that are only run from kthread_run().
--- .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c | 6 ------ .../staging/lustre/lnet/klnds/socklnd/socklnd_cb.c | 6 ------ drivers/staging/lustre/lnet/lnet/acceptor.c | 2 -- drivers/staging/lustre/lnet/lnet/router.c | 2 -- drivers/staging/lustre/lnet/selftest/timer.c | 2 -- 5 files changed, 18 deletions(-)
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c +0 -6
@@ -3288,8 +3288,6 @@ kiblnd_connd(void *arg)int peer_index =0 ;unsigned long deadline = jiffies; -cfs_block_allsigs (); -init_waitqueue_entry (&wait, current); kiblnd_data.kib_connd = current;
@@ -3542,8 +3540,6 @@ kiblnd_scheduler(void *arg)int busy_loops =0 ;int rc; -cfs_block_allsigs (); -init_waitqueue_entry (&wait, current); sched = kiblnd_data.kib_scheds[KIB_THREAD_CPT (id)];
@@ -3676,8 +3672,6 @@ kiblnd_failover_thread(void *arg)LASSERT (*kiblnd_tunables.kib_dev_failover); -cfs_block_allsigs (); -init_waitqueue_entry (&wait, current);write_lock_irqsave (glock, flags);
drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c +0 -6
@@ -1324,8 +1324,6 @@ int ksocknal_scheduler(void *arg) info = ksocknal_data.ksnd_sched_info[KSOCK_THREAD_CPT (id)]; sched = &info->ksi_scheds[KSOCK_THREAD_SID (id)]; -cfs_block_allsigs (); - rc =cfs_cpt_bind (lnet_cpt_table (), info->ksi_cpt);if (rc) { CWARN("Can't set CPU partition affinity to %d: %d\n",
@@ -2078,8 +2076,6 @@ ksocknal_connd(void *arg)int nloops =0 ;int cons_retry =0 ; -cfs_block_allsigs (); -init_waitqueue_entry (&wait, current);spin_lock_bh (connd_lock);
@@ -2472,8 +2468,6 @@ ksocknal_reaper(void *arg)int peer_index =0 ;unsigned long deadline =cfs_time_current (); -cfs_block_allsigs (); -INIT_LIST_HEAD (&enomem_conns);init_waitqueue_entry (&wait, current);
drivers/staging/lustre/lnet/lnet/acceptor.c +0 -2
@@ -335,8 +335,6 @@ lnet_acceptor(void *arg)LASSERT (!lnet_acceptor_state.pta_sock); -cfs_block_allsigs (); - rc =lnet_sock_listen (&lnet_acceptor_state.pta_sock,0 , accept_port, accept_backlog);if (rc) {
drivers/staging/lustre/lnet/lnet/router.c +0 -2
@@ -1226,8 +1226,6 @@ lnet_router_checker(void *arg)struct lnet_peer *rtr;struct list_head *entry; -cfs_block_allsigs (); -while (the_lnet.ln_rc_state ==LNET_RC_STATE_RUNNING ) {__u64 version;int cpt;
drivers/staging/lustre/lnet/selftest/timer.c +0 -2
@@ -170,8 +170,6 @@ stt_timer_main(void *arg) {int rc =0 ; -cfs_block_allsigs (); -while (!stt_data.stt_shuttingdown) {stt_check_timers (&stt_data.stt_prev_slot);
PATCH 5/21 staging: lustre: lnet: remove cfs_block_allsigs calls.
In reply to NeilBrownBoth places that cfs_block_allsigs() is used here,
the goal is to turn an interruptible wait into an uninterruptible way.
So instead of blocking the signals, change TASK_INTERRUPTIBLE to TASK_NOLOAD.
In each case, no other functions called while signals are blocked will sleep - just the one that has been fixed.
In one case, an extra 'interruptible' flag needs to be passed down so the waiting decision can be made at the right place.
--- drivers/staging/lustre/include/linux/lnet/api.h | 1 + drivers/staging/lustre/lnet/lnet/api-ni.c | 15 +++------------ drivers/staging/lustre/lnet/lnet/lib-eq.c | 10 +++++++--- 3 files changed, 11 insertions(+), 15 deletions(-)
drivers/staging/lustre/include/linux/lnet/api.h +1 -0
@@ -169,6 +169,7 @@ int LNetEQFree(struct lnet_handle_eq eventq_in);int LNetEQPoll (struct lnet_handle_eq *eventqs_in,int neq_in,int timeout_ms, +int interruptible,struct lnet_event *event_out,int *which_eq_out);/** @} lnet_eq */
drivers/staging/lustre/lnet/lnet/api-ni.c +3 -12
@@ -961,19 +961,15 @@ static void lnet_ping_md_unlink(struct lnet_ping_info *pinfo, struct lnet_handle_md *md_handle) { - sigset_t blocked = cfs_block_allsigs(); - LNetMDUnlink(*md_handle);LNetInvalidateMDHandle (md_handle);/* NB md could be busy; this just starts the unlink */ while (pinfo->pi_features !=LNET_PING_FEAT_INVAL ) {CDEBUG (D_NET ,"Still waiting for ping MD to unlink\n" ); -set_current_state (TASK_UNINTERRUPTIBLE ); +set_current_state (TASK_NOLOAD );schedule_timeout (HZ ); } - -cfs_restore_sigs (blocked); } static void
@@ -2141,7 +2137,6 @@ static int lnet_ping(struct lnet_process_id id, int timeout_ms,int nob;int rc;int rc2; -sigset_t blocked; infosz = offsetof(struct lnet_ping_info, pi_ni[n_ids]);
@@ -2197,13 +2192,9 @@ static int lnet_ping(struct lnet_process_id id, int timeout_ms, do { /* MUST block for unlink to complete */ - if (unlinked) - blocked = cfs_block_allsigs(); - - rc2 = LNetEQPoll(&eqh, 1, timeout_ms, &event, &which); - if (unlinked) - cfs_restore_sigs(blocked); + rc2 = LNetEQPoll(&eqh, 1, timeout_ms, !unlinked, + &event, &which); CDEBUG(D_NET, "poll %d(%d %d)%s\n", rc2, (rc2 <= 0) ? -1 : event.type,
drivers/staging/lustre/lnet/lnet/lib-eq.c +7 -3
@@ -308,7 +308,7 @@ lnet_eq_dequeue_event(struct lnet_eq *eq, struct lnet_event *ev)*/ static int -lnet_eq_wait_locked (int *timeout_ms) +lnet_eq_wait_locked (int *timeout_ms,long state) __must_hold(&the_lnet.ln_eq_wait_lock) {int tms = *timeout_ms;
@@ -320,7 +320,7 @@ __must_hold(&the_lnet.ln_eq_wait_lock)return -ENXIO ;/* don't want to wait and no new event */ init_waitqueue_entry (&wl, current); -set_current_state (TASK_INTERRUPTIBLE ); +set_current_state (state);add_wait_queue (&the_lnet.ln_eq_waitq, &wl);lnet_eq_wait_unlock ();
@@ -359,6 +359,7 @@ __must_hold(&the_lnet.ln_eq_wait_lock)* \param timeout_ms Time in milliseconds to wait for an event to occur on * one of the EQs. The constant LNET_TIME_FOREVER can be used to indicate an * infinite timeout. +* \param interruptible, if true, use TASK_INTERRUPTIBLE, else TASK_NOLOAD * \param event,which On successful return (1 or -EOVERFLOW), \a event will * hold the next event in the EQs, and \a which will contain the index of the * EQ from which the event was taken.
@@ -372,6 +373,7 @@ __must_hold(&the_lnet.ln_eq_wait_lock)*/ int LNetEQPoll (struct lnet_handle_eq *eventqs,int neq,int timeout_ms, +int interruptible,struct lnet_event *event,int *which) {int wait =1 ;
@@ -412,7 +414,9 @@ LNetEQPoll(struct lnet_handle_eq *eventqs, int neq, int timeout_ms,* 0 : don't want to wait anymore, but might have new event * so need to call dequeue again */ - wait =lnet_eq_wait_locked (&timeout_ms); + wait =lnet_eq_wait_locked (&timeout_ms, + interruptible ?TASK_INTERRUPTIBLE + :TASK_NOLOAD );if (wait <0 )/* no new event */ break ; }
PATCH 6/21 staging: lustre: simplify linux-prim.c
In reply to NeilBrowncfs_block_sigs() is never used.cfs_clear_sigpending() is never used.cfs_block_allsigs() is no longer used.
So those three functions can go.
--- .../staging/lustre/include/linux/libcfs/libcfs.h | 3 - .../staging/lustre/lnet/libcfs/linux/linux-prim.c | 41 -------------------- 2 files changed, 44 deletions(-)
drivers/staging/lustre/include/linux/libcfs/libcfs.h +0 -3
@@ -67,11 +67,8 @@/* * Defined by platform */ -sigset_t cfs_block_allsigs (void ); -sigset_t cfs_block_sigs (unsigned long sigs);sigset_t cfs_block_sigsinv (unsigned long sigs);void cfs_restore_sigs (sigset_t sigset); -void cfs_clear_sigpending (void );struct libcfs_ioctl_handler {struct list_head item;
drivers/staging/lustre/lnet/libcfs/linux/linux-prim.c +0 -41
50 lines not on this page · raw message
PATCH 7/21 staging: lustre: improve API and implementation of blocking signals.
In reply to NeilBrownAccording to comment for set_current_blocked() in kernel/signal.c, changing ->blocked directly is wrong. sigprocmask() should be called instead.
So change cfs_block_sigsinv() and cfs_restore_sigs() to use sigprocmask().
For consistency, change them to pass the sigset_t by reference rather than by value.
Also fix cfs_block_sigsinv() so that it correctly blocks signals above 32 on a 32bit host.
--- .../staging/lustre/include/linux/libcfs/libcfs.h | 4 ++- .../staging/lustre/lnet/libcfs/linux/linux-prim.c | 24 ++++++-------------- drivers/staging/lustre/lustre/include/lustre_lib.h | 18 ++++++++------- drivers/staging/lustre/lustre/llite/llite_mmap.c | 8 +++---- 4 files changed, 22 insertions(+), 32 deletions(-)
drivers/staging/lustre/include/linux/libcfs/libcfs.h +2 -2
@@ -67,8 +67,8 @@/* * Defined by platform */ -sigset_t cfs_block_sigsinv (unsigned long sigs); -void cfs_restore_sigs (sigset_t sigset); +void cfs_block_sigsinv (unsigned long sigs,sigset_t *sigset); +void cfs_restore_sigs (sigset_t *sigset);struct libcfs_ioctl_handler {struct list_head item;
drivers/staging/lustre/lnet/libcfs/linux/linux-prim.c +7 -17
@@ -44,29 +44,19 @@#endif /* Block all signals except for the @sigs */ -sigset_t cfs_block_sigsinv (unsigned long sigs) +void cfs_block_sigsinv (unsigned long sigs,sigset_t *old) { -unsigned long flags; -sigset_t old; +sigset_t new; -spin_lock_irqsave (¤t->sighand->siglock, flags); - old = current->blocked; -sigaddsetmask (¤t->blocked, ~sigs); -recalc_sigpending (); -spin_unlock_irqrestore (¤t->sighand->siglock, flags); - -return old; +siginitsetinv (&new, sigs); +sigorsets (&new, ¤t->blocked, &new); +sigprocmask (SIG_BLOCK , &new, old); }EXPORT_SYMBOL (cfs_block_sigsinv);void -cfs_restore_sigs (sigset_t old) +cfs_restore_sigs (sigset_t *old) { -unsigned long flags; - -spin_lock_irqsave (¤t->sighand->siglock, flags); - current->blocked = old; -recalc_sigpending (); -spin_unlock_irqrestore (¤t->sighand->siglock, flags); +sigprocmask (SIG_SETMASK , old,NULL ); }EXPORT_SYMBOL (cfs_restore_sigs);
drivers/staging/lustre/lustre/include/lustre_lib.h +9 -9
@@ -94,31 +94,31 @@ static inline int l_fatal_signal_pending(struct task_struct *p)*/ #define l_wait_event_abortable (wq, condition) \ ({ \ - sigset_t __blocked; \ + sigset_t __old_blocked; \ int __ret = 0; \ - __blocked = cfs_block_sigsinv(LUSTRE_FATAL_SIGS); \ + cfs_block_sigsinv(LUSTRE_FATAL_SIGS, &__old_blocked); \ __ret = wait_event_interruptible(wq, condition); \ - cfs_restore_sigs(__blocked); \ + cfs_restore_sigs(&__old_blocked); \ __ret; \ })#define l_wait_event_abortable_timeout (wq, condition, timeout) \ ({ \ - sigset_t __blocked; \ + sigset_t __old_blocked; \ int __ret = 0; \ - __blocked = cfs_block_sigsinv(LUSTRE_FATAL_SIGS); \ + cfs_block_sigsinv(LUSTRE_FATAL_SIGS, &__old_blocked); \ __ret = wait_event_interruptible_timeout(wq, condition, timeout);\ - cfs_restore_sigs(__blocked); \ + cfs_restore_sigs(&__old_blocked); \ __ret; \ })#define l_wait_event_abortable_exclusive (wq, condition) \ ({ \ - sigset_t __blocked; \ + sigset_t __old_blocked; \ int __ret = 0; \ - __blocked = cfs_block_sigsinv(LUSTRE_FATAL_SIGS); \ + cfs_block_sigsinv(LUSTRE_FATAL_SIGS, &__old_blocked); \ __ret = wait_event_interruptible_exclusive(wq, condition); \ - cfs_restore_sigs(__blocked); \ + cfs_restore_sigs(&__old_blocked); \ __ret; \ })#endif /* _LUSTRE_LIB_H */
drivers/staging/lustre/lustre/llite/llite_mmap.c +4 -4
@@ -177,14 +177,14 @@ static int ll_page_mkwrite0(struct vm_area_struct *vma, struct page *vmpage, vio->u.fault.ft_vma = vma; vio->u.fault.ft_vmpage = vmpage; - set =cfs_block_sigsinv (sigmask (SIGKILL ) |sigmask (SIGTERM )); +cfs_block_sigsinv (sigmask (SIGKILL ) |sigmask (SIGTERM ), &set); inode =vvp_object_inode (io->ci_obj); lli =ll_i2info (inode); result =cl_io_loop (env, io); -cfs_restore_sigs (set); +cfs_restore_sigs (&set);if (result ==0 ) {struct inode *inode =file_inode (vma->vm_file);
@@ -334,7 +334,7 @@ static int ll_fault(struct vm_fault *vmf)* so that it can be killed by admin but not cause segfault by * other signals. */ - set =cfs_block_sigsinv (sigmask (SIGKILL ) |sigmask (SIGTERM )); +cfs_block_sigsinv (sigmask (SIGKILL ) |sigmask (SIGTERM ), &set); restart: result =ll_fault0 (vmf->vma, vmf);
@@ -360,7 +360,7 @@ static int ll_fault(struct vm_fault *vmf) result =VM_FAULT_LOCKED ; } -cfs_restore_sigs (set); +cfs_restore_sigs (&set);return result; }
PATCH 8/21 staging: lustre: make signal-blocking functions inline
In reply to NeilBrowncfs_block_sigsinv() and cfs_restore_sigs() are now simple enough to inline them.
This means we can discard linux-prim.c
--- .../staging/lustre/include/linux/libcfs/libcfs.h | 20 +++++- drivers/staging/lustre/lnet/libcfs/Makefile | 2 - .../staging/lustre/lnet/libcfs/linux/linux-prim.c | 62 -------------------- 3 files changed, 16 insertions(+), 68 deletions(-) delete mode 100644 drivers/staging/lustre/lnet/libcfs/linux/linux-prim.c
drivers/staging/lustre/include/linux/libcfs/libcfs.h +15 -5
@@ -64,11 +64,21 @@#define LNET_ACCEPTOR_MIN_RESERVED_PORT 512#define LNET_ACCEPTOR_MAX_RESERVED_PORT 1023 -/* -* Defined by platform -*/ -void cfs_block_sigsinv (unsigned long sigs,sigset_t *sigset); -void cfs_restore_sigs (sigset_t *sigset); +/* Block all signals except for the @sigs */ +static inline void cfs_block_sigsinv (unsigned long sigs,sigset_t *old) +{ +sigset_t new; + +siginitsetinv (&new, sigs); +sigorsets (&new, ¤t->blocked, &new); +sigprocmask (SIG_BLOCK , &new, old); +} + +static inline void +cfs_restore_sigs (sigset_t *old) +{ +sigprocmask (SIG_SETMASK , old,NULL ); +}struct libcfs_ioctl_handler {struct list_head item;
drivers/staging/lustre/lnet/libcfs/Makefile +1 -1
@@ -5,7 +5,7 @@ subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include obj-$(CONFIG_LNET) += libcfs.o libcfs-linux-objs := linux-tracefile.o linux-debug.o -libcfs-linux-objs += linux-prim.o linux-cpu.o +libcfs-linux-objs += linux-cpu.o libcfs-linux-objs += linux-module.o libcfs-linux-objs += linux-crypto.o libcfs-linux-objs += linux-crypto-adler.o
drivers/staging/lustre/lnet/libcfs/linux/linux-prim.c deleted +0 -62
62 lines not on this page · raw message
PATCH 9/21 staging: lustre: discard libcfs_kvzalloc_cpt()
In reply to NeilBrownThis function is used precisely once, and is sufficiently trivial that it may as well be open-coded.
Doing so helpfully highlights the similarity between the new kvzalloc_node() call and the already existing kzalloc_node() call in the same function.
--- .../staging/lustre/include/linux/libcfs/libcfs.h | 2 -- .../staging/lustre/lnet/libcfs/linux/linux-mem.c | 7 ------- drivers/staging/lustre/lustre/ptlrpc/service.c | 8 ++++---- 3 files changed, 4 insertions(+), 13 deletions(-)
drivers/staging/lustre/include/linux/libcfs/libcfs.h +0 -2
@@ -113,8 +113,6 @@ static inline void *__container_of(void *ptr, unsigned long shift)#define _LIBCFS_Hvoid *libcfs_kvzalloc (size_t size,gfp_t flags); -void *libcfs_kvzalloc_cpt (struct cfs_cpt_table *cptab,int cpt,size_t size, -gfp_t flags);extern struct miscdevice libcfs_dev;/**
drivers/staging/lustre/lnet/libcfs/linux/linux-mem.c +0 -7
@@ -42,10 +42,3 @@ void *libcfs_kvzalloc(size_t size, gfp_t flags)return ret; }EXPORT_SYMBOL (libcfs_kvzalloc); - -void *libcfs_kvzalloc_cpt (struct cfs_cpt_table *cptab,int cpt,size_t size, -gfp_t flags) -{ -return kvzalloc_node (size, flags,cfs_cpt_spread_node (cptab, cpt)); -} -EXPORT_SYMBOL (libcfs_kvzalloc_cpt);
drivers/staging/lustre/lustre/ptlrpc/service.c +4 -4
@@ -83,10 +83,10 @@ ptlrpc_alloc_rqbd(struct ptlrpc_service_part *svcpt) rqbd->rqbd_cbid.cbid_fn = request_in_callback; rqbd->rqbd_cbid.cbid_arg = rqbd;INIT_LIST_HEAD (&rqbd->rqbd_reqs); - rqbd->rqbd_buffer =libcfs_kvzalloc_cpt (svc->srv_cptable, - svcpt->scp_cpt, - svc->srv_buf_size, -GFP_KERNEL ); + rqbd->rqbd_buffer =kvzalloc_node (svc->srv_buf_size,GFP_KERNEL , +cfs_cpt_spread_node (svc->srv_cptable, + svcpt->scp_cpt)); +if (!rqbd->rqbd_buffer) {kfree (rqbd);return NULL ;
PATCH 10/21 staging: lustre: discard lu_buf allocation library.
In reply to NeilBrownThis library code is unnecessarily generic, but also not generic enough. Library code that performs allocations should always take a gfp_flags argument.
So discard the library and in the one file where it is used, just use kzalloc or krealloc as needed.
In this context, it is clear that vmalloc is never needed.
--- drivers/staging/lustre/lustre/include/lu_object.h | 7 -- drivers/staging/lustre/lustre/llite/llite_lib.c | 2 - drivers/staging/lustre/lustre/obdclass/linkea.c | 16 +++-- drivers/staging/lustre/lustre/obdclass/lu_object.c | 70 -------------------- 4 files changed, 12 insertions(+), 83 deletions(-)
drivers/staging/lustre/lustre/include/lu_object.h +0 -7
@@ -1328,13 +1328,6 @@ struct lu_kmem_descr {int lu_kmem_init (struct lu_kmem_descr *caches);void lu_kmem_fini (struct lu_kmem_descr *caches); -void lu_buf_free (struct lu_buf *buf); -void lu_buf_alloc (struct lu_buf *buf,size_t size); -void lu_buf_realloc (struct lu_buf *buf,size_t size); - -int lu_buf_check_and_grow (struct lu_buf *buf,size_t len); -struct lu_buf *lu_buf_check_and_alloc (struct lu_buf *buf,size_t len); -extern __u32 lu_context_tags_default;extern __u32 lu_session_tags_default;
drivers/staging/lustre/lustre/llite/llite_lib.c +1 -1
@@ -2648,7 +2648,7 @@ int ll_getparent(struct file *file, struct getparent __user *arg) } lb_free: -lu_buf_free (&buf); +kvfree (buf.lb_buf); ldata_free:kfree (ldata);return rc;
drivers/staging/lustre/lustre/obdclass/linkea.c +11 -5
@@ -33,9 +33,11 @@int linkea_data_new (struct linkea_data *ldata,struct lu_buf *buf) { - ldata->ld_buf =lu_buf_check_and_alloc (buf,PAGE_SIZE ); -if (!ldata->ld_buf->lb_buf) + buf->lb_buf =kzalloc (PAGE_SIZE ,GFP_NOFS ); +if (!buf->lb_buf)return -ENOMEM ; + buf->lb_len =PAGE_SIZE ; + ldata->ld_buf = buf; ldata->ld_leh = ldata->ld_buf->lb_buf; ldata->ld_leh->leh_magic =LINK_EA_MAGIC ; ldata->ld_leh->leh_len =sizeof (struct link_ea_header );
@@ -158,11 +160,15 @@ int linkea_add_buf(struct linkea_data *ldata, const struct lu_name *lname, }if (leh->leh_len + reclen > ldata->ld_buf->lb_len) { -if (lu_buf_check_and_grow (ldata->ld_buf, - leh->leh_len + reclen) <0 ) +/* Note: this never happens as MAX_LINKEA_SIZE is 4096, while +* the initial allocation is PAGE_SIZE. +*/ +void *b =krealloc (ldata->ld_buf->lb_buf, leh->leh_len + reclen,GFP_NOFS ); +if (!b)return -ENOMEM ; - leh = ldata->ld_leh = ldata->ld_buf->lb_buf; + ldata->ld_buf->lb_len = leh->leh_len + reclen; + leh = ldata->ld_leh = ldata->ld_buf->lb_buf = b; } ldata->ld_lee = ldata->ld_buf->lb_buf + leh->leh_len;
drivers/staging/lustre/lustre/obdclass/lu_object.c +0 -70
73 lines not on this page · raw message
PATCH 11/21 staging: lustre: improve some libcfs_kvzalloc calls.
In reply to NeilBrownUsing vmalloc with GFP_NOFS is not supported as vmalloc performs some internal allocations with GFP_KERNEL.
So in cases where the size passed to libcfs_kvzalloc() is clearly at most 1 page, convert to kzalloc(). In cases where the call clearly doesn't hold any filesystem locks, convert to GFP_KERNEL.
Unfortunately there are many more that are not easy to fix.
--- drivers/staging/lustre/lustre/llite/dir.c | 2 +- drivers/staging/lustre/lustre/llite/file.c | 4 ++-- .../lustre/lustre/obdclass/linux/linux-module.c | 2 +- drivers/staging/lustre/lustre/obdclass/llog.c | 2 +- .../lustre/lustre/obdclass/lustre_handles.c | 2 +- drivers/staging/lustre/lustre/ptlrpc/client.c | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-)
drivers/staging/lustre/lustre/llite/dir.c +1 -1
@@ -1497,7 +1497,7 @@ static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)if (totalsize >=MDS_MAXREQSIZE /3 )return -E2BIG ; - hur =libcfs_kvzalloc (totalsize,GFP_NOFS ); + hur =kzalloc (totalsize,GFP_NOFS );if (!hur)return -ENOMEM ;
drivers/staging/lustre/lustre/llite/file.c +2 -2
@@ -1318,7 +1318,7 @@ static int ll_lov_setea(struct inode *inode, struct file *file,if (!capable (CAP_SYS_ADMIN ))return -EPERM ; - lump =libcfs_kvzalloc (lum_size,GFP_NOFS ); + lump =kzalloc (lum_size,GFP_NOFS );if (!lump)return -ENOMEM ;
@@ -2998,7 +2998,7 @@ static int ll_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, num_bytes =sizeof (*fiemap) + (extent_count *sizeof (struct fiemap_extent )); - fiemap =libcfs_kvzalloc (num_bytes,GFP_NOFS ); + fiemap =kvzalloc (num_bytes,GFP_KERNEL );if (!fiemap)return -ENOMEM ;
drivers/staging/lustre/lustre/obdclass/linux/linux-module.c +1 -1
@@ -180,7 +180,7 @@ int obd_ioctl_getdata(char **buf, int *len, void __user *arg)* obdfilter-survey is an example, which relies on ioctl. So we'd * better avoid vmalloc on ioctl path. LU-66 */ - *buf =libcfs_kvzalloc (hdr.ioc_len,GFP_NOFS ); + *buf =libcfs_kvzalloc (hdr.ioc_len,GFP_KERNEL );if (!*buf) {CERROR ("Cannot allocate control buffer of len %d\n" , hdr.ioc_len);
drivers/staging/lustre/lustre/obdclass/llog.c +1 -1
@@ -155,7 +155,7 @@ int llog_init_handle(const struct lu_env *env, struct llog_handle *handle,LASSERT (!handle->lgh_hdr);LASSERT (chunk_size >=LLOG_MIN_CHUNK_SIZE ); - llh =libcfs_kvzalloc (sizeof (*llh),GFP_NOFS ); + llh =libcfs_kvzalloc (sizeof (*llh),GFP_KERNEL );if (!llh)return -ENOMEM ; handle->lgh_hdr = llh;
drivers/staging/lustre/lustre/obdclass/lustre_handles.c +1 -1
@@ -185,7 +185,7 @@ int class_handle_init(void)LASSERT (!handle_hash); handle_hash =libcfs_kvzalloc (sizeof (*bucket) *HANDLE_HASH_SIZE , -GFP_NOFS ); +GFP_KERNEL );if (!handle_hash)return -ENOMEM ;
drivers/staging/lustre/lustre/ptlrpc/client.c +2 -2
@@ -544,10 +544,10 @@ int ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq)struct lustre_msg *msg;spin_unlock (&pool->prp_lock); - req =ptlrpc_request_cache_alloc (GFP_NOFS ); + req =ptlrpc_request_cache_alloc (GFP_KERNEL );if (!req)return i; - msg =libcfs_kvzalloc (size,GFP_NOFS ); + msg =libcfs_kvzalloc (size,GFP_KERNEL );if (!msg) {ptlrpc_request_cache_free (req);return i;
PATCH 12/21 staging: lustre: discard libcfs_kvzalloc and linux-mem.c
In reply to NeilBrownThe only interesting difference between libcfs_kvzalloc() and kvzalloc() is that the former appears to work with GFP_NOFS, which the latter gives a WARN_ON_ONCE() when that is attempted.
Each libcfs_kvzalloc() should really be analysed and either converted to a kzalloc() call if the size is never more than a page, or to use GFP_KERNEL if no locks are held.
If there is ever a case where locks are held and a large allocation is needed, then some other technique should be used.
It might be nice to not always blindly zero pages too...
For now, just convert libcfs_kvzalloc() calls to kvzalloc(), and let the warning remind us that there is work to do.
--- .../staging/lustre/include/linux/libcfs/libcfs.h | 2 - drivers/staging/lustre/lnet/libcfs/Makefile | 1 .../staging/lustre/lnet/libcfs/linux/linux-mem.c | 44 -------------------- drivers/staging/lustre/lustre/llite/file.c | 2 - drivers/staging/lustre/lustre/lmv/lmv_obd.c | 4 +- drivers/staging/lustre/lustre/lov/lov_ea.c | 2 - drivers/staging/lustre/lustre/lov/lov_io.c | 2 - drivers/staging/lustre/lustre/lov/lov_lock.c | 2 - drivers/staging/lustre/lustre/lov/lov_object.c | 4 +- drivers/staging/lustre/lustre/lov/lov_pack.c | 2 - drivers/staging/lustre/lustre/mdc/mdc_locks.c | 2 - .../lustre/lustre/obdclass/linux/linux-module.c | 2 - drivers/staging/lustre/lustre/obdclass/llog.c | 4 +- .../lustre/lustre/obdclass/lustre_handles.c | 2 - drivers/staging/lustre/lustre/ptlrpc/client.c | 2 - drivers/staging/lustre/lustre/ptlrpc/sec.c | 4 +- drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c | 2 - drivers/staging/lustre/lustre/ptlrpc/sec_null.c | 8 ++-- drivers/staging/lustre/lustre/ptlrpc/sec_plain.c | 8 ++-- drivers/staging/lustre/lustre/ptlrpc/service.c | 4 +- 20 files changed, 28 insertions(+), 75 deletions(-) delete mode 100644 drivers/staging/lustre/lnet/libcfs/linux/linux-mem.c
drivers/staging/lustre/include/linux/libcfs/libcfs.h +0 -2
@@ -112,8 +112,6 @@ static inline void *__container_of(void *ptr, unsigned long shift)#define _LIBCFS_H -void *libcfs_kvzalloc (size_t size,gfp_t flags); -extern struct miscdevice libcfs_dev;/** * The path of debug log dump upcall script.
drivers/staging/lustre/lnet/libcfs/Makefile +0 -1
@@ -9,7 +9,6 @@ libcfs-linux-objs += linux-cpu.o libcfs-linux-objs += linux-module.o libcfs-linux-objs += linux-crypto.o libcfs-linux-objs += linux-crypto-adler.o -libcfs-linux-objs += linux-mem.o libcfs-linux-objs := $(addprefix linux/,$(libcfs-linux-objs))
drivers/staging/lustre/lnet/libcfs/linux/linux-mem.c deleted +0 -44
44 lines not on this page · raw message
drivers/staging/lustre/lustre/llite/file.c +1 -1
@@ -3361,7 +3361,7 @@ static int ll_layout_fetch(struct inode *inode, struct ldlm_lock *lock) goto out; } - lvbdata =libcfs_kvzalloc (lmmsize,GFP_NOFS ); + lvbdata =kvzalloc (lmmsize,GFP_NOFS );if (!lvbdata) { rc = -ENOMEM ; goto out;
drivers/staging/lustre/lustre/lmv/lmv_obd.c +2 -2
@@ -1035,7 +1035,7 @@ static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp, reqlen = offsetof(typeof(*hur), hur_user_item[nr]) + hur->hur_request.hr_data_len; - req =libcfs_kvzalloc (reqlen,GFP_NOFS ); + req =kvzalloc (reqlen,GFP_NOFS );if (!req)return -ENOMEM ;
@@ -2733,7 +2733,7 @@ static int lmv_unpackmd(struct obd_export *exp, struct lmv_stripe_md **lsmp, lsm_size =lmv_stripe_md_size (0 );if (!lsm) { - lsm =libcfs_kvzalloc (lsm_size,GFP_NOFS ); + lsm =kvzalloc (lsm_size,GFP_NOFS );if (!lsm)return -ENOMEM ; allocated = true;
drivers/staging/lustre/lustre/lov/lov_ea.c +1 -1
@@ -89,7 +89,7 @@ struct lov_stripe_md *lsm_alloc_plain(u16 stripe_count) oinfo_ptrs_size =sizeof (struct lov_oinfo *) * stripe_count; lsm_size =sizeof (*lsm) + oinfo_ptrs_size; - lsm =libcfs_kvzalloc (lsm_size,GFP_NOFS ); + lsm =kvzalloc (lsm_size,GFP_NOFS );if (!lsm)return NULL ;
drivers/staging/lustre/lustre/lov/lov_io.c +1 -1
@@ -243,7 +243,7 @@ static int lov_io_subio_init(const struct lu_env *env, struct lov_io *lio,* when writing a page. -jay */ lio->lis_subs = -libcfs_kvzalloc (lsm->lsm_stripe_count * +kvzalloc (lsm->lsm_stripe_count *sizeof (lio->lis_subs[0 ]),GFP_NOFS );if (lio->lis_subs) {
drivers/staging/lustre/lustre/lov/lov_lock.c +1 -1
@@ -145,7 +145,7 @@ static struct lov_lock *lov_lock_sub_init(const struct lu_env *env, nr++; }LASSERT (nr >0 ); - lovlck = libcfs_kvzalloc(offsetof(struct lov_lock, lls_sub[nr]), + lovlck = kvzalloc(offsetof(struct lov_lock, lls_sub[nr]), GFP_NOFS);if (!lovlck)return ERR_PTR (-ENOMEM );
drivers/staging/lustre/lustre/lov/lov_object.c +2 -2
@@ -242,7 +242,7 @@ static int lov_init_raid0(const struct lu_env *env, struct lov_device *dev, r0->lo_nr = lsm->lsm_stripe_count;LASSERT (r0->lo_nr <=lov_targets_nr (dev)); - r0->lo_sub =libcfs_kvzalloc (r0->lo_nr *sizeof (r0->lo_sub[0 ]), + r0->lo_sub =kvzalloc (r0->lo_nr *sizeof (r0->lo_sub[0 ]),GFP_NOFS );if (r0->lo_sub) {int psz =0 ;
@@ -1375,7 +1375,7 @@ static int lov_object_fiemap(const struct lu_env *env, struct cl_object *obj,if (fiemap_count_to_size (fiemap->fm_extent_count) < buffer_size) buffer_size =fiemap_count_to_size (fiemap->fm_extent_count); - fm_local =libcfs_kvzalloc (buffer_size,GFP_NOFS ); + fm_local =kvzalloc (buffer_size,GFP_NOFS );if (!fm_local) { rc = -ENOMEM ; goto out;
drivers/staging/lustre/lustre/lov/lov_pack.c +1 -1
@@ -333,7 +333,7 @@ int lov_getstripe(struct lov_object *obj, struct lov_stripe_md *lsm, lmmk_size =lov_mds_md_size (stripe_count, lsm->lsm_magic); - lmmk =libcfs_kvzalloc (lmmk_size,GFP_NOFS ); + lmmk =kvzalloc (lmmk_size,GFP_NOFS );if (!lmmk) { rc = -ENOMEM ; goto out;
drivers/staging/lustre/lustre/mdc/mdc_locks.c +1 -1
@@ -660,7 +660,7 @@ static int mdc_finish_enqueue(struct obd_export *exp,LDLM_DEBUG (lock,"layout lock returned by: %s, lvb_len: %d" ,ldlm_it2str (it->it_op), lvb_len); - lmm =libcfs_kvzalloc (lvb_len,GFP_NOFS ); + lmm =kvzalloc (lvb_len,GFP_NOFS );if (!lmm) {LDLM_LOCK_PUT (lock);return -ENOMEM ;
drivers/staging/lustre/lustre/obdclass/linux/linux-module.c +1 -1
@@ -180,7 +180,7 @@ int obd_ioctl_getdata(char **buf, int *len, void __user *arg)* obdfilter-survey is an example, which relies on ioctl. So we'd * better avoid vmalloc on ioctl path. LU-66 */ - *buf =libcfs_kvzalloc (hdr.ioc_len,GFP_KERNEL ); + *buf =kvzalloc (hdr.ioc_len,GFP_KERNEL );if (!*buf) {CERROR ("Cannot allocate control buffer of len %d\n" , hdr.ioc_len);
drivers/staging/lustre/lustre/obdclass/llog.c +2 -2
@@ -155,7 +155,7 @@ int llog_init_handle(const struct lu_env *env, struct llog_handle *handle,LASSERT (!handle->lgh_hdr);LASSERT (chunk_size >=LLOG_MIN_CHUNK_SIZE ); - llh =libcfs_kvzalloc (sizeof (*llh),GFP_KERNEL ); + llh =kvzalloc (sizeof (*llh),GFP_KERNEL );if (!llh)return -ENOMEM ; handle->lgh_hdr = llh;
@@ -240,7 +240,7 @@ static int llog_process_thread(void *arg)/* expect chunk_size to be power of two */ LASSERT (is_power_of_2 (chunk_size)); - buf =libcfs_kvzalloc (chunk_size,GFP_NOFS ); + buf =kvzalloc (chunk_size,GFP_NOFS );if (!buf) { lpi->lpi_rc = -ENOMEM ;return 0 ;
drivers/staging/lustre/lustre/obdclass/lustre_handles.c +1 -1
@@ -184,7 +184,7 @@ int class_handle_init(void)LASSERT (!handle_hash); - handle_hash =libcfs_kvzalloc (sizeof (*bucket) *HANDLE_HASH_SIZE , + handle_hash =kvzalloc (sizeof (*bucket) *HANDLE_HASH_SIZE ,GFP_KERNEL );if (!handle_hash)return -ENOMEM ;
drivers/staging/lustre/lustre/ptlrpc/client.c +1 -1
@@ -547,7 +547,7 @@ int ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq) req =ptlrpc_request_cache_alloc (GFP_KERNEL );if (!req)return i; - msg =libcfs_kvzalloc (size,GFP_KERNEL ); + msg =kvzalloc (size,GFP_KERNEL );if (!msg) {ptlrpc_request_cache_free (req);return i;
drivers/staging/lustre/lustre/ptlrpc/sec.c +2 -2
@@ -442,7 +442,7 @@ int sptlrpc_req_ctx_switch(struct ptlrpc_request *req,/* save request message */ reqmsg_size = req->rq_reqlen;if (reqmsg_size !=0 ) { - reqmsg =libcfs_kvzalloc (reqmsg_size,GFP_NOFS ); + reqmsg =kvzalloc (reqmsg_size,GFP_NOFS );if (!reqmsg)return -ENOMEM ;memcpy (reqmsg, req->rq_reqmsg, reqmsg_size);
@@ -1089,7 +1089,7 @@ int sptlrpc_cli_unwrap_early_reply(struct ptlrpc_request *req, early_size = req->rq_nob_received; early_bufsz =size_roundup_power2 (early_size); - early_buf =libcfs_kvzalloc (early_bufsz,GFP_NOFS ); + early_buf =kvzalloc (early_bufsz,GFP_NOFS );if (!early_buf) { rc = -ENOMEM ; goto err_req;
drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c +1 -1
@@ -375,7 +375,7 @@ static inline void enc_pools_alloc(void) {LASSERT (page_pools.epp_max_pools); page_pools.epp_pools = -libcfs_kvzalloc (page_pools.epp_max_pools * +kvzalloc (page_pools.epp_max_pools *sizeof (*page_pools.epp_pools),GFP_NOFS ); }
drivers/staging/lustre/lustre/ptlrpc/sec_null.c +4 -4
@@ -158,7 +158,7 @@ int null_alloc_reqbuf(struct ptlrpc_sec *sec,int alloc_size =size_roundup_power2 (msgsize);LASSERT (!req->rq_pool); - req->rq_reqbuf =libcfs_kvzalloc (alloc_size,GFP_NOFS ); + req->rq_reqbuf =kvzalloc (alloc_size,GFP_NOFS );if (!req->rq_reqbuf)return -ENOMEM ;
@@ -201,7 +201,7 @@ int null_alloc_repbuf(struct ptlrpc_sec *sec, msgsize =size_roundup_power2 (msgsize); - req->rq_repbuf =libcfs_kvzalloc (msgsize,GFP_NOFS ); + req->rq_repbuf =kvzalloc (msgsize,GFP_NOFS );if (!req->rq_repbuf)return -ENOMEM ;
@@ -246,7 +246,7 @@ int null_enlarge_reqbuf(struct ptlrpc_sec *sec,if (req->rq_reqbuf_len < newmsg_size) { alloc_size =size_roundup_power2 (newmsg_size); - newbuf =libcfs_kvzalloc (alloc_size,GFP_NOFS ); + newbuf =kvzalloc (alloc_size,GFP_NOFS );if (!newbuf)return -ENOMEM ;
@@ -317,7 +317,7 @@ int null_alloc_rs(struct ptlrpc_request *req, int msgsize)/* pre-allocated */ LASSERT (rs->rs_size >= rs_size); }else { - rs =libcfs_kvzalloc (rs_size,GFP_NOFS ); + rs =kvzalloc (rs_size,GFP_NOFS );if (!rs)return -ENOMEM ;
drivers/staging/lustre/lustre/ptlrpc/sec_plain.c +4 -4
@@ -562,7 +562,7 @@ int plain_alloc_reqbuf(struct ptlrpc_sec *sec,LASSERT (!req->rq_pool); alloc_len =size_roundup_power2 (alloc_len); - req->rq_reqbuf =libcfs_kvzalloc (alloc_len,GFP_NOFS ); + req->rq_reqbuf =kvzalloc (alloc_len,GFP_NOFS );if (!req->rq_reqbuf)return -ENOMEM ;
@@ -620,7 +620,7 @@ int plain_alloc_repbuf(struct ptlrpc_sec *sec, alloc_len =size_roundup_power2 (alloc_len); - req->rq_repbuf =libcfs_kvzalloc (alloc_len,GFP_NOFS ); + req->rq_repbuf =kvzalloc (alloc_len,GFP_NOFS );if (!req->rq_repbuf)return -ENOMEM ;
@@ -671,7 +671,7 @@ int plain_enlarge_reqbuf(struct ptlrpc_sec *sec,if (req->rq_reqbuf_len < newbuf_size) { newbuf_size =size_roundup_power2 (newbuf_size); - newbuf =libcfs_kvzalloc (newbuf_size,GFP_NOFS ); + newbuf =kvzalloc (newbuf_size,GFP_NOFS );if (!newbuf)return -ENOMEM ;
@@ -808,7 +808,7 @@ int plain_alloc_rs(struct ptlrpc_request *req, int msgsize)/* pre-allocated */ LASSERT (rs->rs_size >= rs_size); }else { - rs =libcfs_kvzalloc (rs_size,GFP_NOFS ); + rs =kvzalloc (rs_size,GFP_NOFS );if (!rs)return -ENOMEM ;
drivers/staging/lustre/lustre/ptlrpc/service.c +2 -2
@@ -1068,7 +1068,7 @@ static int ptlrpc_at_send_early_reply(struct ptlrpc_request *req) reqcopy =ptlrpc_request_cache_alloc (GFP_NOFS );if (!reqcopy)return -ENOMEM ; - reqmsg =libcfs_kvzalloc (req->rq_reqlen,GFP_NOFS ); + reqmsg =kvzalloc (req->rq_reqlen,GFP_NOFS );if (!reqmsg) { rc = -ENOMEM ; goto out_free;
@@ -2077,7 +2077,7 @@ static int ptlrpc_main(void *arg) }/* Alloc reply state structure for this one */ - rs =libcfs_kvzalloc (svc->srv_max_reply_size,GFP_NOFS ); + rs =kvzalloc (svc->srv_max_reply_size,GFP_NOFS );if (!rs) { rc = -ENOMEM ; goto out_srv_fini;
PATCH 13/21 staging: lustre: remove phantom struct cfs_crypto_hash_desc
In reply to NeilBrownThere is no "struct cfs_crypto_hash_desc" structure. There are only pointers to this structure, which are cast back and forth to struct ahash_request.
So discard cfs_crypto_hash_desc, and just use ahash_request directly.
--- .../lustre/include/linux/libcfs/libcfs_crypto.h | 11 +++----- .../lustre/lnet/libcfs/linux/linux-crypto.c | 29 +++++++++----------- drivers/staging/lustre/lustre/osc/osc_request.c | 2 + drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c | 2 + 4 files changed, 19 insertions(+), 25 deletions(-)
drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h +4 -7
@@ -189,18 +189,15 @@ int cfs_crypto_hash_digest(enum cfs_crypto_hash_alg hash_alg, unsigned char *key, unsigned int key_len, unsigned char *hash, unsigned int *hash_len); -/* cfs crypto hash descriptor */ -struct cfs_crypto_hash_desc ; - -struct cfs_crypto_hash_desc * +struct ahash_request *cfs_crypto_hash_init (enum cfs_crypto_hash_alg hash_alg,unsigned char *key,unsigned int key_len); -int cfs_crypto_hash_update_page (struct cfs_crypto_hash_desc *desc, +int cfs_crypto_hash_update_page (struct ahash_request *desc,struct page *page,unsigned int offset,unsigned int len); -int cfs_crypto_hash_update (struct cfs_crypto_hash_desc *desc,const void *buf, +int cfs_crypto_hash_update (struct ahash_request *desc,const void *buf,unsigned int buf_len); -int cfs_crypto_hash_final (struct cfs_crypto_hash_desc *desc, +int cfs_crypto_hash_final (struct ahash_request *desc,unsigned char *hash,unsigned int *hash_len);int cfs_crypto_register (void );void cfs_crypto_unregister (void );
drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c +13 -16
@@ -42,7 +42,7 @@ static int cfs_crypto_hash_speeds[CFS_HASH_ALG_MAX];/** * Initialize the state descriptor for the specified hash algorithm. * -* An internal routine to allocate the hash-specific state in \a hdesc for +* An internal routine to allocate the hash-specific state in \a req for * use with cfs_crypto_hash_digest() to compute the hash of a single message, * though possibly in multiple chunks. The descriptor internal state should * be freed with cfs_crypto_hash_final().
@@ -50,7 +50,7 @@ static int cfs_crypto_hash_speeds[CFS_HASH_ALG_MAX];* \param[in] hash_alg hash algorithm id (CFS_HASH_ALG_*) * \param[out] type pointer to the hash description in hash_types[] * array -* \param[in,out] hdesc hash state descriptor to be initialized +* \param[in,out] req hash state descriptor to be initialized * \param[in] key initial hash value/state, NULL to use default * value * \param[in] key_len length of \a key
@@ -194,7 +194,7 @@ EXPORT_SYMBOL(cfs_crypto_hash_digest);* \retval pointer to descriptor of hash instance * \retval ERR_PTR(errno) in case of error */ -struct cfs_crypto_hash_desc * +struct ahash_request *cfs_crypto_hash_init (enum cfs_crypto_hash_alg hash_alg,unsigned char *key,unsigned int key_len) {
@@ -206,14 +206,14 @@ cfs_crypto_hash_init(enum cfs_crypto_hash_alg hash_alg,if (err)return ERR_PTR (err); -return (struct cfs_crypto_hash_desc *)req; +return req; }EXPORT_SYMBOL (cfs_crypto_hash_init);/** * Update hash digest computed on data within the given \a page * -* \param[in] hdesc hash state descriptor +* \param[in] hreq hash state descriptor * \param[in] page data page on which to compute the hash * \param[in] offset offset within \a page at which to start hash * \param[in] len length of data on which to compute hash
@@ -221,11 +221,10 @@ EXPORT_SYMBOL(cfs_crypto_hash_init);* \retval 0 for success * \retval negative errno on failure */ -int cfs_crypto_hash_update_page (struct cfs_crypto_hash_desc *hdesc, +int cfs_crypto_hash_update_page (struct ahash_request *req,struct page *page,unsigned int offset,unsigned int len) { -struct ahash_request *req = (void *)hdesc;struct scatterlist sl;sg_init_table (&sl,1 );
@@ -239,17 +238,16 @@ EXPORT_SYMBOL(cfs_crypto_hash_update_page);/** * Update hash digest computed on the specified data * -* \param[in] hdesc hash state descriptor +* \param[in] req hash state descriptor * \param[in] buf data buffer on which to compute the hash * \param[in] buf_len length of \buf on which to compute hash * * \retval 0 for success * \retval negative errno on failure */ -int cfs_crypto_hash_update (struct cfs_crypto_hash_desc *hdesc, +int cfs_crypto_hash_update (struct ahash_request *req,const void *buf,unsigned int buf_len) { -struct ahash_request *req = (void *)hdesc;struct scatterlist sl;sg_init_one (&sl, buf, buf_len);
@@ -262,20 +260,19 @@ EXPORT_SYMBOL(cfs_crypto_hash_update);/** * Finish hash calculation, copy hash digest to buffer, clean up hash descriptor * -* \param[in] hdesc hash descriptor +* \param[in] req hash descriptor * \param[out] hash pointer to hash buffer to store hash digest -* \param[in,out] hash_len pointer to hash buffer size, if \a hdesc = NULL -* only free \a hdesc instead of computing the hash +* \param[in,out] hash_len pointer to hash buffer size, if \a req = NULL +* only free \a req instead of computing the hash * * \retval 0 for success * \retval -EOVERFLOW if hash_len is too small for the hash digest * \retval negative errno for other errors from lower layers */ -int cfs_crypto_hash_final (struct cfs_crypto_hash_desc *hdesc, +int cfs_crypto_hash_final (struct ahash_request *req,unsigned char *hash,unsigned int *hash_len) {int err; -struct ahash_request *req = (void *)hdesc;int size =crypto_ahash_digestsize (crypto_ahash_reqtfm (req));if (!hash || !hash_len) {
@@ -331,7 +328,7 @@ static void cfs_crypto_performance_test(enum cfs_crypto_hash_alg hash_alg)for (start = jiffies, end = start +msecs_to_jiffies (MSEC_PER_SEC ), bcount =0 ;time_before (jiffies, end); bcount++) { -struct cfs_crypto_hash_desc *hdesc; +struct ahash_request *hdesc;int i; hdesc =cfs_crypto_hash_init (hash_alg,NULL ,0 );
drivers/staging/lustre/lustre/osc/osc_request.c +1 -1
@@ -931,7 +931,7 @@ static u32 osc_checksum_bulk(int nob, u32 pg_count, {__u32 cksum;int i =0 ; -struct cfs_crypto_hash_desc *hdesc; +struct ahash_request *hdesc;unsigned int bufsize;unsigned char cfs_alg =cksum_obd2cfs (cksum_type);
drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c +1 -1
@@ -530,7 +530,7 @@ EXPORT_SYMBOL(bulk_sec_desc_unpack);int sptlrpc_get_bulk_checksum (struct ptlrpc_bulk_desc *desc,__u8 alg,void *buf,int buflen) { -struct cfs_crypto_hash_desc *hdesc; +struct ahash_request *hdesc;int hashsize;unsigned int bufsize;int i, err;
PATCH 14/21 staging: lustre: fix assorted checkpatch errors
In reply to NeilBrownPossible the most interesting is the for-loop with no body. I think it reads better as a while loop.
--- .../lustre/lnet/klnds/socklnd/socklnd_lib.c | 2 +- .../staging/lustre/lnet/libcfs/linux/linux-cpu.c | 2 +- drivers/staging/lustre/lustre/include/obd_class.h | 8 ++++---- .../staging/lustre/lustre/include/obd_support.h | 2 +- drivers/staging/lustre/lustre/llite/dcache.c | 2 +- drivers/staging/lustre/lustre/llite/llite_lib.c | 2 +- drivers/staging/lustre/lustre/lov/lov_request.c | 2 +- drivers/staging/lustre/lustre/mdc/mdc_request.c | 6 ++++-- drivers/staging/lustre/lustre/ptlrpc/layout.c | 2 +- drivers/staging/lustre/lustre/ptlrpc/recover.c | 2 +- drivers/staging/lustre/lustre/ptlrpc/service.c | 2 +- 11 files changed, 17 insertions(+), 15 deletions(-)
drivers/staging/lustre/lnet/klnds/socklnd/socklnd_lib.c +1 -1
@@ -189,7 +189,7 @@ ksocknal_lib_recv(struct ksock_conn *conn)if (!(conn->ksnc_rx_to.type &ITER_BVEC ) && conn->ksnc_proto != &ksocknal_protocol_v2x)return rc; - +/* accumulate checksum */ conn->ksnc_msg.ksm_csum =0 ;iov_iter_for_each_range (&conn->ksnc_rx_to, rc, lustre_csum, conn);
drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c +1 -1
@@ -743,7 +743,7 @@ cfs_cpt_table_create(int ncpt) goto failed; } -if (!zalloc_cpumask_var (&mask,GFP_NOFS )){ +if (!zalloc_cpumask_var (&mask,GFP_NOFS )) {CERROR ("Failed to allocate scratch cpumask\n" ); goto failed; }
drivers/staging/lustre/lustre/include/obd_class.h +4 -4
@@ -294,10 +294,10 @@ struct obdo;void obdo_to_ioobj (const struct obdo *oa,struct obd_ioobj *ioobj); -#define OBT (dev) (dev)->obd_type -#define OBP (dev, op) (dev)->obd_type->typ_dt_ops->op -#define MDP (dev, op) (dev)->obd_type->typ_md_ops->op -#define CTXTP (ctxt, op) (ctxt)->loc_logops->lop_##op +#define OBT (dev) ((dev)->obd_type) +#define OBP (dev, op) ((dev)->obd_type->typ_dt_ops->op) +#define MDP (dev, op) ((dev)->obd_type->typ_md_ops->op) +#define CTXTP (ctxt, op) ((ctxt)->loc_logops->lop_##op)/* * Ensure obd_setup: used for cleanup which must be called
drivers/staging/lustre/lustre/include/obd_support.h +1 -1
@@ -516,7 +516,7 @@ extern char obd_jobid_var[];#define POISON_PTR (ptr) ((void)0)#else #define POISON (ptr, c, s) memset(ptr, c, s) -#define POISON_PTR (ptr) (ptr) = (void *)0xdeadbeef +#define POISON_PTR (ptr) ((ptr) = (void *)0xdeadbeef)#endif #ifdef POISON_BULK
drivers/staging/lustre/lustre/llite/dcache.c +1 -1
@@ -100,7 +100,7 @@ static int ll_dcompare(const struct dentry *dentry,return 0 ;/* ensure exclusion against parallel lookup of the same name */ -if (d_in_lookup ((struct dentry *)dentry)) +if (d_in_lookup ((struct dentry *)dentry))return 0 ;if (d_lustre_invalid (dentry))
drivers/staging/lustre/lustre/llite/llite_lib.c +1 -1
@@ -2022,7 +2022,7 @@ void ll_umount_begin(struct super_block *sb)*/ while (cnt <10 && !may_umount (sbi->ll_mnt.mnt)) {schedule_timeout_uninterruptible (HZ ); - cnt ++; + cnt++; }schedule ();
drivers/staging/lustre/lustre/lov/lov_request.c +1 -1
@@ -126,7 +126,7 @@ static int lov_check_and_wait_active(struct lov_obd *lov, int ost_idx)while (cnt < obd_timeout && !lov_check_set (lov, ost_idx)) {schedule_timeout_uninterruptible (HZ ); - cnt ++; + cnt++; }if (tgt->ltd_active)return 1 ;
drivers/staging/lustre/lustre/mdc/mdc_request.c +4 -2
@@ -1060,8 +1060,10 @@ static void mdc_adjust_dirpages(struct page **pages, int cfs_pgs, int lu_pgs)while (--lu_pgs >0 ) { ent =lu_dirent_start (dp); -for (end_dirent = ent; ent; - end_dirent = ent, ent =lu_dirent_next (ent)); +while (ent) { + end_dirent = ent; + ent =lu_dirent_next (ent); + }/* Advance dp to next lu_dirpage. */ dp = (struct lu_dirpage *)((char *)dp +LU_PAGE_SIZE );
drivers/staging/lustre/lustre/ptlrpc/layout.c +1 -1
@@ -1555,7 +1555,7 @@ struct req_format RQF_OST_GET_INFO_FIEMAP =EXPORT_SYMBOL (RQF_OST_GET_INFO_FIEMAP );/* Convenience macro */ -#define FMT_FIELD (fmt, i, j) (fmt)->rf_fields[(i)].d[(j)] +#define FMT_FIELD (fmt, i, j) ((fmt)->rf_fields[(i)].d[(j)])/** * Initializes the capsule abstraction by computing and setting the \a rf_idx
drivers/staging/lustre/lustre/ptlrpc/recover.c +1 -1
@@ -354,7 +354,7 @@ int ptlrpc_recover_import(struct obd_import *imp, char *new_uuid, int async) obd_timeout * HZ);CDEBUG (D_HA ,"%s: recovery finished\n" ,obd2cli_tgt (imp->imp_obd)); - rc = rc?0 : -ETIMEDOUT ; + rc = rc ?0 : -ETIMEDOUT ; } out:
drivers/staging/lustre/lustre/ptlrpc/service.c +1 -1
@@ -2670,7 +2670,7 @@ ptlrpc_service_unlink_rqbd(struct ptlrpc_service *svc) (rc =wait_event_idle_timeout (svcpt->scp_waitq, svcpt->scp_nrqbds_posted ==0 , HZ)) == 0) - cnt ++; + cnt++;if (rc ==0 ) {CWARN ("Service %s waiting for request buffers\n" , svcpt->scp_service->srv_name);
RE: [lustre-devel] [PATCH 14/21] staging: lustre: fix assorted checkpatch errors
Hello Neil,
Quoted 18 lines
drivers/staging/lustre/lustre/mdc/mdc_request.c +4
-2@@ -1060,8 +1060,10 @@ static void mdc_adjust_dirpages(struct page **pages, int cfs_pgs, int lu_pgs)while (--lu_pgs >0 ) { ent =lu_dirent_start (dp); -for (end_dirent = ent; ent; - end_dirent = ent, ent =lu_dirent_next (ent)); +while (ent) { + end_dirent = ent; + ent =lu_dirent_next (ent); + }/* Advance dp to next lu_dirpage. */
Quoted 1 line
dp = (struct
lu_dirpage*)((char *)dp +LU_PAGE_SIZE);
I doubt this is correct replacement. In original code end_dirent is set always in the begin of outer loop (while (--lu_pgs > 0)). But in new code this is missed. Therefore in case of second iteration and (ent = lu_dirent_start(dp)) == NULL the end_dirent will contain a value from previous iteration which is not correct.
Dmitry.
--------------------------------------------------------------------
Joint Stock Company Intel A/O
Registered legal address: Krylatsky Hills Business Park, 17 Krylatskaya Str., Bldg 4, Moscow 121614, Russian Federation
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
RE: [lustre-devel] [PATCH 14/21] staging: lustre: fix assorted checkpatch errors
Quoted 19 lines · Dmitry
Hello Neil,
Quoted 17 lines
drivers/staging/lustre/lustre/mdc/mdc_request.c +4
-2@@ -1060,8 +1060,10 @@ static void mdc_adjust_dirpages(struct page **pages, int cfs_pgs, int lu_pgs)while (--lu_pgs >0 ) { ent =lu_dirent_start (dp); -for (end_dirent = ent; ent; - end_dirent = ent, ent =lu_dirent_next (ent)); +while (ent) { + end_dirent = ent; + ent =lu_dirent_next (ent); + }
Quoted 8 lines
Quoted 2 lines
drivers/staging/lustre/lustre/mdc/mdc_request.c +0
-0/* Advance dp to next lu_dirpage. */ dp = (struct
lu_dirpage*)((char *)dp +LU_PAGE_SIZE);I doubt this is correct replacement. In original code
end_direntis set always in the begin of outer loop (while (--lu_pgs > 0)). But in new code this is missed. Therefore in case of second iteration and (ent =lu_dirent_start(dp)) == NULL theend_direntwill contain a value from previous iteration which is not correct.
Thanks for the review. Yes, you are correct.
I had seen that end_dirent was initialized to NULL, and let myself believe that would make the transformation safe.
In fact, that initialization to NULL is pointless as it is never used.
Maybe this would be better
@@ -1055,13 +1055,14 @@ static void mdc_adjust_dirpages(struct page **pages, int cfs_pgs, int lu_pgs)
__u64 hash_end = le64_to_cpu(dp->ldp_hash_end);
__u32 flags = le32_to_cpu(dp->ldp_flags);
struct lu_dirpage *first = dp;
- struct lu_dirent *end_dirent = NULL;
- struct lu_dirent *ent;
while (--lu_pgs > 0) {
- ent = lu_dirent_start(dp);
- for (end_dirent = ent; ent;
- end_dirent = ent, ent = lu_dirent_next(ent));
+ struct lu_dirent *end_dirent = NULL;
+ struct lu_dirent *ent;
+
+ for (ent = lu_dirent_start(dp); ent;
+ ent = lu_dirent_next(ent))
+ end_dirent = ent;
/* Advance dp to next lu_dirpage. */
dp = (struct lu_dirpage *)((char *)dp + LU_PAGE_SIZE);
??
Thanks,
NeilBrown
RE: [lustre-devel] [PATCH 14/21] staging: lustre: fix assorted checkpatch errors
Quoted 28 lines
-----Original Message-----
Thanks for the review. Yes, you are correct.
I had seen thatend_direntwas initialized to NULL, and let myself believe that would make the transformation safe.
In fact, that initialization to NULL is pointless as it is never used.Maybe this would be better
(quoted diff) +6
-5@@ -1055,13 +1055,14 @@ static void mdc_adjust_dirpages(struct page **pages, int cfs_pgs, int lu_pgs) __u64 hash_end = le64_to_cpu(dp->ldp_hash_end); __u32 flags = le32_to_cpu(dp->ldp_flags); struct lu_dirpage *first = dp; - struct lu_dirent *end_dirent = NULL; - struct lu_dirent *ent; while (--lu_pgs > 0) { - ent = lu_dirent_start(dp); - for (end_dirent = ent; ent; - end_dirent = ent, ent = lu_dirent_next(ent)); + struct lu_dirent *end_dirent = NULL; + struct lu_dirent *ent; + + for (ent = lu_dirent_start(dp); ent; + ent = lu_dirent_next(ent)) + end_dirent = ent; /* Advance dp to next lu_dirpage. */
Quoted 2 lines
dp = (struct
lu_dirpage*)((char *)dp +LU_PAGE_SIZE);
??
Thanks, I agree with this version.
Dmitry.
--------------------------------------------------------------------
Joint Stock Company Intel A/O
Registered legal address: Krylatsky Hills Business Park, 17 Krylatskaya Str., Bldg 4, Moscow 121614, Russian Federation
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
PATCH v2 14/21 staging: lustre: fix assorted checkpatch errors
In reply to NeilBrownPossibly the most interesting is the for-loop with no body. Rearranging and initializing end_dirent on each iteration of the outer while, makes the intent clearer.
---
This version has a correct conversion for that for loop with not body, thanks Dmitry!
drivers/staging/lustre/lnet/klnds/socklnd/socklnd_lib.c | 2 +- drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c | 2 +- drivers/staging/lustre/lustre/include/obd_class.h | 8 ++++---- drivers/staging/lustre/lustre/include/obd_support.h | 2 +- drivers/staging/lustre/lustre/llite/dcache.c | 2 +- drivers/staging/lustre/lustre/llite/llite_lib.c | 2 +- drivers/staging/lustre/lustre/lov/lov_request.c | 2 +- drivers/staging/lustre/lustre/mdc/mdc_request.c | 11 ++++++----- drivers/staging/lustre/lustre/ptlrpc/layout.c | 2 +- drivers/staging/lustre/lustre/ptlrpc/recover.c | 2 +- drivers/staging/lustre/lustre/ptlrpc/service.c | 2 +- 11 files changed, 19 insertions(+), 18 deletions(-)
drivers/staging/lustre/lnet/klnds/socklnd/socklnd_lib.c +1 -1
@@ -189,7 +189,7 @@ ksocknal_lib_recv(struct ksock_conn *conn)if (!(conn->ksnc_rx_to.type &ITER_BVEC ) && conn->ksnc_proto != &ksocknal_protocol_v2x)return rc; - +/* accumulate checksum */ conn->ksnc_msg.ksm_csum =0 ;iov_iter_for_each_range (&conn->ksnc_rx_to, rc, lustre_csum, conn);
drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c +1 -1
@@ -743,7 +743,7 @@ cfs_cpt_table_create(int ncpt) goto failed; } -if (!zalloc_cpumask_var (&mask,GFP_NOFS )){ +if (!zalloc_cpumask_var (&mask,GFP_NOFS )) {CERROR ("Failed to allocate scratch cpumask\n" ); goto failed; }
drivers/staging/lustre/lustre/include/obd_class.h +4 -4
@@ -294,10 +294,10 @@ struct obdo;void obdo_to_ioobj (const struct obdo *oa,struct obd_ioobj *ioobj); -#define OBT (dev) (dev)->obd_type -#define OBP (dev, op) (dev)->obd_type->typ_dt_ops->op -#define MDP (dev, op) (dev)->obd_type->typ_md_ops->op -#define CTXTP (ctxt, op) (ctxt)->loc_logops->lop_##op +#define OBT (dev) ((dev)->obd_type) +#define OBP (dev, op) ((dev)->obd_type->typ_dt_ops->op) +#define MDP (dev, op) ((dev)->obd_type->typ_md_ops->op) +#define CTXTP (ctxt, op) ((ctxt)->loc_logops->lop_##op)/* * Ensure obd_setup: used for cleanup which must be called
drivers/staging/lustre/lustre/include/obd_support.h +1 -1
@@ -516,7 +516,7 @@ extern char obd_jobid_var[];#define POISON_PTR (ptr) ((void)0)#else #define POISON (ptr, c, s) memset(ptr, c, s) -#define POISON_PTR (ptr) (ptr) = (void *)0xdeadbeef +#define POISON_PTR (ptr) ((ptr) = (void *)0xdeadbeef)#endif #ifdef POISON_BULK
drivers/staging/lustre/lustre/llite/dcache.c +1 -1
@@ -100,7 +100,7 @@ static int ll_dcompare(const struct dentry *dentry,return 0 ;/* ensure exclusion against parallel lookup of the same name */ -if (d_in_lookup ((struct dentry *)dentry)) +if (d_in_lookup ((struct dentry *)dentry))return 0 ;if (d_lustre_invalid (dentry))
drivers/staging/lustre/lustre/llite/llite_lib.c +1 -1
@@ -2022,7 +2022,7 @@ void ll_umount_begin(struct super_block *sb)*/ while (cnt <10 && !may_umount (sbi->ll_mnt.mnt)) {schedule_timeout_uninterruptible (HZ ); - cnt ++; + cnt++; }schedule ();
drivers/staging/lustre/lustre/lov/lov_request.c +1 -1
@@ -126,7 +126,7 @@ static int lov_check_and_wait_active(struct lov_obd *lov, int ost_idx)while (cnt < obd_timeout && !lov_check_set (lov, ost_idx)) {schedule_timeout_uninterruptible (HZ ); - cnt ++; + cnt++; }if (tgt->ltd_active)return 1 ;
drivers/staging/lustre/lustre/mdc/mdc_request.c +6 -5
@@ -1055,13 +1055,14 @@ static void mdc_adjust_dirpages(struct page **pages, int cfs_pgs, int lu_pgs)__u64 hash_end =le64_to_cpu (dp->ldp_hash_end);__u32 flags =le32_to_cpu (dp->ldp_flags);struct lu_dirpage *first = dp; -struct lu_dirent *end_dirent =NULL ; -struct lu_dirent *ent;while (--lu_pgs >0 ) { - ent =lu_dirent_start (dp); -for (end_dirent = ent; ent; - end_dirent = ent, ent =lu_dirent_next (ent)); +struct lu_dirent *end_dirent =NULL ; +struct lu_dirent *ent; + +for (ent =lu_dirent_start (dp); ent; + ent =lu_dirent_next (ent)) + end_dirent = ent;/* Advance dp to next lu_dirpage. */ dp = (struct lu_dirpage *)((char *)dp +LU_PAGE_SIZE );
drivers/staging/lustre/lustre/ptlrpc/layout.c +1 -1
@@ -1555,7 +1555,7 @@ struct req_format RQF_OST_GET_INFO_FIEMAP =EXPORT_SYMBOL (RQF_OST_GET_INFO_FIEMAP );/* Convenience macro */ -#define FMT_FIELD (fmt, i, j) (fmt)->rf_fields[(i)].d[(j)] +#define FMT_FIELD (fmt, i, j) ((fmt)->rf_fields[(i)].d[(j)])/** * Initializes the capsule abstraction by computing and setting the \a rf_idx
drivers/staging/lustre/lustre/ptlrpc/recover.c +1 -1
@@ -354,7 +354,7 @@ int ptlrpc_recover_import(struct obd_import *imp, char *new_uuid, int async) obd_timeout * HZ);CDEBUG (D_HA ,"%s: recovery finished\n" ,obd2cli_tgt (imp->imp_obd)); - rc = rc?0 : -ETIMEDOUT ; + rc = rc ?0 : -ETIMEDOUT ; } out:
drivers/staging/lustre/lustre/ptlrpc/service.c +1 -1
@@ -2670,7 +2670,7 @@ ptlrpc_service_unlink_rqbd(struct ptlrpc_service *svc) (rc =wait_event_idle_timeout (svcpt->scp_waitq, svcpt->scp_nrqbds_posted ==0 , HZ)) == 0) - cnt ++; + cnt++;if (rc ==0 ) {CWARN ("Service %s waiting for request buffers\n" , svcpt->scp_service->srv_name);
Signature · 1 line
2.14.0.rc0.dirty
PATCH 15/21 staging: lustre: ptlrpc: list_for_each improvements.
In reply to NeilBrown1/ use list_for_each_entry_safe() instead of
list_for_each_safe() and similar.
2/ use list_first_entry() and list_last_entry() where appropriate.
3/ When removing everything from a list, use
while ((x = list_first_entry_or_null()) {as it makes the intent clear
4/ No need to take a spinlock in a structure that is about
to be freed - we must have exclusive access at this stage.
--- drivers/staging/lustre/lustre/ptlrpc/client.c | 89 +++++++----------------- drivers/staging/lustre/lustre/ptlrpc/import.c | 34 +++------ drivers/staging/lustre/lustre/ptlrpc/pinger.c | 8 +- drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c | 15 +--- drivers/staging/lustre/lustre/ptlrpc/recover.c | 26 +++---- drivers/staging/lustre/lustre/ptlrpc/service.c | 13 +--- 6 files changed, 59 insertions(+), 126 deletions(-)
drivers/staging/lustre/lustre/ptlrpc/client.c +25 -64
@@ -504,19 +504,16 @@ void ptlrpc_request_cache_free(struct ptlrpc_request *req)*/ void ptlrpc_free_rq_pool (struct ptlrpc_request_pool *pool) { -struct list_head *l, *tmp;struct ptlrpc_request *req; -spin_lock (&pool->prp_lock); -list_for_each_safe (l, tmp, &pool->prp_req_list) { - req = list_entry(l, struct ptlrpc_request, rq_list); +while ((req =list_first_entry_or_null (&pool->prp_req_list, + struct ptlrpc_request, rq_list))) {list_del (&req->rq_list);LASSERT (req->rq_reqbuf);LASSERT (req->rq_reqbuf_len == pool->prp_rq_size);kvfree (req->rq_reqbuf);ptlrpc_request_cache_free (req); } -spin_unlock (&pool->prp_lock);kfree (pool); }EXPORT_SYMBOL (ptlrpc_free_rq_pool);
@@ -656,16 +653,13 @@ static void __ptlrpc_free_req_to_pool(struct ptlrpc_request *request)void ptlrpc_add_unreplied (struct ptlrpc_request *req) {struct obd_import *imp = req->rq_import; -struct list_head *tmp;struct ptlrpc_request *iter;assert_spin_locked (&imp->imp_lock);LASSERT (list_empty (&req->rq_unreplied_list));/* unreplied list is sorted by xid in ascending order */ -list_for_each_prev (tmp, &imp->imp_unreplied_list) { - iter = list_entry(tmp, struct ptlrpc_request, - rq_unreplied_list); +list_for_each_entry_reverse (iter, &imp->imp_unreplied_list, rq_unreplied_list) {LASSERT (req->rq_xid != iter->rq_xid);if (req->rq_xid < iter->rq_xid)
@@ -1001,18 +995,14 @@ struct ptlrpc_request_set *ptlrpc_prep_fcset(int max, set_producer_func func,*/ void ptlrpc_set_destroy (struct ptlrpc_request_set *set) { -struct list_head *tmp; -struct list_head *next; +struct ptlrpc_request *req;int expected_phase;int n =0 ;/* Requests on the set should either all be completed, or all be new */ expected_phase = (atomic_read (&set->set_remaining) ==0 ) ?RQ_PHASE_COMPLETE :RQ_PHASE_NEW ; -list_for_each (tmp, &set->set_requests) { -struct ptlrpc_request *req = - list_entry(tmp, struct ptlrpc_request, rq_set_chain); - +list_for_each_entry (req, &set->set_requests, rq_set_chain) {LASSERT (req->rq_phase == expected_phase); n++; }
@@ -1021,9 +1011,9 @@ void ptlrpc_set_destroy(struct ptlrpc_request_set *set)atomic_read (&set->set_remaining) == n,"%d / %d\n" , atomic_read(&set->set_remaining), n); -list_for_each_safe (tmp, next, &set->set_requests) { -struct ptlrpc_request *req = - list_entry(tmp, struct ptlrpc_request, rq_set_chain); +while ((req =list_first_entry_or_null (&set->set_requests, + struct ptlrpc_request, + rq_set_chain))) {list_del_init (&req->rq_set_chain);LASSERT (req->rq_phase == expected_phase);
@@ -1640,7 +1630,7 @@ static inline int ptlrpc_set_producer(struct ptlrpc_request_set *set)*/ int ptlrpc_check_set (const struct lu_env *env,struct ptlrpc_request_set *set) { -struct list_head *tmp, *next; +struct ptlrpc_request *req, *next;struct list_head comp_reqs;int force_timer_recalc =0 ;
@@ -1648,9 +1638,7 @@ int ptlrpc_check_set(const struct lu_env *env, struct ptlrpc_request_set *set)return 1 ;INIT_LIST_HEAD (&comp_reqs); -list_for_each_safe (tmp, next, &set->set_requests) { -struct ptlrpc_request *req = - list_entry(tmp, struct ptlrpc_request, rq_set_chain); +list_for_each_entry_safe (req, next, &set->set_requests, rq_set_chain) {struct obd_import *imp = req->rq_import;int unregistered =0 ;int rc =0 ;
@@ -2126,13 +2114,11 @@ int ptlrpc_expire_one_request(struct ptlrpc_request *req, int async_unlink)*/ void ptlrpc_expired_set (struct ptlrpc_request_set *set) { -struct list_head *tmp; +struct ptlrpc_request *req;time64_t now =ktime_get_real_seconds ();/* A timeout expired. See which reqs it applies to... */ -list_for_each (tmp, &set->set_requests) { -struct ptlrpc_request *req = - list_entry(tmp, struct ptlrpc_request, rq_set_chain); +list_for_each_entry (req, &set->set_requests, rq_set_chain) {/* don't expire request waiting for context */ if (req->rq_wait_ctx)
@@ -2173,13 +2159,10 @@ EXPORT_SYMBOL(ptlrpc_mark_interrupted);*/ static void ptlrpc_interrupted_set (struct ptlrpc_request_set *set) { -struct list_head *tmp; - +struct ptlrpc_request *req;CDEBUG (D_RPCTRACE ,"INTERRUPTED SET %p\n" , set); -list_for_each (tmp, &set->set_requests) { -struct ptlrpc_request *req = - list_entry(tmp, struct ptlrpc_request, rq_set_chain); +list_for_each_entry (req, &set->set_requests, rq_set_chain) {if (req->rq_phase !=RQ_PHASE_RPC && req->rq_phase !=RQ_PHASE_UNREG_RPC )
@@ -2194,14 +2177,12 @@ static void ptlrpc_interrupted_set(struct ptlrpc_request_set *set)*/ int ptlrpc_set_next_timeout (struct ptlrpc_request_set *set) { -struct list_head *tmp;time64_t now =ktime_get_real_seconds ();int timeout =0 ;struct ptlrpc_request *req;time64_t deadline; -list_for_each (tmp, &set->set_requests) { - req = list_entry(tmp, struct ptlrpc_request, rq_set_chain); +list_for_each_entry (req, &set->set_requests, rq_set_chain) {/* Request in-flight? */ if (!(((req->rq_phase == RQ_PHASE_RPC) && !req->rq_waiting) ||
@@ -2240,16 +2221,13 @@ int ptlrpc_set_next_timeout(struct ptlrpc_request_set *set)*/ int ptlrpc_set_wait (struct ptlrpc_request_set *set) { -struct list_head *tmp;struct ptlrpc_request *req;int rc, timeout;if (set->set_producer) (void )ptlrpc_set_producer (set);else -list_for_each (tmp, &set->set_requests) { - req = list_entry(tmp, struct ptlrpc_request, - rq_set_chain); +list_for_each_entry (req, &set->set_requests, rq_set_chain) {if (req->rq_phase ==RQ_PHASE_NEW ) (void )ptlrpc_send_new_req (req); }
@@ -2322,9 +2300,7 @@ int ptlrpc_set_wait(struct ptlrpc_request_set *set)* the error cases -eeb. */ if (rc ==0 &&atomic_read (&set->set_remaining) ==0 ) { -list_for_each (tmp, &set->set_requests) { - req = list_entry(tmp, struct ptlrpc_request, - rq_set_chain); +list_for_each_entry (req, &set->set_requests, rq_set_chain) {spin_lock (&req->rq_lock); req->rq_invalid_rqset =1 ;spin_unlock (&req->rq_lock);
@@ -2335,9 +2311,7 @@ int ptlrpc_set_wait(struct ptlrpc_request_set *set)LASSERT (atomic_read (&set->set_remaining) ==0 ); rc = set->set_rc;/* rq_status of already freed requests if any */ -list_for_each (tmp, &set->set_requests) { - req = list_entry(tmp, struct ptlrpc_request, rq_set_chain); - +list_for_each_entry (req, &set->set_requests, rq_set_chain) {LASSERT (req->rq_phase ==RQ_PHASE_COMPLETE );if (req->rq_status !=0 ) rc = req->rq_status;
@@ -2716,8 +2690,7 @@ EXPORT_SYMBOL(ptlrpc_request_addref);void ptlrpc_retain_replayable_request (struct ptlrpc_request *req,struct obd_import *imp) { -struct list_head *tmp; - +struct ptlrpc_request *iter;assert_spin_locked (&imp->imp_lock);if (req->rq_transno ==0 ) {
@@ -2744,10 +2717,7 @@ void ptlrpc_retain_replayable_request(struct ptlrpc_request *req,LASSERT (imp->imp_replayable);/* Balanced in ptlrpc_free_committed, usually. */ ptlrpc_request_addref (req); -list_for_each_prev (tmp, &imp->imp_replay_list) { -struct ptlrpc_request *iter = - list_entry(tmp, struct ptlrpc_request, rq_replay_list); - +list_for_each_entry_reverse (iter, &imp->imp_replay_list, rq_replay_list) {/* * We may have duplicate transnos if we create and then * open a file, or for closes retained if to match creating
@@ -2955,7 +2925,7 @@ int ptlrpc_replay_req(struct ptlrpc_request *req)*/ void ptlrpc_abort_inflight (struct obd_import *imp) { -struct list_head *tmp, *n; +struct ptlrpc_request *req, *n;/* * Make sure that no new requests get processed for this import.
@@ -2969,10 +2939,7 @@ void ptlrpc_abort_inflight(struct obd_import *imp)* locked? Also, how do we know if the requests on the list are * being freed at this time? */ -list_for_each_safe (tmp, n, &imp->imp_sending_list) { -struct ptlrpc_request *req = - list_entry(tmp, struct ptlrpc_request, rq_list); - +list_for_each_entry_safe (req, n, &imp->imp_sending_list, rq_list) {DEBUG_REQ (D_RPCTRACE , req,"inflight" );spin_lock (&req->rq_lock);
@@ -2984,10 +2951,7 @@ void ptlrpc_abort_inflight(struct obd_import *imp)spin_unlock (&req->rq_lock); } -list_for_each_safe (tmp, n, &imp->imp_delayed_list) { -struct ptlrpc_request *req = - list_entry(tmp, struct ptlrpc_request, rq_list); - +list_for_each_entry_safe (req, n, &imp->imp_delayed_list, rq_list) {DEBUG_REQ (D_RPCTRACE , req,"aborting waiting req" );spin_lock (&req->rq_lock);
@@ -3014,12 +2978,9 @@ void ptlrpc_abort_inflight(struct obd_import *imp)*/ void ptlrpc_abort_set (struct ptlrpc_request_set *set) { -struct list_head *tmp, *pos; - -list_for_each_safe (pos, tmp, &set->set_requests) { -struct ptlrpc_request *req = - list_entry(pos, struct ptlrpc_request, rq_set_chain); +struct ptlrpc_request *req, *tmp; +list_for_each_entry_safe (req, tmp, &set->set_requests, rq_set_chain) {spin_lock (&req->rq_lock);if (req->rq_phase !=RQ_PHASE_RPC ) {spin_unlock (&req->rq_lock);
drivers/staging/lustre/lustre/ptlrpc/import.c +12 -22
@@ -242,15 +242,13 @@ ptlrpc_inflight_deadline(struct ptlrpc_request *req, time64_t now)static unsigned int ptlrpc_inflight_timeout (struct obd_import *imp) {time64_t now =ktime_get_real_seconds (); -struct list_head *tmp, *n; -struct ptlrpc_request *req; +struct ptlrpc_request *req, *n;unsigned int timeout =0 ;spin_lock (&imp->imp_lock); -list_for_each_safe (tmp, n, &imp->imp_sending_list) { - req = list_entry(tmp, struct ptlrpc_request, rq_list); +list_for_each_entry_safe (req, n, &imp->imp_sending_list, rq_list) timeout =max (ptlrpc_inflight_deadline (req, now), timeout); - } +spin_unlock (&imp->imp_lock);return timeout; }
@@ -263,8 +261,7 @@ static unsigned int ptlrpc_inflight_timeout(struct obd_import *imp)*/ void ptlrpc_invalidate_import (struct obd_import *imp) { -struct list_head *tmp, *n; -struct ptlrpc_request *req; +struct ptlrpc_request *req, *n;unsigned int timeout;int rc;
@@ -336,19 +333,13 @@ void ptlrpc_invalidate_import(struct obd_import *imp)*/ rc =0 ; }else { -list_for_each_safe (tmp, n, - &imp->imp_sending_list) { - req =list_entry (tmp, - struct ptlrpc_request, - rq_list); +list_for_each_entry_safe (req, n, + &imp->imp_sending_list, rq_list) {DEBUG_REQ (D_ERROR , req,"still on sending list" ); } -list_for_each_safe (tmp, n, - &imp->imp_delayed_list) { - req =list_entry (tmp, - struct ptlrpc_request, - rq_list); +list_for_each_entry_safe (req, n, + &imp->imp_delayed_list, rq_list) {DEBUG_REQ (D_ERROR , req,"still on delayed list" ); }
@@ -557,14 +548,13 @@ static int import_select_connection(struct obd_import *imp)static int ptlrpc_first_transno (struct obd_import *imp,__u64 *transno) {struct ptlrpc_request *req; -struct list_head *tmp;/* The requests in committed_list always have smaller transnos than * the requests in replay_list */ if (!list_empty (&imp->imp_committed_list)) { - tmp = imp->imp_committed_list.next; - req = list_entry(tmp, struct ptlrpc_request, rq_replay_list); + req =list_first_entry (&imp->imp_committed_list, + struct ptlrpc_request, rq_replay_list); *transno = req->rq_transno;if (req->rq_transno ==0 ) { DEBUG_REQ(D_ERROR, req,
@@ -574,8 +564,8 @@ static int ptlrpc_first_transno(struct obd_import *imp, __u64 *transno)return 1 ; }if (!list_empty (&imp->imp_replay_list)) { - tmp = imp->imp_replay_list.next; - req = list_entry(tmp, struct ptlrpc_request, rq_replay_list); + req =list_first_entry (&imp->imp_replay_list, + struct ptlrpc_request, rq_replay_list); *transno = req->rq_transno;if (req->rq_transno ==0 ) {DEBUG_REQ (D_ERROR , req,"zero transno in replay_list" );
drivers/staging/lustre/lustre/ptlrpc/pinger.c +2 -6
@@ -230,17 +230,13 @@ static int ptlrpc_pinger_main(void *arg)unsigned long this_ping =cfs_time_current ();long time_to_next_wake;struct timeout_item *item; -struct list_head *iter; +struct obd_import *imp;mutex_lock (&pinger_mutex);list_for_each_entry (item, &timeout_list, ti_chain) { item->ti_cb (item, item->ti_cb_data); } -list_for_each (iter, &pinger_imports) { -struct obd_import *imp = - list_entry(iter, struct obd_import, - imp_pinger_chain); - +list_for_each_entry (imp, &pinger_imports, imp_pinger_chain) {ptlrpc_pinger_process_import (imp, this_ping);/* obd_timeout might have changed */ if (imp->imp_pingable && imp->imp_next_ping &&
drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c +5 -10
@@ -197,17 +197,14 @@ ptlrpcd_select_pc(struct ptlrpc_request *req)static int ptlrpcd_steal_rqset (struct ptlrpc_request_set *des,struct ptlrpc_request_set *src) { -struct list_head *tmp, *pos; -struct ptlrpc_request *req; +struct ptlrpc_request *req, *tmp;int rc =0 ;spin_lock (&src->set_new_req_lock);if (likely (!list_empty (&src->set_new_requests))) { -list_for_each_safe (pos, tmp, &src->set_new_requests) { - req = list_entry(pos, struct ptlrpc_request, - rq_set_chain); +list_for_each_entry_safe (req, tmp, &src->set_new_requests, rq_set_chain) req->rq_set = des; - } +list_splice_init (&src->set_new_requests, &des->set_requests); rc =atomic_read (&src->set_new_count);atomic_add (rc, &des->set_remaining);
@@ -273,8 +270,7 @@ static inline void ptlrpc_reqset_get(struct ptlrpc_request_set *set)*/ static int ptlrpcd_check (struct lu_env *env,struct ptlrpcd_ctl *pc) { -struct list_head *tmp, *pos; -struct ptlrpc_request *req; +struct ptlrpc_request *req, *tmp;struct ptlrpc_request_set *set = pc->pc_set;int rc =0 ;int rc2;
@@ -320,8 +316,7 @@ static int ptlrpcd_check(struct lu_env *env, struct ptlrpcd_ctl *pc)/* NB: ptlrpc_check_set has already moved completed request at the * head of seq::set_requests */ -list_for_each_safe (pos, tmp, &set->set_requests) { - req = list_entry(pos, struct ptlrpc_request, rq_set_chain); +list_for_each_entry_safe (req, tmp, &set->set_requests, rq_set_chain) {if (req->rq_phase !=RQ_PHASE_COMPLETE )break ;
drivers/staging/lustre/lustre/ptlrpc/recover.c +11 -15
@@ -66,8 +66,7 @@ void ptlrpc_initiate_recovery(struct obd_import *imp)int ptlrpc_replay_next (struct obd_import *imp,int *inflight) {int rc =0 ; -struct list_head *tmp, *pos; -struct ptlrpc_request *req =NULL ; +struct ptlrpc_request *req =NULL , *pos;__u64 last_transno; *inflight =0 ;
@@ -86,8 +85,8 @@ int ptlrpc_replay_next(struct obd_import *imp, int *inflight)/* Replay all the committed open requests on committed_list first */ if (!list_empty (&imp->imp_committed_list)) { - tmp = imp->imp_committed_list.prev; - req = list_entry(tmp, struct ptlrpc_request, rq_replay_list); + req =list_last_entry (&imp->imp_committed_list, + struct ptlrpc_request, rq_replay_list);/* The last request on committed_list hasn't been replayed */ if (req->rq_transno > last_transno) {
@@ -119,13 +118,13 @@ int ptlrpc_replay_next(struct obd_import *imp, int *inflight)* the imp_replay_list */ if (!req) { -list_for_each_safe (tmp, pos, &imp->imp_replay_list) { - req = list_entry(tmp, struct ptlrpc_request, - rq_replay_list); - -if (req->rq_transno > last_transno) +struct ptlrpc_request *tmp; +list_for_each_entry_safe (tmp, pos, &imp->imp_replay_list, + rq_replay_list) { +if (tmp->rq_transno > last_transno) { + req = tmp;break ; - req =NULL ; + } } }
@@ -211,13 +210,10 @@ int ptlrpc_resend(struct obd_import *imp)*/ void ptlrpc_wake_delayed (struct obd_import *imp) { -struct list_head *tmp, *pos; -struct ptlrpc_request *req; +struct ptlrpc_request *req, *pos;spin_lock (&imp->imp_lock); -list_for_each_safe (tmp, pos, &imp->imp_delayed_list) { - req = list_entry(tmp, struct ptlrpc_request, rq_list); - +list_for_each_entry_safe (req, pos, &imp->imp_delayed_list, rq_list) {DEBUG_REQ (D_HA , req,"waking (set %p):" , req->rq_set);ptlrpc_client_wake_req (req); }
drivers/staging/lustre/lustre/ptlrpc/service.c +4 -9
@@ -726,8 +726,6 @@ static void ptlrpc_server_drop_request(struct ptlrpc_request *req)struct ptlrpc_service_part *svcpt = rqbd->rqbd_svcpt;struct ptlrpc_service *svc = svcpt->scp_service;int refcount; -struct list_head *tmp; -struct list_head *nxt;if (!atomic_dec_and_test (&req->rq_refcount))return ;
@@ -776,9 +774,7 @@ static void ptlrpc_server_drop_request(struct ptlrpc_request *req)/* remove rqbd's reqs from svc's req history while * I've got the service lock */ -list_for_each (tmp, &rqbd->rqbd_reqs) { - req = list_entry(tmp, struct ptlrpc_request, - rq_list); +list_for_each_entry (req, &rqbd->rqbd_reqs, rq_list) {/* Track the highest culled req seq */ if (req->rq_history_seq > svcpt->scp_hist_seq_culled) {
@@ -790,10 +786,9 @@ static void ptlrpc_server_drop_request(struct ptlrpc_request *req)spin_unlock (&svcpt->scp_lock); -list_for_each_safe (tmp, nxt, &rqbd->rqbd_reqs) { - req =list_entry (rqbd->rqbd_reqs.next, - struct ptlrpc_request, - rq_list); +while ((req =list_first_entry_or_null ( + &rqbd->rqbd_reqs, + struct ptlrpc_request, rq_list))) {list_del (&req->rq_list);ptlrpc_server_free_request (req); }
PATCH 16/21 staging: lustre: fid: convert lcs_mutex to a spinlock
In reply to NeilBrownThere is only one place where this lock is held
while the task might sleep - in
ldebugfs_fid_space_seq_write()
while ldebugfs_fid_write_common() is called.
This call can easily be taken out of the locked region by asking it to parse the user data into a local variable, and then copying that variable into ->lcs_space while holding the lock.
Note that ldebugfs_gid_write_common returns >0 on success, so use that to gate updating ->lcs_space.
So make that change, and convert lcs_mutex to a spinlock named lcs_lock. spinlocks are slightly cheaper than mutexes and using one makes is clear that the lock is only held for a short time.
--- drivers/staging/lustre/lustre/fid/fid_request.c | 24 ++++++++--------- drivers/staging/lustre/lustre/fid/lproc_fid.c | 29 +++++++++++--------- drivers/staging/lustre/lustre/include/lustre_fid.h | 2 + 3 files changed, 29 insertions(+), 26 deletions(-)
drivers/staging/lustre/lustre/fid/fid_request.c +12 -12
@@ -198,24 +198,24 @@ static int seq_fid_alloc_prep(struct lu_client_seq *seq,if (seq->lcs_update) {add_wait_queue (&seq->lcs_waitq, link);set_current_state (TASK_UNINTERRUPTIBLE ); -mutex_unlock (&seq->lcs_mutex); +spin_unlock (&seq->lcs_lock);schedule (); -mutex_lock (&seq->lcs_mutex); +spin_lock (&seq->lcs_lock);remove_wait_queue (&seq->lcs_waitq, link);set_current_state (TASK_RUNNING );return -EAGAIN ; } ++seq->lcs_update; -mutex_unlock (&seq->lcs_mutex); +spin_unlock (&seq->lcs_lock);return 0 ; }static void seq_fid_alloc_fini (struct lu_client_seq *seq) {LASSERT (seq->lcs_update ==1 ); -mutex_lock (&seq->lcs_mutex); +spin_lock (&seq->lcs_lock); --seq->lcs_update;wake_up (&seq->lcs_waitq); }
@@ -231,7 +231,7 @@ int seq_client_alloc_fid(const struct lu_env *env,LASSERT (fid);init_waitqueue_entry (&link, current); -mutex_lock (&seq->lcs_mutex); +spin_lock (&seq->lcs_lock);if (OBD_FAIL_CHECK (OBD_FAIL_SEQ_EXHAUST )) seq->lcs_fid.f_oid = seq->lcs_width;
@@ -256,7 +256,7 @@ int seq_client_alloc_fid(const struct lu_env *env,CERROR ("%s: Can't allocate new sequence, rc %d\n" , seq->lcs_name, rc);seq_fid_alloc_fini (seq); -mutex_unlock (&seq->lcs_mutex); +spin_unlock (&seq->lcs_lock);return rc; }
@@ -278,7 +278,7 @@ int seq_client_alloc_fid(const struct lu_env *env, } *fid = seq->lcs_fid; -mutex_unlock (&seq->lcs_mutex); +spin_unlock (&seq->lcs_lock);CDEBUG (D_INFO ,"%s: Allocated FID " DFID "\n" , seq->lcs_name,PFID (fid));
@@ -296,16 +296,16 @@ void seq_client_flush(struct lu_client_seq *seq)LASSERT (seq);init_waitqueue_entry (&link, current); -mutex_lock (&seq->lcs_mutex); +spin_lock (&seq->lcs_lock);while (seq->lcs_update) {add_wait_queue (&seq->lcs_waitq, &link);set_current_state (TASK_UNINTERRUPTIBLE ); -mutex_unlock (&seq->lcs_mutex); +spin_unlock (&seq->lcs_lock);schedule (); -mutex_lock (&seq->lcs_mutex); +spin_lock (&seq->lcs_lock);remove_wait_queue (&seq->lcs_waitq, &link);set_current_state (TASK_RUNNING ); }
@@ -319,7 +319,7 @@ void seq_client_flush(struct lu_client_seq *seq) seq->lcs_space.lsr_index =-1 ;lu_seq_range_init (&seq->lcs_space); -mutex_unlock (&seq->lcs_mutex); +spin_unlock (&seq->lcs_lock); }EXPORT_SYMBOL (seq_client_flush);
@@ -382,7 +382,7 @@ static int seq_client_init(struct lu_client_seq *seq, seq->lcs_type = type; -mutex_init (&seq->lcs_mutex); +spin_lock_init (&seq->lcs_lock);if (type ==LUSTRE_SEQ_METADATA ) seq->lcs_width =LUSTRE_METADATA_SEQ_MAX_WIDTH ;else
drivers/staging/lustre/lustre/fid/lproc_fid.c +16 -13
@@ -98,20 +98,23 @@ ldebugfs_fid_space_seq_write(struct file *file, size_t count, loff_t *off) { struct lu_client_seq *seq; +struct lu_seq_range range;int rc; seq = ((struct seq_file *)file->private_data)->private; -mutex_lock (&seq->lcs_mutex); - rc =ldebugfs_fid_write_common (buffer, count, &seq->lcs_space); + rc =ldebugfs_fid_write_common (buffer, count, &range); + +spin_lock (&seq->lcs_lock); +if (rc >0 ) + seq->lcs_space = range; +spin_unlock (&seq->lcs_lock);if (rc ==0 ) {CDEBUG (D_INFO ,"%s: Space: " DRANGE "\n" , - seq->lcs_name,PRANGE (&seq->lcs_space)); + seq->lcs_name,PRANGE (&range)); } -mutex_unlock (&seq->lcs_mutex); -return count; }
@@ -120,9 +123,9 @@ ldebugfs_fid_space_seq_show(struct seq_file *m, void *unused) {struct lu_client_seq *seq = (struct lu_client_seq *)m->private; -mutex_lock (&seq->lcs_mutex); +spin_lock (&seq->lcs_lock);seq_printf (m,"[%#llx - %#llx]:%x:%s\n" ,PRANGE (&seq->lcs_space)); -mutex_unlock (&seq->lcs_mutex); +spin_unlock (&seq->lcs_lock);return 0 ; }
@@ -142,7 +145,7 @@ ldebugfs_fid_width_seq_write(struct file *file,if (rc)return rc; -mutex_lock (&seq->lcs_mutex); +spin_lock (&seq->lcs_lock);if (seq->lcs_type ==LUSTRE_SEQ_DATA ) max =LUSTRE_DATA_SEQ_MAX_WIDTH ;else
@@ -155,7 +158,7 @@ ldebugfs_fid_width_seq_write(struct file *file, seq->lcs_width); } -mutex_unlock (&seq->lcs_mutex); +spin_unlock (&seq->lcs_lock);return count; }
@@ -165,9 +168,9 @@ ldebugfs_fid_width_seq_show(struct seq_file *m, void *unused) {struct lu_client_seq *seq = (struct lu_client_seq *)m->private; -mutex_lock (&seq->lcs_mutex); +spin_lock (&seq->lcs_lock);seq_printf (m,"%llu\n" , seq->lcs_width); -mutex_unlock (&seq->lcs_mutex); +spin_unlock (&seq->lcs_lock);return 0 ; }
@@ -177,9 +180,9 @@ ldebugfs_fid_fid_seq_show(struct seq_file *m, void *unused) {struct lu_client_seq *seq = (struct lu_client_seq *)m->private; -mutex_lock (&seq->lcs_mutex); +spin_lock (&seq->lcs_lock);seq_printf (m,DFID "\n" ,PFID (&seq->lcs_fid)); -mutex_unlock (&seq->lcs_mutex); +spin_unlock (&seq->lcs_lock);return 0 ; }
drivers/staging/lustre/lustre/include/lustre_fid.h +1 -1
@@ -324,7 +324,7 @@ enum lu_mgr_type {struct lu_client_seq {/* Sequence-controller export. */ struct obd_export *lcs_exp; -struct mutex lcs_mutex; +spinlock_t lcs_lock;/* * Range of allowed for allocation sequences. When using lu_client_seq on
PATCH 17/21 staging: lustre: fid: use wait_event_cmd()
In reply to NeilBrownRather than open-coding a wait event loop twice, use wait_event_cmd() to wait, dropping the spinlock over schedule().
This does require duplicating part of the wait condition, but that is just three tests on values that are in registers or in cache, so the cost is small and the increased readability is large.
--- drivers/staging/lustre/lustre/fid/fid_request.c | 68 +++++++---------------- 1 file changed, 20 insertions(+), 48 deletions(-)
drivers/staging/lustre/lustre/fid/fid_request.c +20 -48
@@ -192,26 +192,6 @@ static int seq_client_alloc_seq(const struct lu_env *env,return rc; } -static int seq_fid_alloc_prep (struct lu_client_seq *seq, -wait_queue_entry_t *link) -{ -if (seq->lcs_update) { -add_wait_queue (&seq->lcs_waitq, link); -set_current_state (TASK_UNINTERRUPTIBLE ); -spin_unlock (&seq->lcs_lock); - -schedule (); - -spin_lock (&seq->lcs_lock); -remove_wait_queue (&seq->lcs_waitq, link); -set_current_state (TASK_RUNNING ); -return -EAGAIN ; - } - ++seq->lcs_update; -spin_unlock (&seq->lcs_lock); -return 0 ; -} -static void seq_fid_alloc_fini (struct lu_client_seq *seq) {LASSERT (seq->lcs_update ==1 );
@@ -224,32 +204,34 @@ static void seq_fid_alloc_fini(struct lu_client_seq *seq)int seq_client_alloc_fid (const struct lu_env *env,struct lu_client_seq *seq,struct lu_fid *fid) { -wait_queue_entry_t link;int rc;LASSERT (seq);LASSERT (fid); -init_waitqueue_entry (&link, current);spin_lock (&seq->lcs_lock);if (OBD_FAIL_CHECK (OBD_FAIL_SEQ_EXHAUST )) seq->lcs_fid.f_oid = seq->lcs_width; -while (1 ) { +wait_event_cmd (seq->lcs_waitq, + (!fid_is_zero (&seq->lcs_fid) && +fid_oid (&seq->lcs_fid) < seq->lcs_width) || + !seq->lcs_update, +spin_unlock (&seq->lcs_lock), +spin_lock (&seq->lcs_lock)); + +if (!fid_is_zero (&seq->lcs_fid) && +fid_oid (&seq->lcs_fid) < seq->lcs_width) { +/* Just bump last allocated fid and return to caller. */ + seq->lcs_fid.f_oid +=1 ; + rc =0 ; + }else {u64 seqnr; -if (!fid_is_zero (&seq->lcs_fid) && -fid_oid (&seq->lcs_fid) < seq->lcs_width) { -/* Just bump last allocated fid and return to caller. */ - seq->lcs_fid.f_oid +=1 ; - rc =0 ; -break ; - } - - rc =seq_fid_alloc_prep (seq, &link); -if (rc) -continue ; +LASSERT (seq->lcs_update ==0 ); + ++seq->lcs_update; +spin_unlock (&seq->lcs_lock); rc =seq_client_alloc_seq (env, seq, &seqnr);if (rc) {
@@ -274,7 +256,6 @@ int seq_client_alloc_fid(const struct lu_env *env, rc =1 ;seq_fid_alloc_fini (seq); -break ; } *fid = seq->lcs_fid;
@@ -292,23 +273,14 @@ EXPORT_SYMBOL(seq_client_alloc_fid);*/ void seq_client_flush (struct lu_client_seq *seq) { -wait_queue_entry_t link;LASSERT (seq); -init_waitqueue_entry (&link, current);spin_lock (&seq->lcs_lock); -while (seq->lcs_update) { -add_wait_queue (&seq->lcs_waitq, &link); -set_current_state (TASK_UNINTERRUPTIBLE ); -spin_unlock (&seq->lcs_lock); - -schedule (); - -spin_lock (&seq->lcs_lock); -remove_wait_queue (&seq->lcs_waitq, &link); -set_current_state (TASK_RUNNING ); - } +wait_event_cmd (seq->lcs_waitq, + !seq->lcs_update, +spin_unlock (&seq->lcs_lock), +spin_lock (&seq->lcs_lock));fid_zero (&seq->lcs_fid);/**
PATCH 18/21 staging: lustre: fid: remove seq_fid_alloc_fini() and simplify
In reply to NeilBrownseq_fid_alloc_fini() is tiny and only called
from two places in the one function. We can move
both those calls earlier and merge them so only
one call is needed. At that point, there is no
value added by having a separate function.
Also instead of using ++ and -- on ->lcs_update to toggle between 0 and 1, explicitly set to 0 or 1 as appropriate.
Moving the locking earlier means that the code which updates seq->lcs_fid is now protected, so ldebugfs_fid_fid_seq_show() now cannot see a torn value.
--- drivers/staging/lustre/lustre/fid/fid_request.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/staging/lustre/lustre/fid/fid_request.c +6 -12
@@ -192,14 +192,6 @@ static int seq_client_alloc_seq(const struct lu_env *env,return rc; } -static void seq_fid_alloc_fini (struct lu_client_seq *seq) -{ -LASSERT (seq->lcs_update ==1 ); -spin_lock (&seq->lcs_lock); - --seq->lcs_update; -wake_up (&seq->lcs_waitq); -} -/* Allocate new fid on passed client @seq and save it to @fid. */ int seq_client_alloc_fid (const struct lu_env *env,struct lu_client_seq *seq,struct lu_fid *fid)
@@ -230,14 +222,18 @@ int seq_client_alloc_fid(const struct lu_env *env,u64 seqnr;LASSERT (seq->lcs_update ==0 ); - ++seq->lcs_update; + seq->lcs_update =1 ;spin_unlock (&seq->lcs_lock); rc =seq_client_alloc_seq (env, seq, &seqnr); + +spin_lock (&seq->lcs_lock); + seq->lcs_update =0 ; +wake_up (&seq->lcs_waitq); +if (rc) {CERROR ("%s: Can't allocate new sequence, rc %d\n" , seq->lcs_name, rc); -seq_fid_alloc_fini (seq);spin_unlock (&seq->lcs_lock);return rc; }
@@ -254,8 +250,6 @@ int seq_client_alloc_fid(const struct lu_env *env,* to setup FLD for it. */ rc =1 ; - -seq_fid_alloc_fini (seq); } *fid = seq->lcs_fid;
PATCH 19/21 staging: lustre: fid: fix up debugfs access to ->lcs_space
In reply to NeilBrownlcs_space can change while the lock is not held
if an RPC in underway. This can be detected byseq->ls_update being set.
In this case, reading or writing the value should return -EBUSY.
Also, the D_INFO CDEBUG() which reports the lcs_space being updated never fires, as it tests the wrong value - ldebugfs_fid_write_common() returns 'count' on success.
Finally, this return value should be returned from ldebugfs_fid_space_seq_write(), rather than always returning 'count', so that errors can be detected.
--- drivers/staging/lustre/lustre/fid/lproc_fid.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/staging/lustre/lustre/fid/lproc_fid.c +11 -4
@@ -106,28 +106,35 @@ ldebugfs_fid_space_seq_write(struct file *file, rc =ldebugfs_fid_write_common (buffer, count, &range);spin_lock (&seq->lcs_lock); +if (seq->lcs_update) +/* An RPC call is active to update lcs_space */ + rc = -EBUSY ;if (rc >0 ) seq->lcs_space = range;spin_unlock (&seq->lcs_lock); -if (rc ==0 ) { +if (rc >0 ) {CDEBUG (D_INFO ,"%s: Space: " DRANGE "\n" , seq->lcs_name,PRANGE (&range)); } -return count; +return rc; }static int ldebugfs_fid_space_seq_show (struct seq_file *m,void *unused) {struct lu_client_seq *seq = (struct lu_client_seq *)m->private; +int rc =0 ;spin_lock (&seq->lcs_lock); -seq_printf (m,"[%#llx - %#llx]:%x:%s\n" ,PRANGE (&seq->lcs_space)); +if (seq->lcs_update) + rc = -EBUSY ; +else +seq_printf (m,"[%#llx - %#llx]:%x:%s\n" ,PRANGE (&seq->lcs_space));spin_unlock (&seq->lcs_lock); -return 0 ; +return rc; } static ssize_t
PATCH 20/21 staging: lustre: fid: perform sanity checks before commiting
In reply to NeilBrownWhen fid fetches a new range from the server, it commits to it (*output = *out) *before* performing sanity checks. This looks backwards.
Don't commit to a value until it has been found to be sane.
--- drivers/staging/lustre/lustre/fid/fid_request.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/staging/lustre/lustre/fid/fid_request.c +5 -5
@@ -118,22 +118,22 @@ static int seq_client_rpc(struct lu_client_seq *seq, goto out_req; out =req_capsule_server_get (&req->rq_pill, &RMF_SEQ_RANGE ); - *output = *out; -if (!lu_seq_range_is_sane (output)) { +if (!lu_seq_range_is_sane (out)) {CERROR ("%s: Invalid range received from server: " -DRANGE "\n" , seq->lcs_name,PRANGE (output)); +DRANGE "\n" , seq->lcs_name,PRANGE (out)); rc = -EINVAL ; goto out_req; } -if (lu_seq_range_is_exhausted (output)) { +if (lu_seq_range_is_exhausted (out)) {CERROR ("%s: Range received from server is exhausted: " -DRANGE "]\n" , seq->lcs_name,PRANGE (output)); +DRANGE "]\n" , seq->lcs_name,PRANGE (out)); rc = -EINVAL ; goto out_req; } + *output = *out;CDEBUG_LIMIT (debug_mask,"%s: Allocated %s-sequence " DRANGE "]\n" , seq->lcs_name, opcname,PRANGE (output));
PATCH 21/21 staging: lustre: socklnd: simplify ksnc_rx_iov_space
In reply to NeilBrownksnc_rx_iov_space is currently a union of two arrays, one of 'struct kvec', the other of 'struct bio_vec'.
The 'struct bio_vec' option is never used. The array of kvec is used to read in a packet header, or to read data that needs to be skipped so as to synchronize with a packet boundary.
In each case the target memory location is a virtual address, never a page, so 'struct bio_vec' is never needed.
When we read into a page, different code steps up a separate array of 'struct bio_vec'.
So remove the bio_vec option, and remove the union ksock_rxiovspace..
--- .../staging/lustre/lnet/klnds/socklnd/socklnd.h | 11 +---------- .../staging/lustre/lnet/klnds/socklnd/socklnd_cb.c | 4 ++-- 2 files changed, 3 insertions(+), 12 deletions(-)
drivers/staging/lustre/lnet/klnds/socklnd/socklnd.h +1 -10
@@ -304,15 +304,6 @@ struct ksock_tx { /* transmit packet *//* network zero copy callback descriptor embedded in struct ksock_tx */ -/* -* space for the rx frag descriptors; we either read a single contiguous -* header, or up to LNET_MAX_IOV frags of payload of either type. -*/ -union ksock_rxiovspace { -struct kvec iov[LNET_MAX_IOV ]; -struct bio_vec kiov[LNET_MAX_IOV ]; -}; -#define SOCKNAL_RX_KSM_HEADER 1/* reading ksock message header */ #define SOCKNAL_RX_LNET_HEADER 2/* reading lnet message header */ #define SOCKNAL_RX_PARSE 3/* Calling lnet_parse() */
@@ -359,7 +350,7 @@ struct ksock_conn {__u8 ksnc_rx_state;/* what is being read */ int ksnc_rx_nob_left;/* # bytes to next hdr/body */ struct iov_iter ksnc_rx_to;/* copy destination */ -union ksock_rxiovspace ksnc_rx_iov_space;/* space for frag descriptors */ +struct kvec ksnc_rx_iov_space[LNET_MAX_IOV ];/* space for frag descriptors */ __u32 ksnc_rx_csum;/* partial checksum for incoming * data */
drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c +2 -2
@@ -986,7 +986,7 @@ int ksocknal_new_packet(struct ksock_conn *conn, int nob_to_skip) {static char ksocknal_slop_buffer[4096 ]; -struct kvec *kvec = (struct kvec *)&conn->ksnc_rx_iov_space; +struct kvec *kvec = conn->ksnc_rx_iov_space;int nob;unsigned int niov;
@@ -1059,7 +1059,7 @@ ksocknal_new_packet(struct ksock_conn *conn, int nob_to_skip)static int ksocknal_process_receive (struct ksock_conn *conn) { -struct kvec *kvec = (struct kvec *)&conn->ksnc_rx_iov_space; +struct kvec *kvec = conn->ksnc_rx_iov_space;struct lnet_hdr *lhdr;struct lnet_process_id *id;int rc;
Lustre networking driver. (Or so I was taught)
Regards,
Patrick
________________________________________
From: lustre-devel <[email protected]> on behalf of NeilBrown <[email protected]>
Sent: Monday, February 19, 2018 8:23:37 PM
To: Oleg Drokin; James Simmons; Andreas Dilger; Greg Kroah-Hartman
Cc: lkml; lustre
Subject: [lustre-devel] [PATCH 00/21] staging: assorted lustre clean-up
Following are assorted patches which clean up parts of lustre. One or two tiny buglets are fixed, but mostly the patches just make the code more readable, often by removing distractions.
The first several patches remove content from libcfs, completely removing 3 files.
There are some list_for_each improvements in ptlrpc, and some code simplification in fid.
Finally a small simplification in socklnd.
(lnd ?? Lustre Networking Domain??)
Thanks,
NeilBrown
---
NeilBrown (21):
staging: lustre: replace all CFS_CAP_* macros with CAP_*
staging: lustre: opencode cfs_cap_{raise,lower,raised}
staging: lustre: remove linux-curproc.c
staging: lustre: remove unnecessary cfs_block_allsigs() calls
staging: lustre: lnet: remove cfs_block_allsigs calls.
staging: lustre: simplify linux-prim.c
staging: lustre: improve API and implementation of blocking signals.
staging: lustre: make signal-blocking functions inline
staging: lustre: discard libcfs_kvzalloc_cpt()
staging: lustre: discard lu_buf allocation library.
staging: lustre: improve some libcfs_kvzalloc calls.
staging: lustre: discard libcfs_kvzalloc and linux-mem.c
staging: lustre: remove phantom struct cfs_crypto_hash_desc
staging: lustre: fix assorted checkpatch errors
staging: lustre: ptlrpc: list_for_each improvements.
staging: lustre: fid: convert lcs_mutex to a spinlock
staging: lustre: fid: use wait_event_cmd()
staging: lustre: fid: remove seq_fid_alloc_fini() and simplify
staging: lustre: fid: fix up debugfs access to ->lcs_space
staging: lustre: fid: perform sanity checks before commiting
staging: lustre: socklnd: simplify ksnc_rx_iov_space
.../staging/lustre/include/linux/libcfs/curproc.h | 37 ++----- .../staging/lustre/include/linux/libcfs/libcfs.h | 27 +++-- .../lustre/include/linux/libcfs/libcfs_crypto.h | 11 +- drivers/staging/lustre/include/linux/lnet/api.h | 1 .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c | 6 - .../staging/lustre/lnet/klnds/socklnd/socklnd.h | 11 -- .../staging/lustre/lnet/klnds/socklnd/socklnd_cb.c | 10 -- .../lustre/lnet/klnds/socklnd/socklnd_lib.c | 2 drivers/staging/lustre/lnet/libcfs/Makefile | 4 - .../staging/lustre/lnet/libcfs/linux/linux-cpu.c | 2 .../lustre/lnet/libcfs/linux/linux-crypto.c | 29 ++--- .../lustre/lnet/libcfs/linux/linux-curproc.c | 108 ------------------- .../staging/lustre/lnet/libcfs/linux/linux-mem.c | 51 --------- .../staging/lustre/lnet/libcfs/linux/linux-prim.c | 113 -------------------- drivers/staging/lustre/lnet/lnet/acceptor.c | 2 drivers/staging/lustre/lnet/lnet/api-ni.c | 15 +-- drivers/staging/lustre/lnet/lnet/lib-eq.c | 10 +- drivers/staging/lustre/lnet/lnet/router.c | 2 drivers/staging/lustre/lnet/selftest/timer.c | 2 drivers/staging/lustre/lustre/fid/fid_request.c | 106 ++++++------------- drivers/staging/lustre/lustre/fid/lproc_fid.c | 44 +++++--- drivers/staging/lustre/lustre/include/lu_object.h | 7 - drivers/staging/lustre/lustre/include/lustre_fid.h | 2 drivers/staging/lustre/lustre/include/lustre_lib.h | 18 ++- drivers/staging/lustre/lustre/include/lustre_sec.h | 3 - drivers/staging/lustre/lustre/include/obd_class.h | 8 + .../staging/lustre/lustre/include/obd_support.h | 2 drivers/staging/lustre/lustre/llite/dcache.c | 2 drivers/staging/lustre/lustre/llite/dir.c | 10 +- drivers/staging/lustre/lustre/llite/file.c | 12 +- drivers/staging/lustre/lustre/llite/llite_lib.c | 8 + drivers/staging/lustre/lustre/llite/llite_mmap.c | 8 + drivers/staging/lustre/lustre/llite/xattr.c | 2 drivers/staging/lustre/lustre/lmv/lmv_obd.c | 4 - drivers/staging/lustre/lustre/lov/lov_ea.c | 2 drivers/staging/lustre/lustre/lov/lov_io.c | 2 drivers/staging/lustre/lustre/lov/lov_lock.c | 2 drivers/staging/lustre/lustre/lov/lov_object.c | 4 - drivers/staging/lustre/lustre/lov/lov_pack.c | 2 drivers/staging/lustre/lustre/lov/lov_request.c | 2 drivers/staging/lustre/lustre/mdc/mdc_locks.c | 2 drivers/staging/lustre/lustre/mdc/mdc_request.c | 6 + drivers/staging/lustre/lustre/obdclass/linkea.c | 16 ++- .../lustre/lustre/obdclass/linux/linux-module.c | 4 - drivers/staging/lustre/lustre/obdclass/llog.c | 22 ++-- drivers/staging/lustre/lustre/obdclass/lu_object.c | 70 ------------ .../lustre/lustre/obdclass/lustre_handles.c | 4 - .../staging/lustre/lustre/obdecho/echo_client.c | 8 + drivers/staging/lustre/lustre/osc/osc_cache.c | 4 - drivers/staging/lustre/lustre/osc/osc_page.c | 2 drivers/staging/lustre/lustre/osc/osc_request.c | 2 drivers/staging/lustre/lustre/ptlrpc/client.c | 93 +++++----------- drivers/staging/lustre/lustre/ptlrpc/import.c | 34 ++---- drivers/staging/lustre/lustre/ptlrpc/layout.c | 2 drivers/staging/lustre/lustre/ptlrpc/pinger.c | 8 - drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c | 15 +-- drivers/staging/lustre/lustre/ptlrpc/recover.c | 28 ++--- drivers/staging/lustre/lustre/ptlrpc/sec.c | 4 - drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c | 4 - drivers/staging/lustre/lustre/ptlrpc/sec_null.c | 8 + drivers/staging/lustre/lustre/ptlrpc/sec_plain.c | 8 + drivers/staging/lustre/lustre/ptlrpc/service.c | 27 ++--- 62 files changed, 295 insertions(+), 769 deletions(-) delete mode 100644 drivers/staging/lustre/lnet/libcfs/linux/linux-curproc.c delete mode 100644 drivers/staging/lustre/lnet/libcfs/linux/linux-mem.c delete mode 100644 drivers/staging/lustre/lnet/libcfs/linux/linux-prim.c
--
Signature
_______________________________________________
lustre-devel mailing list
[email protected]
http://lists.lustre.org/listinfo.cgi/lustre-devel-lustre.org