Ejemplo n.º 1
0
// this host is declared dead; deal with the loss of data
//
int handle_host(DB_HOST& h) {
    DB_VDA_CHUNK_HOST ch;
    char buf[256];
    int retval;

    log_messages.printf(MSG_NORMAL, "processing dead host %d\n", h.id);

    sprintf(buf, "where host_id=%d", h.id);
    while (1) {
        retval = ch.enumerate(buf);
        if (retval == ERR_DB_NOT_FOUND) break;
        if (retval) return retval;
        log_messages.printf(MSG_NORMAL, "   updating file%d\n", ch.vda_file_id);
        DB_VDA_FILE vf;
        retval = vf.lookup_id(ch.vda_file_id);
        if (retval) {
            log_messages.printf(MSG_CRITICAL,
                "   file lookup failed%d\n", ch.vda_file_id
            );
            return retval;
        }
        retval = vf.update_field("need_update=1");
        if (retval) {
            log_messages.printf(MSG_CRITICAL,
                "   file update failed%d\n", ch.vda_file_id
            );
            return retval;
        }
    }
    return 0;
}
Ejemplo n.º 2
0
// if project is using more than its share of disk space,
// remove some chunks and mark vda_files for update
//
static int enforce_quota(CHUNK_LIST& chunks) {
    if (!g_request->host.d_boinc_max) return 0;

    double x = g_request->host.d_boinc_used_project;
    if (config.debug_vda) {
        log_messages.printf(MSG_NORMAL,
            "[vda] share: %f used: %f\n",
            g_request->host.d_boinc_max, x
        );
    }
    CHUNK_LIST::iterator it = chunks.begin();
    while (x > g_request->host.d_boinc_max && it != chunks.end()) {
        DB_VDA_CHUNK_HOST& ch = it->second;
        if (!ch.found) continue;
        FILE_INFO fi;
        strcpy(fi.name, ch.physical_file_name);
        if (config.debug_vda) {
            log_messages.printf(MSG_NORMAL,
                "[vda] deleting: %s\n", ch.physical_file_name
            );
        }
        DB_VDA_FILE vf;
        vf.lookup_id(ch.vda_file_id);
        x -= vf.chunk_size;
        g_reply->file_deletes.push_back(fi);
        it++;
    }
    return 0;
}
Ejemplo n.º 3
0
// process a completed upload:
// if vda_chunk_host found
//      verify md5 of upload
//      move it from upload dir to vda_file dir
//      mark vda_file for update
//      clear transfer_in_progress flag in vda_chunk_host
// else
//      delete from upload dir
//
static int process_completed_upload(char* chunk_name, CHUNK_LIST& chunks) {
    char path[1024], client_filename[1024], dir[1024];
    int retval;

    physical_file_name(g_reply->host.id, chunk_name, client_filename);
    dir_hier_path(
        client_filename, config.upload_dir, config.uldl_dir_fanout, dir, false
    );
    sprintf(path, "%s/%s", dir, client_filename);
    CHUNK_LIST::iterator i2 = chunks.find(string(chunk_name));
    if (i2 == chunks.end()) {
        if (config.debug_vda) {
            log_messages.printf(MSG_NORMAL,
                "[vda] chunk_host not found for %s\n", chunk_name
            );
        }
        boinc_delete_file(path);
    } else {
        char client_md5[64], server_md5[64];
        char chunk_dir[1024];
        DB_VDA_CHUNK_HOST& ch = i2->second;
        DB_VDA_FILE vf;
        double size;

        retval = vf.lookup_id(ch.vda_file_id);
        get_chunk_dir(vf, chunk_name, chunk_dir);
        retval = get_chunk_md5(chunk_dir, server_md5);
        if (retval) return retval;
        retval = md5_file(path, client_md5, size);
        if (retval) return retval;
        if (strcmp(client_md5, server_md5)) {
            if (config.debug_vda) {
                log_messages.printf(MSG_NORMAL,
                    "[vda] MD5 mismatch %s %s\n", client_md5, server_md5
                );
            }
            boinc_delete_file(path);
        } else {
            retval = vf.update_field("need_update=1");
            if (retval) return retval;
            retval = ch.update_field("transfer_in_progress=0");
            if (retval) return retval;
        }
    }
    return 0;
}
Ejemplo n.º 4
0
// issue upload and download commands
//
static int issue_transfer_commands(CHUNK_LIST& chunks) {
    char xml_buf[8192], chunk_name[256], file_name[1024];
    int retval;
    char url[1024], buf[1024];

    CHUNK_LIST::iterator it;
    for (it = chunks.begin(); it != chunks.end(); it++) {
        vector<const char*> urls;
        DB_VDA_CHUNK_HOST& ch = it->second;
        if (!ch.transfer_in_progress) continue;
        if (!ch.transfer_wait) continue;
        DB_VDA_FILE vf;
        retval = vf.lookup_id(ch.vda_file_id);
        if (retval) return retval;
        if (ch.present_on_host) {
            // upload
            //
            sprintf(buf, "upload_%s", ch.physical_file_name);
            if (result_already_on_host(buf)) {
                if (config.debug_vda) {
                    log_messages.printf(MSG_NORMAL,
                        "[vda] upload of %s already in progress\n",
                        ch.physical_file_name
                    );
                }
                continue;
            }
            if (config.debug_vda) {
                log_messages.printf(MSG_NORMAL,
                    "[vda] sending command to upload %s\n",
                    ch.physical_file_name
                );
            }
            urls.push_back(config.upload_url);
            R_RSA_PRIVATE_KEY key;
            retval = get_file_xml(
                ch.physical_file_name,
                urls,
                vf.chunk_size,
                dtime() + VDA_HOST_TIMEOUT,
                false,
                key,
                xml_buf
            );
        } else {
            // download
            //
            sprintf(buf, "download_%s", ch.physical_file_name);
            if (result_already_on_host(buf)) {
                if (config.debug_vda) {
                    log_messages.printf(MSG_NORMAL,
                        "[vda] download of %s already in progress\n",
                        ch.physical_file_name
                    );
                }
                continue;
            }
            char md5[64], chunk_dir[1024];
            int hostid;
            if (config.debug_vda) {
                log_messages.printf(MSG_NORMAL,
                    "[vda] sending command to download %s\n",
                    ch.physical_file_name
                );
            }
            parse_physical_filename(
                ch.physical_file_name,
                hostid,
                chunk_name,
                file_name
            );

            get_chunk_url(vf, chunk_name, url);
            urls.push_back(url);
            get_chunk_dir(vf, chunk_name, chunk_dir);
            retval = get_chunk_md5(chunk_dir, md5);
            if (retval) return retval;
            retval = put_file_xml(
                ch.physical_file_name,
                urls,
                md5,
                vf.chunk_size,
                dtime() + VDA_HOST_TIMEOUT,
                xml_buf
            );
        }
        g_reply->file_transfer_requests.push_back(string(xml_buf));
    }
    return 0;
}
Ejemplo n.º 5
0
// process a completed upload:
// if vda_chunk_host found
//      verify md5 of upload
//      move it from upload dir to vda_file dir
//      mark vda_file for update
//      clear transfer_in_progress flag in vda_chunk_host
// else
//      delete from upload dir
//
static int process_completed_upload(char* phys_filename, CHUNK_LIST& chunks) {
    char path[1024], buf[256];
    char chunk_name[1024], file_name[1024];
    int retval, hostid;

    retval = parse_physical_filename(
        phys_filename, hostid, chunk_name, file_name
    );
    if (retval) {
        log_messages.printf(MSG_NORMAL,
            "[vda] bad upload filename: %s\n", phys_filename
        );
        return retval;
    }
    dir_hier_path(
        phys_filename, config.upload_dir, config.uldl_dir_fanout, path, false
    );

    // if we don't have a DB record for this chunk, delete the file
    // TODO: maybe we should create a DB record instead
    //
    CHUNK_LIST::iterator i2 = chunks.find(string(phys_filename));
    if (i2 == chunks.end()) {
        if (config.debug_vda) {
            log_messages.printf(MSG_NORMAL,
                "[vda] chunk_host not found for %s\n", chunk_name
            );
        }
        boinc_delete_file(path);
        return 0;
    }

    char client_md5[64], server_md5[64];
    char chunk_dir[1024];
    DB_VDA_CHUNK_HOST& ch = i2->second;
    DB_VDA_FILE vf;
    double size;

    retval = vf.lookup_id(ch.vda_file_id);
    get_chunk_dir(vf, chunk_name, chunk_dir);

    // if file already exists on server, delete the upload file
    // Otherwise move the file from upload dir to data dir
    //
    sprintf(buf, "%s/data.vda", chunk_dir);
    if (boinc_file_exists(buf)) {
        boinc_delete_file(path);
    } else {
        retval = get_chunk_md5(chunk_dir, server_md5);
        if (retval) return retval;
        retval = md5_file(path, client_md5, size);
        if (retval) return retval;
        if (strcmp(client_md5, server_md5)) {
            if (config.debug_vda) {
                log_messages.printf(MSG_NORMAL,
                    "[vda] MD5 mismatch %s %s\n", client_md5, server_md5
                );
            }
            boinc_delete_file(path);
        } else {
            char dst_path[1024];
            sprintf(buf, "%s/data.vda", chunk_dir);
            ssize_t n = readlink(buf, dst_path, sizeof(dst_path)-1);
            if (n < 0) {
                log_messages.printf(MSG_CRITICAL,
                    "[vda] readlink() failed\n"
                );
            } else {
                dst_path[n] = 0;
                sprintf(buf, "mv %s %s; chmod g+rw %s", path, dst_path, dst_path);
                retval = system(buf);
                if (retval == -1 || WEXITSTATUS(retval)) {
                    log_messages.printf(MSG_NORMAL,
                        "[vda] command failed: %s\n", buf
                    );
                } else {
                    log_messages.printf(MSG_NORMAL,
                        "[vda] file move succeeded: %s\n", buf
                    );
                }
            }
            retval = vf.update_field("need_update=1");
        }
    }
    sprintf(buf, "host_id=%d and physical_file_name='%s'",
        ch.host_id,
        ch.physical_file_name
    );
    ch.transfer_in_progress = 0;
    retval = ch.update_fields_noid("transfer_in_progress=0", buf);
    if (retval) return retval;
    return 0;
}
Ejemplo n.º 6
0
// issue upload and download commands
//
static int issue_transfer_commands(CHUNK_LIST& chunks) {
    char xml_buf[8192], file_name[1024];
    int retval;
    char url[1024];

    CHUNK_LIST::iterator it;
    for (it = chunks.begin(); it != chunks.end(); it++) {
        vector<const char*> urls;
        DB_VDA_CHUNK_HOST& ch = it->second;
        if (!ch.transfer_in_progress) continue;
        if (!ch.transfer_wait) continue;
        DB_VDA_FILE vf;
        retval = vf.lookup_id(ch.vda_file_id);
        if (retval) return retval;
        if (ch.present_on_host) {
            if (config.debug_vda) {
                log_messages.printf(MSG_NORMAL,
                    "[vda] sending upload command: %s\n", ch.name
                );
            }
            // upload
            //
            sprintf(file_name, "%d_%s__%s", g_reply->host.id, ch.name, vf.name);
            urls.push_back(config.upload_url);
            R_RSA_PRIVATE_KEY key;
            retval = get_file_xml(
                file_name,
                urls,
                ch.size,
                dtime() + VDA_HOST_TIMEOUT,
                false,
                key,
                xml_buf
            );
        } else {
            if (config.debug_vda) {
                log_messages.printf(MSG_NORMAL,
                    "[vda] sending download command: %s\n", ch.name
                );
            }
            // download
            //
            char md5[64], chunk_dir[1024];
            sprintf(file_name, "%s__%s", ch.name, vf.name);
            get_chunk_url(vf, ch.name, url);
            urls.push_back(url);
            get_chunk_dir(vf, ch.name, chunk_dir);
            retval = get_chunk_md5(chunk_dir, md5);
            if (retval) return retval;
            retval = put_file_xml(
                file_name,
                urls,
                md5,
                ch.size,
                dtime() + VDA_HOST_TIMEOUT,
                xml_buf
            );
        }
        g_reply->file_transfer_requests.push_back(string(xml_buf));
    }
    return 0;
}