nfs-ganesha 1.4

nfs4_lease.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 
00040 #ifdef HAVE_CONFIG_H
00041 #include "config.h"
00042 #endif
00043 
00044 #ifdef _SOLARIS
00045 #include "solaris_port.h"
00046 #endif
00047 
00048 #include "log.h"
00049 #include "nfs_core.h"
00050 #include "nfs4.h"
00051 #include "sal_functions.h"
00052 
00053 static unsigned int _valid_lease(nfs_client_id_t * pclientid)
00054 {
00055   time_t t;
00056 
00057   if(pclientid->cid_confirmed == EXPIRED_CLIENT_ID)
00058     return 0;
00059 
00060   if(pclientid->cid_lease_reservations != 0)
00061     return nfs_param.nfsv4_param.lease_lifetime;
00062 
00063   t = time(NULL);
00064 
00065   if(pclientid->cid_last_renew + nfs_param.nfsv4_param.lease_lifetime > t)
00066     return (pclientid->cid_last_renew + nfs_param.nfsv4_param.lease_lifetime) - t;
00067 
00068   return 0;
00069 }
00070 
00082 int valid_lease(nfs_client_id_t * pclientid)
00083 {
00084   unsigned int valid;
00085 
00086   valid = _valid_lease(pclientid);
00087 
00088   if(isFullDebug(COMPONENT_CLIENTID))
00089     {
00090       char str[HASHTABLE_DISPLAY_STRLEN];
00091 
00092       display_client_id_rec(pclientid, str);
00093       LogFullDebug(COMPONENT_CLIENTID,
00094                    "Check Lease %s (Valid=%s %u seconds left)",
00095                    str, valid ? "YES" : "NO", valid);
00096     }
00097 
00098   return valid != 0;
00099 }
00100 
00115 int reserve_lease(nfs_client_id_t * pclientid)
00116 {
00117   unsigned int valid;
00118 
00119   valid = _valid_lease(pclientid);
00120 
00121   if(valid != 0)
00122     pclientid->cid_lease_reservations++;
00123 
00124   if(isFullDebug(COMPONENT_CLIENTID))
00125     {
00126       char str[HASHTABLE_DISPLAY_STRLEN];
00127 
00128       display_client_id_rec(pclientid, str);
00129       LogFullDebug(COMPONENT_CLIENTID,
00130                    "Reserve Lease %s (Valid=%s %u seconds left)",
00131                    str, valid ? "YES" : "NO", valid);
00132     }
00133 
00134   return valid != 0;
00135 }
00136 
00152 void update_lease(nfs_client_id_t * pclientid)
00153 {
00154   pclientid->cid_lease_reservations--;
00155 
00156   /* Renew lease when last reservation is released */
00157   if(pclientid->cid_lease_reservations == 0)
00158     pclientid->cid_last_renew = time(NULL);
00159 
00160   if(isFullDebug(COMPONENT_CLIENTID))
00161     {
00162       char str[HASHTABLE_DISPLAY_STRLEN];
00163 
00164       display_client_id_rec(pclientid, str);
00165       LogFullDebug(COMPONENT_CLIENTID,
00166                    "Update Lease %s",
00167                    str);
00168     }
00169 }