Skip to content

Commit

Permalink
Merge pull request #1154 from SergeyGorenko/srp_daemon_prevent_starti…
Browse files Browse the repository at this point in the history
…ng_on_roce

srp_daemon: Prevent starting when the link layer is not InfiniBand
  • Loading branch information
rleon committed Mar 24, 2022
2 parents 3991231 + 9943468 commit 3b28e0e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions srp_daemon/srp_daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -1902,6 +1902,27 @@ static void umad_resources_destroy(struct umad_resources *umad_res)
umad_done();
}

static int check_link_layer(const char *port_sysfs_path)
{
const char expected_link_layer[] = "InfiniBand";
char link_layer[sizeof(expected_link_layer)];
int ret;

ret = srpd_sys_read_string(port_sysfs_path, "link_layer", link_layer,
sizeof(link_layer));
if (ret < 0) {
pr_err("Couldn't read link layer\n");
return ret;
}

if (strcmp(link_layer, expected_link_layer)) {
pr_err("Unsupported link layer %s\n", link_layer);
return -EINVAL;
}

return 0;
}

static int umad_resources_create(struct umad_resources *umad_res)
{

Expand All @@ -1915,6 +1936,10 @@ static int umad_resources_create(struct umad_resources *umad_res)
return -ENOMEM;
}

ret = check_link_layer(umad_res->port_sysfs_path);
if (ret)
return ret;

umad_res->portid = umad_open_port(config->dev_name, config->port_num);
if (umad_res->portid < 0) {
pr_err("umad_open_port failed for device %s port %d\n",
Expand Down
1 change: 1 addition & 0 deletions srp_daemon/start_on_all_ports.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

for p in /sys/class/infiniband/*/ports/*; do
[ -e "$p" ] || continue
[ "$(cat ${p}/link_layer)" == "InfiniBand" ] || continue
p=${p#/sys/class/infiniband/}
nohup @SYSTEMCTL_BIN@ start "srp_daemon_port@${p/\/ports\//:}" </dev/null >&/dev/null &
done

0 comments on commit 3b28e0e

Please sign in to comment.