]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: journal options on image create/clone/copy
authorMykola Golub <mgolub@mirantis.com>
Mon, 16 Nov 2015 14:54:28 +0000 (16:54 +0200)
committerMykola Golub <mgolub@mirantis.com>
Fri, 4 Dec 2015 11:18:30 +0000 (13:18 +0200)
Signed-off-by: Mykola Golub <mgolub@mirantis.com>
src/include/rbd/librbd.h
src/librbd/Journal.cc
src/librbd/Journal.h
src/librbd/internal.cc

index 0a1a5e68273c8a90af6bbbfc937c53e7ff496d5f..30fd5b9853a555044a3d44765c14ed9715b716f9 100644 (file)
@@ -99,6 +99,9 @@ enum {
   RBD_IMAGE_OPTION_ORDER = 2,
   RBD_IMAGE_OPTION_STRIPE_UNIT = 3,
   RBD_IMAGE_OPTION_STRIPE_COUNT = 4,
+  RBD_IMAGE_OPTION_JOURNAL_ORDER = 5,
+  RBD_IMAGE_OPTION_JOURNAL_SPLAY_WIDTH = 6,
+  RBD_IMAGE_OPTION_JOURNAL_POOL = 7,
 };
 
 CEPH_RBD_API void rbd_image_options_create(rbd_image_options_t* opts);
index 1a229be996761f026601afd9c299aab9b82606fb..8ef0a2f6fa67471becf82d29cdbdd7085f519f92 100644 (file)
@@ -104,7 +104,7 @@ bool Journal::is_journal_supported(ImageCtx &image_ctx) {
 }
 
 int Journal::create(librados::IoCtx &io_ctx, const std::string &image_id,
-                   double commit_age, uint8_t order, uint8_t splay_width,
+                   uint8_t order, uint8_t splay_width,
                    const std::string &object_pool) {
   CephContext *cct = reinterpret_cast<CephContext *>(io_ctx.cct());
   ldout(cct, 5) << __func__ << ": image=" << image_id << dendl;
@@ -123,7 +123,8 @@ int Journal::create(librados::IoCtx &io_ctx, const std::string &image_id,
     pool_id = data_io_ctx.get_id();
   }
 
-  ::journal::Journaler journaler(io_ctx, image_id, "", commit_age);
+  ::journal::Journaler journaler(io_ctx, image_id, "",
+                                cct->_conf->rbd_journal_commit_age);
 
   int r = journaler.create(order, splay_width, pool_id);
   if (r < 0) {
index d2aae91be2e2f749cb7ededc8d26100a286735c9..8823db09a9184295c783d61122387b8fc77f7692 100644 (file)
@@ -43,7 +43,7 @@ public:
 
   static bool is_journal_supported(ImageCtx &image_ctx);
   static int create(librados::IoCtx &io_ctx, const std::string &image_id,
-                   double commit_age, uint8_t order, uint8_t splay_width,
+                   uint8_t order, uint8_t splay_width,
                    const std::string &object_pool);
   static int remove(librados::IoCtx &io_ctx, const std::string &image_id);
   static int reset(librados::IoCtx &io_ctx, const std::string &image_id);
index 4590ded6d9f09775c6a98872fc307258a434bdf5..37ded6c246c4c10881f511bbf5715170dadbd1a3 100644 (file)
@@ -433,6 +433,9 @@ int invoke_async_request(ImageCtx *ictx, const std::string& request_type,
     {RBD_IMAGE_OPTION_ORDER, UINT64},
     {RBD_IMAGE_OPTION_STRIPE_UNIT, UINT64},
     {RBD_IMAGE_OPTION_STRIPE_COUNT, UINT64},
+    {RBD_IMAGE_OPTION_JOURNAL_ORDER, UINT64},
+    {RBD_IMAGE_OPTION_JOURNAL_SPLAY_WIDTH, UINT64},
+    {RBD_IMAGE_OPTION_JOURNAL_POOL, STR},
   };
 
   std::string image_option_name(int optname) {
@@ -451,16 +454,8 @@ int invoke_async_request(ImageCtx *ictx, const std::string& request_type,
       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";
+    case RBD_IMAGE_OPTION_JOURNAL_POOL:
+      return "journal_pool";
     default:
       return "unknown (" + stringify(optname) + ")";
     }
@@ -1182,7 +1177,9 @@ int invoke_async_request(ImageCtx *ictx, const std::string& request_type,
 
   int create_v2(IoCtx& io_ctx, const char *imgname, uint64_t bid, uint64_t size,
                int order, uint64_t features, uint64_t stripe_unit,
-               uint64_t stripe_count)
+               uint64_t stripe_count, uint8_t journal_order,
+               uint8_t journal_splay_width,
+               const std::string &journal_pool)
   {
     ostringstream bid_ss;
     uint32_t extra;
@@ -1276,10 +1273,8 @@ int invoke_async_request(ImageCtx *ictx, const std::string& request_type,
         goto err_remove_object_map;
       }
 
-      r = Journal::create(io_ctx, id, cct->_conf->rbd_journal_commit_age,
-                         cct->_conf->rbd_journal_order,
-                         cct->_conf->rbd_journal_splay_width,
-                         cct->_conf->rbd_journal_pool);
+      r = Journal::create(io_ctx, id, journal_order, journal_splay_width,
+                         journal_pool);
       if (r < 0) {
         lderr(cct) << "error creating journal: " << cpp_strerror(r) << dendl;
         goto err_remove_object_map;
@@ -1449,8 +1444,16 @@ int invoke_async_request(ImageCtx *ictx, const std::string& request_type,
 
       r = create_v1(io_ctx, imgname, bid, size, order);
     } else {
+      uint64_t journal_order = cct->_conf->rbd_journal_order;
+      uint64_t journal_splay_width = cct->_conf->rbd_journal_splay_width;
+      std::string journal_pool = cct->_conf->rbd_journal_pool;
+
+      opts.get(RBD_IMAGE_OPTION_JOURNAL_ORDER, &journal_order);
+      opts.get(RBD_IMAGE_OPTION_JOURNAL_SPLAY_WIDTH, &journal_splay_width);
+      opts.get(RBD_IMAGE_OPTION_JOURNAL_POOL, &journal_pool);
+
       r = create_v2(io_ctx, imgname, bid, size, order, features, stripe_unit,
-                   stripe_count);
+                   stripe_count, journal_order, journal_splay_width, journal_pool);
     }
 
     int r1 = opts.set(RBD_IMAGE_OPTION_ORDER, order);
@@ -1463,39 +1466,46 @@ int invoke_async_request(ImageCtx *ictx, const std::string& request_type,
    * Parent may be in different pool, hence different IoCtx
    */
   int clone(IoCtx& p_ioctx, const char *p_name, const char *p_snap_name,
-           IoCtx& c_ioctx, const char *c_name, ImageOptions& c_opts)
+           IoCtx& c_ioctx, const char *c_name,
+           uint64_t features, int *c_order,
+           uint64_t stripe_unit, int stripe_count)
   {
-    int order = 0;
-    uint64_t features = 0;
-    uint64_t stripe_unit = 0;
-    uint64_t stripe_count = 0;
-    c_opts.get(RBD_IMAGE_OPTION_FEATURES, &features);
-    c_opts.get(RBD_IMAGE_OPTION_STRIPE_UNIT, &stripe_unit);
-    c_opts.get(RBD_IMAGE_OPTION_STRIPE_COUNT, &stripe_count);
+    uint64_t order = *c_order;
 
-    int r = clone(p_ioctx, p_name, p_snap_name, c_ioctx, c_name, features,
-                 &order, stripe_unit, stripe_count);
-    c_opts.set(RBD_IMAGE_OPTION_ORDER, static_cast<uint64_t>(order));
+    ImageOptions opts;
+    opts.set(RBD_IMAGE_OPTION_FORMAT, static_cast<uint64_t>(2));
+    opts.set(RBD_IMAGE_OPTION_FEATURES, features);
+    opts.set(RBD_IMAGE_OPTION_ORDER, order);
+    opts.set(RBD_IMAGE_OPTION_STRIPE_UNIT, stripe_unit);
+    opts.set(RBD_IMAGE_OPTION_STRIPE_COUNT, stripe_count);
+
+    int r = clone(p_ioctx, p_name, p_snap_name, c_ioctx, c_name, opts);
+    opts.get(RBD_IMAGE_OPTION_ORDER, &order);
+    *c_order = order;
     return r;
   }
 
   int clone(IoCtx& p_ioctx, const char *p_name, const char *p_snap_name,
-           IoCtx& c_ioctx, const char *c_name,
-           uint64_t features, int *c_order,
-           uint64_t stripe_unit, int stripe_count)
+           IoCtx& c_ioctx, const char *c_name, ImageOptions& c_opts)
   {
     CephContext *cct = (CephContext *)p_ioctx.cct();
     ldout(cct, 20) << "clone " << &p_ioctx << " name " << p_name << " snap "
                   << p_snap_name << "to child " << &c_ioctx << " name "
-                  << c_name << " features = " << features << " order = "
-                  << *c_order
-                  << " stripe_unit = " << stripe_unit
-                  << " stripe_count = " << stripe_count
-                  << dendl;
+                  << c_name << " opts = " << c_opts << dendl;
 
-    if (features & ~RBD_FEATURES_ALL) {
-      lderr(cct) << "librbd does not support requested features" << dendl;
-      return -ENOSYS;
+    uint64_t format = cct->_conf->rbd_default_format;
+    c_opts.get(RBD_IMAGE_OPTION_FORMAT, &format);
+    if (format < 2) {
+      lderr(cct) << "format 2 or later required for clone" << dendl;
+      return -EINVAL;
+    }
+
+    uint64_t features;
+    if (c_opts.get(RBD_IMAGE_OPTION_FEATURES, &features) != 0) {
+      if (features & ~RBD_FEATURES_ALL) {
+       lderr(cct) << "librbd does not support requested features" << dendl;
+       return -ENOSYS;
+      }
     }
 
     // make sure child doesn't already exist, in either format
@@ -1511,7 +1521,7 @@ int invoke_async_request(ImageCtx *ictx, const std::string& request_type,
     }
 
     bool snap_protected;
-    int order;
+    uint64_t order;
     uint64_t size;
     uint64_t p_features;
     int partial_r;
@@ -1554,12 +1564,12 @@ int invoke_async_request(ImageCtx *ictx, const std::string& request_type,
       goto err_close_parent;
     }
 
-    order = *c_order;
-    if (!order)
-      order = p_imctx->order;
+    order = p_imctx->order;
+    if (c_opts.get(RBD_IMAGE_OPTION_ORDER, &order) != 0) {
+      c_opts.set(RBD_IMAGE_OPTION_ORDER, order);
+    }
 
-    r = create(c_ioctx, c_name, size, false, features, &order,
-              stripe_unit, stripe_count);
+    r = create(c_ioctx, c_name, size, c_opts);
     if (r < 0) {
       lderr(cct) << "error creating child: " << cpp_strerror(r) << dendl;
       goto err_close_parent;
@@ -1574,13 +1584,13 @@ int invoke_async_request(ImageCtx *ictx, const std::string& request_type,
 
     r = cls_client::set_parent(&c_ioctx, c_imctx->header_oid, pspec, size);
     if (r < 0) {
-      lderr(cct) << "couldn't set parent: " << r << dendl;
+      lderr(cct) << "couldn't set parent: " << cpp_strerror(r) << dendl;
       goto err_close_child;
     }
 
     r = cls_client::add_child(&c_ioctx, RBD_CHILDREN, pspec, c_imctx->id);
     if (r < 0) {
-      lderr(cct) << "couldn't add child: " << r << dendl;
+      lderr(cct) << "couldn't add child: " << cpp_strerror(r) << dendl;
       goto err_close_child;
     }
 
@@ -1591,7 +1601,7 @@ int invoke_async_request(ImageCtx *ictx, const std::string& request_type,
     } else if (r == 0 && !pairs.empty()) {
       r = cls_client::metadata_set(&c_ioctx, c_imctx->header_oid, pairs);
       if (r < 0) {
-        lderr(cct) << "couldn't set metadata: " << r << dendl;
+        lderr(cct) << "couldn't set metadata: " << cpp_strerror(r) << dendl;
         goto err_close_child;
       }
     }
@@ -1828,8 +1838,8 @@ int invoke_async_request(ImageCtx *ictx, const std::string& request_type,
         }
         features_mask |= RBD_FEATURE_EXCLUSIVE_LOCK;
 
-        r = Journal::create(ictx->md_ctx, ictx->id, ictx->journal_commit_age,
-                           ictx->journal_order, ictx->journal_splay_width,
+        r = Journal::create(ictx->md_ctx, ictx->id, ictx->journal_order,
+                           ictx->journal_splay_width,
                            ictx->journal_pool);
         if (r < 0) {
           lderr(cct) << "error creating image journal: " << cpp_strerror(r)
@@ -2671,30 +2681,37 @@ int invoke_async_request(ImageCtx *ictx, const std::string& request_type,
     CephContext *cct = (CephContext *)dest_md_ctx.cct();
     ldout(cct, 20) << "copy " << src->name
                   << (src->snap_name.length() ? "@" + src->snap_name : "")
-                  << " -> " << destname << dendl;
+                  << " -> " << destname << " opts = " << opts << dendl;
 
     src->snap_lock.get_read();
     uint64_t features = src->features;
     uint64_t src_size = src->get_image_size(src->snap_id);
     src->snap_lock.put_read();
-    uint64_t stripe_unit = src->stripe_unit;
-    uint64_t stripe_count = src->stripe_count;
-    opts.get(RBD_IMAGE_OPTION_FEATURES, &features);
-    opts.get(RBD_IMAGE_OPTION_STRIPE_UNIT, &stripe_unit);
-    opts.get(RBD_IMAGE_OPTION_STRIPE_COUNT, &stripe_count);
-    int order = src->order;
-    uint64_t opt_order = 0;
-    if (opts.get(RBD_IMAGE_OPTION_ORDER, &opt_order)) {
-      order = opt_order;
+    if (opts.get(RBD_IMAGE_OPTION_FEATURES, &features) != 0) {
+      opts.set(RBD_IMAGE_OPTION_FEATURES, features);
     }
-
     if (features & ~RBD_FEATURES_ALL) {
       lderr(cct) << "librbd does not support requested features" << dendl;
       return -ENOSYS;
     }
+    uint64_t format = src->old_format ? 1 : 2;
+    if (opts.get(RBD_IMAGE_OPTION_FORMAT, &format) != 0) {
+      opts.set(RBD_IMAGE_OPTION_FORMAT, format);
+    }
+    uint64_t stripe_unit = src->stripe_unit;
+    if (opts.get(RBD_IMAGE_OPTION_STRIPE_UNIT, &stripe_unit) != 0) {
+      opts.set(RBD_IMAGE_OPTION_STRIPE_UNIT, stripe_unit);
+    }
+    uint64_t stripe_count = src->stripe_count;
+    if (opts.get(RBD_IMAGE_OPTION_STRIPE_COUNT, &stripe_count) != 0) {
+      opts.set(RBD_IMAGE_OPTION_STRIPE_COUNT, stripe_count);
+    }
+    uint64_t order = src->order;
+    if (opts.get(RBD_IMAGE_OPTION_ORDER, &order) != 0) {
+      opts.set(RBD_IMAGE_OPTION_ORDER, order);
+    }
 
-    int r = create(dest_md_ctx, destname, src_size, src->old_format,
-                  features, &order, stripe_unit, stripe_count);
+    int r = create(dest_md_ctx, destname, src_size, opts);
     if (r < 0) {
       lderr(cct) << "header creation failed" << dendl;
       return r;