[pve-devel] [PATCH pve-container] Add new pct fsck command, to check the rootfs of a container for consistency
Emmanuel Kasper
e.kasper at proxmox.com
Mon Oct 5 17:43:18 CEST 2015
* the filesystem specific command will be called automatically by fsck (at the moment ext4)
* the -y flag ensures that the filesystem can be fixed automcaticall in
a non-interactive session
* the -f flag forces a filesystem check if it detected as clean
---
src/PVE/CLI/pct.pm | 46 ++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 42 insertions(+), 4 deletions(-)
diff --git a/src/PVE/CLI/pct.pm b/src/PVE/CLI/pct.pm
index 8c56f89..bf453c3 100755
--- a/src/PVE/CLI/pct.pm
+++ b/src/PVE/CLI/pct.pm
@@ -124,6 +124,43 @@ __PACKAGE__->register_method ({
exec('lxc-attach', '-n', $param->{vmid}, '--', @{$param->{'extra-args'}});
}});
+ __PACKAGE__->register_method ({
+ name => 'fsck',
+ path => 'fsck',
+ method => 'PUT',
+ description => "Run a filesystem check on the container root filesystem",
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid_running }),
+ force => {
+ optional => 1,
+ type => 'boolean',
+ description => "force checking, even if the filesystem seems clean",
+ default => 0,
+ },
+ },
+ },
+ returns => { type => 'null' },
+
+ code => sub {
+ my ($param) = @_;
+
+ my $conf = PVE::LXC::load_config($param->{vmid});
+ my $storage_cfg = PVE::Cluster::cfs_read_file("storage.cfg");
+
+ PVE::LXC::check_running($param->{vmid}) && die "Cannot run command on active container";
+
+ # todo: handle optional extra mount points
+ my $rootfs = PVE::LXC::parse_ct_mountpoint($conf->{rootfs});
+ my $volume_id = $rootfs->{volume};
+ my $path = PVE::Storage::path($storage_cfg, $volume_id, undef);
+
+ my $command = ['fsck', $path , '-y'];
+ push(@$command, '-f') if $param->{force};
+ PVE::Tools::run_command($command);
+ }});
+
our $cmddef = {
list=> [ 'PVE::API2::LXC', 'vmlist', [], { node => $nodename }, sub {
my $res = shift;
@@ -149,7 +186,7 @@ our $cmddef = {
set => [ 'PVE::API2::LXC::Config', 'update_vm', ['vmid'], { node => $nodename }],
resize => [ "PVE::API2::LXC::Config", 'resize_vm', ['vmid', 'disk', 'size'], { node => $nodename } ],
-
+
create => [ 'PVE::API2::LXC', 'create_vm', ['vmid', 'ostemplate'], { node => $nodename }, $upid_exit ],
restore => [ 'PVE::API2::LXC', 'create_vm', ['vmid', 'ostemplate'], { node => $nodename, restore => 1 }, $upid_exit ],
@@ -158,14 +195,15 @@ our $cmddef = {
resume => [ 'PVE::API2::LXC::Status', 'vm_resume', ['vmid'], { node => $nodename }, $upid_exit],
shutdown => [ 'PVE::API2::LXC::Status', 'vm_shutdown', ['vmid'], { node => $nodename }, $upid_exit],
stop => [ 'PVE::API2::LXC::Status', 'vm_stop', ['vmid'], { node => $nodename }, $upid_exit],
-
+
migrate => [ "PVE::API2::LXC", 'migrate_vm', ['vmid', 'target'], { node => $nodename }, $upid_exit],
-
+
console => [ __PACKAGE__, 'console', ['vmid']],
enter => [ __PACKAGE__, 'enter', ['vmid']],
unlock => [ __PACKAGE__, 'unlock', ['vmid']],
exec => [ __PACKAGE__, 'exec', ['vmid', 'extra-args']],
-
+ fsck => [ __PACKAGE__, 'fsck', ['vmid']],
+
destroy => [ 'PVE::API2::LXC', 'destroy_vm', ['vmid'],
{ node => $nodename }, $upid_exit ],
--
2.1.4
More information about the pve-devel
mailing list