From patchwork Wed Feb 3 02:12:44 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao Xie X-Patchwork-Id: 76568 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o132Darm005019 for ; Wed, 3 Feb 2010 02:13:37 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932331Ab0BCCNf (ORCPT ); Tue, 2 Feb 2010 21:13:35 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:55693 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S932244Ab0BCCNf (ORCPT ); Tue, 2 Feb 2010 21:13:35 -0500 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 74D4817011C; Wed, 3 Feb 2010 10:13:34 +0800 (CST) Received: from fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id o132CsKn029147; Wed, 3 Feb 2010 10:12:54 +0800 Received: from [127.0.0.1] (unknown [10.167.141.211]) by fnst.cn.fujitsu.com (Postfix) with ESMTPA id E0555D47AE; Wed, 3 Feb 2010 10:14:56 +0800 (CST) Message-ID: <4B68DB9C.9050501@cn.fujitsu.com> Date: Wed, 03 Feb 2010 10:12:44 +0800 From: Miao Xie Reply-To: miaox@cn.fujitsu.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.5) Gecko/20091204 Thunderbird/3.0 MIME-Version: 1.0 To: Chris Mason , Wengang Wang CC: Linux Btrfs Subject: [PATCH -V2] btrfs-progs: add mounted-checking for btrfs-vol Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Wed, 03 Feb 2010 02:13:37 +0000 (UTC) diff --git a/btrfs-vol.c b/btrfs-vol.c index 8069778..4ed799d 100644 --- a/btrfs-vol.c +++ b/btrfs-vol.c @@ -108,10 +108,24 @@ int main(int ac, char **av) if (device && strcmp(device, "missing") == 0 && cmd == BTRFS_IOC_RM_DEV) { fprintf(stderr, "removing missing devices from %s\n", mnt); - } else if (device) { + } else if (cmd != BTRFS_IOC_BALANCE) { + if (cmd == BTRFS_IOC_ADD_DEV) { + ret = check_mounted(device); + if (ret < 0) { + fprintf(stderr, + "error checking %s mount status\n", + device); + exit(1); + } + if (ret == 1) { + fprintf(stderr, "%s is mounted\n", device); + exit(1); + } + } devfd = open(device, O_RDWR); - if (!devfd) { + if (devfd < 0) { fprintf(stderr, "Unable to open device %s\n", device); + exit(1); } ret = fstat(devfd, &st); if (ret) {