From: xie xingguo Date: Tue, 26 Apr 2016 07:12:17 +0000 (+0800) Subject: osdc/Objecter: fix race condition for sortbitwise flag detection X-Git-Tag: v11.0.0~642^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7fb6be706be2454cc2a831df29808997f0aa5ab3;p=ceph.git osdc/Objecter: fix race condition for sortbitwise flag detection During list_objects/list_nobjects(), we are checking osdmap's sortbitwise flag setting without holding rwlock in hand, which is a potential race condition. Signed-off-by: xie xingguo --- diff --git a/src/osdc/Objecter.cc b/src/osdc/Objecter.cc index 4221ba60be48..13ba2382b594 100644 --- a/src/osdc/Objecter.cc +++ b/src/osdc/Objecter.cc @@ -3408,19 +3408,19 @@ void Objecter::list_nobjects(NListContext *list_context, Context *onfinish) return; } int pg_num = pool->get_pg_num(); + bool sort_bitwise = osdmap->test_flag(CEPH_OSDMAP_SORTBITWISE); rl.unlock(); if (list_context->starting_pg_num == 0) { // there can't be zero pgs! list_context->starting_pg_num = pg_num; - list_context->sort_bitwise = osdmap->test_flag(CEPH_OSDMAP_SORTBITWISE); + list_context->sort_bitwise = sort_bitwise; ldout(cct, 20) << pg_num << " placement groups" << dendl; } - if (list_context->sort_bitwise != - osdmap->test_flag(CEPH_OSDMAP_SORTBITWISE)) { + if (list_context->sort_bitwise != sort_bitwise) { ldout(cct, 10) << " hobject sort order changed, restarting this pg" << dendl; list_context->cookie = collection_list_handle_t(); - list_context->sort_bitwise = osdmap->test_flag(CEPH_OSDMAP_SORTBITWISE); + list_context->sort_bitwise = sort_bitwise; } if (list_context->starting_pg_num != pg_num) { // start reading from the beginning; the pgs have changed @@ -3564,19 +3564,19 @@ void Objecter::list_objects(ListContext *list_context, Context *onfinish) return; } int pg_num = pool->get_pg_num(); + bool sort_bitwise = osdmap->test_flag(CEPH_OSDMAP_SORTBITWISE); rl.unlock(); if (list_context->starting_pg_num == 0) { // there can't be zero pgs! list_context->starting_pg_num = pg_num; - list_context->sort_bitwise = osdmap->test_flag(CEPH_OSDMAP_SORTBITWISE); + list_context->sort_bitwise = sort_bitwise; ldout(cct, 20) << pg_num << " placement groups" << dendl; } - if (list_context->sort_bitwise != - osdmap->test_flag(CEPH_OSDMAP_SORTBITWISE)) { + if (list_context->sort_bitwise != sort_bitwise) { ldout(cct, 10) << " hobject sort order changed, restarting this pg" << dendl; list_context->cookie = collection_list_handle_t(); - list_context->sort_bitwise = osdmap->test_flag(CEPH_OSDMAP_SORTBITWISE); + list_context->sort_bitwise = sort_bitwise; } if (list_context->starting_pg_num != pg_num) { // start reading from the beginning; the pgs have changed