From patchwork Tue May 5 06:16:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 6335641 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1C5AEBEEE5 for ; Tue, 5 May 2015 06:19:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4CCE420220 for ; Tue, 5 May 2015 06:19:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5E1A32024C for ; Tue, 5 May 2015 06:19:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756079AbbEEGTF (ORCPT ); Tue, 5 May 2015 02:19:05 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:52498 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1756071AbbEEGSz (ORCPT ); Tue, 5 May 2015 02:18:55 -0400 X-IronPort-AV: E=Sophos;i="5.04,848,1406563200"; d="scan'208";a="91655064" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 05 May 2015 14:15:00 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t456HaFr008364 for ; Tue, 5 May 2015 14:17:36 +0800 Received: from localhost.localdomain (10.167.226.33) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Tue, 5 May 2015 14:18:57 +0800 From: Qu Wenruo To: Subject: [PATCH 6/8] btrfs-progs: Introduce change_devices_uuid() function. Date: Tue, 5 May 2015 14:16:44 +0800 Message-ID: <1430806606-3226-7-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.3.7 In-Reply-To: <1430806606-3226-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1430806606-3226-1-git-send-email-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.33] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 This function will change all dev items' fsid. Signed-off-by: Qu Wenruo --- btrfstune.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/btrfstune.c b/btrfstune.c index 6706cd7..8a5b3c2 100644 --- a/btrfstune.c +++ b/btrfstune.c @@ -219,6 +219,49 @@ static int change_device_uuid(struct btrfs_root *root, struct extent_buffer *eb, return ret; } +static int change_devices_uuid(struct btrfs_fs_info *fs_info) +{ + struct btrfs_root *root = fs_info->chunk_root; + struct btrfs_path *path; + struct btrfs_key key = {0, 0, 0}; + int ret = 0; + + /* + * Unlike change_extents_uuid, we only need to change fsid in dev_item + */ + if (!fs_info->new_fsid) + return 0; + + path = btrfs_alloc_path(); + if (!path) + return -ENOMEM; + /* No transaction again */ + ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); + if (ret < 0) + goto out; + + while (1) { + btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]); + if (key.type != BTRFS_DEV_ITEM_KEY || + key.objectid != BTRFS_DEV_ITEMS_OBJECTID) + goto next; + ret = change_device_uuid(root, path->nodes[0], path->slots[0]); + if (ret < 0) + goto out; +next: + ret = btrfs_next_item(root, path); + if (ret < 0) + goto out; + if (ret > 0) { + ret = 0; + goto out; + } + } +out: + btrfs_free_path(path); + return ret; +} + static void print_usage(void) { fprintf(stderr, "usage: btrfstune [options] device\n");