From patchwork Mon Nov 19 16:52:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Staubach X-Patchwork-Id: 1766271 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 128743FCDE for ; Mon, 19 Nov 2012 17:03:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753850Ab2KSRDG (ORCPT ); Mon, 19 Nov 2012 12:03:06 -0500 Received: from p02c12o148.mxlogic.net ([208.65.145.81]:36355 "EHLO p02c12o148.mxlogic.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753785Ab2KSRDF convert rfc822-to-8bit (ORCPT ); Mon, 19 Nov 2012 12:03:05 -0500 X-Greylist: delayed 539 seconds by postgrey-1.27 at vger.kernel.org; Mon, 19 Nov 2012 12:03:04 EST Received: from unknown [69.84.133.248] (EHLO p02c12o148.mxlogic.net) by p02c12o148.mxlogic.net(mxl_mta-6.16.0-0) with ESMTP id 8466aa05.2aaabce01940.5388.00-2460.14345.p02c12o148.mxlogic.net (envelope-from ); Mon, 19 Nov 2012 10:03:04 -0700 (MST) X-MXL-Hash: 50aa6648371aef78-e28063d138e52f8d1af1bd81aae94e328cff1723 Received: from unknown [69.84.133.248] (EHLO IT-1874.Isys.com) by p02c12o148.mxlogic.net(mxl_mta-6.16.0-0) over TLS secured channel with ESMTP id 1d36aa05.0.099.00-2389.185.p02c12o148.mxlogic.net (envelope-from ); Mon, 19 Nov 2012 09:52:35 -0700 (MST) X-MXL-Hash: 50aa63d359268f62-1056faadde037172c132a3a8b209f99d90eb5014 Received: from IT-1874.Isys.com ([172.20.0.223]) by IT-1874.Isys.com ([172.20.0.223]) with mapi; Mon, 19 Nov 2012 11:52:32 -0500 From: Peter Staubach To: Trond Myklebust , "linux-nfs@vger.kernel.org" Date: Mon, 19 Nov 2012 11:52:31 -0500 Subject: RE: [RFC PATCH 1/4] NFS: Add an ioctl to allow applications limited control over caching Thread-Topic: [RFC PATCH 1/4] NFS: Add an ioctl to allow applications limited control over caching Thread-Index: Ac3DooFHeE31C1vwSYuYXdXD27YP5wC05ipg Message-ID: References: <1353033088-47163-1-git-send-email-Trond.Myklebust@netapp.com> In-Reply-To: <1353033088-47163-1-git-send-email-Trond.Myklebust@netapp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US MIME-Version: 1.0 X-AnalysisOut: [v=2.0 cv=f6z/8pOM c=1 sm=1 a=YmXeKoonWU0GTmr6cORa5w==:17 a] X-AnalysisOut: [=pfu-2Dl3pykA:10 a=ooaBVg03rvgA:10 a=BLceEmwcHowA:10 a=kj9] X-AnalysisOut: [zAlcOel0A:10 a=ZC8462-RAAAA:8 a=_njUq414AAAA:8 a=QoFn_Jsrz] X-AnalysisOut: [KMA:10 a=VwQbUJbxAAAA:8 a=JDjsHSkAAAAA:8 a=5vJ58cLSQnaThw-] X-AnalysisOut: [2BdwA:9 a=CjuIK1q_8ugA:10 a=x8gzFH9gYPwA:10 a=Hf6muOzgCGQA] X-AnalysisOut: [:10 a=oysLmeMB_R9wkHso:21 a=5vGQyhWd_NkqRLsn:21] X-Spam: [F=0.2000000000; CM=0.500; S=0.200(2010122901)] X-MAIL-FROM: X-SOURCE-IP: [69.84.133.248] Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Hi. What application is having a problem which can be addressed via this support and what is the problem? Thanx... ps -----Original Message----- From: linux-nfs-owner@vger.kernel.org [mailto:linux-nfs-owner@vger.kernel.org] On Behalf Of Trond Myklebust Sent: Thursday, November 15, 2012 9:31 PM To: linux-nfs@vger.kernel.org Subject: [RFC PATCH 1/4] NFS: Add an ioctl to allow applications limited control over caching Add an ioctl that allows an application to force the NFS client to revalidate the attributes and/or data for a regular file, or directory. Signed-off-by: Trond Myklebust --- fs/nfs/Makefile | 2 +- fs/nfs/dir.c | 4 +++ fs/nfs/file.c | 4 +++ fs/nfs/internal.h | 3 ++ fs/nfs/ioctl.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nfs/ioctl.h | 35 ++++++++++++++++++++++ fs/nfs/nfs4file.c | 4 +++ 7 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 fs/nfs/ioctl.c create mode 100644 fs/nfs/ioctl.h -- 1.7.11.7 -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/nfs/Makefile b/fs/nfs/Makefile index b7db608..581db7a 100644 --- a/fs/nfs/Makefile +++ b/fs/nfs/Makefile @@ -7,7 +7,7 @@ obj-$(CONFIG_NFS_FS) += nfs.o nfs-y := client.o dir.o file.o getroot.o inode.o super.o \ direct.o pagelist.o read.o symlink.o unlink.o \ write.o namespace.o mount_clnt.o \ - dns_resolve.o cache_lib.o + dns_resolve.o cache_lib.o ioctl.o nfs-$(CONFIG_ROOT_NFS) += nfsroot.o nfs-$(CONFIG_SYSCTL) += sysctl.o nfs-$(CONFIG_NFS_FSCACHE) += fscache.o fscache-index.o diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index ce8cb92..10ad886 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -58,6 +58,10 @@ const struct file_operations nfs_dir_operations = { .open = nfs_opendir, .release = nfs_closedir, .fsync = nfs_fsync_dir, + .unlocked_ioctl = nfs_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = nfs_ioctl, +#endif }; const struct address_space_operations nfs_dir_aops = { diff --git a/fs/nfs/file.c b/fs/nfs/file.c index 582bb88..deefa62 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -925,5 +925,9 @@ const struct file_operations nfs_file_operations = { .splice_write = nfs_file_splice_write, .check_flags = nfs_check_flags, .setlease = nfs_setlease, + .unlocked_ioctl = nfs_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = nfs_ioctl, +#endif }; EXPORT_SYMBOL_GPL(nfs_file_operations); diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h index e1827b0..4b425bd 100644 --- a/fs/nfs/internal.h +++ b/fs/nfs/internal.h @@ -481,6 +481,9 @@ extern int nfs41_walk_client_list(struct nfs_client *clp, struct nfs_client **result, struct rpc_cred *cred); +/* ioctl.c */ +extern long nfs_ioctl(struct file *filp, unsigned int cmd, unsigned +long arg); + /* * Determine the device name as a string */ diff --git a/fs/nfs/ioctl.c b/fs/nfs/ioctl.c new file mode 100644 index 0000000..9da5f7d --- /dev/null +++ b/fs/nfs/ioctl.c @@ -0,0 +1,86 @@ +/* + * linux/fs/nfs/ioctl.c + * + * Copyright (C) 2012 Trond Myklebust + * + * nfs ioctl implementation + * + */ + +#include +#include +#include +#include "internal.h" +#include "ioctl.h" + +static long nfs_ioctl_cache_revalidate(struct file *filp, bool +metadata, bool data) { + struct inode *inode = filp->f_path.dentry->d_inode; + struct nfs_inode *nfsi = NFS_I(inode); + umode_t mode = inode->i_mode; + unsigned long invalid = 0; + long ret = -EINVAL; + + if (metadata) + invalid |= NFS_INO_INVALID_ATTR + | NFS_INO_INVALID_ACCESS + | NFS_INO_INVALID_ACL; + if (data) + invalid |= NFS_INO_INVALID_DATA; + + switch (mode & S_IFMT) { + default: + goto out; + case S_IFDIR: + spin_lock(&inode->i_lock); + if (data) + nfsi->cache_change_attribute++; + nfsi->cache_validity |= invalid; + spin_unlock(&inode->i_lock); + break; + case S_IFREG: + vfs_fsync(filp, 1); + if (data) + invalid |= NFS_INO_REVAL_PAGECACHE; + case S_IFLNK: + spin_lock(&inode->i_lock); + nfsi->cache_validity |= invalid; + spin_unlock(&inode->i_lock); + } + ret = nfs_revalidate_inode(NFS_SERVER(inode), inode); + if (ret == 0) + ret = nfs_revalidate_mapping(inode, filp->f_mapping); + +out: + return ret; +} + +static long nfs_ioctl_cachectl(struct file *filp, struct nfs_cachectl +__user *argp) { + u64 cmd; + + if (!(filp->f_mode & (FMODE_READ|FMODE_WRITE))) + return -EBADF; + if (get_user(cmd, &argp->cmd)) + return -EFAULT; + switch (cmd) { + case NFS_CACHECTL_REVALIDATE_ALL: + return nfs_ioctl_cache_revalidate(filp, true, true); + case NFS_CACHECTL_REVALIDATE_METADATA: + return nfs_ioctl_cache_revalidate(filp, true, false); + case NFS_CACHECTL_REVALIDATE_DATA: + return nfs_ioctl_cache_revalidate(filp, false, true); + } + return -EINVAL; +} + +long nfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) +{ + void __user *argp = (void __user *)arg; + + switch (cmd) { + case NFS_IOC_CACHECTL: + return nfs_ioctl_cachectl(filp, argp); + } + return -ENOTTY; +} diff --git a/fs/nfs/ioctl.h b/fs/nfs/ioctl.h new file mode 100644 index 0000000..cf79f0d --- /dev/null +++ b/fs/nfs/ioctl.h @@ -0,0 +1,35 @@ +/* + * linux/fs/nfs/ioctl.h + * + * Copyright (C) 2012 Trond Myklebust + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License v2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + * + * nfs ioctl definitions + * + */ + +#include + +/* Cache revalidation modes */ +#define NFS_CACHECTL_REVALIDATE_ALL 1 +#define NFS_CACHECTL_REVALIDATE_METADATA 2 +#define NFS_CACHECTL_REVALIDATE_DATA 3 + +struct nfs_cachectl { + u64 cmd; +}; + +#define NFS_IOC_CACHECTL _IOW('N', 1, struct nfs_cachectl) diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c index e769930..b221690 100644 --- a/fs/nfs/nfs4file.c +++ b/fs/nfs/nfs4file.c @@ -133,4 +133,8 @@ const struct file_operations nfs4_file_operations = { .splice_write = nfs_file_splice_write, .check_flags = nfs_check_flags, .setlease = nfs_setlease, + .unlocked_ioctl = nfs_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = nfs_ioctl, +#endif };