X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=server-src%2Fserver_util.c;h=72462a3668479c7a7bad348f997bb868145be15b;hb=HEAD;hp=e649359886863ff4a4b64ec250b32036c8b5de53;hpb=d5853102f67d85d8e169f9dbe973ad573306c215;p=debian%2Famanda diff --git a/server-src/server_util.c b/server-src/server_util.c index e649359..72462a3 100644 --- a/server-src/server_util.c +++ b/server-src/server_util.c @@ -1,6 +1,7 @@ /* * Amanda, The Advanced Maryland Automatic Network Disk Archiver * Copyright (c) 1991-1999 University of Maryland at College Park + * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved. * All Rights Reserved. * * Permission to use, copy, modify, distribute, and sell this software and its @@ -49,8 +50,8 @@ const char *cmdstr[] = { "PARTDONE", "PORT-WRITE", "DUMPER-STATUS", /* taper cmds */ "PORT", "TAPE-ERROR", "TAPER-OK", /* taper results */ - "REQUEST-NEW-TAPE", "DIRECTTCP-PORT", - "LAST_TOK", + "REQUEST-NEW-TAPE", "DIRECTTCP-PORT", "TAKE-SCRIBE-FROM", + "START-SCAN", "CLOSE-VOLUME", "LAST_TOK", NULL }; @@ -216,6 +217,9 @@ int check_infofile( return -1; } } + amfree(old_hostinfodir); + amfree(old_diskdir); + amfree(old_infofile); } amfree(diskdir); amfree(hostinfodir); @@ -241,6 +245,8 @@ run_server_script( char *line; char *plugin; char level_number[NUM_STR_SIZE]; + struct stat cmd_stat; + int result; if ((pp_script_get_execute_on(pp_script) & execute_on) == 0) return; @@ -248,40 +254,78 @@ run_server_script( return; plugin = pp_script_get_plugin(pp_script); + cmd = vstralloc(APPLICATION_DIR, "/", plugin, NULL); + result = stat(cmd, &cmd_stat); + if (result == -1) { + dbprintf("Can't stat script '%s': %s\n", cmd, strerror(errno)); + amfree(cmd); + cmd = vstralloc(get_config_dir(), "/application/", plugin, NULL); + result = stat(cmd, &cmd_stat); + if (result == -1) { + dbprintf("Can't stat script '%s': %s\n", cmd, strerror(errno)); + amfree(cmd); + cmd = vstralloc(CONFIG_DIR, "/application/", plugin, NULL); + result = stat(cmd, &cmd_stat); + if (result == -1) { + dbprintf("Can't stat script '%s': %s\n", cmd, strerror(errno)); + amfree(cmd); + cmd = vstralloc(APPLICATION_DIR, "/", plugin, NULL); + } + } + } + g_ptr_array_add(argv_ptr, stralloc(plugin)); switch (execute_on) { + case EXECUTE_ON_PRE_AMCHECK: + command = "PRE-AMCHECK"; + break; case EXECUTE_ON_PRE_DLE_AMCHECK: command = "PRE-DLE-AMCHECK"; break; case EXECUTE_ON_PRE_HOST_AMCHECK: command = "PRE-HOST-AMCHECK"; break; + case EXECUTE_ON_POST_AMCHECK: + command = "POST-AMCHECK"; + break; case EXECUTE_ON_POST_DLE_AMCHECK: command = "POST-DLE-AMCHECK"; break; case EXECUTE_ON_POST_HOST_AMCHECK: command = "POST-HOST-AMCHECK"; break; + case EXECUTE_ON_PRE_ESTIMATE: + command = "PRE-ESTIMATE"; + break; case EXECUTE_ON_PRE_DLE_ESTIMATE: command = "PRE-DLE-ESTIMATE"; break; case EXECUTE_ON_PRE_HOST_ESTIMATE: command = "PRE-HOST-ESTIMATE"; break; + case EXECUTE_ON_POST_ESTIMATE: + command = "POST-ESTIMATE"; + break; case EXECUTE_ON_POST_DLE_ESTIMATE: command = "POST-DLE-ESTIMATE"; break; case EXECUTE_ON_POST_HOST_ESTIMATE: command = "POST-HOST-ESTIMATE"; break; + case EXECUTE_ON_PRE_BACKUP: + command = "PRE-BACKUP"; + break; case EXECUTE_ON_PRE_DLE_BACKUP: command = "PRE-DLE-BACKUP"; break; case EXECUTE_ON_PRE_HOST_BACKUP: command = "PRE-HOST-BACKUP"; break; + case EXECUTE_ON_POST_BACKUP: + command = "POST-BACKUP"; + break; case EXECUTE_ON_POST_DLE_BACKUP: command = "POST-DLE-BACKUP"; break; @@ -338,16 +382,18 @@ run_server_script( if (streamout) { while((line = agets(streamout)) != NULL) { dbprintf("script: %s\n", line); + amfree(line); } } fclose(streamout); waitpid(scriptpid, NULL, 0); g_ptr_array_free_full(argv_ptr); + amfree(cmd); } void -run_server_scripts( +run_server_dle_scripts( execute_on_t execute_on, char *config, disk_t *dp, @@ -363,6 +409,84 @@ run_server_scripts( } } +void +run_server_host_scripts( + execute_on_t execute_on, + char *config, + am_host_t *hostp) +{ + identlist_t pp_scriptlist; + disk_t *dp; + + GHashTable* executed = g_hash_table_new_full(g_str_hash, g_str_equal, + NULL, NULL); + for (dp = hostp->disks; dp != NULL; dp = dp->hostnext) { + if (dp->todo) { + for (pp_scriptlist = dp->pp_scriptlist; pp_scriptlist != NULL; + pp_scriptlist = pp_scriptlist->next) { + int todo = 1; + pp_script_t *pp_script = lookup_pp_script((char *)pp_scriptlist->data); + g_assert(pp_script != NULL); + if (pp_script_get_single_execution(pp_script)) { + todo = g_hash_table_lookup(executed, + pp_script_get_plugin(pp_script)) + == NULL; + } + if (todo) { + run_server_script(pp_script, execute_on, config, dp, -1); + if (pp_script_get_single_execution(pp_script)) { + g_hash_table_insert(executed, + pp_script_get_plugin(pp_script), + GINT_TO_POINTER(1)); + } + } + } + } + } + + g_hash_table_destroy(executed); +} + +void +run_server_global_scripts( + execute_on_t execute_on, + char *config) +{ + identlist_t pp_scriptlist; + disk_t *dp; + am_host_t *host; + + GHashTable* executed = g_hash_table_new_full(g_str_hash, g_str_equal, + NULL, NULL); + for (host = get_hostlist(); host != NULL; host = host->next) { + for (dp = host->disks; dp != NULL; dp = dp->hostnext) { + if (dp->todo) { + for (pp_scriptlist = dp->pp_scriptlist; pp_scriptlist != NULL; + pp_scriptlist = pp_scriptlist->next) { + int todo = 1; + pp_script_t *pp_script = + lookup_pp_script((char *)pp_scriptlist->data); + g_assert(pp_script != NULL); + if (pp_script_get_single_execution(pp_script)) { + todo = g_hash_table_lookup(executed, + pp_script_get_plugin(pp_script)) == NULL; + } + if (todo) { + run_server_script(pp_script, execute_on, config, + dp, -1); + if (pp_script_get_single_execution(pp_script)) { + g_hash_table_insert(executed, + pp_script_get_plugin(pp_script), + GINT_TO_POINTER(1)); + } + } + } + } + } + } + g_hash_table_destroy(executed); +} + void run_amcleanup( char *config_name) @@ -509,8 +633,10 @@ internal_server_estimate( size = (gint64)10000; if (size > tapetype_get_length(tape)/2) size = tapetype_get_length(tape)/2; - if (size > level0_size/2) - size = level0_size/2; + if (level0_size > 0 && dp->strategy != DS_NOFULL) { + if (size > level0_size/2) + size = level0_size/2; + } *stats = 0; } } @@ -543,10 +669,18 @@ internal_server_estimate( size = (gint64)100000; if (size > tapetype_get_length(tape)/2) size = tapetype_get_length(tape)/2; - if (size > level0_size/2) - size = level0_size/2; + if (level0_size > 0 && dp->strategy != DS_NOFULL) { + if (size > level0_size/2) + size = level0_size/2; + } *stats = 0; } + } else { + char *conf_tapetype = getconf_str(CNF_TAPETYPE); + tapetype_t *tape = lookup_tapetype(conf_tapetype); + size = (gint64)100000; + if (size > tapetype_get_length(tape)/2) + size = tapetype_get_length(tape)/2; } return size; @@ -558,10 +692,9 @@ server_can_do_estimate( info_t *info, int level) { - gint64 size; int stats; - size = internal_server_estimate(dp, info, level, &stats); + internal_server_estimate(dp, info, level, &stats); return stats; }