Whamcloud - gitweb
LU-6757 ldiskfs: acquire i_mutex lock for ext4_update_i_disksize 12/16012/3
authorJian Yu <jian.yu@intel.com>
Mon, 24 Aug 2015 06:03:02 +0000 (23:03 -0700)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 26 Aug 2015 15:31:49 +0000 (15:31 +0000)
For RHEL 7.1 kernel version 3.10.0, i_mutex lock needs to be acquired
before calling ext4_update_i_disksize() to avoid races with truncate.

i_size_write() also needs locking around it (normally i_mutex), otherwise
on 32bit/SMP an update of i_size_seqcount can be lost, resulting in
subsequent i_size_read() calls spinning forever.

For large EA support, ext4_xattr_check_names() will return -EIO. This
patch fixes that by checking whether the large EA value is saved in an
external EA inode or not.

Signed-off-by: Jian Yu <jian.yu@intel.com>
Change-Id: I095246cc1f7457defe87ca246edf98bbc051bc29
Reviewed-on: http://review.whamcloud.com/16012
Tested-by: Jenkins
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Yang Sheng <yang.sheng@intel.com>
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
ldiskfs/kernel_patches/patches/rhel7/ext4-large-eas.patch

index 902e512..1fd34aa 100644 (file)
@@ -145,7 +145,15 @@ Index: linux-stage/fs/ext4/xattr.c
 ===================================================================
 --- linux-stage.orig/fs/ext4/xattr.c
 +++ linux-stage/fs/ext4/xattr.c
 ===================================================================
 --- linux-stage.orig/fs/ext4/xattr.c
 +++ linux-stage/fs/ext4/xattr.c
-@@ -233,19 +233,26 @@ ext4_xattr_check_block(struct inode *ino
+@@ -201,6 +201,7 @@ ext4_xattr_check_names(struct ext4_xattr
+       while (!IS_LAST_ENTRY(entry)) {
+               if (entry->e_value_size != 0 &&
++                  entry->e_value_inum == 0 &&
+                   (value_start + le16_to_cpu(entry->e_value_offs) <
+                    (void *)e + sizeof(__u32) ||
+                    value_start + le16_to_cpu(entry->e_value_offs) +
+@@ -233,19 +234,26 @@ ext4_xattr_check_block(struct inode *ino
  }
  
  static inline int
  }
  
  static inline int
@@ -176,7 +184,7 @@ Index: linux-stage/fs/ext4/xattr.c
  {
        struct ext4_xattr_entry *entry;
        size_t name_len;
  {
        struct ext4_xattr_entry *entry;
        size_t name_len;
-@@ -265,11 +272,103 @@ ext4_xattr_find_entry(struct ext4_xattr_
+@@ -265,11 +273,103 @@ ext4_xattr_find_entry(struct ext4_xattr_
                        break;
        }
        *pentry = entry;
                        break;
        }
        *pentry = entry;
@@ -281,7 +289,7 @@ Index: linux-stage/fs/ext4/xattr.c
  static int
  ext4_xattr_block_get(struct inode *inode, int name_index, const char *name,
                     void *buffer, size_t buffer_size)
  static int
  ext4_xattr_block_get(struct inode *inode, int name_index, const char *name,
                     void *buffer, size_t buffer_size)
-@@ -301,7 +400,8 @@ bad_block:
+@@ -301,7 +401,8 @@ bad_block:
        }
        ext4_xattr_cache_insert(bh);
        entry = BFIRST(bh);
        }
        ext4_xattr_cache_insert(bh);
        entry = BFIRST(bh);
@@ -291,7 +299,7 @@ Index: linux-stage/fs/ext4/xattr.c
        if (error == -EIO)
                goto bad_block;
        if (error)
        if (error == -EIO)
                goto bad_block;
        if (error)
-@@ -311,8 +411,16 @@ bad_block:
+@@ -311,8 +412,16 @@ bad_block:
                error = -ERANGE;
                if (size > buffer_size)
                        goto cleanup;
                error = -ERANGE;
                if (size > buffer_size)
                        goto cleanup;
@@ -310,7 +318,7 @@ Index: linux-stage/fs/ext4/xattr.c
        }
        error = size;
  
        }
        error = size;
  
-@@ -346,7 +454,7 @@ ext4_xattr_ibody_get(struct inode *inode
+@@ -346,7 +455,7 @@ ext4_xattr_ibody_get(struct inode *inode
        if (error)
                goto cleanup;
        error = ext4_xattr_find_entry(&entry, name_index, name,
        if (error)
                goto cleanup;
        error = ext4_xattr_find_entry(&entry, name_index, name,
@@ -319,7 +327,7 @@ Index: linux-stage/fs/ext4/xattr.c
        if (error)
                goto cleanup;
        size = le32_to_cpu(entry->e_value_size);
        if (error)
                goto cleanup;
        size = le32_to_cpu(entry->e_value_size);
-@@ -354,8 +462,16 @@ ext4_xattr_ibody_get(struct inode *inode
+@@ -354,8 +463,16 @@ ext4_xattr_ibody_get(struct inode *inode
                error = -ERANGE;
                if (size > buffer_size)
                        goto cleanup;
                error = -ERANGE;
                if (size > buffer_size)
                        goto cleanup;
@@ -338,7 +346,7 @@ Index: linux-stage/fs/ext4/xattr.c
        }
        error = size;
  
        }
        error = size;
  
-@@ -600,7 +716,7 @@ static size_t ext4_xattr_free_space(stru
+@@ -600,7 +717,7 @@ static size_t ext4_xattr_free_space(stru
                                    size_t *min_offs, void *base, int *total)
  {
        for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) {
                                    size_t *min_offs, void *base, int *total)
  {
        for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) {
@@ -347,7 +355,7 @@ Index: linux-stage/fs/ext4/xattr.c
                        size_t offs = le16_to_cpu(last->e_value_offs);
                        if (offs < *min_offs)
                                *min_offs = offs;
                        size_t offs = le16_to_cpu(last->e_value_offs);
                        if (offs < *min_offs)
                                *min_offs = offs;
-@@ -611,16 +727,172 @@ static size_t ext4_xattr_free_space(stru
+@@ -611,16 +728,174 @@ static size_t ext4_xattr_free_space(stru
        return (*min_offs - ((void *)last - base) - sizeof(__u32));
  }
  
        return (*min_offs - ((void *)last - base) - sizeof(__u32));
  }
  
@@ -411,8 +419,10 @@ Index: linux-stage/fs/ext4/xattr.c
 +              block += 1;
 +      }
 +
 +              block += 1;
 +      }
 +
++      mutex_lock(&ea_inode->i_mutex);
 +      i_size_write(ea_inode, wsize);
 +      ext4_update_i_disksize(ea_inode, wsize);
 +      i_size_write(ea_inode, wsize);
 +      ext4_update_i_disksize(ea_inode, wsize);
++      mutex_unlock(&ea_inode->i_mutex);
 +
 +      ext4_mark_inode_dirty(handle, ea_inode);
 +
 +
 +      ext4_mark_inode_dirty(handle, ea_inode);
 +
@@ -522,7 +532,7 @@ Index: linux-stage/fs/ext4/xattr.c
                        size_t offs = le16_to_cpu(last->e_value_offs);
                        if (offs < min_offs)
                                min_offs = offs;
                        size_t offs = le16_to_cpu(last->e_value_offs);
                        if (offs < min_offs)
                                min_offs = offs;
-@@ -628,16 +900,21 @@ ext4_xattr_set_entry(struct ext4_xattr_i
+@@ -628,16 +903,21 @@ ext4_xattr_set_entry(struct ext4_xattr_i
        }
        free = min_offs - ((void *)last - s->base) - sizeof(__u32);
        if (!s->not_found) {
        }
        free = min_offs - ((void *)last - s->base) - sizeof(__u32);
        if (!s->not_found) {
@@ -548,7 +558,7 @@ Index: linux-stage/fs/ext4/xattr.c
                        return -ENOSPC;
        }
  
                        return -ENOSPC;
        }
  
-@@ -651,7 +928,8 @@ ext4_xattr_set_entry(struct ext4_xattr_i
+@@ -651,7 +931,8 @@ ext4_xattr_set_entry(struct ext4_xattr_i
                s->here->e_name_len = name_len;
                memcpy(s->here->e_name, i->name, name_len);
        } else {
                s->here->e_name_len = name_len;
                memcpy(s->here->e_name, i->name, name_len);
        } else {
@@ -558,7 +568,7 @@ Index: linux-stage/fs/ext4/xattr.c
                        void *first_val = s->base + min_offs;
                        size_t offs = le16_to_cpu(s->here->e_value_offs);
                        void *val = s->base + offs;
                        void *first_val = s->base + min_offs;
                        size_t offs = le16_to_cpu(s->here->e_value_offs);
                        void *val = s->base + offs;
-@@ -685,13 +963,17 @@ ext4_xattr_set_entry(struct ext4_xattr_i
+@@ -685,13 +966,17 @@ ext4_xattr_set_entry(struct ext4_xattr_i
                        last = s->first;
                        while (!IS_LAST_ENTRY(last)) {
                                size_t o = le16_to_cpu(last->e_value_offs);
                        last = s->first;
                        while (!IS_LAST_ENTRY(last)) {
                                size_t o = le16_to_cpu(last->e_value_offs);
@@ -578,7 +588,7 @@ Index: linux-stage/fs/ext4/xattr.c
                if (!i->value) {
                        /* Remove the old name. */
                        size_t size = EXT4_XATTR_LEN(name_len);
                if (!i->value) {
                        /* Remove the old name. */
                        size_t size = EXT4_XATTR_LEN(name_len);
-@@ -705,10 +987,17 @@ ext4_xattr_set_entry(struct ext4_xattr_i
+@@ -705,10 +990,17 @@ ext4_xattr_set_entry(struct ext4_xattr_i
        if (i->value) {
                /* Insert the new value. */
                s->here->e_value_size = cpu_to_le32(i->value_len);
        if (i->value) {
                /* Insert the new value. */
                s->here->e_value_size = cpu_to_le32(i->value_len);
@@ -597,7 +607,7 @@ Index: linux-stage/fs/ext4/xattr.c
                        if (i->value == EXT4_ZERO_XATTR_VALUE) {
                                memset(val, 0, size);
                        } else {
                        if (i->value == EXT4_ZERO_XATTR_VALUE) {
                                memset(val, 0, size);
                        } else {
-@@ -758,7 +1047,7 @@ ext4_xattr_block_find(struct inode *inod
+@@ -758,7 +1050,7 @@ ext4_xattr_block_find(struct inode *inod
                bs->s.end = bs->bh->b_data + bs->bh->b_size;
                bs->s.here = bs->s.first;
                error = ext4_xattr_find_entry(&bs->s.here, i->name_index,
                bs->s.end = bs->bh->b_data + bs->bh->b_size;
                bs->s.here = bs->s.first;
                error = ext4_xattr_find_entry(&bs->s.here, i->name_index,
@@ -606,7 +616,7 @@ Index: linux-stage/fs/ext4/xattr.c
                if (error && error != -ENODATA)
                        goto cleanup;
                bs->s.not_found = error;
                if (error && error != -ENODATA)
                        goto cleanup;
                bs->s.not_found = error;
-@@ -782,8 +1071,6 @@ ext4_xattr_block_set(handle_t *handle, s
+@@ -782,8 +1074,6 @@ ext4_xattr_block_set(handle_t *handle, s
  
  #define header(x) ((struct ext4_xattr_header *)(x))
  
  
  #define header(x) ((struct ext4_xattr_header *)(x))
  
@@ -615,7 +625,7 @@ Index: linux-stage/fs/ext4/xattr.c
        if (s->base) {
                ce = mb_cache_entry_get(ext4_xattr_cache, bs->bh->b_bdev,
                                        bs->bh->b_blocknr);
        if (s->base) {
                ce = mb_cache_entry_get(ext4_xattr_cache, bs->bh->b_bdev,
                                        bs->bh->b_blocknr);
-@@ -799,7 +1086,7 @@ ext4_xattr_block_set(handle_t *handle, s
+@@ -799,7 +1089,7 @@ ext4_xattr_block_set(handle_t *handle, s
                                ce = NULL;
                        }
                        ea_bdebug(bs->bh, "modifying in-place");
                                ce = NULL;
                        }
                        ea_bdebug(bs->bh, "modifying in-place");
@@ -624,7 +634,7 @@ Index: linux-stage/fs/ext4/xattr.c
                        if (!error) {
                                if (!IS_LAST_ENTRY(s->first))
                                        ext4_xattr_rehash(header(s->base),
                        if (!error) {
                                if (!IS_LAST_ENTRY(s->first))
                                        ext4_xattr_rehash(header(s->base),
-@@ -850,7 +1137,7 @@ ext4_xattr_block_set(handle_t *handle, s
+@@ -850,7 +1140,7 @@ ext4_xattr_block_set(handle_t *handle, s
                s->end = s->base + sb->s_blocksize;
        }
  
                s->end = s->base + sb->s_blocksize;
        }
  
@@ -633,7 +643,7 @@ Index: linux-stage/fs/ext4/xattr.c
        if (error == -EIO)
                goto bad_block;
        if (error)
        if (error == -EIO)
                goto bad_block;
        if (error)
-@@ -1000,7 +1287,7 @@ int ext4_xattr_ibody_find(struct inode *
+@@ -1000,7 +1290,7 @@ int ext4_xattr_ibody_find(struct inode *
                /* Find the named attribute. */
                error = ext4_xattr_find_entry(&is->s.here, i->name_index,
                                              i->name, is->s.end -
                /* Find the named attribute. */
                error = ext4_xattr_find_entry(&is->s.here, i->name_index,
                                              i->name, is->s.end -
@@ -642,7 +652,7 @@ Index: linux-stage/fs/ext4/xattr.c
                if (error && error != -ENODATA)
                        return error;
                is->s.not_found = error;
                if (error && error != -ENODATA)
                        return error;
                is->s.not_found = error;
-@@ -1018,7 +1305,7 @@ int ext4_xattr_ibody_inline_set(handle_t
+@@ -1018,7 +1308,7 @@ int ext4_xattr_ibody_inline_set(handle_t
  
        if (EXT4_I(inode)->i_extra_isize == 0)
                return -ENOSPC;
  
        if (EXT4_I(inode)->i_extra_isize == 0)
                return -ENOSPC;
@@ -651,7 +661,7 @@ Index: linux-stage/fs/ext4/xattr.c
        if (error) {
                if (error == -ENOSPC &&
                    ext4_has_inline_data(inode)) {
        if (error) {
                if (error == -ENOSPC &&
                    ext4_has_inline_data(inode)) {
-@@ -1030,7 +1317,7 @@ int ext4_xattr_ibody_inline_set(handle_t
+@@ -1030,7 +1320,7 @@ int ext4_xattr_ibody_inline_set(handle_t
                        error = ext4_xattr_ibody_find(inode, i, is);
                        if (error)
                                return error;
                        error = ext4_xattr_ibody_find(inode, i, is);
                        if (error)
                                return error;
@@ -660,7 +670,7 @@ Index: linux-stage/fs/ext4/xattr.c
                }
                if (error)
                        return error;
                }
                if (error)
                        return error;
-@@ -1056,7 +1343,7 @@ static int ext4_xattr_ibody_set(handle_t
+@@ -1056,7 +1346,7 @@ static int ext4_xattr_ibody_set(handle_t
  
        if (EXT4_I(inode)->i_extra_isize == 0)
                return -ENOSPC;
  
        if (EXT4_I(inode)->i_extra_isize == 0)
                return -ENOSPC;
@@ -669,7 +679,7 @@ Index: linux-stage/fs/ext4/xattr.c
        if (error)
                return error;
        header = IHDR(inode, ext4_raw_inode(&is->iloc));
        if (error)
                return error;
        header = IHDR(inode, ext4_raw_inode(&is->iloc));
-@@ -1092,7 +1379,7 @@ ext4_xattr_set_handle(handle_t *handle,
+@@ -1092,7 +1382,7 @@ ext4_xattr_set_handle(handle_t *handle, 
                .name = name,
                .value = value,
                .value_len = value_len,
                .name = name,
                .value = value,
                .value_len = value_len,
@@ -678,7 +688,7 @@ Index: linux-stage/fs/ext4/xattr.c
        };
        struct ext4_xattr_ibody_find is = {
                .s = { .not_found = -ENODATA, },
        };
        struct ext4_xattr_ibody_find is = {
                .s = { .not_found = -ENODATA, },
-@@ -1157,6 +1444,15 @@ ext4_xattr_set_handle(handle_t *handle,
+@@ -1157,6 +1447,15 @@ ext4_xattr_set_handle(handle_t *handle, 
                                        goto cleanup;
                        }
                        error = ext4_xattr_block_set(handle, inode, &i, &bs);
                                        goto cleanup;
                        }
                        error = ext4_xattr_block_set(handle, inode, &i, &bs);
@@ -694,7 +704,7 @@ Index: linux-stage/fs/ext4/xattr.c
                        if (error)
                                goto cleanup;
                        if (!is.s.not_found) {
                        if (error)
                                goto cleanup;
                        if (!is.s.not_found) {
-@@ -1203,9 +1499,22 @@ ext4_xattr_set(struct inode *inode, int
+@@ -1203,9 +1502,22 @@ ext4_xattr_set(struct inode *inode, int 
               const void *value, size_t value_len, int flags)
  {
        handle_t *handle;
               const void *value, size_t value_len, int flags)
  {
        handle_t *handle;
@@ -717,7 +727,7 @@ Index: linux-stage/fs/ext4/xattr.c
  retry:
        handle = ext4_journal_start(inode, EXT4_HT_XATTR, credits);
        if (IS_ERR(handle)) {
  retry:
        handle = ext4_journal_start(inode, EXT4_HT_XATTR, credits);
        if (IS_ERR(handle)) {
-@@ -1217,7 +1526,7 @@ retry:
+@@ -1217,7 +1529,7 @@ retry:
                                              value, value_len, flags);
                error2 = ext4_journal_stop(handle);
                if (error == -ENOSPC &&
                                              value, value_len, flags);
                error2 = ext4_journal_stop(handle);
                if (error == -ENOSPC &&
@@ -726,7 +736,7 @@ Index: linux-stage/fs/ext4/xattr.c
                        goto retry;
                if (error == 0)
                        error = error2;
                        goto retry;
                if (error == 0)
                        error = error2;
-@@ -1239,7 +1548,7 @@ static void ext4_xattr_shift_entries(str
+@@ -1239,7 +1551,7 @@ static void ext4_xattr_shift_entries(str
  
        /* Adjust the value offsets of the entries */
        for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) {
  
        /* Adjust the value offsets of the entries */
        for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) {
@@ -735,7 +745,7 @@ Index: linux-stage/fs/ext4/xattr.c
                        new_offs = le16_to_cpu(last->e_value_offs) +
                                                        value_offs_shift;
                        BUG_ON(new_offs + le32_to_cpu(last->e_value_size)
                        new_offs = le16_to_cpu(last->e_value_offs) +
                                                        value_offs_shift;
                        BUG_ON(new_offs + le32_to_cpu(last->e_value_size)
-@@ -1477,21 +1786,135 @@ cleanup:
+@@ -1477,21 +1789,135 @@ cleanup:
  }
  
  
  }
  
  
@@ -876,7 +886,7 @@ Index: linux-stage/fs/ext4/xattr.c
        bh = sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl);
        if (!bh) {
                EXT4_ERROR_INODE(inode, "block %llu read error",
        bh = sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl);
        if (!bh) {
                EXT4_ERROR_INODE(inode, "block %llu read error",
-@@ -1504,11 +1927,69 @@ ext4_xattr_delete_inode(handle_t *handle
+@@ -1504,11 +1930,69 @@ ext4_xattr_delete_inode(handle_t *handle
                                 EXT4_I(inode)->i_file_acl);
                goto cleanup;
        }
                                 EXT4_I(inode)->i_file_acl);
                goto cleanup;
        }
@@ -946,7 +956,7 @@ Index: linux-stage/fs/ext4/xattr.c
  }
  
  /*
  }
  
  /*
-@@ -1578,10 +2059,9 @@ ext4_xattr_cmp(struct ext4_xattr_header
+@@ -1578,10 +2062,9 @@ ext4_xattr_cmp(struct ext4_xattr_header 
                    entry1->e_name_index != entry2->e_name_index ||
                    entry1->e_name_len != entry2->e_name_len ||
                    entry1->e_value_size != entry2->e_value_size ||
                    entry1->e_name_index != entry2->e_name_index ||
                    entry1->e_name_len != entry2->e_name_len ||
                    entry1->e_value_size != entry2->e_value_size ||
@@ -958,7 +968,7 @@ Index: linux-stage/fs/ext4/xattr.c
                if (memcmp((char *)header1 + le16_to_cpu(entry1->e_value_offs),
                           (char *)header2 + le16_to_cpu(entry2->e_value_offs),
                           le32_to_cpu(entry1->e_value_size)))
                if (memcmp((char *)header1 + le16_to_cpu(entry1->e_value_offs),
                           (char *)header2 + le16_to_cpu(entry2->e_value_offs),
                           le32_to_cpu(entry1->e_value_size)))
-@@ -1665,7 +2145,7 @@ static inline void ext4_xattr_hash_entry
+@@ -1665,7 +2148,7 @@ static inline void ext4_xattr_hash_entry
                       *name++;
        }
  
                       *name++;
        }