write(seastore, offset, bl);
}
+ void zero(
+ SeaStore &seastore,
+ CTransaction &t,
+ uint64_t offset,
+ size_t len) {
+ ceph::buffer::list bl;
+ bl.append_zero(len);
+ bufferlist new_contents;
+ if (offset > 0 && contents.length()) {
+ new_contents.substr_of(
+ contents,
+ 0,
+ std::min<size_t>(offset, contents.length())
+ );
+ }
+ new_contents.append_zero(offset - new_contents.length());
+ new_contents.append(bl);
+
+ auto tail_offset = offset + bl.length();
+ if (contents.length() > tail_offset) {
+ bufferlist tail;
+ tail.substr_of(
+ contents,
+ tail_offset,
+ contents.length() - tail_offset);
+ new_contents.append(tail);
+ }
+ contents.swap(new_contents);
+
+ t.zero(
+ cid,
+ oid,
+ offset,
+ len);
+ }
+
+ void zero(
+ SeaStore &seastore,
+ uint64_t offset,
+ size_t len) {
+ CTransaction t;
+ zero(seastore, t, offset, len);
+ seastore.do_transaction(
+ coll,
+ std::move(t)).get0();
+ }
+
void read(
SeaStore &seastore,
uint64_t offset,
test_obj.remove(*seastore);
});
}
+
+TEST_F(seastore_test_t, zero)
+{
+ run_async([this] {
+ auto &test_obj = get_object(make_oid(0));
+ test_obj.write(
+ *seastore,
+ 1024,
+ 1024,
+ 'a');
+ test_obj.read(
+ *seastore,
+ 1024,
+ 1024);
+ test_obj.check_size(*seastore);
+ test_obj.zero(*seastore, 1124, 200);
+ test_obj.read(
+ *seastore,
+ 1024,
+ 1024);
+ test_obj.check_size(*seastore);
+
+ remove_object(test_obj);
+ });
+}