Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp6017877ybc; Wed, 27 Nov 2019 13:29:39 -0800 (PST) X-Google-Smtp-Source: APXvYqyZItxze2E10TY/rvS1iPm6Y4sBwZ188fNNHoh8ezdVO4nSVrrq9qJUws20JcwevbolPRaq X-Received: by 2002:aa7:d7d7:: with SMTP id e23mr33451657eds.236.1574890179255; Wed, 27 Nov 2019 13:29:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574890179; cv=none; d=google.com; s=arc-20160816; b=rbnLn/P4bGxUn/ypV/BzwUJYytODrGpD+kEBaXqShlkjd7KUjnOJVqBd5FAcdg7De4 Jgv8GcUrimtD1d8XeS8e5ZBA2XyHGPdCTUKTsM9zLks2sQFYbtD5gaD1dFzRiXgfudYb RoStvkv1BKcTUqjIqcf8M7SIiQ8+uUfHqUMzIwAzNdnY1QbUncUx5VtMT4m8c9VB+Iod YsomHTps2YpqJxN0+GUwt1g5tAljyLHN8muY/32JbMDNzi6jchaZmb0G6g/apIoidpci SBJsciUEanUtPImLBPXfijyEYtdbeQMG9VnyG6TafxV0xaNJaIbY7/jugVQ+9gLf7vl5 YyuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kiTDb1mP8pQIC5fKM0b0g+yNOqWL+lIhOlt0RhotVdc=; b=cRPRhVJe0yXR0q7LtByOssLoY6zT+ZdwV/UFDLqMT9n2SeZu1I07ek921uU78LNkLb xeqyZ+Degij32/KWNGXvr/7JE1bQm/9KEcRmWwEET7H3c3tkzLqmpWQ6KnvKhU48aRfM qAnTpGSQfnR4xuLWXNEV4bSdMWMhP0RwBE39qh4HDR877/ldyul9aQNHT64tNKqHiVbn esp+6gt4aP95GZF6wO1Cam6L/n0lFH9QVGOrRMFcpY2Xa3pf//dE37zEWxzUrPmiiiXx ZGv/IHz0xkhazt88sM/0vC9K8+fIpiKCu9ZJZDTONQ0Scz7CSKx894Bz+Tt044eW3ltZ iJTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rCT5LsrW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cb26si12658476edb.106.2019.11.27.13.29.16; Wed, 27 Nov 2019 13:29:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rCT5LsrW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731243AbfK0VAB (ORCPT + 99 others); Wed, 27 Nov 2019 16:00:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:51604 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731493AbfK0U75 (ORCPT ); Wed, 27 Nov 2019 15:59:57 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6D69920862; Wed, 27 Nov 2019 20:59:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888396; bh=9jTiWjD3dsUPaP+cMWDmZ87NWsOHV8AQalAaCPDJXAk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rCT5LsrWqr4b4jp406paMYiGwztE7ob66cPfgUHJUSksXMF+L26cErtynG7kZWuf7 lsu30tib5t8Nv5vGxLzIjTX7XjHE0MYLFZym+ZdD7dmwobsrVmqpgPXemxFI1qliE3 +xr+jZUH3gHvDwzmhkBq3aPD/G4wDYze3xRd8G80= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Luis Henriques , "Yan, Zheng" , Ilya Dryomov , Sasha Levin Subject: [PATCH 4.19 118/306] ceph: only allow punch hole mode in fallocate Date: Wed, 27 Nov 2019 21:29:28 +0100 Message-Id: <20191127203123.779382363@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203114.766709977@linuxfoundation.org> References: <20191127203114.766709977@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Luis Henriques [ Upstream commit bddff633ab7bc60a18a86ac8b322695b6f8594d0 ] Current implementation of cephfs fallocate isn't correct as it doesn't really reserve the space in the cluster, which means that a subsequent call to a write may actually fail due to lack of space. In fact, it is currently possible to fallocate an amount space that is larger than the free space in the cluster. It has behaved this way since the initial commit ad7a60de882a ("ceph: punch hole support"). Since there's no easy solution to fix this at the moment, this patch simply removes support for all fallocate operations but FALLOC_FL_PUNCH_HOLE (which implies FALLOC_FL_KEEP_SIZE). Link: https://tracker.ceph.com/issues/36317 Signed-off-by: Luis Henriques Reviewed-by: "Yan, Zheng" Signed-off-by: Ilya Dryomov Signed-off-by: Sasha Levin --- fs/ceph/file.c | 45 +++++++++------------------------------------ 1 file changed, 9 insertions(+), 36 deletions(-) diff --git a/fs/ceph/file.c b/fs/ceph/file.c index 92ab204336829..91a7ad259bcf2 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -1735,7 +1735,6 @@ static long ceph_fallocate(struct file *file, int mode, struct ceph_file_info *fi = file->private_data; struct inode *inode = file_inode(file); struct ceph_inode_info *ci = ceph_inode(inode); - struct ceph_fs_client *fsc = ceph_inode_to_client(inode); struct ceph_cap_flush *prealloc_cf; int want, got = 0; int dirty; @@ -1743,10 +1742,7 @@ static long ceph_fallocate(struct file *file, int mode, loff_t endoff = 0; loff_t size; - if ((offset + length) > max(i_size_read(inode), fsc->max_file_size)) - return -EFBIG; - - if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE)) + if (mode != (FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE)) return -EOPNOTSUPP; if (!S_ISREG(inode->i_mode)) @@ -1763,18 +1759,6 @@ static long ceph_fallocate(struct file *file, int mode, goto unlock; } - if (!(mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE)) && - ceph_quota_is_max_bytes_exceeded(inode, offset + length)) { - ret = -EDQUOT; - goto unlock; - } - - if (ceph_osdmap_flag(&fsc->client->osdc, CEPH_OSDMAP_FULL) && - !(mode & FALLOC_FL_PUNCH_HOLE)) { - ret = -ENOSPC; - goto unlock; - } - if (ci->i_inline_version != CEPH_INLINE_NONE) { ret = ceph_uninline_data(file, NULL); if (ret < 0) @@ -1782,12 +1766,12 @@ static long ceph_fallocate(struct file *file, int mode, } size = i_size_read(inode); - if (!(mode & FALLOC_FL_KEEP_SIZE)) { - endoff = offset + length; - ret = inode_newsize_ok(inode, endoff); - if (ret) - goto unlock; - } + + /* Are we punching a hole beyond EOF? */ + if (offset >= size) + goto unlock; + if ((offset + length) > size) + length = size - offset; if (fi->fmode & CEPH_FILE_MODE_LAZY) want = CEPH_CAP_FILE_BUFFER | CEPH_CAP_FILE_LAZYIO; @@ -1798,16 +1782,8 @@ static long ceph_fallocate(struct file *file, int mode, if (ret < 0) goto unlock; - if (mode & FALLOC_FL_PUNCH_HOLE) { - if (offset < size) - ceph_zero_pagecache_range(inode, offset, length); - ret = ceph_zero_objects(inode, offset, length); - } else if (endoff > size) { - truncate_pagecache_range(inode, size, -1); - if (ceph_inode_set_size(inode, endoff)) - ceph_check_caps(ceph_inode(inode), - CHECK_CAPS_AUTHONLY, NULL); - } + ceph_zero_pagecache_range(inode, offset, length); + ret = ceph_zero_objects(inode, offset, length); if (!ret) { spin_lock(&ci->i_ceph_lock); @@ -1817,9 +1793,6 @@ static long ceph_fallocate(struct file *file, int mode, spin_unlock(&ci->i_ceph_lock); if (dirty) __mark_inode_dirty(inode, dirty); - if ((endoff > size) && - ceph_quota_is_max_bytes_approaching(inode, endoff)) - ceph_check_caps(ci, CHECK_CAPS_NODELAY, NULL); } ceph_put_cap_refs(ci, got); -- 2.20.1