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_get_luns(struct spdk_jsonrpc_request *request, 42 const struct spdk_json_val *params) 43 { 44 struct spdk_json_write_ctx *w; 45 struct spdk_lun_db_entry *current; 46 47 if (params != NULL) { 48 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, 49 "get_luns requires no parameters"); 50 return; 51 } 52 53 w = spdk_jsonrpc_begin_result(request); 54 if (w == NULL) { 55 return; 56 } 57 58 spdk_json_write_array_begin(w); 59 60 current = spdk_scsi_lun_list_head; 61 while (current != NULL) { 62 struct spdk_scsi_lun *lun = current->lun; 63 64 spdk_json_write_object_begin(w); 65 spdk_json_write_name(w, "claimed"); 66 spdk_json_write_bool(w, lun->claimed); 67 spdk_json_write_name(w, "name"); 68 spdk_json_write_string(w, lun->name); 69 spdk_json_write_object_end(w); 70 71 current = current->next; 72 } 73 74 spdk_json_write_array_end(w); 75 76 spdk_jsonrpc_end_result(request, w); 77 } 78 SPDK_RPC_REGISTER("get_luns", spdk_rpc_get_luns) 79 80 static void 81 spdk_rpc_get_scsi_devices(struct spdk_jsonrpc_request *request, 82 const struct spdk_json_val *params) 83 { 84 struct spdk_json_write_ctx *w; 85 struct spdk_scsi_dev *devs = spdk_scsi_dev_get_list(); 86 int i; 87 88 if (params != NULL) { 89 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, 90 "get_scsi_devices requires no parameters"); 91 return; 92 } 93 94 w = spdk_jsonrpc_begin_result(request); 95 if (w == NULL) { 96 return; 97 } 98 99 spdk_json_write_array_begin(w); 100 101 for (i = 0; i < SPDK_SCSI_MAX_DEVS; i++) { 102 struct spdk_scsi_dev *dev = &devs[i]; 103 104 if (!dev->is_allocated) { 105 continue; 106 } 107 108 spdk_json_write_object_begin(w); 109 110 spdk_json_write_name(w, "id"); 111 spdk_json_write_int32(w, dev->id); 112 113 spdk_json_write_name(w, "device_name"); 114 spdk_json_write_string(w, dev->name); 115 116 spdk_json_write_object_end(w); 117 } 118 spdk_json_write_array_end(w); 119 120 spdk_jsonrpc_end_result(request, w); 121 } 122 SPDK_RPC_REGISTER("get_scsi_devices", spdk_rpc_get_scsi_devices) 123