libceph: Handle rbtree insertion error in handle_backoff_block()
PATCH v3 1/1 libceph: Handle rbtree insertion error in handle_backoff_block()
A message of type CEPH_MSG_OSD_BACKOFF is used to block/unblock requests to specific PGs or objects. If this message has op code CEPH_OSD_BACKOFF_OP_BLOCK, handle_backoff_block() is called to block requests. In this function, a backoff struct is created and inserted into two rbtrees for tracking them. Both insertions use the asserting rbtree insertion function by calling insert_backoff(), respectively insert_backoff_by_id(). If a message contains a backoff with the same begin ceph_hobject_id or the same id as a previous one, the assertion in insert_backoff()/insert_backoff_by_id() triggers a kernel BUG when trying to insert the backoff.
This patch fixes the issue by switching both calls to the non-asserting rbtree function and ignoring the message if one of the insertions fails.
--- net/ceph/osd_client.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
net/ceph/osd_client.c +20 -2
@@ -4427,8 +4427,16 @@ static void handle_backoff_block(struct ceph_osd *osd, struct MOSDBackoff *m) backoff->end = m->end; m->end =NULL ;/* ditto */ -insert_backoff (&spg->backoffs, backoff); -insert_backoff_by_id (&osd->o_backoffs_by_id, backoff); +if (!__insert_backoff (&spg->backoffs, backoff)) { +pr_err_ratelimited ("%s failed to insert backoff\n" , __func__); + goto err_free_backoff; + } + +if (!__insert_backoff_by_id (&osd->o_backoffs_by_id, backoff)) { +pr_err_ratelimited ("%s failed to insert backoff by id\n" , + __func__); + goto err_erase_backoff; + }/* * Ack with original backoff's epoch so that the OSD can
@@ -4440,6 +4448,16 @@ static void handle_backoff_block(struct ceph_osd *osd, struct MOSDBackoff *m)return ; }ceph_con_send (&osd->o_con, msg); +return ; + +err_erase_backoff: +erase_backoff (&spg->backoffs, backoff); +err_free_backoff: +free_backoff (backoff); +if (RB_EMPTY_ROOT (&spg->backoffs)) { +erase_spg_mapping (&osd->o_backoff_mappings, spg); +free_spg_mapping (spg); + } } static bool target_contained_by(const struct ceph_osd_request_target *t,
Signature · 1 line
2.47.3
Quoted 67 lines · Raphael Zimmer
A message of type
CEPH_MSG_OSD_BACKOFFis used to block/unblock requests
to specific PGs or objects. If this message has op codeCEPH_OSD_BACKOFF_OP_BLOCK,handle_backoff_block()is called to block requests. In this function, a backoff struct is created and inserted into two rbtrees for tracking them. Both insertions use the asserting rbtree insertion function by callinginsert_backoff(), respectivelyinsert_backoff_by_id(). If a message contains a backoff with the same beginceph_hobject_idor the same id as a previous one, the assertion in
insert_backoff()/insert_backoff_by_id() triggers a kernel BUG when trying to insert the backoff.This patch fixes the issue by switching both calls to the non- asserting
rbtree function and ignoring the message if one of the insertions fails.Fixes a02a946dfe96 ("libceph: respect RADOS_BACKOFF backoffs")Signed-off-by Raphael Zimmer <[email protected]>---
net/ceph/osd_client.c | 22 ++++++++++++++++++++--1 file changed, 20 insertions(+), 2 deletions(-)net/ceph/osd_client.c +0
-0@@ -4427,8 +4427,16 @@ static void handle_backoff_block(struct ceph_osd *osd, struct MOSDBackoff *m) backoff->end = m->end;
m->end= NULL; /* ditto */net/ceph/osd_client.c +2
-2-insert_backoff (&spg->backoffs, backoff); -insert_backoff_by_id (&osd->o_backoffs_by_id, backoff); +if (!__insert_backoff (&spg->backoffs, backoff)) { + pr_err_ratelimited("%s failed to insert backoff\n",
__func__);net/ceph/osd_client.c +4
-0+ goto err_free_backoff; + } + + if (!__insert_backoff_by_id(&osd->o_backoffs_by_id,backoff)) {
net/ceph/osd_client.c +1
-0+ pr_err_ratelimited("%s failed to insert backoff byid\n",
net/ceph/osd_client.c +3
-0+ __func__); + goto err_erase_backoff; + }
/*
* Ack with original backoff's epoch so that the OSD cannet/ceph/osd_client.c +10
-0@@ -4440,6 +4448,16 @@ static void handle_backoff_block(struct ceph_osd *osd, struct MOSDBackoff *m) return; } ceph_con_send(&osd->o_con, msg); +return ; + +err_erase_backoff: +erase_backoff (&spg->backoffs, backoff); +err_free_backoff: +free_backoff (backoff); +if (RB_EMPTY_ROOT (&spg->backoffs)) { +erase_spg_mapping (&osd->o_backoff_mappings, spg); +free_spg_mapping (spg); + } }
Quoted 3 lines
static bool target_contained_by(const structceph_osd_request_target*t,
Looks good.
Thanks,
Slava.