Received: by 10.192.165.148 with SMTP id m20csp2263047imm; Thu, 26 Apr 2018 08:15:37 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/rUSBraHGXVhbaGDIRjz7DAhRyIui9MwRMarV5q8UACLjBJva9oRS44jpVZk6WR9e5b8E5 X-Received: by 2002:a17:902:24c:: with SMTP id 70-v6mr34723306plc.384.1524755737577; Thu, 26 Apr 2018 08:15:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524755737; cv=none; d=google.com; s=arc-20160816; b=YGLUf0vPsDzXiXhAGwrJHsuYc/Nc29qtUH6MKBJM7a+bTQvjokcopG6t5d+WJx59ln ZBWAnL1XFgSp0Bgh+eQ2iGoG7Cqg5TRS2gumDXBSunh0jZPHKcjbNbjahHun5wHYGAKC 1f+MeWqu4XxTecARWh4axEKmB0Ztwf+qpbjPcJqwFZMyQBwfsjpl7eeTA7Al0QOhC5iT ta/6AQ4LL4nz86z2FmptSUkpeplU9HJjGmW25J63DTJax8fGqttFtg23vLhN6w+1RqRr kYcb3ZxNfvVEpbesbJajzvpapTITToOhl/XNKPsE3zQV/7Nj/IiGlUKfWFoYs3lXG2k8 J89g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=1TRx9pO/yGBE6etRiLTgrlHW13hAyn4NbSdFPim10AQ=; b=L3X2BbtRBTKN3F/kPAbigw+2idRTPpsYfDGlj8EpGCLSWlj1cbg8gFj9o4gIl2tHsC KGQ9/1z9W/56/GAy1JB0aR0qPjw8fnm2ZG9kkVo+r/bjAuVzhMNcjEADloQQs6GVOrEu YuTsn7jWMW0IkLb3fBG2oq4I0/g9pv6OTZXgovfWRx0BNdVHJiWqegn/kdse+Q++9fKF I1XsS+CSZZcudQtq2nXQlXshopctIqTGgAbZ+SI0wQlxyovKHTU3v3eJHcVb68klD8M/ 0JC2t6nd2DmJu3MIUEAICJota1TGo3T2KexXU6mCKmFbi1ZSN+lhbF9g5SAqfTff8Kni OFEg== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p15si4470748pgq.478.2018.04.26.08.15.23; Thu, 26 Apr 2018 08:15:37 -0700 (PDT) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756676AbeDZPNJ (ORCPT + 99 others); Thu, 26 Apr 2018 11:13:09 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55958 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756262AbeDZPNG (ORCPT ); Thu, 26 Apr 2018 11:13:06 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1F433410FBB6; Thu, 26 Apr 2018 15:13:06 +0000 (UTC) Received: from horse.redhat.com (unknown [10.18.25.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B2A0215CDC8; Thu, 26 Apr 2018 15:13:06 +0000 (UTC) Received: by horse.redhat.com (Postfix, from userid 10451) id D0AEE220267; Thu, 26 Apr 2018 11:13:05 -0400 (EDT) Date: Thu, 26 Apr 2018 11:13:05 -0400 From: Vivek Goyal To: Miklos Szeredi Cc: Miklos Szeredi , overlayfs , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 09/35] ovl: stack file ops Message-ID: <20180426151305.GC4308@redhat.com> References: <20180412150826.20988-1-mszeredi@redhat.com> <20180412150826.20988-10-mszeredi@redhat.com> <20180426141337.GA4308@redhat.com> <20180426145641.GB4308@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.1 (2017-09-22) X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 26 Apr 2018 15:13:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 26 Apr 2018 15:13:06 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'vgoyal@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 26, 2018 at 05:01:37PM +0200, Miklos Szeredi wrote: > On Thu, Apr 26, 2018 at 4:56 PM, Vivek Goyal wrote: > > On Thu, Apr 26, 2018 at 04:43:53PM +0200, Miklos Szeredi wrote: > >> On Thu, Apr 26, 2018 at 4:13 PM, Vivek Goyal wrote: > >> > On Thu, Apr 12, 2018 at 05:08:00PM +0200, Miklos Szeredi wrote: > >> > > >> > [..] > >> >> diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c > >> >> new file mode 100644 > >> >> index 000000000000..a0b606885c41 > >> >> --- /dev/null > >> >> +++ b/fs/overlayfs/file.c > >> >> @@ -0,0 +1,76 @@ > >> >> +/* > >> >> + * Copyright (C) 2017 Red Hat, Inc. > >> >> + * > >> >> + * This program is free software; you can redistribute it and/or modify it > >> >> + * under the terms of the GNU General Public License version 2 as published by > >> >> + * the Free Software Foundation. > >> >> + */ > >> >> + > >> >> +#include > >> >> +#include > >> >> +#include > >> >> +#include "overlayfs.h" > >> >> + > >> >> +static struct file *ovl_open_realfile(const struct file *file) > >> >> +{ > >> >> + struct inode *inode = file_inode(file); > >> >> + struct inode *upperinode = ovl_inode_upper(inode); > >> >> + struct inode *realinode = upperinode ?: ovl_inode_lower(inode); > >> >> + struct file *realfile; > >> >> + const struct cred *old_cred; > >> >> + > >> >> + old_cred = ovl_override_creds(inode->i_sb); > >> >> + realfile = path_open(&file->f_path, file->f_flags | O_NOATIME, > >> >> + realinode, current_cred(), false); > >> >> + revert_creds(old_cred); > >> >> + > >> >> + pr_debug("open(%p[%pD2/%c], 0%o) -> (%p, 0%o)\n", > >> >> + file, file, upperinode ? 'u' : 'l', file->f_flags, > >> >> + realfile, IS_ERR(realfile) ? 0 : realfile->f_flags); > >> >> + > >> >> + return realfile; > >> >> +} > >> >> + > >> >> +static int ovl_open(struct inode *inode, struct file *file) > >> >> +{ > >> >> + struct dentry *dentry = file_dentry(file); > >> > > >> > Hi Miklos, > >> > > >> > There is one thing I can't wrap my head around, so I better ask. > >> > > >> > file_dentry() will call ovl_d_real() and try to find dentry based on > >> > inode installed in f->f_inode. If ovl_d_real() can't find inode dentry > >> > matching the passed in inode, it warns. > >> > > >> > Assume, I have a stacked overlay configuration. Let me call top level > >> > overlay layer ovl1 and lower level overlay layer ovl2. Say I open a > >> > file foo.txt. Now ovl_open() in ovl1 decides that realinode is a lower > >> > inode and installs that inode f->f_inode of realfile. (This should be > >> > ovl2 layer inode, let me call it ovl2_inode). Now ovl_open() of ovl2 layer > >> > will be called and it will call file_dentry() and will look for dentry > >> > corresponding to ovl2_inode. I am wondering what if a copy up of foo.txt > >> > was triggered in ovl1 and by the time we called ovl_d_real(dentry, > >> > ovl2_inode), it will start comparing with inode of ovl1_upper and never > >> > find ovl2_inode. > >> > >> Okay, so we've modified ovl_d_real() to allow returning the overlay > >> dentry itself. This is important: when we fail to match ovl1_upper > >> with ovl2_inode, well go on to get ovl2_dentry and call d_real() > >> recursively. That recursive call should match the inode, return it to > >> outer ovl_d_real(), which again will match the inode and return > >> without warning. > > > > So current code does following. > > > > ovl_d_real() { > > ... > > ... > > > > real = ovl_dentry_real(dentry); > > if (inode == d_inode(real)) > > return real; > > > > /* Handle recursion */ > > if (unlikely(real->d_flags & DCACHE_OP_REAL)) > > return real->d_op->d_real(real, inode); > > } > > > > If file got copied up in ovl1, then "real" will be ovl1_upper dentry. And > > upper is regular fs (only ovl1 lower is overlay), then it should not have > > DCACHE_OP_REAL set and that means we will not recurse further and not > > find ovl2 dentry matching ovl2_inode and print warning and return > > ovl1 dentry. > > > > What am I missing. > > Ah, that's indeed buggy. The bug is in "[RFC PATCH 34/35] vfs: > simplify d_op->d_real()". > > I've already reverted that (due to d_real_inode() acquiring a new > user) and the old code should be good (AFAICS). Aha, cool. thanks. While I am at it, let me just ask one more stupid question. I am wondering while opening the underlying realfile, why do we pass in the path/dentry of ovl layer (and not underlying real layer). realfile = path_open(&file->f_path, file->f_flags | O_NOATIME, realinode, current_cred(), false); This forces us to do file_dentry() in ovl_open() later to map top level dentry to underlying dentry. We know the realinode and should be figure out real dentry. Can't we construct path from underlying dentry and mount point and use that to open underlying real file. I am sure there is some reason for doing this way, just trying to understand it. Vivek