-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add manual scsi probe of a Lun #84
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,54 @@ | ||
CC=gcc | ||
CFLAGS= -g | ||
#QUIET = &>/dev/null | ||
VALGRIND_FLAGS= --error-exitcode=1 --leak-check=full -s | ||
|
||
tests: tests_res/parse_kernel_cmdline.exec.log tests_res/parse_kernel_cmdline.valgrind.log tests_res/fetch_kernel_cmdline.exec.log tests_res/fetch_kernel_cmdline.valgrind.log tests_res/trigger_scan.valgrind.log tests_res/trigger_scan.exec.log | ||
|
||
################################################################ | ||
tests_res/parse_kernel_cmdline.exec.log: tests/parse_kernel_cmdline | ||
@echo "======================= Testing... " $< " exec" | ||
@$< > $@ | ||
|
||
tests_res/parse_kernel_cmdline.valgrind.log: tests/parse_kernel_cmdline | ||
@echo "======================= Testing... " $< "valgrind" | ||
@valgrind $(VALGRIND_FLAGS) $< >$@ 2>&1 | ||
|
||
tests/parse_kernel_cmdline: tests/parse_kernel_cmdline.c scsi_probe.o | ||
@echo "======================= Build... " $< | ||
@$(CC) $(CFLAGS) $^ -o $@ | ||
|
||
########################################################################### | ||
tests_res/fetch_kernel_cmdline.exec.log: tests/fetch_kernel_cmdline | ||
@echo "======================= Testing... " $< " exec" | ||
@$< > $@ | ||
|
||
tests_res/fetch_kernel_cmdline.valgrind.log: tests/fetch_kernel_cmdline | ||
@echo "======================= Testing... " $< "valgrind" | ||
@valgrind $(VALGRIND_FLAGS) $< >$@ 2>&1 | ||
|
||
tests/fetch_kernel_cmdline: tests/fetch_kernel_cmdline.c scsi_probe.o | ||
@echo "======================= Build... " $< | ||
@$(CC) $(CFLAGS) $^ -o $@ | ||
|
||
########################################################################### | ||
tests_res/trigger_scan.exec.log: tests/trigger_scan | ||
@echo "======================= Testing... " $< " exec" | ||
@$< > $@ | ||
|
||
tests_res/trigger_scan.valgrind.log: tests/trigger_scan | ||
@echo "======================= Testing... " $< "valgrind" | ||
@valgrind $(VALGRIND_FLAGS) $< >$@ 2>&1 | ||
|
||
tests/trigger_scan: tests/trigger_scan.c scsi_probe.o | ||
@echo "======================= Build... " $< | ||
@$(CC) $(CFLAGS) $^ -o $@ | ||
|
||
########################################################################### | ||
scsi_probe.o: scsi_probe.c scsi_probe.h | ||
@echo "======================= Build... " $< | ||
@$(CC) $(CFLAGS) -c $< -o $@ | ||
|
||
clean: | ||
@echo "======================= CLEAN... " | ||
@rm -f scsi_probe.o tests/parse_kernel_cmdline tests_res/*.log |
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,76 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
#include <errno.h> | ||
#include "scsi_probe.h" | ||
|
||
static int c2i(char *str){ | ||
char *endptr; | ||
int num; | ||
|
||
errno = 0; | ||
num = strtol(str, &endptr, 10); | ||
if ((errno != 0 && num == 0) || (num > 99)) return -1; | ||
if (endptr == str) return -1; | ||
return num; | ||
} | ||
|
||
inline int update_scsi_args(const char *ba_str, struct args *ba){ | ||
char *token; | ||
char *ba_str2; | ||
char *tmp1, *tmp2; | ||
|
||
if (!ba_str) return 0; | ||
if ((ba_str2 = strdup(ba_str)) == NULL) return 0; | ||
token = strtok(ba_str2, " "); | ||
while (token != NULL) { | ||
if (strncmp(token, SCSI_ADDR_BOOT_ARG, strlen(SCSI_ADDR_BOOT_ARG)) == 0) { | ||
tmp1 = strchr(token, '='); | ||
if (tmp1 != NULL) { | ||
tmp2 = tmp1 + 1; | ||
sscanf(tmp2, "%d:%d:%d:%d", &ba->scsi_host, &ba->scsi_channel, &ba->scsi_id, &ba->scsi_lun); | ||
} | ||
} | ||
token = strtok(NULL, " "); | ||
} | ||
free(ba_str2); | ||
return 1; | ||
} | ||
|
||
|
||
int parse_kernel_cmdline(const char *ba_str, struct args *ba){ | ||
memset(ba, 0, sizeof(struct args)); | ||
ba->scsi_manual=strstr(ba_str, "scsi_mod.scan=manual")?1:0; | ||
return update_scsi_args(ba_str, ba); | ||
} | ||
|
||
char *fetch_kernel_cmdline(const char *cmdline_fn){ | ||
FILE *file; | ||
char *cmdline; | ||
|
||
file = fopen(cmdline_fn, "r"); | ||
if (file == NULL) return NULL; | ||
cmdline = (char *) malloc(MAX_BUF); | ||
if (! fgets(cmdline, MAX_BUF, file)) { | ||
free(cmdline); | ||
return NULL; | ||
} | ||
fclose(file); | ||
return cmdline; | ||
} | ||
|
||
|
||
int trigger_scan(struct args *ba, const char *scsi_sys_tmpl, const int scsi_sys_tmpl_sz) { | ||
FILE *file; | ||
char buf[128]; | ||
int n; | ||
|
||
if (ba->scsi_manual==0) return 0; | ||
snprintf(buf, scsi_sys_tmpl_sz, scsi_sys_tmpl, ba->scsi_host); | ||
file = fopen(buf, "w"); | ||
if (file == NULL) return 0; | ||
n = snprintf(buf, MAX_BUF, SCSI_SYS_SCAN_STR, ba->scsi_channel, ba->scsi_id, ba->scsi_lun); | ||
fwrite(buf, n, 1, file); | ||
fclose(file); | ||
return 1; | ||
} |
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,19 @@ | ||
#define MAX_ARGS 100 | ||
#define MAX_BUF 128 | ||
|
||
#define SCSI_SYS_SCAN_STR "%d %d %d\n" | ||
|
||
#define SCSI_ADDR_BOOT_ARG "scsi.addr" | ||
|
||
struct args { | ||
int scsi_manual; | ||
int scsi_host; | ||
int scsi_channel; | ||
int scsi_id; | ||
int scsi_lun; | ||
}; | ||
|
||
int update_scsi_args(const char *, struct args *); | ||
int parse_kernel_cmdline(const char *, struct args *); | ||
char *fetch_kernel_cmdline(const char *); | ||
int trigger_scan(struct args *, const char *, const int); |
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 @@ | ||
pippo=1 pluto=2 paperino=3 |
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,2 @@ | ||
pippo=1 pluto=2 paperino=3 | ||
pippo=z pluto=x paperino=c |
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 @@ | ||
1 2 3 |
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 @@ | ||
3 4 5 |
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,39 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
#include "../scsi_probe.h" | ||
|
||
#define TEST_BUFF_SIZE 200 | ||
|
||
char *results[] = { | ||
"pippo=1 pluto=2 paperino=3\n", | ||
"pippo=1 pluto=2 paperino=3\n", | ||
NULL | ||
}; | ||
|
||
char *test_patterns[] = { | ||
"testfiles/cmd1", | ||
"testfiles/cmd2", | ||
"testfiles/cmd3", | ||
}; | ||
|
||
int main(){ | ||
int i; | ||
char *res; | ||
|
||
for (i=0; i< sizeof(test_patterns)/sizeof(char *); i++) { | ||
res = fetch_kernel_cmdline(test_patterns[i]); | ||
printf( "Test pattern='%s', expected result='%s' Actual result ='%s' -> ", | ||
test_patterns[i], results[i], res); | ||
if (res && results[i]) { | ||
if (strcmp(res, results[i])!=0) { | ||
printf("Failed\n"); | ||
free(res); | ||
return -1; | ||
} | ||
} | ||
printf("Success\n"); | ||
free(res); | ||
} | ||
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,40 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include "../scsi_probe.h" | ||
|
||
#define TEST_BUFF_SIZE 200 | ||
|
||
char *results[] = { | ||
"has manual=1 host=1 addr=2:3:45", | ||
"has manual=1 host=1 addr=2:3:45", | ||
"has manual=1 host=0 addr=0:0:0", | ||
"has manual=0 host=0 addr=0:0:0" | ||
}; | ||
|
||
char *test_patterns[] = { | ||
"pippo=1 pluto=2 scsi_mod.scan=manual scsi.addr=1:2:3:45 paperino=peppe", | ||
"pippo=1 pluto=2 scsi_mod.scan=manual posw scsi.addr=1:2:3:45 paperino=peppe", | ||
"pippo=1 pluto=2 scsi_mod.scan=manual paperino=peppe", | ||
"pippo=1 pluto=2 paperino=peppe", | ||
|
||
}; | ||
|
||
int main(){ | ||
struct args ba; | ||
int i; | ||
char res[TEST_BUFF_SIZE]; | ||
|
||
for (i=0; i< sizeof(test_patterns)/sizeof(char *); i++) { | ||
if (!parse_kernel_cmdline(test_patterns[i], &ba)) return -1; | ||
sprintf(res, "has manual=%d host=%d addr=%d:%d:%d", ba.scsi_manual, ba.scsi_host, ba.scsi_channel, ba.scsi_id, ba.scsi_lun); | ||
|
||
printf( "Test pattern='%s', expected result='%s' Actual result ='%s' -> ", | ||
test_patterns[i], results[i], res); | ||
if (strcmp(res, results[i])) { | ||
printf("Failed\n"); | ||
return -1; | ||
} | ||
printf("Success\n"); | ||
} | ||
return 0; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This statement here is not ifdef'd.
For some reason, I thought it should be enabled, no matter what.
On a second thought, I wonder if you prefer this to be ifdef dependent.
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.
It was false deliberately because in the use case this code was intended for initoverlayfs is the init system, but exec's itself as a systemd process really quickly (and then systemd mounts /proc).
But tbh, it was a micro-optimization, so I don't mind it being true, it was just one less mount call.
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.
Actually, some things are broken here in general (not in this PR, in initoverlayfs main branch) that I have to fix when I come back.
I think if you run the upstream version of this now on a Fedora Workstation machine, it doesn't boot anymore and they are really trivial silly bugs.
I just got distracted by other things the last week or two.