]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: fix target_buffer value overflow in Cache::trim() when metadata_ratio... 12507/head
authorIgor Fedotov <ifedotov@mirantis.com>
Thu, 15 Dec 2016 16:22:16 +0000 (16:22 +0000)
committerIgor Fedotov <ifedotov@mirantis.com>
Thu, 15 Dec 2016 16:26:12 +0000 (16:26 +0000)
Signed-off-by: Igor Fedotov<ifedotov@mirantis.com>
src/os/bluestore/BlueStore.cc

index c813859d6b88f77c3c9b8e2eacacd723a7432c9b..e3a635c439fa8735fe05f97cebf37341e0ce0901 100644 (file)
@@ -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) {