Date: Thu, 09 Oct 2008 17:11:14 +1100
From: Donald Douwsma <donaldd@sgi.com>
Subject: VFS changes to support DMAPI
Patch-mainline: Never
References: bnc#450658

VFS changes to support DMAPI including open_exec(), mprotect() 
and build infastructure.

Acked-by: Jan Kara <jack@suse.cz>

---
 MAINTAINERS        |    7 +++++++
 fs/Kconfig         |   19 +++++++++++++++++++
 fs/Makefile        |    2 ++
 fs/exec.c          |    6 ++++++
 include/linux/fs.h |    2 ++
 include/linux/mm.h |    3 +++
 mm/mprotect.c      |    5 +++++
 7 files changed, 44 insertions(+)

--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7077,6 +7077,13 @@ S:	Supported
 F:	Documentation/filesystems/xfs.txt
 F:	fs/xfs/
 
+DMAPI
+P:	Silicon Graphics Inc
+M:	xfs-masters@oss.sgi.com
+L:	xfs@oss.sgi.com
+W:	http://oss.sgi.com/projects/xfs
+S:	Supported
+
 XILINX SYSTEMACE DRIVER
 M:	Grant Likely <grant.likely@secretlab.ca>
 W:	http://www.secretlab.ca/
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -59,6 +59,25 @@ config FILE_LOCKING
 
 source "fs/notify/Kconfig"
 
+config DMAPI
+	tristate "DMAPI support"
+	help
+	  The Data Management API is a system interface used to implement
+	  the interface defined in the X/Open document:
+	  "Systems Management: Data Storage Management (XDSM) API",
+	  dated February 1997.  This interface is used by hierarchical
+	  storage management systems.
+
+	  If any DMAPI-capable filesystem is built into the kernel, then
+	  DMAPI must also be built into the kernel.
+
+config DMAPI_DEBUG
+	bool "DMAPI debugging support"
+	depends on DMAPI
+	help
+	  If you don't know whether you need it, then you don't need it:
+	  answer N.
+
 source "fs/quota/Kconfig"
 
 source "fs/autofs4/Kconfig"
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -52,6 +52,8 @@ obj-$(CONFIG_FHANDLE)		+= fhandle.o
 
 obj-y				+= quota/
 
+obj-$(CONFIG_DMAPI)		+= dmapi/
+
 obj-$(CONFIG_PROC_FS)		+= proc/
 obj-y				+= partitions/
 obj-$(CONFIG_SYSFS)		+= sysfs/
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -789,6 +789,12 @@ struct file *open_exec(const char *name)
 
 	fsnotify_open(file);
 
+	if (file->f_op && file->f_op->open_exec) {
+		err = file->f_op->open_exec(file->f_path.dentry->d_inode);
+		if (err)
+			goto exit;
+	}
+
 	err = deny_write_access(file);
 	if (err)
 		goto exit;
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1568,6 +1568,8 @@ struct file_operations {
 	int (*flock) (struct file *, int, struct file_lock *);
 	ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
 	ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
+#define HAVE_FOP_OPEN_EXEC
+	int (*open_exec) (struct inode *);
 	int (*setlease)(struct file *, long, struct file_lock **);
 	long (*fallocate)(struct file *file, int mode, loff_t offset,
 			  loff_t len);
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -204,6 +204,9 @@ struct vm_operations_struct {
 	void (*close)(struct vm_area_struct * area);
 	int (*fault)(struct vm_area_struct *vma, struct vm_fault *vmf);
 
+#define HAVE_VMOP_MPROTECT
+	int (*mprotect)(struct vm_area_struct * area, unsigned int newflags);
+
 	/* notification that a previously read-only page is about to become
 	 * writable, if an error is returned it will cause a SIGBUS */
 	int (*page_mkwrite)(struct vm_area_struct *vma, struct vm_fault *vmf);
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -304,6 +304,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long,
 		if (error)
 			goto out;
 
+		if (vma->vm_ops && vma->vm_ops->mprotect) {
+			error = vma->vm_ops->mprotect(vma, newflags);
+			if (error < 0)
+				goto out;
+		}
 		tmp = vma->vm_end;
 		if (tmp > end)
 			tmp = end;
