Changeset 5559712 in mainline for uspace/srv/sysman/units


Ignore:
Timestamp:
2019-08-03T09:28:50Z (6 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
c0e4fc50
Parents:
2dda1d4
git-author:
Michal Koutný <xm.koutny+hos@…> (2015-05-07 11:49:47)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2019-08-03 09:28:50)
Message:

sysman: Naive autostart instrumentation of locsrv

  • Add IPC_FLAG_AUTOSTART flag.
  • libsysman: sysman's broker and control API.
  • Simple implementation of service unit, exposee verification is missing.
  • Simple mapping of exposee to unit name in locsrv.
  • Temporary debug prints in locsrv.

Conflicts:

boot/Makefile.common
boot/arch/amd64/Makefile.inc
uspace/lib/c/include/ipc/services.h
uspace/srv/locsrv/locsrv.c

Location:
uspace/srv/sysman/units
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/sysman/units/unit_cfg.c

    r2dda1d4 r5559712  
    3636#include <stdlib.h>
    3737#include <str.h>
     38#include <sysman/unit.h>
    3839
    3940#include "configuration.h"
     
    6667        text_parse_init(&text_parse);
    6768
    68         const char *last_dot = str_rchr(filename, '.');
    69         if (last_dot == NULL) {
     69        const char *last_sep = str_rchr(filename, UNIT_NAME_SEPARATOR);
     70        if (last_sep == NULL) {
    7071                rc = EINVAL;
    7172                goto finish;
     
    7374
    7475        const char *unit_name = filename;
    75         const char *unit_type_name = last_dot + 1;
     76        const char *unit_type_name = last_sep + 1;
    7677
    7778        unit_type_t unit_type = unit_type_name_to_type(unit_type_name);
     
    195196        unit_cfg_t *u_cfg = CAST_CFG(unit);
    196197        assert(u_cfg);
    197 
    198         u_cfg->path = NULL;
    199 }
    200 
    201 
     198}
    202199
    203200static void unit_cfg_destroy(unit_t *unit)
     
    243240}
    244241
     242static void unit_cfg_exposee_created(unit_t *unit)
     243{
     244        /* Configuration has no exposees. */
     245        assert(false);
     246}
     247
     248static void unit_cfg_fail(unit_t *unit)
     249{
     250        /* Configuration cannot async fail. */
     251        assert(false);
     252}
     253
    245254DEFINE_UNIT_VMT(unit_cfg)
    246255
  • uspace/srv/sysman/units/unit_cfg.h

    r2dda1d4 r5559712  
    3838} unit_cfg_t;
    3939
    40 extern unit_vmt_t unit_cfg_ops;
     40extern unit_vmt_t unit_cfg_vmt;
    4141
    4242#endif
  • uspace/srv/sysman/units/unit_mnt.c

    r2dda1d4 r5559712  
    3232#include <stdlib.h>
    3333#include <vfs/vfs.h>
     34#include <str.h>
    3435
    3536#include "log.h"
     37#include "sysman.h"
    3638#include "unit.h"
    3739
     
    3941
    4042static config_item_t unit_configuration[] = {
    41         {"What",  &config_parse_string, offsetof(unit_mnt_t, device),     NULL},
    42         {"Where", &config_parse_string, offsetof(unit_mnt_t, mountpoint), NULL},
    43         {"Type",  &config_parse_string, offsetof(unit_mnt_t, type),       NULL},
     43        {"What",      &config_parse_string, offsetof(unit_mnt_t, device),     NULL},
     44        {"Where",     &config_parse_string, offsetof(unit_mnt_t, mountpoint), NULL},
     45        {"Type",      &config_parse_string, offsetof(unit_mnt_t, type),       NULL},
     46        {"Autostart", &config_parse_bool,   offsetof(unit_mnt_t, autostart),  "true"},
     47        {"Blocking",  &config_parse_bool,   offsetof(unit_mnt_t, blocking),   "true"},
    4448        CONFIGURATION_ITEM_SENTINEL
    4549};
    4650
     51typedef struct {
     52        char *type;
     53        char *mountpoint;
     54        char *device;
     55        char *options;
     56        unsigned int flags;
     57        unsigned int instance;
     58
     59        unit_t *unit;
     60        bool owner;
     61} mount_data_t;
     62
     63static void mount_data_destroy(mount_data_t **mnt_data_ptr)
     64{
     65        assert(mnt_data_ptr);
     66        if (*mnt_data_ptr == NULL) {
     67                return;
     68        }
     69
     70        mount_data_t *mnt_data = *mnt_data_ptr;
     71        free(mnt_data->type);
     72        free(mnt_data->mountpoint);
     73        free(mnt_data->device);
     74        free(mnt_data->options);
     75
     76        free(mnt_data);
     77        *mnt_data_ptr = NULL;
     78}
     79
     80static bool mount_data_copy(mount_data_t *src, mount_data_t **dst_ptr)
     81{
     82        mount_data_t *dst = malloc(sizeof(mount_data_t));
     83        if (dst == NULL) {
     84                goto fail;
     85        }
     86
     87        dst->type = str_dup(src->type);
     88        if (dst->type == NULL)
     89                goto fail;
     90
     91        dst->mountpoint = str_dup(src->mountpoint);
     92        if (dst->mountpoint == NULL)
     93                goto fail;
     94
     95        dst->device = str_dup(src->device);
     96        if (dst->device == NULL)
     97                goto fail;
     98
     99        dst->options = src->options ? str_dup(src->options) : NULL;
     100        if (src->options != NULL && dst->options == NULL)
     101                goto fail;
     102
     103        dst->flags = src->flags;
     104        dst->instance = src->instance;
     105        dst->unit = src->unit;
     106        dst->owner = true;
     107
     108        *dst_ptr = dst;
     109        return true;
     110
     111fail:
     112        mount_data_destroy(&dst);
     113        return false;
     114}
     115
    47116static void unit_mnt_init(unit_t *unit)
    48117{
    49118        unit_mnt_t *u_mnt = CAST_MNT(unit);
    50119        assert(u_mnt);
    51 
    52         u_mnt->type = NULL;
    53         u_mnt->mountpoint = NULL;
    54         u_mnt->device = NULL;
    55120}
    56121
     
    60125        unit_mnt_t *u_mnt = CAST_MNT(unit);
    61126
    62         sysman_log(LVL_DEBUG2, "%s, %p, %p, %p", __func__,
    63             u_mnt->type, u_mnt->mountpoint, u_mnt->device);
    64127        free(u_mnt->type);
    65128        free(u_mnt->mountpoint);
     
    85148}
    86149
     150static int mount_exec(void *arg)
     151{
     152        mount_data_t *mnt_data = arg;
     153        /*sysman_log(LVL_DEBUG2, "%s(%p, %p, %p, %p, %x, %u)",
     154            __func__,
     155            mnt_data->type, mnt_data->mountpoint, mnt_data->device, mnt_data->options,
     156            mnt_data->flags, mnt_data->instance);*/
     157        int rc = mount(mnt_data->type, mnt_data->mountpoint, mnt_data->device,
     158            mnt_data->options ? mnt_data->options : "",
     159            mnt_data->flags, mnt_data->instance);
     160
     161        if (rc == EOK) {
     162                sysman_log(LVL_DEBUG, "Mount ('%s') mounted",
     163                    unit_name(mnt_data->unit));
     164                /*
     165                 * Emulate future VFS broker fibril that notifies about created
     166                 * exposee.
     167                 * Difference: It'll notify exposee name only, we'll have to
     168                 * match it...
     169                 */
     170                sysman_raise_event(&sysman_event_unit_exposee_created,
     171                    mnt_data->unit);
     172        } else {
     173                sysman_log(LVL_ERROR, "Mount ('%s') failed (%i)",
     174                    unit_name(mnt_data->unit), rc);
     175                /*
     176                 * Think about analogy of this event, probably timeout or sthing
     177                 */
     178                sysman_raise_event(&sysman_event_unit_failed,
     179                    mnt_data->unit);
     180        }
     181
     182        if (mnt_data->owner) {
     183                mount_data_destroy(&mnt_data);
     184        }
     185
     186        return EOK;
     187}
     188
    87189static int unit_mnt_start(unit_t *unit)
    88190{
    89         // TODO replace with non-blocking
    90         const bool blocking = true;
    91191        unit_mnt_t *u_mnt = CAST_MNT(unit);
    92192        assert(u_mnt);
     193        /* autostart implies blocking */
     194        assert(!u_mnt->autostart || u_mnt->blocking);
    93195
    94196       
     
    96198        assert(unit->state == STATE_STOPPED);
    97199
    98 
    99         // TODO use other mount parameters
    100         int rc = mount(u_mnt->type, u_mnt->mountpoint, u_mnt->device, "",
    101             blocking ? IPC_FLAG_BLOCKING : 0, 0);
    102 
    103         if (blocking) {
    104                 if (rc == EOK) {
    105                         sysman_log(LVL_DEBUG, "Mount ('%s') mounted", unit_name(unit));
    106                         unit->state = STATE_STARTED;
    107                 } else {
    108                         sysman_log(LVL_ERROR, "Mount ('%s') failed (%i)",
    109                             unit_name(unit), rc);
    110                         unit->state = STATE_FAILED;
     200        mount_data_t mnt_data;
     201        memset(&mnt_data, 0, sizeof(mnt_data));
     202        mnt_data.type       = u_mnt->type;
     203        mnt_data.mountpoint = u_mnt->mountpoint;
     204        mnt_data.device     = u_mnt->device;
     205        /* TODO use other mount parameters
     206         * mnt_data.options    = u_mnt->options;
     207         * mnt_data.instance   = u_mnt->instance;
     208         */
     209
     210        mnt_data.flags |= u_mnt->blocking ? IPC_FLAG_BLOCKING : 0;
     211        mnt_data.flags |= u_mnt->autostart ? IPC_FLAG_AUTOSTART : 0;
     212        mnt_data.unit = unit;
     213
     214        if (u_mnt->blocking) {
     215                mount_data_t *heap_mnt_data = NULL;
     216                if (!mount_data_copy(&mnt_data, &heap_mnt_data)) {
     217                        return ENOMEM;
    111218                }
     219                fid_t fib = fibril_create(&mount_exec, heap_mnt_data);
     220                unit->state = STATE_STARTING;
     221                fibril_add_ready(fib);
    112222        } else {
    113                 if (rc == EOK) {
    114                         sysman_log(LVL_DEBUG, "Mount ('%s') requested", unit_name(unit));
    115                         unit->state = STATE_STARTING;
    116                 } else {
    117                         sysman_log(LVL_ERROR, "Mount ('%s') request failed (%i)",
    118                             unit_name(unit), rc);
    119                         unit->state = STATE_FAILED;
    120                 }
    121         }
    122 
    123         return rc;
    124 }
     223                unit->state = STATE_STARTING;
     224                mount_exec(&mnt_data);
     225        }
     226
     227        return EOK;
     228}
     229
     230static void unit_mnt_exposee_created(unit_t *unit)
     231{
     232        assert(CAST_MNT(unit));
     233        assert(unit->state == STATE_STOPPED || unit->state == STATE_STARTING);
     234
     235        unit->state = STATE_STARTED;
     236        unit_notify_state(unit);
     237}
     238
     239static void unit_mnt_fail(unit_t *unit)
     240{
     241        assert(CAST_MNT(unit));
     242        assert(unit->state == STATE_STARTING);
     243
     244        unit->state = STATE_FAILED;
     245        unit_notify_state(unit);
     246}
     247
    125248
    126249DEFINE_UNIT_VMT(unit_mnt)
  • uspace/srv/sysman/units/unit_mnt.h

    r2dda1d4 r5559712  
    3838        char *mountpoint;
    3939        char *device;
     40
     41        /** Should be underlying units (FS server, device) be autostarted */
     42        bool autostart;
     43
     44        /** Should mount call be blocking */
     45        bool blocking;
    4046} unit_mnt_t;
    4147
    42 extern unit_vmt_t unit_mnt_ops;
     48extern unit_vmt_t unit_mnt_vmt;
    4349
    4450#endif
  • uspace/srv/sysman/units/unit_tgt.c

    r2dda1d4 r5559712  
    6363}
    6464
     65static void unit_tgt_exposee_created(unit_t *unit)
     66{
     67        /* Target has no exposees. */
     68        assert(false);
     69}
     70
     71static void unit_tgt_fail(unit_t *unit)
     72{
     73        // TODO define semantics and implement
     74}
     75
     76
    6577DEFINE_UNIT_VMT(unit_tgt)
    6678
  • uspace/srv/sysman/units/unit_tgt.h

    r2dda1d4 r5559712  
    3636} unit_tgt_t;
    3737
    38 extern unit_vmt_t unit_tgt_ops;
     38extern unit_vmt_t unit_tgt_vmt;
    3939
    4040#endif
Note: See TracChangeset for help on using the changeset viewer.