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 8FD7D690B4 for ; Thu, 11 Feb 2021 14:11:24 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8DD8A1C368 for ; Thu, 11 Feb 2021 14:11:24 +0100 (CET) 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 634721C330 for ; Thu, 11 Feb 2021 14:11:22 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 2D9BF4623F for ; Thu, 11 Feb 2021 14:11:22 +0100 (CET) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Thu, 11 Feb 2021 14:11:17 +0100 Message-Id: <20210211131120.25849-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.227 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 1/4] proxmox-tape: change lookup_drive_name to extract_drive_name 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: Thu, 11 Feb 2021 13:11:24 -0000 in most uses, we want to remove the drive from the param afterwards where we don't, we already overwrite it with the result of this function this fixes some commands (like 'proxmox-tape read-label --drive foo') that failed with: parameter 'drive': duplicate parameter. Signed-off-by: Dominik Csapak --- src/bin/proxmox-tape.rs | 84 ++++++++++++++------------ src/bin/proxmox_tape/changer.rs | 4 +- src/bin/proxmox_tape/encryption_key.rs | 2 +- 3 files changed, 48 insertions(+), 42 deletions(-) diff --git a/src/bin/proxmox-tape.rs b/src/bin/proxmox-tape.rs index 69db8f3f..5a6ee06f 100644 --- a/src/bin/proxmox-tape.rs +++ b/src/bin/proxmox-tape.rs @@ -57,8 +57,8 @@ use proxmox_backup::{ mod proxmox_tape; use proxmox_tape::*; -pub fn lookup_drive_name( - param: &Value, +pub fn extract_drive_name( + param: &mut Value, config: &SectionConfigData, ) -> Result { @@ -84,6 +84,10 @@ pub fn lookup_drive_name( }) .ok_or_else(|| format_err!("unable to get (default) drive name"))?; + if let Some(map) = param.as_object_mut() { + map.remove("drive"); + } + Ok(drive) } @@ -108,13 +112,13 @@ pub fn lookup_drive_name( }, )] /// Erase media -async fn erase_media(param: Value) -> Result<(), Error> { +async fn erase_media(mut param: Value) -> Result<(), Error> { let output_format = get_output_format(¶m); let (config, _digest) = config::drive::config()?; - let drive = lookup_drive_name(¶m, &config)?; + let drive = extract_drive_name(&mut param, &config)?; let mut client = connect_to_localhost()?; @@ -141,13 +145,13 @@ async fn erase_media(param: Value) -> Result<(), Error> { }, )] /// Rewind tape -async fn rewind(param: Value) -> Result<(), Error> { +async fn rewind(mut param: Value) -> Result<(), Error> { let output_format = get_output_format(¶m); let (config, _digest) = config::drive::config()?; - let drive = lookup_drive_name(¶m, &config)?; + let drive = extract_drive_name(&mut param, &config)?; let mut client = connect_to_localhost()?; @@ -174,13 +178,13 @@ async fn rewind(param: Value) -> Result<(), Error> { }, )] /// Eject/Unload drive media -async fn eject_media(param: Value) -> Result<(), Error> { +async fn eject_media(mut param: Value) -> Result<(), Error> { let output_format = get_output_format(¶m); let (config, _digest) = config::drive::config()?; - let drive = lookup_drive_name(¶m, &config)?; + let drive = extract_drive_name(&mut param, &config)?; let mut client = connect_to_localhost()?; @@ -206,11 +210,11 @@ async fn eject_media(param: Value) -> Result<(), Error> { }, )] /// Load media with specified label -async fn load_media(param: Value) -> Result<(), Error> { +async fn load_media(mut param: Value) -> Result<(), Error> { let (config, _digest) = config::drive::config()?; - let drive = lookup_drive_name(¶m, &config)?; + let drive = extract_drive_name(&mut param, &config)?; let mut client = connect_to_localhost()?; @@ -234,11 +238,11 @@ async fn load_media(param: Value) -> Result<(), Error> { }, )] /// Export media with specified label -async fn export_media(param: Value) -> Result<(), Error> { +async fn export_media(mut param: Value) -> Result<(), Error> { let (config, _digest) = config::drive::config()?; - let drive = lookup_drive_name(¶m, &config)?; + let drive = extract_drive_name(&mut param, &config)?; let mut client = connect_to_localhost()?; @@ -264,11 +268,11 @@ async fn export_media(param: Value) -> Result<(), Error> { }, )] /// Load media from the specified slot -async fn load_media_from_slot(param: Value) -> Result<(), Error> { +async fn load_media_from_slot(mut param: Value) -> Result<(), Error> { let (config, _digest) = config::drive::config()?; - let drive = lookup_drive_name(¶m, &config)?; + let drive = extract_drive_name(&mut param, &config)?; let mut client = connect_to_localhost()?; @@ -295,11 +299,11 @@ async fn load_media_from_slot(param: Value) -> Result<(), Error> { }, )] /// Unload media via changer -async fn unload_media(param: Value) -> Result<(), Error> { +async fn unload_media(mut param: Value) -> Result<(), Error> { let (config, _digest) = config::drive::config()?; - let drive = lookup_drive_name(¶m, &config)?; + let drive = extract_drive_name(&mut param, &config)?; let mut client = connect_to_localhost()?; @@ -331,13 +335,13 @@ async fn unload_media(param: Value) -> Result<(), Error> { }, )] /// Label media -async fn label_media(param: Value) -> Result<(), Error> { +async fn label_media(mut param: Value) -> Result<(), Error> { let output_format = get_output_format(¶m); let (config, _digest) = config::drive::config()?; - let drive = lookup_drive_name(¶m, &config)?; + let drive = extract_drive_name(&mut param, &config)?; let mut client = connect_to_localhost()?; @@ -369,13 +373,13 @@ async fn label_media(param: Value) -> Result<(), Error> { }, )] /// Read media label -async fn read_label(param: Value) -> Result<(), Error> { +async fn read_label(mut param: Value) -> Result<(), Error> { let output_format = get_output_format(¶m); let (config, _digest) = config::drive::config()?; - let drive = lookup_drive_name(¶m, &config)?; + let drive = extract_drive_name(&mut param, &config)?; let client = connect_to_localhost()?; @@ -428,13 +432,13 @@ async fn read_label(param: Value) -> Result<(), Error> { async fn inventory( read_labels: Option, read_all_labels: Option, - param: Value, + mut param: Value, ) -> Result<(), Error> { let output_format = get_output_format(¶m); let (config, _digest) = config::drive::config()?; - let drive = lookup_drive_name(¶m, &config)?; + let drive = extract_drive_name(&mut param, &config)?; let do_read = read_labels.unwrap_or(false) || read_all_labels.unwrap_or(false); @@ -487,13 +491,13 @@ async fn inventory( }, )] /// Label media with barcodes from changer device -async fn barcode_label_media(param: Value) -> Result<(), Error> { +async fn barcode_label_media(mut param: Value) -> Result<(), Error> { let output_format = get_output_format(¶m); let (config, _digest) = config::drive::config()?; - let drive = lookup_drive_name(¶m, &config)?; + let drive = extract_drive_name(&mut param, &config)?; let mut client = connect_to_localhost()?; @@ -516,11 +520,11 @@ async fn barcode_label_media(param: Value) -> Result<(), Error> { }, )] /// Move to end of media (MTEOM, used to debug) -fn move_to_eom(param: Value) -> Result<(), Error> { +fn move_to_eom(mut param: Value) -> Result<(), Error> { let (config, _digest) = config::drive::config()?; - let drive = lookup_drive_name(¶m, &config)?; + let drive = extract_drive_name(&mut param, &config)?; let _lock = lock_tape_device(&config, &drive)?; @@ -545,11 +549,11 @@ fn move_to_eom(param: Value) -> Result<(), Error> { /// /// Note: This reads unless the driver returns an IO Error, so this /// method is expected to fails when we reach EOT. -fn debug_scan(param: Value) -> Result<(), Error> { +fn debug_scan(mut param: Value) -> Result<(), Error> { let (config, _digest) = config::drive::config()?; - let drive = lookup_drive_name(¶m, &config)?; + let drive = extract_drive_name(&mut param, &config)?; let _lock = lock_tape_device(&config, &drive)?; @@ -610,13 +614,13 @@ fn debug_scan(param: Value) -> Result<(), Error> { }, )] /// Read Cartridge Memory (Medium auxiliary memory attributes) -async fn cartridge_memory(param: Value) -> Result<(), Error> { +async fn cartridge_memory(mut param: Value) -> Result<(), Error> { let output_format = get_output_format(¶m); let (config, _digest) = config::drive::config()?; - let drive = lookup_drive_name(¶m, &config)?; + let drive = extract_drive_name(&mut param, &config)?; let client = connect_to_localhost()?; @@ -651,13 +655,13 @@ async fn cartridge_memory(param: Value) -> Result<(), Error> { }, )] /// Read Volume Statistics (SCSI log page 17h) -async fn volume_statistics(param: Value) -> Result<(), Error> { +async fn volume_statistics(mut param: Value) -> Result<(), Error> { let output_format = get_output_format(¶m); let (config, _digest) = config::drive::config()?; - let drive = lookup_drive_name(¶m, &config)?; + let drive = extract_drive_name(&mut param, &config)?; let client = connect_to_localhost()?; @@ -689,13 +693,13 @@ async fn volume_statistics(param: Value) -> Result<(), Error> { }, )] /// Get drive/media status -async fn status(param: Value) -> Result<(), Error> { +async fn status(mut param: Value) -> Result<(), Error> { let output_format = get_output_format(¶m); let (config, _digest) = config::drive::config()?; - let drive = lookup_drive_name(¶m, &config)?; + let drive = extract_drive_name(&mut param, &config)?; let client = connect_to_localhost()?; @@ -748,13 +752,13 @@ async fn status(param: Value) -> Result<(), Error> { }, )] /// Clean drive -async fn clean_drive(param: Value) -> Result<(), Error> { +async fn clean_drive(mut param: Value) -> Result<(), Error> { let output_format = get_output_format(¶m); let (config, _digest) = config::drive::config()?; - let drive = lookup_drive_name(¶m, &config)?; + let drive = extract_drive_name(&mut param, &config)?; let mut client = connect_to_localhost()?; @@ -803,7 +807,7 @@ async fn backup(mut param: Value) -> Result<(), Error> { let (config, _digest) = config::drive::config()?; - param["drive"] = lookup_drive_name(¶m, &config)?.into(); + param["drive"] = extract_drive_name(&mut param, &config)?.into(); let mut client = connect_to_localhost()?; @@ -842,7 +846,7 @@ async fn restore(mut param: Value) -> Result<(), Error> { let (config, _digest) = config::drive::config()?; - param["drive"] = lookup_drive_name(¶m, &config)?.into(); + param["drive"] = extract_drive_name(&mut param, &config)?.into(); let mut client = connect_to_localhost()?; @@ -878,13 +882,13 @@ async fn restore(mut param: Value) -> Result<(), Error> { }, )] /// Scan media and record content -async fn catalog_media(param: Value) -> Result<(), Error> { +async fn catalog_media(mut param: Value) -> Result<(), Error> { let output_format = get_output_format(¶m); let (config, _digest) = config::drive::config()?; - let drive = lookup_drive_name(¶m, &config)?; + let drive = extract_drive_name(&mut param, &config)?; let mut client = connect_to_localhost()?; diff --git a/src/bin/proxmox_tape/changer.rs b/src/bin/proxmox_tape/changer.rs index e3bb7bb3..d5b6ede1 100644 --- a/src/bin/proxmox_tape/changer.rs +++ b/src/bin/proxmox_tape/changer.rs @@ -42,7 +42,9 @@ pub fn lookup_changer_name( return Ok(String::from(name)); } - if let Ok(drive) = crate::lookup_drive_name(&Value::Null, config) { + let mut empty = Value::Null; + + if let Ok(drive) = crate::extract_drive_name(&mut empty, config) { if let Ok(Some((_, name))) = media_changer(config, &drive) { return Ok(name); } diff --git a/src/bin/proxmox_tape/encryption_key.rs b/src/bin/proxmox_tape/encryption_key.rs index 5587d352..9177a377 100644 --- a/src/bin/proxmox_tape/encryption_key.rs +++ b/src/bin/proxmox_tape/encryption_key.rs @@ -214,7 +214,7 @@ async fn restore_key( ) -> Result<(), Error> { let (config, _digest) = config::drive::config()?; - param["drive"] = crate::lookup_drive_name(¶m, &config)?.into(); + param["drive"] = crate::extract_drive_name(&mut param, &config)?.into(); if !tty::stdin_isatty() { bail!("no password input mechanism available"); -- 2.20.1