Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 251141
b: refs/heads/master
c: 5dba308
h: refs/heads/master
i:
  251139: ae40f0c
v: v3
  • Loading branch information
Lukas Czerner authored and Jens Axboe committed May 7, 2011
1 parent 609e6f5 commit 2103e6c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 41 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 900e599eb0c16390ff671652a44e0ea90532220e
refs/heads/master: 5dba3089ed03f84b84c6c739df8330112f04a15d
69 changes: 29 additions & 40 deletions trunk/block/blk-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,23 @@

#include "blk.h"

static void blkdev_discard_end_io(struct bio *bio, int err)
struct bio_batch {
atomic_t done;
unsigned long flags;
struct completion *wait;
};

static void bio_batch_end_io(struct bio *bio, int err)
{
struct bio_batch *bb = bio->bi_private;

if (err) {
if (err == -EOPNOTSUPP)
set_bit(BIO_EOPNOTSUPP, &bio->bi_flags);
clear_bit(BIO_UPTODATE, &bio->bi_flags);
set_bit(BIO_EOPNOTSUPP, &bb->flags);
clear_bit(BIO_UPTODATE, &bb->flags);
}

if (bio->bi_private)
complete(bio->bi_private);

if (atomic_dec_and_test(&bb->done))
complete(bb->wait);
bio_put(bio);
}

Expand All @@ -41,6 +47,7 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
struct request_queue *q = bdev_get_queue(bdev);
int type = REQ_WRITE | REQ_DISCARD;
unsigned int max_discard_sectors;
struct bio_batch bb;
struct bio *bio;
int ret = 0;

Expand All @@ -67,17 +74,21 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
type |= REQ_SECURE;
}

while (nr_sects && !ret) {
atomic_set(&bb.done, 1);
bb.flags = 1 << BIO_UPTODATE;
bb.wait = &wait;

while (nr_sects) {
bio = bio_alloc(gfp_mask, 1);
if (!bio) {
ret = -ENOMEM;
break;
}

bio->bi_sector = sector;
bio->bi_end_io = blkdev_discard_end_io;
bio->bi_end_io = bio_batch_end_io;
bio->bi_bdev = bdev;
bio->bi_private = &wait;
bio->bi_private = &bb;

if (nr_sects > max_discard_sectors) {
bio->bi_size = max_discard_sectors << 9;
Expand All @@ -88,45 +99,23 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
nr_sects = 0;
}

bio_get(bio);
atomic_inc(&bb.done);
submit_bio(type, bio);
}

/* Wait for bios in-flight */
if (!atomic_dec_and_test(&bb.done))
wait_for_completion(&wait);

if (bio_flagged(bio, BIO_EOPNOTSUPP))
ret = -EOPNOTSUPP;
else if (!bio_flagged(bio, BIO_UPTODATE))
ret = -EIO;
bio_put(bio);
}
if (test_bit(BIO_EOPNOTSUPP, &bb.flags))
ret = -EOPNOTSUPP;
else if (!test_bit(BIO_UPTODATE, &bb.flags))
ret = -EIO;

return ret;
}
EXPORT_SYMBOL(blkdev_issue_discard);

struct bio_batch
{
atomic_t done;
unsigned long flags;
struct completion *wait;
};

static void bio_batch_end_io(struct bio *bio, int err)
{
struct bio_batch *bb = bio->bi_private;

if (err) {
if (err == -EOPNOTSUPP)
set_bit(BIO_EOPNOTSUPP, &bb->flags);
else
clear_bit(BIO_UPTODATE, &bb->flags);
}
if (bb)
if (atomic_dec_and_test(&bb->done))
complete(bb->wait);
bio_put(bio);
}

/**
* blkdev_issue_zeroout - generate number of zero filed write bios
* @bdev: blockdev to issue
Expand Down

0 comments on commit 2103e6c

Please sign in to comment.