Chinaunix首页 | 论坛 | 博客
  • 博客访问: 713939
  • 博文数量: 79
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 1338
  • 用 户 组: 普通用户
  • 注册时间: 2012-06-12 08:51
个人简介

XMU->九天揽月->五湖抓鳖->DSP->driver->kernel/OpenWRT->ISP/RTOS

文章分类

全部博文(79)

文章存档

2020年(2)

2018年(3)

2016年(7)

2015年(42)

2014年(25)

分类: LINUX

2014-10-29 20:08:17

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 的回调实现即可。
   

点击(此处)折叠或打开

  1. diff -uNr linux-2.6.36-ori/fs/sysfs/inode.c linux-2.6.36/fs/sysfs/inode.c
  2. --- linux-2.6.36-ori/fs/sysfs/inode.c    2014-10-29 17:25:24.203842130 +0800
  3. +++ linux-2.6.36/fs/sysfs/inode.c    2014-10-29 17:46:47.328092412 +0800
  4. @@ -348,13 +348,16 @@
  5.          return -ENOENT;
  6.  }
  7.  
  8. -int sysfs_permission(struct inode *inode, int mask)
  9. +int sysfs_permission(struct inode *inode, int mask, unsigned int flags)
  10.  {
  11.      struct sysfs_dirent *sd = inode->i_private;
  12.  
  13. -    mutex_lock(&sysfs_mutex);
  14. +    if (flags & IPERM_FLAG_RCU)
  15. +        return -ECHILD;
  16. +
  17. + mutex_lock(&sysfs_mutex);
  18.      sysfs_refresh_inode(sd, inode);
  19.      mutex_unlock(&sysfs_mutex);
  20.  
  21. -    return generic_permission(inode, mask, NULL);
  22. +    return generic_permission(inode, mask, flags, NULL);
  23.  }
  24. diff -uNr linux-2.6.36-ori/fs/sysfs/sysfs.h linux-2.6.36/fs/sysfs/sysfs.h
  25. --- linux-2.6.36-ori/fs/sysfs/sysfs.h    2014-10-29 17:25:24.203842130 +0800
  26. +++ linux-2.6.36/fs/sysfs/sysfs.h    2014-10-29 17:46:47.328092412 +0800
  27. @@ -200,7 +200,7 @@
  28.  struct inode *sysfs_get_inode(struct super_block *sb, struct sysfs_dirent *sd);
  29.  void sysfs_evict_inode(struct inode *inode);
  30.  int sysfs_sd_setattr(struct sysfs_dirent *sd, struct iattr *iattr);
  31. -int sysfs_permission(struct inode *inode, int mask);
  32. +int sysfs_permission(struct inode *inode, int mask, unsigned int flags);
  33.  int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
  34.  int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
  35.  int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value,

  36. diff -uNr linux-2.6.36-ori/fs/proc/base.c linux-2.6.36/fs/proc/base.c
  37. --- linux-2.6.36-ori/fs/proc/base.c    2014-10-29 17:25:24.208842063 +0800
  38. +++ linux-2.6.36/fs/proc/base.c    2014-10-29 17:46:47.326092612 +0800
  39. @@ -2050,11 +2050,14 @@
  40.   * /proc/pid/fd needs a special permission handler so that a process can still
  41.   * access /proc/self/fd after it has executed a setuid().
  42.   */
  43. -static int proc_fd_permission(struct inode *inode, int mask)
  44. +static int proc_fd_permission(struct inode *inode, int mask, unsigned int flags)
  45.  {
  46.      int rv;
  47.  
  48. -    rv = generic_permission(inode, mask, NULL);
  49. +    if (flags & IPERM_FLAG_RCU)
  50. +        return -ECHILD;
  51. +
  52. +    rv = generic_permission(inode, mask, flags, NULL);
  53.      if (rv == 0)
  54.          return 0;
  55.      if (task_pid(current) == proc_pid(inode))

  56. diff -uNr linux-2.6.36-ori/fs/fuse/dir.c linux-2.6.36/fs/fuse/dir.c
  57. --- linux-2.6.36-ori/fs/fuse/dir.c    2014-10-29 17:25:24.287842062 +0800
  58. +++ linux-2.6.36/fs/fuse/dir.c    2014-10-29 17:46:47.318092493 +0800
  59. @@ -981,12 +981,15 @@
  60.   * access request is sent. Execute permission is still checked
  61.   * locally based on file mode.
  62.   */
  63. -static int fuse_permission(struct inode *inode, int mask)
  64. +static int fuse_permission(struct inode *inode, int mask, unsigned int flags)
  65.  {
  66.      struct fuse_conn *fc = get_fuse_conn(inode);
  67.      bool refreshed = false;
  68.      int err = 0;
  69.  
  70. +    if (flags & IPERM_FLAG_RCU)
  71. +        return -ECHILD;
  72. +
  73.      if (!fuse_allow_task(fc, current))
  74.          return -EACCES;
  75.  
  76. @@ -1001,7 +1004,7 @@
  77.      }
  78.  
  79.      if (fc->flags & FUSE_DEFAULT_PERMISSIONS) {
  80. -        err = generic_permission(inode, mask, NULL);
  81. +        err = generic_permission(inode, mask, flags, NULL);
  82.  
  83.          /* If permission is denied, try to refresh file
  84.           attributes. This is also needed, because the root
  85. @@ -1009,7 +1012,7 @@
  86.          if (err == -EACCES && !refreshed) {
  87.              err = fuse_do_getattr(inode, NULL, NULL);
  88.              if (!err)
  89. -                err = generic_permission(inode, mask, NULL);
  90. +                err = generic_permission(inode, mask, flags, NULL);
  91.          }
  92.  
  93.          /* 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,内核就会挂住。

阅读(4895) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~