Changeset 5559712 in mainline for uspace/srv/sysman/units
- Timestamp:
- 2019-08-03T09:28:50Z (6 years ago)
- Children:
- c0e4fc50
- Parents:
- 2dda1d4
- git-author:
- Michal Koutný <xm.koutny+hos@…> (2015-05-07 11:49:47)
- git-committer:
- Matthieu Riolo <matthieu.riolo@…> (2019-08-03 09:28:50)
- Location:
- uspace/srv/sysman/units
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/sysman/units/unit_cfg.c
r2dda1d4 r5559712 36 36 #include <stdlib.h> 37 37 #include <str.h> 38 #include <sysman/unit.h> 38 39 39 40 #include "configuration.h" … … 66 67 text_parse_init(&text_parse); 67 68 68 const char *last_ dot = str_rchr(filename, '.');69 if (last_ dot== NULL) {69 const char *last_sep = str_rchr(filename, UNIT_NAME_SEPARATOR); 70 if (last_sep == NULL) { 70 71 rc = EINVAL; 71 72 goto finish; … … 73 74 74 75 const char *unit_name = filename; 75 const char *unit_type_name = last_ dot+ 1;76 const char *unit_type_name = last_sep + 1; 76 77 77 78 unit_type_t unit_type = unit_type_name_to_type(unit_type_name); … … 195 196 unit_cfg_t *u_cfg = CAST_CFG(unit); 196 197 assert(u_cfg); 197 198 u_cfg->path = NULL; 199 } 200 201 198 } 202 199 203 200 static void unit_cfg_destroy(unit_t *unit) … … 243 240 } 244 241 242 static void unit_cfg_exposee_created(unit_t *unit) 243 { 244 /* Configuration has no exposees. */ 245 assert(false); 246 } 247 248 static void unit_cfg_fail(unit_t *unit) 249 { 250 /* Configuration cannot async fail. */ 251 assert(false); 252 } 253 245 254 DEFINE_UNIT_VMT(unit_cfg) 246 255 -
uspace/srv/sysman/units/unit_cfg.h
r2dda1d4 r5559712 38 38 } unit_cfg_t; 39 39 40 extern unit_vmt_t unit_cfg_ ops;40 extern unit_vmt_t unit_cfg_vmt; 41 41 42 42 #endif -
uspace/srv/sysman/units/unit_mnt.c
r2dda1d4 r5559712 32 32 #include <stdlib.h> 33 33 #include <vfs/vfs.h> 34 #include <str.h> 34 35 35 36 #include "log.h" 37 #include "sysman.h" 36 38 #include "unit.h" 37 39 … … 39 41 40 42 static config_item_t unit_configuration[] = { 41 {"What", &config_parse_string, offsetof(unit_mnt_t, device), NULL}, 42 {"Where", &config_parse_string, offsetof(unit_mnt_t, mountpoint), NULL}, 43 {"Type", &config_parse_string, offsetof(unit_mnt_t, type), NULL}, 43 {"What", &config_parse_string, offsetof(unit_mnt_t, device), NULL}, 44 {"Where", &config_parse_string, offsetof(unit_mnt_t, mountpoint), NULL}, 45 {"Type", &config_parse_string, offsetof(unit_mnt_t, type), NULL}, 46 {"Autostart", &config_parse_bool, offsetof(unit_mnt_t, autostart), "true"}, 47 {"Blocking", &config_parse_bool, offsetof(unit_mnt_t, blocking), "true"}, 44 48 CONFIGURATION_ITEM_SENTINEL 45 49 }; 46 50 51 typedef struct { 52 char *type; 53 char *mountpoint; 54 char *device; 55 char *options; 56 unsigned int flags; 57 unsigned int instance; 58 59 unit_t *unit; 60 bool owner; 61 } mount_data_t; 62 63 static void mount_data_destroy(mount_data_t **mnt_data_ptr) 64 { 65 assert(mnt_data_ptr); 66 if (*mnt_data_ptr == NULL) { 67 return; 68 } 69 70 mount_data_t *mnt_data = *mnt_data_ptr; 71 free(mnt_data->type); 72 free(mnt_data->mountpoint); 73 free(mnt_data->device); 74 free(mnt_data->options); 75 76 free(mnt_data); 77 *mnt_data_ptr = NULL; 78 } 79 80 static bool mount_data_copy(mount_data_t *src, mount_data_t **dst_ptr) 81 { 82 mount_data_t *dst = malloc(sizeof(mount_data_t)); 83 if (dst == NULL) { 84 goto fail; 85 } 86 87 dst->type = str_dup(src->type); 88 if (dst->type == NULL) 89 goto fail; 90 91 dst->mountpoint = str_dup(src->mountpoint); 92 if (dst->mountpoint == NULL) 93 goto fail; 94 95 dst->device = str_dup(src->device); 96 if (dst->device == NULL) 97 goto fail; 98 99 dst->options = src->options ? str_dup(src->options) : NULL; 100 if (src->options != NULL && dst->options == NULL) 101 goto fail; 102 103 dst->flags = src->flags; 104 dst->instance = src->instance; 105 dst->unit = src->unit; 106 dst->owner = true; 107 108 *dst_ptr = dst; 109 return true; 110 111 fail: 112 mount_data_destroy(&dst); 113 return false; 114 } 115 47 116 static void unit_mnt_init(unit_t *unit) 48 117 { 49 118 unit_mnt_t *u_mnt = CAST_MNT(unit); 50 119 assert(u_mnt); 51 52 u_mnt->type = NULL;53 u_mnt->mountpoint = NULL;54 u_mnt->device = NULL;55 120 } 56 121 … … 60 125 unit_mnt_t *u_mnt = CAST_MNT(unit); 61 126 62 sysman_log(LVL_DEBUG2, "%s, %p, %p, %p", __func__,63 u_mnt->type, u_mnt->mountpoint, u_mnt->device);64 127 free(u_mnt->type); 65 128 free(u_mnt->mountpoint); … … 85 148 } 86 149 150 static int mount_exec(void *arg) 151 { 152 mount_data_t *mnt_data = arg; 153 /*sysman_log(LVL_DEBUG2, "%s(%p, %p, %p, %p, %x, %u)", 154 __func__, 155 mnt_data->type, mnt_data->mountpoint, mnt_data->device, mnt_data->options, 156 mnt_data->flags, mnt_data->instance);*/ 157 int rc = mount(mnt_data->type, mnt_data->mountpoint, mnt_data->device, 158 mnt_data->options ? mnt_data->options : "", 159 mnt_data->flags, mnt_data->instance); 160 161 if (rc == EOK) { 162 sysman_log(LVL_DEBUG, "Mount ('%s') mounted", 163 unit_name(mnt_data->unit)); 164 /* 165 * Emulate future VFS broker fibril that notifies about created 166 * exposee. 167 * Difference: It'll notify exposee name only, we'll have to 168 * match it... 169 */ 170 sysman_raise_event(&sysman_event_unit_exposee_created, 171 mnt_data->unit); 172 } else { 173 sysman_log(LVL_ERROR, "Mount ('%s') failed (%i)", 174 unit_name(mnt_data->unit), rc); 175 /* 176 * Think about analogy of this event, probably timeout or sthing 177 */ 178 sysman_raise_event(&sysman_event_unit_failed, 179 mnt_data->unit); 180 } 181 182 if (mnt_data->owner) { 183 mount_data_destroy(&mnt_data); 184 } 185 186 return EOK; 187 } 188 87 189 static int unit_mnt_start(unit_t *unit) 88 190 { 89 // TODO replace with non-blocking90 const bool blocking = true;91 191 unit_mnt_t *u_mnt = CAST_MNT(unit); 92 192 assert(u_mnt); 193 /* autostart implies blocking */ 194 assert(!u_mnt->autostart || u_mnt->blocking); 93 195 94 196 … … 96 198 assert(unit->state == STATE_STOPPED); 97 199 98 99 // TODO use other mount parameters 100 int rc = mount(u_mnt->type, u_mnt->mountpoint, u_mnt->device, "", 101 blocking ? IPC_FLAG_BLOCKING : 0, 0); 102 103 if (blocking) { 104 if (rc == EOK) { 105 sysman_log(LVL_DEBUG, "Mount ('%s') mounted", unit_name(unit)); 106 unit->state = STATE_STARTED; 107 } else { 108 sysman_log(LVL_ERROR, "Mount ('%s') failed (%i)", 109 unit_name(unit), rc); 110 unit->state = STATE_FAILED; 200 mount_data_t mnt_data; 201 memset(&mnt_data, 0, sizeof(mnt_data)); 202 mnt_data.type = u_mnt->type; 203 mnt_data.mountpoint = u_mnt->mountpoint; 204 mnt_data.device = u_mnt->device; 205 /* TODO use other mount parameters 206 * mnt_data.options = u_mnt->options; 207 * mnt_data.instance = u_mnt->instance; 208 */ 209 210 mnt_data.flags |= u_mnt->blocking ? IPC_FLAG_BLOCKING : 0; 211 mnt_data.flags |= u_mnt->autostart ? IPC_FLAG_AUTOSTART : 0; 212 mnt_data.unit = unit; 213 214 if (u_mnt->blocking) { 215 mount_data_t *heap_mnt_data = NULL; 216 if (!mount_data_copy(&mnt_data, &heap_mnt_data)) { 217 return ENOMEM; 111 218 } 219 fid_t fib = fibril_create(&mount_exec, heap_mnt_data); 220 unit->state = STATE_STARTING; 221 fibril_add_ready(fib); 112 222 } else { 113 if (rc == EOK) { 114 sysman_log(LVL_DEBUG, "Mount ('%s') requested", unit_name(unit)); 115 unit->state = STATE_STARTING; 116 } else { 117 sysman_log(LVL_ERROR, "Mount ('%s') request failed (%i)", 118 unit_name(unit), rc); 119 unit->state = STATE_FAILED; 120 } 121 } 122 123 return rc; 124 } 223 unit->state = STATE_STARTING; 224 mount_exec(&mnt_data); 225 } 226 227 return EOK; 228 } 229 230 static void unit_mnt_exposee_created(unit_t *unit) 231 { 232 assert(CAST_MNT(unit)); 233 assert(unit->state == STATE_STOPPED || unit->state == STATE_STARTING); 234 235 unit->state = STATE_STARTED; 236 unit_notify_state(unit); 237 } 238 239 static void unit_mnt_fail(unit_t *unit) 240 { 241 assert(CAST_MNT(unit)); 242 assert(unit->state == STATE_STARTING); 243 244 unit->state = STATE_FAILED; 245 unit_notify_state(unit); 246 } 247 125 248 126 249 DEFINE_UNIT_VMT(unit_mnt) -
uspace/srv/sysman/units/unit_mnt.h
r2dda1d4 r5559712 38 38 char *mountpoint; 39 39 char *device; 40 41 /** Should be underlying units (FS server, device) be autostarted */ 42 bool autostart; 43 44 /** Should mount call be blocking */ 45 bool blocking; 40 46 } unit_mnt_t; 41 47 42 extern unit_vmt_t unit_mnt_ ops;48 extern unit_vmt_t unit_mnt_vmt; 43 49 44 50 #endif -
uspace/srv/sysman/units/unit_tgt.c
r2dda1d4 r5559712 63 63 } 64 64 65 static void unit_tgt_exposee_created(unit_t *unit) 66 { 67 /* Target has no exposees. */ 68 assert(false); 69 } 70 71 static void unit_tgt_fail(unit_t *unit) 72 { 73 // TODO define semantics and implement 74 } 75 76 65 77 DEFINE_UNIT_VMT(unit_tgt) 66 78 -
uspace/srv/sysman/units/unit_tgt.h
r2dda1d4 r5559712 36 36 } unit_tgt_t; 37 37 38 extern unit_vmt_t unit_tgt_ ops;38 extern unit_vmt_t unit_tgt_vmt; 39 39 40 40 #endif
Note:
See TracChangeset
for help on using the changeset viewer.