From 17cdc1cbfa392ebada058b4ff3cacf92e90a6989 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Mon, 18 Jun 2012 14:28:55 +0200 Subject: [PATCH] Back port fixes from BEE to fix Windows bug #1892 --- bacula/src/filed/backup.c | 13 ++++++--- bacula/src/filed/job.c | 56 ++++----------------------------------- bacula/src/jcr.h | 1 + 3 files changed, 15 insertions(+), 55 deletions(-) diff --git a/bacula/src/filed/backup.c b/bacula/src/filed/backup.c index a17e8ceb3f..080e4cf2e9 100644 --- a/bacula/src/filed/backup.c +++ b/bacula/src/filed/backup.c @@ -535,7 +535,7 @@ int save_file(JCR *jcr, FF_PKT *ff_pkt, bool top_level) set_portable_backup(&ff_pkt->bfd); /* disable Win32 BackupRead() */ } - if (ff_pkt->cmd_plugin && !ff_pkt->no_read) { + if (ff_pkt->cmd_plugin) { do_plugin_set = true; /* option and cmd plugin are not compatible together */ @@ -602,7 +602,7 @@ int save_file(JCR *jcr, FF_PKT *ff_pkt, bool top_level) do_read = true; } - if (ff_pkt->cmd_plugin) { + if (ff_pkt->cmd_plugin && !ff_pkt->no_read) { do_read = true; } @@ -1098,12 +1098,16 @@ static int send_data(JCR *jcr, int stream, FF_PKT *ff_pkt, DIGEST *digest, #ifdef HAVE_LZO /** Do compression if turned on */ if (ff_pkt->flags & FO_COMPRESS && ff_pkt->Compress_algo == COMPRESS_LZO1X && jcr->LZO_compress_workset) { + lzo_uint len; /* TODO: See with the latest patch how to handle lzo_uint with 64bit */ + ser_declare; ser_begin(cbuf, sizeof(comp_stream_header)); Dmsg3(400, "cbuf=0x%x rbuf=0x%x len=%u\n", cbuf, rbuf, sd->msglen); - lzores = lzo1x_1_compress((const unsigned char*)rbuf, sd->msglen, cbuf2, &compress_len, jcr->LZO_compress_workset); + lzores = lzo1x_1_compress((const unsigned char*)rbuf, sd->msglen, cbuf2, + &len, jcr->LZO_compress_workset); + compress_len = len; if (lzores == LZO_E_OK && compress_len <= max_compress_len) { /* complete header */ @@ -1536,10 +1540,11 @@ static void close_vss_backup_session(JCR *jcr) Jmsg(jcr, msg_type, 0, _("VSS Writer (BackupComplete): %s\n"), g_pVSSClient->GetWriterInfo(i)); } } + /* Generate Job global writer metadata */ WCHAR *metadata = g_pVSSClient->GetMetadata(); if (metadata) { FF_PKT *ff_pkt = jcr->ff; - ff_pkt->fname = (char *)"job"; + ff_pkt->fname = (char *)"*all*"; /* for all plugins */ ff_pkt->type = FT_RESTORE_FIRST; ff_pkt->LinkFI = 0; ff_pkt->object_name = (char *)"job_metadata.xml"; diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index 61164699df..c59f4cc3cf 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -84,7 +84,6 @@ static int session_cmd(JCR *jcr); static int response(JCR *jcr, BSOCK *sd, char *resp, const char *cmd); static void filed_free_jcr(JCR *jcr); static int open_sd_read_session(JCR *jcr); -static int send_bootstrap_file(JCR *jcr); static int runscript_cmd(JCR *jcr); static int runbefore_cmd(JCR *jcr); static int runafter_cmd(JCR *jcr); @@ -188,7 +187,6 @@ static char OK_close[] = "3000 OK close Status = %d\n"; static char OK_open[] = "3000 OK open ticket = %d\n"; static char OK_data[] = "3000 OK data\n"; static char OK_append[] = "3000 OK append data\n"; -static char OKSDbootstrap[]= "3000 OK bootstrap\n"; /* Commands sent to Storage Daemon */ @@ -765,9 +763,7 @@ static int restore_object_cmd(JCR *jcr) /* we still need to do this to detect a vss restore */ if (strcmp(rop.object_name, "job_metadata.xml") == 0) { Dmsg0(100, "got job metadata\n"); - //free_and_null_pool_memory(jcr->job_metadata); - jcr->job_metadata = rop.object; /* this is like a boolean in the restore case */ - // rop.object = NULL; /* but not this */ + jcr->got_metadata = true; } generate_plugin_event(jcr, bEventRestoreObject, (void *)&rop); @@ -2122,8 +2118,7 @@ static int restore_cmd(JCR *jcr) * No need to enable VSS for restore if we do not have plugin * data to restore */ - enable_vss = jcr->job_metadata != NULL; - jcr->job_metadata = NULL; + enable_vss = jcr->got_metadata; Dmsg2(50, "g_pVSSClient = %p, enable_vss = %d\n", g_pVSSClient, enable_vss); // capture state here, if client is backed up by multiple directors @@ -2274,7 +2269,6 @@ bail_out: dir->fsend(OKstoreend); ret = 1; /* we continue the loop, waiting for next part */ } else { - end_restore_cmd(jcr); ret = 0; /* we stop here */ } @@ -2282,6 +2276,9 @@ bail_out: ret = 0; /* we stop here */ } + if (ret == 0) { + end_restore_cmd(jcr); /* stopping so send bEventEndRestoreJob */ + } return ret; } @@ -2326,10 +2323,6 @@ static int open_sd_read_session(JCR *jcr) return 0; } - if (!send_bootstrap_file(jcr)) { - return 0; - } - /* * Start read of data with Storage daemon */ @@ -2398,42 +2391,3 @@ int response(JCR *jcr, BSOCK *sd, char *resp, const char *cmd) } return 0; } - -static int send_bootstrap_file(JCR *jcr) -{ - FILE *bs; - char buf[2000]; - BSOCK *sd = jcr->store_bsock; - const char *bootstrap = "bootstrap\n"; - int stat = 0; - - Dmsg1(400, "send_bootstrap_file: %s\n", jcr->RestoreBootstrap); - if (!jcr->RestoreBootstrap) { - return 1; - } - bs = fopen(jcr->RestoreBootstrap, "rb"); - if (!bs) { - berrno be; - Jmsg(jcr, M_FATAL, 0, _("Could not open bootstrap file %s: ERR=%s\n"), - jcr->RestoreBootstrap, be.bstrerror()); - jcr->setJobStatus(JS_ErrorTerminated); - goto bail_out; - } - sd->msglen = pm_strcpy(sd->msg, bootstrap); - sd->send(); - while (fgets(buf, sizeof(buf), bs)) { - sd->msglen = Mmsg(sd->msg, "%s", buf); - sd->send(); - } - sd->signal(BNET_EOD); - fclose(bs); - if (!response(jcr, sd, OKSDbootstrap, "Bootstrap")) { - jcr->setJobStatus(JS_ErrorTerminated); - goto bail_out; - } - stat = 1; - -bail_out: - free_bootstrap(jcr); - return stat; -} diff --git a/bacula/src/jcr.h b/bacula/src/jcr.h index 10a40c14dc..3aecc9e75f 100644 --- a/bacula/src/jcr.h +++ b/bacula/src/jcr.h @@ -410,6 +410,7 @@ public: CRYPTO_CTX crypto; /* Crypto ctx */ DIRRES* director; /* Director resource */ bool VSS; /* VSS used by FD */ + bool got_metadata; /* set when found job_metadata */ bool multi_restore; /* Dir can do multiple storage restore */ htable *file_list; /* Previous file list (accurate mode) */ uint64_t base_size; /* compute space saved with base job */ -- 2.39.5