Changeset a35b458 in mainline for uspace/srv/ns
- Timestamp:
- 2018-03-02T20:10:49Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- Location:
- uspace/srv/ns
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/ns/clonable.c
r3061bc1 ra35b458 84 84 return; 85 85 } 86 86 87 87 cs_req_t *csr = list_get_instance(req_link, cs_req_t, link); 88 88 list_remove(req_link); 89 89 90 90 /* Currently we can only handle a single type of clonable service. */ 91 91 assert(csr->service == SERVICE_LOADER); 92 92 93 93 async_answer_0(callid, EOK); 94 94 95 95 async_sess_t *sess = async_callback_receive(EXCHANGE_SERIALIZE); 96 96 if (sess == NULL) 97 97 async_answer_0(callid, EIO); 98 98 99 99 async_exch_t *exch = async_exchange_begin(sess); 100 100 async_forward_fast(csr->callid, exch, csr->iface, csr->arg3, 0, 101 101 IPC_FF_NONE); 102 102 async_exchange_end(exch); 103 103 104 104 free(csr); 105 105 async_hangup(sess); … … 120 120 { 121 121 assert(service == SERVICE_LOADER); 122 122 123 123 cs_req_t *csr = malloc(sizeof(cs_req_t)); 124 124 if (csr == NULL) { … … 126 126 return; 127 127 } 128 128 129 129 /* Spawn a loader. */ 130 130 errno_t rc = loader_spawn("loader"); 131 131 132 132 if (rc != EOK) { 133 133 free(csr); … … 135 135 return; 136 136 } 137 137 138 138 link_initialize(&csr->link); 139 139 csr->service = service; … … 141 141 csr->callid = callid; 142 142 csr->arg3 = IPC_GET_ARG3(*call); 143 143 144 144 /* 145 145 * We can forward the call only after the server we spawned connects -
uspace/srv/ns/ns.c
r3061bc1 ra35b458 69 69 return; 70 70 } 71 71 72 72 async_answer_0(iid, EOK); 73 73 74 74 while (true) { 75 75 process_pending_conn(); 76 76 77 77 callid = async_get_call(&call); 78 78 if (!IPC_GET_IMETHOD(call)) 79 79 break; 80 80 81 81 task_id_t id; 82 82 errno_t retval; 83 83 84 84 service_t service; 85 85 sysarg_t phone; 86 86 87 87 switch (IPC_GET_IMETHOD(call)) { 88 88 case NS_REGISTER: 89 89 service = IPC_GET_ARG1(call); 90 90 phone = IPC_GET_ARG5(call); 91 91 92 92 /* 93 93 * Server requests service registration. … … 99 99 retval = register_service(service, phone, &call); 100 100 } 101 101 102 102 break; 103 103 case NS_PING: … … 120 120 break; 121 121 } 122 122 123 123 async_answer_0(callid, retval); 124 124 } … … 130 130 { 131 131 printf("%s: HelenOS IPC Naming Service\n", NAME); 132 132 133 133 errno_t rc = service_init(); 134 134 if (rc != EOK) 135 135 return rc; 136 136 137 137 rc = clonable_init(); 138 138 if (rc != EOK) 139 139 return rc; 140 140 141 141 rc = task_init(); 142 142 if (rc != EOK) 143 143 return rc; 144 144 145 145 async_set_fallback_port_handler(ns_connection, NULL); 146 146 147 147 printf("%s: Accepting connections\n", NAME); 148 148 async_manager(); 149 149 150 150 /* Not reached */ 151 151 return 0; -
uspace/srv/ns/service.c
r3061bc1 ra35b458 43 43 typedef struct { 44 44 ht_link_t link; 45 45 46 46 /** Service ID */ 47 47 service_t service; 48 48 49 49 /** Session to the service */ 50 50 async_sess_t *sess; … … 60 60 hashed_service_t *service = 61 61 hash_table_get_inst(item, hashed_service_t, link); 62 62 63 63 return service->service; 64 64 } … … 68 68 hashed_service_t *service = 69 69 hash_table_get_inst(item, hashed_service_t, link); 70 70 71 71 return service->service == *(service_t *) key; 72 72 } … … 102 102 return ENOMEM; 103 103 } 104 104 105 105 list_initialize(&pending_conn); 106 106 107 107 return EOK; 108 108 } … … 116 116 if (!link) 117 117 continue; 118 118 119 119 hashed_service_t *hashed_service = hash_table_get_inst(link, hashed_service_t, link); 120 120 async_exch_t *exch = async_exchange_begin(hashed_service->sess); … … 122 122 pending->arg3, 0, IPC_FF_NONE); 123 123 async_exchange_end(exch); 124 124 125 125 list_remove(&pending->link); 126 126 free(pending); 127 127 128 128 goto loop; 129 129 } … … 143 143 if (hash_table_find(&service_hash_table, &service)) 144 144 return EEXIST; 145 145 146 146 hashed_service_t *hashed_service = 147 147 (hashed_service_t *) malloc(sizeof(hashed_service_t)); 148 148 if (!hashed_service) 149 149 return ENOMEM; 150 150 151 151 hashed_service->service = service; 152 152 hashed_service->sess = async_callback_receive(EXCHANGE_SERIALIZE); 153 153 if (hashed_service->sess == NULL) 154 154 return EIO; 155 155 156 156 hash_table_insert(&service_hash_table, &hashed_service->link); 157 157 return EOK; … … 174 174 sysarg_t flags = IPC_GET_ARG4(*call); 175 175 errno_t retval; 176 176 177 177 ht_link_t *link = hash_table_find(&service_hash_table, &service); 178 178 if (!link) { … … 185 185 goto out; 186 186 } 187 187 188 188 link_initialize(&pending->link); 189 189 pending->service = service; … … 191 191 pending->callid = callid; 192 192 pending->arg3 = arg3; 193 193 194 194 list_append(&pending->link, &pending_conn); 195 195 return; 196 196 } 197 197 198 198 retval = ENOENT; 199 199 goto out; 200 200 } 201 201 202 202 hashed_service_t *hashed_service = hash_table_get_inst(link, hashed_service_t, link); 203 203 async_exch_t *exch = async_exchange_begin(hashed_service->sess); … … 205 205 async_exchange_end(exch); 206 206 return; 207 207 208 208 out: 209 209 async_answer_0(callid, retval); -
uspace/srv/ns/task.c
r3061bc1 ra35b458 48 48 typedef struct { 49 49 ht_link_t link; 50 50 51 51 task_id_t id; /**< Task ID. */ 52 52 bool finished; /**< Task is done. */ … … 115 115 sysarg_t in_phone_hash = *(sysarg_t*)key; 116 116 p2i_entry_t *entry = hash_table_get_inst(item, p2i_entry_t, link); 117 117 118 118 return (in_phone_hash == entry->in_phone_hash); 119 119 } … … 157 157 return ENOMEM; 158 158 } 159 159 160 160 if (!hash_table_create(&phone_to_id, 0, 0, &p2i_ops)) { 161 161 printf(NAME ": No memory available for tasks\n"); 162 162 return ENOMEM; 163 163 } 164 164 165 165 list_initialize(&pending_wait); 166 166 return EOK; … … 171 171 { 172 172 task_exit_t texit; 173 173 174 174 loop: 175 175 list_foreach(pending_wait, link, pending_wait_t, pr) { … … 177 177 if (!link) 178 178 continue; 179 179 180 180 hashed_task_t *ht = hash_table_get_inst(link, hashed_task_t, link); 181 181 if (!ht->finished) 182 182 continue; 183 183 184 184 texit = ht->have_rval ? TASK_EXIT_NORMAL : 185 185 TASK_EXIT_UNEXPECTED; 186 186 async_answer_2(pr->callid, EOK, texit, ht->retval); 187 187 188 188 list_remove(&pr->link); 189 189 free(pr); … … 197 197 hashed_task_t *ht = (link != NULL) ? 198 198 hash_table_get_inst(link, hashed_task_t, link) : NULL; 199 199 200 200 if (ht == NULL) { 201 201 /* No such task exists. */ … … 203 203 return; 204 204 } 205 205 206 206 if (ht->finished) { 207 207 task_exit_t texit = ht->have_rval ? TASK_EXIT_NORMAL : … … 210 210 return; 211 211 } 212 212 213 213 /* Add to pending list */ 214 214 pending_wait_t *pr = … … 218 218 return; 219 219 } 220 220 221 221 link_initialize(&pr->link); 222 222 pr->id = id; … … 228 228 { 229 229 task_id_t id = MERGE_LOUP32(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call)); 230 230 231 231 ht_link_t *link = hash_table_find(&phone_to_id, &call->in_phone_hash); 232 232 if (link != NULL) 233 233 return EEXIST; 234 234 235 235 p2i_entry_t *entry = (p2i_entry_t *) malloc(sizeof(p2i_entry_t)); 236 236 if (entry == NULL) 237 237 return ENOMEM; 238 238 239 239 hashed_task_t *ht = (hashed_task_t *) malloc(sizeof(hashed_task_t)); 240 240 if (ht == NULL) { … … 242 242 return ENOMEM; 243 243 } 244 244 245 245 /* 246 246 * Insert into the phone-to-id map. 247 247 */ 248 248 249 249 entry->in_phone_hash = call->in_phone_hash; 250 250 entry->id = id; 251 251 hash_table_insert(&phone_to_id, &entry->link); 252 252 253 253 /* 254 254 * Insert into the main table. 255 255 */ 256 256 257 257 ht->id = id; 258 258 ht->finished = false; … … 260 260 ht->retval = -1; 261 261 hash_table_insert(&task_hash_table, &ht->link); 262 262 263 263 return EOK; 264 264 } … … 269 269 if (link == NULL) 270 270 return ENOENT; 271 271 272 272 p2i_entry_t *entry = hash_table_get_inst(link, p2i_entry_t, link); 273 273 *id = entry->id; 274 274 275 275 return EOK; 276 276 } … … 279 279 { 280 280 task_id_t id = call->in_task_id; 281 281 282 282 ht_link_t *link = hash_table_find(&task_hash_table, &id); 283 283 hashed_task_t *ht = (link != NULL) ? 284 284 hash_table_get_inst(link, hashed_task_t, link) : NULL; 285 285 286 286 if ((ht == NULL) || (ht->finished)) 287 287 return EINVAL; 288 288 289 289 ht->finished = true; 290 290 ht->have_rval = true; 291 291 ht->retval = IPC_GET_ARG1(*call); 292 292 293 293 process_pending_wait(); 294 294 295 295 return EOK; 296 296 } … … 302 302 if (rc != EOK) 303 303 return rc; 304 304 305 305 /* Delete from phone-to-id map. */ 306 306 hash_table_remove(&phone_to_id, &call->in_phone_hash); 307 307 308 308 /* Mark task as finished. */ 309 309 ht_link_t *link = hash_table_find(&task_hash_table, &id); … … 312 312 313 313 hashed_task_t *ht = hash_table_get_inst(link, hashed_task_t, link); 314 314 315 315 ht->finished = true; 316 316 317 317 process_pending_wait(); 318 318 hash_table_remove(&task_hash_table, &id); 319 319 320 320 return EOK; 321 321 }
Note:
See TracChangeset
for help on using the changeset viewer.
