Whamcloud - gitweb
LU-6245 libcfs: use libcfs_private.h only for kernel space 38/22138/11
authorJames Simmons <uja.ornl@yahoo.com>
Wed, 11 Jan 2017 16:24:35 +0000 (11:24 -0500)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 31 Jan 2017 04:07:16 +0000 (04:07 +0000)
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 <uja.ornl@yahoo.com>
Reviewed-on: https://review.whamcloud.com/22138
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Dmitry Eremin <dmitry.eremin@intel.com>
Reviewed-by: Jinshan Xiong <jinshan.xiong@intel.com>
Reviewed-by: Fan Yong <fan.yong@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
19 files changed:
libcfs/include/libcfs/libcfs.h
libcfs/include/libcfs/libcfs_private.h
lustre/include/lprocfs_status.h
lustre/include/lustre/lustre_idl.h
lustre/include/lustre/lustre_ostid.h
lustre/include/lustre/lustre_user.h
lustre/include/lustre_cfg.h
lustre/include/lustre_ioctl.h
lustre/ptlrpc/pack_generic.c
lustre/tests/it_test.c
lustre/utils/gss/sk_utils.c
lustre/utils/libiam.c
lustre/utils/liblustreapi.c
lustre/utils/lustre_lfsck.c
lustre/utils/lustre_rsync.c
lustre/utils/mount_lustre.c
lustre/utils/mount_utils.c
lustre/utils/obd.c
lustre/utils/wiretest.c

index 82d36dd..0f80224 100644 (file)
@@ -110,8 +110,8 @@ void cfs_get_random_bytes(void *buf, int size);
 #endif /* __KERNEL__ */
 
 #include <libcfs/libcfs_debug.h>
-#include <libcfs/libcfs_private.h>
 #ifdef __KERNEL__
+# include <libcfs/libcfs_private.h>
 # include <libcfs/bitmap.h>
 # include <libcfs/libcfs_cpu.h>
 # include <libcfs/libcfs_ioctl.h>
index 22d2a5e..bcd7d56 100644 (file)
@@ -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 <assert.h>
-#  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;
index fb6bbfa..763b9be 100644 (file)
@@ -45,6 +45,7 @@
 #include <linux/spinlock.h>
 #include <linux/seq_file.h>
 
+#include <libcfs/libcfs.h>
 #include <lustre/lustre_idl.h>
 
 struct lprocfs_vars {
index 22e246d..65edd58 100644 (file)
@@ -72,7 +72,6 @@
 #include <asm/byteorder.h>
 #include <linux/types.h>
 
-#include <libcfs/libcfs.h>
 #include <lnet/types.h>
 #include <lustre/lustre_user.h> /* Defn's shared with user-space. */
 #include <lustre_ver.h>
index 5a5d3bc..aebb33e 100644 (file)
@@ -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;
        }
index 4f3f74f..3efc0cb 100644 (file)
@@ -45,6 +45,7 @@
 #include <linux/types.h>
 
 #ifdef __KERNEL__
+# include <linux/fs.h>
 # include <linux/quota.h>
 # include <linux/string.h> /* snprintf() */
 # include <linux/version.h>
index 0685df5..11f1576 100644 (file)
@@ -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]);
+               }
        }
 }
 
index bee494a..ecc6590 100644 (file)
@@ -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;
 }
index 8a79a7b..ec9bdca 100644 (file)
@@ -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);
 
index 7a56b4d..0a4f099 100644 (file)
@@ -33,6 +33,7 @@
  *
  * Author: jay <jxiong@clusterfs.com>
  */
+#include <assert.h>
 #include <errno.h>
 #include <inttypes.h>
 #include <limits.h>
 
 #include <linux/types.h>
 
+/*
+ * 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>
 
index dda80fd..596e3af 100644 (file)
@@ -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);
index 1185c16..b0649ac 100644 (file)
@@ -45,7 +45,6 @@
 #include <string.h>
 #include <endian.h>
 #include <errno.h>
-#include <assert.h>
 #include <sys/ioctl.h>
 #include <sys/types.h>
 
index 8db34b3..6742d45 100644 (file)
@@ -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;
index 2c0f369..f399a32 100644 (file)
@@ -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],
index ea3ca30..2be588c 100644 (file)
  *      [pfid,tfid,name] tracked from (1) is used for this.
  */
 
+#include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <utime.h>
 #include <time.h>
 #include <sys/xattr.h>
+#include <linux/types.h>
 
+#include <libcfs/libcfs_debug.h>
 #include <libcfs/util/string.h>
 #include <libcfs/util/parser.h>
 #include <lustre/lustreapi.h>
-#include <lustre/lustre_idl.h>
 #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)
index 1126748..1b36529 100644 (file)
@@ -48,6 +48,7 @@
 #include <errno.h>
 #include <string.h>
 #include <sys/mount.h>
+#include <sys/param.h>
 #include <lustre_ver.h>
 #include <ctype.h>
 #include <limits.h>
index 85ed583..2027b28 100644 (file)
@@ -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;
index 663b5ec..aa99316 100644 (file)
@@ -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",
index e09003f..3f2ee70 100644 (file)
 #include <lustre/lustre_lfsck_user.h>
 #include <lustre_disk.h>
 
-#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;