-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/msn4800_lc_bu'
- Loading branch information
Showing
11 changed files
with
1,519 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.