[lxc-devel] [lxd/master] File manipulation fixes
stgraber on Github
lxc-bot at linuxcontainers.org
Thu Dec 1 04:29:41 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20161201/86e8adfd/attachment.bin>
-------------- next part --------------
From 48089b33925960e41a20e0cf2e92439038d434fa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 30 Nov 2016 22:58:04 -0500
Subject: [PATCH 1/3] Fix file push error handling
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd/container_lxc.go | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 9602965..a616b46 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -4208,7 +4208,6 @@ func (c *containerLXC) FilePull(srcpath string, dstpath string) (int, int, os.Fi
mode := -1
type_ := "unknown"
var dirEnts []string
-
var errStr string
// Process forkgetfile response
@@ -4228,6 +4227,7 @@ func (c *containerLXC) FilePull(srcpath string, dstpath string) (int, int, os.Fi
if errno == "2" {
return -1, -1, 0, "", nil, os.ErrNotExist
}
+
return -1, -1, 0, "", nil, fmt.Errorf(errStr)
}
@@ -4303,6 +4303,7 @@ func (c *containerLXC) FilePull(srcpath string, dstpath string) (int, int, os.Fi
func (c *containerLXC) FilePush(srcpath string, dstpath string, uid int, gid int, mode int) error {
var rootUid = 0
var rootGid = 0
+ var errStr string
// Map uid and gid if needed
if !c.IsRunning() {
@@ -4349,14 +4350,25 @@ func (c *containerLXC) FilePush(srcpath string, dstpath string, uid int, gid int
}
}
- // Process forkputfile response
- if string(out) != "" {
- if strings.HasPrefix(string(out), "error:") {
- return fmt.Errorf(strings.TrimPrefix(strings.TrimSuffix(string(out), "\n"), "error: "))
+ // Process forkgetfile response
+ for _, line := range strings.Split(strings.TrimRight(string(out), "\n"), "\n") {
+ if line == "" {
+ continue
}
- for _, line := range strings.Split(strings.TrimRight(string(out), "\n"), "\n") {
- shared.LogDebugf("forkgetfile: %s", line)
+ // Extract errors
+ if strings.HasPrefix(line, "error: ") {
+ errStr = strings.TrimPrefix(line, "error: ")
+ continue
+ }
+
+ if strings.HasPrefix(line, "errno: ") {
+ errno := strings.TrimPrefix(line, "errno: ")
+ if errno == "2" {
+ return os.ErrNotExist
+ }
+
+ return fmt.Errorf(errStr)
}
}
From c53d32e73d4378242dbed27b9b331912bb9e6a7b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 30 Nov 2016 23:14:31 -0500
Subject: [PATCH 2/3] Fix logging for file_manip commands
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd/container_lxc.go | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index a616b46..e13e43d 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -4167,9 +4167,10 @@ func (c *containerLXC) FileExists(path string) error {
if err != nil {
return fmt.Errorf(
- "Error calling 'lxd forkcheckfile %s %d': err='%v'",
- path,
+ "Error calling 'lxd forkcheckfile %s %d %s': err='%v'",
+ c.RootfsPath(),
c.InitPID(),
+ path,
err)
}
@@ -4278,9 +4279,10 @@ func (c *containerLXC) FilePull(srcpath string, dstpath string) (int, int, os.Fi
if err != nil {
return -1, -1, 0, "", nil, fmt.Errorf(
- "Error calling 'lxd forkgetfile %s %d %s': err='%v'",
- dstpath,
+ "Error calling 'lxd forkgetfile %s %d %s %s': err='%v'",
+ c.RootfsPath(),
c.InitPID(),
+ dstpath,
srcpath,
err)
}
@@ -4374,13 +4376,17 @@ func (c *containerLXC) FilePush(srcpath string, dstpath string, uid int, gid int
if err != nil {
return fmt.Errorf(
- "Error calling 'lxd forkputfile %s %d %s %d %d %d': err='%v'",
- srcpath,
+ "Error calling 'lxd forkputfile %s %d %s %s %d %d %d %d %d %d': err='%v'",
+ c.RootfsPath(),
c.InitPID(),
+ srcpath,
dstpath,
uid,
gid,
mode,
+ rootUid,
+ rootGid,
+ int(os.FileMode(0640)&os.ModePerm),
err)
}
@@ -4426,9 +4432,10 @@ func (c *containerLXC) FileRemove(path string) error {
if err != nil {
return fmt.Errorf(
- "Error calling 'lxd forkremovefile %s %d': err='%v'",
- path,
+ "Error calling 'lxd forkremovefile %s %d %s': err='%v'",
+ c.RootfsPath(),
c.InitPID(),
+ path,
err)
}
From 37deb0f241e1ecf412727da483ea1d51175022cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 30 Nov 2016 23:14:59 -0500
Subject: [PATCH 3/3] Return a clear error when replacing a directory
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Closes #2668
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd/nsexec.go | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/lxd/nsexec.go b/lxd/nsexec.go
index 356edc1..8d5c038 100644
--- a/lxd/nsexec.go
+++ b/lxd/nsexec.go
@@ -53,6 +53,12 @@ void error(char *msg)
{
int old_errno = errno;
+ if (old_errno == 0) {
+ fprintf(stderr, "%s\n", msg);
+ fprintf(stderr, "errno: 0\n");
+ return;
+ }
+
perror(msg);
fprintf(stderr, "errno: %d\n", old_errno);
}
@@ -230,6 +236,11 @@ int manip_file_in_ns(char *rootfs, int pid, char *host, char *container, bool is
if (is_put)
container_open_flags |= O_CREAT;
+ if (is_put && !is_dir_manip && exists && S_ISDIR(st.st_mode)) {
+ error("error: Path already exists as a directory");
+ goto close_host;
+ }
+
if (exists && S_ISDIR(st.st_mode))
container_open_flags = O_DIRECTORY;
More information about the lxc-devel
mailing list