nfs-ganesha 1.4

fsal_truncate.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 
00049 fsal_status_t ZFSFSAL_truncate(fsal_handle_t * filehandle, /* IN */
00050                             fsal_op_context_t * p_context,      /* IN */
00051                             fsal_size_t length, /* IN */
00052                             fsal_file_t * file_descriptor,      /* Unused in this FSAL */
00053                             fsal_attrib_list_t * object_attributes      /* [ IN/OUT ] */
00054     )
00055 {
00056   int rc;
00057   creden_t cred;
00058 
00059   /* sanity checks.
00060    * note : object_attributes is optional.
00061    */
00062   if(!filehandle || !p_context)
00063     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_truncate);
00064 
00065   /* >> check object type if it's stored into the filehandle << */
00066   if(((zfsfsal_handle_t *)filehandle)->data.type != FSAL_TYPE_FILE)
00067       Return(ERR_FSAL_INVAL, 0, INDEX_FSAL_truncate);
00068 
00069   /* Hook to prevent any modification in a snapshot */
00070   if(((zfsfsal_handle_t *)filehandle)->data.i_snap != 0)
00071   {
00072     LogDebug(COMPONENT_FSAL, "Trying to truncate a file inside a snapshot");
00073     Return(ERR_FSAL_ROFS, 0, INDEX_FSAL_truncate);
00074   }
00075 
00076   cred.uid = p_context->credential.user;
00077   cred.gid = p_context->credential.group;
00078 
00079   TakeTokenFSCall();
00080 
00081   rc = libzfswrap_truncate(((zfsfsal_op_context_t *)p_context)->export_context->p_vfs,
00082                            &cred,
00083                            ((zfsfsal_handle_t *)filehandle)->data.zfs_handle, length);
00084 
00085   ReleaseTokenFSCall();
00086 
00087   /* >> interpret error code << */
00088   if(rc)
00089     Return(posix2fsal_error(rc), 0, INDEX_FSAL_truncate);
00090 
00091   /* >> Optionaly retrieve post op attributes
00092    * If your filesystem truncate call can't return them,
00093    * you can proceed like this : <<
00094    */
00095   if(object_attributes)
00096     {
00097 
00098       fsal_status_t st;
00099 
00100       st = ZFSFSAL_getattrs(filehandle, p_context, object_attributes);
00101 
00102       if(FSAL_IS_ERROR(st))
00103         {
00104           FSAL_CLEAR_MASK(object_attributes->asked_attributes);
00105           FSAL_SET_MASK(object_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR);
00106         }
00107 
00108     }
00109 
00110   /* No error occured */
00111   Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_truncate);
00112 
00113 }