Skip to content

Commit

Permalink
Merge pull request syswonder#21 from ken4647/dev
Browse files Browse the repository at this point in the history
Add module `ax9p` for 9pfs.
  • Loading branch information
coolyjg authored Nov 13, 2023
2 parents 94309c9 + c3ce306 commit 4a74aa0
Show file tree
Hide file tree
Showing 40 changed files with 2,325 additions and 53 deletions.
31 changes: 30 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@
# - `BLK`: Enable storage devices (virtio-blk)
# - `NET`: Enable network devices (virtio-net)
# - `GRAPHIC`: Enable display devices and graphic output (virtio-gpu)
# - `V9P`: Enable virtio-9p devices
# - `BUS`: Device bus type: mmio, pci
# - `DISK_IMG`: Path to the virtual disk image
# - `ACCEL`: Enable hardware acceleration (KVM on linux)
# - `QEMU_LOG`: Enable QEMU logging (log file is "qemu.log")
# - `NET_DUMP`: Enable network packet dump (log file is "netdump.pcap")
# - `NET_DEV`: QEMU netdev backend types: user, tap
# * 9P options:
# - `V9P_PATH`: Host path for backend of virtio-9p
# - `NET_9P_ADDR`: Server address and port for 9P netdev
# - `ANAME_9P`: Path for root of 9pfs(parameter of TATTACH for root)
# - `PROTOCOL_9P`: Default protocol version selected for 9P
# * Network options:
# - `IP`: ArceOS IPv4 address (default is 10.0.2.15 for QEMU user netdev)
# - `GW`: Gateway IPv4 address (default is 10.0.2.2 for QEMU user netdev)
Expand All @@ -44,12 +50,18 @@ APP_FEATURES ?=
BLK ?= n
NET ?= n
GRAPHIC ?= n
V9P ?= n
BUS ?= mmio


DISK_IMG ?= disk.img
QEMU_LOG ?= n
NET_DUMP ?= n
NET_DEV ?= user
V9P_PATH ?= ./
NET_9P_ADDR ?= 127.0.0.1:564
ANAME_9P ?= ./
PROTOCOL_9P ?= 9P2000.L

# Network options
IP ?= 10.0.2.15
Expand Down Expand Up @@ -121,6 +133,9 @@ export AX_LOG=$(LOG)
export AX_TARGET=$(TARGET)
export AX_IP=$(IP)
export AX_GW=$(GW)
export AX_9P_ADDR = $(NET_9P_ADDR)
export AX_ANAME_9P = $(ANAME_9P)
export AX_PROTOCOL_9P = $(PROTOCOL_9P)

# Binutils
CROSS_COMPILE ?= $(ARCH)-linux-musl-
Expand Down
6 changes: 6 additions & 0 deletions api/axfeat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ sched_cfs = ["axtask/sched_cfs", "irq"]
# File system
fs = ["alloc", "paging", "axdriver/virtio-blk", "dep:axfs", "axruntime/fs"] # TODO: try to remove "paging"
myfs = ["axfs?/myfs"]
9pfs = []

# Networking
net = ["alloc", "paging", "axdriver/virtio-net", "dep:axnet", "axruntime/net"]
Expand All @@ -51,6 +52,10 @@ display = ["alloc", "paging", "axdriver/virtio-gpu", "dep:axdisplay", "axruntime
# Signal
signal = ["axruntime/signal"]

# 9P
virtio-9p = ["9pfs", "axdriver/virtio-9p", "ax9p/virtio-9p", "axruntime/virtio-9p"]
net-9p = ["9pfs", "net", "ax9p/net-9p", "axruntime/net-9p"]

# Device drivers
bus-mmio = ["axdriver?/bus-mmio"]
bus-pci = ["axdriver?/bus-pci"]
Expand All @@ -73,6 +78,7 @@ axlog = { path = "../../modules/axlog" }
axalloc = { path = "../../modules/axalloc", optional = true }
axdriver = { path = "../../modules/axdriver", optional = true }
axfs = { path = "../../modules/axfs", optional = true }
ax9p = { path = "../../modules/ax9p", optional = true }
axnet = { path = "../../modules/axnet", optional = true }
axdisplay = { path = "../../modules/axdisplay", optional = true }
axsync = { path = "../../modules/axsync", optional = true }
Expand Down
4 changes: 2 additions & 2 deletions apps/c/filetest/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ int main() {
fd= open("filetest/a.txt", O_RDWR);
fp = fdopen(fd, "r");
fgets(s, 50, fp);
if(strcmp("1 2 3 4", s)) {
if(strcmp("1 2 3 4\n", s)) {
perror("fdopen and freopen failed");
return -1;
}
fgets(s, 50, fp);
if(strcmp("5 6 7 8", s)) {
if(strcmp("5 6 7 8\n", s)) {
perror("fdopen and freopen failed");
return -1;
}
Expand Down
13 changes: 12 additions & 1 deletion apps/c/redis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@
```
make A=apps/c/redis/ LOG=error NET=y BLK=y ARCH=x86_64 SMP=4 ARGS="./redis-server,--bind,0.0.0.0,--port,5555,--save,\"\",--appendonly,no,--protected-mode,no" run
```
- version 3 for aarch64(using 9pfs)
```
make A=apps/c/redis/ LOG=error NET=y V9P=y BLK=y V9P_PATH=apps/c/redis ARCH=aarch64 SMP=4 ARGS="./redis-server,/v9fs/redis.conf" run
```
- version 3 for x86_64(using 9pfs)
```
make A=apps/c/redis/ LOG=error NET=y V9P=y BLK=y V9P_PATH=apps/c/redis ARCH=x86_64 SMP=4 ARGS="./redis-server,/v9fs/redis.conf" run
```
# How to test?
- Use `redis-cli -p 5555` to connect to redis-server, and enjoy ArceOS-Redis world!
Expand Down Expand Up @@ -342,3 +352,4 @@ LRANGE_500 (first 450 elements): 16485.33 requests per second
LRANGE_600 (first 600 elements): 13159.63 requests per second
MSET (10 keys): 72780.20 requests per second
```
1 change: 1 addition & 0 deletions apps/c/redis/features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ net
pipe
epoll
poll
virtio-9p
6 changes: 6 additions & 0 deletions apps/c/redis/redis.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
bind 0.0.0.0
port 5555
protected-mode no
save ""
appendonly no
ignore-warnings ARM64-COW-BUG
2 changes: 1 addition & 1 deletion apps/fs/shell/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ default = []
axfs_vfs = { path = "../../../crates/axfs_vfs", optional = true }
axfs_ramfs = { path = "../../../crates/axfs_ramfs", optional = true }
crate_interface = { path = "../../../crates/crate_interface", optional = true }
axstd = { path = "../../../ulib/axstd", features = ["alloc", "fs"], optional = true }
axstd = { path = "../../../ulib/axstd", features = ["alloc", "fs", "virtio-9p"], optional = true }
18 changes: 18 additions & 0 deletions crates/driver_9p/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "driver_9p"
version = "0.1.0"
edition = "2021"
authors = ["Zheng Wu <[email protected]>"]
description = "Common traits and types for block storage drivers"
license = "GPL-3.0-or-later OR Apache-2.0"
homepage = "https://github.com/rcore-os/arceos"
repository = "https://github.com/rcore-os/arceos/tree/main/crates/driver_common"
documentation = "https://rcore-os.github.io/arceos/driver_common/index.html"

[features]
default = []

[dependencies]
log = "0.4"
spin = "0.9"
driver_common = { path = "../driver_common" }
26 changes: 26 additions & 0 deletions crates/driver_9p/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* Copyright (c) [2023] [Syswonder Community]
* [Rukos] is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/

//! Common traits and types for 9P device drivers (i.e. 9P2000.L, 9P2000.U).
#![no_std]
#![feature(doc_auto_cfg)]
#![feature(const_trait_impl)]

#[doc(no_inline)]
pub use driver_common::BaseDriverOps;

/// Operations that require a 9p driver to implement.
pub trait _9pDriverOps: BaseDriverOps {
/// initialize self(e.g. setup TCP connection)
fn init(&self) -> Result<(), u8>;

/// send bytes of inputs as request and receive get answer in outputs
fn send_with_recv(&mut self, inputs: &[u8], outputs: &mut [u8]) -> Result<u32, u8>; // Ok(length)/Err()
}
2 changes: 2 additions & 0 deletions crates/driver_common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub enum DeviceType {
Net,
/// Graphic display device (e.g., GPU)
Display,
/// Plan-9 device (e.g. 9pfs)
_9P,
}

/// The error type for device operation failures.
Expand Down
2 changes: 1 addition & 1 deletion crates/driver_pci/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ repository = "https://github.com/rcore-os/arceos/tree/main/crates/driver_pci"
documentation = "https://rcore-os.github.io/arceos/driver_pci/index.html"

[dependencies]
virtio-drivers = { git = "https://github.com/rcore-os/virtio-drivers.git", rev = "409ee72" }
virtio-drivers = { git = "https://github.com/syswonder/virtio-drivers.git", rev = "256ec4c"}
6 changes: 5 additions & 1 deletion crates/driver_virtio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ documentation = "https://rcore-os.github.io/arceos/driver_virtio/index.html"
block = ["driver_block"]
net = ["driver_net"]
gpu = ["driver_display"]
v9p = ["driver_9p"]

[dependencies]
log = "0.4"
spin = "0.9"
driver_common = { path = "../driver_common" }
driver_block = { path = "../driver_block", optional = true }
driver_net = { path = "../driver_net", optional = true }
driver_display = { path = "../driver_display", optional = true}
virtio-drivers = { git = "https://github.com/rcore-os/virtio-drivers.git", rev = "409ee72" }
driver_9p = { path = "../driver_9p", optional = true}
virtio-drivers = { git = "https://github.com/syswonder/virtio-drivers.git", rev = "256ec4c" }
5 changes: 5 additions & 0 deletions crates/driver_virtio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ mod blk;
mod gpu;
#[cfg(feature = "net")]
mod net;
#[cfg(feature = "v9p")]
mod v9p;

#[cfg(feature = "block")]
pub use self::blk::VirtIoBlkDev;
#[cfg(feature = "gpu")]
pub use self::gpu::VirtIoGpuDev;
#[cfg(feature = "net")]
pub use self::net::VirtIoNetDev;
#[cfg(feature = "v9p")]
pub use self::v9p::VirtIo9pDev;

pub use virtio_drivers::transport::pci::bus as pci;
pub use virtio_drivers::transport::{mmio::MmioTransport, pci::PciTransport, Transport};
Expand Down Expand Up @@ -84,6 +88,7 @@ const fn as_dev_type(t: VirtIoDevType) -> Option<DeviceType> {
Block => Some(DeviceType::Block),
Network => Some(DeviceType::Net),
GPU => Some(DeviceType::Display),
_9P => Some(DeviceType::_9P),
_ => None,
}
}
Expand Down
52 changes: 52 additions & 0 deletions crates/driver_virtio/src/v9p.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* Copyright (c) [2023] [Syswonder Community]
* [Rukos] is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/

use driver_9p::_9pDriverOps;
use driver_common::{BaseDriverOps, DevResult, DeviceType};
use virtio_drivers::{device::v9p::VirtIO9p as InnerDev, transport::Transport, Hal};

/// The VirtIO 9p device driver.
pub struct VirtIo9pDev<H: Hal, T: Transport> {
inner: InnerDev<H, T>,
}

unsafe impl<H: Hal, T: Transport> Send for VirtIo9pDev<H, T> {}
unsafe impl<H: Hal, T: Transport> Sync for VirtIo9pDev<H, T> {}

impl<H: Hal, T: Transport> VirtIo9pDev<H, T> {
/// Creates a new driver instance and initializes the device, or returns
/// an error if any step fails.
pub fn try_new(transport: T) -> DevResult<Self> {
Ok(Self {
inner: InnerDev::new(transport).unwrap(),
})
}
}

impl<H: Hal, T: Transport> const BaseDriverOps for VirtIo9pDev<H, T> {
fn device_name(&self) -> &str {
"virtio-9p"
}

fn device_type(&self) -> DeviceType {
DeviceType::_9P
}
}

impl<H: Hal, T: Transport> _9pDriverOps for VirtIo9pDev<H, T> {
// initialize self(e.g. setup TCP connection)
fn init(&self) -> Result<(), u8> {
Ok(())
}

// send bytes of inputs as request and receive get answer in outputs
fn send_with_recv(&mut self, inputs: &[u8], outputs: &mut [u8]) -> Result<u32, u8> {
self.inner.request(inputs, outputs)
}
}
Loading

0 comments on commit 4a74aa0

Please sign in to comment.