新聞中心
這篇文章主要介紹SnapRealm類的示例代碼,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比復(fù)興網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式復(fù)興網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋復(fù)興地區(qū)。費(fèi)用合理售后完善,十多年實(shí)體公司更值得信賴。
SnapRealm類說明:
struct SnapRealm {
sr_t srnode; 描述snap的seq、snap創(chuàng)建的時(shí)間、SnapInfo以及snaplink_t相關(guān)內(nèi)容
MDCache *mdcache; 描述Snap在內(nèi)存中的存儲狀態(tài)
CInode *inode; 描述snap對應(yīng)的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數(shù)組
|__若snaps數(shù)組中的SnapInfo的name==name
|__返回true
|__返回false
SnapRealm::add_cap(client, cap)
|__若client不在client_caps數(shù)組中
|__在client_caps數(shù)組中以client為下標(biāo),創(chuàng)建一個(gè)xlist
|__將cap->item_snaprealm_caps添加到client_caps[client]內(nèi)
SnapRealm::remove_cap(client, cap)
|__從cap的item_snaprealm_caps數(shù)組中刪除自己,即:cap->item_snaprealm_caps.remove_myself()
|__若client_caps[client]為空
|__刪除client_caps[client]
|__情況client_caps的client項(xiàng)
SnapRealm::add_open_past_parents(parent, last)
|__在open_past_parents數(shù)組中查找parent的inode number對應(yīng)的項(xiàng)
|__若找到對應(yīng)的項(xiàng)
|__將last插入到open_past_parents數(shù)組,即:p->second.second.insert(last)
|__若沒有找到對應(yīng)的項(xiàng)
|__以parent的inode number為索引,將parent插入到open_past_parents數(shù)組中,即:open_past_parents[parent->inode->ino()].first = parents
|__將last插入到open_past_parents數(shù)組,即:open_past_parents[parent->inode->ino()].second.insert(last)
|__在parent中將當(dāng)前類對象插入到open_past_children集合中,即:parent->open_past_children.insert(this)
|__遞增num_open_past_parents的值
SnapRealm::remove_open_past_parent(ino, last)
|__在open_past_parents數(shù)組中查找ino
|__在open_past_parents數(shù)組中查找last
|__將last從open_past_parents數(shù)組中刪除
|__遞減num_open_past_parents的值
|__若open_past_parents中snapid_t集合為空
|__刪除open_past_parents中的snapid_t集合
|__在open_past_parents數(shù)組中刪除parent對應(yīng)的項(xiàng)
|__在parent中將當(dāng)前類對象從open_past_children數(shù)組中刪除,即:parent->open_past_children.erase(this)
SnapRealm::_remove_missing_parent(snapid, parent, err)
|__在srnode中的past_parents數(shù)組中查找snapid
|__若找到
|__從past_parents數(shù)組中刪除snapid對應(yīng)的項(xiàng),即:srnode.past_parents.erase(p)
SnapRealm::_open_parents(finish, first, last)
|__若parent不為空
|__確保當(dāng)前parent的parent是open的
|__若srnode中past_parents數(shù)組個(gè)數(shù)大于num_open_past_parents
|__遍歷srnode中past_parents數(shù)組
|__從MDCache中得到數(shù)組中parent對應(yīng)的CInode信息,即:parent = mdcache->get_inode(p->second.ino)
|__若parent為空
|__通過MDCache創(chuàng)建parent inode,即:mdcache->open_ino()
|__返回false
|__若parent當(dāng)前狀態(tài)為STATE_PURGING
|__將parent從srnode的past_parents數(shù)組中刪除
|__返回false
|__打開parent的snaprealm的parent,即:parent->snaprealm->_open_parents()
|__在open_past_parents數(shù)組中查找p->second.ino
|__若沒找到
|__調(diào)用add_open_past_parent()將parent->snaprealm加入到open_past_parents數(shù)組中
|__設(shè)置open=true
|__返回true
SnapRealm::have_past_parents_open(first, last)
|__遍歷srnode中past_parents數(shù)組
|__若p->second.first > last
|__退出遍歷
|__在open_past_parents數(shù)組中若沒有找到p->second.ino
|__返回false
|__在open_past_parents數(shù)組中得到p->second.ino對應(yīng)的SnapRealm類對象
|__執(zhí)行SnapRealm類對象的have_past_parents_open()函數(shù)檢查其parent是否是open的
|__是則返回false
|__設(shè)置open=true
|__返回true
SnapRealm::close_parents()
|__遍歷open_past_parents數(shù)組
|__從num_open_past_parents中減去p->second.second.size()值
|__從open_past_parents數(shù)組中的SnapRealm類對象的open_past_children數(shù)組中刪除自己
|__清空open_past_parents數(shù)組
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
|__從MDCache中得到parent的CInode信息
|__調(diào)用parent的snaprealm的build_snap_set()方法
|__若srnode.current_parent_size <= last并且parent不為空
|__調(diào)用parent的build_snap_set()方法
SnapRealm::check_cache()
|__清空cached_snaps數(shù)組和cached_snap_context數(shù)組
|__根據(jù)srnode中的向?qū)?yīng)的值,設(shè)置cached_last_created/cached_last_destroyed/cached_seq
|__調(diào)用build_snap_set(),在cached_snaps上創(chuàng)建snap set_
SnapRealm::get_snaps()
|__調(diào)用check_cache() 在cached_snaps上創(chuàng)建snap
|__返回cached_snaps
SnapRealm::get_snap_context()
|__調(diào)用check_cache() 在cached_snaps上創(chuàng)建snap
|__若cached_snap_context.seq為空
|__設(shè)置cached_snap_context的seq值和snaps數(shù)組的大?。ǜ鶕?jù)cached_seq和cached_seq.size())
|__遍歷cached_snaps數(shù)組
|__將cached_snaps數(shù)組中的項(xiàng)添加到cached_snap_context.__將cached_snaps數(shù)組中的項(xiàng)添加到cached_snaps數(shù)組中
|__返回cached_snap_context
SnapRealm::get_snap_info(infomap, first, last)
|__調(diào)用get_snaps()得到cached_snaps
|__從first開始遍歷srnode中snaps數(shù)組,直到p->first > last
|__將srnode中snaps數(shù)組中的SnapInfo信息添加到infomap中
|__從first開始遍歷srnode中past_parents數(shù)組,直到p->first < first且p->second.first > last
|__從MDCache中得到parent的CInode信息
|__調(diào)用parent的snaprealm的get_snap_info()函數(shù)得到parent的SnapInfo信息
|__若srnode的current_parent_since<=last并且parent不為空
|__調(diào)用parent的get_snap_info()得到parent的SnapInfo信息
SnapRealm::get_snapname(snapid, atino)
|__檢查snapid是否在srnode的snaps數(shù)組中
|__檢查inode號是否等于atino
|__返回srnode.snaps[snapid].name
|__inode號不等于atino
|__返回srnode.snaps[snapid].get_long_name()
|__檢查snapid是否在srnode的past_parents數(shù)組中
|__若在并且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數(shù)組,直到p->first > last
|__若srnode中snaps數(shù)組中對應(yīng)的name==n
|__返回p->first
|__從first開始遍歷srnode中past_parents數(shù)組,直到p->first < first并且p->second.first > last
|__從MDCache中得到parent的CInode信息,即:mdcache->get_inode()
|__調(diào)用oldparent->snaprealm->resolve_snapname() 返回oldparent的snapname
|__若srnode的current_parent_since<=last并且parent不為空
|__調(diào)用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數(shù)組中刪除自己,即:parent->open_children.erase(this)
|__更新parent = newparent
|__在parent的open_children數(shù)組中添加自己,即:parent->open_children.insert(this)
|__調(diào)用invalidate_cached_snaps() 更新MDCache中的snaps信息
SnapRealm::split_at(child)
|__若inode是dir,但child不是dir
|__若child對應(yīng)的inode包含realm
|__將child移入inode的realm中,即:child->inode->move_to_realm(child)
|__直接返回
|__若child是dir
|__遍歷open_children數(shù)組
|__若child不在open_children數(shù)組且child的inode是open_children數(shù)組成員的祖先
|__設(shè)置數(shù)組成員的parent為child,即:realm->parent = child
|__將數(shù)組成員設(shè)置到child的open_children數(shù)組中,即:child->open_children.insert(realm)
|__在當(dāng)前inode的open_children數(shù)組中刪除該項(xiàng),即:open_children->erase(p)
|__遍歷inodes_with_caps數(shù)組
|__若inodes_with_caps數(shù)組成員==child->inode
|__設(shè)置under_child=true
|__若inodes_with_caps數(shù)組成員!=child->inode
|__順著inodes_with_caps數(shù)組成員依次向上遍歷父目錄的CInode
|__若遍歷的CInode==child->inode
|__設(shè)置under_child=true
|__若under_child==true
|__調(diào)用in的move_to_realm(child)函數(shù)
SnapRealm::prune_past_parents()
|__調(diào)用check_cache()
|__遍歷srnode中past_parents數(shù)組
|__在cached_snaps數(shù)組中查到past_parents數(shù)組中snaplink_t.first
|__若在cached_snaps數(shù)組中沒有找到
|__調(diào)用remove_open_past_parent(p->second.ino, p->first) 從past_parents數(shù)組中刪除對應(yīng)的項(xiàng)
|__刪除srnode中past_parents數(shù)組中的項(xiàng),即:srnode.past_parents.erase(p)
以上是“SnapRealm類的示例代碼”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
新聞標(biāo)題:SnapRealm類的示例代碼
分享地址:http://www.dlmjj.cn/article/ghpoji.html


咨詢
建站咨詢
