summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2018-07-13 16:18:34 -0400
committerIlya Dryomov <idryomov@gmail.com>2018-08-02 15:26:12 -0400
commit473bd2d780d1699d81b25f57c0ec4de633a28eb8 (patch)
tree5e7a5a05d3682c1c3e09704263051da78e122c8b
parent67fcd151400242757edbab710402161b2cd38989 (diff)
libceph: use timespec64 in for keepalive2 and ticket validity
ceph_con_keepalive_expired() is the last user of timespec_add() and some of the last uses of ktime_get_real_ts(). Replacing this with timespec64 based interfaces lets us remove that deprecated API. I'm introducing new ceph_encode_timespec64()/ceph_decode_timespec64() here that take timespec64 structures and convert to/from ceph_timespec, which is defined to have an unsigned 32-bit tv_sec member. This extends the range of valid times to year 2106, avoiding the year 2038 overflow. The ceph file system portion still uses the old functions for inode timestamps, this will be done separately after the VFS layer is converted. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Reviewed-by: Ilya Dryomov <idryomov@gmail.com> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
-rw-r--r--include/linux/ceph/decode.h20
-rw-r--r--include/linux/ceph/messenger.h2
-rw-r--r--net/ceph/auth_x.c14
-rw-r--r--net/ceph/auth_x.h2
-rw-r--r--net/ceph/cls_lock_client.c4
-rw-r--r--net/ceph/messenger.c20
6 files changed, 40 insertions, 22 deletions
diff --git a/include/linux/ceph/decode.h b/include/linux/ceph/decode.h
index d143ac8879c6..094b9b4a34f3 100644
--- a/include/linux/ceph/decode.h
+++ b/include/linux/ceph/decode.h
@@ -194,8 +194,26 @@ ceph_decode_skip_n(p, end, sizeof(u8), bad)
194 } while (0) 194 } while (0)
195 195
196/* 196/*
197 * struct ceph_timespec <-> struct timespec 197 * struct ceph_timespec <-> struct timespec64
198 */ 198 */
199static inline void ceph_decode_timespec64(struct timespec64 *ts,
200 const struct ceph_timespec *tv)
201{
202 /*
203 * This will still overflow in year 2106. We could extend
204 * the protocol to steal two more bits from tv_nsec to
205 * add three more 136 year epochs after that the way ext4
206 * does if necessary.
207 */
208 ts->tv_sec = (time64_t)le32_to_cpu(tv->tv_sec);
209 ts->tv_nsec = (long)le32_to_cpu(tv->tv_nsec);
210}
211static inline void ceph_encode_timespec64(struct ceph_timespec *tv,
212 const struct timespec64 *ts)
213{
214 tv->tv_sec = cpu_to_le32((u32)ts->tv_sec);
215 tv->tv_nsec = cpu_to_le32((u32)ts->tv_nsec);
216}
199static inline void ceph_decode_timespec(struct timespec *ts, 217static inline void ceph_decode_timespec(struct timespec *ts,
200 const struct ceph_timespec *tv) 218 const struct ceph_timespec *tv)
201{ 219{
diff --git a/include/linux/ceph/messenger.h b/include/linux/ceph/messenger.h
index c7dfcb8a1fb2..a718b877c597 100644
--- a/include/linux/ceph/messenger.h
+++ b/include/linux/ceph/messenger.h
@@ -330,7 +330,7 @@ struct ceph_connection {
330 int in_base_pos; /* bytes read */ 330 int in_base_pos; /* bytes read */
331 __le64 in_temp_ack; /* for reading an ack */ 331 __le64 in_temp_ack; /* for reading an ack */
332 332
333 struct timespec last_keepalive_ack; /* keepalive2 ack stamp */ 333 struct timespec64 last_keepalive_ack; /* keepalive2 ack stamp */
334 334
335 struct delayed_work work; /* send|recv work */ 335 struct delayed_work work; /* send|recv work */
336 unsigned long delay; /* current delay interval */ 336 unsigned long delay; /* current delay interval */
diff --git a/net/ceph/auth_x.c b/net/ceph/auth_x.c
index 2f4a1baf5f52..b05c3a540a5a 100644
--- a/net/ceph/auth_x.c
+++ b/net/ceph/auth_x.c
@@ -149,12 +149,12 @@ static int process_one_ticket(struct ceph_auth_client *ac,
149 void *dp, *dend; 149 void *dp, *dend;
150 int dlen; 150 int dlen;
151 char is_enc; 151 char is_enc;
152 struct timespec validity; 152 struct timespec64 validity;
153 void *tp, *tpend; 153 void *tp, *tpend;
154 void **ptp; 154 void **ptp;
155 struct ceph_crypto_key new_session_key = { 0 }; 155 struct ceph_crypto_key new_session_key = { 0 };
156 struct ceph_buffer *new_ticket_blob; 156 struct ceph_buffer *new_ticket_blob;
157 unsigned long new_expires, new_renew_after; 157 time64_t new_expires, new_renew_after;
158 u64 new_secret_id; 158 u64 new_secret_id;
159 int ret; 159 int ret;
160 160
@@ -189,11 +189,11 @@ static int process_one_ticket(struct ceph_auth_client *ac,
189 if (ret) 189 if (ret)
190 goto out; 190 goto out;
191 191
192 ceph_decode_timespec(&validity, dp); 192 ceph_decode_timespec64(&validity, dp);
193 dp += sizeof(struct ceph_timespec); 193 dp += sizeof(struct ceph_timespec);
194 new_expires = get_seconds() + validity.tv_sec; 194 new_expires = ktime_get_real_seconds() + validity.tv_sec;
195 new_renew_after = new_expires - (validity.tv_sec / 4); 195 new_renew_after = new_expires - (validity.tv_sec / 4);
196 dout(" expires=%lu renew_after=%lu\n", new_expires, 196 dout(" expires=%llu renew_after=%llu\n", new_expires,
197 new_renew_after); 197 new_renew_after);
198 198
199 /* ticket blob for service */ 199 /* ticket blob for service */
@@ -385,13 +385,13 @@ static bool need_key(struct ceph_x_ticket_handler *th)
385 if (!th->have_key) 385 if (!th->have_key)
386 return true; 386 return true;
387 387
388 return get_seconds() >= th->renew_after; 388 return ktime_get_real_seconds() >= th->renew_after;
389} 389}
390 390
391static bool have_key(struct ceph_x_ticket_handler *th) 391static bool have_key(struct ceph_x_ticket_handler *th)
392{ 392{
393 if (th->have_key) { 393 if (th->have_key) {
394 if (get_seconds() >= th->expires) 394 if (ktime_get_real_seconds() >= th->expires)
395 th->have_key = false; 395 th->have_key = false;
396 } 396 }
397 397
diff --git a/net/ceph/auth_x.h b/net/ceph/auth_x.h
index 454cb54568af..57ba99f7736f 100644
--- a/net/ceph/auth_x.h
+++ b/net/ceph/auth_x.h
@@ -22,7 +22,7 @@ struct ceph_x_ticket_handler {
22 u64 secret_id; 22 u64 secret_id;
23 struct ceph_buffer *ticket_blob; 23 struct ceph_buffer *ticket_blob;
24 24
25 unsigned long renew_after, expires; 25 time64_t renew_after, expires;
26}; 26};
27 27
28#define CEPHX_AU_ENC_BUF_LEN 128 /* big enough for encrypted blob */ 28#define CEPHX_AU_ENC_BUF_LEN 128 /* big enough for encrypted blob */
diff --git a/net/ceph/cls_lock_client.c b/net/ceph/cls_lock_client.c
index 8d2032b2f225..2105a6eaa66c 100644
--- a/net/ceph/cls_lock_client.c
+++ b/net/ceph/cls_lock_client.c
@@ -32,7 +32,7 @@ int ceph_cls_lock(struct ceph_osd_client *osdc,
32 int desc_len = strlen(desc); 32 int desc_len = strlen(desc);
33 void *p, *end; 33 void *p, *end;
34 struct page *lock_op_page; 34 struct page *lock_op_page;
35 struct timespec mtime; 35 struct timespec64 mtime;
36 int ret; 36 int ret;
37 37
38 lock_op_buf_size = name_len + sizeof(__le32) + 38 lock_op_buf_size = name_len + sizeof(__le32) +
@@ -63,7 +63,7 @@ int ceph_cls_lock(struct ceph_osd_client *osdc,
63 ceph_encode_string(&p, end, desc, desc_len); 63 ceph_encode_string(&p, end, desc, desc_len);
64 /* only support infinite duration */ 64 /* only support infinite duration */
65 memset(&mtime, 0, sizeof(mtime)); 65 memset(&mtime, 0, sizeof(mtime));
66 ceph_encode_timespec(p, &mtime); 66 ceph_encode_timespec64(p, &mtime);
67 p += sizeof(struct ceph_timespec); 67 p += sizeof(struct ceph_timespec);
68 ceph_encode_8(&p, flags); 68 ceph_encode_8(&p, flags);
69 69
diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index c6413c360771..3f6336248509 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -1417,11 +1417,11 @@ static void prepare_write_keepalive(struct ceph_connection *con)
1417 dout("prepare_write_keepalive %p\n", con); 1417 dout("prepare_write_keepalive %p\n", con);
1418 con_out_kvec_reset(con); 1418 con_out_kvec_reset(con);
1419 if (con->peer_features & CEPH_FEATURE_MSGR_KEEPALIVE2) { 1419 if (con->peer_features & CEPH_FEATURE_MSGR_KEEPALIVE2) {
1420 struct timespec now; 1420 struct timespec64 now;
1421 1421
1422 ktime_get_real_ts(&now); 1422 ktime_get_real_ts64(&now);
1423 con_out_kvec_add(con, sizeof(tag_keepalive2), &tag_keepalive2); 1423 con_out_kvec_add(con, sizeof(tag_keepalive2), &tag_keepalive2);
1424 ceph_encode_timespec(&con->out_temp_keepalive2, &now); 1424 ceph_encode_timespec64(&con->out_temp_keepalive2, &now);
1425 con_out_kvec_add(con, sizeof(con->out_temp_keepalive2), 1425 con_out_kvec_add(con, sizeof(con->out_temp_keepalive2),
1426 &con->out_temp_keepalive2); 1426 &con->out_temp_keepalive2);
1427 } else { 1427 } else {
@@ -2555,7 +2555,7 @@ static int read_keepalive_ack(struct ceph_connection *con)
2555 int ret = read_partial(con, size, size, &ceph_ts); 2555 int ret = read_partial(con, size, size, &ceph_ts);
2556 if (ret <= 0) 2556 if (ret <= 0)
2557 return ret; 2557 return ret;
2558 ceph_decode_timespec(&con->last_keepalive_ack, &ceph_ts); 2558 ceph_decode_timespec64(&con->last_keepalive_ack, &ceph_ts);
2559 prepare_read_tag(con); 2559 prepare_read_tag(con);
2560 return 1; 2560 return 1;
2561} 2561}
@@ -3223,12 +3223,12 @@ bool ceph_con_keepalive_expired(struct ceph_connection *con,
3223{ 3223{
3224 if (interval > 0 && 3224 if (interval > 0 &&
3225 (con->peer_features & CEPH_FEATURE_MSGR_KEEPALIVE2)) { 3225 (con->peer_features & CEPH_FEATURE_MSGR_KEEPALIVE2)) {
3226 struct timespec now; 3226 struct timespec64 now;
3227 struct timespec ts; 3227 struct timespec64 ts;
3228 ktime_get_real_ts(&now); 3228 ktime_get_real_ts64(&now);
3229 jiffies_to_timespec(interval, &ts); 3229 jiffies_to_timespec64(interval, &ts);
3230 ts = timespec_add(con->last_keepalive_ack, ts); 3230 ts = timespec64_add(con->last_keepalive_ack, ts);
3231 return timespec_compare(&now, &ts) >= 0; 3231 return timespec64_compare(&now, &ts) >= 0;
3232 } 3232 }
3233 return false; 3233 return false;
3234} 3234}