]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
blkdev: move test_get_blkdev_size to test_get_blkdev_props
authorAlan Somers <asomers@gmail.com>
Tue, 3 Oct 2017 15:56:32 +0000 (09:56 -0600)
committerKefu Chai <kchai@redhat.com>
Fri, 19 Oct 2018 11:35:23 +0000 (19:35 +0800)
Also, enhance blkdev test program to show more properties than just size

Signed-off-by: Alan Somers <asomers@gmail.com>
src/test/CMakeLists.txt
src/test/test_get_blkdev_props.cc [new file with mode: 0644]
src/test/test_get_blkdev_size.cc [deleted file]

index 4592520bad2e0826d468113ac45cb9641bb27159..49ae77e2ac5b3227ec2d87ceb095e0f3c3488c1b 100644 (file)
@@ -448,10 +448,10 @@ if(${WITH_CEPHFS})
 endif(${WITH_CEPHFS})
 
 if(HAVE_BLKID)
-  add_executable(ceph_test_get_blkdev_size
-    test_get_blkdev_size.cc
+  add_executable(ceph_test_get_blkdev_props
+    test_get_blkdev_props.cc
     )
-  target_link_libraries(ceph_test_get_blkdev_size
+  target_link_libraries(ceph_test_get_blkdev_props
     ceph-common
     pthread
     ${EXTRALIBS}
diff --git a/src/test/test_get_blkdev_props.cc b/src/test/test_get_blkdev_props.cc
new file mode 100644 (file)
index 0000000..1d16569
--- /dev/null
@@ -0,0 +1,93 @@
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include "include/uuid.h"
+#include "common/blkdev.h"
+
+#define BUFSIZE        80
+
+int main(int argc, char **argv)
+{
+       int fd, ret;
+       int64_t size;
+       bool discard_support;
+       bool nvme;
+       bool rotational;
+       char device[BUFSIZE];
+       char partition[BUFSIZE];
+       char dev[BUFSIZE];
+       char model[BUFSIZE];
+       char serial[BUFSIZE];
+       char device[BUFSIZE];
+       char partition[BUFSIZE];
+
+       if (argc != 2) {
+               fprintf(stderr, "usage: %s <blkdev>\n", argv[0]);
+               return -1;
+       }
+
+       fd = open(argv[1], O_RDONLY);
+       if (fd < 0) {
+               perror("open");
+               return -1;
+       }
+
+       if ((ret = get_block_device_size(fd, &size)) < 0) {
+               fprintf(stderr, "get_block_device_size: %s\n", strerror(-ret));
+               return -1;
+       }
+
+       if ((ret = get_device_by_fd(fd, partition, device, BUFSIZE)) < 0) {
+               fprintf(stderr, "get_device_by_fd: %s\n", strerror(-ret));
+               return -1;
+       }
+
+       discard_support = block_device_support_discard(device);
+
+       nvme = block_device_is_nvme(device);
+
+       rotational = block_device_is_rotational(device);
+
+       if ((ret = block_device_dev(device, dev, BUFSIZE)) < 0) {
+               fprintf(stderr, "block_device_dev: %s\n", strerror(-ret));
+               return -1;
+       }
+
+       if ((ret = blkdev.get_device_by_fd(partition, device, BUFSIZE)) < 0) {
+               fprintf(stderr, "get_device_by_fd: %s\n", strerror(-ret));
+               return -1;
+       }
+
+       ret = blkdev.block_device_model(model, BUFSIZE);
+       if (ret == -ENOENT) {
+               snprintf(model, BUFSIZE, "unknown");
+       } else if (ret < 0) {
+               fprintf(stderr, "block_device_model: %s\n", strerror(-ret));
+               return -1;
+       }
+
+       ret = block_device_serial(device, serial, BUFSIZE);
+       if (ret == -ENOENT) {
+               snprintf(serial, BUFSIZE, "unknown");
+       } else if (ret < 0) {
+               fprintf(stderr, "block_device_serial: %s\n", strerror(-ret));
+               return -1;
+       }
+
+       fprintf(stdout, "Size:\t\t%" PRId64 "\n", size);
+       fprintf(stdout, "Discard:\t%s\n",
+               discard_support ? "supported" : "not supported");
+       fprintf(stdout, "NVME:\t\t%s\n", nvme ? "yes" : "no");
+       fprintf(stdout, "Rotational:\t%s\n", rotational ? "yes" : "no");
+       fprintf(stdout, "Dev:\t\t%s\n", dev);
+       fprintf(stdout, "Device:\t\t%s\n", device);
+       fprintf(stdout, "Partition:\t%s\n", partition);
+       fprintf(stdout, "Model:\t\t%s\n", model);
+       fprintf(stdout, "Serial:\t\t%s\n", serial);
+
+       return 0;
+}
diff --git a/src/test/test_get_blkdev_size.cc b/src/test/test_get_blkdev_size.cc
deleted file mode 100644 (file)
index db19c79..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <fcntl.h>
-#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)
-{
-       int fd, ret;
-       int64_t size;
-
-       if (argc != 2) {
-               fprintf(stderr, "usage: %s <blkdev>\n", argv[0]);
-               return -1;
-       }
-
-       fd = open(argv[1], O_RDONLY);
-       if (fd < 0) {
-               perror("open");
-               return -1;
-       }
-
-       ret = get_block_device_size(fd, &size);
-       if (ret < 0) {
-               fprintf(stderr, "get_block_device_size: %s\n", strerror(-ret));
-               return -1;
-       }
-
-       fprintf(stdout, "%" PRId64, size);
-
-       return 0;
-}