*** empty log message ***

svn path=/trunk/boinc/; revision=12235
This commit is contained in:
David Anderson 2007-03-15 23:01:51 +00:00
parent e8c8d86fb4
commit 71afcf8c06
7 changed files with 89 additions and 46 deletions

View File

@ -2525,3 +2525,31 @@ David 15 Mar 2007
lib/
hostinfo.C
prefs.C,h
David 15 Mar 2007
- core client: change the way slot directories are assigned,
and the way things are cleaned up.
The new design ensures that apps always start running
in an empty directory.
Old:
assign new ACTIVE_TASK the lowest slot number not in use.
When the app starts, try to clean out the slot dir.
If can't clean it out, rename it (to DELETE_ME_*)
and create another dir.
On startup, delete dirs named DELETE_ME_*
The problem: if you can't clean out a dir (on Windows)
you're not going to be able to rename it.
So the app will start in a non-empty dir.
New:
assign new ACTIVE_TASK the lowest slot number not in use
and for which an empty directory can be created.
On start, delete dirs and files not in use by an active task.
- core client: fix bug where clean_out_dir() could return zero
even though the dir isn't emptied.
client/
app.C,h
app_start.C
file_names.C,h
lib/
filesys.C

View File

@ -369,22 +369,49 @@ int ACTIVE_TASK::current_disk_usage(double& size) {
return 0;
}
// Get the next free slot
bool ACTIVE_TASK_SET::is_slot_in_use(int slot) {
unsigned int i;
for (i=0; i<active_tasks.size(); i++) {
if (active_tasks[i]->slot == slot) {
return true;
}
}
return false;
}
bool ACTIVE_TASK_SET::is_slot_dir_in_use(char* dir) {
char path[1024];
unsigned int i;
for (i=0; i<active_tasks.size(); i++) {
get_slot_dir(active_tasks[i]->slot, path, sizeof(path));
if (!strcmp(path, dir)) return true;
}
return false;
}
// Get a free slot,
// and make a slot dir if needed
//
int ACTIVE_TASK_SET::get_free_slot() {
unsigned int i;
int j;
bool found;
int j, retval;
char path[1024];
for (j=0; ; j++) {
found = false;
for (i=0; i<active_tasks.size(); i++) {
if (active_tasks[i]->slot == j) {
found = true;
break;
if (is_slot_in_use(j)) continue;
// make sure we can make an empty directory for this slot
//
get_slot_dir(j, path, sizeof(path));
if (boinc_file_exists(path)) {
if (is_dir(path)) {
retval = clean_out_dir(path);
if (!retval) return j;
}
} else {
retval = make_slot_dir(j);
if (!retval) return j;
}
if (!found) return j;
}
return ERR_NOT_FOUND; // probably never get here
}

View File

@ -226,6 +226,8 @@ public:
bool check_app_exited();
bool check_rsc_limits_exceeded();
bool check_quit_timeout_exceeded();
bool is_slot_in_use(int);
bool is_slot_dir_in_use(char*);
int get_free_slot();
void send_heartbeats();
void send_trickle_downs();

View File

@ -699,14 +699,6 @@ int ACTIVE_TASK::resume_or_start(bool first_time) {
switch (task_state()) {
case PROCESS_UNINITIALIZED:
if (first_time) {
if (!boinc_file_exists(slot_dir)) {
make_slot_dir(slot);
}
retval = clean_out_dir(slot_dir);
if (retval) {
retval = rename_slot_dir(slot);
if (!retval) retval = make_slot_dir(slot);
}
retval = start(true);
str = "Starting";
} else {

View File

@ -170,20 +170,7 @@ int make_slot_dir(int slot) {
return retval;
}
// A slot dir can't be cleaned out
// (e.g. a virus-checker has a file locked).
// Rename it to DELETE_ME_x
//
int rename_slot_dir(int slot) {
char oldname[1024], newname[1024];
sprintf(oldname, "%s/%d", SLOTS_DIR, slot);
sprintf(newname, "%s/DELETE_ME_%d_%d", SLOTS_DIR, slot, (int)gstate.now);
int retval = rename(oldname, newname);
if (retval) return ERR_RENAME;
return 0;
}
// delete directories created by the above
// delete unused stuff in the slots/ directory
//
void delete_old_slot_dirs() {
char filename[1024], path[1024];
@ -196,10 +183,14 @@ void delete_old_slot_dirs() {
strcpy(filename, "");
retval = dir_scan(filename, dirp, sizeof(filename));
if (retval) break;
if (strstr(filename, "DELETE_ME")) {
sprintf(path, "%s/%s", SLOTS_DIR, filename);
clean_out_dir(path);
boinc_rmdir(path);
sprintf(path, "%s/%s", SLOTS_DIR, filename);
if (is_dir(path)) {
if (!gstate.active_tasks.is_slot_dir_in_use(path)) {
clean_out_dir(path);
boinc_rmdir(path);
}
} else {
boinc_delete_file(path);
}
}
dir_close(dirp);

View File

@ -37,7 +37,6 @@ extern void get_slot_dir(int slot, char* path, int len);
extern int make_project_dir(PROJECT&);
extern int remove_project_dir(PROJECT&);
extern int make_slot_dir(int);
extern int rename_slot_dir(int);
extern void delete_old_slot_dirs();
extern void get_account_filename(char* master_url, char* path);
extern bool is_account_file(const char*);

View File

@ -309,10 +309,12 @@ int boinc_truncate(const char* path, double size) {
}
// recursively delete everything in the specified directory
// (but not the directory itself).
// If an error occurs, delete as much as you can.
//
int clean_out_dir(const char* dirpath) {
char filename[256], path[256];
int retval;
int retval, final_retval = 0;
DIRREF dirp;
dirp = dir_open(dirpath);
@ -329,16 +331,18 @@ int clean_out_dir(const char* dirpath) {
retval = dir_scan(filename, dirp, sizeof(filename));
if (retval) break;
sprintf(path, "%s/%s", dirpath, filename);
clean_out_dir(path);
boinc_rmdir(path);
retval = boinc_delete_file(path);
if (retval) {
dir_close(dirp);
return retval;
if (is_dir(path)) {
retval = clean_out_dir(path);
if (retval) final_retval = retval;
retval = boinc_rmdir(path);
if (retval) final_retval = retval;
} else {
retval = boinc_delete_file(path);
if (retval) final_retval = retval;
}
}
dir_close(dirp);
return 0;
return final_retval;
}
// return total size of files in directory and its subdirectories
@ -622,7 +626,7 @@ void boinc_getcwd(char* path) {
#if defined(_WIN32) && !defined(__CYGWIN32__)
_getcwd(path, 256);
#else
getcwd(path, 256);
char* p = getcwd(path, 256);
#endif
}
@ -630,7 +634,7 @@ void relative_to_absolute(const char* relname, char* path) {
#if defined(_WIN32) && !defined(__CYGWIN32__)
_getcwd(path, 256);
#else
getcwd(path, 256);
char* p = getcwd(path, 256);
#endif
if (strlen(relname)) {
strcat(path, "/");