Skip to content

Commit cd6a69c

Browse files
committed
allow user to specify the mount type of a cvmfs repo (fuse or bind)
1 parent ce4f213 commit cd6a69c

File tree

1 file changed

+45
-16
lines changed

1 file changed

+45
-16
lines changed

eessi_container.sh

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -756,14 +756,33 @@ for cvmfs_repo in "${REPOSITORIES[@]}"
756756
do
757757
unset cfg_repo_id
758758
[[ ${VERBOSE} -eq 1 ]] && echo "add fusemount options for CVMFS repo '${cvmfs_repo}'"
759-
# split into name and access mode if ',access=' in $cvmfs_repo
760-
if [[ ${cvmfs_repo} == *",access="* ]] ; then
761-
cvmfs_repo_name=${cvmfs_repo/,access=*/} # remove access mode specification
762-
cvmfs_repo_access=${cvmfs_repo/*,access=/} # remove repo name part
763-
else
764-
cvmfs_repo_name="${cvmfs_repo}"
765-
cvmfs_repo_access="${ACCESS}" # use globally defined access mode
759+
# split into name, access mode, and mount mode
760+
readarray -td, cvmfs_repo_args <<<"$cvmfs_repo"
761+
cvmfs_repo_name=${cvmfs_repo_args[0]}
762+
cvmfs_repo_access="${ACCESS}" # initialize to the default access mode
763+
for arg in ${cvmfs_repo_args[@]:1}; do
764+
if [[ $arg == "access="* ]]; then
765+
cvmfs_repo_access=${arg/access=}
766+
fi
767+
if [[ $arg == "mount="* ]]; then
768+
cvmfs_repo_mount=${arg/mount=}
769+
# check if the specified mount mode is a valid one
770+
if [[ ${cvmfs_repo_mount} != "bind" ]] && [[ ${cvmfs_repo_mount} != "fuse" ]]; then
771+
echo -e "ERROR: mount mode '${cvmfs_repo_mount}' for CVMFS repository\n '${cvmfs_repo_name}' is not known"
772+
exit ${REPOSITORY_ERROR_EXITCODE}
773+
fi
774+
fi
775+
done
776+
# if a mount mode was not specified, we use a bind mount if the repository is available on the host,
777+
# and otherwise we use a fuse mount
778+
if [[ -z ${cvmfs_repo_mount} ]]; then
779+
cvmfs_repo_mount="fuse"
780+
if [[ -x $(command -v cvmfs_config) ]] && cvmfs_config probe ${cvmfs_repo_name} >& /dev/null; then
781+
cvmfs_repo_mount="bind"
782+
fi
766783
fi
784+
[[ ${VERBOSE} -eq 1 ]] && echo "Using a ${cvmfs_repo_mount} mount for /cvmfs/${cvmfs_repo_name}"
785+
767786
# obtain cvmfs_repo_name from EESSI_REPOS_CFG_FILE if cvmfs_repo is in cfg_cvmfs_repos
768787
if [[ ${cfg_cvmfs_repos[${cvmfs_repo_name}]} ]]; then
769788
[[ ${VERBOSE} -eq 1 ]] && echo "repo '${cvmfs_repo_name}' is not an EESSI CVMFS repository..."
@@ -795,9 +814,12 @@ do
795814
echo " session. Will use it as left-most directory in 'lowerdir' argument for fuse-overlayfs."
796815

797816
# make the target CernVM-FS repository available under /cvmfs_ro
798-
export EESSI_READONLY="container:cvmfs2 ${cvmfs_repo_name} /cvmfs_ro/${cvmfs_repo_name}"
799-
800-
EESSI_FUSE_MOUNTS+=("--fusemount" "${EESSI_READONLY}")
817+
if [[ ${cvmfs_repo_mount} == "fuse" ]]; then
818+
export EESSI_READONLY="container:cvmfs2 ${cvmfs_repo_name} /cvmfs_ro/${cvmfs_repo_name}"
819+
EESSI_FUSE_MOUNTS+=("--fusemount" "${EESSI_READONLY}")
820+
elif [[ ${cvmfs_repo_mount} == "bind" ]]; then
821+
BIND_PATHS="/cvmfs/${cvmfs_repo_name}:/cvmfs_ro/${cvmfs_repo_name},${BIND_PATHS}"
822+
fi
801823

802824
# now, put the overlay-upper read-only on top of the repo and make it available under the usual prefix /cvmfs
803825
if [[ "${OVERLAY_TOOL}" == "fuse-overlayfs" ]]; then
@@ -827,10 +849,14 @@ do
827849
# basic "ro" access that doesn't require any fuseoverlay-fs
828850
echo "Mounting '${cvmfs_repo_name}' 'read-only' without fuse-overlayfs."
829851

830-
export EESSI_READONLY="container:cvmfs2 ${cvmfs_repo_name} /cvmfs/${cvmfs_repo_name}"
852+
if [[ ${cvmfs_repo_mount} == "fuse" ]]; then
853+
export EESSI_READONLY="container:cvmfs2 ${cvmfs_repo_name} /cvmfs/${cvmfs_repo_name}"
854+
EESSI_FUSE_MOUNTS+=("--fusemount" "${EESSI_READONLY}")
855+
export EESSI_FUSE_MOUNTS
856+
elif [[ ${cvmfs_repo_mount} == "bind" ]]; then
857+
BIND_PATHS="/cvmfs/${cvmfs_repo_name},${BIND_PATHS}"
858+
fi
831859

832-
EESSI_FUSE_MOUNTS+=("--fusemount" "${EESSI_READONLY}")
833-
export EESSI_FUSE_MOUNTS
834860
fi
835861
elif [[ ${cvmfs_repo_access} == "rw" ]] ; then
836862
# use repo-specific overlay directories
@@ -840,9 +866,12 @@ do
840866
[[ ${VERBOSE} -eq 1 ]] && echo -e "TMP directory contents:\n$(ls -l ${EESSI_TMPDIR})"
841867

842868
# set environment variables for fuse mounts in Singularity container
843-
export EESSI_READONLY="container:cvmfs2 ${cvmfs_repo_name} /cvmfs_ro/${cvmfs_repo_name}"
844-
845-
EESSI_FUSE_MOUNTS+=("--fusemount" "${EESSI_READONLY}")
869+
if [[ ${cvmfs_repo_mount} == "fuse" ]]; then
870+
export EESSI_READONLY="container:cvmfs2 ${cvmfs_repo_name} /cvmfs_ro/${cvmfs_repo_name}"
871+
EESSI_FUSE_MOUNTS+=("--fusemount" "${EESSI_READONLY}")
872+
elif [[ ${cvmfs_repo_mount} == "bind" ]]; then
873+
BIND_PATHS="/cvmfs/${cvmfs_repo_name}:/cvmfs_ro/${cvmfs_repo_name},${BIND_PATHS}"
874+
fi
846875

847876
if [[ "${OVERLAY_TOOL}" == "fuse-overlayfs" ]]; then
848877
EESSI_WRITABLE_OVERLAY="container:fuse-overlayfs"

0 commit comments

Comments
 (0)