[PATCH] virtlockd: acquire locks on re-exec

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Locks held by virtlockd are dropped on re-exec.

virtlockd       94306 POSIX 5.4G WRITE 0     0   0 /tmp/test.qcow2
virtlockd       94306 POSIX   5B WRITE 0     0   0 /run/virtlockd.pid
virtlockd       94306 POSIX   5B WRITE 0     0   0 /run/virtlockd.pid

Acquire locks in PostExecRestart code path.

Signed-off-by: Jim Fehlig <jfehlig@xxxxxxxx>
---

The CLOEXEC flag is set in virLockSpaceNewPostExecRestart(), so I assume
it is fine to call virFileLock() here as well.

 src/util/virlockspace.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c
index 41af0cdb6..420878b0a 100644
--- a/src/util/virlockspace.c
+++ b/src/util/virlockspace.c
@@ -337,6 +337,7 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object)
         virJSONValuePtr owners;
         size_t j;
         ssize_t m;
+        bool shared = false;
 
         if (VIR_ALLOC(res) < 0)
             goto error;
@@ -389,6 +390,21 @@ virLockSpacePtr virLockSpaceNewPostExecRestart(virJSONValuePtr object)
             goto error;
         }
 
+        shared = !!(res->flags & VIR_LOCK_SPACE_ACQUIRE_SHARED);
+        if (virFileLock(res->fd, shared, 0, 1, false) < 0) {
+            if (errno == EACCES || errno == EAGAIN) {
+                virReportError(VIR_ERR_RESOURCE_BUSY,
+                               _("Lockspace resource '%s' is locked"),
+                               res->name);
+            } else {
+                virReportSystemError(errno,
+                                     _("Unable to acquire lock on '%s'"),
+                                     res->path);
+            }
+            virLockSpaceResourceFree(res);
+            goto error;
+        }
+
         if (!(owners = virJSONValueObjectGet(child, "owners"))) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("Missing resource owners in JSON document"));
-- 
2.16.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux