Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (C) 2019 Intel Corporation. All rights reserved.
3 : : * Copyright (c) 2018 Mellanox Technologies LTD. All rights reserved.
4 : : */
5 : :
6 : : #include "spdk/stdinc.h"
7 : : #include "spdk/rpc.h"
8 : : #include "spdk/util.h"
9 : :
10 : : #include "vhost_fuzz.h"
11 : :
12 : : struct rpc_fuzz_vhost_dev_create {
13 : : char *socket;
14 : : bool is_blk;
15 : : bool use_bogus_buffer;
16 : : bool use_valid_buffer;
17 : : bool valid_lun;
18 : : bool test_scsi_tmf;
19 : : };
20 : :
21 : : static const struct spdk_json_object_decoder rpc_fuzz_vhost_dev_create_decoders[] = {
22 : : {"socket", offsetof(struct rpc_fuzz_vhost_dev_create, socket), spdk_json_decode_string},
23 : : {"is_blk", offsetof(struct rpc_fuzz_vhost_dev_create, is_blk), spdk_json_decode_bool, true},
24 : : {"use_bogus_buffer", offsetof(struct rpc_fuzz_vhost_dev_create, use_bogus_buffer), spdk_json_decode_bool, true},
25 : : {"use_valid_buffer", offsetof(struct rpc_fuzz_vhost_dev_create, use_valid_buffer), spdk_json_decode_bool, true},
26 : : {"valid_lun", offsetof(struct rpc_fuzz_vhost_dev_create, valid_lun), spdk_json_decode_bool, true},
27 : : {"test_scsi_tmf", offsetof(struct rpc_fuzz_vhost_dev_create, test_scsi_tmf), spdk_json_decode_bool, true},
28 : : };
29 : :
30 : : static void
31 : 0 : spdk_rpc_fuzz_vhost_create_dev(struct spdk_jsonrpc_request *request,
32 : : const struct spdk_json_val *params)
33 : : {
34 : 0 : struct rpc_fuzz_vhost_dev_create req = {0};
35 : : int rc;
36 : :
37 [ # # ]: 0 : if (spdk_json_decode_object(params, rpc_fuzz_vhost_dev_create_decoders,
38 : : SPDK_COUNTOF(rpc_fuzz_vhost_dev_create_decoders), &req)) {
39 : 0 : fprintf(stderr, "Unable to parse the request.\n");
40 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
41 : : "Unable to parse the object parameters.\n");
42 : 0 : return;
43 : : }
44 : :
45 [ # # ]: 0 : if (strlen(req.socket) > PATH_MAX) {
46 : 0 : fprintf(stderr, "Socket address is too long.\n");
47 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
48 : : "Unable to parse the object parameters.\n");
49 : 0 : free(req.socket);
50 : 0 : return;
51 : : }
52 : :
53 : 0 : rc = fuzz_vhost_dev_init(req.socket, req.is_blk, req.use_bogus_buffer, req.use_valid_buffer,
54 : 0 : req.valid_lun, req.test_scsi_tmf);
55 : :
56 [ # # ]: 0 : if (rc != 0) {
57 [ # # ]: 0 : if (rc == -ENOMEM) {
58 : 0 : fprintf(stderr, "No valid memory for device initialization.\n");
59 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
60 : : "No memory returned from host.\n");
61 [ # # ]: 0 : } else if (rc == -EINVAL) {
62 : 0 : fprintf(stderr, "Invalid device parameters provided.\n");
63 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
64 : : "Parameters provided were invalid.\n");
65 : : } else {
66 : 0 : fprintf(stderr, "unknown error from the guest.\n");
67 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
68 : : "Unexpected error code.\n");
69 : : }
70 : : } else {
71 : 0 : spdk_jsonrpc_send_bool_response(request, true);
72 : : }
73 : :
74 : 0 : free(req.socket);
75 : 0 : return;
76 : : }
77 : 0 : SPDK_RPC_REGISTER("fuzz_vhost_create_dev", spdk_rpc_fuzz_vhost_create_dev, SPDK_RPC_STARTUP);
|