-
Notifications
You must be signed in to change notification settings - Fork 87
/
zbdlib_zenfs.h
94 lines (74 loc) · 3.06 KB
/
zbdlib_zenfs.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
// Copyright (c) 2019-present, Western Digital Corporation
// This source code is licensed under both the GPLv2 (found in the
// COPYING file in the root directory) and Apache 2.0 License
// (found in the LICENSE.Apache file in the root directory).
#pragma once
#if !defined(ROCKSDB_LITE) && defined(OS_LINUX)
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "rocksdb/io_status.h"
#include "zbd_zenfs.h"
namespace ROCKSDB_NAMESPACE {
class ZbdlibBackend : public ZonedBlockDeviceBackend {
private:
std::string filename_;
int read_f_;
int read_direct_f_;
int write_f_;
public:
explicit ZbdlibBackend(std::string bdevname);
~ZbdlibBackend() {
zbd_close(read_f_);
zbd_close(read_direct_f_);
zbd_close(write_f_);
}
IOStatus Open(bool readonly, bool exclusive, unsigned int *max_active_zones,
unsigned int *max_open_zones);
std::unique_ptr<ZoneList> ListZones();
IOStatus Reset(uint64_t start, bool *offline, uint64_t *max_capacity);
IOStatus Finish(uint64_t start);
IOStatus Close(uint64_t start);
int Read(char *buf, int size, uint64_t pos, bool direct);
int Write(char *data, uint32_t size, uint64_t pos);
int InvalidateCache(uint64_t pos, uint64_t size);
bool ZoneIsSwr(std::unique_ptr<ZoneList> &zones, unsigned int idx) {
struct zbd_zone *z = &((struct zbd_zone *)zones->GetData())[idx];
return zbd_zone_type(z) == ZBD_ZONE_TYPE_SWR;
};
bool ZoneIsOffline(std::unique_ptr<ZoneList> &zones, unsigned int idx) {
struct zbd_zone *z = &((struct zbd_zone *)zones->GetData())[idx];
return zbd_zone_offline(z);
};
bool ZoneIsWritable(std::unique_ptr<ZoneList> &zones, unsigned int idx) {
struct zbd_zone *z = &((struct zbd_zone *)zones->GetData())[idx];
return !(zbd_zone_full(z) || zbd_zone_offline(z) || zbd_zone_rdonly(z));
};
bool ZoneIsActive(std::unique_ptr<ZoneList> &zones, unsigned int idx) {
struct zbd_zone *z = &((struct zbd_zone *)zones->GetData())[idx];
return zbd_zone_imp_open(z) || zbd_zone_exp_open(z) || zbd_zone_closed(z);
};
bool ZoneIsOpen(std::unique_ptr<ZoneList> &zones, unsigned int idx) {
struct zbd_zone *z = &((struct zbd_zone *)zones->GetData())[idx];
return zbd_zone_imp_open(z) || zbd_zone_exp_open(z);
};
uint64_t ZoneStart(std::unique_ptr<ZoneList> &zones, unsigned int idx) {
struct zbd_zone *z = &((struct zbd_zone *)zones->GetData())[idx];
return zbd_zone_start(z);
};
uint64_t ZoneMaxCapacity(std::unique_ptr<ZoneList> &zones, unsigned int idx) {
struct zbd_zone *z = &((struct zbd_zone *)zones->GetData())[idx];
return zbd_zone_capacity(z);
};
uint64_t ZoneWp(std::unique_ptr<ZoneList> &zones, unsigned int idx) {
struct zbd_zone *z = &((struct zbd_zone *)zones->GetData())[idx];
return zbd_zone_wp(z);
};
std::string GetFilename() { return filename_; }
private:
IOStatus CheckScheduler();
std::string ErrorToString(int err);
};
} // namespace ROCKSDB_NAMESPACE
#endif // !defined(ROCKSDB_LITE) && defined(OS_LINUX)