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 HPSSFSAL_unlink(hpssfsal_handle_t * parentdir_handle,     /* IN */
00052                               fsal_name_t * p_object_name,      /* IN */
00053                               hpssfsal_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;
00060   hpssfsal_handle_t obj_handle;
00061 
00062   /* sanity checks.
00063    * note : parentdir_attributes are optional.
00064    *        parentdir_handle is mandatory,
00065    *        because, we do not allow to delete FS root !
00066    */
00067   if(!parentdir_handle || !p_context || !p_object_name)
00068     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_unlink);
00069 
00070   /* Action depends on the object type to be deleted.
00071    * To know that, we get fsal object handle.
00072    */
00073   st = HPSSFSAL_lookup(parentdir_handle,        /* IN */
00074                        p_object_name,   /* IN */
00075                        p_context,       /* IN */
00076                        &obj_handle,     /* OUT */
00077                        NULL);   /* IN/OUT */
00078 
00079   if(FSAL_IS_ERROR(st))
00080     Return(st.major, st.minor, INDEX_FSAL_unlink);
00081 
00082   switch (obj_handle.data.obj_type)
00083     {
00084 
00085     case FSAL_TYPE_DIR:
00086 
00087       /* remove a directory */
00088 
00089       TakeTokenFSCall();
00090 
00091       rc = hpss_RmdirHandle(&(parentdir_handle->data.ns_handle),
00092                             p_object_name->name, &(p_context->credential.hpss_usercred));
00093 
00094       ReleaseTokenFSCall();
00095 
00096       /* The EEXIST error is actually an NOTEMPTY error. */
00097 
00098       if(rc == EEXIST || rc == -EEXIST)
00099         Return(ERR_FSAL_NOTEMPTY, -rc, INDEX_FSAL_unlink);
00100       else if(rc)
00101         Return(hpss2fsal_error(rc), -rc, INDEX_FSAL_unlink);
00102 
00103       break;
00104 
00105     case FSAL_TYPE_LNK:
00106     case FSAL_TYPE_FILE:
00107 
00108       /* remove an object */
00109 
00110       TakeTokenFSCall();
00111 
00112       rc = hpss_UnlinkHandle(&(parentdir_handle->data.ns_handle),
00113                              p_object_name->name, &(p_context->credential.hpss_usercred));
00114 
00115       ReleaseTokenFSCall();
00116 
00117       if(rc)
00118         Return(hpss2fsal_error(rc), -rc, INDEX_FSAL_unlink);
00119 
00120       break;
00121 
00122     case FSAL_TYPE_JUNCTION:
00123       /* remove a junction */
00124 
00125       TakeTokenFSCall();
00126 
00127       rc = hpss_JunctionDeleteHandle(&(parentdir_handle->data.ns_handle),
00128                                      p_object_name->name,
00129                                      &(p_context->credential.hpss_usercred));
00130 
00131       ReleaseTokenFSCall();
00132 
00133       if(rc)
00134         Return(hpss2fsal_error(rc), -rc, INDEX_FSAL_unlink);
00135 
00136       break;
00137 
00138     case FSAL_TYPE_FIFO:
00139     case FSAL_TYPE_CHR:
00140     case FSAL_TYPE_BLK:
00141     case FSAL_TYPE_SOCK:
00142     default:
00143       LogCrit(COMPONENT_FSAL, "Unexpected object type : %d\n",
00144                         obj_handle.data.obj_type);
00145       Return(ERR_FSAL_SERVERFAULT, 0, INDEX_FSAL_unlink);
00146 
00147     }
00148 
00149   /* Now, we get new attributes for the parent directory,
00150    * if they are asked.
00151    */
00152 
00153   if(parentdir_attributes)
00154     {
00155 
00156       st = HPSSFSAL_getattrs(parentdir_handle, p_context, parentdir_attributes);
00157 
00158       /* On error, we set a flag in the returned attributes */
00159 
00160       if(FSAL_IS_ERROR(st))
00161         {
00162           FSAL_CLEAR_MASK(parentdir_attributes->asked_attributes);
00163           FSAL_SET_MASK(parentdir_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR);
00164         }
00165     }
00166 
00167   /* OK */
00168   Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_unlink);
00169 
00170 }