Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp878806rdb; Tue, 30 Jan 2024 00:58:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IHRVYpIZfrG7XmkjOVmlieT+Oyj88gunL2AE3ehlBFrVNBtgTZw2PaFyd5KRT+MjU0aGOF9 X-Received: by 2002:a05:6808:189b:b0:3be:30e0:5e1e with SMTP id bi27-20020a056808189b00b003be30e05e1emr7078741oib.55.1706605134199; Tue, 30 Jan 2024 00:58:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706605134; cv=pass; d=google.com; s=arc-20160816; b=EMJoKDf6Rzo3jD/X0NUcVv19RDmzr65Un6fpVLPls/KJHNcecYcmUodV6Fl3UGTZer nmnfVX8Gn+FuwtANouE8pz5O3MUliFx+7KtFaYb0F0tkzXbTEL/GZkys72+Xp6eC0PU8 Sd3CMbC1udSnRUTw0GlPz1m0PlNKj15l8Z3hNWDN3Je+uB07CDgyMcBof/WE8+sdgkyv ryNlgMYlxz7uwlxHFkG4Wot2JWot4arqCFpP1njQKq2a4zrZPhAd7wUqoYaPzhJ8pYHY 2pVqM+t/6gqFkImiwrEDROH1PIWoYcB+uom38iBHEkcmBnCD0GPa9XeCoUxFfpDvXSFl AG3Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=1Ef/D0lEas0yp4KPjSxjRO+7105j66U6WTJQm7R4Kn8=; fh=NxsD1VXGtxX7D22HWBE72S/UAWD4f4gSJFrLKKCXY/E=; b=FhFenOLxPisA6H06BC2U/MAcSNpXBOpglY8If4FeMBTunZrqmzboRM532JkILuyajb MlrGmJc0yssT+RUZim0WAofe8q6xUSpsyyhRImuCopDCOMzaFaRHx7P4BzddYoz4gV8n MrO2Z97l0C9qR3U1MvVQoxDrnIVbL/GTOrxWFzz+62+PX/13BrFyMFCI2aRkDKSlgCTG 8fj0nhPhq1OinwKych+tiezWXF273Wx8mwwhWl/8jMUDDZZzhfS6q933ZhaQAdtvYLX4 yt79kix7NJulCFeP+qmVzMG2vzM5P7Y3MItSGR2m8/D6RWi6S1I4mtnGVwj6STjFESFR UMFw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=lvX7yeCB; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-ext4+bounces-1018-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1018-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id e11-20020aa7980b000000b006dbd5165fadsi7170026pfl.100.2024.01.30.00.58.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 00:58:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-1018-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=lvX7yeCB; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-ext4+bounces-1018-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1018-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 6D99B28A40D for ; Tue, 30 Jan 2024 05:54:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 63988381B6; Tue, 30 Jan 2024 05:54:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="lvX7yeCB" X-Original-To: linux-ext4@vger.kernel.org Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D27C381B9; Tue, 30 Jan 2024 05:54:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706594065; cv=none; b=IKqwN7FwNfPIjQWCVkMQzW2EBm07vXv5zapeSZT4D0o3TK5giW8enS5NjWK2ftT+yyzX8RuqSfYv2gj09pwecTQ48bzJERt/wBwTBzSU8XUBrrxyUx0mW/MbWN4ih5gWab8KlPJQLSnvIs+Ah6zojF+wasaolofuVJZtR9cMv7k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706594065; c=relaxed/simple; bh=JMGNgA5p77L4yCmgHLC5rGqvzm4lD2Au+5vm0jaJPkg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KjPqbnrvNbBGiiuTjlYfpnsvt1smYSlHlnRRCjlJh8baAhfO7f4PO3cfXIkr4+m6boRw+2rTf3ZClgwMZ6nObOL0KraA1hAd/3Ox3TWWXK9iimv+QWVVtv1j4woj0e7Hi8WO9pUFB4DLwgdfX1m5zfYzA7TpD4UcOJe6D1LPQO8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=lvX7yeCB; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org 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=1Ef/D0lEas0yp4KPjSxjRO+7105j66U6WTJQm7R4Kn8=; b=lvX7yeCBJlayQsdK8PUlA0HuhG G5nIQwPrqg5Nr5CgLaofgotf/cYjScz6efp7vuNSpVwXzJ4/3hXRiAslNsbl6O663ILOPkgQyD3cK kDxlr4g2EJlVKFMxf18altMxeF9hMpWcHRfQsG604zLXLaEPcaivh9oyUGZ0rus5JLybfhkfpPFLN Se0FsSeLZE5LcUqhaIKBeIFXdpgew7sUGNLd2DLykvyhzSAdigLBFqQUqNLSvzRpiTpFnFzZSXvg8 ipXacqLFu6Wxjo5LdlHkgqvAC5oqMjRxfeiY3/CiZwn49t0rYk1l5r9uDWrAPKH6o9STDPoDfCNKv ASYOi/nQ==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rUh4a-00000008zkj-0zzP; Tue, 30 Jan 2024 05:54:16 +0000 From: "Matthew Wilcox (Oracle)" To: Christoph Hellwig Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org Subject: [PATCH 2/3] fs: Supply optional buffered_write_operations in buffer.c Date: Tue, 30 Jan 2024 05:54:12 +0000 Message-ID: <20240130055414.2143959-3-willy@infradead.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240130055414.2143959-1-willy@infradead.org> References: <20240130055414.2143959-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit generic_cont_expand_simple() and cont_expand_zero() currently call ->write_begin and ->write_end, so will also need to be converted to use buffered_write_operations. Use macro magic again to pass in optional buffered_write_operations. Signed-off-by: Matthew Wilcox (Oracle) --- fs/buffer.c | 62 +++++++++++++++++++++++++++---------- include/linux/buffer_head.h | 22 ++++++++++--- 2 files changed, 64 insertions(+), 20 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index d3bcf601d3e5..8ed76fc6cff0 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -2441,11 +2441,13 @@ EXPORT_SYMBOL(block_read_full_folio); * truncates. Uses filesystem pagecache writes to allow the filesystem to * deal with the hole. */ -int generic_cont_expand_simple(struct inode *inode, loff_t size) +int generic_cont_expand_simple(struct inode *inode, loff_t size, + const struct buffered_write_operations *ops) { struct address_space *mapping = inode->i_mapping; const struct address_space_operations *aops = mapping->a_ops; struct page *page; + struct folio *folio; void *fsdata = NULL; int err; @@ -2453,11 +2455,17 @@ int generic_cont_expand_simple(struct inode *inode, loff_t size) if (err) goto out; - err = aops->write_begin(NULL, mapping, size, 0, &page, &fsdata); + if (ops) + err = ops->write_begin(NULL, mapping, size, 0, &folio, &fsdata); + else + err = aops->write_begin(NULL, mapping, size, 0, &page, &fsdata); if (err) goto out; - err = aops->write_end(NULL, mapping, size, 0, 0, page, fsdata); + if (ops) + err = ops->write_end(NULL, mapping, size, 0, 0, folio, &fsdata); + else + err = aops->write_end(NULL, mapping, size, 0, 0, page, fsdata); BUG_ON(err > 0); out: @@ -2466,12 +2474,14 @@ int generic_cont_expand_simple(struct inode *inode, loff_t size) EXPORT_SYMBOL(generic_cont_expand_simple); static int cont_expand_zero(struct file *file, struct address_space *mapping, - loff_t pos, loff_t *bytes) + loff_t pos, loff_t *bytes, + const struct buffered_write_operations *ops) { struct inode *inode = mapping->host; const struct address_space_operations *aops = mapping->a_ops; unsigned int blocksize = i_blocksize(inode); struct page *page; + struct folio *folio; void *fsdata = NULL; pgoff_t index, curidx; loff_t curpos; @@ -2489,13 +2499,23 @@ static int cont_expand_zero(struct file *file, struct address_space *mapping, } len = PAGE_SIZE - zerofrom; - err = aops->write_begin(file, mapping, curpos, len, - &page, &fsdata); + if (ops) { + err = ops->write_begin(file, mapping, curpos, len, + &folio, &fsdata); + page = &folio->page; + } else { + err = aops->write_begin(file, mapping, curpos, len, + &page, &fsdata); + } if (err) goto out; zero_user(page, zerofrom, len); - err = aops->write_end(file, mapping, curpos, len, len, - page, fsdata); + if (ops) + err = ops->write_end(file, mapping, curpos, len, len, + folio, &fsdata); + else + err = aops->write_end(file, mapping, curpos, len, len, + page, fsdata); if (err < 0) goto out; BUG_ON(err != len); @@ -2522,13 +2542,23 @@ static int cont_expand_zero(struct file *file, struct address_space *mapping, } len = offset - zerofrom; - err = aops->write_begin(file, mapping, curpos, len, - &page, &fsdata); + if (ops) { + err = ops->write_begin(file, mapping, curpos, len, + &folio, &fsdata); + page = &folio->page; + } else { + err = aops->write_begin(file, mapping, curpos, len, + &page, &fsdata); + } if (err) goto out; zero_user(page, zerofrom, len); - err = aops->write_end(file, mapping, curpos, len, len, - page, fsdata); + if (ops) + err = ops->write_end(file, mapping, curpos, len, len, + folio, &fsdata); + else + err = aops->write_end(file, mapping, curpos, len, len, + page, fsdata); if (err < 0) goto out; BUG_ON(err != len); @@ -2543,16 +2573,16 @@ static int cont_expand_zero(struct file *file, struct address_space *mapping, * We may have to extend the file. */ int cont_write_begin(struct file *file, struct address_space *mapping, - loff_t pos, unsigned len, - struct page **pagep, void **fsdata, - get_block_t *get_block, loff_t *bytes) + loff_t pos, unsigned len, struct page **pagep, void **fsdata, + get_block_t *get_block, loff_t *bytes, + const struct buffered_write_operations *ops) { struct inode *inode = mapping->host; unsigned int blocksize = i_blocksize(inode); unsigned int zerofrom; int err; - err = cont_expand_zero(file, mapping, pos, bytes); + err = cont_expand_zero(file, mapping, pos, bytes, ops); if (err) return err; diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h index d78454a4dd1f..80de88c12d23 100644 --- a/include/linux/buffer_head.h +++ b/include/linux/buffer_head.h @@ -268,16 +268,30 @@ int generic_write_end(struct file *, struct address_space *, loff_t, unsigned, unsigned, struct page *, void *); void folio_zero_new_buffers(struct folio *folio, size_t from, size_t to); -int cont_write_begin(struct file *, struct address_space *, loff_t, - unsigned, struct page **, void **, - get_block_t *, loff_t *); -int generic_cont_expand_simple(struct inode *inode, loff_t size); +int cont_write_begin(struct file *, struct address_space *, loff_t pos, + unsigned len, struct page **, void **fsdata, get_block_t *, + loff_t *bytes, const struct buffered_write_operations *); +int generic_cont_expand_simple(struct inode *inode, loff_t size, + const struct buffered_write_operations *ops); void block_commit_write(struct page *page, unsigned int from, unsigned int to); int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf, get_block_t get_block); sector_t generic_block_bmap(struct address_space *, sector_t, get_block_t *); int block_truncate_page(struct address_space *, loff_t, get_block_t *); +#define _cont_write_begin(file, mapping, pos, len, pagep, fsdata, \ + getblk, bytes, ops, extra...) \ + cont_write_begin(file, mapping, pos, len, pagep, fsdata, \ + getblk,bytes, ops) +#define cont_write_begin(file, mapping, pos, len, pagep, fsdata, \ + getblk, bytes, ops...) \ + _cont_write_begin(file, mapping, pos, len, pagep, fsdata, \ + getblk, bytes, ## ops, NULL) +#define _generic_cont_expand_simple(inode, size, ops, extra...) \ + generic_cont_expand_simple(inode, size, ops) +#define generic_cont_expand_simple(inode, size, ops...) \ + _generic_cont_expand_simple(inode, size, ## ops, NULL) + #ifdef CONFIG_MIGRATION extern int buffer_migrate_folio(struct address_space *, struct folio *dst, struct folio *src, enum migrate_mode); -- 2.43.0