From patchwork Thu Apr 30 18:53:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Whitney X-Patchwork-Id: 1280814 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=i7RnkvTp; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49Cl063kBPz9sRf for ; Fri, 1 May 2020 04:53:42 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726487AbgD3Sxm (ORCPT ); Thu, 30 Apr 2020 14:53:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726318AbgD3Sxl (ORCPT ); Thu, 30 Apr 2020 14:53:41 -0400 Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5437C035494 for ; Thu, 30 Apr 2020 11:53:41 -0700 (PDT) Received: by mail-qt1-x841.google.com with SMTP id 71so5914614qtc.12 for ; Thu, 30 Apr 2020 11:53:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2pBREp5e/I8/ko671CpIgtMBV8fXR6QsUUzjXlMaVIs=; b=i7RnkvTpRlEKz90hCSCsLmG/vBg9oqv7AEE/eqQi4gHdhBKYM6DXnBQxcvc2EN5WCG F/L9oG4kwhXUhaI5C3BDT6JBtO9Rp9zGbWgj76Z+sg2eS7Zm1PugtwOLWS8eSoVYXUTi g9DBdcwV0qheZwfvy5Kf2iOWPFrKh153YBIQQkqOq2q5vgVvtH3MwyUpUdc2gGJG5pUc N865CvdlvI/zjNxhdcRcNcIIxHxp9YmDtoDLgo4PGg8h0EKbrjvsRJ9DwIWC1TUolEth 935491dx2NRMR6IUrZdpam4vc+q+OHOZHE1KOloWkJ+V2E89o3vvMAwcohZj/u6aXMiB gn2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2pBREp5e/I8/ko671CpIgtMBV8fXR6QsUUzjXlMaVIs=; b=UffrBcgV/doRky7hto9EX15bdkL3IWHD5fsArPADcbkpeSKOctBcgoX1GyBJWVd+Cw ddlPsND5bnSWouOAEBW0UvhzbJc/6R57uHRGpcUv+h8Vjed9dhZtC7VliPXMNnuxX8MR Ctkc4ROoN7KK6o96+6KzU5eFvYtVVuP+FmwFmZUolv03jrdpHb2Dmkxj15O1lvn3eAT8 dCDkaBX3QBvUOy8HrRM2ZxY1pQNfyhr+V5YojwwlHoP+JxVB80HUVdwlbuL0l0N30ZEm NVr81aUAiQ+Z1rRywC6xZVHYsC1/OfCBMJjthGPqw2lGQWojzLmO+ypODDzK4yEB4dKR xkEw== X-Gm-Message-State: AGi0PuaRiBrlbkrNleej39k9VttfE1McXBcISxxooviefeSno3gXn9d8 u3+2/fkjZTW1McmY2hBfpmqTkmYU X-Google-Smtp-Source: APiQypJ/tI81kw3Nvnr5pC/U3RCDCM+5tOxPhw/tpuQSZiXKGXKJcVorWrQ+WSkclE1tNhVgP/SWkg== X-Received: by 2002:ac8:f10:: with SMTP id e16mr5098939qtk.89.1588272820807; Thu, 30 Apr 2020 11:53:40 -0700 (PDT) Received: from localhost.localdomain (c-73-60-226-25.hsd1.nh.comcast.net. [73.60.226.25]) by smtp.gmail.com with ESMTPSA id u5sm695815qkm.116.2020.04.30.11.53.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 11:53:40 -0700 (PDT) From: Eric Whitney To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, Eric Whitney Subject: [PATCH 1/4] ext4: remove dead GET_BLOCKS_ZERO code Date: Thu, 30 Apr 2020 14:53:17 -0400 Message-Id: <20200430185320.23001-2-enwlinux@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200430185320.23001-1-enwlinux@gmail.com> References: <20200430185320.23001-1-enwlinux@gmail.com> MIME-Version: 1.0 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org There's no call to ext4_map_blocks() in the current ext4 code with a flags argument that combines EXT4_GET_BLOCKS_CONVERT and EXT4_GET_BLOCKS_ZERO. Remove the code that corresponds to this case from ext4_ext_handle_unwritten_extents(). Signed-off-by: Eric Whitney Reviewed-by: Ritesh Harjani --- fs/ext4/extents.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index f2b577b315a0..59a90492b9dd 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -3826,14 +3826,6 @@ ext4_ext_handle_unwritten_extents(handle_t *handle, struct inode *inode, } /* IO end_io complete, convert the filled extent to written */ if (flags & EXT4_GET_BLOCKS_CONVERT) { - if (flags & EXT4_GET_BLOCKS_ZERO) { - if (allocated > map->m_len) - allocated = map->m_len; - err = ext4_issue_zeroout(inode, map->m_lblk, newblock, - allocated); - if (err < 0) - goto out2; - } ret = ext4_convert_unwritten_extents_endio(handle, inode, map, ppath); if (ret >= 0) From patchwork Thu Apr 30 18:53:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Whitney X-Patchwork-Id: 1280815 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=qmUx+N5K; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49Cl085PDSz9sRf for ; Fri, 1 May 2020 04:53:44 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726488AbgD3Sxo (ORCPT ); Thu, 30 Apr 2020 14:53:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726318AbgD3Sxn (ORCPT ); Thu, 30 Apr 2020 14:53:43 -0400 Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7624C035494 for ; Thu, 30 Apr 2020 11:53:43 -0700 (PDT) Received: by mail-qt1-x842.google.com with SMTP id b1so5977635qtt.1 for ; Thu, 30 Apr 2020 11:53:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5zc5WLDaH0/OFz+swOtTEawhwZRfkWkP/YVekfgyaU4=; b=qmUx+N5KMxuGyyTm6c0m+gmAl/UeE7qimx7L8N0SCxIrHXEvOSx2iZ4Wge6Fzzansg I8VlxnyZeoPmsI7maRVlgA+rUfhQSh1gLM3yNZk8bnhGnH2f0lWsybPvXOa4hrVDI1Gm 0eh52IqPsN6ShoSP5MJ9Uy4O4v0wiR/x+f27b+zLapu8FmzmNpqM2RlnKbqP1AkxIDUU r4d+hIuue0GBYyIguVVR26hQGgJo7jmO9z4tswI2y+dG2OZOA/fSDB4gwN1jo6CkFgdZ Kg0nNiUF0qVqbQz/nm5eMLD8qInopZjxygg4lzUVAmKg5L03+ygAWqYgSv0lAETXcfIL qbwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5zc5WLDaH0/OFz+swOtTEawhwZRfkWkP/YVekfgyaU4=; b=uBHnolGyb5sULENs14qW/AMmfcXAoOZu1GcsRq8UEZdQQ8VglJzp5NTsKckZynVyyO EJhPwMcBeIihhwInpEVJ0RpH3i1QV/V+mV0SAyFLBoVlD/QAIex0hBFWY7OMHilUObvb ckl2rrpudhop5BLsPrGBrHiNcRVBjJHipxqkrz4NNjJQU/2vtMqYRuE+c7gZp25OlJIS ZNPACS/YvCLjYZpZy4k0T5aCn+WQGGwPwIfSZOv9nREd5KpD1+1HwHVVp6wPiGkBMlKg jH4YcUu2XRlAzPo7/r4FhWCPxfetqcYDZC03H1cwMzsNQH0+VCW80rMV7wO6KWswy/iP sMdQ== X-Gm-Message-State: AGi0PuYTjJs9kZTJk0GuWFAJqMahfkC6XwDevNJglRrevDN9l/HDL3oO qPSqZ6tZptU4RRmIBL7UDKCIPY3S X-Google-Smtp-Source: APiQypKwWXx8wiIB0hMGosFWvOHn7BSMVd7C3jERtq52yUMG+bSkql32gVaHhzSsiB17I7Ba3xWArQ== X-Received: by 2002:ac8:7204:: with SMTP id a4mr5257346qtp.324.1588272822873; Thu, 30 Apr 2020 11:53:42 -0700 (PDT) Received: from localhost.localdomain (c-73-60-226-25.hsd1.nh.comcast.net. [73.60.226.25]) by smtp.gmail.com with ESMTPSA id u5sm695815qkm.116.2020.04.30.11.53.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 11:53:42 -0700 (PDT) From: Eric Whitney To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, Eric Whitney Subject: [PATCH 2/4] ext4: remove redundant GET_BLOCKS_CONVERT code Date: Thu, 30 Apr 2020 14:53:18 -0400 Message-Id: <20200430185320.23001-3-enwlinux@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200430185320.23001-1-enwlinux@gmail.com> References: <20200430185320.23001-1-enwlinux@gmail.com> MIME-Version: 1.0 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Remove the redundant code assigning values to ext4_map_blocks components in ext4_ext_handle_unwritten_extents() for the EXT4_GET_BLOCKS_CONVERT case, using the code at the function exit instead. Clean up and reorder that code to eliminate more redundancy and improve readability. Signed-off-by: Eric Whitney --- fs/ext4/extents.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 59a90492b9dd..74aad2d77130 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -3826,20 +3826,14 @@ ext4_ext_handle_unwritten_extents(handle_t *handle, struct inode *inode, } /* IO end_io complete, convert the filled extent to written */ if (flags & EXT4_GET_BLOCKS_CONVERT) { - ret = ext4_convert_unwritten_extents_endio(handle, inode, map, + err = ext4_convert_unwritten_extents_endio(handle, inode, map, ppath); - if (ret >= 0) - ext4_update_inode_fsync_trans(handle, inode, 1); - else - err = ret; - map->m_flags |= EXT4_MAP_MAPPED; - map->m_pblk = newblock; - if (allocated > map->m_len) - allocated = map->m_len; - map->m_len = allocated; - goto out2; + if (err < 0) + goto out2; + ext4_update_inode_fsync_trans(handle, inode, 1); + goto map_out; } - /* buffered IO case */ + /* buffered IO cases */ /* * repeat fallocate creation request * we already have an unwritten extent @@ -3873,18 +3867,14 @@ ext4_ext_handle_unwritten_extents(handle_t *handle, struct inode *inode, } else allocated = ret; map->m_flags |= EXT4_MAP_NEW; - if (allocated > map->m_len) - allocated = map->m_len; - map->m_len = allocated; - map_out: map->m_flags |= EXT4_MAP_MAPPED; out1: + map->m_pblk = newblock; if (allocated > map->m_len) allocated = map->m_len; - ext4_ext_show_leaf(inode, path); - map->m_pblk = newblock; map->m_len = allocated; + ext4_ext_show_leaf(inode, path); out2: return err ? err : allocated; } From patchwork Thu Apr 30 18:53:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Whitney X-Patchwork-Id: 1280816 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=HYkJxRrJ; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49Cl0B1WYYz9sRf for ; Fri, 1 May 2020 04:53:46 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726517AbgD3Sxp (ORCPT ); Thu, 30 Apr 2020 14:53:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726318AbgD3Sxp (ORCPT ); Thu, 30 Apr 2020 14:53:45 -0400 Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79FCBC035494 for ; Thu, 30 Apr 2020 11:53:45 -0700 (PDT) Received: by mail-qt1-x844.google.com with SMTP id x12so5930321qts.9 for ; Thu, 30 Apr 2020 11:53:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eor7mAlAIoNUaULZeHdV3ZV59VkPBmqmTLyrGd7P8mk=; b=HYkJxRrJLzBxyv9jwgRkbW5Unb6ZY3QkMpSnTXOR35g7PXdZ7bQgbEFOFoaYcs/hyD BzcTsBYrmdoLcF4NH7bDJ1Jc/cJ3DoXhuj1acHo2ZEDPPLaac8OzFKdDQz58sJbL2yEg vSJ5oiO0M3sApe6sue0I4SJz6FF42ZXBquJMIZevJRTr+P/GrZbjKAjq3G26uA/2oxIu 9ZtBU8rdkVANh4iBShDWmogAOV7zq5G0tW1cU/kOWsm9sgdYRdlsYzvljOcOYxJWTm8e 3bf73rKcET8m8Llb+11VmOeKOEDmLlUi15wmVp+CgT6zra/6urnAvBt3fv1ois7FZTIx nKiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eor7mAlAIoNUaULZeHdV3ZV59VkPBmqmTLyrGd7P8mk=; b=uAKBTUeA8kqOnnW2OOM3G7T35vCQChX3Yy0r3zcewp5nbgfKaw9OZyn5WpFlzY/Hsn 7FdbgQr3DhQyW+5rkpe74hfxAUUxsNT3w3tlQpXOwdYsmqSyCfGUJxEztI4UAsdWUt5P xgIFVg20jmSApMpiJt+eR4K43RhceLrH69nQmNzdu+az07YwylpvqJCq5SuATe+IZhxa ial7p9SD3ajoEluAYx3EREx7erZKhjmaa7MkPTPs3G07gFWBwCIxXdRnhtWe/64+cGYc TcCJr19C4yvv4Z7A0aFmRL5EENl/uhB+vxuTI6YeXADQCRHrLiYmmoGJYTWwdjgUh1Sg raAg== X-Gm-Message-State: AGi0PuY5CX/18YxhRfmb661ONsie9noNz5sAC4vh04EpmSzj5KLFtpQD i2jrKwH8yHWjHsVoEqfHgUZALpjW X-Google-Smtp-Source: APiQypINq5aOHc4Mm9DxPjx21HOnNKGdJcpedYqUBkQWGKa/iW/Mu4S2FALgBJv++L61GEyuOArRVA== X-Received: by 2002:ac8:4b45:: with SMTP id e5mr5347069qts.86.1588272824593; Thu, 30 Apr 2020 11:53:44 -0700 (PDT) Received: from localhost.localdomain (c-73-60-226-25.hsd1.nh.comcast.net. [73.60.226.25]) by smtp.gmail.com with ESMTPSA id u5sm695815qkm.116.2020.04.30.11.53.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 11:53:44 -0700 (PDT) From: Eric Whitney To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, Eric Whitney Subject: [PATCH 3/4] ext4: clean up GET_BLOCKS_PRE_IO error handling Date: Thu, 30 Apr 2020 14:53:19 -0400 Message-Id: <20200430185320.23001-4-enwlinux@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200430185320.23001-1-enwlinux@gmail.com> References: <20200430185320.23001-1-enwlinux@gmail.com> MIME-Version: 1.0 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org If the call to ext4_split_convert_extents() fails in the EXT4_GET_BLOCKS_PRE_IO case within ext4_ext_handle_unwritten_extents(), error out through the exit point at function end rather than jumping through an intermediate point. Fix the error handling in the event ext4_split_convert_extents() returns 0, which it shouldn't do when splitting an existing extent. The current code returns the passed in value of allocated (which is likely non-zero) while failing to set m_flags, m_pblk, and m_len. Signed-off-by: Eric Whitney --- fs/ext4/extents.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 74aad2d77130..fc99f6c357cd 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -3815,12 +3815,25 @@ ext4_ext_handle_unwritten_extents(handle_t *handle, struct inode *inode, trace_ext4_ext_handle_unwritten_extents(inode, map, flags, allocated, newblock); - /* get_block() before submit the IO, split the extent */ + /* get_block() before submitting IO, split the extent */ if (flags & EXT4_GET_BLOCKS_PRE_IO) { ret = ext4_split_convert_extents(handle, inode, map, ppath, flags | EXT4_GET_BLOCKS_CONVERT); - if (ret <= 0) - goto out; + if (ret < 0) { + err = ret; + goto out2; + } + /* + * shouldn't get a 0 return when splitting an extent unless + * m_len is 0 (bug) or extent has been corrupted + */ + if (unlikely(ret == 0)) { + EXT4_ERROR_INODE(inode, + "unexpected ret == 0, m_len = %u", + map->m_len); + err = -EFSCORRUPTED; + goto out2; + } map->m_flags |= EXT4_MAP_UNWRITTEN; goto out; } @@ -3860,12 +3873,13 @@ ext4_ext_handle_unwritten_extents(handle_t *handle, struct inode *inode, ret = ext4_ext_convert_to_initialized(handle, inode, map, ppath, flags); if (ret >= 0) ext4_update_inode_fsync_trans(handle, inode, 1); -out: + if (ret <= 0) { err = ret; goto out2; - } else - allocated = ret; + } +out: + allocated = ret; map->m_flags |= EXT4_MAP_NEW; map_out: map->m_flags |= EXT4_MAP_MAPPED; From patchwork Thu Apr 30 18:53:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Whitney X-Patchwork-Id: 1280817 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=TuaDdIv/; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49Cl0D0stqz9sRf for ; Fri, 1 May 2020 04:53:48 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726519AbgD3Sxr (ORCPT ); Thu, 30 Apr 2020 14:53:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726318AbgD3Sxr (ORCPT ); Thu, 30 Apr 2020 14:53:47 -0400 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F5C4C035494 for ; Thu, 30 Apr 2020 11:53:47 -0700 (PDT) Received: by mail-qk1-x741.google.com with SMTP id t3so6884665qkg.1 for ; Thu, 30 Apr 2020 11:53:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5vVddqGsOmdchap23aulHNUzb9x3m+wzZQjd8/DLcK0=; b=TuaDdIv/dauINwTxVv4h7aGFKCCPm+iVC0wRrsK5w4yzXdcGvKal8DnYhlDZs8pz9/ Eo/H8IfXzPLsus1wF2p5Eu/9FtESkVRAbx1RM4OJ5ewuNEj0CCY9DAi0Cy29ppH4wPIY 7pr4YMvZ7rQjv8wAGfA3GTy/5jrYbOVpXSZcPXuWgYJXholcBQ4HJ/dVaEVrtce5V1y0 xYCvHiui9GmyXU3IOjjdfkqta2erIrGZgs9+rSn01gDTSE44qamrNoLodo6cd/hBBEPB U+uFQFkdGEi3MPF2ulGV63tfvRoEBx+9QgcgLXLcgNwkyofCJw80/D4Myr7e80/77JrL LBgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5vVddqGsOmdchap23aulHNUzb9x3m+wzZQjd8/DLcK0=; b=jBM80AfEoTotzgqVwqopoX+40qjDLvLgFPKOoSklMxl+JQ+G4MZu0ltqfYHVBp4i/Q eazo5lD6cRW7f9z29fWX00JYYK9zw2Mrz+5WPWBzfMq9O3nXjShd+V12/hFdSgxVxx7H b3Yh+VMiKfa2Skhjk0GF4lBABVG0UFzaphUXKlse1EK6yTzjfvlZYhIFhrG69EkcahUm zqQuIvuJTnMT3Qp1S6bif47a39QZaXcEMtMg2Y7K4DO3c103/UTWL5mn8RPHvjvYErHv IF5HKTIQup5FVjXs/SLhLQKRUu8BkrMv7xAArHv93nklrNEKlX+m+tWetgVtn5Dzh+/v fMeQ== X-Gm-Message-State: AGi0PuY/XGuHL2uDz5c5r4HwH1fwRKzCSe0coX6OFv2Qg31jEPZcEzSy uTgrI3JmV8IqEF2dboJ1NeK1Xzhk X-Google-Smtp-Source: APiQypJy6wN9aVc1l/m74Alxw++4ZMB3byOdZEAe7PMjn4ykCRUR1+Bc7uCSI49pHTsHmQa1ThkfXg== X-Received: by 2002:a05:620a:758:: with SMTP id i24mr4978480qki.46.1588272826495; Thu, 30 Apr 2020 11:53:46 -0700 (PDT) Received: from localhost.localdomain (c-73-60-226-25.hsd1.nh.comcast.net. [73.60.226.25]) by smtp.gmail.com with ESMTPSA id u5sm695815qkm.116.2020.04.30.11.53.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 11:53:46 -0700 (PDT) From: Eric Whitney To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, Eric Whitney Subject: [PATCH 4/4] ext4: clean up ext4_ext_convert_to_initialized() error handling Date: Thu, 30 Apr 2020 14:53:20 -0400 Message-Id: <20200430185320.23001-5-enwlinux@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200430185320.23001-1-enwlinux@gmail.com> References: <20200430185320.23001-1-enwlinux@gmail.com> MIME-Version: 1.0 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org If ext4_ext_convert_to_initialized() fails when called within ext4_ext_handle_unwritten_extents(), immediately error out through the exit point at function end. Fix the error handling in the event ext4_ext_convert_to_initialized() returns 0, which it shouldn't do when converting an existing extent. The current code returns the passed in value of allocated (which is likely non-zero) while failing to set m_flags, m_pblk, and m_len. Signed-off-by: Eric Whitney --- fs/ext4/extents.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index fc99f6c357cd..202787977e3d 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -3869,15 +3869,28 @@ ext4_ext_handle_unwritten_extents(handle_t *handle, struct inode *inode, goto out1; } - /* buffered write, writepage time, convert*/ + /* + * Default case when (flags & EXT4_GET_BLOCKS_CREATE) == 1. + * For buffered writes, at writepage time, etc. Convert a + * discovered unwritten extent to written. + */ ret = ext4_ext_convert_to_initialized(handle, inode, map, ppath, flags); - if (ret >= 0) - ext4_update_inode_fsync_trans(handle, inode, 1); - - if (ret <= 0) { + if (ret < 0) { err = ret; goto out2; } + ext4_update_inode_fsync_trans(handle, inode, 1); + /* + * shouldn't get a 0 return when converting an unwritten extent + * unless m_len is 0 (bug) or extent has been corrupted + */ + if (unlikely(ret == 0)) { + EXT4_ERROR_INODE(inode, "unexpected ret == 0, m_len = %u", + map->m_len); + err = -EFSCORRUPTED; + goto out2; + } + out: allocated = ret; map->m_flags |= EXT4_MAP_NEW;