void zero(uint64_t off, uint64_t len);
void rmxattr(const char *name);
void setxattr(const char *name, const bufferlist& bl);
- void cmpxattr(const char *name, const bufferlist& bl);
+ void cmpxattr(const char *name, uint8_t op, const bufferlist& bl);
+ void cmpxattr(const char *name, uint8_t op, uint64_t v);
void tmap_update(const bufferlist& cmdbl);
void clone_range(uint64_t dst_off,
const std::string& src_oid, uint64_t src_off,
friend class Rados;
};
- /* IoCtx : This is a context in which we can perform I/O.
+ /*
+ * ObjectReadOperation : compount object operation that return value
+ * Batch multiple object operations into a single request, to be applied
+ * atomically.
+ */
+ class ObjectReadOperation
+ {
+ public:
+ ObjectReadOperation();
+ ~ObjectReadOperation();
+
+ void stat();
+ void getxattr(const char *name);
+ void getxattrs();
+
+ private:
+ ObjectOperationImpl *impl;
+ ObjectReadOperation(const ObjectReadOperation& rhs);
+ ObjectReadOperation& operator=(const ObjectReadOperation& rhs);
+ friend class IoCtx;
+ friend class Rados;
+ }; /* IoCtx : This is a context in which we can perform I/O.
* It includes a Pool,
*
* Typical use (error checking omitted):
// compound object operations
int operate(const std::string& oid, ObjectOperation *op, bufferlist *pbl);
+ int operate(const std::string& oid, ObjectReadOperation *op, bufferlist *pbl);
int aio_operate(const std::string& oid, AioCompletion *c, ObjectOperation *op, bufferlist *pbl);
// watch/notify
}
};
+void librados::ObjectReadOperation::stat()
+{
+ ::ObjectOperation *o = (::ObjectOperation *)impl;
+ o->add_op(CEPH_OSD_OP_STAT);
+}
+
+void librados::ObjectReadOperation::getxattr(const char *name)
+{
+ ::ObjectOperation *o = (::ObjectOperation *)impl;
+ o->getxattr(name);
+}
+
+void librados::ObjectReadOperation::getxattrs()
+{
+ ::ObjectOperation *o = (::ObjectOperation *)impl;
+ o->getxattrs();
+}
void librados::ObjectOperation::create(bool exclusive)
{
o->setxattr(name, v);
}
-void librados::ObjectOperation::cmpxattr(const char *name, const bufferlist& v)
+void librados::ObjectOperation::cmpxattr(const char *name, uint8_t op, const bufferlist& v)
+{
+ ::ObjectOperation *o = (::ObjectOperation *)impl;
+ o->cmpxattr(name, op, CEPH_OSD_CMPXATTR_MODE_STRING, v);
+}
+
+void librados::ObjectOperation::cmpxattr(const char *name, uint8_t op, uint64_t v)
{
::ObjectOperation *o = (::ObjectOperation *)impl;
- o->cmpxattr(name, v);
+ bufferlist bl;
+ ::encode(v, bl);
+ o->cmpxattr(name, op, CEPH_OSD_CMPXATTR_MODE_U64, bl);
}
void librados::ObjectOperation::tmap_update(const bufferlist& cmdbl)
int list(Objecter::ListContext *context, int max_entries);
int operate(IoCtxImpl& io, const object_t& oid, ::ObjectOperation *o, bufferlist *pbl);
+ int operate_read(IoCtxImpl& io, const object_t& oid, ::ObjectOperation *o, bufferlist *pbl);
int aio_operate(IoCtxImpl& io, const object_t& oid, ::ObjectOperation *o, AioCompletionImpl *c, bufferlist *pbl);
struct C_aio_Ack : public Context {
return r;
}
+int librados::RadosClient::
+operate_read(IoCtxImpl& io, const object_t& oid, ::ObjectOperation *o, bufferlist *pbl)
+{
+ utime_t ut = ceph_clock_now(cct);
+
+ /* can't write to a snapshot */
+ if (io.snap_seq != CEPH_NOSNAP)
+ return -EINVAL;
+
+ Mutex mylock("RadosClient::mutate::mylock");
+ Cond cond;
+ bool done;
+ int r;
+ eversion_t ver;
+
+ Context *onack = new C_SafeCond(&mylock, &cond, &done, &r);
+
+ lock.Lock();
+ objecter->read(oid, io.oloc,
+ *o, io.snap_seq, pbl, 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::
aio_operate(IoCtxImpl& io, const object_t& oid, ::ObjectOperation *o, AioCompletionImpl *c,
bufferlist *pbl)
return io_ctx_impl->client->operate(*io_ctx_impl, obj, (::ObjectOperation*)o->impl, pbl);
}
+int librados::IoCtx::operate(const std::string& oid, librados::ObjectReadOperation *o, bufferlist *pbl)
+{
+ object_t obj(oid);
+ return io_ctx_impl->client->operate_read(*io_ctx_impl, obj, (::ObjectOperation*)o->impl, pbl);
+}
+
int librados::IoCtx::aio_operate(const std::string& oid, AioCompletion *c, librados::ObjectOperation *o, bufferlist *pbl)
{
object_t obj(oid);
delete o;
}
+librados::ObjectReadOperation::ObjectReadOperation()
+{
+ impl = (ObjectOperationImpl *)new ::ObjectOperation;
+}
+
+librados::ObjectReadOperation::~ObjectReadOperation()
+{
+ ::ObjectOperation *o = (::ObjectOperation *)impl;
+ delete o;
+}
+
///////////////////////////// C API //////////////////////////////
extern "C" int rados_create(rados_t *pcluster, const char * const id)
{
ops[s].data.append(name);
ops[s].data.append(data);
}
+ void add_xattr_cmp(int op, const char *name, uint8_t cmp_op, uint8_t cmp_mode, const bufferlist& data) {
+ int s = ops.size();
+ ops.resize(s+1);
+ ops[s].op.op = op;
+ ops[s].op.xattr.name_len = (name ? strlen(name) : 0);
+ ops[s].op.xattr.value_len = data.length();
+ ops[s].op.xattr.cmp_op = cmp_op;
+ ops[s].op.xattr.cmp_mode = cmp_mode;
+ if (name)
+ ops[s].data.append(name);
+ ops[s].data.append(data);
+ }
void add_call(int op, const char *cname, const char *method, bufferlist &indata) {
int s = ops.size();
ops.resize(s+1);
bl.append(s);
add_xattr(CEPH_OSD_OP_SETXATTR, name, bl);
}
- void cmpxattr(const char *name, const bufferlist& bl) {
- add_xattr(CEPH_OSD_OP_CMPXATTR, name, bl);
+ void cmpxattr(const char *name, uint8_t cmp_op, uint8_t cmp_mode, const bufferlist& bl) {
+ add_xattr_cmp(CEPH_OSD_OP_CMPXATTR, name, cmp_op, cmp_mode, bl);
}
void rmxattr(const char *name) {
bufferlist bl;