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 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 00072 fsal_status_t CEPHFSAL_unlink(fsal_handle_t * extparent, 00073 fsal_name_t * name, 00074 fsal_op_context_t * extcontext, 00075 fsal_attrib_list_t * parentdir_attributes) 00076 { 00077 int rc; 00078 struct stat st; 00079 fsal_status_t status; 00080 char strname[FSAL_MAX_NAME_LEN]; 00081 cephfsal_handle_t* parent = (cephfsal_handle_t*) extparent; 00082 cephfsal_op_context_t* context = (cephfsal_op_context_t*) extcontext; 00083 struct ceph_mount_info *cmount = context->export_context->cmount; 00084 int uid = FSAL_OP_CONTEXT_TO_UID(context); 00085 int gid = FSAL_OP_CONTEXT_TO_GID(context); 00086 00087 /* sanity checks. 00088 * note : parentdir_attributes are optional. 00089 * parentdir_handle is mandatory, 00090 * because, we do not allow to delete FS root ! 00091 */ 00092 00093 if(!parent || !context || !name) 00094 Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_unlink); 00095 00096 if(parentdir_attributes) 00097 { 00098 status = CEPHFSAL_getattrs(extparent, extcontext, 00099 parentdir_attributes); 00100 00101 if(FSAL_IS_ERROR(status)) 00102 { 00103 FSAL_CLEAR_MASK(parentdir_attributes->asked_attributes); 00104 FSAL_SET_MASK(parentdir_attributes->asked_attributes, 00105 FSAL_ATTR_RDATTR_ERR); 00106 } 00107 } 00108 00109 FSAL_name2str(name, strname, FSAL_MAX_NAME_LEN); 00110 00111 TakeTokenFSCall(); 00112 rc = ceph_ll_lookup(cmount, VINODE(parent), strname, &st, uid, gid); 00113 ReleaseTokenFSCall(); 00114 00115 if (rc < 0) 00116 Return(posix2fsal_error(rc), 0, INDEX_FSAL_unlink); 00117 00118 if(S_ISDIR(st.st_mode)) 00119 rc = ceph_ll_rmdir(cmount, VINODE(parent), strname, uid, gid); 00120 else 00121 rc = ceph_ll_unlink(cmount, VINODE(parent), strname, uid, gid); 00122 00123 if (rc < 0) 00124 Return(posix2fsal_error(rc), 0, INDEX_FSAL_unlink); 00125 00126 /* OK */ 00127 Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_unlink); 00128 00129 }