2010-08-05 Milan Broz <mbroz@redhat.com>
* Wipe iteration and salt after KillSlot in LUKS header.
* Rewrite file differ test to C (and fix it to really work).
+ * Switch to 1MiB default alignment of data.
+ For more info see https://bugzilla.redhat.com/show_bug.cgi?id=621684
2010-07-28 Arno Wagner <arno@wagner.name>
* Add FAQ (Frequently Asked Questions) file to distribution.
#define SECTOR_SHIFT 9
#define SECTOR_SIZE (1 << SECTOR_SHIFT)
-#define DEFAULT_ALIGNMENT 4096
+#define DEFAULT_DISK_ALIGNMENT 1048576 /* 1MiB */
+#define DEFAULT_MEM_ALIGNMENT 4096
#define MAX_TTY_PASSWORD_LEN 512
struct crypt_params_luks1 *params)
{
int r;
- unsigned long required_alignment = DEFAULT_ALIGNMENT;
+ unsigned long required_alignment = DEFAULT_DISK_ALIGNMENT;
unsigned long alignment_offset = 0;
if (!cd->device) {
required_alignment = params->data_alignment * SECTOR_SIZE;
else
get_topology_alignment(cd->device, &required_alignment,
- &alignment_offset, DEFAULT_ALIGNMENT);
+ &alignment_offset, DEFAULT_DISK_ALIGNMENT);
r = LUKS_generate_phdr(&cd->hdr, cd->volume_key, cipher, cipher_mode,
(params && params->hash) ? params->hash : "sha1",
static int get_alignment(int fd)
{
- int alignment = DEFAULT_ALIGNMENT;
+ int alignment = DEFAULT_MEM_ALIGNMENT;
#ifdef _PC_REC_XFER_ALIGN
alignment = fpathconf(fd, _PC_REC_XFER_ALIGN);
if (alignment < 0)
- alignment = DEFAULT_ALIGNMENT;
+ alignment = DEFAULT_MEM_ALIGNMENT;
#endif
return alignment;
}
{
int dev_alignment_offset = 0;
unsigned int min_io_size = 0, opt_io_size = 0;
+ unsigned long temp_alignment = 0;
int fd;
*required_alignment = default_alignment;
/* alignment offset, bogus -1 means misaligned/unknown */
if (ioctl(fd, BLKALIGNOFF, &dev_alignment_offset) == -1 || dev_alignment_offset < 0)
dev_alignment_offset = 0;
+ *alignment_offset = (unsigned long)dev_alignment_offset;
- if (*required_alignment < (unsigned long)min_io_size)
- *required_alignment = (unsigned long)min_io_size;
+ temp_alignment = (unsigned long)min_io_size;
- if (*required_alignment < (unsigned long)opt_io_size)
- *required_alignment = (unsigned long)opt_io_size;
+ if (temp_alignment < (unsigned long)opt_io_size)
+ temp_alignment = (unsigned long)opt_io_size;
- *alignment_offset = (unsigned long)dev_alignment_offset;
+ /* If calculated alignment is multiple of default, keep default */
+ if (temp_alignment && (default_alignment % temp_alignment))
+ *required_alignment = temp_alignment;
log_dbg("Topology: IO (%u/%u), offset = %lu; Required alignment is %lu bytes.",
min_io_size, opt_io_size, *alignment_offset, *required_alignment);
char luksMagic[] = LUKS_MAGIC;
uuid_t partitionUuid;
int currentSector;
- int alignSectors = LUKS_ALIGN_KEYSLOTS / SECTOR_SIZE;
+
if (alignPayload == 0)
- alignPayload = alignSectors;
+ alignPayload = DEFAULT_DISK_ALIGNMENT / SECTOR_SIZE;
memset(header,0,sizeof(struct luks_phdr));
return r;
}
- currentSector = round_up_modulo(LUKS_PHDR_SIZE, alignSectors);
+ currentSector = round_up_modulo(LUKS_PHDR_SIZE, LUKS_ALIGN_KEYSLOTS / SECTOR_SIZE);
for(i = 0; i < LUKS_NUMKEYS; ++i) {
header->keyblock[i].active = LUKS_KEY_DISABLED;
header->keyblock[i].keyMaterialOffset = currentSector;
header->keyblock[i].stripes = stripes;
- currentSector = round_up_modulo(currentSector + blocksPerStripeSet, alignSectors);
+ currentSector = round_up_modulo(currentSector + blocksPerStripeSet,
+ LUKS_ALIGN_KEYSLOTS / SECTOR_SIZE);
}
currentSector = round_up_modulo(currentSector, alignPayload);
/* Actually we need only 37, but we don't want struct autoaligning to kick in */
#define UUID_STRING_L 40
-/* Offset to align kesylot area */
+/* Offset to keyslot area [in bytes] */
#define LUKS_ALIGN_KEYSLOTS 4096
/* Any integer values are stored in network byte order on disk and must be
CRYPTSETUP="../src/cryptsetup"
DEV=""
+DEV_STACKED="luks0xbabe"
cleanup() {
udevadm settle 2>/dev/null 2>&1
+ [ -b /dev/mapper/$DEV_STACKED ] && dmsetup remove $DEV_STACKED 2>/dev/null 2>&1
rmmod scsi_debug 2>/dev/null
sleep 2
}
{
if [ -z "$3" ] ; then
echo -n "Formatting using topology info ($1 bits key)...."
- echo xxx| $CRYPTSETUP luksFormat $DEV -q -s $1
+ echo xxx| $CRYPTSETUP luksFormat $DEV -q -i1 -s $1
else
- echo -n "Formatting using forced offset $3 ($1 bits key)..."
- echo xxx| $CRYPTSETUP luksFormat $DEV -q -s $1 --align-payload=$2
+ echo -n "Formatting using forced sector alignment $3 ($1 bits key)..."
+ echo xxx| $CRYPTSETUP luksFormat $DEV -q -i1 -s $1 --align-payload=$2
fi
ALIGN=$($CRYPTSETUP luksDump $DEV |grep "Payload offset" | sed -e s/.*\\t//)
echo "# Create desktop-class 4K drive"
echo "# (logical_block_size=512, physical_block_size=4096, alignment_offset=0)"
add_device dev_size_mb=16 sector_size=512 physblk_exp=3 num_tgts=1
-format 256 2112
-format 128 1088
+format 256 4096
+format 256 2112 8
+format 128 2048
+format 128 1088 8
format 256 8192 8192
format 128 8192 8192
cleanup
echo "# Create desktop-class 4K drive w/ 63-sector DOS partition compensation"
echo "# (logical_block_size=512, physical_block_size=4096, alignment_offset=3584)"
add_device dev_size_mb=16 sector_size=512 physblk_exp=3 lowest_aligned=7 num_tgts=1
-format 256 2119
-format 128 1095
+format 256 4103
+format 256 2119 8
+format 128 2055
+format 128 1095 8
cleanup
echo "# Create enterprise-class 4K drive"
echo "# (logical_block_size=4096, physical_block_size=4096, alignment_offset=0)"
add_device dev_size_mb=16 sector_size=4096 num_tgts=1
-format 256 2560
-format 128 1536
+format 256 4096
+format 256 2560 8
+format 128 2048
+format 128 1536 8
cleanup
echo "# Create classic 512b drive and stack dm-linear"
echo "# (logical_block_size=512, physical_block_size=512, alignment_offset=0)"
add_device dev_size_mb=16 sector_size=512 num_tgts=1
DEV2=$DEV
-DEV=/dev/mapper/luks0xbabe
-dmsetup create luks0xbabe --table "0 32768 linear $DEV2 0"
-format 256 2112
-format 128 1088
+DEV=/dev/mapper/$DEV_STACKED
+dmsetup create $DEV_STACKED --table "0 32768 linear $DEV2 0"
+format 256 4096
+format 256 2112 8
+format 128 2048
+format 128 1088 8
format 128 8192 8192
-dmsetup remove luks0xbabe
cleanup