From 6dd6165a8cb1bb13fd022c57294c40ed3558f692 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Fri, 27 May 2005 09:13:20 +0000 Subject: [PATCH] Implement Maximum Job Spool Size (actually DCR based) git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2092 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/kernstodo | 8 +- bacula/kes-1.37 | 2 + bacula/src/stored/acquire.c | 302 ++++++++++++++++---------------- bacula/src/stored/dev.h | 6 +- bacula/src/stored/spool.c | 204 ++++++++++----------- bacula/src/stored/stored_conf.c | 44 ++--- 6 files changed, 281 insertions(+), 285 deletions(-) diff --git a/bacula/kernstodo b/bacula/kernstodo index c3d0325758..333836635c 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -1,5 +1,5 @@ Kern's ToDo List - 26 May 2005 + 27 May 2005 Major development: Project Developer @@ -68,8 +68,6 @@ For 1.37: - Upgrade to MySQL 4.1.1 See: http://dev.mysql.com/doc/mysql/en/Server_SQL_mode.html - Max Vols limit in Pool off by one? -- Require restore via the restore command or make a restore Job - get the bootstrap file. - Make bootstrap file handle multiple MediaTypes (SD) - Test restoring into a user restricted directory on Win32 -- see bug report. @@ -88,7 +86,6 @@ For 1.37: it can check if Clients are alive. - Implement "NewVolumeEachJob = yes|no" in Dir. -- Implement Maximum Job Spool Size - Remove all old Device resource code in Dir and code to pass it back in SD -- better, rework it to pass back device statistics. - Check locking of resources -- be sure to lock devices where previously @@ -1285,4 +1282,7 @@ Block Position: 0 hour time. I changed the time to 11:59am and everything works fine. Also 12:00am works fine. 0:00pm also works (which I don't think should). None of the values 12:00pm - 12:59pm work for that matter. +- Require restore via the restore command or make a restore Job + get the bootstrap file. +- Implement Maximum Job Spool Size diff --git a/bacula/kes-1.37 b/bacula/kes-1.37 index 5db4c08a9f..b585992f38 100644 --- a/bacula/kes-1.37 +++ b/bacula/kes-1.37 @@ -4,6 +4,8 @@ General: Changes to 1.37.20: +27May05 +- Implement Maximum Job Spool Size (actually DCR based) 26May05 - Use light weight non-recursive locking on jcr chain. - Make JCR a class and implement inc_use_count() and diff --git a/bacula/src/stored/acquire.c b/bacula/src/stored/acquire.c index fd1864ad84..6425e690b4 100644 --- a/bacula/src/stored/acquire.c +++ b/bacula/src/stored/acquire.c @@ -47,11 +47,11 @@ DCR *new_dcr(JCR *jcr, DEVICE *dev) dcr->block = new_block(dev); dcr->rec = new_record(); dcr->spool_fd = -1; - dcr->max_spool_size = dev->device->max_spool_size; + dcr->max_job_spool_size = dev->device->max_job_spool_size; /* Attach this dcr only if dev is initialized */ if (dev->fd != 0 && jcr && jcr->JobType != JT_SYSTEM) { - dev->attached_dcrs->append(dcr); /* attach dcr to device */ -// jcr->dcrs->append(dcr); /* put dcr in list for Job */ + dev->attached_dcrs->append(dcr); /* attach dcr to device */ +// jcr->dcrs->append(dcr); /* put dcr in list for Job */ } return dcr; } @@ -70,13 +70,13 @@ static void remove_dcr_from_dcrs(DCR *dcr) DCR *ldcr; int num = jcr->dcrs->size(); for (i=0; i < num; i++) { - ldcr = (DCR *)jcr->dcrs->get(i); - if (ldcr == dcr) { - jcr->dcrs->remove(i); - if (jcr->dcr == dcr) { - jcr->dcr = NULL; - } - } + ldcr = (DCR *)jcr->dcrs->get(i); + if (ldcr == dcr) { + jcr->dcrs->remove(i); + if (jcr->dcr == dcr) { + jcr->dcr = NULL; + } + } } } } @@ -100,15 +100,15 @@ void free_dcr(DCR *dcr) dev->num_writers--; if (dev->num_writers < 0) { Jmsg1(dcr->jcr, M_ERROR, 0, _("Hey! num_writers=%d!!!!\n"), dev->num_writers); - dev->num_writers = 0; - dcr->reserved_device = false; + dev->num_writers = 0; + dcr->reserved_device = false; } unlock_device(dev); } /* Detach this dcr only if the dev is initialized */ if (dev->fd != 0 && jcr && jcr->JobType != JT_SYSTEM) { - dev->attached_dcrs->remove(dcr); /* detach dcr from device */ + dev->attached_dcrs->remove(dcr); /* detach dcr from device */ // remove_dcr_from_dcrs(dcr); /* remove dcr from jcr list */ } if (dcr->block) { @@ -140,15 +140,15 @@ bool reserve_device_for_read(DCR *dcr) dev->block(BST_DOING_ACQUIRE); - if (device_is_unmounted(dev)) { + if (device_is_unmounted(dev)) { Mmsg(jcr->errmsg, _("Device %s is BLOCKED due to user unmount.\n"), - dev->print_name()); + dev->print_name()); goto bail_out; } if (dev->is_busy()) { Mmsg1(jcr->errmsg, _("Device %s is busy.\n"), - dev->print_name()); + dev->print_name()); goto bail_out; } @@ -169,7 +169,7 @@ bail_out: * leave the block pointers just after the label. * * Returns: NULL if failed for any reason - * dcr if successful + * dcr if successful */ DCR *acquire_device_for_read(DCR *dcr) { @@ -187,7 +187,7 @@ DCR *acquire_device_for_read(DCR *dcr) if (dev->num_writers > 0) { Jmsg2(jcr, M_FATAL, 0, _("Num_writers=%d not zero. Job %d canceled.\n"), - dev->num_writers, jcr->JobId); + dev->num_writers, jcr->JobId); goto get_out; } @@ -202,14 +202,14 @@ DCR *acquire_device_for_read(DCR *dcr) vol = vol->next; } if (!vol) { - goto get_out; /* should not happen */ + goto get_out; /* should not happen */ } bstrncpy(dcr->VolumeName, vol->VolumeName, sizeof(dcr->VolumeName)); init_device_wait_timers(dcr); tape_previously_mounted = dev->can_read() || dev->can_append() || - dev->is_labeled(); + dev->is_labeled(); tape_initially_mounted = tape_previously_mounted; @@ -222,10 +222,10 @@ DCR *acquire_device_for_read(DCR *dcr) dev->num_parts = dcr->VolCatInfo.VolCatParts; for (i=0; i<5; i++) { - dev->clear_labeled(); /* force reread of label */ + dev->clear_labeled(); /* force reread of label */ if (job_canceled(jcr)) { Mmsg1(dev->errmsg, _("Job %d canceled.\n"), jcr->JobId); - goto get_out; /* error return */ + goto get_out; /* error return */ } /* * This code ensures that the device is ready for @@ -234,91 +234,91 @@ DCR *acquire_device_for_read(DCR *dcr) */ for ( ; !dev->is_open(); ) { Dmsg1(120, "bstored: open vol=%s\n", dcr->VolumeName); - if (open_dev(dev, dcr->VolumeName, OPEN_READ_ONLY) < 0) { - if (dev->dev_errno == EIO) { /* no tape loaded */ + if (open_dev(dev, dcr->VolumeName, OPEN_READ_ONLY) < 0) { + if (dev->dev_errno == EIO) { /* no tape loaded */ Jmsg3(jcr, M_WARNING, 0, _("Open device %s Volume \"%s\" failed: ERR=%s\n"), - dev->print_name(), dcr->VolumeName, strerror_dev(dev)); - goto default_path; - } - - /* If we have a dvd that requires mount, - * we need to try to open the label, so the info can be reported - * if a wrong volume has been mounted. */ - if (dev->is_dvd() && (dcr->VolCatInfo.VolCatParts > 0)) { - break; - } - + dev->print_name(), dcr->VolumeName, strerror_dev(dev)); + goto default_path; + } + + /* If we have a dvd that requires mount, + * we need to try to open the label, so the info can be reported + * if a wrong volume has been mounted. */ + if (dev->is_dvd() && (dcr->VolCatInfo.VolCatParts > 0)) { + break; + } + Jmsg3(jcr, M_FATAL, 0, _("Open device %s Volume \"%s\" failed: ERR=%s\n"), - dev->print_name(), dcr->VolumeName, strerror_dev(dev)); - goto get_out; - } + dev->print_name(), dcr->VolumeName, strerror_dev(dev)); + goto get_out; + } Dmsg1(129, "open_dev %s OK\n", dev->print_name()); } if (dev->is_dvd()) { - vol_label_status = read_dev_volume_label_guess(dcr, 0); + vol_label_status = read_dev_volume_label_guess(dcr, 0); } else { - vol_label_status = read_dev_volume_label(dcr); + vol_label_status = read_dev_volume_label(dcr); } Dmsg0(200, "calling read-vol-label\n"); switch (vol_label_status) { case VOL_OK: - vol_ok = true; - memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo)); - break; /* got it */ + vol_ok = true; + memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo)); + break; /* got it */ case VOL_IO_ERROR: - /* - * Send error message generated by read_dev_volume_label() - * only we really had a tape mounted. This supresses superfluous - * error messages when nothing is mounted. - */ - if (tape_previously_mounted) { + /* + * Send error message generated by read_dev_volume_label() + * only we really had a tape mounted. This supresses superfluous + * error messages when nothing is mounted. + */ + if (tape_previously_mounted) { Jmsg(jcr, M_WARNING, 0, "%s", jcr->errmsg); - } - goto default_path; + } + goto default_path; case VOL_NAME_ERROR: - if (tape_initially_mounted) { - tape_initially_mounted = false; - goto default_path; - } - /* Fall through */ + if (tape_initially_mounted) { + tape_initially_mounted = false; + goto default_path; + } + /* Fall through */ default: Jmsg1(jcr, M_WARNING, 0, "%s", jcr->errmsg); default_path: - tape_previously_mounted = true; - - /* If the device requires mount, close it, so the device can be ejected. - * FIXME: This should perhaps be done for all devices. */ - if (dev_cap(dev, CAP_REQMOUNT)) { - force_close_dev(dev); - } - - /* Call autochanger only once unless ask_sysop called */ - if (try_autochanger) { - int stat; + tape_previously_mounted = true; + + /* If the device requires mount, close it, so the device can be ejected. + * FIXME: This should perhaps be done for all devices. */ + if (dev_cap(dev, CAP_REQMOUNT)) { + force_close_dev(dev); + } + + /* Call autochanger only once unless ask_sysop called */ + if (try_autochanger) { + int stat; Dmsg2(200, "calling autoload Vol=%s Slot=%d\n", - dcr->VolumeName, dcr->VolCatInfo.Slot); - stat = autoload_device(dcr, 0, NULL); - if (stat > 0) { - try_autochanger = false; - continue; /* try reading volume mounted */ - } - } - - /* Mount a specific volume and no other */ + dcr->VolumeName, dcr->VolCatInfo.Slot); + stat = autoload_device(dcr, 0, NULL); + if (stat > 0) { + try_autochanger = false; + continue; /* try reading volume mounted */ + } + } + + /* Mount a specific volume and no other */ Dmsg0(200, "calling dir_ask_sysop\n"); - if (!dir_ask_sysop_to_mount_volume(dcr)) { - goto get_out; /* error return */ - } - try_autochanger = true; /* permit using autochanger again */ - continue; /* try reading again */ + if (!dir_ask_sysop_to_mount_volume(dcr)) { + goto get_out; /* error return */ + } + try_autochanger = true; /* permit using autochanger again */ + continue; /* try reading again */ } /* end switch */ break; } /* end for loop */ if (!vol_ok) { Jmsg1(jcr, M_FATAL, 0, _("Too many errors trying to mount device %s.\n"), - dev->print_name()); + dev->print_name()); goto get_out; } @@ -391,8 +391,8 @@ bail_out: /* * Returns: 1 if drive can be reserved - * 0 if we should wait - * -1 on error + * 0 if we should wait + * -1 on error */ static int can_reserve_drive(DCR *dcr) { @@ -403,21 +403,21 @@ static int can_reserve_drive(DCR *dcr) */ if (!dev->can_append() && dev->num_writers == 0) { /* Now check if there are any reservations on the drive */ - if (dev->reserved_device) { - /* Yes, now check if we want the same Pool and pool type */ - if (strcmp(dev->pool_name, dcr->pool_name) == 0 && - strcmp(dev->pool_type, dcr->pool_type) == 0) { - /* OK, compatible device */ - } else { - /* Drive not suitable for us */ - return 0; /* wait */ - } + if (dev->reserved_device) { + /* Yes, now check if we want the same Pool and pool type */ + if (strcmp(dev->pool_name, dcr->pool_name) == 0 && + strcmp(dev->pool_type, dcr->pool_type) == 0) { + /* OK, compatible device */ + } else { + /* Drive not suitable for us */ + return 0; /* wait */ + } } else { - /* Device is available but not yet reserved, reserve it for us */ - bstrncpy(dev->pool_name, dcr->pool_name, sizeof(dev->pool_name)); - bstrncpy(dev->pool_type, dcr->pool_type, sizeof(dev->pool_type)); + /* Device is available but not yet reserved, reserve it for us */ + bstrncpy(dev->pool_name, dcr->pool_name, sizeof(dev->pool_name)); + bstrncpy(dev->pool_type, dcr->pool_type, sizeof(dev->pool_type)); } - return 1; /* reserve drive */ + return 1; /* reserve drive */ } /* @@ -438,19 +438,19 @@ static int can_reserve_drive(DCR *dcr) Dmsg0(190, "device already in append.\n"); /* Yes, now check if we want the same Pool and pool type */ if (strcmp(dev->pool_name, dcr->pool_name) == 0 && - strcmp(dev->pool_type, dcr->pool_type) == 0) { - /* OK, compatible device */ + strcmp(dev->pool_type, dcr->pool_type) == 0) { + /* OK, compatible device */ } else { - /* Drive not suitable for us */ + /* Drive not suitable for us */ Jmsg(jcr, M_WARNING, 0, _("Device %s is busy writing on another Volume.\n"), dev->print_name()); - return 0; /* wait */ + return 0; /* wait */ } } else { Pmsg0(000, "Logic error!!!! Should not get here.\n"); Jmsg0(jcr, M_FATAL, 0, _("Logic error!!!! Should not get here.\n")); - return -1; /* error, should not get here */ + return -1; /* error, should not get here */ } - return 1; /* reserve drive */ + return 1; /* reserve drive */ } /* @@ -458,7 +458,7 @@ static int can_reserve_drive(DCR *dcr) * If this is the first one, we read the label. * * Returns: NULL if failed for any reason - * dcr if successful. + * dcr if successful. * Note, normally reserve_device_for_append() is called * before this routine. */ @@ -501,34 +501,34 @@ DCR *acquire_device_for_append(DCR *dcr) */ bstrncpy(dcr->VolumeName, dev->VolHdr.VolName, sizeof(dcr->VolumeName)); if (!dir_get_volume_info(dcr, GET_VOL_INFO_FOR_WRITE) && - !(dir_find_next_appendable_volume(dcr) && - strcmp(dev->VolHdr.VolName, dcr->VolumeName) == 0)) { /* wrong tape mounted */ + !(dir_find_next_appendable_volume(dcr) && + strcmp(dev->VolHdr.VolName, dcr->VolumeName) == 0)) { /* wrong tape mounted */ Dmsg0(190, "Wrong tape mounted.\n"); - if (dev->num_writers != 0 || dev->reserved_device) { + if (dev->num_writers != 0 || dev->reserved_device) { Jmsg(jcr, M_FATAL, 0, _("Device %s is busy writing on another Volume.\n"), dev->print_name()); - goto get_out; - } - /* Wrong tape mounted, release it, then fall through to get correct one */ + goto get_out; + } + /* Wrong tape mounted, release it, then fall through to get correct one */ Dmsg0(190, "Wrong tape mounted, release and try mount.\n"); - release = true; - do_mount = true; + release = true; + do_mount = true; } else { - /* - * At this point, the correct tape is already mounted, so - * we do not need to do mount_next_write_volume(), unless - * we need to recycle the tape. - */ + /* + * At this point, the correct tape is already mounted, so + * we do not need to do mount_next_write_volume(), unless + * we need to recycle the tape. + */ recycle = strcmp(dcr->VolCatInfo.VolCatStatus, "Recycle") == 0; Dmsg1(190, "Correct tape mounted. recycle=%d\n", recycle); - if (recycle && dev->num_writers != 0) { + if (recycle && dev->num_writers != 0) { Jmsg(jcr, M_FATAL, 0, _("Cannot recycle volume \"%s\"" " on device %s because it is in use by another job.\n"), - dev->VolHdr.VolName, dev->print_name()); - goto get_out; - } - if (dev->num_writers == 0) { - memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo)); - } + dev->VolHdr.VolName, dev->print_name()); + goto get_out; + } + if (dev->num_writers == 0) { + memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo)); + } } } else { /* Not already in append mode, so mount the device */ @@ -541,16 +541,16 @@ DCR *acquire_device_for_append(DCR *dcr) Dmsg0(190, "Do mount_next_write_vol\n"); bool mounted = mount_next_write_volume(dcr, release); if (!mounted) { - if (!job_canceled(jcr)) { + if (!job_canceled(jcr)) { /* Reduce "noise" -- don't print if job canceled */ Jmsg(jcr, M_FATAL, 0, _("Could not ready device %s for append.\n"), - dev->print_name()); - } - goto get_out; + dev->print_name()); + } + goto get_out; } } - dev->num_writers++; /* we are now a writer */ + dev->num_writers++; /* we are now a writer */ if (jcr->NumVolumes == 0) { jcr->NumVolumes = 1; } @@ -589,7 +589,7 @@ bool release_device(DCR *dcr) } if (dev->can_read()) { - dev->clear_read(); /* clear read bit */ + dev->clear_read(); /* clear read bit */ /******FIXME**** send read volume usage statistics to director */ @@ -604,26 +604,26 @@ bool release_device(DCR *dcr) Dmsg1(100, "There are %d writers in release_device\n", dev->num_writers); if (dev->is_labeled()) { Dmsg0(100, "dir_create_jobmedia_record. Release\n"); - if (!dev->at_weot() && !dir_create_jobmedia_record(dcr)) { + if (!dev->at_weot() && !dir_create_jobmedia_record(dcr)) { Jmsg(jcr, M_FATAL, 0, _("Could not create JobMedia record for Volume=\"%s\" Job=%s\n"), - dcr->VolCatInfo.VolCatName, jcr->Job); - } - /* If no more writers, write an EOF */ - if (!dev->num_writers && dev->can_write()) { - weof_dev(dev, 1); - write_ansi_ibm_labels(dcr, ANSI_EOF_LABEL, dev->VolHdr.VolName); - } - if (!dev->at_weot()) { - dev->VolCatInfo.VolCatFiles = dev->file; /* set number of files */ - dev->VolCatInfo.VolCatJobs++; /* increment number of jobs */ - /* Note! do volume update before close, which zaps VolCatInfo */ + dcr->VolCatInfo.VolCatName, jcr->Job); + } + /* If no more writers, write an EOF */ + if (!dev->num_writers && dev->can_write()) { + weof_dev(dev, 1); + write_ansi_ibm_labels(dcr, ANSI_EOF_LABEL, dev->VolHdr.VolName); + } + if (!dev->at_weot()) { + dev->VolCatInfo.VolCatFiles = dev->file; /* set number of files */ + dev->VolCatInfo.VolCatJobs++; /* increment number of jobs */ + /* Note! do volume update before close, which zaps VolCatInfo */ Dmsg0(100, "dir_update_vol_info. Release0\n"); - dir_update_volume_info(dcr, false); /* send Volume info to Director */ - } + dir_update_volume_info(dcr, false); /* send Volume info to Director */ + } } } else { - /* + /* * If we reach here, it is most likely because the job * has failed, since the device is not in read mode and * there are no writers. It was probably reserved. @@ -646,17 +646,17 @@ bool release_device(DCR *dcr) alert = edit_device_codes(dcr, alert, dcr->device->alert_command, ""); bpipe = open_bpipe(alert, 0, "r"); if (bpipe) { - while (fgets(line, sizeof(line), bpipe->rfd)) { + while (fgets(line, sizeof(line), bpipe->rfd)) { Jmsg(jcr, M_ALERT, 0, _("Alert: %s"), line); - } - status = close_bpipe(bpipe); + } + status = close_bpipe(bpipe); } else { - status = errno; + status = errno; } if (status != 0) { - berrno be; + berrno be; Jmsg(jcr, M_ALERT, 0, _("3997 Bad alert command: %s: ERR=%s.\n"), - alert, be.strerror(status)); + alert, be.strerror(status)); } Dmsg1(400, "alert status=%d\n", status); diff --git a/bacula/src/stored/dev.h b/bacula/src/stored/dev.h index 724ce2e1c4..d5fbb73705 100644 --- a/bacula/src/stored/dev.h +++ b/bacula/src/stored/dev.h @@ -215,7 +215,7 @@ public: uint64_t max_file_size; /* max file size to put in one file on volume */ uint64_t volume_capacity; /* advisory capacity */ uint64_t max_spool_size; /* maximum spool file size */ - uint64_t spool_size; /* current spool size */ + uint64_t spool_size; /* current spool size for this device */ uint32_t max_rewind_wait; /* max secs to allow for rewind */ uint32_t max_open_wait; /* max secs to allow for open */ uint32_t max_open_vols; /* max simultaneous open volumes */ @@ -342,8 +342,8 @@ public: uint32_t StartFile; /* Start write file */ uint32_t StartBlock; /* Start write block */ uint32_t EndBlock; /* Ending block written */ - int64_t spool_size; /* Current spool size */ - int64_t max_spool_size; /* Max job spool size */ + int64_t job_spool_size; /* Current job spool size */ + int64_t max_job_spool_size; /* Max job spool size */ char VolumeName[MAX_NAME_LENGTH]; /* Volume name */ char pool_name[MAX_NAME_LENGTH]; /* pool name */ char pool_type[MAX_NAME_LENGTH]; /* pool type */ diff --git a/bacula/src/stored/spool.c b/bacula/src/stored/spool.c index 7b2255b7ca..8aeee106a7 100644 --- a/bacula/src/stored/spool.c +++ b/bacula/src/stored/spool.c @@ -1,7 +1,7 @@ /* * Spooling code * - * Kern Sibbald, March 2004 + * Kern Sibbald, March 2004 * * Version $Id$ */ @@ -35,13 +35,13 @@ static bool write_spool_header(DCR *dcr); static bool write_spool_data(DCR *dcr); struct spool_stats_t { - uint32_t data_jobs; /* current jobs spooling data */ + uint32_t data_jobs; /* current jobs spooling data */ uint32_t attr_jobs; - uint32_t total_data_jobs; /* total jobs to have spooled data */ + uint32_t total_data_jobs; /* total jobs to have spooled data */ uint32_t total_attr_jobs; - int64_t max_data_size; /* max data size */ + int64_t max_data_size; /* max data size */ int64_t max_attr_size; - int64_t data_size; /* current data size (all jobs running) */ + int64_t data_size; /* current data size (all jobs running) */ int64_t attr_size; }; @@ -51,9 +51,9 @@ spool_stats_t spool_stats; /* * Header for data spool record */ struct spool_hdr { - int32_t FirstIndex; /* FirstIndex for buffer */ - int32_t LastIndex; /* LastIndex for buffer */ - uint32_t len; /* length of next buffer */ + int32_t FirstIndex; /* FirstIndex for buffer */ + int32_t LastIndex; /* LastIndex for buffer */ + uint32_t len; /* length of next buffer */ }; enum { @@ -67,15 +67,15 @@ void list_spool_stats(BSOCK *bs) char ed1[30], ed2[30]; if (spool_stats.data_jobs || spool_stats.max_data_size) { bnet_fsend(bs, "Data spooling: %u active jobs, %s bytes; %u total jobs, %s max bytes/job.\n", - spool_stats.data_jobs, edit_uint64_with_commas(spool_stats.data_size, ed1), - spool_stats.total_data_jobs, - edit_uint64_with_commas(spool_stats.max_data_size, ed2)); + spool_stats.data_jobs, edit_uint64_with_commas(spool_stats.data_size, ed1), + spool_stats.total_data_jobs, + edit_uint64_with_commas(spool_stats.max_data_size, ed2)); } if (spool_stats.attr_jobs || spool_stats.max_attr_size) { bnet_fsend(bs, "Attr spooling: %u active jobs, %s bytes; %u total jobs, %s max bytes.\n", - spool_stats.attr_jobs, edit_uint64_with_commas(spool_stats.attr_size, ed1), - spool_stats.total_attr_jobs, - edit_uint64_with_commas(spool_stats.max_attr_size, ed2)); + spool_stats.attr_jobs, edit_uint64_with_commas(spool_stats.attr_size, ed1), + spool_stats.total_attr_jobs, + edit_uint64_with_commas(spool_stats.max_attr_size, ed2)); } } @@ -87,11 +87,11 @@ bool begin_data_spool(DCR *dcr) dcr->spool_data = true; stat = open_data_spool_file(dcr); if (stat) { - dcr->spooling = true; + dcr->spooling = true; Jmsg(dcr->jcr, M_INFO, 0, _("Spooling data ...\n")); - P(mutex); - spool_stats.data_jobs++; - V(mutex); + P(mutex); + spool_stats.data_jobs++; + V(mutex); } } return stat; @@ -115,8 +115,8 @@ bool commit_data_spool(DCR *dcr) stat = despool_data(dcr, true /*commit*/); if (!stat) { Pmsg1(000, "Bad return from despool WroteVol=%d\n", dcr->WroteVol); - close_data_spool_file(dcr); - return false; + close_data_spool_file(dcr); + return false; } return close_data_spool_file(dcr); } @@ -132,7 +132,7 @@ static void make_unique_data_spool_filename(DCR *dcr, POOLMEM **name) dir = working_directory; } Mmsg(name, "%s/%s.data.spool.%s.%s", dir, my_name, dcr->jcr->Job, - dcr->device->hdr.name); + dcr->device->hdr.name); } @@ -148,7 +148,7 @@ static bool open_data_spool_file(DCR *dcr) } else { berrno be; Jmsg(dcr->jcr, M_FATAL, 0, _("Open data spool file %s failed: ERR=%s\n"), name, - be.strerror()); + be.strerror()); free_pool_memory(name); return false; } @@ -164,12 +164,12 @@ static bool close_data_spool_file(DCR *dcr) P(mutex); spool_stats.data_jobs--; spool_stats.total_data_jobs++; - if (spool_stats.data_size < dcr->spool_size) { + if (spool_stats.data_size < dcr->job_spool_size) { spool_stats.data_size = 0; } else { - spool_stats.data_size -= dcr->spool_size; + spool_stats.data_size -= dcr->job_spool_size; } - dcr->spool_size = 0; + dcr->job_spool_size = 0; V(mutex); make_unique_data_spool_filename(dcr, &name); @@ -197,7 +197,7 @@ static bool despool_data(DCR *dcr, bool commit) Dmsg0(100, "Despooling data\n"); Jmsg(jcr, M_INFO, 0, _("%s spooled data to Volume. Despooling %s bytes ...\n"), commit?"Committing":"Writing", - edit_uint64_with_commas(jcr->dcr->spool_size, ec1)); + edit_uint64_with_commas(jcr->dcr->job_spool_size, ec1)); dcr->spooling = false; lock_device(dcr->dev); dcr->dev_locked = true; @@ -218,53 +218,53 @@ static bool despool_data(DCR *dcr, bool commit) rdev->device = dcr->dev->device; rdcr = new_dcr(NULL, rdev); rdcr->spool_fd = dcr->spool_fd; - rdcr->jcr = jcr; /* set a valid jcr */ - block = dcr->block; /* save block */ - dcr->block = rdcr->block; /* make read and write block the same */ + rdcr->jcr = jcr; /* set a valid jcr */ + block = dcr->block; /* save block */ + dcr->block = rdcr->block; /* make read and write block the same */ Dmsg1(800, "read/write block size = %d\n", block->buf_len); lseek(rdcr->spool_fd, 0, SEEK_SET); /* rewind */ for ( ; ok; ) { if (job_canceled(jcr)) { - ok = false; - break; + ok = false; + break; } stat = read_block_from_spool_file(rdcr); if (stat == RB_EOT) { - break; + break; } else if (stat == RB_ERROR) { - ok = false; - break; + ok = false; + break; } ok = write_block_to_device(dcr); if (!ok) { Jmsg2(jcr, M_FATAL, 0, _("Fatal append error on device %s: ERR=%s\n"), - dcr->dev->print_name(), strerror_dev(dcr->dev)); + dcr->dev->print_name(), strerror_dev(dcr->dev)); } Dmsg3(800, "Write block ok=%d FI=%d LI=%d\n", ok, block->FirstIndex, block->LastIndex); } - dcr->block = block; /* reset block */ + dcr->block = block; /* reset block */ lseek(rdcr->spool_fd, 0, SEEK_SET); /* rewind */ if (ftruncate(rdcr->spool_fd, 0) != 0) { berrno be; Jmsg(dcr->jcr, M_ERROR, 0, _("Ftruncate spool file failed: ERR=%s\n"), - be.strerror()); + be.strerror()); Pmsg1(000, "Bad return from ftruncate. ERR=%s\n", be.strerror()); ok = false; } P(mutex); - if (spool_stats.data_size < dcr->spool_size) { + if (spool_stats.data_size < dcr->job_spool_size) { spool_stats.data_size = 0; } else { - spool_stats.data_size -= dcr->spool_size; + spool_stats.data_size -= dcr->job_spool_size; } V(mutex); P(dcr->dev->spool_mutex); - dcr->dev->spool_size -= dcr->spool_size; - dcr->spool_size = 0; /* zap size in input dcr */ + dcr->dev->spool_size -= dcr->job_spool_size; + dcr->job_spool_size = 0; /* zap size in input dcr */ V(dcr->dev->spool_mutex); free_memory(rdev->dev_name); free_pool_memory(rdev->errmsg); @@ -274,7 +274,7 @@ static bool despool_data(DCR *dcr, bool commit) free(rdev); unlock_device(dcr->dev); dcr->dev_locked = false; - dcr->spooling = true; /* turn on spooling again */ + dcr->spooling = true; /* turn on spooling again */ return ok; } @@ -282,8 +282,8 @@ static bool despool_data(DCR *dcr, bool commit) * Read a block from the spool file * * Returns RB_OK on success - * RB_EOT when file done - * RB_ERROR on error + * RB_EOT when file done + * RB_ERROR on error */ static int read_block_from_spool_file(DCR *dcr) { @@ -299,9 +299,9 @@ static int read_block_from_spool_file(DCR *dcr) return RB_EOT; } else if (stat != (ssize_t)rlen) { if (stat == -1) { - berrno be; + berrno be; Jmsg(dcr->jcr, M_FATAL, 0, _("Spool header read error. ERR=%s\n"), - be.strerror()); + be.strerror()); } else { Pmsg2(000, "Spool read error. Wanted %u bytes, got %d\n", rlen, stat); Jmsg2(dcr->jcr, M_FATAL, 0, _("Spool header read error. Wanted %u bytes, got %d\n"), rlen, stat); @@ -335,25 +335,25 @@ static int read_block_from_spool_file(DCR *dcr) * Write a block to the spool file * * Returns: true on success or EOT - * false on hard error + * false on hard error */ bool write_block_to_spool_file(DCR *dcr) { - uint32_t wlen, hlen; /* length to write */ + uint32_t wlen, hlen; /* length to write */ bool despool = false; DEV_BLOCK *block = dcr->block; ASSERT(block->binbuf == ((uint32_t) (block->bufp - block->buf))); - if (block->binbuf <= WRITE_BLKHDR_LENGTH) { /* Does block have data in it? */ + if (block->binbuf <= WRITE_BLKHDR_LENGTH) { /* Does block have data in it? */ return true; } hlen = sizeof(spool_hdr); wlen = block->binbuf; P(dcr->dev->spool_mutex); - dcr->spool_size += hlen + wlen; + dcr->job_spool_size += hlen + wlen; dcr->dev->spool_size += hlen + wlen; - if ((dcr->max_spool_size > 0 && dcr->spool_size >= dcr->max_spool_size) || + if ((dcr->max_job_spool_size > 0 && dcr->job_spool_size >= dcr->max_job_spool_size) || (dcr->dev->max_spool_size > 0 && dcr->dev->spool_size >= dcr->dev->max_spool_size)) { despool = true; } @@ -369,19 +369,19 @@ bool write_block_to_spool_file(DCR *dcr) char ec1[30], ec2[30], ec3[30], ec4[30]; Dmsg4(100, "Despool in write_block_to_spool_file max_size=%s size=%s " "max_job_size=%s job_size=%s\n", - edit_uint64_with_commas(dcr->max_spool_size, ec1), - edit_uint64_with_commas(dcr->spool_size, ec2), - edit_uint64_with_commas(dcr->dev->max_spool_size, ec3), - edit_uint64_with_commas(dcr->dev->spool_size, ec4)); + edit_uint64_with_commas(dcr->max_job_spool_size, ec1), + edit_uint64_with_commas(dcr->job_spool_size, ec2), + edit_uint64_with_commas(dcr->dev->max_spool_size, ec3), + edit_uint64_with_commas(dcr->dev->spool_size, ec4)); #endif Jmsg(dcr->jcr, M_INFO, 0, _("User specified spool size reached.\n")); if (!despool_data(dcr, false)) { Pmsg0(000, "Bad return from despool in write_block.\n"); - return false; + return false; } /* Despooling cleared these variables so reset them */ P(dcr->dev->spool_mutex); - dcr->spool_size += hlen + wlen; + dcr->job_spool_size += hlen + wlen; dcr->dev->spool_size += hlen + wlen; V(dcr->dev->spool_mutex); Jmsg(dcr->jcr, M_INFO, 0, _("Spooling data again ...\n")); @@ -414,25 +414,25 @@ static bool write_spool_header(DCR *dcr) for (int retry=0; retry<=1; retry++) { stat = write(dcr->spool_fd, (char*)&hdr, sizeof(hdr)); if (stat == -1) { - berrno be; + berrno be; Jmsg(dcr->jcr, M_FATAL, 0, _("Error writing header to spool file. ERR=%s\n"), - be.strerror()); + be.strerror()); } if (stat != (ssize_t)sizeof(hdr)) { - /* If we wrote something, truncate it, then despool */ - if (stat != -1) { - if (ftruncate(dcr->spool_fd, lseek(dcr->spool_fd, (off_t)0, SEEK_CUR) - stat) != 0) { - berrno be; + /* If we wrote something, truncate it, then despool */ + if (stat != -1) { + if (ftruncate(dcr->spool_fd, lseek(dcr->spool_fd, (off_t)0, SEEK_CUR) - stat) != 0) { + berrno be; Jmsg(dcr->jcr, M_FATAL, 0, _("Ftruncate spool file failed: ERR=%s\n"), - be.strerror()); - return false; - } - } - if (!despool_data(dcr, false)) { + be.strerror()); + return false; + } + } + if (!despool_data(dcr, false)) { Jmsg(dcr->jcr, M_FATAL, 0, _("Fatal despooling error.")); - return false; - } - continue; /* try again */ + return false; + } + continue; /* try again */ } return true; } @@ -449,31 +449,31 @@ static bool write_spool_data(DCR *dcr) for (int retry=0; retry<=1; retry++) { stat = write(dcr->spool_fd, block->buf, (size_t)block->binbuf); if (stat == -1) { - berrno be; + berrno be; Jmsg(dcr->jcr, M_FATAL, 0, _("Error writing data to spool file. ERR=%s\n"), - be.strerror()); + be.strerror()); } if (stat != (ssize_t)block->binbuf) { - /* - * If we wrote something, truncate it and the header, then despool - */ - if (stat != -1) { - if (ftruncate(dcr->spool_fd, lseek(dcr->spool_fd, (off_t)0, SEEK_CUR) - - stat - sizeof(spool_hdr)) != 0) { - berrno be; + /* + * If we wrote something, truncate it and the header, then despool + */ + if (stat != -1) { + if (ftruncate(dcr->spool_fd, lseek(dcr->spool_fd, (off_t)0, SEEK_CUR) + - stat - sizeof(spool_hdr)) != 0) { + berrno be; Jmsg(dcr->jcr, M_FATAL, 0, _("Ftruncate spool file failed: ERR=%s\n"), - be.strerror()); - return false; - } - } - if (!despool_data(dcr, false)) { + be.strerror()); + return false; + } + } + if (!despool_data(dcr, false)) { Jmsg(dcr->jcr, M_FATAL, 0, _("Fatal despooling error.")); - return false; - } - if (!write_spool_header(dcr)) { - return false; - } - continue; /* try again */ + return false; + } + if (!write_spool_header(dcr)) { + return false; + } + continue; /* try again */ } return true; } @@ -516,9 +516,9 @@ static void update_attr_spool_size(ssize_t size) P(mutex); if (size > 0) { if ((spool_stats.attr_size - size) > 0) { - spool_stats.attr_size -= size; + spool_stats.attr_size -= size; } else { - spool_stats.attr_size = 0; + spool_stats.attr_size = 0; } } V(mutex); @@ -531,26 +531,26 @@ bool commit_attribute_spool(JCR *jcr) if (are_attributes_spooled(jcr)) { if (fseeko(jcr->dir_bsock->spool_fd, 0, SEEK_END) != 0) { - berrno be; + berrno be; Jmsg(jcr, M_FATAL, 0, _("Fseek on attributes file failed: ERR=%s\n"), - be.strerror()); - goto bail_out; + be.strerror()); + goto bail_out; } size = ftello(jcr->dir_bsock->spool_fd); if (size < 0) { - berrno be; + berrno be; Jmsg(jcr, M_FATAL, 0, _("Fseek on attributes file failed: ERR=%s\n"), - be.strerror()); - goto bail_out; + be.strerror()); + 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.max_attr_size = spool_stats.attr_size + size; } spool_stats.attr_size += size; V(mutex); Jmsg(jcr, M_INFO, 0, _("Sending spooled attrs to the Director. Despooling %s bytes ...\n"), - edit_uint64_with_commas(size, ec1)); + edit_uint64_with_commas(size, ec1)); bnet_despool_to_bsock(jcr->dir_bsock, update_attr_spool_size, size); return close_attr_spool_file(jcr, jcr->dir_bsock); } @@ -577,7 +577,7 @@ bool open_attr_spool_file(JCR *jcr, BSOCK *bs) if (!bs->spool_fd) { berrno be; Jmsg(jcr, M_FATAL, 0, _("fopen attr spool file %s failed: ERR=%s\n"), name, - be.strerror()); + be.strerror()); free_pool_memory(name); return false; } diff --git a/bacula/src/stored/stored_conf.c b/bacula/src/stored/stored_conf.c index aa5a829f9c..b3dea456bc 100644 --- a/bacula/src/stored/stored_conf.c +++ b/bacula/src/stored/stored_conf.c @@ -5,24 +5,18 @@ * * Version $Id$ */ - /* Copyright (C) 2000-2005 Kern Sibbald This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. + modify it under the terms of the GNU General Public License + version 2 as ammended with additional clauses defined in the + file LICENSE in the main source directory. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + the file LICENSE for additional details. */ @@ -353,22 +347,22 @@ void free_resource(RES *sres, int type) free_tls_context(res->res_dir.tls_ctx); } if (res->res_dir.tls_ca_certfile) { - free(res->res_dir.tls_ca_certfile); + free(res->res_dir.tls_ca_certfile); } if (res->res_dir.tls_ca_certdir) { - free(res->res_dir.tls_ca_certdir); + free(res->res_dir.tls_ca_certdir); } if (res->res_dir.tls_certfile) { - free(res->res_dir.tls_certfile); + free(res->res_dir.tls_certfile); } if (res->res_dir.tls_keyfile) { - free(res->res_dir.tls_keyfile); + free(res->res_dir.tls_keyfile); } if (res->res_dir.tls_dhfile) { - free(res->res_dir.tls_dhfile); + free(res->res_dir.tls_dhfile); } if (res->res_dir.tls_allowed_cns) { - delete res->res_dir.tls_allowed_cns; + delete res->res_dir.tls_allowed_cns; } #endif /* HAVE_TLS */ break; @@ -407,22 +401,22 @@ void free_resource(RES *sres, int type) free_tls_context(res->res_store.tls_ctx); } if (res->res_store.tls_ca_certfile) { - free(res->res_store.tls_ca_certfile); + free(res->res_store.tls_ca_certfile); } if (res->res_store.tls_ca_certdir) { - free(res->res_store.tls_ca_certdir); + free(res->res_store.tls_ca_certdir); } if (res->res_store.tls_certfile) { - free(res->res_store.tls_certfile); + free(res->res_store.tls_certfile); } if (res->res_store.tls_keyfile) { - free(res->res_store.tls_keyfile); + free(res->res_store.tls_keyfile); } if (res->res_store.tls_dhfile) { - free(res->res_store.tls_dhfile); + free(res->res_store.tls_dhfile); } if (res->res_store.tls_allowed_cns) { - delete res->res_store.tls_allowed_cns; + delete res->res_store.tls_allowed_cns; } #endif /* HAVE_TLS */ break; @@ -531,7 +525,7 @@ void save_resource(int type, RES_ITEM *items, int pass) Emsg1(M_ERROR_TERM, 0, "Cannot find Director resource \"%s\"\n", res_all.res_dir.hdr.name); } #ifdef HAVE_TLS - res->res_dir.tls_allowed_cns = res_all.res_dir.tls_allowed_cns; + res->res_dir.tls_allowed_cns = res_all.res_dir.tls_allowed_cns; #endif break; case R_STORAGE: @@ -540,7 +534,7 @@ void save_resource(int type, RES_ITEM *items, int pass) } res->res_store.messages = res_all.res_store.messages; #ifdef HAVE_TLS - res->res_store.tls_allowed_cns = res_all.res_store.tls_allowed_cns; + res->res_store.tls_allowed_cns = res_all.res_store.tls_allowed_cns; #endif break; case R_AUTOCHANGER: -- 2.39.5