From patchwork Mon Aug 27 12:56:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10577073 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4F415139B for ; Mon, 27 Aug 2018 12:54:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D92C2943E for ; Mon, 27 Aug 2018 12:54:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3226129958; Mon, 27 Aug 2018 12:54:23 +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=-4.7 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, RCVD_IN_SBL_CSS 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 C9B792943E for ; Mon, 27 Aug 2018 12:54:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727329AbeH0Qky (ORCPT ); Mon, 27 Aug 2018 12:40:54 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:36362 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727078AbeH0Qky (ORCPT ); Mon, 27 Aug 2018 12:40:54 -0400 Received: by mail-wr1-f66.google.com with SMTP id m27-v6so13541831wrf.3; Mon, 27 Aug 2018 05:54:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1leOW5IS9WgN/qZzhdESiRoQq8v9eQaKcNoCScgbpRw=; b=b540I5h9bOIsh3e8ioKzmcuXdu8byFnpG646CSlvc2JxRlOn8+NZZ9nplqxfIG03Hv dC5e0vT+HPSzAFbwvSMek4VVPPgziyaWx4LzBvDgKh73fDeEKvgMP2T+x8Efnk6EI4is HDcqmCVeE+NBIhLES4LODz5r3wZyIy2NDlczCbYvAVuP1Uojme/YqOKdVo77kW+62wSg qrxbdDlvbOTyceaMrv4v56lDONTh/R6q5rCeE/Fiy2f8mJkxJDghEq0mlEsk7/BjP7I/ TJA3cA/TvrVSlGHkFC0HYNp/2/rrwGuaGt+UQoe3IjWaP0WR/YPP7eI2GtW1LB8RpwHS zVaw== 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=1leOW5IS9WgN/qZzhdESiRoQq8v9eQaKcNoCScgbpRw=; b=J+14tQ5znOu7JNrxRF54py8icbzyEEsKO4YQ7bDjiqsR0CoFVzuG4Tlr+G4RaPQVsj 7ap7UuGghHvjrFLBy7r58Un1vNYQJXWCh6X1qzn0+FKNW/EVhdNOaseL56PrYwZ3W+Z2 jiErk2/4crcxDzPEGpQE1OgRDCD2HuzI11RXwvjY9tDO0eOmfMfVBNSKJeo5cSwUrPXO SucRJianedKG0Ts7AycS/3nY1Axod2n+jC7YeMwn5vXKlx6pCu9woU+7TLLlNsU0o94b pCwQzIFnFzMO+H5W6wxUAqgXWwHRdEd5xftMBluoPjsBl5eBlzX4AncIP6NAASgpJp8Q oaUA== X-Gm-Message-State: APzg51AMFqo0nkRpT8WSZRWzxNMyqB6TNc/O+GRxmx3CttOuMzdujW6p JwVxQzRa81AW5z5JLGAokUM= X-Google-Smtp-Source: ANB0VdZ3qgXas7YZtcXr+k1uvnOuiiQ1DEltbkSkX8PsAaJjMGCVu+I7im9Jpg6SBf7UtI6AtfvFAg== X-Received: by 2002:a5d:428a:: with SMTP id k10-v6mr9234935wrq.225.1535374459907; Mon, 27 Aug 2018 05:54:19 -0700 (PDT) Received: from localhost.localdomain ([141.226.8.68]) by smtp.gmail.com with ESMTPSA id z14-v6sm8504046wma.18.2018.08.27.05.54.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 27 Aug 2018 05:54:19 -0700 (PDT) From: Amir Goldstein To: Miklos Szeredi Cc: Al Viro , Dave Chinner , linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v3 5/6] vfs: implement readahead(2) using POSIX_FADV_WILLNEED Date: Mon, 27 Aug 2018 15:56:03 +0300 Message-Id: <1535374564-8257-6-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1535374564-8257-1-git-send-email-amir73il@gmail.com> References: <1535374564-8257-1-git-send-email-amir73il@gmail.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 The implementation of readahead(2) syscall is identical to that of fadvise64(POSIX_FADV_WILLNEED) with a few exceptions: 1. readahead(2) returns -EINVAL for !mapping->a_ops and fadvise64() ignores the request and returns 0. 2. fadvise64() checks for integer overflow corner case 3. fadvise64() calls the optional filesystem fadvice() file operation Unite the two implementations by calling vfs_fadvice() from readahead(2) syscall. Check the !mapping->a_ops in readahead(2) syscall to preserve legacy behavior. Suggested-by: Miklos Szeredi Fixes: d1d04ef8572b ("ovl: stack file ops") Signed-off-by: Amir Goldstein --- mm/readahead.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index a59ea70527b9..867a5cc3a62e 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "internal.h" @@ -576,21 +577,19 @@ page_cache_async_readahead(struct address_space *mapping, EXPORT_SYMBOL_GPL(page_cache_async_readahead); static ssize_t -do_readahead(struct address_space *mapping, struct file *filp, - pgoff_t index, unsigned long nr) +do_readahead(struct file *file, loff_t offset, size_t count) { - if (!mapping || !mapping->a_ops) - return -EINVAL; + struct address_space *mapping = file->f_mapping; /* - * Readahead doesn't make sense for DAX inodes, but we don't want it - * to report a failure either. Instead, we just return success and - * don't do any work. + * fadvise() silently ignores an advice for a file with !a_ops and + * returns -EPIPE for a pipe. Keep this check here to comply with legacy + * -EINVAL behavior of readahead(2). */ - if (dax_mapping(mapping)) - return 0; + if (!mapping || !mapping->a_ops || !S_ISREG(file_inode(file)->i_mode)) + return -EINVAL; - return force_page_cache_readahead(mapping, filp, index, nr); + return vfs_fadvise(file, offset, count, POSIX_FADV_WILLNEED); } ssize_t ksys_readahead(int fd, loff_t offset, size_t count) @@ -601,13 +600,8 @@ ssize_t ksys_readahead(int fd, loff_t offset, size_t count) ret = -EBADF; f = fdget(fd); if (f.file) { - if (f.file->f_mode & FMODE_READ) { - struct address_space *mapping = f.file->f_mapping; - pgoff_t start = offset >> PAGE_SHIFT; - pgoff_t end = (offset + count - 1) >> PAGE_SHIFT; - unsigned long len = end - start + 1; - ret = do_readahead(mapping, f.file, start, len); - } + if (f.file->f_mode & FMODE_READ) + ret = do_readahead(f.file, offset, count); fdput(f); } return ret;