From: Kern Sibbald Date: Mon, 5 Mar 2007 22:04:23 +0000 (+0000) Subject: kes More bat implementation. X-Git-Tag: Release-7.0.0~6783 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=fc450096d4c21758f3a4ce08b1fcbb45fd3d22a4;p=bacula%2Fbacula kes More bat implementation. kes File migrate bug with Pool Occupancy using mediaid instead of jobids. Fixes bug #795. kes Fix orphaned buffers in filed backup and verify due to crypto buffers not freed during errors. Fixes bug #789. kes Extend new GUI api code to tree commands. kes Ensure that tree and dot commands check console ACLs. kes Permit marking directory with trailing slash. kes Allow 20 console connections (instead of only 10). git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4321 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/dird/migrate.c b/bacula/src/dird/migrate.c index 6d21bd8a4a..0165f7153d 100644 --- a/bacula/src/dird/migrate.c +++ b/bacula/src/dird/migrate.c @@ -1,23 +1,7 @@ -/* - * - * Bacula Director -- migrate.c -- responsible for doing - * migration jobs. - * - * Kern Sibbald, September MMIV - * - * Basic tasks done here: - * Open DB and create records for this job. - * Open Message Channel with Storage daemon to tell him a job will be starting. - * Open connection with Storage daemon and pass him commands - * to do the backup. - * When the Storage daemon finishes the job, update the DB. - * - * Version $Id$ - */ /* Bacula® - The Network Backup Solution - Copyright (C) 2004-2006 Free Software Foundation Europe e.V. + Copyright (C) 2004-2007 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. @@ -41,6 +25,22 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ +/* + * + * Bacula Director -- migrate.c -- responsible for doing + * migration jobs. + * + * Kern Sibbald, September MMIV + * + * Basic tasks done here: + * Open DB and create records for this job. + * Open Message Channel with Storage daemon to tell him a job will be starting. + * Open connection with Storage daemon and pass him commands + * to do the backup. + * When the Storage daemon finishes the job, update the DB. + * + * Version $Id$ + */ #include "bacula.h" #include "dird.h" @@ -587,7 +587,7 @@ const char *sql_pool_time = */ static int get_job_to_migrate(JCR *jcr) { - char ed1[30]; + char ed1[30], ed2[30]; POOL_MEM query(PM_MESSAGE); JobId_t JobId; DBId_t MediaId = 0; @@ -726,22 +726,26 @@ static int get_job_to_migrate(JCR *jcr) ctx.count = 0; /* Find count of bytes from Jobs */ Mmsg(query, sql_job_bytes, mid.list); + Dmsg1(dbglevel, "Jobbytes query: %s\n", query.c_str()); if (!db_sql_query(jcr->db, query.c_str(), db_int64_handler, (void *)&ctx)) { Jmsg(jcr, M_FATAL, 0, _("SQL failed. ERR=%s\n"), db_strerror(jcr->db)); goto bail_out; } pool_bytes -= ctx.value; - Dmsg1(dbglevel, "Job bytes=%d\n", (int)ctx.value); - Dmsg2(dbglevel, "lowbytes=%d pool=%d\n", (int)jcr->rpool->MigrationLowBytes, - (int)pool_bytes); + Dmsg1(dbglevel, "Total migrate Job bytes=%s\n", edit_int64(ctx.value, ed1)); + Dmsg2(dbglevel, "lowbytes=%s poolafter=%s\n", + edit_int64(jcr->rpool->MigrationLowBytes, ed1), + edit_int64(pool_bytes, ed2)); if (pool_bytes <= (int64_t)jcr->rpool->MigrationLowBytes) { Dmsg0(dbglevel, "We should be done.\n"); break; } } - Dmsg2(dbglevel, "Pool Occupancy ids=%d JobIds=%s\n", jids.count, jids.list); - + /* Transfer jids to ids, where the jobs list is expected */ + ids.count = jids.count; + pm_strcpy(ids.list, jids.list); + Dmsg2(dbglevel, "Pool Occupancy ids=%d JobIds=%s\n", ids.count, ids.list); break; case MT_POOL_TIME: diff --git a/bacula/src/dird/ua_server.c b/bacula/src/dird/ua_server.c index 14ff46d9e8..676f8becc9 100644 --- a/bacula/src/dird/ua_server.c +++ b/bacula/src/dird/ua_server.c @@ -146,13 +146,17 @@ static void *handle_UA_client_request(void *arg) do_a_command(ua, ua->cmd); } if (!ua->quit) { - if (acl_access_ok(ua, Command_ACL, "messages", 8)) { + if (console_msg_pending && acl_access_ok(ua, Command_ACL, "messages", 8)) { if (ua->auto_display_messages) { pm_strcpy(ua->cmd, "messages"); qmessagescmd(ua, ua->cmd); ua->user_notified_msg_pending = false; } else if (!ua->gui && !ua->user_notified_msg_pending && console_msg_pending) { - bsendmsg(ua, _("You have messages.\n")); + if (ua->api) { + user->signal(BNET_MESSAGES_PENDING); + } else { + bsendmsg(ua, _("You have messages.\n")); + } ua->user_notified_msg_pending = true; } } diff --git a/bacula/src/filed/backup.c b/bacula/src/filed/backup.c index 1f970301f9..4af0603576 100644 --- a/bacula/src/filed/backup.c +++ b/bacula/src/filed/backup.c @@ -211,10 +211,13 @@ bool blast_data_to_storage_daemon(JCR *jcr, char *addr) */ static int save_file(FF_PKT *ff_pkt, void *vjcr, bool top_level) { - int stat, data_stream; + int stat, data_stream; + int rtnstat = 0; DIGEST *digest = NULL; DIGEST *signing_digest = NULL; int digest_stream = STREAM_NONE; + SIGNATURE *sig = NULL; + uint8_t *buf = NULL; bool has_file_data = false; // TODO landonf: Allow the user to specify the digest algorithm #ifdef HAVE_SHA2 @@ -369,7 +372,7 @@ static int save_file(FF_PKT *ff_pkt, void *vjcr, bool top_level) Jmsg(jcr, M_NOTSAVED, 0, _("%s signature digest initialization failed\n"), stream_to_ascii(signing_algorithm)); jcr->Errors++; - return 1; + goto good_rtn; } } @@ -388,13 +391,13 @@ static int save_file(FF_PKT *ff_pkt, void *vjcr, bool top_level) if (!set_prog(&ff_pkt->bfd, ff_pkt->reader, jcr)) { Jmsg(jcr, M_FATAL, 0, _("Python reader program \"%s\" not found.\n"), ff_pkt->reader); - return 0; + goto bail_out; } } /* Send attributes -- must be done after binit() */ if (!encode_and_send_attributes(jcr, ff_pkt, data_stream)) { - return 0; + goto bail_out; } /* @@ -424,7 +427,7 @@ static int save_file(FF_PKT *ff_pkt, void *vjcr, bool top_level) stop_thread_timer(tid); tid = NULL; } - return 1; + goto good_rtn; } if (tid) { stop_thread_timer(tid); @@ -455,7 +458,7 @@ static int save_file(FF_PKT *ff_pkt, void *vjcr, bool top_level) stat = send_data(jcr, data_stream, ff_pkt, digest, signing_digest); bclose(&ff_pkt->bfd); if (!stat) { - return 0; + goto bail_out; } } @@ -475,7 +478,7 @@ static int save_file(FF_PKT *ff_pkt, void *vjcr, bool top_level) if (is_bopen(&ff_pkt->bfd)) { bclose(&ff_pkt->bfd); } - return 1; + goto good_rtn; } flags = ff_pkt->flags; ff_pkt->flags &= ~(FO_GZIP|FO_SPARSE); @@ -488,7 +491,7 @@ static int save_file(FF_PKT *ff_pkt, void *vjcr, bool top_level) ff_pkt->flags = flags; bclose(&ff_pkt->bfd); if (!stat) { - return 0; + goto bail_out; } } @@ -511,49 +514,46 @@ static int save_file(FF_PKT *ff_pkt, void *vjcr, bool top_level) if (ff_pkt->flags & FO_ACL) { /* Read access ACLs for files, dirs and links */ if (!read_and_send_acl(jcr, BACL_TYPE_ACCESS, STREAM_UNIX_ATTRIBUTES_ACCESS_ACL)) { - return 0; + goto bail_out; } /* Directories can have default ACLs too */ if (ff_pkt->type == FT_DIREND && (BACL_CAP & BACL_CAP_DEFAULTS_DIR)) { if (!read_and_send_acl(jcr, BACL_TYPE_DEFAULT, STREAM_UNIX_ATTRIBUTES_DEFAULT_ACL)) { - return 0; + goto bail_out; } } } /* Terminate the signing digest and send it to the Storage daemon */ if (signing_digest) { - SIGNATURE *sig; uint32_t size = 0; - uint8_t *buf; if ((sig = crypto_sign_new()) == NULL) { Jmsg(jcr, M_FATAL, 0, _("Failed to allocate memory for stream signature.\n")); - return 0; + goto bail_out; } if (crypto_sign_add_signer(sig, signing_digest, jcr->pki_keypair) == false) { Jmsg(jcr, M_FATAL, 0, _("An error occurred while signing the stream.\n")); - return 0; + goto bail_out; } /* Get signature size */ if (crypto_sign_encode(sig, NULL, &size) == false) { Jmsg(jcr, M_FATAL, 0, _("An error occurred while signing the stream.\n")); - return 0; + goto bail_out; } /* Allocate signature data buffer */ buf = (uint8_t *)malloc(size); if (!buf) { - crypto_sign_free(sig); - return 0; + goto bail_out; } /* Encode signature data */ if (crypto_sign_encode(sig, buf, &size) == false) { Jmsg(jcr, M_FATAL, 0, _("An error occurred while signing the stream.\n")); - return 0; + goto bail_out; } /* Send our header */ @@ -570,10 +570,7 @@ static int save_file(FF_PKT *ff_pkt, void *vjcr, bool top_level) sd->msglen = size; bnet_send(sd); bnet_sig(sd, BNET_EOD); /* end of checksum */ - - crypto_digest_free(signing_digest); - crypto_sign_free(sig); - free(buf); + goto good_rtn; } /* Terminate any digest and send it to Storage daemon and the Director */ @@ -591,11 +588,25 @@ static int save_file(FF_PKT *ff_pkt, void *vjcr, bool top_level) bnet_send(sd); bnet_sig(sd, BNET_EOD); /* end of checksum */ } + } + +good_rtn: + rtnstat = 1; /* good return */ +bail_out: + if (digest) { crypto_digest_free(digest); } - - return 1; + if (signing_digest) { + crypto_digest_free(signing_digest); + } + if (sig) { + crypto_sign_free(sig); + } + if (buf) { + free(buf); + } + return rtnstat; } /* diff --git a/bacula/src/filed/verify.c b/bacula/src/filed/verify.c index 86403d533f..5727706047 100644 --- a/bacula/src/filed/verify.c +++ b/bacula/src/filed/verify.c @@ -248,7 +248,7 @@ static int verify_file(FF_PKT *ff_pkt, void *pkt, bool top_level) if (digest_file(jcr, ff_pkt, digest) != 0) { jcr->Errors++; - return 1; + goto good_rtn; } if (crypto_digest_finalize(digest, (uint8_t *)md, &size)) { @@ -267,11 +267,13 @@ static int verify_file(FF_PKT *ff_pkt, void *pkt, bool top_level) free(digest_buf); } - - crypto_digest_free(digest); } } +good_rtn: + if (digest) { + crypto_digest_free(digest); + } return 1; } diff --git a/bacula/src/lib/bsock.h b/bacula/src/lib/bsock.h index 8c9089408d..cb78bc478f 100644 --- a/bacula/src/lib/bsock.h +++ b/bacula/src/lib/bsock.h @@ -107,7 +107,9 @@ enum { BNET_INVALID_CMD = -13, /* Invalid command sent */ BNET_CMD_FAILED = -14, /* Command failed */ BNET_CMD_OK = -15, /* Command succeeded */ - BNET_CMD_BEGIN = -16 /* Start command execution */ + BNET_CMD_BEGIN = -16, /* Start command execution */ + BNET_MESSAGES_PENDING = 17, /* Messages pending */ + BNET_SERVER_READY = 18 /* Server ready and waiting */ }; #define BNET_SETBUF_READ 1 /* Arg for bnet_set_buffer_size */ diff --git a/bacula/src/qt-console/Makefile b/bacula/src/qt-console/Makefile index 9e2396bf24..4b9f358fe6 100644 --- a/bacula/src/qt-console/Makefile +++ b/bacula/src/qt-console/Makefile @@ -1,6 +1,6 @@ ############################################################################# # Makefile for building: bat -# Generated by qmake (2.01a) (Qt 4.2.1) on: Mon Mar 5 09:37:46 2007 +# Generated by qmake (2.01a) (Qt 4.2.1) on: Mon Mar 5 17:45:21 2007 # Project: bat.pro # Template: app # Command: /usr/bin/qmake -unix -o Makefile bat.pro diff --git a/bacula/src/qt-console/console/console.cpp b/bacula/src/qt-console/console/console.cpp index a46dfff47a..b0bde34df2 100644 --- a/bacula/src/qt-console/console/console.cpp +++ b/bacula/src/qt-console/console/console.cpp @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2007 Free Software Foundation Europe e.V. + Copyright (C) 2007-2007 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. @@ -25,13 +25,12 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ - /* * Version $Id$ * * Console Class * - * Kern Sibbald, January MMVI + * Kern Sibbald, January MMVII * */ @@ -81,9 +80,18 @@ Console::Console(QStackedWidget *parent) treeWidget->expandItem(topItem); readSettings(); + /* Check for messages every 5 seconds */ +// m_timer = new QTimer(this); +// QWidget::connect(m_timer, SIGNAL(timeout()), this, SLOT(poll_messages())); +// m_timer->start(5000); } +void Console::poll_messages() +{ + m_messages_pending = true; +} + /* Terminate any open socket */ void Console::terminate() { @@ -91,6 +99,7 @@ void Console::terminate() m_sock->close(); m_sock = NULL; } + m_timer->stop(); } /* @@ -337,6 +346,7 @@ const QFont Console::get_font() void Console::status_dir() { write_dir("status dir\n"); + displayToPrompt(); } /* @@ -468,6 +478,10 @@ int Console::read() break; } app->processEvents(); +// if (m_api_set && m_messages_pending) { +// write_dir(".messages"); +// m_messages_pending = false; +// } } stat = m_sock->recv(); if (stat >= 0) { @@ -479,6 +493,16 @@ int Console::read() } switch (m_sock->msglen) { + case BNET_SERVER_READY: +// if (m_api_set && m_messages_pending) { +// write_dir(".messages"); +// m_messages_pending = false; +// } + m_at_prompt = true; + continue; + case BNET_MESSAGES_PENDING: + m_messages_pending = true; + continue; case BNET_CMD_BEGIN: m_at_prompt = false; continue; @@ -531,8 +555,7 @@ void Console::read_dir(int fd) (void)fd; if (commDebug) Pmsg0(000, "read_dir\n"); - stat = read(); - if (stat >= 0) { + while ((stat = read()) >= 0) { display_text(msg()); } } diff --git a/bacula/src/qt-console/console/console.h b/bacula/src/qt-console/console/console.h index f9f1c88eb6..aa18014f47 100644 --- a/bacula/src/qt-console/console/console.h +++ b/bacula/src/qt-console/console/console.h @@ -1,10 +1,9 @@ #ifndef _CONSOLE_H_ #define _CONSOLE_H_ - /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2007 Free Software Foundation Europe e.V. + Copyright (C) 2007-2007 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. @@ -98,6 +97,7 @@ public: QStringList type_list; QStringList level_list; + public slots: void connect(void); void read_dir(int fd); @@ -106,6 +106,7 @@ public slots: int write(QString msg); void status_dir(void); void set_font(void); + void poll_messages(void); private: QTextEdit *m_textEdit; @@ -116,6 +117,8 @@ private: QTextCursor *m_cursor; QTreeWidgetItem *m_consoleItem; bool m_api_set; + bool m_messages_pending; + QTimer *m_timer; }; #endif /* _CONSOLE_H_ */ diff --git a/bacula/src/qt-console/label/label.cpp b/bacula/src/qt-console/label/label.cpp index 21b7ef839e..12bd0da72c 100644 --- a/bacula/src/qt-console/label/label.cpp +++ b/bacula/src/qt-console/label/label.cpp @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2007 Free Software Foundation Europe e.V. + Copyright (C) 2007-2007 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,7 @@ /* * Label Dialog class * - * Kern Sibbald, February MMVI + * Kern Sibbald, February MMVII * */ @@ -39,6 +39,7 @@ labelDialog::labelDialog(Console *console) { + m_console = console; setupUi(this); storageCombo->addItems(console->storage_list); poolCombo->addItems(console->pool_list); @@ -57,8 +58,10 @@ void labelDialog::accept() scmd = QString("label volume=\"%1\" pool=\"%2\" storage=\"%3\" slot=%4\n") .arg(volumeName->text()).arg(storageCombo->currentText()) .arg(poolCombo->currentText()).arg(slotSpin->value()); - printf(scmd.toUtf8().data()); + m_console->write_dir(scmd.toUtf8().data()); + m_console->displayToPrompt(); delete this; + mainWin->resetFocus(); } void labelDialog::reject() @@ -66,4 +69,5 @@ void labelDialog::reject() printf("Rejected\n"); this->hide(); delete this; + mainWin->resetFocus(); } diff --git a/bacula/src/qt-console/label/label.h b/bacula/src/qt-console/label/label.h index d06cf40aa3..d5acfd82de 100644 --- a/bacula/src/qt-console/label/label.h +++ b/bacula/src/qt-console/label/label.h @@ -1,3 +1,33 @@ +/* + Bacula® - The Network Backup Solution + + Copyright (C) 2007-2007 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. + This program is Free Software; you can redistribute it and/or + modify it under the terms of version two of the GNU General Public + License as published by the Free Software Foundation plus additions + that are listed in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + Bacula® is a registered trademark of John Walker. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. +*/ +/* + * Kern Sibbald, February MMVII + */ #ifndef _LABEL_H_ #define _LABEL_H_ @@ -13,12 +43,12 @@ class labelDialog : public QDialog, public Ui::labelForm public: labelDialog(Console *console); -public slots: +private slots: void accept(); void reject(); private: - + Console *m_console; }; #endif /* _LABEL_H_ */ diff --git a/bacula/src/qt-console/run/run.cpp b/bacula/src/qt-console/run/run.cpp index 7b99fc9172..9f1b65b2f6 100644 --- a/bacula/src/qt-console/run/run.cpp +++ b/bacula/src/qt-console/run/run.cpp @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2007 Free Software Foundation Europe e.V. + Copyright (C) 2007-2007 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,7 @@ /* * Run Dialog class * - * Kern Sibbald, February MMVI + * Kern Sibbald, February MMVII * * $Id$ */ @@ -37,6 +37,9 @@ #include "bat.h" #include "run.h" +/* + * Setup all the combo boxes and display the dialog + */ runDialog::runDialog(Console *console) { QDateTime dt; @@ -75,9 +78,11 @@ void runDialog::accept() storageCombo->currentText().toUtf8().data(), prioritySpin->value()); -// m_console->write(cmd); + m_console->write_dir(cmd); m_console->display_text(cmd); + m_console->displayToPrompt(); delete this; + mainWin->resetFocus(); } @@ -86,8 +91,14 @@ void runDialog::reject() mainWin->set_status(" Canceled"); this->hide(); delete this; + mainWin->resetFocus(); } +/* + * Called here when the jobname combo box is changed. + * We load the default values for the new job in the + * other combo boxes. + */ void runDialog::job_name_change(int index) { job_defaults job_defs; diff --git a/bacula/technotes-2.1 b/bacula/technotes-2.1 index d3c23ebe18..64f4780870 100644 --- a/bacula/technotes-2.1 +++ b/bacula/technotes-2.1 @@ -2,6 +2,11 @@ General: 05Mar07 +kes More bat implementation. +kes File migrate bug with Pool Occupancy using mediaid instead + of jobids. Fixes bug #795. +kes Fix orphaned buffers in filed backup and verify due to + crypto buffers not freed during errors. Fixes bug #789. kes Extend new GUI api code to tree commands. kes Ensure that tree and dot commands check console ACLs. kes Permit marking directory with trailing slash.