Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp933122ybh; Wed, 11 Mar 2020 13:52:00 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuCL++sq8kj2xZbMcUMi9AdVSE4U5vNVniZX1ynjnBovccXbob0dZ8aad1ByOcMby0GEU8h X-Received: by 2002:a05:6808:8f1:: with SMTP id d17mr364046oic.105.1583959919885; Wed, 11 Mar 2020 13:51:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583959919; cv=none; d=google.com; s=arc-20160816; b=TG59MClZR5epyk/0dLyrxCpz9PgqR9p7A+4tLpP05vFmeiaJOKZBBhO2JCTgG1Oxqn SJbgV7GTWbziBFdqsQSYhdI8oh7qaurDOusiZ+IMITEa8E27p3tpYMQ3ynQ+vsBEW6Yl 0saO5nLj11IZPHo3lgo4JcmHDiBRpnZLButiCt1Jvj1oUsBTPD+dHygVTKCqC8SQH000 m4AtJGZenuKSt/QvHEvvQei7TtSKZs8Jang+2zP/l/3A7QXu663PTzRpG87eFgVBAfAK fQeKvJ4b+EruB3+0Ce2HgfipCxbh+XP39oN1JPbzRbD77/4u34e3ht4lNgdumzzvn0X2 mi8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=LpSP5qu9xOiTgx4uk2C233BP1jdQdXvn6PvwcE+4Y3c=; b=Ca1crBq/RFMDTkf6QFkvjAOovqdQ+o93IFIaJQDaLDYTEQg8uuGjygj6Byu4MNVOWz JKd13ugEWSYIDu/GQANuumXS8rEinmF6+hz1R96AQzU6XMSA0UD87WIHV+zuPe6NGeSf hl5J9ifrT8V3juSh4hbeZiHrFk/xMDMtTf851tKwiy4YazZQyI1yySEPs5cI8rrmZVjp 6XocqoSj7LhldWBy5+IfA3E7rBsecsmcsMEos4pIpEFnvQqJ1re1/fCkq/bGI3gOBGl8 vWRylTxdxOzbsslHdAXG+1or2EvkN+F2kqZYgTAd9i7AHFTltyYkz46n1ftKs/EKBpdq 7a1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=J7PE4T3z; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h25si643831ooa.9.2020.03.11.13.51.47; Wed, 11 Mar 2020 13:51:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=J7PE4T3z; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726873AbgCKUvD (ORCPT + 99 others); Wed, 11 Mar 2020 16:51:03 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:33928 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726713AbgCKUvD (ORCPT ); Wed, 11 Mar 2020 16:51:03 -0400 Received: by mail-qt1-f193.google.com with SMTP id 59so2703614qtb.1 for ; Wed, 11 Mar 2020 13:51:01 -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; bh=LpSP5qu9xOiTgx4uk2C233BP1jdQdXvn6PvwcE+4Y3c=; b=J7PE4T3zX2nkWdw5RIjL4Qn8qqFht9Tk2cAwhmK43IlQNolAUJUgjr4VNByDHakVeT UVJ0VgxsFxer7BhygznfbvDnMlmG+EjIzOtFzWEU6I1TYCgIj08sIHT10vQpcMo82pM3 XAxIBrWdIStEEIIAoBBh8kvzgYd506UkNZzs74V2ABjZwBQJCTQ2gj2TG4zdcQ0IOCMG tZ1zrXdCFB242vvk6cy9/umPk3vsqbCp1B+JBxD0rEfJkFjZrY6P1G2YPgel7718p5xZ XVqbllNL4hATLHpPpyFRznOzoH2gKfuhCfJnpg/DIDespLUjjfO9dpNsf/hL0T8R7y/h OXJw== 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; bh=LpSP5qu9xOiTgx4uk2C233BP1jdQdXvn6PvwcE+4Y3c=; b=VaFaHcpihlemjd84I71QuhyCcWLum3fUOabc4LOWp5YNvddsxr0bw3Ur1XDG0VsSXv P/l6VnvjUhL9dw7nJKQ5ORdIIATxq8/c6G6a/iycHm7juQRV9iARWto6qw3tPheSEdDI N2gajomCVwcAO9VdO/Eymns/OPTzdg+RwuWamKjTG02SZTZy7PpPO2aO+PhGjC95vJ5D 6OkLdMgwoSsRBU/oQytCbbBiOWDGlf5HTl83Rt/szNrGS5T5Vv61xeZsdmSfr7NRajfc 3OcNMqXjWgfHrHnnqoMJ0B2x80K2BM0vKJq+DtAfiQzPVeYKtf44pgfIDsltqkMJOaaQ nZqQ== X-Gm-Message-State: ANhLgQ3ezVvCbi13l1YpneQ5IUNYQKm5aGIbChpznFZg6gcu0HwAnmU+ 6aVjMqdh37eh/nGc2httgOaSZQx0 X-Received: by 2002:ac8:8e7:: with SMTP id y36mr4464631qth.26.1583959861297; Wed, 11 Mar 2020 13:51:01 -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 q24sm1958766qtk.45.2020.03.11.13.51.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Mar 2020 13:51:00 -0700 (PDT) From: Eric Whitney To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, Eric Whitney Subject: [PATCH] ext4: clean up ext4_ext_insert_extent() call in ext4_ext_map_blocks() Date: Wed, 11 Mar 2020 16:50:33 -0400 Message-Id: <20200311205033.25013-1-enwlinux@gmail.com> X-Mailer: git-send-email 2.11.0 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Now that the eofblocks code has been removed, we don't need to assign 0 to err before calling ext4_ext_insert_extent() since it will assign a return value to ret anyway. The variable free_on_err can be eliminated and replaced by a reference to allocated_clusters which clearly conveys the idea that newly allocated blocks should be freed when recovering from an extent insertion failure. The error handling code itself should be restructured so that it errors out immediately on an insertion failure in the case where no new blocks have been allocated (bigalloc) rather than proceeding further into the mapping code. The initializer for fb_flags can also be rearranged for improved readability. Finally, insert a missing space in nearby code. No known bugs are addressed by this patch - it's simply a cleanup. Signed-off-by: Eric Whitney --- fs/ext4/extents.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index bc96529d1509..c2743d024c11 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -4176,7 +4176,7 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, struct ext4_extent newex, *ex, *ex2; struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); ext4_fsblk_t newblock = 0; - int free_on_err = 0, err = 0, depth, ret; + int err = 0, depth, ret; unsigned int allocated = 0, offset = 0; unsigned int allocated_clusters = 0; struct ext4_allocation_request ar; @@ -4374,7 +4374,6 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, goto out2; ext_debug("allocate new block: goal %llu, found %llu/%u\n", ar.goal, newblock, allocated); - free_on_err = 1; allocated_clusters = ar.len; ar.len = EXT4_C2B(sbi, ar.len) - offset; if (ar.len > allocated) @@ -4385,23 +4384,28 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, ext4_ext_store_pblock(&newex, newblock + offset); newex.ee_len = cpu_to_le16(ar.len); /* Mark unwritten */ - if (flags & EXT4_GET_BLOCKS_UNWRIT_EXT){ + if (flags & EXT4_GET_BLOCKS_UNWRIT_EXT) { ext4_ext_mark_unwritten(&newex); map->m_flags |= EXT4_MAP_UNWRITTEN; } - err = 0; err = ext4_ext_insert_extent(handle, inode, &path, &newex, flags); + if (err) { + if (allocated_clusters) { + int fb_flags = 0; - if (err && free_on_err) { - int fb_flags = flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE ? - EXT4_FREE_BLOCKS_NO_QUOT_UPDATE : 0; - /* free data blocks we just allocated */ - /* not a good idea to call discard here directly, - * but otherwise we'd need to call it every free() */ - ext4_discard_preallocations(inode); - ext4_free_blocks(handle, inode, NULL, newblock, - EXT4_C2B(sbi, allocated_clusters), fb_flags); + /* + * free data blocks we just allocated. + * not a good idea to call discard here directly, + * but otherwise we'd need to call it every free(). + */ + ext4_discard_preallocations(inode); + if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) + fb_flags = EXT4_FREE_BLOCKS_NO_QUOT_UPDATE; + ext4_free_blocks(handle, inode, NULL, newblock, + EXT4_C2B(sbi, allocated_clusters), + fb_flags); + } goto out2; } -- 2.11.0