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
)
17 for (i
= 0; i
< num_pages
; i
++) {
19 set_page_dirty_lock(pages
[i
]);
24 EXPORT_SYMBOL(ceph_put_page_vector
);
26 void ceph_release_page_vector(struct page
**pages
, int num_pages
)
30 for (i
= 0; i
< num_pages
; i
++)
31 __free_pages(pages
[i
], 0);
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
)
44 pages
= kmalloc_array(num_pages
, sizeof(*pages
), flags
);
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
);
56 EXPORT_SYMBOL(ceph_alloc_page_vector
);
58 void ceph_copy_from_page_vector(struct page
**pages
,
60 loff_t off
, size_t len
)
63 size_t po
= off
& ~PAGE_MASK
;
67 size_t l
= min_t(size_t, PAGE_SIZE
-po
, left
);
69 memcpy(data
, page_address(pages
[i
]) + po
, l
);
73 if (po
== PAGE_SIZE
) {
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
;
91 dout("zero_page_vector_page %u~%u\n", off
, len
);
93 /* leading partial page? */
95 int end
= min((int)PAGE_SIZE
, off
+ len
);
96 dout("zeroing %d %p head from %d\n", i
, pages
[i
],
98 zero_user_segment(pages
[i
], off
, end
);
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
);
108 /* trailing partial page? */
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
);