[lxc-devel] [lxd/master] Support using btrfs as volume block filesystem
albertodonato on Github
lxc-bot at linuxcontainers.org
Mon Sep 18 14:47:49 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 314 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170918/672fe99a/attachment.bin>
-------------- next part --------------
From 437416cf38745633a36e2d257a07ff9f444b1f60 Mon Sep 17 00:00:00 2001
From: Alberto Donato <alberto.donato at canonical.com>
Date: Mon, 18 Sep 2017 12:33:34 +0200
Subject: [PATCH 1/3] storage: extend makeFSType, remove duplicated mkfs.* code
Signed-off-by: Alberto Donato <alberto.donato at canonical.com>
---
lxd/storage_btrfs.go | 8 ++------
lxd/storage_ceph.go | 6 +++---
lxd/storage_lvm_utils.go | 12 +-----------
lxd/storage_utils.go | 30 +++++++++++++++++++++---------
4 files changed, 27 insertions(+), 29 deletions(-)
diff --git a/lxd/storage_btrfs.go b/lxd/storage_btrfs.go
index 0b58dd135..b78b415ad 100644
--- a/lxd/storage_btrfs.go
+++ b/lxd/storage_btrfs.go
@@ -133,9 +133,7 @@ func (s *storageBtrfs) StoragePoolCreate() error {
return fmt.Errorf("Failed to create sparse file %s: %s", source, err)
}
- output, err := shared.RunCommand(
- "mkfs.btrfs",
- "-L", s.pool.Name, source)
+ output, err := makeFSType(source, "btrfs", &mkfsOptions{label: s.pool.Name})
if err != nil {
return fmt.Errorf("Failed to create the BTRFS pool: %s", output)
}
@@ -146,9 +144,7 @@ func (s *storageBtrfs) StoragePoolCreate() error {
if filepath.IsAbs(source) {
isBlockDev = shared.IsBlockdevPath(source)
if isBlockDev {
- output, err := shared.RunCommand(
- "mkfs.btrfs",
- "-L", s.pool.Name, source)
+ output, err := makeFSType(source, "btrfs", &mkfsOptions{label: s.pool.Name})
if err != nil {
return fmt.Errorf("Failed to create the BTRFS pool: %s", output)
}
diff --git a/lxd/storage_ceph.go b/lxd/storage_ceph.go
index d665527c4..c73a4b4d8 100644
--- a/lxd/storage_ceph.go
+++ b/lxd/storage_ceph.go
@@ -417,7 +417,7 @@ func (s *storageCeph) StoragePoolVolumeCreate() error {
`"%s" on storage pool "%s"`, RBDFilesystem, s.volume.Name,
s.pool.Name)
- msg, err := makeFSType(RBDDevPath, RBDFilesystem)
+ msg, err := makeFSType(RBDDevPath, RBDFilesystem, nil)
if err != nil {
logger.Errorf(`Failed to create filesystem type "%s" on `+
`device path "%s" for RBD storage volume "%s" on `+
@@ -794,7 +794,7 @@ func (s *storageCeph) ContainerCreate(container container) error {
`for container "%s" on storage pool "%s"`, RBDFilesystem,
containerName, s.pool.Name)
- msg, err := makeFSType(RBDDevPath, RBDFilesystem)
+ msg, err := makeFSType(RBDDevPath, RBDFilesystem, nil)
if err != nil {
logger.Errorf(`Failed to create filesystem type "%s" on `+
`device path "%s" for RBD storage volume for `+
@@ -2220,7 +2220,7 @@ func (s *storageCeph) ImageCreate(fingerprint string) error {
// get filesystem
RBDFilesystem := s.getRBDFilesystem()
- msg, err := makeFSType(RBDDevPath, RBDFilesystem)
+ msg, err := makeFSType(RBDDevPath, RBDFilesystem, nil)
if err != nil {
logger.Errorf(`Failed to create filesystem "%s" for RBD `+
`storage volume for image "%s" on storage `+
diff --git a/lxd/storage_lvm_utils.go b/lxd/storage_lvm_utils.go
index 6deacaad1..1383e0c6e 100644
--- a/lxd/storage_lvm_utils.go
+++ b/lxd/storage_lvm_utils.go
@@ -826,17 +826,7 @@ func lvmCreateLv(vgName string, thinPoolName string, lvName string, lvFsType str
fsPath := getLvmDevPath(vgName, volumeType, lvName)
- switch lvFsType {
- case "xfs":
- output, err = shared.TryRunCommand("mkfs.xfs", fsPath)
- default:
- // default = ext4
- output, err = shared.TryRunCommand(
- "mkfs.ext4",
- "-E", "nodiscard,lazy_itable_init=0,lazy_journal_init=0",
- fsPath)
- }
-
+ output, err = makeFSType(fsPath, lvFsType, nil)
if err != nil {
logger.Errorf("Filesystem creation failed: %s.", output)
return fmt.Errorf("Error making filesystem on image LV: %v", err)
diff --git a/lxd/storage_utils.go b/lxd/storage_utils.go
index 6e5588b47..8d26f9a1f 100644
--- a/lxd/storage_utils.go
+++ b/lxd/storage_utils.go
@@ -2,6 +2,7 @@ package main
import (
"database/sql"
+ "fmt"
"os"
"strings"
"syscall"
@@ -11,6 +12,11 @@ import (
"github.com/lxc/lxd/shared"
)
+// Options for filesystem creation
+type mkfsOptions struct {
+ label string
+}
+
// Export the mount options map since we might find it useful in other parts of
// LXD.
type mountOptions struct {
@@ -181,19 +187,25 @@ func lxdUsesPool(dbObj *sql.DB, onDiskPoolName string, driver string, onDiskProp
return false, "", nil
}
-func makeFSType(path string, fsType string) (string, error) {
+func makeFSType(path string, fsType string, options *mkfsOptions) (string, error) {
var err error
var msg string
- switch fsType {
- case "xfs":
- msg, err = shared.TryRunCommand("mkfs.xfs", path)
- default:
- msg, err = shared.TryRunCommand(
- "mkfs.ext4",
- "-E", "nodiscard,lazy_itable_init=0,lazy_journal_init=0",
- path)
+ fsOptions := options
+ if fsOptions == nil {
+ fsOptions = &mkfsOptions{}
+ }
+
+ cmd := []string{fmt.Sprintf("mkfs.%s", fsType), path}
+ if fsOptions.label != "" {
+ cmd = append(cmd, "-L", fsOptions.label)
}
+
+ if fsType == "ext4" {
+ cmd = append(cmd, "-E", "nodiscard,lazy_itable_init=0,lazy_journal_init=0")
+ }
+
+ msg, err = shared.TryRunCommand(cmd[0], cmd[1:]...)
if err != nil {
return msg, err
}
From 2ba5bd1f08147fb8da40b69afeaf4c6ea5878f61 Mon Sep 17 00:00:00 2001
From: Alberto Donato <alberto.donato at canonical.com>
Date: Mon, 18 Sep 2017 15:01:47 +0200
Subject: [PATCH 2/3] storage: support volume.block.filesystem=btrfs
Signed-off-by: Alberto Donato <alberto.donato at canonical.com>
---
lxd/daemon_config.go | 2 +-
lxd/storage_pools_config.go | 2 +-
lxd/storage_volumes_config.go | 2 +-
test/suites/storage.sh | 1 +
4 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/lxd/daemon_config.go b/lxd/daemon_config.go
index c74214e50..35b63220f 100644
--- a/lxd/daemon_config.go
+++ b/lxd/daemon_config.go
@@ -191,7 +191,7 @@ func daemonConfigInit(db *sql.DB) error {
"images.remote_cache_expiry": {valueType: "int", defaultValue: "10", trigger: daemonConfigTriggerExpiry},
// Keys deprecated since the implementation of the storage api.
- "storage.lvm_fstype": {valueType: "string", defaultValue: "ext4", validValues: []string{"ext4", "xfs"}, validator: storageDeprecatedKeys},
+ "storage.lvm_fstype": {valueType: "string", defaultValue: "ext4", validValues: []string{"btrfs", "ext4", "xfs"}, validator: storageDeprecatedKeys},
"storage.lvm_mount_options": {valueType: "string", defaultValue: "discard", validator: storageDeprecatedKeys},
"storage.lvm_thinpool_name": {valueType: "string", defaultValue: "LXDPool", validator: storageDeprecatedKeys},
"storage.lvm_vg_name": {valueType: "string", validator: storageDeprecatedKeys},
diff --git a/lxd/storage_pools_config.go b/lxd/storage_pools_config.go
index 0782052f9..293b2062a 100644
--- a/lxd/storage_pools_config.go
+++ b/lxd/storage_pools_config.go
@@ -60,7 +60,7 @@ var storagePoolConfigKeys = map[string]func(value string) error{
// valid drivers: ceph, lvm
"volume.block.filesystem": func(value string) error {
- return shared.IsOneOf(value, []string{"ext4", "xfs"})
+ return shared.IsOneOf(value, []string{"btrfs", "ext4", "xfs"})
},
"volume.block.mount_options": shared.IsAny,
diff --git a/lxd/storage_volumes_config.go b/lxd/storage_volumes_config.go
index 37ac53877..e1d0ee64c 100644
--- a/lxd/storage_volumes_config.go
+++ b/lxd/storage_volumes_config.go
@@ -11,7 +11,7 @@ import (
var storageVolumeConfigKeys = map[string]func(value string) error{
"block.mount_options": shared.IsAny,
"block.filesystem": func(value string) error {
- return shared.IsOneOf(value, []string{"ext4", "xfs"})
+ return shared.IsOneOf(value, []string{"btrfs", "ext4", "xfs"})
},
"size": func(value string) error {
if value == "" {
diff --git a/test/suites/storage.sh b/test/suites/storage.sh
index 6eadf4307..4342d83b0 100644
--- a/test/suites/storage.sh
+++ b/test/suites/storage.sh
@@ -202,6 +202,7 @@ test_storage() {
lxc storage create "lxdtest-$(basename "${LXD_DIR}")-valid-lvm-pool-config-pool24" lvm rsync.bwlimit=1024
lxc storage create "lxdtest-$(basename "${LXD_DIR}")-valid-lvm-pool-config-pool25" lvm volume.block.mount_options="rw,strictatime,discard"
lxc storage set "lxdtest-$(basename "${LXD_DIR}")-valid-lvm-pool-config-pool25" volume.block.mount_options "rw,lazytime"
+ lxc storage create "lxdtest-$(basename "${LXD_DIR}")-valid-lvm-pool-config-pool26" lvm volume.block.filesystem=btrfs
fi
# Set default storage pool for image import.
From 8b942c27ff9a203e335ee7950d2e7b3ac27c5c4a Mon Sep 17 00:00:00 2001
From: Alberto Donato <alberto.donato at canonical.com>
Date: Mon, 18 Sep 2017 15:29:51 +0200
Subject: [PATCH 3/3] storage: add storage_block_filesystem_btrfs API extension
Signed-off-by: Alberto Donato <alberto.donato at canonical.com>
---
doc/api-extensions.md | 4 ++++
lxd/api_1.0.go | 1 +
2 files changed, 5 insertions(+)
diff --git a/doc/api-extensions.md b/doc/api-extensions.md
index 35666d77b..404856f80 100644
--- a/doc/api-extensions.md
+++ b/doc/api-extensions.md
@@ -330,3 +330,7 @@ This records the actual source passed to LXD during storage pool creation.
This introduces the "ceph.osd.force_reuse" property for the ceph storage
driver. When set to "true" LXD will reuse a osd storage pool that is already in
use by another LXD instance.
+
+## storage\_block\_filesystem\_btrfs
+This adds support for btrfs as a storage volume filesystem, in addition to ext4
+and xfs.
diff --git a/lxd/api_1.0.go b/lxd/api_1.0.go
index 9f81cc463..7b68acdb3 100644
--- a/lxd/api_1.0.go
+++ b/lxd/api_1.0.go
@@ -125,6 +125,7 @@ func api10Get(d *Daemon, r *http.Request) Response {
"resource_limits",
"storage_volatile_initial_source",
"storage_ceph_force_osd_reuse",
+ "storage_block_filesystem_btrfs",
},
APIStatus: "stable",
APIVersion: version.APIVersion,
More information about the lxc-devel
mailing list