Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ scripts/airgap/output/

# Runtime data
.data/
.worktrees/

# Internal dev notes
notes/
25 changes: 25 additions & 0 deletions apps/agent/src/features/storage/iscsi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ impl HostBackend for IscsiHostBackend {
Ok(())
}

async fn resize2fs(&self, attached: &AttachedPath) -> Result<(), StorageError> {
run_resize2fs(attached.path()).await
}

async fn read_snapshot(
&self,
snap: &VolumeSnapshotHandle,
Expand Down Expand Up @@ -203,6 +207,27 @@ impl HostBackend for IscsiHostBackend {
}
}

async fn run_resize2fs(path: &Path) -> Result<(), StorageError> {
let _ = tokio::process::Command::new("e2fsck")
.args(["-f", "-y"])
.arg(path)
.output()
.await?;
let out = tokio::process::Command::new("resize2fs")
.arg(path)
.output()
.await?;
if out.status.success() {
Ok(())
} else {
Err(StorageError::InvalidLocator(format!(
"resize2fs {} failed: {}",
path.display(),
String::from_utf8_lossy(&out.stderr)
)))
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
25 changes: 25 additions & 0 deletions apps/agent/src/features/storage/local_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ impl HostBackend for LocalFileHostBackend {
Ok(())
}

async fn resize2fs(&self, attached: &AttachedPath) -> Result<(), StorageError> {
run_resize2fs(attached.path()).await
}

async fn read_snapshot(
&self,
snap: &VolumeSnapshotHandle,
Expand All @@ -58,6 +62,27 @@ impl HostBackend for LocalFileHostBackend {
}
}

async fn run_resize2fs(path: &Path) -> Result<(), StorageError> {
let _ = tokio::process::Command::new("e2fsck")
.args(["-f", "-y"])
.arg(path)
.output()
.await?;
let out = tokio::process::Command::new("resize2fs")
.arg(path)
.output()
.await?;
if out.status.success() {
Ok(())
} else {
Err(StorageError::InvalidLocator(format!(
"resize2fs {} failed: {}",
path.display(),
String::from_utf8_lossy(&out.stderr)
)))
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
1 change: 1 addition & 0 deletions apps/agent/src/features/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pub mod local_file;
pub mod registry;
pub mod routes;
pub mod s3;
pub mod spdk_lvol;
36 changes: 16 additions & 20 deletions apps/agent/src/features/storage/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,30 +123,26 @@ pub async fn populate(

#[derive(Deserialize)]
pub struct Resize2fsReq {
pub backend_kind: BackendKind,
pub attached: AttachedPath,
}

pub async fn resize2fs(Json(req): Json<Resize2fsReq>) -> impl IntoResponse {
let path = req.attached.path();
let _ = tokio::process::Command::new("e2fsck")
.args(["-f", "-y"])
.arg(path)
.output()
.await
.ok();
let resize = tokio::process::Command::new("resize2fs")
.arg(path)
.output()
.await;
match resize {
Ok(o) if o.status.success() => {
(StatusCode::OK, Json(serde_json::json!({}))).into_response()
pub async fn resize2fs(
State(s): State<Arc<StorageState>>,
Json(req): Json<Resize2fsReq>,
) -> impl IntoResponse {
let backend = match s.registry.get(req.backend_kind) {
Some(b) => b,
None => {
return (
StatusCode::BAD_REQUEST,
Json(serde_json::json!({"error": "unsupported backend kind"})),
)
.into_response()
}
Ok(o) => (
StatusCode::INTERNAL_SERVER_ERROR,
Json(serde_json::json!({"stderr": String::from_utf8_lossy(&o.stderr).to_string()})),
)
.into_response(),
};
match backend.resize2fs(&req.attached).await {
Ok(()) => (StatusCode::OK, Json(serde_json::json!({}))).into_response(),
Err(e) => (
StatusCode::INTERNAL_SERVER_ERROR,
Json(serde_json::json!({"error": e.to_string()})),
Expand Down
Loading
Loading