[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210114002723.643589-4-saranyamohan@google.com>
Date: Wed, 13 Jan 2021 16:27:21 -0800
From: Saranya Muruganandam <saranyamohan@...gle.com>
To: linux-ext4@...r.kernel.org
Cc: tytso@....edu
Subject: [RFC PATCH v1 3/5] libext2fs: allow the unix_io manager's cache to be
disabled and re-enabled
From: Theodore Ts'o <tytso@....edu>
Signed-off-by: Theodore Ts'o <tytso@....edu>
---
lib/ext2fs/ext2_io.h | 1 +
lib/ext2fs/unix_io.c | 19 +++++++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/lib/ext2fs/ext2_io.h b/lib/ext2fs/ext2_io.h
index 2e0da5a5..95c25a7b 100644
--- a/lib/ext2fs/ext2_io.h
+++ b/lib/ext2fs/ext2_io.h
@@ -106,6 +106,7 @@ struct struct_io_manager {
#define IO_FLAG_DIRECT_IO 0x0004
#define IO_FLAG_FORCE_BOUNCE 0x0008
#define IO_FLAG_THREADS 0x0010
+#define IO_FLAG_NOCACHE 0x0020
/*
* Convenience functions....
diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c
index 9385487d..2df53e51 100644
--- a/lib/ext2fs/unix_io.c
+++ b/lib/ext2fs/unix_io.c
@@ -942,6 +942,8 @@ static errcode_t unix_read_blk64(io_channel channel, unsigned long long block,
#ifdef NO_IO_CACHE
return raw_read_blk(channel, data, block, count, buf);
#else
+ if (data->flags & IO_FLAG_NOCACHE)
+ return raw_read_blk(channel, data, block, count, buf);
/*
* If we're doing an odd-sized read or a very large read,
* flush out the cache and then do a direct read.
@@ -1032,6 +1034,8 @@ static errcode_t unix_write_blk64(io_channel channel, unsigned long long block,
#ifdef NO_IO_CACHE
return raw_write_blk(channel, data, block, count, buf);
#else
+ if (data->flags & IO_FLAG_NOCACHE)
+ return raw_write_blk(channel, data, block, count, buf);
/*
* If we're doing an odd-sized write or a very large write,
* flush out the cache completely and then do a direct write.
@@ -1161,6 +1165,7 @@ static errcode_t unix_set_option(io_channel channel, const char *option,
{
struct unix_private_data *data;
unsigned long long tmp;
+ errcode_t retval;
char *end;
EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
@@ -1179,6 +1184,20 @@ static errcode_t unix_set_option(io_channel channel, const char *option,
return EXT2_ET_INVALID_ARGUMENT;
return 0;
}
+ if (!strcmp(option, "cache")) {
+ if (!arg)
+ return EXT2_ET_INVALID_ARGUMENT;
+ if (!strcmp(arg, "on")) {
+ data->flags &= ~IO_FLAG_NOCACHE;
+ return 0;
+ }
+ if (!strcmp(arg, "off")) {
+ retval = flush_cached_blocks(channel, data, 0);
+ data->flags |= IO_FLAG_NOCACHE;
+ return retval;
+ }
+ return EXT2_ET_INVALID_ARGUMENT;
+ }
return EXT2_ET_INVALID_ARGUMENT;
}
--
2.30.0.284.gd98b1dd5eaa7-goog
Powered by blists - more mailing lists