Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp5548774ybe; Tue, 10 Sep 2019 05:35:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzDS845PxkC3NMpaea2i9QpUDELa12KwF3smFbfsQjpF1aqUZzkgNfh42xu1SoS4QiqQDb8 X-Received: by 2002:aa7:c80e:: with SMTP id a14mr12457257edt.205.1568118936114; Tue, 10 Sep 2019 05:35:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568118936; cv=none; d=google.com; s=arc-20160816; b=yxLmbgN5tFyx1fWK+ryvBizT2fgSmQ9emAeIhJP4J518gbzCyhZdR/GQyWAWXjRN9R 0XDn4xmS4l5QrWnd2KrgwXyv4w6MVJePSV++MaV+5SAagerd6lK4+eiXC23pd2dToKUD mNUNcFcD8FZmahWR+EZIPsqnBYhtINjzqxuzh2qWU8d3kon3hEwjgAzzWmtr4kZR/P7N xK63zRy3GWfngMZJf7dtPcwNX+F8LXzMjO9PARTuLadKlndaCBhQrIjvd9UzQXTOL21e uRhS2eEM65kzlAwFY9Qh8oFdZsf0fEknvMIRMM80XKbXv8z2JOpx4qqeNyKntkTasiJs zIFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=xpMwYrMj0JCUefC3R/F8uLVaeqHT3pdUsMCxxoo34M0=; b=JFlSmo3qXZktE4bkcGJ93VTDxn1vOhG3QVGHxSFH5E6ARIE6QoeKxO5BouRcuijxvi q/GeEsotFFiH6Ruk2CgbjX7CkQ6R+xCosPUnpL/KxsPXzqkK+tA5Lueg2/TuovGyFz6c eEk+kXZAR59S4+ei5JlIVhtu/miv0BL9o51f8oA9P64KU2c7SDH70M2xtr+bIQXNMixf l+lA8+llUnhjoFl/aKo0bxk3d8ao5kMpK8jfMBCd1WPrXKmN1hygPMRubV67nZ63L+LZ xRYIihonEmjYYMTBm9XRCeEV+JylchYAaNfdvScjTg5AgD8JkvJG7tBv6RBFKtWB0J0D QOfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mbobrowski-org.20150623.gappssmtp.com header.s=20150623 header.b=Q6a3ZtUH; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l6si8082705eds.67.2019.09.10.05.35.01; Tue, 10 Sep 2019 05:35:36 -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=@mbobrowski-org.20150623.gappssmtp.com header.s=20150623 header.b=Q6a3ZtUH; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729483AbfIJK04 (ORCPT + 99 others); Tue, 10 Sep 2019 06:26:56 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:33587 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727351AbfIJK04 (ORCPT ); Tue, 10 Sep 2019 06:26:56 -0400 Received: by mail-pf1-f195.google.com with SMTP id q10so11286455pfl.0 for ; Tue, 10 Sep 2019 03:26:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mbobrowski-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=xpMwYrMj0JCUefC3R/F8uLVaeqHT3pdUsMCxxoo34M0=; b=Q6a3ZtUHh+oF3nS4bd+r59coZ8xc8KJc3o6GYoeEFOVXK9asgswP5jGwNxVDw5f2rF pnu2F5Q7VURa+qhPdvX5rF6AZ6SG/X4H8CDtifIA5BSU81Fk7dRaAEBJP+d2qWHlF89d oTCbH+IrQUYJlBBsgi2qErquc1IxgzZt8cN+ty/OJ9KXPANmauYg7QLzRoadX0FkXF1z God2D0UKfz5khWVgPh3x0mUwkWgVXKu/Son1ML2GcY2BAX8POr9+Qyl3FUQS2TRvhG3M S/ufvzusja7sYgp3mCA1k3cArBrgIl5BVjlYpkz/7yHln29dcYZzqNRg5NJ8Yg6EFR6/ QvHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=xpMwYrMj0JCUefC3R/F8uLVaeqHT3pdUsMCxxoo34M0=; b=NYwuYTueVyEwMAmQsTrLT5AzMUyDvAvVIV4B8Rr5AwthIIKkVE+BEmi9UzElRs9Ol1 Krh+7aX7RXy7mK6gbmms0n0PcPaaVzIb4E9jGKJmUKQ1HCP4FNxHxI4CPK9zmKEJQ3CZ cm7YFOCvR0lemJQloezRSoCj21+5Ka8fVHoma5rTJ+9948Aw3v0oXUjLeNCBo6V4T2rk 90v+9mNDoTEpgzoO29hfXAqkoh7nx+sCEAUoXv5mCV6u2iip8bawjHH59gcRPxvYAvpG XaUND+g1IgKBLgLKPA30rB5rUVkWPlyj4TG0TrJCFBrHEz/hJiF7YQL/zczQ+RjMyLGO XR3w== X-Gm-Message-State: APjAAAWBJIhjI3r43WU1t2PZKw5w4cG9kkW3oiVlRvksdMyi+TNORA27 +Dx8DQ3W/rEH3jIpVb0905VF X-Received: by 2002:a65:56c1:: with SMTP id w1mr26518414pgs.395.1568111209986; Tue, 10 Sep 2019 03:26:49 -0700 (PDT) Received: from bobrowski ([110.232.114.101]) by smtp.gmail.com with ESMTPSA id h1sm22770149pfk.124.2019.09.10.03.26.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 03:26:49 -0700 (PDT) Date: Tue, 10 Sep 2019 20:26:43 +1000 From: Matthew Bobrowski To: Ritesh Harjani Cc: tytso@mit.edu, jack@suse.cz, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, david@fromorbit.com, hch@infradead.org, darrick.wong@oracle.com Subject: Re: [PATCH v2 2/6] ext4: move inode extension/truncate code out from ext4_iomap_end() Message-ID: <20190910102643.GA9013@bobrowski> References: <20190909081729.3555C42041@d06av24.portsmouth.uk.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190909081729.3555C42041@d06av24.portsmouth.uk.ibm.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Mon, Sep 09, 2019 at 01:47:28PM +0530, Ritesh Harjani wrote: > On 9/9/19 4:49 AM, Matthew Bobrowski wrote: > > +static int ext4_handle_inode_extension(struct inode *inode, loff_t offset, > > + ssize_t len, size_t count) > > +{ > > + handle_t *handle; > > + bool truncate = false; > > + ext4_lblk_t written_blk, end_blk; > > + int ret = 0, blkbits = inode->i_blkbits; > > + > > + handle = ext4_journal_start(inode, EXT4_HT_INODE, 2); > > + if (IS_ERR(handle)) { > > + ret = PTR_ERR(handle); > > + goto orphan_del; > > + } > > + > > + if (ext4_update_inode_size(inode, offset + len)) > > + ext4_mark_inode_dirty(handle, inode); > > + > > + /* > > + * We may need truncate allocated but not written blocks > > + * beyond EOF. > > + */ > > + written_blk = ALIGN(offset + len, 1 << blkbits); > > + end_blk = ALIGN(offset + len + count, 1 << blkbits); > > why add len in end_blk calculation? > shouldn't this be like below? > end_blk = ALIGN(offset + count, 1 << blkbits); I don't believe that would be entirely correct. The reason being is that the 'end_blk' is meant to represent the last logical block which we should expect to have used for the write operation. So, we have the 'offset' which represents starting point, 'len' which is the amount of data that has been written, and 'count' which is the amount of data that we still have left over in the 'iter', if any. The count in the 'iter' is decremented as that data is copied from it. So if we did use 'offset' + 'count', in the instance of a short write, we potentially wouldn't truncate any of the allocated but not written blocks. I guess this would hold true for the DAX code path at this point, seeing as though for the DIO case we pass in '0'. > > +/* > > + * The inode may have been placed onto the orphan list or has had > > + * blocks allocated beyond EOF as a result of an extension. We need to > > + * ensure that any necessary cleanup routines are performed if the > > + * error path has been taken for a write. > > + */ > > +static int ext4_handle_failed_inode_extension(struct inode *inode, loff_t size) > > +{ > > + int ret = 0; > > No need of ret anyways. > > > > + handle_t *handle; > > + > > + if (size > i_size_read(inode)) > > + ext4_truncate_failed_write(inode); > > + > > + if (!list_empty(&EXT4_I(inode)->i_orphan)) { > > + handle = ext4_journal_start(inode, EXT4_HT_INODE, 2); > > + if (IS_ERR(handle)) { > > + if (inode->i_nlink) > > + ext4_orphan_del(NULL, inode); > > + return PTR_ERR(handle); > > + } > > + if (inode->i_nlink) > > + ext4_orphan_del(handle, inode); > > + ext4_journal_stop(handle); > > + } > > + return ret; > > can directly call for `return 0;` True. ----