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_nc(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);
79 for (device=NULL; (device=(DEVRES *)GetNextRes(R_DEVICE, (RES *)device)); ) {
80 for (dev=device->dev; dev; dev=dev->next) {
81 if (dev->state & ST_OPENED) {
82 if (dev->state & ST_LABEL) {
83 bnet_fsend(user, _("Device %s is mounted with Volume \"%s\"\n"),
84 dev_name(dev), dev->VolHdr.VolName);
86 bnet_fsend(user, _("Device %s open but no Bacula volume is mounted.\n"), dev_name(dev));
88 send_blocked_status(jcr, dev);
89 if (dev->state & ST_APPEND) {
90 bpb = dev->VolCatInfo.VolCatBlocks;
94 bpb = dev->VolCatInfo.VolCatBytes / bpb;
95 bnet_fsend(user, _(" Total Bytes=%s Blocks=%s Bytes/block=%s\n"),
96 edit_uint64_with_commas(dev->VolCatInfo.VolCatBytes, b1),
97 edit_uint64_with_commas(dev->VolCatInfo.VolCatBlocks, b2),
98 edit_uint64_with_commas(bpb, b3));
99 } else { /* reading */
100 bpb = dev->VolCatInfo.VolCatReads;
104 if (dev->VolCatInfo.VolCatRBytes > 0) {
105 bpb = dev->VolCatInfo.VolCatRBytes / bpb;
109 bnet_fsend(user, _(" Total Bytes Read=%s Blocks Read=%s Bytes/block=%s\n"),
110 edit_uint64_with_commas(dev->VolCatInfo.VolCatRBytes, b1),
111 edit_uint64_with_commas(dev->VolCatInfo.VolCatReads, b2),
112 edit_uint64_with_commas(bpb, b3));
114 bnet_fsend(user, _(" Positioned at File=%s Block=%s\n"),
115 edit_uint64_with_commas(dev->file, b1),
116 edit_uint64_with_commas(dev->block_num, b2));
119 bnet_fsend(user, _("Device %s is not open.\n"), dev_name(dev));
120 send_blocked_status(jcr, dev);
128 /* NOTE, we reuse a calling argument jcr. Be warned! */
129 for (jcr=NULL; (jcr=get_next_jcr(jcr)); ) {
130 if (jcr->JobStatus == JS_WaitFD) {
131 bnet_fsend(user, _("%s Job %s waiting for Client connection.\n"),
132 job_type_to_str(jcr->JobType), jcr->Job);
135 bnet_fsend(user, _("%s %s job %s using Volume \"%s\" on device %s\n"),
136 job_level_to_str(jcr->JobLevel),
137 job_type_to_str(jcr->JobType),
140 jcr->device->device_name);
141 sec = time(NULL) - jcr->run_time;
145 bps = jcr->JobBytes / sec;
146 bnet_fsend(user, _(" Files=%s Bytes=%s Bytes/sec=%s\n"),
147 edit_uint64_with_commas(jcr->JobFiles, b1),
148 edit_uint64_with_commas(jcr->JobBytes, b2),
149 edit_uint64_with_commas(bps, b3));
152 if (jcr->file_bsock) {
153 bnet_fsend(user, " FDReadSeqNo=%s in_msg=%u out_msg=%d fd=%d\n",
154 edit_uint64_with_commas(jcr->file_bsock->read_seqno, b1),
155 jcr->file_bsock->in_msg_no, jcr->file_bsock->out_msg_no,
156 jcr->file_bsock->fd);
158 bnet_fsend(user, " FDSocket closed\n");
162 free_locked_jcr(jcr);
166 bnet_fsend(user, _("No jobs running.\n"));
170 bnet_fsend(user, "\n\n");
171 dump_resource(R_DEVICE, resources[R_DEVICE-r_first].res_head, sendit, user);
173 bnet_fsend(user, "====\n");
175 bnet_sig(user, BNET_EOD);
179 static void send_blocked_status(JCR *jcr, DEVICE *dev)
181 BSOCK *user = jcr->dir_bsock;
183 switch (dev->dev_blocked) {
185 bnet_fsend(user, _(" Device is BLOCKED. User unmounted.\n"));
187 case BST_UNMOUNTED_WAITING_FOR_SYSOP:
188 bnet_fsend(user, _(" Device is BLOCKED. User unmounted during wait for media/mount.\n"));
190 case BST_WAITING_FOR_SYSOP:
191 if (jcr->JobStatus == JS_WaitMount) {
192 bnet_fsend(user, _(" Device is BLOCKED waiting for mount.\n"));
194 bnet_fsend(user, _(" Device is BLOCKED waiting for appendable media.\n"));
197 case BST_DOING_ACQUIRE:
198 bnet_fsend(user, _(" Device is being initialized.\n"));
200 case BST_WRITING_LABEL:
201 bnet_fsend(user, _(" Device is blocked labeling a Volume.\n"));
206 if (debug_level > 1) {
207 bnet_fsend(user, _("Configured device capabilities:\n"));
208 bnet_fsend(user, "%sEOF ", dev->capabilities & CAP_EOF ? "" : "!");
209 bnet_fsend(user, "%sBSR ", dev->capabilities & CAP_BSR ? "" : "!");
210 bnet_fsend(user, "%sBSF ", dev->capabilities & CAP_BSF ? "" : "!");
211 bnet_fsend(user, "%sFSR ", dev->capabilities & CAP_FSR ? "" : "!");
212 bnet_fsend(user, "%sFSF ", dev->capabilities & CAP_FSF ? "" : "!");
213 bnet_fsend(user, "%sEOM ", dev->capabilities & CAP_EOM ? "" : "!");
214 bnet_fsend(user, "%sREM ", dev->capabilities & CAP_REM ? "" : "!");
215 bnet_fsend(user, "%sRACCESS ", dev->capabilities & CAP_RACCESS ? "" : "!");
216 bnet_fsend(user, "%sAUTOMOUNT ", dev->capabilities & CAP_AUTOMOUNT ? "" : "!");
217 bnet_fsend(user, "%sLABEL ", dev->capabilities & CAP_LABEL ? "" : "!");
218 bnet_fsend(user, "%sANONVOLS ", dev->capabilities & CAP_ANONVOLS ? "" : "!");
219 bnet_fsend(user, "%sALWAYSOPEN ", dev->capabilities & CAP_ALWAYSOPEN ? "" : "!");
220 bnet_fsend(user, "\n");
222 bnet_fsend(user, _("Device status:\n"));
223 bnet_fsend(user, "%sOPENED ", dev->state & ST_OPENED ? "" : "!");
224 bnet_fsend(user, "%sTAPE ", dev->state & ST_TAPE ? "" : "!");
225 bnet_fsend(user, "%sLABEL ", dev->state & ST_LABEL ? "" : "!");
226 bnet_fsend(user, "%sMALLOC ", dev->state & ST_MALLOC ? "" : "!");
227 bnet_fsend(user, "%sAPPEND ", dev->state & ST_APPEND ? "" : "!");
228 bnet_fsend(user, "%sREAD ", dev->state & ST_READ ? "" : "!");
229 bnet_fsend(user, "%sEOT ", dev->state & ST_EOT ? "" : "!");
230 bnet_fsend(user, "%sWEOT ", dev->state & ST_WEOT ? "" : "!");
231 bnet_fsend(user, "%sEOF ", dev->state & ST_EOF ? "" : "!");
232 bnet_fsend(user, "%sNEXTVOL ", dev->state & ST_NEXTVOL ? "" : "!");
233 bnet_fsend(user, "%sSHORT ", dev->state & ST_SHORT ? "" : "!");
234 bnet_fsend(user, "\n");
236 bnet_fsend(user, _("Device parameters:\n"));
237 bnet_fsend(user, "Device name: %s\n", dev->dev_name);
238 bnet_fsend(user, "File=%u block=%u\n", dev->file, dev->block_num);
239 bnet_fsend(user, "Min block=%u Max block=%u\n", dev->min_block_size, dev->max_block_size);
244 static void list_terminated_jobs(void *arg)
246 char dt[MAX_TIME_LENGTH], b1[30], b2[30];
248 struct s_last_job *je;
251 if (last_job.NumJobs == 0) {
252 msg = _("No Terminated Jobs.\n");
253 sendit(msg, strlen(msg), arg);
256 lock_last_jobs_list();
257 msg = _("\nTerminated Jobs:\n");
258 sendit(msg, strlen(msg), arg);
259 msg = _(" JobId Level Files Bytes Status Finished Name \n");
260 sendit(msg, strlen(msg), arg);
261 msg = _("======================================================================\n");
262 sendit(msg, strlen(msg), arg);
263 for (je=NULL; (je=(s_last_job *)last_jobs->next(je)); ) {
264 char JobName[MAX_NAME_LENGTH];
268 bstrftime_nc(dt, sizeof(dt), je->end_time);
269 switch (je->JobType) {
272 bstrncpy(level, " ", sizeof(level));
275 bstrncpy(level, level_to_str(je->JobLevel), sizeof(level));
279 switch (je->JobStatus) {
281 termstat = "Created";
284 case JS_ErrorTerminated:
300 bstrncpy(JobName, je->Job, sizeof(JobName));
301 /* There are three periods after the Job name */
303 for (int i=0; i<3; i++) {
304 if ((p=strrchr(JobName, '.')) != NULL) {
308 bsnprintf(buf, sizeof(buf), _("%6d %-4s %8s %14s %-7s %-8s %s\n"),
311 edit_uint64_with_commas(je->JobFiles, b1),
312 edit_uint64_with_commas(je->JobBytes, b2),
315 sendit(buf, strlen(buf), arg);
317 sendit("\n", 1, arg);
318 unlock_last_jobs_list();
322 * Convert Job Level into a string
324 static char *level_to_str(int level)
335 str = _("Incremental");
338 str = _("Differential");
343 case L_VERIFY_CATALOG:
344 str = _("Verify Catalog");
347 str = _("Init Catalog");
349 case L_VERIFY_VOLUME_TO_CATALOG:
350 str = _("Volume to Catalog");
352 case L_VERIFY_DISK_TO_CATALOG:
353 str = _("Disk to Catalog");
362 str = _("Unknown Job Level");
371 static void sendit(char *msg, int len, void *arg)
373 BSOCK *user = (BSOCK *)arg;
375 memcpy(user->msg, msg, len+1);
376 user->msglen = len+1;