From: Hanna Czenczek Date: Mon, 9 Mar 2026 15:08:46 +0000 (+0100) Subject: block: Move qemu_fcntl_addfl() into osdep.c X-Git-Tag: v11.0.0-rc0~17^2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=247fa896d510d6cc22d697e7c4979d8a3727de52;p=thirdparty%2Fqemu.git block: Move qemu_fcntl_addfl() into osdep.c Move file-posix's helper to add a flag (or a set of flags) to an FD's existing set of flags into osdep.c for other places to use. Suggested-by: Eric Blake Signed-off-by: Hanna Czenczek Message-ID: <20260309150856.26800-16-hreitz@redhat.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- diff --git a/block/file-posix.c b/block/file-posix.c index 6265d2e248b..e49b13d6abb 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1056,21 +1056,6 @@ static int raw_handle_perm_lock(BlockDriverState *bs, return ret; } -/* Sets a specific flag */ -static int fcntl_setfl(int fd, int flag) -{ - int flags; - - flags = fcntl(fd, F_GETFL); - if (flags == -1) { - return -errno; - } - if (fcntl(fd, F_SETFL, flags | flag) == -1) { - return -errno; - } - return 0; -} - static int raw_reconfigure_getfd(BlockDriverState *bs, int flags, int *open_flags, uint64_t perm, Error **errp) { @@ -1109,7 +1094,7 @@ static int raw_reconfigure_getfd(BlockDriverState *bs, int flags, /* dup the original fd */ fd = qemu_dup(s->fd); if (fd >= 0) { - ret = fcntl_setfl(fd, *open_flags); + ret = qemu_fcntl_addfl(fd, *open_flags); if (ret) { qemu_close(fd); fd = -1; diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index b384b5b506b..f151578b5ce 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -633,6 +633,7 @@ int qemu_lock_fd(int fd, int64_t start, int64_t len, bool exclusive); int qemu_unlock_fd(int fd, int64_t start, int64_t len); int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive); bool qemu_has_ofd_lock(void); +int qemu_fcntl_addfl(int fd, int flag); #endif bool qemu_has_direct_io(void); diff --git a/util/osdep.c b/util/osdep.c index 770369831bc..000e7daac8b 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -280,6 +280,24 @@ int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive) return fl.l_type == F_UNLCK ? 0 : -EAGAIN; } } + +/** + * Set the given flag(s) (fcntl GETFL/SETFL) on the given FD, while retaining + * other flags. + */ +int qemu_fcntl_addfl(int fd, int flag) +{ + int flags; + + flags = fcntl(fd, F_GETFL); + if (flags == -1) { + return -errno; + } + if (fcntl(fd, F_SETFL, flags | flag) == -1) { + return -errno; + } + return 0; +} #endif bool qemu_has_direct_io(void)