]> git.proxmox.com Git - proxmox-backup.git/blame - src/tape/changer/mtx/mtx_wrapper.rs
tree-wide: fix needless borrows
[proxmox-backup.git] / src / tape / changer / mtx / mtx_wrapper.rs
CommitLineData
b107fdb9
DM
1use anyhow::Error;
2
25877d05 3use proxmox_sys::command::run_command;
6227654a 4use pbs_api_types::ScsiTapeChanger;
048b43af 5use pbs_tape::MtxStatus;
4c1b7761 6
b107fdb9 7use crate::{
4be47366 8 tape::changer::{
048b43af 9 mtx::parse_mtx_status,
b107fdb9
DM
10 },
11};
12
13/// Run 'mtx status' and return parsed result.
d5035c56 14pub fn mtx_status(config: &ScsiTapeChanger) -> Result<MtxStatus, Error> {
d5035c56
DM
15 let path = &config.path;
16
b107fdb9
DM
17 let mut command = std::process::Command::new("mtx");
18 command.args(&["-f", path, "status"]);
19
20 let output = run_command(command, None)?;
21
d5035c56
DM
22 let mut status = parse_mtx_status(&output)?;
23
9a37bd6c 24 status.mark_import_export_slots(config)?;
b107fdb9
DM
25
26 Ok(status)
27}
28
29/// Run 'mtx load'
30pub fn mtx_load(
31 path: &str,
32 slot: u64,
33 drivenum: u64,
34) -> Result<(), Error> {
35
36 let mut command = std::process::Command::new("mtx");
37 command.args(&["-f", path, "load", &slot.to_string(), &drivenum.to_string()]);
38 run_command(command, None)?;
39
40 Ok(())
41}
42
43/// Run 'mtx unload'
44pub fn mtx_unload(
45 path: &str,
46 slot: u64,
47 drivenum: u64,
48) -> Result<(), Error> {
49
50 let mut command = std::process::Command::new("mtx");
51 command.args(&["-f", path, "unload", &slot.to_string(), &drivenum.to_string()]);
52 run_command(command, None)?;
53
54 Ok(())
55}
56
5d908606
DM
57/// Run 'mtx transfer'
58pub fn mtx_transfer(
59 path: &str,
60 from_slot: u64,
61 to_slot: u64,
62) -> Result<(), Error> {
63
64 let mut command = std::process::Command::new("mtx");
65 command.args(&["-f", path, "transfer", &from_slot.to_string(), &to_slot.to_string()]);
66
67 run_command(command, None)?;
68
69 Ok(())
70}