Line data Source code
1 : /* SPDX-License-Identifier: BSD-3-Clause 2 : * Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>. 3 : * Copyright (C) 2016 Intel Corporation. 4 : * All rights reserved. 5 : */ 6 : 7 : #include "scsi_internal.h" 8 : 9 : #include "spdk/rpc.h" 10 : #include "spdk/util.h" 11 : 12 : static void 13 0 : rpc_scsi_get_devices(struct spdk_jsonrpc_request *request, 14 : const struct spdk_json_val *params) 15 : { 16 : struct spdk_json_write_ctx *w; 17 0 : struct spdk_scsi_dev *devs = scsi_dev_get_list(); 18 : int i; 19 : 20 0 : if (params != NULL) { 21 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, 22 : "scsi_get_devices requires no parameters"); 23 0 : return; 24 : } 25 : 26 0 : w = spdk_jsonrpc_begin_result(request); 27 0 : spdk_json_write_array_begin(w); 28 : 29 0 : for (i = 0; i < SPDK_SCSI_MAX_DEVS; i++) { 30 0 : struct spdk_scsi_dev *dev = &devs[i]; 31 : 32 0 : if (!dev->is_allocated) { 33 0 : continue; 34 : } 35 : 36 0 : spdk_json_write_object_begin(w); 37 : 38 0 : spdk_json_write_named_int32(w, "id", dev->id); 39 : 40 0 : spdk_json_write_named_string(w, "device_name", dev->name); 41 : 42 0 : spdk_json_write_object_end(w); 43 : } 44 0 : spdk_json_write_array_end(w); 45 : 46 0 : spdk_jsonrpc_end_result(request, w); 47 : } 48 0 : SPDK_RPC_REGISTER("scsi_get_devices", rpc_scsi_get_devices, SPDK_RPC_RUNTIME)