]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/autochanger.c
- Require 5 arguments to mtx-changer except list and slots
[bacula/bacula] / bacula / src / stored / autochanger.c
index 84bfae83f1c33854556fa6bf9cade75d8a89d7be..f7b9619bcc4b1ed4b13f9c22628e88c9dbe66d3e 100644 (file)
@@ -7,22 +7,17 @@
  *   Version $Id$
  */
 /*
-   Copyright (C) 2000-2005 Kern Sibbald
+   Copyright (C) 2002-2005 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   modify it under the terms of the GNU General Public License
+   version 2 as amended with additional clauses defined in the
+   file LICENSE in the main source directory.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
 
@@ -30,7 +25,6 @@
 #include "stored.h"                   /* pull in Storage Deamon headers */
 
 /* Forward referenced functions */
-static int get_autochanger_loaded_slot(DCR *dcr);
 static void lock_changer(DCR *dcr);
 static void unlock_changer(DCR *dcr);
 
@@ -60,9 +54,9 @@ int autoload_device(DCR *dcr, int writing, BSOCK *dir)
    slot = dcr->VolCatInfo.InChanger ? dcr->VolCatInfo.Slot : 0;
    /*
     * Handle autoloaders here.  If we cannot autoload it, we
-    *  will return FALSE to ask the sysop.
+    *  will return 0 so that the sysop will be asked to load it.
     */
-   if (writing && dev_cap(dev, CAP_AUTOCHANGER) && slot <= 0) {
+   if (writing && dev->is_autochanger() && slot <= 0) {
       if (dir) {
          return 0;                    /* For user, bail out right now */
       }
@@ -85,7 +79,7 @@ int autoload_device(DCR *dcr, int writing, BSOCK *dir)
       if (loaded != slot) {
          offline_or_rewind_dev(dev);
          /* We are going to load a new tape, so close the device */
-         force_close_dev(dev);
+         force_close_device(dev);
          lock_changer(dcr);
          if (loaded != 0 && loaded != -1) {        /* must unload drive */
             Dmsg0(400, "Doing changer unload.\n");
@@ -102,8 +96,9 @@ int autoload_device(DCR *dcr, int writing, BSOCK *dir)
                Jmsg(jcr, M_FATAL, 0, _("3992 Bad autochanger \"unload slot %d, drive %d\": ERR=%s.\n"),
                     slot, drive, be.strerror());
                goto bail_out;
+            } else {
+               dev->Slot = 0;            /* nothing loaded now */
             }
-
             Dmsg1(400, "unload status=%d\n", status);
          }
          /*
@@ -120,6 +115,7 @@ int autoload_device(DCR *dcr, int writing, BSOCK *dir)
          if (status == 0) {
             Jmsg(jcr, M_INFO, 0, _("3305 Autochanger \"load slot %d, drive %d\", status is OK.\n"),
                     slot, drive);
+            dev->Slot = slot;         /* set currently loaded slot */
          } else {
            berrno be;
            be.set_errno(status);
@@ -131,6 +127,7 @@ int autoload_device(DCR *dcr, int writing, BSOCK *dir)
          Dmsg2(400, "load slot %d status=%d\n", slot, status);
       } else {
          status = 0;                  /* we got what we want */
+         dev->Slot = slot;            /* set currently loaded slot */
       }
       Dmsg1(400, "After changer, status=%d\n", status);
       if (status == 0) {              /* did we succeed? */
@@ -149,13 +146,17 @@ bail_out:
 
 }
 
-static int get_autochanger_loaded_slot(DCR *dcr)
+/*
+ * Returns: -1 if error from changer command
+ *          slot otherwise
+ */
+int get_autochanger_loaded_slot(DCR *dcr)
 {
    JCR *jcr = dcr->jcr;
    POOLMEM *changer, *results;
    int status, loaded;
    uint32_t timeout = dcr->device->max_changer_wait;
-   int drive = dcr->device->drive_index;
+   int drive = dcr->dev->drive_index;
 
    results = get_pool_memory(PM_MESSAGE);
    changer = get_pool_memory(PM_FNAME);
@@ -165,18 +166,20 @@ static int get_autochanger_loaded_slot(DCR *dcr)
    /* Find out what is loaded, zero means device is unloaded */
    Jmsg(jcr, M_INFO, 0, _("3301 Issuing autochanger \"loaded drive %d\" command.\n"),
         drive);
-   changer = edit_device_codes(dcr, changer, 
-                dcr->device->changer_command, "loaded");
+   changer = edit_device_codes(dcr, changer, dcr->device->changer_command, "loaded");
+   *results = 0;
    status = run_program(changer, timeout, results);
-   Dmsg3(50, "run_prog: %s stat=%d result=%s", changer, status, results);
+   Dmsg3(50, "run_prog: %s stat=%d result=%s\n", changer, status, results);
    if (status == 0) {
       loaded = atoi(results);
       if (loaded > 0) {
          Jmsg(jcr, M_INFO, 0, _("3302 Autochanger \"loaded drive %d\", result is Slot %d.\n"),
               drive, loaded);
+         dcr->dev->Slot = loaded;
       } else {
          Jmsg(jcr, M_INFO, 0, _("3302 Autochanger \"loaded drive %d\", result: nothing loaded.\n"),
               drive);
+         dcr->dev->Slot = 0;
       }
    } else {
       berrno be;
@@ -227,9 +230,10 @@ bool autochanger_cmd(DCR *dcr, BSOCK *dir, const char *cmd)
    bool ok = false;
    int stat;
 
-   if (!dev_cap(dev, CAP_AUTOCHANGER) || !dcr->device->changer_name ||
+   if (!dev->is_autochanger() || !dcr->device->changer_name ||
        !dcr->device->changer_command) {
-      bnet_fsend(dir, _("3993 Not a autochanger device.\n"));
+      bnet_fsend(dir, _("3993 Device %s not an autochanger device.\n"),
+         dev->print_name());
       return false;
    }
 
@@ -240,7 +244,7 @@ bool autochanger_cmd(DCR *dcr, BSOCK *dir, const char *cmd)
       /* Yes, to get a good listing, we unload any volumes */
       offline_or_rewind_dev(dev);
       /* We are going to load a new tape, so close the device */
-      force_close_dev(dev);
+      force_close_device(dev);
 
       /* First unload any tape */
       loaded = get_autochanger_loaded_slot(dcr);
@@ -260,6 +264,8 @@ bool autochanger_cmd(DCR *dcr, BSOCK *dir, const char *cmd)
             be.set_errno(stat);
             Jmsg(jcr, M_INFO, 0, _("3995 Bad autochanger \"unload slot %d, drive %d\": ERR=%s.\n"),
                     slot, drive, be.strerror());
+         } else {
+            dev->Slot = 0;            /* nothing loaded */
          }
          dcr->VolCatInfo.Slot = slot;
       }
@@ -273,7 +279,7 @@ bool autochanger_cmd(DCR *dcr, BSOCK *dir, const char *cmd)
    bpipe = open_bpipe(changer, timeout, "r");
    if (!bpipe) {
       unlock_changer(dcr);
-      bnet_fsend(dir, _("3993 Open bpipe failed.\n"));
+      bnet_fsend(dir, _("3996 Open bpipe failed.\n"));
       goto bail_out;
    }
    if (strcmp(cmd, "list") == 0) {