nfs-ganesha 1.4

nfs4_op_savefh.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
00022  * 02110-1301 USA
00023  *
00024  * ---------------------------------------
00025  */
00026 
00038 #ifdef HAVE_CONFIG_H
00039 #include "config.h"
00040 #endif
00041 
00042 #ifdef _SOLARIS
00043 #include "solaris_port.h"
00044 #endif
00045 
00046 #include <stdio.h>
00047 #include <string.h>
00048 #include <pthread.h>
00049 #include <fcntl.h>
00050 #include <sys/file.h>           /* for having FNDELAY */
00051 #include "HashData.h"
00052 #include "HashTable.h"
00053 #include "log.h"
00054 #include "ganesha_rpc.h"
00055 #include "nfs23.h"
00056 #include "nfs4.h"
00057 #include "mount.h"
00058 #include "nfs_core.h"
00059 #include "cache_inode.h"
00060 #include "cache_inode_lru.h"
00061 #include "nfs_exports.h"
00062 #include "nfs_creds.h"
00063 #include "nfs_proto_functions.h"
00064 #include "nfs_proto_tools.h"
00065 #include "nfs_tools.h"
00066 #include "nfs_file_handle.h"
00067 
00087 #define arg_SAVEFH op->nfs_argop4_u.opsavefh
00088 #define res_SAVEFH resp->nfs_resop4_u.opsavefh
00089 
00090 int nfs4_op_savefh(struct nfs_argop4 *op,
00091                    compound_data_t * data,
00092                    struct nfs_resop4 *resp)
00093 {
00094   char __attribute__ ((__unused__)) funcname[] = "nfs4_op_savefh";
00095 
00096   /* First of all, set the reply to zero to make sure it contains no
00097      parasite information */
00098   memset(resp, 0, sizeof(struct nfs_resop4));
00099   resp->resop = NFS4_OP_SAVEFH;
00100   res_SAVEFH.status = NFS4_OK;
00101 
00102   /* Do basic checks on a filehandle */
00103   res_SAVEFH.status = nfs4_sanity_check_FH(data, 0LL);
00104   if(res_SAVEFH.status != NFS4_OK)
00105     return res_SAVEFH.status;
00106 
00107   /* If the savefh is not allocated, do it now */
00108   if(data->savedFH.nfs_fh4_len == 0)
00109     {
00110       res_SAVEFH.status = nfs4_AllocateFH(&(data->savedFH));
00111       if(res_SAVEFH.status != NFS4_OK)
00112         return res_SAVEFH.status;
00113     }
00114 
00115   /* Copy the data from current FH to saved FH */
00116   memcpy(data->savedFH.nfs_fh4_val,
00117          data->currentFH.nfs_fh4_val,
00118          data->currentFH.nfs_fh4_len);
00119   data->savedFH.nfs_fh4_len = data->currentFH.nfs_fh4_len;
00120 
00121 
00122   /* If saved and current entry are equal, skip the following. */
00123 
00124   if (data->saved_entry == data->current_entry) {
00125       goto out;
00126   }
00127 
00128   if (data->saved_entry) {
00129       cache_inode_put(data->saved_entry);
00130       data->saved_entry = NULL;
00131   }
00132 
00133   data->saved_entry = data->current_entry;
00134   data->saved_filetype = data->current_filetype;
00135 
00136   /* Take another reference.  As of now the filehandle is both saved
00137      and current and both must be counted.  Guard this, in case we
00138      have a pseudofs handle. */
00139 
00140   if (data->saved_entry) {
00141        if (cache_inode_lru_ref(data->saved_entry,
00142                                LRU_FLAG_NONE) != CACHE_INODE_SUCCESS) {
00143             data->saved_entry = NULL;
00144             resp->nfs_resop4_u.opsavefh.status = NFS4ERR_STALE;
00145             return resp->nfs_resop4_u.opsavefh.status;
00146        }
00147   }
00148 
00149  out:
00150 
00151   if(isFullDebug(COMPONENT_NFS_V4))
00152     {
00153       char str[LEN_FH_STR];
00154       sprint_fhandle4(str, &data->savedFH);
00155       LogFullDebug(COMPONENT_NFS_V4, "SAVE FH: Saved FH %s", str);
00156     }
00157 
00158   return NFS4_OK;
00159 }                               /* nfs4_op_savefh */
00160 
00171 void nfs4_op_savefh_Free(SAVEFH4res * resp)
00172 {
00173   /* Nothing to be done */
00174   return;
00175 }                               /* nfs4_op_savefh_Free */