Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755877AbdDFMDC (ORCPT ); Thu, 6 Apr 2017 08:03:02 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:36402 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755303AbdDFMCy (ORCPT ); Thu, 6 Apr 2017 08:02:54 -0400 From: Dmitry Monakhov To: linux-kernel@vger.kernel.org Cc: darrick.wong@oracle.com, axboe@kernel.dk, tytso@mit.edu, jack@suse.cz, hch@infradead.org, Dmitry Monakhov Subject: [PATCH 0/5] falloc on blockdevice: what possibly can go whong? Date: Thu, 6 Apr 2017 16:02:44 +0400 Message-Id: <1491480169-1889-1-git-send-email-dmonakhov@openvz.org> X-Mailer: git-send-email 1.9.3 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1648 Lines: 33 If you saw a command "fallocate -k -l 1G /dev/vda" you probably think that user want to preallocate space on thin-provision blkdev. Right? What possibly can go wrong? Unfortunately you may destroy your filesystem and kernel panic. The reason is the bug in blkdev_fallocate() which unconditionally truncate bdev cache. But even if we fix this particular bug there are other places where we still have to truncate blkdev cache even if FS is mounted and holds some bh's 1) nbd: If server disconnected we call kill_bdev() which destroy bdev cache 2) bdev falloc{ FALLOC_FL_ZERO_RANGE, FALLOC_FL_PUNCH_HOLE } definitely expect bdev cache to be truncated. 3) ioctl: BLKDISCARD also must truncate bdev cache There is a discussion whenever we have to permit (2) and (3) on bdev with active filesytem, why shouldn't we force bd_claim for this? But this is advisory user-space interface, because by historical reasons we allow direct_io to blkdev while fs is mounted. I prefer to treat all three cases while FS is mounted as runtime errors. Fs may be corrupted, but we should not panic. This patchset guard fs/blk layer from panic in case of such runtime errors. 0001-bh-Prevent-panic-on-invalid-BHs 0002-block-protect-bdevname-from-null-pointer-bdev 0003-bio-Protect-submit_bio-from-bdevless-bio-s 0004-jbd2-use-stable-bdev-pointer # Finally fix the bug with unconditional cache truncate on bdev 0005-block-truncate-page-cache-only-when-necessary-on-falloc Testcases: xfstests: ./check blockdev/004 blockdev/005 https://github.com/dmonakhov/xfstests/tree/blkdev-falloc-tests-v1 TODO: Prepare patch for util-linux fallocate(2) should claim bdev.