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
38 #include "ndmos.h" /* rpc/rpc.h */
39 #include "ndmprotocol.h"
42 #ifndef NDMOS_OPTION_NO_NDMP2
46 ndmp2_pp_header (void *data, char *buf)
48 ndmp2_header * mh = (ndmp2_header *) data;
50 if (mh->message_type == NDMP2_MESSAGE_REQUEST) {
51 sprintf (buf, "C %s %lu",
52 ndmp2_message_to_str (mh->message),
54 } else if (mh->message_type == NDMP2_MESSAGE_REPLY) {
55 sprintf (buf, "R %s %lu (%lu)",
56 ndmp2_message_to_str (mh->message),
59 if (mh->error != NDMP2_NO_ERR) {
60 sprintf (NDMOS_API_STREND(buf), " %s",
61 ndmp2_error_to_str (mh->error));
62 return 0; /* no body */
65 strcpy (buf, "??? INVALID MESSAGE TYPE");
66 return -1; /* no body */
72 ndmp2_pp_mover_addr (char *buf, ndmp2_mover_addr *ma)
74 sprintf (buf, "%s", ndmp2_mover_addr_type_to_str (ma->addr_type));
75 if (ma->addr_type == NDMP2_ADDR_TCP) {
76 sprintf (NDMOS_API_STREND(buf), "(%lx,%d)",
77 ma->ndmp2_mover_addr_u.addr.ip_addr,
78 ma->ndmp2_mover_addr_u.addr.port);
85 ndmp2_pp_request (ndmp2_message msg, void *data, int lineno, char *buf)
92 strcpy (buf, "<<INVALID MSG>>");
95 case NDMP2_CONNECT_OPEN:
96 NDMP_PP_WITH(ndmp2_connect_open_request)
97 sprintf (buf, "version=%d", p->protocol_version);
101 case NDMP2_CONNECT_CLIENT_AUTH:
102 NDMP_PP_WITH(ndmp2_connect_client_auth_request)
103 sprintf (buf, "auth_type=%s",
104 ndmp2_auth_type_to_str (p->auth_data.auth_type));
105 switch (p->auth_data.auth_type) {
106 case NDMP2_AUTH_NONE:
109 case NDMP2_AUTH_TEXT:
110 sprintf (NDMOS_API_STREND(buf), " auth_id=%s",
111 p->auth_data.ndmp2_auth_data_u.auth_text.auth_id);
115 sprintf (NDMOS_API_STREND(buf), " auth_id=%s",
116 p->auth_data.ndmp2_auth_data_u.auth_md5.auth_id);
120 sprintf (NDMOS_API_STREND(buf), " ????");
126 case NDMP2_CONNECT_CLOSE:
127 case NDMP2_CONFIG_GET_HOST_INFO:
128 case NDMP2_CONFIG_GET_MOVER_TYPE:
129 case NDMP2_SCSI_CLOSE:
130 case NDMP2_SCSI_GET_STATE:
131 case NDMP2_SCSI_RESET_DEVICE:
132 case NDMP2_SCSI_RESET_BUS:
133 case NDMP2_TAPE_GET_STATE:
134 case NDMP2_TAPE_CLOSE:
135 case NDMP2_MOVER_GET_STATE:
136 case NDMP2_MOVER_CONTINUE:
137 case NDMP2_MOVER_ABORT:
138 case NDMP2_MOVER_STOP:
139 case NDMP2_MOVER_CLOSE:
140 case NDMP2_DATA_GET_STATE:
141 case NDMP2_DATA_ABORT:
142 case NDMP2_DATA_STOP:
143 case NDMP2_DATA_GET_ENV:
144 *buf = 0; /* no body */
147 case NDMP2_CONNECT_SERVER_AUTH:
148 strcpy (buf, "<<unimplemented pp>>");
151 case NDMP2_CONFIG_GET_BUTYPE_ATTR:
152 NDMP_PP_WITH(ndmp2_config_get_butype_attr_request)
153 sprintf (buf, "bu_type='%s'", p->name);
157 case NDMP2_CONFIG_GET_AUTH_ATTR:
158 NDMP_PP_WITH(ndmp2_config_get_auth_attr_request)
159 sprintf (buf, "auth_type=%s", ndmp2_auth_type_to_str (p->auth_type));
163 case NDMP2_SCSI_OPEN:
164 NDMP_PP_WITH(ndmp2_scsi_open_request)
165 sprintf (buf, "device='%s'", p->device.name);
169 case NDMP2_SCSI_SET_TARGET:
170 NDMP_PP_WITH(ndmp2_scsi_set_target_request)
171 sprintf (buf, "device='%s' cont=%d sid=%d lun=%d",
172 p->device.name, p->target_controller,
173 p->target_id, p->target_lun);
177 case NDMP2_SCSI_EXECUTE_CDB:
178 case NDMP2_TAPE_EXECUTE_CDB:
179 NDMP_PP_WITH(ndmp2_execute_cdb_request)
181 case 0: sprintf (buf, "flags=0x%lx timeout=%ld datain_len=%ld",
182 p->flags, p->timeout, p->datain_len);
184 case 1: sprintf (buf, "cmd[%d]={", p->cdb.cdb_len);
185 for (j = 0; j < p->cdb.cdb_len; j++) {
186 sprintf (NDMOS_API_STREND(buf), " %02x",
187 p->cdb.cdb_val[j]&0xFF);
196 case NDMP2_TAPE_OPEN:
197 NDMP_PP_WITH(ndmp2_tape_open_request)
198 sprintf (buf, "device='%s' mode=%s",
200 ndmp2_tape_open_mode_to_str (p->mode));
204 case NDMP2_TAPE_MTIO:
205 NDMP_PP_WITH(ndmp2_tape_mtio_request)
206 sprintf (buf, "op=%s count=%ld",
207 ndmp2_tape_mtio_op_to_str(p->tape_op),
212 case NDMP2_TAPE_WRITE:
213 NDMP_PP_WITH(ndmp2_tape_write_request)
214 sprintf (buf, "data_out_len=%d", p->data_out.data_out_len);
218 case NDMP2_TAPE_READ:
219 NDMP_PP_WITH(ndmp2_tape_read_request)
220 sprintf (buf, "count=%ld", p->count);
224 case NDMP2_DATA_START_BACKUP:
225 NDMP_PP_WITH(ndmp2_data_start_backup_request)
227 sprintf (buf, "bu_type='%s' n_env=%d mover=",
228 p->bu_type, p->env.env_len);
229 ndmp2_pp_mover_addr (NDMOS_API_STREND(buf), &p->mover);
232 if (0 <= i && (unsigned)i < p->env.env_len) {
233 sprintf (buf, "env[%d] name='%s' value='%s'",
234 i, p->env.env_val[i].name,
235 p->env.env_val[i].value);
237 strcpy (buf, "--INVALID--");
240 return 1 + p->env.env_len;
244 case NDMP2_DATA_START_RECOVER:
245 case NDMP2_DATA_START_RECOVER_FILEHIST:
246 NDMP_PP_WITH(ndmp2_data_start_recover_request)
248 sprintf (buf, "bu_type='%s' n_env=%d n_nlist=%d mover=",
249 p->bu_type, p->env.env_len,
251 ndmp2_pp_mover_addr (NDMOS_API_STREND(buf), &p->mover);
254 if (0 <= i && (unsigned)i < p->env.env_len) {
255 sprintf (buf, "env[%d] name='%s' value='%s'",
256 i, p->env.env_val[i].name,
257 p->env.env_val[i].value);
260 if (0 <= i && (unsigned)i < p->nlist.nlist_len) {
262 "nl[%d] name='%s' fhi=%lld dest='%s'",
264 p->nlist.nlist_val[i].name,
265 p->nlist.nlist_val[i].fh_info,
266 p->nlist.nlist_val[i].dest);
268 strcpy (buf, "--INVALID--");
272 return 1 + p->env.env_len + p->nlist.nlist_len;
276 case NDMP2_NOTIFY_DATA_HALTED:
277 NDMP_PP_WITH(ndmp2_notify_data_halted_request)
278 sprintf (buf, "reason=%s text_reason='%s'",
279 ndmp2_data_halt_reason_to_str(p->reason),
284 case NDMP2_NOTIFY_CONNECTED:
285 NDMP_PP_WITH(ndmp2_notify_connected_request)
286 sprintf (buf, "reason=%s protocol_version=%d text_reason='%s'",
287 ndmp2_connect_reason_to_str(p->reason),
293 case NDMP2_NOTIFY_MOVER_HALTED:
294 NDMP_PP_WITH(ndmp2_notify_mover_halted_request)
295 sprintf (buf, "reason=%s text_reason='%s'",
296 ndmp2_mover_halt_reason_to_str(p->reason),
301 case NDMP2_NOTIFY_MOVER_PAUSED:
302 NDMP_PP_WITH(ndmp2_notify_mover_paused_request)
303 sprintf (buf, "reason=%s seek_position=%lld",
304 ndmp2_mover_pause_reason_to_str(p->reason),
309 case NDMP2_NOTIFY_DATA_READ:
310 NDMP_PP_WITH(ndmp2_notify_data_read_request)
311 sprintf (buf, "offset=%lld length=%lld",
312 p->offset, p->length);
317 NDMP_PP_WITH(ndmp2_log_log_request)
318 sprintf (buf, "entry='%s'", p->entry);
322 case NDMP2_LOG_DEBUG:
323 NDMP_PP_WITH(ndmp2_log_debug_request)
324 sprintf (buf, "level=%s message='%s'",
325 ndmp2_debug_level_to_str(p->level), p->message);
330 NDMP_PP_WITH(ndmp2_log_file_request)
331 sprintf (buf, "file=%s error=%s",
333 ndmp2_error_to_str(p->error));
337 case NDMP2_FH_ADD_UNIX_PATH:
338 NDMP_PP_WITH(ndmp2_fh_add_unix_path_request)
340 sprintf (buf, "n_paths=%d", p->paths.paths_len);
343 if (0 <= i && (unsigned)i < p->paths.paths_len) {
344 struct ndmp2_fh_unix_path *pa;
346 pa = &p->paths.paths_val[i];
347 sprintf (buf, "[%d] %-15s %7llu %s [%lld]", i,
348 ndmp2_unix_file_type_to_str(pa->fstat.ftype),
353 strcpy (buf, "--INVALID--");
356 return 1 + p->paths.paths_len;
360 case NDMP2_FH_ADD_UNIX_DIR:
361 NDMP_PP_WITH(ndmp2_fh_add_unix_dir_request)
363 sprintf (buf, "n_dirs=%d", p->dirs.dirs_len);
366 if (0 <= i && (unsigned)i < p->dirs.dirs_len) {
367 struct ndmp2_fh_unix_dir *de;
369 de = &p->dirs.dirs_val[i];
370 sprintf (buf, "[%d] %lu %lu %s", i,
371 de->node, de->parent, de->name);
373 strcpy (buf, "--INVALID--");
376 return 1 + p->dirs.dirs_len;
380 case NDMP2_FH_ADD_UNIX_NODE:
381 NDMP_PP_WITH(ndmp2_fh_add_unix_node_request)
383 sprintf (buf, "n_nodes=%d", p->nodes.nodes_len);
386 if (0 <= i && (unsigned)i < p->nodes.nodes_len) {
387 struct ndmp2_fh_unix_node *nd;
389 nd = &p->nodes.nodes_val[i];
390 sprintf (buf, "[%d] %-15s %7llu %lu [%lld]", i,
391 ndmp2_unix_file_type_to_str(nd->fstat.ftype),
396 strcpy (buf, "--INVALID--");
399 return 1 + p->nodes.nodes_len;
403 case NDMP2_MOVER_LISTEN:
404 NDMP_PP_WITH(ndmp2_mover_listen_request)
405 sprintf (buf, "mode=%s addr_type=%s",
406 ndmp2_mover_mode_to_str (p->mode),
407 ndmp2_mover_addr_type_to_str (p->addr_type));
411 case NDMP2_MOVER_SET_WINDOW:
412 NDMP_PP_WITH(ndmp2_mover_set_window_request)
413 sprintf (buf, "offset=%lld length=%lld", p->offset, p->length);
417 case NDMP2_MOVER_READ:
418 NDMP_PP_WITH(ndmp2_mover_read_request)
419 sprintf (buf, "offset=%lld length=%lld", p->offset, p->length);
423 case NDMP2_MOVER_SET_RECORD_SIZE:
424 NDMP_PP_WITH(ndmp2_mover_set_record_size_request)
425 sprintf (buf, "len=%lu", p->len);
429 return 1; /* one line in buf */
435 ndmp2_pp_reply (ndmp2_message msg, void *data, int lineno, char *buf)
442 strcpy (buf, "<<INVALID MSG>>");
445 case NDMP2_CONNECT_OPEN:
446 case NDMP2_CONNECT_CLIENT_AUTH:
447 case NDMP2_SCSI_OPEN:
448 case NDMP2_SCSI_CLOSE:
449 case NDMP2_SCSI_SET_TARGET:
450 case NDMP2_SCSI_RESET_DEVICE:
451 case NDMP2_SCSI_RESET_BUS:
452 case NDMP2_TAPE_OPEN:
453 case NDMP2_TAPE_CLOSE:
454 case NDMP2_MOVER_CONTINUE:
455 case NDMP2_MOVER_ABORT:
456 case NDMP2_MOVER_STOP:
457 case NDMP2_MOVER_READ:
458 case NDMP2_MOVER_SET_WINDOW:
459 case NDMP2_MOVER_CLOSE:
460 case NDMP2_MOVER_SET_RECORD_SIZE:
461 case NDMP2_DATA_START_BACKUP:
462 case NDMP2_DATA_START_RECOVER:
463 case NDMP2_DATA_START_RECOVER_FILEHIST:
464 case NDMP2_DATA_ABORT:
465 case NDMP2_DATA_STOP:
466 NDMP_PP_WITH(ndmp2_error)
467 sprintf (buf, "error=%s", ndmp2_error_to_str(*p));
471 case NDMP2_CONNECT_CLOSE:
475 case NDMP2_CONNECT_SERVER_AUTH:
476 strcpy (buf, "<<unimplemented pp>>");
479 case NDMP2_CONFIG_GET_HOST_INFO:
480 NDMP_PP_WITH(ndmp2_config_get_host_info_reply)
482 case 0: sprintf (buf, "error=%s hostname=%s",
483 ndmp2_error_to_str(p->error),
486 case 1: sprintf (buf, "os_type=%s os_vers=%s hostid=%s",
487 p->os_type, p->os_vers, p->hostid);
489 case 2: sprintf (buf, "auth_type[%d]={", p->auth_type.auth_type_len);
490 for (j = 0; j < p->auth_type.auth_type_len; j++) {
491 sprintf (NDMOS_API_STREND(buf), " %s",
492 ndmp2_auth_type_to_str(
493 p->auth_type.auth_type_val[j]));
498 strcpy (buf, "--INVALID--");
505 case NDMP2_CONFIG_GET_BUTYPE_ATTR:
506 NDMP_PP_WITH(ndmp2_config_get_butype_attr_reply)
507 sprintf (buf, "error=%s attrs=0x%lx",
508 ndmp2_error_to_str(p->error),
513 case NDMP2_CONFIG_GET_MOVER_TYPE:
514 NDMP_PP_WITH(ndmp2_config_get_mover_type_reply)
515 sprintf (buf, "error=%s methods[%d]={",
516 ndmp2_error_to_str(p->error),
517 p->methods.methods_len);
518 for (j = 0; j < p->methods.methods_len; j++) {
519 sprintf (NDMOS_API_STREND(buf), " %s",
520 ndmp2_mover_addr_type_to_str(p->methods.methods_val[j]));
526 case NDMP2_CONFIG_GET_AUTH_ATTR:
527 strcpy (buf, "<<unimplemented pp>>");
530 case NDMP2_SCSI_GET_STATE:
531 NDMP_PP_WITH(ndmp2_scsi_get_state_reply)
532 sprintf (buf, "error=%s cont=%d sid=%d lun=%d",
533 ndmp2_error_to_str(p->error),
534 p->target_controller,
535 p->target_id, p->target_lun);
539 case NDMP2_SCSI_EXECUTE_CDB:
540 case NDMP2_TAPE_EXECUTE_CDB:
541 NDMP_PP_WITH(ndmp2_execute_cdb_reply)
543 case 0: sprintf (buf,
544 "error=%s status=%02x dataout_len=%ld datain_len=%d",
545 ndmp2_error_to_str(p->error),
546 p->status, p->dataout_len, p->datain.datain_len);
548 case 1: sprintf (buf, "sense[%d]={", p->ext_sense.ext_sense_len);
549 for (j = 0; j < p->ext_sense.ext_sense_len; j++) {
550 sprintf (NDMOS_API_STREND(buf), " %02x",
551 p->ext_sense.ext_sense_val[j]&0xFF);
560 case NDMP2_TAPE_GET_STATE:
561 NDMP_PP_WITH(ndmp2_tape_get_state_reply)
563 case 0: sprintf (buf, "error=%s flags=0x%lx file_num=%ld",
564 ndmp2_error_to_str(p->error),
565 p->flags, p->file_num);
567 case 1: sprintf (buf, "soft_errors=%lu block_size=%lu blockno=%lu",
568 p->soft_errors, p->block_size, p->blockno);
570 case 2: sprintf (buf, "total_space=%lld space_remain=%lld",
571 p->total_space, p->space_remain);
574 strcpy (buf, "--INVALID--");
581 case NDMP2_TAPE_MTIO:
582 NDMP_PP_WITH(ndmp2_tape_mtio_reply)
583 sprintf (buf, "error=%s resid_count=%ld",
584 ndmp2_error_to_str(p->error), p->resid_count);
588 case NDMP2_TAPE_WRITE:
589 NDMP_PP_WITH(ndmp2_tape_write_reply)
590 sprintf (buf, "error=%s count=%ld",
591 ndmp2_error_to_str(p->error), p->count);
595 case NDMP2_TAPE_READ:
596 NDMP_PP_WITH(ndmp2_tape_read_reply)
597 sprintf (buf, "error=%s data_in_len=%d",
598 ndmp2_error_to_str(p->error), p->data_in.data_in_len);
602 case NDMP2_DATA_GET_STATE:
603 NDMP_PP_WITH(ndmp2_data_get_state_reply)
605 case 0: sprintf (buf, "error=%s op=%s",
606 ndmp2_error_to_str(p->error),
607 ndmp2_data_operation_to_str(p->operation));
609 case 1: sprintf (buf, "state=%s",
610 ndmp2_data_state_to_str(p->state));
612 case 2: sprintf (buf, "halt_reason=%s",
613 ndmp2_data_halt_reason_to_str(p->halt_reason));
615 case 3: sprintf (buf, "bytes_processed=%lld est_bytes_remain=%lld",
616 p->bytes_processed, p->est_bytes_remain);
618 case 4: sprintf (buf, "est_time_remain=%ld mover=",
620 ndmp2_pp_mover_addr (NDMOS_API_STREND(buf), &p->mover);
622 case 5: sprintf (buf, "read_offset=%lld read_length=%lld",
623 p->read_offset, p->read_length);
626 strcpy (buf, "--INVALID--");
633 case NDMP2_DATA_GET_ENV:
634 NDMP_PP_WITH(ndmp2_data_get_env_reply)
636 sprintf (buf, "error=%s n_env=%d",
637 ndmp2_error_to_str(p->error),
641 if (0 <= i && (unsigned)i < p->env.env_len) {
642 sprintf (buf, "[%d] name='%s' value='%s'",
643 i, p->env.env_val[i].name,
644 p->env.env_val[i].value);
646 strcpy (buf, "--INVALID--");
649 return p->env.env_len + 1;
653 case NDMP2_NOTIFY_DATA_HALTED:
654 case NDMP2_NOTIFY_CONNECTED:
655 case NDMP2_NOTIFY_MOVER_HALTED:
656 case NDMP2_NOTIFY_MOVER_PAUSED:
657 case NDMP2_NOTIFY_DATA_READ:
659 case NDMP2_LOG_DEBUG:
661 case NDMP2_FH_ADD_UNIX_PATH:
662 case NDMP2_FH_ADD_UNIX_DIR:
663 case NDMP2_FH_ADD_UNIX_NODE:
664 strcpy (buf, "<<ILLEGAL REPLY>>");
667 case NDMP2_MOVER_GET_STATE:
668 NDMP_PP_WITH(ndmp2_mover_get_state_reply)
670 case 0: sprintf (buf, "error=%s state=%s",
671 ndmp2_error_to_str(p->error),
672 ndmp2_mover_state_to_str(p->state));
674 case 1: sprintf (buf, "pause_reason=%s",
675 ndmp2_mover_pause_reason_to_str(p->pause_reason));
677 case 2: sprintf (buf, "halt_reason=%s",
678 ndmp2_mover_halt_reason_to_str(p->halt_reason));
680 case 3: sprintf (buf,"record_size=%lu record_num=%lu data_written=%lld",
681 p->record_size, p->record_num, p->data_written);
683 case 4: sprintf (buf, "seek=%lld to_read=%lld win_off=%lld win_len=%lld",
684 p->seek_position, p->bytes_left_to_read,
685 p->window_offset, p->window_length);
688 strcpy (buf, "--INVALID--");
695 case NDMP2_MOVER_LISTEN:
696 NDMP_PP_WITH(ndmp2_mover_listen_reply)
697 sprintf (buf, "error=%s mover=", ndmp2_error_to_str(p->error));
698 ndmp2_pp_mover_addr (NDMOS_API_STREND(buf), &p->mover);
703 return 1; /* one line in buf */
706 #endif /* NDMOS_OPTION_NO_NDMP2 */