~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/bio.h

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /include/linux/bio.h (Version linux-6.12-rc7) and /include/linux/bio.h (Version linux-5.11.22)


  1 /* SPDX-License-Identifier: GPL-2.0 */              1 /* SPDX-License-Identifier: GPL-2.0 */
  2 /*                                                  2 /*
  3  * Copyright (C) 2001 Jens Axboe <axboe@suse.d      3  * Copyright (C) 2001 Jens Axboe <axboe@suse.de>
  4  */                                                 4  */
  5 #ifndef __LINUX_BIO_H                               5 #ifndef __LINUX_BIO_H
  6 #define __LINUX_BIO_H                               6 #define __LINUX_BIO_H
  7                                                     7 
                                                   >>   8 #include <linux/highmem.h>
  8 #include <linux/mempool.h>                          9 #include <linux/mempool.h>
                                                   >>  10 #include <linux/ioprio.h>
  9 /* struct bio, bio_vec and BIO_* flags are def     11 /* struct bio, bio_vec and BIO_* flags are defined in blk_types.h */
 10 #include <linux/blk_types.h>                       12 #include <linux/blk_types.h>
 11 #include <linux/uio.h>                         << 
 12                                                    13 
 13 #define BIO_MAX_VECS            256U           !!  14 #define BIO_DEBUG
 14                                                    15 
 15 struct queue_limits;                           !!  16 #ifdef BIO_DEBUG
                                                   >>  17 #define BIO_BUG_ON      BUG_ON
                                                   >>  18 #else
                                                   >>  19 #define BIO_BUG_ON
                                                   >>  20 #endif
 16                                                    21 
 17 static inline unsigned int bio_max_segs(unsign !!  22 #define BIO_MAX_PAGES           256
 18 {                                              << 
 19         return min(nr_segs, BIO_MAX_VECS);     << 
 20 }                                              << 
 21                                                    23 
 22 #define bio_prio(bio)                   (bio)-     24 #define bio_prio(bio)                   (bio)->bi_ioprio
 23 #define bio_set_prio(bio, prio)         ((bio)     25 #define bio_set_prio(bio, prio)         ((bio)->bi_ioprio = prio)
 24                                                    26 
 25 #define bio_iter_iovec(bio, iter)                  27 #define bio_iter_iovec(bio, iter)                               \
 26         bvec_iter_bvec((bio)->bi_io_vec, (iter     28         bvec_iter_bvec((bio)->bi_io_vec, (iter))
 27                                                    29 
 28 #define bio_iter_page(bio, iter)                   30 #define bio_iter_page(bio, iter)                                \
 29         bvec_iter_page((bio)->bi_io_vec, (iter     31         bvec_iter_page((bio)->bi_io_vec, (iter))
 30 #define bio_iter_len(bio, iter)                    32 #define bio_iter_len(bio, iter)                                 \
 31         bvec_iter_len((bio)->bi_io_vec, (iter)     33         bvec_iter_len((bio)->bi_io_vec, (iter))
 32 #define bio_iter_offset(bio, iter)                 34 #define bio_iter_offset(bio, iter)                              \
 33         bvec_iter_offset((bio)->bi_io_vec, (it     35         bvec_iter_offset((bio)->bi_io_vec, (iter))
 34                                                    36 
 35 #define bio_page(bio)           bio_iter_page(     37 #define bio_page(bio)           bio_iter_page((bio), (bio)->bi_iter)
 36 #define bio_offset(bio)         bio_iter_offse     38 #define bio_offset(bio)         bio_iter_offset((bio), (bio)->bi_iter)
 37 #define bio_iovec(bio)          bio_iter_iovec     39 #define bio_iovec(bio)          bio_iter_iovec((bio), (bio)->bi_iter)
 38                                                    40 
                                                   >>  41 #define bio_multiple_segments(bio)                              \
                                                   >>  42         ((bio)->bi_iter.bi_size != bio_iovec(bio).bv_len)
                                                   >>  43 
 39 #define bvec_iter_sectors(iter) ((iter).bi_siz     44 #define bvec_iter_sectors(iter) ((iter).bi_size >> 9)
 40 #define bvec_iter_end_sector(iter) ((iter).bi_     45 #define bvec_iter_end_sector(iter) ((iter).bi_sector + bvec_iter_sectors((iter)))
 41                                                    46 
 42 #define bio_sectors(bio)        bvec_iter_sect     47 #define bio_sectors(bio)        bvec_iter_sectors((bio)->bi_iter)
 43 #define bio_end_sector(bio)     bvec_iter_end_     48 #define bio_end_sector(bio)     bvec_iter_end_sector((bio)->bi_iter)
 44                                                    49 
 45 /*                                                 50 /*
 46  * Return the data direction, READ or WRITE.       51  * Return the data direction, READ or WRITE.
 47  */                                                52  */
 48 #define bio_data_dir(bio) \                        53 #define bio_data_dir(bio) \
 49         (op_is_write(bio_op(bio)) ? WRITE : RE     54         (op_is_write(bio_op(bio)) ? WRITE : READ)
 50                                                    55 
 51 /*                                                 56 /*
 52  * Check whether this bio carries any data or      57  * Check whether this bio carries any data or not. A NULL bio is allowed.
 53  */                                                58  */
 54 static inline bool bio_has_data(struct bio *bi     59 static inline bool bio_has_data(struct bio *bio)
 55 {                                                  60 {
 56         if (bio &&                                 61         if (bio &&
 57             bio->bi_iter.bi_size &&                62             bio->bi_iter.bi_size &&
 58             bio_op(bio) != REQ_OP_DISCARD &&       63             bio_op(bio) != REQ_OP_DISCARD &&
 59             bio_op(bio) != REQ_OP_SECURE_ERASE     64             bio_op(bio) != REQ_OP_SECURE_ERASE &&
 60             bio_op(bio) != REQ_OP_WRITE_ZEROES     65             bio_op(bio) != REQ_OP_WRITE_ZEROES)
 61                 return true;                       66                 return true;
 62                                                    67 
 63         return false;                              68         return false;
 64 }                                                  69 }
 65                                                    70 
 66 static inline bool bio_no_advance_iter(const s     71 static inline bool bio_no_advance_iter(const struct bio *bio)
 67 {                                                  72 {
 68         return bio_op(bio) == REQ_OP_DISCARD |     73         return bio_op(bio) == REQ_OP_DISCARD ||
 69                bio_op(bio) == REQ_OP_SECURE_ER     74                bio_op(bio) == REQ_OP_SECURE_ERASE ||
                                                   >>  75                bio_op(bio) == REQ_OP_WRITE_SAME ||
 70                bio_op(bio) == REQ_OP_WRITE_ZER     76                bio_op(bio) == REQ_OP_WRITE_ZEROES;
 71 }                                                  77 }
 72                                                    78 
                                                   >>  79 static inline bool bio_mergeable(struct bio *bio)
                                                   >>  80 {
                                                   >>  81         if (bio->bi_opf & REQ_NOMERGE_FLAGS)
                                                   >>  82                 return false;
                                                   >>  83 
                                                   >>  84         return true;
                                                   >>  85 }
                                                   >>  86 
                                                   >>  87 static inline unsigned int bio_cur_bytes(struct bio *bio)
                                                   >>  88 {
                                                   >>  89         if (bio_has_data(bio))
                                                   >>  90                 return bio_iovec(bio).bv_len;
                                                   >>  91         else /* dataless requests such as discard */
                                                   >>  92                 return bio->bi_iter.bi_size;
                                                   >>  93 }
                                                   >>  94 
 73 static inline void *bio_data(struct bio *bio)      95 static inline void *bio_data(struct bio *bio)
 74 {                                                  96 {
 75         if (bio_has_data(bio))                     97         if (bio_has_data(bio))
 76                 return page_address(bio_page(b     98                 return page_address(bio_page(bio)) + bio_offset(bio);
 77                                                    99 
 78         return NULL;                              100         return NULL;
 79 }                                                 101 }
 80                                                   102 
                                                   >> 103 /**
                                                   >> 104  * bio_full - check if the bio is full
                                                   >> 105  * @bio:        bio to check
                                                   >> 106  * @len:        length of one segment to be added
                                                   >> 107  *
                                                   >> 108  * Return true if @bio is full and one segment with @len bytes can't be
                                                   >> 109  * added to the bio, otherwise return false
                                                   >> 110  */
                                                   >> 111 static inline bool bio_full(struct bio *bio, unsigned len)
                                                   >> 112 {
                                                   >> 113         if (bio->bi_vcnt >= bio->bi_max_vecs)
                                                   >> 114                 return true;
                                                   >> 115 
                                                   >> 116         if (bio->bi_iter.bi_size > UINT_MAX - len)
                                                   >> 117                 return true;
                                                   >> 118 
                                                   >> 119         return false;
                                                   >> 120 }
                                                   >> 121 
 81 static inline bool bio_next_segment(const stru    122 static inline bool bio_next_segment(const struct bio *bio,
 82                                     struct bve    123                                     struct bvec_iter_all *iter)
 83 {                                                 124 {
 84         if (iter->idx >= bio->bi_vcnt)            125         if (iter->idx >= bio->bi_vcnt)
 85                 return false;                     126                 return false;
 86                                                   127 
 87         bvec_advance(&bio->bi_io_vec[iter->idx    128         bvec_advance(&bio->bi_io_vec[iter->idx], iter);
 88         return true;                              129         return true;
 89 }                                                 130 }
 90                                                   131 
 91 /*                                                132 /*
 92  * drivers should _never_ use the all version     133  * drivers should _never_ use the all version - the bio may have been split
 93  * before it got to the driver and the driver     134  * before it got to the driver and the driver won't own all of it
 94  */                                               135  */
 95 #define bio_for_each_segment_all(bvl, bio, ite    136 #define bio_for_each_segment_all(bvl, bio, iter) \
 96         for (bvl = bvec_init_iter_all(&iter);     137         for (bvl = bvec_init_iter_all(&iter); bio_next_segment((bio), &iter); )
 97                                                   138 
 98 static inline void bio_advance_iter(const stru    139 static inline void bio_advance_iter(const struct bio *bio,
 99                                     struct bve    140                                     struct bvec_iter *iter, unsigned int bytes)
100 {                                                 141 {
101         iter->bi_sector += bytes >> 9;            142         iter->bi_sector += bytes >> 9;
102                                                   143 
103         if (bio_no_advance_iter(bio))             144         if (bio_no_advance_iter(bio))
104                 iter->bi_size -= bytes;           145                 iter->bi_size -= bytes;
105         else                                      146         else
106                 bvec_iter_advance(bio->bi_io_v    147                 bvec_iter_advance(bio->bi_io_vec, iter, bytes);
107                 /* TODO: It is reasonable to c    148                 /* TODO: It is reasonable to complete bio with error here. */
108 }                                                 149 }
109                                                   150 
110 /* @bytes should be less or equal to bvec[i->b    151 /* @bytes should be less or equal to bvec[i->bi_idx].bv_len */
111 static inline void bio_advance_iter_single(con    152 static inline void bio_advance_iter_single(const struct bio *bio,
112                                            str    153                                            struct bvec_iter *iter,
113                                            uns    154                                            unsigned int bytes)
114 {                                                 155 {
115         iter->bi_sector += bytes >> 9;            156         iter->bi_sector += bytes >> 9;
116                                                   157 
117         if (bio_no_advance_iter(bio))             158         if (bio_no_advance_iter(bio))
118                 iter->bi_size -= bytes;           159                 iter->bi_size -= bytes;
119         else                                      160         else
120                 bvec_iter_advance_single(bio->    161                 bvec_iter_advance_single(bio->bi_io_vec, iter, bytes);
121 }                                                 162 }
122                                                   163 
123 void __bio_advance(struct bio *, unsigned byte << 
124                                                << 
125 /**                                            << 
126  * bio_advance - increment/complete a bio by s << 
127  * @bio:        bio to advance                 << 
128  * @nbytes:     number of bytes to complete    << 
129  *                                             << 
130  * This updates bi_sector, bi_size and bi_idx; << 
131  * complete doesn't align with a bvec boundary << 
132  * be updated on the last bvec as well.        << 
133  *                                             << 
134  * @bio will then represent the remaining, unc << 
135  */                                            << 
136 static inline void bio_advance(struct bio *bio << 
137 {                                              << 
138         if (nbytes == bio->bi_iter.bi_size) {  << 
139                 bio->bi_iter.bi_size = 0;      << 
140                 return;                        << 
141         }                                      << 
142         __bio_advance(bio, nbytes);            << 
143 }                                              << 
144                                                << 
145 #define __bio_for_each_segment(bvl, bio, iter,    164 #define __bio_for_each_segment(bvl, bio, iter, start)                   \
146         for (iter = (start);                      165         for (iter = (start);                                            \
147              (iter).bi_size &&                    166              (iter).bi_size &&                                          \
148                 ((bvl = bio_iter_iovec((bio),     167                 ((bvl = bio_iter_iovec((bio), (iter))), 1);             \
149              bio_advance_iter_single((bio), &(    168              bio_advance_iter_single((bio), &(iter), (bvl).bv_len))
150                                                   169 
151 #define bio_for_each_segment(bvl, bio, iter)      170 #define bio_for_each_segment(bvl, bio, iter)                            \
152         __bio_for_each_segment(bvl, bio, iter,    171         __bio_for_each_segment(bvl, bio, iter, (bio)->bi_iter)
153                                                   172 
154 #define __bio_for_each_bvec(bvl, bio, iter, st    173 #define __bio_for_each_bvec(bvl, bio, iter, start)              \
155         for (iter = (start);                      174         for (iter = (start);                                            \
156              (iter).bi_size &&                    175              (iter).bi_size &&                                          \
157                 ((bvl = mp_bvec_iter_bvec((bio    176                 ((bvl = mp_bvec_iter_bvec((bio)->bi_io_vec, (iter))), 1); \
158              bio_advance_iter_single((bio), &(    177              bio_advance_iter_single((bio), &(iter), (bvl).bv_len))
159                                                   178 
160 /* iterate over multi-page bvec */                179 /* iterate over multi-page bvec */
161 #define bio_for_each_bvec(bvl, bio, iter)         180 #define bio_for_each_bvec(bvl, bio, iter)                       \
162         __bio_for_each_bvec(bvl, bio, iter, (b    181         __bio_for_each_bvec(bvl, bio, iter, (bio)->bi_iter)
163                                                   182 
164 /*                                                183 /*
165  * Iterate over all multi-page bvecs. Drivers     184  * Iterate over all multi-page bvecs. Drivers shouldn't use this version for the
166  * same reasons as bio_for_each_segment_all().    185  * same reasons as bio_for_each_segment_all().
167  */                                               186  */
168 #define bio_for_each_bvec_all(bvl, bio, i)        187 #define bio_for_each_bvec_all(bvl, bio, i)              \
169         for (i = 0, bvl = bio_first_bvec_all(b    188         for (i = 0, bvl = bio_first_bvec_all(bio);      \
170              i < (bio)->bi_vcnt; i++, bvl++)   !! 189              i < (bio)->bi_vcnt; i++, bvl++)            \
171                                                   190 
172 #define bio_iter_last(bvec, iter) ((iter).bi_s    191 #define bio_iter_last(bvec, iter) ((iter).bi_size == (bvec).bv_len)
173                                                   192 
174 static inline unsigned bio_segments(struct bio    193 static inline unsigned bio_segments(struct bio *bio)
175 {                                                 194 {
176         unsigned segs = 0;                        195         unsigned segs = 0;
177         struct bio_vec bv;                        196         struct bio_vec bv;
178         struct bvec_iter iter;                    197         struct bvec_iter iter;
179                                                   198 
180         /*                                        199         /*
181          * We special case discard/write same/    200          * We special case discard/write same/write zeroes, because they
182          * interpret bi_size differently:         201          * interpret bi_size differently:
183          */                                       202          */
184                                                   203 
185         switch (bio_op(bio)) {                    204         switch (bio_op(bio)) {
186         case REQ_OP_DISCARD:                      205         case REQ_OP_DISCARD:
187         case REQ_OP_SECURE_ERASE:                 206         case REQ_OP_SECURE_ERASE:
188         case REQ_OP_WRITE_ZEROES:                 207         case REQ_OP_WRITE_ZEROES:
189                 return 0;                         208                 return 0;
                                                   >> 209         case REQ_OP_WRITE_SAME:
                                                   >> 210                 return 1;
190         default:                                  211         default:
191                 break;                            212                 break;
192         }                                         213         }
193                                                   214 
194         bio_for_each_segment(bv, bio, iter)       215         bio_for_each_segment(bv, bio, iter)
195                 segs++;                           216                 segs++;
196                                                   217 
197         return segs;                              218         return segs;
198 }                                                 219 }
199                                                   220 
200 /*                                                221 /*
201  * get a reference to a bio, so it won't disap    222  * get a reference to a bio, so it won't disappear. the intended use is
202  * something like:                                223  * something like:
203  *                                                224  *
204  * bio_get(bio);                                  225  * bio_get(bio);
205  * submit_bio(rw, bio);                           226  * submit_bio(rw, bio);
206  * if (bio->bi_flags ...)                         227  * if (bio->bi_flags ...)
207  *      do_something                              228  *      do_something
208  * bio_put(bio);                                  229  * bio_put(bio);
209  *                                                230  *
210  * without the bio_get(), it could potentially    231  * without the bio_get(), it could potentially complete I/O before submit_bio
211  * returns. and then bio would be freed memory    232  * returns. and then bio would be freed memory when if (bio->bi_flags ...)
212  * runs                                           233  * runs
213  */                                               234  */
214 static inline void bio_get(struct bio *bio)       235 static inline void bio_get(struct bio *bio)
215 {                                                 236 {
216         bio->bi_flags |= (1 << BIO_REFFED);       237         bio->bi_flags |= (1 << BIO_REFFED);
217         smp_mb__before_atomic();                  238         smp_mb__before_atomic();
218         atomic_inc(&bio->__bi_cnt);               239         atomic_inc(&bio->__bi_cnt);
219 }                                                 240 }
220                                                   241 
221 static inline void bio_cnt_set(struct bio *bio    242 static inline void bio_cnt_set(struct bio *bio, unsigned int count)
222 {                                                 243 {
223         if (count != 1) {                         244         if (count != 1) {
224                 bio->bi_flags |= (1 << BIO_REF    245                 bio->bi_flags |= (1 << BIO_REFFED);
225                 smp_mb();                         246                 smp_mb();
226         }                                         247         }
227         atomic_set(&bio->__bi_cnt, count);        248         atomic_set(&bio->__bi_cnt, count);
228 }                                                 249 }
229                                                   250 
230 static inline bool bio_flagged(struct bio *bio    251 static inline bool bio_flagged(struct bio *bio, unsigned int bit)
231 {                                                 252 {
232         return bio->bi_flags & (1U << bit);    !! 253         return (bio->bi_flags & (1U << bit)) != 0;
233 }                                                 254 }
234                                                   255 
235 static inline void bio_set_flag(struct bio *bi    256 static inline void bio_set_flag(struct bio *bio, unsigned int bit)
236 {                                                 257 {
237         bio->bi_flags |= (1U << bit);             258         bio->bi_flags |= (1U << bit);
238 }                                                 259 }
239                                                   260 
240 static inline void bio_clear_flag(struct bio *    261 static inline void bio_clear_flag(struct bio *bio, unsigned int bit)
241 {                                                 262 {
242         bio->bi_flags &= ~(1U << bit);            263         bio->bi_flags &= ~(1U << bit);
243 }                                                 264 }
244                                                   265 
                                                   >> 266 static inline void bio_get_first_bvec(struct bio *bio, struct bio_vec *bv)
                                                   >> 267 {
                                                   >> 268         *bv = bio_iovec(bio);
                                                   >> 269 }
                                                   >> 270 
                                                   >> 271 static inline void bio_get_last_bvec(struct bio *bio, struct bio_vec *bv)
                                                   >> 272 {
                                                   >> 273         struct bvec_iter iter = bio->bi_iter;
                                                   >> 274         int idx;
                                                   >> 275 
                                                   >> 276         if (unlikely(!bio_multiple_segments(bio))) {
                                                   >> 277                 *bv = bio_iovec(bio);
                                                   >> 278                 return;
                                                   >> 279         }
                                                   >> 280 
                                                   >> 281         bio_advance_iter(bio, &iter, iter.bi_size);
                                                   >> 282 
                                                   >> 283         if (!iter.bi_bvec_done)
                                                   >> 284                 idx = iter.bi_idx - 1;
                                                   >> 285         else    /* in the middle of bvec */
                                                   >> 286                 idx = iter.bi_idx;
                                                   >> 287 
                                                   >> 288         *bv = bio->bi_io_vec[idx];
                                                   >> 289 
                                                   >> 290         /*
                                                   >> 291          * iter.bi_bvec_done records actual length of the last bvec
                                                   >> 292          * if this bio ends in the middle of one io vector
                                                   >> 293          */
                                                   >> 294         if (iter.bi_bvec_done)
                                                   >> 295                 bv->bv_len = iter.bi_bvec_done;
                                                   >> 296 }
                                                   >> 297 
245 static inline struct bio_vec *bio_first_bvec_a    298 static inline struct bio_vec *bio_first_bvec_all(struct bio *bio)
246 {                                                 299 {
247         WARN_ON_ONCE(bio_flagged(bio, BIO_CLON    300         WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED));
248         return bio->bi_io_vec;                    301         return bio->bi_io_vec;
249 }                                                 302 }
250                                                   303 
251 static inline struct page *bio_first_page_all(    304 static inline struct page *bio_first_page_all(struct bio *bio)
252 {                                                 305 {
253         return bio_first_bvec_all(bio)->bv_pag    306         return bio_first_bvec_all(bio)->bv_page;
254 }                                                 307 }
255                                                   308 
256 static inline struct folio *bio_first_folio_al << 
257 {                                              << 
258         return page_folio(bio_first_page_all(b << 
259 }                                              << 
260                                                << 
261 static inline struct bio_vec *bio_last_bvec_al    309 static inline struct bio_vec *bio_last_bvec_all(struct bio *bio)
262 {                                                 310 {
263         WARN_ON_ONCE(bio_flagged(bio, BIO_CLON    311         WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED));
264         return &bio->bi_io_vec[bio->bi_vcnt -     312         return &bio->bi_io_vec[bio->bi_vcnt - 1];
265 }                                                 313 }
266                                                   314 
267 /**                                            !! 315 enum bip_flags {
268  * struct folio_iter - State for iterating all !! 316         BIP_BLOCK_INTEGRITY     = 1 << 0, /* block layer owns integrity data */
269  * @folio: The current folio we're iterating.  !! 317         BIP_MAPPED_INTEGRITY    = 1 << 1, /* ref tag has been remapped */
270  * @offset: The byte offset within the current !! 318         BIP_CTRL_NOCHECK        = 1 << 2, /* disable HBA integrity checking */
271  * @length: The number of bytes in this iterat !! 319         BIP_DISK_NOCHECK        = 1 << 3, /* disable disk integrity checking */
272  *      boundary).                             !! 320         BIP_IP_CHECKSUM         = 1 << 4, /* IP checksum */
273  */                                            << 
274 struct folio_iter {                            << 
275         struct folio *folio;                   << 
276         size_t offset;                         << 
277         size_t length;                         << 
278         /* private: for use by the iterator */ << 
279         struct folio *_next;                   << 
280         size_t _seg_count;                     << 
281         int _i;                                << 
282 };                                                321 };
283                                                   322 
284 static inline void bio_first_folio(struct foli !! 323 /*
285                                    int i)      !! 324  * bio integrity payload
                                                   >> 325  */
                                                   >> 326 struct bio_integrity_payload {
                                                   >> 327         struct bio              *bip_bio;       /* parent bio */
                                                   >> 328 
                                                   >> 329         struct bvec_iter        bip_iter;
                                                   >> 330 
                                                   >> 331         unsigned short          bip_slab;       /* slab the bip came from */
                                                   >> 332         unsigned short          bip_vcnt;       /* # of integrity bio_vecs */
                                                   >> 333         unsigned short          bip_max_vcnt;   /* integrity bio_vec slots */
                                                   >> 334         unsigned short          bip_flags;      /* control flags */
                                                   >> 335 
                                                   >> 336         struct bvec_iter        bio_iter;       /* for rewinding parent bio */
                                                   >> 337 
                                                   >> 338         struct work_struct      bip_work;       /* I/O completion */
                                                   >> 339 
                                                   >> 340         struct bio_vec          *bip_vec;
                                                   >> 341         struct bio_vec          bip_inline_vecs[];/* embedded bvec array */
                                                   >> 342 };
                                                   >> 343 
                                                   >> 344 #if defined(CONFIG_BLK_DEV_INTEGRITY)
                                                   >> 345 
                                                   >> 346 static inline struct bio_integrity_payload *bio_integrity(struct bio *bio)
286 {                                                 347 {
287         struct bio_vec *bvec = bio_first_bvec_ !! 348         if (bio->bi_opf & REQ_INTEGRITY)
                                                   >> 349                 return bio->bi_integrity;
288                                                   350 
289         if (unlikely(i >= bio->bi_vcnt)) {     !! 351         return NULL;
290                 fi->folio = NULL;              !! 352 }
291                 return;                        << 
292         }                                      << 
293                                                   353 
294         fi->folio = page_folio(bvec->bv_page); !! 354 static inline bool bio_integrity_flagged(struct bio *bio, enum bip_flags flag)
295         fi->offset = bvec->bv_offset +         !! 355 {
296                         PAGE_SIZE * (bvec->bv_ !! 356         struct bio_integrity_payload *bip = bio_integrity(bio);
297         fi->_seg_count = bvec->bv_len;         !! 357 
298         fi->length = min(folio_size(fi->folio) !! 358         if (bip)
299         fi->_next = folio_next(fi->folio);     !! 359                 return bip->bip_flags & flag;
300         fi->_i = i;                            !! 360 
301 }                                              !! 361         return false;
302                                                << 
303 static inline void bio_next_folio(struct folio << 
304 {                                              << 
305         fi->_seg_count -= fi->length;          << 
306         if (fi->_seg_count) {                  << 
307                 fi->folio = fi->_next;         << 
308                 fi->offset = 0;                << 
309                 fi->length = min(folio_size(fi << 
310                 fi->_next = folio_next(fi->fol << 
311         } else {                               << 
312                 bio_first_folio(fi, bio, fi->_ << 
313         }                                      << 
314 }                                                 362 }
315                                                   363 
316 /**                                            !! 364 static inline sector_t bip_get_seed(struct bio_integrity_payload *bip)
317  * bio_for_each_folio_all - Iterate over each  !! 365 {
318  * @fi: struct folio_iter which is updated for !! 366         return bip->bip_iter.bi_sector;
319  * @bio: struct bio to iterate over.           !! 367 }
320  */                                            !! 368 
321 #define bio_for_each_folio_all(fi, bio)        !! 369 static inline void bip_set_seed(struct bio_integrity_payload *bip,
322         for (bio_first_folio(&fi, bio, 0); fi. !! 370                                 sector_t seed)
                                                   >> 371 {
                                                   >> 372         bip->bip_iter.bi_sector = seed;
                                                   >> 373 }
                                                   >> 374 
                                                   >> 375 #endif /* CONFIG_BLK_DEV_INTEGRITY */
323                                                   376 
324 void bio_trim(struct bio *bio, sector_t offset !! 377 extern void bio_trim(struct bio *bio, int offset, int size);
325 extern struct bio *bio_split(struct bio *bio,     378 extern struct bio *bio_split(struct bio *bio, int sectors,
326                              gfp_t gfp, struct    379                              gfp_t gfp, struct bio_set *bs);
327 int bio_split_rw_at(struct bio *bio, const str << 
328                 unsigned *segs, unsigned max_b << 
329                                                   380 
330 /**                                               381 /**
331  * bio_next_split - get next @sectors from a b    382  * bio_next_split - get next @sectors from a bio, splitting if necessary
332  * @bio:        bio to split                      383  * @bio:        bio to split
333  * @sectors:    number of sectors to split fro    384  * @sectors:    number of sectors to split from the front of @bio
334  * @gfp:        gfp mask                          385  * @gfp:        gfp mask
335  * @bs:         bio set to allocate from          386  * @bs:         bio set to allocate from
336  *                                                387  *
337  * Return: a bio representing the next @sector !! 388  * Returns a bio representing the next @sectors of @bio - if the bio is smaller
338  * than @sectors, returns the original bio unc    389  * than @sectors, returns the original bio unchanged.
339  */                                               390  */
340 static inline struct bio *bio_next_split(struc    391 static inline struct bio *bio_next_split(struct bio *bio, int sectors,
341                                          gfp_t    392                                          gfp_t gfp, struct bio_set *bs)
342 {                                                 393 {
343         if (sectors >= bio_sectors(bio))          394         if (sectors >= bio_sectors(bio))
344                 return bio;                       395                 return bio;
345                                                   396 
346         return bio_split(bio, sectors, gfp, bs    397         return bio_split(bio, sectors, gfp, bs);
347 }                                                 398 }
348                                                   399 
349 enum {                                            400 enum {
350         BIOSET_NEED_BVECS = BIT(0),               401         BIOSET_NEED_BVECS = BIT(0),
351         BIOSET_NEED_RESCUER = BIT(1),             402         BIOSET_NEED_RESCUER = BIT(1),
352         BIOSET_PERCPU_CACHE = BIT(2),          << 
353 };                                                403 };
354 extern int bioset_init(struct bio_set *, unsig    404 extern int bioset_init(struct bio_set *, unsigned int, unsigned int, int flags);
355 extern void bioset_exit(struct bio_set *);        405 extern void bioset_exit(struct bio_set *);
356 extern int biovec_init_pool(mempool_t *pool, i    406 extern int biovec_init_pool(mempool_t *pool, int pool_entries);
                                                   >> 407 extern int bioset_init_from_src(struct bio_set *bs, struct bio_set *src);
357                                                   408 
358 struct bio *bio_alloc_bioset(struct block_devi !! 409 extern struct bio *bio_alloc_bioset(gfp_t, unsigned int, struct bio_set *);
359                              blk_opf_t opf, gf << 
360                              struct bio_set *b << 
361 struct bio *bio_kmalloc(unsigned short nr_vecs << 
362 extern void bio_put(struct bio *);                410 extern void bio_put(struct bio *);
363                                                   411 
364 struct bio *bio_alloc_clone(struct block_devic !! 412 extern void __bio_clone_fast(struct bio *, struct bio *);
365                 gfp_t gfp, struct bio_set *bs) !! 413 extern struct bio *bio_clone_fast(struct bio *, gfp_t, struct bio_set *);
366 int bio_init_clone(struct block_device *bdev,  << 
367                 struct bio *bio_src, gfp_t gfp << 
368                                                   414 
369 extern struct bio_set fs_bio_set;                 415 extern struct bio_set fs_bio_set;
370                                                   416 
371 static inline struct bio *bio_alloc(struct blo !! 417 static inline struct bio *bio_alloc(gfp_t gfp_mask, unsigned int nr_iovecs)
372                 unsigned short nr_vecs, blk_op !! 418 {
                                                   >> 419         return bio_alloc_bioset(gfp_mask, nr_iovecs, &fs_bio_set);
                                                   >> 420 }
                                                   >> 421 
                                                   >> 422 static inline struct bio *bio_kmalloc(gfp_t gfp_mask, unsigned int nr_iovecs)
373 {                                                 423 {
374         return bio_alloc_bioset(bdev, nr_vecs, !! 424         return bio_alloc_bioset(gfp_mask, nr_iovecs, NULL);
375 }                                                 425 }
376                                                   426 
377 void submit_bio(struct bio *bio);              !! 427 extern blk_qc_t submit_bio(struct bio *);
378                                                   428 
379 extern void bio_endio(struct bio *);              429 extern void bio_endio(struct bio *);
380                                                   430 
381 static inline void bio_io_error(struct bio *bi    431 static inline void bio_io_error(struct bio *bio)
382 {                                                 432 {
383         bio->bi_status = BLK_STS_IOERR;           433         bio->bi_status = BLK_STS_IOERR;
384         bio_endio(bio);                           434         bio_endio(bio);
385 }                                                 435 }
386                                                   436 
387 static inline void bio_wouldblock_error(struct    437 static inline void bio_wouldblock_error(struct bio *bio)
388 {                                                 438 {
389         bio_set_flag(bio, BIO_QUIET);             439         bio_set_flag(bio, BIO_QUIET);
390         bio->bi_status = BLK_STS_AGAIN;           440         bio->bi_status = BLK_STS_AGAIN;
391         bio_endio(bio);                           441         bio_endio(bio);
392 }                                                 442 }
393                                                   443 
394 /*                                             << 
395  * Calculate number of bvec segments that shou << 
396  * pointed by @iter. If @iter is backed by bve << 
397  * instead of allocating a new one.            << 
398  */                                            << 
399 static inline int bio_iov_vecs_to_alloc(struct << 
400 {                                              << 
401         if (iov_iter_is_bvec(iter))            << 
402                 return 0;                      << 
403         return iov_iter_npages(iter, max_segs) << 
404 }                                              << 
405                                                << 
406 struct request_queue;                             444 struct request_queue;
407                                                   445 
408 extern int submit_bio_wait(struct bio *bio);      446 extern int submit_bio_wait(struct bio *bio);
409 void bio_init(struct bio *bio, struct block_de !! 447 extern void bio_advance(struct bio *, unsigned);
410               unsigned short max_vecs, blk_opf !! 448 
                                                   >> 449 extern void bio_init(struct bio *bio, struct bio_vec *table,
                                                   >> 450                      unsigned short max_vecs);
411 extern void bio_uninit(struct bio *);             451 extern void bio_uninit(struct bio *);
412 void bio_reset(struct bio *bio, struct block_d !! 452 extern void bio_reset(struct bio *);
413 void bio_chain(struct bio *, struct bio *);       453 void bio_chain(struct bio *, struct bio *);
414                                                   454 
415 int __must_check bio_add_page(struct bio *bio, !! 455 extern int bio_add_page(struct bio *, struct page *, unsigned int,unsigned int);
416                               unsigned off);   << 
417 bool __must_check bio_add_folio(struct bio *bi << 
418                                 size_t len, si << 
419 extern int bio_add_pc_page(struct request_queu    456 extern int bio_add_pc_page(struct request_queue *, struct bio *, struct page *,
420                            unsigned int, unsig    457                            unsigned int, unsigned int);
421 int bio_add_zone_append_page(struct bio *bio,  !! 458 bool __bio_try_merge_page(struct bio *bio, struct page *page,
422                              unsigned int len, !! 459                 unsigned int len, unsigned int off, bool *same_page);
423 void __bio_add_page(struct bio *bio, struct pa    460 void __bio_add_page(struct bio *bio, struct page *page,
424                 unsigned int len, unsigned int    461                 unsigned int len, unsigned int off);
425 void bio_add_folio_nofail(struct bio *bio, str << 
426                           size_t off);         << 
427 int bio_iov_iter_get_pages(struct bio *bio, st    462 int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter);
428 void bio_iov_bvec_set(struct bio *bio, struct  !! 463 void bio_release_pages(struct bio *bio, bool mark_dirty);
429 void __bio_release_pages(struct bio *bio, bool << 
430 extern void bio_set_pages_dirty(struct bio *bi    464 extern void bio_set_pages_dirty(struct bio *bio);
431 extern void bio_check_pages_dirty(struct bio *    465 extern void bio_check_pages_dirty(struct bio *bio);
432                                                   466 
433 extern void bio_copy_data_iter(struct bio *dst    467 extern void bio_copy_data_iter(struct bio *dst, struct bvec_iter *dst_iter,
434                                struct bio *src    468                                struct bio *src, struct bvec_iter *src_iter);
435 extern void bio_copy_data(struct bio *dst, str    469 extern void bio_copy_data(struct bio *dst, struct bio *src);
                                                   >> 470 extern void bio_list_copy_data(struct bio *dst, struct bio *src);
436 extern void bio_free_pages(struct bio *bio);      471 extern void bio_free_pages(struct bio *bio);
437 void guard_bio_eod(struct bio *bio);           << 
438 void zero_fill_bio_iter(struct bio *bio, struc    472 void zero_fill_bio_iter(struct bio *bio, struct bvec_iter iter);
                                                   >> 473 void bio_truncate(struct bio *bio, unsigned new_size);
                                                   >> 474 void guard_bio_eod(struct bio *bio);
439                                                   475 
440 static inline void zero_fill_bio(struct bio *b    476 static inline void zero_fill_bio(struct bio *bio)
441 {                                                 477 {
442         zero_fill_bio_iter(bio, bio->bi_iter);    478         zero_fill_bio_iter(bio, bio->bi_iter);
443 }                                                 479 }
444                                                   480 
445 static inline void bio_release_pages(struct bi !! 481 extern struct bio_vec *bvec_alloc(gfp_t, int, unsigned long *, mempool_t *);
446 {                                              !! 482 extern void bvec_free(mempool_t *, struct bio_vec *, unsigned int);
447         if (bio_flagged(bio, BIO_PAGE_PINNED)) !! 483 extern unsigned int bvec_nr_vecs(unsigned short idx);
448                 __bio_release_pages(bio, mark_ !! 484 extern const char *bio_devname(struct bio *bio, char *buffer);
449 }                                              !! 485 
                                                   >> 486 #define bio_set_dev(bio, bdev)                  \
                                                   >> 487 do {                                            \
                                                   >> 488         if ((bio)->bi_disk != (bdev)->bd_disk)  \
                                                   >> 489                 bio_clear_flag(bio, BIO_THROTTLED);\
                                                   >> 490         (bio)->bi_disk = (bdev)->bd_disk;       \
                                                   >> 491         (bio)->bi_partno = (bdev)->bd_partno;   \
                                                   >> 492         bio_associate_blkg(bio);                \
                                                   >> 493 } while (0)
                                                   >> 494 
                                                   >> 495 #define bio_copy_dev(dst, src)                  \
                                                   >> 496 do {                                            \
                                                   >> 497         (dst)->bi_disk = (src)->bi_disk;        \
                                                   >> 498         (dst)->bi_partno = (src)->bi_partno;    \
                                                   >> 499         bio_clone_blkg_association(dst, src);   \
                                                   >> 500 } while (0)
450                                                   501 
451 #define bio_dev(bio) \                            502 #define bio_dev(bio) \
452         disk_devt((bio)->bi_bdev->bd_disk)     !! 503         disk_devt((bio)->bi_disk)
453                                                   504 
454 #ifdef CONFIG_BLK_CGROUP                          505 #ifdef CONFIG_BLK_CGROUP
455 void bio_associate_blkg(struct bio *bio);         506 void bio_associate_blkg(struct bio *bio);
456 void bio_associate_blkg_from_css(struct bio *b    507 void bio_associate_blkg_from_css(struct bio *bio,
457                                  struct cgroup    508                                  struct cgroup_subsys_state *css);
458 void bio_clone_blkg_association(struct bio *ds    509 void bio_clone_blkg_association(struct bio *dst, struct bio *src);
459 void blkcg_punt_bio_submit(struct bio *bio);   << 
460 #else   /* CONFIG_BLK_CGROUP */                   510 #else   /* CONFIG_BLK_CGROUP */
461 static inline void bio_associate_blkg(struct b    511 static inline void bio_associate_blkg(struct bio *bio) { }
462 static inline void bio_associate_blkg_from_css    512 static inline void bio_associate_blkg_from_css(struct bio *bio,
463                                                   513                                                struct cgroup_subsys_state *css)
464 { }                                               514 { }
465 static inline void bio_clone_blkg_association(    515 static inline void bio_clone_blkg_association(struct bio *dst,
466                                                   516                                               struct bio *src) { }
467 static inline void blkcg_punt_bio_submit(struc !! 517 #endif  /* CONFIG_BLK_CGROUP */
                                                   >> 518 
                                                   >> 519 #ifdef CONFIG_HIGHMEM
                                                   >> 520 /*
                                                   >> 521  * remember never ever reenable interrupts between a bvec_kmap_irq and
                                                   >> 522  * bvec_kunmap_irq!
                                                   >> 523  */
                                                   >> 524 static inline char *bvec_kmap_irq(struct bio_vec *bvec, unsigned long *flags)
468 {                                                 525 {
469         submit_bio(bio);                       !! 526         unsigned long addr;
                                                   >> 527 
                                                   >> 528         /*
                                                   >> 529          * might not be a highmem page, but the preempt/irq count
                                                   >> 530          * balancing is a lot nicer this way
                                                   >> 531          */
                                                   >> 532         local_irq_save(*flags);
                                                   >> 533         addr = (unsigned long) kmap_atomic(bvec->bv_page);
                                                   >> 534 
                                                   >> 535         BUG_ON(addr & ~PAGE_MASK);
                                                   >> 536 
                                                   >> 537         return (char *) addr + bvec->bv_offset;
470 }                                                 538 }
471 #endif  /* CONFIG_BLK_CGROUP */                << 
472                                                   539 
473 static inline void bio_set_dev(struct bio *bio !! 540 static inline void bvec_kunmap_irq(char *buffer, unsigned long *flags)
474 {                                                 541 {
475         bio_clear_flag(bio, BIO_REMAPPED);     !! 542         unsigned long ptr = (unsigned long) buffer & PAGE_MASK;
476         if (bio->bi_bdev != bdev)              !! 543 
477                 bio_clear_flag(bio, BIO_BPS_TH !! 544         kunmap_atomic((void *) ptr);
478         bio->bi_bdev = bdev;                   !! 545         local_irq_restore(*flags);
479         bio_associate_blkg(bio);               << 
480 }                                                 546 }
481                                                   547 
                                                   >> 548 #else
                                                   >> 549 static inline char *bvec_kmap_irq(struct bio_vec *bvec, unsigned long *flags)
                                                   >> 550 {
                                                   >> 551         return page_address(bvec->bv_page) + bvec->bv_offset;
                                                   >> 552 }
                                                   >> 553 
                                                   >> 554 static inline void bvec_kunmap_irq(char *buffer, unsigned long *flags)
                                                   >> 555 {
                                                   >> 556         *flags = 0;
                                                   >> 557 }
                                                   >> 558 #endif
                                                   >> 559 
482 /*                                                560 /*
483  * BIO list management for use by remapping dr    561  * BIO list management for use by remapping drivers (e.g. DM or MD) and loop.
484  *                                                562  *
485  * A bio_list anchors a singly-linked list of     563  * A bio_list anchors a singly-linked list of bios chained through the bi_next
486  * member of the bio.  The bio_list also cache    564  * member of the bio.  The bio_list also caches the last list member to allow
487  * fast access to the tail.                       565  * fast access to the tail.
488  */                                               566  */
489 struct bio_list {                                 567 struct bio_list {
490         struct bio *head;                         568         struct bio *head;
491         struct bio *tail;                         569         struct bio *tail;
492 };                                                570 };
493                                                   571 
494 static inline int bio_list_empty(const struct     572 static inline int bio_list_empty(const struct bio_list *bl)
495 {                                                 573 {
496         return bl->head == NULL;                  574         return bl->head == NULL;
497 }                                                 575 }
498                                                   576 
499 static inline void bio_list_init(struct bio_li    577 static inline void bio_list_init(struct bio_list *bl)
500 {                                                 578 {
501         bl->head = bl->tail = NULL;               579         bl->head = bl->tail = NULL;
502 }                                                 580 }
503                                                   581 
504 #define BIO_EMPTY_LIST  { NULL, NULL }            582 #define BIO_EMPTY_LIST  { NULL, NULL }
505                                                   583 
506 #define bio_list_for_each(bio, bl) \              584 #define bio_list_for_each(bio, bl) \
507         for (bio = (bl)->head; bio; bio = bio-    585         for (bio = (bl)->head; bio; bio = bio->bi_next)
508                                                   586 
509 static inline unsigned bio_list_size(const str    587 static inline unsigned bio_list_size(const struct bio_list *bl)
510 {                                                 588 {
511         unsigned sz = 0;                          589         unsigned sz = 0;
512         struct bio *bio;                          590         struct bio *bio;
513                                                   591 
514         bio_list_for_each(bio, bl)                592         bio_list_for_each(bio, bl)
515                 sz++;                             593                 sz++;
516                                                   594 
517         return sz;                                595         return sz;
518 }                                                 596 }
519                                                   597 
520 static inline void bio_list_add(struct bio_lis    598 static inline void bio_list_add(struct bio_list *bl, struct bio *bio)
521 {                                                 599 {
522         bio->bi_next = NULL;                      600         bio->bi_next = NULL;
523                                                   601 
524         if (bl->tail)                             602         if (bl->tail)
525                 bl->tail->bi_next = bio;          603                 bl->tail->bi_next = bio;
526         else                                      604         else
527                 bl->head = bio;                   605                 bl->head = bio;
528                                                   606 
529         bl->tail = bio;                           607         bl->tail = bio;
530 }                                                 608 }
531                                                   609 
532 static inline void bio_list_add_head(struct bi    610 static inline void bio_list_add_head(struct bio_list *bl, struct bio *bio)
533 {                                                 611 {
534         bio->bi_next = bl->head;                  612         bio->bi_next = bl->head;
535                                                   613 
536         bl->head = bio;                           614         bl->head = bio;
537                                                   615 
538         if (!bl->tail)                            616         if (!bl->tail)
539                 bl->tail = bio;                   617                 bl->tail = bio;
540 }                                                 618 }
541                                                   619 
542 static inline void bio_list_merge(struct bio_l    620 static inline void bio_list_merge(struct bio_list *bl, struct bio_list *bl2)
543 {                                                 621 {
544         if (!bl2->head)                           622         if (!bl2->head)
545                 return;                           623                 return;
546                                                   624 
547         if (bl->tail)                             625         if (bl->tail)
548                 bl->tail->bi_next = bl2->head;    626                 bl->tail->bi_next = bl2->head;
549         else                                      627         else
550                 bl->head = bl2->head;             628                 bl->head = bl2->head;
551                                                   629 
552         bl->tail = bl2->tail;                     630         bl->tail = bl2->tail;
553 }                                                 631 }
554                                                   632 
555 static inline void bio_list_merge_init(struct  << 
556                 struct bio_list *bl2)          << 
557 {                                              << 
558         bio_list_merge(bl, bl2);               << 
559         bio_list_init(bl2);                    << 
560 }                                              << 
561                                                << 
562 static inline void bio_list_merge_head(struct     633 static inline void bio_list_merge_head(struct bio_list *bl,
563                                        struct     634                                        struct bio_list *bl2)
564 {                                                 635 {
565         if (!bl2->head)                           636         if (!bl2->head)
566                 return;                           637                 return;
567                                                   638 
568         if (bl->head)                             639         if (bl->head)
569                 bl2->tail->bi_next = bl->head;    640                 bl2->tail->bi_next = bl->head;
570         else                                      641         else
571                 bl->tail = bl2->tail;             642                 bl->tail = bl2->tail;
572                                                   643 
573         bl->head = bl2->head;                     644         bl->head = bl2->head;
574 }                                                 645 }
575                                                   646 
576 static inline struct bio *bio_list_peek(struct    647 static inline struct bio *bio_list_peek(struct bio_list *bl)
577 {                                                 648 {
578         return bl->head;                          649         return bl->head;
579 }                                                 650 }
580                                                   651 
581 static inline struct bio *bio_list_pop(struct     652 static inline struct bio *bio_list_pop(struct bio_list *bl)
582 {                                                 653 {
583         struct bio *bio = bl->head;               654         struct bio *bio = bl->head;
584                                                   655 
585         if (bio) {                                656         if (bio) {
586                 bl->head = bl->head->bi_next;     657                 bl->head = bl->head->bi_next;
587                 if (!bl->head)                    658                 if (!bl->head)
588                         bl->tail = NULL;          659                         bl->tail = NULL;
589                                                   660 
590                 bio->bi_next = NULL;              661                 bio->bi_next = NULL;
591         }                                         662         }
592                                                   663 
593         return bio;                               664         return bio;
594 }                                                 665 }
595                                                   666 
596 static inline struct bio *bio_list_get(struct     667 static inline struct bio *bio_list_get(struct bio_list *bl)
597 {                                                 668 {
598         struct bio *bio = bl->head;               669         struct bio *bio = bl->head;
599                                                   670 
600         bl->head = bl->tail = NULL;               671         bl->head = bl->tail = NULL;
601                                                   672 
602         return bio;                               673         return bio;
603 }                                                 674 }
604                                                   675 
605 /*                                                676 /*
606  * Increment chain count for the bio. Make sur    677  * Increment chain count for the bio. Make sure the CHAIN flag update
607  * is visible before the raised count.            678  * is visible before the raised count.
608  */                                               679  */
609 static inline void bio_inc_remaining(struct bi    680 static inline void bio_inc_remaining(struct bio *bio)
610 {                                                 681 {
611         bio_set_flag(bio, BIO_CHAIN);             682         bio_set_flag(bio, BIO_CHAIN);
612         smp_mb__before_atomic();                  683         smp_mb__before_atomic();
613         atomic_inc(&bio->__bi_remaining);         684         atomic_inc(&bio->__bi_remaining);
614 }                                                 685 }
615                                                   686 
616 /*                                                687 /*
617  * bio_set is used to allow other portions of     688  * bio_set is used to allow other portions of the IO system to
618  * allocate their own private memory pools for    689  * allocate their own private memory pools for bio and iovec structures.
619  * These memory pools in turn all allocate fro    690  * These memory pools in turn all allocate from the bio_slab
620  * and the bvec_slabs[].                          691  * and the bvec_slabs[].
621  */                                               692  */
622 #define BIO_POOL_SIZE 2                           693 #define BIO_POOL_SIZE 2
623                                                   694 
624 struct bio_set {                                  695 struct bio_set {
625         struct kmem_cache *bio_slab;              696         struct kmem_cache *bio_slab;
626         unsigned int front_pad;                   697         unsigned int front_pad;
627                                                   698 
628         /*                                     << 
629          * per-cpu bio alloc cache             << 
630          */                                    << 
631         struct bio_alloc_cache __percpu *cache << 
632                                                << 
633         mempool_t bio_pool;                       699         mempool_t bio_pool;
634         mempool_t bvec_pool;                      700         mempool_t bvec_pool;
635 #if defined(CONFIG_BLK_DEV_INTEGRITY)             701 #if defined(CONFIG_BLK_DEV_INTEGRITY)
636         mempool_t bio_integrity_pool;             702         mempool_t bio_integrity_pool;
637         mempool_t bvec_integrity_pool;            703         mempool_t bvec_integrity_pool;
638 #endif                                            704 #endif
639                                                   705 
640         unsigned int back_pad;                 << 
641         /*                                        706         /*
642          * Deadlock avoidance for stacking blo    707          * Deadlock avoidance for stacking block drivers: see comments in
643          * bio_alloc_bioset() for details         708          * bio_alloc_bioset() for details
644          */                                       709          */
645         spinlock_t              rescue_lock;      710         spinlock_t              rescue_lock;
646         struct bio_list         rescue_list;      711         struct bio_list         rescue_list;
647         struct work_struct      rescue_work;      712         struct work_struct      rescue_work;
648         struct workqueue_struct *rescue_workqu    713         struct workqueue_struct *rescue_workqueue;
                                                   >> 714 };
649                                                   715 
650         /*                                     !! 716 struct biovec_slab {
651          * Hot un-plug notifier for the per-cp !! 717         int nr_vecs;
652          */                                    !! 718         char *name;
653         struct hlist_node cpuhp_dead;          !! 719         struct kmem_cache *slab;
654 };                                                720 };
655                                                   721 
656 static inline bool bioset_initialized(struct b    722 static inline bool bioset_initialized(struct bio_set *bs)
657 {                                                 723 {
658         return bs->bio_slab != NULL;              724         return bs->bio_slab != NULL;
659 }                                                 725 }
660                                                   726 
                                                   >> 727 #if defined(CONFIG_BLK_DEV_INTEGRITY)
                                                   >> 728 
                                                   >> 729 #define bip_for_each_vec(bvl, bip, iter)                                \
                                                   >> 730         for_each_bvec(bvl, (bip)->bip_vec, iter, (bip)->bip_iter)
                                                   >> 731 
                                                   >> 732 #define bio_for_each_integrity_vec(_bvl, _bio, _iter)                   \
                                                   >> 733         for_each_bio(_bio)                                              \
                                                   >> 734                 bip_for_each_vec(_bvl, _bio->bi_integrity, _iter)
                                                   >> 735 
                                                   >> 736 extern struct bio_integrity_payload *bio_integrity_alloc(struct bio *, gfp_t, unsigned int);
                                                   >> 737 extern int bio_integrity_add_page(struct bio *, struct page *, unsigned int, unsigned int);
                                                   >> 738 extern bool bio_integrity_prep(struct bio *);
                                                   >> 739 extern void bio_integrity_advance(struct bio *, unsigned int);
                                                   >> 740 extern void bio_integrity_trim(struct bio *);
                                                   >> 741 extern int bio_integrity_clone(struct bio *, struct bio *, gfp_t);
                                                   >> 742 extern int bioset_integrity_create(struct bio_set *, int);
                                                   >> 743 extern void bioset_integrity_free(struct bio_set *);
                                                   >> 744 extern void bio_integrity_init(void);
                                                   >> 745 
                                                   >> 746 #else /* CONFIG_BLK_DEV_INTEGRITY */
                                                   >> 747 
                                                   >> 748 static inline void *bio_integrity(struct bio *bio)
                                                   >> 749 {
                                                   >> 750         return NULL;
                                                   >> 751 }
                                                   >> 752 
                                                   >> 753 static inline int bioset_integrity_create(struct bio_set *bs, int pool_size)
                                                   >> 754 {
                                                   >> 755         return 0;
                                                   >> 756 }
                                                   >> 757 
                                                   >> 758 static inline void bioset_integrity_free (struct bio_set *bs)
                                                   >> 759 {
                                                   >> 760         return;
                                                   >> 761 }
                                                   >> 762 
                                                   >> 763 static inline bool bio_integrity_prep(struct bio *bio)
                                                   >> 764 {
                                                   >> 765         return true;
                                                   >> 766 }
                                                   >> 767 
                                                   >> 768 static inline int bio_integrity_clone(struct bio *bio, struct bio *bio_src,
                                                   >> 769                                       gfp_t gfp_mask)
                                                   >> 770 {
                                                   >> 771         return 0;
                                                   >> 772 }
                                                   >> 773 
                                                   >> 774 static inline void bio_integrity_advance(struct bio *bio,
                                                   >> 775                                          unsigned int bytes_done)
                                                   >> 776 {
                                                   >> 777         return;
                                                   >> 778 }
                                                   >> 779 
                                                   >> 780 static inline void bio_integrity_trim(struct bio *bio)
                                                   >> 781 {
                                                   >> 782         return;
                                                   >> 783 }
                                                   >> 784 
                                                   >> 785 static inline void bio_integrity_init(void)
                                                   >> 786 {
                                                   >> 787         return;
                                                   >> 788 }
                                                   >> 789 
                                                   >> 790 static inline bool bio_integrity_flagged(struct bio *bio, enum bip_flags flag)
                                                   >> 791 {
                                                   >> 792         return false;
                                                   >> 793 }
                                                   >> 794 
                                                   >> 795 static inline void *bio_integrity_alloc(struct bio * bio, gfp_t gfp,
                                                   >> 796                                                                 unsigned int nr)
                                                   >> 797 {
                                                   >> 798         return ERR_PTR(-EINVAL);
                                                   >> 799 }
                                                   >> 800 
                                                   >> 801 static inline int bio_integrity_add_page(struct bio *bio, struct page *page,
                                                   >> 802                                         unsigned int len, unsigned int offset)
                                                   >> 803 {
                                                   >> 804         return 0;
                                                   >> 805 }
                                                   >> 806 
                                                   >> 807 #endif /* CONFIG_BLK_DEV_INTEGRITY */
                                                   >> 808 
661 /*                                                809 /*
662  * Mark a bio as polled. Note that for async p    810  * Mark a bio as polled. Note that for async polled IO, the caller must
663  * expect -EWOULDBLOCK if we cannot allocate a    811  * expect -EWOULDBLOCK if we cannot allocate a request (or other resources).
664  * We cannot block waiting for requests on pol    812  * We cannot block waiting for requests on polled IO, as those completions
665  * must be found by the caller. This is differ    813  * must be found by the caller. This is different than IRQ driven IO, where
666  * it's safe to wait for IO to complete.          814  * it's safe to wait for IO to complete.
667  */                                               815  */
668 static inline void bio_set_polled(struct bio *    816 static inline void bio_set_polled(struct bio *bio, struct kiocb *kiocb)
669 {                                                 817 {
670         bio->bi_opf |= REQ_POLLED;             !! 818         bio->bi_opf |= REQ_HIPRI;
671         if (kiocb->ki_flags & IOCB_NOWAIT)     !! 819         if (!is_sync_kiocb(kiocb))
672                 bio->bi_opf |= REQ_NOWAIT;        820                 bio->bi_opf |= REQ_NOWAIT;
673 }                                                 821 }
674                                                << 
675 static inline void bio_clear_polled(struct bio << 
676 {                                              << 
677         bio->bi_opf &= ~REQ_POLLED;            << 
678 }                                              << 
679                                                << 
680 struct bio *blk_next_bio(struct bio *bio, stru << 
681                 unsigned int nr_pages, blk_opf << 
682 struct bio *bio_chain_and_submit(struct bio *p << 
683                                                << 
684 struct bio *blk_alloc_discard_bio(struct block << 
685                 sector_t *sector, sector_t *nr << 
686                                                   822 
687 #endif /* __LINUX_BIO_H */                        823 #endif /* __LINUX_BIO_H */
688                                                   824 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php