mirror of
https://github.com/ceph/ceph
synced 2025-02-23 11:07:35 +00:00
Merge pull request #4699 from joehandzik/master
FileStore: Collect device partition information Reviewed-by: Sage Weil <sage@redhat.com> Reviewed-by: Haomai Wang <haomaiwang@gmail.com>
This commit is contained in:
commit
4fe62cd7a1
37
configure.ac
37
configure.ac
@ -268,25 +268,36 @@ ACX_PTHREAD
|
||||
|
||||
AC_CHECK_LIB([uuid], [uuid_parse], [true], AC_MSG_FAILURE([libuuid not found]))
|
||||
|
||||
# rbd {map,unmap,showmapped} dependencies, Linux only
|
||||
if test x"$linux" = x"yes" -a x"$with_rbd" = x"yes"; then
|
||||
#Linux only dependencies
|
||||
if test x"$linux" = x"yes"; then
|
||||
# libblkid
|
||||
AC_CHECK_HEADER([blkid/blkid.h], [],
|
||||
AC_MSG_ERROR([blkid/blkid.h not found (libblkid-dev, libblkid-devel)]))
|
||||
AC_CHECK_LIB([blkid], [blkid_devno_to_wholedisk], [true],
|
||||
AC_CHECK_LIB([blkid], [blkid_get_cache], [true],
|
||||
AC_MSG_FAILURE([libblkid not found]))
|
||||
AC_CHECK_LIB([blkid], [blkid_find_dev_with_tag], [true],
|
||||
AC_MSG_FAILURE([libblkid not found]))
|
||||
AC_CHECK_LIB([blkid], [blkid_dev_devname], [true],
|
||||
AC_MSG_FAILURE([libblkid not found]))
|
||||
|
||||
# libudev
|
||||
AC_CHECK_HEADER([libudev.h], [],
|
||||
AC_MSG_ERROR([libudev.h not found (libudev-dev, libudev-devel)]))
|
||||
AC_CHECK_LIB([udev], [udev_monitor_receive_device], [true],
|
||||
AC_MSG_FAILURE([libudev not found]))
|
||||
# rbd {map,unmap,showmapped} dependencies, Linux only
|
||||
if test x"$with_rbd" = x"yes"; then
|
||||
# libblkid
|
||||
AC_CHECK_LIB([blkid], [blkid_devno_to_wholedisk], [true],
|
||||
AC_MSG_FAILURE([libblkid not found]))
|
||||
|
||||
# libexpat
|
||||
AC_CHECK_HEADER([expat.h], [],
|
||||
AC_MSG_ERROR([expat.h not found (libexpat-devel)]))
|
||||
AC_CHECK_LIB([expat], [XML_Parse], [true],
|
||||
AC_MSG_FAILURE([libexpat not found]))
|
||||
# libudev
|
||||
AC_CHECK_HEADER([libudev.h], [],
|
||||
AC_MSG_ERROR([libudev.h not found (libudev-dev, libudev-devel)]))
|
||||
AC_CHECK_LIB([udev], [udev_monitor_receive_device], [true],
|
||||
AC_MSG_FAILURE([libudev not found]))
|
||||
|
||||
# libexpat
|
||||
AC_CHECK_HEADER([expat.h], [],
|
||||
AC_MSG_ERROR([expat.h not found (libexpat-devel)]))
|
||||
AC_CHECK_LIB([expat], [XML_Parse], [true],
|
||||
AC_MSG_FAILURE([libexpat not found]))
|
||||
fi
|
||||
fi
|
||||
|
||||
#
|
||||
|
@ -135,7 +135,7 @@ LIBCOMMON_DEPS += \
|
||||
$(LIBCRUSH) $(LIBJSON_SPIRIT) $(LIBLOG) $(LIBARCH)
|
||||
|
||||
if LINUX
|
||||
LIBCOMMON_DEPS += -lrt
|
||||
LIBCOMMON_DEPS += -lrt -lblkid -luuid
|
||||
endif # LINUX
|
||||
|
||||
libcommon_la_SOURCES = common/buffer.cc
|
||||
|
@ -11,6 +11,10 @@
|
||||
|
||||
#ifdef __linux__
|
||||
#include <linux/fs.h>
|
||||
#include "include/uuid.h"
|
||||
#include <blkid/blkid.h>
|
||||
|
||||
#define UUID_LEN 36
|
||||
|
||||
static const char *sandbox_dir = "";
|
||||
|
||||
@ -162,6 +166,36 @@ int block_device_discard(int fd, int64_t offset, int64_t len)
|
||||
return ioctl(fd, BLKDISCARD, range);
|
||||
}
|
||||
|
||||
int get_device_by_uuid(uuid_d dev_uuid, const char* label, char* partition,
|
||||
char* device)
|
||||
{
|
||||
char uuid_str[UUID_LEN+1];
|
||||
char basename[PATH_MAX];
|
||||
const char* temp_partition_ptr = NULL;
|
||||
blkid_cache cache = NULL;
|
||||
blkid_dev dev = NULL;
|
||||
int rc = 0;
|
||||
|
||||
uuid_unparse((const unsigned char*)&dev_uuid.uuid, uuid_str);
|
||||
|
||||
if (blkid_get_cache(&cache, NULL) >= 0)
|
||||
dev = blkid_find_dev_with_tag(cache, label, (const char*)uuid_str);
|
||||
|
||||
if (dev) {
|
||||
temp_partition_ptr = blkid_dev_devname(dev);
|
||||
strncpy(partition, temp_partition_ptr, PATH_MAX);
|
||||
rc = get_block_device_base(partition, basename,
|
||||
sizeof(basename));
|
||||
if (rc >= 0)
|
||||
strncpy(device, basename, sizeof(basename));
|
||||
else
|
||||
return -ENODEV;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
#include <sys/disk.h>
|
||||
|
||||
@ -189,6 +223,12 @@ int block_device_discard(int fd, int64_t offset, int64_t len)
|
||||
{
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
int get_device_by_uuid(uuid_d dev_uuid, const char* label, char* partition,
|
||||
char* device)
|
||||
{
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
#elif defined(__FreeBSD__)
|
||||
#include <sys/disk.h>
|
||||
|
||||
@ -209,6 +249,12 @@ int block_device_discard(int fd, int64_t offset, int64_t len)
|
||||
{
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
int get_device_by_uuid(uuid_d dev_uuid, const char* label, char* partition,
|
||||
char* device)
|
||||
{
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
#else
|
||||
# error "Unable to query block device size: unsupported platform, please report."
|
||||
#endif
|
||||
|
@ -9,4 +9,6 @@ extern int get_block_device_size(int fd, int64_t *psize);
|
||||
extern int64_t get_block_device_int_property(const char *devname, const char *property);
|
||||
extern bool block_device_support_discard(const char *devname);
|
||||
extern int block_device_discard(int fd, int64_t offset, int64_t len);
|
||||
extern int get_device_by_uuid(uuid_d dev_uuid, const char* label,
|
||||
char* partition, char* device);
|
||||
#endif
|
||||
|
@ -76,6 +76,7 @@ using ceph::crypto::SHA1;
|
||||
#include "include/assert.h"
|
||||
|
||||
#include "common/config.h"
|
||||
#include "common/blkdev.h"
|
||||
|
||||
#ifdef WITH_LTTNG
|
||||
#include "tracing/objectstore.h"
|
||||
@ -637,10 +638,32 @@ bool parse_attrname(char **name)
|
||||
|
||||
void FileStore::collect_metadata(map<string,string> *pm)
|
||||
{
|
||||
char partition_path[PATH_MAX];
|
||||
char dev_node[PATH_MAX];
|
||||
int rc = 0;
|
||||
|
||||
(*pm)["filestore_backend"] = backend->get_name();
|
||||
ostringstream ss;
|
||||
ss << "0x" << std::hex << m_fs_type << std::dec;
|
||||
(*pm)["filestore_f_type"] = ss.str();
|
||||
|
||||
rc = get_device_by_uuid(get_fsid(), "PARTUUID", partition_path,
|
||||
dev_node);
|
||||
|
||||
switch (rc) {
|
||||
case -EOPNOTSUPP:
|
||||
case -EINVAL:
|
||||
(*pm)["backend_filestore_partition_path"] = "unknown";
|
||||
(*pm)["backend_filestore_dev_node"] = "unknown";
|
||||
break;
|
||||
case -ENODEV:
|
||||
(*pm)["backend_filestore_partition_path"] = string(partition_path);
|
||||
(*pm)["backend_filestore_dev_node"] = "unknown";
|
||||
break;
|
||||
default:
|
||||
(*pm)["backend_filestore_partition_path"] = string(partition_path);
|
||||
(*pm)["backend_filestore_dev_node"] = string(dev_node);
|
||||
}
|
||||
}
|
||||
|
||||
int FileStore::statfs(struct statfs *buf)
|
||||
|
@ -82,6 +82,8 @@ TEST_P(StoreTest, collect_metadata) {
|
||||
if (GetParam() == string("filestore")) {
|
||||
ASSERT_NE(pm.count("filestore_backend"), 0u);
|
||||
ASSERT_NE(pm.count("filestore_f_type"), 0u);
|
||||
ASSERT_NE(pm.count("backend_filestore_partition_path"), 0u);
|
||||
ASSERT_NE(pm.count("backend_filestore_dev_node"), 0u);
|
||||
} else if (GetParam() == string("keyvaluestore")) {
|
||||
ASSERT_NE(pm.count("keyvaluestore_backend"), 0u);
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <inttypes.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include "include/uuid.h"
|
||||
#include "common/blkdev.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
Loading…
Reference in New Issue
Block a user