From patchwork Mon Oct 30 06:56:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 831900 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 3yQQHz3fyVz9t3B; Mon, 30 Oct 2017 17:56:31 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1e93zo-00031N-FU; Mon, 30 Oct 2017 06:56:28 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1e93zn-00030v-6M for kernel-team@lists.canonical.com; Mon, 30 Oct 2017 06:56:27 +0000 Received: from mail-pg0-f70.google.com ([74.125.83.70]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1e93zm-0003KE-R8 for kernel-team@lists.canonical.com; Mon, 30 Oct 2017 06:56:26 +0000 Received: by mail-pg0-f70.google.com with SMTP id t10so12649467pgo.20 for ; Sun, 29 Oct 2017 23:56:26 -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:subject:date:message-id:in-reply-to :references; bh=DEHameffUZr+1rw6C7h6Qy5UIUnGT1MT4t8M9YjZeEA=; b=lO/ixV/bNle+p1s+KhC4yVudn1lGTdJCD9zuBDi/AKBHnZc0lSv4MW6hlOd5lf1PRV R3VluZf5y5fi/xR/K4w/9tGyZd805xqd73caiYKWl68EbzcWtniTTtL5+9+6CfZaFxEW 3Go/eEwBA6Y6aZR8uBXAo69Wu1la3rUYJIjPWIiBYp9lqZQLb4QAbUpvTG0lSaSEuvmE pTXqYVKGi2NcDQvcKGoHQtk1iSzViyZq9ltyGgRsvDlMS0j9kJYlY7W5fuFbu/YZnEDb sPjZwtXUqevYtbwsqloIhB71KI82bx+NtuyNQ+/hVATZ6HusEE/Qp1aJCIe+9lBKJwDD 4Lcg== X-Gm-Message-State: AMCzsaU09tz50KVsfx7JOIqTv7NFS2MmdsV47p0UX7D6AJIHfIZ8VHSN eKj6G1g0pncByqkFEtR9sc4Ecja6YTHn2BHM6Uf8gvXY+7cDq5SwDqSNqy3NXAzQAnwl99TcxqQ oeoNGnRy9UdejvIopvR/u+5GZibjlAfexfUJRkqfCvqgRHz3y X-Received: by 10.98.147.197 with SMTP id r66mr7950385pfk.20.1509346585386; Sun, 29 Oct 2017 23:56:25 -0700 (PDT) X-Google-Smtp-Source: ABhQp+QBcxP54Kl2ixva4LTssRKjh9upTs59sF8j3dQqQ+e7OYSx7VnbiGc9PrOKR8iKzjNrJRgdFA== X-Received: by 10.98.147.197 with SMTP id r66mr7950379pfk.20.1509346585186; Sun, 29 Oct 2017 23:56:25 -0700 (PDT) Received: from localhost.localdomain (ppp121-45-199-178.bras1.cbr1.internode.on.net. [121.45.199.178]) by smtp.gmail.com with ESMTPSA id 85sm25345850pfz.119.2017.10.29.23.56.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Oct 2017 23:56:24 -0700 (PDT) From: Daniel Axtens To: kernel-team@lists.canonical.com Subject: [SRU][Xenial][PATCH 1/2] ovl: check if all layers are on the same fs Date: Mon, 30 Oct 2017 17:56:13 +1100 Message-Id: <20171030065614.10145-2-daniel.axtens@canonical.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171030065614.10145-1-daniel.axtens@canonical.com> References: <20171030065614.10145-1-daniel.axtens@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Amir Goldstein BugLink: https://bugs.launchpad.net/bugs/1728489 Some features can only work when all layers are on the same fs. Test this condition during mount time, so features can check them later. Add helper ovl_same_sb() to return the common super block in case all layers are on the same fs. Signed-off-by: Amir Goldstein Signed-off-by: Miklos Szeredi (backported from commit 7bcd74b98d7bac3e5149894caaf72de6989af7f0) Signed-off-by: Daniel Axtens --- fs/overlayfs/overlayfs.h | 1 + fs/overlayfs/super.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h index 5ab50cd102af..fdd7ea8b96f3 100644 --- a/fs/overlayfs/overlayfs.h +++ b/fs/overlayfs/overlayfs.h @@ -164,6 +164,7 @@ static inline int ovl_do_whiteout(struct inode *dir, struct dentry *dentry, } const struct cred *ovl_override_creds(struct super_block *sb); +struct super_block *ovl_same_sb(struct super_block *sb); enum ovl_path_type ovl_path_type(struct dentry *dentry); u64 ovl_dentry_version_get(struct dentry *dentry); void ovl_dentry_version_inc(struct dentry *dentry); diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index 6c3077473fa8..9d8e5278a199 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -44,6 +44,8 @@ struct ovl_fs { /* pathnames of lower and upper dirs, for show_options */ struct ovl_config config; struct cred *mounter_creds; + /* sb common to all layers */ + struct super_block *same_sb; }; struct ovl_dir_cache; @@ -430,6 +432,13 @@ static const struct dentry_operations ovl_reval_dentry_operations = { .d_weak_revalidate = ovl_dentry_weak_revalidate, }; +struct super_block *ovl_same_sb(struct super_block *sb) +{ + struct ovl_fs *ofs = sb->s_fs_info; + + return ofs->same_sb; +} + static struct ovl_entry *ovl_alloc_entry(unsigned int numlower) { size_t size = offsetof(struct ovl_entry, lowerstack[numlower]); @@ -1157,11 +1166,19 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent) ufs->lower_mnt[ufs->numlower] = mnt; ufs->numlower++; + + /* Check if all lower layers are on same sb */ + if (i == 0) + ufs->same_sb = mnt->mnt_sb; + else if (ufs->same_sb != mnt->mnt_sb) + ufs->same_sb = NULL; } /* If the upper fs is nonexistent, we mark overlayfs r/o too */ if (!ufs->upper_mnt) sb->s_flags |= MS_RDONLY; + else if (ufs->upper_mnt->mnt_sb != ufs->same_sb) + ufs->same_sb = NULL; if (remote) sb->s_d_op = &ovl_reval_dentry_operations; From patchwork Mon Oct 30 06:56:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 831901 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 3yQQJ24hbHz9t3B; Mon, 30 Oct 2017 17:56:34 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1e93zq-000331-Jo; Mon, 30 Oct 2017 06:56:30 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1e93zp-000320-BB for kernel-team@lists.canonical.com; Mon, 30 Oct 2017 06:56:29 +0000 Received: from mail-pg0-f72.google.com ([74.125.83.72]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1e93zo-0003KJ-W7 for kernel-team@lists.canonical.com; Mon, 30 Oct 2017 06:56:29 +0000 Received: by mail-pg0-f72.google.com with SMTP id u23so12664901pgo.4 for ; Sun, 29 Oct 2017 23:56:28 -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:subject:date:message-id:in-reply-to :references; bh=OqOxsIzXbDVDjp3LaZQ2tH4NhDq6LBBpT8LQ+JF6cvg=; b=IpKjJpUZR4WSdW+0CkASBG9zBDC1nzJKZUiWKgktY+r5ATR2e+q4x/eWy+V9PNDrGN FSVB5LWbaKVc2OjuIcOnT/VnvQtkmgrV9jx55fRlYnO70DEvUnBw9ZImdZRDDaDrCER4 MZxmpuWO6kOesM6oc8d3UfpASXouquDS+VGY2GSlkM1PQG1RPtd/LEmO+yRh/a6z/gTT C8qrN+63RnfDbsLJ571CzfFgOykR75ABj6CObupHEXh2fOvlQW/gw+k18nj0QcJUCruf ZNHIdOp17Nxodip9jwceUV3Id0f0YdvDidFxzGlEqRy2gRacHCt3HwV8FXr+ug87TP4n dG4g== X-Gm-Message-State: AMCzsaXtdAWfZA3KWfYk954W7CKrKP2W+X5gb5X2QlL690BFiVqG8B2C W+T+oRTC1SXgC7elyLFKwM+bTrGvoe7f8K4078eTixT2Dc7MeTfGz47XTFjVsny+/vyfv2YgF5Y cEgZFFJCr1mx57jq1cgC2eCYVeP5rVDc9rjTTgSxUrFByTafe X-Received: by 10.101.81.135 with SMTP id h7mr7190674pgq.320.1509346587582; Sun, 29 Oct 2017 23:56:27 -0700 (PDT) X-Google-Smtp-Source: ABhQp+Qmsvp5zwiCk6AZSefuJmkW773koUo73Qg0gG58thXr2lJcBQy980Uj8k+dNlKl/BMz5knSCw== X-Received: by 10.101.81.135 with SMTP id h7mr7190662pgq.320.1509346587346; Sun, 29 Oct 2017 23:56:27 -0700 (PDT) Received: from localhost.localdomain (ppp121-45-199-178.bras1.cbr1.internode.on.net. [121.45.199.178]) by smtp.gmail.com with ESMTPSA id 85sm25345850pfz.119.2017.10.29.23.56.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Oct 2017 23:56:26 -0700 (PDT) From: Daniel Axtens To: kernel-team@lists.canonical.com Subject: [SRU][Xenial][PATCH 2/2] ovl: persistent inode number for directories Date: Mon, 30 Oct 2017 17:56:14 +1100 Message-Id: <20171030065614.10145-3-daniel.axtens@canonical.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171030065614.10145-1-daniel.axtens@canonical.com> References: <20171030065614.10145-1-daniel.axtens@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Amir Goldstein BugLink: https://bugs.launchpad.net/bugs/1728489 stat(2) on overlay directories reports the overlay temp inode number, which is constant across copy up, but is not persistent. When all layers are on the same fs, report the copy up origin inode number for directories. This inode number is persistent, unique across the overlay mount and constant across copy up. Signed-off-by: Amir Goldstein Signed-off-by: Miklos Szeredi (backported from commit b7a807dc2010334e62e0afd89d6f7a8913eb14ff) Signed-off-by: Daniel Axtens --- fs/overlayfs/dir.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c index 6e0c7274b0f2..7b8bbd05e9a0 100644 --- a/fs/overlayfs/dir.c +++ b/fs/overlayfs/dir.c @@ -176,8 +176,35 @@ static int ovl_dir_getattr(struct vfsmount *mnt, struct dentry *dentry, if (err) return err; + /* + * When all layers are on the same fs, use the copy-up-origin st_ino, + * which is persistent, unique and constant across copy up. + * + * Otherwise the pair {real st_ino; overlay st_dev} is not unique, so + * use the non persistent overlay st_ino. + */ + if (ovl_same_sb(dentry->d_sb)) { + if (OVL_TYPE_MERGE(type) && OVL_TYPE_UPPER(type)) { + struct kstat lowerstat; + + ovl_path_lower(dentry, &realpath); + err = vfs_getattr(&realpath, &lowerstat); + if (err) + return err; + + WARN_ON_ONCE(stat->dev != lowerstat.dev); + stat->ino = lowerstat.ino; + } + } else { + stat->ino = dentry->d_inode->i_ino; + } + + /* + * Always use the overlay st_dev for directories, so 'find -xdev' will + * scan the entire overlay mount and won't cross the overlay mount + * boundaries. + */ stat->dev = dentry->d_sb->s_dev; - stat->ino = dentry->d_inode->i_ino; /* * It's probably not worth it to count subdirs to get the