Skip to content

Commit

Permalink
dird: Add support for non-interactive label barcodes.
Browse files Browse the repository at this point in the history
We should not ask for confirmation in batch mode and accept the yes
keyword as indication that we should not be interactive like we do in
other situations. Also add the drive argument to label which is needed
when we have a multidrive autochanger.
  • Loading branch information
Marco van Wieringen committed Feb 18, 2016
1 parent 240a876 commit ebb8346
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
12 changes: 6 additions & 6 deletions src/dird/ua_cmds.c
Expand Up @@ -137,7 +137,7 @@ static struct cmdstruct commands[] = {
{ NT_("import"), import_cmd, _("Import volumes from import/export slots to normal slots"),
NT_("storage=<storage-name> [ srcslots=<slot-selection> dstslots=<slot-selection> volume=<volume-name> scan ]"), true, true },
{ NT_("label"), label_cmd, _("Label a tape"),
NT_("storage=<storage-name> volume=<volume-name> pool=<pool-name> slot=<slot> [ barcodes ] [ encrypt ]"), false, true },
NT_("storage=<storage-name> volume=<volume-name> pool=<pool-name> slot=<slot> [ drive = <drivenum>] [ barcodes ] [ encrypt ] [ yes ]"), false, true },
{ NT_("list"), list_cmd, _("List objects from catalog"),
NT_("basefiles jobid=<jobid> | basefiles ujobid=<complete_name> |\n"
"backups client=<client-name> [fileset=<fileset-name>] [jobstatus=<status>] [level=<level>] [order=<asc|desc>] [limit=<number>] |\n"
Expand Down Expand Up @@ -188,15 +188,15 @@ static struct cmdstruct commands[] = {
{ NT_("memory"), memory_cmd, _("Print current memory usage"),
NT_(""), true, false },
{ NT_("mount"), mount_cmd, _("Mount storage"),
NT_("storage=<storage-name> slot=<num> drive=<num>\n"
NT_("storage=<storage-name> slot=<num> drive=<drivenum>\n"
"\tjobid=<jobid> | job=<job-name> | ujobid=<complete_name>"), false, true },
{ NT_("move"), move_cmd, _("Move slots in an autochanger"),
NT_("storage=<storage-name> srcslots=<slot-selection> dstslots=<slot-selection>"), true, true },
{ NT_("prune"), prune_cmd, _("Prune records from catalog"),
NT_("files | jobs | jobtype=<jobtype> | pool=<pool-name> | client=<client-name> | volume=<volume-name> | directory=<directory> | recursive"), true, true },
{ NT_("purge"), purge_cmd, _("Purge records from catalog"),
NT_("files jobs volume=<volume-name> [ action=<action> devicetype=<type> pool=<pool-name>\n"
"\tallpools storage=<storage-name> drive=<num> ]"), true, true },
"\tallpools storage=<storage-name> drive=<drivenum> ]"), true, true },
{ NT_("quit"), quit_cmd, _("Terminate Bconsole session"),
NT_(""), false, false },
{ NT_("query"), query_cmd, _("Query catalog"),
Expand All @@ -213,7 +213,7 @@ static struct cmdstruct commands[] = {
NT_("storage=<storage-name> oldvolume=<old-volume-name>\n"
"\tvolume=<new-volume-name> pool=<pool-name> [ encrypt ]"), false, true },
{ NT_("release"), release_cmd, _("Release storage"),
NT_("storage=<storage-name> [ drive=<num> ] [ alldrives ]"), false, true },
NT_("storage=<storage-name> [ drive=<drivenum> ] [ alldrives ]"), false, true },
{ NT_("reload"), reload_cmd, _("Reload conf file"),
NT_(""), true, true },
{ NT_("rerun"), rerun_cmd, _("Rerun a job"),
Expand Down Expand Up @@ -252,10 +252,10 @@ static struct cmdstruct commands[] = {
{ NT_("trace"), trace_cmd, _("Turn on/off trace to file"),
NT_("on | off"), true, true },
{ NT_("unmount"), unmount_cmd, _("Unmount storage"),
NT_("storage=<storage-name> [ drive=<num> ]\n"
NT_("storage=<storage-name> [ drive=<drivenum> ]\n"
"\tjobid=<jobid> | job=<job-name> | ujobid=<complete_name>"), false, true },
{ NT_("umount"), unmount_cmd, _("Umount - for old-time Unix guys, see unmount"),
NT_("storage=<storage-name> [ drive=<num> ]\n"
NT_("storage=<storage-name> [ drive=<drivenum> ]\n"
"\tjobid=<jobid> | job=<job-name> | ujobid=<complete_name>"), false, true },
{ NT_("update"), update_cmd, _("Update volume, pool or stats"),
NT_("stats\n"
Expand Down
29 changes: 19 additions & 10 deletions src/dird/ua_label.c
Expand Up @@ -30,7 +30,8 @@
#include "dird.h"

/* Forward referenced functions */
static void label_from_barcodes(UAContext *ua, int drive, bool label_encrypt);
static void label_from_barcodes(UAContext *ua, int drive,
bool label_encrypt, bool yes);
static bool send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr,
POOL_DBR *pr, bool relabel, bool media_record_exists,
int drive);
Expand Down Expand Up @@ -75,18 +76,19 @@ static inline bool is_cleaning_tape(UAContext *ua, MEDIA_DBR *mr, POOL_DBR *pr)
*/
static int do_label(UAContext *ua, const char *cmd, bool relabel)
{
USTORERES store;
int i, j;
int drive;
BSOCK *sd;
char dev_name[MAX_NAME_LENGTH];
MEDIA_DBR mr, omr;
POOL_DBR pr;
USTORERES store;
bool ok = false;
bool yes = false; /* Was "yes" given on cmdline */
bool print_reminder = true;
bool label_barcodes = false;
bool label_encrypt = false;
int ok = FALSE;
int i, j;
int drive;
bool media_record_exists = false;
char dev_name[MAX_NAME_LENGTH];
static const char *barcode_keywords[] = {
"barcode",
"barcodes",
Expand All @@ -101,6 +103,10 @@ static int do_label(UAContext *ua, const char *cmd, bool relabel)
memset(&mr, 0, sizeof(mr));
memset(&omr, 0, sizeof(omr));

if (ua->batch || find_arg(ua, NT_("yes")) > 0) {
yes = true;
}

/*
* Look for one of the barcode keywords
*/
Expand Down Expand Up @@ -152,7 +158,7 @@ static int do_label(UAContext *ua, const char *cmd, bool relabel)
drive = get_storage_drive(ua, store.store);

if (label_barcodes) {
label_from_barcodes(ua, drive, label_encrypt);
label_from_barcodes(ua, drive, label_encrypt, yes);
return 1;
}

Expand Down Expand Up @@ -276,7 +282,6 @@ static int do_label(UAContext *ua, const char *cmd, bool relabel)
}

ok = send_label_request(ua, &mr, &omr, &pr, relabel, media_record_exists, drive);

if (ok) {
sd = ua->jcr->store_bsock;
if (relabel) {
Expand Down Expand Up @@ -346,7 +351,8 @@ static int do_label(UAContext *ua, const char *cmd, bool relabel)
/*
* Request SD to send us the slot:barcodes, then wiffle through them all labeling them.
*/
static void label_from_barcodes(UAContext *ua, int drive, bool label_encrypt)
static void label_from_barcodes(UAContext *ua, int drive,
bool label_encrypt, bool yes)
{
STORERES *store = ua->jcr->res.wstore;
POOL_DBR pr;
Expand Down Expand Up @@ -389,10 +395,13 @@ static void label_from_barcodes(UAContext *ua, int drive, bool label_encrypt)
}
ua->send_msg("%4d %s\n", vl->Slot, vl->VolName);
}
if (!get_yesno(ua, _("Do you want to label these Volumes? (yes|no): ")) ||

if (!yes ||
!get_yesno(ua, _("Do you want to label these Volumes? (yes|no): ")) ||
(ua->pint32_val == 0)) {
goto bail_out;
}

/*
* Select a pool
*/
Expand Down

0 comments on commit ebb8346

Please sign in to comment.