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 14:07:57 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2018-04-03 17:16:55 +00:00
|
|
|
|
|
|
|
#ifndef BTRFS_EXTENT_IO_H
|
|
|
|
#define BTRFS_EXTENT_IO_H
|
2008-01-24 21:13:08 +00:00
|
|
|
|
|
|
|
#include <linux/rbtree.h>
|
2017-03-03 08:55:19 +00:00
|
|
|
#include <linux/refcount.h>
|
2020-05-23 07:30:11 +00:00
|
|
|
#include <linux/fiemap.h>
|
2020-12-02 06:48:01 +00:00
|
|
|
#include <linux/btrfs_tree.h>
|
2021-07-27 12:53:55 +00:00
|
|
|
#include "compression.h"
|
2015-10-12 04:08:16 +00:00
|
|
|
#include "ulist.h"
|
2022-09-09 15:31:38 +00:00
|
|
|
#include "misc.h"
|
2008-01-24 21:13:08 +00:00
|
|
|
|
2023-01-26 21:00:59 +00:00
|
|
|
struct btrfs_trans_handle;
|
|
|
|
|
2018-11-27 14:03:20 +00:00
|
|
|
enum {
|
|
|
|
EXTENT_BUFFER_UPTODATE,
|
|
|
|
EXTENT_BUFFER_DIRTY,
|
|
|
|
EXTENT_BUFFER_CORRUPT,
|
|
|
|
/* this got triggered by readahead */
|
|
|
|
EXTENT_BUFFER_READAHEAD,
|
|
|
|
EXTENT_BUFFER_TREE_REF,
|
|
|
|
EXTENT_BUFFER_STALE,
|
|
|
|
EXTENT_BUFFER_WRITEBACK,
|
|
|
|
/* read IO error */
|
|
|
|
EXTENT_BUFFER_READ_ERR,
|
|
|
|
EXTENT_BUFFER_UNMAPPED,
|
|
|
|
EXTENT_BUFFER_IN_TREE,
|
|
|
|
/* write IO error */
|
|
|
|
EXTENT_BUFFER_WRITE_ERR,
|
2023-11-23 15:47:15 +00:00
|
|
|
/* Indicate the extent buffer is written zeroed out (for zoned) */
|
|
|
|
EXTENT_BUFFER_ZONED_ZEROOUT,
|
2023-05-03 15:24:40 +00:00
|
|
|
/* Indicate that extent buffer pages a being read */
|
|
|
|
EXTENT_BUFFER_READING,
|
2018-11-27 14:03:20 +00: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 14:25:08 +00:00
|
|
|
|
2017-02-10 15:41:05 +00:00
|
|
|
/* these are flags for __process_pages_contig */
|
2022-09-09 15:31:38 +00:00
|
|
|
enum {
|
|
|
|
ENUM_BIT(PAGE_UNLOCK),
|
|
|
|
/* Page starts writeback, clear dirty bit and set writeback bit */
|
|
|
|
ENUM_BIT(PAGE_START_WRITEBACK),
|
|
|
|
ENUM_BIT(PAGE_END_WRITEBACK),
|
|
|
|
ENUM_BIT(PAGE_SET_ORDERED),
|
|
|
|
};
|
2009-10-08 15:27:10 +00:00
|
|
|
|
2008-01-24 21:13:08 +00:00
|
|
|
/*
|
2023-11-17 03:54:14 +00:00
|
|
|
* Folio private values. Every page that is controlled by the extent map has
|
|
|
|
* folio private set to this value.
|
2008-01-24 21:13:08 +00:00
|
|
|
*/
|
2023-11-17 03:54:14 +00:00
|
|
|
#define EXTENT_FOLIO_PRIVATE 1
|
2008-01-24 21:13:08 +00:00
|
|
|
|
2016-09-23 00:24:20 +00: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)))
|
|
|
|
|
2012-03-27 01:57:36 +00:00
|
|
|
struct btrfs_root;
|
2017-02-20 11:51:03 +00:00
|
|
|
struct btrfs_inode;
|
2021-04-01 08:03:39 +00:00
|
|
|
struct btrfs_fs_info;
|
2019-09-23 14:05:19 +00:00
|
|
|
struct extent_io_tree;
|
btrfs: move tree block parentness check into validate_extent_buffer()
[BACKGROUND]
Although both btrfs metadata and data has their read time verification
done at endio time (btrfs_validate_metadata_buffer() and
btrfs_verify_data_csum()), metadata has extra verification, mostly
parentness check including first key/transid/owner_root/level, done at
read_tree_block() and btrfs_read_extent_buffer().
On the other hand, all the data verification is done at endio context.
[ENHANCEMENT]
This patch will make a new union in btrfs_bio, taking the space of the
old data checksums, thus it will not increase the memory usage.
With that extra btrfs_tree_parent_check inside btrfs_bio, we can just
pass the check parameter into read_extent_buffer_pages(), and before
submitting the bio, we can copy the check structure into btrfs_bio.
And finally at endio time, we can grab btrfs_bio::parent_check and pass
it to validate_extent_buffer(), to move the remaining checks into it.
This brings the following benefits:
- Much simpler btrfs_read_extent_buffer()
Now it only needs to iterate through all mirrors.
- Simpler read-time transid check
Previously we go verify_parent_transid() after reading out the extent
buffer.
Now the transid check is done inside the endio function, no other
code can modify the content.
Thus no need to use the extent lock anymore.
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-09-14 05:32:51 +00:00
|
|
|
struct btrfs_tree_parent_check;
|
2017-06-23 01:05:23 +00:00
|
|
|
|
2022-09-09 21:53:18 +00:00
|
|
|
int __init extent_buffer_init_cachep(void);
|
|
|
|
void __cold extent_buffer_free_cachep(void);
|
|
|
|
|
2020-12-02 06:48:01 +00:00
|
|
|
#define INLINE_EXTENT_BUFFER_PAGES (BTRFS_MAX_METADATA_BLOCKSIZE / PAGE_SIZE)
|
2008-01-24 21:13:08 +00: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 14:25:08 +00:00
|
|
|
unsigned long bflags;
|
2013-12-16 18:24:27 +00:00
|
|
|
struct btrfs_fs_info *fs_info;
|
2023-11-16 05:19:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The address where the eb can be accessed without any cross-page handling.
|
|
|
|
* This can be NULL if not possible.
|
|
|
|
*/
|
|
|
|
void *addr;
|
|
|
|
|
2012-03-09 21:01:49 +00:00
|
|
|
spinlock_t refs_lock;
|
2010-08-06 17:21:20 +00:00
|
|
|
atomic_t refs;
|
2012-04-16 13:42:26 +00:00
|
|
|
int read_mirror;
|
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 11:25:56 +00:00
|
|
|
/* >= 0 if eb belongs to a log tree, -1 otherwise */
|
btrfs: reorder extent buffer members for better packing
After the rwsem replaced the tree lock implementation, the extent buffer
got smaller but leaving some holes behind. By changing log_index type
and reordering, we can squeeze the size further to 240 bytes, measured on
release config on x86_64. Log_index spans only 3 values and needs to be
signed.
Before:
struct extent_buffer {
u64 start; /* 0 8 */
long unsigned int len; /* 8 8 */
long unsigned int bflags; /* 16 8 */
struct btrfs_fs_info * fs_info; /* 24 8 */
spinlock_t refs_lock; /* 32 4 */
atomic_t refs; /* 36 4 */
atomic_t io_pages; /* 40 4 */
int read_mirror; /* 44 4 */
struct callback_head callback_head __attribute__((__aligned__(8))); /* 48 16 */
/* --- cacheline 1 boundary (64 bytes) --- */
pid_t lock_owner; /* 64 4 */
bool lock_recursed; /* 68 1 */
/* XXX 3 bytes hole, try to pack */
struct rw_semaphore lock; /* 72 40 */
short int log_index; /* 112 2 */
/* XXX 6 bytes hole, try to pack */
struct page * pages[16]; /* 120 128 */
/* size: 248, cachelines: 4, members: 14 */
/* sum members: 239, holes: 2, sum holes: 9 */
/* forced alignments: 1 */
/* last cacheline: 56 bytes */
} __attribute__((__aligned__(8)));
After:
struct extent_buffer {
u64 start; /* 0 8 */
long unsigned int len; /* 8 8 */
long unsigned int bflags; /* 16 8 */
struct btrfs_fs_info * fs_info; /* 24 8 */
spinlock_t refs_lock; /* 32 4 */
atomic_t refs; /* 36 4 */
atomic_t io_pages; /* 40 4 */
int read_mirror; /* 44 4 */
struct callback_head callback_head __attribute__((__aligned__(8))); /* 48 16 */
/* --- cacheline 1 boundary (64 bytes) --- */
pid_t lock_owner; /* 64 4 */
bool lock_recursed; /* 68 1 */
s8 log_index; /* 69 1 */
/* XXX 2 bytes hole, try to pack */
struct rw_semaphore lock; /* 72 40 */
struct page * pages[16]; /* 112 128 */
/* size: 240, cachelines: 4, members: 14 */
/* sum members: 238, holes: 1, sum holes: 2 */
/* forced alignments: 1 */
/* last cacheline: 48 bytes */
} __attribute__((__aligned__(8)));
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-10-29 14:33:45 +00:00
|
|
|
s8 log_index;
|
2023-09-07 23:09:42 +00:00
|
|
|
struct rcu_head rcu_head;
|
btrfs: reorder extent buffer members for better packing
After the rwsem replaced the tree lock implementation, the extent buffer
got smaller but leaving some holes behind. By changing log_index type
and reordering, we can squeeze the size further to 240 bytes, measured on
release config on x86_64. Log_index spans only 3 values and needs to be
signed.
Before:
struct extent_buffer {
u64 start; /* 0 8 */
long unsigned int len; /* 8 8 */
long unsigned int bflags; /* 16 8 */
struct btrfs_fs_info * fs_info; /* 24 8 */
spinlock_t refs_lock; /* 32 4 */
atomic_t refs; /* 36 4 */
atomic_t io_pages; /* 40 4 */
int read_mirror; /* 44 4 */
struct callback_head callback_head __attribute__((__aligned__(8))); /* 48 16 */
/* --- cacheline 1 boundary (64 bytes) --- */
pid_t lock_owner; /* 64 4 */
bool lock_recursed; /* 68 1 */
/* XXX 3 bytes hole, try to pack */
struct rw_semaphore lock; /* 72 40 */
short int log_index; /* 112 2 */
/* XXX 6 bytes hole, try to pack */
struct page * pages[16]; /* 120 128 */
/* size: 248, cachelines: 4, members: 14 */
/* sum members: 239, holes: 2, sum holes: 9 */
/* forced alignments: 1 */
/* last cacheline: 56 bytes */
} __attribute__((__aligned__(8)));
After:
struct extent_buffer {
u64 start; /* 0 8 */
long unsigned int len; /* 8 8 */
long unsigned int bflags; /* 16 8 */
struct btrfs_fs_info * fs_info; /* 24 8 */
spinlock_t refs_lock; /* 32 4 */
atomic_t refs; /* 36 4 */
atomic_t io_pages; /* 40 4 */
int read_mirror; /* 44 4 */
struct callback_head callback_head __attribute__((__aligned__(8))); /* 48 16 */
/* --- cacheline 1 boundary (64 bytes) --- */
pid_t lock_owner; /* 64 4 */
bool lock_recursed; /* 68 1 */
s8 log_index; /* 69 1 */
/* XXX 2 bytes hole, try to pack */
struct rw_semaphore lock; /* 72 40 */
struct page * pages[16]; /* 112 128 */
/* size: 240, cachelines: 4, members: 14 */
/* sum members: 238, holes: 1, sum holes: 2 */
/* forced alignments: 1 */
/* last cacheline: 48 bytes */
} __attribute__((__aligned__(8)));
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2020-10-29 14:33:45 +00:00
|
|
|
|
|
|
|
struct rw_semaphore lock;
|
2011-07-16 19:23:14 +00:00
|
|
|
|
2023-12-06 23:09:27 +00:00
|
|
|
/*
|
|
|
|
* Pointers to all the folios of the extent buffer.
|
|
|
|
*
|
|
|
|
* For now the folio is always order 0 (aka, a single page).
|
|
|
|
*/
|
|
|
|
struct folio *folios[INLINE_EXTENT_BUFFER_PAGES];
|
2013-04-22 16:12:31 +00:00
|
|
|
#ifdef CONFIG_BTRFS_DEBUG
|
|
|
|
struct list_head leak_list;
|
2023-09-07 23:09:42 +00:00
|
|
|
pid_t lock_owner;
|
2013-04-22 16:12:31 +00:00
|
|
|
#endif
|
2008-01-24 21:13:08 +00:00
|
|
|
};
|
|
|
|
|
2023-08-07 16:12:31 +00:00
|
|
|
struct btrfs_eb_write_context {
|
|
|
|
struct writeback_control *wbc;
|
|
|
|
struct extent_buffer *eb;
|
2023-08-07 16:12:32 +00:00
|
|
|
/* Block group @eb resides in. Only used for zoned mode. */
|
|
|
|
struct btrfs_block_group *zoned_bg;
|
2023-08-07 16:12:31 +00:00
|
|
|
};
|
|
|
|
|
2022-11-15 16:16:13 +00:00
|
|
|
/*
|
|
|
|
* Get the correct offset inside the page of extent buffer.
|
|
|
|
*
|
|
|
|
* @eb: target extent buffer
|
|
|
|
* @start: offset inside the extent buffer
|
|
|
|
*
|
|
|
|
* Will handle both sectorsize == PAGE_SIZE and sectorsize < PAGE_SIZE cases.
|
|
|
|
*/
|
|
|
|
static inline size_t get_eb_offset_in_page(const struct extent_buffer *eb,
|
|
|
|
unsigned long offset)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* For sectorsize == PAGE_SIZE case, eb->start will always be aligned
|
|
|
|
* to PAGE_SIZE, thus adding it won't cause any difference.
|
|
|
|
*
|
|
|
|
* For sectorsize < PAGE_SIZE, we must only read the data that belongs
|
|
|
|
* to the eb, thus we have to take the eb->start into consideration.
|
|
|
|
*/
|
|
|
|
return offset_in_page(offset + eb->start);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned long get_eb_page_index(unsigned long offset)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* For sectorsize == PAGE_SIZE case, plain >> PAGE_SHIFT is enough.
|
|
|
|
*
|
|
|
|
* For sectorsize < PAGE_SIZE case, we only support 64K PAGE_SIZE,
|
|
|
|
* and have ensured that all tree blocks are contained in one page,
|
|
|
|
* thus we always get index == 0.
|
|
|
|
*/
|
|
|
|
return offset >> PAGE_SHIFT;
|
|
|
|
}
|
|
|
|
|
2015-10-12 04:08:16 +00: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 */
|
2022-03-07 10:00:04 +00:00
|
|
|
u64 bytes_changed;
|
2015-10-12 04:08:16 +00:00
|
|
|
|
|
|
|
/* Changed ranges */
|
2017-02-13 12:42:29 +00:00
|
|
|
struct ulist range_changed;
|
2015-10-12 04:08:16 +00:00
|
|
|
};
|
|
|
|
|
2017-02-27 07:10:38 +00: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);
|
|
|
|
}
|
|
|
|
|
2008-01-24 21:13:08 +00:00
|
|
|
struct extent_map_tree;
|
|
|
|
|
2018-04-19 07:46:34 +00:00
|
|
|
int try_release_extent_mapping(struct page *page, gfp_t mask);
|
2013-04-26 14:56:29 +00:00
|
|
|
int try_release_extent_buffer(struct page *page);
|
2015-12-03 13:41:30 +00:00
|
|
|
|
2022-05-25 02:55:07 +00:00
|
|
|
int btrfs_read_folio(struct file *file, struct folio *folio);
|
2023-06-28 15:31:42 +00:00
|
|
|
void extent_write_locked_range(struct inode *inode, struct page *locked_page,
|
|
|
|
u64 start, u64 end, struct writeback_control *wbc,
|
|
|
|
bool pages_dirty);
|
2018-04-19 07:46:38 +00:00
|
|
|
int extent_writepages(struct address_space *mapping,
|
2008-01-24 21:13:08 +00:00
|
|
|
struct writeback_control *wbc);
|
2012-03-13 13:38:00 +00:00
|
|
|
int btree_write_cache_pages(struct address_space *mapping,
|
|
|
|
struct writeback_control *wbc);
|
2020-06-02 04:47:05 +00:00
|
|
|
void extent_readahead(struct readahead_control *rac);
|
2020-08-31 11:42:49 +00:00
|
|
|
int extent_fiemap(struct btrfs_inode *inode, struct fiemap_extent_info *fieinfo,
|
2020-06-23 18:56:12 +00:00
|
|
|
u64 start, u64 len);
|
2021-01-26 08:34:00 +00:00
|
|
|
int set_page_extent_mapped(struct page *page);
|
|
|
|
void clear_page_extent_mapped(struct page *page);
|
2008-01-24 21:13:08 +00:00
|
|
|
|
2013-12-16 18:24:27 +00:00
|
|
|
struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info,
|
2020-11-05 15:45:20 +00:00
|
|
|
u64 start, u64 owner_root, int level);
|
2015-09-30 03:50:31 +00:00
|
|
|
struct extent_buffer *__alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
|
|
|
|
u64 start, unsigned long len);
|
2014-06-15 01:20:26 +00:00
|
|
|
struct extent_buffer *alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
|
2016-06-15 13:22:56 +00:00
|
|
|
u64 start);
|
2020-04-29 01:04:10 +00:00
|
|
|
struct extent_buffer *btrfs_clone_extent_buffer(const struct extent_buffer *src);
|
2013-12-16 18:24:27 +00:00
|
|
|
struct extent_buffer *find_extent_buffer(struct btrfs_fs_info *fs_info,
|
2013-10-07 15:45:25 +00:00
|
|
|
u64 start);
|
2008-01-24 21:13:08 +00:00
|
|
|
void free_extent_buffer(struct extent_buffer *eb);
|
2012-03-09 21:01:49 +00:00
|
|
|
void free_extent_buffer_stale(struct extent_buffer *eb);
|
2011-06-10 12:06:53 +00:00
|
|
|
#define WAIT_NONE 0
|
|
|
|
#define WAIT_COMPLETE 1
|
|
|
|
#define WAIT_PAGE_LOCK 2
|
btrfs: move tree block parentness check into validate_extent_buffer()
[BACKGROUND]
Although both btrfs metadata and data has their read time verification
done at endio time (btrfs_validate_metadata_buffer() and
btrfs_verify_data_csum()), metadata has extra verification, mostly
parentness check including first key/transid/owner_root/level, done at
read_tree_block() and btrfs_read_extent_buffer().
On the other hand, all the data verification is done at endio context.
[ENHANCEMENT]
This patch will make a new union in btrfs_bio, taking the space of the
old data checksums, thus it will not increase the memory usage.
With that extra btrfs_tree_parent_check inside btrfs_bio, we can just
pass the check parameter into read_extent_buffer_pages(), and before
submitting the bio, we can copy the check structure into btrfs_bio.
And finally at endio time, we can grab btrfs_bio::parent_check and pass
it to validate_extent_buffer(), to move the remaining checks into it.
This brings the following benefits:
- Much simpler btrfs_read_extent_buffer()
Now it only needs to iterate through all mirrors.
- Simpler read-time transid check
Previously we go verify_parent_transid() after reading out the extent
buffer.
Now the transid check is done inside the endio function, no other
code can modify the content.
Thus no need to use the extent lock anymore.
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2022-09-14 05:32:51 +00:00
|
|
|
int read_extent_buffer_pages(struct extent_buffer *eb, int wait, int mirror_num,
|
|
|
|
struct btrfs_tree_parent_check *parent_check);
|
2013-04-24 20:41:19 +00:00
|
|
|
void wait_on_extent_buffer_writeback(struct extent_buffer *eb);
|
2020-11-05 15:45:09 +00:00
|
|
|
void btrfs_readahead_tree_block(struct btrfs_fs_info *fs_info,
|
2020-11-05 15:45:20 +00:00
|
|
|
u64 bytenr, u64 owner_root, u64 gen, int level);
|
2020-11-05 15:45:09 +00:00
|
|
|
void btrfs_readahead_node_child(struct extent_buffer *node, int slot);
|
2012-09-29 08:07:47 +00:00
|
|
|
|
2018-03-01 17:20:27 +00:00
|
|
|
static inline int num_extent_pages(const struct extent_buffer *eb)
|
2012-09-29 08:07:47 +00:00
|
|
|
{
|
2020-12-02 06:48:03 +00:00
|
|
|
/*
|
|
|
|
* For sectorsize == PAGE_SIZE case, since nodesize is always aligned to
|
|
|
|
* sectorsize, it's just eb->len >> PAGE_SHIFT.
|
|
|
|
*
|
|
|
|
* For sectorsize < PAGE_SIZE case, we could have nodesize < PAGE_SIZE,
|
|
|
|
* thus have to ensure we get at least one page.
|
|
|
|
*/
|
|
|
|
return (eb->len >> PAGE_SHIFT) ?: 1;
|
2012-09-29 08:07:47 +00:00
|
|
|
}
|
|
|
|
|
2020-04-29 01:04:10 +00:00
|
|
|
static inline int extent_buffer_uptodate(const struct extent_buffer *eb)
|
2018-02-13 04:35:44 +00:00
|
|
|
{
|
|
|
|
return test_bit(EXTENT_BUFFER_UPTODATE, &eb->bflags);
|
|
|
|
}
|
|
|
|
|
2017-06-29 03:56:53 +00: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-24 21:13:08 +00:00
|
|
|
unsigned long start,
|
|
|
|
unsigned long len);
|
2020-08-10 15:42:27 +00:00
|
|
|
int read_extent_buffer_to_user_nofault(const struct extent_buffer *eb,
|
|
|
|
void __user *dst, unsigned long start,
|
|
|
|
unsigned long len);
|
2020-04-29 01:04:10 +00:00
|
|
|
void write_extent_buffer(const struct extent_buffer *eb, const void *src,
|
2008-01-24 21:13:08 +00:00
|
|
|
unsigned long start, unsigned long len);
|
2023-07-15 11:08:30 +00:00
|
|
|
|
|
|
|
static inline void write_extent_buffer_chunk_tree_uuid(
|
|
|
|
const struct extent_buffer *eb, const void *chunk_tree_uuid)
|
|
|
|
{
|
|
|
|
write_extent_buffer(eb, chunk_tree_uuid,
|
|
|
|
offsetof(struct btrfs_header, chunk_tree_uuid),
|
|
|
|
BTRFS_FSID_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void write_extent_buffer_fsid(const struct extent_buffer *eb,
|
|
|
|
const void *fsid)
|
|
|
|
{
|
|
|
|
write_extent_buffer(eb, fsid, offsetof(struct btrfs_header, fsid),
|
|
|
|
BTRFS_FSID_SIZE);
|
|
|
|
}
|
|
|
|
|
2020-04-29 01:04:10 +00:00
|
|
|
void copy_extent_buffer_full(const struct extent_buffer *dst,
|
|
|
|
const struct extent_buffer *src);
|
|
|
|
void copy_extent_buffer(const struct extent_buffer *dst,
|
|
|
|
const struct extent_buffer *src,
|
2008-01-24 21:13:08 +00:00
|
|
|
unsigned long dst_offset, unsigned long src_offset,
|
|
|
|
unsigned long len);
|
2020-04-29 01:04:10 +00:00
|
|
|
void memcpy_extent_buffer(const struct extent_buffer *dst,
|
|
|
|
unsigned long dst_offset, unsigned long src_offset,
|
|
|
|
unsigned long len);
|
|
|
|
void memmove_extent_buffer(const struct extent_buffer *dst,
|
|
|
|
unsigned long dst_offset, unsigned long src_offset,
|
2016-11-08 17:09:03 +00:00
|
|
|
unsigned long len);
|
2020-04-29 01:04:10 +00:00
|
|
|
void memzero_extent_buffer(const struct extent_buffer *eb, unsigned long start,
|
2016-11-08 17:09:03 +00:00
|
|
|
unsigned long len);
|
2020-04-29 01:04:10 +00:00
|
|
|
int extent_buffer_test_bit(const struct extent_buffer *eb, unsigned long start,
|
2015-09-30 03:50:30 +00:00
|
|
|
unsigned long pos);
|
2020-04-29 01:04:10 +00:00
|
|
|
void extent_buffer_bitmap_set(const struct extent_buffer *eb, unsigned long start,
|
2015-09-30 03:50:30 +00:00
|
|
|
unsigned long pos, unsigned long len);
|
2020-04-29 01:04:10 +00:00
|
|
|
void extent_buffer_bitmap_clear(const struct extent_buffer *eb,
|
|
|
|
unsigned long start, unsigned long pos,
|
|
|
|
unsigned long len);
|
2023-05-08 14:58:38 +00:00
|
|
|
void set_extent_buffer_dirty(struct extent_buffer *eb);
|
2015-12-03 12:08:59 +00:00
|
|
|
void set_extent_buffer_uptodate(struct extent_buffer *eb);
|
2015-12-03 12:08:59 +00:00
|
|
|
void clear_extent_buffer_uptodate(struct extent_buffer *eb);
|
2015-12-03 12:08:59 +00:00
|
|
|
void extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end);
|
2020-06-03 05:55:06 +00:00
|
|
|
void extent_clear_unlock_delalloc(struct btrfs_inode *inode, u64 start, u64 end,
|
2019-07-17 13:18:16 +00:00
|
|
|
struct page *locked_page,
|
2020-11-13 12:51:40 +00:00
|
|
|
u32 bits_to_clear, unsigned long page_ops);
|
2022-09-09 21:53:38 +00:00
|
|
|
int extent_invalidate_folio(struct extent_io_tree *tree,
|
|
|
|
struct folio *folio, size_t offset);
|
2023-01-26 21:00:59 +00:00
|
|
|
void btrfs_clear_buffer_dirty(struct btrfs_trans_handle *trans,
|
|
|
|
struct extent_buffer *buf);
|
2022-03-30 20:11:22 +00:00
|
|
|
|
2023-11-29 22:32:08 +00:00
|
|
|
int btrfs_alloc_page_array(unsigned int nr_pages, struct page **page_array,
|
|
|
|
gfp_t extra_gfp);
|
2011-07-22 13:41:52 +00:00
|
|
|
|
2013-10-09 16:00:56 +00:00
|
|
|
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
|
2019-06-21 15:02:54 +00:00
|
|
|
bool find_lock_delalloc_range(struct inode *inode,
|
2018-11-19 09:38:17 +00:00
|
|
|
struct page *locked_page, u64 *start,
|
|
|
|
u64 *end);
|
2014-10-07 20:24:20 +00:00
|
|
|
#endif
|
2014-05-07 21:06:09 +00:00
|
|
|
struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info,
|
2016-06-15 13:22:56 +00:00
|
|
|
u64 start);
|
2020-02-14 21:11:40 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_BTRFS_DEBUG
|
|
|
|
void btrfs_extent_buffer_leak_debug_check(struct btrfs_fs_info *fs_info);
|
|
|
|
#else
|
|
|
|
#define btrfs_extent_buffer_leak_debug_check(fs_info) do {} while (0)
|
|
|
|
#endif
|
|
|
|
|
2013-10-09 16:00:56 +00:00
|
|
|
#endif
|