From patchwork Tue May 29 14:46:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 10435759 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4AC80602BF for ; Tue, 29 May 2018 14:48:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A760284C3 for ; Tue, 29 May 2018 14:48:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F0A62860C; Tue, 29 May 2018 14:48:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3521284C3 for ; Tue, 29 May 2018 14:48:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935576AbeE2OsY (ORCPT ); Tue, 29 May 2018 10:48:24 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:55950 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936677AbeE2Oqs (ORCPT ); Tue, 29 May 2018 10:46:48 -0400 Received: by mail-wm0-f66.google.com with SMTP id a8-v6so41346990wmg.5 for ; Tue, 29 May 2018 07:46:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=esBFL3bJJqdjUY4IuWwcTEJ8/TNaqhdkM1KTquCiceA=; b=gjN/OqoUlrgnuBFodaL7/jJX+Hw75luKr0isMErjCQZFxOeWvP+/lZG14gSEGfB/78 8wAPhZRkRAuUEc7qNRlSEHJEKYRKkfmUSPUoorgj+cD/J9jK25ygIseMkVx1izKPcpGO RGT7nCw642pwRFgZNJXkkYkX4VKMq9epjCeGS/IwJLh/KH+0n9JIoHL9YJSzd77dAiEj kEKitez7UKHhYB6fVjgWbN60FW36J53ubNhtPyzMpOBdGs7ozT2XB6sH8iCYhl7e7RqL 4FxPeANakVzy6L+/qLEqlUxV2nJjRJcP5kebf/GwncjW4hybpBXtsZDOgIR0xbvzyLtR uoLg== X-Gm-Message-State: ALKqPwcwsiN8UaXMAQS30l91gekyv3VkY4bqyz4TOz/8y6/1iZNG9Ada 7oZ5rFhMLU3BD/ibBTc6yswns03rXS8= X-Google-Smtp-Source: ADUXVKJcjFJjsCjNAH6UL4Zu3fRSFthGwhbZxYiGuR8OFKYigR3drmp6Rd8JNpqM5AZ2SkplovybqA== X-Received: by 2002:a1c:6503:: with SMTP id z3-v6mr10530590wmb.11.1527605207090; Tue, 29 May 2018 07:46:47 -0700 (PDT) Received: from veci.piliscsaba.redhat.com (catv-176-63-54-97.catv.broadband.hu. [176.63.54.97]) by smtp.gmail.com with ESMTPSA id n71-v6sm20942227wmi.14.2018.05.29.07.46.45 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 May 2018 07:46:46 -0700 (PDT) From: Miklos Szeredi To: linux-unionfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 26/28] ovl: Do not do metadata only copy-up for truncate operation Date: Tue, 29 May 2018 16:46:10 +0200 Message-Id: <20180529144612.16675-27-mszeredi@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180529144612.16675-1-mszeredi@redhat.com> References: <20180529144612.16675-1-mszeredi@redhat.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Vivek Goyal truncate should copy up full file (and not do metacopy only), otherwise it will be broken. For example, use truncate to increase size of a file so that any read beyong existing size will return null bytes. If we don't copy up full file, then we end up opening lower file and read from it only reads upto the old size (and not new size after truncate). Hence to avoid such situations, copy up data as well when file size changes. So far it was being done by d_real(O_WRONLY) call in truncate() path. Now that patch has been reverted. So force full copy up in ovl_setattr() if size of file is changing. Signed-off-by: Vivek Goyal Reviewed-by: Amir Goldstein Signed-off-by: Miklos Szeredi --- fs/overlayfs/inode.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c index ac1d2a581a6e..e31d64206a01 100644 --- a/fs/overlayfs/inode.c +++ b/fs/overlayfs/inode.c @@ -19,6 +19,7 @@ int ovl_setattr(struct dentry *dentry, struct iattr *attr) { int err; + bool full_copy_up = false; struct dentry *upperdentry; const struct cred *old_cred; @@ -36,9 +37,15 @@ int ovl_setattr(struct dentry *dentry, struct iattr *attr) err = -ETXTBSY; if (atomic_read(&realinode->i_writecount) < 0) goto out_drop_write; + + /* Truncate should trigger data copy up as well */ + full_copy_up = true; } - err = ovl_copy_up(dentry); + if (!full_copy_up) + err = ovl_copy_up(dentry); + else + err = ovl_copy_up_with_data(dentry); if (!err) { struct inode *winode = NULL;