From: Miao Xie <miaox@cn.fujitsu.com>
To: Chris Mason <chris.mason@oracle.com>
Cc: Linux Btrfs <linux-btrfs@vger.kernel.org>
Subject: [PATCH] btrfs-progs: add mounted-checking for btrfs-vol
Date: Tue, 02 Feb 2010 16:45:58 +0800 [thread overview]
Message-ID: <4B67E646.4050001@cn.fujitsu.com> (raw)
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>
---
btrfs-vol.c | 16 +++++++++++++++-
1 files changed, 15 insertions(+), 1 deletions(-)
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) {
--
1.6.5.2
next reply other threads:[~2010-02-02 8:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-02 8:45 Miao Xie [this message]
2010-02-02 9:08 ` [PATCH] btrfs-progs: add mounted-checking for btrfs-vol Wengang Wang
2010-02-03 2:11 ` Miao Xie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4B67E646.4050001@cn.fujitsu.com \
--to=miaox@cn.fujitsu.com \
--cc=chris.mason@oracle.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.