Whamcloud - gitweb
LU-6722 ldiskfs: fix credits at ldiskfs_delete_inode
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / sles12 / ext4-large-eas.patch
index 8ff7f93..2820da2 100644 (file)
@@ -20,7 +20,7 @@ Index: linux-stage/fs/ext4/ext4.h
  #define EXT4_MMP_MAX_CHECK_INTERVAL   300UL
  
  /*
-+ * Maximum size of xattr attributes for FEATURE_INCOMPAT_EA_INODE 1Mb
++ * Maximum size of xattr attributes for FEATURE_INCOMPAT_EA_INODE 1MB
 + * This limit is arbitrary, but is reasonable for the xattr API.
 + */
 +#define EXT4_XATTR_MAX_LARGE_EA_SIZE    (1024 * 1024)
@@ -81,17 +81,12 @@ Index: linux-stage/fs/ext4/inode.c
        if (IS_ERR(handle)) {
                ext4_std_error(inode->i_sb, PTR_ERR(handle));
                /*
-@@ -248,9 +248,36 @@ void ext4_evict_inode(struct inode *inod
-               sb_end_intwrite(inode->i_sb);
-               goto no_delete;
-       }
--
+@@ -251,6 +251,32 @@ void ext4_evict_inode(struct inode *inod
        if (IS_SYNC(inode))
                ext4_handle_sync(handle);
 +
-+      /*
-+       * Delete xattr inode before deleting the main inode.
-+       */
++      /* Delete xattr inode before deleting the main inode. */
 +      err = ext4_xattr_delete_inode(handle, inode, &lea_ino_array);
 +      if (err) {
 +              ext4_warning(inode->i_sb,
@@ -119,11 +114,22 @@ Index: linux-stage/fs/ext4/inode.c
        inode->i_size = 0;
        err = ext4_mark_inode_dirty(handle, inode);
        if (err) {
-@@ -305,8 +332,12 @@ void ext4_evict_inode(struct inode *inod
-               ext4_clear_inode(inode);
-       else
+@@ -269,10 +296,10 @@ void ext4_evict_inode(struct inode *inod
+        * enough credits left in the handle to remove the inode from
+        * the orphan list and set the dtime field.
+        */
+-      if (!ext4_handle_has_enough_credits(handle, 3)) {
+-              err = ext4_journal_extend(handle, 3);
++      if (!ext4_handle_has_enough_credits(handle, extra_credits)) {
++              err = ext4_journal_extend(handle, extra_credits);
+               if (err > 0)
+-                      err = ext4_journal_restart(handle, 3);
++                      err = ext4_journal_restart(handle, extra_credits);
+               if (err != 0) {
+                       ext4_warning(inode->i_sb,
+                                    "couldn't extend journal (err %d)", err);
+@@ -307,6 +334,9 @@ void ext4_evict_inode(struct inode *inod
                ext4_free_inode(handle, inode);
-+
        ext4_journal_stop(handle);
        sb_end_intwrite(inode->i_sb);
 +
@@ -132,7 +138,7 @@ Index: linux-stage/fs/ext4/inode.c
        return;
  no_delete:
        ext4_clear_inode(inode);        /* We must guarantee clearing of inode... */
-@@ -4777,7 +4808,7 @@ static int ext4_index_trans_blocks(struc
+@@ -4777,7 +4807,7 @@ static int ext4_index_trans_blocks(struc
   *
   * Also account for superblock, inode, quota and xattr blocks
   */
@@ -145,6 +151,14 @@ Index: linux-stage/fs/ext4/xattr.c
 ===================================================================
 --- linux-stage.orig/fs/ext4/xattr.c
 +++ linux-stage/fs/ext4/xattr.c
+@@ -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 +233,26 @@ ext4_xattr_check_block(struct inode *ino
  }
  
@@ -156,11 +170,10 @@ Index: linux-stage/fs/ext4/xattr.c
        size_t value_size = le32_to_cpu(entry->e_value_size);
  
 -      if (entry->e_value_block != 0 || value_size > size ||
--          le16_to_cpu(entry->e_value_offs) + value_size > size)
-+      if ((entry->e_value_inum == 0) &&
-+         (le16_to_cpu(entry->e_value_offs) + value_size > size))
++      if (!entry->e_value_inum &&
+           le16_to_cpu(entry->e_value_offs) + value_size > size)
 +              return -EIO;
-+      if (entry->e_value_inum != 0 &&
++      if (entry->e_value_inum &&
 +          (le32_to_cpu(entry->e_value_inum) < EXT4_FIRST_INO(inode->i_sb) ||
 +           le32_to_cpu(entry->e_value_inum) >
 +           le32_to_cpu(EXT4_SB(inode->i_sb)->s_es->s_inodes_count)))
@@ -176,7 +189,7 @@ Index: linux-stage/fs/ext4/xattr.c
  {
        struct ext4_xattr_entry *entry;
        size_t name_len;
-@@ -265,11 +272,103 @@ ext4_xattr_find_entry(struct ext4_xattr_
+@@ -265,11 +272,109 @@ ext4_xattr_find_entry(struct ext4_xattr_
                        break;
        }
        *pentry = entry;
@@ -189,8 +202,7 @@ Index: linux-stage/fs/ext4/xattr.c
 +/*
 + * Read the EA value from an inode.
 + */
-+static int
-+ext4_xattr_inode_read(struct inode *ea_inode, void *buf, size_t *size)
++static int ext4_xattr_inode_read(struct inode *ea_inode, void *buf, size_t *size)
 +{
 +      unsigned long block = 0;
 +      struct buffer_head *bh = NULL;
@@ -223,28 +235,36 @@ Index: linux-stage/fs/ext4/xattr.c
 +      return err;
 +}
 +
-+struct inode *ext4_xattr_inode_iget(struct inode *parent, int ea_ino, int *err)
++/*
++ * Fetch the xattr inode from disk.
++ *
++ * The xattr inode stores the parent inode number and generation so that
++ * the kernel and e2fsck can verify the xattr inode is valid upon access.
++ */
++struct inode *ext4_xattr_inode_iget(struct inode *parent,
++                                  unsigned long ea_ino, int *err)
 +{
 +      struct inode *ea_inode = NULL;
 +
 +      ea_inode = ext4_iget(parent->i_sb, ea_ino);
 +      if (IS_ERR(ea_inode) || is_bad_inode(ea_inode)) {
-+              ext4_error(parent->i_sb, "error while reading EA inode %d",
-+                         ea_ino);
-+              *err = -EIO;
++              int rc = IS_ERR(ea_inode) ? PTR_ERR(ea_inode) : 0;
++              ext4_error(parent->i_sb, "error while reading EA inode %lu "
++                         "/ %d %d", ea_ino, rc, is_bad_inode(ea_inode));
++              *err = rc != 0 ? rc : -EIO;
 +              return NULL;
 +      }
 +
-+      if (ea_inode->i_xattr_inode_parent != parent->i_ino ||
++      if (EXT4_XATTR_INODE_GET_PARENT(ea_inode) != parent->i_ino ||
 +          ea_inode->i_generation != parent->i_generation) {
-+              ext4_error(parent->i_sb, "Backpointer from EA inode %d "
++              ext4_error(parent->i_sb, "Backpointer from EA inode %lu "
 +                         "to parent invalid.", ea_ino);
 +              *err = -EINVAL;
 +              goto error;
 +      }
 +
 +      if (!(EXT4_I(ea_inode)->i_flags & EXT4_EA_INODE_FL)) {
-+              ext4_error(parent->i_sb, "EA inode %d does not have "
++              ext4_error(parent->i_sb, "EA inode %lu does not have "
 +                         "EXT4_EA_INODE_FL flag set.\n", ea_ino);
 +              *err = -EINVAL;
 +              goto error;
@@ -261,9 +281,8 @@ Index: linux-stage/fs/ext4/xattr.c
 +/*
 + * Read the value from the EA inode.
 + */
-+static int
-+ext4_xattr_inode_get(struct inode *inode, int ea_ino, void *buffer,
-+                   size_t *size)
++static int ext4_xattr_inode_get(struct inode *inode, unsigned long ea_ino,
++                              void *buffer, size_t *size)
 +{
 +      struct inode *ea_inode = NULL;
 +      int err;
@@ -297,7 +316,7 @@ Index: linux-stage/fs/ext4/xattr.c
                        goto cleanup;
 -              memcpy(buffer, bh->b_data + le16_to_cpu(entry->e_value_offs),
 -                     size);
-+              if (entry->e_value_inum != 0) {
++              if (entry->e_value_inum) {
 +                      error = ext4_xattr_inode_get(inode,
 +                                           le32_to_cpu(entry->e_value_inum),
 +                                           buffer, &size);
@@ -325,7 +344,7 @@ Index: linux-stage/fs/ext4/xattr.c
                        goto cleanup;
 -              memcpy(buffer, (void *)IFIRST(header) +
 -                     le16_to_cpu(entry->e_value_offs), size);
-+              if (entry->e_value_inum != 0) {
++              if (entry->e_value_inum) {
 +                      error = ext4_xattr_inode_get(inode,
 +                                           le32_to_cpu(entry->e_value_inum),
 +                                           buffer, &size);
@@ -343,7 +362,7 @@ Index: linux-stage/fs/ext4/xattr.c
        for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) {
                *total += EXT4_XATTR_LEN(last->e_name_len);
 -              if (!last->e_value_block && last->e_value_size) {
-+              if (last->e_value_inum == 0 && last->e_value_size > 0) {
++              if (!last->e_value_inum && last->e_value_size) {
                        size_t offs = le16_to_cpu(last->e_value_offs);
                        if (offs < *min_offs)
                                *min_offs = offs;
@@ -448,7 +467,7 @@ Index: linux-stage/fs/ext4/xattr.c
 +               * A back-pointer from EA inode to parent inode will be useful
 +               * for e2fsck.
 +               */
-+              ea_inode->i_xattr_inode_parent = inode->i_ino;
++              EXT4_XATTR_INODE_SET_PARENT(ea_inode, inode->i_ino);
 +              unlock_new_inode(ea_inode);
 +      }
 +
@@ -459,7 +478,7 @@ Index: linux-stage/fs/ext4/xattr.c
 + * Unlink the inode storing the value of the EA.
 + */
 +int
-+ext4_xattr_inode_unlink(struct inode *inode, int ea_ino)
++ext4_xattr_inode_unlink(struct inode *inode, unsigned long ea_ino)
 +{
 +      struct inode *ea_inode = NULL;
 +      int err;
@@ -478,7 +497,7 @@ Index: linux-stage/fs/ext4/xattr.c
 + * Add value of the EA in an inode.
 + */
 +static int
-+ext4_xattr_inode_set(handle_t *handle, struct inode *inode, int *ea_ino,
++ext4_xattr_inode_set(handle_t *handle, struct inode *inode, unsigned long *ea_ino,
 +                   const void *value, size_t value_len)
 +{
 +      struct inode *ea_inode = NULL;
@@ -518,7 +537,7 @@ Index: linux-stage/fs/ext4/xattr.c
        last = s->first;
        for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) {
 -              if (!last->e_value_block && last->e_value_size) {
-+              if (last->e_value_inum == 0 && last->e_value_size > 0) {
++              if (!last->e_value_inum && last->e_value_size) {
                        size_t offs = le16_to_cpu(last->e_value_offs);
                        if (offs < min_offs)
                                min_offs = offs;
@@ -527,8 +546,8 @@ Index: linux-stage/fs/ext4/xattr.c
        free = min_offs - ((void *)last - s->base) - sizeof(__u32);
        if (!s->not_found) {
 -              if (!s->here->e_value_block && s->here->e_value_size) {
-+              if (!in_inode && s->here->e_value_inum == 0 &&
-+                  s->here->e_value_size > 0) {
++              if (!in_inode &&
++                  !s->here->e_value_inum && s->here->e_value_size) {
                        size_t size = le32_to_cpu(s->here->e_value_size);
                        free += EXT4_XATTR_SIZE(size);
                }
@@ -553,8 +572,8 @@ Index: linux-stage/fs/ext4/xattr.c
                memcpy(s->here->e_name, i->name, name_len);
        } else {
 -              if (!s->here->e_value_block && s->here->e_value_size) {
-+              if (s->here->e_value_offs > 0 && s->here->e_value_inum == 0 &&
-+                  s->here->e_value_size > 0) {
++              if (!s->here->e_value_inum && s->here->e_value_size &&
++                  s->here->e_value_offs > 0) {
                        void *first_val = s->base + min_offs;
                        size_t offs = le16_to_cpu(s->here->e_value_offs);
                        void *val = s->base + offs;
@@ -570,7 +589,7 @@ Index: linux-stage/fs/ext4/xattr.c
                                last = EXT4_XATTR_NEXT(last);
                        }
                }
-+              if (s->here->e_value_inum != 0) {
++              if (s->here->e_value_inum) {
 +                      ext4_xattr_inode_unlink(inode,
 +                                      le32_to_cpu(s->here->e_value_inum));
 +                      s->here->e_value_inum = 0;
@@ -584,7 +603,7 @@ Index: linux-stage/fs/ext4/xattr.c
                s->here->e_value_size = cpu_to_le32(i->value_len);
 -              if (i->value_len) {
 +              if (in_inode) {
-+                      int ea_ino = le32_to_cpu(s->here->e_value_inum);
++                      unsigned long ea_ino = le32_to_cpu(s->here->e_value_inum);
 +                      ext4_xattr_inode_set(handle, inode, &ea_ino, i->value,
 +                                           i->value_len);
 +                      s->here->e_value_inum = cpu_to_le32(ea_ino);
@@ -602,7 +621,7 @@ Index: linux-stage/fs/ext4/xattr.c
                bs->s.here = bs->s.first;
                error = ext4_xattr_find_entry(&bs->s.here, i->name_index,
 -                                            i->name, bs->bh->b_size, 1);
-+                                           i->name, bs->bh->b_size, 1, inode);
++                                            i->name, bs->bh->b_size, 1, inode);
                if (error && error != -ENODATA)
                        goto cleanup;
                bs->s.not_found = error;
@@ -731,7 +750,7 @@ Index: linux-stage/fs/ext4/xattr.c
        /* Adjust the value offsets of the entries */
        for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) {
 -              if (!last->e_value_block && last->e_value_size) {
-+              if (last->e_value_inum == 0 && last->e_value_size > 0) {
++              if (!last->e_value_inum && 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)
@@ -853,9 +872,9 @@ Index: linux-stage/fs/ext4/xattr.c
                goto cleanup;
 +      raw_inode = ext4_raw_inode(&iloc);
 +      header = IHDR(inode, raw_inode);
-+      entry = IFIRST(header);
-+      for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
-+              if (entry->e_value_inum == 0)
++      for (entry = IFIRST(header); !IS_LAST_ENTRY(entry);
++           entry = EXT4_XATTR_NEXT(entry)) {
++              if (!entry->e_value_inum)
 +                      continue;
 +              if (ext4_expand_ino_array(lea_ino_array,
 +                                        entry->e_value_inum) != 0) {
@@ -881,9 +900,9 @@ Index: linux-stage/fs/ext4/xattr.c
                goto cleanup;
        }
 +
-+      entry = BFIRST(bh);
-+      for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
-+              if (entry->e_value_inum == 0)
++      for (entry = BFIRST(bh); !IS_LAST_ENTRY(entry);
++           entry = EXT4_XATTR_NEXT(entry)) {
++              if (!entry->e_value_inum)
 +                      continue;
 +              if (ext4_expand_ino_array(lea_ino_array,
 +                                        entry->e_value_inum) != 0)
@@ -963,7 +982,7 @@ Index: linux-stage/fs/ext4/xattr.c
        }
  
 -      if (entry->e_value_block == 0 && entry->e_value_size != 0) {
-+      if (entry->e_value_inum == 0 && entry->e_value_size != 0) {
++      if (!entry->e_value_inum && entry->e_value_size) {
                __le32 *value = (__le32 *)((char *)header +
                        le16_to_cpu(entry->e_value_offs));
                for (n = (le32_to_cpu(entry->e_value_size) +
@@ -980,11 +999,22 @@ Index: linux-stage/fs/ext4/xattr.h
        __le32  e_value_size;   /* size of attribute value */
        __le32  e_hash;         /* hash value of name and value */
        char    e_name[0];      /* attribute name */
-@@ -67,6 +67,15 @@ struct ext4_xattr_entry {
+@@ -67,6 +67,26 @@ struct ext4_xattr_entry {
                EXT4_I(inode)->i_extra_isize))
  #define IFIRST(hdr) ((struct ext4_xattr_entry *)((hdr)+1))
  
-+#define i_xattr_inode_parent i_mtime.tv_sec
++/*
++ * Link EA inode back to parent one using i_mtime field.
++ * Extra integer type conversion added to ignore higher
++ * bits in i_mtime.tv_sec which might be set by ext4_get()
++ */
++#define EXT4_XATTR_INODE_SET_PARENT(inode, inum)      \
++do {                                                  \
++      (inode)->i_mtime.tv_sec = inum;                 \
++} while(0)
++
++#define EXT4_XATTR_INODE_GET_PARENT(inode)            \
++      ((__u32)(inode)->i_mtime.tv_sec)
 +
 +/*
 + * The minimum size of EA value when you start storing it in an external inode
@@ -1014,9 +1044,9 @@ Index: linux-stage/fs/ext4/xattr.h
  extern int ext4_xattr_set_handle(handle_t *, struct inode *, int, const char *, const void *, size_t, int);
  
 -extern void ext4_xattr_delete_inode(handle_t *, struct inode *);
-+extern struct inode *ext4_xattr_inode_iget(struct inode *parent, int ea_ino,
++extern struct inode *ext4_xattr_inode_iget(struct inode *parent, unsigned long ea_ino,
 +                                         int *err);
-+extern int ext4_xattr_inode_unlink(struct inode *inode, int ea_ino);
++extern int ext4_xattr_inode_unlink(struct inode *inode, unsigned long ea_ino);
 +extern int ext4_xattr_delete_inode(handle_t *handle, struct inode *inode,
 +                                 struct ext4_xattr_ino_array **array);
 +extern void ext4_xattr_inode_array_free(struct inode *inode,