diff options
author | Matthias Koenig | 2007-06-20 15:17:47 +0200 |
---|---|---|
committer | Karel Zak | 2007-06-27 16:15:50 +0200 |
commit | 6ffa7c9383a3fca31b5f70eb8d3528d0b09980aa (patch) | |
tree | 4f2c09d22b1a790d8b7cfa8722b75e0ace042f84 /mount/lomount.c | |
parent | mount: loop device race condition (diff) | |
download | kernel-qcow2-util-linux-6ffa7c9383a3fca31b5f70eb8d3528d0b09980aa.tar.gz kernel-qcow2-util-linux-6ffa7c9383a3fca31b5f70eb8d3528d0b09980aa.tar.xz kernel-qcow2-util-linux-6ffa7c9383a3fca31b5f70eb8d3528d0b09980aa.zip |
mount: loop device race condition
Fix race in losetup
Retry acquiring a loop device if set_loop failed with EBUSY
Signed-Off-By: Matthias Koenig <mkoenig@suse.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'mount/lomount.c')
-rw-r--r-- | mount/lomount.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/mount/lomount.c b/mount/lomount.c index a5def9804..2989717e4 100644 --- a/mount/lomount.c +++ b/mount/lomount.c @@ -563,9 +563,9 @@ main(int argc, char **argv) { device = find_unused_loop_device(); if (device == NULL) return -1; - if (verbose) - printf("Loop device is %s\n", device); if (argc == optind) { + if (verbose) + printf("Loop device is %s\n", device); printf("%s\n", device); return 0; } @@ -587,10 +587,23 @@ main(int argc, char **argv) { usage(); if (passfd && sscanf(passfd, "%d", &pfd) != 1) usage(); - res = set_loop(device, file, off, encryption, pfd, &ro); - if (res == 0 && showdev && find) { + do { + res = set_loop(device, file, off, encryption, pfd, &ro); + if (res == 2 && find) { + if (verbose) + printf("stolen loop=%s...trying again\n", + device); + free(device); + if (!(device = find_unused_loop_device())) + return -1; + } + } while (find && res == 2); + + if (verbose && res == 0) + printf("Loop device is %s\n", device); + + if (res == 0 && showdev && find) printf("%s\n", device); - } } return res; } |