From: Michal Rakowski Date: Mon, 30 Aug 2021 08:54:56 +0000 (+0200) Subject: Fix #8098 About director crash for Migration job X-Git-Tag: Release-11.3.2~357 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0c8658a11adc954bc72ae20a4800a5dabdd05936;p=thirdparty%2Fbacula.git Fix #8098 About director crash for Migration job All of the 'read' storage groups members have to be incremented/decremented instead of just first on from the list. --- diff --git a/bacula/src/dird/store_mngr.c b/bacula/src/dird/store_mngr.c index 45383fc72..fa204000c 100644 --- a/bacula/src/dird/store_mngr.c +++ b/bacula/src/dird/store_mngr.c @@ -150,69 +150,82 @@ bool storage::set_current_storage(STORE *storage) { return false; } -bool storage::inc_rstores(JCR *jcr) { - lock_guard lg(mutex); - - if (list->empty()) { +/* Returns true if it was possible to increment Storage's write counter, + * returns false otherwise */ +static bool inc_wstore(STORE *wstore) { + Dmsg1(dbglvl, "Wstore=%s\n", wstore->name()); + int num = wstore->getNumConcurrentJobs(); + if (num < wstore->MaxConcurrentJobs) { + num = wstore->incNumConcurrentJobs(1); + Dmsg2(dbglvl, "Store: %s Inc wncj=%d\n", wstore->name(), num); return true; } - int num = store->getNumConcurrentJobs(); - int numread = store->getNumConcurrentReadJobs(); - int maxread = store->MaxConcurrentReadJobs; - if (num < store->MaxConcurrentJobs && + return false; +} + +/* Returns true if it was possible to increment Storage's read counter, + * returns false otherwise */ +static bool inc_rstore(JCR *jcr, STORE *rstore) { + int num = rstore->getNumConcurrentJobs(); + int numread = rstore->getNumConcurrentReadJobs(); + int maxread = rstore->MaxConcurrentReadJobs; + if (num < rstore->MaxConcurrentJobs && (jcr->getJobType() == JT_RESTORE || numread == 0 || maxread == 0 || /* No limit set */ numread < maxread)) /* Below the limit */ { - numread = store->incNumConcurrentReadJobs(1); - num = store->incNumConcurrentJobs(1); - Dmsg2(dbglvl, "Store: %s Inc rncj=%d\n", store->name(), num); + numread = rstore->incNumConcurrentReadJobs(1); + num = rstore->incNumConcurrentJobs(1); + Dmsg3(dbglvl, "Store: %s Inc ncj= %d rncj=%d\n", rstore->name(), num, numread); return true; } return false; } -bool storage::inc_wstores(JCR *jcr) { - STORE *store; - bool ret; +bool storage::inc_stores(JCR *jcr) { lock_guard lg(mutex); + STORE *tmp_store; + bool ret = false; /* Set if any of the storages in the list was incremented */ if (list->empty()) { return true; } - /* Create a temp copy of wstore list */ + /* Create a temp copy of the store list */ alist *tmp_list = New(alist(10, not_owned_by_alist)); if (!tmp_list) { Dmsg1(dbglvl, "Failed to allocate tmp list for jobid: %d\n", jcr->JobId); return false; } - foreach_alist(store, list) { - tmp_list->append(store); + foreach_alist(tmp_store, list) { + tmp_list->append(tmp_store); } - /* Reset write list */ + /* Reset list */ list->destroy(); list->init(10, not_owned_by_alist); - foreach_alist(store, tmp_list) { - Dmsg1(dbglvl, "Wstore=%s\n", store->name()); - int num = store->getNumConcurrentJobs(); - if (num < store->MaxConcurrentJobs) { - num = store->incNumConcurrentJobs(1); - Dmsg2(dbglvl, "Store: %s Inc wncj=%d\n", store->name(), num); - list->append(store); + foreach_alist(tmp_store, tmp_list) { + if (write) { + if (inc_wstore(tmp_store)) { + /* Counter incremented, can be added to list */ + list->append(tmp_store); + } + } else if (inc_rstore(jcr, tmp_store)) { + /* Counter incremented, can be added to list */ + list->append(tmp_store); } } if (!list->empty()) { + /* We were able to increment at least 1 storage from the list */ ret = true; } else { - /* Failed to increment counter in at least one storage */ + /* Failed to increment counter for at least one storage */ ret = false; } @@ -228,14 +241,6 @@ bool storage::inc_wstores(JCR *jcr) { return ret; } -bool storage::inc_stores(JCR *jcr) { - if (write) { - return inc_wstores(jcr); - } else { - return inc_rstores(jcr); - } -} - void storage::dec_stores() { lock_guard lg(mutex);