* [PATCH] btrfs-progs: add mounted-checking for btrfs-vol
@ 2010-02-02 8:45 Miao Xie
2010-02-02 9:08 ` Wengang Wang
0 siblings, 1 reply; 3+ messages in thread
From: Miao Xie @ 2010-02-02 8:45 UTC (permalink / raw)
To: Chris Mason; +Cc: Linux Btrfs
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] btrfs-progs: add mounted-checking for btrfs-vol
2010-02-02 8:45 [PATCH] btrfs-progs: add mounted-checking for btrfs-vol Miao Xie
@ 2010-02-02 9:08 ` Wengang Wang
2010-02-03 2:11 ` Miao Xie
0 siblings, 1 reply; 3+ messages in thread
From: Wengang Wang @ 2010-02-02 9:08 UTC (permalink / raw)
To: Miao Xie; +Cc: Chris Mason, Linux Btrfs
Hi,
A problem that not in this patch.
On 10-02-02 16:45, Miao Xie wrote:
> 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) {
I think open() returning -1 means an error. So it should be
if (devfd < 0)
instead of
if (!devfd)
regards,
wengang.
> fprintf(stderr, "Unable to open device %s\n", device);
> + exit(1);
> }
> ret = fstat(devfd, &st);
> if (ret) {
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] btrfs-progs: add mounted-checking for btrfs-vol
2010-02-02 9:08 ` Wengang Wang
@ 2010-02-03 2:11 ` Miao Xie
0 siblings, 0 replies; 3+ messages in thread
From: Miao Xie @ 2010-02-03 2:11 UTC (permalink / raw)
To: Wengang Wang; +Cc: Chris Mason, Linux Btrfs
Hi,
on 2010-2-2 17:08, Wengang Wang wrote:
[snip]
>> devfd = open(device, O_RDWR);
>> if (!devfd) {
> I think open() returning -1 means an error. So it should be
> if (devfd < 0)
> instead of
> if (!devfd)
Yes, you are right.
Thanks for your comment. I'll remake a patch.
Regards
Miao
>
> regards,
> wengang.
>> fprintf(stderr, "Unable to open device %s\n", device);
>> + exit(1);
>> }
>> ret = fstat(devfd, &st);
>> if (ret) {
>
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-02-03 2:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-02 8:45 [PATCH] btrfs-progs: add mounted-checking for btrfs-vol Miao Xie
2010-02-02 9:08 ` Wengang Wang
2010-02-03 2:11 ` Miao Xie
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).