1 Index: src/dird/catreq.c
2 ===================================================================
3 --- src/dird/catreq.c (révision 8270)
4 +++ src/dird/catreq.c (copie de travail)
9 - * Update File Attributes in the catalog with data
10 - * sent by the Storage daemon. Note, we receive the whole
11 - * attribute record, but we select out only the stat packet,
12 - * VolSessionId, VolSessionTime, FileIndex, file type, and
13 - * file name to store in the catalog.
14 + * Note, we receive the whole attribute record, but we select out only the stat
15 + * packet, VolSessionId, VolSessionTime, FileIndex, file type, and file name to
16 + * store in the catalog.
18 -void catalog_update(JCR *jcr, BSOCK *bs)
19 +static void update_attribute(JCR *jcr, char *msg, int32_t msglen)
22 uint32_t VolSessionId, VolSessionTime;
29 - if (job_canceled(jcr) || !jcr->pool->catalog_files) {
30 - goto bail_out; /* user disabled cataloging */
33 - omsg = get_memory(bs->msglen+1);
34 - pm_strcpy(omsg, bs->msg);
35 - bs->fsend(_("1994 Invalid Catalog Update: %s"), omsg);
36 - Jmsg1(jcr, M_FATAL, 0, _("Invalid Catalog Update; DB not open: %s"), omsg);
41 /* Start transaction allocates jcr->attr and jcr->ar if needed */
42 db_start_transaction(jcr, jcr->db); /* start transaction if not already open */
45 * there may be a cached attr so we cannot yet write into
46 * jcr->attr or jcr->ar
50 skip_nonspaces(&p); /* UpdCat */
52 skip_nonspaces(&p); /* Job=nnn */
54 unser_uint32(data_len);
57 - Dmsg1(400, "UpdCat msg=%s\n", bs->msg);
58 + Dmsg1(400, "UpdCat msg=%s\n", msg);
59 Dmsg5(400, "UpdCat VolSessId=%d VolSessT=%d FI=%d Strm=%d data_len=%d\n",
60 VolSessionId, VolSessionTime, FileIndex, Stream, data_len);
65 /* Any cached attr is flushed so we can reuse jcr->attr and jcr->ar */
66 - jcr->attr = check_pool_memory_size(jcr->attr, bs->msglen);
67 - memcpy(jcr->attr, bs->msg, bs->msglen);
68 - p = jcr->attr - bs->msg + p; /* point p into jcr->attr */
69 + jcr->attr = check_pool_memory_size(jcr->attr, msglen);
70 + memcpy(jcr->attr, msg, msglen);
71 + p = jcr->attr - msg + p; /* point p into jcr->attr */
72 skip_nonspaces(&p); /* skip FileIndex */
74 filetype = str_to_int32(p); /* TODO: choose between unserialize and str_to_int32 */
82 + * Update File Attributes in the catalog with data
83 + * sent by the Storage daemon.
85 +void catalog_update(JCR *jcr, BSOCK *bs)
89 + if (job_canceled(jcr) || !jcr->pool->catalog_files) {
90 + goto bail_out; /* user disabled cataloging */
93 + omsg = get_memory(bs->msglen+1);
94 + pm_strcpy(omsg, bs->msg);
95 + bs->fsend(_("1994 Invalid Catalog Update: %s"), omsg);
96 + Jmsg1(jcr, M_FATAL, 0, _("Invalid Catalog Update; DB not open: %s"), omsg);
102 + update_attribute(jcr, bs->msg, bs->msglen);
105 if (job_canceled(jcr)) {
106 cancel_storage_daemon_job(jcr);
111 + * Update File Attributes in the catalog with data read from
112 + * the storage daemon spool file. We receive the filename and
113 + * we try to read it.
115 +bool despool_attributes_from_file(JCR *jcr, const char *file)
120 + ssize_t last = 0, size = 0;
122 + int32_t msglen; /* message length */
123 + POOLMEM *msg = get_pool_memory(PM_MESSAGE);
124 + FILE *spool_fd=NULL;
126 + Dmsg0(0, "Begin despool_attributes_from_file\n");
128 + if (job_canceled(jcr) || !jcr->pool->catalog_files || !jcr->db) {
129 + goto bail_out; /* user disabled cataloging */
132 + spool_fd = fopen(file, "rb");
134 + Dmsg0(0, "cancel despool_attributes_from_file\n");
135 + /* send an error message */
138 +#if defined(HAVE_POSIX_FADVISE) && defined(POSIX_FADV_WILLNEED)
139 + posix_fadvise(fileno(spool_fd), 0, 0, POSIX_FADV_WILLNEED);
142 + while (fread((char *)&pktsiz, 1, sizeof(int32_t), spool_fd) ==
144 + size += sizeof(int32_t);
145 + msglen = ntohl(pktsiz);
147 + if (msglen > (int32_t) sizeof_pool_memory(msg)) {
148 + msg = realloc_pool_memory(msg, msglen + 1);
150 + nbytes = fread(msg, 1, msglen, spool_fd);
151 + if (nbytes != (size_t) msglen) {
153 + Dmsg2(400, "nbytes=%d msglen=%d\n", nbytes, msglen);
154 + Qmsg1(jcr, M_FATAL, 0, _("fread attr spool error. ERR=%s\n"),
159 + if ((++count & 0x3F) == 0) {
163 + update_attribute(jcr, msg, msglen);
165 + if (ferror(spool_fd)) {
167 + Qmsg1(jcr, M_FATAL, 0, _("fread attr spool error. ERR=%s\n"),
178 + if (job_canceled(jcr)) {
179 + cancel_storage_daemon_job(jcr);
182 + free_pool_memory(msg);
183 + Dmsg1(0, "End despool_attributes_from_file ret=%i\n", ret);
186 Index: src/dird/getmsg.c
187 ===================================================================
188 --- src/dird/getmsg.c (révision 8270)
189 +++ src/dird/getmsg.c (copie de travail)
194 - Dmsg2(300, "bget_dirmsg %d: %s\n", n, bs->msg);
195 + Dmsg2(100, "bget_dirmsg %d: %s\n", n, bs->msg);
197 if (is_bnet_stop(bs)) {
198 return n; /* error or terminate */
200 catalog_update(jcr, bs);
203 + if (bs->msg[0] == 'B') { /* SD sending file spool attributes */
204 + Dmsg2(0, "Blast attributes jcr 0x%x: %s", jcr, bs->msg);
205 + char filename[MAX_NAME_LENGTH];
206 + if (sscanf(bs->msg, "BlastAttr Job=%127s File=%127s",
207 + Job, filename) != 2) {
208 + Jmsg1(jcr, M_ERROR, 0, _("Malformed message: %s\n"), bs->msg);
211 + unbash_spaces(filename);
212 + if (despool_attributes_from_file(jcr, filename)) {
213 + bs->fsend("1000 OK BlastAttr\n");
215 + bs->fsend("1990 ERROR BlastAttr\n");
219 if (bs->msg[0] == 'M') { /* Mount request */
220 Dmsg1(900, "Mount req: %s", bs->msg);
221 mount_request(jcr, bs, msg);
222 Index: src/dird/protos.h
223 ===================================================================
224 --- src/dird/protos.h (révision 8270)
225 +++ src/dird/protos.h (copie de travail)
228 extern void catalog_request(JCR *jcr, BSOCK *bs);
229 extern void catalog_update(JCR *jcr, BSOCK *bs);
230 +extern bool despool_attributes_from_file(JCR *jcr, const char *file);
233 extern const char *level_to_str(int level);
234 Index: src/stored/spool.c
235 ===================================================================
236 --- src/stored/spool.c (révision 8270)
237 +++ src/stored/spool.c (copie de travail)
238 @@ -622,13 +622,40 @@
242 +static void make_unique_spool_filename(JCR *jcr, POOLMEM **name, int fd)
244 + Mmsg(name, "%s/%s.attr.%s.%d.spool", working_directory, my_name,
248 +static bool blast_attr_spool_file(JCR *jcr, boffset_t size)
250 + /* send full spool file name */
251 + POOLMEM *name = get_pool_memory(PM_MESSAGE);
252 + make_unique_spool_filename(jcr, &name, jcr->dir_bsock->m_fd);
254 + jcr->dir_bsock->fsend("BlastAttr Job=%s File=%s\n",
256 + free_pool_memory(name);
258 + if (jcr->dir_bsock->recv() <= 0) {
259 + Jmsg(jcr, M_FATAL, 0, _("Network error on BlastAttributes.\n"));
263 + if (!bstrcmp(jcr->dir_bsock->msg, "1000 OK BlastAttr\n")) {
269 bool commit_attribute_spool(JCR *jcr)
275 - Dmsg1(100, "Commit attributes at %s\n", bstrftimes(tbuf, sizeof(tbuf),
276 + Dmsg1(0, "Commit attributes at %s\n", bstrftimes(tbuf, sizeof(tbuf),
277 ( utime_t)time(NULL)));
278 if (are_attributes_spooled(jcr)) {
279 if (fseeko(jcr->dir_bsock->m_spool_fd, 0, SEEK_END) != 0) {
281 dir_send_job_status(jcr);
282 Jmsg(jcr, M_INFO, 0, _("Sending spooled attrs to the Director. Despooling %s bytes ...\n"),
283 edit_uint64_with_commas(size, ec1));
284 - jcr->dir_bsock->despool(update_attr_spool_size, size);
286 + if (!blast_attr_spool_file(jcr, size)) {
287 + /* Can't read spool file from director side,
288 + * send content over network.
290 + jcr->dir_bsock->despool(update_attr_spool_size, size);
292 return close_attr_spool_file(jcr, jcr->dir_bsock);
299 -static void make_unique_spool_filename(JCR *jcr, POOLMEM **name, int fd)
301 - Mmsg(name, "%s/%s.attr.%s.%d.spool", working_directory, my_name,
306 bool open_attr_spool_file(JCR *jcr, BSOCK *bs)
308 POOLMEM *name = get_pool_memory(PM_MESSAGE);