2012-02-21 20:55:09 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2012 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
// cmdline interface for VDA (volunteer data archival)
|
|
|
|
//
|
|
|
|
// usages:
|
|
|
|
// vda add path add a file
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2012-07-02 18:51:02 +00:00
|
|
|
#include <unistd.h>
|
2012-07-23 21:53:09 +00:00
|
|
|
#include <set>
|
2012-02-21 20:55:09 +00:00
|
|
|
|
|
|
|
#include "boinc_db.h"
|
2012-02-24 03:09:56 +00:00
|
|
|
#include "filesys.h"
|
2012-02-21 20:55:09 +00:00
|
|
|
#include "sched_config.h"
|
2012-02-29 07:22:59 +00:00
|
|
|
#include "sched_util.h"
|
2013-06-07 00:31:46 +00:00
|
|
|
#include "str_replace.h"
|
2012-02-21 20:55:09 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
#include "vda_lib.h"
|
|
|
|
|
2012-07-23 21:53:09 +00:00
|
|
|
using std::set;
|
|
|
|
|
2012-02-21 20:55:09 +00:00
|
|
|
void usage() {
|
2012-08-12 06:54:20 +00:00
|
|
|
printf("Usage: vda [add|remove|retrieve|status] path\n");
|
2012-02-21 20:55:09 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2012-07-23 21:53:09 +00:00
|
|
|
void show_msg(char* msg) {
|
|
|
|
printf("%s", msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const char* indent(int n) {
|
|
|
|
static const char *buf = " ";
|
|
|
|
static int len = strlen(buf);
|
|
|
|
return buf + len - n*3;
|
|
|
|
}
|
|
|
|
|
|
|
|
void META_CHUNK::print_status(int level) {
|
|
|
|
printf("%smeta-chunk %s\n", indent(level), name);
|
|
|
|
for (unsigned int i=0; i<children.size(); i++) {
|
|
|
|
if (bottom_level) {
|
|
|
|
CHUNK* c = (CHUNK*)children[i];
|
|
|
|
c->print_status(level+1);
|
|
|
|
} else {
|
|
|
|
META_CHUNK* mc = (META_CHUNK*)children[i];
|
|
|
|
mc->print_status(level+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHUNK::print_status(int level) {
|
|
|
|
printf("%schunk %s\n", indent(level), name);
|
2012-08-08 21:37:51 +00:00
|
|
|
level++;
|
|
|
|
printf(
|
|
|
|
"%spresent on server: %s\n",
|
|
|
|
indent(level), present_on_server?"yes":"no"
|
|
|
|
);
|
2012-07-23 21:53:09 +00:00
|
|
|
set<VDA_CHUNK_HOST*>::iterator i;
|
|
|
|
for (i=hosts.begin(); i!=hosts.end(); i++) {
|
|
|
|
VDA_CHUNK_HOST* ch = *i;
|
2012-08-08 21:37:51 +00:00
|
|
|
ch->print_status(level);
|
2012-07-23 21:53:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VDA_CHUNK_HOST::print_status(int level) {
|
|
|
|
printf("%shost %d\n", indent(level), host_id);
|
2012-08-08 21:37:51 +00:00
|
|
|
level++;
|
2012-07-23 21:53:09 +00:00
|
|
|
printf("%spresent on host: %s\n",
|
|
|
|
indent(level), present_on_host?"yes":"no"
|
|
|
|
);
|
|
|
|
printf("%stransfer in progress: %s\n",
|
|
|
|
indent(level), transfer_in_progress?"yes":"no"
|
|
|
|
);
|
|
|
|
printf("%stransfer wait: %s\n",
|
|
|
|
indent(level), transfer_wait?"yes":"no"
|
|
|
|
);
|
|
|
|
if (transfer_request_time) {
|
|
|
|
printf("%stransfer request time: %s\n",
|
|
|
|
indent(level), time_to_string(transfer_request_time)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (transfer_send_time) {
|
|
|
|
printf("%stransfer send time: %s\n",
|
|
|
|
indent(level), time_to_string(transfer_send_time)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-21 20:55:09 +00:00
|
|
|
int handle_add(const char* path) {
|
2013-06-04 05:42:53 +00:00
|
|
|
char dir[MAXPATHLEN], filename[256], buf[1024];
|
2012-02-21 20:55:09 +00:00
|
|
|
DB_VDA_FILE vf;
|
|
|
|
POLICY policy;
|
2012-02-24 03:09:56 +00:00
|
|
|
double size;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
retval = file_size(path, size);
|
|
|
|
if (retval) {
|
2012-08-12 06:54:20 +00:00
|
|
|
printf("no file %s\n", path);
|
2012-02-24 03:09:56 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2012-02-21 20:55:09 +00:00
|
|
|
|
2013-06-04 05:42:53 +00:00
|
|
|
safe_strcpy(dir, path);
|
2012-02-21 20:55:09 +00:00
|
|
|
char* p = strrchr(dir, '/');
|
|
|
|
*p = 0;
|
2013-06-04 05:42:53 +00:00
|
|
|
safe_strcpy(filename, p+1);
|
2012-02-21 20:55:09 +00:00
|
|
|
|
2012-02-24 21:13:00 +00:00
|
|
|
// make sure there's a valid policy file in the dir
|
2012-02-21 20:55:09 +00:00
|
|
|
//
|
|
|
|
sprintf(buf, "%s/boinc_meta.txt", dir);
|
2012-02-24 03:09:56 +00:00
|
|
|
retval = policy.parse(buf);
|
2012-02-21 20:55:09 +00:00
|
|
|
if (retval) {
|
2012-08-12 06:54:20 +00:00
|
|
|
printf("Can't parse policy file.\n");
|
2012-02-21 20:55:09 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-02-24 21:13:00 +00:00
|
|
|
// add a DB record and mark it for update
|
2012-02-21 20:55:09 +00:00
|
|
|
//
|
2012-02-24 03:09:56 +00:00
|
|
|
vf.create_time = dtime();
|
2013-06-04 05:42:53 +00:00
|
|
|
safe_strcpy(vf.dir, dir);
|
|
|
|
safe_strcpy(vf.file_name, filename);
|
2012-02-24 03:09:56 +00:00
|
|
|
vf.size = size;
|
2012-07-25 21:41:32 +00:00
|
|
|
vf.chunk_size = 0; // don't know this yet; set by vdad
|
2012-02-21 20:55:09 +00:00
|
|
|
vf.need_update = 1;
|
2012-02-24 03:09:56 +00:00
|
|
|
vf.initialized = 0;
|
2012-03-29 07:58:47 +00:00
|
|
|
vf.retrieving = 0;
|
2012-08-17 06:10:25 +00:00
|
|
|
vf.retrieved = 0;
|
2012-02-21 20:55:09 +00:00
|
|
|
retval = vf.insert();
|
|
|
|
if (retval) {
|
2012-08-12 06:54:20 +00:00
|
|
|
printf("Can't insert DB record\n");
|
2012-02-21 20:55:09 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-29 07:22:59 +00:00
|
|
|
int handle_remove(const char* name) {
|
|
|
|
DB_VDA_FILE vf;
|
|
|
|
char buf[1024];
|
2012-07-23 21:53:09 +00:00
|
|
|
sprintf(buf, "where file_name='%s'", name);
|
2012-02-29 07:22:59 +00:00
|
|
|
int retval = vf.lookup(buf);
|
|
|
|
if (retval) return retval;
|
|
|
|
|
|
|
|
// delete DB records
|
|
|
|
//
|
|
|
|
DB_VDA_CHUNK_HOST ch;
|
|
|
|
sprintf(buf, "vda_file_id=%d", vf.id);
|
|
|
|
ch.delete_from_db_multi(buf);
|
|
|
|
vf.delete_from_db();
|
|
|
|
|
2012-03-29 07:58:47 +00:00
|
|
|
// remove symlink from download hier
|
|
|
|
//
|
2012-02-29 07:22:59 +00:00
|
|
|
dir_hier_path(name, config.download_dir, config.uldl_dir_fanout, buf);
|
|
|
|
unlink(buf);
|
2012-03-29 07:58:47 +00:00
|
|
|
|
|
|
|
// remove encoded data and directories
|
|
|
|
//
|
2012-02-29 07:22:59 +00:00
|
|
|
retval = chdir(vf.dir);
|
|
|
|
if (retval) perror("chdir");
|
2012-08-17 23:27:44 +00:00
|
|
|
retval = system("/bin/rm -rf [0-9]* Coding data.vda chunk_sizes.txt");
|
2012-02-29 07:22:59 +00:00
|
|
|
if (retval) perror("system");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-29 20:58:45 +00:00
|
|
|
int handle_retrieve(const char* name) {
|
|
|
|
DB_VDA_FILE vf;
|
|
|
|
char buf[1024];
|
2012-07-23 21:53:09 +00:00
|
|
|
sprintf(buf, "where file_name='%s'", name);
|
2012-02-29 20:58:45 +00:00
|
|
|
int retval = vf.lookup(buf);
|
|
|
|
if (retval) return retval;
|
2012-08-15 21:27:38 +00:00
|
|
|
retval = vf.update_field("retrieving=1, need_update=1");
|
2012-02-29 20:58:45 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
int handle_status(const char* name) {
|
2012-07-23 21:53:09 +00:00
|
|
|
DB_VDA_FILE dvf;
|
2012-02-29 20:58:45 +00:00
|
|
|
char buf[1024];
|
2012-07-23 21:53:09 +00:00
|
|
|
sprintf(buf, "where file_name='%s'", name);
|
|
|
|
int retval = dvf.lookup(buf);
|
2012-02-29 20:58:45 +00:00
|
|
|
if (retval) return retval;
|
2012-07-23 21:53:09 +00:00
|
|
|
|
|
|
|
VDA_FILE_AUX vf = dvf;
|
|
|
|
sprintf(buf, "%s/boinc_meta.txt", vf.dir);
|
|
|
|
retval = vf.policy.parse(buf);
|
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(MSG_CRITICAL, "Can't parse policy file %s\n", buf);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
retval = vf.get_state();
|
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(MSG_CRITICAL, "Can't get file state: %d\n", retval);
|
|
|
|
return retval;
|
|
|
|
}
|
2012-08-17 06:10:25 +00:00
|
|
|
printf("status for file %s:\n", vf.file_name);
|
2012-08-15 21:27:38 +00:00
|
|
|
vf.meta_chunk->recovery_plan();
|
|
|
|
vf.meta_chunk->compute_min_failures();
|
2012-07-23 21:53:09 +00:00
|
|
|
vf.meta_chunk->print_status(0);
|
2012-08-15 21:27:38 +00:00
|
|
|
printf("fault tolerance level: %d\n", vf.meta_chunk->min_failures-1);
|
2012-08-17 06:10:25 +00:00
|
|
|
if (vf.retrieving) {
|
|
|
|
if (vf.retrieved) {
|
|
|
|
printf("Retrieving: completed\n");
|
|
|
|
} else {
|
|
|
|
printf("Retrieving: in progress\n");
|
|
|
|
}
|
|
|
|
}
|
2012-07-23 21:53:09 +00:00
|
|
|
|
2012-02-29 20:58:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-12 06:54:20 +00:00
|
|
|
int handle_update(const char* name) {
|
|
|
|
DB_VDA_FILE dvf;
|
|
|
|
char buf[1024];
|
|
|
|
sprintf(buf, "where file_name='%s'", name);
|
|
|
|
int retval = dvf.lookup(buf);
|
|
|
|
if (retval) return retval;
|
|
|
|
return dvf.update_field("need_update=1");
|
|
|
|
}
|
|
|
|
|
2012-02-21 20:55:09 +00:00
|
|
|
int main(int argc, char** argv) {
|
|
|
|
int retval = config.parse_file();
|
|
|
|
if (retval) {
|
2012-08-12 06:54:20 +00:00
|
|
|
printf("can't parse config file\n");
|
2012-02-21 20:55:09 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
retval = boinc_db.open(
|
|
|
|
config.db_name, config.db_host, config.db_user, config.db_passwd
|
|
|
|
);
|
|
|
|
if (retval) {
|
2012-08-12 06:54:20 +00:00
|
|
|
printf("can't open DB\n");
|
2012-02-21 20:55:09 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
for (int i=1; i<argc; i++) {
|
|
|
|
if (!strcmp(argv[i], "add")) {
|
|
|
|
if (argc != 3) usage();
|
|
|
|
retval = handle_add(argv[++i]);
|
|
|
|
if (retval) {
|
2012-08-12 06:54:20 +00:00
|
|
|
printf("error %d: %s\n", retval, boincerror(retval));
|
2012-02-21 20:55:09 +00:00
|
|
|
} else {
|
|
|
|
printf("file added successfully\n");
|
|
|
|
}
|
|
|
|
exit(retval);
|
|
|
|
}
|
2012-02-29 07:22:59 +00:00
|
|
|
if (!strcmp(argv[i], "remove")) {
|
|
|
|
if (argc != 3) usage();
|
|
|
|
retval = handle_remove(argv[++i]);
|
|
|
|
if (retval) {
|
2012-08-12 06:54:20 +00:00
|
|
|
printf("error %d: %s\n", retval, boincerror(retval));
|
2012-02-29 07:22:59 +00:00
|
|
|
} else {
|
|
|
|
printf("file removed successfully\n");
|
|
|
|
}
|
|
|
|
exit(retval);
|
|
|
|
}
|
2012-02-29 20:58:45 +00:00
|
|
|
if (!strcmp(argv[i], "retrieve")) {
|
|
|
|
if (argc != 3) usage();
|
|
|
|
retval = handle_retrieve(argv[++i]);
|
|
|
|
if (retval) {
|
2012-08-12 06:54:20 +00:00
|
|
|
printf("error %d: %s\n", retval, boincerror(retval));
|
2012-02-29 20:58:45 +00:00
|
|
|
} else {
|
|
|
|
printf("file retrieval started\n");
|
|
|
|
}
|
|
|
|
exit(retval);
|
|
|
|
}
|
|
|
|
if (!strcmp(argv[i], "status")) {
|
|
|
|
if (argc != 3) usage();
|
|
|
|
retval = handle_status(argv[++i]);
|
|
|
|
if (retval) {
|
2012-08-12 06:54:20 +00:00
|
|
|
printf("error %d: %s\n", retval, boincerror(retval));
|
|
|
|
}
|
|
|
|
exit(retval);
|
|
|
|
}
|
|
|
|
if (!strcmp(argv[i], "update")) {
|
|
|
|
if (argc != 3) usage();
|
|
|
|
retval = handle_update(argv[++i]);
|
|
|
|
if (retval) {
|
|
|
|
printf("error %d: %s\n", retval, boincerror(retval));
|
|
|
|
} else {
|
|
|
|
printf("file marked for update by vdad\n");
|
2012-02-29 20:58:45 +00:00
|
|
|
}
|
|
|
|
exit(retval);
|
|
|
|
}
|
2012-02-21 20:55:09 +00:00
|
|
|
usage();
|
|
|
|
}
|
|
|
|
usage();
|
|
|
|
}
|