Commit c7e4e85
src/nbd: avoid race with udev during setup
With the NBD_CFLAG_DISCONNECT_ON_CLOSE flag set, the nbd device will be
automatically removed when there are no more users after it was was
opened the first time.
The idea here is, that the nbd device is created, and then immediately
mounted (possibly with dm-verity or dm-crypt in between). Wenn the
bundle ist later unmounted then the nbd device is automatically removed.
Unfortunately this is racy: udev will see the new device and open it
immediately. If it closes the device before it is mounted (or dm-verity
or dm-crypt is configured) then the nbd device is removed immediately
and mounting will fail.
So instead create the nbd device without NBD_CFLAG_DISCONNECT_ON_CLOSE,
open it to keep it busy and then reconfigure the device to set
NBD_CFLAG_DISCONNECT_ON_CLOSE. The file descriptor is kept open until
the bundle is mounted.
Note that with this change, the nbd device will not be fully removed if
rauc dies between creating the nbd device and reconfiguring it, or if
reconfiguring fails.
Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
Signed-off-by: Jan Luebbe <jlu@pengutronix.de>1 parent 5ec5cd9 commit c7e4e85
3 files changed
+35
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3094 | 3094 | | |
3095 | 3095 | | |
3096 | 3096 | | |
3097 | | - | |
| 3097 | + | |
3098 | 3098 | | |
3099 | 3099 | | |
3100 | 3100 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
145 | | - | |
| 145 | + | |
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
| 154 | + | |
| 155 | + | |
154 | 156 | | |
155 | 157 | | |
| 158 | + | |
156 | 159 | | |
157 | 160 | | |
158 | 161 | | |
| |||
177 | 180 | | |
178 | 181 | | |
179 | 182 | | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
204 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
205 | 230 | | |
206 | 231 | | |
207 | 232 | | |
208 | 233 | | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
209 | 237 | | |
210 | 238 | | |
211 | 239 | | |
| |||
0 commit comments