Revert "brd: remove support for BLKFLSBUF" 83/239983/2 accepted/tizen/unified/20200806.062547 submit/tizen/20200806.024854
authorSeung-Woo Kim <sw0312.kim@samsung.com>
Fri, 31 Jul 2020 06:19:08 +0000 (15:19 +0900)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Mon, 3 Aug 2020 07:15:07 +0000 (07:15 +0000)
This reverts commit ff26956875c2f05e12ecec9938411a2c7dfc767d.

To free ramdisk memory, BLKFLSBUF support is required.

Change-Id: Ib363fdcb65a21914c8baa2099e4b1ce6242428e2
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
drivers/block/brd.c

index 502f72d..0b4dced 100644 (file)
@@ -374,9 +374,44 @@ static int brd_rw_page(struct block_device *bdev, sector_t sector,
        return err;
 }
 
+static int brd_ioctl(struct block_device *bdev, fmode_t mode,
+                       unsigned int cmd, unsigned long arg)
+{
+       int error;
+       struct brd_device *brd = bdev->bd_disk->private_data;
+
+       if (cmd != BLKFLSBUF)
+               return -ENOTTY;
+
+       /*
+        * ram device BLKFLSBUF has special semantics, we want to actually
+        * release and destroy the ramdisk data.
+        */
+       mutex_lock(&brd_mutex);
+       mutex_lock(&bdev->bd_mutex);
+       error = -EBUSY;
+       if (bdev->bd_openers <= 1) {
+               /*
+                * Kill the cache first, so it isn't written back to the
+                * device.
+                *
+                * Another thread might instantiate more buffercache here,
+                * but there is not much we can do to close that race.
+                */
+               kill_bdev(bdev);
+               brd_free_pages(brd);
+               error = 0;
+       }
+       mutex_unlock(&bdev->bd_mutex);
+       mutex_unlock(&brd_mutex);
+
+       return error;
+}
+
 static const struct block_device_operations brd_fops = {
        .owner =                THIS_MODULE,
        .rw_page =              brd_rw_page,
+       .ioctl =                brd_ioctl,
 };
 
 /*