]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librados: support clone_range
authorYehuda Sadeh <yehuda@hq.newdream.net>
Fri, 3 Jun 2011 18:22:11 +0000 (11:22 -0700)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Fri, 3 Jun 2011 18:22:11 +0000 (11:22 -0700)
src/include/rados/librados.h
src/include/rados/librados.hpp
src/librados.cc
src/osdc/Objecter.h

index b681cfcbe0c16e2bf7e7f83b699d154b2cab05b7..9a603a7541a7e64ccbaa9ee1be31f29ca572bee8 100644 (file)
@@ -141,6 +141,8 @@ uint64_t rados_get_last_version(rados_ioctx_t io);
 
 int rados_write(rados_ioctx_t io, const char *oid, const char *buf, size_t len, uint64_t off);
 int rados_write_full(rados_ioctx_t io, const char *oid, const char *buf, size_t len, uint64_t off);
+int rados_clone_range(rados_ioctx_t io, const char *dst, uint64_t dst_off,
+                      const char *src, uint64_t src_off, size_t len);
 int rados_append(rados_ioctx_t io, const char *oid, const char *buf, size_t len);
 int rados_read(rados_ioctx_t io, const char *oid, char *buf, size_t len, uint64_t off);
 int rados_remove(rados_ioctx_t io, const char *oid);
index 8609777a0a3fadf2e6ba0d2dae6c7d228359b97e..0753ae566e7276bc1864d6159d5d96c175a62b5d 100644 (file)
@@ -156,6 +156,9 @@ namespace librados
     int write(const std::string& oid, bufferlist& bl, size_t len, uint64_t off);
     int append(const std::string& oid, bufferlist& bl, size_t len);
     int write_full(const std::string& oid, bufferlist& bl);
+    int clone_range(const std::string& dst_oid, uint64_t dst_off,
+                   const std::string& src_oid, uint64_t src_off,
+                   size_t len);
     int read(const std::string& oid, bufferlist& bl, size_t len, uint64_t off);
     int remove(const std::string& oid);
     int trunc(const std::string& oid, uint64_t size);
index 7b3ff3ca043d1d1a6b9466a995df10243f004eb6..dbe067bfe200a1c0d7ca8fab4acfe0c036016754 100644 (file)
@@ -213,8 +213,6 @@ void librados::ObjectOperation::tmap_update(const bufferlist& cmdbl)
 
 
 
-
-
 librados::WatchCtx::
 ~WatchCtx()
 {
@@ -443,6 +441,8 @@ public:
   int write(IoCtxImpl& io, const object_t& oid, bufferlist& bl, size_t len, uint64_t off);
   int append(IoCtxImpl& io, const object_t& oid, bufferlist& bl, size_t len);
   int write_full(IoCtxImpl& io, const object_t& oid, bufferlist& bl);
+  int clone_range(IoCtxImpl& io, const object_t& dst_oid, uint64_t dst_offset,
+                  const object_t& src_oid, uint64_t src_offset, uint64_t len);
   int read(IoCtxImpl& io, const object_t& oid, bufferlist& bl, size_t len, uint64_t off);
   int mapext(IoCtxImpl& io, const object_t& oid, uint64_t off, size_t len, std::map<uint64_t,uint64_t>& m);
   int sparse_read(IoCtxImpl& io, const object_t& oid, std::map<uint64_t,uint64_t>& m, bufferlist& bl,
@@ -1354,6 +1354,45 @@ write_full(IoCtxImpl& io, const object_t& oid, bufferlist& bl)
   return r;
 }
 
+int librados::RadosClient::
+clone_range(IoCtxImpl& io, const object_t& dst_oid, uint64_t dst_offset, const object_t& src_oid, uint64_t src_offset, uint64_t len)
+{
+  utime_t ut = g_clock.now();
+
+  /* can't write to a snapshot */
+  if (io.snap_seq != CEPH_NOSNAP)
+    return -EROFS;
+
+  Mutex mylock("RadosClient::clone_range::mylock");
+  Cond cond;
+  bool done;
+  int r;
+  Context *onack = new C_SafeCond(&mylock, &cond, &done, &r);
+  eversion_t ver;
+
+  bufferlist outbl;
+
+  lock.Lock();
+  ::SnapContext snapc;
+  ::ObjectOperation wr;
+  if (io.assert_ver) {
+    wr.assert_version(io.assert_ver);
+    io.assert_ver = 0;
+  }
+  wr.clone_range(src_oid, src_offset, len, dst_offset);
+  objecter->mutate(dst_oid, io.oloc, wr, snapc, ut, 0, onack, NULL, &ver);
+  lock.Unlock();
+
+  mylock.Lock();
+  while (!done)
+    cond.Wait(mylock);
+  mylock.Unlock();
+
+  set_sync_op_version(io, ver);
+
+  return r;
+}
+
 int librados::RadosClient::
 operate(IoCtxImpl& io, const object_t& oid, ::ObjectOperation *o, bufferlist *pbl)
 {
@@ -2376,6 +2415,15 @@ write_full(const std::string& oid, bufferlist& bl)
   return io_ctx_impl->client->write_full(*io_ctx_impl, obj, bl);
 }
 
+int librados::IoCtx::
+clone_range(const std::string& dst_oid, uint64_t dst_off,
+            const std::string& src_oid, uint64_t src_off,
+            size_t len)
+{
+  object_t src(src_oid), dst(dst_oid);
+  return io_ctx_impl->client->clone_range(*io_ctx_impl, dst, dst_off, src, src_off, len);
+}
+
 int librados::IoCtx::
 read(const std::string& oid, bufferlist& bl, size_t len, uint64_t off)
 {
@@ -3113,6 +3161,14 @@ extern "C" int rados_write_full(rados_ioctx_t io, const char *o, const char *buf
   return ctx->client->write_full(*ctx, oid, bl);
 }
 
+extern "C" int rados_clone_range(rados_ioctx_t io, const char *dst, uint64_t dst_off,
+                                 const char *src, uint64_t src_off, size_t len)
+{
+  librados::IoCtxImpl *ctx = (librados::IoCtxImpl *)io;
+  object_t dst_oid(dst), src_oid(src);
+  return ctx->client->clone_range(*ctx, dst_oid, dst_off, src_oid, src_off, len);
+}
+
 extern "C" int rados_trunc(rados_ioctx_t io, const char *o, uint64_t size)
 {
   librados::IoCtxImpl *ctx = (librados::IoCtxImpl *)io;
index 73129bbfc4941edb0a1dc71ee1dce2b5ecc15b27..2a1fc4065f118c0305773a82c433130372e3a27d 100644 (file)
@@ -178,7 +178,7 @@ struct ObjectOperation {
     add_data(CEPH_OSD_OP_SPARSE_READ, off, len, bl);
   }
 
-  void clone_range(object_t& src_oid, uint64_t src_offset, uint64_t len, uint64_t dst_offset) {
+  void clone_range(const object_t& src_oid, uint64_t src_offset, uint64_t len, uint64_t dst_offset) {
     bufferlist bl;
     src_oids.push_back(src_oid);
     add_clone_range(CEPH_OSD_OP_CLONERANGE, dst_offset, len, src_offset, src_oids.size()-1);