From: xie xingguo Date: Thu, 22 Sep 2016 11:59:05 +0000 (+0800) Subject: os/bluestore: fix race condition of global csum setting X-Git-Tag: v11.0.1~126^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=07f697799bd9ffc865ff776a33ab7f6c6df72da9;p=ceph.git os/bluestore: fix race condition of global csum setting The global csum_type option can be changed dynamically and can be fixed by upgrading into std::atomic. Signed-off-by: xie xingguo --- diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 0ec048f6f29..43eb9d7d45c 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -4728,8 +4728,7 @@ int BlueStore::_do_read( } else { for (auto reg : b2r_it->second) { // determine how much of the blob to read - uint64_t chunk_size = bptr->get_blob().get_chunk_size( - csum_type != bluestore_blob_t::CSUM_NONE, block_size); + uint64_t chunk_size = bptr->get_blob().get_chunk_size(true, block_size); uint64_t r_off = reg.blob_xoffset; uint64_t r_len = reg.length; unsigned front = r_off % chunk_size; @@ -7337,8 +7336,9 @@ int BlueStore::_do_alloc_write( << dendl; // checksum - if (csum_type) { - b->dirty_blob().init_csum(csum_type, csum_order, csum_length); + int csum = csum_type.load(); + if (csum) { + b->dirty_blob().init_csum(csum, csum_order, csum_length); b->dirty_blob().calc_csum(b_off, *l); } if (wi.mark_unused) { diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 5e5253d5cc9..b206bb087b1 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -1336,7 +1336,7 @@ private: set debug_data_error_objects; set debug_mdata_error_objects; - int csum_type; + std::atomic csum_type; uint64_t block_size; ///< block size of block device (power of 2) uint64_t block_mask; ///< mask to get just the block offset