2 * Read code for Storage daemon
4 * Kern Sibbald, November MM
9 Copyright (C) 2000-2004 Kern Sibbald and John Walker
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2 of
14 the License, or (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public
22 License along with this program; if not, write to the Free
23 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
31 /* Forward referenced subroutines */
32 static bool record_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec);
35 /* Responses sent to the File daemon */
36 static char OK_data[] = "3000 OK data\n";
37 static char FD_error[] = "3000 error\n";
38 static char rec_header[] = "rechdr %ld %ld %ld %ld %ld";
41 * Read Data and send to File Daemon
42 * Returns: false on failure
45 bool do_read_data(JCR *jcr)
47 BSOCK *fd = jcr->file_bsock;
51 Dmsg0(20, "Start read data.\n");
53 if (!bnet_set_buffer_size(fd, jcr->device->max_network_buffer_size, BNET_SETBUF_WRITE)) {
59 if (jcr->NumVolumes == 0) {
60 Jmsg(jcr, M_FATAL, 0, _("No Volume names found for restore.\n"));
62 bnet_fsend(fd, FD_error);
66 Dmsg2(200, "Found %d volumes names to restore. First=%s\n", jcr->NumVolumes,
67 jcr->VolList->VolumeName);
69 pm_strcpy(&jcr->VolumeName, jcr->VolList->VolumeName);
72 * Ready device for reading, and read records
74 if (!(dcr=acquire_device_for_read(jcr))) {
79 /* Tell File daemon we will send data */
80 bnet_fsend(fd, OK_data);
81 ok = read_records(dcr, record_cb, mount_next_read_volume);
83 /* Send end of data to FD */
84 bnet_sig(fd, BNET_EOD);
86 if (!release_device(jcr)) {
91 Dmsg0(30, "Done reading.\n");
96 * Called here for each record from read_records()
100 static bool record_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec)
102 BSOCK *fd = jcr->file_bsock;
106 if (rec->FileIndex < 0) {
109 Dmsg5(100, "Send to FD: SessId=%u SessTim=%u FI=%d Strm=%d, len=%d\n",
110 rec->VolSessionId, rec->VolSessionTime, rec->FileIndex, rec->Stream,
113 /* Send record header to File daemon */
114 if (!bnet_fsend(fd, rec_header, rec->VolSessionId, rec->VolSessionTime,
115 rec->FileIndex, rec->Stream, rec->data_len)) {
116 Dmsg1(30, ">filed: Error Hdr=%s\n", fd->msg);
117 Jmsg1(jcr, M_FATAL, 0, _("Error sending to File daemon. ERR=%s\n"),
121 Dmsg1(30, ">filed: Hdr=%s\n", fd->msg);
125 /* Send data record to File daemon */
126 save_msg = fd->msg; /* save fd message pointer */
127 fd->msg = rec->data; /* pass data directly to bnet_send */
128 fd->msglen = rec->data_len;
129 Dmsg1(30, ">filed: send %d bytes data.\n", fd->msglen);
130 if (!bnet_send(fd)) {
131 Pmsg1(000, "Error sending to FD. ERR=%s\n", bnet_strerror(fd));
132 Jmsg1(jcr, M_FATAL, 0, _("Error sending to File daemon. ERR=%s\n"),
137 fd->msg = save_msg; /* restore fd message pointer */