1 This patch fixes a problem with overriding storage daemon
2 specifications. Previously they were not always honored.
3 This implements more uniform handling. It also eliminates
4 an orphaned buffer situation using JobDefs.
5 Apply to version 1.36.1 with:
8 patch -p0 <1.36.1-store.patch
14 ===================================================================
15 RCS file: /cvsroot/bacula/bacula/src/dird/job.c,v
16 retrieving revision 1.92
18 --- src/dird/job.c 21 Nov 2004 13:10:15 -0000 1.92
19 +++ src/dird/job.c 21 Dec 2004 13:04:08 -0000
22 * Kern Sibbald, October MM
28 - Copyright (C) 2000-2004 Kern Sibbald and John Walker
29 + Copyright (C) 2000-2004 Kern Sibbald
31 This program is free software; you can redistribute it and/or
32 modify it under the terms of the GNU General Public License as
34 if (!ua->jcr->storage[0]) {
35 copy_storage(ua->jcr, jcr);
37 - ua->jcr->store = jcr->store;
38 + set_storage(ua->jcr, jcr->store);
40 if (!connect_to_storage_daemon(ua->jcr, 10, SDConnectTimeout, 1)) {
41 bsendmsg(ua, _("Failed to connect to Storage daemon.\n"));
43 if (jcr->term_wait_inited) {
44 pthread_cond_destroy(&jcr->term_wait);
46 + /* Delete lists setup to hold storage pointers */
47 + for (int i=0; i<MAX_STORE; i++) {
48 + if (jcr->storage[i]) {
49 + delete jcr->storage[i];
52 jcr->job_end_push.destroy();
53 Dmsg0(200, "End dird free_jcr\n");
58 jcr->JobPriority = job->Priority;
59 + /* Copy storage definitions -- deleted in dir_free_jcr above */
60 for (int i=0; i<MAX_STORE; i++) {
61 - jcr->storage[i] = job->storage[i];
63 + if (job->storage[i]) {
64 + jcr->storage[i] = New(alist(10, not_owned_by_alist));
65 + foreach_alist(st, job->storage[i]) {
66 + jcr->storage[i]->append(st);
70 - if (!jcr->store && jcr->storage[0]) {
71 + if (jcr->storage[0]) {
72 jcr->store = (STORE *)jcr->storage[0]->first();
74 jcr->client = job->client;
76 for (int i=0; i < MAX_STORE; i++) {
77 if (old_jcr->storage[i]) {
79 + if (old_jcr->storage[i]) {
80 + delete old_jcr->storage[i];
82 new_jcr->storage[i] = New(alist(10, not_owned_by_alist));
83 foreach_alist(st, old_jcr->storage[i]) {
84 new_jcr->storage[i]->append(st);
90 +/* Set storage override */
91 +void set_storage(JCR *jcr, STORE *store)
94 + jcr->storage[0]->prepend(store);
96 Index: src/dird/msgchan.c
97 ===================================================================
98 RCS file: /cvsroot/bacula/bacula/src/dird/msgchan.c,v
99 retrieving revision 1.32
100 diff -u -r1.32 msgchan.c
101 --- src/dird/msgchan.c 29 Sep 2004 19:58:17 -0000 1.32
102 +++ src/dird/msgchan.c 21 Dec 2004 13:04:08 -0000
104 * Create a thread to interact with the Storage daemon
105 * who returns a job status and requests Catalog services, etc.
111 - Copyright (C) 2000-2004 Kern Sibbald and John Walker
112 + Copyright (C) 2000-2004 Kern Sibbald
114 This program is free software; you can redistribute it and/or
115 modify it under the terms of the GNU General Public License as
117 int max_retry_time, int verbose)
120 - STORE *store = jcr->store;
122 - jcr->store = store = (STORE *)jcr->storage[0]->first();
126 + store = (STORE *)jcr->storage[0]->first();
129 * Open message channel with the Storage daemon
132 int start_storage_daemon_job(JCR *jcr)
139 POOL_MEM device_name, pool_name, pool_type, media_type;
142 - storage = jcr->store;
143 sd = jcr->store_bsock;
145 * Now send JobId and permissions, and get back the authorization key.
146 @@ -139,23 +138,29 @@
148 * Send use device = xxx media = yyy pool = zzz
150 - pm_strcpy(device_name, storage->dev_name);
151 - pm_strcpy(media_type, storage->media_type);
152 - pm_strcpy(pool_type, jcr->pool->pool_type);
153 - pm_strcpy(pool_name, jcr->pool->hdr.name);
154 - bash_spaces(device_name);
155 - bash_spaces(media_type);
156 - bash_spaces(pool_type);
157 - bash_spaces(pool_name);
158 - bnet_fsend(sd, use_device, device_name.c_str(),
159 - media_type.c_str(), pool_name.c_str(), pool_type.c_str());
160 - Dmsg1(110, ">stored: %s", sd->msg);
161 - status = response(jcr, sd, OK_device, "Use Device", NO_DISPLAY);
163 - pm_strcpy(pool_type, sd->msg); /* save message */
164 - Jmsg(jcr, M_FATAL, 0, _("\n"
165 - " Storage daemon didn't accept Device \"%s\" because:\n %s"),
166 - device_name.c_str(), pool_type.c_str()/* sd->msg */);
168 + for (i=0; i < MAX_STORE; i++) {
169 + if (jcr->storage[i]) {
170 + storage = (STORE *)jcr->storage[i]->first();
171 + pm_strcpy(device_name, storage->dev_name);
172 + pm_strcpy(media_type, storage->media_type);
173 + pm_strcpy(pool_type, jcr->pool->pool_type);
174 + pm_strcpy(pool_name, jcr->pool->hdr.name);
175 + bash_spaces(device_name);
176 + bash_spaces(media_type);
177 + bash_spaces(pool_type);
178 + bash_spaces(pool_name);
179 + bnet_fsend(sd, use_device, device_name.c_str(),
180 + media_type.c_str(), pool_name.c_str(), pool_type.c_str());
181 + Dmsg1(110, ">stored: %s", sd->msg);
182 + status = response(jcr, sd, OK_device, "Use Device", NO_DISPLAY);
184 + pm_strcpy(pool_type, sd->msg); /* save message */
185 + Jmsg(jcr, M_FATAL, 0, _("\n"
186 + " Storage daemon didn't accept Device \"%s\" because:\n %s"),
187 + device_name.c_str(), pool_type.c_str()/* sd->msg */);
193 Index: src/dird/protos.h
194 ===================================================================
195 RCS file: /cvsroot/bacula/bacula/src/dird/protos.h,v
196 retrieving revision 1.56
197 diff -u -r1.56 protos.h
198 --- src/dird/protos.h 17 Nov 2004 22:48:22 -0000 1.56
199 +++ src/dird/protos.h 21 Dec 2004 13:04:08 -0000
202 * Director external function prototypes
208 Copyright (C) 2000-2004 Kern Sibbald and John Walker
212 extern int connect_to_file_daemon(JCR *jcr, int retry_interval,
213 - int max_retry_time, int verbose);
214 + int max_retry_time, int verbose);
215 extern int send_include_list(JCR *jcr);
216 extern int send_exclude_list(JCR *jcr);
217 extern int send_bootstrap_file(JCR *jcr);
219 extern int get_attributes_and_put_in_catalog(JCR *jcr);
220 extern int get_attributes_and_compare_to_catalog(JCR *jcr, JobId_t JobId);
221 extern int put_file_into_catalog(JCR *jcr, long file_index, char *fname,
222 - char *link, char *attr, int stream);
223 + char *link, char *attr, int stream);
224 extern void get_level_since_time(JCR *jcr, char *since, int since_len);
225 extern int send_run_before_and_after_commands(JCR *jcr);
228 extern int cancel_job(UAContext *ua, JCR *jcr);
229 extern void init_jcr_job_record(JCR *jcr);
230 extern void copy_storage(JCR *new_jcr, JCR *old_jcr);
231 +extern void set_storage(JCR *jcr, STORE *store);
234 extern void mount_request(JCR *jcr, BSOCK *bs, char *buf);
237 extern bool connect_to_storage_daemon(JCR *jcr, int retry_interval,
238 - int max_retry_time, int verbose);
239 + int max_retry_time, int verbose);
240 extern int start_storage_daemon_job(JCR *jcr);
241 extern int start_storage_daemon_message_thread(JCR *jcr);
242 extern int bget_dirmsg(BSOCK *bs);
243 @@ -149,28 +150,28 @@
244 void free_ua_context(UAContext *ua);
247 -STORE *select_storage_resource(UAContext *ua);
248 -JOB *select_job_resource(UAContext *ua);
249 -JOB *select_restore_job_resource(UAContext *ua);
250 -CLIENT *select_client_resource(UAContext *ua);
251 +STORE *select_storage_resource(UAContext *ua);
252 +JOB *select_job_resource(UAContext *ua);
253 +JOB *select_restore_job_resource(UAContext *ua);
254 +CLIENT *select_client_resource(UAContext *ua);
255 FILESET *select_fileset_resource(UAContext *ua);
256 -int select_pool_and_media_dbr(UAContext *ua, POOL_DBR *pr, MEDIA_DBR *mr);
257 -int select_media_dbr(UAContext *ua, MEDIA_DBR *mr);
258 -bool select_pool_dbr(UAContext *ua, POOL_DBR *pr);
259 -int select_client_dbr(UAContext *ua, CLIENT_DBR *cr);
261 -void start_prompt(UAContext *ua, const char *msg);
262 -void add_prompt(UAContext *ua, const char *prompt);
263 -int do_prompt(UAContext *ua, const char *automsg, const char *msg, char *prompt, int max_prompt);
264 -CAT *get_catalog_resource(UAContext *ua);
265 +int select_pool_and_media_dbr(UAContext *ua, POOL_DBR *pr, MEDIA_DBR *mr);
266 +int select_media_dbr(UAContext *ua, MEDIA_DBR *mr);
267 +bool select_pool_dbr(UAContext *ua, POOL_DBR *pr);
268 +int select_client_dbr(UAContext *ua, CLIENT_DBR *cr);
270 +void start_prompt(UAContext *ua, const char *msg);
271 +void add_prompt(UAContext *ua, const char *prompt);
272 +int do_prompt(UAContext *ua, const char *automsg, const char *msg, char *prompt, int max_prompt);
273 +CAT *get_catalog_resource(UAContext *ua);
274 STORE *get_storage_resource(UAContext *ua, int use_default);
275 -int get_media_type(UAContext *ua, char *MediaType, int max_media);
276 -bool get_pool_dbr(UAContext *ua, POOL_DBR *pr);
277 -int get_client_dbr(UAContext *ua, CLIENT_DBR *cr);
278 +int get_media_type(UAContext *ua, char *MediaType, int max_media);
279 +bool get_pool_dbr(UAContext *ua, POOL_DBR *pr);
280 +int get_client_dbr(UAContext *ua, CLIENT_DBR *cr);
281 POOL *get_pool_resource(UAContext *ua);
282 POOL *select_pool_resource(UAContext *ua);
283 CLIENT *get_client_resource(UAContext *ua);
284 -int get_job_dbr(UAContext *ua, JOB_DBR *jr);
285 +int get_job_dbr(UAContext *ua, JOB_DBR *jr);
287 int find_arg_keyword(UAContext *ua, const char **list);
288 int find_arg(UAContext *ua, const char *keyword);
292 int purge_jobs_from_volume(UAContext *ua, MEDIA_DBR *mr);
295 +extern int run_cmd(UAContext *ua, const char *cmd);
296 Index: src/dird/scheduler.c
297 ===================================================================
298 RCS file: /cvsroot/bacula/bacula/src/dird/scheduler.c,v
299 retrieving revision 1.27
300 diff -u -r1.27 scheduler.c
301 --- src/dird/scheduler.c 3 Oct 2004 19:47:34 -0000 1.27
302 +++ src/dird/scheduler.c 21 Dec 2004 13:04:08 -0000
307 - Copyright (C) 2000-2004 Kern Sibbald and John Walker
308 + Copyright (C) 2000-2004 Kern Sibbald
310 This program is free software; you can redistribute it and/or
311 modify it under the terms of the GNU General Public License as
313 jcr->dif_pool = run->dif_pool; /* override dif pool */
316 - jcr->store = run->storage; /* override storage */
317 + set_storage(jcr, run->storage); /* override storage */
320 jcr->messages = run->msgs; /* override messages */
322 ===================================================================
323 RCS file: /cvsroot/bacula/bacula/src/dird/ua.h,v
324 retrieving revision 1.23
326 --- src/dird/ua.h 18 Jun 2004 10:07:41 -0000 1.23
327 +++ src/dird/ua.h 21 Dec 2004 13:04:08 -0000
330 * Kern Sibbald, August MMI
336 Copyright (C) 2000-2004 Kern Sibbald and John Walker
338 bool automount; /* if set, mount after label */
339 bool quit; /* if set, quit */
340 bool verbose; /* set for normal UA verbosity */
341 + bool batch; /* set for non-interactive mode */
342 uint32_t pint32_val; /* positive integer */
343 int32_t int32_val; /* positive/negative */
345 Index: src/dird/ua_cmds.c
346 ===================================================================
347 RCS file: /cvsroot/bacula/bacula/src/dird/ua_cmds.c,v
348 retrieving revision 1.127
349 diff -u -r1.127 ua_cmds.c
350 --- src/dird/ua_cmds.c 4 Oct 2004 20:34:01 -0000 1.127
351 +++ src/dird/ua_cmds.c 21 Dec 2004 13:04:10 -0000
354 * Kern Sibbald, September MM
362 extern int gui_cmd(UAContext *ua, const char *cmd);
363 extern int sqlquerycmd(UAContext *ua, const char *cmd);
364 extern int querycmd(UAContext *ua, const char *cmd);
365 -extern int run_cmd(UAContext *ua, const char *cmd);
366 extern int retentioncmd(UAContext *ua, const char *cmd);
367 extern int prunecmd(UAContext *ua, const char *cmd);
368 extern int purgecmd(UAContext *ua, const char *cmd);
369 @@ -1195,7 +1194,7 @@
373 - jcr->store = store;
374 + set_storage(jcr, store);
375 /* Try connecting for up to 15 seconds */
376 bsendmsg(ua, _("Connecting to Storage daemon %s at %s:%d\n"),
377 store->hdr.name, store->address, store->SDport);
378 @@ -1254,8 +1253,10 @@
379 /* Count Storage items */
382 - for (i=0; (store = (STORE *)GetNextRes(R_STORAGE, (RES *)store)); i++)
385 + foreach_res(store, R_STORAGE) {
388 unique_store = (STORE **) malloc(i * sizeof(STORE));
389 /* Find Unique Storage address/port */
390 store = (STORE *)GetNextRes(R_STORAGE, NULL);
391 @@ -1286,8 +1287,10 @@
392 /* Count Client items */
395 - for (i=0; (client = (CLIENT *)GetNextRes(R_CLIENT, (RES *)client)); i++)
398 + foreach_res(client, R_CLIENT) {
401 unique_client = (CLIENT **) malloc(i * sizeof(CLIENT));
402 /* Find Unique Client address/port */
403 client = (CLIENT *)GetNextRes(R_CLIENT, NULL);
404 @@ -1841,7 +1844,7 @@
405 Dmsg2(120, "Found storage, MediaType=%s DevName=%s\n",
406 store->media_type, store->dev_name);
408 - jcr->store = store;
409 + set_storage(jcr, store);
410 if (!connect_to_storage_daemon(jcr, 10, SDConnectTimeout, 1)) {
411 bsendmsg(ua, _("Failed to connect to Storage daemon.\n"));
413 Index: src/dird/ua_label.c
414 ===================================================================
415 RCS file: /cvsroot/bacula/bacula/src/dird/ua_label.c,v
416 retrieving revision 1.38
417 diff -u -r1.38 ua_label.c
418 --- src/dird/ua_label.c 17 Aug 2004 14:40:09 -0000 1.38
419 +++ src/dird/ua_label.c 21 Dec 2004 13:04:10 -0000
424 - Copyright (C) 2000-2004 Kern Sibbald and John Walker
425 + Copyright (C) 2000-2004 Kern Sibbald
427 This program is free software; you can redistribute it and/or
428 modify it under the terms of the GNU General Public License as
433 - ua->jcr->store = store;
434 + set_storage(ua->jcr, store);
436 scan = find_arg(ua, _("scan")) >= 0;
442 - ua->jcr->store = store;
443 + set_storage(ua->jcr, store);
445 if (!relabel && find_arg_keyword(ua, barcode_keyword) >= 0) {
446 label_from_barcodes(ua);
447 Index: src/dird/ua_run.c
448 ===================================================================
449 RCS file: /cvsroot/bacula/bacula/src/dird/ua_run.c,v
450 retrieving revision 1.58
451 diff -u -r1.58 ua_run.c
452 --- src/dird/ua_run.c 8 Nov 2004 21:12:12 -0000 1.58
453 +++ src/dird/ua_run.c 21 Dec 2004 13:04:11 -0000
456 * Kern Sibbald, December MMI
463 - Copyright (C) 2001-2004 Kern Sibbald and John Walker
464 + Copyright (C) 2001-2004 Kern Sibbald
466 This program is free software; you can redistribute it and/or
467 modify it under the terms of the GNU General Public License as
470 * run <job-name> jobid=nn
472 + * Returns: 0 on error
476 int run_cmd(UAContext *ua, const char *cmd)
481 for (i=1; i<ua->argc; i++) {
482 - Dmsg2(200, "Doing arg %d = %s\n", i, ua->argk[i]);
483 + Dmsg2(800, "Doing arg %d = %s\n", i, ua->argk[i]);
485 /* Keep looking until we find a good keyword */
486 for (j=0; !kw_ok && kw[j]; j++) {
487 @@ -111,12 +114,12 @@
488 bsendmsg(ua, _("Value missing for keyword %s\n"), ua->argk[i]);
491 - Dmsg1(200, "Got keyword=%s\n", kw[j]);
492 + Dmsg1(800, "Got keyword=%s\n", kw[j]);
496 bsendmsg(ua, _("Job name specified twice.\n"));
500 job_name = ua->argv[i];
505 bsendmsg(ua, _("JobId specified twice.\n"));
514 bsendmsg(ua, _("Client specified twice.\n"));
518 client_name = ua->argv[i];
521 case 4: /* fileset */
523 bsendmsg(ua, _("FileSet specified twice.\n"));
527 fileset_name = ua->argv[i];
532 bsendmsg(ua, _("Level specified twice.\n"));
536 level_name = ua->argv[i];
541 bsendmsg(ua, _("Storage specified twice.\n"));
545 store_name = ua->argv[i];
550 bsendmsg(ua, _("Pool specified twice.\n"));
554 pool_name = ua->argv[i];
559 bsendmsg(ua, _("Where specified twice.\n"));
566 case 10: /* bootstrap */
568 bsendmsg(ua, _("Bootstrap specified twice.\n"));
572 bootstrap = ua->argv[i];
575 case 11: /* replace */
577 bsendmsg(ua, _("Replace specified twice.\n"));
581 replace = ua->argv[i];
586 bsendmsg(ua, _("When specified twice.\n"));
593 case 13: /* Priority */
595 bsendmsg(ua, _("Priority specified twice.\n"));
599 Priority = atoi(ua->argv[i]);
602 case 15: /* Verify Job */
603 if (verify_job_name) {
604 bsendmsg(ua, _("Verify Job specified twice.\n"));
608 verify_job_name = ua->argv[i];
610 @@ -255,21 +258,22 @@
611 Dmsg1(200, "Set jobname=%s\n", job_name);
613 bsendmsg(ua, _("Invalid keyword: %s\n"), ua->argk[i]);
618 } /* end argc loop */
620 - Dmsg0(200, "Done scan.\n");
621 + Dmsg0(800, "Done scan.\n");
624 if (catalog_name != NULL) {
625 catalog = (CAT *)GetResWithName(R_CATALOG, catalog_name);
626 if (catalog == NULL) {
627 bsendmsg(ua, _("Catalog \"%s\" not found\n"), catalog_name);
632 + Dmsg1(200, "Using catalog=%s\n", catalog_name);
636 @@ -287,11 +291,11 @@
637 job = select_job_resource(ua);
642 } else if (!acl_access_ok(ua, Job_ACL, job->hdr.name)) {
643 bsendmsg(ua, _("No authorization. Job \"%s\".\n"),
651 } else if (!acl_access_ok(ua, Storage_ACL, store->hdr.name)) {
652 bsendmsg(ua, _("No authorization. Storage \"%s\".\n"),
657 + Dmsg1(200, "Using storage=%s\n", store->hdr.name);
660 pool = (POOL *)GetResWithName(R_POOL, pool_name);
661 @@ -325,12 +330,13 @@
662 pool = job->pool; /* use default */
667 } else if (!acl_access_ok(ua, Pool_ACL, store->hdr.name)) {
668 bsendmsg(ua, _("No authorization. Pool \"%s\".\n"),
673 + Dmsg1(200, "Using pool\n", pool->hdr.name);
676 client = (CLIENT *)GetResWithName(R_CLIENT, client_name);
677 @@ -344,12 +350,13 @@
678 client = job->client; /* use default */
683 } else if (!acl_access_ok(ua, Client_ACL, store->hdr.name)) {
684 bsendmsg(ua, _("No authorization. Client \"%s\".\n"),
689 + Dmsg1(200, "Using client=%s\n", client->hdr.name);
692 fileset = (FILESET *)GetResWithName(R_FILESET, fileset_name);
693 @@ -361,11 +368,11 @@
694 fileset = job->fileset; /* use default */
699 } else if (!acl_access_ok(ua, FileSet_ACL, store->hdr.name)) {
700 bsendmsg(ua, _("No authorization. FileSet \"%s\".\n"),
706 if (verify_job_name) {
708 set_jcr_defaults(jcr, job);
710 jcr->verify_job = verify_job;
711 - jcr->store = store;
712 + set_storage(jcr, store);
713 jcr->client = client;
714 jcr->fileset = fileset;
719 /* Run without prompting? */
720 - if (find_arg(ua, _("yes")) > 0) {
721 + if (ua->batch || find_arg(ua, _("yes")) > 0) {
727 store = select_storage_resource(ua);
729 - jcr->store = store;
730 + set_storage(jcr, store);
736 bsendmsg(ua, _("Job started. JobId=%u\n"), JobId);
743 Index: src/dird/ua_server.c
744 ===================================================================
745 RCS file: /cvsroot/bacula/bacula/src/dird/ua_server.c,v
746 retrieving revision 1.35
747 diff -u -r1.35 ua_server.c
748 --- src/dird/ua_server.c 19 Sep 2004 18:56:24 -0000 1.35
749 +++ src/dird/ua_server.c 21 Dec 2004 13:04:11 -0000
753 jcr = new_jcr(sizeof(JCR), dird_free_jcr);
755 + * The job and defaults are not really used, but
756 + * we set them up to ensure that everything is correctly
760 + jcr->job = (JOB *)GetNextRes(R_JOB, NULL);
761 + set_jcr_defaults(jcr, jcr->job);
763 jcr->sd_auth_key = bstrdup("dummy"); /* dummy Storage daemon key */
764 create_unique_job_name(jcr, base_name);
765 jcr->sched_time = jcr->start_time;
767 jcr->JobLevel = L_NONE;
768 jcr->JobStatus = JS_Running;
771 - * None of these are really defined for control JCRs, so we
772 - * simply take the first of each one. This ensures that there
773 - * will be no null pointer references.
776 - jcr->job = (JOB *)GetNextRes(R_JOB, NULL);
777 - jcr->messages = (MSGS *)GetNextRes(R_MSGS, NULL);
778 - jcr->client = (CLIENT *)GetNextRes(R_CLIENT, NULL);
779 - jcr->pool = (POOL *)GetNextRes(R_POOL, NULL);
780 - jcr->catalog = (CAT *)GetNextRes(R_CATALOG, NULL);
781 - jcr->store = (STORE *)GetNextRes(R_STORAGE, NULL);
782 - jcr->fileset = (FILESET *)GetNextRes(R_FILESET, NULL);
787 Index: src/dird/ua_status.c
788 ===================================================================
789 RCS file: /cvsroot/bacula/bacula/src/dird/ua_status.c,v
790 retrieving revision 1.61
791 diff -u -r1.61 ua_status.c
792 --- src/dird/ua_status.c 19 Sep 2004 18:56:25 -0000 1.61
793 +++ src/dird/ua_status.c 21 Dec 2004 13:04:12 -0000
798 - ua->jcr->store = store;
799 + set_storage(ua->jcr, store);
800 /* Try connecting for up to 15 seconds */
801 bsendmsg(ua, _("Connecting to Storage daemon %s at %s:%d\n"),
802 store->hdr.name, store->address, store->SDport);