1. 12 1月, 2022 1 次提交
    • J
      select: Fix indefinitely sleeping task in poll_schedule_timeout() · 68514dac
      Jan Kara 提交于
      A task can end up indefinitely sleeping in do_select() ->
      poll_schedule_timeout() when the following race happens:
      
        TASK1 (thread1)             TASK2                   TASK1 (thread2)
        do_select()
          setup poll_wqueues table
          with 'fd'
                                    write data to 'fd'
                                      pollwake()
                                        table->triggered = 1
                                                            closes 'fd' thread1 is
                                                              waiting for
          poll_schedule_timeout()
            - sees table->triggered
            table->triggered = 0
            return -EINTR
          loop back in do_select()
      
      But at this point when TASK1 loops back, the fdget() in the setup of
      poll_wqueues fails.  So now so we never find 'fd' is ready for reading
      and sleep in poll_schedule_timeout() indefinitely.
      
      Treat an fd that got closed as a fd on which some event happened.  This
      makes sure cannot block indefinitely in do_select().
      
      Another option would be to return -EBADF in this case but that has a
      potential of subtly breaking applications that excercise this behavior
      and it happens to work for them.  So returning fd as active seems like a
      safer choice.
      Suggested-by: NLinus Torvalds <torvalds@linux-foundation.org>
      CC: stable@vger.kernel.org
      Signed-off-by: NJan Kara <jack@suse.cz>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      68514dac
  2. 11 1月, 2022 29 次提交
  3. 07 1月, 2022 10 次提交
    • Q
      btrfs: output more debug messages for uncommitted transaction · 36c86a9e
      Qu Wenruo 提交于
      Print extra information about how many dirty bytes an uncommitted
      has at the end of mount.
      Signed-off-by: NQu Wenruo <wqu@suse.com>
      Reviewed-by: NDavid Sterba <dsterba@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      36c86a9e
    • F
      btrfs: respect the max size in the header when activating swap file · c2f82263
      Filipe Manana 提交于
      If we extended the size of a swapfile after its header was created (by the
      mkswap utility) and then try to activate it, we will map the entire file
      when activating the swap file, instead of limiting to the max size defined
      in the swap file's header.
      
      Currently test case generic/643 from fstests fails because we do not
      respect that size limit defined in the swap file's header.
      
      So fix this by not mapping file ranges beyond the max size defined in the
      swap header.
      
      This is the same type of bug that iomap used to have, and was fixed in
      commit 36ca7943 ("mm/swap: consider max pages in
      iomap_swapfile_add_extent").
      
      Fixes: ed46ff3d ("Btrfs: support swap files")
      CC: stable@vger.kernel.org # 5.4+
      Reviewed-and-tested-by: Josef Bacik <josef@toxicpanda.com
      Signed-off-by: NFilipe Manana <fdmanana@suse.com>
      Reviewed-by: NDavid Sterba <dsterba@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      c2f82263
    • Y
      btrfs: fix argument list that the kdoc format and script verified · be8d1a2a
      Yang Li 提交于
      The warnings were found by running scripts/kernel-doc, which is
      caused by using 'make W=1'.
      
      fs/btrfs/extent_io.c:3210: warning: Function parameter or member
      'bio_ctrl' not described in 'btrfs_bio_add_page'
      fs/btrfs/extent_io.c:3210: warning: Excess function parameter 'bio'
      description in 'btrfs_bio_add_page'
      fs/btrfs/extent_io.c:3210: warning: Excess function parameter
      'prev_bio_flags' description in 'btrfs_bio_add_page'
      fs/btrfs/space-info.c:1602: warning: Excess function parameter 'root'
      description in 'btrfs_reserve_metadata_bytes'
      fs/btrfs/space-info.c:1602: warning: Function parameter or member
      'fs_info' not described in 'btrfs_reserve_metadata_bytes'
      
      Note: this is fixing only the warnings regarding parameter list, the
      first line is not strictly conforming to the kdoc format as the btrfs
      codebase does not stick to that and keeps the first line more free form
      (because it's only for internal use).
      Reported-by: NAbaci Robot <abaci@linux.alibaba.com>
      Signed-off-by: NYang Li <yang.lee@linux.alibaba.com>
      Reviewed-by: NDavid Sterba <dsterba@suse.com>
      [ add note ]
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      be8d1a2a
    • S
      btrfs: remove unnecessary parameter type from compression_decompress_bio · 4a9e803e
      Su Yue 提交于
      btrfs_decompress_bio, the only caller of compression_decompress_bio gets
      type from @CB and passes it to compression_decompress_bio.
      However, compression_decompress_bio can get compression type directly
      from @CB.
      
      So remove the parameter and access it through @CB.  No functional
      change.
      Reviewed-by: NQu Wenruo <wqu@suse.com>
      Signed-off-by: NSu Yue <l@damenly.su>
      Reviewed-by: NDavid Sterba <dsterba@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      4a9e803e
    • Q
      btrfs: selftests: dump extent io tree if extent-io-tree test failed · 856e4794
      Qu Wenruo 提交于
      When code modifying extent-io-tree get modified and got that selftest
      failed, it can take some time to pin down the cause.
      
      To make it easier to expose the problem, dump the extent io tree if the
      selftest failed.
      
      This can save developers debug time, especially since the selftest we
      can not use the trace events, thus have to manually add debug trace
      points.
      Reviewed-by: NJosef Bacik <josef@toxicpanda.com>
      Signed-off-by: NQu Wenruo <wqu@suse.com>
      Reviewed-by: NDavid Sterba <dsterba@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      856e4794
    • Q
      btrfs: scrub: cleanup the argument list of scrub_stripe() · 2ae8ae3d
      Qu Wenruo 提交于
      The argument list of btrfs_stripe() has similar problems of
      scrub_chunk():
      
      - Duplicated and ambiguous @base argument
        Can be fetched from btrfs_block_group::bg.
      
      - Ambiguous argument @length
        It's again device extent length
      
      - Ambiguous argument @num
        The instinctive guess would be mirror number, but in fact it's stripe
        index.
      
      Fix it by:
      
      - Remove @base parameter
      
      - Rename @length to @dev_extent_len
      
      - Rename @num to @stripe_index
      Signed-off-by: NQu Wenruo <wqu@suse.com>
      Reviewed-by: NDavid Sterba <dsterba@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      2ae8ae3d
    • Q
      btrfs: scrub: cleanup the argument list of scrub_chunk() · d04fbe19
      Qu Wenruo 提交于
      The argument list of scrub_chunk() has the following problems:
      
      - Duplicated @chunk_offset
        It is the same as btrfs_block_group::start.
      
      - Confusing @length
        The most instinctive guess is chunk length, and one may want to delete
        it, but the truth is, it's the device extent length.
      
      Fix this by:
      
      - Remove @chunk_offset
        Use btrfs_block_group::start instead.
      
      - Rename @length to @dev_extent_len
        Also rename the caller to remove the ambiguous naming.
      
      - Rename @cache to @bg
        The "_cache" suffix for btrfs_block_group has been removed for a while.
      Signed-off-by: NQu Wenruo <wqu@suse.com>
      Reviewed-by: NDavid Sterba <dsterba@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      d04fbe19
    • Q
      btrfs: remove reada infrastructure · f26c9238
      Qu Wenruo 提交于
      Currently there is only one user for btrfs metadata readahead, and
      that's scrub.
      
      But even for the single user, it's not providing the correct
      functionality it needs, as scrub needs reada for commit root, which
      current readahead can't provide. (Although it's pretty easy to add such
      feature).
      
      Despite this, there are some extra problems related to metadata
      readahead:
      
      - Duplicated feature with btrfs_path::reada
      
      - Partly duplicated feature of btrfs_fs_info::buffer_radix
        Btrfs already caches its metadata in buffer_radix, while readahead
        tries to read the tree block no matter if it's already cached.
      
      - Poor layer separation
        Metadata readahead works kinda at device level.
        This is definitely not the correct layer it should be, since metadata
        is at btrfs logical address space, it should not bother device at all.
      
        This brings extra chance for bugs to sneak in, while brings
        unnecessary complexity.
      
      - Dead code
        In the very beginning of scrub.c we have #undef DEBUG, rendering all
        the debug related code useless and unable to test.
      
      Thus here I purpose to remove the metadata readahead mechanism
      completely.
      
      [BENCHMARK]
      There is a full benchmark for the scrub performance difference using the
      old btrfs_reada_add() and btrfs_path::reada.
      
      For the worst case (no dirty metadata, slow HDD), there could be a 5%
      performance drop for scrub.
      For other cases (even SATA SSD), there is no distinguishable performance
      difference.
      
      The number is reported scrub speed, in MiB/s.
      The resolution is limited by the reported duration, which only has a
      resolution of 1 second.
      
      	Old		New		Diff
      SSD	455.3		466.332		+2.42%
      HDD	103.927 	98.012		-5.69%
      
      Comprehensive test methodology is in the cover letter of the patch.
      Signed-off-by: NQu Wenruo <wqu@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      f26c9238
    • Q
      btrfs: scrub: use btrfs_path::reada for extent tree readahead · dcf62b20
      Qu Wenruo 提交于
      For scrub, we trigger two readaheads for two trees, extent tree to get
      where to scrub, and csum tree to get the data checksum.
      
      For csum tree we already trigger readahead in
      btrfs_lookup_csums_range(), by setting path->reada.
      But for extent tree we don't have any path based readahead.
      
      Add the readahead for extent tree as well, so we can later remove the
      btrfs_reada_add() based readahead.
      Signed-off-by: NQu Wenruo <wqu@suse.com>
      Reviewed-by: NDavid Sterba <dsterba@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      dcf62b20
    • Q
      btrfs: scrub: remove the unnecessary path parameter for scrub_raid56_parity() · 2522dbe8
      Qu Wenruo 提交于
      In function scrub_stripe() we allocated two btrfs_path's, one @path for
      extent tree search and another @ppath for full stripe extent tree search
      for RAID56.
      
      This is totally umncessary, as the @ppath usage is completely inside
      scrub_raid56_parity(), thus we can move the path allocation into
      scrub_raid56_parity() completely.
      Signed-off-by: NQu Wenruo <wqu@suse.com>
      Reviewed-by: NDavid Sterba <dsterba@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      2522dbe8