nfs-ganesha 1.4
|
00001 /* 00002 * Copyright IBM Corporation, 2012 00003 * Contributor: Frank Filz <ffilz@us.ibm.com> 00004 * 00005 * -------------------------- 00006 * 00007 * This program is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 3 of the License, or (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 * 00021 * 00022 */ 00023 00024 #ifdef HAVE_CONFIG_H 00025 #include "config.h" 00026 #endif 00027 00028 #ifdef _SOLARIS 00029 #include "solaris_port.h" 00030 #endif 00031 00032 #include <stdio.h> 00033 #include <string.h> 00034 #include <pthread.h> 00035 #include "ganesha_rpc.h" 00036 #include "log.h" 00037 #include "nlm4.h" 00038 #include "sal_functions.h" 00039 #include "nlm_util.h" 00040 #include "nlm_async.h" 00041 00054 int nlm4_Share(nfs_arg_t * parg, 00055 exportlist_t * pexport, 00056 fsal_op_context_t * pcontext, 00057 nfs_worker_data_t * pworker, 00058 struct svc_req * preq, 00059 nfs_res_t * pres) 00060 { 00061 nlm4_shareargs * arg = &parg->arg_nlm4_share; 00062 cache_entry_t * pentry; 00063 state_status_t state_status = STATE_SUCCESS; 00064 char buffer[MAXNETOBJ_SZ * 2]; 00065 state_nsm_client_t * nsm_client; 00066 state_nlm_client_t * nlm_client; 00067 state_owner_t * nlm_owner; 00068 int rc; 00069 int grace = nfs_in_grace(); 00070 00071 pres->res_nlm4share.sequence = 0; 00072 00073 netobj_to_string(&arg->cookie, buffer, 1024); 00074 LogDebug(COMPONENT_NLM, 00075 "REQUEST PROCESSING: Calling nlm4_Share cookie=%s reclaim=%s", 00076 buffer, 00077 arg->reclaim ? "yes" : "no"); 00078 00079 if(!copy_netobj(&pres->res_nlm4share.cookie, &arg->cookie)) 00080 { 00081 pres->res_nlm4share.stat = NLM4_FAILED; 00082 LogDebug(COMPONENT_NLM, "REQUEST RESULT: nlm4_Share %s", 00083 lock_result_str(pres->res_nlm4share.stat)); 00084 return NFS_REQ_OK; 00085 } 00086 00087 /* Allow only reclaim share request during recovery and visa versa. 00088 * Note: NLM_SHARE is indicated to be non-monitored, however, it does 00089 * have a reclaim flag, so we will honor the reclaim flag if used. 00090 */ 00091 if((grace && !arg->reclaim) || 00092 (!grace && arg->reclaim)) 00093 { 00094 pres->res_nlm4share.stat = NLM4_DENIED_GRACE_PERIOD; 00095 LogDebug(COMPONENT_NLM, "REQUEST RESULT: nlm4_Share %s", 00096 lock_result_str(pres->res_nlm4share.stat)); 00097 return NFS_REQ_OK; 00098 } 00099 00100 rc = nlm_process_share_parms(preq, 00101 &arg->share, 00102 &pentry, 00103 pcontext, 00104 CARE_NO_MONITOR, 00105 &nsm_client, 00106 &nlm_client, 00107 &nlm_owner); 00108 00109 if(rc >= 0) 00110 { 00111 /* Present the error back to the client */ 00112 pres->res_nlm4share.stat = (nlm4_stats)rc; 00113 LogDebug(COMPONENT_NLM, "REQUEST RESULT: nlm4_Share %s", 00114 lock_result_str(pres->res_nlm4share.stat)); 00115 return NFS_REQ_OK; 00116 } 00117 00118 if(state_nlm_share(pentry, 00119 pcontext, 00120 pexport, 00121 arg->share.access, 00122 arg->share.mode, 00123 nlm_owner, 00124 &state_status) != STATE_SUCCESS) 00125 { 00126 pres->res_nlm4share.stat = nlm_convert_state_error(state_status); 00127 } 00128 else 00129 { 00130 pres->res_nlm4share.stat = NLM4_GRANTED; 00131 } 00132 00133 /* Release the NLM Client and NLM Owner references we have */ 00134 dec_nsm_client_ref(nsm_client); 00135 dec_nlm_client_ref(nlm_client); 00136 dec_state_owner_ref(nlm_owner); 00137 cache_inode_put(pentry); 00138 00139 LogDebug(COMPONENT_NLM, "REQUEST RESULT: nlm4_Share %s", 00140 lock_result_str(pres->res_nlm4share.stat)); 00141 return NFS_REQ_OK; 00142 } 00143 00152 void nlm4_Share_Free(nfs_res_t * pres) 00153 { 00154 netobj_free(&pres->res_nlm4share.cookie); 00155 return; 00156 }