Example #1
0
bool commit_attribute_spool(JCR *jcr)
{
    boffset_t size, data_end;
    char ec1[30];
    char tbuf[MAX_TIME_LENGTH];
    BSOCK *dir;

    Dmsg1(100, "Commit attributes at %s\n", bstrftimes(tbuf, sizeof(tbuf), (utime_t)time(NULL)));
    if (are_attributes_spooled(jcr)) {
        dir = jcr->dir_bsock;
        if ((size = lseek(dir->m_spool_fd, 0, SEEK_END)) == -1) {
            berrno be;

            Jmsg(jcr, M_FATAL, 0, _("lseek on attributes file failed: ERR=%s\n"), be.bstrerror());
            jcr->forceJobStatus(JS_FatalError);  /* override any Incomplete */
            goto bail_out;
        }

        if (jcr->is_JobStatus(JS_Incomplete)) {
            data_end = dir->get_data_end();

            /*
             * Check and truncate to last valid data_end if necssary
             */
            if (size > data_end) {
                if (ftruncate(dir->m_spool_fd, data_end) != 0) {
                    berrno be;

                    Jmsg(jcr, M_FATAL, 0, _("Truncate on attributes file failed: ERR=%s\n"), be.bstrerror());
                    jcr->forceJobStatus(JS_FatalError);  /* override any Incomplete */
                    goto bail_out;
                }
                Dmsg2(100, "=== Attrib spool truncated from %lld to %lld\n", size, data_end);
                size = data_end;
            }
        }

        if (size < 0) {
            berrno be;

            Jmsg(jcr, M_FATAL, 0, _("Fseek on attributes file failed: ERR=%s\n"),
                 be.bstrerror());
            jcr->forceJobStatus(JS_FatalError);  /* override any Incomplete */
            goto bail_out;
        }

        P(mutex);
        if (spool_stats.attr_size + size > spool_stats.max_attr_size) {
            spool_stats.max_attr_size = spool_stats.attr_size + size;
        }
        spool_stats.attr_size += size;
        V(mutex);

        jcr->sendJobStatus(JS_AttrDespooling);
        Jmsg(jcr, M_INFO, 0, _("Sending spooled attrs to the Director. Despooling %s bytes ...\n"),
             edit_uint64_with_commas(size, ec1));

        if (!blast_attr_spool_file(jcr, size)) {
            /* Can't read spool file from director side,
             * send content over network.
             */
            dir->despool(update_attr_spool_size, size);
        }
        return close_attr_spool_file(jcr, dir);
    }
    return true;

bail_out:
    close_attr_spool_file(jcr, dir);
    return false;
}