nfs-ganesha 1.4

fsal_rename.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 #include "fsal_common.h"
00022 
00023 #include <hpss_errno.h>
00024 
00066 fsal_status_t HPSSFSAL_rename(hpssfsal_handle_t * old_parentdir_handle, /* IN */
00067                               fsal_name_t * p_old_name, /* IN */
00068                               hpssfsal_handle_t * new_parentdir_handle, /* IN */
00069                               fsal_name_t * p_new_name, /* IN */
00070                               hpssfsal_op_context_t * p_context,        /* IN */
00071                               fsal_attrib_list_t * src_dir_attributes,  /* [ IN/OUT ] */
00072                               fsal_attrib_list_t * tgt_dir_attributes   /* [ IN/OUT ] */
00073     )
00074 {
00075 
00076   int rc;
00077 
00078   /* sanity checks.
00079    * note : src/tgt_dir_attributes are optional.
00080    */
00081   if(!old_parentdir_handle ||
00082      !new_parentdir_handle || !p_old_name || !p_new_name || !p_context)
00083     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_rename);
00084 
00085   TakeTokenFSCall();
00086 
00087   rc = hpss_RenameHandle(&(old_parentdir_handle->data.ns_handle),
00088                          p_old_name->name,
00089                          &(new_parentdir_handle->data.ns_handle),
00090                          p_new_name->name, &(p_context->credential.hpss_usercred));
00091 
00092   ReleaseTokenFSCall();
00093 
00094   /* convert the HPSS EEXIST error to the expected error ENOTEMPTY */
00095   if(rc == HPSS_EEXIST)
00096     Return(ERR_FSAL_NOTEMPTY, -rc, INDEX_FSAL_rename);
00097 
00098   /* the source or the target directory handles may be stale */
00099   if(rc == HPSS_ENOTDIR || rc == HPSS_ENOENT)
00100     {
00101       if(HPSSFSAL_IsStaleHandle(&old_parentdir_handle->data.ns_handle,
00102                                 &p_context->credential.hpss_usercred) ||
00103          HPSSFSAL_IsStaleHandle(&new_parentdir_handle->data.ns_handle,
00104                                 &p_context->credential.hpss_usercred))
00105         {
00106           Return(ERR_FSAL_STALE, -rc, INDEX_FSAL_rename);
00107         }
00108     }
00109 
00110   /* any other error */
00111   if(rc)
00112     Return(hpss2fsal_error(rc), -rc, INDEX_FSAL_rename);
00113 
00114   /* optionnaly get attributes */
00115 
00116   if(src_dir_attributes)
00117     {
00118 
00119       fsal_status_t st;
00120 
00121       st = HPSSFSAL_getattrs(old_parentdir_handle, p_context, src_dir_attributes);
00122 
00123       if(FSAL_IS_ERROR(st))
00124         {
00125           FSAL_CLEAR_MASK(src_dir_attributes->asked_attributes);
00126           FSAL_SET_MASK(src_dir_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR);
00127         }
00128 
00129     }
00130 
00131   if(tgt_dir_attributes)
00132     {
00133 
00134       fsal_status_t st;
00135 
00136       /* optimization: */
00137 
00138       if(!FSAL_handlecmp(old_parentdir_handle, new_parentdir_handle, &st)
00139          && src_dir_attributes)
00140         {
00141 
00142           /* If source dir = target dir, we just copy the attributes.
00143            * to avoid doing another getattr.
00144            */
00145 
00146           (*tgt_dir_attributes) = (*src_dir_attributes);
00147 
00148         }
00149       else
00150         {
00151 
00152           /* get attributes */
00153           st = HPSSFSAL_getattrs(new_parentdir_handle, p_context, tgt_dir_attributes);
00154 
00155           if(FSAL_IS_ERROR(st))
00156             {
00157               FSAL_CLEAR_MASK(tgt_dir_attributes->asked_attributes);
00158               FSAL_SET_MASK(tgt_dir_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR);
00159             }
00160 
00161         }
00162 
00163     }
00164 
00165   /* OK */
00166   Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_rename);
00167 
00168 }