[pve-devel] [PATCH manager 2/2] Add createcephfs to pveceph

Thomas Lamprecht t.lamprecht at proxmox.com
Mon Nov 19 17:31:39 CET 2018


On 11/14/18 1:23 PM, Alwin Antreich wrote:
> Signed-off-by: Alwin Antreich <a.antreich at proxmox.com>
> ---
>  PVE/API2/CephFS.pm | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  PVE/CLI/pveceph.pm |  1 +
>  2 files changed, 82 insertions(+)
> 
> diff --git a/PVE/API2/CephFS.pm b/PVE/API2/CephFS.pm
> index b1c32b4f..fd4d7154 100644
> --- a/PVE/API2/CephFS.pm
> +++ b/PVE/API2/CephFS.pm
> @@ -4,6 +4,8 @@ use strict;
>  use warnings;
>  use Cwd qw(abs_path);
>  use PVE::CephTools;
> +use PVE::API2::Ceph;
> +use PVE::API2::Storage::Config;
>  use PVE::RPCEnvironment;
>  use PVE::JSONSchema qw(get_standard_option);
>  use PVE::RADOS;
> @@ -129,3 +131,82 @@ __PACKAGE__->register_method ({
>  	return $rpcenv->fork_worker('cephdestroymds', "mds.$mdsid",  $authuser, $worker);
>      }});
>  
> +__PACKAGE__->register_method ({
> +    name => 'createfs',
> +    path => 'fs',

s/fs// As you specify paths already relative to fs/ (which is registered in API2::Ceph)

This'd make it .../ceph/fs/fs and you have no index telling the API that another fs
subdir exists. But just making it '' let's it work and is probably what you wanted.

> +    method => 'POST',
> +    description => "Create Ceph filesystem",
> +    proxyto => 'node',
> +    protected => 1,
> +    permissions => {
> +	check => ['perm', '/', [ 'Sys.Modify' ]],
> +    },
> +    parameters => {
> +	additionalProperties => 0,
> +	properties => {
> +	    node => get_standard_option('pve-node'),
> +	    name => {
> +		description => "The ceph filesystem name. It must be unique.",

missing:
default => 'cephfs',

> +		type => 'string',
> +		optional => 1,
> +	    },
> +	    pg_num => {
> +		description => "Number of placement groups.",
> +		type => 'integer',
> +		default => 64,
> +		optional => 1,
> +		minimum => 8,
> +		maximum => 32768,
> +	    },
> +	},
> +    },
> +    returns => { type => 'string' },
> +    code => sub {
> +	my ($param) = @_;
> +
> +	PVE::CephTools::check_ceph_inited();
> +
> +	my $pve_ckeyring_path = PVE::CephTools::get_config('pve_ckeyring_path');
> +
> +	die "Ceph is not fully configured - missing '$pve_ckeyring_path'\n"
> +	    if ! -f $pve_ckeyring_path;
> +
> +	my $fs_name = $param->{name} // 'cephfs';
> +	my $pg_num = $param->{pg_num} // 64;
> +
> +	my $rpcenv = PVE::RPCEnvironment::get();
> +	my $user = $rpcenv->get_user();
> +
> +	my $worker = sub {
> +	    my $pool_data = "${fs_name}_data";
> +	    my $pool_meta = "${fs_name}_metadata";
> +
> +	    my $pool_param = {};
> +	    $pool_param->{application} = 'cephfs';
> +	    $pool_param->{node} = $param->{node};
> +
> +	    # create cephfs data pool
> +	    $pool_param->{name} = $pool_data;
> +	    $pool_param->{pg_num} = $pg_num;
> +	    PVE::API2::Ceph->createpool($pool_param);
> +
> +	    # create cephfs metadata pool
> +	    my $meta_pg_num = $pg_num / 4;
> +	    $pool_param->{name} = $pool_meta;
> +	    $pool_param->{pg_num} = ($meta_pg_num >= 8) ? $meta_pg_num : 8;
> +	    PVE::API2::Ceph->createpool($pool_param);

pre-checks if any of this exists and cleanup is missing?

E.g., first pool could be created, second not, then a rollback (removing first again) would
be desired, I guess? Else you may get a "dangling" pool.

> +
> +	    my $rados = PVE::RADOS->new();
> +	    $rados->mon_command({
> +		prefix => "fs new",
> +		fs_name => $fs_name,
> +		metadata => $pool_meta,
> +		data => $pool_data,
> +		format => 'plain',
> +	    });
> +	};
> +
> +	return $rpcenv->fork_worker('cephcreatefs', $fs_name,  $user, $worker);
> +    }});
> +
> +1;
> diff --git a/PVE/CLI/pveceph.pm b/PVE/CLI/pveceph.pm
> index 02ed565e..e2984d02 100755
> --- a/PVE/CLI/pveceph.pm
> +++ b/PVE/CLI/pveceph.pm
> @@ -170,6 +170,7 @@ our $cmddef = {
>      }],
>      createpool => [ 'PVE::API2::Ceph', 'createpool', ['name'], { node => $nodename }],
>      destroypool => [ 'PVE::API2::Ceph', 'destroypool', ['name'], { node => $nodename } ],
> +    createfs => [ 'PVE::API2::CephFS', 'createfs', ['name'], { node => $nodename }],
>      createosd => [ 'PVE::API2::CephOSD', 'createosd', ['dev'], { node => $nodename }, $upid_exit],
>      destroyosd => [ 'PVE::API2::CephOSD', 'destroyosd', ['osdid'], { node => $nodename }, $upid_exit],
>      createmon => [ 'PVE::API2::Ceph', 'createmon', [], { node => $nodename }, $upid_exit],
> 





More information about the pve-devel mailing list