Skip to content

Commit e08f9e9

Browse files
hreineckeigaw
authored andcommitted
libnvme/nvme.i: raise exception when disconnect fails
nvme_disconnect_ctrl() can fail, and will return an error if so. So update the python binding to properly raise an exception when disconnect fails. Signed-off-by: Hannes Reinecke <[email protected]>
1 parent 75d1e37 commit e08f9e9

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

libnvme/nvme.i

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,22 @@ PyObject *hostid_from_file();
132132
}
133133
}
134134

135+
%exception nvme_ctrl::disconnect {
136+
connect_err = 0;
137+
errno = 0;
138+
$action /* $action sets connect_err to non-zero value on failure */
139+
if (connect_err == 1) {
140+
SWIG_exception(SWIG_AttributeError, "No controller connection");
141+
} else if (connect_err) {
142+
const char *errstr = nvme_errno_to_string(errno);
143+
if (errstr) {
144+
SWIG_exception(SWIG_RuntimeError, errstr);
145+
} else {
146+
SWIG_exception(SWIG_RuntimeError, "Disconnect failed");
147+
}
148+
}
149+
}
150+
135151
%exception nvme_ctrl::discover {
136152
discover_err = 0;
137153
$action /* $action sets discover_err to non-zero value on failure */
@@ -807,9 +823,19 @@ struct nvme_ns {
807823
nvme_rescan_ctrl($self);
808824
}
809825
void disconnect() {
826+
int ret;
827+
const char *dev;
828+
829+
dev = nvme_ctrl_get_name($self);
830+
if (!dev) {
831+
connect_err = 1;
832+
return;
833+
}
810834
Py_BEGIN_ALLOW_THREADS /* Release Python GIL */
811-
nvme_disconnect_ctrl($self);
835+
ret = nvme_disconnect_ctrl($self);
812836
Py_END_ALLOW_THREADS /* Reacquire Python GIL */
837+
if (ret < 0)
838+
connect_err = 2;
813839
}
814840

815841
%feature("autodoc", "@return: True if controller supports explicit registration. False otherwise.") is_registration_supported;

0 commit comments

Comments
 (0)