]> git.proxmox.com Git - ceph.git/blob - ceph/src/common/blkdev.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / common / blkdev.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef __CEPH_COMMON_BLKDEV_H
5 #define __CEPH_COMMON_BLKDEV_H
6
7 #include <set>
8 #include <map>
9 #include <string>
10 #include "json_spirit/json_spirit_value.h"
11
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
16 // get $vendor_$model_$serial style device id
17 extern std::string get_device_id(const std::string& devname,
18 std::string *err=0);
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
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
39 // for VDO
40 /// return an op fd for the sysfs stats dir, if this is a VDO device
41 extern int get_vdo_stats_handle(const char *devname, std::string *vdo_name);
42 extern int64_t get_vdo_stat(int fd, const char *property);
43 extern bool get_vdo_utilization(int fd, uint64_t *total, uint64_t *avail);
44
45 class BlkDev {
46 public:
47 BlkDev(int fd);
48 BlkDev(const std::string& devname);
49 /* GoogleMock requires a virtual destructor */
50 virtual ~BlkDev() {}
51
52 // from an fd
53 int discard(int64_t offset, int64_t len) const;
54 int get_size(int64_t *psize) const;
55 int get_devid(dev_t *id) const;
56 int partition(char* partition, size_t max) const;
57 // from a device (e.g., "sdb")
58 bool support_discard() const;
59 bool is_rotational() const;
60 int get_numa_node(int *node) const;
61 int dev(char *dev, size_t max) const;
62 int vendor(char *vendor, size_t max) const;
63 int model(char *model, size_t max) const;
64 int serial(char *serial, size_t max) const;
65
66 /* virtual for testing purposes */
67 virtual const char *sysfsdir() const;
68 virtual int wholedisk(char* device, size_t max) const;
69 int wholedisk(std::string *s) const {
70 char out[PATH_MAX] = {0};
71 int r = wholedisk(out, sizeof(out));
72 if (r < 0) {
73 return r;
74 }
75 *s = out;
76 return r;
77 }
78
79 protected:
80 int64_t get_int_property(const char* prop) const;
81 int64_t get_string_property(const char* prop, char *val,
82 size_t maxlen) const;
83
84 private:
85 int fd = -1;
86 std::string devname;
87 };
88
89 #endif