Changeset 64ffd83 in mainline for uspace/srv
- Timestamp:
- 2018-07-24T09:43:38Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bec18a9
- Parents:
- 05208d9
- git-author:
- Jiri Svoboda <jiri@…> (2018-07-23 18:41:45)
- git-committer:
- Jiri Svoboda <jiri@…> (2018-07-24 09:43:38)
- Location:
- uspace/srv/volsrv
- Files:
-
- 5 added
- 5 edited
-
Makefile (modified) (1 diff)
-
part.c (modified) (12 diffs)
-
part.h (modified) (2 diffs)
-
test/main.c (added)
-
test/volume.c (added)
-
types/part.h (modified) (2 diffs)
-
types/volume.h (added)
-
volsrv.c (modified) (7 diffs)
-
volume.c (added)
-
volume.h (added)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/volsrv/Makefile
r05208d9 r64ffd83 37 37 mkfs.c \ 38 38 part.c \ 39 volsrv.c 39 volsrv.c \ 40 volume.c 41 42 TEST_SOURCES = \ 43 volume.c \ 44 test/main.c \ 45 test/volume.c 40 46 41 47 include $(USPACE_PREFIX)/Makefile.common -
uspace/srv/volsrv/part.c
r05208d9 r64ffd83 45 45 #include <str_error.h> 46 46 #include <vfs/vfs.h> 47 #include <vol.h> 47 48 48 49 #include "empty.h" … … 50 51 #include "part.h" 51 52 #include "types/part.h" 53 #include "volume.h" 52 54 53 55 static errno_t vol_part_add_locked(vol_parts_t *, service_id_t); … … 191 193 return; 192 194 195 if (part->volume != NULL) 196 vol_volume_del_ref(part->volume); 197 193 198 free(part->cur_mp); 194 199 free(part->svc_name); … … 202 207 struct fsname_type *fst; 203 208 char *label; 209 vol_volume_t *volume; 204 210 errno_t rc; 205 211 … … 250 256 } 251 257 258 /* Look up new or existing volume. */ 259 rc = vol_volume_lookup_ref(part->parts->volumes, part->label, &volume); 260 if (rc != EOK) 261 goto error; 262 263 part->volume = volume; 252 264 return EOK; 253 265 … … 275 287 } 276 288 289 /** Determine the default mount point for a partition. 290 * 291 * @param part Partition 292 * @return Pointer to the constant string "Auto" or "None" 293 */ 294 static const char *vol_part_def_mountp(vol_part_t *part) 295 { 296 return vol_part_allow_mount_by_def(part) ? "Auto" : "None"; 297 } 298 299 /** Mount partition. 300 * 301 * @param part Partition 302 */ 277 303 static errno_t vol_part_mount(vol_part_t *part) 278 304 { 305 const char *cfg_mp; 279 306 char *mp; 280 307 int err; 281 errno_t rc; 282 283 if (str_size(part->label) < 1) { 284 /* Don't mount nameless volumes */ 285 log_msg(LOG_DEFAULT, LVL_NOTE, "Not mounting nameless partition."); 308 bool mp_auto; 309 errno_t rc; 310 311 /* Get configured mount point */ 312 if (str_size(part->volume->mountp) > 0) { 313 cfg_mp = part->volume->mountp; 314 log_msg(LOG_DEFAULT, LVL_NOTE, "Configured mount point '%s", 315 cfg_mp); 316 } else { 317 cfg_mp = vol_part_def_mountp(part); 318 log_msg(LOG_DEFAULT, LVL_NOTE, "Default mount point '%s", 319 cfg_mp); 320 } 321 322 if (str_cmp(cfg_mp, "Auto") == 0 || str_cmp(cfg_mp, "auto") == 0) { 323 324 if (str_size(part->label) < 1) { 325 /* Don't mount nameless volumes */ 326 log_msg(LOG_DEFAULT, LVL_NOTE, "Not mounting nameless volume."); 327 return EOK; 328 } 329 330 log_msg(LOG_DEFAULT, LVL_NOTE, "Determine MP label='%s'", part->label); 331 err = asprintf(&mp, "/vol/%s", part->label); 332 if (err < 0) { 333 log_msg(LOG_DEFAULT, LVL_ERROR, "Out of memory"); 334 return ENOMEM; 335 } 336 337 log_msg(LOG_DEFAULT, LVL_NOTE, "Create mount point '%s'", mp); 338 rc = vfs_link_path(mp, KIND_DIRECTORY, NULL); 339 if (rc != EOK) { 340 log_msg(LOG_DEFAULT, LVL_ERROR, "Error creating mount point '%s'", 341 mp); 342 free(mp); 343 return EIO; 344 } 345 346 mp_auto = true; 347 } else if (str_cmp(cfg_mp, "None") == 0 || str_cmp(cfg_mp, "none") == 0) { 348 log_msg(LOG_DEFAULT, LVL_NOTE, "Not mounting volume."); 286 349 return EOK; 287 } 288 289 if (!vol_part_allow_mount_by_def(part)) { 290 /* Don't mount partition by default */ 291 log_msg(LOG_DEFAULT, LVL_NOTE, "Not mounting per default policy."); 292 return EOK; 293 } 294 295 log_msg(LOG_DEFAULT, LVL_NOTE, "Determine MP label='%s'", part->label); 296 err = asprintf(&mp, "/vol/%s", part->label); 297 if (err < 0) { 298 log_msg(LOG_DEFAULT, LVL_ERROR, "Out of memory"); 299 return ENOMEM; 300 } 301 302 log_msg(LOG_DEFAULT, LVL_NOTE, "Create mount point '%s'", mp); 303 rc = vfs_link_path(mp, KIND_DIRECTORY, NULL); 304 if (rc != EOK) { 305 log_msg(LOG_DEFAULT, LVL_ERROR, "Error creating mount point '%s'", 306 mp); 307 free(mp); 308 return EIO; 350 } else { 351 mp = str_dup(cfg_mp); 352 mp_auto = false; 309 353 } 310 354 … … 319 363 320 364 part->cur_mp = mp; 321 part->cur_mp_auto = true;365 part->cur_mp_auto = mp_auto; 322 366 323 367 return rc; … … 385 429 } 386 430 387 errno_t vol_part_add (vol_parts_t *parts, service_id_t sid)431 errno_t vol_part_add_part(vol_parts_t *parts, service_id_t sid) 388 432 { 389 433 errno_t rc; … … 403 447 } 404 448 405 errno_t vol_parts_create(vol_ parts_t **rparts)449 errno_t vol_parts_create(vol_volumes_t *volumes, vol_parts_t **rparts) 406 450 { 407 451 vol_parts_t *parts; … … 413 457 fibril_mutex_initialize(&parts->lock); 414 458 list_initialize(&parts->parts); 459 parts->volumes = volumes; 415 460 416 461 *rparts = parts; … … 557 602 } 558 603 604 /** Set mount point. 605 * 606 * Verify and set a mount point. If the value of the mount point is 607 * the same as the default value, we will actually unset the mount point 608 * value (therefore effectively changing it to use the default). 609 * 610 * @return EOK on success, error code otherwise 611 */ 612 static errno_t vol_part_mountp_set(vol_part_t *part, const char *mountp) 613 { 614 errno_t rc; 615 const char *def_mp; 616 const char *mp; 617 618 rc = vol_mountp_validate(mountp); 619 if (rc != EOK) 620 return rc; 621 622 def_mp = vol_part_def_mountp(part); 623 624 /* If the value is the same as default, set to empty string. */ 625 if (str_cmp(def_mp, mountp) == 0) 626 mp = ""; 627 else 628 mp = mountp; 629 630 rc = vol_volume_set_mountp(part->volume, mp); 631 if (rc != EOK) 632 return rc; 633 634 return EOK; 635 } 636 559 637 errno_t vol_part_mkfs_part(vol_part_t *part, vol_fstype_t fstype, 560 const char *label )638 const char *label, const char *mountp) 561 639 { 562 640 errno_t rc; … … 585 663 } 586 664 665 rc = vol_part_mountp_set(part, mountp); 666 if (rc != EOK) { 667 fibril_mutex_unlock(&part->parts->lock); 668 return rc; 669 } 670 587 671 rc = vol_part_mount(part); 588 672 if (rc != EOK) { -
uspace/srv/volsrv/part.h
r05208d9 r64ffd83 42 42 #include <types/vol.h> 43 43 #include "types/part.h" 44 #include "types/volume.h" 44 45 45 extern errno_t vol_parts_create(vol_ parts_t **);46 extern errno_t vol_parts_create(vol_volumes_t *, vol_parts_t **); 46 47 extern void vol_parts_destroy(vol_parts_t *); 47 48 extern errno_t vol_part_discovery_start(vol_parts_t *); 48 extern errno_t vol_part_add (vol_parts_t *, service_id_t);49 extern errno_t vol_part_add_part(vol_parts_t *, service_id_t); 49 50 extern errno_t vol_part_get_ids(vol_parts_t *, service_id_t *, size_t, 50 51 size_t *); … … 54 55 extern errno_t vol_part_eject_part(vol_part_t *); 55 56 extern errno_t vol_part_empty_part(vol_part_t *); 56 extern errno_t vol_part_mkfs_part(vol_part_t *, vol_fstype_t, const char *); 57 extern errno_t vol_part_mkfs_part(vol_part_t *, vol_fstype_t, const char *, 58 const char *); 57 59 extern errno_t vol_part_get_info(vol_part_t *, vol_part_info_t *); 58 60 -
uspace/srv/volsrv/types/part.h
r05208d9 r64ffd83 66 66 /** Mounted at automatic mount point */ 67 67 bool cur_mp_auto; 68 /** Volume */ 69 struct vol_volume *volume; 68 70 } vol_part_t; 69 71 … … 74 76 /** Partitions (list of vol_part_t) */ 75 77 list_t parts; 78 /** Underlying volumes */ 79 struct vol_volumes *volumes; 76 80 } vol_parts_t; 77 81 -
uspace/srv/volsrv/volsrv.c
r05208d9 r64ffd83 49 49 #include "mkfs.h" 50 50 #include "part.h" 51 #include "volume.h" 51 52 52 53 #define NAME "volsrv" … … 57 58 { 58 59 errno_t rc; 60 vol_volumes_t *volumes = NULL; 59 61 vol_parts_t *parts = NULL; 60 62 61 63 log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_init()"); 62 64 63 rc = vol_parts_create(&parts); 65 rc = vol_volumes_create(&volumes); 66 if (rc != EOK) 67 goto error; 68 69 rc = vol_parts_create(volumes, &parts); 64 70 if (rc != EOK) 65 71 goto error; … … 87 93 return EOK; 88 94 error: 95 vol_volumes_destroy(volumes); 89 96 vol_parts_destroy(parts); 90 97 return rc; … … 131 138 sid = IPC_GET_ARG1(*icall); 132 139 133 rc = vol_part_add (parts, sid);140 rc = vol_part_add_part(parts, sid); 134 141 if (rc != EOK) { 135 142 async_answer_0(icall, rc); … … 285 292 vol_fstype_t fstype; 286 293 char *label; 294 char *mountp; 287 295 errno_t rc; 288 296 … … 304 312 } 305 313 314 rc = async_data_write_accept((void **)&mountp, true, 0, VOL_MOUNTP_MAXLEN, 315 0, NULL); 316 if (rc != EOK) { 317 free(label); 318 async_answer_0(icall, rc); 319 return; 320 } 321 322 if (mountp != NULL) { 323 log_msg(LOG_DEFAULT, LVL_NOTE, "vol_part_mkfs_srv: mountp='%s'", 324 mountp); 325 } 326 306 327 rc = vol_part_find_by_id_ref(parts, sid, &part); 307 328 if (rc != EOK) { … … 311 332 } 312 333 313 rc = vol_part_mkfs_part(part, fstype, label );334 rc = vol_part_mkfs_part(part, fstype, label, mountp); 314 335 if (rc != EOK) { 315 336 free(label);
Note:
See TracChangeset
for help on using the changeset viewer.
