lib/utils_crypt: optimize seek to keyfile-offset
authorDave Reisner <dreisner@archlinux.org>
Fri, 24 Aug 2012 21:45:25 +0000 (17:45 -0400)
committerMilan Broz <gmazyland@gmail.com>
Mon, 27 Aug 2012 11:10:00 +0000 (13:10 +0200)
commit961682aa6b22877beb83c148ec157063383d94ee
tree58e249c27d3096f6191451273aae3c985ec8c364
parent2f37cfe569d3ed88b6e822ad2d1ff351ba7af5eb
lib/utils_crypt: optimize seek to keyfile-offset

Avoid using unbuffered reads when "seeking" to a keyfile offset. This is
abysmally slow when the key is hidden at the end of a large device.
Instead, try to actually call lseek, falling back on reading in chunks
of BUFSIZ bytes until the desired offset is reached.

Command line:

  cryptsetup luksOpen /dev/vdc1 home \
      --keyfile /dev/vdd --keyfile-size 4096 --keyfile-offset 123456789

Before:

  real   0m25.589s
  user   0m7.030s
  sys    0m18.479s

After:

  real   0m4.464s
  user   0m4.253s
  sys    0m0.157s
ChangeLog
lib/utils_crypt.c