From patchwork Mon Aug 24 08:45:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaolei X-Patchwork-Id: 7061811 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 57403C05AC for ; Mon, 24 Aug 2015 08:46:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 75BE8206E9 for ; Mon, 24 Aug 2015 08:46:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6EF3B20211 for ; Mon, 24 Aug 2015 08:46:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753694AbbHXIqp (ORCPT ); Mon, 24 Aug 2015 04:46:45 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:36039 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751980AbbHXIqp (ORCPT ); Mon, 24 Aug 2015 04:46:45 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="99950053" Received: from bogon (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 24 Aug 2015 16:49:54 +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 t7O8kbbK002344 for ; Mon, 24 Aug 2015 16:46:37 +0800 Received: from localhost.localdomain (10.167.226.114) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server id 14.3.181.6; Mon, 24 Aug 2015 16:46:42 +0800 From: Zhao Lei To: CC: Zhao Lei Subject: [PATCH 1/2] btrfs-progs: Introduce btrfs_close_all_devices to close all fs_devices in fs_uuids list Date: Mon, 24 Aug 2015 16:45:02 +0800 Message-ID: <9f0cf7c0a07faefb4f3af86f8e7c63b56a338b7a.1440405874.git.zhaolei@cn.fujitsu.com> X-Mailer: git-send-email 1.8.5.1 MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-8.3 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 more than one fs_devices in fs_uuids list(as mkfs.btrfs), we need close them all before exit. This function is for above propose. Signed-off-by: Zhao Lei --- volumes.c | 11 +++++++++++ volumes.h | 1 + 2 files changed, 12 insertions(+) diff --git a/volumes.c b/volumes.c index f7462c5..ca50f1c 100644 --- a/volumes.c +++ b/volumes.c @@ -198,6 +198,17 @@ again: return 0; } +void btrfs_close_all_devices(void) +{ + struct btrfs_fs_devices *fs_devices; + + while (!list_empty(&fs_uuids)) { + fs_devices = list_entry(fs_uuids.next, struct btrfs_fs_devices, + list); + btrfs_close_devices(fs_devices); + } +} + int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, int flags) { int fd; diff --git a/volumes.h b/volumes.h index 71d5d66..f776131 100644 --- a/volumes.h +++ b/volumes.h @@ -187,6 +187,7 @@ int btrfs_add_device(struct btrfs_trans_handle *trans, int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, int flags); int btrfs_close_devices(struct btrfs_fs_devices *fs_devices); +void btrfs_close_all_devices(void); int btrfs_add_device(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct btrfs_device *device);