From 11ac7d7f999d3aad09eaa19d5396afdcb91de9f5 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Thu, 8 Feb 2007 10:56:41 +0000 Subject: [PATCH] kes Fix dird/ua_cmds.c so that a cancel command checks if the console is authorized to cancel the job. This fixes bug #767. kes Modify SD so that the VolCatJobs medium record is updated at the beginning of a Job rather than the end. This fixes bug #775 where exceeding MaxVolJobs caused jobs to fail. kes Added a mutex around getting and setting Volume information so that multiple simultaneous jobs will single thread. Switch to using Subversion kes Remove src/pygtk-console/ from configure git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/branches/Branch-2.0@4146 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/autoconf/configure.in | 1 - bacula/configure | 3 +-- bacula/src/dird/ua_cmds.c | 17 +++++++++++++---- bacula/src/stored/acquire.c | 5 +++-- bacula/src/stored/askdir.c | 25 ++++++++++++++++++++++--- bacula/src/stored/block.c | 3 +-- bacula/src/stored/device.c | 3 +++ bacula/technotes-2.0 | 13 +++++++++++++ 8 files changed, 56 insertions(+), 14 deletions(-) diff --git a/bacula/autoconf/configure.in b/bacula/autoconf/configure.in index 8a0c153d99..4ba634568a 100644 --- a/bacula/autoconf/configure.in +++ b/bacula/autoconf/configure.in @@ -2049,7 +2049,6 @@ AC_OUTPUT([autoconf/Make.common \ src/cats/drop_bacula_tables \ src/cats/drop_bacula_database \ src/findlib/Makefile \ - src/pygtk-console/Makefile \ src/tools/Makefile \ po/Makefile.in \ $PFILES ], diff --git a/bacula/configure b/bacula/configure index 5e768c3660..a3816265f5 100755 --- a/bacula/configure +++ b/bacula/configure @@ -33785,7 +33785,7 @@ if test "x${subsysdir}" = "x${sbindir}" ; then exit 1 fi -ac_config_files="$ac_config_files autoconf/Make.common Makefile manpages/Makefile scripts/startmysql scripts/stopmysql scripts/btraceback scripts/startit scripts/stopit scripts/bconsole scripts/gconsole scripts/bacula scripts/bacula-ctl-dir scripts/bacula-ctl-fd scripts/bacula-ctl-sd scripts/devel_bacula scripts/Makefile scripts/logrotate scripts/bacula.desktop.gnome1 scripts/bacula.desktop.gnome2 scripts/bacula.desktop.gnome1.consolehelper scripts/bacula.desktop.gnome2.consolehelper scripts/bacula.desktop.gnome1.xsu scripts/bacula.desktop.gnome2.xsu scripts/gnome-console.console_apps scripts/mtx-changer scripts/disk-changer scripts/dvd-handler scripts/dvd-simulator scripts/bacula-tray-monitor.desktop scripts/logwatch/Makefile scripts/logwatch/logfile.bacula.conf scripts/wxconsole.console_apps scripts/wxconsole.desktop.consolehelper scripts/wxconsole.desktop.xsu src/Makefile src/host.h src/console/Makefile src/console/bconsole.conf src/gnome2-console/Makefile src/gnome2-console/gnome-console.conf src/wx-console/Makefile src/wx-console/wx-console.conf src/tray-monitor/Makefile src/tray-monitor/tray-monitor.conf src/dird/Makefile src/dird/bacula-dir.conf src/lib/Makefile src/stored/Makefile src/stored/bacula-sd.conf src/filed/Makefile src/filed/bacula-fd.conf src/cats/Makefile src/cats/make_catalog_backup src/cats/delete_catalog_backup src/cats/create_postgresql_database src/cats/update_postgresql_tables src/cats/make_postgresql_tables src/cats/grant_postgresql_privileges src/cats/drop_postgresql_tables src/cats/drop_postgresql_database src/cats/create_mysql_database src/cats/update_mysql_tables src/cats/make_mysql_tables src/cats/grant_mysql_privileges src/cats/drop_mysql_tables src/cats/drop_mysql_database src/cats/create_sqlite_database src/cats/update_sqlite_tables src/cats/make_sqlite_tables src/cats/grant_sqlite_privileges src/cats/drop_sqlite_tables src/cats/drop_sqlite_database src/cats/create_sqlite3_database src/cats/update_sqlite3_tables src/cats/make_sqlite3_tables src/cats/grant_sqlite3_privileges src/cats/drop_sqlite3_tables src/cats/drop_sqlite3_database src/cats/sqlite src/cats/mysql src/cats/create_bdb_database src/cats/update_bdb_tables src/cats/make_bdb_tables src/cats/grant_bdb_privileges src/cats/drop_bdb_tables src/cats/drop_bdb_database src/cats/create_bacula_database src/cats/update_bacula_tables src/cats/grant_bacula_privileges src/cats/make_bacula_tables src/cats/drop_bacula_tables src/cats/drop_bacula_database src/findlib/Makefile src/pygtk-console/Makefile src/tools/Makefile po/Makefile.in $PFILES" +ac_config_files="$ac_config_files autoconf/Make.common Makefile manpages/Makefile scripts/startmysql scripts/stopmysql scripts/btraceback scripts/startit scripts/stopit scripts/bconsole scripts/gconsole scripts/bacula scripts/bacula-ctl-dir scripts/bacula-ctl-fd scripts/bacula-ctl-sd scripts/devel_bacula scripts/Makefile scripts/logrotate scripts/bacula.desktop.gnome1 scripts/bacula.desktop.gnome2 scripts/bacula.desktop.gnome1.consolehelper scripts/bacula.desktop.gnome2.consolehelper scripts/bacula.desktop.gnome1.xsu scripts/bacula.desktop.gnome2.xsu scripts/gnome-console.console_apps scripts/mtx-changer scripts/disk-changer scripts/dvd-handler scripts/dvd-simulator scripts/bacula-tray-monitor.desktop scripts/logwatch/Makefile scripts/logwatch/logfile.bacula.conf scripts/wxconsole.console_apps scripts/wxconsole.desktop.consolehelper scripts/wxconsole.desktop.xsu src/Makefile src/host.h src/console/Makefile src/console/bconsole.conf src/gnome2-console/Makefile src/gnome2-console/gnome-console.conf src/wx-console/Makefile src/wx-console/wx-console.conf src/tray-monitor/Makefile src/tray-monitor/tray-monitor.conf src/dird/Makefile src/dird/bacula-dir.conf src/lib/Makefile src/stored/Makefile src/stored/bacula-sd.conf src/filed/Makefile src/filed/bacula-fd.conf src/cats/Makefile src/cats/make_catalog_backup src/cats/delete_catalog_backup src/cats/create_postgresql_database src/cats/update_postgresql_tables src/cats/make_postgresql_tables src/cats/grant_postgresql_privileges src/cats/drop_postgresql_tables src/cats/drop_postgresql_database src/cats/create_mysql_database src/cats/update_mysql_tables src/cats/make_mysql_tables src/cats/grant_mysql_privileges src/cats/drop_mysql_tables src/cats/drop_mysql_database src/cats/create_sqlite_database src/cats/update_sqlite_tables src/cats/make_sqlite_tables src/cats/grant_sqlite_privileges src/cats/drop_sqlite_tables src/cats/drop_sqlite_database src/cats/create_sqlite3_database src/cats/update_sqlite3_tables src/cats/make_sqlite3_tables src/cats/grant_sqlite3_privileges src/cats/drop_sqlite3_tables src/cats/drop_sqlite3_database src/cats/sqlite src/cats/mysql src/cats/create_bdb_database src/cats/update_bdb_tables src/cats/make_bdb_tables src/cats/grant_bdb_privileges src/cats/drop_bdb_tables src/cats/drop_bdb_database src/cats/create_bacula_database src/cats/update_bacula_tables src/cats/grant_bacula_privileges src/cats/make_bacula_tables src/cats/drop_bacula_tables src/cats/drop_bacula_database src/findlib/Makefile src/tools/Makefile po/Makefile.in $PFILES" ac_config_commands="$ac_config_commands default" @@ -34439,7 +34439,6 @@ do "src/cats/drop_bacula_tables") CONFIG_FILES="$CONFIG_FILES src/cats/drop_bacula_tables" ;; "src/cats/drop_bacula_database") CONFIG_FILES="$CONFIG_FILES src/cats/drop_bacula_database" ;; "src/findlib/Makefile") CONFIG_FILES="$CONFIG_FILES src/findlib/Makefile" ;; - "src/pygtk-console/Makefile") CONFIG_FILES="$CONFIG_FILES src/pygtk-console/Makefile" ;; "src/tools/Makefile") CONFIG_FILES="$CONFIG_FILES src/tools/Makefile" ;; "po/Makefile.in") CONFIG_FILES="$CONFIG_FILES po/Makefile.in" ;; "$PFILES") CONFIG_FILES="$CONFIG_FILES $PFILES" ;; diff --git a/bacula/src/dird/ua_cmds.c b/bacula/src/dird/ua_cmds.c index d5bf15931e..268e5158b2 100644 --- a/bacula/src/dird/ua_cmds.c +++ b/bacula/src/dird/ua_cmds.c @@ -423,16 +423,25 @@ static int cancel_cmd(UAContext *ua, const char *cmd) } } - /* If we still do not have a jcr, - * throw up a list and ask the user to select one. - */ - if (!jcr) { + if (jcr) { + if (jcr->job && !acl_access_ok(ua, Job_ACL, jcr->job->name())) { + bsendmsg(ua, _("Unauthorized command from this console.\n")); + return 1; + } + } else { + /* + * If we still do not have a jcr, + * throw up a list and ask the user to select one. + */ char buf[1000]; /* Count Jobs running */ foreach_jcr(jcr) { if (jcr->JobId == 0) { /* this is us */ continue; } + if (!acl_access_ok(ua, Job_ACL, jcr->job->name())) { + continue; /* skip not authorized */ + } njobs++; } endeach_jcr(jcr); diff --git a/bacula/src/stored/acquire.c b/bacula/src/stored/acquire.c index 9fa9f79c95..69c8fa2049 100644 --- a/bacula/src/stored/acquire.c +++ b/bacula/src/stored/acquire.c @@ -8,7 +8,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2002-2006 Free Software Foundation Europe e.V. + Copyright (C) 2002-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. @@ -406,6 +406,8 @@ DCR *acquire_device_for_append(DCR *dcr) if (jcr->NumWriteVolumes == 0) { jcr->NumWriteVolumes = 1; } + dev->VolCatInfo.VolCatJobs++; /* increment number of jobs on vol */ + dir_update_volume_info(dcr, false); /* send Volume info to Director */ P(dev->mutex); if (dcr->reserved_device) { dev->reserved_device--; @@ -486,7 +488,6 @@ bool release_device(DCR *dcr) } if (!dev->at_weot()) { dev->VolCatInfo.VolCatFiles = dev->file; /* set number of files */ - dev->VolCatInfo.VolCatJobs++; /* increment number of jobs */ /* Note! do volume update before close, which zaps VolCatInfo */ Dmsg0(100, "dir_update_vol_info. Release0\n"); dir_update_volume_info(dcr, false); /* send Volume info to Director */ diff --git a/bacula/src/stored/askdir.c b/bacula/src/stored/askdir.c index a42863cabb..6525bfe7de 100644 --- a/bacula/src/stored/askdir.c +++ b/bacula/src/stored/askdir.c @@ -9,7 +9,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2006 Free Software Foundation Europe e.V. + Copyright (C) 2000-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. @@ -62,6 +62,8 @@ static char OK_media[] = "1000 OK VolName=%127s VolJobs=%u VolFiles=%lu" static char OK_create[] = "1000 OK CreateJobMedia\n"; +static pthread_mutex_t vol_info_mutex = PTHREAD_MUTEX_INITIALIZER; + #ifdef needed static char Device_update[] = "DevUpd Job=%s device=%s " @@ -155,6 +157,11 @@ bool dir_send_job_status(JCR *jcr) * and * dir_find_next_appendable_volume() * + * NOTE!!! All calls to this routine must be protected by + * locking vol_info_mutex before calling it so that + * we don't have one thread modifying the parameters + * and another reading them. + * * Returns: true on success and vol info in dcr->VolCatInfo * false on failure */ @@ -214,6 +221,7 @@ bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw writing) JCR *jcr = dcr->jcr; BSOCK *dir = jcr->dir_bsock; + P(vol_info_mutex); bstrncpy(dcr->VolCatInfo.VolCatName, dcr->VolumeName, sizeof(dcr->VolCatInfo.VolCatName)); bash_spaces(dcr->VolCatInfo.VolCatName); bnet_fsend(dir, Get_Vol_Info, jcr->Job, dcr->VolCatInfo.VolCatName, @@ -221,6 +229,7 @@ bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw writing) Dmsg1(100, ">dird: %s", dir->msg); unbash_spaces(dcr->VolCatInfo.VolCatName); bool ok = do_get_volume_info(dcr); + V(vol_info_mutex); return ok; } @@ -247,6 +256,7 @@ bool dir_find_next_appendable_volume(DCR *dcr) * drive, so we continue looking for a not in use Volume. */ lock_reservations(); + P(vol_info_mutex); for (int vol_index=1; vol_index < 20; vol_index++) { bash_spaces(dcr->media_type); bash_spaces(dcr->pool_name); @@ -273,10 +283,12 @@ bool dir_find_next_appendable_volume(DCR *dcr) if (found) { Dmsg0(400, "dir_find_next_appendable_volume return true\n"); new_volume(dcr, dcr->VolumeName); /* reserve volume */ + V(vol_info_mutex); unlock_reservations(); return true; } dcr->VolumeName[0] = 0; + V(vol_info_mutex); unlock_reservations(); return false; } @@ -296,6 +308,7 @@ bool dir_update_volume_info(DCR *dcr, bool label) VOLUME_CAT_INFO *vol = &dev->VolCatInfo; char ed1[50], ed2[50], ed3[50], ed4[50], ed5[50]; int InChanger; + bool ok = false; POOL_MEM VolumeName; /* If system job, do not update catalog */ @@ -314,6 +327,8 @@ bool dir_update_volume_info(DCR *dcr, bool label) return false; } + /* Lock during Volume update */ + P(vol_info_mutex); Dmsg1(100, "Update cat VolFiles=%d\n", dev->file); /* Just labeled or relabeled the tape */ if (label) { @@ -340,12 +355,16 @@ bool dir_update_volume_info(DCR *dcr, bool label) Jmsg(jcr, M_FATAL, 0, "%s", jcr->errmsg); Dmsg2(100, _("Didn't get vol info vol=%s: ERR=%s"), vol->VolCatName, jcr->errmsg); - return false; + goto bail_out; } Dmsg1(420, "get_volume_info(): %s", dir->msg); /* Update dev Volume info in case something changed (e.g. expired) */ dev->VolCatInfo = dcr->VolCatInfo; - return true; + ok = true; + +bail_out: + V(vol_info_mutex); + return ok; } /* diff --git a/bacula/src/stored/block.c b/bacula/src/stored/block.c index 8ebdaf7edf..2c3f08e56c 100644 --- a/bacula/src/stored/block.c +++ b/bacula/src/stored/block.c @@ -11,7 +11,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2001-2006 Free Software Foundation Europe e.V. + Copyright (C) 2001-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. @@ -729,7 +729,6 @@ static bool terminate_writing_volume(DCR *dcr) } bstrncpy(dev->VolCatInfo.VolCatStatus, "Full", sizeof(dev->VolCatInfo.VolCatStatus)); dev->VolCatInfo.VolCatFiles = dev->file; /* set number of files */ - dev->VolCatInfo.VolCatJobs++; /* increment number of jobs */ if (dev->is_dvd()) { if (!dvd_write_part(dcr)) { /* write last part */ diff --git a/bacula/src/stored/device.c b/bacula/src/stored/device.c index 4884d3cc71..b70902ef00 100644 --- a/bacula/src/stored/device.c +++ b/bacula/src/stored/device.c @@ -122,6 +122,9 @@ bool fixup_device_block_write_error(DCR *dcr) } P(dev->mutex); /* lock again */ + dev->VolCatInfo.VolCatJobs++; /* increment number of jobs on vol */ + dir_update_volume_info(dcr, false); /* send Volume info to Director */ + Jmsg(jcr, M_INFO, 0, _("New volume \"%s\" mounted on device %s at %s.\n"), dcr->VolumeName, dev->print_name(), bstrftime(dt, sizeof(dt), time(NULL))); diff --git a/bacula/technotes-2.0 b/bacula/technotes-2.0 index 572a2827ad..afaca2d1c8 100644 --- a/bacula/technotes-2.0 +++ b/bacula/technotes-2.0 @@ -1,6 +1,19 @@ Technical notes on version 2.0 General: +08Feb07 +kes Fix dird/ua_cmds.c so that a cancel command checks if the + console is authorized to cancel the job. This fixes bug + #767. +kes Modify SD so that the VolCatJobs medium record is updated + at the beginning of a Job rather than the end. This + fixes bug #775 where exceeding MaxVolJobs caused jobs + to fail. +kes Added a mutex around getting and setting Volume information + so that multiple simultaneous jobs will single thread. +07Feb07 + Switch to using Subversion +kes Remove src/pygtk-console/ from configure 06Feb07 kes Delete src/lib/btree.c from win32 build, then add rblist.c plus the entrypoints. -- 2.39.5