1 /*- 2 * BSD LICENSE 3 * 4 * Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>. 5 * Copyright (c) Intel Corporation. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * * Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * * Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in 16 * the documentation and/or other materials provided with the 17 * distribution. 18 * * Neither the name of Intel Corporation nor the names of its 19 * contributors may be used to endorse or promote products derived 20 * from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 35 #include "scsi_internal.h" 36 37 #include "spdk/rpc.h" 38 #include "spdk/util.h" 39 40 static void 41 spdk_rpc_scsi_get_devices(struct spdk_jsonrpc_request *request, 42 const struct spdk_json_val *params) 43 { 44 struct spdk_json_write_ctx *w; 45 struct spdk_scsi_dev *devs = spdk_scsi_dev_get_list(); 46 int i; 47 48 if (params != NULL) { 49 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, 50 "scsi_get_devices requires no parameters"); 51 return; 52 } 53 54 w = spdk_jsonrpc_begin_result(request); 55 spdk_json_write_array_begin(w); 56 57 for (i = 0; i < SPDK_SCSI_MAX_DEVS; i++) { 58 struct spdk_scsi_dev *dev = &devs[i]; 59 60 if (!dev->is_allocated) { 61 continue; 62 } 63 64 spdk_json_write_object_begin(w); 65 66 spdk_json_write_named_int32(w, "id", dev->id); 67 68 spdk_json_write_named_string(w, "device_name", dev->name); 69 70 spdk_json_write_object_end(w); 71 } 72 spdk_json_write_array_end(w); 73 74 spdk_jsonrpc_end_result(request, w); 75 } 76 SPDK_RPC_REGISTER("scsi_get_devices", spdk_rpc_scsi_get_devices, SPDK_RPC_RUNTIME) 77 SPDK_RPC_REGISTER_ALIAS_DEPRECATED(scsi_get_devices, get_scsi_devices) 78