From patchwork Wed Aug 26 14:03:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaolei X-Patchwork-Id: 7077731 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 5821DC05AC for ; Wed, 26 Aug 2015 14:39:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 84094208D8 for ; Wed, 26 Aug 2015 14:39:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BB945208E2 for ; Wed, 26 Aug 2015 14:39:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756597AbbHZOFV (ORCPT ); Wed, 26 Aug 2015 10:05:21 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:64775 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1756359AbbHZOFT (ORCPT ); Wed, 26 Aug 2015 10:05:19 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="100045100" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 26 Aug 2015 22:08:24 +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 t7QE58NE026801 for ; Wed, 26 Aug 2015 22:05:08 +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; Wed, 26 Aug 2015 22:05:14 +0800 From: Zhao Lei To: CC: Zhao Lei Subject: [PATCH 1/4] btrfs-progs: Fix infinite loop of btrfs subvolumn sync Date: Wed, 26 Aug 2015 22:03:36 +0800 Message-ID: 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 We can trigger the bug by following operation: (no wait between commands 3~5) btrfs subvolume create /mnt/btrfs/mysubvol btrfs subvolume snapshot /mnt/btrfs/mysubvol /mnt/btrfs/mysubvol_snap btrfs subvolume delete /mnt/btrfs/mysubvol_snap btrfs subvolume delete /mnt/btrfs/mysubvol btrfs subvolume sync /mnt/btrfs The last command will not exit. Reason: List of "deleted subvolumes" are not currectly set. It caused by a typo of value assign, in detail: *ids[idx] = sh->offset; should be: (*ids)[idx] = sh->offset; So only first element is set to right memory address. If there are multiple "deleted subvolumes", program will keep wait. Above typo also caused some segment fault in my test. This patch fixed above bug. Signed-off-by: Zhao Lei --- cmds-subvolume.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmds-subvolume.c b/cmds-subvolume.c index 61f08f5..8e8d019 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -1207,7 +1207,7 @@ static int enumerate_dead_subvols(int fd, int count, u64 **ids) off += sizeof(*sh); if (sh->type == BTRFS_ORPHAN_ITEM_KEY) { - *ids[idx] = sh->offset; + (*ids)[idx] = sh->offset; idx++; if (idx >= count) { u64 *newids;