nfs-ganesha 1.4

cache_inode_weakref.c

Go to the documentation of this file.
00001 /*
00002  * vim:expandtab:shiftwidth=8:tabstop=8:
00003  *
00004  * Copyright (C) 2010, The Linux Box Corporation
00005  * Contributor : Matt Benjamin <matt@linuxbox.com>
00006  *
00007  * Some portions Copyright CEA/DAM/DIF  (2008)
00008  * contributeur : Philippe DENIEL   philippe.deniel@cea.fr
00009  *                Thomas LEIBOVICI  thomas.leibovici@cea.fr
00010  *
00011  *
00012  * This program is free software; you can redistribute it and/or
00013  * modify it under the terms of the GNU Lesser General Public License
00014  * as published by the Free Software Foundation; either version 3 of
00015  * the License, or (at your option) any later version.
00016  *
00017  * This program is distributed in the hope that it will be useful, but
00018  * WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020  * Lesser General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU Lesser General Public
00023  * License along with this library; if not, write to the Free Software
00024  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00025  * 02110-1301 USA
00026  *
00027  * -------------
00028  */
00029 
00030 #ifdef HAVE_CONFIG_H
00031 #include "config.h"
00032 #endif
00033 
00034 #ifdef _SOLARIS
00035 #include "solaris_port.h"
00036 #endif                          /* _SOLARIS */
00037 
00038 #include <unistd.h>
00039 #include <sys/types.h>
00040 #include <sys/param.h>
00041 #include <time.h>
00042 #include <pthread.h>
00043 #include <assert.h>
00044 #include "nlm_list.h"
00045 #include "fsal.h"
00046 #include "nfs_core.h"
00047 #include "log.h"
00048 #include "cache_inode.h"
00049 #include "cache_inode_lru.h"
00050 #include "cache_inode_weakref.h"
00051 #include "generic_weakref.h"
00052 
00066 #define WEAKREF_PARTITIONS 17
00067 
00068 static gweakref_table_t *cache_inode_wt = NULL;
00069 
00075 void cache_inode_weakref_init()
00076 {
00077     cache_inode_wt = gweakref_init(17, 32767 /* unlike in ht, desire prime */);
00078 }
00079 
00092 gweakref_t cache_inode_weakref_insert(cache_entry_t *entry)
00093 {
00094     return (gweakref_insert(cache_inode_wt, entry));
00095 }
00096 
00117 cache_entry_t *cache_inode_weakref_get(gweakref_t *ref,
00118                                        uint32_t flags)
00119 {
00120     pthread_rwlock_t *lock = NULL;
00121     cache_entry_t *entry =
00122         (cache_entry_t *) gweakref_lookupex(cache_inode_wt, ref, &lock);
00123 
00124     if (entry) {
00125         if (cache_inode_lru_ref(entry, flags)
00126             != CACHE_INODE_SUCCESS) {
00127             pthread_rwlock_unlock(lock);
00128             return NULL;
00129         }
00130         pthread_rwlock_unlock(lock);
00131     }
00132 
00133     return (entry);
00134 }
00135 
00146 void cache_inode_weakref_delete(gweakref_t *ref)
00147 {
00148     gweakref_delete(cache_inode_wt, ref);
00149 }
00150 
00157 void cache_inode_weakref_shutdown()
00158 {
00159     gweakref_destroy(cache_inode_wt);
00160 }