forked from ceph/ceph
/
Allocator.h
79 lines (64 loc) · 2.4 KB
/
Allocator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*
*/
#ifndef CEPH_OS_BLUESTORE_ALLOCATOR_H
#define CEPH_OS_BLUESTORE_ALLOCATOR_H
#include "kv/KeyValueDB.h"
#include <ostream>
#include "include/assert.h"
#include "os/bluestore/bluestore_types.h"
class FreelistManager;
class Allocator {
public:
virtual ~Allocator() {}
virtual int reserve(uint64_t need) = 0;
virtual void unreserve(uint64_t unused) = 0;
virtual int allocate(
uint64_t need_size, uint64_t alloc_unit, int64_t hint,
uint64_t *offset, uint32_t *length) = 0;
/*
* Allocate required number of blocks in n number of extents.
* Min and Max number of extents are limited by:
* a. alloc unit
* b. max_alloc_size.
* as no extent can be lesser than alloc_unit and greater than max_alloc size.
* Apart from that extents can vary between these lower and higher limits according
* to free block search algorithm and availability of contiguous space.
*/
virtual int alloc_extents(uint64_t want_size, uint64_t alloc_unit,
uint64_t max_alloc_size, int64_t hint,
std::vector<AllocExtent> *extents, int *count) = 0;
int alloc_extents(uint64_t want_size, uint64_t alloc_unit,
int64_t hint, std::vector<AllocExtent> *extents, int *count) {
return alloc_extents(want_size, alloc_unit, want_size, hint, extents, count);
}
virtual int release(
uint64_t offset, uint64_t length) = 0;
virtual int release_extents(std::vector<AllocExtent> *extents, int count) {
int res = 0;
for (int i = 0; i < count; i++) {
res = release((*extents)[i].offset, (*extents)[i].length);
if (res != 0) {
break;
}
}
return res;
}
virtual void commit_start() = 0;
virtual void commit_finish() = 0;
virtual void dump(std::ostream& out) = 0;
virtual void init_add_free(uint64_t offset, uint64_t length) = 0;
virtual void init_rm_free(uint64_t offset, uint64_t length) = 0;
virtual uint64_t get_free() = 0;
virtual void shutdown() = 0;
static Allocator *create(string type, int64_t size, int64_t block_size);
};
#endif