nfs-ganesha 1.4

mfsl_async_truncate.c

Go to the documentation of this file.
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_truncate_async_op(mfsl_async_op_desc_t * popasyncdesc)
00060 {
00061   fsal_status_t fsal_status;
00062 
00063   LogDebug(COMPONENT_MFSL, "Making asynchronous FSAL_truncate for async op %p",
00064                   popasyncdesc);
00065 
00066   P(popasyncdesc->op_args.truncate.pmobject->lock);
00067   fsal_status = FSAL_truncate(&(popasyncdesc->op_args.truncate.pmobject->handle), &popasyncdesc->fsal_op_context, popasyncdesc->op_args.truncate.size, NULL,    /* deprecated parameter */
00068                               &popasyncdesc->op_res.truncate.attr);
00069   V(popasyncdesc->op_args.truncate.pmobject->lock);
00070 
00071   return fsal_status;
00072 }                               /* MFSL_truncate_async_op */
00073 
00088 fsal_status_t MFSAL_truncate_check_perms(mfsl_object_t * filehandle,
00089                                          mfsl_object_specific_data_t * pspecdata,
00090                                          fsal_op_context_t * p_context,
00091                                          mfsl_context_t * p_mfsl_context)
00092 {
00093   fsal_status_t fsal_status;
00094 
00095   fsal_status = FSAL_test_access(p_context, FSAL_W_OK, &pspecdata->async_attr);
00096 
00097   if(FSAL_IS_ERROR(fsal_status))
00098     return fsal_status;
00099 
00100   MFSL_return(ERR_FSAL_NO_ERROR, 0);
00101 }                               /* MFSL_truncate_check_perms */
00102 
00119 fsal_status_t MFSL_truncate(mfsl_object_t * filehandle, /* IN */
00120                             fsal_op_context_t * p_context,      /* IN */
00121                             mfsl_context_t * p_mfsl_context,    /* IN */
00122                             fsal_size_t length, fsal_file_t * file_descriptor,  /* INOUT */
00123                             fsal_attrib_list_t * object_attributes      /* [ IN/OUT ] */
00124     )
00125 {
00126   fsal_status_t fsal_status;
00127   mfsl_async_op_desc_t *pasyncopdesc = NULL;
00128   mfsl_object_specific_data_t *pasyncdata = NULL;
00129 
00130   P(p_mfsl_context->lock);
00131 
00132   pasyncopdesc = pool_alloc(p_mfsl_context->pool_async_op, NULL);
00133 
00134   V(p_mfsl_context->lock);
00135 
00136   if(pasyncopdesc == NULL)
00137     MFSL_return(ERR_FSAL_INVAL, 0);
00138 
00139   if(gettimeofday(&pasyncopdesc->op_time, NULL) != 0)
00140     {
00141       /* Could'not get time of day... Stopping, this may need a major failure */
00142       LogMajor(COMPONENT_MFSL, "MFSL_truncate: cannot get time of day... exiting");
00143       exit(1);
00144     }
00145 
00146   /* Is the object asynchronous ? */
00147   if(!mfsl_async_get_specdata(filehandle, &pasyncdata))
00148     {
00149       /* Not yet asynchronous object */
00150       P(p_mfsl_context->lock);
00151 
00152       pasyncdata = pool_alloc(p_mfsl_context->pool_spec_data, NULL);
00153 
00154       V(p_mfsl_context->lock);
00155 
00156       /* In this case use object_attributes parameter to initiate asynchronous object */
00157       pasyncdata->async_attr = *object_attributes;
00158     }
00159 
00160   fsal_status =
00161       MFSAL_truncate_check_perms(filehandle, pasyncdata, p_context, p_mfsl_context);
00162 
00163   if(FSAL_IS_ERROR(fsal_status))
00164     return fsal_status;
00165 
00166   LogDebug(COMPONENT_MFSL,  "Creating asyncop %p",
00167                     pasyncopdesc);
00168 
00169   pasyncopdesc->op_type = MFSL_ASYNC_OP_TRUNCATE;
00170   pasyncopdesc->op_mobject = filehandle;
00171   pasyncopdesc->op_args.truncate.pmobject = filehandle;
00172   pasyncopdesc->op_args.truncate.size = length;
00173   pasyncopdesc->op_res.truncate.attr = *object_attributes;
00174 
00175   pasyncopdesc->op_func = MFSL_truncate_async_op;
00176   pasyncopdesc->fsal_op_context = *p_context;
00177 
00178   pasyncopdesc->ptr_mfsl_context = (caddr_t) p_mfsl_context;
00179 
00180   fsal_status = MFSL_async_post(pasyncopdesc);
00181   if(FSAL_IS_ERROR(fsal_status))
00182     return fsal_status;
00183 
00184   /* Update the associated times for this object */
00185   pasyncdata->async_attr = *object_attributes;
00186   pasyncdata->async_attr.ctime.seconds = pasyncopdesc->op_time.tv_sec;
00187   pasyncdata->async_attr.ctime.nseconds = pasyncopdesc->op_time.tv_usec;  
00188   filehandle->health = MFSL_ASYNC_ASYNCHRONOUS;
00189 
00190   /* Set output attributes */
00191   *object_attributes = pasyncdata->async_attr;
00192 
00193   if(!mfsl_async_set_specdata(filehandle, pasyncdata))
00194     MFSL_return(ERR_FSAL_SERVERFAULT, 0);
00195 
00196   MFSL_return(ERR_FSAL_NO_ERROR, 0);
00197 }                               /* MFSL_truncate */