Changeset 6efec7e3 in mainline


Ignore:
Timestamp:
2019-08-03T07:38:34Z (5 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
59ba708
Parents:
4fe7fcb
git-author:
Michal Koutný <xm.koutny+hos@…> (2015-03-17 19:54:13)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2019-08-03 07:38:34)
Message:

Unit polymorphism (simple mount), debug logging

Location:
uspace/srv/sysman
Files:
6 added
7 edited
2 moved

Legend:

Unmodified
Added
Removed
  • uspace/srv/sysman/Makefile

    r4fe7fcb r6efec7e3  
    2929
    3030USPACE_PREFIX = ../..
     31EXTRA_CFLAGS = -I. -I./units
    3132BINARY = sysman
    3233STATIC_NEEDED = y
     
    3839        main.c \
    3940        sysman.c \
    40         unit.c
     41        unit.c \
     42        units/unit_cfg.c \
     43        units/unit_mnt.c  \
     44        units/unit_tgt.c
    4145
    4246include $(USPACE_PREFIX)/Makefile.common
  • uspace/srv/sysman/configuration.c

    r4fe7fcb r6efec7e3  
    55
    66#include "configuration.h"
     7#include "log.h"
    78
    89static list_t units;
     
    1718int configuration_add_unit(unit_t *unit)
    1819{
     20        sysman_log(LVL_DEBUG2, "%s(%p)", __func__, unit);
    1921        assert(unit);
    2022        assert(unit->state == STATE_EMBRYO);
     
    3133int configuration_commit(void)
    3234{
     35        sysman_log(LVL_DEBUG2, "%s", __func__);
     36
    3337        fibril_mutex_lock(&units_mtx);
    3438        list_foreach(units, units, unit_t, u) {
  • uspace/srv/sysman/job.c

    r4fe7fcb r6efec7e3  
    88
    99#include "job.h"
     10#include "log.h"
    1011#include "unit.h"
    1112
     
    1920static int job_run_start(job_t *job)
    2021{
     22        sysman_log(LVL_DEBUG, "%s(%p)", __func__, job);
    2123        unit_t *unit = job->unit;
    2224
  • uspace/srv/sysman/job.h

    r4fe7fcb r6efec7e3  
    2525} job_link_t;
    2626
     27/** Job represents pending or running operation on unit */
    2728struct job {
    2829        /** Link to queue job is in */
  • uspace/srv/sysman/main.c

    r4fe7fcb r6efec7e3  
    44#include <stddef.h>
    55#include <stdio.h>
     6#include <str.h>
    67
    78#include "configuration.h"
     
    2122        /*
    2223         * Build hard coded configuration.
     24         *
     25         * Strings are allocated on heap, so that they can be free'd by an
     26         * owning unit.
    2327         */
    2428        int result = EOK;
     
    3337        }
    3438        // TODO Use RDFMT
    35         mnt_initrd->data.mnt.type       = "ext4fs";
    36         mnt_initrd->data.mnt.mountpoint = "/";
    37         mnt_initrd->data.mnt.device     = "bd/initrd";
     39        mnt_initrd->data.mnt.type       = str_dup("ext4fs");
     40        mnt_initrd->data.mnt.mountpoint = str_dup("/");
     41        mnt_initrd->data.mnt.device     = str_dup("bd/initrd");
    3842
    3943        cfg_init = unit_create(UNIT_CONFIGURATION);
     
    4246                goto fail;
    4347        }
    44         cfg_init->data.cfg.path = "/cfg/";
     48        cfg_init->data.cfg.path = str_dup("/cfg/");
    4549       
    4650        tgt_default = unit_create(UNIT_TARGET);
  • uspace/srv/sysman/unit.c

    r4fe7fcb r6efec7e3  
    66#include <stdlib.h>
    77
     8#include "log.h"
    89#include "unit.h"
     10
     11/** Virtual method table for each unit type */
     12static unit_ops_t *unit_type_vmts[] = {
     13        [UNIT_TARGET]        = &unit_tgt_ops,
     14        [UNIT_MOUNT]         = &unit_mnt_ops,
     15        [UNIT_CONFIGURATION] = &unit_cfg_ops
     16};
    917
    1018static void unit_init(unit_t *unit, unit_type_t type)
     
    1220        assert(unit);
    1321
     22        memset(unit, 0, sizeof(unit_t));
    1423        link_initialize(&unit->units);
    1524       
     
    2130        list_initialize(&unit->dependants);
    2231        list_initialize(&unit->dependencies);
     32
     33        unit_type_vmts[unit->type]->init(unit);
    2334}
    2435
     
    3344
    3445/** Release resources used by unit structure */
    35 void unit_destroy(unit_t **unit)
     46void unit_destroy(unit_t **unit_ptr)
    3647{
    37         if (*unit == NULL)
     48        unit_t *unit = *unit_ptr;
     49        if (unit == NULL)
    3850                return;
     51
     52        unit_type_vmts[unit->type]->destroy(unit);
    3953        /* TODO:
    4054         *      edges,
    41          *      specific unit data,
    4255         *      check it's not an active unit,
    4356         *      other resources to come
    4457         */
    45         free(*unit);
    46         *unit = NULL;
     58        free(unit);
     59        unit_ptr = NULL;
     60}
     61
     62void unit_set_state(unit_t *unit, unit_state_t state)
     63{
     64        fibril_mutex_lock(&unit->state_mtx);
     65        unit->state = state;
     66        fibril_condvar_broadcast(&unit->state_cv);
     67        fibril_mutex_unlock(&unit->state_mtx);
    4768}
    4869
     
    5475int unit_start(unit_t *unit)
    5576{
    56         // TODO actually start the unit
    57         printf("Starting unit of type %i\n", unit->type);
    58         return EOK;
     77        sysman_log(LVL_DEBUG, "%s(%p)", __func__, unit);
     78        return unit_type_vmts[unit->type]->start(unit);
    5979}
  • uspace/srv/sysman/unit.h

    r4fe7fcb r6efec7e3  
    77#include "unit_mnt.h"
    88#include "unit_cfg.h"
     9#include "unit_tgt.h"
     10#include "unit_types.h"
    911
    10 typedef enum {
    11         UNIT_TARGET = 0,
    12         UNIT_MOUNT,
    13         UNIT_CONFIGURATION
    14 } unit_type_t;
    15 
    16 typedef enum {
    17         STATE_EMBRYO = 0,
    18         STATE_STARTED,
    19         STATE_STOPPED
    20 } unit_state_t;
    21 
    22 typedef struct {
     12struct unit {
    2313        link_t units;
    2414
     
    3626                unit_cfg_t cfg;
    3727        } data;
    38 } unit_t;
     28};
    3929
    4030
     
    4232extern void unit_destroy(unit_t **);
    4333
     34// TODO add flags argument with explicit notification?
     35extern void unit_set_state(unit_t *, unit_state_t);
     36
    4437extern int unit_start(unit_t *);
    4538
  • uspace/srv/sysman/units/unit_cfg.h

    r4fe7fcb r6efec7e3  
    11#ifndef SYSMAN_UNIT_CFG_H
    22#define SYSMAN_UNIT_CFG_H
     3
     4#include "unit_types.h"
    35
    46typedef struct {
     
    68} unit_cfg_t;
    79
     10extern unit_ops_t unit_cfg_ops;
     11
    812#endif
  • uspace/srv/sysman/units/unit_mnt.h

    r4fe7fcb r6efec7e3  
    11#ifndef SYSMAN_UNIT_MNT_H
    22#define SYSMAN_UNIT_MNT_H
     3
     4#include "unit_types.h"
    35
    46typedef struct {
     
    810} unit_mnt_t;
    911
     12extern unit_ops_t unit_mnt_ops;
     13
     14
    1015#endif
    1116
Note: See TracChangeset for help on using the changeset viewer.