Skip to content

Commit

Permalink
Limit storage list to autochangers automatically.
Browse files Browse the repository at this point in the history
There are several commands and command parameters
that only make sense on autochangers like

- label barcodes
- status slots
- import/export/move

If those commands are given, we automatically limit the storage
to autochangers only.
  • Loading branch information
pstorz authored and Marco van Wieringen committed May 26, 2014
1 parent a349577 commit 709154b
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 35 deletions.
5 changes: 3 additions & 2 deletions src/dird/protos.h
Expand Up @@ -286,7 +286,7 @@ JCR *new_control_jcr(const char *base_name, int job_type);
void free_ua_context(UAContext *ua);

/* ua_select.c */
STORERES *select_storage_resource(UAContext *ua);
STORERES *select_storage_resource(UAContext *ua, bool autochanger_only = false);
JOBRES *select_job_resource(UAContext *ua);
JOBRES *select_enable_disable_job_resource(UAContext *ua, bool enable);
JOBRES *select_restore_job_resource(UAContext *ua);
Expand All @@ -302,7 +302,8 @@ void start_prompt(UAContext *ua, const char *msg);
void add_prompt(UAContext *ua, const char *prompt);
int do_prompt(UAContext *ua, const char *automsg, const char *msg, char *prompt, int max_prompt);
CATRES *get_catalog_resource(UAContext *ua);
STORERES *get_storage_resource(UAContext *ua, bool use_default);
STORERES *get_storage_resource(UAContext *ua, bool use_default = false,
bool autochanger_only = false);
int get_storage_drive(UAContext *ua, STORERES *store);
int get_storage_slot(UAContext *ua, STORERES *store);
int get_media_type(UAContext *ua, char *MediaType, int max_media);
Expand Down
12 changes: 6 additions & 6 deletions src/dird/ua_cmds.c
Expand Up @@ -353,7 +353,7 @@ static int add_cmd(UAContext *ua, const char *cmd)
}

/* Get media type */
if ((store = get_storage_resource(ua, false /* no default */)) != NULL) {
if ((store = get_storage_resource(ua)) != NULL) {
bstrncpy(mr.MediaType, store->media_type, sizeof(mr.MediaType));
} else if (!get_media_type(ua, mr.MediaType, sizeof(mr.MediaType))) {
return 1;
Expand Down Expand Up @@ -486,7 +486,7 @@ static inline int cancel_storage_daemon_job(UAContext *ua, const char *cmd)
int i;
STORERES *store;

store = get_storage_resource(ua, false /* no default */);
store = get_storage_resource(ua);
if (store) {
/*
* See what JobId to cancel on the storage daemon.
Expand Down Expand Up @@ -892,7 +892,7 @@ static int setbwlimit_cmd(UAContext *ua, const char *cmd)

delete selection;
} else if (find_arg(ua, NT_("storage")) >= 0) {
store = get_storage_resource(ua, false /* no default */);
store = get_storage_resource(ua);
} else {
client = get_client_resource(ua);
}
Expand Down Expand Up @@ -1253,7 +1253,7 @@ static int setdebug_cmd(UAContext *ua, const char *cmd)
return 1;
}
}
store = get_storage_resource(ua, false /* no default */);
store = get_storage_resource(ua);
if (store) {
switch (store->Protocol) {
case APT_NDMPV2:
Expand Down Expand Up @@ -1285,7 +1285,7 @@ static int setdebug_cmd(UAContext *ua, const char *cmd)
set_trace(trace_flag);
break;
case 1:
store = get_storage_resource(ua, false /* no default */);
store = get_storage_resource(ua);
if (store) {
switch (store->Protocol) {
case APT_NDMPV2:
Expand Down Expand Up @@ -1940,7 +1940,7 @@ static void do_mount_cmd(UAContext *ua, const char *cmd)
}
Dmsg2(120, "%s: %s\n", cmd, ua->UA_sock->msg);

store.store = get_storage_resource(ua, true /* arg is storage */);
store.store = get_storage_resource(ua, true, false);
if (!store.store) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/dird/ua_dotcmds.c
Expand Up @@ -720,7 +720,7 @@ static bool admin_cmds(UAContext *ua, const char *cmd)
store = (STORERES *)GetResWithName(R_STORAGE, ua->argv[i]);
}
if (!store) {
store = get_storage_resource(ua, false/*no default*/);
store = get_storage_resource(ua);
}
}
}
Expand All @@ -739,7 +739,7 @@ static bool admin_cmds(UAContext *ua, const char *cmd)
dir=true;
break;
case 1:
store = get_storage_resource(ua, false/*no default*/);
store = get_storage_resource(ua);
break;
case 2:
client = select_client_resource(ua);
Expand Down
2 changes: 1 addition & 1 deletion src/dird/ua_impexp.c
Expand Up @@ -1018,7 +1018,7 @@ static int perform_move_operation(UAContext *ua, enum e_move_op operation)
int i, max_slots;
int retval = 0;

store.store = get_storage_resource(ua, false/*no default*/);
store.store = get_storage_resource(ua, false, true);
if (!store.store) {
return retval;
}
Expand Down
2 changes: 1 addition & 1 deletion src/dird/ua_label.c
Expand Up @@ -119,7 +119,7 @@ static int do_label(UAContext *ua, const char *cmd, bool relabel)
label_encrypt = true;
}

store.store = get_storage_resource(ua, true/*use default*/);
store.store = get_storage_resource(ua, true, label_barcodes);
if (!store.store) {
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/dird/ua_purge.c
Expand Up @@ -721,7 +721,7 @@ static int action_on_purge_cmd(UAContext *ua, const char *cmd)
}

/* Choose storage */
ua->jcr->res.wstore = store = get_storage_resource(ua, false);
ua->jcr->res.wstore = store = get_storage_resource(ua);
if (!store) {
goto bail_out;
}
Expand Down
2 changes: 1 addition & 1 deletion src/dird/ua_restore.c
Expand Up @@ -1602,7 +1602,7 @@ void find_storage_resource(UAContext *ua, RESTORE_CTX &rx, char *Storage, char *
/*
* Take command line arg, or ask user if none
*/
rx.store = get_storage_resource(ua, false /* don't use default */);
rx.store = get_storage_resource(ua);
if (rx.store) {
Dmsg1(200, "Set store=%s\n", rx.store->name());
}
Expand Down
51 changes: 33 additions & 18 deletions src/dird/ua_select.c
Expand Up @@ -143,16 +143,27 @@ int do_keyword_prompt(UAContext *ua, const char *msg, const char **list)
/*
* Select a Storage resource from prompt list
*/
STORERES *select_storage_resource(UAContext *ua)
STORERES *select_storage_resource(UAContext *ua, bool autochanger_only)
{
char name[MAX_NAME_LENGTH];
STORERES *store;

start_prompt(ua, _("The defined Storage resources are:\n"));
if (autochanger_only) {
start_prompt(ua, _("The defined Autochanger Storage resources are:\n"));
} else {
start_prompt(ua, _("The defined Storage resources are:\n"));
}

LockRes();
foreach_res(store, R_STORAGE) {
if (acl_access_ok(ua, Storage_ACL, store->name())) {
add_prompt(ua, store->name());
if (autochanger_only) {
if (store->autochanger) {
add_prompt(ua, store->name());
}
} else {
add_prompt(ua, store->name());
}
}
}
UnlockRes();
Expand Down Expand Up @@ -901,24 +912,28 @@ int do_prompt(UAContext *ua, const char *automsg, const char *msg,


/*
* We scan what the user has entered looking for
* storage=<storage-resource>
* job=<job_name>
* jobid=<jobid>
* ? (prompt him with storage list)
* <some-error> (prompt him with storage list)
* We scan what the user has entered looking for :
* - storage=<storage-resource>
* - job=<job_name>
* - jobid=<jobid>
* - ? (prompt him with storage list)
* - <some-error> (prompt him with storage list)
*
* If use_default is set, we assume that any keyword without a value
* is the name of the Storage resource wanted.
* is the name of the Storage resource wanted.
*
* If autochangers_only is given, we limit the output to autochangers only.
*/
STORERES *get_storage_resource(UAContext *ua, bool use_default)
STORERES *get_storage_resource(UAContext *ua, bool use_default, bool autochangers_only)
{
char *store_name = NULL;
STORERES *store = NULL;
int jobid;
JCR *jcr;
int i;
JCR *jcr;
int jobid;
char ed1[50];
char *store_name = NULL;
STORERES *store = NULL;

Dmsg1(100, "get_storage_resource: autochangers_only is %d\n", autochangers_only);

for (i = 1; i < ua->argc; i++) {
/*
Expand All @@ -929,14 +944,14 @@ STORERES *get_storage_resource(UAContext *ua, bool use_default)
}
if (use_default && !ua->argv[i]) {
/*
* Ignore barcode, barcodes, encrypt. scan and slots keywords.
* Ignore barcode, barcodes, encrypt, scan and slots keywords.
*/
if (bstrcasecmp("barcode", ua->argk[i]) ||
bstrcasecmp("barcodes", ua->argk[i]) ||
bstrcasecmp("encrypt", ua->argk[i]) ||
bstrcasecmp("scan", ua->argk[i]) ||
bstrcasecmp("slots", ua->argk[i])) {
continue;
continue;
}
/*
* Default argument is storage
Expand Down Expand Up @@ -1013,7 +1028,7 @@ STORERES *get_storage_resource(UAContext *ua, bool use_default)
}
/* No keywords found, so present a selection list */
if (!store) {
store = select_storage_resource(ua);
store = select_storage_resource(ua, autochangers_only);
}
return store;
}
Expand Down
10 changes: 8 additions & 2 deletions src/dird/ua_status.c
Expand Up @@ -113,7 +113,7 @@ bool dot_status_cmd(UAContext *ua, const char *cmd)
}
}
} else if (bstrcasecmp(ua->argk[1], "storage")) {
store = get_storage_resource(ua, false /*no default*/);
store = get_storage_resource(ua);
if (store) {
switch (store->Protocol) {
case APT_NDMPV2:
Expand Down Expand Up @@ -151,6 +151,7 @@ int status_cmd(UAContext *ua, const char *cmd)
STORERES *store;
CLIENTRES *client;
int item, i;
bool autochangers_only;

Dmsg1(20, "status:%s:\n", cmd);

Expand Down Expand Up @@ -186,7 +187,12 @@ int status_cmd(UAContext *ua, const char *cmd)
return 0;
}
} else {
store = get_storage_resource(ua, false/*no default*/);
/*
* limit storages to autochangers if slots is given
*/
autochangers_only = (find_arg(ua, NT_("slots")) > 0);
store = get_storage_resource(ua, false, autochangers_only);

if (store) {
if (find_arg(ua, NT_("slots")) > 0) {
switch (store->Protocol) {
Expand Down
2 changes: 1 addition & 1 deletion src/dird/ua_update.c
Expand Up @@ -1005,7 +1005,7 @@ static void update_slots(UAContext *ua)
if (!open_client_db(ua)) {
return;
}
store.store = get_storage_resource(ua, true/*arg is storage*/);
store.store = get_storage_resource(ua, true, true);
if (!store.store) {
return;
}
Expand Down

0 comments on commit 709154b

Please sign in to comment.