Changeset 6efec7e3 in mainline
- Timestamp:
- 2019-08-03T07:38:34Z (5 years ago)
- 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)
- Location:
- uspace/srv/sysman
- Files:
-
- 6 added
- 7 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/sysman/Makefile
r4fe7fcb r6efec7e3 29 29 30 30 USPACE_PREFIX = ../.. 31 EXTRA_CFLAGS = -I. -I./units 31 32 BINARY = sysman 32 33 STATIC_NEEDED = y … … 38 39 main.c \ 39 40 sysman.c \ 40 unit.c 41 unit.c \ 42 units/unit_cfg.c \ 43 units/unit_mnt.c \ 44 units/unit_tgt.c 41 45 42 46 include $(USPACE_PREFIX)/Makefile.common -
uspace/srv/sysman/configuration.c
r4fe7fcb r6efec7e3 5 5 6 6 #include "configuration.h" 7 #include "log.h" 7 8 8 9 static list_t units; … … 17 18 int configuration_add_unit(unit_t *unit) 18 19 { 20 sysman_log(LVL_DEBUG2, "%s(%p)", __func__, unit); 19 21 assert(unit); 20 22 assert(unit->state == STATE_EMBRYO); … … 31 33 int configuration_commit(void) 32 34 { 35 sysman_log(LVL_DEBUG2, "%s", __func__); 36 33 37 fibril_mutex_lock(&units_mtx); 34 38 list_foreach(units, units, unit_t, u) { -
uspace/srv/sysman/job.c
r4fe7fcb r6efec7e3 8 8 9 9 #include "job.h" 10 #include "log.h" 10 11 #include "unit.h" 11 12 … … 19 20 static int job_run_start(job_t *job) 20 21 { 22 sysman_log(LVL_DEBUG, "%s(%p)", __func__, job); 21 23 unit_t *unit = job->unit; 22 24 -
uspace/srv/sysman/job.h
r4fe7fcb r6efec7e3 25 25 } job_link_t; 26 26 27 /** Job represents pending or running operation on unit */ 27 28 struct job { 28 29 /** Link to queue job is in */ -
uspace/srv/sysman/main.c
r4fe7fcb r6efec7e3 4 4 #include <stddef.h> 5 5 #include <stdio.h> 6 #include <str.h> 6 7 7 8 #include "configuration.h" … … 21 22 /* 22 23 * Build hard coded configuration. 24 * 25 * Strings are allocated on heap, so that they can be free'd by an 26 * owning unit. 23 27 */ 24 28 int result = EOK; … … 33 37 } 34 38 // 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"); 38 42 39 43 cfg_init = unit_create(UNIT_CONFIGURATION); … … 42 46 goto fail; 43 47 } 44 cfg_init->data.cfg.path = "/cfg/";48 cfg_init->data.cfg.path = str_dup("/cfg/"); 45 49 46 50 tgt_default = unit_create(UNIT_TARGET); -
uspace/srv/sysman/unit.c
r4fe7fcb r6efec7e3 6 6 #include <stdlib.h> 7 7 8 #include "log.h" 8 9 #include "unit.h" 10 11 /** Virtual method table for each unit type */ 12 static 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 }; 9 17 10 18 static void unit_init(unit_t *unit, unit_type_t type) … … 12 20 assert(unit); 13 21 22 memset(unit, 0, sizeof(unit_t)); 14 23 link_initialize(&unit->units); 15 24 … … 21 30 list_initialize(&unit->dependants); 22 31 list_initialize(&unit->dependencies); 32 33 unit_type_vmts[unit->type]->init(unit); 23 34 } 24 35 … … 33 44 34 45 /** Release resources used by unit structure */ 35 void unit_destroy(unit_t **unit )46 void unit_destroy(unit_t **unit_ptr) 36 47 { 37 if (*unit == NULL) 48 unit_t *unit = *unit_ptr; 49 if (unit == NULL) 38 50 return; 51 52 unit_type_vmts[unit->type]->destroy(unit); 39 53 /* TODO: 40 54 * edges, 41 * specific unit data,42 55 * check it's not an active unit, 43 56 * other resources to come 44 57 */ 45 free(*unit); 46 *unit = NULL; 58 free(unit); 59 unit_ptr = NULL; 60 } 61 62 void 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); 47 68 } 48 69 … … 54 75 int unit_start(unit_t *unit) 55 76 { 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); 59 79 } -
uspace/srv/sysman/unit.h
r4fe7fcb r6efec7e3 7 7 #include "unit_mnt.h" 8 8 #include "unit_cfg.h" 9 #include "unit_tgt.h" 10 #include "unit_types.h" 9 11 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 { 12 struct unit { 23 13 link_t units; 24 14 … … 36 26 unit_cfg_t cfg; 37 27 } data; 38 } unit_t;28 }; 39 29 40 30 … … 42 32 extern void unit_destroy(unit_t **); 43 33 34 // TODO add flags argument with explicit notification? 35 extern void unit_set_state(unit_t *, unit_state_t); 36 44 37 extern int unit_start(unit_t *); 45 38 -
uspace/srv/sysman/units/unit_cfg.h
r4fe7fcb r6efec7e3 1 1 #ifndef SYSMAN_UNIT_CFG_H 2 2 #define SYSMAN_UNIT_CFG_H 3 4 #include "unit_types.h" 3 5 4 6 typedef struct { … … 6 8 } unit_cfg_t; 7 9 10 extern unit_ops_t unit_cfg_ops; 11 8 12 #endif -
uspace/srv/sysman/units/unit_mnt.h
r4fe7fcb r6efec7e3 1 1 #ifndef SYSMAN_UNIT_MNT_H 2 2 #define SYSMAN_UNIT_MNT_H 3 4 #include "unit_types.h" 3 5 4 6 typedef struct { … … 8 10 } unit_mnt_t; 9 11 12 extern unit_ops_t unit_mnt_ops; 13 14 10 15 #endif 11 16
Note:
See TracChangeset
for help on using the changeset viewer.