nfs-ganesha 1.4
|
00001 /* 00002 * Copyright IBM Corporation, 2010 00003 * Contributor: Aneesh Kumar K.v <aneesh.kumar@linux.vnet.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 License 00009 * as published by the Free Software Foundation; either version 3 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, but 00013 * 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 00020 * 02110-1301 USA 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 "log.h" 00036 #include "ganesha_rpc.h" 00037 #include "nlm4.h" 00038 #include "sal_functions.h" 00039 #include "nlm_util.h" 00040 #include "nlm_async.h" 00041 00053 int nlm4_Unlock(nfs_arg_t *parg, 00054 exportlist_t *pexport, 00055 fsal_op_context_t *pcontext, 00056 nfs_worker_data_t *pworker, 00057 struct svc_req *preq, 00058 nfs_res_t *pres) 00059 { 00060 nlm4_unlockargs * arg = &parg->arg_nlm4_unlock; 00061 cache_entry_t * pentry; 00062 state_status_t state_status = STATE_SUCCESS; 00063 char buffer[MAXNETOBJ_SZ * 2]; 00064 state_nsm_client_t * nsm_client; 00065 state_nlm_client_t * nlm_client; 00066 state_owner_t * nlm_owner; 00067 fsal_lock_param_t lock; 00068 int rc; 00069 00070 netobj_to_string(&arg->cookie, buffer, sizeof(buffer)); 00071 LogDebug(COMPONENT_NLM, 00072 "REQUEST PROCESSING: Calling nlm4_Unlock svid=%d off=%llx len=%llx cookie=%s", 00073 (int) arg->alock.svid, 00074 (unsigned long long) arg->alock.l_offset, 00075 (unsigned long long) arg->alock.l_len, 00076 buffer); 00077 00078 if(!copy_netobj(&pres->res_nlm4test.cookie, &arg->cookie)) 00079 { 00080 pres->res_nlm4.stat.stat = NLM4_FAILED; 00081 LogDebug(COMPONENT_NLM, "REQUEST RESULT: nlm4_Unlock %s", 00082 lock_result_str(pres->res_nlm4.stat.stat)); 00083 return NFS_REQ_OK; 00084 } 00085 00086 00087 if(nfs_in_grace()) 00088 { 00089 pres->res_nlm4.stat.stat = NLM4_DENIED_GRACE_PERIOD; 00090 LogDebug(COMPONENT_NLM, "REQUEST RESULT: nlm4_Unlock %s", 00091 lock_result_str(pres->res_nlm4.stat.stat)); 00092 return NFS_REQ_OK; 00093 } 00094 00095 rc = nlm_process_parameters(preq, 00096 FALSE, /* exlcusive doesn't matter */ 00097 &arg->alock, 00098 &lock, 00099 &pentry, 00100 pcontext, 00101 CARE_NOT, /* unlock doesn't care if owner is found */ 00102 &nsm_client, 00103 &nlm_client, 00104 &nlm_owner, 00105 NULL); 00106 00107 if(rc >= 0) 00108 { 00109 /* Present the error back to the client */ 00110 pres->res_nlm4.stat.stat = (nlm4_stats)rc; 00111 LogDebug(COMPONENT_NLM, "REQUEST RESULT: nlm4_Unlock %s", 00112 lock_result_str(pres->res_nlm4.stat.stat)); 00113 return NFS_REQ_OK; 00114 } 00115 00116 if(state_unlock(pentry, 00117 pcontext, 00118 pexport, 00119 nlm_owner, 00120 NULL, 00121 &lock, 00122 &state_status) != STATE_SUCCESS) 00123 { 00124 /* Unlock could fail in the FSAL and make a bit of a mess, especially if 00125 * we are in out of memory situation. Such an error is logged by 00126 * Cache Inode. 00127 */ 00128 pres->res_nlm4test.test_stat.stat = nlm_convert_state_error(state_status); 00129 } 00130 else 00131 { 00132 pres->res_nlm4.stat.stat = NLM4_GRANTED; 00133 } 00134 00135 /* Release the NLM Client and NLM Owner references we have */ 00136 dec_nsm_client_ref(nsm_client); 00137 dec_nlm_client_ref(nlm_client); 00138 dec_state_owner_ref(nlm_owner); 00139 cache_inode_put(pentry); 00140 00141 LogDebug(COMPONENT_NLM, "REQUEST RESULT: nlm4_Unlock %s", 00142 lock_result_str(pres->res_nlm4.stat.stat)); 00143 return NFS_REQ_OK; 00144 } 00145 00146 static void nlm4_unlock_message_resp(state_async_queue_t *arg) 00147 { 00148 state_nlm_async_data_t * nlm_arg = &arg->state_async_data.state_nlm_async_data; 00149 00150 if(isFullDebug(COMPONENT_NLM)) 00151 { 00152 char buffer[1024]; 00153 netobj_to_string(&nlm_arg->nlm_async_args.nlm_async_res.res_nlm4test.cookie, buffer, 1024); 00154 LogFullDebug(COMPONENT_NLM, 00155 "Calling nlm_send_async cookie=%s status=%s", 00156 buffer, lock_result_str(nlm_arg->nlm_async_args.nlm_async_res.res_nlm4.stat.stat)); 00157 } 00158 nlm_send_async(NLMPROC4_UNLOCK_RES, 00159 nlm_arg->nlm_async_host, 00160 &(nlm_arg->nlm_async_args.nlm_async_res), 00161 NULL); 00162 nlm4_Unlock_Free(&nlm_arg->nlm_async_args.nlm_async_res); 00163 dec_nsm_client_ref(nlm_arg->nlm_async_host->slc_nsm_client); 00164 dec_nlm_client_ref(nlm_arg->nlm_async_host); 00165 gsh_free(arg); 00166 } 00167 00179 int nlm4_Unlock_Message(nfs_arg_t *parg, 00180 exportlist_t *pexport, 00181 fsal_op_context_t *pcontext, 00182 nfs_worker_data_t *pworker, 00183 struct svc_req *preq, 00184 nfs_res_t *pres) 00185 { 00186 state_nlm_client_t * nlm_client = NULL; 00187 state_nsm_client_t * nsm_client; 00188 nlm4_unlockargs * arg = &parg->arg_nlm4_unlock; 00189 int rc = NFS_REQ_OK; 00190 00191 LogDebug(COMPONENT_NLM, "REQUEST PROCESSING: Calling nlm_Unlock_Message"); 00192 00193 nsm_client = get_nsm_client(CARE_NO_MONITOR, preq->rq_xprt, arg->alock.caller_name); 00194 00195 if(nsm_client != NULL) 00196 nlm_client = get_nlm_client(CARE_NO_MONITOR, preq->rq_xprt, nsm_client, arg->alock.caller_name); 00197 00198 if(nlm_client == NULL) 00199 rc = NFS_REQ_DROP; 00200 else 00201 rc = nlm4_Unlock(parg, pexport, pcontext, pworker, preq, pres); 00202 00203 if(rc == NFS_REQ_OK) 00204 rc = nlm_send_async_res_nlm4(nlm_client, nlm4_unlock_message_resp, pres); 00205 00206 if(rc == NFS_REQ_DROP) 00207 { 00208 if(nsm_client != NULL) 00209 dec_nsm_client_ref(nsm_client); 00210 if(nlm_client != NULL) 00211 dec_nlm_client_ref(nlm_client); 00212 LogCrit(COMPONENT_NLM, 00213 "Could not send async response for nlm_Unlock_Message"); 00214 } 00215 00216 return NFS_REQ_DROP; 00217 } 00218 00227 void nlm4_Unlock_Free(nfs_res_t * pres) 00228 { 00229 netobj_free(&pres->res_nlm4test.cookie); 00230 return; 00231 }