]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
Merge tag 'for-linus-v4.13-2' of git://git.kernel.org/pub/scm/linux/kernel/git/jlayto...
authorLinus Torvalds <torvalds@linux-foundation.org>
Sat, 8 Jul 2017 02:38:17 +0000 (19:38 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 8 Jul 2017 02:38:17 +0000 (19:38 -0700)
Pull Writeback error handling updates from Jeff Layton:
 "This pile represents the bulk of the writeback error handling fixes
  that I have for this cycle. Some of the earlier patches in this pile
  may look trivial but they are prerequisites for later patches in the
  series.

  The aim of this set is to improve how we track and report writeback
  errors to userland. Most applications that care about data integrity
  will periodically call fsync/fdatasync/msync to ensure that their
  writes have made it to the backing store.

  For a very long time, we have tracked writeback errors using two flags
  in the address_space: AS_EIO and AS_ENOSPC. Those flags are set when a
  writeback error occurs (via mapping_set_error) and are cleared as a
  side-effect of filemap_check_errors (as you noted yesterday). This
  model really sucks for userland.

  Only the first task to call fsync (or msync or fdatasync) will see the
  error. Any subsequent task calling fsync on a file will get back 0
  (unless another writeback error occurs in the interim). If I have
  several tasks writing to a file and calling fsync to ensure that their
  writes got stored, then I need to have them coordinate with one
  another. That's difficult enough, but in a world of containerized
  setups that coordination may even not be possible.

  But wait...it gets worse!

  The calls to filemap_check_errors can be buried pretty far down in the
  call stack, and there are internal callers of filemap_write_and_wait
  and the like that also end up clearing those errors. Many of those
  callers ignore the error return from that function or return it to
  userland at nonsensical times (e.g. truncate() or stat()). If I get
  back -EIO on a truncate, there is no reason to think that it was
  because some previous writeback failed, and a subsequent fsync() will
  (incorrectly) return 0.

  This pile aims to do three things:

   1) ensure that when a writeback error occurs that that error will be
      reported to userland on a subsequent fsync/fdatasync/msync call,
      regardless of what internal callers are doing

   2) report writeback errors on all file descriptions that were open at
      the time that the error occurred. This is a user-visible change,
      but I think most applications are written to assume this behavior
      anyway. Those that aren't are unlikely to be hurt by it.

   3) document what filesystems should do when there is a writeback
      error. Today, there is very little consistency between them, and a
      lot of cargo-cult copying. We need to make it very clear what
      filesystems should do in this situation.

  To achieve this, the set adds a new data type (errseq_t) and then
  builds new writeback error tracking infrastructure around that. Once
  all of that is in place, we change the filesystems to use the new
  infrastructure for reporting wb errors to userland.

  Note that this is just the initial foray into cleaning up this mess.
  There is a lot of work remaining here:

   1) convert the rest of the filesystems in a similar fashion. Once the
      initial set is in, then I think most other fs' will be fairly
      simple to convert. Hopefully most of those can in via individual
      filesystem trees.

   2) convert internal waiters on writeback to use errseq_t for
      detecting errors instead of relying on the AS_* flags. I have some
      draft patches for this for ext4, but they are not quite ready for
      prime time yet.

  This was a discussion topic this year at LSF/MM too. If you're
  interested in the gory details, LWN has some good articles about this:

      https://lwn.net/Articles/718734/
      https://lwn.net/Articles/724307/"

* tag 'for-linus-v4.13-2' of git://git.kernel.org/pub/scm/linux/kernel/git/jlayton/linux:
  btrfs: minimal conversion to errseq_t writeback error reporting on fsync
  xfs: minimal conversion to errseq_t writeback error reporting
  ext4: use errseq_t based error handling for reporting data writeback errors
  fs: convert __generic_file_fsync to use errseq_t based reporting
  block: convert to errseq_t based writeback error tracking
  dax: set errors in mapping when writeback fails
  Documentation: flesh out the section in vfs.txt on storing and reporting writeback errors
  mm: set both AS_EIO/AS_ENOSPC and errseq_t in mapping_set_error
  fs: new infrastructure for writeback error handling and reporting
  lib: add errseq_t type and infrastructure for handling it
  mm: don't TestClearPageError in __filemap_fdatawait_range
  mm: clear AS_EIO/AS_ENOSPC when writeback initiation fails
  jbd2: don't clear and reset errors after waiting on writeback
  buffer: set errors in mapping at the time that the error occurs
  fs: check for writeback errors after syncing out buffers in generic_file_fsync
  buffer: use mapping_set_error instead of setting the flag
  mm: fix mapping_set_error call in me_pagecache_dirty

13 files changed:
1  2 
MAINTAINERS
fs/block_dev.c
fs/btrfs/file.c
fs/buffer.c
fs/dax.c
fs/gfs2/lops.c
fs/open.c
fs/xfs/xfs_file.c
include/linux/fs.h
include/linux/pagemap.h
lib/Makefile
mm/filemap.c
mm/memory-failure.c

diff --cc MAINTAINERS
Simple merge
diff --cc fs/block_dev.c
Simple merge
diff --cc fs/btrfs/file.c
Simple merge
diff --cc fs/buffer.c
Simple merge
diff --cc fs/dax.c
index b1cd18dcc17754354ac1fd7c880c8366547719a2,441280e15d5b8ee101f60cdc747a617d944bcecd..306c2b603fb8aa8845558a2bf8226523e5282cdb
+++ b/fs/dax.c
@@@ -855,10 -856,11 +855,12 @@@ int dax_writeback_mapping_range(struct 
  
                        ret = dax_writeback_one(bdev, dax_dev, mapping,
                                        indices[i], pvec.pages[i]);
-                       if (ret < 0)
+                       if (ret < 0) {
+                               mapping_set_error(mapping, ret);
                                goto out;
+                       }
                }
 +              start_index = indices[pvec.nr - 1] + 1;
        }
  out:
        put_dax(dax_dev);
diff --cc fs/gfs2/lops.c
Simple merge
diff --cc fs/open.c
Simple merge
Simple merge
index 978fb5966a2517b060bf9e64a9e2d7c6350da2c0,78b5c2901712ff07abbd549ca7c18d2183ac418e..0cfa47125d52472809c2ede29c3fcfae21a2b18c
@@@ -31,8 -30,7 +31,9 @@@
  #include <linux/percpu-rwsem.h>
  #include <linux/workqueue.h>
  #include <linux/delayed_call.h>
 +#include <linux/uuid.h>
+ #include <linux/errseq.h>
 +
  #include <asm/byteorder.h>
  #include <uapi/linux/fs.h>
  
@@@ -2536,11 -2516,9 +2539,11 @@@ extern int write_inode_now(struct inod
  extern int filemap_fdatawrite(struct address_space *);
  extern int filemap_flush(struct address_space *);
  extern int filemap_fdatawait(struct address_space *);
- extern void filemap_fdatawait_keep_errors(struct address_space *);
+ extern int filemap_fdatawait_keep_errors(struct address_space *mapping);
  extern int filemap_fdatawait_range(struct address_space *, loff_t lstart,
                                   loff_t lend);
 +extern bool filemap_range_has_page(struct address_space *, loff_t lstart,
 +                                loff_t lend);
  extern int filemap_write_and_wait(struct address_space *mapping);
  extern int filemap_write_and_wait_range(struct address_space *mapping,
                                        loff_t lstart, loff_t lend);
Simple merge
diff --cc lib/Makefile
Simple merge
diff --cc mm/filemap.c
index 2e906ef521431ec4d5758631448f13327bdc2665,d7a30aefee0d413c9d0726047b91c95f4bf8073f..3247b4208034723c82ad05f0ca4cc880cbdc91d9
@@@ -376,39 -386,7 +386,39 @@@ int filemap_flush(struct address_space 
  }
  EXPORT_SYMBOL(filemap_flush);
  
- static int __filemap_fdatawait_range(struct address_space *mapping,
 +/**
 + * filemap_range_has_page - check if a page exists in range.
 + * @mapping:           address space within which to check
 + * @start_byte:        offset in bytes where the range starts
 + * @end_byte:          offset in bytes where the range ends (inclusive)
 + *
 + * Find at least one page in the range supplied, usually used to check if
 + * direct writing in this range will trigger a writeback.
 + */
 +bool filemap_range_has_page(struct address_space *mapping,
 +                         loff_t start_byte, loff_t end_byte)
 +{
 +      pgoff_t index = start_byte >> PAGE_SHIFT;
 +      pgoff_t end = end_byte >> PAGE_SHIFT;
 +      struct pagevec pvec;
 +      bool ret;
 +
 +      if (end_byte < start_byte)
 +              return false;
 +
 +      if (mapping->nrpages == 0)
 +              return false;
 +
 +      pagevec_init(&pvec, 0);
 +      if (!pagevec_lookup(&pvec, mapping, index, 1))
 +              return false;
 +      ret = (pvec.pages[0]->index <= end);
 +      pagevec_release(&pvec);
 +      return ret;
 +}
 +EXPORT_SYMBOL(filemap_range_has_page);
 +
+ static void __filemap_fdatawait_range(struct address_space *mapping,
                                     loff_t start_byte, loff_t end_byte)
  {
        pgoff_t index = start_byte >> PAGE_SHIFT;
Simple merge