From: RadosÅ‚aw Korzeniewski Date: Tue, 23 Mar 2021 15:02:11 +0000 (+0100) Subject: metaplugin: Update debugging logs. X-Git-Tag: Release-11.3.2~653 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f988b84840334f7f6b13cff9e36a43a35954fde;p=thirdparty%2Fbacula.git metaplugin: Update debugging logs. --- diff --git a/bacula/src/plugins/fd/pluginlib/pluginlib.cpp b/bacula/src/plugins/fd/pluginlib/pluginlib.cpp index 9ee2f4603..7d091a77a 100644 --- a/bacula/src/plugins/fd/pluginlib/pluginlib.cpp +++ b/bacula/src/plugins/fd/pluginlib/pluginlib.cpp @@ -616,15 +616,3 @@ bool scan_parameter_str(const char * cmd, const char *prefix, POOL_MEM ¶m) return false; } - -void transcript_bin_data_to_display(char (&buf)[17], const char *data, int len) -{ - for (int a = 0; a < len && a < 16; a++) { - if (isalnum(data[a]) || isspace(data[a])){ - buf[a] = data[a]; - } else { - buf[a] = '.'; - } - buf[a + 1] = 0; - } -} diff --git a/bacula/src/plugins/fd/pluginlib/ptcomm.cpp b/bacula/src/plugins/fd/pluginlib/ptcomm.cpp index b91219f86..010966240 100644 --- a/bacula/src/plugins/fd/pluginlib/ptcomm.cpp +++ b/bacula/src/plugins/fd/pluginlib/ptcomm.cpp @@ -311,7 +311,7 @@ int32_t PTCOMM::recvbackend_header(bpContext *ctx, char cmd) // some packet commands require data header.length[6] = 0; /* end of string */ - DMSG2(ctx, DDEBUG, "RECV: %c %s\n", header.status, header.length); + DMSG2(ctx, DDEBUG, "HEADERRECV: %c %s\n", header.status, header.length); /* check for protocol status */ if (header.status == 'F'){ @@ -436,14 +436,15 @@ int32_t PTCOMM::handle_read_header(bpContext *ctx, char cmd) int32_t PTCOMM::handle_payload(bpContext *ctx, char *buf, int32_t nbytes) { // handle raw data read as payload - if(!recvbackend_data(ctx, buf, nbytes)) - { + if(!recvbackend_data(ctx, buf, nbytes)){ // error DMSG0(ctx, DERROR, "PTCOMM cannot get packet payload from backend.\n"); JMSG0(ctx, is_fatal() ? M_FATAL : M_ERROR, "PTCOMM cannot get packet payload from backend.\n"); f_eod = f_error = f_fatal = true; return -1; } + char bindata[17]; + DMSG1(ctx, DDEBUG, "RECV> %s\n", asciidump(buf, nbytes, bindata, 17)); return nbytes; } @@ -504,8 +505,7 @@ int32_t PTCOMM::recvbackend_fixed(bpContext *ctx, char cmd, char *buf, int32_t b { int32_t length = remaininglen; - if (!f_cont) - { + if (!f_cont){ // handle header length = handle_read_header(ctx, cmd); if (length < 0) @@ -513,8 +513,7 @@ int32_t PTCOMM::recvbackend_fixed(bpContext *ctx, char cmd, char *buf, int32_t b } // handle data payload - if (length > 0) - { + if (length > 0){ // we will need subsequent call to handle remaining data only when `buf` to short f_cont = length > bufsize; int32_t nbytes = f_cont * bufsize + (!f_cont) * length; @@ -576,16 +575,17 @@ int32_t PTCOMM::sendbackend(bpContext *ctx, char cmd, POOLMEM *buf, int32_t len) header = &myheader; #endif header->status = cmd; - char bindata[17]; - transcript_bin_data_to_display(bindata, buf, len); - DMSG2(ctx, DDEBUG, "SENT: %c %s\n", header->status, bindata); - if (bsnprintf(header->length, sizeof(PTHEADER), "%06i", len) != 6){ + + if (bsnprintf(header->length, sizeof(header->length), "%06i\n", len) != 7){ /* problem rendering packet header */ DMSG0(ctx, DERROR, "Problem rendering packet header for command.\n"); JMSG0(ctx, M_FATAL, "Problem rendering packet header for command.\n"); return -1; } - header->length[6] = '\n'; + // header->length[6] = '\n'; + + char bindata[17]; + DMSG3(ctx, DDEBUG, "SENT: %c %s %s\n", header->status, header->length, asciidump(buf, len, bindata, sizeof(bindata))); #ifdef NEED_REVIEW status = sendbackend_data(ctx, (char*)header, len + sizeof(PTHEADER)); diff --git a/bacula/src/plugins/fd/pluginlib/ptcomm.h b/bacula/src/plugins/fd/pluginlib/ptcomm.h index c869f46e7..5b8da78b3 100644 --- a/bacula/src/plugins/fd/pluginlib/ptcomm.h +++ b/bacula/src/plugins/fd/pluginlib/ptcomm.h @@ -172,7 +172,7 @@ public: * -1 - when encountered any error * - the number of bytes sent, success */ - inline int32_t signal_eod(bpContext *ctx) { return sendbackend(ctx, 'F', NULL, 0); } + inline int32_t signal_eod(bpContext *ctx) { return sendbackend(ctx, 'F', "000000", 0); } /** * @brief Signal end of communication to the backend. @@ -183,7 +183,7 @@ public: * -1 - when encountered any error * - the number of bytes sent, success */ - inline int32_t signal_term(bpContext *ctx) { return sendbackend(ctx, 'T', NULL, 0); } + inline int32_t signal_term(bpContext *ctx) { return sendbackend(ctx, 'T', "000000", 0); } void terminate(bpContext *ctx); diff --git a/bacula/src/plugins/fd/pluginlib/test_metaplugin_backend.c b/bacula/src/plugins/fd/pluginlib/test_metaplugin_backend.c index e4b5ca1be..9deaddceb 100644 --- a/bacula/src/plugins/fd/pluginlib/test_metaplugin_backend.c +++ b/bacula/src/plugins/fd/pluginlib/test_metaplugin_backend.c @@ -406,7 +406,21 @@ void perform_backup() write_plugin('A', "Some error...\n"); return; } - +#if 0 + snprintf(buf, BIGBUFLEN, "FNAME:%s/bucket/%d/directory\n", PLUGINPREFIX, mypid); + write_plugin('C', buf); + write_plugin('C', "STAT:D 1024 100 100 040755 1\n"); + write_plugin('C', "TSTAMP:1504271937 1504271937 1504271937\n"); + signal_eod(); + write_plugin('I', "TEST15 - backup dir + xattrs"); + write_plugin('C', "DATA\n"); + write_plugin('D', "/* here comes a file data contents */"); + write_plugin('D', "/* here comes another file line */"); + signal_eod(); + write_plugin('C', "XATTR\n"); + write_plugin('D', "bacula.custom.data=Inteos\nsystem.custom.data=Bacula\n"); + signal_eod(); +#endif snprintf(buf, BIGBUFLEN, "FNAME:%s/bucket/%d/\n", PLUGINPREFIX, mypid); write_plugin('C', buf); write_plugin('C', "STAT:D 1024 100 100 040755 1\n"); @@ -699,6 +713,8 @@ void perform_restore(){ /* empty file to restore */ LOG("#> Empty file."); continue; + } else { + LOG("#> file data saved."); } loopgo = true; fsize = len;