]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
7c673cae FG |
4 | #ifndef __CEPH_COMMON_BLKDEV_H |
5 | #define __CEPH_COMMON_BLKDEV_H | |
6 | ||
11fdf7f2 | 7 | #include <set> |
9f95a23c | 8 | #include <map> |
11fdf7f2 TL |
9 | #include <string> |
10 | #include "json_spirit/json_spirit_value.h" | |
11 | ||
11fdf7f2 TL |
12 | extern int get_device_by_path(const char *path, char* partition, char* device, size_t max); |
13 | ||
14 | extern std::string _decode_model_enc(const std::string& in); // helper, exported only so we can unit test | |
15 | ||
9f95a23c | 16 | // get $vendor_$model_$serial style device id |
11fdf7f2 TL |
17 | extern std::string get_device_id(const std::string& devname, |
18 | std::string *err=0); | |
9f95a23c TL |
19 | |
20 | // get /dev/disk/by-path/... style device id that is stable for a disk slot across reboots etc | |
21 | extern std::string get_device_path(const std::string& devname, | |
22 | std::string *err=0); | |
23 | ||
24 | // populate daemon metadata map with device info | |
25 | extern void get_device_metadata( | |
26 | const std::set<std::string>& devnames, | |
27 | std::map<std::string,std::string> *pm, | |
28 | std::map<std::string,std::string> *errs); | |
29 | ||
11fdf7f2 TL |
30 | extern void get_dm_parents(const std::string& dev, std::set<std::string> *ls); |
31 | extern int block_device_get_metrics(const std::string& devname, int timeout, | |
32 | json_spirit::mValue *result); | |
33 | ||
34 | // do everything to translate a device to the raw physical devices that | |
35 | // back it, including partitions -> wholedisks and dm -> constituent devices. | |
36 | extern void get_raw_devices(const std::string& in, | |
37 | std::set<std::string> *ls); | |
38 | ||
11fdf7f2 TL |
39 | class BlkDev { |
40 | public: | |
41 | BlkDev(int fd); | |
42 | BlkDev(const std::string& devname); | |
43 | /* GoogleMock requires a virtual destructor */ | |
44 | virtual ~BlkDev() {} | |
45 | ||
46 | // from an fd | |
47 | int discard(int64_t offset, int64_t len) const; | |
48 | int get_size(int64_t *psize) const; | |
49 | int get_devid(dev_t *id) const; | |
50 | int partition(char* partition, size_t max) const; | |
51 | // from a device (e.g., "sdb") | |
52 | bool support_discard() const; | |
20effc67 | 53 | int get_optimal_io_size() const; |
11fdf7f2 TL |
54 | bool is_rotational() const; |
55 | int get_numa_node(int *node) const; | |
56 | int dev(char *dev, size_t max) const; | |
57 | int vendor(char *vendor, size_t max) const; | |
58 | int model(char *model, size_t max) const; | |
59 | int serial(char *serial, size_t max) const; | |
60 | ||
61 | /* virtual for testing purposes */ | |
62 | virtual const char *sysfsdir() const; | |
63 | virtual int wholedisk(char* device, size_t max) const; | |
64 | int wholedisk(std::string *s) const { | |
65 | char out[PATH_MAX] = {0}; | |
66 | int r = wholedisk(out, sizeof(out)); | |
67 | if (r < 0) { | |
68 | return r; | |
69 | } | |
70 | *s = out; | |
71 | return r; | |
72 | } | |
73 | ||
74 | protected: | |
9f95a23c TL |
75 | int64_t get_int_property(const char* prop) const; |
76 | int64_t get_string_property(const char* prop, char *val, | |
11fdf7f2 TL |
77 | size_t maxlen) const; |
78 | ||
79 | private: | |
80 | int fd = -1; | |
81 | std::string devname; | |
82 | }; | |
7c673cae FG |
83 | |
84 | #endif |