Kernel needs some time to delete a device after losetup --detach. If the losetup --find is called just after losetup --delete, it can sometimes attempt to recycle the device that is just being released. To prevent this race, clear the AUTOCLEAR flag of the device. Signed-off-by: Stanislav Brabec <sbrabec@xxxxxxx> --- sys-utils/losetup.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c index 28cde2b..ba096fe 100644 --- a/sys-utils/losetup.c +++ b/sys-utils/losetup.c @@ -720,6 +720,12 @@ int main(int argc, char **argv) /* We found a device to recycle. Do not check * for conflict. If it is conflicting, then * user was already warned in past. */ + lc.info.lo_flags &= !LO_FLAGS_AUTOCLEAR; + if (loopcxt_set_status(&lc)) { + loopcxt_deinit(&lc); + errx(EXIT_FAILURE, _("%s: failed to re-use loop device"), + loopcxt_get_device(&lc)); + } goto got_device; } loopcxt_deinit(&lc); -- 2.9.2 -- Best Regards / S pozdravem, Stanislav Brabec software developer --------------------------------------------------------------------- SUSE LINUX, s. r. o. e-mail: sbrabec@xxxxxxxx Křižíkova 148/34 (Corso IIa) tel: +49 911 7405384547 186 00 Praha 8-Karlín fax: +420 284 084 001 Czech Republic http://www.suse.cz/ PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76 -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html