/** * Update <key, oldval> with <key, val> */ int zht_update(const char *key, const char *val) { log_msg("cshou debug === zht_update: key = %s, value = %s\n", key, val); return zht_insert(key, val); char res[ZHT_MAX_BUFF] = {0}; int stat = zht_lookup(key, res); if (ZHT_LOOKUP_FAIL == stat) { int insert_res = zht_insert(key, val); if (insert_res) { log_msg("DFZ debug: zht_update() _insert() failed code %d. \n\n", insert_res); return -1; } return 0; } int remove_res = zht_remove(key); log_msg("DFZ debug: zht_update() - remove_res = %d. \n\n", remove_res); int insert_res = zht_insert(key, val); log_msg("DFZ debug: zht_update() - insert_res = %d. \n\n", insert_res); char newval[ZHT_MAX_BUFF] = {0}; int status = zht_lookup(key, newval); log_msg("DFZ debug: zht_update() - status = %d. \n\n", status); if (ZHT_LOOKUP_FAIL == status) log_msg("DFZ debug: zht_update() - key %s not found. \n\n", key); else log_msg("DFZ debug: zht_update() - key = %s, newval = %s. \n\n", key, newval); return 0; }
/** * Update <key, oldval> with <key, val> */ int zht_update(const char *key, const char *val) { // /*DFZ debug*/ // char oldval[PATH_MAX] = {0}; // int status = zht_lookup(key, oldval); // log_msg("DFZ debug: zht_update() - status = %d. \n\n", status); // if (ZHT_LOOKUP_FAIL == status) // log_msg("DFZ debug: zht_update() - key %s not found. \n\n", key); // else // log_msg("DFZ debug: zht_update() - key = %s, oldval = %s. \n\n", key, oldval); /*ZHT supports update semantics now: */ return zht_insert(key, val); char res[ZHT_MAX_BUFF] = {0}; int stat = zht_lookup(key, res); if (ZHT_LOOKUP_FAIL == stat) { int insert_res = zht_insert(key, val); if (insert_res) { log_msg("DFZ debug: zht_update() _insert() failed code %d. \n\n", insert_res); return -1; } return 0; } int remove_res = zht_remove(key); log_msg("DFZ debug: zht_update() - remove_res = %d. \n\n", remove_res); // /*DFZ debug*/ // status = zht_lookup(key, oldval); // if (ZHT_LOOKUP_FAIL == status) // log_msg("DFZ debug: zht_update() - key %s not found. \n\n", key); // else // log_msg("DFZ debug: zht_update() - key = %s, oldval = %s. \n\n", key, oldval); // // log_msg("DFZ debug: zht_update() - key = %s, val = %s. \n\n", key, val); int insert_res = zht_insert(key, val); log_msg("DFZ debug: zht_update() - insert_res = %d. \n\n", insert_res); char newval[ZHT_MAX_BUFF] = {0}; int status = zht_lookup(key, newval); log_msg("DFZ debug: zht_update() - status = %d. \n\n", status); if (ZHT_LOOKUP_FAIL == status) log_msg("DFZ debug: zht_update() - key %s not found. \n\n", key); else log_msg("DFZ debug: zht_update() - key = %s, newval = %s. \n\n", key, newval); return 0; }
/** * Create a directory * * DFZ: updated for ZHT */ int fusion_mkdir(const char *path, mode_t mode) { int retstat = 0; char fpath[PATH_MAX] = {0}; log_msg("\nfusion_mkdir(path=\"%s\", mode=0%3o)\n", path, mode); fusion_fullpath(fpath, path); retstat = mkdir(fpath, mode); if (retstat < 0) retstat = fusion_error("fusion_mkdir mkdir"); /* update ZHT with dir changes */ char parentpath[PATH_MAX] = {0}; char curpath[PATH_MAX] = {0}; char fullpath[PATH_MAX] = {0}; char *pch = strrchr(path, '/'); strncpy(parentpath, path, pch - path + 1); strcpy(curpath, pch + 1); strcat(curpath, "/"); strcpy(fullpath, path); strcat(fullpath, "/"); log_msg("\n==========DFZ debug: fusion_mkdir() parentpath = %s, curpath = %s.\n\n", parentpath, curpath); zht_insert(fullpath, " "); zht_append(parentpath, curpath); return retstat; }
/** * FUSE document: * * Create and open a file * * If the file does not exist, first create it with the specified * mode, and then open it. * * If this method is not implemented or under Linux kernel * versions earlier than 2.6.15, the mknod() and open() methods * will be called instead. * * Introduced in version 2.5 * * ***************************************************************** * DFZ: * In fusionFS, a file creation always happens in the local node */ int fusion_create(const char *path, mode_t mode, struct fuse_file_info *fi) { int retstat = 0; char fpath[PATH_MAX] = {0}; int fd; log_msg("\nfusion_create(path=\"%s\", mode=0%03o, fi=0x%08x)\n", path, mode, fi); fusion_fullpath(fpath, path); /*if <path> exists in ZHT, we should return at this point*/ char res[ZHT_MAX_BUFF] = {0}; int stat = zht_lookup(path, res); if (ZHT_LOOKUP_FAIL == stat) { log_msg("\n================DFZ ERROR: file already exists. \n"); return -1; } /*create the local file*/ fd = creat(fpath, mode); if (fd < 0) retstat = fusion_error("fusion_create creat"); fi->fh = fd; log_fi(fi); /*add the filename to its parent path in the ZHT entry*/ char dirname[PATH_MAX] = {0}; char *pch = strrchr(path, '/'); strncpy(dirname, path, pch - path + 1); log_msg("\n================DFZ debug: dirname = %s \n", dirname); char oldval[ZHT_MAX_BUFF] = {0}; stat = zht_lookup(dirname, oldval); if (ZHT_LOOKUP_FAIL == stat) { log_msg("\n================DFZ ERROR: no parent path exists. \n"); return -1; } log_msg("\n================DFZ debug: oldval = %s. \n", oldval); zht_append(dirname, pch + 1); // log_msg("cshou debug ==== dirname=%s, filename=%s\n", dirname, pch + 1); /*insert <path, ip_addr> into ZHT */ char addr[PATH_MAX] = {0}; net_getmyip(addr); log_msg("\n================DFZ debug _create(): addr = %s. \n", addr); if (zht_insert(path, addr)) log_msg("\n================ERROR _create(): failed to insert <%s, %s> to ZHT. \n", path, addr); char myaddr[PATH_MAX] = {0}; net_getmyip(myaddr); spade_create(myaddr, fpath, fuse_get_context()->pid); return retstat; }
int Worker::update_nodehistory(uint32_t currnode, string alltasks) { int num_vector_count, per_vector_count; vector<vector<string> > tokenize_string = tokenize(alltasks, '\"', '\'', num_vector_count, per_vector_count); uint32_t num_nodes = svrclient.memberList.size(); //cout << "Worker = " << selfIndex << " num_vector_count = " << num_vector_count << " per_vector_count = " << per_vector_count << endl; for (int i = 0; i < num_vector_count; i++) { for (int j = 0; j < per_vector_count; j++) { try { string &taskid = tokenize_string.at(i).at(j); string value = zht_lookup(taskid); Package recv_pkg; recv_pkg.ParseFromString(value); int index = myhash(taskid.c_str(), num_nodes); if (index != selfIndex) { cout << "something wrong..doing remote update_nodehistory index = " << index << " selfIndex = " << selfIndex << endl; } // update number of moves (increment) uint32_t old_nummoves = recv_pkg.nummoves(); recv_pkg.set_nummoves(old_nummoves + 1); // update current location of task recv_pkg.set_currnode(currnode); // update task migration history stringstream nodehistory_ss; nodehistory_ss << currnode << "\'"; string new_nodehistory(nodehistory_ss.str()); new_nodehistory.append(recv_pkg.nodehistory()); //cout << "update_nodehistory: task " << recv_pkg.virtualpath() << " node history = " << recv_pkg.nodehistory(); recv_pkg.set_nodehistory(new_nodehistory); //cout << " node history = " << recv_pkg.nodehistory() << endl; // insert updated task into ZHT int ret = zht_insert(recv_pkg.SerializeAsString()); if (ret != 0) { cout << "update_nodehistory: zht_insert error ret = " << ret << endl; exit(1); } } catch (exception& e) { cout << "update_nodehistory: (tokenize_string.at(i).at(0)) " << " " << e.what() << endl; exit(1); } } } return 0; }
int Worker::update_numwait(string alltasks) { int num_vector_count, per_vector_count; vector<vector<string> > tokenize_string = tokenize(alltasks, '\"', '\'', num_vector_count, per_vector_count); uint32_t num_nodes = svrclient.memberList.size(); for (int i = 0; i < num_vector_count; i++) { for (int j = 0; j < per_vector_count; j++) { try { string &taskid = tokenize_string.at(i).at(j); string value = zht_lookup(taskid); Package recv_pkg; recv_pkg.ParseFromString(value); int index = myhash(taskid.c_str(), num_nodes); if (index != selfIndex) { cout << "something wrong..doing remote update_numwait: index = " << index << " selfIndex = " << selfIndex << endl; } // update number of tasks to wait (decrement) uint32_t old_numwait = recv_pkg.numwait(); recv_pkg.set_numwait(old_numwait - 1); notr++; if (LOGGING) { if (old_numwait - 1 == 0) { log_fp << "task = " << taskid << " is ready" << endl; } } // insert updated task into ZHT int ret = zht_insert(recv_pkg.SerializeAsString()); if (ret != 0) { cout << "update_numwait: old_numwait = " << old_numwait << endl; cout << "update_numwait: zht_insert error ret = " << ret << " key = " << taskid << " index = " << index << " selfindex = " << selfIndex << endl; exit(1); } } catch (exception& e) { cout << "update_numwait: (tokenize_string.at(i).at(0)) " << " " << e.what() << endl; exit(1); } } } log_fp << "notr = " << notr << endl; return 0; }
int Worker::zht_ins_mul(Package &package) { int num_vector_count, per_vector_count; vector<vector<string> > tokenize_string = tokenize(package.realfullpath(), '$', '#', num_vector_count, per_vector_count); //cout << " num_vector_count = " << num_vector_count << " per_vector_count = " << per_vector_count << endl; for (int i = 0; i < per_vector_count; i++) { zht_insert(tokenize_string.at(0).at(i)); } //cout << "Server: " << selfIndex << " no. tasks inserted = " << per_vector_count << endl; TaskQueue_Item *qi; pthread_mutex_lock(&w_lock); for (int i = 0; i < per_vector_count; i++) { Package pkg; pkg.ParseFromString(tokenize_string.at(0).at(i)); qi = new TaskQueue_Item(); qi->task_id = pkg.virtualpath(); (&wqueue)->push_back(qi); } pthread_mutex_unlock(&w_lock); return per_vector_count; }
int main(int argc, char *argv[]) { int i; int fuse_stat; struct fusion_state *fusion_data; // fusionfs doesn't do any access checking on its own (the comment // blocks in fuse.h mention some of the functions that need // accesses checked -- but note there are other functions, like // chown(), that also need checking!). Since running fusionfs as root // will therefore open Metrodome-sized holes in the system // security, we'll check if root is trying to mount the filesystem // and refuse if it is. The somewhat smaller hole of an ordinary // user doing it with the allow_other flag is still there because // I don't want to parse the options string. if ((getuid() == 0) || (geteuid() == 0)) { fprintf(stderr, "Running BBFS as root opens unnacceptable security holes\n"); return 1; } fusion_data = calloc(sizeof(struct fusion_state), 1); if (fusion_data == NULL) { perror("main calloc"); abort(); } fusion_data->logfile = log_open(); // libfuse is able to do most of the command line parsing; all I // need to do is to extract the rootdir; this will be the first // non-option passed in. I'm using the GNU non-standard extension // and having realpath malloc the space for the path // the string. for (i = 1; (i < argc) && (argv[i][0] == '-'); i++) if (argv[i][1] == 'o') i++; // -o takes a parameter; need to // skip it too. This doesn't // handle "squashed" parameters if ((argc - i) != 2) fusion_usage(); fusion_data->rootdir = realpath(argv[i], NULL); argv[i] = argv[i + 1]; argc--; /* * DFZ: test gbuf starts */ printf("\n=====Start testing Google Protocol Buffer=====\n\n"); size_t size = 0, size2 = 0; Package pkg = PACKAGE__INIT; Package *pkg_rtn; /* test data */ pkg.has_replicano = 1; /* This is in need if this int32 is optional */ pkg.replicano = 5; pkg.has_operation = 1; pkg.operation = 3; pkg.virtualpath = "mykey"; pkg.realfullpath = "mypathname"; pkg.has_isdir = true; pkg.isdir = false; /* pack the data */ size = package__get_packed_size(&pkg); unsigned char *packed = malloc(size); size2 = package__pack(&pkg, packed); assert(size == size2); printf("\n=====DFZ debug gbuf: packed = %s. \n\n", packed); /* unpack the data */ pkg_rtn = package__unpack(NULL, size, packed); /* verify the matchings */ printf("dfz debug: pkg_rtn->replicano = %d \n", pkg_rtn->replicano); printf("dfz debug: pkg_rtn->operation = %d \n", pkg_rtn->operation); printf("dfz debug: pkg_rtn->virtualpath = %s \n", pkg_rtn->virtualpath); printf("dfz debug: pkg_rtn->realfullpath = %s \n", pkg_rtn->realfullpath); package__free_unpacked(pkg_rtn, NULL); free(packed); printf("\n=====Finish testing Google Protocol Buffer=====\n\n"); /* * DFZ: test gbuf ends */ /* DFZ: initialize the hash table */ zht_init(); /* initialize new spade */ fprintf(stderr, "init spade...\n"); if (spade_init() < 0) { perror("spade failed"); return -1; } printf("spade done \n"); /*DFZ: add root dir in ZHT*/ zht_insert("/", " "); /*DFZ: test GPU erasure printf("start testing GPU erasure.\n"); gib_context gc; int m = 2, n = 2; int rc = gib_init(m, n, &gc); if (rc) { printf("error in gib_init.\n"); exit (1); } int bs = 1024 * 1024; void *data, *dense_data; gib_alloc(&data, bs, &bs, gc); gib_generate(data, bs, gc); char buff_id[256] = {'1'}; gib_recover(data, bs, buff_id, m, gc); gib_free(data, gc); gib_destroy(gc); printf("GPU erasure successful. \n"); DFZ: end of GPU erasure test*/ fprintf(stderr, "about to call fuse_main\n"); fuse_stat = fuse_main(argc, argv, &fusion_oper, fusion_data); fprintf(stderr, "fuse_main returned %d\n", fuse_stat); /* DFZ: destruct the hash table */ zht_free(); spade_close(); return fuse_stat; }