]> git.proxmox.com Git - ceph.git/blob - ceph/src/os/bluestore/FreelistManager.cc
import ceph quincy 17.2.6
[ceph.git] / ceph / src / os / bluestore / FreelistManager.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include "FreelistManager.h"
5 #include "BitmapFreelistManager.h"
6 #ifdef HAVE_LIBZBD
7 #include "ZonedFreelistManager.h"
8 #endif
9
10 FreelistManager *FreelistManager::create(
11 CephContext* cct,
12 std::string type,
13 std::string prefix)
14 {
15 // a bit of a hack... we hard-code the prefixes here. we need to
16 // put the freelistmanagers in different prefixes because the merge
17 // op is per prefix, has to done pre-db-open, and we don't know the
18 // freelist type until after we open the db.
19 ceph_assert(prefix == "B");
20 if (type == "bitmap") {
21 return new BitmapFreelistManager(cct, "B", "b");
22 }
23 if (type == "null") {
24 // use BitmapFreelistManager with the null option to stop allocations from going to RocksDB
25 auto *fm = new BitmapFreelistManager(cct, "B", "b");
26 fm->set_null_manager();
27 return fm;
28 }
29
30 #ifdef HAVE_LIBZBD
31 // With zoned drives there is only one FreelistManager implementation that we
32 // can use, and we also know if a drive is zoned right after opening it
33 // (BlueStore::_open_bdev). Hence, we set freelist_type to "zoned" whenever
34 // we open the device and it turns out to be is zoned. We ignore |prefix|
35 // passed to create and use the prefixes defined for zoned devices at the top
36 // of BlueStore.cc.
37 if (type == "zoned")
38 return new ZonedFreelistManager(cct, "Z", "z");
39 #endif
40
41 return NULL;
42 }
43
44 void FreelistManager::setup_merge_operators(KeyValueDB *db,
45 const std::string& type)
46 {
47 #ifdef HAVE_LIBZBD
48 if (type == "zoned")
49 ZonedFreelistManager::setup_merge_operator(db, "z");
50 else
51 #endif
52 BitmapFreelistManager::setup_merge_operator(db, "b");
53 }