openwrt的rootfs默认都是squashfs的,只读属性,压缩性高。为了实现可写的需求,openwrt利用了overlay来实现。本文在broadcom的sdk 2.6.36上实现overlayfs支持。
从openwrt的官方站上找到早期的2.6kernel的overlayfs补丁文件,实际对比下,比较合适的就这个:
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-2.6.38/209-overlayfs.patch?rev=26213,
在此基础上,因为涉及到了struct inode_operations,故proc,sysfs,fuse模块都得必须手动修改,对照编译错误,修改下 *_inode_operations.permission 的回调实现即可。
-
diff -uNr linux-2.6.36-ori/fs/sysfs/inode.c linux-2.6.36/fs/sysfs/inode.c
-
--- linux-2.6.36-ori/fs/sysfs/inode.c 2014-10-29 17:25:24.203842130 +0800
-
+++ linux-2.6.36/fs/sysfs/inode.c 2014-10-29 17:46:47.328092412 +0800
-
@@ -348,13 +348,16 @@
-
return -ENOENT;
-
}
-
-
-int sysfs_permission(struct inode *inode, int mask)
-
+int sysfs_permission(struct inode *inode, int mask, unsigned int flags)
-
{
-
struct sysfs_dirent *sd = inode->i_private;
-
-
- mutex_lock(&sysfs_mutex);
-
+ if (flags & IPERM_FLAG_RCU)
-
+ return -ECHILD;
-
+
-
+ mutex_lock(&sysfs_mutex);
-
sysfs_refresh_inode(sd, inode);
-
mutex_unlock(&sysfs_mutex);
-
-
- return generic_permission(inode, mask, NULL);
-
+ return generic_permission(inode, mask, flags, NULL);
-
}
-
diff -uNr linux-2.6.36-ori/fs/sysfs/sysfs.h linux-2.6.36/fs/sysfs/sysfs.h
-
--- linux-2.6.36-ori/fs/sysfs/sysfs.h 2014-10-29 17:25:24.203842130 +0800
-
+++ linux-2.6.36/fs/sysfs/sysfs.h 2014-10-29 17:46:47.328092412 +0800
-
@@ -200,7 +200,7 @@
-
struct inode *sysfs_get_inode(struct super_block *sb, struct sysfs_dirent *sd);
-
void sysfs_evict_inode(struct inode *inode);
-
int sysfs_sd_setattr(struct sysfs_dirent *sd, struct iattr *iattr);
-
-int sysfs_permission(struct inode *inode, int mask);
-
+int sysfs_permission(struct inode *inode, int mask, unsigned int flags);
-
int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
-
int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
-
int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value,
-
-
diff -uNr linux-2.6.36-ori/fs/proc/base.c linux-2.6.36/fs/proc/base.c
-
--- linux-2.6.36-ori/fs/proc/base.c 2014-10-29 17:25:24.208842063 +0800
-
+++ linux-2.6.36/fs/proc/base.c 2014-10-29 17:46:47.326092612 +0800
-
@@ -2050,11 +2050,14 @@
-
* /proc/pid/fd needs a special permission handler so that a process can still
-
* access /proc/self/fd after it has executed a setuid().
-
*/
-
-static int proc_fd_permission(struct inode *inode, int mask)
-
+static int proc_fd_permission(struct inode *inode, int mask, unsigned int flags)
-
{
-
int rv;
-
-
- rv = generic_permission(inode, mask, NULL);
-
+ if (flags & IPERM_FLAG_RCU)
-
+ return -ECHILD;
-
+
-
+ rv = generic_permission(inode, mask, flags, NULL);
-
if (rv == 0)
-
return 0;
-
if (task_pid(current) == proc_pid(inode))
-
-
diff -uNr linux-2.6.36-ori/fs/fuse/dir.c linux-2.6.36/fs/fuse/dir.c
-
--- linux-2.6.36-ori/fs/fuse/dir.c 2014-10-29 17:25:24.287842062 +0800
-
+++ linux-2.6.36/fs/fuse/dir.c 2014-10-29 17:46:47.318092493 +0800
-
@@ -981,12 +981,15 @@
-
* access request is sent. Execute permission is still checked
-
* locally based on file mode.
-
*/
-
-static int fuse_permission(struct inode *inode, int mask)
-
+static int fuse_permission(struct inode *inode, int mask, unsigned int flags)
-
{
-
struct fuse_conn *fc = get_fuse_conn(inode);
-
bool refreshed = false;
-
int err = 0;
-
-
+ if (flags & IPERM_FLAG_RCU)
-
+ return -ECHILD;
-
+
-
if (!fuse_allow_task(fc, current))
-
return -EACCES;
-
-
@@ -1001,7 +1004,7 @@
-
}
-
-
if (fc->flags & FUSE_DEFAULT_PERMISSIONS) {
-
- err = generic_permission(inode, mask, NULL);
-
+ err = generic_permission(inode, mask, flags, NULL);
-
-
/* If permission is denied, try to refresh file
-
attributes. This is also needed, because the root
-
@@ -1009,7 +1012,7 @@
-
if (err == -EACCES && !refreshed) {
-
err = fuse_do_getattr(inode, NULL, NULL);
-
if (!err)
-
- err = generic_permission(inode, mask, NULL);
-
+ err = generic_permission(inode, mask, flags, NULL);
-
}
-
-
/* Note: the opposite of the above test does not
还有一个overlayfs的patch非常重要,
https://dev.openwrt.org/browser/trunk/target/linux/generic/patches-2.6.38/210-overlayfs_fix_readdir_deadlock.patch?rev=26213
解决overlayfs上死锁问题。问题现象是进入overlay的目录后ls,内核就会挂住。
阅读(4891) | 评论(0) | 转发(0) |