Example #1
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;
}
Example #2
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);
}
Example #3
0
int
ndmca_media_load_seek (struct ndm_session *sess, uint64_t pos)
{
	struct ndm_control_agent *ca = sess->control_acb;
	struct ndm_job_param *	job = &ca->job;
	int			n_media = job->media_tab.n_media;
	struct ndmmedia *	me;

	for (me = job->media_tab.head; me; me = me->next) {
		if (me->begin_offset <= pos && pos < me->end_offset)
			break;
	}

	if (!me || me->index > n_media) {
		ndmalogf (sess, 0, 0, "Seek to unspecified media");
		return -1;
	}

	ca->cur_media_ix = me->index;
	return ndmca_media_load_current (sess);
}
Example #4
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;
}
Example #5
0
int
ndmca_media_load_first (struct ndm_session *sess)
{
	sess->control_acb->cur_media_ix = 1;
	return ndmca_media_load_current (sess);
}