Skip to contentSkip to conversation

overlayfs: module and statfs fixes

PATCH Applied Andy Whitcroft 2 participants 4 messages Oct 1, 2010 – Oct 4, 2010

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

cover overlayfs: module and statfs fixes

Just been playing with overlayfs and hit a couple of issues. First I was not able to build this filesystem as a module. Second statfs support was missing. Following this email are a couple of patches which I used to fix these up. I am not 100% sure the statfs approach is quite right, but its not clear the semantics can ever be correct in the face of an overlay.

With these applied I was able to drop an overlay over the top of a very out of date Ubuntu chroot and upgrade it to the latest and greatest; all without incident.

Nice.

-apw

Andy Whitcroft (2):
overlayfs: export security_inode_permission to allow overlayfs to be
modular
overlayfs: add statfs support

 fs/overlayfs/overlayfs.c |   20 ++++++++++++++++++++
 security/security.c      |    1 +
 2 files changed, 21 insertions(+), 0 deletions(-)
#1 lore raw

PATCH 1/2 overlayfs: export security_inode_permission to allow overlayfs to be modular

When compiling overlayfs as a module we end up with an unknown symbol 'security_inode_permission'. Export it.

---
 security/security.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
security/security.c +1 -0
index ca39940..b8329cc 100644
@@ -556,6 +556,7 @@ int security_inode_permission(struct inode *inode, int mask)
 		return 0;
 	return security_ops->inode_permission(inode, mask);
 }
+EXPORT_SYMBOL_GPL(security_inode_permission);
 
 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
 {
Signature · 1 line
1.7.0.4
#2 lore raw

PATCH 2/2 overlayfs: add statfs support

In reply to Andy Whitcroft

Add support for statfs to the overlayfs filesystem. As the upper layer is the target of all write operations assume that the space in that filesystem is the space in the overlayfs. There will be some inaccuracy as overwriting a file will copy it up and consume space we were not expecting, but it is better than nothing.

Use the upper layer dentry and mount from the overlayfs root inode, passing the statfs call to that filesystem.

---
 fs/overlayfs/overlayfs.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
fs/overlayfs/overlayfs.c +20 -0
index 61139fa..2bef9c1 100644
@@ -1943,9 +1943,29 @@ static int ovl_remount_fs(struct super_block *sb, int *flagsp, char *data)
 		return mnt_want_write(ufs->upper_mnt);
 }
 
+/**
+ * ovl_statfs
+ * @sb: The overlayfs super block
+ * @buf: The struct kstatfs to fill in with stats
+ *
+ * Get the filesystem statistics.  As writes always target the upper layer
+ * filesystem pass the statfs to the same filesystem.
+ */
+static int ovl_statfs(struct dentry *dentry, struct kstatfs *buf)
+{
+	struct dentry *root_dentry = dentry->d_sb->s_root;
+	struct path path;
+	ovl_path_upper(root_dentry, &path);
+
+	if (!path.dentry->d_sb->s_op->statfs)
+		return -ENOSYS;
+	return path.dentry->d_sb->s_op->statfs(path.dentry, buf);
+}
+
 static const struct super_operations ovl_super_operations = {
 	.put_super	= ovl_put_super,
 	.remount_fs	= ovl_remount_fs,
+	.statfs		= ovl_statfs,
 };
 
 struct ovl_config {
Signature · 1 line
1.7.0.4
maintainer Applied
#3 lore raw
In reply to Andy Whitcroft
Quoted 5 lines · Andy Whitcroft

Just been playing with overlayfs and hit a couple of issues. First I was not able to build this filesystem as a module. Second statfs support was missing. Following this email are a couple of patches which I used to fix these up. I am not 100% sure the statfs approach is quite right, but its not clear the semantics can ever be correct in the face of an overlay.

Applied both patches and pused to the overlayfs.v3 branch. Also pushed a patch changing two BUG_ONs to WARN_ON.

Quoted 4 lines

With these applied I was able to drop an overlay over the top of a very out of date Ubuntu chroot and upgrade it to the latest and greatest; all without incident.

Great, thanks for testing.

Miklos