vnode的數據結構:node
1 struct sd_vnode { 2 struct rb_node rb; 3 const struct sd_node *node; 4 uint64_t hash; 5 }; 6 7 struct vnode_info { 8 struct rb_root vroot; // vnode的root ? 9 struct rb_root nroot; // node的root ? 10 int nr_nodes; 11 int nr_zones; 12 refcnt_t refcnt; 13 };
oid和vnode的映射關係:數據結構
1 /* If v1_hash < oid_hash <= v2_hash, then oid is resident on v2 根據oid,從root出發查找第一個合適的位置 */ 2 static inline struct sd_vnode * 3 oid_to_first_vnode(uint64_t oid, struct rb_root *root) 4 { 5 struct sd_vnode dummy = { 6 .hash = sd_hash_oid(oid), 7 }; 8 return rb_nsearch(root, &dummy, rb, vnode_cmp); 9 } 10 /* oid向vnode映射: 原則是先找到第一個存放的位置,隨後的位置按照next向下找,只要在不一樣的zone下,均可以 */ 11 /* Replica are placed along the ring one by one with different zones */ 12 static inline void oid_to_vnodes(uint64_t oid, struct rb_root *root, 13 int nr_copies, 14 const struct sd_vnode **vnodes) 15 { 16 const struct sd_vnode *next = oid_to_first_vnode(oid, root); 17 18 vnodes[0] = next; 19 for (int i = 1; i < nr_copies; i++) { 20 next: 21 next = rb_entry(rb_next(&next->rb), struct sd_vnode, rb); 22 if (!next) /* Wrap around */ 23 next = rb_entry(rb_first(root), struct sd_vnode, rb); 24 if (unlikely(next == vnodes[0])) 25 panic("can't find a valid vnode"); 26 for (int j = 0; j < i; j++) 27 if (same_zone(vnodes[j], next)) // 逐個比較已分配的vnode,不能在同一個分區zone內 28 goto next; 29 vnodes[i] = next; 30 } 31 } 32 33 static inline const struct sd_vnode * 34 oid_to_vnode(uint64_t oid, struct rb_root *root, int copy_idx) 35 { 36 const struct sd_vnode *vnodes[SD_MAX_COPIES]; 37 38 oid_to_vnodes(oid, root, copy_idx + 1, vnodes); 39 40 return vnodes[copy_idx]; 41 } 42 /* 爲一個oid分配copy_idx個vnode */ 43 static inline const struct sd_node * 44 oid_to_node(uint64_t oid, struct rb_root *root, int copy_idx) 45 { 46 const struct sd_vnode *vnode; 47 48 vnode = oid_to_vnode(oid, root, copy_idx); 49 50 return vnode->node; 51 } 52 53 static inline void oid_to_nodes(uint64_t oid, struct rb_root *root, 54 int nr_copies, 55 const struct sd_node **nodes) 56 { 57 const struct sd_vnode *vnodes[SD_MAX_COPIES]; 58 59 oid_to_vnodes(oid, root, nr_copies, vnodes); 60 for (int i = 0; i < nr_copies; i++) 61 nodes[i] = vnodes[i]->node; 62 }
物理node的結構體:ide
1 struct sd_node { 2 struct rb_node rb; // 存儲node信息的rbtree 3 struct node_id nid; // nodeid 4 uint16_t nr_vnodes; // 對應vnode的個數 5 uint32_t zone; // zone的id ? 6 uint64_t space; // ? 7 #ifdef HAVE_DISKVNODES 8 #define SD_MAX_NODES 830 // vdisk mode下最大支持節點個數 9 #define SD_NODE_SIZE (80 + sizeof(struct disk_info) * DISK_MAX) 10 struct disk_info disks[DISK_MAX]; // 節點下物理磁盤的個數,最大支持32盤 11 #else // 非vdisk mode模式 12 #define SD_MAX_NODES 6144 // 最大節點個數 13 #define SD_NODE_SIZE 80 // 該模式下全部的磁盤一視同仁,並無vdisk的管理和disk管理 14 struct disk_info disks[0]; 15 #endif 16 };