]> git.proxmox.com Git - ceph.git/blame - ceph/src/common/blkdev.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / common / blkdev.h
CommitLineData
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
12extern int get_device_by_path(const char *path, char* partition, char* device, size_t max);
13
14extern 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
17extern 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
21extern std::string get_device_path(const std::string& devname,
22 std::string *err=0);
23
24// populate daemon metadata map with device info
25extern 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
30extern void get_dm_parents(const std::string& dev, std::set<std::string> *ls);
31extern 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.
36extern 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
41extern int get_vdo_stats_handle(const char *devname, std::string *vdo_name);
42extern int64_t get_vdo_stat(int fd, const char *property);
43extern bool get_vdo_utilization(int fd, uint64_t *total, uint64_t *avail);
44
45class BlkDev {
46public:
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;
20effc67 59 int get_optimal_io_size() const;
11fdf7f2
TL
60 bool is_rotational() const;
61 int get_numa_node(int *node) const;
62 int dev(char *dev, size_t max) const;
63 int vendor(char *vendor, size_t max) const;
64 int model(char *model, size_t max) const;
65 int serial(char *serial, size_t max) const;
66
67 /* virtual for testing purposes */
68 virtual const char *sysfsdir() const;
69 virtual int wholedisk(char* device, size_t max) const;
70 int wholedisk(std::string *s) const {
71 char out[PATH_MAX] = {0};
72 int r = wholedisk(out, sizeof(out));
73 if (r < 0) {
74 return r;
75 }
76 *s = out;
77 return r;
78 }
79
80protected:
9f95a23c
TL
81 int64_t get_int_property(const char* prop) const;
82 int64_t get_string_property(const char* prop, char *val,
11fdf7f2
TL
83 size_t maxlen) const;
84
85private:
86 int fd = -1;
87 std::string devname;
88};
7c673cae
FG
89
90#endif