diff --git a/rafs/src/builder/compact.rs b/rafs/src/builder/compact.rs index 1c6040e5c8a..11d30f42c39 100644 --- a/rafs/src/builder/compact.rs +++ b/rafs/src/builder/compact.rs @@ -3,7 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 use std::collections::hash_map::Entry; -use std::collections::HashMap; +use std::collections::{HashMap, VecDeque}; use std::io::Write; use std::ops::Deref; use std::path::PathBuf; @@ -252,7 +252,7 @@ pub struct BlobCompactor { /// new blobs new_blob_mgr: BlobManager, /// inode list - nodes: Vec, + nodes: VecDeque, /// chunk --> list c2nodes: HashMap>, /// original blob index --> list @@ -265,7 +265,7 @@ impl BlobCompactor { pub fn new( version: RafsVersion, ori_blob_mgr: BlobManager, - nodes: Vec, + nodes: VecDeque, backend: Arc, digester: digest::Algorithm, ) -> Result { @@ -596,7 +596,7 @@ impl BlobCompactor { let tree = Tree::from_bootstrap(&rs, &mut _dict)?; let mut bootstrap = Bootstrap::new()?; bootstrap.build(&mut build_ctx, &mut bootstrap_ctx, tree)?; - let mut nodes = Vec::new(); + let mut nodes = VecDeque::new(); // move out nodes std::mem::swap(&mut bootstrap_ctx.nodes, &mut nodes); let mut compactor = Self::new( diff --git a/rafs/src/builder/core/blob.rs b/rafs/src/builder/core/blob.rs index 5623aaeac78..bf08add4d1a 100644 --- a/rafs/src/builder/core/blob.rs +++ b/rafs/src/builder/core/blob.rs @@ -3,6 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 use std::borrow::Cow; +use std::collections::VecDeque; use std::io::Write; use std::slice; @@ -27,7 +28,7 @@ impl Blob { /// Dump blob file and generate chunks pub(crate) fn dump( ctx: &BuildContext, - nodes: &mut [Node], + nodes: &mut VecDeque, blob_mgr: &mut BlobManager, blob_writer: &mut ArtifactWriter, ) -> Result<()> { diff --git a/rafs/src/builder/core/bootstrap.rs b/rafs/src/builder/core/bootstrap.rs index 74b9f67ee9a..57c863849ff 100644 --- a/rafs/src/builder/core/bootstrap.rs +++ b/rafs/src/builder/core/bootstrap.rs @@ -3,6 +3,7 @@ // // SPDX-License-Identifier: Apache-2.0 +use std::collections::VecDeque; use std::ffi::OsString; use anyhow::{Context, Error, Result}; @@ -52,7 +53,7 @@ impl Bootstrap { ) -> Result<()> { // used to compute nid(ino) for v6 let root_offset = bootstrap_ctx.offset; - let mut nodes = Vec::with_capacity(0x10000); + let mut nodes = VecDeque::with_capacity(0x10000); // Special handling of the root inode assert!(tree.node.is_dir()); @@ -63,7 +64,7 @@ impl Bootstrap { tree.node.inode.set_ino(RAFS_V5_ROOT_INODE); } ctx.prefetch.insert_if_need(&tree.node); - nodes.push(tree.node.clone()); + nodes.push_back(tree.node.clone()); Self::build_rafs(ctx, bootstrap_ctx, &mut tree, &mut nodes)?; if ctx.fs_version.is_v6() && !bootstrap_ctx.layered { @@ -147,7 +148,7 @@ impl Bootstrap { ctx: &mut BuildContext, bootstrap_ctx: &mut BootstrapContext, tree: &mut Tree, - nodes: &mut Vec, + nodes: &mut VecDeque, ) -> Result<()> { let index = nodes.len() as u32 + 1; let parent = &mut nodes[tree.node.index as usize - 1]; @@ -231,14 +232,14 @@ impl Bootstrap { (true, Some(whiteout_type)) => { // Insert removal operations at the head, so they will be handled first when // applying to lower layer. - nodes.insert(0, child.node.clone()); + nodes.push_front(child.node.clone()); if whiteout_type == WhiteoutType::OverlayFsOpaque { // For the overlayfs opaque, we need to remove the lower node that has the // same name first, then apply upper node to the node tree of lower layer. child .node .remove_xattr(&OsString::from(OVERLAYFS_WHITEOUT_OPAQUE)); - nodes.push(child.node.clone()); + nodes.push_back(child.node.clone()); } } (false, Some(whiteout_type)) => { @@ -248,9 +249,9 @@ impl Bootstrap { .node .remove_xattr(&OsString::from(OVERLAYFS_WHITEOUT_OPAQUE)); } - nodes.push(child.node.clone()); + nodes.push_back(child.node.clone()); } - _ => nodes.push(child.node.clone()), + _ => nodes.push_back(child.node.clone()), } ctx.prefetch.insert_if_need(&child.node); diff --git a/rafs/src/builder/core/context.rs b/rafs/src/builder/core/context.rs index a9c26da1b89..9c427db450e 100644 --- a/rafs/src/builder/core/context.rs +++ b/rafs/src/builder/core/context.rs @@ -960,7 +960,7 @@ pub struct BootstrapContext { /// Cache node index for hardlinks, HashMap<(layer_index, real_inode, dev), Vec>. pub(crate) inode_map: HashMap<(u16, Inode, u64), Vec>, /// Store all nodes in ascendant order, indexed by (node.index - 1). - pub nodes: Vec, + pub nodes: VecDeque, /// Current position to write in f_bootstrap pub(crate) offset: u64, pub(crate) writer: Box, @@ -979,7 +979,7 @@ impl BootstrapContext { Ok(Self { layered, inode_map: HashMap::new(), - nodes: Vec::new(), + nodes: VecDeque::new(), offset: EROFS_BLOCK_SIZE_4096, writer, v6_available_blocks: vec![ diff --git a/rafs/src/builder/core/layout.rs b/rafs/src/builder/core/layout.rs index 1d0346298c4..f3a53258236 100644 --- a/rafs/src/builder/core/layout.rs +++ b/rafs/src/builder/core/layout.rs @@ -3,6 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 use anyhow::Result; +use std::collections::VecDeque; use super::node::Node; use crate::builder::{Overlay, Prefetch}; @@ -11,7 +12,10 @@ use crate::builder::{Overlay, Prefetch}; pub struct BlobLayout {} impl BlobLayout { - pub fn layout_blob_simple(prefetch: &Prefetch, nodes: &[Node]) -> Result<(Vec, usize)> { + pub fn layout_blob_simple( + prefetch: &Prefetch, + nodes: &VecDeque, + ) -> Result<(Vec, usize)> { let mut inodes = Vec::with_capacity(nodes.len()); // Put all prefetch inodes at the head diff --git a/rafs/src/builder/core/prefetch.rs b/rafs/src/builder/core/prefetch.rs index 4391a74e527..d4855f9fc93 100644 --- a/rafs/src/builder/core/prefetch.rs +++ b/rafs/src/builder/core/prefetch.rs @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: Apache-2.0 -use std::collections::BTreeMap; +use std::collections::{BTreeMap, VecDeque}; use std::path::PathBuf; use std::str::FromStr; @@ -181,7 +181,7 @@ impl Prefetch { } /// Generate filesystem layer prefetch list for RAFS v5. - pub fn get_v5_prefetch_table(&mut self, nodes: &[Node]) -> Option { + pub fn get_v5_prefetch_table(&mut self, nodes: &VecDeque) -> Option { if self.policy == PrefetchPolicy::Fs { let mut prefetch_table = RafsV5PrefetchTable::new(); for i in self.patterns.values().filter_map(|v| *v) { @@ -199,7 +199,7 @@ impl Prefetch { /// Generate filesystem layer prefetch list for RAFS v6. pub fn get_v6_prefetch_table( &mut self, - nodes: &[Node], + nodes: &VecDeque, meta_addr: u64, ) -> Option { if self.policy == PrefetchPolicy::Fs { diff --git a/rafs/src/builder/core/v6.rs b/rafs/src/builder/core/v6.rs index 6cc8a921e6a..18add7866d7 100644 --- a/rafs/src/builder/core/v6.rs +++ b/rafs/src/builder/core/v6.rs @@ -3,7 +3,7 @@ // // SPDX-License-Identifier: Apache-2.0 -use std::collections::BTreeMap; +use std::collections::{BTreeMap, VecDeque}; use std::ffi::{OsStr, OsString}; use std::io::SeekFrom; use std::mem::size_of; @@ -556,7 +556,7 @@ impl BuildContext { } impl Bootstrap { - pub(crate) fn v6_update_dirents(nodes: &mut Vec, tree: &Tree, parent_offset: u64) { + pub(crate) fn v6_update_dirents(nodes: &mut VecDeque, tree: &Tree, parent_offset: u64) { let node = &mut nodes[tree.node.index as usize - 1]; let node_offset = node.v6_offset; if !node.is_dir() { diff --git a/rafs/src/builder/merge.rs b/rafs/src/builder/merge.rs index cbed3de08bc..a303cd9b31c 100644 --- a/rafs/src/builder/merge.rs +++ b/rafs/src/builder/merge.rs @@ -2,9 +2,9 @@ // // SPDX-License-Identifier: Apache-2.0 -use std::collections::btree_map::Entry; -use std::collections::HashMap; use std::collections::HashSet; +use std::collections::{HashMap, VecDeque}; +use std::collections::hash_map::Entry; use std::convert::TryFrom; use std::path::{Path, PathBuf}; use std::sync::Arc; @@ -211,7 +211,7 @@ impl Merger { } if let Some(tree) = &mut tree { - let mut nodes = Vec::new(); + let mut nodes = VecDeque::new(); rs.walk_directory::( rs.superblock.root_ino(), None, @@ -245,8 +245,8 @@ impl Merger { match node.whiteout_type(WhiteoutSpec::Oci) { // Insert whiteouts at the head, so they will be handled first when // applying to lower layer. - Some(_) => nodes.insert(0, node), - _ => nodes.push(node), + Some(_) => nodes.push_front(node), + _ => nodes.push_back(node), } Ok(()) },