Changeset 63a3276 in mainline


Ignore:
Timestamp:
2019-08-06T19:20:35Z (5 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
3f05ef7
Parents:
72c8f77
git-author:
Michal Koutný <xm.koutny+hos@…> (2015-06-17 23:02:03)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2019-08-06 19:20:35)
Message:

sysman: Instrumented locsrv for autostart

  • also refactored unit name derivation in other brokers
  • exposee creation is not used in unit's lifecycle (failed assertion)

Conflicts:

uspace/lib/c/generic/loc.c
uspace/srv/devman/driver.c
uspace/srv/devman/drv_conn.c
uspace/srv/hid/compositor/compositor.c
uspace/srv/locsrv/locsrv.c
uspace/srv/vfs/vfs.h
uspace/srv/vfs/vfs_ops.c
uspace/srv/vfs/vfs_register.c

Location:
uspace
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/loc.c

    r72c8f77 r63a3276  
    329329        async_exch_t *exch;
    330330
    331         if (flags & IPC_FLAG_BLOCKING)
     331        if ((flags & IPC_FLAG_BLOCKING) || flags & IPC_FLAG_AUTOSTART)
    332332                exch = loc_exchange_begin_blocking(INTERFACE_LOC_CONSUMER);
    333333        else {
  • uspace/srv/devman/driver.c

    r72c8f77 r63a3276  
    186186
    187187        return drv_cnt;
     188}
     189
     190/** Get name of unit that represents the driver
     191 *
     192 * @param[in]  drv
     193 * @param[out] unit_name_ptr  should be free'd after use, not touched on fail
     194 *
     195 * @return     EOK on success
     196 * @return     ENOMEM
     197 */
     198errno_t driver_unit_name(driver_t *drv, char **unit_name_ptr)
     199{
     200        char *unit_name = NULL;
     201        asprintf(&unit_name, "%s%c%s", drv->name, UNIT_NAME_SEPARATOR,
     202            UNIT_SVC_TYPE_NAME);
     203
     204        if (unit_name == NULL) {
     205                return ENOMEM;
     206        } else {
     207                *unit_name_ptr = unit_name;
     208                return EOK;
     209        }
    188210}
    189211
     
    320342
    321343        char *unit_name = NULL;
    322         asprintf(&unit_name, "%s%c%s", drv->name, UNIT_NAME_SEPARATOR,
    323             UNIT_SVC_TYPE_NAME);
    324         if (unit_name == NULL) {
     344        if (driver_unit_name(drv, &unit_name) != EOK) {
    325345                return false;
    326346        }
     
    333353        int flags = 0;
    334354        rc = sysman_unit_start(unit_name, flags);
     355        free(unit_name);
    335356
    336357        if (rc != EOK) {
     
    338359                    "Request to start driver `%s' failed: %s.",
    339360                    drv->name, str_error(rc));
    340                 free(unit_name);
    341361                return false;
    342362        }
    343363
    344364        drv->state = DRIVER_STARTING;
    345         free(unit_name);
    346365        return true;
    347366}
  • uspace/srv/devman/driver.h

    r72c8f77 r63a3276  
    4242extern bool get_driver_info(const char *, const char *, driver_t *);
    4343extern int lookup_available_drivers(driver_list_t *, const char *);
     44extern int driver_unit_name(driver_t *, char **);
    4445
    4546extern driver_t *find_best_match_driver(driver_list_t *, dev_node_t *);
  • uspace/srv/devman/drv_conn.c

    r72c8f77 r63a3276  
    3636
    3737#include <assert.h>
     38#include <async.h>
     39#include <errno.h>
     40#include <fibril_synch.h>
     41#include <io/log.h>
     42#include <ipc/devman.h>
     43#include <ipc/driver.h>
    3844#include <ipc/services.h>
     45#include <loc.h>
    3946#include <ns.h>
    40 #include <async.h>
     47#include <stdbool.h>
    4148#include <stdio.h>
    42 #include <errno.h>
    43 #include <str_error.h>
    44 #include <stdbool.h>
    45 #include <fibril_synch.h>
    4649#include <stdlib.h>
    4750#include <str.h>
    48 #include <io/log.h>
    49 #include <ipc/devman.h>
    50 #include <loc.h>
     51#include <str_error.h>
     52#include <sysman/broker.h>
    5153
    5254#include "client_conn.h"
     
    6769        driver_t *driver = NULL;
    6870        char *drv_name = NULL;
     71        char *unit_name = NULL;
    6972
    7073        log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_driver_register");
     
    104107        }
    105108
     109        /* Notify sysman about started driver */
     110        rc = driver_unit_name(driver, &unit_name);
     111        if (rc != EOK) {
     112                fibril_mutex_unlock(&driver->driver_mutex);
     113                async_answer_0(callid, rc);
     114                return NULL;
     115        }
     116        sysman_main_exposee_added(unit_name, call->in_task_id);
     117        free(unit_name);
     118       
    106119        switch (driver->state) {
    107120        case DRIVER_NOT_STARTED:
  • uspace/srv/hid/compositor/compositor.c

    r72c8f77 r63a3276  
    22672267        if (!list_empty(&viewport_list))
    22682268                input_activate(input);
    2269 
    22702269ret:
    22712270        fibril_mutex_unlock(&discovery_mtx);
     
    22852284        bg_color = PIXEL(255, 69, 51, 103);
    22862285
    2287         /* Register compositor server. */
    2288         async_set_fallback_port_handler(client_connection, NULL);
    2289 
    2290         errno_t rc = loc_server_register(NAME);
     2286        /* Establish input bidirectional connection. */
     2287        errno_t rc = input_connect(input_svc);
     2288        if (rc != EOK) {
     2289                printf("%s: Failed to connect to input service.\n", NAME);
     2290                return rc;
     2291        }
     2292
     2293        rc = loc_register_cat_change_cb(category_change_cb, NULL);
     2294        if (rc != EOK) {
     2295                printf("%s: Failed to register category change callback\n", NAME);
     2296                input_disconnect();
     2297                return rc;
     2298        }
     2299
     2300        discover_viewports();
     2301
     2302        comp_restrict_pointers();
     2303        comp_damage(0, 0, UINT32_MAX, UINT32_MAX);
     2304
     2305        /* Finally, register compositor server. */
     2306        async_set_fallback_port_handler(client_connection);
     2307       
     2308        rc = loc_server_register(NAME);
    22912309        if (rc != EOK) {
    22922310                printf("%s: Unable to register server (%s)\n", NAME, str_error(rc));
    2293                 return -1;
    2294         }
    2295 
     2311                return rc;
     2312        }
     2313       
    22962314        server_name = name;
    2297 
    2298         char svc[LOC_NAME_MAXLEN + 1];
    2299         snprintf(svc, LOC_NAME_MAXLEN, "%s/%s", NAMESPACE, server_name);
    2300 
    2301         service_id_t service_id;
    2302         rc = loc_service_register(svc, &service_id);
    2303         if (rc != EOK) {
    2304                 printf("%s: Unable to register service %s\n", NAME, svc);
    2305                 return rc;
    2306         }
    2307 
     2315       
    23082316        /* Prepare window registrator (entrypoint for clients). */
    23092317        char winreg[LOC_NAME_MAXLEN + 1];
     
    23112319        if (loc_service_register(winreg, &winreg_id) != EOK) {
    23122320                printf("%s: Unable to register service %s\n", NAME, winreg);
    2313                 return -1;
    2314         }
    2315 
    2316         /* Establish input bidirectional connection. */
    2317         rc = input_connect(input_svc);
    2318         if (rc != EOK) {
    2319                 printf("%s: Failed to connect to input service.\n", NAME);
    23202321                return rc;
    23212322        }
    2322 
    2323         rc = loc_register_cat_change_cb(category_change_cb, NULL);
    2324         if (rc != EOK) {
    2325                 printf("%s: Failed to register category change callback\n", NAME);
    2326                 input_disconnect();
    2327                 return rc;
    2328         }
    2329 
    2330         discover_viewports();
    2331 
    2332         comp_restrict_pointers();
    2333         comp_damage(0, 0, UINT32_MAX, UINT32_MAX);
    23342323
    23352324        return EOK;
  • uspace/srv/locsrv/locsrv.c

    r72c8f77 r63a3276  
    6464} cb_sess_t;
    6565
     66typedef enum {
     67        NAME_TO_START,
     68        NAME_TO_EXPOSE
     69} unit_name_t;
     70
    6671LIST_INITIALIZE(services_list);
    6772LIST_INITIALIZE(namespaces_list);
     
    335340}
    336341
    337 static int loc_service_request_start(const char *ns_name, const char *name)
     342/** Derive unit name from service name according to purpose
     343 *
     344 * All services in 'device' namespace are considered to be drivers and
     345 * devman is thus requested to start. Otherwise name of unit is made
     346 * from fully qualified name of service (namespace separator is changed
     347 * for usage in unit name.
     348 */
     349static int loc_service_unit_name(const char *ns_name, const char *name,
     350    unit_name_t name_type, char **unit_name_ptr)
    338351{
    339352        char *service_name = NULL;
    340 
    341         /*
    342          * All services in 'device' namespace are considered to be drivers and
    343          * devman is thus requested to start. Otherwise name of unit is made
    344          * from fully qualified name of service (namespace separator is changed
    345          * for usage in unit name.
    346          */
    347         if (str_cmp(ns_name, LOC_DEVICE_NAMESPACE) == 0) {
     353        if (name_type == NAME_TO_START &&
     354            str_cmp(ns_name, LOC_DEVICE_NAMESPACE) == 0) {
    348355                asprintf(&service_name, "%s", SERVICE_NAME_DEVMAN);
    349356        } else if (str_cmp(ns_name, "") == 0) {
     
    365372        }
    366373
    367         int rc = sysman_unit_start(unit_name, IPC_FLAG_BLOCKING);
     374        *unit_name_ptr = unit_name;
     375        return EOK;
     376}
     377
     378static int loc_service_request_start(const char *ns_name, const char *name)
     379{
     380        char *unit_name;
     381        int rc = loc_service_unit_name(ns_name, name, NAME_TO_START, &unit_name);
     382        if (rc != EOK) {
     383                return rc;
     384        }
     385
     386        rc = sysman_unit_start(unit_name, IPC_FLAG_BLOCKING);
    368387        free(unit_name);
    369         free(service_name);
    370388        return rc;
    371389}
     
    555573                return;
    556574        }
     575
     576        /* Notify sysman about new exposee */
     577        char *unit_name = NULL;
     578        rc = loc_service_unit_name(namespace->name, service->name,
     579            NAME_TO_EXPOSE, &unit_name);
     580        if (rc != EOK) {
     581                loc_namespace_destroy(namespace);
     582                fibril_mutex_unlock(&services_list_mutex);
     583                free(service->name);
     584                free(service);
     585                free(unit_name);
     586                async_answer_0(iid, rc);
     587                return;
     588        }
     589
     590        if (str_cmp(namespace->name, LOC_DEVICE_NAMESPACE) == 0) {
     591                sysman_exposee_added(unit_name);
     592        } else {
     593                sysman_main_exposee_added(unit_name, icall->in_task_id);
     594        }
     595        free(unit_name);
    557596
    558597        /* Get unique service ID */
     
    837876                }
    838877
    839                 if (flags & IPC_FLAG_BLOCKING) {
     878                if ((flags & IPC_FLAG_BLOCKING) || flags & IPC_FLAG_AUTOSTART) {
    840879                        fibril_condvar_wait(&services_list_cv,
    841880                            &services_list_mutex);
  • uspace/srv/sysman/connection_broker.c

    r72c8f77 r63a3276  
    2929#include <errno.h>
    3030#include <ipc/sysman.h>
     31#include <stdlib.h>
    3132
     33#include "configuration.h"
    3234#include "connection_broker.h"
    3335#include "log.h"
     36#include "sysman.h"
    3437
    3538static void sysman_broker_register(ipc_callid_t iid, ipc_call_t *icall)
     
    5457static void sysman_main_exposee_added(ipc_callid_t iid, ipc_call_t *icall)
    5558{
    56         sysman_log(LVL_DEBUG2, "%s", __func__);
    57         async_answer_0(iid, ENOTSUP);
    58         // TODO implement
     59        char *unit_name = NULL;
     60        sysarg_t retval;
     61
     62        int rc = async_data_write_accept((void **) &unit_name, true,
     63            0, 0, 0, NULL);
     64        if (rc != EOK) {
     65                retval = rc;
     66                goto finish;
     67        }
     68
     69        unit_t *unit = configuration_find_unit_by_name(unit_name);
     70        if (unit == NULL) {
     71                //sysman_log(LVL_NOTE, "Unit '%s' not found.", unit_name);
     72                retval = ENOENT;
     73                goto finish;
     74        }
     75
     76        // TODO propagate caller task ID
     77        sysman_raise_event(&sysman_event_unit_exposee_created, unit);
     78
     79        retval = EOK;
     80
     81finish:
     82        async_answer_0(iid, retval);
     83        free(unit_name);
    5984}
    6085
    6186static void sysman_exposee_added(ipc_callid_t iid, ipc_call_t *icall)
    6287{
    63         sysman_log(LVL_DEBUG2, "%s", __func__);
    64         async_answer_0(iid, ENOTSUP);
    65         // TODO implement
     88        char *exposee = NULL;
     89        sysarg_t retval;
     90
     91        /* Just accept data and further not supported. */
     92        int rc = async_data_write_accept((void **) &exposee, true,
     93            0, 0, 0, NULL);
     94        if (rc != EOK) {
     95                retval = rc;
     96                goto finish;
     97        }
     98
     99        //sysman_log(LVL_DEBUG2, "%s(%s)", __func__, exposee);
     100
     101        retval = ENOTSUP;
     102
     103finish:
     104        async_answer_0(iid, retval);
     105        free(exposee);
    66106}
    67107
  • uspace/srv/sysman/connection_ctl.c

    r72c8f77 r63a3276  
    8484
    8585        if (!(flags & IPC_FLAG_BLOCKING)) {
    86                 retval = sysman_queue_job(unit, STATE_STARTED, NULL, NULL);
     86                retval = sysman_run_job(unit, STATE_STARTED, NULL, NULL);
    8787                goto answer;
    8888        }
     
    9393                goto answer;
    9494        }
    95         retval = sysman_queue_job(unit, STATE_STARTED, &answer_callback,
     95        retval = sysman_run_job(unit, STATE_STARTED, &answer_callback,
    9696            iid_ptr);
    9797        if (retval != EOK) {
  • uspace/srv/sysman/job.c

    r72c8f77 r63a3276  
    487487        }
    488488        if (rc != EOK) {
     489                //TODO here is 'rc' value "lost" (not propagated further)
    489490                sysman_log(LVL_DEBUG, "%s(%p), %s -> %i, error: %i",
    490491                    __func__, job, unit_name(u), job->target_state, rc);
  • uspace/srv/sysman/unit.h

    r72c8f77 r63a3276  
    7373        link_t bfs_link;
    7474
    75         /** Seen tag for BFS traverse, must be reset before each BFS */
    76         bool bfs_tag;
     75        /** Auxiliary job created during BFS traverse, its presence serves also
     76         * as BFS tag */
     77        job_t *bfs_job;
    7778
     79        /** Job assigned to unit in transitional state */
    7880        job_t *job;
    7981
  • uspace/srv/sysman/units/unit_svc.c

    r72c8f77 r63a3276  
    9393        }
    9494
     95        unit->state = STATE_STARTING;
     96
    9597        /*
    9698         * This is temporary workaround, until proper reporting from brokers
    9799         * about exposees will work. We assume the service succesfully starts
    98          * in a moment.
     100         * in a moment. Applies to naming service only.
    99101         */
    100         unit->state = STATE_STARTING;
    101         async_usleep(20000);
    102         unit->state = STATE_STARTED;
     102        // TODO this is even hack in the workaround, exposees doesn't work properly
     103        if (true || str_cmp(unit->name, "devman.svc") == 0 ||
     104            str_cmp(unit->name, "logger.svc") == 0 ||
     105            str_cmp(unit->name, "irc.svc") == 0) {
     106                async_usleep(100000);
     107                unit->state = STATE_STARTED;
     108        }
    103109
    104110        /*
    105111         * Workaround to see log output even after devman starts (and overrides
    106          * kernel's frame buffer. It's here since devman is started as a
    107          * service (however not all services are devman...).
     112         * kernel's frame buffer.
    108113         */
    109         if (console_kcon()) {
    110                 sysman_log(LVL_DEBUG2, "%s: Kconsole grabbed.", __func__);
    111         } else {
    112                 sysman_log(LVL_DEBUG2, "%s: no kconsole.", __func__);
     114        if (str_cmp(unit->name, "devman.svc") == 0) {
     115                async_usleep(100000);
     116                if (console_kcon()) {
     117                        sysman_log(LVL_DEBUG2, "%s: Kconsole grabbed.", __func__);
     118                } else {
     119                        sysman_log(LVL_DEBUG2, "%s: no kconsole.", __func__);
     120                }
    113121        }
    114122
     
    118126static void unit_svc_exposee_created(unit_t *unit)
    119127{
    120         // TODO implement
     128        assert(CAST_SVC(unit));
     129        assert(unit->state == STATE_STOPPED || unit->state == STATE_STARTING || unit->state==STATE_STARTED);
     130
     131        unit->state = STATE_STARTED;
     132        unit_notify_state(unit);
    121133}
    122134
  • uspace/srv/vfs/vfs.h

    r72c8f77 r63a3276  
    176176extern void vfs_exchange_release(async_exch_t *);
    177177
    178 extern fs_handle_t fs_name_to_handle(unsigned int instance, const char *, bool);
     178extern fs_handle_t fs_name_to_handle(const char *, unsigned int instance, bool);
    179179extern vfs_info_t *fs_handle_to_info(fs_handle_t);
    180 extern errno_t vfs_get_fstypes(vfs_fstypes_t *);
     180extern errno_t fs_unit_name(const char *, unsigned int, char **);
    181181
    182182extern errno_t vfs_lookup_internal(vfs_node_t *, char *, int, vfs_lookup_res_t *);
  • uspace/srv/vfs/vfs_ops.c

    r72c8f77 r63a3276  
    136136        fibril_mutex_lock(&fs_list_lock);
    137137        while (true) {
    138                 fs_handle = fs_name_to_handle(instance, fsname, false);
     138                fs_handle = fs_name_to_handle(fsname, instance, false);
    139139                if (!fs_handle) {
    140140                        if ((flags & IPC_FLAG_AUTOSTART)) {
     
    220220        char *unit_name = NULL;
    221221
    222         assert(instance == 0);
    223         /*
    224          * Unit name is made simply by considering service of the same name as
    225          * given FS name.
    226          * TODO instance identifier is not implemented.
    227          */
    228         asprintf(&unit_name, "%s%c%s", fs_name, UNIT_NAME_SEPARATOR,
    229             UNIT_SVC_TYPE_NAME);
    230         if (unit_name == NULL) {
    231                 return ENOMEM;
    232         }
    233 
    234         int rc = sysman_unit_start(unit_name, IPC_FLAG_BLOCKING);
     222        errno_t rc = fs_unit_name(fs_name, instance, &unit_name);
     223        if (rc != EOK) {
     224                return rc;
     225        }
     226
     227        rc = sysman_unit_start(unit_name, IPC_FLAG_BLOCKING);
    235228
    236229        free(unit_name);
     
    246239
    247240        fibril_mutex_lock(&fs_list_lock);
    248         fs_handle = fs_name_to_handle(0, fs_name, false);
     241        fs_handle = fs_name_to_handle(fs_name, 0, false);
    249242        fibril_mutex_unlock(&fs_list_lock);
    250243
  • uspace/srv/vfs/vfs_register.c

    r72c8f77 r63a3276  
    3636 */
    3737
    38 #include <ipc/services.h>
     38#include <adt/list.h>
     39#include <as.h>
     40#include <assert.h>
    3941#include <async.h>
     42#include <atomic.h>
     43#include <ctype.h>
     44#include <errno.h>
    4045#include <fibril.h>
    4146#include <fibril_synch.h>
    42 #include <errno.h>
     47#include <ipc/services.h>
     48#include <stdbool.h>
    4349#include <stdio.h>
    4450#include <stdlib.h>
    4551#include <str.h>
    46 #include <ctype.h>
    47 #include <stdbool.h>
    48 #include <adt/list.h>
    49 #include <as.h>
    50 #include <assert.h>
    51 #include <stdatomic.h>
    52 #include <vfs/vfs.h>
     52#include <sysman/broker.h>
    5353#include "vfs.h"
    5454
     
    149149         * Check for duplicit registrations.
    150150         */
    151         if (fs_name_to_handle(fs_info->vfs_info.instance,
    152             fs_info->vfs_info.name, false)) {
     151        if (fs_name_to_handle(fs_info->vfs_info.name,
     152            fs_info->vfs_info.instance, false)) {
    153153                /*
    154154                 * We already register a fs like this.
     
    161161        }
    162162
     163        /* Notify sysman about started FS server */
     164        char *unit_name = NULL;
     165        rc = fs_unit_name(fs_info->vfs_info.name, fs_info->vfs_info.instance,
     166            &unit_name);
     167        if (rc != EOK) {
     168                dprintf("Unknow unit name for FS server.\n");
     169                fibril_mutex_unlock(&fs_list_lock);
     170                free(fs_info);
     171                async_answer_0(rid, rc);
     172                return;
     173        }
     174        sysman_main_exposee_added(unit_name, request->in_task_id);
     175        free(unit_name);
     176       
    163177        /*
    164178         * Add fs_info to the list of registered FS's.
     
    288302 *
    289303 * @param name File system name.
     304 * @param instance
    290305 * @param lock If true, the function will lock and unlock the
    291306 *             fs_list_lock.
     
    294309 *
    295310 */
    296 fs_handle_t fs_name_to_handle(unsigned int instance, const char *name, bool lock)
     311fs_handle_t fs_name_to_handle(const char *name, unsigned int instance, bool lock)
    297312{
    298313        int handle = 0;
     
    393408}
    394409
     410/** Get name of unit that represents the filesystem server
     411 *
     412 * Unit name is made simply by considering service of the same name as
     413 * given FS name.
     414 * TODO instance identifier is not implemented.
     415 *
     416 * @param[in]  fs_name
     417 * @param[in]  instance
     418 * @param[out] unit_name_ptr  should be free'd after use, not touched on fail
     419 *
     420 * @return     EOK on success
     421 * @return     ENOMEM
     422 */
     423errno_t fs_unit_name(const char *fs_name, unsigned int instance,
     424    char **unit_name_ptr)
     425{
     426        assert(instance == 0);
     427
     428        char *unit_name = NULL;
     429        asprintf(&unit_name, "%s%c%s", fs_name, UNIT_NAME_SEPARATOR,
     430            UNIT_SVC_TYPE_NAME);
     431
     432        if (unit_name == NULL) {
     433                return ENOMEM;
     434        } else {
     435                *unit_name_ptr = unit_name;
     436                return EOK;
     437        }
     438}
     439
    395440/**
    396441 * @}
Note: See TracChangeset for help on using the changeset viewer.