diff options
author | Matt Benjamin <mbenjamin@redhat.com> | 2015-10-29 19:58:47 +0100 |
---|---|---|
committer | Matt Benjamin <mbenjamin@redhat.com> | 2016-02-12 18:05:26 +0100 |
commit | 540ce769ceaa860c8d4ff24f4fd2f5adc1ca2abc (patch) | |
tree | e3cac0be2c5ca67112ab640597a53ea1176bd5bc /src | |
parent | librgw: remove junk prints (diff) | |
download | ceph-540ce769ceaa860c8d4ff24f4fd2f5adc1ca2abc.tar.xz ceph-540ce769ceaa860c8d4ff24f4fd2f5adc1ca2abc.zip |
librgw: improve rgw_write and add WRITE_READ_VERIFY
Update rgw_write to return bytes written as an OUT argument,
use and verify in PUT test.
A new WRITE_READ_VERIFY test writes 16 checksummed, 64K data pages
to the object when --bulk specified. The returned write value is
checked, but pages not re-read (yet).
Signed-off-by: Matt Benjamin <mbenjamin@redhat.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/include/rados/rgw_file.h | 2 | ||||
-rw-r--r-- | src/rgw/rgw_file.cc | 5 | ||||
-rw-r--r-- | src/rgw/rgw_file.h | 7 | ||||
-rw-r--r-- | src/test/librgw_file_gp.cc | 32 |
4 files changed, 39 insertions, 7 deletions
diff --git a/src/include/rados/rgw_file.h b/src/include/rados/rgw_file.h index 27c67caaaed..5689d7469cc 100644 --- a/src/include/rados/rgw_file.h +++ b/src/include/rados/rgw_file.h @@ -204,7 +204,7 @@ int rgw_readv(struct rgw_fs *rgw_fs, */ int rgw_write(struct rgw_fs *rgw_fs, struct rgw_file_handle *fh, uint64_t offset, - size_t length, void *buffer); + size_t length, size_t *bytes_written, void *buffer); /* XXX add release fn and UIO type */ diff --git a/src/rgw/rgw_file.cc b/src/rgw/rgw_file.cc index 89e84e8e982..6136f7848bd 100644 --- a/src/rgw/rgw_file.cc +++ b/src/rgw/rgw_file.cc @@ -347,7 +347,7 @@ int rgw_read(struct rgw_fs *rgw_fs, */ int rgw_write(struct rgw_fs *rgw_fs, struct rgw_file_handle *fh, uint64_t offset, - size_t length, void *buffer) + size_t length, size_t *bytes_written, void *buffer) { CephContext* cct = static_cast<CephContext*>(rgw_fs->rgw); RGWLibFS *fs = static_cast<RGWLibFS*>(rgw_fs->fs_private); @@ -364,8 +364,11 @@ int rgw_write(struct rgw_fs *rgw_fs, /* XXX */ RGWPutObjRequest req(cct, fs->get_user(), rgw_fh->bucket_name(), rgw_fh->object_name(), bl); + int rc = librgw.get_fe()->execute_req(&req); + *bytes_written = (rc == 0) ? req.bytes_written : 0; + return rc; } diff --git a/src/rgw/rgw_file.h b/src/rgw/rgw_file.h index f2b5f532707..02e62f54125 100644 --- a/src/rgw/rgw_file.h +++ b/src/rgw/rgw_file.h @@ -379,12 +379,13 @@ public: const std::string& bucket_name; const std::string& obj_name; buffer::list& bl; /* XXX */ + size_t bytes_written; RGWPutObjRequest(CephContext* _cct, RGWUserInfo *_user, const std::string& _bname, const std::string& _oname, buffer::list& _bl) : RGWLibRequest(_cct, _user), bucket_name(_bname), obj_name(_oname), - bl(_bl) { + bl(_bl), bytes_written(0) { magic = 75; op = this; } @@ -428,7 +429,9 @@ public: virtual int get_data(buffer::list& _bl) { /* XXX for now, use sharing semantics */ _bl.claim(bl); - return _bl.length(); + uint32_t len = _bl.length(); + bytes_written += len; + return len; } virtual void send_response() {} diff --git a/src/test/librgw_file_gp.cc b/src/test/librgw_file_gp.cc index bc3d8058d75..4b9fa9b28cf 100644 --- a/src/test/librgw_file_gp.cc +++ b/src/test/librgw_file_gp.cc @@ -39,6 +39,7 @@ namespace { bool do_pre_list = false; bool do_put = false; + bool do_bulk = false; bool do_get = false; bool do_delete = false; @@ -116,7 +117,7 @@ namespace { } ~ZPageSet() { - for (int ix = 0; ix < pages.size(); ++ix) + for (unsigned int ix = 0; ix < pages.size(); ++ix) delete pages[ix]; free(iovs); } @@ -175,7 +176,7 @@ TEST(LibRGW, LIST_OBJECTS) { } TEST(LibRGW, LOOKUP_OBJECT) { - if (do_get || do_put) { + if (do_get || do_put || do_bulk) { int ret = rgw_lookup(fs, bucket_fh, object_name.c_str(), &object_fh, 0 /* flags */); ASSERT_EQ(ret, 0); @@ -191,9 +192,12 @@ TEST(LibRGW, OBJ_OPEN) { TEST(LibRGW, PUT_OBJECT) { if (do_put) { + size_t nbytes; string data = "hi mom"; // fix this - int ret = rgw_write(fs, object_fh, 0, data.length(), (void*) data.c_str()); + int ret = rgw_write(fs, object_fh, 0, data.length(), &nbytes, + (void*) data.c_str()); ASSERT_EQ(ret, 0); + ASSERT_EQ(nbytes, data.length()); } } @@ -210,6 +214,25 @@ TEST(LibRGW, GET_OBJECT) { } } +TEST(LibRGW, WRITE_READ_VERIFY) +{ + if (do_bulk) { + const int iovcnt = 16; + ZPageSet zp_set1{iovcnt}; // 1M random data in 16 64K pages + struct iovec *iovs = zp_set1.get_iovs(); + + /* read after write POSIX-style */ + size_t nbytes, off = 0; + for (int ix = 0; ix < 16; ++ix, off += 65536) { + struct iovec *iov = &iovs[ix]; + int ret = rgw_write(fs, object_fh, off, 65536, &nbytes, iov->iov_base); + ASSERT_EQ(ret, 0); + ASSERT_EQ(nbytes, size_t(65536)); + } + zp_set1.reset_iovs(); + } +} + TEST(LibRGW, DELETE_OBJECT) { if (do_delete) { int ret = rgw_unlink(fs, bucket_fh, object_name.c_str()); @@ -276,6 +299,9 @@ int main(int argc, char *argv[]) } else if (ceph_argparse_flag(args, arg_iter, "--put", (char*) nullptr)) { do_put = true; + } else if (ceph_argparse_flag(args, arg_iter, "--bulk", + (char*) nullptr)) { + do_bulk = true; } else if (ceph_argparse_flag(args, arg_iter, "--delete", (char*) nullptr)) { do_delete = true; |