diff --git a/blockstore_impl.h b/blockstore_impl.h index e33ad00f..ee2cc2f8 100644 --- a/blockstore_impl.h +++ b/blockstore_impl.h @@ -194,6 +194,8 @@ class blockstore_impl_t // Sparse write tracking granularity. 4 KB is a good choice. Must be a multiple of disk_alignment uint64_t bitmap_granularity = 4096; bool readonly = false; + // By default, Blockstore locks all opened devices exclusively. This option can be used to disable locking + bool disable_flock = false; // It is safe to disable fsync() if drive write cache is writethrough bool disable_data_fsync = false, disable_meta_fsync = false, disable_journal_fsync = false; // Enable if you want every operation to be executed with an "implicit fsync" diff --git a/blockstore_open.cpp b/blockstore_open.cpp index f109f93a..19befbfa 100644 --- a/blockstore_open.cpp +++ b/blockstore_open.cpp @@ -1,3 +1,4 @@ +#include #include "blockstore_impl.h" static uint32_t is_power_of_two(uint64_t value) @@ -34,6 +35,10 @@ void blockstore_impl_t::parse_config(blockstore_config_t & config) { disable_journal_fsync = true; } + if (config["disable_device_lock"] == "true" || config["disable_device_lock"] == "1" || config["disable_device_lock"] == "yes") + { + disable_flock = true; + } if (config["immediate_commit"] == "all") { immediate_commit = IMMEDIATE_ALL; @@ -286,6 +291,10 @@ void blockstore_impl_t::open_data() { throw std::runtime_error("data_offset exceeds device size = "+std::to_string(data_size)); } + if (!disable_flock && flock(data_fd, LOCK_EX) != 0) + { + throw std::runtime_error(std::string("Failed to lock data device: ") + strerror(errno)); + } } void blockstore_impl_t::open_meta() @@ -303,6 +312,10 @@ void blockstore_impl_t::open_meta() { throw std::runtime_error("meta_offset exceeds device size = "+std::to_string(meta_size)); } + if (!disable_flock && flock(meta_fd, LOCK_EX) != 0) + { + throw std::runtime_error(std::string("Failed to lock metadata device: ") + strerror(errno)); + } } else { @@ -324,7 +337,11 @@ void blockstore_impl_t::open_journal() { throw std::runtime_error("Failed to open journal device"); } - check_size(journal.fd, &journal.device_size, "metadata device"); + check_size(journal.fd, &journal.device_size, "journal device"); + if (!disable_flock && flock(journal.fd, LOCK_EX) != 0) + { + throw std::runtime_error(std::string("Failed to lock journal device: ") + strerror(errno)); + } } else { diff --git a/osd_peering_pg.cpp b/osd_peering_pg.cpp index f208efa6..6cfa0a0d 100644 --- a/osd_peering_pg.cpp +++ b/osd_peering_pg.cpp @@ -357,6 +357,7 @@ void pg_t::calc_object_states() void pg_t::print_state() { + // FIXME Immediately report state on each change printf( "[PG %u] is %s%s%s%s%s%s%s%s%s (%lu objects)\n", pg_num, (state & PG_OFFLINE) ? "offline" : "",