From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752179AbdBTIDG (ORCPT ); Mon, 20 Feb 2017 03:03:06 -0500 Received: from szxga01-in.huawei.com ([45.249.212.187]:2808 "EHLO dggrg01-dlp.huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752116AbdBTIDD (ORCPT ); Mon, 20 Feb 2017 03:03:03 -0500 X-Greylist: delayed 800 seconds by postgrey-1.27 at vger.kernel.org; Mon, 20 Feb 2017 03:02:57 EST Subject: Re: [PATCH 4/9] vfs: intercept reads to overlay files References: <1487347778-18596-1-git-send-email-mszeredi@redhat.com> <1487347778-18596-5-git-send-email-mszeredi@redhat.com> From: "zhangyi (F)" To: CC: , , , Al Viro , Message-ID: Date: Mon, 20 Feb 2017 15:47:03 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.244.145] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090206.58AA9F4B.0006,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 21d3f82f0c6c687967163cf04678c85b Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2017/2/18 00:10, Miklos Szeredi wrote: > diff --git a/fs/open.c b/fs/open.c > index 9921f70bc5ca..4916ccff29f5 100644 > --- a/fs/open.c > +++ b/fs/open.c > @@ -762,6 +762,8 @@ static int do_dentry_open(struct file *f, > if ((f->f_mode & FMODE_WRITE) && > likely(f->f_op->write || f->f_op->write_iter)) > f->f_mode |= FMODE_CAN_WRITE; > + if (unlikely(d_inode(f->f_path.dentry) != inode)) > + f->f_mode |= FMODE_OVERLAY; Can we just add flag to the "readonly && not copied" file, not all overlayfs files? Beacuse we just want to check the ro file before copied-up. > f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC); > > diff --git a/fs/overlay_util.c b/fs/overlay_util.c new file mode 100644 index 000000000000..0daff19bad0b > --- /dev/null > +++ b/fs/overlay_util.c > @@ -0,0 +1,39 @@ > +/* > + * 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. > + */ > +#if IS_ENABLED(CONFIG_OVERLAY_FS) > + > +#include > +#include > +#include > +#include "internal.h" > + > +static bool overlay_file_consistent(struct file *file) { > + return d_real_inode(file->f_path.dentry) == file_inode(file); } > + > +ssize_t overlay_read_iter(struct file *file, struct kiocb *kio, > + struct iov_iter *iter) > +{ > + ssize_t ret; > + > + if (likely(overlay_file_consistent(file))) > + return file->f_op->read_iter(kio, iter); > + > + file = filp_clone_open(file); > + if (IS_ERR(file)) > + return PTR_ERR(file); > + > + ret = vfs_iter_read(file, iter, &kio->ki_pos); > + fput(file); > + > + return ret; > +} > +EXPORT_SYMBOL(overlay_read_iter); Can we try to replace the old file with the new file, and then clear the f_mode flag we added? If so, we can avoid opening file for each reading call and avoid copied file consistency check. Thanks. zhangyi