nfs-ganesha 1.4
|
00001 /* 00002 * vim:expandtab:shiftwidth=8:tabstop=8: 00003 * 00004 * Copyright (C) 2010, The Linux Box Corporation 00005 * Contributor : Adam C. Emerson <aemerson@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 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 00035 #ifdef HAVE_CONFIG_H 00036 #include "config.h" 00037 #endif 00038 00039 #include "fsal.h" 00040 #include "fsal_internal.h" 00041 #include "fsal_convert.h" 00042 00079 fsal_status_t CEPHFSAL_create(fsal_handle_t * extparent, 00080 fsal_name_t * filename, 00081 fsal_op_context_t * extcontext, 00082 fsal_accessmode_t accessmode, 00083 fsal_handle_t * object_handle, 00084 fsal_attrib_list_t * object_attributes) 00085 { 00086 int rc; 00087 mode_t mode; 00088 struct Fh *fd; 00089 struct stat st; 00090 char strname[FSAL_MAX_NAME_LEN]; 00091 cephfsal_handle_t* parent = (cephfsal_handle_t*) extparent; 00092 cephfsal_op_context_t* context = (cephfsal_op_context_t*) extcontext; 00093 struct ceph_mount_info *cmount = context->export_context->cmount; 00094 int uid = FSAL_OP_CONTEXT_TO_UID(context); 00095 int gid = FSAL_OP_CONTEXT_TO_GID(context); 00096 00097 /* sanity checks. 00098 * note : object_attributes is optional. 00099 */ 00100 if(!parent || !context || !object_handle || !filename) 00101 Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_create); 00102 00103 memset(object_handle, 0, sizeof(cephfsal_handle_t)); 00104 00105 mode = fsal2unix_mode(accessmode); 00106 mode = mode & ~global_fs_info.umask; 00107 00108 FSAL_name2str(filename, strname, FSAL_MAX_NAME_LEN); 00109 00110 TakeTokenFSCall(); 00111 00112 rc = ceph_ll_create(cmount, VINODE(parent), strname, 00113 mode, 0, &fd, &st, uid, gid); 00114 ceph_ll_close(cmount, fd); 00115 00116 ReleaseTokenFSCall(); 00117 00118 if (rc < 0) 00119 Return(posix2fsal_error(rc), 0, INDEX_FSAL_create); 00120 00121 rc = stat2fsal_fh(cmount, 00122 &st, 00123 (cephfsal_handle_t*) object_handle); 00124 00125 if (rc < 0) 00126 Return(posix2fsal_error(rc), 0, INDEX_FSAL_create); 00127 00128 if(object_attributes) 00129 { 00130 fsal_status_t status; 00131 status = posix2fsal_attributes(&st, object_attributes); 00132 if(FSAL_IS_ERROR(status)) 00133 { 00134 FSAL_CLEAR_MASK(object_attributes->asked_attributes); 00135 FSAL_SET_MASK(object_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR); 00136 Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_create); 00137 } 00138 } 00139 00140 /* OK */ 00141 Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_create); 00142 } 00143 00181 fsal_status_t CEPHFSAL_mkdir(fsal_handle_t * extparent, 00182 fsal_name_t * dirname, 00183 fsal_op_context_t * extcontext, 00184 fsal_accessmode_t accessmode, 00185 fsal_handle_t * object_handle, 00186 fsal_attrib_list_t * object_attributes) 00187 { 00188 int rc; 00189 mode_t mode; 00190 struct stat st; 00191 char strname[FSAL_MAX_NAME_LEN]; 00192 cephfsal_handle_t* parent = (cephfsal_handle_t*) extparent; 00193 cephfsal_op_context_t* context = (cephfsal_op_context_t*) extcontext; 00194 struct ceph_mount_info *cmount = context->export_context->cmount; 00195 int uid = FSAL_OP_CONTEXT_TO_UID(context); 00196 int gid = FSAL_OP_CONTEXT_TO_GID(context); 00197 00198 /* sanity checks. 00199 * note : object_attributes is optional. 00200 */ 00201 if(!parent || !context || !object_handle || !dirname) 00202 Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_mkdir); 00203 00204 memset(object_handle, 0, sizeof(cephfsal_handle_t)); 00205 00206 mode = fsal2unix_mode(accessmode); 00207 mode = mode & ~global_fs_info.umask; 00208 00209 FSAL_name2str(dirname, strname, FSAL_MAX_NAME_LEN); 00210 TakeTokenFSCall(); 00211 00212 rc = ceph_ll_mkdir(cmount, VINODE(parent), dirname->name, 00213 mode, &st, uid, gid); 00214 00215 ReleaseTokenFSCall(); 00216 00217 if (rc < 0) 00218 Return(posix2fsal_error(rc), 0, INDEX_FSAL_mkdir); 00219 00220 rc = stat2fsal_fh(cmount, 00221 &st, 00222 (cephfsal_handle_t*) object_handle); 00223 00224 if (rc < 0) 00225 Return(posix2fsal_error(rc), 0, INDEX_FSAL_create); 00226 00227 if(object_attributes) 00228 { 00229 fsal_status_t status; 00230 status = posix2fsal_attributes(&st, object_attributes); 00231 if(FSAL_IS_ERROR(status)) 00232 { 00233 FSAL_CLEAR_MASK(object_attributes->asked_attributes); 00234 FSAL_SET_MASK(object_attributes->asked_attributes, 00235 FSAL_ATTR_RDATTR_ERR); 00236 Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_mkdir); 00237 } 00238 } 00239 00240 /* OK */ 00241 Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_mkdir); 00242 } 00243 00281 fsal_status_t CEPHFSAL_link(fsal_handle_t * exttarget, 00282 fsal_handle_t * extdir, 00283 fsal_name_t * link_name, 00284 fsal_op_context_t * extcontext, 00285 fsal_attrib_list_t * attributes) 00286 { 00287 int rc; 00288 struct stat st; 00289 char strname[FSAL_MAX_NAME_LEN]; 00290 cephfsal_handle_t* target = (cephfsal_handle_t*) exttarget; 00291 cephfsal_handle_t* dir = (cephfsal_handle_t*) extdir; 00292 cephfsal_op_context_t* context = (cephfsal_op_context_t*) context; 00293 struct ceph_mount_info *cmount = context->export_context->cmount; 00294 int uid = FSAL_OP_CONTEXT_TO_UID(context); 00295 int gid = FSAL_OP_CONTEXT_TO_GID(context); 00296 00297 /* sanity checks. 00298 * note : attributes is optional. 00299 */ 00300 if(!target || !dir || !context || !link_name) 00301 Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_link); 00302 00303 memset(target, 0, sizeof(cephfsal_handle_t)); 00304 00305 /* Tests if hardlinking is allowed by configuration. */ 00306 00307 if(!global_fs_info.link_support) 00308 Return(ERR_FSAL_NOTSUPP, 0, INDEX_FSAL_link); 00309 00310 FSAL_name2str(link_name, strname, FSAL_MAX_NAME_LEN); 00311 00312 TakeTokenFSCall(); 00313 rc = ceph_ll_link(cmount, VINODE(target), VINODE(dir), strname, &st, 00314 uid, gid); 00315 ReleaseTokenFSCall(); 00316 00317 if (rc < 0) 00318 Return(posix2fsal_error(rc), 0, INDEX_FSAL_link); 00319 00320 if(attributes) 00321 { 00322 fsal_status_t status; 00323 status = posix2fsal_attributes(&st, attributes); 00324 if(FSAL_IS_ERROR(status)) 00325 { 00326 FSAL_CLEAR_MASK(attributes->asked_attributes); 00327 FSAL_SET_MASK(attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR); 00328 Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_link); 00329 } 00330 } 00331 00332 /* OK */ 00333 Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_link); 00334 } 00335 00343 fsal_status_t CEPHFSAL_mknode(fsal_handle_t * parent, 00344 fsal_name_t * node_name, 00345 fsal_op_context_t * context, 00346 fsal_accessmode_t accessmode, 00347 fsal_nodetype_t nodetype, 00348 fsal_dev_t * dev, 00349 fsal_handle_t * object_handle, 00350 fsal_attrib_list_t * node_attributes) 00351 { 00352 /* sanity checks. 00353 * note : link_attributes is optional. 00354 */ 00355 if(!parent|| !context || !nodetype || !dev || !node_name) 00356 Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_mknode); 00357 00358 /* Not implemented */ 00359 Return(ERR_FSAL_NOTSUPP, 0, INDEX_FSAL_mknode); 00360 00361 }