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);
50 * Status command from Director
52 int status_cmd(JCR *jcr)
56 int found, bps, sec, bpb;
57 BSOCK *user = jcr->dir_bsock;
58 char dt[MAX_TIME_LENGTH];
59 char b1[30], b2[30], b3[30];
61 bnet_fsend(user, "\n%s Version: " VERSION " (" BDATE ") %s %s %s\n", my_name,
62 HOST_OS, DISTNAME, DISTVER);
63 bstrftime(dt, sizeof(dt), daemon_start_time);
64 bnet_fsend(user, _("Daemon started %s, %d Job%s run.\n"), dt, last_job.NumJobs,
65 last_job.NumJobs == 1 ? "" : "s");
66 if (last_job.NumJobs > 0) {
69 bstrftime(dt, sizeof(dt), last_job.end_time);
70 bnet_fsend(user, _("Last Job %s finished at %s\n"), last_job.Job, dt);
72 jobstatus_to_ascii(last_job.JobStatus, termstat, sizeof(termstat));
73 bnet_fsend(user, _(" Files=%s Bytes=%s Termination Status=%s\n"),
74 edit_uint64_with_commas(last_job.JobFiles, b1),
75 edit_uint64_with_commas(last_job.JobBytes, b2),
80 for (device=NULL; (device=(DEVRES *)GetNextRes(R_DEVICE, (RES *)device)); ) {
81 for (dev=device->dev; dev; dev=dev->next) {
82 if (dev->state & ST_OPENED) {
83 if (dev->state & ST_LABEL) {
84 bnet_fsend(user, _("Device %s is mounted with Volume \"%s\"\n"),
85 dev_name(dev), dev->VolHdr.VolName);
87 bnet_fsend(user, _("Device %s open but no Bacula volume is mounted.\n"), dev_name(dev));
89 send_blocked_status(jcr, dev);
90 if (dev->state & ST_APPEND) {
91 bpb = dev->VolCatInfo.VolCatBlocks;
95 bpb = dev->VolCatInfo.VolCatBytes / bpb;
96 bnet_fsend(user, _(" Total Bytes=%s Blocks=%s Bytes/block=%s\n"),
97 edit_uint64_with_commas(dev->VolCatInfo.VolCatBytes, b1),
98 edit_uint64_with_commas(dev->VolCatInfo.VolCatBlocks, b2),
99 edit_uint64_with_commas(bpb, b3));
100 } else { /* reading */
101 bpb = dev->VolCatInfo.VolCatReads;
105 if (dev->VolCatInfo.VolCatRBytes > 0) {
106 bpb = dev->VolCatInfo.VolCatRBytes / bpb;
110 bnet_fsend(user, _(" Total Bytes Read=%s Blocks Read=%s Bytes/block=%s\n"),
111 edit_uint64_with_commas(dev->VolCatInfo.VolCatRBytes, b1),
112 edit_uint64_with_commas(dev->VolCatInfo.VolCatReads, b2),
113 edit_uint64_with_commas(bpb, b3));
115 bnet_fsend(user, _(" Positioned at File=%s Block=%s\n"),
116 edit_uint64_with_commas(dev->file, b1),
117 edit_uint64_with_commas(dev->block_num, b2));
120 bnet_fsend(user, _("Device %s is not open.\n"), dev_name(dev));
121 send_blocked_status(jcr, dev);
129 /* NOTE, we reuse a calling argument jcr. Be warned! */
130 for (jcr=NULL; (jcr=get_next_jcr(jcr)); ) {
131 if (jcr->JobStatus == JS_WaitFD) {
132 bnet_fsend(user, _("%s Job %s waiting for Client connection.\n"),
133 job_type_to_str(jcr->JobType), jcr->Job);
136 bnet_fsend(user, _("%s %s job %s using Volume \"%s\" on device %s\n"),
137 job_level_to_str(jcr->JobLevel),
138 job_type_to_str(jcr->JobType),
141 jcr->device->device_name);
142 sec = time(NULL) - jcr->run_time;
146 bps = jcr->JobBytes / sec;
147 bnet_fsend(user, _(" Files=%s Bytes=%s Bytes/sec=%s\n"),
148 edit_uint64_with_commas(jcr->JobFiles, b1),
149 edit_uint64_with_commas(jcr->JobBytes, b2),
150 edit_uint64_with_commas(bps, b3));
153 if (jcr->file_bsock) {
154 bnet_fsend(user, " FDReadSeqNo=%s in_msg=%u out_msg=%d fd=%d\n",
155 edit_uint64_with_commas(jcr->file_bsock->read_seqno, b1),
156 jcr->file_bsock->in_msg_no, jcr->file_bsock->out_msg_no,
157 jcr->file_bsock->fd);
159 bnet_fsend(user, " FDSocket closed\n");
163 free_locked_jcr(jcr);
167 bnet_fsend(user, _("No jobs running.\n"));
171 bnet_fsend(user, "\n\n");
172 dump_resource(R_DEVICE, resources[R_DEVICE-r_first].res_head, sendit, user);
174 bnet_fsend(user, "====\n");
176 bnet_sig(user, BNET_EOD);
180 static void send_blocked_status(JCR *jcr, DEVICE *dev)
182 BSOCK *user = jcr->dir_bsock;
184 switch (dev->dev_blocked) {
186 bnet_fsend(user, _(" Device is BLOCKED. User unmounted.\n"));
188 case BST_UNMOUNTED_WAITING_FOR_SYSOP:
189 bnet_fsend(user, _(" Device is BLOCKED. User unmounted during wait for media/mount.\n"));
191 case BST_WAITING_FOR_SYSOP:
192 if (jcr->JobStatus == JS_WaitMount) {
193 bnet_fsend(user, _(" Device is BLOCKED waiting for mount.\n"));
195 bnet_fsend(user, _(" Device is BLOCKED waiting for appendable media.\n"));
198 case BST_DOING_ACQUIRE:
199 bnet_fsend(user, _(" Device is being initialized.\n"));
201 case BST_WRITING_LABEL:
202 bnet_fsend(user, _(" Device is blocked labeling a Volume.\n"));