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.206.2.6 2006/11/24 18:05: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 off_t conf_maxdumpsize;
60 int conf_runspercycle;
65 int conf_usetimestamps;
67 #define HOST_READY ((void *)0) /* must be 0 */
68 #define HOST_ACTIVE ((void *)1)
69 #define HOST_DONE ((void *)2)
71 #define DISK_READY 0 /* must be 0 */
73 #define DISK_PARTIALY_DONE 2
76 typedef struct est_s {
81 off_t dump_nsize; /* native size */
82 off_t dump_csize; /* compressed size */
83 int degr_level; /* if dump_level == 0, what would be the inc level */
84 off_t degr_nsize; /* native degraded size */
85 off_t degr_csize; /* compressed degraded size */
91 double fullrate, incrrate;
92 double fullcomp, incrcomp;
94 int level[MAX_LEVELS];
95 char *dumpdate[MAX_LEVELS];
96 off_t est_size[MAX_LEVELS];
99 #define est(dp) ((est_t *)(dp)->up)
101 /* pestq = partial estimate */
102 disklist_t startq, waitq, pestq, estq, failq, schedq;
104 double total_lev0, balanced_size, balance_threshold;
110 size_t tt_blocksize_kb;
111 int runs_per_cycle = 0;
113 char *planner_timestamp = NULL;
115 static am_feature_t *our_features = NULL;
116 static char *our_feature_string = NULL;
118 /* We keep a LIFO queue of before images for all modifications made
119 * to schedq in our attempt to make the schedule fit on the tape.
120 * Enough information is stored to reinstate a dump if it turns out
121 * that it shouldn't have been touched after all.
123 typedef struct bi_s {
126 int deleted; /* 0=modified, 1=deleted */
127 disk_t *dp; /* The disk that was changed */
128 int level; /* The original level */
129 off_t nsize; /* The original native size */
130 off_t csize; /* The original compressed size */
131 char *errstr; /* A message describing why this disk is here */
134 typedef struct bilist_s {
138 bilist_t biq; /* The BI queue itself */
141 * ========================================================================
146 static void setup_estimate(disk_t *dp);
147 static void get_estimates(void);
148 static void analyze_estimate(disk_t *dp);
149 static void handle_failed(disk_t *dp);
150 static void delay_dumps(void);
151 static int promote_highest_priority_incremental(void);
152 static int promote_hills(void);
153 static void output_scheduleline(disk_t *dp);
154 int main(int, char **);
156 int main(int argc, char **argv)
161 unsigned long malloc_hist_1, malloc_size_1;
162 unsigned long malloc_hist_2, malloc_size_2;
169 times_t section_start;
172 int new_argc, my_argc;
173 char **new_argv, **my_argv;
179 setvbuf(stderr, (char *)NULL, (int)_IOLBF, 0);
181 parse_server_conf(argc, argv, &new_argc, &new_argv);
186 config_name = stralloc(my_argv[1]);
187 config_dir = vstralloc(CONFIG_DIR, "/", config_name, "/", NULL);
189 char my_cwd[STR_SIZE];
191 if (getcwd(my_cwd, SIZEOF(my_cwd)) == NULL) {
192 error("cannot determine current working directory");
195 config_dir = stralloc2(my_cwd, "/");
196 if ((config_name = strrchr(my_cwd, '/')) != NULL) {
197 config_name = stralloc(config_name + 1);
203 set_pname("planner");
205 dbopen(DBG_SUBDIR_SERVER);
207 /* Don't die when child closes pipe */
208 signal(SIGPIPE, SIG_IGN);
210 malloc_size_1 = malloc_inuse(&malloc_hist_1);
212 erroutput_type = (ERR_AMANDALOG|ERR_INTERACTIVE);
213 set_logerror(logerror);
215 section_start = curclock();
217 our_features = am_init_feature_set();
218 our_feature_string = am_feature_to_string(our_features);
220 fprintf(stderr, "%s: pid %ld executable %s version %s\n",
221 get_pname(), (long) getpid(), my_argv[0], version());
222 for (i = 0; version_info[i] != NULL; i++)
223 fprintf(stderr, "%s: %s", get_pname(), version_info[i]);
226 * 1. Networking Setup
228 * Planner runs setuid to get a priviledged socket for BSD security.
229 * We get the socket right away as root, then set euid to normal
230 * user. Keeping saved uid as root.
242 * From this point on we are running under our real uid, so we don't
243 * have to worry about opening security holes below. Make sure we
247 if(getpwuid(getuid()) == NULL) {
248 error("can't get login name for my uid %ld", (long)getuid());
253 * 2. Read in Configuration Information
255 * All the Amanda configuration files are loaded before we begin.
258 fprintf(stderr,"READING CONF FILES...\n");
260 conffile = stralloc2(config_dir, CONFFILE_NAME);
261 if(read_conffile(conffile)) {
262 error("errors processing config file \"%s\"", conffile);
267 dbrename(config_name, DBG_SUBDIR_SERVER);
269 report_bad_conf_arg();
271 conf_diskfile = getconf_str(CNF_DISKFILE);
272 if (*conf_diskfile == '/') {
273 conf_diskfile = stralloc(conf_diskfile);
275 conf_diskfile = stralloc2(config_dir, conf_diskfile);
277 if (read_diskfile(conf_diskfile, &origq) < 0) {
278 error("could not load disklist \"%s\"", conf_diskfile);
281 if(origq.head == NULL) {
282 error("empty disklist \"%s\"", conf_diskfile);
286 errstr = match_disklist(&origq, my_argc-2, my_argv+2);
288 fprintf(stderr,"%s",errstr);
292 for(dp = origq.head; dp != NULL; dp = dp->next) {
294 qname = quote_string(dp->name);
295 log_add(L_DISK, "%s %s", dp->host->hostname, qname);
302 error("no DLE to backup");
305 amfree(conf_diskfile);
307 conf_tapelist = getconf_str(CNF_TAPELIST);
308 if (*conf_tapelist == '/') {
309 conf_tapelist = stralloc(conf_tapelist);
311 conf_tapelist = stralloc2(config_dir, conf_tapelist);
313 if(read_tapelist(conf_tapelist)) {
314 error("could not load tapelist \"%s\"", conf_tapelist);
317 amfree(conf_tapelist);
319 conf_infofile = getconf_str(CNF_INFOFILE);
320 if (*conf_infofile == '/') {
321 conf_infofile = stralloc(conf_infofile);
323 conf_infofile = stralloc2(config_dir, conf_infofile);
325 if(open_infofile(conf_infofile)) {
326 error("could not open info db \"%s\"", conf_infofile);
329 if (check_infofile(conf_infofile, &origq, &errstr) == -1) {
330 log_add(L_WARNING, "problem copying infofile: %s", errstr);
333 amfree(conf_infofile);
335 conf_tapetype = getconf_str(CNF_TAPETYPE);
336 conf_maxdumpsize = getconf_am64(CNF_MAXDUMPSIZE);
337 conf_runtapes = getconf_int(CNF_RUNTAPES);
338 conf_dumpcycle = getconf_int(CNF_DUMPCYCLE);
339 conf_runspercycle = getconf_int(CNF_RUNSPERCYCLE);
340 conf_tapecycle = getconf_int(CNF_TAPECYCLE);
341 conf_etimeout = getconf_int(CNF_ETIMEOUT);
342 conf_reserve = getconf_int(CNF_RESERVE);
343 conf_autoflush = getconf_boolean(CNF_AUTOFLUSH);
344 conf_usetimestamps = getconf_boolean(CNF_USETIMESTAMPS);
346 amfree(planner_timestamp);
348 if(conf_usetimestamps == 0) {
349 planner_timestamp = construct_datestamp(NULL);
352 planner_timestamp = construct_timestamp(NULL);
354 log_add(L_START, "date %s", planner_timestamp);
355 printf("DATE %s\n", planner_timestamp);
357 fprintf(stderr, "%s: timestamp %s\n",
358 get_pname(), planner_timestamp);
360 /* some initializations */
362 if(conf_runspercycle == 0) {
363 runs_per_cycle = conf_dumpcycle;
364 } else if(conf_runspercycle == -1 ) {
365 runs_per_cycle = guess_runs_from_tapelist();
367 runs_per_cycle = conf_runspercycle;
369 if (runs_per_cycle <= 0) {
374 * do some basic sanity checking
376 if(conf_tapecycle <= runs_per_cycle) {
377 log_add(L_WARNING, "tapecycle (%d) <= runspercycle (%d)",
378 conf_tapecycle, runs_per_cycle);
381 tape = lookup_tapetype(conf_tapetype);
382 if(conf_maxdumpsize > (off_t)0) {
383 tape_length = (off_t)conf_maxdumpsize;
386 tape_length = tapetype_get_length(tape) * (off_t)conf_runtapes;
388 tape_mark = (size_t)tapetype_get_filemark(tape);
389 tt_blocksize_kb = (size_t)tapetype_get_blocksize(tape);
390 tt_blocksize = tt_blocksize_kb * 1024;
392 fprintf(stderr, "%s: time %s: startup took %s secs\n",
394 walltime_str(curclock()),
395 walltime_str(timessub(curclock(), section_start)));
398 * 3. Send autoflush dumps left on the holding disks
400 * This should give us something to do while we generate the new
404 fprintf(stderr,"\nSENDING FLUSHES...\n");
410 holding_list = get_flush(NULL, NULL, 0, 0);
411 for(holding_file=holding_list->first; holding_file != NULL;
412 holding_file = holding_file->next) {
413 get_dumpfile(holding_file->name, &file);
415 log_add(L_DISK, "%s %s", file.name, file.disk);
417 "FLUSH %s %s %s %d %s\n",
424 "FLUSH %s %s %s %d %s\n",
431 free_sl(holding_list);
434 fprintf(stderr, "ENDFLUSH\n");
435 fprintf(stdout, "ENDFLUSH\n");
439 * 4. Calculate Preliminary Dump Levels
441 * Before we can get estimates from the remote slave hosts, we make a
442 * first attempt at guessing what dump levels we will be dumping at
443 * based on the curinfo database.
446 fprintf(stderr,"\nSETTING UP FOR ESTIMATES...\n");
447 section_start = curclock();
449 startq.head = startq.tail = NULL;
450 while(!empty(origq)) {
451 disk_t *dp = dequeue_disk(&origq);
457 fprintf(stderr, "%s: time %s: setting up estimates took %s secs\n",
459 walltime_str(curclock()),
460 walltime_str(timessub(curclock(), section_start)));
464 * 5. Get Dump Size Estimates from Remote Client Hosts
466 * Each host is queried (in parallel) for dump size information on all
467 * of its disks, and the results gathered as they come in.
470 /* go out and get the dump estimates */
472 fprintf(stderr,"\nGETTING ESTIMATES...\n");
473 section_start = curclock();
475 estq.head = estq.tail = NULL;
476 pestq.head = pestq.tail = NULL;
477 waitq.head = waitq.tail = NULL;
478 failq.head = failq.tail = NULL;
482 fprintf(stderr, "%s: time %s: getting estimates took %s secs\n",
484 walltime_str(curclock()),
485 walltime_str(timessub(curclock(), section_start)));
488 * At this point, all disks with estimates are in estq, and
489 * all the disks on hosts that didn't respond to our inquiry
493 dump_queue("FAILED", failq, 15, stderr);
494 dump_queue("DONE", estq, 15, stderr);
498 * 6. Analyze Dump Estimates
500 * Each disk's estimates are looked at to determine what level it
501 * should dump at, and to calculate the expected size and time taking
502 * historical dump rates and compression ratios into account. The
503 * total expected size is accumulated as well.
506 fprintf(stderr,"\nANALYZING ESTIMATES...\n");
507 section_start = curclock();
509 /* an empty tape still has a label and an endmark */
510 total_size = ((off_t)tt_blocksize_kb + (off_t)tape_mark) * (off_t)2;
514 schedq.head = schedq.tail = NULL;
515 while(!empty(estq)) analyze_estimate(dequeue_disk(&estq));
516 while(!empty(failq)) handle_failed(dequeue_disk(&failq));
519 * At this point, all the disks are on schedq sorted by priority.
520 * The total estimated size of the backups is in total_size.
526 fprintf(stderr, "INITIAL SCHEDULE (size " OFF_T_FMT "):\n",
527 (OFF_T_FMT_TYPE)total_size);
528 for(dp = schedq.head; dp != NULL; dp = dp->next) {
529 qname = quote_string(dp->name);
530 fprintf(stderr, " %s %s pri %d lev %d nsize " OFF_T_FMT " csize " OFF_T_FMT "\n",
531 dp->host->hostname, qname, est(dp)->dump_priority,
533 (OFF_T_FMT_TYPE)est(dp)->dump_nsize,
534 (OFF_T_FMT_TYPE)est(dp)->dump_csize);
541 * 7. Delay Dumps if Schedule Too Big
543 * If the generated schedule is too big to fit on the tape, we need to
544 * delay some full dumps to make room. Incrementals will be done
545 * instead (except for new or forced disks).
547 * In extreme cases, delaying all the full dumps is not even enough.
548 * If so, some low-priority incrementals will be skipped completely
549 * until the dumps fit on the tape.
552 fprintf(stderr, "\nDELAYING DUMPS IF NEEDED, total_size " OFF_T_FMT
553 ", tape length " OFF_T_FMT " mark " SIZE_T_FMT "\n",
554 (OFF_T_FMT_TYPE)total_size,
555 (OFF_T_FMT_TYPE)tape_length,
556 (SIZE_T_FMT_TYPE)tape_mark);
558 initial_size = total_size;
562 /* XXX - why bother checking this? */
563 if(empty(schedq) && total_size < initial_size) {
564 error("cannot fit anything on tape, bailing out");
570 * 8. Promote Dumps if Schedule Too Small
572 * Amanda attempts to balance the full dumps over the length of the
573 * dump cycle. If this night's full dumps are too small relative to
574 * the other nights, promote some high-priority full dumps that will be
575 * due for the next run, to full dumps for tonight, taking care not to
576 * overflow the tape size.
578 * This doesn't work too well for small sites. For these we scan ahead
579 * looking for nights that have an excessive number of dumps and promote
582 * Amanda never delays full dumps just for the sake of balancing the
583 * schedule, so it can take a full cycle to balance the schedule after
588 "\nPROMOTING DUMPS IF NEEDED, total_lev0 %1.0lf, balanced_size %1.0lf...\n",
589 total_lev0, balanced_size);
591 balance_threshold = balanced_size * PROMOTE_THRESHOLD;
593 while((balanced_size - total_lev0) > balance_threshold && moved_one)
594 moved_one = promote_highest_priority_incremental();
596 moved_one = promote_hills();
598 fprintf(stderr, "%s: time %s: analysis took %s secs\n",
600 walltime_str(curclock()),
601 walltime_str(timessub(curclock(), section_start)));
604 /* done with prvileged ops, make sure root privilege is dropped */
605 if ( geteuid() == 0 ) {
613 * The schedule goes to stdout, presumably to driver. A copy is written
614 * on stderr for the debug file.
617 fprintf(stderr,"\nGENERATING SCHEDULE:\n--------\n");
619 while(!empty(schedq)) output_scheduleline(dequeue_disk(&schedq));
620 fprintf(stderr, "--------\n");
623 log_add(L_FINISH, "date %s time %s", planner_timestamp, walltime_str(curclock()));
626 free_new_argv(new_argc, new_argv);
627 free_server_config();
628 amfree(planner_timestamp);
631 amfree(our_feature_string);
632 am_release_feature_set(our_features);
635 malloc_size_2 = malloc_inuse(&malloc_hist_2);
637 if(malloc_size_1 != malloc_size_2) {
638 malloc_list(fileno(stderr), malloc_hist_1, malloc_hist_2);
649 * ========================================================================
650 * SETUP FOR ESTIMATES
654 static void askfor(est_t *, int, int, info_t *);
655 static int last_level(info_t *info); /* subroutines */
656 static off_t est_size(disk_t *dp, int level);
657 static off_t est_tape_size(disk_t *dp, int level);
658 static int next_level0(disk_t *dp, info_t *info);
659 static int runs_at(info_t *info, int lev);
660 static off_t bump_thresh(int level, off_t size_level_0, int bumppercent, off_t bumpsize, double bumpmult);
661 static int when_overwrite(char *label);
664 est_t *ep, /* esimate data block */
665 int seq, /* sequence number of request */
666 int lev, /* dump level being requested */
667 info_t *info) /* info block for disk */
669 if(seq < 0 || seq >= MAX_LEVELS) {
670 error("error [planner askfor: seq out of range 0..%d: %d]",
674 if(lev < -1 || lev >= DUMP_LEVELS) {
675 error("error [planner askfor: lev out of range -1..%d: %d]",
682 ep->dumpdate[seq] = (char *)0;
683 ep->est_size[seq] = (off_t)-2;
687 ep->level[seq] = lev;
689 ep->dumpdate[seq] = stralloc(get_dumpdate(info,lev));
690 malloc_mark(ep->dumpdate[seq]);
692 ep->est_size[seq] = (off_t)-2;
707 assert(dp && dp->host);
709 qname = quote_string(dp->name);
710 fprintf(stderr, "%s: time %s: setting up estimates for %s:%s\n",
711 get_pname(), walltime_str(curclock()),
712 dp->host->hostname, qname);
714 /* get current information about disk */
716 if(get_info(dp->host->hostname, dp->name, &info)) {
717 /* no record for this disk, make a note of it */
718 log_add(L_INFO, "Adding new disk %s:%s.", dp->host->hostname, dp->name);
721 /* setup working data struct for disk */
723 ep = alloc(SIZEOF(est_t));
725 dp->up = (void *) ep;
726 ep->state = DISK_READY;
727 ep->dump_nsize = (off_t)-1;
728 ep->dump_csize = (off_t)-1;
729 ep->dump_priority = dp->priority;
733 /* calculated fields */
735 if (ISSET(info.command, FORCE_FULL)) {
736 /* force a level 0, kind of like a new disk */
737 if(dp->strategy == DS_NOFULL) {
739 * XXX - Not sure what it means to force a no-full disk. The
740 * purpose of no-full is to just dump changes relative to a
741 * stable base, for example root partitions that vary only
742 * slightly from a site-wide prototype. Only the variations
745 * If we allow a level 0 onto the Amanda cycle, then we are
746 * hosed when that tape gets re-used next. Disallow this for
750 "Cannot force full dump of %s:%s with no-full option.",
751 dp->host->hostname, qname);
753 /* clear force command */
754 CLR(info.command, FORCE_FULL);
755 if(put_info(dp->host->hostname, dp->name, &info)) {
756 error("could not put info record for %s:%s: %s",
757 dp->host->hostname, qname, strerror(errno));
760 ep->last_level = last_level(&info);
761 ep->next_level0 = next_level0(dp, &info);
765 ep->next_level0 = -conf_dumpcycle;
766 log_add(L_INFO, "Forcing full dump of %s:%s as directed.",
767 dp->host->hostname, qname);
770 else if(dp->strategy == DS_NOFULL) {
771 /* force estimate of level 1 */
773 ep->next_level0 = next_level0(dp, &info);
776 ep->last_level = last_level(&info);
777 ep->next_level0 = next_level0(dp, &info);
780 /* adjust priority levels */
782 /* warn if dump will be overwritten */
783 if(ep->last_level > -1) {
784 overwrite_runs = when_overwrite(info.inf[0].label);
785 if(overwrite_runs == 0) {
786 log_add(L_WARNING, "Last full dump of %s:%s "
787 "on tape %s overwritten on this run.",
788 dp->host->hostname, qname, info.inf[0].label);
790 else if(overwrite_runs <= RUNS_REDZONE) {
791 log_add(L_WARNING, "Last full dump of %s:%s on "
792 "tape %s overwritten in %d run%s.",
793 dp->host->hostname, qname, info.inf[0].label,
794 overwrite_runs, overwrite_runs == 1? "" : "s");
798 if(ep->next_level0 < 0) {
799 fprintf(stderr,"%s:%s overdue %d day%s for level 0\n",
800 dp->host->hostname, qname,
801 - ep->next_level0, ((- ep->next_level0) == 1) ? "" : "s");
802 ep->dump_priority -= ep->next_level0;
804 else if (ISSET(info.command, FORCE_FULL))
805 ep->dump_priority += 1;
806 /* else XXX bump up the priority of incrementals that failed last night */
808 /* handle external level 0 dumps */
810 if(dp->skip_full && dp->strategy != DS_NOINC) {
811 if(ep->next_level0 <= 0) {
812 /* update the date field */
813 info.inf[0].date = today;
814 CLR(info.command, FORCE_FULL);
815 ep->next_level0 += conf_dumpcycle;
817 if(put_info(dp->host->hostname, dp->name, &info)) {
818 error("could not put info record for %s:%s: %s",
819 dp->host->hostname, qname, strerror(errno));
822 log_add(L_INFO, "Skipping full dump of %s:%s today.",
823 dp->host->hostname, qname);
824 fprintf(stderr,"%s:%s lev 0 skipped due to skip-full flag\n",
825 dp->host->hostname, qname);
826 /* don't enqueue the disk */
827 askfor(ep, 0, -1, &info);
828 askfor(ep, 1, -1, &info);
829 askfor(ep, 2, -1, &info);
830 fprintf(stderr, "%s: SKIPPED %s %s 0 [skip-full]\n",
831 get_pname(), dp->host->hostname, qname);
832 log_add(L_SUCCESS, "%s %s %s 0 [skipped: skip-full]",
833 dp->host->hostname, qname, planner_timestamp);
838 if(ep->last_level == -1) {
839 /* probably a new disk, but skip-full means no full! */
843 if(ep->next_level0 == 1) {
844 log_add(L_WARNING, "Skipping full dump of %s:%s tomorrow.",
845 dp->host->hostname, qname);
849 if(dp->strategy == DS_INCRONLY && ep->last_level == -1 && !ISSET(info.command, FORCE_FULL)) {
850 /* don't enqueue the disk */
851 askfor(ep, 0, -1, &info);
852 askfor(ep, 1, -1, &info);
853 askfor(ep, 2, -1, &info);
854 log_add(L_FAIL, "%s %s 19000101 1 [Skipping incronly because no full dump were done]",
855 dp->host->hostname, qname);
856 fprintf(stderr,"%s:%s lev 1 skipped due to strategy incronly and no full dump were done\n",
857 dp->host->hostname, qname);
862 /* handle "skip-incr" type archives */
864 if(dp->skip_incr && ep->next_level0 > 0) {
865 fprintf(stderr,"%s:%s lev 1 skipped due to skip-incr flag\n",
866 dp->host->hostname, qname);
867 /* don't enqueue the disk */
868 askfor(ep, 0, -1, &info);
869 askfor(ep, 1, -1, &info);
870 askfor(ep, 2, -1, &info);
872 fprintf(stderr, "%s: SKIPPED %s %s 1 [skip-incr]\n",
873 get_pname(), dp->host->hostname, qname);
875 log_add(L_SUCCESS, "%s %s %s 1 [skipped: skip-incr]",
876 dp->host->hostname, qname, planner_timestamp);
881 if( ep->last_level == -1 && ep->next_level0 > 0 &&
882 dp->strategy != DS_NOFULL && dp->strategy != DS_INCRONLY &&
883 conf_reserve == 100) {
884 log_add(L_WARNING, "%s:%s mismatch: no tapelist record, "
885 "but curinfo next_level0: %d.",
886 dp->host->hostname, qname, ep->next_level0);
890 if(ep->last_level == 0) ep->level_days = 0;
891 else ep->level_days = runs_at(&info, ep->last_level);
892 ep->last_lev0size = info.inf[0].csize;
894 ep->fullrate = perf_average(info.full.rate, 0.0);
895 ep->incrrate = perf_average(info.incr.rate, 0.0);
897 ep->fullcomp = perf_average(info.full.comp, dp->comprate[0]);
898 ep->incrcomp = perf_average(info.incr.comp, dp->comprate[1]);
900 /* determine which estimates to get */
904 if (dp->strategy == DS_NOINC ||
906 (!ISSET(info.command, FORCE_BUMP) ||
908 ep->last_level == -1))) {
909 if(info.command & FORCE_BUMP && ep->last_level == -1) {
911 "Remove force-bump command of %s:%s because it's a new disk.",
912 dp->host->hostname, qname);
914 switch (dp->strategy) {
917 askfor(ep, i++, 0, &info);
919 log_add(L_INFO, "Ignoring skip_full for %s:%s "
920 "because the strategy is NOINC.",
921 dp->host->hostname, qname);
923 if(info.command & FORCE_BUMP) {
925 "Ignoring FORCE_BUMP for %s:%s because the strategy is NOINC.",
926 dp->host->hostname, qname);
935 if (ISSET(info.command, FORCE_FULL))
936 askfor(ep, i++, 0, &info);
941 if(!dp->skip_incr && !(dp->strategy == DS_NOINC)) {
942 if(ep->last_level == -1) { /* a new disk */
943 if(dp->strategy == DS_NOFULL || dp->strategy == DS_INCRONLY) {
944 askfor(ep, i++, 1, &info);
946 assert(!dp->skip_full); /* should be handled above */
948 } else { /* not new, pick normally */
951 curr_level = ep->last_level;
953 if (ISSET(info.command, FORCE_NO_BUMP)) {
954 if(curr_level > 0) { /* level 0 already asked for */
955 askfor(ep, i++, curr_level, &info);
957 log_add(L_INFO,"Preventing bump of %s:%s as directed.",
958 dp->host->hostname, qname);
959 } else if (ISSET(info.command, FORCE_BUMP)
960 && curr_level + 1 < DUMP_LEVELS) {
961 askfor(ep, i++, curr_level+1, &info);
962 log_add(L_INFO,"Bumping of %s:%s at level %d as directed.",
963 dp->host->hostname, qname, curr_level+1);
964 } else if (curr_level == 0) {
965 askfor(ep, i++, 1, &info);
967 askfor(ep, i++, curr_level, &info);
969 * If last time we dumped less than the threshold, then this
970 * time we will too, OR the extra size will be charged to both
971 * cur_level and cur_level + 1, so we will never bump. Also,
972 * if we haven't been at this level 2 days, or the dump failed
973 * last night, we can't bump.
975 if((info.inf[curr_level].size == (off_t)0 || /* no data, try it anyway */
976 (((info.inf[curr_level].size > bump_thresh(curr_level, info.inf[0].size,dp->bumppercent, dp->bumpsize, dp->bumpmult)))
977 && ep->level_days >= dp->bumpdays))
978 && curr_level + 1 < DUMP_LEVELS) {
979 askfor(ep, i++, curr_level+1, &info);
985 while(i < MAX_LEVELS) /* mark end of estimates */
986 askfor(ep, i++, -1, &info);
990 fprintf(stderr, "setup_estimate: %s:%s: command %u, options: %s "
991 "last_level %d next_level0 %d level_days %d getting estimates "
992 "%d (" OFF_T_FMT ") %d (" OFF_T_FMT ") %d (" OFF_T_FMT ")\n",
993 dp->host->hostname, qname, info.command,
994 dp->strategy == DS_NOFULL ? "no-full" :
995 dp->strategy == DS_INCRONLY ? "incr-only" :
996 dp->skip_full ? "skip-full" :
997 dp->skip_incr ? "skip-incr" : "none",
998 ep->last_level, ep->next_level0, ep->level_days,
999 ep->level[0], (OFF_T_FMT_TYPE)ep->est_size[0],
1000 ep->level[1], (OFF_T_FMT_TYPE)ep->est_size[1],
1001 ep->level[2], (OFF_T_FMT_TYPE)ep->est_size[2]);
1003 assert(ep->level[0] != -1);
1004 enqueue_disk(&startq, dp);
1008 static int when_overwrite(
1014 runtapes = conf_runtapes;
1015 if(runtapes == 0) runtapes = 1;
1017 if((tp = lookup_tapelabel(label)) == NULL)
1018 return 1; /* "shouldn't happen", but trigger warning message */
1019 else if(tp->reuse == 0)
1021 else if(lookup_nb_tape() > conf_tapecycle)
1022 return (lookup_nb_tape() - tp->position) / runtapes;
1024 return (conf_tapecycle - tp->position) / runtapes;
1027 /* Return the estimated size for a particular dump */
1028 static off_t est_size(
1034 for(i = 0; i < MAX_LEVELS; i++) {
1035 if(level == est(dp)->level[i])
1036 return est(dp)->est_size[i];
1041 /* Return the estimated on-tape size of a particular dump */
1042 static off_t est_tape_size(
1049 size = est_size(dp, level);
1051 if(size == (off_t)-1) return size;
1053 if(dp->compress == COMP_NONE)
1056 if(level == 0) ratio = est(dp)->fullcomp;
1057 else ratio = est(dp)->incrcomp;
1060 * make sure over-inflated compression ratios don't throw off the
1061 * estimates, this is mostly for when you have a small dump getting
1062 * compressed which takes up alot more disk/tape space relatively due
1063 * to the overhead of the compression. This is specifically for
1064 * Digital Unix vdump. This patch is courtesy of Rudolf Gabler
1065 * (RUG@USM.Uni-Muenchen.DE)
1068 if(ratio > 1.1) ratio = 1.1;
1070 size = (off_t)((double)size * ratio);
1073 * Ratio can be very small in some error situations, so make sure
1074 * size goes back greater than zero. It may not be right, but
1075 * indicates we did get an estimate.
1077 if(size <= (off_t)0) {
1085 /* what was the level of the last successful dump to tape? */
1086 static int last_level(
1089 int min_pos, min_level, i;
1090 time_t lev0_date, last_date;
1093 if(info->last_level != -1)
1094 return info->last_level;
1096 /* to keep compatibility with old infofile */
1097 min_pos = 1000000000;
1101 for(i = 0; i < 9; i++) {
1102 if(conf_reserve < 100) {
1103 if(i == 0) lev0_date = info->inf[0].date;
1104 else if(info->inf[i].date < lev0_date) continue;
1105 if(info->inf[i].date > last_date) {
1106 last_date = info->inf[i].date;
1111 if((tp = lookup_tapelabel(info->inf[i].label)) == NULL) continue;
1112 /* cull any entries from previous cycles */
1113 if(i == 0) lev0_date = info->inf[0].date;
1114 else if(info->inf[i].date < lev0_date) continue;
1116 if(tp->position < min_pos) {
1117 min_pos = tp->position;
1122 info->last_level = i;
1126 /* when is next level 0 due? 0 = today, 1 = tomorrow, etc*/
1132 if(dp->strategy == DS_NOFULL || dp->strategy == DS_INCRONLY)
1133 return 1; /* fake it */
1134 else if (dp->strategy == DS_NOINC)
1136 else if(info->inf[0].date < (time_t)0)
1137 return -days_diff(EPOCH, today); /* new disk */
1139 return dp->dumpcycle - days_diff(info->inf[0].date, today);
1142 /* how many runs at current level? */
1147 tape_t *cur_tape, *old_tape;
1150 last = last_level(info);
1151 if(lev != last) return 0;
1152 if(lev == 0) return 1;
1154 if(info->consecutive_runs != -1)
1155 return info->consecutive_runs;
1157 /* to keep compatibility with old infofile */
1158 cur_tape = lookup_tapelabel(info->inf[lev].label);
1159 old_tape = lookup_tapelabel(info->inf[lev-1].label);
1160 if(cur_tape == NULL || old_tape == NULL) return 0;
1162 if(conf_runtapes == 0)
1163 nb_runs = (old_tape->position - cur_tape->position) / 1;
1165 nb_runs = (old_tape->position - cur_tape->position) / conf_runtapes;
1166 info->consecutive_runs = nb_runs;
1172 static off_t bump_thresh(
1181 if ((bumppercent != 0) && (size_level_0 > (off_t)1024)) {
1182 bump = ((double)size_level_0 * (double)bumppercent) / 100.0;
1185 bump = (double)bumpsize;
1187 while(--level) bump = bump * bumpmult;
1195 * ========================================================================
1196 * GET REMOTE DUMP SIZE ESTIMATES
1200 static void getsize(am_host_t *hostp);
1201 static disk_t *lookup_hostdisk(am_host_t *hp, char *str);
1202 static void handle_result(void *datap, pkt_t *pkt, security_handle_t *sech);
1205 static void get_estimates(void)
1209 int something_started;
1211 something_started = 1;
1212 while(something_started) {
1213 something_started = 0;
1214 for(dp = startq.head; dp != NULL; dp = dp->next) {
1216 if(hostp->up == HOST_READY) {
1217 something_started = 1;
1221 * dp is no longer on startq, so dp->next is not valid
1222 * and we have to start all over.
1230 while(!empty(waitq)) {
1231 disk_t *dp = dequeue_disk(&waitq);
1232 est(dp)->errstr = "hmm, disk was stranded on waitq";
1233 enqueue_disk(&failq, dp);
1236 while(!empty(pestq)) {
1237 disk_t *dp = dequeue_disk(&pestq);
1238 char * qname = quote_string(dp->name);
1240 if(est(dp)->level[0] != -1 && est(dp)->est_size[0] < (off_t)0) {
1241 if(est(dp)->est_size[0] == (off_t)-1) {
1242 log_add(L_WARNING, "disk %s:%s, estimate of level %d failed.",
1243 dp->host->hostname, qname, est(dp)->level[0]);
1247 "disk %s:%s, estimate of level %d timed out.",
1248 dp->host->hostname, qname, est(dp)->level[0]);
1250 est(dp)->level[0] = -1;
1253 if(est(dp)->level[1] != -1 && est(dp)->est_size[1] < (off_t)0) {
1254 if(est(dp)->est_size[1] == (off_t)-1) {
1256 "disk %s:%s, estimate of level %d failed.",
1257 dp->host->hostname, qname, est(dp)->level[1]);
1261 "disk %s:%s, estimate of level %d timed out.",
1262 dp->host->hostname, qname, est(dp)->level[1]);
1264 est(dp)->level[1] = -1;
1267 if(est(dp)->level[2] != -1 && est(dp)->est_size[2] < (off_t)0) {
1268 if(est(dp)->est_size[2] == (off_t)-1) {
1270 "disk %s:%s, estimate of level %d failed.",
1271 dp->host->hostname, qname, est(dp)->level[2]);
1275 "disk %s:%s, estimate of level %d timed out.",
1276 dp->host->hostname, qname, est(dp)->level[2]);
1278 est(dp)->level[2] = -1;
1281 if((est(dp)->level[0] != -1 && est(dp)->est_size[0] > (off_t)0) ||
1282 (est(dp)->level[1] != -1 && est(dp)->est_size[1] > (off_t)0) ||
1283 (est(dp)->level[2] != -1 && est(dp)->est_size[2] > (off_t)0)) {
1284 enqueue_disk(&estq, dp);
1287 est(dp)->errstr = vstralloc("disk ", qname,
1288 ", all estimate timed out", NULL);
1289 enqueue_disk(&failq, dp);
1295 static void getsize(
1298 char number[NUM_STR_SIZE], *req;
1301 time_t estimates, timeout;
1303 const security_driver_t *secdrv;
1308 assert(hostp->disks != NULL);
1310 if(hostp->up != HOST_READY) {
1315 * The first time through here we send a "noop" request. This will
1316 * return the feature list from the client if it supports that.
1317 * If it does not, handle_result() will set the feature list to an
1318 * empty structure. In either case, we do the disks on the second
1319 * (and subsequent) pass(es).
1321 if(hostp->features != NULL) { /* sendsize service */
1325 int has_features = am_has_feature(hostp->features,
1326 fe_req_options_features);
1327 int has_hostname = am_has_feature(hostp->features,
1328 fe_req_options_hostname);
1329 int has_maxdumps = am_has_feature(hostp->features,
1330 fe_req_options_maxdumps);
1331 int has_config = am_has_feature(hostp->features,
1332 fe_req_options_config);
1334 snprintf(number, SIZEOF(number), "%d", hostp->maxdumps);
1335 req = vstralloc("SERVICE ", "sendsize", "\n",
1337 has_features ? "features=" : "",
1338 has_features ? our_feature_string : "",
1339 has_features ? ";" : "",
1340 has_maxdumps ? "maxdumps=" : "",
1341 has_maxdumps ? number : "",
1342 has_maxdumps ? ";" : "",
1343 has_hostname ? "hostname=" : "",
1344 has_hostname ? hostp->hostname : "",
1345 has_hostname ? ";" : "",
1346 has_config ? "config=" : "",
1347 has_config ? config_name : "",
1348 has_config ? ";" : "",
1351 req_len = strlen(req);
1352 req_len += 128; /* room for SECURITY ... */
1354 for(dp = hostp->disks; dp != NULL; dp = dp->hostnext) {
1358 if(dp->todo == 0) continue;
1360 if(est(dp)->state != DISK_READY) continue;
1362 est(dp)->got_estimate = 0;
1363 if(est(dp)->level[0] == -1) {
1364 est(dp)->state = DISK_DONE;
1368 qname = quote_string(dp->name);
1369 if(dp->estimate == ES_CLIENT ||
1370 dp->estimate == ES_CALCSIZE) {
1373 for(i = 0; i < MAX_LEVELS; i++) {
1375 char *exclude1 = "";
1376 char *exclude2 = "";
1377 char *excludefree = NULL;
1378 char *include1 = "";
1379 char *include2 = "";
1380 char *includefree = NULL;
1381 char spindle[NUM_STR_SIZE];
1382 char level[NUM_STR_SIZE];
1383 int lev = est(dp)->level[i];
1385 if(lev == -1) break;
1387 snprintf(level, SIZEOF(level), "%d", lev);
1388 snprintf(spindle, SIZEOF(spindle), "%d", dp->spindle);
1389 if(am_has_feature(hostp->features,fe_sendsize_req_options)){
1390 exclude1 = " OPTIONS |";
1391 exclude2 = optionstr(dp, hostp->features, NULL);
1392 if ( exclude2 == NULL ) {
1393 error("problem with option string, check the dumptype definition.\n");
1395 excludefree = exclude2;
1399 if(dp->exclude_file &&
1400 dp->exclude_file->nb_element == 1) {
1401 exclude1 = " exclude-file=";
1403 quote_string(dp->exclude_file->first->name);
1404 excludefree = exclude2;
1406 else if(dp->exclude_list &&
1407 dp->exclude_list->nb_element == 1) {
1408 exclude1 = " exclude-list=";
1410 quote_string(dp->exclude_list->first->name);
1411 excludefree = exclude2;
1413 if(dp->include_file &&
1414 dp->include_file->nb_element == 1) {
1415 include1 = " include-file=";
1417 quote_string(dp->include_file->first->name);
1418 includefree = include2;
1420 else if(dp->include_list &&
1421 dp->include_list->nb_element == 1) {
1422 include1 = " include-list=";
1424 quote_string(dp->include_list->first->name);
1425 includefree = include2;
1429 if(dp->estimate == ES_CALCSIZE &&
1430 !am_has_feature(hostp->features, fe_calcsize_estimate)) {
1431 log_add(L_WARNING,"%s:%s does not support CALCSIZE for estimate, using CLIENT.\n",
1432 hostp->hostname, qname);
1433 dp->estimate = ES_CLIENT;
1435 if(dp->estimate == ES_CLIENT)
1438 calcsize = "CALCSIZE ";
1440 if(strncmp(dp->program,"DUMP",4) == 0 ||
1441 strncmp(dp->program,"GNUTAR",6) == 0) {
1446 l = vstralloc(calcsize,
1450 " ", dp->device ? dp->device : "",
1452 " ", est(dp)->dumpdate[i],
1454 " ", exclude1, exclude2,
1455 ((includefree != NULL) ? " " : ""),
1462 amfree(includefree);
1463 amfree(excludefree);
1471 est(dp)->state = DISK_ACTIVE;
1472 remove_disk(&startq, dp);
1474 else if (dp->estimate == ES_SERVER) {
1477 get_info(dp->host->hostname, dp->name, &info);
1478 for(i = 0; i < MAX_LEVELS; i++) {
1480 int lev = est(dp)->level[i];
1482 if(lev == -1) break;
1483 if(lev == 0) { /* use latest level 0, should do extrapolation */
1484 off_t est_size = (off_t)0;
1487 for(j=NB_HISTORY-2;j>=0;j--) {
1488 if(info.history[j].level == 0) {
1489 if(info.history[j].size < (off_t)0) continue;
1490 est_size = info.history[j].size;
1495 est(dp)->est_size[i] = est_size;
1497 else if(info.inf[lev].size > (off_t)1000) { /* stats */
1498 est(dp)->est_size[i] = info.inf[lev].size;
1501 est(dp)->est_size[i] = (off_t)1000000;
1504 else if(lev == est(dp)->last_level) {
1505 /* means of all X day at the same level */
1508 off_t est_size_day[NB_DAY];
1509 int nb_est_day[NB_DAY];
1510 for(j=0;j<NB_DAY;j++) {
1511 est_size_day[j]=(off_t)0;
1515 for(j=NB_HISTORY-2;j>=0;j--) {
1516 if(info.history[j].level <= 0) continue;
1517 if(info.history[j].size < (off_t)0) continue;
1518 if(info.history[j].level==info.history[j+1].level) {
1519 if(nb_day <NB_DAY-1) nb_day++;
1520 est_size_day[nb_day] += info.history[j].size;
1521 nb_est_day[nb_day]++;
1527 nb_day = info.consecutive_runs + 1;
1528 if(nb_day > NB_DAY-1) nb_day = NB_DAY-1;
1530 while(nb_day > 0 && nb_est_day[nb_day] == 0) nb_day--;
1532 if(nb_est_day[nb_day] > 0) {
1533 est(dp)->est_size[i] = est_size_day[nb_day] /
1534 (off_t)nb_est_day[nb_day];
1536 else if(info.inf[lev].size > (off_t)1000) { /* stats */
1537 est(dp)->est_size[i] = info.inf[lev].size;
1540 est(dp)->est_size[i] = (off_t)10000;
1543 else if(lev == est(dp)->last_level + 1) {
1544 /* means of all first day at a new level */
1545 off_t est_size = (off_t)0;
1548 for(j=NB_HISTORY-2;j>=0;j--) {
1549 if(info.history[j].level <= 0) continue;
1550 if(info.history[j].size < (off_t)0) continue;
1551 if(info.history[j].level == info.history[j+1].level + 1 ) {
1552 est_size += info.history[j].size;
1557 est(dp)->est_size[i] = est_size / (off_t)nb_est;
1559 else if(info.inf[lev].size > (off_t)1000) { /* stats */
1560 est(dp)->est_size[i] = info.inf[lev].size;
1563 est(dp)->est_size[i] = (off_t)100000;
1567 fprintf(stderr,"%s time %s: got result for host %s disk %s:",
1568 get_pname(), walltime_str(curclock()),
1569 dp->host->hostname, qname);
1570 fprintf(stderr," %d -> " OFF_T_FMT "K, %d -> " OFF_T_FMT "K, %d -> " OFF_T_FMT "K\n",
1571 est(dp)->level[0], (OFF_T_FMT_TYPE)est(dp)->est_size[0],
1572 est(dp)->level[1], (OFF_T_FMT_TYPE)est(dp)->est_size[1],
1573 est(dp)->level[2], (OFF_T_FMT_TYPE)est(dp)->est_size[2]);
1574 est(dp)->state = DISK_DONE;
1575 remove_disk(&startq, dp);
1576 enqueue_disk(&estq, dp);
1581 if(estimates == 0) {
1583 hostp->up = HOST_DONE;
1587 if (conf_etimeout < 0) {
1588 timeout = - conf_etimeout;
1590 timeout = estimates * conf_etimeout;
1592 } else { /* noop service */
1593 req = vstralloc("SERVICE ", "noop", "\n",
1595 "features=", our_feature_string, ";",
1599 * We use ctimeout for the "noop" request because it should be
1600 * very fast and etimeout has other side effects.
1602 timeout = getconf_int(CNF_CTIMEOUT);
1605 secdrv = security_getdriver(hostp->disks->security_driver);
1606 if (secdrv == NULL) {
1607 error("could not find security driver '%s' for host '%s'",
1608 hostp->disks->security_driver, hostp->hostname);
1611 hostp->up = HOST_ACTIVE;
1613 for(dp = hostp->disks; dp != NULL; dp = dp->hostnext) {
1617 if(est(dp)->state == DISK_ACTIVE) {
1618 est(dp)->errstr = NULL;
1619 enqueue_disk(&waitq, dp);
1623 protocol_sendreq(hostp->hostname, secdrv, amhost_get_security_conf,
1624 req, timeout, handle_result, hostp);
1628 static disk_t *lookup_hostdisk(
1629 /*@keep@*/ am_host_t *hp,
1634 for(dp = hp->disks; dp != NULL; dp = dp->hostnext)
1635 if(strcmp(str, dp->name) == 0) return dp;
1641 static void handle_result(
1644 security_handle_t *sech)
1650 char *msgdisk=NULL, *msgdisk_undo=NULL, msgdisk_undo_ch = '\0';
1651 char *remoterr, *errbuf = NULL;
1660 OFF_T_FMT_TYPE size_;
1662 hostp = (am_host_t *)datap;
1663 hostp->up = HOST_READY;
1666 errbuf = vstralloc("Request to ", hostp->hostname, " failed: ",
1667 security_geterror(sech), NULL);
1670 if (pkt->type == P_NAK) {
1672 if(strncmp(pkt->body, sc, SIZEOF(sc)-1) == 0) {
1673 s = pkt->body + SIZEOF(sc)-1;
1677 goto NAK_parse_failed;
1679 skip_whitespace(s, ch);
1680 if(ch == '\0') goto NAK_parse_failed;
1682 if((s = strchr(remoterr, '\n')) != NULL) {
1683 if(s == remoterr) goto NAK_parse_failed;
1686 if (strcmp(remoterr, "unknown service: noop") != 0
1687 && strcmp(remoterr, "noop: invalid service") != 0) {
1688 errbuf = vstralloc(hostp->hostname, " NAK: ", remoterr, NULL);
1694 msgdisk_undo = NULL;
1700 #define sc "OPTIONS "
1701 if(strncmp(line, sc, SIZEOF(sc)-1) == 0) {
1704 #define sc "features="
1705 t = strstr(line, sc);
1706 if(t != NULL && (isspace((int)t[-1]) || t[-1] == ';')) {
1709 am_release_feature_set(hostp->features);
1710 if((hostp->features = am_string_to_feature(t)) == NULL) {
1711 errbuf = vstralloc(hostp->hostname,
1712 ": bad features value: ",
1719 skip_quoted_line(s, ch);
1724 if(strncmp(line, sc, SIZEOF(sc) - 1) == 0) {
1725 t = line + SIZEOF(sc) - 1;
1730 skip_whitespace(t, tch);
1736 * If the "error" is that the "noop" service is unknown, it
1737 * just means the client is "old" (does not support the servie).
1738 * We can ignore this.
1740 if(hostp->features == NULL
1741 && pkt->type == P_NAK
1742 && (strcmp(t - 1, "unknown service: noop") == 0
1743 || strcmp(t - 1, "noop: invalid service") == 0)) {
1744 skip_quoted_line(s, ch);
1747 errbuf = vstralloc(hostp->hostname,
1748 (pkt->type == P_NAK) ? "NAK " : "",
1757 skip_quoted_string(t, tch);
1758 msgdisk_undo = t - 1;
1759 msgdisk_undo_ch = *msgdisk_undo;
1760 *msgdisk_undo = '\0';
1761 disk = unquote_string(msgdisk);
1762 skip_whitespace(t, tch);
1766 size_ = (OFF_T_FMT_TYPE)0;
1767 if (sscanf(t - 1, "%d SIZE " OFF_T_FMT , &level, &size_) != 2) {
1771 dp = lookup_hostdisk(hostp, disk);
1774 *msgdisk_undo = msgdisk_undo_ch; /* for error message */
1775 msgdisk_undo = NULL;
1778 log_add(L_ERROR, "%s: invalid reply from sendsize: `%s'\n",
1779 hostp->hostname, line);
1781 for(i = 0; i < MAX_LEVELS; i++) {
1782 if(est(dp)->level[i] == level) {
1783 est(dp)->est_size[i] = size;
1787 if(i == MAX_LEVELS) {
1788 goto bad_msg; /* this est wasn't requested */
1790 est(dp)->got_estimate++;
1792 skip_quoted_line(s, ch);
1795 if(hostp->up == HOST_READY && hostp->features == NULL) {
1797 * The client does not support the features list, so give it an
1800 dbprintf(("%s: no feature set from host %s\n",
1801 debug_prefix_time(NULL), hostp->hostname));
1802 hostp->features = am_set_default_feature_set();
1805 security_close_connection(sech, hostp->hostname);
1807 /* XXX what about disks that only got some estimates... do we care? */
1808 /* XXX amanda 2.1 treated that case as a bad msg */
1810 for(dp = hostp->disks; dp != NULL; dp = dp->hostnext) {
1811 if(dp->todo == 0) continue;
1812 if(est(dp)->state != DISK_ACTIVE &&
1813 est(dp)->state != DISK_PARTIALY_DONE) continue;
1815 if(est(dp)->state == DISK_ACTIVE) {
1816 remove_disk(&waitq, dp);
1818 else if(est(dp)->state == DISK_PARTIALY_DONE) {
1819 remove_disk(&pestq, dp);
1822 if(pkt->type == P_REP) {
1823 est(dp)->state = DISK_DONE;
1825 else if(pkt->type == P_PREP) {
1826 est(dp)->state = DISK_PARTIALY_DONE;
1829 if(est(dp)->level[0] == -1) continue; /* ignore this disk */
1832 qname = quote_string(dp->name);
1833 if(pkt->type == P_PREP) {
1834 fprintf(stderr,"%s: time %s: got partial result for host %s disk %s:",
1835 get_pname(), walltime_str(curclock()),
1836 dp->host->hostname, qname);
1837 fprintf(stderr," %d -> " OFF_T_FMT "K, %d -> " OFF_T_FMT "K, %d -> " OFF_T_FMT "K\n",
1838 est(dp)->level[0], (OFF_T_FMT_TYPE)est(dp)->est_size[0],
1839 est(dp)->level[1], (OFF_T_FMT_TYPE)est(dp)->est_size[1],
1840 est(dp)->level[2], (OFF_T_FMT_TYPE)est(dp)->est_size[2]);
1841 enqueue_disk(&pestq, dp);
1843 else if(pkt->type == P_REP) {
1844 fprintf(stderr,"%s: time %s: got result for host %s disk %s:",
1845 get_pname(), walltime_str(curclock()),
1846 dp->host->hostname, qname);
1847 fprintf(stderr," %d -> " OFF_T_FMT "K, %d -> " OFF_T_FMT "K, %d -> " OFF_T_FMT "K\n",
1848 est(dp)->level[0], (OFF_T_FMT_TYPE)est(dp)->est_size[0],
1849 est(dp)->level[1], (OFF_T_FMT_TYPE)est(dp)->est_size[1],
1850 est(dp)->level[2], (OFF_T_FMT_TYPE)est(dp)->est_size[2]);
1851 if((est(dp)->level[0] != -1 && est(dp)->est_size[0] > (off_t)0) ||
1852 (est(dp)->level[1] != -1 && est(dp)->est_size[1] > (off_t)0) ||
1853 (est(dp)->level[2] != -1 && est(dp)->est_size[2] > (off_t)0)) {
1855 if(est(dp)->level[2] != -1 && est(dp)->est_size[2] < (off_t)0) {
1857 "disk %s:%s, estimate of level %d failed.",
1858 dp->host->hostname, qname, est(dp)->level[2]);
1859 est(dp)->level[2] = -1;
1861 if(est(dp)->level[1] != -1 && est(dp)->est_size[1] < (off_t)0) {
1863 "disk %s:%s, estimate of level %d failed.",
1864 dp->host->hostname, qname,
1866 est(dp)->level[1] = -1;
1868 if(est(dp)->level[0] != -1 && est(dp)->est_size[0] < (off_t)0) {
1870 "disk %s:%s, estimate of level %d failed.",
1871 dp->host->hostname, qname, est(dp)->level[0]);
1872 est(dp)->level[0] = -1;
1874 enqueue_disk(&estq, dp);
1877 enqueue_disk(&failq, dp);
1878 if(est(dp)->got_estimate) {
1879 est(dp)->errstr = vstralloc("disk ", qname,
1880 ", all estimate failed", NULL);
1883 fprintf(stderr, "error result for host %s disk %s: missing estimate\n",
1884 dp->host->hostname, qname);
1885 est(dp)->errstr = vstralloc("missing result for ", qname,
1886 " in ", dp->host->hostname,
1899 /* msgdisk_undo is always NULL */
1900 /* if(msgdisk_undo) { */
1901 /* *msgdisk_undo = msgdisk_undo_ch; */
1902 /* msgdisk_undo = NULL; */
1904 errbuf = stralloc2(hostp->hostname, " NAK: [NAK parse failed]");
1905 fprintf(stderr, "got strange nak from %s:\n----\n%s----\n\n",
1906 hostp->hostname, pkt->body);
1911 *msgdisk_undo = msgdisk_undo_ch;
1912 msgdisk_undo = NULL;
1914 fprintf(stderr,"got a bad message, stopped at:\n");
1916 fprintf(stderr,"----\n%s----\n\n", line);
1917 errbuf = stralloc2("badly formatted response from ", hostp->hostname);
1922 for(dp = hostp->disks; dp != NULL; dp = dp->hostnext) {
1923 if(est(dp)->state != DISK_ACTIVE) continue;
1924 qname = quote_string(dp->name);
1925 est(dp)->state = DISK_DONE;
1926 if(est(dp)->state == DISK_ACTIVE) {
1927 est(dp)->state = DISK_DONE;
1928 remove_disk(&waitq, dp);
1929 enqueue_disk(&failq, dp);
1932 est(dp)->errstr = stralloc(errbuf);
1933 fprintf(stderr, "error result for host %s disk %s: %s\n",
1934 dp->host->hostname, qname, errbuf);
1940 * If there were no disks involved, make sure the error gets
1943 log_add(L_ERROR, "%s", errbuf);
1945 hostp->up = HOST_DONE;
1953 * ========================================================================
1958 static int schedule_order(disk_t *a, disk_t *b); /* subroutines */
1959 static int pick_inclevel(disk_t *dp);
1961 static void analyze_estimate(
1967 char *qname = quote_string(dp->name);
1971 fprintf(stderr, "pondering %s:%s... ",
1972 dp->host->hostname, qname);
1973 fprintf(stderr, "next_level0 %d last_level %d ",
1974 ep->next_level0, ep->last_level);
1976 if(get_info(dp->host->hostname, dp->name, &info) == 0) {
1980 ep->degr_level = -1;
1981 ep->degr_nsize = (off_t)-1;
1982 ep->degr_csize = (off_t)-1;
1984 if(ep->next_level0 <= 0 || (have_info && ep->last_level == 0
1985 && (info.command & FORCE_NO_BUMP))) {
1986 if(ep->next_level0 <= 0) {
1987 fprintf(stderr,"(due for level 0) ");
1990 ep->dump_nsize = est_size(dp, 0);
1991 ep->dump_csize = est_tape_size(dp, 0);
1992 if(ep->dump_csize <= (off_t)0) {
1994 "(no estimate for level 0, picking an incr level)\n");
1995 ep->dump_level = pick_inclevel(dp);
1996 ep->dump_nsize = est_size(dp, ep->dump_level);
1997 ep->dump_csize = est_tape_size(dp, ep->dump_level);
1999 if(ep->dump_nsize == (off_t)-1) {
2000 ep->dump_level = ep->dump_level + 1;
2001 ep->dump_nsize = est_size(dp, ep->dump_level);
2002 ep->dump_csize = est_tape_size(dp, ep->dump_level);
2006 total_lev0 += (double) ep->dump_csize;
2007 if(ep->last_level == -1 || dp->skip_incr) {
2008 fprintf(stderr,"(%s disk, can't switch to degraded mode)\n",
2009 dp->skip_incr? "skip-incr":"new");
2010 ep->degr_level = -1;
2011 ep->degr_nsize = (off_t)-1;
2012 ep->degr_csize = (off_t)-1;
2015 /* fill in degraded mode info */
2016 fprintf(stderr,"(picking inclevel for degraded mode)");
2017 ep->degr_level = pick_inclevel(dp);
2018 ep->degr_nsize = est_size(dp, ep->degr_level);
2019 ep->degr_csize = est_tape_size(dp, ep->degr_level);
2020 if(ep->degr_csize == (off_t)-1) {
2021 ep->degr_level = ep->degr_level + 1;
2022 ep->degr_nsize = est_size(dp, ep->degr_level);
2023 ep->degr_csize = est_tape_size(dp, ep->degr_level);
2025 if(ep->degr_csize == (off_t)-1) {
2026 fprintf(stderr,"(no inc estimate)");
2027 ep->degr_level = -1;
2029 fprintf(stderr,"\n");
2034 fprintf(stderr,"(not due for a full dump, picking an incr level)\n");
2035 /* XXX - if this returns -1 may be we should force a total? */
2036 ep->dump_level = pick_inclevel(dp);
2037 ep->dump_nsize = est_size(dp, ep->dump_level);
2038 ep->dump_csize = est_tape_size(dp, ep->dump_level);
2040 if(ep->dump_csize == (off_t)-1) {
2041 ep->dump_level = ep->last_level;
2042 ep->dump_nsize = est_size(dp, ep->dump_level);
2043 ep->dump_csize = est_tape_size(dp, ep->dump_level);
2045 if(ep->dump_csize == (off_t)-1) {
2046 ep->dump_level = ep->last_level + 1;
2047 ep->dump_nsize = est_size(dp, ep->dump_level);
2048 ep->dump_csize = est_tape_size(dp, ep->dump_level);
2050 if(ep->dump_csize == (off_t)-1) {
2052 ep->dump_nsize = est_size(dp, ep->dump_level);
2053 ep->dump_csize = est_tape_size(dp, ep->dump_level);
2057 fprintf(stderr," curr level %d nsize " OFF_T_FMT " csize " OFF_T_FMT " ",
2058 ep->dump_level, (OFF_T_FMT_TYPE)ep->dump_nsize,
2059 (OFF_T_FMT_TYPE)ep->dump_csize);
2061 insert_disk(&schedq, dp, schedule_order);
2063 total_size += (off_t)tt_blocksize_kb + ep->dump_csize + tape_mark;
2065 /* update the balanced size */
2066 if(!(dp->skip_full || dp->strategy == DS_NOFULL ||
2067 dp->strategy == DS_INCRONLY)) {
2070 lev0size = est_tape_size(dp, 0);
2071 if(lev0size == (off_t)-1) lev0size = ep->last_lev0size;
2073 balanced_size += (double)(lev0size / (off_t)runs_per_cycle);
2076 fprintf(stderr,"total size " OFF_T_FMT " total_lev0 %1.0lf balanced-lev0size %1.0lf\n",
2077 (OFF_T_FMT_TYPE)total_size, total_lev0, balanced_size);
2081 static void handle_failed(
2085 char *qname = quote_string(dp->name);
2088 * From George Scott <George.Scott@cc.monash.edu.au>:
2090 * If a machine is down when the planner is run it guesses from historical
2091 * data what the size of tonights dump is likely to be and schedules a
2092 * dump anyway. The dumper then usually discovers that that machine is
2093 * still down and ends up with a half full tape. Unfortunately the
2094 * planner had to delay another dump because it thought that the tape was
2095 * full. The fix here is for the planner to ignore unavailable machines
2096 * rather than ignore the fact that they are unavailable.
2101 if(est(dp)->last_level != -1) {
2103 "Could not get estimate for %s:%s, using historical data.",
2104 dp->host->hostname, qname);
2105 analyze_estimate(dp);
2111 errstr = est(dp)->errstr? est(dp)->errstr : "hmm, no error indicator!";
2113 fprintf(stderr, "%s: FAILED %s %s %s 0 [%s]\n",
2114 get_pname(), dp->host->hostname, qname, planner_timestamp, errstr);
2116 log_add(L_FAIL, "%s %s %s 0 [%s]", dp->host->hostname, qname,
2117 planner_timestamp, errstr);
2120 /* XXX - memory leak with *dp */
2125 * insert-sort by decreasing priority, then
2126 * by decreasing size within priority levels.
2129 static int schedule_order(
2136 diff = est(b)->dump_priority - est(a)->dump_priority;
2137 if(diff != 0) return diff;
2139 ldiff = est(b)->dump_csize - est(a)->dump_csize;
2140 if(ldiff < (off_t)0) return -1; /* XXX - there has to be a better way to dothis */
2141 if(ldiff > (off_t)0) return 1;
2146 static int pick_inclevel(
2149 int base_level, bump_level;
2150 off_t base_size, bump_size;
2154 base_level = est(dp)->last_level;
2156 /* if last night was level 0, do level 1 tonight, no ifs or buts */
2157 if(base_level == 0) {
2158 fprintf(stderr," picklev: last night 0, so tonight level 1\n");
2162 /* if no-full option set, always do level 1 */
2163 if(dp->strategy == DS_NOFULL) {
2164 fprintf(stderr," picklev: no-full set, so always level 1\n");
2168 base_size = est_size(dp, base_level);
2170 /* if we didn't get an estimate, we can't do an inc */
2171 if(base_size == (off_t)-1) {
2172 base_size = est_size(dp, base_level+1);
2173 if(base_size > (off_t)0) /* FORCE_BUMP */
2174 return base_level+1;
2175 fprintf(stderr," picklev: no estimate for level %d, so no incs\n", base_level);
2179 thresh = bump_thresh(base_level, est_size(dp, 0), dp->bumppercent, dp->bumpsize, dp->bumpmult);
2182 " pick: size " OFF_T_FMT " level %d days %d (thresh " OFF_T_FMT "K, %d days)\n",
2183 (OFF_T_FMT_TYPE)base_size, base_level, est(dp)->level_days,
2184 (OFF_T_FMT_TYPE)thresh, dp->bumpdays);
2187 || est(dp)->level_days < dp->bumpdays
2188 || base_size <= thresh)
2191 bump_level = base_level + 1;
2192 bump_size = est_size(dp, bump_level);
2194 if(bump_size == (off_t)-1) return base_level;
2196 fprintf(stderr, " pick: next size " OFF_T_FMT "... ",
2197 (OFF_T_FMT_TYPE)bump_size);
2199 if(base_size - bump_size < thresh) {
2200 fprintf(stderr, "not bumped\n");
2204 qname = quote_string(dp->name);
2205 fprintf(stderr, "BUMPED\n");
2206 log_add(L_INFO, "Incremental of %s:%s bumped to level %d.",
2207 dp->host->hostname, qname, bump_level);
2217 ** ========================================================================
2220 ** We have two strategies here:
2224 ** If we are trying to fit too much on the tape something has to go. We
2225 ** try to delay totals until tomorrow by converting them into incrementals
2226 ** and, if that is not effective enough, dropping incrementals altogether.
2227 ** While we are searching for the guilty dump (the one that is really
2228 ** causing the schedule to be oversize) we have probably trampled on a lot of
2229 ** innocent dumps, so we maintain a "before image" list and use this to
2230 ** put back what we can.
2232 ** 2. Promote dumps.
2234 ** We try to keep the amount of tape used by total dumps the same each night.
2235 ** If there is some spare tape in this run we have a look to see if any of
2236 ** tonights incrementals could be promoted to totals and leave us with a
2237 ** more balanced cycle.
2240 static void delay_one_dump(disk_t *dp, int delete, ...);
2241 static int promote_highest_priority_incremental(void);
2242 static int promote_hills(void);
2244 /* delay any dumps that will not fit */
2245 static void delay_dumps(void)
2252 off_t new_total; /* New total_size */
2253 char est_kb[20]; /* Text formatted dump size */
2254 int nb_forced_level_0;
2260 biq.head = biq.tail = NULL;
2263 ** 1. Delay dumps that are way oversize.
2265 ** Dumps larger that the size of the tapes we are using are just plain
2266 ** not going to fit no matter how many other dumps we drop. Delay
2267 ** oversize totals until tomorrow (by which time my owner will have
2268 ** resolved the problem!) and drop incrementals altogether. Naturally
2269 ** a large total might be delayed into a large incremental so these
2270 ** need to be checked for separately.
2273 for(dp = schedq.head; dp != NULL; dp = ndp) {
2274 int avail_tapes = 1;
2275 if (dp->tape_splitsize > (off_t)0)
2276 avail_tapes = conf_runtapes;
2278 ndp = dp->next; /* remove_disk zaps this */
2280 full_size = est_tape_size(dp, 0);
2281 if (full_size > tapetype_get_length(tape) * (off_t)avail_tapes) {
2282 char *qname = quote_string(dp->name);
2283 if (conf_runtapes > 1 && dp->tape_splitsize == (off_t)0) {
2284 log_add(L_WARNING, "disk %s:%s, full dump (" OFF_T_FMT
2285 "KB) will be larger than available tape space"
2286 ", you could define a splitsize",
2287 dp->host->hostname, qname,
2288 (OFF_T_FMT_TYPE)full_size);
2290 log_add(L_WARNING, "disk %s:%s, full dump (" OFF_T_FMT
2291 "KB) will be larger than available tape space",
2292 dp->host->hostname, qname,
2293 (OFF_T_FMT_TYPE)full_size);
2298 if (est(dp)->dump_csize == (off_t)-1 ||
2299 est(dp)->dump_csize <= tapetype_get_length(tape) * (off_t)avail_tapes) {
2303 /* Format dumpsize for messages */
2304 snprintf(est_kb, 20, OFF_T_FMT " KB,",
2305 (OFF_T_FMT_TYPE)est(dp)->dump_csize);
2307 if(est(dp)->dump_level == 0) {
2310 message = "but cannot incremental dump skip-incr disk";
2312 else if(est(dp)->last_level < 0) {
2314 message = "but cannot incremental dump new disk";
2316 else if(est(dp)->degr_level < 0) {
2318 message = "but no incremental estimate";
2320 else if (est(dp)->degr_csize > tapetype_get_length(tape)) {
2322 message = "incremental dump also larger than tape";
2326 message = "full dump delayed";
2331 message = "skipping incremental";
2333 delay_one_dump(dp, delete, "dump larger than available tape space,",
2334 est_kb, message, NULL);
2338 ** 2. Delay total dumps.
2340 ** Delay total dumps until tomorrow (or the day after!). We start with
2341 ** the lowest priority (most dispensable) and work forwards. We take
2342 ** care not to delay *all* the dumps since this could lead to a stale
2343 ** mate [for any one disk there are only three ways tomorrows dump will
2344 ** be smaller than todays: 1. we do a level 0 today so tomorows dump
2345 ** will be a level 1; 2. the disk gets more data so that it is bumped
2346 ** tomorrow (this can be a slow process); and, 3. the disk looses some
2347 ** data (when does that ever happen?)].
2350 nb_forced_level_0 = 0;
2352 for(dp = schedq.head; dp != NULL && preserve == NULL; dp = dp->next)
2353 if(est(dp)->dump_level == 0)
2356 /* 2.a. Do not delay forced full */
2357 for(dp = schedq.tail;
2358 dp != NULL && total_size > tape_length;
2362 if(est(dp)->dump_level != 0) continue;
2364 get_info(dp->host->hostname, dp->name, &info);
2365 if(info.command & FORCE_FULL) {
2366 nb_forced_level_0 += 1;
2371 if(dp != preserve) {
2373 /* Format dumpsize for messages */
2374 snprintf(est_kb, 20, OFF_T_FMT " KB,",
2375 (OFF_T_FMT_TYPE)est(dp)->dump_csize);
2379 message = "but cannot incremental dump skip-incr disk";
2381 else if(est(dp)->last_level < 0) {
2383 message = "but cannot incremental dump new disk";
2385 else if(est(dp)->degr_level < 0) {
2387 message = "but no incremental estimate";
2391 message = "full dump delayed";
2393 delay_one_dump(dp, delete, "dumps too big,", est_kb,
2398 /* 2.b. Delay forced full if needed */
2399 if(nb_forced_level_0 > 0 && total_size > tape_length) {
2400 for(dp = schedq.tail;
2401 dp != NULL && total_size > tape_length;
2405 if(est(dp)->dump_level == 0 && dp != preserve) {
2407 /* Format dumpsize for messages */
2408 snprintf(est_kb, 20, OFF_T_FMT " KB,",
2409 (OFF_T_FMT_TYPE)est(dp)->dump_csize);
2413 message = "but cannot incremental dump skip-incr disk";
2415 else if(est(dp)->last_level < 0) {
2417 message = "but cannot incremental dump new disk";
2419 else if(est(dp)->degr_level < 0) {
2421 message = "but no incremental estimate";
2425 message = "full dump delayed";
2427 delay_one_dump(dp, delete, "dumps too big,", est_kb,
2434 ** 3. Delay incremental dumps.
2436 ** Delay incremental dumps until tomorrow. This is a last ditch attempt
2437 ** at making things fit. Again, we start with the lowest priority (most
2438 ** dispensable) and work forwards.
2441 for(dp = schedq.tail;
2442 dp != NULL && total_size > tape_length;
2446 if(est(dp)->dump_level != 0) {
2448 /* Format dumpsize for messages */
2449 snprintf(est_kb, 20, OFF_T_FMT " KB,",
2450 (OFF_T_FMT_TYPE)est(dp)->dump_csize);
2452 delay_one_dump(dp, 1,
2453 "dumps way too big,",
2455 "must skip incremental dumps",
2461 ** 4. Reinstate delayed dumps.
2463 ** We might not have needed to stomp on all of the dumps we have just
2464 ** delayed above. Try to reinstate them all starting with the last one
2465 ** and working forwards. It is unlikely that the last one will fit back
2466 ** in but why complicate the code?
2469 /*@i@*/ for(bi = biq.tail; bi != NULL; bi = nbi) {
2470 int avail_tapes = 1;
2473 if(dp->tape_splitsize > (off_t)0)
2474 avail_tapes = conf_runtapes;
2477 new_total = total_size + (off_t)tt_blocksize_kb +
2478 bi->csize + (off_t)tape_mark;
2480 new_total = total_size - est(dp)->dump_csize + bi->csize;
2482 if((new_total <= tape_length) &&
2483 (bi->csize < (tapetype_get_length(tape) * (off_t)avail_tapes))) {
2485 total_size = new_total;
2487 if(bi->level == 0) {
2488 total_lev0 += (double) bi->csize;
2490 insert_disk(&schedq, dp, schedule_order);
2493 est(dp)->dump_level = bi->level;
2494 est(dp)->dump_nsize = bi->nsize;
2495 est(dp)->dump_csize = bi->csize;
2499 if(bi->next == NULL)
2500 biq.tail = bi->prev;
2502 (bi->next)->prev = bi->prev;
2503 if(bi->prev == NULL)
2504 biq.head = bi->next;
2506 (bi->prev)->next = bi->next;
2514 ** 5. Output messages about what we have done.
2516 ** We can't output messages while we are delaying dumps because we might
2517 ** reinstate them later. We remember all the messages and output them
2521 /*@i@*/ for(bi = biq.head; bi != NULL; bi = nbi) {
2524 fprintf(stderr, "%s: FAILED %s\n", get_pname(), bi->errstr);
2525 log_add(L_FAIL, "%s", bi->errstr);
2529 fprintf(stderr, " delay: %s now at level %d\n",
2530 bi->errstr, est(dp)->dump_level);
2531 log_add(L_INFO, "%s", bi->errstr);
2539 fprintf(stderr, " delay: Total size now " OFF_T_FMT ".\n",
2540 (OFF_T_FMT_TYPE)total_size);
2547 * Remove a dump or modify it from full to incremental.
2548 * Keep track of it on the bi q in case we can add it back later.
2551 static void delay_one_dump,
2557 char level_str[NUM_STR_SIZE];
2560 char *qname = quote_string(dp->name);
2562 arglist_start(argp, delete);
2564 total_size -= (off_t)tt_blocksize_kb + est(dp)->dump_csize + (off_t)tape_mark;
2565 if(est(dp)->dump_level == 0) {
2566 total_lev0 -= (double) est(dp)->dump_csize;
2569 bi = alloc(SIZEOF(bi_t));
2571 bi->prev = biq.tail;
2572 if(biq.tail == NULL)
2575 biq.tail->next = bi;
2578 bi->deleted = delete;
2580 bi->level = est(dp)->dump_level;
2581 bi->nsize = est(dp)->dump_nsize;
2582 bi->csize = est(dp)->dump_csize;
2584 snprintf(level_str, SIZEOF(level_str), "%d", est(dp)->dump_level);
2585 bi->errstr = vstralloc(dp->host->hostname,
2587 " ", planner_timestamp ? planner_timestamp : "?",
2591 while ((next = arglist_val(argp, char *)) != NULL) {
2592 bi->errstr = newvstralloc(bi->errstr, bi->errstr, sep, next, NULL);
2595 strappend(bi->errstr, "]");
2599 remove_disk(&schedq, dp);
2601 est(dp)->dump_level = est(dp)->degr_level;
2602 est(dp)->dump_nsize = est(dp)->degr_nsize;
2603 est(dp)->dump_csize = est(dp)->degr_csize;
2604 total_size += (off_t)tt_blocksize_kb + est(dp)->dump_csize + (off_t)tape_mark;
2611 static int promote_highest_priority_incremental(void)
2613 disk_t *dp, *dp1, *dp_promote;
2614 off_t new_size, new_total, new_lev0;
2616 int nb_today, nb_same_day, nb_today2;
2617 int nb_disk_today, nb_disk_same_day;
2621 * return 1 if did so; must update total_size correctly; must not
2622 * cause total_size to exceed tape_length
2626 for(dp = schedq.head; dp != NULL; dp = dp->next) {
2628 est(dp)->promote = -1000;
2630 if(est_size(dp,0) <= (off_t)0)
2633 if(est(dp)->next_level0 <= 0)
2636 if(est(dp)->next_level0 > dp->maxpromoteday)
2639 new_size = est_tape_size(dp, 0);
2640 new_total = total_size - est(dp)->dump_csize + new_size;
2641 new_lev0 = (off_t)total_lev0 + new_size;
2646 nb_disk_same_day = 0;
2647 for(dp1 = schedq.head; dp1 != NULL; dp1 = dp1->next) {
2648 if(est(dp1)->dump_level == 0)
2650 else if(est(dp1)->next_level0 == est(dp)->next_level0)
2652 if(strcmp(dp->host->hostname, dp1->host->hostname) == 0) {
2653 if(est(dp1)->dump_level == 0)
2655 else if(est(dp1)->next_level0 == est(dp)->next_level0)
2660 /* do not promote if overflow tape */
2661 if(new_total > tape_length)
2664 /* do not promote if overflow balanced size and something today */
2665 /* promote if nothing today */
2666 if((new_lev0 > (off_t)(balanced_size + balance_threshold)) &&
2667 (nb_disk_today > 0))
2670 /* do not promote if only one disk due that day and nothing today */
2671 if(nb_disk_same_day == 1 && nb_disk_today == 0)
2674 nb_today2 = nb_today*nb_today;
2675 if(nb_today == 0 && nb_same_day > 1)
2678 if(nb_same_day >= nb_today2) {
2679 est(dp)->promote = ((nb_same_day - nb_today2)*(nb_same_day - nb_today2)) +
2680 conf_dumpcycle - est(dp)->next_level0;
2683 est(dp)->promote = -nb_today2 +
2684 conf_dumpcycle - est(dp)->next_level0;
2687 qname = quote_string(dp->name);
2688 if(!dp_promote || est(dp_promote)->promote < est(dp)->promote) {
2690 fprintf(stderr," try %s:%s %d %d %d = %d\n",
2691 dp->host->hostname, qname, nb_same_day, nb_today, est(dp)->next_level0, est(dp)->promote);
2694 fprintf(stderr,"no try %s:%s %d %d %d = %d\n",
2695 dp->host->hostname, qname, nb_same_day, nb_today, est(dp)->next_level0, est(dp)->promote);
2703 qname = quote_string(dp->name);
2704 new_size = est_tape_size(dp, 0);
2705 new_total = total_size - est(dp)->dump_csize + new_size;
2706 new_lev0 = (off_t)total_lev0 + new_size;
2708 total_size = new_total;
2709 total_lev0 = (double)new_lev0;
2710 check_days = est(dp)->next_level0;
2711 est(dp)->degr_level = est(dp)->dump_level;
2712 est(dp)->degr_nsize = est(dp)->dump_nsize;
2713 est(dp)->degr_csize = est(dp)->dump_csize;
2714 est(dp)->dump_level = 0;
2715 est(dp)->dump_nsize = est_size(dp, 0);
2716 est(dp)->dump_csize = new_size;
2717 est(dp)->next_level0 = 0;
2720 " promote: moving %s:%s up, total_lev0 %1.0lf, total_size " OFF_T_FMT "\n",
2721 dp->host->hostname, qname,
2722 total_lev0, (OFF_T_FMT_TYPE)total_size);
2725 "Full dump of %s:%s promoted from %d day%s ahead.",
2726 dp->host->hostname, qname,
2727 check_days, (check_days == 1) ? "" : "s");
2735 static int promote_hills(void)
2738 struct balance_stats {
2750 /* If we are already doing a level 0 don't bother */
2754 /* Do the guts of an "amadmin balance" */
2755 my_dumpcycle = conf_dumpcycle;
2756 if(my_dumpcycle > 10000) my_dumpcycle = 10000;
2758 sp = (struct balance_stats *)
2759 alloc(SIZEOF(struct balance_stats) * my_dumpcycle);
2761 for(days = 0; days < my_dumpcycle; days++) {
2763 sp[days].size = (off_t)0;
2766 for(dp = schedq.head; dp != NULL; dp = dp->next) {
2767 days = est(dp)->next_level0; /* This is > 0 by definition */
2768 if(days<my_dumpcycle && !dp->skip_full && dp->strategy != DS_NOFULL &&
2769 dp->strategy != DS_INCRONLY) {
2771 sp[days].size += est(dp)->last_lev0size;
2775 /* Search for a suitable big hill and cut it down */
2777 /* Find the tallest hill */
2778 hill_size = (off_t)0;
2779 for(days = 0; days < my_dumpcycle; days++) {
2780 if(sp[days].disks > 1 && sp[days].size > hill_size) {
2781 hill_size = sp[days].size;
2786 if(hill_size <= (off_t)0) break; /* no suitable hills */
2788 /* Find all the dumps in that hill and try and remove one */
2789 for(dp = schedq.head; dp != NULL; dp = dp->next) {
2790 if(est(dp)->next_level0 != hill_days ||
2791 est(dp)->next_level0 > dp->maxpromoteday ||
2793 dp->strategy == DS_NOFULL ||
2794 dp->strategy == DS_INCRONLY)
2796 new_size = est_tape_size(dp, 0);
2797 new_total = total_size - est(dp)->dump_csize + new_size;
2798 if(new_total > tape_length)
2800 /* We found a disk we can promote */
2801 qname = quote_string(dp->name);
2802 total_size = new_total;
2803 total_lev0 += (double)new_size;
2804 est(dp)->degr_level = est(dp)->dump_level;
2805 est(dp)->degr_nsize = est(dp)->dump_nsize;
2806 est(dp)->degr_csize = est(dp)->dump_csize;
2807 est(dp)->dump_level = 0;
2808 est(dp)->next_level0 = 0;
2809 est(dp)->dump_nsize = est_size(dp, 0);
2810 est(dp)->dump_csize = new_size;
2813 " promote: moving %s:%s up, total_lev0 %1.0lf, total_size " OFF_T_FMT "\n",
2814 dp->host->hostname, qname,
2815 total_lev0, (OFF_T_FMT_TYPE)total_size);
2818 "Full dump of %s:%s specially promoted from %d day%s ahead.",
2819 dp->host->hostname, qname,
2820 hill_days, (hill_days == 1) ? "" : "s");
2826 /* All the disks in that hill were unsuitable. */
2827 sp[hill_days].disks = 0; /* Don't get tricked again */
2835 * ========================================================================
2838 * XXX - memory leak - we shouldn't just throw away *dp
2840 static void output_scheduleline(
2844 time_t dump_time = 0, degr_time = 0;
2845 double dump_kps = 0, degr_kps = 0;
2846 char *schedline = NULL, *degr_str = NULL;
2847 char dump_priority_str[NUM_STR_SIZE];
2848 char dump_level_str[NUM_STR_SIZE];
2849 char dump_nsize_str[NUM_STR_SIZE];
2850 char dump_csize_str[NUM_STR_SIZE];
2851 char dump_time_str[NUM_STR_SIZE];
2852 char dump_kps_str[NUM_STR_SIZE];
2853 char degr_level_str[NUM_STR_SIZE];
2854 char degr_nsize_str[NUM_STR_SIZE];
2855 char degr_csize_str[NUM_STR_SIZE];
2856 char degr_time_str[NUM_STR_SIZE];
2857 char degr_kps_str[NUM_STR_SIZE];
2858 char *dump_date, *degr_date;
2861 char *qname = quote_string(dp->name);
2865 if(ep->dump_csize == (off_t)-1) {
2866 /* no estimate, fail the disk */
2868 "%s: FAILED %s %s %s %d [no estimate]\n",
2870 dp->host->hostname, qname, planner_timestamp, ep->dump_level);
2871 log_add(L_FAIL, "%s %s %s %d [no estimate]",
2872 dp->host->hostname, qname, planner_timestamp, ep->dump_level);
2877 dump_date = degr_date = (char *)0;
2878 for(i = 0; i < MAX_LEVELS; i++) {
2879 if(ep->dump_level == ep->level[i])
2880 dump_date = ep->dumpdate[i];
2881 if(ep->degr_level == ep->level[i])
2882 degr_date = ep->dumpdate[i];
2885 #define fix_rate(rate) (rate < 1.0 ? DEFAULT_DUMPRATE : rate)
2887 if(ep->dump_level == 0) {
2888 dump_kps = fix_rate(ep->fullrate);
2889 dump_time = (time_t)((double)ep->dump_csize / dump_kps);
2891 if(ep->degr_csize != (off_t)-1) {
2892 degr_kps = fix_rate(ep->incrrate);
2893 degr_time = (time_t)((double)ep->degr_csize / degr_kps);
2897 dump_kps = fix_rate(ep->incrrate);
2898 dump_time = (time_t)((double)ep->dump_csize / dump_kps);
2901 if(ep->dump_level == 0 && ep->degr_csize != (off_t)-1) {
2902 snprintf(degr_level_str, sizeof(degr_level_str),
2903 "%d", ep->degr_level);
2904 snprintf(degr_nsize_str, sizeof(degr_nsize_str),
2905 OFF_T_FMT, (OFF_T_FMT_TYPE)ep->degr_nsize);
2906 snprintf(degr_csize_str, sizeof(degr_csize_str),
2907 OFF_T_FMT, (OFF_T_FMT_TYPE)ep->degr_csize);
2908 snprintf(degr_time_str, sizeof(degr_time_str),
2909 OFF_T_FMT, (OFF_T_FMT_TYPE)degr_time);
2910 snprintf(degr_kps_str, sizeof(degr_kps_str),
2912 degr_str = vstralloc(" ", degr_level_str,
2914 " ", degr_nsize_str,
2915 " ", degr_csize_str,
2920 snprintf(dump_priority_str, SIZEOF(dump_priority_str),
2921 "%d", ep->dump_priority);
2922 snprintf(dump_level_str, SIZEOF(dump_level_str),
2923 "%d", ep->dump_level);
2924 snprintf(dump_nsize_str, sizeof(dump_nsize_str),
2925 OFF_T_FMT, (OFF_T_FMT_TYPE)ep->dump_nsize);
2926 snprintf(dump_csize_str, sizeof(dump_csize_str),
2927 OFF_T_FMT, (OFF_T_FMT_TYPE)ep->dump_csize);
2928 snprintf(dump_time_str, sizeof(dump_time_str),
2929 OFF_T_FMT, (OFF_T_FMT_TYPE)dump_time);
2930 snprintf(dump_kps_str, sizeof(dump_kps_str),
2932 features = am_feature_to_string(dp->host->features);
2933 schedline = vstralloc("DUMP ",dp->host->hostname,
2936 " ", planner_timestamp,
2937 " ", dump_priority_str,
2938 " ", dump_level_str,
2940 " ", dump_nsize_str,
2941 " ", dump_csize_str,
2944 degr_str ? degr_str : "",
2947 fputs(schedline, stdout);
2948 fputs(schedline, stderr);