~ [ 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-4.17.19)


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

~ [ 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