libceph: use keepalive2 to verify the mon session is alive
PATCH 1/1 libceph: use keepalive2 to verify the mon session is alive
Signed-off-by Yan, Zheng <[email protected]>
--- include/linux/ceph/libceph.h | 2 ++ include/linux/ceph/messenger.h | 4 +++ include/linux/ceph/msgr.h | 4 ++- net/ceph/ceph_common.c | 18 ++++++++++++- net/ceph/messenger.c | 60 ++++++++++++++++++++++++++++++++++++++---- net/ceph/mon_client.c | 38 ++++++++++++++++++++------ 6 files changed, 111 insertions(+), 15 deletions(-)
include/linux/ceph/libceph.h +2 -0
@@ -46,6 +46,7 @@ struct ceph_options {unsigned long mount_timeout;/* jiffies */ unsigned long osd_idle_ttl;/* jiffies */ unsigned long osd_keepalive_timeout;/* jiffies */ +unsigned long mon_keepalive_timeout;/* jiffies */ /* * any type that can't be simply compared or doesn't need need
@@ -66,6 +67,7 @@ struct ceph_options {#define CEPH_MOUNT_TIMEOUT_DEFAULT msecs_to_jiffies(60 * 1000)#define CEPH_OSD_KEEPALIVE_DEFAULT msecs_to_jiffies(5 * 1000)#define CEPH_OSD_IDLE_TTL_DEFAULT msecs_to_jiffies(60 * 1000) +#define CEPH_MON_KEEPALIVE_DEFAULT msecs_to_jiffies(30 * 1000)#define CEPH_MSG_MAX_FRONT_LEN (16*1024*1024)#define CEPH_MSG_MAX_MIDDLE_LEN (16*1024*1024)
include/linux/ceph/messenger.h +4 -0
@@ -248,6 +248,8 @@ struct ceph_connection {int in_base_pos;/* bytes read */ __le64 in_temp_ack;/* for reading an ack */ +struct timespec last_keepalive_ack; +struct delayed_work work;/* send|recv work */ unsigned long delay;/* current delay interval */ };
@@ -285,6 +287,8 @@ extern void ceph_msg_revoke(struct ceph_msg *msg);extern void ceph_msg_revoke_incoming (struct ceph_msg *msg);extern void ceph_con_keepalive (struct ceph_connection *con); +extern int ceph_con_keepalive_expired (struct ceph_connection *con, +unsigned long interval);extern void ceph_msg_data_add_pages (struct ceph_msg *msg,struct page **pages,size_t length,size_t alignment);
include/linux/ceph/msgr.h +3 -1
@@ -84,10 +84,12 @@ struct ceph_entity_inst {#define CEPH_MSGR_TAG_MSG 7/* message */ #define CEPH_MSGR_TAG_ACK 8/* message ack */ #define CEPH_MSGR_TAG_KEEPALIVE 9/* just a keepalive byte! */ -#define CEPH_MSGR_TAG_BADPROTOVER 10/* bad protocol version */ +#define CEPH_MSGR_TAG_BADPROTOVER 10/* bad protocol version */ #define CEPH_MSGR_TAG_BADAUTHORIZER 11/* bad authorizer */ #define CEPH_MSGR_TAG_FEATURES 12/* insufficient features */ #define CEPH_MSGR_TAG_SEQ 13/* 64-bit int follows with seen seq number */ +#define CEPH_MSGR_TAG_KEEPALIVE2 14/* keepalive2 byte + ceph_timespec */ +#define CEPH_MSGR_TAG_KEEPALIVE2_ACK 15/* keepalive2 reply */ /*
net/ceph/ceph_common.c +17 -1
@@ -226,6 +226,7 @@ static int parse_fsid(const char *str, struct ceph_fsid *fsid)* ceph options */ enum { + Opt_monkeepalivetimeout, Opt_osdtimeout, Opt_osdkeepalivetimeout, Opt_mount_timeout,
@@ -250,6 +251,7 @@ enum { };static match_table_t opt_tokens = { + {Opt_monkeepalivetimeout,"monkeepalive=%d" }, {Opt_osdtimeout,"osdtimeout=%d" }, {Opt_osdkeepalivetimeout,"osdkeepalive=%d" }, {Opt_mount_timeout,"mount_timeout=%d" },
@@ -354,9 +356,10 @@ ceph_parse_options(char *options, const char *dev_name,/* start with defaults */ opt->flags =CEPH_OPT_DEFAULT ; - opt->osd_keepalive_timeout =CEPH_OSD_KEEPALIVE_DEFAULT ; opt->mount_timeout =CEPH_MOUNT_TIMEOUT_DEFAULT ; opt->osd_idle_ttl =CEPH_OSD_IDLE_TTL_DEFAULT ; + opt->osd_keepalive_timeout =CEPH_OSD_KEEPALIVE_DEFAULT ; + opt->mon_keepalive_timeout =CEPH_MON_KEEPALIVE_DEFAULT ;/* get mon ip(s) */ /* ip1[:port1][,ip2[:port2]...] */
@@ -460,6 +463,16 @@ ceph_parse_options(char *options, const char *dev_name, } opt->osd_idle_ttl =msecs_to_jiffies (intval *1000 );break ; +case Opt_monkeepalivetimeout: +/* 0 isn't well defined right now, reject it */ +if (intval <1 || intval >INT_MAX /1000 ) { +pr_err ("monkeepalive out of range\n" ); + err = -EINVAL ; + goto out; + } + opt->mon_keepalive_timeout = +msecs_to_jiffies (intval *1000 ); +break ;case Opt_mount_timeout:/* 0 is "wait forever" (i.e. infinite timeout) */ if (intval <0 || intval >INT_MAX /1000 ) {
@@ -542,6 +555,9 @@ int ceph_print_client_options(struct seq_file *m, struct ceph_client *client)if (opt->osd_keepalive_timeout !=CEPH_OSD_KEEPALIVE_DEFAULT )seq_printf (m,"osdkeepalivetimeout=%d," ,jiffies_to_msecs (opt->osd_keepalive_timeout) /1000 ); +if (opt->mon_keepalive_timeout !=CEPH_MON_KEEPALIVE_DEFAULT ) +seq_printf (m,"monkeepalivetimeout=%d," , +jiffies_to_msecs (opt->mon_keepalive_timeout) /1000 );/* drop redundant comma */ if (m->count != pos)
net/ceph/messenger.c +55 -5
114 lines not on this page · raw message
net/ceph/mon_client.c +30 -8
@@ -149,6 +149,10 @@ static int __open_session(struct ceph_mon_client *monc)CEPH_ENTITY_TYPE_MON , monc->cur_mon, &monc->monmap->mon_inst[monc->cur_mon].addr); +/* send an initial keepalive to ensure our timestamp is +* valid by the time we are in an OPENED state */ +ceph_con_keepalive (&monc->con); +/* initiatiate authentication handshake */ ret = ceph_auth_build_hello(monc->auth, monc->m_auth->front.iov_base,
@@ -170,14 +174,19 @@ static bool __sub_expired(struct ceph_mon_client *monc)*/ static void __schedule_delayed (struct ceph_mon_client *monc) { -unsigned int delay; +struct ceph_options *opt = monc->client->options; +unsigned long delay; -if (monc->cur_mon <0 ||__sub_expired (monc)) +if (monc->cur_mon <0 ||__sub_expired (monc)) { delay =10 *HZ ; -else + }else { delay =20 *HZ ; -dout ("__schedule_delayed after %u\n" , delay); -schedule_delayed_work (&monc->delayed_work, delay); +if (opt->mon_keepalive_timeout >0 ) + delay =min (delay, opt->mon_keepalive_timeout >>2 ); + } +dout ("__schedule_delayed after %lu\n" , delay); +schedule_delayed_work (&monc->delayed_work, +round_jiffies_relative (delay)); }/*
@@ -743,11 +752,24 @@ static void delayed_work(struct work_struct *work)__close_session (monc);__open_session (monc);/* continue hunting */ }else { -ceph_con_keepalive (&monc->con); +struct ceph_options *opt = monc->client->options; +int is_auth =ceph_auth_is_authenticated (monc->auth); +if (is_auth && opt->mon_keepalive_timeout >0 && +ceph_con_keepalive_expired (&monc->con, + opt->mon_keepalive_timeout)) { +dout ("monc keepalive timeout\n" ); + is_auth =0 ; +__close_session (monc); + monc->hunting = true; +__open_session (monc); + } -__validate_auth (monc); +if (!monc->hunting) { +ceph_con_keepalive (&monc->con); +__validate_auth (monc); + } -if (ceph_auth_is_authenticated (monc->auth)) +if (is_auth)__send_subscribe (monc); }__schedule_delayed (monc);
Signature · 1 line
1.9.3
Ilya Dryomov
maintainerQuoted 9 lines · Zheng
Signed-off-by Yan, Zheng <[email protected]>--- include/linux/ceph/libceph.h | 2 ++ include/linux/ceph/messenger.h | 4 +++ include/linux/ceph/msgr.h | 4 ++- net/ceph/ceph_common.c | 18 ++++++++++++- net/ceph/messenger.c | 60 ++++++++++++++++++++++++++++++++++++++---- net/ceph/mon_client.c | 38 ++++++++++++++++++++------ 6 files changed, 111 insertions(+), 15 deletions(-)
Hi Zheng,
Just want to make sure you saw my "Re: " message - I had a few suggestions. This one looks like the one I commented on, straight from the testing branch.
Thanks,
Ilya