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: less code redundancy #11740

Merged
merged 3 commits into from
Nov 2, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 24 additions & 30 deletions src/os/bluestore/BlueStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3155,8 +3155,7 @@ int BlueStore::_open_db(bool create)
{
int r;
assert(!db);
char fn[PATH_MAX];
snprintf(fn, sizeof(fn), "%s/db", path.c_str());
string fn = path + "/db";
string options;
stringstream err;
ceph::shared_ptr<Int64ArrayMergeOperator> merge_op(new Int64ArrayMergeOperator);
Expand Down Expand Up @@ -3204,11 +3203,11 @@ int BlueStore::_open_db(bool create)
}
bluefs = new BlueFS;

char bfn[PATH_MAX];
string bfn;
struct stat st;

snprintf(bfn, sizeof(bfn), "%s/block.db", path.c_str());
if (::stat(bfn, &st) == 0) {
bfn = path + "/block.db";
if (::stat(bfn.c_str(), &st) == 0) {
r = bluefs->add_block_device(BlueFS::BDEV_DB, bfn);
if (r < 0) {
derr << __func__ << " add block device(" << bfn << ") returned: "
Expand Down Expand Up @@ -3240,7 +3239,7 @@ int BlueStore::_open_db(bool create)
}

// shared device
snprintf(bfn, sizeof(bfn), "%s/block", path.c_str());
bfn = path + "/block";
r = bluefs->add_block_device(bluefs_shared_bdev, bfn);
if (r < 0) {
derr << __func__ << " add block device(" << bfn << ") returned: "
Expand All @@ -3261,8 +3260,8 @@ int BlueStore::_open_db(bool create)
bluefs_extents.insert(BLUEFS_START, initial);
}

snprintf(bfn, sizeof(bfn), "%s/block.wal", path.c_str());
if (::stat(bfn, &st) == 0) {
bfn = path + "/block.wal";
if (::stat(bfn.c_str(), &st) == 0) {
r = bluefs->add_block_device(BlueFS::BDEV_WAL, bfn);
if (r < 0) {
derr << __func__ << " add block device(" << bfn << ") returned: "
Expand Down Expand Up @@ -3317,35 +3316,33 @@ int BlueStore::_open_db(bool create)
env = new BlueRocksEnv(bluefs);

// simplify the dir names, too, as "seen" by rocksdb
strcpy(fn, "db");
fn = "db";
}

if (bluefs_shared_bdev == BlueFS::BDEV_SLOW) {
// we have both block.db and block; tell rocksdb!
// note: the second (last) size value doesn't really matter
char db_paths[PATH_MAX*3];
snprintf(
db_paths, sizeof(db_paths), "%s,%lld %s.slow,%lld",
fn,
(unsigned long long)bluefs->get_block_device_size(BlueFS::BDEV_DB) *
95 / 100,
fn,
(unsigned long long)bluefs->get_block_device_size(BlueFS::BDEV_SLOW) *
95 / 100);
g_conf->set_val("rocksdb_db_paths", db_paths, false, false);
ostringstream db_paths;
uint64_t db_size = bluefs->get_block_device_size(BlueFS::BDEV_DB);
uint64_t slow_size = bluefs->get_block_device_size(BlueFS::BDEV_SLOW);
db_paths << fn << ","
<< (uint64_t)(db_size * 95 / 100) << " "
<< fn + ".slow" << ","
<< (uint64_t)(slow_size * 95 / 100);
g_conf->set_val("rocksdb_db_paths", db_paths.str(), false, false);
dout(10) << __func__ << " set rocksdb_db_paths to "
<< g_conf->rocksdb_db_paths << dendl;
}

if (create) {
env->CreateDir(fn);
if (g_conf->rocksdb_separate_wal_dir)
env->CreateDir(string(fn) + ".wal");
env->CreateDir(fn + ".wal");
if (g_conf->rocksdb_db_paths.length())
env->CreateDir(string(fn) + ".slow");
env->CreateDir(fn + ".slow");
}
} else if (create) {
int r = ::mkdir(fn, 0755);
int r = ::mkdir(fn.c_str(), 0755);
if (r < 0)
r = -errno;
if (r < 0 && r != -EEXIST) {
Expand All @@ -3356,9 +3353,8 @@ int BlueStore::_open_db(bool create)

// wal_dir, too!
if (g_conf->rocksdb_separate_wal_dir) {
char walfn[PATH_MAX];
snprintf(walfn, sizeof(walfn), "%s/db.wal", path.c_str());
r = ::mkdir(walfn, 0755);
string walfn = path + "/db.wal";
r = ::mkdir(walfn.c_str(), 0755);
if (r < 0)
r = -errno;
if (r < 0 && r != -EEXIST) {
Expand Down Expand Up @@ -4117,8 +4113,7 @@ int BlueStore::_fsck_check_extents(
const vector<bluestore_pextent_t>& extents,
bool compressed,
boost::dynamic_bitset<> &used_blocks,
store_statfs_t& expected_statfs,
bool deep)
store_statfs_t& expected_statfs)
{
dout(30) << __func__ << " oid " << oid << " extents " << extents << dendl;
int errors = 0;
Expand Down Expand Up @@ -4424,8 +4419,7 @@ int BlueStore::fsck(bool deep)
errors += _fsck_check_extents(oid, blob.extents,
blob.is_compressed(),
used_blocks,
expected_statfs,
deep);
expected_statfs);
}
}
if (deep) {
Expand Down Expand Up @@ -4487,7 +4481,7 @@ int BlueStore::fsck(bool deep)
errors += _fsck_check_extents(p->second.oids.front(),
extents,
p->second.compressed,
used_blocks, expected_statfs, deep);
used_blocks, expected_statfs);
sb_info.erase(p);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/os/bluestore/BlueStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -1581,8 +1581,7 @@ class BlueStore : public ObjectStore,
const vector<bluestore_pextent_t>& extents,
bool compressed,
boost::dynamic_bitset<> &used_blocks,
store_statfs_t& expected_statfs,
bool deep);
store_statfs_t& expected_statfs);

void _buffer_cache_write(
TransContext *txc,
Expand Down
17 changes: 2 additions & 15 deletions src/tools/ceph_objectstore_tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2594,21 +2594,8 @@ int main(int argc, char **argv)
myexit(1);
}

if (op == "fsck") {
int r = fs->fsck(false);
if (r < 0) {
cerr << "fsck failed: " << cpp_strerror(r) << std::endl;
myexit(1);
}
if (r > 0) {
cerr << "fsck found " << r << " errors" << std::endl;
myexit(1);
}
cout << "fsck found no errors" << std::endl;
exit(0);
}
if (op == "fsck-deep") {
int r = fs->fsck(true);
if (op == "fsck" || op == "fsck-deep") {
int r = fs->fsck(op == "fsck-deep");
if (r < 0) {
cerr << "fsck failed: " << cpp_strerror(r) << std::endl;
myexit(1);
Expand Down