From patchwork Mon Jul 7 01:54:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gui Hecheng X-Patchwork-Id: 4491941 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7F14C9F1AC for ; Mon, 7 Jul 2014 02:00:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A10AA20222 for ; Mon, 7 Jul 2014 02:00:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BBEA920225 for ; Mon, 7 Jul 2014 02:00:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752768AbaGGCAe (ORCPT ); Sun, 6 Jul 2014 22:00:34 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:39592 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752136AbaGGCAc (ORCPT ); Sun, 6 Jul 2014 22:00:32 -0400 X-IronPort-AV: E=Sophos;i="5.00,846,1396972800"; d="scan'208";a="32911542" Received: from localhost (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 07 Jul 2014 09:57:47 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s6720Te5027346; Mon, 7 Jul 2014 10:00:29 +0800 Received: from localhost.localdomain (10.167.226.111) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Mon, 7 Jul 2014 10:00:33 +0800 From: Gui Hecheng To: CC: , Gui Hecheng Subject: [PATCH v2] btrfs-progs: add ask_user confirmation for btrfstune clear seeding flag Date: Mon, 7 Jul 2014 09:54:52 +0800 Message-ID: <1404698093-4149-1-git-send-email-guihc.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <20140703165145.GG1553@twin.jikos.cz> References: <20140703165145.GG1553@twin.jikos.cz> MIME-Version: 1.0 X-Originating-IP: [10.167.226.111] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If we do the following: # mkfs.btrfs -f # mount # dd if=/dev/urandom of=/data bs=1M count=100 # umount # btrfstune -S 1 <--- make seeding device # mount # btrfs dev add -f # umount # btrfstune -S 0 <--- clear seeding flag # mount <=== new device not mountable When mounting the new device, btrfs will check whether the seeding flag is set when try to open seeding device. If the user clears the seeding flag of the seeding device, the new device will not be mountable. Even set the seeding flag back will not recovery this problem, because the generation has been changed. So clear the seeding flag has the chance to damage the derived new fs. So I add user confirmation check when clearing seeding flag. Signed-off-by: Gui Hecheng --- changelog v1->v2: add certain scenario description --- btrfstune.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/btrfstune.c b/btrfstune.c index 3f2f0cd..0895204 100644 --- a/btrfstune.c +++ b/btrfstune.c @@ -56,6 +56,7 @@ static int update_seeding_flag(struct btrfs_root *root, int set_flag) return 1; } super_flags &= ~BTRFS_SUPER_FLAG_SEEDING; + fprintf(stderr, "Warning: Seeding flag cleared.\n"); } trans = btrfs_start_transaction(root, 1); @@ -103,6 +104,7 @@ static void print_usage(void) fprintf(stderr, "\t-S value\tpositive value will enable seeding, zero to disable, negative is not allowed\n"); fprintf(stderr, "\t-r \t\tenable extended inode refs\n"); fprintf(stderr, "\t-x \t\tenable skinny metadata extent refs\n"); + fprintf(stderr, "\t-f \t\tforce to clear flags, make sure that you are aware of the dangers\n"); } int main(int argc, char *argv[]) @@ -113,11 +115,12 @@ int main(int argc, char *argv[]) int seeding_flag = 0; u64 seeding_value = 0; int skinny_flag = 0; + int force = 0; int ret; optind = 1; while(1) { - int c = getopt(argc, argv, "S:rx"); + int c = getopt(argc, argv, "S:rxf"); if (c < 0) break; switch(c) { @@ -131,6 +134,9 @@ int main(int argc, char *argv[]) case 'x': skinny_flag = 1; break; + case 'f': + force = 1; + break; default: print_usage(); return 1; @@ -169,6 +175,15 @@ int main(int argc, char *argv[]) } if (seeding_flag) { + if (!seeding_value && !force) { + fprintf(stderr, "Warning: This is dangerous, clearing the seeding flag may cause the derived device not to be mountable!\n"); + ret = ask_user("We are going to clear the seeding flag, are you sure?"); + if (!ret) { + fprintf(stderr, "Clear seeding flag canceled\n"); + return 1; + } + } + ret = update_seeding_flag(root, seeding_value); if (!ret) success++;