From patchwork Sat Mar 25 06:56:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhanchengbin X-Patchwork-Id: 1761027 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=gandalf.ozlabs.org; envelope-from=srs0=nwpa=7r=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pk8zj2Kd2z1yYQ for ; Sat, 25 Mar 2023 17:58:09 +1100 (AEDT) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Pk8zj1pSRz4x7y for ; Sat, 25 Mar 2023 17:58:09 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4Pk8zj1mXdz4xDh; Sat, 25 Mar 2023 17:58:09 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Pk8zj1hT7z4x7y for ; Sat, 25 Mar 2023 17:58:09 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231932AbjCYG6H (ORCPT ); Sat, 25 Mar 2023 02:58:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231443AbjCYG6E (ORCPT ); Sat, 25 Mar 2023 02:58:04 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB79E166FD for ; Fri, 24 Mar 2023 23:57:54 -0700 (PDT) Received: from dggpeml500016.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Pk8yw2vn3zKncm; Sat, 25 Mar 2023 14:57:28 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggpeml500016.china.huawei.com (7.185.36.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Sat, 25 Mar 2023 14:57:53 +0800 From: zhanchengbin To: CC: , , , , zhanchengbin Subject: [PATCH 1/2] lib/ext2fs: add error handle in unix_flush and unix_write_byte Date: Sat, 25 Mar 2023 14:56:51 +0800 Message-ID: <20230325065652.2111384-2-zhanchengbin1@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230325065652.2111384-1-zhanchengbin1@huawei.com> References: <20230325065652.2111384-1-zhanchengbin1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpeml500016.china.huawei.com (7.185.36.70) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED, 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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org As you can see, a new error handling has been added for fsync, and the error handling for unix_write_byte function has reused the error handling of write_blk. Signed-off-by: zhanchengbin --- lib/ext2fs/ext2_io.h | 2 ++ lib/ext2fs/unix_io.c | 37 ++++++++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/lib/ext2fs/ext2_io.h b/lib/ext2fs/ext2_io.h index 679184e3..becd7078 100644 --- a/lib/ext2fs/ext2_io.h +++ b/lib/ext2fs/ext2_io.h @@ -56,6 +56,8 @@ struct struct_io_channel { size_t size, int actual_bytes_written, errcode_t error); + errcode_t (*sync_error)(io_channel channel, + errcode_t error); int refcount; int flags; long reserved[14]; diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c index 3171c736..283b4eb6 100644 --- a/lib/ext2fs/unix_io.c +++ b/lib/ext2fs/unix_io.c @@ -1250,7 +1250,8 @@ static errcode_t unix_write_byte(io_channel channel, unsigned long offset, #ifdef ALIGN_DEBUG printf("unix_write_byte: O_DIRECT fallback\n"); #endif - return EXT2_ET_UNIMPLEMENTED; + retval = EXT2_ET_UNIMPLEMENTED; + goto error_out; } #ifndef NO_IO_CACHE @@ -1258,19 +1259,30 @@ static errcode_t unix_write_byte(io_channel channel, unsigned long offset, * Flush out the cache completely */ if ((retval = flush_cached_blocks(channel, data, FLUSH_INVALIDATE))) - return retval; + goto error_out; #endif - if (lseek(data->dev, offset + data->offset, SEEK_SET) < 0) - return errno; + if (lseek(data->dev, offset + data->offset, SEEK_SET) < 0) { + retval = errno; + goto error_out; + } actual = write(data->dev, buf, size); - if (actual < 0) - return errno; - if (actual != size) - return EXT2_ET_SHORT_WRITE; - + if (actual < 0) { + retval = errno; + goto error_out; + } + if (actual != size) { + retval = EXT2_ET_SHORT_WRITE; + goto error_out; + } return 0; +error_out: + if (channel->write_error) + retval = (channel->write_error)(channel, + offset / channel->block_size, 0, buf, + size, actual, retval); + return retval; } /* @@ -1289,8 +1301,11 @@ static errcode_t unix_flush(io_channel channel) retval = flush_cached_blocks(channel, data, 0); #endif #ifdef HAVE_FSYNC - if (!retval && fsync(data->dev) != 0) - return errno; + if (!retval && fsync(data->dev) != 0) { + if (channel->sync_error) + retval = (channel->sync_error)(channel, errno); + return retval; + } #endif return retval; } From patchwork Sat Mar 25 06:56:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhanchengbin X-Patchwork-Id: 1761025 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=gandalf.ozlabs.org; envelope-from=srs0=nwpa=7r=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pk8zj14fHz1yY7 for ; Sat, 25 Mar 2023 17:58:09 +1100 (AEDT) Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Pk8zj01zGz4x7y for ; Sat, 25 Mar 2023 17:58:09 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4Pk8zh757Vz4xDh; Sat, 25 Mar 2023 17:58:08 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Pk8zh706qz4x7y for ; Sat, 25 Mar 2023 17:58:08 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231915AbjCYG6F (ORCPT ); Sat, 25 Mar 2023 02:58:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231867AbjCYG6E (ORCPT ); Sat, 25 Mar 2023 02:58:04 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68DD9B9 for ; Fri, 24 Mar 2023 23:57:55 -0700 (PDT) Received: from dggpeml500016.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Pk8vN1m56zSp3T; Sat, 25 Mar 2023 14:54:24 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggpeml500016.china.huawei.com (7.185.36.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Sat, 25 Mar 2023 14:57:53 +0800 From: zhanchengbin To: CC: , , , , zhanchengbin Subject: [PATCH 2/2] e2fsck: add sync error handle to e2fsck. Date: Sat, 25 Mar 2023 14:56:52 +0800 Message-ID: <20230325065652.2111384-3-zhanchengbin1@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230325065652.2111384-1-zhanchengbin1@huawei.com> References: <20230325065652.2111384-1-zhanchengbin1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpeml500016.china.huawei.com (7.185.36.70) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED, 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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org If fsync fails during fsck, it is silent and users will not perceive it, so a function to handle fsync failure should be added to fsck. Signed-off-by: zhanchengbin --- e2fsck/ehandler.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/e2fsck/ehandler.c b/e2fsck/ehandler.c index 71ca301c..ae35f3ef 100644 --- a/e2fsck/ehandler.c +++ b/e2fsck/ehandler.c @@ -118,6 +118,29 @@ static errcode_t e2fsck_handle_write_error(io_channel channel, return error; } +static errcode_t e2fsck_handle_sync_error(io_channel channel, + errcode_t error) +{ + ext2_filsys fs = (ext2_filsys) channel->app_data; + e2fsck_t ctx; + + ctx = (e2fsck_t) fs->priv_data; + if (ctx->flags & E2F_FLAG_EXITING) + return 0; + + if (operation) + printf(_("Error sync (%s) while %s. "), + error_message(error), operation); + else + printf(_("Error sync (%s). "), + error_message(error)); + preenhalt(ctx); + if (ask(ctx, _("Ignore error"), 1)) + return 0; + + return error; +} + const char *ehandler_operation(const char *op) { const char *ret = operation; @@ -130,4 +153,5 @@ void ehandler_init(io_channel channel) { channel->read_error = e2fsck_handle_read_error; channel->write_error = e2fsck_handle_write_error; + channel->sync_error = e2fsck_handle_sync_error; }