bio.h 3.6 KB

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