diff options
Diffstat (limited to 'fs/ceph/pagelist.c')
-rw-r--r-- | fs/ceph/pagelist.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/fs/ceph/pagelist.c b/fs/ceph/pagelist.c new file mode 100644 index 000000000000..5f8dbf7c745a --- /dev/null +++ b/fs/ceph/pagelist.c | |||
@@ -0,0 +1,55 @@ | |||
1 | |||
2 | #include <linux/gfp.h> | ||
3 | #include <linux/pagemap.h> | ||
4 | #include <linux/highmem.h> | ||
5 | |||
6 | #include "pagelist.h" | ||
7 | |||
8 | int ceph_pagelist_release(struct ceph_pagelist *pl) | ||
9 | { | ||
10 | if (pl->mapped_tail) | ||
11 | kunmap(pl->mapped_tail); | ||
12 | while (!list_empty(&pl->head)) { | ||
13 | struct page *page = list_first_entry(&pl->head, struct page, | ||
14 | lru); | ||
15 | list_del(&page->lru); | ||
16 | __free_page(page); | ||
17 | } | ||
18 | return 0; | ||
19 | } | ||
20 | |||
21 | static int ceph_pagelist_addpage(struct ceph_pagelist *pl) | ||
22 | { | ||
23 | struct page *page = alloc_page(GFP_NOFS); | ||
24 | if (!page) | ||
25 | return -ENOMEM; | ||
26 | pl->room += PAGE_SIZE; | ||
27 | list_add_tail(&page->lru, &pl->head); | ||
28 | if (pl->mapped_tail) | ||
29 | kunmap(pl->mapped_tail); | ||
30 | pl->mapped_tail = kmap(page); | ||
31 | return 0; | ||
32 | } | ||
33 | |||
34 | int ceph_pagelist_append(struct ceph_pagelist *pl, void *buf, size_t len) | ||
35 | { | ||
36 | while (pl->room < len) { | ||
37 | size_t bit = pl->room; | ||
38 | int ret; | ||
39 | |||
40 | memcpy(pl->mapped_tail + (pl->length & ~PAGE_CACHE_MASK), | ||
41 | buf, bit); | ||
42 | pl->length += bit; | ||
43 | pl->room -= bit; | ||
44 | buf += bit; | ||
45 | len -= bit; | ||
46 | ret = ceph_pagelist_addpage(pl); | ||
47 | if (ret) | ||
48 | return ret; | ||
49 | } | ||
50 | |||
51 | memcpy(pl->mapped_tail + (pl->length & ~PAGE_CACHE_MASK), buf, len); | ||
52 | pl->length += len; | ||
53 | pl->room -= len; | ||
54 | return 0; | ||
55 | } | ||