ASoC: update for removeal of slab.h from percpu.h
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / fs / ceph / pagelist.c
blob370e93695474024b048c503fc9a82c1b30f762ef
2 #include <linux/pagemap.h>
3 #include <linux/highmem.h>
5 #include "pagelist.h"
7 int ceph_pagelist_release(struct ceph_pagelist *pl)
9 if (pl->mapped_tail)
10 kunmap(pl->mapped_tail);
11 while (!list_empty(&pl->head)) {
12 struct page *page = list_first_entry(&pl->head, struct page,
13 lru);
14 list_del(&page->lru);
15 __free_page(page);
17 return 0;
20 static int ceph_pagelist_addpage(struct ceph_pagelist *pl)
22 struct page *page = alloc_page(GFP_NOFS);
23 if (!page)
24 return -ENOMEM;
25 pl->room += PAGE_SIZE;
26 list_add_tail(&page->lru, &pl->head);
27 if (pl->mapped_tail)
28 kunmap(pl->mapped_tail);
29 pl->mapped_tail = kmap(page);
30 return 0;
33 int ceph_pagelist_append(struct ceph_pagelist *pl, void *buf, size_t len)
35 while (pl->room < len) {
36 size_t bit = pl->room;
37 int ret;
39 memcpy(pl->mapped_tail + (pl->length & ~PAGE_CACHE_MASK),
40 buf, bit);
41 pl->length += bit;
42 pl->room -= bit;
43 buf += bit;
44 len -= bit;
45 ret = ceph_pagelist_addpage(pl);
46 if (ret)
47 return ret;
50 memcpy(pl->mapped_tail + (pl->length & ~PAGE_CACHE_MASK), buf, len);
51 pl->length += len;
52 pl->room -= len;
53 return 0;