]> git.sur5r.net Git - bacula/bacula/commitdiff
kes Fix bug with job name duplication if more than 60 jobs created
authorKern Sibbald <kern@sibbald.com>
Fri, 7 Nov 2008 16:26:48 +0000 (16:26 +0000)
committerKern Sibbald <kern@sibbald.com>
Fri, 7 Nov 2008 16:26:48 +0000 (16:26 +0000)
     during a minute.
kes  Correct some bugs of cleanup in SD if the FD connection fails.

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/branches/Branch-2.4@8012 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/patches/2.4.3-jobs.patch [new file with mode: 0644]
bacula/patchnotes-2.4
bacula/src/dird/job.c
bacula/src/lib/bnet_server.c
bacula/src/stored/job.c
bacula/src/version.h
bacula/technotes-2.4

diff --git a/bacula/patches/2.4.3-jobs.patch b/bacula/patches/2.4.3-jobs.patch
new file mode 100644 (file)
index 0000000..25d2d3c
--- /dev/null
@@ -0,0 +1,127 @@
+
+ This patch corrects two problems:
+ 1. If you start more than 60 jobs within a 1 minute period, the unique
+    jobname (critical for the daemons) can be duplicated leading to 
+    authentication failures and orphaned jobs.
+ 2. FD jobs that fail SD authentication were not properly cleaned up.
+
+ Apply it to Bacula 2.4.3 (possibly earlier versions)
+ with:
+
+ cd <bacula-source>
+ patch -p0 <2.4.3-jobs.patch
+ ./configure <your-options>
+ make
+ ...
+ make install
+
+
+Index: src/dird/job.c
+===================================================================
+--- src/dird/job.c     (revision 8011)
++++ src/dird/job.c     (working copy)
+@@ -758,17 +758,17 @@
+    static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+    static time_t last_start_time = 0;
+    static int seq = 0;
+-   time_t now;
++   time_t now = time(NULL);
+    struct tm tm;
+    char dt[MAX_TIME_LENGTH];
+    char name[MAX_NAME_LENGTH];
+    char *p;
++   int len;
+    /* Guarantee unique start time -- maximum one per second, and
+     * thus unique Job Name
+     */
+    P(mutex);                          /* lock creation of jobs */
+-   now = time(NULL);
+    seq++;
+    if (seq > 59) {                    /* wrap as if it is seconds */
+       seq = 0;
+@@ -783,9 +783,10 @@
+    /* Form Unique JobName */
+    (void)localtime_r(&now, &tm);
+    /* Use only characters that are permitted in Windows filenames */
+-   strftime(dt, sizeof(dt), "%Y-%m-%d_%H.%M", &tm);
++   strftime(dt, sizeof(dt), "%Y-%m-%d_%H.%M.%S", &tm);
++   len = strlen(dt) + 5;   /* dt + .%02d EOS */
+    bstrncpy(name, base_name, sizeof(name));
+-   name[sizeof(name)-22] = 0;          /* truncate if too long */
++   name[sizeof(name)-len] = 0;          /* truncate if too long */
+    bsnprintf(jcr->Job, sizeof(jcr->Job), "%s.%s.%02d", name, dt, seq); /* add date & time */
+    /* Convert spaces into underscores */
+    for (p=jcr->Job; *p; p++) {
+@@ -793,6 +794,7 @@
+          *p = '_';
+       }
+    }
++   Dmsg2(100, "JobId=%u created Job=%s\n", jcr->JobId, jcr->Job);
+ }
+ /* Called directly from job rescheduling */
+Index: src/stored/job.c
+===================================================================
+--- src/stored/job.c   (revision 8011)
++++ src/stored/job.c   (working copy)
+@@ -228,21 +228,25 @@
+    if (!(jcr=get_jcr_by_full_name(job_name))) {
+       Jmsg1(NULL, M_FATAL, 0, _("FD connect failed: Job name not found: %s\n"), job_name);
+       Dmsg1(3, "**** Job \"%s\" not found\n", job_name);
++      fd->close();
+       return;
+    }
+-   jcr->file_bsock = fd;
+-   jcr->file_bsock->set_jcr(jcr);
+-
+    Dmsg1(110, "Found Job %s\n", job_name);
+    if (jcr->authenticated) {
+       Jmsg2(jcr, M_FATAL, 0, _("Hey!!!! JobId %u Job %s already authenticated.\n"),
+          (uint32_t)jcr->JobId, jcr->Job);
++      Dmsg2(50, "Hey!!!! JobId %u Job %s already authenticated.\n",
++         (uint32_t)jcr->JobId, jcr->Job);
++      fd->close();
+       free_jcr(jcr);
+       return;
+    }
++   jcr->file_bsock = fd;
++   jcr->file_bsock->set_jcr(jcr);
++
+    /*
+     * Authenticate the File daemon
+     */
+Index: src/lib/bnet_server.c
+===================================================================
+--- src/lib/bnet_server.c      (revision 8011)
++++ src/lib/bnet_server.c      (working copy)
+@@ -1,7 +1,7 @@
+ /*
+    Bacula® - The Network Backup Solution
+-   Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
++   Copyright (C) 2000-2008 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.
+@@ -20,7 +20,7 @@
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+    02110-1301, USA.
+-   Bacula® is a registered trademark of John Walker.
++   Bacula® is a registered trademark of Kern Sibbald.
+    The licensor of Bacula is the Free Software Foundation Europe
+    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+    Switzerland, email:ftf@fsfeurope.org.
+@@ -137,7 +137,7 @@
+                   be.bstrerror());
+          }
+       }
+-      listen(fd_ptr->fd, 5);       /* tell system we are ready */
++      listen(fd_ptr->fd, 20);      /* tell system we are ready */
+       sockfds.append(fd_ptr);
+    }
+    /* Start work queue thread */
index 0a3b0c6f468d5c84b46362dffb1e352a9dcbe672..a2530c6f208b2c14966f21f5e376600bad331457 100644 (file)
@@ -6,6 +6,7 @@ Patches Released to Source Forge:
 
 Patches Committed:
 28Oct08
+2.4.3-jobs.patch
 2.4.3-orphaned-jobs.patch
 2.4.3-migrate-log.patch
 2.4.3-migrate.patch
@@ -14,6 +15,12 @@ Patches Committed:
 2.4.3-win32-runscript-unicode-path.patch
 
 Patches being Tested:
+07Nov08
+2.4.3-jobs.patch
+kes If you start more than 60 jobs within a 1 minute period, the unique
+    jobname (critical for the daemons) can be duplicated leading to 
+    authentication failures and orphaned jobs.
+kes FD jobs that fail SD authentication were not properly cleaned up.
 03Nov08
 2.4.3-getmsg.patch
 kes  Patch to use BSOCK jcr rather than searching for it.
index 5ee7cd02bd1069f75f066462f192f21ddb9bc83b..07b9dff7f4746d512c51ef086da3e93f4c7a072e 100644 (file)
@@ -758,17 +758,17 @@ void create_unique_job_name(JCR *jcr, const char *base_name)
    static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
    static time_t last_start_time = 0;
    static int seq = 0;
-   time_t now;
+   time_t now = time(NULL);
    struct tm tm;
    char dt[MAX_TIME_LENGTH];
    char name[MAX_NAME_LENGTH];
    char *p;
+   int len;
 
    /* Guarantee unique start time -- maximum one per second, and
     * thus unique Job Name
     */
    P(mutex);                          /* lock creation of jobs */
-   now = time(NULL);
    seq++;
    if (seq > 59) {                    /* wrap as if it is seconds */
       seq = 0;
@@ -783,9 +783,10 @@ void create_unique_job_name(JCR *jcr, const char *base_name)
    /* Form Unique JobName */
    (void)localtime_r(&now, &tm);
    /* Use only characters that are permitted in Windows filenames */
-   strftime(dt, sizeof(dt), "%Y-%m-%d_%H.%M", &tm);
+   strftime(dt, sizeof(dt), "%Y-%m-%d_%H.%M.%S", &tm);
+   len = strlen(dt) + 5;   /* dt + .%02d EOS */
    bstrncpy(name, base_name, sizeof(name));
-   name[sizeof(name)-22] = 0;          /* truncate if too long */
+   name[sizeof(name)-len] = 0;          /* truncate if too long */
    bsnprintf(jcr->Job, sizeof(jcr->Job), "%s.%s.%02d", name, dt, seq); /* add date & time */
    /* Convert spaces into underscores */
    for (p=jcr->Job; *p; p++) {
@@ -793,6 +794,7 @@ void create_unique_job_name(JCR *jcr, const char *base_name)
          *p = '_';
       }
    }
+   Dmsg2(100, "JobId=%u created Job=%s\n", jcr->JobId, jcr->Job);
 }
 
 /* Called directly from job rescheduling */
index d6bac6de0523b447fa8a1a045c41efa2fa793b63..320278801a3e64c06fca44ece14bb2b7503b067b 100644 (file)
@@ -1,7 +1,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2008 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.
@@ -20,7 +20,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Bacula® is a registered trademark of John Walker.
+   Bacula® is a registered trademark of Kern Sibbald.
    The licensor of Bacula is the Free Software Foundation Europe
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
@@ -137,7 +137,7 @@ bnet_thread_server(dlist *addrs, int max_clients, workq_t *client_wq,
                   be.bstrerror());
          }
       }
-      listen(fd_ptr->fd, 5);       /* tell system we are ready */
+      listen(fd_ptr->fd, 20);      /* tell system we are ready */
       sockfds.append(fd_ptr);
    }
    /* Start work queue thread */
index 10443ceb5f9fe8070f47a5e91b2d5194c36d3d6a..79ae1cf9a9b0c5b16bde7f4a6c065eb0ac9a8c16 100644 (file)
@@ -228,21 +228,25 @@ void handle_filed_connection(BSOCK *fd, char *job_name)
    if (!(jcr=get_jcr_by_full_name(job_name))) {
       Jmsg1(NULL, M_FATAL, 0, _("FD connect failed: Job name not found: %s\n"), job_name);
       Dmsg1(3, "**** Job \"%s\" not found\n", job_name);
+      fd->close();
       return;
    }
 
-   jcr->file_bsock = fd;
-   jcr->file_bsock->set_jcr(jcr);
-
    Dmsg1(110, "Found Job %s\n", job_name);
 
    if (jcr->authenticated) {
       Jmsg2(jcr, M_FATAL, 0, _("Hey!!!! JobId %u Job %s already authenticated.\n"),
          (uint32_t)jcr->JobId, jcr->Job);
+      Dmsg2(50, "Hey!!!! JobId %u Job %s already authenticated.\n",
+         (uint32_t)jcr->JobId, jcr->Job);
+      fd->close();
       free_jcr(jcr);
       return;
    }
 
+   jcr->file_bsock = fd;
+   jcr->file_bsock->set_jcr(jcr);
+
    /*
     * Authenticate the File daemon
     */
index 13204b757547bb4c0aabf56ac395898dbd186b26..ed2d57a5511772ddf615f84e99370e032dad1da1 100644 (file)
@@ -3,9 +3,9 @@
  */
 
 #undef  VERSION
-#define VERSION "2.4.3"
-#define BDATE   "28 October 2008"
-#define LSMDATE "28Oct08"
+#define VERSION "2.4.4"
+#define BDATE   "07 November 2008"
+#define LSMDATE "07Nov08"
 
 #define PROG_COPYRIGHT "Copyright (C) %d-2008 Free Software Foundation Europe e.V.\n"
 #define BYEAR "2008"       /* year for copyright messages in progs */
index 01548ef6a1fc46429766a4e80bb0fb1fb0852426..ddaad5cb04297d2cc1eff4365690496720260992 100644 (file)
@@ -1,6 +1,10 @@
               Technical notes on version 2.4
 
 General:
+07Nov08
+kes  Fix bug with job name duplication if more than 60 jobs created
+     during a minute.
+kes  Correct some bugs of cleanup in SD if the FD connection fails.
 02Nov08
 kes  Fix orphaned jobs (possible deadlock) while pruning.
 31Oct08