From patchwork Tue Feb 2 08:45:58 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao Xie X-Patchwork-Id: 76340 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 o128ktDo023223 for ; Tue, 2 Feb 2010 08:46:56 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753157Ab0BBIqw (ORCPT ); Tue, 2 Feb 2010 03:46:52 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:49187 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1750884Ab0BBIqw (ORCPT ); Tue, 2 Feb 2010 03:46:52 -0500 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 7387317003F; Tue, 2 Feb 2010 16:46:50 +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 o128kB3x014468; Tue, 2 Feb 2010 16:46:11 +0800 Received: from [127.0.0.1] (unknown [10.167.141.211]) by fnst.cn.fujitsu.com (Postfix) with ESMTPA id 800BAD47AE; Tue, 2 Feb 2010 16:48:12 +0800 (CST) Message-ID: <4B67E646.4050001@cn.fujitsu.com> Date: Tue, 02 Feb 2010 16:45:58 +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 CC: Linux Btrfs Subject: [PATCH] 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]); Tue, 02 Feb 2010 08:46:56 +0000 (UTC) diff --git a/btrfs-vol.c b/btrfs-vol.c index 8069778..f781c06 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) { fprintf(stderr, "Unable to open device %s\n", device); + exit(1); } ret = fstat(devfd, &st); if (ret) {