[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
Tue Oct 6 11:28:50 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 automcatically in
a non-interactive session
* the -f flag forces a filesystem check even if the fs seems clean
---
src/PVE/CLI/pct.pm | 46 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/src/PVE/CLI/pct.pm b/src/PVE/CLI/pct.pm
index 8c56f89..ae6ec3d 100755
--- a/src/PVE/CLI/pct.pm
+++ b/src/PVE/CLI/pct.pm
@@ -124,6 +124,51 @@ __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_stopped }),
+ force => {
+ optional => 1,
+ type => 'boolean',
+ description => "force checking, even if the filesystem seems clean",
+ default => 0,
+ },
+ },
+ },
+ returns => { type => 'null' },
+ code => sub {
+ my ($param) = @_;
+ my $vmid = $param->{vmid};
+
+ my $conf = PVE::LXC::load_config($vmid);
+ my $storage_cfg = PVE::Cluster::cfs_read_file("storage.cfg");
+
+ # todo: handle optional extra mount points
+ my $rootfs = PVE::LXC::parse_ct_mountpoint($conf->{rootfs});
+ my $path = PVE::Storage::path($storage_cfg, $rootfs->{volume}, undef);
+
+ my $command = ['fsck', $path , '-y'];
+ push(@$command, '-f') if $param->{force};
+
+ #begin critical path: from here we need to lock the container
+ PVE::LXC::lock_aquire($vmid);
+ if (PVE::LXC::check_running($vmid)) {
+ PVE::LXC::lock_release($vmid);
+ die "Cannot run command on active container\n";
+ } else {
+ PVE::Tools::run_command($command);
+ PVE::LXC::lock_release($vmid);
+ }
+
+ return undef;
+ }});
+
our $cmddef = {
list=> [ 'PVE::API2::LXC', 'vmlist', [], { node => $nodename }, sub {
my $res = shift;
@@ -165,6 +210,7 @@ our $cmddef = {
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