New option DISK_FOLLOW_SYMLINKS
authorMartin Schwenke <martin@meltin.net>
Mon, 7 May 2012 03:54:46 +0000 (13:54 +1000)
committerMartin Schwenke <martin@meltin.net>
Mon, 7 May 2012 03:54:46 +0000 (13:54 +1000)
If DISK_FOLLOW_SYMLINKS=yes then for any disk image paths that are a
symlink, follow the symlink when creating the image.

This allows disk images to be reorganised, perhaps across several
disks, and replaced with symlinks.  On the next cluster creation the
symlinks will be respected and the layout of disk images will be
maintained.

Signed-off-by: Martin Schwenke <martin@meltin.net>
autocluster
config.d/00base.defconf
config.d/10shareddisk.defconf
config.d/60tsm.defconf

index f5fae9fe0e4d9854430dbad02d27c9d734d688e0..cec09e4e08afb3add5be5fd926e68f0b4c38bd83 100755 (executable)
@@ -197,28 +197,32 @@ create_node_COMMON ()
 
     mkdir -p $VIRTBASE/$CLUSTER tmp
 
-    rm -f "$DISK"
+    local di="$DISK"
+    if [ "$DISK_FOLLOW_SYMLINKS" = "yes" -a -L "$DISK" ] ; then
+       di=$(readlink "$DISK")
+    fi
+    rm -f "$di"
     case "$SYSTEM_DISK_FORMAT" in
        qcow2)
            echo "Creating the disk..."
-           qemu-img create -b "$base_disk" -f qcow2 "$DISK"
+           qemu-img create -b "$base_disk" -f qcow2 "$di"
            create_node_configure_image "$DISK" "$type"
            ;;
        raw)
            echo "Creating the disk..."
-           cp -v --sparse=always "$base_disk" "$DISK"
+           cp -v --sparse=always "$base_disk" "$di"
            create_node_configure_image "$DISK" "$type"
            ;;
        reflink)
            echo "Creating the disk..."
-           cp -v --reflink=always "$base_disk" "$DISK"
+           cp -v --reflink=always "$base_disk" "$di"
            create_node_configure_image "$DISK" "$type"
            ;;
        mmclone)
            echo "Creating the disk (using mmclone)..."
            local base_snap="${base_disk}.snap"
            [ -f "$base_snap" ] || mmclone snap "$base_disk" "$base_snap"
-           mmclone copy "$base_snap" "$DISK"
+           mmclone copy "$base_snap" "$di"
            create_node_configure_image "$DISK" "$type"
            ;;
        none)
@@ -488,8 +492,13 @@ create_base() {
     echo "Testing WEBPROXY $WEBPROXY"
     test_proxy
 
+    local di="$DISK"
+    if [ "$DISK_FOLLOW_SYMLINKS" = "yes" -a -L "$DISK" ] ; then
+       di=$(readlink "$DISK")
+    fi
+
     echo "Creating the disk"
-    qemu-img create -f $BASE_FORMAT "$DISK" $DISKSIZE
+    qemu-img create -f $BASE_FORMAT "$di" $DISKSIZE
 
     rm -rf tmp
     mkdir -p mnt tmp tmp/ISO
index 5cb7d1cd6067e745041fa7541b37e2edcc05a6c3..ba39c062840ead09269a1518eb20c72f8a3dd892 100644 (file)
@@ -40,6 +40,9 @@ defconf BASENAME "ac-base" \
 defconf BASE_PER_NODE_TYPE "no" \
        "<yes|no>" "Use per-node-type base images"
 
+defconf DISK_FOLLOW_SYMLINKS "no" \
+       "<yes|no>" "If disk images use symlinks then follow them to overwrite"
+
 ######################################################################
 
 # Virtualisation
index 903727cfd87fcafb324ffd834023542cf3008b54..d53765d44bb0a5236dcb8784e86cafb69e8790ea 100644 (file)
@@ -128,6 +128,9 @@ EOF
        local i
        for i in $(seq 1 $SHAREDDISK_COUNT); do
            local f="$VIRTBASE/$CLUSTER/shared$i"
+           if [ "$DISK_FOLLOW_SYMLINKS" = "yes" -a -L "$f" ] ; then
+               f=$(readlink "$f")
+           fi
            rm -f "$f"
            if [ "$SHARED_DISK_TYPE" = "iscsi" ] ; then
                dd if=/dev/zero seek=$SHAREDDISKSIZE bs=1 count=1 of="$f"
index 8e2aacd4f3d3e5126eb0375eda9feb0ea9c460f1..1e22f1d2e094674820ce210b9e5354f368b8e929 100644 (file)
@@ -84,8 +84,13 @@ create_node_tsm_server ()
     echo "Creating TSM server node $name"
     create_node_COMMON "$name" "$ip_offset" "$type" "$TSM_TEMPLATE"
 
+    local di="$TSMDISK"
+    if [ "$DISK_FOLLOW_SYMLINKS" = "yes" -a -L "$TSMDISK" ] ; then
+       di=$(readlink "$TSMDISK")
+    fi
+
     echo "Creating tsm disk"
-    qemu-img create -f qcow2 "$TSMDISK" $TSMDISKSIZE
+    qemu-img create -f qcow2 "$di" $TSMDISKSIZE
 
     echo
 }