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:
		
							parent
							
								
									9b9d8285fe
								
							
						
					
					
						commit
						e65ab41b7c
					
				
							
								
								
									
										31
									
								
								run/disk.sh
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								run/disk.sh
									
									
									
									
									
								
							@ -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" = "F" ]; 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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -82,11 +92,9 @@ if [ ! -f "${DATA}" ]; then
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if [ "$ALLOCATE" = "F" ]; then
 | 
					    if [ "$ALLOCATE" = "F" ]; then
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      MB=$(( (DATA_SIZE + 1048575)/1048576 ))
 | 
					      echo "INFO: Writing ${DISK_SIZE} of zeroes, please wait.."
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      echo "INFO: Writing ${MB} MB of zeroes, please wait.."
 | 
					      dd if=/dev/zero of="${DATA}" count="${DATA_SIZE}" bs=1M iflag=count_bytes
 | 
				
			||||||
      dd if=/dev/zero of="${DATA}" count="${MB}" bs=1M
 | 
					 | 
				
			||||||
      truncate -s "${DATA_SIZE}" "${DATA}"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -103,19 +111,18 @@ if [ ! -f "${DATA}" ]; then
 | 
				
			|||||||
    echo "ERROR: Virtual disk does not exist ($DATA)" && exit 88
 | 
					    echo "ERROR: Virtual disk does not exist ($DATA)" && exit 88
 | 
				
			||||||
  fi
 | 
					  fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # Check the filesize
 | 
					 | 
				
			||||||
  SIZE=$(stat -c%s "${DATA}")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if [[ SIZE -ne DATA_SIZE ]]; then
 | 
					 | 
				
			||||||
    rm -f "${DATA}"
 | 
					 | 
				
			||||||
    echo "ERROR: Virtual disk has the wrong size: ${SIZE}" && exit 89
 | 
					 | 
				
			||||||
  fi
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  # Format as BTRFS filesystem
 | 
					  # Format as BTRFS filesystem
 | 
				
			||||||
  mkfs.btrfs -q -L data -d single -m dup "${DATA}" > /dev/null
 | 
					  mkfs.btrfs -q -L data -d single -m dup "${DATA}" > /dev/null
 | 
				
			||||||
 | 
					
 | 
				
			||||||
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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user