Re: [PATCH RFC] introduce ioctl to completely invalidate page cache

3 messages, 3 authors, 2014-10-03 · open the first message on its own page

Re: [PATCH RFC] introduce ioctl to completely invalidate page cache

From: Jens Axboe <axboe@kernel.dk>
Date: 2014-10-02 19:59:39

On 10/02/2014 10:09 AM, Thanos Makatos wrote:
quoted hunk
This patch introduces a new ioctl called BLKFLUSHBUFS2, which is pretty
similar to BLKFLUSHBUFS except that is also invalidates the page cache.
This allows for a complete invalidation of the cached data of a
particular block device, which might be useful for cases like
synchronising the caches of an iSCSI block device used by multiple
hosts.

Signed-off-by: Thanos Makatos <redacted>
---
 block/compat_ioctl.c    |    1 +
 block/ioctl.c           |   13 +++++++++++--
 include/uapi/linux/fs.h |    1 +
 3 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
index 18b282c..672388ab 100644
--- a/block/compat_ioctl.c
+++ b/block/compat_ioctl.c
@@ -688,6 +688,7 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
 	case BLKDISCARDZEROES:
 		return compat_put_uint(arg, bdev_discard_zeroes_data(bdev));
 	case BLKFLSBUF:
+	case BLKFLSBUF2:
 	case BLKROSET:
 	case BLKDISCARD:
 	case BLKSECDISCARD:
diff --git a/block/ioctl.c b/block/ioctl.c
index d6cda81..0c427a7 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -268,6 +268,12 @@ static inline int is_unrecognized_ioctl(int ret)
 		ret == -ENOIOCTLCMD;
 }
 
+static void flush_buffer_cache(struct block_device *bdev)
+{
+	fsync_bdev(bdev);
+	invalidate_bdev(bdev);
+}
+
 /*
  * always keep this in sync with compat_blkdev_ioctl()
  */
@@ -282,6 +288,7 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
 
 	switch(cmd) {
 	case BLKFLSBUF:
+	case BLKFLSBUF2:
 		if (!capable(CAP_SYS_ADMIN))
 			return -EACCES;
 
@@ -289,8 +296,10 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
 		if (!is_unrecognized_ioctl(ret))
 			return ret;
 
-		fsync_bdev(bdev);
-		invalidate_bdev(bdev);
+		flush_buffer_cache(bdev);
+		if (BLKFLSBUF2 == cmd)
+			return invalidate_inode_pages2(
+					bdev->bd_inode->i_mapping);
 		return 0;
We're currently ignoring the buffer cache sync and invalidation (which
is odd), but at least being consistent would be good.

Might also need a filemap_write_and_wait() to sync before invalidation.

-- 
Jens Axboe

Re: [PATCH RFC] introduce ioctl to completely invalidate page cache

From: Dave Chinner <david@fromorbit.com>
Date: 2014-10-03 05:27:37

On Thu, Oct 02, 2014 at 01:59:40PM -0600, Jens Axboe wrote:
On 10/02/2014 10:09 AM, Thanos Makatos wrote:
quoted
This patch introduces a new ioctl called BLKFLUSHBUFS2, which is pretty
What a horrible name. Whatever happened to naming ioctls interfaces
after their function? i.e. BLKFLUSHINVAL?

Cheers,

Dave?

-- 
Dave Chinner
david@fromorbit.com

RE: [PATCH RFC] introduce ioctl to completely invalidate page cache

From: Thanos Makatos <hidden>
Date: 2014-10-03 09:00:17

quoted
quoted
This patch introduces a new ioctl called BLKFLUSHBUFS2, which is
pretty
What a horrible name. Whatever happened to naming ioctls interfaces after
their function? i.e. BLKFLUSHINVAL?
Indeed it's not a good name, I'm open to suggestions!
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help