您的位置:首页 > 其它

OSD&FileStore之CompatSet

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

为什么需要该兼容性管理模块:

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

涉及的主要类型:

struct Feature   //(CompatSet的内部结构体)标识一个具体的特性
class FeatureSet //(CompatSet的内部类) 标识一组特性集合
struct CompatSet // 兼容性管理的主要类型

CompatSet |- Feature
|- FeatureSet


struct Feature:

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

id:特性的唯一标识

name:特性的名字

class FeatureSet:

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

mask:标识该组特性的位图

names:是一个map,key为特性的id,value为特性的name

struct CompatSet:

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

compat:该组中的特性支持与否,对读写没有任何影响。

ro_compat:该组中的特性,如果不支持,则会影响写入操作,读操作没有影响。

incompat:该组中的特性,如果不支持,则会影响读写操作。

其中主要的成员函数:

/* 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);
}


/* does this filesystem implementation have the
features required to write the other? */
bool CompatSet::writeable(CompatSet const& other) const {
return readable(other) &&
!((other.ro_compat.mask ^ ro_compat.mask) & other.ro_compat.mask);
}


/* 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;
}


/* Get the features supported by other CompatSet but not this one,
¦* as a CompatSet.
¦*/
CompatSet CompatSet::unsupported(CompatSet& other) {
¦ CompatSet diff;
¦ uint64_t other_compat =
¦ ¦ ((other.compat.mask ^ compat.mask) & other.compat.mask);
¦ uint64_t other_ro_compat =
¦ ¦ ((other.ro_compat.mask ^ ro_compat.mask) & other.ro_compat.mask);
¦ uint64_t other_incompat =
¦ ¦ ((other.incompat.mask ^ incompat.mask) & other.incompat.mask);
¦ for (int id = 1; id < 64; ++id) {
¦ ¦ uint64_t mask = (uint64_t)1 << id;
¦ ¦ if (mask & other_compat) {
diff.compat.insert( Feature(id, other.compat.names[id]));
¦ ¦ }
¦ ¦ if (mask & other_ro_compat) {
diff.ro_compat.insert(Feature(id, other.ro_compat.names[id]));
¦ ¦ }
¦ ¦ if (mask & other_incompat) {
diff.incompat.insert( Feature(id, other.incompat.names[id]));
¦ ¦ }
¦ }
¦ return diff;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ceph FileStore