/* Get the internal representation of a connection */ static inline struct intern_connection *net_conn_get_internal(net_connection_t nc) { struct intern_connection *ic; ic = cos_map_lookup(&connections, nc); return ic; }
static inline struct evt *mapping_find(long extern_evt) { struct evt *e = cos_map_lookup(&evt_map, extern_evt); if (NULL == e) return e; assert(e->extern_id == extern_evt); return e; }
struct cos_cbuf_item *mgr_get_client_mem(struct spd_tmem_info *sti) { spdid_t s_spdid; /* struct cb_desc *d; */ struct cos_cbuf_item *cci = NULL, *list; assert(sti); s_spdid = sti->spdid; list = &spd_tmem_info_list[s_spdid].tmem_list; for (cci = FIRST_LIST(list, next, prev) ; cci != list ; cci = FIRST_LIST(cci, next, prev)) { union cbuf_meta cm; cm.c_0.v = cci->entry->c_0.v; if (!CBUF_IN_USE(cm.c.flags)) break; } if (cci == list) goto err; assert(&cci->desc == cos_map_lookup(&cb_ids, cci->desc.cbid)); /* struct cb_mapping *m; */ /* m = FIRST_LIST(&cci->desc.owner, next, prev); */ mgr_remove_client_mem(sti, cci); DOUT("spd: %d Leaving get cli mem:: num_allocated %d num_desired %d\n",s_spdid, sti->num_allocated, sti->num_desired); done: return cci; err: cci = NULL; goto done; }
static int http_read_write(spdid_t spdid, long connection_id, char *reqs, int req_sz, char *resp, int resp_sz) { struct connection *c; c = cos_map_lookup(&conn_map, connection_id); if (NULL == c) return -EINVAL; return connection_process_requests(c, reqs, req_sz, resp, resp_sz); }
int content_read(spdid_t spdid, long connection_id, char *buff, int sz) { struct connection *c; // printc("HTTP read"); c = cos_map_lookup(&conn_map, connection_id); if (NULL == c) return -EINVAL; return connection_get_reply(c, buff, sz); }
int content_write(spdid_t spdid, long connection_id, char *reqs, int sz) { struct connection *c; // printc("HTTP write"); c = cos_map_lookup(&conn_map, connection_id); if (NULL == c) return -EINVAL; if (connection_parse_requests(c, reqs, sz)) return -EINVAL; return sz; }
int content_remove(spdid_t spdid, long conn_id) { struct connection *c = cos_map_lookup(&conn_map, conn_id); if (NULL == c) return 1; cos_map_del(&conn_map, c->conn_id); c->conn_id = -1; http_free_connection(c); /* bookkeeping */ http_conn_cnt++; return 0; }
struct connection *connmgr_accept(int fd) { struct sockaddr_in sai; int new_fd; unsigned int len = sizeof(sai); struct connection *c; long c_id; new_fd = accept(fd, (struct sockaddr *)&sai, &len); if (-1 == new_fd) { perror("accept"); return NULL; } c_id = http_open_connection(new_fd); c = cos_map_lookup(&conn_map, c_id); if (NULL == c) http_close_connection(c_id); return c; }
static struct rec_data_tor * map_rd_lookup(td_t tid) { return (struct rec_data_tor *)cos_map_lookup(&uniq_tids, tid); }
static struct rec_data_lk * rdlk_lookup(int id) { return (struct rec_data_lk *)cos_map_lookup(&uniq_lkids, id); }
// block_cli_if_tracking_map_fn pred 1 start desc_global_false // block_cli_if_tracking_map_fn pred 1 end // block_cli_if_tracking_map_fn 1 start static inline struct desc_track *call_desc_lookup(int id) { return (struct desc_track *)cos_map_lookup(&IDL_service_desc_maps, id); }
void * cbuf_c_retrieve(spdid_t spdid, int cbid, int len) { void *ret = NULL; char *l_addr, *d_addr; struct cb_desc *d; struct cb_mapping *m; TAKE(); d = cos_map_lookup(&cb_ids, cbid); /* sanity and access checks */ if (!d || d->obj_sz < len) goto done; #ifdef PRINCIPAL_CHECKS if (d->principal != cos_get_thd_id()) goto done; #endif /* DOUT("info: thd_id %d obj_size %d addr %p\n", d->principal, d->obj_sz, d->addr); */ m = malloc(sizeof(struct cb_mapping)); if (!m) goto done; /* u64_t start,end; */ /* rdtscll(start); */ INIT_LIST(m, next, prev); d_addr = valloc_alloc(cos_spd_id(), spdid, 1); l_addr = d->addr; //cbuf_item addr, initialized in cos_init() /* l_addr = d->owner.addr; // mapped from owner */ assert(d_addr && l_addr); /* rdtscll(end); */ /* printc("cost of valloc: %lu\n", end-start); */ /* rdtscll(start); */ /* if (!mman_alias_page(cos_spd_id(), (vaddr_t)d->addr, spdid, (vaddr_t)page)) goto err; */ if (unlikely(!mman_alias_page(cos_spd_id(), (vaddr_t)l_addr, spdid, (vaddr_t)d_addr))) { printc("No alias!\n"); goto err; } /* DOUT("<<<MAPPED>>> mgr addr %p client addr %p\n ",l_addr, d_addr); */ /* rdtscll(end); */ /* printc("cost of mman_alias_page: %lu\n", end-start); */ m->cbd = d; m->spd = spdid; m->addr = (vaddr_t)d_addr; //struct cb_mapping *m; ADD_LIST(&d->owner, m, next, prev); ret = (void *)d_addr; done: RELEASE(); return ret; err: valloc_free(cos_spd_id(), spdid, d_addr, 1); free(m); goto done; }
int cbuf_c_create(spdid_t spdid, int size, long cbid) { int ret = -1; void *v; struct spd_tmem_info *sti; struct cos_cbuf_item *cbuf_item; struct cb_desc *d; union cbuf_meta *mc = NULL; /* DOUT("thd: %d spd: %d cbuf_c_create is called here!!\n", cos_get_thd_id(), spdid); */ /* DOUT("passed cbid is %ld\n",cbid); */ TAKE(); sti = get_spd_info(spdid); /* Make sure we have access to the component shared page */ assert(SPD_IS_MANAGED(sti)); assert(cbid >= 0); if (cbid) { // vector should already exist v = cos_map_lookup(&cb_ids, cbid); if (unlikely((spdid_t)(int)v != spdid)) goto err; } else { cbid = cos_map_add(&cb_ids, (void *)(unsigned long)spdid); if ((mc = __spd_cbvect_lookup_range(sti, (cbid))) == NULL){ RELEASE(); return cbid*-1; } } cos_map_del(&cb_ids, cbid); cbuf_item = tmem_grant(sti); assert(cbuf_item); d = &cbuf_item->desc; d->principal = cos_get_thd_id(); d->obj_sz = PAGE_SIZE; d->owner.spd = sti->spdid; d->owner.cbd = d; /* Jiguo: This can be two different cases: 1. A local cached one is returned with a cbid 2. A cbuf item is obtained from the global free list without cbid */ DOUT("d->cbid is %d\n",d->cbid); if (d->cbid == 0) { INIT_LIST(&d->owner, next, prev); // only created when first time cbid = cos_map_add(&cb_ids, d); // we use a new cbuf DOUT("new cbid is %ld\n",cbid); } else { cbid = cbuf_item->desc.cbid; // use a local cached one DOUT("cached cbid is %ld\n",cbid); } DOUT("cbuf_create:::new cbid is %ld\n",cbid); ret = d->cbid = cbid; mc = __spd_cbvect_lookup_range(sti, cbid); assert(mc); cbuf_item->entry = mc; mc->c.ptr = d->owner.addr >> PAGE_ORDER; mc->c.obj_sz = ((unsigned int)PAGE_SIZE) >> CBUF_OBJ_SZ_SHIFT; mc->c_0.th_id = cos_get_thd_id(); mc->c.flags |= CBUFM_IN_USE | CBUFM_TOUCHED; done: RELEASE(); return ret; err: ret = -1; goto done; }