From: Kern Sibbald Date: Wed, 30 Oct 2002 14:22:10 +0000 (+0000) Subject: Fix GZIP compression bug -- kes30Oct02 X-Git-Tag: Release-1.27~40 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=bbd98c9e14b3c68ff7054024729edd3000b9a786;p=bacula%2Fbacula Fix GZIP compression bug -- kes30Oct02 git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@178 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/dird/sql_cmds.c b/bacula/src/dird/sql_cmds.c index f2ebc13a99..5c8b006871 100644 --- a/bacula/src/dird/sql_cmds.c +++ b/bacula/src/dird/sql_cmds.c @@ -213,7 +213,7 @@ char *uar_sel_all_temp1 = "SELECT * FROM temp1"; /* Select filesets for this Client */ char *uar_sel_fileset = - "SELECT FileSet.FileSetId,FileSet.FileSet FROM Job," + "SELECT FileSet.FileSetId,FileSet.FileSet,FileSet.MD5 FROM Job," "Client,FileSet WHERE Job.FileSetId=FileSet.FileSetId " "AND Job.ClientId=Client.ClientId AND Client.Name='%s' " "GROUP BY FileSet.FileSetId"; diff --git a/bacula/src/dird/ua_restore.c b/bacula/src/dird/ua_restore.c index c0a957821f..96e99053a5 100644 --- a/bacula/src/dird/ua_restore.c +++ b/bacula/src/dird/ua_restore.c @@ -365,16 +365,15 @@ static int user_select_jobids(UAContext *ua, JobIds *ji) free_pool_memory(query); return 0; } - fsr.FileSetId = 0; - strcpy(fsr.FileSet, fileset_name); + fsr.FileSetId = atoi(fileset_name); /* Id is first part of name */ if (!db_get_fileset_record(ua->db, &fsr)) { bsendmsg(ua, "Error getting FileSet record: %s\n", db_strerror(ua->db)); bsendmsg(ua, _("This probably means you modified the FileSet.\n" "Continuing anyway.\n")); } + /* Find JobId of last Full backup for this client, fileset */ Mmsg(&query, uar_last_full, ji->client->hdr.name, fsr.FileSetId); - /* Find JobId of full Backup of system */ if (!db_sql_query(ua->db, query, NULL, NULL)) { bsendmsg(ua, "%s\n", db_strerror(ua->db)); } @@ -494,7 +493,10 @@ static int last_full_handler(void *ctx, int num_fields, char **row) */ static int fileset_handler(void *ctx, int num_fields, char **row) { - add_prompt((UAContext *)ctx, row[1]); + char prompt[MAX_NAME_LENGTH+200]; + + snprintf(prompt, sizeof(prompt), "%s %s %s", row[0], row[1], row[2]); + add_prompt((UAContext *)ctx, prompt); return 0; } diff --git a/bacula/src/filed/backup.c b/bacula/src/filed/backup.c index a3ceebcf65..40c5143a27 100644 --- a/bacula/src/filed/backup.c +++ b/bacula/src/filed/backup.c @@ -54,11 +54,12 @@ int blast_data_to_storage_daemon(JCR *jcr, char *addr) jcr->buf_size = sd->msglen; /* Adjust for compression so that output buffer is - * 12 bytes + 0.1% larger than input buffer plus 2 bytes. + * 12 bytes + 0.1% larger than input buffer plus 18 bytes. + * This gives a bit extra plus room for the sparse addr if any. * Note, we adjust the read size to be smaller so that the * same output buffer can be used without growing it. */ - jcr->compress_buf_size = jcr->buf_size + ((jcr->buf_size+999) / 1000) + 14; + jcr->compress_buf_size = jcr->buf_size + ((jcr->buf_size+999) / 1000) + 30; jcr->compress_buf = get_memory(jcr->compress_buf_size); Dmsg1(100, "set_find_options ff=%p\n", jcr->ff); @@ -238,12 +239,15 @@ static int save_file(FF_PKT *ff_pkt, void *ijcr) * */ if (ff_pkt->fid >= 0) { + uint64_t fileAddr = 0; /* file address */ + char *rbuf, *wbuf; + int rsize = jcr->buf_size; /* read buffer size */ + + msgsave = sd->msg; + rbuf = sd->msg; /* read buffer */ + wbuf = sd->msg; /* write buffer */ Dmsg1(100, "Saving data, type=%d\n", ff_pkt->type); - /* - * Send Data header to Storage daemon - * - */ if (ff_pkt->flags & FO_SPARSE) { stream = STREAM_SPARSE_DATA; @@ -252,7 +256,7 @@ static int save_file(FF_PKT *ff_pkt, void *ijcr) } #ifdef HAVE_LIBZ - uLong compress_len; + uLong compress_len, max_compress_len = 0; const Bytef *cbuf = NULL; if (ff_pkt->flags & FO_GZIP) { @@ -264,15 +268,20 @@ static int save_file(FF_PKT *ff_pkt, void *ijcr) if (ff_pkt->flags & FO_SPARSE) { cbuf = (Bytef *)jcr->compress_buf + SPARSE_FADDR_SIZE; - compress_len = jcr->compress_buf_size - SPARSE_FADDR_SIZE; + max_compress_len = jcr->compress_buf_size - SPARSE_FADDR_SIZE; } else { cbuf = (Bytef *)jcr->compress_buf; - compress_len = jcr->compress_buf_size; /* set max length */ + max_compress_len = jcr->compress_buf_size; /* set max length */ } + wbuf = jcr->compress_buf; /* compressed output here */ } #endif #ifndef NO_FD_SEND_TEST + /* + * Send Data header to Storage daemon + * + */ if (!bnet_fsend(sd, "%ld %d 0", jcr->JobFiles, stream)) { close(ff_pkt->fid); return 0; @@ -284,12 +293,10 @@ static int save_file(FF_PKT *ff_pkt, void *ijcr) MD5Init(&md5c); } - msgsave = sd->msg; - uint64_t fileAddr = 0; /* file address */ - char *rbuf = sd->msg; /* read buffer */ - int rsize = jcr->buf_size; /* read size */ - - /* Make space at beginning of buffer for fileAddr */ + /* + * Make space at beginning of buffer for fileAddr because this + * same buffer will be used for writing if compression if off. + */ if (ff_pkt->flags & FO_SPARSE) { rbuf += SPARSE_FADDR_SIZE; rsize -= SPARSE_FADDR_SIZE; @@ -309,7 +316,7 @@ static int save_file(FF_PKT *ff_pkt, void *ijcr) sparseBlock = is_buf_zero(rbuf, rsize); } - ser_begin(sd->msg, SPARSE_FADDR_SIZE); + ser_begin(wbuf, SPARSE_FADDR_SIZE); ser_uint64(fileAddr); /* store fileAddr in begin of buffer */ } @@ -325,20 +332,24 @@ static int save_file(FF_PKT *ff_pkt, void *ijcr) #ifdef HAVE_LIBZ /* Do compression if turned on */ if (!sparseBlock && ff_pkt->flags & FO_GZIP) { - if (compress2((Bytef *)cbuf, &compress_len, + int zstat; + compress_len = max_compress_len; + Dmsg4(400, "cbuf=0x%x len=%u rbuf=0x%x len=%u\n", cbuf, compress_len, + rbuf, sd->msglen); + /* NOTE! This call modifies compress_len !!! */ + if ((zstat=compress2((Bytef *)cbuf, &compress_len, (const Bytef *)rbuf, (uLong)sd->msglen, - ff_pkt->GZIP_level) != Z_OK) { - Jmsg(jcr, M_FATAL, 0, _("Compression error\n")); + ff_pkt->GZIP_level)) != Z_OK) { + Jmsg(jcr, M_FATAL, 0, _("Compression error: %d\n"), zstat); sd->msg = msgsave; sd->msglen = 0; close(ff_pkt->fid); return 0; } - Dmsg2(100, "compressed len=%d uncompressed len=%d\n", + Dmsg2(400, "compressed len=%d uncompressed len=%d\n", compress_len, sd->msglen); - sd->msg = jcr->compress_buf; /* write compressed buffer */ - sd->msglen = compress_len; + sd->msglen = compress_len; /* set compressed length */ } #endif @@ -348,6 +359,7 @@ static int save_file(FF_PKT *ff_pkt, void *ijcr) if (ff_pkt->flags & FO_SPARSE) { sd->msglen += SPARSE_FADDR_SIZE; /* include fileAddr in size */ } + sd->msg = wbuf; /* set correct write buffer */ if (!bnet_send(sd)) { sd->msg = msgsave; /* restore read buffer */ sd->msglen = 0; diff --git a/bacula/src/filed/restore.c b/bacula/src/filed/restore.c index 5bac82fd52..8953758e1b 100644 --- a/bacula/src/filed/restore.c +++ b/bacula/src/filed/restore.c @@ -295,16 +295,22 @@ void do_restore(JCR *jcr) } else if (stream == STREAM_GZIP_DATA || stream == STREAM_SPARSE_GZIP_DATA) { #ifdef HAVE_LIBZ if (extract) { + ser_declare; uLong compress_len; + uint64_t faddr; + char ec1[50]; int stat; if (stream == STREAM_SPARSE_GZIP_DATA) { wbuf = sd->msg + SPARSE_FADDR_SIZE; wsize = sd->msglen - SPARSE_FADDR_SIZE; - if (fileAddr != *((uint64_t *)sd->msg)) { - fileAddr = *((uint64_t *)sd->msg); + ser_begin(sd->msg, SPARSE_FADDR_SIZE); + unser_uint64(faddr); + if (fileAddr != faddr) { + fileAddr = faddr; if (lseek(ofd, (off_t)fileAddr, SEEK_SET) < 0) { - Jmsg2(jcr, M_ERROR, 0, "Seek error on %s: %s\n", ofile, strerror(errno)); + Jmsg3(jcr, M_ERROR, 0, _("Seek to %s error on %s: ERR=%s\n"), + edit_uint64(fileAddr, ec1), ofile, strerror(errno)); goto bail_out; } } diff --git a/bacula/src/lib/protos.h b/bacula/src/lib/protos.h index 14d2bf3a08..5fed9a48d1 100644 --- a/bacula/src/lib/protos.h +++ b/bacula/src/lib/protos.h @@ -31,6 +31,7 @@ int bin_to_base64 (char *buf, char *bin, int len); /* bmisc.c */ char *bstrncpy (char *dest, char *src, int maxlen); +char *bstrncat (char *dest, char *src, int maxlen); void *b_malloc (char *file, int line, size_t size); #ifndef DEBUG void *bmalloc (size_t size); diff --git a/bacula/src/stored/bextract.c b/bacula/src/stored/bextract.c index 70f474d1ec..c5a5554d76 100644 --- a/bacula/src/stored/bextract.c +++ b/bacula/src/stored/bextract.c @@ -399,7 +399,7 @@ static void record_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec) fileAddr += wsize; } - } else if (rec->Stream == STREAM_GZIP_DATA) { + } else if (rec->Stream == STREAM_GZIP_DATA || rec->Stream == STREAM_SPARSE_GZIP_DATA) { #ifdef HAVE_LIBZ if (extract) { uLongf compress_len;