Skip to content
Snippets Groups Projects
Commit c8616363 authored by mattwu's avatar mattwu
Browse files

b=16150

i=adilger
i=robert
i=liang
winnt libcfs cleanup
parent 5ca10545
No related branches found
No related tags found
No related merge requests found
Showing
with 256 additions and 127 deletions
SUBDIRS := linux posix util
if DARWIN
SUBDIRS += darwin
......@@ -6,7 +5,8 @@ endif
DIST_SUBDIRS := $(SUBDIRS)
EXTRA_DIST := curproc.h libcfs_private.h libcfs.h list.h lltrace.h \
user-lock.h user-prim.h user-time.h \
user-tcpip.h user-bitops.h bitmap.h user-mem.h\
libcfs_prim.h libcfs_private.h libcfs_hash.h libcfs_time.h \
libcfs_debug.h libcfsutil.h libcfs_ioctl.h
user-lock.h user-prim.h user-time.h user-mem.h \
user-tcpip.h user-bitops.h bitmap.h \
libcfs_prim.h libcfs_time.h libcfs_hash.h \
libcfs_debug.h libcfsutil.h libcfs_ioctl.h \
libcfs_pack.h libcfs_unpack.h
......@@ -61,6 +61,10 @@ typedef int16_t __s16;
typedef int32_t __s32;
typedef int64_t __s64;
/* long integer with size equal to pointer */
typedef unsigned long ulong_ptr_t;
typedef long long_ptr_t;
#ifdef __KERNEL__
#include <kern/kern_types.h>
......
......@@ -127,4 +127,16 @@ typedef struct {
# define LL_POISON ((long)0x5a5a5a5a)
# define LP_POISON ((void *)(long)0x5a5a5a5a)
/*
* long_ptr_t & ulong_ptr_t, same to "long" for gcc
*/
# define LPLU "%lu"
# define LPLD "%ld"
# define LPLX "%#lx"
/*
* pid_t
*/
# define LPPID "%d"
#endif
......@@ -56,10 +56,9 @@
#include "curproc.h"
#ifndef offsetof
# define offsetof(typ,memb) ((unsigned long)((char *)&(((typ *)0)->memb)))
# define offsetof(typ,memb) ((long)(long_ptr_t)((char *)&(((typ *)0)->memb)))
#endif
/* cardinality of array */
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(a) ((sizeof (a)) / (sizeof ((a)[0])))
#endif
......@@ -68,31 +67,15 @@
/* given a pointer @ptr to the field @member embedded into type (usually
* struct) @type, return pointer to the embedding instance of @type. */
#define container_of(ptr, type, member) \
((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
((type *)((char *)(ptr)-(char *)(&((type *)0)->member)))
#endif
#define container_of0(ptr, type, member) \
({ \
typeof(ptr) __ptr = (ptr); \
type *__res; \
\
if (unlikely(IS_ERR(__ptr) || __ptr == NULL)) \
__res = (type *)__ptr; \
else \
__res = container_of(__ptr, type, member); \
__res; \
})
static inline int __is_po2(unsigned long long val)
{
return !(val & (val - 1));
}
/*
* true iff @i is power-of-2
*/
#define IS_PO2(i) \
({ \
typeof(i) __i; \
\
__i = (i); \
!(__i & (__i - 1)); \
})
#define IS_PO2(val) __is_po2((unsigned long long)(val))
#define LOWEST_BIT_SET(x) ((x) & ~((x) - 1))
......@@ -301,6 +284,18 @@ int cfs_univ2oflags(int flags);
#include <libcfs/libcfs_prim.h>
#include <libcfs/libcfs_time.h>
/* container_of depends on "likely" which is defined in libcfs_private.h */
static inline void *__container_of(void *ptr, unsigned long shift)
{
if (unlikely(IS_ERR(ptr) || ptr == NULL))
return ptr;
else
return (char *)ptr - shift;
}
#define container_of0(ptr, type, member) \
((type *)__container_of((void *)(ptr), offsetof(type, member)))
#define _LIBCFS_H
#endif /* _LIBCFS_H */
......@@ -179,23 +179,23 @@ static inline int cdebug_show(unsigned int mask, unsigned int subsystem)
((libcfs_debug & mask) && (libcfs_subsystem_debug & subsystem));
}
#define __CDEBUG(cdls, mask, format, a...) \
#define __CDEBUG(cdls, mask, format, ...) \
do { \
CHECK_STACK(); \
\
if (cdebug_show(mask, DEBUG_SUBSYSTEM)) \
libcfs_debug_msg(cdls, DEBUG_SUBSYSTEM, mask, \
__FILE__, __FUNCTION__, __LINE__, \
format, ## a); \
format, ## __VA_ARGS__); \
} while (0)
#define CDEBUG(mask, format, a...) __CDEBUG(NULL, mask, format, ## a)
#define CDEBUG(mask, format, ...) __CDEBUG(NULL, mask, format, ## __VA_ARGS__)
#define CDEBUG_LIMIT(mask, format, a...) \
#define CDEBUG_LIMIT(mask, format, ...) \
do { \
static cfs_debug_limit_state_t cdls; \
\
__CDEBUG(&cdls, mask, format, ## a); \
__CDEBUG(&cdls, mask, format, ## __VA_ARGS__);\
} while (0)
#else /* !CDEBUG_ENABLED */
......@@ -203,18 +203,18 @@ static inline int cdebug_show(unsigned int mask, unsigned int subsystem)
{
return 0;
}
#define CDEBUG(mask, format, a...) (void)(0)
#define CDEBUG_LIMIT(mask, format, a...) (void)(0)
#define CDEBUG(mask, format, ...) (void)(0)
#define CDEBUG_LIMIT(mask, format, ...) (void)(0)
#warning "CDEBUG IS DISABLED. THIS SHOULD NEVER BE DONE FOR PRODUCTION!"
#endif
#else /* !__KERNEL__ && (!__arch_lib__ || LUSTRE_UTILS) */
#define CDEBUG(mask, format, a...) \
#define CDEBUG(mask, format, ...) \
do { \
if (((mask) & D_CANTMASK) != 0) \
fprintf(stderr, "(%s:%d:%s()) " format, \
__FILE__, __LINE__, __FUNCTION__, ## a); \
__FILE__, __LINE__, __FUNCTION__, ## __VA_ARGS__);\
} while (0)
#define CDEBUG_LIMIT CDEBUG
......@@ -222,27 +222,27 @@ do { \
#endif /* !__KERNEL__ ... */
#define CWARN(format, a...) CDEBUG_LIMIT(D_WARNING, format, ## a)
#define CERROR(format, a...) CDEBUG_LIMIT(D_ERROR, format, ## a)
#define CEMERG(format, a...) CDEBUG_LIMIT(D_EMERG, format, ## a)
#define CWARN(format, ...) CDEBUG_LIMIT(D_WARNING, format, ## __VA_ARGS__)
#define CERROR(format, ...) CDEBUG_LIMIT(D_ERROR, format, ## __VA_ARGS__)
#define CEMERG(format, ...) CDEBUG_LIMIT(D_EMERG, format, ## __VA_ARGS__)
#define LCONSOLE(mask, format, a...) CDEBUG(D_CONSOLE | (mask), format, ## a)
#define LCONSOLE_INFO(format, a...) CDEBUG_LIMIT(D_CONSOLE, format, ## a)
#define LCONSOLE_WARN(format, a...) CDEBUG_LIMIT(D_CONSOLE | D_WARNING, format, ## a)
#define LCONSOLE_ERROR_MSG(errnum, format, a...) CDEBUG_LIMIT(D_CONSOLE | D_ERROR, \
"%x-%x: " format, errnum, LERRCHKSUM(errnum), ## a)
#define LCONSOLE_ERROR(format, a...) LCONSOLE_ERROR_MSG(0x00, format, ## a)
#define LCONSOLE(mask, format, ...) CDEBUG(D_CONSOLE | (mask), format, ## __VA_ARGS__)
#define LCONSOLE_INFO(format, ...) CDEBUG_LIMIT(D_CONSOLE, format, ## __VA_ARGS__)
#define LCONSOLE_WARN(format, ...) CDEBUG_LIMIT(D_CONSOLE | D_WARNING, format, ## __VA_ARGS__)
#define LCONSOLE_ERROR_MSG(errnum, format, ...) CDEBUG_LIMIT(D_CONSOLE | D_ERROR, \
"%x-%x: " format, errnum, LERRCHKSUM(errnum), ## __VA_ARGS__)
#define LCONSOLE_ERROR(format, ...) LCONSOLE_ERROR_MSG(0x00, format, ## __VA_ARGS__)
#define LCONSOLE_EMERG(format, a...) CDEBUG(D_CONSOLE | D_EMERG, format, ## a)
#define LCONSOLE_EMERG(format, ...) CDEBUG(D_CONSOLE | D_EMERG, format, ## __VA_ARGS__)
#ifdef CDEBUG_ENABLED
#define GOTO(label, rc) \
do { \
long GOTO__ret = (long)(rc); \
CDEBUG(D_TRACE,"Process leaving via %s (rc=%lu : %ld : %lx)\n", \
#label, (unsigned long)GOTO__ret, (signed long)GOTO__ret,\
(signed long)GOTO__ret); \
long_ptr_t GOTO__ret = (long_ptr_t)(rc); \
CDEBUG(D_TRACE,"Process leaving via %s (rc=" LPLU " : " LPLD \
" : " LPLX ")\n", #label, (ulong_ptr_t)GOTO__ret, \
GOTO__ret, GOTO__ret); \
goto label; \
} while (0)
#else
......@@ -255,6 +255,7 @@ do { \
* if rc == NULL, we need to code as RETURN((void *)NULL), otherwise
* there will be a warning in osx.
*/
#if defined(__GNUC__)
#define RETURN(rc) \
do { \
typeof(rc) RETURN__ret = (rc); \
......@@ -263,6 +264,16 @@ do { \
EXIT_NESTING; \
return RETURN__ret; \
} while (0)
#elif defined(_MSC_VER)
#define RETURN(rc) \
do { \
CDEBUG(D_TRACE, "Process leaving.\n"); \
EXIT_NESTING; \
return (rc); \
} while (0)
#else
# error "Unkown compiler"
#endif /* __GNUC__ */
#define ENTRY \
ENTRY_NESTING; \
......@@ -293,11 +304,11 @@ struct libcfs_debug_msg_data {
};
#define DEBUG_MSG_DATA_INIT(cdls, subsystem, file, func, ln ) { \
.msg_cdls = (cdls), \
.msg_subsys = (subsystem), \
.msg_file = (file), \
.msg_fn = (func), \
.msg_line = (ln) \
/* msg_cdls */ (cdls), \
/* msg_subsys */ (subsystem), \
/* msg_file */ (file), \
/* msg_fn */ (func), \
/* msg_line */ (ln) \
}
......@@ -311,8 +322,8 @@ extern int libcfs_debug_vmsg2(cfs_debug_limit_state_t *cdls,
#define libcfs_debug_vmsg(cdls, subsys, mask, file, fn, line, format, args) \
libcfs_debug_vmsg2(cdls, subsys, mask, file, fn,line,format,args,NULL,NULL)
#define libcfs_debug_msg(cdls, subsys, mask, file, fn, line, format, a...) \
libcfs_debug_vmsg2(cdls, subsys, mask, file, fn,line,NULL,NULL,format, ##a)
#define libcfs_debug_msg(cdls, subsys, mask, file, fn, line, format, ...) \
libcfs_debug_vmsg2(cdls, subsys, mask, file, fn,line,NULL,NULL,format, ## __VA_ARGS__)
#define cdebug_va(cdls, mask, file, func, line, fmt, args) do { \
CHECK_STACK(); \
......@@ -322,17 +333,26 @@ extern int libcfs_debug_vmsg2(cfs_debug_limit_state_t *cdls,
(file), (func), (line), fmt, args); \
} while(0);
#define cdebug(cdls, mask, file, func, line, fmt, a...) do { \
#define cdebug(cdls, mask, file, func, line, fmt, ...) do { \
CHECK_STACK(); \
\
if (cdebug_show(mask, DEBUG_SUBSYSTEM)) \
libcfs_debug_msg(cdls, DEBUG_SUBSYSTEM, (mask), \
(file), (func), (line), fmt, ## a); \
(file), (func), (line), fmt, ## __VA_ARGS__);\
} while(0);
extern void libcfs_assertion_failed(const char *expr, const char *file,
const char *fn, const int line);
#if defined(HAVE_BGL_SUPPORT)
#define DEBUG_FILE_PATH_DEFAULT "/bgl/ion/tmp/lustre-log"
#elif defined(__arch_um__)
#define DEBUG_FILE_PATH_DEFAULT "/r/tmp/lustre-log"
#elif defined(__WINNT__)
#define DEBUG_FILE_PATH_DEFAULT "\\SystemRoot\\temp\\lustre-log"
#else
#define DEBUG_FILE_PATH_DEFAULT "/tmp/lustre-log"
#endif
#endif /* __LIBCFS_DEBUG_H__ */
#if !defined(__GNUC__) && defined(_MSC_VER)
#pragma warning(disable:4103)
#pragma pack(push, 1)
#endif
......@@ -69,7 +69,7 @@ int64_t cfs_waitq_timedwait(cfs_waitlink_t *link, cfs_task_state_t state,
/*
* Timer
*/
typedef void (cfs_timer_func_t)(unsigned long);
typedef void (cfs_timer_func_t)(ulong_ptr_t);
void cfs_init_timer(cfs_timer_t *t);
void cfs_timer_init(cfs_timer_t *t, cfs_timer_func_t *func, void *arg);
......
......@@ -71,55 +71,53 @@
*
* requires -Wall. Unfortunately this rules out use of likely/unlikely.
*/
#define LASSERT(cond) \
({ \
if (cond) \
; \
else \
libcfs_assertion_failed( #cond , __FILE__, \
__FUNCTION__, __LINE__); \
})
#define LASSERTF(cond, fmt, a...) \
({ \
#define LASSERT(cond) \
do { \
if (cond) \
; \
else \
libcfs_assertion_failed( #cond , __FILE__, \
__FUNCTION__, __LINE__); \
} while(0)
#define LASSERTF(cond, fmt, ...) \
do { \
if (cond) \
; \
else { \
libcfs_debug_msg(NULL, DEBUG_SUBSYSTEM, D_EMERG, \
__FILE__, __FUNCTION__,__LINE__, \
"ASSERTION(" #cond ") failed: " fmt, \
## a); \
## __VA_ARGS__); \
LBUG(); \
} \
})
} while(0)
#else /* !LASSERT_CHECKED */
#define LASSERT(cond) \
({ \
if (unlikely(!(cond))) \
libcfs_assertion_failed(#cond , __FILE__, \
__FUNCTION__, __LINE__); \
})
#define LASSERT(cond) \
do { \
if (unlikely(!(cond))) \
libcfs_assertion_failed(#cond , __FILE__, \
__FUNCTION__, __LINE__); \
} while(0)
#define LASSERTF(cond, fmt, a...) \
({ \
#define LASSERTF(cond, fmt, ...) \
do { \
if (unlikely(!(cond))) { \
libcfs_debug_msg(NULL, DEBUG_SUBSYSTEM, D_EMERG, \
__FILE__, __FUNCTION__,__LINE__, \
"ASSERTION(" #cond ") failed: " fmt, \
## a); \
## __VA_ARGS__ ); \
LBUG(); \
} \
})
} while(0)
#endif /* !LASSERT_CHECKED */
#else /* !LIBCFS_DEBUG */
/* sizeof is to use expression without evaluating it. */
# define LASSERT(e) ((void)sizeof!!(e))
# define LASSERTF(cond, fmt...) ((void)sizeof!!(cond))
# define LASSERTF(cond, ...) ((void)sizeof!!(cond))
#endif /* !LIBCFS_DEBUG */
#ifdef INVARIANT_CHECK
......@@ -237,10 +235,10 @@ void libcfs_debug_set_level(unsigned int debug_level);
# undef NDEBUG
# include <assert.h>
# define LASSERT(e) assert(e)
# define LASSERTF(cond, args...) \
# define LASSERTF(cond, ...) \
do { \
if (!(cond)) \
CERROR(args); \
CERROR(__VA_ARGS__); \
assert(cond); \
} while (0)
# define LBUG() assert(0)
......@@ -251,12 +249,12 @@ do { \
# endif
# else
# define LASSERT(e) ((void)sizeof!!(e))
# define LASSERTF(cond, args...) ((void)sizeof!!(cond))
# define LASSERTF(cond, ...) ((void)sizeof!!(cond))
# define LBUG() ((void)(0))
# define LINVRNT(exp) ((void)sizeof!!(exp))
# endif /* LIBCFS_DEBUG */
# define KLASSERT(e) ((void)0)
# define printk(format, args...) printf (format, ## args)
# define printk printf
# ifdef CRAY_XT3 /* buggy calloc! */
# define LIBCFS_ALLOC(ptr, size) \
do { \
......@@ -277,10 +275,13 @@ int libcfs_debug_cleanup(void);
* build go below this comment. Actual compiler/compiler version
* specific implementations come from the above header files
*/
#ifdef __GNUC__
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#else
#define likely(x) (!!(x))
#define unlikely(x) (!!(x))
#endif
/* !__KERNEL__ */
#endif
......@@ -298,7 +299,7 @@ int libcfs_debug_cleanup(void);
* value after conversion...
*
*/
#define CLASSERT(cond) ({ switch(42) { case (cond): case 0: break; } })
#define CLASSERT(cond) do {switch(42) {case (cond): case 0: break;}} while (0)
/* support decl needed both by kernel and liblustre */
int libcfs_isknown_lnd(int type);
......
......@@ -47,12 +47,12 @@
static inline cfs_time_t cfs_time_add(cfs_time_t t, cfs_duration_t d)
{
return t + d;
return (cfs_time_t)(t + d);
}
static inline cfs_duration_t cfs_time_sub(cfs_time_t t1, cfs_time_t t2)
{
return t1 - t2;
return (cfs_time_t)(t1 - t2);
}
static inline int cfs_time_before(cfs_time_t t1, cfs_time_t t2)
......
#if !defined(__GNUC__) && defined(_MSC_VER)
#pragma warning(disable:4103)
#pragma pack(pop)
#endif
......@@ -354,6 +354,18 @@ extern int lwt_snapshot (cycles_t *now, int *ncpu, int *total_size,
# define LPF64 "l"
#endif
/*
* long_ptr_t & ulong_ptr_t, same to "long" for gcc
*/
# define LPLU "%lu"
# define LPLD "%ld"
# define LPLX "%#lx"
/*
* pid_t
*/
# define LPPID "%d"
#ifdef HAVE_SIZE_T_LONG
# define LPSZ "%lu"
#else
......
......@@ -117,6 +117,10 @@ typedef kernel_cap_t cfs_kernel_cap_t;
struct cfs_stack_trace {
};
/* long integer with size equal to pointer */
typedef unsigned long ulong_ptr_t;
typedef long long_ptr_t;
#ifndef WITH_WATCHDOG
#define WITH_WATCHDOG
#endif
......
......@@ -82,6 +82,7 @@
* - down_write(x)
* - up_write(x)
*/
#define fini_rwsem(s) do {} while(0)
/*
* rwlock_t (use Linux kernel's primitives)
......
......@@ -53,6 +53,7 @@
#include <linux/config.h>
#endif
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/proc_fs.h>
......@@ -204,15 +205,15 @@ do { \
retval == 0; condition met; we're good.
retval > 0; timed out.
*/
#define cfs_waitq_wait_event_timeout(wq, condition, timeout) \
({ \
int __ret = 0; \
#define cfs_waitq_wait_event_timeout(wq, condition, timeout, ret) \
do { \
ret = 0; \
if (!(condition)) \
__wait_event_timeout(wq, condition, timeout, __ret); \
__ret; \
})
__wait_event_timeout(wq, condition, timeout, ret); \
} while (0)
#else
#define cfs_waitq_wait_event_timeout wait_event_timeout
#define cfs_waitq_wait_event_timeout(wq, condition, timeout, ret) \
ret = wait_event_timeout(wq, condition, timeout)
#endif
#ifndef wait_event_interruptible_timeout /* Only for RHEL3 2.4.21 kernel */
......@@ -251,16 +252,16 @@ do { \
retval < 0; interrupted by signal.
retval > 0; timed out.
*/
#define cfs_waitq_wait_event_interruptible_timeout(wq, condition, timeout) \
({ \
int __ret = 0; \
#define cfs_waitq_wait_event_interruptible_timeout(wq, condition, timeout, ret)\
do { \
ret = 0; \
if (!(condition)) \
__wait_event_interruptible_timeout(wq, condition, \
timeout, __ret); \
__ret; \
})
timeout, ret); \
} while (0)
#else
#define cfs_waitq_wait_event_interruptible_timeout wait_event_interruptible_timeout
#define cfs_waitq_wait_event_interruptible_timeout(wq, c, timeout, ret) \
ret = wait_event_interruptible_timeout(wq, c, timeout)
#endif
#endif
......@@ -96,6 +96,11 @@
#endif
# define cfs_wait_event_interruptible(wq, condition, ret) \
ret = wait_event_interruptible(wq, condition)
# define cfs_wait_event_interruptible_exclusive(wq, condition, ret) \
ret = wait_event_interruptible(wq, condition)
#if defined(__arch_um__) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,20))
#define UML_PID(tsk) ((tsk)->thread.extern_pid)
#elif defined(__arch_um__) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
......
......@@ -28,11 +28,7 @@
* using the generic single-entry routines.
*/
#ifndef __WINNT__
#define prefetch(a) ((void)a)
#else
#define prefetch(a) ((void *)a)
#endif
struct list_head {
struct list_head *next, *prev;
......@@ -208,7 +204,7 @@ static inline void list_splice_init(struct list_head *list,
* @member: the name of the list_struct within the struct.
*/
#define list_entry(ptr, type, member) \
((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
((type *)((char *)(ptr)-(char *)(&((type *)0)->member)))
/**
* list_for_each - iterate over a list
......@@ -253,8 +249,8 @@ struct hlist_node {
#define NULL_P ((void *)0)
#endif
#define CFS_HLIST_HEAD_INIT { .first = NULL_P }
#define CFS_HLIST_HEAD(name) struct hlist_head name = { .first = NULL_P }
#define CFS_HLIST_HEAD_INIT { NULL_P }
#define CFS_HLIST_HEAD(name) struct hlist_head name = { NULL_P }
#define CFS_INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL_P)
#define CFS_INIT_HLIST_NODE(ptr) ((ptr)->next = NULL_P, (ptr)->pprev = NULL_P)
......@@ -329,11 +325,11 @@ static inline void hlist_add_after(struct hlist_node *n,
#define hlist_entry(ptr, type, member) container_of(ptr,type,member)
#define hlist_for_each(pos, head) \
for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \
for (pos = (head)->first; pos && (prefetch(pos->next), 1); \
pos = pos->next)
#define hlist_for_each_safe(pos, n, head) \
for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
for (pos = (head)->first; pos && (n = pos->next, 1); \
pos = n)
/**
......@@ -395,7 +391,7 @@ static inline void hlist_add_after(struct hlist_node *n,
* @head: the head for your list.
*/
#define list_for_each_prev(pos, head) \
for (pos = (head)->prev, prefetch(pos->prev); pos != (head); \
for (pos = (head)->prev, prefetch(pos->prev); pos != (head); \
pos = pos->prev, prefetch(pos->prev))
#endif /* list_for_each_prev */
......@@ -441,6 +437,7 @@ static inline void hlist_add_after(struct hlist_node *n,
n = list_entry(pos->member.next, typeof(*pos), member); \
&pos->member != (head); \
pos = n, n = list_entry(n->member.next, typeof(*n), member))
#endif /* list_for_each_entry_safe */
#ifndef list_for_each_entry_safe_from
......@@ -454,10 +451,44 @@ static inline void hlist_add_after(struct hlist_node *n,
* Iterate over list of given type from current point, safe against
* removal of list entry.
*/
#define list_for_each_entry_safe_from(pos, n, head, member) \
for (n = list_entry(pos->member.next, typeof(*pos), member); \
&pos->member != (head); \
#define list_for_each_entry_safe_from(pos, n, head, member) \
for (n = list_entry(pos->member.next, typeof(*pos), member); \
&pos->member != (head); \
pos = n, n = list_entry(n->member.next, typeof(*n), member))
#endif /* list_for_each_entry_safe_from */
#define cfs_list_for_each_entry_typed(pos, head, type, member) \
for (pos = list_entry((head)->next, type, member), \
prefetch(pos->member.next); \
&pos->member != (head); \
pos = list_entry(pos->member.next, type, member), \
prefetch(pos->member.next))
#define cfs_list_for_each_entry_reverse_typed(pos, head, type, member) \
for (pos = list_entry((head)->prev, type, member); \
prefetch(pos->member.prev), &pos->member != (head); \
pos = list_entry(pos->member.prev, type, member))
#define cfs_list_for_each_entry_safe_typed(pos, n, head, type, member) \
for (pos = list_entry((head)->next, type, member), \
n = list_entry(pos->member.next, type, member); \
&pos->member != (head); \
pos = n, n = list_entry(n->member.next, type, member))
#define cfs_list_for_each_entry_safe_from_typed(pos, n, head, type, member) \
for (n = list_entry(pos->member.next, type, member); \
&pos->member != (head); \
pos = n, n = list_entry(n->member.next, type, member))
#define cfs_hlist_for_each_entry_typed(tpos, pos, head, type, member) \
for (pos = (head)->first; \
pos && (prefetch(pos->next), 1) && \
(tpos = hlist_entry(pos, type, member), 1); \
pos = pos->next)
#define cfs_hlist_for_each_entry_safe_typed(tpos, pos, n, head, type, member)\
for (pos = (head)->first; \
pos && (n = pos->next, 1) && \
(tpos = hlist_entry(pos, type, member), 1); \
pos = n)
#endif /* __LIBCFS_LUSTRE_LIST_H__ */
......@@ -43,6 +43,7 @@
#ifndef __LIBCFS_POSIX_LIBCFS_H__
#define __LIBCFS_POSIX_LIBCFS_H__
#include <errno.h>
#include <sys/errno.h>
#include <string.h>
#include <stdarg.h>
......@@ -51,14 +52,28 @@
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <limits.h>
#include <assert.h>
#include <sys/ioctl.h>
#include <sys/signal.h>
#include <signal.h>
#include <sys/time.h>
#include <time.h>
#include <getopt.h>
#include <signal.h>
#include <pwd.h>
#include <sys/socket.h>
#include <sys/utsname.h>
#include <ctype.h>
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_LIBPTHREAD
#include <pthread.h>
......@@ -331,7 +346,8 @@ static inline struct radix_tree_node *radix_tree_lookup0(struct radix_tree_root
if (list_empty(&root->list))
return NULL;
list_for_each_entry(node, &root->list, _node)
cfs_list_for_each_entry_typed(node, &root->list,
struct radix_tree_node, _node)
if (node->index == idx)
return node;
......
......@@ -61,4 +61,8 @@ typedef unsigned int __u32;
typedef __signed__ long long __s64;
typedef unsigned long long __u64;
/* long integer with size equal to pointer */
typedef unsigned long ulong_ptr_t;
typedef long long_ptr_t;
#endif
......@@ -146,4 +146,16 @@ typedef struct {
# error "No word size defined"
#endif
/*
* long_ptr_t & ulong_ptr_t, same to "long" for gcc
*/
# define LPLU "%lu"
# define LPLD "%ld"
# define LPLX "%#lx"
/*
* pid_t
*/
# define LPPID "%d"
#endif
......@@ -149,6 +149,7 @@ struct completion {
typedef int (*cfs_wait_handler_t) (int timeout);
void set_completion_wait_handler(cfs_wait_handler_t *handler);
void init_completion(struct completion *c);
void init_completion_module(cfs_wait_handler_t handler);
void complete(struct completion *c);
void wait_for_completion(struct completion *c);
int wait_for_completion_interruptible(struct completion *c);
......@@ -182,6 +183,7 @@ void down_write(struct rw_semaphore *s);
int down_write_trylock(struct rw_semaphore *s);
void up_read(struct rw_semaphore *s);
void up_write(struct rw_semaphore *s);
void fini_rwsem(struct rw_semaphore *s);
/*
* read-write lock : Need to be investigated more!!
......@@ -348,7 +350,7 @@ static inline int mutex_is_locked(struct mutex *lock)
**************************************************************************/
struct lock_class_key {
;
int foo;
};
static inline void lockdep_set_class(void *lock, struct lock_class_key *key)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment