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
* put into the ready queue.
*/
if (jcr->acquired_resource_locks) {
- if (jcr->rstore) {
- jcr->rstore->NumConcurrentJobs--;
- Dmsg1(200, "Dec rncj=%d\n", jcr->rstore->NumConcurrentJobs);
- ASSERT(jcr->rstore->NumConcurrentJobs >= 0);
- }
- if (jcr->wstore) {
- jcr->wstore->NumConcurrentJobs--;
- Dmsg1(200, "Dec wncj=%d\n", jcr->wstore->NumConcurrentJobs);
- ASSERT(jcr->wstore->NumConcurrentJobs >= 0);
- }
+ dec_read_store(jcr);
+ dec_write_store(jcr);
jcr->client->NumConcurrentJobs--;
jcr->job->NumConcurrentJobs--;
jcr->acquired_resource_locks = false;
}
if (jcr->rstore) {
Dmsg1(200, "Rstore=%s\n", jcr->rstore->name());
- if (jcr->rstore->NumConcurrentJobs == 0 &&
+ if (jcr->rstore->NumConcurrentReadJobs == 0 &&
jcr->rstore->NumConcurrentJobs < jcr->rstore->MaxConcurrentJobs) {
/* Simple case, first job */
- jcr->rstore->NumConcurrentJobs = 1;
+ 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) {
+// } 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 {
jcr->wstore->NumConcurrentJobs++;
Dmsg1(200, "Inc wncj=%d\n", jcr->wstore->NumConcurrentJobs);
} else if (jcr->rstore) {
- jcr->rstore->NumConcurrentJobs--; /* back out rstore */
- Dmsg1(200, "Fail wncj=%d\n", jcr->wstore->NumConcurrentJobs);
- ASSERT(jcr->rstore->NumConcurrentJobs >= 0);
+ 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);
- ASSERT(jcr->wstore->NumConcurrentJobs >= 0);
- }
- if (jcr->rstore) {
- jcr->rstore->NumConcurrentJobs--;
- Dmsg1(200, "Dec rncj=%d\n", jcr->rstore->NumConcurrentJobs);
- ASSERT(jcr->rstore->NumConcurrentJobs >= 0);
- }
+ 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);
- ASSERT(jcr->wstore->NumConcurrentJobs >= 0);
- }
- if (jcr->rstore) {
- jcr->rstore->NumConcurrentJobs--;
- Dmsg1(200, "Dec rncj=%d\n", jcr->rstore->NumConcurrentJobs);
- ASSERT(jcr->rstore->NumConcurrentJobs >= 0);
- }
+ 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);
+ }
+}
extern void *start_heap;
/* Forward referenced functions */
-static void list_terminated_jobs(STATUS_PKT *sp, bool api);
-static void list_running_jobs(STATUS_PKT *sp, bool api);
-static void list_status_header(STATUS_PKT *sp, bool api);
+static void list_terminated_jobs(STATUS_PKT *sp);
+static void list_running_jobs(STATUS_PKT *sp);
+static void list_status_header(STATUS_PKT *sp);
static void sendit(const char *msg, int len, STATUS_PKT *sp);
static const char *level_to_str(int level);
*/
void output_status(STATUS_PKT *sp)
{
- list_status_header(sp, false /*no api*/);
- list_running_jobs(sp, false /*no api*/);
- list_terminated_jobs(sp, false /*no api*/);
+ list_status_header(sp);
+ list_running_jobs(sp);
+ list_terminated_jobs(sp);
}
-static void list_status_header(STATUS_PKT *sp, bool api)
+static void list_status_header(STATUS_PKT *sp)
{
POOL_MEM msg(PM_MESSAGE);
char b1[32], b2[32], b3[32], b4[32], b5[35];
sendit(msg.c_str(), len, sp);
}
-static void list_running_jobs(STATUS_PKT *sp, bool api)
+static void list_running_jobs(STATUS_PKT *sp)
{
int sec, bps;
POOL_MEM msg(PM_MESSAGE);
* List running jobs
*/
Dmsg0(1000, "Begin status jcr loop.\n");
- if (!api) {
+ if (!sp->api) {
len = Mmsg(msg, _("\nRunning Jobs:\n"));
sendit(msg.c_str(), len, sp);
}
}
endeach_jcr(njcr);
- if (!api) {
+ if (!sp->api) {
if (!found) {
len = Mmsg(msg, _("No Jobs running.\n"));
sendit(msg.c_str(), len, sp);
}
-static void list_terminated_jobs(STATUS_PKT *sp, bool api)
+static void list_terminated_jobs(STATUS_PKT *sp)
{
char dt[MAX_TIME_LENGTH], b1[30], b2[30];
char level[10];
struct s_last_job *je;
const char *msg;
- if (!api) {
+ if (!sp->api) {
msg = _("\nTerminated Jobs:\n");
sendit(msg, strlen(msg), sp);
}
if (last_jobs->size() == 0) {
- if (!api) sendit(_("====\n"), 5, sp);
+ if (!sp->api) sendit(_("====\n"), 5, sp);
return;
}
lock_last_jobs_list();
- if (!api) {
+ if (!sp->api) {
msg = _(" JobId Level Files Bytes Status Finished Name \n");
sendit(msg, strlen(msg), sp);
msg = _("======================================================================\n");
*p = 0;
}
}
- if (api) {
+ if (sp->api) {
bsnprintf(buf, sizeof(buf), _("%6d\t%-6s\t%8s\t%10s\t%-7s\t%-8s\t%s\n"),
je->JobId,
level,
}
sendit(buf, strlen(buf), sp);
}
- if (!api) sendit(_("====\n"), 5, sp);
+ if (!sp->api) sendit(_("====\n"), 5, sp);
unlock_last_jobs_list();
}
user->fsend("\n");
sp.bs = user;
+ sp.api = false; /* no API output */
output_status(&sp);
user->signal(BNET_EOD);
dir->fsend(DotStatusJob, job->JobId, job->JobStatus, job->Errors);
}
} else if (strcasecmp(cmd, "header") == 0) {
- list_status_header(&sp, true/*api*/);
+ sp.api = true;
+ list_status_header(&sp);
} else if (strcasecmp(cmd, "running") == 0) {
- list_running_jobs(&sp, true/*api*/);
+ sp.api = true;
+ list_running_jobs(&sp);
} else if (strcasecmp(cmd, "terminated") == 0) {
- list_terminated_jobs(&sp, true/*api*/);
+ sp.api = true;
+ list_terminated_jobs(&sp);
} else {
pm_strcpy(&jcr->errmsg, dir->msg);
Jmsg1(jcr, M_FATAL, 0, _("Bad .status command: %s\n"), jcr->errmsg);
static void sendit(const char *msg, int len, void *arg);
static void send_blocked_status(DEVICE *dev, STATUS_PKT *sp);
+static void send_device_status(DEVICE *dev, STATUS_PKT *sp);
static void list_terminated_jobs(STATUS_PKT *sp);
static void list_running_jobs(STATUS_PKT *sp);
static void list_jobs_waiting_on_reservation(STATUS_PKT *sp);
len = Mmsg(msg, _("In Use Volume status:\n"));
- sendit(msg, len, sp);
+ if (!sp->api) sendit(msg, len, sp);
list_volumes(sendit, (void *)sp);
- sendit("====\n\n", 6, sp);
+ if (!sp->api) sendit("====\n\n", 6, sp);
#ifdef xxx
if (debug_level > 10) {
#endif
list_spool_stats(sendit, (void *)sp);
+ if (!sp->api) sendit("====\n\n", 6, sp);
}
int bpb;
len = Mmsg(msg, _("\nDevice status:\n"));
- sendit(msg, len, sp);
+ if (!sp->api) sendit(msg, len, sp);
foreach_res(changer, R_AUTOCHANGER) {
len = Mmsg(msg, _("Autochanger \"%s\" with devices:\n"),
}
}
}
- sendit("====\n\n", 6, sp);
+ if (!sp->api) sendit("====\n\n", 6, sp);
}
static void list_status_header(STATUS_PKT *sp)
}
}
if (debug_level > 1) {
- len = Mmsg(msg, _("Configured device capabilities:\n"));
- sendit(msg, len, sp);
+ send_device_status(dev, sp);
+ }
+}
- len = Mmsg(msg, "%sEOF %sBSR %sBSF %sFSR %sFSF %sEOM %sREM %sRACCESS %sAUTOMOUNT %sLABEL %sANONVOLS %sALWAYSOPEN\n",
- dev->capabilities & CAP_EOF ? "" : "!",
- dev->capabilities & CAP_BSR ? "" : "!",
- dev->capabilities & CAP_BSF ? "" : "!",
- dev->capabilities & CAP_FSR ? "" : "!",
- dev->capabilities & CAP_FSF ? "" : "!",
- dev->capabilities & CAP_EOM ? "" : "!",
- dev->capabilities & CAP_REM ? "" : "!",
- dev->capabilities & CAP_RACCESS ? "" : "!",
- dev->capabilities & CAP_AUTOMOUNT ? "" : "!",
- dev->capabilities & CAP_LABEL ? "" : "!",
- dev->capabilities & CAP_ANONVOLS ? "" : "!",
- dev->capabilities & CAP_ALWAYSOPEN ? "" : "!");
- sendit(msg, len, sp);
+static void send_device_status(DEVICE *dev, STATUS_PKT *sp)
+{
+ POOL_MEM msg(PM_MESSAGE);
+ int len;
- len = Mmsg(msg, _("Device state:\n"));
- sendit(msg, len, sp);
+ len = Mmsg(msg, _("Configured device capabilities:\n"));
+ sendit(msg, len, sp);
- len = Mmsg(msg, "%sOPENED %sTAPE %sLABEL %sMALLOC %sAPPEND %sREAD %sEOT %sWEOT %sEOF %sNEXTVOL %sSHORT %sMOUNTED\n",
- dev->is_open() ? "" : "!",
- dev->is_tape() ? "" : "!",
- dev->is_labeled() ? "" : "!",
- dev->state & ST_MALLOC ? "" : "!",
- dev->can_append() ? "" : "!",
- dev->can_read() ? "" : "!",
- dev->at_eot() ? "" : "!",
- dev->state & ST_WEOT ? "" : "!",
- dev->at_eof() ? "" : "!",
- dev->state & ST_NEXTVOL ? "" : "!",
- dev->state & ST_SHORT ? "" : "!",
- dev->state & ST_MOUNTED ? "" : "!");
- sendit(msg, len, sp);
+ len = Mmsg(msg, "%sEOF %sBSR %sBSF %sFSR %sFSF %sEOM %sREM %sRACCESS %sAUTOMOUNT %sLABEL %sANONVOLS %sALWAYSOPEN\n",
+ dev->capabilities & CAP_EOF ? "" : "!",
+ dev->capabilities & CAP_BSR ? "" : "!",
+ dev->capabilities & CAP_BSF ? "" : "!",
+ dev->capabilities & CAP_FSR ? "" : "!",
+ dev->capabilities & CAP_FSF ? "" : "!",
+ dev->capabilities & CAP_EOM ? "" : "!",
+ dev->capabilities & CAP_REM ? "" : "!",
+ dev->capabilities & CAP_RACCESS ? "" : "!",
+ dev->capabilities & CAP_AUTOMOUNT ? "" : "!",
+ dev->capabilities & CAP_LABEL ? "" : "!",
+ dev->capabilities & CAP_ANONVOLS ? "" : "!",
+ dev->capabilities & CAP_ALWAYSOPEN ? "" : "!");
+ sendit(msg, len, sp);
- len = Mmsg(msg, _("num_writers=%d block=%d\n\n"), dev->num_writers, dev->blocked());
- sendit(msg, len, sp);
+ len = Mmsg(msg, _("Device state:\n"));
+ sendit(msg, len, sp);
- len = Mmsg(msg, _("Device parameters:\n"));
- sendit(msg, len, sp);
+ len = Mmsg(msg, "%sOPENED %sTAPE %sLABEL %sMALLOC %sAPPEND %sREAD %sEOT %sWEOT %sEOF %sNEXTVOL %sSHORT %sMOUNTED\n",
+ dev->is_open() ? "" : "!",
+ dev->is_tape() ? "" : "!",
+ dev->is_labeled() ? "" : "!",
+ dev->state & ST_MALLOC ? "" : "!",
+ dev->can_append() ? "" : "!",
+ dev->can_read() ? "" : "!",
+ dev->at_eot() ? "" : "!",
+ dev->state & ST_WEOT ? "" : "!",
+ dev->at_eof() ? "" : "!",
+ dev->state & ST_NEXTVOL ? "" : "!",
+ dev->state & ST_SHORT ? "" : "!",
+ dev->state & ST_MOUNTED ? "" : "!");
+ sendit(msg, len, sp);
- len = Mmsg(msg, _("Archive name: %s Device name: %s\n"), dev->archive_name(),
- dev->name());
- sendit(msg, len, sp);
+ len = Mmsg(msg, _("num_writers=%d block=%d\n\n"), dev->num_writers, dev->blocked());
+ sendit(msg, len, sp);
- len = Mmsg(msg, _("File=%u block=%u\n"), dev->file, dev->block_num);
- sendit(msg, len, sp);
+ len = Mmsg(msg, _("Device parameters:\n"));
+ sendit(msg, len, sp);
- len = Mmsg(msg, _("Min block=%u Max block=%u\n"), dev->min_block_size, dev->max_block_size);
- sendit(msg, len, sp);
- }
+ len = Mmsg(msg, _("Archive name: %s Device name: %s\n"), dev->archive_name(),
+ dev->name());
+ sendit(msg, len, sp);
+
+ len = Mmsg(msg, _("File=%u block=%u\n"), dev->file, dev->block_num);
+ sendit(msg, len, sp);
+
+ len = Mmsg(msg, _("Min block=%u Max block=%u\n"), dev->min_block_size, dev->max_block_size);
+ sendit(msg, len, sp);
}
static void list_running_jobs(STATUS_PKT *sp)
POOL_MEM msg(PM_MESSAGE);
len = Mmsg(msg, _("\nRunning Jobs:\n"));
- sendit(msg, len, sp);
+ if (!sp->api) sendit(msg, len, sp);
foreach_jcr(jcr) {
if (jcr->JobStatus == JS_WaitFD) {
if (!found) {
len = Mmsg(msg, _("No Jobs running.\n"));
- sendit(msg, len, sp);
+ if (!sp->api) sendit(msg, len, sp);
}
- sendit("====\n", 5, sp);
+ if (!sp->api) sendit("====\n", 5, sp);
}
static void list_jobs_waiting_on_reservation(STATUS_PKT *sp)
int len;
len = Mmsg(msg, _("\nJobs waiting to reserve a drive:\n"));
- sendit(msg, len, sp);
+ if (!sp->api) sendit(msg, len, sp);
foreach_jcr(jcr) {
if (!jcr->reserve_msgs) {
}
endeach_jcr(jcr);
- sendit("====\n", 5, sp);
+ if (!sp->api) sendit("====\n", 5, sp);
}
const char *msg;
msg = _("\nTerminated Jobs:\n");
- sendit(msg, strlen(msg), sp);
+ if (!sp->api) sendit(msg, strlen(msg), sp);
if (last_jobs->size() == 0) {
- sendit("====\n", 5, sp);
+ if (!sp->api) sendit("====\n", 5, sp);
return;
}
lock_last_jobs_list();
msg = _(" JobId Level Files Bytes Status Finished Name \n");
- sendit(msg, strlen(msg), sp);
+ if (!sp->api) sendit(msg, strlen(msg), sp);
msg = _("===================================================================\n");
- sendit(msg, strlen(msg), sp);
+ if (!sp->api) sendit(msg, strlen(msg), sp);
foreach_dlist(je, last_jobs) {
char JobName[MAX_NAME_LENGTH];
const char *termstat;
*p = 0;
}
}
- bsnprintf(buf, sizeof(buf), _("%6d %-6s %8s %10s %-7s %-8s %s\n"),
- je->JobId,
- level,
- edit_uint64_with_commas(je->JobFiles, b1),
- edit_uint64_with_suffix(je->JobBytes, b2),
- termstat,
- dt, JobName);
+ if (sp->api) {
+ bsnprintf(buf, sizeof(buf), _("%6d\t%-6s\t%8s\t%10s\t%-7s\t%-8s\t%s\n"),
+ je->JobId,
+ level,
+ edit_uint64_with_commas(je->JobFiles, b1),
+ edit_uint64_with_suffix(je->JobBytes, b2),
+ termstat,
+ dt, JobName);
+ } else {
+ bsnprintf(buf, sizeof(buf), _("%6d %-6s %8s %10s %-7s %-8s %s\n"),
+ je->JobId,
+ level,
+ edit_uint64_with_commas(je->JobFiles, b1),
+ edit_uint64_with_suffix(je->JobBytes, b2),
+ termstat,
+ dt, JobName);
+ }
sendit(buf, strlen(buf), sp);
}
unlock_last_jobs_list();
- sendit("====\n", 5, sp);
+ if (!sp->api) sendit("====\n", 5, sp);
}
/*
*/
bool status_cmd(JCR *jcr)
{
- BSOCK *bs = jcr->dir_bsock;
+ BSOCK *dir = jcr->dir_bsock;
STATUS_PKT sp;
- bs->fsend("\n");
- sp.bs = bs;
+ dir->fsend("\n");
+ sp.bs = dir;
output_status(&sp);
- bs->signal(BNET_EOD);
- return 1;
+ dir->signal(BNET_EOD);
+ return true;
}
/*
bool qstatus_cmd(JCR *jcr)
{
BSOCK *dir = jcr->dir_bsock;
- POOL_MEM time;
+ POOL_MEM cmd;
JCR *njcr;
s_last_job* job;
+ STATUS_PKT sp;
- if (sscanf(dir->msg, qstatus, time.c_str()) != 1) {
+ sp.bs = dir;
+ if (sscanf(dir->msg, qstatus, cmd.c_str()) != 1) {
pm_strcpy(jcr->errmsg, dir->msg);
Jmsg1(jcr, M_FATAL, 0, _("Bad .status command: %s\n"), jcr->errmsg);
dir->fsend(_("3900 Bad .status command, missing argument.\n"));
dir->signal(BNET_EOD);
return false;
}
- unbash_spaces(time);
+ unbash_spaces(cmd);
+
+ Dmsg1(000, "cmd=%s\n", cmd.c_str());
- if (strcmp(time.c_str(), "current") == 0) {
- dir->fsend(OKqstatus, time.c_str());
+ if (strcmp(cmd.c_str(), "current") == 0) {
+ dir->fsend(OKqstatus, cmd.c_str());
foreach_jcr(njcr) {
if (njcr->JobId != 0) {
dir->fsend(DotStatusJob, njcr->JobId, njcr->JobStatus, njcr->JobErrors);
}
}
endeach_jcr(njcr);
- } else if (strcmp(time.c_str(), "last") == 0) {
- dir->fsend(OKqstatus, time.c_str());
+ } else if (strcmp(cmd.c_str(), "last") == 0) {
+ dir->fsend(OKqstatus, cmd.c_str());
if ((last_jobs) && (last_jobs->size() > 0)) {
job = (s_last_job*)last_jobs->last();
dir->fsend(DotStatusJob, job->JobId, job->JobStatus, job->Errors);
}
+ } else if (strcasecmp(cmd.c_str(), "header") == 0) {
+ sp.api = true;
+ list_status_header(&sp);
+ } else if (strcasecmp(cmd.c_str(), "running") == 0) {
+ sp.api = true;
+ list_running_jobs(&sp);
+ } else if (strcasecmp(cmd.c_str(), "waitreservation") == 0) {
+ sp.api = true;
+ list_jobs_waiting_on_reservation(&sp);
+ } else if (strcasecmp(cmd.c_str(), "devices") == 0) {
+ sp.api = true;
+ list_devices(&sp);
+ } else if (strcasecmp(cmd.c_str(), "volumes") == 0) {
+ sp.api = true;
+ list_volumes(sendit, &sp);
+ } else if (strcasecmp(cmd.c_str(), "spooling") == 0) {
+ sp.api = true;
+ list_spool_stats(sendit, &sp);
+ } else if (strcasecmp(cmd.c_str(), "terminated") == 0) {
+ sp.api = true;
+ list_terminated_jobs(&sp);
} else {
pm_strcpy(jcr->errmsg, dir->msg);
Jmsg1(jcr, M_FATAL, 0, _("Bad .status command: %s\n"), jcr->errmsg);