-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[systemd-generator]: Fix dependency update for multi-asic platform #4820
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,12 +147,16 @@ static void replace_multi_inst_dep(char *src) { | |
char *line_copy; | ||
char *service_name; | ||
char *type; | ||
char *save_ptr1 = NULL; | ||
char *save_ptr2 = NULL; | ||
ssize_t nread; | ||
bool section_done = false; | ||
char tmp_file_path[PATH_MAX]; | ||
|
||
/* assumes that the service files has 3 sections, | ||
/* Assumes that the service files has 3 sections, | ||
* in the order: Unit, Service and Install. | ||
* Assumes that the timer file has 3 sectiosn, | ||
* in the order: Unit, Timer and Install. | ||
* Read service dependency from Unit and Install | ||
* sections, replace if dependent on multi instance | ||
* service. | ||
|
@@ -162,30 +166,31 @@ static void replace_multi_inst_dep(char *src) { | |
fp_tmp = fopen(tmp_file_path, "w"); | ||
|
||
while ((nread = getline(&line, &len, fp_src)) != -1 ) { | ||
if (strstr(line, "[Service]") != NULL) { | ||
if ((strstr(line, "[Service]") != NULL) || | ||
(strstr(line, "[Timer]") != NULL)) { | ||
section_done = true; | ||
fputs(line,fp_tmp); | ||
} else if (strstr(line, "[Install]") != NULL) { | ||
} else if (strstr(line, "[Install]") != NULL) { | ||
section_done = false; | ||
fputs(line,fp_tmp); | ||
} else if ((strstr(line, "[Unit]") != NULL) || | ||
(strstr(line, "Description") != NULL) || | ||
(section_done == true)){ | ||
(section_done == true)) { | ||
fputs(line,fp_tmp); | ||
} else { | ||
line_copy = strdup(line); | ||
token = strtok(line_copy, "="); | ||
while ((word = strtok(NULL, " "))){ | ||
token = strtok_r(line_copy, "=", &save_ptr1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Rewrite everything by python? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The initial change to add systemd-generator had a discussion on this after which it was decided that C will be used. Guohan had pointed to a reference: "If you are careful, you can implement generators in shell scripts. We do recommend C code however, since generators are executed synchronously and hence delay the entire boot if they are slow." https://www.freedesktop.org/software/systemd/man/systemd.generator.html. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for sharing the history discussion.
In reply to: 443869780 [](ancestors = 443869780) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did a comparison on runtime between c and c++. On a mulit-asic platform, C program takes 2643 micro seconds and c++ take 2651 micro seconds. As there is not much difference, we can move to c++. Will raise another PR to move to code c++ with stream functions for string operations to make it less error prone. |
||
while ((word = strtok_r(NULL, " ", &save_ptr1))) { | ||
if((strchr(word, '.') == NULL) || | ||
(strchr(word, '@') != NULL)) { | ||
snprintf(buf, MAX_BUF_SIZE,"%s=%s\n",token, word); | ||
fputs(buf,fp_tmp); | ||
} else { | ||
service_name = strdup(word); | ||
service_name = strtok(service_name, "."); | ||
type = strtok(NULL, " "); | ||
service_name = strtok_r(service_name, ".", &save_ptr2); | ||
type = strtok_r(NULL, " ", &save_ptr2); | ||
if (is_multi_instance_service(word)) { | ||
for(i = 0; i < num_asics; i++){ | ||
for(i = 0; i < num_asics; i++) { | ||
snprintf(buf, MAX_BUF_SIZE, "%s=%s@%d.%s\n", | ||
token, service_name, i, type); | ||
fputs(buf,fp_tmp); | ||
|
@@ -513,7 +518,7 @@ static int get_num_of_asic() { | |
|
||
while ((nread = getline(&line, &len, fp)) != -1) { | ||
if ((strstr(line, "onie_platform") != NULL) || | ||
(strstr(line, "aboot_platform") != NULL)) { | ||
(strstr(line, "aboot_platform") != NULL)) { | ||
token = strtok(line, "="); | ||
platform = strtok(NULL, "="); | ||
strip_trailing_newline(platform); | ||
|
@@ -580,7 +585,7 @@ int main(int argc, char **argv) { | |
|
||
// For each unit file, get the installation targets and install the unit | ||
for (int i = 0; i < num_unit_files; i++) { | ||
unit_instance = strdup(unit_files[i]); | ||
unit_instance = strdup(unit_files[i]); | ||
if ((num_asics == 1) && strstr(unit_instance, "@") != NULL) { | ||
prefix = strtok(unit_instance, "@"); | ||
suffix = strtok(NULL, "@"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why no longer calling
systemctl enable
on the timers?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
systemctl enable will create a mapping of the service in /etc/systemd/system/.wants directory. This can cause issue in multi-asic platform. The dependencies that are created in systemd generator are present in /var/run/systemd/generator/.wants directory.
To explain better, I have directory structure from VS platform, with systemctl enable and without it.
Without enable: single asic VS platform
Though timers.target.wants directory is present in /etc/systemd/system and /var/run/systemd/generator, systemctl -r shows all under timers.target:
If we keep sysctl enable, then in mutli-asic platform, /etc/systemd/system/swss.service.wants directory is created with snmp.timer in it. /var/run/systemd/generator/[email protected] also has snmp.timer. So, this is not inline with the required dependency.