Changeset b55f62a in mainline
- Timestamp:
- 2019-08-07T09:29:33Z (6 years ago)
- Children:
- 918ac9b
- Parents:
- 2df7d824
- git-author:
- Michal Koutný <xm.koutny+hos@…> (2015-11-02 00:50:02)
- git-committer:
- Matthieu Riolo <matthieu.riolo@…> (2019-08-07 09:29:33)
- Location:
- uspace
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/Makefile
r2df7d824 rb55f62a 72 72 app/sportdmp \ 73 73 app/stats \ 74 app/sysctl \ 74 75 app/taskdump \ 75 76 app/tester \ -
uspace/lib/c/include/ipc/sysman.h
r2df7d824 rb55f62a 44 44 SYSMAN_BROKER_EXP_ADDED, 45 45 SYSMAN_BROKER_EXP_REMOVED, 46 SYSMAN_CTL_UNIT_START 46 SYSMAN_CTL_UNIT_START, 47 SYSMAN_CTL_GET_UNITS, 48 SYSMAN_CTL_UNIT_GET_NAME, 49 SYSMAN_CTL_UNIT_GET_STATE 47 50 } sysman_ipc_method_t; 48 51 … … 53 56 } sysman_interface_t; 54 57 58 typedef sysarg_t unit_handle_t; 59 60 typedef enum { 61 UNIT_TYPE_INVALID = -1, 62 UNIT_CONFIGURATION = 0, 63 UNIT_MOUNT, 64 UNIT_SERVICE, 65 UNIT_TARGET 66 } unit_type_t; 67 68 typedef enum { 69 STATE_EMBRYO = 0, 70 STATE_STARTING, 71 STATE_STARTED, 72 STATE_STOPPED, 73 STATE_FAILED 74 } unit_state_t; 75 55 76 #endif 56 77 -
uspace/lib/sysman/include/sysman/ctl.h
r2df7d824 rb55f62a 30 30 #define _SYSMAN_CTL_H 31 31 32 #include <ipc/sysman.h> 32 33 #include <sysman/unit.h> 33 34 34 35 int sysman_unit_start(const char *, int); 35 36 37 int sysman_get_units(unit_handle_t **, size_t *); 38 39 int sysman_unit_get_name(unit_handle_t, char *, size_t); 40 int sysman_unit_get_state(unit_handle_t, unit_state_t *); 36 41 #endif -
uspace/lib/sysman/src/ctl.c
r2df7d824 rb55f62a 29 29 #include <async.h> 30 30 #include <errno.h> 31 #include <stdlib.h> 31 32 #include <str.h> 32 33 #include <sysman/ctl.h> … … 57 58 return rc; 58 59 } 60 61 static int sysman_get_units_once(sysarg_t *buf, size_t buf_size, 62 size_t *act_size) 63 { 64 async_exch_t *exch = sysman_exchange_begin(SYSMAN_PORT_CTL); 65 66 ipc_call_t answer; 67 aid_t req = async_send_0(exch, SYSMAN_CTL_GET_UNITS, &answer); 68 int rc = async_data_read_start(exch, buf, buf_size); 69 70 sysman_exchange_end(exch); 71 72 if (rc != EOK) { 73 async_forget(req); 74 return rc; 75 } 76 77 sysarg_t retval; 78 async_wait_for(req, &retval); 79 80 if (retval != EOK) { 81 return retval; 82 } 83 84 *act_size = IPC_GET_ARG1(answer); 85 return EOK; 86 } 87 88 int sysman_get_units(unit_handle_t **units_ptr, size_t *cnt_ptr) 89 { 90 *units_ptr = NULL; 91 *cnt_ptr = 0; 92 93 unit_handle_t *units = NULL; 94 size_t alloc_size = 0; 95 size_t act_size = 0; 96 97 while (true) { 98 int rc = sysman_get_units_once(units, alloc_size, &act_size); 99 if (rc != EOK) { 100 return rc; 101 } 102 103 if (act_size <= alloc_size) { 104 break; 105 } 106 107 alloc_size = act_size; 108 units = realloc(units, alloc_size); 109 if (units == NULL) { 110 return ENOMEM; 111 } 112 } 113 114 *units_ptr = units; 115 *cnt_ptr = act_size / sizeof(unit_handle_t); 116 return EOK; 117 } 118 119 int sysman_unit_get_name(unit_handle_t handle, char *buf, size_t buf_size) 120 { 121 async_exch_t *exch = sysman_exchange_begin(SYSMAN_PORT_CTL); 122 123 ipc_call_t answer; 124 aid_t req = async_send_1(exch, SYSMAN_CTL_UNIT_GET_NAME, handle, &answer); 125 int rc = async_data_read_start(exch, buf, buf_size); 126 127 sysman_exchange_end(exch); 128 129 if (rc != EOK) { 130 async_forget(req); 131 return rc; 132 } 133 134 sysarg_t retval; 135 async_wait_for(req, &retval); 136 137 if (retval != EOK) { 138 return retval; 139 } 140 141 return EOK; 142 } 143 144 int sysman_unit_get_state(unit_handle_t handle, unit_state_t *state) 145 { 146 async_exch_t *exch = sysman_exchange_begin(SYSMAN_PORT_CTL); 147 int rc = async_req_1_1(exch, SYSMAN_CTL_UNIT_GET_STATE, handle, state); 148 sysman_exchange_end(exch); 149 150 return rc; 151 } -
uspace/srv/sysman/configuration.c
r2df7d824 rb55f62a 43 43 44 44 static hash_table_t units_by_name; 45 static hash_table_t units_by_handle; 45 46 46 47 /* Hash table functions */ 48 static size_t units_by_handle_ht_hash(const ht_link_t *item) 49 { 50 unit_t *unit = 51 hash_table_get_inst(item, unit_t, units_by_handle); 52 return unit->handle; 53 } 54 55 static size_t units_by_handle_ht_key_hash(void *key) 56 { 57 return *(unit_handle_t *)key; 58 } 59 60 static bool units_by_handle_ht_equal(const ht_link_t *item1, const ht_link_t *item2) 61 { 62 return 63 hash_table_get_inst(item1, unit_t, units_by_handle) == 64 hash_table_get_inst(item2, unit_t, units_by_handle); 65 } 66 67 static bool units_by_handle_ht_key_equal(void *key, const ht_link_t *item) 68 { 69 return *(unit_handle_t *)key == 70 hash_table_get_inst(item, unit_t, units_by_handle)->handle; 71 } 72 73 static hash_table_ops_t units_by_handle_ht_ops = { 74 .hash = &units_by_handle_ht_hash, 75 .key_hash = &units_by_handle_ht_key_hash, 76 .equal = &units_by_handle_ht_equal, 77 .key_equal = &units_by_handle_ht_key_equal, 78 .remove_callback = NULL // TODO realy unneeded? 79 }; 80 47 81 static size_t units_by_name_ht_hash(const ht_link_t *item) 48 82 { … … 59 93 static bool units_by_name_ht_equal(const ht_link_t *item1, const ht_link_t *item2) 60 94 { 61 return str_cmp(62 hash_table_get_inst(item1, unit_t, units_by_ name)->name,63 hash_table_get_inst(item2, unit_t, units_by_ name)->name) == 0;95 return 96 hash_table_get_inst(item1, unit_t, units_by_handle) == 97 hash_table_get_inst(item2, unit_t, units_by_handle); 64 98 } 65 99 … … 84 118 { 85 119 hash_table_create(&units_by_name, 0, 0, &units_by_name_ht_ops); 120 hash_table_create(&units_by_handle, 0, 0, &units_by_handle_ht_ops); 86 121 } 87 122 … … 90 125 assert(unit); 91 126 assert(unit->state == STATE_EMBRYO); 127 assert(unit->handle == 0); 92 128 assert(unit->name != NULL); 93 129 sysman_log(LVL_DEBUG2, "%s('%s')", __func__, unit_name(unit)); 94 130 95 131 if (hash_table_insert_unique(&units_by_name, &unit->units_by_name)) { 132 /* Pointers are same size as unit_handle_t both on 32b and 64b */ 133 unit->handle = (unit_handle_t)unit; 134 135 hash_table_insert(&units_by_handle, &unit->units_by_handle); 96 136 list_append(&unit->units, &units); 97 137 return EOK; … … 218 258 } 219 259 260 unit_t *configuration_find_unit_by_handle(unit_handle_t handle) 261 { 262 ht_link_t *ht_link = hash_table_find(&units_by_handle, &handle); 263 if (ht_link != NULL) { 264 return hash_table_get_inst(ht_link, unit_t, units_by_handle); 265 } else { 266 return NULL; 267 } 268 } 269 -
uspace/srv/sysman/configuration.h
r2df7d824 rb55f62a 31 31 32 32 #include <adt/list.h> 33 #include <ipc/sysman.h> 33 34 34 35 #include "unit.h" … … 49 50 50 51 extern unit_t *configuration_find_unit_by_name(const char *); 52 extern unit_t *configuration_find_unit_by_handle(unit_handle_t); 51 53 52 54 -
uspace/srv/sysman/connection_ctl.c
r2df7d824 rb55f62a 29 29 #include <errno.h> 30 30 #include <ipc/sysman.h> 31 #include <macros.h> 31 32 #include <stdlib.h> 33 #include <str.h> 32 34 33 35 #include "configuration.h" … … 61 63 job_del_ref(&job); 62 64 } 63 64 65 static void sysman_unit_start(ipc_callid_t iid, ipc_call_t *icall) 65 66 { … … 77 78 sysman_log(LVL_DEBUG2, "%s(%s, %x)", __func__, unit_name, flags); 78 79 80 // TODO this is connection fibril, UNSYNCHRONIZED access to units! 79 81 unit_t *unit = configuration_find_unit_by_name(unit_name); 80 82 if (unit == NULL) { … … 109 111 } 110 112 113 static int fill_handles_buffer(unit_handle_t *buffer, size_t size, 114 size_t *act_size) 115 { 116 if (size % sizeof(unit_handle_t) != 0) { 117 return EINVAL; 118 } 119 120 size_t filled = 0; 121 size_t to_fill = size / sizeof(unit_handle_t); 122 size_t total = 0; 123 list_foreach(units, units, unit_t, u) { 124 if (filled < to_fill) { 125 buffer[filled++] = u->handle; 126 } 127 ++total; 128 } 129 *act_size = total * sizeof(unit_handle_t); 130 return EOK; 131 } 132 133 static void sysman_get_units(ipc_callid_t iid, ipc_call_t *icall) 134 { 135 ipc_callid_t callid; 136 size_t size; 137 size_t act_size; 138 int rc; 139 140 if (!async_data_read_receive(&callid, &size)) { 141 async_answer_0(callid, EREFUSED); 142 async_answer_0(iid, EREFUSED); 143 return; 144 } 145 146 147 unit_handle_t *handles = malloc(size); 148 if (handles == NULL && size > 0) { 149 async_answer_0(callid, ENOMEM); 150 async_answer_0(iid, ENOMEM); 151 return; 152 } 153 154 155 // TODO UNSYNCHRONIZED access to units! 156 rc = fill_handles_buffer(handles, size, &act_size); 157 if (rc != EOK) { 158 async_answer_0(callid, rc); 159 async_answer_0(iid, rc); 160 return; 161 } 162 163 size_t real_size = min(act_size, size); 164 sysarg_t retval = async_data_read_finalize(callid, handles, real_size); 165 free(handles); 166 167 async_answer_1(iid, retval, act_size); 168 } 169 170 static void sysman_unit_get_name(ipc_callid_t iid, ipc_call_t *icall) 171 { 172 ipc_callid_t callid; 173 size_t size; 174 175 if (!async_data_read_receive(&callid, &size)) { 176 async_answer_0(callid, EREFUSED); 177 async_answer_0(iid, EREFUSED); 178 return; 179 } 180 181 // TODO UNSYNCHRONIZED access to units! 182 unit_t *u = configuration_find_unit_by_handle(IPC_GET_ARG1(*icall)); 183 if (u == NULL) { 184 async_answer_0(callid, ENOENT); 185 async_answer_0(iid, ENOENT); 186 return; 187 } 188 189 size_t real_size = min(str_size(u->name) + 1, size); 190 sysarg_t retval = async_data_read_finalize(callid, u->name, real_size); 191 192 async_answer_0(iid, retval); 193 } 194 195 static void sysman_unit_get_state(ipc_callid_t iid, ipc_call_t *icall) 196 { 197 // TODO UNSYNCHRONIZED access to units! 198 unit_t *u = configuration_find_unit_by_handle(IPC_GET_ARG1(*icall)); 199 if (u == NULL) { 200 async_answer_0(iid, ENOENT); 201 } else { 202 async_answer_1(iid, EOK, u->state); 203 } 204 } 205 111 206 void sysman_connection_ctl(ipc_callid_t iid, ipc_call_t *icall) 112 207 { … … 128 223 sysman_unit_start(callid, &call); 129 224 break; 225 case SYSMAN_CTL_GET_UNITS: 226 sysman_get_units(callid, &call); 227 break; 228 case SYSMAN_CTL_UNIT_GET_NAME: 229 sysman_unit_get_name(callid, &call); 230 break; 231 case SYSMAN_CTL_UNIT_GET_STATE: 232 sysman_unit_get_state(callid, &call); 233 break; 130 234 default: 131 235 async_answer_0(callid, ENOENT); -
uspace/srv/sysman/sm_task.c
r2df7d824 rb55f62a 89 89 sm_task_event_t *tev = data; 90 90 91 sysman_log(LVL_DEBUG2, "%s, %" PRIu64 " %i", 92 __func__, tev->task_id, tev->flags); 91 93 unit_svc_t *u_svc = sm_task_find_service(tev->task_id); 92 94 if (u_svc == NULL) { -
uspace/srv/sysman/unit.h
r2df7d824 rb55f62a 39 39 #include <conf/text_parse.h> 40 40 #include <fibril_synch.h> 41 42 typedef enum { 43 UNIT_TYPE_INVALID = -1, 44 UNIT_CONFIGURATION = 0, 45 UNIT_MOUNT, 46 UNIT_SERVICE, 47 UNIT_TARGET 48 } unit_type_t; 49 50 typedef enum { 51 STATE_EMBRYO = 0, 52 STATE_STARTING, 53 STATE_STARTED, 54 STATE_STOPPED, 55 STATE_FAILED 56 } unit_state_t; 41 #include <ipc/sysman.h> 57 42 58 43 /* Forward declarations */ … … 66 51 /** Link to name-to-unit hash table */ 67 52 ht_link_t units_by_name; 53 54 /** Link to handle-to-unit hash table */ 55 ht_link_t units_by_handle; 68 56 69 57 /** Link to list of all units */ … … 80 68 job_t *job; 81 69 70 unit_handle_t handle; 82 71 unit_type_t type; 83 72 char *name;
Note:
See TracChangeset
for help on using the changeset viewer.