nfs-ganesha 1.4
|
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 00022 * 02110-1301 USA 00023 * 00024 * --------------------------------------- 00025 */ 00026 00037 #ifdef HAVE_CONFIG_H 00038 #include "config.h" 00039 #endif 00040 00041 #ifdef _SOLARIS 00042 #include "solaris_port.h" 00043 #endif /* _SOLARIS */ 00044 00045 #include "abstract_atomic.h" 00046 #include "log.h" 00047 #include "HashData.h" 00048 #include "HashTable.h" 00049 #include "fsal.h" 00050 #include "cache_inode.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 #include <assert.h> 00058 00074 cache_inode_status_t 00075 cache_inode_readlink(cache_entry_t *entry, 00076 fsal_path_t *link_content, 00077 fsal_op_context_t *context, 00078 cache_inode_status_t *status) 00079 { 00080 fsal_status_t fsal_status = {0, 0}; 00081 00082 /* Set the return default to CACHE_INODE_SUCCESS */ 00083 *status = CACHE_INODE_SUCCESS; 00084 00085 if (entry->type != SYMBOLIC_LINK) { 00086 *status = CACHE_INODE_BAD_TYPE; 00087 return *status; 00088 } 00089 00090 assert(entry->object.symlink); 00091 pthread_rwlock_rdlock(&entry->content_lock); 00092 if (!(entry->flags & CACHE_INODE_TRUST_CONTENT)) { 00093 /* Our data are stale. Drop the lock, get a 00094 write-lock, load in new data, and copy it out to 00095 the caller. */ 00096 pthread_rwlock_unlock(&entry->content_lock); 00097 pthread_rwlock_wrlock(&entry->content_lock); 00098 /* Make sure nobody updated the content while we were 00099 waiting. */ 00100 if (!(entry->flags & CACHE_INODE_TRUST_CONTENT)) { 00101 fsal_status 00102 = FSAL_readlink(&entry->handle, 00103 context, 00104 &entry->object.symlink->content, 00105 NULL); 00106 if (!(FSAL_IS_ERROR(fsal_status))) { 00107 atomic_set_uint32_t_bits(&entry->flags, 00108 CACHE_INODE_TRUST_CONTENT); 00109 } 00110 } 00111 } 00112 if (!(FSAL_IS_ERROR(fsal_status))) { 00113 FSAL_pathcpy(link_content, 00114 &(entry->object.symlink->content)); 00115 } 00116 pthread_rwlock_unlock(&entry->content_lock); 00117 00118 if (FSAL_IS_ERROR(fsal_status)) { 00119 *status = cache_inode_error_convert(fsal_status); 00120 if (fsal_status.major == ERR_FSAL_STALE) { 00121 cache_inode_kill_entry(entry); 00122 } 00123 return *status; 00124 } 00125 00126 return *status; 00127 } /* cache_inode_readlink */