]>
git.proxmox.com Git - pve-storage.git/blob - PVE/API2/Disks/LVMThin.pm
1 package PVE
::API2
::Disks
::LVMThin
;
6 use PVE
::Storage
::LvmThinPlugin
;
8 use PVE
::JSONSchema
qw(get_standard_option);
9 use PVE
::API2
::Storage
::Config
;
11 use PVE
::Tools
qw(run_command lock_file);
13 use PVE
::RPCEnvironment
;
16 use base
qw(PVE::RESTHandler);
18 __PACKAGE__-
>register_method ({
25 check
=> ['perm', '/', ['Sys.Audit', 'Datastore.Audit'], any
=> 1],
27 description
=> "List LVM thinpools",
29 additionalProperties
=> 0,
31 node
=> get_standard_option
('pve-node'),
41 description
=> 'The name of the thinpool.',
45 description
=> 'The size of the thinpool in bytes.',
49 description
=> 'The used bytes of the thinpool.',
53 description
=> 'The size of the metadata lv in bytes.',
57 description
=> 'The used bytes of the metadata lv.',
64 return PVE
::Storage
::LvmThinPlugin
::list_thinpools
(undef);
67 __PACKAGE__-
>register_method ({
74 check
=> ['perm', '/', ['Sys.Modify', 'Datastore.Allocate']],
76 description
=> "Create an LVM thinpool",
78 additionalProperties
=> 0,
80 node
=> get_standard_option
('pve-node'),
81 name
=> get_standard_option
('pve-storage-id'),
84 description
=> 'The block device you want to create the thinpool on.',
87 description
=> "Configure storage using the thinpool.",
94 returns
=> { type
=> 'string' },
98 my $rpcenv = PVE
::RPCEnvironment
::get
();
99 my $user = $rpcenv->get_user();
101 my $name = $param->{name
};
102 my $dev = $param->{device
};
103 my $node = $param->{node
};
105 $dev = PVE
::Diskmanage
::verify_blockdev_path
($dev);
106 PVE
::Diskmanage
::assert_disk_unused
($dev);
107 PVE
::Storage
::assert_sid_unused
($name) if $param->{add_storage
};
110 PVE
::Diskmanage
::locked_disk_action
(sub {
111 PVE
::Diskmanage
::assert_disk_unused
($dev);
113 PVE
::Storage
::LVMPlugin
::lvm_create_volume_group
($dev, $name);
114 my $pv = PVE
::Storage
::LVMPlugin
::lvm_pv_info
($dev);
115 # keep some free space just in case
116 my $datasize = $pv->{size
} - 128*1024;
117 # default to 1% for metadata
118 my $metadatasize = $datasize/100;
119 # but at least 1G, as recommended in lvmthin man
120 $metadatasize = 1024*1024 if $metadatasize < 1024*1024;
121 # but at most 16G, which is the current lvm max
122 $metadatasize = 16*1024*1024 if $metadatasize > 16*1024*1024;
123 # shrink data by needed amount for metadata
124 $datasize -= 2*$metadatasize;
128 '--type', 'thin-pool',
130 '--poolmetadatasize', "${metadatasize}K",
135 # FIXME: Remove once we depend on systemd >= v249.
136 # Work around udev bug https://github.com/systemd/systemd/issues/18525 to ensure the
137 # udev database is updated.
138 eval { run_command
(['udevadm', 'trigger', $dev]); };
141 if ($param->{add_storage
}) {
142 my $storage_params = {
147 content
=> 'rootdir,images',
151 PVE
::API2
::Storage
::Config-
>create($storage_params);
156 return $rpcenv->fork_worker('lvmthincreate', $name, $user, $worker);