1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
|
/*
* Copyright (c) 1998,1999,2000
* Traakan, Inc., Los Altos, CA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice unmodified, this list of conditions, and the following
* disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Project: NDMJOB
* Ident: $Id: $
*
* Description:
*
*/
#include "ndmagents.h"
#ifndef NDMOS_OPTION_NO_CONTROL_AGENT
#define RETERR if (errcnt++ >= errskip) return errcnt;
#define ERROR(S) { if (errbuf) strcpy(errbuf, (S)); RETERR }
/*
* To just check a job:
* rc = ndma_job_audit (job, 0, 0);
* if (rc) { "error" }
*
* To display everything wrong with a job:
* i = n_err = 0;
* do {
* n_err = ndma_job_audit (job, errbuf, i);
* if (n_err) display (errbuf);
* i++;
* } while (i < n_err);
*
* if (n_err) { "error" }
*/
int
ndma_job_audit (struct ndm_job_param *job, char *errbuf, int errskip)
{
int errcnt = 0;
char * audit_what;
switch (job->operation) {
default:
ERROR ("invalid operatiton")
return -1;
case NDM_JOB_OP_BACKUP: audit_what = "DfbBmM"; break;
case NDM_JOB_OP_EXTRACT: audit_what = "DfbBmM"; break;
case NDM_JOB_OP_TOC: audit_what = "DfbBmM"; break;
case NDM_JOB_OP_QUERY_AGENTS: audit_what = ""; break;
case NDM_JOB_OP_INIT_LABELS: audit_what = "TfmM"; break;
case NDM_JOB_OP_LIST_LABELS: audit_what = "TfM"; break;
case NDM_JOB_OP_REMEDY_ROBOT: audit_what = ""; break;
case NDM_JOB_OP_TEST_TAPE: audit_what = "TfM"; break;
case NDM_JOB_OP_TEST_MOVER: audit_what = "TfbM"; break;
case NDM_JOB_OP_TEST_DATA: audit_what = "DB"; break;
case NDM_JOB_OP_REWIND_TAPE: audit_what = "Tf"; break;
case NDM_JOB_OP_EJECT_TAPE: audit_what = "Tf"; break;
case NDM_JOB_OP_MOVE_TAPE: audit_what = "Rr@"; break;
case NDM_JOB_OP_IMPORT_TAPE: audit_what = "Rr@"; break;
case NDM_JOB_OP_EXPORT_TAPE: audit_what = "Rr@"; break;
case NDM_JOB_OP_LOAD_TAPE: audit_what = "Rr@"; break;
case NDM_JOB_OP_UNLOAD_TAPE: audit_what = "Rr"; break;
case NDM_JOB_OP_INIT_ELEM_STATUS: audit_what = "Rr"; break;
}
while (*audit_what) switch (*audit_what++) {
case 'D': /* DATA agent provided */
if (job->data_agent.conn_type == NDMCONN_TYPE_NONE)
ERROR("missing DATA agent")
break;
case 'T': /* TAPE agent provided (use DATA if given) */
if (job->data_agent.conn_type == NDMCONN_TYPE_NONE
&& job->tape_agent.conn_type == NDMCONN_TYPE_NONE)
ERROR("missing TAPE or DATA agent")
break;
case 'R': /* ROBOT agent provided (use TAPE or DATA if given) */
if (job->data_agent.conn_type == NDMCONN_TYPE_NONE
&& job->tape_agent.conn_type == NDMCONN_TYPE_NONE
&& job->robot_agent.conn_type == NDMCONN_TYPE_NONE)
ERROR("missing ROBOT, TAPE or DATA agent")
break;
case 'B': /* Backup type */
if (!job->bu_type)
ERROR("missing bu_type")
break;
case 'b': /* block (record) size */
if (!job->record_size)
ERROR("missing record size")
break;
case 'f': /* tape file */
if (!job->tape_device)
ERROR("missing tape device")
break;
case 'm': /* media entry/ies */
if (job->media_tab.n_media < 1)
ERROR("missing media entry")
break;
case 'M': /* ? */
errcnt += ndma_job_media_audit (job, errbuf, errskip-errcnt);
break;
case 'r': /* robot file/device name */
if (!job->have_robot)
ERROR ("missing robot SCSI address");
break;
case '@': /* from and/or to address */
if (job->operation == NDM_JOB_OP_MOVE_TAPE
|| job->operation == NDM_JOB_OP_EXPORT_TAPE
|| job->operation == NDM_JOB_OP_LOAD_TAPE) {
if (!job->from_addr_given)
ERROR ("missing 'from' slot address");
}
if (job->operation == NDM_JOB_OP_MOVE_TAPE
|| job->operation == NDM_JOB_OP_IMPORT_TAPE) {
if (!job->to_addr_given)
ERROR ("missing 'to' slot address");
}
break;
default:
ERROR ("INTERNAL BOTCH")
return -2;
}
if (job->robot_agent.conn_type != NDMCONN_TYPE_NONE
&& !job->have_robot
&& job->operation != NDM_JOB_OP_QUERY_AGENTS) {
ERROR ("robot agent, but no robot")
}
return errcnt;
}
int
ndma_job_media_audit (struct ndm_job_param *job, char *errbuf, int errskip)
{
struct ndm_media_table *mtab = &job->media_tab;
int n_media = mtab->n_media;
struct ndmmedia * me;
struct ndmmedia * me2;
int errcnt = 0;
int i, j;
if (job->have_robot) {
for (i = 0; i < n_media; i++) {
me = &mtab->media[i];
if (!me->valid_slot) {
if (errbuf) {
sprintf (errbuf,
"media #%d missing slot address",
i+1);
}
RETERR
continue;
}
for (j = i+1; j < n_media; j++) {
me2 = &mtab->media[j];
if (! me2->valid_slot)
continue;
if (me->slot_addr == me2->slot_addr) {
if (errbuf) {
sprintf (errbuf,
"media #%d dup slot addr w/ #%d",
i+1, j+1);
}
RETERR
}
}
}
} else {
if (n_media > 1) {
ERROR ("no robot, too many media")
}
for (i = 0; i < n_media; i++) {
me = &mtab->media[i];
if (me->valid_slot) {
if (errbuf) {
sprintf (errbuf,
"media #%d slot address, but no robot",
i+1);
}
RETERR
}
}
}
if (job->operation == NDM_JOB_OP_INIT_LABELS) {
for (i = 0; i < n_media; i++) {
me = &mtab->media[i];
if (! me->valid_label) {
if (errbuf) {
sprintf (errbuf,
"media #%d missing label",
i+1);
}
RETERR
}
}
}
return 0;
}
void
ndma_job_auto_adjust (struct ndm_job_param *job)
{
if (job->media_tab.n_media == 0
&& !job->have_robot
&& job->operation != NDM_JOB_OP_INIT_LABELS) {
/* synthesize one media table entry */
NDMOS_MACRO_ZEROFILL (&job->media_tab.media[0]);
job->media_tab.n_media = 1;
}
}
#endif /* !NDMOS_OPTION_NO_CONTROL_AGENT */
|