License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 21:07:57 +07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2018-04-04 00:16:55 +07:00
|
|
|
|
|
|
|
#ifndef BTRFS_EXTENT_IO_H
|
|
|
|
#define BTRFS_EXTENT_IO_H
|
2008-01-25 04:13:08 +07:00
|
|
|
|
|
|
|
#include <linux/rbtree.h>
|
2017-03-03 15:55:19 +07:00
|
|
|
#include <linux/refcount.h>
|
2015-10-12 11:08:16 +07:00
|
|
|
#include "ulist.h"
|
2008-01-25 04:13:08 +07:00
|
|
|
|
|
|
|
/* bits for the extent state */
|
2015-01-15 01:52:13 +07:00
|
|
|
#define EXTENT_DIRTY (1U << 0)
|
|
|
|
#define EXTENT_WRITEBACK (1U << 1)
|
|
|
|
#define EXTENT_UPTODATE (1U << 2)
|
|
|
|
#define EXTENT_LOCKED (1U << 3)
|
|
|
|
#define EXTENT_NEW (1U << 4)
|
|
|
|
#define EXTENT_DELALLOC (1U << 5)
|
|
|
|
#define EXTENT_DEFRAG (1U << 6)
|
|
|
|
#define EXTENT_BOUNDARY (1U << 9)
|
|
|
|
#define EXTENT_NODATASUM (1U << 10)
|
2017-03-07 06:04:20 +07:00
|
|
|
#define EXTENT_CLEAR_META_RESV (1U << 11)
|
2015-01-15 01:52:13 +07:00
|
|
|
#define EXTENT_FIRST_DELALLOC (1U << 12)
|
|
|
|
#define EXTENT_NEED_WAIT (1U << 13)
|
|
|
|
#define EXTENT_DAMAGED (1U << 14)
|
|
|
|
#define EXTENT_NORESERVE (1U << 15)
|
2015-10-12 15:05:40 +07:00
|
|
|
#define EXTENT_QGROUP_RESERVED (1U << 16)
|
btrfs: update btrfs_space_info's bytes_may_use timely
This patch can fix some false ENOSPC errors, below test script can
reproduce one false ENOSPC error:
#!/bin/bash
dd if=/dev/zero of=fs.img bs=$((1024*1024)) count=128
dev=$(losetup --show -f fs.img)
mkfs.btrfs -f -M $dev
mkdir /tmp/mntpoint
mount $dev /tmp/mntpoint
cd /tmp/mntpoint
xfs_io -f -c "falloc 0 $((64*1024*1024))" testfile
Above script will fail for ENOSPC reason, but indeed fs still has free
space to satisfy this request. Please see call graph:
btrfs_fallocate()
|-> btrfs_alloc_data_chunk_ondemand()
| bytes_may_use += 64M
|-> btrfs_prealloc_file_range()
|-> btrfs_reserve_extent()
|-> btrfs_add_reserved_bytes()
| alloc_type is RESERVE_ALLOC_NO_ACCOUNT, so it does not
| change bytes_may_use, and bytes_reserved += 64M. Now
| bytes_may_use + bytes_reserved == 128M, which is greater
| than btrfs_space_info's total_bytes, false enospc occurs.
| Note, the bytes_may_use decrease operation will be done in
| end of btrfs_fallocate(), which is too late.
Here is another simple case for buffered write:
CPU 1 | CPU 2
|
|-> cow_file_range() |-> __btrfs_buffered_write()
|-> btrfs_reserve_extent() | |
| | |
| | |
| ..... | |-> btrfs_check_data_free_space()
| |
| |
|-> extent_clear_unlock_delalloc() |
In CPU 1, btrfs_reserve_extent()->find_free_extent()->
btrfs_add_reserved_bytes() do not decrease bytes_may_use, the decrease
operation will be delayed to be done in extent_clear_unlock_delalloc().
Assume in this case, btrfs_reserve_extent() reserved 128MB data, CPU2's
btrfs_check_data_free_space() tries to reserve 100MB data space.
If
100MB > data_sinfo->total_bytes - data_sinfo->bytes_used -
data_sinfo->bytes_reserved - data_sinfo->bytes_pinned -
data_sinfo->bytes_readonly - data_sinfo->bytes_may_use
btrfs_check_data_free_space() will try to allcate new data chunk or call
btrfs_start_delalloc_roots(), or commit current transaction in order to
reserve some free space, obviously a lot of work. But indeed it's not
necessary as long as decreasing bytes_may_use timely, we still have
free space, decreasing 128M from bytes_may_use.
To fix this issue, this patch chooses to update bytes_may_use for both
data and metadata in btrfs_add_reserved_bytes(). For compress path, real
extent length may not be equal to file content length, so introduce a
ram_bytes argument for btrfs_reserve_extent(), find_free_extent() and
btrfs_add_reserved_bytes(), it's becasue bytes_may_use is increased by
file content length. Then compress path can update bytes_may_use
correctly. Also now we can discard RESERVE_ALLOC_NO_ACCOUNT, RESERVE_ALLOC
and RESERVE_FREE.
As we know, usually EXTENT_DO_ACCOUNTING is used for error path. In
run_delalloc_nocow(), for inode marked as NODATACOW or extent marked as
PREALLOC, we also need to update bytes_may_use, but can not pass
EXTENT_DO_ACCOUNTING, because it also clears metadata reservation, so
here we introduce EXTENT_CLEAR_DATA_RESV flag to indicate btrfs_clear_bit_hook()
to update btrfs_space_info's bytes_may_use.
Meanwhile __btrfs_prealloc_file_range() will call
btrfs_free_reserved_data_space() internally for both sucessful and failed
path, btrfs_prealloc_file_range()'s callers does not need to call
btrfs_free_reserved_data_space() any more.
Signed-off-by: Wang Xiaoguang <wangxg.fnst@cn.fujitsu.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Chris Mason <clm@fb.com>
2016-07-25 14:51:40 +07:00
|
|
|
#define EXTENT_CLEAR_DATA_RESV (1U << 17)
|
Btrfs: fix reported number of inode blocks
Currently when there are buffered writes that were not yet flushed and
they fall within allocated ranges of the file (that is, not in holes or
beyond eof assuming there are no prealloc extents beyond eof), btrfs
simply reports an incorrect number of used blocks through the stat(2)
system call (or any of its variants), regardless of mount options or
inode flags (compress, compress-force, nodatacow). This is because the
number of blocks used that is reported is based on the current number
of bytes in the vfs inode plus the number of dealloc bytes in the btrfs
inode. The later covers bytes that both fall within allocated regions
of the file and holes.
Example scenarios where the number of reported blocks is wrong while the
buffered writes are not flushed:
$ mkfs.btrfs -f /dev/sdc
$ mount /dev/sdc /mnt/sdc
$ xfs_io -f -c "pwrite -S 0xaa 0 64K" /mnt/sdc/foo1
wrote 65536/65536 bytes at offset 0
64 KiB, 16 ops; 0.0000 sec (259.336 MiB/sec and 66390.0415 ops/sec)
$ sync
$ xfs_io -c "pwrite -S 0xbb 0 64K" /mnt/sdc/foo1
wrote 65536/65536 bytes at offset 0
64 KiB, 16 ops; 0.0000 sec (192.308 MiB/sec and 49230.7692 ops/sec)
# The following should have reported 64K...
$ du -h /mnt/sdc/foo1
128K /mnt/sdc/foo1
$ sync
# After flushing the buffered write, it now reports the correct value.
$ du -h /mnt/sdc/foo1
64K /mnt/sdc/foo1
$ xfs_io -f -c "falloc -k 0 128K" -c "pwrite -S 0xaa 0 64K" /mnt/sdc/foo2
wrote 65536/65536 bytes at offset 0
64 KiB, 16 ops; 0.0000 sec (520.833 MiB/sec and 133333.3333 ops/sec)
$ sync
$ xfs_io -c "pwrite -S 0xbb 64K 64K" /mnt/sdc/foo2
wrote 65536/65536 bytes at offset 65536
64 KiB, 16 ops; 0.0000 sec (260.417 MiB/sec and 66666.6667 ops/sec)
# The following should have reported 128K...
$ du -h /mnt/sdc/foo2
192K /mnt/sdc/foo2
$ sync
# After flushing the buffered write, it now reports the correct value.
$ du -h /mnt/sdc/foo2
128K /mnt/sdc/foo2
So the number of used file blocks is simply incorrect, unlike in other
filesystems such as ext4 and xfs for example, but only while the buffered
writes are not flushed.
Fix this by tracking the number of delalloc bytes that fall within holes
and beyond eof of a file, and use instead this new counter when reporting
the number of used blocks for an inode.
Another different problem that exists is that the delalloc bytes counter
is reset when writeback starts (by clearing the EXTENT_DEALLOC flag from
the respective range in the inode's iotree) and the vfs inode's bytes
counter is only incremented when writeback finishes (through
insert_reserved_file_extent()). Therefore while writeback is ongoing we
simply report a wrong number of blocks used by an inode if the write
operation covers a range previously unallocated. While this change does
not fix this problem, it does minimizes it a lot by shortening that time
window, as the new dealloc bytes counter (new_delalloc_bytes) is only
decremented when writeback finishes right before updating the vfs inode's
bytes counter. Fully fixing this second problem is not trivial and will
be addressed later by a different patch.
Signed-off-by: Filipe Manana <fdmanana@suse.com>
2017-04-03 16:45:46 +07:00
|
|
|
#define EXTENT_DELALLOC_NEW (1U << 18)
|
2015-01-15 01:52:13 +07:00
|
|
|
#define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK)
|
2017-03-07 06:04:20 +07:00
|
|
|
#define EXTENT_DO_ACCOUNTING (EXTENT_CLEAR_META_RESV | \
|
|
|
|
EXTENT_CLEAR_DATA_RESV)
|
2015-01-15 01:52:13 +07:00
|
|
|
#define EXTENT_CTLBITS (EXTENT_DO_ACCOUNTING | EXTENT_FIRST_DELALLOC)
|
2008-01-25 04:13:08 +07:00
|
|
|
|
2010-12-17 13:21:50 +07:00
|
|
|
/*
|
|
|
|
* flags for bio submission. The high bits indicate the compression
|
|
|
|
* type for this bio
|
|
|
|
*/
|
Btrfs: Add zlib compression support
This is a large change for adding compression on reading and writing,
both for inline and regular extents. It does some fairly large
surgery to the writeback paths.
Compression is off by default and enabled by mount -o compress. Even
when the -o compress mount option is not used, it is possible to read
compressed extents off the disk.
If compression for a given set of pages fails to make them smaller, the
file is flagged to avoid future compression attempts later.
* While finding delalloc extents, the pages are locked before being sent down
to the delalloc handler. This allows the delalloc handler to do complex things
such as cleaning the pages, marking them writeback and starting IO on their
behalf.
* Inline extents are inserted at delalloc time now. This allows us to compress
the data before inserting the inline extent, and it allows us to insert
an inline extent that spans multiple pages.
* All of the in-memory extent representations (extent_map.c, ordered-data.c etc)
are changed to record both an in-memory size and an on disk size, as well
as a flag for compression.
From a disk format point of view, the extent pointers in the file are changed
to record the on disk size of a given extent and some encoding flags.
Space in the disk format is allocated for compression encoding, as well
as encryption and a generic 'other' field. Neither the encryption or the
'other' field are currently used.
In order to limit the amount of data read for a single random read in the
file, the size of a compressed extent is limited to 128k. This is a
software only limit, the disk format supports u64 sized compressed extents.
In order to limit the ram consumed while processing extents, the uncompressed
size of a compressed extent is limited to 256k. This is a software only limit
and will be subject to tuning later.
Checksumming is still done on compressed extents, and it is done on the
uncompressed version of the data. This way additional encodings can be
layered on without having to figure out which encoding to checksum.
Compression happens at delalloc time, which is basically singled threaded because
it is usually done by a single pdflush thread. This makes it tricky to
spread the compression load across all the cpus on the box. We'll have to
look at parallel pdflush walks of dirty inodes at a later time.
Decompression is hooked into readpages and it does spread across CPUs nicely.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2008-10-30 01:49:59 +07:00
|
|
|
#define EXTENT_BIO_COMPRESSED 1
|
2010-12-17 13:21:50 +07:00
|
|
|
#define EXTENT_BIO_FLAG_SHIFT 16
|
Btrfs: Add zlib compression support
This is a large change for adding compression on reading and writing,
both for inline and regular extents. It does some fairly large
surgery to the writeback paths.
Compression is off by default and enabled by mount -o compress. Even
when the -o compress mount option is not used, it is possible to read
compressed extents off the disk.
If compression for a given set of pages fails to make them smaller, the
file is flagged to avoid future compression attempts later.
* While finding delalloc extents, the pages are locked before being sent down
to the delalloc handler. This allows the delalloc handler to do complex things
such as cleaning the pages, marking them writeback and starting IO on their
behalf.
* Inline extents are inserted at delalloc time now. This allows us to compress
the data before inserting the inline extent, and it allows us to insert
an inline extent that spans multiple pages.
* All of the in-memory extent representations (extent_map.c, ordered-data.c etc)
are changed to record both an in-memory size and an on disk size, as well
as a flag for compression.
From a disk format point of view, the extent pointers in the file are changed
to record the on disk size of a given extent and some encoding flags.
Space in the disk format is allocated for compression encoding, as well
as encryption and a generic 'other' field. Neither the encryption or the
'other' field are currently used.
In order to limit the amount of data read for a single random read in the
file, the size of a compressed extent is limited to 128k. This is a
software only limit, the disk format supports u64 sized compressed extents.
In order to limit the ram consumed while processing extents, the uncompressed
size of a compressed extent is limited to 256k. This is a software only limit
and will be subject to tuning later.
Checksumming is still done on compressed extents, and it is done on the
uncompressed version of the data. This way additional encodings can be
layered on without having to figure out which encoding to checksum.
Compression happens at delalloc time, which is basically singled threaded because
it is usually done by a single pdflush thread. This makes it tricky to
spread the compression load across all the cpus on the box. We'll have to
look at parallel pdflush walks of dirty inodes at a later time.
Decompression is hooked into readpages and it does spread across CPUs nicely.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2008-10-30 01:49:59 +07:00
|
|
|
|
Btrfs: Change btree locking to use explicit blocking points
Most of the btrfs metadata operations can be protected by a spinlock,
but some operations still need to schedule.
So far, btrfs has been using a mutex along with a trylock loop,
most of the time it is able to avoid going for the full mutex, so
the trylock loop is a big performance gain.
This commit is step one for getting rid of the blocking locks entirely.
btrfs_tree_lock takes a spinlock, and the code explicitly switches
to a blocking lock when it starts an operation that can schedule.
We'll be able get rid of the blocking locks in smaller pieces over time.
Tracing allows us to find the most common cause of blocking, so we
can start with the hot spots first.
The basic idea is:
btrfs_tree_lock() returns with the spin lock held
btrfs_set_lock_blocking() sets the EXTENT_BUFFER_BLOCKING bit in
the extent buffer flags, and then drops the spin lock. The buffer is
still considered locked by all of the btrfs code.
If btrfs_tree_lock gets the spinlock but finds the blocking bit set, it drops
the spin lock and waits on a wait queue for the blocking bit to go away.
Much of the code that needs to set the blocking bit finishes without actually
blocking a good percentage of the time. So, an adaptive spin is still
used against the blocking bit to avoid very high context switch rates.
btrfs_clear_lock_blocking() clears the blocking bit and returns
with the spinlock held again.
btrfs_tree_unlock() can be called on either blocking or spinning locks,
it does the right thing based on the blocking bit.
ctree.c has a helper function to set/clear all the locked buffers in a
path as blocking.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-02-04 21:25:08 +07:00
|
|
|
/* these are bit numbers for test/set bit */
|
|
|
|
#define EXTENT_BUFFER_UPTODATE 0
|
2009-03-13 22:00:37 +07:00
|
|
|
#define EXTENT_BUFFER_DIRTY 2
|
2011-03-17 00:42:43 +07:00
|
|
|
#define EXTENT_BUFFER_CORRUPT 3
|
2011-05-23 19:25:41 +07:00
|
|
|
#define EXTENT_BUFFER_READAHEAD 4 /* this got triggered by readahead */
|
2012-03-10 04:01:49 +07:00
|
|
|
#define EXTENT_BUFFER_TREE_REF 5
|
|
|
|
#define EXTENT_BUFFER_STALE 6
|
2012-03-13 20:38:00 +07:00
|
|
|
#define EXTENT_BUFFER_WRITEBACK 7
|
Btrfs: be aware of btree inode write errors to avoid fs corruption
While we have a transaction ongoing, the VM might decide at any time
to call btree_inode->i_mapping->a_ops->writepages(), which will start
writeback of dirty pages belonging to btree nodes/leafs. This call
might return an error or the writeback might finish with an error
before we attempt to commit the running transaction. If this happens,
we might have no way of knowing that such error happened when we are
committing the transaction - because the pages might no longer be
marked dirty nor tagged for writeback (if a subsequent modification
to the extent buffer didn't happen before the transaction commit) which
makes filemap_fdata[write|wait]_range unable to find such pages (even
if they're marked with SetPageError).
So if this happens we must abort the transaction, otherwise we commit
a super block with btree roots that point to btree nodes/leafs whose
content on disk is invalid - either garbage or the content of some
node/leaf from a past generation that got cowed or deleted and is no
longer valid (for this later case we end up getting error messages like
"parent transid verify failed on 10826481664 wanted 25748 found 29562"
when reading btree nodes/leafs from disk).
Note that setting and checking AS_EIO/AS_ENOSPC in the btree inode's
i_mapping would not be enough because we need to distinguish between
log tree extents (not fatal) vs non-log tree extents (fatal) and
because the next call to filemap_fdatawait_range() will catch and clear
such errors in the mapping - and that call might be from a log sync and
not from a transaction commit, which means we would not know about the
error at transaction commit time. Also, checking for the eb flag
EXTENT_BUFFER_IOERR at transaction commit time isn't done and would
not be completely reliable, as the eb might be removed from memory and
read back when trying to get it, which clears that flag right before
reading the eb's pages from disk, making us not know about the previous
write error.
Using the new 3 flags for the btree inode also makes us achieve the
goal of AS_EIO/AS_ENOSPC when writepages() returns success, started
writeback for all dirty pages and before filemap_fdatawait_range() is
called, the writeback for all dirty pages had already finished with
errors - because we were not using AS_EIO/AS_ENOSPC,
filemap_fdatawait_range() would return success, as it could not know
that writeback errors happened (the pages were no longer tagged for
writeback).
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Chris Mason <clm@fb.com>
2014-09-26 18:25:56 +07:00
|
|
|
#define EXTENT_BUFFER_READ_ERR 8 /* read IO error */
|
2018-06-27 20:38:24 +07:00
|
|
|
#define EXTENT_BUFFER_UNMAPPED 9
|
2013-12-13 22:41:51 +07:00
|
|
|
#define EXTENT_BUFFER_IN_TREE 10
|
Btrfs: be aware of btree inode write errors to avoid fs corruption
While we have a transaction ongoing, the VM might decide at any time
to call btree_inode->i_mapping->a_ops->writepages(), which will start
writeback of dirty pages belonging to btree nodes/leafs. This call
might return an error or the writeback might finish with an error
before we attempt to commit the running transaction. If this happens,
we might have no way of knowing that such error happened when we are
committing the transaction - because the pages might no longer be
marked dirty nor tagged for writeback (if a subsequent modification
to the extent buffer didn't happen before the transaction commit) which
makes filemap_fdata[write|wait]_range unable to find such pages (even
if they're marked with SetPageError).
So if this happens we must abort the transaction, otherwise we commit
a super block with btree roots that point to btree nodes/leafs whose
content on disk is invalid - either garbage or the content of some
node/leaf from a past generation that got cowed or deleted and is no
longer valid (for this later case we end up getting error messages like
"parent transid verify failed on 10826481664 wanted 25748 found 29562"
when reading btree nodes/leafs from disk).
Note that setting and checking AS_EIO/AS_ENOSPC in the btree inode's
i_mapping would not be enough because we need to distinguish between
log tree extents (not fatal) vs non-log tree extents (fatal) and
because the next call to filemap_fdatawait_range() will catch and clear
such errors in the mapping - and that call might be from a log sync and
not from a transaction commit, which means we would not know about the
error at transaction commit time. Also, checking for the eb flag
EXTENT_BUFFER_IOERR at transaction commit time isn't done and would
not be completely reliable, as the eb might be removed from memory and
read back when trying to get it, which clears that flag right before
reading the eb's pages from disk, making us not know about the previous
write error.
Using the new 3 flags for the btree inode also makes us achieve the
goal of AS_EIO/AS_ENOSPC when writepages() returns success, started
writeback for all dirty pages and before filemap_fdatawait_range() is
called, the writeback for all dirty pages had already finished with
errors - because we were not using AS_EIO/AS_ENOSPC,
filemap_fdatawait_range() would return success, as it could not know
that writeback errors happened (the pages were no longer tagged for
writeback).
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Chris Mason <clm@fb.com>
2014-09-26 18:25:56 +07:00
|
|
|
#define EXTENT_BUFFER_WRITE_ERR 11 /* write IO error */
|
Btrfs: Change btree locking to use explicit blocking points
Most of the btrfs metadata operations can be protected by a spinlock,
but some operations still need to schedule.
So far, btrfs has been using a mutex along with a trylock loop,
most of the time it is able to avoid going for the full mutex, so
the trylock loop is a big performance gain.
This commit is step one for getting rid of the blocking locks entirely.
btrfs_tree_lock takes a spinlock, and the code explicitly switches
to a blocking lock when it starts an operation that can schedule.
We'll be able get rid of the blocking locks in smaller pieces over time.
Tracing allows us to find the most common cause of blocking, so we
can start with the hot spots first.
The basic idea is:
btrfs_tree_lock() returns with the spin lock held
btrfs_set_lock_blocking() sets the EXTENT_BUFFER_BLOCKING bit in
the extent buffer flags, and then drops the spin lock. The buffer is
still considered locked by all of the btrfs code.
If btrfs_tree_lock gets the spinlock but finds the blocking bit set, it drops
the spin lock and waits on a wait queue for the blocking bit to go away.
Much of the code that needs to set the blocking bit finishes without actually
blocking a good percentage of the time. So, an adaptive spin is still
used against the blocking bit to avoid very high context switch rates.
btrfs_clear_lock_blocking() clears the blocking bit and returns
with the spinlock held again.
btrfs_tree_unlock() can be called on either blocking or spinning locks,
it does the right thing based on the blocking bit.
ctree.c has a helper function to set/clear all the locked buffers in a
path as blocking.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-02-04 21:25:08 +07:00
|
|
|
|
2017-02-10 22:41:05 +07:00
|
|
|
/* these are flags for __process_pages_contig */
|
2013-07-29 22:20:47 +07:00
|
|
|
#define PAGE_UNLOCK (1 << 0)
|
|
|
|
#define PAGE_CLEAR_DIRTY (1 << 1)
|
|
|
|
#define PAGE_SET_WRITEBACK (1 << 2)
|
|
|
|
#define PAGE_END_WRITEBACK (1 << 3)
|
|
|
|
#define PAGE_SET_PRIVATE2 (1 << 4)
|
2014-10-07 04:14:22 +07:00
|
|
|
#define PAGE_SET_ERROR (1 << 5)
|
2017-02-10 22:41:05 +07:00
|
|
|
#define PAGE_LOCK (1 << 6)
|
2009-10-08 22:27:10 +07:00
|
|
|
|
2008-01-25 04:13:08 +07:00
|
|
|
/*
|
|
|
|
* page->private values. Every page that is controlled by the extent
|
|
|
|
* map has page->private set to one.
|
|
|
|
*/
|
|
|
|
#define EXTENT_PAGE_PRIVATE 1
|
|
|
|
|
2016-09-23 07:24:20 +07:00
|
|
|
/*
|
|
|
|
* The extent buffer bitmap operations are done with byte granularity instead of
|
|
|
|
* word granularity for two reasons:
|
|
|
|
* 1. The bitmaps must be little-endian on disk.
|
|
|
|
* 2. Bitmap items are not guaranteed to be aligned to a word and therefore a
|
|
|
|
* single word in a bitmap may straddle two pages in the extent buffer.
|
|
|
|
*/
|
|
|
|
#define BIT_BYTE(nr) ((nr) / BITS_PER_BYTE)
|
|
|
|
#define BYTE_MASK ((1 << BITS_PER_BYTE) - 1)
|
|
|
|
#define BITMAP_FIRST_BYTE_MASK(start) \
|
|
|
|
((BYTE_MASK << ((start) & (BITS_PER_BYTE - 1))) & BYTE_MASK)
|
|
|
|
#define BITMAP_LAST_BYTE_MASK(nbits) \
|
|
|
|
(BYTE_MASK >> (-(nbits) & (BITS_PER_BYTE - 1)))
|
|
|
|
|
2008-01-29 21:59:12 +07:00
|
|
|
struct extent_state;
|
2012-03-27 08:57:36 +07:00
|
|
|
struct btrfs_root;
|
2017-02-20 18:51:03 +07:00
|
|
|
struct btrfs_inode;
|
2013-07-25 18:22:34 +07:00
|
|
|
struct btrfs_io_bio;
|
2016-02-11 19:24:13 +07:00
|
|
|
struct io_failure_record;
|
2008-01-29 21:59:12 +07:00
|
|
|
|
2017-07-06 06:41:23 +07:00
|
|
|
typedef blk_status_t (extent_submit_bio_hook_t)(void *private_data, struct bio *bio,
|
2016-06-06 02:31:54 +07:00
|
|
|
int mirror_num, unsigned long bio_flags,
|
|
|
|
u64 bio_offset);
|
2017-06-23 08:05:23 +07:00
|
|
|
|
|
|
|
typedef blk_status_t (extent_submit_bio_start_t)(void *private_data,
|
2018-03-08 19:47:33 +07:00
|
|
|
struct bio *bio, u64 bio_offset);
|
2017-06-23 08:05:23 +07:00
|
|
|
|
2008-01-25 04:13:08 +07:00
|
|
|
struct extent_io_ops {
|
2017-02-17 21:27:44 +07:00
|
|
|
/*
|
|
|
|
* The following callbacks must be allways defined, the function
|
|
|
|
* pointer will be called unconditionally.
|
|
|
|
*/
|
2008-04-16 22:14:51 +07:00
|
|
|
extent_submit_bio_hook_t *submit_bio_hook;
|
2017-02-17 21:27:44 +07:00
|
|
|
int (*readpage_end_io_hook)(struct btrfs_io_bio *io_bio, u64 phy_offset,
|
|
|
|
struct page *page, u64 start, u64 end,
|
|
|
|
int mirror);
|
2017-02-17 22:24:29 +07:00
|
|
|
int (*readpage_io_failed_hook)(struct page *page, int failed_mirror);
|
2017-02-17 21:27:44 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Optional hooks, called if the pointer is not NULL
|
|
|
|
*/
|
2017-05-05 22:57:13 +07:00
|
|
|
int (*fill_delalloc)(void *private_data, struct page *locked_page,
|
2017-02-17 21:27:44 +07:00
|
|
|
u64 start, u64 end, int *page_started,
|
2017-10-24 12:18:16 +07:00
|
|
|
unsigned long *nr_written,
|
|
|
|
struct writeback_control *wbc);
|
2017-02-17 21:27:44 +07:00
|
|
|
|
|
|
|
int (*writepage_start_hook)(struct page *page, u64 start, u64 end);
|
2017-02-17 21:18:32 +07:00
|
|
|
void (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
|
2008-07-17 23:53:50 +07:00
|
|
|
struct extent_state *state, int uptodate);
|
2017-05-05 22:57:13 +07:00
|
|
|
void (*set_bit_hook)(void *private_data, struct extent_state *state,
|
2015-01-15 01:52:13 +07:00
|
|
|
unsigned *bits);
|
2017-05-05 22:57:13 +07:00
|
|
|
void (*clear_bit_hook)(void *private_data,
|
2017-02-20 18:51:03 +07:00
|
|
|
struct extent_state *state,
|
|
|
|
unsigned *bits);
|
2017-05-05 22:57:13 +07:00
|
|
|
void (*merge_extent_hook)(void *private_data,
|
2011-07-21 23:56:09 +07:00
|
|
|
struct extent_state *new,
|
|
|
|
struct extent_state *other);
|
2017-05-05 22:57:13 +07:00
|
|
|
void (*split_extent_hook)(void *private_data,
|
2011-07-21 23:56:09 +07:00
|
|
|
struct extent_state *orig, u64 split);
|
2017-05-05 22:57:13 +07:00
|
|
|
void (*check_extent_io_range)(void *private_data, const char *caller,
|
|
|
|
u64 start, u64 end);
|
2008-01-25 04:13:08 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct extent_io_tree {
|
|
|
|
struct rb_root state;
|
2017-05-05 22:57:13 +07:00
|
|
|
void *private_data;
|
2008-01-25 04:13:08 +07:00
|
|
|
u64 dirty_bytes;
|
2012-03-13 20:38:00 +07:00
|
|
|
int track_uptodate;
|
2008-01-29 21:59:12 +07:00
|
|
|
spinlock_t lock;
|
2015-01-03 00:23:10 +07:00
|
|
|
const struct extent_io_ops *ops;
|
2008-01-25 04:13:08 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct extent_state {
|
|
|
|
u64 start;
|
|
|
|
u64 end; /* inclusive */
|
|
|
|
struct rb_node rb_node;
|
2009-09-12 03:12:44 +07:00
|
|
|
|
|
|
|
/* ADD NEW ELEMENTS AFTER THIS */
|
2008-01-25 04:13:08 +07:00
|
|
|
wait_queue_head_t wq;
|
2017-03-03 15:55:19 +07:00
|
|
|
refcount_t refs;
|
2015-01-15 01:52:13 +07:00
|
|
|
unsigned state;
|
2008-01-25 04:13:08 +07:00
|
|
|
|
2016-02-11 19:24:13 +07:00
|
|
|
struct io_failure_record *failrec;
|
2008-01-25 04:13:08 +07:00
|
|
|
|
2013-04-22 23:12:31 +07:00
|
|
|
#ifdef CONFIG_BTRFS_DEBUG
|
2008-03-27 03:24:23 +07:00
|
|
|
struct list_head leak_list;
|
2013-04-22 23:12:31 +07:00
|
|
|
#endif
|
2008-01-25 04:13:08 +07:00
|
|
|
};
|
|
|
|
|
2010-08-07 00:21:20 +07:00
|
|
|
#define INLINE_EXTENT_BUFFER_PAGES 16
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 19:29:47 +07:00
|
|
|
#define MAX_INLINE_EXTENT_BUFFER_SIZE (INLINE_EXTENT_BUFFER_PAGES * PAGE_SIZE)
|
2008-01-25 04:13:08 +07:00
|
|
|
struct extent_buffer {
|
|
|
|
u64 start;
|
|
|
|
unsigned long len;
|
Btrfs: Change btree locking to use explicit blocking points
Most of the btrfs metadata operations can be protected by a spinlock,
but some operations still need to schedule.
So far, btrfs has been using a mutex along with a trylock loop,
most of the time it is able to avoid going for the full mutex, so
the trylock loop is a big performance gain.
This commit is step one for getting rid of the blocking locks entirely.
btrfs_tree_lock takes a spinlock, and the code explicitly switches
to a blocking lock when it starts an operation that can schedule.
We'll be able get rid of the blocking locks in smaller pieces over time.
Tracing allows us to find the most common cause of blocking, so we
can start with the hot spots first.
The basic idea is:
btrfs_tree_lock() returns with the spin lock held
btrfs_set_lock_blocking() sets the EXTENT_BUFFER_BLOCKING bit in
the extent buffer flags, and then drops the spin lock. The buffer is
still considered locked by all of the btrfs code.
If btrfs_tree_lock gets the spinlock but finds the blocking bit set, it drops
the spin lock and waits on a wait queue for the blocking bit to go away.
Much of the code that needs to set the blocking bit finishes without actually
blocking a good percentage of the time. So, an adaptive spin is still
used against the blocking bit to avoid very high context switch rates.
btrfs_clear_lock_blocking() clears the blocking bit and returns
with the spinlock held again.
btrfs_tree_unlock() can be called on either blocking or spinning locks,
it does the right thing based on the blocking bit.
ctree.c has a helper function to set/clear all the locked buffers in a
path as blocking.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-02-04 21:25:08 +07:00
|
|
|
unsigned long bflags;
|
2013-12-17 01:24:27 +07:00
|
|
|
struct btrfs_fs_info *fs_info;
|
2012-03-10 04:01:49 +07:00
|
|
|
spinlock_t refs_lock;
|
2010-08-07 00:21:20 +07:00
|
|
|
atomic_t refs;
|
2012-03-13 20:38:00 +07:00
|
|
|
atomic_t io_pages;
|
2012-04-16 20:42:26 +07:00
|
|
|
int read_mirror;
|
2010-10-27 07:57:29 +07:00
|
|
|
struct rcu_head rcu_head;
|
2011-09-13 15:55:48 +07:00
|
|
|
pid_t lock_owner;
|
Btrfs: Change btree locking to use explicit blocking points
Most of the btrfs metadata operations can be protected by a spinlock,
but some operations still need to schedule.
So far, btrfs has been using a mutex along with a trylock loop,
most of the time it is able to avoid going for the full mutex, so
the trylock loop is a big performance gain.
This commit is step one for getting rid of the blocking locks entirely.
btrfs_tree_lock takes a spinlock, and the code explicitly switches
to a blocking lock when it starts an operation that can schedule.
We'll be able get rid of the blocking locks in smaller pieces over time.
Tracing allows us to find the most common cause of blocking, so we
can start with the hot spots first.
The basic idea is:
btrfs_tree_lock() returns with the spin lock held
btrfs_set_lock_blocking() sets the EXTENT_BUFFER_BLOCKING bit in
the extent buffer flags, and then drops the spin lock. The buffer is
still considered locked by all of the btrfs code.
If btrfs_tree_lock gets the spinlock but finds the blocking bit set, it drops
the spin lock and waits on a wait queue for the blocking bit to go away.
Much of the code that needs to set the blocking bit finishes without actually
blocking a good percentage of the time. So, an adaptive spin is still
used against the blocking bit to avoid very high context switch rates.
btrfs_clear_lock_blocking() clears the blocking bit and returns
with the spinlock held again.
btrfs_tree_unlock() can be called on either blocking or spinning locks,
it does the right thing based on the blocking bit.
ctree.c has a helper function to set/clear all the locked buffers in a
path as blocking.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-02-04 21:25:08 +07:00
|
|
|
|
2011-07-17 02:23:14 +07:00
|
|
|
/* count of read lock holders on the extent buffer */
|
|
|
|
atomic_t write_locks;
|
|
|
|
atomic_t read_locks;
|
|
|
|
atomic_t blocking_writers;
|
|
|
|
atomic_t blocking_readers;
|
|
|
|
atomic_t spinning_readers;
|
|
|
|
atomic_t spinning_writers;
|
Btrfs: be aware of btree inode write errors to avoid fs corruption
While we have a transaction ongoing, the VM might decide at any time
to call btree_inode->i_mapping->a_ops->writepages(), which will start
writeback of dirty pages belonging to btree nodes/leafs. This call
might return an error or the writeback might finish with an error
before we attempt to commit the running transaction. If this happens,
we might have no way of knowing that such error happened when we are
committing the transaction - because the pages might no longer be
marked dirty nor tagged for writeback (if a subsequent modification
to the extent buffer didn't happen before the transaction commit) which
makes filemap_fdata[write|wait]_range unable to find such pages (even
if they're marked with SetPageError).
So if this happens we must abort the transaction, otherwise we commit
a super block with btree roots that point to btree nodes/leafs whose
content on disk is invalid - either garbage or the content of some
node/leaf from a past generation that got cowed or deleted and is no
longer valid (for this later case we end up getting error messages like
"parent transid verify failed on 10826481664 wanted 25748 found 29562"
when reading btree nodes/leafs from disk).
Note that setting and checking AS_EIO/AS_ENOSPC in the btree inode's
i_mapping would not be enough because we need to distinguish between
log tree extents (not fatal) vs non-log tree extents (fatal) and
because the next call to filemap_fdatawait_range() will catch and clear
such errors in the mapping - and that call might be from a log sync and
not from a transaction commit, which means we would not know about the
error at transaction commit time. Also, checking for the eb flag
EXTENT_BUFFER_IOERR at transaction commit time isn't done and would
not be completely reliable, as the eb might be removed from memory and
read back when trying to get it, which clears that flag right before
reading the eb's pages from disk, making us not know about the previous
write error.
Using the new 3 flags for the btree inode also makes us achieve the
goal of AS_EIO/AS_ENOSPC when writepages() returns success, started
writeback for all dirty pages and before filemap_fdatawait_range() is
called, the writeback for all dirty pages had already finished with
errors - because we were not using AS_EIO/AS_ENOSPC,
filemap_fdatawait_range() would return success, as it could not know
that writeback errors happened (the pages were no longer tagged for
writeback).
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Chris Mason <clm@fb.com>
2014-09-26 18:25:56 +07:00
|
|
|
short lock_nested;
|
|
|
|
/* >= 0 if eb belongs to a log tree, -1 otherwise */
|
|
|
|
short log_index;
|
2011-07-17 02:23:14 +07:00
|
|
|
|
|
|
|
/* protects write locks */
|
|
|
|
rwlock_t lock;
|
|
|
|
|
|
|
|
/* readers use lock_wq while they wait for the write
|
|
|
|
* lock holders to unlock
|
|
|
|
*/
|
|
|
|
wait_queue_head_t write_lock_wq;
|
Btrfs: Change btree locking to use explicit blocking points
Most of the btrfs metadata operations can be protected by a spinlock,
but some operations still need to schedule.
So far, btrfs has been using a mutex along with a trylock loop,
most of the time it is able to avoid going for the full mutex, so
the trylock loop is a big performance gain.
This commit is step one for getting rid of the blocking locks entirely.
btrfs_tree_lock takes a spinlock, and the code explicitly switches
to a blocking lock when it starts an operation that can schedule.
We'll be able get rid of the blocking locks in smaller pieces over time.
Tracing allows us to find the most common cause of blocking, so we
can start with the hot spots first.
The basic idea is:
btrfs_tree_lock() returns with the spin lock held
btrfs_set_lock_blocking() sets the EXTENT_BUFFER_BLOCKING bit in
the extent buffer flags, and then drops the spin lock. The buffer is
still considered locked by all of the btrfs code.
If btrfs_tree_lock gets the spinlock but finds the blocking bit set, it drops
the spin lock and waits on a wait queue for the blocking bit to go away.
Much of the code that needs to set the blocking bit finishes without actually
blocking a good percentage of the time. So, an adaptive spin is still
used against the blocking bit to avoid very high context switch rates.
btrfs_clear_lock_blocking() clears the blocking bit and returns
with the spinlock held again.
btrfs_tree_unlock() can be called on either blocking or spinning locks,
it does the right thing based on the blocking bit.
ctree.c has a helper function to set/clear all the locked buffers in a
path as blocking.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-02-04 21:25:08 +07:00
|
|
|
|
2011-07-17 02:23:14 +07:00
|
|
|
/* writers use read_lock_wq while they wait for readers
|
|
|
|
* to unlock
|
Btrfs: Change btree locking to use explicit blocking points
Most of the btrfs metadata operations can be protected by a spinlock,
but some operations still need to schedule.
So far, btrfs has been using a mutex along with a trylock loop,
most of the time it is able to avoid going for the full mutex, so
the trylock loop is a big performance gain.
This commit is step one for getting rid of the blocking locks entirely.
btrfs_tree_lock takes a spinlock, and the code explicitly switches
to a blocking lock when it starts an operation that can schedule.
We'll be able get rid of the blocking locks in smaller pieces over time.
Tracing allows us to find the most common cause of blocking, so we
can start with the hot spots first.
The basic idea is:
btrfs_tree_lock() returns with the spin lock held
btrfs_set_lock_blocking() sets the EXTENT_BUFFER_BLOCKING bit in
the extent buffer flags, and then drops the spin lock. The buffer is
still considered locked by all of the btrfs code.
If btrfs_tree_lock gets the spinlock but finds the blocking bit set, it drops
the spin lock and waits on a wait queue for the blocking bit to go away.
Much of the code that needs to set the blocking bit finishes without actually
blocking a good percentage of the time. So, an adaptive spin is still
used against the blocking bit to avoid very high context switch rates.
btrfs_clear_lock_blocking() clears the blocking bit and returns
with the spinlock held again.
btrfs_tree_unlock() can be called on either blocking or spinning locks,
it does the right thing based on the blocking bit.
ctree.c has a helper function to set/clear all the locked buffers in a
path as blocking.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-02-04 21:25:08 +07:00
|
|
|
*/
|
2011-07-17 02:23:14 +07:00
|
|
|
wait_queue_head_t read_lock_wq;
|
2013-02-28 21:54:18 +07:00
|
|
|
struct page *pages[INLINE_EXTENT_BUFFER_PAGES];
|
2013-04-22 23:12:31 +07:00
|
|
|
#ifdef CONFIG_BTRFS_DEBUG
|
|
|
|
struct list_head leak_list;
|
|
|
|
#endif
|
2008-01-25 04:13:08 +07:00
|
|
|
};
|
|
|
|
|
2015-10-12 11:08:16 +07:00
|
|
|
/*
|
|
|
|
* Structure to record how many bytes and which ranges are set/cleared
|
|
|
|
*/
|
|
|
|
struct extent_changeset {
|
|
|
|
/* How many bytes are set/cleared in this operation */
|
2017-02-27 14:10:36 +07:00
|
|
|
unsigned int bytes_changed;
|
2015-10-12 11:08:16 +07:00
|
|
|
|
|
|
|
/* Changed ranges */
|
2017-02-13 19:42:29 +07:00
|
|
|
struct ulist range_changed;
|
2015-10-12 11:08:16 +07:00
|
|
|
};
|
|
|
|
|
2017-02-27 14:10:38 +07:00
|
|
|
static inline void extent_changeset_init(struct extent_changeset *changeset)
|
|
|
|
{
|
|
|
|
changeset->bytes_changed = 0;
|
|
|
|
ulist_init(&changeset->range_changed);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct extent_changeset *extent_changeset_alloc(void)
|
|
|
|
{
|
|
|
|
struct extent_changeset *ret;
|
|
|
|
|
|
|
|
ret = kmalloc(sizeof(*ret), GFP_KERNEL);
|
|
|
|
if (!ret)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
extent_changeset_init(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void extent_changeset_release(struct extent_changeset *changeset)
|
|
|
|
{
|
|
|
|
if (!changeset)
|
|
|
|
return;
|
|
|
|
changeset->bytes_changed = 0;
|
|
|
|
ulist_release(&changeset->range_changed);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void extent_changeset_free(struct extent_changeset *changeset)
|
|
|
|
{
|
|
|
|
if (!changeset)
|
|
|
|
return;
|
|
|
|
extent_changeset_release(changeset);
|
|
|
|
kfree(changeset);
|
|
|
|
}
|
|
|
|
|
2010-12-17 13:21:50 +07:00
|
|
|
static inline void extent_set_compress_type(unsigned long *bio_flags,
|
|
|
|
int compress_type)
|
|
|
|
{
|
|
|
|
*bio_flags |= compress_type << EXTENT_BIO_FLAG_SHIFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int extent_compress_type(unsigned long bio_flags)
|
|
|
|
{
|
|
|
|
return bio_flags >> EXTENT_BIO_FLAG_SHIFT;
|
|
|
|
}
|
|
|
|
|
2008-01-25 04:13:08 +07:00
|
|
|
struct extent_map_tree;
|
|
|
|
|
2017-02-20 18:51:06 +07:00
|
|
|
typedef struct extent_map *(get_extent_t)(struct btrfs_inode *inode,
|
2008-01-25 04:13:08 +07:00
|
|
|
struct page *page,
|
2011-04-19 19:29:38 +07:00
|
|
|
size_t pg_offset,
|
2008-01-25 04:13:08 +07:00
|
|
|
u64 start, u64 len,
|
|
|
|
int create);
|
|
|
|
|
2017-05-05 22:57:13 +07:00
|
|
|
void extent_io_tree_init(struct extent_io_tree *tree, void *private_data);
|
2018-04-19 14:46:34 +07:00
|
|
|
int try_release_extent_mapping(struct page *page, gfp_t mask);
|
2013-04-26 21:56:29 +07:00
|
|
|
int try_release_extent_buffer(struct page *page);
|
2009-09-03 00:24:36 +07:00
|
|
|
int lock_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
|
2015-12-03 20:30:40 +07:00
|
|
|
struct extent_state **cached);
|
2015-12-03 20:41:30 +07:00
|
|
|
|
|
|
|
static inline int lock_extent(struct extent_io_tree *tree, u64 start, u64 end)
|
|
|
|
{
|
|
|
|
return lock_extent_bits(tree, start, end, NULL);
|
|
|
|
}
|
|
|
|
|
2012-03-01 20:57:19 +07:00
|
|
|
int try_lock_extent(struct extent_io_tree *tree, u64 start, u64 end);
|
2008-01-25 04:13:08 +07:00
|
|
|
int extent_read_full_page(struct extent_io_tree *tree, struct page *page,
|
2011-06-14 01:02:58 +07:00
|
|
|
get_extent_t *get_extent, int mirror_num);
|
2008-01-25 04:13:08 +07:00
|
|
|
int __init extent_io_init(void);
|
2018-02-19 23:24:18 +07:00
|
|
|
void __cold extent_io_exit(void);
|
2008-01-25 04:13:08 +07:00
|
|
|
|
|
|
|
u64 count_range_bits(struct extent_io_tree *tree,
|
|
|
|
u64 *start, u64 search_end,
|
2015-01-15 01:52:13 +07:00
|
|
|
u64 max_bytes, unsigned bits, int contig);
|
2008-01-25 04:13:08 +07:00
|
|
|
|
2010-05-26 07:56:50 +07:00
|
|
|
void free_extent_state(struct extent_state *state);
|
2008-01-25 04:13:08 +07:00
|
|
|
int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end,
|
2015-01-15 01:52:13 +07:00
|
|
|
unsigned bits, int filled,
|
2013-04-29 20:38:46 +07:00
|
|
|
struct extent_state *cached_state);
|
2015-10-12 14:35:38 +07:00
|
|
|
int clear_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
|
2016-04-27 04:54:39 +07:00
|
|
|
unsigned bits, struct extent_changeset *changeset);
|
2008-07-17 23:53:50 +07:00
|
|
|
int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
|
2015-01-15 01:52:13 +07:00
|
|
|
unsigned bits, int wake, int delete,
|
2017-10-31 22:37:52 +07:00
|
|
|
struct extent_state **cached);
|
2017-10-31 22:30:47 +07:00
|
|
|
int __clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
|
|
|
|
unsigned bits, int wake, int delete,
|
|
|
|
struct extent_state **cached, gfp_t mask,
|
|
|
|
struct extent_changeset *changeset);
|
2015-12-03 20:08:11 +07:00
|
|
|
|
2015-12-03 20:08:11 +07:00
|
|
|
static inline int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end)
|
|
|
|
{
|
2017-10-31 22:37:52 +07:00
|
|
|
return clear_extent_bit(tree, start, end, EXTENT_LOCKED, 1, 0, NULL);
|
2015-12-03 20:08:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int unlock_extent_cached(struct extent_io_tree *tree, u64 start,
|
2017-12-13 03:43:52 +07:00
|
|
|
u64 end, struct extent_state **cached)
|
2015-12-03 20:08:11 +07:00
|
|
|
{
|
2017-10-31 22:30:47 +07:00
|
|
|
return __clear_extent_bit(tree, start, end, EXTENT_LOCKED, 1, 0, cached,
|
2017-12-13 03:43:52 +07:00
|
|
|
GFP_NOFS, NULL);
|
2015-12-03 20:08:11 +07:00
|
|
|
}
|
|
|
|
|
2017-12-08 00:52:54 +07:00
|
|
|
static inline int unlock_extent_cached_atomic(struct extent_io_tree *tree,
|
|
|
|
u64 start, u64 end, struct extent_state **cached)
|
2015-12-03 20:08:11 +07:00
|
|
|
{
|
2017-12-08 00:52:54 +07:00
|
|
|
return __clear_extent_bit(tree, start, end, EXTENT_LOCKED, 1, 0, cached,
|
|
|
|
GFP_ATOMIC, NULL);
|
2015-12-03 20:08:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int clear_extent_bits(struct extent_io_tree *tree, u64 start,
|
2016-04-27 04:54:39 +07:00
|
|
|
u64 end, unsigned bits)
|
2015-12-03 20:08:11 +07:00
|
|
|
{
|
|
|
|
int wake = 0;
|
|
|
|
|
|
|
|
if (bits & EXTENT_LOCKED)
|
|
|
|
wake = 1;
|
|
|
|
|
2017-10-31 22:37:52 +07:00
|
|
|
return clear_extent_bit(tree, start, end, bits, wake, 0, NULL);
|
2015-12-03 20:08:11 +07:00
|
|
|
}
|
|
|
|
|
2015-10-12 13:53:37 +07:00
|
|
|
int set_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
|
2016-04-27 04:54:39 +07:00
|
|
|
unsigned bits, struct extent_changeset *changeset);
|
2010-05-26 07:56:50 +07:00
|
|
|
int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
|
2015-01-15 01:52:13 +07:00
|
|
|
unsigned bits, u64 *failed_start,
|
2010-05-26 07:56:50 +07:00
|
|
|
struct extent_state **cached_state, gfp_t mask);
|
2015-12-03 20:08:11 +07:00
|
|
|
|
|
|
|
static inline int set_extent_bits(struct extent_io_tree *tree, u64 start,
|
2016-04-27 04:54:39 +07:00
|
|
|
u64 end, unsigned bits)
|
2015-12-03 20:08:11 +07:00
|
|
|
{
|
2016-04-27 04:54:39 +07:00
|
|
|
return set_extent_bit(tree, start, end, bits, NULL, NULL, GFP_NOFS);
|
2015-12-03 20:08:11 +07:00
|
|
|
}
|
|
|
|
|
2015-12-03 20:08:11 +07:00
|
|
|
static inline int clear_extent_uptodate(struct extent_io_tree *tree, u64 start,
|
2017-10-31 23:02:39 +07:00
|
|
|
u64 end, struct extent_state **cached_state)
|
2015-12-03 20:08:11 +07:00
|
|
|
{
|
2017-10-31 22:30:47 +07:00
|
|
|
return __clear_extent_bit(tree, start, end, EXTENT_UPTODATE, 0, 0,
|
2017-10-31 23:02:39 +07:00
|
|
|
cached_state, GFP_NOFS, NULL);
|
2015-12-03 20:08:11 +07:00
|
|
|
}
|
2015-12-03 20:08:11 +07:00
|
|
|
|
|
|
|
static inline int set_extent_dirty(struct extent_io_tree *tree, u64 start,
|
|
|
|
u64 end, gfp_t mask)
|
|
|
|
{
|
|
|
|
return set_extent_bit(tree, start, end, EXTENT_DIRTY, NULL,
|
|
|
|
NULL, mask);
|
|
|
|
}
|
|
|
|
|
2015-12-03 20:08:11 +07:00
|
|
|
static inline int clear_extent_dirty(struct extent_io_tree *tree, u64 start,
|
2016-04-27 04:54:39 +07:00
|
|
|
u64 end)
|
2015-12-03 20:08:11 +07:00
|
|
|
{
|
|
|
|
return clear_extent_bit(tree, start, end,
|
|
|
|
EXTENT_DIRTY | EXTENT_DELALLOC |
|
2017-10-31 22:37:52 +07:00
|
|
|
EXTENT_DO_ACCOUNTING, 0, 0, NULL);
|
2015-12-03 20:08:11 +07:00
|
|
|
}
|
|
|
|
|
2011-09-27 00:56:12 +07:00
|
|
|
int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
|
2015-01-15 01:52:13 +07:00
|
|
|
unsigned bits, unsigned clear_bits,
|
2016-04-27 04:54:39 +07:00
|
|
|
struct extent_state **cached_state);
|
2015-12-03 20:08:11 +07:00
|
|
|
|
|
|
|
static inline int set_extent_delalloc(struct extent_io_tree *tree, u64 start,
|
2017-11-04 07:16:59 +07:00
|
|
|
u64 end, unsigned int extra_bits,
|
|
|
|
struct extent_state **cached_state)
|
2015-12-03 20:08:11 +07:00
|
|
|
{
|
|
|
|
return set_extent_bit(tree, start, end,
|
2017-11-04 07:16:59 +07:00
|
|
|
EXTENT_DELALLOC | EXTENT_UPTODATE | extra_bits,
|
2016-04-27 04:54:39 +07:00
|
|
|
NULL, cached_state, GFP_NOFS);
|
2015-12-03 20:08:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int set_extent_defrag(struct extent_io_tree *tree, u64 start,
|
2016-04-27 04:54:39 +07:00
|
|
|
u64 end, struct extent_state **cached_state)
|
2015-12-03 20:08:11 +07:00
|
|
|
{
|
|
|
|
return set_extent_bit(tree, start, end,
|
|
|
|
EXTENT_DELALLOC | EXTENT_UPTODATE | EXTENT_DEFRAG,
|
2016-04-27 04:54:39 +07:00
|
|
|
NULL, cached_state, GFP_NOFS);
|
2015-12-03 20:08:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int set_extent_new(struct extent_io_tree *tree, u64 start,
|
2016-04-27 04:54:39 +07:00
|
|
|
u64 end)
|
2015-12-03 20:08:11 +07:00
|
|
|
{
|
2016-04-27 04:54:39 +07:00
|
|
|
return set_extent_bit(tree, start, end, EXTENT_NEW, NULL, NULL,
|
|
|
|
GFP_NOFS);
|
2015-12-03 20:08:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int set_extent_uptodate(struct extent_io_tree *tree, u64 start,
|
|
|
|
u64 end, struct extent_state **cached_state, gfp_t mask)
|
|
|
|
{
|
|
|
|
return set_extent_bit(tree, start, end, EXTENT_UPTODATE, NULL,
|
|
|
|
cached_state, mask);
|
|
|
|
}
|
|
|
|
|
2008-01-25 04:13:08 +07:00
|
|
|
int find_first_extent_bit(struct extent_io_tree *tree, u64 start,
|
2015-01-15 01:52:13 +07:00
|
|
|
u64 *start_ret, u64 *end_ret, unsigned bits,
|
2012-09-28 04:07:30 +07:00
|
|
|
struct extent_state **cached_state);
|
2008-01-25 04:13:08 +07:00
|
|
|
int extent_invalidatepage(struct extent_io_tree *tree,
|
|
|
|
struct page *page, unsigned long offset);
|
2017-12-08 20:55:59 +07:00
|
|
|
int extent_write_full_page(struct page *page, struct writeback_control *wbc);
|
2017-12-08 20:55:58 +07:00
|
|
|
int extent_write_locked_range(struct inode *inode, u64 start, u64 end,
|
2008-11-07 10:02:51 +07:00
|
|
|
int mode);
|
2018-04-19 14:46:38 +07:00
|
|
|
int extent_writepages(struct address_space *mapping,
|
2008-01-25 04:13:08 +07:00
|
|
|
struct writeback_control *wbc);
|
2012-03-13 20:38:00 +07:00
|
|
|
int btree_write_cache_pages(struct address_space *mapping,
|
|
|
|
struct writeback_control *wbc);
|
2018-04-19 14:46:36 +07:00
|
|
|
int extent_readpages(struct address_space *mapping, struct list_head *pages,
|
|
|
|
unsigned nr_pages);
|
2009-01-22 02:39:14 +07:00
|
|
|
int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
|
2017-06-23 09:09:57 +07:00
|
|
|
__u64 start, __u64 len);
|
2008-01-25 04:13:08 +07:00
|
|
|
void set_page_extent_mapped(struct page *page);
|
|
|
|
|
2013-12-17 01:24:27 +07:00
|
|
|
struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info,
|
2014-06-15 08:00:04 +07:00
|
|
|
u64 start);
|
2015-09-30 10:50:31 +07:00
|
|
|
struct extent_buffer *__alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
|
|
|
|
u64 start, unsigned long len);
|
2014-06-15 08:20:26 +07:00
|
|
|
struct extent_buffer *alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
|
2016-06-15 20:22:56 +07:00
|
|
|
u64 start);
|
2012-05-16 22:00:02 +07:00
|
|
|
struct extent_buffer *btrfs_clone_extent_buffer(struct extent_buffer *src);
|
2013-12-17 01:24:27 +07:00
|
|
|
struct extent_buffer *find_extent_buffer(struct btrfs_fs_info *fs_info,
|
2013-10-07 22:45:25 +07:00
|
|
|
u64 start);
|
2008-01-25 04:13:08 +07:00
|
|
|
void free_extent_buffer(struct extent_buffer *eb);
|
2012-03-10 04:01:49 +07:00
|
|
|
void free_extent_buffer_stale(struct extent_buffer *eb);
|
2011-06-10 19:06:53 +07:00
|
|
|
#define WAIT_NONE 0
|
|
|
|
#define WAIT_COMPLETE 1
|
|
|
|
#define WAIT_PAGE_LOCK 2
|
2008-01-25 04:13:08 +07:00
|
|
|
int read_extent_buffer_pages(struct extent_io_tree *tree,
|
2016-09-03 02:40:03 +07:00
|
|
|
struct extent_buffer *eb, int wait,
|
2017-06-23 09:09:57 +07:00
|
|
|
int mirror_num);
|
2013-04-25 03:41:19 +07:00
|
|
|
void wait_on_extent_buffer_writeback(struct extent_buffer *eb);
|
2012-09-29 15:07:47 +07:00
|
|
|
|
2018-03-02 00:20:27 +07:00
|
|
|
static inline int num_extent_pages(const struct extent_buffer *eb)
|
2012-09-29 15:07:47 +07:00
|
|
|
{
|
2018-07-04 22:49:31 +07:00
|
|
|
return (round_up(eb->start + eb->len, PAGE_SIZE) >> PAGE_SHIFT) -
|
|
|
|
(eb->start >> PAGE_SHIFT);
|
2012-09-29 15:07:47 +07:00
|
|
|
}
|
|
|
|
|
2008-01-25 04:13:08 +07:00
|
|
|
static inline void extent_buffer_get(struct extent_buffer *eb)
|
|
|
|
{
|
|
|
|
atomic_inc(&eb->refs);
|
|
|
|
}
|
|
|
|
|
2018-02-13 11:35:44 +07:00
|
|
|
static inline int extent_buffer_uptodate(struct extent_buffer *eb)
|
|
|
|
{
|
|
|
|
return test_bit(EXTENT_BUFFER_UPTODATE, &eb->bflags);
|
|
|
|
}
|
|
|
|
|
2017-06-29 10:56:53 +07:00
|
|
|
int memcmp_extent_buffer(const struct extent_buffer *eb, const void *ptrv,
|
|
|
|
unsigned long start, unsigned long len);
|
|
|
|
void read_extent_buffer(const struct extent_buffer *eb, void *dst,
|
2008-01-25 04:13:08 +07:00
|
|
|
unsigned long start,
|
|
|
|
unsigned long len);
|
2017-06-29 10:56:53 +07:00
|
|
|
int read_extent_buffer_to_user(const struct extent_buffer *eb,
|
|
|
|
void __user *dst, unsigned long start,
|
2014-01-30 22:24:01 +07:00
|
|
|
unsigned long len);
|
2016-11-09 23:43:38 +07:00
|
|
|
void write_extent_buffer_fsid(struct extent_buffer *eb, const void *src);
|
|
|
|
void write_extent_buffer_chunk_tree_uuid(struct extent_buffer *eb,
|
|
|
|
const void *src);
|
2008-01-25 04:13:08 +07:00
|
|
|
void write_extent_buffer(struct extent_buffer *eb, const void *src,
|
|
|
|
unsigned long start, unsigned long len);
|
2016-11-09 00:30:31 +07:00
|
|
|
void copy_extent_buffer_full(struct extent_buffer *dst,
|
|
|
|
struct extent_buffer *src);
|
2008-01-25 04:13:08 +07:00
|
|
|
void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src,
|
|
|
|
unsigned long dst_offset, unsigned long src_offset,
|
|
|
|
unsigned long len);
|
|
|
|
void memcpy_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
|
|
|
|
unsigned long src_offset, unsigned long len);
|
|
|
|
void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
|
|
|
|
unsigned long src_offset, unsigned long len);
|
2016-11-09 00:09:03 +07:00
|
|
|
void memzero_extent_buffer(struct extent_buffer *eb, unsigned long start,
|
|
|
|
unsigned long len);
|
2015-09-30 10:50:30 +07:00
|
|
|
int extent_buffer_test_bit(struct extent_buffer *eb, unsigned long start,
|
|
|
|
unsigned long pos);
|
|
|
|
void extent_buffer_bitmap_set(struct extent_buffer *eb, unsigned long start,
|
|
|
|
unsigned long pos, unsigned long len);
|
|
|
|
void extent_buffer_bitmap_clear(struct extent_buffer *eb, unsigned long start,
|
|
|
|
unsigned long pos, unsigned long len);
|
2012-03-29 07:31:37 +07:00
|
|
|
void clear_extent_buffer_dirty(struct extent_buffer *eb);
|
2018-09-14 00:44:42 +07:00
|
|
|
bool set_extent_buffer_dirty(struct extent_buffer *eb);
|
2015-12-03 19:08:59 +07:00
|
|
|
void set_extent_buffer_uptodate(struct extent_buffer *eb);
|
2015-12-03 19:08:59 +07:00
|
|
|
void clear_extent_buffer_uptodate(struct extent_buffer *eb);
|
2014-03-29 04:07:27 +07:00
|
|
|
int extent_buffer_under_io(struct extent_buffer *eb);
|
2017-06-29 10:56:53 +07:00
|
|
|
int map_private_extent_buffer(const struct extent_buffer *eb,
|
|
|
|
unsigned long offset, unsigned long min_len,
|
|
|
|
char **map, unsigned long *map_start,
|
|
|
|
unsigned long *map_len);
|
2015-12-03 19:08:59 +07:00
|
|
|
void extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end);
|
2015-12-03 19:08:59 +07:00
|
|
|
void extent_range_redirty_for_io(struct inode *inode, u64 start, u64 end);
|
2015-12-03 19:08:59 +07:00
|
|
|
void extent_clear_unlock_delalloc(struct inode *inode, u64 start, u64 end,
|
2016-07-19 15:50:36 +07:00
|
|
|
u64 delalloc_end, struct page *locked_page,
|
2015-01-15 01:52:13 +07:00
|
|
|
unsigned bits_to_clear,
|
2013-07-29 22:20:47 +07:00
|
|
|
unsigned long page_ops);
|
2017-06-02 23:35:36 +07:00
|
|
|
struct bio *btrfs_bio_alloc(struct block_device *bdev, u64 first_byte);
|
2017-06-12 22:29:41 +07:00
|
|
|
struct bio *btrfs_io_bio_alloc(unsigned int nr_iovecs);
|
2017-06-02 22:48:13 +07:00
|
|
|
struct bio *btrfs_bio_clone(struct bio *bio);
|
2017-05-17 00:57:14 +07:00
|
|
|
struct bio *btrfs_bio_clone_partial(struct bio *orig, int offset, int size);
|
2011-07-22 20:41:52 +07:00
|
|
|
|
2012-11-05 21:46:42 +07:00
|
|
|
struct btrfs_fs_info;
|
2017-02-20 18:50:55 +07:00
|
|
|
struct btrfs_inode;
|
2011-07-22 20:41:52 +07:00
|
|
|
|
2017-05-05 22:57:14 +07:00
|
|
|
int repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start,
|
|
|
|
u64 length, u64 logical, struct page *page,
|
|
|
|
unsigned int pg_offset, int mirror_num);
|
2017-05-05 22:57:15 +07:00
|
|
|
int clean_io_failure(struct btrfs_fs_info *fs_info,
|
|
|
|
struct extent_io_tree *failure_tree,
|
|
|
|
struct extent_io_tree *io_tree, u64 start,
|
|
|
|
struct page *page, u64 ino, unsigned int pg_offset);
|
2015-12-03 19:08:59 +07:00
|
|
|
void end_extent_writepage(struct page *page, int err, u64 start, u64 end);
|
2016-06-23 05:54:24 +07:00
|
|
|
int repair_eb_io_failure(struct btrfs_fs_info *fs_info,
|
|
|
|
struct extent_buffer *eb, int mirror_num);
|
2014-09-12 17:43:59 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* When IO fails, either with EIO or csum verification fails, we
|
|
|
|
* try other mirrors that might have a good copy of the data. This
|
|
|
|
* io_failure_record is used to record state as we go through all the
|
|
|
|
* mirrors. If another mirror has good data, the page is set up to date
|
|
|
|
* and things continue. If a good mirror can't be found, the original
|
|
|
|
* bio end_io callback is called to indicate things have failed.
|
|
|
|
*/
|
|
|
|
struct io_failure_record {
|
|
|
|
struct page *page;
|
|
|
|
u64 start;
|
|
|
|
u64 len;
|
|
|
|
u64 logical;
|
|
|
|
unsigned long bio_flags;
|
|
|
|
int this_mirror;
|
|
|
|
int failed_mirror;
|
|
|
|
int in_validation;
|
|
|
|
};
|
|
|
|
|
2017-02-20 18:50:52 +07:00
|
|
|
|
2017-02-20 18:50:57 +07:00
|
|
|
void btrfs_free_io_failure_record(struct btrfs_inode *inode, u64 start,
|
|
|
|
u64 end);
|
2014-09-12 17:43:59 +07:00
|
|
|
int btrfs_get_io_failure_record(struct inode *inode, u64 start, u64 end,
|
|
|
|
struct io_failure_record **failrec_ret);
|
2017-12-18 19:22:11 +07:00
|
|
|
bool btrfs_check_repairable(struct inode *inode, unsigned failed_bio_pages,
|
2017-07-14 05:00:50 +07:00
|
|
|
struct io_failure_record *failrec, int fail_mirror);
|
2014-09-12 17:43:59 +07:00
|
|
|
struct bio *btrfs_create_repair_bio(struct inode *inode, struct bio *failed_bio,
|
|
|
|
struct io_failure_record *failrec,
|
|
|
|
struct page *page, int pg_offset, int icsum,
|
2014-09-12 17:44:03 +07:00
|
|
|
bio_end_io_t *endio_func, void *data);
|
2017-05-05 22:57:15 +07:00
|
|
|
int free_io_failure(struct extent_io_tree *failure_tree,
|
|
|
|
struct extent_io_tree *io_tree,
|
|
|
|
struct io_failure_record *rec);
|
2013-10-09 23:00:56 +07:00
|
|
|
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
|
2018-08-17 22:28:06 +07:00
|
|
|
u64 btrfs_find_lock_delalloc_range(struct inode *inode,
|
2013-10-09 23:00:56 +07:00
|
|
|
struct extent_io_tree *tree,
|
|
|
|
struct page *locked_page, u64 *start,
|
|
|
|
u64 *end, u64 max_bytes);
|
2014-10-08 03:24:20 +07:00
|
|
|
#endif
|
2014-05-08 04:06:09 +07:00
|
|
|
struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info,
|
2016-06-15 20:22:56 +07:00
|
|
|
u64 start);
|
2018-04-04 00:16:55 +07:00
|
|
|
|
2013-10-09 23:00:56 +07:00
|
|
|
#endif
|