fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / fs / jfs / jfs_inode.c
index 4340659..5fc2d56 100644 (file)
@@ -3,23 +3,23 @@
  *
  *   This program is free software;  you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or 
+ *   the Free Software Foundation; either version 2 of the License, or
  *   (at your option) any later version.
- * 
+ *
  *   This program is distributed in the hope that it will be useful,
  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
  *   the GNU General Public License for more details.
  *
  *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software 
+ *   along with this program;  if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
 #include <linux/fs.h>
 #include <linux/quotaops.h>
 #include <linux/vs_dlimit.h>
-#include <linux/vserver/xid.h>
+#include <linux/vs_tag.h>
 #include "jfs_incore.h"
 #include "jfs_inode.h"
 #include "jfs_filsys.h"
 #include "jfs_dinode.h"
 #include "jfs_debug.h"
 
+
+void jfs_set_inode_flags(struct inode *inode)
+{
+       unsigned int flags = JFS_IP(inode)->mode2;
+
+       inode->i_flags &= ~(S_IMMUTABLE | S_IUNLINK | S_BARRIER |
+               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
+
+       if (flags & JFS_IMMUTABLE_FL)
+               inode->i_flags |= S_IMMUTABLE;
+       if (flags & JFS_IUNLINK_FL)
+               inode->i_flags |= S_IUNLINK;
+       if (flags & JFS_BARRIER_FL)
+               inode->i_flags |= S_BARRIER;
+
+       if (flags & JFS_SYNC_FL)
+               inode->i_flags |= S_SYNC;
+       if (flags & JFS_APPEND_FL)
+               inode->i_flags |= S_APPEND;
+       if (flags & JFS_NOATIME_FL)
+               inode->i_flags |= S_NOATIME;
+       if (flags & JFS_DIRSYNC_FL)
+               inode->i_flags |= S_DIRSYNC;
+}
+
+int jfs_sync_flags(struct inode *inode)
+{
+       unsigned int oldflags, newflags;
+
+       oldflags = JFS_IP(inode)->mode2;
+       newflags = oldflags & ~(JFS_IMMUTABLE_FL |
+               JFS_IUNLINK_FL | JFS_BARRIER_FL);
+
+       if (IS_IMMUTABLE(inode))
+               newflags |= JFS_IMMUTABLE_FL;
+       if (IS_IUNLINK(inode))
+               newflags |= JFS_IUNLINK_FL;
+       if (IS_BARRIER(inode))
+               newflags |= JFS_BARRIER_FL;
+
+       if (oldflags ^ newflags) {
+               JFS_IP(inode)->mode2 = newflags;
+               inode->i_ctime = CURRENT_TIME;
+               mark_inode_dirty(inode);
+       }
+       return 0;
+}
+
 /*
  * NAME:       ialloc()
  *
@@ -43,7 +91,7 @@ struct inode *ialloc(struct inode *parent, umode_t mode)
        inode = new_inode(sb);
        if (!inode) {
                jfs_warn("ialloc: new_inode returned NULL!");
-               return inode;
+               return ERR_PTR(-ENOMEM);
        }
 
        jfs_inode = JFS_IP(inode);
@@ -51,9 +99,10 @@ struct inode *ialloc(struct inode *parent, umode_t mode)
        rc = diAlloc(parent, S_ISDIR(mode), inode);
        if (rc) {
                jfs_warn("ialloc: diAlloc returned %d!", rc);
-               make_bad_inode(inode);
+               if (rc == -EIO)
+                       make_bad_inode(inode);
                iput(inode);
-               return NULL;
+               return ERR_PTR(rc);
        }
 
        inode->i_uid = current->fsuid;
@@ -64,7 +113,14 @@ struct inode *ialloc(struct inode *parent, umode_t mode)
        } else
                inode->i_gid = current->fsgid;
 
-       inode->i_xid = vx_current_fsxid(sb);
+       /*
+        * New inodes need to save sane values on disk when
+        * uid & gid mount options are used
+        */
+       jfs_inode->saved_uid = inode->i_uid;
+       jfs_inode->saved_gid = inode->i_gid;
+
+       inode->i_tag = dx_current_fstag(sb);
        if (DLIMIT_ALLOC_INODE(inode)) {
                iput(inode);
                return NULL;
@@ -79,15 +135,24 @@ struct inode *ialloc(struct inode *parent, umode_t mode)
                inode->i_flags |= S_NOQUOTA;
                inode->i_nlink = 0;
                iput(inode);
-               return NULL;
+               return ERR_PTR(-EDQUOT);
        }
 
        inode->i_mode = mode;
-       if (S_ISDIR(mode))
-               jfs_inode->mode2 = IDIRECTORY | mode;
-       else
-               jfs_inode->mode2 = INLINEEA | ISPARSE | mode;
-       inode->i_blksize = sb->s_blocksize;
+       /* inherit flags from parent */
+       jfs_inode->mode2 = JFS_IP(parent)->mode2 & JFS_FL_INHERIT;
+
+       if (S_ISDIR(mode)) {
+               jfs_inode->mode2 |= IDIRECTORY;
+               jfs_inode->mode2 &= ~JFS_DIRSYNC_FL;
+       }
+       else {
+               jfs_inode->mode2 |= INLINEEA | ISPARSE;
+               if (S_ISLNK(mode))
+                       jfs_inode->mode2 &= ~(JFS_IMMUTABLE_FL|JFS_APPEND_FL);
+       }
+       jfs_inode->mode2 |= mode;
+
        inode->i_blocks = 0;
        inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
        jfs_inode->otime = inode->i_ctime.tv_sec;
@@ -107,6 +172,7 @@ struct inode *ialloc(struct inode *parent, umode_t mode)
        jfs_inode->atlhead = 0;
        jfs_inode->atltail = 0;
        jfs_inode->xtlid = 0;
+       jfs_set_inode_flags(inode);
 
        jfs_info("ialloc returns inode = 0x%p\n", inode);