nfs-ganesha 1.4

fsal_unlink.c

Go to the documentation of this file.
00001 /*
00002  * vim:expandtab:shiftwidth=8:tabstop=8:
00003  */
00004 
00014 #ifdef HAVE_CONFIG_H
00015 #include "config.h"
00016 #endif
00017 
00018 #include "fsal.h"
00019 #include "fsal_internal.h"
00020 #include "fsal_convert.h"
00021 
00051 fsal_status_t ZFSFSAL_unlink(fsal_handle_t * parentdir_handle,     /* IN */
00052                           fsal_name_t * p_object_name,  /* IN */
00053                           fsal_op_context_t * p_context,        /* IN */
00054                           fsal_attrib_list_t * parentdir_attributes     /* [IN/OUT ] */
00055     )
00056 {
00057 
00058   fsal_status_t st;
00059   int rc, type;
00060   inogen_t object;
00061   creden_t cred;
00062 
00063   /* sanity checks.
00064    * note : parentdir_attributes are optional.
00065    *        parentdir_handle is mandatory,
00066    *        because, we do not allow to delete FS root !
00067    */
00068   if(!parentdir_handle || !p_context || !p_object_name)
00069     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_unlink);
00070 
00071   /* Hook to prevent removing anything from snapshots */
00072   if(((zfsfsal_handle_t *)parentdir_handle)->data.i_snap != 0)
00073   {
00074     LogDebug(COMPONENT_FSAL, "Trying to remove an object from a snapshot");
00075     Return(ERR_FSAL_ROFS, 0, INDEX_FSAL_unlink);
00076   }
00077 
00078   cred.uid = p_context->credential.user;
00079   cred.gid = p_context->credential.group;
00080 
00081   TakeTokenFSCall();
00082 
00083   if(!(rc = libzfswrap_lookup(((zfsfsal_op_context_t *)p_context)->export_context->p_vfs, &cred,
00084                               ((zfsfsal_handle_t *)parentdir_handle)->data.zfs_handle,
00085                               p_object_name->name, &object, &type)))
00086   {
00087     if(type == S_IFDIR)
00088       rc = libzfswrap_rmdir(((zfsfsal_op_context_t *)p_context)->export_context->p_vfs, &cred,
00089                             ((zfsfsal_handle_t *)parentdir_handle)->data.zfs_handle, p_object_name->name);
00090     else
00091       rc = libzfswrap_unlink(((zfsfsal_op_context_t *)p_context)->export_context->p_vfs, &cred,
00092                              ((zfsfsal_handle_t *)parentdir_handle)->data.zfs_handle, p_object_name->name);
00093   }
00094 
00095   ReleaseTokenFSCall();
00096 
00097   if(rc)
00098     Return(posix2fsal_error(rc), 0, INDEX_FSAL_unlink);
00099 
00100   /* >> get post op attributes for the parent, if they are asked,
00101    * and your filesystem didn't return them << */
00102 
00103   if(parentdir_attributes)
00104     {
00105 
00106       st = ZFSFSAL_getattrs(parentdir_handle, p_context, parentdir_attributes);
00107 
00108       /* On error, we set a flag in the returned attributes */
00109 
00110       if(FSAL_IS_ERROR(st))
00111         {
00112           FSAL_CLEAR_MASK(parentdir_attributes->asked_attributes);
00113           FSAL_SET_MASK(parentdir_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR);
00114         }
00115     }
00116 
00117   /* OK */
00118   Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_unlink);
00119 
00120 }