]>
git.proxmox.com Git - ceph.git/blob - 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
4 #ifndef __CEPH_COMMON_BLKDEV_H
5 #define __CEPH_COMMON_BLKDEV_H
10 #include "json_spirit/json_spirit_value.h"
12 extern int get_device_by_path(const char *path
, char* partition
, char* device
, size_t max
);
14 extern std::string
_decode_model_enc(const std::string
& in
); // helper, exported only so we can unit test
16 // get $vendor_$model_$serial style device id
17 extern std::string
get_device_id(const std::string
& devname
,
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
,
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
);
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
);
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
);
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
);
48 BlkDev(const std::string
& devname
);
49 /* GoogleMock requires a virtual destructor */
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;
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
));
80 int64_t get_int_property(const char* prop
) const;
81 int64_t get_string_property(const char* prop
, char *val
,