From: Jaegeuk Kim <jaegeuk@kernel.org>
To: linux-f2fs-devel@lists.sourceforge.net
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Subject: [f2fs-dev] [PATCH 2/2] fsck.f2fs: fix cache offset for multiple partitions
Date: Mon, 16 Oct 2023 14:58:49 -0700 [thread overview]
Message-ID: <20231016215849.639313-2-jaegeuk@kernel.org> (raw)
In-Reply-To: <20231016215849.639313-1-jaegeuk@kernel.org>
The cache offset should have been considered multiple partitions per fd.
Let's fix.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
lib/libf2fs_io.c | 45 +++++++++++++++++++++++++--------------------
1 file changed, 25 insertions(+), 20 deletions(-)
diff --git a/lib/libf2fs_io.c b/lib/libf2fs_io.c
index 74e5f3ac49ba..39d377777259 100644
--- a/lib/libf2fs_io.c
+++ b/lib/libf2fs_io.c
@@ -246,7 +246,7 @@ static inline long dcache_relocate(long entry, int n)
dcache_config.num_cache_entry;
}
-static long dcache_find(off_t blk)
+static long dcache_find(__u64 blk)
{
register long n = dcache_config.num_cache_entry;
register unsigned m = dcache_config.max_hash_collision;
@@ -267,8 +267,13 @@ static long dcache_find(off_t blk)
}
/* Physical read into cache */
-static int dcache_io_read(int fd, long entry, off_t offset, off_t blk)
+static int dcache_io_read(long entry, __u64 offset, off_t blk)
{
+ int fd = __get_device_fd(&offset);
+
+ if (fd < 0)
+ return fd;
+
if (lseek(fd, offset, SEEK_SET) < 0) {
MSG(0, "\n lseek fail.\n");
return -1;
@@ -297,12 +302,11 @@ static int dcache_io_read(int fd, long entry, off_t offset, off_t blk)
* 1: cache not available (uninitialized)
* -1: error
*/
-static int dcache_update_rw(int fd, void *buf, off_t offset,
+static int dcache_update_rw(void *buf, __u64 offset,
size_t byte_count, bool is_write)
{
- off_t blk;
+ __u64 blk, start;
int addr_in_blk;
- off_t start;
if (!dcache_initialized)
dcache_init(); /* auto initialize */
@@ -337,7 +341,7 @@ static int dcache_update_rw(int fd, void *buf, off_t offset,
if (dcache_valid[entry])
++dcache_rreplace;
/* read: physical I/O read into cache */
- err = dcache_io_read(fd, entry, start, blk);
+ err = dcache_io_read(entry, start, blk);
if (err)
return err;
}
@@ -366,15 +370,15 @@ static int dcache_update_rw(int fd, void *buf, off_t offset,
* return value: 1: cache not available
* 0: success, -1: I/O error
*/
-int dcache_update_cache(int fd, void *buf, off_t offset, size_t count)
+int dcache_update_cache(void *buf, __u64 offset, size_t count)
{
- return dcache_update_rw(fd, buf, offset, count, true);
+ return dcache_update_rw(buf, offset, count, true);
}
/* handles read into cache + read into buffer */
-int dcache_read(int fd, void *buf, off_t offset, size_t count)
+int dcache_read(void *buf, __u64 offset, size_t count)
{
- return dcache_update_rw(fd, buf, offset, count, false);
+ return dcache_update_rw(buf, offset, count, false);
}
/*
@@ -517,15 +521,15 @@ int dev_read(void *buf, __u64 offset, size_t len)
return sparse_read_blk(offset / F2FS_BLKSIZE,
len / F2FS_BLKSIZE, buf);
- fd = __get_device_fd(&offset);
- if (fd < 0)
- return fd;
-
/* err = 1: cache not available, fall back to non-cache R/W */
/* err = 0: success, err=-1: I/O error */
- err = dcache_read(fd, buf, (off_t)offset, len);
+ err = dcache_read(buf, offset, len);
if (err <= 0)
return err;
+
+ fd = __get_device_fd(&offset);
+ if (fd < 0)
+ return fd;
if (lseek(fd, (off_t)offset, SEEK_SET) < 0)
return -1;
if (read(fd, buf, len) < 0)
@@ -561,16 +565,17 @@ int dev_write(void *buf, __u64 offset, size_t len)
return sparse_write_blk(offset / F2FS_BLKSIZE,
len / F2FS_BLKSIZE, buf);
- fd = __get_device_fd(&offset);
- if (fd < 0)
- return fd;
-
/*
* dcache_update_cache() just update cache, won't do I/O.
* Thus even no error, we need normal non-cache I/O for actual write
*/
- if (dcache_update_cache(fd, buf, (off_t)offset, len) < 0)
+ if (dcache_update_cache(buf, offset, len) < 0)
return -1;
+
+ fd = __get_device_fd(&offset);
+ if (fd < 0)
+ return fd;
+
if (lseek(fd, (off_t)offset, SEEK_SET) < 0)
return -1;
if (write(fd, buf, len) < 0)
--
2.42.0.655.g421f12c284-goog
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next prev parent reply other threads:[~2023-10-16 21:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-16 21:58 [f2fs-dev] [PATCH 1/2] Revert "f2fs-tools: do not support user-space cache" Jaegeuk Kim
2023-10-16 21:58 ` Jaegeuk Kim [this message]
2023-11-15 7:15 ` [f2fs-dev] [PATCH 2/2] fsck.f2fs: fix cache offset for multiple partitions Chao Yu
2023-11-15 7:10 ` [f2fs-dev] [PATCH 1/2] Revert "f2fs-tools: do not support user-space cache" Chao Yu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231016215849.639313-2-jaegeuk@kernel.org \
--to=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).