成都网站建设设计

将想法与焦点和您一起共享

SnapRealm类的示例代码

这篇文章主要介绍SnapRealm类的示例代码,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

创新互联公司-专业网站定制、快速模板网站建设、高性价比复兴网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式复兴网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖复兴地区。费用合理售后完善,十多年实体公司更值得信赖。

SnapRealm类说明:

struct SnapRealm {
   sr_t srnode;        描述snap的seq、snap创建的时间、SnapInfo以及snaplink_t相关内容
   MDCache *mdcache;    描述Snap在内存中的存储状态
   CInode *inode;    描述snap对应的inode信息
   SnapRealm *parent;
   set open_children;
   set open_past_children;
   map>> open_past_parents;    
   unsigned num_open_past_parents;
   snapid_t cached_seq;            self+all past+present parents的最大seq
   snapid_t cached_last_created;        all past+present parents的最大last_created
   snapid_t cached_last_destroyed;
   set cached_snaps;
   SnapContext cached_snap_context;
   bufferlist cached_snap_trace;
   elist inodes_with_caps;            有效的realm splits
   map*> client_caps;    记录所有需要snap通知的clients
 };

SnapRealm类方法:
SnapRealm::exists(name)            检查snap name是否存在
|__遍历srnode中snaps数组
  |__若snaps数组中的SnapInfo的name==name
    |__返回true
|__返回false

SnapRealm::add_cap(client, cap)
|__若client不在client_caps数组中
  |__在client_caps数组中以client为下标,创建一个xlist
|__将cap->item_snaprealm_caps添加到client_caps[client]内

SnapRealm::remove_cap(client, cap)
|__从cap的item_snaprealm_caps数组中删除自己,即:cap->item_snaprealm_caps.remove_myself()
|__若client_caps[client]为空
  |__删除client_caps[client]
  |__情况client_caps的client项

SnapRealm::add_open_past_parents(parent, last)
|__在open_past_parents数组中查找parent的inode number对应的项
  |__若找到对应的项
    |__将last插入到open_past_parents数组,即:p->second.second.insert(last)
  |__若没有找到对应的项
    |__以parent的inode number为索引,将parent插入到open_past_parents数组中,即:open_past_parents[parent->inode->ino()].first = parents
    |__将last插入到open_past_parents数组,即:open_past_parents[parent->inode->ino()].second.insert(last)
    |__在parent中将当前类对象插入到open_past_children集合中,即:parent->open_past_children.insert(this)
|__递增num_open_past_parents的值

SnapRealm::remove_open_past_parent(ino, last)
|__在open_past_parents数组中查找ino
|__在open_past_parents数组中查找last
|__将last从open_past_parents数组中删除
|__递减num_open_past_parents的值
|__若open_past_parents中snapid_t集合为空
  |__删除open_past_parents中的snapid_t集合
  |__在open_past_parents数组中删除parent对应的项
  |__在parent中将当前类对象从open_past_children数组中删除,即:parent->open_past_children.erase(this)

SnapRealm::_remove_missing_parent(snapid, parent, err)
|__在srnode中的past_parents数组中查找snapid
  |__若找到 
    |__从past_parents数组中删除snapid对应的项,即:srnode.past_parents.erase(p)

SnapRealm::_open_parents(finish, first, last)
|__若parent不为空
  |__确保当前parent的parent是open的
|__若srnode中past_parents数组个数大于num_open_past_parents
  |__遍历srnode中past_parents数组
    |__从MDCache中得到数组中parent对应的CInode信息,即:parent = mdcache->get_inode(p->second.ino)
    |__若parent为空
      |__通过MDCache创建parent inode,即:mdcache->open_ino()
      |__返回false
    |__若parent当前状态为STATE_PURGING
      |__将parent从srnode的past_parents数组中删除
      |__返回false
    |__打开parent的snaprealm的parent,即:parent->snaprealm->_open_parents()
    |__在open_past_parents数组中查找p->second.ino 
      |__若没找到
    |__调用add_open_past_parent()将parent->snaprealm加入到open_past_parents数组中
|__设置open=true
|__返回true

SnapRealm::have_past_parents_open(first, last)
|__遍历srnode中past_parents数组
  |__若p->second.first > last
    |__退出遍历
  |__在open_past_parents数组中若没有找到p->second.ino
    |__返回false
  |__在open_past_parents数组中得到p->second.ino对应的SnapRealm类对象
  |__执行SnapRealm类对象的have_past_parents_open()函数检查其parent是否是open的
    |__是则返回false
|__设置open=true
|__返回true

SnapRealm::close_parents()
|__遍历open_past_parents数组
  |__从num_open_past_parents中减去p->second.second.size()值
  |__从open_past_parents数组中的SnapRealm类对象的open_past_children数组中删除自己
|__清空open_past_parents数组

SnapRealm::build_snap_set(s, max_seq, max_last_created, max_last_destroyed, first, last)
|__若srnode的seq>max_seq
  |__max_seq = srnode.seq 
|__若srnode的last_created>max_last_created
  |__max_last_created = srnode.last_created 
|__若srnode的last_destroyed>max_last_destroyed
  |__max_last_destroyed = srnode.max_last_destroyed
|__从first开始遍历srnode.snaps,直到srnode.snaps.snapid_t.first > last
  |__将srnode.snaps.snapid_t添加到s集合中
|__从first开始遍历srnode.past_parents,直到srnode.snaps.snapid_t last
  |__从MDCache中得到parent的CInode信息
  |__调用parent的snaprealm的build_snap_set()方法
|__若srnode.current_parent_size <= last并且parent不为空
  |__调用parent的build_snap_set()方法
  
SnapRealm::check_cache()
|__清空cached_snaps数组和cached_snap_context数组
|__根据srnode中的向对应的值,设置cached_last_created/cached_last_destroyed/cached_seq
|__调用build_snap_set(),在cached_snaps上创建snap set_ 

SnapRealm::get_snaps()
|__调用check_cache()    在cached_snaps上创建snap
|__返回cached_snaps

SnapRealm::get_snap_context()
|__调用check_cache()    在cached_snaps上创建snap
|__若cached_snap_context.seq为空
  |__设置cached_snap_context的seq值和snaps数组的大小(根据cached_seq和cached_seq.size())
  |__遍历cached_snaps数组
    |__将cached_snaps数组中的项添加到cached_snap_context.__将cached_snaps数组中的项添加到cached_snaps数组中
|__返回cached_snap_context

SnapRealm::get_snap_info(infomap, first, last)
|__调用get_snaps()得到cached_snaps
|__从first开始遍历srnode中snaps数组,直到p->first > last
  |__将srnode中snaps数组中的SnapInfo信息添加到infomap中
|__从first开始遍历srnode中past_parents数组,直到p->first < first且p->second.first > last
  |__从MDCache中得到parent的CInode信息
  |__调用parent的snaprealm的get_snap_info()函数得到parent的SnapInfo信息
|__若srnode的current_parent_since<=last并且parent不为空
  |__调用parent的get_snap_info()得到parent的SnapInfo信息

SnapRealm::get_snapname(snapid, atino)
|__检查snapid是否在srnode的snaps数组中
  |__检查inode号是否等于atino
    |__返回srnode.snaps[snapid].name
  |__inode号不等于atino
    |__返回srnode.snaps[snapid].get_long_name()
|__检查snapid是否在srnode的past_parents数组中
  |__若在并且p->second.first <= snapid
    |__从MDCache中得到parent的CInode信息,即:mdcache->get_inode()
    |__返回oldparent->snaprealm->get_snapname()    返回oldparent的snapname
|__返回parent->get_snapname()        返回parent的snapname

SnapRealm::resolve_snapname(n, atino, first, last)
|__从first开始遍历srnode中snaps数组,直到p->first > last
  |__若srnode中snaps数组中对应的name==n
    |__返回p->first 
|__从first开始遍历srnode中past_parents数组,直到p->first < first并且p->second.first > last
  |__从MDCache中得到parent的CInode信息,即:mdcache->get_inode()
  |__调用oldparent->snaprealm->resolve_snapname()    返回oldparent的snapname
|__若srnode的current_parent_since<=last并且parent不为空
  |__调用parent->resolve_snapname()    返回parent的snapname
  
SnapRealm::adjust_parent()
|__得到newparent,即:newparent = inode->get_parent_dn()->get_dir()->get_inode()->find_snaprealm()
|__若newparent!=parent
  |__从paernt的open_children数组中删除自己,即:parent->open_children.erase(this)
  |__更新parent = newparent
  |__在parent的open_children数组中添加自己,即:parent->open_children.insert(this)
  |__调用invalidate_cached_snaps()    更新MDCache中的snaps信息
  
SnapRealm::split_at(child)
|__若inode是dir,但child不是dir
    |__若child对应的inode包含realm
      |__将child移入inode的realm中,即:child->inode->move_to_realm(child)
    |__直接返回
|__若child是dir
  |__遍历open_children数组
    |__若child不在open_children数组且child的inode是open_children数组成员的祖先
      |__设置数组成员的parent为child,即:realm->parent = child
      |__将数组成员设置到child的open_children数组中,即:child->open_children.insert(realm)
      |__在当前inode的open_children数组中删除该项,即:open_children->erase(p)
|__遍历inodes_with_caps数组
  |__若inodes_with_caps数组成员==child->inode
    |__设置under_child=true
  |__若inodes_with_caps数组成员!=child->inode
    |__顺着inodes_with_caps数组成员依次向上遍历父目录的CInode
      |__若遍历的CInode==child->inode
    |__设置under_child=true
|__若under_child==true
  |__调用in的move_to_realm(child)函数

SnapRealm::prune_past_parents()
|__调用check_cache()
|__遍历srnode中past_parents数组
  |__在cached_snaps数组中查到past_parents数组中snaplink_t.first 
    |__若在cached_snaps数组中没有找到
      |__调用remove_open_past_parent(p->second.ino, p->first)    从past_parents数组中删除对应的项
      |__删除srnode中past_parents数组中的项,即:srnode.past_parents.erase(p)
 

以上是“SnapRealm类的示例代码”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!


新闻标题:SnapRealm类的示例代码
文章网址:http://chengdu.cdxwcx.cn/article/ghpoji.html