Skip to content

Commit 2e32bae

Browse files
minchanktorvalds
authored andcommitted
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 <[email protected]> Reported-by: Alexander E. Patrakov <[email protected]> Tested-by: Alexander E. Patrakov <[email protected]> Reviewed-by: Sergey Senozhatsky <[email protected]> Cc: Nitin Gupta <[email protected]> Acked-by: Jerome Marchand <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent e98f776 commit 2e32bae

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/block/zram/zram_drv.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,8 +622,10 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity)
622622
memset(&zram->stats, 0, sizeof(zram->stats));
623623

624624
zram->disksize = 0;
625-
if (reset_capacity)
625+
if (reset_capacity) {
626626
set_capacity(zram->disk, 0);
627+
revalidate_disk(zram->disk);
628+
}
627629
up_write(&zram->init_lock);
628630
}
629631

@@ -664,6 +666,7 @@ static ssize_t disksize_store(struct device *dev,
664666
zram->comp = comp;
665667
zram->disksize = disksize;
666668
set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT);
669+
revalidate_disk(zram->disk);
667670
up_write(&zram->init_lock);
668671
return len;
669672

0 commit comments

Comments
 (0)