[pve-devel] [PATCH pve-container] Add new pct fsck command, to check the rootfs of a container for consistency

Dietmar Maurer dietmar at proxmox.com
Mon Oct 5 18:20:50 CEST 2015


comments inline:

> On October 5, 2015 at 5:43 PM Emmanuel Kasper <e.kasper at proxmox.com> wrote:
> 
> 
> * 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 }),

completion looks wrong to me - you want all (or all stopped) containers instead.

> +		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";

you need to lock the CT before doing this test.

> +
> +	# 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);

I guess you need to keep the container lock while running fsck. 

And you need to correctly return 'null':

return undef;

> +    }});
> +
>  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 } ],
> -    
> +

Please send a separate patch for white space cleanups.



More information about the pve-devel mailing list