溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

SnapRealm類的示例代碼

發(fā)布時間:2021-12-18 16:52:58 來源:億速云 閱讀:159 作者:小新 欄目:云計算

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

SnapRealm類說明:

struct SnapRealm {
   sr_t srnode;        描述snap的seq、snap創(chuàng)建的時間、SnapInfo以及snaplink_t相關內容
   MDCache *mdcache;    描述Snap在內存中的存儲狀態(tài)
   CInode *inode;    描述snap對應的inode信息
   SnapRealm *parent;
   set<SnapRealm*> open_children;
   set<SnapRealm*> open_past_children;
   map<inodeno_t, pair<SnapRealm*, set<snapid_t>>> 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<snapid_t> cached_snaps;
   SnapContext cached_snap_context;
   bufferlist cached_snap_trace;
   elist<CInode*> inodes_with_caps;            有效的realm splits
   map<client_t, xlist<Capability*>*> 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為下標,創(chuàng)建一個xlist<Capability*>
|__將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創(chuàng)建parent inode,即:mdcache->open_ino()
      |__返回false
    |__若parent當前狀態(tài)為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類對象
  |__執(zhí)行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<first并且srnode.snaps.snaplink_t.first > 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上創(chuàng)建snap set_ 

SnapRealm::get_snaps()
|__調用check_cache()    在cached_snaps上創(chuàng)建snap
|__返回cached_snaps

SnapRealm::get_snap_context()
|__調用check_cache()    在cached_snaps上創(chuàng)建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類的示例代碼”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業(yè)資訊頻道!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI