diff options
author | Brian Behlendorf <[email protected]> | 2010-06-11 14:48:18 -0700 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2010-06-11 15:57:25 -0700 |
commit | b868e22f05fd85be16afee800207f72b8e310d32 (patch) | |
tree | da050e86b8d79b4de1eac65640aa1506b06d51ea | |
parent | bb1bb2c4c49659b47d65beb8ac24dc2c86989553 (diff) |
Add kmem_asprintf(), strfree(), strdup(), and minor cleanup.
This patch adds three missing Solaris functions: kmem_asprintf(), strfree(),
and strdup(). They are all implemented as a thin layer which just calls
their Linux counterparts. As part of this an autoconf check for kvasprintf
was added because it does not appear in older kernels. If the kernel does
not provide it then spl-generic implements it.
Additionally the dead DEBUG_KMEM_UNIMPLEMENTED code was removed to clean
things up and make the kmem.h a little more readable.
-rw-r--r-- | config/spl-build.m4 | 14 | ||||
-rwxr-xr-x | configure | 82 | ||||
-rw-r--r-- | include/sys/kmem.h | 55 | ||||
-rw-r--r-- | module/spl/spl-kmem.c | 46 | ||||
-rw-r--r-- | spl_config.h.in | 3 |
5 files changed, 149 insertions, 51 deletions
diff --git a/config/spl-build.m4 b/config/spl-build.m4 index a0fdb3e82..6f312e25a 100644 --- a/config/spl-build.m4 +++ b/config/spl-build.m4 @@ -75,6 +75,7 @@ AC_DEFUN([SPL_AC_CONFIG_KERNEL], [ SPL_AC_GROUPS_SEARCH SPL_AC_PUT_TASK_STRUCT SPL_AC_5ARGS_PROC_HANDLER + SPL_AC_KVASPRINTF ]) AC_DEFUN([SPL_AC_MODULE_SYMVERS], [ @@ -1399,3 +1400,16 @@ AC_DEFUN([SPL_AC_5ARGS_PROC_HANDLER], [ AC_MSG_RESULT(no) ]) ]) + +dnl # +dnl # 2.6.x API change, +dnl # kvasprintf() function added. +dnl # +AC_DEFUN([SPL_AC_KVASPRINTF], [ + SPL_CHECK_SYMBOL_EXPORT( + [kvasprintf], + [], + [AC_DEFINE(HAVE_KVASPRINTF, 1, + [kvasprintf() is available])], + []) +]) @@ -14826,6 +14826,47 @@ fi + + { $as_echo "$as_me:$LINENO: checking whether symbol kvasprintf is exported" >&5 +$as_echo_n "checking whether symbol kvasprintf is exported... " >&6; } + grep -q -E '[[:space:]]kvasprintf[[:space:]]' \ + $LINUX_OBJ/Module*.symvers 2>/dev/null + rc=$? + if test $rc -ne 0; then + export=0 + for file in ; do + grep -q -E "EXPORT_SYMBOL.*(kvasprintf)" \ + "$LINUX_OBJ/$file" 2>/dev/null + rc=$? + if test $rc -eq 0; then + export=1 + break; + fi + done + if test $export -eq 0; then + { $as_echo "$as_me:$LINENO: result: no" >&5 +$as_echo "no" >&6; } + + else + { $as_echo "$as_me:$LINENO: result: yes" >&5 +$as_echo "yes" >&6; } + +cat >>confdefs.h <<\_ACEOF +#define HAVE_KVASPRINTF 1 +_ACEOF + + fi + else + { $as_echo "$as_me:$LINENO: result: yes" >&5 +$as_echo "yes" >&6; } + +cat >>confdefs.h <<\_ACEOF +#define HAVE_KVASPRINTF 1 +_ACEOF + + fi + + ;; user) ;; all) @@ -18180,6 +18221,47 @@ fi + { $as_echo "$as_me:$LINENO: checking whether symbol kvasprintf is exported" >&5 +$as_echo_n "checking whether symbol kvasprintf is exported... " >&6; } + grep -q -E '[[:space:]]kvasprintf[[:space:]]' \ + $LINUX_OBJ/Module*.symvers 2>/dev/null + rc=$? + if test $rc -ne 0; then + export=0 + for file in ; do + grep -q -E "EXPORT_SYMBOL.*(kvasprintf)" \ + "$LINUX_OBJ/$file" 2>/dev/null + rc=$? + if test $rc -eq 0; then + export=1 + break; + fi + done + if test $export -eq 0; then + { $as_echo "$as_me:$LINENO: result: no" >&5 +$as_echo "no" >&6; } + + else + { $as_echo "$as_me:$LINENO: result: yes" >&5 +$as_echo "yes" >&6; } + +cat >>confdefs.h <<\_ACEOF +#define HAVE_KVASPRINTF 1 +_ACEOF + + fi + else + { $as_echo "$as_me:$LINENO: result: yes" >&5 +$as_echo "yes" >&6; } + +cat >>confdefs.h <<\_ACEOF +#define HAVE_KVASPRINTF 1 +_ACEOF + + fi + + + ;; srpm) ;; *) diff --git a/include/sys/kmem.h b/include/sys/kmem.h index 2dd73a8e5..b6da6d0ac 100644 --- a/include/sys/kmem.h +++ b/include/sys/kmem.h @@ -25,8 +25,6 @@ #ifndef _SPL_KMEM_H #define _SPL_KMEM_H -#undef DEBUG_KMEM_UNIMPLEMENTED - #include <linux/module.h> #include <linux/slab.h> #include <linux/vmalloc.h> @@ -218,14 +216,6 @@ extern void vmem_free_debug(void *ptr, size_t size); #endif /* DEBUG_KMEM */ -#ifdef DEBUG_KMEM_UNIMPLEMENTED -static __inline__ void * -kmem_alloc_tryhard(size_t size, size_t *alloc_size, int kmflags) -{ -#error "kmem_alloc_tryhard() not implemented" -} -#endif /* DEBUG_KMEM_UNIMPLEMENTED */ - /* * Slab allocation interfaces */ @@ -256,47 +246,10 @@ enum { #define KMC_REAP_CHUNK INT_MAX #define KMC_DEFAULT_SEEKS 1 -#ifdef DEBUG_KMEM_UNIMPLEMENTED -static __inline__ void kmem_init(void) { -#error "kmem_init() not implemented" -} - -static __inline__ void kmem_thread_init(void) { -#error "kmem_thread_init() not implemented" -} - -static __inline__ void kmem_mp_init(void) { -#error "kmem_mp_init() not implemented" -} - -static __inline__ void kmem_reap_idspace(void) { -#error "kmem_reap_idspace() not implemented" -} - -static __inline__ size_t kmem_avail(void) { -#error "kmem_avail() not implemented" -} - -static __inline__ size_t kmem_maxavail(void) { -#error "kmem_maxavail() not implemented" -} - -static __inline__ uint64_t kmem_cache_stat(spl_kmem_cache_t *cache) { -#error "kmem_cache_stat() not implemented" -} -#endif /* DEBUG_KMEM_UNIMPLEMENTED */ - -/* XXX - Used by arc.c to adjust its memory footprint. We may want - * to use this hook in the future to adjust behavior based on - * debug levels. For now it's safe to always return 0. - */ -static __inline__ int -kmem_debugging(void) -{ - return 0; -} - -extern int kmem_set_warning(int flag); +extern int kmem_debugging(void); +extern char *kmem_asprintf(const char *fmt, ...); +#define strfree(str) kfree(str) +#define strdup(str) kstrdup(str, GFP_KERNEL) extern struct list_head spl_kmem_cache_list; extern struct rw_semaphore spl_kmem_cache_sem; diff --git a/module/spl/spl-kmem.c b/module/spl/spl-kmem.c index 5a421d40e..117959546 100644 --- a/module/spl/spl-kmem.c +++ b/module/spl/spl-kmem.c @@ -208,6 +208,52 @@ vmem_size(vmem_t *vmp, int typemask) } EXPORT_SYMBOL(vmem_size); +int +kmem_debugging(void) +{ + return 0; +} +EXPORT_SYMBOL(kmem_debugging); + +#ifndef HAVE_KVASPRINTF +/* Simplified asprintf. */ +char *kvasprintf(gfp_t gfp, const char *fmt, va_list ap) +{ + unsigned int len; + char *p; + va_list aq; + + va_copy(aq, ap); + len = vsnprintf(NULL, 0, fmt, aq); + va_end(aq); + + p = kmalloc(len+1, gfp); + if (!p) + return NULL; + + vsnprintf(p, len+1, fmt, ap); + + return p; +} +EXPORT_SYMBOL(kvasprintf); +#endif /* HAVE_KVASPRINTF */ + +char * +kmem_asprintf(const char *fmt, ...) +{ + va_list args; + char *ptr; + + va_start(args, fmt); + do { + ptr = kvasprintf(GFP_KERNEL, fmt, args); + } while (ptr == NULL); + va_end(args); + + return ptr; +} +EXPORT_SYMBOL(kmem_asprintf); + /* * Memory allocation interfaces and debugging for basic kmem_* * and vmem_* style memory allocation. When DEBUG_KMEM is enabled diff --git a/spl_config.h.in b/spl_config.h.in index ac608d44f..fdef876b3 100644 --- a/spl_config.h.in +++ b/spl_config.h.in @@ -102,6 +102,9 @@ /* kmalloc_node() is available */ #undef HAVE_KMALLOC_NODE +/* kvasprintf() is available */ +#undef HAVE_KVASPRINTF + /* Define to 1 if you have the <memory.h> header file. */ #undef HAVE_MEMORY_H |