+ Dmsg2(dbglevel, "Pool Occupancy ids=%d MediaIds=%s\n", ids.count, ids.list);
+
+ if (!find_jobids_from_mediaid_list(jcr, &ids, "Volume")) {
+ goto bail_out;
+ }
+ /* ids == list of jobs */
+ p = ids.list;
+ for (int i=0; i < (int)ids.count; i++) {
+ stat = get_next_dbid_from_list(&p, &DBId);
+ Dmsg2(dbglevel, "get_next_dbid stat=%d JobId=%u\n", stat, (uint32_t)DBId);
+ if (stat < 0) {
+ Jmsg(jcr, M_FATAL, 0, _("Invalid JobId found.\n"));
+ goto bail_out;
+ } else if (stat == 0) {
+ break;
+ }
+
+ mid.count = 1;
+ Mmsg(mid.list, "%s", edit_int64(DBId, ed1));
+ if (jids.count > 0) {
+ pm_strcat(jids.list, ",");
+ }
+ pm_strcat(jids.list, mid.list);
+ jids.count += mid.count;
+
+ /* Find count of bytes from Jobs */
+ Mmsg(query, sql_job_bytes, mid.list);
+ Dmsg1(dbglevel, "Jobbytes query: %s\n", query.c_str());
+ if (!db_sql_query(jcr->db, query.c_str(), db_int64_handler, (void *)&ctx)) {
+ Jmsg(jcr, M_FATAL, 0, _("SQL failed. ERR=%s\n"), db_strerror(jcr->db));
+ goto bail_out;
+ }
+ pool_bytes -= ctx.value;
+ Dmsg2(dbglevel, "Total %s Job bytes=%s\n", jcr->get_ActionName(0), edit_int64_with_commas(ctx.value, ed1));
+ Dmsg2(dbglevel, "lowbytes=%s poolafter=%s\n",
+ edit_int64_with_commas(jcr->rpool->MigrationLowBytes, ed1),
+ edit_int64_with_commas(pool_bytes, ed2));
+ if (pool_bytes <= (int64_t)jcr->rpool->MigrationLowBytes) {
+ Dmsg0(dbglevel, "We should be done.\n");
+ break;
+ }
+ }
+ /* Transfer jids to ids, where the jobs list is expected */
+ ids.count = jids.count;
+ pm_strcpy(ids.list, jids.list);
+ Dmsg2(dbglevel, "Pool Occupancy ids=%d JobIds=%s\n", ids.count, ids.list);