From e367a541343e7b781b48d46d9a430e452dd05735 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Mon, 5 Apr 2010 22:51:30 +0200 Subject: [PATCH] Start RESTORE_OBJECT code --- bacula/src/baconfig.h | 1 + bacula/src/dird/catreq.c | 36 ++++++++++++++++++++++------------- bacula/src/filed/restore.c | 4 ++++ bacula/src/stored/append.c | 16 +++++++++------- bacula/src/stored/mac.c | 7 ++++--- bacula/src/stored/match_bsr.c | 9 +++++---- bacula/src/stored/record.c | 6 ++++-- 7 files changed, 50 insertions(+), 29 deletions(-) diff --git a/bacula/src/baconfig.h b/bacula/src/baconfig.h index cfe2a3c40f..195d688f4d 100644 --- a/bacula/src/baconfig.h +++ b/bacula/src/baconfig.h @@ -242,6 +242,7 @@ void InitWinAPIWrapper(); #define STREAM_ENCRYPTED_MACOS_FORK_DATA 25 /* Encrypted, uncompressed Mac resource fork */ #define STREAM_PLUGIN_NAME 26 /* Plugin "file" string */ #define STREAM_PLUGIN_DATA 27 /* Plugin specific data */ +#define STREAM_RESTORE_OBJECT 28 /* Special restore object */ /** * Additional Stream definitions. Once defined these must NEVER diff --git a/bacula/src/dird/catreq.c b/bacula/src/dird/catreq.c index 5af634c290..1c85ee8cf2 100644 --- a/bacula/src/dird/catreq.c +++ b/bacula/src/dird/catreq.c @@ -383,7 +383,8 @@ static void update_attribute(JCR *jcr, char *msg, int32_t msglen) db_start_transaction(jcr, jcr->db); /* start transaction if not already open */ ar = jcr->ar; - /* Start by scanning directly in the message buffer to get Stream + /* + * Start by scanning directly in the message buffer to get Stream * there may be a cached attr so we cannot yet write into * jcr->attr or jcr->ar */ @@ -395,12 +396,17 @@ static void update_attribute(JCR *jcr, char *msg, int32_t msglen) skip_nonspaces(&p); /* FileAttributes */ p += 1; unser_begin(p, 0); - unser_uint32(VolSessionId); - unser_uint32(VolSessionTime); - unser_int32(FileIndex); - unser_int32(Stream); - unser_uint32(data_len); - p += unser_length(p); + unser_uint32(VolSessionId); /* VolSessionId */ + unser_uint32(VolSessionTime); /* VolSessionTime */ + unser_int32(FileIndex); /* FileIndex */ + unser_int32(Stream); /* Stream */ + unser_uint32(data_len); /* Record length */ + p += unser_length(p); /* Raw record follows */ + + /* + * At this point p points to the raw record, which varies according + * to what kind of a record (Stream) was sent + */ Dmsg1(400, "UpdCat msg=%s\n", msg); Dmsg5(400, "UpdCat VolSessId=%d VolSessT=%d FI=%d Strm=%d data_len=%d\n", @@ -449,6 +455,10 @@ static void update_attribute(JCR *jcr, char *msg, int32_t msglen) Dmsg2(400, "dirdFileIndex != FileIndex) { @@ -516,7 +526,7 @@ void catalog_update(JCR *jcr, BSOCK *bs) if (!jcr->pool->catalog_files) { return; /* user disabled cataloging */ } - if (job_canceled(jcr)) { + if (jcr->is_job_canceled()) { goto bail_out; } if (!jcr->db) { @@ -530,7 +540,7 @@ void catalog_update(JCR *jcr, BSOCK *bs) update_attribute(jcr, bs->msg, bs->msglen); bail_out: - if (job_canceled(jcr)) { + if (jcr->is_job_canceled()) { cancel_storage_daemon_job(jcr); } } @@ -553,7 +563,7 @@ bool despool_attributes_from_file(JCR *jcr, const char *file) Dmsg0(100, "Begin despool_attributes_from_file\n"); - if (job_canceled(jcr) || !jcr->pool->catalog_files || !jcr->db) { + if (jcr->is_job_canceled() || !jcr->pool->catalog_files || !jcr->db) { goto bail_out; /* user disabled cataloging */ } @@ -588,9 +598,9 @@ bool despool_attributes_from_file(JCR *jcr, const char *file) last = size; } } - if (!job_canceled(jcr)) { + if (!jcr->is_job_canceled()) { update_attribute(jcr, msg, msglen); - if (job_canceled(jcr)) { + if (jcr->is_job_canceled()) { goto bail_out; } } @@ -608,7 +618,7 @@ bail_out: fclose(spool_fd); } - if (job_canceled(jcr)) { + if (jcr->is_job_canceled()) { cancel_storage_daemon_job(jcr); } diff --git a/bacula/src/filed/restore.c b/bacula/src/filed/restore.c index 649862df4c..b79146ee07 100644 --- a/bacula/src/filed/restore.c +++ b/bacula/src/filed/restore.c @@ -760,6 +760,10 @@ void do_restore(JCR *jcr) plugin_name_stream(jcr, sd->msg); break; + case STREAM_RESTORE_OBJECT: + close_previous_stream(rctx); + break; + default: close_previous_stream(rctx); Jmsg(jcr, M_ERROR, 0, _("Unknown stream=%d ignored. This shouldn't happen!\n"), diff --git a/bacula/src/stored/append.c b/bacula/src/stored/append.c index 0623426503..9ad04b60c3 100644 --- a/bacula/src/stored/append.c +++ b/bacula/src/stored/append.c @@ -139,7 +139,7 @@ bool do_append_data(JCR *jcr) */ dcr->VolFirstIndex = dcr->VolLastIndex = 0; jcr->run_time = time(NULL); /* start counting time for rates */ - for (last_file_index = 0; ok && !job_canceled(jcr); ) { + for (last_file_index = 0; ok && !jcr->is_job_canceled(); ) { /* Read Stream header from the File daemon. * The stream header consists of the following: @@ -180,7 +180,7 @@ bool do_append_data(JCR *jcr) /* Read data stream from the File daemon. * The data stream is just raw bytes */ - while ((n=bget_msg(fd)) > 0 && !job_canceled(jcr)) { + while ((n=bget_msg(fd)) > 0 && !jcr->is_job_canceled()) { rec.VolSessionId = jcr->VolSessionId; rec.VolSessionTime = jcr->VolSessionTime; rec.FileIndex = file_index; @@ -213,7 +213,9 @@ bool do_append_data(JCR *jcr) stream_to_ascii(buf2, rec.Stream, rec.FileIndex), rec.data_len); /* Send attributes and digest to Director for Catalog */ - if (stream == STREAM_UNIX_ATTRIBUTES || stream == STREAM_UNIX_ATTRIBUTES_EX || + if (stream == STREAM_UNIX_ATTRIBUTES || + stream == STREAM_UNIX_ATTRIBUTES_EX || + stream == STREAM_RESTORE_OBJECT || crypto_digest_stream_type(stream) != CRYPTO_DIGEST_NONE) { if (!jcr->no_attributes) { BSOCK *dir = jcr->dir_bsock; @@ -236,7 +238,7 @@ bool do_append_data(JCR *jcr) Dmsg1(650, "End read loop with FD. Stat=%d\n", n); if (fd->is_error()) { - if (!job_canceled(jcr)) { + if (!jcr->is_job_canceled()) { Dmsg1(350, "Network read error from FD. ERR=%s\n", fd->bstrerror()); Jmsg1(jcr, M_FATAL, 0, _("Network error reading from FD. ERR=%s\n"), fd->bstrerror()); @@ -281,7 +283,7 @@ bool do_append_data(JCR *jcr) if (ok || dev->can_write()) { if (!write_session_label(dcr, EOS_LABEL)) { /* Print only if ok and not cancelled to avoid spurious messages */ - if (ok && !job_canceled(jcr)) { + if (ok && !jcr->is_job_canceled()) { Jmsg1(jcr, M_FATAL, 0, _("Error writing end session label. ERR=%s\n"), dev->bstrerror()); } @@ -296,7 +298,7 @@ bool do_append_data(JCR *jcr) /* Flush out final partial block of this session */ if (!write_block_to_device(dcr)) { /* Print only if ok and not cancelled to avoid spurious messages */ - if (ok && !job_canceled(jcr)) { + if (ok && !jcr->is_job_canceled()) { Jmsg2(jcr, M_FATAL, 0, _("Fatal append error on device %s: ERR=%s\n"), dev->print_name(), dev->bstrerror()); Dmsg0(100, _("Set ok=FALSE after write_block_to_device.\n")); @@ -328,7 +330,7 @@ bool do_append_data(JCR *jcr) */ release_device(dcr); - if (!ok || job_canceled(jcr)) { + if (!ok || jcr->is_job_canceled()) { discard_attribute_spool(jcr); } else { commit_attribute_spool(jcr); diff --git a/bacula/src/stored/mac.c b/bacula/src/stored/mac.c index 6599466477..88a9aa9147 100644 --- a/bacula/src/stored/mac.c +++ b/bacula/src/stored/mac.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2006-2009 Free Software Foundation Europe e.V. + Copyright (C) 2006-2010 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -31,7 +31,6 @@ * * Kern Sibbald, January MMVI * - * Version $Id$ */ #include "bacula.h" @@ -265,7 +264,9 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec) /* Send attributes and digest to Director for Catalog */ stream = rec->Stream; - if (stream == STREAM_UNIX_ATTRIBUTES || stream == STREAM_UNIX_ATTRIBUTES_EX || + if (stream == STREAM_UNIX_ATTRIBUTES || + stream == STREAM_UNIX_ATTRIBUTES_EX || + stream == STREAM_RESTORE_OBJECT || crypto_digest_stream_type(stream) != CRYPTO_DIGEST_NONE) { if (!jcr->no_attributes) { BSOCK *dir = jcr->dir_bsock; diff --git a/bacula/src/stored/match_bsr.c b/bacula/src/stored/match_bsr.c index 88ec25d15c..769c8f3a5d 100644 --- a/bacula/src/stored/match_bsr.c +++ b/bacula/src/stored/match_bsr.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2002-2008 Free Software Foundation Europe e.V. + Copyright (C) 2002-2010 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -31,7 +31,6 @@ * * Kern Sibbald, June MMII * - * Version $Id$ */ /* @@ -145,10 +144,12 @@ static int match_fileregex(BSR *bsr, DEV_RECORD *rec, JCR *jcr) if (bsr->fileregex_re == NULL) return 1; - if (bsr->attr == NULL) + if (bsr->attr == NULL) { bsr->attr = new_attr(jcr); + } - /* The code breaks if the first record associated with a file is + /* + * The code breaks if the first record associated with a file is * not of this type */ if (rec->Stream == STREAM_UNIX_ATTRIBUTES || diff --git a/bacula/src/stored/record.c b/bacula/src/stored/record.c index 2fcdd22b00..3ac2fef9bd 100644 --- a/bacula/src/stored/record.c +++ b/bacula/src/stored/record.c @@ -32,8 +32,6 @@ * Kern Sibbald, April MMI * added BB02 format October MMII * - * Version $Id$ - * */ @@ -102,6 +100,8 @@ const char *stream_to_ascii(char *buf, int stream, int fi) return "UATTR"; case STREAM_FILE_DATA: return "DATA"; + case STREAM_RESTORE_OBJECT: + return "RESTORE_OBJECT"; case STREAM_WIN32_DATA: return "WIN32-DATA"; case STREAM_WIN32_GZIP_DATA: @@ -150,6 +150,8 @@ const char *stream_to_ascii(char *buf, int stream, int fi) return "contUATTR"; case -STREAM_FILE_DATA: return "contDATA"; + case -STREAM_RESTORE_OBJECT: + return "contRESTORE_OBJECT"; case -STREAM_WIN32_DATA: return "contWIN32-DATA"; case -STREAM_WIN32_GZIP_DATA: -- 2.39.5