nfs-ganesha 1.4

nfs4_op_commit.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 #ifdef _PNFS_DS
00066 #include "fsal_pnfs.h"
00067 #endif /* _PNFS_DS */
00068 
00069 #ifdef _PNFS_DS
00070 static int op_dscommit(struct nfs_argop4 *op,
00071                        compound_data_t * data,
00072                        struct nfs_resop4 *resp);
00073 #endif /* _PNFS_DS */
00074 
00075 
00090 #define arg_COMMIT4 op->nfs_argop4_u.opcommit
00091 #define res_COMMIT4 resp->nfs_resop4_u.opcommit
00092 
00093 int nfs4_op_commit(struct nfs_argop4 *op, compound_data_t * data, struct nfs_resop4 *resp)
00094 {
00095   char __attribute__ ((__unused__)) funcname[] = "nfs4_op_commit";
00096 
00097   cache_inode_status_t cache_status;
00098 
00099   /* for the moment, read/write are not done asynchronously, no commit is necessary */
00100   resp->resop = NFS4_OP_COMMIT;
00101   res_COMMIT4.status = NFS4_OK;
00102 
00103   LogFullDebug(COMPONENT_NFS_V4,
00104                "      COMMIT4: Commit order over offset = %"PRIu64", size = %"PRIu32,
00105                arg_COMMIT4.offset, (uint32_t)arg_COMMIT4.count);
00106 
00107   /* 
00108    * Do basic checks on a filehandle 
00109    * Commit is done only on a file
00110    */
00111   res_COMMIT4.status = nfs4_sanity_check_FH(data, REGULAR_FILE);
00112   if(res_COMMIT4.status != NFS4_OK)
00113     return res_COMMIT4.status;
00114 
00115 #ifdef _PNFS_DS
00116   if((data->minorversion == 1) &&
00117      (nfs4_Is_Fh_DSHandle(&data->currentFH)))
00118     {
00119       return(op_dscommit(op, data, resp));
00120     }
00121 #endif /* _PNFS_DS */
00122 
00123   // FIX ME!! At the moment we just assume the user is _not_ using
00124   // the ganesha unsafe buffer. In the future, a check based on
00125   // export config params (similar to nfs3_Commit.c) should be made.
00126   if(cache_inode_commit(data->current_entry,
00127                         arg_COMMIT4.offset,
00128                         arg_COMMIT4.count,
00129                         CACHE_INODE_UNSAFE_WRITE_TO_FS_BUFFER,
00130                         data->pcontext,
00131                         &cache_status) != CACHE_INODE_SUCCESS)
00132     {
00133       res_COMMIT4.status = NFS4ERR_INVAL;
00134       return res_COMMIT4.status;
00135     }
00136 
00137   memcpy(res_COMMIT4.COMMIT4res_u.resok4.writeverf, (char *)&NFS4_write_verifier,
00138          NFS4_VERIFIER_SIZE);
00139 
00140   /* If you reach this point, then an error occured */
00141   res_COMMIT4.status = NFS4_OK;
00142   return res_COMMIT4.status;
00143 }                               /* nfs4_op_commit */
00144 
00155 void nfs4_op_commit_Free(COMMIT4res * resp)
00156 {
00157   /* Nothing to be done */
00158   return;
00159 }                               /* nfs4_op_commit_Free */
00160 
00161 #ifdef _PNFS_DS
00162 
00174 static int op_dscommit(struct nfs_argop4 *op,
00175                        compound_data_t * data,
00176                        struct nfs_resop4 *resp)
00177 {
00178   /* FSAL file handle */
00179   fsal_handle_t handle;
00180   struct fsal_handle_desc fh_desc;
00181   /* NFSv4 status code */
00182   nfsstat4 nfs_status = 0;
00183 
00184   /* Construct the FSAL file handle */
00185 
00186   if ((nfs4_FhandleToFSAL(&data->currentFH,
00187                           &fh_desc,
00188                           data->pcontext)) == 0)
00189     {
00190       res_COMMIT4.status = NFS4ERR_INVAL;
00191       return res_COMMIT4.status;
00192     }
00193 
00194   memset(&handle, 0, sizeof(handle));
00195   memcpy(&handle, fh_desc.start, fh_desc.len);
00196 
00197   /* Call the commit operation */
00198 
00199   nfs_status = fsal_dsfunctions
00200     .DS_commit(&handle,
00201                data->pcontext,
00202                arg_COMMIT4.offset,
00203                arg_COMMIT4.count,
00204                &res_COMMIT4.COMMIT4res_u.resok4.writeverf);
00205 
00206   res_COMMIT4.status = nfs_status;
00207   return res_COMMIT4.status;
00208 }
00209 
00210 #endif /* _PNFS_DS */