nfs-ganesha 1.4
|
00001 /* 00002 * vim:expandtab:shiftwidth=8:tabstop=8: 00003 * 00004 * Copyright (C) 2010 The Linux Box, Inc. 00005 * Contributor : Adam C. Emerson <aemerson@linuxbox.com> 00006 * 00007 * 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 00014 * License as published by the Free Software Foundation; either 00015 * version 3 of the License, or (at your option) any later version. 00016 * 00017 * This program is distributed in the hope that it will be useful, 00018 * but 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 02110-1301 USA 00025 * 00026 * ------------- 00027 */ 00028 00034 #ifdef HAVE_CONFIG_H 00035 #include "config.h" 00036 #endif 00037 00038 #include "fsal.h" 00039 #include "fsal_internal.h" 00040 #include "fsal_convert.h" 00041 00077 fsal_status_t CEPHFSAL_lookup(fsal_handle_t * extparent, 00078 fsal_name_t * filename, 00079 fsal_op_context_t * extcontext, 00080 fsal_handle_t * exthandle, 00081 fsal_attrib_list_t * object_attributes) 00082 { 00083 int rc; 00084 struct stat st; 00085 fsal_status_t status; 00086 cephfsal_handle_t* parent = (cephfsal_handle_t*) extparent; 00087 cephfsal_op_context_t* context = (cephfsal_op_context_t*) extcontext; 00088 cephfsal_handle_t* handle = (cephfsal_handle_t*) exthandle; 00089 char str[FSAL_MAX_NAME_LEN]; 00090 struct ceph_mount_info *cmount = context->export_context->cmount; 00091 00092 /* sanity checks 00093 * note : object_attributes is optionnal 00094 * parent_directory_handle may be null for getting FS root. 00095 */ 00096 if(!handle || !context) 00097 Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_lookup); 00098 00099 memset(handle, 0, sizeof(cephfsal_handle_t)); 00100 00101 /* retrieves root handle */ 00102 00103 if(!parent) 00104 { 00105 /* check that filename is NULL, 00106 * else, parent should not 00107 * be NULL. 00108 */ 00109 if(filename != NULL) 00110 Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_lookup); 00111 00112 /* Ceph seems to have a constant identifying the root inode. 00113 Possible source of bugs, so check here if trouble */ 00114 00115 VINODE(handle).ino.val = CEPH_INO_ROOT; 00116 VINODE(handle).snapid.val = CEPH_NOSNAP; 00117 00118 if(object_attributes) 00119 { 00120 status = CEPHFSAL_getattrs(exthandle, extcontext, object_attributes); 00121 00122 if(FSAL_IS_ERROR(status)) 00123 { 00124 FSAL_CLEAR_MASK(object_attributes->asked_attributes); 00125 FSAL_SET_MASK(object_attributes->asked_attributes, 00126 FSAL_ATTR_RDATTR_ERR); 00127 } 00128 } 00129 } 00130 else /* this is a real lookup(parent, name) */ 00131 { 00132 /* the filename should not be null */ 00133 if(filename == NULL) 00134 Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_lookup); 00135 00136 FSAL_name2str(filename, str, FSAL_MAX_NAME_LEN); 00137 00138 /* Ceph returns POSIX errors, so let's use them */ 00139 00140 rc = ceph_ll_lookup(cmount, 00141 VINODE(parent), str, &st, 00142 FSAL_OP_CONTEXT_TO_UID(context), 00143 FSAL_OP_CONTEXT_TO_GID(context)); 00144 00145 if(rc) 00146 { 00147 Return(posix2fsal_error(rc), 0, INDEX_FSAL_lookup); 00148 } 00149 00150 rc = stat2fsal_fh(cmount, &st, handle); 00151 00152 if (rc < 0) 00153 Return(posix2fsal_error(rc), 0, INDEX_FSAL_create); 00154 00155 if(object_attributes) 00156 { 00157 /* convert attributes */ 00158 status = posix2fsal_attributes(&st, object_attributes); 00159 if(FSAL_IS_ERROR(status)) 00160 { 00161 FSAL_CLEAR_MASK(object_attributes->asked_attributes); 00162 FSAL_SET_MASK(object_attributes->asked_attributes, 00163 FSAL_ATTR_RDATTR_ERR); 00164 Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_lookup); 00165 } 00166 } 00167 } 00168 00169 /* lookup complete ! */ 00170 Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_lookup); 00171 00172 } 00173 00201 fsal_status_t CEPHFSAL_lookupJunction(fsal_handle_t * extjunction, 00202 fsal_op_context_t * extcontext, 00203 fsal_handle_t * extfsroot, 00204 fsal_attrib_list_t * fsroot_attributes) 00205 { 00206 Return(ERR_FSAL_SERVERFAULT, 0, INDEX_FSAL_lookup); 00207 } 00208 00243 fsal_status_t CEPHFSAL_lookupPath(fsal_path_t * path, 00244 fsal_op_context_t * extcontext, 00245 fsal_handle_t * exthandle, 00246 fsal_attrib_list_t * object_attributes) 00247 { 00248 int rc; 00249 struct stat st; 00250 fsal_status_t status; 00251 cephfsal_handle_t* handle = (cephfsal_handle_t*) exthandle; 00252 cephfsal_op_context_t* context = (cephfsal_op_context_t*) extcontext; 00253 char str[FSAL_MAX_PATH_LEN]; 00254 struct ceph_mount_info *cmount = context->export_context->cmount; 00255 00256 /* sanity checks 00257 * note : object_attributes is optionnal 00258 * parent_directory_handle may be null for getting FS root. 00259 */ 00260 if(!path || !context || !handle) 00261 Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_lookupPath); 00262 00263 memset(handle, 0, sizeof(cephfsal_handle_t)); 00264 00265 FSAL_path2str(path, str, FSAL_MAX_PATH_LEN); 00266 00267 /* retrieves root handle */ 00268 00269 if((strcmp(str, "/") == 0)) 00270 { 00271 VINODE(handle).ino.val = CEPH_INO_ROOT; 00272 VINODE(handle).snapid.val = CEPH_NOSNAP; 00273 00274 if(object_attributes) 00275 { 00276 status = CEPHFSAL_getattrs(exthandle, extcontext, 00277 object_attributes); 00278 00279 /* On error, we set a flag in the returned attributes */ 00280 00281 if(FSAL_IS_ERROR(status)) 00282 { 00283 FSAL_CLEAR_MASK(object_attributes->asked_attributes); 00284 FSAL_SET_MASK(object_attributes->asked_attributes, 00285 FSAL_ATTR_RDATTR_ERR); 00286 } 00287 } 00288 } 00289 else /* this is a real lookup(parent, name) */ 00290 { 00291 rc = ceph_ll_walk(cmount, str, &st); 00292 00293 if(rc) 00294 { 00295 Return(posix2fsal_error(rc), 0, INDEX_FSAL_lookupPath); 00296 } 00297 00298 stat2fsal_fh(cmount, &st, handle); 00299 if (rc < 0) 00300 Return(posix2fsal_error(rc), 0, INDEX_FSAL_create); 00301 00302 if(object_attributes) 00303 { 00304 status = posix2fsal_attributes(&st, object_attributes); 00305 if(FSAL_IS_ERROR(status)) 00306 { 00307 FSAL_CLEAR_MASK(object_attributes->asked_attributes); 00308 FSAL_SET_MASK(object_attributes->asked_attributes, 00309 FSAL_ATTR_RDATTR_ERR); 00310 Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_getattrs); 00311 } 00312 } 00313 } 00314 00315 /* lookup complete ! */ 00316 Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_lookup); 00317 }