From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 6949E60D82 for ; Mon, 19 Oct 2020 16:46:36 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 608302DCDE for ; Mon, 19 Oct 2020 16:46:06 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id D4A122DCC0 for ; Mon, 19 Oct 2020 16:46:02 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 960CC45E12 for ; Mon, 19 Oct 2020 16:46:02 +0200 (CEST) From: Stefan Reiter To: pbs-devel@lists.proxmox.com Date: Mon, 19 Oct 2020 16:45:22 +0200 Message-Id: <20201019144523.24840-2-s.reiter@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201019144523.24840-1-s.reiter@proxmox.com> References: <20201019144523.24840-1-s.reiter@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.034 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup 2/3] datastore: cleanup open and load config only once X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Oct 2020 14:46:36 -0000 Force consumers to use the lookup_datastore method instead of potentially opening a datastore twice, and pass the config we have already loaded into open_with_path, removing the need for open(1). Signed-off-by: Stefan Reiter --- src/backup/datastore.rs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/backup/datastore.rs b/src/backup/datastore.rs index 46039576..a856e2f4 100644 --- a/src/backup/datastore.rs +++ b/src/backup/datastore.rs @@ -46,17 +46,18 @@ impl DataStore { let (config, _digest) = datastore::config()?; let config: datastore::DataStoreConfig = config.lookup("datastore", name)?; + let path = PathBuf::from(&config.path); let mut map = DATASTORE_MAP.lock().unwrap(); if let Some(datastore) = map.get(name) { // Compare Config - if changed, create new Datastore object! - if datastore.chunk_store.base == PathBuf::from(&config.path) { + if datastore.chunk_store.base == path { return Ok(datastore.clone()); } } - let datastore = DataStore::open(name)?; + let datastore = DataStore::open_with_path(name, &path, config)?; let datastore = Arc::new(datastore); map.insert(name.to_string(), datastore.clone()); @@ -64,18 +65,7 @@ impl DataStore { Ok(datastore) } - pub fn open(store_name: &str) -> Result { - - let (config, _digest) = datastore::config()?; - let (_, store_config) = config.sections.get(store_name) - .ok_or(format_err!("no such datastore '{}'", store_name))?; - - let path = store_config["path"].as_str().unwrap(); - - Self::open_with_path(store_name, Path::new(path)) - } - - pub fn open_with_path(store_name: &str, path: &Path) -> Result { + fn open_with_path(store_name: &str, path: &Path, config: DataStoreConfig) -> Result { let chunk_store = ChunkStore::open(store_name, path)?; let gc_status = GarbageCollectionStatus::default(); -- 2.20.1