X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=server-src%2Fdriver.c;h=e51612104c6814485274f788eb1d8d79bcbe96ee;hb=d74dc4d908fcbc1a4ef474edaf51e61ec90eab6b;hp=594f694ec052b660c1e0839479752537c4a57994;hpb=34197d9f46a5f4e944378cbb65fca32ee0eec7b9;p=debian%2Famanda diff --git a/server-src/driver.c b/server-src/driver.c index 594f694..e516121 100644 --- a/server-src/driver.c +++ b/server-src/driver.c @@ -24,7 +24,7 @@ * file named AUTHORS, in the root directory of this distribution. */ /* - * $Id: driver.c,v 1.198.2.6 2006/12/27 14:44:48 martinea Exp $ + * $Id: driver.c 6512 2007-05-24 17:00:24Z ian $ * * controlling process for the Amanda backup system */ @@ -34,8 +34,6 @@ * tape. Probably not effective though, should do this in planner. */ -#define HOLD_DEBUG - #include "amanda.h" #include "clock.h" #include "conffile.h" @@ -44,12 +42,30 @@ #include "holding.h" #include "infofile.h" #include "logfile.h" -#include "statfs.h" +#include "fsusage.h" #include "version.h" #include "driverio.h" #include "server_util.h" - -static disklist_t waitq, runq, tapeq, roomq; +#include "timestamp.h" + +#define driver_debug(i, ...) do { \ + if ((i) <= debug_driver) { \ + dbprintf(__VA_ARGS__); \ + } \ +} while (0) + +#define hold_debug(i, ...) do { \ + if ((i) <= debug_holding) { \ + dbprintf(__VA_ARGS__); \ + } \ +} while (0) + +static disklist_t waitq; // dle waiting estimate result +static disklist_t runq; // dle waiting to be dumped to holding disk +static disklist_t directq; // dle waiting to be dumped directly to tape +static disklist_t tapeq; // dle on holding disk waiting to be written + // to tape +static disklist_t roomq; // dle waiting for more space on holding disk static int pending_aborts; static disk_t *taper_disk; static int degraded_mode; @@ -61,7 +77,7 @@ static int inparallel; static int nodump = 0; static off_t tape_length = (off_t)0; static off_t tape_left = (off_t)0; -static int current_tape = 1; +static int current_tape = 0; static int conf_taperalgo; static int conf_runtapes; static time_t sleep_time; @@ -70,30 +86,44 @@ static char *driver_timestamp; static char *hd_driver_timestamp; static am_host_t *flushhost = NULL; static int need_degraded=0; - +static holdalloc_t *holdalloc; +static int num_holdalloc; static event_handle_t *dumpers_ev_time = NULL; static event_handle_t *schedule_ev_read = NULL; +static int conf_flush_threshold_dumped; +static int conf_flush_threshold_scheduled; +static int conf_taperflush; +static off_t flush_threshold_dumped; +static off_t flush_threshold_scheduled; +static off_t taperflush; +static int schedule_done; // 1 if we don't wait for a + // schedule from the planner +static int force_flush; // All dump are terminated, we + // must now respect taper_flush static int wait_children(int count); static void wait_for_children(void); -static void allocate_bandwidth(interface_t *ip, unsigned long kps); +static void allocate_bandwidth(netif_t *ip, unsigned long kps); static int assign_holdingdisk(assignedhd_t **holdp, disk_t *diskp); static void adjust_diskspace(disk_t *diskp, cmd_t cmd); static void delete_diskspace(disk_t *diskp); static assignedhd_t **build_diskspace(char *destname); static int client_constrained(disk_t *dp); -static void deallocate_bandwidth(interface_t *ip, unsigned long kps); +static void deallocate_bandwidth(netif_t *ip, unsigned long kps); static void dump_schedule(disklist_t *qp, char *str); -static int dump_to_tape(disk_t *dp); +static void dump_to_tape(disk_t *dp); static assignedhd_t **find_diskspace(off_t size, int *cur_idle, assignedhd_t *preferred); -static unsigned long free_kps(interface_t *ip); +static unsigned long free_kps(netif_t *ip); static off_t free_space(void); -static void dumper_result(disk_t *dp); +static void dumper_chunker_result(disk_t *dp); +static void dumper_taper_result(disk_t *dp); +static void file_taper_result(disk_t *dp); static void handle_dumper_result(void *); static void handle_chunker_result(void *); static void handle_dumpers_time(void *); static void handle_taper_result(void *); + static void holdingdisk_state(char *time_str); static dumper_t *idle_dumper(void); static void interface_state(char *time_str); @@ -105,59 +135,69 @@ static void startaflush(void); static void start_degraded_mode(disklist_t *queuep); static void start_some_dumps(disklist_t *rq); static void continue_port_dumps(void); -static void update_failed_dump_to_tape(disk_t *); -#if 0 -static void dump_state(const char *str); -#endif -int main(int main_argc, char **main_argv); +static void update_failed_dump(disk_t *); + +typedef enum { + TAPE_ACTION_NO_ACTION = 0, + TAPE_ACTION_NEW_TAPE = (1 << 0), + TAPE_ACTION_NO_NEW_TAPE = (1 << 1), + TAPE_ACTION_START_A_FLUSH = (1 << 2) +} TapeAction; + +static TapeAction tape_action(char **why_no_new_tape); static const char *idle_strings[] = { #define NOT_IDLE 0 - "not-idle", + T_("not-idle"), #define IDLE_NO_DUMPERS 1 - "no-dumpers", + T_("no-dumpers"), #define IDLE_START_WAIT 2 - "start-wait", + T_("start-wait"), #define IDLE_NO_HOLD 3 - "no-hold", + T_("no-hold"), #define IDLE_CLIENT_CONSTRAINED 4 - "client-constrained", -#define IDLE_NO_DISKSPACE 5 - "no-diskspace", -#define IDLE_TOO_LARGE 6 - "file-too-large", -#define IDLE_NO_BANDWIDTH 7 - "no-bandwidth", -#define IDLE_TAPER_WAIT 8 - "taper-wait", + T_("client-constrained"), +#define IDLE_NO_BANDWIDTH 5 + T_("no-bandwidth"), +#define IDLE_NO_DISKSPACE 6 + T_("no-diskspace") }; int main( - int main_argc, - char ** main_argv) + int argc, + char ** argv) { disklist_t origq; disk_t *diskp; int dsk; dumper_t *dumper; char *newdir = NULL; - generic_fs_stats_t fs; + struct fs_usage fsusage; holdingdisk_t *hdp; - unsigned long malloc_hist_1, malloc_size_1; - unsigned long malloc_hist_2, malloc_size_2; unsigned long reserve = 100; - char *conffile; char *conf_diskfile; cmd_t cmd; int result_argc; - char *result_argv[MAX_ARGS+1]; + char **result_argv = NULL; char *taper_program; char *conf_tapetype; tapetype_t *tape; char *line; - int new_argc, my_argc; - char **new_argv, **my_argv; + char hostname[1025]; + intmax_t kb_avail; + config_overwrites_t *cfg_ovr = NULL; + char *cfg_opt = NULL; + holdalloc_t *ha, *ha_last; + + /* + * Configure program for internationalization: + * 1) Only set the message locale for now. + * 2) Set textdomain for all amanda related programs to "amanda" + * We don't want to be forced to support dozens of message catalogs. + */ + setlocale(LC_MESSAGES, "C"); + textdomain("amanda"); safe_fd(-1, 0); @@ -173,55 +213,44 @@ main( /* Don't die when child closes pipe */ signal(SIGPIPE, SIG_IGN); - malloc_size_1 = malloc_inuse(&malloc_hist_1); - erroutput_type = (ERR_AMANDALOG|ERR_INTERACTIVE); set_logerror(logerror); startclock(); - parse_server_conf(main_argc, main_argv, &new_argc, &new_argv); - my_argc = new_argc; - my_argv = new_argv; - - printf("%s: pid %ld executable %s version %s\n", - get_pname(), (long) getpid(), my_argv[0], version()); - - if (my_argc > 1) { - config_name = stralloc(my_argv[1]); - config_dir = vstralloc(CONFIG_DIR, "/", config_name, "/", NULL); - if(my_argc > 2) { - if(strncmp(my_argv[2], "nodump", 6) == 0) { - nodump = 1; - } - } + cfg_ovr = extract_commandline_config_overwrites(&argc, &argv); - } else { + if (argc > 1) + cfg_opt = argv[1]; + config_init(CONFIG_INIT_EXPLICIT_NAME | CONFIG_INIT_USE_CWD, cfg_opt); + apply_config_overwrites(cfg_ovr); - char my_cwd[STR_SIZE]; + conf_diskfile = config_dir_relative(getconf_str(CNF_DISKFILE)); + read_diskfile(conf_diskfile, &origq); + amfree(conf_diskfile); - if (getcwd(my_cwd, SIZEOF(my_cwd)) == NULL) { - error("cannot determine current working directory"); - /*NOTREACHED*/ - } - config_dir = stralloc2(my_cwd, "/"); - if ((config_name = strrchr(my_cwd, '/')) != NULL) { - config_name = stralloc(config_name + 1); + if (config_errors(NULL) >= CFGERR_WARNINGS) { + config_print_errors(); + if (config_errors(NULL) >= CFGERR_ERRORS) { + g_critical(_("errors processing config file")); } } - safe_cd(); + log_add(L_INFO, "%s pid %ld", get_pname(), (long)getpid()); + g_printf(_("%s: pid %ld executable %s version %s\n"), + get_pname(), (long) getpid(), argv[0], version()); - conffile = stralloc2(config_dir, CONFFILE_NAME); - if(read_conffile(conffile)) { - error("errors processing config file \"%s\"", conffile); - /*NOTREACHED*/ + if(argc > 2) { + if(strncmp(argv[2], "nodump", 6) == 0) { + nodump = 1; + } } - amfree(conffile); - dbrename(config_name, DBG_SUBDIR_SERVER); + safe_cd(); /* do this *after* config_init */ - report_bad_conf_arg(); + check_running_as(RUNNING_AS_DUMPUSER); + + dbrename(get_config_name(), DBG_SUBDIR_SERVER); amfree(driver_timestamp); /* read timestamp from stdin */ @@ -231,14 +260,17 @@ main( amfree(line); } if ( line == NULL ) { - error("Did not get DATE line from planner"); + error(_("Did not get DATE line from planner")); /*NOTREACHED*/ } driver_timestamp = alloc(15); strncpy(driver_timestamp, &line[5], 14); driver_timestamp[14] = '\0'; amfree(line); - log_add(L_START,"date %s", driver_timestamp); + log_add(L_START,_("date %s"), driver_timestamp); + + gethostname(hostname, SIZEOF(hostname)); + log_add(L_STATS,_("hostname %s"), hostname); /* check that we don't do many dump in a day and usetimestamps is off */ if(strlen(driver_timestamp) == 8) { @@ -249,21 +281,21 @@ main( char *oldlogfile = vstralloc(conf_logdir, "/oldlog/log.", driver_timestamp, ".0", NULL); if(access(logfile, F_OK) == 0 || access(oldlogfile, F_OK) == 0) { - log_add(L_WARNING, "WARNING: This is not the first amdump run today. Enable the usetimestamps option in the configuration file if you want to run amdump more than once per calendar day."); + log_add(L_WARNING, _("WARNING: This is not the first amdump run today. Enable the usetimestamps option in the configuration file if you want to run amdump more than once per calendar day.")); } amfree(oldlogfile); amfree(logfile); } - hd_driver_timestamp = construct_timestamp(NULL); + hd_driver_timestamp = get_timestamp_from_time(0); } else { hd_driver_timestamp = stralloc(driver_timestamp); } - taper_program = vstralloc(libexecdir, "/", "taper", versionsuffix(), NULL); - dumper_program = vstralloc(libexecdir, "/", "dumper", versionsuffix(), + taper_program = vstralloc(amlibexecdir, "/", "taper", versionsuffix(), NULL); + dumper_program = vstralloc(amlibexecdir, "/", "dumper", versionsuffix(), NULL); - chunker_program = vstralloc(libexecdir, "/", "chunker", versionsuffix(), + chunker_program = vstralloc(amlibexecdir, "/", "chunker", versionsuffix(), NULL); conf_taperalgo = getconf_taperalgo(CNF_TAPERALGO); @@ -271,21 +303,18 @@ main( conf_runtapes = getconf_int(CNF_RUNTAPES); tape = lookup_tapetype(conf_tapetype); tape_length = tapetype_get_length(tape); - printf("driver: tape size " OFF_T_FMT "\n", (OFF_T_FMT_TYPE)tape_length); + g_printf("driver: tape size %lld\n", (long long)tape_length); + conf_flush_threshold_dumped = getconf_int(CNF_FLUSH_THRESHOLD_DUMPED); + conf_flush_threshold_scheduled = getconf_int(CNF_FLUSH_THRESHOLD_SCHEDULED); + conf_taperflush = getconf_int(CNF_TAPERFLUSH); - /* start initializing: read in databases */ + flush_threshold_dumped = (conf_flush_threshold_dumped * tape_length) / 100; + flush_threshold_scheduled = (conf_flush_threshold_scheduled * tape_length) / 100; + taperflush = (conf_taperflush *tape_length) / 100; - conf_diskfile = getconf_str(CNF_DISKFILE); - if (*conf_diskfile == '/') { - conf_diskfile = stralloc(conf_diskfile); - } else { - conf_diskfile = stralloc2(config_dir, conf_diskfile); - } - if (read_diskfile(conf_diskfile, &origq) < 0) { - error("could not load disklist \"%s\"", conf_diskfile); - /*NOTREACHED*/ - } - amfree(conf_diskfile); + driver_debug(1, _("flush_threshold_dumped: %lld\n"), (long long)flush_threshold_dumped); + driver_debug(1, _("flush_threshold_scheduled: %lld\n"), (long long)flush_threshold_scheduled); + driver_debug(1, _("taperflush: %lld\n"), (long long)taperflush); /* set up any configuration-dependent variables */ @@ -294,62 +323,81 @@ main( reserve = (unsigned long)getconf_int(CNF_RESERVE); total_disksize = (off_t)0; - for(hdp = getconf_holdingdisks(), dsk = 0; hdp != NULL; hdp = hdp->next, dsk++) { - hdp->up = (void *)alloc(SIZEOF(holdalloc_t)); - holdalloc(hdp)->allocated_dumpers = 0; - holdalloc(hdp)->allocated_space = (off_t)0; + ha_last = NULL; + num_holdalloc = 0; + for(hdp = getconf_holdingdisks(), dsk = 0; hdp != NULL; hdp = holdingdisk_next(hdp), dsk++) { + ha = alloc(SIZEOF(holdalloc_t)); + num_holdalloc++; + + /* link the list in the same order as getconf_holdingdisks's results */ + ha->next = NULL; + if (ha_last == NULL) + holdalloc = ha; + else + ha_last->next = ha; + ha_last = ha; + + ha->hdisk = hdp; + ha->allocated_dumpers = 0; + ha->allocated_space = (off_t)0; + ha->disksize = holdingdisk_get_disksize(hdp); - if(get_fs_stats(holdingdisk_get_diskdir(hdp), &fs) == -1 + /* get disk size */ + if(get_fs_usage(holdingdisk_get_diskdir(hdp), NULL, &fsusage) == -1 || access(holdingdisk_get_diskdir(hdp), W_OK) == -1) { - log_add(L_WARNING, "WARNING: ignoring holding disk %s: %s\n", + log_add(L_WARNING, _("WARNING: ignoring holding disk %s: %s\n"), holdingdisk_get_diskdir(hdp), strerror(errno)); - hdp->disksize = 0L; + ha->disksize = 0L; continue; } - if(fs.avail != (off_t)-1) { - if(hdp->disksize > (off_t)0) { - if(hdp->disksize > fs.avail) { - log_add(L_WARNING, - "WARNING: %s: " OFF_T_FMT " KB requested, " - "but only " OFF_T_FMT " KB available.", - holdingdisk_get_diskdir(hdp), - (OFF_T_FMT_TYPE)hdp->disksize, - (OFF_T_FMT_TYPE)fs.avail); - hdp->disksize = fs.avail; - } - } - else if((fs.avail + hdp->disksize) < (off_t)0) { + /* do the division first to avoid potential integer overflow */ + if (fsusage.fsu_bavail_top_bit_set) + kb_avail = 0; + else + kb_avail = fsusage.fsu_bavail / 1024 * fsusage.fsu_blocksize; + + if(ha->disksize > (off_t)0) { + if(ha->disksize > kb_avail) { log_add(L_WARNING, - "WARNING: %s: not " OFF_T_FMT " KB free.", - holdingdisk_get_diskdir(hdp), -hdp->disksize); - hdp->disksize = (off_t)0; - continue; + _("WARNING: %s: %lld KB requested, " + "but only %lld KB available."), + holdingdisk_get_diskdir(hdp), + (long long)ha->disksize, + (long long)kb_avail); + ha->disksize = kb_avail; } - else - hdp->disksize += fs.avail; } + /* ha->disksize is negative; use all but that amount */ + else if(kb_avail < -ha->disksize) { + log_add(L_WARNING, + _("WARNING: %s: not %lld KB free."), + holdingdisk_get_diskdir(hdp), + (long long)-ha->disksize); + ha->disksize = (off_t)0; + continue; + } + else + ha->disksize += kb_avail; - printf("driver: adding holding disk %d dir %s size " - OFF_T_FMT " chunksize " OFF_T_FMT "\n", + g_printf(_("driver: adding holding disk %d dir %s size %lld chunksize %lld\n"), dsk, holdingdisk_get_diskdir(hdp), - (OFF_T_FMT_TYPE)hdp->disksize, - (OFF_T_FMT_TYPE)(holdingdisk_get_chunksize(hdp))); + (long long)ha->disksize, + (long long)(holdingdisk_get_chunksize(hdp))); newdir = newvstralloc(newdir, holdingdisk_get_diskdir(hdp), "/", hd_driver_timestamp, NULL); if(!mkholdingdir(newdir)) { - hdp->disksize = (off_t)0; + ha->disksize = (off_t)0; } - total_disksize += hdp->disksize; + total_disksize += ha->disksize; } reserved_space = total_disksize * (off_t)(reserve / 100); - printf("reserving " OFF_T_FMT " out of " OFF_T_FMT - " for degraded-mode dumps\n", - (OFF_T_FMT_TYPE)reserved_space, (OFF_T_FMT_TYPE)free_space()); + g_printf(_("reserving %lld out of %lld for degraded-mode dumps\n"), + (long long)reserved_space, (long long)free_space()); amfree(newdir); @@ -376,39 +424,45 @@ main( runq.head = NULL; runq.tail = NULL; + directq.head = NULL; + directq.tail = NULL; waitq = origq; + taper_state = TAPER_STATE_DEFAULT; tapeq = read_flush(); roomq.head = roomq.tail = NULL; - log_add(L_STATS, "startup time %s", walltime_str(curclock())); + log_add(L_STATS, _("startup time %s"), walltime_str(curclock())); - printf("driver: start time %s inparallel %d bandwidth %lu diskspace " - OFF_T_FMT " ", walltime_str(curclock()), inparallel, - free_kps((interface_t *)0), (OFF_T_FMT_TYPE)free_space()); - printf(" dir %s datestamp %s driver: drain-ends tapeq %s big-dumpers %s\n", + g_printf(_("driver: start time %s inparallel %d bandwidth %lu diskspace %lld "), walltime_str(curclock()), inparallel, + free_kps(NULL), (long long)free_space()); + g_printf(_(" dir %s datestamp %s driver: drain-ends tapeq %s big-dumpers %s\n"), "OBSOLETE", driver_timestamp, taperalgo2str(conf_taperalgo), getconf_str(CNF_DUMPORDER)); fflush(stdout); /* ok, planner is done, now lets see if the tape is ready */ - if(conf_runtapes > 0) { - cmd = getresult(taper, 1, &result_argc, result_argv, MAX_ARGS+1); - - if(cmd != TAPER_OK) { + if (conf_runtapes > 0) { + cmd = getresult(taper, 1, &result_argc, &result_argv); + if (cmd != TAPER_OK) { /* no tape, go into degraded mode: dump to holding disk */ - need_degraded=1; + need_degraded = 1; } - } - else { - need_degraded=1; + } else { + need_degraded = 1; } tape_left = tape_length; taper_busy = 0; + amfree(taper_input_error); + amfree(taper_tape_error); taper_disk = NULL; taper_ev_read = NULL; + + schedule_done = nodump; + force_flush = 0; + if(!need_degraded) startaflush(); if(!nodump) @@ -417,50 +471,82 @@ main( short_dump_state(); event_loop(0); - /* handle any remaining dumps by dumping directly to tape, if possible */ + force_flush = 1; - while(!empty(runq) && taper > 0) { + /* mv runq to directq */ + while (!empty(runq)) { diskp = dequeue_disk(&runq); + headqueue_disk(&directq, diskp); + } + + /* handle any remaining dumps by dumping directly to tape, if possible */ + while(!empty(directq) && taper > 0) { + time_t sleep_time = 100000000; + disk_t *sleep_diskp = NULL; + time_t now = time(0); + + /* Find one we can do immediately or the sonner */ + for (diskp = directq.head; diskp != NULL; diskp = diskp->next) { + if (diskp->to_holdingdisk == HOLD_REQUIRED || + degraded_mode) { + sleep_time = 0; + sleep_diskp = diskp; + } else if (diskp->host->start_t - now < sleep_time && + diskp->start_t -now < sleep_time) { + if (diskp->host->start_t > diskp->start_t) + sleep_time = diskp->host->start_t - now; + else + sleep_time = diskp->start_t - now; + sleep_diskp = diskp; + } + } + diskp = sleep_diskp; + if (sleep_time > 0) + sleep(sleep_time); + remove_disk(&directq, diskp); + if (diskp->to_holdingdisk == HOLD_REQUIRED) { + char *qname = quote_string(diskp->name); log_add(L_FAIL, "%s %s %s %d [%s]", - diskp->host->hostname, diskp->name, sched(diskp)->datestamp, + diskp->host->hostname, qname, sched(diskp)->datestamp, sched(diskp)->level, - "can't dump required holdingdisk"); + _("can't dump required holdingdisk")); + amfree(qname); } else if (!degraded_mode) { - int rc = dump_to_tape(diskp); - if(rc == 1) - log_add(L_INFO, - "%s %s %d [dump to tape failed, will try again]", - diskp->host->hostname, - diskp->name, - sched(diskp)->level); - else if(rc == 2) - log_add(L_FAIL, "%s %s %s %d [dump to tape failed]", - diskp->host->hostname, - diskp->name, - sched(diskp)->datestamp, - sched(diskp)->level); + taper_state |= TAPER_STATE_DUMP_TO_TAPE; + dump_to_tape(diskp); + event_loop(0); + taper_state &= ~TAPER_STATE_DUMP_TO_TAPE; } - else + else { + char *qname = quote_string(diskp->name); log_add(L_FAIL, "%s %s %s %d [%s]", - diskp->host->hostname, diskp->name, sched(diskp)->datestamp, + diskp->host->hostname, qname, sched(diskp)->datestamp, sched(diskp)->level, - diskp->to_holdingdisk == HOLD_AUTO ? - "no more holding disk space" : - "can't dump no-hold disk in degraded mode"); + num_holdalloc == 0 ? + _("can't do degraded dump without holding disk") : + diskp->to_holdingdisk != HOLD_NEVER ? + _("out of holding space in degraded mode") : + _("can't dump 'holdingdisk never' dle in degraded mode")); + amfree(qname); + } } + /* fill up the tape or start new one for taperflush */ + startaflush(); + event_loop(0); + short_dump_state(); /* for amstatus */ - printf("driver: QUITTING time %s telling children to quit\n", + g_printf(_("driver: QUITTING time %s telling children to quit\n"), walltime_str(curclock())); fflush(stdout); if(!nodump) { for(dumper = dmptable; dumper < dmptable + inparallel; dumper++) { if(dumper->fd >= 0) - dumper_cmd(dumper, QUIT, NULL); + dumper_cmd(dumper, QUIT, NULL, NULL); } } @@ -471,29 +557,22 @@ main( /* wait for all to die */ wait_children(600); - for(hdp = getconf_holdingdisks(); hdp != NULL; hdp = hdp->next) { - cleanup_holdingdisk(holdingdisk_get_diskdir(hdp), 0); - amfree(hdp->up); - } + /* cleanup */ + holding_cleanup(NULL, NULL); + amfree(newdir); check_unfree_serial(); - printf("driver: FINISHED time %s\n", walltime_str(curclock())); + g_printf(_("driver: FINISHED time %s\n"), walltime_str(curclock())); fflush(stdout); - log_add(L_FINISH,"date %s time %s", driver_timestamp, walltime_str(curclock())); + log_add(L_FINISH,_("date %s time %s"), driver_timestamp, walltime_str(curclock())); + log_add(L_INFO, "pid-done %ld", (long)getpid()); amfree(driver_timestamp); - free_new_argv(new_argc, new_argv); amfree(dumper_program); amfree(taper_program); - amfree(config_dir); - amfree(config_name); - - malloc_size_2 = malloc_inuse(&malloc_hist_2); - - if(malloc_size_1 != malloc_size_2) { - malloc_list(fileno(stderr), malloc_hist_1, malloc_hist_2); - } + if (result_argv) + g_strfreev(result_argv); dbclose(); @@ -523,10 +602,10 @@ wait_children(int count) if (pid > 0) { what = NULL; if (! WIFEXITED(retstat)) { - what = "signal"; + what = _("signal"); code = WTERMSIG(retstat); } else if (WEXITSTATUS(retstat) != 0) { - what = "code"; + what = _("code"); code = WEXITSTATUS(retstat); } who = NULL; @@ -551,9 +630,9 @@ wait_children(int count) who = stralloc("unknown"); } if(who && what) { - log_add(L_WARNING, "%s pid %u exited with %s %d\n", who, + log_add(L_WARNING, _("%s pid %u exited with %s %d\n"), who, (unsigned)pid, what, code); - printf("driver: %s pid %u exited with %s %d\n", who, + g_printf(_("driver: %s pid %u exited with %s %d\n"), who, (unsigned)pid, what, code); } amfree(who); @@ -575,14 +654,14 @@ kill_children(int signal) if(!nodump) { for(dumper = dmptable; dumper < dmptable + inparallel; dumper++) { if (!dumper->down && dumper->pid > 1) { - printf("driver: sending signal %d to %s pid %u\n", signal, + g_printf(_("driver: sending signal %d to %s pid %u\n"), signal, dumper->name, (unsigned)dumper->pid); if (kill(dumper->pid, signal) == -1 && errno == ESRCH) { if (dumper->chunker) dumper->chunker->pid = 0; } if (dumper->chunker && dumper->chunker->pid > 1) { - printf("driver: sending signal %d to %s pid %u\n", signal, + g_printf(_("driver: sending signal %d to %s pid %u\n"), signal, dumper->chunker->name, (unsigned)dumper->chunker->pid); if (kill(dumper->chunker->pid, signal) == -1 && @@ -593,11 +672,12 @@ kill_children(int signal) } } - if(taper_pid > 1) - printf("driver: sending signal %d to %s pid %u\n", signal, + if(taper_pid > 1) { + g_printf(_("driver: sending signal %d to %s pid %u\n"), signal, "taper", (unsigned)taper_pid); if (kill(taper_pid, signal) == -1 && errno == ESRCH) taper_pid = 0; + } } static void @@ -608,10 +688,10 @@ wait_for_children(void) if(!nodump) { for(dumper = dmptable; dumper < dmptable + inparallel; dumper++) { if (dumper->pid > 1 && dumper->fd >= 0) { - dumper_cmd(dumper, QUIT, NULL); + dumper_cmd(dumper, QUIT, NULL, NULL); if (dumper->chunker && dumper->chunker->pid > 1 && dumper->chunker->fd >= 0) - chunker_cmd(dumper->chunker, QUIT, NULL); + chunker_cmd(dumper->chunker, QUIT, NULL, NULL); } } } @@ -641,8 +721,22 @@ startaflush(void) char *datestamp; int extra_tapes = 0; char *qname; + TapeAction result_tape_action; + char *why_no_new_tape; + + result_tape_action = tape_action(&why_no_new_tape); - if(!degraded_mode && !taper_busy && !empty(tapeq)) { + if (result_tape_action & TAPE_ACTION_NEW_TAPE) { + taper_state &= ~TAPER_STATE_WAIT_FOR_TAPE; + taper_cmd(NEW_TAPE, NULL, NULL, 0, NULL); + } else if (result_tape_action & TAPE_ACTION_NO_NEW_TAPE) { + taper_state &= ~TAPER_STATE_WAIT_FOR_TAPE; + taper_cmd(NO_NEW_TAPE, why_no_new_tape, NULL, 0, NULL); + start_degraded_mode(&runq); + } + + if (!degraded_mode && !taper_busy && !empty(tapeq) && + (result_tape_action & TAPE_ACTION_START_A_FLUSH)) { datestamp = sched(tapeq.head)->datestamp; switch(conf_taperalgo) { @@ -701,8 +795,8 @@ startaflush(void) } if(!dp) { /* ALGO_SMALLEST, or default if nothing fit. */ if(conf_taperalgo != ALGO_SMALLEST) { - fprintf(stderr, - "driver: startaflush: Using SMALLEST because nothing fit\n"); + g_fprintf(stderr, + _("driver: startaflush: Using SMALLEST because nothing fit\n")); } fit = dp = tapeq.head; while (fit != NULL) { @@ -721,30 +815,37 @@ startaflush(void) if (dp) { taper_disk = dp; taper_busy = 1; + amfree(taper_input_error); + amfree(taper_tape_error); + taper_result = LAST_TOK; + taper_sendresult = 0; + taper_first_label = NULL; + taper_written = 0; + taper_state &= ~TAPER_STATE_DUMP_TO_TAPE; + taper_dumper = NULL; qname = quote_string(dp->name); taper_cmd(FILE_WRITE, dp, sched(dp)->destname, sched(dp)->level, sched(dp)->datestamp); - fprintf(stderr,"driver: startaflush: %s %s %s " - OFF_T_FMT " " OFF_T_FMT "\n", + g_fprintf(stderr,_("driver: startaflush: %s %s %s %lld %lld\n"), taperalgo2str(conf_taperalgo), dp->host->hostname, qname, - (OFF_T_FMT_TYPE)sched(taper_disk)->act_size, - (OFF_T_FMT_TYPE)tape_left); + (long long)sched(taper_disk)->act_size, + (long long)tape_left); if(sched(dp)->act_size <= tape_left) tape_left -= sched(dp)->act_size; else tape_left = (off_t)0; amfree(qname); } else { - error("FATAL: Taper marked busy and no work found."); + error(_("FATAL: Taper marked busy and no work found.")); /*NOTREACHED*/ } + short_dump_state(); } else if(!taper_busy && taper_ev_read != NULL) { event_release(taper_ev_read); taper_ev_read = NULL; } } - static int client_constrained( disk_t * dp) @@ -777,15 +878,17 @@ start_some_dumps( { int cur_idle; disk_t *diskp, *delayed_diskp, *diskp_accept; + disk_t *dp; assignedhd_t **holdp=NULL, **holdp_accept; const time_t now = time(NULL); cmd_t cmd; int result_argc; - char *result_argv[MAX_ARGS+1]; + char **result_argv; chunker_t *chunker; dumper_t *dumper; char dumptype; char *dumporder; + int busy_dumpers = 0; idle_reason = IDLE_NO_DUMPERS; sleep_time = 0; @@ -795,9 +898,15 @@ start_some_dumps( dumpers_ev_time = NULL; } + for(dumper = dmptable; dumper < (dmptable+inparallel); dumper++) { + if( dumper->busy ) { + busy_dumpers++; + } + } + for (dumper = dmptable; dumper < dmptable+inparallel; dumper++) { - if( dumper->busy ) { + if( dumper->busy || dumper->down) { continue; } @@ -867,6 +976,10 @@ start_some_dumps( } else if ((holdp = find_diskspace(sched(diskp)->est_size, &cur_idle, NULL)) == NULL) { cur_idle = max(cur_idle, IDLE_NO_DISKSPACE); + if (empty(tapeq) && busy_dumpers == 0) { + remove_disk(rq, diskp); + enqueue_disk(&directq, diskp); + } } else if (client_constrained(diskp)) { free_assignedhd(holdp); cur_idle = max(cur_idle, IDLE_CLIENT_CONSTRAINED); @@ -888,7 +1001,7 @@ start_some_dumps( break; case 'B': accept = (sched(diskp)->est_kps > sched(diskp_accept)->est_kps); break; - default: log_add(L_WARNING, "Unknown dumporder character \'%c\', using 's'.\n", + default: log_add(L_WARNING, _("Unknown dumporder character \'%c\', using 's'.\n"), dumptype); accept = (sched(diskp)->est_size < sched(diskp_accept)->est_size); break; @@ -950,23 +1063,25 @@ start_some_dumps( chunker->result = LAST_TOK; dumper->result = LAST_TOK; startup_chunk_process(chunker,chunker_program); - chunker_cmd(chunker, START, (void *)driver_timestamp); + chunker_cmd(chunker, START, NULL, driver_timestamp); chunker->dumper = dumper; - chunker_cmd(chunker, PORT_WRITE, diskp); - cmd = getresult(chunker->fd, 1, &result_argc, result_argv, MAX_ARGS+1); + chunker_cmd(chunker, PORT_WRITE, diskp, NULL); + cmd = getresult(chunker->fd, 1, &result_argc, &result_argv); if(cmd != PORT) { assignedhd_t **h=NULL; int activehd; + char *qname = quote_string(diskp->name); - printf("driver: did not get PORT from %s for %s:%s\n", - chunker->name, diskp->host->hostname, diskp->name); + g_printf(_("driver: did not get PORT from %s for %s:%s\n"), + chunker->name, diskp->host->hostname, qname); + amfree(qname); fflush(stdout); deallocate_bandwidth(diskp->host->netif, sched(diskp)->est_kps); h = sched(diskp)->holdp; activehd = sched(diskp)->activehd; h[activehd]->used = 0; - holdalloc(h[activehd]->disk)->allocated_dumpers--; + h[activehd]->disk->allocated_dumpers--; adjust_diskspace(diskp, DONE); delete_diskspace(diskp); diskp->host->inprogress--; @@ -974,9 +1089,9 @@ start_some_dumps( sched(diskp)->dumper = NULL; dumper->busy = 0; dumper->dp = NULL; - sched(diskp)->attempted++; + sched(diskp)->dump_attempted++; free_serial_dp(diskp); - if(sched(diskp)->attempted < 2) + if(sched(diskp)->dump_attempted < 2) enqueue_disk(rq, diskp); } else { @@ -984,11 +1099,25 @@ start_some_dumps( handle_dumper_result, dumper); chunker->ev_read = event_register((event_id_t)chunker->fd, EV_READFD, handle_chunker_result, chunker); - dumper->output_port = atoi(result_argv[2]); + dumper->output_port = atoi(result_argv[1]); - dumper_cmd(dumper, PORT_DUMP, diskp); + if (diskp->host->pre_script == 0) { + for (dp=diskp->host->disks; dp != NULL; dp = dp->hostnext) { + run_server_scripts(EXECUTE_ON_PRE_HOST_BACKUP, + get_config_name(), dp, -1); + } + diskp->host->pre_script = 1; + } + run_server_scripts(EXECUTE_ON_PRE_DLE_BACKUP, + get_config_name(), diskp, + sched(diskp)->level); + dumper_cmd(dumper, PORT_DUMP, diskp, NULL); } diskp->host->start_t = now + 15; + + if (result_argv) + g_strfreev(result_argv); + short_dump_state(); } } } @@ -1017,17 +1146,17 @@ dump_schedule( disk_t *dp; char *qname; - printf("dump of driver schedule %s:\n--------\n", str); + g_printf(_("dump of driver schedule %s:\n--------\n"), str); for(dp = qp->head; dp != NULL; dp = dp->next) { qname = quote_string(dp->name); - printf(" %-20s %-25s lv %d t %5lu s " OFF_T_FMT " p %d\n", + g_printf(" %-20s %-25s lv %d t %5lu s %lld p %d\n", dp->host->hostname, qname, sched(dp)->level, sched(dp)->est_time, - (OFF_T_FMT_TYPE)sched(dp)->est_size, sched(dp)->priority); + (long long)sched(dp)->est_size, sched(dp)->priority); amfree(qname); } - printf("--------\n"); + g_printf("--------\n"); } static void @@ -1039,14 +1168,9 @@ start_degraded_mode( off_t est_full_size; char *qname; - if (taper_ev_read != NULL) { - event_release(taper_ev_read); - taper_ev_read = NULL; - } - newq.head = newq.tail = 0; - dump_schedule(queuep, "before start degraded mode"); + dump_schedule(queuep, _("before start degraded mode")); est_full_size = (off_t)0; while(!empty(*queuep)) { @@ -1072,9 +1196,9 @@ start_degraded_mode( enqueue_disk(&newq, dp); } else { - log_add(L_FAIL,"%s %s %s %d [can't switch to incremental dump]", + log_add(L_FAIL, "%s %s %s %d [%s]", dp->host->hostname, qname, sched(dp)->datestamp, - sched(dp)->level); + sched(dp)->level, sched(dp)->degr_mesg); } } amfree(qname); @@ -1083,7 +1207,7 @@ start_degraded_mode( /*@i@*/ *queuep = newq; degraded_mode = 1; - dump_schedule(queuep, "after start degraded mode"); + dump_schedule(queuep, _("after start degraded mode")); } @@ -1112,7 +1236,7 @@ continue_port_dumps(void) } assert( dumper < dmptable + inparallel ); sched(dp)->activehd = assign_holdingdisk( h, dp ); - chunker_cmd( dumper->chunker, CONTINUE, dp ); + chunker_cmd( dumper->chunker, CONTINUE, dp, NULL ); amfree(h); remove_disk( &roomq, dp ); } @@ -1155,8 +1279,8 @@ continue_port_dumps(void) * We abort that dump, hopefully not wasting too much time retrying it. */ remove_disk( &roomq, dp ); - chunker_cmd( sched(dp)->dumper->chunker, ABORT, NULL); - dumper_cmd( sched(dp)->dumper, ABORT, NULL ); + chunker_cmd(sched(dp)->dumper->chunker, ABORT, NULL, _("Not enough holding disk space")); + dumper_cmd( sched(dp)->dumper, ABORT, NULL, _("Not enough holding disk space")); pending_aborts++; } } @@ -1164,148 +1288,232 @@ continue_port_dumps(void) static void handle_taper_result( - void * cookie) + void *cookie G_GNUC_UNUSED) { disk_t *dp; - off_t filenum; cmd_t cmd; int result_argc; - char *result_argv[MAX_ARGS+1]; - int avail_tapes = 0; - - (void)cookie; /* Quiet unused parameter warning */ + char **result_argv; + char *qname, *q; + char *s; assert(cookie == NULL); + amfree(taper_input_error); + amfree(taper_tape_error); do { short_dump_state(); - cmd = getresult(taper, 1, &result_argc, result_argv, MAX_ARGS+1); + cmd = getresult(taper, 1, &result_argc, &result_argv); switch(cmd) { - case PARTIAL: - case DONE: /* DONE