From patchwork Mon May 7 08:37:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 10383603 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 9B91760159 for ; Mon, 7 May 2018 08:47:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8FE9E28823 for ; Mon, 7 May 2018 08:47:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 84CA528B24; Mon, 7 May 2018 08:47:32 +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 317FF28823 for ; Mon, 7 May 2018 08:47:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752416AbeEGIr3 (ORCPT ); Mon, 7 May 2018 04:47:29 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:52114 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752135AbeEGIi3 (ORCPT ); Mon, 7 May 2018 04:38:29 -0400 Received: by mail-wm0-f65.google.com with SMTP id j4so12056936wme.1 for ; Mon, 07 May 2018 01:38: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:cc:subject:date:message-id:in-reply-to :references; bh=w3ISRALrxiZb0tBpzTga2UiXWAM05XSQu1T1cGI0SkM=; b=alASHuP4Ab3FkZKfArvbPhtv8YeP6Lmv/MWTvU0raSt//MafyikipQKX78SiGaDUHG v8vLS7TaXbORCMGSf4cD+RpT919aOLXU4HlFuPWJ8zcmv6ONG1bGUITqvSW8WTFFwot5 cvkEj0a+Eeb1hLqn9SCWWN77cJETXKshHFpTyQ6c8i0rnPcTs3ot04xtefl2RgWZsBMj eumdQsKoWaL8cng+jfjmqxUpUKzolIbpvf9Xod97juuPkPP9r7oBXsAxiXJSJoqak7sq P6pxWrE8L3vuBVmLKmxhUgRLaJhOykK++Cqlt4V33v74gvR+ecidIghSbJhSRNxZj2r5 BqwA== X-Gm-Message-State: ALKqPwdl2OXI+wB+kjXp2uk8SeCz5vWbOSe0Ph82ttvlyOgRY0N1PzX9 am0+//5pxkb4d5HUu4GAdYdniP1txb4= X-Google-Smtp-Source: AB8JxZpJOuj9KlLFID6hXT8iK8qf7F6LGf3fUYHVn95LwmgmagIsnl+YlyUKK7EsSQysQoXIHVuyaw== X-Received: by 2002:a1c:7e8d:: with SMTP id z135-v6mr184267wmc.6.1525682308054; Mon, 07 May 2018 01:38:28 -0700 (PDT) Received: from veci.piliscsaba.redhat.com (C2B0E321.catv.pool.telekom.hu. [194.176.227.33]) by smtp.gmail.com with ESMTPSA id h8-v6sm5908050wmc.16.2018.05.07.01.38.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 May 2018 01:38:27 -0700 (PDT) From: Miklos Szeredi To: linux-unionfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 13/35] ovl: add ovl_read_iter() Date: Mon, 7 May 2018 10:37:45 +0200 Message-Id: <20180507083807.28792-14-mszeredi@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180507083807.28792-1-mszeredi@redhat.com> References: <20180507083807.28792-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 Implement stacked reading. Signed-off-by: Miklos Szeredi --- fs/overlayfs/file.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index db8778e7c37a..bbc40a14acf8 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "overlayfs.h" static struct file *ovl_open_realfile(const struct file *file) @@ -129,8 +130,74 @@ static loff_t ovl_llseek(struct file *file, loff_t offset, int whence) i_size_read(realinode)); } +static void ovl_file_accessed(struct file *file) +{ + struct inode *inode, *upperinode; + + if (file->f_flags & O_NOATIME) + return; + + inode = file_inode(file); + upperinode = ovl_inode_upper(inode); + + if (!upperinode) + return; + + if ((!timespec_equal(&inode->i_mtime, &upperinode->i_mtime) || + !timespec_equal(&inode->i_ctime, &upperinode->i_ctime))) { + inode->i_mtime = upperinode->i_mtime; + inode->i_ctime = upperinode->i_ctime; + } + + touch_atime(&file->f_path); +} + +static rwf_t ovl_iocb_to_rwf(struct kiocb *iocb) +{ + int ifl = iocb->ki_flags; + rwf_t flags = 0; + + if (ifl & IOCB_NOWAIT) + flags |= RWF_NOWAIT; + if (ifl & IOCB_HIPRI) + flags |= RWF_HIPRI; + if (ifl & IOCB_DSYNC) + flags |= RWF_DSYNC; + if (ifl & IOCB_SYNC) + flags |= RWF_SYNC; + + return flags; +} + +static ssize_t ovl_read_iter(struct kiocb *iocb, struct iov_iter *iter) +{ + struct file *file = iocb->ki_filp; + struct fd real; + const struct cred *old_cred; + ssize_t ret; + + if (!iov_iter_count(iter)) + return 0; + + ret = ovl_real_fdget(file, &real); + if (ret) + return ret; + + old_cred = ovl_override_creds(file_inode(file)->i_sb); + ret = vfs_iter_read(real.file, iter, &iocb->ki_pos, + ovl_iocb_to_rwf(iocb)); + revert_creds(old_cred); + + ovl_file_accessed(file); + + fdput(real); + + return ret; +} + const struct file_operations ovl_file_operations = { .open = ovl_open, .release = ovl_release, .llseek = ovl_llseek, + .read_iter = ovl_read_iter, };