]> git.proxmox.com Git - ceph.git/blame - ceph/src/osdc/Striper.h
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / osdc / Striper.h
CommitLineData
7c673cae
FG
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
9f95a23c 18#include "include/common_fwd.h"
7c673cae
FG
19#include "include/types.h"
20#include "osd/osd_types.h"
9f95a23c 21#include "osdc/StriperTypes.h"
7c673cae 22
7c673cae
FG
23
24//namespace ceph {
25
26 class Striper {
27 public:
9f95a23c
TL
28 static void file_to_extents(
29 CephContext *cct, const file_layout_t *layout, uint64_t offset,
30 uint64_t len, uint64_t trunc_size, uint64_t buffer_offset,
31 striper::LightweightObjectExtents* object_extents);
32
7c673cae 33 /*
9f95a23c 34 * std::map (ino, layout, offset, len) to a (list of) ObjectExtents (byte
7c673cae
FG
35 * ranges in objects on (primary) osds)
36 */
37 static void file_to_extents(CephContext *cct, const char *object_format,
38 const file_layout_t *layout,
39 uint64_t offset, uint64_t len,
40 uint64_t trunc_size,
9f95a23c 41 std::map<object_t, std::vector<ObjectExtent> >& extents,
7c673cae
FG
42 uint64_t buffer_offset=0);
43
44 static void file_to_extents(CephContext *cct, const char *object_format,
45 const file_layout_t *layout,
46 uint64_t offset, uint64_t len,
47 uint64_t trunc_size,
9f95a23c 48 std::vector<ObjectExtent>& extents,
7c673cae
FG
49 uint64_t buffer_offset=0);
50
51 static void file_to_extents(CephContext *cct, inodeno_t ino,
52 const file_layout_t *layout,
53 uint64_t offset, uint64_t len,
54 uint64_t trunc_size,
9f95a23c 55 std::vector<ObjectExtent>& extents) {
7c673cae
FG
56 // generate prefix/format
57 char buf[32];
58 snprintf(buf, sizeof(buf), "%llx.%%08llx", (long long unsigned)ino);
59
60 file_to_extents(cct, buf, layout, offset, len, trunc_size, extents);
61 }
62
7c673cae 63 /**
9f95a23c 64 * reverse std::map an object extent to file extents
7c673cae
FG
65 */
66 static void extent_to_file(CephContext *cct, file_layout_t *layout,
67 uint64_t objectno, uint64_t off, uint64_t len,
9f95a23c 68 std::vector<std::pair<uint64_t, uint64_t> >& extents);
7c673cae
FG
69
70 static uint64_t object_truncate_size(
71 CephContext *cct, const file_layout_t *layout,
72 uint64_t objectno, uint64_t trunc_size);
73
74 static uint64_t get_num_objects(const file_layout_t& layout,
75 uint64_t size);
f67539c2
TL
76
77 static uint64_t get_file_offset(CephContext *cct,
78 const file_layout_t *layout, uint64_t objectno, uint64_t off);
7c673cae
FG
79 /*
80 * helper to assemble a striped result
81 */
82 class StripedReadResult {
83 // offset -> (data, intended length)
9f95a23c 84 std::map<uint64_t, std::pair<ceph::buffer::list, uint64_t> > partial;
7c673cae
FG
85 uint64_t total_intended_len = 0; //sum of partial.second.second
86
87 public:
88 void add_partial_result(
9f95a23c
TL
89 CephContext *cct, ceph::buffer::list& bl,
90 const std::vector<std::pair<uint64_t,uint64_t> >& buffer_extents);
91 void add_partial_result(
92 CephContext *cct, ceph::buffer::list&& bl,
93 const striper::LightweightBufferExtents& buffer_extents);
94
7c673cae
FG
95 /**
96 * add sparse read into results
97 *
98 * @param bl buffer
9f95a23c 99 * @param bl_map std::map of which logical source extents this covers
7c673cae
FG
100 * @param bl_off logical buffer offset (e.g., first bl_map key
101 * if the buffer is not sparse)
102 * @param buffer_extents output buffer extents the data maps to
103 */
104 void add_partial_sparse_result(
9f95a23c
TL
105 CephContext *cct, ceph::buffer::list& bl,
106 const std::map<uint64_t, uint64_t>& bl_map, uint64_t bl_off,
107 const std::vector<std::pair<uint64_t,uint64_t> >& buffer_extents);
108 void add_partial_sparse_result(
f67539c2
TL
109 CephContext *cct, ceph::buffer::list&& bl,
110 const std::vector<std::pair<uint64_t, uint64_t>>& bl_map,
111 uint64_t bl_off,
112 const striper::LightweightBufferExtents& buffer_extents);
7c673cae 113
9f95a23c
TL
114 void assemble_result(CephContext *cct, ceph::buffer::list& bl,
115 bool zero_tail);
7c673cae
FG
116
117 /**
118 * @buffer copy read data into buffer
119 * @len the length of buffer
120 */
121 void assemble_result(CephContext *cct, char *buffer, size_t len);
9f95a23c 122
f67539c2
TL
123 uint64_t assemble_result(CephContext *cct,
124 std::map<uint64_t, uint64_t> *extent_map,
125 ceph::buffer::list *bl);
7c673cae
FG
126 };
127
128 };
129
130//};
131
132#endif