Changeset 698a249


Ignore:
Timestamp:
07/16/14 08:31:42 (11 months ago)
Author:
Kris Moore <kris@…>
Branches:
master, enter/10, releng/10.0.3, releng/10.1, releng/10.1.1, releng/10.1.2
Children:
03eaf3af
Parents:
bb5d187
Message:

When using warden to create jails, do all ZFS ops relative to the
JAILDIR dataset, this will allow moving JAILDIR around, and fix
issues with odd dataset creation.

This fix implies that your JAILDIR is indeed a mounted ZFS dataset,
but we have assumed that for a while now anyway.

Location:
src-sh/warden/scripts/backend
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src-sh/warden/scripts/backend/createjail.sh

    r4905ba9 r698a249  
    184184# If we are setting up a linux jail, lets do it now 
    185185if [ "$LINUXJAIL" = "YES" ] ; then 
    186    # Create ZFS mount 
    187    tank=`getZFSTank "$JDIR"` 
    188    if [ -z "$tank" ] ; then 
    189      exit_err "Failed getting ZFS dataset for $JDIR.."; 
    190    fi 
    191    zfs create -o mountpoint=${JAILDIR} -p ${tank}${JAILDIR} 
     186   # Get the dataset of the jails mountpoint 
     187   rDataSet=`mount | grep "on ${JDIR} " | awk '{print $1}'` 
     188   tSubDir=`basename $JAILDIR` 
     189   nDataSet="${rDataSet}/${tSubDir}" 
     190 
     191   zfs create -p ${nDataSet} 
    192192   if [ $? -ne 0 ] ; then exit_err "Failed creating ZFS dataset"; fi 
    193193   setup_linux_jail 
     
    197197echo "Building new Jail... Please wait..." 
    198198 
     199 
     200# Get the dataset of the jails mountpoint 
     201rDataSet=`mount | grep "on ${JDIR} " | awk '{print $1}'` 
     202nSubDir=`basename $JAILDIR` 
     203nDataSet="${rDataSet}/${nSubDir}" 
     204oSubDir=`basename $WORLDCHROOT` 
     205oDataSet="${rDataSet}/${oSubDir}" 
     206 
    199207# Create ZFS CLONE 
    200 tank=`getZFSTank "$JDIR"` 
    201 zfsp=`getZFSRelativePath "${WORLDCHROOT}"` 
    202 jailp=`getZFSRelativePath "${JAILDIR}"` 
    203 zfs clone ${tank}${zfsp}@clean ${tank}${jailp} 
     208zfs clone ${oDataSet}@clean ${nDataSet} 
    204209if [ $? -ne 0 ] ; then exit_err "Failed creating clean ZFS base clone"; fi 
    205210 
  • src-sh/warden/scripts/backend/createtemplate.sh

    r4905ba9 r698a249  
    7878create_template() 
    7979{ 
    80   local zfsp=`getZFSRelativePath "${TDIR}"` 
     80  # Get the dataset of the jails mountpoint 
     81  rDataSet=`mount | grep "on ${JDIR} " | awk '{print $1}'` 
     82  tSubDir=`basename $TDIR` 
     83  nDataSet="${rDataSet}/${tSubDir}" 
    8184 
    82   # Use ZFS base for cloning 
    83   tank=`getZFSTank "${JDIR}"` 
    84   isDirZFS "${TDIR}" "1" 
    85   if [ $? -ne 0 ] ; then 
    86      echo "Creating ZFS ${TDIR} dataset..." 
    87      zfs create -o mountpoint=${TDIR} -p ${tank}${zfsp} 
    88      if [ $? -ne 0 ] ; then exit_err "Failed creating ZFS base dataset"; fi 
    89   fi 
     85  echo "Creating ZFS ${nDataSet} dataset..." 
     86  zfs create -p ${nDataSet} 
     87  if [ $? -ne 0 ] ; then exit_err "Failed creating ZFS base dataset"; fi 
    9088 
    9189  # Using a supplied tar file? 
     
    113111  fi 
    114112 
    115   zfs snapshot ${tank}${zfsp}@clean 
     113  zfs snapshot ${nDataSet}@clean 
    116114  if [ $? -ne 0 ] ; then exit_err "Failed creating clean ZFS base snapshot"; fi 
    117115 
  • src-sh/warden/scripts/backend/deletejail.sh

    rc7c25aa r698a249  
    6363isDirZFS "${JAILDIR}" "1" 
    6464if [ $? -eq 0 ] ; then 
     65  # Get the dataset of the jails mountpoint 
     66  rDataSet=`mount | grep "on ${JDIR} " | awk '{print $1}'` 
     67  tSubDir=`basename $JAILDIR` 
     68  jDataSet="${rDataSet}/${tSubDir}" 
     69 
    6570  # Create ZFS mount 
    66   tank=`getZFSTank "$JDIR"` 
    67   jailp=`getZFSRelativePath "${JAILDIR}"` 
    68   rc_halt "zfs destroy -r ${tank}${jailp}" 
     71  rc_halt "zfs destroy -r ${jDataSet}" 
    6972  rmdir ${JAILDIR} 2>/dev/null 
    7073else 
  • src-sh/warden/scripts/backend/functions.sh

    r2a7010e r698a249  
    9595    printerror "Error in download data, checksum mismatch. Please try again later." 
    9696 
    97   local zfsp=`getZFSRelativePath "${WORLDCHROOT}"` 
    98  
    99   # Use ZFS base for cloning 
    100   echo "Creating ZFS ${WORLDCHROOT} dataset..." 
    101   tank=`getZFSTank "${JDIR}"` 
     97  # Get the dataset of the jails mountpoint 
     98  rDataSet=`mount | grep "on ${JDIR} " | awk '{print $1}'` 
     99  tSubDir=`basename $WORLDCHROOT` 
     100  nDataSet="${rDataSet}/${tSubDir}" 
     101 
     102  echo "Creating ZFS ${nDataSet} dataset..." 
    102103  isDirZFS "${WORLDCHROOT}" "1" 
    103104  if [ $? -ne 0 ] ; then 
    104      zfs create -o mountpoint=/${tank}${zfsp} -p ${tank}${zfsp} 
     105     zfs create -p ${nDataSet} 
    105106     if [ $? -ne 0 ] ; then exit_err "Failed creating ZFS base dataset"; fi 
    106107     mkdir -p "${WORLDCHROOT}/.plugins" >/dev/null 2>&1 
     
    110111  if [ $? -ne 0 ] ; then exit_err "Failed extracting ZFS chroot environment"; fi 
    111112 
    112   zfs snapshot ${tank}${zfsp}@clean 
     113  zfs snapshot ${nDataSet}@clean 
    113114  if [ $? -ne 0 ] ; then exit_err "Failed creating clean ZFS base snapshot"; fi 
    114115  rm ${PJAIL} 
     
    150151    printerror "Error in download data, checksum mismatch. Please try again later." 
    151152 
    152   local zfsp=`getZFSRelativePath "${CHROOT}"` 
    153  
    154   # Use ZFS base for cloning 
     153  # Get the dataset of the jails mountpoint 
     154  rDataSet=`mount | grep "on ${JDIR} " | awk '{print $1}'` 
     155  tSubDir=`basename $CHROOT` 
     156  nDataSet="${rDataSet}/${tSubDir}" 
     157 
    155158  echo "Creating ZFS ${CHROOT} dataset..." 
    156   tank=`getZFSTank "${JDIR}"` 
    157159  isDirZFS "${CHROOT}" "1" 
    158160  if [ $? -ne 0 ] ; then 
    159      zfs create -o mountpoint=/${tank}${zfsp} -p ${tank}${zfsp} 
     161     zfs create -p ${nDataSet} 
    160162     if [ $? -ne 0 ] ; then exit_err "Failed creating ZFS base dataset"; fi 
    161163  fi 
     
    164166  if [ $? -ne 0 ] ; then exit_err "Failed extracting ZFS chroot environment"; fi 
    165167 
    166   zfs snapshot ${tank}${zfsp}@clean 
     168  zfs snapshot ${nDataSet}@clean 
    167169  if [ $? -ne 0 ] ; then exit_err "Failed creating clean ZFS base snapshot"; fi 
    168170  rm ${FBSD_TARBALL} 
     
    383385} 
    384386 
    385 rmZFSClone() { 
    386   CLONEDIR="${CDIR}/${3}-${2}" 
    387   isDirZFS "${CLONEDIR}" "1" 
    388   if [ $? -ne 0 ] ; then printerror "Not a ZFS volume: ${CLONEDIR}" ; fi 
    389   tank=`getZFSTank "${CLONEDIR}"` 
    390   rp=`getZFSRelativePath "${CLONEDIR}"` 
    391   zfs destroy ${tank}${rp} 
    392 } 
    393  
    394387rmZFSSnap() { 
    395388  isDirZFS "${1}" "1" 
    396389  if [ $? -ne 0 ] ; then printerror "Not a ZFS volume: ${1}" ; fi 
    397   tank=`getZFSTank "$1"` 
    398   rp=`getZFSRelativePath "$1"` 
    399   zfs destroy $tank${rp}@$2 
     390 
     391  # Get the dataset of the jails mountpoint 
     392  rDataSet=`mount | grep "on ${1} " | awk '{print $1}'` 
     393  zfs destroy ${rDataSet}@$2 
    400394} 
    401395 
     
    436430  if [ $? -ne 0 ] ; then printerror "Not a ZFS volume: ${1}" ; fi 
    437431 
    438   tank=`getZFSTank "$1"` 
    439   rp=`getZFSRelativePath "$1"` 
    440   newrp=`getZFSRelativePath "$2"` 
     432  # Get the dataset of the jails mountpoint 
     433  rDataSet=`mount | grep "on ${JDIR} " | awk '{print $1}'` 
     434  oSubDir=`basename $1` 
     435  oDataSet="${rDataSet}/${oSubDir}" 
     436  nSubDir=`basename $2` 
     437  nDataSet="${rDataSet}/${nSubDir}" 
    441438 
    442439  zdate=`date +%Y-%m-%d-%H-%M-%S` 
     
    444441 
    445442  # Create a temp snapshot we can clone 
    446   zfs snapshot $tank${rp}@${snapName} 
     443  zfs snapshot ${oDataSet}@${snapName} 
    447444  if [ $? -ne 0 ] ; then printerror "Failed creating snapshot!" ; fi 
    448445 
    449446  # Clone the snapshot 
    450   zfs clone -p ${tank}${rp}@${snapName} ${tank}${newrp} 
     447  zfs clone -p ${oDataSet}@${snapName} ${nDataSet} 
    451448  if [ $? -ne 0 ] ; then printerror "Failed cloning snapshot!" ; fi 
    452449 
     
    11341131   isDirZFS "${tDir}" "1" 
    11351132   if [ $? -ne 0 ] ; then printerror "Not a ZFS volume: ${tDir}" ; fi 
    1136    tank=`getZFSTank "$tDir"` 
    1137    rp=`getZFSRelativePath "$tDir"` 
    1138    zfs destroy -r $tank${rp}  
     1133 
     1134   # Get the dataset of the jails mountpoint 
     1135   rDataSet=`mount | grep "on ${tDir} " | awk '{print $1}'` 
     1136 
     1137   zfs destroy -r ${rDataSet} 
    11391138   if [ $? -ne 0 ] ; then 
    11401139     exit_err "Could not remove template, perhaps you have jails still using it?" 
  • src-sh/warden/scripts/backend/importjail.sh

    rd8b454f r698a249  
    4949echo "Importing ${IFILE} into jail ${JAILNAME}" 
    5050 
    51 # Create ZFS dataset for this jail 
    52 tank=`getZFSTank "$JDIR"` 
    53 rp=`getZFSRelativePath "${JAILDIR}"` 
    54 zfs create -p ${tank}${rp} 
     51# Get the dataset of the jails mountpoint 
     52rDataSet=`mount | grep "on ${JDIR} " | awk '{print $1}'` 
     53tSubDir=`basename $JAILDIR` 
     54nDataSet="${rDataSet}/${tSubDir}" 
     55 
     56zfs create -p ${nDataSet} 
    5557if [ $? -ne 0 ] ; then 
    5658   exit_err "Failed creating ZFS dataset for jail ${JAILDIR}" 
Note: See TracChangeset for help on using the changeset viewer.