]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
fs: nfs: Make nfs boot time y2038 safe
authorDeepa Dinamani <deepa.kernel@gmail.com>
Sat, 1 Oct 2016 23:46:26 +0000 (16:46 -0700)
committerAnna Schumaker <Anna.Schumaker@Netapp.com>
Tue, 4 Oct 2016 20:20:26 +0000 (16:20 -0400)
boot_time is represented as a struct timespec.
struct timespec and CURRENT_TIME are not y2038 safe.
Overall, the plan is to use timespec64 and ktime_t for
all internal kernel representation of timestamps.
CURRENT_TIME will also be removed.

boot_time is used to construct the nfs client boot verifier.

Use ktime_t to represent boot_time and ktime_get_real() for
the boot_time value.

Following Trond's request https://lkml.org/lkml/2016/6/9/22 ,
use ktime_t instead of converting to struct timespec64.

Use higher and lower 32 bit parts of ktime_t for the boot
verifier.

Use the lower 32 bit part of ktime_t for the authsys_parms
stamp field.

Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Cc: Trond Myklebust <trond.myklebust@primarydata.com>
Cc: Anna Schumaker <anna.schumaker@netapp.com>
Cc: linux-nfs@vger.kernel.org
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
fs/nfs/client.c
fs/nfs/netns.h
fs/nfs/nfs4proc.c
fs/nfs/nfs4xdr.c

index 51136b03788d6a65885716f04f508befcc69eb05..7555ba889d1fce916cc96b8f23c03ad4d6037366 100644 (file)
@@ -1082,7 +1082,7 @@ void nfs_clients_init(struct net *net)
        idr_init(&nn->cb_ident_idr);
 #endif
        spin_lock_init(&nn->nfs_client_lock);
-       nn->boot_time = CURRENT_TIME;
+       nn->boot_time = ktime_get_real();
 }
 
 #ifdef CONFIG_PROC_FS
index f0e06e4acbef188988547eb4d8bf66178e6d3183..fbce0d885d4c2dc77bb98f604ec881175e945eb7 100644 (file)
@@ -29,7 +29,7 @@ struct nfs_net {
        int cb_users[NFS4_MAX_MINOR_VERSION + 1];
 #endif
        spinlock_t nfs_client_lock;
-       struct timespec boot_time;
+       ktime_t boot_time;
 #ifdef CONFIG_PROC_FS
        struct proc_dir_entry *proc_nfsfs;
 #endif
index 8b30cdf41848a71e7b1eaceee003eb4b31bfdff1..ed7da820d4bfdba1c5ca6237c51fd5aaa50a9544 100644 (file)
@@ -5299,12 +5299,14 @@ static void nfs4_init_boot_verifier(const struct nfs_client *clp,
        if (test_bit(NFS4CLNT_PURGE_STATE, &clp->cl_state)) {
                /* An impossible timestamp guarantees this value
                 * will never match a generated boot time. */
-               verf[0] = 0;
-               verf[1] = cpu_to_be32(NSEC_PER_SEC + 1);
+               verf[0] = cpu_to_be32(U32_MAX);
+               verf[1] = cpu_to_be32(U32_MAX);
        } else {
                struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
-               verf[0] = cpu_to_be32(nn->boot_time.tv_sec);
-               verf[1] = cpu_to_be32(nn->boot_time.tv_nsec);
+               u64 ns = ktime_to_ns(nn->boot_time);
+
+               verf[0] = cpu_to_be32(ns >> 32);
+               verf[1] = cpu_to_be32(ns);
        }
        memcpy(bootverf->data, verf, sizeof(bootverf->data));
 }
index 17b4e059c588f727388d705532d4b3a2e1e83b6e..fc89e5ed07eec90f1a0ef12134c9e29a693ee209 100644 (file)
@@ -1850,7 +1850,7 @@ static void encode_create_session(struct xdr_stream *xdr,
        *p++ = cpu_to_be32(RPC_AUTH_UNIX);                      /* auth_sys */
 
        /* authsys_parms rfc1831 */
-       *p++ = cpu_to_be32(nn->boot_time.tv_nsec);      /* stamp */
+       *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */
        p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
        *p++ = cpu_to_be32(0);                          /* UID */
        *p++ = cpu_to_be32(0);                          /* GID */