Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/msn4800_lc_bu'
Browse files Browse the repository at this point in the history
  • Loading branch information
vadimp-nvidia committed Feb 7, 2021
2 parents 3ad9788 + 955632a commit ea3eb93
Show file tree
Hide file tree
Showing 11 changed files with 1,519 additions and 237 deletions.
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Homepage: http://www.mellanox.com

Package:hw-management
Architecture: any
Depends: ${misc:Depends}, ${shlibs:Depends}, lsb-base (>= 3.0-6)
Depends: ${misc:Depends}, ${shlibs:Depends}, lsb-base (>= 3.0-6), python
Description: Thermal control and chassis management for Mellanox systems
This package supports Mellanox switches family for chassis
management and thermal control.
73 changes: 73 additions & 0 deletions examples/src/ev_hndl/lc_event_handler.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (C) Mellanox Technologies, Ltd. 2001-2020 ALL RIGHTS RESERVED.
*
* This software product is a proprietary product of Mellanox Technologies, Ltd.
* (the "Company") and all right, title, and interest in and to the software product,
* including all associated intellectual property rights, are and shall
* remain exclusively with the Company.
*
* This software product is governed by the End User License Agreement
* provided with the software product.
*
* Sysfs event handle example.
*/
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <sys/inotify.h>
#include <sys/poll.h>
#include <sys/stat.h>
#include <unistd.h>


#define EVENT_SIZE (sizeof(struct inotify_event))
#define EVENT_NUM 128
#define BUF_LEN (EVENT_SIZE*EVENT_NUM)
#define POWER_ON 1
//#define LC1_VERIFIED_PATH "/var/run/hw-management/events/lc1_verified"

int main(int argc, char *argv[]) {
char events_buffer[BUF_LEN];
char * event_filepath;
int wd, ifd, len, i=0;
char event_val;
FILE* fd;
if(argc != 2) {
printf("Invalid argument number %d. Pass event filepath as argument.\n", argc);
}
event_filepath=argv[1];
ifd = inotify_init();
wd = inotify_add_watch(ifd, event_filepath, IN_CLOSE_WRITE);
if (wd < 0) {
printf("Failed to add file %s to watch, %s \n",
event_filepath, strerror(errno));
return -1;
} else {
while(1) {
len = read(ifd, &events_buffer, BUF_LEN);
i=0;
while (i < len) {
struct inotify_event *event = (struct inotify_event *) &events_buffer[i];
if (wd == event->wd) {
if (event->mask & IN_CLOSE_WRITE) {
fd = fopen(event_filepath, "r");
event_val=(char)fgetc(fd);
printf("event: %s %c.\n", event_filepath, event_val);
// Do some event based action. For lc{n}_verifiled:
// Validation line card type, max power consumption, CPLD version, VPD, INI blob.
// Validate VPD /var/run/hw-management/lc1/eeprom/vpd.
// Validate INI /var/run/hw-management/lc1/eeprom/ini.
// Check /var/run/hw-management/lc1/system/max_power is enough power.
// Continue init flow - power on line card.
}
}
i += EVENT_SIZE + event->len;
}
}
}
return(0);
}
57 changes: 57 additions & 0 deletions examples/src/ev_hndl/lc_event_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/python
"""
@copyright:
Copyright (C) Mellanox Technologies Ltd. 2001-2020. ALL RIGHTS RESERVED.
This software product is a proprietary product of Mellanox Technologies
Ltd. (the "Company") and all right, title, and interest in and to the
software product, including all associated intellectual property rights,
are and shall remain exclusively with the Company.
This software product is governed by the End User License Agreement
provided with the software product.
@date:
07 Oct 2020
@author:
Mykola Kostenok
"""
#############################
# Global imports
#############################
import sys
import os
import inotify.adapters

if __name__ == '__main__':
if len(sys.argv) != 2:
print "Invalid argument nums. Pass event filepath as argument."
sys.exit(0)
FILEPATH = sys.argv[1]
INOTIFY = inotify.adapters.Inotify()
if not INOTIFY:
print "inotify_adapter error"
sys.exit(0)
if not os.path.exists(FILEPATH):
print "no file {}".format(FILEPATH)
sys.exit(0)
INOTIFY.add_watch(FILEPATH, mask=inotify.constants.IN_CLOSE_WRITE)
for event in INOTIFY.event_gen(yield_nones=False):
(_, type_names, path, filename) = event
handler_file = open(FILEPATH)
if not handler_file:
print "no file {}".format(FILEPATH)
sys.exit(0)
val = handler_file.read(1)
handler_file.close()
print "{} {}".format(os.path.basename(FILEPATH), val)
# Do some event based action. For lc{n}_verifiled:
# Validation line card type, max power consumption, CPLD version, VPD, INI blob.
# Validate VPD /var/run/hw-management/lc1/eeprom/vpd.
# Validate INI /var/run/hw-management/lc1/eeprom/ini.
# Check /var/run/hw-management/lc1/system/max_power is enough power.
# Continue init flow - power on line card.

sys.exit(0)
Loading

0 comments on commit ea3eb93

Please sign in to comment.