2 * Copyright (c) 1998,1999,2000
3 * Traakan, Inc., Los Altos, CA
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice unmodified, this list of conditions, and the following
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 #ifndef NDMOS_OPTION_NO_CONTROL_AGENT
47 struct ndm_job_param * job = &the_job;
51 NDMOS_MACRO_ZEROFILL(job);
55 ndma_job_auto_adjust (job);
58 apply_rules (job, o_rules);
62 rc = ndma_job_audit (job, errbuf, i);
63 if (rc > n_err || rc < 0) {
64 ndmjob_log (0, "error: %s", errbuf);
67 } while (i++ < n_err);
70 error_byebye ("can't proceed");
81 struct ndm_job_param * job = &the_job;
85 case NDM_JOB_OP_QUERY_AGENTS:
86 case NDM_JOB_OP_INIT_LABELS:
87 case NDM_JOB_OP_LIST_LABELS:
88 case NDM_JOB_OP_REMEDY_ROBOT:
89 case NDM_JOB_OP_TEST_TAPE:
90 case NDM_JOB_OP_TEST_MOVER:
91 case NDM_JOB_OP_TEST_DATA:
92 case NDM_JOB_OP_REWIND_TAPE:
93 case NDM_JOB_OP_EJECT_TAPE:
94 case NDM_JOB_OP_MOVE_TAPE:
95 case NDM_JOB_OP_IMPORT_TAPE:
96 case NDM_JOB_OP_EXPORT_TAPE:
97 case NDM_JOB_OP_LOAD_TAPE:
98 case NDM_JOB_OP_UNLOAD_TAPE:
99 case NDM_JOB_OP_INIT_ELEM_STATUS:
102 case NDM_JOB_OP_BACKUP:
103 args_to_job_backup_env();
107 args_to_job_recover_env();
108 args_to_job_recover_nlist();
113 case NDM_JOB_OP_EXTRACT:
114 args_to_job_recover_env();
115 args_to_job_recover_nlist();
119 case 'D': /* -o daemon */
123 printf ("mode -%c not implemented yet\n", the_mode);
126 job->operation = the_mode;
129 job->data_agent = D_data_agent;
130 job->bu_type = B_bu_type;
131 for (i = 0; i < nn_E_environment; i++)
132 job->env_tab.env[i] = E_environment[i];
133 job->env_tab.n_env = nn_E_environment;
134 if (the_mode == NDM_JOB_OP_EXTRACT || the_mode == NDM_JOB_OP_TOC) {
135 for (i = 0; (i < n_file_arg) && (i < NDM_MAX_NLIST); i++) {
136 job->nlist_tab.nlist[i] = nlist[i];
137 job->nlist_tab.nlist_new[i] = nlist_new[i];
138 job->nlist_tab.n_nlist = i + 1;
141 job->index_log.deliver = ndmjob_ixlog_deliver;
144 job->tape_agent = T_tape_agent;
145 job->tape_device = f_tape_device;
146 job->record_size = b_bsize * 512;
147 job->tape_timeout = o_tape_timeout;
148 job->use_eject = o_use_eject;
149 job->tape_target = o_tape_scsi;
150 job->tape_tcp = o_tape_tcp;
153 job->robot_agent = R_robot_agent;
154 job->robot_target = r_robot_target;
155 job->robot_timeout = o_robot_timeout;
156 if (o_tape_addr >= 0) {
157 job->drive_addr = o_tape_addr;
158 job->drive_addr_given = 1;
160 if (o_from_addr >= 0) {
161 job->from_addr = o_from_addr;
162 job->from_addr_given = 1;
164 if (o_to_addr >= 0) {
165 job->to_addr = o_to_addr;
166 job->to_addr_given = 1;
172 for (i = 0; i < n_m_media; i++)
173 job->media_tab.media[i] = m_media[i];
174 job->media_tab.n_media = n_m_media;
181 args_to_job_backup_env (void)
183 int n_env = n_E_environment;
187 E_environment[n_env].name = "FILESYSTEM";
188 E_environment[n_env].value = C_chdir;
192 E_environment[n_env].name = "HIST";
193 E_environment[n_env].value = I_index_file ? "y" : "n";
196 E_environment[n_env].name = "TYPE";
197 E_environment[n_env].value = B_bu_type;
201 E_environment[n_env].name = "USER";
202 E_environment[n_env].value = U_user;
206 for (i = 0; (i < n_e_exclude_pattern) && (n_env < NDM_MAX_ENV-2); i++) {
207 E_environment[n_env].name = "EXCLUDE";
208 E_environment[n_env].value = e_exclude_pattern[i];
211 for (i = 0; (i < n_file_arg) && (n_env < NDM_MAX_ENV-1); i++) {
212 E_environment[n_env].name = "FILES";
213 E_environment[n_env].value = file_arg[i];
218 E_environment[n_env].name = "RULES";
219 E_environment[n_env].value = o_rules;
222 nn_E_environment = n_env;
228 args_to_job_recover_env (void)
230 int n_env = n_E_environment;
234 E_environment[n_env].name = "PREFIX";
235 E_environment[n_env].value = C_chdir;
239 E_environment[n_env].name = "HIST";
240 E_environment[n_env].value = I_index_file ? "y" : "n";
243 E_environment[n_env].name = "TYPE";
244 E_environment[n_env].value = B_bu_type;
248 E_environment[n_env].name = "USER";
249 E_environment[n_env].value = U_user;
253 for (i = 0; i < n_e_exclude_pattern; i++) {
254 E_environment[n_env].name = "EXCLUDE";
255 E_environment[n_env].value = e_exclude_pattern[i];
260 E_environment[n_env].name = "RULES";
261 E_environment[n_env].value = o_rules;
264 nn_E_environment = n_env;
266 /* file_arg[]s are done in nlist[] */
268 jndex_merge_environment ();
270 return nn_E_environment;
274 normalize_name (char *name)
279 if (*p == '/' && p[1] == '/') {
283 if (p[0] == '/' && p[1] == '.' && (p[2] == '/' || p[2] == 0)) {
293 args_to_job_recover_nlist (void)
296 int i, prefix_len, len;
300 prefix_len = strlen (C_chdir) + 2;
305 for (i = 0; (i < n_file_arg) && (i < NDM_MAX_NLIST); i++) {
306 if (file_arg_new[i]) {
307 len = strlen (file_arg_new[i]) + prefix_len + 1;
309 dest = NDMOS_API_MALLOC (len);
312 strcpy (dest, C_chdir);
314 if (file_arg_new[i][0] != '/') {
317 strcat (dest, file_arg_new[i]);
319 normalize_name (file_arg_new[i]);
320 normalize_name (file_arg[i]);
321 normalize_name (dest);
323 nlist[i].original_path = file_arg[i];
324 nlist[i].destination_path = dest;
326 len = strlen (file_arg[i]) + prefix_len + 1;
328 dest = NDMOS_API_MALLOC (len);
331 strcpy (dest, C_chdir);
333 if (file_arg[i][0] != '/') {
337 strcat (dest, file_arg[i]);
339 normalize_name (file_arg[i]);
340 normalize_name (dest);
342 nlist[i].original_path = file_arg[i];
343 nlist[i].destination_path = dest;
347 return not_found; /* should ALWAYS be 0 */
352 * Index files are sequentially searched. They can be VERY big.
353 * There is a credible effort for efficiency here.
354 * Probably lots and lots and lots of room for improvement.
357 FILE * jndex_open (void);
368 /* error messages already given */
372 ndmjob_log (1, "Processing input index (-J%s)", J_index_file);
374 if (n_file_arg > 0) {
375 rc = ndmfhdb_add_fh_info_to_nlist (fp, nlist, n_file_arg);
377 /* toast one way or another */
381 jndex_fetch_post_backup_data_env(fp);
382 jndex_fetch_post_backup_media(fp);
386 if (jndex_audit_not_found ()) {
388 "Warning: Missing index entries, valid file name(s)?");
391 jndex_merge_media ();
404 ndmjob_log (1, "Warning: No -J input index?");
408 ndmjob_log (1, "Reading input index (-I%s)", J_index_file);
409 fp = fopen(J_index_file, "r");
411 perror (J_index_file);
412 error_byebye ("Can not open -J%s input index", J_index_file);
416 if (fgets (buf, sizeof buf, fp) == NULL) {
418 error_byebye ("Failed read 1st line of -J%s", J_index_file);
422 if (strcmp (buf, "##ndmjob -I\n") != 0) {
424 error_byebye ("Bad 1st line in -J%s", J_index_file);
428 if (fgets (buf, sizeof buf, fp) == NULL) {
430 error_byebye ("Failed read 2nd line of -J%s", J_index_file);
434 if (strcmp (buf, "##ndmjob -J\n") != 0) {
436 error_byebye ("Bad 2nd line in -J%s", J_index_file);
440 ndmjob_log (2, "Opened index (-J%s)", J_index_file);
452 for (i = 0; i < n_ji_media; i++) {
453 struct ndmmedia * me = &ji_media[i];
455 ndmmedia_to_str (me, buf);
456 ndmjob_log (3, "ji me[%d] %s", i, buf);
459 for (i = 0; i < n_ji_environment; i++) {
460 ndmp9_pval * pv = &ji_environment[i];
462 ndmjob_log (3, "ji env[%d] %s=%s", i, pv->name, pv->value);
465 for (i = 0; (i < n_file_arg) && (i < NDM_MAX_NLIST); i++) {
466 if (nlist[i].fh_info.valid) {
467 ndmjob_log (3, "ji fil[%d] fi=%lld %s",
468 i, nlist[i].fh_info.value, file_arg[i]);
470 ndmjob_log (3, "ji fil[%d] not-found %s",
479 jndex_merge_media (void)
481 struct ndmmedia * me;
482 struct ndmmedia * jme;
485 for (j = 0; j < n_ji_media; j++) {
488 if (! jme->valid_label)
489 continue; /* can't match it up */
491 for (i = 0; i < n_m_media; i++) {
494 if (! me->valid_label)
495 continue; /* can't match it up */
497 if (strcmp (jme->label, me->label) != 0)
500 if (!jme->valid_slot && me->valid_slot) {
501 jme->slot_addr = me->slot_addr;
507 for (i = 0; i < n_ji_media; i++) {
508 m_media[i] = ji_media[i];
512 ndmjob_log (3, "After merging input -J index with -m entries");
513 for (i = 0; i < n_m_media; i++) {
517 ndmmedia_to_str (me, buf);
518 ndmjob_log (3, "%d: -m %s", i+1, buf);
525 jndex_audit_not_found (void)
530 for (i = 0; (i < n_file_arg) && (i < NDM_MAX_NLIST); i++) {
531 if (!nlist[i].fh_info.valid) {
532 ndmjob_log (0, "No index entry for %s", file_arg[i]);
541 jndex_merge_environment (void)
545 for (i = 0; i < n_ji_environment; i++) {
546 E_environment[nn_E_environment++] = ji_environment[i];
553 jndex_fetch_post_backup_data_env (FILE *fp)
560 rc = ndmbstf_first (fp, "DE ", buf, sizeof buf);
562 return rc; /* error or not found */
566 while (buf[0] == 'D' && buf[1] == 'E' && buf[2] == ' ') {
567 if (n_ji_environment >= NDM_MAX_ENV) {
572 while (*p == ' ') p++;
574 if (!strchr (p, '=')) {
578 p = NDMOS_API_STRDUP (p);
582 ji_environment[n_ji_environment].name = p;
583 ji_environment[n_ji_environment].value = q;
587 rc = ndmbstf_getline (fp, buf, sizeof buf);
594 ndmjob_log (1, "Malformed in -J%s: %s", J_index_file, buf);
598 ndmjob_log (1, "Overflow in -J%s: %s", J_index_file, buf);
605 jndex_fetch_post_backup_media (FILE *fp)
610 rc = ndmbstf_first (fp, "CM ", buf, sizeof buf);
612 return rc; /* error or not found */
615 /* CM 01 T103/10850K */
616 while (buf[0] == 'C' && buf[1] == 'M' && buf[2] == ' ') {
617 struct ndmmedia * me;
619 if (n_ji_media >= NDM_MAX_MEDIA) {
623 me = &ji_media[n_ji_media];
624 if (ndmmedia_from_str (me, &buf[6])) {
629 rc = ndmbstf_getline (fp, buf, sizeof buf);
636 ndmjob_log (1, "Malformed in -J%s: %s", J_index_file, buf);
640 ndmjob_log (1, "Overflow in -J%s: %s", J_index_file, buf);
646 #endif /* !NDMOS_OPTION_NO_CONTROL_AGENT */