Changeset b82985e in mainline for uspace/srv


Ignore:
Timestamp:
2018-10-12T13:16:04Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d09eeb2
Parents:
6d00aff
Message:

Inserting volume by path.

Location:
uspace/srv/volsrv
Files:
3 edited

Legend:

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

    r6d00aff rb82985e  
    297297}
    298298
    299 /** Mount partition.
     299/** Determine actual mount path to be used for a partition.
    300300 *
    301301 * @param part Partition
    302  */
    303 static errno_t vol_part_mount(vol_part_t *part)
     302 * @param rpath Place to store pointer to newly allocated string or @c NULL
     303 *              if volume should not be mounted
     304 * @param rauto Place to store boolean flag whether mount point is automatic
     305 *
     306 * @return EOK on success, ENOMEM if out of memory
     307 */
     308static errno_t vol_part_determine_mount_path(vol_part_t *part, char **rpath,
     309    bool *rauto)
    304310{
    305311        const char *cfg_mp;
    306312        char *mp;
     313        bool mp_auto;
    307314        int err;
    308         bool mp_auto;
    309         errno_t rc;
    310315
    311316        /* Get configured mount point */
     
    324329                if (str_size(part->label) < 1) {
    325330                        /* Don't mount nameless volumes */
    326                         log_msg(LOG_DEFAULT, LVL_NOTE, "Not mounting nameless volume.");
     331                        *rpath = NULL;
     332                        *rauto = false;
    327333                        return EOK;
    328334                }
     
    335341                }
    336342
     343                mp_auto = true;
     344        } else if (str_cmp(cfg_mp, "None") == 0 || str_cmp(cfg_mp, "none") == 0) {
     345                mp = NULL;
     346                mp_auto = false;
     347        } else {
     348                mp = str_dup(cfg_mp);
     349                mp_auto = false;
     350        }
     351
     352        *rpath = mp;
     353        *rauto = mp_auto;
     354        return EOK;
     355}
     356
     357/** Mount partition.
     358 *
     359 * @param part Partition
     360 */
     361static errno_t vol_part_mount(vol_part_t *part)
     362{
     363        char *mp;
     364        bool mp_auto;
     365        errno_t rc;
     366
     367        rc = vol_part_determine_mount_path(part, &mp, &mp_auto);
     368        if (rc != EOK) {
     369                log_msg(LOG_DEFAULT, LVL_ERROR, "Error determining mount point.\n");
     370                return rc;
     371        }
     372
     373        if (mp == NULL) {
     374                log_msg(LOG_DEFAULT, LVL_NOTE, "Not mounting volume.");
     375                return EOK;
     376        }
     377
     378        if (mp_auto) {
     379                /* Create directory for automatic mount point */
    337380                log_msg(LOG_DEFAULT, LVL_NOTE, "Create mount point '%s'", mp);
    338381                rc = vfs_link_path(mp, KIND_DIRECTORY, NULL);
     
    343386                        return EIO;
    344387                }
    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.");
    349                 return EOK;
    350         } else {
    351                 mp = str_dup(cfg_mp);
    352                 mp_auto = false;
    353388        }
    354389
     
    545580}
    546581
     582/** Find partition by filesystem path.
     583 *
     584 * @param parts Partitions
     585 * @param path Filesystem path
     586 * @param rpart Place to store pointer to partition
     587 * @return EOK on success, ENOENT if not found, ENOMEM if out of memory
     588 */
     589errno_t vol_part_find_by_path_ref(vol_parts_t *parts, const char *path,
     590    vol_part_t **rpart)
     591{
     592        errno_t rc;
     593        char *mpath;
     594        bool mauto;
     595
     596        fibril_mutex_lock(&parts->lock);
     597
     598        list_foreach(parts->parts, lparts, vol_part_t, part) {
     599                rc = vol_part_determine_mount_path(part, &mpath, &mauto);
     600                if (rc != EOK) {
     601                        fibril_mutex_unlock(&parts->lock);
     602                        return ENOMEM;
     603                }
     604
     605                if (mpath != NULL && str_cmp(mpath, path) == 0) {
     606                        /* Add reference */
     607                        refcount_up(&part->refcnt);
     608                        fibril_mutex_unlock(&parts->lock);
     609                        free(mpath);
     610                        *rpart = part;
     611                        return EOK;
     612                }
     613
     614                if (mpath != NULL)
     615                        free(mpath);
     616        }
     617
     618        fibril_mutex_unlock(&parts->lock);
     619        return ENOENT;
     620}
     621
    547622void vol_part_del_ref(vol_part_t *part)
    548623{
  • uspace/srv/volsrv/part.h

    r6d00aff rb82985e  
    5252extern errno_t vol_part_find_by_id_ref(vol_parts_t *, service_id_t,
    5353    vol_part_t **);
     54extern errno_t vol_part_find_by_path_ref(vol_parts_t *, const char *,
     55    vol_part_t **);
    5456extern void vol_part_del_ref(vol_part_t *);
    5557extern errno_t vol_part_eject_part(vol_part_t *);
  • uspace/srv/volsrv/volsrv.c

    r6d00aff rb82985e  
    250250}
    251251
     252static void vol_part_insert_by_path_srv(vol_parts_t *parts, ipc_call_t *icall)
     253{
     254        vol_part_t *part;
     255        char *path = NULL;
     256        errno_t rc;
     257
     258        log_msg(LOG_DEFAULT, LVL_NOTE, "vol_part_insert_by_path_srv()");
     259
     260        rc = async_data_write_accept((void **)&path, true, 0, VOL_MOUNTP_MAXLEN,
     261            0, NULL);
     262        if (rc != EOK) {
     263                async_answer_0(icall, rc);
     264                goto error;
     265        }
     266
     267        rc = vol_part_find_by_path_ref(parts, path, &part);
     268        if (rc != EOK) {
     269                async_answer_0(icall, ENOENT);
     270                goto error;
     271        }
     272
     273        rc = vol_part_insert_part(part);
     274        if (rc != EOK) {
     275                async_answer_0(icall, rc);
     276                vol_part_del_ref(part);
     277                goto error;
     278        }
     279
     280        free(path);
     281        vol_part_del_ref(part);
     282        async_answer_0(icall, EOK);
     283
     284        return;
     285error:
     286        if (path != NULL)
     287                free(path);
     288}
     289
     290
    252291static void vol_part_empty_srv(vol_parts_t *parts, ipc_call_t *icall)
    253292{
     
    545584                        vol_part_insert_srv(parts, &call);
    546585                        break;
     586                case VOL_PART_INSERT_BY_PATH:
     587                        vol_part_insert_by_path_srv(parts, &call);
     588                        break;
    547589                case VOL_PART_LSUPP:
    548590                        vol_part_get_lsupp_srv(parts, &call);
Note: See TracChangeset for help on using the changeset viewer.