Changeset 64ffd83 in mainline for uspace/srv/volsrv/part.c


Ignore:
Timestamp:
2018-07-24T09:43:38Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
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)
Message:

Configuring mount point for (newly created) paritions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/volsrv/part.c

    r05208d9 r64ffd83  
    4545#include <str_error.h>
    4646#include <vfs/vfs.h>
     47#include <vol.h>
    4748
    4849#include "empty.h"
     
    5051#include "part.h"
    5152#include "types/part.h"
     53#include "volume.h"
    5254
    5355static errno_t vol_part_add_locked(vol_parts_t *, service_id_t);
     
    191193                return;
    192194
     195        if (part->volume != NULL)
     196                vol_volume_del_ref(part->volume);
     197
    193198        free(part->cur_mp);
    194199        free(part->svc_name);
     
    202207        struct fsname_type *fst;
    203208        char *label;
     209        vol_volume_t *volume;
    204210        errno_t rc;
    205211
     
    250256        }
    251257
     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;
    252264        return EOK;
    253265
     
    275287}
    276288
     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 */
     294static 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 */
    277303static errno_t vol_part_mount(vol_part_t *part)
    278304{
     305        const char *cfg_mp;
    279306        char *mp;
    280307        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.");
    286349                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;
    309353        }
    310354
     
    319363
    320364        part->cur_mp = mp;
    321         part->cur_mp_auto = true;
     365        part->cur_mp_auto = mp_auto;
    322366
    323367        return rc;
     
    385429}
    386430
    387 errno_t vol_part_add(vol_parts_t *parts, service_id_t sid)
     431errno_t vol_part_add_part(vol_parts_t *parts, service_id_t sid)
    388432{
    389433        errno_t rc;
     
    403447}
    404448
    405 errno_t vol_parts_create(vol_parts_t **rparts)
     449errno_t vol_parts_create(vol_volumes_t *volumes, vol_parts_t **rparts)
    406450{
    407451        vol_parts_t *parts;
     
    413457        fibril_mutex_initialize(&parts->lock);
    414458        list_initialize(&parts->parts);
     459        parts->volumes = volumes;
    415460
    416461        *rparts = parts;
     
    557602}
    558603
     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 */
     612static 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
    559637errno_t vol_part_mkfs_part(vol_part_t *part, vol_fstype_t fstype,
    560     const char *label)
     638    const char *label, const char *mountp)
    561639{
    562640        errno_t rc;
     
    585663        }
    586664
     665        rc = vol_part_mountp_set(part, mountp);
     666        if (rc != EOK) {
     667                fibril_mutex_unlock(&part->parts->lock);
     668                return rc;
     669        }
     670
    587671        rc = vol_part_mount(part);
    588672        if (rc != EOK) {
Note: See TracChangeset for help on using the changeset viewer.