The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6531

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===

From 6a1c1d9e719af8be4978d598424a205772dfc965 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com>
Date: Fri, 29 Nov 2019 16:41:31 -0500
Subject: [PATCH 1/4] lxd/vm: Implement freeze/unfreeze
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
---
 lxd/qmp/monitor.go |  5 +++++
 lxd/vm_qemu.go     | 28 +++++++++++++++++++++++++++-
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/lxd/qmp/monitor.go b/lxd/qmp/monitor.go
index 3a1ad4343c..79a2692519 100644
--- a/lxd/qmp/monitor.go
+++ b/lxd/qmp/monitor.go
@@ -268,6 +268,11 @@ func (m *Monitor) Start() error {
        return m.runCmd("cont")
 }
 
+// Pause tells QEMU to temporarily stop the emulation.
+func (m *Monitor) Pause() error {
+       return m.runCmd("stop")
+}
+
 // Quit tells QEMU to exit immediately.
 func (m *Monitor) Quit() error {
        return m.runCmd("quit")
diff --git a/lxd/vm_qemu.go b/lxd/vm_qemu.go
index 053063beb4..3efa91e1f0 100644
--- a/lxd/vm_qemu.go
+++ b/lxd/vm_qemu.go
@@ -430,6 +430,18 @@ func (vm *vmQemu) generateAgentCert() (string, string, 
string, string, error) {
 }
 
 func (vm *vmQemu) Freeze() error {
+       // Connect to the monitor.
+       monitor, err := qmp.Connect(vm.getMonitorPath(), 
vm.getMonitorEventHandler())
+       if err != nil {
+               return err
+       }
+
+       // Send the stop command.
+       err = monitor.Pause()
+       if err != nil {
+               return err
+       }
+
        return nil
 }
 
@@ -1431,7 +1443,19 @@ func (vm *vmQemu) Stop(stateful bool) error {
 }
 
 func (vm *vmQemu) Unfreeze() error {
-       return fmt.Errorf("Unfreeze Not implemented")
+       // Connect to the monitor.
+       monitor, err := qmp.Connect(vm.getMonitorPath(), 
vm.getMonitorEventHandler())
+       if err != nil {
+               return err
+       }
+
+       // Send the cont command.
+       err = monitor.Start()
+       if err != nil {
+               return err
+       }
+
+       return nil
 }
 
 func (vm *vmQemu) IsPrivileged() bool {
@@ -2812,6 +2836,8 @@ func (vm *vmQemu) statusCode() api.StatusCode {
 
        if status == "running" {
                return api.Running
+       } else if status == "paused" {
+               return api.Frozen
        }
 
        return api.Stopped

From 7e0083634ae8dffeda8c31f19514faadb3b8541a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com>
Date: Fri, 29 Nov 2019 16:43:56 -0500
Subject: [PATCH 2/4] lxd/vm: Privileged mode doesn't apply
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
---
 lxd/vm_qemu.go | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lxd/vm_qemu.go b/lxd/vm_qemu.go
index 3efa91e1f0..41ecbf8385 100644
--- a/lxd/vm_qemu.go
+++ b/lxd/vm_qemu.go
@@ -1459,7 +1459,8 @@ func (vm *vmQemu) Unfreeze() error {
 }
 
 func (vm *vmQemu) IsPrivileged() bool {
-       return shared.IsTrue(vm.expandedConfig["security.privileged"])
+       // Privileged mode doesn't apply to virtual machines
+       return false
 }
 
 func (vm *vmQemu) Restore(source instance.Instance, stateful bool) error {

From a7ea7e3cbb0b0bcee078f250d8bb449d8bd98e7b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com>
Date: Fri, 29 Nov 2019 17:05:47 -0500
Subject: [PATCH 3/4] client: Add agent version of DeleteInstanceFile
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
---
 client/lxd_instances.go | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/client/lxd_instances.go b/client/lxd_instances.go
index 9b042d469c..340a4b9bf5 100644
--- a/client/lxd_instances.go
+++ b/client/lxd_instances.go
@@ -1109,17 +1109,31 @@ func (r *ProtocolLXD) CreateInstanceFile(instanceName 
string, filePath string, a
 
 // DeleteInstanceFile deletes a file in the instance.
 func (r *ProtocolLXD) DeleteInstanceFile(instanceName string, filePath string) 
error {
-       path, _, err := r.instanceTypeToPath(api.InstanceTypeAny)
-       if err != nil {
-               return err
-       }
-
        if !r.HasExtension("file_delete") {
                return fmt.Errorf("The server is missing the required 
\"file_delete\" API extension")
        }
 
+       var requestURL string
+
+       if r.IsAgent() {
+               requestURL = fmt.Sprintf("/files?path=%s", 
url.QueryEscape(filePath))
+       } else {
+               path, _, err := r.instanceTypeToPath(api.InstanceTypeAny)
+               if err != nil {
+                       return err
+               }
+
+               // Prepare the HTTP request
+               requestURL = fmt.Sprintf("%s/%s/files?path=%s", path, 
url.PathEscape(instanceName), url.QueryEscape(filePath))
+       }
+
+       requestURL, err := r.setQueryAttributes(requestURL)
+       if err != nil {
+               return err
+       }
+
        // Send the request
-       _, _, err = r.query("DELETE", fmt.Sprintf("%s/%s/files?path=%s", path, 
url.PathEscape(instanceName), url.QueryEscape(filePath)), nil, "")
+       _, _, err = r.query("DELETE", requestURL, nil, "")
        if err != nil {
                return err
        }

From 0788330915ff9327af0b30f6b82be5da5cd9be1e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com>
Date: Fri, 29 Nov 2019 17:05:58 -0500
Subject: [PATCH 4/4] lxd/vm: Add FileRemove support
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
---
 lxd/vm_qemu.go | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/lxd/vm_qemu.go b/lxd/vm_qemu.go
index 41ecbf8385..284ef6df37 100644
--- a/lxd/vm_qemu.go
+++ b/lxd/vm_qemu.go
@@ -2305,7 +2305,25 @@ func (vm *vmQemu) FilePush(fileType string, srcPath 
string, dstPath string, uid
 }
 
 func (vm *vmQemu) FileRemove(path string) error {
-       return fmt.Errorf("FileRemove Not implemented")
+       // Connect to the agent.
+       client, err := vm.getAgentClient()
+       if err != nil {
+               return err
+       }
+
+       agent, err := lxdClient.ConnectLXDHTTP(nil, client)
+       if err != nil {
+               return fmt.Errorf("Failed to connect to lxd-agent")
+       }
+       defer agent.Disconnect()
+
+       // Delete instance file.
+       err = agent.DeleteInstanceFile("", path)
+       if err != nil {
+               return err
+       }
+
+       return nil
 }
 
 func (vm *vmQemu) Console() (*os.File, chan error, error) {
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to