+/*
+ Bacula® - The Network Backup Solution
+
+ Copyright (C) 2003-2010 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.
+ This program is Free Software; you can redistribute it and/or
+ modify it under the terms of version two of the GNU General Public
+ License as published by the Free Software Foundation and included
+ in the file LICENSE.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ 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.
+*/
/*
* This file handles the status command
*
* Kern Sibbald, May MMIII
*
- * Version $Id$
*
*/
-/*
- Copyright (C) 2003-2005 Kern Sibbald
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- version 2 as amended with additional clauses defined in the
- file LICENSE in the main source directory.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- the file LICENSE for additional details.
-
- */
#include "bacula.h"
#include "stored.h"
+#include "lib/status.h"
/* Exported variables */
/* Imported variables */
extern BSOCK *filed_chan;
-extern int r_first, r_last;
-extern struct s_res resources[];
-extern char my_name[];
-extern time_t daemon_start_time;
-extern int num_jobs_run;
-
+extern void *start_heap;
/* Static variables */
static char qstatus[] = ".status %127s\n";
/* Forward referenced functions */
-static void send_blocked_status(JCR *jcr, DEVICE *dev);
-static void list_terminated_jobs(void *arg);
-static void list_running_jobs(BSOCK *user);
+static void sendit(const char *msg, int len, STATUS_PKT *sp);
+static void sendit(POOL_MEM &msg, int len, STATUS_PKT *sp);
static void sendit(const char *msg, int len, void *arg);
-static const char *level_to_str(int level);
+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);
+static void list_status_header(STATUS_PKT *sp);
+static void list_devices(STATUS_PKT *sp);
+
+static const char *level_to_str(int level);
/*
* Status command from Director
*/
-bool status_cmd(JCR *jcr)
+void output_status(STATUS_PKT *sp)
{
- DEVRES *device;
- AUTOCHANGER *changer;
- DEVICE *dev;
- BSOCK *user = jcr->dir_bsock;
- char dt[MAX_TIME_LENGTH];
- char b1[30], b2[30], b3[30];
- int bpb;
+ POOL_MEM msg(PM_MESSAGE);
+ int len;
- bnet_fsend(user, _("\n%s Version: %s (%s) %s %s %s\n"), my_name,
- VERSION, BDATE, HOST_OS, DISTNAME, DISTVER);
- bstrftime_nc(dt, sizeof(dt), daemon_start_time);
- if (num_jobs_run == 1) {
- bnet_fsend(user, _("Daemon started %s, 1 Job run since started.\n"), dt);
- }
- else {
- bnet_fsend(user, _("Daemon started %s, %d Jobs run since started.\n"), dt, num_jobs_run);
- }
- if (debug_level > 0) {
- char b1[35], b2[35], b3[35], b4[35];
- bnet_fsend(user, _(" Heap: bytes=%s max_bytes=%s bufs=%s max_bufs=%s\n"),
- edit_uint64_with_commas(sm_bytes, b1),
- edit_uint64_with_commas(sm_max_bytes, b2),
- edit_uint64_with_commas(sm_buffers, b3),
- edit_uint64_with_commas(sm_max_buffers, b4));
- }
+ list_status_header(sp);
/*
* List running jobs
*/
- list_running_jobs(user);
+ list_running_jobs(sp);
+
+ /*
+ * List jobs stuck in reservation system
+ */
+ list_jobs_waiting_on_reservation(sp);
/*
* List terminated jobs
*/
- list_terminated_jobs(user);
+ list_terminated_jobs(sp);
/*
* List devices
*/
- bnet_fsend(user, _("\nDevice status:\n"));
+ list_devices(sp);
+
+
+ len = Mmsg(msg, _("Used Volume status:\n"));
+ if (!sp->api) sendit(msg, len, sp);
+
+ list_volumes(sendit, (void *)sp);
+ if (!sp->api) sendit("====\n\n", 6, sp);
+
+#ifdef xxx
+ if (debug_level > 10) {
+ bs->fsend(_("====\n\n"));
+ dump_resource(R_DEVICE, resources[R_DEVICE-r_first].res_head, sendit, user);
+ bs->fsend(_("====\n\n"));
+ }
+#endif
+
+ list_spool_stats(sendit, (void *)sp);
+ if (!sp->api) sendit("====\n\n", 6, sp);
+}
+
+
+static void list_devices(STATUS_PKT *sp)
+{
+ DEVRES *device;
+ AUTOCHANGER *changer;
+ DEVICE *dev;
+ char b1[35], b2[35], b3[35];
+ POOL_MEM msg(PM_MESSAGE);
+ int len;
+ int bpb;
+
+ len = Mmsg(msg, _("\nDevice status:\n"));
+ if (!sp->api) sendit(msg, len, sp);
+
foreach_res(changer, R_AUTOCHANGER) {
- bnet_fsend(user, _("Autochanger \"%s\" with devices:\n"),
+ len = Mmsg(msg, _("Autochanger \"%s\" with devices:\n"),
changer->hdr.name);
+ sendit(msg, len, sp);
+
foreach_alist(device, changer->device) {
if (device->dev) {
- bnet_fsend(user, " %s\n", device->dev->print_name());
+ len = Mmsg(msg, " %s\n", device->dev->print_name());
+ sendit(msg, len, sp);
} else {
- bnet_fsend(user, " %s\n", device->hdr.name);
+ len = Mmsg(msg, " %s\n", device->hdr.name);
+ sendit(msg, len, sp);
}
}
}
dev = device->dev;
if (dev && dev->is_open()) {
if (dev->is_labeled()) {
- bnet_fsend(user, _("Device %s is mounted with Volume \"%s\"\n"),
- dev->print_name(), dev->VolHdr.VolumeName);
+ len = Mmsg(msg, _("Device %s is mounted with:\n"
+ " Volume: %s\n"
+ " Pool: %s\n"
+ " Media type: %s\n"),
+ dev->print_name(),
+ dev->VolHdr.VolumeName,
+ dev->pool_name[0]?dev->pool_name:"*unknown*",
+ dev->device->media_type);
+ sendit(msg, len, sp);
} else {
- bnet_fsend(user, _("Device %s open but no Bacula volume is mounted.\n"),
+ len = Mmsg(msg, _("Device %s open but no Bacula volume is currently mounted.\n"),
dev->print_name());
+ sendit(msg, len, sp);
}
- send_blocked_status(jcr, dev);
+ send_blocked_status(dev, sp);
if (dev->can_append()) {
bpb = dev->VolCatInfo.VolCatBlocks;
if (bpb <= 0) {
bpb = 1;
}
bpb = dev->VolCatInfo.VolCatBytes / bpb;
- bnet_fsend(user, _(" Total Bytes=%s Blocks=%s Bytes/block=%s\n"),
+ len = Mmsg(msg, _(" Total Bytes=%s Blocks=%s Bytes/block=%s\n"),
edit_uint64_with_commas(dev->VolCatInfo.VolCatBytes, b1),
edit_uint64_with_commas(dev->VolCatInfo.VolCatBlocks, b2),
edit_uint64_with_commas(bpb, b3));
+ sendit(msg, len, sp);
} else { /* reading */
bpb = dev->VolCatInfo.VolCatReads;
if (bpb <= 0) {
} else {
bpb = 0;
}
- bnet_fsend(user, _(" Total Bytes Read=%s Blocks Read=%s Bytes/block=%s\n"),
+ len = Mmsg(msg, _(" Total Bytes Read=%s Blocks Read=%s Bytes/block=%s\n"),
edit_uint64_with_commas(dev->VolCatInfo.VolCatRBytes, b1),
edit_uint64_with_commas(dev->VolCatInfo.VolCatReads, b2),
edit_uint64_with_commas(bpb, b3));
+ sendit(msg, len, sp);
}
- bnet_fsend(user, _(" Positioned at File=%s Block=%s\n"),
+ len = Mmsg(msg, _(" Positioned at File=%s Block=%s\n"),
edit_uint64_with_commas(dev->file, b1),
edit_uint64_with_commas(dev->block_num, b2));
+ sendit(msg, len, sp);
} else {
if (dev) {
- bnet_fsend(user, _("Device %s is not open or does not exist.\n"), dev->print_name());
- } else {
- bnet_fsend(user, _("Device \"%s\" is not open or does not exist.\n"), device->hdr.name);
+ len = Mmsg(msg, _("Device %s is not open.\n"), dev->print_name());
+ sendit(msg, len, sp);
+ send_blocked_status(dev, sp);
+ } else {
+ len = Mmsg(msg, _("Device \"%s\" is not open or does not exist.\n"), device->hdr.name);
+ sendit(msg, len, sp);
}
- send_blocked_status(jcr, dev);
}
}
- bnet_fsend(user, _("====\n\n"));
- bnet_fsend(user, _("Volume status:\n"));
- list_volumes(user);
-
+ if (!sp->api) sendit("====\n\n", 6, sp);
+}
-#ifdef xxx
- if (debug_level > 0) {
- bnet_fsend(user, _("====\n\n"));
- dump_resource(R_DEVICE, resources[R_DEVICE-r_first].res_head, sendit, user);
- }
- bnet_fsend(user, _("====\n\n"));
-#endif
+static void list_status_header(STATUS_PKT *sp)
+{
+ char dt[MAX_TIME_LENGTH];
+ char b1[35], b2[35], b3[35], b4[35], b5[35];
+ POOL_MEM msg(PM_MESSAGE);
+ int len;
- list_spool_stats(user);
+ len = Mmsg(msg, _("%s Version: %s (%s) %s %s %s\n"),
+ my_name, VERSION, BDATE, HOST_OS, DISTNAME, DISTVER);
+ sendit(msg, len, sp);
- bnet_sig(user, BNET_EOD);
- return true;
+ bstrftime_nc(dt, sizeof(dt), daemon_start_time);
+
+
+ len = Mmsg(msg, _("Daemon started %s. Jobs: run=%d, running=%d.\n"),
+ dt, num_jobs_run, job_count());
+ sendit(msg, len, sp);
+
+ len = Mmsg(msg, _(" Heap: heap=%s smbytes=%s max_bytes=%s bufs=%s max_bufs=%s\n"),
+ edit_uint64_with_commas((char *)sbrk(0)-(char *)start_heap, b1),
+ edit_uint64_with_commas(sm_bytes, b2),
+ edit_uint64_with_commas(sm_max_bytes, b3),
+ edit_uint64_with_commas(sm_buffers, b4),
+ edit_uint64_with_commas(sm_max_buffers, b5));
+ sendit(msg, len, sp);
+ len = Mmsg(msg, "Sizes: boffset_t=%d size_t=%d int32_t=%d int64_t=%d\n",
+ (int)sizeof(boffset_t), (int)sizeof(size_t), (int)sizeof(int32_t),
+ (int)sizeof(int64_t));
+ sendit(msg, len, sp);
}
-static void send_blocked_status(JCR *jcr, DEVICE *dev)
+static void send_blocked_status(DEVICE *dev, STATUS_PKT *sp)
{
- BSOCK *user = jcr->dir_bsock;
- DCR *dcr = jcr->dcr;
+ POOL_MEM msg(PM_MESSAGE);
+ int len;
if (!dev) {
- bnet_fsend(user, _("No DEVICE structure.\n\n"));
+ len = Mmsg(msg, _("No DEVICE structure.\n\n"));
+ sendit(msg, len, sp);
return;
}
- switch (dev->dev_blocked) {
+ switch (dev->blocked()) {
case BST_UNMOUNTED:
- bnet_fsend(user, _(" Device is BLOCKED. User unmounted.\n"));
+ len = Mmsg(msg, _(" Device is BLOCKED. User unmounted.\n"));
+ sendit(msg, len, sp);
break;
case BST_UNMOUNTED_WAITING_FOR_SYSOP:
- bnet_fsend(user, _(" Device is BLOCKED. User unmounted during wait for media/mount.\n"));
+ len = Mmsg(msg, _(" Device is BLOCKED. User unmounted during wait for media/mount.\n"));
+ sendit(msg, len, sp);
break;
case BST_WAITING_FOR_SYSOP:
- if (jcr->JobStatus == JS_WaitMount) {
- bnet_fsend(user, _(" Device is BLOCKED waiting for mount of volume \"%s\".\n"),
- dcr->VolumeName);
- } else {
- bnet_fsend(user, _(" Device is BLOCKED waiting for media.\n"));
+ {
+ dlist *dcrs = dev->attached_dcrs;
+ bool found_jcr = false;
+
+ if (dcrs != NULL) {
+ DCR *dcr;
+ for (dcr = (DCR *)dcrs->first(); dcr != NULL; dcr = (DCR *)dcrs->next(dcr)) {
+ if (dcr->jcr->JobStatus == JS_WaitMount) {
+ len = Mmsg(msg, _(" Device is BLOCKED waiting for mount of volume \"%s\",\n"
+ " Pool: %s\n"
+ " Media type: %s\n"),
+ dcr->VolumeName,
+ dcr->pool_name,
+ dcr->media_type);
+ sendit(msg, len, sp);
+ found_jcr = true;
+ } else if (dcr->jcr->JobStatus == JS_WaitMedia) {
+ len = Mmsg(msg, _(" Device is BLOCKED waiting to create a volume for:\n"
+ " Pool: %s\n"
+ " Media type: %s\n"),
+ dcr->pool_name,
+ dcr->media_type);
+ sendit(msg, len, sp);
+ found_jcr = true;
+ }
+ }
+ }
+
+ if (!found_jcr) {
+ len = Mmsg(msg, _(" Device is BLOCKED waiting for media.\n"));
+ sendit(msg, len, sp);
+ }
}
break;
case BST_DOING_ACQUIRE:
- bnet_fsend(user, _(" Device is being initialized.\n"));
+ len = Mmsg(msg, _(" Device is being initialized.\n"));
+ sendit(msg, len, sp);
break;
case BST_WRITING_LABEL:
- bnet_fsend(user, _(" Device is blocked labeling a Volume.\n"));
+ len = Mmsg(msg, _(" Device is blocked labeling a Volume.\n"));
+ sendit(msg, len, sp);
break;
default:
break;
}
/* Send autochanger slot status */
if (dev->is_autochanger()) {
- if (dev->Slot) {
- bnet_fsend(user, _(" Slot %d is loaded in drive %d.\n"),
- dev->Slot, dev->drive_index);
+ if (dev->get_slot() > 0) {
+ len = Mmsg(msg, _(" Slot %d is loaded in drive %d.\n"),
+ dev->get_slot(), dev->drive_index);
+ sendit(msg, len, sp);
+ } else if (dev->get_slot() == 0) {
+ len = Mmsg(msg, _(" Drive %d is not loaded.\n"), dev->drive_index);
+ sendit(msg, len, sp);
} else {
- bnet_fsend(user, _(" Drive %d is not loaded.\n"), dev->drive_index);
+ len = Mmsg(msg, _(" Drive %d status unknown.\n"), dev->drive_index);
+ sendit(msg, len, sp);
}
}
if (debug_level > 1) {
- bnet_fsend(user, _("Configured device capabilities:\n"));
- bnet_fsend(user, "%sEOF ", dev->capabilities & CAP_EOF ? "" : "!");
- bnet_fsend(user, "%sBSR ", dev->capabilities & CAP_BSR ? "" : "!");
- bnet_fsend(user, "%sBSF ", dev->capabilities & CAP_BSF ? "" : "!");
- bnet_fsend(user, "%sFSR ", dev->capabilities & CAP_FSR ? "" : "!");
- bnet_fsend(user, "%sFSF ", dev->capabilities & CAP_FSF ? "" : "!");
- bnet_fsend(user, "%sEOM ", dev->capabilities & CAP_EOM ? "" : "!");
- bnet_fsend(user, "%sREM ", dev->capabilities & CAP_REM ? "" : "!");
- bnet_fsend(user, "%sRACCESS ", dev->capabilities & CAP_RACCESS ? "" : "!");
- bnet_fsend(user, "%sAUTOMOUNT ", dev->capabilities & CAP_AUTOMOUNT ? "" : "!");
- bnet_fsend(user, "%sLABEL ", dev->capabilities & CAP_LABEL ? "" : "!");
- bnet_fsend(user, "%sANONVOLS ", dev->capabilities & CAP_ANONVOLS ? "" : "!");
- bnet_fsend(user, "%sALWAYSOPEN ", dev->capabilities & CAP_ALWAYSOPEN ? "" : "!");
- bnet_fsend(user, "\n");
-
- bnet_fsend(user, _("Device state:\n"));
- bnet_fsend(user, "%sOPENED ", dev->is_open() ? "" : "!");
- bnet_fsend(user, "%sTAPE ", dev->is_tape() ? "" : "!");
- bnet_fsend(user, "%sLABEL ", dev->is_labeled() ? "" : "!");
- bnet_fsend(user, "%sMALLOC ", dev->state & ST_MALLOC ? "" : "!");
- bnet_fsend(user, "%sAPPEND ", dev->can_append() ? "" : "!");
- bnet_fsend(user, "%sREAD ", dev->can_read() ? "" : "!");
- bnet_fsend(user, "%sEOT ", dev->at_eot() ? "" : "!");
- bnet_fsend(user, "%sWEOT ", dev->state & ST_WEOT ? "" : "!");
- bnet_fsend(user, "%sEOF ", dev->at_eof() ? "" : "!");
- bnet_fsend(user, "%sNEXTVOL ", dev->state & ST_NEXTVOL ? "" : "!");
- bnet_fsend(user, "%sSHORT ", dev->state & ST_SHORT ? "" : "!");
- bnet_fsend(user, "%sMOUNTED ", dev->state & ST_MOUNTED ? "" : "!");
- bnet_fsend(user, "\n");
- bnet_fsend(user, _("num_writers=%d JobStatus=%c block=%d\n\n"), dev->num_writers,
- jcr->JobStatus, dev->dev_blocked);
-
- bnet_fsend(user, _("Device parameters:\n"));
- bnet_fsend(user, _("Archive name: %s Device name: %s\n"), dev->archive_name(),
- dev->name());
- bnet_fsend(user, _("File=%u block=%u\n"), dev->file, dev->block_num);
- bnet_fsend(user, _("Min block=%u Max block=%u\n"), dev->min_block_size, dev->max_block_size);
+ send_device_status(dev, sp);
}
+}
+static void send_device_status(DEVICE *dev, STATUS_PKT *sp)
+{
+ POOL_MEM msg(PM_MESSAGE);
+ int len;
+
+ len = Mmsg(msg, _("Configured device capabilities:\n"));
+ 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, _("Device state:\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, _("num_writers=%d reserved=%d block=%d\n\n"), dev->num_writers,
+ dev->num_reserved(), dev->blocked());
+ sendit(msg, len, sp);
+
+ len = Mmsg(msg, _("Device parameters:\n"));
+ 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(BSOCK *user)
+static void list_running_jobs(STATUS_PKT *sp)
{
bool found = false;
int bps, sec;
JCR *jcr;
+ DCR *dcr, *rdcr;
char JobName[MAX_NAME_LENGTH];
char b1[30], b2[30], b3[30];
+ int len;
+ POOL_MEM msg(PM_MESSAGE);
+
+ len = Mmsg(msg, _("\nRunning Jobs:\n"));
+ if (!sp->api) sendit(msg, len, sp);
- bnet_fsend(user, _("\nRunning Jobs:\n"));
foreach_jcr(jcr) {
if (jcr->JobStatus == JS_WaitFD) {
- bnet_fsend(user, _("%s Job %s waiting for Client connection.\n"),
- job_type_to_str(jcr->JobType), jcr->Job);
+ len = Mmsg(msg, _("%s Job %s waiting for Client connection.\n"),
+ job_type_to_str(jcr->getJobType()), jcr->Job);
+ sendit(msg, len, sp);
}
- if (jcr->dcr && jcr->dcr->device) {
+ dcr = jcr->dcr;
+ rdcr = jcr->read_dcr;
+ if ((dcr && dcr->device) || (rdcr && rdcr->device)) {
bstrncpy(JobName, jcr->Job, sizeof(JobName));
/* There are three periods after the Job name */
char *p;
*p = 0;
}
}
- bnet_fsend(user, _("%s %s job %s JobId=%d Volume=\"%s\" device=\"%s\"\n"),
- job_level_to_str(jcr->JobLevel),
- job_type_to_str(jcr->JobType),
+ if (rdcr && rdcr->device) {
+ len = Mmsg(msg, _("Reading: %s %s job %s JobId=%d Volume=\"%s\"\n"
+ " pool=\"%s\" device=%s\n"),
+ job_level_to_str(jcr->getJobLevel()),
+ job_type_to_str(jcr->getJobType()),
JobName,
jcr->JobId,
- jcr->dcr->VolumeName,
- jcr->dcr->device->device_name);
+ rdcr->VolumeName,
+ rdcr->pool_name,
+ rdcr->dev?rdcr->dev->print_name():
+ rdcr->device->device_name);
+ sendit(msg, len, sp);
+ }
+ if (dcr && dcr->device) {
+ len = Mmsg(msg, _("Writing: %s %s job %s JobId=%d Volume=\"%s\"\n"
+ " pool=\"%s\" device=%s\n"),
+ job_level_to_str(jcr->getJobLevel()),
+ job_type_to_str(jcr->getJobType()),
+ JobName,
+ jcr->JobId,
+ dcr->VolumeName,
+ dcr->pool_name,
+ dcr->dev?dcr->dev->print_name():
+ dcr->device->device_name);
+ sendit(msg, len, sp);
+ len= Mmsg(msg, _(" spooling=%d despooling=%d despool_wait=%d\n"),
+ dcr->spooling, dcr->despooling, dcr->despool_wait);
+ sendit(msg, len, sp);
+ }
sec = time(NULL) - jcr->run_time;
if (sec <= 0) {
sec = 1;
}
bps = jcr->JobBytes / sec;
- bnet_fsend(user, _(" Files=%s Bytes=%s Bytes/sec=%s\n"),
+ len = Mmsg(msg, _(" Files=%s Bytes=%s Bytes/sec=%s\n"),
edit_uint64_with_commas(jcr->JobFiles, b1),
edit_uint64_with_commas(jcr->JobBytes, b2),
edit_uint64_with_commas(bps, b3));
+ sendit(msg, len, sp);
found = true;
#ifdef DEBUG
if (jcr->file_bsock) {
- bnet_fsend(user, _(" FDReadSeqNo=%s in_msg=%u out_msg=%d fd=%d\n"),
+ len = Mmsg(msg, _(" FDReadSeqNo=%s in_msg=%u out_msg=%d fd=%d\n"),
edit_uint64_with_commas(jcr->file_bsock->read_seqno, b1),
jcr->file_bsock->in_msg_no, jcr->file_bsock->out_msg_no,
- jcr->file_bsock->fd);
+ jcr->file_bsock->m_fd);
+ sendit(msg, len, sp);
} else {
- bnet_fsend(user, _(" FDSocket closed\n"));
+ len = Mmsg(msg, _(" FDSocket closed\n"));
+ sendit(msg, len, sp);
}
#endif
}
- free_jcr(jcr);
}
+ endeach_jcr(jcr);
+
if (!found) {
- bnet_fsend(user, _("No Jobs running.\n"));
+ len = Mmsg(msg, _("No Jobs running.\n"));
+ if (!sp->api) sendit(msg, len, sp);
+ }
+ if (!sp->api) sendit("====\n", 5, sp);
+}
+
+static void list_jobs_waiting_on_reservation(STATUS_PKT *sp)
+{
+ JCR *jcr;
+ POOL_MEM msg(PM_MESSAGE);
+ int len;
+
+ len = Mmsg(msg, _("\nJobs waiting to reserve a drive:\n"));
+ if (!sp->api) sendit(msg, len, sp);
+
+ foreach_jcr(jcr) {
+ if (!jcr->reserve_msgs) {
+ continue;
+ }
+ send_drive_reserve_messages(jcr, sendit, sp);
}
- bnet_fsend(user, _("====\n"));
+ endeach_jcr(jcr);
+
+ if (!sp->api) sendit("====\n", 5, sp);
}
-static void list_terminated_jobs(void *arg)
+
+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;
+ msg = _("\nTerminated Jobs:\n");
+ if (!sp->api) sendit(msg, strlen(msg), sp);
if (last_jobs->size() == 0) {
- msg = _("No Terminated Jobs.\n");
- sendit(msg, strlen(msg), arg);
+ if (!sp->api) sendit("====\n", 5, sp);
return;
}
lock_last_jobs_list();
- msg = _("\nTerminated Jobs:\n");
- sendit(msg, strlen(msg), arg);
- msg = _(" JobId Level Files Bytes Status Finished Name \n");
- sendit(msg, strlen(msg), arg);
- msg = _("======================================================================\n");
- sendit(msg, strlen(msg), arg);
+ msg = _(" JobId Level Files Bytes Status Finished Name \n");
+ if (!sp->api) sendit(msg, strlen(msg), sp);
+ msg = _("===================================================================\n");
+ if (!sp->api) sendit(msg, strlen(msg), sp);
foreach_dlist(je, last_jobs) {
char JobName[MAX_NAME_LENGTH];
const char *termstat;
case JS_Terminated:
termstat = _("OK");
break;
+ case JS_Warnings:
+ termstat = _("OK -- with warnings");
+ break;
default:
termstat = _("Other");
break;
*p = 0;
}
}
- bsnprintf(buf, sizeof(buf), _("%6d %-6s %8s %14s %-7s %-8s %s\n"),
- je->JobId,
- level,
- edit_uint64_with_commas(je->JobFiles, b1),
- edit_uint64_with_commas(je->JobBytes, b2),
- termstat,
- dt, JobName);
- sendit(buf, strlen(buf), arg);
+ 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);
}
- sendit(_("====\n"), 5, arg);
unlock_last_jobs_list();
+ if (!sp->api) sendit("====\n", 5, sp);
}
/*
/*
* Send to Director
*/
-static void sendit(const char *msg, int len, void *arg)
+static void sendit(const char *msg, int len, STATUS_PKT *sp)
+{
+ BSOCK *bs = sp->bs;
+ if (bs) {
+ memcpy(bs->msg, msg, len+1);
+ bs->msglen = len+1;
+ bs->send();
+ } else {
+ sp->callback(msg, len, sp->context);
+ }
+}
+
+static void sendit(const char *msg, int len, void *sp)
+{
+ sendit(msg, len, (STATUS_PKT *)sp);
+}
+
+static void sendit(POOL_MEM &msg, int len, STATUS_PKT *sp)
+{
+ BSOCK *bs = sp->bs;
+ if (bs) {
+ memcpy(bs->msg, msg.c_str(), len+1);
+ bs->msglen = len+1;
+ bs->send();
+ } else {
+ sp->callback(msg.c_str(), len, sp->context);
+ }
+}
+
+
+/*
+ * Status command from Director
+ */
+bool status_cmd(JCR *jcr)
{
- BSOCK *user = (BSOCK *)arg;
+ BSOCK *dir = jcr->dir_bsock;
+ STATUS_PKT sp;
- memcpy(user->msg, msg, len+1);
- user->msglen = len+1;
- bnet_send(user);
+ dir->fsend("\n");
+ sp.bs = dir;
+ output_status(&sp);
+ 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);
- bnet_fsend(dir, _("3900 Bad .status command, missing argument.\n"));
- bnet_sig(dir, BNET_EOD);
+ dir->fsend(_("3900 Bad .status command, missing argument.\n"));
+ dir->signal(BNET_EOD);
return false;
}
- unbash_spaces(time);
+ unbash_spaces(cmd);
+
+ Dmsg1(200, "cmd=%s\n", cmd.c_str());
- if (strcmp(time.c_str(), "current") == 0) {
- bnet_fsend(dir, OKqstatus, time.c_str());
+ if (strcmp(cmd.c_str(), "current") == 0) {
+ dir->fsend(OKqstatus, cmd.c_str());
foreach_jcr(njcr) {
if (njcr->JobId != 0) {
- bnet_fsend(dir, DotStatusJob, njcr->JobId, njcr->JobStatus, njcr->JobErrors);
+ dir->fsend(DotStatusJob, njcr->JobId, njcr->JobStatus, njcr->JobErrors);
}
- free_jcr(njcr);
}
- }
- else if (strcmp(time.c_str(), "last") == 0) {
- bnet_fsend(dir, OKqstatus, time.c_str());
+ endeach_jcr(njcr);
+ } 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();
- bnet_fsend(dir, DotStatusJob, job->JobId, job->JobStatus, job->Errors);
+ dir->fsend(DotStatusJob, job->JobId, job->JobStatus, job->Errors);
}
- }
- else {
+ } 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);
- bnet_fsend(dir, _("3900 Bad .status command, wrong argument.\n"));
- bnet_sig(dir, BNET_EOD);
+ dir->fsend(_("3900 Bad .status command, wrong argument.\n"));
+ dir->signal(BNET_EOD);
return false;
}
- bnet_sig(dir, BNET_EOD);
+ dir->signal(BNET_EOD);
return true;
}
+
+#if defined(HAVE_WIN32)
+int bacstat = 0;
+
+/* Return a one line status for the tray monitor */
+char *bac_status(char *buf, int buf_len)
+{
+ JCR *njcr;
+ const char *termstat = _("Bacula Storage: Idle");
+ struct s_last_job *job;
+ int stat = 0; /* Idle */
+
+ if (!last_jobs) {
+ goto done;
+ }
+ Dmsg0(1000, "Begin bac_status jcr loop.\n");
+ foreach_jcr(njcr) {
+ if (njcr->JobId != 0) {
+ stat = JS_Running;
+ termstat = _("Bacula Storage: Running");
+ break;
+ }
+ }
+ endeach_jcr(njcr);
+
+ if (stat != 0) {
+ goto done;
+ }
+ if (last_jobs->size() > 0) {
+ job = (struct s_last_job *)last_jobs->last();
+ stat = job->JobStatus;
+ switch (job->JobStatus) {
+ case JS_Canceled:
+ termstat = _("Bacula Storage: Last Job Canceled");
+ break;
+ case JS_ErrorTerminated:
+ case JS_FatalError:
+ termstat = _("Bacula Storage: Last Job Failed");
+ break;
+ default:
+ if (job->Errors) {
+ termstat = _("Bacula Storage: Last Job had Warnings");
+ }
+ break;
+ }
+ }
+ Dmsg0(1000, "End bac_status jcr loop.\n");
+done:
+ bacstat = stat;
+ if (buf) {
+ bstrncpy(buf, termstat, buf_len);
+ }
+ return buf;
+}
+
+#endif /* HAVE_WIN32 */