nfs-ganesha 1.4
|
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 00036 #ifdef HAVE_CONFIG_H 00037 #include "config.h" 00038 #endif 00039 00040 #ifdef _SOLARIS 00041 #include "solaris_port.h" 00042 #endif 00043 00044 #include <stdio.h> 00045 #include <string.h> 00046 #include <pthread.h> 00047 #include <fcntl.h> 00048 #include <sys/file.h> /* for having FNDELAY */ 00049 #include "HashData.h" 00050 #include "HashTable.h" 00051 #include "log.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_proto_tools.h" 00061 #include "nfs_tools.h" 00062 00081 int nfs3_Commit(nfs_arg_t *parg, 00082 exportlist_t *pexport, 00083 fsal_op_context_t *pcontext, 00084 nfs_worker_data_t *pworker, 00085 struct svc_req *preq, 00086 nfs_res_t *pres) 00087 { 00088 cache_inode_status_t cache_status; 00089 cache_entry_t *pentry = NULL; 00090 cache_inode_fsal_data_t fsal_data; 00091 fsal_attrib_list_t pre_attr; 00092 fsal_attrib_list_t *ppre_attr; 00093 uint64_t typeofcommit; 00094 int rc = NFS_REQ_OK; 00095 00096 if(isDebug(COMPONENT_NFSPROTO)) 00097 { 00098 char str[LEN_FH_STR]; 00099 sprint_fhandle3(str, &(parg->arg_commit3.file)); 00100 LogDebug(COMPONENT_NFSPROTO, 00101 "REQUEST PROCESSING: Calling nfs3_Commit handle: %s", str); 00102 } 00103 00104 /* to avoid setting it on each error case */ 00105 pres->res_commit3.COMMIT3res_u.resfail.file_wcc.before.attributes_follow = FALSE; 00106 pres->res_commit3.COMMIT3res_u.resfail.file_wcc.after.attributes_follow = FALSE; 00107 ppre_attr = NULL; 00108 00109 /* Convert file handle into a fsal_handle */ 00110 if(nfs3_FhandleToFSAL(&(parg->arg_commit3.file), &fsal_data.fh_desc, pcontext) == 0) 00111 { 00112 rc = NFS_REQ_DROP; 00113 goto out; 00114 } 00115 00116 /* Get the entry in the cache_inode */ 00117 if((pentry = cache_inode_get(&fsal_data, 00118 &pre_attr, 00119 pcontext, 00120 NULL, 00121 &cache_status)) == NULL) 00122 { 00123 /* Stale NFS FH ? */ 00124 pres->res_commit3.status = NFS3ERR_STALE; 00125 rc = NFS_REQ_OK; 00126 goto out; 00127 } 00128 00129 if((pexport->use_commit == TRUE) && 00130 (pexport->use_ganesha_write_buffer == FALSE)) 00131 typeofcommit = CACHE_INODE_UNSAFE_WRITE_TO_FS_BUFFER; 00132 else if((pexport->use_commit == TRUE) && 00133 (pexport->use_ganesha_write_buffer == TRUE)) 00134 typeofcommit = CACHE_INODE_UNSAFE_WRITE_TO_GANESHA_BUFFER; 00135 else 00136 { 00137 /* We only do stable writes with this export so no need to execute a commit */ 00138 rc = NFS_REQ_OK; 00139 goto out; 00140 } 00141 00142 /* Do not use DC if data cache is enabled, the data is kept synchronous is the DC */ 00143 if(cache_inode_commit(pentry, 00144 parg->arg_commit3.offset, 00145 parg->arg_commit3.count, 00146 typeofcommit, 00147 pcontext, 00148 &cache_status) != CACHE_INODE_SUCCESS) 00149 { 00150 pres->res_commit3.status = NFS3ERR_IO;; 00151 00152 nfs_SetWccData(pexport, 00153 ppre_attr, 00154 ppre_attr, &(pres->res_commit3.COMMIT3res_u.resfail.file_wcc)); 00155 00156 rc = NFS_REQ_OK; 00157 goto out; 00158 } 00159 00160 /* Set the pre_attr */ 00161 ppre_attr = &pre_attr; 00162 00163 nfs_SetWccData(pexport, 00164 ppre_attr, ppre_attr, &(pres->res_commit3.COMMIT3res_u.resok.file_wcc)); 00165 00166 /* Set the write verifier */ 00167 memcpy(pres->res_commit3.COMMIT3res_u.resok.verf, NFS3_write_verifier, 00168 sizeof(writeverf3)); 00169 pres->res_commit3.status = NFS3_OK; 00170 00171 out: 00172 00173 if (pentry) 00174 { 00175 cache_inode_put(pentry); 00176 } 00177 00178 return rc; 00179 } /* nfs3_Commit */ 00180 00189 void nfs3_Commit_Free(nfs_res_t * pres) 00190 { 00191 /* Nothing to do */ 00192 return; 00193 } /* nfs3_Commit_Free */