Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/freebsd/poudriere.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/share
diff options
context:
space:
mode:
authorBryan Drewery <bryan@shatow.net>2014-04-04 16:43:11 +0400
committerBryan Drewery <bryan@shatow.net>2014-04-04 16:43:11 +0400
commit7124fbd9307042c8e91f0887bc6c1d427cda130b (patch)
treebb831cae533569cbd826b1fa57577453f15e86ba /src/share
parent720599f65de2b178977378f876bfe76015e075d5 (diff)
Move file system handling to fs.sh
Diffstat (limited to 'src/share')
-rwxr-xr-xsrc/share/poudriere/common.sh147
-rw-r--r--src/share/poudriere/include/fs.sh170
2 files changed, 171 insertions, 146 deletions
diff --git a/src/share/poudriere/common.sh b/src/share/poudriere/common.sh
index ff4635e2..897b5173 100755
--- a/src/share/poudriere/common.sh
+++ b/src/share/poudriere/common.sh
@@ -559,74 +559,6 @@ fetch_file() {
fetch -p -o $1 $2 || fetch -p -o $1 $2 || err 1 "Failed to fetch from $2"
}
-createfs() {
- [ $# -ne 3 ] && eargs createfs name mnt fs
- local name mnt fs
- name=$1
- mnt=$(echo $2 | sed -e "s,//,/,g")
- fs=$3
-
- [ -z "${NO_ZFS}" ] || fs=none
-
- if [ -n "${fs}" -a "${fs}" != "none" ]; then
- msg_n "Creating ${name} fs..."
- zfs create -p \
- -o mountpoint=${mnt} ${fs} || err 1 " fail"
- echo " done"
- else
- mkdir -p ${mnt}
- fi
-}
-
-rollbackfs() {
- [ $# -ne 2 ] && eargs rollbackfs name mnt
- local name=$1
- local mnt=$2
- local fs=$(zfs_getfs ${mnt})
- local mtree_mnt
-
- if [ -n "${fs}" ]; then
- zfs rollback -r ${fs}@${name} || err 1 "Unable to rollback ${fs}"
- return
- fi
-
- if [ "${name}" = "prepkg" ]; then
- mtree_mnt="${MASTERMNT}"
- else
- mtree_mnt="${mnt}"
- fi
-
- cpdup -i0 -x ${MASTERMNT} ${mnt}
-}
-
-umountfs() {
- [ $# -lt 1 ] && eargs umountfs mnt childonly
- local mnt=$1
- local childonly=$2
- local pattern
-
- [ -n "${childonly}" ] && pattern="/"
-
- [ -d "${mnt}" ] || return 0
- mnt=$(realpath ${mnt})
- mount | sort -r -k 2 | while read dev on pt opts; do
- case ${pt} in
- ${mnt}${pattern}*)
- umount -f ${pt} || :
- [ "${dev#/dev/md*}" != "${dev}" ] && mdconfig -d -u ${dev#/dev/md*}
- ;;
- esac
- done
-
- return 0
-}
-
-zfs_getfs() {
- [ $# -ne 1 ] && eargs zfs_getfs mnt
- local mnt=$(realpath $1)
- mount -t zfs | awk -v n="${mnt}" ' $3 == n { print $1 }'
-}
-
unmarkfs() {
[ $# -ne 2 ] && eargs unmarkfs name mnt
local name=$1
@@ -756,64 +688,6 @@ EOF
echo " done"
}
-mnt_tmpfs() {
- [ $# -lt 2 ] && eargs mnt_tmpfs type dst
- local type="$1"
- local dst="$2"
- local limit size
-
- case ${type} in
- data)
- # Limit data to 1GiB
- limit=1
- ;;
-
- *)
- limit=${TMPFS_LIMIT}
- ;;
- esac
-
- [ -n "${limit}" ] && size="-o size=${limit}G"
-
- mount -t tmpfs ${size} tmpfs "${dst}"
-}
-
-clonefs() {
- [ $# -lt 2 ] && eargs clonefs from to snap
- local from=$1
- local to=$2
- local snap=$3
- local name zfs_to
- local fs=$(zfs_getfs ${from})
-
- destroyfs ${to} jail
- mkdir -p ${to}
- to=$(realpath ${to})
- [ ${TMPFS_ALL} -eq 1 ] && unset fs
- if [ -n "${fs}" ]; then
- name=${to##*/}
-
- if [ "${name}" = "ref" ]; then
- zfs_to=${fs%/*}/${MASTERNAME}-${name}
- else
- zfs_to=${fs}/${name}
- fi
-
- zfs clone -o mountpoint=${to} \
- -o sync=disabled \
- -o atime=off \
- -o compression=off \
- ${fs}@${snap} \
- ${zfs_to}
- else
- [ ${TMPFS_ALL} -eq 1 ] && mnt_tmpfs all ${to}
- # Mount /usr/src into target, no need for anything to write to it
- mkdir -p ${to}/usr/src
- ${NULLMOUNT} -o ro ${from}/usr/src ${to}/usr/src
- cpdup -x ${from} ${to}
- fi
-}
-
rm() {
local arg
@@ -825,26 +699,6 @@ rm() {
/bin/rm "$@"
}
-destroyfs() {
- [ $# -ne 2 ] && eargs destroyfs name type
- local mnt fs type
- mnt=$1
- type=$2
- [ -d ${mnt} ] || return 0
- mnt=$(realpath ${mnt})
- fs=$(zfs_getfs ${mnt})
- umountfs ${mnt} 1
- if [ ${TMPFS_ALL} -eq 1 ]; then
- umount -f ${mnt} 2>/dev/null || :
- elif [ -n "${fs}" -a "${fs}" != "none" ]; then
- zfs destroy -rf ${fs}
- rmdir ${mnt}
- else
- chflags -R noschg ${mnt}
- rm -rf ${mnt}
- fi
-}
-
do_jail_mounts() {
[ $# -ne 2 ] && eargs do_jail_mounts mnt arch
local mnt=$1
@@ -3745,3 +3599,4 @@ fi
. $(dirname ${0})/include/parallel.sh
. $(dirname ${0})/include/hash.sh
+. $(dirname ${0})/include/fs.sh
diff --git a/src/share/poudriere/include/fs.sh b/src/share/poudriere/include/fs.sh
new file mode 100644
index 00000000..c4716551
--- /dev/null
+++ b/src/share/poudriere/include/fs.sh
@@ -0,0 +1,170 @@
+# Copyright (c) 2010-2013 Baptiste Daroussin <bapt@FreeBSD.org>
+# Copyright (c) 2012-2014 Bryan Drewery <bdrewery@FreeBSD.org>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+
+createfs() {
+ [ $# -ne 3 ] && eargs createfs name mnt fs
+ local name mnt fs
+ name=$1
+ mnt=$(echo $2 | sed -e "s,//,/,g")
+ fs=$3
+
+ [ -z "${NO_ZFS}" ] || fs=none
+
+ if [ -n "${fs}" -a "${fs}" != "none" ]; then
+ msg_n "Creating ${name} fs..."
+ zfs create -p \
+ -o mountpoint=${mnt} ${fs} || err 1 " fail"
+ echo " done"
+ else
+ mkdir -p ${mnt}
+ fi
+}
+
+rollbackfs() {
+ [ $# -ne 2 ] && eargs rollbackfs name mnt
+ local name=$1
+ local mnt=$2
+ local fs=$(zfs_getfs ${mnt})
+ local mtree_mnt
+
+ if [ -n "${fs}" ]; then
+ zfs rollback -r ${fs}@${name} || err 1 "Unable to rollback ${fs}"
+ return
+ fi
+
+ if [ "${name}" = "prepkg" ]; then
+ mtree_mnt="${MASTERMNT}"
+ else
+ mtree_mnt="${mnt}"
+ fi
+
+ cpdup -i0 -x ${MASTERMNT} ${mnt}
+}
+
+umountfs() {
+ [ $# -lt 1 ] && eargs umountfs mnt childonly
+ local mnt=$1
+ local childonly=$2
+ local pattern
+
+ [ -n "${childonly}" ] && pattern="/"
+
+ [ -d "${mnt}" ] || return 0
+ mnt=$(realpath ${mnt})
+ mount | sort -r -k 2 | while read dev on pt opts; do
+ case ${pt} in
+ ${mnt}${pattern}*)
+ umount -f ${pt} || :
+ [ "${dev#/dev/md*}" != "${dev}" ] && mdconfig -d -u ${dev#/dev/md*}
+ ;;
+ esac
+ done
+
+ return 0
+}
+
+zfs_getfs() {
+ [ $# -ne 1 ] && eargs zfs_getfs mnt
+ local mnt=$(realpath $1)
+ mount -t zfs | awk -v n="${mnt}" ' $3 == n { print $1 }'
+}
+
+mnt_tmpfs() {
+ [ $# -lt 2 ] && eargs mnt_tmpfs type dst
+ local type="$1"
+ local dst="$2"
+ local limit size
+
+ case ${type} in
+ data)
+ # Limit data to 1GiB
+ limit=1
+ ;;
+
+ *)
+ limit=${TMPFS_LIMIT}
+ ;;
+ esac
+
+ [ -n "${limit}" ] && size="-o size=${limit}G"
+
+ mount -t tmpfs ${size} tmpfs "${dst}"
+}
+
+clonefs() {
+ [ $# -lt 2 ] && eargs clonefs from to snap
+ local from=$1
+ local to=$2
+ local snap=$3
+ local name zfs_to
+ local fs=$(zfs_getfs ${from})
+
+ destroyfs ${to} jail
+ mkdir -p ${to}
+ to=$(realpath ${to})
+ [ ${TMPFS_ALL} -eq 1 ] && unset fs
+ if [ -n "${fs}" ]; then
+ name=${to##*/}
+
+ if [ "${name}" = "ref" ]; then
+ zfs_to=${fs%/*}/${MASTERNAME}-${name}
+ else
+ zfs_to=${fs}/${name}
+ fi
+
+ zfs clone -o mountpoint=${to} \
+ -o sync=disabled \
+ -o atime=off \
+ -o compression=off \
+ ${fs}@${snap} \
+ ${zfs_to}
+ else
+ [ ${TMPFS_ALL} -eq 1 ] && mnt_tmpfs all ${to}
+ # Mount /usr/src into target, no need for anything to write to it
+ mkdir -p ${to}/usr/src
+ ${NULLMOUNT} -o ro ${from}/usr/src ${to}/usr/src
+ cpdup -x ${from} ${to}
+ fi
+}
+
+destroyfs() {
+ [ $# -ne 2 ] && eargs destroyfs name type
+ local mnt fs type
+ mnt=$1
+ type=$2
+ [ -d ${mnt} ] || return 0
+ mnt=$(realpath ${mnt})
+ fs=$(zfs_getfs ${mnt})
+ umountfs ${mnt} 1
+ if [ ${TMPFS_ALL} -eq 1 ]; then
+ umount -f ${mnt} 2>/dev/null || :
+ elif [ -n "${fs}" -a "${fs}" != "none" ]; then
+ zfs destroy -rf ${fs}
+ rmdir ${mnt}
+ else
+ chflags -R noschg ${mnt}
+ rm -rf ${mnt}
+ fi
+}