1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_CEPH_STRIPER_H
3 #define _LINUX_CEPH_STRIPER_H
4 
5 #include <linux/list.h>
6 #include <linux/types.h>
7 
8 struct ceph_file_layout;
9 
10 void ceph_calc_file_object_mapping(struct ceph_file_layout *l,
11 				   u64 off, u64 len,
12 				   u64 *objno, u64 *objoff, u32 *xlen);
13 
14 struct ceph_object_extent {
15 	struct list_head oe_item;
16 	u64 oe_objno;
17 	u64 oe_off;
18 	u64 oe_len;
19 };
20 
ceph_object_extent_init(struct ceph_object_extent * ex)21 static inline void ceph_object_extent_init(struct ceph_object_extent *ex)
22 {
23 	INIT_LIST_HEAD(&ex->oe_item);
24 }
25 
26 /*
27  * Called for each mapped stripe unit.
28  *
29  * @bytes: number of bytes mapped, i.e. the minimum of the full length
30  *         requested (file extent length) or the remainder of the stripe
31  *         unit within an object
32  */
33 typedef void (*ceph_object_extent_fn_t)(struct ceph_object_extent *ex,
34 					u32 bytes, void *arg);
35 
36 int ceph_file_to_extents(struct ceph_file_layout *l, u64 off, u64 len,
37 			 struct list_head *object_extents,
38 			 struct ceph_object_extent *alloc_fn(void *arg),
39 			 void *alloc_arg,
40 			 ceph_object_extent_fn_t action_fn,
41 			 void *action_arg);
42 int ceph_iterate_extents(struct ceph_file_layout *l, u64 off, u64 len,
43 			 struct list_head *object_extents,
44 			 ceph_object_extent_fn_t action_fn,
45 			 void *action_arg);
46 
47 struct ceph_file_extent {
48 	u64 fe_off;
49 	u64 fe_len;
50 };
51 
ceph_file_extents_bytes(struct ceph_file_extent * file_extents,u32 num_file_extents)52 static inline u64 ceph_file_extents_bytes(struct ceph_file_extent *file_extents,
53 					  u32 num_file_extents)
54 {
55 	u64 bytes = 0;
56 	u32 i;
57 
58 	for (i = 0; i < num_file_extents; i++)
59 		bytes += file_extents[i].fe_len;
60 
61 	return bytes;
62 }
63 
64 int ceph_extent_to_file(struct ceph_file_layout *l,
65 			u64 objno, u64 objoff, u64 objlen,
66 			struct ceph_file_extent **file_extents,
67 			u32 *num_file_extents);
68 
69 u64 ceph_get_num_objects(struct ceph_file_layout *l, u64 size);
70 
71 #endif
72