1.3 CompatSet

reference

https://blog.csdn.net/litianze99/article/details/74596843

CompatSet是一个结构体类型,其用于对特性兼容性进行管理。该类型的定义位于src/include/CompatSet.h文件中。

为什么

OSD对外提供一些功能特性,这个些特性需要OSD后端的存储驱动(或者文件系统)如filestore支持,如果后端驱动不支持,即两者之间在某些特性上不能兼容,就会影响读写操作,所以谨慎处理这些特性的兼容性是非常重要的。

struct CompatSet {
struct Feature {
uint64_t id;
std::string name;
Feature(uint64_t _id, const std::string& _name) : id(_id), name(_name) {}
};
class FeatureSet {
uint64_t mask;
std::map<uint64_t, std::string> names;
}
// These features have no impact on the read / write status
FeatureSet compat;
// If any of these features are missing, read is possible ( as long
// as no incompat feature is missing ) but it is not possible to write
FeatureSet ro_compat;
// If any of these features are missing, read or write is not possible
FeatureSet incompat;

Feature

该类型包含两个重要属性:

  • id:特性的唯一标识
  • name:特性的名字

FeatureSet

该类型包含两个重要属性:

  • mask:标识该组特性的位图
  • names:是一个map,key为特性的id,value为特性的name

属性

该类型中包含了三个重要的属性,分别是:compatro_compatincompat,都是FeatureSet实例。

  • compat:该组中的特性支持与否,对读写没有任何影响。
  • ro_compat:该组中的特性,如果不支持,则会影响写入操作,读操作没有影响。
  • incompat:该组中的特性,如果不支持,则会影响读写操作。

主要的功能与接口

readable

// 这个文件系统是否实现了相应的接口,进而可以读取另外一个file system.
/* does this filesystem implementation have the
features required to read the other? */
bool CompatSet::readable(CompatSet const& other) const {
return !((other.incompat.mask ^ incompat.mask) & other.incompat.mask);
}

writeable

// 这个文件系统的实现,是否有需要写other时所需的特性
/* does this filesystem implementation have the
features required to write the other? */
bool writeable(CompatSet const& other) const {
return readable(other) &&
!((other.ro_compat.mask ^ ro_compat.mask) & other.ro_compat.mask);
}

compare

注意这里的比较是基于特性的比较。a<b时是不能保证b<a的。这是因为

  • 0 表示两者的特性集是一样
  • 1 表示a是b的超集
  • -1表示a缺少b里面至少一个特性
/* Compare this CompatSet to another.
* CAREFULLY NOTE: This operation is NOT commutative.
* a > b DOES NOT imply that b < a.
* If returns:
* 0: The CompatSets have the same feature set.
* 1: This CompatSet's features are a strict superset of the other's.
* -1: This CompatSet is missing at least one feature
* described in the other. It may still have more features, though.
*/
int CompatSet::compare(const CompatSet& other) {
if ((other.compat.mask == compat.mask) &&
(other.ro_compat.mask == ro_compat.mask) &&
(other.incompat.mask == incompat.mask)) return 0;
//okay, they're not the same
//if we're writeable we have a superset of theirs on incompat and ro_compat
if (writeable(other) && !((other.compat.mask ^ compat.mask)
& other.compat.mask)) return 1;
//if we make it here, we weren't writeable or had a difference compat set
return -1;
}

unsupported