]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/blkdev: add get_device_by_path
authorSage Weil <sage@redhat.com>
Tue, 18 Sep 2018 19:29:21 +0000 (14:29 -0500)
committerSage Weil <sage@redhat.com>
Mon, 15 Oct 2018 14:44:05 +0000 (09:44 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/common/blkdev.cc
src/common/blkdev.h

index f7c476076d9926ebb256922345a7630cab02d2b8..5e103e15b6030d7ebd6440771bc4c5b3473aafd3 100644 (file)
 #include "include/uuid.h"
 #include "blkdev.h"
 
+int get_device_by_path(const char *path, char* partition, char* device,
+                      size_t max)
+{
+  int fd = ::open(path, O_RDONLY|O_DIRECTORY);
+  if (fd < 0) {
+    return -errno;
+  }
+  int r = get_device_by_fd(fd, partition, device, max);
+  ::close(fd);
+  return r;
+}
+
+
 #ifdef __linux__
 #include <libudev.h>
 #include <linux/fs.h>
index 6e29d0eb8fb3a031ca8e812ad0169b9ce6013633..6cbe16b6f88d812e57e64232c54c3274a90b08f3 100644 (file)
@@ -13,6 +13,7 @@ extern int get_block_device_base(const char *path, char *devname, size_t len);
 // from an fd
 extern int block_device_discard(int fd, int64_t offset, int64_t len);
 extern int get_block_device_size(int fd, int64_t *psize);
+extern int get_device_by_path(const char *path, char* partition, char* device, size_t max);
 extern int get_device_by_fd(int fd, char* partition, char* device, size_t max);
 
 // from a device (e.g., "sdb")