Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Sample code for the SnapRealm class

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the sample code of SnapRealm class, which is very detailed and has certain reference value. Friends who are interested must finish it!

The SnapRealm class description:

Struct SnapRealm {sr_t srnode; describes the seq of snap, the time of creation of snap, SnapInfo and snaplink_t related content MDCache * mdcache; describes the storage status of Snap in memory CInode * inode; describes inode information SnapRealm * parent; set open_children; set open_past_children; map open_past_parents; unsigned num_open_past_parents; snapid_t cached_seq corresponding to snap Maximum seq snapid_t cached_last_created; all past+present parents of self+all past+present parents, maximum last_created snapid_t cached_last_destroyed; set cached_snaps; SnapContext cached_snap_context; bufferlist cached_snap_trace; elist inodes_with_caps; of valid realm splits map client_caps; record all clients that requires snap notification}

SnapRealm class methods:

SnapRealm::exists (name) checks whether snap name exists

| | _ _ traverses the snaps array in srnode |

| | _ _ if the name==name of SnapInfo in snaps array |

| | _ _ returns true |

| | _ _ returns false |

SnapRealm::add_cap (client, cap)

| | _ _ if client is not in client_caps array |

| | _ _ create a xlist in the client_caps array with client as the subscript |

| | _ _ add cap- > item_snaprealm_caps to client_ capsule [client] |

SnapRealm::remove_cap (client, cap)

| | _ _ delete yourself from the item_snaprealm_caps array of cap, that is, cap- > item_snaprealm_caps.remove_myself () |

| | _ _ if client _ caps[ client] is empty |

| | _ _ delete client_ [client] |

| | _ _ the client entry of the situation client_caps |

SnapRealm::add_open_past_parents (parent, last)

| | _ _ find the entry corresponding to the inode number of parent in the open_past_parents array |

| | _ _ if the corresponding item is found |

| | _ _ insert last into the open_past_parents array, that is, p-> second.second.insert (last) |

| | _ _ if no corresponding item is found |

| | _ _ insert parent into the open_past_parents array with the inode number of parent as the index, that is, open_past_ parents [parent-> inode- > ino ()] .first = parents |

| | _ _ insert last into the open_past_parents array, that is, open_past_ parents [parent-> inode- > ino ()] .second.insert (last) |

| | _ _ insert the current class object into the open_past_children collection in parent, namely: parent- > open_past_children.insert (this) |

| | _ _ increments the value of num_open_past_parents |

SnapRealm::remove_open_past_parent (ino, last)

| | _ _ find ino in open_past_parents array |

| | _ _ find last in open_past_parents array |

| | _ _ remove last from the open_past_parents array |

| | _ _ decreasing the value of num_open_past_parents |

| | _ _ if open _ past_parents snapid_t collection is empty |

| | _ _ Delete the snapid_t collection in open_past_parents |

| | _ _ delete the entry corresponding to parent in the open_past_parents array |

| | _ _ removes the current class object from the open_past_children array in parent, that is, parent- > open_past_children.erase (this) |

SnapRealm::_remove_missing_parent (snapid, parent, err)

| | _ _ find snapid in the past_parents array in srnode |

| _ _ if found

| | _ _ delete the entry corresponding to snapid from the past_parents array, namely: srnode.past_parents.erase (p) |

SnapRealm::_open_parents (finish, first, last)

| | _ _ if parent is not empty |

| | _ _ make sure that the parent of the current parent is open |

| | _ _ if the number of past_parents arrays in srnode is greater than num_open_past_parents |

| | _ _ traverses the past_parents array in srnode |

| | _ _ get the CInode information corresponding to parent in the array from MDCache, namely: parent = mdcache- > get_inode (p-> second.ino) |

| | _ _ if parent is empty |

| | _ _ create parent inode via MDCache, that is, mdcache- > open_ino () |

| | _ _ returns false |

| | _ _ if parent's current status is STATE_PURGING |

| | _ _ delete parent from the past_parents array of srnode |

| | _ _ returns false |

| | _ _ Open the parent of parent's snaprealm, that is, parent- > snaprealm- > _ open_parents () |

| | _ _ look for p-> second.ino in the open_past_parents array |

| | _ _ if not found |

| | _ _ call add_open_past_parent () to add parent- > snaprealm to the open_past_parents array |

| | _ _ set open=true |

| | _ _ returns true |

SnapRealm::have_past_parents_open (first, last)

| | _ _ traverses the past_parents array in srnode |

| | _ _ if p-> second.first > last |

| | _ _ exits traversal |

| | _ _ if p-> second.ino is not found in the open_past_parents array |

| | _ _ returns false |

| | _ _ get the SnapRealm class object corresponding to p-> second.ino in the open_past_parents array |

| | _ _ execute the have_past_parents_open () function of the SnapRealm class object to check whether its parent is open |

| | _ _ Yes, false is returned |

| | _ _ set open=true |

| | _ _ returns true |

SnapRealm::close_parents ()

| | _ _ traverse the open_past_parents array |

| | _ _ subtract the value of p-> second.second.size () from num_open_past_parents |

| | _ _ delete yourself from the open_past_children array of SnapRealm class objects in the open_past_parents array |

| | _ _ empty the open_past_parents array |

SnapRealm::build_snap_set (s, max_seq, max_last_created, max_last_destroyed, first, last)

| | _ _ if the seq of srnode > max_seq |

| | _ max_seq = srnode.seq |

| | _ _ if the last_created of srnode > max_last_created |

| | _ max_last_created = srnode.last_created |

| | _ _ if the last_destroyed of srnode > max_last_destroyed |

| | _ max_last_destroyed = srnode.max_last_destroyed |

| | _ _ traverse srnode.snaps from first until srnode.snaps.snapid_t.first > last |

| | _ _ add srnode.snaps.snapid_t to s collection |

| | _ _ traverse srnode.past_parents from first to srnode.snaps.snapid_t last |

| | _ _ get the CInode information of parent from MDCache |

| | _ _ call the build_snap_set () method of parent's snaprealm |

| | _ _ if srnode.current _ parent_size first > last |

| | _ _ add the SnapInfo information from the snaps array in srnode to infomap |

| | _ _ traverse the past_parents array in srnode from first until p-> first |

< first且p->

Second.first > last

| | _ _ get the CInode information of parent from MDCache |

| | _ _ call the get_snap_info () function of parent's snaprealm to get the SnapInfo information of parent |

| | _ _ if current_parent_sincesecond.first get_inode () of srnode |

| | _ _ returns oldparent- > snaprealm- > get_snapname () returns the snapname of oldparent |

| | _ _ returns parent- > get_snapname () returns the snapname of parent |

SnapRealm::resolve_snapname (n, atino, first, last)

| | _ _ traverse the snaps array in srnode from first until p-> first > last |

| | _ _ if the corresponding name==n in the snaps array in srnode |

| | _ _ returns p-> first |

| | _ _ traverse the past_parents array in srnode from first until p-> first |

< first并且p->

Second.first > last

| | _ _ get the CInode information of parent from MDCache, that is, mdcache- > get_inode () |

| | _ _ call oldparent- > snaprealm- > resolve_snapname () to return the snapname of oldparent |

| | _ _ if current_parent_sinceresolve_snapname () of srnode returns snapname of parent |

SnapRealm::adjust_parent ()

| | _ _ get newparent, that is: newparent = inode- > get_parent_dn ()-> get_dir ()-> get_inode ()-> find_snaprealm () |

| | _ _ if newparentinvalid parent |

| | _ _ delete yourself from the open_children array of paernt, that is, parent- > open_children.erase (this) |

| | _ _ update parent = newparent |

| | _ _ add yourself to the open_children array of parent, that is, parent- > open_children.insert (this) |

| | _ _ call invalidate_cached_snaps () to update the snaps information in MDCache |

SnapRealm::split_at (child)

| | _ _ if inode is dir, but child is not dir |

| | _ _ if the inode corresponding to child contains realm |

| | _ _ move child to the realm of inode, that is, child- > inode- > move_to_realm (child) |

| | _ _ return directly |

| | _ _ if child is dir |

| | _ _ traverse the open_children array |

| | _ _ if child is not in the open_children array and the inode of child is the ancestor of the open_children array member |

| | _ _ set the parent of the array member to child, that is, realm- > parent = child |

| | _ _ set the array members to the open_children array of child, that is, child- > open_children.insert (realm) |

| | _ _ delete the entry in the open_children array of the current inode, that is, open_children- > erase (p) |

| | _ _ traverse the inodes_with_caps array |

| | _ _ Ruinodes _ with_caps array member = = child- > inode |

| | _ _ set under_child=true |

| | _ _ Ruinodes _ with_caps array member! = child- > inode |

| | _ _ traverses the CInode of the parent directory in turn along the inodes_with_caps array members |

| | _ _ if ergodic CInode==child- > inode |

| | _ _ set under_child=true |

| | _ _ under _ child==true |

| | _ _ call move_to_realm (child) function of in |

SnapRealm::prune_past_parents ()

| | _ _ call check_cache () |

| | _ _ traverses the past_parents array in srnode |

| | _ _ find snaplink_t.first in cached_snaps array in past_parents array |

| | _ _ if not found in the cached_snaps array |

| | _ _ call remove_open_past_parent (p-> second.ino, p-> first) to delete the corresponding entry from the past_parents array |

| | _ _ Delete the entry in the past_parents array in srnode, namely: srnode.past_parents.erase (p) |

The above is all the content of this article "sample Code of the SnapRealm Class". Thank you for reading it! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report