File Index
Files and directories
Sign in
FILE

bio.h

File preview with syntax highlighting.

linux-6.19.14/fs/btrfs/bio.h C
  1/* SPDX-License-Identifier: GPL-2.0 */
  2/*
  3 * Copyright (C) 2007 Oracle.  All rights reserved.
  4 * Copyright (C) 2022 Christoph Hellwig.
  5 */
  6
  7#ifndef BTRFS_BIO_H
  8#define BTRFS_BIO_H
  9
 10#include <linux/types.h>
 11#include <linux/bio.h>
 12#include <linux/workqueue.h>
 13#include "tree-checker.h"
 14
 15struct btrfs_bio;
 16struct btrfs_fs_info;
 17struct btrfs_inode;
 18
 19#define BTRFS_BIO_INLINE_CSUM_SIZE	64
 20
 21typedef void (*btrfs_bio_end_io_t)(struct btrfs_bio *bbio);
 22
 23/*
 24 * Highlevel btrfs I/O structure.  It is allocated by btrfs_bio_alloc and
 25 * passed to btrfs_submit_bbio() for mapping to the physical devices.
 26 */
 27struct btrfs_bio {
 28	/*
 29	 * Inode and offset into it that this I/O operates on.
 30	 *
 31	 * If the inode is a data one, csum verification and read-repair
 32	 * will be done automatically.
 33	 * If the inode is a metadata one, everything is handled by the caller.
 34	 */
 35	struct btrfs_inode *inode;
 36	u64 file_offset;
 37
 38	union {
 39		/*
 40		 * For data reads: checksumming and original I/O information.
 41		 * (for internal use in the btrfs_submit_bbio() machinery only)
 42		 */
 43		struct {
 44			u8 *csum;
 45			u8 csum_inline[BTRFS_BIO_INLINE_CSUM_SIZE];
 46			struct bvec_iter saved_iter;
 47		};
 48
 49		/*
 50		 * For data writes:
 51		 * - ordered extent covering the bio
 52		 * - pointer to the checksums for this bio
 53		 * - original physical address from the allocator
 54		 *   (for zone append only)
 55		 * - original logical address, used for checksumming fscrypt bios
 56		 */
 57		struct {
 58			struct btrfs_ordered_extent *ordered;
 59			struct btrfs_ordered_sum *sums;
 60			struct work_struct csum_work;
 61			struct completion csum_done;
 62			struct bvec_iter csum_saved_iter;
 63			u64 orig_physical;
 64			u64 orig_logical;
 65		};
 66
 67		/* For metadata reads: parentness verification. */
 68		struct btrfs_tree_parent_check parent_check;
 69	};
 70
 71	/* End I/O information supplied to btrfs_bio_alloc */
 72	btrfs_bio_end_io_t end_io;
 73	void *private;
 74
 75	/* For internal use in read end I/O handling */
 76	unsigned int mirror_num;
 77	atomic_t pending_ios;
 78	struct work_struct end_io_work;
 79
 80	/* Save the first error status of split bio. */
 81	blk_status_t status;
 82
 83	/* Use the commit root to look up csums (data read bio only). */
 84	bool csum_search_commit_root;
 85
 86	/*
 87	 * Since scrub will reuse btree inode, we need this flag to distinguish
 88	 * scrub bios.
 89	 */
 90	bool is_scrub;
 91
 92	/* Whether the csum generation for data write is async. */
 93	bool async_csum;
 94
 95	/* Whether the bio is written using zone append. */
 96	bool can_use_append;
 97
 98	/*
 99	 * This member must come last, bio_alloc_bioset will allocate enough
100	 * bytes for entire btrfs_bio but relies on bio being last.
101	 */
102	struct bio bio;
103};
104
105static inline struct btrfs_bio *btrfs_bio(struct bio *bio)
106{
107	return container_of(bio, struct btrfs_bio, bio);
108}
109
110int __init btrfs_bioset_init(void);
111void __cold btrfs_bioset_exit(void);
112
113void btrfs_bio_init(struct btrfs_bio *bbio, struct btrfs_inode *inode, u64 file_offset,
114		    btrfs_bio_end_io_t end_io, void *private);
115struct btrfs_bio *btrfs_bio_alloc(unsigned int nr_vecs, blk_opf_t opf,
116				  struct btrfs_inode *inode, u64 file_offset,
117				  btrfs_bio_end_io_t end_io, void *private);
118void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status);
119
120/* Submit using blkcg_punt_bio_submit. */
121#define REQ_BTRFS_CGROUP_PUNT			REQ_FS_PRIVATE
122
123void btrfs_submit_bbio(struct btrfs_bio *bbio, int mirror_num);
124void btrfs_submit_repair_write(struct btrfs_bio *bbio, int mirror_num, bool dev_replace);
125int btrfs_repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 fileoff,
126			    u32 length, u64 logical, const phys_addr_t paddrs[],
127			    unsigned int step, int mirror_num);
128
129#endif
~/ Read-only file preview.