X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fobdclass%2Flustre_handles.c;h=6cf943b6db85f985264122c019f8d2392801c963;hb=44cc42f556c668de09479f706beea4b6e600eb4b;hp=ec8e51ddb0a1a205870b995c37f21d6112345757;hpb=0f8dca08a4f68cba82c2c822998ecc309d3b7aaf;p=fs%2Flustre-release.git diff --git a/lustre/obdclass/lustre_handles.c b/lustre/obdclass/lustre_handles.c index ec8e51d..6cf943b 100644 --- a/lustre/obdclass/lustre_handles.c +++ b/lustre/obdclass/lustre_handles.c @@ -1,6 +1,4 @@ -/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: - * +/* * GPL HEADER START * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -28,6 +26,8 @@ /* * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. + * + * Copyright (c) 2011, Whamcloud, Inc. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -47,7 +47,7 @@ #include #include -#if !defined(HAVE_RCU) || !defined(__KERNEL__) +#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 @@ -55,19 +55,17 @@ # 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 /* ifndef HAVE_RCU */ +#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; + cfs_spinlock_t lock; + cfs_list_t head; } *handle_hash; -static cfs_atomic_t handle_count = CFS_ATOMIC_INIT(0); - #ifdef __arch_um__ /* For unknown reason, UML uses kmalloc rather than vmalloc to allocate * memory(OBD_VMALLOC). Therefore, we have to redefine the @@ -75,7 +73,7 @@ static cfs_atomic_t handle_count = CFS_ATOMIC_INIT(0); */ #define HANDLE_HASH_SIZE 4096 #else -#define HANDLE_HASH_SIZE (1 << 14) +#define HANDLE_HASH_SIZE (1 << 16) #endif /* ifdef __arch_um__ */ #define HANDLE_HASH_MASK (HANDLE_HASH_SIZE - 1) @@ -84,7 +82,8 @@ static cfs_atomic_t handle_count = CFS_ATOMIC_INIT(0); * Generate a unique 64bit cookie (hash) for a handle and insert it into * global (per-node) hash-table. */ -void class_handle_hash(struct portals_handle *h, portals_handle_addref_cb cb) +void class_handle_hash(struct portals_handle *h, + struct portals_handle_ops *ops) { struct handle_bucket *bucket; ENTRY; @@ -110,9 +109,8 @@ void class_handle_hash(struct portals_handle *h, portals_handle_addref_cb cb) handle_base += HANDLE_INCR; } cfs_spin_unlock(&handle_base_lock); - - cfs_atomic_inc(&handle_count); - h->h_addref = cb; + + h->h_ops = ops; cfs_spin_lock_init(&h->h_lock); bucket = &handle_hash[h->h_cookie & HANDLE_HASH_MASK]; @@ -125,6 +123,7 @@ void class_handle_hash(struct portals_handle *h, portals_handle_addref_cb cb) h, h->h_cookie); EXIT; } +EXPORT_SYMBOL(class_handle_hash); static void class_handle_unhash_nolock(struct portals_handle *h) { @@ -155,9 +154,8 @@ void class_handle_unhash(struct portals_handle *h) cfs_spin_lock(&bucket->lock); class_handle_unhash_nolock(h); cfs_spin_unlock(&bucket->lock); - - cfs_atomic_dec(&handle_count); } +EXPORT_SYMBOL(class_handle_unhash); void class_handle_hash_back(struct portals_handle *h) { @@ -166,7 +164,6 @@ void class_handle_hash_back(struct portals_handle *h) bucket = handle_hash + (h->h_cookie & HANDLE_HASH_MASK); - cfs_atomic_inc(&handle_count); cfs_spin_lock(&bucket->lock); list_add_rcu(&h->h_link, &bucket->head); h->h_in = 1; @@ -174,6 +171,7 @@ void class_handle_hash_back(struct portals_handle *h) EXIT; } +EXPORT_SYMBOL(class_handle_hash_back); void *class_handle2object(__u64 cookie) { @@ -184,8 +182,8 @@ void *class_handle2object(__u64 cookie) LASSERT(handle_hash != NULL); - /* Be careful when you want to change this code. See the - * rcu_read_lock() definition on top this file. - jxiong */ + /* Be careful when you want to change this code. See the + * rcu_read_lock() definition on top this file. - jxiong */ bucket = handle_hash + (cookie & HANDLE_HASH_MASK); rcu_read_lock(); @@ -195,7 +193,7 @@ void *class_handle2object(__u64 cookie) cfs_spin_lock(&h->h_lock); if (likely(h->h_in != 0)) { - h->h_addref(h); + h->h_ops->hop_addref(h); retval = h; } cfs_spin_unlock(&h->h_lock); @@ -205,18 +203,19 @@ void *class_handle2object(__u64 cookie) RETURN(retval); } +EXPORT_SYMBOL(class_handle2object); void class_handle_free_cb(cfs_rcu_head_t *rcu) { - struct portals_handle *h = RCU2HANDLE(rcu); - if (h->h_free_cb) { - h->h_free_cb(h->h_ptr, h->h_size); - } else { - void *ptr = h->h_ptr; - unsigned int size = h->h_size; - OBD_FREE(ptr, size); - } + struct portals_handle *h = RCU2HANDLE(rcu); + void *ptr = (void *)(unsigned long)h->h_cookie; + + if (h->h_ops->hop_free != NULL) + h->h_ops->hop_free(ptr, h->h_size); + else + OBD_FREE(ptr, h->h_size); } +EXPORT_SYMBOL(class_handle_free_cb); int class_handle_init(void) { @@ -226,7 +225,7 @@ int class_handle_init(void) LASSERT(handle_hash == NULL); - OBD_VMALLOC(handle_hash, sizeof(*bucket) * HANDLE_HASH_SIZE); + OBD_ALLOC_LARGE(handle_hash, sizeof(*bucket) * HANDLE_HASH_SIZE); if (handle_hash == NULL) return -ENOMEM; @@ -238,32 +237,36 @@ int class_handle_init(void) } /** bug 21430: add randomness to the initial base */ - ll_get_random_bytes(seed, sizeof(seed)); + cfs_get_random_bytes(seed, sizeof(seed)); cfs_gettimeofday(&tv); - ll_srand(tv.tv_sec ^ seed[0], tv.tv_usec ^ seed[1]); + cfs_srand(tv.tv_sec ^ seed[0], tv.tv_usec ^ seed[1]); - ll_get_random_bytes(&handle_base, sizeof(handle_base)); + cfs_get_random_bytes(&handle_base, sizeof(handle_base)); LASSERT(handle_base != 0ULL); return 0; } -static void cleanup_all_handles(void) +static int cleanup_all_handles(void) { + int rc; int i; - for (i = 0; i < HANDLE_HASH_SIZE; i++) { + for (rc = i = 0; i < HANDLE_HASH_SIZE; i++) { struct portals_handle *h; cfs_spin_lock(&handle_hash[i].lock); list_for_each_entry_rcu(h, &(handle_hash[i].head), h_link) { - CERROR("force clean handle "LPX64" addr %p addref %p\n", - h->h_cookie, h, h->h_addref); + CERROR("force clean handle "LPX64" addr %p ops %p\n", + h->h_cookie, h, h->h_ops); class_handle_unhash_nolock(h); + rc++; } cfs_spin_unlock(&handle_hash[i].lock); } + + return rc; } void class_handle_cleanup(void) @@ -271,15 +274,11 @@ void class_handle_cleanup(void) int count; LASSERT(handle_hash != NULL); - count = cfs_atomic_read(&handle_count); - if (count != 0) { - CERROR("handle_count at cleanup: %d\n", count); - cleanup_all_handles(); - } + count = cleanup_all_handles(); - OBD_VFREE(handle_hash, sizeof(*handle_hash) * HANDLE_HASH_SIZE); + OBD_FREE_LARGE(handle_hash, sizeof(*handle_hash) * HANDLE_HASH_SIZE); handle_hash = NULL; - if (cfs_atomic_read(&handle_count)) - CERROR("leaked %d handles\n", cfs_atomic_read(&handle_count)); + if (count != 0) + CERROR("handle_count at cleanup: %d\n", count); }