Whamcloud - gitweb
b=17670
[fs/lustre-release.git] / libcfs / include / libcfs / posix / libcfs.h
index e74e717..37072e0 100644 (file)
@@ -16,8 +16,8 @@
  * 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 [sun.com URL with a
- * copy of GPLv2].
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
  *
  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  * CA 95054 USA or visit www.sun.com if you need additional information or
 #ifndef __LIBCFS_POSIX_LIBCFS_H__
 #define __LIBCFS_POSIX_LIBCFS_H__
 
+#include <errno.h>
 #include <sys/errno.h>
 #include <string.h>
 #include <stdarg.h>
+#include <stddef.h>
 #include <stdio.h>
 #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>
@@ -210,6 +226,7 @@ typedef __u32 cfs_kernel_cap_t;
  */
 struct module {
         int count;
+        char *name;
 };
 
 static inline void MODULE_AUTHOR(char *name)
@@ -219,7 +236,7 @@ static inline void MODULE_AUTHOR(char *name)
 #define MODULE_DESCRIPTION(name) MODULE_AUTHOR(name)
 #define MODULE_LICENSE(name) MODULE_AUTHOR(name)
 
-#define THIS_MODULE NULL
+#define THIS_MODULE (void *)0x11111
 #define __init
 #define __exit
 
@@ -242,4 +259,161 @@ static inline void module_put(struct module *module)
 }
 
 
+static inline int module_refcount(struct module *m)
+{
+        return 1;
+}
+
+/***************************************************************************
+ *
+ * Linux kernel slab shrinker emulation. Currently used only in lu_object.c
+ *
+ ***************************************************************************/
+
+struct shrinker {
+        ;
+};
+
+#define DEFAULT_SEEKS (0)
+
+typedef int (*shrinker_t)(int, unsigned int);
+
+static inline struct shrinker *set_shrinker(int seeks, shrinker_t shrinkert)
+{
+        return (struct shrinker *)0xdeadbea1; // Cannot return NULL here
+}
+
+static inline void remove_shrinker(struct shrinker *shrinker)
+{
+}
+
+/***************************************************************************
+ *
+ * Linux kernel radix tree emulation.
+ *
+ * XXX this stub-implementation assumes that elements stored in a radix tree
+ *     are struct page's and nothing else. Proper implementation will be
+ *     committed soon.
+ *
+ ***************************************************************************/
+
+struct radix_tree_root {
+        struct list_head list;
+        void *rnode;
+};
+
+struct radix_tree_node {
+        struct list_head _node;
+        unsigned long index;
+        void *item;
+};
+
+#define RADIX_TREE_INIT(mask)  {               \
+                NOT_IMPLEMENTED                 \
+}
+
+#define RADIX_TREE(name, mask) \
+       struct radix_tree_root name = RADIX_TREE_INIT(mask)
+
+
+#define INIT_RADIX_TREE(root, mask)                                    \
+do {                                                                   \
+       CFS_INIT_LIST_HEAD(&((struct radix_tree_root *)root)->list);    \
+        ((struct radix_tree_root *)root)->rnode = NULL;                 \
+} while (0)
+
+static inline int radix_tree_insert(struct radix_tree_root *root,
+                        unsigned long idx, void *item)
+{
+        struct radix_tree_node *node;
+        node = malloc(sizeof(*node));
+        if (!node)
+                return -ENOMEM;
+
+        CFS_INIT_LIST_HEAD(&node->_node);
+        node->index = idx;
+        node->item = item;
+        list_add_tail(&node->_node, &root->list);
+        root->rnode = (void *)1001;
+        return 0;
+}
+
+static inline struct radix_tree_node *radix_tree_lookup0(struct radix_tree_root *root,
+                                      unsigned long idx)
+{
+        struct radix_tree_node *node;
+
+        if (list_empty(&root->list))
+                return NULL;
+
+        cfs_list_for_each_entry_typed(node, &root->list,
+                                      struct radix_tree_node, _node)
+                if (node->index == idx)
+                        return node;
+
+        return NULL;
+}
+
+static inline void *radix_tree_lookup(struct radix_tree_root *root,
+                                      unsigned long idx)
+{
+        struct radix_tree_node *node = radix_tree_lookup0(root, idx);
+
+        if (node)
+                return node->item;
+        return node;
+}
+
+static inline void *radix_tree_delete(struct radix_tree_root *root,
+                                      unsigned long idx)
+{
+        struct radix_tree_node *p = radix_tree_lookup0(root, idx);
+        void *item;
+
+        if (p == NULL)
+                return NULL;
+
+        list_del_init(&p->_node);
+        item = p->item;
+        free(p);
+        if (list_empty(&root->list))
+                root->rnode = NULL;
+
+        return item;
+}
+
+static inline unsigned int
+radix_tree_gang_lookup(struct radix_tree_root *root, void **results,
+                       unsigned long first_index, unsigned int max_items)
+{
+        int i;
+        int j = 0;
+
+        for (i = 0; i < max_items; i++, first_index++) {
+                results[j++] = radix_tree_lookup(root, first_index);
+                if (results[j - 1] == NULL)
+                        --j;
+        }
+
+        return j;
+}
+
+static inline int radix_tree_preload(int gfp_mask)
+{
+        return 0;
+}
+
+void radix_tree_init(void);
+
+static inline void radix_tree_preload_end(void)
+{
+}
+
+typedef ssize_t (*read_actor_t)();
+
+#define CFS_IFSHIFT 12
+
+#define CFS_IFTODT(type)           (((type) & S_IFMT) >> CFS_IFSHIFT)
+#define CFS_DTTOIF(dirtype)        ((dirtype) << CFS_IFSHIFT)
+
 #endif