2 * This file handles the status command
4 * Kern Sibbald, May MMIII
10 Copyright (C) 2000-2003 Kern Sibbald and John Walker
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation; either version 2 of
15 the License, or (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public
23 License along with this program; if not, write to the Free
24 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
32 /* Exported variables */
34 /* Imported variables */
35 extern BSOCK *filed_chan;
36 extern int r_first, r_last;
37 extern struct s_res resources[];
38 extern char my_name[];
39 extern time_t daemon_start_time;
40 extern struct s_last_job last_job;
42 /* Static variables */
45 /* Forward referenced functions */
46 static void send_blocked_status(JCR *jcr, DEVICE *dev);
47 static void list_terminated_jobs(void *arg);
48 static void sendit(char *msg, int len, void *arg);
49 static char *level_to_str(int level);
53 * Status command from Director
55 int status_cmd(JCR *jcr)
59 int found, bps, sec, bpb;
60 BSOCK *user = jcr->dir_bsock;
61 char dt[MAX_TIME_LENGTH];
62 char b1[30], b2[30], b3[30];
64 bnet_fsend(user, "\n%s Version: " VERSION " (" BDATE ") %s %s %s\n", my_name,
65 HOST_OS, DISTNAME, DISTVER);
66 bstrftime(dt, sizeof(dt), daemon_start_time);
67 bnet_fsend(user, _("Daemon started %s, %d Job%s run.\n"), dt, last_job.NumJobs,
68 last_job.NumJobs == 1 ? "" : "s");
71 * List terminated jobs
73 list_terminated_jobs(user);
77 bstrftime(dt, sizeof(dt), last_job.end_time);
78 bnet_fsend(user, _("Last Job %s finished at %s\n"), last_job.Job, dt);
80 jobstatus_to_ascii(last_job.JobStatus, termstat, sizeof(termstat));
81 bnet_fsend(user, _(" Files=%s Bytes=%s Termination Status=%s\n"),
82 edit_uint64_with_commas(last_job.JobFiles, b1),
83 edit_uint64_with_commas(last_job.JobBytes, b2),
91 for (device=NULL; (device=(DEVRES *)GetNextRes(R_DEVICE, (RES *)device)); ) {
92 for (dev=device->dev; dev; dev=dev->next) {
93 if (dev->state & ST_OPENED) {
94 if (dev->state & ST_LABEL) {
95 bnet_fsend(user, _("Device %s is mounted with Volume \"%s\"\n"),
96 dev_name(dev), dev->VolHdr.VolName);
98 bnet_fsend(user, _("Device %s open but no Bacula volume is mounted.\n"), dev_name(dev));
100 send_blocked_status(jcr, dev);
101 if (dev->state & ST_APPEND) {
102 bpb = dev->VolCatInfo.VolCatBlocks;
106 bpb = dev->VolCatInfo.VolCatBytes / bpb;
107 bnet_fsend(user, _(" Total Bytes=%s Blocks=%s Bytes/block=%s\n"),
108 edit_uint64_with_commas(dev->VolCatInfo.VolCatBytes, b1),
109 edit_uint64_with_commas(dev->VolCatInfo.VolCatBlocks, b2),
110 edit_uint64_with_commas(bpb, b3));
111 } else { /* reading */
112 bpb = dev->VolCatInfo.VolCatReads;
116 if (dev->VolCatInfo.VolCatRBytes > 0) {
117 bpb = dev->VolCatInfo.VolCatRBytes / bpb;
121 bnet_fsend(user, _(" Total Bytes Read=%s Blocks Read=%s Bytes/block=%s\n"),
122 edit_uint64_with_commas(dev->VolCatInfo.VolCatRBytes, b1),
123 edit_uint64_with_commas(dev->VolCatInfo.VolCatReads, b2),
124 edit_uint64_with_commas(bpb, b3));
126 bnet_fsend(user, _(" Positioned at File=%s Block=%s\n"),
127 edit_uint64_with_commas(dev->file, b1),
128 edit_uint64_with_commas(dev->block_num, b2));
131 bnet_fsend(user, _("Device %s is not open.\n"), dev_name(dev));
132 send_blocked_status(jcr, dev);
140 /* NOTE, we reuse a calling argument jcr. Be warned! */
141 for (jcr=NULL; (jcr=get_next_jcr(jcr)); ) {
142 if (jcr->JobStatus == JS_WaitFD) {
143 bnet_fsend(user, _("%s Job %s waiting for Client connection.\n"),
144 job_type_to_str(jcr->JobType), jcr->Job);
147 bnet_fsend(user, _("%s %s job %s using Volume \"%s\" on device %s\n"),
148 job_level_to_str(jcr->JobLevel),
149 job_type_to_str(jcr->JobType),
152 jcr->device->device_name);
153 sec = time(NULL) - jcr->run_time;
157 bps = jcr->JobBytes / sec;
158 bnet_fsend(user, _(" Files=%s Bytes=%s Bytes/sec=%s\n"),
159 edit_uint64_with_commas(jcr->JobFiles, b1),
160 edit_uint64_with_commas(jcr->JobBytes, b2),
161 edit_uint64_with_commas(bps, b3));
164 if (jcr->file_bsock) {
165 bnet_fsend(user, " FDReadSeqNo=%s in_msg=%u out_msg=%d fd=%d\n",
166 edit_uint64_with_commas(jcr->file_bsock->read_seqno, b1),
167 jcr->file_bsock->in_msg_no, jcr->file_bsock->out_msg_no,
168 jcr->file_bsock->fd);
170 bnet_fsend(user, " FDSocket closed\n");
174 free_locked_jcr(jcr);
178 bnet_fsend(user, _("No jobs running.\n"));
182 bnet_fsend(user, "\n\n");
183 dump_resource(R_DEVICE, resources[R_DEVICE-r_first].res_head, sendit, user);
185 bnet_fsend(user, "====\n");
187 bnet_sig(user, BNET_EOD);
191 static void send_blocked_status(JCR *jcr, DEVICE *dev)
193 BSOCK *user = jcr->dir_bsock;
195 switch (dev->dev_blocked) {
197 bnet_fsend(user, _(" Device is BLOCKED. User unmounted.\n"));
199 case BST_UNMOUNTED_WAITING_FOR_SYSOP:
200 bnet_fsend(user, _(" Device is BLOCKED. User unmounted during wait for media/mount.\n"));
202 case BST_WAITING_FOR_SYSOP:
203 if (jcr->JobStatus == JS_WaitMount) {
204 bnet_fsend(user, _(" Device is BLOCKED waiting for mount.\n"));
206 bnet_fsend(user, _(" Device is BLOCKED waiting for appendable media.\n"));
209 case BST_DOING_ACQUIRE:
210 bnet_fsend(user, _(" Device is being initialized.\n"));
212 case BST_WRITING_LABEL:
213 bnet_fsend(user, _(" Device is blocked labeling a Volume.\n"));
218 if (debug_level > 1) {
219 bnet_fsend(user, _("Configured device capabilities:\n"));
220 bnet_fsend(user, "%sEOF ", dev->capabilities & CAP_EOF ? "" : "!");
221 bnet_fsend(user, "%sBSR ", dev->capabilities & CAP_BSR ? "" : "!");
222 bnet_fsend(user, "%sBSF ", dev->capabilities & CAP_BSF ? "" : "!");
223 bnet_fsend(user, "%sFSR ", dev->capabilities & CAP_FSR ? "" : "!");
224 bnet_fsend(user, "%sFSF ", dev->capabilities & CAP_FSF ? "" : "!");
225 bnet_fsend(user, "%sEOM ", dev->capabilities & CAP_EOM ? "" : "!");
226 bnet_fsend(user, "%sREM ", dev->capabilities & CAP_REM ? "" : "!");
227 bnet_fsend(user, "%sRACCESS ", dev->capabilities & CAP_RACCESS ? "" : "!");
228 bnet_fsend(user, "%sAUTOMOUNT ", dev->capabilities & CAP_AUTOMOUNT ? "" : "!");
229 bnet_fsend(user, "%sLABEL ", dev->capabilities & CAP_LABEL ? "" : "!");
230 bnet_fsend(user, "%sANONVOLS ", dev->capabilities & CAP_ANONVOLS ? "" : "!");
231 bnet_fsend(user, "%sALWAYSOPEN ", dev->capabilities & CAP_ALWAYSOPEN ? "" : "!");
232 bnet_fsend(user, "\n");
234 bnet_fsend(user, _("Device status:\n"));
235 bnet_fsend(user, "%sOPENED ", dev->state & ST_OPENED ? "" : "!");
236 bnet_fsend(user, "%sTAPE ", dev->state & ST_TAPE ? "" : "!");
237 bnet_fsend(user, "%sLABEL ", dev->state & ST_LABEL ? "" : "!");
238 bnet_fsend(user, "%sMALLOC ", dev->state & ST_MALLOC ? "" : "!");
239 bnet_fsend(user, "%sAPPEND ", dev->state & ST_APPEND ? "" : "!");
240 bnet_fsend(user, "%sREAD ", dev->state & ST_READ ? "" : "!");
241 bnet_fsend(user, "%sEOT ", dev->state & ST_EOT ? "" : "!");
242 bnet_fsend(user, "%sWEOT ", dev->state & ST_WEOT ? "" : "!");
243 bnet_fsend(user, "%sEOF ", dev->state & ST_EOF ? "" : "!");
244 bnet_fsend(user, "%sNEXTVOL ", dev->state & ST_NEXTVOL ? "" : "!");
245 bnet_fsend(user, "%sSHORT ", dev->state & ST_SHORT ? "" : "!");
246 bnet_fsend(user, "\n");
248 bnet_fsend(user, _("Device parameters:\n"));
249 bnet_fsend(user, "Device name: %s\n", dev->dev_name);
250 bnet_fsend(user, "File=%u block=%u\n", dev->file, dev->block_num);
251 bnet_fsend(user, "Min block=%u Max block=%u\n", dev->min_block_size, dev->max_block_size);
256 static void list_terminated_jobs(void *arg)
258 char dt[MAX_TIME_LENGTH], b1[30], b2[30];
260 struct s_last_job *je;
263 if (last_job.NumJobs == 0) {
264 msg = _("No Terminated Jobs.\n");
265 sendit(msg, strlen(msg), arg);
268 lock_last_jobs_list();
269 msg = _("\nTerminated Jobs:\n");
270 sendit(msg, strlen(msg), arg);
271 msg = _("Level Files Bytes Status Finished Name \n");
272 sendit(msg, strlen(msg), arg);
273 msg = _("====================================================================\n");
274 sendit(msg, strlen(msg), arg);
275 for (je=NULL; (je=(s_last_job *)last_jobs->next(je)); ) {
276 char JobName[MAX_NAME_LENGTH];
280 bstrftime(dt, sizeof(dt), je->end_time);
281 strcpy(dt+7, dt+9); /* cut century */
282 switch (je->JobType) {
285 bstrncpy(level, " ", sizeof(level));
288 bstrncpy(level, level_to_str(je->JobLevel), sizeof(level));
292 switch (je->JobStatus) {
294 termstat = "Created";
297 case JS_ErrorTerminated:
313 bstrncpy(JobName, je->Job, sizeof(JobName));
314 /* There are three periods after the Job name */
316 for (int i=0; i<3; i++) {
317 if ((p=strrchr(JobName, '.')) != NULL) {
321 bsnprintf(buf, sizeof(buf), _("%-4s %8s %12s %-7s %-8s %s\n"),
323 edit_uint64_with_commas(je->JobFiles, b1),
324 edit_uint64_with_commas(je->JobBytes, b2),
327 sendit(buf, strlen(buf), arg);
329 sendit("\n", 1, arg);
330 unlock_last_jobs_list();
334 * Convert Job Level into a string
336 static char *level_to_str(int level)
347 str = _("Incremental");
350 str = _("Differential");
355 case L_VERIFY_CATALOG:
356 str = _("Verify Catalog");
359 str = _("Init Catalog");
361 case L_VERIFY_VOLUME_TO_CATALOG:
362 str = _("Volume to Catalog");
364 case L_VERIFY_DISK_TO_CATALOG:
365 str = _("Disk to Catalog");
374 str = _("Unknown Job Level");
383 static void sendit(char *msg, int len, void *arg)
385 BSOCK *user = (BSOCK *)arg;
387 memcpy(user->msg, msg, len+1);
388 user->msglen = len+1;