Skip to contentSkip to conversation

fsstack: generic stackable filesystem helper functions

PATCH In review JosefJeff Sipek 3 participants 8 messages Oct 17, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fsstack: generic stackable filesystem helper functions

From: Josef "Jeff" Sipek <[email protected]>

The following patches introduce fsstack_copy_* functions. These functions copy inode attributes (such as {a,c,m}time, mode, etc.) from one inode to another.

While, intended for stackable filesystems any portion of the kernel wishing to copy inode attributes can use them.

This series consists of two patches, the first introduces the fsstack functions, and the second makes eCryptfs a user.

Changes since previous submission:

- rename to fsstack (akpm)
- removed fstack_copy_attr_timesizes (akpm)
- move non-inlined functions to fs/stack.c (Jan Engelhardt)

#1 lore raw

PATCH 1/1 fsstack: Introduce fsstack_copy_{attr,inode}_*

From: Josef "Jeff" Sipek <[email protected]>

The following patch introduces several fsstack_copy_* functions which allow stackable filesystems (such as eCryptfs and Unionfs) to easily copy over (currently only) inode attributes. This prevents code duplication and allows for code reuse.

---

3 files changed, 80 insertions(+), 1 deletion(-)
fs/Makefile              |    3 ++-
fs/stack.c               |   39 +++++++++++++++++++++++++++++++++++++++
include/linux/fs_stack.h |   39 +++++++++++++++++++++++++++++++++++++++
fs/Makefile +2 -1
@@ -10,7 +10,8 @@ obj-y :=	open.o read_write.o file_table.
 		ioctl.o readdir.o select.o fifo.o locks.o dcache.o inode.o \
 		attr.o bad_inode.o file.o filesystems.o namespace.o aio.o \
 		seq_file.o xattr.o libfs.o fs-writeback.o \
-		pnode.o drop_caches.o splice.o sync.o utimes.o
+		pnode.o drop_caches.o splice.o sync.o utimes.o \
+		stack.o
 
 ifeq ($(CONFIG_BLOCK),y)
 obj-y +=	buffer.o bio.o block_dev.o direct-io.o mpage.o ioprio.o
fs/stack.c new file +39 -0
new file mode 100644
@@ -0,0 +1,39 @@
+#include <linux/module.h>
+#include <linux/fs.h>
+
+/* does _NOT_ require i_mutex to be held.
+ *
+ * This function cannot be inlined since i_size_{read,write} is rather
+ * heavy-weight on 32-bit systems
+ */
+void fsstack_copy_inode_size(struct inode *dst, const struct inode *src)
+{
+	i_size_write(dst, i_size_read((struct inode *)src));
+	dst->i_blocks = src->i_blocks;
+}
+
+/* copy all attributes; get_nlinks is optional way to override the i_nlink
+ * copying
+ */
+void __fsstack_copy_attr_all(struct inode *dest,
+			     const struct inode *src,
+			     int (*get_nlinks)(struct inode *))
+{
+	if (!get_nlinks)
+		dest->i_nlink = src->i_nlink;
+	else
+		dest->i_nlink = (*get_nlinks)(dest);
+
+	dest->i_mode = src->i_mode;
+	dest->i_uid = src->i_uid;
+	dest->i_gid = src->i_gid;
+	dest->i_rdev = src->i_rdev;
+	dest->i_atime = src->i_atime;
+	dest->i_mtime = src->i_mtime;
+	dest->i_ctime = src->i_ctime;
+	dest->i_blkbits = src->i_blkbits;
+	dest->i_flags = src->i_flags;
+}
+
+EXPORT_SYMBOL_GPL(fsstack_copy_inode_size);
+EXPORT_SYMBOL_GPL(__fsstack_copy_attr_all);
include/linux/fs_stack.h new file +39 -0
new file mode 100644
@@ -0,0 +1,39 @@
+#ifndef _LINUX_FS_STACK_H
+#define _LINUX_FS_STACK_H
+
+/* This file defines generic functions used primarily by stackable
+ * filesystems; none of these functions require i_mutex to be held.
+ */
+
+#include <linux/fs.h>
+
+/* externs for fs/stack.c */
+extern void __fsstack_copy_attr_all(struct inode *dest,
+				    const struct inode *src,
+				    int (*get_nlinks)(struct inode *));
+
+extern void fsstack_copy_inode_size(struct inode *dst, const struct inode *src);
+
+/* inlines */
+static inline void fsstack_copy_attr_atime(struct inode *dest,
+					   const struct inode *src)
+{
+	dest->i_atime = src->i_atime;
+}
+
+static inline void fsstack_copy_attr_times(struct inode *dest,
+					   const struct inode *src)
+{
+	dest->i_atime = src->i_atime;
+	dest->i_mtime = src->i_mtime;
+	dest->i_ctime = src->i_ctime;
+}
+
+static inline void fsstack_copy_attr_all(struct inode *dest,
+					 const struct inode *src)
+{
+	__fsstack_copy_attr_all(dest, src, NULL);
+}
+
+#endif /* _LINUX_FS_STACK_H */
+
#4 lore raw

PATCH 1/1 eCryptfs: Use fsstack's generic copy inode attr functions

In reply to JosefJeff Sipek

From: Josef "Jeff" Sipek <[email protected]>

Replace eCryptfs specific code & calls with the more generic fsstack equivalents and remove the eCryptfs specific functions.

---

3 files changed, 24 insertions(+), 59 deletions(-)
fs/ecryptfs/file.c  |    3 +-
fs/ecryptfs/inode.c |   75 ++++++++++++---------------------------------------
fs/ecryptfs/main.c  |    5 ++-
fs/ecryptfs/file.c +2 -1
@@ -30,6 +30,7 @@
 #include <linux/security.h>
 #include <linux/smp_lock.h>
 #include <linux/compat.h>
+#include <linux/fs_stack.h>
 #include "ecryptfs_kernel.h"
 
 /**
@@ -192,7 +193,7 @@ retry:
 		goto retry;
 	file->f_pos = lower_file->f_pos;
 	if (rc >= 0)
-		ecryptfs_copy_attr_atime(inode, lower_file->f_dentry->d_inode);
+		fsstack_copy_attr_atime(inode, lower_file->f_dentry->d_inode);
 	return rc;
 }
 
fs/ecryptfs/inode.c +19 -56

154 lines not on this page · raw message

fs/ecryptfs/main.c +3 -2
@@ -35,6 +35,7 @@
 #include <linux/pagemap.h>
 #include <linux/key.h>
 #include <linux/parser.h>
+#include <linux/fs_stack.h>
 #include "ecryptfs_kernel.h"
 
 /**
@@ -115,10 +116,10 @@ int ecryptfs_interpose(struct dentry *lo
 		d_add(dentry, inode);
 	else
 		d_instantiate(dentry, inode);
-	ecryptfs_copy_attr_all(inode, lower_inode);
+	fsstack_copy_attr_all(inode, lower_inode);
 	/* This size will be overwritten for real files w/ headers and
 	 * other metadata */
-	ecryptfs_copy_inode_size(inode, lower_inode);
+	fsstack_copy_inode_size(inode, lower_inode);
 out:
 	return rc;
 }
#5 lore raw

PATCH 1/1 fsstack: Introduce fsstack_copy_{attr,inode}_*

In reply to JosefJeff Sipek

From: Josef "Jeff" Sipek <[email protected]>

The following patch introduces several fsstack_copy_* functions which allow stackable filesystems (such as eCryptfs and Unionfs) to easily copy over (currently only) inode attributes. This prevents code duplication and allows for code reuse.

---

3 files changed, 80 insertions(+), 1 deletion(-)
fs/Makefile              |    3 ++-
fs/stack.c               |   39 +++++++++++++++++++++++++++++++++++++++
include/linux/fs_stack.h |   39 +++++++++++++++++++++++++++++++++++++++
fs/Makefile +2 -1
@@ -10,7 +10,8 @@ obj-y :=	open.o read_write.o file_table.
 		ioctl.o readdir.o select.o fifo.o locks.o dcache.o inode.o \
 		attr.o bad_inode.o file.o filesystems.o namespace.o aio.o \
 		seq_file.o xattr.o libfs.o fs-writeback.o \
-		pnode.o drop_caches.o splice.o sync.o utimes.o
+		pnode.o drop_caches.o splice.o sync.o utimes.o \
+		stack.o
 
 ifeq ($(CONFIG_BLOCK),y)
 obj-y +=	buffer.o bio.o block_dev.o direct-io.o mpage.o ioprio.o
fs/stack.c new file +39 -0
new file mode 100644
@@ -0,0 +1,39 @@
+#include <linux/module.h>
+#include <linux/fs.h>
+
+/* does _NOT_ require i_mutex to be held.
+ *
+ * This function cannot be inlined since i_size_{read,write} is rather
+ * heavy-weight on 32-bit systems
+ */
+void fsstack_copy_inode_size(struct inode *dst, const struct inode *src)
+{
+	i_size_write(dst, i_size_read((struct inode *)src));
+	dst->i_blocks = src->i_blocks;
+}
+
+/* copy all attributes; get_nlinks is optional way to override the i_nlink
+ * copying
+ */
+void __fsstack_copy_attr_all(struct inode *dest,
+			     const struct inode *src,
+			     int (*get_nlinks)(struct inode *))
+{
+	if (!get_nlinks)
+		dest->i_nlink = src->i_nlink;
+	else
+		dest->i_nlink = (*get_nlinks)(dest);
+
+	dest->i_mode = src->i_mode;
+	dest->i_uid = src->i_uid;
+	dest->i_gid = src->i_gid;
+	dest->i_rdev = src->i_rdev;
+	dest->i_atime = src->i_atime;
+	dest->i_mtime = src->i_mtime;
+	dest->i_ctime = src->i_ctime;
+	dest->i_blkbits = src->i_blkbits;
+	dest->i_flags = src->i_flags;
+}
+
+EXPORT_SYMBOL_GPL(fsstack_copy_inode_size);
+EXPORT_SYMBOL_GPL(__fsstack_copy_attr_all);
include/linux/fs_stack.h new file +39 -0
new file mode 100644
@@ -0,0 +1,39 @@
+#ifndef _LINUX_FS_STACK_H
+#define _LINUX_FS_STACK_H
+
+/* This file defines generic functions used primarily by stackable
+ * filesystems; none of these functions require i_mutex to be held.
+ */
+
+#include <linux/fs.h>
+
+/* externs for fs/stack.c */
+extern void __fsstack_copy_attr_all(struct inode *dest,
+				    const struct inode *src,
+				    int (*get_nlinks)(struct inode *));
+
+extern void fsstack_copy_inode_size(struct inode *dst, const struct inode *src);
+
+/* inlines */
+static inline void fsstack_copy_attr_atime(struct inode *dest,
+					   const struct inode *src)
+{
+	dest->i_atime = src->i_atime;
+}
+
+static inline void fsstack_copy_attr_times(struct inode *dest,
+					   const struct inode *src)
+{
+	dest->i_atime = src->i_atime;
+	dest->i_mtime = src->i_mtime;
+	dest->i_ctime = src->i_ctime;
+}
+
+static inline void fsstack_copy_attr_all(struct inode *dest,
+					 const struct inode *src)
+{
+	__fsstack_copy_attr_all(dest, src, NULL);
+}
+
+#endif /* _LINUX_FS_STACK_H */
+
#6 lore raw

PATCH 1/1 eCryptfs: Use fsstack's generic copy inode attr functions

In reply to JosefJeff Sipek

From: Josef "Jeff" Sipek <[email protected]>

Replace eCryptfs specific code & calls with the more generic fsstack equivalents and remove the eCryptfs specific functions.

---

3 files changed, 24 insertions(+), 59 deletions(-)
fs/ecryptfs/file.c  |    3 +-
fs/ecryptfs/inode.c |   75 ++++++++++++---------------------------------------
fs/ecryptfs/main.c  |    5 ++-
fs/ecryptfs/file.c +2 -1
@@ -30,6 +30,7 @@
 #include <linux/security.h>
 #include <linux/smp_lock.h>
 #include <linux/compat.h>
+#include <linux/fs_stack.h>
 #include "ecryptfs_kernel.h"
 
 /**
@@ -192,7 +193,7 @@ retry:
 		goto retry;
 	file->f_pos = lower_file->f_pos;
 	if (rc >= 0)
-		ecryptfs_copy_attr_atime(inode, lower_file->f_dentry->d_inode);
+		fsstack_copy_attr_atime(inode, lower_file->f_dentry->d_inode);
 	return rc;
 }
 
fs/ecryptfs/inode.c +19 -56

154 lines not on this page · raw message

fs/ecryptfs/main.c +3 -2
@@ -35,6 +35,7 @@
 #include <linux/pagemap.h>
 #include <linux/key.h>
 #include <linux/parser.h>
+#include <linux/fs_stack.h>
 #include "ecryptfs_kernel.h"
 
 /**
@@ -115,10 +116,10 @@ int ecryptfs_interpose(struct dentry *lo
 		d_add(dentry, inode);
 	else
 		d_instantiate(dentry, inode);
-	ecryptfs_copy_attr_all(inode, lower_inode);
+	fsstack_copy_attr_all(inode, lower_inode);
 	/* This size will be overwritten for real files w/ headers and
 	 * other metadata */
-	ecryptfs_copy_inode_size(inode, lower_inode);
+	fsstack_copy_inode_size(inode, lower_inode);
 out:
 	return rc;
 }
#7 lore raw

Re: [PATCH 0 of 2] fsstack: generic... - ignore this copy

In reply to JosefJeff Sipek
Quoted 1 line · Josef Jeff Sipek

From: Josef "Jeff" Sipek <[email protected]>

This was sent accidentally (without all the Cc's for example)...please ignore..

Josef "Jeff" Sipek.

Signature · 1 line
Penguin : Linux version 2.4.20-46.9.legacysmp on an i686 machine (5564.00 BogoMips).
#2 lore raw

Re: [PATCH 1 of 2] fsstack: Introduce fsstack_copy_{attr,inode}_*

In reply to JosefJeff Sipek
Quoted 2 lines

To: [email protected]

(Superb idea to prekill any Cc, re-adding them)

Quoted 7 lines
fs/stack.c new file +4 -0
+void __fsstack_copy_attr_all(struct inode *dest,
+			     const struct inode *src,
+			     int (*get_nlinks)(struct inode *))
+{

[big]

include/linux/fs_stack.h new file +2 -0
+}
+

include/linux/fs_stack.h line 36

Quoted 10 lines
include/linux/fs_stack.h new file +10 -0
+/* externs for fs/stack.c */
+extern void __fsstack_copy_attr_all(struct inode *dest,
+				    const struct inode *src,
+				    int (*get_nlinks)(struct inode *));
+
+static inline void fsstack_copy_attr_all(struct inode *dest,
+					 const struct inode *src)
+{
+	__fsstack_copy_attr_all(dest, src, NULL);
+}

Do we really need this indirection? Can't __fsstack_copy_attr_all be named fsstack_copy_attr_all instead?

	-`J'
#3 lore raw

Re: [PATCH 1 of 2] fsstack: Introduce fsstack_copy_{attr,inode}_*

Quoted 4 lines · Jan Engelhardt
Quoted 2 lines

To: [email protected]

(Superb idea to prekill any Cc, re-adding them)

Yeah, I like to test the emails but I accidentally sent them. From now on, no testing :)

Quoted 12 lines
Quoted 12 lines
fs/stack.c new file +4 -0
+void __fsstack_copy_attr_all(struct inode *dest,
+			     const struct inode *src,
+			     int (*get_nlinks)(struct inode *))
+{

[big]

include/linux/fs_stack.h new file +7 -0
+}
+
+/* externs for fs/stack.c */
+extern void __fsstack_copy_attr_all(struct inode *dest,
+				    const struct inode *src,
+				    int (*get_nlinks)(struct inode *));
+
Quoted 8 lines

include/linux/fs_stack.h line 36

Quoted 5 lines
include/linux/fs_stack.h new file +5 -0
+static inline void fsstack_copy_attr_all(struct inode *dest,
+					 const struct inode *src)
+{
+	__fsstack_copy_attr_all(dest, src, NULL);
+}

Do we really need this indirection? Can't __fsstack_copy_attr_all be named fsstack_copy_attr_all instead?

I suppose it could. There is no API-breakage to avoid.

Josef "Jeff" Sipek.

Signature · 3 lines
Computer Science is no more about computers than astronomy is about
telescopes.
		- Edsger Dijkstra