]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librados: add with_reference flag when redirect or chunk is enabled
authormyoungwon oh <omwmw@sk.com>
Tue, 27 Feb 2018 14:33:22 +0000 (23:33 +0900)
committermyoungwon oh <omwmw@sk.com>
Fri, 13 Apr 2018 17:34:27 +0000 (02:34 +0900)
Signed-off-by: Myoungwon Oh <omwmw@sk.com>
src/include/rados.h
src/include/rados/librados.hpp
src/librados/librados.cc
src/osdc/Objecter.h
src/tools/rados/rados.cc

index c89e76059a98ea54d012b3a32d6295f628b920f6..959a76d12348e0394b4f50319197ae85f7a61d23 100644 (file)
@@ -468,6 +468,7 @@ enum {
        CEPH_OSD_OP_FLAG_FADVISE_WILLNEED   = 0x10,/* data will be accessed in the near future */
        CEPH_OSD_OP_FLAG_FADVISE_DONTNEED   = 0x20,/* data will not be accessed in the near future */
        CEPH_OSD_OP_FLAG_FADVISE_NOCACHE   = 0x40, /* data will be accessed only once by this client */
+       CEPH_OSD_OP_FLAG_WITH_REFERENCE   = 0x80, /* need reference couting */
 };
 
 #define EOLDSNAPC    85  /* ORDERSNAP flag set; writer has old snapc*/
index 5c7befc49e4e16abc01295e9f036087926c4c441..39d402ce08d4c388386a1b53511f9acdb1ffb12f 100644 (file)
@@ -469,9 +469,9 @@ namespace librados
      * Set redirect target
      */
     void set_redirect(const std::string& tgt_obj, const IoCtx& tgt_ioctx,
-                     uint64_t tgt_version);
+                     uint64_t tgt_version, int flag = 0);
     void set_chunk(uint64_t src_offset, uint64_t src_length, const IoCtx& tgt_ioctx,
-                   std::string tgt_oid, uint64_t tgt_offset);
+                   std::string tgt_oid, uint64_t tgt_offset, int flag = 0);
     void tier_promote();
 
 
index b7315045b191c1defd8aec0f4d0dbabfccc2d67f..7289a021312b68729b7fedd233fb6aa5097c0e69 100644 (file)
@@ -607,22 +607,24 @@ void librados::ObjectReadOperation::cache_evict()
 
 void librados::ObjectWriteOperation::set_redirect(const std::string& tgt_obj, 
                                                  const IoCtx& tgt_ioctx,
-                                                 uint64_t tgt_version)
+                                                 uint64_t tgt_version,
+                                                 int flag)
 {
   ::ObjectOperation *o = &impl->o;
   o->set_redirect(object_t(tgt_obj), tgt_ioctx.io_ctx_impl->snap_seq,
-                         tgt_ioctx.io_ctx_impl->oloc, tgt_version);
+                         tgt_ioctx.io_ctx_impl->oloc, tgt_version, flag);
 }
 
 void librados::ObjectWriteOperation::set_chunk(uint64_t src_offset,
                                               uint64_t src_length,
                                               const IoCtx& tgt_ioctx,
                                               string tgt_oid,
-                                              uint64_t tgt_offset)
+                                              uint64_t tgt_offset,
+                                              int flag)
 {
   ::ObjectOperation *o = &impl->o;
   o->set_chunk(src_offset, src_length, 
-              tgt_ioctx.io_ctx_impl->oloc, object_t(tgt_oid), tgt_offset);
+              tgt_ioctx.io_ctx_impl->oloc, object_t(tgt_oid), tgt_offset, flag);
 }
 
 void librados::ObjectWriteOperation::tier_promote()
index d2507dcb6b5ec76ad99de7e85912c3e5bf39e59b..e7733c98694a64aadd7b5418a424270def26256a 100644 (file)
@@ -1134,22 +1134,24 @@ struct ObjectOperation {
    * Extensible tier
    */
   void set_redirect(object_t tgt, snapid_t snapid, object_locator_t tgt_oloc, 
-                   version_t tgt_version) {
+                   version_t tgt_version, int flag) {
     OSDOp& osd_op = add_op(CEPH_OSD_OP_SET_REDIRECT);
     osd_op.op.copy_from.snapid = snapid;
     osd_op.op.copy_from.src_version = tgt_version;
     encode(tgt, osd_op.indata);
     encode(tgt_oloc, osd_op.indata);
+    set_last_op_flags(flag);
   }
 
   void set_chunk(uint64_t src_offset, uint64_t src_length, object_locator_t tgt_oloc,
-                object_t tgt_oid, uint64_t tgt_offset) {
+                object_t tgt_oid, uint64_t tgt_offset, int flag) {
     OSDOp& osd_op = add_op(CEPH_OSD_OP_SET_CHUNK);
     encode(src_offset, osd_op.indata);
     encode(src_length, osd_op.indata);
     encode(tgt_oloc, osd_op.indata);
     encode(tgt_oid, osd_op.indata);
     encode(tgt_offset, osd_op.indata);
+    set_last_op_flags(flag);
   }
 
   void tier_promote() {
index 78feb4c38d650c743b7400701dc6a212fc340ce4..de4427b59b3a57007d7a46ecef5f695ed28b891d 100644 (file)
@@ -126,9 +126,9 @@ void usage(ostream& out)
 "   listwatchers <obj-name>          list the watchers of this object\n"
 "   set-alloc-hint <obj-name> <expected-object-size> <expected-write-size>\n"
 "                                    set allocation hint for an object\n"
-"   set-redirect <object A> --target-pool <caspool> <target object A>\n"
+"   set-redirect <object A> --target-pool <caspool> <target object A> [--with-reference]\n"
 "                                    set redirect target\n"
-"   set-chunk <object A> <offset> <length> --target-pool <caspool> <target object A> <taget-offset>\n"
+"   set-chunk <object A> <offset> <length> --target-pool <caspool> <target object A> <taget-offset> [--with-reference]\n"
 "                                    convert an object to chunked object\n"
 "   tier-promote <obj-name>         promote the object to the base tier\n"
 "\n"
@@ -1725,6 +1725,7 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,
   bool omap_key_valid = false;
   std::string omap_key;
   std::string omap_key_pretty;
+  bool with_reference = false;
 
   Rados rados;
   IoCtx io_ctx;
@@ -1940,6 +1941,10 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,
         omap_key_pretty = "(binary key)";
     }
   }
+  i = opts.find("with-reference");
+  if (i != opts.end()) {
+    with_reference = true;
+  }
 
   // open rados
   ret = rados.init_with_context(g_ceph_context);
@@ -3597,7 +3602,11 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,
     }
 
     ObjectWriteOperation op;
-    op.set_redirect(target_obj, target_ctx, 0);
+    if (with_reference) {
+      op.set_redirect(target_obj, target_ctx, 0, CEPH_OSD_OP_FLAG_WITH_REFERENCE);
+    } else {
+      op.set_redirect(target_obj, target_ctx, 0);
+    }
     ret = io_ctx.operate(nargs[1], &op);
     if (ret < 0) {
       cerr << "error set-redirect " << pool_name << "/" << nargs[1] << " => " << target << "/" << target_obj << ": " << cpp_strerror(ret) << std::endl;
@@ -3643,7 +3652,11 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts,
     IoCtx target_ctx;
     ret = rados.ioctx_create(target, target_ctx);
     ObjectWriteOperation op;
-    op.set_chunk(offset, length, target_ctx, tgt_oid, tgt_offset);
+    if (with_reference) {
+      op.set_chunk(offset, length, target_ctx, tgt_oid, tgt_offset, CEPH_OSD_OP_FLAG_WITH_REFERENCE);
+    } else {
+      op.set_chunk(offset, length, target_ctx, tgt_oid, tgt_offset);
+    }
     ret = io_ctx.operate(nargs[1], &op);
     if (ret < 0) {
       cerr << "error set-chunk " << pool_name << "/" << nargs[1] << " " << " offset " << offset
@@ -3908,6 +3921,8 @@ int main(int argc, const char **argv)
       opts["with-clones"] = "true";
     } else if (ceph_argparse_witharg(args, i, &val, "--omap-key-file", (char*)NULL)) {
       opts["omap-key-file"] = val;
+    } else if (ceph_argparse_flag(args, i, "--with-reference", (char*)NULL)) {
+      opts["with-reference"] = "true";
     } else {
       if (val[0] == '-')
         usage_exit();