nfs-ganesha 1.4

fsal_attrs.c

Go to the documentation of this file.
00001 /*
00002  * vim:expandtab:shiftwidth=8:tabstop=8:
00003  *
00004  * Copyright (C) 2010, The Linux Box Corporation
00005  * Contributor : Adam C. Emerson <aemerson@linuxbox.com>
00006  *
00007  * Some portions Copyright CEA/DAM/DIF  (2008)
00008  * contributeur : Philippe DENIEL   philippe.deniel@cea.fr
00009  *                Thomas LEIBOVICI  thomas.leibovici@cea.fr
00010  *
00011  *
00012  * This program is free software; you can redistribute it and/or
00013  * modify it under the terms of the GNU Lesser General Public
00014  * License as published by the Free Software Foundation; either
00015  * version 3 of the License, or (at your option) any later version.
00016  *
00017  * This program is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020  * Lesser General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU Lesser General Public
00023  * License along with this library; if not, write to the Free Software
00024  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00025  *
00026  * -------------
00027  */
00028 
00035 #ifdef HAVE_CONFIG_H
00036 #include "config.h"
00037 #endif
00038 
00039 #include "fsal.h"
00040 #include "fsal_internal.h"
00041 #include "fsal_convert.h"
00042 
00064 fsal_status_t CEPHFSAL_getattrs(fsal_handle_t * exthandle,
00065                                 fsal_op_context_t * extcontext,
00066                                 fsal_attrib_list_t * object_attributes)
00067 {
00068   int rc;
00069   struct stat st;
00070   fsal_status_t status;
00071   cephfsal_handle_t* filehandle = (cephfsal_handle_t*) exthandle;
00072   cephfsal_op_context_t* context = (cephfsal_op_context_t*) extcontext;
00073   int uid = FSAL_OP_CONTEXT_TO_UID(context);
00074   int gid = FSAL_OP_CONTEXT_TO_GID(context);
00075 
00076   /* sanity checks.
00077    * note : object_attributes is mandatory in FSAL_getattrs.
00078    */
00079   if(!filehandle || !context || !object_attributes)
00080     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_getattrs);
00081 
00082   TakeTokenFSCall();
00083 
00084   rc = ceph_ll_getattr(context->export_context->cmount, VINODE(filehandle),
00085                        &st, uid, gid);
00086 
00087   ReleaseTokenFSCall();
00088 
00089   if (rc < 0)
00090     Return(posix2fsal_error(rc), 0, INDEX_FSAL_getattrs);
00091 
00092   /* convert attributes */
00093   status = posix2fsal_attributes(&st, object_attributes);
00094   if(FSAL_IS_ERROR(status))
00095     {
00096       FSAL_CLEAR_MASK(object_attributes->asked_attributes);
00097       FSAL_SET_MASK(object_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR);
00098       Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_getattrs);
00099     }
00100 
00101   Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_getattrs);
00102 }
00103 
00137 fsal_status_t CEPHFSAL_setattrs(fsal_handle_t * exthandle,
00138                                 fsal_op_context_t * extcontext,
00139                                 fsal_attrib_list_t * attrib_set,
00140                                 fsal_attrib_list_t * object_attributes)
00141 {
00142   cephfsal_handle_t* filehandle = (cephfsal_handle_t*) exthandle;
00143   cephfsal_op_context_t* context = (cephfsal_op_context_t*) extcontext;
00144   struct stat st;
00145   fsal_attrib_list_t attrs;
00146   int rc, mask=0;
00147   int uid = FSAL_OP_CONTEXT_TO_UID(context);
00148   int gid = FSAL_OP_CONTEXT_TO_GID(context);
00149 
00150   /* sanity checks.
00151    * note : object_attributes is optional.
00152    */
00153   if(!filehandle || !context || !attrib_set)
00154     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_setattrs);
00155 
00156   /* local copy of attributes */
00157   attrs = *attrib_set;
00158 
00159   /* First, check that FSAL attributes changes are allowed. */
00160 
00161   /* Is it allowed to change times ? */
00162 
00163   if(!global_fs_info.cansettime)
00164     {
00165       if(attrs.asked_attributes &
00166          (FSAL_ATTR_ATIME |
00167           FSAL_ATTR_CREATION |
00168           FSAL_ATTR_CTIME |
00169           FSAL_ATTR_MTIME))
00170         {
00171 
00172           /* handled as an unsettable attribute. */
00173           Return(ERR_FSAL_INVAL, 0, INDEX_FSAL_setattrs);
00174         }
00175 
00176     }
00177 
00178   /* apply umask, if mode attribute is to be changed */
00179 
00180   if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_MODE))
00181     {
00182       attrs.mode &= (~global_fs_info.umask);
00183     }
00184 
00185   /* Build flags and struct stat */
00186 
00187   if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_MODE))
00188     {
00189       mask |= CEPH_SETATTR_MODE;
00190       st.st_mode = fsal2unix_mode(attrs.mode);
00191     }
00192   if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_OWNER))
00193     {
00194       mask |= CEPH_SETATTR_UID;
00195       st.st_uid = attrs.owner;
00196     }
00197   if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_GROUP))
00198     {
00199       mask |= CEPH_SETATTR_UID;
00200       st.st_gid = attrs.group;
00201     }
00202   if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_ATIME))
00203     {
00204       mask |= CEPH_SETATTR_ATIME;
00205       st.st_atime = attrs.atime.seconds;
00206     }
00207   if (FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_MTIME))
00208     {
00209       mask |= CEPH_SETATTR_MTIME;
00210       st.st_mtime = attrs.mtime.seconds;
00211     }
00212   if (FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_CTIME))
00213     {
00214       mask |= CEPH_SETATTR_CTIME;
00215       st.st_ctime = attrs.ctime.seconds;
00216     }
00217 
00218   TakeTokenFSCall();
00219 
00220   rc = ceph_ll_setattr(context->export_context->cmount, VINODE(filehandle),
00221                        &st, mask, uid, gid);
00222 
00223   ReleaseTokenFSCall();
00224 
00225   if (rc < 0)
00226     Return(posix2fsal_error(rc), 0, INDEX_FSAL_getattrs);
00227 
00228   if(object_attributes)
00229     {
00230       fsal_status_t status;
00231       status = CEPHFSAL_getattrs(exthandle, extcontext, object_attributes);
00232 
00233       /* on error, we set a special bit in the mask. */
00234       if(FSAL_IS_ERROR(status))
00235         {
00236           FSAL_CLEAR_MASK(object_attributes->asked_attributes);
00237           FSAL_SET_MASK(object_attributes->asked_attributes,
00238                         FSAL_ATTR_RDATTR_ERR);
00239         }
00240 
00241     }
00242 
00243   Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_setattrs);
00244 }
00245 
00265 fsal_status_t CEPHFSAL_getextattrs(fsal_handle_t * p_filehandle,
00266                                    fsal_op_context_t * p_context,
00267                                    fsal_extattrib_list_t * p_object_attributes)
00268 {
00269   Return(ERR_FSAL_NOTSUPP, 0, INDEX_FSAL_getextattrs);
00270 } /* CEPHFSAL_getextattrs */