]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/blkdev: implement get_device_by_fd
authorSage Weil <sage@redhat.com>
Fri, 24 Mar 2017 00:18:18 +0000 (19:18 -0500)
committerSage Weil <sage@redhat.com>
Wed, 29 Mar 2017 17:23:59 +0000 (13:23 -0400)
Complement to get_device_by_uuid, but we provide an fd.

Signed-off-by: Sage Weil <sage@redhat.com>
src/common/blkdev.cc
src/common/blkdev.h

index f3262d53a81c5252bcd595fd8c1b7d54ac723b35..17fe0e6ac835725211bf40b683947ddf472e07d2 100644 (file)
@@ -222,6 +222,27 @@ int get_device_by_uuid(uuid_d dev_uuid, const char* label, char* partition,
     blkid_put_cache(cache);
   return rc;
 }
+
+int get_device_by_fd(int fd, char *partition, char *device)
+{
+  struct stat st;
+  int r = fstat(fd, &st);
+  if (r < 0) {
+    return -EINVAL;  // hrm.
+  }
+  char *t = blkid_devno_to_devname(st.st_rdev);
+  if (!t) {
+    return -EINVAL;
+  }
+  strcpy(partition, t);
+  dev_t diskdev;
+  r = blkid_devno_to_wholedisk(st.st_rdev, device, PATH_MAX, &diskdev);
+  if (r < 0) {
+    return -EINVAL;
+  }
+  return 0;
+}
+
 #elif defined(__APPLE__)
 #include <sys/disk.h>
 
@@ -291,6 +312,10 @@ int get_device_by_uuid(uuid_d dev_uuid, const char* label, char* partition,
 {
   return -EOPNOTSUPP;
 }
+int get_device_by_fd(int fd, char* partition, char* device)
+{
+  return -EOPNOTSUPP;
+}
 #else
 int get_block_device_size(int fd, int64_t *psize)
 {
@@ -317,4 +342,9 @@ int get_device_by_uuid(uuid_d dev_uuid, const char* label, char* partition,
 {
   return -EOPNOTSUPP;
 }
+
+int get_device_by_fd(int fd, char* partition, char* device)
+{
+  return -EOPNOTSUPP;
+}
 #endif
index e37f5694e84a79987fcbf4a196635242ea18e52c..b0459b750df78c67025cef665c1cd7c41cd1afb1 100644 (file)
@@ -12,4 +12,5 @@ extern bool block_device_is_rotational(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);
+extern int get_device_by_fd(int fd, char* partition, char* device);
 #endif