all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Cc: Wolfgang Bumiller <w.bumiller@proxmox.com>
Subject: Re: [pve-devel] [PATCH storage] btrfs: check for btrfs in on_add_hook and activate
Date: Thu, 24 Jun 2021 09:56:58 +0200	[thread overview]
Message-ID: <1624521156.jnauh4rg8d.astroid@nora.none> (raw)
In-Reply-To: <20210624072920.43336-1-w.bumiller@proxmox.com>

On June 24, 2021 9:29 am, Wolfgang Bumiller wrote:
> Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
> ---
>  PVE/Storage/BTRFSPlugin.pm | 30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
> 
> diff --git a/PVE/Storage/BTRFSPlugin.pm b/PVE/Storage/BTRFSPlugin.pm
> index 133edc6..0e111a0 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,8 +90,29 @@ 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) = @_;
> +    assert_btrfs($scfg->{path});
>      return PVE::Storage::DirPlugin::activate_storage($class, $storeid, $scfg, $cache);

shouldn't this be the other way round? first check for things like 
is_mountpoint, then whether btrfs is there.. makes for less confusing 
error message at least..

>  }
>  
> @@ -179,6 +201,14 @@ sub btrfs_cmd {
>      return $msg;
>  }
>  
> +sub on_add_hook {
> +    my ($class, $storeid, $scfg, %param) = @_;
> +
> +    assert_btrfs($scfg->{path});

not needed - adding a new storage calls activate_storage if the storage 
is enabled..

> +
> +    return;
> +}
> +
>  sub btrfs_get_subvol_id {
>      my ($class, $path) = @_;
>      my $info = $class->btrfs_cmd(['subvolume', 'show', '--', $path]);
> -- 
> 2.30.2
> 
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
> 
> 
> 




  reply	other threads:[~2021-06-24  7:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-24  7:29 Wolfgang Bumiller
2021-06-24  7:56 ` Fabian Grünbichler [this message]
2021-06-24  8:43   ` Wolfgang Bumiller
2021-06-24  9:10   ` Thomas Lamprecht
2021-06-24  9:23     ` Fabian Grünbichler
2021-06-24  9:27       ` Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1624521156.jnauh4rg8d.astroid@nora.none \
    --to=f.gruenbichler@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    --cc=w.bumiller@proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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