From 988397ba01dde0cb30e5922af714ddaeed017dba Mon Sep 17 00:00:00 2001 From: "John L. Hammond" Date: Mon, 6 Oct 2014 09:40:12 -0400 Subject: [PATCH 1/1] LU-2675 libcfs: remove unused libcfs.a code Remove unused code from libcfs.a. Delete the files: libcfs/libcfs/posix/posix-adler.c libcfs/libcfs/posix/posix-crc32.c libcfs/libcfs/posix/posix-debug.c libcfs/libcfs/posix/posix-proc.c libcfs/libcfs/posix/rbtree.c libcfs/libcfs/user-bitops.c libcfs/libcfs/user-crc32pclmul.c libcfs/libcfs/user-crypto.c libcfs/libcfs/user-lock.c libcfs/libcfs/user-mem.c libcfs/libcfs/user-prim.c libcfs/libcfs/user-tcpip.c Signed-off-by: John L. Hammond Change-Id: Ic7b6539147fc66a3cefa0caddfc995474014e098 Reviewed-on: http://review.whamcloud.com/10668 Tested-by: Jenkins Reviewed-by: Bob Glossman Reviewed-by: James Simmons Tested-by: Maloo Reviewed-by: Oleg Drokin --- libcfs/libcfs/autoMakefile.am | 16 +- libcfs/libcfs/posix/Makefile.am | 2 +- libcfs/libcfs/posix/posix-adler.c | 83 ----- libcfs/libcfs/posix/posix-crc32.c | 79 ----- libcfs/libcfs/posix/posix-debug.c | 246 -------------- libcfs/libcfs/posix/posix-proc.c | 44 --- libcfs/libcfs/posix/rbtree.c | 333 ------------------ libcfs/libcfs/user-bitops.c | 111 ------ libcfs/libcfs/user-crc32pclmul.c | 91 ----- libcfs/libcfs/user-crypto.c | 431 ----------------------- libcfs/libcfs/user-lock.c | 391 --------------------- libcfs/libcfs/user-mem.c | 132 -------- libcfs/libcfs/user-prim.c | 404 ---------------------- libcfs/libcfs/user-tcpip.c | 697 -------------------------------------- lustre/autoconf/lustre-core.m4 | 4 - 15 files changed, 4 insertions(+), 3060 deletions(-) delete mode 100644 libcfs/libcfs/posix/posix-adler.c delete mode 100644 libcfs/libcfs/posix/posix-crc32.c delete mode 100644 libcfs/libcfs/posix/posix-debug.c delete mode 100644 libcfs/libcfs/posix/posix-proc.c delete mode 100644 libcfs/libcfs/posix/rbtree.c delete mode 100644 libcfs/libcfs/user-bitops.c delete mode 100644 libcfs/libcfs/user-crc32pclmul.c delete mode 100644 libcfs/libcfs/user-crypto.c delete mode 100644 libcfs/libcfs/user-lock.c delete mode 100644 libcfs/libcfs/user-mem.c delete mode 100644 libcfs/libcfs/user-prim.c delete mode 100644 libcfs/libcfs/user-tcpip.c diff --git a/libcfs/libcfs/autoMakefile.am b/libcfs/libcfs/autoMakefile.am index 604ed12..e1363a5 100644 --- a/libcfs/libcfs/autoMakefile.am +++ b/libcfs/libcfs/autoMakefile.am @@ -40,17 +40,7 @@ SUBDIRS = linux util posix DIST_SUBDIRS = linux util posix noinst_LIBRARIES= libcfs.a -libcfs_a_SOURCES= posix/posix-debug.c user-prim.c user-lock.c user-tcpip.c \ - prng.c user-bitops.c user-mem.c hash.c kernel_user_comm.c \ - workitem.c fail.c libcfs_cpu.c libcfs_mem.c libcfs_lock.c \ - posix/rbtree.c user-crypto.c posix/posix-crc32.c \ - posix/posix-adler.c posix/posix-proc.c heap.c user-string.c - -if HAVE_PCLMULQDQ -if NEED_PCLMULQDQ_CRC32 -libcfs_a_SOURCES += user-crc32pclmul.c linux/crc32-pclmul_asm.S -endif -endif +libcfs_a_SOURCES = user-string.c libcfs_a_CPPFLAGS = $(LLCPPFLAGS) libcfs_a_CFLAGS = $(LLCFLAGS) @@ -73,6 +63,6 @@ endif # MODULES MOSTLYCLEANFILES := @MOSTLYCLEANFILES@ linux-*.c linux/*.o libcfs EXTRA_DIST := $(libcfs-all-objs:%.o=%.c) tracefile.h prng.c \ - user-lock.c user-tcpip.c user-bitops.c user-prim.c workitem.c \ - user-mem.c kernel_user_comm.c fail.c libcfs_cpu.c heap.c \ + workitem.c \ + kernel_user_comm.c fail.c libcfs_cpu.c heap.c \ libcfs_mem.c libcfs_lock.c user-string.c linux/linux-tracefile.h diff --git a/libcfs/libcfs/posix/Makefile.am b/libcfs/libcfs/posix/Makefile.am index 3cfdf7a..0788a75 100644 --- a/libcfs/libcfs/posix/Makefile.am +++ b/libcfs/libcfs/posix/Makefile.am @@ -1,3 +1,3 @@ -EXTRA_DIST = posix-debug.c posix-tracefile.h +EXTRA_DIST = posix-tracefile.h diff --git a/libcfs/libcfs/posix/posix-adler.c b/libcfs/libcfs/posix/posix-adler.c deleted file mode 100644 index 36931d4..0000000 --- a/libcfs/libcfs/posix/posix-adler.c +++ /dev/null @@ -1,83 +0,0 @@ -/* Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly Mark Adler - jloup@gzip.org madler@alumni.caltech.edu - - - The data format used by the zlib library is described by RFCs (Request for - Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt - (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). -*/ -#include - - -#define BASE 65521L /* largest prime smaller than 65536 */ -#define NMAX 5552 -/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ - -#define DO1(buf, i) {s1 += buf[i]; s2 += s1; } -#define DO2(buf, i) DO1(buf, i); DO1(buf, i + 1); -#define DO4(buf, i) DO2(buf, i); DO2(buf, i + 2); -#define DO8(buf, i) DO4(buf, i); DO4(buf, i + 4); -#define DO16(buf) DO8(buf, 0); DO8(buf, 8); - -/* ========================================================================= */ -/* - Update a running Adler-32 checksum with the bytes buf[0..len-1] and - return the updated checksum. If buf is NULL, this function returns - the required initial value for the checksum. - An Adler-32 checksum is almost as reliable as a CRC32 but can be computed - much faster. Usage example: - - uLong adler = adler32(0L, NULL, 0); - - while (read_buffer(buffer, length) != EOF) { - adler = adler32(adler, buffer, length); - } - if (adler != original_adler) error(); -*/ -unsigned long zlib_adler32(unsigned long adler, - const unsigned char *buf, - unsigned int len) -{ - unsigned long s1 = adler & 0xffff; - unsigned long s2 = (adler >> 16) & 0xffff; - int k; - - if (buf == NULL) - return 1L; - - while (len > 0) { - k = len < NMAX ? len : NMAX; - len -= k; - while (k >= 16) { - DO16(buf); - buf += 16; - k -= 16; - } - if (k != 0) - do { - s1 += *buf++; - s2 += s1; - } while (--k); - s1 %= BASE; - s2 %= BASE; - } - return (s2 << 16) | s1; -} diff --git a/libcfs/libcfs/posix/posix-crc32.c b/libcfs/libcfs/posix/posix-crc32.c deleted file mode 100644 index 4937c8c..0000000 --- a/libcfs/libcfs/posix/posix-crc32.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * This file contains part of linux kernel implementation of crc32 - * kernel version 2.6.32 - */ -#include -#include -#define CRCPOLY_LE 0xedb88320 -#define CRC_LE_BITS 8 -#define LE_TABLE_SIZE (1 << CRC_LE_BITS) - -static unsigned int crc32table_le[LE_TABLE_SIZE]; -/** - * crc32init_le() - allocate and initialize LE table data - * - * crc is the crc of the byte i; other entries are filled in based on the - * fact that crctable[i^j] = crctable[i] ^ crctable[j]. - * - */ -void crc32init_le(void) -{ - unsigned i, j; - unsigned int crc = 1; - - crc32table_le[0] = 0; - - for (i = 1 << (CRC_LE_BITS - 1); i; i >>= 1) { - crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0); - for (j = 0; j < LE_TABLE_SIZE; j += 2 * i) - crc32table_le[i + j] = crc ^ crc32table_le[j]; - } -} - -unsigned int crc32_le(unsigned int crc, unsigned char const *p, size_t len) -{ - const unsigned int *b = (unsigned int *)p; - const unsigned int *tab = crc32table_le; - -# if __BYTE_ORDER == __LITTLE_ENDIAN -# define DO_CRC(x) crc = tab[(crc ^ (x)) & 255] ^ (crc>>8) -# else -# define DO_CRC(x) crc = tab[((crc >> 24) ^ (x)) & 255] ^ (crc<<8) -# endif - - crc = cpu_to_le32(crc); - /* Align it */ - if (unlikely(((long)b) & 3 && len)) { - do { - unsigned char *p = (unsigned char *)b; - DO_CRC(*p++); - b = (void *)p; - } while ((--len) && ((long)b) & 3); - } - if (likely(len >= 4)) { - /* load data 32 bits wide, xor data 32 bits wide. */ - size_t save_len = len & 3; - len = len >> 2; - --b; /* use pre increment below(*++b) for speed */ - do { - crc ^= *++b; - DO_CRC(0); - DO_CRC(0); - DO_CRC(0); - DO_CRC(0); - } while (--len); - b++; /* point to next byte(s) */ - len = save_len; - } - /* And the last few bytes */ - if (len) { - do { - unsigned char *p = (unsigned char *)b; - DO_CRC(*p++); - b = (void *)p; - } while (--len); - } - - return le32_to_cpu(crc); -#undef DO_CRC -} diff --git a/libcfs/libcfs/posix/posix-debug.c b/libcfs/libcfs/posix/posix-debug.c deleted file mode 100644 index 32ccdcc..0000000 --- a/libcfs/libcfs/posix/posix-debug.c +++ /dev/null @@ -1,246 +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. - * - * Copyright (c) 2012, Intel Corporation. - */ -/* - * This file is part of Lustre, http://www.lustre.org/ - * Lustre is a trademark of Sun Microsystems, Inc. - * - * libcfs/libcfs/posix/posix_debug.c - * - * Userspace debugging. - * - */ - -# define DEBUG_SUBSYSTEM S_LNET - -#include - -static char debug_file_name[1024]; -unsigned int libcfs_subsystem_debug = ~(S_LNET | S_LND); -unsigned int libcfs_debug = 0; - -#ifdef HAVE_NETDB_H -#include -#endif /* HAVE_NETDB_H */ -struct utsname *tmp_utsname; -static char source_nid[sizeof(tmp_utsname->nodename)]; - -static int source_pid; -int smp_processor_id = 1; -char libcfs_debug_file_path[1024]; -FILE *debug_file_fd; - -int portals_do_debug_dumplog(void *arg) -{ - printf("Look in %s\n", debug_file_name); - return 0; -} - - -void portals_debug_print(void) -{ - return; -} - - -void libcfs_debug_dumplog(void) -{ - printf("Look in %s\n", debug_file_name); - return; -} - -int libcfs_debug_init(unsigned long bufsize) -{ - char *debug_mask = NULL; - char *debug_subsys = NULL; - char *debug_filename; - - struct utsname myname; - - if (uname(&myname) == 0) - strcpy(source_nid, myname.nodename); - source_pid = getpid(); - - /* debug masks */ - debug_mask = getenv("LIBLUSTRE_DEBUG_MASK"); - if (debug_mask) - libcfs_debug = (unsigned int) strtol(debug_mask, NULL, 0); - - debug_subsys = getenv("LIBLUSTRE_DEBUG_SUBSYS"); - if (debug_subsys) - libcfs_subsystem_debug = - (unsigned int) strtol(debug_subsys, NULL, 0); - - debug_filename = getenv("LIBLUSTRE_DEBUG_BASE"); - if (debug_filename) { - strncpy(libcfs_debug_file_path, debug_filename, - sizeof(libcfs_debug_file_path)); - libcfs_debug_file_path[sizeof(libcfs_debug_file_path)-1] = '\0'; - } - - debug_filename = getenv("LIBLUSTRE_DEBUG_FILE"); - if (debug_filename) { - strncpy(debug_file_name, debug_filename, - sizeof(debug_file_name)); - debug_file_name[sizeof(debug_file_name) - 1] = '\0'; - } - - if (debug_file_name[0] == '\0' && libcfs_debug_file_path[0] != '\0') - snprintf(debug_file_name, sizeof(debug_file_name), - "%s-%s-"CFS_TIME_T".log", libcfs_debug_file_path, - source_nid, time(0)); - - if (strcmp(debug_file_name, "stdout") == 0 || - strcmp(debug_file_name, "-") == 0) { - debug_file_fd = stdout; - } else if (strcmp(debug_file_name, "stderr") == 0) { - debug_file_fd = stderr; - } else if (debug_file_name[0] != '\0') { - debug_file_fd = fopen(debug_file_name, "w"); - if (debug_file_fd == NULL) - fprintf(stderr, "%s: unable to open '%s': %s\n", - source_nid, debug_file_name, strerror(errno)); - } - - if (debug_file_fd == NULL) - debug_file_fd = stdout; - - return 0; -} - -int libcfs_debug_cleanup(void) -{ - if (debug_file_fd != stdout && debug_file_fd != stderr) - fclose(debug_file_fd); - return 0; -} - -int libcfs_debug_clear_buffer(void) -{ - return 0; -} - -int libcfs_debug_mark_buffer(const char *text) -{ - - fprintf(debug_file_fd, "*******************************************************************************\n"); - fprintf(debug_file_fd, "DEBUG MARKER: %s\n", text); - fprintf(debug_file_fd, "*******************************************************************************\n"); - - return 0; -} - -int libcfs_debug_msg(struct libcfs_debug_msg_data *msgdata, - const char *format, ...) -{ - va_list args; - int rc; - - va_start(args, format); - rc = libcfs_debug_vmsg2(msgdata, format, args, NULL); - va_end(args); - - return rc; -} - -int -libcfs_debug_vmsg2(struct libcfs_debug_msg_data *msgdata, - const char *format1, va_list args, - const char *format2, ...) -{ - struct timeval tv; - int nob; - int remain; - va_list ap; - char buf[PAGE_CACHE_SIZE]; /* size 4096 used for compatimble - * with linux, where message can`t - * be exceed PAGE_SIZE */ - int console = 0; - char *prefix = "Lustre"; - - if ((!console) && (!debug_file_fd)) { - return 0; - } - - if (msgdata->msg_mask & (D_EMERG | D_ERROR)) - prefix = "LustreError"; - - nob = snprintf(buf, sizeof(buf), "%s: %u-%s:(%s:%d:%s()): ", prefix, - source_pid, source_nid, msgdata->msg_file, - msgdata->msg_line, msgdata->msg_fn); - - remain = sizeof(buf) - nob; - if (format1) { - nob += vsnprintf(&buf[nob], remain, format1, args); - } - - remain = sizeof(buf) - nob; - if ((format2) && (remain > 0)) { - va_start(ap, format2); - nob += vsnprintf(&buf[nob], remain, format2, ap); - va_end(ap); - } - - if (debug_file_fd == NULL) - return 0; - - gettimeofday(&tv, NULL); - - fprintf(debug_file_fd, CFS_TIME_T".%06lu:%u:%s:(%s:%d:%s()): %s", - tv.tv_sec, (unsigned long)tv.tv_usec, source_pid, source_nid, - msgdata->msg_file, msgdata->msg_line, msgdata->msg_fn, buf); - - return 0; -} - -/* - * a helper function for RETURN(): the sole purpose is to save 8-16 bytes - * on the stack - function calling RETURN() doesn't need to allocate two - * additional 'rc' on the stack - */ -long libcfs_log_return(struct libcfs_debug_msg_data *msgdata, long rc) -{ - libcfs_debug_msg(msgdata, "Process leaving (rc=%lu : %ld : %lx)\n", - rc, rc, rc); - return rc; -} - -/* - * a helper function for GOTO(): the sole purpose is to save 8-16 bytes - * on the stack - function calling GOTO() doesn't need to allocate two - * additional 'rc' on the stack - */ -void libcfs_log_goto(struct libcfs_debug_msg_data *msgdata, const char *l, - long_ptr_t rc) -{ - libcfs_debug_msg(msgdata, "Process leaving via %s (rc=" LPLU " : " - LPLD " : " LPLX ")\n", l, (ulong_ptr_t) rc, rc, rc); -} diff --git a/libcfs/libcfs/posix/posix-proc.c b/libcfs/libcfs/posix/posix-proc.c deleted file mode 100644 index 8566ff7..0000000 --- a/libcfs/libcfs/posix/posix-proc.c +++ /dev/null @@ -1,44 +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.gnu.org/licenses/gpl-2.0.html - * - * GPL HEADER END - */ -/* - * Authors: James Simmons - */ -#include - -int seq_printf(struct seq_file *m, const char *f, ...) -{ - va_list args; - int len; - - if (m->count < m->size) { - va_start(args, f); - len = vsnprintf(m->buf + m->count, m->size - m->count, f, args); - va_end(args); - if (m->count + len < m->size) { - m->count += len; - return 0; - } - } - m->count = m->size; - return -1; -} -EXPORT_SYMBOL(seq_printf); diff --git a/libcfs/libcfs/posix/rbtree.c b/libcfs/libcfs/posix/rbtree.c deleted file mode 100644 index 9d0e5bb..0000000 --- a/libcfs/libcfs/posix/rbtree.c +++ /dev/null @@ -1,333 +0,0 @@ -/* - Red Black Trees - (C) 1999 Andrea Arcangeli - (C) 2002 David Woodhouse - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - 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 for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - linux/lib/rbtree.c -*/ - -#include - -static void __rb_rotate_left(struct rb_node *node, struct rb_root *root) -{ - struct rb_node *right = node->rb_right; - struct rb_node *parent = rb_parent(node); - - node->rb_right = right->rb_left; - if (node->rb_right != NULL) - rb_set_parent(right->rb_left, node); - right->rb_left = node; - - rb_set_parent(right, parent); - - if (parent) { - if (node == parent->rb_left) - parent->rb_left = right; - else - parent->rb_right = right; - } else - root->rb_node = right; - rb_set_parent(node, right); -} - -static void __rb_rotate_right(struct rb_node *node, struct rb_root *root) -{ - struct rb_node *left = node->rb_left; - struct rb_node *parent = rb_parent(node); - - node->rb_left = left->rb_right; - if (node->rb_left != NULL) - rb_set_parent(left->rb_right, node); - left->rb_right = node; - - rb_set_parent(left, parent); - - if (parent) { - if (node == parent->rb_right) - parent->rb_right = left; - else - parent->rb_left = left; - } else - root->rb_node = left; - rb_set_parent(node, left); -} - -void rb_insert_color(struct rb_node *node, struct rb_root *root) -{ - struct rb_node *parent, *gparent; - - while ((parent = rb_parent(node)) != NULL && rb_is_red(parent)) { - gparent = rb_parent(parent); - - if (parent == gparent->rb_left) { - register struct rb_node *uncle = gparent->rb_right; - if (uncle && rb_is_red(uncle)) { - rb_set_black(uncle); - rb_set_black(parent); - rb_set_red(gparent); - node = gparent; - continue; - } - - if (parent->rb_right == node) { - register struct rb_node *tmp; - __rb_rotate_left(parent, root); - tmp = parent; - parent = node; - node = tmp; - } - - rb_set_black(parent); - rb_set_red(gparent); - __rb_rotate_right(gparent, root); - } else { - register struct rb_node *uncle = gparent->rb_left; - if (uncle && rb_is_red(uncle)) { - rb_set_black(uncle); - rb_set_black(parent); - rb_set_red(gparent); - node = gparent; - continue; - } - - if (parent->rb_left == node) { - register struct rb_node *tmp; - __rb_rotate_right(parent, root); - tmp = parent; - parent = node; - node = tmp; - } - - rb_set_black(parent); - rb_set_red(gparent); - __rb_rotate_left(gparent, root); - } - } - - rb_set_black(root->rb_node); -} - -static void __rb_erase_color(struct rb_node *node, struct rb_node *parent, - struct rb_root *root) -{ - struct rb_node *ptr; - - while ((!node || rb_is_black(node)) && node != root->rb_node) { - if (parent->rb_left == node) { - ptr = parent->rb_right; - if (rb_is_red(ptr)) { - rb_set_black(ptr); - rb_set_red(parent); - __rb_rotate_left(parent, root); - ptr = parent->rb_right; - } - if ((!ptr->rb_left || rb_is_black(ptr->rb_left)) && - (!ptr->rb_right || rb_is_black(ptr->rb_right))) { - rb_set_red(ptr); - node = parent; - parent = rb_parent(node); - } else { - if (!ptr->rb_right || - rb_is_black(ptr->rb_right)) { - rb_set_black(ptr->rb_left); - rb_set_red(ptr); - __rb_rotate_right(ptr, root); - ptr = parent->rb_right; - } - rb_set_color(ptr, rb_color(parent)); - rb_set_black(parent); - rb_set_black(ptr->rb_right); - __rb_rotate_left(parent, root); - node = root->rb_node; - break; - } - } else { - ptr = parent->rb_left; - if (rb_is_red(ptr)) { - rb_set_black(ptr); - rb_set_red(parent); - __rb_rotate_right(parent, root); - ptr = parent->rb_left; - } - if ((!ptr->rb_left || rb_is_black(ptr->rb_left)) && - (!ptr->rb_right || rb_is_black(ptr->rb_right))) { - rb_set_red(ptr); - node = parent; - parent = rb_parent(node); - } else { - if (!ptr->rb_left || - rb_is_black(ptr->rb_left)) { - rb_set_black(ptr->rb_right); - rb_set_red(ptr); - __rb_rotate_left(ptr, root); - ptr = parent->rb_left; - } - rb_set_color(ptr, rb_color(parent)); - rb_set_black(parent); - rb_set_black(ptr->rb_left); - __rb_rotate_right(parent, root); - node = root->rb_node; - break; - } - } - } - if (node) - rb_set_black(node); -} - -void rb_erase(struct rb_node *node, struct rb_root *root) -{ - struct rb_node *child, *parent; - int color; - - if (!node->rb_left) - child = node->rb_right; - else if (!node->rb_right) - child = node->rb_left; - else { - struct rb_node *old = node, *left; - - node = node->rb_right; - while ((left = node->rb_left) != NULL) - node = left; - - if (rb_parent(old)) { - if (rb_parent(old)->rb_left == old) - rb_parent(old)->rb_left = node; - else - rb_parent(old)->rb_right = node; - } else - root->rb_node = node; - - child = node->rb_right; - parent = rb_parent(node); - color = rb_color(node); - - if (parent == old) { - parent = node; - } else { - if (child) - rb_set_parent(child, parent); - parent->rb_left = child; - - node->rb_right = old->rb_right; - rb_set_parent(old->rb_right, node); - } - - node->rb_parent_color = old->rb_parent_color; - node->rb_left = old->rb_left; - rb_set_parent(old->rb_left, node); - - goto color; - } - - parent = rb_parent(node); - color = rb_color(node); - - if (child) - rb_set_parent(child, parent); - if (parent) { - if (parent->rb_left == node) - parent->rb_left = child; - else - parent->rb_right = child; - } else - root->rb_node = child; - - color: - if (color == RB_BLACK) - __rb_erase_color(child, parent, root); -} - -/* - * This function returns the first node (in sort order) of the tree. - */ -struct rb_node *rb_first(const struct rb_root *root) -{ - struct rb_node *n; - - n = root->rb_node; - if (!n) - return NULL; - while (n->rb_left) - n = n->rb_left; - return n; -} - -struct rb_node *rb_last(const struct rb_root *root) -{ - struct rb_node *n; - - n = root->rb_node; - if (!n) - return NULL; - while (n->rb_right) - n = n->rb_right; - return n; -} - -struct rb_node *rb_next(const struct rb_node *node) -{ - struct rb_node *parent; - - if (rb_parent(node) == node) - return NULL; - - /* If we have a right-hand child, go down and then left as far - as we can. */ - if (node->rb_right) { - node = node->rb_right; - while (node->rb_left) - node = node->rb_left; - return (struct rb_node *)node; - } - - /* No right-hand children. Everything down and left is - smaller than us, so any 'next' node must be in the general - direction of our parent. Go up the tree; any time the - ancestor is a right-hand child of its parent, keep going - up. First time it's a left-hand child of its parent, said - parent is our 'next' node. */ - while ((parent = rb_parent(node)) && node == parent->rb_right) - node = parent; - - return parent; -} - -struct rb_node *rb_prev(const struct rb_node *node) -{ - struct rb_node *parent; - - if (rb_parent(node) == node) - return NULL; - - /* If we have a left-hand child, go down and then right as far - as we can. */ - if (node->rb_left) { - node = node->rb_left; - while (node->rb_right) - node = node->rb_right; - return (struct rb_node *)node; - } - - /* No left-hand children. Go up till we find an ancestor which - is a right-hand child of its parent */ - while ((parent = rb_parent(node)) && node == parent->rb_left) - node = parent; - - return parent; -} diff --git a/libcfs/libcfs/user-bitops.c b/libcfs/libcfs/user-bitops.c deleted file mode 100644 index 65f2da9..0000000 --- a/libcfs/libcfs/user-bitops.c +++ /dev/null @@ -1,111 +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. - * - * Copyright (c) 2012, Intel Corporation. - */ -/* - * This file is part of Lustre, http://www.lustre.org/ - * Lustre is a trademark of Sun Microsystems, Inc. - */ -#ifndef __KERNEL__ - -#include -#include - -#define OFF_BY_START(start) ((start)/BITS_PER_LONG) - -unsigned long find_next_bit(unsigned long *addr, - unsigned long size, unsigned long offset) -{ - unsigned long *word, *last; - unsigned long first_bit, bit, base; - - word = addr + OFF_BY_START(offset); - last = addr + OFF_BY_START(size-1); - first_bit = offset % BITS_PER_LONG; - base = offset - first_bit; - - if (offset >= size) - return size; - if (first_bit != 0) { - int tmp = (*word++) & (~0UL << first_bit); - bit = __cfs_ffs(tmp); - if (bit < BITS_PER_LONG) - goto found; - word++; - base += BITS_PER_LONG; - } - while (word <= last) { - if (*word != 0UL) { - bit = __cfs_ffs(*word); - goto found; - } - word++; - base += BITS_PER_LONG; - } - return size; -found: - return base + bit; -} - -unsigned long find_next_zero_bit(unsigned long *addr, - unsigned long size, unsigned long offset) -{ - unsigned long *word, *last; - unsigned long first_bit, bit, base; - - word = addr + OFF_BY_START(offset); - last = addr + OFF_BY_START(size-1); - first_bit = offset % BITS_PER_LONG; - base = offset - first_bit; - - if (offset >= size) - return size; - if (first_bit != 0) { - int tmp = (*word++) & (~0UL << first_bit); - bit = ffz(tmp); - if (bit < BITS_PER_LONG) - goto found; - word++; - base += BITS_PER_LONG; - } - while (word <= last) { - if (*word != ~0UL) { - bit = ffz(*word); - goto found; - } - word++; - base += BITS_PER_LONG; - } - return size; -found: - return base + bit; -} - -#endif diff --git a/libcfs/libcfs/user-crc32pclmul.c b/libcfs/libcfs/user-crc32pclmul.c deleted file mode 100644 index 720459d..0000000 --- a/libcfs/libcfs/user-crc32pclmul.c +++ /dev/null @@ -1,91 +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.gnu.org/licenses - * - * Please visit http://www.xyratex.com/contact if you need additional - * information or have any questions. - * - * GPL HEADER END - */ - -/* - * Copyright 2012 Xyratex Technology Limited - * - */ - -#include -#include -#include - -#define CHKSUM_BLOCK_SIZE 1 -#define CHKSUM_DIGEST_SIZE 4 - -#define PCLMUL_MIN_LEN 64L /* minimum size of buffer - * for crc32_pclmul_le_16 */ -#define SCALE_F 16L /* size of xmm register */ -#define SCALE_F_MASK (SCALE_F - 1) - -unsigned int crc32_pclmul_le(unsigned int crc, unsigned char const *p, - size_t len) -{ - unsigned int iquotient; - unsigned int iremainder; - unsigned int prealign; - - if (len < PCLMUL_MIN_LEN + SCALE_F_MASK) - return crc32_le(crc, p, len); - - if ((long)p & SCALE_F_MASK) { - /* align p to 16 byte */ - prealign = SCALE_F - ((long)p & SCALE_F_MASK); - - crc = crc32_le(crc, p, prealign); - len -= prealign; - p = (unsigned char *)(((unsigned long)p + SCALE_F_MASK) & - ~SCALE_F_MASK); - } - iquotient = len & (~SCALE_F_MASK); - iremainder = len & SCALE_F_MASK; - - crc = crc32_pclmul_le_16(p, iquotient, crc); - - if (iremainder) - crc = crc32_le(crc, p + iquotient, iremainder); - - return crc; -} -#ifndef bit_PCLMUL -#define bit_PCLMUL (1 << 1) -#endif - -int crc32_pclmul_init(void) -{ - unsigned int eax, ebx, ecx, edx, level; - - eax = ebx = ecx = edx = 0; - level = 1; - /* get cpuid */ - __asm__ ("xchg{l}\t{%%}ebx, %1\n\t" \ - "cpuid\n\t" \ - "xchg{l}\t{%%}ebx, %1\n\t" \ - : "=a" (eax), "=r" (ebx), "=c" (ecx), "=d" (edx) \ - : "0" (level)); - - if (ecx & bit_PCLMUL) - return 1; - - return -1; -} diff --git a/libcfs/libcfs/user-crypto.c b/libcfs/libcfs/user-crypto.c deleted file mode 100644 index 1d0acab..0000000 --- a/libcfs/libcfs/user-crypto.c +++ /dev/null @@ -1,431 +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.gnu.org/licenses - * - * Please visit http://www.xyratex.com/contact if you need additional - * information or have any questions. - * - * GPL HEADER END - */ - -/* - * Copyright 2012 Xyratex Technology Limited - */ - -/* - * Libcfs crypto hash interfaces for user mode. - */ - -#include -#include -#include -#include - -/** - * Array of hash algorithm speed in MByte per second - */ -static int cfs_crypto_hash_speeds[CFS_HASH_ALG_MAX]; - -struct __hash_alg { - /** - * Initialization of algorithm - */ - int (*init)(void); - /** - * Start function for the hash instance - */ - int (*start)(void *ctx, unsigned char *p, unsigned int len); - /** - * Partial update checksum - */ - int (*update)(void *ctx, const unsigned char *p, unsigned int len); - /** - * Final function for the instance destroy context and copy digest - */ - int (*final)(void *ctx, unsigned char *p, unsigned int len); - /** - * Destroy algorithm - */ - void (*fini)(void); - unsigned int ha_ctx_size; /**< size of context */ - unsigned int ha_priority; /**< implementation priority - defined by developer - to get one from equal algorithm */ - unsigned char ha_id; /**< algorithm identifier */ -}; - -struct hash_desc { - const struct __hash_alg *hd_hash; - unsigned char hd_ctx[0]; -}; - -static int crc32_update_wrapper(void *ctx, const unsigned char *p, - unsigned int len) -{ - unsigned int crc = *(unsigned int *)ctx; - - crc = crc32_le(crc, p, len); - - *(unsigned int *)ctx = crc; - return 0; -} - -static int adler_wrapper(void *ctx, const unsigned char *p, - unsigned int len) -{ - unsigned int cksum = *(unsigned int *)ctx; - - cksum = zlib_adler32(cksum, p, len); - - *(unsigned int *)ctx = cksum; - return 0; -} - -#if defined(HAVE_PCLMULQDQ) && defined(NEED_CRC32_ACCEL) -static int crc32_pclmul_wrapper(void *ctx, const unsigned char *p, - unsigned int len) -{ - unsigned int cksum = *(unsigned int *)ctx; - - cksum = crc32_pclmul_le(cksum, p, len); - - *(unsigned int *)ctx = cksum; - return 0; -} -#endif - -static int start_generic(void *ctx, unsigned char *key, - unsigned int key_len) -{ - const struct cfs_crypto_hash_type *type; - struct hash_desc *hd = container_of(ctx, struct hash_desc, - hd_ctx); - type = cfs_crypto_hash_type(hd->hd_hash->ha_id); - LASSERT(type != NULL); - - /* copy key to context */ - if (key && key_len == hd->hd_hash->ha_ctx_size) { - memcpy(ctx, key, key_len); - } else if (type->cht_key != 0) { - memcpy(ctx, &type->cht_key, type->cht_size); - } else { - CWARN("Invalid key or key_len, zero context\n"); - memset(ctx, 0, hd->hd_hash->ha_ctx_size); - } - return 0; -} - -static int final_generic(void *ctx, unsigned char *hash, - unsigned int hash_len) -{ - const struct cfs_crypto_hash_type *type; - struct hash_desc *hd = container_of(ctx, struct hash_desc, - hd_ctx); - type = cfs_crypto_hash_type(hd->hd_hash->ha_id); - LASSERT(type != NULL); - /* copy context to out hash */ - LASSERT(hd->hd_hash->ha_ctx_size == type->cht_size); - memcpy(hash, ctx, hd->hd_hash->ha_ctx_size); - - - return 0; -} - -static struct __hash_alg crypto_hash[] = { - {.ha_id = CFS_HASH_ALG_CRC32, - .ha_ctx_size = sizeof(unsigned int), - .ha_priority = 10, - .init = crc32init_le, - .update = crc32_update_wrapper, - .start = start_generic, - .final = final_generic, - .fini = NULL}, - {.ha_id = CFS_HASH_ALG_ADLER32, - .ha_ctx_size = sizeof(unsigned int), - .ha_priority = 10, - .init = NULL, - .update = adler_wrapper, - .start = start_generic, - .final = final_generic, - .fini = NULL}, -#if defined(HAVE_PCLMULQDQ) && defined(NEED_CRC32_ACCEL) - {.ha_id = CFS_HASH_ALG_CRC32, - .ha_ctx_size = sizeof(unsigned int), - .ha_priority = 100, - .init = crc32_pclmul_init, - .update = crc32_pclmul_wrapper, - .start = start_generic, - .final = final_generic, - .fini = NULL}, -#endif - }; - -/** - * Go through hashes to find the hash with max priority for the hash_alg - * algorithm. This is done for different implementation of the same - * algorithm. Priority is staticaly defined by developer, and can be zeroed - * if initialization of algo is unsuccessful. - */ -static const struct __hash_alg -*cfs_crypto_hash_best_alg(enum cfs_crypto_hash_alg hash_alg) -{ - int max_priority = 0; - const struct __hash_alg *alg = NULL; - int i; - - for (i = 0; i < ARRAY_SIZE(crypto_hash); i++) { - if (hash_alg == crypto_hash[i].ha_id && - max_priority < crypto_hash[i].ha_priority) { - max_priority = crypto_hash[i].ha_priority; - alg = &crypto_hash[i]; - } - } - - return alg; -} - -struct cfs_crypto_hash_desc -*cfs_crypto_hash_init(enum cfs_crypto_hash_alg hash_alg, - unsigned char *key, unsigned int key_len) -{ - struct hash_desc *hdesc = NULL; - const struct cfs_crypto_hash_type *type; - const struct __hash_alg *ha = NULL; - int err; - - type = cfs_crypto_hash_type(hash_alg); - if (type == NULL) { - CWARN("Unsupported hash algorithm id = %d, max id is %d\n", - hash_alg, CFS_HASH_ALG_MAX); - return ERR_PTR(-EINVAL); - } - - ha = cfs_crypto_hash_best_alg(hash_alg); - if (ha == NULL) { - CERROR("Failed to get hash algorithm\n"); - return ERR_PTR(-ENODEV); - } - - hdesc = kmalloc(sizeof(*hdesc) + ha->ha_ctx_size, 0); - if (hdesc == NULL) - return ERR_PTR(-ENOMEM); - - hdesc->hd_hash = ha; - - if (ha->start != NULL) { - err = ha->start(hdesc->hd_ctx, key, key_len); - if (err == 0) { - return (struct cfs_crypto_hash_desc *) hdesc; - } else { - kfree(hdesc); - return ERR_PTR(err); - } - } - - return (struct cfs_crypto_hash_desc *) hdesc; -} - -int cfs_crypto_hash_update(struct cfs_crypto_hash_desc *desc, const void *buf, - unsigned int buf_len) -{ - struct hash_desc *d = (struct hash_desc *)desc; - return d->hd_hash->update(d->hd_ctx, buf, buf_len); -} - -int cfs_crypto_hash_update_page(struct cfs_crypto_hash_desc *desc, - struct page *page, unsigned int offset, - unsigned int len) -{ - const void *p = page->addr + offset; - - return cfs_crypto_hash_update(desc, p, len); -} - -/** - * To get final hash and destroy cfs_crypto_hash_desc, caller - * should use valid hash buffer with enougth len for hash. - * If hash_len pointer is NULL - destroy descriptor. - */ -int cfs_crypto_hash_final(struct cfs_crypto_hash_desc *desc, - unsigned char *hash, unsigned int *hash_len) -{ - const struct cfs_crypto_hash_type *type; - struct hash_desc *d = (struct hash_desc *)desc; - int size; - int err; - - LASSERT(d != NULL); - type = cfs_crypto_hash_type(d->hd_hash->ha_id); - LASSERT(type != NULL); - size = type->cht_size; - - if (hash == NULL || hash_len == NULL) { - err = 0; - goto free; - } - if (*hash_len < size) { - err = -EOVERFLOW; - goto free; - } - - LASSERT(d->hd_hash->final != NULL); - err = d->hd_hash->final(d->hd_ctx, hash, *hash_len); -free: - kfree(d); - - return err; -} - -int cfs_crypto_hash_digest(enum cfs_crypto_hash_alg hash_alg, - const void *buf, unsigned int buf_len, - unsigned char *key, unsigned int key_len, - unsigned char *hash, unsigned int *hash_len) -{ - struct cfs_crypto_hash_desc *desc; - int err, err2; - - desc = cfs_crypto_hash_init(hash_alg, key, key_len); - - if (IS_ERR(desc)) - return PTR_ERR(desc); - - err = cfs_crypto_hash_update(desc, buf, buf_len); - if (err != 0) - hash_len = NULL; - - err2 = cfs_crypto_hash_final(desc, hash, hash_len); - if (err2 != 0 && err == 0) - err = err2; - - return err; -} - - -static void cfs_crypto_start_timer(struct timeval *start) -{ - gettimeofday(start, NULL); - return; -} - -/** return usec */ -static long cfs_crypto_get_sec(struct timeval *start) -{ - struct timeval end; - - gettimeofday(&end, NULL); - - return cfs_timeval_sub(&end, start, NULL); -} - -static void cfs_crypto_performance_test(enum cfs_crypto_hash_alg hash_alg, - const unsigned char *buf, - unsigned int buf_len) -{ - struct timeval start; - int bcount, err, msec; - int iteration = 400; /* do test 400 times */ - unsigned char hash[64]; - unsigned int hash_len = 64; - - cfs_crypto_start_timer(&start); - for (bcount = 0; bcount < iteration; bcount++) { - err = cfs_crypto_hash_digest(hash_alg, buf, buf_len, NULL, 0, - hash, &hash_len); - if (err) - break; - - } - - msec = (int)(cfs_crypto_get_sec(&start) / 1000.0); - if (err) { - cfs_crypto_hash_speeds[hash_alg] = -1; - CDEBUG(D_INFO, "Crypto hash algorithm err = %d\n", err); - } else { - long tmp; - tmp = ((bcount * buf_len / msec) * 1000) / (1024 * 1024); - cfs_crypto_hash_speeds[hash_alg] = (int)tmp; - } - CDEBUG(D_CONFIG, "Crypto hash algorithm %s speed = %d MB/s\n", - cfs_crypto_hash_name(hash_alg), - cfs_crypto_hash_speeds[hash_alg]); -} - -int cfs_crypto_hash_speed(enum cfs_crypto_hash_alg hash_alg) -{ - if (hash_alg < CFS_HASH_ALG_MAX) - return cfs_crypto_hash_speeds[hash_alg]; - else - return -1; -} - -/** - * Do performance test for all hash algorithms. - */ -static int cfs_crypto_test_hashes(void) -{ - unsigned char i; - unsigned char *data; - unsigned int j, data_len = 1024 * 1024; - - data = kmalloc(data_len, 0); - if (data == NULL) { - CERROR("Failed to allocate mem\n"); - return -ENOMEM; - } - for (j = 0; j < data_len; j++) - data[j] = j & 0xff; - - for (i = 0; i < CFS_HASH_ALG_MAX; i++) - cfs_crypto_performance_test(i, data, data_len); - - kfree(data); - return 0; -} - -/** - * Register crypto hash algorithms - */ -int cfs_crypto_register(void) -{ - int i, err; - for (i = 0; i < ARRAY_SIZE(crypto_hash); i++) { - if (crypto_hash[i].init == NULL) - continue; - err = crypto_hash[i].init(); - if (err < 0) { - crypto_hash[i].ha_priority = 0; - CWARN("Failed to initialize hash %s, error %d\n", - cfs_crypto_hash_name(crypto_hash[i].ha_id), err); - } - } - - cfs_crypto_test_hashes(); - return 0; -} - -/** - * Unregister - */ -void cfs_crypto_unregister(void) -{ - int i; - for (i = 0; i < ARRAY_SIZE(crypto_hash); i++) { - if (crypto_hash[i].fini == NULL) - continue; - if (crypto_hash[i].ha_priority > 0) - crypto_hash[i].fini(); - } -} diff --git a/libcfs/libcfs/user-lock.c b/libcfs/libcfs/user-lock.c deleted file mode 100644 index fcba2cd..0000000 --- a/libcfs/libcfs/user-lock.c +++ /dev/null @@ -1,391 +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. - * - * Copyright (c) 2012, Intel Corporation. - */ -/* - * This file is part of Lustre, http://www.lustre.org/ - * Lustre is a trademark of Sun Microsystems, Inc. - * - * libcfs/libcfs/user-lock.c - * - * Author: Nikita Danilov - */ - -/* Implementations of portable synchronization APIs for liblustre */ - -/* - * liblustre is single-threaded, so most "synchronization" APIs are trivial. - * - * XXX Liang: There are several branches share lnet with b_hd_newconfig, - * if we define lock APIs at here, there will be conflict with liblustre - * in other branches. - */ - -#ifndef __KERNEL__ - -#include - -/* - * Optional debugging (magic stamping and checking ownership) can be added. - */ - -/* - * spin_lock - * - * - spin_lock_init(x) - * - spin_lock(x) - * - spin_lock_nested(x, subclass) - * - spin_unlock(x) - * - spin_trylock(x) - * - * - spin_lock_irqsave(x, f) - * - spin_unlock_irqrestore(x, f) - * - * No-op implementation. - */ - -void spin_lock_init(spinlock_t *lock) -{ - LASSERT(lock != NULL); - (void)lock; -} - -void spin_lock(spinlock_t *lock) -{ - (void)lock; -} - -void spin_unlock(spinlock_t *lock) -{ - (void)lock; -} - -int spin_trylock(spinlock_t *lock) -{ - (void)lock; - return 1; -} - -void spin_lock_bh_init(spinlock_t *lock) -{ - LASSERT(lock != NULL); - (void)lock; -} - -void spin_lock_bh(spinlock_t *lock) -{ - LASSERT(lock != NULL); - (void)lock; -} - -void spin_unlock_bh(spinlock_t *lock) -{ - LASSERT(lock != NULL); - (void)lock; -} - -/* - * Semaphore - * - * - sema_init(x, v) - * - __down(x) - * - __up(x) - */ - -void sema_init(struct semaphore *s, int val) -{ - LASSERT(s != NULL); - (void)s; - (void)val; -} - -void __down(struct semaphore *s) -{ - LASSERT(s != NULL); - (void)s; -} - -int __down_interruptible(struct semaphore *s) -{ - LASSERT(s != NULL); - (void)s; - return 0; -} - -void __up(struct semaphore *s) -{ - LASSERT(s != NULL); - (void)s; -} - - -/* - * Completion: - * - * - init_completion(c) - * - complete(c) - * - wait_for_completion(c) - */ -static wait_handler_t wait_handler; - -void init_completion_module(wait_handler_t handler) -{ - wait_handler = handler; -} - -int call_wait_handler(int timeout) -{ - if (!wait_handler) - return -ENOSYS; - return wait_handler(timeout); -} - -#ifndef HAVE_LIBPTHREAD -void init_completion(struct completion *c) -{ - LASSERT(c != NULL); - c->done = 0; - init_waitqueue_head(&c->wait); -} - -void fini_completion(struct completion *c) -{ -} - -void complete(struct completion *c) -{ - LASSERT(c != NULL); - c->done = 1; - wake_up(&c->wait); -} - -void wait_for_completion(struct completion *c) -{ - LASSERT(c != NULL); - do { - if (call_wait_handler(1000) < 0) - break; - } while (c->done == 0); -} - -int wait_for_completion_interruptible(struct completion *c) -{ - LASSERT(c != NULL); - do { - if (call_wait_handler(1000) < 0) - break; - } while (c->done == 0); - return 0; -} -#endif /* HAVE_LIBPTHREAD */ - -/* - * rw_semaphore: - * - * - DECLARE_RWSEM(x) - * - init_rwsem(x) - * - down_read(x) - * - up_read(x) - * - down_write(x) - * - up_write(x) - */ - -void init_rwsem(struct rw_semaphore *s) -{ - LASSERT(s != NULL); - (void)s; -} - -void down_read(struct rw_semaphore *s) -{ - LASSERT(s != NULL); - (void)s; -} - -int down_read_trylock(struct rw_semaphore *s) -{ - LASSERT(s != NULL); - (void)s; - return 1; -} - -void down_write(struct rw_semaphore *s) -{ - LASSERT(s != NULL); - (void)s; -} - -void downgrade_write(struct rw_semaphore *s) -{ - LASSERT(s != NULL); - (void)s; -} - -int down_write_trylock(struct rw_semaphore *s) -{ - LASSERT(s != NULL); - (void)s; - return 1; -} - -void up_read(struct rw_semaphore *s) -{ - LASSERT(s != NULL); - (void)s; -} - -void up_write(struct rw_semaphore *s) -{ - LASSERT(s != NULL); - (void)s; -} - -void fini_rwsem(struct rw_semaphore *s) -{ - LASSERT(s != NULL); - (void)s; -} - -#ifdef HAVE_LIBPTHREAD - -/* - * Multi-threaded user space completion - */ - -void init_completion(struct completion *c) -{ - LASSERT(c != NULL); - c->c_done = 0; - pthread_mutex_init(&c->c_mut, NULL); - pthread_cond_init(&c->c_cond, NULL); -} - -void fini_completion(struct completion *c) -{ - LASSERT(c != NULL); - pthread_mutex_destroy(&c->c_mut); - pthread_cond_destroy(&c->c_cond); -} - -void complete(struct completion *c) -{ - LASSERT(c != NULL); - pthread_mutex_lock(&c->c_mut); - c->c_done++; - pthread_cond_signal(&c->c_cond); - pthread_mutex_unlock(&c->c_mut); -} - -void wait_for_completion(struct completion *c) -{ - LASSERT(c != NULL); - pthread_mutex_lock(&c->c_mut); - while (c->c_done == 0) - pthread_cond_wait(&c->c_cond, &c->c_mut); - c->c_done--; - pthread_mutex_unlock(&c->c_mut); -} - -/* - * Multi-threaded user space atomic primitives - */ - -static pthread_mutex_t atomic_guard_lock = PTHREAD_MUTEX_INITIALIZER; - -int mt_atomic_read(mt_atomic_t *a) -{ - int r; - - pthread_mutex_lock(&atomic_guard_lock); - r = a->counter; - pthread_mutex_unlock(&atomic_guard_lock); - return r; -} - -void mt_atomic_set(mt_atomic_t *a, int b) -{ - pthread_mutex_lock(&atomic_guard_lock); - a->counter = b; - pthread_mutex_unlock(&atomic_guard_lock); -} - -int mt_atomic_dec_and_test(mt_atomic_t *a) -{ - int r; - - pthread_mutex_lock(&atomic_guard_lock); - r = --a->counter; - pthread_mutex_unlock(&atomic_guard_lock); - return (r == 0); -} - -void mt_atomic_inc(mt_atomic_t *a) -{ - pthread_mutex_lock(&atomic_guard_lock); - ++a->counter; - pthread_mutex_unlock(&atomic_guard_lock); -} - -void mt_atomic_dec(mt_atomic_t *a) -{ - pthread_mutex_lock(&atomic_guard_lock); - --a->counter; - pthread_mutex_unlock(&atomic_guard_lock); -} -void mt_atomic_add(int b, mt_atomic_t *a) - -{ - pthread_mutex_lock(&atomic_guard_lock); - a->counter += b; - pthread_mutex_unlock(&atomic_guard_lock); -} - -void mt_atomic_sub(int b, mt_atomic_t *a) -{ - pthread_mutex_lock(&atomic_guard_lock); - a->counter -= b; - pthread_mutex_unlock(&atomic_guard_lock); -} - -#endif /* HAVE_LIBPTHREAD */ - - -/* !__KERNEL__ */ -#endif - -/* - * Local variables: - * c-indentation-style: "K&R" - * c-basic-offset: 8 - * tab-width: 8 - * fill-column: 80 - * scroll-step: 1 - * End: - */ diff --git a/libcfs/libcfs/user-mem.c b/libcfs/libcfs/user-mem.c deleted file mode 100644 index a7caf14..0000000 --- a/libcfs/libcfs/user-mem.c +++ /dev/null @@ -1,132 +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/libcfs/user-mem.c - * - * Userspace memory management. - * - */ - -#ifdef __KERNEL__ -#error "This is not kernel code." -#endif - -#include - -/* - * Allocator - */ - -struct page *alloc_page(unsigned int flags) -{ - struct page *pg = malloc(sizeof(*pg)); - int rc = 0; - - if (!pg) - return NULL; - pg->addr = NULL; - - rc = posix_memalign(&pg->addr, PAGE_CACHE_SIZE, PAGE_CACHE_SIZE); - if (rc != 0 || pg->addr == NULL) { - free(pg); - return NULL; - } - return pg; -} - -void __free_page(struct page *pg) -{ - free(pg->addr); - - free(pg); -} - -void *page_address(struct page *pg) -{ - return pg->addr; -} - -void *kmap(struct page *pg) -{ - return pg->addr; -} - -void kunmap(struct page *pg) -{ -} - -/* - * SLAB allocator - */ - -struct kmem_cache * -kmem_cache_create(const char *name, size_t objsize, size_t off, - unsigned long flags, void *ctor) -{ - struct kmem_cache *c; - - c = malloc(sizeof(*c)); - if (!c) - return NULL; - c->size = objsize; - CDEBUG(D_MALLOC, "alloc slab cache %s at %p, objsize %d\n", - name, c, (int)objsize); - return c; -} - -void kmem_cache_destroy(struct kmem_cache *c) -{ - CDEBUG(D_MALLOC, "destroy slab cache %p, objsize %u\n", c, c->size); - free(c); -} - -void *kmem_cache_alloc(struct kmem_cache *c, int gfp) -{ - return kmalloc(c->size, gfp); -} - -void kmem_cache_free(struct kmem_cache *c, void *addr) -{ - kfree(addr); -} - -/** - * Returns true if \a addr is an address of an allocated object in a slab \a - * kmem. Used in assertions. This check is optimistically imprecise, i.e., it - * occasionally returns true for the incorrect addresses, but if it returns - * false, then the addresses is guaranteed to be incorrect. - */ -int kmem_is_in_cache(const void *addr, const struct kmem_cache *kmem) -{ - return 1; -} diff --git a/libcfs/libcfs/user-prim.c b/libcfs/libcfs/user-prim.c deleted file mode 100644 index 2066499..0000000 --- a/libcfs/libcfs/user-prim.c +++ /dev/null @@ -1,404 +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. - * - * Copyright (c) 2011, 2012, Intel Corporation. - */ -/* - * This file is part of Lustre, http://www.lustre.org/ - * Lustre is a trademark of Sun Microsystems, Inc. - * - * libcfs/libcfs/user-prim.c - * - * Implementations of portable APIs for liblustre - * - * Author: Nikita Danilov - */ - -/* - * liblustre is single-threaded, so most "synchronization" APIs are trivial. - */ - -#ifndef __KERNEL__ - -#include -#include - -/* - * Wait queue. No-op implementation. - */ - -void init_waitqueue_head(struct cfs_waitq *waitq) -{ - LASSERT(waitq != NULL); - (void)waitq; -} - -void init_waitqueue_entry_current(struct cfs_waitlink *link) -{ - LASSERT(link != NULL); - (void)link; -} - -void add_wait_queue(struct cfs_waitq *waitq, struct cfs_waitlink *link) -{ - LASSERT(waitq != NULL); - LASSERT(link != NULL); - (void)waitq; - (void)link; -} - -void add_wait_queue_exclusive(struct cfs_waitq *waitq, struct cfs_waitlink *link) -{ - LASSERT(waitq != NULL); - LASSERT(link != NULL); - (void)waitq; - (void)link; -} - -void add_wait_queue_exclusive_head(struct cfs_waitq *waitq, struct cfs_waitlink *link) -{ - add_wait_queue_exclusive(waitq, link); -} - -void remove_wait_queue(struct cfs_waitq *waitq, struct cfs_waitlink *link) -{ - LASSERT(waitq != NULL); - LASSERT(link != NULL); - (void)waitq; - (void)link; -} - -int waitqueue_active(struct cfs_waitq *waitq) -{ - LASSERT(waitq != NULL); - (void)waitq; - return 0; -} - -void wake_up(struct cfs_waitq *waitq) -{ - LASSERT(waitq != NULL); - (void)waitq; -} - -void wake_up_nr(struct cfs_waitq *waitq, int nr) -{ - LASSERT(waitq != NULL); - (void)waitq; -} - -void wake_up_all(struct cfs_waitq *waitq) -{ - LASSERT(waitq != NULL); - (void)waitq; -} - -void waitq_wait(struct cfs_waitlink *link, long state) -{ - LASSERT(link != NULL); - (void)link; - - /* well, wait for something to happen */ - call_wait_handler(0); -} - -int64_t waitq_timedwait(struct cfs_waitlink *link, long state, - int64_t timeout) -{ - LASSERT(link != NULL); - (void)link; - call_wait_handler(timeout); - return 0; -} - -void schedule_timeout_and_set_state(long state, int64_t timeout) -{ - wait_queue_t l; - /* sleep(timeout) here instead? */ - waitq_timedwait(&l, state, timeout); -} - -void -cfs_pause(cfs_duration_t d) -{ - struct timespec s; - - cfs_duration_nsec(d, &s); - nanosleep(&s, NULL); -} - -int need_resched(void) -{ - return 0; -} - -void cond_resched(void) -{ -} - -/* - * Timer - */ - -void cfs_init_timer(struct timer_list *t) -{ - INIT_LIST_HEAD(&t->tl_list); -} - -void cfs_timer_init(struct timer_list *l, cfs_timer_func_t *func, void *arg) -{ - INIT_LIST_HEAD(&l->tl_list); - l->function = func; - l->data = (ulong_ptr_t)arg; - return; -} - -int cfs_timer_is_armed(struct timer_list *l) -{ - if (cfs_time_before(cfs_time_current(), l->expires)) - return 1; - else - return 0; -} - -void cfs_timer_arm(struct timer_list *l, cfs_time_t deadline) -{ - l->expires = deadline; -} - -void cfs_timer_disarm(struct timer_list *l) -{ -} -cfs_time_t cfs_timer_deadline(struct timer_list *l) -{ - return l->expires; -} - - -#ifdef HAVE_LIBPTHREAD - -/* - * Threads - */ - -struct lustre_thread_arg { - cfs_thread_t f; - void *arg; -}; -static void *cfs_thread_helper(void *data) -{ - struct lustre_thread_arg *targ = data; - cfs_thread_t f = targ->f; - void *arg = targ->arg; - - free(targ); - - (void)f(arg); - return NULL; -} - -void *kthread_run(cfs_thread_t func, void *arg, const char namefmt[], ...) -{ - pthread_t tid; - pthread_attr_t tattr; - int rc; - struct lustre_thread_arg *targ_p = - malloc(sizeof(struct lustre_thread_arg)); - - if (targ_p == NULL) - return ERR_PTR(-ENOMEM); - - targ_p->f = func; - targ_p->arg = arg; - - pthread_attr_init(&tattr); - pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED); - rc = pthread_create(&tid, &tattr, cfs_thread_helper, targ_p); - pthread_attr_destroy(&tattr); - return ERR_PTR(rc); -} -#endif - -struct user_namespace init_user_ns __read_mostly; -EXPORT_SYMBOL(init_user_ns); - -uid_t current_uid(void) -{ - return getuid(); -} - -gid_t current_gid(void) -{ - return getgid(); -} - -uid_t current_fsuid(void) -{ - return getuid(); -} - -gid_t current_fsgid(void) -{ - return getgid(); -} - -/* Read the environment variable of current process specified by @key. */ -int cfs_get_environ(const char *key, char *value, int *val_len) -{ - char *entry; - int len; - - entry = getenv(key); - if (entry == NULL) - return -ENOENT; - - len = strlcpy(value, entry, *val_len); - if (len >= *val_len) - return -EOVERFLOW; - - return 0; -} - -void cfs_enter_debugger(void) -{ - /* - * nothing for now. - */ -} - -int unshare_fs_struct() -{ - return 0; -} - -sigset_t cfs_block_allsigs(void) -{ - sigset_t all; - sigset_t old; - int rc; - - sigfillset(&all); - rc = sigprocmask(SIG_BLOCK, &all, &old); - LASSERT(rc == 0); - - return old; -} - -sigset_t cfs_block_sigs(unsigned long sigs) -{ - sigset_t old; - sigset_t blocks = { { sigs } }; /* kludge */ - int rc; - - rc = sigprocmask(SIG_BLOCK, &blocks, &old); - LASSERT (rc == 0); - - return old; -} - -/* Block all signals except for the @sigs. It's only used in - * Linux kernel, just a dummy here. */ -sigset_t cfs_block_sigsinv(unsigned long sigs) -{ - sigset_t old; - int rc; - - /* Return old blocked sigs */ - rc = sigprocmask(SIG_SETMASK, NULL, &old); - LASSERT(rc == 0); - - return old; -} - -void cfs_restore_sigs(sigset_t old) -{ - int rc = sigprocmask(SIG_SETMASK, &old, NULL); - - LASSERT (rc == 0); -} - -int cfs_signal_pending(void) -{ - sigset_t empty; - sigset_t set; - int rc; - - rc = sigpending(&set); - LASSERT (rc == 0); - - sigemptyset(&empty); - - return !memcmp(&empty, &set, sizeof(set)); -} - -void cfs_clear_sigpending(void) -{ - return; -} - - -/* - * In glibc (NOT in Linux, so check above is not right), implement - * stack-back-tracing through backtrace() function. - */ -#include - -void cfs_stack_trace_fill(struct cfs_stack_trace *trace) -{ - backtrace(trace->frame, ARRAY_SIZE(trace->frame)); -} - -void *cfs_stack_trace_frame(struct cfs_stack_trace *trace, int frame_no) -{ - if (0 <= frame_no && frame_no < ARRAY_SIZE(trace->frame)) - return trace->frame[frame_no]; - else - return NULL; -} - - -void lbug_with_loc(struct libcfs_debug_msg_data *msgdata) -{ - /* No libcfs_catastrophe in userspace! */ - libcfs_debug_msg(msgdata, "LBUG\n"); - abort(); -} - -/* !__KERNEL__ */ -#endif - -/* - * Local variables: - * c-indentation-style: "K&R" - * c-basic-offset: 8 - * tab-width: 8 - * fill-column: 80 - * scroll-step: 1 - * End: - */ diff --git a/libcfs/libcfs/user-tcpip.c b/libcfs/libcfs/user-tcpip.c deleted file mode 100644 index da0d2a1..0000000 --- a/libcfs/libcfs/user-tcpip.c +++ /dev/null @@ -1,697 +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. - */ - -#if !defined(__KERNEL__) || !defined(REDSTORM) - -#include - -#include -#ifdef HAVE_NETINET_IN_H -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * Functions to get network interfaces info - */ - -int -libcfs_sock_ioctl(int cmd, unsigned long arg) -{ - int fd, rc; - - fd = socket(AF_INET, SOCK_STREAM, 0); - - if (fd < 0) { - rc = -errno; - CERROR("socket() failed: errno==%d\n", errno); - return rc; - } - - rc = ioctl(fd, cmd, arg); - - close(fd); - return rc; -} - -int -libcfs_ipif_query (char *name, int *up, __u32 *ip) -{ - struct ifreq ifr; - int nob; - int rc; - __u32 val; - - nob = strlen(name); - if (nob >= IFNAMSIZ) { - CERROR("Interface name %s too long\n", name); - return -EINVAL; - } - - CLASSERT (sizeof(ifr.ifr_name) >= IFNAMSIZ); - - strcpy(ifr.ifr_name, name); - rc = libcfs_sock_ioctl(SIOCGIFFLAGS, (unsigned long)&ifr); - - if (rc != 0) { - CERROR("Can't get flags for interface %s\n", name); - return rc; - } - - if ((ifr.ifr_flags & IFF_UP) == 0) { - CDEBUG(D_NET, "Interface %s down\n", name); - *up = 0; - *ip = 0; - return 0; - } - - *up = 1; - - strcpy(ifr.ifr_name, name); - ifr.ifr_addr.sa_family = AF_INET; - rc = libcfs_sock_ioctl(SIOCGIFADDR, (unsigned long)&ifr); - - if (rc != 0) { - CERROR("Can't get IP address for interface %s\n", name); - return rc; - } - - val = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr; - *ip = ntohl(val); - - return 0; -} - -void -libcfs_ipif_free_enumeration (char **names, int n) -{ - int i; - - LASSERT (n > 0); - - for (i = 0; i < n && names[i] != NULL; i++) - LIBCFS_FREE(names[i], IFNAMSIZ); - - LIBCFS_FREE(names, n * sizeof(*names)); -} - -int -libcfs_ipif_enumerate (char ***namesp) -{ - /* Allocate and fill in 'names', returning # interfaces/error */ - char **names; - int nalloc; - int nfound; - struct ifreq *ifr; - struct ifconf ifc; - int rc; - int nob; - int i; - - - nalloc = 16; /* first guess at max interfaces */ - for (;;) { - LIBCFS_ALLOC(ifr, nalloc * sizeof(*ifr)); - if (ifr == NULL) { - CERROR ("ENOMEM enumerating up to %d interfaces\n", - nalloc); - rc = -ENOMEM; - goto out0; - } - - ifc.ifc_buf = (char *)ifr; - ifc.ifc_len = nalloc * sizeof(*ifr); - - rc = libcfs_sock_ioctl(SIOCGIFCONF, (unsigned long)&ifc); - - if (rc < 0) { - CERROR ("Error %d enumerating interfaces\n", rc); - goto out1; - } - - LASSERT (rc == 0); - - nfound = ifc.ifc_len/sizeof(*ifr); - LASSERT (nfound <= nalloc); - - if (nfound < nalloc) - break; - - LIBCFS_FREE(ifr, nalloc * sizeof(*ifr)); - nalloc *= 2; - } - - if (nfound == 0) - goto out1; - - LIBCFS_ALLOC(names, nfound * sizeof(*names)); - if (names == NULL) { - rc = -ENOMEM; - goto out1; - } - /* NULL out all names[i] */ - memset (names, 0, nfound * sizeof(*names)); - - for (i = 0; i < nfound; i++) { - - nob = strlen (ifr[i].ifr_name); - if (nob >= IFNAMSIZ) { - /* no space for terminating NULL */ - CERROR("interface name %.*s too long (%d max)\n", - nob, ifr[i].ifr_name, IFNAMSIZ); - rc = -ENAMETOOLONG; - goto out2; - } - - LIBCFS_ALLOC(names[i], IFNAMSIZ); - if (names[i] == NULL) { - rc = -ENOMEM; - goto out2; - } - - memcpy(names[i], ifr[i].ifr_name, nob); - names[i][nob] = 0; - } - - *namesp = names; - rc = nfound; - - out2: - if (rc < 0) - libcfs_ipif_free_enumeration(names, nfound); - out1: - LIBCFS_FREE(ifr, nalloc * sizeof(*ifr)); - out0: - return rc; -} - -/* - * Network functions used by user-land lnet acceptor - */ - -int -libcfs_sock_listen (cfs_socket_t **sockp, - __u32 local_ip, int local_port, int backlog) -{ - int rc; - int fatal; - - rc = libcfs_sock_create(sockp, &fatal, local_ip, local_port); - if (rc != 0) - return rc; - - if ( listen((*sockp)->s_fd, backlog) ) { - rc = -errno; - CERROR("listen() with backlog==%d failed: errno==%d\n", - backlog, errno); - goto failed; - } - - return 0; - - failed: - libcfs_sock_release(*sockp); - return rc; -} - -void -libcfs_sock_release (cfs_socket_t *sock) -{ - close(sock->s_fd); - LIBCFS_FREE(sock, sizeof(cfs_socket_t)); -} - -int -libcfs_sock_accept (cfs_socket_t **newsockp, cfs_socket_t *sock) -{ - struct sockaddr_in accaddr; - socklen_t accaddr_len = sizeof(struct sockaddr_in); - - LIBCFS_ALLOC(*newsockp, sizeof(cfs_socket_t)); - if (*newsockp == NULL) { - CERROR ("Can't alloc memory for cfs_socket_t\n"); - return -ENOMEM; - } - - (*newsockp)->s_fd = accept(sock->s_fd, - (struct sockaddr *)&accaddr, &accaddr_len); - - if ( (*newsockp)->s_fd < 0 ) { - int rc = -errno; - CERROR("accept() failed: errno==%d\n", -rc); - LIBCFS_FREE(*newsockp, sizeof(cfs_socket_t)); - return rc; - } - - return 0; -} - -int -libcfs_sock_read (cfs_socket_t *sock, void *buffer, int nob, int timeout) -{ - int rc; - struct pollfd pfd; - cfs_time_t start_time = cfs_time_current(); - - pfd.fd = sock->s_fd; - pfd.events = POLLIN; - pfd.revents = 0; - - /* poll(2) measures timeout in msec */ - timeout *= 1000; - - while (nob != 0 && timeout > 0) { - cfs_time_t current_time; - - rc = poll(&pfd, 1, timeout); - if (rc < 0) - return -errno; - if (rc == 0) - return -ETIMEDOUT; - if ((pfd.revents & POLLIN) == 0) - return -EIO; - - rc = read(sock->s_fd, buffer, nob); - if (rc < 0) - return -errno; - if (rc == 0) - return -EIO; - - buffer = ((char *)buffer) + rc; - nob -= rc; - - current_time = cfs_time_current(); - timeout -= 1000 * - cfs_duration_sec(cfs_time_sub(current_time, - start_time)); - start_time = current_time; - } - - if (nob == 0) - return 0; - else - return -ETIMEDOUT; -} - -int -libcfs_sock_write (cfs_socket_t *sock, void *buffer, int nob, int timeout) -{ - int rc; - struct pollfd pfd; - cfs_time_t start_time = cfs_time_current(); - - pfd.fd = sock->s_fd; - pfd.events = POLLOUT; - pfd.revents = 0; - - /* poll(2) measures timeout in msec */ - timeout *= 1000; - - while (nob != 0 && timeout > 0) { - cfs_time_t current_time; - - rc = poll(&pfd, 1, timeout); - if (rc < 0) - return -errno; - if (rc == 0) - return -ETIMEDOUT; - if ((pfd.revents & POLLOUT) == 0) - return -EIO; - - rc = write(sock->s_fd, buffer, nob); - if (rc < 0) - return -errno; - if (rc == 0) - return -EIO; - - buffer = ((char *)buffer) + rc; - nob -= rc; - - current_time = cfs_time_current(); - timeout -= 1000 * - cfs_duration_sec(cfs_time_sub(current_time, - start_time)); - start_time = current_time; - } - - if (nob == 0) - return 0; - else - return -ETIMEDOUT; -} - -/* Just try to connect to localhost to wake up entity that are - * sleeping in accept() */ -void -libcfs_sock_abort_accept(cfs_socket_t *sock) -{ - int fd, rc; - struct sockaddr_in remaddr; - struct sockaddr_in locaddr; - socklen_t alen = sizeof(struct sockaddr_in); - - rc = getsockname(sock->s_fd, (struct sockaddr *)&remaddr, &alen); - if ( rc != 0 ) { - CERROR("getsockname() failed: errno==%d\n", errno); - return; - } - - memset(&locaddr, 0, sizeof(locaddr)); - locaddr.sin_family = AF_INET; - locaddr.sin_port = remaddr.sin_port; - locaddr.sin_addr.s_addr = inet_addr("127.0.0.1"); - - fd = socket(AF_INET, SOCK_STREAM, 0); - if ( fd < 0 ) { - CERROR("socket() failed: errno==%d\n", errno); - return; - } - - rc = connect(fd, (struct sockaddr *)&locaddr, sizeof(locaddr)); - if ( rc != 0 ) { - if ( errno != ECONNREFUSED ) - CERROR("connect() failed: errno==%d\n", errno); - else - CDEBUG(D_NET, "Nobody to wake up at %d\n", - ntohs(remaddr.sin_port)); - } - - close(fd); -} - -int -libcfs_sock_getaddr(cfs_socket_t *sock, int remote, __u32 *ip, int *port) -{ - int rc; - struct sockaddr_in peer_addr; - socklen_t peer_addr_len = sizeof(peer_addr); - - LASSERT(remote == 1); - - rc = getpeername(sock->s_fd, - (struct sockaddr *)&peer_addr, &peer_addr_len); - if (rc != 0) - return -errno; - - if (ip != NULL) - *ip = ntohl(peer_addr.sin_addr.s_addr); - if (port != NULL) - *port = ntohs(peer_addr.sin_port); - - return rc; -} - -/* - * Network functions of common use - */ - -int -libcfs_socketpair(cfs_socket_t **sockp) -{ - int rc, i, fdp[2]; - - LIBCFS_ALLOC(sockp[0], sizeof(cfs_socket_t)); - if (sockp[0] == NULL) { - CERROR ("Can't alloc memory for cfs_socket_t (1)\n"); - return -ENOMEM; - } - - LIBCFS_ALLOC(sockp[1], sizeof(cfs_socket_t)); - if (sockp[1] == NULL) { - CERROR ("Can't alloc memory for cfs_socket_t (2)\n"); - LIBCFS_FREE(sockp[0], sizeof(cfs_socket_t)); - return -ENOMEM; - } - - rc = socketpair(AF_UNIX, SOCK_STREAM, 0, fdp); - if (rc != 0) { - rc = -errno; - CERROR ("Cannot create socket pair\n"); - LIBCFS_FREE(sockp[0], sizeof(cfs_socket_t)); - LIBCFS_FREE(sockp[1], sizeof(cfs_socket_t)); - return rc; - } - - sockp[0]->s_fd = fdp[0]; - sockp[1]->s_fd = fdp[1]; - - for (i = 0; i < 2; i++) { - rc = libcfs_fcntl_nonblock(sockp[i]); - if (rc) { - libcfs_sock_release(sockp[0]); - libcfs_sock_release(sockp[1]); - return rc; - } - } - - return 0; -} - -int -libcfs_fcntl_nonblock(cfs_socket_t *sock) -{ - int rc, flags; - - flags = fcntl(sock->s_fd, F_GETFL, 0); - if (flags == -1) { - rc = -errno; - CERROR ("Cannot get socket flags\n"); - return rc; - } - - rc = fcntl(sock->s_fd, F_SETFL, flags | O_NONBLOCK); - if (rc != 0) { - rc = -errno; - CERROR ("Cannot set socket flags\n"); - return rc; - } - - return 0; -} - -int -libcfs_sock_set_nagle(cfs_socket_t *sock, int nagle) -{ - int rc; - int option = nagle ? 0 : 1; - - rc = setsockopt(sock->s_fd, - IPPROTO_TCP, TCP_NODELAY, &option, sizeof(option)); - if (rc != 0) { - rc = -errno; - CERROR ("Cannot set NODELAY socket option\n"); - return rc; - } - - return 0; -} - -int -libcfs_sock_set_bufsiz(cfs_socket_t *sock, int bufsiz) -{ - int rc, option; - - LASSERT (bufsiz != 0); - - option = bufsiz; - rc = setsockopt(sock->s_fd, - SOL_SOCKET, SO_SNDBUF, &option, sizeof(option)); - if (rc != 0) { - rc = -errno; - CERROR ("Cannot set SNDBUF socket option\n"); - return rc; - } - - option = bufsiz; - rc = setsockopt(sock->s_fd, - SOL_SOCKET, SO_RCVBUF, &option, sizeof(option)); - if (rc != 0) { - rc = -errno; - CERROR ("Cannot set RCVBUF socket option\n"); - return rc; - } - - return 0; -} - -int -libcfs_sock_bind(cfs_socket_t *sock, __u32 ip, __u16 port) -{ - int rc; - struct sockaddr_in locaddr; - - if (ip == 0 && port == 0) - return 0; - - memset(&locaddr, 0, sizeof(locaddr)); - locaddr.sin_family = AF_INET; - locaddr.sin_addr.s_addr = (ip == 0) ? INADDR_ANY : htonl(ip); - locaddr.sin_port = htons(port); - - rc = bind(sock->s_fd, (struct sockaddr *)&locaddr, sizeof(locaddr)); - if (rc != 0) { - rc = -errno; - CERROR("Cannot bind to %d.%d.%d.%d %d: %d\n", - HIPQUAD(ip), port, rc); - return rc; - } - - return 0; -} - -int -libcfs_sock_create(cfs_socket_t **sockp, int *fatal, - __u32 local_ip, int local_port) -{ - int rc, fd, option; - - *fatal = 1; - - LIBCFS_ALLOC(*sockp, sizeof(cfs_socket_t)); - if (*sockp == NULL) { - CERROR("Can't alloc memory for cfs_socket_t\n"); - return -ENOMEM; - } - - fd = socket(AF_INET, SOCK_STREAM, 0); - if (fd < 0) { - rc = -errno; - CERROR("Cannot create socket: %d\n", rc); - LIBCFS_FREE(*sockp, sizeof(cfs_socket_t)); - return rc; - } - - (*sockp)->s_fd = fd; - - option = 1; - rc = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, - &option, sizeof(option)); - if (rc != 0) { - rc = -errno; - CERROR("Cannot set SO_REUSEADDR for socket: %d\n", rc); - libcfs_sock_release(*sockp); - return rc; - } - - rc = libcfs_sock_bind(*sockp, local_ip, local_port); - if (rc != 0) { - *fatal = 0; - libcfs_sock_release(*sockp); - } - - return rc; -} - -int -libcfs_sock_connect(cfs_socket_t *sock, __u32 ip, __u16 port) -{ - int rc; - struct sockaddr_in addr; - - memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = htonl(ip); - addr.sin_port = htons(port); - - rc = connect(sock->s_fd, (struct sockaddr *)&addr, - sizeof(struct sockaddr_in)); - - if(rc != 0 && errno != EINPROGRESS) { - rc = -errno; - if (rc != -EADDRINUSE && rc != -EADDRNOTAVAIL) - CERROR ("Cannot connect to %u.%u.%u.%u:%d (err=%d)\n", - HIPQUAD(ip), port, errno); - return rc; - } - - return 0; -} - -/* NB: EPIPE and ECONNRESET are considered as non-fatal - * because: - * 1) it still makes sense to continue reading && - * 2) anyway, poll() will set up POLLHUP|POLLERR flags */ -int -libcfs_sock_writev(cfs_socket_t *sock, const struct iovec *vector, int count) -{ - int rc; - - rc = syscall(SYS_writev, sock->s_fd, vector, count); - - if (rc == 0) /* write nothing */ - return 0; - - if (rc < 0) { - if (errno == EAGAIN || /* write nothing */ - errno == EPIPE || /* non-fatal error */ - errno == ECONNRESET) /* non-fatal error */ - return 0; - else - return -errno; - } - - return rc; -} - -int -libcfs_sock_readv(cfs_socket_t *sock, const struct iovec *vector, int count) -{ - int rc; - - rc = syscall(SYS_readv, sock->s_fd, vector, count); - - if (rc == 0) /* EOF */ - return -EIO; - - if (rc < 0) { - if (errno == EAGAIN) /* read nothing */ - return 0; - else - return -errno; - } - - return rc; -} - -#endif /* !__KERNEL__ || !defined(REDSTORM) */ diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4 index b59aa2e..07e19b6 100644 --- a/lustre/autoconf/lustre-core.m4 +++ b/lustre/autoconf/lustre-core.m4 @@ -1863,10 +1863,6 @@ AC_CHECK_HEADERS([sys/user.h sys/vfs.h stdint.h blkid/blkid.h]) # libcfs/include/libcfs/linux/linux-prim.h, ... AC_CHECK_HEADERS([linux/types.h sys/types.h linux/unistd.h unistd.h]) -# libcfs/libcfs/user-tcpip.c -AC_CHECK_HEADERS([netinet/in.h]) -AC_CHECK_FUNCS([inet_ntoa]) - # libcfs/include/libcfs/linux/linux-prim.h AC_CHECK_HEADERS([linux/random.h], [], [], [#ifdef HAVE_LINUX_TYPES_H -- 1.8.3.1