[PC-BSD Commits] r21496 - pcbsd/branches/9.1/src-sh/warden/scripts/backend

svn at pcbsd.org svn at pcbsd.org
Thu Feb 14 11:04:20 PST 2013


Author: kris
Date: 2013-02-14 19:04:20 +0000 (Thu, 14 Feb 2013)
New Revision: 21496

Modified:
   pcbsd/branches/9.1/src-sh/warden/scripts/backend/createjail.sh
   pcbsd/branches/9.1/src-sh/warden/scripts/backend/functions.sh
Log:

Backport the other ZFS fixes to warden / 9.1



Modified: pcbsd/branches/9.1/src-sh/warden/scripts/backend/createjail.sh
===================================================================
--- pcbsd/branches/9.1/src-sh/warden/scripts/backend/createjail.sh	2013-02-14 19:01:17 UTC (rev 21495)
+++ pcbsd/branches/9.1/src-sh/warden/scripts/backend/createjail.sh	2013-02-14 19:04:20 UTC (rev 21496)
@@ -9,14 +9,8 @@
 . ${PROGDIR}/scripts/backend/functions.sh
 
 # Location of the chroot environment
-isDirZFS "${JDIR}"
-if [ $? -eq 0 ] ; then
-  WORLDCHROOT="${JDIR}/.warden-chroot-${ARCH}"
-  export WORLDCHROOT
-else
-  WORLDCHROOT="${JDIR}/.warden-chroot-${ARCH}.txz"
-  export WORLDCHROOT
-fi
+WORLDCHROOT="${JDIR}/.warden-chroot-${ARCH}"
+export WORLDCHROOT
 
 setup_linux_jail()
 {
@@ -89,6 +83,7 @@
 # See if we are overriding the default archive file
 if [ ! -z "$ARCHIVEFILE" ] ; then
    WORLDCHROOT="$ARCHIVEFILE"
+   export WORLDCHROOT
 fi
 
 if [ -z "$IP" -o -z "${HOST}" -o -z "$SOURCE" -o -z "${PORTS}" -o -z "${STARTUP}" ] 
@@ -126,7 +121,16 @@
    if [ $? -eq 0 ] ; then
      # Create ZFS mount
      tank=`getZFSTank "$JDIR"`
-     zfs create -o mountpoint=${JAILDIR} -p ${tank}${JAILDIR}
+     # Check the mount-point for this tank
+     zMnt=`getZFSMount "$tank"`
+     if [ zMnt = "/" ] ; then
+        zfs create -o mountpoint=${JAILDIR} -p ${tank}${JAILDIR}
+        if [ $? -ne 0 ] ; then exit_err "Failed creating ZFS dataset"; fi
+     else
+        tMnt=`echo $JAILDIR | sed "s|^${zMnt}||g"`
+        zfs create -o mountpoint=${JAILDIR} -p ${tank}${tMnt}
+        if [ $? -ne 0 ] ; then exit_err "Failed creating ZFS dataset"; fi
+     fi
    else
      mkdir -p "${JAILDIR}"
    fi
@@ -140,13 +144,26 @@
 if [ $? -eq 0 ] ; then
    # Create ZFS CLONE
    tank=`getZFSTank "$JDIR"`
-   zfs clone ${tank}${WORLDCHROOT}@clean ${tank}${JAILDIR}
-   if [ $? -ne 0 ] ; then exit_err "Failed creating clean ZFS base clone"; fi
+   # Check the mount-point for this tank
+   zMnt=`getZFSMount "$tank"`
+   if [ zMnt = "/" ] ; then
+      zfs clone ${tank}${WORLDCHROOT}@clean ${tank}${JAILDIR}
+      if [ $? -ne 0 ] ; then exit_err "Failed creating clean ZFS base clone"; fi
+    else
+      tMnt=`echo $JAILDIR | sed "s|^${zMnt}||g"`
+      crDir=`echo $WORLDCHROOT | sed "s|^${zMnt}||g"`
+      zfs clone ${tank}${crDir}@clean ${tank}${tMnt}
+      if [ $? -ne 0 ] ; then exit_err "Failed creating clean ZFS base clone"; fi
+    fi
 else
    # Running on UFS
    mkdir -p "${JAILDIR}"
    echo "Installing world..."
-   tar xvf ${WORLDCHROOT} -C "${JAILDIR}" 2>/dev/null
+   if [ -d "${WORLDCHROOT}" ] ; then
+     tar cvf - -C ${WORLDCHROOT} . 2>/dev/null | tar xpvf - -C "${JAILDIR}" 2>/dev/null
+   else
+     tar xvf ${WORLDCHROOT} -C "${JAILDIR}" 2>/dev/null
+   fi
    echo "Done"
 fi
 
@@ -225,6 +242,11 @@
   touch "${JMETADIR}/autostart"
 fi
 
+# Check if we need to copy the timezone file
+if [ -e "/etc/localtime" ] ; then
+   cp /etc/localtime ${JDIR}/${IP}/etc/localtime
+fi
+
 # Set the default meta-pkg set
 mkdir -p ${JDIR}/${IP}/usr/local/etc >/dev/null 2>/dev/null
 echo "PCBSD_METAPKGSET: warden" > ${JDIR}/${IP}/usr/local/etc/pcbsd.conf

Modified: pcbsd/branches/9.1/src-sh/warden/scripts/backend/functions.sh
===================================================================
--- pcbsd/branches/9.1/src-sh/warden/scripts/backend/functions.sh	2013-02-14 19:01:17 UTC (rev 21495)
+++ pcbsd/branches/9.1/src-sh/warden/scripts/backend/functions.sh	2013-02-14 19:04:20 UTC (rev 21496)
@@ -49,10 +49,13 @@
 ### Download the chroot
 downloadchroot() {
 
-  SYSVER="$(pbreg get /PC-BSD/Version)"
-  FBSD_TARBALL="fbsd-release.txz"
-  FBSD_TARBALL_CKSUM="${FBSD_TARBALL}.md5"
+  SYSVER="$(uname -r)"
 
+  local dFiles="base.txz doc.txz games.txz"
+  if [ "$ARCH" = "amd64" ] ; then
+     dFiles="$dFiles lib32.txz"
+  fi
+
   # Set the mirror URL, may be overridden by setting MIRRORURL environment variable
   if [ -z "${MIRRORURL}" ]; then
     get_mirror
@@ -63,40 +66,49 @@
   cd ${JDIR}
 
   echo "Fetching jail environment. This may take a while..."
-  echo "Downloading ${MIRRORURL}/${SYSVER}/${ARCH}/netinstall/${FBSD_TARBALL} ..."
+  for i in $dFiles
+  do
+    echo "Downloading ${MIRRORURL}/${SYSVER}/${ARCH}/dist/${i} ..."
 
-  get_file "${MIRRORURL}/${SYSVER}/${ARCH}/netinstall/${FBSD_TARBALL}" "$FBSD_TARBALL" 3
-  [ $? -ne 0 ] && printerror "Error while downloading the portsjail."
+    get_file "${MIRRORURL}/${SYSVER}/${ARCH}/dist/${i}" "$i" 3
+    [ $? -ne 0 ] && printerror "Error while downloading the freebsd world."
+  done
 
-  get_file "${MIRRORURL}/${SYSVER}/${ARCH}/netinstall/${FBSD_TARBALL_CKSUM}" "$FBSD_TARBALL_CKSUM" 3
-  [ $? -ne 0 ] && printerror "Error while downloading the portsjail."
 
-  [ "$(md5 -q ${FBSD_TARBALL})" != "$(cat ${FBSD_TARBALL_CKSUM})" ] &&
-    printerror "Error in download data, checksum mismatch. Please try again later."
-
   # Creating ZFS dataset?
-  isDirZFS "${JDIR}"
+  isDirZFS "${JDIR}" "1"
   if [ $? -eq 0 ] ; then
     # Use ZFS base for cloning
     echo "Creating ZFS ${WORLDCHROOT} dataset..."
     tank=`getZFSTank "$JDIR"`
     isDirZFS "${WORLDCHROOT}" "1"
     if [ $? -ne 0 ] ; then
-       zfs create -o mountpoint=${WORLDCHROOT} -p ${tank}${WORLDCHROOT}
+       # Check the mount-point for this tank
+       zData=`getZFSDataset "$JDIR"`
+       if [ -z "$zData" ] ; then 
+          exit_err "Failed getting ZFS dataset for $JDIR.."; 
+       fi
+       zfs create -o mountpoint=${WORLDCHROOT} -p ${zData}/`basename ${WORLDCHROOT}`
        if [ $? -ne 0 ] ; then exit_err "Failed creating ZFS base dataset"; fi
     fi
+  else
+    mkdir ${WORLDCHROOT}
+  fi
 
-    tar xvpf ${FBSD_TARBALL} -C ${WORLDCHROOT} 2>/dev/null
-    if [ $? -ne 0 ] ; then exit_err "Failed extracting ZFS chroot environment"; fi
+  # Extract dist files
+  for i in $dFiles
+  do
+    tar xvpf ${i} -C ${WORLDCHROOT} 2>/dev/null
+    if [ $? -ne 0 ] ; then exit_err "Failed extracting freebsd environment"; fi
+    rm ${i}
+  done
 
-    zfs snapshot ${tank}${WORLDCHROOT}@clean
+  # Create ZFS clean snapshot
+  isDirZFS "${JDIR}"
+  if [ $? -eq 0 ] ; then
+    zfs snapshot ${zData}/`basename $WORLDCHROOT`@clean
     if [ $? -ne 0 ] ; then exit_err "Failed creating clean ZFS base snapshot"; fi
-    rm ${FBSD_TARBALL}
-  else
-    # Save the chroot tarball
-    mv ${FBSD_TARBALL} ${WORLDCHROOT}
   fi
-  rm ${FBSD_TARBALL_CKSUM}
 };
 
 
@@ -195,49 +207,77 @@
 mkZFSSnap() {
   isDirZFS "${1}" "1"
   if [ $? -ne 0 ] ; then printerror "Not a ZFS volume: ${1}" ; fi
-  tank=`getZFSTank "$1"`
   zdate=`date +%Y-%m-%d-%H-%M-%S`
-  zfs snapshot $tank${1}@$zdate
+  # Check the mount-point for this tank
+  zData=`getZFSDataset "$1"`
+  if [ -z "$zData" ] ; then
+     exit_err "Failed getting ZFS dataset for $1..";
+  fi
+  zfs snapshot ${zData}@$zdate
+  if [ $? -ne 0 ] ; then exit_err "Failed snapshot of dataset: $1"; fi
 }
 
 listZFSSnap() {
   isDirZFS "${1}" "1"
   if [ $? -ne 0 ] ; then printerror "Not a ZFS volume: ${1}" ; fi
-  tank=`getZFSTank "$1"`
-  zfs list -t snapshot | grep -w "^${tank}${1}" | cut -d '@' -f 2 | awk '{print $1}'
+  # Check the mount-point for this tank
+  zData=`getZFSDataset "$1"`
+  if [ -z "$zData" ] ; then
+     exit_err "Failed getting ZFS dataset for $1..";
+  fi
+  zfs list -t snapshot | grep -w "^${zData}" | cut -d '@' -f 2 | awk '{print $1}'
 }
 
 listZFSClone() {
   isDirZFS "${1}" "1"
   if [ $? -ne 0 ] ; then printerror "Not a ZFS volume: ${1}" ; fi
-  tank=`getZFSTank "$1"`
   echo "Clone Directory: ${CDIR}"
   echo "-----------------------------------"
-  zfs list | grep -w "^${tank}${CDIR}/${2}" | awk '{print $5}' | sed "s|${CDIR}/${2}-||g"
+  # Check the mount-point for this tank
+  zData=`getZFSDataset "$CDIR"`
+  if [ -z "$zData" ] ; then
+     exit_err "Failed getting ZFS dataset for $CDIR..";
+  fi
+  zfs list | grep -w "^${zData}/${2}" | awk '{print $5}' | sed "s|${CDIR}/${2}-||g"
 }
 
 rmZFSClone() {
   CLONEDIR="${CDIR}/${3}-${2}"
   isDirZFS "${CLONEDIR}" "1"
   if [ $? -ne 0 ] ; then printerror "Not a ZFS volume: ${CLONEDIR}" ; fi
-  tank=`getZFSTank "$2"`
-  zfs destroy ${tank}${CLONEDIR}
+  # Check the mount-point for this tank
+  zData=`getZFSDataset "$CLONEDIR"`
+  if [ -z "$zData" ] ; then
+     exit_err "Failed getting ZFS dataset for $CLONEDIR..";
+  fi
+  zfs destroy ${zData}
+  if [ $? -ne 0 ] ; then exit_err "Failed removing: $CLONEDIR"; fi
 }
 
 rmZFSSnap() {
   isDirZFS "${1}" "1"
   if [ $? -ne 0 ] ; then printerror "Not a ZFS volume: ${1}" ; fi
   tank=`getZFSTank "$1"`
-  zfs destroy $tank${1}@$2
+  # Check the mount-point for this tank
+  zData=`getZFSDataset "$1"`
+  if [ -z "$zData" ] ; then
+     exit_err "Failed getting ZFS dataset for $1..";
+  fi
+  zfs destroy ${zData}@$2
+  if [ $? -ne 0 ] ; then exit_err "Failed removing: ${1}@${2}"; fi
 }
 
 revertZFSSnap() {
   isDirZFS "${1}" "1"
   if [ $? -ne 0 ] ; then printerror "Not a ZFS volume: ${1}" ; fi
-  tank=`getZFSTank "$1"`
+  # Check the mount-point for this tank
+  zData=`getZFSDataset "$1"`
+  if [ -z "$zData" ] ; then
+     exit_err "Failed getting ZFS dataset for $1..";
+  fi
 
   # Make sure this is a valid snapshot
-  zfs list -t snapshot | grep -w "^${tank}${1}" | cut -d '@' -f 2 | awk '{print $1}' | grep -q ${2}
+  zfs list -t snapshot | grep -w "^${zData}" | cut -d '@' -f 2 | awk '{print $1}' | grep -q ${2}
   if [ $? -ne 0 ] ; then printerror "Invalid ZFS snapshot!" ; fi
 
   # Check if the jail is running first
@@ -253,7 +293,8 @@
   fi
 
   # Rollback the snapshot
-  zfs rollback -R -f ${tank}${1}@$2
+  zfs rollback -R -f ${zData}@$2
+  if [ $? -ne 0 ] ; then exit_err "Failed rollback: ${zData}@${2}"; fi
 
   # If it was started, restart the jail now
   if [ "$restartJail" = "YES" ]; then
@@ -265,10 +306,18 @@
 cloneZFSSnap() {
   isDirZFS "${1}" "1"
   if [ $? -ne 0 ] ; then printerror "Not a ZFS volume: ${1}" ; fi
-  tank=`getZFSTank "$1"`
+  # Check the mount-point for this tank
+  zData=`getZFSDataset "$1"`
+  if [ -z "$zData" ] ; then
+     exit_err "Failed getting ZFS dataset for $1..";
+  fi
+  zDataJ=`getZFSDataset "$JDIR"`
+  if [ -z "$zDataJ" ] ; then
+     exit_err "Failed getting ZFS dataset for $JDIR..";
+  fi
 
   # Make sure this is a valid snapshot
-  zfs list -t snapshot | grep -w "^${tank}${1}" | cut -d '@' -f 2 | awk '{print $1}' | grep -q ${2}
+  zfs list -t snapshot | grep -w "^${zData}" | cut -d '@' -f 2 | awk '{print $1}' | grep -q ${2}
   if [ $? -ne 0 ] ; then printerror "Invalid ZFS snapshot!" ; fi
 
   if [ -d "${CDIR}/${3}-${2}" ] ; then
@@ -276,7 +325,7 @@
   fi
 
   # Clone the snapshot
-  zfs clone -p ${tank}${1}@$2 ${tank}${CDIR}/${3}-${2}
+  zfs clone -p ${zData}@$2 ${zDataJ}/`basename $CDIR`/${3}-${2}
 
   echo "Snapshot cloned and mounted to: ${CDIR}/${3}-${2}"
 }



More information about the Commits mailing list