Skip to content
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
5 changes: 5 additions & 0 deletions src/os/bluestore/BlockDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class BlockDevice {
uint64_t block_size;
bool support_discard = false;
bool rotational = true;
bool lock_exclusive = true;

public:
aio_callback_t aio_callback;
Expand All @@ -162,6 +163,10 @@ class BlockDevice {

virtual void aio_submit(IOContext *ioc) = 0;

void set_no_exclusive_lock() {
lock_exclusive = false;
}

uint64_t get_size() const { return size; }
uint64_t get_block_size() const { return block_size; }

Expand Down
9 changes: 7 additions & 2 deletions src/os/bluestore/BlueFS.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,17 @@ void BlueFS::_update_logger_stats()
}
}

int BlueFS::add_block_device(unsigned id, const string& path, bool trim)
int BlueFS::add_block_device(unsigned id, const string& path, bool trim,
bool shared_with_bluestore)
{
dout(10) << __func__ << " bdev " << id << " path " << path << dendl;
ceph_assert(id < bdev.size());
ceph_assert(bdev[id] == NULL);
BlockDevice *b = BlockDevice::create(cct, path, NULL, NULL, discard_cb[id], static_cast<void*>(this));
BlockDevice *b = BlockDevice::create(cct, path, NULL, NULL,
discard_cb[id], static_cast<void*>(this));
if (shared_with_bluestore) {
b->set_no_exclusive_lock();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A little convoluted...if shared_with_bluestore is true then lock_exclusive becomes false, but this does look like it'll do the right thing.

int r = b->open(path);
if (r < 0) {
delete b;
Expand Down
3 changes: 2 additions & 1 deletion src/os/bluestore/BlueFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,8 @@ class BlueFS {
void set_slow_device_expander(BlueFSDeviceExpander* a) {
slow_dev_expander = a;
}
int add_block_device(unsigned bdev, const string& path, bool trim);
int add_block_device(unsigned bdev, const string& path, bool trim,
bool shared_with_bluestore=false);
bool bdev_support_label(unsigned id);
uint64_t get_block_device_size(unsigned bdev);

Expand Down
3 changes: 2 additions & 1 deletion src/os/bluestore/BlueStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4982,7 +4982,8 @@ int BlueStore::_minimal_open_bluefs(bool create)
// shared device
bfn = path + "/block";
// never trim here
r = bluefs->add_block_device(bluefs_shared_bdev, bfn, false);
r = bluefs->add_block_device(bluefs_shared_bdev, bfn, false,
true /* shared with bluestore */);
if (r < 0) {
derr << __func__ << " add block device(" << bfn << ") returned: "
<< cpp_strerror(r) << dendl;
Expand Down
24 changes: 13 additions & 11 deletions src/os/bluestore/KernelDevice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/file.h>

#include "KernelDevice.h"
#include "include/types.h"
Expand Down Expand Up @@ -55,13 +56,12 @@ KernelDevice::KernelDevice(CephContext* cct, aio_callback_t cb, void *cbpriv, ai

int KernelDevice::_lock()
{
struct flock l;
memset(&l, 0, sizeof(l));
l.l_type = F_WRLCK;
l.l_whence = SEEK_SET;
int r = ::fcntl(fd_directs[WRITE_LIFE_NOT_SET], F_SETLK, &l);
if (r < 0)
dout(10) << __func__ << " " << fd_directs[WRITE_LIFE_NOT_SET] << dendl;
int r = ::flock(fd_directs[WRITE_LIFE_NOT_SET], LOCK_EX | LOCK_NB);
if (r < 0) {
derr << __func__ << " flock failed on " << path << dendl;
return -errno;
}
return 0;
}

Expand Down Expand Up @@ -122,11 +122,13 @@ int KernelDevice::open(const string& p)
goto out_fail;
}

r = _lock();
if (r < 0) {
derr << __func__ << " failed to lock " << path << ": " << cpp_strerror(r)
<< dendl;
goto out_fail;
if (lock_exclusive) {
r = _lock();
if (r < 0) {
derr << __func__ << " failed to lock " << path << ": " << cpp_strerror(r)
<< dendl;
goto out_fail;
}
}

struct stat st;
Expand Down