]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: output operator for image options
authorMykola Golub <mgolub@mirantis.com>
Thu, 19 Nov 2015 11:04:43 +0000 (13:04 +0200)
committerMykola Golub <mgolub@mirantis.com>
Fri, 4 Dec 2015 11:18:30 +0000 (13:18 +0200)
It is going to be used for diagnostic.

Signed-off-by: Mykola Golub <mgolub@mirantis.com>
src/librbd/internal.cc
src/librbd/internal.h

index 985b16f24e809e49f135d29b2acfadf6ec51216f..4590ded6d9f09775c6a98872fc307258a434bdf5 100644 (file)
@@ -435,6 +435,78 @@ int invoke_async_request(ImageCtx *ictx, const std::string& request_type,
     {RBD_IMAGE_OPTION_STRIPE_COUNT, UINT64},
   };
 
+  std::string image_option_name(int optname) {
+    switch (optname) {
+    case RBD_IMAGE_OPTION_FORMAT:
+      return "format";
+    case RBD_IMAGE_OPTION_FEATURES:
+      return "features";
+    case RBD_IMAGE_OPTION_ORDER:
+      return "order";
+    case RBD_IMAGE_OPTION_STRIPE_UNIT:
+      return "stripe_unit";
+    case RBD_IMAGE_OPTION_STRIPE_COUNT:
+      return "stripe_count";
+    case RBD_IMAGE_OPTION_JOURNAL_ORDER:
+      return "journal_order";
+    case RBD_IMAGE_OPTION_JOURNAL_SPLAY_WIDTH:
+      return "journal_splay_width";
+    case RBD_IMAGE_OPTION_JOURNAL_COMMIT_AGE_MS:
+      return "journal_commit_age_ms";
+    case RBD_IMAGE_OPTION_JOURNAL_OBJECT_FLUSH_INTERVAL:
+      return "journal_object_flush_interval";
+    case RBD_IMAGE_OPTION_JOURNAL_OBJECT_FLUSH_BYTES:
+      return "journal_object_flush_bytes";
+    case RBD_IMAGE_OPTION_JOURNAL_OBJECT_FLUSH_AGE_MS:
+      return "journal_object_flush_age_ms";
+    case RBD_IMAGE_OPTION_JOURNAL_OBJECT_POOL:
+      return "journal_object_pool";
+    default:
+      return "unknown (" + stringify(optname) + ")";
+    }
+  }
+
+  std::ostream &operator<<(std::ostream &os, rbd_image_options_t &opts) {
+    image_options_ref* opts_ = static_cast<image_options_ref*>(opts);
+
+    os << "[";
+
+    for (image_options_t::const_iterator i = (*opts_)->begin();
+        i != (*opts_)->end(); i++) {
+      os << (i == (*opts_)->begin() ? "" : ", ") << image_option_name(i->first)
+        << "=" << i->second;
+    }
+
+    os << "]";
+
+    return os;
+  }
+
+  std::ostream &operator<<(std::ostream &os, ImageOptions &opts) {
+    os << "[";
+
+    const char *delimiter = "";
+    for (auto &i : IMAGE_OPTIONS_TYPE_MAPPING) {
+      if (i.second == STR) {
+       std::string val;
+       if (opts.get(i.first, &val) == 0) {
+         os << delimiter << image_option_name(i.first) << "=" << val;
+         delimiter = ", ";
+       }
+      } else if (i.second == UINT64) {
+       uint64_t val;
+       if (opts.get(i.first, &val) == 0) {
+         os << delimiter << image_option_name(i.first) << "=" << val;
+         delimiter = ", ";
+       }
+      }
+    }
+
+    os << "]";
+
+    return os;
+  }
+
   void image_options_create(rbd_image_options_t* opts)
   {
     image_options_ref* opts_ = new image_options_ref(new image_options_t());
index a08dd02ab0921f93b279905808b3e04675922419..42b48c3ef45164973d9d9827d57db2fee9afd8d6 100644 (file)
@@ -78,6 +78,7 @@ namespace librbd {
 
   bool has_parent(int64_t parent_pool_id, uint64_t off, uint64_t overlap);
 
+  std::string image_option_name(int optname);
   void image_options_create(rbd_image_options_t* opts);
   void image_options_create_ref(rbd_image_options_t* opts,
                                rbd_image_options_t orig);