*/
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);
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);
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);
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,
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);
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)
{