nfs-ganesha 1.4

nfs4_op_getattr.c

Go to the documentation of this file.
00001 /*
00002  * vim:expandtab:shiftwidth=8:tabstop=8:
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  * --------------------------------------- */
00035 #ifdef HAVE_CONFIG_H
00036 #include "config.h"
00037 #endif
00038 
00039 #ifdef _SOLARIS
00040 #include "solaris_port.h"
00041 #endif
00042 
00043 #include <stdio.h>
00044 #include <string.h>
00045 #include <pthread.h>
00046 #include <fcntl.h>
00047 #include <sys/file.h>           /* for having FNDELAY */
00048 #include "HashData.h"
00049 #include "HashTable.h"
00050 #include "log.h"
00051 #include "ganesha_rpc.h"
00052 #include "nfs23.h"
00053 #include "nfs4.h"
00054 #include "mount.h"
00055 #include "nfs_core.h"
00056 #include "cache_inode.h"
00057 #include "nfs_exports.h"
00058 #include "nfs_creds.h"
00059 #include "nfs_proto_functions.h"
00060 #include "nfs_tools.h"
00061 #include "nfs_proto_tools.h"
00062 #include "nfs_file_handle.h"
00063 
00064 #define arg_GETATTR4 op->nfs_argop4_u.opgetattr
00065 #define res_GETATTR4 resp->nfs_resop4_u.opgetattr
00066 
00080 int nfs4_op_getattr(struct nfs_argop4 *op,
00081                     compound_data_t * data, struct nfs_resop4 *resp)
00082 {
00083   char __attribute__ ((__unused__)) funcname[] = "nfs4_op_getattr";
00084 
00085   fsal_attrib_list_t   attr;
00086   cache_inode_status_t cache_status;
00087 
00088   /* This is a NFS4_OP_GETTAR */
00089   resp->resop = NFS4_OP_GETATTR;
00090   res_GETATTR4.status = NFS4_OK;
00091 
00092   /* Do basic checks on a filehandle */
00093   res_GETATTR4.status = nfs4_sanity_check_FH(data, 0LL);
00094   if(res_GETATTR4.status != NFS4_OK)
00095     return res_GETATTR4.status;
00096 
00097   /* Pseudo Fs management */
00098   if(nfs4_Is_Fh_Pseudo(&(data->currentFH)))
00099     return nfs4_op_getattr_pseudo(op, data, resp);
00100 
00101   if (nfs_export_check_security(data->reqp, data->pexport) == FALSE)
00102     {
00103       res_GETATTR4.status = NFS4ERR_PERM;
00104       return res_GETATTR4.status;
00105     }
00106 
00107   /* If Filehandle points to a xattr object, manage it via the xattrs specific functions */
00108   if(nfs4_Is_Fh_Xattr(&(data->currentFH)))
00109     return nfs4_op_getattr_xattr(op, data, resp);
00110 
00111   if(isFullDebug(COMPONENT_NFS_V4))
00112     {
00113       char str[LEN_FH_STR];
00114       sprint_fhandle4(str, &data->currentFH);
00115       LogFullDebug(COMPONENT_NFS_V4, "NFS4_OP_GETATTR: Current FH %s", str);
00116     }
00117 
00118   /* Sanity check: if no attributes are wanted, nothing is to be done.
00119    * In this case NFS4_OK is to be returned */
00120   if(arg_GETATTR4.attr_request.bitmap4_len == 0)
00121     {
00122       res_GETATTR4.status = NFS4_OK;
00123       return res_GETATTR4.status;
00124     }
00125 
00126   /* Get only attributes that are allowed to be read */
00127   if(!nfs4_Fattr_Check_Access_Bitmap(&arg_GETATTR4.attr_request, FATTR4_ATTR_READ))
00128     {
00129       res_GETATTR4.status = NFS4ERR_INVAL;
00130       return res_GETATTR4.status;
00131     }
00132 
00133   if( !nfs4_bitmap4_Remove_Unsupported( &arg_GETATTR4.attr_request ) )
00134     {
00135       res_GETATTR4.status = NFS4ERR_SERVERFAULT ;
00136       return res_GETATTR4.status;
00137     }
00138 
00139 
00140   /*
00141    * Get attributes.
00142    */
00143   if(cache_inode_getattr(data->current_entry,
00144                          &attr,
00145                          data->pcontext, &cache_status) == CACHE_INODE_SUCCESS)
00146     {
00147       if(nfs4_FSALattr_To_Fattr(data->pexport,
00148                                 &attr,
00149                                 &(res_GETATTR4.GETATTR4res_u.resok4.obj_attributes),
00150                                 data,
00151                                 &(data->currentFH), &(arg_GETATTR4.attr_request)) != 0)
00152         res_GETATTR4.status = NFS4ERR_SERVERFAULT;
00153       else
00154         res_GETATTR4.status = NFS4_OK;
00155 
00156       return res_GETATTR4.status;
00157     }
00158   res_GETATTR4.status = nfs4_Errno(cache_status);
00159 
00160   return res_GETATTR4.status;
00161 }                               /* nfs4_op_getattr */
00162 
00173 void nfs4_op_getattr_Free(GETATTR4res * resp)
00174 {
00175   if(resp->status == NFS4_OK)
00176     nfs4_Fattr_Free(&resp->GETATTR4res_u.resok4.obj_attributes);
00177   return;
00178 }                               /* nfs4_op_getattr_Free */