nfs-ganesha 1.4

nfs4_op_putrootfh.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_file_handle.h"
00063 #include "nfs_tools.h"
00064 
00080 static int CreateROOTFH4(nfs_fh4 * fh, compound_data_t * data)
00081 {
00082   pseudofs_entry_t psfsentry;
00083   int              status = 0;
00084 
00085   psfsentry = *(data->pseudofs->reverse_tab[0]);
00086 
00087   if((status = nfs4_AllocateFH(&(data->rootFH))) != NFS4_OK)
00088     return status;
00089 
00090   if(!nfs4_PseudoToFhandle(&(data->rootFH), &psfsentry))
00091     return NFS4ERR_BADHANDLE;
00092 
00093   LogHandleNFS4("CREATE ROOT FH: ", &data->rootFH);
00094 
00095   return NFS4_OK;
00096 }                               /* CreateROOTFH4 */
00097 
00114 #define arg_PUTROOTFH4 op->nfs_argop4_u.opputrootfh
00115 #define res_PUTROOTFH4 resp->nfs_resop4_u.opputrootfh
00116 
00117 int nfs4_op_putrootfh(struct nfs_argop4 *op,
00118                       compound_data_t * data, struct nfs_resop4 *resp)
00119 {
00120   char __attribute__ ((__unused__)) funcname[] = "nfs4_op_putrootfh";
00121 
00122   /* This NFS4 Operation has no argument, it just get then ROOTFH (replace MOUNTPROC3_MNT) */
00123 
00124   /* First of all, set the reply to zero to make sure it contains no parasite information */
00125   memset(resp, 0, sizeof(struct nfs_resop4));
00126   resp->resop = NFS4_OP_PUTROOTFH;
00127 
00128   res_PUTROOTFH4.status = CreateROOTFH4(&(data->rootFH), data);
00129   if(res_PUTROOTFH4.status != NFS4_OK)
00130     return res_PUTROOTFH4.status;
00131 
00132   if (data->current_entry) {
00133       cache_inode_put(data->current_entry);
00134   }
00135   data->current_entry = NULL;   /* No cache inode entry for the directory within pseudo fs */
00136   data->current_filetype = DIRECTORY;      /* Only directory in the pseudo fs */
00137 
00138   /* I copy the root FH to the currentFH and, if not already done, to the publicFH */
00139   /* For the moment, I choose to have rootFH = publicFH */
00140   /* For initial mounted_on_FH, I'll use the rootFH, this will change at junction traversal */
00141   if(data->currentFH.nfs_fh4_len == 0)
00142     {
00143       res_PUTROOTFH4.status = nfs4_AllocateFH(&(data->currentFH));
00144       if(res_PUTROOTFH4.status != NFS4_OK)
00145         return res_PUTROOTFH4.status;
00146     }
00147   memcpy((char *)(data->currentFH.nfs_fh4_val), (char *)(data->rootFH.nfs_fh4_val),
00148          data->rootFH.nfs_fh4_len);
00149   data->currentFH.nfs_fh4_len = data->rootFH.nfs_fh4_len;
00150 
00151   if(data->mounted_on_FH.nfs_fh4_len == 0)
00152     {
00153       res_PUTROOTFH4.status = nfs4_AllocateFH(&(data->mounted_on_FH));
00154       if(res_PUTROOTFH4.status != NFS4_OK)
00155         return res_PUTROOTFH4.status;
00156     }
00157   memcpy((char *)(data->mounted_on_FH.nfs_fh4_val), (char *)(data->rootFH.nfs_fh4_val),
00158          data->rootFH.nfs_fh4_len);
00159   data->mounted_on_FH.nfs_fh4_len = data->rootFH.nfs_fh4_len;
00160 
00161   if(data->publicFH.nfs_fh4_len == 0)
00162     {
00163       res_PUTROOTFH4.status = nfs4_AllocateFH(&(data->publicFH));
00164       if(res_PUTROOTFH4.status != NFS4_OK)
00165         return res_PUTROOTFH4.status;
00166     }
00167   /* Copy the data where they are supposed to be */
00168   memcpy((char *)(data->publicFH.nfs_fh4_val), (char *)(data->rootFH.nfs_fh4_val),
00169          data->rootFH.nfs_fh4_len);
00170   data->publicFH.nfs_fh4_len = data->rootFH.nfs_fh4_len;
00171 
00172   LogHandleNFS4("NFS4 PUTROOTFH ROOT    FH: ", &data->rootFH);
00173   LogHandleNFS4("NFS4 PUTROOTFH CURRENT FH: ", &data->currentFH);
00174 
00175   LogFullDebug(COMPONENT_NFS_V4,
00176                     "NFS4 PUTROOTFH: Ending on status %d",
00177                     res_PUTROOTFH4.status);
00178 
00179   return res_PUTROOTFH4.status;
00180 }                               /* nfs4_op_putrootfh */
00181 
00192 void nfs4_op_putrootfh_Free(PUTROOTFH4res * resp)
00193 {
00194   /* Nothing to be done */
00195   return;
00196 }                               /* nfs4_op_putrootfh_Free */