diff options
Diffstat (limited to 'drivers/block/aoe/aoecmd.c')
-rw-r--r-- | drivers/block/aoe/aoecmd.c | 153 |
1 files changed, 60 insertions, 93 deletions
diff --git a/drivers/block/aoe/aoecmd.c b/drivers/block/aoe/aoecmd.c index d2515435e23f..8184451b57c0 100644 --- a/drivers/block/aoe/aoecmd.c +++ b/drivers/block/aoe/aoecmd.c | |||
@@ -196,8 +196,7 @@ aoe_freetframe(struct frame *f) | |||
196 | 196 | ||
197 | t = f->t; | 197 | t = f->t; |
198 | f->buf = NULL; | 198 | f->buf = NULL; |
199 | f->lba = 0; | 199 | memset(&f->iter, 0, sizeof(f->iter)); |
200 | f->bv = NULL; | ||
201 | f->r_skb = NULL; | 200 | f->r_skb = NULL; |
202 | f->flags = 0; | 201 | f->flags = 0; |
203 | list_add(&f->head, &t->ffree); | 202 | list_add(&f->head, &t->ffree); |
@@ -295,21 +294,14 @@ newframe(struct aoedev *d) | |||
295 | } | 294 | } |
296 | 295 | ||
297 | static void | 296 | static void |
298 | skb_fillup(struct sk_buff *skb, struct bio_vec *bv, ulong off, ulong cnt) | 297 | skb_fillup(struct sk_buff *skb, struct bio *bio, struct bvec_iter iter) |
299 | { | 298 | { |
300 | int frag = 0; | 299 | int frag = 0; |
301 | ulong fcnt; | 300 | struct bio_vec bv; |
302 | loop: | 301 | |
303 | fcnt = bv->bv_len - (off - bv->bv_offset); | 302 | __bio_for_each_segment(bv, bio, iter, iter) |
304 | if (fcnt > cnt) | 303 | skb_fill_page_desc(skb, frag++, bv.bv_page, |
305 | fcnt = cnt; | 304 | bv.bv_offset, bv.bv_len); |
306 | skb_fill_page_desc(skb, frag++, bv->bv_page, off, fcnt); | ||
307 | cnt -= fcnt; | ||
308 | if (cnt <= 0) | ||
309 | return; | ||
310 | bv++; | ||
311 | off = bv->bv_offset; | ||
312 | goto loop; | ||
313 | } | 305 | } |
314 | 306 | ||
315 | static void | 307 | static void |
@@ -346,12 +338,10 @@ ata_rw_frameinit(struct frame *f) | |||
346 | t->nout++; | 338 | t->nout++; |
347 | f->waited = 0; | 339 | f->waited = 0; |
348 | f->waited_total = 0; | 340 | f->waited_total = 0; |
349 | if (f->buf) | ||
350 | f->lba = f->buf->sector; | ||
351 | 341 | ||
352 | /* set up ata header */ | 342 | /* set up ata header */ |
353 | ah->scnt = f->bcnt >> 9; | 343 | ah->scnt = f->iter.bi_size >> 9; |
354 | put_lba(ah, f->lba); | 344 | put_lba(ah, f->iter.bi_sector); |
355 | if (t->d->flags & DEVFL_EXT) { | 345 | if (t->d->flags & DEVFL_EXT) { |
356 | ah->aflags |= AOEAFL_EXT; | 346 | ah->aflags |= AOEAFL_EXT; |
357 | } else { | 347 | } else { |
@@ -360,11 +350,11 @@ ata_rw_frameinit(struct frame *f) | |||
360 | ah->lba3 |= 0xe0; /* LBA bit + obsolete 0xa0 */ | 350 | ah->lba3 |= 0xe0; /* LBA bit + obsolete 0xa0 */ |
361 | } | 351 | } |
362 | if (f->buf && bio_data_dir(f->buf->bio) == WRITE) { | 352 | if (f->buf && bio_data_dir(f->buf->bio) == WRITE) { |
363 | skb_fillup(skb, f->bv, f->bv_off, f->bcnt); | 353 | skb_fillup(skb, f->buf->bio, f->iter); |
364 | ah->aflags |= AOEAFL_WRITE; | 354 | ah->aflags |= AOEAFL_WRITE; |
365 | skb->len += f->bcnt; | 355 | skb->len += f->iter.bi_size; |
366 | skb->data_len = f->bcnt; | 356 | skb->data_len = f->iter.bi_size; |
367 | skb->truesize += f->bcnt; | 357 | skb->truesize += f->iter.bi_size; |
368 | t->wpkts++; | 358 | t->wpkts++; |
369 | } else { | 359 | } else { |
370 | t->rpkts++; | 360 | t->rpkts++; |
@@ -382,7 +372,6 @@ aoecmd_ata_rw(struct aoedev *d) | |||
382 | struct buf *buf; | 372 | struct buf *buf; |
383 | struct sk_buff *skb; | 373 | struct sk_buff *skb; |
384 | struct sk_buff_head queue; | 374 | struct sk_buff_head queue; |
385 | ulong bcnt, fbcnt; | ||
386 | 375 | ||
387 | buf = nextbuf(d); | 376 | buf = nextbuf(d); |
388 | if (buf == NULL) | 377 | if (buf == NULL) |
@@ -390,39 +379,22 @@ aoecmd_ata_rw(struct aoedev *d) | |||
390 | f = newframe(d); | 379 | f = newframe(d); |
391 | if (f == NULL) | 380 | if (f == NULL) |
392 | return 0; | 381 | return 0; |
393 | bcnt = d->maxbcnt; | ||
394 | if (bcnt == 0) | ||
395 | bcnt = DEFAULTBCNT; | ||
396 | if (bcnt > buf->resid) | ||
397 | bcnt = buf->resid; | ||
398 | fbcnt = bcnt; | ||
399 | f->bv = buf->bv; | ||
400 | f->bv_off = f->bv->bv_offset + (f->bv->bv_len - buf->bv_resid); | ||
401 | do { | ||
402 | if (fbcnt < buf->bv_resid) { | ||
403 | buf->bv_resid -= fbcnt; | ||
404 | buf->resid -= fbcnt; | ||
405 | break; | ||
406 | } | ||
407 | fbcnt -= buf->bv_resid; | ||
408 | buf->resid -= buf->bv_resid; | ||
409 | if (buf->resid == 0) { | ||
410 | d->ip.buf = NULL; | ||
411 | break; | ||
412 | } | ||
413 | buf->bv++; | ||
414 | buf->bv_resid = buf->bv->bv_len; | ||
415 | WARN_ON(buf->bv_resid == 0); | ||
416 | } while (fbcnt); | ||
417 | 382 | ||
418 | /* initialize the headers & frame */ | 383 | /* initialize the headers & frame */ |
419 | f->buf = buf; | 384 | f->buf = buf; |
420 | f->bcnt = bcnt; | 385 | f->iter = buf->iter; |
421 | ata_rw_frameinit(f); | 386 | f->iter.bi_size = min_t(unsigned long, |
387 | d->maxbcnt ?: DEFAULTBCNT, | ||
388 | f->iter.bi_size); | ||
389 | bio_advance_iter(buf->bio, &buf->iter, f->iter.bi_size); | ||
390 | |||
391 | if (!buf->iter.bi_size) | ||
392 | d->ip.buf = NULL; | ||
422 | 393 | ||
423 | /* mark all tracking fields and load out */ | 394 | /* mark all tracking fields and load out */ |
424 | buf->nframesout += 1; | 395 | buf->nframesout += 1; |
425 | buf->sector += bcnt >> 9; | 396 | |
397 | ata_rw_frameinit(f); | ||
426 | 398 | ||
427 | skb = skb_clone(f->skb, GFP_ATOMIC); | 399 | skb = skb_clone(f->skb, GFP_ATOMIC); |
428 | if (skb) { | 400 | if (skb) { |
@@ -613,10 +585,7 @@ reassign_frame(struct frame *f) | |||
613 | skb = nf->skb; | 585 | skb = nf->skb; |
614 | nf->skb = f->skb; | 586 | nf->skb = f->skb; |
615 | nf->buf = f->buf; | 587 | nf->buf = f->buf; |
616 | nf->bcnt = f->bcnt; | 588 | nf->iter = f->iter; |
617 | nf->lba = f->lba; | ||
618 | nf->bv = f->bv; | ||
619 | nf->bv_off = f->bv_off; | ||
620 | nf->waited = 0; | 589 | nf->waited = 0; |
621 | nf->waited_total = f->waited_total; | 590 | nf->waited_total = f->waited_total; |
622 | nf->sent = f->sent; | 591 | nf->sent = f->sent; |
@@ -648,19 +617,19 @@ probe(struct aoetgt *t) | |||
648 | } | 617 | } |
649 | f->flags |= FFL_PROBE; | 618 | f->flags |= FFL_PROBE; |
650 | ifrotate(t); | 619 | ifrotate(t); |
651 | f->bcnt = t->d->maxbcnt ? t->d->maxbcnt : DEFAULTBCNT; | 620 | f->iter.bi_size = t->d->maxbcnt ? t->d->maxbcnt : DEFAULTBCNT; |
652 | ata_rw_frameinit(f); | 621 | ata_rw_frameinit(f); |
653 | skb = f->skb; | 622 | skb = f->skb; |
654 | for (frag = 0, n = f->bcnt; n > 0; ++frag, n -= m) { | 623 | for (frag = 0, n = f->iter.bi_size; n > 0; ++frag, n -= m) { |
655 | if (n < PAGE_SIZE) | 624 | if (n < PAGE_SIZE) |
656 | m = n; | 625 | m = n; |
657 | else | 626 | else |
658 | m = PAGE_SIZE; | 627 | m = PAGE_SIZE; |
659 | skb_fill_page_desc(skb, frag, empty_page, 0, m); | 628 | skb_fill_page_desc(skb, frag, empty_page, 0, m); |
660 | } | 629 | } |
661 | skb->len += f->bcnt; | 630 | skb->len += f->iter.bi_size; |
662 | skb->data_len = f->bcnt; | 631 | skb->data_len = f->iter.bi_size; |
663 | skb->truesize += f->bcnt; | 632 | skb->truesize += f->iter.bi_size; |
664 | 633 | ||
665 | skb = skb_clone(f->skb, GFP_ATOMIC); | 634 | skb = skb_clone(f->skb, GFP_ATOMIC); |
666 | if (skb) { | 635 | if (skb) { |
@@ -897,15 +866,15 @@ rqbiocnt(struct request *r) | |||
897 | static void | 866 | static void |
898 | bio_pageinc(struct bio *bio) | 867 | bio_pageinc(struct bio *bio) |
899 | { | 868 | { |
900 | struct bio_vec *bv; | 869 | struct bio_vec bv; |
901 | struct page *page; | 870 | struct page *page; |
902 | int i; | 871 | struct bvec_iter iter; |
903 | 872 | ||
904 | bio_for_each_segment(bv, bio, i) { | 873 | bio_for_each_segment(bv, bio, iter) { |
905 | /* Non-zero page count for non-head members of | 874 | /* Non-zero page count for non-head members of |
906 | * compound pages is no longer allowed by the kernel. | 875 | * compound pages is no longer allowed by the kernel. |
907 | */ | 876 | */ |
908 | page = compound_trans_head(bv->bv_page); | 877 | page = compound_trans_head(bv.bv_page); |
909 | atomic_inc(&page->_count); | 878 | atomic_inc(&page->_count); |
910 | } | 879 | } |
911 | } | 880 | } |
@@ -913,12 +882,12 @@ bio_pageinc(struct bio *bio) | |||
913 | static void | 882 | static void |
914 | bio_pagedec(struct bio *bio) | 883 | bio_pagedec(struct bio *bio) |
915 | { | 884 | { |
916 | struct bio_vec *bv; | ||
917 | struct page *page; | 885 | struct page *page; |
918 | int i; | 886 | struct bio_vec bv; |
887 | struct bvec_iter iter; | ||
919 | 888 | ||
920 | bio_for_each_segment(bv, bio, i) { | 889 | bio_for_each_segment(bv, bio, iter) { |
921 | page = compound_trans_head(bv->bv_page); | 890 | page = compound_trans_head(bv.bv_page); |
922 | atomic_dec(&page->_count); | 891 | atomic_dec(&page->_count); |
923 | } | 892 | } |
924 | } | 893 | } |
@@ -929,12 +898,8 @@ bufinit(struct buf *buf, struct request *rq, struct bio *bio) | |||
929 | memset(buf, 0, sizeof(*buf)); | 898 | memset(buf, 0, sizeof(*buf)); |
930 | buf->rq = rq; | 899 | buf->rq = rq; |
931 | buf->bio = bio; | 900 | buf->bio = bio; |
932 | buf->resid = bio->bi_size; | 901 | buf->iter = bio->bi_iter; |
933 | buf->sector = bio->bi_sector; | ||
934 | bio_pageinc(bio); | 902 | bio_pageinc(bio); |
935 | buf->bv = bio_iovec(bio); | ||
936 | buf->bv_resid = buf->bv->bv_len; | ||
937 | WARN_ON(buf->bv_resid == 0); | ||
938 | } | 903 | } |
939 | 904 | ||
940 | static struct buf * | 905 | static struct buf * |
@@ -1119,24 +1084,18 @@ gettgt(struct aoedev *d, char *addr) | |||
1119 | } | 1084 | } |
1120 | 1085 | ||
1121 | static void | 1086 | static void |
1122 | bvcpy(struct bio_vec *bv, ulong off, struct sk_buff *skb, long cnt) | 1087 | bvcpy(struct sk_buff *skb, struct bio *bio, struct bvec_iter iter, long cnt) |
1123 | { | 1088 | { |
1124 | ulong fcnt; | ||
1125 | char *p; | ||
1126 | int soff = 0; | 1089 | int soff = 0; |
1127 | loop: | 1090 | struct bio_vec bv; |
1128 | fcnt = bv->bv_len - (off - bv->bv_offset); | 1091 | |
1129 | if (fcnt > cnt) | 1092 | iter.bi_size = cnt; |
1130 | fcnt = cnt; | 1093 | |
1131 | p = page_address(bv->bv_page) + off; | 1094 | __bio_for_each_segment(bv, bio, iter, iter) { |
1132 | skb_copy_bits(skb, soff, p, fcnt); | 1095 | char *p = page_address(bv.bv_page) + bv.bv_offset; |
1133 | soff += fcnt; | 1096 | skb_copy_bits(skb, soff, p, bv.bv_len); |
1134 | cnt -= fcnt; | 1097 | soff += bv.bv_len; |
1135 | if (cnt <= 0) | 1098 | } |
1136 | return; | ||
1137 | bv++; | ||
1138 | off = bv->bv_offset; | ||
1139 | goto loop; | ||
1140 | } | 1099 | } |
1141 | 1100 | ||
1142 | void | 1101 | void |
@@ -1152,7 +1111,7 @@ aoe_end_request(struct aoedev *d, struct request *rq, int fastfail) | |||
1152 | do { | 1111 | do { |
1153 | bio = rq->bio; | 1112 | bio = rq->bio; |
1154 | bok = !fastfail && test_bit(BIO_UPTODATE, &bio->bi_flags); | 1113 | bok = !fastfail && test_bit(BIO_UPTODATE, &bio->bi_flags); |
1155 | } while (__blk_end_request(rq, bok ? 0 : -EIO, bio->bi_size)); | 1114 | } while (__blk_end_request(rq, bok ? 0 : -EIO, bio->bi_iter.bi_size)); |
1156 | 1115 | ||
1157 | /* cf. http://lkml.org/lkml/2006/10/31/28 */ | 1116 | /* cf. http://lkml.org/lkml/2006/10/31/28 */ |
1158 | if (!fastfail) | 1117 | if (!fastfail) |
@@ -1229,7 +1188,15 @@ noskb: if (buf) | |||
1229 | clear_bit(BIO_UPTODATE, &buf->bio->bi_flags); | 1188 | clear_bit(BIO_UPTODATE, &buf->bio->bi_flags); |
1230 | break; | 1189 | break; |
1231 | } | 1190 | } |
1232 | bvcpy(f->bv, f->bv_off, skb, n); | 1191 | if (n > f->iter.bi_size) { |
1192 | pr_err_ratelimited("%s e%ld.%d. bytes=%ld need=%u\n", | ||
1193 | "aoe: too-large data size in read from", | ||
1194 | (long) d->aoemajor, d->aoeminor, | ||
1195 | n, f->iter.bi_size); | ||
1196 | clear_bit(BIO_UPTODATE, &buf->bio->bi_flags); | ||
1197 | break; | ||
1198 | } | ||
1199 | bvcpy(skb, f->buf->bio, f->iter, n); | ||
1233 | case ATA_CMD_PIO_WRITE: | 1200 | case ATA_CMD_PIO_WRITE: |
1234 | case ATA_CMD_PIO_WRITE_EXT: | 1201 | case ATA_CMD_PIO_WRITE_EXT: |
1235 | spin_lock_irq(&d->lock); | 1202 | spin_lock_irq(&d->lock); |
@@ -1272,7 +1239,7 @@ out: | |||
1272 | 1239 | ||
1273 | aoe_freetframe(f); | 1240 | aoe_freetframe(f); |
1274 | 1241 | ||
1275 | if (buf && --buf->nframesout == 0 && buf->resid == 0) | 1242 | if (buf && --buf->nframesout == 0 && buf->iter.bi_size == 0) |
1276 | aoe_end_buf(d, buf); | 1243 | aoe_end_buf(d, buf); |
1277 | 1244 | ||
1278 | spin_unlock_irq(&d->lock); | 1245 | spin_unlock_irq(&d->lock); |
@@ -1727,7 +1694,7 @@ aoe_failbuf(struct aoedev *d, struct buf *buf) | |||
1727 | { | 1694 | { |
1728 | if (buf == NULL) | 1695 | if (buf == NULL) |
1729 | return; | 1696 | return; |
1730 | buf->resid = 0; | 1697 | buf->iter.bi_size = 0; |
1731 | clear_bit(BIO_UPTODATE, &buf->bio->bi_flags); | 1698 | clear_bit(BIO_UPTODATE, &buf->bio->bi_flags); |
1732 | if (buf->nframesout == 0) | 1699 | if (buf->nframesout == 0) |
1733 | aoe_end_buf(d, buf); | 1700 | aoe_end_buf(d, buf); |