Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3396106pxf; Mon, 22 Mar 2021 05:35:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrakjqCje2+FeJBl2758IS0st/2TGCDfOISMbCxYYxx5SWZonMktIzMvENWsnwaKIi6ypW X-Received: by 2002:a17:906:1c41:: with SMTP id l1mr19013881ejg.299.1616416558829; Mon, 22 Mar 2021 05:35:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616416558; cv=none; d=google.com; s=arc-20160816; b=kwKWvQqPsfbxk/rIAMx2nKmIkvFrZ1TGSUkLfMPSdrLOSaYCtK9geRa0NpSui/6Y5X 2NiS07E3ibOeUaFnil+Fb15Ymx7t/dHoMKwf8+xJwMaHzyUZBjertcCMobaMptrMatyB toxPzacQLNBFvgMgSeWMSiHrXVki/4Y0e5nzCJIZY0M2tXoZEneX6KSC3FRaqwVQgJ9R l2wRmj6iSbmNVxXksyHuCMa+/RqxMnO0qMz1Wvh3aOYEXt8CjdTfiCxVeIrnh5iRLhTv eoJ7MHoEEfrLNx1Z9qSRUHsPRPYvZQw99tqA+77Wz1fJXqJWzB35SF0hS1LXYBcA4ao8 Miqg== 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:subject:cc:to :from:dkim-signature; bh=wR6eZcLA/n6jPrbtOk/TZ+0aOcZej770JYINUo4ip+E=; b=qUKmuG48Qw8nVgGsLAB1mZJgc3l0UNdwZXfAB/CUQfX3scrsDaX5+Wq/0XZx2xma77 iDSxkYz48VmuIV1wrpPjbV131x20vx0jnr+R7L5W4DbLO9gKdXK89lOX6cFuM2IedmAi CP4n7VDVko91x4hhFqsEewYUE9FF/eFpn9xCLIubtPjWCsfmW5IfjZMP1KY+eTchPBd7 7JCRqWznwS2+bZbGSKT+sIUGlGis82X6GPlhWRMl0y0FzeTtEWyO5beCPuZbY4Utr72G w4l/ekiKY91NayvTe9lpqSqV5pHOBv9nhdk2ecTe4kR2qDJq/z/TUD6Y9uUbq2LaXpDv FXAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wySULFtf; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ca24si11133057edb.330.2021.03.22.05.35.36; Mon, 22 Mar 2021 05:35:58 -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=@linuxfoundation.org header.s=korg header.b=wySULFtf; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231558AbhCVMe0 (ORCPT + 99 others); Mon, 22 Mar 2021 08:34:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:54828 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231460AbhCVMcJ (ORCPT ); Mon, 22 Mar 2021 08:32:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DD71E619A8; Mon, 22 Mar 2021 12:32:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1616416322; bh=FF+/HZal6UdekTFYU1FwbwMDwy1bNdTFtT35oxYa1yQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wySULFtfFb4dp6W1xLdnNEWHDlyXn8jVnxMdZ3rYJaX6d4lGszEoPn3qVVilN+3ur lL+w3gMRUzkTU4GFrqehcypDSnOouaHWh2vQFsJxrGaxpyMyHQR6Bwm6VE03KxtN0/ qW8X6xix2nIhiLJUFdOSEXgvhtSj0jkNvFniwFw8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Steve French , Aurelien Aptel Subject: [PATCH 5.11 061/120] cifs: fix allocation size on newly created files Date: Mon, 22 Mar 2021 13:27:24 +0100 Message-Id: <20210322121931.724084948@linuxfoundation.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210322121929.669628946@linuxfoundation.org> References: <20210322121929.669628946@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Steve French commit 65af8f0166f4d15e61c63db498ec7981acdd897f upstream. Applications that create and extend and write to a file do not expect to see 0 allocation size. When file is extended, set its allocation size to a plausible value until we have a chance to query the server for it. When the file is cached this will prevent showing an impossible number of allocated blocks (like 0). This fixes e.g. xfstests 614 which does 1) create a file and set its size to 64K 2) mmap write 64K to the file 3) stat -c %b for the file (to query the number of allocated blocks) It was failing because we returned 0 blocks. Even though we would return the correct cached file size, we returned an impossible allocation size. Signed-off-by: Steve French CC: Reviewed-by: Aurelien Aptel Signed-off-by: Greg Kroah-Hartman --- fs/cifs/inode.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c @@ -2383,7 +2383,7 @@ int cifs_getattr(const struct path *path * We need to be sure that all dirty pages are written and the server * has actual ctime, mtime and file length. */ - if ((request_mask & (STATX_CTIME | STATX_MTIME | STATX_SIZE)) && + if ((request_mask & (STATX_CTIME | STATX_MTIME | STATX_SIZE | STATX_BLOCKS)) && !CIFS_CACHE_READ(CIFS_I(inode)) && inode->i_mapping && inode->i_mapping->nrpages != 0) { rc = filemap_fdatawait(inode->i_mapping); @@ -2573,6 +2573,14 @@ set_size_out: if (rc == 0) { cifsInode->server_eof = attrs->ia_size; cifs_setsize(inode, attrs->ia_size); + /* + * i_blocks is not related to (i_size / i_blksize), but instead + * 512 byte (2**9) size is required for calculating num blocks. + * Until we can query the server for actual allocation size, + * this is best estimate we have for blocks allocated for a file + * Number of blocks must be rounded up so size 1 is not 0 blocks + */ + inode->i_blocks = (512 - 1 + attrs->ia_size) >> 9; /* * The man page of truncate says if the size changed,