- patches.fixes/patch-2.6.11-rc1: 2.6.11-rc1.
[linux-flexiantxendom0-3.2.10.git] / fs / ext2 / xattr.c
index 837104e..758f797 100644 (file)
@@ -24,7 +24,7 @@
  *
  *   +------------------+
  *   | header           |
- *   ¦ entry 1          | |
+ *   | entry 1          | |
  *   | entry 2          | | growing downwards
  *   | entry 3          | v
  *   | four null bytes  |
@@ -95,13 +95,12 @@ static int ext2_xattr_set2(struct inode *, struct buffer_head *,
 static int ext2_xattr_cache_insert(struct buffer_head *);
 static struct buffer_head *ext2_xattr_cache_find(struct inode *,
                                                 struct ext2_xattr_header *);
-static void ext2_xattr_cache_remove(struct buffer_head *);
 static void ext2_xattr_rehash(struct ext2_xattr_header *,
                              struct ext2_xattr_entry *);
 
 static struct mb_cache *ext2_xattr_cache;
 
-static struct xattr_handler *ext2_xattr_handler_map[EXT2_XATTR_INDEX_MAX] = {
+static struct xattr_handler *ext2_xattr_handler_map[] = {
        [EXT2_XATTR_INDEX_USER]              = &ext2_xattr_user_handler,
 #ifdef CONFIG_EXT2_FS_POSIX_ACL
        [EXT2_XATTR_INDEX_POSIX_ACL_ACCESS]  = &ext2_xattr_acl_access_handler,
@@ -131,23 +130,12 @@ ext2_xattr_handler(int name_index)
 {
        struct xattr_handler *handler = NULL;
 
-       if (name_index > 0 && name_index <= EXT2_XATTR_INDEX_MAX)
+       if (name_index > 0 && name_index < ARRAY_SIZE(ext2_xattr_handler_map))
                handler = ext2_xattr_handler_map[name_index];
        return handler;
 }
 
 /*
- * Inode operation listxattr()
- *
- * dentry->d_inode->i_sem: don't care
- */
-ssize_t
-ext2_listxattr(struct dentry *dentry, char *buffer, size_t size)
-{
-       return ext2_xattr_list(dentry->d_inode, buffer, size);
-}
-
-/*
  * ext2_xattr_get()
  *
  * Copy an extended attribute into the buffer
@@ -260,7 +248,7 @@ cleanup:
  * Returns a negative error number on failure, or the number of bytes
  * used / required on success.
  */
-int
+static int
 ext2_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
 {
        struct buffer_head *bh = NULL;
@@ -335,6 +323,17 @@ cleanup:
 }
 
 /*
+ * Inode operation listxattr()
+ *
+ * dentry->d_inode->i_sem: don't care
+ */
+ssize_t
+ext2_listxattr(struct dentry *dentry, char *buffer, size_t size)
+{
+       return ext2_xattr_list(dentry->d_inode, buffer, size);
+}
+
+/*
  * If the EXT2_FEATURE_COMPAT_EXT_ATTR feature of this file system is
  * not set, set it.
  */
@@ -494,15 +493,22 @@ bad_block:                ext2_error(sb, "ext2_xattr_set",
        /* Here we know that we can set the new attribute. */
 
        if (header) {
+               struct mb_cache_entry *ce;
+
                /* assert(header == HDR(bh)); */
+               ce = mb_cache_entry_get(ext2_xattr_cache, bh->b_bdev,
+                                       bh->b_blocknr);
                lock_buffer(bh);
                if (header->h_refcount == cpu_to_le32(1)) {
                        ea_bdebug(bh, "modifying in-place");
-                       ext2_xattr_cache_remove(bh);
+                       if (ce)
+                               mb_cache_entry_free(ce);
                        /* keep the buffer locked while modifying it. */
                } else {
                        int offset;
 
+                       if (ce)
+                               mb_cache_entry_release(ce);
                        unlock_buffer(bh);
                        ea_bdebug(bh, "cloning");
                        header = kmalloc(bh->b_size, GFP_KERNEL);
@@ -697,7 +703,7 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
 
        /* Update the inode. */
        EXT2_I(inode)->i_file_acl = new_bh ? new_bh->b_blocknr : 0;
-       inode->i_ctime = CURRENT_TIME;
+       inode->i_ctime = CURRENT_TIME_SEC;
        if (IS_SYNC(inode)) {
                error = ext2_sync_inode (inode);
                if (error)
@@ -707,13 +713,19 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
 
        error = 0;
        if (old_bh && old_bh != new_bh) {
+               struct mb_cache_entry *ce;
+
                /*
                 * If there was an old block and we are no longer using it,
                 * release the old block.
                 */
+               ce = mb_cache_entry_get(ext2_xattr_cache, old_bh->b_bdev,
+                                       old_bh->b_blocknr);
                lock_buffer(old_bh);
                if (HDR(old_bh)->h_refcount == cpu_to_le32(1)) {
                        /* Free the old block. */
+                       if (ce)
+                               mb_cache_entry_free(ce);
                        ea_bdebug(old_bh, "freeing");
                        ext2_free_blocks(inode, old_bh->b_blocknr, 1);
                        /* We let our caller release old_bh, so we
@@ -724,6 +736,8 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
                        /* Decrement the refcount only. */
                        HDR(old_bh)->h_refcount = cpu_to_le32(
                                le32_to_cpu(HDR(old_bh)->h_refcount) - 1);
+                       if (ce)
+                               mb_cache_entry_release(ce);
                        DQUOT_FREE_BLOCK(inode, 1);
                        mark_buffer_dirty(old_bh);
                        ea_bdebug(old_bh, "refcount now=%d",
@@ -748,6 +762,7 @@ void
 ext2_xattr_delete_inode(struct inode *inode)
 {
        struct buffer_head *bh = NULL;
+       struct mb_cache_entry *ce;
 
        down_write(&EXT2_I(inode)->xattr_sem);
        if (!EXT2_I(inode)->i_file_acl)
@@ -767,15 +782,19 @@ ext2_xattr_delete_inode(struct inode *inode)
                        EXT2_I(inode)->i_file_acl);
                goto cleanup;
        }
+       ce = mb_cache_entry_get(ext2_xattr_cache, bh->b_bdev, bh->b_blocknr);
        lock_buffer(bh);
        if (HDR(bh)->h_refcount == cpu_to_le32(1)) {
-               ext2_xattr_cache_remove(bh);
+               if (ce)
+                       mb_cache_entry_free(ce);
                ext2_free_blocks(inode, EXT2_I(inode)->i_file_acl, 1);
                get_bh(bh);
                bforget(bh);
        } else {
                HDR(bh)->h_refcount = cpu_to_le32(
                        le32_to_cpu(HDR(bh)->h_refcount) - 1);
+               if (ce)
+                       mb_cache_entry_release(ce);
                mark_buffer_dirty(bh);
                if (IS_SYNC(inode))
                        sync_dirty_buffer(bh);
@@ -892,11 +911,19 @@ ext2_xattr_cache_find(struct inode *inode, struct ext2_xattr_header *header)
        if (!header->h_hash)
                return NULL;  /* never share */
        ea_idebug(inode, "looking for cached blocks [%x]", (int)hash);
+again:
        ce = mb_cache_entry_find_first(ext2_xattr_cache, 0,
                                       inode->i_sb->s_bdev, hash);
        while (ce) {
-               struct buffer_head *bh = sb_bread(inode->i_sb, ce->e_block);
+               struct buffer_head *bh;
+
+               if (IS_ERR(ce)) {
+                       if (PTR_ERR(ce) == -EAGAIN)
+                               goto again;
+                       break;
+               }
 
+               bh = sb_bread(inode->i_sb, ce->e_block);
                if (!bh) {
                        ext2_error(inode->i_sb, "ext2_xattr_cache_find",
                                "inode %ld: block %ld read error",
@@ -923,26 +950,6 @@ ext2_xattr_cache_find(struct inode *inode, struct ext2_xattr_header *header)
        return NULL;
 }
 
-/*
- * ext2_xattr_cache_remove()
- *
- * Remove the cache entry of a block from the cache. Called when a
- * block becomes invalid.
- */
-static void
-ext2_xattr_cache_remove(struct buffer_head *bh)
-{
-       struct mb_cache_entry *ce;
-
-       ce = mb_cache_entry_get(ext2_xattr_cache, bh->b_bdev, bh->b_blocknr);
-       if (ce) {
-               ea_bdebug(bh, "removing (%d cache entries remaining)",
-                         atomic_read(&ext2_xattr_cache->c_entry_count)-1);
-               mb_cache_entry_free(ce);
-       } else 
-               ea_bdebug(bh, "no cache entry");
-}
-
 #define NAME_HASH_SHIFT 5
 #define VALUE_HASH_SHIFT 16
 
@@ -1016,7 +1023,7 @@ init_ext2_xattr(void)
 {
        ext2_xattr_cache = mb_cache_create("ext2_xattr", NULL,
                sizeof(struct mb_cache_entry) +
-               sizeof(struct mb_cache_entry_index), 1, 6);
+               sizeof(((struct mb_cache_entry *) 0)->e_indexes[0]), 1, 6);
        if (!ext2_xattr_cache)
                return -ENOMEM;
        return 0;