Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add read_only #161

Merged
merged 2 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
run: |
mkdir -p /data/action/_work/sealfs/sealfs/target
if [ -d /data/backup/debug ]; then
mv /data/backup/debug w/data/action/_work/sealfs/sealfs/target
mv /data/backup/debug /data/action/_work/sealfs/sealfs/target
fi

- name: Build
Expand Down
2 changes: 1 addition & 1 deletion docker/client/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM debian:bullseye-20221205

RUN apt update && apt upgrade -y && apt-mark unhold libcap2 && \
apt install -y libfuse3-3 libfuse2 libibverbs1 && \
apt install -y fuse3 libfuse3-3 libfuse2 libibverbs1 && \
apt clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

Expand Down
65 changes: 49 additions & 16 deletions src/client/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use fuser::{BackgroundSession, MountOption};
use log::{error, info};

use crate::{
common::{errors::CONNECTION_ERROR, sender::REQUEST_TIMEOUT},
common::{
errors::CONNECTION_ERROR, sender::REQUEST_TIMEOUT, serialization::MountVolumeSendMetaData,
},
rpc::{
client::{RpcClient, UnixStreamCreator},
server::Handler,
Expand All @@ -28,7 +30,7 @@ const LIST_MOUNTPOINTS: u32 = 4;

pub struct SealfsFused {
pub client: Arc<Client>,
pub mount_points: DashMap<String, (String, BackgroundSession)>,
pub mount_points: DashMap<String, (String, bool, BackgroundSession)>,
pub index_file: String,
}

Expand All @@ -47,8 +49,18 @@ impl SealfsFused {
}
}

pub async fn mount(&self, mountpoint: String, volume_name: String) -> Result<(), i32> {
let mut options = vec![MountOption::RW, MountOption::FSName("seal".to_string())];
pub async fn mount(
&self,
mountpoint: String,
volume_name: String,
read_only: bool,
) -> Result<(), i32> {
let mount_mode = if read_only {
MountOption::RO
} else {
MountOption::RW
};
let mut options = vec![mount_mode, MountOption::FSName("seal".to_string())];
options.push(MountOption::AutoUnmount);
options.push(MountOption::AllowRoot);
let result = self.client.init_volume(&volume_name).await;
Expand All @@ -62,7 +74,8 @@ impl SealfsFused {
) {
Ok(session) => {
info!("mount success");
self.mount_points.insert(mountpoint, (volume_name, session));
self.mount_points
.insert(mountpoint, (volume_name, read_only, session));
Ok(())
}
Err(e) => {
Expand Down Expand Up @@ -101,7 +114,7 @@ impl SealfsFused {
std::fs::remove_file(&self.index_file).unwrap_or(());
let mut file = std::fs::File::create(&self.index_file).unwrap();
for k in self.mount_points.iter() {
let line = format!("{}\n{}\n\n", k.key(), k.value().0);
let line = format!("{}\n{}\n{}\n\n", k.key(), k.value().0, k.value().1);
file.write_all(line.as_bytes()).unwrap();
}
}
Expand All @@ -127,11 +140,12 @@ impl SealfsFused {
}
}
let lines: Vec<&str> = content.split('\n').collect();
for i in 0..lines.len() / 3 {
let mountpoint = lines[i * 3].to_owned();
let volume_name = lines[i * 3 + 1].to_owned();
for i in 0..lines.len() / 4 {
let mountpoint = lines[i * 4].to_owned();
let volume_name = lines[i * 4 + 1].to_owned();
let read_only = lines[i * 4 + 2].parse::<bool>().unwrap();
info!("mounting volume {} to {}", volume_name, mountpoint);
match self.mount(mountpoint, volume_name.clone()).await {
match self.mount(mountpoint, volume_name.clone(), read_only).await {
Ok(_) => {
info!("mount success");
}
Expand Down Expand Up @@ -161,9 +175,16 @@ impl Handler for SealfsFused {
) -> anyhow::Result<(i32, u32, usize, usize, Vec<u8>, Vec<u8>)> {
match operation_type {
MOUNT => {
let mountpoint = String::from_utf8(path).unwrap();
let volume_name = String::from_utf8(metadata).unwrap();
match self.mount(mountpoint, volume_name).await {
let send_meta_data: MountVolumeSendMetaData =
bincode::deserialize(&metadata).unwrap();
match self
.mount(
send_meta_data.mount_point,
send_meta_data.volume_name,
send_meta_data.read_only,
)
.await
{
Ok(_) => {
self.sync_index_file();
Ok((0, 0, 0, 0, vec![], vec![]))
Expand Down Expand Up @@ -230,21 +251,33 @@ impl LocalCli {
})
}

pub async fn mount(&self, volume_name: &str, mount_point: &str) -> Result<(), i32> {
pub async fn mount(
&self,
volume_name: &str,
mount_point: &str,
read_only: bool,
) -> Result<(), i32> {
let mut status = 0i32;
let mut rsp_flags = 0u32;

let mut recv_meta_data_length = 0usize;
let mut recv_data_length = 0usize;

let send_meta_data = bincode::serialize(&MountVolumeSendMetaData {
volume_name: volume_name.to_string(),
mount_point: mount_point.to_string(),
read_only,
})
.unwrap();

let result = self
.client
.call_remote(
&self.path,
MOUNT,
0,
mount_point,
volume_name.as_bytes(),
"",
&send_meta_data,
&[],
&mut status,
&mut rsp_flags,
Expand Down
8 changes: 6 additions & 2 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ enum Commands {
#[arg(required = true, name = "volume-name")]
volume_name: Option<String>,

#[arg(name = "socket-path")]
#[arg(long = "socket-path", name = "socket-path")]
socket_path: Option<String>,

#[arg(long = "read-only", name = "read-only")]
read_only: bool,
},
Umount {
/// Unmount FUSE at given path
Expand Down Expand Up @@ -507,6 +510,7 @@ pub async fn run_command() -> Result<(), Box<dyn std::error::Error>> {
mount_point,
volume_name,
socket_path,
read_only,
} => {
let socket_path = match socket_path {
Some(path) => path,
Expand All @@ -519,7 +523,7 @@ pub async fn run_command() -> Result<(), Box<dyn std::error::Error>> {
}

let result = local_client
.mount(&volume_name.unwrap(), &mount_point.unwrap())
.mount(&volume_name.unwrap(), &mount_point.unwrap(), read_only)
.await;
match result {
Ok(_) => info!("mount success"),
Expand Down
7 changes: 7 additions & 0 deletions src/common/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,13 @@ pub struct CreateVolumeSendMetaData {
pub size: u64,
}

#[derive(Serialize, Deserialize, PartialEq)]
pub struct MountVolumeSendMetaData {
pub volume_name: String,
pub mount_point: String,
pub read_only: bool,
}

#[derive(Serialize, Deserialize, PartialEq, Clone)]
pub struct Volume {
pub name: String,
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub const MAX_DATA_LENGTH: usize = 65536 * 128;
pub const MAX_METADATA_LENGTH: usize = 4096;
pub const MAX_COPY_LENGTH: usize = 1024 * 8;

pub const CONNECTION_RETRY_TIMES: i32 = 20;
pub const CONNECTION_RETRY_TIMES: i32 = 100;
pub const SEND_RETRY_TIMES: i32 = 3;

// request
Expand Down