Re: [REGRESSION] 3.12-rc1: Trying to create snapshot corrupted filesystem

2013-09-20 Thread Josef Bacik
On Sat, Sep 21, 2013 at 12:25:02AM +0200, Martin Steigerwald wrote:
> Hi!
> 
> I tried to create a snapshot today like this:
> 
> merkaba:/mnt/debian-zeit> ls -l
> insgesamt 0
> drwxr-xr-x 1 root root 210 Sep 20 11:48 root
> merkaba:/mnt/debian-zeit> btrfs subvol list /
> ID 256 gen 21382 top level 5 path root
> merkaba:/mnt/debian-zeit> btrfs subvol snap -r root root-2013-09-20
> merkaba:/mnt/debian-zeit#1>
> 

You will want the patch I just sent,

Btrfs: create the uuid tree on remount rw

and that should fix the snapshot problems.  Thanks,

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


[PATCH] Btrfs: create the uuid tree on remount rw

2013-09-20 Thread Josef Bacik
Users have been complaining of the uuid tree stuff warning that there is no uuid
root when trying to do snapshot operations.  This is because if you mount -o ro
we will not create the uuid tree.  But then if you mount -o rw,remount we will
still not create it and then any subsequent snapshot/subvol operations you try
to do will fail gloriously.  Fix this by creating the uuid_root on remount rw if
it was not already there.  Thanks,

Signed-off-by: Josef Bacik 
---
 fs/btrfs/super.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 6ab0df5..05cfd79 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1383,6 +1383,16 @@ static int btrfs_remount(struct super_block *sb, int 
*flags, char *data)
pr_warn("btrfs: failed to resume dev_replace\n");
goto restore;
}
+
+   if (!fs_info->uuid_root) {
+   pr_info("btrfs: creating UUID tree\n");
+   ret = btrfs_create_uuid_tree(fs_info);
+   if (ret) {
+   pr_warn("btrfs: failed to create the uuid "
+   "%d\n", ret);
+   goto restore;
+   }
+   }
sb->s_flags &= ~MS_RDONLY;
}
 out:
-- 
1.8.3.1

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


[PATCH] Btrfs: reset intwrite on transaction abort

2013-09-20 Thread Josef Bacik
If we abort a transaction in the middle of a commit we weren't undoing the
intwrite locking.  This patch fixes that problem.

Signed-off-by: Josef Bacik 
---
 fs/btrfs/transaction.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index e7a9535..2fa7017 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -1552,6 +1552,8 @@ static void cleanup_transaction(struct btrfs_trans_handle 
*trans,
root->fs_info->running_transaction = NULL;
spin_unlock(&root->fs_info->trans_lock);
 
+   if (trans->type & __TRANS_FREEZABLE)
+   sb_end_intwrite(root->fs_info->sb);
put_transaction(cur_trans);
put_transaction(cur_trans);
 
-- 
1.8.3.1

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


Re: [REGRESSION] 3.12-rc1: Trying to create snapshot corrupted filesystem

2013-09-20 Thread Josef Bacik
On Sat, Sep 21, 2013 at 12:25:02AM +0200, Martin Steigerwald wrote:
> Hi!
> 
> I tried to create a snapshot today like this:
> 
> merkaba:/mnt/debian-zeit> ls -l
> insgesamt 0
> drwxr-xr-x 1 root root 210 Sep 20 11:48 root
> merkaba:/mnt/debian-zeit> btrfs subvol list /
> ID 256 gen 21382 top level 5 path root
> merkaba:/mnt/debian-zeit> btrfs subvol snap -r root root-2013-09-20
> merkaba:/mnt/debian-zeit#1>
> 

Nevermind I've reproduced it, sorry about that I will get it fixed up and a
patch sent out right away.  Thanks,

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


Re: [REGRESSION] 3.12-rc1: Trying to create snapshot corrupted filesystem

2013-09-20 Thread Josef Bacik
On Sat, Sep 21, 2013 at 12:25:02AM +0200, Martin Steigerwald wrote:
> Hi!
> 
> I tried to create a snapshot today like this:
> 
> merkaba:/mnt/debian-zeit> ls -l
> insgesamt 0
> drwxr-xr-x 1 root root 210 Sep 20 11:48 root
> merkaba:/mnt/debian-zeit> btrfs subvol list /
> ID 256 gen 21382 top level 5 path root
> merkaba:/mnt/debian-zeit> btrfs subvol snap -r root root-2013-09-20
> merkaba:/mnt/debian-zeit#1>
>

Do you happen to have your messages from the point where you first booted the
3.12 kernel?  Could you attach them please if you do?  Thanks,

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


Re: [PATCH 4/4] Btrfs-progs: add super-recover to recover bad supers

2013-09-20 Thread Wang Shilong
Hello David,

> On Wed, Sep 18, 2013 at 11:31:16PM +0800, Wang Shilong wrote:
 static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path,
 u64 sb_bytenr,
 u64 root_tree_bytenr, int writes,
 -   int partial, int restore)
 +   int partial, int restore,
 +   int run_ioctl)
>>> 
>>> Yet another parameter to __open_ctree_fd, this really needs a cleanup.
>>> (Later is fine.)
>> 
>> I have considered about this, __open_ctree_fd() is a *static* helper, if i 
>> don't
>> add another parameter to it. I have to move out of __open_ctree_fd()  into
>> open_ctree_with_broken_super() which also seems  not good!
> 
> The idea is that all open_ctree* variants will take one parameter that
> accumulates what's currently passed via writes/partial/restore/run_ioctl:
> 
> #define OPEN_CTREE_PARTIAL(1 << 0ULL)
> #define OPEN_CTREE_WRITES (1 << 1ULL)
> etc ...
> 
> static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path,
>u64 sb_bytenr,
>u64 root_tree_bytenr,
>unsigned open_flags)
> 
> and the callers updated accordingly. The calls then look like
> 
> - open_ctree_fs_info_restore(target, 0, 0, 0, 1);
> + open_ctree_fs_info_restore(target, 0, 0, OPEN_CTREE_PARTIAL);

Good idea, i think this should be another patch. 

Thanks,
Wang

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


[REGRESSION] 3.12-rc1: Trying to create snapshot corrupted filesystem

2013-09-20 Thread Martin Steigerwald
Hi!

I tried to create a snapshot today like this:

merkaba:/mnt/debian-zeit> ls -l
insgesamt 0
drwxr-xr-x 1 root root 210 Sep 20 11:48 root
merkaba:/mnt/debian-zeit> btrfs subvol list /
ID 256 gen 21382 top level 5 path root
merkaba:/mnt/debian-zeit> btrfs subvol snap -r root root-2013-09-20
merkaba:/mnt/debian-zeit#1>

on

martin@merkaba:~> cat /proc/version 
Linux version 3.12.0-rc1-tp520 (martin@merkaba) (gcc version 4.8.1 (Debian 
4.8.1-10) ) #30 SMP PREEMPT Tue Sep 17 12:40:01 CEST 2013

and got this:

[   44.069468] [ cut here ]
[   44.073291] WARNING: CPU: 3 PID: 3660 at fs/btrfs/uuid-tree.c:45 
btrfs_uuid_tree_add+0x4e/0x2a0 [btrfs]()
[   44.073345] Modules linked in: ip6table_filter ip6_tables iptable_filter 
ip_tables ebtable_nat ebtables x_tables rfcomm bnep bluetooth cuse nfnetlin
k_queue nfnetlink_log nfnetlink cpufreq_userspace cpufreq_stats 
cpufreq_powersave cpufreq_conservative pci_stub vboxpci(O) vboxnetadp(O) 
vboxnetflt(O) 
vboxdrv(O) binfmt_misc uinput ext4 crc16 mbcache jbd2 fuse ecryptfs sbs sbshc 
joydev hdaps(O) tp_smapi(O) thinkpad_ec(O) loop firewire_sbp2 dm_crypt sn
d_hda_codec_hdmi snd_hda_codec_conexant snd_hda_intel snd_hda_codec snd_hwdep 
snd_pcm_oss snd_mixer_oss x86_pkg_temp_thermal intel_powerclamp coretemp 
snd_pcm kvm_intel kvm snd_page_alloc iwldvm mac80211 microcode snd_seq_midi 
snd_seq_midi_event psmouse iwlwifi pcspkr serio_raw i2c_i801 snd_rawmidi lp
c_ich mfd_core cfg80211 snd_seq snd_seq_device thinkpad_acpi snd_timer tpm_tis 
tpm battery tpm_bios nvram ac rfkill snd evdev soundcore processor btrfs
 xor raid6_pq libcrc32c md_mod dm_mirror dm_region_hash dm_log dm_mod sg sr_mod 
cdrom sd_mod crc_t10dif crct10dif_pclmul crc32_pclmul crc32c_intel ghas
h_clmulni_intel aesni_intel aes_x86_64 lrw gf128mul ahci glue_helper sata_sil24 
ablk_helper libahci cryptd sdhci_pci libata ehci_pci sdhci firewire_ohc
i ehci_hcd mmc_core firewire_core crc_itu_t scsi_mod usbcore e1000e usb_common 
ptp pps_core thermal
[   44.073393] CPU: 3 PID: 3660 Comm: btrfs Tainted: G   O 
3.12.0-rc1-tp520 #30
[   44.073394] Hardware name: LENOVO 42433WG/42433WG, BIOS 8AET63WW (1.43 ) 
05/08/2013
[   44.073398]   880201e57a58 81420f5f 

[   44.073401]  880201e57a90 81036a58 a029928f 
88020f8e11e0
[   44.073404]  880201e57be0  00fb 
880201e57aa0
[   44.073405] Call Trace:
[   44.073413]  [] dump_stack+0x4e/0x82
[   44.073418]  [] warn_slowpath_common+0x7a/0x93
[   44.073451]  [] ? btrfs_uuid_tree_add+0x4e/0x2a0 [btrfs]
[   44.073454]  [] warn_slowpath_null+0x15/0x17
[   44.073484]  [] btrfs_uuid_tree_add+0x4e/0x2a0 [btrfs]
[   44.073511]  [] ? btrfs_update_inode+0x41/0x85 [btrfs]
[   44.073536]  [] create_pending_snapshot+0x605/0x6c5 [btrfs]
[   44.073559]  [] create_pending_snapshots+0x6d/0x89 [btrfs]
[   44.073581]  [] btrfs_commit_transaction+0x3a0/0x857 
[btrfs]
[   44.073610]  [] btrfs_mksubvol.isra.27+0x253/0x37f [btrfs]
[   44.073637]  [] 
btrfs_ioctl_snap_create_transid+0x121/0x151 [btrfs]
[   44.073662]  [] btrfs_ioctl_snap_create_v2+0xcb/0x11c 
[btrfs]
[   44.073688]  [] btrfs_ioctl+0x419/0x1e59 [btrfs]
[   44.073692]  [] ? __do_page_fault+0x33d/0x3b1
[   44.073696]  [] ? __cycles_2_ns+0xd/0x4d
[   44.073701]  [] vfs_ioctl+0x18/0x34
[   44.073704]  [] do_vfs_ioctl+0x32f/0x3e4
[   44.073708]  [] SyS_ioctl+0x52/0x7d
[   44.073712]  [] tracesys+0xdd/0xe2
[   44.073714] ---[ end trace 2968ecf24298c279 ]---
[   44.073716] [ cut here ]
[   44.073743] WARNING: CPU: 3 PID: 3660 at fs/btrfs/uuid-tree.c:109 
btrfs_uuid_tree_add+0x177/0x2a0 [btrfs]()
[   44.073777] Modules linked in: ip6table_filter ip6_tables iptable_filter 
ip_tables ebtable_nat ebtables x_tables rfcomm bnep bluetooth cuse 
nfnetlink_queue nfnetlink_log nfnetlink cpufreq_userspace cpufreq_stats 
cpufreq_powersave cpufreq_conservative pci_stub vboxpci(O) vboxnetadp(O) 
vboxnetflt(O) vboxdrv(O) binfmt_misc uinput ext4 crc16 mbcache jbd2 fuse 
ecryptfs sbs sbshc joydev hdaps(O) tp_smapi(O) thinkpad_ec(O) loop 
firewire_sbp2 dm_crypt snd_hda_codec_hdmi snd_hda_codec_conexant snd_hda_intel 
snd_hda_codec snd_hwdep snd_pcm_oss snd_mixer_oss x86_pkg_temp_thermal 
intel_powerclamp coretemp snd_pcm kvm_intel kvm snd_page_alloc iwldvm mac80211 
microcode snd_seq_midi snd_seq_midi_event psmouse iwlwifi pcspkr serio_raw 
i2c_i801 snd_rawmidi lpc_ich mfd_core cfg80211 snd_seq snd_seq_device 
thinkpad_acpi snd_timer tpm_tis tpm battery tpm_bios nvram ac rfkill snd evdev 
soundcore processor btrfs xor raid6_pq libcrc32c md_mod dm_mirror 
dm_region_hash dm_log dm_mod sg sr_mod cdrom sd_mod crc_t10dif crct10dif_pclmul 
crc32_pclmul crc32c_intel ghash_clmulni_intel aesni_intel aes_x86_64 lrw 
gf128mul ahci glue_helper sata_sil24 ablk_helper libahci cryptd sdhci_pci 
libata ehci_pci sdhci firewire_ohci ehci_hcd mmc_core firewire_core crc_itu_t 
scsi_mod usbcore e1000e usb_common ptp pps_c

Re: Handful of btrfs fixes for 3.11.x stable

2013-09-20 Thread Chris Mason
Quoting David Sterba (2013-09-20 12:34:39)
> Hi stable team,
> 
> please add the following commits to 3.11 tree, they fix user visible problems,
> were tested and are now present in 3.12-rc1.
> 
> 3d05ca371200b3366530621abf73769024581b79
> b13a004528c3e5eb060a26eee795f5a0da7bfe9f
> 7ef67ffda91cc0c56f33937bfdf1d057b9ee96ca
> ca6d07c1d74bf7ba3083bc31a9aeeaa1d0ad86aa

Thanks Dave, I'll pull these into a -stable tree and send a pull
request.

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


[PATCH v2] btrfs-progs: clear_extent_bits: Fix memory leak.

2013-09-20 Thread chandan
The 'prealloc' extent_state structure is leaked for the case when the 'desired
range' encapsulates/covers the 'extent range'.

Signed-off-by: chandan 
---
v1->v2: Fix commit message.
---
 extent_io.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/extent_io.c b/extent_io.c
index acc4702..1c481d5 100644
--- a/extent_io.c
+++ b/extent_io.c
@@ -210,9 +210,11 @@ int clear_extent_bits(struct extent_io_tree *tree, u64 
start,
int set = 0;
 
 again:
-   prealloc = alloc_extent_state();
-   if (!prealloc)
-   return -ENOMEM;
+   if (!prealloc) {
+   prealloc = alloc_extent_state();
+   if (!prealloc)
+   return -ENOMEM;
+   }
 
/*
 * this search will find the extents that end after
-- 
1.8.3.1


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


[PATCH] btrfs-progs: clear_extent_bits: Fix memory leak.

2013-09-20 Thread chandan
The 'prealloc' extent_state structure is leaked for the case when an 'extent
range' encapsulates/covers the 'desired range'.

Signed-off-by: chandan 
---
 extent_io.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/extent_io.c b/extent_io.c
index acc4702..1c481d5 100644
--- a/extent_io.c
+++ b/extent_io.c
@@ -210,9 +210,11 @@ int clear_extent_bits(struct extent_io_tree *tree, u64 
start,
int set = 0;
 
 again:
-   prealloc = alloc_extent_state();
-   if (!prealloc)
-   return -ENOMEM;
+   if (!prealloc) {
+   prealloc = alloc_extent_state();
+   if (!prealloc)
+   return -ENOMEM;
+   }
 
/*
 * this search will find the extents that end after
-- 
1.8.3.1


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


[PATCH] Btrfs-progs: fix the min ticks check in print_seek_histogram

2013-09-20 Thread Josef Bacik
Before I had been dividing by 5 but that gave me too much output so I changed it
to 20 without changing the min seeks test.  Fix this to avoid a divide by 0
problem.  Thanks,

Signed-off-by: Josef Bacik 
---
 btrfs-calc-size.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/btrfs-calc-size.c b/btrfs-calc-size.c
index ab942c6..b2c888c 100644
--- a/btrfs-calc-size.c
+++ b/btrfs-calc-size.c
@@ -228,7 +228,7 @@ static void print_seek_histogram(struct root_stats *stat)
u64 max_seek = stat->max_seek_len;
int digits = 1;
 
-   if (stat->total_seeks < 5)
+   if (stat->total_seeks < 20)
return;
 
while ((max_seek /= 10))
-- 
1.8.3.1

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


Re: [PATCH] Btrfs-progs: add a bunch of new statistics to btrfs-calc-size

2013-09-20 Thread David Sterba
On Fri, Sep 20, 2013 at 11:32:41AM -0400, Josef Bacik wrote:
> I've been wanting to get back to the allocator and make some changes to try 
> and
> fix our fragmenation woes with lots of metadata.  But in order to make these
> changes I need to have something to tell me if my changes are making a real
> measurable difference.  So this patch adds a bunch of new statistics to
> btrfs-calc-size.  It will tell me how long it took to read in the trees, how
> many seeks it had (both forward and backward).  It will tell me how far spread
> out the tree is and spit out a nice histogram of the seeks.  Here is some 
> sample
> output

Nice!

> + /* Make a tick count as 5% of the total seeks */
> + tick_interval = stat->total_seeks / 20;
> + printf("\tSeek histogram\n");
> + for (; n; n = rb_next(n)) {
> + u64 ticks, gticks = 0;
> +
> + seek = rb_entry(n, struct seek, n);
> + ticks = seek->count / tick_interval;
> + if (group_count)
> + gticks = group_count / tick_interval;

Divsion by zero, core dumped.

>   total_size = pretty_sizes(stat.total_bytes);

> + printf("\tTotal size: %s\n", total_size);

>   free(total_size);

There's the pretty_size thing that can be used directly in printf and
without free(). I've switched them all and committed to integration.
Please send a separate fix for the 0-division problem.

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


Re: Handful of btrfs fixes for 3.11.x stable

2013-09-20 Thread Greg KH
On Fri, Sep 20, 2013 at 06:34:39PM +0200, David Sterba wrote:
> Hi stable team,
> 
> please add the following commits to 3.11 tree, they fix user visible problems,
> were tested and are now present in 3.12-rc1.
> 
> 3d05ca371200b3366530621abf73769024581b79
> b13a004528c3e5eb060a26eee795f5a0da7bfe9f
> 7ef67ffda91cc0c56f33937bfdf1d057b9ee96ca
> ca6d07c1d74bf7ba3083bc31a9aeeaa1d0ad86aa
> 
> Josef Bacik (4):
>   Btrfs: reset ret in record_one_backref
>   Btrfs: change how we queue blocks for backref checking
>   Btrfs: skip subvol entries when checking if we've created a dir already
>   Btrfs: remove ourselves from the cluster list under lock

Thanks for this, I'll queue them up soon.  Are any of these applicable
for 3.10 as well?

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] btrfs-progs: fix loop device mount checks

2013-09-20 Thread David Sterba
When creating a fs on a loop device, mkfs checks whether the same file
is not already mounted, but a backing file of another loop dev does not
exist, mkfs fails. This fixes a bug during openSUSE installation.

Signed-off-by: David Sterba 
---
 utils.c | 36 +---
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/utils.c b/utils.c
index 5fa193b..357983d 100644
--- a/utils.c
+++ b/utils.c
@@ -803,11 +803,11 @@ static int is_same_blk_file(const char* a, const char* b)
char real_a[PATH_MAX];
char real_b[PATH_MAX];
 
-   if(!realpath(a, real_a) ||
-  !realpath(b, real_b))
-   {
-   return -errno;
-   }
+   if(!realpath(a, real_a))
+   strcpy(real_a, a);
+
+   if (!realpath(b, real_b))
+   strcpy(real_b, b);
 
/* Identical path? */
if(strcmp(real_a, real_b) == 0)
@@ -848,8 +848,8 @@ static int is_same_loop_file(const char* a, const char* b)
 {
char res_a[PATH_MAX];
char res_b[PATH_MAX];
-   const char* final_a;
-   const char* final_b;
+   const char* final_a = NULL;
+   const char* final_b = NULL;
int ret;
 
/* Resolve a if it is a loop device */
@@ -858,10 +858,13 @@ static int is_same_loop_file(const char* a, const char* b)
return 0;
return ret;
} else if (ret) {
-   if ((ret = resolve_loop_device(a, res_a, sizeof(res_a))) < 0)
-   return ret;
-
-   final_a = res_a;
+   ret = resolve_loop_device(a, res_a, sizeof(res_a));
+   if (ret < 0) {
+   if (errno != EPERM)
+   return ret;
+   } else {
+   final_a = res_a;
+   }
} else {
final_a = a;
}
@@ -872,10 +875,13 @@ static int is_same_loop_file(const char* a, const char* b)
return 0;
return ret;
} else if (ret) {
-   if((ret = resolve_loop_device(b, res_b, sizeof(res_b))) < 0)
-   return ret;
-
-   final_b = res_b;
+   ret = resolve_loop_device(b, res_b, sizeof(res_b));
+   if (ret < 0) {
+   if (errno != EPERM)
+   return ret;
+   } else {
+   final_b = res_b;
+   }
} else {
final_b = b;
}
-- 
1.8.3.1

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


[PATCH] btrfs-progs: check if device supports trim

2013-09-20 Thread David Sterba
The message about trim was printed unconditionally, we should check if
trim is supported at all.

Signed-off-by: David Sterba 
---
 utils.c | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/utils.c b/utils.c
index 5fa193b..6c74654 100644
--- a/utils.c
+++ b/utils.c
@@ -597,13 +597,16 @@ int btrfs_prepare_device(int fd, char *file, int 
zero_end, u64 *block_count_ret,
}
 
if (discard) {
-   fprintf(stderr, "Performing full device TRIM (%s) ...\n",
-   pretty_size(block_count));
/*
-* We intentionally ignore errors from the discard ioctl.  It is
-* not necessary for the mkfs functionality but just an 
optimization.
+* We intentionally ignore errors from the discard ioctl.  It
+* is not necessary for the mkfs functionality but just an
+* optimization.
 */
-   discard_blocks(fd, 0, block_count);
+   if (discard_blocks(fd, 0, 0) == 0) {
+   fprintf(stderr, "Performing full device TRIM (%s) 
...\n",
+   pretty_size(block_count));
+   discard_blocks(fd, 0, block_count);
+   }
}
 
ret = zero_dev_start(fd);
-- 
1.8.3.1

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


Handful of btrfs fixes for 3.11.x stable

2013-09-20 Thread David Sterba
Hi stable team,

please add the following commits to 3.11 tree, they fix user visible problems,
were tested and are now present in 3.12-rc1.

3d05ca371200b3366530621abf73769024581b79
b13a004528c3e5eb060a26eee795f5a0da7bfe9f
7ef67ffda91cc0c56f33937bfdf1d057b9ee96ca
ca6d07c1d74bf7ba3083bc31a9aeeaa1d0ad86aa

Josef Bacik (4):
  Btrfs: reset ret in record_one_backref
  Btrfs: change how we queue blocks for backref checking
  Btrfs: skip subvol entries when checking if we've created a dir already
  Btrfs: remove ourselves from the cluster list under lock

 fs/btrfs/extent-tree.c |  3 ++-
 fs/btrfs/inode.c   |  3 +--
 fs/btrfs/relocation.c  | 14 +++---
 fs/btrfs/send.c|  3 ++-
 4 files changed, 12 insertions(+), 11 deletions(-)
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] Btrfs-progs: add a bunch of new statistics to btrfs-calc-size

2013-09-20 Thread Josef Bacik
I've been wanting to get back to the allocator and make some changes to try and
fix our fragmenation woes with lots of metadata.  But in order to make these
changes I need to have something to tell me if my changes are making a real
measurable difference.  So this patch adds a bunch of new statistics to
btrfs-calc-size.  It will tell me how long it took to read in the trees, how
many seeks it had (both forward and backward).  It will tell me how far spread
out the tree is and spit out a nice histogram of the seeks.  Here is some sample
output

Calculating size of extent tree
Total size: 60.74MB
Inline data: 0.00
Total seeks: 5020
Forward seeks: 3691
Backward seeks: 1329
Avg seek len: 929.53MB
Seek histogram
  4096 -   4096:   1043 
  8192 -  73728:760 ###
 81920 -   52527104:753 ###
  53518336 -  168009728:753 ###
 168591360 -  696045568:753 ###
 696238080 - 7560364032:753 ###
7560437760 - 8409739264:178 |
Total clusters: 1874
Avg cluster size: 25.17KB
Min cluster size: 8.00KB
Max cluster size: 472.00KB
Total disk spread: 7.90GB
Total read time: 0 s 341670 us
Levels: 4

This way we can have good numbers to back up any changes we make to the
allocator.  Thanks,

Signed-off-by: Josef Bacik 
---
 btrfs-calc-size.c | 284 --
 1 file changed, 274 insertions(+), 10 deletions(-)

diff --git a/btrfs-calc-size.c b/btrfs-calc-size.c
index c4adfb0..ab942c6 100644
--- a/btrfs-calc-size.c
+++ b/btrfs-calc-size.c
@@ -24,6 +24,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include "kerncompat.h"
 #include "ctree.h"
@@ -38,11 +40,29 @@
 static int verbose = 0;
 static int no_pretty = 0;
 
+struct seek {
+   u64 distance;
+   u64 count;
+   struct rb_node n;
+};
+
 struct root_stats {
u64 total_nodes;
u64 total_leaves;
u64 total_bytes;
u64 total_inline;
+   u64 total_seeks;
+   u64 forward_seeks;
+   u64 backward_seeks;
+   u64 total_seek_len;
+   u64 max_seek_len;
+   u64 total_clusters;
+   u64 total_cluster_size;
+   u64 min_cluster_size;
+   u64 max_cluster_size;
+   u64 lowest_bytenr;
+   u64 highest_bytenr;
+   struct rb_root seek_root;
int total_levels;
 };
 
@@ -51,6 +71,36 @@ struct fs_root {
struct btrfs_key *snaps;
 };
 
+static int add_seek(struct rb_root *root, u64 dist)
+{
+   struct rb_node **p = &root->rb_node;
+   struct rb_node *parent = NULL;
+   struct seek *seek = NULL;
+
+   while (*p) {
+   parent = *p;
+   seek = rb_entry(parent, struct seek, n);
+
+   if (dist < seek->distance) {
+   p = &(*p)->rb_left;
+   } else if (dist > seek->distance) {
+   p = &(*p)->rb_right;
+   } else {
+   seek->count++;
+   return 0;
+   }
+   }
+
+   seek = malloc(sizeof(struct seek));
+   if (!seek)
+   return -ENOMEM;
+   seek->distance = dist;
+   seek->count = 1;
+   rb_link_node(&seek->n, parent, p);
+   rb_insert_color(&seek->n, root);
+   return 0;
+}
+
 static int walk_leaf(struct btrfs_root *root, struct btrfs_path *path,
 struct root_stats *stat, int find_inline)
 {
@@ -80,22 +130,33 @@ static int walk_leaf(struct btrfs_root *root, struct 
btrfs_path *path,
return 0;
 }
 
+static u64 calc_distance(u64 block1, u64 block2)
+{
+   if (block1 < block2)
+   return block2 - block1;
+   return block1 - block2;
+}
+
 static int walk_nodes(struct btrfs_root *root, struct btrfs_path *path,
  struct root_stats *stat, int level, int find_inline)
 {
struct extent_buffer *b = path->nodes[level];
+   u64 last_block;
+   u64 cluster_size = root->leafsize;
int i;
int ret = 0;
 
stat->total_bytes += root->nodesize;
stat->total_nodes++;
 
+   last_block = btrfs_header_bytenr(b);
for (i = 0; i < btrfs_header_nritems(b); i++) {
struct extent_buffer *tmp = NULL;
+   u64 cur_blocknr = btrfs_node_blockptr(b, i);
 
path->slots[level] = i;
if ((level - 1) > 0 || find_inline) {
-   tmp = read_tree_block(root, btrfs_node_blockptr(b, i),
+   tmp = read_tree_block(root, cur_blocknr,
  btrfs_level_size(root, level - 1),
  btrfs_node_ptr_generation(b, i));
if (!tmp) {

Re: [PATCH] btrfs: remove unused parameter from btrfs_header_fsid

2013-09-20 Thread Eric Sandeen
On 9/20/13 8:27 AM, Ross Kirk wrote:
> Remove unused parameter, 'eb'. Unused since introduction in
> 5f39d397dfbe140a14edecd4e73c34ce23c4f9ee
> 
> Signed-off-by: Ross Kirk 

A few points; was this against latest upstream?

Upstream, fba6aa75654394fccf2530041e9451414c28084f removed
all the superfluous (unsigned long) casts when this function
gets called.  So I think you need to rebase this.

(that commit would be great to apply to userspace as well to keep things
more in sync).

But it seems like this could be cleaned up even more:

static inline unsigned long btrfs_header_fsid(struct extent_buffer *eb)
{
return offsetof(struct btrfs_header, fsid);
}

really?  We have a function which just returns a static value from offsetof?

And to a caveman-code-reader like me, I'd sure expect "btrfs_header_fsid" to
give me an fsid, not an offset of a structure member.  :(

And as for types, I'm not sure why write_extent_buffer takes an unsigned long
for start; if nothing else it seems to actually be used as a size_t inside the
function.  Argh.

Well -

I suppose for now, removing the unused var is a decent start, after you rebase.

btrfs_header_chunk_tree_uuid() could get similar treatments in kernelspace
and/or userspace.  As could btrfs_leaf_data().

Welcome to "peeling the onion."  :)

-Eric

> ---
>  fs/btrfs/ctree.c   |   10 +-
>  fs/btrfs/ctree.h   |2 +-
>  fs/btrfs/disk-io.c |6 +++---
>  fs/btrfs/ioctl.c   |2 +-
>  4 files changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
> index 63cde75..febc672 100644
> --- a/fs/btrfs/ctree.c
> +++ b/fs/btrfs/ctree.c
> @@ -275,7 +275,7 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
>   btrfs_set_header_owner(cow, new_root_objectid);
>  
>   write_extent_buffer(cow, root->fs_info->fsid,
> - (unsigned long)btrfs_header_fsid(cow),
> + (unsigned long)btrfs_header_fsid(),
>   BTRFS_FSID_SIZE);
>  
>   WARN_ON(btrfs_header_generation(buf) > trans->transid);
> @@ -1047,7 +1047,7 @@ static noinline int __btrfs_cow_block(struct 
> btrfs_trans_handle *trans,
>   btrfs_set_header_owner(cow, root->root_key.objectid);
>  
>   write_extent_buffer(cow, root->fs_info->fsid,
> - (unsigned long)btrfs_header_fsid(cow),
> + (unsigned long)btrfs_header_fsid(),
>   BTRFS_FSID_SIZE);
>  
>   ret = update_ref_for_cow(trans, root, buf, cow, &last_ref);
> @@ -3145,7 +3145,7 @@ static noinline int insert_new_root(struct 
> btrfs_trans_handle *trans,
>   btrfs_set_header_owner(c, root->root_key.objectid);
>  
>   write_extent_buffer(c, root->fs_info->fsid,
> - (unsigned long)btrfs_header_fsid(c),
> + (unsigned long)btrfs_header_fsid(),
>   BTRFS_FSID_SIZE);
>  
>   write_extent_buffer(c, root->fs_info->chunk_tree_uuid,
> @@ -3285,7 +3285,7 @@ static noinline int split_node(struct 
> btrfs_trans_handle *trans,
>   btrfs_set_header_backref_rev(split, BTRFS_MIXED_BACKREF_REV);
>   btrfs_set_header_owner(split, root->root_key.objectid);
>   write_extent_buffer(split, root->fs_info->fsid,
> - (unsigned long)btrfs_header_fsid(split),
> + (unsigned long)btrfs_header_fsid(),
>   BTRFS_FSID_SIZE);
>   write_extent_buffer(split, root->fs_info->chunk_tree_uuid,
>   (unsigned long)btrfs_header_chunk_tree_uuid(split),
> @@ -4041,7 +4041,7 @@ again:
>   btrfs_set_header_owner(right, root->root_key.objectid);
>   btrfs_set_header_level(right, 0);
>   write_extent_buffer(right, root->fs_info->fsid,
> - (unsigned long)btrfs_header_fsid(right),
> + (unsigned long)btrfs_header_fsid(),
>   BTRFS_FSID_SIZE);
>  
>   write_extent_buffer(right, root->fs_info->chunk_tree_uuid,
> diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> index e0bab4d..972a2f8 100644
> --- a/fs/btrfs/ctree.h
> +++ b/fs/btrfs/ctree.h
> @@ -2602,7 +2602,7 @@ static inline void btrfs_set_header_backref_rev(struct 
> extent_buffer *eb,
>   btrfs_set_header_flags(eb, flags);
>  }
>  
> -static inline u8 *btrfs_header_fsid(struct extent_buffer *eb)
> +static inline u8 *btrfs_header_fsid(void)
>  {
>   unsigned long ptr = offsetof(struct btrfs_header, fsid);
>   return (u8 *)ptr;
> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> index 3c2886c..e038693 100644
> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
> @@ -497,7 +497,7 @@ static int check_tree_block_fsid(struct btrfs_root *root,
>   u8 fsid[BTRFS_UUID_SIZE];
>   int ret = 1;
>  
> - read_extent_buffer(eb, fsid, (unsigned long)btrfs_header_fsid(eb),
> + read_extent_buffer(eb, fsid, (unsigned long)btrfs_header_fsid(),
> 

Re: [PATCH] btrfs-progs: drop unused parameter from btrfs_item_nr

2013-09-20 Thread Eric Sandeen
On 9/20/13 4:55 AM, Ross Kirk wrote:
> Remove unused eb parameter from btrfs_item_nr, unused since introduced
> in e63b425f1444d2472ea05a6b2b9cf865f35b
> 
> Signed-off-by: Ross Kirk 

I think the only possible reason to keep it is for consistency
with every other btrfs_item_$FOO() which does take a 
struct extent_buffer as the first arg.

But on technical terms anyway,

Reviewed-by: Eric Sandeen 

Thanks,
-Eric

> ---
>  btrfs-calc-size.c |2 +-
>  btrfs-image.c |6 +++---
>  cmds-restore.c|2 +-
>  ctree.c   |   30 +++---
>  ctree.h   |   13 ++---
>  dir-item.c|2 +-
>  print-tree.c  |2 +-
>  root-tree.c   |2 +-
>  utils.c   |   36 ++--
>  9 files changed, 47 insertions(+), 48 deletions(-)
> 
> diff --git a/btrfs-calc-size.c b/btrfs-calc-size.c
> index c4adfb0..ba0d42d 100644
> --- a/btrfs-calc-size.c
> +++ b/btrfs-calc-size.c
> @@ -74,7 +74,7 @@ static int walk_leaf(struct btrfs_root *root, struct 
> btrfs_path *path,
>   if (btrfs_file_extent_type(b, fi) == BTRFS_FILE_EXTENT_INLINE)
>   stat->total_inline +=
>   btrfs_file_extent_inline_item_len(b,
> - btrfs_item_nr(b, i));
> + btrfs_item_nr(i));
>   }
>  
>   return 0;
> diff --git a/btrfs-image.c b/btrfs-image.c
> index 82aa4f3..879ca72 100644
> --- a/btrfs-image.c
> +++ b/btrfs-image.c
> @@ -494,7 +494,7 @@ static void zero_items(struct metadump_struct *md, u8 
> *dst,
>   int i, extent_type;
>  
>   for (i = 0; i < nritems; i++) {
> - item = btrfs_item_nr(src, i);
> + item = btrfs_item_nr(i);
>   btrfs_item_key_to_cpu(src, &key, i);
>   if (key.type == BTRFS_CSUM_ITEM_KEY) {
>   size = btrfs_item_size_nr(src, i);
> @@ -1437,7 +1437,7 @@ static void truncate_item(struct extent_buffer *eb, int 
> slot, u32 new_size)
>  
>   for (i = slot; i < nritems; i++) {
>   u32 ioff;
> - item = btrfs_item_nr(eb, i);
> + item = btrfs_item_nr(i);
>   ioff = btrfs_item_offset(eb, item);
>   btrfs_set_item_offset(eb, item, ioff + size_diff);
>   }
> @@ -1445,7 +1445,7 @@ static void truncate_item(struct extent_buffer *eb, int 
> slot, u32 new_size)
>   memmove_extent_buffer(eb, btrfs_leaf_data(eb) + data_end + size_diff,
> btrfs_leaf_data(eb) + data_end,
> old_data_start + new_size - data_end);
> - item = btrfs_item_nr(eb, slot);
> + item = btrfs_item_nr(slot);
>   btrfs_set_item_size(eb, item, new_size);
>  }
>  
> diff --git a/cmds-restore.c b/cmds-restore.c
> index e48df40..6db6598 100644
> --- a/cmds-restore.c
> +++ b/cmds-restore.c
> @@ -223,7 +223,7 @@ static int copy_one_inline(int fd, struct btrfs_path 
> *path, u64 pos)
>   struct btrfs_file_extent_item);
>   ptr = btrfs_file_extent_inline_start(fi);
>   len = btrfs_file_extent_inline_item_len(leaf,
> - btrfs_item_nr(leaf, path->slots[0]));
> + btrfs_item_nr(path->slots[0]));
>   read_extent_buffer(leaf, buf, ptr, len);
>  
>   compress = btrfs_file_extent_compression(leaf, fi);
> diff --git a/ctree.c b/ctree.c
> index 1a4f3f0..c42c84f 100644
> --- a/ctree.c
> +++ b/ctree.c
> @@ -1792,7 +1792,7 @@ static int push_leaf_right(struct btrfs_trans_handle 
> *trans, struct btrfs_root
>  
>   i = left_nritems - 1;
>   while (i >= nr) {
> - item = btrfs_item_nr(left, i);
> + item = btrfs_item_nr(i);
>  
>   if (path->slots[0] == i)
>   push_space += data_size + sizeof(*item);
> @@ -1848,7 +1848,7 @@ static int push_leaf_right(struct btrfs_trans_handle 
> *trans, struct btrfs_root
>   btrfs_set_header_nritems(right, right_nritems);
>   push_space = BTRFS_LEAF_DATA_SIZE(root);
>   for (i = 0; i < right_nritems; i++) {
> - item = btrfs_item_nr(right, i);
> + item = btrfs_item_nr(i);
>   push_space -= btrfs_item_size(right, item);
>   btrfs_set_item_offset(right, item, push_space);
>   }
> @@ -1939,7 +1939,7 @@ static int push_leaf_left(struct btrfs_trans_handle 
> *trans, struct btrfs_root
>   nr = right_nritems - 1;
>  
>   for (i = 0; i < nr; i++) {
> - item = btrfs_item_nr(right, i);
> + item = btrfs_item_nr(i);
>  
>   if (path->slots[0] == i)
>   push_space += data_size + sizeof(*item);
> @@ -1980,7 +1980,7 @@ static int push_leaf_left(struct btrfs_trans_handle 
> *trans, struct btrfs_root
>   for (i = old_left_nritems; i < old_left_nritems + push_items; i++) {
>   u32 ioff;
>  

[PATCH] Btrfs: remove path arg from btrfs_truncate_free_space_cache

2013-09-20 Thread Filipe David Borba Manana
Not used for anything, and removing it avoids caller's need to
allocate a path structure.

Signed-off-by: Filipe David Borba Manana 
---
 fs/btrfs/extent-tree.c  |3 +--
 fs/btrfs/free-space-cache.c |1 -
 fs/btrfs/free-space-cache.h |1 -
 fs/btrfs/inode-map.c|2 +-
 fs/btrfs/relocation.c   |   11 +--
 5 files changed, 3 insertions(+), 15 deletions(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index d58bef1..55b537f 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -3197,8 +3197,7 @@ again:
if (ret)
goto out_put;
 
-   ret = btrfs_truncate_free_space_cache(root, trans, path,
- inode);
+   ret = btrfs_truncate_free_space_cache(root, trans, inode);
if (ret)
goto out_put;
}
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index 38e3779..7fd48df 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -218,7 +218,6 @@ int btrfs_check_trunc_cache_free_space(struct btrfs_root 
*root,
 
 int btrfs_truncate_free_space_cache(struct btrfs_root *root,
struct btrfs_trans_handle *trans,
-   struct btrfs_path *path,
struct inode *inode)
 {
loff_t oldsize;
diff --git a/fs/btrfs/free-space-cache.h b/fs/btrfs/free-space-cache.h
index ba8d5a1..0cf4977 100644
--- a/fs/btrfs/free-space-cache.h
+++ b/fs/btrfs/free-space-cache.h
@@ -58,7 +58,6 @@ int btrfs_check_trunc_cache_free_space(struct btrfs_root 
*root,
   struct btrfs_block_rsv *rsv);
 int btrfs_truncate_free_space_cache(struct btrfs_root *root,
struct btrfs_trans_handle *trans,
-   struct btrfs_path *path,
struct inode *inode);
 int load_free_space_cache(struct btrfs_fs_info *fs_info,
  struct btrfs_block_group_cache *block_group);
diff --git a/fs/btrfs/inode-map.c b/fs/btrfs/inode-map.c
index b863e45..014de49 100644
--- a/fs/btrfs/inode-map.c
+++ b/fs/btrfs/inode-map.c
@@ -466,7 +466,7 @@ again:
}
 
if (i_size_read(inode) > 0) {
-   ret = btrfs_truncate_free_space_cache(root, trans, path, inode);
+   ret = btrfs_truncate_free_space_cache(root, trans, inode);
if (ret) {
if (ret != -ENOSPC)
btrfs_abort_transaction(trans, root, ret);
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index a5a2632..5ca7ea9 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -3407,7 +3407,6 @@ static int delete_block_group_cache(struct btrfs_fs_info 
*fs_info,
struct inode *inode, u64 ino)
 {
struct btrfs_key key;
-   struct btrfs_path *path;
struct btrfs_root *root = fs_info->tree_root;
struct btrfs_trans_handle *trans;
int ret = 0;
@@ -3432,22 +3431,14 @@ truncate:
if (ret)
goto out;
 
-   path = btrfs_alloc_path();
-   if (!path) {
-   ret = -ENOMEM;
-   goto out;
-   }
-
trans = btrfs_join_transaction(root);
if (IS_ERR(trans)) {
-   btrfs_free_path(path);
ret = PTR_ERR(trans);
goto out;
}
 
-   ret = btrfs_truncate_free_space_cache(root, trans, path, inode);
+   ret = btrfs_truncate_free_space_cache(root, trans, inode);
 
-   btrfs_free_path(path);
btrfs_end_transaction(trans, root);
btrfs_btree_balance_dirty(root);
 out:
-- 
1.7.9.5

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


[PATCH] Btrfs: remove duplicated ino cache's inode lookup

2013-09-20 Thread Filipe David Borba Manana
We're doing a unnecessary extra lookup of the ino cache's
inode when we already have it (and holding a reference)
during the process of saving the ino cache contents to disk.
Therefore remove this extra lookup.

Signed-off-by: Filipe David Borba Manana 
---
 fs/btrfs/free-space-cache.c |9 ++---
 fs/btrfs/free-space-cache.h |3 ++-
 fs/btrfs/inode-map.c|2 +-
 3 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index 4f419ba..38e3779 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -2969,19 +2969,15 @@ out:
 
 int btrfs_write_out_ino_cache(struct btrfs_root *root,
  struct btrfs_trans_handle *trans,
- struct btrfs_path *path)
+ struct btrfs_path *path,
+ struct inode *inode)
 {
struct btrfs_free_space_ctl *ctl = root->free_ino_ctl;
-   struct inode *inode;
int ret;
 
if (!btrfs_test_opt(root, INODE_MAP_CACHE))
return 0;
 
-   inode = lookup_free_ino_inode(root, path);
-   if (IS_ERR(inode))
-   return 0;
-
ret = __btrfs_write_out_cache(root, inode, ctl, NULL, trans, path, 0);
if (ret) {
btrfs_delalloc_release_metadata(inode, inode->i_size);
@@ -2992,7 +2988,6 @@ int btrfs_write_out_ino_cache(struct btrfs_root *root,
 #endif
}
 
-   iput(inode);
return ret;
 }
 
diff --git a/fs/btrfs/free-space-cache.h b/fs/btrfs/free-space-cache.h
index e737f92..ba8d5a1 100644
--- a/fs/btrfs/free-space-cache.h
+++ b/fs/btrfs/free-space-cache.h
@@ -76,7 +76,8 @@ int load_free_ino_cache(struct btrfs_fs_info *fs_info,
struct btrfs_root *root);
 int btrfs_write_out_ino_cache(struct btrfs_root *root,
  struct btrfs_trans_handle *trans,
- struct btrfs_path *path);
+ struct btrfs_path *path,
+ struct inode *inode);
 
 void btrfs_init_free_space_ctl(struct btrfs_block_group_cache *block_group);
 int __btrfs_add_free_space(struct btrfs_free_space_ctl *ctl,
diff --git a/fs/btrfs/inode-map.c b/fs/btrfs/inode-map.c
index d11e1c6..b863e45 100644
--- a/fs/btrfs/inode-map.c
+++ b/fs/btrfs/inode-map.c
@@ -503,7 +503,7 @@ again:
}
btrfs_free_reserved_data_space(inode, prealloc);
 
-   ret = btrfs_write_out_ino_cache(root, trans, path);
+   ret = btrfs_write_out_ino_cache(root, trans, path, inode);
 out_put:
iput(inode);
 out_release:
-- 
1.7.9.5

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


[PATCH] btrfs-progs: remove unused parameter from btrfs_header_fsid

2013-09-20 Thread Ross Kirk
Remove unused parameter, 'eb'. Unused since introduction in
e63b425f1444d2472ea05a6b2b9cf865f35b

Signed-off-by: Ross Kirk 
---
 cmds-chunk.c |4 ++--
 ctree.c  |   12 ++--
 ctree.h  |2 +-
 disk-io.c|2 +-
 print-tree.c |2 +-
 utils.c  |2 +-
 6 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/cmds-chunk.c b/cmds-chunk.c
index 03314de..c83958e 100644
--- a/cmds-chunk.c
+++ b/cmds-chunk.c
@@ -743,7 +743,7 @@ static int scan_one_device(struct recover_control *rc, int 
fd,
break;
 
if (memcmp_extent_buffer(buf, rc->fs_devices->fsid,
-(unsigned long)btrfs_header_fsid(buf),
+(unsigned long)btrfs_header_fsid(),
 BTRFS_FSID_SIZE)) {
bytenr += rc->sectorsize;
continue;
@@ -1044,7 +1044,7 @@ static int __rebuild_chunk_root(struct btrfs_trans_handle 
*trans,
btrfs_set_header_backref_rev(cow, BTRFS_MIXED_BACKREF_REV);
btrfs_set_header_owner(cow, BTRFS_CHUNK_TREE_OBJECTID);
write_extent_buffer(cow, root->fs_info->fsid,
-   (unsigned long)btrfs_header_fsid(cow),
+   (unsigned long)btrfs_header_fsid(),
BTRFS_FSID_SIZE);
 
write_extent_buffer(cow, root->fs_info->chunk_tree_uuid,
diff --git a/ctree.c b/ctree.c
index c42c84f..e86703b 100644
--- a/ctree.c
+++ b/ctree.c
@@ -122,7 +122,7 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
btrfs_set_header_owner(cow, new_root_objectid);
 
write_extent_buffer(cow, root->fs_info->fsid,
-   (unsigned long)btrfs_header_fsid(cow),
+   (unsigned long)btrfs_header_fsid(),
BTRFS_FSID_SIZE);
 
WARN_ON(btrfs_header_generation(buf) > trans->transid);
@@ -169,7 +169,7 @@ init:
btrfs_set_header_owner(c, root->root_key.objectid);
 
write_extent_buffer(c, root->fs_info->fsid,
-   (unsigned long)btrfs_header_fsid(c),
+   (unsigned long)btrfs_header_fsid(),
BTRFS_FSID_SIZE);
 
write_extent_buffer(c, root->fs_info->chunk_tree_uuid,
@@ -343,7 +343,7 @@ int __btrfs_cow_block(struct btrfs_trans_handle *trans,
btrfs_set_header_owner(cow, root->root_key.objectid);
 
write_extent_buffer(cow, root->fs_info->fsid,
-   (unsigned long)btrfs_header_fsid(cow),
+   (unsigned long)btrfs_header_fsid(),
BTRFS_FSID_SIZE);
 
WARN_ON(btrfs_header_generation(buf) > trans->transid);
@@ -1529,7 +1529,7 @@ static int noinline insert_new_root(struct 
btrfs_trans_handle *trans,
btrfs_set_header_owner(c, root->root_key.objectid);
 
write_extent_buffer(c, root->fs_info->fsid,
-   (unsigned long)btrfs_header_fsid(c),
+   (unsigned long)btrfs_header_fsid(),
BTRFS_FSID_SIZE);
 
write_extent_buffer(c, root->fs_info->chunk_tree_uuid,
@@ -1650,7 +1650,7 @@ static int split_node(struct btrfs_trans_handle *trans, 
struct btrfs_root
btrfs_set_header_backref_rev(split, BTRFS_MIXED_BACKREF_REV);
btrfs_set_header_owner(split, root->root_key.objectid);
write_extent_buffer(split, root->fs_info->fsid,
-   (unsigned long)btrfs_header_fsid(split),
+   (unsigned long)btrfs_header_fsid(),
BTRFS_FSID_SIZE);
write_extent_buffer(split, root->fs_info->chunk_tree_uuid,
(unsigned long)btrfs_header_chunk_tree_uuid(split),
@@ -2211,7 +2211,7 @@ again:
btrfs_set_header_owner(right, root->root_key.objectid);
btrfs_set_header_level(right, 0);
write_extent_buffer(right, root->fs_info->fsid,
-   (unsigned long)btrfs_header_fsid(right),
+   (unsigned long)btrfs_header_fsid(),
BTRFS_FSID_SIZE);
 
write_extent_buffer(right, root->fs_info->chunk_tree_uuid,
diff --git a/ctree.h b/ctree.h
index 7f40b3b..6b29d05 100644
--- a/ctree.h
+++ b/ctree.h
@@ -1747,7 +1747,7 @@ static inline void btrfs_set_header_backref_rev(struct 
extent_buffer *eb,
btrfs_set_header_flags(eb, flags);
 }
 
-static inline u8 *btrfs_header_fsid(struct extent_buffer *eb)
+static inline u8 *btrfs_header_fsid(void)
 {
unsigned long ptr = offsetof(struct btrfs_header, fsid);
return (u8 *)ptr;
diff --git a/disk-io.c b/disk-io.c
index 13dbe27..2ab0612 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -50,7 +50,7 @@ static int check_tree_block(struct btrfs_root *root, struct 
extent_buffer *buf)
fs_devices = root->fs_info->fs_devices;
while (fs_devices) 

[PATCH] btrfs: remove unused parameter from btrfs_header_fsid

2013-09-20 Thread Ross Kirk
Remove unused parameter, 'eb'. Unused since introduction in
5f39d397dfbe140a14edecd4e73c34ce23c4f9ee

Signed-off-by: Ross Kirk 
---
 fs/btrfs/ctree.c   |   10 +-
 fs/btrfs/ctree.h   |2 +-
 fs/btrfs/disk-io.c |6 +++---
 fs/btrfs/ioctl.c   |2 +-
 4 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 63cde75..febc672 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -275,7 +275,7 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
btrfs_set_header_owner(cow, new_root_objectid);
 
write_extent_buffer(cow, root->fs_info->fsid,
-   (unsigned long)btrfs_header_fsid(cow),
+   (unsigned long)btrfs_header_fsid(),
BTRFS_FSID_SIZE);
 
WARN_ON(btrfs_header_generation(buf) > trans->transid);
@@ -1047,7 +1047,7 @@ static noinline int __btrfs_cow_block(struct 
btrfs_trans_handle *trans,
btrfs_set_header_owner(cow, root->root_key.objectid);
 
write_extent_buffer(cow, root->fs_info->fsid,
-   (unsigned long)btrfs_header_fsid(cow),
+   (unsigned long)btrfs_header_fsid(),
BTRFS_FSID_SIZE);
 
ret = update_ref_for_cow(trans, root, buf, cow, &last_ref);
@@ -3145,7 +3145,7 @@ static noinline int insert_new_root(struct 
btrfs_trans_handle *trans,
btrfs_set_header_owner(c, root->root_key.objectid);
 
write_extent_buffer(c, root->fs_info->fsid,
-   (unsigned long)btrfs_header_fsid(c),
+   (unsigned long)btrfs_header_fsid(),
BTRFS_FSID_SIZE);
 
write_extent_buffer(c, root->fs_info->chunk_tree_uuid,
@@ -3285,7 +3285,7 @@ static noinline int split_node(struct btrfs_trans_handle 
*trans,
btrfs_set_header_backref_rev(split, BTRFS_MIXED_BACKREF_REV);
btrfs_set_header_owner(split, root->root_key.objectid);
write_extent_buffer(split, root->fs_info->fsid,
-   (unsigned long)btrfs_header_fsid(split),
+   (unsigned long)btrfs_header_fsid(),
BTRFS_FSID_SIZE);
write_extent_buffer(split, root->fs_info->chunk_tree_uuid,
(unsigned long)btrfs_header_chunk_tree_uuid(split),
@@ -4041,7 +4041,7 @@ again:
btrfs_set_header_owner(right, root->root_key.objectid);
btrfs_set_header_level(right, 0);
write_extent_buffer(right, root->fs_info->fsid,
-   (unsigned long)btrfs_header_fsid(right),
+   (unsigned long)btrfs_header_fsid(),
BTRFS_FSID_SIZE);
 
write_extent_buffer(right, root->fs_info->chunk_tree_uuid,
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index e0bab4d..972a2f8 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -2602,7 +2602,7 @@ static inline void btrfs_set_header_backref_rev(struct 
extent_buffer *eb,
btrfs_set_header_flags(eb, flags);
 }
 
-static inline u8 *btrfs_header_fsid(struct extent_buffer *eb)
+static inline u8 *btrfs_header_fsid(void)
 {
unsigned long ptr = offsetof(struct btrfs_header, fsid);
return (u8 *)ptr;
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 3c2886c..e038693 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -497,7 +497,7 @@ static int check_tree_block_fsid(struct btrfs_root *root,
u8 fsid[BTRFS_UUID_SIZE];
int ret = 1;
 
-   read_extent_buffer(eb, fsid, (unsigned long)btrfs_header_fsid(eb),
+   read_extent_buffer(eb, fsid, (unsigned long)btrfs_header_fsid(),
   BTRFS_FSID_SIZE);
while (fs_devices) {
if (!memcmp(fsid, fs_devices->fsid, BTRFS_FSID_SIZE)) {
@@ -1291,7 +1291,7 @@ struct btrfs_root *btrfs_create_tree(struct 
btrfs_trans_handle *trans,
root->node = leaf;
 
write_extent_buffer(leaf, fs_info->fsid,
-   (unsigned long)btrfs_header_fsid(leaf),
+   (unsigned long)btrfs_header_fsid(),
BTRFS_FSID_SIZE);
write_extent_buffer(leaf, fs_info->chunk_tree_uuid,
(unsigned long)btrfs_header_chunk_tree_uuid(leaf),
@@ -1378,7 +1378,7 @@ static struct btrfs_root *alloc_log_tree(struct 
btrfs_trans_handle *trans,
root->node = leaf;
 
write_extent_buffer(root->node, root->fs_info->fsid,
-   (unsigned long)btrfs_header_fsid(root->node),
+   (unsigned long)btrfs_header_fsid(),
BTRFS_FSID_SIZE);
btrfs_mark_buffer_dirty(root->node);
btrfs_tree_unlock(root->node);
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 0e17a30..464e569 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -426,7 +426,7 @@ static noinline int create_subvol(struct

[PATCH] btrfs-progs: drop unused parameter from btrfs_item_nr

2013-09-20 Thread Ross Kirk
Remove unused eb parameter from btrfs_item_nr, unused since introduced
in e63b425f1444d2472ea05a6b2b9cf865f35b

Signed-off-by: Ross Kirk 
---
 btrfs-calc-size.c |2 +-
 btrfs-image.c |6 +++---
 cmds-restore.c|2 +-
 ctree.c   |   30 +++---
 ctree.h   |   13 ++---
 dir-item.c|2 +-
 print-tree.c  |2 +-
 root-tree.c   |2 +-
 utils.c   |   36 ++--
 9 files changed, 47 insertions(+), 48 deletions(-)

diff --git a/btrfs-calc-size.c b/btrfs-calc-size.c
index c4adfb0..ba0d42d 100644
--- a/btrfs-calc-size.c
+++ b/btrfs-calc-size.c
@@ -74,7 +74,7 @@ static int walk_leaf(struct btrfs_root *root, struct 
btrfs_path *path,
if (btrfs_file_extent_type(b, fi) == BTRFS_FILE_EXTENT_INLINE)
stat->total_inline +=
btrfs_file_extent_inline_item_len(b,
-   btrfs_item_nr(b, i));
+   btrfs_item_nr(i));
}
 
return 0;
diff --git a/btrfs-image.c b/btrfs-image.c
index 82aa4f3..879ca72 100644
--- a/btrfs-image.c
+++ b/btrfs-image.c
@@ -494,7 +494,7 @@ static void zero_items(struct metadump_struct *md, u8 *dst,
int i, extent_type;
 
for (i = 0; i < nritems; i++) {
-   item = btrfs_item_nr(src, i);
+   item = btrfs_item_nr(i);
btrfs_item_key_to_cpu(src, &key, i);
if (key.type == BTRFS_CSUM_ITEM_KEY) {
size = btrfs_item_size_nr(src, i);
@@ -1437,7 +1437,7 @@ static void truncate_item(struct extent_buffer *eb, int 
slot, u32 new_size)
 
for (i = slot; i < nritems; i++) {
u32 ioff;
-   item = btrfs_item_nr(eb, i);
+   item = btrfs_item_nr(i);
ioff = btrfs_item_offset(eb, item);
btrfs_set_item_offset(eb, item, ioff + size_diff);
}
@@ -1445,7 +1445,7 @@ static void truncate_item(struct extent_buffer *eb, int 
slot, u32 new_size)
memmove_extent_buffer(eb, btrfs_leaf_data(eb) + data_end + size_diff,
  btrfs_leaf_data(eb) + data_end,
  old_data_start + new_size - data_end);
-   item = btrfs_item_nr(eb, slot);
+   item = btrfs_item_nr(slot);
btrfs_set_item_size(eb, item, new_size);
 }
 
diff --git a/cmds-restore.c b/cmds-restore.c
index e48df40..6db6598 100644
--- a/cmds-restore.c
+++ b/cmds-restore.c
@@ -223,7 +223,7 @@ static int copy_one_inline(int fd, struct btrfs_path *path, 
u64 pos)
struct btrfs_file_extent_item);
ptr = btrfs_file_extent_inline_start(fi);
len = btrfs_file_extent_inline_item_len(leaf,
-   btrfs_item_nr(leaf, path->slots[0]));
+   btrfs_item_nr(path->slots[0]));
read_extent_buffer(leaf, buf, ptr, len);
 
compress = btrfs_file_extent_compression(leaf, fi);
diff --git a/ctree.c b/ctree.c
index 1a4f3f0..c42c84f 100644
--- a/ctree.c
+++ b/ctree.c
@@ -1792,7 +1792,7 @@ static int push_leaf_right(struct btrfs_trans_handle 
*trans, struct btrfs_root
 
i = left_nritems - 1;
while (i >= nr) {
-   item = btrfs_item_nr(left, i);
+   item = btrfs_item_nr(i);
 
if (path->slots[0] == i)
push_space += data_size + sizeof(*item);
@@ -1848,7 +1848,7 @@ static int push_leaf_right(struct btrfs_trans_handle 
*trans, struct btrfs_root
btrfs_set_header_nritems(right, right_nritems);
push_space = BTRFS_LEAF_DATA_SIZE(root);
for (i = 0; i < right_nritems; i++) {
-   item = btrfs_item_nr(right, i);
+   item = btrfs_item_nr(i);
push_space -= btrfs_item_size(right, item);
btrfs_set_item_offset(right, item, push_space);
}
@@ -1939,7 +1939,7 @@ static int push_leaf_left(struct btrfs_trans_handle 
*trans, struct btrfs_root
nr = right_nritems - 1;
 
for (i = 0; i < nr; i++) {
-   item = btrfs_item_nr(right, i);
+   item = btrfs_item_nr(i);
 
if (path->slots[0] == i)
push_space += data_size + sizeof(*item);
@@ -1980,7 +1980,7 @@ static int push_leaf_left(struct btrfs_trans_handle 
*trans, struct btrfs_root
for (i = old_left_nritems; i < old_left_nritems + push_items; i++) {
u32 ioff;
 
-   item = btrfs_item_nr(left, i);
+   item = btrfs_item_nr(i);
ioff = btrfs_item_offset(left, item);
btrfs_set_item_offset(left, item,
  ioff - (BTRFS_LEAF_DATA_SIZE(root) - old_left_item_size));
@@ -2010,7 +2010,7 @@ static int push_leaf_left(struct btrfs_trans_handle 
*trans, struct btrfs_root
btrfs_set_

Re: [PATCH] Btrfs: allocate the free space by the existed max extent size when ENOSPC

2013-09-20 Thread David Sterba
On Wed, Sep 18, 2013 at 12:04:30PM +0800, Miao Xie wrote:
> On Tue, 17 Sep 2013 15:13:12 +0200, David Sterba wrote:
> > On Mon, Sep 09, 2013 at 02:21:58PM +0800, Miao Xie wrote:
> >> On fri, 06 Sep 2013 15:47:08 +0200, Stefan Behrens wrote:
> > The massive slowdown is present in current 3.12-rc code, which means V3
> > did not make it into the pull.
> > 
> > Miao please send an incremental fix for rc2.
> 
> This patch has not been merged into 3.12-rc, so the above problem should be
> introduced by other patch.

Sorry, my oversight.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: rootfs crash

2013-09-20 Thread Jogi Hofmüller
Hi,

Am 2013-09-20 06:49, schrieb Jérôme Poulin:

> Did you make sure you aren't working with a dead SSD?

The SSDs are working quite fine.  I was worried about that too, but
since I managed to get raw disk images using `dd` I was pretty sure they
were alright.  In fact I reinstalled Debian on the Laptop and am using
it to write this email right now ;)

> That would make everything much more complicated than it should be. I
> also had a Zenbook from Asus with SSD with Btrfs, and it died 2
> months ago. It couldn't handle Btrfs for more than 6 months. Either
> those SSDs are weak or Btrfs really is an SSD killer even though it
> is a COW FS.

That sounds bad!  I will have a close look on the devices.

Regards!
-- 
j.hofmüller

Optimism doesn't alter the laws of physics. - Subcommander T'Pol



signature.asc
Description: OpenPGP digital signature