remove unused imports

This commit is contained in:
Samuka007 2024-10-16 08:15:04 +00:00
parent ce8026c0d4
commit de148a1dd6
17 changed files with 38 additions and 266 deletions

View File

@ -8,7 +8,7 @@ use crate::driver::base::kobject::{
};
use crate::driver::base::kset::KSet;
use crate::filesystem::kernfs::KernFSInode;
use crate::init::initcall::INITCALL_DEVICE;
// use crate::init::initcall::INITCALL_DEVICE;
use crate::libs::rwlock::{RwLockReadGuard, RwLockWriteGuard};
use crate::libs::spinlock::{SpinLock, SpinLockGuard};
use crate::net::{generate_iface_id, NET_DEVICES};
@ -26,7 +26,7 @@ use smoltcp::{
wire::{IpAddress, IpCidr},
};
use system_error::SystemError;
use unified_init::macros::unified_init;
// use unified_init::macros::unified_init;
use super::{register_netdevice, NetDeivceState, NetDeviceCommonData, Operstate};

View File

@ -1,9 +1,5 @@
use alloc::{fmt, vec::Vec};
use alloc::{string::String, sync::Arc};
use smoltcp::{
iface,
wire::{self, EthernetAddress},
};
use sysfs::netdev_register_kobject;
use crate::{

View File

@ -1,5 +1,4 @@
use alloc::sync::Arc;
use log::{debug, warn};
use system_error::SystemError;
use super::{
@ -58,7 +57,7 @@ pub fn do_fchmodat(dirfd: i32, path: *const u8, _mode: ModeType) -> Result<usize
// 如果找不到文件则返回错误码ENOENT
let _inode = inode.lookup_follow_symlink(path.as_str(), VFS_MAX_FOLLOW_SYMLINK_TIMES)?;
warn!("do_fchmodat: not implemented yet\n");
log::warn!("do_fchmodat: not implemented yet\n");
// todo: 真正去改变文件的权限
return Ok(0);

View File

@ -2,7 +2,6 @@ use core::ffi::c_void;
use core::mem::size_of;
use alloc::{string::String, sync::Arc, vec::Vec};
use log::{debug, warn};
use system_error::SystemError;
use crate::producefs;
@ -1225,7 +1224,7 @@ impl Syscall {
// TODO: unimplemented
// 未实现的命令返回0不报错。
warn!("fcntl: unimplemented command: {:?}, defaults to 0.", cmd);
log::warn!("fcntl: unimplemented command: {:?}, defaults to 0.", cmd);
return Err(SystemError::ENOSYS);
}
}
@ -1614,7 +1613,7 @@ impl Syscall {
// fchmod没完全实现因此不修改文件的权限
// todo: 实现fchmod
warn!("fchmod not fully implemented");
log::warn!("fchmod not fully implemented");
return Ok(0);
}
/// #挂载文件系统

View File

@ -2,10 +2,7 @@
//! 注意net模块下为了方便导入模块细分且共用部分模块直接使用
//! `pub use`导出,导入时也常见`use crate::net::socket::*`的写法,
//! 敬请注意。
use core::{
fmt::{self, Debug},
sync::atomic::AtomicUsize,
};
use core::sync::atomic::AtomicUsize;
use alloc::{collections::BTreeMap, sync::Arc};

View File

@ -1,6 +1,6 @@
use alloc::vec::Vec;
use alloc::{string::String, sync::Arc};
use alloc::sync::Arc;
use system_error::SystemError;
use crate::libs::spinlock::SpinLock;
@ -75,6 +75,7 @@ impl Buffer {
#[derive(Debug)]
pub struct Metadata {
/// 默认的元数据缓冲区大小
#[allow(dead_code)]
metadata_buf_size: usize,
/// 默认的缓冲区大小
buf_size: usize,

View File

@ -6,10 +6,8 @@ use alloc::{
use system_error::SystemError;
use crate::{
libs::{spinlock::SpinLock, wait_queue::EventWaitQueue},
net::event_poll::{EPollEventType, EPollItem, EventPoll},
process::ProcessManager,
sched::{schedule, SchedMode},
libs::spinlock::SpinLock,
net::event_poll::{EPollItem, EventPoll},
};
#[derive(Debug, Clone)]

View File

@ -5,6 +5,7 @@ use system_error::SystemError::{self, *};
pub mod port;
pub use port::PortManager;
#[allow(dead_code)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Types {
Raw,

View File

@ -2,9 +2,7 @@ use inet::InetSocket;
use smoltcp;
use system_error::SystemError::{self, *};
use crate::filesystem::vfs::IndexNode;
use crate::libs::rwlock::RwLock;
use crate::libs::spinlock::SpinLock;
use crate::net::event_poll::EPollEventType;
use crate::net::net_core::poll_ifaces;
use crate::net::socket::*;
@ -210,15 +208,11 @@ impl Socket for UdpSocket {
}
fn send(&self, buffer: &[u8], flags: MessageFlag) -> Result<usize, SystemError> {
// if flags.contains(MessageFlag::DONTWAIT) {
if flags.contains(MessageFlag::DONTWAIT) {
log::warn!("Nonblock send is not implemented yet");
}
return self.try_send(buffer, None);
// } else {
// // return self
// // .wait_queue
// // .busy_wait(EP::EPOLLOUT, || self.try_send(buffer, None));
// todo!()
// }
}
fn send_to(
@ -227,21 +221,14 @@ impl Socket for UdpSocket {
flags: MessageFlag,
address: Endpoint,
) -> Result<usize, SystemError> {
// if flags.contains(MessageFlag::DONTWAIT) {
if flags.contains(MessageFlag::DONTWAIT) {
log::warn!("Nonblock send is not implemented yet");
}
if let Endpoint::Ip(remote) = address {
return self.try_send(buffer, Some(remote));
}
// } else {
// // return self
// // .wait_queue
// // .busy_wait(EP::EPOLLOUT, || {
// // if let Endpoint::Ip(remote) = address {
// // return self.try_send(buffer, Some(remote.addr));
// // }
// // return Err(EAFNOSUPPORT);
// // });
// todo!()
// }
return Err(EINVAL);
}

View File

@ -1,4 +1,4 @@
use core::sync::atomic::{AtomicU32, AtomicUsize};
use core::sync::atomic::AtomicUsize;
use crate::libs::rwlock::RwLock;
use crate::net::socket::EPollEventType;
@ -10,7 +10,7 @@ use system_error::SystemError::{self, *};
use super::inet::UNSPECIFIED_LOCAL_ENDPOINT;
pub const DEFAULT_METADATA_BUF_SIZE: usize = 1024;
// pub const DEFAULT_METADATA_BUF_SIZE: usize = 1024;
pub const DEFAULT_RX_BUF_SIZE: usize = 512 * 1024;
pub const DEFAULT_TX_BUF_SIZE: usize = 512 * 1024;

View File

@ -20,9 +20,8 @@ type EP = EPollEventType;
#[derive(Debug)]
pub struct TcpSocket {
inner: RwLock<Option<Inner>>,
shutdown: Shutdown,
shutdown: Shutdown, // TODO set shutdown status
nonblock: AtomicBool,
epitems: EPollItems,
wait_queue: WaitQueue,
self_ref: Weak<Self>,
pollee: AtomicUsize,
@ -34,7 +33,6 @@ impl TcpSocket {
inner: RwLock::new(Some(Inner::Init(Init::new()))),
shutdown: Shutdown::new(),
nonblock: AtomicBool::new(nonblock),
epitems: EPollItems::default(),
wait_queue: WaitQueue::default(),
self_ref: me.clone(),
pollee: AtomicUsize::new((EP::EPOLLIN.bits() | EP::EPOLLOUT.bits()) as usize),
@ -46,7 +44,6 @@ impl TcpSocket {
inner: RwLock::new(Some(Inner::Established(inner))),
shutdown: Shutdown::new(),
nonblock: AtomicBool::new(nonblock),
epitems: EPollItems::default(),
wait_queue: WaitQueue::default(),
self_ref: me.clone(),
pollee: AtomicUsize::new((EP::EPOLLIN.bits() | EP::EPOLLOUT.bits()) as usize),
@ -57,18 +54,6 @@ impl TcpSocket {
self.nonblock.load(core::sync::atomic::Ordering::Relaxed)
}
#[inline]
fn write_state<F>(&self, mut f: F) -> Result<(), SystemError>
where
F: FnMut(Inner) -> Result<Inner, SystemError>,
{
let mut inner_guard = self.inner.write();
let inner = inner_guard.take().expect("Tcp Inner is None");
let update = f(inner)?;
inner_guard.replace(update);
Ok(())
}
pub fn do_bind(&self, local_endpoint: smoltcp::wire::IpEndpoint) -> Result<(), SystemError> {
let mut writer = self.inner.write();
match writer.take().expect("Tcp Inner is None") {
@ -335,163 +320,8 @@ impl Socket for TcpSocket {
impl InetSocket for TcpSocket {
fn on_iface_events(&self) {
if self.update_events() {
let result = self.finish_connect();
let _result = self.finish_connect();
// set error
}
}
}
// #[derive(Debug)]
// // #[cast_to([sync] IndexNode)]
// struct TcpStream {
// inner: Established,
// shutdown: Shutdown,
// nonblock: AtomicBool,
// epitems: EPollItems,
// wait_queue: WaitQueue,
// self_ref: Weak<Self>,
// }
// impl TcpStream {
// pub fn is_nonblock(&self) -> bool {
// self.nonblock.load(core::sync::atomic::Ordering::Relaxed)
// }
// pub fn read(&self, buf: &mut [u8]) -> Result<usize, SystemError> {
// if self.nonblock.load(core::sync::atomic::Ordering::Relaxed) {
// return self.recv_slice(buf);
// } else {
// return self.wait_queue().busy_wait(
// EP::EPOLLIN,
// || self.recv_slice(buf)
// )
// }
// }
// pub fn recv_slice(&self, buf: &mut [u8]) -> Result<usize, SystemError> {
// let received = self.inner.recv_slice(buf);
// poll_ifaces();
// received
// }
// pub fn send_slice(&self, buf: &[u8]) -> Result<usize, SystemError> {
// let sent = self.inner.send_slice(buf);
// poll_ifaces();
// sent
// }
// }
// use crate::net::socket::{Inode, Socket};
// use crate::filesystem::vfs::IndexNode;
// impl IndexNode for TcpStream {
// fn read_at(
// &self,
// _offset: usize,
// _len: usize,
// buf: &mut [u8],
// data: crate::libs::spinlock::SpinLockGuard<crate::filesystem::vfs::FilePrivateData>,
// ) -> Result<usize, SystemError> {
// drop(data);
// self.read(buf)
// }
// fn write_at(
// &self,
// _offset: usize,
// _len: usize,
// buf: &[u8],
// data: crate::libs::spinlock::SpinLockGuard<crate::filesystem::vfs::FilePrivateData>,
// ) -> Result<usize, SystemError> {
// drop(data);
// self.send_slice(buf)
// }
// fn fs(&self) -> alloc::sync::Arc<dyn crate::filesystem::vfs::FileSystem> {
// todo!("TcpSocket::fs")
// }
// fn as_any_ref(&self) -> &dyn core::any::Any {
// self
// }
// fn list(&self) -> Result<alloc::vec::Vec<alloc::string::String>, SystemError> {
// todo!("TcpSocket::list")
// }
// }
// impl Socket for TcpStream {
// fn wait_queue(&self) -> WaitQueue {
// self.wait_queue.clone()
// }
// fn poll(&self) -> usize {
// // self.inner.with(|socket| {
// // let mut mask = EPollEventType::empty();
// // let shutdown = self.shutdown.get();
// // let state = socket.state();
// // use smoltcp::socket::tcp::State::*;
// // type EP = crate::net::event_poll::EPollEventType;
// // if shutdown.is_both_shutdown() || state == Closed {
// // mask |= EP::EPOLLHUP;
// // }
// // if shutdown.is_recv_shutdown() {
// // mask |= EP::EPOLLIN | EP::EPOLLRDNORM | EP::EPOLLRDHUP;
// // }
// // if state != SynSent && state != SynReceived {
// // if socket.can_recv() {
// // mask |= EP::EPOLLIN | EP::EPOLLRDNORM;
// // }
// // if !shutdown.is_send_shutdown() {
// // // __sk_stream_is_writeable这是一个内联函数用于判断一个TCP套接字是否可写。
// // //
// // // 以下是函数的逐行解释:
// // // static inline bool __sk_stream_is_writeable(const struct sock *sk, int wake)
// // // - 这行定义了函数__sk_stream_is_writeable它是一个内联函数static inline
// // // 这意味着在调用点直接展开代码,而不是调用函数体。函数接收两个参数:
// // // 一个指向struct sock对象的指针sk代表套接字和一个整型变量wake。
// // //
// // // return sk_stream_wspace(sk) >= sk_stream_min_wspace(sk) &&
// // // - 这行代码调用了sk_stream_wspace函数获取套接字sk的可写空间write space大小。
// // // 随后与sk_stream_min_wspace调用结果进行比较该函数返回套接字为了保持稳定写入速度所需的
// // // 最小可写空间。如果当前可写空间大于或等于最小可写空间,则表达式为真。
// // // __sk_stream_memory_free(sk, wake);
// // // - 这行代码调用了__sk_stream_memory_free函数它可能用于检查套接字的内存缓冲区是否
// // // 有足够的空间可供写入数据。参数wake可能用于通知网络协议栈有数据需要发送如果设置了相应的标志。
// // // 综上所述__sk_stream_is_writeable函数的目的是判断一个TCP套接字是否可以安全地进行写操作
// // // 它基于套接字的当前可写空间和所需的最小空间以及内存缓冲区的可用性。只有当这两个条件都满足时,
// // // 函数才会返回true表示套接字是可写的。
// // if socket.can_send() {
// // mask |= EP::EPOLLOUT | EP::EPOLLWRNORM | EP::EPOLLWRBAND;
// // } else {
// // todo!("TcpStream::poll: buffer space not enough");
// // }
// // } else {
// // mask |= EP::EPOLLOUT | EP::EPOLLWRNORM;
// // }
// // // TODO tcp urg data => EPOLLPRI
// // } else if state == SynSent /* inet_test_bit */ {
// // log::warn!("Active TCP fastopen socket with defer_connect");
// // mask |= EP::EPOLLOUT | EP::EPOLLWRNORM;
// // }
// // // TODO socket error
// // return Ok(mask);
// // })
// self.pollee.load(core::sync::atomic::Ordering::Relaxed)
// }
// fn send_buffer_size(&self) -> usize {
// self.inner.with(|socket| socket.send_capacity())
// }
// fn recv_buffer_size(&self) -> usize {
// self.inner.with(|socket| socket.recv_capacity())
// }
// }

View File

@ -49,7 +49,7 @@ impl IndexNode for Inode {
fn poll(
&self,
private_data: &crate::filesystem::vfs::FilePrivateData,
_: &crate::filesystem::vfs::FilePrivateData,
) -> Result<usize, SystemError> {
Ok(self.inner.poll())
}
@ -180,11 +180,11 @@ impl Inode {
self.epoll_items.clone()
}
pub fn set_nonblock(&self, nonblock: bool) {
pub fn set_nonblock(&self, _nonblock: bool) {
log::warn!("nonblock is not support yet");
}
pub fn set_close_on_exec(&self, close_on_exec: bool) {
pub fn set_close_on_exec(&self, _close_on_exec: bool) {
log::warn!("close_on_exec is not support yet");
}

View File

@ -11,7 +11,7 @@ mod utils;
use crate::libs::wait_queue::WaitQueue;
pub use base::Socket;
use buffer::Buffer;
pub use common::{
shutdown::*,
// poll_unit::{EPollItems, WaitQueue},

View File

@ -118,6 +118,7 @@ impl SeqpacketSocket {
self.is_nonblocking.load(Ordering::Relaxed)
}
#[allow(dead_code)]
fn set_nonblocking(&self, nonblocking: bool) {
self.is_nonblocking.store(nonblocking, Ordering::Relaxed);
}

View File

@ -21,7 +21,7 @@ pub fn create_socket(
todo!("unsupport address family");
}
};
// inode.set_nonblock(is_nonblock);
// inode.set_close_on_exec(is_close_on_exec);
inode.set_nonblock(is_nonblock);
inode.set_close_on_exec(is_close_on_exec);
return Ok(inode);
}

View File

@ -1,27 +1,14 @@
use core::{cmp::min, ffi::CStr};
use acpi::address;
use alloc::{boxed::Box, sync::Arc};
use alloc::sync::Arc;
use log::debug;
use num_traits::{FromPrimitive, ToPrimitive};
use smoltcp::wire;
use system_error::SystemError::{self, *};
use crate::{
filesystem::vfs::{
file::{File, FileMode},
syscall::{IoVec, IoVecs},
FileType,
},
libs::spinlock::SpinLockGuard,
mm::{verify_area, VirtAddr},
// net::socket::{netlink::af_netlink::NetlinkSock, AddressFamily},
filesystem::vfs::file::{File, FileMode},
process::ProcessManager,
syscall::Syscall,
};
use super::socket::{self, Endpoint, Socket};
use super::socket::{unix::Unix, AddressFamily as AF};
use super::socket::{self, Endpoint, unix::Unix, AddressFamily as AF};
pub use super::syscall_util::*;
@ -94,31 +81,10 @@ impl Syscall {
// check address family, only support AF_UNIX
if address_family != AF::Unix {
log::warn!("only support AF_UNIX, {:?} with protocol {:?} is not supported", address_family, protocol);
return Err(SystemError::EAFNOSUPPORT);
}
// 创建一对socket
// let inode0 = socket::create_socket(
// address_family,
// stype,
// protocol as u32,
// socket_type.is_nonblock(),
// socket_type.is_cloexec(),
// )?;
// let inode1 = socket::create_socket(
// address_family,
// stype,
// protocol as u32,
// socket_type.is_nonblock(),
// socket_type.is_cloexec(),
// )?;
// // 进行pair
// unsafe {
// inode0.connect(socket::Endpoint::Inode(inode1.clone()))?;
// inode1.connect(socket::Endpoint::Inode(inode0.clone()))?;
// }
// 创建一对新的unix socket pair
let (inode0, inode1) = Unix::new_pairs(stype)?;

View File

@ -33,20 +33,17 @@ impl SysArgSocketType {
use alloc::sync::Arc;
use core::ffi::CStr;
use unix::INODE_MAP;
use crate::{
filesystem::vfs::{
file::FileMode, FileType, IndexNode, MAX_PATHLEN, ROOT_INODE, VFS_MAX_FOLLOW_SYMLINK_TIMES,
FileType, IndexNode, ROOT_INODE, VFS_MAX_FOLLOW_SYMLINK_TIMES,
},
libs::casting::DowncastArc,
mm::{verify_area, VirtAddr},
net::socket::{self, *},
process::ProcessManager,
syscall::Syscall,
net::socket::*,
process::ProcessManager
};
use smoltcp;
use system_error::SystemError::{self, *};
use system_error::SystemError;
// 参考资料: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html#tag_13_32
#[repr(C)]