From patchwork Wed Nov 29 16:56:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13473217 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A26B6C4167B for ; Wed, 29 Nov 2023 16:56:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 66D406B03C6; Wed, 29 Nov 2023 11:56:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4EF576B03CC; Wed, 29 Nov 2023 11:56:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 390856B03CD; Wed, 29 Nov 2023 11:56:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 2A2586B03C6 for ; Wed, 29 Nov 2023 11:56:36 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 05BE6120544 for ; Wed, 29 Nov 2023 16:56:35 +0000 (UTC) X-FDA: 81511595592.22.C55696D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 49BE140010 for ; Wed, 29 Nov 2023 16:56:33 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fvJsW8tH; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701276993; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ElC8RAQdfN2Ln/hT1ay+FjIT1Y57onjWn6huuiDhwuM=; b=suOTmghStU5mC8lP0YZgvYEHLNh3ADFLjvOrgO65Pu9//A3iagPJVAPQRkpzOxPxXPoEJN ELKRB7Pwem4YzBeT1WjjyeM3CFrn3gKIIXRIIG4UAZk2ss5ajGO7C5rp5vMrboGn70Y0b/ k5Mq7WwLT3TAthUKyZtwh7Cbt770uO4= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=fvJsW8tH; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701276993; a=rsa-sha256; cv=none; b=p2tVUrInMuF9YABiyErSq3dYI4RmhNwPE8oogqJntMIM97oZXAQiNatlQI4ApGWYWcQTQW LBEHq+3Iguv/Bp8RZ/7QoY6tRFUjL6sD/EBgWNF8IYQj66R0mkTAPASOrqtRRWJFLcZKdx ZfAerjOrLXVXeKER98VtBv2zuGvo5dw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701276992; 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=ElC8RAQdfN2Ln/hT1ay+FjIT1Y57onjWn6huuiDhwuM=; b=fvJsW8tHpliIE/T2tHtD2Co2yzRsKIBn4J4KgoL44WriaY6hP3ukrlrggPiCPY3hHgcWV7 G0rMBXumgCXMafU3DVoxR0ryfkl17R/jUAJip/uriX3ByANHbBVFJMJJluLMLjvJmhlDZV cyktq6rlnBmxTyUakeKsiNN44tYIOyw= 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-331-HkqjQLWeM0mvcv48uRBM8w-1; Wed, 29 Nov 2023 11:56:26 -0500 X-MC-Unique: HkqjQLWeM0mvcv48uRBM8w-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 30CB7185A7A9; Wed, 29 Nov 2023 16:56:26 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.161]) by smtp.corp.redhat.com (Postfix) with ESMTP id B90BD112130A; Wed, 29 Nov 2023 16:56:24 +0000 (UTC) From: David Howells To: Steve French Cc: David Howells , Paulo Alcantara , Shyam Prasad N , Rohith Surabattula , Matthew Wilcox , Jeff Layton , linux-cifs@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 1/3] cifs: Fix FALLOC_FL_ZERO_RANGE by setting i_size if EOF moved Date: Wed, 29 Nov 2023 16:56:17 +0000 Message-ID: <20231129165619.2339490-2-dhowells@redhat.com> In-Reply-To: <20231129165619.2339490-1-dhowells@redhat.com> References: <20231129165619.2339490-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Rspamd-Queue-Id: 49BE140010 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: pn9mqpfh77369cc8fuif8fb3ibu764ax X-HE-Tag: 1701276993-157312 X-HE-Meta: U2FsdGVkX1/QVWlbDV5s5jKkA4Hz/XKWO1FcaAmMdxTLFq25ckjNqqcllATEhFRkCSjnPD8n5DU6EEarRu8s11sPRSRGfsyzv4nQDtZv6FfDNJ8nkCMvoRuKH0s8U2ms5jy34s0hGbnA/waHb7AUCvw90KKJv74gG/T5bqBxRHWJCzhZEa+RhJmn5irAvzhv0dMCCeEQtukUEq3qVgb9AFAXAiJYGpC9hCeiJ8upTOnuF3cCNvePchk4SGpMaydGrFx23kUxeXM4WV1guSSfc0GIjnWG82iWbxWaJftECeEdJOQYQ5XFp3qQ4HA8WHB4cRfD1xkbGKjhv8EHrwKzTFyQ1gjj1OtI6oVf5WRRUk2odnDHk0ryedfAGgL8eIAmuHF7L5X+SOgNlbdQZI+joPXu8pQV6dsjw3lJZUqlqw1gBr1QyS02r8frYcgbgkGKV4QdSICMWhmD63ux64xhx9SdX0BWT2Vi3rcURhBbchfHa0tT+A+062RMOHMK6pIEbGWVSq68GyY4bJVxkPZKDMQytVGJFjObJQxKQ40mkTXi5Mby6Oz5Zqng4dBkKbmjhwYAr2Qc0l9DFAvuCKBP+f0Gp/dq6mbEsOwAqeGNRlf9T+YDvXfapEA0PVtrlEsvZqj8yqoDk0D4fHEjW5EOlSwwEnL7M55cGJX1+IxhGEDv/0wNeEY6bDBxmCDuVaYpYAkdNj5YOy46Og87t3EvJ6GAe/GSCSnqHBD7BZVYOBsuGqxin3cXtY6hFbw6CsNzjRMsRqH9KAagFOlc17ha2VoAM3wD25pWQC2uAXi3puJPcT9PRaBi1XBPrFrj7sUhOm0ozQUXWUqRw7Xkw4NGXIZKn04EKMsS2P35OQqY5dfjQoGX48NxyrMWi8X4ZAkf4fXmvaZK5Dfq2AYdtO+1imQYpGsNSsELIfxK99lEHDnu5p4I/ymegwS+xHrbzr6KJtWKarM05lIxkCEG/Wb BA+exeRc veJ10s9ApTCwAVoVoaIvvJt2LkNw2fSl6hl9RO6cGHCkMceN5pg2RO6A8gzegBxVBDLmTRWBUcU8MkdH44E7pE5Qo66ygWyJB/92roKSurRoSGro1W0SrguMgDoSRpkj7DqH1wILulspstT6ReqEzvPgLwA8xfJSFDdzzv77FN8zIFxOFVY/mrFOr9Y+igvLZmZsQ/aK1dCCd6ZhAQ9UBfCmnTCqorh6Llt69ZjobTZNLzRIX+oz2PFRTwUbBmzJ0c67R1BTb5tAUo/ob7KrhWaUsIG54v0zLFL8XZwnp3rZlNof72L8m5qGKHb3HBnFt3HDaR+An86khWwUNC9fc+7RpvyRd1ptTFkmPcWFT87gP8hXGAPRIYORlC7EnMsidWZOoEYVStWEi8yROT4RxeqDfY4LgqABbw50CBcIgdl5ozPL+puO621qih+3ZiqICEo7nxbHgMgRteUit9y2WW0Yut7grZmlGbqW4ZT6G+h/EqG1h99mz0YWUEa96GBgLHHhngKDvIj61HPavModxdnsJaQpMMuwkyrfRY3G8uX7EjII= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Fix the cifs filesystem implementations of FALLOC_FL_ZERO_RANGE, in smb3_zero_range(), to set i_size after extending the file on the server. Fixes: 72c419d9b073 ("cifs: fix smb3_zero_range so it can expand the file-size when required") Signed-off-by: David Howells cc: Steve French cc: Paulo Alcantara cc: Shyam Prasad N cc: Rohith Surabattula cc: Jeff Layton cc: linux-cifs@vger.kernel.org cc: linux-mm@kvack.org Acked-by: Paulo Alcantara (SUSE) --- fs/smb/client/smb2ops.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index a959ed2c9b22..572d2c22a703 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -3307,6 +3307,7 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, struct inode *inode = file_inode(file); struct cifsInodeInfo *cifsi = CIFS_I(inode); struct cifsFileInfo *cfile = file->private_data; + unsigned long long new_size; long rc; unsigned int xid; __le64 eof; @@ -3337,10 +3338,15 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, /* * do we also need to change the size of the file? */ - if (keep_size == false && i_size_read(inode) < offset + len) { - eof = cpu_to_le64(offset + len); + new_size = offset + len; + if (keep_size == false && (unsigned long long)i_size_read(inode) < new_size) { + eof = cpu_to_le64(new_size); rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, cfile->fid.volatile_fid, cfile->pid, &eof); + if (rc >= 0) { + truncate_setsize(inode, new_size); + fscache_resize_cookie(cifs_inode_cookie(inode), new_size); + } } zero_range_exit: From patchwork Wed Nov 29 16:56:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13473216 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B035C10DAA for ; Wed, 29 Nov 2023 16:56:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B592B6B03C2; Wed, 29 Nov 2023 11:56:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B0A306B03C6; Wed, 29 Nov 2023 11:56:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D2DA6B03CC; Wed, 29 Nov 2023 11:56:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 904266B03C2 for ; Wed, 29 Nov 2023 11:56:35 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5598A14059D for ; Wed, 29 Nov 2023 16:56:35 +0000 (UTC) X-FDA: 81511595550.05.B33C36C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf02.hostedemail.com (Postfix) with ESMTP id 739188001C for ; Wed, 29 Nov 2023 16:56:33 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=E1SVpREi; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf02.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701276993; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=dPjSTDvJjKZvQqpuoRax99jzMiuqvHWjt5D7woIueGo=; b=6hEyJjhNSH8udM/ilxVLF3CNE2QfrR78f6e91Uut5trjq2PpeRCI7X45a6Q1OkxBmTd+Ly Ji7GECLYNprP4GffK5iqTdo2wikBznt1hRJAnXWJoLyvBTqrh5SPUYm3HZpa8cd+yGxQwk wJc622uKswYwpIA3r794fwgwgym3j68= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=E1SVpREi; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf02.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701276993; a=rsa-sha256; cv=none; b=Ix25BYBOlG02/MlT504Ed0em4tmX2Jvi+HChDg3asAgf73un/BSTZvhlHeoMR0rfab9qBo XeMGUb99IVWGVITfuCi6lnkLpWabhIZYTAbGahcRLyfrkOIqdnFKSspigXSuGyKytapa4f IjYPg0FqlWL04SNcnleXKam7mbivqXU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701276992; 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=dPjSTDvJjKZvQqpuoRax99jzMiuqvHWjt5D7woIueGo=; b=E1SVpREi48e1BMrMM3+zthfshN/G648ofe9LB9kQ+tOYKyTAe20v69/CAk0i1qw9MWEz+h v9QVxFFzWb5hbm8XwbndUk7ttqzSDiG5l8eMj6+RPqxa1ZekgGSdiqcN+JdjTVLpFn8qzb OIl/4vSINNdZbBn4ul87N+NPU95TUaM= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-508-1kcZMNfDO66ZvxPfVdWQfg-1; Wed, 29 Nov 2023 11:56:29 -0500 X-MC-Unique: 1kcZMNfDO66ZvxPfVdWQfg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 888851C0BB75; Wed, 29 Nov 2023 16:56:28 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.161]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF0D3C15886; Wed, 29 Nov 2023 16:56:26 +0000 (UTC) From: David Howells To: Steve French Cc: David Howells , Paulo Alcantara , Shyam Prasad N , Rohith Surabattula , Matthew Wilcox , Jeff Layton , linux-cifs@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 2/3] cifs: Fix FALLOC_FL_INSERT_RANGE by setting i_size after EOF moved Date: Wed, 29 Nov 2023 16:56:18 +0000 Message-ID: <20231129165619.2339490-3-dhowells@redhat.com> In-Reply-To: <20231129165619.2339490-1-dhowells@redhat.com> References: <20231129165619.2339490-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Rspamd-Queue-Id: 739188001C X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: fm3zw1y1dmumaprje8fog4onsr7i9ifb X-HE-Tag: 1701276993-554364 X-HE-Meta: U2FsdGVkX19STVBW4RNYdvphNkfQUIt9U60U6N6537asn1Z3Zpa7t3owX46Xya4D5hkeE1NgESSuY7+VD7Ze1JfD1iMaYhQKPSarquQonnMrQ6TpOcw1kQkR7NVARTTtzU5eKL1IVaef/SDC2BqZThBC2ghBeVagOJ5AvHW25eG14tHHRNw/QDFm+FsgE/uAGArG51sr3DmMEjaUQv9RqwHXpv6NU+mHz9DwfyTReRMixJQL2IQiWocyXzBak2tevPbmzEX4LJYJqmjOo8r/GJ7zKUq+bf9cPitr63osbbdy4X5fS08Xu946Jklf0HoDSzXLZ1mUVNXaYuU4Q+O1hplgGYxl/M7lK5TILI4BxtyIH44ULHedOEf2Y+SZ9lRhYq1UOtt3YciTtqIJn09tGiGtsARXJP6ylk5rsn8ZbzqnTOyswweFS/1bwMo5ynZ8e5Ef/qm6uqxIJzTKwYaigALLZHLuh99rEC2DXi2lAW5LPOUcNQ7oGOmFccYRpuwoTO4RwSuscxFjcSoJrzJP0BZfXZpssUSn5wxsE7AlOIHTSZFxshZZxiJFQYQw1hBfsVJOo/Crnd0+deV6ryCgH3en+rP2P5N6AMdP3wA2hA+sfKsZ+KyOofr3ELRueFoNW09epnSjn0YSEqPFRSv6VeN03J/Ov6LAM62QQi9Av95ddaWjl2dVTNxiitGDwHeYI1QYLU5oFkTH/MsxSGeKW7HZG39i4lncvF9roUXkdKAdNshCGRbsuYFpOt86KQB3Qhd3jtnK6EJ6rvq26Myu9PygoNIRDRBxH1cLKhzFMFs+/ElEFYif9cioNeNRvD1UVyXdHpD1ONBIqWliU3F1klIB2qERdWw9ndvGpvpHOjXXm/HcUxQdWlq2/yEq8DpB27PY1i68dPrlkOIeMKNneu8giFC4v/vvAl8nG2Jla8UFZ+lwAlkal2O1Owt8YIyW1WFMO+9tUlBr9/Yuzlw m7ec3ho4 4MIYXPxvpA0K/idG/YksA00gnrHSWrlcuAW23IsjDvKYP9WNa1WHFgJhKlv4ZBiWDJ+YzB02Te/aCKvlHS6ksMdTtLkqHfsCfEJ1mhPiy/E64CaWZaFJfjddYHceozdDJgChb8lAmsdhk4qg6P71GmqC6o+PBu0rhLeADNHSBwWVtX5AlcXEKMF7RrgJC6Oir0xMjZhTz6hJTkJo+iyARLN+uV9bhmFYEaKtju5WRUeJCn/SMhMGFOjVIzGO99iJ9cfSWvG463akKmx5bcUsL9oGMBRz9z9hrN3AGliTUNo5vMVsLtoJJUW43NwualgfFilkse2RyOw6KyEfL/F36eqJqx2IGhmWGUFDwA/qOI/A5M98dFlLMYBly6hAjv4/buFYEsTucF/TMP+Xrxk5eAYfFU9dYJlsUQEFvSiuUmur8ojN5jqIFn/+8YyZXXaV8Je9/XQHhdfl58H8vxIqkgeWzgBWPGC4odxe1YfC+MqfWrQ5OLbDwDuAe+bIyXi3miwj+BPheB3kNSJkA9mq5qpcNiwEucO9iWhF8XL3C18h2PZM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Fix the cifs filesystem implementations of FALLOC_FL_INSERT_RANGE, in smb3_insert_range(), to set i_size after extending the file on the server and before we do the copy to open the gap (as we don't clean up the EOF marker if the copy fails). Fixes: 7fe6fe95b936 ("cifs: add FALLOC_FL_INSERT_RANGE support") Signed-off-by: David Howells cc: Steve French cc: Paulo Alcantara cc: Shyam Prasad N cc: Rohith Surabattula cc: Jeff Layton cc: linux-cifs@vger.kernel.org cc: linux-mm@kvack.org Acked-by: Paulo Alcantara (SUSE) --- fs/smb/client/smb2ops.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index 572d2c22a703..65a00c8b8494 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -3741,6 +3741,9 @@ static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon, if (rc < 0) goto out_2; + truncate_setsize(inode, old_eof + len); + fscache_resize_cookie(cifs_inode_cookie(inode), i_size_read(inode)); + rc = smb2_copychunk_range(xid, cfile, cfile, off, count, off + len); if (rc < 0) goto out_2; From patchwork Wed Nov 29 16:56:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13473218 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF716C10DAA for ; Wed, 29 Nov 2023 16:56:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 910DD6B03CC; Wed, 29 Nov 2023 11:56:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C18C6B03CF; Wed, 29 Nov 2023 11:56:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 73C736B03D1; Wed, 29 Nov 2023 11:56:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 4DFA26B03CC for ; Wed, 29 Nov 2023 11:56:38 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 244B9405E5 for ; Wed, 29 Nov 2023 16:56:38 +0000 (UTC) X-FDA: 81511595676.26.E460CD9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf13.hostedemail.com (Postfix) with ESMTP id 652D620018 for ; Wed, 29 Nov 2023 16:56:36 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HU6Ent7t; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701276996; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=COPRnbgqFRrVTqm5I44AgZNsfxPh98/uI2N+0tyCzMg=; b=2GWZrbwLRTvMI5G3oylnvFcjAhSUd3CCwBwf/jgNcbLI3B6eO4c/VzKKlyewzYHB/M8f76 UoChhMUHSOUMOAXnOKPdRyLu051M5Tr1Tw8ILIqlCRoCF2THleYp+EfHb1zxUNr086QdpV 98SttvHKcYAZS/fGzpv4PsEI7W0ZT/w= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HU6Ent7t; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701276996; a=rsa-sha256; cv=none; b=IUEbMurPV/h1wEQcWyOQo77KxlAL5kuE2jn41mG3h41BPgEGYr/WhHdiHovTrvsUY2pmWs qsWBGOTDfyLJl8MNmBHD+ZLMPw/BBjnKus7bBtNO4Yyd4YC5Jj9ODMrtT9vc/v3GoLLAmE WZtMlXQZONguJQTAB4cNMzPboy179dk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701276995; 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=COPRnbgqFRrVTqm5I44AgZNsfxPh98/uI2N+0tyCzMg=; b=HU6Ent7tyOT0HoL6tcmXT/YZyG4F7yhVeIZE/US3Pg84kYlSL51nNCP7nTEWtrRuk/Fjlk BgXym7kmIWiRDFYK2klBlIB6hQJbNfx31PREF7/NfdFCzxkz7Y7Q83Kg0xw8T8jr4B4025 ZNHRXBpVl04YAJ9KCE3unavJEl3AOmI= 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-401-1Jup_HL8MAqAK-WhrLNE6A-1; Wed, 29 Nov 2023 11:56:32 -0500 X-MC-Unique: 1Jup_HL8MAqAK-WhrLNE6A-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 D583784B0C9; Wed, 29 Nov 2023 16:56:30 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.161]) by smtp.corp.redhat.com (Postfix) with ESMTP id 555FA502A; Wed, 29 Nov 2023 16:56:29 +0000 (UTC) From: David Howells To: Steve French Cc: David Howells , Paulo Alcantara , Shyam Prasad N , Rohith Surabattula , Matthew Wilcox , Jeff Layton , linux-cifs@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 3/3] cifs: Fix flushing, invalidation and file size with copy_file_range() Date: Wed, 29 Nov 2023 16:56:19 +0000 Message-ID: <20231129165619.2339490-4-dhowells@redhat.com> In-Reply-To: <20231129165619.2339490-1-dhowells@redhat.com> References: <20231129165619.2339490-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 652D620018 X-Stat-Signature: c1ybh9xqsjt7xejdki3zdnacib4bzxj8 X-Rspam-User: X-HE-Tag: 1701276996-383628 X-HE-Meta: U2FsdGVkX1+wquNKYRzMbxvLytMOHZvyfS9t5ibgSknxXIaIrnLuC07cyoUYep9R7TL7GXQbpegoMNm5OgCZrQVwFokeTy7ogGYyKeJWnanEkfKZ8x8Z9jYlWHH8Sr5e05a7aG+jcrDCCLFtAH2AwRlMMphHn2XR9lvmG+qYT4te0TOUEAPHNjaAYqM/6jBvS5A42A4Hu5P6tqky29izoEWIbtHHH1AYqJx6MD2NXZcPPZ7URuMOim8lPuYaPYZOKU3hhT+yLCdiKvllkiMZQmp5718478saDLBQOHdebygNnbfb1U9ZkByUZ4J9Rn8eDtCqLYr4A1UmB/xMf8nwHlf8Kg9pQOIZUedivY4NjCHWlSwHNtxVY/FxjLdgkyxfhHcOYaMSRRb8FR+vjaArDtppY89XbGyoVz8vy6EOVsCMFybNianfjh4tItESQ2g0GATCPTuD0Z65oebM3+pvqvycm4VearBSQK811Lh8z0WhvVJBlSAA2x0feSBstfDw1e6ha5PJrX2gzrkQ2XUh0ih/S795DTcZKg2ZdRwF+ZKF50Jh7THha2zhWOviPIbNoUdKSXki8i+kMoU655/yfMhtacolhmVAmy9GL/OMwqStGTyS2offybmQa4JbU8E2CzTPIVtpOe7ADVkSIkLQxPtHu4A6TObl1T4q01cU2PmvISetYkv/VGBUeYbIYt/hSs94Uu5PKUzphTRlX4Ua43StZlspE4MGUYIW+fS8YpWJPhnvb8hvv3JHi265ggAHAKM+9VCFU/Pv6hlDp5J379C0HjwKLjXKaU8QH6uLsKRxcVgOOqSxcQDib8YUb5a4GCNmiwx4HRak0QYEQk6dO6UluAIx5YpGsTH5J0E7SVb8eX/rDm9gIDRscANhf8nUN3ZHqXMSpUmLP7yc1aECwyuF6gszX0VCFzIklyKD9cUQvY9Tylg4GDNVKSqcDEaBveUhpRJsPf77mesXF9k Jc0SlRLW Ep6W26usnRa7PTGIhivn0zXA+jrtoLmW/1rvUSmf6NQ2jDc8Nx49kaULDHV1Kd4LSUyLmaSEGKcvJ4ZM1FfifpmXaYlKKJhJzFfhELBo1sSY8jiIDZVodoI5k/caSwnb3VQVk7cTdPoNKDXHbcMFpyZQZnOG7fqsXXNciwapJqCEiAn9S5FvMLZbC3GQ2AI5lM/a27bR/nYVvdexrEhzueVYZBGJNnAXCwMtCy3E4xJRyV1c36+N6YCjEo+nJB3YnuwC7rMZGhGF5FJk8fyO8xjNSwFD3LYYWuqx8OST6p3w18UngJgreYZ78evOChiMVJvc9ZctInIMb/F0SoVJBYmWuRZxtOA8hk9N+YI1IYH5TTg9Or4sGpgQJT06hMr0Hh5cDhsxUooHA65o8DMHYA0sUahzI9FdjXjNolTDa+ir1bp/XlRnPUSo1gYxNzOBk8TmxAtVwqv/dztRcJh4fmzJ1PcwROjT26wcBMM/cHmAde9cp2btdK0xx9tKhYrKyrZPixHqhiWaHGcswDL29cOmTNQHYjZNBaNox9Z58sIEHSRhej0s4FW2ynt1eA/Y56bxvxbIKSPKuudemCxDSK/4iPmJA3XKRjLB0vbFE1AXCy6s= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Fix a number of issues in the cifs filesystem implementation of the copy_file_range() syscall in cifs_file_copychunk_range(). Firstly, the invalidation of the destination range is handled incorrectly: We shouldn't just invalidate the whole file as dirty data in the file may get lost and we can't just call truncate_inode_pages_range() to invalidate the destination range as that will erase parts of a partial folio at each end whilst invalidating and discarding all the folios in the middle. We need to force all the folios covering the range to be reloaded, but we mustn't lose dirty data in them that's not in the destination range. Further, we shouldn't simply round out the range to PAGE_SIZE at each end as cifs should move to support multipage folios. Secondly, there's an issue whereby a write may have extended the file locally, but not have been written back yet. This can leaves the local idea of the EOF at a later point than the server's EOF. If a copy request is issued, this will fail on the server with STATUS_INVALID_VIEW_SIZE (which gets translated to -EIO locally) if the copy source extends past the server's EOF. Fix this by: (0) Flush the source region (already done). The flush does nothing and the EOF isn't moved if the source region has no dirty data. (1) Move the EOF to the end of the source region if it isn't already at least at this point. [!] Rather than moving the EOF, it might be better to split the copy range into a part to be copied and a part to be cleared with FSCTL_SET_ZERO_DATA. (2) Find the folio (if present) at each end of the range, flushing it and increasing the region-to-be-invalidated to cover those in their entirety. (3) Fully discard all the folios covering the range as we want them to be reloaded. (4) Then perform the copy. Thirdly, set i_size after doing the copychunk_range operation as this value may be used by various things internally. stat() hides the issue because setting ->time to 0 causes cifs_getatr() to revalidate the attributes. These were causing the generic/075 xfstest to fail. Fixes: 620d8745b35d ("Introduce cifs_copy_file_range()") Signed-off-by: David Howells cc: Steve French cc: Paulo Alcantara cc: Shyam Prasad N cc: Rohith Surabattula cc: Matthew Wilcox cc: Jeff Layton cc: linux-cifs@vger.kernel.org cc: linux-mm@kvack.org Acked-by: Paulo Alcantara (SUSE) --- fs/smb/client/cifsfs.c | 80 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 3 deletions(-) diff --git a/fs/smb/client/cifsfs.c b/fs/smb/client/cifsfs.c index ea3a7a668b45..6db88422f314 100644 --- a/fs/smb/client/cifsfs.c +++ b/fs/smb/client/cifsfs.c @@ -1256,6 +1256,45 @@ static loff_t cifs_remap_file_range(struct file *src_file, loff_t off, return rc < 0 ? rc : len; } +/* + * Flush out either the folio that overlaps the beginning of a range in which + * pos resides (if _fstart is given) or the folio that overlaps the end of a + * range (if _fstart is NULL) unless that folio is entirely within the range + * we're going to invalidate. + */ +static int cifs_flush_folio(struct inode *inode, loff_t pos, loff_t *_fstart, loff_t *_fend) +{ + struct folio *folio; + unsigned long long fpos, fend; + pgoff_t index = pos / PAGE_SIZE; + size_t size; + int rc = 0; + + folio = filemap_get_folio(inode->i_mapping, index); + if (IS_ERR(folio)) { + if (_fstart) + *_fstart = pos; + *_fend = pos; + return 0; + } + + size = folio_size(folio); + fpos = folio_pos(folio); + fend = fpos + size - 1; + if (_fstart) + *_fstart = fpos; + *_fend = fend; + if (_fstart && pos == fpos) + goto out; + if (!_fstart && pos == fend) + goto out; + + rc = filemap_write_and_wait_range(inode->i_mapping, fpos, fend); +out: + folio_put(folio); + return rc; +} + ssize_t cifs_file_copychunk_range(unsigned int xid, struct file *src_file, loff_t off, struct file *dst_file, loff_t destoff, @@ -1263,10 +1302,12 @@ ssize_t cifs_file_copychunk_range(unsigned int xid, { struct inode *src_inode = file_inode(src_file); struct inode *target_inode = file_inode(dst_file); + struct cifsInodeInfo *src_cifsi = CIFS_I(src_inode); struct cifsFileInfo *smb_file_src; struct cifsFileInfo *smb_file_target; struct cifs_tcon *src_tcon; struct cifs_tcon *target_tcon; + unsigned long long destend, fstart, fend; ssize_t rc; cifs_dbg(FYI, "copychunk range\n"); @@ -1306,13 +1347,46 @@ ssize_t cifs_file_copychunk_range(unsigned int xid, if (rc) goto unlock; - /* should we flush first and last page first */ - truncate_inode_pages(&target_inode->i_data, 0); + /* The server-side copy will fail if the source crosses the EOF marker. + * Advance the EOF marker after the flush above to the end of the range + * if it's short of that. + */ + if (src_cifsi->server_eof < off + len) { + rc = src_tcon->ses->server->ops->set_file_size( + xid, src_tcon, smb_file_src, off + len, false); + if (rc < 0) + goto unlock; + + fscache_resize_cookie(cifs_inode_cookie(src_inode), + i_size_read(src_inode)); + } + + destend = destoff + len - 1; + + /* Flush the folios at either end of the destination range to prevent + * accidental loss of dirty data outside of the range. + */ + fstart = destoff; + + rc = cifs_flush_folio(target_inode, destoff, &fstart, &fend); + if (rc) + goto unlock; + if (destend > fend) { + rc = cifs_flush_folio(target_inode, destend, NULL, &fend); + if (rc) + goto unlock; + } + + /* Discard all the folios that overlap the destination region. */ + truncate_inode_pages_range(&target_inode->i_data, fstart, fend); rc = file_modified(dst_file); - if (!rc) + if (!rc) { rc = target_tcon->ses->server->ops->copychunk_range(xid, smb_file_src, smb_file_target, off, len, destoff); + if (rc > 0 && destoff + rc > i_size_read(target_inode)) + truncate_setsize(target_inode, destoff + rc); + } file_accessed(src_file);