Changeset 64ffd83 in mainline for uspace/srv/volsrv/part.c
- 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)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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) {
Note:
See TracChangeset
for help on using the changeset viewer.