endif
DIST_SUBDIRS = linux posix util darwin
-EXTRA_DIST = curproc.h libcfs_private.h libcfs.h list.h \
- user-lock.h user-prim.h user-time.h user-mem.h \
- user-tcpip.h user-bitops.h bitmap.h user-crypto.h \
- libcfs_prim.h libcfs_time.h libcfs_hash.h libcfs_cpu.h \
- libcfs_debug.h libcfsutil.h libcfs_ioctl.h \
- libcfs_pack.h libcfs_unpack.h libcfs_string.h \
- libcfs_kernelcomm.h libcfs_workitem.h lucache.h \
- libcfs_fail.h params_tree.h libcfs_crypto.h libcfs_heap.h
+EXTRA_DIST = \
+ bitmap.h \
+ curproc.h \
+ err.h \
+ libcfs.h \
+ libcfs_cpu.h \
+ libcfs_crypto.h \
+ libcfs_debug.h \
+ libcfs_fail.h \
+ libcfs_hash.h \
+ libcfs_heap.h \
+ libcfs_ioctl.h \
+ libcfs_kernelcomm.h \
+ libcfs_pack.h \
+ libcfs_prim.h \
+ libcfs_private.h \
+ libcfs_string.h \
+ libcfs_time.h \
+ libcfs_unpack.h \
+ libcfs_workitem.h \
+ libcfsutil.h \
+ list.h \
+ lucache.h \
+ params_tree.h \
+ user-bitops.h \
+ user-crypto.h \
+ user-lock.h \
+ user-mem.h \
+ user-prim.h \
+ user-tcpip.h \
+ user-time.h
#define KERN_INFO "<6>" /* informational */
#define KERN_DEBUG "<7>" /* debug-level messages */
-static inline long PTR_ERR(const void *ptr)
-{
- return (long) ptr;
-}
-
-#define ERR_PTR(err) ((void *)err)
-#define IS_ERR(p) ((unsigned long)(p) + 1000 < 1000)
-
#else /* !__KERNEL__ */
typedef struct cfs_proc_dir_entry {
--- /dev/null
+/*
+ * 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
+ */
+/*
+ * Copyright (c) 2014, Intel Corporation.
+ * Author: John L. Hammond <john.hammond@intel.com>
+ */
+#ifndef LIBCFS_ERR_H_
+#define LIBCFS_ERR_H_
+
+#if defined(__linux__) && defined(__KERNEL__)
+# include <linux/err.h>
+#else /* __KERNEL__ */
+
+# define IS_ERR_VALUE(x) ((x) >= (unsigned long)-4095)
+
+static inline void *ERR_PTR(long error)
+{
+ return (void *)error;
+}
+
+static inline long PTR_ERR(const void *ptr)
+{
+ return (long)ptr;
+}
+
+static inline long IS_ERR(const void *ptr)
+{
+ return IS_ERR_VALUE((unsigned long)ptr);
+}
+
+static inline long IS_ERR_OR_NULL(const void *ptr)
+{
+ return IS_ERR_VALUE((unsigned long)ptr) || ptr == NULL;
+}
+
+/**
+ * ERR_CAST - Explicitly cast an error-valued pointer to another pointer type
+ * @ptr: The pointer to cast.
+ *
+ * Explicitly cast an error-valued pointer to another pointer type in such a
+ * way as to make it clear that's what's going on.
+ */
+static inline void *ERR_CAST(const void *ptr)
+{
+ /* Cast away the const. */
+ return (void *)ptr;
+}
+
+# endif /* !__KERNEL__ */
+
+#endif /* LIBCFS_ERR_H_ */
void cfs_srand(unsigned int, unsigned int);
void cfs_get_random_bytes(void *buf, int size);
+#include <libcfs/err.h>
#include <libcfs/libcfs_debug.h>
#include <libcfs/libcfs_cpu.h>
#include <libcfs/libcfs_private.h>
#include <libcfs/libcfs_crypto.h>
/* container_of depends on "likely" which is defined in libcfs_private.h */
-static inline void *__container_of(void *ptr, unsigned long shift)
+static inline void *__container_of(const void *ptr, unsigned long shift)
{
- if (unlikely(IS_ERR(ptr) || ptr == NULL))
- return ptr;
- else
- return (char *)ptr - shift;
+ if (unlikely(IS_ERR(ptr) || ptr == NULL))
+ return ERR_CAST(ptr);
+ else
+ return (char *)ptr - shift;
}
-#define container_of0(ptr, type, member) \
- ((type *)__container_of((void *)(ptr), offsetof(type, member)))
+#define container_of0(ptr, type, member) \
+ ((type *)__container_of((ptr), offsetof(type, member)))
#define _LIBCFS_H
# define do_gettimeofday(tv) gettimeofday(tv, NULL);
typedef unsigned long long cfs_cycles_t;
-#define IS_ERR(a) ((unsigned long)(a) > (unsigned long)-1000L)
-#define IS_ERR_VALUE(a) (IS_ERR(a))
-#define PTR_ERR(a) ((long)(a))
-#define ERR_PTR(a) ((void*)((long)(a)))
-
/* this goes in posix-fs.h */
#include <sys/mount.h>
* misc
*/
-#define ERR_PTR(error) ((void *)(long_ptr_t)(error))
-#define PTR_ERR(ptr) ((long)(long_ptr_t) (ptr))
-#define IS_ERR(ptr) ((long)(((ulong_ptr_t) (ptr)) > (ulong_ptr_t)(-1000L)))
-
#endif /* __LIBCFS_WINNT_CFS_FS_H__*/
return obj ? lu2cl(lu_object_next(&obj->co_lu)) : NULL;
}
-static inline struct cl_device *cl_object_device(const struct cl_object *o)
-{
- LASSERT(o == NULL || IS_ERR(o) || lu_device_is_cl(o->co_lu.lo_dev));
- return container_of0(o->co_lu.lo_dev, struct cl_device, cd_lu_dev);
-}
-
static inline struct cl_object_header *luh2coh(const struct lu_object_header *h)
{
return container_of0(h, struct cl_object_header, coh_lu);
#include <darwin/lustre_compat.h>
-/* for obd_class.h */
-# ifndef ERR_PTR
-# define ERR_PTR(a) ((void *)(a))
-# endif
-
#endif
#else /* !__KERNEL__ */
# define LTIME_S(time) (time)
/* for obd_class.h */
-# ifndef ERR_PTR
-# define ERR_PTR(a) ((void *)(a))
-# endif
#endif /* __KERNEL__ */
#endif
return (obj ? lu2md(lu_object_next(&obj->mo_lu)) : NULL);
}
-static inline struct md_device *md_obj2dev(const struct md_object *o)
-{
- LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->mo_lu.lo_dev));
- return container_of0(o->mo_lu.lo_dev, struct md_device, md_lu_dev);
-}
-
static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
{
return lu_device_init(&md->md_lu_dev, t);