2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1999 University of Maryland at College Park
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of U.M. not be used in advertising or
11 * publicity pertaining to distribution of the software without specific,
12 * written prior permission. U.M. makes no representations about the
13 * suitability of this software for any purpose. It is provided "as is"
14 * without express or implied warranty.
16 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Authors: the Amanda Development Team. Its members are listed in a
24 * file named AUTHORS, in the root directory of this distribution.
27 * $Id: planner.c 10421 2008-03-06 18:48:30Z martineau $
29 * backup schedule planner for the Amanda backup system.
44 #include "amfeatures.h"
45 #include "server_util.h"
47 #include "timestamp.h"
50 #define planner_debug(i,x) do { \
51 if ((i) <= debug_planner) { \
56 #define MAX_LEVELS 3 /* max# of estimates per filesys */
58 #define RUNS_REDZONE 5 /* should be in conf file? */
60 #define PROMOTE_THRESHOLD 0.05 /* if <5% unbalanced, don't promote */
61 #define DEFAULT_DUMPRATE 1024.0 /* K/s */
63 /* configuration file stuff */
66 gint64 conf_maxdumpsize;
69 int conf_runspercycle;
74 int conf_usetimestamps;
76 #define HOST_READY ((void *)0) /* must be 0 */
77 #define HOST_ACTIVE ((void *)1)
78 #define HOST_DONE ((void *)2)
80 #define DISK_READY 0 /* must be 0 */
82 #define DISK_PARTIALY_DONE 2
85 typedef struct one_est_s {
87 gint64 nsize; /* native size */
88 gint64 csize; /* compressed size */
90 int guessed; /* If server guessed the estimate size */
92 static one_est_t default_one_est = {-1, -1, -1, "INVALID_DATE", 0};
94 typedef struct est_s {
100 one_est_t estimate[MAX_LEVELS];
102 gint64 last_lev0size;
107 double fullrate, incrrate;
108 double fullcomp, incrcomp;
113 #define est(dp) ((est_t *)(dp)->up)
115 /* pestq = partial estimate */
116 disklist_t startq, waitq, pestq, estq, failq, schedq;
118 double total_lev0, balanced_size, balance_threshold;
124 size_t tt_blocksize_kb;
125 int runs_per_cycle = 0;
127 char *planner_timestamp = NULL;
129 static am_feature_t *our_features = NULL;
130 static char *our_feature_string = NULL;
132 /* We keep a LIFO queue of before images for all modifications made
133 * to schedq in our attempt to make the schedule fit on the tape.
134 * Enough information is stored to reinstate a dump if it turns out
135 * that it shouldn't have been touched after all.
137 typedef struct bi_s {
140 int deleted; /* 0=modified, 1=deleted */
141 disk_t *dp; /* The disk that was changed */
142 int level; /* The original level */
143 gint64 nsize; /* The original native size */
144 gint64 csize; /* The original compressed size */
145 char *errstr; /* A message describing why this disk is here */
148 typedef struct bilist_s {
152 bilist_t biq; /* The BI queue itself */
155 * ========================================================================
160 static void setup_estimate(disk_t *dp);
161 static void get_estimates(void);
162 static void analyze_estimate(disk_t *dp);
163 static void handle_failed(disk_t *dp);
164 static void delay_dumps(void);
165 static int promote_highest_priority_incremental(void);
166 static int promote_hills(void);
167 static void output_scheduleline(disk_t *dp);
168 static void server_estimate(disk_t *dp, int i, info_t *info, int level);
169 int main(int, char **);
185 times_t section_start;
189 config_overrides_t *cfg_ovr = NULL;
190 char *cfg_opt = NULL;
192 int exit_status = EXIT_SUCCESS;
193 gboolean no_taper = FALSE;
196 * Configure program for internationalization:
197 * 1) Only set the message locale for now.
198 * 2) Set textdomain for all amanda related programs to "amanda"
199 * We don't want to be forced to support dozens of message catalogs.
201 setlocale(LC_MESSAGES, "C");
202 textdomain("amanda");
204 /* drop root privileges */
205 planner_setuid = set_root_privs(0);
209 set_pname("planner");
211 dbopen(DBG_SUBDIR_SERVER);
213 cfg_ovr = extract_commandline_config_overrides(&argc, &argv);
217 set_config_overrides(cfg_ovr);
218 config_init(CONFIG_INIT_EXPLICIT_NAME | CONFIG_INIT_USE_CWD, cfg_opt);
220 /* conf_diskfile is freed later, as it may be used in an error message */
221 conf_diskfile = config_dir_relative(getconf_str(CNF_DISKFILE));
222 read_diskfile(conf_diskfile, &origq);
223 disable_skip_disk(&origq);
225 /* Don't die when child closes pipe */
226 signal(SIGPIPE, SIG_IGN);
228 setvbuf(stderr, (char *)NULL, (int)_IOLBF, 0);
230 add_amanda_log_handler(amanda_log_stderr);
231 add_amanda_log_handler(amanda_log_trace_log);
233 if (!planner_setuid) {
234 error(_("planner must be run setuid root"));
237 if (config_errors(NULL) >= CFGERR_ERRORS) {
238 g_critical(_("errors processing config file"));
243 check_running_as(RUNNING_AS_ROOT | RUNNING_AS_UID_ONLY);
245 dbrename(get_config_name(), DBG_SUBDIR_SERVER);
248 section_start = curclock();
250 our_features = am_init_feature_set();
251 our_feature_string = am_feature_to_string(our_features);
253 log_add(L_INFO, "%s pid %ld", get_pname(), (long)getpid());
254 g_fprintf(stderr, _("%s: pid %ld executable %s version %s\n"),
255 get_pname(), (long) getpid(), argv[0], VERSION);
256 for (i = 0; version_info[i] != NULL; i++)
257 g_fprintf(stderr, _("%s: %s"), get_pname(), version_info[i]);
260 if (argc - diskarg_offset > 1 && strcmp(argv[diskarg_offset], "--starttime") == 0) {
261 planner_timestamp = stralloc(argv[diskarg_offset+1]);
264 if (argc - diskarg_offset > 0 && strcmp(argv[diskarg_offset], "--no-taper") == 0) {
271 * 1. Networking Setup
278 * 2. Read in Configuration Information
280 * All the Amanda configuration files are loaded before we begin.
283 g_fprintf(stderr,_("READING CONF INFO...\n"));
285 if(origq.head == NULL) {
286 error(_("empty disklist \"%s\""), conf_diskfile);
290 amfree(conf_diskfile);
292 conf_tapelist = config_dir_relative(getconf_str(CNF_TAPELIST));
293 if(read_tapelist(conf_tapelist)) {
294 error(_("could not load tapelist \"%s\""), conf_tapelist);
297 amfree(conf_tapelist);
299 conf_infofile = config_dir_relative(getconf_str(CNF_INFOFILE));
300 if(open_infofile(conf_infofile)) {
301 error(_("could not open info db \"%s\""), conf_infofile);
304 if (check_infofile(conf_infofile, &origq, &errstr) == -1) {
305 log_add(L_WARNING, "problem copying infofile: %s", errstr);
308 amfree(conf_infofile);
310 conf_tapetype = getconf_str(CNF_TAPETYPE);
311 conf_maxdumpsize = getconf_int64(CNF_MAXDUMPSIZE);
312 conf_runtapes = getconf_int(CNF_RUNTAPES);
313 conf_dumpcycle = getconf_int(CNF_DUMPCYCLE);
314 conf_runspercycle = getconf_int(CNF_RUNSPERCYCLE);
315 conf_tapecycle = getconf_int(CNF_TAPECYCLE);
316 conf_etimeout = (time_t)getconf_int(CNF_ETIMEOUT);
317 conf_reserve = getconf_int(CNF_RESERVE);
318 conf_autoflush = getconf_boolean(CNF_AUTOFLUSH);
319 conf_usetimestamps = getconf_boolean(CNF_USETIMESTAMPS);
322 if (planner_timestamp) {
323 if (conf_usetimestamps == 0) {
324 planner_timestamp[8] = '\0';
326 } else if(conf_usetimestamps == 0) {
327 planner_timestamp = get_datestamp_from_time(0);
330 planner_timestamp = get_timestamp_from_time(0);
332 log_add(L_START, _("date %s"), planner_timestamp);
333 g_printf("DATE %s\n", planner_timestamp);
335 g_fprintf(stderr, _("%s: timestamp %s\n"),
336 get_pname(), planner_timestamp);
338 errstr = match_disklist(&origq, argc-diskarg_offset,
339 argv+diskarg_offset);
341 g_fprintf(stderr,"%s",errstr);
342 exit_status = EXIT_FAILURE;
345 for (dp = origq.head; dp != NULL; dp = dp->next) {
347 qname = quote_string(dp->name);
348 log_add(L_DISK, "%s %s", dp->host->hostname, qname);
356 error(_("no DLE to backup; %s"), errstr);
358 error(_("no DLE to backup"));
362 log_add(L_WARNING, "WARNING: %s", errstr);
366 /* some initializations */
368 if(conf_runspercycle == 0) {
369 runs_per_cycle = conf_dumpcycle;
370 } else if(conf_runspercycle == -1 ) {
371 runs_per_cycle = guess_runs_from_tapelist();
373 runs_per_cycle = conf_runspercycle;
375 if (runs_per_cycle <= 0) {
380 * do some basic sanity checking
382 if(conf_tapecycle <= runs_per_cycle) {
383 log_add(L_WARNING, _("tapecycle (%d) <= runspercycle (%d)"),
384 conf_tapecycle, runs_per_cycle);
387 tape = lookup_tapetype(conf_tapetype);
388 if(conf_maxdumpsize > (gint64)0) {
389 tape_length = conf_maxdumpsize;
390 g_fprintf(stderr, "planner: tape_length is set from maxdumpsize (%jd KB)\n",
391 (intmax_t)conf_maxdumpsize);
394 tape_length = tapetype_get_length(tape) * (gint64)conf_runtapes;
395 g_fprintf(stderr, "planner: tape_length is set from tape length (%jd KB) * runtapes (%d) == %jd KB\n",
396 (intmax_t)tapetype_get_length(tape),
398 (intmax_t)tape_length);
400 tape_mark = (size_t)tapetype_get_filemark(tape);
401 tt_blocksize_kb = (size_t)tapetype_get_blocksize(tape);
402 tt_blocksize = tt_blocksize_kb * 1024;
404 g_fprintf(stderr, _("%s: time %s: startup took %s secs\n"),
406 walltime_str(curclock()),
407 walltime_str(timessub(curclock(), section_start)));
410 * 3. Send autoflush dumps left on the holding disks
412 * This should give us something to do while we generate the new
416 g_fprintf(stderr,_("\nSENDING FLUSHES...\n"));
418 if(conf_autoflush && !no_taper) {
420 GSList *holding_list, *holding_file;
421 char *qdisk, *qhname;
423 /* get *all* flushable files in holding, without checking against
424 * the disklist (which may not contain some of the dumps) */
425 holding_list = holding_get_files_for_flush(NULL);
426 for(holding_file=holding_list; holding_file != NULL;
427 holding_file = holding_file->next) {
428 holding_file_get_dumpfile((char *)holding_file->data, &file);
430 if (holding_file_size((char *)holding_file->data, 1) <= 0) {
431 log_add(L_INFO, "%s: removing file with no data.",
432 (char *)holding_file->data);
433 holding_file_unlink((char *)holding_file->data);
434 dumpfile_free_data(&file);
438 /* see if this matches the command-line arguments */
439 if (!match_dumpfile(&file, argc-diskarg_offset,
440 argv+diskarg_offset)) {
444 qdisk = quote_string(file.disk);
445 qhname = quote_string((char *)holding_file->data);
446 log_add(L_DISK, "%s %s", file.name, qdisk);
448 "FLUSH %s %s %s %d %s\n",
455 "FLUSH %s %s %s %d %s\n",
463 dumpfile_free_data(&file);
465 g_slist_free_full(holding_list);
468 g_fprintf(stderr, _("ENDFLUSH\n"));
469 g_fprintf(stdout, _("ENDFLUSH\n"));
473 * 4. Calculate Preliminary Dump Levels
475 * Before we can get estimates from the remote slave hosts, we make a
476 * first attempt at guessing what dump levels we will be dumping at
477 * based on the curinfo database.
480 g_fprintf(stderr,_("\nSETTING UP FOR ESTIMATES...\n"));
481 section_start = curclock();
483 startq.head = startq.tail = NULL;
484 while(!empty(origq)) {
485 disk_t *dp = dequeue_disk(&origq);
491 g_fprintf(stderr, _("%s: time %s: setting up estimates took %s secs\n"),
493 walltime_str(curclock()),
494 walltime_str(timessub(curclock(), section_start)));
498 * 5. Get Dump Size Estimates from Remote Client Hosts
500 * Each host is queried (in parallel) for dump size information on all
501 * of its disks, and the results gathered as they come in.
504 /* go out and get the dump estimates */
506 g_fprintf(stderr,_("\nGETTING ESTIMATES...\n"));
507 section_start = curclock();
509 estq.head = estq.tail = NULL;
510 pestq.head = pestq.tail = NULL;
511 waitq.head = waitq.tail = NULL;
512 failq.head = failq.tail = NULL;
516 g_fprintf(stderr, _("%s: time %s: getting estimates took %s secs\n"),
518 walltime_str(curclock()),
519 walltime_str(timessub(curclock(), section_start)));
522 * At this point, all disks with estimates are in estq, and
523 * all the disks on hosts that didn't respond to our inquiry
527 dump_queue("FAILED", failq, 15, stderr);
528 dump_queue("DONE", estq, 15, stderr);
531 exit_status = EXIT_FAILURE;
535 * 6. Analyze Dump Estimates
537 * Each disk's estimates are looked at to determine what level it
538 * should dump at, and to calculate the expected size and time taking
539 * historical dump rates and compression ratios into account. The
540 * total expected size is accumulated as well.
543 g_fprintf(stderr,_("\nANALYZING ESTIMATES...\n"));
544 section_start = curclock();
546 /* an empty tape still has a label and an endmark */
547 total_size = ((gint64)tt_blocksize_kb + (gint64)tape_mark) * (gint64)2;
551 schedq.head = schedq.tail = NULL;
552 while(!empty(estq)) analyze_estimate(dequeue_disk(&estq));
553 while(!empty(failq)) handle_failed(dequeue_disk(&failq));
556 * At this point, all the disks are on schedq sorted by priority.
557 * The total estimated size of the backups is in total_size.
563 g_fprintf(stderr, _("INITIAL SCHEDULE (size %lld):\n"),
564 (long long)total_size);
565 for(dp = schedq.head; dp != NULL; dp = dp->next) {
566 qname = quote_string(dp->name);
567 g_fprintf(stderr, _(" %s %s pri %d lev %d nsize %lld csize %lld\n"),
568 dp->host->hostname, qname, est(dp)->dump_priority,
569 est(dp)->dump_est->level,
570 (long long)est(dp)->dump_est->nsize,
571 (long long)est(dp)->dump_est->csize);
578 * 7. Delay Dumps if Schedule Too Big
580 * If the generated schedule is too big to fit on the tape, we need to
581 * delay some full dumps to make room. Incrementals will be done
582 * instead (except for new or forced disks).
584 * In extreme cases, delaying all the full dumps is not even enough.
585 * If so, some low-priority incrementals will be skipped completely
586 * until the dumps fit on the tape.
589 g_fprintf(stderr, _("\nDELAYING DUMPS IF NEEDED, total_size %lld, tape length %lld mark %zu\n"),
590 (long long)total_size,
591 (long long)tape_length,
594 initial_size = total_size;
598 /* XXX - why bother checking this? */
599 if(empty(schedq) && total_size < initial_size) {
600 error(_("cannot fit anything on tape, bailing out"));
606 * 8. Promote Dumps if Schedule Too Small
608 * Amanda attempts to balance the full dumps over the length of the
609 * dump cycle. If this night's full dumps are too small relative to
610 * the other nights, promote some high-priority full dumps that will be
611 * due for the next run, to full dumps for tonight, taking care not to
612 * overflow the tape size.
614 * This doesn't work too well for small sites. For these we scan ahead
615 * looking for nights that have an excessive number of dumps and promote
618 * Amanda never delays full dumps just for the sake of balancing the
619 * schedule, so it can take a full cycle to balance the schedule after
624 _("\nPROMOTING DUMPS IF NEEDED, total_lev0 %1.0lf, balanced_size %1.0lf...\n"),
625 total_lev0, balanced_size);
627 balance_threshold = balanced_size * PROMOTE_THRESHOLD;
629 while((balanced_size - total_lev0) > balance_threshold && moved_one)
630 moved_one = promote_highest_priority_incremental();
632 moved_one = promote_hills();
634 g_fprintf(stderr, _("%s: time %s: analysis took %s secs\n"),
636 walltime_str(curclock()),
637 walltime_str(timessub(curclock(), section_start)));
643 * The schedule goes to stdout, presumably to driver. A copy is written
644 * on stderr for the debug file.
647 g_fprintf(stderr,_("\nGENERATING SCHEDULE:\n--------\n"));
649 exit_status = EXIT_FAILURE;
650 g_fprintf(stderr, _("--> Generated empty schedule! <--\n"));
652 while(!empty(schedq)) output_scheduleline(dequeue_disk(&schedq));
654 g_fprintf(stderr, _("--------\n"));
657 log_add(L_FINISH, _("date %s time %s"), planner_timestamp, walltime_str(curclock()));
658 log_add(L_INFO, "pid-done %ld", (long)getpid());
661 amfree(planner_timestamp);
662 amfree(our_feature_string);
663 am_release_feature_set(our_features);
674 * ========================================================================
675 * SETUP FOR ESTIMATES
679 static void askfor(est_t *, int, int, info_t *);
680 static int last_level(info_t *info); /* subroutines */
681 static one_est_t *est_for_level(disk_t *dp, int level);
682 static void est_csize(disk_t *dp, one_est_t *one_est);
683 static gint64 est_tape_size(disk_t *dp, int level);
684 static int next_level0(disk_t *dp, info_t *info);
685 static int runs_at(info_t *info, int lev);
686 static gint64 bump_thresh(int level, gint64 size_level_0, int bumppercent, gint64 bumpsize, double bumpmult);
687 static int when_overwrite(char *label);
690 est_t *ep, /* esimate data block */
691 int seq, /* sequence number of request */
692 int lev, /* dump level being requested */
693 info_t *info) /* info block for disk */
695 if(seq < 0 || seq >= MAX_LEVELS) {
696 error(_("error [planner askfor: seq out of range 0..%d: %d]"),
700 if(lev < -1 || lev >= DUMP_LEVELS) {
701 error(_("error [planner askfor: lev out of range -1..%d: %d]"),
707 ep->estimate[seq].level = -1;
708 ep->estimate[seq].dumpdate = (char *)0;
709 ep->estimate[seq].nsize = (gint64)-3;
710 ep->estimate[seq].csize = (gint64)-3;
711 ep->estimate[seq].guessed = 0;
715 ep->estimate[seq].level = lev;
717 ep->estimate[seq].dumpdate = stralloc(get_dumpdate(info,lev));
719 ep->estimate[seq].nsize = (gint64)-3;
720 ep->estimate[seq].csize = (gint64)-3;
721 ep->estimate[seq].guessed = 0;
736 assert(dp && dp->host);
738 qname = quote_string(dp->name);
739 g_fprintf(stderr, _("%s: time %s: setting up estimates for %s:%s\n"),
740 get_pname(), walltime_str(curclock()),
741 dp->host->hostname, qname);
743 /* get current information about disk */
745 if(get_info(dp->host->hostname, dp->name, &info)) {
746 /* no record for this disk, make a note of it */
747 log_add(L_INFO, _("Adding new disk %s:%s."), dp->host->hostname, qname);
750 if (dp->data_path == DATA_PATH_DIRECTTCP) {
751 if (dp->compress != COMP_NONE) {
752 log_add(L_FAIL, _("%s %s %s 0 [Can't compress directtcp data-path]"),
753 dp->host->hostname, qname, planner_timestamp);
754 g_fprintf(stderr,_("%s:%s lev 0 skipped can't compress directtcp data-path\n"),
755 dp->host->hostname, qname);
759 if (dp->encrypt != ENCRYPT_NONE) {
760 log_add(L_FAIL, _("%s %s %s 0 [Can't encrypt directtcp data-path]"),
761 dp->host->hostname, qname, planner_timestamp);
762 g_fprintf(stderr,_("%s:%s lev 0 skipped can't encrypt directtcp data-path\n"),
763 dp->host->hostname, qname);
767 if (dp->to_holdingdisk == HOLD_REQUIRED) {
768 log_add(L_FAIL, _("%s %s %s 0 [Holding disk can't be use for directtcp data-path]"),
769 dp->host->hostname, qname, planner_timestamp);
770 g_fprintf(stderr,_("%s:%s lev 0 skipped Holding disk can't be use for directtcp data-path\n"),
771 dp->host->hostname, qname);
774 } else if (dp->to_holdingdisk == HOLD_AUTO) {
775 g_fprintf(stderr,_("%s:%s Disabling holding disk\n"),
776 dp->host->hostname, qname);
777 dp->to_holdingdisk = HOLD_NEVER;
781 /* setup working data struct for disk */
783 ep = alloc(SIZEOF(est_t));
784 dp->up = (void *) ep;
785 ep->state = DISK_READY;
786 ep->dump_priority = dp->priority;
790 ep->degr_mesg = NULL;
791 ep->dump_est = &default_one_est;
792 ep->degr_est = &default_one_est;
794 /* calculated fields */
796 if (ISSET(info.command, FORCE_FULL)) {
797 /* force a level 0, kind of like a new disk */
798 if(dp->strategy == DS_NOFULL) {
800 * XXX - Not sure what it means to force a no-full disk. The
801 * purpose of no-full is to just dump changes relative to a
802 * stable base, for example root partitions that vary only
803 * slightly from a site-wide prototype. Only the variations
806 * If we allow a level 0 onto the Amanda cycle, then we are
807 * hosed when that tape gets re-used next. Disallow this for
811 _("Cannot force full dump of %s:%s with no-full option."),
812 dp->host->hostname, qname);
814 /* clear force command */
815 CLR(info.command, FORCE_FULL);
816 ep->last_level = last_level(&info);
817 ep->next_level0 = next_level0(dp, &info);
818 } else if (dp->strategy == DS_INCRONLY) {
820 _("Cannot force full dump of %s:%s with incronly option."),
821 dp->host->hostname, qname);
823 /* clear force command */
824 CLR(info.command, FORCE_FULL);
825 ep->last_level = last_level(&info);
826 ep->next_level0 = next_level0(dp, &info);
828 ep->degr_mesg = _("Skipping: force-full disk can't be dumped in degraded mode");
830 ep->next_level0 = -conf_dumpcycle;
831 log_add(L_INFO, _("Forcing full dump of %s:%s as directed."),
832 dp->host->hostname, qname);
835 else if(dp->strategy == DS_NOFULL) {
836 /* force estimate of level 1 */
838 ep->next_level0 = next_level0(dp, &info);
841 ep->last_level = last_level(&info);
842 ep->next_level0 = next_level0(dp, &info);
845 /* adjust priority levels */
847 /* warn if dump will be overwritten */
848 if (ep->last_level > -1 && strlen(info.inf[0].label) > 0) {
849 overwrite_runs = when_overwrite(info.inf[0].label);
850 if(overwrite_runs == 0) {
851 log_add(L_WARNING, _("Last full dump of %s:%s "
852 "on tape %s overwritten on this run."),
853 dp->host->hostname, qname, info.inf[0].label);
854 } else if(overwrite_runs <= RUNS_REDZONE) {
856 plural(_("Last full dump of %s:%s on tape %s overwritten in %d run."),
857 _("Last full dump of %s:%s on tape %s overwritten in %d runs."), overwrite_runs),
858 dp->host->hostname, qname, info.inf[0].label,
863 /* warn if last level 1 will be overwritten */
864 if (ep->last_level > 1 && strlen(info.inf[1].label) > 0) {
865 overwrite_runs = when_overwrite(info.inf[1].label);
866 if(overwrite_runs == 0) {
867 log_add(L_WARNING, _("Last level 1 dump of %s:%s "
868 "on tape %s overwritten on this run, resetting to level 1"),
869 dp->host->hostname, qname, info.inf[1].label);
871 } else if(overwrite_runs <= RUNS_REDZONE) {
873 plural(_("Last level 1 dump of %s:%s on tape %s overwritten in %d run."),
874 _("Last level 1 dump of %s:%s on tape %s overwritten in %d runs."), overwrite_runs),
875 dp->host->hostname, qname, info.inf[1].label,
880 if(ep->next_level0 < 0) {
881 g_fprintf(stderr,plural(_("%s:%s overdue %d day for level 0\n"),
882 _("%s:%s overdue %d days for level 0\n"),
884 dp->host->hostname, qname, (-ep->next_level0));
885 ep->dump_priority -= ep->next_level0;
887 else if (ISSET(info.command, FORCE_FULL))
888 ep->dump_priority += 1;
889 /* else XXX bump up the priority of incrementals that failed last night */
891 /* handle external level 0 dumps */
893 if(dp->skip_full && dp->strategy != DS_NOINC) {
894 if(ep->next_level0 <= 0) {
895 /* update the date field */
896 info.inf[0].date = today;
897 CLR(info.command, FORCE_FULL);
898 ep->next_level0 += conf_dumpcycle;
900 if(put_info(dp->host->hostname, dp->name, &info)) {
901 error(_("could not put info record for %s:%s: %s"),
902 dp->host->hostname, qname, strerror(errno));
905 log_add(L_INFO, _("Skipping full dump of %s:%s today."),
906 dp->host->hostname, qname);
907 g_fprintf(stderr,_("%s:%s lev 0 skipped due to skip-full flag\n"),
908 dp->host->hostname, qname);
909 /* don't enqueue the disk */
910 askfor(ep, 0, -1, &info);
911 askfor(ep, 1, -1, &info);
912 askfor(ep, 2, -1, &info);
913 g_fprintf(stderr, _("%s: SKIPPED %s %s 0 [skip-full]\n"),
914 get_pname(), dp->host->hostname, qname);
915 log_add(L_SUCCESS, _("%s %s %s 0 [skipped: skip-full]"),
916 dp->host->hostname, qname, planner_timestamp);
921 if(ep->last_level == -1) {
922 /* probably a new disk, but skip-full means no full! */
926 if(ep->next_level0 == 1) {
927 log_add(L_WARNING, _("Skipping full dump of %s:%s tomorrow."),
928 dp->host->hostname, qname);
932 if(dp->strategy == DS_INCRONLY && ep->last_level == -1 && !ISSET(info.command, FORCE_FULL)) {
933 /* don't enqueue the disk */
934 askfor(ep, 0, -1, &info);
935 askfor(ep, 1, -1, &info);
936 askfor(ep, 2, -1, &info);
937 log_add(L_FAIL, _("%s %s 19000101 1 [Skipping incronly because no full dump were done]"),
938 dp->host->hostname, qname);
939 g_fprintf(stderr,_("%s:%s lev 1 skipped due to strategy incronly and no full dump were done\n"),
940 dp->host->hostname, qname);
945 /* handle "skip-incr" type archives */
947 if(dp->skip_incr && ep->next_level0 > 0) {
948 g_fprintf(stderr,_("%s:%s lev 1 skipped due to skip-incr flag\n"),
949 dp->host->hostname, qname);
950 /* don't enqueue the disk */
951 askfor(ep, 0, -1, &info);
952 askfor(ep, 1, -1, &info);
953 askfor(ep, 2, -1, &info);
955 g_fprintf(stderr, _("%s: SKIPPED %s %s 1 [skip-incr]\n"),
956 get_pname(), dp->host->hostname, qname);
958 log_add(L_SUCCESS, _("%s %s %s 1 [skipped: skip-incr]"),
959 dp->host->hostname, qname, planner_timestamp);
964 if( ep->last_level == -1 && ep->next_level0 > 0 &&
965 dp->strategy != DS_NOFULL && dp->strategy != DS_INCRONLY &&
966 conf_reserve == 100) {
967 log_add(L_WARNING, _("%s:%s mismatch: no tapelist record, "
968 "but curinfo next_level0: %d."),
969 dp->host->hostname, qname, ep->next_level0);
973 if(ep->last_level == 0) ep->level_days = 0;
974 else ep->level_days = runs_at(&info, ep->last_level);
975 ep->last_lev0size = info.inf[0].csize;
977 ep->fullrate = perf_average(info.full.rate, 0.0);
978 ep->incrrate = perf_average(info.incr.rate, 0.0);
980 ep->fullcomp = perf_average(info.full.comp, dp->comprate[0]);
981 ep->incrcomp = perf_average(info.incr.comp, dp->comprate[1]);
983 /* determine which estimates to get */
987 if (dp->strategy == DS_NOINC ||
989 (!ISSET(info.command, FORCE_BUMP) ||
991 ep->last_level == -1))) {
992 if(ISSET(info.command, FORCE_BUMP) && ep->last_level == -1) {
994 _("Remove force-bump command of %s:%s because it's a new disk."),
995 dp->host->hostname, qname);
997 switch (dp->strategy) {
1000 askfor(ep, i++, 0, &info);
1002 log_add(L_INFO, _("Ignoring skip-full for %s:%s "
1003 "because the strategy is NOINC."),
1004 dp->host->hostname, qname);
1006 if(ISSET(info.command, FORCE_BUMP)) {
1008 _("Ignoring FORCE_BUMP for %s:%s because the strategy is NOINC."),
1009 dp->host->hostname, qname);
1018 if (ISSET(info.command, FORCE_FULL))
1024 if(!dp->skip_incr && !(dp->strategy == DS_NOINC)) {
1025 if(ep->last_level == -1) { /* a new disk */
1026 if (ep->degr_mesg == NULL)
1027 ep->degr_mesg = _("Skipping: new disk can't be dumped in degraded mode");
1028 if(dp->strategy == DS_NOFULL || dp->strategy == DS_INCRONLY) {
1029 askfor(ep, i++, 1, &info);
1031 assert(!dp->skip_full); /* should be handled above */
1033 } else { /* not new, pick normally */
1036 curr_level = ep->last_level;
1038 if (ISSET(info.command, FORCE_NO_BUMP)) {
1039 if(curr_level > 0) { /* level 0 already asked for */
1040 askfor(ep, i++, curr_level, &info);
1042 log_add(L_INFO,_("Preventing bump of %s:%s as directed."),
1043 dp->host->hostname, qname);
1044 ep->degr_mesg = _("Skipping: force-no-bump disk can't be dumped in degraded mode");
1045 } else if (ISSET(info.command, FORCE_BUMP)
1046 && curr_level + 1 < DUMP_LEVELS) {
1047 askfor(ep, i++, curr_level+1, &info);
1048 log_add(L_INFO,_("Bumping of %s:%s at level %d as directed."),
1049 dp->host->hostname, qname, curr_level+1);
1050 ep->degr_mesg = _("Skipping: force-bump disk can't be dumped in degraded mode");
1051 } else if (curr_level == 0) {
1052 askfor(ep, i++, 1, &info);
1054 askfor(ep, i++, curr_level, &info);
1056 * If last time we dumped less than the threshold, then this
1057 * time we will too, OR the extra size will be charged to both
1058 * cur_level and cur_level + 1, so we will never bump. Also,
1059 * if we haven't been at this level 2 days, or the dump failed
1060 * last night, we can't bump.
1062 if((info.inf[curr_level].size == (gint64)0 || /* no data, try it anyway */
1063 (((info.inf[curr_level].size > bump_thresh(curr_level, info.inf[0].size,dp->bumppercent, dp->bumpsize, dp->bumpmult)))
1064 && ep->level_days >= dp->bumpdays))
1065 && curr_level + 1 < DUMP_LEVELS) {
1066 askfor(ep, i++, curr_level+1, &info);
1072 while(i < MAX_LEVELS) /* mark end of estimates */
1073 askfor(ep, i++, -1, &info);
1077 g_fprintf(stderr, _("setup_estimate: %s:%s: command %u, options: %s "
1078 "last_level %d next_level0 %d level_days %d getting estimates "
1079 "%d (%lld) %d (%lld) %d (%lld)\n"),
1080 dp->host->hostname, qname, info.command,
1081 dp->strategy == DS_NOFULL ? "no-full" :
1082 dp->strategy == DS_INCRONLY ? "incr-only" :
1083 dp->skip_full ? "skip-full" :
1084 dp->skip_incr ? "skip-incr" : "none",
1085 ep->last_level, ep->next_level0, ep->level_days,
1086 ep->estimate[0].level, (long long)ep->estimate[0].nsize,
1087 ep->estimate[1].level, (long long)ep->estimate[1].nsize,
1088 ep->estimate[2].level, (long long)ep->estimate[2].nsize);
1090 assert(ep->estimate[0].level != -1);
1091 enqueue_disk(&startq, dp);
1095 static int when_overwrite(
1101 runtapes = conf_runtapes;
1102 if(runtapes == 0) runtapes = 1;
1104 if((tp = lookup_tapelabel(label)) == NULL)
1105 return 1; /* "shouldn't happen", but trigger warning message */
1106 else if(tp->reuse == 0)
1108 else if(lookup_nb_tape() > conf_tapecycle)
1109 return (lookup_nb_tape() - tp->position) / runtapes;
1111 return (conf_tapecycle - tp->position) / runtapes;
1114 /* Return the estimated size for a particular dump */
1122 if (level < 0 || level >= DUMP_LEVELS)
1123 return &default_one_est;
1125 for (i = 0; i < MAX_LEVELS; i++) {
1126 if (level == est(dp)->estimate[i].level) {
1127 if (est(dp)->estimate[i].csize <= -1) {
1128 est_csize(dp, &est(dp)->estimate[i]);
1130 return &est(dp)->estimate[i];
1133 return &default_one_est;
1136 /* Return the estimated on-tape size of a particular dump */
1142 gint64 size = one_est->nsize;
1145 if (dp->compress == COMP_NONE) {
1146 one_est->csize = one_est->nsize;
1150 if (one_est->level == 0) ratio = est(dp)->fullcomp;
1151 else ratio = est(dp)->incrcomp;
1154 * make sure over-inflated compression ratios don't throw off the
1155 * estimates, this is mostly for when you have a small dump getting
1156 * compressed which takes up alot more disk/tape space relatively due
1157 * to the overhead of the compression. This is specifically for
1158 * Digital Unix vdump. This patch is courtesy of Rudolf Gabler
1159 * (RUG@USM.Uni-Muenchen.DE)
1162 if (ratio > 1.1) ratio = 1.1;
1164 size = (gint64)((double)size * ratio);
1167 * Ratio can be very small in some error situations, so make sure
1168 * size goes back greater than zero. It may not be right, but
1169 * indicates we did get an estimate.
1171 if (size <= (gint64)0) {
1175 one_est->csize = size;
1178 static gint64 est_tape_size(
1182 one_est_t *dump_est;
1184 dump_est = est_for_level(dp, level);
1185 if (dump_est->level >= 0 && dump_est->csize <= -1)
1186 est_csize(dp, dump_est);
1187 return dump_est->csize;
1191 /* what was the level of the last successful dump to tape? */
1192 static int last_level(
1195 int min_pos, min_level, i;
1196 time_t lev0_date, last_date;
1199 if(info->last_level != -1)
1200 return info->last_level;
1202 /* to keep compatibility with old infofile */
1203 min_pos = 1000000000;
1207 for(i = 0; i < 9; i++) {
1208 if(conf_reserve < 100) {
1209 if(i == 0) lev0_date = info->inf[0].date;
1210 else if(info->inf[i].date < lev0_date) continue;
1211 if(info->inf[i].date > last_date) {
1212 last_date = info->inf[i].date;
1217 if((tp = lookup_tapelabel(info->inf[i].label)) == NULL) continue;
1218 /* cull any entries from previous cycles */
1219 if(i == 0) lev0_date = info->inf[0].date;
1220 else if(info->inf[i].date < lev0_date) continue;
1222 if(tp->position < min_pos) {
1223 min_pos = tp->position;
1228 info->last_level = i;
1232 /* when is next level 0 due? 0 = today, 1 = tomorrow, etc*/
1238 if(dp->strategy == DS_NOFULL || dp->strategy == DS_INCRONLY)
1239 return 1; /* fake it */
1240 else if (dp->strategy == DS_NOINC)
1242 else if(info->inf[0].date < (time_t)0)
1243 return -days_diff(EPOCH, today); /* new disk */
1245 return dp->dumpcycle - days_diff(info->inf[0].date, today);
1248 /* how many runs at current level? */
1253 tape_t *cur_tape, *old_tape;
1256 last = last_level(info);
1257 if(lev != last) return 0;
1258 if(lev == 0) return 1;
1260 if(info->consecutive_runs != -1)
1261 return info->consecutive_runs;
1263 /* to keep compatibility with old infofile */
1264 cur_tape = lookup_tapelabel(info->inf[lev].label);
1265 old_tape = lookup_tapelabel(info->inf[lev-1].label);
1266 if(cur_tape == NULL || old_tape == NULL) return 0;
1268 if(conf_runtapes == 0)
1269 nb_runs = (old_tape->position - cur_tape->position) / 1;
1271 nb_runs = (old_tape->position - cur_tape->position) / conf_runtapes;
1272 info->consecutive_runs = nb_runs;
1278 static gint64 bump_thresh(
1280 gint64 size_level_0,
1287 if ((bumppercent != 0) && (size_level_0 > (gint64)1024)) {
1288 bump = ((double)size_level_0 * (double)bumppercent) / 100.0;
1291 bump = (double)bumpsize;
1293 while(--level) bump = bump * bumpmult;
1295 return (gint64)bump;
1301 * ========================================================================
1302 * GET REMOTE DUMP SIZE ESTIMATES
1306 static void getsize(am_host_t *hostp);
1307 static disk_t *lookup_hostdisk(am_host_t *hp, char *str);
1308 static void handle_result(void *datap, pkt_t *pkt, security_handle_t *sech);
1311 static void get_estimates(void)
1315 int something_started;
1317 something_started = 1;
1318 while(something_started) {
1319 something_started = 0;
1320 for(dp = startq.head; dp != NULL; dp = dp->next) {
1322 if(hostp->up == HOST_READY) {
1323 something_started = 1;
1324 for(dp1 = hostp->disks; dp1 != NULL; dp1 = dp1->hostnext) {
1326 run_server_scripts(EXECUTE_ON_PRE_HOST_ESTIMATE,
1327 get_config_name(), dp1,
1328 est(dp1)->estimate[0].level);
1330 for(dp1 = hostp->disks; dp1 != NULL; dp1 = dp1->hostnext) {
1332 run_server_scripts(EXECUTE_ON_PRE_DLE_ESTIMATE,
1333 get_config_name(), dp1,
1334 est(dp1)->estimate[0].level);
1339 * dp is no longer on startq, so dp->next is not valid
1340 * and we have to start all over.
1348 while(!empty(waitq)) {
1349 disk_t *dp = dequeue_disk(&waitq);
1350 est(dp)->errstr = _("hmm, disk was stranded on waitq");
1351 enqueue_disk(&failq, dp);
1354 while(!empty(pestq)) {
1355 disk_t *dp = dequeue_disk(&pestq);
1356 char * qname = quote_string(dp->name);
1359 for (i=0; i < MAX_LEVELS; i++) {
1360 if (est(dp)->estimate[i].level != -1 &&
1361 est(dp)->estimate[i].nsize < (gint64)0) {
1362 if (est(dp)->estimate[i].nsize == (gint64)-3) {
1364 _("disk %s:%s, estimate of level %d timed out."),
1365 dp->host->hostname, qname, est(dp)->estimate[i].level);
1367 est(dp)->estimate[i].level = -1;
1371 if ((est(dp)->estimate[0].level != -1 &&
1372 est(dp)->estimate[0].nsize > (gint64)0) ||
1373 (est(dp)->estimate[1].level != -1 &&
1374 est(dp)->estimate[1].nsize > (gint64)0) ||
1375 (est(dp)->estimate[2].level != -1 &&
1376 est(dp)->estimate[2].nsize > (gint64)0)) {
1377 enqueue_disk(&estq, dp);
1380 est(dp)->errstr = vstralloc("disk ", qname,
1381 _(", all estimate timed out"), NULL);
1382 enqueue_disk(&failq, dp);
1388 static void getsize(
1391 char number[NUM_STR_SIZE], *req;
1394 time_t estimates, timeout;
1396 const security_driver_t *secdrv;
1398 char * qname, *b64disk = NULL;
1399 char * qdevice, *b64device = NULL;
1400 estimate_t estimate;
1403 assert(hostp->disks != NULL);
1405 if(hostp->up != HOST_READY) {
1410 * The first time through here we send a "noop" request. This will
1411 * return the feature list from the client if it supports that.
1412 * If it does not, handle_result() will set the feature list to an
1413 * empty structure. In either case, we do the disks on the second
1414 * (and subsequent) pass(es).
1416 if(hostp->features != NULL) { /* sendsize service */
1420 int has_features = am_has_feature(hostp->features,
1421 fe_req_options_features);
1422 int has_hostname = am_has_feature(hostp->features,
1423 fe_req_options_hostname);
1424 int has_maxdumps = am_has_feature(hostp->features,
1425 fe_req_options_maxdumps);
1426 int has_config = am_has_feature(hostp->features,
1427 fe_req_options_config);
1429 g_snprintf(number, SIZEOF(number), "%d", hostp->maxdumps);
1430 req = vstralloc("SERVICE ", "sendsize", "\n",
1432 has_features ? "features=" : "",
1433 has_features ? our_feature_string : "",
1434 has_features ? ";" : "",
1435 has_maxdumps ? "maxdumps=" : "",
1436 has_maxdumps ? number : "",
1437 has_maxdumps ? ";" : "",
1438 has_hostname ? "hostname=" : "",
1439 has_hostname ? hostp->hostname : "",
1440 has_hostname ? ";" : "",
1441 has_config ? "config=" : "",
1442 has_config ? get_config_name() : "",
1443 has_config ? ";" : "",
1446 req_len = strlen(req);
1447 req_len += 128; /* room for SECURITY ... */
1449 for(dp = hostp->disks; dp != NULL; dp = dp->hostnext) {
1453 GPtrArray *errarray;
1455 if(dp->todo == 0) continue;
1457 if(est(dp)->state != DISK_READY) continue;
1459 est(dp)->got_estimate = 0;
1460 if (est(dp)->estimate[0].level == -1) {
1461 est(dp)->state = DISK_DONE;
1465 qname = quote_string(dp->name);
1467 errarray = validate_optionstr(dp);
1468 if (errarray->len > 0) {
1470 for (i=0; i < errarray->len; i++) {
1471 log_add(L_FAIL, _("%s %s %s 0 [%s]"),
1472 dp->host->hostname, qname,
1474 (char *)g_ptr_array_index(errarray, i));
1477 est(dp)->state = DISK_DONE;
1481 b64disk = amxml_format_tag("disk", dp->name);
1482 qdevice = quote_string(dp->device);
1483 estimate = (estimate_t)GPOINTER_TO_INT(dp->estimatelist->data);
1485 b64device = amxml_format_tag("diskdevice", dp->device);
1487 estimate = ES_CLIENT;
1488 for (el = dp->estimatelist; el != NULL; el = el->next) {
1489 estimate = (estimate_t)GPOINTER_TO_INT(el->data);
1490 if (estimate == ES_SERVER)
1493 if (estimate == ES_SERVER) {
1496 get_info(dp->host->hostname, dp->name, &info);
1497 for(i = 0; i < MAX_LEVELS; i++) {
1498 int lev = est(dp)->estimate[i].level;
1500 if(lev == -1) break;
1501 server_estimate(dp, i, &info, lev);
1503 g_fprintf(stderr,_("%s time %s: got result for host %s disk %s:"),
1504 get_pname(), walltime_str(curclock()),
1505 dp->host->hostname, qname);
1506 g_fprintf(stderr,_(" %d -> %lldK, %d -> %lldK, %d -> %lldK\n"),
1507 est(dp)->estimate[0].level,
1508 (long long)est(dp)->estimate[0].nsize,
1509 est(dp)->estimate[1].level,
1510 (long long)est(dp)->estimate[1].nsize,
1511 est(dp)->estimate[2].level,
1512 (long long)est(dp)->estimate[2].nsize);
1513 if (!am_has_feature(hostp->features, fe_xml_estimate)) {
1514 est(dp)->state = DISK_DONE;
1515 remove_disk(&startq, dp);
1516 enqueue_disk(&estq, dp);
1520 estimate = ES_SERVER;
1521 for (el = dp->estimatelist; el != NULL; el = el->next) {
1522 estimate = (estimate_t)GPOINTER_TO_INT(el->data);
1523 if (estimate == ES_CLIENT || estimate == ES_CALCSIZE)
1526 if (estimate == ES_CLIENT ||
1527 estimate == ES_CALCSIZE ||
1528 (am_has_feature(hostp->features, fe_req_xml) &&
1529 am_has_feature(hostp->features, fe_xml_estimate))) {
1533 if (am_has_feature(hostp->features, fe_req_xml)) {
1534 char *levelstr = NULL;
1535 char *spindlestr = NULL;
1536 char level[NUM_STR_SIZE];
1537 char spindle[NUM_STR_SIZE];
1542 get_info(dp->host->hostname, dp->name, &info);
1543 for(i = 0; i < MAX_LEVELS; i++) {
1545 int lev = est(dp)->estimate[i].level;
1546 if (lev == -1) break;
1547 g_snprintf(level, SIZEOF(level), "%d", lev);
1548 if (am_has_feature(hostp->features, fe_xml_level_server) &&
1549 server_can_do_estimate(dp, &info, lev)) {
1550 server = "<server>YES</server>";
1554 vstrextend(&levelstr, " <level>",
1556 "</level>\n", NULL);
1558 g_snprintf(spindle, SIZEOF(spindle), "%d", dp->spindle);
1559 spindlestr = vstralloc(" <spindle>",
1561 "</spindle>\n", NULL);
1562 o = xml_optionstr(dp, 0);
1564 if (strcmp(dp->program,"DUMP") == 0 ||
1565 strcmp(dp->program,"GNUTAR") == 0) {
1566 l = vstralloc("<dle>\n",
1569 "</program>\n", NULL);
1571 l = vstralloc("<dle>\n",
1572 " <program>APPLICATION</program>\n",
1574 if (dp->application) {
1575 application_t *application;
1578 application = lookup_application(dp->application);
1579 g_assert(application != NULL);
1580 xml_app = xml_application(dp, application,
1582 vstrextend(&l, xml_app, NULL);
1587 es = xml_estimate(dp->estimatelist, hostp->features);
1588 vstrextend(&l, es, "\n", NULL);
1590 vstrextend(&l, " ", b64disk, "\n", NULL);
1592 vstrextend(&l, " ", b64device, "\n", NULL);
1593 vstrextend(&l, levelstr, spindlestr, o, "</dle>\n", NULL);
1600 } else if (strcmp(dp->program,"DUMP") != 0 &&
1601 strcmp(dp->program,"GNUTAR") != 0) {
1602 est(dp)->errstr = newvstrallocf(est(dp)->errstr,
1603 _("does not support application-api"));
1605 for(i = 0; i < MAX_LEVELS; i++) {
1607 char *exclude1 = "";
1608 char *exclude2 = "";
1609 char *excludefree = NULL;
1610 char *include1 = "";
1611 char *include2 = "";
1612 char *includefree = NULL;
1613 char spindle[NUM_STR_SIZE];
1614 char level[NUM_STR_SIZE];
1615 int lev = est(dp)->estimate[i].level;
1617 if(lev == -1) break;
1619 g_snprintf(level, SIZEOF(level), "%d", lev);
1620 g_snprintf(spindle, SIZEOF(spindle), "%d", dp->spindle);
1621 if (am_has_feature(hostp->features,
1622 fe_sendsize_req_options)){
1623 exclude1 = " OPTIONS |";
1624 exclude2 = optionstr(dp);
1625 if ( exclude2 == NULL ) {
1626 error(_("problem with option string, check the dumptype definition.\n"));
1628 excludefree = exclude2;
1631 if (dp->exclude_file &&
1632 dp->exclude_file->nb_element == 1) {
1633 exclude1 = " exclude-file=";
1634 exclude2 = quote_string(
1635 dp->exclude_file->first->name);
1636 excludefree = exclude2;
1638 else if (dp->exclude_list &&
1639 dp->exclude_list->nb_element == 1) {
1640 exclude1 = " exclude-list=";
1641 exclude2 = quote_string(
1642 dp->exclude_list->first->name);
1643 excludefree = exclude2;
1645 if (dp->include_file &&
1646 dp->include_file->nb_element == 1) {
1647 include1 = " include-file=";
1648 include2 = quote_string(
1649 dp->include_file->first->name);
1650 includefree = include2;
1652 else if (dp->include_list &&
1653 dp->include_list->nb_element == 1) {
1654 include1 = " include-list=";
1655 include2 = quote_string(
1656 dp->include_list->first->name);
1657 includefree = include2;
1661 if (estimate == ES_CALCSIZE &&
1662 !am_has_feature(hostp->features,
1663 fe_calcsize_estimate)) {
1665 _("%s:%s does not support CALCSIZE for estimate, using CLIENT.\n"),
1666 hostp->hostname, qname);
1667 estimate = ES_CLIENT;
1669 if(estimate == ES_CLIENT)
1672 calcsize = "CALCSIZE ";
1674 l = vstralloc(calcsize,
1677 " ", dp->device ? qdevice : "",
1679 " ", est(dp)->estimate[i].dumpdate,
1681 " ", exclude1, exclude2,
1682 ((includefree != NULL) ? " " : ""),
1689 amfree(includefree);
1690 amfree(excludefree);
1698 if (est(dp)->state == DISK_DONE) {
1699 remove_disk(&estq, dp);
1700 est(dp)->state = DISK_PARTIALY_DONE;
1701 enqueue_disk(&pestq, dp);
1703 remove_disk(&startq, dp);
1704 est(dp)->state = DISK_ACTIVE;
1706 } else if (est(dp)->state != DISK_DONE) {
1707 remove_disk(&startq, dp);
1708 est(dp)->state = DISK_DONE;
1709 if (est(dp)->errstr == NULL) {
1710 est(dp)->errstr = vstrallocf(
1711 _("Can't request estimate"));
1713 enqueue_disk(&failq, dp);
1722 if(estimates == 0) {
1724 hostp->up = HOST_DONE;
1728 if (conf_etimeout < 0) {
1729 timeout = - conf_etimeout;
1731 timeout = estimates * conf_etimeout;
1733 } else { /* noop service */
1734 req = vstralloc("SERVICE ", "noop", "\n",
1736 "features=", our_feature_string, ";",
1740 * We use ctimeout for the "noop" request because it should be
1741 * very fast and etimeout has other side effects.
1743 timeout = (time_t)getconf_int(CNF_CTIMEOUT);
1746 dbprintf(_("send request:\n----\n%s\n----\n\n"), req);
1747 secdrv = security_getdriver(hostp->disks->auth);
1748 if (secdrv == NULL) {
1749 hostp->up = HOST_DONE;
1751 _("Could not find security driver '%s' for host '%s'"),
1752 hostp->disks->auth, hostp->hostname);
1756 hostp->up = HOST_ACTIVE;
1758 for(dp = hostp->disks; dp != NULL; dp = dp->hostnext) {
1762 if(est(dp)->state == DISK_ACTIVE) {
1763 est(dp)->errstr = NULL;
1764 enqueue_disk(&waitq, dp);
1768 protocol_sendreq(hostp->hostname, secdrv, amhost_get_security_conf,
1769 req, timeout, handle_result, hostp);
1774 static disk_t *lookup_hostdisk(
1775 /*@keep@*/ am_host_t *hp,
1780 for(dp = hp->disks; dp != NULL; dp = dp->hostnext)
1781 if(strcmp(str, dp->name) == 0) return dp;
1787 static void handle_result(
1790 security_handle_t *sech)
1796 char *msg, msg_undo;
1797 char *remoterr, *errbuf = NULL;
1808 hostp = (am_host_t *)datap;
1809 hostp->up = HOST_READY;
1812 errbuf = vstrallocf(_("Request to %s failed: %s"),
1813 hostp->hostname, security_geterror(sech));
1816 if (pkt->type == P_NAK) {
1818 if(strncmp_const_skip(s, "ERROR ", s, ch) == 0) {
1821 goto NAK_parse_failed;
1823 skip_whitespace(s, ch);
1824 if(ch == '\0') goto NAK_parse_failed;
1826 if((s = strchr(remoterr, '\n')) != NULL) {
1827 if(s == remoterr) goto NAK_parse_failed;
1830 if (strcmp(remoterr, "unknown service: noop") != 0
1831 && strcmp(remoterr, "noop: invalid service") != 0) {
1832 errbuf = vstralloc(hostp->hostname, " NAK: ", remoterr, NULL);
1838 dbprintf(_("got reply:\n----\n%s\n----\n\n"), pkt->body);
1844 if(strncmp_const(line, "OPTIONS ") == 0) {
1845 t = strstr(line, "features=");
1846 if(t != NULL && (g_ascii_isspace((int)t[-1]) || t[-1] == ';')) {
1847 char *u = strchr(t, ';');
1850 t += SIZEOF("features=")-1;
1851 am_release_feature_set(hostp->features);
1852 if((hostp->features = am_string_to_feature(t)) == NULL) {
1853 errbuf = vstrallocf(hostp->hostname,
1854 _(": bad features value: %s\n"), line);
1860 skip_quoted_line(s, ch);
1865 if ((strncmp_const_skip(t, "ERROR ", t, tch) == 0) ||
1866 (strncmp_const_skip(t, "WARNING ", t, tch) == 0)) {
1868 skip_whitespace(t, tch);
1874 * If the "error" is that the "noop" service is unknown, it
1875 * just means the client is "old" (does not support the servie).
1876 * We can ignore this.
1878 if(hostp->features == NULL
1879 && pkt->type == P_NAK
1880 && (strcmp(t - 1, "unknown service: noop") == 0
1881 || strcmp(t - 1, "noop: invalid service") == 0)) {
1882 skip_quoted_line(s, ch);
1886 if (t) /* truncate after the first line */
1888 errbuf = vstralloc(hostp->hostname,
1889 (pkt->type == P_NAK) ? "NAK " : "",
1898 skip_quoted_string(t, tch);
1900 disk = unquote_string(msg);
1902 skip_whitespace(t, tch);
1904 if (sscanf(t - 1, "%d", &level) != 1) {
1908 skip_integer(t, tch);
1909 skip_whitespace(t, tch);
1911 dp = lookup_hostdisk(hostp, disk);
1913 log_add(L_ERROR, _("%s: invalid reply from sendsize: `%s'\n"),
1914 hostp->hostname, line);
1919 if (strncmp_const(t-1,"SIZE ") == 0) {
1920 if (sscanf(t - 1, "SIZE %lld", &size_) != 1) {
1923 size = (gint64)size_;
1924 } else if ((strncmp_const(t-1,"ERROR ") == 0) ||
1925 (strncmp_const(t-1,"WARNING ") == 0)) {
1926 skip_non_whitespace(t, tch);
1927 skip_whitespace(t, tch);
1929 skip_quoted_string(t,tch);
1932 if (pkt->type == P_REP && !est(dp)->errstr) {
1933 est(dp)->errstr = unquote_string(msg);
1942 for (i = 0; i < MAX_LEVELS; i++) {
1943 if (est(dp)->estimate[i].level == level) {
1944 if (size == (gint64)-2) {
1945 est(dp)->estimate[i].nsize = -1; /* remove estimate */
1946 est(dp)->estimate[i].guessed = 0;
1947 } else if (size > (gint64)-1) {
1948 /* take the size returned by the client */
1949 est(dp)->estimate[i].nsize = size;
1950 est(dp)->estimate[i].guessed = 0;
1955 if (i == MAX_LEVELS) {
1956 goto bad_msg; /* this est wasn't requested */
1958 est(dp)->got_estimate++;
1962 skip_quoted_line(s, ch);
1965 if(hostp->up == HOST_READY && hostp->features == NULL) {
1967 * The client does not support the features list, so give it an
1970 dbprintf(_("no feature set from host %s\n"), hostp->hostname);
1971 hostp->features = am_set_default_feature_set();
1974 security_close_connection(sech, hostp->hostname);
1976 /* XXX what about disks that only got some estimates... do we care? */
1977 /* XXX amanda 2.1 treated that case as a bad msg */
1979 for(dp = hostp->disks; dp != NULL; dp = dp->hostnext) {
1980 if(dp->todo == 0) continue;
1981 if(est(dp)->state != DISK_ACTIVE &&
1982 est(dp)->state != DISK_PARTIALY_DONE) continue;
1984 if(est(dp)->state == DISK_ACTIVE) {
1985 remove_disk(&waitq, dp);
1987 else if(est(dp)->state == DISK_PARTIALY_DONE) {
1988 remove_disk(&pestq, dp);
1991 if(pkt->type == P_REP) {
1992 est(dp)->state = DISK_DONE;
1994 else if(pkt->type == P_PREP) {
1995 est(dp)->state = DISK_PARTIALY_DONE;
1998 if (est(dp)->estimate[0].level == -1) continue; /* ignore this disk */
2001 qname = quote_string(dp->name);
2002 if(pkt->type == P_PREP) {
2003 g_fprintf(stderr,_("%s: time %s: got partial result for host %s disk %s:"),
2004 get_pname(), walltime_str(curclock()),
2005 dp->host->hostname, qname);
2006 g_fprintf(stderr,_(" %d -> %lldK, %d -> %lldK, %d -> %lldK\n"),
2007 est(dp)->estimate[0].level,
2008 (long long)est(dp)->estimate[0].nsize,
2009 est(dp)->estimate[1].level,
2010 (long long)est(dp)->estimate[1].nsize,
2011 est(dp)->estimate[2].level,
2012 (long long)est(dp)->estimate[2].nsize);
2013 enqueue_disk(&pestq, dp);
2015 else if(pkt->type == P_REP) {
2016 g_fprintf(stderr,_("%s: time %s: got result for host %s disk %s:"),
2017 get_pname(), walltime_str(curclock()),
2018 dp->host->hostname, qname);
2019 g_fprintf(stderr,_(" %d -> %lldK, %d -> %lldK, %d -> %lldK\n"),
2020 est(dp)->estimate[0].level,
2021 (long long)est(dp)->estimate[0].nsize,
2022 est(dp)->estimate[1].level,
2023 (long long)est(dp)->estimate[1].nsize,
2024 est(dp)->estimate[2].level,
2025 (long long)est(dp)->estimate[2].nsize);
2026 if ((est(dp)->estimate[0].level != -1 &&
2027 est(dp)->estimate[0].nsize > (gint64)0) ||
2028 (est(dp)->estimate[1].level != -1 &&
2029 est(dp)->estimate[1].nsize > (gint64)0) ||
2030 (est(dp)->estimate[2].level != -1 &&
2031 est(dp)->estimate[2].nsize > (gint64)0)) {
2033 for (i=MAX_LEVELS-1; i >=0; i--) {
2034 if (est(dp)->estimate[i].level != -1 &&
2035 est(dp)->estimate[i].nsize < (gint64)0) {
2036 est(dp)->estimate[i].level = -1;
2039 enqueue_disk(&estq, dp);
2042 enqueue_disk(&failq, dp);
2043 if(est(dp)->got_estimate && !est(dp)->errstr) {
2044 est(dp)->errstr = vstrallocf("disk %s, all estimate failed",
2049 _("error result for host %s disk %s: missing estimate\n"),
2050 dp->host->hostname, qname);
2051 if (est(dp)->errstr == NULL) {
2052 est(dp)->errstr = vstrallocf(_("missing result for %s in %s response"),
2053 qname, dp->host->hostname);
2057 hostp->up = HOST_DONE;
2059 if (est(dp)->post_dle == 0 &&
2060 (pkt->type == P_REP ||
2061 ((est(dp)->estimate[0].level == -1 ||
2062 est(dp)->estimate[0].nsize > (gint64)0) &&
2063 (est(dp)->estimate[1].level == -1 ||
2064 est(dp)->estimate[1].nsize > (gint64)0) &&
2065 (est(dp)->estimate[2].level == -1 ||
2066 est(dp)->estimate[2].nsize > (gint64)0)))) {
2067 run_server_scripts(EXECUTE_ON_POST_DLE_ESTIMATE,
2068 get_config_name(), dp,
2069 est(dp)->estimate[0].level);
2070 est(dp)->post_dle = 1;
2075 if(hostp->up == HOST_DONE) {
2076 for(dp = hostp->disks; dp != NULL; dp = dp->hostnext) {
2078 if (pkt->type == P_REP) {
2079 run_server_scripts(EXECUTE_ON_POST_HOST_ESTIMATE,
2080 get_config_name(), dp,
2081 est(dp)->estimate[0].level);
2087 /* try to clean up any defunct processes, since Amanda doesn't wait() for
2089 while(waitpid(-1, NULL, WNOHANG)> 0);
2094 errbuf = vstrallocf(_("%s NAK: [NAK parse failed]"), hostp->hostname);
2095 g_fprintf(stderr, _("got strange nak from %s:\n----\n%s----\n\n"),
2096 hostp->hostname, pkt->body);
2100 g_fprintf(stderr,_("got a bad message, stopped at:\n"));
2102 g_fprintf(stderr,_("----\n%s----\n\n"), line);
2103 errbuf = stralloc2(_("badly formatted response from "), hostp->hostname);
2108 for(dp = hostp->disks; dp != NULL; dp = dp->hostnext) {
2110 if(est(dp)->state == DISK_ACTIVE) {
2111 qname = quote_string(dp->name);
2112 est(dp)->state = DISK_DONE;
2113 remove_disk(&waitq, dp);
2114 enqueue_disk(&failq, dp);
2117 est(dp)->errstr = stralloc(errbuf);
2118 g_fprintf(stderr, _("error result for host %s disk %s: %s\n"),
2119 dp->host->hostname, qname, errbuf);
2126 * If there were no disks involved, make sure the error gets
2129 log_add(L_ERROR, "%s", errbuf);
2131 hostp->up = HOST_DONE;
2133 /* try to clean up any defunct processes, since Amanda doesn't wait() for
2135 while(waitpid(-1, NULL, WNOHANG)> 0);
2142 * ========================================================================
2147 static int schedule_order(disk_t *a, disk_t *b); /* subroutines */
2148 static one_est_t *pick_inclevel(disk_t *dp);
2150 static void analyze_estimate(
2156 char *qname = quote_string(dp->name);
2160 g_fprintf(stderr, _("pondering %s:%s... "),
2161 dp->host->hostname, qname);
2162 g_fprintf(stderr, _("next_level0 %d last_level %d "),
2163 ep->next_level0, ep->last_level);
2165 if(get_info(dp->host->hostname, dp->name, &info) == 0) {
2169 ep->degr_est = &default_one_est;
2171 if (ep->next_level0 <= 0 || (have_info && ep->last_level == 0
2172 && (ISSET(info.command, FORCE_NO_BUMP)))) {
2173 if (ep->next_level0 <= 0) {
2174 g_fprintf(stderr,_("(due for level 0) "));
2176 ep->dump_est = est_for_level(dp, 0);
2177 if (ep->dump_est->csize <= (gint64)0) {
2179 _("(no estimate for level 0, picking an incr level)\n"));
2180 ep->dump_est = pick_inclevel(dp);
2182 if (ep->dump_est->nsize == (gint64)-1) {
2183 ep->dump_est = est_for_level(dp, ep->dump_est->level + 1);
2187 total_lev0 += (double) ep->dump_est->csize;
2188 if(ep->last_level == -1 || dp->skip_incr) {
2189 g_fprintf(stderr,_("(%s disk, can't switch to degraded mode)\n"),
2190 dp->skip_incr? "skip-incr":_("new"));
2191 if (dp->skip_incr && ep->degr_mesg == NULL) {
2192 ep->degr_mesg = _("Skpping: skip-incr disk can't be dumped in degraded mode");
2194 ep->degr_est = &default_one_est;
2197 /* fill in degraded mode info */
2198 g_fprintf(stderr,_("(picking inclevel for degraded mode)"));
2199 ep->degr_est = pick_inclevel(dp);
2200 if (ep->degr_est->csize == (gint64)-1) {
2201 ep->degr_est = est_for_level(dp, ep->degr_est->level + 1);
2203 if (ep->degr_est->csize == (gint64)-1) {
2204 g_fprintf(stderr,_("(no inc estimate)"));
2205 if (ep->degr_mesg == NULL)
2206 ep->degr_mesg = _("Skipping: an incremental estimate could not be performed, so disk cannot be dumped in degraded mode");
2207 ep->degr_est = &default_one_est;
2209 g_fprintf(stderr,"\n");
2214 g_fprintf(stderr,_("(not due for a full dump, picking an incr level)\n"));
2215 /* XXX - if this returns -1 may be we should force a total? */
2216 ep->dump_est = pick_inclevel(dp);
2218 if (ep->dump_est->csize == (gint64)-1) {
2219 ep->dump_est = est_for_level(dp, ep->last_level);
2221 if (ep->dump_est->csize == (gint64)-1) {
2222 ep->dump_est = est_for_level(dp, ep->last_level + 1);
2224 if (ep->dump_est->csize == (gint64)-1) {
2225 ep->dump_est = est_for_level(dp, 0);
2227 if (ep->degr_mesg == NULL) {
2228 ep->degr_mesg = _("Skipping: a full is not planned, so can't dump in degraded mode");
2232 if (ep->dump_est->level < 0) {
2234 char *q = quote_string("no estimate");
2236 g_fprintf(stderr,_(" no valid estimate\n"));
2237 for(i=0; i<MAX_LEVELS; i++) {
2238 if (est(dp)->estimate[i].level >= 0) {
2239 g_fprintf(stderr,(" level: %d nsize: %lld csize: %lld\n"),
2240 est(dp)->estimate[i].level,
2241 (long long)est(dp)->estimate[i].nsize,
2242 (long long)est(dp)->estimate[i].csize);
2245 log_add(L_WARNING, _("%s %s %s 0 %s"), dp->host->hostname, qname,
2246 planner_timestamp, q);
2250 g_fprintf(stderr,_(" curr level %d nsize %lld csize %lld "),
2251 ep->dump_est->level, (long long)ep->dump_est->nsize,
2252 (long long)ep->dump_est->csize);
2254 insert_disk(&schedq, dp, schedule_order);
2256 total_size += (gint64)tt_blocksize_kb + ep->dump_est->csize + tape_mark;
2258 /* update the balanced size */
2259 if(!(dp->skip_full || dp->strategy == DS_NOFULL ||
2260 dp->strategy == DS_INCRONLY)) {
2263 lev0size = est_tape_size(dp, 0);
2264 if(lev0size == (gint64)-1) lev0size = ep->last_lev0size;
2266 balanced_size += (double)(lev0size / (gint64)runs_per_cycle);
2269 g_fprintf(stderr,_("total size %lld total_lev0 %1.0lf balanced-lev0size %1.0lf\n"),
2270 (long long)total_size, total_lev0, balanced_size);
2272 /* Log errstr even if the estimate succeeded */
2273 /* It can be an error from a script */
2274 if (est(dp)->errstr) {
2275 char *qerrstr = quote_string(est(dp)->errstr);
2276 /* Log only a warning if a server estimate is available */
2277 if (est(dp)->estimate[0].nsize > 0 ||
2278 est(dp)->estimate[1].nsize > 0 ||
2279 est(dp)->estimate[2].nsize > 0) {
2280 log_add(L_WARNING, _("%s %s %s 0 %s"), dp->host->hostname, qname,
2281 planner_timestamp, qerrstr);
2283 log_add(L_FAIL, _("%s %s %s 0 %s"), dp->host->hostname, qname,
2284 planner_timestamp, qerrstr);
2292 static void handle_failed(
2295 char *errstr, *errstr1, *qerrstr;
2296 char *qname = quote_string(dp->name);
2298 errstr = est(dp)->errstr? est(dp)->errstr : _("hmm, no error indicator!");
2299 errstr1 = vstralloc("[",errstr,"]", NULL);
2300 qerrstr = quote_string(errstr1);
2303 g_fprintf(stderr, _("%s: FAILED %s %s %s 0 %s\n"),
2304 get_pname(), dp->host->hostname, qname, planner_timestamp, qerrstr);
2306 log_add(L_FAIL, _("%s %s %s 0 %s"), dp->host->hostname, qname,
2307 planner_timestamp, qerrstr);
2311 /* XXX - memory leak with *dp */
2316 * insert-sort by decreasing priority, then
2317 * by decreasing size within priority levels.
2320 static int schedule_order(
2327 diff = est(b)->dump_priority - est(a)->dump_priority;
2328 if(diff != 0) return diff;
2330 ldiff = est(b)->dump_est->csize - est(a)->dump_est->csize;
2331 if(ldiff < (gint64)0) return -1; /* XXX - there has to be a better way to dothis */
2332 if(ldiff > (gint64)0) return 1;
2337 static one_est_t *pick_inclevel(
2340 one_est_t *level0_est, *base_est, *bump_est;
2344 level0_est = est_for_level(dp, 0);
2345 base_est = est_for_level(dp, est(dp)->last_level);
2347 /* if last night was level 0, do level 1 tonight, no ifs or buts */
2348 if (base_est->level == 0) {
2349 g_fprintf(stderr,_(" picklev: last night 0, so tonight level 1\n"));
2350 return est_for_level(dp, 1);
2353 /* if no-full option set, always do level 1 */
2354 if(dp->strategy == DS_NOFULL) {
2355 g_fprintf(stderr,_(" picklev: no-full set, so always level 1\n"));
2356 return est_for_level(dp, 1);
2359 /* if we didn't get an estimate, we can't do an inc */
2360 if (base_est->nsize == (gint64)-1) {
2361 bump_est = est_for_level(dp, est(dp)->last_level + 1);
2362 if (bump_est->nsize > (gint64)0) { /* FORCE_BUMP */
2363 g_fprintf(stderr,_(" picklev: bumping to level %d\n"), bump_est->level);
2366 g_fprintf(stderr,_(" picklev: no estimate for level %d, so no incs\n"), base_est->level);
2370 thresh = bump_thresh(base_est->level, level0_est->nsize, dp->bumppercent,
2371 dp->bumpsize, dp->bumpmult);
2374 _(" pick: size %lld level %d days %d (thresh %lldK, %d days)\n"),
2375 (long long)base_est->nsize, base_est->level, est(dp)->level_days,
2376 (long long)thresh, dp->bumpdays);
2378 if(base_est->level == (DUMP_LEVELS - 1)
2379 || est(dp)->level_days < dp->bumpdays
2380 || base_est->nsize <= thresh)
2383 bump_est = est_for_level(dp, base_est->level + 1);
2385 if (bump_est->nsize == (gint64)-1)
2388 g_fprintf(stderr, _(" pick: next size %lld... "),
2389 (long long)bump_est->nsize);
2391 if (base_est->nsize - bump_est->nsize < thresh) {
2392 g_fprintf(stderr, _("not bumped\n"));
2396 qname = quote_string(dp->name);
2397 g_fprintf(stderr, _("BUMPED\n"));
2398 log_add(L_INFO, _("Incremental of %s:%s bumped to level %d."),
2399 dp->host->hostname, qname, bump_est->level);
2409 ** ========================================================================
2412 ** We have two strategies here:
2416 ** If we are trying to fit too much on the tape something has to go. We
2417 ** try to delay totals until tomorrow by converting them into incrementals
2418 ** and, if that is not effective enough, dropping incrementals altogether.
2419 ** While we are searching for the guilty dump (the one that is really
2420 ** causing the schedule to be oversize) we have probably trampled on a lot of
2421 ** innocent dumps, so we maintain a "before image" list and use this to
2422 ** put back what we can.
2424 ** 2. Promote dumps.
2426 ** We try to keep the amount of tape used by total dumps the same each night.
2427 ** If there is some spare tape in this run we have a look to see if any of
2428 ** tonights incrementals could be promoted to totals and leave us with a
2429 ** more balanced cycle.
2432 static void delay_one_dump(disk_t *dp, int delete, ...);
2433 static int promote_highest_priority_incremental(void);
2434 static int promote_hills(void);
2436 /* delay any dumps that will not fit */
2437 static void delay_dumps(void)
2444 gint64 new_total; /* New total_size */
2445 char est_kb[20]; /* Text formatted dump size */
2446 int nb_forced_level_0;
2452 biq.head = biq.tail = NULL;
2455 ** 1. Delay dumps that are way oversize.
2457 ** Dumps larger that the size of the tapes we are using are just plain
2458 ** not going to fit no matter how many other dumps we drop. Delay
2459 ** oversize totals until tomorrow (by which time my owner will have
2460 ** resolved the problem!) and drop incrementals altogether. Naturally
2461 ** a large total might be delayed into a large incremental so these
2462 ** need to be checked for separately.
2465 for(dp = schedq.head; dp != NULL; dp = ndp) {
2466 int avail_tapes = 1;
2467 if (dp->splitsize > (gint64)0)
2468 avail_tapes = conf_runtapes;
2470 ndp = dp->next; /* remove_disk zaps this */
2472 full_size = est_tape_size(dp, 0);
2473 if (full_size > tapetype_get_length(tape) * (gint64)avail_tapes) {
2474 char *qname = quote_string(dp->name);
2475 if (conf_runtapes > 1 && dp->splitsize == (gint64)0) {
2476 log_add(L_WARNING, _("disk %s:%s, full dump (%lldKB) will be larger than available tape space"
2477 ", you could define a splitsize"),
2478 dp->host->hostname, qname,
2479 (long long)full_size);
2481 log_add(L_WARNING, _("disk %s:%s, full dump (%lldKB) will be larger than available tape space"),
2482 dp->host->hostname, qname,
2483 (long long)full_size);
2488 if (est(dp)->dump_est->csize == (gint64)-1 ||
2489 est(dp)->dump_est->csize <= tapetype_get_length(tape) * (gint64)avail_tapes) {
2493 /* Format dumpsize for messages */
2494 g_snprintf(est_kb, 20, "%lld KB,",
2495 (long long)est(dp)->dump_est->csize);
2497 if(est(dp)->dump_est->level == 0) {
2500 message = _("but cannot incremental dump skip-incr disk");
2502 else if(est(dp)->last_level < 0) {
2504 message = _("but cannot incremental dump new disk");
2506 else if(est(dp)->degr_est->level < 0) {
2508 message = _("but no incremental estimate");
2510 else if (est(dp)->degr_est->csize > tapetype_get_length(tape)) {
2512 message = _("incremental dump also larger than tape");
2516 message = _("full dump delayed");
2521 message = _("skipping incremental");
2523 delay_one_dump(dp, delete, _("dump larger than available tape space,"),
2524 est_kb, message, NULL);
2528 ** 2. Delay total dumps.
2530 ** Delay total dumps until tomorrow (or the day after!). We start with
2531 ** the lowest priority (most dispensable) and work forwards. We take
2532 ** care not to delay *all* the dumps since this could lead to a stale
2533 ** mate [for any one disk there are only three ways tomorrows dump will
2534 ** be smaller than todays: 1. we do a level 0 today so tomorows dump
2535 ** will be a level 1; 2. the disk gets more data so that it is bumped
2536 ** tomorrow (this can be a slow process); and, 3. the disk looses some
2537 ** data (when does that ever happen?)].
2540 nb_forced_level_0 = 0;
2542 for(dp = schedq.head; dp != NULL && preserve == NULL; dp = dp->next)
2543 if(est(dp)->dump_est->level == 0)
2546 /* 2.a. Do not delay forced full */
2547 for(dp = schedq.tail;
2548 dp != NULL && total_size > tape_length;
2552 if(est(dp)->dump_est->level != 0) continue;
2554 get_info(dp->host->hostname, dp->name, &info);
2555 if(ISSET(info.command, FORCE_FULL)) {
2556 nb_forced_level_0 += 1;
2561 if(dp != preserve) {
2563 /* Format dumpsize for messages */
2564 g_snprintf(est_kb, 20, "%lld KB,",
2565 (long long)est(dp)->dump_est->csize);
2569 message = _("but cannot incremental dump skip-incr disk");
2571 else if(est(dp)->last_level < 0) {
2573 message = _("but cannot incremental dump new disk");
2575 else if(est(dp)->degr_est->level < 0) {
2577 message = _("but no incremental estimate");
2581 message = _("full dump delayed");
2583 delay_one_dump(dp, delete, _("dumps too big,"), est_kb,
2588 /* 2.b. Delay forced full if needed */
2589 if(nb_forced_level_0 > 0 && total_size > tape_length) {
2590 for(dp = schedq.tail;
2591 dp != NULL && total_size > tape_length;
2595 if(est(dp)->dump_est->level == 0 && dp != preserve) {
2597 /* Format dumpsize for messages */
2598 g_snprintf(est_kb, 20, "%lld KB,",
2599 (long long)est(dp)->dump_est->csize);
2603 message = _("but cannot incremental dump skip-incr disk");
2605 else if(est(dp)->last_level < 0) {
2607 message = _("but cannot incremental dump new disk");
2609 else if(est(dp)->degr_est->level < 0) {
2611 message = _("but no incremental estimate");
2615 message = _("full dump delayed");
2617 delay_one_dump(dp, delete, _("dumps too big,"), est_kb,
2624 ** 3. Delay incremental dumps.
2626 ** Delay incremental dumps until tomorrow. This is a last ditch attempt
2627 ** at making things fit. Again, we start with the lowest priority (most
2628 ** dispensable) and work forwards.
2631 for(dp = schedq.tail;
2632 dp != NULL && total_size > tape_length;
2636 if(est(dp)->dump_est->level != 0) {
2638 /* Format dumpsize for messages */
2639 g_snprintf(est_kb, 20, "%lld KB,",
2640 (long long)est(dp)->dump_est->csize);
2642 delay_one_dump(dp, 1,
2643 _("dumps way too big,"),
2645 _("must skip incremental dumps"),
2651 ** 4. Reinstate delayed dumps.
2653 ** We might not have needed to stomp on all of the dumps we have just
2654 ** delayed above. Try to reinstate them all starting with the last one
2655 ** and working forwards. It is unlikely that the last one will fit back
2656 ** in but why complicate the code?
2659 /*@i@*/ for(bi = biq.tail; bi != NULL; bi = nbi) {
2660 int avail_tapes = 1;
2663 if(dp->splitsize > (gint64)0)
2664 avail_tapes = conf_runtapes;
2667 new_total = total_size + (gint64)tt_blocksize_kb +
2668 bi->csize + (gint64)tape_mark;
2670 new_total = total_size - est(dp)->dump_est->csize + bi->csize;
2672 if((new_total <= tape_length) &&
2673 (bi->csize < (tapetype_get_length(tape) * (gint64)avail_tapes))) {
2675 total_size = new_total;
2677 if(bi->level == 0) {
2678 total_lev0 += (double) bi->csize;
2680 insert_disk(&schedq, dp, schedule_order);
2683 est(dp)->dump_est = est_for_level(dp, bi->level);
2687 if(bi->next == NULL)
2688 biq.tail = bi->prev;
2690 (bi->next)->prev = bi->prev;
2691 if(bi->prev == NULL)
2692 biq.head = bi->next;
2694 (bi->prev)->next = bi->next;
2702 ** 5. Output messages about what we have done.
2704 ** We can't output messages while we are delaying dumps because we might
2705 ** reinstate them later. We remember all the messages and output them
2709 /*@i@*/ for(bi = biq.head; bi != NULL; bi = nbi) {
2712 g_fprintf(stderr, "%s: FAILED %s\n", get_pname(), bi->errstr);
2713 log_add(L_FAIL, "%s", bi->errstr);
2717 g_fprintf(stderr, _(" delay: %s now at level %d\n"),
2718 bi->errstr, est(dp)->dump_est->level);
2719 log_add(L_INFO, "%s", bi->errstr);
2727 g_fprintf(stderr, _(" delay: Total size now %lld.\n"),
2728 (long long)total_size);
2735 * Remove a dump or modify it from full to incremental.
2736 * Keep track of it on the bi q in case we can add it back later.
2739 static void delay_one_dump,
2745 char level_str[NUM_STR_SIZE];
2748 char *qname = quote_string(dp->name);
2749 char *errstr, *qerrstr;
2751 arglist_start(argp, delete);
2753 total_size -= (gint64)tt_blocksize_kb + est(dp)->dump_est->csize + (gint64)tape_mark;
2754 if(est(dp)->dump_est->level == 0) {
2755 total_lev0 -= (double) est(dp)->dump_est->csize;
2758 bi = alloc(SIZEOF(bi_t));
2760 bi->prev = biq.tail;
2761 if(biq.tail == NULL)
2764 biq.tail->next = bi;
2767 bi->deleted = delete;
2769 bi->level = est(dp)->dump_est->level;
2770 bi->nsize = est(dp)->dump_est->nsize;
2771 bi->csize = est(dp)->dump_est->csize;
2773 g_snprintf(level_str, SIZEOF(level_str), "%d", est(dp)->dump_est->level);
2774 bi->errstr = vstralloc(dp->host->hostname,
2776 " ", planner_timestamp ? planner_timestamp : "?",
2781 while ((next = arglist_val(argp, char *)) != NULL) {
2782 vstrextend(&errstr, sep, next, NULL);
2785 strappend(errstr, "]");
2786 qerrstr = quote_string(errstr);
2787 vstrextend(&bi->errstr, " ", qerrstr, NULL);
2793 remove_disk(&schedq, dp);
2795 est(dp)->dump_est = est(dp)->degr_est;
2796 total_size += (gint64)tt_blocksize_kb + est(dp)->dump_est->csize + (gint64)tape_mark;
2803 static int promote_highest_priority_incremental(void)
2805 disk_t *dp, *dp1, *dp_promote;
2806 gint64 new_total, new_lev0;
2808 int nb_today, nb_same_day, nb_today2;
2809 int nb_disk_today, nb_disk_same_day;
2813 * return 1 if did so; must update total_size correctly; must not
2814 * cause total_size to exceed tape_length
2818 for(dp = schedq.head; dp != NULL; dp = dp->next) {
2819 one_est_t *level0_est = est_for_level(dp, 0);
2820 est(dp)->promote = -1000;
2822 if (level0_est->nsize <= (gint64)0)
2825 if(est(dp)->next_level0 <= 0)
2828 if(est(dp)->next_level0 > dp->maxpromoteday)
2831 new_total = total_size - est(dp)->dump_est->csize + level0_est->csize;
2832 new_lev0 = (gint64)total_lev0 + level0_est->csize;
2837 nb_disk_same_day = 0;
2838 for(dp1 = schedq.head; dp1 != NULL; dp1 = dp1->next) {
2839 if(est(dp1)->dump_est->level == 0)
2841 else if(est(dp1)->next_level0 == est(dp)->next_level0)
2843 if(strcmp(dp->host->hostname, dp1->host->hostname) == 0) {
2844 if(est(dp1)->dump_est->level == 0)
2846 else if(est(dp1)->next_level0 == est(dp)->next_level0)
2851 /* do not promote if overflow tape */
2852 if(new_total > tape_length)
2855 /* do not promote if overflow balanced size and something today */
2856 /* promote if nothing today */
2857 if((new_lev0 > (gint64)(balanced_size + balance_threshold)) &&
2858 (nb_disk_today > 0))
2861 /* do not promote if only one disk due that day and nothing today */
2862 if(nb_disk_same_day == 1 && nb_disk_today == 0)
2865 nb_today2 = nb_today*nb_today;
2866 if(nb_today == 0 && nb_same_day > 1)
2869 if(nb_same_day >= nb_today2) {
2870 est(dp)->promote = ((nb_same_day - nb_today2)*(nb_same_day - nb_today2)) +
2871 conf_dumpcycle - est(dp)->next_level0;
2874 est(dp)->promote = -nb_today2 +
2875 conf_dumpcycle - est(dp)->next_level0;
2878 qname = quote_string(dp->name);
2879 if(!dp_promote || est(dp_promote)->promote < est(dp)->promote) {
2881 g_fprintf(stderr," try %s:%s %d %d %d = %d\n",
2882 dp->host->hostname, qname, nb_same_day, nb_today, est(dp)->next_level0, est(dp)->promote);
2885 g_fprintf(stderr,"no try %s:%s %d %d %d = %d\n",
2886 dp->host->hostname, qname, nb_same_day, nb_today, est(dp)->next_level0, est(dp)->promote);
2892 one_est_t *level0_est;
2894 level0_est = est_for_level(dp, 0);
2896 qname = quote_string(dp->name);
2897 new_total = total_size - est(dp)->dump_est->csize + level0_est->csize;
2898 new_lev0 = (gint64)total_lev0 + level0_est->csize;
2900 total_size = new_total;
2901 total_lev0 = (double)new_lev0;
2902 check_days = est(dp)->next_level0;
2903 est(dp)->degr_est = est(dp)->dump_est;
2904 est(dp)->dump_est = level0_est;
2905 est(dp)->next_level0 = 0;
2908 _(" promote: moving %s:%s up, total_lev0 %1.0lf, total_size %lld\n"),
2909 dp->host->hostname, qname,
2910 total_lev0, (long long)total_size);
2913 plural(_("Full dump of %s:%s promoted from %d day ahead."),
2914 _("Full dump of %s:%s promoted from %d days ahead."),
2916 dp->host->hostname, qname, check_days);
2924 static int promote_hills(void)
2927 struct balance_stats {
2938 /* If we are already doing a level 0 don't bother */
2942 /* Do the guts of an "amadmin balance" */
2943 my_dumpcycle = conf_dumpcycle;
2944 if(my_dumpcycle > 10000) my_dumpcycle = 10000;
2946 sp = (struct balance_stats *)
2947 alloc(SIZEOF(struct balance_stats) * my_dumpcycle);
2949 for(days = 0; days < my_dumpcycle; days++) {
2951 sp[days].size = (gint64)0;
2954 for(dp = schedq.head; dp != NULL; dp = dp->next) {
2955 days = est(dp)->next_level0; /* This is > 0 by definition */
2956 if(days<my_dumpcycle && !dp->skip_full && dp->strategy != DS_NOFULL &&
2957 dp->strategy != DS_INCRONLY) {
2959 sp[days].size += est(dp)->last_lev0size;
2963 /* Search for a suitable big hill and cut it down */
2965 /* Find the tallest hill */
2966 hill_size = (gint64)0;
2967 for(days = 0; days < my_dumpcycle; days++) {
2968 if(sp[days].disks > 1 && sp[days].size > hill_size) {
2969 hill_size = sp[days].size;
2974 if(hill_size <= (gint64)0) break; /* no suitable hills */
2976 /* Find all the dumps in that hill and try and remove one */
2977 for(dp = schedq.head; dp != NULL; dp = dp->next) {
2978 one_est_t *level0_est;
2979 if(est(dp)->next_level0 != hill_days ||
2980 est(dp)->next_level0 > dp->maxpromoteday ||
2982 dp->strategy == DS_NOFULL ||
2983 dp->strategy == DS_INCRONLY)
2985 level0_est = est_for_level(dp, 0);
2986 if (level0_est->nsize <= (gint64)0)
2988 new_total = total_size - est(dp)->dump_est->csize + level0_est->csize;
2989 if(new_total > tape_length)
2991 /* We found a disk we can promote */
2992 qname = quote_string(dp->name);
2993 total_size = new_total;
2994 total_lev0 += (double)level0_est->csize;
2995 est(dp)->degr_est = est(dp)->dump_est;
2996 est(dp)->dump_est = level0_est;
2997 est(dp)->next_level0 = 0;
3000 _(" promote: moving %s:%s up, total_lev0 %1.0lf, total_size %lld\n"),
3001 dp->host->hostname, qname,
3002 total_lev0, (long long)total_size);
3005 plural(_("Full dump of %s:%s specially promoted from %d day ahead."),
3006 _("Full dump of %s:%s specially promoted from %d days ahead."),
3008 dp->host->hostname, qname, hill_days);
3014 /* All the disks in that hill were unsuitable. */
3015 sp[hill_days].disks = 0; /* Don't get tricked again */
3023 * ========================================================================
3026 * XXX - memory leak - we shouldn't just throw away *dp
3028 static void output_scheduleline(
3032 time_t dump_time = 0, degr_time = 0;
3033 double dump_kps = 0, degr_kps = 0;
3034 char *schedline = NULL, *degr_str = NULL;
3035 char dump_priority_str[NUM_STR_SIZE];
3036 char dump_level_str[NUM_STR_SIZE];
3037 char dump_nsize_str[NUM_STR_SIZE];
3038 char dump_csize_str[NUM_STR_SIZE];
3039 char dump_time_str[NUM_STR_SIZE];
3040 char dump_kps_str[NUM_STR_SIZE];
3041 char degr_level_str[NUM_STR_SIZE];
3042 char degr_nsize_str[NUM_STR_SIZE];
3043 char degr_csize_str[NUM_STR_SIZE];
3044 char degr_time_str[NUM_STR_SIZE];
3045 char degr_kps_str[NUM_STR_SIZE];
3046 char *dump_date, *degr_date;
3048 char *qname = quote_string(dp->name);
3052 if(ep->dump_est->csize == (gint64)-1) {
3053 /* no estimate, fail the disk */
3055 _("%s: FAILED %s %s %s %d \"[no estimate]\"\n"),
3057 dp->host->hostname, qname, planner_timestamp, ep->dump_est->level);
3058 log_add(L_FAIL, _("%s %s %s %d [no estimate]"),
3059 dp->host->hostname, qname, planner_timestamp, ep->dump_est->level);
3064 dump_date = ep->dump_est->dumpdate;
3065 degr_date = ep->degr_est->dumpdate;
3067 #define fix_rate(rate) (rate < 1.0 ? DEFAULT_DUMPRATE : rate)
3069 if(ep->dump_est->level == 0) {
3070 dump_kps = fix_rate(ep->fullrate);
3071 dump_time = (time_t)((double)ep->dump_est->csize / dump_kps);
3073 if(ep->degr_est->csize != (gint64)-1) {
3074 degr_kps = fix_rate(ep->incrrate);
3075 degr_time = (time_t)((double)ep->degr_est->csize / degr_kps);
3079 dump_kps = fix_rate(ep->incrrate);
3080 dump_time = (time_t)((double)ep->dump_est->csize / dump_kps);
3083 if(ep->dump_est->level == 0 && ep->degr_est->csize != (gint64)-1) {
3084 g_snprintf(degr_level_str, sizeof(degr_level_str),
3085 "%d", ep->degr_est->level);
3086 g_snprintf(degr_nsize_str, sizeof(degr_nsize_str),
3087 "%lld", (long long)ep->degr_est->nsize);
3088 g_snprintf(degr_csize_str, sizeof(degr_csize_str),
3089 "%lld", (long long)ep->degr_est->csize);
3090 g_snprintf(degr_time_str, sizeof(degr_time_str),
3091 "%lld", (long long)degr_time);
3092 g_snprintf(degr_kps_str, sizeof(degr_kps_str),
3094 degr_str = vstralloc(" ", degr_level_str,
3096 " ", degr_nsize_str,
3097 " ", degr_csize_str,
3103 if (ep->degr_mesg) {
3104 degr_mesg = quote_string(ep->degr_mesg);
3106 degr_mesg = quote_string(_("Skipping: cannot dump in degraded mode for unknown reason"));
3108 degr_str = vstralloc(" ", degr_mesg, NULL);
3111 g_snprintf(dump_priority_str, SIZEOF(dump_priority_str),
3112 "%d", ep->dump_priority);
3113 g_snprintf(dump_level_str, SIZEOF(dump_level_str),
3114 "%d", ep->dump_est->level);
3115 g_snprintf(dump_nsize_str, sizeof(dump_nsize_str),
3116 "%lld", (long long)ep->dump_est->nsize);
3117 g_snprintf(dump_csize_str, sizeof(dump_csize_str),
3118 "%lld", (long long)ep->dump_est->csize);
3119 g_snprintf(dump_time_str, sizeof(dump_time_str),
3120 "%lld", (long long)dump_time);
3121 g_snprintf(dump_kps_str, sizeof(dump_kps_str),
3123 features = am_feature_to_string(dp->host->features);
3124 schedline = vstralloc("DUMP ",dp->host->hostname,
3127 " ", planner_timestamp,
3128 " ", dump_priority_str,
3129 " ", dump_level_str,
3131 " ", dump_nsize_str,
3132 " ", dump_csize_str,
3135 degr_str ? degr_str : "",
3138 if (est(dp)->dump_est->guessed == 1) {
3139 log_add(L_WARNING, _("WARNING: no history available for %s:%s; guessing that size will be %lld KB\n"), dp->host->hostname, qname, (long long)est(dp)->dump_est->csize);
3141 fputs(schedline, stdout);
3142 fputs(schedline, stderr);
3159 size = internal_server_estimate(dp, info, level, &stats);
3161 est(dp)->dump_est = &est(dp)->estimate[i];
3162 est(dp)->estimate[i].nsize = size;
3164 est(dp)->estimate[i].guessed = 1;