From 450c5592aee49ea660593d25e453d1fed904e514 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 6 Jan 2013 16:45:11 -0800 Subject: [PATCH] - scheduler: add feature for deleting no-longer-used sticky files. Create a file "file_delete_regex" in your project dir. Each line is a regular expression. Any sticky file whose name matches one of the expressions is deleted. --- sched/Makefile.am | 5 ++-- sched/handle_request.cpp | 5 ++++ sched/sched_files.cpp | 61 ++++++++++++++++++++++++++++++++++++++++ sched/sched_files.h | 19 +++++++++++++ sched/sched_main.cpp | 18 ++++++------ 5 files changed, 98 insertions(+), 10 deletions(-) create mode 100644 sched/sched_files.cpp create mode 100644 sched/sched_files.h diff --git a/sched/Makefile.am b/sched/Makefile.am index d793b0a87c..3a789fadd1 100644 --- a/sched/Makefile.am +++ b/sched/Makefile.am @@ -149,14 +149,15 @@ cgi_sources = \ hr.cpp \ hr_info.cpp \ plan_class_spec.cpp \ - sched_main.cpp \ sched_array.cpp \ sched_assign.cpp \ sched_customize.cpp \ + sched_files.cpp \ sched_hr.cpp \ - sched_resend.cpp \ sched_limit.cpp \ sched_locality.cpp \ + sched_main.cpp \ + sched_resend.cpp \ sched_result.cpp \ sched_score.cpp \ sched_send.cpp \ diff --git a/sched/handle_request.cpp b/sched/handle_request.cpp index f259f0970f..97f26d13a2 100644 --- a/sched/handle_request.cpp +++ b/sched/handle_request.cpp @@ -50,6 +50,7 @@ #include "sched_vda.h" #include "credit.h" +#include "sched_files.h" #include "sched_main.h" #include "sched_types.h" #include "sched_util.h" @@ -1101,6 +1102,10 @@ void process_request(char* code_sign_key) { memset(&g_reply->wreq, 0, sizeof(g_reply->wreq)); + // if client has sticky files we don't need any more, tell it + // + do_file_delete_regex(); + // if different major version of BOINC, just send a message // if (wrong_core_client_version() diff --git a/sched/sched_files.cpp b/sched/sched_files.cpp new file mode 100644 index 0000000000..b81515294d --- /dev/null +++ b/sched/sched_files.cpp @@ -0,0 +1,61 @@ +// This file is part of BOINC. +// http://boinc.berkeley.edu +// Copyright (C) 2013 University of California +// +// BOINC is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// BOINC is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with BOINC. If not, see . + +#include +#include +#include + +#include "sched_msgs.h" +#include "sched_types.h" +#include "str_util.h" + +#include "sched_files.h" + +std::vector file_delete_regex; + +int init_file_delete_regex() { + char buf[256]; + FILE* f = fopen("../file_delete_regex", "r"); + if (!f) return 0; + while (fgets(buf, sizeof(buf), f)) { + strip_whitespace(buf); + if (!strlen(buf)) continue; + regex_t re; + if (regcomp(&re, buf, REG_EXTENDED|REG_NOSUB)) { + log_messages.printf(MSG_CRITICAL, + "invalid regular expression in file_delete_regex: %s\n", buf + ); + } else { + file_delete_regex.push_back(re); + } + } + return 0; +} + +int do_file_delete_regex() { + for (unsigned int i=0; ifile_infos.size(); i++) { + FILE_INFO& fi = g_request->file_infos[i]; + for (unsigned int j=0; jfile_deletes.push_back(fi); + break; + } + } + } + return 0; +} diff --git a/sched/sched_files.h b/sched/sched_files.h new file mode 100644 index 0000000000..0309fc7e6e --- /dev/null +++ b/sched/sched_files.h @@ -0,0 +1,19 @@ +// This file is part of BOINC. +// http://boinc.berkeley.edu +// Copyright (C) 2013 University of California +// +// BOINC is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// BOINC is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with BOINC. If not, see . + +extern int init_file_delete_regex(); +extern int do_file_delete_regex(); diff --git a/sched/sched_main.cpp b/sched/sched_main.cpp index 3ce90524ab..4ebc2b514e 100644 --- a/sched/sched_main.cpp +++ b/sched/sched_main.cpp @@ -43,22 +43,23 @@ #include #include "boinc_db.h" -#include "parse.h" -#include "filesys.h" #include "error_numbers.h" +#include "filesys.h" +#include "parse.h" #include "shmem.h" -#include "util.h" #include "str_util.h" -#include "synch.h" #include "svn_version.h" +#include "synch.h" +#include "util.h" -#include "sched_config.h" -#include "sched_types.h" #include "handle_request.h" -#include "sched_util.h" +#include "sched_config.h" +#include "sched_files.h" #include "sched_msgs.h" -#include "sched_main.h" +#include "sched_types.h" +#include "sched_util.h" +#include "sched_main.h" // Useful for debugging, if your cgi script keeps crashing. This // makes it dump a core file that you can load into a debugger to see @@ -494,6 +495,7 @@ int main(int argc, char** argv) { gui_urls.init(); project_files.init(); + init_file_delete_regex(); sprintf(path, "%s/code_sign_public", config.key_dir); retval = read_file_malloc(path, code_sign_key);