nfs-ganesha 1.4

cache_inode_access.c

Go to the documentation of this file.
00001 /*
00002  * vim:expandtab:shiftwidth=8:tabstop=8:
00003  *
00004  * Copyright CEA/DAM/DIF  (2008)
00005  * contributeur : Philippe DENIEL   philippe.deniel@cea.fr
00006  *                Thomas LEIBOVICI  thomas.leibovici@cea.fr
00007  *
00008  *
00009  * This program is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 3 of the License, or (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with this library; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00022  *
00023  * ---------------------------------------
00024  */
00025 
00036 #ifdef HAVE_CONFIG_H
00037 #include "config.h"
00038 #endif
00039 
00040 #ifdef _SOLARIS
00041 #include "solaris_port.h"
00042 #endif                          /* _SOLARIS */
00043 
00044 #include "LRU_List.h"
00045 #include "log.h"
00046 #include "HashData.h"
00047 #include "HashTable.h"
00048 #include "fsal.h"
00049 #include "cache_inode.h"
00050 #include "abstract_mem.h"
00051 
00052 #include <unistd.h>
00053 #include <sys/types.h>
00054 #include <sys/param.h>
00055 #include <time.h>
00056 #include <pthread.h>
00057 
00074 cache_inode_status_t
00075 cache_inode_access_sw(cache_entry_t *entry,
00076                       fsal_accessflags_t access_type,
00077                       fsal_op_context_t *context,
00078                       cache_inode_status_t *status,
00079                       int use_mutex)
00080 {
00081      fsal_status_t fsal_status;
00082      fsal_accessflags_t used_access_type;
00083 
00084      LogFullDebug(COMPONENT_CACHE_INODE,
00085                   "cache_inode_access_sw: access_type=0X%x",
00086                   access_type);
00087 
00088      /* Set the return default to CACHE_INODE_SUCCESS */
00089      *status = CACHE_INODE_SUCCESS;
00090 
00091      /*
00092       * We do no explicit access test in FSAL for FSAL_F_OK: it is
00093       * considered that if an entry resides in the cache_inode, then a
00094       * FSAL_getattrs was successfully made to populate the cache entry,
00095       * this means that the entry exists. For this reason, F_OK is
00096       * managed internally
00097       */
00098      if(access_type != FSAL_F_OK) {
00099           /* We get ride of F_OK */
00100           used_access_type = access_type & ~FSAL_F_OK;
00101 
00102           /*
00103            * Function FSAL_test_access is used instead of FSAL_access.
00104            * This allow to take benefit of the previously cached
00105            * attributes. This behavior is configurable via the
00106            * configuration file.
00107            */
00108 
00109           if(cache_inode_params.use_test_access == 1) {
00110                /* We actually need the lock here since we're using
00111                   the attribute cache, so get it if the caller didn't
00112                   acquire it.  */
00113                if(use_mutex) {
00114                     if ((*status
00115                          = cache_inode_lock_trust_attrs(entry,
00116                                                         context))
00117                         != CACHE_INODE_SUCCESS) {
00118                          goto out;
00119                     }
00120                }
00121                fsal_status
00122                     = FSAL_test_access(context,
00123                                        used_access_type,
00124                                        &entry->attributes);
00125                if (use_mutex) {
00126                     pthread_rwlock_unlock(&entry->attr_lock);
00127                }
00128           } else {
00129                /* There is no reason to hold the mutex here, since we
00130                   aren't doing anything with cached attributes. */
00131                     fsal_status = FSAL_access(&entry->handle, context,
00132                                               used_access_type, NULL);
00133           }
00134 
00135           if(FSAL_IS_ERROR(fsal_status)) {
00136                *status = cache_inode_error_convert(fsal_status);
00137                if (fsal_status.major == ERR_FSAL_STALE) {
00138                     cache_inode_kill_entry(entry);
00139                }
00140           } else {
00141                *status = CACHE_INODE_SUCCESS;
00142           }
00143      }
00144 
00145 out:
00146      return *status;
00147 }
00148 
00165 cache_inode_status_t
00166 cache_inode_access_no_mutex(cache_entry_t *entry,
00167                             fsal_accessflags_t access_type,
00168                             fsal_op_context_t *context,
00169                             cache_inode_status_t *status)
00170 {
00171     return cache_inode_access_sw(entry, access_type,
00172                                  context, status, FALSE);
00173 }
00174 
00190 cache_inode_status_t
00191 cache_inode_access(cache_entry_t *entry,
00192                    fsal_accessflags_t access_type,
00193                    fsal_op_context_t *context,
00194                    cache_inode_status_t *status)
00195 {
00196     return cache_inode_access_sw(entry, access_type,
00197                                  context, status, TRUE);
00198 }