Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp925571pxb; Thu, 25 Feb 2021 20:18:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJyNDTlFXkuPjEMS/o+RlXt9VBVzLJlHv5ada6OkG04cJz2XzCzBDcltMEvgw+IdcDv4ZjA7 X-Received: by 2002:a17:906:1fc7:: with SMTP id e7mr1174228ejt.202.1614313123915; Thu, 25 Feb 2021 20:18:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614313123; cv=none; d=google.com; s=arc-20160816; b=VvLp3yIZWhaCrDwGnBRb+XnRXsmk8CiPW/4mFrJJF7q3KWgvTZFipaVMwIzG8NPERl xMJjVZu95vOSPD+Ktu8a4RlAZNGKO23usnvsaYM5MNFwsRuHQ8mBM9HCDTNypvKxb+Um WMjIl5CDDmsDLMPYlP7knhVSI5QQLuQxOWMHal0BzoScin7fEDQmTbxEeC/0bhAFGGte 5OXU2Ivbv9nmXmWMPpP1/4sActP6WYhH4gQqULZpIHV0w1ueryFCg5Nm9JSShMhVad4Q 0+kSHAcKkVzSeGRGEBdT1+LTn77pMDNfU1HRfHMLi7+YPdnX2hM9i5xdmHHS9bYKg7J2 XUuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=sh7L847pNTGoMzMLVEXBPDINiIGHQaZ+xN6ffvIiew8=; b=DoSxngfEjQK0w+9WiIG7RbUVKN9M3OUppyiRessEZXzrp9DkU0bkjGTjFOwUVEWa3/ mhFmnubbLavEA7xjhBV9Kox07iQvdQttYj3altl3az8WgnmJJODLorp3PmhoKJCVJrus BXi3Jljwu0iMt8CpPfQN/+Yf0q9e+c6bMFSva3NU6Z4I9OZirhuBaQIt/1z4dSuqdks8 DIiNXzRJHAbRNF0KWSvAxH1uiiFUPrSI8h7+SNLoQdHHYd4jv0EV7QnAazks5QTUkHpZ rplMRfm7uVfww6Tq9JYucSvJd2R8cuilpwYL1aD+5xO9xsb3srOKUcpnNOW6NIx0qI0h eFDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GaKlhVvb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c8si5200572ede.246.2021.02.25.20.18.19; Thu, 25 Feb 2021 20:18:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GaKlhVvb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229841AbhBZEP3 (ORCPT + 99 others); Thu, 25 Feb 2021 23:15:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:60660 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229492AbhBZEP1 (ORCPT ); Thu, 25 Feb 2021 23:15:27 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9227864EDC; Fri, 26 Feb 2021 04:14:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614312885; bh=sgWuxqBTz4uJmSaPMNWjznkck8E4uzq3eRWOtth4/Pk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=GaKlhVvbTBQ10wmdG8lJGORHMFm7ED+I2ZQh6j3TMj5vcfdLDA91LE6NAJU6sYUAQ PLQ/fdnQyVxpFDdaGoY8MBdg+9xQznfx/6tHoJIAPnTa5XymqVuRDgGDR9woUdGIt1 qR9bvxbSIdjDrVgZMmBG3RdSwbrzz2s14VpCvmDDxQir6273b544lhaey0J9JohhGF /F9PfucDLwp+H/egWwJ0jCumTfHCKrfrAlR7rN1QEeK4gDR++yhSE51klT4tcnTvSp QGkqBbHSLvEQYMwJNM9436fxTtc2kUqBJVmlSHPW//XR7cYfGQxa9nqGz78tOJbvah n5IabVC/GXYtw== Date: Thu, 25 Feb 2021 20:14:46 -0800 From: "Darrick J. Wong" To: Shiyang Ruan Cc: linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-nvdimm@lists.01.org, linux-fsdevel@vger.kernel.org, darrick.wong@oracle.com, dan.j.williams@intel.com, willy@infradead.org, jack@suse.cz, viro@zeniv.linux.org.uk, linux-btrfs@vger.kernel.org, ocfs2-devel@oss.oracle.com, david@fromorbit.com, hch@lst.de, rgoldwyn@suse.de Subject: Re: [PATCH v2 07/10] iomap: Introduce iomap_apply2() for operations on two files Message-ID: <20210226041446.GV7272@magnolia> References: <20210226002030.653855-1-ruansy.fnst@fujitsu.com> <20210226002030.653855-8-ruansy.fnst@fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210226002030.653855-8-ruansy.fnst@fujitsu.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 26, 2021 at 08:20:27AM +0800, Shiyang Ruan wrote: > Some operations, such as comparing a range of data in two files under > fsdax mode, requires nested iomap_open()/iomap_end() on two file. Thus, > we introduce iomap_apply2() to accept arguments from two files and > iomap_actor2_t for actions on two files. > > Signed-off-by: Shiyang Ruan > --- > fs/iomap/apply.c | 51 +++++++++++++++++++++++++++++++++++++++++++ > include/linux/iomap.h | 7 +++++- > 2 files changed, 57 insertions(+), 1 deletion(-) > > diff --git a/fs/iomap/apply.c b/fs/iomap/apply.c > index 26ab6563181f..fd2f8bde5791 100644 > --- a/fs/iomap/apply.c > +++ b/fs/iomap/apply.c > @@ -97,3 +97,54 @@ iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags, > > return written ? written : ret; > } > + > +loff_t > +iomap_apply2(struct inode *ino1, loff_t pos1, struct inode *ino2, loff_t pos2, > + loff_t length, unsigned int flags, const struct iomap_ops *ops, > + void *data, iomap_actor2_t actor) > +{ > + struct iomap smap = { .type = IOMAP_HOLE }; > + struct iomap dmap = { .type = IOMAP_HOLE }; > + loff_t written = 0, ret; > + > + ret = ops->iomap_begin(ino1, pos1, length, 0, &smap, NULL); > + if (ret) > + goto out_src; > + if (WARN_ON(smap.offset > pos1)) { > + written = -EIO; > + goto out_src; > + } > + if (WARN_ON(smap.length == 0)) { > + written = -EIO; > + goto out_src; > + } > + > + ret = ops->iomap_begin(ino2, pos2, length, 0, &dmap, NULL); > + if (ret) > + goto out_dest; > + if (WARN_ON(dmap.offset > pos2)) { > + written = -EIO; > + goto out_dest; > + } > + if (WARN_ON(dmap.length == 0)) { > + written = -EIO; > + goto out_dest; > + } > + > + /* make sure extent length of two file is equal */ > + if (WARN_ON(smap.length != dmap.length)) { Why not set smap.length and dmap.length to min(smap.length, dmap.length) ? --D > + written = -EIO; > + goto out_dest; > + } > + > + written = actor(ino1, pos1, ino2, pos2, length, data, &smap, &dmap); > + > +out_dest: > + if (ops->iomap_end) > + ret = ops->iomap_end(ino2, pos2, length, 0, 0, &dmap); > +out_src: > + if (ops->iomap_end) > + ret = ops->iomap_end(ino1, pos1, length, 0, 0, &smap); > + > + return ret; > +} > diff --git a/include/linux/iomap.h b/include/linux/iomap.h > index 5bd3cac4df9c..913f98897a77 100644 > --- a/include/linux/iomap.h > +++ b/include/linux/iomap.h > @@ -148,10 +148,15 @@ struct iomap_ops { > */ > typedef loff_t (*iomap_actor_t)(struct inode *inode, loff_t pos, loff_t len, > void *data, struct iomap *iomap, struct iomap *srcmap); > - > +typedef loff_t (*iomap_actor2_t)(struct inode *ino1, loff_t pos1, > + struct inode *ino2, loff_t pos2, loff_t len, void *data, > + struct iomap *smap, struct iomap *dmap); > loff_t iomap_apply(struct inode *inode, loff_t pos, loff_t length, > unsigned flags, const struct iomap_ops *ops, void *data, > iomap_actor_t actor); > +loff_t iomap_apply2(struct inode *ino1, loff_t pos1, struct inode *ino2, > + loff_t pos2, loff_t length, unsigned int flags, > + const struct iomap_ops *ops, void *data, iomap_actor2_t actor); > > ssize_t iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *from, > const struct iomap_ops *ops); > -- > 2.30.1 > > >