/*
Bacula® - The Network Backup Solution
- Copyright (C) 2003-2007 Free Software Foundation Europe e.V.
+ Copyright (C) 2003-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.
static int start_server(jobq_t *jq);
static bool acquire_resources(JCR *jcr);
-
-
+static void dec_read_store(JCR *jcr);
+static void dec_write_store(JCR *jcr);
/*
* Initialize a job queue
pthread_t id;
/*
- * if any threads are idle, wake one --
- * actually we do a broadcast because on /lib/tls
+ * if any threads are idle, wake one.
+ * Actually we do a broadcast because on /lib/tls
* these signals seem to get lost from time to time.
*/
if (jq->idle_workers > 0) {
* put into the ready queue.
*/
if (jcr->acquired_resource_locks) {
- if (jcr->rstore) {
- jcr->rstore->NumConcurrentJobs = 0;
- Dmsg1(200, "Dec rncj=%d\n", jcr->rstore->NumConcurrentJobs);
- }
- if (jcr->wstore) {
- jcr->wstore->NumConcurrentJobs--;
- Dmsg1(200, "Dec wncj=%d\n", jcr->wstore->NumConcurrentJobs);
- }
+ dec_read_store(jcr);
+ dec_write_store(jcr);
jcr->client->NumConcurrentJobs--;
jcr->job->NumConcurrentJobs--;
jcr->acquired_resource_locks = false;
bool skip_this_jcr = false;
jcr->acquired_resource_locks = false;
+ if (jcr->rstore == jcr->wstore) { /* deadlock */
+ Jmsg(jcr, M_FATAL, 0, _("Job canceled. Attempt to read and write same device.\n"
+ " Read storage \"%s\" (From %s) -- Write storage \"%s\" (From %s)\n"),
+ jcr->rstore->name(), jcr->rstore_source, jcr->wstore->name(), jcr->wstore_source);
+ set_jcr_job_status(jcr, JS_Canceled);
+ return false;
+ }
if (jcr->rstore) {
Dmsg1(200, "Rstore=%s\n", jcr->rstore->name());
- /*
- * Let only one Restore/Verify job run at a time regardless
- * of MaxConcurrentjobs.
- */
- if (jcr->rstore->NumConcurrentJobs == 0) {
- jcr->rstore->NumConcurrentJobs = 1;
+ if (jcr->rstore->NumConcurrentReadJobs == 0 &&
+ jcr->rstore->NumConcurrentJobs < jcr->rstore->MaxConcurrentJobs) {
+ /* Simple case, first job */
+ jcr->rstore->NumConcurrentReadJobs = 1;
+ jcr->rstore->NumConcurrentJobs++;
Dmsg0(200, "Set rncj=1\n");
+ /* We can do this only if multi-drive autochanger */
+// } else if (jcr->rstore->NumConcurrentJobs < jcr->rstore->MaxConcurrentJobs
+// && jcr->rstore->NumConcurrentReadJobs < jcr->rstore->MaxConcurrentReadJobs) {
+// jcr->rstore->NumConcurrentReadJobs++;
+// jcr->rstore->NumConcurrentJobs++;
+// Dmsg1(200, "Inc rncj=%d\n", jcr->rstore->NumConcurrentJobs);
} else {
Dmsg1(200, "Fail rncj=%d\n", jcr->rstore->NumConcurrentJobs);
set_jcr_job_status(jcr, JS_WaitStoreRes);
if (jcr->wstore) {
Dmsg1(200, "Wstore=%s\n", jcr->wstore->name());
- if (jcr->rstore == jcr->wstore) { /* deadlock */
- jcr->rstore->NumConcurrentJobs = 0; /* back out rstore */
- Jmsg(jcr, M_FATAL, 0, _("Job canceled. Attempt to read and write same device.\n"
- " Read storage \"%s\" (From %s) -- Write storage \"%s\" (From %s)\n"),
- jcr->rstore->name(), jcr->rstore_source, jcr->wstore->name(), jcr->wstore_source);
- set_jcr_job_status(jcr, JS_Canceled);
- return false;
- }
if (jcr->wstore->NumConcurrentJobs == 0 &&
jcr->wstore->NumConcurrentJobs < jcr->wstore->MaxConcurrentJobs) {
/* Simple case, first job */
jcr->wstore->NumConcurrentJobs++;
Dmsg1(200, "Inc wncj=%d\n", jcr->wstore->NumConcurrentJobs);
} else if (jcr->rstore) {
- jcr->rstore->NumConcurrentJobs = 0; /* back out rstore */
- Dmsg1(200, "Fail wncj=%d\n", jcr->wstore->NumConcurrentJobs);
+ dec_read_store(jcr);
skip_this_jcr = true;
} else {
Dmsg1(200, "Fail wncj=%d\n", jcr->wstore->NumConcurrentJobs);
jcr->client->NumConcurrentJobs++;
} else {
/* Back out previous locks */
- if (jcr->wstore) {
- jcr->wstore->NumConcurrentJobs--;
- Dmsg1(200, "Dec wncj=%d\n", jcr->wstore->NumConcurrentJobs);
- }
- if (jcr->rstore) {
- jcr->rstore->NumConcurrentJobs = 0;
- Dmsg1(200, "Dec rncj=%d\n", jcr->rstore->NumConcurrentJobs);
- }
+ dec_write_store(jcr);
+ dec_read_store(jcr);
set_jcr_job_status(jcr, JS_WaitClientRes);
return false;
}
jcr->job->NumConcurrentJobs++;
} else {
/* Back out previous locks */
- if (jcr->wstore) {
- jcr->wstore->NumConcurrentJobs--;
- Dmsg1(200, "Dec wncj=%d\n", jcr->wstore->NumConcurrentJobs);
- }
- if (jcr->rstore) {
- jcr->rstore->NumConcurrentJobs = 0;
- Dmsg1(200, "Dec rncj=%d\n", jcr->rstore->NumConcurrentJobs);
- }
+ dec_write_store(jcr);
+ dec_read_store(jcr);
jcr->client->NumConcurrentJobs--;
set_jcr_job_status(jcr, JS_WaitJobRes);
return false;
jcr->acquired_resource_locks = true;
return true;
}
+
+static void dec_read_store(JCR *jcr)
+{
+ if (jcr->rstore) {
+ jcr->rstore->NumConcurrentReadJobs--; /* back out rstore */
+ jcr->rstore->NumConcurrentJobs--; /* back out rstore */
+ Dmsg1(200, "Dec wncj=%d\n", jcr->wstore->NumConcurrentJobs);
+ ASSERT(jcr->rstore->NumConcurrentReadJobs >= 0);
+ ASSERT(jcr->rstore->NumConcurrentJobs >= 0);
+ }
+}
+
+static void dec_write_store(JCR *jcr)
+{
+ if (jcr->wstore) {
+ jcr->wstore->NumConcurrentJobs--;
+ Dmsg1(200, "Dec wncj=%d\n", jcr->wstore->NumConcurrentJobs);
+ ASSERT(jcr->wstore->NumConcurrentJobs >= 0);
+ }
+}