Changeset 241f1985 in mainline for uspace/srv/taskman


Ignore:
Timestamp:
2019-08-31T10:45:17Z (6 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
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)
Message:

Correcting failure from previous merge

The commits from Michal Koutný from the branch system-daemon
where built on a old version of Helenos. Because of this
many types and API functions have changed. This commit
upgrades the merge code

Location:
uspace/srv/taskman
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/taskman/event.c

    rf92b315 r241f1985  
    4949        task_id_t id;         /**< Task ID who we wait for. */
    5050        task_id_t waiter_id;  /**< Task ID who waits. */
    51         ipc_callid_t callid;  /**< Call ID waiting for the event. */
     51        ipc_call_t *icall;  /**< Call ID waiting for the event. */
    5252        int flags;            /**< Wait flags. */
    5353} pending_wait_t;
     
    5959static FIBRIL_RWLOCK_INITIALIZE(listeners_lock);
    6060
    61 int event_init(void)
     61errno_t event_init(void)
    6262{
    6363        list_initialize(&pending_waits);
     
    150150                int match = notify_flags & pr->flags;
    151151                // 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);
    153153
    154154                if (match == 0) {
     
    156156                                /* Nothing to wait for anymore */
    157157                                if (answer) {
    158                                         async_answer_0(pr->callid, EINTR);
     158                                        async_answer_0(pr->icall, EINTR);
    159159                                }
    160160                        } else {
     
    165165                        if ((pr->flags & TASK_WAIT_BOTH) && match == TASK_WAIT_EXIT) {
    166166                                /* 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);
    168168                        } else {
    169169                                /* Send both exit status and retval, caller
    170170                                 * should know what is valid */
    171                                 async_answer_3(pr->callid, EOK, t->exit,
     171                                async_answer_3(pr->icall, EOK, t->exit,
    172172                                    t->retval, rest);
    173173                        }
     
    195195
    196196void event_register_listener(task_id_t id, bool past_events, async_sess_t *sess,
    197     ipc_callid_t iid)
    198 {
    199         int rc = EOK;
     197    ipc_call_t *icall)
     198{
     199        errno_t rc = EOK;
    200200        /*
    201201         * We have lock of tasks structures so that we can guarantee
     
    219219         * while we dump events.
    220220         */
    221         async_answer_0(iid, rc);
     221        async_answer_0(icall, rc);
    222222        if (past_events) {
    223223                task_foreach(&dump_walker, t->sess);
     
    228228        fibril_rwlock_write_unlock(&task_hash_table_lock);
    229229        if (rc != EOK) {
    230                 async_answer_0(iid, rc);
    231         }
    232 }
    233 
    234 void wait_for_task(task_id_t id, int flags, ipc_callid_t callid,
     230                async_answer_0(icall, rc);
     231        }
     232}
     233
     234void wait_for_task(task_id_t id, int flags, ipc_call_t *icall,
    235235     task_id_t waiter_id)
    236236{
     
    244244        if (t == NULL) {
    245245                /* No such task exists. */
    246                 async_answer_0(callid, ENOENT);
     246                async_answer_0(icall, ENOENT);
    247247                return;
    248248        }
     
    250250        if (t->exit != TASK_EXIT_RUNNING) {
    251251                //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);
    253253                return;
    254254        }
     
    267267        }
    268268
    269         int rc = EOK;
     269        errno_t rc = EOK;
    270270        if (pr == NULL) {
    271271                pr = malloc(sizeof(pending_wait_t));
     
    279279                pr->waiter_id = waiter_id;
    280280                pr->flags = flags;
    281                 pr->callid = callid;
     281                pr->icall = icall;
    282282
    283283                list_append(&pr->link, &pending_waits);
     
    288288                 * fibril).
    289289                 */
    290                 rc = EEXISTS;
     290                rc = EEXIST;
    291291        } else {
    292292                /*
     
    294294                 */
    295295                pr->flags &= ~TASK_WAIT_BOTH; // TODO maybe new flags should be set?
    296                 pr->callid = callid;
     296                pr->icall = icall;
    297297        }
    298298
     
    300300        fibril_rwlock_write_unlock(&pending_wait_lock);
    301301        // 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
     308errno_t task_set_retval(task_id_t sender, int retval, bool wait_for_exit)
     309{
     310        errno_t rc = EOK;
    311311       
    312312        fibril_rwlock_write_lock(&task_hash_table_lock);
  • uspace/srv/taskman/event.h

    rf92b315 r241f1985  
    3939#include <abi/proc/task.h>
    4040
    41 extern int event_init(void);
     41extern errno_t event_init(void);
    4242
    4343extern void event_register_listener(task_id_t, bool, async_sess_t *,
    44     ipc_callid_t);
    45 extern void dump_events(task_id_t, ipc_callid_t);
    46 extern void wait_for_task(task_id_t, int, ipc_callid_t, task_id_t);
    47 extern int task_set_retval(task_id_t, int, bool);
     44    ipc_call_t *);
     45extern void dump_events(task_id_t, ipc_call_t *);
     46extern void wait_for_task(task_id_t, int, ipc_call_t *, task_id_t);
     47extern errno_t task_set_retval(task_id_t, int, bool);
    4848
    4949extern void task_terminated(task_id_t, exit_reason_t);
  • uspace/srv/taskman/main.c

    rf92b315 r241f1985  
    7171 * Static functions
    7272 */
    73 static void connect_to_loader(ipc_callid_t iid, ipc_call_t *icall)
    74 {
    75         DPRINTF("%s:%i from %llu\n", __func__, __LINE__, icall->in_task_id);
     73static void connect_to_loader(ipc_call_t *icall)
     74{
     75        DPRINTF("%s:%i from %llu\n", __func__, __LINE__, icall->task_id);
    7676        /* We don't accept the connection request, we forward it instead to
    7777         * freshly spawned loader. */
    78         int rc = loader_spawn("loader");
    79        
    80         if (rc != EOK) {
    81                 async_answer_0(iid, rc);
     78        errno_t rc = loader_spawn("loader");
     79       
     80        if (rc != EOK) {
     81                async_answer_0(icall, rc);
    8282                return;
    8383        }
     
    8989        /* Forward the connection request (strip interface arg). */
    9090        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);
    9595        async_exchange_end(exch);
    9696
     
    100100
    101101        if (rc != EOK) {
    102                 async_answer_0(iid, rc);
     102                async_answer_0(icall, rc);
    103103                return;
    104104        }
     
    107107}
    108108
    109 static void connect_to_ns(ipc_callid_t iid, ipc_call_t *icall)
    110 {
    111         DPRINTF("%s, %llu\n", __func__, icall->in_task_id);
     109static void connect_to_ns(ipc_call_t *icall)
     110{
     111        DPRINTF("%s, %llu\n", __func__, icall->task_id);
    112112
    113113        /* Wait until we know NS */
     
    120120        /* Do not accept connection, forward it */
    121121        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);
    123123        async_exchange_end(exch);
    124124
    125125        if (rc != EOK) {
    126                 async_answer_0(iid, rc);
    127                 return;
    128         }
    129 }
    130 
    131 static void taskman_new_task(ipc_callid_t iid, ipc_call_t *icall)
    132 {
    133         int rc = task_intro(icall->in_task_id);
    134         async_answer_0(iid, rc);
    135 }
    136 
    137 static void taskman_i_am_ns(ipc_callid_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
     131static 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
     137static void taskman_i_am_ns(ipc_call_t *icall)
     138{
     139        DPRINTF("%s, %llu\n", __func__, icall->task_id);
     140        errno_t rc = EOK;
    141141
    142142        fibril_mutex_lock(&session_ns_mtx);
    143143        if (session_ns != NULL) {
    144                 rc = EEXISTS;
     144                rc = EEXIST;
    145145                goto finish;
    146146        }
     
    157157finish:
    158158        fibril_mutex_unlock(&session_ns_mtx);
    159         async_answer_0(iid, rc);
    160 }
    161 
    162 static void taskman_ctl_wait(ipc_callid_t iid, ipc_call_t *icall)
     159        async_answer_0(icall, rc);
     160}
     161
     162static void taskman_ctl_wait(ipc_call_t *icall)
    163163{
    164164        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, iid, waiter_id);
    170 }
    171 
    172 static void taskman_ctl_retval(ipc_callid_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
     172static 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);
    177177
    178178        DPRINTF("%s:%i from %llu/%i\n", __func__, __LINE__, sender, retval);
    179179
    180         int rc = task_set_retval(sender, retval, wait_for_exit);
    181         async_answer_0(iid, rc);
    182 }
    183 
    184 static void taskman_ctl_ev_callback(ipc_callid_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
     184static 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);
    189189
    190190        /* Atomic -- will be used for notifications only */
    191191        async_sess_t *sess = async_callback_receive(EXCHANGE_ATOMIC);
    192192        if (sess == NULL) {
    193                 async_answer_0(iid, 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_callid_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
     200static 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);
    204204        DPRINTF("%s:%i from %llu/%i\n", __func__, __LINE__, id, exit_reason);
    205205        task_terminated(id, exit_reason);
    206206}
    207207
    208 static void task_fault_event(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    209 {
    210         task_id_t id = MERGE_LOUP32(IPC_GET_ARG1(*icall), IPC_GET_ARG2(*icall));
     208static 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));
    211211        DPRINTF("%s:%i from %llu\n", __func__, __LINE__, id);
    212212        task_failed(id);
    213213}
    214214
    215 static void loader_callback(ipc_callid_t iid, ipc_call_t *icall)
    216 {
    217         DPRINTF("%s:%i from %llu\n", __func__, __LINE__, icall->in_task_id);
     215static void loader_callback(ipc_call_t *icall)
     216{
     217        DPRINTF("%s:%i from %llu\n", __func__, __LINE__, icall->task_id);
    218218        // TODO check that loader is expected, would probably discard prodcons
    219219        //      scheme
     
    222222        sess_ref_t *sess_ref = malloc(sizeof(sess_ref_t));
    223223        if (sess_ref == NULL) {
    224                 async_answer_0(iid, ENOMEM);
     224                async_answer_0(icall, ENOMEM);
    225225        }
    226226
     
    228228        sess_ref->sess = async_callback_receive_start(EXCHANGE_ATOMIC, icall);
    229229        if (sess_ref->sess == NULL) {
    230                 async_answer_0(iid, EINVAL);
    231                 return;
    232         }
    233 
    234         async_answer_0(iid, EOK);
     230                async_answer_0(icall, EINVAL);
     231                return;
     232        }
     233
     234        async_answer_0(icall, EOK);
    235235
    236236        /* Notify spawners */
     
    239239}
    240240
    241 static bool handle_call(ipc_callid_t iid, ipc_call_t *icall)
    242 {
    243         switch (IPC_GET_IMETHOD(*icall)) {
     241static bool handle_call(ipc_call_t *icall)
     242{
     243        switch (ipc_get_imethod(icall)) {
    244244        case TASKMAN_NEW_TASK:
    245                 taskman_new_task(iid, icall);
     245                taskman_new_task(icall);
    246246                break;
    247247        case TASKMAN_I_AM_NS:
    248                 taskman_i_am_ns(iid, icall);
     248                taskman_i_am_ns(icall);
    249249                break;
    250250        case TASKMAN_WAIT:
    251                 taskman_ctl_wait(iid, icall);
     251                taskman_ctl_wait(icall);
    252252                break;
    253253        case TASKMAN_RETVAL:
    254                 taskman_ctl_retval(iid, icall);
     254                taskman_ctl_retval(icall);
    255255                break;
    256256        case TASKMAN_EVENT_CALLBACK:
    257                 taskman_ctl_ev_callback(iid, icall);
     257                taskman_ctl_ev_callback(icall);
    258258                break;
    259259        default:
     
    263263}
    264264
    265 static bool handle_implicit_call(ipc_callid_t iid, ipc_call_t *icall)
     265static bool handle_implicit_call(ipc_call_t *icall)
    266266{
    267267        /*DPRINTF("%s:%i %i(%i) from %llu\n", __func__, __LINE__,
     
    270270            icall->in_task_id);*/
    271271
    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)) {
    274274                case TASKMAN_CONNECT_TO_NS:
    275                         connect_to_ns(iid, icall);
     275                        connect_to_ns(icall);
    276276                        break;
    277277                case TASKMAN_CONNECT_TO_LOADER:
    278                         connect_to_loader(iid, icall);
     278                        connect_to_loader(icall);
    279279                        break;
    280280                case TASKMAN_LOADER_CALLBACK:
    281                         loader_callback(iid, icall);
     281                        loader_callback(icall);
    282282                        break;
    283283                default:
     
    286286                }
    287287        } else {
    288                 return handle_call(iid, icall);
     288                return handle_call(icall);
    289289        }
    290290
     
    292292}
    293293
    294 static void implicit_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    295 {
    296         if (!handle_implicit_call(iid, icall)) {
    297                 async_answer_0(iid, ENOTSUP);
     294static void implicit_connection(ipc_call_t *icall, void *arg)
     295{
     296        if (!handle_implicit_call(icall)) {
     297                async_answer_0(icall, ENOTSUP);
    298298                return;
    299299        }
     
    301301        while (true) {
    302302                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)) {
    306305                        /* Client disconnected */
    307306                        break;
    308307                }
    309308
    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);
    312311                        break;
    313312                }
     
    315314}
    316315
    317 static void taskman_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
     316static void taskman_connection(ipc_call_t *icall, void *arg)
    318317{
    319318        /*
     
    324323         * "listening" on such connections.
    325324         */
    326         if (!handle_implicit_call(iid, icall)) {
    327                 /* If cannot handle connection requst, give up trying */
    328                 async_answer_0(iid, EHANGUP);
     325        if (!handle_implicit_call(icall)) {
     326                /* If cannot handle connection request, give up trying */
     327                async_answer_0(icall, EHANGUP);
    329328                return;
    330329        }
     
    339338        /* Initialization */
    340339        prodcons_initialize(&sess_queue);
    341         int rc = tasks_init();
     340        errno_t rc = tasks_init();
    342341        if (rc != EOK) {
    343342                return rc;
     
    368367        /* Start sysman server */
    369368        async_set_implicit_connection(implicit_connection);
    370         async_set_client_connection(taskman_connection);
     369        async_set_fallback_port_handler(taskman_connection, NULL);
    371370
    372371        printf(NAME ": Accepting connections\n");
  • uspace/srv/taskman/task.c

    rf92b315 r241f1985  
    5757 */
    5858
    59 static size_t ht_task_key_hash(void *key)
     59static size_t ht_task_key_hash(const void *key)
    6060{
    6161        return *(task_id_t*)key;
     
    6868}
    6969
    70 static bool ht_task_key_equal(void *key, const ht_link_t *item)
     70static bool ht_task_key_equal(const void *key, const ht_link_t *item)
    7171{
    7272        task_t *ht = hash_table_get_inst(item, task_t, link);
     
    199199        task_t *t = task_get_by_id(id);
    200200        if (t != NULL) {
    201                 rc = EEXISTS;
     201                rc = EEXIST;
    202202                goto finish;
    203203        }
Note: See TracChangeset for help on using the changeset viewer.