Changeset 241f1985 in mainline for uspace/srv/taskman
- Timestamp:
- 2019-08-31T10:45:17Z (6 years ago)
- Children:
- 102f641
- Parents:
- f92b315
- git-author:
- Matthieu Riolo <matthieu.riolo@…> (2019-08-23 22:04:34)
- git-committer:
- Matthieu Riolo <matthieu.riolo@…> (2019-08-31 10:45:17)
- Location:
- uspace/srv/taskman
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/taskman/event.c
rf92b315 r241f1985 49 49 task_id_t id; /**< Task ID who we wait for. */ 50 50 task_id_t waiter_id; /**< Task ID who waits. */ 51 ipc_call id_t callid; /**< Call ID waiting for the event. */51 ipc_call_t *icall; /**< Call ID waiting for the event. */ 52 52 int flags; /**< Wait flags. */ 53 53 } pending_wait_t; … … 59 59 static FIBRIL_RWLOCK_INITIALIZE(listeners_lock); 60 60 61 int event_init(void)61 errno_t event_init(void) 62 62 { 63 63 list_initialize(&pending_waits); … … 150 150 int match = notify_flags & pr->flags; 151 151 // TODO why do I even accept such calls? 152 bool answer = !(pr-> callid & IPC_CALLID_NOTIFICATION);152 bool answer = !(pr->icall->flags & IPC_CALL_NOTIF); 153 153 154 154 if (match == 0) { … … 156 156 /* Nothing to wait for anymore */ 157 157 if (answer) { 158 async_answer_0(pr-> callid, EINTR);158 async_answer_0(pr->icall, EINTR); 159 159 } 160 160 } else { … … 165 165 if ((pr->flags & TASK_WAIT_BOTH) && match == TASK_WAIT_EXIT) { 166 166 /* No sense to wait for both anymore */ 167 async_answer_1(pr-> callid, EINTR, t->exit);167 async_answer_1(pr->icall, EINTR, t->exit); 168 168 } else { 169 169 /* Send both exit status and retval, caller 170 170 * should know what is valid */ 171 async_answer_3(pr-> callid, EOK, t->exit,171 async_answer_3(pr->icall, EOK, t->exit, 172 172 t->retval, rest); 173 173 } … … 195 195 196 196 void event_register_listener(task_id_t id, bool past_events, async_sess_t *sess, 197 ipc_call id_t iid)198 { 199 int rc = EOK;197 ipc_call_t *icall) 198 { 199 errno_t rc = EOK; 200 200 /* 201 201 * We have lock of tasks structures so that we can guarantee … … 219 219 * while we dump events. 220 220 */ 221 async_answer_0(i id, rc);221 async_answer_0(icall, rc); 222 222 if (past_events) { 223 223 task_foreach(&dump_walker, t->sess); … … 228 228 fibril_rwlock_write_unlock(&task_hash_table_lock); 229 229 if (rc != EOK) { 230 async_answer_0(i id, rc);231 } 232 } 233 234 void wait_for_task(task_id_t id, int flags, ipc_call id_t callid,230 async_answer_0(icall, rc); 231 } 232 } 233 234 void wait_for_task(task_id_t id, int flags, ipc_call_t *icall, 235 235 task_id_t waiter_id) 236 236 { … … 244 244 if (t == NULL) { 245 245 /* No such task exists. */ 246 async_answer_0( callid, ENOENT);246 async_answer_0(icall, ENOENT); 247 247 return; 248 248 } … … 250 250 if (t->exit != TASK_EXIT_RUNNING) { 251 251 //TODO are flags BOTH processed correctly here? 252 async_answer_3( callid, EOK, t->exit, t->retval, 0);252 async_answer_3(icall, EOK, t->exit, t->retval, 0); 253 253 return; 254 254 } … … 267 267 } 268 268 269 int rc = EOK;269 errno_t rc = EOK; 270 270 if (pr == NULL) { 271 271 pr = malloc(sizeof(pending_wait_t)); … … 279 279 pr->waiter_id = waiter_id; 280 280 pr->flags = flags; 281 pr-> callid = callid;281 pr->icall = icall; 282 282 283 283 list_append(&pr->link, &pending_waits); … … 288 288 * fibril). 289 289 */ 290 rc = EEXIST S;290 rc = EEXIST; 291 291 } else { 292 292 /* … … 294 294 */ 295 295 pr->flags &= ~TASK_WAIT_BOTH; // TODO maybe new flags should be set? 296 pr-> callid = callid;296 pr->icall = icall; 297 297 } 298 298 … … 300 300 fibril_rwlock_write_unlock(&pending_wait_lock); 301 301 // TODO why IPC_CALLID_NOTIFICATION? explain! 302 if (rc != EOK && !( callid & IPC_CALLID_NOTIFICATION)) {303 async_answer_0( callid, rc);304 } 305 } 306 307 308 int task_set_retval(task_id_t sender, int retval, bool wait_for_exit)309 { 310 int rc = EOK;302 if (rc != EOK && !(icall->flags & IPC_CALL_NOTIF)) { 303 async_answer_0(icall, rc); 304 } 305 } 306 307 308 errno_t task_set_retval(task_id_t sender, int retval, bool wait_for_exit) 309 { 310 errno_t rc = EOK; 311 311 312 312 fibril_rwlock_write_lock(&task_hash_table_lock); -
uspace/srv/taskman/event.h
rf92b315 r241f1985 39 39 #include <abi/proc/task.h> 40 40 41 extern int event_init(void);41 extern errno_t event_init(void); 42 42 43 43 extern void event_register_listener(task_id_t, bool, async_sess_t *, 44 ipc_call id_t);45 extern void dump_events(task_id_t, ipc_call id_t);46 extern void wait_for_task(task_id_t, int, ipc_call id_t, task_id_t);47 extern int task_set_retval(task_id_t, int, bool);44 ipc_call_t *); 45 extern void dump_events(task_id_t, ipc_call_t *); 46 extern void wait_for_task(task_id_t, int, ipc_call_t *, task_id_t); 47 extern errno_t task_set_retval(task_id_t, int, bool); 48 48 49 49 extern void task_terminated(task_id_t, exit_reason_t); -
uspace/srv/taskman/main.c
rf92b315 r241f1985 71 71 * Static functions 72 72 */ 73 static void connect_to_loader(ipc_call id_t iid, ipc_call_t *icall)74 { 75 DPRINTF("%s:%i from %llu\n", __func__, __LINE__, icall-> in_task_id);73 static void connect_to_loader(ipc_call_t *icall) 74 { 75 DPRINTF("%s:%i from %llu\n", __func__, __LINE__, icall->task_id); 76 76 /* We don't accept the connection request, we forward it instead to 77 77 * freshly spawned loader. */ 78 int rc = loader_spawn("loader");79 80 if (rc != EOK) { 81 async_answer_0(i id, rc);78 errno_t rc = loader_spawn("loader"); 79 80 if (rc != EOK) { 81 async_answer_0(icall, rc); 82 82 return; 83 83 } … … 89 89 /* Forward the connection request (strip interface arg). */ 90 90 async_exch_t *exch = async_exchange_begin(sess_ref->sess); 91 rc = async_forward_ fast(iid, exch,92 IPC_GET_ARG2(*icall),93 IPC_GET_ARG3(*icall),94 0,IPC_FF_NONE);91 rc = async_forward_1(icall, exch, 92 ipc_get_arg2(icall), 93 ipc_get_arg3(icall), 94 IPC_FF_NONE); 95 95 async_exchange_end(exch); 96 96 … … 100 100 101 101 if (rc != EOK) { 102 async_answer_0(i id, rc);102 async_answer_0(icall, rc); 103 103 return; 104 104 } … … 107 107 } 108 108 109 static void connect_to_ns(ipc_call id_t iid, ipc_call_t *icall)110 { 111 DPRINTF("%s, %llu\n", __func__, icall-> in_task_id);109 static void connect_to_ns(ipc_call_t *icall) 110 { 111 DPRINTF("%s, %llu\n", __func__, icall->task_id); 112 112 113 113 /* Wait until we know NS */ … … 120 120 /* Do not accept connection, forward it */ 121 121 async_exch_t *exch = async_exchange_begin(session_ns); 122 int rc = async_forward_fast(iid, exch, 0, 0, 0, IPC_FF_NONE);122 errno_t rc = async_forward_0(icall, exch, 0, IPC_FF_NONE); 123 123 async_exchange_end(exch); 124 124 125 125 if (rc != EOK) { 126 async_answer_0(i id, rc);127 return; 128 } 129 } 130 131 static void taskman_new_task(ipc_call id_t iid, ipc_call_t *icall)132 { 133 int rc = task_intro(icall->in_task_id);134 async_answer_0(i id, rc);135 } 136 137 static void taskman_i_am_ns(ipc_call id_t iid, ipc_call_t *icall)138 { 139 DPRINTF("%s, %llu\n", __func__, icall-> in_task_id);140 int rc = EOK;126 async_answer_0(icall, rc); 127 return; 128 } 129 } 130 131 static void taskman_new_task(ipc_call_t *icall) 132 { 133 errno_t rc = task_intro(icall->task_id); 134 async_answer_0(icall, rc); 135 } 136 137 static void taskman_i_am_ns(ipc_call_t *icall) 138 { 139 DPRINTF("%s, %llu\n", __func__, icall->task_id); 140 errno_t rc = EOK; 141 141 142 142 fibril_mutex_lock(&session_ns_mtx); 143 143 if (session_ns != NULL) { 144 rc = EEXIST S;144 rc = EEXIST; 145 145 goto finish; 146 146 } … … 157 157 finish: 158 158 fibril_mutex_unlock(&session_ns_mtx); 159 async_answer_0(i id, rc);160 } 161 162 static void taskman_ctl_wait(ipc_call id_t iid, ipc_call_t *icall)159 async_answer_0(icall, rc); 160 } 161 162 static void taskman_ctl_wait(ipc_call_t *icall) 163 163 { 164 164 task_id_t id = (task_id_t) 165 MERGE_LOUP32( IPC_GET_ARG1(*icall), IPC_GET_ARG2(*icall));166 int flags = IPC_GET_ARG3(*icall);167 task_id_t waiter_id = icall-> in_task_id;168 169 wait_for_task(id, flags, i id, waiter_id);170 } 171 172 static void taskman_ctl_retval(ipc_call id_t iid, ipc_call_t *icall)173 { 174 task_id_t sender = icall-> in_task_id;175 int retval = IPC_GET_ARG1(*icall);176 bool wait_for_exit = IPC_GET_ARG2(*icall);165 MERGE_LOUP32(ipc_get_arg1(icall), ipc_get_arg2(icall)); 166 int flags = ipc_get_arg3(icall); 167 task_id_t waiter_id = icall->task_id; 168 169 wait_for_task(id, flags, icall, waiter_id); 170 } 171 172 static void taskman_ctl_retval(ipc_call_t *icall) 173 { 174 task_id_t sender = icall->task_id; 175 int retval = ipc_get_arg1(icall); 176 bool wait_for_exit = ipc_get_arg2(icall); 177 177 178 178 DPRINTF("%s:%i from %llu/%i\n", __func__, __LINE__, sender, retval); 179 179 180 int rc = task_set_retval(sender, retval, wait_for_exit);181 async_answer_0(i id, rc);182 } 183 184 static void taskman_ctl_ev_callback(ipc_call id_t iid, ipc_call_t *icall)185 { 186 DPRINTF("%s:%i from %llu\n", __func__, __LINE__, icall-> in_task_id);187 188 bool past_events = IPC_GET_ARG1(*icall);180 errno_t rc = task_set_retval(sender, retval, wait_for_exit); 181 async_answer_0(icall, rc); 182 } 183 184 static void taskman_ctl_ev_callback(ipc_call_t *icall) 185 { 186 DPRINTF("%s:%i from %llu\n", __func__, __LINE__, icall->task_id); 187 188 bool past_events = ipc_get_arg1(icall); 189 189 190 190 /* Atomic -- will be used for notifications only */ 191 191 async_sess_t *sess = async_callback_receive(EXCHANGE_ATOMIC); 192 192 if (sess == NULL) { 193 async_answer_0(i id, ENOMEM);194 return; 195 } 196 197 event_register_listener(icall-> in_task_id, past_events, sess, iid);198 } 199 200 static void task_exit_event(ipc_call id_t iid, ipc_call_t *icall, void *arg)201 { 202 task_id_t id = MERGE_LOUP32( IPC_GET_ARG1(*icall), IPC_GET_ARG2(*icall));203 exit_reason_t exit_reason = IPC_GET_ARG3(*icall);193 async_answer_0(icall, ENOMEM); 194 return; 195 } 196 197 event_register_listener(icall->task_id, past_events, sess, icall); 198 } 199 200 static void task_exit_event(ipc_call_t *icall, void *arg) 201 { 202 task_id_t id = MERGE_LOUP32(ipc_get_arg1(icall), ipc_get_arg2(icall)); 203 exit_reason_t exit_reason = ipc_get_arg3(icall); 204 204 DPRINTF("%s:%i from %llu/%i\n", __func__, __LINE__, id, exit_reason); 205 205 task_terminated(id, exit_reason); 206 206 } 207 207 208 static void task_fault_event(ipc_call id_t iid, ipc_call_t *icall, void *arg)209 { 210 task_id_t id = MERGE_LOUP32( IPC_GET_ARG1(*icall), IPC_GET_ARG2(*icall));208 static void task_fault_event(ipc_call_t *icall, void *arg) 209 { 210 task_id_t id = MERGE_LOUP32(ipc_get_arg1(icall), ipc_get_arg2(icall)); 211 211 DPRINTF("%s:%i from %llu\n", __func__, __LINE__, id); 212 212 task_failed(id); 213 213 } 214 214 215 static void loader_callback(ipc_call id_t iid, ipc_call_t *icall)216 { 217 DPRINTF("%s:%i from %llu\n", __func__, __LINE__, icall-> in_task_id);215 static void loader_callback(ipc_call_t *icall) 216 { 217 DPRINTF("%s:%i from %llu\n", __func__, __LINE__, icall->task_id); 218 218 // TODO check that loader is expected, would probably discard prodcons 219 219 // scheme … … 222 222 sess_ref_t *sess_ref = malloc(sizeof(sess_ref_t)); 223 223 if (sess_ref == NULL) { 224 async_answer_0(i id, ENOMEM);224 async_answer_0(icall, ENOMEM); 225 225 } 226 226 … … 228 228 sess_ref->sess = async_callback_receive_start(EXCHANGE_ATOMIC, icall); 229 229 if (sess_ref->sess == NULL) { 230 async_answer_0(i id, EINVAL);231 return; 232 } 233 234 async_answer_0(i id, EOK);230 async_answer_0(icall, EINVAL); 231 return; 232 } 233 234 async_answer_0(icall, EOK); 235 235 236 236 /* Notify spawners */ … … 239 239 } 240 240 241 static bool handle_call(ipc_call id_t iid, ipc_call_t *icall)242 { 243 switch ( IPC_GET_IMETHOD(*icall)) {241 static bool handle_call(ipc_call_t *icall) 242 { 243 switch (ipc_get_imethod(icall)) { 244 244 case TASKMAN_NEW_TASK: 245 taskman_new_task(i id, icall);245 taskman_new_task(icall); 246 246 break; 247 247 case TASKMAN_I_AM_NS: 248 taskman_i_am_ns(i id, icall);248 taskman_i_am_ns(icall); 249 249 break; 250 250 case TASKMAN_WAIT: 251 taskman_ctl_wait(i id, icall);251 taskman_ctl_wait(icall); 252 252 break; 253 253 case TASKMAN_RETVAL: 254 taskman_ctl_retval(i id, icall);254 taskman_ctl_retval(icall); 255 255 break; 256 256 case TASKMAN_EVENT_CALLBACK: 257 taskman_ctl_ev_callback(i id, icall);257 taskman_ctl_ev_callback(icall); 258 258 break; 259 259 default: … … 263 263 } 264 264 265 static bool handle_implicit_call(ipc_call id_t iid, ipc_call_t *icall)265 static bool handle_implicit_call(ipc_call_t *icall) 266 266 { 267 267 /*DPRINTF("%s:%i %i(%i) from %llu\n", __func__, __LINE__, … … 270 270 icall->in_task_id);*/ 271 271 272 if ( IPC_GET_IMETHOD(*icall) < IPC_FIRST_USER_METHOD) {273 switch ( IPC_GET_ARG1(*icall)) {272 if (ipc_get_imethod(icall) < IPC_FIRST_USER_METHOD) { 273 switch (ipc_get_arg1(icall)) { 274 274 case TASKMAN_CONNECT_TO_NS: 275 connect_to_ns(i id, icall);275 connect_to_ns(icall); 276 276 break; 277 277 case TASKMAN_CONNECT_TO_LOADER: 278 connect_to_loader(i id, icall);278 connect_to_loader(icall); 279 279 break; 280 280 case TASKMAN_LOADER_CALLBACK: 281 loader_callback(i id, icall);281 loader_callback(icall); 282 282 break; 283 283 default: … … 286 286 } 287 287 } else { 288 return handle_call(i id, icall);288 return handle_call(icall); 289 289 } 290 290 … … 292 292 } 293 293 294 static void implicit_connection(ipc_call id_t iid, ipc_call_t *icall, void *arg)295 { 296 if (!handle_implicit_call(i id, icall)) {297 async_answer_0(i id, ENOTSUP);294 static void implicit_connection(ipc_call_t *icall, void *arg) 295 { 296 if (!handle_implicit_call(icall)) { 297 async_answer_0(icall, ENOTSUP); 298 298 return; 299 299 } … … 301 301 while (true) { 302 302 ipc_call_t call; 303 ipc_callid_t callid = async_get_call(&call); 304 305 if (!IPC_GET_IMETHOD(call)) { 303 304 if (!async_get_call(&call) || !ipc_get_imethod(&call)) { 306 305 /* Client disconnected */ 307 306 break; 308 307 } 309 308 310 if (!handle_implicit_call( callid,&call)) {311 async_answer_0( callid, ENOTSUP);309 if (!handle_implicit_call(&call)) { 310 async_answer_0(icall, ENOTSUP); 312 311 break; 313 312 } … … 315 314 } 316 315 317 static void taskman_connection(ipc_call id_t iid, ipc_call_t *icall, void *arg)316 static void taskman_connection(ipc_call_t *icall, void *arg) 318 317 { 319 318 /* … … 324 323 * "listening" on such connections. 325 324 */ 326 if (!handle_implicit_call(i id, icall)) {327 /* If cannot handle connection requ st, give up trying */328 async_answer_0(i id, EHANGUP);325 if (!handle_implicit_call(icall)) { 326 /* If cannot handle connection request, give up trying */ 327 async_answer_0(icall, EHANGUP); 329 328 return; 330 329 } … … 339 338 /* Initialization */ 340 339 prodcons_initialize(&sess_queue); 341 int rc = tasks_init();340 errno_t rc = tasks_init(); 342 341 if (rc != EOK) { 343 342 return rc; … … 368 367 /* Start sysman server */ 369 368 async_set_implicit_connection(implicit_connection); 370 async_set_ client_connection(taskman_connection);369 async_set_fallback_port_handler(taskman_connection, NULL); 371 370 372 371 printf(NAME ": Accepting connections\n"); -
uspace/srv/taskman/task.c
rf92b315 r241f1985 57 57 */ 58 58 59 static size_t ht_task_key_hash( void *key)59 static size_t ht_task_key_hash(const void *key) 60 60 { 61 61 return *(task_id_t*)key; … … 68 68 } 69 69 70 static bool ht_task_key_equal( void *key, const ht_link_t *item)70 static bool ht_task_key_equal(const void *key, const ht_link_t *item) 71 71 { 72 72 task_t *ht = hash_table_get_inst(item, task_t, link); … … 199 199 task_t *t = task_get_by_id(id); 200 200 if (t != NULL) { 201 rc = EEXIST S;201 rc = EEXIST; 202 202 goto finish; 203 203 }
Note:
See TracChangeset
for help on using the changeset viewer.