aboutsummaryrefslogtreecommitdiffstats
path: root/block/blk-lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'block/blk-lib.c')
-rw-r--r--block/blk-lib.c41
1 files changed, 14 insertions, 27 deletions
diff --git a/block/blk-lib.c b/block/blk-lib.c
index c1fc55a83ba1..1a320d2406b0 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -39,8 +39,7 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
39{ 39{
40 DECLARE_COMPLETION_ONSTACK(wait); 40 DECLARE_COMPLETION_ONSTACK(wait);
41 struct request_queue *q = bdev_get_queue(bdev); 41 struct request_queue *q = bdev_get_queue(bdev);
42 int type = flags & BLKDEV_IFL_BARRIER ? 42 int type = REQ_WRITE | REQ_DISCARD;
43 DISCARD_BARRIER : DISCARD_NOBARRIER;
44 unsigned int max_discard_sectors; 43 unsigned int max_discard_sectors;
45 struct bio *bio; 44 struct bio *bio;
46 int ret = 0; 45 int ret = 0;
@@ -62,6 +61,12 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
62 max_discard_sectors &= ~(disc_sects - 1); 61 max_discard_sectors &= ~(disc_sects - 1);
63 } 62 }
64 63
64 if (flags & BLKDEV_DISCARD_SECURE) {
65 if (!blk_queue_secdiscard(q))
66 return -EOPNOTSUPP;
67 type |= REQ_SECURE;
68 }
69
65 while (nr_sects && !ret) { 70 while (nr_sects && !ret) {
66 bio = bio_alloc(gfp_mask, 1); 71 bio = bio_alloc(gfp_mask, 1);
67 if (!bio) { 72 if (!bio) {
@@ -72,8 +77,7 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
72 bio->bi_sector = sector; 77 bio->bi_sector = sector;
73 bio->bi_end_io = blkdev_discard_end_io; 78 bio->bi_end_io = blkdev_discard_end_io;
74 bio->bi_bdev = bdev; 79 bio->bi_bdev = bdev;
75 if (flags & BLKDEV_IFL_WAIT) 80 bio->bi_private = &wait;
76 bio->bi_private = &wait;
77 81
78 if (nr_sects > max_discard_sectors) { 82 if (nr_sects > max_discard_sectors) {
79 bio->bi_size = max_discard_sectors << 9; 83 bio->bi_size = max_discard_sectors << 9;
@@ -87,8 +91,7 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
87 bio_get(bio); 91 bio_get(bio);
88 submit_bio(type, bio); 92 submit_bio(type, bio);
89 93
90 if (flags & BLKDEV_IFL_WAIT) 94 wait_for_completion(&wait);
91 wait_for_completion(&wait);
92 95
93 if (bio_flagged(bio, BIO_EOPNOTSUPP)) 96 if (bio_flagged(bio, BIO_EOPNOTSUPP))
94 ret = -EOPNOTSUPP; 97 ret = -EOPNOTSUPP;
@@ -134,7 +137,6 @@ static void bio_batch_end_io(struct bio *bio, int err)
134 * @sector: start sector 137 * @sector: start sector
135 * @nr_sects: number of sectors to write 138 * @nr_sects: number of sectors to write
136 * @gfp_mask: memory allocation flags (for bio_alloc) 139 * @gfp_mask: memory allocation flags (for bio_alloc)
137 * @flags: BLKDEV_IFL_* flags to control behaviour
138 * 140 *
139 * Description: 141 * Description:
140 * Generate and issue number of bios with zerofiled pages. 142 * Generate and issue number of bios with zerofiled pages.
@@ -143,7 +145,7 @@ static void bio_batch_end_io(struct bio *bio, int err)
143 */ 145 */
144 146
145int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, 147int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
146 sector_t nr_sects, gfp_t gfp_mask, unsigned long flags) 148 sector_t nr_sects, gfp_t gfp_mask)
147{ 149{
148 int ret; 150 int ret;
149 struct bio *bio; 151 struct bio *bio;
@@ -156,12 +158,6 @@ int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
156 bb.wait = &wait; 158 bb.wait = &wait;
157 bb.end_io = NULL; 159 bb.end_io = NULL;
158 160
159 if (flags & BLKDEV_IFL_BARRIER) {
160 /* issue async barrier before the data */
161 ret = blkdev_issue_flush(bdev, gfp_mask, NULL, 0);
162 if (ret)
163 return ret;
164 }
165submit: 161submit:
166 ret = 0; 162 ret = 0;
167 while (nr_sects != 0) { 163 while (nr_sects != 0) {
@@ -175,8 +171,7 @@ submit:
175 bio->bi_sector = sector; 171 bio->bi_sector = sector;
176 bio->bi_bdev = bdev; 172 bio->bi_bdev = bdev;
177 bio->bi_end_io = bio_batch_end_io; 173 bio->bi_end_io = bio_batch_end_io;
178 if (flags & BLKDEV_IFL_WAIT) 174 bio->bi_private = &bb;
179 bio->bi_private = &bb;
180 175
181 while (nr_sects != 0) { 176 while (nr_sects != 0) {
182 sz = min((sector_t) PAGE_SIZE >> 9 , nr_sects); 177 sz = min((sector_t) PAGE_SIZE >> 9 , nr_sects);
@@ -193,18 +188,10 @@ submit:
193 issued++; 188 issued++;
194 submit_bio(WRITE, bio); 189 submit_bio(WRITE, bio);
195 } 190 }
196 /*
197 * When all data bios are in flight. Send final barrier if requeted.
198 */
199 if (nr_sects == 0 && flags & BLKDEV_IFL_BARRIER)
200 ret = blkdev_issue_flush(bdev, gfp_mask, NULL,
201 flags & BLKDEV_IFL_WAIT);
202
203 191
204 if (flags & BLKDEV_IFL_WAIT) 192 /* Wait for bios in-flight */
205 /* Wait for bios in-flight */ 193 while (issued != atomic_read(&bb.done))
206 while ( issued != atomic_read(&bb.done)) 194 wait_for_completion(&wait);
207 wait_for_completion(&wait);
208 195
209 if (!test_bit(BIO_UPTODATE, &bb.flags)) 196 if (!test_bit(BIO_UPTODATE, &bb.flags))
210 /* One of bios in the batch was completed with error.*/ 197 /* One of bios in the batch was completed with error.*/