From 709154beebb283ef9e9e4427fa142b9030a20228 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Thu, 22 May 2014 13:03:04 +0200 Subject: [PATCH] Limit storage list to autochangers automatically. 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. --- src/dird/protos.h | 5 +++-- src/dird/ua_cmds.c | 12 +++++----- src/dird/ua_dotcmds.c | 4 ++-- src/dird/ua_impexp.c | 2 +- src/dird/ua_label.c | 2 +- src/dird/ua_purge.c | 2 +- src/dird/ua_restore.c | 2 +- src/dird/ua_select.c | 51 ++++++++++++++++++++++++++++--------------- src/dird/ua_status.c | 10 +++++++-- src/dird/ua_update.c | 2 +- 10 files changed, 57 insertions(+), 35 deletions(-) diff --git a/src/dird/protos.h b/src/dird/protos.h index a60348a3087..516ffefcd07 100644 --- a/src/dird/protos.h +++ b/src/dird/protos.h @@ -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); @@ -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); diff --git a/src/dird/ua_cmds.c b/src/dird/ua_cmds.c index 79fa5052fab..276bb5c105e 100644 --- a/src/dird/ua_cmds.c +++ b/src/dird/ua_cmds.c @@ -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; @@ -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. @@ -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); } @@ -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: @@ -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: @@ -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; } diff --git a/src/dird/ua_dotcmds.c b/src/dird/ua_dotcmds.c index dd91fd85afb..64fd8e3f228 100644 --- a/src/dird/ua_dotcmds.c +++ b/src/dird/ua_dotcmds.c @@ -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); } } } @@ -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); diff --git a/src/dird/ua_impexp.c b/src/dird/ua_impexp.c index 9b5c9ec60fc..52a14642955 100644 --- a/src/dird/ua_impexp.c +++ b/src/dird/ua_impexp.c @@ -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; } diff --git a/src/dird/ua_label.c b/src/dird/ua_label.c index 0f2326b09bf..6335d2cc6b4 100644 --- a/src/dird/ua_label.c +++ b/src/dird/ua_label.c @@ -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; } diff --git a/src/dird/ua_purge.c b/src/dird/ua_purge.c index b20ee012f04..9f41430fa4b 100644 --- a/src/dird/ua_purge.c +++ b/src/dird/ua_purge.c @@ -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; } diff --git a/src/dird/ua_restore.c b/src/dird/ua_restore.c index bc5bef60e5b..364ad5cde57 100644 --- a/src/dird/ua_restore.c +++ b/src/dird/ua_restore.c @@ -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()); } diff --git a/src/dird/ua_select.c b/src/dird/ua_select.c index 5785fc99fbd..6bc77b73955 100644 --- a/src/dird/ua_select.c +++ b/src/dird/ua_select.c @@ -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(); @@ -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= - * job= - * jobid= - * ? (prompt him with storage list) - * (prompt him with storage list) + * We scan what the user has entered looking for : + * - storage= + * - job= + * - jobid= + * - ? (prompt him with storage list) + * - (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++) { /* @@ -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 @@ -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; } diff --git a/src/dird/ua_status.c b/src/dird/ua_status.c index 11c104e4d52..c959736a1b2 100644 --- a/src/dird/ua_status.c +++ b/src/dird/ua_status.c @@ -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: @@ -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); @@ -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) { diff --git a/src/dird/ua_update.c b/src/dird/ua_update.c index 5289c3465d9..ac091b3f30d 100644 --- a/src/dird/ua_update.c +++ b/src/dird/ua_update.c @@ -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; }