* [pve-devel] [PATCH v2 storage] btrfs: check for btrfs in on_add_hook and activate
@ 2021-06-24 8:45 Wolfgang Bumiller
2021-06-24 9:21 ` [pve-devel] applied: " Thomas Lamprecht
0 siblings, 1 reply; 2+ messages in thread
From: Wolfgang Bumiller @ 2021-06-24 8:45 UTC (permalink / raw)
To: pve-devel
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
---
Changes to v1:
* Fabian's feedback:
* removed on_add_hook since activate_storage is called anyway
* moved btrfs check to after the DirPlugin checks
PVE/Storage/BTRFSPlugin.pm | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/PVE/Storage/BTRFSPlugin.pm b/PVE/Storage/BTRFSPlugin.pm
index 133edc6..dc5894a 100644
--- a/PVE/Storage/BTRFSPlugin.pm
+++ b/PVE/Storage/BTRFSPlugin.pm
@@ -20,6 +20,7 @@ use constant {
FS_NOCOW_FL => 0x00800000,
FS_IOC_GETFLAGS => 0x40086602,
FS_IOC_SETFLAGS => 0x80086601,
+ BTRFS_MAGIC => 0x9123683e,
};
# Configuration (similar to DirPlugin)
@@ -89,9 +90,30 @@ sub check_config {
return PVE::Storage::DirPlugin::check_config($self, $sectionId, $config, $create, $skipSchemaCheck);
}
+my sub getfsmagic($) {
+ my ($path) = @_;
+ # The field type sizes in `struct statfs` are defined in a rather annoying way, and we only
+ # need the first field, which is a `long` for our supported platforms.
+ # Should be moved to pve-rs, so this can be the problem of the `libc` crate ;-)
+ # Just round up and extract what we need:
+ my $buf = pack('x160');
+ if (0 != syscall(&PVE::Syscall::SYS_statfs, $path, $buf)) {
+ die "statfs on '$path' failed - $!\n";
+ }
+
+ return unpack('L!', $buf);
+}
+
+my sub assert_btrfs($) {
+ my ($path) = @_;
+ die "'$path' is not a btrfs file system\n"
+ if getfsmagic($path) != BTRFS_MAGIC;
+}
+
sub activate_storage {
my ($class, $storeid, $scfg, $cache) = @_;
- return PVE::Storage::DirPlugin::activate_storage($class, $storeid, $scfg, $cache);
+ PVE::Storage::DirPlugin::activate_storage($class, $storeid, $scfg, $cache);
+ assert_btrfs($scfg->{path});
}
sub status {
--
2.30.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* [pve-devel] applied: [PATCH v2 storage] btrfs: check for btrfs in on_add_hook and activate
2021-06-24 8:45 [pve-devel] [PATCH v2 storage] btrfs: check for btrfs in on_add_hook and activate Wolfgang Bumiller
@ 2021-06-24 9:21 ` Thomas Lamprecht
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2021-06-24 9:21 UTC (permalink / raw)
To: Proxmox VE development discussion, Wolfgang Bumiller
On 24.06.21 10:45, Wolfgang Bumiller wrote:
> Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
> ---
> Changes to v1:
> * Fabian's feedback:
> * removed on_add_hook since activate_storage is called anyway
> * moved btrfs check to after the DirPlugin checks
>
> PVE/Storage/BTRFSPlugin.pm | 24 +++++++++++++++++++++++-
> 1 file changed, 23 insertions(+), 1 deletion(-)
>
>
applied, thanks! I made a follow-up on top to avoid leaving over sub-directories
form the DirPlugin::activate_storage call in the case that assert_btrfs fails.
----8<----
diff --git a/PVE/Storage/BTRFSPlugin.pm b/PVE/Storage/BTRFSPlugin.pm
index dc5894a..5360dca 100644
--- a/PVE/Storage/BTRFSPlugin.pm
+++ b/PVE/Storage/BTRFSPlugin.pm
@@ -112,8 +112,21 @@ my sub assert_btrfs($) {
sub activate_storage {
my ($class, $storeid, $scfg, $cache) = @_;
- PVE::Storage::DirPlugin::activate_storage($class, $storeid, $scfg, $cache);
- assert_btrfs($scfg->{path});
+
+ my $path = $scfg->{path};
+ if (!defined($scfg->{mkdir}) || $scfg->{mkdir}) {
+ mkpath $path;
+ }
+
+ my $mp = PVE::Storage::DirPlugin::parse_is_mountpoint($scfg);
+ if (defined($mp) && !path_is_mounted($mp, $cache->{mountdata})) {
+ die "unable to activate storage '$storeid' - directory is expected to be a mount point but"
+ ." is not mounted: '$mp'\n";
+ }
+
+ assert_btrfs($path); # only assert this stuff now, ensures $path is there and better UX
+
+ $class->SUPER::activate_storage($storeid, $scfg, $cache);
}
sub status {
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-06-24 9:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-24 8:45 [pve-devel] [PATCH v2 storage] btrfs: check for btrfs in on_add_hook and activate Wolfgang Bumiller
2021-06-24 9:21 ` [pve-devel] applied: " Thomas Lamprecht
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal