From patchwork Fri Jul 1 02:52:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hu Weiwen X-Patchwork-Id: 586344 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3551C43334 for ; Fri, 1 Jul 2022 02:53:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233740AbiGACxT (ORCPT ); Thu, 30 Jun 2022 22:53:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233716AbiGACxR (ORCPT ); Thu, 30 Jun 2022 22:53:17 -0400 Received: from mail.scut.edu.cn (stumail2.scut.edu.cn [202.38.213.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 38CEF18399 for ; Thu, 30 Jun 2022 19:53:13 -0700 (PDT) Received: from IT00043538.localdomain (unknown [120.196.70.37]) by main (Coremail) with SMTP id AQAAfwCH6H1WYb5iao+OAA--.64930S2; Fri, 01 Jul 2022 10:52:06 +0800 (CST) From: Hu Weiwen To: Xiubo Li , ceph-devel@vger.kernel.org Cc: Hu Weiwen Subject: [RESEND PATCH] ceph: don't truncate file in atomic_open Date: Fri, 1 Jul 2022 10:52:27 +0800 Message-Id: <20220701025227.21636-1-sehuww@mail.scut.edu.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <59d7c10f-7419-971b-c13c-71865f897953@redhat.com> References: <59d7c10f-7419-971b-c13c-71865f897953@redhat.com> MIME-Version: 1.0 X-CM-TRANSID: AQAAfwCH6H1WYb5iao+OAA--.64930S2 X-Coremail-Antispam: 1UD129KBjvJXoW7tr48tF18GFW8ArW5Xr1fWFg_yoW8GF4DpF 4fXF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devel@vger.kernel.org Clear O_TRUNC from the flags sent in the MDS create request. `atomic_open' is called before permission check. We should not do any modification to the file here. The caller will do the truncation afterward. Fixes: 124e68e74099 ("ceph: file operations") Signed-off-by: Hu Weiwen --- rebased onto ceph_client repo testing branch fs/ceph/file.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/ceph/file.c b/fs/ceph/file.c index 296fd1c7ece8..289e66e9cbb0 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -745,6 +745,11 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry, err = ceph_wait_on_conflict_unlink(dentry); if (err) return err; + /* + * Do not truncate the file, since atomic_open is called before the + * permission check. The caller will do the truncation afterward. + */ + flags &= ~O_TRUNC; retry: if (flags & O_CREAT) { @@ -836,9 +841,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry, set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags); req->r_new_inode = new_inode; new_inode = NULL; - err = ceph_mdsc_do_request(mdsc, - (flags & (O_CREAT|O_TRUNC)) ? dir : NULL, - req); + err = ceph_mdsc_do_request(mdsc, (flags & O_CREAT) ? dir : NULL, req); if (err == -ENOENT) { dentry = ceph_handle_snapdir(req, dentry); if (IS_ERR(dentry)) {