[lxc-devel] [lxd/master] LXD init: Verify ZFS pool when in interactive mode.

2018-12-11 Thread dnegreira on Github
The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/5350

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) ===
Follow up of: https://github.com/lxc/lxd/pull/5345
The ZFS pool is only verified at a later stage as soon LXD tries to create it.

This causes some frustration as we need to go through the whole lxd init process only to find out a mistake was made at a later stage.

This PR implements a function to verify if a ZFS pool exists and a check on the `lxd init` interactive process that calls that same function when a user defines the pool setting to have a ZFS backend.
From e257b2cbe243030f129f1d3ab7e02da42b768926 Mon Sep 17 00:00:00 2001
From: David Negreira 
Date: Wed, 12 Dec 2018 00:27:23 +0100
Subject: [PATCH 1/2] lxd/storage_zfs_utils: Add zfsPoolVolumeExists

Signed-off-by: David Negreira 
---
 lxd/storage_zfs_utils.go | 17 +
 1 file changed, 17 insertions(+)

diff --git a/lxd/storage_zfs_utils.go b/lxd/storage_zfs_utils.go
index f6583a8b46..4ce07da45f 100644
--- a/lxd/storage_zfs_utils.go
+++ b/lxd/storage_zfs_utils.go
@@ -89,6 +89,23 @@ func zfsPoolCheck(pool string) error {
return nil
 }
 
+// zfsPoolVolumeExists verifies if a specific ZFS pool or volume exists.
+func zfsPoolVolumeExists(dataset string) (bool, error) {
+   output, err := shared.RunCommand(
+   "zfs", "list", "-Ho", "name")
+
+   if err != nil {
+   return false, err
+   }
+
+   for _, name := range strings.Split(output, "\n") {
+   if name == dataset {
+   return true, nil
+   }
+   }
+   return false, nil
+}
+
 func zfsPoolCreate(pool string, vdev string) error {
var output string
var err error

From 0fab33b93ea699fc1938ec8f3081c1a148b0c969 Mon Sep 17 00:00:00 2001
From: David Negreira 
Date: Wed, 12 Dec 2018 00:27:28 +0100
Subject: [PATCH 2/2] lxd/init: Checks if a zfs storage pool or dataset exists

Signed-off-by: David Negreira 
---
 lxd/main_init_interactive.go | 27 +++
 1 file changed, 27 insertions(+)

diff --git a/lxd/main_init_interactive.go b/lxd/main_init_interactive.go
index 623b0bfe2e..12aafeb21a 100644
--- a/lxd/main_init_interactive.go
+++ b/lxd/main_init_interactive.go
@@ -495,6 +495,18 @@ func (c *cmdInit) askStoragePool(config *cmdInitData, d 
lxd.ContainerServer, poo
 
// Ask for the number of placement groups
pool.Config["ceph.osd.pg_num"] = 
cli.AskString("Number of placement groups [default=32]: ", "32", nil)
+   }
+   if pool.Driver == "zfs" {
+   if os.Geteuid() != 0 {
+   return fmt.Errorf("In order to create a 
ZFS pool, we require root privileges")
+   }
+   poolvolumeexists, err := 
zfsPoolVolumeExists(pool.Name)
+   if err != nil {
+   return err
+   }
+   if poolvolumeexists {
+   return fmt.Errorf("'%s' ZFS pool 
already exists", pool.Name)
+   }
} else if cli.AskBool("Would you like to use an 
existing block device? (yes/no) [default=no]: ", "no") {
deviceExists := func(path string) error {
if !shared.IsBlockdevPath(path) {
@@ -551,6 +563,21 @@ func (c *cmdInit) askStoragePool(config *cmdInitData, d 
lxd.ContainerServer, poo
// ask for the name of the existing pool
pool.Config["source"] = cli.AskString("Name of 
the existing OSD storage pool [default=lxd]: ", "lxd", nil)
pool.Config["ceph.osd.pool_name"] = 
pool.Config["source"]
+   }
+   if pool.Driver == "zfs" {
+   if os.Geteuid() != 0 {
+   return fmt.Errorf("In order to create a 
ZFS pool, we require root privileges")
+   }
+   answer := cli.AskString("Name of the existing 
ZFS storage pool: ", "", nil)
+   poolvolumeexists, err := 
zfsPoolVolumeExists(answer)
+   if err != nil {
+   return err
+   }
+   if poolvolumeexists == false {
+   return fmt.Errorf("'%s' ZFS pool or 
dataset does not exist", answer)
+   } else {
+ 

[lxc-devel] [lxc/master] CMD log macros: append a newline

2018-12-11 Thread tych0 on Github
The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/2750

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) ===
The log appenders for the regular log macros append a newline as necessary,
and the usage of these is written so it does to. So, let's add a newline.

Signed-off-by: Tycho Andersen 
From cd427d39e37f624df539520b070b99e55c1727f6 Mon Sep 17 00:00:00 2001
From: Tycho Andersen 
Date: Tue, 11 Dec 2018 09:51:31 -0700
Subject: [PATCH] CMD log macros: append a newline

The log appenders for the regular log macros append a newline as necessary,
and the usage of these is written so it does to. So, let's add a newline.

Signed-off-by: Tycho Andersen 
---
 src/lxc/log.h | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/lxc/log.h b/src/lxc/log.h
index 008df7a73..d4a89d616 100644
--- a/src/lxc/log.h
+++ b/src/lxc/log.h
@@ -452,16 +452,16 @@ ATTR_UNUSED static inline void LXC_##LEVEL(struct 
lxc_log_locinfo* locinfo,   \
ERROR("%s - " format, ptr, ##__VA_ARGS__); \
} while (0)
 
-#define CMD_SYSERROR(format, ...)\
-   do { \
-   lxc_log_strerror_r;  \
-   fprintf(stderr, "%s - " format, ptr, ##__VA_ARGS__); \
+#define CMD_SYSERROR(format, ...)  \
+   do {   \
+   lxc_log_strerror_r;\
+   fprintf(stderr, "%s - \n" format, ptr, ##__VA_ARGS__); \
} while (0)
 
-#define CMD_SYSINFO(format, ...)\
-   do {\
-   lxc_log_strerror_r; \
-   printf("%s - " format, ptr, ##__VA_ARGS__); \
+#define CMD_SYSINFO(format, ...)  \
+   do {  \
+   lxc_log_strerror_r;   \
+   printf("%s - \n" format, ptr, ##__VA_ARGS__); \
} while (0)
 
 extern int lxc_log_fd;
___
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel


[lxc-devel] [lxc/lxc] 4f08c8: storage: remove unused function

2018-12-11 Thread GitHub
  Branch: refs/heads/master
  Home:   https://github.com/lxc/lxc
  Commit: 4f08c8d46f7231635278aaa61025a1df0fa4d659
  https://github.com/lxc/lxc/commit/4f08c8d46f7231635278aaa61025a1df0fa4d659
  Author: Christian Brauner 
  Date:   2018-12-11 (Tue, 11 Dec 2018)

  Changed paths:
M src/lxc/storage/storage_utils.c
M src/lxc/storage/storage_utils.h

  Log Message:
  ---
  storage: remove unused function

Signed-off-by: Christian Brauner 


  Commit: b3fc069e4121b283b78c82d715100bddcf326d48
  https://github.com/lxc/lxc/commit/b3fc069e4121b283b78c82d715100bddcf326d48
  Author: Wolfgang Bumiller 
  Date:   2018-12-11 (Tue, 11 Dec 2018)

  Changed paths:
M src/lxc/storage/storage_utils.c
M src/lxc/storage/storage_utils.h

  Log Message:
  ---
  Merge pull request #2749 from brauner/2018-12-11/storage_utils

storage: src cannot be truncated


Compare: https://github.com/lxc/lxc/compare/be50a0d9c58d...b3fc069e4121
  **NOTE:** This service has been marked for deprecation: 
https://developer.github.com/changes/2018-04-25-github-services-deprecation/

  Functionality will be removed from GitHub.com on January 31st, 2019.
___
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel


[lxc-devel] [lxc/lxc] 87b717: commands: backport robust infrastructure

2018-12-11 Thread GitHub
  Branch: refs/heads/stable-2.0
  Home:   https://github.com/lxc/lxc
  Commit: 87b7179ca78af19bdf763df9bd1ca6a3db099a60
  https://github.com/lxc/lxc/commit/87b7179ca78af19bdf763df9bd1ca6a3db099a60
  Author: Christian Brauner 
  Date:   2018-12-11 (Tue, 11 Dec 2018)

  Changed paths:
M src/lxc/commands.c
M src/lxc/commands.h
M src/lxc/commands_utils.c
M src/lxc/commands_utils.h

  Log Message:
  ---
  commands: backport robust infrastructure

Signed-off-by: Christian Brauner 



  **NOTE:** This service has been marked for deprecation: 
https://developer.github.com/changes/2018-04-25-github-services-deprecation/

  Functionality will be removed from GitHub.com on January 31st, 2019.
___
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel


[lxc-devel] [lxc/master] storage: src cannot be truncated

2018-12-11 Thread brauner on Github
The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/2749

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) ===
s/strlcpy/strncpy/g

Signed-off-by: Christian Brauner 
From 2970e75408559d99ec3d5f5f393c9020a0698cb5 Mon Sep 17 00:00:00 2001
From: Christian Brauner 
Date: Tue, 11 Dec 2018 11:36:54 +0100
Subject: [PATCH] storage: src cannot be truncated

s/strlcpy/strncpy/g

Signed-off-by: Christian Brauner 
---
 src/lxc/storage/storage_utils.c | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/src/lxc/storage/storage_utils.c b/src/lxc/storage/storage_utils.c
index fa4e7270bd..8bf55c52bd 100644
--- a/src/lxc/storage/storage_utils.c
+++ b/src/lxc/storage/storage_utils.c
@@ -95,14 +95,8 @@ char *dir_new_path(char *src, const char *oldname, const 
char *name,
}
 
while ((p2 = strstr(src, oldname)) != NULL) {
-   size_t retlen;
-
/* copy text up to oldname */
-   retlen = strlcpy(p, src, p2 - src);
-   if (retlen >= p2 - src) {
-   free(ret);
-   return NULL;
-   }
+   strncpy(p, src, p2 - src);
 
/* move target pointer (p) */
p += p2 - src;
___
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel


[lxc-devel] [lxc/lxc] c458e2: storage: src cannot be truncated

2018-12-11 Thread GitHub
  Branch: refs/heads/stable-2.0
  Home:   https://github.com/lxc/lxc
  Commit: c458e2120b83163a3e77707dafeed0352bdaa5d0
  https://github.com/lxc/lxc/commit/c458e2120b83163a3e77707dafeed0352bdaa5d0
  Author: Christian Brauner 
  Date:   2018-12-11 (Tue, 11 Dec 2018)

  Changed paths:
M src/lxc/storage/storage_utils.c

  Log Message:
  ---
  storage: src cannot be truncated

s/strlcpy/strncpy/g

Signed-off-by: Christian Brauner 



  **NOTE:** This service has been marked for deprecation: 
https://developer.github.com/changes/2018-04-25-github-services-deprecation/

  Functionality will be removed from GitHub.com on January 31st, 2019.
___
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel