[PC-BSD Commits] r21493 - pcbsd/current/src-sh/warden/scripts/backend

svn at pcbsd.org svn at pcbsd.org
Thu Feb 14 10:54:43 PST 2013


Author: kris
Date: 2013-02-14 18:54:43 +0000 (Thu, 14 Feb 2013)
New Revision: 21493

Modified:
   pcbsd/current/src-sh/warden/scripts/backend/functions.sh
Log:

Use the new ZFS Dataset function to fix up some broken functionality
in the warden when dealing with ZFS commands. Corrects issues with
non / mounted ZFS pools, and other misc errors



Modified: pcbsd/current/src-sh/warden/scripts/backend/functions.sh
===================================================================
--- pcbsd/current/src-sh/warden/scripts/backend/functions.sh	2013-02-14 18:53:22 UTC (rev 21492)
+++ pcbsd/current/src-sh/warden/scripts/backend/functions.sh	2013-02-14 18:54:43 UTC (rev 21493)
@@ -76,7 +76,7 @@
 
 
   # Creating ZFS dataset?
-  isDirZFS "${JDIR}"
+  isDirZFS "${JDIR}" "1"
   if [ $? -eq 0 ] ; then
     # Use ZFS base for cloning
     echo "Creating ZFS ${WORLDCHROOT} dataset..."
@@ -84,16 +84,12 @@
     isDirZFS "${WORLDCHROOT}" "1"
     if [ $? -ne 0 ] ; then
        # Check the mount-point for this tank
-       zMnt=`getZFSMount "$tank"`
-       if [ zMnt = "/" ] ; then
-	 local tMnt="$WORLDCHROOT"
-         zfs create -o mountpoint=${WORLDCHROOT} -p ${tank}${WORLDCHROOT}
-         if [ $? -ne 0 ] ; then exit_err "Failed creating ZFS base dataset"; fi
-       else
-	 local tMnt=`echo $WORLDCHROOT | sed "s|^${zMnt}||g"` 
-         zfs create -o mountpoint=${WORLDCHROOT} -p ${tank}${tMnt}
-         if [ $? -ne 0 ] ; then exit_err "Failed creating ZFS base dataset"; fi
+       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}
@@ -110,7 +106,7 @@
   # Create ZFS clean snapshot
   isDirZFS "${JDIR}"
   if [ $? -eq 0 ] ; then
-    zfs snapshot ${tank}${tMnt}@clean
+    zfs snapshot ${zData}/`basename $WORLDCHROOT`@clean
     if [ $? -ne 0 ] ; then exit_err "Failed creating clean ZFS base snapshot"; fi
   fi
 };
@@ -211,65 +207,51 @@
 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`
   # Check the mount-point for this tank
-  zMnt=`getZFSMount "$tank"`
-  if [ zMnt = "/" ] ; then
-    zfs snapshot $tank${1}@$zdate
-    if [ $? -ne 0 ] ; then exit_err "Failed snapshot of dataset: $1"; fi
-  else
-    local tMnt=`echo ${1} | sed "s|^${zMnt}||g"` 
-    zfs snapshot $tank${tMnt}@$zdate
-    if [ $? -ne 0 ] ; then exit_err "Failed snapshot of dataset: $1"; fi
+  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"`
   # Check the mount-point for this tank
-  zMnt=`getZFSMount "$tank"`
-  if [ zMnt = "/" ] ; then
-    zfs list -t snapshot | grep -w "^${tank}${1}" | cut -d '@' -f 2 | awk '{print $1}'
-  else
-    local tMnt=`echo ${1} | sed "s|^${zMnt}||g"` 
-    zfs list -t snapshot | grep -w "^${tank}${tMnt}" | cut -d '@' -f 2 | awk '{print $1}'
+  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 "-----------------------------------"
   # Check the mount-point for this tank
-  zMnt=`getZFSMount "$tank"`
-  if [ zMnt = "/" ] ; then
-    zfs list | grep -w "^${tank}${CDIR}/${2}" | awk '{print $5}' | sed "s|${CDIR}/${2}-||g"
-  else
-    local tMnt=`echo ${CDIR} | sed "s|^${zMnt}||g"` 
-    zfs list | grep -w "^${tank}${tMnt}/${2}" | awk '{print $5}' | sed "s|${CDIR}/${2}-||g"
+  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"`
   # Check the mount-point for this tank
-  zMnt=`getZFSMount "$tank"`
-  if [ zMnt = "/" ] ; then
-    zfs destroy ${tank}${CLONEDIR}
-    if [ $? -ne 0 ] ; then exit_err "Failed removing: $CLONEDIR"; fi
-  else
-    local tMnt=`echo ${CLONEDIR} | sed "s|^${zMnt}||g"` 
-    zfs destroy ${tank}${tMnt}
-    if [ $? -ne 0 ] ; then exit_err "Failed removing: $CLONEDIR"; fi
+  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() {
@@ -277,31 +259,25 @@
   if [ $? -ne 0 ] ; then printerror "Not a ZFS volume: ${1}" ; fi
   tank=`getZFSTank "$1"`
   # Check the mount-point for this tank
-  zMnt=`getZFSMount "$tank"`
-  if [ zMnt = "/" ] ; then
-    zfs destroy $tank${1}@$2
-    if [ $? -ne 0 ] ; then exit_err "Failed removing: ${1}@${2}"; fi
-  else
-    local tMnt=`echo ${1} | sed "s|^${zMnt}||g"` 
-    zfs destroy $tank${tMnt}@$2
-    if [ $? -ne 0 ] ; then exit_err "Failed removing: ${tMnt}@${2}"; fi
+  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
-  zMnt=`getZFSMount "$tank"`
-  if [ zMnt = "/" ] ; then
-    local tMnt="${1}"
-  else
-    local tMnt=`echo ${1} | sed "s|^${zMnt}||g"` 
+  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}${tMnt}" | 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
@@ -317,8 +293,8 @@
   fi
 
   # Rollback the snapshot
-  zfs rollback -R -f ${tank}${tMnt}@$2
-  if [ $? -ne 0 ] ; then exit_err "Failed rollback: ${tMnt}@${2}"; fi
+  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
@@ -330,19 +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
-  zMnt=`getZFSMount "$tank"`
-  if [ zMnt = "/" ] ; then
-    local tMnt="${1}"
-    local cMnt="${CDIR}"
-  else
-    local tMnt=`echo ${1} | sed "s|^${zMnt}||g"` 
-    local cMnt=`echo ${CDIR} | sed "s|^${zMnt}||g"` 
+  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}${tMnt}" | 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
@@ -350,7 +325,7 @@
   fi
 
   # Clone the snapshot
-  zfs clone -p ${tank}${tMnt}@$2 ${tank}${cMnt}/${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