Skip to contentSkip to conversation

Stackfs: generic stackable filesystem helper functions

PATCH In review JosefJeff Sipek 6 participants 11 messages Oct 13, 2006 – Oct 15, 2006

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

PATCH 1/1 Stackfs: Introduce stackfs_copy_{attr,inode}_*

In reply to JosefJeff Sipek

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

The following patch introduces several stackfs_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.

---

1 file changed, 65 insertions(+)

include/linux/stack_fs.h | 65 ++++++++++++++++++++++++++++++++++++++++++++++

include/linux/stack_fs.h new file +65 -0
new file mode 100644
@@ -0,0 +1,65 @@
+#ifndef _LINUX_STACK_FS_H
+#define _LINUX_STACK_FS_H
+
+/* This file defines generic functions used primarily by stackable
+ * filesystems
+ */
+
+static inline void stackfs_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;
+}
+
+static inline void stackfs_copy_attr_atime(struct inode *dest,
+					   const struct inode *src)
+{
+	dest->i_atime = src->i_atime;
+}
+
+static inline void stackfs_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 stackfs_copy_attr_timesizes(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;
+	stackfs_copy_inode_size(dest, src);
+}
+
+static inline void __stackfs_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;
+}
+
+static inline void stackfs_copy_attr_all(struct inode *dest,
+					 const struct inode *src)
+{
+	__stackfs_copy_attr_all(dest, src, NULL);
+}
+
+#endif /* _LINUX_STACK_FS_H */
+
#0 lore raw

PATCH 1/1 Stackfs: generic stackable filesystem helper functions

The following patches introduce stackfs_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 stackfs functions, and the second makes eCryptfs a user.

4 files changed, 85 insertions(+), 59 deletions(-)
fs/ecryptfs/file.c       |    3 +
fs/ecryptfs/inode.c      |   71 +++++++++-------------------------------------
fs/ecryptfs/main.c       |    5 +--
include/linux/stack_fs.h |   65 ++++++++++++++++++++++++++++++++++++++++++
#9 lore raw

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

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

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

---

3 files changed, 20 insertions(+), 59 deletions(-)
fs/ecryptfs/file.c  |    3 +-
fs/ecryptfs/inode.c |   71 ++++++++++-----------------------------------------
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/stack_fs.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);
+		stackfs_copy_attr_atime(inode, lower_file->f_dentry->d_inode);
 	return rc;
 }
 
fs/ecryptfs/inode.c +15 -56

150 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/stack_fs.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);
+	stackfs_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);
+	stackfs_copy_inode_size(inode, lower_inode);
 out:
 	return rc;
 }
#10 lore raw
In reply to JosefJeff Sipek

Hi Jeff,

Quoted 3 lines · Josef Jeff Sipek

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

Looks ok to me. Thanks!

#2 lore raw

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

In reply to JosefJeff Sipek

include/linux/stack_fs.h line 11

Quoted 4 lines · Josef Jeff Sipek
include/linux/stack_fs.h new file +4 -0
+static inline void stackfs_copy_inode_size(struct inode *dst,
+					   const struct inode *src)
+{
+	i_size_write(dst, i_size_read((struct inode *)src));

Instead of casting, I'd change the signature of i_size_read.

#4 lore raw

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

In reply to JosefJeff Sipek
Quoted 6 lines · On Fri, 13 Oct 2006 07:18:49 -0400 Josef "Jeff" Sipek <[email protected]>…

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

The following patch introduces several stackfs_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.

Fair enough.

Quoted 1 line

include/linux/stack_fs.h | 65 ++++++++++++++++++++++++++++++++++++++++++++++

The name stack_fs implies that there's a filesystem called stackfs. Only there isn't. I wonder if we can choose a better name for all of this. Maybe fs_stack_*?

Quoted 9 lines
include/linux/stack_fs.h new file +3 -0
new file mode 100644
@@ -0,0 +1,65 @@
+#ifndef _LINUX_STACK_FS_H
+#define _LINUX_STACK_FS_H
+

include/linux/stack_fs.h line 13

Quoted 10 lines
include/linux/stack_fs.h new file +10 -0
+/* This file defines generic functions used primarily by stackable
+ * filesystems
+ */
+
+static inline void stackfs_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;
+}

What are the locking requirements for these functions? Presumably the caller must hold i_mutex on at least the source inode, and perhaps the destination one?

If i_mutex is held, i_size_read() isn't needed.

If i_mutex is held, i_size_write() isn't needed either.

So please document the locking requirements via source comments and then see if this can be simplified.

If this function stays as it is, it's too big to inline.

Quoted 21 lines
include/linux/stack_fs.h new file +21 -0
+static inline void stackfs_copy_attr_atime(struct inode *dest,
+					   const struct inode *src)
+{
+	dest->i_atime = src->i_atime;
+}
+
+static inline void stackfs_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 stackfs_copy_attr_timesizes(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;
+	stackfs_copy_inode_size(dest, src);

include/linux/stack_fs.h line 45

Quoted 10 lines
include/linux/stack_fs.h new file +10 -0
+}
+
+static inline void __stackfs_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);

I cannot find a get_nlinks() in 2.6.19-rc2?

Quoted 6 lines
include/linux/stack_fs.h new file +6 -0
+	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;

include/linux/stack_fs.h line 62

Quoted 10 lines
include/linux/stack_fs.h new file +9 -0
+	dest->i_ctime = src->i_ctime;
+	dest->i_blkbits = src->i_blkbits;
+	dest->i_flags = src->i_flags;
+}
 
+static inline void stackfs_copy_attr_all(struct inode *dest,
+					 const struct inode *src)
+{
+	__stackfs_copy_attr_all(dest, src, NULL);
+}

Many of these functions are too large to be inlined. Suggest they be placed in fs/fs-stack.c (or whatever we call it).

The functions themselves seem a bit arbitrary. stackfs_copy_attr_timesizes() copy the three timestamps and the size. Is there actually any methodical reason for that, or is it simply some sequence which happens to have been observed in ecryptfs?

And please - if I asked these questions when reviewing the patch, others will ask them when reading the code two years from now. So please treat my questions as "gosh, I should have put a comment in there".

#5 lore raw

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

Quoted 7 lines · Andrew Morton
Quoted 1 line · On Fri, 13 Oct 2006 07:18:49 -0400 Josef "Jeff" Sipek <[email protected]>…

include/linux/stack_fs.h | 65 ++++++++++++++++++++++++++++++++++++++++++++++

The name stack_fs implies that there's a filesystem called stackfs. Only there isn't. I wonder if we can choose a better name for all of this. Maybe fs_stack_*?

fs_stack_* sounds good to me.

Quoted 10 lines

What are the locking requirements for these functions? Presumably the caller must hold i_mutex on at least the source inode, and perhaps the destination one?

If i_mutex is held, i_size_read() isn't needed.

If i_mutex is held, i_size_write() isn't needed either.

So please document the locking requirements via source comments and then see if this can be simplified.

Fair enough. I'll submit an updated version.

Quoted 10 lines

include/linux/stack_fs.h line 45

Quoted 8 lines
include/linux/stack_fs.h new file +8 -0
+static inline void __stackfs_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);

I cannot find a get_nlinks() in 2.6.19-rc2?

It is the last argument to the function. Perhaps the function name is deceiving.

Quoted 2 lines

Many of these functions are too large to be inlined. Suggest they be placed in fs/fs-stack.c (or whatever we call it).

Ack. As a rule of thumb, for functions like these (laundry list of assignments), what's a good threshold?

Quoted 4 lines

The functions themselves seem a bit arbitrary. stackfs_copy_attr_timesizes() copy the three timestamps and the size. Is there actually any methodical reason for that, or is it simply some sequence which happens to have been observed in ecryptfs?

These functions come from the FiST templates [1]. Some of these can definitely removed, or split up.

Quoted 3 lines

And please - if I asked these questions when reviewing the patch, others will ask them when reading the code two years from now. So please treat my questions as "gosh, I should have put a comment in there".

That's exactly how I look at it.

Josef "Jeff" Sipek.

Signature · 2 lines
Bad pun of the week: The formula 1 control computer suffered from a race
condition
#6 lore raw

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

On Fri, Oct 13, 2006 at 04:07:05PM -0400, Josef Sipek wrote:
...

Quoted 2 lines

These functions come from the FiST templates [1]. Some of these can definitely removed, or split up.

Forgot to say what [1] was...

[1] http://www.filesystems.org/

Josef "Jeff" Sipek.

Signature · 5 lines
It used to be said [...] that AIX looks like one space alien discovered
Unix, and described it to another different space alien who then implemented
AIX. But their universal translators were broken and they'd had to gesture a
lot.
		- Paul Tomblin 
#7 lore raw

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

In reply to Josef Sipek
Quoted 11 lines · On Fri, 13 Oct 2006 16:07:05 -0400 Josef Sipek <[email protected]> wrote:
Quoted 10 lines

include/linux/stack_fs.h line 45

Quoted 8 lines
include/linux/stack_fs.h new file +8 -0
+static inline void __stackfs_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);

I cannot find a get_nlinks() in 2.6.19-rc2?

Quoted 2 lines

It is the last argument to the function. Perhaps the function name is deceiving.

doh.

That's why us old farts like to see

	dest->i_nlink = (*get_nlinks)(dest);
#8 lore raw

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

In reply to Josef Sipek
Quoted 3 lines
Quoted 3 lines

Many of these functions are too large to be inlined. Suggest they be placed in fs/fs-stack.c (or whatever we call it).

fs/stack.c would probably be enough -- fs/fs-stack.c is like include/linux/reiserfs_fs.h

Quoted 2 lines

Ack. As a rule of thumb, for functions like these (laundry list of assignments), what's a good threshold?

3 or 4 I guess. Might want to take a look at other static-inline functions.

	-`J'
#3 lore raw

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

In reply to Andrew James Wade
Quoted 8 lines · Josef Jeff Sipek

Review

Quoted 4 lines
(quoted diff) +4 -0
+static inline void stackfs_copy_inode_size(struct inode *dst,
+					   const struct inode *src)
+{
+	i_size_write(dst, i_size_read((struct inode *)src));

Instead of casting, I'd change the signature of i_size_read.

Change the signature of i_size_read(), IMINOR() and IMAJOR() because they, or the functions they call, will never modify the argument. Compile-tested on x86 allmodconfig.

include/linux/fs.h +3 -3
Index: linux-2.6.19-rc1/include/linux/fs.h
===================================================================
@@ -633,7 +633,7 @@ enum inode_i_mutex_lock_class
  * cmpxchg8b without the need of the lock prefix). For SMP compiles
  * and 64bit archs it makes no difference if preempt is enabled or not.
  */
-static inline loff_t i_size_read(struct inode *inode)
+static inline loff_t i_size_read(const struct inode *inode)
 {
 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
 	loff_t i_size;
@@ -672,12 +672,12 @@ static inline void i_size_write(struct i
 #endif
 }
 
-static inline unsigned iminor(struct inode *inode)
+static inline unsigned iminor(const struct inode *inode)
 {
 	return MINOR(inode->i_rdev);
 }
 
-static inline unsigned imajor(struct inode *inode)
+static inline unsigned imajor(const struct inode *inode)
 {
 	return MAJOR(inode->i_rdev);
 }

#<EOF>

	-`J'