From: Sage Weil Date: Fri, 24 Mar 2017 15:22:16 +0000 (-0400) Subject: common/blkdev: take fd for device node or regular file X-Git-Tag: v12.0.2~164^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1a6a1be777dc853875479facea203a3eb098aca7;p=ceph.git common/blkdev: take fd for device node or regular file Either way, return the partition and device name for the underlying device. Signed-off-by: Sage Weil --- diff --git a/src/common/blkdev.cc b/src/common/blkdev.cc index 6e956deece04..bc89eea4cf14 100644 --- a/src/common/blkdev.cc +++ b/src/common/blkdev.cc @@ -252,13 +252,15 @@ int get_device_by_fd(int fd, char *partition, char *device) if (r < 0) { return -EINVAL; // hrm. } - char *t = blkid_devno_to_devname(st.st_rdev); + dev_t devid = S_ISBLK(st.st_mode) ? st.st_rdev : st.st_dev; + char *t = blkid_devno_to_devname(devid); if (!t) { return -EINVAL; } strcpy(partition, t); + free(t); dev_t diskdev; - r = blkid_devno_to_wholedisk(st.st_rdev, device, PATH_MAX, &diskdev); + r = blkid_devno_to_wholedisk(devid, device, PATH_MAX, &diskdev); if (r < 0) { return -EINVAL; }