bio.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. /*
  17. * Maximum number of sectors for a single bio to limit the size of the
  18. * checksum array. This matches the number of bio_vecs per bio and thus the
  19. * I/O size for buffered I/O.
  20. */
  21. #define BTRFS_MAX_BIO_SECTORS (256)
  22. typedef void (*btrfs_bio_end_io_t)(struct btrfs_bio *bbio);
  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. */
  27. struct btrfs_bio {
  28. /*
  29. * Inode and offset into it that this I/O operates on.
  30. * Only set for data I/O.
  31. */
  32. struct btrfs_inode *inode;
  33. u64 file_offset;
  34. union {
  35. /*
  36. * For data reads: checksumming and original I/O information.
  37. * (for internal use in the btrfs_submit_bbio() machinery only)
  38. */
  39. struct {
  40. u8 *csum;
  41. u8 csum_inline[BTRFS_BIO_INLINE_CSUM_SIZE];
  42. struct bvec_iter saved_iter;
  43. };
  44. /*
  45. * For data writes:
  46. * - ordered extent covering the bio
  47. * - pointer to the checksums for this bio
  48. * - original physical address from the allocator
  49. * (for zone append only)
  50. */
  51. struct {
  52. struct btrfs_ordered_extent *ordered;
  53. struct btrfs_ordered_sum *sums;
  54. u64 orig_physical;
  55. };
  56. /* For metadata reads: parentness verification. */
  57. struct btrfs_tree_parent_check parent_check;
  58. };
  59. /* End I/O information supplied to btrfs_bio_alloc */
  60. btrfs_bio_end_io_t end_io;
  61. void *private;
  62. /* For internal use in read end I/O handling */
  63. unsigned int mirror_num;
  64. atomic_t pending_ios;
  65. struct work_struct end_io_work;
  66. /* File system that this I/O operates on. */
  67. struct btrfs_fs_info *fs_info;
  68. /* Save the first error status of split bio. */
  69. blk_status_t status;
  70. /*
  71. * This member must come last, bio_alloc_bioset will allocate enough
  72. * bytes for entire btrfs_bio but relies on bio being last.
  73. */
  74. struct bio bio;
  75. };
  76. static inline struct btrfs_bio *btrfs_bio(struct bio *bio)
  77. {
  78. return container_of(bio, struct btrfs_bio, bio);
  79. }
  80. int __init btrfs_bioset_init(void);
  81. void __cold btrfs_bioset_exit(void);
  82. void btrfs_bio_init(struct btrfs_bio *bbio, struct btrfs_fs_info *fs_info,
  83. btrfs_bio_end_io_t end_io, void *private);
  84. struct btrfs_bio *btrfs_bio_alloc(unsigned int nr_vecs, blk_opf_t opf,
  85. struct btrfs_fs_info *fs_info,
  86. btrfs_bio_end_io_t end_io, void *private);
  87. void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status);
  88. /* Submit using blkcg_punt_bio_submit. */
  89. #define REQ_BTRFS_CGROUP_PUNT REQ_FS_PRIVATE
  90. void btrfs_submit_bbio(struct btrfs_bio *bbio, int mirror_num);
  91. void btrfs_submit_repair_write(struct btrfs_bio *bbio, int mirror_num, bool dev_replace);
  92. int btrfs_repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start,
  93. u64 length, u64 logical, struct folio *folio,
  94. unsigned int folio_offset, int mirror_num);
  95. #endif