Exemplo n.º 1
0
void
ndmta_mover_start_active (struct ndm_session *sess)
{
	struct ndm_tape_agent *	ta = sess->tape_acb;

	ndmalogf (sess, 0, 6, "mover going active");
	ndma_send_logmsg(sess, NDMP9_LOG_DEBUG, sess->plumb.control,
		"mover going active");

	switch (ta->mover_state.mode) {
	case NDMP9_MOVER_MODE_READ:
		ndmis_tape_start (sess, NDMCHAN_MODE_READ);
		ndmta_mover_active (sess);
		break;

	case NDMP9_MOVER_MODE_WRITE:
		ndmis_tape_start (sess, NDMCHAN_MODE_WRITE);
		ndmta_mover_active (sess);
		break;

	default:
		ndmalogf (sess, 0, 0, "BOTCH mover listen, unknown mode");
		break;
	}
}
Exemplo n.º 2
0
/* VERY VERY HARD */
int
ndmca_monitor_seek_tape (struct ndm_session *sess)
{
	struct ndm_control_agent *ca = sess->control_acb;
	int			rc;
	uint64_t		pos;

	pos = ca->last_notify_mover_paused.seek_position;

	ndmalogf (sess, 0, 1, "Operation requires a different tape");

/*	ndmca_media_capture_mover_window (sess);	// !!! */
	ndmca_media_calculate_offsets (sess);

	rc = ndmca_media_unload_current(sess);
	if (rc) return rc;

	rc = ndmca_media_load_seek (sess, pos);
	if (rc) return rc;

	rc = ndmca_media_set_window_current (sess);
	if (rc) return rc;

	rc = ndmca_mover_continue(sess);
	if (rc) return rc;

	ndmalogf (sess, 0, 1, "Operation resuming");

	return 0;
}
Exemplo n.º 3
0
int
ndmca_media_open_tape (struct ndm_session *sess)
{
	struct ndm_control_agent *ca = sess->control_acb;
	int			rc;
	unsigned int		t;

	ndmalogf (sess, 0, 1, "Opening tape drive %s %s",
			ca->job.tape_device,
			(ca->tape_mode == NDMP9_TAPE_RDWR_MODE)
				? "read/write" : "read-only");

	rc = -1;
	for (t = 0; t <= ca->job.tape_timeout; t += 10) {
		if (t > 0) {
			ndmalogf (sess, 0, 1,
				"Pausing ten seconds before retry (%d/%d)",
				t, ca->job.tape_timeout);
			sleep (10);
		}
		rc = ndmca_tape_open(sess);
		if (rc == 0) break;
	}

	if (rc) {
		/* should interpret the error */
		ndmalogf (sess, 0, 0, "failed open tape drive %s %s",
			ca->job.tape_device,
			(ca->tape_mode == NDMP9_TAPE_RDWR_MODE)
				? "read/write" : "read-only");
	}

	return rc;
}
Exemplo n.º 4
0
int
ndmca_media_tattle (struct ndm_session *sess)
{
	struct ndm_control_agent *ca = sess->control_acb;
	struct ndm_job_param *	job = &ca->job;
	struct ndmmedia *	me;
	int			line, nline;

	if (!sess->dump_media_info) {
		return 0;
        }

	for (me = job->media_tab.head; me; me = me->next) {
		char			buf[80];

		nline = ndmmedia_pp (me, 0, buf);
		ndmalogf (sess, 0, 1, "media #%d %s", me->index, buf);

		for (line = 1; line < nline; line++) {
			nline = ndmmedia_pp (me, line, buf);
			ndmalogf (sess, 0, 2, "         %s", buf);
		}
	}
	return 0;
}
Exemplo n.º 5
0
int
ndmca_monitor_get_post_backup_env (struct ndm_session *sess)
{
	struct ndm_control_agent *ca = sess->control_acb;
	struct ndmlog *		ixlog = &ca->job.index_log;
	struct ndm_env_entry *	entry;
	int			rc;

	rc = ndmca_data_get_env (sess);
	if (rc && ca->data_state.error == NDMP9_ILLEGAL_STATE_ERR) {
		ndmalogf (sess, 0, 2, "fetch post backup env failed");
		return 0;
	}
	if (rc) {
		ndmalogf (sess, 0, 0, "fetch post backup env failed");
		return -1;
	}

	/*
	 * Only print the data when a deliver function was defined.
	 */
	if (ixlog->deliver) {
		for (entry = ca->job.result_env_tab.head; entry; entry = entry->next) {
			ndmlogf (ixlog, "DE", 0, "%s=%s", entry->pval.name, entry->pval.value);
		}
	}

	return 0;
}
Exemplo n.º 6
0
int
ndmca_monitor_load_next (struct ndm_session *sess)
{
	struct ndm_control_agent *ca = sess->control_acb;
	int			rc;

	ndmalogf (sess, 0, 1, "Operation requires next tape");

	ndmca_media_capture_mover_window (sess);
	ndmca_media_calculate_offsets (sess);

	if (ca->tape_mode == NDMP9_TAPE_RDWR_MODE) {
	    if (ca->mover_state.pause_reason != NDMP9_MOVER_PAUSE_EOM)
		ndmca_media_write_filemarks (sess);
	    else
		ndmalogf (sess, 0, 1, "At EOM, not writing filemarks");
	}

	rc = ndmca_media_unload_current(sess);
	if (rc) return rc;

	rc = ndmca_media_load_next(sess);
	if (rc) return rc;

	rc = ndmca_media_set_window_current (sess);
	if (rc) return rc;

	rc = ndmca_mover_continue(sess);
	if (rc) return rc;

	ndmalogf (sess, 0, 1, "Operation resuming");

	return 0;
}
Exemplo n.º 7
0
int
ndmca_op_init_labels (struct ndm_session *sess)
{
    struct ndm_control_agent *ca = sess->control_acb;
    struct ndm_job_param *	job = &ca->job;
    struct ndm_media_table *mtab = &job->media_tab;
    int			n_media = mtab->n_media;
    struct ndmmedia *	me;
    int			rc, errors;

    ca->tape_mode = NDMP9_TAPE_RDWR_MODE;
    ca->is_label_op = 1;

    if (n_media <= 0) {
        ndmalogf (sess, 0, 0, "No media entries in table");
        return -1;
    }

    errors = 0;
    for (me = mtab->head; me; me = me->next) {
        if (me->valid_label)
            continue;

        ndmalogf (sess, 0, 0, "media #%d missing a label", me->index);
        errors++;
    }
    if (errors)
        return -1;

    rc = ndmca_op_robot_startup (sess, 1);
    if (rc) return rc;	/* already tattled */

    rc = ndmca_connect_tape_agent (sess);
    if (rc) {
        ndmconn_destruct (sess->plumb.tape);
        sess->plumb.tape = NULL;
        return rc;	/* already tattled */
    }

    for (me = mtab->head; me; me = me->next) {
        ca->cur_media_ix = me->index;

        rc = ndmca_media_load_current (sess);
        if (rc) {
            /* already tattled */
            continue;
        }

        rc = ndmca_media_write_label (sess, 'm', me->label);
        if (rc) {
            ndmalogf (sess, 0, 0, "failed label write");
        }

        ndmca_media_write_filemarks(sess);
        ndmca_media_unload_current (sess);
    }

    return rc;
}
Exemplo n.º 8
0
int
ndmca_test_data_listen (struct ndm_session *sess, ndmp9_error expect_err,
			ndmp9_addr_type addr_type)
{
	struct ndmconn *	conn = sess->plumb.data;
	struct ndm_control_agent *ca = sess->control_acb;
	int			rc;

	/* close previous test if there is one */
	ndmca_test_close (sess);

	switch (conn->protocol_version) {
	default:	return -1234;

#ifndef NDMOS_OPTION_NO_NDMP3
	case NDMP3VER:
	    NDMC_WITH(ndmp3_data_listen, NDMP3VER)
		request->addr_type = addr_type;

		rc = NDMTEST_CALL(conn);
		if (rc) return rc;

		if (expect_err == NDMP9_NO_ERR
		 && request->addr_type
		    != reply->data_connection_addr.addr_type) {
			/* TODO: use proper test format */
			ndmalogf (sess, "Test", 1,
				"DATA_LISTEN addr_type mismatch");
			return -1;
		}
		ndmp_3to9_addr (&reply->data_connection_addr, &ca->data_addr);
	    NDMC_ENDWITH
	    break;
#endif /* !NDMOS_OPTION_NO_NDMP3 */
#ifndef NDMOS_OPTION_NO_NDMP4
	case NDMP4VER:
	    NDMC_WITH(ndmp4_data_listen, NDMP4VER)
		request->addr_type = addr_type;

		rc = NDMTEST_CALL(conn);
		if (rc) return rc;

		if (expect_err == NDMP9_NO_ERR
		 && request->addr_type
		    != reply->connect_addr.addr_type) {
			/* TODO: use proper test format */
			ndmalogf (sess, "Test", 1,
				"DATA_LISTEN addr_type mismatch");
			return -1;
		}
		ndmp_4to9_addr (&reply->connect_addr, &ca->data_addr);
	    NDMC_ENDWITH
	    break;
#endif /* !NDMOS_OPTION_NO_NDMP4 */
	}

	return 0;
}
Exemplo n.º 9
0
int
ndmca_connect_xxx_agent (
  struct ndm_session *sess,
  struct ndmconn **connp,
  char *prefix,
  struct ndmagent *agent)
{
	struct ndmconn *	conn = *connp;
	char *			err;
	int			rc;

	if (conn)
		return 0;		/* already connected */

	if (agent->conn_type == NDMCONN_TYPE_NONE) {
		ndmalogf (sess, 0, 0, "agent %s not give", prefix+1);
		return -1;
	}

	conn = ndmconn_initialize (0, prefix);
	if (!conn) {
		ndmalogf (sess, prefix, 0, "can't init connection");
		return -1;
	}

	if (sess->control_acb.job.time_limit > 0)
	    conn->time_limit = sess->control_acb.job.time_limit;

	ndmconn_set_snoop (conn, &sess->param.log, sess->param.log_level);

	conn->call = ndma_call;
	conn->context = sess;
	conn->unexpected = ndma_dispatch_ctrl_unexpected;

	rc = ndmconn_connect_agent (conn, agent);
	if (rc) {
		err = "Can't connect";
		goto error_out;
	}

	rc = ndmconn_auth_agent (conn, agent);
	if (rc) {
		err = "Can't auth (bad pw?)";
		goto error_out;
	}

	*connp = conn;
	return 0;

  error_out:
	ndmalogf (sess, prefix, 0, "err %s", ndmconn_get_err_msg (conn));
	//ndmconn_destruct (conn);
	*connp = conn;
	return -1;

}
Exemplo n.º 10
0
int
ndmca_op_recover_files (struct ndm_session *sess)
{
	struct ndm_control_agent *ca = sess->control_acb;
	int			rc;

	ca->tape_mode = NDMP9_TAPE_READ_MODE;
	ca->mover_mode = NDMP9_MOVER_MODE_WRITE;
	ca->is_label_op = 0;

	rc = ndmca_backreco_startup (sess);
	if (rc) return rc;

	rc = ndmca_data_start_recover (sess);
	if (rc == 0) {
		rc = ndmca_monitor_startup (sess);
		if (rc == 0) {
			rc = ndmca_monitor_recover (sess);
		}
	}

	if (rc == 0)
	    rc = ndmca_monitor_shutdown (sess);
	else
	    ndmca_monitor_shutdown (sess);

	if (rc == 0) {
	    if (ca->recover_log_file_count > 0) {
		struct ndm_control_agent *ca = sess->control_acb;
		int		    n_nlist = ca->job.nlist_tab.n_nlist;

		ndmalogf (sess, 0, 0,
			  "LOG_FILE messages: %d OK, %d ERROR, total %d of %d",
			  ca->recover_log_file_ok,
			  ca->recover_log_file_error,
			  ca->recover_log_file_count,
			  n_nlist);
	   if (ca->recover_log_file_ok < n_nlist) {
		ndmalogf (sess, 0, 0,
			  "LOG_FILE messages: WARNING OK(%d) < (%d)Expected in namelist",
			  ca->recover_log_file_ok, n_nlist);
		}
		if (ca->recover_log_file_ok < ca->recover_log_file_count) {
		    rc = 1;
		}
	    } else {
		ndmalogf (sess, 0, 1,
			  "DATA did not report any LOG_FILE messages");
	    }
	}

	if(!ca->job.tape_tcp)
		ndmca_media_tattle (sess);

	return rc;
}
Exemplo n.º 11
0
int
ndmta_quantum (struct ndm_session *sess)
{
	struct ndm_tape_agent *	ta = &sess->tape_acb;
	int			rc = 0;	/* did nothing */

	switch (ta->mover_state.state) {
	default:
		ndmalogf (sess, 0, 0, "BOTCH mover state");
		return -1;

	case NDMP9_MOVER_STATE_IDLE:
	case NDMP9_MOVER_STATE_PAUSED:
	case NDMP9_MOVER_STATE_HALTED:
		break;

	case NDMP9_MOVER_STATE_LISTEN:
		switch (sess->plumb.image_stream.tape_ep.connect_status) {
		case NDMIS_CONN_LISTEN:		/* no connection yet */
			break;

		case NDMIS_CONN_ACCEPTED:	/* we're in business */
			ndmta_mover_start_active (sess);
			rc = 1;		/* did something */
			break;

		case NDMIS_CONN_BOTCHED:	/* accept() went south */
		default:			/* ain't suppose to happen */
			ndmta_mover_halt(sess,NDMP9_MOVER_HALT_CONNECT_ERROR);
			break;
		}
		break;

	case NDMP9_MOVER_STATE_ACTIVE:
		switch (ta->mover_state.mode) {
		case NDMP9_MOVER_MODE_READ:
			rc = ndmta_read_quantum (sess);
			break;

		case NDMP9_MOVER_MODE_WRITE:
			rc = ndmta_write_quantum (sess);
			break;

		default:
			ndmalogf (sess, 0, 0,
				"BOTCH mover active, unknown mode");
			return -1;
		}
		break;
	}

	ndmta_mover_send_notice (sess);

	return rc;
}
Exemplo n.º 12
0
int
ndmca_monitor_backup_tape_tcp (struct ndm_session *sess)
{
	struct ndm_control_agent *ca = sess->control_acb;
	int			count;
	ndmp9_data_state	ds;
	char *estb;

	ndmalogf (sess, 0, 3, "Monitoring backup");

	for (count = 0; count < 10; count++) {
		ndmca_mon_wait_for_something (sess, count <= 1 ? 30 : 10);
		if (ndmca_monitor_get_states(sess) < 0)
		    break;

#if 0
		if (count > 2)
			ndmca_mon_show_states(sess);
#endif

		ds = ca->data_state.state;

		estb = ndmca_data_est(ca);

		ndmalogf (sess, 0, 1,
			  "DATA: bytes %lldKB%s",
			  ca->data_state.bytes_processed/1024LL,
			  estb ? estb : "");

		ca->job.bytes_written = ca->data_state.bytes_processed;

		if (ds == NDMP9_DATA_STATE_ACTIVE) {
			count = 0;
			continue;
		}

		/*
		 * If DATA has halted, the show is over.
		 */
		if (ds == NDMP9_DATA_STATE_HALTED) {
			ndmalogf (sess, 0, 2, "Operation done, cleaning up");

			ndmca_monitor_get_post_backup_env (sess);

			return 0;
		}
	}

	ndmalogf (sess, 0, 0, "Operation monitoring mishandled, cancelling");
	return -1;
}
Exemplo n.º 13
0
int
ndmca_monitor_startup (struct ndm_session *sess)
{
	struct ndm_control_agent *ca = sess->control_acb;
	ndmp9_data_state	ds;
	ndmp9_mover_state	ms;
	int			count;

	ndmalogf (sess, 0, 3, "Waiting for operation to start");

	if (ca->job.tape_tcp)
		return 0;

	for (count = 0; count < 10; count++) {
		if (ndmca_monitor_get_states (sess) < 0)
		    break;

		ds = ca->data_state.state;
		if (!ca->job.tape_tcp)
			ms = ca->mover_state.state;
		else
			ms = NDMP9_MOVER_STATE_ACTIVE;

		if (ds == NDMP9_DATA_STATE_ACTIVE
		 && ms == NDMP9_MOVER_STATE_ACTIVE) {
			ndmalogf (sess, 0, 1, "Operation started");
			return 0;
		}

		if (ds == NDMP9_DATA_STATE_HALTED
		    && ms == NDMP9_MOVER_STATE_HALTED) {
			/* operation finished immediately */
			return 0;
		}

		if (ds != NDMP9_DATA_STATE_IDLE
		 && ms != NDMP9_MOVER_STATE_IDLE
		 && ms != NDMP9_MOVER_STATE_LISTEN) {
			ndmalogf (sess, 0, 1,
				  "Operation started in unusual fashion");
			return 0;
		}

		ndmca_mon_wait_for_something (sess, 2);
	}

	ndmalogf (sess, 0, 0, "Operation failed to start");
	return -1;
}
Exemplo n.º 14
0
static ndmp9_error
scsi_fail_with_sense_code(struct ndm_session *sess,
	    ndmp9_execute_cdb_reply *reply,
	    int status, int sense_key, int asq)
{
	unsigned char ext_sense[] = {
		0x72, /* current errors */
		sense_key & SCSI_SENSE_SENSE_KEY_MASK,
		(asq >> 8) & 0xff,
		(asq     ) & 0xff,
		0,
		0,
		0,
		0 };

	ndmalogf(sess, 0, 3, "sending failure; status=0x%02x sense_key=0x%02x asq=0x%04x",
		    status, sense_key, asq);

	reply->status = status;
	reply->ext_sense.ext_sense_len = sizeof(ext_sense);
	reply->ext_sense.ext_sense_val = NDMOS_API_MALLOC(sizeof(ext_sense));
	NDMOS_API_BCOPY(ext_sense, reply->ext_sense.ext_sense_val, sizeof(ext_sense));

	return NDMP9_NO_ERR;
}
Exemplo n.º 15
0
/*
 * finish a test phase (part of a series)
 */
void ndmca_test_done_phase(struct ndm_session* sess)
{
  struct ndm_control_agent* ca = sess->control_acb;
  char* status;
  int had_active = (sess->control_acb->active_test != 0);

  /* close previous test if there is one */
  ndmca_test_close(sess);

  if (ca->n_step_fail)
    status = "Failed";
  else if (ca->n_step_warn)
    status = "Almost";
  else if (ca->n_step_pass > 0)
    status = "Passed";
  else
    status = "Whiffed";

  ndmalogf(sess, "TEST", 0, "Test %s %s -- pass=%d warn=%d fail=%d (total %d)",
           ca->test_phase, status, ca->n_step_pass, ca->n_step_warn,
           ca->n_step_fail, ca->n_step_tests);

  ca->total_n_step_pass += ca->n_step_pass;
  ca->total_n_step_warn += ca->n_step_warn;
  ca->total_n_step_fail += ca->n_step_fail;
  ca->total_n_step_tests += ca->n_step_tests;

  /* advance test count if we didn't have an active test so
   * clean up phases have a new test count
   */
  if (!had_active) sess->control_acb->test_step++;
}
Exemplo n.º 16
0
int
ndmca_connect_tape_agent (struct ndm_session *sess)
{
	int		rc;

	if (sess->control_acb.job.tape_agent.conn_type == NDMCONN_TYPE_NONE) {
		rc = ndmca_connect_data_agent (sess);
		if (rc) {
			ndmconn_destruct (sess->plumb.data);
			return rc;
		}
		sess->plumb.tape = sess->plumb.data;
		rc = 0;
	} else {
		rc = ndmca_connect_xxx_agent (sess,
				&sess->plumb.tape,
				"#T",
				&sess->control_acb.job.tape_agent);
		ndmalogf (sess, 0, 7, "ndmca_connect_tape_agent: %d %p", rc, sess->plumb.tape);
	}

	if (rc == 0) {
		if (sess->plumb.tape->conn_type == NDMCONN_TYPE_RESIDENT) {
			sess->tape_acb.protocol_version =
					sess->plumb.tape->protocol_version;
		}
	}

	return rc;
}
Exemplo n.º 17
0
int
ndmca_data_listen (struct ndm_session *sess)
{
	struct ndmconn *	conn = sess->plumb.data;
	struct ndm_control_agent *ca = &sess->control_acb;
	int			rc;

	NDMC_WITH(ndmp9_data_listen, NDMP9VER)
		if (sess->plumb.tape == sess->plumb.data) {
			request->addr_type = NDMP9_ADDR_LOCAL;
		} else {
			request->addr_type = NDMP9_ADDR_TCP;
		}
		rc = NDMC_CALL(conn);
		if (rc) return rc;

		if (request->addr_type
		 != reply->data_connection_addr.addr_type) {
			ndmalogf (sess, 0, 0,
				"DATA_LISTEN addr_type mismatch");
			return -1;
		}

		ca->data_addr = reply->data_connection_addr;
	NDMC_ENDWITH

	return 0;
}
Exemplo n.º 18
0
int
ndmca_tt_wrapper (struct ndm_session *sess,
  int (*func)(struct ndm_session *sess))
{
	int		rc;

	rc = (*func)(sess);

	if (rc != 0) {
		ndmalogf (sess, "Test", 1, "Failure");
	}

	ndmca_test_done_phase (sess);

	/* clean up mess */
	ndmca_test_log_note (sess, 2, "Cleaning up...");

	ndmca_tape_open (sess);	/* Open the tape, OK if already opened */
	ndmca_tape_mtio (sess, NDMP9_MTIO_REW, 1, 0);
	rc = ndmca_tape_close (sess);	/* close, collective error */
	if (rc != 0) {
		ndmca_test_log_note (sess, 0, "Cleaning up failed, quiting");
	} else {
		ndmca_test_log_note (sess, 2, "Cleaning up done");
	}

	return rc;
}
Exemplo n.º 19
0
int
ndmis_tcp_connect (struct ndm_session *sess, struct ndmp9_addr *connect_addr)
{
	struct ndm_image_stream *is = &sess->plumb.image_stream;
	ndmp9_tcp_addr *	tcp_addr=&connect_addr->ndmp9_addr_u.tcp_addr;
	char *			what = "???";
	struct sockaddr		sa;
	int			connect_sock;

	NDMOS_MACRO_SET_SOCKADDR (&sa, tcp_addr->ip_addr, tcp_addr->port);

	what = "socket";
	connect_sock = socket (AF_INET, SOCK_STREAM, 0);
	if (connect_sock < 0)
		goto fail;

	what = "connect";
	if (connect (connect_sock, &sa, sizeof sa) < 0)
		goto fail;


	/* write what we know, ndmis...addrs() will update if possible */
	is->remote.peer_addr = *connect_addr;

	ndmis_tcp_green_light (sess, connect_sock, NDMIS_CONN_CONNECTED);

	return 0;

  fail:
	ndmalogf (sess, 0, 2, "ndmis_tcp_connect(): %s failed", what);
	if (connect_sock >= 0) close (connect_sock);

	return -1;
}
Exemplo n.º 20
0
int
ndmca_media_capture_mover_window (struct ndm_session *sess)
{
	struct ndm_control_agent *ca = sess->control_acb;
	struct ndmlog *		ixlog = &ca->job.index_log;
	struct ndm_job_param *	job = &ca->job;
	struct ndmmedia *	me;
	ndmp9_mover_state	ms = ca->mover_state.state;
	ndmp9_mover_pause_reason pr = ca->mover_state.pause_reason;
	char			buf[100];
	uint64_t		wlen;

	for (me = job->media_tab.head; me; me = me->next) {
		if (me->index == ca->cur_media_ix)
			break;
	}

	if (!me) {
		return -1;
	}

	if (ms == NDMP9_MOVER_STATE_PAUSED) {
		if (pr == NDMP9_MOVER_PAUSE_SEEK) {
			/* end-of-window */
		} else if (pr == NDMP9_MOVER_PAUSE_EOM) {
			me->media_eom = 1;	/* tape full */
		} else if (pr == NDMP9_MOVER_PAUSE_EOF) {
			me->media_eof = 1;
		} else if (pr == NDMP9_MOVER_PAUSE_MEDIA_ERROR) {
			me->media_io_error = 1;
		} else {
			/* what */
		}
	} else if (ms == NDMP9_MOVER_STATE_HALTED) {
		/* if tape_mode == READ, this may not actually be the window */
	/* TODO: should STATE_LISTEN be considered? */
	} else {
		ndmalogf (sess, 0, 1,
			"Warning: capturing offset w/o quiescent mover");
	}

	wlen = ca->mover_state.record_num;
	wlen *= job->record_size;
	wlen -= job->last_w_offset;	/* want the size of this image */

	me->valid_n_bytes = 1;
	me->nb_determined = 1;
	me->n_bytes = wlen;

	/*
	 * Only print the data when a deliver function was defined.
	 */
	if (ixlog->deliver) {
		ndmmedia_pp (me, 0, buf);
		ndmlogf (ixlog, "CM", 0, "%02d %s", ca->cur_media_ix, buf);
	}

	return 0;
}
Exemplo n.º 21
0
void
ndmca_test_log_note (struct ndm_session *sess, int level, char *msg)
{
	ndmalogf (sess, "Test", level, "%s #%d %s",
		sess->control_acb.test_phase,
		sess->control_acb.test_step,
		msg);
}
Exemplo n.º 22
0
/*
 * close or end a test if not already closed
 */
void
ndmca_test_close (struct ndm_session *sess)
{
    if (sess->control_acb.active_test != 0) {
	/* count test */
	sess->control_acb.n_step_tests++;

	/* display results */
	if (sess->control_acb.active_test_failed) {
	    ndmalogf (sess, "Test", 1,
		      "%s #%d -- Failed %s %s",
		      sess->control_acb.test_phase,
		      sess->control_acb.test_step,
		      sess->control_acb.active_test,
		      sess->control_acb.active_test_failed);
	    sess->control_acb.n_step_fail++;
	    exit(1);
	} else if (sess->control_acb.active_test_warned) {
	    ndmalogf (sess, "Test", 1,
		      "%s #%d -- Almost %s %s",
		      sess->control_acb.test_phase,
		      sess->control_acb.test_step,
		      sess->control_acb.active_test,
		      sess->control_acb.active_test_warned);
	    sess->control_acb.n_step_warn++;
	    exit(1);
	} else {
	    ndmalogf (sess, "Test", 2,
		      "%s #%d -- Passed %s",
		      sess->control_acb.test_phase,
		      sess->control_acb.test_step,
		      sess->control_acb.active_test);
	    sess->control_acb.n_step_pass++;
	}

	/* clear flags */
	sess->control_acb.active_test = (char *)0;
	sess->control_acb.active_test_failed = (char *)0;
	sess->control_acb.active_test_warned = (char *)0;

	/* advance test count */
	sess->control_acb.test_step++;

    }
}
Exemplo n.º 23
0
int
ndmca_mon_wait_for_something (struct ndm_session *sess, int max_delay_secs)
{
	struct ndm_control_agent *ca = sess->control_acb;
	int			delta, notices;
	int			time_ref = time(0) + max_delay_secs;

	ndmalogf (sess, 0, 5, "mon_wait_for_something() entered");

	for (;;) {
		delta = time_ref - time(0);
		if (delta <= 0)
			break;

		notices = 0;
		if (ca->pending_notify_data_read) {
			/* leave visible */
			notices++;
		}
		if (ca->pending_notify_data_halted) {
			/* just used to "wake up" */
			ca->pending_notify_data_halted = 0;
			notices++;
		}
		if (ca->pending_notify_mover_paused) {
			/* leave visible */
			notices++;
		}
		if (ca->pending_notify_mover_halted) {
			/* just used to "wake up" */
			ca->pending_notify_mover_halted = 0;
			notices++;
		}

		ndma_session_quantum (sess, notices ? 0 : delta);

		if (notices)
			break;
	}

	ndmalogf (sess, 0, 5, "mon_wait_for_something() happened, resid=%d",
			delta);

	return 0;
}
Exemplo n.º 24
0
int
ndmca_op_test_data (struct ndm_session *sess)
{
	struct ndm_control_agent *ca = sess->control_acb;
	struct ndmconn *	conn;
	int			(*save_call) (struct ndmconn *conn,
						struct ndmp_xa_buf *xa);
	int			rc;

	rc = ndmca_connect_data_agent(sess);
	if (rc) {
		ndmconn_destruct (sess->plumb.data);
		return rc;
	}

	conn = sess->plumb.data;
	save_call = conn->call;
	conn->call = ndma_call_no_tattle;

	/* perform query to find out about TCP and LOCAL support */
	rc = ndmca_test_query_conn_types (sess, conn);
	if (rc) return rc;

	rc = ndmca_td_wrapper (sess, ndmca_td_idle);
	if (sess->plumb.data->protocol_version >= 3) {
	    // version 3 and later adds LISTEN
	    rc = ndmca_td_wrapper (sess, ndmca_td_listen);
	}

	ndmca_test_done_series (sess, "test-data");

	ca = sess->control_acb;
	if (ca->has_tcp_addr && ca->has_local_addr) {
	    ndmalogf (sess, "TEST", 0, "LOCAL and TCP addressing tested.");
	} else if (ca->has_tcp_addr) {
	    ndmalogf (sess, "TEST", 0, "TCP addressing ONLY tested.");
	} else if (ca->has_local_addr) {
	    ndmalogf (sess, "TEST", 0, "LOCAL addressing ONLY tested.");
	} else {
	    ndmalogf (sess, "TEST", 0, "Neither TCP or LOCAL addressing tested.");
	}

	return 0;
}
Exemplo n.º 25
0
/*
 * start a test phase (part of a series)
 */
void ndmca_test_phase(struct ndm_session* sess, char* test_phase, char* desc)
{
  ndmalogf(sess, "TEST", 0, "Test %s -- %s", test_phase, desc);

  sess->control_acb->test_phase = test_phase;
  sess->control_acb->test_step = 1;
  sess->control_acb->n_step_pass = 0;
  sess->control_acb->n_step_fail = 0;
  sess->control_acb->n_step_warn = 0;
  sess->control_acb->n_step_tests = 0;
}
Exemplo n.º 26
0
int
ndmca_media_close_tape (struct ndm_session *sess)
{
	struct ndm_control_agent *ca = sess->control_acb;
	int			rc;

	ndmalogf (sess, 0, 2, "Closing tape drive %s", ca->job.tape_device);

	rc = ndmca_tape_close (sess);

	return 0;
}
Exemplo n.º 27
0
int
ndmca_media_mtio_tape (struct ndm_session *sess,
  ndmp9_tape_mtio_op op, uint32_t count, uint32_t *resid)
{
	int			rc;

	if (op == NDMP9_MTIO_REW) {
		ndmalogf (sess, 0, 1, "Commanding tape drive to rewind");
	} else if (op == NDMP9_MTIO_OFF) {
		ndmalogf (sess, 0, 1,
			"Commanding tape drive to eject (go offline)");
	} else {
		ndmalogf (sess, 0, 2, "Commanding tape drive to %s %d times",
			ndmp9_tape_mtio_op_to_str (op),
			count);
	}

	rc = ndmca_tape_mtio (sess, op, count, resid);

	return rc;
}
Exemplo n.º 28
0
/*
 * TODO: It would be nice that if a media entry has a problem
 *       during load_current() to just skip over it and proceed
 *       to the next one. It will be really annoying to have a
 *       long running backup terminate because of a write-protect
 *       or label-check error when there are perfectly good
 *       tapes available.
 */
int
ndmca_media_load_next (struct ndm_session *sess)
{
	int		n_media =  sess->control_acb->job.media_tab.n_media;

	if (sess->control_acb->cur_media_ix >= n_media) {
		ndmalogf (sess, 0, 0, "Out of tapes");
		return -1;
	}
	sess->control_acb->cur_media_ix++;
	return ndmca_media_load_current (sess);
}
Exemplo n.º 29
0
int
ndmis_tcp_get_local_and_peer_addrs (struct ndm_session *sess)
{
	struct ndm_image_stream *is = &sess->plumb.image_stream;
	char *			what = "???";
	struct sockaddr		sa;
	struct sockaddr_in *	sin = (struct sockaddr_in *) &sa;
	ndmp9_tcp_addr *	tcp_addr;
	socklen_t		len;
	int			rc = 0;

	len = sizeof sa;
	what = "getpeername";
	if (getpeername (is->chan.fd, &sa, &len) < 0) {
		/* this is best effort */
		ndmalogf (sess, 0, 2, "ndmis_tcp..._addrs(): %s failed", what);
		rc = -1;
	} else {
		is->remote.peer_addr.addr_type = NDMP9_ADDR_TCP;
		tcp_addr = &is->remote.peer_addr.ndmp9_addr_u.tcp_addr;
		tcp_addr->ip_addr = ntohl (sin->sin_addr.s_addr);
		tcp_addr->port = ntohs (sin->sin_port);
	}

	len = sizeof sa;
	what = "getsockname";
	if (getsockname (is->chan.fd, &sa, &len) < 0) {
		/* this is best effort */
		ndmalogf (sess, 0, 2, "ndmis_tcp..._addrs(): %s failed", what);
		rc = -1;
	} else {
		is->remote.local_addr.addr_type = NDMP9_ADDR_TCP;
		tcp_addr = &is->remote.peer_addr.ndmp9_addr_u.tcp_addr;
		tcp_addr->ip_addr = ntohl (sin->sin_addr.s_addr);
		tcp_addr->port = ntohs (sin->sin_port);
	}

	return rc;
}
Exemplo n.º 30
0
void ndmca_test_log_step(struct ndm_session* sess, int level, char* msg)
{
  int had_active = (sess->control_acb->active_test != 0);

  ndmalogf(sess, "Test", level, "%s #%d -- %s", sess->control_acb->test_phase,
           sess->control_acb->test_step, msg);

  /* in case we have a open test -- close it */
  ndmca_test_close(sess);

  /* advance test count if we didn't have an active test */
  if (!had_active) sess->control_acb->test_step++;
}