drm/virtio: Don't return error if virtio-gpu PCI dev is not found
[drm/drm-misc.git] / net / ceph / pagevec.c
blob4509757d8b3be6ff49554d4110a25fc4ad991ad6
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/ceph/ceph_debug.h>
4 #include <linux/module.h>
5 #include <linux/sched.h>
6 #include <linux/slab.h>
7 #include <linux/file.h>
8 #include <linux/namei.h>
9 #include <linux/writeback.h>
11 #include <linux/ceph/libceph.h>
13 void ceph_put_page_vector(struct page **pages, int num_pages, bool dirty)
15 int i;
17 for (i = 0; i < num_pages; i++) {
18 if (dirty)
19 set_page_dirty_lock(pages[i]);
20 put_page(pages[i]);
22 kvfree(pages);
24 EXPORT_SYMBOL(ceph_put_page_vector);
26 void ceph_release_page_vector(struct page **pages, int num_pages)
28 int i;
30 for (i = 0; i < num_pages; i++)
31 __free_pages(pages[i], 0);
32 kfree(pages);
34 EXPORT_SYMBOL(ceph_release_page_vector);
37 * allocate a vector new pages
39 struct page **ceph_alloc_page_vector(int num_pages, gfp_t flags)
41 struct page **pages;
42 int i;
44 pages = kmalloc_array(num_pages, sizeof(*pages), flags);
45 if (!pages)
46 return ERR_PTR(-ENOMEM);
47 for (i = 0; i < num_pages; i++) {
48 pages[i] = __page_cache_alloc(flags);
49 if (pages[i] == NULL) {
50 ceph_release_page_vector(pages, i);
51 return ERR_PTR(-ENOMEM);
54 return pages;
56 EXPORT_SYMBOL(ceph_alloc_page_vector);
58 void ceph_copy_from_page_vector(struct page **pages,
59 void *data,
60 loff_t off, size_t len)
62 int i = 0;
63 size_t po = off & ~PAGE_MASK;
64 size_t left = len;
66 while (left > 0) {
67 size_t l = min_t(size_t, PAGE_SIZE-po, left);
69 memcpy(data, page_address(pages[i]) + po, l);
70 data += l;
71 left -= l;
72 po += l;
73 if (po == PAGE_SIZE) {
74 po = 0;
75 i++;
79 EXPORT_SYMBOL(ceph_copy_from_page_vector);
82 * Zero an extent within a page vector. Offset is relative to the
83 * start of the first page.
85 void ceph_zero_page_vector_range(int off, int len, struct page **pages)
87 int i = off >> PAGE_SHIFT;
89 off &= ~PAGE_MASK;
91 dout("zero_page_vector_page %u~%u\n", off, len);
93 /* leading partial page? */
94 if (off) {
95 int end = min((int)PAGE_SIZE, off + len);
96 dout("zeroing %d %p head from %d\n", i, pages[i],
97 (int)off);
98 zero_user_segment(pages[i], off, end);
99 len -= (end - off);
100 i++;
102 while (len >= PAGE_SIZE) {
103 dout("zeroing %d %p len=%d\n", i, pages[i], len);
104 zero_user_segment(pages[i], 0, PAGE_SIZE);
105 len -= PAGE_SIZE;
106 i++;
108 /* trailing partial page? */
109 if (len) {
110 dout("zeroing %d %p tail to %d\n", i, pages[i], (int)len);
111 zero_user_segment(pages[i], 0, len);
114 EXPORT_SYMBOL(ceph_zero_page_vector_range);