Changeset 5559712 in mainline for uspace/srv/sysman/units/unit_mnt.c
- Timestamp:
- 2019-08-03T09:28:50Z (5 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)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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)
Note:
See TracChangeset
for help on using the changeset viewer.