#include "diskfile.h"
#include "infofile.h"
#include "logfile.h"
+#include "timestamp.h"
#define GLOBAL /* the global variables defined here */
#include "driverio.h"
{
dumper_t *dumper;
- taper = -1;
+ taper_fd = -1;
for(dumper = dmptable; dumper < dmptable + MAX_DUMPERS; dumper++) {
dumper->fd = -1;
static char buf[NUM_STR_SIZE + 32];
dumper_t *dumper;
- if (fd == taper)
+ if (fd == taper_fd)
return ("taper");
for (dumper = dmptable; dumper < dmptable + MAX_DUMPERS; dumper++) {
void
startup_tape_process(
- char *taper_program)
+ char *taper_program,
+ int taper_parallel_write,
+ gboolean no_taper)
{
- int fd[2];
- char **config_options;
+ int fd[2];
+ int i;
+ char **config_options;
+ taper_t *taper;
+
+ /* always allocate the tapetable */
+ tapetable = calloc(sizeof(taper_t), taper_parallel_write+1);
+
+ for (taper = tapetable, i = 0; i < taper_parallel_write; taper++, i++) {
+ taper->name = g_strdup_printf("worker%d", i);
+ taper->sendresult = 0;
+ taper->input_error = NULL;
+ taper->tape_error = NULL;
+ taper->result = 0;
+ taper->dumper = NULL;
+ taper->disk = NULL;
+ taper->first_label = NULL;
+ taper->first_fileno = 0;
+ taper->state = TAPER_STATE_DEFAULT;
+ taper->left = 0;
+ taper->written = 0;
+
+ /* jump right to degraded mode if there's no taper */
+ if (no_taper) {
+ taper->tape_error = g_strdup("no taper started (--no-taper)");
+ taper->result = BOGUS;
+ }
+ }
+
+ /* don't start the taper if we're not supposed to */
+ if (no_taper)
+ return;
if(socketpair(AF_UNIX, SOCK_STREAM, 0, fd) == -1) {
error(_("taper pipe: %s"), strerror(errno));
default: /* parent process */
aclose(fd[1]);
- taper = fd[0];
+ taper_fd = fd[0];
taper_ev_read = NULL;
}
}
if((line = areads(fd)) == NULL) {
if(errno) {
- error(_("reading result from %s: %s"), childstr(fd), strerror(errno));
- /*NOTREACHED*/
+ g_fprintf(stderr, _("reading result from %s: %s"), childstr(fd), strerror(errno));
}
*result_argv = NULL;
*result_argc = 0; /* EOF */
}
+static char *
+taper_splitting_args(
+ disk_t *dp)
+{
+ GString *args = NULL;
+ char *q = NULL;
+ dumptype_t *dt = dp->config;
+ tapetype_t *tt;
+
+ tt = lookup_tapetype(getconf_str(CNF_TAPETYPE));
+ g_assert(tt != NULL);
+
+ args = g_string_new("");
+
+ /* old dumptype-based parameters, using empty strings when not seen */
+ if (dt) { /* 'dt' may be NULL for flushes */
+ if (dumptype_seen(dt, DUMPTYPE_TAPE_SPLITSIZE)) {
+ g_string_append_printf(args, "%ju ",
+ (uintmax_t)dumptype_get_tape_splitsize(dt)*1024);
+ } else {
+ g_string_append(args, "\"\" ");
+ }
+
+ q = quote_string(dumptype_seen(dt, DUMPTYPE_SPLIT_DISKBUFFER)?
+ dumptype_get_split_diskbuffer(dt) : "");
+ g_string_append_printf(args, "%s ", q);
+ g_free(q);
+
+ if (dumptype_seen(dt, DUMPTYPE_FALLBACK_SPLITSIZE)) {
+ g_string_append_printf(args, "%ju ",
+ (uintmax_t)dumptype_get_fallback_splitsize(dt)*1024);
+ } else {
+ g_string_append(args, "\"\" ");
+ }
+
+ if (dumptype_seen(dt, DUMPTYPE_ALLOW_SPLIT)) {
+ g_string_append_printf(args, "%d ",
+ (int)dumptype_get_allow_split(dt));
+ } else {
+ g_string_append(args, "\"\" ");
+ }
+ } else {
+ g_string_append(args, "\"\" \"\" \"\" \"\" ");
+ }
+
+ /* new tapetype-based parameters */
+ if (tapetype_seen(tt, TAPETYPE_PART_SIZE)) {
+ g_string_append_printf(args, "%ju ",
+ (uintmax_t)tapetype_get_part_size(tt)*1024);
+ } else {
+ g_string_append(args, "\"\" ");
+ }
+
+ q = "";
+ if (tapetype_seen(tt, TAPETYPE_PART_CACHE_TYPE)) {
+ switch (tapetype_get_part_cache_type(tt)) {
+ default:
+ case PART_CACHE_TYPE_NONE:
+ q = "none";
+ break;
+
+ case PART_CACHE_TYPE_MEMORY:
+ q = "memory";
+ break;
+
+ case PART_CACHE_TYPE_DISK:
+ q = "disk";
+ break;
+ }
+ }
+ q = quote_string(q);
+ g_string_append_printf(args, "%s ", q);
+ g_free(q);
+
+ q = quote_string(tapetype_seen(tt, TAPETYPE_PART_CACHE_DIR)?
+ tapetype_get_part_cache_dir(tt) : "");
+ g_string_append_printf(args, "%s ", q);
+ g_free(q);
+
+ if (tapetype_seen(tt, TAPETYPE_PART_CACHE_MAX_SIZE)) {
+ g_string_append_printf(args, "%ju ",
+ (uintmax_t)tapetype_get_part_cache_max_size(tt)*1024);
+ } else {
+ g_string_append(args, "\"\" ");
+ }
+
+
+ return g_string_free(args, FALSE);
+}
+
int
taper_cmd(
cmd_t cmd,
{
char *cmdline = NULL;
char number[NUM_STR_SIZE];
- char splitsize[NUM_STR_SIZE];
- char fallback_splitsize[NUM_STR_SIZE];
- char *diskbuffer = NULL;
+ char orig_kb[NUM_STR_SIZE];
+ char *data_path;
disk_t *dp;
char *qname;
char *qdest;
char *q;
+ char *splitargs;
+ uintmax_t origsize;
switch(cmd) {
case START_TAPER:
- cmdline = vstralloc(cmdstr[cmd], " ", (char *)ptr, "\n", NULL);
+ cmdline = vstralloc(cmdstr[cmd],
+ " ", destname,
+ " ", datestamp,
+ "\n", NULL);
break;
case FILE_WRITE:
dp = (disk_t *) ptr;
qname = quote_string(dp->name);
qdest = quote_string(destname);
g_snprintf(number, SIZEOF(number), "%d", level);
- g_snprintf(splitsize, SIZEOF(splitsize), "%lld",
- (long long)dp->tape_splitsize * 1024);
+ if (sched(dp)->origsize >= 0)
+ origsize = sched(dp)->origsize;
+ else
+ origsize = 0;
+ g_snprintf(orig_kb, SIZEOF(orig_kb), "%ju", origsize);
+ splitargs = taper_splitting_args(dp);
cmdline = vstralloc(cmdstr[cmd],
+ " ", sched(dp)->taper->name,
" ", disk2serial(dp),
" ", qdest,
" ", dp->host->hostname,
" ", qname,
" ", number,
" ", datestamp,
- " ", splitsize,
+ " ", splitargs,
+ orig_kb,
"\n", NULL);
+ amfree(splitargs);
amfree(qdest);
amfree(qname);
break;
+
case PORT_WRITE:
dp = (disk_t *) ptr;
qname = quote_string(dp->name);
g_snprintf(number, SIZEOF(number), "%d", level);
+ data_path = data_path_to_string(dp->data_path);
/*
If we haven't been given a place to buffer split dumps to disk,
make the argument something besides and empty string so's taper
won't get confused
*/
- if(!dp->split_diskbuffer || dp->split_diskbuffer[0] == '\0'){
- diskbuffer = "NULL";
- } else {
- diskbuffer = dp->split_diskbuffer;
- }
- g_snprintf(splitsize, SIZEOF(splitsize), "%lld",
- (long long)dp->tape_splitsize * 1024);
- g_snprintf(fallback_splitsize, SIZEOF(fallback_splitsize), "%lld",
- (long long)dp->fallback_splitsize * 1024);
+ splitargs = taper_splitting_args(dp);
cmdline = vstralloc(cmdstr[cmd],
+ " ", sched(dp)->taper->name,
" ", disk2serial(dp),
" ", dp->host->hostname,
" ", qname,
" ", number,
" ", datestamp,
- " ", splitsize,
- " ", diskbuffer,
- " ", fallback_splitsize,
+ " ", splitargs,
+ data_path,
"\n", NULL);
+ amfree(splitargs);
amfree(qname);
break;
case DONE: /* handle */
+ dp = (disk_t *) ptr;
+ if (sched(dp)->origsize >= 0)
+ origsize = sched(dp)->origsize;
+ else
+ origsize = 0;
+ g_snprintf(number, SIZEOF(number), "%ju", origsize);
+ cmdline = vstralloc(cmdstr[cmd],
+ " ", sched(dp)->taper->name,
+ " ", disk2serial(dp),
+ " ", number,
+ "\n", NULL);
+ break;
case FAILED: /* handle */
dp = (disk_t *) ptr;
cmdline = vstralloc(cmdstr[cmd],
+ " ", sched(dp)->taper->name,
" ", disk2serial(dp),
"\n", NULL);
break;
case NO_NEW_TAPE:
- q = quote_string((char *)ptr);
+ dp = (disk_t *) ptr;
+ q = quote_string(destname); /* reason why no new tape */
cmdline = vstralloc(cmdstr[cmd],
+ " ", sched(dp)->taper->name,
+ " ", disk2serial(dp),
" ", q,
"\n", NULL);
amfree(q);
break;
case NEW_TAPE:
+ dp = (disk_t *) ptr;
+ cmdline = vstralloc(cmdstr[cmd],
+ " ", sched(dp)->taper->name,
+ " ", disk2serial(dp),
+ "\n", NULL);
+ break;
+ case START_SCAN:
+ dp = (disk_t *) ptr;
+ cmdline = vstralloc(cmdstr[cmd],
+ " ", sched(dp)->taper->name,
+ " ", disk2serial(dp),
+ "\n", NULL);
+ break;
+ case TAKE_SCRIBE_FROM:
+ dp = (disk_t *) ptr;
+ cmdline = vstralloc(cmdstr[cmd],
+ " ", sched(dp)->taper->name,
+ " ", disk2serial(dp),
+ " ", destname, /* name of worker */
+ "\n", NULL);
+ break;
case QUIT:
cmdline = stralloc2(cmdstr[cmd], "\n");
break;
g_printf(_("driver: send-cmd time %s to taper: %s"),
walltime_str(curclock()), cmdline);
fflush(stdout);
- if ((full_write(taper, cmdline, strlen(cmdline))) < strlen(cmdline)) {
+ if ((full_write(taper_fd, cmdline, strlen(cmdline))) < strlen(cmdline)) {
g_printf(_("writing taper command '%s' failed: %s\n"),
cmdline, strerror(errno));
fflush(stdout);
amfree(cmdline);
return 0;
}
- if(cmd == QUIT) aclose(taper);
+ if(cmd == QUIT) aclose(taper_fd);
amfree(cmdline);
return 1;
}
char *cmdline = NULL;
char number[NUM_STR_SIZE];
char numberport[NUM_STR_SIZE];
- char *o;
+ char *o, *oo;
char *device;
char *features;
char *qname;
}
if (dp != NULL) {
+ application_t *application = NULL;
+ char *plugin;
+ char *qplugin;
+ char *qamandad_path;
+ char *qclient_username;
+ char *qclient_port;
+ char *qssh_keys;
+
+ if (dp->application != NULL) {
+ application = lookup_application(dp->application);
+ g_assert(application != NULL);
+ }
+
device = quote_string((dp->device) ? dp->device : "NODEVICE");
qname = quote_string(dp->name);
g_snprintf(number, SIZEOF(number), "%d", sched(dp)->level);
g_snprintf(numberport, SIZEOF(numberport), "%d", dumper->output_port);
features = am_feature_to_string(dp->host->features);
if (am_has_feature(dp->host->features, fe_req_xml)) {
- o = xml_optionstr(dp, dp->host->features, NULL, 1);
- if (dp->application) {
- char *app = xml_application(dp->application,
- dp->host->features);
- vstrextend(&o, app, NULL);
- amfree(app);
+ o = xml_optionstr(dp, 1);
+ if (application) {
+ char *xml_app;
+ xml_app = xml_application(dp, application,
+ dp->host->features);
+ vstrextend(&o, xml_app, NULL);
+ amfree(xml_app);
}
- o = quote_string(o);
+ oo = quote_string(o);
+ amfree(o);
+ o = oo;
} else {
- o = optionstr(dp, dp->host->features, NULL);
+ o = optionstr(dp);
}
- if ( o == NULL ) {
- error(_("problem with option string, check the dumptype definition.\n"));
+
+ g_assert(dp->program);
+ if (0 == strcmp(dp->program, "APPLICATION")) {
+ g_assert(application != NULL);
+ plugin = application_get_plugin(application);
+ } else {
+ plugin = dp->program;
}
+ qplugin = quote_string(plugin);
+ qamandad_path = quote_string(dp->amandad_path);
+ qclient_username = quote_string(dp->client_username);
+ qclient_port = quote_string(dp->client_port);
+ qssh_keys = quote_string(dp->ssh_keys);
+ dbprintf("security_driver %s\n", dp->auth);
- dbprintf("security_driver %s\n", dp->security_driver);
cmdline = vstralloc(cmdstr[cmd],
" ", disk2serial(dp),
" ", numberport,
" ", device,
" ", number,
" ", sched(dp)->dumpdate,
- " ", dp->program && strcmp(dp->program,"APPLICATION")!=0 ? dp->program: application_get_plugin(dp->application),
- " ", dp->amandad_path,
- " ", dp->client_username,
- " ", dp->ssh_keys,
- " ", dp->security_driver,
+ " ", qplugin,
+ " ", qamandad_path,
+ " ", qclient_username,
+ " ", qclient_port,
+ " ", qssh_keys,
+ " ", dp->auth,
+ " ", data_path_to_string(dp->data_path),
+ " ", dp->dataport_list,
" |", o,
"\n", NULL);
+ amfree(qplugin);
+ amfree(qamandad_path);
+ amfree(qclient_username);
+ amfree(qclient_port);
+ amfree(qssh_keys);
amfree(features);
amfree(o);
amfree(qname);
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"));
- }
+ o = optionstr(dp);
cmdline = vstralloc(cmdstr[cmd],
" ", disk2serial(dp),
" ", qdest,
" ", disk2serial(dp),
"\n", NULL);
} else {
- cmdline = vstralloc(cmdstr[cmd], "\n");
+ cmdline = vstralloc(cmdstr[cmd], "\n", NULL);
}
break;
default:
return 1;
}
-#define MAX_SERIAL MAX_DUMPERS+1 /* one for the taper */
+#define MAX_SERIAL MAX_DUMPERS*2 /* one for each dumper and taper */
long generation = 1;
}
}
- g_printf(_("driver: error time %s serial not found\n"),
- walltime_str(curclock()));
+ g_printf(_("driver: error time %s serial not found for disk %s\n"),
+ walltime_str(curclock()), dp->name);
}
infp->size = origsize;
infp->csize = dumpsize;
infp->secs = dumptime;
- infp->date = sched(dp)->timestamp;
+ infp->date = get_time_from_timestamp(sched(dp)->datestamp);
if(level == 0) perfp = &info.full;
else perfp = &info.incr;
if (origsize >= (off_t)0 && level == info.last_level) {
info.consecutive_runs++;
- } else if (origsize >= (off_t)0 || level < info.last_level) {
+ } else if (origsize >= (off_t)0) {
info.last_level = level;
info.consecutive_runs = 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].date = get_time_from_timestamp(sched(dp)->datestamp);
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);
+ if (put_info(dp->host->hostname, dp->name, &info)) {
+ int save_errno = errno;
+ g_fprintf(stderr, _("infofile update failed (%s,'%s'): %s\n"),
+ dp->host->hostname, dp->name, strerror(save_errno));
+ log_add(L_ERROR, _("infofile update failed (%s,'%s'): %s\n"),
+ dp->host->hostname, dp->name, strerror(save_errno));
+ error(_("infofile update failed (%s,'%s'): %s\n"),
+ dp->host->hostname, dp->name, strerror(save_errno));
/*NOTREACHED*/
}
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);
+ if (put_info(dp->host->hostname, dp->name, &info)) {
+ int save_errno = errno;
+ g_fprintf(stderr, _("infofile update failed (%s,'%s'): %s\n"),
+ dp->host->hostname, dp->name, strerror(save_errno));
+ log_add(L_ERROR, _("infofile update failed (%s,'%s'): %s\n"),
+ dp->host->hostname, dp->name, strerror(save_errno));
+ error(_("infofile update failed (%s,'%s'): %s\n"),
+ dp->host->hostname, dp->name, strerror(save_errno));
/*NOTREACHED*/
}
close_infofile();