]> git.proxmox.com Git - proxmox-backup.git/commitdiff
tape: implement eject
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 9 Dec 2020 16:50:48 +0000 (17:50 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 9 Dec 2020 16:50:48 +0000 (17:50 +0100)
src/api2/tape/drive.rs
src/bin/proxmox-tape.rs

index a5d6c3f1e1fd62249e007e4802ee5b2492357cac..1f12c4cbe351b65f2795cba1ef6a61594e24c5e1 100644 (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()
index de70a61d8bd28e15093d7b0388009dd4096c51ba..0bf1a5da98ef1211646b85e08353657bcbc1e864 100644 (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())
         ;