tape: add pmt weof

This commit is contained in:
Dietmar Maurer 2021-01-31 17:33:07 +01:00
parent 28f60e5291
commit 83b8949a98
3 changed files with 54 additions and 8 deletions

View File

@ -18,10 +18,20 @@ use proxmox::{
api::{ api::{
api, api,
cli::*, cli::*,
schema::{
Schema,
IntegerSchema,
},
RpcEnvironment, RpcEnvironment,
}, },
}; };
pub const FILE_MARK_COUNT_SCHEMA: Schema =
IntegerSchema::new("File mark count.")
.minimum(1)
.minimum(i32::MAX as isize)
.schema();
use proxmox_backup::{ use proxmox_backup::{
config::{ config::{
self, self,
@ -36,6 +46,7 @@ use proxmox_backup::{
complete_drive_path, complete_drive_path,
linux_tape_device_list, linux_tape_device_list,
drive::{ drive::{
linux_mtio::MTCmd,
TapeDriver, TapeDriver,
LinuxTapeHandle, LinuxTapeHandle,
open_linux_tape_device, open_linux_tape_device,
@ -99,9 +110,7 @@ fn get_tape_handle(param: &Value) -> Result<LinuxTapeHandle, Error> {
optional: true, optional: true,
}, },
count: { count: {
description: "File mark count.", schema: FILE_MARK_COUNT_SCHEMA,
type: i32,
minimum: 1
}, },
}, },
}, },
@ -258,9 +267,7 @@ fn erase(fast: Option<bool>, param: Value) -> Result<(), Error> {
optional: true, optional: true,
}, },
count: { count: {
description: "File mark count.", schema: FILE_MARK_COUNT_SCHEMA,
type: i32,
minimum: 1
}, },
}, },
}, },
@ -462,6 +469,33 @@ fn volume_statistics(param: Value) -> Result<(), Error> {
Ok(()) Ok(())
} }
#[api(
input: {
properties: {
drive: {
schema: DRIVE_NAME_SCHEMA,
optional: true,
},
device: {
schema: LINUX_DRIVE_PATH_SCHEMA,
optional: true,
},
count: {
schema: FILE_MARK_COUNT_SCHEMA,
optional: true,
},
},
},
)]
/// Write count (default 1) EOF marks at current position.
fn weof(count: Option<i32>, param: Value) -> Result<(), Error> {
let mut handle = get_tape_handle(&param)?;
handle.mtop(MTCmd::MTWEOF, count.unwrap_or(1), "write EOF mark")?;
Ok(())
}
fn main() -> Result<(), Error> { fn main() -> Result<(), Error> {
let uid = nix::unistd::Uid::current(); let uid = nix::unistd::Uid::current();
@ -489,6 +523,7 @@ fn main() -> Result<(), Error> {
.insert("scan", CliCommand::new(&API_METHOD_SCAN)) .insert("scan", CliCommand::new(&API_METHOD_SCAN))
.insert("status", std_cmd(&API_METHOD_STATUS)) .insert("status", std_cmd(&API_METHOD_STATUS))
.insert("volume-statistics", std_cmd(&API_METHOD_VOLUME_STATISTICS)) .insert("volume-statistics", std_cmd(&API_METHOD_VOLUME_STATISTICS))
.insert("weof", std_cmd(&API_METHOD_WEOF))
; ;
let mut rpcenv = CliEnvironment::new(); let mut rpcenv = CliEnvironment::new();

View File

@ -193,6 +193,16 @@ impl LinuxTapeHandle {
Ok(()) Ok(())
} }
pub fn mtop(&mut self, mt_op: MTCmd, mt_count: i32, msg: &str) -> Result<(), Error> {
let cmd = mtop { mt_op, mt_count };
unsafe {
mtioctop(self.file.as_raw_fd(), &cmd)
}.map_err(|err| format_err!("{} failed (count {}) - {}", msg, mt_count, err))?;
Ok(())
}
pub fn mtload(&mut self) -> Result<(), Error> { pub fn mtload(&mut self) -> Result<(), Error> {
let cmd = mtop { mt_op: MTCmd::MTLOAD, mt_count: 1, }; let cmd = mtop { mt_op: MTCmd::MTLOAD, mt_count: 1, };

View File

@ -1,7 +1,8 @@
//! Tape drivers //! Tape drivers
mod virtual_tape; mod virtual_tape;
mod linux_mtio;
pub mod linux_mtio;
mod tape_alert_flags; mod tape_alert_flags;
pub use tape_alert_flags::*; pub use tape_alert_flags::*;