Changeset 694253c in mainline


Ignore:
Timestamp:
2019-08-03T07:35:41Z (5 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
c0c388d2
Parents:
f42ee6f
git-author:
Michal Koutný <xm.koutny+hos@…> (2015-03-13 02:06:30)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2019-08-03 07:35:41)
Message:

Skeleton for sysman (unit) jobs control

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

Legend:

Unmodified
Added
Removed
  • uspace/srv/sysman/Makefile

    rf42ee6f r694253c  
    3535        configuration.c \
    3636        dep.c \
     37        job.c \
    3738        main.c \
    3839        sysman.c \
  • uspace/srv/sysman/dep.c

    rf42ee6f r694253c  
    1010int dep_add_dependency(unit_t *dependant, unit_t *dependency)
    1111{
    12         unit_dependency_t *edge = malloc(sizeof(unit_t));
     12        unit_dependency_t *edge = malloc(sizeof(unit_dependency_t));
    1313        if (edge == NULL) {
    1414                return ENOMEM;
    1515        }
     16        link_initialize(&edge->dependants);
     17        link_initialize(&edge->dependencies);
     18
    1619        // TODO check existence of the edge
    1720        // TODO locking
    1821        // TODO check types and states of connected units
    19         /* Do not initalize links as they are immediately inserted into list */
    2022        list_append(&edge->dependants, &dependency->dependants);
    2123        list_append(&edge->dependencies, &dependant->dependencies);
  • uspace/srv/sysman/main.c

    rf42ee6f r694253c  
    77#include "configuration.h"
    88#include "dep.h"
     9#include "job.h"
    910#include "sysman.h"
    1011#include "unit.h"
     
    8586
    8687        configuration_init();
     88        job_queue_init();
    8789
    8890        /*
  • uspace/srv/sysman/sysman.c

    rf42ee6f r694253c  
     1#include <adt/list.h>
    12#include <errno.h>
    23
     4#include "dep.h"
     5#include "job.h"
    36#include "sysman.h"
     7
     8static int sysman_create_closure_jobs(unit_t *unit, job_t **entry_job_ptr,
     9    list_t *accumulator, job_type_t type)
     10{
     11        int rc = EOK;
     12        job_t *job = job_create(type);
     13        if (job == NULL) {
     14                rc = ENOMEM;
     15                goto fail;
     16        }
     17
     18        job->unit = unit;
     19        // TODO set blocking jobs
     20
     21        list_foreach(unit->dependencies, dependencies, unit_dependency_t, edge) {
     22                rc = sysman_create_closure_jobs(edge->dependency, NULL,
     23                    accumulator, type);
     24                if (rc != EOK) {
     25                        goto fail;
     26                }
     27        }
     28
     29        list_append(&job->link, accumulator);
     30
     31        if (entry_job_ptr != NULL) {
     32                *entry_job_ptr = job;
     33        }
     34        return EOK;
     35
     36fail:
     37        job_destroy(&job);
     38        return rc;
     39}
    440
    541int sysman_unit_start(unit_t *unit)
    642{
    7         // satisfy dependencies
    8         // start unit (via restarter)
    9         return EOK;
     43        list_t new_jobs;
     44        list_initialize(&new_jobs);
     45
     46        job_t *job = NULL;
     47        int rc = sysman_create_closure_jobs(unit, &job, &new_jobs, JOB_START);
     48        if (rc != EOK) {
     49                return rc;
     50        }
     51
     52        job_queue_jobs(&new_jobs);
     53
     54        return job_wait(job);
    1055}
  • uspace/srv/sysman/unit.c

    rf42ee6f r694253c  
    11#include <assert.h>
     2#include <errno.h>
     3#include <fibril_synch.h>
    24#include <mem.h>
     5#include <stdio.h>
    36#include <stdlib.h>
    47
     
    912        assert(unit);
    1013
    11         memset(unit, 0, sizeof(unit));
     14        link_initialize(&unit->units);
     15       
     16        unit->type = type;
     17        unit->state = STATE_EMBRYO;
     18        fibril_mutex_initialize(&unit->state_mtx);
     19        fibril_condvar_initialize(&unit->state_cv);
    1220
    13         link_initialize(&unit->units);
    1421        list_initialize(&unit->dependants);
    1522        list_initialize(&unit->dependencies);
    16 
    17         unit->type = type;
    18         unit->state = STATE_EMBRYO;
    1923}
    2024
     
    4246        *unit = NULL;
    4347}
     48
     49/** Issue request to restarter to start a unit
     50 *
     51 * Return from this function only means start request was issued.
     52 * If you need to wait for real start of the unit, use waiting on state_cv.
     53 */
     54int unit_start(unit_t *unit)
     55{
     56        // TODO actually start the unit
     57        printf("Starting unit of type %i\n", unit->type);
     58        return EOK;
     59}
  • uspace/srv/sysman/unit.h

    rf42ee6f r694253c  
    33
    44#include <adt/list.h>
     5#include <fibril_synch.h>
    56
    67#include "unit_mnt.h"
     
    1516typedef enum {
    1617        STATE_EMBRYO = 0,
     18        STATE_STARTED,
    1719        STATE_STOPPED
    1820} unit_state_t;
     
    2224
    2325        unit_type_t type;
     26
    2427        unit_state_t state;
     28        fibril_mutex_t state_mtx;
     29        fibril_condvar_t state_cv;
    2530
    2631        list_t dependencies;
     
    3742extern void unit_destroy(unit_t **);
    3843
     44extern int unit_start(unit_t *);
    3945
    4046#endif
Note: See TracChangeset for help on using the changeset viewer.