Received: by 2002:a05:6a10:8395:0:0:0:0 with SMTP id n21csp104013pxh; Tue, 9 Nov 2021 07:58:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJz3AZBPwqs1DKDLpJ+YljQsAlC6SCf2wYESbjWGMZmSbbJucjBb+hLlHBC+DEdwcldiNY/I X-Received: by 2002:a92:7607:: with SMTP id r7mr2749550ilc.317.1636473491433; Tue, 09 Nov 2021 07:58:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636473491; cv=none; d=google.com; s=arc-20160816; b=jKbguCaDwtavt76CMjTnXRTwQ4szFdH4DzFo6+Eyj297lFI2XglrvujtPftBdvNKJf ZhUpPytv1JlMcPV85lXaH1nguMlMQwsZXjZ3/XTKyWWiZQvtp5FSCvFNktvYOSeCCdSX vICty3eg0rH3aKU4gvWFsGwcrmtKK7yBCsu+Q9NVxGwvuNjU2A8lKz+WAWOkhZQg0JhA imaahVUFAeFxb4mi1mZ5RukDT4k5cS+j753jCs3h1GkZTbS5yAy0XZwd5PxuU31A7f1Y Tj7rY8ztBwNYieglXjb9zbdvqtjKFNk8/oSB0RwVKh953cH8hi72YMMvI7ARKoeuxdW2 Y9Yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SW8Zo8xNPpf5PRQj/yoxD2eK+vSZCdgKjxBBcNAut5E=; b=Qk4ntigpk46p8vymdJ0Va4f+/1vvZgZ4kcfbpev9oP3xZIda/4FV1erCv/MhSjTVsQ HkrR/jbc7+2FmNfCcOxP3qTR4sr/9i36sCUwoEjdzbiBvHvMYCzgda41OuWi0Vw+5g4j hl0lSfVDniwHN59sU4z6dKM7+R1q70OrsAU+nUlNUnpa6k/bLsOEg8mhqlbHlmQ0TNU5 KjBFgBbF/cMW8cqMF9hQcyy78daWdSA+K0+tdFjRBYyX6cnF0jYx96S+5yHRfDQj/vmU e+ev2sPfLj+y8SQi/bsqjIOO+dyHJIR6uZ5PkHj9X+U6CqNEsloasnZ0000zzengFzri 9g4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=IAd2z0n4; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e3si36937957ilu.146.2021.11.09.07.57.56; Tue, 09 Nov 2021 07:58:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-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=@infradead.org header.s=casper.20170209 header.b=IAd2z0n4; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244234AbhKIIgn (ORCPT + 99 others); Tue, 9 Nov 2021 03:36:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244192AbhKIIgi (ORCPT ); Tue, 9 Nov 2021 03:36:38 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D378AC0613F5; Tue, 9 Nov 2021 00:33:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=SW8Zo8xNPpf5PRQj/yoxD2eK+vSZCdgKjxBBcNAut5E=; b=IAd2z0n4+rSaZjOAQAcHkUiG7e AHKwIW3QT0BU34bqCQuvoimP884y7lMTrSi4ev67fFNWoK1dDvk5amFAb1n/57yJ+Cb+3n1zj4Gbe YQPgAi5L5rz7YsX4eE0j3hCuAMWPdWSq6kU6krKBw+bSRtv/zYPnHKCRNminIPWP6laGvD1ySu1/T onyeNMCfFyCWBxzeP2yuXUxNRqQg/kDKSkylEst+HmEWCXAPXsfje13JJ/FKQNbF/0EmnJ+G2P9v1 SSDU4goh3tuk4pjnxSDpwGrNlqzT2hYG7o05V7aC4jrXohtehEvjw1MAGEkXVzVVTQXeoF3k/MQXg T5uHRctQ==; Received: from [2001:4bb8:19a:7ee7:fb46:2fe1:8652:d9d4] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mkMZb-000s5r-P1; Tue, 09 Nov 2021 08:33:44 +0000 From: Christoph Hellwig To: Dan Williams Cc: Mike Snitzer , Ira Weiny , dm-devel@redhat.com, linux-xfs@vger.kernel.org, nvdimm@lists.linux.dev, linux-s390@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-erofs@lists.ozlabs.org, linux-ext4@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH 17/29] fsdax: factor out a dax_memzero helper Date: Tue, 9 Nov 2021 09:32:57 +0100 Message-Id: <20211109083309.584081-18-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211109083309.584081-1-hch@lst.de> References: <20211109083309.584081-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Factor out a helper for the "manual" zeroing of a DAX range to clean up dax_iomap_zero a lot. Signed-off-by: Christoph Hellwig --- fs/dax.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index d7a923d152240..dc9ebeff850ab 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -1121,34 +1121,36 @@ static vm_fault_t dax_pmd_load_hole(struct xa_state *xas, struct vm_fault *vmf, } #endif /* CONFIG_FS_DAX_PMD */ +static int dax_memzero(struct dax_device *dax_dev, pgoff_t pgoff, + unsigned int offset, size_t size) +{ + void *kaddr; + long rc; + + rc = dax_direct_access(dax_dev, pgoff, 1, &kaddr, NULL); + if (rc >= 0) { + memset(kaddr + offset, 0, size); + dax_flush(dax_dev, kaddr + offset, size); + } + return rc; +} + s64 dax_iomap_zero(loff_t pos, u64 length, struct iomap *iomap) { pgoff_t pgoff = dax_iomap_pgoff(iomap, pos); long rc, id; - void *kaddr; - bool page_aligned = false; unsigned offset = offset_in_page(pos); unsigned size = min_t(u64, PAGE_SIZE - offset, length); - if (IS_ALIGNED(pos, PAGE_SIZE) && size == PAGE_SIZE) - page_aligned = true; - id = dax_read_lock(); - - if (page_aligned) + if (IS_ALIGNED(pos, PAGE_SIZE) && size == PAGE_SIZE) rc = dax_zero_page_range(iomap->dax_dev, pgoff, 1); else - rc = dax_direct_access(iomap->dax_dev, pgoff, 1, &kaddr, NULL); - if (rc < 0) { - dax_read_unlock(id); - return rc; - } - - if (!page_aligned) { - memset(kaddr + offset, 0, size); - dax_flush(iomap->dax_dev, kaddr + offset, size); - } + rc = dax_memzero(iomap->dax_dev, pgoff, offset, size); dax_read_unlock(id); + + if (rc < 0) + return rc; return size; } -- 2.30.2