⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 driverio.c

📁 开源备份软件源码 AMANDA, the Advanced Maryland Automatic Network Disk Archiver, is a backup system that a
💻 C
📖 第 1 页 / 共 2 页
字号:
			    " ", device,			    " ", number,			    " ", sched(dp)->dumpdate,			    " ", dp->program,			    " ", dp->amandad_path,			    " ", dp->client_username,			    " ", dp->ssh_keys,			    " |", o,			    "\n", NULL);	    amfree(features);	    amfree(o);	    amfree(qname);	    amfree(device);	} else {		error(_("PORT-DUMP without disk pointer\n"));		/*NOTREACHED*/	}	break;    case QUIT:    case ABORT:	if( dp ) {	    qdest = quote_string(sched(dp)->destname);	    cmdline = vstralloc(cmdstr[cmd],				" ", qdest,				"\n", NULL );	    amfree(qdest);	} else {	    cmdline = stralloc2(cmdstr[cmd], "\n");	}	break;    default:	error(_("Don't know how to send %s command to dumper"), cmdstr[cmd]);	/*NOTREACHED*/    }    /*     * Note: cmdline already has a '\n'.     */    if(dumper->down) {	g_printf(_("driver: send-cmd time %s ignored to down dumper %s: %s"),	       walltime_str(curclock()), dumper->name, cmdline);    } else {	g_printf(_("driver: send-cmd time %s to %s: %s"),	       walltime_str(curclock()), dumper->name, cmdline);	fflush(stdout);	if (fullwrite(dumper->fd, cmdline, strlen(cmdline)) < 0) {	    g_printf(_("writing %s command: %s\n"), dumper->name, strerror(errno));	    fflush(stdout);	    amfree(cmdline);	    return 0;	}	if (cmd == QUIT) aclose(dumper->fd);    }    amfree(cmdline);    return 1;}intchunker_cmd(    chunker_t *chunker,    cmd_t cmd,    disk_t *dp){    char *cmdline = NULL;    char number[NUM_STR_SIZE];    char chunksize[NUM_STR_SIZE];    char use[NUM_STR_SIZE];    char *o;    int activehd=0;    assignedhd_t **h=NULL;    char *features;    char *qname;    char *qdest;    switch(cmd) {    case START:	cmdline = vstralloc(cmdstr[cmd], " ", (char *)dp, "\n", NULL);	break;    case PORT_WRITE:	if(dp && sched(dp) && sched(dp)->holdp) {	    h = sched(dp)->holdp;	    activehd = sched(dp)->activehd;	}	if (dp && h) {	    qname = quote_string(dp->name);	    qdest = quote_string(sched(dp)->destname);	    h[activehd]->disk->allocated_dumpers++;	    g_snprintf(number, SIZEOF(number), "%d", sched(dp)->level);	    g_snprintf(chunksize, SIZEOF(chunksize), "%lld",		    (long long)holdingdisk_get_chunksize(h[0]->disk->hdisk));	    g_snprintf(use, SIZEOF(use), "%lld",		    (long long)h[0]->reserved);	    features = am_feature_to_string(dp->host->features);	    o = optionstr(dp, dp->host->features, NULL);	    if ( o == NULL ) {	      error(_("problem with option string, check the dumptype definition.\n"));	    }	    cmdline = vstralloc(cmdstr[cmd],			    " ", disk2serial(dp),			    " ", qdest,			    " ", dp->host->hostname,			    " ", features,			    " ", qname,			    " ", number,			    " ", sched(dp)->dumpdate,			    " ", chunksize,			    " ", dp->program,			    " ", use,			    " |", o,			    "\n", NULL);	    amfree(features);	    amfree(o);	    amfree(qdest);	    amfree(qname);	} else {		error(_("%s command without disk and holding disk.\n"),		      cmdstr[cmd]);		/*NOTREACHED*/	}	break;    case CONTINUE:	if(dp && sched(dp) && sched(dp)->holdp) {	    h = sched(dp)->holdp;	    activehd = sched(dp)->activehd;	}	if(dp && h) {	    qname = quote_string(dp->name);	    qdest = quote_string(h[activehd]->destname);	    h[activehd]->disk->allocated_dumpers++;	    g_snprintf(chunksize, SIZEOF(chunksize), "%lld", 		     (long long)holdingdisk_get_chunksize(h[activehd]->disk->hdisk));	    g_snprintf(use, SIZEOF(use), "%lld", 		     (long long)(h[activehd]->reserved - h[activehd]->used));	    cmdline = vstralloc(cmdstr[cmd],				" ", disk2serial(dp),				" ", qdest,				" ", chunksize,				" ", use,				"\n", NULL );	    amfree(qdest);	    amfree(qname);	} else {	    cmdline = stralloc2(cmdstr[cmd], "\n");	}	break;    case QUIT:    case ABORT:	cmdline = stralloc2(cmdstr[cmd], "\n");	break;    case DONE:    case FAILED:	if( dp ) {	    cmdline = vstralloc(cmdstr[cmd],				" ", disk2serial(dp),				"\n",  NULL);	} else {	    cmdline = vstralloc(cmdstr[cmd], "\n");	}	break;    default:	error(_("Don't know how to send %s command to chunker"), cmdstr[cmd]);	/*NOTREACHED*/    }    /*     * Note: cmdline already has a '\n'.     */    g_printf(_("driver: send-cmd time %s to %s: %s"),	   walltime_str(curclock()), chunker->name, cmdline);    fflush(stdout);    if (fullwrite(chunker->fd, cmdline, strlen(cmdline)) < 0) {	g_printf(_("writing %s command: %s\n"), chunker->name, strerror(errno));	fflush(stdout);	amfree(cmdline);	return 0;    }    if (cmd == QUIT) aclose(chunker->fd);    amfree(cmdline);    return 1;}#define MAX_SERIAL MAX_DUMPERS+1	/* one for the taper */long generation = 1;struct serial_s {    long gen;    disk_t *dp;} stable[MAX_SERIAL];disk_t *serial2disk(    char *str){    int rc, s;    long gen;    rc = sscanf(str, "%d-%ld", &s, &gen);    if(rc != 2) {	error(_("error [serial2disk \"%s\" parse error]"), str);	/*NOTREACHED*/    } else if (s < 0 || s >= MAX_SERIAL) {	error(_("error [serial out of range 0..%d: %d]"), MAX_SERIAL, s);	/*NOTREACHED*/    }    if(gen != stable[s].gen)	g_printf(_("driver: serial2disk error time %s serial gen mismatch %s\n"),	       walltime_str(curclock()), str);    return stable[s].dp;}voidfree_serial(    char *str){    int rc, s;    long gen;    rc = sscanf(str, _("%d-%ld"), &s, &gen);    if(!(rc == 2 && s >= 0 && s < MAX_SERIAL)) {	/* nuke self to get core dump for Brett */	g_fprintf(stderr, _("driver: free_serial: str \"%s\" rc %d s %d\n"),		str, rc, s);	fflush(stderr);	abort();    }    if(gen != stable[s].gen)	g_printf(_("driver: free_serial error time %s serial gen mismatch %s\n"),	       walltime_str(curclock()),str);    stable[s].gen = 0;    stable[s].dp = NULL;}voidfree_serial_dp(    disk_t *dp){    int s;    for(s = 0; s < MAX_SERIAL; s++) {	if(stable[s].dp == dp) {	    stable[s].gen = 0;	    stable[s].dp = NULL;	    return;	}    }    g_printf(_("driver: error time %s serial not found\n"),	   walltime_str(curclock()));}voidcheck_unfree_serial(void){    int s;    /* find used serial number */    for(s = 0; s < MAX_SERIAL; s++) {	if(stable[s].gen != 0 || stable[s].dp != NULL) {	    g_printf(_("driver: error time %s bug: serial in use: %02d-%05ld\n"),		   walltime_str(curclock()), s, stable[s].gen);	}    }}char *disk2serial(    disk_t *dp){    int s;    static char str[NUM_STR_SIZE];    for(s = 0; s < MAX_SERIAL; s++) {	if(stable[s].dp == dp) {	    g_snprintf(str, SIZEOF(str), "%02d-%05ld", s, stable[s].gen);	    return str;	}    }    /* find unused serial number */    for(s = 0; s < MAX_SERIAL; s++)	if(stable[s].gen == 0 && stable[s].dp == NULL)	    break;    if(s >= MAX_SERIAL) {	g_printf(_("driver: error time %s bug: out of serial numbers\n"),	       walltime_str(curclock()));	s = 0;    }    stable[s].gen = generation++;    stable[s].dp = dp;    g_snprintf(str, SIZEOF(str), "%02d-%05ld", s, stable[s].gen);    return str;}voidupdate_info_dumper(     disk_t *dp,     off_t origsize,     off_t dumpsize,     time_t dumptime){    int level, i;    info_t info;    stats_t *infp;    perf_t *perfp;    char *conf_infofile;    level = sched(dp)->level;    conf_infofile = config_dir_relative(getconf_str(CNF_INFOFILE));    if (open_infofile(conf_infofile)) {	error(_("could not open info db \"%s\""), conf_infofile);	/*NOTREACHED*/    }    amfree(conf_infofile);    get_info(dp->host->hostname, dp->name, &info);    /* Clean up information about this and higher-level dumps.  This       assumes that update_info_dumper() is always run before       update_info_taper(). */    for (i = level; i < DUMP_LEVELS; ++i) {      infp = &info.inf[i];      infp->size = (off_t)-1;      infp->csize = (off_t)-1;      infp->secs = (time_t)-1;      infp->date = (time_t)-1;      infp->label[0] = '\0';      infp->filenum = 0;    }    /* now store information about this dump */    infp = &info.inf[level];    infp->size = origsize;    infp->csize = dumpsize;    infp->secs = dumptime;    infp->date = sched(dp)->timestamp;    if(level == 0) perfp = &info.full;    else perfp = &info.incr;    /* Update the stats, but only if the new values are meaningful */    if(dp->compress != COMP_NONE && origsize > (off_t)0) {	newperf(perfp->comp, (double)dumpsize/(double)origsize);    }    if(dumptime > (time_t)0) {	if((off_t)dumptime >= dumpsize)	    newperf(perfp->rate, 1);	else	    newperf(perfp->rate, (double)dumpsize/(double)dumptime);    }    if(getconf_int(CNF_RESERVE)<100) {	info.command = NO_COMMAND;    }    if(level == info.last_level)	info.consecutive_runs++;    else {	info.last_level = level;	info.consecutive_runs = 1;    }    if(origsize >= (off_t)0 && dumpsize >= (off_t)0) {	for(i=NB_HISTORY-1;i>0;i--) {	    info.history[i] = info.history[i-1];	}	info.history[0].level = level;	info.history[0].size  = origsize;	info.history[0].csize = dumpsize;	info.history[0].date  = sched(dp)->timestamp;	info.history[0].secs  = dumptime;    }    if(put_info(dp->host->hostname, dp->name, &info)) {	error(_("infofile update failed (%s,'%s')\n"), dp->host->hostname, dp->name);	/*NOTREACHED*/    }    close_infofile();}voidupdate_info_taper(    disk_t *dp,    char *label,    off_t filenum,    int level){    info_t info;    stats_t *infp;    int rc;    rc = open_infofile(getconf_str(CNF_INFOFILE));    if(rc) {	error(_("could not open infofile %s: %s (%d)"), getconf_str(CNF_INFOFILE),	      strerror(errno), rc);	/*NOTREACHED*/    }    get_info(dp->host->hostname, dp->name, &info);    infp = &info.inf[level];    /* XXX - should we record these two if no-record? */    strncpy(infp->label, label, SIZEOF(infp->label)-1);    infp->label[SIZEOF(infp->label)-1] = '\0';    infp->filenum = filenum;    info.command = NO_COMMAND;    if(put_info(dp->host->hostname, dp->name, &info)) {	error(_("infofile update failed (%s,'%s')\n"), dp->host->hostname, dp->name);	/*NOTREACHED*/    }    close_infofile();}/* Free an array of pointers to assignedhd_t after freeing the * assignedhd_t themselves. The array must be NULL-terminated. */void free_assignedhd(    assignedhd_t **ahd){    int i;    if( !ahd ) { return; }    for( i = 0; ahd[i]; i++ ) {	amfree(ahd[i]->destname);	amfree(ahd[i]);    }    amfree(ahd);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -