Skip to content

Commit

Permalink
driver/*.c: report reconnection attempts as a "driver.state" [network…
Browse files Browse the repository at this point in the history
  • Loading branch information
jimklimov committed Jan 5, 2023
1 parent ef65497 commit a250ccd
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/nut-names.txt
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,8 @@ driver: Internal driver information
the stable working loop | init.starting, init.quiet,
init.device, init.info,
init.updateinfo (first walk),
reconnect.trying,
reconnect.updateinfo,
updateinfo, quiet, dumping,
cleanup.upsdrv, cleanup.exit
|===============================================================================
Expand Down
3 changes: 3 additions & 0 deletions drivers/adelsystem_cbi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,7 @@ void modbus_reconnect(void)
int rval;

upsdebugx(1, "modbus_reconnect, trying to reconnect to modbus server");
dstate_setinfo("driver.state", "reconnect.trying");

/* clear current modbus context */
modbus_close(mbctx);
Expand Down Expand Up @@ -1340,5 +1341,7 @@ void modbus_reconnect(void)
}
/* #elif (defined NUT_MODBUS_TIMEOUT_ARG_timeval) // some un-castable type in fields */
#endif /* NUT_MODBUS_TIMEOUT_ARG_* */

dstate_setinfo("driver.state", "quiet");
}

5 changes: 5 additions & 0 deletions drivers/bcmxcp_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,13 +385,18 @@ void upsdrv_cleanup(void)

void upsdrv_reconnect(void)
{
dstate_setinfo("driver.state", "reconnect.trying");

upsdebugx(4, "==================================================");
upsdebugx(4, "= device has been disconnected, try to reconnect =");
upsdebugx(4, "==================================================");

nutusb_close(upsdev, "USB");
upsdev = NULL;

upsdrv_initups();

dstate_setinfo("driver.state", "quiet");
}

/* USB functions */
Expand Down
5 changes: 5 additions & 0 deletions drivers/blazer_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,15 @@ ssize_t blazer_command(const char *cmd, char *buf, size_t buflen)
ssize_t ret;

if (udev == NULL) {
dstate_setinfo("driver.state", "reconnect.trying");

ret = usb->open_dev(&udev, &usbdevice, reopen_matcher, NULL);

if (ret < 1) {
return ret;
}

dstate_setinfo("driver.state", "reconnect.updateinfo");
}

ret = (*subdriver_command)(cmd, buf, buflen);
Expand Down Expand Up @@ -496,6 +500,7 @@ ssize_t blazer_command(const char *cmd, char *buf, size_t buflen)
case LIBUSB_ERROR_NOT_FOUND: /* No such file or directory */
fallthrough_case_reconnect:
/* Uh oh, got to reconnect! */
dstate_setinfo("driver.state", "reconnect.trying");
usb->close_dev(udev);
udev = NULL;
break;
Expand Down
3 changes: 3 additions & 0 deletions drivers/generic_modbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,7 @@ void modbus_reconnect(void)
int rval;

upsdebugx(2, "modbus_reconnect, trying to reconnect to modbus server");
dstate_setinfo("driver.state", "reconnect.trying");

/* clear current modbus context */
modbus_close(mbctx);
Expand Down Expand Up @@ -1097,4 +1098,6 @@ void modbus_reconnect(void)
}
/* #elif (defined NUT_MODBUS_TIMEOUT_ARG_timeval) // some un-castable type in fields */
#endif /* NUT_MODBUS_TIMEOUT_ARG_* */

dstate_setinfo("driver.state", "quiet");
}
2 changes: 2 additions & 0 deletions drivers/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,8 @@ int main(int argc, char **argv)
/* get the base data established before allowing connections */
dstate_setinfo("driver.state", "init.info");
upsdrv_initinfo();
/* Note: a few drivers also call their upsdrv_updateinfo() during
* their upsdrv_initinfo(), possibly to impact the initialization */
dstate_setinfo("driver.state", "init.updateinfo");
upsdrv_updateinfo();
dstate_setinfo("driver.state", "init.quiet");
Expand Down
5 changes: 5 additions & 0 deletions drivers/nutdrv_qx.c
Original file line number Diff line number Diff line change
Expand Up @@ -3163,11 +3163,15 @@ static ssize_t qx_command(const char *cmd, char *buf, size_t buflen)
# endif /* QX_SERIAL (&& QX_USB)*/

if (udev == NULL) {
dstate_setinfo("driver.state", "reconnect.trying");

ret = usb->open_dev(&udev, &usbdevice, reopen_matcher, NULL);

if (ret < 1) {
return ret;
}

dstate_setinfo("driver.state", "reconnect.updateinfo");
}

ret = (*subdriver_command)(cmd, buf, buflen);
Expand Down Expand Up @@ -3229,6 +3233,7 @@ static ssize_t qx_command(const char *cmd, char *buf, size_t buflen)
case LIBUSB_ERROR_NOT_FOUND: /* No such file or directory */
fallthrough_case_reconnect:
/* Uh oh, got to reconnect! */
dstate_setinfo("driver.state", "reconnect.trying");
usb->close_dev(udev);
udev = NULL;
break;
Expand Down
3 changes: 3 additions & 0 deletions drivers/powerman-pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ static int reconnect_ups(void)
{
pm_err_t rv;

dstate_setinfo("driver.state", "reconnect.trying");

upsdebugx(4, "===================================================");
upsdebugx(4, "= connection lost with Powerman, try to reconnect =");
upsdebugx(4, "===================================================");
Expand All @@ -202,6 +204,7 @@ static int reconnect_ups(void)
if ((rv = pm_connect(device_path, NULL, &pm, 0)) != PM_ESUCCESS)
return 0;
else {
dstate_setinfo("driver.state", "quiet");
upsdebugx(4, "connection restored with Powerman");
return 1;
}
Expand Down
5 changes: 5 additions & 0 deletions drivers/riello_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,17 @@ static int riello_command(uint8_t *cmd, uint8_t *buf, uint16_t length, uint16_t
int ret;

if (udev == NULL) {
dstate_setinfo("driver.state", "reconnect.trying");

ret = usb->open_dev(&udev, &usbdevice, reopen_matcher, &driver_callback);

upsdebugx (3, "riello_command err udev NULL : %d ", ret);
if (ret < 0)
return ret;

dstate_setinfo("driver.state", "reconnect.updateinfo");
upsdrv_initinfo(); /* reconnect usb cable */
dstate_setinfo("driver.state", "quiet");
}

ret = (*subdriver_command)(cmd, buf, length, buflen);
Expand Down Expand Up @@ -404,6 +408,7 @@ static int riello_command(uint8_t *cmd, uint8_t *buf, uint16_t length, uint16_t
case LIBUSB_ERROR_NOT_FOUND: /* No such file or directory */
fallthrough_case_reconnect:
/* Uh oh, got to reconnect! */
dstate_setinfo("driver.state", "reconnect.trying");
usb->close_dev(udev);
udev = NULL;
break;
Expand Down
5 changes: 5 additions & 0 deletions drivers/tripplite_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ static int reconnect_ups(void)
return 1;
}

dstate_setinfo("driver.state", "reconnect.trying");

upsdebugx(2, "==================================================");
upsdebugx(2, "= device has been disconnected, try to reconnect =");
upsdebugx(2, "==================================================");
Expand All @@ -337,6 +339,7 @@ static int reconnect_ups(void)
}

hd = &curDevice;
dstate_setinfo("driver.state", "quiet");

return ret;
}
Expand Down Expand Up @@ -563,7 +566,9 @@ static void usb_comm_fail(int res, const char *msg)
if(hd) {
upslogx(LOG_NOTICE, "Successfully reconnected");
try = 0;
dstate_setinfo("driver.state", "reconnect.updateinfo");
upsdrv_initinfo();
dstate_setinfo("driver.state", "quiet");
} else {
if(try > MAX_RECONNECT_TRIES) {
fatalx(EXIT_FAILURE, "Too many unsuccessful reconnection attempts");
Expand Down
4 changes: 4 additions & 0 deletions drivers/usbhid-ups.c
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,7 @@ void upsdrv_updateinfo(void)
case LIBUSB_ERROR_NO_MEM: /* Insufficient memory */
fallthrough_reconnect:
/* Uh oh, got to reconnect! */
dstate_setinfo("driver.state", "reconnect.trying");
hd = NULL;
return;
case LIBUSB_ERROR_IO: /* I/O error */
Expand Down Expand Up @@ -1595,6 +1596,8 @@ static int reconnect_ups(void)
char *val;
int wait_before_reconnect = 0;

dstate_setinfo("driver.state", "reconnect.trying");

/* Init time to wait before trying to reconnect (seconds) */
val = getval(HU_VAR_WAITBEFORERECONNECT);
if (val) {
Expand Down Expand Up @@ -1627,6 +1630,7 @@ static int reconnect_ups(void)
return 1;
}

dstate_setinfo("driver.state", "quiet");
return 0;
}

Expand Down

0 comments on commit a250ccd

Please sign in to comment.