From 3b84a1ee5213563945225854a50e9037bb9646db Mon Sep 17 00:00:00 2001 From: "John L. Hammond" Date: Wed, 15 Apr 2015 12:54:51 -0400 Subject: [PATCH] LU-6245 libcfs: remove libcfsutil.h Remove libcfsutil.h, fixup some headers, rename libcfs/util/libcfsutil_ioctl.h to libcfs/util/ioctl.h, remove libcfs/util/platform.h, remove libcfs/util/util.c, do some other stuff. With these changes libcfs.h can be removed from libcfs userland library. Signed-off-by: John L. Hammond Signed-off-by: James Simmons Change-Id: I23c0531cd1c50a652799ad807d506fda35b22b3b Reviewed-on: http://review.whamcloud.com/14180 Reviewed-by: Dmitry Eremin Reviewed-by: frank zago Tested-by: Jenkins Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- libcfs/include/libcfs/Makefile.am | 1 - libcfs/include/libcfs/libcfs.h | 7 +- libcfs/include/libcfs/libcfs_ioctl.h | 106 +++------ libcfs/include/libcfs/libcfs_private.h | 22 -- libcfs/include/libcfs/libcfsutil.h | 58 ----- libcfs/include/libcfs/types.h | 1 + libcfs/include/libcfs/user-prim.h | 7 - libcfs/include/libcfs/util/Makefile.am | 2 +- .../libcfs/util/{libcfsutil_ioctl.h => ioctl.h} | 23 +- libcfs/include/libcfs/util/platform.h | 76 ------- libcfs/libcfs/autoMakefile.am | 2 +- libcfs/libcfs/linux/linux-module.c | 2 +- libcfs/libcfs/linux/linux-prim.c | 14 -- libcfs/libcfs/module.c | 12 +- libcfs/libcfs/util/Makefile.am | 2 +- libcfs/libcfs/util/l_ioctl.c | 241 ++++----------------- libcfs/libcfs/util/nidstrings.c | 24 +- libcfs/libcfs/util/parser.c | 19 +- libcfs/libcfs/util/util.c | 45 ---- lnet/include/lnet/lib-lnet.h | 16 ++ lnet/include/lnet/nidstr.h | 22 ++ lnet/utils/debug.c | 19 +- lnet/utils/lnetconfig/liblnetconfig.c | 7 +- lnet/utils/lnetctl.c | 15 +- lnet/utils/lst.c | 21 +- lnet/utils/portals.c | 19 +- lustre/utils/lctl.c | 2 +- lustre/utils/lfs.c | 3 +- lustre/utils/lustre_cfg.c | 2 +- lustre/utils/lustre_lfsck.c | 3 +- lustre/utils/lustre_rsync.c | 2 +- lustre/utils/obd.c | 16 +- 32 files changed, 223 insertions(+), 588 deletions(-) delete mode 100644 libcfs/include/libcfs/libcfsutil.h rename libcfs/include/libcfs/util/{libcfsutil_ioctl.h => ioctl.h} (78%) delete mode 100644 libcfs/include/libcfs/util/platform.h delete mode 100644 libcfs/libcfs/util/util.c diff --git a/libcfs/include/libcfs/Makefile.am b/libcfs/include/libcfs/Makefile.am index 8d73baa..794c204 100644 --- a/libcfs/include/libcfs/Makefile.am +++ b/libcfs/include/libcfs/Makefile.am @@ -25,7 +25,6 @@ EXTRA_DIST = \ libcfs_string.h \ libcfs_time.h \ libcfs_workitem.h \ - libcfsutil.h \ list.h \ types.h \ user-bitops.h \ diff --git a/libcfs/include/libcfs/libcfs.h b/libcfs/include/libcfs/libcfs.h index d32d061..98474d9 100644 --- a/libcfs/include/libcfs/libcfs.h +++ b/libcfs/include/libcfs/libcfs.h @@ -249,7 +249,9 @@ void cfs_get_random_bytes(void *buf, int size); #include #include #include -#include +#ifdef __KERNEL__ +# include +#endif /* __KERNEL__ */ #include #include #ifdef __KERNEL__ @@ -276,7 +278,4 @@ static inline void *__container_of(const void *ptr, unsigned long shift) #define _LIBCFS_H -int libcfs_arch_init(void); -void libcfs_arch_cleanup(void); - #endif /* _LIBCFS_H */ diff --git a/libcfs/include/libcfs/libcfs_ioctl.h b/libcfs/include/libcfs/libcfs_ioctl.h index 6d8781f..1ed8766 100644 --- a/libcfs/include/libcfs/libcfs_ioctl.h +++ b/libcfs/include/libcfs/libcfs_ioctl.h @@ -36,7 +36,7 @@ * libcfs/include/libcfs/libcfs_ioctl.h * * Low-level ioctl data structures. Kernel ioctl functions declared here, - * and user space functions are in libcfsutil_ioctl.h. + * and user space functions are in libcfs/util/ioctl.h. * */ @@ -101,22 +101,6 @@ do { \ (data).hdr.ioc_len = sizeof(data); \ } while (0) - -#ifdef __KERNEL__ - -struct libcfs_ioctl_handler { - struct list_head item; - int (*handle_ioctl)(unsigned int cmd, struct libcfs_ioctl_hdr *hdr); -}; - -#define DECLARE_IOCTL_HANDLER(ident, func) \ - static struct libcfs_ioctl_handler ident = { \ - /* .item = */ LIST_HEAD_INIT(ident.item), \ - /* .handle_ioctl = */ func \ - } - -#endif - /* 'f' ioctls are defined in lustre_ioctl.h and lustre_user.h except for: */ #define LIBCFS_IOC_DEBUG_MASK _IOWR('f', 250, long) #define IOCTL_LIBCFS_TYPE long @@ -190,89 +174,55 @@ struct libcfs_ioctl_handler { static inline int libcfs_ioctl_packlen(struct libcfs_ioctl_data *data) { int len = sizeof(*data); - len += cfs_size_round(data->ioc_inllen1); - len += cfs_size_round(data->ioc_inllen2); + len += (data->ioc_inllen1 + 7) & ~7; + len += (data->ioc_inllen2 + 7) & ~7; return len; } static inline bool libcfs_ioctl_is_invalid(struct libcfs_ioctl_data *data) { - if (data->ioc_hdr.ioc_len > (1<<30)) { - CERROR("LIBCFS ioctl: ioc_len larger than 1<<30\n"); + if (data->ioc_hdr.ioc_len > (1<<30)) return 1; - } - if (data->ioc_inllen1 > (1<<30)) { - CERROR("LIBCFS ioctl: ioc_inllen1 larger than 1<<30\n"); + + if (data->ioc_inllen1 > (1<<30)) return 1; - } - if (data->ioc_inllen2 > (1<<30)) { - CERROR("LIBCFS ioctl: ioc_inllen2 larger than 1<<30\n"); + + if (data->ioc_inllen2 > (1<<30)) return 1; - } - if (data->ioc_inlbuf1 && data->ioc_inllen1 == 0) { - CERROR("LIBCFS ioctl: inlbuf1 pointer but 0 length\n"); + + if (data->ioc_inlbuf1 && data->ioc_inllen1 == 0) return 1; - } - if (data->ioc_inlbuf2 && data->ioc_inllen2 == 0) { - CERROR("LIBCFS ioctl: inlbuf2 pointer but 0 length\n"); + + if (data->ioc_inlbuf2 && data->ioc_inllen2 == 0) return 1; - } - if (data->ioc_pbuf1 && data->ioc_plen1 == 0) { - CERROR("LIBCFS ioctl: pbuf1 pointer but 0 length\n"); + + if (data->ioc_pbuf1 && data->ioc_plen1 == 0) return 1; - } - if (data->ioc_pbuf2 && data->ioc_plen2 == 0) { - CERROR("LIBCFS ioctl: pbuf2 pointer but 0 length\n"); + + if (data->ioc_pbuf2 && data->ioc_plen2 == 0) return 1; - } - if (data->ioc_plen1 && data->ioc_pbuf1 == NULL) { - CERROR("LIBCFS ioctl: plen1 nonzero but no pbuf1 pointer\n"); + + if (data->ioc_plen1 && data->ioc_pbuf1 == NULL) return 1; - } - if (data->ioc_plen2 && data->ioc_pbuf2 == NULL) { - CERROR("LIBCFS ioctl: plen2 nonzero but no pbuf2 pointer\n"); + + if (data->ioc_plen2 && data->ioc_pbuf2 == NULL) return 1; - } - if ((__u32)libcfs_ioctl_packlen(data) != data->ioc_hdr.ioc_len) { - CERROR("LIBCFS ioctl: packlen != ioc_len\n"); + + if ((__u32)libcfs_ioctl_packlen(data) != data->ioc_hdr.ioc_len) return 1; - } + if (data->ioc_inllen1 && - data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') { - CERROR("LIBCFS ioctl: inlbuf1 not 0 terminated\n"); + data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') return 1; - } + if (data->ioc_inllen2 && - data->ioc_bulk[cfs_size_round(data->ioc_inllen1) + - data->ioc_inllen2 - 1] != '\0') { - CERROR("LIBCFS ioctl: inlbuf2 not 0 terminated\n"); + data->ioc_bulk[((data->ioc_inllen1 + 7) & ~7) + + data->ioc_inllen2 - 1] != '\0') return 1; - } - return 0; -} - -#ifdef __KERNEL__ - -extern int libcfs_register_ioctl(struct libcfs_ioctl_handler *hand); -extern int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand); -extern int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp, - struct libcfs_ioctl_hdr __user *uparam); -static inline int libcfs_ioctl_popdata(struct libcfs_ioctl_hdr *hdr, - struct libcfs_ioctl_hdr __user *uparam) -{ - if (copy_to_user(uparam, hdr, hdr->ioc_len)) - return -EFAULT; - return 0; -} - -static inline void libcfs_ioctl_freedata(struct libcfs_ioctl_hdr *hdr) -{ - LIBCFS_FREE(hdr, hdr->ioc_len); + return 0; } -#endif - extern int libcfs_ioctl_data_adjust(struct libcfs_ioctl_data *data); #endif /* __LIBCFS_IOCTL_H__ */ diff --git a/libcfs/include/libcfs/libcfs_private.h b/libcfs/include/libcfs/libcfs_private.h index 662630d..cfb146d 100644 --- a/libcfs/include/libcfs/libcfs_private.h +++ b/libcfs/include/libcfs/libcfs_private.h @@ -594,28 +594,6 @@ do { \ ptr += cfs_size_round(len); \ } while (0) -/** - * Lustre Network Driver types. - */ -enum { - /* Only add to these values (i.e. don't ever change or redefine them): - * network addresses depend on them... */ - QSWLND = 1, - SOCKLND = 2, - GMLND = 3, /* obsolete, keep it so that libcfs_nid2str works */ - PTLLND = 4, - O2IBLND = 5, - CIBLND = 6, - OPENIBLND = 7, - IIBLND = 8, - LOLND = 9, - RALND = 10, - VIBLND = 11, - MXLND = 12, - GNILND = 13, - GNIIPLND = 14, -}; - extern struct cfs_psdev_ops libcfs_psdev_ops; extern struct miscdevice libcfs_dev; extern struct cfs_wi_sched *cfs_sched_rehash; diff --git a/libcfs/include/libcfs/libcfsutil.h b/libcfs/include/libcfs/libcfsutil.h deleted file mode 100644 index cd2783f..0000000 --- a/libcfs/include/libcfs/libcfsutil.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * GPL HEADER START - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 only, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License version 2 for more details (a copy is included - * in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU General Public License - * version 2 along with this program; If not, see - * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf - * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. - * - * GPL HEADER END - */ -/* - * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - */ -/* - * This file is part of Lustre, http://www.lustre.org/ - * Lustre is a trademark of Sun Microsystems, Inc. - * - * libcfs/include/libcfs/libcfsutil.h - * - * A library used for userspace utilities. - * - */ - -#ifndef __LIBCFSUTIL_H__ -#define __LIBCFSUTIL_H__ - -#ifndef LUSTRE_UTILS -#define LUSTRE_UTILS 1 -#endif - -#include - -#include -#include -#include - -/* - * Defined by libcfs/libcfs/util/util.c - */ -int libcfs_tcd_type_max(void); - -#endif /* __LIBCFSUTIL_H__ */ diff --git a/libcfs/include/libcfs/types.h b/libcfs/include/libcfs/types.h index b4fd790..7e3fe2f 100644 --- a/libcfs/include/libcfs/types.h +++ b/libcfs/include/libcfs/types.h @@ -33,6 +33,7 @@ #ifndef __KERNEL__ # include /* LONG_MAX */ # include /* bool */ +# include /* size_t */ #endif /* !__KERNEL__ */ #if defined(_ASM_GENERIC_INT_L64_H) diff --git a/libcfs/include/libcfs/user-prim.h b/libcfs/include/libcfs/user-prim.h index eb5bb5a..1752694 100644 --- a/libcfs/include/libcfs/user-prim.h +++ b/libcfs/include/libcfs/user-prim.h @@ -235,11 +235,4 @@ struct group_info{ }; #define get_random_bytes(val, size) (*val) = 0 -/* utility libcfs init/fini entries */ -static inline int libcfs_arch_init(void) { - return 0; -} -static inline void libcfs_arch_cleanup(void) { -} - #endif /* __LIBCFS_USER_PRIM_H__ */ diff --git a/libcfs/include/libcfs/util/Makefile.am b/libcfs/include/libcfs/util/Makefile.am index d019394..8bde63f 100644 --- a/libcfs/include/libcfs/util/Makefile.am +++ b/libcfs/include/libcfs/util/Makefile.am @@ -1 +1 @@ -EXTRA_DIST = parser.h platform.h string.h libcfsutil_ioctl.h +EXTRA_DIST = ioctl.h parser.h string.h diff --git a/libcfs/include/libcfs/util/libcfsutil_ioctl.h b/libcfs/include/libcfs/util/ioctl.h similarity index 78% rename from libcfs/include/libcfs/util/libcfsutil_ioctl.h rename to libcfs/include/libcfs/util/ioctl.h index 173935a..5bf447b 100644 --- a/libcfs/include/libcfs/util/libcfsutil_ioctl.h +++ b/libcfs/include/libcfs/util/ioctl.h @@ -33,23 +33,26 @@ * This file is part of Lustre, http://www.lustre.org/ * Lustre is a trademark of Sun Microsystems, Inc. * - * libcfs/include/libcfs/util/libcfsutil_ioctl.h + * libcfs/include/libcfs/util/ioctl.h * * Utility functions for calling ioctls. * */ +#ifndef _LIBCFS_IOCTL_H_ +#define _LIBCFS_IOCTL_H_ -/* FIXME - rename these to libcfs_ */ +#include +#include + +/* Sparse annotation. */ +#define __user +#include + +/* FIXME - rename these to libcfs_ */ int libcfs_ioctl_pack(struct libcfs_ioctl_data *data, char **pbuf, int max); void libcfs_ioctl_unpack(struct libcfs_ioctl_data *data, char *pbuf); -typedef int (ioc_handler_t)(int dev_id, unsigned int opc, void *buf); -void set_ioc_handler(ioc_handler_t *handler); -int register_ioc_dev(int dev_id, const char * dev_name, int major, int minor); +int register_ioc_dev(int dev_id, const char *dev_name, int major, int minor); void unregister_ioc_dev(int dev_id); -int set_ioctl_dump(char * file); int l_ioctl(int dev_id, unsigned int opc, void *buf); -int parse_dump(char * dump_file, ioc_handler_t ioc_func); -int jt_ioc_dump(int argc, char **argv); -extern char *dump_filename; -int dump(int dev_id, unsigned int opc, void *buf); +#endif diff --git a/libcfs/include/libcfs/util/platform.h b/libcfs/include/libcfs/util/platform.h deleted file mode 100644 index 62aaf3f..0000000 --- a/libcfs/include/libcfs/util/platform.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * GPL HEADER START - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 only, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License version 2 for more details (a copy is included - * in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU General Public License - * version 2 along with this program; If not, see - * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf - * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. - * - * GPL HEADER END - */ -/* - * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - */ -/* - * This file is part of Lustre, http://www.lustre.org/ - * Lustre is a trademark of Sun Microsystems, Inc. - * - * libcfs/include/libcfs/libcfsutil.h - * - * A portability layer for multi-threaded userspace applications. - * - */ - -#ifndef __LUSTRE_UTILS_PLATFORM_H -#define __LUSTRE_UTILS_PLATFORM_H - - -#ifdef HAVE_LIBREADLINE -#define READLINE_LIBRARY -#include - -/* completion_matches() is #if 0-ed out in modern glibc */ - -#ifndef completion_matches -# define completion_matches rl_completion_matches -#endif -extern void using_history(void); -extern void stifle_history(int); -extern void add_history(char *); -#endif /* HAVE_LIBREADLINE */ - -#include -#include -#if HAVE_LIBPTHREAD -#include -#include -#include - -typedef pthread_mutex_t l_mutex_t; -typedef pthread_cond_t l_cond_t; -#define l_mutex_init(s) pthread_mutex_init(s, NULL) -#define l_mutex_lock(s) pthread_mutex_lock(s) -#define l_mutex_unlock(s) pthread_mutex_unlock(s) -#define l_cond_init(c) pthread_cond_init(c, NULL) -#define l_cond_broadcast(c) pthread_cond_broadcast(c) -#define l_cond_wait(c, s) pthread_cond_wait(c, s) -#endif - - -#endif diff --git a/libcfs/libcfs/autoMakefile.am b/libcfs/libcfs/autoMakefile.am index 4a04674..b706b52 100644 --- a/libcfs/libcfs/autoMakefile.am +++ b/libcfs/libcfs/autoMakefile.am @@ -47,7 +47,7 @@ libcfs_a_CFLAGS = $(LLCFLAGS) if UTILS lib_LIBRARIES = libcfsutil.a -libcfsutil_a_SOURCES = util/parser.c util/l_ioctl.c util/util.c +libcfsutil_a_SOURCES = util/parser.c util/l_ioctl.c libcfsutil_a_CPPFLAGS = $(LLCPPFLAGS) libcfsutil_a_CFLAGS = $(LLCFLAGS) -DLUSTRE_UTILS=1 endif diff --git a/libcfs/libcfs/linux/linux-module.c b/libcfs/libcfs/linux/linux-module.c index 7175e44..970283e 100644 --- a/libcfs/libcfs/linux/linux-module.c +++ b/libcfs/libcfs/linux/linux-module.c @@ -96,7 +96,7 @@ int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp, RETURN(0); failed: - libcfs_ioctl_freedata(*hdr_pp); + LIBCFS_FREE(*hdr_pp, hdr.ioc_len); RETURN(err); } diff --git a/libcfs/libcfs/linux/linux-prim.c b/libcfs/libcfs/linux/linux-prim.c index 2f1eec1..0a617df 100644 --- a/libcfs/libcfs/linux/linux-prim.c +++ b/libcfs/libcfs/linux/linux-prim.c @@ -167,20 +167,6 @@ cfs_clear_sigpending(void) spin_unlock_irqrestore(¤t->sighand->siglock, flags); } -int -libcfs_arch_init(void) -{ - return 0; -} - -void -libcfs_arch_cleanup(void) -{ - return; -} - -EXPORT_SYMBOL(libcfs_arch_init); -EXPORT_SYMBOL(libcfs_arch_cleanup); EXPORT_SYMBOL(cfs_enter_debugger); EXPORT_SYMBOL(cfs_block_allsigs); EXPORT_SYMBOL(cfs_block_sigs); diff --git a/libcfs/libcfs/module.c b/libcfs/libcfs/module.c index 767bc07..a00679c 100644 --- a/libcfs/libcfs/module.c +++ b/libcfs/libcfs/module.c @@ -288,15 +288,17 @@ static int libcfs_ioctl(struct cfs_psdev_file *pfile, if (err == -EINVAL) continue; - if (err == 0) - err = libcfs_ioctl_popdata(hdr, uparam); + if (err == 0) { + if (copy_to_user(uparam, hdr, hdr->ioc_len)) + err = -EFAULT; + } break; } up_read(&ioctl_list_sem); break; } } out: - libcfs_ioctl_freedata(hdr); + LIBCFS_FREE(hdr, hdr->ioc_len); RETURN(err); } @@ -316,8 +318,6 @@ static int init_libcfs_module(void) { int rc; - libcfs_arch_init(); - rc = libcfs_debug_init(5 * 1024 * 1024); if (rc < 0) { printk(KERN_ERR "LustreError: libcfs_debug_init: %d\n", rc); @@ -408,8 +408,6 @@ static void exit_libcfs_module(void) if (rc) printk(KERN_ERR "LustreError: libcfs_debug_cleanup: %d\n", rc); - - libcfs_arch_cleanup(); } cfs_module(libcfs, "1.0.0", init_libcfs_module, exit_libcfs_module); diff --git a/libcfs/libcfs/util/Makefile.am b/libcfs/libcfs/util/Makefile.am index baa1f5a..311f4aa 100644 --- a/libcfs/libcfs/util/Makefile.am +++ b/libcfs/libcfs/util/Makefile.am @@ -1 +1 @@ -EXTRA_DIST = parser.c l_ioctl.c nidstrings.c string.c util.c +EXTRA_DIST = parser.c l_ioctl.c nidstrings.c string.c diff --git a/libcfs/libcfs/util/l_ioctl.c b/libcfs/libcfs/util/l_ioctl.c index 76b4f12..4fa4ab1 100644 --- a/libcfs/libcfs/util/l_ioctl.c +++ b/libcfs/libcfs/util/l_ioctl.c @@ -22,13 +22,20 @@ #define __USE_FILE_OFFSET64 +#include +#include +#include +#include +#include #include #include -#include -#include +#include +#include +#include +#include -static ioc_handler_t do_ioctl; /* forward ref */ -static ioc_handler_t *current_ioc_handler = &do_ioctl; +#include +#include struct ioc_dev { const char * dev_name; @@ -45,28 +52,17 @@ struct dump_hdr { unsigned int opc; }; -char *dump_filename; - -void -set_ioc_handler (ioc_handler_t *handler) -{ - if (handler == NULL) - current_ioc_handler = do_ioctl; - else - current_ioc_handler = handler; -} - /* Catamount has no , so just define it here */ #ifndef MKDEV # define MKDEV(a,b) (((a) << 8) | (b)) #endif static int -open_ioc_dev(int dev_id) +open_ioc_dev(int dev_id) { const char * dev_name; - if (dev_id < 0 || + if (dev_id < 0 || dev_id >= sizeof(ioc_dev_list) / sizeof(ioc_dev_list[0])) return -EINVAL; @@ -103,13 +99,12 @@ open_ioc_dev(int dev_id) } -static int -do_ioctl(int dev_id, unsigned int opc, void *buf) +int l_ioctl(int dev_id, unsigned int opc, void *buf) { int fd, rc; - + fd = open_ioc_dev(dev_id); - if (fd < 0) + if (fd < 0) return fd; rc = ioctl(fd, opc, buf); @@ -117,63 +112,12 @@ do_ioctl(int dev_id, unsigned int opc, void *buf) return rc; } -static FILE * -get_dump_file() -{ - FILE *fp = NULL; - - if (!dump_filename) { - fprintf(stderr, "no dump filename\n"); - } else - fp = fopen(dump_filename, "a"); - return fp; -} - -/* - * The dump file should start with a description of which devices are - * used, but for now it will assume whatever app reads the file will - * know what to do. */ -int -dump(int dev_id, unsigned int opc, void *buf) -{ - FILE *fp; - struct dump_hdr dump_hdr; - struct libcfs_ioctl_hdr * ioc_hdr = (struct libcfs_ioctl_hdr *) buf; - int rc; - - printf("dumping opc %x to %s\n", opc, dump_filename); - - - dump_hdr.magic = 0xdeadbeef; - dump_hdr.dev_id = dev_id; - dump_hdr.opc = opc; - - fp = get_dump_file(); - if (fp == NULL) { - fprintf(stderr, "%s: %s\n", dump_filename, - strerror(errno)); - return -EINVAL; - } - - rc = fwrite(&dump_hdr, sizeof(dump_hdr), 1, fp); - if (rc == 1) - rc = fwrite(buf, ioc_hdr->ioc_len, 1, fp); - fclose(fp); - if (rc != 1) { - fprintf(stderr, "%s: %s\n", dump_filename, - strerror(errno)); - return -EINVAL; - } - - return 0; -} - /* register a device to send ioctls to. */ -int -register_ioc_dev(int dev_id, const char * dev_name, int major, int minor) +int +register_ioc_dev(int dev_id, const char *dev_name, int major, int minor) { - if (dev_id < 0 || + if (dev_id < 0 || dev_id >= sizeof(ioc_dev_list) / sizeof(ioc_dev_list[0])) return -EINVAL; @@ -183,12 +127,12 @@ register_ioc_dev(int dev_id, const char * dev_name, int major, int minor) ioc_dev_list[dev_id].dev_fd = -1; ioc_dev_list[dev_id].dev_major = major; ioc_dev_list[dev_id].dev_minor = minor; - + return dev_id; } void -unregister_ioc_dev(int dev_id) +unregister_ioc_dev(int dev_id) { if (dev_id < 0 || dev_id >= sizeof(ioc_dev_list) / sizeof(ioc_dev_list[0])) @@ -202,120 +146,6 @@ unregister_ioc_dev(int dev_id) ioc_dev_list[dev_id].dev_fd = -1; } -/* If this file is set, then all ioctl buffers will be - appended to the file. */ -int -set_ioctl_dump(char * file) -{ - if (dump_filename) - free(dump_filename); - - dump_filename = strdup(file); - if (dump_filename == NULL) - abort(); - - set_ioc_handler(&dump); - return 0; -} - -int -l_ioctl(int dev_id, unsigned int opc, void *buf) -{ - return current_ioc_handler(dev_id, opc, buf); -} - -/* Read an ioctl dump file, and call the ioc_func for each ioctl buffer - * in the file. For example: - * - * parse_dump("lctl.dump", l_ioctl); - * - * Note: if using l_ioctl, then you also need to register_ioc_dev() for - * each device used in the dump. - */ -int -parse_dump(char * dump_file, ioc_handler_t ioc_func) -{ - int line =0; - char *start, *buf, *end; - struct stat st; - int fd; - - fd = open(dump_file, O_RDONLY); - if (fd < 0) { - fprintf(stderr, "couldn't open %s: %s\n", dump_file, - strerror(errno)); - exit(1); - } - - if (fstat(fd, &st)) { - perror("stat fails"); - exit(1); - } - - if (st.st_size < 1) { - fprintf(stderr, "KML is empty\n"); - exit(1); - } - - start = buf = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE , fd, 0); - end = start + st.st_size; - close(fd); - if (start == MAP_FAILED) { - fprintf(stderr, "can't create file mapping\n"); - exit(1); - } - - while (buf < end) { - struct dump_hdr *dump_hdr = (struct dump_hdr *) buf; - struct libcfs_ioctl_hdr * data; - char tmp[8096]; - int rc; - - line++; - - data = (struct libcfs_ioctl_hdr *) (buf + sizeof(*dump_hdr)); - if (buf + data->ioc_len > end ) { - fprintf(stderr, "dump file overflow, %p + %d > %p\n", buf, - data->ioc_len, end); - return -1; - } -#if 0 - printf ("dump_hdr: %lx data: %lx\n", - (unsigned long)dump_hdr - (unsigned long)buf, (unsigned long)data - (unsigned long)buf); - - printf("%d: opcode %x len: %d ver: %x ", line, dump_hdr->opc, - data->ioc_len, data->ioc_version); -#endif - - memcpy(tmp, data, data->ioc_len); - - rc = ioc_func(dump_hdr->dev_id, dump_hdr->opc, tmp); - if (rc) { - printf("failed: %d\n", rc); - exit(1); - } - - buf += data->ioc_len + sizeof(*dump_hdr); - } - - munmap(start, end - start); - - return 0; -} - -int -jt_ioc_dump(int argc, char **argv) -{ - if (argc > 2) { - fprintf(stderr, "usage: %s [hostname]\n", argv[0]); - return 0; - } - printf("setting dumpfile to: %s\n", argv[1]); - - set_ioctl_dump(argv[1]); - return 0; -} - int libcfs_ioctl_pack(struct libcfs_ioctl_data *data, char **pbuf, int max) { @@ -334,10 +164,17 @@ int libcfs_ioctl_pack(struct libcfs_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_inlbuf2 != NULL) - LOGL(data->ioc_inlbuf2, data->ioc_inllen2, ptr); + if (data->ioc_inlbuf1 != NULL) { + memcpy((char *)ptr, (const char *)data->ioc_inlbuf1, + data->ioc_inllen1); + ptr += ((data->ioc_inllen1 + 7) & ~7); + } + if (data->ioc_inlbuf2 != NULL) { + memcpy((char *)ptr, (const char *)data->ioc_inlbuf2, + data->ioc_inllen2); + ptr += ((data->ioc_inllen2 + 7) & ~7); + } + if (libcfs_ioctl_is_invalid(overlay)) return 1; @@ -357,8 +194,14 @@ libcfs_ioctl_unpack(struct libcfs_ioctl_data *data, char *pbuf) memcpy(data, pbuf, sizeof(*data)); ptr = &overlay->ioc_bulk[0]; - if (data->ioc_inlbuf1 != NULL) - LOGU(data->ioc_inlbuf1, data->ioc_inllen1, ptr); - if (data->ioc_inlbuf2 != NULL) - LOGU(data->ioc_inlbuf2, data->ioc_inllen2, ptr); + if (data->ioc_inlbuf1 != NULL) { + memcpy((char *)data->ioc_inlbuf1, (const char *)ptr, + data->ioc_inllen1); + ptr += ((data->ioc_inllen1 + 7) & ~7); + } + if (data->ioc_inlbuf2 != NULL) { + memcpy((char *)data->ioc_inlbuf2, (const char *)ptr, + data->ioc_inllen2); + ptr += ((data->ioc_inllen2 + 7) & ~7); + } } diff --git a/libcfs/libcfs/util/nidstrings.c b/libcfs/libcfs/util/nidstrings.c index 26c4fec..fbc678b 100644 --- a/libcfs/libcfs/util/nidstrings.c +++ b/libcfs/libcfs/util/nidstrings.c @@ -40,8 +40,15 @@ #define DEBUG_SUBSYSTEM S_LNET +#include +#include +#include +#include +#include +#include + #include -#include +#include #include #ifdef HAVE_GETHOSTBYNAME # include @@ -556,7 +563,7 @@ libcfs_str2nid(const char *str) sep = str + strlen(str); net = LNET_MKNET(SOCKLND, 0); nf = libcfs_lnd2netstrfns(SOCKLND); - LASSERT(nf != NULL); + assert(nf != NULL); } if (!nf->nf_str2addr(str, (int)(sep - str), &addr)) @@ -799,7 +806,8 @@ parse_nidrange(struct cfs_lstr *src, struct list_head *nidlist) return 1; failed: - CWARN("can't parse nidrange: \"%.*s\"\n", tmp.ls_len, tmp.ls_str); + fprintf(stderr, "can't parse nidrange: \"%.*s\"\n", + tmp.ls_len, tmp.ls_str); return 0; } @@ -896,7 +904,7 @@ libcfs_num_match(__u32 addr, struct list_head *numaddr) { struct cfs_expr_list *el; - LASSERT(!list_empty(numaddr)); + assert(!list_empty(numaddr)); el = list_entry(numaddr->next, struct cfs_expr_list, el_link); return cfs_expr_list_match(addr, el); @@ -933,11 +941,11 @@ int cfs_match_nid(lnet_nid_t nid, struct list_head *nidlist) static int libcfs_num_addr_range_print(char *buffer, int count, struct list_head *list) { - int i = 0, j = 0; struct cfs_expr_list *el; + int i = 0, j = 0; list_for_each_entry(el, list, el_link) { - LASSERT(j++ < 1); + assert(j++ < 1); i += cfs_expr_list_print(buffer + i, count - i, el); } return i; @@ -950,7 +958,7 @@ libcfs_ip_addr_range_print(char *buffer, int count, struct list_head *list) struct cfs_expr_list *el; list_for_each_entry(el, list, el_link) { - LASSERT(j++ < 4); + assert(j++ < 4); if (i != 0) i += snprintf(buffer + i, count - i, "."); i += cfs_expr_list_print(buffer + i, count - i, el); @@ -1021,7 +1029,7 @@ int cfs_print_nidlist(char *buffer, int count, struct list_head *nidlist) i += snprintf(buffer + i, count - i, " "); if (nr->nr_all != 0) { - LASSERT(list_empty(&nr->nr_addrranges)); + assert(list_empty(&nr->nr_addrranges)); i += snprintf(buffer + i, count - i, "*"); i += cfs_print_network(buffer + i, count - i, nr); } else { diff --git a/libcfs/libcfs/util/parser.c b/libcfs/libcfs/util/parser.c index 6ca87e0..ae5e082 100644 --- a/libcfs/libcfs/util/parser.c +++ b/libcfs/libcfs/util/parser.c @@ -20,8 +20,23 @@ * */ +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef HAVE_LIBREADLINE +# include +# include +#endif /* HAVE_LIBREADLINE */ +#include +#include + +#include #include -#include static command_t * top_level; /* Top level of commands, initialized by * InitParser */ @@ -236,7 +251,7 @@ static char **command_completion(const char *text, int start, int end) if (*(pos - 1) == ' ') match_tbl = table->pc_sub_cmd; } - return completion_matches(text, command_generator); + return rl_completion_matches(text, command_generator); } #endif diff --git a/libcfs/libcfs/util/util.c b/libcfs/libcfs/util/util.c deleted file mode 100644 index 6bc351f..0000000 --- a/libcfs/libcfs/util/util.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * GPL HEADER START - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 only, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License version 2 for more details (a copy is included - * in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU General Public License - * version 2 along with this program; If not, see - * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf - * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. - * - * GPL HEADER END - */ -/* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - */ -/* - * This file is part of Lustre, http://www.lustre.org/ - * Lustre is a trademark of Sun Microsystems, Inc. - * - * libcfs/libcfs/util/util.c - * - */ - -#include -#include "../tracefile.h" - -int -libcfs_tcd_type_max(void) -{ - return CFS_TCD_TYPE_MAX; -} diff --git a/lnet/include/lnet/lib-lnet.h b/lnet/include/lnet/lib-lnet.h index 5676cdb..94aed03 100644 --- a/lnet/include/lnet/lib-lnet.h +++ b/lnet/include/lnet/lib-lnet.h @@ -481,6 +481,22 @@ int lnet_get_net_config(int idx, struct lnet_ioctl_net_config *net_config); int lnet_get_rtr_pool_cfg(int idx, struct lnet_ioctl_pool_cfg *pool_cfg); +struct libcfs_ioctl_handler { + struct list_head item; + int (*handle_ioctl)(unsigned int cmd, struct libcfs_ioctl_hdr *hdr); +}; + +#define DECLARE_IOCTL_HANDLER(ident, func) \ + static struct libcfs_ioctl_handler ident = { \ + /* .item = */ LIST_HEAD_INIT(ident.item), \ + /* .handle_ioctl = */ func \ + } + +extern int libcfs_register_ioctl(struct libcfs_ioctl_handler *hand); +extern int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand); +extern int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp, + struct libcfs_ioctl_hdr __user *uparam); + void lnet_proc_init(void); void lnet_proc_fini(void); int lnet_rtrpools_alloc(int im_a_router); diff --git a/lnet/include/lnet/nidstr.h b/lnet/include/lnet/nidstr.h index fcfcbfb..a0b3059 100644 --- a/lnet/include/lnet/nidstr.h +++ b/lnet/include/lnet/nidstr.h @@ -29,6 +29,28 @@ #define _LNET_NIDSTRINGS_H #include +/** + * Lustre Network Driver types. + */ +enum { + /* Only add to these values (i.e. don't ever change or redefine them): + * network addresses depend on them... */ + QSWLND = 1, + SOCKLND = 2, + GMLND = 3, + PTLLND = 4, + O2IBLND = 5, + CIBLND = 6, + OPENIBLND = 7, + IIBLND = 8, + LOLND = 9, + RALND = 10, + VIBLND = 11, + MXLND = 12, + GNILND = 13, + GNIIPLND = 14, +}; + struct list_head; #define LNET_NIDSTR_COUNT 1024 /* # of nidstrings */ diff --git a/lnet/utils/debug.c b/lnet/utils/debug.c index c5469eb..49456cf 100644 --- a/lnet/utils/debug.c +++ b/lnet/utils/debug.c @@ -43,7 +43,8 @@ #define _GNU_SOURCE #endif -#include +#include +#include #include static char rawbuf[8192]; @@ -191,19 +192,8 @@ static int applymask(char* procpath, int value) static void applymask_all(unsigned int subs_mask, unsigned int debug_mask) { - if (!dump_filename) { - applymask(SUBSYS_DEBUG_CTL_NAME, subs_mask); - applymask(DEBUG_CTL_NAME, debug_mask); - } else { - struct libcfs_debug_ioctl_data data; - - data.hdr.ioc_len = sizeof(data); - data.hdr.ioc_version = 0; - data.subs = subs_mask; - data.debug = debug_mask; - - dump(OBD_DEV_ID, LIBCFS_IOC_DEBUG_MASK, &data); - } + applymask(SUBSYS_DEBUG_CTL_NAME, subs_mask); + applymask(DEBUG_CTL_NAME, debug_mask); printf("Applied subsystem_debug=%d, debug=%d to /proc/sys/lnet\n", subs_mask, debug_mask); } @@ -368,7 +358,6 @@ readhdr: goto readhdr; if (hdr->ph_len > 4094 || /* is this header bogus? */ - hdr->ph_type >= libcfs_tcd_type_max() || hdr->ph_stack > 65536 || hdr->ph_sec < (1 << 30) || hdr->ph_usec > 1000000000 || diff --git a/lnet/utils/lnetconfig/liblnetconfig.c b/lnet/utils/lnetconfig/liblnetconfig.c index 93d733a..7923ccb 100644 --- a/lnet/utils/lnetconfig/liblnetconfig.c +++ b/lnet/utils/lnetconfig/liblnetconfig.c @@ -33,9 +33,14 @@ * calls the APIs mentioned in 1 */ +#include +#include +#include #include #include -#include +#include +#include +#include #include #include #include diff --git a/lnet/utils/lnetctl.c b/lnet/utils/lnetctl.c index 43ed605..831543d 100644 --- a/lnet/utils/lnetctl.c +++ b/lnet/utils/lnetctl.c @@ -23,12 +23,12 @@ * Author: * Amir Shehata */ - +#include #include #include -#include +#include +#include #include -#include #include "cyaml/cyaml.h" #include "lnetconfig/liblnetconfig.h" @@ -996,14 +996,6 @@ int main(int argc, char **argv) return rc; } - rc = libcfs_arch_init(); - if (rc < 0) { - cYAML_build_error(-1, -1, "lnetctl", "startup", - "cannot initialize libcfs", &err_rc); - cYAML_print_tree2file(stderr, err_rc); - return rc; - } - Parser_init("lnetctl > ", list); if (argc > 1) { rc = Parser_execarg(argc - 1, &argv[1], list); @@ -1013,6 +1005,5 @@ int main(int argc, char **argv) Parser_commands(); errorout: - libcfs_arch_cleanup(); return rc; } diff --git a/lnet/utils/lst.c b/lnet/utils/lst.c index 81803db..da14214 100644 --- a/lnet/utils/lst.c +++ b/lnet/utils/lst.c @@ -37,12 +37,20 @@ * * Author: Liang Zhen */ - +#include #include #include #include - -#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include #include #include #include @@ -3299,10 +3307,6 @@ main(int argc, char **argv) setlinebuf(stdout); - rc = libcfs_arch_init(); - if (rc < 0) - return rc; - rc = lst_initialize(); if (rc < 0) goto errorout; @@ -3310,7 +3314,7 @@ main(int argc, char **argv) rc = ptl_initialize(argc, argv); if (rc < 0) goto errorout; - + Parser_init("lst > ", lst_cmdlist); if (argc != 1) { @@ -3321,6 +3325,5 @@ main(int argc, char **argv) Parser_commands(); errorout: - libcfs_arch_cleanup(); return rc; } diff --git a/lnet/utils/portals.c b/lnet/utils/portals.c index 1f314c9..714cb64 100644 --- a/lnet/utils/portals.c +++ b/lnet/utils/portals.c @@ -19,13 +19,24 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ - -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include -#include -#include unsigned int libcfs_debug; unsigned int libcfs_printk = D_CANTMASK; diff --git a/lustre/utils/lctl.c b/lustre/utils/lctl.c index 58cbae5..9b1d0a3 100644 --- a/lustre/utils/lctl.c +++ b/lustre/utils/lctl.c @@ -42,9 +42,9 @@ #include #include +#include #include #include "obdctl.h" -#include #include static int jt_noop(int argc, char **argv) { diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index edb5676..699d73e 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -66,7 +66,8 @@ #endif #include -#include +#include +#include #include #include diff --git a/lustre/utils/lustre_cfg.c b/lustre/utils/lustre_cfg.c index 3f02d5b..c9e1c20 100644 --- a/lustre/utils/lustre_cfg.c +++ b/lustre/utils/lustre_cfg.c @@ -50,6 +50,7 @@ #include #include +#include #include #include #include @@ -65,7 +66,6 @@ #include "obdctl.h" #include -#include #include static char * lcfg_devname; diff --git a/lustre/utils/lustre_lfsck.c b/lustre/utils/lustre_lfsck.c index 3237680..4cf35d1 100644 --- a/lustre/utils/lustre_lfsck.c +++ b/lustre/utils/lustre_lfsck.c @@ -41,9 +41,10 @@ #include "obdctl.h" #include -#include #include #include +/* Needs to be last to avoid clashes */ +#include static struct option long_opt_start[] = { {"device", required_argument, 0, 'M'}, diff --git a/lustre/utils/lustre_rsync.c b/lustre/utils/lustre_rsync.c index 5d28634..e7b3830 100644 --- a/lustre/utils/lustre_rsync.c +++ b/lustre/utils/lustre_rsync.c @@ -121,7 +121,7 @@ #include #include -#include +#include #include #include #include "lustre_rsync.h" diff --git a/lustre/utils/obd.c b/lustre/utils/obd.c index 87b0d5b..0dc4ed9 100644 --- a/lustre/utils/obd.c +++ b/lustre/utils/obd.c @@ -65,6 +65,9 @@ #include "obdctl.h" #include +#include +#include + #include #include #include @@ -72,7 +75,6 @@ #include #include -#include #include #define MAX_STRING_SIZE 128 @@ -87,8 +89,8 @@ #define MAX_BASE_ID 0xffffffff #define NIDSTRING_LENGTH 64 struct shared_data { - l_mutex_t mutex; - l_cond_t cond; + pthread_mutex_t mutex; + pthread_cond_t cond; int stopping; struct { __u64 counters[MAX_THREADS]; @@ -423,22 +425,22 @@ out: static inline void shmem_lock(void) { - l_mutex_lock(&shared_data->mutex); + pthread_mutex_lock(&shared_data->mutex); } static inline void shmem_unlock(void) { - l_mutex_unlock(&shared_data->mutex); + pthread_mutex_unlock(&shared_data->mutex); } static inline void shmem_wait(void) { - l_cond_wait(&shared_data->cond, &shared_data->mutex); + pthread_cond_wait(&shared_data->cond, &shared_data->mutex); } static inline void shmem_wakeup_all(void) { - l_cond_broadcast(&shared_data->cond); + pthread_cond_broadcast(&shared_data->cond); } static inline void shmem_reset(int total_threads) -- 1.8.3.1