2 * Read code for Storage daemon
4 * Kern Sibbald, November MM
9 Copyright (C) 2000-2006 Kern Sibbald
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License
13 version 2 as amended with additional clauses defined in the
14 file LICENSE in the main source directory.
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
19 the file LICENSE for additional details.
26 /* Forward referenced subroutines */
27 static bool record_cb(DCR *dcr, DEV_RECORD *rec);
30 /* Responses sent to the File daemon */
31 static char OK_data[] = "3000 OK data\n";
32 static char FD_error[] = "3000 error\n";
33 static char rec_header[] = "rechdr %ld %ld %ld %ld %ld";
36 * Read Data and send to File Daemon
37 * Returns: false on failure
40 bool do_read_data(JCR *jcr)
42 BSOCK *fd = jcr->file_bsock;
44 DCR *dcr = jcr->read_dcr;
46 Dmsg0(20, "Start read data.\n");
48 if (!bnet_set_buffer_size(fd, dcr->device->max_network_buffer_size, BNET_SETBUF_WRITE)) {
53 create_restore_volume_list(jcr);
54 if (jcr->NumVolumes == 0) {
55 Jmsg(jcr, M_FATAL, 0, _("No Volume names found for restore.\n"));
56 free_restore_volume_list(jcr);
57 bnet_fsend(fd, FD_error);
61 Dmsg2(200, "Found %d volumes names to restore. First=%s\n", jcr->NumVolumes,
62 jcr->VolList->VolumeName);
64 /* Ready device for reading */
65 if (!acquire_device_for_read(dcr)) {
66 free_restore_volume_list(jcr);
67 bnet_fsend(fd, FD_error);
71 /* Tell File daemon we will send data */
72 bnet_fsend(fd, OK_data);
73 ok = read_records(dcr, record_cb, mount_next_read_volume);
75 /* Send end of data to FD */
76 bnet_sig(fd, BNET_EOD);
78 if (!release_device(jcr->read_dcr)) {
82 free_restore_volume_list(jcr);
83 Dmsg0(30, "Done reading.\n");
88 * Called here for each record from read_records()
92 static bool record_cb(DCR *dcr, DEV_RECORD *rec)
95 BSOCK *fd = jcr->file_bsock;
99 if (rec->FileIndex < 0) {
102 Dmsg5(400, "Send to FD: SessId=%u SessTim=%u FI=%d Strm=%d, len=%d\n",
103 rec->VolSessionId, rec->VolSessionTime, rec->FileIndex, rec->Stream,
106 /* Send record header to File daemon */
107 if (!bnet_fsend(fd, rec_header, rec->VolSessionId, rec->VolSessionTime,
108 rec->FileIndex, rec->Stream, rec->data_len)) {
109 Pmsg1(000, _(">filed: Error Hdr=%s\n"), fd->msg);
110 Jmsg1(jcr, M_FATAL, 0, _("Error sending to File daemon. ERR=%s\n"),
114 Dmsg1(400, ">filed: Hdr=%s\n", fd->msg);
118 /* Send data record to File daemon */
119 save_msg = fd->msg; /* save fd message pointer */
120 fd->msg = rec->data; /* pass data directly to bnet_send */
121 fd->msglen = rec->data_len;
122 Dmsg1(400, ">filed: send %d bytes data.\n", fd->msglen);
123 if (!bnet_send(fd)) {
124 Pmsg1(000, _("Error sending to FD. ERR=%s\n"), bnet_strerror(fd));
125 Jmsg1(jcr, M_FATAL, 0, _("Error sending to File daemon. ERR=%s\n"),
130 fd->msg = save_msg; /* restore fd message pointer */