btrfs-progs: add mounted-checking for btrfs-vol
PATCH 1/1 btrfs-progs: 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 <[email protected]>
--- btrfs-vol.c | 16 +++++++++++++++- 1 files changed, 15 insertions(+), 1 deletions(-)
btrfs-vol.c +15 -1
@@ -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) {
Signature · 1 line
1.6.5.2
Hi,
A problem that not in this patch.
Quoted 23 lines · Miao Xie
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 <[email protected]>--- btrfs-vol.c | 16 +++++++++++++++- 1 files changed, 15 insertions(+), 1 deletions(-)btrfs-vol.c +6
-1@@ -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",
btrfs-vol.c int main(int ac, char **av) · line 126
Quoted 10 lines
btrfs-vol.c +8
-0+ 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.
Quoted 5 lines
btrfs-vol.c +1
-0fprintf (stderr,"Unable to open device %s\n" , device); +exit (1 ); } ret =fstat (devfd, &st);if (ret) {
Hi,
on 2010-2-2 17:08, Wengang Wang wrote:
[snip]
Quoted 6 lines
btrfs-vol.c int main(int ac, char **av) · line 126
Quoted 2 lines
btrfs-vol.c +0
-0devfd =open (device,O_RDWR );if (!devfd) {I think
open()returning -1 means an error. So it should beif (devfd < 0) instead of if (!devfd)
Yes, you are right.
Thanks for your comment. I'll remake a patch.
Regards
Miao
Quoted 11 lines
regards,
wengang.Quoted 5 lines
btrfs-vol.c +1
-0fprintf (stderr,"Unable to open device %s\n" , device); +exit (1 ); } ret =fstat (devfd, &st);if (ret) {