From patchwork Tue Jan 29 17:10:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 216605 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id BF11B2C0109 for ; Wed, 30 Jan 2013 04:10:52 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753481Ab3A2RKw (ORCPT ); Tue, 29 Jan 2013 12:10:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42933 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753021Ab3A2RKv (ORCPT ); Tue, 29 Jan 2013 12:10:51 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r0THApaQ021346 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 29 Jan 2013 12:10:51 -0500 Received: from liberator.sandeen.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r0THAnoN031833 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 29 Jan 2013 12:10:50 -0500 Message-ID: <51080299.9040507@redhat.com> Date: Tue, 29 Jan 2013 11:10:49 -0600 From: Eric Sandeen User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 MIME-Version: 1.0 To: ext4 development Subject: [PATCH, RFC V2] mke2fs: wipe out old btrfs superblocks References: <510800B6.4090505@redhat.com> In-Reply-To: <510800B6.4090505@redhat.com> X-Enigmail-Version: 1.5 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org btrfs sticks superblocks at 64k, 64M, and 256G. If we don't overwrite those, libblkid may accidentally identify an ext* filesystem with old btrfs superblocks as btrfs, and we'll be sad. libblkid provides a blkid_wipe_fs() functionality to zero all existing signatures, but that'd break our handy-dandy undo capability, I think. So I'm not sure we have any other choice but to do it ourselves. There is a slight error here in that if the mkfs does not span the entire device, we won't overwrite signatures past the end of the filesystem, but that case should be pretty rare. (The same slight error in logic applies to the existing "wipe old MD superblock" path). Signed-off-by: Eric Sandeen blocksize < 4096) + blocks = 4096 / fs->blocksize; + /* + * Wipe out any old btrfs superblocks, at + * 64k, 64M, and 256G. + */ + start = 64ULL * 1024 / fs->blocksize; + retval += ext2fs_zero_blocks2(fs, start, blocks, NULL, NULL); + start = 64ULL * 1024 * 1024 / fs->blocksize; + if (start + blocks <= ext2fs_blocks_count(fs->super)) + retval += ext2fs_zero_blocks2(fs, start, blocks, NULL, NULL); + start = 256ULL * 1024 * 1024 * 1024 / fs->blocksize; + if (start + blocks <= ext2fs_blocks_count(fs->super)) + retval += ext2fs_zero_blocks2(fs, start, blocks, NULL, NULL); + /* free the static zeroing buffer */ + ext2fs_zero_blocks2(0, 0, 0, 0, 0); + return retval; +} + static void fix_cluster_bg_counts(ext2_filsys fs) { blk64_t cluster, num_clusters, tot_free; @@ -2440,6 +2466,12 @@ int main (int argc, char *argv[]) } } + if (!noaction) { + retval = mke2fs_wipe_btrfs(fs); + if (retval) + printf(_("Failed to wipe old btrfs super locations\n")); + } + sprintf(tdb_string, "tdb_data_size=%d", fs->blocksize <= 4096 ? 32768 : fs->blocksize * 8); io_channel_set_options(fs->io, tdb_string);