Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / os / bluestore / Allocator.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  * This is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License version 2.1, as published by the Free Software
9  * Foundation.  See file COPYING.
10  *
11  */
12 #ifndef CEPH_OS_BLUESTORE_ALLOCATOR_H
13 #define CEPH_OS_BLUESTORE_ALLOCATOR_H
14
15 #include <ostream>
16 #include "include/assert.h"
17 #include "os/bluestore/bluestore_types.h"
18
19 class FreelistManager;
20
21 class Allocator {
22 public:
23   virtual ~Allocator() {}
24
25   virtual int reserve(uint64_t need) = 0;
26   virtual void unreserve(uint64_t unused) = 0;
27
28   /*
29    * Allocate required number of blocks in n number of extents.
30    * Min and Max number of extents are limited by:
31    * a. alloc unit
32    * b. max_alloc_size.
33    * as no extent can be lesser than alloc_unit and greater than max_alloc size.
34    * Apart from that extents can vary between these lower and higher limits according
35    * to free block search algorithm and availability of contiguous space.
36    */
37   virtual int64_t allocate(uint64_t want_size, uint64_t alloc_unit,
38                            uint64_t max_alloc_size, int64_t hint,
39                            AllocExtentVector *extents) = 0;
40
41   int64_t allocate(uint64_t want_size, uint64_t alloc_unit,
42                    int64_t hint, AllocExtentVector *extents) {
43     return allocate(want_size, alloc_unit, want_size, hint, extents);
44   }
45
46   virtual void release(
47     uint64_t offset, uint64_t length) = 0;
48
49   virtual void dump() = 0;
50
51   virtual void init_add_free(uint64_t offset, uint64_t length) = 0;
52   virtual void init_rm_free(uint64_t offset, uint64_t length) = 0;
53
54   virtual uint64_t get_free() = 0;
55
56   virtual void shutdown() = 0;
57   static Allocator *create(CephContext* cct, string type, int64_t size,
58                            int64_t block_size);
59 };
60
61 #endif