From patchwork Mon Oct 16 21:58:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaegeuk Kim X-Patchwork-Id: 13424214 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B0FB1CDB474 for ; Mon, 16 Oct 2023 21:59:04 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1qsVc6-0007kf-H9; Mon, 16 Oct 2023 21:59:03 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1qsVc4-0007kR-CX for linux-f2fs-devel@lists.sourceforge.net; Mon, 16 Oct 2023 21:59:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=hIL2tY6Ya3vXaRYdpIXxGg5UF1TByOarqlrzQ1IPHw8=; b=LayMk+uAYT5FvMX3BWh98M9XhK A9sw3qnVmL3qlNJVCssx0b6Bt2bj+uvR9oSeF6G4cpb1rqWH0Y1yiRDx7ZOzHVpbrwrgjDi1nagPg fIvOx+XH5ZgpI2Evh2PFnb6jzEpXas4gC9YI1XmcRGdv6NqwWY5B/GfzMcDnpbeWSKxo=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=hIL2tY6Ya3vXaRYdpIXxGg5UF1TByOarqlrzQ1IPHw8=; b=M7LIF7xdl2fw5e9e/rcAagMW8B dkca9/ZngzpgNUF4SRWh4dQB7o/19t3xYPYbdE2jrtJdmvfEEhKyLnCqMSiSdv+M0kVXJWWfN85nW xWuf0COmL/pKTWIxTg2WkgSAPAklxFtVOcZP0P0a5/g4zCmwbp24lKmRUBHpz+5dEK+4=; Received: from dfw.source.kernel.org ([139.178.84.217]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1qsVc4-00HA6e-42 for linux-f2fs-devel@lists.sourceforge.net; Mon, 16 Oct 2023 21:59:00 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id B37E8611C3 for ; Mon, 16 Oct 2023 21:58:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56835C433C8; Mon, 16 Oct 2023 21:58:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697493534; bh=tPneTTHKFMRHD0Rybv8/aIBgzOJ0UU1S3RNxLEY6rEc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FfXxOi6PNKCnL+r/nEnKEOr29udj5Yjo4qO+yaF2auO1GMGJSLFC5DsREEsXRNohq wOBMUQfqTlHFNxkRe1VxXIsFt3KzW0IMBhBplRT6SZaL+zXgvGan0RDft+ENITNmDP TspT9JZnJGMf+AbNwK4ARIjShln5RMtwyqVCGCUU9R9P5eKQ9b/A7J9kqELc0OyCNI DxfnpZ72iBw9fFN03Tod3sIESIURSAhCCE/vge4/yLPnK3jol+H3uSCwSB1V6H69LY GnH6pC1diMAZFKNJ1hwc2FT/fNYmdv16qL3vKpjJmHMkOpGjWtodqj8A4VQaYh7TKg ZFlsDBPD3yL4A== From: Jaegeuk Kim To: linux-f2fs-devel@lists.sourceforge.net Date: Mon, 16 Oct 2023 14:58:49 -0700 Message-ID: <20231016215849.639313-2-jaegeuk@kernel.org> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog In-Reply-To: <20231016215849.639313-1-jaegeuk@kernel.org> References: <20231016215849.639313-1-jaegeuk@kernel.org> MIME-Version: 1.0 X-Headers-End: 1qsVc4-00HA6e-42 Subject: [f2fs-dev] [PATCH 2/2] fsck.f2fs: fix cache offset for multiple partitions X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jaegeuk Kim Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net The cache offset should have been considered multiple partitions per fd. Let's fix. Signed-off-by: Jaegeuk Kim Reviewed-by: Chao Yu --- 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)