Skip to content

Commit c8bb959

Browse files
committed
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 <[email protected]> Reviewed-by: Andrea Bolognani <[email protected]> Reviewed-by: Ján Tomko <[email protected]>
1 parent fa44bc8 commit c8bb959

File tree

4 files changed

+28
-35
lines changed

4 files changed

+28
-35
lines changed

src/libvirt_private.syms

-1
Original file line numberDiff line numberDiff line change
@@ -2076,7 +2076,6 @@ virFileFindHugeTLBFS;
20762076
virFileFindMountPoint;
20772077
virFileFindResource;
20782078
virFileFindResourceFull;
2079-
virFileFlock;
20802079
virFileFreeACLs;
20812080
virFileGetACLs;
20822081
virFileGetDefaultHugepage;

src/util/virfile.c

+1-30
Original file line numberDiff line numberDiff line change
@@ -463,30 +463,9 @@ int virFileUnlock(int fd, off_t start, off_t len)
463463
}
464464

465465

466-
/**
467-
* virFileFlock:
468-
* @fd: file descriptor to call flock on
469-
* @lock: true for lock, false for unlock
470-
* @shared: true if shared, false for exclusive, ignored if `@lock == false`
471-
*
472-
* This is just a simple wrapper around flock(2) that errors out on unsupported
473-
* platforms.
474-
*
475-
* The lock will be released when @fd is closed or this function is called with
476-
* `@lock == false`.
477-
*
478-
* Returns 0 on success, -1 otherwise (with errno set)
479-
*/
480-
int virFileFlock(int fd, bool lock, bool shared)
481-
{
482-
if (lock)
483-
return flock(fd, shared ? LOCK_SH : LOCK_EX);
484-
485-
return flock(fd, LOCK_UN);
486-
}
487-
488466
#else /* WIN32 */
489467

468+
490469
int virFileLock(int fd G_GNUC_UNUSED,
491470
bool shared G_GNUC_UNUSED,
492471
off_t start G_GNUC_UNUSED,
@@ -505,14 +484,6 @@ int virFileUnlock(int fd G_GNUC_UNUSED,
505484
}
506485

507486

508-
int virFileFlock(int fd G_GNUC_UNUSED,
509-
bool lock G_GNUC_UNUSED,
510-
bool shared G_GNUC_UNUSED)
511-
{
512-
errno = ENOSYS;
513-
return -1;
514-
}
515-
516487
#endif /* WIN32 */
517488

518489

src/util/virfile.h

-2
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ int virFileLock(int fd, bool shared, off_t start, off_t len, bool waitForLock)
118118
int virFileUnlock(int fd, off_t start, off_t len)
119119
G_GNUC_NO_INLINE;
120120

121-
int virFileFlock(int fd, bool lock, bool shared);
122-
123121
typedef int (*virFileRewriteFunc)(int fd, const void *opaque);
124122
int virFileRewrite(const char *path,
125123
mode_t mode,

src/util/virresctrl.c

+27-2
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,8 @@ VIR_ONCE_GLOBAL_INIT(virResctrl);
453453

454454

455455
/* Common functions */
456+
#ifndef WIN32
457+
456458
static int
457459
virResctrlLockWrite(void)
458460
{
@@ -463,7 +465,7 @@ virResctrlLockWrite(void)
463465
return -1;
464466
}
465467

466-
if (virFileFlock(fd, true, false) < 0) {
468+
if (flock(fd, LOCK_EX) < 0) {
467469
virReportSystemError(errno, "%s", _("Cannot lock resctrl"));
468470
VIR_FORCE_CLOSE(fd);
469471
return -1;
@@ -485,7 +487,7 @@ virResctrlUnlock(int fd)
485487
virReportSystemError(errno, "%s", _("Cannot close resctrl"));
486488

487489
/* Trying to save the already broken */
488-
if (virFileFlock(fd, false, false) < 0)
490+
if (flock(fd, LOCK_UN) < 0)
489491
virReportSystemError(errno, "%s", _("Cannot unlock resctrl"));
490492

491493
return -1;
@@ -494,6 +496,29 @@ virResctrlUnlock(int fd)
494496
return 0;
495497
}
496498

499+
#else /* WIN32 */
500+
501+
static int
502+
virResctrlLockWrite(void)
503+
{
504+
virReportSystemError(ENOSYS, "%s",
505+
_("resctrl locking is not supported "
506+
"on this platform"));
507+
return -1;
508+
}
509+
510+
511+
static int
512+
virResctrlUnlock(int fd G_GNUC_UNUSED)
513+
{
514+
virReportSystemError(ENOSYS, "%s",
515+
_("resctrl locking is not supported "
516+
"on this platform"));
517+
return -1;
518+
}
519+
520+
#endif /* WIN32 */
521+
497522

498523
/* virResctrlInfo-related definitions */
499524
static int

0 commit comments

Comments
 (0)