From patchwork Mon May 1 13:42:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9706629 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 AA5B660385 for ; Mon, 1 May 2017 13:42:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D247205A8 for ; Mon, 1 May 2017 13:42:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9210E2807E; Mon, 1 May 2017 13:42:31 +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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 43D91205A8 for ; Mon, 1 May 2017 13:42:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2998401AbdEANm3 (ORCPT ); Mon, 1 May 2017 09:42:29 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:34130 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1424607AbdEANmU (ORCPT ); Mon, 1 May 2017 09:42:20 -0400 Received: by mail-wr0-f195.google.com with SMTP id 6so13845343wrb.1; Mon, 01 May 2017 06:42:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bmOEW19EBj0cJbVgirfoUmQqyaKf4GZqK30sSY/huaU=; b=kP0OYPJF185QOmmcdaLP1u/6SFEJSGL88jh5WOMVMYfMieRBN4SkMtW9NveteDT01y 6+cxHYiznnUKfo6+MBm5cECgC9oC0y/Cvz6o2pyjc/SW0McImo8osvD43II3OH8T1fIi H69PlFm1Wt9ld1xF5T95X6W7GgEn6wcy+KsHvIH9Z0jdvbPZg5vaF6dYzNYTUzaLcVCi J/5Ez2QCd26IhFw/k+BGtvPf3iy9AKqHrssQpPtxhUz9sBiLkRHI10qJzivbLimE9OI7 rUoRrriXfkrgrdWwbckciVhC77dogKmTufZ3burq6LpkERGz3a/0DBPzWE+h4SLYRBcb 0ZxQ== 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=bmOEW19EBj0cJbVgirfoUmQqyaKf4GZqK30sSY/huaU=; b=KvKbES2Y0N9kpEWSpK3VGUwamfn2KHVnrtePwe5E5Ax07S7i+c6ufLDbBfqWvWg0xF hxjAxQ2FJYkiC/iTjUWo8X7rPiL8EtLRRAavbmgTvWkpI7Cng95723fxCOevLR4L4hLy ujemw+TyZkipWLld8FGxZxa1N51SRUq8ReCsPBz/fMmkJag+in1q1RShnHHjCxNIxnBZ Le27tvdYHS80rBiPjMhJwqCu9uqkClqM7c+m14w6p+RQpCH+z7JkLEUDQHPhx+t1iFij JW14txtTuhqqbA2f3atD546lHX+Rq625ZufIYRhM90DBz9gD1YzdId7MGM3fn7ZofDz8 4fhg== X-Gm-Message-State: AN3rC/53lavw9w9FWulfZXnMpQOJrLh7Ke8llvopw/VIlJxYmG32FPhP n/EonrYd6mY2vw== X-Received: by 10.223.148.5 with SMTP id 5mr13140627wrq.44.1493646138650; Mon, 01 May 2017 06:42:18 -0700 (PDT) Received: from amir-VirtualBox.lan (bzq-79-179-55-127.red.bezeqint.net. [79.179.55.127]) by smtp.gmail.com with ESMTPSA id l82sm12532249wmf.17.2017.05.01.06.42.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 01 May 2017 06:42:18 -0700 (PDT) From: Amir Goldstein To: Miklos Szeredi Cc: Vivek Goyal , Al Viro , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v4 12/15] ovl: fix du --one-file-system on overlay mount Date: Mon, 1 May 2017 16:42:03 +0300 Message-Id: <1493646126-10101-13-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1493646126-10101-1-git-send-email-amir73il@gmail.com> References: <1493646126-10101-1-git-send-email-amir73il@gmail.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 Overlay directory inodes report overlay st_dev to stat(2). Overlay non-dir inodes report real st_dev and real st_ino to stat(2). Due to the different st_dev values for dir and non-dir inodes, when executing the command du -x on an overlay mount, the result is wrong, because non-dirs are not accounted for in the overlay disk usage. The reason that the overlay st_dev is not used for non-dir is because the tuple overlay st_dev and real st_ino is not unique when overlay layers are not on the same fs. When all overlay layers are on the same fs, that tuple is unique, so use overlay st_dev for non-dirs to get the correct result from du -x. Signed-off-by: Amir Goldstein --- fs/overlayfs/inode.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c index 9c0c4e1..ec5230f 100644 --- a/fs/overlayfs/inode.c +++ b/fs/overlayfs/inode.c @@ -73,8 +73,10 @@ static int ovl_getattr(const struct path *path, struct kstat *stat, return err; /* - * When all layers are on the same fs, we use st_ino of the copy up - * origin, if we know it. + * When all layers are on the same fs, all real inode number are + * unique, so we use the overlay st_dev, which is friendly to du -x. + * + * We also use st_ino of the copy up origin, if we know it. * This guaranties constant st_dev/st_ino across copy up. * * When redirect_fh is enabled, this also guaranties persistent @@ -83,15 +85,14 @@ static int ovl_getattr(const struct path *path, struct kstat *stat, if (ovl_same_sb(dentry->d_sb)) { struct dentry *lower = ovl_dentry_lower(dentry); + stat->dev = dentry->d_sb->s_dev; /* * Lower hardlinks are broken on copy up to differnt upper * files, so we cannot use the lower origin st_ino for those * different files, even for the same fs case. */ - if (lower && lower->d_inode->i_nlink == 1) { - stat->dev = lower->d_sb->s_dev; + if (lower && lower->d_inode->i_nlink == 1) stat->ino = lower->d_inode->i_ino; - } } return 0;