From patchwork Thu Apr 11 09:58:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 2427021 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 7D6A83FD8C for ; Thu, 11 Apr 2013 09:57:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753743Ab3DKJ5r (ORCPT ); Thu, 11 Apr 2013 05:57:47 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:17256 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753703Ab3DKJ5q (ORCPT ); Thu, 11 Apr 2013 05:57:46 -0400 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r3B9v2wZ008390 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 11 Apr 2013 09:57:03 GMT Received: from userz7021.oracle.com (userz7021.oracle.com [156.151.31.85]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r3B9v1c8026390 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Thu, 11 Apr 2013 09:57:02 GMT Received: from abhmt115.oracle.com (abhmt115.oracle.com [141.146.116.67]) by userz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r3B9v0tb000412; Thu, 11 Apr 2013 09:57:00 GMT Received: from wish.sg.oracle.com (/10.186.101.18) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 11 Apr 2013 02:57:00 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH] btrfs-progs: avoid ioctl for multipath-dev with its non-multipath path Date: Thu, 11 Apr 2013 17:58:33 +0800 Message-Id: <1365674313-4482-1-git-send-email-anand.jain@oracle.com> X-Mailer: git-send-email 1.8.1.164.g2d0029e In-Reply-To: <1365141303-10571-1-git-send-email-anand.jain@oracle.com> References: <1365141303-10571-1-git-send-email-anand.jain@oracle.com> X-Source-IP: acsinet21.oracle.com [141.146.126.237] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We should avoid using non multi-path (mp) path for mp disks As of now there is no good way (like api) to check that. A workaround way is to check if the O_EXCL open is unsuccessful. This is safe since otherwise the BTRFS_IOC_SCAN_DEV ioctl would fail if the disk-path can not be opened with the flag O_EXCL set. Signed-off-by: Anand Jain --- utils.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/utils.c b/utils.c index 3308668..0231677 100644 --- a/utils.c +++ b/utils.c @@ -1105,6 +1105,13 @@ again: if (!S_ISBLK(st.st_mode)) { continue; } + + /* Do not test for O_EXCL here since btrfs when + * mounted will open with O_EXCL, and if we don't + * allow btrfs_scan_one_device pass thru + * btrfs fi show will not show the btrfs fs which + * are mounted + */ fd = open(fullpath, O_RDONLY); if (fd < 0) { /* ignore the following errors: @@ -1122,10 +1129,18 @@ again: &num_devices, BTRFS_SUPER_INFO_OFFSET, 0ull); + close(fd); + if (ret == 0 && flags & BTRFS_SCAN_REGISTER) { + /* Test if the dev is already opened with O_EXCL flag + * if yes then no need to call ioctl since the + * ioctl will anyway fail. + */ + fd = open(fullpath, O_RDONLY|O_EXCL); + if (fd < 0) continue; + close(fd); btrfs_register_one_device(fullpath); } - close(fd); } if (!list_empty(&pending_list)) { free(pending); @@ -1444,6 +1459,12 @@ scan_again: continue; } + /* Do not test for O_EXCL here since btrfs when + * mounted will open with O_EXCL, and if we don't + * allow btrfs_scan_one_device pass thru + * btrfs fi show will not show the btrfs fs which + * are mounted + */ fd = open(fullpath, O_RDONLY); if (fd < 0) { fprintf(stderr, "failed to open %s: %s\n", @@ -1455,6 +1476,13 @@ scan_again: BTRFS_SUPER_INFO_OFFSET, 0ull); if (ret == 0 && flags & BTRFS_SCAN_REGISTER) { + /* Test if the dev is already opened with O_EXCL flag + * if yes then no need to call ioctl since the + * ioctl will anyway fail. + */ + fd = open(fullpath, O_RDONLY|O_EXCL); + if (fd < 0) continue; + close(fd); btrfs_register_one_device(fullpath); } close(fd);