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: v10.2.1~48 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=030883f41d3d2d8f297b3d3f6e7c7fa5a06ea4c0;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 (cherry picked from commit 7fb6be706be2454cc2a831df29808997f0aa5ab3) --- diff --git a/src/osdc/Objecter.cc b/src/osdc/Objecter.cc index 92a869836d00..c1f4e91c130e 100644 --- a/src/osdc/Objecter.cc +++ b/src/osdc/Objecter.cc @@ -3410,19 +3410,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 @@ -3566,19 +3566,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