From patchwork Tue Feb 19 11:51:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boaz Harrosh X-Patchwork-Id: 10819753 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 C59B71399 for ; Tue, 19 Feb 2019 11:52:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B1AB42B5BF for ; Tue, 19 Feb 2019 11:52:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A64672B923; Tue, 19 Feb 2019 11:52:15 +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,DKIM_SIGNED, DKIM_VALID,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 145042B5BF for ; Tue, 19 Feb 2019 11:52:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728159AbfBSLwO (ORCPT ); Tue, 19 Feb 2019 06:52:14 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:54959 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728091AbfBSLwO (ORCPT ); Tue, 19 Feb 2019 06:52:14 -0500 Received: by mail-wm1-f68.google.com with SMTP id a62so2311714wmh.4 for ; Tue, 19 Feb 2019 03:52:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=plexistor-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SHHO+HEeGaxE67a91Z2NMaxKD4xU8ZvIf+7LE/QIBQY=; b=e2DSJRiSoqb310Bz1hEFSnaJiMAKQut7s4vE0iH38Hccvyo2dW6I17px7BpHEJDUAC X9ZHD80B1+7iOSEamRMvmApD987WsTgNrIwuDZx0HkupK3MIXWx7NcYyspEARVTJfm6V Z2OChYpYaLcbRYEcGQaN5L0ChxT2k4czE2ZXuQzzrzzOfe+TUL3F7UDFkV2hjWo4GRZ+ lcPRXeVYXaLxxKm2szY6a4U1+2aqnrYh/7MZkcd6m7MmVI+Uxe1ZNVBh00TImdRDKJWI 92sfZpjzjPDyx2ic9WVLT7Yhq2KSxJq8USzV+KucV5i5BhI+sMA0T8K7iNABNgY76PhV xM1Q== 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:mime-version:content-transfer-encoding; bh=SHHO+HEeGaxE67a91Z2NMaxKD4xU8ZvIf+7LE/QIBQY=; b=m8HfBuwP018K4nqvGFvmMMtqcluAd1P7Wc7yZc11mLLUyatejnR88GAwo177OQ1sM3 mOgNtzU9DVaM0FwArXTe0+34wdSBkiGCSOyKDZeCu+UqEzSeiSqeWXMxQOrA38LJRxbs 32fmfa4ffHb/m+0WjhIlgcSbsDUsjI7JVkkYlRnXwKm7uEU4QCXcHbntVCg1oZfNQnMR z7kSA6swUkr2MGIuwpQIgBl35BomRxJ+iBFi2pww1LxOfAIMeIw4UuxPwEuIbs5kgC+W mSa4RofPl1KJQtfsofTh4/SOoZREoxBrmhVjOr0R+u10F1f3phxmnuewPvOh3/ckk2Rz u/6A== X-Gm-Message-State: AHQUAub/BzZjyw2IfUulBM871jS3oJuWPfg2DU5KWIyFVGXAWtED9kv2 973bVMbOMtNgc4XFOHxAukUllWv1of0= X-Google-Smtp-Source: AHgI3IYQ6+dl0RKKiM+95456f9mnJ4e2pKqeSp9HYCv7DsbYc6u5u+ADAZtS9vtvVRw27iEsWW1Yow== X-Received: by 2002:adf:c543:: with SMTP id s3mr16493386wrf.192.1550577131459; Tue, 19 Feb 2019 03:52:11 -0800 (PST) Received: from Bfire.plexistor.com ([207.232.55.62]) by smtp.gmail.com with ESMTPSA id t18sm3605830wmt.8.2019.02.19.03.52.09 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 19 Feb 2019 03:52:11 -0800 (PST) From: Boaz harrosh To: linux-fsdevel , Anna Schumaker , Al Viro Cc: Ric Wheeler , Miklos Szeredi , Steven Whitehouse , Jefff moyer , Amir Goldstein , Amit Golander , Sagi Manole Subject: [RFC PATCH 16/17] zuf: Special IOCTL fadvise (TODO) Date: Tue, 19 Feb 2019 13:51:35 +0200 Message-Id: <20190219115136.29952-17-boaz@plexistor.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190219115136.29952-1-boaz@plexistor.com> References: <20190219115136.29952-1-boaz@plexistor.com> MIME-Version: 1.0 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 From: Boaz Harrosh We establish an fadvise dispatch with zus. We also define a new IOCTL to drive this into zuf. The IOCTL has the same structure and constants as the fadvise syscall. However: TODO: The VFS does not call into the FS for fadvise, And since we do not use a page-cache it is an no-op for zuf. We need to send a patch to vfs that lets an FS Hop in if it wants to implement its own fadvise. Signed-off-by: Boaz Harrosh --- fs/zuf/_extern.h | 2 ++ fs/zuf/ioctl.c | 25 ++++++++++++++++++++++ fs/zuf/rw.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++ fs/zuf/zuf-core.c | 1 + fs/zuf/zus_api.h | 14 ++++++++++++ 5 files changed, 96 insertions(+) diff --git a/fs/zuf/_extern.h b/fs/zuf/_extern.h index 2e515af0bb22..e345b737499d 100644 --- a/fs/zuf/_extern.h +++ b/fs/zuf/_extern.h @@ -66,6 +66,8 @@ ssize_t zuf_rw_read_iter(struct super_block *sb, struct inode *inode, ssize_t zuf_rw_write_iter(struct super_block *sb, struct inode *inode, struct kiocb *kiocb, struct iov_iter *ii); int zuf_trim_edge(struct inode *inode, ulong filepos, uint len); +int zuf_fadvise(struct super_block *sb, struct inode *inode, + loff_t offset, loff_t len, int advise, bool rand); int zuf_iom_execute_sync(struct super_block *sb, struct inode *inode, __u64 *iom_e, uint iom_n); int zuf_iom_execute_async(struct super_block *sb, struct zus_iomap_build *iomb, diff --git a/fs/zuf/ioctl.c b/fs/zuf/ioctl.c index 13ce65764c38..fb9727ab9d31 100644 --- a/fs/zuf/ioctl.c +++ b/fs/zuf/ioctl.c @@ -238,6 +238,29 @@ static int _ioc_setversion(struct inode *inode, uint __user *parg) return err; } +static int _ioc_fadvise(struct file *file, ulong arg) +{ + struct inode *inode = file_inode(file); + struct zuf_inode_info *zii = ZUII(inode); + struct zufs_ioc_fadvise iof = {}; + int err; + + if (!S_ISREG(inode->i_mode)) + return -EINVAL; + + if (arg && copy_from_user(&iof, (void __user *)arg, sizeof(iof))) + return -EFAULT; + + zuf_r_lock(zii); + + err = zuf_fadvise(inode->i_sb, inode, iof.offset, iof.length, + iof.advise, file->f_mode & FMODE_RANDOM); + + zuf_r_unlock(zii); + + return err; +} + long zuf_ioctl(struct file *filp, unsigned int cmd, ulong arg) { struct inode *inode = filp->f_inode; @@ -252,6 +275,8 @@ long zuf_ioctl(struct file *filp, unsigned int cmd, ulong arg) return put_user(inode->i_generation, (int __user *)arg); case FS_IOC_SETVERSION: return _ioc_setversion(inode, parg); + case ZUFS_IOC_FADVISE: + return _ioc_fadvise(filp, arg); default: return _ioctl_dispatch(inode, cmd, arg); } diff --git a/fs/zuf/rw.c b/fs/zuf/rw.c index 400d24ea7914..0cdb3c257ff8 100644 --- a/fs/zuf/rw.c +++ b/fs/zuf/rw.c @@ -315,6 +315,60 @@ ssize_t zuf_rw_write_iter(struct super_block *sb, struct inode *inode, return ret; } +static int _fadv_willneed(struct super_block *sb, struct inode *inode, + loff_t offset, loff_t len, bool rand) +{ + struct zufs_ioc_IO io = {}; + struct __zufs_ra ra = { + .start = md_o2p(offset), + .ra_pages = md_o2p_up(len), + .prev_pos = offset - 1, + }; + int err; + + io.ra.start = ra.start; + io.ra.ra_pages = ra.ra_pages; + io.ra.prev_pos = ra.prev_pos; + io.flags = rand ? ZUFS_IO_RAND : 0; + + err = _IO_dispatch(SBI(sb), &io, ZUII(inode), ZUFS_OP_PRE_READ, 0, + NULL, 0, offset, 0); + return err; +} + +static int _fadv_dontneed(struct super_block *sb, struct inode *inode, + loff_t offset, loff_t len) +{ + struct zufs_ioc_range ioc_range = { + .hdr.in_len = sizeof(ioc_range), + .hdr.operation = ZUFS_OP_SYNC, + .zus_ii = ZUII(inode)->zus_ii, + .offset = offset, + .length = len, + .ioc_flags = ZUFS_RF_DONTNEED, + }; + + return zufc_dispatch(ZUF_ROOT(SBI(sb)), &ioc_range.hdr, NULL, 0); +} + +int zuf_fadvise(struct super_block *sb, struct inode *inode, + loff_t offset, loff_t len, int advise, bool rand) +{ + switch (advise) { + case POSIX_FADV_WILLNEED: + return _fadv_willneed(sb, inode, offset, len, rand); + case POSIX_FADV_DONTNEED: + return _fadv_dontneed(sb, inode, offset, len); + case POSIX_FADV_NOREUSE: /* TODO */ + case POSIX_FADV_SEQUENTIAL: /* TODO: turn off random */ + case POSIX_FADV_NORMAL: + return 0; + default: + return -EINVAL; + } + return -EINVAL; +} + /* ~~~~ iom_dec.c ~~~ */ /* for now here (at rw.c) looks logical */ diff --git a/fs/zuf/zuf-core.c b/fs/zuf/zuf-core.c index c6b614465ab3..2afccfcf90bb 100644 --- a/fs/zuf/zuf-core.c +++ b/fs/zuf/zuf-core.c @@ -778,6 +778,7 @@ const char *zuf_op_name(enum e_zufs_operation op) CASE_ENUM_NAME(ZUFS_OP_CLONE ); CASE_ENUM_NAME(ZUFS_OP_COPY ); CASE_ENUM_NAME(ZUFS_OP_READ ); + CASE_ENUM_NAME(ZUFS_OP_PRE_READ ); CASE_ENUM_NAME(ZUFS_OP_WRITE ); CASE_ENUM_NAME(ZUFS_OP_GET_BLOCK ); CASE_ENUM_NAME(ZUFS_OP_PUT_BLOCK ); diff --git a/fs/zuf/zus_api.h b/fs/zuf/zus_api.h index 40f369d20306..95fb5c35cde5 100644 --- a/fs/zuf/zus_api.h +++ b/fs/zuf/zus_api.h @@ -159,6 +159,19 @@ struct zus_inode { /* Total ZUFS_INODE_SIZE bytes always */ }; +/* ~~~~~ vfs extension ioctl commands ~~~~~ */ + +/* TODO: This one needs to be an FS vector called from + * the fadvise() system call. (Future patch) + */ +struct zufs_ioc_fadvise { + __u64 offset; + __u64 length; /* if 0 all file */ + __u64 advise; +} __packed; + +#define ZUFS_IOC_FADVISE _IOW('S', 2, struct zufs_ioc_fadvise) + /* ~~~~~ ZUFS API ioctl commands ~~~~~ */ enum { ZUS_API_MAP_MAX_PAGES = 1024, @@ -341,6 +354,7 @@ enum e_zufs_operation { ZUFS_OP_COPY, ZUFS_OP_READ, + ZUFS_OP_PRE_READ, ZUFS_OP_WRITE, ZUFS_OP_GET_BLOCK, ZUFS_OP_PUT_BLOCK,