Changeset 8ae8262 in mainline
- Timestamp:
- 2019-08-07T11:08:17Z (5 years ago)
- Children:
- 130ba46
- Parents:
- 5353f50
- git-author:
- Michal Koutný <xm.koutny+hos@…> (2015-11-12 02:56:35)
- git-committer:
- Matthieu Riolo <matthieu.riolo@…> (2019-08-07 11:08:17)
- Location:
- uspace
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/include/ipc/sysman.h
r5353f50 r8ae8262 69 69 70 70 typedef enum { 71 STATE_EMBRYO = 0, // embryo is orthogonal to states (again convergence to systemd...)72 71 STATE_STARTING, 73 72 STATE_STARTED, -
uspace/srv/sysman/repo.c
r5353f50 r8ae8262 74 74 .equal = &units_by_handle_ht_equal, 75 75 .key_equal = &units_by_handle_ht_key_equal, 76 .remove_callback = NULL // TODO realy unneeded?76 .remove_callback = NULL 77 77 }; 78 78 … … 108 108 .equal = &units_by_name_ht_equal, 109 109 .key_equal = &units_by_name_ht_key_equal, 110 .remove_callback = NULL // TODO realy unneeded?110 .remove_callback = NULL 111 111 }; 112 112 113 113 /* Repository functions */ 114 115 static void repo_remove_unit_internal(unit_t *u) 116 { 117 hash_table_remove_item(&units_by_name, &u->units_by_name); 118 hash_table_remove_item(&units_by_handle, &u->units_by_handle); 119 list_remove(&u->units); 120 121 // TODO decrease refcount of unit 122 // unit may be referenced e.g. from running job, thus we cannot simply destroy it 123 } 114 124 115 125 void repo_init(void) … … 122 132 { 123 133 assert(unit); 124 assert(unit-> state == STATE_EMBRYO);134 assert(unit->repo_state == REPO_EMBRYO); 125 135 assert(unit->handle == 0); 126 136 assert(unit->name != NULL); … … 139 149 } 140 150 151 int repo_remove_unit(unit_t *unit) 152 { 153 unit->repo_state = REPO_ZOMBIE; 154 return EOK; /* We could check that unit is present in repo etc... */ 155 } 156 141 157 void repo_begin_update(void) { 142 158 sysman_log(LVL_DEBUG2, "%s", __func__); … … 146 162 { 147 163 unit_t *unit = hash_table_get_inst(ht_link, unit_t, units_by_name); 148 if (unit->state == STATE_EMBRYO) { 149 unit->state = STATE_STOPPED; 164 if (unit->repo_state == REPO_ZOMBIE) { 165 repo_remove_unit_internal(unit); 166 return true; 167 } 168 169 if (unit->repo_state == REPO_EMBRYO) { 170 unit->repo_state = REPO_LIVING; 150 171 } 151 172 … … 162 183 163 184 /* 164 * Apply commit to all units_by_name, each commited unit commits its outgoing 165 * deps, thus eventually commiting all embryo deps as well. 185 * Apply commit to all units_by_name, each commited unit commits its 186 * outgoing deps, thus eventually commiting all embryo deps as well. 187 * 188 * TODO why not iterate over units list? 166 189 */ 167 190 hash_table_apply(&units_by_name, &repo_commit_unit, NULL); … … 180 203 } 181 204 182 if (unit-> state == STATE_EMBRYO) {183 hash_table_remove_item(&units_by_name, ht_link);184 list_remove(&unit->units);185 unit _destroy(&unit);205 if (unit->repo_state == REPO_EMBRYO) { 206 repo_remove_unit_internal(unit); 207 } else if (unit->repo_state == REPO_ZOMBIE) { 208 unit->repo_state = REPO_LIVING; 186 209 } 187 210 -
uspace/srv/sysman/repo.h
r5353f50 r8ae8262 32 32 #include <adt/list.h> 33 33 #include <ipc/sysman.h> 34 #include <stdio.h> 34 35 35 36 #include "unit.h" 37 38 #define ANONYMOUS_SERVICE_MASK "service_%" PRIu64 36 39 37 40 extern list_t units; … … 40 43 41 44 extern int repo_add_unit(unit_t *); 45 extern int repo_remove_unit(unit_t *); 42 46 43 47 extern void repo_begin_update(void); -
uspace/srv/sysman/sm_task.c
r5353f50 r8ae8262 28 28 29 29 #include <adt/list.h> 30 #include <errno.h> 30 31 #include <stdlib.h> 31 32 #include <task.h> 33 #include <sysman/unit.h> 32 34 33 35 #include "repo.h" … … 35 37 #include "sysman.h" 36 38 #include "sm_task.h" 39 37 40 38 41 /** Structure for boxing task event */ … … 85 88 } 86 89 90 static unit_svc_t *sm_task_create_service(task_id_t tid) 91 { 92 unit_t *u_svc = unit_create(UNIT_SERVICE); 93 bool in_repo_update = false; 94 int rc = EOK; 95 96 if (u_svc == NULL) { 97 goto fail; 98 } 99 100 rc = asprintf(&u_svc->name, ANONYMOUS_SERVICE_MASK "%c%s", tid, 101 UNIT_NAME_SEPARATOR, UNIT_SVC_TYPE_NAME); 102 if (rc < 0) { 103 goto fail; 104 } 105 106 CAST_SVC(u_svc)->main_task_id = tid; 107 CAST_SVC(u_svc)->anonymous = true; 108 /* exec_start is left undefined, maybe could be hinted by kernel's task 109 * name */ 110 111 repo_begin_update(); 112 in_repo_update = true; 113 114 rc = repo_add_unit(u_svc); 115 if (rc != EOK) { 116 goto fail; 117 } 118 119 repo_commit(); 120 121 return CAST_SVC(u_svc); 122 123 fail: 124 if (in_repo_update) { 125 repo_rollback(); 126 } 127 128 unit_destroy(&u_svc); 129 return NULL; 130 } 131 132 static void sm_task_delete_service(unit_svc_t *u_svc) 133 { 134 repo_begin_update(); 135 int rc = repo_remove_unit(&u_svc->unit); 136 if (rc != EOK) { 137 sysman_log(LVL_WARN, "Can't remove unit %s (%i).", 138 unit_name(&u_svc->unit), rc); 139 repo_rollback(); 140 return; 141 } 142 143 repo_commit(); 144 } 145 87 146 static void sysman_event_task_event(void *data) 88 147 { … … 92 151 __func__, tev->task_id, tev->flags); 93 152 unit_svc_t *u_svc = sm_task_find_service(tev->task_id); 153 94 154 if (u_svc == NULL) { 95 goto finish; 155 if (tev->flags & TASK_WAIT_EXIT) { 156 /* Non-service task exited, ignore. */ 157 goto finish; 158 } 159 160 u_svc = sm_task_create_service(tev->task_id); 161 if (u_svc == NULL) { 162 sysman_log(LVL_WARN, 163 "Unable to create anonymous service for task %" PRIu64 ".", 164 tev->task_id); 165 goto finish; 166 } 167 168 sysman_log(LVL_DEBUG, "Created anonymous service %s.", 169 unit_name(&u_svc->unit)); 170 171 /* Inject state so that further processing makes sense */ 172 u_svc->unit.state = STATE_STARTING; 96 173 } 97 174 … … 111 188 u->state = STATE_FAILED; 112 189 } 190 113 191 } 114 192 if (tev->flags & TASK_WAIT_RETVAL) { … … 119 197 unit_notify_state(u); 120 198 199 if ((tev->flags & TASK_WAIT_EXIT) && u_svc->anonymous) { 200 sysman_log(LVL_DEBUG, "Deleted anonymous service %s.", 201 unit_name(&u_svc->unit)); 202 sm_task_delete_service(u_svc); 203 } 121 204 finish: 122 205 free(tev); -
uspace/srv/sysman/unit.c
r5353f50 r8ae8262 68 68 69 69 unit->type = type; 70 unit->state = STATE_EMBRYO; 70 unit->state = STATE_STOPPED; 71 unit->repo_state = REPO_EMBRYO; 71 72 72 73 link_initialize(&unit->units); -
uspace/srv/sysman/unit.h
r5353f50 r8ae8262 48 48 struct job; 49 49 50 /* Represents presence of unit in repo during modifications */ 51 typedef enum { 52 REPO_EMBRYO, 53 REPO_LIVING, 54 REPO_ZOMBIE 55 } repo_state_t; 56 50 57 typedef struct { 51 58 /** Link to name-to-unit hash table */ … … 80 87 81 88 unit_state_t state; 89 90 repo_state_t repo_state; 82 91 83 92 list_t edges_in; -
uspace/srv/sysman/units/unit_cfg.c
r5353f50 r8ae8262 177 177 } 178 178 179 assert(unit-> state == STATE_EMBRYO);179 assert(unit->repo_state == REPO_EMBRYO); 180 180 repo_add_unit(unit); 181 181 } -
uspace/srv/sysman/units/unit_svc.h
r5353f50 r8ae8262 41 41 42 42 task_id_t main_task_id; 43 44 bool anonymous; 43 45 } unit_svc_t; 44 46
Note:
See TracChangeset
for help on using the changeset viewer.