All of lore.kernel.org
 help / color / mirror / Atom feed
* btrfs:  memory leak on error path
@ 2009-03-26 13:39 error27
  2009-03-26 13:42 ` btrfs: dereferencing freed memory Dan Carpenter
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: error27 @ 2009-03-26 13:39 UTC (permalink / raw)
  To: chris.mason; +Cc: linux-btrfs

This was found by smatch (http://repo.or.cz/w/smatch.git/)

regards,
dan carpenter

Signed-off-by: Dan Carpenter <error27@gmail.com>

--- orig/fs/btrfs/volumes.c	2009-03-26 15:59:39.000000000 +0300
+++ devel/fs/btrfs/volumes.c	2009-03-26 16:00:28.000000000 +0300
@@ -342,6 +342,7 @@
 	return fs_devices;
 error:
 	free_fs_devices(fs_devices);
+	kfree(device);
 	return ERR_PTR(-ENOMEM);
 }
 

^ permalink raw reply	[flat|nested] 17+ messages in thread

* btrfs:  dereferencing freed memory
  2009-03-26 13:39 btrfs: memory leak on error path error27
@ 2009-03-26 13:42 ` Dan Carpenter
  2009-03-26 13:45 ` btrfs: returning under lock Dan Carpenter
  2009-03-26 13:54 ` unhandled kmallocs remaining Dan Carpenter
  2 siblings, 0 replies; 17+ messages in thread
From: Dan Carpenter @ 2009-03-26 13:42 UTC (permalink / raw)
  To: chris.mason; +Cc: linux-btrfs

This was found by smatch (http://repo.or.cz/w/smatch.git/)

regards,
dan carpenter

Signed-off-by: Dan Carpenter <error27@gmail.com>
--- orig/fs/btrfs/async-thread.c	2009-03-26 16:36:46.000000000 +0300
+++ devel/fs/btrfs/async-thread.c	2009-03-26 16:39:08.000000000 +0300
@@ -278,8 +278,8 @@
 					   workers->num_workers + i);
 		worker->workers = workers;
 		if (IS_ERR(worker->task)) {
-			kfree(worker);
 			ret = PTR_ERR(worker->task);
+			kfree(worker);
 			goto fail;
 		}
 

^ permalink raw reply	[flat|nested] 17+ messages in thread

* btrfs:  returning under lock
  2009-03-26 13:39 btrfs: memory leak on error path error27
  2009-03-26 13:42 ` btrfs: dereferencing freed memory Dan Carpenter
@ 2009-03-26 13:45 ` Dan Carpenter
  2009-03-26 13:54 ` unhandled kmallocs remaining Dan Carpenter
  2 siblings, 0 replies; 17+ messages in thread
From: Dan Carpenter @ 2009-03-26 13:45 UTC (permalink / raw)
  To: chris.mason; +Cc: linux-btrfs

This was found by smatch (http://repo.or.cz/w/smatch.git/)

regards,
dan carpenter

Signed-off-by: Dan Carpenter <error27@gmail.com>

--- orig/fs/btrfs/transaction.c	2009-03-26 16:25:37.000000000 +0300
+++ devel/fs/btrfs/transaction.c	2009-03-26 16:26:36.000000000 +0300
@@ -914,8 +914,10 @@
 	}
 
 	pinned_copy = kmalloc(sizeof(*pinned_copy), GFP_NOFS);
-	if (!pinned_copy)
+	if (!pinned_copy) {
+		mutex_unlock(&root->fs_info->trans_mutex);
 		return -ENOMEM;
+	}
 
 	extent_io_tree_init(pinned_copy,
 			     root->fs_info->btree_inode->i_mapping, GFP_NOFS);

^ permalink raw reply	[flat|nested] 17+ messages in thread

* unhandled kmallocs remaining
  2009-03-26 13:39 btrfs: memory leak on error path error27
  2009-03-26 13:42 ` btrfs: dereferencing freed memory Dan Carpenter
  2009-03-26 13:45 ` btrfs: returning under lock Dan Carpenter
@ 2009-03-26 13:54 ` Dan Carpenter
  2009-03-26 14:04   ` btrfs: [patch] remove dead code Dan Carpenter
                     ` (2 more replies)
  2 siblings, 3 replies; 17+ messages in thread
From: Dan Carpenter @ 2009-03-26 13:54 UTC (permalink / raw)
  To: chris.mason; +Cc: linux-btrfs

There are only 4 remaining kmallocs that don't have error handling in 
btrfs.

fs/btrfs/inode.c +277 add_async_extent() 'async_extent'
        async_extent = kmalloc(sizeof(*async_extent), GFP_NOFS);
        async_extent->start = start;

fs/btrfs/inode.c +866 cow_file_range_async() 'async_cow'
                async_cow = kmalloc(sizeof(*async_cow), GFP_NOFS);
                async_cow->inode = inode;

fs/btrfs/compression.c +355 btrfs_submit_compressed_write() 'cb'
        cb = kmalloc(compressed_bio_size(root, compressed_len), GFP_NOFS);
        atomic_set(&cb->pending_bios, 0);

fs/btrfs/compression.c +605 btrfs_submit_compressed_read() 'cb'
        cb = kmalloc(compressed_bio_size(root, compressed_len), GFP_NOFS);
        atomic_set(&cb->pending_bios, 0);

For this kernel release I'm fishing for reported by tags.
Reported-by: Dan Carpenter <error27@gmail.com>

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 17+ messages in thread

* btrfs:  [patch] remove dead code
  2009-03-26 13:54 ` unhandled kmallocs remaining Dan Carpenter
@ 2009-03-26 14:04   ` Dan Carpenter
  2009-03-26 14:10   ` [patch] btrfs: " Dan Carpenter
  2009-03-26 14:20   ` [patch] btrfs: remove dead code #3 Dan Carpenter
  2 siblings, 0 replies; 17+ messages in thread
From: Dan Carpenter @ 2009-03-26 14:04 UTC (permalink / raw)
  To: chris.mason; +Cc: linux-btrfs

This is a small clean up.

regards,
dan carpenter

Signed-off-by: Dan Carpenter <error27@gmail.com>

--- orig/fs/btrfs/disk-io.c	2009-03-26 17:00:57.000000000 +0300
+++ devel/fs/btrfs/disk-io.c	2009-03-26 17:01:44.000000000 +0300
@@ -1387,8 +1387,6 @@
 
 	ret = extent_range_uptodate(io_tree, start + length,
 				    start + buf_len - 1);
-	if (ret == 1)
-		return ret;
 	return ret;
 }
 


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [patch] btrfs: remove dead code
  2009-03-26 13:54 ` unhandled kmallocs remaining Dan Carpenter
  2009-03-26 14:04   ` btrfs: [patch] remove dead code Dan Carpenter
@ 2009-03-26 14:10   ` Dan Carpenter
  2009-03-26 14:20   ` [patch] btrfs: remove dead code #3 Dan Carpenter
  2 siblings, 0 replies; 17+ messages in thread
From: Dan Carpenter @ 2009-03-26 14:10 UTC (permalink / raw)
  To: chris.mason; +Cc: linux-btrfs

merge is always NULL at this point.

regards,
dan carpenter

Signed-off-by: Dan Carpenter <error27@gmail.com>

--- orig/fs/btrfs/extent_map.c	2009-03-26 17:07:20.000000000 +0300
+++ devel/fs/btrfs/extent_map.c	2009-03-26 17:07:39.000000000 +0300
@@ -234,7 +234,6 @@
 	rb = tree_insert(&tree->map, em->start, &em->rb_node);
 	if (rb) {
 		ret = -EEXIST;
-		free_extent_map(merge);
 		goto out;
 	}
 	atomic_inc(&em->refs);

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [patch] btrfs: remove dead code #3
  2009-03-26 13:54 ` unhandled kmallocs remaining Dan Carpenter
  2009-03-26 14:04   ` btrfs: [patch] remove dead code Dan Carpenter
  2009-03-26 14:10   ` [patch] btrfs: " Dan Carpenter
@ 2009-03-26 14:20   ` Dan Carpenter
  2009-03-26 14:39     ` Jens Axboe
  2 siblings, 1 reply; 17+ messages in thread
From: Dan Carpenter @ 2009-03-26 14:20 UTC (permalink / raw)
  Cc: chris.mason, linux-btrfs

kzalloc() already initialized ->error to zero.

regards,
dan carpenter

Signed-off-by: Dan Carpenter <error27@gmail.com>

--- orig/fs/btrfs/volumes.c	2009-03-26 17:14:13.000000000 +0300
+++ devel/fs/btrfs/volumes.c	2009-03-26 17:14:55.000000000 +0300
@@ -2422,10 +2422,8 @@
 		multi = kzalloc(btrfs_multi_bio_size(stripes_allocated),
 				GFP_NOFS);
 		if (!multi)
 			return -ENOMEM;
-
-		atomic_set(&multi->error, 0);
 	}
 
 	spin_lock(&em_tree->lock);
 	em = lookup_extent_mapping(em_tree, logical, *length);

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [patch] btrfs: remove dead code #3
  2009-03-26 14:20   ` [patch] btrfs: remove dead code #3 Dan Carpenter
@ 2009-03-26 14:39     ` Jens Axboe
  2009-03-26 14:48       ` Chris Mason
  0 siblings, 1 reply; 17+ messages in thread
From: Jens Axboe @ 2009-03-26 14:39 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: no, To-header, on, input <, 

On Thu, Mar 26 2009, Dan Carpenter wrote:
> kzalloc() already initialized ->error to zero.
> 
> regards,
> dan carpenter
> 
> Signed-off-by: Dan Carpenter <error27@gmail.com>
> 
> --- orig/fs/btrfs/volumes.c	2009-03-26 17:14:13.000000000 +0300
> +++ devel/fs/btrfs/volumes.c	2009-03-26 17:14:55.000000000 +0300
> @@ -2422,10 +2422,8 @@
>  		multi = kzalloc(btrfs_multi_bio_size(stripes_allocated),
>  				GFP_NOFS);
>  		if (!multi)
>  			return -ENOMEM;
> -
> -		atomic_set(&multi->error, 0);
>  	}
>  
>  	spin_lock(&em_tree->lock);
>  	em = lookup_extent_mapping(em_tree, logical, *length);

Careful, some archs require a barrier there. It's dangerous to makes
assumptions about the underlying implementation of such things, I'd
leave that one alone.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [patch] btrfs: remove dead code #3
  2009-03-26 14:39     ` Jens Axboe
@ 2009-03-26 14:48       ` Chris Mason
  2009-03-26 15:43         ` Jens Axboe
  0 siblings, 1 reply; 17+ messages in thread
From: Chris Mason @ 2009-03-26 14:48 UTC (permalink / raw)
  To: Jens Axboe; +Cc: Dan Carpenter, no, To-header, on, ;;chris.mason, linux-btrfs

On Thu, 2009-03-26 at 15:39 +0100, Jens Axboe wrote:
> On Thu, Mar 26 2009, Dan Carpenter wrote:
> > kzalloc() already initialized ->error to zero.
> > 
> > regards,
> > dan carpenter
> > 
> > Signed-off-by: Dan Carpenter <error27@gmail.com>
> > 
> > --- orig/fs/btrfs/volumes.c	2009-03-26 17:14:13.000000000 +0300
> > +++ devel/fs/btrfs/volumes.c	2009-03-26 17:14:55.000000000 +0300
> > @@ -2422,10 +2422,8 @@
> >  		multi = kzalloc(btrfs_multi_bio_size(stripes_allocated),
> >  				GFP_NOFS);
> >  		if (!multi)
> >  			return -ENOMEM;
> > -
> > -		atomic_set(&multi->error, 0);
> >  	}
> >  
> >  	spin_lock(&em_tree->lock);
> >  	em = lookup_extent_mapping(em_tree, logical, *length);
> 
> Careful, some archs require a barrier there. It's dangerous to makes
> assumptions about the underlying implementation of such things, I'd
> leave that one alone.
> 
Yeah, I'm not so much worried about the barrier as I am that assuming a
memset can init an atomic in general.

-chris



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [patch] btrfs: remove dead code #3
  2009-03-26 14:48       ` Chris Mason
@ 2009-03-26 15:43         ` Jens Axboe
  2009-03-26 23:30           ` linux-2.6.29: BUG at fs/btrfs/extent-tree.c:3433 Matteo Frigo
  0 siblings, 1 reply; 17+ messages in thread
From: Jens Axboe @ 2009-03-26 15:43 UTC (permalink / raw)
  To: Chris Mason; +Cc: Dan Carpenter, no, To-header, on, ;;chris.mason, linux-btrfs

On Thu, Mar 26 2009, Chris Mason wrote:
> On Thu, 2009-03-26 at 15:39 +0100, Jens Axboe wrote:
> > On Thu, Mar 26 2009, Dan Carpenter wrote:
> > > kzalloc() already initialized ->error to zero.
> > > 
> > > regards,
> > > dan carpenter
> > > 
> > > Signed-off-by: Dan Carpenter <error27@gmail.com>
> > > 
> > > --- orig/fs/btrfs/volumes.c	2009-03-26 17:14:13.000000000 +0300
> > > +++ devel/fs/btrfs/volumes.c	2009-03-26 17:14:55.000000000 +0300
> > > @@ -2422,10 +2422,8 @@
> > >  		multi = kzalloc(btrfs_multi_bio_size(stripes_allocated),
> > >  				GFP_NOFS);
> > >  		if (!multi)
> > >  			return -ENOMEM;
> > > -
> > > -		atomic_set(&multi->error, 0);
> > >  	}
> > >  
> > >  	spin_lock(&em_tree->lock);
> > >  	em = lookup_extent_mapping(em_tree, logical, *length);
> > 
> > Careful, some archs require a barrier there. It's dangerous to makes
> > assumptions about the underlying implementation of such things, I'd
> > leave that one alone.
> > 
> Yeah, I'm not so much worried about the barrier as I am that assuming a
> memset can init an atomic in general.

Right, it was more a generic comment. As to the memset(), if someone
decided to add a magic to atomic_t or something for debug purposes, it
would break. That's the bigger problem here :-)

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 17+ messages in thread

* linux-2.6.29: BUG at fs/btrfs/extent-tree.c:3433
  2009-03-26 15:43         ` Jens Axboe
@ 2009-03-26 23:30           ` Matteo Frigo
  0 siblings, 0 replies; 17+ messages in thread
From: Matteo Frigo @ 2009-03-26 23:30 UTC (permalink / raw)
  To: linux-btrfs

The following series of commands reliably causes a kernel BUG
with linux-2.6.29:

   lvcreate -L 10G -n x0 test
   lvcreate -L 10G -n x1 test
   lvcreate -L 10G -n x2 test
   mkfs.btrfs -m raid1 -d raid1 /dev/mapper/test-x[01]
   mount /dev/mapper/test-x0 /mnt
   umount /mnt
   lvremove test/x1
   mount -o degraded /dev/mapper/test-x0 /mnt
   btrfs-vol -a /dev/mapper/test-x2 /mnt

The dmesg log is attached.

Thanks for your work on btrfs.

Regards,
Matteo Frigo


[  137.894985] btrfs: allowing degraded mounts
[  138.175419] btrfs searching for 4096 bytes, num_bytes 4096, loop 2, allowed_alloc 0
[  138.176529] btrfs allocation failed flags 18, wanted 4096
[  138.177203] space_info has 8384512 free, is not full
[  138.177206] space_info total=8388608, pinned=0, delalloc=0, may_use=0, used=4096
[  138.177209] block group 20971520 has 8388608 bytes, 4096 used 0 pinned 0 reserved
[  138.177212] 1 blocks of free space at or bigger than bytes is
[  138.177247] ------------[ cut here ]------------
[  138.177865] kernel BUG at fs/btrfs/extent-tree.c:3433!
[  138.178514] invalid opcode: 0000 [#1] SMP 
[  138.179305] last sysfs file: /sys/block/dm-3/removable
[  138.179943] CPU 0 
[  138.180514] Modules linked in: btrfs zlib_deflate zlib_inflate crc32c libcrc32c ipv6 nfs lockd nfs_acl auth_rpcgss sunrpc loop virtio_console virtio_balloon snd_pcm snd_timer snd soundcore snd_page_alloc pcspkr psmouse serio_raw i2c_piix4 i2c_core parport_pc parport button joydev evdev ext3 jbd mbcache dm_mirror dm_region_hash dm_log dm_snapshot dm_mod usbhid hid ide_gd_mod ata_generic ide_pci_generic ata_piix libata scsi_mod floppy virtio_pci virtio_ring virtio e1000 uhci_hcd ehci_hcd piix ide_core thermal processor fan thermal_sys
[  138.180514] Pid: 2444, comm: btrfs-vol Not tainted 2.6.29 #1 
[  138.180514] RIP: 0010:[<ffffffffa03800c3>]  [<ffffffffa03800c3>] __btrfs_reserve_extent+0x290/0x2a5 [btrfs]
[  138.180514] RSP: 0018:ffff88001cce58a8  EFLAGS: 00010246
[  138.180514] RAX: ffff88001d975a38 RBX: ffff88001c41beec RCX: ffffffff8047ad6c
[  138.180514] RDX: 00000000ffffffff RSI: 0000000000000246 RDI: 0000000000000246
[  138.180514] RBP: ffff88001d975960 R08: ffff88001cce540d R09: 0000000000000000
[  138.180514] R10: 000000000000000a R11: 0000000000018600 R12: 0000000000001000
[  138.180514] R13: ffff88001d975a30 R14: ffff88001d975a18 R15: ffff88001c488000
[  138.180514] FS:  00007f63aa2ce740(0000) GS:ffffffff806d4000(0000) knlGS:0000000000000000
[  138.180514] CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
[  138.180514] CR2: 00007f63a9c44d60 CR3: 000000001c497000 CR4: 00000000000006e0
[  138.180514] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[  138.180514] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
[  138.180514] Process btrfs-vol (pid: 2444, threadinfo ffff88001cce4000, task ffff88001d946cf0)
[  138.180514] Stack:
[  138.180514]  0000000000000000 ffff88001cce59b8 0000000000000000 0000000000000000
[  138.180514]  ffff880000000012 ffff88001c06ebc8 0000000000000000 0000000000000000
[  138.180514]  0000000000000000 ffff88001cce59b8 ffff88001c432000 0000000000000003
[  138.180514] Call Trace:
[  138.180514]  [<ffffffffa03818f9>] ? btrfs_alloc_extent+0x4a/0xa2 [btrfs]
[  138.180514]  [<ffffffffa03819ba>] ? btrfs_alloc_free_block+0x69/0x96 [btrfs]
[  138.180514]  [<ffffffff803a3de6>] ? extract_buf+0x7e/0xf2
[  138.180514]  [<ffffffffa0374380>] ? __btrfs_cow_block+0x1ed/0x885 [btrfs]
[  138.180514]  [<ffffffff803a3804>] ? mix_pool_bytes_extract+0x57/0x14a
[  138.180514]  [<ffffffffa037518d>] ? btrfs_cow_block+0x1e7/0x1f6 [btrfs]
[  138.180514]  [<ffffffffa037992c>] ? btrfs_search_slot+0x35e/0x99c [btrfs]
[  138.180514]  [<ffffffffa037a4e1>] ? btrfs_insert_empty_items+0x7f/0x4a3 [btrfs]
[  138.180514]  [<ffffffffa03ab039>] ? btrfs_add_device+0x7a/0x1b9 [btrfs]
[  138.180514]  [<ffffffff8047ae12>] ? _spin_lock+0x5/0x7
[  138.180514]  [<ffffffffa03ac201>] ? btrfs_init_new_device+0x719/0x908 [btrfs]
[  138.180514]  [<ffffffff8028f06f>] ? generic_file_aio_write_nolock+0x33/0x7f
[  138.180514]  [<ffffffffa03ae689>] ? btrfs_ioctl+0x607/0x7f6 [btrfs]
[  138.180514]  [<ffffffff80257062>] ? autoremove_wake_function+0x0/0x2e
[  138.180514]  [<ffffffff802a458e>] ? free_pgtables+0x9c/0xbe
[  138.180514]  [<ffffffff802c90aa>] ? vfs_ioctl+0x21/0x6c
[  138.180514]  [<ffffffff802c952e>] ? do_vfs_ioctl+0x439/0x472
[  138.180514]  [<ffffffff802bdad7>] ? vfs_write+0x121/0x156
[  138.180514]  [<ffffffff802c95b8>] ? sys_ioctl+0x51/0x70
[  138.180514]  [<ffffffff8021102a>] ? system_call_fastpath+0x16/0x1b
[  138.180514] Code: 8b 85 b8 00 00 00 48 8d a8 48 ff ff ff 48 8b 85 b8 00 00 00 0f 18 08 48 8d 85 b8 00 00 00 49 39 c6 75 9a 4c 89 ef e8 87 9e ed df <0f> 0b eb fe 48 83 c4 48 31 c0 5b 5d 41 5c 41 5d 41 5e 41 5f c3 
[  138.180514] RIP  [<ffffffffa03800c3>] __btrfs_reserve_extent+0x290/0x2a5 [btrfs]
[  138.180514]  RSP <ffff88001cce58a8>
[  138.232118] ---[ end trace 12da8dfd82a051da ]---


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] btrfs: Remove dead code
  2022-01-28 11:50 [PATCH] btrfs: Remove " Muhammad Usama Anjum
@ 2022-02-01 14:05 ` David Sterba
  0 siblings, 0 replies; 17+ messages in thread
From: David Sterba @ 2022-02-01 14:05 UTC (permalink / raw)
  To: Muhammad Usama Anjum
  Cc: Chris Mason, Josef Bacik, David Sterba, Qu Wenruo, kernel,
	kernel-janitors, linux-btrfs, linux-kernel

On Fri, Jan 28, 2022 at 04:50:27PM +0500, Muhammad Usama Anjum wrote:
> Local variable stop_loop is assigned only once, to a constant value 0,
> making it effectively constant through out its scope. This constant
> variable is guarding deadcode. The two if conditions can never be true.
> Remove the variable and make the logic simple.
> 
> Fixes: 585f784357d8 ("btrfs: use scrub_simple_mirror() to handle RAID56 data stripe scrub")

Thanks, this patch is still only in for-next so the change can be folded
into it.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH] btrfs: Remove dead code
@ 2022-01-28 11:50 Muhammad Usama Anjum
  2022-02-01 14:05 ` David Sterba
  0 siblings, 1 reply; 17+ messages in thread
From: Muhammad Usama Anjum @ 2022-01-28 11:50 UTC (permalink / raw)
  To: Chris Mason, Josef Bacik, David Sterba, Qu Wenruo
  Cc: Muhammad Usama Anjum, kernel, kernel-janitors, linux-btrfs, linux-kernel

Local variable stop_loop is assigned only once, to a constant value 0,
making it effectively constant through out its scope. This constant
variable is guarding deadcode. The two if conditions can never be true.
Remove the variable and make the logic simple.

Fixes: 585f784357d8 ("btrfs: use scrub_simple_mirror() to handle RAID56 data stripe scrub")
Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
---
 fs/btrfs/scrub.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 4baa8e43d585b..26bbe93c3aa3c 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -3533,7 +3533,6 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
 	u64 offset;	/* Offset inside the chunk */
 	u64 stripe_logical;
 	u64 stripe_end;
-	int stop_loop = 0;
 
 	path = btrfs_alloc_path();
 	if (!path)
@@ -3652,14 +3651,8 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
 		logical += increment;
 		physical += map->stripe_len;
 		spin_lock(&sctx->stat_lock);
-		if (stop_loop)
-			sctx->stat.last_physical = map->stripes[stripe_index].physical +
-						   dev_extent_len;
-		else
-			sctx->stat.last_physical = physical;
+		sctx->stat.last_physical = physical;
 		spin_unlock(&sctx->stat_lock);
-		if (stop_loop)
-			break;
 	}
 out:
 	/* push queued extents */
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH] btrfs: remove dead code
  2013-11-29 17:01 [PATCH] " Michal Nazarewicz
@ 2013-11-29 20:00 ` Filipe David Manana
  0 siblings, 0 replies; 17+ messages in thread
From: Filipe David Manana @ 2013-11-29 20:00 UTC (permalink / raw)
  To: Michal Nazarewicz; +Cc: Chris Mason, linux-btrfs, linux-kernel

On Fri, Nov 29, 2013 at 5:01 PM, Michal Nazarewicz <mpn@google.com> wrote:
> From: Michal Nazarewicz <mina86@mina86.com>
>
> [commit 8185554d: fix incorrect inode acl reset] introduced a dead
> code by adding a condition which can never be true to an else
> branch.  The condition can never be true because it is already
> checked by a previous if statement which causes function to return.
>
> Signed-off-by: Michal Nazarewicz <mina86@mina86.com>

Reviewed-By: Filipe David Borba Manana <fdmanana@gmail.com>

> ---
>  fs/btrfs/acl.c | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
>
> diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c
> index 0890c83..460f36b 100644
> --- a/fs/btrfs/acl.c
> +++ b/fs/btrfs/acl.c
> @@ -225,13 +225,8 @@ int btrfs_init_acl(struct btrfs_trans_handle *trans,
>                 ret = posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
>                 if (ret < 0)
>                         return ret;
> -
> -               if (ret > 0) {
> -                       /* we need an acl */
> +               if (ret > 0) /* we need an acl */
>                         ret = btrfs_set_acl(trans, inode, acl, ACL_TYPE_ACCESS);
> -               } else if (ret < 0) {
> -                       cache_no_acl(inode);
> -               }
>         } else {
>                 cache_no_acl(inode);
>         }
> --
> 1.8.4.1
>



-- 
Filipe David Manana,

"Reasonable men adapt themselves to the world.
 Unreasonable men adapt the world to themselves.
 That's why all progress depends on unreasonable men."

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH] btrfs: remove dead code
@ 2013-11-29 17:01 Michal Nazarewicz
  2013-11-29 20:00 ` Filipe David Manana
  0 siblings, 1 reply; 17+ messages in thread
From: Michal Nazarewicz @ 2013-11-29 17:01 UTC (permalink / raw)
  To: Chris Mason, Filipe David Borba Manana; +Cc: linux-btrfs, linux-kernel

From: Michal Nazarewicz <mina86@mina86.com>

[commit 8185554d: fix incorrect inode acl reset] introduced a dead
code by adding a condition which can never be true to an else
branch.  The condition can never be true because it is already
checked by a previous if statement which causes function to return.

Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
---
 fs/btrfs/acl.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c
index 0890c83..460f36b 100644
--- a/fs/btrfs/acl.c
+++ b/fs/btrfs/acl.c
@@ -225,13 +225,8 @@ int btrfs_init_acl(struct btrfs_trans_handle *trans,
 		ret = posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
 		if (ret < 0)
 			return ret;
-
-		if (ret > 0) {
-			/* we need an acl */
+		if (ret > 0) /* we need an acl */
 			ret = btrfs_set_acl(trans, inode, acl, ACL_TYPE_ACCESS);
-		} else if (ret < 0) {
-			cache_no_acl(inode);
-		}
 	} else {
 		cache_no_acl(inode);
 	}
-- 
1.8.4.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [patch] btrfs: remove dead code
@ 2010-01-07 15:25 Dan Carpenter
  0 siblings, 0 replies; 17+ messages in thread
From: Dan Carpenter @ 2010-01-07 15:25 UTC (permalink / raw)
  To: Chris Mason; +Cc: linux-btrfs

rb_node cannot be an ERR_PTR() here.  Both implimentations of __tree_search()
return either a valid pointer or NULL.

It doesn't make a runtime difference but without this patch smatch thinks that
lookup_extent_mapping() can return an ERR_PTR().  It can wait until 2.6.34 
obviously.

Signed-off-by: Dan Carpenter <error27@gmail.com>

--- orig/fs/btrfs/extent_map.c	2010-01-07 10:50:30.000000000 +0300
+++ devel/fs/btrfs/extent_map.c	2010-01-07 10:50:40.000000000 +0300
@@ -349,10 +349,6 @@ struct extent_map *lookup_extent_mapping
 		em = NULL;
 		goto out;
 	}
-	if (IS_ERR(rb_node)) {
-		em = ERR_PTR(PTR_ERR(rb_node));
-		goto out;
-	}
 	em = rb_entry(rb_node, struct extent_map, rb_node);
 	if (end > em->start && start < extent_map_end(em))
 		goto found;

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH] Btrfs: remove dead code
@ 2009-08-24 18:40 Josef Bacik
  0 siblings, 0 replies; 17+ messages in thread
From: Josef Bacik @ 2009-08-24 18:40 UTC (permalink / raw)
  To: linux-btrfs

This patch removes a bunch of dead code from the snapshot removal stuff.  It was
confusing me when doing the metadata ENOSPC stuff so I killed it.

Signed-off-by: Josef Bacik <jbacik@redhat.com>
---
 fs/btrfs/extent-tree.c |  706 ------------------------------------------------
 1 files changed, 0 insertions(+), 706 deletions(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 10da1b6..92bc72e 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -4471,430 +4471,6 @@ struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
 	return buf;
 }
 
-#if 0
-int btrfs_drop_leaf_ref(struct btrfs_trans_handle *trans,
-			struct btrfs_root *root, struct extent_buffer *leaf)
-{
-	u64 disk_bytenr;
-	u64 num_bytes;
-	struct btrfs_key key;
-	struct btrfs_file_extent_item *fi;
-	u32 nritems;
-	int i;
-	int ret;
-
-	BUG_ON(!btrfs_is_leaf(leaf));
-	nritems = btrfs_header_nritems(leaf);
-
-	for (i = 0; i < nritems; i++) {
-		cond_resched();
-		btrfs_item_key_to_cpu(leaf, &key, i);
-
-		/* only extents have references, skip everything else */
-		if (btrfs_key_type(&key) != BTRFS_EXTENT_DATA_KEY)
-			continue;
-
-		fi = btrfs_item_ptr(leaf, i, struct btrfs_file_extent_item);
-
-		/* inline extents live in the btree, they don't have refs */
-		if (btrfs_file_extent_type(leaf, fi) ==
-		    BTRFS_FILE_EXTENT_INLINE)
-			continue;
-
-		disk_bytenr = btrfs_file_extent_disk_bytenr(leaf, fi);
-
-		/* holes don't have refs */
-		if (disk_bytenr == 0)
-			continue;
-
-		num_bytes = btrfs_file_extent_disk_num_bytes(leaf, fi);
-		ret = btrfs_free_extent(trans, root, disk_bytenr, num_bytes,
-					leaf->start, 0, key.objectid, 0);
-		BUG_ON(ret);
-	}
-	return 0;
-}
-
-static noinline int cache_drop_leaf_ref(struct btrfs_trans_handle *trans,
-					struct btrfs_root *root,
-					struct btrfs_leaf_ref *ref)
-{
-	int i;
-	int ret;
-	struct btrfs_extent_info *info;
-	struct refsort *sorted;
-
-	if (ref->nritems == 0)
-		return 0;
-
-	sorted = kmalloc(sizeof(*sorted) * ref->nritems, GFP_NOFS);
-	for (i = 0; i < ref->nritems; i++) {
-		sorted[i].bytenr = ref->extents[i].bytenr;
-		sorted[i].slot = i;
-	}
-	sort(sorted, ref->nritems, sizeof(struct refsort), refsort_cmp, NULL);
-
-	/*
-	 * the items in the ref were sorted when the ref was inserted
-	 * into the ref cache, so this is already in order
-	 */
-	for (i = 0; i < ref->nritems; i++) {
-		info = ref->extents + sorted[i].slot;
-		ret = btrfs_free_extent(trans, root, info->bytenr,
-					  info->num_bytes, ref->bytenr,
-					  ref->owner, ref->generation,
-					  info->objectid, 0);
-
-		atomic_inc(&root->fs_info->throttle_gen);
-		wake_up(&root->fs_info->transaction_throttle);
-		cond_resched();
-
-		BUG_ON(ret);
-		info++;
-	}
-
-	kfree(sorted);
-	return 0;
-}
-
-
-static int drop_snap_lookup_refcount(struct btrfs_trans_handle *trans,
-				     struct btrfs_root *root, u64 start,
-				     u64 len, u32 *refs)
-{
-	int ret;
-
-	ret = btrfs_lookup_extent_refs(trans, root, start, len, refs);
-	BUG_ON(ret);
-
-#if 0 /* some debugging code in case we see problems here */
-	/* if the refs count is one, it won't get increased again.  But
-	 * if the ref count is > 1, someone may be decreasing it at
-	 * the same time we are.
-	 */
-	if (*refs != 1) {
-		struct extent_buffer *eb = NULL;
-		eb = btrfs_find_create_tree_block(root, start, len);
-		if (eb)
-			btrfs_tree_lock(eb);
-
-		mutex_lock(&root->fs_info->alloc_mutex);
-		ret = lookup_extent_ref(NULL, root, start, len, refs);
-		BUG_ON(ret);
-		mutex_unlock(&root->fs_info->alloc_mutex);
-
-		if (eb) {
-			btrfs_tree_unlock(eb);
-			free_extent_buffer(eb);
-		}
-		if (*refs == 1) {
-			printk(KERN_ERR "btrfs block %llu went down to one "
-			       "during drop_snap\n", (unsigned long long)start);
-		}
-
-	}
-#endif
-
-	cond_resched();
-	return ret;
-}
-
-
-/*
- * this is used while deleting old snapshots, and it drops the refs
- * on a whole subtree starting from a level 1 node.
- *
- * The idea is to sort all the leaf pointers, and then drop the
- * ref on all the leaves in order.  Most of the time the leaves
- * will have ref cache entries, so no leaf IOs will be required to
- * find the extents they have references on.
- *
- * For each leaf, any references it has are also dropped in order
- *
- * This ends up dropping the references in something close to optimal
- * order for reading and modifying the extent allocation tree.
- */
-static noinline int drop_level_one_refs(struct btrfs_trans_handle *trans,
-					struct btrfs_root *root,
-					struct btrfs_path *path)
-{
-	u64 bytenr;
-	u64 root_owner;
-	u64 root_gen;
-	struct extent_buffer *eb = path->nodes[1];
-	struct extent_buffer *leaf;
-	struct btrfs_leaf_ref *ref;
-	struct refsort *sorted = NULL;
-	int nritems = btrfs_header_nritems(eb);
-	int ret;
-	int i;
-	int refi = 0;
-	int slot = path->slots[1];
-	u32 blocksize = btrfs_level_size(root, 0);
-	u32 refs;
-
-	if (nritems == 0)
-		goto out;
-
-	root_owner = btrfs_header_owner(eb);
-	root_gen = btrfs_header_generation(eb);
-	sorted = kmalloc(sizeof(*sorted) * nritems, GFP_NOFS);
-
-	/*
-	 * step one, sort all the leaf pointers so we don't scribble
-	 * randomly into the extent allocation tree
-	 */
-	for (i = slot; i < nritems; i++) {
-		sorted[refi].bytenr = btrfs_node_blockptr(eb, i);
-		sorted[refi].slot = i;
-		refi++;
-	}
-
-	/*
-	 * nritems won't be zero, but if we're picking up drop_snapshot
-	 * after a crash, slot might be > 0, so double check things
-	 * just in case.
-	 */
-	if (refi == 0)
-		goto out;
-
-	sort(sorted, refi, sizeof(struct refsort), refsort_cmp, NULL);
-
-	/*
-	 * the first loop frees everything the leaves point to
-	 */
-	for (i = 0; i < refi; i++) {
-		u64 ptr_gen;
-
-		bytenr = sorted[i].bytenr;
-
-		/*
-		 * check the reference count on this leaf.  If it is > 1
-		 * we just decrement it below and don't update any
-		 * of the refs the leaf points to.
-		 */
-		ret = drop_snap_lookup_refcount(trans, root, bytenr,
-						blocksize, &refs);
-		BUG_ON(ret);
-		if (refs != 1)
-			continue;
-
-		ptr_gen = btrfs_node_ptr_generation(eb, sorted[i].slot);
-
-		/*
-		 * the leaf only had one reference, which means the
-		 * only thing pointing to this leaf is the snapshot
-		 * we're deleting.  It isn't possible for the reference
-		 * count to increase again later
-		 *
-		 * The reference cache is checked for the leaf,
-		 * and if found we'll be able to drop any refs held by
-		 * the leaf without needing to read it in.
-		 */
-		ref = btrfs_lookup_leaf_ref(root, bytenr);
-		if (ref && ref->generation != ptr_gen) {
-			btrfs_free_leaf_ref(root, ref);
-			ref = NULL;
-		}
-		if (ref) {
-			ret = cache_drop_leaf_ref(trans, root, ref);
-			BUG_ON(ret);
-			btrfs_remove_leaf_ref(root, ref);
-			btrfs_free_leaf_ref(root, ref);
-		} else {
-			/*
-			 * the leaf wasn't in the reference cache, so
-			 * we have to read it.
-			 */
-			leaf = read_tree_block(root, bytenr, blocksize,
-					       ptr_gen);
-			ret = btrfs_drop_leaf_ref(trans, root, leaf);
-			BUG_ON(ret);
-			free_extent_buffer(leaf);
-		}
-		atomic_inc(&root->fs_info->throttle_gen);
-		wake_up(&root->fs_info->transaction_throttle);
-		cond_resched();
-	}
-
-	/*
-	 * run through the loop again to free the refs on the leaves.
-	 * This is faster than doing it in the loop above because
-	 * the leaves are likely to be clustered together.  We end up
-	 * working in nice chunks on the extent allocation tree.
-	 */
-	for (i = 0; i < refi; i++) {
-		bytenr = sorted[i].bytenr;
-		ret = btrfs_free_extent(trans, root, bytenr,
-					blocksize, eb->start,
-					root_owner, root_gen, 0, 1);
-		BUG_ON(ret);
-
-		atomic_inc(&root->fs_info->throttle_gen);
-		wake_up(&root->fs_info->transaction_throttle);
-		cond_resched();
-	}
-out:
-	kfree(sorted);
-
-	/*
-	 * update the path to show we've processed the entire level 1
-	 * node.  This will get saved into the root's drop_snapshot_progress
-	 * field so these drops are not repeated again if this transaction
-	 * commits.
-	 */
-	path->slots[1] = nritems;
-	return 0;
-}
-
-/*
- * helper function for drop_snapshot, this walks down the tree dropping ref
- * counts as it goes.
- */
-static noinline int walk_down_tree(struct btrfs_trans_handle *trans,
-				   struct btrfs_root *root,
-				   struct btrfs_path *path, int *level)
-{
-	u64 root_owner;
-	u64 root_gen;
-	u64 bytenr;
-	u64 ptr_gen;
-	struct extent_buffer *next;
-	struct extent_buffer *cur;
-	struct extent_buffer *parent;
-	u32 blocksize;
-	int ret;
-	u32 refs;
-
-	WARN_ON(*level < 0);
-	WARN_ON(*level >= BTRFS_MAX_LEVEL);
-	ret = drop_snap_lookup_refcount(trans, root, path->nodes[*level]->start,
-				path->nodes[*level]->len, &refs);
-	BUG_ON(ret);
-	if (refs > 1)
-		goto out;
-
-	/*
-	 * walk down to the last node level and free all the leaves
-	 */
-	while (*level >= 0) {
-		WARN_ON(*level < 0);
-		WARN_ON(*level >= BTRFS_MAX_LEVEL);
-		cur = path->nodes[*level];
-
-		if (btrfs_header_level(cur) != *level)
-			WARN_ON(1);
-
-		if (path->slots[*level] >=
-		    btrfs_header_nritems(cur))
-			break;
-
-		/* the new code goes down to level 1 and does all the
-		 * leaves pointed to that node in bulk.  So, this check
-		 * for level 0 will always be false.
-		 *
-		 * But, the disk format allows the drop_snapshot_progress
-		 * field in the root to leave things in a state where
-		 * a leaf will need cleaning up here.  If someone crashes
-		 * with the old code and then boots with the new code,
-		 * we might find a leaf here.
-		 */
-		if (*level == 0) {
-			ret = btrfs_drop_leaf_ref(trans, root, cur);
-			BUG_ON(ret);
-			break;
-		}
-
-		/*
-		 * once we get to level one, process the whole node
-		 * at once, including everything below it.
-		 */
-		if (*level == 1) {
-			ret = drop_level_one_refs(trans, root, path);
-			BUG_ON(ret);
-			break;
-		}
-
-		bytenr = btrfs_node_blockptr(cur, path->slots[*level]);
-		ptr_gen = btrfs_node_ptr_generation(cur, path->slots[*level]);
-		blocksize = btrfs_level_size(root, *level - 1);
-
-		ret = drop_snap_lookup_refcount(trans, root, bytenr,
-						blocksize, &refs);
-		BUG_ON(ret);
-
-		/*
-		 * if there is more than one reference, we don't need
-		 * to read that node to drop any references it has.  We
-		 * just drop the ref we hold on that node and move on to the
-		 * next slot in this level.
-		 */
-		if (refs != 1) {
-			parent = path->nodes[*level];
-			root_owner = btrfs_header_owner(parent);
-			root_gen = btrfs_header_generation(parent);
-			path->slots[*level]++;
-
-			ret = btrfs_free_extent(trans, root, bytenr,
-						blocksize, parent->start,
-						root_owner, root_gen,
-						*level - 1, 1);
-			BUG_ON(ret);
-
-			atomic_inc(&root->fs_info->throttle_gen);
-			wake_up(&root->fs_info->transaction_throttle);
-			cond_resched();
-
-			continue;
-		}
-
-		/*
-		 * we need to keep freeing things in the next level down.
-		 * read the block and loop around to process it
-		 */
-		next = read_tree_block(root, bytenr, blocksize, ptr_gen);
-		WARN_ON(*level <= 0);
-		if (path->nodes[*level-1])
-			free_extent_buffer(path->nodes[*level-1]);
-		path->nodes[*level-1] = next;
-		*level = btrfs_header_level(next);
-		path->slots[*level] = 0;
-		cond_resched();
-	}
-out:
-	WARN_ON(*level < 0);
-	WARN_ON(*level >= BTRFS_MAX_LEVEL);
-
-	if (path->nodes[*level] == root->node) {
-		parent = path->nodes[*level];
-		bytenr = path->nodes[*level]->start;
-	} else {
-		parent = path->nodes[*level + 1];
-		bytenr = btrfs_node_blockptr(parent, path->slots[*level + 1]);
-	}
-
-	blocksize = btrfs_level_size(root, *level);
-	root_owner = btrfs_header_owner(parent);
-	root_gen = btrfs_header_generation(parent);
-
-	/*
-	 * cleanup and free the reference on the last node
-	 * we processed
-	 */
-	ret = btrfs_free_extent(trans, root, bytenr, blocksize,
-				  parent->start, root_owner, root_gen,
-				  *level, 1);
-	free_extent_buffer(path->nodes[*level]);
-	path->nodes[*level] = NULL;
-
-	*level += 1;
-	BUG_ON(ret);
-
-	cond_resched();
-	return 0;
-}
-#endif
-
 struct walk_control {
 	u64 refs[BTRFS_MAX_LEVEL];
 	u64 flags[BTRFS_MAX_LEVEL];
@@ -6966,288 +6542,6 @@ int btrfs_prepare_block_group_relocation(struct btrfs_root *root,
 	return 0;
 }
 
-#if 0
-static int __insert_orphan_inode(struct btrfs_trans_handle *trans,
-				 struct btrfs_root *root,
-				 u64 objectid, u64 size)
-{
-	struct btrfs_path *path;
-	struct btrfs_inode_item *item;
-	struct extent_buffer *leaf;
-	int ret;
-
-	path = btrfs_alloc_path();
-	if (!path)
-		return -ENOMEM;
-
-	path->leave_spinning = 1;
-	ret = btrfs_insert_empty_inode(trans, root, path, objectid);
-	if (ret)
-		goto out;
-
-	leaf = path->nodes[0];
-	item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_inode_item);
-	memset_extent_buffer(leaf, 0, (unsigned long)item, sizeof(*item));
-	btrfs_set_inode_generation(leaf, item, 1);
-	btrfs_set_inode_size(leaf, item, size);
-	btrfs_set_inode_mode(leaf, item, S_IFREG | 0600);
-	btrfs_set_inode_flags(leaf, item, BTRFS_INODE_NOCOMPRESS);
-	btrfs_mark_buffer_dirty(leaf);
-	btrfs_release_path(root, path);
-out:
-	btrfs_free_path(path);
-	return ret;
-}
-
-static noinline struct inode *create_reloc_inode(struct btrfs_fs_info *fs_info,
-					struct btrfs_block_group_cache *group)
-{
-	struct inode *inode = NULL;
-	struct btrfs_trans_handle *trans;
-	struct btrfs_root *root;
-	struct btrfs_key root_key;
-	u64 objectid = BTRFS_FIRST_FREE_OBJECTID;
-	int err = 0;
-
-	root_key.objectid = BTRFS_DATA_RELOC_TREE_OBJECTID;
-	root_key.type = BTRFS_ROOT_ITEM_KEY;
-	root_key.offset = (u64)-1;
-	root = btrfs_read_fs_root_no_name(fs_info, &root_key);
-	if (IS_ERR(root))
-		return ERR_CAST(root);
-
-	trans = btrfs_start_transaction(root, 1);
-	BUG_ON(!trans);
-
-	err = btrfs_find_free_objectid(trans, root, objectid, &objectid);
-	if (err)
-		goto out;
-
-	err = __insert_orphan_inode(trans, root, objectid, group->key.offset);
-	BUG_ON(err);
-
-	err = btrfs_insert_file_extent(trans, root, objectid, 0, 0, 0,
-				       group->key.offset, 0, group->key.offset,
-				       0, 0, 0);
-	BUG_ON(err);
-
-	inode = btrfs_iget_locked(root->fs_info->sb, objectid, root);
-	if (inode->i_state & I_NEW) {
-		BTRFS_I(inode)->root = root;
-		BTRFS_I(inode)->location.objectid = objectid;
-		BTRFS_I(inode)->location.type = BTRFS_INODE_ITEM_KEY;
-		BTRFS_I(inode)->location.offset = 0;
-		btrfs_read_locked_inode(inode);
-		unlock_new_inode(inode);
-		BUG_ON(is_bad_inode(inode));
-	} else {
-		BUG_ON(1);
-	}
-	BTRFS_I(inode)->index_cnt = group->key.objectid;
-
-	err = btrfs_orphan_add(trans, inode);
-out:
-	btrfs_end_transaction(trans, root);
-	if (err) {
-		if (inode)
-			iput(inode);
-		inode = ERR_PTR(err);
-	}
-	return inode;
-}
-
-int btrfs_reloc_clone_csums(struct inode *inode, u64 file_pos, u64 len)
-{
-
-	struct btrfs_ordered_sum *sums;
-	struct btrfs_sector_sum *sector_sum;
-	struct btrfs_ordered_extent *ordered;
-	struct btrfs_root *root = BTRFS_I(inode)->root;
-	struct list_head list;
-	size_t offset;
-	int ret;
-	u64 disk_bytenr;
-
-	INIT_LIST_HEAD(&list);
-
-	ordered = btrfs_lookup_ordered_extent(inode, file_pos);
-	BUG_ON(ordered->file_offset != file_pos || ordered->len != len);
-
-	disk_bytenr = file_pos + BTRFS_I(inode)->index_cnt;
-	ret = btrfs_lookup_csums_range(root->fs_info->csum_root, disk_bytenr,
-				       disk_bytenr + len - 1, &list);
-
-	while (!list_empty(&list)) {
-		sums = list_entry(list.next, struct btrfs_ordered_sum, list);
-		list_del_init(&sums->list);
-
-		sector_sum = sums->sums;
-		sums->bytenr = ordered->start;
-
-		offset = 0;
-		while (offset < sums->len) {
-			sector_sum->bytenr += ordered->start - disk_bytenr;
-			sector_sum++;
-			offset += root->sectorsize;
-		}
-
-		btrfs_add_ordered_sum(inode, ordered, sums);
-	}
-	btrfs_put_ordered_extent(ordered);
-	return 0;
-}
-
-int btrfs_relocate_block_group(struct btrfs_root *root, u64 group_start)
-{
-	struct btrfs_trans_handle *trans;
-	struct btrfs_path *path;
-	struct btrfs_fs_info *info = root->fs_info;
-	struct extent_buffer *leaf;
-	struct inode *reloc_inode;
-	struct btrfs_block_group_cache *block_group;
-	struct btrfs_key key;
-	u64 skipped;
-	u64 cur_byte;
-	u64 total_found;
-	u32 nritems;
-	int ret;
-	int progress;
-	int pass = 0;
-
-	root = root->fs_info->extent_root;
-
-	block_group = btrfs_lookup_block_group(info, group_start);
-	BUG_ON(!block_group);
-
-	printk(KERN_INFO "btrfs relocating block group %llu flags %llu\n",
-	       (unsigned long long)block_group->key.objectid,
-	       (unsigned long long)block_group->flags);
-
-	path = btrfs_alloc_path();
-	BUG_ON(!path);
-
-	reloc_inode = create_reloc_inode(info, block_group);
-	BUG_ON(IS_ERR(reloc_inode));
-
-	__alloc_chunk_for_shrink(root, block_group, 1);
-	set_block_group_readonly(block_group);
-
-	btrfs_start_delalloc_inodes(info->tree_root);
-	btrfs_wait_ordered_extents(info->tree_root, 0);
-again:
-	skipped = 0;
-	total_found = 0;
-	progress = 0;
-	key.objectid = block_group->key.objectid;
-	key.offset = 0;
-	key.type = 0;
-	cur_byte = key.objectid;
-
-	trans = btrfs_start_transaction(info->tree_root, 1);
-	btrfs_commit_transaction(trans, info->tree_root);
-
-	mutex_lock(&root->fs_info->cleaner_mutex);
-	btrfs_clean_old_snapshots(info->tree_root);
-	btrfs_remove_leaf_refs(info->tree_root, (u64)-1, 1);
-	mutex_unlock(&root->fs_info->cleaner_mutex);
-
-	trans = btrfs_start_transaction(info->tree_root, 1);
-	btrfs_commit_transaction(trans, info->tree_root);
-
-	while (1) {
-		ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
-		if (ret < 0)
-			goto out;
-next:
-		leaf = path->nodes[0];
-		nritems = btrfs_header_nritems(leaf);
-		if (path->slots[0] >= nritems) {
-			ret = btrfs_next_leaf(root, path);
-			if (ret < 0)
-				goto out;
-			if (ret == 1) {
-				ret = 0;
-				break;
-			}
-			leaf = path->nodes[0];
-			nritems = btrfs_header_nritems(leaf);
-		}
-
-		btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
-
-		if (key.objectid >= block_group->key.objectid +
-		    block_group->key.offset)
-			break;
-
-		if (progress && need_resched()) {
-			btrfs_release_path(root, path);
-			cond_resched();
-			progress = 0;
-			continue;
-		}
-		progress = 1;
-
-		if (btrfs_key_type(&key) != BTRFS_EXTENT_ITEM_KEY ||
-		    key.objectid + key.offset <= cur_byte) {
-			path->slots[0]++;
-			goto next;
-		}
-
-		total_found++;
-		cur_byte = key.objectid + key.offset;
-		btrfs_release_path(root, path);
-
-		__alloc_chunk_for_shrink(root, block_group, 0);
-		ret = relocate_one_extent(root, path, &key, block_group,
-					  reloc_inode, pass);
-		BUG_ON(ret < 0);
-		if (ret > 0)
-			skipped++;
-
-		key.objectid = cur_byte;
-		key.type = 0;
-		key.offset = 0;
-	}
-
-	btrfs_release_path(root, path);
-
-	if (pass == 0) {
-		btrfs_wait_ordered_range(reloc_inode, 0, (u64)-1);
-		invalidate_mapping_pages(reloc_inode->i_mapping, 0, -1);
-	}
-
-	if (total_found > 0) {
-		printk(KERN_INFO "btrfs found %llu extents in pass %d\n",
-		       (unsigned long long)total_found, pass);
-		pass++;
-		if (total_found == skipped && pass > 2) {
-			iput(reloc_inode);
-			reloc_inode = create_reloc_inode(info, block_group);
-			pass = 0;
-		}
-		goto again;
-	}
-
-	/* delete reloc_inode */
-	iput(reloc_inode);
-
-	/* unpin extents in this range */
-	trans = btrfs_start_transaction(info->tree_root, 1);
-	btrfs_commit_transaction(trans, info->tree_root);
-
-	spin_lock(&block_group->lock);
-	WARN_ON(block_group->pinned > 0);
-	WARN_ON(block_group->reserved > 0);
-	WARN_ON(btrfs_block_group_used(&block_group->item) > 0);
-	spin_unlock(&block_group->lock);
-	btrfs_put_block_group(block_group);
-	ret = 0;
-out:
-	btrfs_free_path(path);
-	return ret;
-}
-#endif
-
 /*
  * checks to see if its even possible to relocate this block group.
  *
-- 
1.5.4.3


^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2022-02-01 14:06 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-26 13:39 btrfs: memory leak on error path error27
2009-03-26 13:42 ` btrfs: dereferencing freed memory Dan Carpenter
2009-03-26 13:45 ` btrfs: returning under lock Dan Carpenter
2009-03-26 13:54 ` unhandled kmallocs remaining Dan Carpenter
2009-03-26 14:04   ` btrfs: [patch] remove dead code Dan Carpenter
2009-03-26 14:10   ` [patch] btrfs: " Dan Carpenter
2009-03-26 14:20   ` [patch] btrfs: remove dead code #3 Dan Carpenter
2009-03-26 14:39     ` Jens Axboe
2009-03-26 14:48       ` Chris Mason
2009-03-26 15:43         ` Jens Axboe
2009-03-26 23:30           ` linux-2.6.29: BUG at fs/btrfs/extent-tree.c:3433 Matteo Frigo
2009-08-24 18:40 [PATCH] Btrfs: remove dead code Josef Bacik
2010-01-07 15:25 [patch] btrfs: " Dan Carpenter
2013-11-29 17:01 [PATCH] " Michal Nazarewicz
2013-11-29 20:00 ` Filipe David Manana
2022-01-28 11:50 [PATCH] btrfs: Remove " Muhammad Usama Anjum
2022-02-01 14:05 ` David Sterba

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.