]>
git.proxmox.com Git - ceph.git/blob - 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
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
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.
15 #ifndef CEPH_STRIPER_H
16 #define CEPH_STRIPER_H
18 #include "include/types.h"
19 #include "osd/osd_types.h"
28 * map (ino, layout, offset, len) to a (list of) ObjectExtents (byte
29 * ranges in objects on (primary) osds)
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
,
35 map
<object_t
, vector
<ObjectExtent
> >& extents
,
36 uint64_t buffer_offset
=0);
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
,
42 vector
<ObjectExtent
>& extents
,
43 uint64_t buffer_offset
=0);
45 static void file_to_extents(CephContext
*cct
, inodeno_t ino
,
46 const file_layout_t
*layout
,
47 uint64_t offset
, uint64_t len
,
49 vector
<ObjectExtent
>& extents
) {
50 // generate prefix/format
52 snprintf(buf
, sizeof(buf
), "%llx.%%08llx", (long long unsigned)ino
);
54 file_to_extents(cct
, buf
, layout
, offset
, len
, trunc_size
, extents
);
57 static void assimilate_extents(
58 map
<object_t
, vector
<ObjectExtent
> >& object_extents
,
59 vector
<ObjectExtent
>& extents
);
62 * reverse map an object extent to file extents
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
);
68 static uint64_t object_truncate_size(
69 CephContext
*cct
, const file_layout_t
*layout
,
70 uint64_t objectno
, uint64_t trunc_size
);
72 static uint64_t get_num_objects(const file_layout_t
& layout
,
75 * helper to assemble a striped result
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
83 void add_partial_result(
84 CephContext
*cct
, bufferlist
& bl
,
85 const vector
<pair
<uint64_t,uint64_t> >& buffer_extents
);
87 * add sparse read into results
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
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
);
100 void assemble_result(CephContext
*cct
, bufferlist
& bl
, bool zero_tail
);
103 * @buffer copy read data into buffer
104 * @len the length of buffer
106 void assemble_result(CephContext
*cct
, char *buffer
, size_t len
);