From f1b03ad15110c42b948b331327b6e9040bf18097 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 15 Sep 2019 14:19:35 +0200 Subject: [PATCH] everything ready for pool creation testing --- dirkules/hardware/btrfsTools.py | 14 ++++++++++-- dirkules/manager/viewManager.py | 37 +++++++++++++++++++++++++++++--- dirkules/templates/pool_add.html | 6 +++--- 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/dirkules/hardware/btrfsTools.py b/dirkules/hardware/btrfsTools.py index f0626c8..b4a6663 100644 --- a/dirkules/hardware/btrfsTools.py +++ b/dirkules/hardware/btrfsTools.py @@ -62,5 +62,15 @@ def get_raid(label): return raid_map -def create_pool(): - pass +def create_pool(label, drives, raid, mount_options): + btrfs_drives = "" + for d in drives: + drive_name = "/dev/" + d.name + # stderr and stdout not captured + subprocess.run(["sgdisk", "-Z", drive_name], shell=False, timeout=20, check=True) + subprocess.run(["wipefs", "-a", drive_name], shell=False, timeout=20, check=True) + subprocess.run(["sgdisk", "-o", drive_name], shell=False, timeout=20, check=True) + subprocess.run(["sgdisk", "-N", 1, drive_name], shell=False, timeout=20, check=True) + btrfs_drives = btrfs_drives + drive_name + " " + + subprocess.run(["mkfs.btrfs", "-f", "-L", label, "-d", raid, btrfs_drives], shell=False, timeout=20, check=True) diff --git a/dirkules/manager/viewManager.py b/dirkules/manager/viewManager.py index eb286a6..9a240a3 100644 --- a/dirkules/manager/viewManager.py +++ b/dirkules/manager/viewManager.py @@ -50,19 +50,50 @@ def is_system_drive(drive): return True return False + def create_btrfs_pool(form): - label = form.name.data + label = str(form.name.data) + drives = list() + str_drives = form.drives.data.split(",") + for d in str_drives: + drives.append(Drive.query.filter(Drive.name == d).scalar()) if int(form.raid_config.data) == 1: raid = "single" elif int(form.raid_config.data) == 2: raid = "raid0" elif int(form.raid_config.data) == 3: raid = "raid1" - drives = form.drives.data.split(",") + # if only one drive has been selected: always use single + if len(drives) == 1: + raid = "single" mount_options = ["defaults"] if bool(form.inode_cache.data): mount_options.append("inode_cache") if int(form.space_cache.data) == 2: mount_options.append("space_cache=v1") elif int(form.space_cache.data) == 3: - mount_options.append("space_cache=v2") \ No newline at end of file + mount_options.append("space_cache=v2") + if int(form.compression.data) == 2: + mount_options.append("compress=zlib") + elif int(form.compression.data) == 3: + mount_options.append("compress=lzo") + if pure_ssd(drives) and not pure_hdd(drives): + mount_options.append("ssd") + elif pure_hdd(drives) and not pure_ssd(drives): + mount_options.append("autodefrag") + # now we are ready to create the pool. + # Warning: drives contains objects, not names!! Use drive.name + + +def pure_ssd(drives): + for d in drives: + if d.rota or d.hotplug: + return False + return True + + +def pure_hdd(drives): + for d in drives: + if not d.rota or d.hotplug: + return False + return True diff --git a/dirkules/templates/pool_add.html b/dirkules/templates/pool_add.html index f5463af..27cf1eb 100644 --- a/dirkules/templates/pool_add.html +++ b/dirkules/templates/pool_add.html @@ -43,9 +43,9 @@

Kompression

Hinweis
-

"zlib" ist stabiler und ab btrfs-progs 0.19 verfügbar.
"lzo" ist schneller und leicht - höhere Kompression auf, ist jedoch erst ab Kernel Version 3.x verfügbar. Es kann jedoch zum - einfrieren des Systems führen.

+

ZLIB - langsam, stabil, hohe Kompression
+ LZO - schnelle Kompression, schlechteres Kompressionsverhältnis als ZLIB +

{{ render_field(form.compression) }}