Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os/bluestore: move assert of read/write to base class #17033

Merged
merged 1 commit into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/os/bluestore/BlockDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ class BlockDevice {
virtual int invalidate_cache(uint64_t off, uint64_t len) = 0;
virtual int open(const std::string& path) = 0;
virtual void close() = 0;

protected:
bool is_valid_io(uint64_t off, uint64_t len) const {
return (off % block_size == 0 &&
len % block_size == 0 &&
len > 0 &&
off < size &&
off + len <= size);
}
};

#endif //CEPH_OS_BLUESTORE_BLOCKDEVICE_H
12 changes: 2 additions & 10 deletions src/os/bluestore/KernelDevice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -567,11 +567,7 @@ int KernelDevice::write(
dout(20) << __func__ << " 0x" << std::hex << off << "~" << len << std::dec
<< (buffered ? " (buffered)" : " (direct)")
<< dendl;
assert(off % block_size == 0);
assert(len % block_size == 0);
assert(len > 0);
assert(off < size);
assert(off + len <= size);
assert(is_valid_io(off, len));

if ((!buffered || bl.get_num_buffers() >= IOV_MAX) &&
bl.rebuild_aligned_size_and_memory(block_size, block_size)) {
Expand Down Expand Up @@ -653,11 +649,7 @@ int KernelDevice::read(uint64_t off, uint64_t len, bufferlist *pbl,
dout(5) << __func__ << " 0x" << std::hex << off << "~" << len << std::dec
<< (buffered ? " (buffered)" : " (direct)")
<< dendl;
assert(off % block_size == 0);
assert(len % block_size == 0);
assert(len > 0);
assert(off < size);
assert(off + len <= size);
assert(is_valid_io(off, len));

_aio_log_start(ioc, off, len);

Expand Down
18 changes: 3 additions & 15 deletions src/os/bluestore/NVMEDevice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -988,11 +988,7 @@ int NVMEDevice::aio_write(
uint64_t len = bl.length();
dout(20) << __func__ << " " << off << "~" << len << " ioc " << ioc
<< " buffered " << buffered << dendl;
assert(off % block_size == 0);
assert(len % block_size == 0);
assert(len > 0);
assert(off < size);
assert(off + len <= size);
assert(is_valid_io(off, len));

Task *t = new Task(this, IOCommand::WRITE_COMMAND, off, len);

Expand Down Expand Up @@ -1036,11 +1032,7 @@ int NVMEDevice::read(uint64_t off, uint64_t len, bufferlist *pbl,
bool buffered)
{
dout(5) << __func__ << " " << off << "~" << len << " ioc " << ioc << dendl;
assert(off % block_size == 0);
assert(len % block_size == 0);
assert(len > 0);
assert(off < size);
assert(off + len <= size);
assert(is_valid_io(off, len));

Task *t = new Task(this, IOCommand::READ_COMMAND, off, len, 1);
bufferptr p = buffer::create_page_aligned(len);
Expand Down Expand Up @@ -1071,11 +1063,7 @@ int NVMEDevice::aio_read(
IOContext *ioc)
{
dout(20) << __func__ << " " << off << "~" << len << " ioc " << ioc << dendl;
assert(off % block_size == 0);
assert(len % block_size == 0);
assert(len > 0);
assert(off < size);
assert(off + len <= size);
assert(is_valid_io(off, len));

Task *t = new Task(this, IOCommand::READ_COMMAND, off, len);

Expand Down
13 changes: 4 additions & 9 deletions src/os/bluestore/PMEMDevice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@ int PMEMDevice::write(uint64_t off, bufferlist& bl, bool buffered)
{
uint64_t len = bl.length();
dout(20) << __func__ << " " << off << "~" << len << dendl;
assert(len > 0);
assert(off < size);
assert(off + len <= size);
assert(is_valid_io(off, len));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is different here. Only 3 assert statements

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@majianpeng For this place, I think the original code misses 2 assert, do you agree?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, PMEMDevice is based on byte address. So offset && length are not limited by block_size (in fact by directIO requirement)


dout(40) << "data: ";
bl.hexdump(*_dout);
Expand Down Expand Up @@ -261,9 +259,7 @@ int PMEMDevice::read(uint64_t off, uint64_t len, bufferlist *pbl,
bool buffered)
{
dout(5) << __func__ << " " << off << "~" << len << dendl;
assert(len > 0);
assert(off < size);
assert(off + len <= size);
assert(is_valid_io(off, len));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto


bufferptr p = buffer::create_page_aligned(len);
memcpy(p.c_str(), addr + off, len);
Expand All @@ -286,9 +282,8 @@ int PMEMDevice::aio_read(uint64_t off, uint64_t len, bufferlist *pbl,

int PMEMDevice::read_random(uint64_t off, uint64_t len, char *buf, bool buffered)
{
assert(len > 0);
assert(off < size);
assert(off + len <= size);
dout(5) << __func__ << " " << off << "~" << len << dendl;
assert(is_valid_io(off, len));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto


memcpy(buf, addr + off, len);
return 0;
Expand Down
7 changes: 7 additions & 0 deletions src/os/bluestore/PMEMDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ class PMEMDevice : public BlockDevice {
int invalidate_cache(uint64_t off, uint64_t len) override;
int open(const std::string &path) override;
void close() override;

private:
bool is_valid_io(uint64_t off, uint64_t len) const {
return (len > 0 &&
off < size &&
off + len <= size);
}
};

#endif