Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

nfds: avoid gettimeofday for nfssvc_boot time

do_gettimeofday() is deprecated and we should generally use time64_t
based functions instead.

In case of nfsd, all three users of nfssvc_boot only use the initial
time as a unique token, and are not affected by it overflowing, so they
are not affected by the y2038 overflow.

This converts the structure to timespec64 anyway and adds comments
to all uses, to document that we have thought about it and avoid
having to look at it again.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>

authored by

Arnd Bergmann and committed by
J. Bruce Fields
256a89fa 818a34eb

+11 -8
+1 -1
fs/nfsd/netns.h
··· 107 107 bool lockd_up; 108 108 109 109 /* Time of server startup */ 110 - struct timeval nfssvc_boot; 110 + struct timespec64 nfssvc_boot; 111 111 112 112 /* 113 113 * Max number of connections this nfsd container will allow. Defaults
+6 -4
fs/nfsd/nfs3xdr.c
··· 747 747 if (resp->status == 0) { 748 748 *p++ = htonl(resp->count); 749 749 *p++ = htonl(resp->committed); 750 - *p++ = htonl(nn->nfssvc_boot.tv_sec); 751 - *p++ = htonl(nn->nfssvc_boot.tv_usec); 750 + /* unique identifier, y2038 overflow can be ignored */ 751 + *p++ = htonl((u32)nn->nfssvc_boot.tv_sec); 752 + *p++ = htonl(nn->nfssvc_boot.tv_nsec); 752 753 } 753 754 return xdr_ressize_check(rqstp, p); 754 755 } ··· 1119 1118 p = encode_wcc_data(rqstp, p, &resp->fh); 1120 1119 /* Write verifier */ 1121 1120 if (resp->status == 0) { 1122 - *p++ = htonl(nn->nfssvc_boot.tv_sec); 1123 - *p++ = htonl(nn->nfssvc_boot.tv_usec); 1121 + /* unique identifier, y2038 overflow can be ignored */ 1122 + *p++ = htonl((u32)nn->nfssvc_boot.tv_sec); 1123 + *p++ = htonl(nn->nfssvc_boot.tv_nsec); 1124 1124 } 1125 1125 return xdr_ressize_check(rqstp, p); 1126 1126 }
+3 -2
fs/nfsd/nfs4proc.c
··· 564 564 565 565 /* 566 566 * This is opaque to client, so no need to byte-swap. Use 567 - * __force to keep sparse happy 567 + * __force to keep sparse happy. y2038 time_t overflow is 568 + * irrelevant in this usage. 568 569 */ 569 570 verf[0] = (__force __be32)nn->nfssvc_boot.tv_sec; 570 - verf[1] = (__force __be32)nn->nfssvc_boot.tv_usec; 571 + verf[1] = (__force __be32)nn->nfssvc_boot.tv_nsec; 571 572 memcpy(verifier->data, verf, sizeof(verifier->data)); 572 573 } 573 574
+1 -1
fs/nfsd/nfssvc.c
··· 516 516 register_inet6addr_notifier(&nfsd_inet6addr_notifier); 517 517 #endif 518 518 } 519 - do_gettimeofday(&nn->nfssvc_boot); /* record boot time */ 519 + ktime_get_real_ts64(&nn->nfssvc_boot); /* record boot time */ 520 520 return 0; 521 521 } 522 522