nfs-ganesha 1.4

nlm_Unshare.c

Go to the documentation of this file.
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_Unshare(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_Unshare 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_Unshare %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    * This is a little more bizare for UNSHARE, but, we'll still honor
00091    * the reclaim flag.
00092    */
00093   if((grace && !arg->reclaim) ||
00094      (!grace && arg->reclaim))
00095     {
00096       pres->res_nlm4share.stat = NLM4_DENIED_GRACE_PERIOD;
00097       LogDebug(COMPONENT_NLM, "REQUEST RESULT: nlm4_Unshare %s",
00098                lock_result_str(pres->res_nlm4share.stat));
00099       return NFS_REQ_OK;
00100     }
00101 
00102   rc = nlm_process_share_parms(preq,
00103                                &arg->share,
00104                                &pentry,
00105                                pcontext,
00106                                CARE_NOT,
00107                                &nsm_client,
00108                                &nlm_client,
00109                                &nlm_owner);
00110 
00111   if(rc >= 0)
00112     {
00113       /* Present the error back to the client */
00114       pres->res_nlm4share.stat = (nlm4_stats)rc;
00115       LogDebug(COMPONENT_NLM, "REQUEST RESULT: nlm4_Unshare %s",
00116                lock_result_str(pres->res_nlm4share.stat));
00117       return NFS_REQ_OK;
00118     }
00119 
00120   if(state_nlm_unshare(pentry,
00121                        pcontext,
00122                        arg->share.access,
00123                        arg->share.mode,
00124                        nlm_owner,
00125                        &state_status) != STATE_SUCCESS)
00126     {
00127       pres->res_nlm4share.stat = nlm_convert_state_error(state_status);
00128     }
00129   else
00130     {
00131       pres->res_nlm4share.stat = NLM4_GRANTED;
00132     }
00133 
00134   /* Release the NLM Client and NLM Owner references we have */
00135   dec_nsm_client_ref(nsm_client);
00136   dec_nlm_client_ref(nlm_client);
00137   dec_state_owner_ref(nlm_owner);
00138   cache_inode_put(pentry);
00139 
00140   LogDebug(COMPONENT_NLM, "REQUEST RESULT: nlm4_Unshare %s",
00141            lock_result_str(pres->res_nlm4share.stat));
00142   return NFS_REQ_OK;
00143 }
00144 
00153 void nlm4_Unshare_Free(nfs_res_t * pres)
00154 {
00155   netobj_free(&pres->res_nlm4share.cookie);
00156   return;
00157 }