From: Daan De Meyer Date: Fri, 11 Aug 2023 08:41:04 +0000 (+0200) Subject: repart: Allow acquire shared lock on --copy-from files/devices X-Git-Tag: v255-rc1~749^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3cdcf4e204f34244d4b686f6d433e49e88f59496;p=thirdparty%2Fsystemd.git repart: Allow acquire shared lock on --copy-from files/devices We're not going to modify these, so no need for an exclusive lock. --- diff --git a/src/partition/repart.c b/src/partition/repart.c index 033f441af3c..d5a64bfa12b 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -1814,7 +1814,7 @@ static int find_verity_sibling(Context *context, Partition *p, VerityMode mode, return 0; } -static int context_open_and_lock_backing_fd(const char *node, int *backing_fd) { +static int context_open_and_lock_backing_fd(const char *node, int operation, int *backing_fd) { _cleanup_close_ int fd = -EBADF; assert(node); @@ -1828,7 +1828,7 @@ static int context_open_and_lock_backing_fd(const char *node, int *backing_fd) { return log_error_errno(errno, "Failed to open device '%s': %m", node); /* Tell udev not to interfere while we are processing the device */ - if (flock(fd, arg_dry_run ? LOCK_SH : LOCK_EX) < 0) + if (flock(fd, operation) < 0) return log_error_errno(errno, "Failed to lock device '%s': %m", node); log_debug("Device %s opened and locked.", node); @@ -1917,7 +1917,7 @@ static int context_copy_from(Context *context) { if (!arg_copy_from) return 0; - r = context_open_and_lock_backing_fd(arg_copy_from, &fd); + r = context_open_and_lock_backing_fd(arg_copy_from, LOCK_SH, &fd); if (r < 0) return r; @@ -2223,7 +2223,8 @@ static int context_load_partition_table(Context *context) { else { uint32_t ssz; - r = context_open_and_lock_backing_fd(context->node, &context->backing_fd); + r = context_open_and_lock_backing_fd(context->node, arg_dry_run ? LOCK_SH : LOCK_EX, + &context->backing_fd); if (r < 0) return r; @@ -2270,7 +2271,9 @@ static int context_load_partition_table(Context *context) { if (context->backing_fd < 0) { /* If we have no fd referencing the device yet, make a copy of the fd now, so that we have one */ - r = context_open_and_lock_backing_fd(FORMAT_PROC_FD_PATH(fdisk_get_devfd(c)), &context->backing_fd); + r = context_open_and_lock_backing_fd(FORMAT_PROC_FD_PATH(fdisk_get_devfd(c)), + arg_dry_run ? LOCK_SH : LOCK_EX, + &context->backing_fd); if (r < 0) return r; }