Changeset 9532981 in mainline
- Timestamp:
- 2019-08-07T09:35:37Z (5 years ago)
- Children:
- db34424
- Parents:
- af92309
- git-author:
- Michal Koutný <xm.koutny+hos@…> (2015-11-02 23:10:51)
- git-committer:
- Matthieu Riolo <matthieu.riolo@…> (2019-08-07 09:35:37)
- Location:
- uspace
- Files:
-
- 13 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/include/ipc/sysman.h
raf92309 r9532981 67 67 68 68 typedef enum { 69 STATE_EMBRYO = 0, 69 STATE_EMBRYO = 0, // embryo is orthogonal to states (again convergence to systemd...) 70 70 STATE_STARTING, 71 71 STATE_STARTED, -
uspace/srv/sysman/Makefile
raf92309 r9532981 40 40 connection_broker.c \ 41 41 connection_ctl.c \ 42 dep.c \42 edge.c \ 43 43 job.c \ 44 44 log.c \ -
uspace/srv/sysman/edge.c
raf92309 r9532981 32 32 #include <str.h> 33 33 34 #include " dep.h"34 #include "edge.h" 35 35 36 static void dep_dependency_init(unit_dependency_t *dep)36 static void edge_init(unit_edge_t *e) 37 37 { 38 memset(dep, 0, sizeof(*dep)); 39 link_initialize(&dep->dependants); 40 link_initialize(&dep->dependencies); 41 42 dep->state = DEP_EMBRYO; 38 memset(e, 0, sizeof(*e)); 39 link_initialize(&e->edges_in); 40 link_initialize(&e->edges_out); 43 41 } 44 42 45 unit_ dependency_t *dep_dependency_create(void)43 unit_edge_t *edge_create(void) 46 44 { 47 unit_ dependency_t *dep = malloc(sizeof(unit_dependency_t));48 if ( dep) {49 dep_dependency_init(dep);45 unit_edge_t *e = malloc(sizeof(unit_edge_t)); 46 if (e) { 47 edge_init(e); 50 48 } 51 return dep;49 return e; 52 50 } 53 51 54 void dep_dependency_destroy(unit_dependency_t **dep_ptr)52 void edge_destroy(unit_edge_t **e_ptr) 55 53 { 56 unit_ dependency_t *dep = *dep_ptr;57 if ( dep== NULL) {54 unit_edge_t *e = *e_ptr; 55 if (e == NULL) { 58 56 return; 59 57 } 60 58 61 list_remove(& dep->dependencies);62 list_remove(& dep->dependants);59 list_remove(&e->edges_in); 60 list_remove(&e->edges_out); 63 61 64 free( dep->dependency_name);65 free( dep);62 free(e->output_name); 63 free(e); 66 64 67 * dep_ptr = NULL;65 *e_ptr = NULL; 68 66 } 69 67 70 int dep_sprout_dependency(unit_t *dependant, const char *dependency_name)68 int edge_sprout_out(unit_t *input, const char *output_name) 71 69 { 72 unit_ dependency_t *dep = dep_dependency_create();70 unit_edge_t *e = edge_create(); 73 71 int rc; 74 72 75 if ( dep== NULL) {73 if (e == NULL) { 76 74 rc = ENOMEM; 77 75 goto finish; 78 76 } 79 77 80 dep->dependency_name = str_dup(dependency_name);81 if ( dep->dependency_name == NULL) {78 e->output_name = str_dup(output_name); 79 if (e->output_name == NULL) { 82 80 rc = ENOMEM; 83 81 goto finish; 84 82 } 85 83 86 list_append(& dep->dependencies, &dependant->dependencies);87 dep->dependant = dependant;84 list_append(&e->edges_out, &input->edges_out); 85 e->input = input; 88 86 89 87 rc = EOK; … … 91 89 finish: 92 90 if (rc != EOK) { 93 dep_dependency_destroy(&dep);91 edge_destroy(&e); 94 92 } 95 93 return rc; 96 94 } 97 95 98 void dep_resolve_dependency(unit_dependency_t *dep, unit_t *unit)96 void edge_resolve_output(unit_edge_t *e, unit_t *unit) 99 97 { 100 assert( dep->dependency== NULL);101 assert( dep->dependency_name != NULL);98 assert(e->output == NULL); 99 assert(e->output_name != NULL); 102 100 103 // TODO add to other side dependantslist104 dep->dependency= unit;105 free( dep->dependency_name);106 dep->dependency_name = NULL;101 // TODO add to other side edges_in list 102 e->output = unit; 103 free(e->output_name); 104 e->output_name = NULL; 107 105 } 108 106 … … 112 110 * @return ENOMEM 113 111 */ 114 int dep_add_dependency(unit_t *dependant, unit_t *dependency)112 int edge_connect(unit_t *input, unit_t *output) 115 113 { 116 unit_ dependency_t *dep = dep_dependency_create();117 if ( dep== NULL) {114 unit_edge_t *e = edge_create(); 115 if (e == NULL) { 118 116 return ENOMEM; 119 117 } 120 118 121 // TODO check existence of the dep119 // TODO check existence of the e 122 120 // TODO locking 123 121 // TODO check types and states of connected units 124 list_append(& dep->dependants, &dependency->dependants);125 list_append(& dep->dependencies, &dependant->dependencies);122 list_append(&e->edges_in, &output->edges_in); 123 list_append(&e->edges_out, &input->edges_out); 126 124 127 dep->dependant = dependant;128 dep->dependency = dependency;125 e->input = input; 126 e->output = output; 129 127 return EOK; 130 128 } 131 129 132 /** Remove dependency from dependencygraph130 /** Remove output from output graph 133 131 * 134 * Given dependencyis removed from graph and unallocated.132 * Given output is removed from graph and unallocated. 135 133 */ 136 void dep_remove_dependency(unit_dependency_t **dep_ptr)134 void edge_remove(unit_edge_t **e_ptr) 137 135 { 138 136 // TODO here should be some checks, othewise replace this wrapper with 139 137 // direct destroy 140 dep_dependency_destroy(dep_ptr);138 edge_destroy(e_ptr); 141 139 } -
uspace/srv/sysman/edge.h
raf92309 r9532981 27 27 */ 28 28 29 #ifndef SYSMAN_ DEP_H30 #define SYSMAN_ DEP_H29 #ifndef SYSMAN_EDGE_H 30 #define SYSMAN_EDGE_H 31 31 32 32 #include <adt/list.h> … … 34 34 #include "unit.h" 35 35 36 typedef enum { 37 DEP_EMBRYO, 38 DEP_VALID 39 } dependency_state_t; 40 41 /** Dependency edge between unit in dependency graph 36 /** Dependency edge between units in dependency graph 42 37 * 43 38 * @code 44 * dependant ---> dependency39 * input ---> output 45 40 * @endcode 46 41 * 47 42 */ 48 43 typedef struct { 49 /** Link to dependantslist */50 link_t dependants;51 /** Link to dependencieslist */52 link_t dependencies;44 /** Link to edges_out list */ 45 link_t edges_in; 46 /** Link to edges_out list */ 47 link_t edges_out; 53 48 54 dependency_state_t state;49 bool commited; 55 50 56 51 /** Unit that depends on another */ 57 unit_t * dependant;52 unit_t *input; 58 53 59 54 /** Unit that is dependency for another */ 60 unit_t * dependency;55 unit_t *output; 61 56 62 /** Name of the dependency unit, for resolved dependencies it's NULL57 /** Name of the output unit, for resolved edges it's NULL 63 58 * 64 * @note Either dependency or dependency_name is set. Never both nor 65 * none. 59 * @note Either output or output_nameis set. Never both nor none. 66 60 */ 67 char * dependency_name;68 } unit_ dependency_t;61 char *output_name; 62 } unit_edge_t; 69 63 70 extern unit_ dependency_t *dep_dependency_create(void);71 extern void dep_dependency_destroy(unit_dependency_t **);64 extern unit_edge_t *edge_create(void); 65 extern void edge_destroy(unit_edge_t **); 72 66 73 extern int dep_sprout_dependency(unit_t *, const char *);74 extern void dep_resolve_dependency(unit_dependency_t *, unit_t *);67 extern int edge_sprout_out(unit_t *, const char *); 68 extern void edge_resolve_output(unit_edge_t *, unit_t *); 75 69 76 extern int dep_add_dependency(unit_t *, unit_t *);77 extern void dep_remove_dependency(unit_dependency_t **);70 extern int edge_connect(unit_t *, unit_t *); 71 extern void edge_remove(unit_edge_t **); 78 72 79 73 -
uspace/srv/sysman/job.c
raf92309 r9532981 33 33 34 34 #include "repo.h" 35 #include " dep.h"35 #include "edge.h" 36 36 #include "job.h" 37 37 #include "log.h" … … 411 411 * appropriate jobs (currently "After" only). 412 412 */ 413 list_foreach(unit-> dependencies, dependencies, unit_dependency_t, dep) {414 unit_t *u = dep->dependency;413 list_foreach(unit->edges_out, edges_out, unit_edge_t, e) { 414 unit_t *u = e->output; 415 415 job_t *blocking_job; 416 416 -
uspace/srv/sysman/main.c
raf92309 r9532981 40 40 #include "connection_broker.h" 41 41 #include "connection_ctl.h" 42 #include " dep.h"42 #include "edge.h" 43 43 #include "job.h" 44 44 #include "log.h" … … 137 137 repo_add_unit(tgt_init); 138 138 139 rc = dep_add_dependency(tgt_init, cfg_init);139 rc = edge_connect(tgt_init, cfg_init); 140 140 if (rc != EOK) { 141 141 goto rollback; 142 142 } 143 143 144 rc = dep_add_dependency(cfg_init, mnt_initrd);144 rc = edge_connect(cfg_init, mnt_initrd); 145 145 if (rc != EOK) { 146 146 goto rollback; -
uspace/srv/sysman/repo.c
raf92309 r9532981 35 35 36 36 #include "repo.h" 37 #include " dep.h"37 #include "edge.h" 38 38 #include "log.h" 39 39 … … 148 148 { 149 149 unit_t *unit = hash_table_get_inst(ht_link, unit_t, units_by_name); 150 // TODO state locking?151 150 if (unit->state == STATE_EMBRYO) { 152 151 unit->state = STATE_STOPPED; 153 152 } 154 153 155 list_foreach(unit->dependencies, dependencies, unit_dependency_t, dep) { 156 if (dep->state == DEP_EMBRYO) { 157 dep->state = DEP_VALID; 158 } 154 list_foreach(unit->edges_out, edges_out, unit_edge_t, e) { 155 e->commited = true; 159 156 } 160 157 return true; … … 177 174 unit_t *unit = hash_table_get_inst(ht_link, unit_t, units_by_name); 178 175 179 list_foreach_safe(unit-> dependencies, cur_link, next_link) {180 unit_ dependency_t *dep=181 list_get_instance(cur_link, unit_ dependency_t, dependencies);182 if ( dep->state == DEP_EMBRYO) {183 dep_remove_dependency(&dep);176 list_foreach_safe(unit->edges_out, cur_link, next_link) { 177 unit_edge_t *e = 178 list_get_instance(cur_link, unit_edge_t, edges_out); 179 if (!e->commited) { 180 edge_remove(&e); 184 181 } 185 182 } … … 210 207 unit_t *unit = hash_table_get_inst(ht_link, unit_t, units_by_name); 211 208 212 list_foreach(unit-> dependencies, dependencies, unit_dependency_t, dep) {213 assert( dep->dependant == unit);214 assert(( dep->dependency != NULL) != (dep->dependency_name != NULL));215 if ( dep->dependency) {209 list_foreach(unit->edges_out, edges_out, unit_edge_t, e) { 210 assert(e->input == unit); 211 assert((e->output != NULL) != (e->output_name != NULL)); 212 if (e->output) { 216 213 continue; 217 214 } 218 215 219 unit_t * dependency=220 repo_find_unit_by_name( dep->dependency_name);221 if ( dependency== NULL) {216 unit_t *output = 217 repo_find_unit_by_name(e->output_name); 218 if (output == NULL) { 222 219 sysman_log(LVL_ERROR, 223 220 "Cannot resolve dependency of '%s' to unit '%s'", 224 unit_name(unit), dep->dependency_name);221 unit_name(unit), e->output_name); 225 222 *has_error_ptr = true; 226 223 // TODO should we just leave the sprout untouched? 227 224 } else { 228 dep_resolve_dependency(dep, dependency);225 edge_resolve_output(e, output); 229 226 } 230 227 } … … 238 235 * @return ENOENT when one or more resolution fails, information is logged 239 236 */ 240 int repo_resolve_ dependecies(void)237 int repo_resolve_references(void) 241 238 { 242 239 sysman_log(LVL_DEBUG2, "%s", __func__); -
uspace/srv/sysman/repo.h
raf92309 r9532981 47 47 extern void repo_rollback(void); 48 48 49 extern int repo_resolve_ dependecies(void);49 extern int repo_resolve_references(void); 50 50 51 51 extern unit_t *repo_find_unit_by_name(const char *); -
uspace/srv/sysman/test/job_closure.c
raf92309 r9532981 140 140 * u0 -> u1 -> u2 -> u3 141 141 */ 142 mock_add_ dependency(u0, u1);143 mock_add_ dependency(u1, u2);144 mock_add_ dependency(u2, u3);142 mock_add_edge(u0, u1); 143 mock_add_edge(u1, u2); 144 mock_add_edge(u2, u3); 145 145 146 146 /* Intentionally omit u0 */ … … 172 172 * \-> u3 173 173 */ 174 mock_add_ dependency(u0, u1);175 mock_add_ dependency(u1, u2);176 mock_add_ dependency(u1, u3);174 mock_add_edge(u0, u1); 175 mock_add_edge(u1, u2); 176 mock_add_edge(u1, u3); 177 177 178 178 job_t *main_job = job_create(u1, STATE_STARTED); … … 204 204 * \-> u3 205 205 */ 206 mock_add_ dependency(u0, u1);207 mock_add_ dependency(u1, u2);208 mock_add_ dependency(u1, u3);209 mock_add_ dependency(u2, u3);206 mock_add_edge(u0, u1); 207 mock_add_edge(u1, u2); 208 mock_add_edge(u1, u3); 209 mock_add_edge(u2, u3); 210 210 211 211 job_t *main_job = job_create(u1, STATE_STARTED); -
uspace/srv/sysman/test/job_queue.c
raf92309 r9532981 131 131 132 132 /* All services require root fs */ 133 mock_add_ dependency(s0, m0);134 mock_add_ dependency(s1, m0);133 mock_add_edge(s0, m0); 134 mock_add_edge(s1, m0); 135 135 136 136 /* S1 requires another mount and S0 */ 137 mock_add_ dependency(s1, s0);137 mock_add_edge(s1, s0); 138 138 139 139 /* Enforce initial state */ -
uspace/srv/sysman/test/mock_unit.c
raf92309 r9532981 29 29 #include <assert.h> 30 30 31 #include "../ dep.h"31 #include "../edge.h" 32 32 33 33 #include "mock_unit.h" … … 76 76 } 77 77 78 void mock_add_ dependency(unit_t *dependant, unit_t *dependency)78 void mock_add_edge(unit_t *input, unit_t *output) 79 79 { 80 int rc = dep_add_dependency(dependant, dependency);80 int rc = edge_connect(input, output); 81 81 assert(rc == EOK); 82 82 83 link_t *link = list_last(& dependant->dependencies);84 unit_ dependency_t *dep=85 list_get_instance(link, unit_ dependency_t, dependencies);86 dep->state = DEP_VALID;83 link_t *link = list_last(&input->edges_out); 84 unit_edge_t *e = 85 list_get_instance(link, unit_edge_t, edges_out); 86 e->commited = true; 87 87 } 88 88 -
uspace/srv/sysman/test/mock_unit.h
raf92309 r9532981 46 46 47 47 extern void mock_set_units_state(unit_state_t state); 48 extern void mock_add_ dependency(unit_t *dependant, unit_t *dependency);48 extern void mock_add_edge(unit_t *, unit_t *); 49 49 50 50 extern int mock_unit_vmt_start_sync(unit_t *); -
uspace/srv/sysman/unit.c
raf92309 r9532981 39 39 #include <sysman/unit.h> 40 40 41 #include " dep.h"41 #include "edge.h" 42 42 #include "log.h" 43 43 #include "sysman.h" … … 72 72 link_initialize(&unit->units); 73 73 link_initialize(&unit->bfs_link); 74 list_initialize(&unit-> dependants);75 list_initialize(&unit-> dependencies);74 list_initialize(&unit->edges_in); 75 list_initialize(&unit->edges_out); 76 76 77 77 UNIT_VMT(unit)->init(unit); … … 159 159 } 160 160 161 // TODO move to libsysman 161 162 unit_type_t unit_type_name_to_type(const char *type_name) 162 163 { … … 199 200 200 201 while ((cur_tok = str_tok(to_split, " ", &to_split))) { 201 if ( dep_sprout_dependency(unit, cur_tok) != EOK) {202 if (edge_sprout_out(unit, cur_tok) != EOK) { 202 203 result = false; 203 204 goto finish; -
uspace/srv/sysman/unit.h
raf92309 r9532981 74 74 unit_state_t state; 75 75 76 list_t dependencies;77 list_t dependants;76 list_t edges_in; 77 list_t edges_out; 78 78 } unit_t; 79 79 -
uspace/srv/sysman/units/unit_cfg.c
raf92309 r9532981 182 182 closedir(dir); 183 183 184 int rc = repo_resolve_ dependecies();184 int rc = repo_resolve_references(); 185 185 if (rc != EOK) { 186 186 repo_rollback();
Note:
See TracChangeset
for help on using the changeset viewer.