Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp2044918lqa; Tue, 30 Apr 2024 07:01:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWRVtBSVUr/t0bwSB2ZMAvkZ1QH6fi/ZPVyRMKHxcPWm6S877bZgNdGLqH1F79Qjj+PRhP77MOqD0OXpFGset6iESelxaCIPE3/nCTsFg== X-Google-Smtp-Source: AGHT+IHARjuidBZSAhuG3fEPiyJESqUXugtEjUnBxgc0jIGTKzWKv2QJACHNJ2nus2UAnLHobjDn X-Received: by 2002:a05:6512:3109:b0:518:a66e:aad2 with SMTP id n9-20020a056512310900b00518a66eaad2mr2215846lfb.63.1714485715853; Tue, 30 Apr 2024 07:01:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714485715; cv=pass; d=google.com; s=arc-20160816; b=ESSaYsADYEAXilyu0/cjYzWKL06fHczbsJKgh2UEHcGCeqxLioj6vRlncBq9t0wwyL f9+R+mfhGmrbqnLHFOtMVG1ea9FrTUAkkc5+L3CGTQ70bCCGsMlu7QF5DG+3qmUoD3zw pwlwvH2hjidfT4IulFoAqqNcDiRhBoQiZ6Hi2tsARU3hyJI7kMftHhQxONGKvxcTZUs/ uwYG/uEhy7XInWB7cCGnhG5G5wq8KW/u9fa8ArkWyTB5OeDQY9zHIuNihE3AdF1YtSty Kq1MGgzMoWaSN2hM8yD8le0LEOvug9DHL6TxfdzZxrH+Vd4fEcESjA/Qr1dEx6mnBYbN kQmA== 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=TVvsQkYCcJVRpP2m+QZDwQmmWSsKMODgUlfWruXZbkI=; fh=D72SRyTeGTT5e8cHVnWso1+T4PfZOoBdL/zxY6by6YI=; b=xlTAZFHpx+R8qPyr13+fjsDoLceQFyf8xfFDTcoYKoZDaWvaTP7ETCmmW/BfqxmcGP IuqO9d3NbHXlX6JmlV3aV1yAKlJ1lwsNyXUbJQNngUV7C446OuFkOXWer0sXXixBfgFc qTnGbb2uInGEQ21eiM4L+HAIqzpESzdG5Rp2tWdHb2Mm0X1t5WIfQ7I6Itr+IozBi8bg iN8WRIYcJ2E8atd8wxf2g3UzG+yD3VFXm6lq0LLo2Akq5pxtwpnVHKWlPVdiqxpBhrRo c/ieC4E2/1+bHDNtE7Qd1iXPbZgW3nC7NvBgwUmv+njZWrMM4XUY7CPnpqPU3eTS9hVW 5qFg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="I/RB5qh5"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-nfs+bounces-3077-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-nfs+bounces-3077-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id e8-20020a50a688000000b005723aba91fesi7107420edc.321.2024.04.30.07.01.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 07:01:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs+bounces-3077-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="I/RB5qh5"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-nfs+bounces-3077-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-nfs+bounces-3077-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 7856B1F22791 for ; Tue, 30 Apr 2024 14:01:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A0F38174ED3; Tue, 30 Apr 2024 14:01:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="I/RB5qh5" X-Original-To: linux-nfs@vger.kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 162D1173341 for ; Tue, 30 Apr 2024 14:01:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714485675; cv=none; b=DJADpzQYvLW7ZTpwruoH2S2GZCccwAlOY0fxI81IOGKKyMC6uubMiKA5RdPx/DQppQgSPTbZZ4K2yQ0rtb9KK7vgQq+eQBJ+hiRhjZahV4iFLHD+LG+X5fgOq94riE7WZ11rG4/4E1hJpM8p1ywhqW1PAPrHhaRJ04Qla4rEvYw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714485675; c=relaxed/simple; bh=ARhpxIXoeLR1ngpuAVV3Ez9EqVtZ9SlP4nibSX43Umk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Akb0WObXErPSBYP4tuB4uaMFUvAjX/ct9ZgCL05iJE/gh7UDnxg0mhKAkcPyCQsjJZUTayiAyYfQF5D4WjBbI+5Sy+u15Q5u7zbZFjryxEVMu4bbs3+F8/Jygm3hECHRH5lRGRM2XfupxHTo+JQQ+FDtsOKQJmewrprRdZyWzAs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=I/RB5qh5; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714485673; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TVvsQkYCcJVRpP2m+QZDwQmmWSsKMODgUlfWruXZbkI=; b=I/RB5qh5+uVIQ+EFfmvDM/IVtqJXNo639Sp+TANRZfRmZ+Kp0wZhGQWLMcNGkB4vTpyxwD yxMTLTlfRReRIOFSxjShVkppBUeP19a9EIeSI44lhCia940+DZPrKO0JWhL4Hm7vw7Ej21 F3HHWzgqDsrizaG2euScK5Ho2g6xpy4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-277-zRMsxZfENTaJb65jT9Kr8g-1; Tue, 30 Apr 2024 10:01:09 -0400 X-MC-Unique: zRMsxZfENTaJb65jT9Kr8g-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E9CEC830D37; Tue, 30 Apr 2024 14:01:06 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71CEA1121313; Tue, 30 Apr 2024 14:01:03 +0000 (UTC) From: David Howells To: Christian Brauner , Jeff Layton , Gao Xiang , Dominique Martinet Cc: David Howells , Matthew Wilcox , Steve French , Marc Dionne , Paulo Alcantara , Shyam Prasad N , Tom Talpey , Eric Van Hensbergen , Ilya Dryomov , netfs@lists.linux.dev, linux-cachefs@redhat.com, linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs@lists.linux.dev, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Steve French , Shyam Prasad N , Rohith Surabattula Subject: [PATCH v2 01/22] netfs: Update i_blocks when write committed to pagecache Date: Tue, 30 Apr 2024 15:00:32 +0100 Message-ID: <20240430140056.261997-2-dhowells@redhat.com> In-Reply-To: <20240430140056.261997-1-dhowells@redhat.com> References: <20240430140056.261997-1-dhowells@redhat.com> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 Update i_blocks when i_size is updated when we finish making a write to the pagecache to reflect the amount of space we think will be consumed. This maintains cifs commit dbfdff402d89854126658376cbcb08363194d3cd ("smb3: update allocation size more accurately on write completion") which would otherwise be removed by the cifs part of the netfs writeback rewrite. Signed-off-by: David Howells Reviewed-by: Jeff Layton cc: Steve French cc: Shyam Prasad N cc: Rohith Surabattula cc: linux-cifs@vger.kernel.org cc: netfs@lists.linux.dev cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- fs/netfs/buffered_write.c | 45 +++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/fs/netfs/buffered_write.c b/fs/netfs/buffered_write.c index 267b622d923b..f7455a579f21 100644 --- a/fs/netfs/buffered_write.c +++ b/fs/netfs/buffered_write.c @@ -130,6 +130,37 @@ static struct folio *netfs_grab_folio_for_write(struct address_space *mapping, mapping_gfp_mask(mapping)); } +/* + * Update i_size and estimate the update to i_blocks to reflect the additional + * data written into the pagecache until we can find out from the server what + * the values actually are. + */ +static void netfs_update_i_size(struct netfs_inode *ctx, struct inode *inode, + loff_t i_size, loff_t pos, size_t copied) +{ + blkcnt_t add; + size_t gap; + + if (ctx->ops->update_i_size) { + ctx->ops->update_i_size(inode, pos); + return; + } + + i_size_write(inode, pos); +#if IS_ENABLED(CONFIG_FSCACHE) + fscache_update_cookie(ctx->cache, NULL, &pos); +#endif + + gap = SECTOR_SIZE - (i_size & (SECTOR_SIZE - 1)); + if (copied > gap) { + add = DIV_ROUND_UP(copied - gap, SECTOR_SIZE); + + inode->i_blocks = min_t(blkcnt_t, + DIV_ROUND_UP(pos, SECTOR_SIZE), + inode->i_blocks + add); + } +} + /** * netfs_perform_write - Copy data into the pagecache. * @iocb: The operation parameters @@ -351,18 +382,10 @@ ssize_t netfs_perform_write(struct kiocb *iocb, struct iov_iter *iter, trace_netfs_folio(folio, trace); /* Update the inode size if we moved the EOF marker */ - i_size = i_size_read(inode); pos += copied; - if (pos > i_size) { - if (ctx->ops->update_i_size) { - ctx->ops->update_i_size(inode, pos); - } else { - i_size_write(inode, pos); -#if IS_ENABLED(CONFIG_FSCACHE) - fscache_update_cookie(ctx->cache, NULL, &pos); -#endif - } - } + i_size = i_size_read(inode); + if (pos > i_size) + netfs_update_i_size(ctx, inode, i_size, pos, copied); written += copied; if (likely(!wreq)) {