Date: Thu, 09 Oct 2008 17:11:14 +1100
From: Donald Douwsma <donaldd@sgi.com>
Subject: VFS changes to support DMAPI
Patch-mainline: not yet
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
@@ -6228,6 +6228,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
@@ -57,6 +57,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/autofs/Kconfig"
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -53,6 +53,8 @@ obj-$(CONFIG_GENERIC_ACL)	+= generic_acl
 
 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
@@ -680,6 +680,12 @@ struct file *open_exec(const char *name)
 
 	fsnotify_open(file->f_path.dentry);
 
+	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
@@ -1508,6 +1508,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 **);
 };
 
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -187,6 +187,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
@@ -294,6 +294,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;
