mirror of
				https://github.com/vdsm/virtual-dsm.git
				synced 2025-11-04 08:54:51 +08:00 
			
		
		
		
	Add full preallocation (writing zeroes)
This commit is contained in:
		
						commit
						621a95d080
					
				
							
								
								
									
										32
									
								
								run/disk.sh
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								run/disk.sh
									
									
									
									
									
								
							@ -29,7 +29,7 @@ if [ -f "${DATA}" ]; then
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    echo "INFO: Resizing data disk from $OLD_SIZE to $DATA_SIZE bytes.."
 | 
					    echo "INFO: Resizing data disk from $OLD_SIZE to $DATA_SIZE bytes.."
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if [ "$ALLOCATE" != "Y" ]; then
 | 
					    if [ "$ALLOCATE" = "N" ]; then
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      truncate -s "${DATA_SIZE}" "${DATA}"; 
 | 
					      truncate -s "${DATA_SIZE}" "${DATA}"; 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -45,12 +45,22 @@ if [ -f "${DATA}" ]; then
 | 
				
			|||||||
        echo "ERROR: Specify a smaller size or disable preallocation with ALLOCATION=N." && exit 84
 | 
					        echo "ERROR: Specify a smaller size or disable preallocation with ALLOCATION=N." && exit 84
 | 
				
			||||||
      fi
 | 
					      fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if [ "$ALLOCATE" = "Z" ]; then
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        GB=$(( (REQ + 1073741823)/1073741824 ))
 | 
				
			||||||
 | 
					        echo "INFO: Writing ${GB} GB of zeroes, please wait.."
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        dd if=/dev/zero of="${DATA}" seek="${OLD_SIZE}" count="${REQ}" bs=1M iflag=count_bytes oflag=seek_bytes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      else
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then
 | 
					        if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then
 | 
				
			||||||
          echo "ERROR: Could not allocate a file for the virtual disk." && exit 85
 | 
					          echo "ERROR: Could not allocate a file for the virtual disk." && exit 85
 | 
				
			||||||
        fi
 | 
					        fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      fi
 | 
					      fi
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
 | 
					  fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if [ "$DATA_SIZE" -lt "$OLD_SIZE" ]; then
 | 
					  if [ "$DATA_SIZE" -lt "$OLD_SIZE" ]; then
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -66,7 +76,7 @@ if [ ! -f "${DATA}" ]; then
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  # Create an empty file
 | 
					  # Create an empty file
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if [ "$ALLOCATE" != "Y" ]; then
 | 
					  if [ "$ALLOCATE" = "N" ]; then
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    truncate -s "${DATA_SIZE}" "${DATA}"
 | 
					    truncate -s "${DATA_SIZE}" "${DATA}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -80,16 +90,25 @@ if [ ! -f "${DATA}" ]; then
 | 
				
			|||||||
      echo "ERROR: Specify a smaller size or disable preallocation with ALLOCATION=N." && exit 86
 | 
					      echo "ERROR: Specify a smaller size or disable preallocation with ALLOCATION=N." && exit 86
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if [ "$ALLOCATE" = "Z" ]; then
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      echo "INFO: Writing ${DISK_SIZE} of zeroes, please wait.."
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      dd if=/dev/zero of="${DATA}" count="${DATA_SIZE}" bs=1M iflag=count_bytes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then
 | 
					      if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then
 | 
				
			||||||
        rm -f "${DATA}"
 | 
					        rm -f "${DATA}"
 | 
				
			||||||
        echo "ERROR: Could not allocate a file for the virtual disk." && exit 87
 | 
					        echo "ERROR: Could not allocate a file for the virtual disk." && exit 87
 | 
				
			||||||
      fi
 | 
					      fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
 | 
					  fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # Check if file exists
 | 
					  # Check if file exists
 | 
				
			||||||
  if [ ! -f "${DATA}" ]; then
 | 
					  if [ ! -f "${DATA}" ]; then
 | 
				
			||||||
    echo "ERROR: Virtual DSM data disk does not exist ($DATA)" && exit 88
 | 
					    echo "ERROR: Virtual disk does not exist ($DATA)" && exit 88
 | 
				
			||||||
  fi
 | 
					  fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # Format as BTRFS filesystem
 | 
					  # Format as BTRFS filesystem
 | 
				
			||||||
@ -97,6 +116,13 @@ if [ ! -f "${DATA}" ]; then
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Check the filesize
 | 
				
			||||||
 | 
					SIZE=$(stat -c%s "${DATA}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [[ SIZE -ne DATA_SIZE ]]; then
 | 
				
			||||||
 | 
					  echo "ERROR: Virtual disk has the wrong size: ${SIZE}" && exit 89
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
AGENT="${STORAGE}/${BASE}.agent"
 | 
					AGENT="${STORAGE}/${BASE}.agent"
 | 
				
			||||||
[ -f "$AGENT" ] && AGENT_VERSION=$(cat "${AGENT}") || AGENT_VERSION=1
 | 
					[ -f "$AGENT" ] && AGENT_VERSION=$(cat "${AGENT}") || AGENT_VERSION=1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -106,7 +106,7 @@ unzip -q -o "$BOOT".zip -d $TMP
 | 
				
			|||||||
echo "Install: Creating partition table..."
 | 
					echo "Install: Creating partition table..."
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SYSTEM="$TMP/sys.img"
 | 
					SYSTEM="$TMP/sys.img"
 | 
				
			||||||
SYSTEM_SIZE="4954537983"
 | 
					SYSTEM_SIZE=4954537983
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Check free diskspace
 | 
					# Check free diskspace
 | 
				
			||||||
SPACE=$(df --output=avail -B 1 "$TMP" | tail -n 1)
 | 
					SPACE=$(df --output=avail -B 1 "$TMP" | tail -n 1)
 | 
				
			||||||
@ -115,9 +115,35 @@ if (( SYSTEM_SIZE > SPACE )); then
 | 
				
			|||||||
  echo "ERROR: Not enough free space to create a 4 GB system disk." && exit 87
 | 
					  echo "ERROR: Not enough free space to create a 4 GB system disk." && exit 87
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if ! fallocate -l "${SYSTEM_SIZE}" "${SYSTEM}"; then
 | 
					if [ "$ALLOCATE" != "Z" ]; then
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  # Cannot use truncate here because of swap partition
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if ! fallocate -l "${SYSTEM_SIZE}" "${SYSTEM}"; then
 | 
				
			||||||
    rm -f "${SYSTEM}"
 | 
					    rm -f "${SYSTEM}"
 | 
				
			||||||
    echo "ERROR: Could not allocate a file for the system disk." && exit 88
 | 
					    echo "ERROR: Could not allocate a file for the system disk." && exit 88
 | 
				
			||||||
 | 
					  fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					else
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  GB=$(( (SYSTEM_SIZE + 1073741823)/1073741824 ))
 | 
				
			||||||
 | 
					  echo "INFO: Writing ${GB} GB of zeroes, please wait.."
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  dd if=/dev/zero of="${SYSTEM}" count="${SYSTEM_SIZE}" bs=1M iflag=count_bytes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Check if file exists
 | 
				
			||||||
 | 
					if [ ! -f "${SYSTEM}" ]; then
 | 
				
			||||||
 | 
					    echo "ERROR: System disk does not exist ($SYSTEM)" && exit 89
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Check the filesize
 | 
				
			||||||
 | 
					SIZE=$(stat -c%s "${SYSTEM}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [[ SIZE -ne SYSTEM_SIZE ]]; then
 | 
				
			||||||
 | 
					  rm -f "${SYSTEM}"
 | 
				
			||||||
 | 
					  echo "ERROR: System disk has the wrong size: ${SIZE}" && exit 90
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
PART="$TMP/partition.fdisk"
 | 
					PART="$TMP/partition.fdisk"
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user