Skip to contentSkip to conversation

spapr-vscsi: Report error on unsupported MAD requests

PATCH Superseded Alexey Kardashevskiy 4 participants 4 messages Aug 23, 2013 – Aug 27, 2013

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spapr-vscsi: Report error on unsupported MAD requests

The existing driver just dropped unsupported requests. This adds error responses to those unhandled requests.

---
 hw/scsi/spapr_vscsi.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
hw/scsi/spapr_vscsi.c +6 -6
index cc35b1b..9259d7e 100644
@@ -957,24 +957,24 @@ static int vscsi_handle_mad_req(VSCSIState *s, vscsi_req *req)
         break;
     case VIOSRP_ERROR_LOG_TYPE:
         fprintf(stderr, "Unsupported ERROR LOG MAD IU\n");
-        mad->error_log.common.status = cpu_to_be16(1);
-        vscsi_send_iu(s, req, sizeof(mad->error_log), VIOSRP_MAD_FORMAT);
         break;
     case VIOSRP_ADAPTER_INFO_TYPE:
         vscsi_send_adapter_info(s, req);
-        break;
+        return 1;
     case VIOSRP_HOST_CONFIG_TYPE:
-        mad->host_config.common.status = cpu_to_be16(1);
-        vscsi_send_iu(s, req, sizeof(mad->host_config), VIOSRP_MAD_FORMAT);
+        fprintf(stderr, "Unsupported HOST CONFIG TYPE MAD IU\n");
         break;
     case VIOSRP_CAPABILITIES_TYPE:
         vscsi_send_capabilities(s, req);
-        break;
+        return 1;
     default:
         fprintf(stderr, "VSCSI: Unknown MAD type %02x\n",
                 be32_to_cpu(mad->empty_iu.common.type));
     }
 
+    mad->empty_iu.common.status = cpu_to_be16(VIOSRP_MAD_NOT_SUPPORTED);
+    vscsi_send_iu(s, req, mad->empty_iu.common.length, VIOSRP_MAD_FORMAT);
+
     return 1;
 }
 
Signature · 1 line
1.8.4.rc4
#1 lore raw
Quoted 13 lines · Alexey Kardashevskiy

The existing driver just dropped unsupported requests. This adds error responses to those unhandled requests.

---
hw/scsi/spapr_vscsi.c | 12 ++++++------

1 file changed, 6 insertions(+), 6 deletions(-)
hw/scsi/spapr_vscsi.c +0 -0
index cc35b1b..9259d7e 100644

hw/scsi/spapr_vscsi.c static int vscsi_handle_mad_req(VSCSIState *s, vscsi_req *req) · line 959

Quoted 3 lines
hw/scsi/spapr_vscsi.c +0 -0
@@ -957,24 +957,24 @@ static int vscsi_handle_mad_req(VSCSIState *s, vscsi_req *req)
        break;
    case VIOSRP_ERROR_LOG_TYPE:
        fprintf(stderr, "Unsupported ERROR LOG MAD IU\n");

These should probably be error_report() calls.

hw/scsi/spapr_vscsi.c static int vscsi_handle_mad_req(VSCSIState *s, vscsi_req *req) · line 961

Quoted 2 lines
hw/scsi/spapr_vscsi.c +0 -2
-        mad->error_log.common.status = cpu_to_be16(1);
-        vscsi_send_iu(s, req, sizeof(mad->error_log), VIOSRP_MAD_FORMAT);

This changes the reply from sizeof(mad->error_log) to mad->empty_io.common.length. Is this correct?

hw/scsi/spapr_vscsi.c static int vscsi_handle_mad_req(VSCSIState *s, vscsi_req *req) · line 963

Quoted 5 lines
hw/scsi/spapr_vscsi.c +1 -1
        break;
    case VIOSRP_ADAPTER_INFO_TYPE:
        vscsi_send_adapter_info(s, req);
-        break;
+        return 1;

Please turn this into a boolean variable that tells the common code below that we've successfully handled the request.

Quoted 4 lines
hw/scsi/spapr_vscsi.c +1 -2
    case VIOSRP_HOST_CONFIG_TYPE:
-        mad->host_config.common.status = cpu_to_be16(1);
-        vscsi_send_iu(s, req, sizeof(mad->host_config), VIOSRP_MAD_FORMAT);
+        fprintf(stderr, "Unsupported HOST CONFIG TYPE MAD IU\n");

hw/scsi/spapr_vscsi.c static int vscsi_handle_mad_req(VSCSIState *s, vscsi_req *req) · line 974

Quoted 10 lines
hw/scsi/spapr_vscsi.c +1 -1
        break;
    case VIOSRP_CAPABILITIES_TYPE:
        vscsi_send_capabilities(s, req);
-        break;
+        return 1;
    default:
        fprintf(stderr, "VSCSI: Unknown MAD type %02x\n",
                be32_to_cpu(mad->empty_iu.common.type));
    }
 

then you can just put the handling below in an

if (!request_handled) { }

block which makes the code a lot easier to follow. Multiple exit points of a function are a pretty regular source of breakage, because you're very likely to miss one.

hw/scsi/spapr_vscsi.c static int vscsi_handle_mad_req(VSCSIState *s, vscsi_req *req) · line 976

Quoted 2 lines
hw/scsi/spapr_vscsi.c +2 -0
+    mad->empty_iu.common.status = cpu_to_be16(VIOSRP_MAD_NOT_SUPPORTED);
+    vscsi_send_iu(s, req, mad->empty_iu.common.length, VIOSRP_MAD_FORMAT);

Doesn't the length have to be endianness swapped too?

Alex

Quoted 7 lines
hw/scsi/spapr_vscsi.c +1 -0
+
    return 1;
 }
 
Signature · 1 line
1.8.4.rc4
#2 lore raw
In reply to Alexey Kardashevskiy

Il 23/08/2013 11:23, Alexey Kardashevskiy ha scritto:

Quoted 13 lines

The existing driver just dropped unsupported requests. This adds error responses to those unhandled requests.

---
 hw/scsi/spapr_vscsi.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
hw/scsi/spapr_vscsi.c +0 -0
index cc35b1b..9259d7e 100644

hw/scsi/spapr_vscsi.c static int vscsi_handle_mad_req(VSCSIState *s, vscsi_req *req) · line 959

Quoted 3 lines
hw/scsi/spapr_vscsi.c +0 -0
@@ -957,24 +957,24 @@ static int vscsi_handle_mad_req(VSCSIState *s, vscsi_req *req)
         break;
     case VIOSRP_ERROR_LOG_TYPE:
         fprintf(stderr, "Unsupported ERROR LOG MAD IU\n");

Please use error_report...

hw/scsi/spapr_vscsi.c static int vscsi_handle_mad_req(VSCSIState *s, vscsi_req *req) · line 965

Quoted 11 lines
hw/scsi/spapr_vscsi.c +2 -5
-        mad->error_log.common.status = cpu_to_be16(1);
-        vscsi_send_iu(s, req, sizeof(mad->error_log), VIOSRP_MAD_FORMAT);
         break;
     case VIOSRP_ADAPTER_INFO_TYPE:
         vscsi_send_adapter_info(s, req);
-        break;
+        return 1;
     case VIOSRP_HOST_CONFIG_TYPE:
-        mad->host_config.common.status = cpu_to_be16(1);
-        vscsi_send_iu(s, req, sizeof(mad->host_config), VIOSRP_MAD_FORMAT);
+        fprintf(stderr, "Unsupported HOST CONFIG TYPE MAD IU\n");

... especially in this new fprintf...

hw/scsi/spapr_vscsi.c static int vscsi_handle_mad_req(VSCSIState *s, vscsi_req *req) · line 972

Quoted 8 lines
hw/scsi/spapr_vscsi.c +1 -1
         break;
     case VIOSRP_CAPABILITIES_TYPE:
         vscsi_send_capabilities(s, req);
-        break;
+        return 1;
     default:
         fprintf(stderr, "VSCSI: Unknown MAD type %02x\n",
                 be32_to_cpu(mad->empty_iu.common.type));

... and here too, please.

Thanks,

Paolo

Quoted 9 lines
hw/scsi/spapr_vscsi.c +3 -0
     }
 
+    mad->empty_iu.common.status = cpu_to_be16(VIOSRP_MAD_NOT_SUPPORTED);
+    vscsi_send_iu(s, req, mad->empty_iu.common.length, VIOSRP_MAD_FORMAT);
+
     return 1;
 }
 
#3 lore raw
Quoted 9 lines · Paolo Bonzini

Il 23/08/2013 11:23, Alexey Kardashevskiy ha scritto:

Quoted 8 lines

The existing driver just dropped unsupported requests. This adds error responses to those unhandled requests.

---
 hw/scsi/spapr_vscsi.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
Quoted 10 lines

hw/scsi/spapr_vscsi.c static int vscsi_handle_mad_req(VSCSIState *s, vscsi_req *req) · line 959

Quoted 8 lines
hw/scsi/spapr_vscsi.c +0 -0
index cc35b1b..9259d7e 100644
@@ -957,24 +957,24 @@ static int vscsi_handle_mad_req(VSCSIState *s, vscsi_req *req)
         break;
     case VIOSRP_ERROR_LOG_TYPE:
         fprintf(stderr, "Unsupported ERROR LOG MAD IU\n");

Please use error_report...

So we have this discussion on IRC and I somewhat disagree..

Yes, this driver should be updated to use error_report. However, it currently doesn't and I think it should remain consistent. IE. This patch should use whatever the driver already uses and a separate patch should convert the whole thing to error_report.

Quoted 38 lines

hw/scsi/spapr_vscsi.c static int vscsi_handle_mad_req(VSCSIState *s, vscsi_req *req) · line 965

Quoted 11 lines
hw/scsi/spapr_vscsi.c +2 -5
-        mad->error_log.common.status = cpu_to_be16(1);
-        vscsi_send_iu(s, req, sizeof(mad->error_log), VIOSRP_MAD_FORMAT);
         break;
     case VIOSRP_ADAPTER_INFO_TYPE:
         vscsi_send_adapter_info(s, req);
-        break;
+        return 1;
     case VIOSRP_HOST_CONFIG_TYPE:
-        mad->host_config.common.status = cpu_to_be16(1);
-        vscsi_send_iu(s, req, sizeof(mad->host_config), VIOSRP_MAD_FORMAT);
+        fprintf(stderr, "Unsupported HOST CONFIG TYPE MAD IU\n");

... especially in this new fprintf...

hw/scsi/spapr_vscsi.c static int vscsi_handle_mad_req(VSCSIState *s, vscsi_req *req) · line 972

Quoted 8 lines
hw/scsi/spapr_vscsi.c +1 -1
         break;
     case VIOSRP_CAPABILITIES_TYPE:
         vscsi_send_capabilities(s, req);
-        break;
+        return 1;
     default:
         fprintf(stderr, "VSCSI: Unknown MAD type %02x\n",
                 be32_to_cpu(mad->empty_iu.common.type));

... and here too, please.

Thanks,

Paolo

Quoted 9 lines
hw/scsi/spapr_vscsi.c +3 -0
     }
 
+    mad->empty_iu.common.status = cpu_to_be16(VIOSRP_MAD_NOT_SUPPORTED);
+    vscsi_send_iu(s, req, mad->empty_iu.common.length, VIOSRP_MAD_FORMAT);
+
     return 1;
 }