Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp515301rdb; Tue, 19 Sep 2023 02:14:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHclgNrlzkUq5Ch5LLQY86unAusSZ7P5j6KcDgNFXDlq31MdIkiA+hsuqmt8nAg59ELMhFt X-Received: by 2002:a05:6870:b489:b0:1b0:b13:c16 with SMTP id y9-20020a056870b48900b001b00b130c16mr14877063oap.2.1695114846052; Tue, 19 Sep 2023 02:14:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695114846; cv=none; d=google.com; s=arc-20160816; b=cmv75U3+Pr4Pc4YCHKBsyQWqFcdPEFTAgNlyFLyeA++Lh/5ge/OhGugFHH/LRNpO+e eQ4IdFfCVKdvMP8CECSSzfMchTJANuLPo6E+M1bEY6X20Wliq/cx531j7vAiRKpwkTXs gov4IW+A1310CMd9FA+kRVKxhaJO+11qSs5Awdm7GQBctL4M7GjICKaAR5u86OCV9w9f qYIDHrixjYxc/VILOuLvCh3RZtK9C78Nk7BMMmd8cLj49/v2nIdM5kh/A7Rvswt7bsNC N7huRwaF0MANuc5g9NczqWYryVaGnoxy4YIv7pWKKCQgy7m4AHu8zScHrZrNluO4qm65 9IBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=iOM8GKQZFsCtZquRVR+P44pBO1jO6LSkZvLlQwmDs8M=; fh=6iIdDMHM3xs7FqY7rwk7A+QeZqkhrispzuMT8+1se1M=; b=g41BU/EZzB+cZi5lxxc2kbdavEMu4WQ6Fh0/OWxBkYPEPazyUhqy1DAPpzYshxSsIC 2JaffJR4bOAaXUHxBkQ5NNcXnQKCZbKzXHIBzHd4kioBoXtz/bUb4XrGgxTAwPQHMj9W M3pIjTwId6Faz2J5Zii8PYwNFrbpfpomZaIz3diSD9+zRQhjhcnVkIWtlMfQg+U/pqeL 8Rre0fu4oIxA755oVBs098KWyjP9DfDhLKueXA8BSrhUfakd8ckcD03E0X4K6xEyhf2Z Ln47p3AEj6rXM3hYNu2IIoOSxVy+ua+ny0JyQ7Ea5rch09m6PHWleVyyEYcOHFcz3z9I 9IdQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id cg12-20020a056a00290c00b0068e486a14e1si9310078pfb.163.2023.09.19.02.14.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 02:14:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 5DC918043002; Tue, 19 Sep 2023 02:09:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229714AbjISJJt (ORCPT + 99 others); Tue, 19 Sep 2023 05:09:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229821AbjISJJq (ORCPT ); Tue, 19 Sep 2023 05:09:46 -0400 Received: from omta001.cacentral1.a.cloudfilter.net (omta001.cacentral1.a.cloudfilter.net [3.97.99.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8C2CBA for ; Tue, 19 Sep 2023 02:09:39 -0700 (PDT) Received: from shw-obgw-4004a.ext.cloudfilter.net ([10.228.9.227]) by cmsmtp with ESMTP id iUiBqeSiWLAoIiWjjq8HJR; Tue, 19 Sep 2023 09:09:39 +0000 Received: from webber.adilger.int ([70.77.221.9]) by cmsmtp with ESMTP id iWjhqEziq3fOSiWjiqAHxS; Tue, 19 Sep 2023 09:09:39 +0000 X-Authority-Analysis: v=2.4 cv=J8G5USrS c=1 sm=1 tr=0 ts=65096553 a=2Y6h5+ypAxmHcsumz2f7Og==:117 a=2Y6h5+ypAxmHcsumz2f7Og==:17 a=pGLkceISAAAA:8 a=RPJ6JBhKAAAA:8 a=GiWcz6MfNhDLV59xR1kA:9 a=fa_un-3J20JGBB2Tu-mn:22 From: Andreas Dilger To: tytso@mit.edu Cc: linux-ext4@vger.kernel.org, Alexey Lyashkov , Andreas Dilger Subject: [PATCH 5/7] [v2] lib: deduplicate buffer_head/kernel emulation Date: Tue, 19 Sep 2023 03:09:31 -0600 Message-Id: <20230919090933.25567-1-adilger@dilger.ca> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4xfFNf+XYlraaCSOwcWcjBVUnqA/gwoTP0GS4pIyiwIuHwc1IHR1X/PONSPh/x54R4VUWXwtco3S9hnm29C1Hq1GGi6gZy/626K5XauC9AkACTTn7d3swA qDZQV+pDfAehPKDRo4RTmS1dT1kLdNOIiuP3/26wDhqf3oYNo3BGsGD+msrpVeqBS5C8a4OgZPktr5j2ZTneNzbT7ZBGMVMPqYa7KpypZ4XL3yK1Z+1AZvTH QDn9mR2exhoY0I6CW7EkYxMvRVgKPDM+CinFbFuH81BQBm2N/JrHzt3wDNoJkD9j X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Tue, 19 Sep 2023 02:09:46 -0700 (PDT) From: Alexey Lyashkov Move buffer_head and device code into libsupport to allow it to be shared between debugfs and e2fsck. Signed-off-by: Alexey Lyashkov Reviewed-by: Andreas Dilger --- debugfs/journal.c | 147 ---------------------------------------------- e2fsck/journal.c | 143 -------------------------------------------- 2 files changed, 290 deletions(-) diff --git a/debugfs/journal.c b/debugfs/journal.c index 8c84be25..6e8dec35 100644 --- a/debugfs/journal.c +++ b/debugfs/journal.c @@ -26,8 +26,6 @@ #include "uuid/uuid.h" #include "journal.h" -static int bh_count = 0; - #if EXT2_FLAT_INCLUDES #include "blkid.h" #else @@ -47,151 +45,6 @@ static int bh_count = 0; * to use the recovery.c file virtually unchanged from the kernel, so we * don't have to do much to keep kernel and user recovery in sync. */ -int jbd2_journal_bmap(journal_t *journal, unsigned long block, - unsigned long long *phys) -{ -#ifdef USE_INODE_IO - *phys = block; - return 0; -#else - struct inode *inode = journal->j_inode; - errcode_t retval; - blk64_t pblk; - - if (!inode) { - *phys = block; - return 0; - } - - retval = ext2fs_bmap2(inode->i_fs, inode->i_ino, - &inode->i_ext2, NULL, 0, (blk64_t) block, - 0, &pblk); - *phys = pblk; - return (int) retval; -#endif -} - -struct buffer_head *getblk(kdev_t kdev, unsigned long long blocknr, - int blocksize) -{ - struct buffer_head *bh; - int bufsize = sizeof(*bh) + kdev->k_fs->blocksize - - sizeof(bh->b_data); - errcode_t retval; - - retval = ext2fs_get_memzero(bufsize, &bh); - if (retval) - return NULL; - - if (journal_enable_debug >= 3) - bh_count++; - jfs_debug(4, "getblk for block %llu (%d bytes)(total %d)\n", - blocknr, blocksize, bh_count); - - bh->b_fs = kdev->k_fs; - if (kdev->k_dev == K_DEV_FS) - bh->b_io = kdev->k_fs->io; - else - bh->b_io = kdev->k_fs->journal_io; - bh->b_size = blocksize; - bh->b_blocknr = blocknr; - - return bh; -} - -int sync_blockdev(kdev_t kdev) -{ - io_channel io; - - if (kdev->k_dev == K_DEV_FS) - io = kdev->k_fs->io; - else - io = kdev->k_fs->journal_io; - - return io_channel_flush(io) ? EIO : 0; -} - -void ll_rw_block(int rw, int op_flags EXT2FS_ATTR((unused)), int nr, - struct buffer_head *bhp[]) -{ - errcode_t retval; - struct buffer_head *bh; - - for (; nr > 0; --nr) { - bh = *bhp++; - if (rw == REQ_OP_READ && !bh->b_uptodate) { - jfs_debug(3, "reading block %llu/%p\n", - bh->b_blocknr, (void *) bh); - retval = io_channel_read_blk64(bh->b_io, - bh->b_blocknr, - 1, bh->b_data); - if (retval) { - com_err(bh->b_fs->device_name, retval, - "while reading block %llu\n", - bh->b_blocknr); - bh->b_err = (int) retval; - continue; - } - bh->b_uptodate = 1; - } else if (rw == REQ_OP_WRITE && bh->b_dirty) { - jfs_debug(3, "writing block %llu/%p\n", - bh->b_blocknr, - (void *) bh); - retval = io_channel_write_blk64(bh->b_io, - bh->b_blocknr, - 1, bh->b_data); - if (retval) { - com_err(bh->b_fs->device_name, retval, - "while writing block %llu\n", - bh->b_blocknr); - bh->b_err = (int) retval; - continue; - } - bh->b_dirty = 0; - bh->b_uptodate = 1; - } else { - jfs_debug(3, "no-op %s for block %llu\n", - rw == REQ_OP_READ ? "read" : "write", - bh->b_blocknr); - } - } -} - -void mark_buffer_dirty(struct buffer_head *bh) -{ - bh->b_dirty = 1; -} - -static void mark_buffer_clean(struct buffer_head *bh) -{ - bh->b_dirty = 0; -} - -void brelse(struct buffer_head *bh) -{ - if (bh->b_dirty) - ll_rw_block(REQ_OP_WRITE, 0, 1, &bh); - jfs_debug(3, "freeing block %llu/%p (total %d)\n", - bh->b_blocknr, (void *) bh, --bh_count); - ext2fs_free_mem(&bh); -} - -int buffer_uptodate(struct buffer_head *bh) -{ - return bh->b_uptodate; -} - -void mark_buffer_uptodate(struct buffer_head *bh, int val) -{ - bh->b_uptodate = val; -} - -void wait_on_buffer(struct buffer_head *bh) -{ - if (!bh->b_uptodate) - ll_rw_block(REQ_OP_READ, 0, 1, &bh); -} - static void ext2fs_clear_recover(ext2_filsys fs, int error) { diff --git a/e2fsck/journal.c b/e2fsck/journal.c index d6129ed1..02251956 100644 --- a/e2fsck/journal.c +++ b/e2fsck/journal.c @@ -27,8 +27,6 @@ #include "problem.h" #include "uuid/uuid.h" -static int bh_count = 0; - /* * Define USE_INODE_IO to use the inode_io.c / fileio.c codepaths. * This creates a larger static binary, and a smaller binary using @@ -42,147 +40,6 @@ static int bh_count = 0; * to use the recovery.c file virtually unchanged from the kernel, so we * don't have to do much to keep kernel and user recovery in sync. */ -int jbd2_journal_bmap(journal_t *journal, unsigned long block, - unsigned long long *phys) -{ -#ifdef USE_INODE_IO - *phys = block; - return 0; -#else - struct inode *inode = journal->j_inode; - errcode_t retval; - blk64_t pblk; - - if (!inode) { - *phys = block; - return 0; - } - - retval= ext2fs_bmap2(inode->i_fs, inode->i_ino, - &inode->i_ext2, NULL, 0, (blk64_t) block, - 0, &pblk); - *phys = pblk; - return -1 * ((int) retval); -#endif -} - -struct buffer_head *getblk(kdev_t kdev, unsigned long long blocknr, - int blocksize) -{ - struct buffer_head *bh; - int bufsize = sizeof(*bh) + kdev->k_fs->blocksize - - sizeof(bh->b_data); - errcode_t retval; - - retval = ext2fs_get_memzero(bufsize, &bh); - if (retval) - return NULL; - - if (journal_enable_debug >= 3) - bh_count++; - jfs_debug(4, "getblk for block %llu (%d bytes)(total %d)\n", - blocknr, blocksize, bh_count); - - bh->b_fs = kdev->k_fs; - if (kdev->k_dev == K_DEV_FS) - bh->b_io = kdev->k_fs->io; - else - bh->b_io = kdev->k_fs->journal_io; - bh->b_size = blocksize; - bh->b_blocknr = blocknr; - - return bh; -} - -int sync_blockdev(kdev_t kdev) -{ - io_channel io; - - if (kdev->k_dev == K_DEV_FS) - io = kdev->k_fs->io; - else - io = kdev->k_fs->journal_io; - - return io_channel_flush(io) ? -EIO : 0; -} - -void ll_rw_block(int rw, int op_flags EXT2FS_ATTR((unused)), int nr, - struct buffer_head *bhp[]) -{ - errcode_t retval; - struct buffer_head *bh; - - for (; nr > 0; --nr) { - bh = *bhp++; - if (rw == REQ_OP_READ && !bh->b_uptodate) { - jfs_debug(3, "reading block %llu/%p\n", - bh->b_blocknr, (void *) bh); - retval = io_channel_read_blk64(bh->b_io, - bh->b_blocknr, - 1, bh->b_data); - if (retval) { - com_err(bh->b_fs->device_name, retval, - "while reading block %llu\n", - bh->b_blocknr); - bh->b_err = (int) retval; - continue; - } - bh->b_uptodate = 1; - } else if (rw == REQ_OP_WRITE && bh->b_dirty) { - jfs_debug(3, "writing block %llu/%p\n", - bh->b_blocknr, - (void *) bh); - retval = io_channel_write_blk64(bh->b_io, - bh->b_blocknr, - 1, bh->b_data); - if (retval) { - com_err(bh->b_fs->device_name, retval, - "while writing block %llu\n", - bh->b_blocknr); - bh->b_err = (int) retval; - continue; - } - bh->b_dirty = 0; - bh->b_uptodate = 1; - } else { - jfs_debug(3, "no-op %s for block %llu\n", - rw == REQ_OP_READ ? "read" : "write", - bh->b_blocknr); - } - } -} - -void mark_buffer_dirty(struct buffer_head *bh) -{ - bh->b_dirty = 1; -} - -void brelse(struct buffer_head *bh) -{ - if (bh->b_dirty) - ll_rw_block(REQ_OP_WRITE, 0, 1, &bh); - jfs_debug(3, "freeing block %llu/%p (total %d)\n", - bh->b_blocknr, (void *) bh, --bh_count); - ext2fs_free_mem(&bh); -} - -int buffer_uptodate(struct buffer_head *bh) -{ - return bh->b_uptodate; -} - -void mark_buffer_uptodate(struct buffer_head *bh, int val) -{ - bh->b_uptodate = val; -} - -void wait_on_buffer(struct buffer_head *bh) -{ - if (!bh->b_uptodate) - ll_rw_block(REQ_OP_READ, 0, 1, &bh); -} - - static void e2fsck_clear_recover(e2fsck_t ctx, int error) { ext2fs_clear_feature_journal_needs_recovery(ctx->fs->super); -- 2.25.1