ceph-rbd: osdc support for osd call and rollback operations
[deliverable/linux.git] / fs / ceph / pagelist.c
1
2 #include <linux/gfp.h>
3 #include <linux/pagemap.h>
4 #include <linux/highmem.h>
5
6 #include "pagelist.h"
7
8 static void ceph_pagelist_unmap_tail(struct ceph_pagelist *pl)
9 {
10 struct page *page = list_entry(pl->head.prev, struct page,
11 lru);
12 kunmap(page);
13 }
14
15 int ceph_pagelist_release(struct ceph_pagelist *pl)
16 {
17 if (pl->mapped_tail)
18 ceph_pagelist_unmap_tail(pl);
19
20 while (!list_empty(&pl->head)) {
21 struct page *page = list_first_entry(&pl->head, struct page,
22 lru);
23 list_del(&page->lru);
24 __free_page(page);
25 }
26 return 0;
27 }
28
29 static int ceph_pagelist_addpage(struct ceph_pagelist *pl)
30 {
31 struct page *page = __page_cache_alloc(GFP_NOFS);
32 if (!page)
33 return -ENOMEM;
34 pl->room += PAGE_SIZE;
35 list_add_tail(&page->lru, &pl->head);
36 if (pl->mapped_tail)
37 ceph_pagelist_unmap_tail(pl);
38 pl->mapped_tail = kmap(page);
39 return 0;
40 }
41
42 int ceph_pagelist_append(struct ceph_pagelist *pl, const void *buf, size_t len)
43 {
44 while (pl->room < len) {
45 size_t bit = pl->room;
46 int ret;
47
48 memcpy(pl->mapped_tail + (pl->length & ~PAGE_CACHE_MASK),
49 buf, bit);
50 pl->length += bit;
51 pl->room -= bit;
52 buf += bit;
53 len -= bit;
54 ret = ceph_pagelist_addpage(pl);
55 if (ret)
56 return ret;
57 }
58
59 memcpy(pl->mapped_tail + (pl->length & ~PAGE_CACHE_MASK), buf, len);
60 pl->length += len;
61 pl->room -= len;
62 return 0;
63 }
This page took 0.030501 seconds and 5 git commands to generate.