mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-11-17 01:51:00 +03:00
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.
This commit is contained in:
parent
bb1bb2c4c4
commit
b868e22f05
@ -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])],
|
||||
[])
|
||||
])
|
||||
|
82
configure
vendored
82
configure
vendored
@ -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) ;;
|
||||
*)
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user