nfs-ganesha 1.4

nfs4_op_release_lockowner.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 "sal_functions.h"
00059 #include "cache_inode.h"
00060 #include "nfs_exports.h"
00061 #include "nfs_creds.h"
00062 #include "nfs_proto_functions.h"
00063 #include "nfs_tools.h"
00064 
00077 #define arg_RELEASE_LOCKOWNER4 op->nfs_argop4_u.oprelease_lockowner
00078 #define res_RELEASE_LOCKOWNER4 resp->nfs_resop4_u.oprelease_lockowner
00079 
00080 int nfs4_op_release_lockowner(struct nfs_argop4 * op,
00081                               compound_data_t   * data,
00082                               struct nfs_resop4 * resp)
00083 {
00084   nfs_client_id_t         * pnfs_client_id;
00085   state_owner_t           * plock_owner;
00086   state_nfs4_owner_name_t   owner_name;
00087 
00088   LogDebug(COMPONENT_NFS_V4_LOCK,
00089            "Entering NFS v4 RELEASE_LOCKOWNER handler -----------------------------------------------------");
00090 
00091   resp->resop = NFS4_OP_RELEASE_LOCKOWNER;
00092   res_RELEASE_LOCKOWNER4.status = NFS4_OK;
00093 
00094   /* Check clientid */
00095   if(nfs_client_id_get_confirmed(arg_RELEASE_LOCKOWNER4.lock_owner.clientid,
00096                                  &pnfs_client_id) != CLIENT_ID_SUCCESS)
00097     {
00098       res_RELEASE_LOCKOWNER4.status = NFS4ERR_STALE_CLIENTID;
00099       goto out2;
00100     }
00101 
00102   /* The protocol doesn't allow for EXPIRED, so return STALE_CLIENTID */
00103   P(pnfs_client_id->cid_mutex);
00104 
00105   if(!reserve_lease(pnfs_client_id))
00106     {
00107       V(pnfs_client_id->cid_mutex);
00108 
00109       dec_client_id_ref(pnfs_client_id);
00110 
00111       res_RELEASE_LOCKOWNER4.status = NFS4ERR_STALE_CLIENTID;
00112       goto out2;
00113     }
00114 
00115   V(pnfs_client_id->cid_mutex);
00116 
00117   /* look up the lock owner and see if we can find it */
00118   convert_nfs4_lock_owner(&arg_RELEASE_LOCKOWNER4.lock_owner, &owner_name, 0LL);
00119 
00120   if(!nfs4_owner_Get_Pointer(&owner_name, &plock_owner))
00121     {
00122       /* the owner doesn't exist, we are done */
00123       LogDebug(COMPONENT_NFS_V4_LOCK,
00124                "lock owner does not exist");
00125       res_RELEASE_LOCKOWNER4.status = NFS4_OK;
00126       goto out1;
00127     }
00128 
00129   /* got the owner, does it still have any locks being held */
00130   if(!glist_empty(&plock_owner->so_lock_list))
00131     {
00132       res_RELEASE_LOCKOWNER4.status = NFS4ERR_LOCKS_HELD;
00133     }
00134   else
00135     {
00136       /* found the lock owner and it doesn't have any locks, release it */
00137       release_lockstate(plock_owner);
00138 
00139       res_RELEASE_LOCKOWNER4.status = NFS4_OK;
00140     }
00141 
00142   /* Release the reference to the lock owner acquired via
00143      nfs4_owner_Get_Pointer */
00144   dec_state_owner_ref(plock_owner);
00145 
00146  out1:
00147 
00148   /* Update the lease before exit */
00149   P(pnfs_client_id->cid_mutex);
00150 
00151   update_lease(pnfs_client_id);
00152 
00153   V(pnfs_client_id->cid_mutex);
00154 
00155   dec_client_id_ref(pnfs_client_id);
00156 
00157  out2:
00158 
00159   LogDebug(COMPONENT_NFS_V4_LOCK,
00160            "Leaving NFS v4 RELEASE_LOCKOWNER handler -----------------------------------------------------");
00161 
00162   return res_RELEASE_LOCKOWNER4.status;
00163 }                               /* nfs4_op_release_lock_owner */
00164 
00175 void nfs4_op_release_lockowner_Free(RELEASE_LOCKOWNER4res * resp)
00176 {
00177   /* Nothing to be done */
00178   return;
00179 }                               /* nfs4_op_release_lockowner_Free */