X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Fstored%2Ffd_cmds.c;h=6e491361a784e7e2770269a0986526b674dc0e6c;hb=b22b260eaa7fb9f122523fff0e324dca5904b97f;hp=482cc68b47f38e4943b539d691e7990d4ddac373;hpb=eecae5bbee34f428e4909d90fd1d01365c404515;p=bacula%2Fbacula diff --git a/bacula/src/stored/fd_cmds.c b/bacula/src/stored/fd_cmds.c index 482cc68b47..6e491361a7 100644 --- a/bacula/src/stored/fd_cmds.c +++ b/bacula/src/stored/fd_cmds.c @@ -6,29 +6,24 @@ * We get here because the Director has initiated a Job with * the Storage daemon, then done the same with the File daemon, * then when the Storage daemon receives a proper connection from - * the File daemon, control is passed here to handle the + * the File daemon, control is passed here to handle the * subsequent File daemon commands. * * Version $Id$ - * + * */ /* - Copyright (C) 2000-2004 Kern Sibbald and John Walker + Copyright (C) 2000-2006 Kern Sibbald This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. + modify it under the terms of the GNU General Public License + version 2 as amended with additional clauses defined in the + file LICENSE in the main source directory. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + the file LICENSE for additional details. */ @@ -53,16 +48,17 @@ 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 bootstrap_cmd(JCR *jcr); +bool get_bootstrap_file(JCR *jcr, BSOCK *bs); struct s_cmds { const char *cmd; bool (*func)(JCR *jcr); }; -/* +/* * The following are the recognized commands from the File daemon */ static struct s_cmds fd_cmds[] = { @@ -74,7 +70,7 @@ static struct s_cmds fd_cmds[] = { {"read data", read_data_cmd}, {"read close", read_close_session}, {"bootstrap", bootstrap_cmd}, - {NULL, NULL} /* list terminator */ + {NULL, NULL} /* list terminator */ }; /* Commands from the File daemon that require additional scanning */ @@ -93,7 +89,7 @@ static char ERROR_bootstrap[] = "3904 Error bootstrap\n"; /* Information sent to the Director */ static char Job_start[] = "3010 Job %s start\n"; -static char Job_end[] = +char Job_end[] = "3099 Job %s end JobStatus=%d JobFiles=%d JobBytes=%s\n"; /* @@ -116,51 +112,52 @@ void run_job(JCR *jcr) fd->jcr = jcr; dir->jcr = jcr; Dmsg1(120, "Start run Job=%s\n", jcr->Job); - bnet_fsend(dir, Job_start, jcr->Job); + bnet_fsend(dir, Job_start, jcr->Job); jcr->start_time = time(NULL); jcr->run_time = jcr->start_time; set_jcr_job_status(jcr, JS_Running); - dir_send_job_status(jcr); /* update director */ + dir_send_job_status(jcr); /* update director */ for (quit=false; !quit;) { int stat; /* Read command coming from the File daemon */ stat = bnet_recv(fd); - if (is_bnet_stop(fd)) { /* hardeof or error */ - break; /* connection terminated */ + if (is_bnet_stop(fd)) { /* hardeof or error */ + break; /* connection terminated */ } if (stat <= 0) { - continue; /* ignore signals and zero length msgs */ + continue; /* ignore signals and zero length msgs */ } Dmsg1(110, "msg); found = false; for (i=0; fd_cmds[i].cmd; i++) { - if (strncmp(fd_cmds[i].cmd, fd->msg, strlen(fd_cmds[i].cmd)) == 0) { - found = true; /* indicate command found */ - if (!fd_cmds[i].func(jcr)) { /* do command */ - set_jcr_job_status(jcr, JS_ErrorTerminated); - quit = true; - } - break; - } + if (strncmp(fd_cmds[i].cmd, fd->msg, strlen(fd_cmds[i].cmd)) == 0) { + found = true; /* indicate command found */ + if (!fd_cmds[i].func(jcr) || job_canceled(jcr)) { /* do command */ + set_jcr_job_status(jcr, JS_ErrorTerminated); + quit = true; + } + break; + } } - if (!found) { /* command not found */ + if (!found) { /* command not found */ Dmsg1(110, "msg); - bnet_fsend(fd, ferrmsg); - break; + bnet_fsend(fd, ferrmsg); + break; } } bnet_sig(fd, BNET_TERMINATE); /* signal to FD job is done */ jcr->end_time = time(NULL); - dequeue_messages(jcr); /* send any queued messages */ + dequeue_messages(jcr); /* send any queued messages */ set_jcr_job_status(jcr, JS_Terminated); + generate_daemon_event(jcr, "JobEnd"); bnet_fsend(dir, Job_end, jcr->Job, jcr->JobStatus, jcr->JobFiles, edit_uint64(jcr->JobBytes, ec1)); - bnet_sig(dir, BNET_EOD); /* send EOD to Director daemon */ + bnet_sig(dir, BNET_EOD); /* send EOD to Director daemon */ return; } - + /* * Append Data command * Open Data Channel and receive Data for archiving @@ -175,10 +172,10 @@ static bool append_data_cmd(JCR *jcr) Dmsg1(110, "msg); jcr->JobType = JT_BACKUP; if (do_append_data(jcr)) { - return bnet_fsend(fd, OK_append); + return bnet_fsend(fd, OK_append); } else { - bnet_suppress_error_messages(fd, 1); /* ignore errors at this point */ - bnet_fsend(fd, ERROR_append); + bnet_suppress_error_messages(fd, 1); /* ignore errors at this point */ + bnet_fsend(fd, ERROR_append); } } else { bnet_fsend(fd, NOT_opened); @@ -200,7 +197,7 @@ static bool append_end_session(JCR *jcr) } -/* +/* * Append Open session command * */ @@ -214,8 +211,7 @@ static bool append_open_session(JCR *jcr) return false; } - Dmsg1(110, "Append open session: %s\n", dev_name(jcr->device->dev)); - jcr->session_opened = TRUE; + jcr->session_opened = true; /* Send "Ticket" to File Daemon */ bnet_fsend(fd, OK_open, jcr->VolSessionId); @@ -226,8 +222,8 @@ static bool append_open_session(JCR *jcr) /* * Append Close session command - * Close the append session and send back Statistics - * (need to fix statistics) + * Close the append session and send back Statistics + * (need to fix statistics) */ static bool append_close_session(JCR *jcr) { @@ -242,9 +238,7 @@ static bool append_close_session(JCR *jcr) bnet_fsend(fd, OK_close, jcr->JobStatus); Dmsg1(120, ">filed: %s", fd->msg); - bnet_sig(fd, BNET_EOD); /* send EOD to File daemon */ - - Dmsg1(110, "Append close session: %s\n", dev_name(jcr->device->dev)); + bnet_sig(fd, BNET_EOD); /* send EOD to File daemon */ jcr->session_opened = false; return true; @@ -252,7 +246,7 @@ static bool append_close_session(JCR *jcr) /* * Read Data command - * Open Data Channel, read the data from + * Open Data Channel, read the data from * the archive device and send to File * daemon. */ @@ -270,7 +264,7 @@ static bool read_data_cmd(JCR *jcr) } } -/* +/* * Read Open session command * * We need to scan for the parameters of the job @@ -286,24 +280,22 @@ static bool read_open_session(JCR *jcr) return false; } - if (sscanf(fd->msg, read_open, jcr->dcr->VolumeName, &jcr->read_VolSessionId, - &jcr->read_VolSessionTime, &jcr->read_StartFile, &jcr->read_EndFile, - &jcr->read_StartBlock, &jcr->read_EndBlock) == 7) { + if (sscanf(fd->msg, read_open, jcr->read_dcr->VolumeName, &jcr->read_VolSessionId, + &jcr->read_VolSessionTime, &jcr->read_StartFile, &jcr->read_EndFile, + &jcr->read_StartBlock, &jcr->read_EndBlock) == 7) { if (jcr->session_opened) { - bnet_fsend(fd, NOT_opened); - return false; + bnet_fsend(fd, NOT_opened); + return false; } Dmsg4(100, "read_open_session got: JobId=%d Vol=%s VolSessId=%ld VolSessT=%ld\n", - jcr->JobId, jcr->dcr->VolumeName, jcr->read_VolSessionId, - jcr->read_VolSessionTime); + jcr->JobId, jcr->read_dcr->VolumeName, jcr->read_VolSessionId, + jcr->read_VolSessionTime); Dmsg4(100, " StartF=%ld EndF=%ld StartB=%ld EndB=%ld\n", - jcr->read_StartFile, jcr->read_EndFile, jcr->read_StartBlock, - jcr->read_EndBlock); + jcr->read_StartFile, jcr->read_EndFile, jcr->read_StartBlock, + jcr->read_EndBlock); } - Dmsg1(110, "Read open session: %s\n", dev_name(jcr->device->dev)); - - jcr->session_opened = TRUE; + jcr->session_opened = true; jcr->JobType = JT_RESTORE; /* Send "Ticket" to File Daemon */ @@ -313,9 +305,16 @@ static bool read_open_session(JCR *jcr) return true; } -bool bootstrap_cmd(JCR *jcr) +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) { - BSOCK *fd = jcr->file_bsock; POOLMEM *fname = get_pool_memory(PM_FNAME); FILE *bs; bool ok = false; @@ -324,19 +323,22 @@ bool bootstrap_cmd(JCR *jcr) unlink(jcr->RestoreBootstrap); free_pool_memory(jcr->RestoreBootstrap); } - Mmsg(fname, "%s/%s.%s.bootstrap", me->working_directory, me->hdr.name, - jcr->Job); + 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+"); /* create file */ + bs = fopen(fname, "a+b"); /* create file */ if (!bs) { Jmsg(jcr, M_FATAL, 0, _("Could not create bootstrap file %s: ERR=%s\n"), - jcr->RestoreBootstrap, strerror(errno)); + jcr->RestoreBootstrap, strerror(errno)); goto bail_out; } - while (bnet_recv(fd) >= 0) { - Dmsg1(400, "storedmsg); - fputs(fd->msg, bs); + while (bnet_recv(sock) >= 0) { + Dmsg1(400, "storedmsg); + fputs(sock->msg, bs); } fclose(bs); jcr->bsr = parse_bsr(jcr, jcr->RestoreBootstrap); @@ -354,16 +356,16 @@ bail_out: free_pool_memory(jcr->RestoreBootstrap); jcr->RestoreBootstrap = NULL; if (!ok) { - bnet_fsend(fd, ERROR_bootstrap); + bnet_fsend(sock, ERROR_bootstrap); return false; } - return bnet_fsend(fd, OK_bootstrap); + return bnet_fsend(sock, OK_bootstrap); } /* * Read Close session command - * Close the read session + * Close the read session */ static bool read_close_session(JCR *jcr) { @@ -378,8 +380,8 @@ static bool read_close_session(JCR *jcr) bnet_fsend(fd, OK_close); Dmsg1(160, ">filed: %s\n", fd->msg); - bnet_sig(fd, BNET_EOD); /* send EOD to File daemon */ - - jcr->session_opened = FALSE; + bnet_sig(fd, BNET_EOD); /* send EOD to File daemon */ + + jcr->session_opened = false; return true; }