]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/stored/status.c
New query.sql, JobMedia VolIndex, add Release command
[bacula/bacula] / bacula / src / stored / status.c
1 /*
2  *  This file handles the status command
3  *
4  *     Kern Sibbald, May MMIII
5  *
6  *   Version $Id$
7  *  
8  */
9 /*
10    Copyright (C) 2000-2003 Kern Sibbald and John Walker
11
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.
16
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.
21
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,
25    MA 02111-1307, USA.
26
27  */
28
29 #include "bacula.h"
30 #include "stored.h"
31
32 /* Exported variables */
33
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;
41
42 /* Static variables */
43
44
45 /* Forward referenced functions */
46 static void send_blocked_status(JCR *jcr, DEVICE *dev);
47
48
49 /*
50  * Status command from Director
51  */
52 int status_cmd(JCR *jcr)
53 {
54    DEVRES *device;
55    DEVICE *dev;
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];
60
61    bnet_fsend(user, "\n%s Version: " VERSION " (" BDATE ")\n", my_name);
62    bstrftime(dt, sizeof(dt), daemon_start_time);
63    bnet_fsend(user, _("Daemon started %s, %d Job%s run.\n"), dt, last_job.NumJobs,
64         last_job.NumJobs == 1 ? "" : "s");
65    if (last_job.NumJobs > 0) {
66       char termstat[30];
67
68       bstrftime(dt, sizeof(dt), last_job.end_time);
69       bnet_fsend(user, _("Last Job %s finished at %s\n"), last_job.Job, dt);
70
71       jobstatus_to_ascii(last_job.JobStatus, termstat, sizeof(termstat));
72       bnet_fsend(user, _("  Files=%s Bytes=%s Termination Status=%s\n"), 
73            edit_uint64_with_commas(last_job.JobFiles, b1),
74            edit_uint64_with_commas(last_job.JobBytes, b2),
75            termstat);
76    }
77
78    LockRes();
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);
85             } else {
86                bnet_fsend(user, _("Device %s open but no Bacula volume is mounted.\n"), dev_name(dev));
87             }
88             send_blocked_status(jcr, dev);
89             if (dev->state & ST_APPEND) {
90                bpb = dev->VolCatInfo.VolCatBlocks;
91                if (bpb <= 0) {
92                   bpb = 1;
93                }
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;
101                if (bpb <= 0) {
102                   bpb = 1;
103                }
104                if (dev->VolCatInfo.VolCatRBytes > 0) {
105                   bpb = dev->VolCatInfo.VolCatRBytes / bpb;
106                } else {
107                   bpb = 0;
108                }
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));
113             }
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));
117
118          } else {
119             bnet_fsend(user, _("Device %s is not open.\n"), dev_name(dev));
120             send_blocked_status(jcr, dev);
121          }
122       }
123    }
124    UnlockRes();
125
126    found = 0;
127    lock_jcr_chain();
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);
133       }
134       if (jcr->device) {
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),
138                    jcr->VolumeName,
139                    jcr->Job, jcr->device->device_name);
140          sec = time(NULL) - jcr->run_time;
141          if (sec <= 0) {
142             sec = 1;
143          }
144          bps = jcr->JobBytes / sec;
145          bnet_fsend(user, _("    Files=%s Bytes=%s Bytes/sec=%s\n"), 
146             edit_uint64_with_commas(jcr->JobFiles, b1),
147             edit_uint64_with_commas(jcr->JobBytes, b2),
148             edit_uint64_with_commas(bps, b3));
149          found = 1;
150 #ifdef DEBUG
151          if (jcr->file_bsock) {
152             bnet_fsend(user, "    FDReadSeqNo=%s in_msg=%u out_msg=%d fd=%d\n", 
153                edit_uint64_with_commas(jcr->file_bsock->read_seqno, b1),
154                jcr->file_bsock->in_msg_no, jcr->file_bsock->out_msg_no,
155                jcr->file_bsock->fd);
156          } else {
157             bnet_fsend(user, "    FDSocket closed\n");
158          }
159 #endif
160       }
161       free_locked_jcr(jcr);
162    }
163    unlock_jcr_chain();
164    if (!found) {
165       bnet_fsend(user, _("No jobs running.\n"));
166    }
167
168 #ifdef full_status
169    bnet_fsend(user, "\n\n");
170    dump_resource(R_DEVICE, resources[R_DEVICE-r_first].res_head, sendit, user);
171 #endif
172    bnet_fsend(user, "====\n");
173
174    bnet_sig(user, BNET_EOD);
175    return 1;
176 }
177
178 static void send_blocked_status(JCR *jcr, DEVICE *dev) 
179 {
180    BSOCK *user = jcr->dir_bsock;
181
182    switch (dev->dev_blocked) {
183    case BST_UNMOUNTED:
184       bnet_fsend(user, _("    Device is BLOCKED. User unmounted.\n"));
185       break;
186    case BST_UNMOUNTED_WAITING_FOR_SYSOP:
187       bnet_fsend(user, _("    Device is BLOCKED. User unmounted during wait for media/mount.\n"));
188       break;
189    case BST_WAITING_FOR_SYSOP:
190       if (jcr->JobStatus == JS_WaitMount) {
191          bnet_fsend(user, _("    Device is BLOCKED waiting for mount.\n"));
192       } else {
193          bnet_fsend(user, _("    Device is BLOCKED waiting for appendable media.\n"));
194       }
195       break;
196    case BST_DOING_ACQUIRE:
197       bnet_fsend(user, _("    Device is being initialized.\n"));
198       break;
199    case BST_WRITING_LABEL:
200       bnet_fsend(user, _("    Device is blocked labeling a Volume.\n"));
201       break;
202    default:
203       break;
204    }
205 }