uint64_t block_size;
bool support_discard = false;
bool rotational = true;
+ bool lock_exclusive = true;
public:
aio_callback_t aio_callback;
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; }
}
}
-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();
+ }
int r = b->open(path);
if (r < 0) {
delete b;
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);
// 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;
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <sys/file.h>
#include "KernelDevice.h"
#include "include/types.h"
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;
}
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;