Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp903990ybp; Wed, 9 Oct 2019 06:06:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqxI7jqaZ/XeGmWVSlF87fkrhV0KcPWy3AG/u6pyxL/X+WvXleJGajSkDWjsGM1/iAw+rQJG X-Received: by 2002:a50:cb86:: with SMTP id k6mr2903280edi.270.1570626404110; Wed, 09 Oct 2019 06:06:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570626404; cv=none; d=google.com; s=arc-20160816; b=v2iEX2Vn8yfPH90oIjTHn+rlNIyE4V3xX7/7WaQwgIBwVw1n2wLNZ+8KZ3XJpsPoHo n3fJl8HWYH0G3xVYRgbGHC1k2Hnnk1FaRboye6qpKkmVatDPtCXk2KblGW/yJvYvB/0o /8+G+yK2+P+mhk0hf5PTjACqiOcpPPbpTjvEacQitXrA37JSl28ek0TxBqLeo+VZovPN /A0RtzoYVh3s3oQO3B5MYtHXlrr1HrVFiVWp8FBe7uikE+/L5Torcs0/my51or9Tszej R8NEtwCWAH/ZT6dASDMXUNyUg0wPG35Cg1JCaCBbURNvMmgJuYRnqQ9Lc2GAdOrMaWqH qW7w== 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; bh=Jt0TM3PzfltHRK7acAzPauqtPxt2PUcx3D6ACMAVrRw=; b=w8kMwTm5d30MNOHF3xYQiob8dMrpKMWWTN1f7v/oJtdBPABAXdJwjl+6Qk7DfAOQBj 0DW6wBDY0cIHY+uTCc6WzIe3oDvXyJbWCnzEVlH4VoQpGZtoXwcZhCCrQxJHVYdB+4z9 K2AYO/i1foIHV/M7fDFAuKS4CeDCrfTXWh/PQURP5XVcsUlqMql5QVoWhPDL/O5zKpfS eLS7UrY6EHIckqE+hbbbfBttPOrOsskT+TX5QtCzkM7c3EowHPjAJnMwbzzmsJcApoT2 Y5dO9BrJOXENyYr3OB9Qz3Rbcans5iFzW8eJvTsWjzQueYdSHFEpX42TxyF2+APGeJ5G /0xw== ARC-Authentication-Results: i=1; mx.google.com; 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 q13si1106877eju.46.2019.10.09.06.06.14; Wed, 09 Oct 2019 06:06:44 -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; 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 S1731224AbfJINGN (ORCPT + 99 others); Wed, 9 Oct 2019 09:06:13 -0400 Received: from mx2.suse.de ([195.135.220.15]:34158 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730858AbfJINGN (ORCPT ); Wed, 9 Oct 2019 09:06:13 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 5F941AE55; Wed, 9 Oct 2019 13:06:10 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id B732B1E4851; Wed, 9 Oct 2019 15:06:09 +0200 (CEST) Date: Wed, 9 Oct 2019 15:06:09 +0200 From: Jan Kara To: Matthew Bobrowski Cc: Jan Kara , tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, hch@infradead.org, david@fromorbit.com, darrick.wong@oracle.com Subject: Re: [PATCH v4 1/8] ext4: move out iomap field population into separate helper Message-ID: <20191009130609.GD5050@quack2.suse.cz> References: <8b4499e47bea3841194850e1b3eeb924d87e69a5.1570100361.git.mbobrowski@mbobrowski.org> <20191008102709.GD5078@quack2.suse.cz> <20191009085721.GA1534@poseidon.bobrowski.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191009085721.GA1534@poseidon.bobrowski.net> 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 Wed 09-10-19 19:57:23, Matthew Bobrowski wrote: > On Tue, Oct 08, 2019 at 12:27:09PM +0200, Jan Kara wrote: > > On Thu 03-10-19 21:33:09, Matthew Bobrowski wrote: > > > +static int ext4_set_iomap(struct inode *inode, struct iomap *iomap, u16 type, > > > + unsigned long first_block, struct ext4_map_blocks *map) > > > +{ > > > + u8 blkbits = inode->i_blkbits; > > > + > > > + iomap->flags = 0; > > > + if (ext4_inode_datasync_dirty(inode)) > > > + iomap->flags |= IOMAP_F_DIRTY; > > > + iomap->bdev = inode->i_sb->s_bdev; > > > + iomap->dax_dev = EXT4_SB(inode->i_sb)->s_daxdev; > > > + iomap->offset = (u64) first_block << blkbits; > > > + iomap->length = (u64) map->m_len << blkbits; > > > + > > > + if (type) { > > > + iomap->type = type; > > > + iomap->addr = IOMAP_NULL_ADDR; > > > + } else { > > > + if (map->m_flags & EXT4_MAP_MAPPED) { > > > + iomap->type = IOMAP_MAPPED; > > > + } else if (map->m_flags & EXT4_MAP_UNWRITTEN) { > > > + iomap->type = IOMAP_UNWRITTEN; > > > + } else { > > > + WARN_ON_ONCE(1); > > > + return -EIO; > > > + } > > > + iomap->addr = (u64) map->m_pblk << blkbits; > > > + } > > > > Looking at this function now, the 'type' argument looks a bit weird. Can we > > perhaps just remove the 'type' argument and change the above to: > > We can, but refer to the point below. > > > if (map->m_flags & (EXT4_MAP_MAPPED | EXT4_MAP_UNWRITTEN)) { > > if (map->m_flags & EXT4_MAP_MAPPED) > > iomap->type = IOMAP_MAPPED; > > else if (map->m_flags & EXT4_MAP_UNWRITTEN) > > iomap->type = IOMAP_UNWRITTEN; > > iomap->addr = (u64) map->m_pblk << blkbits; > > } else { > > iomap->type = IOMAP_HOLE; > > iomap->addr = IOMAP_NULL_ADDR; > > } > > > > And then in ext4_iomap_begin() we overwrite the type to: > > > > if (delalloc && iomap->type == IOMAP_HOLE) > > iomap->type = IOMAP_DELALLOC; > > > > That would IMO make ext4_set_iomap() arguments harder to get wrong. > > I was thinking about this while doing a bunch of other things at work > today. I'm kind of aligned with what Christoph mentioned around > possibly duplicating some of the post 'iomap->type' setting from both > current and any future ext4_set_iomap() callers. In addition to this, > my thought was that if we're populating the iomap structure with > values respectively, then it would make most sense to encapsulate > those routines, if possible, within the ext4_set_iomap() as that's the > sole purpose of the function. Well, what I dislike about 'type' argument is the inconsistency in it's handling. It is useful only for HOLE/DELALLOC, anything else will just give you invalid iomap and you have to be careful to pass 0 in that case. I understand the concern about possible duplication but since only IOMAP_REPORT cares about IOMAP_DELALLOC, I'm not much concerned about it. But another sensible API would be to optionally pass 'struct extent_status *es' argument to ext4_set_iomap() and if this argument is non-NULL, ext4_set_iomap() will handle the intersection of ext4_map_blocks and extent_status and deduce appropriate resulting type from that. Honza -- Jan Kara SUSE Labs, CR