nfs-ganesha 1.4

nfs4_op_lookupp.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  * ---------------------------------------
00024  */
00025 
00037 #ifdef HAVE_CONFIG_H
00038 #include "config.h"
00039 #endif
00040 
00041 #ifdef _SOLARIS
00042 #include "solaris_port.h"
00043 #endif
00044 
00045 #include <stdio.h>
00046 #include <string.h>
00047 #include <pthread.h>
00048 #include <fcntl.h>
00049 #include <sys/file.h>           /* for having FNDELAY */
00050 #include "HashData.h"
00051 #include "HashTable.h"
00052 #include "log.h"
00053 #include "ganesha_rpc.h"
00054 #include "nfs23.h"
00055 #include "nfs4.h"
00056 #include "mount.h"
00057 #include "nfs_core.h"
00058 #include "cache_inode.h"
00059 #include "nfs_exports.h"
00060 #include "nfs_creds.h"
00061 #include "nfs_proto_functions.h"
00062 #include "nfs_proto_tools.h"
00063 #include "nfs_tools.h"
00064 #include "nfs_file_handle.h"
00065 
00078 #define arg_LOOKUPP4 op->nfs_argop4_u.oplookupp
00079 #define res_LOOKUPP4 resp->nfs_resop4_u.oplookupp
00080 
00081 int nfs4_op_lookupp(struct nfs_argop4 *op,
00082                     compound_data_t * data, struct nfs_resop4 *resp)
00083 {
00084   char __attribute__ ((__unused__)) funcname[] = "nfs4_op_lookupp";
00085 
00086   fsal_name_t            name;
00087   cache_entry_t        * dir_pentry = NULL;
00088   cache_entry_t        * file_pentry = NULL;
00089   fsal_attrib_list_t     attrlookup;
00090   cache_inode_status_t   cache_status;
00091   int                    error = 0;
00092   fsal_handle_t        * pfsal_handle = NULL;
00093 
00094   resp->resop = NFS4_OP_LOOKUPP;
00095   res_LOOKUPP4.status = NFS4_OK;
00096 
00097   /* Do basic checks on a filehandle */
00098   res_LOOKUPP4.status = nfs4_sanity_check_FH(data, 0LL);
00099   if(res_LOOKUPP4.status != NFS4_OK)
00100     return res_LOOKUPP4.status;
00101 
00102   /* looking up for parent directory from ROOTFH return NFS4ERR_NOENT (RFC3530, page 166) */
00103   if(data->currentFH.nfs_fh4_len == data->rootFH.nfs_fh4_len
00104      && memcmp(data->currentFH.nfs_fh4_val, data->rootFH.nfs_fh4_val,
00105                data->currentFH.nfs_fh4_len) == 0)
00106     {
00107       /* Nothing to do, just reply with success */
00108       res_LOOKUPP4.status = NFS4ERR_NOENT;
00109       return res_LOOKUPP4.status;
00110     }
00111 
00112   /* If in pseudoFS, proceed with pseudoFS specific functions */
00113   if(nfs4_Is_Fh_Pseudo(&(data->currentFH)))
00114     return nfs4_op_lookupp_pseudo(op, data, resp);
00115 
00116   /* If Filehandle points to a xattr object, manage it via the xattrs specific functions */
00117   if(nfs4_Is_Fh_Xattr(&(data->currentFH)))
00118     return nfs4_op_lookupp_xattr(op, data, resp);
00119 
00120   /* If data->exportp is null, a junction from pseudo fs was traversed, credp and exportp have to be updated */
00121   if(data->pexport == NULL)
00122     {
00123       if((error = nfs4_SetCompoundExport(data)) != NFS4_OK)
00124         {
00125           res_LOOKUPP4.status = error;
00126           return res_LOOKUPP4.status;
00127         }
00128     }
00129 
00130   /* Preparying for cache_inode_lookup ".." */
00131   file_pentry = NULL;
00132   dir_pentry = data->current_entry;
00133   name = FSAL_DOT_DOT;
00134 
00135   /* BUGAZOMEU: Faire la gestion des cross junction traverse */
00136   if((file_pentry
00137       = cache_inode_lookup(dir_pentry,
00138                            &name,
00139                            &attrlookup,
00140                            data->pcontext, &cache_status)) != NULL)
00141     {
00142       /* Extract the fsal attributes from the cache inode pentry */
00143       pfsal_handle = &file_pentry->handle;
00144 
00145       /* Convert it to a file handle */
00146       if(!nfs4_FSALToFhandle(&data->currentFH, pfsal_handle, data))
00147         {
00148           res_LOOKUPP4.status = NFS4ERR_SERVERFAULT;
00149           cache_inode_put(file_pentry);
00150           return res_LOOKUPP4.status;
00151         }
00152 
00153       /* Copy this to the mounted on FH (if no junction is traversed */
00154       memcpy((char *)(data->mounted_on_FH.nfs_fh4_val),
00155              (char *)(data->currentFH.nfs_fh4_val), data->currentFH.nfs_fh4_len);
00156       data->mounted_on_FH.nfs_fh4_len = data->currentFH.nfs_fh4_len;
00157 
00158       /* Release dir_pentry, as it is not reachable from anywhere in
00159          compound after this function returns.  Count on later
00160          operations or nfs4_Compound to clean up current_entry. */
00161 
00162       if (dir_pentry)
00163         cache_inode_put(dir_pentry);
00164 
00165       /* Keep the pointer within the compound data */
00166       data->current_entry = file_pentry;
00167       data->current_filetype = file_pentry->type;
00168 
00169       /* Return successfully */
00170       res_LOOKUPP4.status = NFS4_OK;
00171       return NFS4_OK;
00172 
00173     }
00174 
00175   /* If the part of the code is reached, then something wrong occured in the
00176    * lookup process, status is not HPSS_E_NOERROR and contains the code for
00177    * the error */
00178 
00179   /* For any wrong file type LOOKUPP should return NFS4ERR_NOTDIR */
00180   res_LOOKUPP4.status = nfs4_Errno(cache_status);
00181 
00182   return res_LOOKUPP4.status;
00183 }                               /* nfs4_op_lookupp */
00184 
00195 void nfs4_op_lookupp_Free(LOOKUPP4res * resp)
00196 {
00197   /* Nothing to be done */
00198   return;
00199 }                               /* nfs4_op_lookupp_Free */