Skip to contentSkip to conversation

Btrfs-progs: save us an unnecessary ioctl call

PATCH In review Wang Shilong 5 participants 14 messages May 13, 2014 – May 16, 2014 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs-progs: save us an unnecessary ioctl call

Btrfs device id start from 1, not 0.

---
 utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
utils.c +1 -1
index 560c557..d480353 100644
@@ -1765,7 +1765,7 @@ int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args,
 		goto out;
 	}
 
-	for (; i <= fi_args->max_id; ++i) {
+	for (i = 1; i <= fi_args->max_id; ++i) {
 		BUG_ON(ndevs >= fi_args->num_devices);
 		ret = get_device_info(fd, i, &di_args[ndevs]);
 		if (ret == -ENODEV)
Signature · 1 line
1.8.2.1
#1 lore raw

PATCH 1/1 Btrfs: set right total device count for seeding support

Seeding device support allows us to create a new filesystem based on existed filesystem.

However newly created filesystem's @total_devices should include seed devices. This patch fix the following problem:

 # mkfs.btrfs -f /dev/sdb
 # btrfstune -S 1 /dev/sdb
 # mount /dev/sdb /mnt
 # btrfs device add -f /dev/sdc /mnt --->fs_devices->total_devices = 1
 # umount /mnt
 # mount /dev/sdc /mnt               --->fs_devices->total_devices = 2

This is because we record right @total_devices in superblock, but @fs_devices->total_devices is reset to be 0 in btrfs_prepare_sprout().

Fix this problem by not resetting @fs_devices->total_devices.

---
 fs/btrfs/volumes.c | 1 -
 1 file changed, 1 deletion(-)
fs/btrfs/volumes.c +0 -1
index 6fd7fe6..19b2d32 100644
@@ -1883,7 +1883,6 @@ static int btrfs_prepare_sprout(struct btrfs_root *root)
 	fs_devices->seeding = 0;
 	fs_devices->num_devices = 0;
 	fs_devices->open_devices = 0;
-	fs_devices->total_devices = 0;
 	fs_devices->seed = seed_devices;
 
 	generate_random_uuid(fs_devices->fsid);
Signature · 1 line
1.8.2.1
#7 lore raw
In reply to Wang Shilong
Quoted 12 lines · Wang Shilong

Btrfs device id start from 1, not 0.

---
 utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
utils.c +0 -0
index 560c557..d480353 100644

utils.c int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args, · line 1766

Quoted 2 lines
utils.c +0 -0
@@ -1765,7 +1765,7 @@ int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args,
 		goto out;
 	}

You've not seen the two assignments in get_fs_info() above the lines that you change:

        if (is_block_device(path)) {
                ...
                fi_args->max_id = devid;
                i = devid;
Quoted 6 lines
utils.c +1 -1
-	for (; i <= fi_args->max_id; ++i) {
+	for (i = 1; i <= fi_args->max_id; ++i) {
 		BUG_ON(ndevs >= fi_args->num_devices);
 		ret = get_device_info(fd, i, &di_args[ndevs]);
 		if (ret == -ENODEV)
#8 lore raw
Quoted 18 lines · Stefan Behrens
Quoted 12 lines · Wang Shilong

Btrfs device id start from 1, not 0.

---
  utils.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
utils.c +0 -0
index 560c557..d480353 100644

utils.c int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args, · line 1766

Quoted 2 lines
utils.c +0 -0
@@ -1765,7 +1765,7 @@ int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args,
  		goto out;
  	}

You've not seen the two assignments in get_fs_info() above the lines that you change:

Quoted 4 lines
         if (is_block_device(path)) {
                 ...
                 fi_args->max_id = devid;
                 i = devid;

Oops, i did not see this one, but this condition may not meet, so i guess the right fix is to set i=1 when declaration, something like:

int i = 1;

Quoted 13 lines

utils.c int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args, · line 1771

Quoted 7 lines
utils.c +1 -1
-	for (; i <= fi_args->max_id; ++i) {
+	for (i = 1; i <= fi_args->max_id; ++i) {
  		BUG_ON(ndevs >= fi_args->num_devices);
  		ret = get_device_info(fd, i, &di_args[ndevs]);
  		if (ret == -ENODEV)

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#9 lore raw
In reply to Wang Shilong
Quoted 3 lines

Btrfs device id start from 1, not 0.

That was an intentional change.

50275ba btrfs-progs: there is devid 0 when replace is running

Quoted 20 lines
---
  utils.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
utils.c +1 -1
index 560c557..d480353 100644
@@ -1765,7 +1765,7 @@ int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args,
  		goto out;
  	}
 
-	for (; i <= fi_args->max_id; ++i) {
+	for (i = 1; i <= fi_args->max_id; ++i) {
  		BUG_ON(ndevs >= fi_args->num_devices);
  		ret = get_device_info(fd, i, &di_args[ndevs]);
  		if (ret == -ENODEV)
#10 lore raw
In reply to Wang Shilong

utils.c int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args, · line 1768

Quoted 10 lines · Wang Shilong

Btrfs device id start from 1, not 0.

utils.c +1 -1
@@ -1765,7 +1765,7 @@ int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args,
 		goto out;
 	}
 
-	for (; i <= fi_args->max_id; ++i) {
+	for (i = 1; i <= fi_args->max_id; ++i) {

You're right about the device id start, but forcing 1 here breaks the case when get_fs_info is called with block device as an argument and 'i' is set to the devid a few lines above.

Initializing i to 1 in the declaration block is the right fix IMO, and as this is a trivial change I'll do that myself, no need to resend.

Quoted 3 lines
utils.c +0 -0
 		BUG_ON(ndevs >= fi_args->num_devices);
 		ret = get_device_info(fd, i, &di_args[ndevs]);
 		if (ret == -ENODEV)
#11 lore raw

David,

As mentioned, this patch will back-out the earlier patch

50275bacab0f62b91453fbfa29e75c2bb77bf9b6

I am confused on what I am missing ? Any comment?

Thanks, Anand

Quoted 27 lines · David Sterba

utils.c int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args, · line 1768

Quoted 10 lines · Wang Shilong

Btrfs device id start from 1, not 0.

utils.c +1 -1
@@ -1765,7 +1765,7 @@ int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args,
  		goto out;
  	}
 
-	for (; i <= fi_args->max_id; ++i) {
+	for (i = 1; i <= fi_args->max_id; ++i) {

You're right about the device id start, but forcing 1 here breaks the case when get_fs_info is called with block device as an argument and 'i' is set to the devid a few lines above.

Initializing i to 1 in the declaration block is the right fix IMO, and as this is a trivial change I'll do that myself, no need to resend.

utils.c int get_fs_info(char *path, struct btrfs_ioctl_fs_info_args *fi_args, · line 1771

Quoted 3 lines
utils.c +0 -0
  		BUG_ON(ndevs >= fi_args->num_devices);
  		ret = get_device_info(fd, i, &di_args[ndevs]);
  		if (ret == -ENODEV)

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#12 lore raw

Hi Anand,

Quoted 8 lines · Anand Jain

David,

As mentioned, this patch will back-out the earlier patch

50275bacab0f62b91453fbfa29e75c2bb77bf9b6

I am confused on what I am missing ? Any comment?

You are right, i guess dave just missed your previous thread.:-) dave, please ignore my patch, sorry for noise.

Thanks,
Wang

Quoted 35 lines

Thanks, Anand

Quoted 17 lines · David Sterba

utils.c int get_fs_info(char *path, struct · line 1769

Quoted 11 lines · Wang Shilong

Btrfs device id start from 1, not 0.

utils.c +1 -1
@@ -1765,7 +1765,7 @@ int get_fs_info(char *path, struct 
 btrfs_ioctl_fs_info_args *fi_args,
          goto out;
      }
 
-    for (; i <= fi_args->max_id; ++i) {
+    for (i = 1; i <= fi_args->max_id; ++i) {

You're right about the device id start, but forcing 1 here breaks the case when get_fs_info is called with block device as an argument and 'i' is set to the devid a few lines above.

Quoted 11 lines

Initializing i to 1 in the declaration block is the right fix IMO, and as this is a trivial change I'll do that myself, no need to resend.

Quoted 3 lines
utils.c +0 -0
          BUG_ON(ndevs >= fi_args->num_devices);
          ret = get_device_info(fd, i, &di_args[ndevs]);
          if (ret == -ENODEV)
Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

.

#13 lore raw
Quoted 4 lines · Wang Shilong

Hi Anand,

Quoted 1 line · Anand Jain
Quoted 8 lines
Quoted 7 lines

David,

As mentioned, this patch will back-out the earlier patch

50275bacab0f62b91453fbfa29e75c2bb77bf9b6

I am confused on what I am missing ? Any comment?

You are right, i guess dave just missed your previous thread.:-)

Oh I did, sorry.

#2 lore raw

Re: [PATCH] Btrfs: set right total device count for seeding support

In reply to Wang Shilong

Wang,

There seems to be a problem - after we delete the seed disk, the total_devices didn't decrement back to 1. reproducer as in the below test case. (I used btrfs-devlist (posted) to check fs_devices).

Quoted 4 lines
# mkfs.btrfs -f /dev/sdb
# btrfstune -S 1 /dev/sdb
# mount /dev/sdb /mnt
# btrfs device add -f /dev/sdc /mnt --->fs_devices->total_devices = 1

mount -o rw,remount /mnt
btrfs dev del /dev/sdb /mnt --> fs_devices->total_devices is still 2

Thanks, Anand

Quoted 36 lines · Wang Shilong

Seeding device support allows us to create a new filesystem based on existed filesystem.

However newly created filesystem's @total_devices should include seed devices. This patch fix the following problem:

  # mkfs.btrfs -f /dev/sdb
  # btrfstune -S 1 /dev/sdb
  # mount /dev/sdb /mnt
  # btrfs device add -f /dev/sdc /mnt --->fs_devices->total_devices = 1
  # umount /mnt
  # mount /dev/sdc /mnt               --->fs_devices->total_devices = 2

This is because we record right @total_devices in superblock, but @fs_devices->total_devices is reset to be 0 in btrfs_prepare_sprout().

Fix this problem by not resetting @fs_devices->total_devices.

---
  fs/btrfs/volumes.c | 1 -
  1 file changed, 1 deletion(-)
fs/btrfs/volumes.c +0 -1
index 6fd7fe6..19b2d32 100644
@@ -1883,7 +1883,6 @@ static int btrfs_prepare_sprout(struct btrfs_root *root)
  	fs_devices->seeding = 0;
  	fs_devices->num_devices = 0;
  	fs_devices->open_devices = 0;
-	fs_devices->total_devices = 0;
  	fs_devices->seed = seed_devices;
 
  	generate_random_uuid(fs_devices->fsid);
#3 lore raw

Re: [PATCH] Btrfs: set right total device count for seeding support

Wang,

when we unmount && mount (instead of remount) and followed with device del <seed> it ends up with null pointer deref at btrfs_shrink_dev. Thats because the btrfs_root is not set for seed disk as we mounted the writable sprout disk. I am writing a separate fix for that as its a new bug.

Thanks, Anand

Quoted 60 lines · Anand Jain

Wang,

There seems to be a problem - after we delete the seed disk, the total_devices didn't decrement back to 1. reproducer as in the below test case. (I used btrfs-devlist (posted) to check fs_devices).

Quoted 4 lines
# mkfs.btrfs -f /dev/sdb
# btrfstune -S 1 /dev/sdb
# mount /dev/sdb /mnt
# btrfs device add -f /dev/sdc /mnt --->fs_devices->total_devices = 1

mount -o rw,remount /mnt
btrfs dev del /dev/sdb /mnt --> fs_devices->total_devices is still 2

Thanks, Anand

Quoted 35 lines · Wang Shilong

Seeding device support allows us to create a new filesystem based on existed filesystem.

However newly created filesystem's @total_devices should include seed devices. This patch fix the following problem:

  # mkfs.btrfs -f /dev/sdb
  # btrfstune -S 1 /dev/sdb
  # mount /dev/sdb /mnt
  # btrfs device add -f /dev/sdc /mnt --->fs_devices->total_devices = 1
  # umount /mnt
  # mount /dev/sdc /mnt               --->fs_devices->total_devices = 2

This is because we record right @total_devices in superblock, but @fs_devices->total_devices is reset to be 0 in btrfs_prepare_sprout().

Fix this problem by not resetting @fs_devices->total_devices.

---
  fs/btrfs/volumes.c | 1 -
  1 file changed, 1 deletion(-)
fs/btrfs/volumes.c +0 -1
index 6fd7fe6..19b2d32 100644
@@ -1883,7 +1883,6 @@ static int btrfs_prepare_sprout(struct
 btrfs_root *root)
      fs_devices->seeding = 0;
      fs_devices->num_devices = 0;
      fs_devices->open_devices = 0;
-    fs_devices->total_devices = 0;
      fs_devices->seed = seed_devices;
 
Quoted 2 lines
      generate_random_uuid(fs_devices->fsid);

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw

Re: [PATCH] Btrfs: set right total device count for seeding support

In reply to Anand Jain

2014-05-16 22:14 GMT+08:00 Anand Jain <[email protected]>:

Quoted 7 lines

Wang,

There seems to be a problem - after we delete the seed disk, the total_devices didn't decrement back to 1. reproducer as in the below test case. (I used btrfs-devlist (posted) to check fs_devices).

There should be other problems flighting or i missed something , i'll take a look at this. Thanks Anand for finding this.

Quoted 56 lines
Quoted 6 lines

# mkfs.btrfs -f /dev/sdb
# btrfstune -S 1 /dev/sdb
# mount /dev/sdb /mnt
# btrfs device add -f /dev/sdc /mnt --->fs_devices->total_devices = 1

mount -o rw,remount /mnt
btrfs dev del /dev/sdb /mnt --> fs_devices->total_devices is still 2

Thanks, Anand

Quoted 36 lines · Wang Shilong

Seeding device support allows us to create a new filesystem based on existed filesystem.

However newly created filesystem's @total_devices should include seed devices. This patch fix the following problem:

  # mkfs.btrfs -f /dev/sdb
  # btrfstune -S 1 /dev/sdb
  # mount /dev/sdb /mnt
  # btrfs device add -f /dev/sdc /mnt --->fs_devices->total_devices = 1
  # umount /mnt
  # mount /dev/sdc /mnt               --->fs_devices->total_devices = 2

This is because we record right @total_devices in superblock, but @fs_devices->total_devices is reset to be 0 in btrfs_prepare_sprout().

Fix this problem by not resetting @fs_devices->total_devices.

---
  fs/btrfs/volumes.c | 1 -
  1 file changed, 1 deletion(-)
fs/btrfs/volumes.c +0 -1
index 6fd7fe6..19b2d32 100644
@@ -1883,7 +1883,6 @@ static int btrfs_prepare_sprout(struct btrfs_root
 *root)
        fs_devices->seeding = 0;
        fs_devices->num_devices = 0;
        fs_devices->open_devices = 0;
-       fs_devices->total_devices = 0;
        fs_devices->seed = seed_devices;
 
Quoted 2 lines
        generate_random_uuid(fs_devices->fsid);

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw

Re: [PATCH] Btrfs: set right total device count for seeding support

In reply to Anand Jain

2014-05-16 22:44 GMT+08:00 Anand Jain <[email protected]>:

Quoted 9 lines

Wang,

when we unmount && mount (instead of remount) and followed with device del <seed> it ends up with null pointer deref at btrfs_shrink_dev. Thats because the btrfs_root is not set for seed disk as we mounted the writable sprout disk. I am writing a separate fix for that as its a new bug.

You means this one which was addressed by Liu few days ago?
https://patchwork.kernel.org/patch/4150471/

Quoted 73 lines

Thanks, Anand

Quoted 56 lines · Anand Jain

Wang,

There seems to be a problem - after we delete the seed disk, the total_devices didn't decrement back to 1. reproducer as in the below test case. (I used btrfs-devlist (posted) to check fs_devices).

Quoted 4 lines
# mkfs.btrfs -f /dev/sdb
# btrfstune -S 1 /dev/sdb
# mount /dev/sdb /mnt
# btrfs device add -f /dev/sdc /mnt --->fs_devices->total_devices = 1

mount -o rw,remount /mnt
btrfs dev del /dev/sdb /mnt --> fs_devices->total_devices is still 2

Thanks, Anand

Quoted 36 lines · Wang Shilong

Seeding device support allows us to create a new filesystem based on existed filesystem.

However newly created filesystem's @total_devices should include seed devices. This patch fix the following problem:

  # mkfs.btrfs -f /dev/sdb
  # btrfstune -S 1 /dev/sdb
  # mount /dev/sdb /mnt
  # btrfs device add -f /dev/sdc /mnt --->fs_devices->total_devices = 1
  # umount /mnt
  # mount /dev/sdc /mnt               --->fs_devices->total_devices = 2

This is because we record right @total_devices in superblock, but @fs_devices->total_devices is reset to be 0 in btrfs_prepare_sprout().

Fix this problem by not resetting @fs_devices->total_devices.

---
  fs/btrfs/volumes.c | 1 -
  1 file changed, 1 deletion(-)
fs/btrfs/volumes.c +0 -1
index 6fd7fe6..19b2d32 100644
@@ -1883,7 +1883,6 @@ static int btrfs_prepare_sprout(struct
 btrfs_root *root)
      fs_devices->seeding = 0;
      fs_devices->num_devices = 0;
      fs_devices->open_devices = 0;
-    fs_devices->total_devices = 0;
      fs_devices->seed = seed_devices;
 
Quoted 6 lines
Quoted 2 lines
      generate_random_uuid(fs_devices->fsid);

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw

Re: [PATCH] Btrfs: set right total device count for seeding support

Quoted 5 lines · Shilong Wang

2014-05-16 22:44 GMT+08:00 Anand Jain <[email protected]>:

Quoted 4 lines

Wang,

Quoted 8 lines
Quoted 5 lines

when we unmount && mount (instead of remount) and followed with device del <seed> it ends up with null pointer deref at btrfs_shrink_dev. Thats because the btrfs_root is not set for seed disk as we mounted the writable sprout disk. I am writing a separate fix for that as its a new bug.

You means this one which was addressed by Liu few days ago?
https://patchwork.kernel.org/patch/4150471/

Ah there is already a patch. yes thats the one. Thanks.

Quoted 77 lines
Quoted 68 lines
Quoted 1 line
Quoted 1 line

Thanks, Anand

Quoted 56 lines · Anand Jain

Wang,

There seems to be a problem - after we delete the seed disk, the total_devices didn't decrement back to 1. reproducer as in the below test case. (I used btrfs-devlist (posted) to check fs_devices).

Quoted 4 lines
# mkfs.btrfs -f /dev/sdb
# btrfstune -S 1 /dev/sdb
# mount /dev/sdb /mnt
# btrfs device add -f /dev/sdc /mnt --->fs_devices->total_devices = 1

mount -o rw,remount /mnt
btrfs dev del /dev/sdb /mnt --> fs_devices->total_devices is still 2

Thanks, Anand

Quoted 36 lines · Wang Shilong

Seeding device support allows us to create a new filesystem based on existed filesystem.

However newly created filesystem's @total_devices should include seed devices. This patch fix the following problem:

   # mkfs.btrfs -f /dev/sdb
   # btrfstune -S 1 /dev/sdb
   # mount /dev/sdb /mnt
   # btrfs device add -f /dev/sdc /mnt --->fs_devices->total_devices = 1
   # umount /mnt
   # mount /dev/sdc /mnt               --->fs_devices->total_devices = 2

This is because we record right @total_devices in superblock, but @fs_devices->total_devices is reset to be 0 in btrfs_prepare_sprout().

Fix this problem by not resetting @fs_devices->total_devices.

---
   fs/btrfs/volumes.c | 1 -
   1 file changed, 1 deletion(-)
fs/btrfs/volumes.c +0 -1
index 6fd7fe6..19b2d32 100644
@@ -1883,7 +1883,6 @@ static int btrfs_prepare_sprout(struct
 btrfs_root *root)
       fs_devices->seeding = 0;
       fs_devices->num_devices = 0;
       fs_devices->open_devices = 0;
-    fs_devices->total_devices = 0;
       fs_devices->seed = seed_devices;
 
Quoted 6 lines
Quoted 2 lines
       generate_random_uuid(fs_devices->fsid);

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html