OSD&FileStore之CompatSet
2017-07-06 19:07
274 查看
CompatSet是一个结构体类型,其用于对特性兼容性进行管理。该类型的定义位于src/include/CompatSet.h文件中。
id:特性的唯一标识
name:特性的名字
mask:标识该组特性的位图
names:是一个map,key为特性的id,value为特性的name
compat:该组中的特性支持与否,对读写没有任何影响。
ro_compat:该组中的特性,如果不支持,则会影响写入操作,读操作没有影响。
incompat:该组中的特性,如果不支持,则会影响读写操作。
为什么需要该兼容性管理模块:
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; }
相关文章推荐
- ./sqlplusSP2-0667: Message file sp1<lang>.msb not found。SP2-0750: You may need to set ORACLE_HOME t
- SP2-0667: Message file sp1<lang>.msb not found SP2-0750: You may need to set ORACLE_HOME to your Ora
- vim --cmd "set fileencoding=utf-8"
- 关于 dojo.data.ItemFileWriteStore & dojox.grid.DataGrid 一个注意事项
- if (!doc.setContent(&file))出错的解决方法
- Qt if(!doc.setContent(&file)出错
- FileStore::mkjournal()&&FileJournal::create()
- Set fso = Server.CreateObject("Scripting.FileSystemObject")
- 用Qt读取xml文件,程序执行到 if(!doc.setContent(&file)) 时候出错
- WebLogic Server启动异常:The file store "WLS_DIAGNOSTICS" could not be opened
- Working With The File System & Streams (1)
- A Better File Upload Progress Bar using Python, AJAX Prototype, & JSON
- [解决问题][不能更新eclipse]错误提示:Error retrieving "feature.xml". [error in opening zip file]
- File Hosting Review, About file hosting & storage sites
- Working With The File System & Streams (3)
- What's the effect of hashCode() & equals() when adding object to List/Set/Map
- File Hosting & Storage Review
- 关于更改file控件中"浏览...." 字样
- Perl Mgmt Tips: Add "WITH ENCRYPTION" to SQL source file
- How to set the enviroment variables of JDK &amp; Eclipse!