nfs-ganesha 1.4
|
00001 /* 00002 * 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 /* fsal_types contains constants and type definitions for FSAL */ 00041 #include "fsal_types.h" 00042 #include "fsal.h" 00043 #include "mfsl_types.h" 00044 #include "mfsl.h" 00045 #include "common_utils.h" 00046 00047 extern mfsl_parameter_t mfsl_param; 00048 00059 fsal_status_t MFSL_unlink_async_op(mfsl_async_op_desc_t * popasyncdesc) 00060 { 00061 fsal_status_t fsal_status; 00062 00063 LogDebug(COMPONENT_MFSL, "Making asynchronous FSAL_unlink for async op %p", 00064 popasyncdesc); 00065 00066 P(popasyncdesc->op_args.remove.pmobject->lock); 00067 fsal_status = FSAL_unlink(&(popasyncdesc->op_args.remove.pmobject->handle), 00068 &popasyncdesc->op_args.remove.name, 00069 &popasyncdesc->fsal_op_context, 00070 &popasyncdesc->op_res.remove.attr); 00071 V(popasyncdesc->op_args.remove.pmobject->lock); 00072 00073 return fsal_status; 00074 } /* MFSL_unlink_async_op */ 00075 00091 fsal_status_t MFSAL_unlink_check_perms(mfsl_object_t * dir_handle, /* IN */ 00092 mfsl_object_specific_data_t * dir_pspecdata, /* IN */ 00093 fsal_name_t * p_object_name, /* IN */ 00094 fsal_attrib_list_t * dir_attributes, /* [ IN/OUT ] */ 00095 fsal_op_context_t * p_context, /* IN */ 00096 mfsl_context_t * p_mfsl_context /* IN */ ) 00097 { 00098 fsal_status_t fsal_status; 00099 00100 fsal_status = FSAL_unlink_access(p_context, dir_attributes); 00101 00102 if(FSAL_IS_ERROR(fsal_status)) 00103 return fsal_status; 00104 00106 MFSL_return(ERR_FSAL_NO_ERROR, 0); 00107 } /* MFSL_unlink_check_perms */ 00108 00124 fsal_status_t MFSL_unlink(mfsl_object_t * dir_handle, /* IN */ 00125 fsal_name_t * p_object_name, /* IN */ 00126 mfsl_object_t * object_handle, /* INOUT */ 00127 fsal_op_context_t * p_context, /* IN */ 00128 mfsl_context_t * p_mfsl_context, /* IN */ 00129 fsal_attrib_list_t * dir_attributes /* [ IN/OUT ] */ ) 00130 { 00131 fsal_status_t fsal_status; 00132 mfsl_async_op_desc_t *pasyncopdesc = NULL; 00133 mfsl_object_specific_data_t *dir_pasyncdata = NULL; 00134 mfsl_object_specific_data_t *obj_pasyncdata = NULL; 00135 00136 pasyncopdesc = pool_alloc(p_mfsl_context->pool_async_op, NULL); 00137 00138 if(pasyncopdesc == NULL) 00139 MFSL_return(ERR_FSAL_INVAL, 0); 00140 00141 if(gettimeofday(&pasyncopdesc->op_time, NULL) != 0) 00142 { 00143 /* Could'not get time of day... Stopping, this may need a major failure */ 00144 LogMajor(COMPONENT_MFSL, "MFSL_link: cannot get time of day... exiting"); 00145 exit(1); 00146 } 00147 00148 if(!mfsl_async_get_specdata(dir_handle, &dir_pasyncdata)) 00149 { 00150 /* Target is not yet asynchronous */ 00151 00152 dir_pasyncdata = pool_alloc(p_mfsl_context->pool_spec_data, NULL); 00153 00154 /* In this case use object_attributes parameter to initiate 00155 asynchronous object */ 00156 dir_pasyncdata->async_attr = *dir_attributes; 00157 } 00158 00159 fsal_status = MFSAL_unlink_check_perms(dir_handle, 00160 dir_pasyncdata, 00161 p_object_name, 00162 dir_attributes, p_context, p_mfsl_context); 00163 00164 if(FSAL_IS_ERROR(fsal_status)) 00165 return fsal_status; 00166 00167 LogDebug(COMPONENT_MFSL, "Creating asyncop %p", 00168 pasyncopdesc); 00169 00170 pasyncopdesc->op_type = MFSL_ASYNC_OP_REMOVE; 00171 00172 pasyncopdesc->op_args.remove.pmobject = dir_handle; 00173 pasyncopdesc->op_args.remove.name = *p_object_name; 00174 pasyncopdesc->op_res.remove.attr = *dir_attributes; 00175 00176 pasyncopdesc->op_func = MFSL_unlink_async_op; 00177 pasyncopdesc->fsal_op_context = *p_context; 00178 00179 pasyncopdesc->ptr_mfsl_context = (caddr_t) p_mfsl_context; 00180 00181 fsal_status = MFSL_async_post(pasyncopdesc); 00182 if(FSAL_IS_ERROR(fsal_status)) 00183 return fsal_status; 00184 00185 /* Update the asynchronous metadata */ 00186 dir_pasyncdata->async_attr.ctime.seconds = pasyncopdesc->op_time.tv_sec; 00187 dir_pasyncdata->async_attr.ctime.nseconds = pasyncopdesc->op_time.tv_usec; 00188 dir_handle->health = MFSL_ASYNC_ASYNCHRONOUS; 00189 00190 if(!mfsl_async_set_specdata(dir_handle, dir_pasyncdata)) 00191 MFSL_return(ERR_FSAL_SERVERFAULT, 0); 00192 00193 if(!mfsl_async_get_specdata(object_handle, &obj_pasyncdata)) 00194 { 00195 /* The object to be deleted is not asynchronous, but it has has 00196 * to become asynchronous to be correctly managed until the FSAL 00197 * deletes it */ 00198 obj_pasyncdata = pool_alloc(p_mfsl_context->pool_spec_data, NULL); 00199 00200 /* Possible bug here with getattr because it has not data */ 00201 } 00202 00203 /* Depending on the value of numlinks, the object should be deleted or not */ 00204 if((obj_pasyncdata->async_attr.numlinks > 1) 00205 && (obj_pasyncdata->async_attr.type == FSAL_TYPE_FILE)) 00206 obj_pasyncdata->async_attr.numlinks -= 1; 00207 else 00208 obj_pasyncdata->deleted = TRUE; 00209 00210 if(!mfsl_async_set_specdata(object_handle, obj_pasyncdata)) 00211 MFSL_return(ERR_FSAL_SERVERFAULT, 0); 00212 00213 /* Return the correct attributes */ 00214 *dir_attributes = dir_pasyncdata->async_attr; 00215 00216 MFSL_return(ERR_FSAL_NO_ERROR, 0); 00217 } /* MFSL_unlink */