Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2751633pxj; Mon, 14 Jun 2021 06:26:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy63EcqrNmPQWtL4ClNnJyD1jC1lfVrAtGwJjrsYbZmcK77pGP1fieXGnJPFBPV+fNKgMjh X-Received: by 2002:a17:906:35db:: with SMTP id p27mr15226294ejb.391.1623677167701; Mon, 14 Jun 2021 06:26:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623677167; cv=none; d=google.com; s=arc-20160816; b=Iv9FEGhvd3j7EOj/yh5XxBb8DDFsuNU+suHq2Ob0RsVrD8UxKtaOgerLs5/HvW+Q3p TynSyehtslDseBjuBH+PrhdpDR1KNszOHBIpQFG1HoRIgGE4X38LPueaFf5APqqAs7os s+OOXXAQqYqfvGbof92yjNCgpgX7AzLU8Fqt7IcpvD3zX9KT5uIm55Sm5VhFLIUZAvEk JC/fxomftiEIznMy6th+0VstqLMUsbI/4dUTTDpN56O2cX76rMh/lp3Q2y0suRIMmiQK GlAr2K/O52UEoD28cNXFLanjIbNJXFiGb3yqI4rMLUxdVptp1pXPi6qNmywGQUHlBFBT 9c1w== 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 :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization:dkim-signature; bh=hHKlTZYrE3qayq9WgDP8elW69NUaJIZRckah9/2ZzdE=; b=zFzDSa2IqcT72SnQonqc7BDl9VyVDGiFZdfklRygbeb/UYSHzG2DghYI4mtAdI9UYd 3dP3udbQpUfhx3Ll5qeJPPmDbtaJ+RkJ2AIZT3J0gCGEvhFX2VrWI1j0IT3bry7dsq6O tEtr/CG3Yu+jK+9jBRXNIdubdQ0lyMTxOExvU//i0BgJbSHGSe8KXJo14+1t86cPdjhI wZcAo5tC5KmrbRFMO4xQWQvVDL7v8SXQrrZ1YRAzUrjHboo2UBRYHAXpsxAkKNShzJd1 QWUutY88uocUXMxi0FlchPmLgN9eg0uc5VIDu7RD4OXYextON/qHJbybq5rFuzTiMpxm 8TzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UEl99jSY; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 16si10694197ejd.349.2021.06.14.06.25.44; Mon, 14 Jun 2021 06:26:07 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b=UEl99jSY; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233879AbhFNNXB (ORCPT + 99 others); Mon, 14 Jun 2021 09:23:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:47832 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233912AbhFNNWr (ORCPT ); Mon, 14 Jun 2021 09:22:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623676844; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hHKlTZYrE3qayq9WgDP8elW69NUaJIZRckah9/2ZzdE=; b=UEl99jSYMC9OxsCfpUblZmeV14UqkJrALTq5TScUXfjlpwnotUZAi7AuvIrbhEGMElMkbS DozTV6J6BB/kaJmYielIR4YW+pm+Qe2b2qv5E/TNTMH+6ftdzs5fYQ1rickbjXOy+7LJIb tGFnfiIK6MDPsU5C+ktWRHNcJGGzc98= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-540-5ZrqStiTM_WeGQlQadA7jQ-1; Mon, 14 Jun 2021 09:20:35 -0400 X-MC-Unique: 5ZrqStiTM_WeGQlQadA7jQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 690AD100CFC6; Mon, 14 Jun 2021 13:20:28 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-118-65.rdu2.redhat.com [10.10.118.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 05DEA5C238; Mon, 14 Jun 2021 13:20:25 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 2/3] afs: Fix afs_write_end() to handle short writes From: David Howells To: jlayton@kernel.org, willy@infradead.org Cc: linux-afs@lists.infradead.org, dhowells@redhat.com, linux-afs@lists.infradead.org, ceph-devel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Mon, 14 Jun 2021 14:20:25 +0100 Message-ID: <162367682522.460125.5652091227576721609.stgit@warthog.procyon.org.uk> In-Reply-To: <162367681795.460125.11729955608839747375.stgit@warthog.procyon.org.uk> References: <162367681795.460125.11729955608839747375.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.23 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Fix afs_write_end() to correctly handle a short copy into the intended write region of the page. Two things are necessary: (1) If the page is not up to date, then we should just return 0 (ie. indicating a zero-length copy). The loop in generic_perform_write() will go around again, possibly breaking up the iterator into discrete chunks. This is analogous to commit b9de313cf05fe08fa59efaf19756ec5283af672a for ceph. (2) The page should not have been set uptodate if it wasn't completely set up by netfs_write_begin() (this will be fixed in the next page), so we need to set PG_uptodate here in such a case. Fixes: 3003bbd0697b ("afs: Use the netfs_write_begin() helper") Reported-by: Jeff Layton Signed-off-by: David Howells cc: linux-afs@lists.infradead.org --- fs/afs/write.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/afs/write.c b/fs/afs/write.c index f68274c39f47..4b3f16ca2810 100644 --- a/fs/afs/write.c +++ b/fs/afs/write.c @@ -121,6 +121,16 @@ int afs_write_end(struct file *file, struct address_space *mapping, _enter("{%llx:%llu},{%lx}", vnode->fid.vid, vnode->fid.vnode, page->index); + len = min_t(size_t, len, thp_size(page) - from); + if (!PageUptodate(page)) { + if (copied < len) { + copied = 0; + goto out; + } + + SetPageUptodate(page); + } + if (copied == 0) goto out; @@ -135,8 +145,6 @@ int afs_write_end(struct file *file, struct address_space *mapping, write_sequnlock(&vnode->cb_lock); } - ASSERT(PageUptodate(page)); - if (PagePrivate(page)) { priv = page_private(page); f = afs_page_dirty_from(page, priv);