return (ret < 0 ? ret : s->err.ret);
} /* process_request */
-int start_continued_request(RGWLibContinuedReq* req)
+int RGWLibProcess::start_request(RGWLibContinuedReq* req)
{
int ret = 0;
+ int op_ret = 0;
dout(1) << "====== " << __func__
<< " starting new continued request req=" << hex << req << dec
op->pre_exec();
req->exec_start();
+ op_ret = op->get_ret();
+
done:
- return ret;
+ return (ret < 0 ? ret : s->err.ret);
}
-int finish_continued_request(RGWLibContinuedReq* req)
+int RGWLibProcess::finish_request(RGWLibContinuedReq* req)
{
+ return 0;
}
int RGWLibFrontend::init()
return fhr;
} /* RGWLibFS::stat_leaf */
+int RGWFileHandle::write(uint64_t off, size_t len, size_t *bytes_written,
+ void *buffer)
+{
+ using std::get;
+ lock_guard guard(mtx);
+
+ int rc = 0;
+ buffer::list bl;
+ bl.push_back(
+ buffer::create_static(len, static_cast<char*>(buffer)));
+
+ file* f = get<file>(&variant_type);
+ if (! f->write_req) {
+ /* start */
+ std::string object_name = full_object_name();
+ f->write_req =
+ new RGWWriteRequest(fs->get_context(), fs->get_user(), bucket_name(),
+ object_name);
+ rc = librgw.get_fe()->start_req(f->write_req);
+ }
+
+ f->write_req->put_data(off, bl);
+ rc = f->write_req->exec_continue();
+
+ size_t min_size = off + len;
+ if (min_size > get_size())
+ set_size(min_size);
+
+ *bytes_written = (rc == 0) ? len : 0;
+ return rc;
+} /* RGWFileHandle::write */
+
+RGWFileHandle::file::~file()
+{
+ delete write_req;
+}
+
/* librgw */
extern "C" {
RGWFileHandle* rgw_fh = get_rgwfh(fh);
if (! rgw_fh->is_file())
- return -EINVAL;
-
- /* XXXX testing only */
- buffer::list bl;
- bl.push_back(
- buffer::create_static(length /* XXX size */, static_cast<char*>(buffer)));
-
- /* XXX */
- std::string oname = rgw_fh->full_object_name();
- RGWPutObjRequest req(cct, fs->get_user(), rgw_fh->bucket_name(),
- oname, bl);
-
- int rc = librgw.get_fe()->execute_req(&req);
-
- /* XXX move into request */
- size_t min_size = offset+length;
- if (min_size > rgw_fh->get_size())
- rgw_fh->set_size(min_size);
+ return -EISDIR;
- *bytes_written = (rc == 0) ? req.bytes_written : 0;
+ if (! rgw_fh->is_open())
+ return -EPERM;
- return rc;
+ return rgw_fh->write(offset, length, bytes_written, buffer);
}
/*
class RGWLibFS;
class RGWFileHandle;
+ class RGWWriteRequest;
typedef boost::intrusive_ptr<RGWFileHandle> RGWFHRef;
} state;
struct file {
+ RGWWriteRequest* write_req;
+ file() : write_req(nullptr) {}
+ ~file();
};
struct directory {
return EPERM;
}
+ int write(uint64_t off, size_t len, size_t *nbytes, void *buffer);
+ int write_finish();
+
void close() {
lock_guard guard(mtx);
flags &= ~FLAG_OPEN;
public:
const std::string& bucket_name;
const std::string& obj_name;
- buffer::list& bl; /* XXX */
+ buffer::list bl;
+ off_t last_off;
+ off_t next_off;
size_t bytes_written;
RGWWriteRequest(CephContext* _cct, RGWUserInfo *_user,
- const std::string& _bname, const std::string& _oname,
- buffer::list& _bl)
+ const std::string& _bname, const std::string& _oname)
: RGWLibContinuedReq(_cct, _user), bucket_name(_bname), obj_name(_oname),
- bl(_bl), bytes_written(0) {
+ last_off(0), next_off(0), bytes_written(0) {
magic = 81;
op = this;
}
return len;
}
+ void put_data(off_t off, buffer::list& _bl) {
+ next_off = off;
+ bl.claim(_bl);
+ }
+
virtual int exec_start() {
return 0;
}
virtual int exec_continue() {
+ if (next_off != last_off)
+ return -EIO;
+ /* XXX consume bl */
return 0;
}
void set_access_key(RGWAccessKey& key) { access_key = key; }
/* requests w/continue semantics */
- int start_continued_request(RGWLibContinuedReq* req);
- int finish_continued_request(RGWLibContinuedReq* req);
+ int start_request(RGWLibContinuedReq* req);
+ int finish_request(RGWLibContinuedReq* req);
}; /* RGWLibProcess */
class RGWLibFrontend : public RGWProcessFrontend {
return static_cast<RGWLibProcess*>(pprocess)->process_request(req); // !async
}
+ inline int start_req(RGWLibContinuedReq* req) {
+ return static_cast<RGWLibProcess*>(pprocess)->start_request(req);
+ }
+
+ inline int finish_req(RGWLibContinuedReq* req) {
+ return static_cast<RGWLibProcess*>(pprocess)->finish_request(req);
+ }
+
}; /* RGWLibFrontend */
#endif /* RGW_LIB_H */