-#ifdef __KERNEL__
-#include <linux/types.h>
-#include <linux/random.h>
-#else
-#include <liblustre.h>
-#endif
-
-
-#include <linux/kp30.h>
-#include <linux/lustre_handles.h>
-
-static spinlock_t handle_lock = SPIN_LOCK_UNLOCKED;
-static spinlock_t random_lock = SPIN_LOCK_UNLOCKED;
-static struct list_head *handle_hash = NULL;
-static int handle_count = 0;
+#ifndef __KERNEL__
+# include <liblustre.h>
+#endif
+
+#include <obd_support.h>
+#include <lustre_handles.h>
+#include <lustre_lib.h>
+
+#ifndef __KERNEL__
+# define list_add_rcu cfs_list_add
+# define list_del_rcu cfs_list_del
+# define list_for_each_rcu cfs_list_for_each
+# define list_for_each_safe_rcu cfs_list_for_each_safe
+# define list_for_each_entry_rcu cfs_list_for_each_entry
+# define rcu_read_lock() cfs_spin_lock(&bucket->lock)
+# define rcu_read_unlock() cfs_spin_unlock(&bucket->lock)
+#endif /* !__KERNEL__ */
+
+static __u64 handle_base;
+#define HANDLE_INCR 7
+static cfs_spinlock_t handle_base_lock;
+
+static struct handle_bucket {
+ cfs_spinlock_t lock;
+ cfs_list_t head;
+} *handle_hash;
+
+#ifdef __arch_um__
+/* For unknown reason, UML uses kmalloc rather than vmalloc to allocate
+ * memory(OBD_VMALLOC). Therefore, we have to redefine the
+ * HANDLE_HASH_SIZE to make the hash heads don't exceed 128K.
+ */
+#define HANDLE_HASH_SIZE 4096
+#else
+#define HANDLE_HASH_SIZE (1 << 16)
+#endif /* ifdef __arch_um__ */