mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-23 01:13:23 +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();
|
||||
|
@ -1,6 +1,6 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use aster_frame::mm::{Frame, Segment, VmAllocOptions, VmIo};
|
||||
use aster_frame::mm::{Frame, FrameAllocOptions, Segment, VmIo};
|
||||
|
||||
use super::{
|
||||
bio::{Bio, BioEnqueueError, BioSegment, BioStatus, BioType, BioWaiter, SubmittedBio},
|
||||
@ -89,7 +89,7 @@ impl VmIo for dyn BlockDevice {
|
||||
let last = Bid::from_offset(offset + buf.len() - 1).to_raw();
|
||||
last - first + 1
|
||||
};
|
||||
let segment = VmAllocOptions::new(num_blocks as usize)
|
||||
let segment = FrameAllocOptions::new(num_blocks as usize)
|
||||
.uninit(true)
|
||||
.alloc_contiguous()?;
|
||||
let bio_segment = BioSegment::from_segment(segment, offset % BLOCK_SIZE, buf.len());
|
||||
@ -130,7 +130,7 @@ impl VmIo for dyn BlockDevice {
|
||||
let last = Bid::from_offset(offset + buf.len() - 1).to_raw();
|
||||
last - first + 1
|
||||
};
|
||||
let segment = VmAllocOptions::new(num_blocks as usize)
|
||||
let segment = FrameAllocOptions::new(num_blocks as usize)
|
||||
.uninit(true)
|
||||
.alloc_contiguous()?;
|
||||
segment.write_bytes(offset % BLOCK_SIZE, buf)?;
|
||||
@ -171,7 +171,7 @@ impl dyn BlockDevice {
|
||||
let last = Bid::from_offset(offset + buf.len() - 1).to_raw();
|
||||
last - first + 1
|
||||
};
|
||||
let segment = VmAllocOptions::new(num_blocks as usize)
|
||||
let segment = FrameAllocOptions::new(num_blocks as usize)
|
||||
.uninit(true)
|
||||
.alloc_contiguous()?;
|
||||
segment.write_bytes(offset % BLOCK_SIZE, buf)?;
|
||||
|
@ -4,7 +4,9 @@ use alloc::{collections::LinkedList, sync::Arc};
|
||||
|
||||
use align_ext::AlignExt;
|
||||
use aster_frame::{
|
||||
mm::{Daddr, DmaDirection, DmaStream, HasDaddr, VmAllocOptions, VmReader, VmWriter, PAGE_SIZE},
|
||||
mm::{
|
||||
Daddr, DmaDirection, DmaStream, FrameAllocOptions, HasDaddr, VmReader, VmWriter, PAGE_SIZE,
|
||||
},
|
||||
sync::SpinLock,
|
||||
};
|
||||
use pod::Pod;
|
||||
@ -27,7 +29,7 @@ impl TxBuffer {
|
||||
} else {
|
||||
let segment = {
|
||||
let nframes = (nbytes.align_up(PAGE_SIZE)) / PAGE_SIZE;
|
||||
VmAllocOptions::new(nframes).alloc_contiguous().unwrap()
|
||||
FrameAllocOptions::new(nframes).alloc_contiguous().unwrap()
|
||||
};
|
||||
DmaStream::map(segment, DmaDirection::ToDevice, false).unwrap()
|
||||
};
|
||||
|
@ -9,7 +9,9 @@ use alloc::{
|
||||
use core::ops::Range;
|
||||
|
||||
use aster_frame::{
|
||||
mm::{Daddr, DmaDirection, DmaStream, HasDaddr, VmAllocOptions, VmReader, VmWriter, PAGE_SIZE},
|
||||
mm::{
|
||||
Daddr, DmaDirection, DmaStream, FrameAllocOptions, HasDaddr, VmReader, VmWriter, PAGE_SIZE,
|
||||
},
|
||||
sync::{RwLock, SpinLock},
|
||||
};
|
||||
use bitvec::{array::BitArray, prelude::Lsb0};
|
||||
@ -145,7 +147,7 @@ impl DmaPage {
|
||||
pool: Weak<DmaPool>,
|
||||
) -> Result<Self, aster_frame::Error> {
|
||||
let dma_stream = {
|
||||
let vm_segment = VmAllocOptions::new(1).alloc_contiguous()?;
|
||||
let vm_segment = FrameAllocOptions::new(1).alloc_contiguous()?;
|
||||
|
||||
DmaStream::map(vm_segment, direction, is_cache_coherent)
|
||||
.map_err(|_| aster_frame::Error::AccessDenied)?
|
||||
|
@ -9,7 +9,7 @@ use aster_block::{
|
||||
};
|
||||
use aster_frame::{
|
||||
io_mem::IoMem,
|
||||
mm::{DmaDirection, DmaStream, DmaStreamSlice, VmAllocOptions, VmIo},
|
||||
mm::{DmaDirection, DmaStream, DmaStreamSlice, FrameAllocOptions, VmIo},
|
||||
sync::SpinLock,
|
||||
trap::TrapFrame,
|
||||
};
|
||||
@ -100,12 +100,12 @@ impl DeviceInner {
|
||||
let queue = VirtQueue::new(0, Self::QUEUE_SIZE, transport.as_mut())
|
||||
.expect("create virtqueue failed");
|
||||
let block_requests = {
|
||||
let vm_segment = VmAllocOptions::new(1).alloc_contiguous().unwrap();
|
||||
let vm_segment = FrameAllocOptions::new(1).alloc_contiguous().unwrap();
|
||||
DmaStream::map(vm_segment, DmaDirection::Bidirectional, false).unwrap()
|
||||
};
|
||||
assert!(Self::QUEUE_SIZE as usize * REQ_SIZE <= block_requests.nbytes());
|
||||
let block_responses = {
|
||||
let vm_segment = VmAllocOptions::new(1).alloc_contiguous().unwrap();
|
||||
let vm_segment = FrameAllocOptions::new(1).alloc_contiguous().unwrap();
|
||||
DmaStream::map(vm_segment, DmaDirection::Bidirectional, false).unwrap()
|
||||
};
|
||||
assert!(Self::QUEUE_SIZE as usize * RESP_SIZE <= block_responses.nbytes());
|
||||
@ -216,7 +216,7 @@ impl DeviceInner {
|
||||
};
|
||||
const MAX_ID_LENGTH: usize = 20;
|
||||
let device_id_stream = {
|
||||
let segment = VmAllocOptions::new(1)
|
||||
let segment = FrameAllocOptions::new(1)
|
||||
.uninit(true)
|
||||
.alloc_contiguous()
|
||||
.unwrap();
|
||||
|
@ -6,7 +6,7 @@ use core::hint::spin_loop;
|
||||
use aster_console::{AnyConsoleDevice, ConsoleCallback};
|
||||
use aster_frame::{
|
||||
io_mem::IoMem,
|
||||
mm::{DmaDirection, DmaStream, DmaStreamSlice, VmAllocOptions, VmReader},
|
||||
mm::{DmaDirection, DmaStream, DmaStreamSlice, FrameAllocOptions, VmReader},
|
||||
sync::{RwLock, SpinLock},
|
||||
trap::TrapFrame,
|
||||
};
|
||||
@ -87,12 +87,12 @@ impl ConsoleDevice {
|
||||
SpinLock::new(VirtQueue::new(TRANSMIT0_QUEUE_INDEX, 2, transport.as_mut()).unwrap());
|
||||
|
||||
let send_buffer = {
|
||||
let vm_segment = VmAllocOptions::new(1).alloc_contiguous().unwrap();
|
||||
let vm_segment = FrameAllocOptions::new(1).alloc_contiguous().unwrap();
|
||||
DmaStream::map(vm_segment, DmaDirection::ToDevice, false).unwrap()
|
||||
};
|
||||
|
||||
let receive_buffer = {
|
||||
let vm_segment = VmAllocOptions::new(1).alloc_contiguous().unwrap();
|
||||
let vm_segment = FrameAllocOptions::new(1).alloc_contiguous().unwrap();
|
||||
DmaStream::map(vm_segment, DmaDirection::FromDevice, false).unwrap()
|
||||
};
|
||||
|
||||
|
@ -10,7 +10,7 @@ use core::{fmt::Debug, iter, mem};
|
||||
|
||||
use aster_frame::{
|
||||
io_mem::IoMem,
|
||||
mm::{DmaDirection, DmaStream, HasDaddr, VmAllocOptions, VmIo, PAGE_SIZE},
|
||||
mm::{DmaDirection, DmaStream, FrameAllocOptions, HasDaddr, VmIo, PAGE_SIZE},
|
||||
offset_of,
|
||||
sync::{RwLock, SpinLock},
|
||||
trap::TrapFrame,
|
||||
@ -239,7 +239,7 @@ impl EventTable {
|
||||
fn new(num_events: usize) -> Self {
|
||||
assert!(num_events * mem::size_of::<VirtioInputEvent>() <= PAGE_SIZE);
|
||||
|
||||
let vm_segment = VmAllocOptions::new(1).alloc_contiguous().unwrap();
|
||||
let vm_segment = FrameAllocOptions::new(1).alloc_contiguous().unwrap();
|
||||
|
||||
let default_event = VirtioInputEvent::default();
|
||||
let iter = iter::repeat(&default_event).take(EVENT_SIZE);
|
||||
|
@ -10,7 +10,7 @@ use core::{
|
||||
|
||||
use aster_frame::{
|
||||
io_mem::IoMem,
|
||||
mm::{DmaCoherent, VmAllocOptions},
|
||||
mm::{DmaCoherent, FrameAllocOptions},
|
||||
offset_of,
|
||||
};
|
||||
use aster_rights::{Dup, TRightSet, TRights, Write};
|
||||
@ -82,7 +82,7 @@ impl VirtQueue {
|
||||
let desc_size = size_of::<Descriptor>() * size as usize;
|
||||
|
||||
let (seg1, seg2) = {
|
||||
let continue_segment = VmAllocOptions::new(2).alloc_contiguous().unwrap();
|
||||
let continue_segment = FrameAllocOptions::new(2).alloc_contiguous().unwrap();
|
||||
let seg1 = continue_segment.range(0..1);
|
||||
let seg2 = continue_segment.range(1..2);
|
||||
(seg1, seg2)
|
||||
@ -101,17 +101,17 @@ impl VirtQueue {
|
||||
}
|
||||
(
|
||||
SafePtr::new(
|
||||
DmaCoherent::map(VmAllocOptions::new(1).alloc_contiguous().unwrap(), true)
|
||||
DmaCoherent::map(FrameAllocOptions::new(1).alloc_contiguous().unwrap(), true)
|
||||
.unwrap(),
|
||||
0,
|
||||
),
|
||||
SafePtr::new(
|
||||
DmaCoherent::map(VmAllocOptions::new(1).alloc_contiguous().unwrap(), true)
|
||||
DmaCoherent::map(FrameAllocOptions::new(1).alloc_contiguous().unwrap(), true)
|
||||
.unwrap(),
|
||||
0,
|
||||
),
|
||||
SafePtr::new(
|
||||
DmaCoherent::map(VmAllocOptions::new(1).alloc_contiguous().unwrap(), true)
|
||||
DmaCoherent::map(FrameAllocOptions::new(1).alloc_contiguous().unwrap(), true)
|
||||
.unwrap(),
|
||||
0,
|
||||
),
|
||||
|
Reference in New Issue
Block a user