Пример #1
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;
}
Пример #2
0
int ndmca_test_load_tape(struct ndm_session* sess)
{
  struct ndm_control_agent* ca = sess->control_acb;
  int rc;

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

  rc = ndmca_op_robot_startup(sess, 1);
  if (rc) return rc;

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

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

  ndmca_tape_close(sess);

  return 0;
}
Пример #3
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;
}
Пример #4
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;
}
Пример #5
0
static void
finalize_impl(GObject *goself)
{
    NDMPConnection *self = NDMP_CONNECTION(goself);

    /* chain up first */
    G_OBJECT_CLASS(parent_class)->finalize(goself);

    g_debug("closing conn#%d", self->connid);

    /* close this connection if necessary */
    if (self->conn) {
	ndmconn_destruct(self->conn);
	self->conn = NULL;
    }

    if (self->log_state) {
	g_free(self->log_state);
	self->log_state = NULL;
    }
}
Пример #6
0
int
ndmca_op_list_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;
    char			labbuf[NDMMEDIA_LABEL_MAX];
    char			buf[200];
    struct ndmmedia *	me;
    int			rc;

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

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

    if (job->media_tab.n_media == 0) {
        if (job->have_robot) {
            rc = ndmca_robot_synthesize_media (sess);
            if (rc) return rc;	/* already tattled */
        } else {
            /*
             * No fixup. Should be done by now.
             * See ndma_job_auto_adjust()
             */
        }
    }

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

    n_media = mtab->n_media;

    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_read_label (sess, labbuf);
        if (rc == 'm' || rc == 'V') {
            strcpy (me->label, labbuf);
            me->valid_label = 1;
            ndmmedia_to_str (me, buf);
            ndmalogf (sess, "ME", 0, "%s", buf);
        } else {
            ndmalogf (sess, 0, 0, "failed label read");
        }
        ndmca_media_unload_current (sess);
    }

    return rc;
}
Пример #7
0
int
ndmca_backreco_startup (struct ndm_session *sess)
{
	struct ndm_control_agent *ca = sess->control_acb;
	int			rc = 0;

	if (!ca->job.tape_tcp)
		rc = ndmca_op_robot_startup (sess, 1);
	if (rc) return rc;

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

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

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

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

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

	ndmca_media_calculate_offsets (sess);

	if (sess->control_acb->swap_connect &&
	    (sess->plumb.tape->protocol_version >= 3)) {
	    if (sess->plumb.tape->protocol_version < 4) {
		rc = ndmca_data_listen (sess);
		if (rc) return rc;

		rc = ndmca_media_set_window_current (sess);
		if (rc) return rc;
	    } else {
		rc = ndmca_media_set_window_current (sess);
		if (rc) return rc;

		rc = ndmca_data_listen (sess);
		if (rc) return rc;
	    }
	} else {
	    if (sess->plumb.tape->protocol_version < 4) {
		rc = ndmca_mover_listen (sess);
		if (rc) return rc;

		rc = ndmca_media_set_window_current (sess);
		if (rc) return rc;
	    } else {
		rc = ndmca_media_set_window_current (sess);
		if (rc) return rc;

		rc = ndmca_mover_listen (sess);
		if (rc) return rc;
	    }
	}

	return 0;
}
Пример #8
0
int
ndma_server_session (struct ndm_session *sess, int control_sock)
{
	struct ndmconn *	conn;
	int			rc;
	struct sockaddr		sa;
	socklen_t		len;

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

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

	len = sizeof sa;
	rc = getpeername (control_sock, &sa, &len);
	if (rc < 0) {
		perror ("getpeername");
	} else {
		char ip_addr[100];
		ndmalogf (sess, 0, 2, "Connection accepted from %s",
			inet_ntop ( AF_INET,
				   &(((struct sockaddr_in *)&sa)->sin_addr),
				   ip_addr, 100));
	}

	len = sizeof sa;
	rc = getsockname (control_sock, &sa, &len);
	if (rc < 0) {
		perror ("getsockname");
	} else {
		char ip_addr[100];
		ndmalogf (sess, 0, 2, "Connection accepted to %s",
			inet_ntop( AF_INET,
				   &((struct sockaddr_in *)&sa)->sin_addr,
				   ip_addr, 100));
	}

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

	ndmos_condition_control_socket (sess, control_sock);

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

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

	sess->plumb.control = conn;

	while (!conn->chan.eof) {
		ndma_session_quantum (sess, 1000);
	}

#if 0
	{
	    char ip_addr[100];
	    ndmalogf (sess, 0, 2, "Connection close %s",
		    inet_ntop( AF_INET,
			       &((struct sockaddr_in *)&sa)->sin_addr,
			       ip_addr, 100));
	}
#endif

	ndmconn_destruct (conn);

	ndma_session_decommission (sess);

	return 0;
}