From: Kern Sibbald Date: Tue, 14 Jul 2009 13:46:39 +0000 (+0000) Subject: More cleanup of bootstrap X-Git-Tag: Release-3.0.2~83 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8166201d1ef25119a23de6a75d1c774a9da66850;p=bacula%2Fbacula More cleanup of bootstrap git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@8983 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index c91f2135fa..3c67b2ed08 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -118,7 +118,7 @@ static struct s_cmds cmds[] = { {".status", qstatus_cmd, 1}, {"storage ", storage_cmd, 0}, {"verify", verify_cmd, 0}, - {"bootstrap", bootstrap_cmd, 0}, +// {"bootstrap", bootstrap_cmd, 0}, {"RunBeforeNow", runbeforenow_cmd, 0}, {"RunBeforeJob", runbefore_cmd, 0}, {"RunAfterJob", runafter_cmd, 0}, diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index 524b207629..19374afddf 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -61,6 +61,8 @@ extern bool init_done; static char derrmsg[] = "3900 Invalid command\n"; static char OKsetdebug[] = "3000 OK setdebug=%d\n"; static char invalid_cmd[] = "3997 Invalid command for a Director with Monitor directive enabled.\n"; +static char OK_bootstrap[] = "3000 OK bootstrap\n"; +static char ERROR_bootstrap[] = "3904 Error bootstrap\n"; /* Imported functions */ extern void terminate_child(); @@ -935,6 +937,62 @@ static bool release_cmd(JCR *jcr) return true; } +static pthread_mutex_t bsr_mutex = PTHREAD_MUTEX_INITIALIZER; +static uint32_t bsr_uniq = 0; + +static bool get_bootstrap_file(JCR *jcr, BSOCK *sock) +{ + POOLMEM *fname = get_pool_memory(PM_FNAME); + FILE *bs; + bool ok = false; + + if (jcr->RestoreBootstrap) { + unlink(jcr->RestoreBootstrap); + free_pool_memory(jcr->RestoreBootstrap); + } + P(bsr_mutex); + bsr_uniq++; + Mmsg(fname, "%s/%s.%s.%d.bootstrap", me->working_directory, me->hdr.name, + jcr->Job, bsr_uniq); + V(bsr_mutex); + Dmsg1(400, "bootstrap=%s\n", fname); + jcr->RestoreBootstrap = fname; + bs = fopen(fname, "a+b"); /* create file */ + if (!bs) { + berrno be; + Jmsg(jcr, M_FATAL, 0, _("Could not create bootstrap file %s: ERR=%s\n"), + jcr->RestoreBootstrap, be.bstrerror()); + goto bail_out; + } + Dmsg0(10, "=== Bootstrap file ===\n"); + while (sock->recv() >= 0) { + Dmsg1(10, "%s", sock->msg); + fputs(sock->msg, bs); + } + fclose(bs); + Dmsg0(10, "=== end bootstrap file ===\n"); + jcr->bsr = parse_bsr(jcr, jcr->RestoreBootstrap); + if (!jcr->bsr) { + Jmsg(jcr, M_FATAL, 0, _("Error parsing bootstrap file.\n")); + goto bail_out; + } + if (debug_level >= 10) { + dump_bsr(jcr->bsr, true); + } + /* If we got a bootstrap, we are reading, so create read volume list */ + create_restore_volume_list(jcr); + ok = true; + +bail_out: + unlink(jcr->RestoreBootstrap); + free_pool_memory(jcr->RestoreBootstrap); + jcr->RestoreBootstrap = NULL; + if (!ok) { + sock->fsend(ERROR_bootstrap); + return false; + } + return sock->fsend(OK_bootstrap); +} static bool bootstrap_cmd(JCR *jcr) { diff --git a/bacula/src/stored/fd_cmds.c b/bacula/src/stored/fd_cmds.c index 88223497b6..403957874b 100644 --- a/bacula/src/stored/fd_cmds.c +++ b/bacula/src/stored/fd_cmds.c @@ -61,7 +61,6 @@ static bool append_end_session(JCR *jcr); static bool read_open_session(JCR *jcr); static bool read_data_cmd(JCR *jcr); static bool read_close_session(JCR *jcr); -static bool bootstrap_cmd(JCR *jcr); /* Exported function */ bool get_bootstrap_file(JCR *jcr, BSOCK *bs); @@ -82,7 +81,6 @@ static struct s_cmds fd_cmds[] = { {"read open", read_open_session}, {"read data", read_data_cmd}, {"read close", read_close_session}, - {"bootstrap", bootstrap_cmd}, {NULL, NULL} /* list terminator */ }; @@ -96,8 +94,6 @@ static char OK_end[] = "3000 OK end\n"; static char OK_close[] = "3000 OK close Status = %d\n"; static char OK_open[] = "3000 OK open ticket = %d\n"; static char ERROR_append[] = "3903 Error append data\n"; -static char OK_bootstrap[] = "3000 OK bootstrap\n"; -static char ERROR_bootstrap[] = "3904 Error bootstrap\n"; /* Information sent to the Director */ static char Job_start[] = "3010 Job %s start\n"; @@ -341,69 +337,6 @@ static bool read_open_session(JCR *jcr) return true; } -static bool bootstrap_cmd(JCR *jcr) -{ - return get_bootstrap_file(jcr, jcr->file_bsock); -} - -static pthread_mutex_t bsr_mutex = PTHREAD_MUTEX_INITIALIZER; -static uint32_t bsr_uniq = 0; - -bool get_bootstrap_file(JCR *jcr, BSOCK *sock) -{ - POOLMEM *fname = get_pool_memory(PM_FNAME); - FILE *bs; - bool ok = false; - - if (jcr->RestoreBootstrap) { - unlink(jcr->RestoreBootstrap); - free_pool_memory(jcr->RestoreBootstrap); - } - P(bsr_mutex); - bsr_uniq++; - Mmsg(fname, "%s/%s.%s.%d.bootstrap", me->working_directory, me->hdr.name, - jcr->Job, bsr_uniq); - V(bsr_mutex); - Dmsg1(400, "bootstrap=%s\n", fname); - jcr->RestoreBootstrap = fname; - bs = fopen(fname, "a+b"); /* create file */ - if (!bs) { - berrno be; - Jmsg(jcr, M_FATAL, 0, _("Could not create bootstrap file %s: ERR=%s\n"), - jcr->RestoreBootstrap, be.bstrerror()); - goto bail_out; - } - Dmsg0(10, "=== Bootstrap file ===\n"); - while (sock->recv() >= 0) { - Dmsg1(10, "%s", sock->msg); - fputs(sock->msg, bs); - } - fclose(bs); - Dmsg0(10, "=== end bootstrap file ===\n"); - jcr->bsr = parse_bsr(jcr, jcr->RestoreBootstrap); - if (!jcr->bsr) { - Jmsg(jcr, M_FATAL, 0, _("Error parsing bootstrap file.\n")); - goto bail_out; - } - if (debug_level >= 10) { - dump_bsr(jcr->bsr, true); - } - /* If we got a bootstrap, we are reading, so create read volume list */ - create_restore_volume_list(jcr); - ok = true; - -bail_out: - unlink(jcr->RestoreBootstrap); - free_pool_memory(jcr->RestoreBootstrap); - jcr->RestoreBootstrap = NULL; - if (!ok) { - sock->fsend(ERROR_bootstrap); - return false; - } - return sock->fsend(OK_bootstrap); -} - - /* * Read Close session command * Close the read session diff --git a/bacula/src/stored/protos.h b/bacula/src/stored/protos.h index b511bea0cc..db34f428e0 100644 --- a/bacula/src/stored/protos.h +++ b/bacula/src/stored/protos.h @@ -139,7 +139,6 @@ void *handle_connection_request(void *arg); /* From fd_cmds.c */ void run_job(JCR *jcr); -bool get_bootstrap_file(JCR *jcr, BSOCK *bsock); void do_fd_commands(JCR *jcr); /* From job.c */ diff --git a/bacula/technotes b/bacula/technotes index 975ad18264..37bad750f1 100644 --- a/bacula/technotes +++ b/bacula/technotes @@ -2,6 +2,8 @@ General: +14Jul09 +kes More cleanup of bootstrap 13Jul09 kes Send bootstrap directly from DIR to SD kes Create build scripts for Win64 somewhat equilavent to the Win32 ones.