nfs-ganesha 1.4

mfsl_async_setattr.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_setattr_async_op(mfsl_async_op_desc_t * popasyncdesc)
00060 {
00061   fsal_status_t fsal_status;
00062 
00063   LogDebug(COMPONENT_MFSL, "Making asynchronous FSAL_setattrs for async op %p",
00064                   popasyncdesc);
00065 
00066   P(popasyncdesc->op_args.setattr.pmobject->lock);
00067   fsal_status = FSAL_setattrs(&(popasyncdesc->op_args.setattr.pmobject->handle),
00068                               &popasyncdesc->fsal_op_context,
00069                               &popasyncdesc->op_args.setattr.attr,
00070                               &popasyncdesc->op_res.setattr.attr);
00071   V(popasyncdesc->op_args.setattr.pmobject->lock);
00072 
00073   return fsal_status;
00074 }                               /* MFSL_setattr_async_op */
00075 
00090 fsal_status_t MFSL_setattrs_check_perms(mfsl_object_t * filehandle,     /* IN */
00091                                         mfsl_object_specific_data_t * pspecdata,        /* IN */
00092                                         fsal_op_context_t * p_context,  /* IN */
00093                                         mfsl_context_t * p_mfsl_context,        /* IN */
00094                                         fsal_attrib_list_t * attrib_set /* IN */ )
00095 {
00096   fsal_status_t fsal_status;
00097 
00098   /* Root is the only one that can chown or chgrp */
00099   if(attrib_set->asked_attributes & (FSAL_ATTR_OWNER | FSAL_ATTR_GROUP))
00100     {
00101       if(p_context->user_credential.user != 0)
00102         MFSL_return(ERR_FSAL_ACCESS, 0);
00103     }
00104 
00105   fsal_status = FSAL_setattr_access(p_context, attrib_set, &pspecdata->async_attr);
00106 
00107   if(FSAL_IS_ERROR(fsal_status))
00108     return fsal_status;
00109 
00110   MFSL_return(ERR_FSAL_NO_ERROR, 0);
00111 }                               /* MFSL_setattr_check_perms */
00112 
00128 fsal_status_t MFSL_setattrs(mfsl_object_t * filehandle, /* IN */
00129                             fsal_op_context_t * p_context,      /* IN */
00130                             mfsl_context_t * p_mfsl_context,    /* IN */
00131                             fsal_attrib_list_t * attrib_set,    /* IN */
00132                             fsal_attrib_list_t * object_attributes      /* [ IN/OUT ] */
00133     )
00134 {
00135   fsal_status_t fsal_status;
00136   mfsl_async_op_desc_t *pasyncopdesc = NULL;
00137   mfsl_object_specific_data_t *pasyncdata = NULL;
00138 
00139   P(p_mfsl_context->lock);
00140 
00141   pasyncopdesc = pool_alloc(p_mfsl_context->pool_async_op, NULL);
00142 
00143   V(p_mfsl_context->lock);
00144 
00145   if(pasyncopdesc == NULL)
00146     MFSL_return(ERR_FSAL_INVAL, 0);
00147 
00148   if(gettimeofday(&pasyncopdesc->op_time, NULL) != 0)
00149     {
00150       /* Could'not get time of day... Stopping, this may need a major failure */
00151       LogMajor(COMPONENT_MFSL, "MFSL_setattrs: cannot get time of day... exiting");
00152       exit(1);
00153     }
00154 
00155   /* Is the object asynchronous ? */
00156   if(!mfsl_async_get_specdata(filehandle, &pasyncdata))
00157     {
00158       /* Not yet asynchronous object */
00159       P(p_mfsl_context->lock);
00160 
00161       pasyncdata = pool_alloc(p_mfsl_context->pool_spec_data, NULL);
00162 
00163       V(p_mfsl_context->lock);
00164 
00165       /* In this case use object_attributes parameter to initiate asynchronous object */
00166       pasyncdata->async_attr = *object_attributes;
00167     }
00168 
00169   fsal_status =
00170       MFSL_setattrs_check_perms(filehandle, pasyncdata, p_context, p_mfsl_context,
00171                                 attrib_set);
00172 
00173   if(FSAL_IS_ERROR(fsal_status))
00174     return fsal_status;
00175 
00176   LogDebug(COMPONENT_MFSL,  "Creating asyncop %p",
00177                     pasyncopdesc);
00178 
00179   pasyncopdesc->op_type = MFSL_ASYNC_OP_SETATTR;
00180   pasyncopdesc->op_mobject = filehandle;
00181   pasyncopdesc->op_args.setattr.pmobject = filehandle;
00182   pasyncopdesc->op_args.setattr.attr = *attrib_set;
00183   pasyncopdesc->op_res.setattr.attr = *attrib_set;
00184 
00185   pasyncopdesc->op_func = MFSL_setattr_async_op;
00186   pasyncopdesc->fsal_op_context = *p_context;
00187 
00188   pasyncopdesc->ptr_mfsl_context = (caddr_t) p_mfsl_context;
00189 
00190   fsal_status = MFSL_async_post(pasyncopdesc);
00191   if(FSAL_IS_ERROR(fsal_status))
00192     return fsal_status;
00193 
00194   /* Update the associated times for this object */
00195   pasyncdata->async_attr.ctime.seconds = pasyncopdesc->op_time.tv_sec;
00196   pasyncdata->async_attr.ctime.nseconds = pasyncopdesc->op_time.tv_usec;  
00197   filehandle->health = MFSL_ASYNC_ASYNCHRONOUS;
00198 
00199   /* merge the attributes to the asynchronous attributes */
00200   if((attrib_set->asked_attributes & FSAL_ATTR_SIZE) ||
00201      (attrib_set->asked_attributes & FSAL_ATTR_SPACEUSED))
00202     {
00203       /* Operation on a non data cached file */
00204       pasyncdata->async_attr.filesize = attrib_set->filesize;
00205       pasyncdata->async_attr.spaceused = attrib_set->spaceused;
00206     }
00207 
00208   if(attrib_set->asked_attributes & (FSAL_ATTR_MODE | FSAL_ATTR_OWNER | FSAL_ATTR_GROUP))
00209     {
00210       if(attrib_set->asked_attributes & FSAL_ATTR_MODE)
00211         pasyncdata->async_attr.mode = attrib_set->mode;
00212 
00213       if(attrib_set->asked_attributes & FSAL_ATTR_OWNER)
00214         pasyncdata->async_attr.owner = attrib_set->owner;
00215 
00216       if(attrib_set->asked_attributes & FSAL_ATTR_GROUP)
00217         pasyncdata->async_attr.group = attrib_set->group;
00218     }
00219 
00220   if(attrib_set->asked_attributes & (FSAL_ATTR_ATIME | FSAL_ATTR_MTIME))
00221     {
00222       if(attrib_set->asked_attributes & FSAL_ATTR_ATIME)
00223         pasyncdata->async_attr.atime = attrib_set->atime;
00224 
00225       if(attrib_set->asked_attributes & FSAL_ATTR_MTIME)
00226         pasyncdata->async_attr.mtime = attrib_set->mtime;
00227     }
00228 
00229   /* Set output attributes */
00230   *object_attributes = pasyncdata->async_attr;
00231 
00232   if(!mfsl_async_set_specdata(filehandle, pasyncdata))
00233     MFSL_return(ERR_FSAL_SERVERFAULT, 0);
00234 
00235   MFSL_return(ERR_FSAL_NO_ERROR, 0);
00236 }                               /* MFSL_setattr */