projects/linux·blob assoc-array-fixes · refs

776 lines · 20.4 KiB

1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (C) 2001 Jens Axboe <[email protected]>
4 */
5#ifndef __LINUX_BIO_H
6#define __LINUX_BIO_H
7
8#include <linux/mempool.h>
9/* struct bio, bio_vec and BIO_* flags are defined in blk_types.h */
10#include <linux/blk_types.h>
11#include <linux/uio.h>
12
13#define BIO_MAX_VECS 256U
14#define BIO_MAX_INLINE_VECS UIO_MAXIOV
15
16struct queue_limits;
17
18static inline unsigned int bio_max_segs(unsigned int nr_segs)
19{
20 return min(nr_segs, BIO_MAX_VECS);
21}
22
23#define bio_iter_iovec(bio, iter) \
24 bvec_iter_bvec((bio)->bi_io_vec, (iter))
25
26#define bio_iter_page(bio, iter) \
27 bvec_iter_page((bio)->bi_io_vec, (iter))
28#define bio_iter_len(bio, iter) \
29 bvec_iter_len((bio)->bi_io_vec, (iter))
30#define bio_iter_offset(bio, iter) \
31 bvec_iter_offset((bio)->bi_io_vec, (iter))
32
33#define bio_page(bio) bio_iter_page((bio), (bio)->bi_iter)
34#define bio_offset(bio) bio_iter_offset((bio), (bio)->bi_iter)
35#define bio_iovec(bio) bio_iter_iovec((bio), (bio)->bi_iter)
36
37#define bvec_iter_sectors(iter) ((iter).bi_size >> 9)
38#define bvec_iter_end_sector(iter) ((iter).bi_sector + bvec_iter_sectors((iter)))
39
40#define bio_sectors(bio) bvec_iter_sectors((bio)->bi_iter)
41#define bio_end_sector(bio) bvec_iter_end_sector((bio)->bi_iter)
42
43/*
44 * Return the data direction, READ or WRITE.
45 */
46#define bio_data_dir(bio) \
47 (op_is_write(bio_op(bio)) ? WRITE : READ)
48
49static inline bool bio_flagged(const struct bio *bio, unsigned int bit)
50{
51 return bio->bi_flags & (1U << bit);
52}
53
54static inline void bio_set_flag(struct bio *bio, unsigned int bit)
55{
56 bio->bi_flags |= (1U << bit);
57}
58
59static inline void bio_clear_flag(struct bio *bio, unsigned int bit)
60{
61 bio->bi_flags &= ~(1U << bit);
62}
63
64/*
65 * Check whether this bio carries any data or not. A NULL bio is allowed.
66 */
67static inline bool bio_has_data(struct bio *bio)
68{
69 if (bio &&
70 bio->bi_iter.bi_size &&
71 bio_op(bio) != REQ_OP_DISCARD &&
72 bio_op(bio) != REQ_OP_SECURE_ERASE &&
73 bio_op(bio) != REQ_OP_WRITE_ZEROES)
74 return true;
75
76 return false;
77}
78
79static inline bool bio_no_advance_iter(const struct bio *bio)
80{
81 return bio_op(bio) == REQ_OP_DISCARD ||
82 bio_op(bio) == REQ_OP_SECURE_ERASE ||
83 bio_op(bio) == REQ_OP_WRITE_ZEROES;
84}
85
86static inline void *bio_data(struct bio *bio)
87{
88 if (bio_has_data(bio))
89 return page_address(bio_page(bio)) + bio_offset(bio);
90
91 return NULL;
92}
93
94static inline bool bio_next_segment(const struct bio *bio,
95 struct bvec_iter_all *iter)
96{
97 if (iter->idx >= bio->bi_vcnt)
98 return false;
99
100 bvec_advance(&bio->bi_io_vec[iter->idx], iter);
101 return true;
102}
103
104/*
105 * drivers should _never_ use the all version - the bio may have been split
106 * before it got to the driver and the driver won't own all of it
107 */
108#define bio_for_each_segment_all(bvl, bio, iter) \
109 for (bvl = bvec_init_iter_all(&iter); bio_next_segment((bio), &iter); )
110
111static inline void bio_advance_iter(const struct bio *bio,
112 struct bvec_iter *iter, unsigned int bytes)
113{
114 iter->bi_sector += bytes >> 9;
115
116 if (bio_no_advance_iter(bio))
117 iter->bi_size -= bytes;
118 else
119 bvec_iter_advance(bio->bi_io_vec, iter, bytes);
120 /* TODO: It is reasonable to complete bio with error here. */
121}
122
123/* @bytes should be less or equal to bvec[i->bi_idx].bv_len */
124static inline void bio_advance_iter_single(const struct bio *bio,
125 struct bvec_iter *iter,
126 unsigned int bytes)
127{
128 iter->bi_sector += bytes >> 9;
129
130 if (bio_no_advance_iter(bio))
131 iter->bi_size -= bytes;
132 else
133 bvec_iter_advance_single(bio->bi_io_vec, iter, bytes);
134}
135
136void __bio_advance(struct bio *, unsigned bytes);
137
138/**
139 * bio_advance - increment/complete a bio by some number of bytes
140 * @bio: bio to advance
141 * @nbytes: number of bytes to complete
142 *
143 * This updates bi_sector, bi_size and bi_idx; if the number of bytes to
144 * complete doesn't align with a bvec boundary, then bv_len and bv_offset will
145 * be updated on the last bvec as well.
146 *
147 * @bio will then represent the remaining, uncompleted portion of the io.
148 */
149static inline void bio_advance(struct bio *bio, unsigned int nbytes)
150{
151 if (nbytes == bio->bi_iter.bi_size) {
152 bio->bi_iter.bi_size = 0;
153 return;
154 }
155 __bio_advance(bio, nbytes);
156}
157
158#define __bio_for_each_segment(bvl, bio, iter, start) \
159 for (iter = (start); \
160 (iter).bi_size && \
161 ((bvl = bio_iter_iovec((bio), (iter))), 1); \
162 bio_advance_iter_single((bio), &(iter), (bvl).bv_len))
163
164#define bio_for_each_segment(bvl, bio, iter) \
165 __bio_for_each_segment(bvl, bio, iter, (bio)->bi_iter)
166
167#define __bio_for_each_bvec(bvl, bio, iter, start) \
168 for (iter = (start); \
169 (iter).bi_size && \
170 ((bvl = mp_bvec_iter_bvec((bio)->bi_io_vec, (iter))), 1); \
171 bio_advance_iter_single((bio), &(iter), (bvl).bv_len))
172
173/* iterate over multi-page bvec */
174#define bio_for_each_bvec(bvl, bio, iter) \
175 __bio_for_each_bvec(bvl, bio, iter, (bio)->bi_iter)
176
177/*
178 * Iterate over all multi-page bvecs. Drivers shouldn't use this version for the
179 * same reasons as bio_for_each_segment_all().
180 */
181#define bio_for_each_bvec_all(bvl, bio, i) \
182 for (i = 0, bvl = bio_first_bvec_all(bio); \
183 i < (bio)->bi_vcnt; i++, bvl++)
184
185#define bio_iter_last(bvec, iter) ((iter).bi_size == (bvec).bv_len)
186
187static inline unsigned bio_segments(struct bio *bio)
188{
189 unsigned segs = 0;
190 struct bio_vec bv;
191 struct bvec_iter iter;
192
193 /*
194 * We special case discard/write same/write zeroes, because they
195 * interpret bi_size differently:
196 */
197
198 switch (bio_op(bio)) {
199 case REQ_OP_DISCARD:
200 case REQ_OP_SECURE_ERASE:
201 case REQ_OP_WRITE_ZEROES:
202 return 0;
203 default:
204 break;
205 }
206
207 bio_for_each_segment(bv, bio, iter)
208 segs++;
209
210 return segs;
211}
212
213/*
214 * get a reference to a bio, so it won't disappear. the intended use is
215 * something like:
216 *
217 * bio_get(bio);
218 * submit_bio(rw, bio);
219 * if (bio->bi_flags ...)
220 * do_something
221 * bio_put(bio);
222 *
223 * without the bio_get(), it could potentially complete I/O before submit_bio
224 * returns. and then bio would be freed memory when if (bio->bi_flags ...)
225 * runs
226 */
227static inline void bio_get(struct bio *bio)
228{
229 bio->bi_flags |= (1 << BIO_REFFED);
230 smp_mb__before_atomic();
231 atomic_inc(&bio->__bi_cnt);
232}
233
234static inline void bio_cnt_set(struct bio *bio, unsigned int count)
235{
236 if (count != 1) {
237 bio->bi_flags |= (1 << BIO_REFFED);
238 smp_mb();
239 }
240 atomic_set(&bio->__bi_cnt, count);
241}
242
243static inline struct bio_vec *bio_first_bvec_all(struct bio *bio)
244{
245 WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED));
246 return bio->bi_io_vec;
247}
248
249static inline struct page *bio_first_page_all(struct bio *bio)
250{
251 return bio_first_bvec_all(bio)->bv_page;
252}
253
254static inline struct folio *bio_first_folio_all(struct bio *bio)
255{
256 return page_folio(bio_first_page_all(bio));
257}
258
259/**
260 * struct folio_iter - State for iterating all folios in a bio.
261 * @folio: The current folio we're iterating. NULL after the last folio.
262 * @offset: The byte offset within the current folio.
263 * @length: The number of bytes in this iteration (will not cross folio
264 * boundary).
265 */
266struct folio_iter {
267 struct folio *folio;
268 size_t offset;
269 size_t length;
270 /* private: for use by the iterator */
271 struct folio *_next;
272 size_t _seg_count;
273 int _i;
274};
275
276static inline void bio_first_folio(struct folio_iter *fi, struct bio *bio,
277 int i)
278{
279 struct bio_vec *bvec = bio_first_bvec_all(bio) + i;
280
281 if (unlikely(i >= bio->bi_vcnt)) {
282 fi->folio = NULL;
283 return;
284 }
285
286 fi->folio = bvec_folio(bvec);
287 fi->offset = bvec->bv_offset +
288 PAGE_SIZE * folio_page_idx(fi->folio, bvec->bv_page);
289 fi->_seg_count = bvec->bv_len;
290 fi->length = min(folio_size(fi->folio) - fi->offset, fi->_seg_count);
291 fi->_next = folio_next(fi->folio);
292 fi->_i = i;
293}
294
295static inline void bio_next_folio(struct folio_iter *fi, struct bio *bio)
296{
297 fi->_seg_count -= fi->length;
298 if (fi->_seg_count) {
299 fi->folio = fi->_next;
300 fi->offset = 0;
301 fi->length = min(folio_size(fi->folio), fi->_seg_count);
302 fi->_next = folio_next(fi->folio);
303 } else {
304 bio_first_folio(fi, bio, fi->_i + 1);
305 }
306}
307
308/**
309 * bio_for_each_folio_all - Iterate over each folio in a bio.
310 * @fi: struct folio_iter which is updated for each folio.
311 * @bio: struct bio to iterate over.
312 */
313#define bio_for_each_folio_all(fi, bio) \
314 for (bio_first_folio(&fi, bio, 0); fi.folio; bio_next_folio(&fi, bio))
315
316void bio_trim(struct bio *bio, sector_t offset, sector_t size);
317extern struct bio *bio_split(struct bio *bio, int sectors,
318 gfp_t gfp, struct bio_set *bs);
319int bio_split_io_at(struct bio *bio, const struct queue_limits *lim,
320 unsigned *segs, unsigned max_bytes, unsigned len_align);
321u8 bio_seg_gap(struct request_queue *q, struct bio *prev, struct bio *next,
322 u8 gaps_bit);
323
324/**
325 * bio_next_split - get next @sectors from a bio, splitting if necessary
326 * @bio: bio to split
327 * @sectors: number of sectors to split from the front of @bio
328 * @gfp: gfp mask
329 * @bs: bio set to allocate from
330 *
331 * Return: a bio representing the next @sectors of @bio - if the bio is smaller
332 * than @sectors, returns the original bio unchanged.
333 */
334static inline struct bio *bio_next_split(struct bio *bio, int sectors,
335 gfp_t gfp, struct bio_set *bs)
336{
337 if (sectors >= bio_sectors(bio))
338 return bio;
339
340 return bio_split(bio, sectors, gfp, bs);
341}
342
343enum {
344 BIOSET_NEED_BVECS = BIT(0),
345 BIOSET_NEED_RESCUER = BIT(1),
346 BIOSET_PERCPU_CACHE = BIT(2),
347};
348extern int bioset_init(struct bio_set *, unsigned int, unsigned int, int flags);
349extern void bioset_exit(struct bio_set *);
350
351struct bio *bio_alloc_bioset(struct block_device *bdev, unsigned short nr_vecs,
352 blk_opf_t opf, gfp_t gfp, struct bio_set *bs);
353struct bio *bio_kmalloc(unsigned short nr_vecs, gfp_t gfp_mask);
354extern void bio_put(struct bio *);
355
356struct bio *bio_alloc_clone(struct block_device *bdev, struct bio *bio_src,
357 gfp_t gfp, struct bio_set *bs);
358int bio_init_clone(struct block_device *bdev, struct bio *bio,
359 struct bio *bio_src, gfp_t gfp);
360
361extern struct bio_set fs_bio_set;
362
363static inline struct bio *bio_alloc(struct block_device *bdev,
364 unsigned short nr_vecs, blk_opf_t opf, gfp_t gfp_mask)
365{
366 return bio_alloc_bioset(bdev, nr_vecs, opf, gfp_mask, &fs_bio_set);
367}
368
369void submit_bio(struct bio *bio);
370
371/**
372 * bio_in_atomic - check if the current context is unsafe for bio completion
373 *
374 * Return: %true in atomic contexts (e.g. hard/soft IRQ, preempt-disabled);
375 * %false when a bio can be safely completed in the current context.
376 */
377static inline bool bio_in_atomic(void)
378{
379 if (IS_ENABLED(CONFIG_PREEMPTION) && rcu_preempt_depth())
380 return true;
381 if (!IS_ENABLED(CONFIG_PREEMPT_COUNT))
382 return true;
383 return !preemptible();
384}
385
386void __bio_complete_in_task(struct bio *bio);
387
388/**
389 * bio_complete_in_task - ensure a bio is completed in preemptible task context
390 * @bio: bio to complete
391 *
392 * If called from non-task context, offload the bio completion to a worker
393 * thread and return %true. Else return %false and do nothing.
394 *
395 * Uses BIO_COMPLETE_IN_TASK as a sentinel: if set, the bio was already
396 * deferred and we are running in the worker — return %false so the
397 * callback proceeds instead of re-deferring.
398 */
399static inline bool bio_complete_in_task(struct bio *bio)
400{
401 if (bio_flagged(bio, BIO_COMPLETE_IN_TASK))
402 return false;
403 if (!bio_in_atomic())
404 return false;
405 bio_set_flag(bio, BIO_COMPLETE_IN_TASK);
406 __bio_complete_in_task(bio);
407 return true;
408}
409
410extern void bio_endio(struct bio *);
411
412/**
413 * bio_endio_status - end I/O on a bio with a specific status
414 * @bio: bio
415 * @status: status to set
416 *
417 * Set @bio->bi_status to @status and call bio_endio().
418 **/
419static inline void bio_endio_status(struct bio *bio, blk_status_t status)
420{
421 bio->bi_status = status;
422 bio_endio(bio);
423}
424
425static inline void bio_io_error(struct bio *bio)
426{
427 bio_endio_status(bio, BLK_STS_IOERR);
428}
429
430static inline void bio_wouldblock_error(struct bio *bio)
431{
432 bio_endio_status(bio, BLK_STS_AGAIN);
433}
434
435/*
436 * Calculate number of bvec segments that should be allocated to fit data
437 * pointed by @iter. If @iter is backed by bvec it's going to be reused
438 * instead of allocating a new one.
439 */
440static inline int bio_iov_vecs_to_alloc(struct iov_iter *iter, int max_segs)
441{
442 if (iov_iter_is_bvec(iter))
443 return 0;
444 return iov_iter_npages(iter, max_segs);
445}
446
447/**
448 * bio_iov_bounce_nr_vecs - calculate number of bvecs for a bounce bio
449 * @iter: iter to bounce from
450 * @op: REQ_OP_* for the bio
451 *
452 * Calculates how many bvecs are needed for the next bio to bounce from/to
453 * @iter.
454 */
455static inline unsigned short
456bio_iov_bounce_nr_vecs(struct iov_iter *iter, blk_opf_t op)
457{
458 /*
459 * We still need to bounce bvec iters, so don't special case them
460 * here unlike in bio_iov_vecs_to_alloc.
461 *
462 * For reads we need to use a vector for the bounce buffer, account
463 * for that here.
464 */
465 if (op_is_write(op))
466 return iov_iter_npages(iter, BIO_MAX_VECS);
467 return iov_iter_npages(iter, BIO_MAX_VECS - 1) + 1;
468}
469
470struct request_queue;
471
472void bio_init(struct bio *bio, struct block_device *bdev, struct bio_vec *table,
473 unsigned short max_vecs, blk_opf_t opf);
474static inline void bio_init_inline(struct bio *bio, struct block_device *bdev,
475 unsigned short max_vecs, blk_opf_t opf)
476{
477 bio_init(bio, bdev, bio_inline_vecs(bio), max_vecs, opf);
478}
479extern void bio_uninit(struct bio *);
480void bio_reset(struct bio *bio, struct block_device *bdev, blk_opf_t opf);
481void bio_reuse(struct bio *bio, blk_opf_t opf);
482void bio_chain(struct bio *, struct bio *);
483void bio_await(struct bio *bio, void *priv,
484 void (*submit)(struct bio *bio, void *priv));
485
486int __must_check bio_add_page(struct bio *bio, struct page *page, unsigned len,
487 unsigned off);
488bool __must_check bio_add_folio(struct bio *bio, struct folio *folio,
489 size_t len, size_t off);
490void __bio_add_page(struct bio *bio, struct page *page,
491 unsigned int len, unsigned int off);
492void bio_add_folio_nofail(struct bio *bio, struct folio *folio, size_t len,
493 size_t off);
494void bio_add_virt_nofail(struct bio *bio, void *vaddr, unsigned len);
495
496/**
497 * bio_add_max_vecs - number of bio_vecs needed to add data to a bio
498 * @kaddr: kernel virtual address to add
499 * @len: length in bytes to add
500 *
501 * Calculate how many bio_vecs need to be allocated to add the kernel virtual
502 * address range in [@kaddr:@len] in the worse case.
503 */
504static inline unsigned int bio_add_max_vecs(void *kaddr, unsigned int len)
505{
506 if (is_vmalloc_addr(kaddr))
507 return DIV_ROUND_UP(offset_in_page(kaddr) + len, PAGE_SIZE);
508 return 1;
509}
510
511unsigned int bio_add_vmalloc_chunk(struct bio *bio, void *vaddr, unsigned len);
512bool bio_add_vmalloc(struct bio *bio, void *vaddr, unsigned int len);
513
514int submit_bio_wait(struct bio *bio);
515int bdev_rw_virt(struct block_device *bdev, sector_t sector, void *data,
516 size_t len, enum req_op op);
517
518int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter,
519 unsigned mem_align_mask, unsigned len_align_mask);
520
521bool bio_iov_iter_set(struct bio *bio, const struct iov_iter *iter);
522void __bio_release_pages(struct bio *bio, bool mark_dirty);
523extern void bio_set_pages_dirty(struct bio *bio);
524extern void bio_check_pages_dirty(struct bio *bio);
525
526int bio_iov_iter_bounce(struct bio *bio, struct iov_iter *iter, size_t maxlen,
527 size_t minsize);
528void bio_iov_iter_unbounce(struct bio *bio, bool is_error, bool mark_dirty);
529
530extern void bio_copy_data(struct bio *dst, struct bio *src);
531extern void bio_free_pages(struct bio *bio);
532void zero_fill_bio(struct bio *bio);
533void guard_bio_eod(struct bio *bio);
534
535static inline void bio_release_pages(struct bio *bio, bool mark_dirty)
536{
537 if (bio_flagged(bio, BIO_PAGE_PINNED))
538 __bio_release_pages(bio, mark_dirty);
539}
540
541#define bio_dev(bio) \
542 disk_devt((bio)->bi_bdev->bd_disk)
543
544#ifdef CONFIG_BLK_CGROUP
545void bio_associate_blkg(struct bio *bio);
546void bio_associate_blkg_from_css(struct bio *bio,
547 struct cgroup_subsys_state *css);
548void bio_clone_blkg_association(struct bio *dst, struct bio *src);
549void blkcg_punt_bio_submit(struct bio *bio);
550#else /* CONFIG_BLK_CGROUP */
551static inline void bio_associate_blkg(struct bio *bio) { }
552static inline void bio_associate_blkg_from_css(struct bio *bio,
553 struct cgroup_subsys_state *css)
554{ }
555static inline void bio_clone_blkg_association(struct bio *dst,
556 struct bio *src) { }
557static inline void blkcg_punt_bio_submit(struct bio *bio)
558{
559 submit_bio(bio);
560}
561#endif /* CONFIG_BLK_CGROUP */
562
563static inline void bio_set_dev(struct bio *bio, struct block_device *bdev)
564{
565 bio_clear_flag(bio, BIO_REMAPPED);
566 if (bio->bi_bdev != bdev)
567 bio_clear_flag(bio, BIO_BPS_THROTTLED);
568 bio->bi_bdev = bdev;
569 bio_associate_blkg(bio);
570}
571
572/*
573 * BIO list management for use by remapping drivers (e.g. DM or MD) and loop.
574 *
575 * A bio_list anchors a singly-linked list of bios chained through the bi_next
576 * member of the bio. The bio_list also caches the last list member to allow
577 * fast access to the tail.
578 */
579struct bio_list {
580 struct bio *head;
581 struct bio *tail;
582};
583
584static inline int bio_list_empty(const struct bio_list *bl)
585{
586 return bl->head == NULL;
587}
588
589static inline void bio_list_init(struct bio_list *bl)
590{
591 bl->head = bl->tail = NULL;
592}
593
594#define BIO_EMPTY_LIST { NULL, NULL }
595
596#define bio_list_for_each(bio, bl) \
597 for (bio = (bl)->head; bio; bio = bio->bi_next)
598
599static inline unsigned bio_list_size(const struct bio_list *bl)
600{
601 unsigned sz = 0;
602 struct bio *bio;
603
604 bio_list_for_each(bio, bl)
605 sz++;
606
607 return sz;
608}
609
610static inline void bio_list_add(struct bio_list *bl, struct bio *bio)
611{
612 bio->bi_next = NULL;
613
614 if (bl->tail)
615 bl->tail->bi_next = bio;
616 else
617 bl->head = bio;
618
619 bl->tail = bio;
620}
621
622static inline void bio_list_add_head(struct bio_list *bl, struct bio *bio)
623{
624 bio->bi_next = bl->head;
625
626 bl->head = bio;
627
628 if (!bl->tail)
629 bl->tail = bio;
630}
631
632static inline void bio_list_merge(struct bio_list *bl, struct bio_list *bl2)
633{
634 if (!bl2->head)
635 return;
636
637 if (bl->tail)
638 bl->tail->bi_next = bl2->head;
639 else
640 bl->head = bl2->head;
641
642 bl->tail = bl2->tail;
643}
644
645static inline void bio_list_merge_init(struct bio_list *bl,
646 struct bio_list *bl2)
647{
648 bio_list_merge(bl, bl2);
649 bio_list_init(bl2);
650}
651
652static inline void bio_list_merge_head(struct bio_list *bl,
653 struct bio_list *bl2)
654{
655 if (!bl2->head)
656 return;
657
658 if (bl->head)
659 bl2->tail->bi_next = bl->head;
660 else
661 bl->tail = bl2->tail;
662
663 bl->head = bl2->head;
664}
665
666static inline struct bio *bio_list_peek(struct bio_list *bl)
667{
668 return bl->head;
669}
670
671static inline struct bio *bio_list_pop(struct bio_list *bl)
672{
673 struct bio *bio = bl->head;
674
675 if (bio) {
676 bl->head = bl->head->bi_next;
677 if (!bl->head)
678 bl->tail = NULL;
679
680 bio->bi_next = NULL;
681 }
682
683 return bio;
684}
685
686static inline struct bio *bio_list_get(struct bio_list *bl)
687{
688 struct bio *bio = bl->head;
689
690 bl->head = bl->tail = NULL;
691
692 return bio;
693}
694
695/*
696 * Increment chain count for the bio. Make sure the CHAIN flag update
697 * is visible before the raised count.
698 */
699static inline void bio_inc_remaining(struct bio *bio)
700{
701 bio_set_flag(bio, BIO_CHAIN);
702 smp_mb__before_atomic();
703 atomic_inc(&bio->__bi_remaining);
704}
705
706/*
707 * bio_set is used to allow other portions of the IO system to
708 * allocate their own private memory pools for bio and iovec structures.
709 * These memory pools in turn all allocate from the bio_slab
710 * and the bvec_slabs[].
711 */
712#define BIO_POOL_SIZE 2
713
714struct bio_set {
715 struct kmem_cache *bio_slab;
716 unsigned int front_pad;
717
718 /*
719 * per-cpu bio alloc cache
720 */
721 struct bio_alloc_cache __percpu *cache;
722
723 mempool_t bio_pool;
724 mempool_t bvec_pool;
725
726 unsigned int back_pad;
727 /*
728 * Deadlock avoidance for stacking block drivers: see comments in
729 * bio_alloc_bioset() for details
730 */
731 spinlock_t rescue_lock;
732 struct bio_list rescue_list;
733 struct work_struct rescue_work;
734 struct workqueue_struct *rescue_workqueue;
735
736 /*
737 * Hot un-plug notifier for the per-cpu cache, if used
738 */
739 struct hlist_node cpuhp_dead;
740};
741
742static inline bool bioset_initialized(struct bio_set *bs)
743{
744 return bs->bio_slab != NULL;
745}
746
747static inline void bio_clear_polled(struct bio *bio)
748{
749 bio->bi_opf &= ~REQ_POLLED;
750}
751
752/**
753 * bio_is_zone_append - is this a zone append bio?
754 * @bio: bio to check
755 *
756 * Check if @bio is a zone append operation. Core block layer code and end_io
757 * handlers must use this instead of an open coded REQ_OP_ZONE_APPEND check
758 * because the block layer can rewrite REQ_OP_ZONE_APPEND to REQ_OP_WRITE if
759 * it is not natively supported.
760 */
761static inline bool bio_is_zone_append(struct bio *bio)
762{
763 if (!IS_ENABLED(CONFIG_BLK_DEV_ZONED))
764 return false;
765 return bio_op(bio) == REQ_OP_ZONE_APPEND ||
766 bio_flagged(bio, BIO_EMULATES_ZONE_APPEND);
767}
768
769struct bio *blk_next_bio(struct bio *bio, struct block_device *bdev,
770 unsigned int nr_pages, blk_opf_t opf, gfp_t gfp);
771struct bio *bio_chain_and_submit(struct bio *prev, struct bio *new);
772
773struct bio *blk_alloc_discard_bio(struct block_device *bdev,
774 sector_t *sector, sector_t *nr_sects, gfp_t gfp_mask);
775
776#endif /* __LINUX_BIO_H */