tape: implement eject

This commit is contained in:
Dietmar Maurer 2020-12-09 17:50:48 +01:00
parent 5fb694e8c0
commit 0098b712a5
2 changed files with 68 additions and 0 deletions

View File

@ -18,6 +18,7 @@ use crate::{
mtx_unload,
linux_tape_device_list,
open_drive,
media_changer,
},
};
@ -162,6 +163,32 @@ pub fn rewind(drive: String) -> Result<(), Error> {
Ok(())
}
#[api(
input: {
properties: {
drive: {
schema: DRIVE_ID_SCHEMA,
},
},
},
)]
/// Eject/Unload drive media
pub fn eject_media(drive: String) -> Result<(), Error> {
let (config, _digest) = config::drive::config()?;
let (mut changer, _) = media_changer(&config, &drive, false)?;
if !changer.eject_on_unload() {
let mut drive = open_drive(&config, &drive)?;
drive.eject_media()?;
}
changer.unload_media()?;
Ok(())
}
pub const SUBDIRS: SubdirMap = &[
(
"rewind",
@ -173,6 +200,11 @@ pub const SUBDIRS: SubdirMap = &[
&Router::new()
.put(&API_METHOD_ERASE_MEDIA)
),
(
"eject-media",
&Router::new()
.put(&API_METHOD_EJECT_MEDIA)
),
(
"load-slot",
&Router::new()

View File

@ -108,6 +108,7 @@ fn rewind(
mut param: Value,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<(), Error> {
let (config, _digest) = config::drive::config()?;
param["drive"] = lookup_drive_name(&param, &config)?.into();
@ -122,6 +123,36 @@ fn rewind(
Ok(())
}
#[api(
input: {
properties: {
drive: {
schema: DRIVE_ID_SCHEMA,
optional: true,
},
},
},
)]
/// Eject/Unload drive media
fn eject_media(
mut param: Value,
rpcenv: &mut dyn RpcEnvironment,
) -> Result<(), Error> {
let (config, _digest) = config::drive::config()?;
param["drive"] = lookup_drive_name(&param, &config)?.into();
let info = &api2::tape::drive::API_METHOD_EJECT_MEDIA;
match info.handler {
ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?,
_ => unreachable!(),
};
Ok(())
}
fn main() {
let cmd_def = CliCommandMap::new()
@ -135,6 +166,11 @@ fn main() {
CliCommand::new(&API_METHOD_ERASE_MEDIA)
.completion_cb("drive", complete_drive_name)
)
.insert(
"eject",
CliCommand::new(&API_METHOD_EJECT_MEDIA)
.completion_cb("drive", complete_drive_name)
)
.insert("changer", changer_commands())
.insert("drive", drive_commands())
;