]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librados: implement/document tmap_{get,put}
authorSage Weil <sage@newdream.net>
Wed, 10 Aug 2011 23:07:33 +0000 (16:07 -0700)
committerSage Weil <sage@newdream.net>
Wed, 10 Aug 2011 23:07:33 +0000 (16:07 -0700)
These aren't strictly necessary now (you can just read the raw object or
do a writefull and get the same thing) but this way we document the format
and can change the backend to be smarter in the future without changing up
the interface.

Signed-off-by: Sage Weil <sage@newdream.net>
src/include/rados/librados.h
src/include/rados/librados.hpp
src/librados.cc

index 185fefb6eb84552b56dc54b71678884885e150da..939406ba1692cfcca449d7467f7e8e407567723a 100644 (file)
@@ -250,6 +250,44 @@ int rados_stat(rados_ioctx_t io, const char *o, uint64_t *psize, time_t *pmtime)
  */
 int rados_tmap_update(rados_ioctx_t io, const char *o, const char *cmdbuf, size_t cmdbuflen);
 
+/**
+ * Store complete tmap (trivial map) object
+ *
+ * Put a full tmap object into the store, replacing what was there.
+ *
+ * The format of the @buf buffer is:
+ *    4 bytes - length of header (little endian)
+ *    N bytes - header data
+ *    4 bytes - number of keys (little endian)
+ * and for each key,
+ *    4 bytes - key name length (little endian)
+ *    N bytes - key name
+ *    4 bytes - value length (little endian)
+ *    M bytes - value data
+ *
+ * @param io ioctx
+ * @param o object name
+ * @param buf buffer
+ * @param buflen buffer length
+ * @return 0 for success or negative error code
+ */
+int rados_tmap_put(rados_ioctx_t io, const char *o, const char *buf, size_t buflen);
+
+/**
+ * Fetch complete tmap (trivial map) object
+ *
+ * Read a full tmap object.  See rados_tmap_put() for the format the
+ * data is returned in.  If the supplied buffer isn't big enough,
+ * returns -ERANGE.
+ *
+ * @param io ioctx
+ * @param o object name
+ * @param buf buffer
+ * @param buflen buffer length
+ * @return 0 for success or negative error code
+ */
+int rados_tmap_get(rados_ioctx_t io, const char *o, char *buf, size_t buflen);
+
 int rados_exec(rados_ioctx_t io, const char *oid, const char *cls, const char *method,
               const char *in_buf, size_t in_len, char *buf, size_t out_len);
 
index 0b634c19757c8cc157ba2b079b9e7de2238da88a..ca55707828c592940614860eb0c64939f143075c 100644 (file)
@@ -247,6 +247,8 @@ namespace librados
     int exec(const std::string& oid, const char *cls, const char *method,
             bufferlist& inbl, bufferlist& outbl);
     int tmap_update(const std::string& oid, bufferlist& cmdbl);
+    int tmap_put(const std::string& oid, bufferlist& bl);
+    int tmap_get(const std::string& oid, bufferlist& bl);
 
     void snap_set_read(snap_t seq);
     int selfmanaged_snap_set_write_ctx(snap_t seq, std::vector<snap_t>& snaps);
index 6986a21e101d590f7993e17d08e4e5d702ed9142..678e0cef0386e27ebe80bc3f8c2b59385a299d5e 100644 (file)
@@ -595,6 +595,9 @@ public:
   int trunc(IoCtxImpl& io, const object_t& oid, uint64_t size);
 
   int tmap_update(IoCtxImpl& io, const object_t& oid, bufferlist& cmdbl);
+  int tmap_put(IoCtxImpl& io, const object_t& oid, bufferlist& bl);
+  int tmap_get(IoCtxImpl& io, const object_t& oid, bufferlist& bl);
+
   int exec(IoCtxImpl& io, const object_t& oid, const char *cls, const char *method, bufferlist& inbl, bufferlist& outbl);
 
   int getxattr(IoCtxImpl& io, const object_t& oid, const char *name, bufferlist& bl);
@@ -1999,8 +2002,7 @@ trunc(IoCtxImpl& io, const object_t& oid, uint64_t size)
   return r;
 }
 
-int librados::RadosClient::
-tmap_update(IoCtxImpl& io, const object_t& oid, bufferlist& cmdbl)
+int librados::RadosClient::tmap_update(IoCtxImpl& io, const object_t& oid, bufferlist& cmdbl)
 {
   utime_t ut = ceph_clock_now(cct);
 
@@ -2035,6 +2037,75 @@ tmap_update(IoCtxImpl& io, const object_t& oid, bufferlist& cmdbl)
   return r;
 }
 
+int librados::RadosClient::tmap_put(IoCtxImpl& io, const object_t& oid, bufferlist& bl)
+{
+  utime_t ut = ceph_clock_now(cct);
+
+  /* can't write to a snapshot */
+  if (io.snap_seq != CEPH_NOSNAP)
+    return -EROFS;
+
+  Mutex mylock("RadosClient::tmap_put::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;
+  prepare_assert_ops(&io, &wr);
+  wr.tmap_put(bl);
+  objecter->mutate(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::tmap_get(IoCtxImpl& io, const object_t& oid, bufferlist& bl)
+{
+  utime_t ut = ceph_clock_now(cct);
+
+  /* can't write to a snapshot */
+  if (io.snap_seq != CEPH_NOSNAP)
+    return -EROFS;
+
+  Mutex mylock("RadosClient::tmap_put::mylock");
+  Cond cond;
+  bool done;
+  int r;
+  Context *onack = new C_SafeCond(&mylock, &cond, &done, &r);
+  eversion_t ver;
+
+  bufferlist outbl;
+
+  lock.Lock();
+  ::ObjectOperation rd;
+  prepare_assert_ops(&io, &rd);
+  rd.tmap_get();
+  objecter->read(oid, io.oloc, rd, io.snap_seq, &bl, 0, onack, &ver);
+  lock.Unlock();
+
+  mylock.Lock();
+  while (!done)
+    cond.Wait(mylock);
+  mylock.Unlock();
+
+  set_sync_op_version(io, ver);
+
+  return r;
+}
+
 
 int librados::RadosClient::
 exec(IoCtxImpl& io, const object_t& oid, const char *cls, const char *method,
@@ -2882,13 +2953,24 @@ exec(const std::string& oid, const char *cls, const char *method,
   return io_ctx_impl->client->exec(*io_ctx_impl, obj, cls, method, inbl, outbl);
 }
 
-int librados::IoCtx::
-tmap_update(const std::string& oid, bufferlist& cmdbl)
+int librados::IoCtx::tmap_update(const std::string& oid, bufferlist& cmdbl)
 {
   object_t obj(oid);
   return io_ctx_impl->client->tmap_update(*io_ctx_impl, obj, cmdbl);
 }
 
+int librados::IoCtx::tmap_put(const std::string& oid, bufferlist& bl)
+{
+  object_t obj(oid);
+  return io_ctx_impl->client->tmap_put(*io_ctx_impl, obj, bl);
+}
+
+int librados::IoCtx::tmap_get(const std::string& oid, bufferlist& bl)
+{
+  object_t obj(oid);
+  return io_ctx_impl->client->tmap_get(*io_ctx_impl, obj, bl);
+}
+
 int librados::IoCtx::operate(const std::string& oid, librados::ObjectWriteOperation *o, bufferlist *pbl)
 {
   object_t obj(oid);
@@ -3946,6 +4028,29 @@ extern "C" int rados_tmap_update(rados_ioctx_t io, const char *o, const char *cm
   return ctx->client->tmap_update(*ctx, oid, cmdbl);
 }
 
+extern "C" int rados_tmap_put(rados_ioctx_t io, const char *o, const char *buf, size_t buflen)
+{
+  librados::IoCtxImpl *ctx = (librados::IoCtxImpl *)io;
+  object_t oid(o);
+  bufferlist bl;
+  bl.append(buf, buflen);
+  return ctx->client->tmap_put(*ctx, oid, bl);
+}
+
+extern "C" int rados_tmap_get(rados_ioctx_t io, const char *o, char *buf, size_t buflen)
+{
+  librados::IoCtxImpl *ctx = (librados::IoCtxImpl *)io;
+  object_t oid(o);
+  bufferlist bl;
+  int r = ctx->client->tmap_get(*ctx, oid, bl);
+  if (r < 0)
+    return r;
+  if (bl.length() > buflen)
+    return -ERANGE;
+  bl.copy(0, bl.length(), buf);
+  return bl.length();
+}
+
 extern "C" int rados_exec(rados_ioctx_t io, const char *o, const char *cls, const char *method,
                          const char *inbuf, size_t in_len, char *buf, size_t out_len)
 {