From 18006082cc6b3a2dfa14205257e6eb76ee1de669 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Wed, 7 Apr 2010 21:26:25 +0200 Subject: [PATCH] Get binary objects working --- bacula/src/baconfig.h | 1 - bacula/src/dird/catreq.c | 4 --- bacula/src/filed/backup.c | 34 +++++++++++++++++++++----- bacula/src/filed/fd_plugins.c | 19 +++++++++++--- bacula/src/filed/fd_plugins.h | 1 + bacula/src/filed/restore.c | 20 ++++----------- bacula/src/findlib/attribs.c | 2 +- bacula/src/findlib/find.h | 1 + bacula/src/lib/attr.c | 31 ++++++++++++++--------- bacula/src/lib/mem_pool.h | 3 +-- bacula/src/lib/protos.h | 2 +- bacula/src/plugins/fd/test-plugin-fd.c | 6 +++-- bacula/src/stored/append.c | 4 +-- bacula/src/stored/bextract.c | 2 +- bacula/src/stored/bls.c | 2 +- bacula/src/stored/bscan.c | 2 +- bacula/src/stored/mac.c | 1 - bacula/src/stored/match_bsr.c | 2 +- bacula/src/stored/record.c | 4 --- bacula/src/stored/record.h | 4 +-- 20 files changed, 83 insertions(+), 62 deletions(-) diff --git a/bacula/src/baconfig.h b/bacula/src/baconfig.h index c9ed17001b..31311507c8 100644 --- a/bacula/src/baconfig.h +++ b/bacula/src/baconfig.h @@ -242,7 +242,6 @@ 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 1c85ee8cf2..573a279520 100644 --- a/bacula/src/dird/catreq.c +++ b/bacula/src/dird/catreq.c @@ -455,10 +455,6 @@ static void update_attribute(JCR *jcr, char *msg, int32_t msglen) Dmsg2(400, "dirdFileIndex != FileIndex) { diff --git a/bacula/src/filed/backup.c b/bacula/src/filed/backup.c index a8303798bf..717ff977a6 100644 --- a/bacula/src/filed/backup.c +++ b/bacula/src/filed/backup.c @@ -528,11 +528,12 @@ int save_file(JCR *jcr, FF_PKT *ff_pkt, bool top_level) (!is_portable_backup(&ff_pkt->bfd) && ff_pkt->type == FT_DIREND)) { do_read = true; } - if (ff_pkt->cmd_plugin) { + + if (ff_pkt->cmd_plugin && ff_pkt->type != FT_RESTORE_FIRST) { do_read = true; } - Dmsg1(400, "do_read=%d\n", do_read); + Dmsg2(000, "type=%d do_read=%d\n", ff_pkt->type, do_read); if (do_read) { btimer_t *tid; @@ -1113,8 +1114,17 @@ bool encode_and_send_attributes(JCR *jcr, FF_PKT *ff_pkt, int &data_stream) encode_stat(attribs, &ff_pkt->statp, ff_pkt->LinkFI, data_stream); /** Now possibly extend the attributes */ - attribsEx = attribsExBuf; - attr_stream = encode_attribsEx(jcr, attribsEx, ff_pkt); + if (ff_pkt->type == FT_RESTORE_FIRST) { + /** + * For restore objects, we return the object in the extended + * attributes. + */ + attribsEx = ff_pkt->object; + attr_stream = STREAM_UNIX_ATTRIBUTES_EX; + } else { + attribsEx = attribsExBuf; + attr_stream = encode_attribsEx(jcr, attribsEx, ff_pkt); + } Dmsg3(300, "File %s\nattribs=%s\nattribsEx=%s\n", ff_pkt->fname, attribs, attribsEx); @@ -1167,8 +1177,20 @@ bool encode_and_send_attributes(JCR *jcr, FF_PKT *ff_pkt, int &data_stream) ff_pkt->type, ff_pkt->link, 0, attribs, 0, 0, attribsEx, 0); break; case FT_RESTORE_FIRST: - attribsEx = ff_pkt->object; /* put object as extended attributes */ - /* Fall through wanted */ + /** + * Note, we edit everything as we do for the default case, but the + * object is tacked on to the end in place of the extended attributes, + * but we do a memcpy so that the object can be a binary object. + */ + Dmsg6(000, "Type=%d DataStream=%d attrStream=%d File=%s\nattribs=%s\nattribsEx=%s", + ff_pkt->type, data_stream, STREAM_UNIX_ATTRIBUTES_EX, + ff_pkt->fname, attribs, ff_pkt->object); + sd->msglen = Mmsg(sd->msg, "%ld %d %s%c%s%c%c", + jcr->JobFiles, ff_pkt->type, ff_pkt->fname, 0, attribs, 0, 0); + sd->msg = check_pool_memory_size(sd->msg, sd->msglen + ff_pkt->object_len + 1); + memcpy(sd->msg + sd->msglen, ff_pkt->object, ff_pkt->object_len); + sd->msglen += ff_pkt->object_len; + stat = sd->send(); default: stat = sd->fsend("%ld %d %s%c%s%c%c%s%c", jcr->JobFiles, ff_pkt->type, ff_pkt->fname, 0, attribs, 0, 0, attribsEx, 0); diff --git a/bacula/src/filed/fd_plugins.c b/bacula/src/filed/fd_plugins.c index beefdef0c6..4f5b7a2e12 100644 --- a/bacula/src/filed/fd_plugins.c +++ b/bacula/src/filed/fd_plugins.c @@ -34,7 +34,7 @@ #include "bacula.h" #include "filed.h" -const int dbglvl = 150; +const int dbglvl = 0; #ifdef HAVE_WIN32 const char *plugin_type = "-fd.dll"; #else @@ -293,11 +293,15 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level) ff_pkt->link = link.c_str(); ff_pkt->type = sp.type; ff_pkt->object = sp.object; + ff_pkt->object_len = sp.object_len; if (sp.type == FT_RESTORE_FIRST) { ff_pkt->LinkFI = sp.index; /* restore object index */ } memcpy(&ff_pkt->statp, &sp.statp, sizeof(ff_pkt->statp)); - Dmsg1(dbglvl, "Save_file: file=%s\n", fname.c_str()); + Dmsg2(dbglvl, "startBackup returned type=%d, fname=%s\n", sp.type, sp.fname); + if (sp.object) { + Dmsg2(dbglvl, "index=%d object=%s\n", sp.index, sp.object); + } save_file(jcr, ff_pkt, true); bRC rc = plug_func(plugin)->endBackupFile(jcr->plugin_ctx); if (rc == bRC_More || rc == bRC_OK) { @@ -493,7 +497,11 @@ int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace) rp.RegexWhere = jcr->RegexWhere; rp.replace = jcr->replace; rp.create_status = CF_ERROR; - Dmsg1(dbglvl, "call plugin createFile=%s\n", rp.ofname); + Dmsg4(dbglvl, "call plugin createFile stream=%d type=%d LinkFI=%d File=%s\n", + rp.stream, rp.type, rp.LinkFI, rp.ofname); + if (rp.attrEx) { + Dmsg1(dbglvl, "attrEx=\"%s\"\n", rp.attrEx); + } rc = plug_func(plugin)->createFile(plugin_ctx, &rp); if (rc != bRC_OK) { Qmsg2(jcr, M_ERROR, 0, _("Plugin createFile call failed. Stat=%d file=%s\n"), @@ -509,6 +517,9 @@ int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace) if (rp.create_status == CF_CREATED) { return rp.create_status; /* yes, no need to bopen */ } + if (rp.type == FT_RESTORE_FIRST) { + return CF_CREATED; + } flags = O_WRONLY | O_CREAT | O_TRUNC | O_BINARY; Dmsg0(dbglvl, "call bopen\n"); @@ -660,7 +671,7 @@ void new_plugins(JCR *jcr) Dmsg0(dbglvl, "plugin list is NULL\n"); return; } - if (jcr->is_job_canceled()) { + if (jcr->is_job_canceled() || jcr->JobId == 0) { return; } diff --git a/bacula/src/filed/fd_plugins.h b/bacula/src/filed/fd_plugins.h index 6858a5e16d..e88d77e549 100644 --- a/bacula/src/filed/fd_plugins.h +++ b/bacula/src/filed/fd_plugins.h @@ -83,6 +83,7 @@ struct save_pkt { bool portable; /* set if data format is portable */ char *cmd; /* command */ char *object; /* restore object data to save */ + int32_t object_len; /* restore object length */ int32_t index; /* restore object index */ int32_t pkt_end; /* end packet sentinel */ }; diff --git a/bacula/src/filed/restore.c b/bacula/src/filed/restore.c index b79146ee07..ff2925aa8a 100644 --- a/bacula/src/filed/restore.c +++ b/bacula/src/filed/restore.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2008 Free Software Foundation Europe e.V. + Copyright (C) 2000-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. @@ -323,20 +323,14 @@ void do_restore(JCR *jcr) /* * Unpack attributes and do sanity check them */ - if (!unpack_attributes_record(jcr, rctx.stream, sd->msg, attr)) { + if (!unpack_attributes_record(jcr, rctx.stream, sd->msg, sd->msglen, attr)) { goto bail_out; } -#ifdef xxx - if (file_index != attr->file_index) { - Jmsg(jcr, M_FATAL, 0, _("Record header file index %ld not equal record index %ld\n"), - file_index, attr->file_index); - Dmsg0(200, "File index error\n"); - goto bail_out; - } -#endif - Dmsg3(200, "File %s\nattrib=%s\nattribsEx=%s\n", attr->fname, + Dmsg3(000, "File %s\nattrib=%s\nattribsEx=%s\n", attr->fname, attr->attr, attr->attrEx); + Dmsg3(000, "=== msglen=%d attrExlen=%d msg=%s\n", sd->msglen, + strlen(attr->attrEx), sd->msg); attr->data_stream = decode_stat(attr->attr, &attr->statp, &attr->LinkFI); @@ -760,10 +754,6 @@ 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/findlib/attribs.c b/bacula/src/findlib/attribs.c index 950bb2ad78..53b60fff82 100644 --- a/bacula/src/findlib/attribs.c +++ b/bacula/src/findlib/attribs.c @@ -71,7 +71,7 @@ int select_data_stream(FF_PKT *ff_pkt) /* This is a plugin special restore object */ if (ff_pkt->type == FT_RESTORE_FIRST) { ff_pkt->flags = 0; - return STREAM_RESTORE_OBJECT; + return STREAM_FILE_DATA; } /** diff --git a/bacula/src/findlib/find.h b/bacula/src/findlib/find.h index 7d2cbb9b25..f0324da3db 100644 --- a/bacula/src/findlib/find.h +++ b/bacula/src/findlib/find.h @@ -196,6 +196,7 @@ struct FF_PKT { struct stat statp; /* stat packet */ int32_t FileIndex; /* FileIndex of this file */ int32_t LinkFI; /* FileIndex of main hard linked file */ + int32_t object_len; /* Object length */ struct f_link *linked; /* Set if this file is hard linked */ int type; /* FT_ type from above */ int ff_errno; /* errno */ diff --git a/bacula/src/lib/attr.c b/bacula/src/lib/attr.c index e2eae5f28c..321895c3a6 100644 --- a/bacula/src/lib/attr.c +++ b/bacula/src/lib/attr.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2003-2007 Free Software Foundation Europe e.V. + Copyright (C) 2003-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. @@ -30,7 +30,6 @@ * * Kern Sibbald, June MMIII (code pulled from filed/restore.c and updated) * - * Version $Id$ */ @@ -58,9 +57,10 @@ void free_attr(ATTR *attr) free(attr); } -int unpack_attributes_record(JCR *jcr, int32_t stream, char *rec, ATTR *attr) +int unpack_attributes_record(JCR *jcr, int32_t stream, char *rec, int32_t reclen, ATTR *attr) { char *p; + int object_len; /* * An Attributes record consists of: * File_index @@ -102,14 +102,23 @@ int unpack_attributes_record(JCR *jcr, int32_t stream, char *rec, ATTR *attr) attr->lname = p; /* set link position */ while (*p++ != 0) /* skip link */ { } - pm_strcpy(attr->attrEx, p); /* copy extended attributes, if any */ - - if (attr->data_stream) { - int64_t val; - while (*p++ != 0) /* skip extended attributes */ - { } - from_base64(&val, p); - attr->data_stream = (int32_t)val; + if (attr->type == FT_RESTORE_FIRST) { + /* We have an object, so do a binary copy */ + object_len = reclen + rec - p; + attr->attrEx = check_pool_memory_size(attr->attrEx, object_len + 1); + memcpy(attr->attrEx, p, object_len); + /* Add a EOS for those who attempt to print the object */ + p = attr->attrEx + object_len; + *p = 0; + } else { + pm_strcpy(attr->attrEx, p); /* copy extended attributes, if any */ + if (attr->data_stream) { + int64_t val; + while (*p++ != 0) /* skip extended attributes */ + { } + from_base64(&val, p); + attr->data_stream = (int32_t)val; + } } Dmsg7(400, "unpack_attr FI=%d Type=%d fname=%s attr=%s lname=%s attrEx=%s ds=%d\n", attr->file_index, attr->type, attr->fname, attr->attr, attr->lname, diff --git a/bacula/src/lib/mem_pool.h b/bacula/src/lib/mem_pool.h index 8926b2f2d3..a4d85468f8 100644 --- a/bacula/src/lib/mem_pool.h +++ b/bacula/src/lib/mem_pool.h @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2008 Free Software Foundation Europe e.V. + Copyright (C) 2000-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. @@ -30,7 +30,6 @@ * * Kern Sibbald, MM * - * Version $Id$ */ #ifndef __MEM_POOL_H_ diff --git a/bacula/src/lib/protos.h b/bacula/src/lib/protos.h index 6e024ea161..48196a0bf4 100644 --- a/bacula/src/lib/protos.h +++ b/bacula/src/lib/protos.h @@ -39,7 +39,7 @@ class JCR; /* attr.c */ ATTR *new_attr(JCR *jcr); void free_attr(ATTR *attr); -int unpack_attributes_record(JCR *jcr, int32_t stream, char *rec, ATTR *attr); +int unpack_attributes_record(JCR *jcr, int32_t stream, char *rec, int32_t reclen, ATTR *attr); void build_attr_output_fnames(JCR *jcr, ATTR *attr); void print_ls_output(JCR *jcr, ATTR *attr); diff --git a/bacula/src/plugins/fd/test-plugin-fd.c b/bacula/src/plugins/fd/test-plugin-fd.c index df36da3b80..2a50927813 100644 --- a/bacula/src/plugins/fd/test-plugin-fd.c +++ b/bacula/src/plugins/fd/test-plugin-fd.c @@ -287,7 +287,8 @@ static bRC startBackupFile(bpContext *ctx, struct save_pkt *sp) sp->statp.st_size = -1; sp->statp.st_blksize = 4096; sp->statp.st_blocks = 1; - sp->object = (char *)"This is test data for the restore object\n"; + sp->object = (char *)"This is test data for the restore object."; + sp->object_len = strlen(sp->object); sp->index = 2; p_ctx->backup = true; printf("test-plugin-fd: startBackupFile\n"); @@ -312,7 +313,8 @@ static bRC endBackupFile(bpContext *ctx) */ static bRC pluginIO(bpContext *ctx, struct io_pkt *io) { - return bRC_OK; + printf("test-plugin-fd: pluginIO\n"); + return bRC_Error; } /* diff --git a/bacula/src/stored/append.c b/bacula/src/stored/append.c index 9ad04b60c3..16062c4bf5 100644 --- a/bacula/src/stored/append.c +++ b/bacula/src/stored/append.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2009 Free Software Foundation Europe e.V. + Copyright (C) 2000-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. @@ -29,7 +29,6 @@ * Append code for Storage daemon * Kern Sibbald, May MM * - * Version $Id$ */ #include "bacula.h" @@ -215,7 +214,6 @@ bool do_append_data(JCR *jcr) /* Send attributes and digest to Director for Catalog */ 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/bextract.c b/bacula/src/stored/bextract.c index f4aa3dbaa6..9ac4ed39b9 100644 --- a/bacula/src/stored/bextract.c +++ b/bacula/src/stored/bextract.c @@ -323,7 +323,7 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec) extract = false; } - if (!unpack_attributes_record(jcr, rec->Stream, rec->data, attr)) { + if (!unpack_attributes_record(jcr, rec->Stream, rec->data, rec->data_len, attr)) { Emsg0(M_ERROR_TERM, 0, _("Cannot continue.\n")); } diff --git a/bacula/src/stored/bls.c b/bacula/src/stored/bls.c index 4a53a64b57..ae2f101129 100644 --- a/bacula/src/stored/bls.c +++ b/bacula/src/stored/bls.c @@ -382,7 +382,7 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec) if (rec->Stream == STREAM_UNIX_ATTRIBUTES || rec->Stream == STREAM_UNIX_ATTRIBUTES_EX) { - if (!unpack_attributes_record(jcr, rec->Stream, rec->data, attr)) { + if (!unpack_attributes_record(jcr, rec->Stream, rec->data, rec->data_len, attr)) { if (!forge_on) { Emsg0(M_ERROR_TERM, 0, _("Cannot continue.\n")); } else { diff --git a/bacula/src/stored/bscan.c b/bacula/src/stored/bscan.c index 3c09d96bf1..619d6e37d6 100644 --- a/bacula/src/stored/bscan.c +++ b/bacula/src/stored/bscan.c @@ -662,7 +662,7 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec) case STREAM_UNIX_ATTRIBUTES: case STREAM_UNIX_ATTRIBUTES_EX: - if (!unpack_attributes_record(bjcr, rec->Stream, rec->data, attr)) { + if (!unpack_attributes_record(bjcr, rec->Stream, rec->data, rec->data_len, attr)) { Emsg0(M_ERROR_TERM, 0, _("Cannot continue.\n")); } diff --git a/bacula/src/stored/mac.c b/bacula/src/stored/mac.c index 88a9aa9147..f58ba6380c 100644 --- a/bacula/src/stored/mac.c +++ b/bacula/src/stored/mac.c @@ -266,7 +266,6 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec) stream = rec->Stream; 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 769c8f3a5d..2ba46e9c52 100644 --- a/bacula/src/stored/match_bsr.c +++ b/bacula/src/stored/match_bsr.c @@ -155,7 +155,7 @@ static int match_fileregex(BSR *bsr, DEV_RECORD *rec, JCR *jcr) if (rec->Stream == STREAM_UNIX_ATTRIBUTES || rec->Stream == STREAM_UNIX_ATTRIBUTES_EX) { bsr->skip_file = false; - if (unpack_attributes_record(jcr, rec->Stream, rec->data, bsr->attr)) { + if (unpack_attributes_record(jcr, rec->Stream, rec->data, rec->data_len, bsr->attr)) { if (regexec(bsr->fileregex_re, bsr->attr->fname, 0, NULL, 0) == 0) { Dmsg2(dbglevel, "Matched pattern, fname=%s FI=%d\n", bsr->attr->fname, rec->FileIndex); diff --git a/bacula/src/stored/record.c b/bacula/src/stored/record.c index 3ac2fef9bd..dd6c7980ae 100644 --- a/bacula/src/stored/record.c +++ b/bacula/src/stored/record.c @@ -100,8 +100,6 @@ 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,8 +148,6 @@ 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: diff --git a/bacula/src/stored/record.h b/bacula/src/stored/record.h index eb3f91f9e2..c9e7bd4dfd 100644 --- a/bacula/src/stored/record.h +++ b/bacula/src/stored/record.h @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2008 Free Software Foundation Europe e.V. + Copyright (C) 2000-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,8 +31,6 @@ * * Kern Sibbald, MM * - * Version $Id$ - * */ -- 2.39.5