X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=libcfs%2Finclude%2Flibcfs%2Flibcfs.h;h=4a96608cfa7a9e0bff606e281ebdacf90510da51;hb=fa507031d245b08c7f24efed32819daf2aa42ab3;hp=5486e0c4f085e6f0795c26478b613c63b1f53d49;hpb=4dfa0e1c84605218376feea6d5cfe6402249148e;p=fs%2Flustre-release.git diff --git a/libcfs/include/libcfs/libcfs.h b/libcfs/include/libcfs/libcfs.h index 5486e0c..4a96608 100644 --- a/libcfs/include/libcfs/libcfs.h +++ b/libcfs/include/libcfs/libcfs.h @@ -26,7 +26,7 @@ * GPL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved + * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. */ /* @@ -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)) @@ -120,6 +103,10 @@ #include +#ifndef cfs_for_each_possible_cpu +# error cfs_for_each_possible_cpu is not supported by kernel! +#endif + /* libcfs tcpip */ int libcfs_ipif_query(char *name, int *up, __u32 *ip, __u32 *mask); int libcfs_ipif_enumerate(char ***names); @@ -147,8 +134,10 @@ struct lc_watchdog *lc_watchdog_add(int time, void *data); /* Enables a watchdog and resets its timer. */ -void lc_watchdog_touch_ms(struct lc_watchdog *lcw, int timeout_ms); -void lc_watchdog_touch(struct lc_watchdog *lcw); +void lc_watchdog_touch(struct lc_watchdog *lcw, int timeout); +#define CFS_GET_TIMEOUT(svc) (max_t(int, obd_timeout, \ + AT_OFF ? 0 : at_get(&svc->srv_at_estimate)) * \ + svc->srv_watchdog_factor) /* Disable a watchdog; touch it to restart it. */ void lc_watchdog_disable(struct lc_watchdog *lcw); @@ -271,10 +260,15 @@ void cfs_stack_trace_fill(struct cfs_stack_trace *trace); */ void *cfs_stack_trace_frame(struct cfs_stack_trace *trace, int frame_no); +#ifndef O_NOACCESS +#define O_NOACCESS O_NONBLOCK +#endif + /* * Universal open flags. */ -#define CFS_O_ACCMODE 0003 +#define CFS_O_NOACCESS 0003 +#define CFS_O_ACCMODE CFS_O_NOACCESS #define CFS_O_CREAT 0100 #define CFS_O_EXCL 0200 #define CFS_O_NOCTTY 0400 @@ -295,11 +289,38 @@ int cfs_oflags2univ(int flags); /* convert universal open flags to local open flags */ int cfs_univ2oflags(int flags); +/* + * Random number handling + */ + +/* returns a random 32-bit integer */ +unsigned int cfs_rand(void); +/* seed the generator */ +void cfs_srand(unsigned int, unsigned int); +void cfs_get_random_bytes(void *buf, int size); + #include #include #include #include #include +#include +#include +#include +#include +#include + +/* 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