📄 driver.c
字号:
if (cmd == DONE) { chunker_cmd(dumper->chunker, DONE, dp); } else { chunker_cmd(dumper->chunker, FAILED, dp); } } if( dumper->result != LAST_TOK && dumper->chunker->result != LAST_TOK) dumper_chunker_result(dp); } else { /* send the dumper result to the taper */ if (taper_sendresult) { if (cmd == DONE) { taper_cmd(DONE, driver_timestamp, NULL, 0, NULL); } else { taper_cmd(FAILED, driver_timestamp, NULL, 0, NULL); } taper_sendresult = 0; } } if (taper_dumper && taper_result != LAST_TOK) { dumper_taper_result(dp); } } while(areads_dataready(dumper->fd));}static voidhandle_chunker_result( void * cookie){ /*static int pending_aborts = 0;*/ chunker_t *chunker = cookie; assignedhd_t **h=NULL; dumper_t *dumper; disk_t *dp, *sdp; cmd_t cmd; int result_argc; char *result_argv[MAX_ARGS+1]; int dummy; int activehd = -1; char *qname; assert(chunker != NULL); dumper = chunker->dumper; assert(dumper != NULL); dp = dumper->dp; assert(dp != NULL); assert(sched(dp) != NULL); assert(sched(dp)->destname != NULL); assert(dp != NULL && sched(dp) != NULL && sched(dp)->destname); if(dp && sched(dp) && sched(dp)->holdp) { h = sched(dp)->holdp; activehd = sched(dp)->activehd; } do { short_dump_state(); cmd = getresult(chunker->fd, 1, &result_argc, result_argv, MAX_ARGS+1); if(cmd != BOGUS) { /* result_argv[2] always contains the serial number */ sdp = serial2disk(result_argv[2]); if (sdp != dp) { error(_("Invalid serial number %s"), result_argv[2]); g_assert_not_reached(); } } switch(cmd) { case PARTIAL: /* PARTIAL <handle> <dumpsize> <errstr> */ case DONE: /* DONE <handle> <dumpsize> <errstr> */ if(result_argc != 4) { error(_("error [chunker %s result_argc != 4: %d]"), cmdstr[cmd], result_argc); /*NOTREACHED*/ } /*free_serial(result_argv[2]);*/ sched(dp)->dumpsize = (off_t)atof(result_argv[3]); qname = quote_string(dp->name); g_printf(_("driver: finished-cmd time %s %s chunked %s:%s\n"), walltime_str(curclock()), chunker->name, dp->host->hostname, qname); fflush(stdout); amfree(qname); event_release(chunker->ev_read); chunker->result = cmd; break; case TRYAGAIN: /* TRY-AGAIN <handle> <errstr> */ event_release(chunker->ev_read); chunker->result = cmd; break; case FAILED: /* FAILED <handle> <errstr> */ /*free_serial(result_argv[2]);*/ event_release(chunker->ev_read); chunker->result = cmd; break; case NO_ROOM: /* NO-ROOM <handle> <missing_size> */ if (!h || activehd < 0) { /* should never happen */ error(_("!h || activehd < 0")); /*NOTREACHED*/ } h[activehd]->used -= OFF_T_ATOI(result_argv[3]); h[activehd]->reserved -= OFF_T_ATOI(result_argv[3]); h[activehd]->disk->allocated_space -= OFF_T_ATOI(result_argv[3]); h[activehd]->disk->disksize -= OFF_T_ATOI(result_argv[3]); break; case RQ_MORE_DISK: /* RQ-MORE-DISK <handle> */ if (!h || activehd < 0) { /* should never happen */ error(_("!h || activehd < 0")); /*NOTREACHED*/ } h[activehd]->disk->allocated_dumpers--; h[activehd]->used = h[activehd]->reserved; if( h[++activehd] ) { /* There's still some allocated space left. * Tell the dumper about it. */ sched(dp)->activehd++; chunker_cmd( chunker, CONTINUE, dp ); } else { /* !h[++activehd] - must allocate more space */ sched(dp)->act_size = sched(dp)->est_size; /* not quite true */ sched(dp)->est_size = (sched(dp)->act_size/(off_t)20) * (off_t)21; /* +5% */ sched(dp)->est_size = am_round(sched(dp)->est_size, (off_t)DISK_BLOCK_KB); if (sched(dp)->est_size < sched(dp)->act_size + 2*DISK_BLOCK_KB) sched(dp)->est_size += 2 * DISK_BLOCK_KB; h = find_diskspace( sched(dp)->est_size - sched(dp)->act_size, &dummy, h[activehd-1] ); if( !h ) { /* No diskspace available. The reason for this will be * determined in continue_port_dumps(). */ enqueue_disk( &roomq, dp ); continue_port_dumps(); } else { /* OK, allocate space for disk and have chunker continue */ sched(dp)->activehd = assign_holdingdisk( h, dp ); chunker_cmd( chunker, CONTINUE, dp ); amfree(h); } } break; case ABORT_FINISHED: /* ABORT-FINISHED <handle> */ /* * We sent an ABORT from the NO-ROOM case because this dump * wasn't going to fit onto the holding disk. We now need to * clean up the remains of this image, and try to finish * other dumps that are waiting on disk space. */ /*assert(pending_aborts);*/ /*free_serial(result_argv[2]);*/ event_release(chunker->ev_read); chunker->result = cmd; break; case BOGUS: /* either EOF or garbage from chunker. Turn it off */ log_add(L_WARNING, _("%s pid %ld is messed up, ignoring it.\n"), chunker->name, (long)chunker->pid); if(dp) { /* if it was dumping something, zap it and try again */ if (!h || activehd < 0) { /* should never happen */ error(_("!h || activehd < 0")); /*NOTREACHED*/ } qname = quote_string(dp->name); if(sched(dp)->dump_attempted) { log_add(L_FAIL, _("%s %s %s %d [%s died]"), dp->host->hostname, qname, sched(dp)->datestamp, sched(dp)->level, chunker->name); } else { log_add(L_WARNING, _("%s died while dumping %s:%s lev %d."), chunker->name, dp->host->hostname, qname, sched(dp)->level); } amfree(qname); dp = NULL; } event_release(chunker->ev_read); chunker->result = cmd; break; default: assert(0); } if(chunker->result != LAST_TOK && chunker->dumper->result != LAST_TOK) dumper_chunker_result(dp); } while(areads_dataready(chunker->fd));}static disklist_tread_flush(void){ sched_t *sp; disk_t *dp; int line; dumpfile_t file; char *hostname, *diskname, *datestamp; int level; char *destname; disk_t *dp1; char *inpline = NULL; char *command; char *s; int ch; disklist_t tq; char *qname = NULL; char *qdestname = NULL; tq.head = tq.tail = NULL; for(line = 0; (inpline = agets(stdin)) != NULL; free(inpline)) { line++; if (inpline[0] == '\0') continue; s = inpline; ch = *s++; skip_whitespace(s, ch); /* find the command */ if(ch == '\0') { error(_("flush line %d: syntax error (no command)"), line); /*NOTREACHED*/ } command = s - 1; skip_non_whitespace(s, ch); s[-1] = '\0'; if(strcmp(command,"ENDFLUSH") == 0) { break; } if(strcmp(command,"FLUSH") != 0) { error(_("flush line %d: syntax error (%s != FLUSH)"), line, command); /*NOTREACHED*/ } skip_whitespace(s, ch); /* find the hostname */ if(ch == '\0') { error(_("flush line %d: syntax error (no hostname)"), line); /*NOTREACHED*/ } hostname = s - 1; skip_non_whitespace(s, ch); s[-1] = '\0'; skip_whitespace(s, ch); /* find the diskname */ if(ch == '\0') { error(_("flush line %d: syntax error (no diskname)"), line); /*NOTREACHED*/ } qname = s - 1; skip_quoted_string(s, ch); s[-1] = '\0'; /* terminate the disk name */ diskname = unquote_string(qname); skip_whitespace(s, ch); /* find the datestamp */ if(ch == '\0') { error(_("flush line %d: syntax error (no datestamp)"), line); /*NOTREACHED*/ } datestamp = s - 1; skip_non_whitespace(s, ch); s[-1] = '\0'; skip_whitespace(s, ch); /* find the level number */ if(ch == '\0' || sscanf(s - 1, "%d", &level) != 1) { error(_("flush line %d: syntax error (bad level)"), line); /*NOTREACHED*/ } skip_integer(s, ch); skip_whitespace(s, ch); /* find the filename */ if(ch == '\0') { error(_("flush line %d: syntax error (no filename)"), line); /*NOTREACHED*/ } qdestname = s - 1; skip_quoted_string(s, ch); s[-1] = '\0'; destname = unquote_string(qdestname); holding_file_get_dumpfile(destname, &file); if( file.type != F_DUMPFILE) { if( file.type != F_CONT_DUMPFILE ) log_add(L_INFO, _("%s: ignoring cruft file."), destname); amfree(diskname); amfree(destname); continue; } if(strcmp(hostname, file.name) != 0 || strcmp(diskname, file.disk) != 0 || strcmp(datestamp, file.datestamp) != 0) { log_add(L_INFO, _("disk %s:%s not consistent with file %s"), hostname, diskname, destname); amfree(diskname); amfree(destname); continue; } amfree(diskname); dp = lookup_disk(file.name, file.disk); if (dp == NULL) { log_add(L_INFO, _("%s: disk %s:%s not in database, skipping it."), destname, file.name, file.disk); amfree(destname); continue; } if(file.dumplevel < 0 || file.dumplevel > 9) { log_add(L_INFO, _("%s: ignoring file with bogus dump level %d."), destname, file.dumplevel); amfree(destname); continue; } if (holding_file_size(destname,1) <= 0) { log_add(L_INFO, "%s: removing file with no data.", destname); holding_file_unlink(destname); amfree(destname); continue; } dp1 = (disk_t *)alloc(SIZEOF(disk_t)); *dp1 = *dp; dp1->next = dp1->prev = NULL; /* add it to the flushhost list */ if(!flushhost) { flushhost = alloc(SIZEOF(am_host_t)); flushhost->next = NULL; flushhost->hostname = stralloc("FLUSHHOST"); flushhost->up = NULL; flushhost->features = NULL; } dp1->hostnext = flushhost->disks; flushhost->disks = dp1; sp = (sched_t *) alloc(SIZEOF(sched_t)); sp->destname = destname; sp->level = file.dumplevel; sp->dumpdate = NULL; sp->degr_dumpdate = NULL; sp->datestamp = stralloc(file.datestamp); sp->est_nsize = (off_t)0; sp->est_csize = (off_t)0; sp->est_time = 0; sp->est_kps = 10; sp->priority = 0; sp->degr_level = -1; sp->dump_attempted = 0; sp->taper_attempted = 0; sp->act_size = holding_file_size(destname, 0); sp->holdp = build_diskspace(destname); if(sp->holdp == NULL) continue; sp->dumper = NULL; sp->timestamp = (time_t)0; dp1->up = (char *)sp; enqueue_disk(&tq, dp1); } amfree(inpline); /*@i@*/ return tq;}static voidread_schedule( void * cookie){ sched_t *sp; disk_t *dp; int level, line, priority; char *dumpdate, *degr_dumpdate; int degr_level; time_t time, degr_time; time_t *time_p = &time; time_t *degr_time_p = °r_time; off_t nsize, csize, degr_nsize, degr_csize; unsigned long kps, degr_kps; char *hostname, *features, *diskname, *datestamp, *inpline = NULL; char *command; char *s; int ch; off_t flush_size = (off_t)0; char *qname = NULL; long long time_; long long nsize_; long long csize_; long long degr_nsize_; long long degr_csize_; (void)cookie; /* Quiet unused parameter warning */ event_release(schedule_ev_read); /* read schedule from stdin */ for(line = 0; (inpline = agets(stdin)) != NULL; free(inpline)) { if (inpline[0] == '\0') continue; line++; s = inpline; ch = *s++; skip_whitespace(s, ch); /* find the command */ if(ch == '\0') { error(_("schedule line %d: syntax error (no command)"), line); /*NOTREACHED*/ } command = s - 1; skip_non_whitespace(s, ch); s[-1] = '\0'; if(strcmp(command,"DUMP") != 0) { error(_("schedule line %d: syntax error (%s != DUMP)"), line, command); /*NOTREACHED*/ } skip_whitespace(s, ch); /* find
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -