]> git.proxmox.com Git - ceph.git/blob - ceph/src/osdc/Striper.h
update sources to 12.2.8
[ceph.git] / ceph / src / osdc / Striper.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15 #ifndef CEPH_STRIPER_H
16 #define CEPH_STRIPER_H
17
18 #include "include/types.h"
19 #include "osd/osd_types.h"
20
21 class CephContext;
22
23 //namespace ceph {
24
25 class Striper {
26 public:
27 /*
28 * map (ino, layout, offset, len) to a (list of) ObjectExtents (byte
29 * ranges in objects on (primary) osds)
30 */
31 static void file_to_extents(CephContext *cct, const char *object_format,
32 const file_layout_t *layout,
33 uint64_t offset, uint64_t len,
34 uint64_t trunc_size,
35 map<object_t, vector<ObjectExtent> >& extents,
36 uint64_t buffer_offset=0);
37
38 static void file_to_extents(CephContext *cct, const char *object_format,
39 const file_layout_t *layout,
40 uint64_t offset, uint64_t len,
41 uint64_t trunc_size,
42 vector<ObjectExtent>& extents,
43 uint64_t buffer_offset=0);
44
45 static void file_to_extents(CephContext *cct, inodeno_t ino,
46 const file_layout_t *layout,
47 uint64_t offset, uint64_t len,
48 uint64_t trunc_size,
49 vector<ObjectExtent>& extents) {
50 // generate prefix/format
51 char buf[32];
52 snprintf(buf, sizeof(buf), "%llx.%%08llx", (long long unsigned)ino);
53
54 file_to_extents(cct, buf, layout, offset, len, trunc_size, extents);
55 }
56
57 static void assimilate_extents(
58 map<object_t, vector<ObjectExtent> >& object_extents,
59 vector<ObjectExtent>& extents);
60
61 /**
62 * reverse map an object extent to file extents
63 */
64 static void extent_to_file(CephContext *cct, file_layout_t *layout,
65 uint64_t objectno, uint64_t off, uint64_t len,
66 vector<pair<uint64_t, uint64_t> >& extents);
67
68 static uint64_t object_truncate_size(
69 CephContext *cct, const file_layout_t *layout,
70 uint64_t objectno, uint64_t trunc_size);
71
72 static uint64_t get_num_objects(const file_layout_t& layout,
73 uint64_t size);
74 /*
75 * helper to assemble a striped result
76 */
77 class StripedReadResult {
78 // offset -> (data, intended length)
79 map<uint64_t, pair<bufferlist, uint64_t> > partial;
80 uint64_t total_intended_len = 0; //sum of partial.second.second
81
82 public:
83 void add_partial_result(
84 CephContext *cct, bufferlist& bl,
85 const vector<pair<uint64_t,uint64_t> >& buffer_extents);
86 /**
87 * add sparse read into results
88 *
89 * @param bl buffer
90 * @param bl_map map of which logical source extents this covers
91 * @param bl_off logical buffer offset (e.g., first bl_map key
92 * if the buffer is not sparse)
93 * @param buffer_extents output buffer extents the data maps to
94 */
95 void add_partial_sparse_result(
96 CephContext *cct, bufferlist& bl,
97 const map<uint64_t, uint64_t>& bl_map, uint64_t bl_off,
98 const vector<pair<uint64_t,uint64_t> >& buffer_extents);
99
100 void assemble_result(CephContext *cct, bufferlist& bl, bool zero_tail);
101
102 /**
103 * @buffer copy read data into buffer
104 * @len the length of buffer
105 */
106 void assemble_result(CephContext *cct, char *buffer, size_t len);
107 };
108
109 };
110
111 //};
112
113 #endif