From 5ef5c7d48f53763e1c617c9e0583f55317fd0aff Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Thu, 8 Feb 2007 10:54:40 +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. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4145 91ce42f0-d328-0410-95d8-f526ca767f89 --- 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/src/version.h | 4 ++-- bacula/technotes-2.1 | 10 ++++++++++ 7 files changed, 54 insertions(+), 13 deletions(-) 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/src/version.h b/bacula/src/version.h index cbf20e0913..3164edbca8 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -4,8 +4,8 @@ #undef VERSION #define VERSION "2.1.2" -#define BDATE "07 February 2007" -#define LSMDATE "07Feb07" +#define BDATE "08 February 2007" +#define LSMDATE "08Feb07" #define PROG_COPYRIGHT "Copyright (C) %d-2007 Free Software Foundation Europe e.V.\n" #define BYEAR "2007" /* year for copyright messages in progs */ diff --git a/bacula/technotes-2.1 b/bacula/technotes-2.1 index a45a683854..d2ab0bdde0 100644 --- a/bacula/technotes-2.1 +++ b/bacula/technotes-2.1 @@ -1,6 +1,16 @@ Technical notes on version 2.1 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 -- 2.39.5