]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd/cache/pwl: fix parsing of cache_type in create_image_cache_state() 41244/head
authorIlya Dryomov <idryomov@gmail.com>
Wed, 5 May 2021 10:29:44 +0000 (12:29 +0200)
committerIlya Dryomov <idryomov@gmail.com>
Sun, 9 May 2021 20:10:16 +0000 (22:10 +0200)
cache_type is a string (currently "ssd" or "rwl"), not an int.  When
coerced to an int, the result is 0 -- JSONFormattable ends up calling
atoi() under the hood and atoi() does not detect errors...

As the value of rbd_persistent_cache_mode option is validated by the
option parser (enum type) and, separately, ImageCacheState::cache_type
is validated in InitRequest::get_image_cache_state() when creating
an instance of the approprate WriteLog, don't attempt to validate it
in ImageCacheState::create_image_cache_state().

Fixes: https://tracker.ceph.com/issues/50668
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
(cherry picked from commit ec7af7ede9beacec91140996abe343a5db48004f)

src/librbd/cache/pwl/ImageCacheState.cc

index 4fb6f529f2577715b34bb1ecf1d9cc7f80ddba80..11074befb57da642198b7055422e5c0a0dbf4e8b 100644 (file)
@@ -54,8 +54,9 @@ ImageCacheState<I>::ImageCacheState(
   present = (bool)f["present"];
   empty = (bool)f["empty"];
   clean = (bool)f["clean"];
-  host = (string)f["pwl_host"];
-  path = (string)f["pwl_path"];
+  cache_type = f["cache_type"];
+  host = f["pwl_host"];
+  path = f["pwl_path"];
   uint64_t pwl_size;
   std::istringstream iss(f["pwl_size"]);
   iss >> pwl_size;
@@ -142,19 +143,10 @@ ImageCacheState<I>* ImageCacheState<I>::create_image_cache_state(
     }
 
     bool cache_exists = (bool)f["present"];
-    int cache_type = (int)f["cache_type"];
-
-    switch (cache_type) {
-      case IMAGE_CACHE_TYPE_SSD:
-      case IMAGE_CACHE_TYPE_RWL:
-        if (!cache_exists) {
-          cache_state = new ImageCacheState<I>(image_ctx, plugin_api);
-        } else {
-          cache_state = new ImageCacheState<I>(image_ctx, f, plugin_api);
-        }
-        break;
-      default:
-       r = -EINVAL;
+    if (!cache_exists) {
+      cache_state = new ImageCacheState<I>(image_ctx, plugin_api);
+    } else {
+      cache_state = new ImageCacheState<I>(image_ctx, f, plugin_api);
     }
   }
   return cache_state;