From patchwork Thu Sep 4 02:27:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 4842201 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A4E7D9F314 for ; Thu, 4 Sep 2014 02:27:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CE9C42020F for ; Thu, 4 Sep 2014 02:27:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B035420200 for ; Thu, 4 Sep 2014 02:27:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756693AbaIDC1v (ORCPT ); Wed, 3 Sep 2014 22:27:51 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:19679 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1750908AbaIDC1u (ORCPT ); Wed, 3 Sep 2014 22:27:50 -0400 X-IronPort-AV: E=Sophos;i="5.04,462,1406563200"; d="scan'208";a="35491808" Received: from localhost (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 04 Sep 2014 10:24:53 +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 s842RkIx002434 for ; Thu, 4 Sep 2014 10:27:46 +0800 Received: from adam-work.lan (10.167.226.33) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Thu, 4 Sep 2014 10:27:48 +0800 From: Qu Wenruo To: Subject: [PATCH] btrfs-progs: fix find_mount_root() to handle duplicated mount point correctly Date: Thu, 4 Sep 2014 10:27:48 +0800 Message-ID: <1409797668-11870-1-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.1.0 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=-8.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 Original find_mount_root() will use the first mount point match and return it. It was OK until the following commit, which will also check the fstype: de22c28ef31d9721606ba059 btrfs-progs: Check fstype in find_mount_root() With fstype check, we should check the last match, not only the first one. Or the following mount will not pass the find_mount_root(): /dev/sdc on /mnt/test type ext4 (rw,relatime,data=ordered) /dev/sdb on /mnt/test type btrfs (rw,relatime,space_cache) This patch will use the last match to do the fstype check. Reported-by: Remco Hosman Signed-off-bu: Remco Hosman Signed-off-by: Qu Wenruo Reviewed-by: Omar Sandoval --- utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils.c b/utils.c index 6c09366..6a16b06 100644 --- a/utils.c +++ b/utils.c @@ -2359,8 +2359,8 @@ int find_mount_root(const char *path, char **mount_root) while ((ent = getmntent(mnttab))) { len = strlen(ent->mnt_dir); if (strncmp(ent->mnt_dir, path, len) == 0) { - /* match found */ - if (longest_matchlen < len) { + /* match found and use the latest match */ + if (longest_matchlen <= len) { free(longest_match); longest_matchlen = len; longest_match = strdup(ent->mnt_dir);