From: James Simmons Date: Wed, 11 Jan 2017 16:24:35 +0000 (-0500) Subject: LU-6245 libcfs: use libcfs_private.h only for kernel space X-Git-Tag: 2.9.53~42 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=f431777cf5cbb0f1493e91a35bbc2a26e1d14db9 LU-6245 libcfs: use libcfs_private.h only for kernel space The current lustre userland code no longer uses special macros which are present in libcfs_private.h. We can then eliminate those macros and only use the libcfs_private.h header for kernel space. The special macros no longer needed for userland are: 1) LOGL and LOGU which were used in the UAPI header lustre_cfg.h and lustre_ioctl.h. 2) [un]likely macros used in the UAPI header lustre_ostid.h 3) The special libcfs assert macros Change-Id: Iaa54bdcfb6104d13f2aabae63335e041481244a5 Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/22138 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Dmitry Eremin Reviewed-by: Jinshan Xiong Reviewed-by: Fan Yong Reviewed-by: Oleg Drokin --- diff --git a/libcfs/include/libcfs/libcfs.h b/libcfs/include/libcfs/libcfs.h index 82d36dd..0f80224 100644 --- a/libcfs/include/libcfs/libcfs.h +++ b/libcfs/include/libcfs/libcfs.h @@ -110,8 +110,8 @@ void cfs_get_random_bytes(void *buf, int size); #endif /* __KERNEL__ */ #include -#include #ifdef __KERNEL__ +# include # include # include # include diff --git a/libcfs/include/libcfs/libcfs_private.h b/libcfs/include/libcfs/libcfs_private.h index 22d2a5e..bcd7d56 100644 --- a/libcfs/include/libcfs/libcfs_private.h +++ b/libcfs/include/libcfs/libcfs_private.h @@ -42,8 +42,6 @@ # define DEBUG_SUBSYSTEM S_UNDEFINED #endif -#ifdef __KERNEL__ - #ifdef LIBCFS_DEBUG /* @@ -121,12 +119,13 @@ do { \ lbug_with_loc(&msgdata); \ } while(0) -extern atomic_t libcfs_kmemory; /* * Memory */ #ifdef LIBCFS_DEBUG +extern atomic_t libcfs_kmemory; + # define libcfs_kmem_inc(ptr, size) \ do { \ atomic_add(size, &libcfs_kmemory); \ @@ -233,17 +232,7 @@ do { \ /******************************************************************************/ -/* htonl hack - either this, or compile with -O2. Stupid byteorder/generic.h */ -#if defined(__GNUC__) && (__GNUC__ >= 2) && !defined(__OPTIMIZE__) -#define ___htonl(x) __cpu_to_be32(x) -#define ___htons(x) __cpu_to_be16(x) -#define ___ntohl(x) __be32_to_cpu(x) -#define ___ntohs(x) __be16_to_cpu(x) -#define htonl(x) ___htonl(x) -#define ntohl(x) ___ntohl(x) -#define htons(x) ___htons(x) -#define ntohs(x) ___ntohs(x) -#endif +struct task_struct; void libcfs_debug_dumpstack(struct task_struct *tsk); void libcfs_debug_dumplog(void); @@ -252,59 +241,6 @@ int libcfs_debug_cleanup(void); int libcfs_debug_clear_buffer(void); int libcfs_debug_mark_buffer(const char *text); -#else /* !__KERNEL__ */ -# ifdef LIBCFS_DEBUG -# undef NDEBUG -# include -# define LASSERT(e) assert(e) -# define LASSERTF(cond, ...) \ -do { \ - if (!(cond)) \ - CERROR(__VA_ARGS__); \ - assert(cond); \ -} while (0) -# define LBUG() assert(0) -# ifdef CONFIG_LUSTRE_DEBUG_EXPENSIVE_CHECK -# define LINVRNT(exp) LASSERT(exp) -# else -# define LINVRNT(exp) ((void)sizeof!!(exp)) -# endif -# else -# define LASSERT(e) ((void)sizeof!!(e)) -# define LASSERTF(cond, ...) ((void)sizeof!!(cond)) -# define LBUG() ((void)(0)) -# define LINVRNT(exp) ((void)sizeof!!(exp)) -# endif /* LIBCFS_DEBUG */ -# define KLASSERT(e) ((void)0) -# define printk printf -#define LIBCFS_ALLOC_GFP(ptr, size, mask) \ -do { \ - (ptr) = calloc(1, size); \ -} while (0) -# define LIBCFS_FREE(ptr, size) do { free(ptr); } while((size) - (size)) -# define LIBCFS_ALLOC(ptr, size) \ - LIBCFS_ALLOC_GFP(ptr, size, 0) -# define LIBCFS_CPT_ALLOC_GFP(ptr, cptab, cpt, size, mask) \ - LIBCFS_ALLOC(ptr, size) -# define LIBCFS_CPT_ALLOC(ptr, cptab, cpt, size) \ - LIBCFS_ALLOC(ptr, size) - -void libcfs_debug_dumplog(void); -int libcfs_debug_init(unsigned long bufsize); -int libcfs_debug_cleanup(void); - -#define libcfs_debug_dumpstack(tsk) ((void)0) - -/* - * Generic compiler-dependent macros required for kernel - * build go below this comment. Actual compiler/compiler version - * specific implementations come from the above header files - */ -#define likely(x) __builtin_expect(!!(x), 1) -#define unlikely(x) __builtin_expect(!!(x), 0) -/* !__KERNEL__ */ -#endif - /* * allocate a variable array, returned value is an array of pointers. * Caller can specify length of array by count. @@ -473,20 +409,6 @@ static inline size_t cfs_round_strlen(char *fset) return cfs_size_round(strlen(fset) + 1); } -#define LOGL(var,len,ptr) \ -do { \ - if (var) \ - memcpy((char *)ptr, (const char *)var, len); \ - ptr += cfs_size_round(len); \ -} while (0) - -#define LOGU(var,len,ptr) \ -do { \ - if (var) \ - memcpy((char *)var, (const char *)ptr, len); \ - ptr += cfs_size_round(len); \ -} while (0) - extern struct cfs_psdev_ops libcfs_psdev_ops; extern struct miscdevice libcfs_dev; extern struct cfs_wi_sched *cfs_sched_rehash; diff --git a/lustre/include/lprocfs_status.h b/lustre/include/lprocfs_status.h index fb6bbfa..763b9be 100644 --- a/lustre/include/lprocfs_status.h +++ b/lustre/include/lprocfs_status.h @@ -45,6 +45,7 @@ #include #include +#include #include struct lprocfs_vars { diff --git a/lustre/include/lustre/lustre_idl.h b/lustre/include/lustre/lustre_idl.h index 22e246d..65edd58 100644 --- a/lustre/include/lustre/lustre_idl.h +++ b/lustre/include/lustre/lustre_idl.h @@ -72,7 +72,6 @@ #include #include -#include #include #include /* Defn's shared with user-space. */ #include diff --git a/lustre/include/lustre/lustre_ostid.h b/lustre/include/lustre/lustre_ostid.h index 5a5d3bc..aebb33e 100644 --- a/lustre/include/lustre/lustre_ostid.h +++ b/lustre/include/lustre/lustre_ostid.h @@ -78,7 +78,7 @@ static inline __u64 ostid_seq(const struct ost_id *ostid) if (fid_seq_is_mdt0(ostid->oi.oi_seq)) return FID_SEQ_OST_MDT0; - if (unlikely(fid_seq_is_default(ostid->oi.oi_seq))) + if (fid_seq_is_default(ostid->oi.oi_seq)) return FID_SEQ_LOV_DEFAULT; if (fid_is_idif(&ostid->oi_fid)) @@ -93,7 +93,7 @@ static inline __u64 ostid_id(const struct ost_id *ostid) if (fid_seq_is_mdt0(ostid->oi.oi_seq)) return ostid->oi.oi_id & IDIF_OID_MASK; - if (unlikely(fid_seq_is_default(ostid->oi.oi_seq))) + if (fid_seq_is_default(ostid->oi.oi_seq)) return ostid->oi.oi_id; if (fid_is_idif(&ostid->oi_fid)) @@ -192,7 +192,7 @@ static inline void ostid_le_to_cpu(const struct ost_id *src_oi, /* pack any OST FID into an ostid (id/seq) for the wire/disk */ static inline int fid_to_ostid(const struct lu_fid *fid, struct ost_id *ostid) { - if (unlikely(fid_seq_is_igif(fid->f_seq))) { + if (fid_seq_is_igif(fid->f_seq)) { CERROR("bad IGIF, "DFID"\n", PFID(fid)); return -EBADF; } diff --git a/lustre/include/lustre/lustre_user.h b/lustre/include/lustre/lustre_user.h index 4f3f74f..3efc0cb 100644 --- a/lustre/include/lustre/lustre_user.h +++ b/lustre/include/lustre/lustre_user.h @@ -45,6 +45,7 @@ #include #ifdef __KERNEL__ +# include # include # include /* snprintf() */ # include diff --git a/lustre/include/lustre_cfg.h b/lustre/include/lustre_cfg.h index 0685df5..11f1576 100644 --- a/lustre/include/lustre_cfg.h +++ b/lustre/include/lustre_cfg.h @@ -182,7 +182,9 @@ static inline void *lustre_cfg_buf(struct lustre_cfg *lcfg, __u32 index) __u32 i; size_t offset; __u32 bufcount; - LASSERT (lcfg != NULL); + + if (!lcfg) + return NULL; bufcount = lcfg->lcfg_bufcount; if (index >= bufcount) @@ -264,7 +266,10 @@ static inline void lustre_cfg_init(struct lustre_cfg *lcfg, int cmd, ptr = (char *)lcfg + LCFG_HDR_SIZE(lcfg->lcfg_bufcount); for (i = 0; i < lcfg->lcfg_bufcount; i++) { lcfg->lcfg_buflens[i] = bufs->lcfg_buflen[i]; - LOGL((char *)bufs->lcfg_buf[i], bufs->lcfg_buflen[i], ptr); + if (bufs->lcfg_buf[i]) { + memcpy(ptr, bufs->lcfg_buf[i], bufs->lcfg_buflen[i]); + ptr += cfs_size_round(bufs->lcfg_buflen[i]); + } } } diff --git a/lustre/include/lustre_ioctl.h b/lustre/include/lustre_ioctl.h index bee494a..ecc6590 100644 --- a/lustre/include/lustre_ioctl.h +++ b/lustre/include/lustre_ioctl.h @@ -248,17 +248,25 @@ static inline int obd_ioctl_pack(struct obd_ioctl_data *data, char **pbuf, memcpy(*pbuf, data, sizeof(*data)); ptr = overlay->ioc_bulk; - if (data->ioc_inlbuf1 != NULL) - LOGL(data->ioc_inlbuf1, data->ioc_inllen1, ptr); + if (data->ioc_inlbuf1) { + memcpy(ptr, data->ioc_inlbuf1, data->ioc_inllen1); + ptr += cfs_size_round(data->ioc_inllen1); + } - if (data->ioc_inlbuf2 != NULL) - LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr); + if (data->ioc_inlbuf2) { + memcpy(ptr, data->ioc_inlbuf2, data->ioc_inllen2); + ptr += cfs_size_round(data->ioc_inllen2); + } - if (data->ioc_inlbuf3 != NULL) - LOGL(data->ioc_inlbuf3, data->ioc_inllen3, ptr); + if (data->ioc_inlbuf3) { + memcpy(ptr, data->ioc_inlbuf3, data->ioc_inllen3); + ptr += cfs_size_round(data->ioc_inllen3); + } - if (data->ioc_inlbuf4 != NULL) - LOGL(data->ioc_inlbuf4, data->ioc_inllen4, ptr); + if (data->ioc_inlbuf4) { + memcpy(ptr, data->ioc_inlbuf4, data->ioc_inllen4); + ptr += cfs_size_round(data->ioc_inllen4); + } if (obd_ioctl_is_invalid(overlay)) { fprintf(stderr, "invalid ioctl data: ioc_len = %u, " @@ -290,17 +298,25 @@ obd_ioctl_unpack(struct obd_ioctl_data *data, char *pbuf, int max_len) memcpy(data, pbuf, sizeof(*data)); ptr = overlay->ioc_bulk; - if (data->ioc_inlbuf1 != NULL) - LOGU(data->ioc_inlbuf1, data->ioc_inllen1, ptr); + if (data->ioc_inlbuf1) { + memcpy(data->ioc_inlbuf1, ptr, data->ioc_inllen1); + ptr += cfs_size_round(data->ioc_inllen1); + } - if (data->ioc_inlbuf2 != NULL) - LOGU(data->ioc_inlbuf2, data->ioc_inllen2, ptr); + if (data->ioc_inlbuf2) { + memcpy(data->ioc_inlbuf2, ptr, data->ioc_inllen2); + ptr += cfs_size_round(data->ioc_inllen2); + } - if (data->ioc_inlbuf3 != NULL) - LOGU(data->ioc_inlbuf3, data->ioc_inllen3, ptr); + if (data->ioc_inlbuf3) { + memcpy(data->ioc_inlbuf3, ptr, data->ioc_inllen3); + ptr += cfs_size_round(data->ioc_inllen3); + } - if (data->ioc_inlbuf4 != NULL) - LOGU(data->ioc_inlbuf4, data->ioc_inllen4, ptr); + if (data->ioc_inlbuf4) { + memcpy(data->ioc_inlbuf4, ptr, data->ioc_inllen4); + ptr += cfs_size_round(data->ioc_inllen4); + } return 0; } diff --git a/lustre/ptlrpc/pack_generic.c b/lustre/ptlrpc/pack_generic.c index 8a79a7b..ec9bdca 100644 --- a/lustre/ptlrpc/pack_generic.c +++ b/lustre/ptlrpc/pack_generic.c @@ -202,11 +202,14 @@ void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, __u32 *lens, if (bufs == NULL) return; - ptr = (char *)msg + lustre_msg_hdr_size_v2(count); - for (i = 0; i < count; i++) { - char *tmp = bufs[i]; - LOGL(tmp, lens[i], ptr); - } + ptr = (char *)msg + lustre_msg_hdr_size_v2(count); + for (i = 0; i < count; i++) { + char *tmp = bufs[i]; + + if (tmp) + memcpy(ptr, tmp, lens[i]); + ptr += cfs_size_round(lens[i]); + } } EXPORT_SYMBOL(lustre_init_msg_v2); diff --git a/lustre/tests/it_test.c b/lustre/tests/it_test.c index 7a56b4d..0a4f099 100644 --- a/lustre/tests/it_test.c +++ b/lustre/tests/it_test.c @@ -33,6 +33,7 @@ * * Author: jay */ +#include #include #include #include @@ -45,7 +46,13 @@ #include +/* + * it_test.c is built against one of the lustre kernel + * files (interval_tree.c). This pulls in kernel specific + * definitions which are not of interest for user land. + */ #define EXPORT_SYMBOL(s) +#define LASSERT assert #include <../ldlm/interval_tree.c> diff --git a/lustre/utils/gss/sk_utils.c b/lustre/utils/gss/sk_utils.c index dda80fd..596e3af 100644 --- a/lustre/utils/gss/sk_utils.c +++ b/lustre/utils/gss/sk_utils.c @@ -1004,8 +1004,10 @@ int sk_kdf(gss_buffer_desc *derived_key , gss_buffer_desc *origin_key, return rc; } - LASSERT(sk_hmac_types[hmac_alg].sht_bytes == - tmp_hash.length); + if (sk_hmac_types[hmac_alg].sht_bytes != tmp_hash.length) { + free(tmp_hash.value); + return -EINVAL; + } bytes = (remain < tmp_hash.length) ? remain : tmp_hash.length; memcpy(keydata, tmp_hash.value, bytes); diff --git a/lustre/utils/libiam.c b/lustre/utils/libiam.c index 1185c16..b0649ac 100644 --- a/lustre/utils/libiam.c +++ b/lustre/utils/libiam.c @@ -45,7 +45,6 @@ #include #include #include -#include #include #include diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index 8db34b3..6742d45 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -2716,9 +2716,10 @@ static int print_failed_tgt(struct find_param *param, char *path, int type) { struct obd_statfs stat_buf; struct obd_uuid uuid_buf; - int ret; + int ret; - LASSERT(type == LL_STATFS_LOV || type == LL_STATFS_LMV); + if (type != LL_STATFS_LOV && type != LL_STATFS_LMV) + return -EINVAL; memset(&stat_buf, 0, sizeof(struct obd_statfs)); memset(&uuid_buf, 0, sizeof(struct obd_uuid)); @@ -2746,7 +2747,8 @@ static int cb_find_init(char *path, DIR *parent, DIR **dirp, int checked_type = 0; int ret = 0; - LASSERT(parent != NULL || dir != NULL); + if (parent == NULL && dir == NULL) + return -EINVAL; param->fp_lmd->lmd_lmm.lmm_stripe_count = 0; @@ -3082,7 +3084,9 @@ static int cb_migrate_mdt_init(char *path, DIR *parent, DIR **dirp, char *filename; bool retry = false; - LASSERT(parent != NULL || dirp != NULL); + if (parent == NULL && dirp == NULL) + return -EINVAL; + if (dirp != NULL) closedir(*dirp); @@ -3201,7 +3205,8 @@ static int cb_get_mdt_index(char *path, DIR *parent, DIR **dirp, void *data, int ret; int mdtidx; - LASSERT(parent != NULL || d != NULL); + if (parent == NULL && d == NULL) + return -EINVAL; if (d != NULL) { ret = llapi_file_fget_mdtidx(dirfd(d), &mdtidx); @@ -3263,7 +3268,8 @@ static int cb_getstripe(char *path, DIR *parent, DIR **dirp, void *data, DIR *d = dirp == NULL ? NULL : *dirp; int ret = 0; - LASSERT(parent != NULL || d != NULL); + if (parent == NULL && d == NULL) + return -EINVAL; if (param->fp_obd_uuid) { param->fp_quiet = 1; diff --git a/lustre/utils/lustre_lfsck.c b/lustre/utils/lustre_lfsck.c index 2c0f369..f399a32 100644 --- a/lustre/utils/lustre_lfsck.c +++ b/lustre/utils/lustre_lfsck.c @@ -240,12 +240,18 @@ static int lfsck_get_dev_name(struct obd_ioctl_data *data, char *device, } ptr = strrchr(param.gl_pathv[0], '-'); - LASSERT(ptr != NULL); + if (ptr == NULL) { + rc = -EINVAL; + goto out; + } for (i = 1; i < param.gl_pathc; i++) { char *ptr2 = strrchr(param.gl_pathv[i], '-'); - LASSERT(ptr2 != NULL); + if (ptr2 == NULL) { + rc = -EINVAL; + goto out; + } if ((ptr - param.gl_pathv[0]) != (ptr2 - param.gl_pathv[i]) || strncmp(param.gl_pathv[0], param.gl_pathv[i], diff --git a/lustre/utils/lustre_rsync.c b/lustre/utils/lustre_rsync.c index ea3ca30..2be588c 100644 --- a/lustre/utils/lustre_rsync.c +++ b/lustre/utils/lustre_rsync.c @@ -103,6 +103,7 @@ * [pfid,tfid,name] tracked from (1) is used for this. */ +#include #include #include #include @@ -118,11 +119,12 @@ #include #include #include +#include +#include #include #include #include -#include #include "lustre_rsync.h" #define REPLICATE_STATUS_VER 1 @@ -909,7 +911,7 @@ int lr_move(struct lr_info *info) int special_dest = 0; char srcpath[PATH_MAX + 1] = ""; - LASSERT(info->is_extended); + assert(info->is_extended); rc_src = lr_get_path(info, info->spfid); if (rc_src < 0 && rc_src != -ENOENT) diff --git a/lustre/utils/mount_lustre.c b/lustre/utils/mount_lustre.c index 1126748..1b36529 100644 --- a/lustre/utils/mount_lustre.c +++ b/lustre/utils/mount_lustre.c @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include diff --git a/lustre/utils/mount_utils.c b/lustre/utils/mount_utils.c index 85ed583..2027b28 100644 --- a/lustre/utils/mount_utils.c +++ b/lustre/utils/mount_utils.c @@ -619,7 +619,7 @@ void unload_backfs_module(struct module_backfs_ops *ops) /* Return true if backfs_ops has operations for the given mount_type. */ int backfs_mount_type_okay(enum ldd_mount_type mount_type) { - if (unlikely(mount_type >= LDD_MT_LAST || mount_type < 0)) { + if (mount_type >= LDD_MT_LAST || mount_type < 0) { fatal(); fprintf(stderr, "fs type out of range %d\n", mount_type); return 0; diff --git a/lustre/utils/obd.c b/lustre/utils/obd.c index 663b5ec..aa99316 100644 --- a/lustre/utils/obd.c +++ b/lustre/utils/obd.c @@ -2776,7 +2776,9 @@ static int check_pool_cmd(enum lcfg_command_type cmd, switch (cmd) { case LCFG_POOL_NEW: { - LASSERT(ostname == NULL); + if (ostname != NULL) + return -EINVAL; + if (rc >= 0) { fprintf(stderr, "Pool %s.%s already exists\n", fsname, poolname); @@ -2785,7 +2787,9 @@ static int check_pool_cmd(enum lcfg_command_type cmd, return 0; } case LCFG_POOL_DEL: { - LASSERT(ostname == NULL); + if (ostname != NULL) + return -EINVAL; + if (rc == 1) { fprintf(stderr, "Pool %s.%s not empty, " "please remove all members\n", diff --git a/lustre/utils/wiretest.c b/lustre/utils/wiretest.c index e09003f..3f2ee70 100644 --- a/lustre/utils/wiretest.c +++ b/lustre/utils/wiretest.c @@ -39,10 +39,15 @@ #include #include -#undef LASSERT -#undef LASSERTF #define LASSERT(cond) if (!(cond)) { printf("failed " #cond "\n"); ret = 1; } #define LASSERTF(cond, fmt, ...) if (!(cond)) { printf("failed '" #cond "'" fmt, ## __VA_ARGS__);ret = 1;} +/* + * Compile-time LASSERT, which verifies correctness at compile-time rather + * than runtime. If "cond" is true, then there are two different cases + * ("(non-zero)" and "0"). If "cond" is false, then there are two identical cases + * ("0" and "0"), which is an error that causes the compiler to complain. + */ +#define CLASSERT(cond) do {switch (1) {case (cond): case 0: break; } } while (0) int ret;