mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-26 19:03:27 +00:00
Refactor the source structure in aster_frame::mm
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
e8595b95fe
commit
7095b37e7e
@ -9,7 +9,7 @@ use aster_block::{
|
||||
id::{Bid, BlockId},
|
||||
BLOCK_SIZE,
|
||||
};
|
||||
use aster_frame::mm::{Frame, VmAllocOptions, VmIo};
|
||||
use aster_frame::mm::{Frame, FrameAllocOptions, VmIo};
|
||||
use aster_rights::Full;
|
||||
|
||||
use super::{
|
||||
@ -1242,7 +1242,10 @@ impl Inode for ExfatInode {
|
||||
.discard_range(read_off..read_off + read_len);
|
||||
|
||||
let mut buf_offset = 0;
|
||||
let frame = VmAllocOptions::new(1).uninit(true).alloc_single().unwrap();
|
||||
let frame = FrameAllocOptions::new(1)
|
||||
.uninit(true)
|
||||
.alloc_single()
|
||||
.unwrap();
|
||||
|
||||
let start_pos = inner.start_chain.walk_to_cluster_at_offset(read_off)?;
|
||||
let cluster_size = inner.fs().cluster_size();
|
||||
@ -1355,7 +1358,10 @@ impl Inode for ExfatInode {
|
||||
let mut cur_offset = start_pos.1;
|
||||
for _ in Bid::from_offset(offset)..Bid::from_offset(end_offset) {
|
||||
let frame = {
|
||||
let frame = VmAllocOptions::new(1).uninit(true).alloc_single().unwrap();
|
||||
let frame = FrameAllocOptions::new(1)
|
||||
.uninit(true)
|
||||
.alloc_single()
|
||||
.unwrap();
|
||||
frame.write_bytes(0, &buf[buf_offset..buf_offset + BLOCK_SIZE])?;
|
||||
frame
|
||||
};
|
||||
|
@ -21,7 +21,7 @@ mod test {
|
||||
bio::{BioEnqueueError, BioStatus, BioType, SubmittedBio},
|
||||
BlockDevice,
|
||||
};
|
||||
use aster_frame::mm::{Segment, VmAllocOptions, VmIo};
|
||||
use aster_frame::mm::{FrameAllocOptions, Segment, VmIo};
|
||||
use rand::{rngs::SmallRng, RngCore, SeedableRng};
|
||||
|
||||
use crate::{
|
||||
@ -102,7 +102,7 @@ mod test {
|
||||
/// Read exfat disk image
|
||||
fn new_vm_segment_from_image() -> Segment {
|
||||
let vm_segment = {
|
||||
VmAllocOptions::new(EXFAT_IMAGE.len() / PAGE_SIZE)
|
||||
FrameAllocOptions::new(EXFAT_IMAGE.len() / PAGE_SIZE)
|
||||
.is_contiguous(true)
|
||||
.uninit(true)
|
||||
.alloc_contiguous()
|
||||
|
@ -40,7 +40,7 @@ impl Ext2 {
|
||||
let npages = ((super_block.block_groups_count() as usize)
|
||||
* core::mem::size_of::<RawGroupDescriptor>())
|
||||
.div_ceil(BLOCK_SIZE);
|
||||
let segment = VmAllocOptions::new(npages)
|
||||
let segment = FrameAllocOptions::new(npages)
|
||||
.uninit(true)
|
||||
.alloc_contiguous()?;
|
||||
match block_device.read_blocks_sync(super_block.group_descriptors_bid(0), &segment)? {
|
||||
|
@ -132,7 +132,7 @@ impl IndirectBlock {
|
||||
/// Allocates an uninitialized block whose bytes are to be populated with
|
||||
/// data loaded from the disk.
|
||||
fn alloc_uninit() -> Result<Self> {
|
||||
let frame = VmAllocOptions::new(1).uninit(true).alloc_single()?;
|
||||
let frame = FrameAllocOptions::new(1).uninit(true).alloc_single()?;
|
||||
Ok(Self {
|
||||
frame,
|
||||
state: State::Uninit,
|
||||
@ -141,7 +141,7 @@ impl IndirectBlock {
|
||||
|
||||
/// Allocates a new block with its bytes initialized to zero.
|
||||
pub fn alloc() -> Result<Self> {
|
||||
let frame = VmAllocOptions::new(1).alloc_single()?;
|
||||
let frame = FrameAllocOptions::new(1).alloc_single()?;
|
||||
Ok(Self {
|
||||
frame,
|
||||
state: State::Dirty,
|
||||
|
@ -653,7 +653,10 @@ impl Inner {
|
||||
|
||||
let mut buf_offset = 0;
|
||||
for bid in Bid::from_offset(offset)..Bid::from_offset(offset + read_len) {
|
||||
let frame = VmAllocOptions::new(1).uninit(true).alloc_single().unwrap();
|
||||
let frame = FrameAllocOptions::new(1)
|
||||
.uninit(true)
|
||||
.alloc_single()
|
||||
.unwrap();
|
||||
self.inode_impl
|
||||
.read_block_sync(bid.to_raw() as Ext2Bid, &frame)?;
|
||||
frame.read_bytes(0, &mut buf[buf_offset..buf_offset + BLOCK_SIZE])?;
|
||||
@ -691,7 +694,10 @@ impl Inner {
|
||||
let mut buf_offset = 0;
|
||||
for bid in Bid::from_offset(offset)..Bid::from_offset(end_offset) {
|
||||
let frame = {
|
||||
let frame = VmAllocOptions::new(1).uninit(true).alloc_single().unwrap();
|
||||
let frame = FrameAllocOptions::new(1)
|
||||
.uninit(true)
|
||||
.alloc_single()
|
||||
.unwrap();
|
||||
frame.write_bytes(0, &buf[buf_offset..buf_offset + BLOCK_SIZE])?;
|
||||
frame
|
||||
};
|
||||
@ -1572,7 +1578,7 @@ impl InodeImpl {
|
||||
|
||||
pub fn sync_data_holes(&self) -> Result<()> {
|
||||
let inner = self.0.read();
|
||||
let zero_frame = VmAllocOptions::new(1).alloc_single().unwrap();
|
||||
let zero_frame = FrameAllocOptions::new(1).alloc_single().unwrap();
|
||||
for bid in 0..inner.desc.blocks_count() {
|
||||
let is_data_hole = inner.blocks_hole_desc.read().is_hole(bid as usize);
|
||||
if is_data_hole {
|
||||
|
@ -12,7 +12,7 @@ pub(super) use aster_block::{
|
||||
BlockDevice, BLOCK_SIZE,
|
||||
};
|
||||
pub(super) use aster_frame::{
|
||||
mm::{Frame, Segment, VmAllocOptions, VmIo},
|
||||
mm::{Frame, FrameAllocOptions, Segment, VmIo},
|
||||
sync::{RwMutex, RwMutexReadGuard, RwMutexWriteGuard},
|
||||
};
|
||||
pub(super) use aster_rights::Full;
|
||||
|
@ -3,7 +3,7 @@
|
||||
use core::ops::Range;
|
||||
|
||||
use aster_block::bio::{BioStatus, BioWaiter};
|
||||
use aster_frame::mm::{Frame, VmAllocOptions};
|
||||
use aster_frame::mm::{Frame, FrameAllocOptions};
|
||||
use aster_rights::Full;
|
||||
use lru::LruCache;
|
||||
|
||||
@ -208,7 +208,7 @@ struct Page {
|
||||
|
||||
impl Page {
|
||||
pub fn alloc() -> Result<Self> {
|
||||
let frame = VmAllocOptions::new(1).uninit(true).alloc_single()?;
|
||||
let frame = FrameAllocOptions::new(1).uninit(true).alloc_single()?;
|
||||
Ok(Self {
|
||||
frame,
|
||||
state: PageState::Uninit,
|
||||
@ -216,7 +216,7 @@ impl Page {
|
||||
}
|
||||
|
||||
pub fn alloc_zero() -> Result<Self> {
|
||||
let frame = VmAllocOptions::new(1).alloc_single()?;
|
||||
let frame = FrameAllocOptions::new(1).alloc_single()?;
|
||||
Ok(Self {
|
||||
frame,
|
||||
state: PageState::Dirty,
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
use core::ops::Range;
|
||||
|
||||
use aster_frame::mm::{Frame, PageFlags, VmFrameVec, VmIo, VmMapOptions, VmSpace};
|
||||
use aster_frame::mm::{Frame, FrameVec, PageFlags, VmIo, VmMapOptions, VmSpace};
|
||||
|
||||
use super::{interval::Interval, is_intersected, Vmar, Vmar_};
|
||||
use crate::{
|
||||
@ -484,7 +484,7 @@ impl VmMappingInner {
|
||||
vm_space.unmap(&(map_addr..(map_addr + PAGE_SIZE))).unwrap();
|
||||
}
|
||||
|
||||
vm_space.map(VmFrameVec::from_one_frame(frame), &vm_map_options)?;
|
||||
vm_space.map(FrameVec::from_one_frame(frame), &vm_map_options)?;
|
||||
self.mapped_pages.insert(page_idx);
|
||||
Ok(())
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ use core::ops::Range;
|
||||
use align_ext::AlignExt;
|
||||
use aster_frame::{
|
||||
collections::xarray::{CursorMut, XArray, XMark},
|
||||
mm::{Frame, VmAllocOptions, VmReader, VmWriter},
|
||||
mm::{Frame, FrameAllocOptions, VmReader, VmWriter},
|
||||
};
|
||||
use aster_rights::Rights;
|
||||
|
||||
@ -195,7 +195,7 @@ pub(super) struct Vmo_ {
|
||||
}
|
||||
|
||||
fn clone_page(page: &Frame) -> Result<Frame> {
|
||||
let new_page = VmAllocOptions::new(1).alloc_single()?;
|
||||
let new_page = FrameAllocOptions::new(1).alloc_single()?;
|
||||
new_page.copy_from(page);
|
||||
Ok(new_page)
|
||||
}
|
||||
@ -221,7 +221,7 @@ impl Vmo_ {
|
||||
None => {
|
||||
// Condition 1. The new anonymous page only need to be marked as `ExclusivePage`
|
||||
// when current VMO is a cow VMO, otherwise this mark is meaningless.
|
||||
(VmAllocOptions::new(1).alloc_single()?, is_cow_vmo)
|
||||
(FrameAllocOptions::new(1).alloc_single()?, is_cow_vmo)
|
||||
}
|
||||
Some(pager) => {
|
||||
let page = pager.commit_page(page_idx)?;
|
||||
|
@ -7,7 +7,7 @@ use core::{marker::PhantomData, ops::Range};
|
||||
use align_ext::AlignExt;
|
||||
use aster_frame::{
|
||||
collections::xarray::XArray,
|
||||
mm::{Frame, VmAllocOptions},
|
||||
mm::{Frame, FrameAllocOptions},
|
||||
};
|
||||
use aster_rights::{Dup, Rights, TRightSet, TRights, Write};
|
||||
use aster_rights_proc::require;
|
||||
@ -144,7 +144,7 @@ fn committed_pages_if_continuous(flags: VmoFlags, size: usize) -> Result<XArray<
|
||||
if flags.contains(VmoFlags::CONTIGUOUS) {
|
||||
// if the vmo is continuous, we need to allocate frames for the vmo
|
||||
let frames_num = size / PAGE_SIZE;
|
||||
let frames = VmAllocOptions::new(frames_num)
|
||||
let frames = FrameAllocOptions::new(frames_num)
|
||||
.is_contiguous(true)
|
||||
.alloc()?;
|
||||
let mut committed_pages = XArray::new();
|
||||
|
Reference in New Issue
Block a user