From patchwork Mon Jul 7 01:56:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gui Hecheng X-Patchwork-Id: 4491971 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4A62ABEEAA for ; Mon, 7 Jul 2014 02:02:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8BFD420221 for ; Mon, 7 Jul 2014 02:02:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BC13120220 for ; Mon, 7 Jul 2014 02:02:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752586AbaGGCC3 (ORCPT ); Sun, 6 Jul 2014 22:02:29 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:20298 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752246AbaGGCC2 (ORCPT ); Sun, 6 Jul 2014 22:02:28 -0400 X-IronPort-AV: E=Sophos;i="5.00,846,1396972800"; d="scan'208";a="32911677" Received: from localhost (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 07 Jul 2014 09:59:44 +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 s6722Pt6027532; Mon, 7 Jul 2014 10:02:25 +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:02:30 +0800 From: Gui Hecheng To: CC: , Gui Hecheng Subject: [PATCH v2] btrfs-progs: add mount status check for btrfs-image Date: Mon, 7 Jul 2014 09:56:51 +0800 Message-ID: <1404698211-4236-1-git-send-email-guihc.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <20140703165818.GH1553@twin.jikos.cz> References: <20140703165818.GH1553@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 When btrfs-image run on a mounted filesystem, the undergoing fs operations may change what you have imaged a while ago. In this case, give a warning to remind the user that he may not get a consistent image he wants. Signed-off-by: Gui Hecheng --- changelog: v1->v2: just give a warning if device mounted and let it continue --- btrfs-image.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/btrfs-image.c b/btrfs-image.c index 985aa26..e1d5482 100644 --- a/btrfs-image.c +++ b/btrfs-image.c @@ -2570,10 +2570,18 @@ int main(int argc, char *argv[]) num_threads = 1; } - if (create) + if (create) { + ret = check_mounted(source); + if (ret < 0) { + fprintf(stderr, "Could not check mount status: %s\n", + strerror(-ret)); + exit(1); + } else if (ret) + fprintf(stderr, "WARNING: The device is mounted. Make sure you didn't do modifications.\n"); + ret = create_metadump(source, out, num_threads, compress_level, sanitize, walk_trees); - else + } else ret = restore_metadump(source, out, old_restore, 1, multi_devices); if (ret) {