mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-13 17:18:01 +03:00
util: Get rid of virFileFlock()
It was created to get rid of conditional compilation in the resctrl code and make it usable anywhere else. However this is not something that is going to be used in other places because it is not portable and resctrl is just very specific in this regard. And there is no reason why there could not be a preprocessor conditional in the resctrl code. Also the interface of virFileFlock() was very ambiguous which lead to some issues. Signed-off-by: Martin Kletzander <mkletzan@redhat.com> Reviewed-by: Andrea Bolognani <abologna@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
fa44bc8fd0
commit
c8bb95912e
@ -2076,7 +2076,6 @@ virFileFindHugeTLBFS;
|
|||||||
virFileFindMountPoint;
|
virFileFindMountPoint;
|
||||||
virFileFindResource;
|
virFileFindResource;
|
||||||
virFileFindResourceFull;
|
virFileFindResourceFull;
|
||||||
virFileFlock;
|
|
||||||
virFileFreeACLs;
|
virFileFreeACLs;
|
||||||
virFileGetACLs;
|
virFileGetACLs;
|
||||||
virFileGetDefaultHugepage;
|
virFileGetDefaultHugepage;
|
||||||
|
@ -463,30 +463,9 @@ int virFileUnlock(int fd, off_t start, off_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* virFileFlock:
|
|
||||||
* @fd: file descriptor to call flock on
|
|
||||||
* @lock: true for lock, false for unlock
|
|
||||||
* @shared: true if shared, false for exclusive, ignored if `@lock == false`
|
|
||||||
*
|
|
||||||
* This is just a simple wrapper around flock(2) that errors out on unsupported
|
|
||||||
* platforms.
|
|
||||||
*
|
|
||||||
* The lock will be released when @fd is closed or this function is called with
|
|
||||||
* `@lock == false`.
|
|
||||||
*
|
|
||||||
* Returns 0 on success, -1 otherwise (with errno set)
|
|
||||||
*/
|
|
||||||
int virFileFlock(int fd, bool lock, bool shared)
|
|
||||||
{
|
|
||||||
if (lock)
|
|
||||||
return flock(fd, shared ? LOCK_SH : LOCK_EX);
|
|
||||||
|
|
||||||
return flock(fd, LOCK_UN);
|
|
||||||
}
|
|
||||||
|
|
||||||
#else /* WIN32 */
|
#else /* WIN32 */
|
||||||
|
|
||||||
|
|
||||||
int virFileLock(int fd G_GNUC_UNUSED,
|
int virFileLock(int fd G_GNUC_UNUSED,
|
||||||
bool shared G_GNUC_UNUSED,
|
bool shared G_GNUC_UNUSED,
|
||||||
off_t start G_GNUC_UNUSED,
|
off_t start G_GNUC_UNUSED,
|
||||||
@ -505,14 +484,6 @@ int virFileUnlock(int fd G_GNUC_UNUSED,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int virFileFlock(int fd G_GNUC_UNUSED,
|
|
||||||
bool lock G_GNUC_UNUSED,
|
|
||||||
bool shared G_GNUC_UNUSED)
|
|
||||||
{
|
|
||||||
errno = ENOSYS;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* WIN32 */
|
#endif /* WIN32 */
|
||||||
|
|
||||||
|
|
||||||
|
@ -118,8 +118,6 @@ int virFileLock(int fd, bool shared, off_t start, off_t len, bool waitForLock)
|
|||||||
int virFileUnlock(int fd, off_t start, off_t len)
|
int virFileUnlock(int fd, off_t start, off_t len)
|
||||||
G_GNUC_NO_INLINE;
|
G_GNUC_NO_INLINE;
|
||||||
|
|
||||||
int virFileFlock(int fd, bool lock, bool shared);
|
|
||||||
|
|
||||||
typedef int (*virFileRewriteFunc)(int fd, const void *opaque);
|
typedef int (*virFileRewriteFunc)(int fd, const void *opaque);
|
||||||
int virFileRewrite(const char *path,
|
int virFileRewrite(const char *path,
|
||||||
mode_t mode,
|
mode_t mode,
|
||||||
|
@ -453,6 +453,8 @@ VIR_ONCE_GLOBAL_INIT(virResctrl);
|
|||||||
|
|
||||||
|
|
||||||
/* Common functions */
|
/* Common functions */
|
||||||
|
#ifndef WIN32
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virResctrlLockWrite(void)
|
virResctrlLockWrite(void)
|
||||||
{
|
{
|
||||||
@ -463,7 +465,7 @@ virResctrlLockWrite(void)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virFileFlock(fd, true, false) < 0) {
|
if (flock(fd, LOCK_EX) < 0) {
|
||||||
virReportSystemError(errno, "%s", _("Cannot lock resctrl"));
|
virReportSystemError(errno, "%s", _("Cannot lock resctrl"));
|
||||||
VIR_FORCE_CLOSE(fd);
|
VIR_FORCE_CLOSE(fd);
|
||||||
return -1;
|
return -1;
|
||||||
@ -485,7 +487,7 @@ virResctrlUnlock(int fd)
|
|||||||
virReportSystemError(errno, "%s", _("Cannot close resctrl"));
|
virReportSystemError(errno, "%s", _("Cannot close resctrl"));
|
||||||
|
|
||||||
/* Trying to save the already broken */
|
/* Trying to save the already broken */
|
||||||
if (virFileFlock(fd, false, false) < 0)
|
if (flock(fd, LOCK_UN) < 0)
|
||||||
virReportSystemError(errno, "%s", _("Cannot unlock resctrl"));
|
virReportSystemError(errno, "%s", _("Cannot unlock resctrl"));
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
@ -494,6 +496,29 @@ virResctrlUnlock(int fd)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else /* WIN32 */
|
||||||
|
|
||||||
|
static int
|
||||||
|
virResctrlLockWrite(void)
|
||||||
|
{
|
||||||
|
virReportSystemError(ENOSYS, "%s",
|
||||||
|
_("resctrl locking is not supported "
|
||||||
|
"on this platform"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
virResctrlUnlock(int fd G_GNUC_UNUSED)
|
||||||
|
{
|
||||||
|
virReportSystemError(ENOSYS, "%s",
|
||||||
|
_("resctrl locking is not supported "
|
||||||
|
"on this platform"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* WIN32 */
|
||||||
|
|
||||||
|
|
||||||
/* virResctrlInfo-related definitions */
|
/* virResctrlInfo-related definitions */
|
||||||
static int
|
static int
|
||||||
|
Loading…
Reference in New Issue
Block a user