return 0;
}
-int cls_cxx_create(cls_method_context_t hctx, bool exclusive)
+int cls_cxx_create(cls_method_context_t hctx, const bool exclusive)
{
- return 0;
+ OSDOp op{CEPH_OSD_OP_CREATE};
+ op.op.flags = (exclusive ? CEPH_OSD_OP_FLAG_EXCL : 0);
+ try {
+ reinterpret_cast<ceph::osd::OpsExecuter*>(hctx)->do_osd_op(op).get();
+ return 0;
+ } catch (ceph::osd::error& e) {
+ return -e.code().value();
+ }
}
int cls_cxx_remove(cls_method_context_t hctx)
return do_read_op([&osd_op] (auto& backend, const auto& os) {
return backend.getxattr(os, osd_op);
});
+ case CEPH_OSD_OP_CREATE:
+ return do_write_op([&osd_op] (auto& backend, auto& os, auto& txn) {
+ return backend.create(os, osd_op, txn);
+ });
case CEPH_OSD_OP_WRITE:
return do_write_op([&osd_op] (auto& backend, auto& os, auto& txn) {
return backend.write(os, osd_op, txn);
return seastar::now();
}
+seastar::future<> PGBackend::create(
+ ObjectState& os,
+ const OSDOp& osd_op,
+ ceph::os::Transaction& txn)
+{
+ const int flags = le32_to_cpu(osd_op.op.flags);
+ if (os.exists && !os.oi.is_whiteout() && (flags & CEPH_OSD_OP_FLAG_EXCL)) {
+ // this is an exclusive create
+ throw ceph::osd::make_error(-EEXIST);
+ }
+
+ if (osd_op.indata.length()) {
+ // handle the legacy. `category` is no longer implemented.
+ try {
+ auto p = osd_op.indata.cbegin();
+ std::string category;
+ decode(category, p);
+ } catch (buffer::error&) {
+ throw ceph::osd::invalid_argument();
+ }
+ }
+ maybe_create_new_object(os, txn);
+ txn.nop();
+ return seastar::now();
+}
+
seastar::future<> PGBackend::remove(ObjectState& os,
ceph::os::Transaction& txn)
{
seastar::future<> stat(
const ObjectState& os,
OSDOp& osd_op);
+
+ seastar::future<> create(
+ ObjectState& os,
+ const OSDOp& osd_op,
+ ceph::os::Transaction& trans);
seastar::future<> remove(
ObjectState& os,
ceph::os::Transaction& txn);