summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiao Xie <miaox@cn.fujitsu.com>2010-09-09 13:41:47 +0800
committerChris Mason <chris.mason@oracle.com>2010-09-23 20:26:49 -0400
commitddf85067bbf93408690465a5f88e208f70889130 (patch)
treecddb7a75274094a17bb9aa5bb3a171bf604baf84
parent595cb1df15c47ffc9f119d7c3f5e3717d2b5c04d (diff)
downloadbtrfs-progs-ddf85067bbf93408690465a5f88e208f70889130.tar.gz
add mounted-checking for btrfs-vol
Adding a mounted device is dangerous because it will destroy the filesystem on that mounted device. So we add mounted-checking for btrfs-vol. Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
-rw-r--r--btrfs-vol.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/btrfs-vol.c b/btrfs-vol.c
index 80697783..4ed799d2 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) {