1 Index: src/dird/catreq.c
2 ===================================================================
3 --- src/dird/catreq.c (révision 8261)
4 +++ src/dird/catreq.c (copie de travail)
10 - * Update File Attributes in the catalog with data
11 - * sent by the Storage daemon. Note, we receive the whole
12 - * attribute record, but we select out only the stat packet,
13 - * VolSessionId, VolSessionTime, FileIndex, file type, and
14 - * file name to store in the catalog.
16 -void catalog_update(JCR *jcr, BSOCK *bs)
17 +static void insert_attribute(JCR *jcr, char *msg, int32_t msglen)
20 uint32_t VolSessionId, VolSessionTime;
27 - if (job_canceled(jcr) || !jcr->pool->catalog_files) {
28 - goto bail_out; /* user disabled cataloging */
31 - omsg = get_memory(bs->msglen+1);
32 - pm_strcpy(omsg, bs->msg);
33 - bs->fsend(_("1994 Invalid Catalog Update: %s"), omsg);
34 - Jmsg1(jcr, M_FATAL, 0, _("Invalid Catalog Update; DB not open: %s"), omsg);
39 /* Start transaction allocates jcr->attr and jcr->ar if needed */
40 db_start_transaction(jcr, jcr->db); /* start transaction if not already open */
43 * there may be a cached attr so we cannot yet write into
44 * jcr->attr or jcr->ar
48 skip_nonspaces(&p); /* UpdCat */
50 skip_nonspaces(&p); /* Job=nnn */
52 unser_uint32(data_len);
55 - Dmsg1(400, "UpdCat msg=%s\n", bs->msg);
56 + Dmsg1(400, "UpdCat msg=%s\n", msg);
57 Dmsg5(400, "UpdCat VolSessId=%d VolSessT=%d FI=%d Strm=%d data_len=%d\n",
58 VolSessionId, VolSessionTime, FileIndex, Stream, data_len);
63 /* Any cached attr is flushed so we can reuse jcr->attr and jcr->ar */
64 - jcr->attr = check_pool_memory_size(jcr->attr, bs->msglen);
65 - memcpy(jcr->attr, bs->msg, bs->msglen);
66 - p = jcr->attr - bs->msg + p; /* point p into jcr->attr */
67 + jcr->attr = check_pool_memory_size(jcr->attr, msglen);
68 + memcpy(jcr->attr, msg, msglen);
69 + p = jcr->attr - msg + p; /* point p into jcr->attr */
70 skip_nonspaces(&p); /* skip FileIndex */
72 filetype = str_to_int32(p); /* TODO: choose between unserialize and str_to_int32 */
80 + * Update File Attributes in the catalog with data
81 + * sent by the Storage daemon. Note, we receive the whole
82 + * attribute record, but we select out only the stat packet,
83 + * VolSessionId, VolSessionTime, FileIndex, file type, and
84 + * file name to store in the catalog.
86 +void catalog_update(JCR *jcr, BSOCK *bs)
90 + if (job_canceled(jcr) || !jcr->pool->catalog_files) {
91 + goto bail_out; /* user disabled cataloging */
94 + omsg = get_memory(bs->msglen+1);
95 + pm_strcpy(omsg, bs->msg);
96 + bs->fsend(_("1994 Invalid Catalog Update: %s"), omsg);
97 + Jmsg1(jcr, M_FATAL, 0, _("Invalid Catalog Update; DB not open: %s"), omsg);
103 + insert_attribute(jcr, bs->msg, bs->msglen);
106 if (job_canceled(jcr)) {
107 cancel_storage_daemon_job(jcr);
111 +bool despool_attributes_from_file(JCR *jcr, const char *file)
116 + ssize_t last = 0, size = 0;
118 + int32_t msglen; /* message length */
119 + POOLMEM *msg = get_pool_memory(PM_MESSAGE);
122 + Dmsg0(0, "Begin despool_attributes_from_file\n");
124 + spool_fd = fopen(file, "rb");
126 + /* send an error message */
129 +#if defined(HAVE_POSIX_FADVISE) && defined(POSIX_FADV_WILLNEED)
130 + posix_fadvise(fileno(spool_fd), 0, 0, POSIX_FADV_WILLNEED);
133 + while (fread((char *)&pktsiz, 1, sizeof(int32_t), spool_fd) ==
135 + size += sizeof(int32_t);
136 + msglen = ntohl(pktsiz);
138 + if (msglen > (int32_t) sizeof_pool_memory(msg)) {
139 + msg = realloc_pool_memory(msg, msglen + 1);
141 + nbytes = fread(msg, 1, msglen, spool_fd);
142 + if (nbytes != (size_t) msglen) {
144 + Dmsg2(400, "nbytes=%d msglen=%d\n", nbytes, msglen);
145 + Qmsg1(jcr, M_FATAL, 0, _("fread attr spool error. ERR=%s\n"),
150 + if ((++count & 0x3F) == 0) {
154 + insert_attribute(jcr, msg, msglen);
156 + if (ferror(spool_fd)) {
158 + Qmsg1(jcr, M_FATAL, 0, _("fread attr spool error. ERR=%s\n"),
169 + if (job_canceled(jcr)) {
170 + cancel_storage_daemon_job(jcr);
173 + free_pool_memory(msg);
174 + Dmsg1(0, "End despool_attributes_from_file ret=%i\n", ret);
177 Index: src/dird/getmsg.c
178 ===================================================================
179 --- src/dird/getmsg.c (révision 8258)
180 +++ src/dird/getmsg.c (copie de travail)
185 - Dmsg2(300, "bget_dirmsg %d: %s\n", n, bs->msg);
186 + Dmsg2(0, "bget_dirmsg %d: %s\n", n, bs->msg);
188 if (is_bnet_stop(bs)) {
189 return n; /* error or terminate */
191 catalog_update(jcr, bs);
194 + if (bs->msg[0] == 'B') { /* SD sending file spool attributes */
195 + Dmsg2(0, "Blast attributes jcr 0x%x: %s", jcr, bs->msg);
196 + char filename[MAX_NAME_LENGTH];
197 + if (sscanf(bs->msg, "BlastAttr Job=%127s File=%127s",
198 + Job, filename) != 2) {
199 + Jmsg1(jcr, M_ERROR, 0, _("Malformed message: %s\n"), bs->msg);
202 + unbash_spaces(filename);
203 + if (despool_attributes_from_file(jcr, filename)) {
204 + bs->fsend("1000 OK BlastAttr\n");
206 + bs->fsend("3000 ERROR BlastAttr\n");
210 if (bs->msg[0] == 'M') { /* Mount request */
211 Dmsg1(900, "Mount req: %s", bs->msg);
212 mount_request(jcr, bs, msg);
213 Index: src/dird/protos.h
214 ===================================================================
215 --- src/dird/protos.h (révision 8258)
216 +++ src/dird/protos.h (copie de travail)
219 extern void catalog_request(JCR *jcr, BSOCK *bs);
220 extern void catalog_update(JCR *jcr, BSOCK *bs);
221 +extern bool despool_attributes_from_file(JCR *jcr, const char *file);
224 extern const char *level_to_str(int level);
225 Index: src/stored/spool.c
226 ===================================================================
227 --- src/stored/spool.c (révision 8258)
228 +++ src/stored/spool.c (copie de travail)
229 @@ -622,13 +622,19 @@
233 +static void make_unique_spool_filename(JCR *jcr, POOLMEM **name, int fd)
235 + Mmsg(name, "%s/%s.attr.%s.%d.spool", working_directory, my_name,
239 bool commit_attribute_spool(JCR *jcr)
245 - Dmsg1(100, "Commit attributes at %s\n", bstrftimes(tbuf, sizeof(tbuf),
246 + Dmsg1(0, "Commit attributes at %s\n", bstrftimes(tbuf, sizeof(tbuf),
247 ( utime_t)time(NULL)));
248 if (are_attributes_spooled(jcr)) {
249 if (fseeko(jcr->dir_bsock->m_spool_fd, 0, SEEK_END) != 0) {
251 dir_send_job_status(jcr);
252 Jmsg(jcr, M_INFO, 0, _("Sending spooled attrs to the Director. Despooling %s bytes ...\n"),
253 edit_uint64_with_commas(size, ec1));
254 - jcr->dir_bsock->despool(update_attr_spool_size, size);
256 + /* send full spool file name */
257 + POOLMEM *name = get_pool_memory(PM_MESSAGE);
258 + make_unique_spool_filename(jcr, &name, jcr->dir_bsock->m_fd);
260 + jcr->dir_bsock->fsend("BlastAttr Job=%s File=%s\n",
262 + free_pool_memory(name);
264 + if (jcr->dir_bsock->recv() <= 0) {
265 + Jmsg(jcr, M_FATAL, 0, _("Network error on BlastAttributes.\n"));
269 + if (!bstrcmp(jcr->dir_bsock->msg, "1000 OK BlastAttr\n")) {
270 + jcr->dir_bsock->despool(update_attr_spool_size, size);
272 return close_attr_spool_file(jcr, jcr->dir_bsock);
279 -static void make_unique_spool_filename(JCR *jcr, POOLMEM **name, int fd)
281 - Mmsg(name, "%s/%s.attr.%s.%d.spool", working_directory, my_name,
286 bool open_attr_spool_file(JCR *jcr, BSOCK *bs)
288 POOLMEM *name = get_pool_memory(PM_MESSAGE);