Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 109188
b: refs/heads/master
c: 76029ff
h: refs/heads/master
v: v3
  • Loading branch information
FUJITA Tomonori authored and Jens Axboe committed Aug 27, 2008
1 parent f18e854 commit 24fb18e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 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: 48fd4f93a00eac844678629f2f00518e146ed30d
refs/heads/master: 76029ff37f31dad64641489c610d98955217bb68
38 changes: 28 additions & 10 deletions trunk/fs/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,20 +469,21 @@ static void bio_free_map_data(struct bio_map_data *bmd)
kfree(bmd);
}

static struct bio_map_data *bio_alloc_map_data(int nr_segs, int iov_count)
static struct bio_map_data *bio_alloc_map_data(int nr_segs, int iov_count,
gfp_t gfp_mask)
{
struct bio_map_data *bmd = kmalloc(sizeof(*bmd), GFP_KERNEL);
struct bio_map_data *bmd = kmalloc(sizeof(*bmd), gfp_mask);

if (!bmd)
return NULL;

bmd->iovecs = kmalloc(sizeof(struct bio_vec) * nr_segs, GFP_KERNEL);
bmd->iovecs = kmalloc(sizeof(struct bio_vec) * nr_segs, gfp_mask);
if (!bmd->iovecs) {
kfree(bmd);
return NULL;
}

bmd->sgvecs = kmalloc(sizeof(struct sg_iovec) * iov_count, GFP_KERNEL);
bmd->sgvecs = kmalloc(sizeof(struct sg_iovec) * iov_count, gfp_mask);
if (bmd->sgvecs)
return bmd;

Expand Down Expand Up @@ -596,7 +597,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q, struct sg_iovec *iov,
len += iov[i].iov_len;
}

bmd = bio_alloc_map_data(nr_pages, iov_count);
bmd = bio_alloc_map_data(nr_pages, iov_count, GFP_KERNEL);
if (!bmd)
return ERR_PTR(-ENOMEM);

Expand Down Expand Up @@ -942,19 +943,22 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
{
struct bio_vec *bvec;
const int read = bio_data_dir(bio) == READ;
char *p = bio->bi_private;
struct bio_map_data *bmd = bio->bi_private;
int i;
char *p = bmd->sgvecs[0].iov_base;

__bio_for_each_segment(bvec, bio, i, 0) {
char *addr = page_address(bvec->bv_page);
int len = bmd->iovecs[i].bv_len;

if (read && !err)
memcpy(p, addr, bvec->bv_len);
memcpy(p, addr, len);

__free_page(bvec->bv_page);
p += bvec->bv_len;
p += len;
}

bio_free_map_data(bmd);
bio_put(bio);
}

Expand All @@ -978,11 +982,21 @@ struct bio *bio_copy_kern(struct request_queue *q, void *data, unsigned int len,
const int nr_pages = end - start;
struct bio *bio;
struct bio_vec *bvec;
struct bio_map_data *bmd;
int i, ret;
struct sg_iovec iov;

iov.iov_base = data;
iov.iov_len = len;

bmd = bio_alloc_map_data(nr_pages, 1, gfp_mask);
if (!bmd)
return ERR_PTR(-ENOMEM);

ret = -ENOMEM;
bio = bio_alloc(gfp_mask, nr_pages);
if (!bio)
return ERR_PTR(-ENOMEM);
goto out_bmd;

while (len) {
struct page *page;
Expand Down Expand Up @@ -1016,14 +1030,18 @@ struct bio *bio_copy_kern(struct request_queue *q, void *data, unsigned int len,
}
}

bio->bi_private = data;
bio->bi_private = bmd;
bio->bi_end_io = bio_copy_kern_endio;

bio_set_map_data(bmd, bio, &iov, 1);
return bio;
cleanup:
bio_for_each_segment(bvec, bio, i)
__free_page(bvec->bv_page);

bio_put(bio);
out_bmd:
bio_free_map_data(bmd);

return ERR_PTR(ret);
}
Expand Down

0 comments on commit 24fb18e

Please sign in to comment.