int main(int argc, char *argv[]) { int err = 0; int hsize, i, tc; if (argc == 3) { hsize = atoi(argv[1]); tc = atoi(argv[2]); } else { hsize = 1024; tc = 20; } hvfs_info(mds, "DH UNIT TESTing (%d)...\n", hsize); /* init mds unit test */ lib_init(); err = mds_init(10); if (err) { hvfs_err(mds, "mds_init() failed %d\n", err); goto out; } /* insert to DH */ for (i = 0; i < tc; i++) { dh_insert(i); } /* search in DH */ for (i = 0; i < tc; i++) { dh_search(i); } /* remove from DH */ for (i = 0; i < tc; i++) { dh_remove(i); } /* let us insert the GDT DH */ hvfs_info(mds, ">>>>>>>>>>>>\n"); dh_insert(0); hvfs_info(mds, ">>>>>>>>>>>>\n"); bitmap_insert(0, 0); hvfs_info(mds, ">>>>>>>>>>>>\n"); /* re-search in DH */ for (i = 0; i < tc; i++) { dh_search(i); } mds_destroy(); out: return err; }
/* * The server listen's on the given port, when a client connects it * sends a list of all available files in it's working direcroty to * the server, the sever registers the files in it's data structure * later on request it can retrieve the requested file's host thus * letting the client connect to the host to get the requested file. * * The server handles each request with a different thread, when the * thread's work is done it's automatically cleared from memory. */ int main(int argc, char **argv) { int i; client *c; size_t size; int port = PORT; int lSock, cSock; pthread_t cThread; struct sockaddr_in clientAddress; fd_set read_fd_set; assert(pthread_mutex_init(&m, NULL) == 0); assert(pthread_cond_init(&pending_task_condition, NULL) == 0); if (argc == 2) { port = strToInt(argv[1]); if (port == -1) { printf("Server Error: Invalid port number. Switching back to default (%d).\n", PORT); port = PORT; } } lSock = create_socket(port); assert(listen(lSock, TCP_LISTEN_BACKLOG) != -1); FD_ZERO (&active_fd_set); FD_SET (lSock, &active_fd_set); mds_init(); while (1) { read_fd_set = active_fd_set; assert(select(FD_SETSIZE, &read_fd_set, NULL, NULL, NULL) != -1); for (i = 0; i < FD_SETSIZE; i++) { if (FD_ISSET(i, &read_fd_set)) { if (i == lSock) { size = sizeof(clientAddress); assert((cSock = accept(lSock, (struct sockaddr *)&clientAddress, &size)) != -1); assert(pthread_mutex_lock(&m) == 0); FD_SET(cSock, &active_fd_set); id++; c = cl_createItem(id, cSock, &clientAddress, NULL); mds_put_client(c); assert(pthread_mutex_unlock(&m) == 0); assert(pthread_create(&cThread, NULL, client_thread, &id) == 0); sleep(2); send(cSock, SERVER_WELCOME_MESSAGE, BUFSIZE, 0); } else { task_for = i; assert(pthread_cond_broadcast(&pending_task_condition) == 0); } } } } done = 1; assert(pthread_cond_broadcast(&pending_task_condition) == 0); assert(pthread_mutex_unlock(&m) == 0); sleep(2); pthread_mutex_destroy(&m); pthread_cond_destroy(&pending_task_condition); mds_clear(); return 0; }
int main(int argc, char *argv[]) { struct xnet_type_ops ops = { .buf_alloc = __mds_buf_alloc, .buf_free = NULL, .recv_handler = mds_spool_dispatch, .dispatcher = mds_fe_dispatch, }; int err = 0; int self, sport = -1, i, j; int memonly, memlimit, mode, plot_method; char *value; char *ring_ip = NULL; char profiling_fname[256]; hvfs_info(xnet, "MDS Unit Testing...\n"); hvfs_info(xnet, "Mode is 0/1 (no ring/with ring)\n"); if (argc < 2) { hvfs_err(xnet, "Self ID is not provided.\n"); err = EINVAL; return err; } else { self = atoi(argv[1]); hvfs_info(xnet, "Self type+ID is mds:%d.\n", self); if (argc == 4) { ring_ip = argv[2]; sport = atoi(argv[3]); } else if (argc == 3) ring_ip = argv[2]; } value = getenv("memonly"); if (value) { memonly = atoi(value); } else memonly = 1; value = getenv("memlimit"); if (value) { memlimit = atoi(value); } else memlimit = 0; value = getenv("mode"); if (value) { mode = atoi(value); } else mode = 0; value = getenv("fsid"); if (value) { fsid = atoi(value); } else fsid = 0; value = getenv("plot"); if (value) { plot_method = atoi(value); } else plot_method = MDS_PROF_PLOT; st_init(); mds_pre_init(); hmo.prof.xnet = &g_xnet_prof; hmo.conf.itbid_check = 1; hmo.conf.prof_plot = plot_method; hmo.conf.option |= HVFS_MDS_NOSCRUB; hmo.cb_branch_init = mds_cb_branch_init; hmo.cb_branch_destroy = mds_cb_branch_destroy; mds_init(11); /* set the uuid base! */ hmi.uuid_base = (u64)self << 45; for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { xnet_update_ipaddr(HVFS_TYPE(i, j), 1, &ipaddr[i], (short *)(&port[i][j])); } } xnet_update_ipaddr(HVFS_CLIENT(12), 1, &ipaddr[4], (short *)(&port[4][0])); xnet_update_ipaddr(HVFS_MDS(4), 1, &ipaddr[0], (short *)(&port[4][1])); /* prepare the ring address */ if (!ring_ip) { xnet_update_ipaddr(HVFS_RING(0), 1, &ipaddr[3], (short *)(&port[3][0])); if (sport == -1) sport = port[TYPE_MDS][self]; } else { xnet_update_ipaddr(HVFS_RING(0), 1, &ring_ip, (short *)(&port[3][0])); if (sport == -1) sport = port[TYPE_MDS][0]; } /* setup the profiling file */ memset(profiling_fname, 0, sizeof(profiling_fname)); sprintf(profiling_fname, "./CP-BACK-mds.%d", self); hmo.conf.pf_file = fopen(profiling_fname, "w+"); if (!hmo.conf.pf_file) { hvfs_err(xnet, "fopen() profiling file %s faield %d\n", profiling_fname, errno); return EINVAL; } self = HVFS_MDS(self); hmo.xc = xnet_register_type(0, sport, self, &ops); if (IS_ERR(hmo.xc)) { err = PTR_ERR(hmo.xc); return err; } hmo.site_id = self; if (mode == 0) { hmi.gdt_salt = 0; hvfs_info(xnet, "Select GDT salt to %lx\n", hmi.gdt_salt); hmi.root_uuid = 1; hmi.root_salt = 0xdfeadb0; hvfs_info(xnet, "Select root salt to %lx\n", hmi.root_salt); #if 0 ring_add(&hmo.chring[CH_RING_MDS], HVFS_MDS(0)); ring_add(&hmo.chring[CH_RING_MDS], HVFS_MDS(1)); ring_add(&hmo.chring[CH_RING_MDS], HVFS_MDS(2)); ring_add(&hmo.chring[CH_RING_MDS], HVFS_MDS(3)); #else ring_add(&hmo.chring[CH_RING_MDS], HVFS_MDS(4)); #endif ring_add(&hmo.chring[CH_RING_MDSL], HVFS_MDSL(0)); ring_add(&hmo.chring[CH_RING_MDSL], HVFS_MDSL(1)); ring_resort_nolock(hmo.chring[CH_RING_MDS]); ring_resort_nolock(hmo.chring[CH_RING_MDSL]); ring_dump(hmo.chring[CH_RING_MDS]); ring_dump(hmo.chring[CH_RING_MDSL]); /* insert the GDT DH */ dh_insert(hmi.gdt_uuid, hmi.gdt_uuid, hmi.gdt_salt); bitmap_insert(0, 0); } else { hmo.cb_exit = mds_cb_exit; hmo.cb_hb = mds_cb_hb; hmo.cb_ring_update = mds_cb_ring_update; /* use ring info to init the mds */ err = r2cli_do_reg(self, HVFS_RING(0), fsid, 0); if (err) { hvfs_err(xnet, "reg self %x w/ r2 %x failed w/ %d\n", self, HVFS_RING(0), err); goto out; } hvfs_info(xnet, "HMI gdt uuid %ld salt %lx txg %ld\n", hmi.gdt_uuid, hmi.gdt_salt, atomic64_read(&hmi.mi_txg)); } err = mds_verify(); if (err) { hvfs_err(xnet, "Verify MDS configration failed!\n"); goto out; } // SET_TRACING_FLAG(xnet, HVFS_DEBUG); // SET_TRACING_FLAG(mds, HVFS_DEBUG | HVFS_VERBOSE); hvfs_info(xnet, "MDS is UP for serving requests now.\n"); msg_wait(); xnet_unregister_type(hmo.xc); st_destroy(); mds_destroy(); return 0; out: st_destroy(); mds_destroy(); return err; }
int main(int argc, char *argv[]) { struct xnet_msg *msg; struct xnet_type_ops ops = { .buf_alloc = NULL, .buf_free = NULL, .recv_handler = xnet_test_handler, }; int err = 0; int dsite; short port; hvfs_info(xnet, "XNET Simple UNIT TESTing ...\n"); if (argc == 2) { port = 8210; dsite = 0; } else { port = 8412; dsite = 1; } mds_init(10); st_init(); xc = xnet_register_type(0, port, !dsite, &ops); if (IS_ERR(xc)) { err = PTR_ERR(xc); goto out; } xnet_update_ipaddr(0, 1, ipaddr1, port1); xnet_update_ipaddr(1, 1, ipaddr2, port2); /* alloc one msg and send it to the peer site */ msg = xnet_alloc_msg(XNET_MSG_NORMAL); if (!msg) { hvfs_err(xnet, "xnet_alloc_msg() failed\n"); err = -ENOMEM; goto out_unreg; } // SET_TRACING_FLAG(xnet, HVFS_DEBUG); xnet_msg_fill_tx(msg, XNET_MSG_REQ, XNET_NEED_DATA_FREE | XNET_NEED_REPLY, !dsite, dsite); if (dsite) { int i; lib_timer_def(); lib_timer_start(&begin); for (i = 0; i < 100; i++) { xnet_send(xc, msg); } lib_timer_stop(&end); lib_timer_echo_plus(&begin, &end, 10, "Ping-Poing Latency\t"); } else { int i; lib_timer_def(); lib_timer_start(&begin); for (i = 0; i < 100; i++) { xnet_wait_any(xc); } lib_timer_stop(&end); lib_timer_echo_plus(&begin, &end, 10, "Handle Latency\t"); } out_unreg: xnet_unregister_type(xc); out: st_destroy(); mds_destroy(); return err; }