|
| 1 | +// SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of libnvme. |
| 5 | + * |
| 6 | + * Copyright (c) 2025, Dell Technologies Inc. or its subsidiaries. |
| 7 | + * Authors: Martin Belanger <[email protected]> |
| 8 | + * |
| 9 | + * ____ _ _ ____ _ |
| 10 | + * / ___| ___ _ __ ___ _ __ __ _| |_ ___ __| | / ___|___ __| | ___ |
| 11 | + * | | _ / _ \ '_ \ / _ \ '__/ _` | __/ _ \/ _` | | | / _ \ / _` |/ _ \ |
| 12 | + * | |_| | __/ | | | __/ | | (_| | || __/ (_| | | |__| (_) | (_| | __/ |
| 13 | + * \____|\___|_| |_|\___|_| \__,_|\__\___|\__,_| \____\___/ \__,_|\___| |
| 14 | + * |
| 15 | + * Auto-generated struct member accessors (setter/getter) |
| 16 | + * |
| 17 | + * To update run: meson compile -C [BUILD-DIR] update-accessors |
| 18 | + * Or: make update-accessors |
| 19 | + */ |
| 20 | +%pythoncode %{ |
| 21 | +def _nvme_guarded_setattr(self, name, value): |
| 22 | + """Reject writes to unknown attributes. |
| 23 | +
|
| 24 | + Typos like ``ctrl.nqn = x`` (should be ``ctrl.subsysnqn``) are |
| 25 | + silently ignored by default Python ``__setattr__``. This guard |
| 26 | + raises ``AttributeError`` for any name not already present on the |
| 27 | + object, keeping the struct-like API strict. |
| 28 | + """ |
| 29 | + if name.startswith('_') or name in ('this', 'thisown') or hasattr(type(self), name): |
| 30 | + object.__setattr__(self, name, value) |
| 31 | + else: |
| 32 | + raise AttributeError( |
| 33 | + f"{type(self).__name__!r} has no attribute {name!r}") |
| 34 | +%} |
| 35 | + |
| 36 | +/* struct libnvme_ns */ |
| 37 | +%rename(Namespace) libnvme_ns; |
| 38 | +%rename(libnvme_ns_command_retry_count_get) libnvme_ns_get_command_retry_count; |
| 39 | +%rename(libnvme_ns_command_error_count_get) libnvme_ns_get_command_error_count; |
| 40 | +%rename(libnvme_ns_requeue_no_usable_path_count_get) libnvme_ns_get_requeue_no_usable_path_count; |
| 41 | +%rename(libnvme_ns_fail_no_available_path_count_get) libnvme_ns_get_fail_no_available_path_count; |
| 42 | +%{ |
| 43 | + #define libnvme_ns_command_retry_count_get libnvme_ns_get_command_retry_count |
| 44 | + #define libnvme_ns_command_error_count_get libnvme_ns_get_command_error_count |
| 45 | + #define libnvme_ns_requeue_no_usable_path_count_get libnvme_ns_get_requeue_no_usable_path_count |
| 46 | + #define libnvme_ns_fail_no_available_path_count_get libnvme_ns_get_fail_no_available_path_count |
| 47 | +%} |
| 48 | +struct libnvme_ns { |
| 49 | + __u32 nsid; |
| 50 | + %immutable name; |
| 51 | + const char * name; |
| 52 | + %immutable generic_name; |
| 53 | + const char * generic_name; |
| 54 | + const char * sysfs_dir; |
| 55 | + int lba_shift; |
| 56 | + int lba_size; |
| 57 | + int meta_size; |
| 58 | + uint64_t lba_count; |
| 59 | + uint64_t lba_util; |
| 60 | + %immutable eui64; |
| 61 | + uint8_t eui64[8]; |
| 62 | + %immutable nguid; |
| 63 | + uint8_t nguid[16]; |
| 64 | + %immutable csi; |
| 65 | + enum nvme_csi csi; |
| 66 | + %extend { |
| 67 | + %immutable command_retry_count; |
| 68 | + long command_retry_count; |
| 69 | + %immutable command_error_count; |
| 70 | + long command_error_count; |
| 71 | + %immutable requeue_no_usable_path_count; |
| 72 | + long requeue_no_usable_path_count; |
| 73 | + %immutable fail_no_available_path_count; |
| 74 | + long fail_no_available_path_count; |
| 75 | + } |
| 76 | +}; |
| 77 | + |
| 78 | +%pythoncode %{ |
| 79 | +Namespace.__setattr__ = _nvme_guarded_setattr |
| 80 | +%} |
| 81 | + |
| 82 | +/* struct libnvme_ctrl */ |
| 83 | +%rename(Ctrl) libnvme_ctrl; |
| 84 | +%rename(libnvme_ctrl_state_get) libnvme_ctrl_get_state; |
| 85 | +%rename(libnvme_ctrl_command_error_count_get) libnvme_ctrl_get_command_error_count; |
| 86 | +%rename(libnvme_ctrl_reset_count_get) libnvme_ctrl_get_reset_count; |
| 87 | +%rename(libnvme_ctrl_reconnect_count_get) libnvme_ctrl_get_reconnect_count; |
| 88 | +%{ |
| 89 | + #define libnvme_ctrl_state_get libnvme_ctrl_get_state |
| 90 | + #define libnvme_ctrl_command_error_count_get libnvme_ctrl_get_command_error_count |
| 91 | + #define libnvme_ctrl_reset_count_get libnvme_ctrl_get_reset_count |
| 92 | + #define libnvme_ctrl_reconnect_count_get libnvme_ctrl_get_reconnect_count |
| 93 | +%} |
| 94 | +struct libnvme_ctrl { |
| 95 | + %immutable name; |
| 96 | + const char * name; |
| 97 | + %immutable sysfs_dir; |
| 98 | + const char * sysfs_dir; |
| 99 | + %immutable address; |
| 100 | + const char * address; |
| 101 | + %immutable firmware; |
| 102 | + const char * firmware; |
| 103 | + %immutable model; |
| 104 | + const char * model; |
| 105 | + %immutable numa_node; |
| 106 | + const char * numa_node; |
| 107 | + %immutable queue_count; |
| 108 | + const char * queue_count; |
| 109 | + %immutable serial; |
| 110 | + const char * serial; |
| 111 | + %immutable sqsize; |
| 112 | + const char * sqsize; |
| 113 | + %immutable transport; |
| 114 | + const char * transport; |
| 115 | + %immutable subsysnqn; |
| 116 | + const char * subsysnqn; |
| 117 | + %immutable traddr; |
| 118 | + const char * traddr; |
| 119 | + %immutable trsvcid; |
| 120 | + const char * trsvcid; |
| 121 | + const char * dhchap_host_key; |
| 122 | + const char * dhchap_ctrl_key; |
| 123 | + const char * keyring; |
| 124 | + const char * tls_key_identity; |
| 125 | + const char * tls_key; |
| 126 | + %immutable cntrltype; |
| 127 | + const char * cntrltype; |
| 128 | + %immutable cntlid; |
| 129 | + const char * cntlid; |
| 130 | + %immutable dctype; |
| 131 | + const char * dctype; |
| 132 | + %immutable phy_slot; |
| 133 | + const char * phy_slot; |
| 134 | + %immutable host_traddr; |
| 135 | + const char * host_traddr; |
| 136 | + %immutable host_iface; |
| 137 | + const char * host_iface; |
| 138 | + bool discovery_ctrl; |
| 139 | + bool unique_discovery_ctrl; |
| 140 | + bool discovered; |
| 141 | + bool persistent; |
| 142 | + %extend { |
| 143 | + %immutable state; |
| 144 | + const char * state; |
| 145 | + %immutable command_error_count; |
| 146 | + long command_error_count; |
| 147 | + %immutable reset_count; |
| 148 | + long reset_count; |
| 149 | + %immutable reconnect_count; |
| 150 | + long reconnect_count; |
| 151 | + } |
| 152 | +}; |
| 153 | + |
| 154 | +%pythoncode %{ |
| 155 | +Ctrl.__setattr__ = _nvme_guarded_setattr |
| 156 | +%} |
| 157 | + |
| 158 | +/* struct libnvme_subsystem */ |
| 159 | +%rename(Subsystem) libnvme_subsystem; |
| 160 | +%rename(libnvme_subsystem_iopolicy_get) libnvme_subsystem_get_iopolicy; |
| 161 | +%{ |
| 162 | + #define libnvme_subsystem_iopolicy_get libnvme_subsystem_get_iopolicy |
| 163 | +%} |
| 164 | +struct libnvme_subsystem { |
| 165 | + %immutable name; |
| 166 | + const char * name; |
| 167 | + %immutable sysfs_dir; |
| 168 | + const char * sysfs_dir; |
| 169 | + %immutable subsysnqn; |
| 170 | + const char * subsysnqn; |
| 171 | + %immutable model; |
| 172 | + const char * model; |
| 173 | + %immutable serial; |
| 174 | + const char * serial; |
| 175 | + %immutable firmware; |
| 176 | + const char * firmware; |
| 177 | + %immutable subsystype; |
| 178 | + const char * subsystype; |
| 179 | + const char * application; |
| 180 | + %extend { |
| 181 | + %immutable iopolicy; |
| 182 | + const char * iopolicy; |
| 183 | + } |
| 184 | +}; |
| 185 | + |
| 186 | +%pythoncode %{ |
| 187 | +Subsystem.__setattr__ = _nvme_guarded_setattr |
| 188 | +%} |
| 189 | + |
| 190 | +/* struct libnvme_host */ |
| 191 | +%rename(Host) libnvme_host; |
| 192 | +%rename(libnvme_host_pdc_enabled_set) libnvme_host_set_pdc_enabled; |
| 193 | +%{ |
| 194 | + #define libnvme_host_pdc_enabled_set libnvme_host_set_pdc_enabled |
| 195 | +%} |
| 196 | +struct libnvme_host { |
| 197 | + %immutable hostnqn; |
| 198 | + const char * hostnqn; |
| 199 | + %immutable hostid; |
| 200 | + const char * hostid; |
| 201 | + const char * dhchap_host_key; |
| 202 | + const char * hostsymname; |
| 203 | +}; |
| 204 | + |
| 205 | +%pythoncode %{ |
| 206 | +Host.__setattr__ = _nvme_guarded_setattr |
| 207 | +%} |
| 208 | + |
| 209 | +/* struct libnvme_global_ctx */ |
| 210 | +%rename(GlobalCtx) libnvme_global_ctx; |
| 211 | +struct libnvme_global_ctx { |
| 212 | +}; |
| 213 | + |
| 214 | +%pythoncode %{ |
| 215 | +GlobalCtx.__setattr__ = _nvme_guarded_setattr |
| 216 | +%} |
| 217 | + |
0 commit comments