[lxc-devel] [crio-lxc/master] add lint target, clean up some trivial things
The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/crio-lxc/pull/20 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 282de8dec8e79cada960186e9cabba07b611a42f Mon Sep 17 00:00:00 2001 From: Michael McCracken Date: Mon, 10 Feb 2020 15:28:15 -0800 Subject: [PATCH 1/3] create: propagate errors from ensureShell function Fixes #9 Signed-off-by: Michael McCracken --- cmd/create.go | 19 +++ 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/cmd/create.go b/cmd/create.go index 6e6ed4b..0c52d23 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -54,32 +54,33 @@ var NamespaceMap = map[string]string{ "uts": "uts", } -func ensureShell(rootfs string) { +func ensureShell(rootfs string) error { shPath := filepath.Join(rootfs, "bin/sh") if exists, _ := pathExists(shPath); exists { - return + return nil } var err error err = RunCommand("mkdir", filepath.Join(rootfs, "bin")) if err != nil { - fmt.Printf("Failed doing mkdir: %v\n", err) + return errors.Wrapf(err, "Failed doing mkdir") } err = RunCommand("cp", "/bin/busybox", filepath.Join(rootfs, "bin/")) if err != nil { - fmt.Printf("Failed copying busybox: %v\n", err) + return errors.Wrapf(err, "Failed copying busybox") } err = RunCommand("ln", filepath.Join(rootfs, "bin/busybox"), filepath.Join(rootfs, "bin/stat")) if err != nil { - fmt.Printf("Failed linking stat: %v\n", err) + return errors.Wrapf(err, "Failed linking stat") } err = RunCommand("ln", filepath.Join(rootfs, "bin/busybox"), filepath.Join(rootfs, "bin/sh")) if err != nil { - fmt.Printf("Failed linking sh: %v\n", err) + return errors.Wrapf(err, "Failed linking sh") } err = RunCommand("ln", filepath.Join(rootfs, "bin/busybox"), filepath.Join(rootfs, "bin/tee")) if err != nil { - fmt.Printf("Failed linking tee : %v\n", err) + return errors.Wrapf(err, "Failed linking tee") } + return nil } const ( @@ -243,7 +244,9 @@ func configureContainer(ctx *cli.Context, c *lxc.Container, spec *specs.Spec) er return errors.Wrapf(err, "couldn't write wrapper init") } - ensureShell(spec.Root.Path) + if err := ensureShell(spec.Root.Path); err != nil { + return errors.Wrap(err, "couldn't ensure a shell exists in container") + } if err := c.SetConfigItem("lxc.init.cwd", spec.Process.Cwd); err != nil { return errors.Wrap(err, "failed to set CWD") From 3718a05f3eb22bd0d3ba9979d3aa284cc44e4cee Mon Sep 17 00:00:00 2001 From: Michael McCracken Date: Mon, 10 Feb 2020 15:31:02 -0800 Subject: [PATCH 2/3] add linter target to makefile adds initial lint.yaml with some common annoying messages excluded. assumes you have golangci-lint installed. Signed-off-by: Michael McCracken --- Makefile | 3 +++ lint.yaml | 17 + 2 files changed, 20 insertions(+) create mode 100644 lint.yaml diff --git a/Makefile b/Makefile index e92cbd1..1d8f2b2 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,9 @@ COMMIT=$(if $(shell git status --porcelain --untracked-files=no),$(COMMIT_HASH)- TEST?=$(patsubst test/%.bats,%,$(wildcard test/*.bats)) PACKAGES_DIR?=~/packages +lint: + golangci-lint run -c ./lint.yaml ./... + crio-lxc: $(GO_SRC) go build -ldflags "-X main.version=$(COMMIT)" -o crio-lxc ./cmd diff --git a/lint.yaml b/lint.yaml new file mode 100644 index 000..f58ce3b --- /dev/null +++ b/lint.yaml @@ -0,0 +1,17 @@ +issues: + exclude: +- 'Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*printf?|os\.(Un)?Setenv). is not checked' +- 'error strings should not be capitalized' +- 'error strings should not end with punctuation' +- 'File is not `goimports`-ed' +- 'has \d* occurrences, make it a constant' +- 'line is \d* characters' +- 'is a global variable' +- 'ifElseChain: rewrite if-else to switch statement' +- 'Error return value of `.*` is not checked' +- 'cyclomatic complexity \d* of func' +- 'G107: Potential HTTP request made with variable url' +- 'should have name of the form ErrFoo' +- 'naked return in func' +- 'by other packages, and that stutters; consider calling this' +- 'File is not `gofmt`-ed with `-s`' From fa3e39e1e3873b530feb280184df64dec3024145 Mon Sep 17 00:00:00 2001 From: Michael McCracken Date: Mon, 10 Feb 2020 15:34:59 -0800 Subject: [PATCH 3/3] minor lint fixes Signed-off-by: Michael McCracken --- cmd/create.go | 2 +- cmd/state.go | 2 +-
[lxc-devel] [lxd/master] lxd/container: Protect file push/pull from shift
The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6864 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) === Closes #6853 Signed-off-by: Stéphane Graber From 6428f8287f433bec7da838cb48e65457dba29c99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= Date: Mon, 10 Feb 2020 16:43:32 -0500 Subject: [PATCH] lxd/container: Protect file push/pull from shift MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #6853 Signed-off-by: Stéphane Graber --- lxd/container_lxc.go | 12 1 file changed, 12 insertions(+) diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go index 5f2f972754..361ff52d6e 100644 --- a/lxd/container_lxc.go +++ b/lxd/container_lxc.go @@ -5349,6 +5349,12 @@ func (c *containerLXC) FileExists(path string) error { } func (c *containerLXC) FilePull(srcpath string, dstpath string) (int64, int64, os.FileMode, string, []string, error) { + // Check for ongoing operations (that may involve shifting). + op := operationlock.Get(c.id) + if op != nil { + op.Wait() + } + var ourStart bool var err error // Setup container storage if needed @@ -5472,6 +5478,12 @@ func (c *containerLXC) FilePull(srcpath string, dstpath string) (int64, int64, o } func (c *containerLXC) FilePush(type_ string, srcpath string, dstpath string, uid int64, gid int64, mode int, write string) error { + // Check for ongoing operations (that may involve shifting). + op := operationlock.Get(c.id) + if op != nil { + op.Wait() + } + var rootUid int64 var rootGid int64 var errStr string ___ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel
[lxc-devel] [lxd/master] lxc/file: Follow symlinks on individual file transfers
The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6863 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 844c70cfb5942a1dea97a3282b21b5819cfd0633 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= Date: Mon, 10 Feb 2020 15:58:38 -0500 Subject: [PATCH 1/2] shared: Add HostPathFollow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Graber --- shared/util.go | 17 + 1 file changed, 17 insertions(+) diff --git a/shared/util.go b/shared/util.go index 43b11b495c..ffaa750b9d 100644 --- a/shared/util.go +++ b/shared/util.go @@ -106,6 +106,23 @@ func IsUnixSocket(path string) bool { return (stat.Mode() & os.ModeSocket) == os.ModeSocket } +// HostPathFollow takes a valid path (from HostPath) and resolves it +// all the way to its target or to the last which can be resolved. +func HostPathFollow(path string) string { + for { + target, err := os.Readlink(path) + if err != nil { + return path + } + + if target == path { + return path + } + + path = HostPath(target) + } +} + // HostPath returns the host path for the provided path // On a normal system, this does nothing // When inside of a snap environment, returns the real path From 0a33b7065266b1bd9b5c6c8e7297eec273fbdbcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= Date: Mon, 10 Feb 2020 15:59:10 -0500 Subject: [PATCH 2/2] lxc/file: Follow symlinks on individual file transfers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Graber --- lxc/file.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lxc/file.go b/lxc/file.go index 83c5255f1c..aa7167a84b 100644 --- a/lxc/file.go +++ b/lxc/file.go @@ -535,6 +535,9 @@ func (c *cmdFilePush) Run(cmd *cobra.Command, args []string) error { if f == "-" { file = os.Stdin } else { + // Follow symlinks within the snap environment. + f = shared.HostPathFollow(f) + file, err = os.Open(f) if err != nil { return err ___ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel
[lxc-devel] [lxc/lxc] b8a6a0: lxclock: fix a small memory leak
Branch: refs/heads/master Home: https://github.com/lxc/lxc Commit: b8a6a00cc385fc0c6f36c6497f03a3fd40059706 https://github.com/lxc/lxc/commit/b8a6a00cc385fc0c6f36c6497f03a3fd40059706 Author: Tycho Andersen Date: 2020-02-10 (Mon, 10 Feb 2020) Changed paths: M src/lxc/lxclock.c Log Message: --- lxclock: fix a small memory leak if (!name), we allocate an unnamed semaphore, but if we then fail to allocate/create the lock, we don't free this semaphore, and we just leak it. Signed-off-by: Tycho Andersen Commit: 1d5f322246e030e1c6aa7b27c322bfc6995eb4d6 https://github.com/lxc/lxc/commit/1d5f322246e030e1c6aa7b27c322bfc6995eb4d6 Author: Christian Brauner Date: 2020-02-10 (Mon, 10 Feb 2020) Changed paths: M src/lxc/lxclock.c Log Message: --- Merge pull request #3264 from tych0/fix-leak lxclock: fix a small memory leak Compare: https://github.com/lxc/lxc/compare/a5ee97e62914...1d5f322246e0 ___ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel
[lxc-devel] [lxd/master] Re-disable clustering upgrade test
The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6861 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) === Signed-off-by: Free Ekanayaka From 9557298ebae4ed0e1190d26a283af9026a49a760 Mon Sep 17 00:00:00 2001 From: Free Ekanayaka Date: Mon, 10 Feb 2020 15:51:35 + Subject: [PATCH] Re-disable clustering upgrade test Signed-off-by: Free Ekanayaka --- test/main.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/main.sh b/test/main.sh index 563b409187..adb76d1f73 100755 --- a/test/main.sh +++ b/test/main.sh @@ -180,7 +180,7 @@ run_test test_clustering_dns "clustering DNS" run_test test_clustering_recover "clustering recovery" run_test test_clustering_handover "clustering handover" run_test test_clustering_rebalance "clustering rebalance" -run_test test_clustering_upgrade "clustering upgrade" +# run_test test_clustering_upgrade "clustering upgrade" run_test test_projects_default "default project" run_test test_projects_crud "projects CRUD operations" run_test test_projects_containers "containers inside projects" ___ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel
[lxc-devel] [lxd/master] lxd: Fix error message when deleting storage pools
The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6860 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) === This checks all projects for attached volumes when attempting to delete a storage pool. This fixes #6697. Signed-off-by: Thomas Hipp From f9339c0ac1ab9fd489eb614cd53ac356cec80968 Mon Sep 17 00:00:00 2001 From: Thomas Hipp Date: Mon, 10 Feb 2020 16:38:12 +0100 Subject: [PATCH] lxd: Fix error message when deleting storage pools This checks all projects for attached volumes when attempting to delete a storage pool. Signed-off-by: Thomas Hipp --- lxd/storage_pools.go | 42 -- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/lxd/storage_pools.go b/lxd/storage_pools.go index 2bc243885a..c978fc1c82 100644 --- a/lxd/storage_pools.go +++ b/lxd/storage_pools.go @@ -674,27 +674,41 @@ func storagePoolDeleteCheckPreconditions(cluster *db.Cluster, poolName string, p return response.InternalError(err) } + var projects []string + + err = cluster.Transaction(func(tx *db.ClusterTx) error { + projects, err = tx.ProjectNames() + return err + }) + if err != nil { + return response.InternalError(err) + } + if len(volumeNames) > 0 { - volumes, err := cluster.StoragePoolVolumesGet("default", poolID, supportedVolumeTypes) - if err != nil { - return response.InternalError(err) - } + for _, project := range projects { + volumes, err := cluster.StoragePoolVolumesGet(project, poolID, supportedVolumeTypes) + if err != nil { + return response.InternalError(err) + } - for _, volume := range volumes { - if volume.Type != "image" { - return response.BadRequest(fmt.Errorf("storage pool \"%s\" has volumes attached to it", poolName)) + for _, volume := range volumes { + if volume.Type != "image" { + return response.BadRequest(fmt.Errorf("storage pool \"%s\" has volumes attached to it", poolName)) + } } } } - // Check if the storage pool is still referenced in any profiles. - profiles, err := profilesUsingPoolGetNames(cluster, "default", poolName) - if err != nil { - return response.SmartError(err) - } + for _, project := range projects { + // Check if the storage pool is still referenced in any profiles. + profiles, err := profilesUsingPoolGetNames(cluster, project, poolName) + if err != nil { + return response.SmartError(err) + } - if len(profiles) > 0 { - return response.BadRequest(fmt.Errorf("Storage pool \"%s\" has profiles using it:\n%s", poolName, strings.Join(profiles, "\n"))) + if len(profiles) > 0 { + return response.BadRequest(fmt.Errorf("Storage pool \"%s\" has profiles using it:\n%s", poolName, strings.Join(profiles, "\n"))) + } } return nil ___ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel
[lxc-devel] [lxc/master] lxclock: fix a small memory leak
The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/3264 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) === if (!name), we allocate an unnamed semaphore, but if we then fail to allocate/create the lock, we don't free this semaphore, and we just leak it. Signed-off-by: Tycho Andersen From b8a6a00cc385fc0c6f36c6497f03a3fd40059706 Mon Sep 17 00:00:00 2001 From: Tycho Andersen Date: Mon, 10 Feb 2020 08:14:33 -0700 Subject: [PATCH] lxclock: fix a small memory leak if (!name), we allocate an unnamed semaphore, but if we then fail to allocate/create the lock, we don't free this semaphore, and we just leak it. Signed-off-by: Tycho Andersen --- src/lxc/lxclock.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lxc/lxclock.c b/src/lxc/lxclock.c index a77951a5b4..318e5bf5a3 100644 --- a/src/lxc/lxclock.c +++ b/src/lxc/lxclock.c @@ -169,6 +169,8 @@ struct lxc_lock *lxc_newlock(const char *lxcpath, const char *name) l->type = LXC_LOCK_FLOCK; l->u.f.fname = lxclock_name(lxcpath, name); if (!l->u.f.fname) { + if (!name) + free(l->u.sem); free(l); l = NULL; goto on_error; ___ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel
[lxc-devel] [lxd/master] Consider the default port when checking address overlap
The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6859 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) === Signed-off-by: Free Ekanayaka From 29966798bd0a0585939d56f060e348e33e18ddfe Mon Sep 17 00:00:00 2001 From: Free Ekanayaka Date: Mon, 10 Feb 2020 09:57:00 + Subject: [PATCH] Consider the default port when checking address overlap Signed-off-by: Free Ekanayaka --- lxd/util/net.go | 3 +++ lxd/util/net_test.go | 1 + 2 files changed, 4 insertions(+) diff --git a/lxd/util/net.go b/lxd/util/net.go index 154a0d98f5..af99fc98cd 100644 --- a/lxd/util/net.go +++ b/lxd/util/net.go @@ -138,6 +138,9 @@ func NetworkInterfaceAddress() string { // address2, in the sense that they are either the same address or address2 is // specified using a wildcard with the same port of address1. func IsAddressCovered(address1, address2 string) bool { + address1 = CanonicalNetworkAddress(address1) + address2 = CanonicalNetworkAddress(address2) + if address1 == address2 { return true } diff --git a/lxd/util/net_test.go b/lxd/util/net_test.go index 6c75a06ed0..e79ace9c3b 100644 --- a/lxd/util/net_test.go +++ b/lxd/util/net_test.go @@ -71,6 +71,7 @@ func TestIsAddressCovered(t *testing.T) { {"[::1]:8443", ":8443", true}, {":8443", "[::]:8443", true}, {"0.0.0.0:8443", "[::]:8443", true}, + {"10.30.0.8:8443", "[::]", true}, } // Test some localhost cases too ___ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel