mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-03-12 08:58:20 +03:00
makefs: lock device while we operate
Let's implement our own specs, i.e. https://systemd.io/BLOCK_DEVICE_LOCKING/ This should address issues like this: #13162
This commit is contained in:
parent
ac83e5aeca
commit
0181ad85b3
@ -7,7 +7,9 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "blockdev-util.h"
|
||||
#include "dissect-image.h"
|
||||
#include "fd-util.h"
|
||||
#include "main-func.h"
|
||||
#include "process-util.h"
|
||||
#include "signal-util.h"
|
||||
@ -42,6 +44,7 @@ static int makefs(const char *type, const char *device) {
|
||||
|
||||
static int run(int argc, char *argv[]) {
|
||||
_cleanup_free_ char *device = NULL, *type = NULL, *detected = NULL;
|
||||
_cleanup_close_ int lock_fd = -1;
|
||||
struct stat st;
|
||||
int r;
|
||||
|
||||
@ -63,7 +66,13 @@ static int run(int argc, char *argv[]) {
|
||||
if (stat(device, &st) < 0)
|
||||
return log_error_errno(errno, "Failed to stat \"%s\": %m", device);
|
||||
|
||||
if (!S_ISBLK(st.st_mode))
|
||||
if (S_ISBLK(st.st_mode)) {
|
||||
/* Lock the device so that udev doesn't interfere with our work */
|
||||
|
||||
lock_fd = lock_whole_block_device(st.st_rdev, LOCK_EX);
|
||||
if (lock_fd < 0)
|
||||
return log_error_errno(lock_fd, "Failed to lock whole block device of \"%s\": %m", device);
|
||||
} else
|
||||
log_info("%s is not a block device.", device);
|
||||
|
||||
r = probe_filesystem(device, &detected);
|
||||
|
Loading…
x
Reference in New Issue
Block a user