qapi/parser: enable pylint checks
[qemu/armbru.git] / hw / nvme / subsys.c
blob495dcff5ebb8f87e768b415926f3d140cd94891b
1 /*
2 * QEMU NVM Express Subsystem: nvme-subsys
4 * Copyright (c) 2021 Minwoo Im <minwoo.im.dev@gmail.com>
6 * This code is licensed under the GNU GPL v2. Refer COPYING.
7 */
9 #include "qemu/osdep.h"
10 #include "qapi/error.h"
12 #include "nvme.h"
14 int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp)
16 NvmeSubsystem *subsys = n->subsys;
17 int cntlid;
19 for (cntlid = 0; cntlid < ARRAY_SIZE(subsys->ctrls); cntlid++) {
20 if (!subsys->ctrls[cntlid]) {
21 break;
25 if (cntlid == ARRAY_SIZE(subsys->ctrls)) {
26 error_setg(errp, "no more free controller id");
27 return -1;
30 subsys->ctrls[cntlid] = n;
32 return cntlid;
35 void nvme_subsys_unregister_ctrl(NvmeSubsystem *subsys, NvmeCtrl *n)
37 subsys->ctrls[n->cntlid] = NULL;
40 static void nvme_subsys_setup(NvmeSubsystem *subsys)
42 const char *nqn = subsys->params.nqn ?
43 subsys->params.nqn : subsys->parent_obj.id;
45 snprintf((char *)subsys->subnqn, sizeof(subsys->subnqn),
46 "nqn.2019-08.org.qemu:%s", nqn);
49 static void nvme_subsys_realize(DeviceState *dev, Error **errp)
51 NvmeSubsystem *subsys = NVME_SUBSYS(dev);
53 qbus_init(&subsys->bus, sizeof(NvmeBus), TYPE_NVME_BUS, dev, dev->id);
55 nvme_subsys_setup(subsys);
58 static Property nvme_subsystem_props[] = {
59 DEFINE_PROP_STRING("nqn", NvmeSubsystem, params.nqn),
60 DEFINE_PROP_END_OF_LIST(),
63 static void nvme_subsys_class_init(ObjectClass *oc, void *data)
65 DeviceClass *dc = DEVICE_CLASS(oc);
67 set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
69 dc->realize = nvme_subsys_realize;
70 dc->desc = "Virtual NVMe subsystem";
71 dc->hotpluggable = false;
73 device_class_set_props(dc, nvme_subsystem_props);
76 static const TypeInfo nvme_subsys_info = {
77 .name = TYPE_NVME_SUBSYS,
78 .parent = TYPE_DEVICE,
79 .class_init = nvme_subsys_class_init,
80 .instance_size = sizeof(NvmeSubsystem),
83 static void nvme_subsys_register_types(void)
85 type_register_static(&nvme_subsys_info);
88 type_init(nvme_subsys_register_types)