osd::mkfs()
----BlueStore:mkfs()
--------Bluestore::_open_db()
-----------Bluefs->add_block_device()
-----------Bluefs->add_block_extent()
-----------Bluefs->mkfs()
-----------Bluefs->mount()
---------------Bluefs->_open_super()
---------------Bluefs->_init_alloc()
---------------Bluefs->_replay()
在osd的部署过程中会对BlueStore进行初始化
1、设置fsid,设置为 osd的uuid
2、初始化bluestore
3、挂载bluestore
4、读取bluestore的superblock信息,如果已存在superblock,则检查相关信息;如果不存在,则先设置cluster_fsid、osd_fsid、whoami、compat_features信息,然后通过事务创建superblock。
5、写fsid文件
int OSD::mkfs(CephContext *cct, ObjectStore *store, const string &dev,
uuid_d fsid, int whoami)
{
// if we are fed a uuid for this osd, use it.
store->set_fsid(cct->_conf->osd_uuid); //设置fs的fsid为osd的uuid
ret = store->mkfs(); //bulestore初始化
store->set_cache_shards(1); // doesn't matter for mkfs!
ret = store->mount(); //blustore的mount
ret = store->read(coll_t::meta(), OSD_SUPERBLOCK_GOBJECT, 0, 0, sbbl); //获取bluestore的superblock数据
if (ret >= 0) {
//检查superblock的相关信息
} else {
//设置superblock相关信息
sb.cluster_fsid = fsid;
sb.osd_fsid = store->get_fsid();
sb.whoami = whoami;
sb.compat_features = get_osd_initial_compat_set();
//通过bluestore事务来创建superblock
ObjectStore::Transaction t;
t.create_collection(coll_t::meta(), 0);
t.write(coll_t::meta(), OSD_SUPERBLOCK_GOBJECT, 0, bl.length(), bl);
ret = store->apply_transaction(osr.get(), std::move(t));
}
//写fsid文件
ret = write_meta(cct, store, sb.cluster_fsid, sb.osd_fsid, whoami);
}
bluestore的mkfs过程
int BlueStore::mkfs()
{
r = read_meta("mkfs_done", &done); //读取元数据信息??并进行fsck
r = read_meta("type", &type); //读取类型数据,判断是否为bluestore
freelist_type = "bitmap"; //设置空闲空间的存储格式为bitmap
r = _open_path(); //判断osd_max_object_size是否小于4GB,BlueStore has hard limit of 4GB
r = _open_fsid(true); //感觉是在读取fsid有没有成功配置??
r = _lock_fsid(); //为fsid相关文件上锁,如果无法上锁,有可能是因为有其他的ceph-osd还在运行状态
r = _read_fsid(&old_fsid); //读取fsid相关配置信息,判断相关配置信息是否正确,如果没有fsid,则生成一个随机的fsid???
r = _setup_block_symlink_or_file("block", cct->_conf->bluestore_block_path,
cct->_conf->bluestore_block_size,
cct->_conf->bluestore_block_create); //创建block链接或文件??
if (cct->_conf->bluestore_bluefs) {
r = _setup_block_symlink_or_file("block.wal", cct->_conf->bluestore_block_wal_p