Skip to contentSkip to conversation

blockdev: report error on block latency histogram set error

PATCH In review zhenwei pi 2 participants 2 messages Oct 18, 2018 – Oct 31, 2018

lore
Share & tools
lore

zhenwei pi

author
#0 lore raw

PATCH 1/1 blockdev: report error on block latency histogram set error

Function block_latency_histogram_set may return error, but qapi ignore this. This can be reproduced easily by qmp command:
virsh qemu-monitor-command INSTANCE '{"execute":"x-block-latency-histogram-set", "arguments":{"device":"drive-virtio-disk1","boundaries":[10,200,40]}}' In fact this command does not work, but we still get success result.

qmp_x_block_latency_histogram_set is a batch setting API, report error ASAP.

---
 blockdev.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
blockdev.c +16 -3
index a8755bd..03b1aa3 100644
@@ -4377,6 +4377,7 @@ void qmp_x_block_latency_histogram_set(
 {
     BlockBackend *blk = blk_by_name(device);
     BlockAcctStats *stats;
+    int ret;
 
     if (!blk) {
         error_setg(errp, "Device '%s' not found", device);
@@ -4392,21 +4393,33 @@ void qmp_x_block_latency_histogram_set(
     }
 
     if (has_boundaries || has_boundaries_read) {
-        block_latency_histogram_set(
+        ret = block_latency_histogram_set(
             stats, BLOCK_ACCT_READ,
             has_boundaries_read ? boundaries_read : boundaries);
+        if (ret) {
+            error_setg(errp, "Device '%s' set read boundaries fail", device);
+            return;
+        }
     }
 
     if (has_boundaries || has_boundaries_write) {
-        block_latency_histogram_set(
+        ret = block_latency_histogram_set(
             stats, BLOCK_ACCT_WRITE,
             has_boundaries_write ? boundaries_write : boundaries);
+        if (ret) {
+            error_setg(errp, "Device '%s' set write boundaries fail", device);
+            return;
+        }
     }
 
     if (has_boundaries || has_boundaries_flush) {
-        block_latency_histogram_set(
+        ret = block_latency_histogram_set(
             stats, BLOCK_ACCT_FLUSH,
             has_boundaries_flush ? boundaries_flush : boundaries);
+        if (ret) {
+            error_setg(errp, "Device '%s' set flush boundaries fail", device);
+            return;
+        }
     }
 }
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 10 lines · zhenwei pi

Function block_latency_histogram_set may return error, but qapi ignore this.
This can be reproduced easily by qmp command:
virsh qemu-monitor-command INSTANCE '{"execute":"x-block-latency-histogram-set", "arguments":{"device":"drive-virtio-disk1","boundaries":[10,200,40]}}' In fact this command does not work, but we still get success result.

qmp_x_block_latency_histogram_set is a batch setting API, report error ASAP.

Good catch, thank you, it's my fault!

The problem of the patch is that in case of error, boundaries for read (or write) may be set, when others are not.
Better thing is refactor it somehow so that in case of error nothing changed finally.

Quoted 58 lines

---
 blockdev.c | 19 ++++++++++++++++---

 1 file changed, 16 insertions(+), 3 deletions(-)
blockdev.c +16 -3
index a8755bd..03b1aa3 100644
@@ -4377,6 +4377,7 @@ void qmp_x_block_latency_histogram_set(
  {
      BlockBackend *blk = blk_by_name(device);
      BlockAcctStats *stats;
+    int ret;
 
      if (!blk) {
          error_setg(errp, "Device '%s' not found", device);
@@ -4392,21 +4393,33 @@ void qmp_x_block_latency_histogram_set(
      }
 
      if (has_boundaries || has_boundaries_read) {
-        block_latency_histogram_set(
+        ret = block_latency_histogram_set(
              stats, BLOCK_ACCT_READ,
              has_boundaries_read ? boundaries_read : boundaries);
+        if (ret) {
+            error_setg(errp, "Device '%s' set read boundaries fail", 
 device);
+            return;
+        }
      }
 
      if (has_boundaries || has_boundaries_write) {
-        block_latency_histogram_set(
+        ret = block_latency_histogram_set(
              stats, BLOCK_ACCT_WRITE,
              has_boundaries_write ? boundaries_write : boundaries);
+        if (ret) {
+            error_setg(errp, "Device '%s' set write boundaries fail", 
 device);
+            return;
+        }
      }
 
      if (has_boundaries || has_boundaries_flush) {
-        block_latency_histogram_set(
+        ret = block_latency_histogram_set(
              stats, BLOCK_ACCT_FLUSH,
              has_boundaries_flush ? boundaries_flush : boundaries);
+        if (ret) {
+            error_setg(errp, "Device '%s' set flush boundaries fail", 
 device);
+            return;
+        }

     }
 }

Signature · 2 lines
Best regards,
Vladimir