Linux Audio

Check our new training course

Loading...
v6.2
  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/bio.h>
 11#include <linux/workqueue.h>
 12#include "tree-checker.h"
 13
 14struct btrfs_bio;
 15struct btrfs_fs_info;
 
 16
 17#define BTRFS_BIO_INLINE_CSUM_SIZE	64
 18
 19/*
 20 * Maximum number of sectors for a single bio to limit the size of the
 21 * checksum array.  This matches the number of bio_vecs per bio and thus the
 22 * I/O size for buffered I/O.
 23 */
 24#define BTRFS_MAX_BIO_SECTORS		(256)
 25
 26typedef void (*btrfs_bio_end_io_t)(struct btrfs_bio *bbio);
 27
 28/*
 29 * Additional info to pass along bio.
 30 *
 31 * Mostly for btrfs specific features like csum and mirror_num.
 32 */
 33struct btrfs_bio {
 34	unsigned int mirror_num:7;
 35
 36	/*
 37	 * Extra indicator for metadata bios.
 38	 * For some btrfs bios they use pages without a mapping, thus
 39	 * we can not rely on page->mapping->host to determine if
 40	 * it's a metadata bio.
 41	 */
 42	unsigned int is_metadata:1;
 43	struct bvec_iter iter;
 44
 45	/* for direct I/O */
 46	u64 file_offset;
 47
 48	/* @device is for stripe IO submission. */
 49	struct btrfs_device *device;
 50	union {
 51		/* For data checksum verification. */
 
 
 
 52		struct {
 53			u8 *csum;
 54			u8 csum_inline[BTRFS_BIO_INLINE_CSUM_SIZE];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 55		};
 56
 57		/* For metadata parentness verification. */
 58		struct btrfs_tree_parent_check parent_check;
 59	};
 60
 61	/* End I/O information supplied to btrfs_bio_alloc */
 62	btrfs_bio_end_io_t end_io;
 63	void *private;
 64
 65	/* For read end I/O handling */
 
 
 66	struct work_struct end_io_work;
 67
 
 
 
 
 
 
 68	/*
 69	 * This member must come last, bio_alloc_bioset will allocate enough
 70	 * bytes for entire btrfs_bio but relies on bio being last.
 71	 */
 72	struct bio bio;
 73};
 74
 75static inline struct btrfs_bio *btrfs_bio(struct bio *bio)
 76{
 77	return container_of(bio, struct btrfs_bio, bio);
 78}
 79
 80int __init btrfs_bioset_init(void);
 81void __cold btrfs_bioset_exit(void);
 82
 83struct bio *btrfs_bio_alloc(unsigned int nr_vecs, blk_opf_t opf,
 84			    btrfs_bio_end_io_t end_io, void *private);
 85struct bio *btrfs_bio_clone_partial(struct bio *orig, u64 offset, u64 size,
 86				    btrfs_bio_end_io_t end_io, void *private);
 87
 
 88
 89static inline void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status)
 90{
 91	bbio->bio.bi_status = status;
 92	bbio->end_io(bbio);
 93}
 94
 95static inline void btrfs_bio_free_csum(struct btrfs_bio *bbio)
 96{
 97	if (bbio->is_metadata)
 98		return;
 99	if (bbio->csum != bbio->csum_inline) {
100		kfree(bbio->csum);
101		bbio->csum = NULL;
102	}
103}
104
105/*
106 * Iterate through a btrfs_bio (@bbio) on a per-sector basis.
107 *
108 * bvl        - struct bio_vec
109 * bbio       - struct btrfs_bio
110 * iters      - struct bvec_iter
111 * bio_offset - unsigned int
112 */
113#define btrfs_bio_for_each_sector(fs_info, bvl, bbio, iter, bio_offset)	\
114	for ((iter) = (bbio)->iter, (bio_offset) = 0;			\
115	     (iter).bi_size &&					\
116	     (((bvl) = bio_iter_iovec((&(bbio)->bio), (iter))), 1);	\
117	     (bio_offset) += fs_info->sectorsize,			\
118	     bio_advance_iter_single(&(bbio)->bio, &(iter),		\
119	     (fs_info)->sectorsize))
120
121void btrfs_submit_bio(struct btrfs_fs_info *fs_info, struct bio *bio,
122		      int mirror_num);
123int btrfs_repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start,
124			    u64 length, u64 logical, struct page *page,
125			    unsigned int pg_offset, int mirror_num);
126
127#endif
v6.13.7
  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
 21/*
 22 * Maximum number of sectors for a single bio to limit the size of the
 23 * checksum array.  This matches the number of bio_vecs per bio and thus the
 24 * I/O size for buffered I/O.
 25 */
 26#define BTRFS_MAX_BIO_SECTORS		(256)
 27
 28typedef void (*btrfs_bio_end_io_t)(struct btrfs_bio *bbio);
 29
 30/*
 31 * Highlevel btrfs I/O structure.  It is allocated by btrfs_bio_alloc and
 32 * passed to btrfs_submit_bbio() for mapping to the physical devices.
 
 33 */
 34struct btrfs_bio {
 
 
 35	/*
 36	 * Inode and offset into it that this I/O operates on.
 37	 * Only set for data I/O.
 
 
 38	 */
 39	struct btrfs_inode *inode;
 
 
 
 40	u64 file_offset;
 41
 
 
 42	union {
 43		/*
 44		 * For data reads: checksumming and original I/O information.
 45		 * (for internal use in the btrfs_submit_bbio() machinery only)
 46		 */
 47		struct {
 48			u8 *csum;
 49			u8 csum_inline[BTRFS_BIO_INLINE_CSUM_SIZE];
 50			struct bvec_iter saved_iter;
 51		};
 52
 53		/*
 54		 * For data writes:
 55		 * - ordered extent covering the bio
 56		 * - pointer to the checksums for this bio
 57		 * - original physical address from the allocator
 58		 *   (for zone append only)
 59		 */
 60		struct {
 61			struct btrfs_ordered_extent *ordered;
 62			struct btrfs_ordered_sum *sums;
 63			u64 orig_physical;
 64		};
 65
 66		/* For metadata reads: parentness verification. */
 67		struct btrfs_tree_parent_check parent_check;
 68	};
 69
 70	/* End I/O information supplied to btrfs_bio_alloc */
 71	btrfs_bio_end_io_t end_io;
 72	void *private;
 73
 74	/* For internal use in read end I/O handling */
 75	unsigned int mirror_num;
 76	atomic_t pending_ios;
 77	struct work_struct end_io_work;
 78
 79	/* File system that this I/O operates on. */
 80	struct btrfs_fs_info *fs_info;
 81
 82	/* Save the first error status of split bio. */
 83	blk_status_t status;
 84
 85	/*
 86	 * This member must come last, bio_alloc_bioset will allocate enough
 87	 * bytes for entire btrfs_bio but relies on bio being last.
 88	 */
 89	struct bio bio;
 90};
 91
 92static inline struct btrfs_bio *btrfs_bio(struct bio *bio)
 93{
 94	return container_of(bio, struct btrfs_bio, bio);
 95}
 96
 97int __init btrfs_bioset_init(void);
 98void __cold btrfs_bioset_exit(void);
 99
100void btrfs_bio_init(struct btrfs_bio *bbio, struct btrfs_fs_info *fs_info,
101		    btrfs_bio_end_io_t end_io, void *private);
102struct btrfs_bio *btrfs_bio_alloc(unsigned int nr_vecs, blk_opf_t opf,
103				  struct btrfs_fs_info *fs_info,
104				  btrfs_bio_end_io_t end_io, void *private);
105void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status);
106
107/* Submit using blkcg_punt_bio_submit. */
108#define REQ_BTRFS_CGROUP_PUNT			REQ_FS_PRIVATE
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
110void btrfs_submit_bbio(struct btrfs_bio *bbio, int mirror_num);
111void btrfs_submit_repair_write(struct btrfs_bio *bbio, int mirror_num, bool dev_replace);
112int btrfs_repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start,
113			    u64 length, u64 logical, struct folio *folio,
114			    unsigned int folio_offset, int mirror_num);
115
116#endif