2 * This file handles the status command
4 * Kern Sibbald, May MMIII
10 Copyright (C) 2000-2004 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 int num_jobs_run;
43 /* Static variables */
46 /* Forward referenced functions */
47 static void send_blocked_status(JCR *jcr, DEVICE *dev);
48 static void list_terminated_jobs(void *arg);
49 static void list_running_jobs(BSOCK *user);
50 static void sendit(const char *msg, int len, void *arg);
51 static const char *level_to_str(int level);
55 * Status command from Director
57 int status_cmd(JCR *jcr)
61 BSOCK *user = jcr->dir_bsock;
62 char dt[MAX_TIME_LENGTH];
63 char b1[30], b2[30], b3[30];
66 bnet_fsend(user, "\n%s Version: " VERSION " (" BDATE ") %s %s %s\n", my_name,
67 HOST_OS, DISTNAME, DISTVER);
68 bstrftime_nc(dt, sizeof(dt), daemon_start_time);
69 bnet_fsend(user, _("Daemon started %s, %d Job%s run since started.\n"), dt, num_jobs_run,
70 num_jobs_run == 1 ? "" : "s");
71 if (debug_level > 0) {
72 char b1[35], b2[35], b3[35], b4[35];
73 bnet_fsend(user, _(" Heap: bytes=%s max_bytes=%s bufs=%s max_bufs=%s\n"),
74 edit_uint64_with_commas(sm_bytes, b1),
75 edit_uint64_with_commas(sm_max_bytes, b2),
76 edit_uint64_with_commas(sm_buffers, b3),
77 edit_uint64_with_commas(sm_max_buffers, b4));
83 list_running_jobs(user);
86 * List terminated jobs
88 list_terminated_jobs(user);
93 bnet_fsend(user, _("\nDevice status:\n"));
95 foreach_res(device, R_DEVICE) {
96 for (dev=device->dev; dev; dev=dev->next) {
97 if (dev_state(dev, ST_OPENED)) {
98 if (dev_state(dev, ST_LABEL)) {
99 bnet_fsend(user, _("Device \"%s\" is mounted with Volume \"%s\"\n"),
100 dev_name(dev), dev->VolHdr.VolName);
102 bnet_fsend(user, _("Device \"%s\" open but no Bacula volume is mounted.\n"), dev_name(dev));
104 send_blocked_status(jcr, dev);
105 if (dev_state(dev, ST_APPEND)) {
106 bpb = dev->VolCatInfo.VolCatBlocks;
110 bpb = dev->VolCatInfo.VolCatBytes / bpb;
111 bnet_fsend(user, _(" Total Bytes=%s Blocks=%s Bytes/block=%s\n"),
112 edit_uint64_with_commas(dev->VolCatInfo.VolCatBytes, b1),
113 edit_uint64_with_commas(dev->VolCatInfo.VolCatBlocks, b2),
114 edit_uint64_with_commas(bpb, b3));
115 } else { /* reading */
116 bpb = dev->VolCatInfo.VolCatReads;
120 if (dev->VolCatInfo.VolCatRBytes > 0) {
121 bpb = dev->VolCatInfo.VolCatRBytes / bpb;
125 bnet_fsend(user, _(" Total Bytes Read=%s Blocks Read=%s Bytes/block=%s\n"),
126 edit_uint64_with_commas(dev->VolCatInfo.VolCatRBytes, b1),
127 edit_uint64_with_commas(dev->VolCatInfo.VolCatReads, b2),
128 edit_uint64_with_commas(bpb, b3));
130 bnet_fsend(user, _(" Positioned at File=%s Block=%s\n"),
131 edit_uint64_with_commas(dev->file, b1),
132 edit_uint64_with_commas(dev->block_num, b2));
135 bnet_fsend(user, _("Device \"%s\" is not open.\n"), dev_name(dev));
136 send_blocked_status(jcr, dev);
144 bnet_fsend(user, "\n\n");
145 dump_resource(R_DEVICE, resources[R_DEVICE-r_first].res_head, sendit, user);
147 bnet_fsend(user, "====\n\n");
149 list_spool_stats(user);
151 bnet_sig(user, BNET_EOD);
155 static void send_blocked_status(JCR *jcr, DEVICE *dev)
157 BSOCK *user = jcr->dir_bsock;
159 switch (dev->dev_blocked) {
161 bnet_fsend(user, _(" Device is BLOCKED. User unmounted.\n"));
163 case BST_UNMOUNTED_WAITING_FOR_SYSOP:
164 bnet_fsend(user, _(" Device is BLOCKED. User unmounted during wait for media/mount.\n"));
166 case BST_WAITING_FOR_SYSOP:
167 if (jcr->JobStatus == JS_WaitMount) {
168 bnet_fsend(user, _(" Device is BLOCKED waiting for mount of volume \"%s\".\n"),
171 bnet_fsend(user, _(" Device is BLOCKED waiting for appendable media.\n"));
174 case BST_DOING_ACQUIRE:
175 bnet_fsend(user, _(" Device is being initialized.\n"));
177 case BST_WRITING_LABEL:
178 bnet_fsend(user, _(" Device is blocked labeling a Volume.\n"));
183 if (debug_level > 1) {
184 bnet_fsend(user, _("Configured device capabilities:\n"));
185 bnet_fsend(user, "%sEOF ", dev->capabilities & CAP_EOF ? "" : "!");
186 bnet_fsend(user, "%sBSR ", dev->capabilities & CAP_BSR ? "" : "!");
187 bnet_fsend(user, "%sBSF ", dev->capabilities & CAP_BSF ? "" : "!");
188 bnet_fsend(user, "%sFSR ", dev->capabilities & CAP_FSR ? "" : "!");
189 bnet_fsend(user, "%sFSF ", dev->capabilities & CAP_FSF ? "" : "!");
190 bnet_fsend(user, "%sEOM ", dev->capabilities & CAP_EOM ? "" : "!");
191 bnet_fsend(user, "%sREM ", dev->capabilities & CAP_REM ? "" : "!");
192 bnet_fsend(user, "%sRACCESS ", dev->capabilities & CAP_RACCESS ? "" : "!");
193 bnet_fsend(user, "%sAUTOMOUNT ", dev->capabilities & CAP_AUTOMOUNT ? "" : "!");
194 bnet_fsend(user, "%sLABEL ", dev->capabilities & CAP_LABEL ? "" : "!");
195 bnet_fsend(user, "%sANONVOLS ", dev->capabilities & CAP_ANONVOLS ? "" : "!");
196 bnet_fsend(user, "%sALWAYSOPEN ", dev->capabilities & CAP_ALWAYSOPEN ? "" : "!");
197 bnet_fsend(user, "\n");
199 bnet_fsend(user, _("Device status:\n"));
200 bnet_fsend(user, "%sOPENED ", dev->state & ST_OPENED ? "" : "!");
201 bnet_fsend(user, "%sTAPE ", dev->state & ST_TAPE ? "" : "!");
202 bnet_fsend(user, "%sLABEL ", dev->state & ST_LABEL ? "" : "!");
203 bnet_fsend(user, "%sMALLOC ", dev->state & ST_MALLOC ? "" : "!");
204 bnet_fsend(user, "%sAPPEND ", dev->state & ST_APPEND ? "" : "!");
205 bnet_fsend(user, "%sREAD ", dev->state & ST_READ ? "" : "!");
206 bnet_fsend(user, "%sEOT ", dev->state & ST_EOT ? "" : "!");
207 bnet_fsend(user, "%sWEOT ", dev->state & ST_WEOT ? "" : "!");
208 bnet_fsend(user, "%sEOF ", dev->state & ST_EOF ? "" : "!");
209 bnet_fsend(user, "%sNEXTVOL ", dev->state & ST_NEXTVOL ? "" : "!");
210 bnet_fsend(user, "%sSHORT ", dev->state & ST_SHORT ? "" : "!");
211 bnet_fsend(user, "\n");
213 bnet_fsend(user, _("Device parameters:\n"));
214 bnet_fsend(user, "Device name: %s\n", dev->dev_name);
215 bnet_fsend(user, "File=%u block=%u\n", dev->file, dev->block_num);
216 bnet_fsend(user, "Min block=%u Max block=%u\n", dev->min_block_size, dev->max_block_size);
221 static void list_running_jobs(BSOCK *user)
226 char JobName[MAX_NAME_LENGTH];
227 char b1[30], b2[30], b3[30];
229 bnet_fsend(user, _("\nRunning Jobs:\n"));
232 if (jcr->JobStatus == JS_WaitFD) {
233 bnet_fsend(user, _("%s Job %s waiting for Client connection.\n"),
234 job_type_to_str(jcr->JobType), jcr->Job);
237 bstrncpy(JobName, jcr->Job, sizeof(JobName));
238 /* There are three periods after the Job name */
240 for (int i=0; i<3; i++) {
241 if ((p=strrchr(JobName, '.')) != NULL) {
245 bnet_fsend(user, _("%s %s job %s JobId=%d Volume=\"%s\" device=\"%s\"\n"),
246 job_level_to_str(jcr->JobLevel),
247 job_type_to_str(jcr->JobType),
251 jcr->device->device_name);
252 sec = time(NULL) - jcr->run_time;
256 bps = jcr->JobBytes / sec;
257 bnet_fsend(user, _(" Files=%s Bytes=%s Bytes/sec=%s\n"),
258 edit_uint64_with_commas(jcr->JobFiles, b1),
259 edit_uint64_with_commas(jcr->JobBytes, b2),
260 edit_uint64_with_commas(bps, b3));
263 if (jcr->file_bsock) {
264 bnet_fsend(user, " FDReadSeqNo=%s in_msg=%u out_msg=%d fd=%d\n",
265 edit_uint64_with_commas(jcr->file_bsock->read_seqno, b1),
266 jcr->file_bsock->in_msg_no, jcr->file_bsock->out_msg_no,
267 jcr->file_bsock->fd);
269 bnet_fsend(user, " FDSocket closed\n");
273 free_locked_jcr(jcr);
277 bnet_fsend(user, _("No Jobs running.\n"));
279 bnet_fsend(user, "====\n");
282 static void list_terminated_jobs(void *arg)
284 char dt[MAX_TIME_LENGTH], b1[30], b2[30];
286 struct s_last_job *je;
289 if (last_jobs->size() == 0) {
290 msg = _("No Terminated Jobs.\n");
291 sendit(msg, strlen(msg), arg);
294 lock_last_jobs_list();
295 msg = _("\nTerminated Jobs:\n");
296 sendit(msg, strlen(msg), arg);
297 msg = _(" JobId Level Files Bytes Status Finished Name \n");
298 sendit(msg, strlen(msg), arg);
299 msg = _("======================================================================\n");
300 sendit(msg, strlen(msg), arg);
301 foreach_dlist(je, last_jobs) {
302 char JobName[MAX_NAME_LENGTH];
303 const char *termstat;
306 bstrftime_nc(dt, sizeof(dt), je->end_time);
307 switch (je->JobType) {
310 bstrncpy(level, " ", sizeof(level));
313 bstrncpy(level, level_to_str(je->JobLevel), sizeof(level));
317 switch (je->JobStatus) {
319 termstat = "Created";
322 case JS_ErrorTerminated:
338 bstrncpy(JobName, je->Job, sizeof(JobName));
339 /* There are three periods after the Job name */
341 for (int i=0; i<3; i++) {
342 if ((p=strrchr(JobName, '.')) != NULL) {
346 bsnprintf(buf, sizeof(buf), _("%6d %-6s %8s %14s %-7s %-8s %s\n"),
349 edit_uint64_with_commas(je->JobFiles, b1),
350 edit_uint64_with_commas(je->JobBytes, b2),
353 sendit(buf, strlen(buf), arg);
355 sendit("====\n", 5, arg);
356 unlock_last_jobs_list();
360 * Convert Job Level into a string
362 static const char *level_to_str(int level)
373 str = _("Incremental");
376 str = _("Differential");
381 case L_VERIFY_CATALOG:
382 str = _("Verify Catalog");
385 str = _("Init Catalog");
387 case L_VERIFY_VOLUME_TO_CATALOG:
388 str = _("Volume to Catalog");
390 case L_VERIFY_DISK_TO_CATALOG:
391 str = _("Disk to Catalog");
400 str = _("Unknown Job Level");
409 static void sendit(const char *msg, int len, void *arg)
411 BSOCK *user = (BSOCK *)arg;
413 memcpy(user->msg, msg, len+1);
414 user->msglen = len+1;