* Copyright (C) 2002 Cluster File Systems, Inc.
* Author: Phil Schwan <phil@clusterfs.com>
*
- * This file is part of Portals, http://www.sf.net/projects/sandiaportals/
+ * This file is part of Lustre, http://www.lustre.org/
*
- * Portals is free software; you can redistribute it and/or
- * modify it under the terms of version 2.1 of the GNU Lesser General
- * Public License as published by the Free Software Foundation.
+ * Lustre is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
*
- * Portals is distributed in the hope that it will be useful,
+ * Lustre 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 Lesser General Public License for more details.
+ * GNU General Public License for more details.
*
- * You should have received a copy of the GNU Lesser General Public
- * License along with Portals; if not, write to the Free Software
+ * You should have received a copy of the GNU General Public License
+ * along with Lustre; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#define DEBUG_SUBSYSTEM S_CLASS
#ifdef __KERNEL__
-#include <linux/types.h>
-#include <linux/random.h>
+# include <linux/types.h>
+# include <linux/random.h>
#else
-#include <liblustre.h>
+# include <liblustre.h>
#endif
-
-#include <linux/kp30.h>
+#include <linux/obd_support.h>
#include <linux/lustre_handles.h>
static spinlock_t handle_lock = SPIN_LOCK_UNLOCKED;
-static spinlock_t random_lock = SPIN_LOCK_UNLOCKED;
+static __u64 handle_base;
+#define HANDLE_INCR 7
static struct list_head *handle_hash = NULL;
static int handle_count = 0;
LASSERT(h != NULL);
LASSERT(list_empty(&h->h_link));
- /* My hypothesis is that get_random_bytes, if called from two threads at
- * the same time, will return the same bytes. -phil */
- spin_lock(&random_lock);
- get_random_bytes(&h->h_cookie, sizeof(h->h_cookie));
- spin_unlock(&random_lock);
+ spin_lock(&handle_lock);
+ h->h_cookie = handle_base;
+ handle_base += HANDLE_INCR;
+ spin_unlock(&handle_lock);
h->h_addref = cb;
-
bucket = handle_hash + (h->h_cookie & HANDLE_HASH_MASK);
-
CDEBUG(D_INFO, "adding object %p with handle "LPX64" to hash\n",
h, h->h_cookie);
static void class_handle_unhash_nolock(struct portals_handle *h)
{
- LASSERT(!list_empty(&h->h_link));
+ if (list_empty(&h->h_link)) {
+ CERROR("removing an already-removed handle ("LPX64")\n",
+ h->h_cookie);
+ return;
+ }
CDEBUG(D_INFO, "removing object %p with handle "LPX64" from hash\n",
h, h->h_cookie);
LASSERT(handle_hash != NULL);
- spin_lock(&handle_lock);
bucket = handle_hash + (cookie & HANDLE_HASH_MASK);
+ spin_lock(&handle_lock);
list_for_each(tmp, bucket) {
struct portals_handle *h;
h = list_entry(tmp, struct portals_handle, h_link);
LASSERT(handle_hash == NULL);
- PORTAL_ALLOC(handle_hash, sizeof(*handle_hash) * HANDLE_HASH_SIZE);
+ OBD_VMALLOC(handle_hash, sizeof(*handle_hash) * HANDLE_HASH_SIZE);
if (handle_hash == NULL)
return -ENOMEM;
bucket--)
INIT_LIST_HEAD(bucket);
+ get_random_bytes(&handle_base, sizeof(handle_base));
+ LASSERT(handle_base != 0ULL);
+
return 0;
}
cleanup_all_handles();
}
- PORTAL_FREE(handle_hash, sizeof(*handle_hash) * HANDLE_HASH_SIZE);
+ OBD_VFREE(handle_hash, sizeof(*handle_hash) * HANDLE_HASH_SIZE);
handle_hash = NULL;
if (handle_count)