From 5333618d70fcd30c45a7bd79315025975c57542c Mon Sep 17 00:00:00 2001 From: Jiang Liu Date: Sat, 5 Aug 2023 23:44:06 +0800 Subject: [PATCH] agent: make add_storage() take &[Storage] instead of Vec Simplify add_storage() by taking &[Storage] instead of Vec. Signed-off-by: Jiang Liu --- src/agent/src/mount.rs | 15 +++++++-------- src/agent/src/rpc.rs | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/agent/src/mount.rs b/src/agent/src/mount.rs index 84227b1821..fdc314fd8f 100644 --- a/src/agent/src/mount.rs +++ b/src/agent/src/mount.rs @@ -861,17 +861,16 @@ fn parse_mount_flags_and_options(options_vec: Vec<&str>) -> (MsFlags, String) { #[instrument] pub async fn add_storages( logger: Logger, - storages: Vec, + storages: &[Storage], sandbox: &Arc>, cid: Option, ) -> Result> { let mut mount_list = Vec::new(); for storage in storages { - let handler_name = storage.driver.clone(); - let logger = logger.new(o!( - "subsystem" => "storage", - "storage-type" => handler_name.to_owned())); + let handler_name = &storage.driver; + let logger = + logger.new(o!( "subsystem" => "storage", "storage-type" => handler_name.to_string())); { let mut sb = sandbox.lock().await; @@ -916,9 +915,9 @@ pub async fn add_storages( "add_storages failed, storage: {:?}, error: {:?} ", storage, e ); let mut sb = sandbox.lock().await; - sb.unset_sandbox_storage(&storage.mount_point) - .map_err(|e| warn!(logger, "fail to unset sandbox storage {:?}", e)) - .ok(); + if let Err(e) = sb.unset_sandbox_storage(&storage.mount_point) { + warn!(logger, "fail to unset sandbox storage {:?}", e); + } return Err(e); } Ok(m) => m, diff --git a/src/agent/src/rpc.rs b/src/agent/src/rpc.rs index ecbd0592d7..a8e0beb1e1 100644 --- a/src/agent/src/rpc.rs +++ b/src/agent/src/rpc.rs @@ -180,7 +180,7 @@ impl AgentService { // list) to bind mount all of them inside the container. let m = add_storages( sl(), - req.storages, + &req.storages, &self.sandbox, Some(req.container_id.clone()), ) @@ -1217,7 +1217,7 @@ impl agent_ttrpc::AgentService for AgentService { .map_err(|e| ttrpc_error(ttrpc::Code::INTERNAL, e))?; } - match add_storages(sl(), req.storages.to_vec(), &self.sandbox, None).await { + match add_storages(sl(), &req.storages, &self.sandbox, None).await { Ok(m) => { self.sandbox.lock().await.mounts = m; }