From d3714de65b8ebc62eaa4af3df03652e5573110d9 Mon Sep 17 00:00:00 2001 From: weisd Date: Tue, 25 Jun 2024 17:33:46 +0800 Subject: [PATCH] run init --- ecstore/src/error.rs | 2 -- ecstore/src/lib.rs | 1 - ecstore/src/store.rs | 10 ++++++++-- rustfs/src/config/mod.rs | 5 ++--- rustfs/src/main.rs | 6 ++++-- ecstore/src/s3.rs => rustfs/src/storage/ecfs.rs | 17 +++++++++++++++-- rustfs/src/storage/mod.rs | 1 + scripts/run.sh | 9 ++++----- 8 files changed, 34 insertions(+), 17 deletions(-) rename ecstore/src/s3.rs => rustfs/src/storage/ecfs.rs (96%) diff --git a/ecstore/src/error.rs b/ecstore/src/error.rs index 698a164c..055efd5c 100644 --- a/ecstore/src/error.rs +++ b/ecstore/src/error.rs @@ -12,8 +12,6 @@ pub struct Error { source: StdError, } -pub type Result = std::result::Result; - impl Error { #[must_use] #[track_caller] diff --git a/ecstore/src/lib.rs b/ecstore/src/lib.rs index 2321c314..80649912 100644 --- a/ecstore/src/lib.rs +++ b/ecstore/src/lib.rs @@ -3,7 +3,6 @@ mod ellipses; mod endpoint; mod erasure; pub mod error; -pub mod s3; pub mod store; mod stream; mod utils; diff --git a/ecstore/src/store.rs b/ecstore/src/store.rs index 9bc3ee2b..230a6e84 100644 --- a/ecstore/src/store.rs +++ b/ecstore/src/store.rs @@ -1,7 +1,9 @@ use uuid::Uuid; +use crate::{disks_layout::DisksLayout, endpoint::create_server_endpoints}; + use super::endpoint::Endpoint; -use super::error::Result; +use anyhow::Result; use std::fmt::Debug; @@ -14,7 +16,11 @@ pub struct ECStore { } impl ECStore { - pub fn new(endpoints: Vec) -> Result { + pub fn new(endpoints: Vec, address: String) -> Result { + let layouts = DisksLayout::new(endpoints)?; + + let (pools, _) = create_server_endpoints(address, &layouts.pools, layouts.legacy)?; + Ok(ECStore { id: Uuid::nil(), pools: Vec::new(), diff --git a/rustfs/src/config/mod.rs b/rustfs/src/config/mod.rs index 043de8b6..a9c1f40c 100644 --- a/rustfs/src/config/mod.rs +++ b/rustfs/src/config/mod.rs @@ -1,5 +1,4 @@ use clap::Parser; -use std::path::PathBuf; /// Default port that a rustfs server listens on. /// @@ -10,10 +9,10 @@ pub const DEFAULT_PORT: u16 = 9000; pub struct Opt { /// DIR points to a directory on a filesystem. #[arg(required = true)] - pub volumes: Vec, + pub volumes: Vec, /// bind to a specific ADDRESS:PORT, ADDRESS can be an IP or hostname - #[arg(long, default_value_t = format!(":{}", DEFAULT_PORT))] + #[arg(long, default_value_t = format!("0.0.0.0:{}", DEFAULT_PORT))] pub address: String, /// Access key used for authentication. diff --git a/rustfs/src/main.rs b/rustfs/src/main.rs index b0f45231..28ad2488 100644 --- a/rustfs/src/main.rs +++ b/rustfs/src/main.rs @@ -3,6 +3,7 @@ mod storage; use anyhow::Result; use clap::Parser; +use ecstore::store::ECStore; use hyper_util::{ rt::{TokioExecutor, TokioIo}, server::conn::auto::Builder as ConnBuilder, @@ -10,7 +11,7 @@ use hyper_util::{ use s3s::{auth::SimpleAuth, service::S3ServiceBuilder}; use std::io::IsTerminal; use tokio::net::TcpListener; -use tracing::info; +use tracing::{debug, info}; fn setup_tracing() { use tracing_subscriber::EnvFilter; @@ -35,9 +36,10 @@ fn main() -> Result<()> { #[tokio::main] async fn run(opt: config::Opt) -> Result<()> { + debug!("opt: {:?}", &opt); // Setup S3 service let service = { - let mut b = S3ServiceBuilder::new(storage::SimpleFS {}); + let mut b = S3ServiceBuilder::new(storage::ecfs::EC::new(opt.volumes)?); // Enable authentication if let (Some(ak), Some(sk)) = (opt.access_key, opt.secret_key) { diff --git a/ecstore/src/s3.rs b/rustfs/src/storage/ecfs.rs similarity index 96% rename from ecstore/src/s3.rs rename to rustfs/src/storage/ecfs.rs index 464ccb62..ddd16cff 100644 --- a/ecstore/src/s3.rs +++ b/rustfs/src/storage/ecfs.rs @@ -4,10 +4,23 @@ use s3s::S3Result; use s3s::S3; use s3s::{S3Request, S3Response}; -use crate::store::ECStore; +use anyhow::Result; +use ecstore::store::ECStore; + +#[derive(Debug)] +pub struct EC { + store: ECStore, +} + +impl EC { + pub fn new(endpoints: Vec) -> Result { + let store = ECStore::new(endpoints)?; + Ok(EC { store }) + } +} #[async_trait::async_trait] -impl S3 for ECStore { +impl S3 for EC { #[tracing::instrument] async fn create_bucket( &self, diff --git a/rustfs/src/storage/mod.rs b/rustfs/src/storage/mod.rs index 30a6d416..5b13c1fe 100644 --- a/rustfs/src/storage/mod.rs +++ b/rustfs/src/storage/mod.rs @@ -1,3 +1,4 @@ +pub mod ecfs; mod simple_fs; pub use simple_fs::SimpleFS; diff --git a/scripts/run.sh b/scripts/run.sh index 37864993..51815961 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -10,9 +10,8 @@ if [ -z "$RUST_LOG" ]; then fi cargo run \ - -- --access-key AKEXAMPLERUSTFS \ - -- --secret-key SKEXAMPLERUSTFS \ - -- --host localhost \ - -- --port 9010 \ - -- --domain-name localhost:9010 \ + -- --access-key AKEXAMPLERUSTFS \ + --secret-key SKEXAMPLERUSTFS \ + --address 0.0.0.0:9010 \ + --domain-name localhost:9010 \ "$DATA_DIR"