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,v 1.180 2006/03/10 13:51:06 martinea Exp $
29 * backup schedule planner for the Amanda backup system.
43 #include "amfeatures.h"
44 #include "server_util.h"
47 #define MAX_LEVELS 3 /* max# of estimates per filesys */
49 #define RUNS_REDZONE 5 /* should be in conf file? */
51 #define PROMOTE_THRESHOLD 0.05 /* if <5% unbalanced, don't promote */
52 #define DEFAULT_DUMPRATE 1024.0 /* K/s */
54 /* configuration file stuff */
57 am64_t conf_maxdumpsize;
60 int conf_runspercycle;
66 #define HOST_READY ((void *)0) /* must be 0 */
67 #define HOST_ACTIVE ((void *)1)
68 #define HOST_DONE ((void *)2)
70 #define DISK_READY 0 /* must be 0 */
72 #define DISK_PARTIALY_DONE 2
75 typedef struct est_s {
81 int degr_level; /* if dump_level == 0, what would be the inc level */
88 double fullrate, incrrate;
89 double fullcomp, incrcomp;
91 int level[MAX_LEVELS];
92 char *dumpdate[MAX_LEVELS];
93 long est_size[MAX_LEVELS];
96 #define est(dp) ((est_t *)(dp)->up)
98 /* pestq = partial estimate */
99 disklist_t startq, waitq, pestq, estq, failq, schedq;
101 double total_lev0, balanced_size, balance_threshold;
102 am64_t tape_length, tape_mark;
106 long tt_blocksize_kb;
107 int runs_per_cycle = 0;
109 char *datestamp = NULL;
111 static am_feature_t *our_features = NULL;
112 static char *our_feature_string = NULL;
114 /* We keep a LIFO queue of before images for all modifications made
115 * to schedq in our attempt to make the schedule fit on the tape.
116 * Enough information is stored to reinstate a dump if it turns out
117 * that it shouldn't have been touched after all.
119 typedef struct bi_s {
122 int deleted; /* 0=modified, 1=deleted */
123 disk_t *dp; /* The disk that was changed */
124 int level; /* The original level */
125 long size; /* The original size */
126 char *errstr; /* A message describing why this disk is here */
129 typedef struct bilist_s {
133 bilist_t biq; /* The BI queue itself */
136 * ========================================================================
141 static void setup_estimate P((disk_t *dp));
142 static void get_estimates P((void));
143 static void analyze_estimate P((disk_t *dp));
144 static void handle_failed P((disk_t *dp));
145 static void delay_dumps P((void));
146 static int promote_highest_priority_incremental P((void));
147 static int promote_hills P((void));
148 static void output_scheduleline P((disk_t *dp));
149 int main P((int, char **));
158 unsigned long malloc_hist_1, malloc_size_1;
159 unsigned long malloc_hist_2, malloc_size_2;
166 times_t section_start;
170 setvbuf(stderr, (char *)NULL, _IOLBF, 0);
173 config_name = stralloc(argv[1]);
174 config_dir = vstralloc(CONFIG_DIR, "/", config_name, "/", NULL);
176 char my_cwd[STR_SIZE];
178 if (getcwd(my_cwd, sizeof(my_cwd)) == NULL) {
179 error("cannot determine current working directory");
181 config_dir = stralloc2(my_cwd, "/");
182 if ((config_name = strrchr(my_cwd, '/')) != NULL) {
183 config_name = stralloc(config_name + 1);
189 set_pname("planner");
191 /* Don't die when child closes pipe */
192 signal(SIGPIPE, SIG_IGN);
194 malloc_size_1 = malloc_inuse(&malloc_hist_1);
196 erroutput_type = (ERR_AMANDALOG|ERR_INTERACTIVE);
197 set_logerror(logerror);
199 section_start = curclock();
201 our_features = am_init_feature_set();
202 our_feature_string = am_feature_to_string(our_features);
204 fprintf(stderr, "%s: pid %ld executable %s version %s\n",
205 get_pname(), (long) getpid(), argv[0], version());
206 for (i = 0; version_info[i] != NULL; i++)
207 fprintf(stderr, "%s: %s", get_pname(), version_info[i]);
210 * 1. Networking Setup
212 * Planner runs setuid to get a priviledged socket for BSD security.
213 * We get the socket right away as root, then setuid back to a normal
214 * user. If we are not using BSD security, planner is not installed
221 uid_t ruid = getuid();
228 * From this point on we are running under our real uid, so we don't
229 * have to worry about opening security holes below. Make sure we
233 if(getpwuid(getuid()) == NULL)
234 error("can't get login name for my uid %ld", (long)getuid());
237 * 2. Read in Configuration Information
239 * All the Amanda configuration files are loaded before we begin.
242 fprintf(stderr,"READING CONF FILES...\n");
244 conffile = stralloc2(config_dir, CONFFILE_NAME);
245 if(read_conffile(conffile)) {
246 error("errors processing config file \"%s\"", conffile);
250 conf_diskfile = getconf_str(CNF_DISKFILE);
251 if (*conf_diskfile == '/') {
252 conf_diskfile = stralloc(conf_diskfile);
254 conf_diskfile = stralloc2(config_dir, conf_diskfile);
256 if (read_diskfile(conf_diskfile, &origq) < 0) {
257 error("could not load disklist \"%s\"", conf_diskfile);
259 match_disklist(&origq, argc-2, argv+2);
260 for(dp = origq.head; dp != NULL; dp = dp->next) {
262 log_add(L_DISK, "%s %s", dp->host->hostname, dp->name);
264 amfree(conf_diskfile);
266 conf_tapelist = getconf_str(CNF_TAPELIST);
267 if (*conf_tapelist == '/') {
268 conf_tapelist = stralloc(conf_tapelist);
270 conf_tapelist = stralloc2(config_dir, conf_tapelist);
272 if(read_tapelist(conf_tapelist)) {
273 error("could not load tapelist \"%s\"", conf_tapelist);
275 amfree(conf_tapelist);
277 conf_infofile = getconf_str(CNF_INFOFILE);
278 if (*conf_infofile == '/') {
279 conf_infofile = stralloc(conf_infofile);
281 conf_infofile = stralloc2(config_dir, conf_infofile);
283 if(open_infofile(conf_infofile)) {
284 error("could not open info db \"%s\"", conf_infofile);
286 amfree(conf_infofile);
288 conf_tapetype = getconf_str(CNF_TAPETYPE);
289 conf_maxdumpsize = getconf_am64(CNF_MAXDUMPSIZE);
290 conf_runtapes = getconf_int(CNF_RUNTAPES);
291 conf_dumpcycle = getconf_int(CNF_DUMPCYCLE);
292 conf_runspercycle = getconf_int(CNF_RUNSPERCYCLE);
293 conf_tapecycle = getconf_int(CNF_TAPECYCLE);
294 conf_etimeout = getconf_int(CNF_ETIMEOUT);
295 conf_reserve = getconf_int(CNF_RESERVE);
296 conf_autoflush = getconf_int(CNF_AUTOFLUSH);
300 datestamp = construct_datestamp(NULL);
301 log_add(L_START, "date %s", datestamp);
303 /* some initializations */
305 if(conf_runspercycle == 0) {
306 runs_per_cycle = conf_dumpcycle;
307 } else if(conf_runspercycle == -1 ) {
308 runs_per_cycle = guess_runs_from_tapelist();
310 runs_per_cycle = conf_runspercycle;
312 if (runs_per_cycle <= 0) {
317 * do some basic sanity checking
319 if(conf_tapecycle <= runs_per_cycle) {
320 log_add(L_WARNING, "tapecycle (%d) <= runspercycle (%d)",
321 conf_tapecycle, runs_per_cycle);
324 tape = lookup_tapetype(conf_tapetype);
325 if(conf_maxdumpsize > 0) {
326 tape_length = conf_maxdumpsize;
329 tape_length = tape->length * conf_runtapes;
331 tape_mark = tape->filemark;
332 tt_blocksize_kb = tape->blocksize;
333 tt_blocksize = tt_blocksize_kb * 1024;
335 fprintf(stderr, "%s: time %s: startup took %s secs\n",
337 walltime_str(curclock()),
338 walltime_str(timessub(curclock(), section_start)));
341 * 3. Send autoflush dumps left on the holding disks
343 * This should give us something to do while we generate the new
347 fprintf(stderr,"\nSENDING FLUSHES...\n");
353 holding_list = get_flush(NULL, NULL, 0, 0);
354 for(holding_file=holding_list->first; holding_file != NULL;
355 holding_file = holding_file->next) {
356 get_dumpfile(holding_file->name, &file);
358 log_add(L_DISK, "%s %s", file.name, file.disk);
360 "FLUSH %s %s %s %d %s\n",
367 "FLUSH %s %s %s %d %s\n",
374 free_sl(holding_list);
377 fprintf(stderr, "ENDFLUSH\n");
378 fprintf(stdout, "ENDFLUSH\n");
382 * 4. Calculate Preliminary Dump Levels
384 * Before we can get estimates from the remote slave hosts, we make a
385 * first attempt at guessing what dump levels we will be dumping at
386 * based on the curinfo database.
389 fprintf(stderr,"\nSETTING UP FOR ESTIMATES...\n");
390 section_start = curclock();
392 startq.head = startq.tail = NULL;
393 while(!empty(origq)) {
394 disk_t *dp = dequeue_disk(&origq);
400 fprintf(stderr, "%s: time %s: setting up estimates took %s secs\n",
402 walltime_str(curclock()),
403 walltime_str(timessub(curclock(), section_start)));
407 * 5. Get Dump Size Estimates from Remote Client Hosts
409 * Each host is queried (in parallel) for dump size information on all
410 * of its disks, and the results gathered as they come in.
413 /* go out and get the dump estimates */
415 fprintf(stderr,"\nGETTING ESTIMATES...\n");
416 section_start = curclock();
418 estq.head = estq.tail = NULL;
419 pestq.head = pestq.tail = NULL;
420 waitq.head = waitq.tail = NULL;
421 failq.head = failq.tail = NULL;
425 fprintf(stderr, "%s: time %s: getting estimates took %s secs\n",
427 walltime_str(curclock()),
428 walltime_str(timessub(curclock(), section_start)));
431 * At this point, all disks with estimates are in estq, and
432 * all the disks on hosts that didn't respond to our inquiry
436 dump_queue("FAILED", failq, 15, stderr);
437 dump_queue("DONE", estq, 15, stderr);
441 * 6. Analyze Dump Estimates
443 * Each disk's estimates are looked at to determine what level it
444 * should dump at, and to calculate the expected size and time taking
445 * historical dump rates and compression ratios into account. The
446 * total expected size is accumulated as well.
449 fprintf(stderr,"\nANALYZING ESTIMATES...\n");
450 section_start = curclock();
452 /* an empty tape still has a label and an endmark */
453 total_size = (tt_blocksize_kb + tape_mark) * 2;
457 schedq.head = schedq.tail = NULL;
458 while(!empty(estq)) analyze_estimate(dequeue_disk(&estq));
459 while(!empty(failq)) handle_failed(dequeue_disk(&failq));
462 * At this point, all the disks are on schedq sorted by priority.
463 * The total estimated size of the backups is in total_size.
469 fprintf(stderr, "INITIAL SCHEDULE (size " AM64_FMT "):\n", total_size);
470 for(dp = schedq.head; dp != NULL; dp = dp->next) {
471 fprintf(stderr, " %s %s pri %d lev %d size %ld\n",
472 dp->host->hostname, dp->name, est(dp)->dump_priority,
473 est(dp)->dump_level, est(dp)->dump_size);
479 * 7. Delay Dumps if Schedule Too Big
481 * If the generated schedule is too big to fit on the tape, we need to
482 * delay some full dumps to make room. Incrementals will be done
483 * instead (except for new or forced disks).
485 * In extreme cases, delaying all the full dumps is not even enough.
486 * If so, some low-priority incrementals will be skipped completely
487 * until the dumps fit on the tape.
491 "\nDELAYING DUMPS IF NEEDED, total_size " AM64_FMT ", tape length " AM64_FMT " mark " AM64_FMT "\n",
492 total_size, tape_length, tape_mark);
494 initial_size = total_size;
498 /* XXX - why bother checking this? */
499 if(empty(schedq) && total_size < initial_size)
500 error("cannot fit anything on tape, bailing out");
504 * 8. Promote Dumps if Schedule Too Small
506 * Amanda attempts to balance the full dumps over the length of the
507 * dump cycle. If this night's full dumps are too small relative to
508 * the other nights, promote some high-priority full dumps that will be
509 * due for the next run, to full dumps for tonight, taking care not to
510 * overflow the tape size.
512 * This doesn't work too well for small sites. For these we scan ahead
513 * looking for nights that have an excessive number of dumps and promote
516 * Amanda never delays full dumps just for the sake of balancing the
517 * schedule, so it can take a full cycle to balance the schedule after
522 "\nPROMOTING DUMPS IF NEEDED, total_lev0 %1.0f, balanced_size %1.0f...\n",
523 total_lev0, balanced_size);
525 balance_threshold = balanced_size * PROMOTE_THRESHOLD;
527 while((balanced_size - total_lev0) > balance_threshold && moved_one)
528 moved_one = promote_highest_priority_incremental();
530 moved_one = promote_hills();
532 fprintf(stderr, "%s: time %s: analysis took %s secs\n",
534 walltime_str(curclock()),
535 walltime_str(timessub(curclock(), section_start)));
541 * The schedule goes to stdout, presumably to driver. A copy is written
542 * on stderr for the debug file.
545 fprintf(stderr,"\nGENERATING SCHEDULE:\n--------\n");
547 while(!empty(schedq)) output_scheduleline(dequeue_disk(&schedq));
548 fprintf(stderr, "--------\n");
551 log_add(L_FINISH, "date %s time %s", datestamp, walltime_str(curclock()));
556 amfree(our_feature_string);
557 am_release_feature_set(our_features);
560 malloc_size_2 = malloc_inuse(&malloc_hist_2);
562 if(malloc_size_1 != malloc_size_2) {
563 malloc_list(fileno(stderr), malloc_hist_1, malloc_hist_2);
572 * ========================================================================
573 * SETUP FOR ESTIMATES
577 static void askfor P((est_t *, int, int, info_t *));
578 static int last_level P((info_t *info)); /* subroutines */
579 static long est_size P((disk_t *dp, int level));
580 static long est_tape_size P((disk_t *dp, int level));
581 static int next_level0 P((disk_t *dp, info_t *info));
582 static int runs_at P((info_t *info, int lev));
583 static long bump_thresh P((int level, long size_level_0, int bumppercent, int bumpsize, double bumpmult));
584 static int when_overwrite P((char *label));
586 static void askfor(ep, seq, lev, info)
587 est_t *ep; /* esimate data block */
588 int seq; /* sequence number of request */
589 int lev; /* dump level being requested */
590 info_t *info; /* info block for disk */
592 if(seq < 0 || seq >= MAX_LEVELS) {
593 error("error [planner askfor: seq out of range 0..%d: %d]",
596 if(lev < -1 || lev >= DUMP_LEVELS) {
597 error("error [planner askfor: lev out of range -1..%d: %d]",
603 ep->dumpdate[seq] = (char *)0;
604 ep->est_size[seq] = -2;
608 ep->level[seq] = lev;
610 ep->dumpdate[seq] = stralloc(get_dumpdate(info,lev));
611 malloc_mark(ep->dumpdate[seq]);
613 ep->est_size[seq] = -2;
626 assert(dp && dp->host);
627 fprintf(stderr, "%s: time %s: setting up estimates for %s:%s\n",
628 get_pname(), walltime_str(curclock()),
629 dp->host->hostname, dp->name);
631 /* get current information about disk */
633 if(get_info(dp->host->hostname, dp->name, &info)) {
634 /* no record for this disk, make a note of it */
635 log_add(L_INFO, "Adding new disk %s:%s.", dp->host->hostname, dp->name);
638 /* setup working data struct for disk */
640 ep = alloc(sizeof(est_t));
642 dp->up = (void *) ep;
643 ep->state = DISK_READY;
645 ep->dump_priority = dp->priority;
649 /* calculated fields */
651 if (ISSET(info.command, FORCE_FULL)) {
652 /* force a level 0, kind of like a new disk */
653 if(dp->strategy == DS_NOFULL) {
655 * XXX - Not sure what it means to force a no-full disk. The
656 * purpose of no-full is to just dump changes relative to a
657 * stable base, for example root partitions that vary only
658 * slightly from a site-wide prototype. Only the variations
661 * If we allow a level 0 onto the Amanda cycle, then we are
662 * hosed when that tape gets re-used next. Disallow this for
666 "Cannot force full dump of %s:%s with no-full option.",
667 dp->host->hostname, dp->name);
669 /* clear force command */
670 CLR(info.command, FORCE_FULL);
671 if(put_info(dp->host->hostname, dp->name, &info))
672 error("could not put info record for %s:%s: %s",
673 dp->host->hostname, dp->name, strerror(errno));
674 ep->last_level = last_level(&info);
675 ep->next_level0 = next_level0(dp, &info);
679 ep->next_level0 = -conf_dumpcycle;
680 log_add(L_INFO, "Forcing full dump of %s:%s as directed.",
681 dp->host->hostname, dp->name);
684 else if(dp->strategy == DS_NOFULL) {
685 /* force estimate of level 1 */
687 ep->next_level0 = next_level0(dp, &info);
690 ep->last_level = last_level(&info);
691 ep->next_level0 = next_level0(dp, &info);
694 /* adjust priority levels */
696 if(ep->next_level0 < 0) {
697 fprintf(stderr,"%s:%s overdue %d day%s for level 0\n",
698 dp->host->hostname, dp->name,
699 - ep->next_level0, ((- ep->next_level0) == 1) ? "" : "s");
700 ep->dump_priority -= ep->next_level0;
701 /* warn if dump will be overwritten */
702 if(ep->last_level > -1) {
703 int overwrite_runs = when_overwrite(info.inf[0].label);
704 if(overwrite_runs == 0) {
706 "Last full dump of %s:%s on tape %s overwritten on this run.",
707 dp->host->hostname, dp->name, info.inf[0].label);
709 else if(overwrite_runs < RUNS_REDZONE) {
711 "Last full dump of %s:%s on tape %s overwritten in %d run%s.",
712 dp->host->hostname, dp->name, info.inf[0].label,
713 overwrite_runs, overwrite_runs == 1? "" : "s");
717 else if (ISSET(info.command, FORCE_FULL))
718 ep->dump_priority += 1;
719 /* else XXX bump up the priority of incrementals that failed last night */
721 /* handle external level 0 dumps */
723 if(dp->skip_full && dp->strategy != DS_NOINC) {
724 if(ep->next_level0 <= 0) {
725 /* update the date field */
726 info.inf[0].date = today;
727 CLR(info.command, FORCE_FULL);
728 ep->next_level0 += conf_dumpcycle;
730 if(put_info(dp->host->hostname, dp->name, &info))
731 error("could not put info record for %s:%s: %s",
732 dp->host->hostname, dp->name, strerror(errno));
733 log_add(L_INFO, "Skipping full dump of %s:%s today.",
734 dp->host->hostname, dp->name);
735 fprintf(stderr,"%s:%s lev 0 skipped due to skip-full flag\n",
736 dp->host->hostname, dp->name);
737 /* don't enqueue the disk */
738 askfor(ep, 0, -1, &info);
739 askfor(ep, 1, -1, &info);
740 askfor(ep, 2, -1, &info);
741 fprintf(stderr, "%s: SKIPPED %s %s 0 [skip-full]\n",
742 get_pname(), dp->host->hostname, dp->name);
743 log_add(L_SUCCESS, "%s %s %s 0 [skipped: skip-full]",
744 dp->host->hostname, dp->name, datestamp);
748 if(ep->last_level == -1) {
749 /* probably a new disk, but skip-full means no full! */
753 if(ep->next_level0 == 1) {
754 log_add(L_WARNING, "Skipping full dump of %s:%s tomorrow.",
755 dp->host->hostname, dp->name);
759 if(dp->strategy == DS_INCRONLY && ep->last_level == -1 && !ISSET(info.command, FORCE_FULL)) {
760 /* don't enqueue the disk */
761 askfor(ep, 0, -1, &info);
762 askfor(ep, 1, -1, &info);
763 askfor(ep, 2, -1, &info);
764 log_add(L_FAIL, "%s %s 19000101 1 [Skipping incronly because no full dump were done]",
765 dp->host->hostname, dp->name);
766 fprintf(stderr,"%s:%s lev 1 skipped due to strategy incronly and no full dump were done\n",
767 dp->host->hostname, dp->name);
771 /* handle "skip-incr" type archives */
773 if(dp->skip_incr && ep->next_level0 > 0) {
774 fprintf(stderr,"%s:%s lev 1 skipped due to skip-incr flag\n",
775 dp->host->hostname, dp->name);
776 /* don't enqueue the disk */
777 askfor(ep, 0, -1, &info);
778 askfor(ep, 1, -1, &info);
779 askfor(ep, 2, -1, &info);
781 fprintf(stderr, "%s: SKIPPED %s %s 1 [skip-incr]\n",
782 get_pname(), dp->host->hostname, dp->name);
784 log_add(L_SUCCESS, "%s %s %s 1 [skipped: skip-incr]",
785 dp->host->hostname, dp->name, datestamp);
789 if( ep->last_level == -1 && ep->next_level0 > 0 &&
790 dp->strategy != DS_NOFULL && dp->strategy != DS_INCRONLY &&
791 conf_reserve == 100) {
793 "%s:%s mismatch: no tapelist record, but curinfo next_level0: %d.",
794 dp->host->hostname, dp->name, ep->next_level0);
798 if(ep->last_level == 0) ep->level_days = 0;
799 else ep->level_days = runs_at(&info, ep->last_level);
800 ep->last_lev0size = info.inf[0].csize;
802 ep->fullrate = perf_average(info.full.rate, 0.0);
803 ep->incrrate = perf_average(info.incr.rate, 0.0);
805 ep->fullcomp = perf_average(info.full.comp, dp->comprate[0]);
806 ep->incrcomp = perf_average(info.incr.comp, dp->comprate[1]);
808 /* determine which estimates to get */
812 if (dp->strategy == DS_NOINC ||
814 (!ISSET(info.command, FORCE_BUMP) ||
816 ep->last_level == -1))) {
817 if(info.command & FORCE_BUMP && ep->last_level == -1) {
819 "Remove force-bump command of %s:%s because it's a new disk.",
820 dp->host->hostname, dp->name);
822 switch (dp->strategy) {
825 askfor(ep, i++, 0, &info);
828 "Ignoring skip_full for %s:%s because the strategy is NOINC.",
829 dp->host->hostname, dp->name);
831 if(info.command & FORCE_BUMP) {
833 "Ignoring FORCE_BUMP for %s:%s because the strategy is NOINC.",
834 dp->host->hostname, dp->name);
843 if (ISSET(info.command, FORCE_FULL))
844 askfor(ep, i++, 0, &info);
849 if(!dp->skip_incr && !(dp->strategy == DS_NOINC)) {
850 if(ep->last_level == -1) { /* a new disk */
851 if(dp->strategy == DS_NOFULL || dp->strategy == DS_INCRONLY) {
852 askfor(ep, i++, 1, &info);
854 assert(!dp->skip_full); /* should be handled above */
856 } else { /* not new, pick normally */
859 curr_level = ep->last_level;
861 if (ISSET(info.command, FORCE_NO_BUMP)) {
862 if(curr_level > 0) { /* level 0 already asked for */
863 askfor(ep, i++, curr_level, &info);
865 log_add(L_INFO,"Preventing bump of %s:%s as directed.",
866 dp->host->hostname, dp->name);
867 } else if (ISSET(info.command, FORCE_BUMP)
868 && curr_level + 1 < DUMP_LEVELS) {
869 askfor(ep, i++, curr_level+1, &info);
870 log_add(L_INFO,"Bumping of %s:%s at level %d as directed.",
871 dp->host->hostname, dp->name, curr_level+1);
872 } else if (curr_level == 0) {
873 askfor(ep, i++, 1, &info);
875 askfor(ep, i++, curr_level, &info);
877 * If last time we dumped less than the threshold, then this
878 * time we will too, OR the extra size will be charged to both
879 * cur_level and cur_level + 1, so we will never bump. Also,
880 * if we haven't been at this level 2 days, or the dump failed
881 * last night, we can't bump.
883 if((info.inf[curr_level].size == 0 || /* no data, try it anyway */
884 (((info.inf[curr_level].size > bump_thresh(curr_level, info.inf[0].size,dp->bumppercent, dp->bumpsize, dp->bumpmult)))
885 && ep->level_days >= dp->bumpdays))
886 && curr_level + 1 < DUMP_LEVELS) {
887 askfor(ep, i++, curr_level+1, &info);
893 while(i < MAX_LEVELS) /* mark end of estimates */
894 askfor(ep, i++, -1, &info);
898 fprintf(stderr, "setup_estimate: %s:%s: command %d, options: %s last_level %d next_level0 %d level_days %d getting estimates %d (%ld) %d (%ld) %d (%ld)\n",
899 dp->host->hostname, dp->name, info.command,
900 dp->strategy == DS_NOFULL ? "no-full" :
901 dp->strategy == DS_INCRONLY ? "incr-only" :
902 dp->skip_full ? "skip-full" :
903 dp->skip_incr ? "skip-incr" : "none",
904 ep->last_level, ep->next_level0, ep->level_days,
905 ep->level[0], ep->est_size[0],
906 ep->level[1], ep->est_size[1],
907 ep->level[2], ep->est_size[2]);
909 assert(ep->level[0] != -1);
910 enqueue_disk(&startq, dp);
913 static int when_overwrite(label)
918 if((tp = lookup_tapelabel(label)) == NULL)
919 return 1; /* "shouldn't happen", but trigger warning message */
920 else if(!reusable_tape(tp))
922 else if(lookup_nb_tape() > conf_tapecycle)
923 return (lookup_nb_tape() - tp->position) / conf_runtapes;
925 return (conf_tapecycle - tp->position) / conf_runtapes;
928 /* Return the estimated size for a particular dump */
929 static long est_size(dp, level)
935 for(i = 0; i < MAX_LEVELS; i++) {
936 if(level == est(dp)->level[i])
937 return est(dp)->est_size[i];
942 /* Return the estimated on-tape size of a particular dump */
943 static long est_tape_size(dp, level)
950 size = est_size(dp, level);
952 if(size == -1) return size;
954 if(dp->compress == COMP_NONE)
957 if(level == 0) ratio = est(dp)->fullcomp;
958 else ratio = est(dp)->incrcomp;
961 * make sure over-inflated compression ratios don't throw off the
962 * estimates, this is mostly for when you have a small dump getting
963 * compressed which takes up alot more disk/tape space relatively due
964 * to the overhead of the compression. This is specifically for
965 * Digital Unix vdump. This patch is courtesy of Rudolf Gabler
966 * (RUG@USM.Uni-Muenchen.DE)
969 if(ratio > 1.1) ratio = 1.1;
974 * Ratio can be very small in some error situations, so make sure
975 * size goes back greater than zero. It may not be right, but
976 * indicates we did get an estimate.
986 /* what was the level of the last successful dump to tape? */
987 static int last_level(info)
990 int min_pos, min_level, i;
991 time_t lev0_date, last_date;
994 if(info->last_level != -1)
995 return info->last_level;
997 /* to keep compatibility with old infofile */
998 min_pos = 1000000000;
1002 for(i = 0; i < 9; i++) {
1003 if(conf_reserve < 100) {
1004 if(i == 0) lev0_date = info->inf[0].date;
1005 else if(info->inf[i].date < lev0_date) continue;
1006 if(info->inf[i].date > last_date) {
1007 last_date = info->inf[i].date;
1012 if((tp = lookup_tapelabel(info->inf[i].label)) == NULL) continue;
1013 /* cull any entries from previous cycles */
1014 if(i == 0) lev0_date = info->inf[0].date;
1015 else if(info->inf[i].date < lev0_date) continue;
1017 if(tp->position < min_pos) {
1018 min_pos = tp->position;
1023 info->last_level = i;
1027 /* when is next level 0 due? 0 = today, 1 = tomorrow, etc*/
1029 next_level0(dp, info)
1033 if(dp->strategy == DS_NOFULL || dp->strategy == DS_INCRONLY)
1034 return 1; /* fake it */
1035 else if (dp->strategy == DS_NOINC)
1037 else if(info->inf[0].date < (time_t)0)
1038 return -days_diff(EPOCH, today); /* new disk */
1040 return dp->dumpcycle - days_diff(info->inf[0].date, today);
1043 /* how many runs at current level? */
1044 static int runs_at(info, lev)
1048 tape_t *cur_tape, *old_tape;
1051 last = last_level(info);
1052 if(lev != last) return 0;
1053 if(lev == 0) return 1;
1055 if(info->consecutive_runs != -1)
1056 return info->consecutive_runs;
1058 /* to keep compatibility with old infofile */
1059 cur_tape = lookup_tapelabel(info->inf[lev].label);
1060 old_tape = lookup_tapelabel(info->inf[lev-1].label);
1061 if(cur_tape == NULL || old_tape == NULL) return 0;
1063 nb_runs = (old_tape->position - cur_tape->position) / conf_runtapes;
1064 info->consecutive_runs = nb_runs;
1070 static long bump_thresh(level, size_level_0, bumppercent, bumpsize, bumpmult)
1079 if(bumppercent != 0 && size_level_0 > 1024) {
1080 bump = (size_level_0 * bumppercent)/100.0;
1085 while(--level) bump = bump * bumpmult;
1093 * ========================================================================
1094 * GET REMOTE DUMP SIZE ESTIMATES
1098 static void getsize P((am_host_t *hostp));
1099 static disk_t *lookup_hostdisk P((am_host_t *hp, char *str));
1100 static void handle_result P((void *datap, pkt_t *pkt, security_handle_t *sech));
1103 static void get_estimates P((void))
1107 int something_started;
1109 something_started = 1;
1110 while(something_started) {
1111 something_started = 0;
1112 for(dp = startq.head; dp != NULL; dp = dp->next) {
1114 if(hostp->up == HOST_READY) {
1115 something_started = 1;
1119 * dp is no longer on startq, so dp->next is not valid
1120 * and we have to start all over.
1128 while(!empty(waitq)) {
1129 disk_t *dp = dequeue_disk(&waitq);
1130 est(dp)->errstr = "hmm, disk was stranded on waitq";
1131 enqueue_disk(&failq, dp);
1134 while(!empty(pestq)) {
1135 disk_t *dp = dequeue_disk(&pestq);
1137 if(est(dp)->level[0] != -1 && est(dp)->est_size[0] < 0) {
1138 if(est(dp)->est_size[0] == -1) {
1140 "disk %s:%s, estimate of level %d failed.",
1141 dp->host->hostname, dp->name,
1146 "disk %s:%s, estimate of level %d timed out.",
1147 dp->host->hostname, dp->name,
1150 est(dp)->level[0] = -1;
1153 if(est(dp)->level[1] != -1 && est(dp)->est_size[1] < 0) {
1154 if(est(dp)->est_size[1] == -1) {
1156 "disk %s:%s, estimate of level %d failed.",
1157 dp->host->hostname, dp->name,
1162 "disk %s:%s, estimate of level %d timed out.",
1163 dp->host->hostname, dp->name,
1166 est(dp)->level[1] = -1;
1169 if(est(dp)->level[2] != -1 && est(dp)->est_size[2] < 0) {
1170 if(est(dp)->est_size[2] == -1) {
1172 "disk %s:%s, estimate of level %d failed.",
1173 dp->host->hostname, dp->name,
1178 "disk %s:%s, estimate of level %d timed out.",
1179 dp->host->hostname, dp->name,
1182 est(dp)->level[2] = -1;
1185 if((est(dp)->level[0] != -1 && est(dp)->est_size[0] > 0) ||
1186 (est(dp)->level[1] != -1 && est(dp)->est_size[1] > 0) ||
1187 (est(dp)->level[2] != -1 && est(dp)->est_size[2] > 0)) {
1188 enqueue_disk(&estq, dp);
1191 est(dp)->errstr = vstralloc("disk ", dp->name,
1192 ", all estimate timed out", NULL);
1193 enqueue_disk(&failq, dp);
1198 static void getsize(hostp)
1201 char number[NUM_STR_SIZE], *req;
1203 int i, estimates, timeout, req_len;
1204 const security_driver_t *secdrv;
1208 assert(hostp->disks != NULL);
1210 if(hostp->up != HOST_READY) {
1215 * The first time through here we send a "noop" request. This will
1216 * return the feature list from the client if it supports that.
1217 * If it does not, handle_result() will set the feature list to an
1218 * empty structure. In either case, we do the disks on the second
1219 * (and subsequent) pass(es).
1221 if(hostp->features != NULL) { /* sendsize service */
1225 int has_features = am_has_feature(hostp->features,
1226 fe_req_options_features);
1227 int has_hostname = am_has_feature(hostp->features,
1228 fe_req_options_hostname);
1229 int has_maxdumps = am_has_feature(hostp->features,
1230 fe_req_options_maxdumps);
1232 snprintf(number, sizeof(number), "%d", hostp->maxdumps);
1233 req = vstralloc("SERVICE ", "sendsize", "\n",
1235 has_features ? "features=" : "",
1236 has_features ? our_feature_string : "",
1237 has_features ? ";" : "",
1238 has_maxdumps ? "maxdumps=" : "",
1239 has_maxdumps ? number : "",
1240 has_maxdumps ? ";" : "",
1241 has_hostname ? "hostname=" : "",
1242 has_hostname ? hostp->hostname : "",
1243 has_hostname ? ";" : "",
1246 req_len = strlen(req);
1247 req_len += 128; /* room for SECURITY ... */
1249 for(dp = hostp->disks; dp != NULL; dp = dp->hostnext) {
1253 if(dp->todo == 0) continue;
1255 if(est(dp)->state != DISK_READY) continue;
1257 est(dp)->got_estimate = 0;
1258 if(est(dp)->level[0] == -1) {
1259 est(dp)->state = DISK_DONE;
1263 if(dp->estimate == ES_CLIENT ||
1264 dp->estimate == ES_CALCSIZE) {
1267 for(i = 0; i < MAX_LEVELS; i++) {
1269 char *exclude1 = "";
1270 char *exclude2 = "";
1271 char *excludefree = NULL;
1272 char spindle[NUM_STR_SIZE];
1273 char level[NUM_STR_SIZE];
1274 int lev = est(dp)->level[i];
1276 if(lev == -1) break;
1278 snprintf(level, sizeof(level), "%d", lev);
1279 snprintf(spindle, sizeof(spindle), "%d", dp->spindle);
1280 if(am_has_feature(hostp->features,fe_sendsize_req_options)){
1281 exclude1 = " OPTIONS |";
1282 exclude2 = optionstr(dp, hostp->features, NULL);
1283 excludefree = exclude2;
1286 if(dp->exclude_file &&
1287 dp->exclude_file->nb_element == 1) {
1288 exclude1 = " exclude-file=";
1289 exclude2 = dp->exclude_file->first->name;
1291 else if(dp->exclude_list &&
1292 dp->exclude_list->nb_element == 1) {
1293 exclude1 = " exclude-list=";
1294 exclude2 = dp->exclude_list->first->name;
1298 if(dp->estimate == ES_CALCSIZE &&
1299 !am_has_feature(hostp->features, fe_calcsize_estimate)) {
1300 log_add(L_WARNING,"%s:%s does not support CALCSIZE for estimate, using CLIENT.\n",
1301 hostp->hostname, dp->name);
1302 dp->estimate = ES_CLIENT;
1304 if(dp->estimate == ES_CLIENT)
1307 calcsize = "CALCSIZE ";
1309 if(strncmp(dp->program,"DUMP",4) == 0 ||
1310 strncmp(dp->program,"GNUTAR",6) == 0) {
1315 l = vstralloc(calcsize,
1319 " ", dp->device ? dp->device : "",
1321 " ", est(dp)->dumpdate[i],
1323 " ", exclude1, exclude2,
1329 amfree(excludefree);
1332 * Allow 2X for err response.
1334 if(req_len + s_len > MAX_PACKET / 2) {
1344 est(dp)->state = DISK_ACTIVE;
1345 remove_disk(&startq, dp);
1347 else if (dp->estimate == ES_SERVER) {
1350 get_info(dp->host->hostname, dp->name, &info);
1351 for(i = 0; i < MAX_LEVELS; i++) {
1353 int lev = est(dp)->level[i];
1355 if(lev == -1) break;
1356 if(lev == 0) { /* use latest level 0, should do extrapolation */
1360 for(j=NB_HISTORY-2;j>=0;j--) {
1361 if(info.history[j].level == 0) {
1362 if(info.history[j].size < 0) continue;
1363 est_size = info.history[j].size;
1368 est(dp)->est_size[i] = est_size;
1370 else if(info.inf[lev].size > 1000) { /* stats */
1371 est(dp)->est_size[i] = info.inf[lev].size;
1374 est(dp)->est_size[i] = 1000000;
1377 else if(lev == est(dp)->last_level) {
1378 /* means of all X day at the same level */
1381 long est_size_day[NB_DAY];
1382 int nb_est_day[NB_DAY];
1383 for(j=0;j<NB_DAY;j++) {
1388 for(j=NB_HISTORY-2;j>=0;j--) {
1389 if(info.history[j].level <= 0) continue;
1390 if(info.history[j].size < 0) continue;
1391 if(info.history[j].level==info.history[j+1].level) {
1392 if(nb_day <NB_DAY-1) nb_day++;
1393 est_size_day[nb_day] += info.history[j].size;
1394 nb_est_day[nb_day]++;
1400 nb_day = info.consecutive_runs + 1;
1401 if(nb_day > NB_DAY-1) nb_day = NB_DAY-1;
1403 while(nb_day > 0 && nb_est_day[nb_day] == 0) nb_day--;
1405 if(nb_est_day[nb_day] > 0) {
1406 est(dp)->est_size[i] =
1407 est_size_day[nb_day] / nb_est_day[nb_day];
1409 else if(info.inf[lev].size > 1000) { /* stats */
1410 est(dp)->est_size[i] = info.inf[lev].size;
1413 est(dp)->est_size[i] = 10000;
1416 else if(lev == est(dp)->last_level + 1) {
1417 /* means of all first day at a new level */
1421 for(j=NB_HISTORY-2;j>=0;j--) {
1422 if(info.history[j].level <= 0) continue;
1423 if(info.history[j].size < 0) continue;
1424 if(info.history[j].level == info.history[j+1].level + 1 ) {
1425 est_size += info.history[j].size;
1430 est(dp)->est_size[i] = est_size / nb_est;
1432 else if(info.inf[lev].size > 1000) { /* stats */
1433 est(dp)->est_size[i] = info.inf[lev].size;
1436 est(dp)->est_size[i] = 100000;
1440 fprintf(stderr,"%s time %s: got result for host %s disk %s:",
1441 get_pname(), walltime_str(curclock()),
1442 dp->host->hostname, dp->name);
1443 fprintf(stderr," %d -> %ldK, %d -> %ldK, %d -> %ldK\n",
1444 est(dp)->level[0], est(dp)->est_size[0],
1445 est(dp)->level[1], est(dp)->est_size[1],
1446 est(dp)->level[2], est(dp)->est_size[2]);
1447 est(dp)->state = DISK_DONE;
1448 remove_disk(&startq, dp);
1449 enqueue_disk(&estq, dp);
1453 if(estimates == 0) {
1455 hostp->up = HOST_DONE;
1459 if (conf_etimeout < 0) {
1460 timeout = - conf_etimeout;
1462 timeout = estimates * conf_etimeout;
1464 } else { /* noop service */
1465 req = vstralloc("SERVICE ", "noop", "\n",
1467 "features=", our_feature_string, ";",
1471 * We use ctimeout for the "noop" request because it should be
1472 * very fast and etimeout has other side effects.
1474 timeout = getconf_int(CNF_CTIMEOUT);
1477 secdrv = security_getdriver(hostp->disks->security_driver);
1478 if (secdrv == NULL) {
1479 error("could not find security driver '%s' for host '%s'",
1480 hostp->disks->security_driver, hostp->hostname);
1482 hostp->up = HOST_ACTIVE;
1484 for(dp = hostp->disks; dp != NULL; dp = dp->hostnext) {
1488 if(est(dp)->state == DISK_ACTIVE) {
1489 est(dp)->errstr = NULL;
1490 enqueue_disk(&waitq, dp);
1494 protocol_sendreq(hostp->hostname, secdrv, generic_get_security_conf,
1495 req, timeout, handle_result, hostp);
1499 static disk_t *lookup_hostdisk(hp, str)
1505 for(dp = hp->disks; dp != NULL; dp = dp->hostnext)
1506 if(strcmp(str, dp->name) == 0) return dp;
1512 static void handle_result(datap, pkt, sech)
1515 security_handle_t *sech;
1521 char *msgdisk=NULL, *msgdisk_undo=NULL, msgdisk_undo_ch = '\0';
1522 char *remoterr, *errbuf = NULL;
1530 hostp = (am_host_t *)datap;
1531 hostp->up = HOST_READY;
1534 errbuf = vstralloc("Request to ", hostp->hostname, " failed: ",
1535 security_geterror(sech), NULL);
1538 if (pkt->type == P_NAK) {
1540 if(strncmp(pkt->body, sc, sizeof(sc)-1) == 0) {
1541 s = pkt->body + sizeof(sc)-1;
1545 goto NAK_parse_failed;
1547 skip_whitespace(s, ch);
1548 if(ch == '\0') goto NAK_parse_failed;
1550 if((s = strchr(remoterr, '\n')) != NULL) {
1551 if(s == remoterr) goto NAK_parse_failed;
1554 if (strcmp(remoterr, "unknown service: noop") != 0
1555 && strcmp(remoterr, "noop: invalid service") != 0) {
1556 errbuf = vstralloc(hostp->hostname, " NAK: ", remoterr, NULL);
1562 msgdisk_undo = NULL;
1568 if (s[-2] == '\n') {
1572 #define sc "OPTIONS "
1573 if(strncmp(line, sc, sizeof(sc)-1) == 0) {
1576 #define sc "features="
1577 t = strstr(line, sc);
1578 if(t != NULL && (isspace((int)t[-1]) || t[-1] == ';')) {
1581 am_release_feature_set(hostp->features);
1582 if((hostp->features = am_string_to_feature(t)) == NULL) {
1583 errbuf = vstralloc(hostp->hostname,
1584 ": bad features value: ",
1596 if(strncmp(line, sc, sizeof(sc)-1) == 0) {
1597 t = line + sizeof(sc)-1;
1602 skip_whitespace(t, tch);
1607 * If the "error" is that the "noop" service is unknown, it
1608 * just means the client is "old" (does not support the servie).
1609 * We can ignore this.
1611 if(hostp->features == NULL
1612 && pkt->type == P_NAK
1613 && (strcmp(t - 1, "unknown service: noop") == 0
1614 || strcmp(t - 1, "noop: invalid service") == 0)) {
1617 errbuf = vstralloc(hostp->hostname,
1618 (pkt->type == P_NAK) ? "NAK " : "",
1628 skip_non_whitespace(t, tch);
1629 msgdisk_undo = t - 1;
1630 msgdisk_undo_ch = *msgdisk_undo;
1631 *msgdisk_undo = '\0';
1633 skip_whitespace(t, tch);
1634 if (sscanf(t - 1, "%d SIZE %ld", &level, &size) != 2) {
1638 dp = lookup_hostdisk(hostp, msgdisk);
1640 *msgdisk_undo = msgdisk_undo_ch; /* for error message */
1641 msgdisk_undo = NULL;
1644 log_add(L_ERROR, "%s: invalid reply from sendsize: `%s'\n",
1645 hostp->hostname, line);
1647 for(i = 0; i < MAX_LEVELS; i++) {
1648 if(est(dp)->level[i] == level) {
1649 est(dp)->est_size[i] = size;
1653 if(i == MAX_LEVELS) {
1654 goto bad_msg; /* this est wasn't requested */
1656 est(dp)->got_estimate++;
1660 if(hostp->up == HOST_READY && hostp->features == NULL) {
1662 * The client does not support the features list, so give it an
1665 dbprintf(("%s: no feature set from host %s\n",
1666 debug_prefix_time(NULL), hostp->hostname));
1667 hostp->features = am_set_default_feature_set();
1671 /* XXX what about disks that only got some estimates... do we care? */
1672 /* XXX amanda 2.1 treated that case as a bad msg */
1674 for(dp = hostp->disks; dp != NULL; dp = dp->hostnext) {
1675 if(dp->todo == 0) continue;
1676 if(est(dp)->state != DISK_ACTIVE &&
1677 est(dp)->state != DISK_PARTIALY_DONE) continue;
1679 if(est(dp)->state == DISK_ACTIVE) {
1680 remove_disk(&waitq, dp);
1682 else if(est(dp)->state == DISK_PARTIALY_DONE) {
1683 remove_disk(&pestq, dp);
1686 if(pkt->type == P_REP) {
1687 est(dp)->state = DISK_DONE;
1689 else if(pkt->type == P_PREP) {
1690 est(dp)->state = DISK_PARTIALY_DONE;
1693 if(est(dp)->level[0] == -1) continue; /* ignore this disk */
1696 if(pkt->type == P_PREP) {
1697 fprintf(stderr,"%s: time %s: got partial result for host %s disk %s:",
1698 get_pname(), walltime_str(curclock()),
1699 dp->host->hostname, dp->name);
1700 fprintf(stderr," %d -> %ldK, %d -> %ldK, %d -> %ldK\n",
1701 est(dp)->level[0], est(dp)->est_size[0],
1702 est(dp)->level[1], est(dp)->est_size[1],
1703 est(dp)->level[2], est(dp)->est_size[2]);
1704 enqueue_disk(&pestq, dp);
1706 else if(pkt->type == P_REP) {
1707 fprintf(stderr,"%s: time %s: got result for host %s disk %s:",
1708 get_pname(), walltime_str(curclock()),
1709 dp->host->hostname, dp->name);
1710 fprintf(stderr," %d -> %ldK, %d -> %ldK, %d -> %ldK\n",
1711 est(dp)->level[0], est(dp)->est_size[0],
1712 est(dp)->level[1], est(dp)->est_size[1],
1713 est(dp)->level[2], est(dp)->est_size[2]);
1714 if((est(dp)->level[0] != -1 && est(dp)->est_size[0] > 0) ||
1715 (est(dp)->level[1] != -1 && est(dp)->est_size[1] > 0) ||
1716 (est(dp)->level[2] != -1 && est(dp)->est_size[2] > 0)) {
1718 if(est(dp)->level[2] != -1 && est(dp)->est_size[2] < 0) {
1720 "disk %s:%s, estimate of level %d failed.",
1721 dp->host->hostname, dp->name,
1723 est(dp)->level[2] = -1;
1725 if(est(dp)->level[1] != -1 && est(dp)->est_size[1] < 0) {
1727 "disk %s:%s, estimate of level %d failed.",
1728 dp->host->hostname, dp->name,
1730 est(dp)->level[1] = -1;
1732 if(est(dp)->level[0] != -1 && est(dp)->est_size[0] < 0) {
1734 "disk %s:%s, estimate of level %d failed.",
1735 dp->host->hostname, dp->name,
1737 est(dp)->level[0] = -1;
1739 enqueue_disk(&estq, dp);
1742 enqueue_disk(&failq, dp);
1743 if(est(dp)->got_estimate) {
1744 est(dp)->errstr = vstralloc("disk ", dp->name,
1745 ", all estimate failed", NULL);
1748 fprintf(stderr, "error result for host %s disk %s: missing estimate\n",
1749 dp->host->hostname, dp->name);
1750 est(dp)->errstr = vstralloc("missing result for ", dp->name,
1751 " in ", dp->host->hostname,
1763 /* msgdisk_undo is always NULL */
1764 /* if(msgdisk_undo) { */
1765 /* *msgdisk_undo = msgdisk_undo_ch; */
1766 /* msgdisk_undo = NULL; */
1768 errbuf = stralloc2(hostp->hostname, " NAK: [NAK parse failed]");
1769 fprintf(stderr, "got strange nak from %s:\n----\n%s----\n\n",
1770 hostp->hostname, pkt->body);
1776 *msgdisk_undo = msgdisk_undo_ch;
1777 msgdisk_undo = NULL;
1779 fprintf(stderr,"got a bad message, stopped at:\n");
1780 fprintf(stderr,"----\n%s----\n\n", line);
1781 errbuf = stralloc2("badly formatted response from ", hostp->hostname);
1782 /* fall through to ... */
1787 for(dp = hostp->disks; dp != NULL; dp = dp->hostnext) {
1788 if(est(dp)->state != DISK_ACTIVE) continue;
1789 est(dp)->state = DISK_DONE;
1790 if(est(dp)->state == DISK_ACTIVE) {
1791 est(dp)->state = DISK_DONE;
1792 remove_disk(&waitq, dp);
1793 enqueue_disk(&failq, dp);
1796 est(dp)->errstr = stralloc(errbuf);
1797 fprintf(stderr, "error result for host %s disk %s: %s\n",
1798 dp->host->hostname, dp->name, errbuf);
1803 * If there were no disks involved, make sure the error gets
1806 log_add(L_ERROR, "%s", errbuf);
1808 hostp->up = HOST_DONE;
1816 * ========================================================================
1821 static int schedule_order P((disk_t *a, disk_t *b)); /* subroutines */
1822 static int pick_inclevel P((disk_t *dp));
1824 static void analyze_estimate(dp)
1833 fprintf(stderr, "pondering %s:%s... ",
1834 dp->host->hostname, dp->name);
1835 fprintf(stderr, "next_level0 %d last_level %d ",
1836 ep->next_level0, ep->last_level);
1838 if(get_info(dp->host->hostname, dp->name, &info) == 0) {
1842 ep->degr_level = -1;
1845 if(ep->next_level0 <= 0
1846 || (have_info && ep->last_level == 0 && (info.command & FORCE_NO_BUMP))) {
1847 if(ep->next_level0 <= 0) {
1848 fprintf(stderr,"(due for level 0) ");
1851 ep->dump_size = est_tape_size(dp, 0);
1852 if(ep->dump_size <= 0) {
1854 "(no estimate for level 0, picking an incr level)\n");
1855 ep->dump_level = pick_inclevel(dp);
1856 ep->dump_size = est_tape_size(dp, ep->dump_level);
1858 if(ep->dump_size == -1) {
1859 ep->dump_level = ep->dump_level + 1;
1860 ep->dump_size = est_tape_size(dp, ep->dump_level);
1864 total_lev0 += (double) ep->dump_size;
1865 if(ep->last_level == -1 || dp->skip_incr) {
1866 fprintf(stderr,"(%s disk, can't switch to degraded mode)\n",
1867 dp->skip_incr? "skip-incr":"new");
1868 ep->degr_level = -1;
1872 /* fill in degraded mode info */
1873 fprintf(stderr,"(picking inclevel for degraded mode)");
1874 ep->degr_level = pick_inclevel(dp);
1875 ep->degr_size = est_tape_size(dp, ep->degr_level);
1876 if(ep->degr_size == -1) {
1877 ep->degr_level = ep->degr_level + 1;
1878 ep->degr_size = est_tape_size(dp, ep->degr_level);
1880 if(ep->degr_size == -1) {
1881 fprintf(stderr,"(no inc estimate)");
1882 ep->degr_level = -1;
1884 fprintf(stderr,"\n");
1889 fprintf(stderr,"(not due for a full dump, picking an incr level)\n");
1890 /* XXX - if this returns -1 may be we should force a total? */
1891 ep->dump_level = pick_inclevel(dp);
1892 ep->dump_size = est_tape_size(dp, ep->dump_level);
1894 if(ep->dump_size == -1) {
1895 ep->dump_level = ep->last_level;
1896 ep->dump_size = est_tape_size(dp, ep->dump_level);
1898 if(ep->dump_size == -1) {
1899 ep->dump_level = ep->last_level + 1;
1900 ep->dump_size = est_tape_size(dp, ep->dump_level);
1902 if(ep->dump_size == -1) {
1904 ep->dump_size = est_tape_size(dp, ep->dump_level);
1908 fprintf(stderr," curr level %d size %ld ", ep->dump_level, ep->dump_size);
1910 insert_disk(&schedq, dp, schedule_order);
1912 total_size += tt_blocksize_kb + ep->dump_size + tape_mark;
1914 /* update the balanced size */
1915 if(!(dp->skip_full || dp->strategy == DS_NOFULL ||
1916 dp->strategy == DS_INCRONLY)) {
1919 lev0size = est_tape_size(dp, 0);
1920 if(lev0size == -1) lev0size = ep->last_lev0size;
1922 balanced_size += lev0size / runs_per_cycle;
1925 fprintf(stderr,"total size " AM64_FMT " total_lev0 %1.0f balanced-lev0size %1.0f\n",
1926 total_size, total_lev0, balanced_size);
1929 static void handle_failed(dp)
1935 * From George Scott <George.Scott@cc.monash.edu.au>:
1937 * If a machine is down when the planner is run it guesses from historical
1938 * data what the size of tonights dump is likely to be and schedules a
1939 * dump anyway. The dumper then usually discovers that that machine is
1940 * still down and ends up with a half full tape. Unfortunately the
1941 * planner had to delay another dump because it thought that the tape was
1942 * full. The fix here is for the planner to ignore unavailable machines
1943 * rather than ignore the fact that they are unavailable.
1948 if(est(dp)->last_level != -1) {
1950 "Could not get estimate for %s:%s, using historical data.",
1951 dp->host->hostname, dp->name);
1952 analyze_estimate(dp);
1957 errstr = est(dp)->errstr? est(dp)->errstr : "hmm, no error indicator!";
1959 fprintf(stderr, "%s: FAILED %s %s %s 0 [%s]\n",
1960 get_pname(), dp->host->hostname, dp->name, datestamp, errstr);
1962 log_add(L_FAIL, "%s %s %s 0 [%s]", dp->host->hostname, dp->name,
1965 /* XXX - memory leak with *dp */
1969 static int schedule_order(a, b)
1972 * insert-sort by decreasing priority, then
1973 * by decreasing size within priority levels.
1979 diff = est(b)->dump_priority - est(a)->dump_priority;
1980 if(diff != 0) return diff;
1982 ldiff = est(b)->dump_size - est(a)->dump_size;
1983 if(ldiff < 0) return -1; /* XXX - there has to be a better way to dothis */
1984 if(ldiff > 0) return 1;
1989 static int pick_inclevel(dp)
1992 int base_level, bump_level;
1993 long base_size, bump_size;
1996 base_level = est(dp)->last_level;
1998 /* if last night was level 0, do level 1 tonight, no ifs or buts */
1999 if(base_level == 0) {
2000 fprintf(stderr," picklev: last night 0, so tonight level 1\n");
2004 /* if no-full option set, always do level 1 */
2005 if(dp->strategy == DS_NOFULL) {
2006 fprintf(stderr," picklev: no-full set, so always level 1\n");
2010 base_size = est_size(dp, base_level);
2012 /* if we didn't get an estimate, we can't do an inc */
2013 if(base_size == -1) {
2014 base_size = est_size(dp, base_level+1);
2015 if(base_size > 0) /* FORCE_BUMP */
2016 return base_level+1;
2017 fprintf(stderr," picklev: no estimate for level %d, so no incs\n", base_level);
2021 thresh = bump_thresh(base_level, est_size(dp, 0), dp->bumppercent, dp->bumpsize, dp->bumpmult);
2024 " pick: size %ld level %d days %d (thresh %ldK, %d days)\n",
2025 base_size, base_level, est(dp)->level_days,
2026 thresh, dp->bumpdays);
2029 || est(dp)->level_days < dp->bumpdays
2030 || base_size <= thresh)
2033 bump_level = base_level + 1;
2034 bump_size = est_size(dp, bump_level);
2036 if(bump_size == -1) return base_level;
2038 fprintf(stderr, " pick: next size %ld... ", bump_size);
2040 if(base_size - bump_size < thresh) {
2041 fprintf(stderr, "not bumped\n");
2045 fprintf(stderr, "BUMPED\n");
2046 log_add(L_INFO, "Incremental of %s:%s bumped to level %d.",
2047 dp->host->hostname, dp->name, bump_level);
2056 ** ========================================================================
2059 ** We have two strategies here:
2063 ** If we are trying to fit too much on the tape something has to go. We
2064 ** try to delay totals until tomorrow by converting them into incrementals
2065 ** and, if that is not effective enough, dropping incrementals altogether.
2066 ** While we are searching for the guilty dump (the one that is really
2067 ** causing the schedule to be oversize) we have probably trampled on a lot of
2068 ** innocent dumps, so we maintain a "before image" list and use this to
2069 ** put back what we can.
2071 ** 2. Promote dumps.
2073 ** We try to keep the amount of tape used by total dumps the same each night.
2074 ** If there is some spare tape in this run we have a look to see if any of
2075 ** tonights incrementals could be promoted to totals and leave us with a
2076 ** more balanced cycle.
2079 static void delay_one_dump P((disk_t *dp, int delete, ...));
2081 static void delay_dumps P((void))
2082 /* delay any dumps that will not fit */
2084 disk_t *dp, *ndp, *preserve;
2086 am64_t new_total; /* New total_size */
2087 char est_kb[20]; /* Text formatted dump size */
2088 int nb_forced_level_0;
2093 biq.head = biq.tail = NULL;
2096 ** 1. Delay dumps that are way oversize.
2098 ** Dumps larger that the size of the tapes we are using are just plain
2099 ** not going to fit no matter how many other dumps we drop. Delay
2100 ** oversize totals until tomorrow (by which time my owner will have
2101 ** resolved the problem!) and drop incrementals altogether. Naturally
2102 ** a large total might be delayed into a large incremental so these
2103 ** need to be checked for separately.
2106 for(dp = schedq.head; dp != NULL; dp = ndp) {
2107 int avail_tapes = 1;
2108 if (dp->tape_splitsize > 0)
2109 avail_tapes = conf_runtapes;
2111 ndp = dp->next; /* remove_disk zaps this */
2113 if (est(dp)->dump_size == -1 ||
2114 est(dp)->dump_size <= tape->length * avail_tapes) {
2118 /* Format dumpsize for messages */
2119 snprintf(est_kb, 20, "%ld KB,", est(dp)->dump_size);
2121 if(est(dp)->dump_level == 0) {
2124 message = "but cannot incremental dump skip-incr disk";
2126 else if(est(dp)->last_level < 0) {
2128 message = "but cannot incremental dump new disk";
2130 else if(est(dp)->degr_level < 0) {
2132 message = "but no incremental estimate";
2134 else if (est(dp)->degr_size > tape->length) {
2136 message = "incremental dump also larger than tape";
2140 message = "full dump delayed";
2145 message = "skipping incremental";
2147 delay_one_dump(dp, delete, "dump larger than available tape space,", est_kb,
2152 ** 2. Delay total dumps.
2154 ** Delay total dumps until tomorrow (or the day after!). We start with
2155 ** the lowest priority (most dispensable) and work forwards. We take
2156 ** care not to delay *all* the dumps since this could lead to a stale
2157 ** mate [for any one disk there are only three ways tomorrows dump will
2158 ** be smaller than todays: 1. we do a level 0 today so tomorows dump
2159 ** will be a level 1; 2. the disk gets more data so that it is bumped
2160 ** tomorrow (this can be a slow process); and, 3. the disk looses some
2161 ** data (when does that ever happen?)].
2164 nb_forced_level_0 = 0;
2166 for(dp = schedq.head; dp != NULL && preserve == NULL; dp = dp->next)
2167 if(est(dp)->dump_level == 0)
2170 /* 2.a. Do not delay forced full */
2171 for(dp = schedq.tail;
2172 dp != NULL && total_size > tape_length;
2176 if(est(dp)->dump_level != 0) continue;
2178 get_info(dp->host->hostname, dp->name, &info);
2179 if(info.command & FORCE_FULL) {
2180 nb_forced_level_0 += 1;
2185 if(dp != preserve) {
2187 /* Format dumpsize for messages */
2188 snprintf(est_kb, 20, "%ld KB,", est(dp)->dump_size);
2192 message = "but cannot incremental dump skip-incr disk";
2194 else if(est(dp)->last_level < 0) {
2196 message = "but cannot incremental dump new disk";
2198 else if(est(dp)->degr_level < 0) {
2200 message = "but no incremental estimate";
2204 message = "full dump delayed";
2206 delay_one_dump(dp, delete, "dumps too big,", est_kb,
2211 /* 2.b. Delay forced full if needed */
2212 if(nb_forced_level_0 > 0 && total_size > tape_length) {
2213 for(dp = schedq.tail;
2214 dp != NULL && total_size > tape_length;
2218 if(est(dp)->dump_level == 0 && dp != preserve) {
2220 /* Format dumpsize for messages */
2221 snprintf(est_kb, 20, "%ld KB,", est(dp)->dump_size);
2225 message = "but cannot incremental dump skip-incr disk";
2227 else if(est(dp)->last_level < 0) {
2229 message = "but cannot incremental dump new disk";
2231 else if(est(dp)->degr_level < 0) {
2233 message = "but no incremental estimate";
2237 message = "full dump delayed";
2239 delay_one_dump(dp, delete, "dumps too big,", est_kb,
2246 ** 3. Delay incremental dumps.
2248 ** Delay incremental dumps until tomorrow. This is a last ditch attempt
2249 ** at making things fit. Again, we start with the lowest priority (most
2250 ** dispensable) and work forwards.
2253 for(dp = schedq.tail;
2254 dp != NULL && total_size > tape_length;
2258 if(est(dp)->dump_level != 0) {
2260 /* Format dumpsize for messages */
2261 snprintf(est_kb, 20, "%ld KB,", est(dp)->dump_size);
2263 delay_one_dump(dp, 1,
2264 "dumps way too big,",
2266 "must skip incremental dumps",
2272 ** 4. Reinstate delayed dumps.
2274 ** We might not have needed to stomp on all of the dumps we have just
2275 ** delayed above. Try to reinstate them all starting with the last one
2276 ** and working forwards. It is unlikely that the last one will fit back
2277 ** in but why complicate the code?
2280 for(bi = biq.tail; bi != NULL; bi = nbi) {
2281 int avail_tapes = 1;
2284 if(dp->tape_splitsize > 0) avail_tapes = conf_runtapes;
2287 new_total = total_size + tt_blocksize_kb + bi->size + tape_mark;
2289 new_total = total_size - est(dp)->dump_size + bi->size;
2291 if(new_total <= tape_length && bi->size < tape->length * avail_tapes) {
2293 total_size = new_total;
2295 if(bi->level == 0) {
2296 total_lev0 += (double) bi->size;
2298 insert_disk(&schedq, dp, schedule_order);
2301 est(dp)->dump_level = bi->level;
2302 est(dp)->dump_size = bi->size;
2306 if(bi->next == NULL)
2307 biq.tail = bi->prev;
2309 (bi->next)->prev = bi->prev;
2310 if(bi->prev == NULL)
2311 biq.head = bi->next;
2313 (bi->prev)->next = bi->next;
2320 ** 5. Output messages about what we have done.
2322 ** We can't output messages while we are delaying dumps because we might
2323 ** reinstate them later. We remember all the messages and output them
2327 for(bi = biq.head; bi != NULL; bi = nbi) {
2331 fprintf(stderr, "%s: FAILED %s\n", get_pname(), bi->errstr);
2332 log_add(L_FAIL, "%s", bi->errstr);
2336 fprintf(stderr, " delay: %s now at level %d\n",
2337 bi->errstr, est(dp)->dump_level);
2338 log_add(L_INFO, "%s", bi->errstr);
2341 /* Clean up - dont be too fancy! */
2346 fprintf(stderr, " delay: Total size now " AM64_FMT ".\n", total_size);
2353 * Remove a dump or modify it from full to incremental.
2354 * Keep track of it on the bi q in case we can add it back later.
2356 arglist_function1(static void delay_one_dump,
2362 char level_str[NUM_STR_SIZE];
2366 arglist_start(argp, delete);
2368 total_size -= tt_blocksize_kb + est(dp)->dump_size + tape_mark;
2369 if(est(dp)->dump_level == 0) {
2370 total_lev0 -= (double) est(dp)->dump_size;
2373 bi = alloc(sizeof(bi_t));
2375 bi->prev = biq.tail;
2376 if(biq.tail == NULL)
2379 biq.tail->next = bi;
2382 bi->deleted = delete;
2384 bi->level = est(dp)->dump_level;
2385 bi->size = est(dp)->dump_size;
2387 snprintf(level_str, sizeof(level_str), "%d", est(dp)->dump_level);
2388 bi->errstr = vstralloc(dp->host->hostname,
2390 " ", datestamp ? datestamp : "?",
2394 while ((next = arglist_val(argp, char *)) != NULL) {
2395 bi->errstr = newvstralloc(bi->errstr, bi->errstr, sep, next, NULL);
2398 strappend(bi->errstr, "]");
2402 remove_disk(&schedq, dp);
2404 est(dp)->dump_level = est(dp)->degr_level;
2405 est(dp)->dump_size = est(dp)->degr_size;
2406 total_size += tt_blocksize_kb + est(dp)->dump_size + tape_mark;
2413 static int promote_highest_priority_incremental P((void))
2415 disk_t *dp, *dp1, *dp_promote;
2416 long new_size, new_total, new_lev0;
2418 int nb_today, nb_same_day, nb_today2;
2419 int nb_disk_today, nb_disk_same_day;
2422 * return 1 if did so; must update total_size correctly; must not
2423 * cause total_size to exceed tape_length
2427 for(dp = schedq.head; dp != NULL; dp = dp->next) {
2429 est(dp)->promote = -1000;
2431 if(est_size(dp,0) <= 0)
2434 if(est(dp)->next_level0 <= 0)
2437 if(est(dp)->next_level0 > dp->maxpromoteday)
2440 new_size = est_tape_size(dp, 0);
2441 new_total = total_size - est(dp)->dump_size + new_size;
2442 new_lev0 = total_lev0 + new_size;
2447 nb_disk_same_day = 0;
2448 for(dp1 = schedq.head; dp1 != NULL; dp1 = dp1->next) {
2449 if(est(dp1)->dump_level == 0)
2451 else if(est(dp1)->next_level0 == est(dp)->next_level0)
2453 if(strcmp(dp->host->hostname, dp1->host->hostname) == 0) {
2454 if(est(dp1)->dump_level == 0)
2456 else if(est(dp1)->next_level0 == est(dp)->next_level0)
2461 /* do not promote if overflow tape */
2462 if(new_total > tape_length) continue;
2464 /* do not promote if overflow balanced size and something today */
2465 /* promote if nothing today */
2466 if(new_lev0 > balanced_size+balance_threshold && nb_disk_today > 0)
2469 /* do not promote if only one disk due that day and nothing today */
2470 if(nb_disk_same_day == 1 && nb_disk_today == 0) continue;
2472 nb_today2 = nb_today*nb_today;
2473 if(nb_today == 0 && nb_same_day > 1) nb_same_day++;
2475 if(nb_same_day >= nb_today2) {
2476 est(dp)->promote = ((nb_same_day - nb_today2)*(nb_same_day - nb_today2)) +
2477 conf_dumpcycle - est(dp)->next_level0;
2480 est(dp)->promote = -nb_today2 +
2481 conf_dumpcycle - est(dp)->next_level0;
2484 if(!dp_promote || est(dp_promote)->promote < est(dp)->promote) {
2486 fprintf(stderr," try %s:%s %d %d %d = %d\n",
2487 dp->host->hostname, dp->name, nb_same_day, nb_today, est(dp)->next_level0, est(dp)->promote);
2490 fprintf(stderr,"no try %s:%s %d %d %d = %d\n",
2491 dp->host->hostname, dp->name, nb_same_day, nb_today, est(dp)->next_level0, est(dp)->promote);
2498 new_size = est_tape_size(dp, 0);
2499 new_total = total_size - est(dp)->dump_size + new_size;
2500 new_lev0 = total_lev0 + new_size;
2502 total_size = new_total;
2503 total_lev0 = new_lev0;
2504 check_days = est(dp)->next_level0;
2505 est(dp)->degr_level = est(dp)->dump_level;
2506 est(dp)->degr_size = est(dp)->dump_size;
2507 est(dp)->dump_level = 0;
2508 est(dp)->dump_size = new_size;
2509 est(dp)->next_level0 = 0;
2512 " promote: moving %s:%s up, total_lev0 %1.0f, total_size " AM64_FMT "\n",
2513 dp->host->hostname, dp->name,
2514 total_lev0, total_size);
2517 "Full dump of %s:%s promoted from %d day%s ahead.",
2518 dp->host->hostname, dp->name,
2519 check_days, (check_days == 1) ? "" : "s");
2526 static int promote_hills P((void))
2529 struct balance_stats {
2540 /* If we are already doing a level 0 don't bother */
2544 /* Do the guts of an "amadmin balance" */
2545 my_dumpcycle = conf_dumpcycle;
2546 if(my_dumpcycle > 10000) my_dumpcycle = 10000;
2548 sp = (struct balance_stats *)
2549 alloc(sizeof(struct balance_stats) * my_dumpcycle);
2551 for(days = 0; days < my_dumpcycle; days++)
2552 sp[days].disks = sp[days].size = 0;
2554 for(dp = schedq.head; dp != NULL; dp = dp->next) {
2555 days = est(dp)->next_level0; /* This is > 0 by definition */
2556 if(days<my_dumpcycle && !dp->skip_full && dp->strategy != DS_NOFULL &&
2557 dp->strategy != DS_INCRONLY) {
2559 sp[days].size += est(dp)->last_lev0size;
2563 /* Search for a suitable big hill and cut it down */
2565 /* Find the tallest hill */
2567 for(days = 0; days < my_dumpcycle; days++) {
2568 if(sp[days].disks > 1 && sp[days].size > hill_size) {
2569 hill_size = sp[days].size;
2574 if(hill_size <= 0) break; /* no suitable hills */
2576 /* Find all the dumps in that hill and try and remove one */
2577 for(dp = schedq.head; dp != NULL; dp = dp->next) {
2578 if(est(dp)->next_level0 != hill_days ||
2579 est(dp)->next_level0 > dp->maxpromoteday ||
2581 dp->strategy == DS_NOFULL ||
2582 dp->strategy == DS_INCRONLY)
2584 new_size = est_tape_size(dp, 0);
2585 new_total = total_size - est(dp)->dump_size + new_size;
2586 if(new_total > tape_length)
2588 /* We found a disk we can promote */
2589 total_size = new_total;
2590 total_lev0 += new_size;
2591 est(dp)->degr_level = est(dp)->dump_level;
2592 est(dp)->degr_size = est(dp)->dump_size;
2593 est(dp)->dump_level = 0;
2594 est(dp)->next_level0 = 0;
2595 est(dp)->dump_size = new_size;
2598 " promote: moving %s:%s up, total_lev0 %1.0f, total_size " AM64_FMT "\n",
2599 dp->host->hostname, dp->name,
2600 total_lev0, total_size);
2603 "Full dump of %s:%s specially promoted from %d day%s ahead.",
2604 dp->host->hostname, dp->name,
2605 hill_days, (hill_days == 1) ? "" : "s");
2610 /* All the disks in that hill were unsuitable. */
2611 sp[hill_days].disks = 0; /* Don't get tricked again */
2619 * ========================================================================
2622 * XXX - memory leak - we shouldn't just throw away *dp
2624 static void output_scheduleline(dp)
2628 long dump_time = 0, degr_time = 0;
2629 char *schedline = NULL, *degr_str = NULL;
2630 char dump_priority_str[NUM_STR_SIZE];
2631 char dump_level_str[NUM_STR_SIZE];
2632 char dump_size_str[NUM_STR_SIZE];
2633 char dump_time_str[NUM_STR_SIZE];
2634 char degr_level_str[NUM_STR_SIZE];
2635 char degr_size_str[NUM_STR_SIZE];
2636 char degr_time_str[NUM_STR_SIZE];
2637 char *dump_date, *degr_date;
2643 if(ep->dump_size == -1) {
2644 /* no estimate, fail the disk */
2646 "%s: FAILED %s %s %s %d [no estimate]\n",
2648 dp->host->hostname, dp->name, datestamp, ep->dump_level);
2649 log_add(L_FAIL, "%s %s %s %d [no estimate]",
2650 dp->host->hostname, dp->name, datestamp, ep->dump_level);
2654 dump_date = degr_date = (char *)0;
2655 for(i = 0; i < MAX_LEVELS; i++) {
2656 if(ep->dump_level == ep->level[i])
2657 dump_date = ep->dumpdate[i];
2658 if(ep->degr_level == ep->level[i])
2659 degr_date = ep->dumpdate[i];
2662 #define fix_rate(rate) (rate < 1.0 ? DEFAULT_DUMPRATE : rate)
2664 if(ep->dump_level == 0) {
2665 dump_time = ep->dump_size / fix_rate(ep->fullrate);
2667 if(ep->degr_size != -1) {
2668 degr_time = ep->degr_size / fix_rate(ep->incrrate);
2672 dump_time = ep->dump_size / fix_rate(ep->incrrate);
2675 if(ep->dump_level == 0 && ep->degr_size != -1) {
2676 snprintf(degr_level_str, sizeof(degr_level_str),
2677 "%d", ep->degr_level);
2678 snprintf(degr_size_str, sizeof(degr_size_str),
2679 "%ld", ep->degr_size);
2680 snprintf(degr_time_str, sizeof(degr_time_str),
2682 degr_str = vstralloc(" ", degr_level_str,
2688 snprintf(dump_priority_str, sizeof(dump_priority_str),
2689 "%d", ep->dump_priority);
2690 snprintf(dump_level_str, sizeof(dump_level_str),
2691 "%d", ep->dump_level);
2692 snprintf(dump_size_str, sizeof(dump_size_str),
2693 "%ld", ep->dump_size);
2694 snprintf(dump_time_str, sizeof(dump_time_str),
2696 features = am_feature_to_string(dp->host->features);
2697 schedline = vstralloc("DUMP ",dp->host->hostname,
2701 " ", dump_priority_str,
2702 " ", dump_level_str,
2706 degr_str ? degr_str : "",
2709 fputs(schedline, stdout);
2710 fputs(schedline, stderr);