From patchwork Tue May 5 06:16:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 6335631 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 365B9BEEE1 for ; Tue, 5 May 2015 06:19:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5B78720220 for ; Tue, 5 May 2015 06:19:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8BDFA20225 for ; Tue, 5 May 2015 06:19:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932792AbbEEGTA (ORCPT ); Tue, 5 May 2015 02:19:00 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:23855 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752624AbbEEGSx (ORCPT ); Tue, 5 May 2015 02:18:53 -0400 X-IronPort-AV: E=Sophos;i="5.04,848,1406563200"; d="scan'208";a="91655061" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 05 May 2015 14:14:59 +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 t456HZRP008357 for ; Tue, 5 May 2015 14:17:35 +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:56 +0800 From: Qu Wenruo To: Subject: [PATCH 5/8] btrfs-progs: Introduce function change_device_uuid(). Date: Tue, 5 May 2015 14:16:43 +0800 Message-ID: <1430806606-3226-6-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 just change a device item's uuid. Signed-off-by: Qu Wenruo --- btrfstune.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/btrfstune.c b/btrfstune.c index 9c1b7aa..6706cd7 100644 --- a/btrfstune.c +++ b/btrfstune.c @@ -198,6 +198,27 @@ out: return ret; } +static int change_device_uuid(struct btrfs_root *root, struct extent_buffer *eb, + int slot) +{ + struct btrfs_fs_info *fs_info = root->fs_info; + struct btrfs_dev_item *di; + int ret = 0; + + di = btrfs_item_ptr(eb, slot, struct btrfs_dev_item); + if (fs_info->new_fsid) { + if (!memcmp_extent_buffer(eb, fs_info->new_fsid, + (unsigned long)btrfs_device_fsid(di), + BTRFS_FSID_SIZE)) + return ret; + write_extent_buffer(eb, fs_info->new_fsid, + (unsigned long)btrfs_device_fsid(di), + BTRFS_FSID_SIZE); + ret = write_tree_block(NULL, root, eb); + } + return ret; +} + static void print_usage(void) { fprintf(stderr, "usage: btrfstune [options] device\n");