Skip to content

Commit

Permalink
ndmp: Loop over BSRs when doing recover of NDMP
Browse files Browse the repository at this point in the history
  • Loading branch information
pstorz authored and Marco van Wieringen committed Dec 17, 2015
1 parent 30139df commit 1f73aa4
Showing 1 changed file with 131 additions and 120 deletions.
251 changes: 131 additions & 120 deletions src/dird/ndmp_dma_restore.c
Expand Up @@ -644,145 +644,156 @@ static inline bool do_ndmp_restore_bootstrap(JCR *jcr)
Dmsg0(50, "Storage daemon connection OK\n");

/*
* Walk each fileindex of the current BSR record. Each different fileindex is
* a seperate NDMP stream.
* Walk over each bsr record
*/
cnt = 0;
for (fileindex = bsr->FileIndex; fileindex; fileindex = fileindex->next) {
for (current_fi = fileindex->findex; current_fi <= fileindex->findex2; current_fi++) {
/*
* See if this is the first Restore NDMP stream or not. For NDMP we can have multiple Backup
* runs as part of the same Job. When we are restoring data from a Native Storage Daemon
* we let it know to expect a next restore session. It will generate a new authorization
* key so we wait for the nextrun_ready conditional variable to be raised by the msg_thread.
*/
if (jcr->store_bsock && cnt > 0) {
jcr->store_bsock->fsend("nextrun");
P(mutex);
pthread_cond_wait(&jcr->nextrun_ready, &mutex);
V(mutex);
}
for (bsr = jcr->bsr; bsr; bsr = bsr->next) {
/*
* Walk each fileindex of the current BSR record. Each different fileindex is
* a separate NDMP stream.
*/
for (fileindex = bsr->FileIndex; fileindex; fileindex = fileindex->next) {
for (current_fi = fileindex->findex; current_fi <= fileindex->findex2; current_fi++) {
/*
* See if this is the first Restore NDMP stream or not. For NDMP we can have multiple Backup
* runs as part of the same Job. When we are restoring data from a Native Storage Daemon
* we let it know to expect a next restore session. It will generate a new authorization
* key so we wait for the nextrun_ready conditional variable to be raised by the msg_thread.
*/
if (jcr->store_bsock && cnt > 0) {
jcr->store_bsock->fsend("nextrun");
P(mutex);
pthread_cond_wait(&jcr->nextrun_ready, &mutex);
V(mutex);
}

/*
* Perform the actual NDMP job.
* Initialize a new NDMP session
*/
memset(&ndmp_sess, 0, sizeof(ndmp_sess));
ndmp_sess.conn_snooping = (me->ndmp_snooping) ? 1 : 0;
ndmp_sess.control_agent_enabled = 1;

ndmp_sess.param = (struct ndm_session_param *)malloc(sizeof(struct ndm_session_param));
memset(ndmp_sess.param, 0, sizeof(struct ndm_session_param));
ndmp_sess.param->log.deliver = ndmp_loghandler;
ndmp_sess.param->log_level = native_to_ndmp_loglevel(NdmpLoglevel, debug_level, nis);
nis->jcr = jcr;
ndmp_sess.param->log.ctx = nis;
ndmp_sess.param->log_tag = bstrdup("DIR-NDMP");
/*
* Perform the actual NDMP job.
* Initialize a new NDMP session
*/
memset(&ndmp_sess, 0, sizeof(ndmp_sess));
ndmp_sess.conn_snooping = (me->ndmp_snooping) ? 1 : 0;
ndmp_sess.control_agent_enabled = 1;

ndmp_sess.param = (struct ndm_session_param *)malloc(sizeof(struct ndm_session_param));
memset(ndmp_sess.param, 0, sizeof(struct ndm_session_param));
ndmp_sess.param->log.deliver = ndmp_loghandler;
ndmp_sess.param->log_level = native_to_ndmp_loglevel(NdmpLoglevel, debug_level, nis);
nis->jcr = jcr;
ndmp_sess.param->log.ctx = nis;
ndmp_sess.param->log_tag = bstrdup("DIR-NDMP");

/*
* Initialize the session structure.
*/
if (ndma_session_initialize(&ndmp_sess)) {
goto cleanup_ndmp;
}
session_initialized = true;
/*
* Initialize the session structure.
*/
if (ndma_session_initialize(&ndmp_sess)) {
goto cleanup_ndmp;
}
session_initialized = true;

/*
* Copy the actual job to perform.
*/
jcr->jr.FileIndex = current_fi;
if (bsr->sessid && bsr->sesstime) {
jcr->jr.VolSessionId = bsr->sessid->sessid;
jcr->jr.VolSessionTime = bsr->sesstime->sesstime;
} else {
Jmsg(jcr, M_FATAL, 0, _("Wrong BSR missing sessid and/or sesstime\n"));
goto cleanup_ndmp;
}
/*
* Copy the actual job to perform.
*/
jcr->jr.FileIndex = current_fi;
if (bsr->sessid && bsr->sesstime) {
jcr->jr.VolSessionId = bsr->sessid->sessid;
jcr->jr.VolSessionTime = bsr->sesstime->sesstime;
} else {
Jmsg(jcr, M_FATAL, 0, _("Wrong BSR missing sessid and/or sesstime\n"));
goto cleanup_ndmp;
}

memcpy(&ndmp_sess.control_acb->job, &ndmp_job, sizeof(struct ndm_job_param));
if (!fill_restore_environment(jcr,
current_fi,
&ndmp_sess.control_acb->job)) {
goto cleanup_ndmp;
}
memcpy(&ndmp_sess.control_acb->job, &ndmp_job, sizeof(struct ndm_job_param));
if (!fill_restore_environment(jcr,
current_fi,
&ndmp_sess.control_acb->job)) {
Jmsg(jcr, M_ERROR, 0, _("ERROR in fill_restore_environment\n"));
goto cleanup_ndmp;
}

ndma_job_auto_adjust(&ndmp_sess.control_acb->job);
if (!ndmp_validate_job(jcr, &ndmp_sess.control_acb->job)) {
goto cleanup_ndmp;
}
ndma_job_auto_adjust(&ndmp_sess.control_acb->job);
if (!ndmp_validate_job(jcr, &ndmp_sess.control_acb->job)) {
Jmsg(jcr, M_ERROR, 0, _("ERROR in ndmp_validate_job\n"));
goto cleanup_ndmp;
}

/*
* Commission the session for a run.
*/
if (ndma_session_commission(&ndmp_sess)) {
goto cleanup_ndmp;
}
/*
* Commission the session for a run.
*/
if (ndma_session_commission(&ndmp_sess)) {
Jmsg(jcr, M_ERROR, 0, _("ERROR in ndma_session_commission\n"));
goto cleanup_ndmp;
}

/*
* Setup the DMA.
*/
if (ndmca_connect_control_agent(&ndmp_sess)) {
goto cleanup_ndmp;
}
/*
* Setup the DMA.
*/
if (ndmca_connect_control_agent(&ndmp_sess)) {
Jmsg(jcr, M_ERROR, 0, _("ERROR in ndmca_connect_control_agent\n"));
goto cleanup_ndmp;
}

ndmp_sess.conn_open = 1;
ndmp_sess.conn_authorized = 1;
ndmp_sess.conn_open = 1;
ndmp_sess.conn_authorized = 1;

/*
* Let the DMA perform its magic.
*/
if (ndmca_control_agent(&ndmp_sess) != 0) {
goto cleanup_ndmp;
}
/*
* Let the DMA perform its magic.
*/
if (ndmca_control_agent(&ndmp_sess) != 0) {
Jmsg(jcr, M_ERROR, 0, _("ERROR in ndmca_control_agent\n"));
goto cleanup_ndmp;
}

/*
* See if there were any errors during the restore.
*/
if (!extract_post_restore_stats(jcr, &ndmp_sess)) {
goto cleanup_ndmp;
}
/*
* See if there were any errors during the restore.
*/
if (!extract_post_restore_stats(jcr, &ndmp_sess)) {
Jmsg(jcr, M_ERROR, 0, _("ERROR in extract_post_restore_stats\n"));
goto cleanup_ndmp;
}

/*
* Reset the NDMP session states.
*/
ndma_session_decommission(&ndmp_sess);
/*
* Reset the NDMP session states.
*/
ndma_session_decommission(&ndmp_sess);

/*
* Cleanup the job after it has run.
*/
ndma_destroy_env_list(&ndmp_sess.control_acb->job.env_tab);
ndma_destroy_env_list(&ndmp_sess.control_acb->job.result_env_tab);
ndma_destroy_nlist(&ndmp_sess.control_acb->job.nlist_tab);
/*
* Cleanup the job after it has run.
*/
ndma_destroy_env_list(&ndmp_sess.control_acb->job.env_tab);
ndma_destroy_env_list(&ndmp_sess.control_acb->job.result_env_tab);
ndma_destroy_nlist(&ndmp_sess.control_acb->job.nlist_tab);

/*
* Release any tape device name allocated.
*/
if (ndmp_sess.control_acb->job.tape_device) {
free(ndmp_sess.control_acb->job.tape_device);
ndmp_sess.control_acb->job.tape_device = NULL;
}
/*
* Release any tape device name allocated.
*/
if (ndmp_sess.control_acb->job.tape_device) {
free(ndmp_sess.control_acb->job.tape_device);
ndmp_sess.control_acb->job.tape_device = NULL;
}

/*
* Destroy the session.
*/
ndma_session_destroy(&ndmp_sess);
/*
* Destroy the session.
*/
ndma_session_destroy(&ndmp_sess);

/*
* Free the param block.
*/
free(ndmp_sess.param->log_tag);
free(ndmp_sess.param);
ndmp_sess.param = NULL;
/*
* Free the param block.
*/
free(ndmp_sess.param->log_tag);
free(ndmp_sess.param);
ndmp_sess.param = NULL;

/*
* Reset the initialized state so we don't try to cleanup again.
*/
session_initialized = false;
/*
* Reset the initialized state so we don't try to cleanup again.
*/
session_initialized = false;

/*
* Keep track that we finished this part of the restore.
*/
cnt++;
/*
* Keep track that we finished this part of the restore.
*/
cnt++;
}
}
}

Expand Down

0 comments on commit 1f73aa4

Please sign in to comment.