Skip to content

Commit

Permalink
Merge pull request ceph#9818 from ifed01/wip-zero-length-writes
Browse files Browse the repository at this point in the history
os/store_test: uniform zero length writes handling

Reviewed-by: Sage Weil <[email protected]>
  • Loading branch information
liewegas authored Jun 20, 2016
2 parents 0793a28 + 6beb243 commit ba31806
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/os/memstore/MemStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1031,9 +1031,11 @@ int MemStore::_write(const coll_t& cid, const ghobject_t& oid,
return -ENOENT;

ObjectRef o = c->get_or_create_object(oid);
const ssize_t old_size = o->get_size();
o->write(offset, bl);
used_bytes += (o->get_size() - old_size);
if (len > 0) {
const ssize_t old_size = o->get_size();
o->write(offset, bl);
used_bytes += (o->get_size() - old_size);
}

return 0;
}
Expand Down
35 changes: 33 additions & 2 deletions src/test/objectstore/store_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1972,6 +1972,35 @@ TEST_P(StoreTest, MiscFragmentTests) {

}

TEST_P(StoreTest, ZeroLengthWrite) {
ObjectStore::Sequencer osr("test");
int r;
coll_t cid;
ghobject_t hoid(hobject_t(sobject_t("foo", CEPH_NOSNAP)));
{
ObjectStore::Transaction t;
t.create_collection(cid, 0);
t.touch(cid, hoid);
r = apply_transaction(store, &osr, std::move(t));
ASSERT_EQ(r, 0);
}
{
ObjectStore::Transaction t;
bufferlist empty;
t.write(cid, hoid, 1048576, 0, empty);
r = apply_transaction(store, &osr, std::move(t));
ASSERT_EQ(r, 0);
}
struct stat stat;
r = store->stat(cid, hoid, &stat);
ASSERT_EQ(0, r);
ASSERT_EQ(0, stat.st_size);

bufferlist newdata;
r = store->read(cid, hoid, 0, 1048576, newdata);
ASSERT_EQ(0, r);
}

TEST_P(StoreTest, SimpleAttrTest) {
ObjectStore::Sequencer osr("test");
int r;
Expand Down Expand Up @@ -3438,8 +3467,10 @@ class SyntheticWorkloadState {

bufferlist& data = contents[new_obj].data;
if (data.length() <= offset) {
data.append_zero(offset-data.length());
data.append(bl);
if (len > 0) {
data.append_zero(offset-data.length());
data.append(bl);
}
} else {
bufferlist value;
assert(data.length() > offset);
Expand Down

0 comments on commit ba31806

Please sign in to comment.