summaryrefslogtreecommitdiff
path: root/security/keys/key.c
diff options
context:
space:
mode:
authorBryan Schumaker <bjschuma@netapp.com>2012-02-24 14:14:50 -0500
committerTrond Myklebust <Trond.Myklebust@netapp.com>2012-03-01 16:50:31 -0500
commit59e6b9c11341e3b8ac5925427c903d4eae435bd8 (patch)
tree68b39f847badedfca1476fbbf7ef6049a444f493 /security/keys/key.c
parent0cb3284b535bd5eacc287632b55150c8e5d9edc7 (diff)
Created a function for setting timeouts on keys
The keyctl_set_timeout function isn't exported to other parts of the kernel, but I want to use it for the NFS idmapper. I already have the key, but I wanted a generic way to set the timeout. Signed-off-by: Bryan Schumaker <bjschuma@netapp.com> Acked-by: David Howells <dhowells@redhat.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'security/keys/key.c')
-rw-r--r--security/keys/key.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/security/keys/key.c b/security/keys/key.c
index 7ada8019be1f..06783cffb3af 100644
--- a/security/keys/key.c
+++ b/security/keys/key.c
@@ -671,6 +671,26 @@ found_kernel_type:
return ktype;
}
+void key_set_timeout(struct key *key, unsigned timeout)
+{
+ struct timespec now;
+ time_t expiry = 0;
+
+ /* make the changes with the locks held to prevent races */
+ down_write(&key->sem);
+
+ if (timeout > 0) {
+ now = current_kernel_time();
+ expiry = now.tv_sec + timeout;
+ }
+
+ key->expiry = expiry;
+ key_schedule_gc(key->expiry + key_gc_delay);
+
+ up_write(&key->sem);
+}
+EXPORT_SYMBOL_GPL(key_set_timeout);
+
/*
* Unlock a key type locked by key_type_lookup().
*/