Commit d5232e6
committed
Lock PCI allocated file
When running on heavy a load, sriov-cni might be invoked multiple times
by the kubelet or the container runtime. In these situations, it might happen
that a `cmdAdd` or a `cmdDel` run on the same device that is still handled by
a `cmdDel` instance (e.g. when the IPAM plugin takes a long time to finish).
This commit adds a Lock mechanism around the `/var/lib/cni/sriov/<PCI>.lock` file,
to avoid two or more instances handling the same the device.
The lock is based on `flock` [1] using the `O_CLOEXEC` flag, which garantees that the lock
is released when the process finishes.
[1] https://linux.die.net/man/2/flock
Signed-off-by: Andrea Panattoni <[email protected]>1 parent b811f7a commit d5232e6
File tree
4 files changed
+67
-2
lines changed- cmd/sriov
- pkg
- config
- utils
4 files changed
+67
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
248 | 259 | | |
249 | 260 | | |
250 | 261 | | |
| |||
317 | 328 | | |
318 | 329 | | |
319 | 330 | | |
320 | | - | |
321 | 331 | | |
322 | 332 | | |
323 | 333 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
51 | 60 | | |
52 | 61 | | |
53 | 62 | | |
| |||
56 | 65 | | |
57 | 66 | | |
58 | 67 | | |
59 | | - | |
60 | 68 | | |
61 | 69 | | |
62 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
16 | 21 | | |
17 | 22 | | |
18 | 23 | | |
| |||
80 | 85 | | |
81 | 86 | | |
82 | 87 | | |
| 88 | + | |
83 | 89 | | |
84 | 90 | | |
85 | 91 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| 12 | + | |
| 13 | + | |
10 | 14 | | |
11 | 15 | | |
| 16 | + | |
| 17 | + | |
12 | 18 | | |
13 | 19 | | |
14 | 20 | | |
| |||
25 | 31 | | |
26 | 32 | | |
27 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
28 | 69 | | |
29 | 70 | | |
30 | 71 | | |
| |||
0 commit comments