From patchwork Thu Apr 12 15:08:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 10338817 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 BE799602D8 for ; Thu, 12 Apr 2018 15:22:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B414925F31 for ; Thu, 12 Apr 2018 15:22:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A8DA52785D; Thu, 12 Apr 2018 15:22:17 +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=unavailable 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 5BB5025F31 for ; Thu, 12 Apr 2018 15:22:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753725AbeDLPVq (ORCPT ); Thu, 12 Apr 2018 11:21:46 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:37876 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753160AbeDLPIq (ORCPT ); Thu, 12 Apr 2018 11:08:46 -0400 Received: by mail-wm0-f68.google.com with SMTP id l16so6486620wmh.2 for ; Thu, 12 Apr 2018 08:08:45 -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=rCTtcbDKZXF0c1i1Wkkh8uHzOuMNIKfNqc4AZVAAq6g=; b=iPBQt7C5wxC+dHXpBzZ3mHpHLscBS8qWXi6E7pBKTjJ1EVUObH4/wJWCxeGWz9sqgf o2bzgw8QBtlkFxGASRejL4g1/rPqaUxsSVlMuMs3aZZmXWSI/ccvix3MT+hJhvPqi70+ bG1OpamTa9fzkPrXAAcs5kXpGJcpOBYHQXKBETbDK2x+YQObbqk6df0hwyBAQb+5mHeu ePSxazPAqssnRFbb6VmFpkZOXi2pTNdnqFQlzm+PhleHbvpOT0vKR8T7FDEDOiEvPzxF jo5MYKPrJFibmAkqq0VzH83eynEk+JgXCJ3cog/DW0G3rEEG6hN1aConL0rO0NOrgR6k o3ig== X-Gm-Message-State: ALQs6tDKa5K6tPP5vLE3z6wqQJb6fyMesRQZD1hEqf5EsJgtTcujuDbO Tj/YySsCZIGSkUnBnXwqlHPq4d0PH/s= X-Google-Smtp-Source: AIpwx4/RIlkiOGUBNUVHSUFieK/OjD+/587duMNddpNF3eopwZ0K0dBG5JlPguzTU0jyC2q2Q6n41A== X-Received: by 10.28.138.69 with SMTP id m66mr1077855wmd.117.1523545724605; Thu, 12 Apr 2018 08:08:44 -0700 (PDT) Received: from veci.piliscsaba.redhat.com (catv-176-63-54-97.catv.broadband.hu. [176.63.54.97]) by smtp.gmail.com with ESMTPSA id p197sm2621783wme.43.2018.04.12.08.08.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 12 Apr 2018 08:08:44 -0700 (PDT) From: Miklos Szeredi To: linux-unionfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 11/35] ovl: readd read_iter Date: Thu, 12 Apr 2018 17:08:02 +0200 Message-Id: <20180412150826.20988-12-mszeredi@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180412150826.20988-1-mszeredi@redhat.com> References: <20180412150826.20988-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 | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index 409b542ff30c..a19429c5965d 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,63 @@ 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 = file_inode(file); + + if ((file->f_flags & O_NOATIME) || !ovl_inode_upper(inode)) + return; + + ovl_copytimes(inode); + 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_file(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, };