zram: revalidate disk after capacity change
authorMinchan Kim <minchan@kernel.org>
Wed, 2 Jul 2014 22:22:36 +0000 (15:22 -0700)
committerAlex Shi <alex.shi@linaro.org>
Mon, 11 May 2015 13:03:20 +0000 (21:03 +0800)
commit888210267e226f437abb7fd0604530032a98cafa
tree6f27d41824c6c72432c5bd7b8fc4f9261131cb20
parentc398e6a3df7562a1a70e2ad487dcda2c3cb635e9
zram: revalidate disk after capacity change

Alexander reported mkswap on /dev/zram0 is failed if other process is
opening the block device file.

Step is as follows,

0. Reset the unused zram device.
1. Use a program that opens /dev/zram0 with O_RDWR and sleeps
   until killed.
2. While that program sleeps, echo the correct value to
   /sys/block/zram0/disksize.
3. Verify (e.g. in /proc/partitions) that the disk size is applied
   correctly. It is.
4. While that program still sleeps, attempt to mkswap /dev/zram0.
   This fails: mkswap: error: swap area needs to be at least 40 KiB

When I investigated, the size get by ioctl(fd, BLKGETSIZE64, xxx) on
mkswap to get a size of blockdev was zero although zram0 has right size by
2.

The reason is zram didn't revalidate disk after changing capacity so that
size of blockdev's inode is not uptodate until all of file is close.

This patch should fix the BUG.

Signed-off-by: Minchan Kim <minchan@kernel.org>
Reported-by: Alexander E. Patrakov <patrakov@gmail.com>
Tested-by: Alexander E. Patrakov <patrakov@gmail.com>
Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Nitin Gupta <ngupta@vflare.org>
Acked-by: Jerome Marchand <jmarchan@redhat.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit 2e32baea46ce542c561a519414c840295b229c8f)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
drivers/block/zram/zram_drv.c