Skip to content

Commit

Permalink
nbd: add auto mount options
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanHai authored and ilixiaocui committed Jul 8, 2021
1 parent 7800ea6 commit 34734ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions nbd/nbd-package/etc/curve/curvetab
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
# this file record the correspondence of curve nbd images/ devices
# add record when 'curve-nbd map' and 'curve-nbd unmap'
#
# format: device image mount
# /dev/nbd0 cbd:pool//curvefile_test_ /curve
# format: device image mount options
# /dev/nbd0 cbd:pool//curvefile_test_ /curve -o discard
21 changes: 11 additions & 10 deletions nbd/nbd-package/usr/bin/map_curve_disk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ fi
function usage() {
echo "Usage: ./map_curve_disk.sh start"
echo " -c/--confPath: set the confPath (default /etc/curve/curvetab)"
echo " file format is:dealflag \t device \t image \t mountpoint(option)"
echo " example: + /dev/nbd0 cbd:pool//curvefile_test_ /test"
echo " file format is:dealflag \t device \t image \t mountpoint(optional) \t mountoption(optional)"
echo " example: + /dev/nbd0 cbd:pool//curvefile_test_ /test -t ext4 -o discard"
echo " -h/--help: get the script usage"
echo "Examples:"
echo " ./map_curve_disk.sh start //use the default configuration"
Expand All @@ -45,8 +45,8 @@ function dealcurvetab() {
declare -A recordmap
while read line
do
flag=$(echo $line | awk '{print $1}')
device=$(echo $line | awk '{print $2}')
flag=$(echo "$line" | awk '{print $1}')
device=$(echo "$line" | awk '{print $2}')
if [ "$flag" = "+" ]
then
recordmap["$device"]=$line
Expand All @@ -56,7 +56,7 @@ function dealcurvetab() {
fi
done < ${confPath}
for key in ${!recordmap[@]}; do
echo ${recordmap[$key]} >> ${confPath}.bak
echo "${recordmap[$key]}" >> ${confPath}.bak
done
}

Expand All @@ -70,13 +70,14 @@ function map() {

cat ${confPath}.bak | grep -v '#' | while read line
do
device=$(echo $line | awk '{print $2}')
image=$(echo $line | awk '{print $3}')
mount=$(echo $line | awk '{print $4}')
device=$(echo "$line" | awk -F'\t' '{print $2}')
image=$(echo "$line" | awk -F'\t' '{print $3}')
mountpoint=$(echo "$line" | awk -F'\t' '{print $4}')
option=$(echo "$line" | awk -F'\t' '{print $5}')
curve-nbd map $image --device $device
if [ "$mount" != "" ]
if [ "$mountpoint" != "" ]
then
mount $device $mount
mount $option $device $mountpoint
fi
done
mv ${confPath}.bak ${confPath}
Expand Down

0 comments on commit 34734ec

Please sign in to comment.