OSD&FileStore之CompatSet

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;                                                                                                                                                  
  }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值