tape: sg-tape-cmd tape-alert-flags
This commit is contained in:
parent
c9fdd142a4
commit
74595b8821
@ -95,6 +95,33 @@ fn cartridge_memory(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[api(
|
||||||
|
input: {
|
||||||
|
properties: {
|
||||||
|
device: {
|
||||||
|
schema: LINUX_DRIVE_PATH_SCHEMA,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)]
|
||||||
|
/// Read Tape Alert Flags
|
||||||
|
fn tape_alert_flags(
|
||||||
|
device: Option<String>,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
|
||||||
|
let result = proxmox::try_block!({
|
||||||
|
let mut handle = get_tape_handle(device)?;
|
||||||
|
|
||||||
|
let flags = handle.tape_alert_flags()?;
|
||||||
|
Ok(flags.bits())
|
||||||
|
}).map_err(|err: Error| err.to_string());
|
||||||
|
|
||||||
|
println!("{}", serde_json::to_string_pretty(&result)?);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Error> {
|
fn main() -> Result<(), Error> {
|
||||||
|
|
||||||
// check if we are user root or backup
|
// check if we are user root or backup
|
||||||
@ -126,6 +153,10 @@ fn main() -> Result<(), Error> {
|
|||||||
"cartridge-memory",
|
"cartridge-memory",
|
||||||
CliCommand::new(&API_METHOD_CARTRIDGE_MEMORY)
|
CliCommand::new(&API_METHOD_CARTRIDGE_MEMORY)
|
||||||
)
|
)
|
||||||
|
.insert(
|
||||||
|
"tape-alert-flags",
|
||||||
|
CliCommand::new(&API_METHOD_TAPE_ALERT_FLAGS)
|
||||||
|
)
|
||||||
;
|
;
|
||||||
|
|
||||||
let mut rpcenv = CliEnvironment::new();
|
let mut rpcenv = CliEnvironment::new();
|
||||||
|
@ -18,8 +18,10 @@ use crate::{
|
|||||||
tape::{
|
tape::{
|
||||||
TapeRead,
|
TapeRead,
|
||||||
TapeWrite,
|
TapeWrite,
|
||||||
|
TapeAlertFlags,
|
||||||
read_mam_attributes,
|
read_mam_attributes,
|
||||||
mam_extract_media_usage,
|
mam_extract_media_usage,
|
||||||
|
read_tape_alert_flags,
|
||||||
drive::{
|
drive::{
|
||||||
LinuxTapeDrive,
|
LinuxTapeDrive,
|
||||||
TapeDriver,
|
TapeDriver,
|
||||||
@ -294,6 +296,27 @@ impl LinuxTapeHandle {
|
|||||||
let result: Result<Vec<MamAttribute>, String> = serde_json::from_str(&output)?;
|
let result: Result<Vec<MamAttribute>, String> = serde_json::from_str(&output)?;
|
||||||
result.map_err(|err| format_err!("{}", err))
|
result.map_err(|err| format_err!("{}", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Read Tape Alert Flags
|
||||||
|
///
|
||||||
|
/// Note: Only 'root' user may run RAW SG commands, so we need to
|
||||||
|
/// spawn setuid binary 'sg-tape-cmd'.
|
||||||
|
pub fn tape_alert_flags(&mut self) -> Result<TapeAlertFlags, Error> {
|
||||||
|
|
||||||
|
if nix::unistd::Uid::effective().is_root() {
|
||||||
|
return read_tape_alert_flags(&mut self.file);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut command = std::process::Command::new(
|
||||||
|
"/usr/lib/x86_64-linux-gnu/proxmox-backup/sg-tape-cmd");
|
||||||
|
command.args(&["tape-alert-flags"]);
|
||||||
|
command.stdin(unsafe { std::process::Stdio::from_raw_fd(self.file.as_raw_fd())});
|
||||||
|
let output = run_command(command, None)?;
|
||||||
|
let result: Result<u64, String> = serde_json::from_str(&output)?;
|
||||||
|
result
|
||||||
|
.map_err(|err| format_err!("{}", err))
|
||||||
|
.map(|bits| TapeAlertFlags::from_bits_truncate(bits))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ use proxmox::tools::io::ReadExt;
|
|||||||
use crate::{
|
use crate::{
|
||||||
api2::types::MamAttribute,
|
api2::types::MamAttribute,
|
||||||
tape::{
|
tape::{
|
||||||
tape_alert_flags::TapeAlertFlags,
|
TapeAlertFlags,
|
||||||
sgutils2::SgRaw,
|
sgutils2::SgRaw,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
mod virtual_tape;
|
mod virtual_tape;
|
||||||
mod linux_mtio;
|
mod linux_mtio;
|
||||||
|
|
||||||
pub mod tape_alert_flags;
|
mod tape_alert_flags;
|
||||||
|
pub use tape_alert_flags::*;
|
||||||
|
|
||||||
pub mod linux_tape;
|
pub mod linux_tape;
|
||||||
|
|
||||||
mod mam;
|
mod mam;
|
||||||
|
Loading…
Reference in New Issue
Block a user