From: Igor Fedotov Date: Thu, 15 Dec 2016 16:22:16 +0000 (+0000) Subject: os/bluestore: fix target_buffer value overflow in Cache::trim() when metadata_ratio... X-Git-Tag: v11.1.1~42^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F12507%2Fhead;p=ceph.git os/bluestore: fix target_buffer value overflow in Cache::trim() when metadata_ratio is set to 1 Signed-off-by: Igor Fedotov --- diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index c813859d6b8..e3a635c439f 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -530,7 +530,17 @@ void BlueStore::Cache::trim( uint64_t current_buffer = _get_buffer_bytes(); uint64_t current = current_meta + current_buffer; - uint64_t target_meta = target_bytes * target_meta_ratio; + uint64_t target_meta = target_bytes * (double)target_meta_ratio; //need to cast to double + //since float(1) might produce inaccurate value + // for target_meta (a bit greater than target_bytes) + // that causes overflow in target_buffer below. + //Consider the following code: + //uint64_t i =(uint64_t)227*1024*1024*1024 + 1; + //float f = 1; + //uint64_t i2 = i*f; + //assert(i == i2); + + target_meta = min(target_bytes, target_meta); //and just in case that ratio is > 1 uint64_t target_buffer = target_bytes - target_meta; if (current <= target_bytes) {