[Devel] [PATCH hci-8.1 v2 1/1] block: let container root set the block size of and flush its device

Konstantin Khorenko khorenko at virtuozzo.com
Thu Oct 29 18:49:51 MSK 2026


On 10/23/26 12:52, Pavel Tikhomirov wrote:
> On 10/22/26 04:25, Eva Kurchatova wrote:
>>  static int blkdev_flushbuf(struct block_device *bdev, unsigned cmd,
>>  		unsigned long arg)
>>  {
>> -	if (!capable(CAP_SYS_ADMIN))
>> +	if (!blkdev_admin_capable(bdev))
>>  		return -EACCES;
>>  
>>  	mutex_lock(&bdev->bd_holder_lock);
>> -	if (bdev->bd_holder_ops && bdev->bd_holder_ops->sync)
>> +	if (bdev->bd_holder_ops && bdev->bd_holder_ops->sync) {
>> +		/* A filesystem on the device is synced by its own mount, not from a container */
>> +		if (!ve_is_super(get_exec_env())) {
>> +			mutex_unlock(&bdev->bd_holder_lock);
>> +			return -EBUSY;
>> +		}
>>  		bdev->bd_holder_ops->sync(bdev);
> 
> This looks a bit overprotective, if we allow writing to this disk directly, why not allow syncing it directly, mounted fs or not.
> 
> Not a blocker though, fine either way.
> 
> Reviewed-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>

> This looks a bit overprotective, if we allow writing to this disk
> directly, why not allow syncing it directly, mounted fs or not.

Agreed, we will open this path.

It is reachable only with a device cgroup write grant on that very
device, bdev_permission(BLK_OPEN_WRITE) is checked at ioctl time. CT
disks from vzctl have W (write for mount only), so they stay at -EACCES.

With a write grant the CT can already overwrite the filesystem under
the mount. Forcing its writeback is strictly less than that.

fs_bdev_sync() is what syncfs() does: sync_filesystem() under s_umount
shared, with bd_holder_lock dropped before. Nothing the host does not
already get from any syncfs() on that mount.

invalidate_bdev() drops clean pages only, the dirty ones went through
the sync first, and busy buffers of a mounted fs are skipped. The cost
is a metadata re-read, not data.

The only thing it bypasses is the VE sync filter in ksys_sync(), and
raw write access to the device makes that filter moot anyway. On the
CT's own mounted loop it restores host parity: blockdev --flushbufs
behaves as on the host.

> Not a blocker though, fine either way.
>
> Reviewed-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>

Thanks.


--
Best regards,

Konstantin Khorenko,
Virtuozzo Linux Kernel Team


More information about the Devel mailing list