Persoonlijke en beleggingslening.

2018-03-26 Thread Funding Trusts Finance


-- 
Goede dag,
  
We zijn Funding Trusts Finance verstrekt leningen per postadvertentie. Wij 
bieden verschillende soorten leningen of projectleningen (korte en lange 
termijnleningen, persoonlijke leningen, leningen aan bedrijven enz.) Met een 
rentetarief van 3%. We verstrekken leningen aan mensen in nood, ongeacht hun 
locatie, geslacht, burgerlijke staat, opleiding of baan, maar moeten een legale 
manier van terugbetaling hebben. Onze leningen variëren tussen 5.000,00 
tot 20.000.000,00 US Dollar of Euro of Pond met een maximale duur van 15 jaar. 
Als u geïnteresseerd bent in meer informatie, hebben we investeerders die 
geïnteresseerd zijn in het financieren van projecten van groot volume. De 
procedures zijn als volgt: -

1-De klant moet een korte samenvatting van het project verzenden. Dit moet het 
totale bedrag omvatten dat vereist is voor het project, geschat rendement op 
investering, terugbetalingsperiode van de lening, dit mag niet meer dan 20 jaar 
zijn

Neem contact met ons op: i...@fundingtrustsfinance.com

INFORMATIE NODIG

Jullie namen:
Adres: ...
Telefoon: ...
Benodigde hoeveelheid: ...
Looptijd: ...
Beroep: ...
Maandelijks inkomensniveau: ..
Geslacht: ..
Geboortedatum: ...
Staat: ...
Land: .
Doel: .

"Miljoenen mensen in de wereld hebben een kredietprobleem van een of andere 
vorm. Je bent niet de enige. We hebben een hele reeks leningopties die kunnen 
helpen. Ontdek nu je opties!"

Met vriendelijke groet,
Ronny Hens,
i...@fundingtrustsfinance.com
WEBSITE: www.fundingtrustfinance.com
--
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


Persoonlijke en beleggingslening.

2018-03-26 Thread Funding Trusts Finance


-- 
Goede dag,
  
We zijn Funding Trusts Finance verstrekt leningen per postadvertentie. Wij 
bieden verschillende soorten leningen of projectleningen (korte en lange 
termijnleningen, persoonlijke leningen, leningen aan bedrijven enz.) Met een 
rentetarief van 3%. We verstrekken leningen aan mensen in nood, ongeacht hun 
locatie, geslacht, burgerlijke staat, opleiding of baan, maar moeten een legale 
manier van terugbetaling hebben. Onze leningen variëren tussen 5.000,00 
tot 20.000.000,00 US Dollar of Euro of Pond met een maximale duur van 15 jaar. 
Als u geïnteresseerd bent in meer informatie, hebben we investeerders die 
geïnteresseerd zijn in het financieren van projecten van groot volume. De 
procedures zijn als volgt: -

1-De klant moet een korte samenvatting van het project verzenden. Dit moet het 
totale bedrag omvatten dat vereist is voor het project, geschat rendement op 
investering, terugbetalingsperiode van de lening, dit mag niet meer dan 20 jaar 
zijn

Neem contact met ons op: i...@fundingtrustsfinance.com

INFORMATIE NODIG

Jullie namen:
Adres: ...
Telefoon: ...
Benodigde hoeveelheid: ...
Looptijd: ...
Beroep: ...
Maandelijks inkomensniveau: ..
Geslacht: ..
Geboortedatum: ...
Staat: ...
Land: .
Doel: .

"Miljoenen mensen in de wereld hebben een kredietprobleem van een of andere 
vorm. Je bent niet de enige. We hebben een hele reeks leningopties die kunnen 
helpen. Ontdek nu je opties!"

Met vriendelijke groet,
Ronny Hens,
i...@fundingtrustsfinance.com
WEBSITE: www.fundingtrustfinance.com
--
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


Persoonlijke en beleggingslening.

2018-03-26 Thread Funding Trusts Finance


-- 
Goede dag,
  
We zijn Funding Trusts Finance verstrekt leningen per postadvertentie. Wij 
bieden verschillende soorten leningen of projectleningen (korte en lange 
termijnleningen, persoonlijke leningen, leningen aan bedrijven enz.) Met een 
rentetarief van 3%. We verstrekken leningen aan mensen in nood, ongeacht hun 
locatie, geslacht, burgerlijke staat, opleiding of baan, maar moeten een legale 
manier van terugbetaling hebben. Onze leningen variëren tussen 5.000,00 
tot 20.000.000,00 US Dollar of Euro of Pond met een maximale duur van 15 jaar. 
Als u geïnteresseerd bent in meer informatie, hebben we investeerders die 
geïnteresseerd zijn in het financieren van projecten van groot volume. De 
procedures zijn als volgt: -

1-De klant moet een korte samenvatting van het project verzenden. Dit moet het 
totale bedrag omvatten dat vereist is voor het project, geschat rendement op 
investering, terugbetalingsperiode van de lening, dit mag niet meer dan 20 jaar 
zijn

Neem contact met ons op: i...@fundingtrustsfinance.com

INFORMATIE NODIG

Jullie namen:
Adres: ...
Telefoon: ...
Benodigde hoeveelheid: ...
Looptijd: ...
Beroep: ...
Maandelijks inkomensniveau: ..
Geslacht: ..
Geboortedatum: ...
Staat: ...
Land: .
Doel: .

"Miljoenen mensen in de wereld hebben een kredietprobleem van een of andere 
vorm. Je bent niet de enige. We hebben een hele reeks leningopties die kunnen 
helpen. Ontdek nu je opties!"

Met vriendelijke groet,
Ronny Hens,
i...@fundingtrustsfinance.com
WEBSITE: www.fundingtrustfinance.com
--
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: wipe copies of the stale superblock beyond -b size

2018-03-26 Thread Nikolay Borisov


On 27.03.2018 02:50, Anand Jain wrote:
> 
> 
>> I told you this code can be made a lot simpler, simply by modifying the
>> last argument passed to zero_dev_clamped. I even posted the resulting
>> diff which was just 3 lines changed.
>>
>> I agree that it's a good idea to wipe all available superblock when we
>> use -b. However I don't agree with your approach - it adds a loop, it
>> adds a bunch of checks and makes the complexity orders of magnitude
>> higher than it could be. So I'm asking again - is there any inherent
>> benefit which I'm missing in your newly added 35 lines of code against
>> just passing the block device to zero_dev_clamped and letting the
>> existing logic take care of everything?
> 
> I had that idea for v1 as well, but I didn't do it because it would
> zero bytenr_copy#2 even when there is no btrfs superblock, (which is
> fine only with in block_count).
> 
> Some might view it as corrupting the usr data (for which they have
> specified -b option?)? I am just discussing I don't have any usecase
> to prove it though. Do you have any idea?
> If you think it should be ok, I shall go ahead and zero without
> checking for the btrfs superblock beyond block_count.

Right, so the pertinent question is - is anyone expecting to do mkfs on
a volume irrespective of the options and expect to be able to recover
data prior to the mkfs? I think the answer is 'no', but let's see what
the community says.

> 
> Thanks, Anand
> 
--
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 1/2] btrfs-progs: print-tree: Use macro to replace immediate number for readable flags string buffer length

2018-03-26 Thread Qu Wenruo
In print-tree, we have a lot of parsers to convert numeric flags to
human readable string.

For the buffer size we're using immediate numbers for all their callers.
Change this to macro so it will be much easier for us to expand the
buffer size.

Signed-off-by: Qu Wenruo 
---
changelog:
v2:
  Move all buffer length macros to the header part.
  Change comment to refer to the buffer length marco for later
  modication.
---
 print-tree.c | 50 +++---
 1 file changed, 39 insertions(+), 11 deletions(-)

diff --git a/print-tree.c b/print-tree.c
index a2f6bfc027c9..064f1bb9ff8c 100644
--- a/print-tree.c
+++ b/print-tree.c
@@ -26,6 +26,12 @@
 #include "print-tree.h"
 #include "utils.h"
 
+#define BG_FLAGS_BUF_LEN   64  /* for bg_flags_to_str() */
+#define QGROUP_FLAGS_BUF_LEN   32  /* for qgroup_flags_to_str() */
+#define EXTENT_FLAGS_BUF_LEN   32  /* for extent_flags_to_str() */
+#define ROOT_FLAGS_BUF_LEN 16  /* for root_flags_to_str() */
+#define INODE_FLAGS_BUF_LEN128 /* for inode_flags_to_str() */
+#define HEADER_FLAGS_BUF_LEN   32  /* for header_flags_to_str() */
 
 static void print_dir_item_type(struct extent_buffer *eb,
 struct btrfs_dir_item *di)
@@ -137,7 +143,13 @@ static void print_inode_ref_item(struct extent_buffer *eb, 
u32 size,
}
 }
 
-/* Caller should ensure sizeof(*ret)>=21 "DATA|METADATA|RAID10" */
+/*
+ * Caller should ensure sizeof(*ret)>=21 "DATA|METADATA|RAID10"
+ * Here we bump up to 64 bytes to handle the worst (and invalid) case:
+ * "DATA|METADATA|SYSTEM|RAID0|RAID1|DUP|RAID10|RAID5|RAID6"
+ *
+ * BG_FLAGS_BUF_LEN is ensured to have enough space.
+ */
 static void bg_flags_to_str(u64 flags, char *ret)
 {
int empty = 1;
@@ -180,7 +192,11 @@ static void bg_flags_to_str(u64 flags, char *ret)
}
 }
 
-/* Caller should ensure sizeof(*ret)>= 26 "OFF|SCANNING|INCONSISTENT" */
+/*
+ * Caller should ensure sizeof(*ret)>= 26 "OFF|SCANNING|INCONSISTENT"
+ *
+ * QGROUP_FLAGS_BUF_LEN is ensured to have enough space.
+ */
 static void qgroup_flags_to_str(u64 flags, char *ret)
 {
if (flags & BTRFS_QGROUP_STATUS_FLAG_ON)
@@ -199,7 +215,7 @@ void print_chunk_item(struct extent_buffer *eb, struct 
btrfs_chunk *chunk)
u16 num_stripes = btrfs_chunk_num_stripes(eb, chunk);
int i;
u32 chunk_item_size;
-   char chunk_flags_str[32] = {0};
+   char chunk_flags_str[BG_FLAGS_BUF_LEN] = {0};
 
/* The chunk must contain at least one stripe */
if (num_stripes < 1) {
@@ -385,7 +401,11 @@ static void print_file_extent_item(struct extent_buffer 
*eb,
compress_str);
 }
 
-/* Caller should ensure sizeof(*ret) >= 16("DATA|TREE_BLOCK") */
+/*
+ * Caller should ensure sizeof(*ret) > strlen("DATA|TREE_BLOCK|FULL_BACKREF")
+ *
+ * EXTENT_FLAGS_BUF_LEN is ensured to have enough space.
+ */
 static void extent_flags_to_str(u64 flags, char *ret)
 {
int empty = 1;
@@ -420,7 +440,7 @@ void print_extent_item(struct extent_buffer *eb, int slot, 
int metadata)
u32 item_size = btrfs_item_size_nr(eb, slot);
u64 flags;
u64 offset;
-   char flags_str[32] = {0};
+   char flags_str[EXTENT_FLAGS_BUF_LEN] = {0};
 
if (item_size < sizeof(*ei)) {
 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
@@ -542,6 +562,8 @@ static int empty_uuid(const u8 *uuid)
 
 /*
  * Caller must ensure sizeof(*ret) >= 7 "RDONLY"
+ *
+ * ROOT_FLAGS_BUF_LEN is ensured to have enough space
  */
 static void root_flags_to_str(u64 flags, char *ret)
 {
@@ -577,7 +599,7 @@ static void print_root_item(struct extent_buffer *leaf, int 
slot)
struct btrfs_root_item root_item;
int len;
char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
-   char flags_str[32] = {0};
+   char flags_str[ROOT_FLAGS_BUF_LEN] = {0};
struct btrfs_key drop_key;
 
ri = btrfs_item_ptr(leaf, slot, struct btrfs_root_item);
@@ -887,6 +909,8 @@ static void print_uuid_item(struct extent_buffer *l, 
unsigned long offset,
 /*
  * Caller should ensure sizeof(*ret) >= 102: all charactors plus '|' of
  * BTRFS_INODE_* flags
+ *
+ * INODE_FLAGS_BUF_LEN is ensured to have enough space
  */
 static void inode_flags_to_str(u64 flags, char *ret)
 {
@@ -911,7 +935,7 @@ static void inode_flags_to_str(u64 flags, char *ret)
 static void print_inode_item(struct extent_buffer *eb,
struct btrfs_inode_item *ii)
 {
-   char flags_str[256];
+   char flags_str[INODE_FLAGS_BUF_LEN];
 
memset(flags_str, 0, sizeof(flags_str));
inode_flags_to_str(btrfs_inode_flags(eb, ii), flags_str);
@@ -1002,7 +1026,7 @@ static void print_block_group_item(struct extent_buffer 
*eb,
struct btrfs_block_group_item *bgi)
 {
struct btrfs_block_group_item bg_item;
-   char flags_str[256];
+   char flags_str[BG_FLAGS_BUF_LEN];
 
read_extent_buffer(eb, &bg_item, (unsigned long)bgi, sizeof(bg_ite

Re: Corruption on Big Endian System

2018-03-26 Thread Anand Jain




On 03/26/2018 11:00 PM, Ashu Tiwary wrote:

It appears my system may have hit the issue reverted here (
https://www.mail-archive.com/linux-btrfs@vger.kernel.org/msg74621.html
) ( [PATCH] Revert "btrfs: use proper endianness accessors for
super_copy" ); system is an IBM OpenPower 720 (Big Endian) running
Fedora 27; kernel was at 4.15.9; attempting to reboot after updating
system (including kernel to 4.15.10) caused system to not be able to
boot:


 Sorry for the inconvenience. Can you please provide:
   btrfs in dump-super -af 

 David has a tool to fix it. I can't find in his github. David?

Thanks, Anand


=
  Mounting /sysroot...
[   34.644721] BTRFS warning (device dm-3): suspicious: generation <
chunk_root_generation: 15959351903540740096 < 17261735521269317632
[   34.644761] BTRFS info (device dm-3): disk space caching is enabled
[   34.644771] BTRFS info (device dm-3): has skinny extents
[   34.645925] BTRFS critical (device dm-3): unable to find logical
71472550772736 length 65536
[   34.645941] BTRFS critical (device dm-3): unable to find logical
71472550772736 length 65536
[   34.645952] BTRFS error (device dm-3): failed to read chunk root
[   34.807156] BTRFS error (device dm-3): open_ctree failed
[FAILED] Failed to mount /sysroot.
=

It appears there is a manual method available to repair the corrupted
superblock: can that be made available?

Thanks,

-Ashu

--
Ashu Tiwary
ashuat...@gmail.com
--
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


--
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 00/14] Qgroup metadata reservation rework

2018-03-26 Thread Qu Wenruo


On 2018年03月26日 22:10, David Sterba wrote:
> On Wed, Dec 13, 2017 at 08:55:21AM +0800, Qu Wenruo wrote:
>> On 2017年12月13日 05:12, David Sterba wrote:
>>> On Tue, Dec 12, 2017 at 03:34:22PM +0800, Qu Wenruo wrote:
 The patch is consist of 2 main parts:
 1) Type based qgroup reservation
The original patchset is sent several months ago.
Nothing is modified at all, just rebased. And not conflict at all.

It's from patch 1 to patch 6.

 2) Split meta qgroup reservation into per-trans and prealloc sub types
The real work to address metadata underflow.
Due to the over-reserve problem, this part is still in RFC state.
But the framework should mostly be fine, only needs extra fine-tuning
to get more accurate qgroup rsv to avoid too early limit.

It's from patch 7 to 14.
>>>
>>> I'm going to add the whole patchset to next, the first part has been
>>> there for some time and no test failures were reported. I optimistically
>>> expect that the second part will also be fine.
>>
>> The type based reservation is completely fine, since it doesn't
>> introduce anything new, just a preparation for the incoming meta rework.
>>
>> However I prefer not to push the whole patchset to upstream until
>> over-reserve behavior is solved.
>> Since it breaks quite some test cases with small limit.
> 
> Merging plan for this patchset from last week was to postpone until
> 4.18 due to lack of final testing here. I've tried to run this with
> quotas enabled an fstests that led to warnings in the power failure
> simulation tests.

Which test case?

> 
> As there's going to be one more rc, this gives us one more week to
> decide if its' ok-ish to merge this patch and fix the fallouts during
> the normal cycle.
> 
> Given that this patchset has been in for-next for a long time, I'd do
> the merge now and focus on testing for that patchset as the rest of
> devel patches looks good.
> 
> Please let me know if you have objections.

I'm completely fine with the decision.

Thanks,
Qu

> 



signature.asc
Description: OpenPGP digital signature


Re: [PATCH] btrfs-progs: wipe copies of the stale superblock beyond -b size

2018-03-26 Thread Anand Jain




I told you this code can be made a lot simpler, simply by modifying the
last argument passed to zero_dev_clamped. I even posted the resulting
diff which was just 3 lines changed.

I agree that it's a good idea to wipe all available superblock when we
use -b. However I don't agree with your approach - it adds a loop, it
adds a bunch of checks and makes the complexity orders of magnitude
higher than it could be. So I'm asking again - is there any inherent
benefit which I'm missing in your newly added 35 lines of code against
just passing the block device to zero_dev_clamped and letting the
existing logic take care of everything?


I had that idea for v1 as well, but I didn't do it because it would
zero bytenr_copy#2 even when there is no btrfs superblock, (which is
fine only with in block_count).

Some might view it as corrupting the usr data (for which they have
specified -b option?)? I am just discussing I don't have any usecase
to prove it though. Do you have any idea?
If you think it should be ok, I shall go ahead and zero without
checking for the btrfs superblock beyond block_count.

Thanks, Anand
--
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 v2 0/3] Allow rmdir(2) to delete a subvolume

2018-03-26 Thread Goffredo Baroncelli
Hi Misono,

On 03/26/2018 10:28 AM, Misono Tomohiro wrote:
> changelog:
>   v1 -> v2 ... split the patch to hopefully make review easier
> 
> 1st patch is a preparation work just moving the declaration of
> may_destroy_subvol().
> 
> 2nd patch is the main part. New function btrfs_delete_subvolume() is
> introduced and used in btrfs_rmdir() when a direcoty is an empty
> subvolume. The function is almost the copy of second half of
> btrfs_ioctl_snap_destroy().
> The code path for "sub delete" is not changed yet.
> 
> 3rd patch is a cleanup of btrfs_ioctl_snap_destroy() and uses 
> brrfs_delete_subvolume() for "sub delete" too.
> 
> Tomohiro Misono (3):
>   btrfs: move may_destroy_subvol() from ioctl.c to inode.c
>   btrfs: Allow rmdir(2) to delete a subvolume
>   btrfs: cleanup btrfs_ioctl_snap_destroy() by using btrfs_delete_subvolume()
> 
>  fs/btrfs/ctree.h |   5 +-
>  fs/btrfs/inode.c | 199 
> ++-
>  fs/btrfs/ioctl.c | 185 +--
>  3 files changed, 200 insertions(+), 189 deletions(-)
> 

I checked this patch, and it works. You can add
Tested-by: Goffredo Baroncelli 

-

ghigo@venice:/tmp$ btrfs sub cre a
Create subvolume './a'
ghigo@venice:/tmp$ btrfs sub cre a/b
Create subvolume 'a/b'
ghigo@venice:/tmp$ btrfs sub cre a/b/d
Create subvolume 'a/b/d'
ghigo@venice:/tmp$ touch a/b/d/c
ghigo@venice:/tmp$ rm -rf a
ghigo@venice:/tmp$ ls -la
total 4
drwxrwxrwt 1 root  root  492 Mar 26 21:18 .
drwxr-xr-x 1 root  root  196 Mar 14 19:41 ..
drwxrwxrwt 1 root  root0 Mar 26 21:17 .font-unix
drwxrwxrwt 1 root  root8 Mar 26 21:18 .ICE-unix
drwxrwxrwt 1 root  root0 Mar 26 21:17 .Test-unix
-r--r--r-- 1 root  root   11 Mar 26 21:17 .X0-lock
drwxrwxrwt 1 root  root4 Mar 26 21:17 .X11-unix
drwxrwxrwt 1 root  root0 Mar 26 21:17 .XIM-unix



ghigo@venice:/tmp$ btrfs sub crea a
Create subvolume './a'
ghigo@venice:/tmp$ touch a/b
ghigo@venice:/tmp$ rmdir a
rmdir: failed to remove 'a': Directory not empty
ghigo@venice:/tmp$ rm a/b 
ghigo@venice:/tmp$ rmdir a



ghigo@venice:/tmp$ btrfs sub cre d
Create subvolume './d'
ghigo@venice:/tmp$ su - pippo
Password: 
pippo@venice:~$ cd /tmp/
pippo@venice:/tmp$ rmdir d
rmdir: failed to remove 'd': Operation not permitted
pippo@venice:/tmp$ sudo chown pippo d
[sudo] password for pippo: 
pippo@venice:/tmp$ rmdir d

-- 
gpg @keyserver.linux.it: Goffredo Baroncelli 
Key fingerprint BBF5 1610 0B64 DAC6 5F7D  17B2 0EDA 9B37 8B82 E0B5
--
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: wipe copies of the stale superblock beyond -b size

2018-03-26 Thread Nikolay Borisov


On 26.03.2018 11:27, Anand Jain wrote:
> During the mkfs.btrfs -b  btrfs_prepare_device() zeros all
> the superblock bytenr locations only if the bytenr is below the
> blockcount. The problem with this is that if the BTRFS is recreated
> with a smaller size then we will leave the stale superblock in the disk
> which shall confuse the recovery. As shown in the test case below.
> 
>  mkfs.btrfs -qf /dev/mapper/vg-lv
>  mkfs.btrfs -qf -b1G /dev/mapper/vg-lv
>  btrfs in dump-super -a /dev/mapper/vg-lv | grep '.fsid|superblock:'
> 
>  superblock: bytenr=65536, device=/dev/mapper/vg-lv
>  dev_item.fsidebc67d01-7fc5-43f0-90b4-d1925002551e [match]
>  superblock: bytenr=67108864, device=/dev/mapper/vg-lv
>  dev_item.fsidebc67d01-7fc5-43f0-90b4-d1925002551e [match]
>  superblock: bytenr=274877906944, device=/dev/mapper/vg-lv
>  dev_item.fsidb97a9206-593b-4933-a424-c6a6ee23fe7c [match]
> 
> So if we find a valid superblock zero it even if it's beyond the
> blockcount.
> 
> Signed-off-by: Anand Jain 
> ---
>  utils.c | 35 +++
>  1 file changed, 35 insertions(+)
> 
> diff --git a/utils.c b/utils.c
> index e9cb3a82fda6..6a9408b06e73 100644
> --- a/utils.c
> +++ b/utils.c
> @@ -365,6 +365,41 @@ int btrfs_prepare_device(int fd, const char *file, u64 
> *block_count_ret,
>   return 1;
>   }
>  
> + /*
> +  * Check for the BTRFS SB copies up until btrfs_device_size() and zero
> +  * it. So that kernel (or user for the manual recovery) don't have to
> +  * confuse with the stale SB copy during recovery.
> +  */
> + if (block_count != btrfs_device_size(fd, &st)) {
> + for (i = 1; i < BTRFS_SUPER_MIRROR_MAX; i++) {
> + struct btrfs_super_block *disk_super;
> + char buf[BTRFS_SUPER_INFO_SIZE];
> + disk_super = (struct btrfs_super_block *)buf;
> +
> + /* Already zeroed above */
> + if (btrfs_sb_offset(i) < block_count)
> + continue;
> +
> + /* Beyond actual disk size */
> + if (btrfs_sb_offset(i) >= btrfs_device_size(fd, &st))
> + continue;
> +
> + /* Does not contain any stale SB */
> + if (btrfs_read_dev_super(fd, disk_super,
> +  btrfs_sb_offset(i), 0))
> + continue;
> +
> + ret = zero_dev_clamped(fd, btrfs_sb_offset(i),
> + BTRFS_SUPER_INFO_SIZE,
> + btrfs_device_size(fd, &st));
> + if (ret < 0) {
> + error("failed to zero device '%s' bytenr %llu: 
> %s",
> + file, btrfs_sb_offset(i), 
> strerror(-ret));
> + return 1;
> + }
> + }
> + }
> +

I told you this code can be made a lot simpler, simply by modifying the
last argument passed to zero_dev_clamped. I even posted the resulting
diff which was just 3 lines changed.

I agree that it's a good idea to wipe all available superblock when we
use -b. However I don't agree with your approach - it adds a loop, it
adds a bunch of checks and makes the complexity orders of magnitude
higher than it could be. So I'm asking again - is there any inherent
benefit which I'm missing in your newly added 35 lines of code against
just passing the block device to zero_dev_clamped and letting the
existing logic take care of everything?

>   *block_count_ret = block_count;
>   return 0;
>  }
> 
--
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


Corruption on Big Endian System

2018-03-26 Thread Ashu Tiwary
It appears my system may have hit the issue reverted here (
https://www.mail-archive.com/linux-btrfs@vger.kernel.org/msg74621.html
) ( [PATCH] Revert "btrfs: use proper endianness accessors for
super_copy" ); system is an IBM OpenPower 720 (Big Endian) running
Fedora 27; kernel was at 4.15.9; attempting to reboot after updating
system (including kernel to 4.15.10) caused system to not be able to
boot:

=
 Mounting /sysroot...
[   34.644721] BTRFS warning (device dm-3): suspicious: generation <
chunk_root_generation: 15959351903540740096 < 17261735521269317632
[   34.644761] BTRFS info (device dm-3): disk space caching is enabled
[   34.644771] BTRFS info (device dm-3): has skinny extents
[   34.645925] BTRFS critical (device dm-3): unable to find logical
71472550772736 length 65536
[   34.645941] BTRFS critical (device dm-3): unable to find logical
71472550772736 length 65536
[   34.645952] BTRFS error (device dm-3): failed to read chunk root
[   34.807156] BTRFS error (device dm-3): open_ctree failed
[FAILED] Failed to mount /sysroot.
=

It appears there is a manual method available to repair the corrupted
superblock: can that be made available?

Thanks,

-Ashu

--
Ashu Tiwary
ashuat...@gmail.com
--
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: spurious full btrfs corruption

2018-03-26 Thread Christoph Anton Mitterer
Hey Qu.

Some update on the corruption issue on my Fujitsu notebook:


Finally got around running some memtest on it... and few seconds after
it started I already got this:
https://paste.pics/1ff8b13b94f31082bc7410acfb1c6693

So plenty of bad memory...

I'd say it's probably not so unlikely that *this* was the actual reason
for btrfs-metadata corruption.

It would perfectly fit to the symptom that I saw shortly before the fs
was completely destroyed:
The spurious csum errors on reads that went away when I read the file
again.



I'd guess you also found no further issue with the v1 space cache
and/or the tree log in the meantime?
So it's probably safe to turn them on again?



We(aka you + me testing fixes) can still look in the issue that newer
btrfsprogs no longer recover anything from the broken fs, while older
to.
I can keep the image around, so no reason to hurry from your side.



Cheers,
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


Re: [PATCH v2] btrfs-progs: Add test for collision DIR_ITEM handling

2018-03-26 Thread Qu Wenruo


On 2018年03月26日 21:59, Nikolay Borisov wrote:
> Verify that if we have an otherwise clean filesystem, containging collided
> DIR_ITEM, btrfs check lowmem's mode can correctly handle those and not produce
> any false positives.
> 
> This if fixed by commit titled:
> 
>  "btrfs-progs: Fix DIR_ITEM checking in lowmem"
> 
> Signed-off-by: Nikolay Borisov 

Reviewed-by: Qu Wenruo 

Thanks,
Qu

> ---
>  .../031-lowmem-collission-dir-items/test.sh| 23 
> ++
>  1 file changed, 23 insertions(+)
>  create mode 100755 tests/fsck-tests/031-lowmem-collission-dir-items/test.sh
> 
> diff --git a/tests/fsck-tests/031-lowmem-collission-dir-items/test.sh 
> b/tests/fsck-tests/031-lowmem-collission-dir-items/test.sh
> new file mode 100755
> index ..fa0b88af0557
> --- /dev/null
> +++ b/tests/fsck-tests/031-lowmem-collission-dir-items/test.sh
> @@ -0,0 +1,23 @@
> +#!/bin/bash
> +# Ensure that running btrfs check on a fs which has name collisions of files
> +# doesn't result in false positives. This test is specifically targeted at
> +# lowmem mode.
> +source "$TEST_TOP/common"
> +
> +check_prereq btrfs
> +check_prereq mkfs.btrfs
> +
> +setup_root_helper
> +prepare_test_dev
> +
> +run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV"
> +run_check_mount_test_dev
> +
> +# Create 2 files whose names collide
> +run_check $SUDO_HELPER touch 
> "$TEST_MNT/5ab4e206XVT1U3ZF647YS2PD4AKAG826"
> +run_check $SUDO_HELPER touch 
> "$TEST_MNT/5ab4e26aAP1C3VQBE79IJOTVOEZIR9YU"
> +
> +run_check_umount_test_dev
> +
> +# The fs is clean so lowmem shouldn't produce any warnings
> +run_check "$TOP/btrfs" check --readonly "$TEST_DEV"
> 



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 00/14] Qgroup metadata reservation rework

2018-03-26 Thread David Sterba
On Wed, Dec 13, 2017 at 08:55:21AM +0800, Qu Wenruo wrote:
> On 2017年12月13日 05:12, David Sterba wrote:
> > On Tue, Dec 12, 2017 at 03:34:22PM +0800, Qu Wenruo wrote:
> >> The patch is consist of 2 main parts:
> >> 1) Type based qgroup reservation
> >>The original patchset is sent several months ago.
> >>Nothing is modified at all, just rebased. And not conflict at all.
> >>
> >>It's from patch 1 to patch 6.
> >>
> >> 2) Split meta qgroup reservation into per-trans and prealloc sub types
> >>The real work to address metadata underflow.
> >>Due to the over-reserve problem, this part is still in RFC state.
> >>But the framework should mostly be fine, only needs extra fine-tuning
> >>to get more accurate qgroup rsv to avoid too early limit.
> >>
> >>It's from patch 7 to 14.
> > 
> > I'm going to add the whole patchset to next, the first part has been
> > there for some time and no test failures were reported. I optimistically
> > expect that the second part will also be fine.
> 
> The type based reservation is completely fine, since it doesn't
> introduce anything new, just a preparation for the incoming meta rework.
> 
> However I prefer not to push the whole patchset to upstream until
> over-reserve behavior is solved.
> Since it breaks quite some test cases with small limit.

Merging plan for this patchset from last week was to postpone until
4.18 due to lack of final testing here. I've tried to run this with
quotas enabled an fstests that led to warnings in the power failure
simulation tests.

As there's going to be one more rc, this gives us one more week to
decide if its' ok-ish to merge this patch and fix the fallouts during
the normal cycle.

Given that this patchset has been in for-next for a long time, I'd do
the merge now and focus on testing for that patchset as the rest of
devel patches looks good.

Please let me know if you have objections.
--
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: Add test for collision DIR_ITEM handling

2018-03-26 Thread Nikolay Borisov
Verify that if we have an otherwise clean filesystem, containging collided
DIR_ITEM, btrfs check lowmem's mode can correctly handle those and not produce
any false positives.

This if fixed by commit titled:

 "btrfs-progs: Fix DIR_ITEM checking in lowmem"

Signed-off-by: Nikolay Borisov 
---
 .../031-lowmem-collission-dir-items/test.sh| 23 ++
 1 file changed, 23 insertions(+)
 create mode 100755 tests/fsck-tests/031-lowmem-collission-dir-items/test.sh

diff --git a/tests/fsck-tests/031-lowmem-collission-dir-items/test.sh 
b/tests/fsck-tests/031-lowmem-collission-dir-items/test.sh
new file mode 100755
index ..fa0b88af0557
--- /dev/null
+++ b/tests/fsck-tests/031-lowmem-collission-dir-items/test.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+# Ensure that running btrfs check on a fs which has name collisions of files
+# doesn't result in false positives. This test is specifically targeted at
+# lowmem mode.
+source "$TEST_TOP/common"
+
+check_prereq btrfs
+check_prereq mkfs.btrfs
+
+setup_root_helper
+prepare_test_dev
+
+run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV"
+run_check_mount_test_dev
+
+# Create 2 files whose names collide
+run_check $SUDO_HELPER touch 
"$TEST_MNT/5ab4e206XVT1U3ZF647YS2PD4AKAG826"
+run_check $SUDO_HELPER touch 
"$TEST_MNT/5ab4e26aAP1C3VQBE79IJOTVOEZIR9YU"
+
+run_check_umount_test_dev
+
+# The fs is clean so lowmem shouldn't produce any warnings
+run_check "$TOP/btrfs" check --readonly "$TEST_DEV"
-- 
2.7.4

--
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 2/2] btrfs-progs: Add test for collision DIR_ITEM handling

2018-03-26 Thread David Sterba
On Mon, Mar 26, 2018 at 04:24:47PM +0300, Nikolay Borisov wrote:
> >> +# The fs is clean so lowmem shouldn't produce any warnings
> >> +run_check "$TOP/btrfs" check --mode=lowmem --readonly "$TEST_DEV"
> > 
> > I understand this is a pinpoint test case for lowmem mode, but for
> > lowmem mode test, we set TEST_ENABLE_OVERRIDE and the whole test case
> > will use lowmem mode.
> 
> So how exactly is this argument supposed to be used. I tried:
> 
> TEST_ENABLE_OVERRIDE=true TEST=031\* ./fsck-tests.sh  - no --lowmem is
> appended
> 
> I modify the TEST_ENABLE_OVERRIDE=false to TEST_ENABLE_OVERRIDE=true in
> common.local and then just run TEST=031\* ./fsck-tests.sh and it works.
> 
> TEST_ENABLE_OVERRIDE=true TEST_ARGS_CHECK=--mode=lowmem TEST=031\*
> ./fsck-tests.sh - this also works?

This is how it's supposed to work via the commandline:

- TEST_ENABLE_OVERRIDE is a global switch for any user-defined overrides
- TEST_ARGS_CHECK specifies what should be appended to 'check'.
> 
> 
> I'm not entirely sure what the ci config is but at this point I'm
> beginning to worry that if I omit the explicit --mode option this test
> might never be run in lowmem mode.

CI config == .travis.yml, ie. configuration for the continuous
integration, that among others also runs check tests in default and
lowmem mode.

We don't want mode-specific tests but rather single testcase that can be
selectively used with original or lowmem mode. So even if you have a
regression test for lowmem, it also must pass in the original mode and
therefore there are no switches inside the test script.
--
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 2/2] btrfs-progs: Add test for collision DIR_ITEM handling

2018-03-26 Thread Qu Wenruo


On 2018年03月26日 21:24, Nikolay Borisov wrote:
> 
> 
> On 25.03.2018 14:44, Qu Wenruo wrote:
>>
>>
>> On 2018年03月23日 22:48, Nikolay Borisov wrote:
>>> Verify that if we have an otherwise clean filesystem, containging collided 
>>> DIR_ITEM, btrfs check lowmem's mode can correctly handle those and not 
>>> produce
>>> any false positives. 
>>>
>>> This if fixed by commit titled:
>>>
>>>  "btrfs-progs: Fix DIR_ITEM checking in lowmem" 
>>>
>>> Signed-off-by: Nikolay Borisov 
>>
>> Looks pretty good.
>>
>> However a nitpick inlined below.
>>
>>> ---
>>>  .../031-lowmem-collission-dir-items/test.sh| 27 
>>> ++
>>>  1 file changed, 27 insertions(+)
>>>  create mode 100755 tests/fsck-tests/031-lowmem-collission-dir-items/test.sh
>>>
>>> diff --git a/tests/fsck-tests/031-lowmem-collission-dir-items/test.sh 
>>> b/tests/fsck-tests/031-lowmem-collission-dir-items/test.sh
>>> new file mode 100755
>>> index 000..8a01889
>>> --- /dev/null
>>> +++ b/tests/fsck-tests/031-lowmem-collission-dir-items/test.sh
>>> @@ -0,0 +1,27 @@
>>> +#!/bin/bash
>>> +# Ensure that running btrfs check in lowmem mode on a fs
>>> +# which contains DIR_ITEM with collissions handles it
>>> +# properly
>>> +source "$TEST_TOP/common"
>>> +
>>> +check_prereq btrfs
>>> +check_prereq mkfs.btrfs
>>> +
>>> +setup_root_helper
>>> +prepare_test_dev
>>> +
>>> +run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV"
>>> +run_check_mount_test_dev
>>> +
>>> +# Create 2 files whose names collide
>>> +
>>> +run_check $SUDO_HELPER touch 
>>> "$TEST_MNT/5ab4e206XVT1U3ZF647YS2PD4AKAG826"
>>> +run_check $SUDO_HELPER touch 
>>> "$TEST_MNT/5ab4e26aAP1C3VQBE79IJOTVOEZIR9YU"
>>> +
>>> +run_check_umount_test_dev
>>> +
>>> +# The fs is clean so lowmem shouldn't produce any warnings
>>> +run_check "$TOP/btrfs" check --mode=lowmem --readonly "$TEST_DEV"
>>
>> I understand this is a pinpoint test case for lowmem mode, but for
>> lowmem mode test, we set TEST_ENABLE_OVERRIDE and the whole test case
>> will use lowmem mode.
> 
> So how exactly is this argument supposed to be used. I tried:

TEST_ARGS_CHECK="--mode=lowmem" is forgot.

> 
> TEST_ENABLE_OVERRIDE=true TEST=031\* ./fsck-tests.sh  - no --lowmem is
> appended
> 
> I modify the TEST_ENABLE_OVERRIDE=false to TEST_ENABLE_OVERRIDE=true in
> common.local and then just run TEST=031\* ./fsck-tests.sh and it works.
> 
> TEST_ENABLE_OVERRIDE=true TEST_ARGS_CHECK=--mode=lowmem TEST=031\*
> ./fsck-tests.sh - this also works?

Yep

> 
> 
> I'm not entirely sure what the ci config is but at this point I'm
> beginning to worry that if I omit the explicit --mode option this test
> might never be run in lowmem mode.
> 
> The whole TEST_ENABLE_OVERRIDE situation seems a bit finicky.

I'm not familiar with CI things so it may be a good time point to check
and enhance it if possible?

Thanks,
Qu

> 
>>
>> So it doesn't seem necessary to explicitly call lowmem check here.
>> Just normal run_check "$TOP/btrfs" check would be enough.
>> (And this will also test original mode)
>>
>>> +if [ $? -ne 0 ]; then
>>> +   _fail "check --lowmem doesn't handle collissioned DIR_ITEMs correctly"
>>> +fi
>>>
>> IIRC run_check() will check the return value and exit if failure.
>> So this seems not necessary.
>>
>> Thanks,
>> Qu
>>
> --
> 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
> 



signature.asc
Description: OpenPGP digital signature


Re: [PATCH] btrfs-progs: check/original: Remove unused variable first_key

2018-03-26 Thread David Sterba
On Thu, Mar 22, 2018 at 05:06:24PM +0800, Qu Wenruo wrote:
> This @first_key variable is introduced in f5c4c4f3b75b
> ("btrfsck: add code to rebuild extent records"), however it's not only
> unused, but also used incorrectly.
> 
> It's calling btrfs_item_key_to_cpu() on an node extent buffer.
> 
> Anyway, just remove it.
> 
> Fixes: f5c4c4f3b75b ("btrfsck: add code to rebuild extent records")
> Signed-off-by: Qu Wenruo 

Applied, thanks.
--
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 2/2] btrfs-progs: Add test for collision DIR_ITEM handling

2018-03-26 Thread Nikolay Borisov


On 25.03.2018 14:44, Qu Wenruo wrote:
> 
> 
> On 2018年03月23日 22:48, Nikolay Borisov wrote:
>> Verify that if we have an otherwise clean filesystem, containging collided 
>> DIR_ITEM, btrfs check lowmem's mode can correctly handle those and not 
>> produce
>> any false positives. 
>>
>> This if fixed by commit titled:
>>
>>  "btrfs-progs: Fix DIR_ITEM checking in lowmem" 
>>
>> Signed-off-by: Nikolay Borisov 
> 
> Looks pretty good.
> 
> However a nitpick inlined below.
> 
>> ---
>>  .../031-lowmem-collission-dir-items/test.sh| 27 
>> ++
>>  1 file changed, 27 insertions(+)
>>  create mode 100755 tests/fsck-tests/031-lowmem-collission-dir-items/test.sh
>>
>> diff --git a/tests/fsck-tests/031-lowmem-collission-dir-items/test.sh 
>> b/tests/fsck-tests/031-lowmem-collission-dir-items/test.sh
>> new file mode 100755
>> index 000..8a01889
>> --- /dev/null
>> +++ b/tests/fsck-tests/031-lowmem-collission-dir-items/test.sh
>> @@ -0,0 +1,27 @@
>> +#!/bin/bash
>> +# Ensure that running btrfs check in lowmem mode on a fs
>> +# which contains DIR_ITEM with collissions handles it
>> +# properly
>> +source "$TEST_TOP/common"
>> +
>> +check_prereq btrfs
>> +check_prereq mkfs.btrfs
>> +
>> +setup_root_helper
>> +prepare_test_dev
>> +
>> +run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV"
>> +run_check_mount_test_dev
>> +
>> +# Create 2 files whose names collide
>> +
>> +run_check $SUDO_HELPER touch 
>> "$TEST_MNT/5ab4e206XVT1U3ZF647YS2PD4AKAG826"
>> +run_check $SUDO_HELPER touch 
>> "$TEST_MNT/5ab4e26aAP1C3VQBE79IJOTVOEZIR9YU"
>> +
>> +run_check_umount_test_dev
>> +
>> +# The fs is clean so lowmem shouldn't produce any warnings
>> +run_check "$TOP/btrfs" check --mode=lowmem --readonly "$TEST_DEV"
> 
> I understand this is a pinpoint test case for lowmem mode, but for
> lowmem mode test, we set TEST_ENABLE_OVERRIDE and the whole test case
> will use lowmem mode.

So how exactly is this argument supposed to be used. I tried:

TEST_ENABLE_OVERRIDE=true TEST=031\* ./fsck-tests.sh  - no --lowmem is
appended

I modify the TEST_ENABLE_OVERRIDE=false to TEST_ENABLE_OVERRIDE=true in
common.local and then just run TEST=031\* ./fsck-tests.sh and it works.

TEST_ENABLE_OVERRIDE=true TEST_ARGS_CHECK=--mode=lowmem TEST=031\*
./fsck-tests.sh - this also works?


I'm not entirely sure what the ci config is but at this point I'm
beginning to worry that if I omit the explicit --mode option this test
might never be run in lowmem mode.

The whole TEST_ENABLE_OVERRIDE situation seems a bit finicky.

> 
> So it doesn't seem necessary to explicitly call lowmem check here.
> Just normal run_check "$TOP/btrfs" check would be enough.
> (And this will also test original mode)
> 
>> +if [ $? -ne 0 ]; then
>> +_fail "check --lowmem doesn't handle collissioned DIR_ITEMs correctly"
>> +fi
>>
> IIRC run_check() will check the return value and exit if failure.
> So this seems not necessary.
> 
> Thanks,
> Qu
> 
--
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 v2] btrfs-progs: mkfs: add uuid and otime to ROOT_ITEM of, FS_TREE

2018-03-26 Thread David Sterba
On Fri, Mar 23, 2018 at 05:16:49PM +0900, Misono Tomohiro wrote:
> Currently, the top-level subvolume lacks the UUID. As a result, both
> non-snapshot subvolume and snapshot of top-level subvolume do not have
> Parent UUID and cannot be distinguisued. Therefore "fi show" of
> top-level lists all the subvolumes which lacks the UUID in
> "Snapshot(s)" filed.  Also, it lacks the otime information.
> 
> Fix this by adding the UUID and otime at the mkfs time.  As a
> consequence, snapshots of top-level subvolume now have a Parent UUID and
> UUID tree will create an entry for top-level subvolume at mount time.
> This should not cause the problem for current kernel, but user program
> which relies on the empty Parent UUID may be affected by this change.
> 
> Signed-off-by: Tomohiro Misono 
> ---
> v1 -> v2: clear o/ctime in create_tree()

Yeah that's better, thanks. Patch replaced.
--
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: remove BTRFS_CRC32_SIZE definition

2018-03-26 Thread David Sterba
On Mon, Mar 26, 2018 at 03:57:09PM +0800, Qu Wenruo wrote:
> 
> 
> On 2018年03月26日 08:54, Misono Tomohiro wrote:
> > On 2018/03/23 18:14, Qu Wenruo wrote:
> >>
> >>
> >> On 2018年03月23日 16:20, Misono Tomohiro wrote:
> >>> The kernel code no longer has BTRFS_CRC32_SIZE and only uses
> >>> btrfs_csum_sizes[]. So, update the progs code as well.
> >>>
> >>> Suggested-by: Qu Wenruo 
> >>> Signed-off-by: Tomohiro Misono 
> >>> ---
> >>>  convert/common.c |  2 +-
> >>>  convert/main.c   |  2 +-
> >>>  ctree.h  |  3 +--
> >>>  image/main.c |  4 ++--
> >>>  mkfs/common.c| 14 +++---
> >>>  5 files changed, 12 insertions(+), 13 deletions(-)
> >>>
> >>> diff --git a/convert/common.c b/convert/common.c
> >>> index 3860f3b9..2b944fd8 100644
> >>> --- a/convert/common.c
> >>> +++ b/convert/common.c
> >>> @@ -219,7 +219,7 @@ static inline int write_temp_extent_buffer(int fd, 
> >>> struct extent_buffer *buf,
> >>>  {
> >>>   int ret;
> >>>  
> >>> - csum_tree_block_size(buf, BTRFS_CRC32_SIZE, 0);
> >>> + csum_tree_block_size(buf, btrfs_csum_sizes[BTRFS_CSUM_TYPE_CRC32], 0);
> >>
> >> I'd say the normal kernel way to do this is like this, other than using
> >> BTRFS_CSUM_TYPE_CRC32:
> >>u16 csum_size = btrfs_super_csum_size(fs_info->super_copy);
> >>
> >> Thanks,
> >> Qu
> > 
> > 
> > Thanks, but we cannot access fs_info or struct btrfs_super_block here (and 
> > others in this diff).
> > Should we pass the csum type parameter as an argument? Since currently the 
> > only
> > supported type is crc32, I'm not sure if we should write the code so 
> > generic at this time.
> 
> Fair enough.

Yeah, at this point I'm ok with replacing it with just the reference to
the array. It's obvious that this could be generalized once there are
more csum algorithms.
--
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 v2 1/3] btrfs: Move may_destroy_subvol() from ioctl.c to inode.c

2018-03-26 Thread Nikolay Borisov


On 26.03.2018 11:28, Misono Tomohiro wrote:
> This is a preparation work to allow rmdir(2) to delete a subvolume.
> 
> Signed-off-by: Tomohiro Misono 
> ---
>  fs/btrfs/ctree.h |  1 +
>  fs/btrfs/inode.c | 54 ++
>  fs/btrfs/ioctl.c | 54 --
>  3 files changed, 55 insertions(+), 54 deletions(-)
> 
> diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> index da308774b8a4..2dbead106aab 100644
> --- a/fs/btrfs/ctree.h
> +++ b/fs/btrfs/ctree.h
> @@ -3166,6 +3166,7 @@ int btrfs_unlink_subvol(struct btrfs_trans_handle 
> *trans,
>   struct btrfs_root *root,
>   struct inode *dir, u64 objectid,
>   const char *name, int name_len);
> +noinline int may_destroy_subvol(struct btrfs_root *root);

Why the explicit noinline? If it's for "documentation"/appearing in
stack traces purposes then you should use noinline_for_stack. But I
don't think it's really needed.

>  int btrfs_truncate_block(struct inode *inode, loff_t from, loff_t len,
>   int front);
>  int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index f53470112670..db66fa4fede6 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -4333,6 +4333,60 @@ int btrfs_unlink_subvol(struct btrfs_trans_handle 
> *trans,
>   return ret;
>  }
>  
> +/*
> + * helper to check if the subvolume references other subvolumes
> + */
> +noinline int may_destroy_subvol(struct btrfs_root *root)
> +{
> + struct btrfs_fs_info *fs_info = root->fs_info;
> + struct btrfs_path *path;
> + struct btrfs_dir_item *di;
> + struct btrfs_key key;
> + u64 dir_id;
> + int ret;
> +
> + path = btrfs_alloc_path();
> + if (!path)
> + return -ENOMEM;
> +
> + /* Make sure this root isn't set as the default subvol */
> + dir_id = btrfs_super_root_dir(fs_info->super_copy);
> + di = btrfs_lookup_dir_item(NULL, fs_info->tree_root, path,
> +dir_id, "default", 7, 0);
> + if (di && !IS_ERR(di)) {
> + btrfs_dir_item_key_to_cpu(path->nodes[0], di, &key);
> + if (key.objectid == root->root_key.objectid) {
> + ret = -EPERM;
> + btrfs_err(fs_info,
> +   "deleting default subvolume %llu is not 
> allowed",
> +   key.objectid);
> + goto out;
> + }
> + btrfs_release_path(path);
> + }
> +
> + key.objectid = root->root_key.objectid;
> + key.type = BTRFS_ROOT_REF_KEY;
> + key.offset = (u64)-1;
> +
> + ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, path, 0, 0);
> + if (ret < 0)
> + goto out;
> + BUG_ON(ret == 0);
> +
> + ret = 0;
> + if (path->slots[0] > 0) {
> + path->slots[0]--;
> + btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
> + if (key.objectid == root->root_key.objectid &&
> + key.type == BTRFS_ROOT_REF_KEY)
> + ret = -ENOTEMPTY;
> + }
> +out:
> + btrfs_free_path(path);
> + return ret;
> +}
> +
>  static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
>  {
>   struct inode *inode = d_inode(dentry);
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 111ee282b777..11af9eb449ef 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -1843,60 +1843,6 @@ static noinline int btrfs_ioctl_subvol_setflags(struct 
> file *file,
>   return ret;
>  }
>  
> -/*
> - * helper to check if the subvolume references other subvolumes
> - */
> -static noinline int may_destroy_subvol(struct btrfs_root *root)
> -{
> - struct btrfs_fs_info *fs_info = root->fs_info;
> - struct btrfs_path *path;
> - struct btrfs_dir_item *di;
> - struct btrfs_key key;
> - u64 dir_id;
> - int ret;
> -
> - path = btrfs_alloc_path();
> - if (!path)
> - return -ENOMEM;
> -
> - /* Make sure this root isn't set as the default subvol */
> - dir_id = btrfs_super_root_dir(fs_info->super_copy);
> - di = btrfs_lookup_dir_item(NULL, fs_info->tree_root, path,
> -dir_id, "default", 7, 0);
> - if (di && !IS_ERR(di)) {
> - btrfs_dir_item_key_to_cpu(path->nodes[0], di, &key);
> - if (key.objectid == root->root_key.objectid) {
> - ret = -EPERM;
> - btrfs_err(fs_info,
> -   "deleting default subvolume %llu is not 
> allowed",
> -   key.objectid);
> - goto out;
> - }
> - btrfs_release_path(path);
> - }
> -
> - key.objectid = root->root_key.objectid;
> - key.type = BTRFS_ROOT_REF_KEY;
> - key.offset = (u64)-1;
> -
> -  

[PATCH v2 2/3] btrfs: Allow rmdir(2) to delete a subvolume

2018-03-26 Thread Misono Tomohiro
This patch changes the behavior of rmdir(2) to allow it to delete
an empty subvolume by default, unless it is not a default subvolume
and send is not in progress.

New function btrfs_delete_subvolume() is almost equal to the second half
of btrfs_ioctl_snap_destroy(). This function requires inode_lock for both
@dir and inode of @dentry. For rmdir(2) it is already acquired in vfs
layer before calling btrfs_rmdir().

Note that while a non-privileged user cannot delete a read-only subvolume
by "btrfs subvolume delete" when user_subvol_rm_allowd mount option is
enabled, rmdir(2) can delete an empty read-only subvolume.
(However, rm -r cannot use for read-only subvolume containing files.)

Signed-off-by: Tomohiro Misono 
---
 fs/btrfs/inode.c | 143 ++-
 1 file changed, 142 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index db66fa4fede6..b778776eee8e 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -4387,6 +4387,147 @@ noinline int may_destroy_subvol(struct btrfs_root *root)
return ret;
 }
 
+static int btrfs_delete_subvolume(struct inode *dir, struct dentry *dentry)
+{
+   struct btrfs_fs_info *fs_info = btrfs_sb(dentry->d_sb);
+   struct btrfs_root *root = BTRFS_I(dir)->root;
+   struct inode *inode = d_inode(dentry);
+   struct btrfs_root *dest = BTRFS_I(inode)->root;
+   struct btrfs_trans_handle *trans;
+   struct btrfs_block_rsv block_rsv;
+   u64 root_flags;
+   u64 qgroup_reserved;
+   int ret;
+   int err;
+
+   /*
+* Don't allow to delete a subvolume with send in progress. This is
+* inside the i_mutex so the error handling that has to drop the bit
+* again is not run concurrently.
+*/
+   spin_lock(&dest->root_item_lock);
+   root_flags = btrfs_root_flags(&dest->root_item);
+   if (dest->send_in_progress == 0) {
+   btrfs_set_root_flags(&dest->root_item,
+   root_flags | BTRFS_ROOT_SUBVOL_DEAD);
+   spin_unlock(&dest->root_item_lock);
+   } else {
+   spin_unlock(&dest->root_item_lock);
+   btrfs_warn(fs_info,
+  "Attempt to delete subvolume %llu during send",
+  dest->root_key.objectid);
+   err = -EPERM;
+   return err;
+   }
+
+   down_write(&fs_info->subvol_sem);
+
+   err = may_destroy_subvol(dest);
+   if (err)
+   goto out_up_write;
+
+   btrfs_init_block_rsv(&block_rsv, BTRFS_BLOCK_RSV_TEMP);
+   /*
+* One for dir inode, two for dir entries, two for root
+* ref/backref.
+*/
+   err = btrfs_subvolume_reserve_metadata(root, &block_rsv,
+  5, &qgroup_reserved, true);
+   if (err)
+   goto out_up_write;
+
+   trans = btrfs_start_transaction(root, 0);
+   if (IS_ERR(trans)) {
+   err = PTR_ERR(trans);
+   goto out_release;
+   }
+   trans->block_rsv = &block_rsv;
+   trans->bytes_reserved = block_rsv.size;
+
+   btrfs_record_snapshot_destroy(trans, BTRFS_I(dir));
+
+   ret = btrfs_unlink_subvol(trans, root, dir,
+   dest->root_key.objectid,
+   dentry->d_name.name,
+   dentry->d_name.len);
+   if (ret) {
+   err = ret;
+   btrfs_abort_transaction(trans, ret);
+   goto out_end_trans;
+   }
+
+   btrfs_record_root_in_trans(trans, dest);
+
+   memset(&dest->root_item.drop_progress, 0,
+   sizeof(dest->root_item.drop_progress));
+   dest->root_item.drop_level = 0;
+   btrfs_set_root_refs(&dest->root_item, 0);
+
+   if (!test_and_set_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED, &dest->state)) {
+   ret = btrfs_insert_orphan_item(trans,
+   fs_info->tree_root,
+   dest->root_key.objectid);
+   if (ret) {
+   btrfs_abort_transaction(trans, ret);
+   err = ret;
+   goto out_end_trans;
+   }
+   }
+
+   ret = btrfs_uuid_tree_rem(trans, fs_info, dest->root_item.uuid,
+ BTRFS_UUID_KEY_SUBVOL,
+ dest->root_key.objectid);
+   if (ret && ret != -ENOENT) {
+   btrfs_abort_transaction(trans, ret);
+   err = ret;
+   goto out_end_trans;
+   }
+   if (!btrfs_is_empty_uuid(dest->root_item.received_uuid)) {
+   ret = btrfs_uuid_tree_rem(trans, fs_info,
+ dest->root_item.received_uuid,
+ BTRFS_UUID_KEY_RECEIVED_SUBVOL,
+ dest->root_key.objectid);
+

[PATCH v2 3/3] btrfs: Cleanup btrfs_ioctl_snap_destroy() by using btrfs_delete_subvolume()

2018-03-26 Thread Misono Tomohiro
Use btrfs_delete_subvolume() in btrfs_ioctl_snap_destroy() too to
cleanup the code. Call of d_delete() is still required since
btrfs_delete_subvolume() does not call it (for rmdir(2), vfs layer later
calls it).

As a result, btrfs_unlink_subvol() and may_destroy_subvol()
become static functions. No functional change happens.

Signed-off-by: Tomohiro Misono 
---
 fs/btrfs/ctree.h |   6 +--
 fs/btrfs/inode.c |   6 +--
 fs/btrfs/ioctl.c | 131 +--
 3 files changed, 6 insertions(+), 137 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 2dbead106aab..6f23f0694ac3 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -3162,11 +3162,7 @@ int btrfs_unlink_inode(struct btrfs_trans_handle *trans,
 int btrfs_add_link(struct btrfs_trans_handle *trans,
   struct btrfs_inode *parent_inode, struct btrfs_inode *inode,
   const char *name, int name_len, int add_backref, u64 index);
-int btrfs_unlink_subvol(struct btrfs_trans_handle *trans,
-   struct btrfs_root *root,
-   struct inode *dir, u64 objectid,
-   const char *name, int name_len);
-noinline int may_destroy_subvol(struct btrfs_root *root);
+int btrfs_delete_subvolume(struct inode *dir, struct dentry *dentry);
 int btrfs_truncate_block(struct inode *inode, loff_t from, loff_t len,
int front);
 int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index b778776eee8e..c23e41e6cdfe 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -4252,7 +4252,7 @@ static int btrfs_unlink(struct inode *dir, struct dentry 
*dentry)
return ret;
 }
 
-int btrfs_unlink_subvol(struct btrfs_trans_handle *trans,
+static int btrfs_unlink_subvol(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct inode *dir, u64 objectid,
const char *name, int name_len)
@@ -4336,7 +4336,7 @@ int btrfs_unlink_subvol(struct btrfs_trans_handle *trans,
 /*
  * helper to check if the subvolume references other subvolumes
  */
-noinline int may_destroy_subvol(struct btrfs_root *root)
+static noinline int may_destroy_subvol(struct btrfs_root *root)
 {
struct btrfs_fs_info *fs_info = root->fs_info;
struct btrfs_path *path;
@@ -4387,7 +4387,7 @@ noinline int may_destroy_subvol(struct btrfs_root *root)
return ret;
 }
 
-static int btrfs_delete_subvolume(struct inode *dir, struct dentry *dentry)
+int btrfs_delete_subvolume(struct inode *dir, struct dentry *dentry)
 {
struct btrfs_fs_info *fs_info = btrfs_sb(dentry->d_sb);
struct btrfs_root *root = BTRFS_I(dir)->root;
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 11af9eb449ef..7559a1a82e6d 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2266,12 +2266,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct file 
*file,
struct btrfs_root *root = BTRFS_I(dir)->root;
struct btrfs_root *dest = NULL;
struct btrfs_ioctl_vol_args *vol_args;
-   struct btrfs_trans_handle *trans;
-   struct btrfs_block_rsv block_rsv;
-   u64 root_flags;
-   u64 qgroup_reserved;
int namelen;
-   int ret;
int err = 0;
 
if (!S_ISDIR(dir->i_mode))
@@ -2355,133 +2350,11 @@ static noinline int btrfs_ioctl_snap_destroy(struct 
file *file,
}
 
inode_lock(inode);
-
-   /*
-* Don't allow to delete a subvolume with send in progress. This is
-* inside the i_mutex so the error handling that has to drop the bit
-* again is not run concurrently.
-*/
-   spin_lock(&dest->root_item_lock);
-   root_flags = btrfs_root_flags(&dest->root_item);
-   if (dest->send_in_progress == 0) {
-   btrfs_set_root_flags(&dest->root_item,
-   root_flags | BTRFS_ROOT_SUBVOL_DEAD);
-   spin_unlock(&dest->root_item_lock);
-   } else {
-   spin_unlock(&dest->root_item_lock);
-   btrfs_warn(fs_info,
-  "Attempt to delete subvolume %llu during send",
-  dest->root_key.objectid);
-   err = -EPERM;
-   goto out_unlock_inode;
-   }
-
-   down_write(&fs_info->subvol_sem);
-
-   err = may_destroy_subvol(dest);
-   if (err)
-   goto out_up_write;
-
-   btrfs_init_block_rsv(&block_rsv, BTRFS_BLOCK_RSV_TEMP);
-   /*
-* One for dir inode, two for dir entries, two for root
-* ref/backref.
-*/
-   err = btrfs_subvolume_reserve_metadata(root, &block_rsv,
-  5, &qgroup_reserved, true);
-   if (err)
-   goto out_up_write;
-
-   trans = btrfs_start_transaction(root, 0);
-   if (IS_ERR(trans)) {
-   err = PTR_ERR(trans);
-   

[PATCH v2 1/3] btrfs: Move may_destroy_subvol() from ioctl.c to inode.c

2018-03-26 Thread Misono Tomohiro
This is a preparation work to allow rmdir(2) to delete a subvolume.

Signed-off-by: Tomohiro Misono 
---
 fs/btrfs/ctree.h |  1 +
 fs/btrfs/inode.c | 54 ++
 fs/btrfs/ioctl.c | 54 --
 3 files changed, 55 insertions(+), 54 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index da308774b8a4..2dbead106aab 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -3166,6 +3166,7 @@ int btrfs_unlink_subvol(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct inode *dir, u64 objectid,
const char *name, int name_len);
+noinline int may_destroy_subvol(struct btrfs_root *root);
 int btrfs_truncate_block(struct inode *inode, loff_t from, loff_t len,
int front);
 int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index f53470112670..db66fa4fede6 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -4333,6 +4333,60 @@ int btrfs_unlink_subvol(struct btrfs_trans_handle *trans,
return ret;
 }
 
+/*
+ * helper to check if the subvolume references other subvolumes
+ */
+noinline int may_destroy_subvol(struct btrfs_root *root)
+{
+   struct btrfs_fs_info *fs_info = root->fs_info;
+   struct btrfs_path *path;
+   struct btrfs_dir_item *di;
+   struct btrfs_key key;
+   u64 dir_id;
+   int ret;
+
+   path = btrfs_alloc_path();
+   if (!path)
+   return -ENOMEM;
+
+   /* Make sure this root isn't set as the default subvol */
+   dir_id = btrfs_super_root_dir(fs_info->super_copy);
+   di = btrfs_lookup_dir_item(NULL, fs_info->tree_root, path,
+  dir_id, "default", 7, 0);
+   if (di && !IS_ERR(di)) {
+   btrfs_dir_item_key_to_cpu(path->nodes[0], di, &key);
+   if (key.objectid == root->root_key.objectid) {
+   ret = -EPERM;
+   btrfs_err(fs_info,
+ "deleting default subvolume %llu is not 
allowed",
+ key.objectid);
+   goto out;
+   }
+   btrfs_release_path(path);
+   }
+
+   key.objectid = root->root_key.objectid;
+   key.type = BTRFS_ROOT_REF_KEY;
+   key.offset = (u64)-1;
+
+   ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, path, 0, 0);
+   if (ret < 0)
+   goto out;
+   BUG_ON(ret == 0);
+
+   ret = 0;
+   if (path->slots[0] > 0) {
+   path->slots[0]--;
+   btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
+   if (key.objectid == root->root_key.objectid &&
+   key.type == BTRFS_ROOT_REF_KEY)
+   ret = -ENOTEMPTY;
+   }
+out:
+   btrfs_free_path(path);
+   return ret;
+}
+
 static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
 {
struct inode *inode = d_inode(dentry);
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 111ee282b777..11af9eb449ef 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1843,60 +1843,6 @@ static noinline int btrfs_ioctl_subvol_setflags(struct 
file *file,
return ret;
 }
 
-/*
- * helper to check if the subvolume references other subvolumes
- */
-static noinline int may_destroy_subvol(struct btrfs_root *root)
-{
-   struct btrfs_fs_info *fs_info = root->fs_info;
-   struct btrfs_path *path;
-   struct btrfs_dir_item *di;
-   struct btrfs_key key;
-   u64 dir_id;
-   int ret;
-
-   path = btrfs_alloc_path();
-   if (!path)
-   return -ENOMEM;
-
-   /* Make sure this root isn't set as the default subvol */
-   dir_id = btrfs_super_root_dir(fs_info->super_copy);
-   di = btrfs_lookup_dir_item(NULL, fs_info->tree_root, path,
-  dir_id, "default", 7, 0);
-   if (di && !IS_ERR(di)) {
-   btrfs_dir_item_key_to_cpu(path->nodes[0], di, &key);
-   if (key.objectid == root->root_key.objectid) {
-   ret = -EPERM;
-   btrfs_err(fs_info,
- "deleting default subvolume %llu is not 
allowed",
- key.objectid);
-   goto out;
-   }
-   btrfs_release_path(path);
-   }
-
-   key.objectid = root->root_key.objectid;
-   key.type = BTRFS_ROOT_REF_KEY;
-   key.offset = (u64)-1;
-
-   ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, path, 0, 0);
-   if (ret < 0)
-   goto out;
-   BUG_ON(ret == 0);
-
-   ret = 0;
-   if (path->slots[0] > 0) {
-   path->slots[0]--;
-   btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
-   if (key.objec

[PATCH 2/8] btrfs: return required error from btrfs_check_super_csum

2018-03-26 Thread Anand Jain
Return the required -EINVAL and -EUCLEAN from the function
btrfs_check_super_csum(). And more the error log into the
parent function.

Signed-off-by: Anand Jain 
---
 fs/btrfs/disk-io.c | 27 ---
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index b9b435579527..8b4e602ed60a 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -392,9 +392,10 @@ static int verify_parent_transid(struct extent_io_tree 
*io_tree,
 /*
  * Return 0 if the superblock checksum type matches the checksum value of that
  * algorithm. Pass the raw disk superblock data.
+ * Otherwise: -EINVAL  if csum type is not found
+ *   -EUCLEAN if csum does not match
  */
-static int btrfs_check_super_csum(struct btrfs_fs_info *fs_info,
- char *raw_disk_sb)
+static int btrfs_check_super_csum(char *raw_disk_sb)
 {
struct btrfs_super_block *disk_sb =
(struct btrfs_super_block *)raw_disk_sb;
@@ -402,11 +403,8 @@ static int btrfs_check_super_csum(struct btrfs_fs_info 
*fs_info,
u32 crc = ~(u32)0;
char result[sizeof(crc)];
 
-   if (csum_type >= ARRAY_SIZE(btrfs_csum_sizes)) {
-   btrfs_err(fs_info, "unsupported checksum algorithm %u",
- csum_type);
-   return 1;
-   }
+   if (csum_type >= ARRAY_SIZE(btrfs_csum_sizes))
+   return -EINVAL;
 
/*
 * The super_block structure does not span the whole
@@ -418,7 +416,7 @@ static int btrfs_check_super_csum(struct btrfs_fs_info 
*fs_info,
btrfs_csum_final(crc, result);
 
if (memcmp(raw_disk_sb, result, sizeof(result)))
-   return 1;
+   return -EUCLEAN;
 
return 0;
 }
@@ -2570,9 +2568,16 @@ int open_ctree(struct super_block *sb,
 * We want to check superblock checksum, the type is stored inside.
 * Pass the whole disk block of size BTRFS_SUPER_INFO_SIZE (4k).
 */
-   if (btrfs_check_super_csum(fs_info, bh->b_data)) {
-   btrfs_err(fs_info, "superblock checksum mismatch");
-   err = -EINVAL;
+   err = btrfs_check_super_csum(bh->b_data);
+   if (err) {
+   if (err == -EINVAL)
+   pr_err("BTRFS error (device %pg): "\
+   "unsupported checksum algorithm",
+   fs_devices->latest_bdev);
+   else
+   pr_err("BTRFS error (device %pg): "\
+   "superblock checksum mismatch",
+   fs_devices->latest_bdev);
brelse(bh);
goto fail_alloc;
}
-- 
2.7.0

--
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 0/3] Allow rmdir(2) to delete a subvolume

2018-03-26 Thread Misono Tomohiro
changelog:
  v1 -> v2 ... split the patch to hopefully make review easier

1st patch is a preparation work just moving the declaration of
may_destroy_subvol().

2nd patch is the main part. New function btrfs_delete_subvolume() is
introduced and used in btrfs_rmdir() when a direcoty is an empty
subvolume. The function is almost the copy of second half of
btrfs_ioctl_snap_destroy().
The code path for "sub delete" is not changed yet.

3rd patch is a cleanup of btrfs_ioctl_snap_destroy() and uses 
brrfs_delete_subvolume() for "sub delete" too.

Tomohiro Misono (3):
  btrfs: move may_destroy_subvol() from ioctl.c to inode.c
  btrfs: Allow rmdir(2) to delete a subvolume
  btrfs: cleanup btrfs_ioctl_snap_destroy() by using btrfs_delete_subvolume()

 fs/btrfs/ctree.h |   5 +-
 fs/btrfs/inode.c | 199 ++-
 fs/btrfs/ioctl.c | 185 +--
 3 files changed, 200 insertions(+), 189 deletions(-)

-- 
2.14.3

--
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 1/8] btrfs: cleanup btrfs_check_super_csum() for better code flow

2018-03-26 Thread Anand Jain
We check the %csum_type twice. Drop one. Check for the csum_type and
then for the csum. Which also matches with the progs which have better
logic. This is preparatory patch to get proper error code from
btrfs_check_super_csum().

Signed-off-by: Anand Jain 
---
 fs/btrfs/disk-io.c | 38 +-
 1 file changed, 17 insertions(+), 21 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 1657d6aa4fa6..b9b435579527 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -399,32 +399,28 @@ static int btrfs_check_super_csum(struct btrfs_fs_info 
*fs_info,
struct btrfs_super_block *disk_sb =
(struct btrfs_super_block *)raw_disk_sb;
u16 csum_type = btrfs_super_csum_type(disk_sb);
-   int ret = 0;
-
-   if (csum_type == BTRFS_CSUM_TYPE_CRC32) {
-   u32 crc = ~(u32)0;
-   char result[sizeof(crc)];
-
-   /*
-* The super_block structure does not span the whole
-* BTRFS_SUPER_INFO_SIZE range, we expect that the unused space
-* is filled with zeros and is included in the checksum.
-*/
-   crc = btrfs_csum_data(raw_disk_sb + BTRFS_CSUM_SIZE,
-   crc, BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
-   btrfs_csum_final(crc, result);
-
-   if (memcmp(raw_disk_sb, result, sizeof(result)))
-   ret = 1;
-   }
+   u32 crc = ~(u32)0;
+   char result[sizeof(crc)];
 
if (csum_type >= ARRAY_SIZE(btrfs_csum_sizes)) {
btrfs_err(fs_info, "unsupported checksum algorithm %u",
-   csum_type);
-   ret = 1;
+ csum_type);
+   return 1;
}
 
-   return ret;
+   /*
+* The super_block structure does not span the whole
+* BTRFS_SUPER_INFO_SIZE range, we expect that the unused space
+* is filled with zeros and is included in the checksum.
+*/
+   crc = btrfs_csum_data(raw_disk_sb + BTRFS_CSUM_SIZE,
+ crc, BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
+   btrfs_csum_final(crc, result);
+
+   if (memcmp(raw_disk_sb, result, sizeof(result)))
+   return 1;
+
+   return 0;
 }
 
 /*
-- 
2.7.0

--
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 3/8] btrfs: cleanup btrfs_read_disk_super() to return std error

2018-03-26 Thread Anand Jain
The only caller btrfs_scan_one_device() sets -EINVAL for error from
btrfs_read_disk_super(), so this patch returns -EINVAL from the latter
function.

A preparatory patch to add csum check in btrfs_read_disk_super().

Signed-off-by: Anand Jain 
---
 fs/btrfs/volumes.c | 15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 87d183accdb2..ed22f0a3d239 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1154,23 +1154,23 @@ static int btrfs_read_disk_super(struct block_device 
*bdev, u64 bytenr,
 
/* make sure our super fits in the device */
if (bytenr + PAGE_SIZE >= i_size_read(bdev->bd_inode))
-   return 1;
+   return -EINVAL;
 
/* make sure our super fits in the page */
if (sizeof(**disk_super) > PAGE_SIZE)
-   return 1;
+   return -EINVAL;
 
/* make sure our super doesn't straddle pages on disk */
index = bytenr >> PAGE_SHIFT;
if ((bytenr + sizeof(**disk_super) - 1) >> PAGE_SHIFT != index)
-   return 1;
+   return -EINVAL;
 
/* pull in the page with our super */
*page = read_cache_page_gfp(bdev->bd_inode->i_mapping,
   index, GFP_KERNEL);
 
if (IS_ERR_OR_NULL(*page))
-   return 1;
+   return -EINVAL;
 
p = kmap(*page);
 
@@ -1180,7 +1180,7 @@ static int btrfs_read_disk_super(struct block_device 
*bdev, u64 bytenr,
if (btrfs_super_bytenr(*disk_super) != bytenr ||
btrfs_super_magic(*disk_super) != BTRFS_MAGIC) {
btrfs_release_disk_super(*page);
-   return 1;
+   return -EINVAL;
}
 
if ((*disk_super)->label[0] &&
@@ -1218,10 +1218,9 @@ int btrfs_scan_one_device(const char *path, fmode_t 
flags, void *holder,
if (IS_ERR(bdev))
return PTR_ERR(bdev);
 
-   if (btrfs_read_disk_super(bdev, bytenr, &page, &disk_super)) {
-   ret = -EINVAL;
+   ret = btrfs_read_disk_super(bdev, bytenr, &page, &disk_super);
+   if (ret)
goto error_bdev_put;
-   }
 
mutex_lock(&uuid_mutex);
device = device_list_add(path, disk_super);
-- 
2.7.0

--
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 5/8] btrfs: check if the fsid in the primary sb and copy sb are same

2018-03-26 Thread Anand Jain
During the btrfs dev scan make sure that other copies of superblock
contain the same fsid as the primary SB. So that we bring to the
user notice if the superblock has been overwritten.

 mkfs.btrfs -fq /dev/sdc
 mkfs.btrfs -fq /dev/sdb
 dd if=/dev/sdb of=/dev/sdc count=4K skip=64K seek=64K obs=1 ibs=1
 mount /dev/sdc /btrfs

Caveat: Pls note that older btrfs-progs do not wipe the non-overwriting
stale superblock like copy2 if a smaller mkfs.btrfs -bis created.
So this patch in the kernel will report error. The workaround is to wipe
the superblock manually, like
 dd if=/dev/zero of= seek=274877906944 ibs=1 obs=1 count4K
OR apply btrfs-progs patch
  btrfs-progs: wipe copies of the stale superblock beyond -b size
which shall find and wipe the non overwriting superblock.

Signed-off-by: Anand Jain 
---
 fs/btrfs/volumes.c | 60 ++
 1 file changed, 47 insertions(+), 13 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index ed22f0a3d239..45dd0674571b 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1198,40 +1198,74 @@ static int btrfs_read_disk_super(struct block_device 
*bdev, u64 bytenr,
 int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder,
  struct btrfs_fs_devices **fs_devices_ret)
 {
+   struct btrfs_super_block *disk_super_primary;
struct btrfs_super_block *disk_super;
struct btrfs_device *device;
struct block_device *bdev;
struct page *page;
int ret = 0;
-   u64 bytenr;
+   int i;
 
-   /*
-* we would like to check all the supers, but that would make
-* a btrfs mount succeed after a mkfs from a different FS.
-* So, we need to add a special mount option to scan for
-* later supers, using BTRFS_SUPER_MIRROR_MAX instead
-*/
-   bytenr = btrfs_sb_offset(0);
flags |= FMODE_EXCL;
 
bdev = blkdev_get_by_path(path, flags, holder);
if (IS_ERR(bdev))
return PTR_ERR(bdev);
 
-   ret = btrfs_read_disk_super(bdev, bytenr, &page, &disk_super);
-   if (ret)
+   disk_super_primary = kzalloc(sizeof(*disk_super_primary), GFP_KERNEL);
+   if (!disk_super_primary) {
+   ret = -ENOMEM;
goto error_bdev_put;
+   }
+
+   /*
+* We would like to check all the supers and use one good copy,
+* but that would make a btrfs mount succeed after a mkfs from
+* a different FS.
+* So, we need to add a special mount option to scan for
+* later supers, using BTRFS_SUPER_MIRROR_MAX instead.
+* So, just validate if all copies of the superblocks are ok
+* and have the same fsid.
+*/
+   for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) {
+   u64 bytenr = btrfs_sb_offset(i);
+
+   ret = btrfs_read_disk_super(bdev, bytenr, &page, &disk_super);
+   if (ret) {
+   if (i == 0)
+   goto error_kfree;
+   /* copy2 is optional */
+   ret = 0;
+   continue;
+   }
+
+   if (i == 0) {
+   memcpy(disk_super_primary, disk_super,
+  sizeof(*disk_super_primary));
+   btrfs_release_disk_super(page);
+   continue;
+   } else if (memcmp(disk_super_primary->fsid, disk_super->fsid,
+  BTRFS_FSID_SIZE)) {
+   pr_err("BTRFS (device %pg): superblock fsid missmatch "\
+   "primary %pU copy%d %pU", bdev,
+   disk_super_primary->fsid, i, disk_super->fsid);
+   ret = -EINVAL;
+   btrfs_release_disk_super(page);
+   goto error_kfree;
+   }
+   btrfs_release_disk_super(page);
+   }
 
mutex_lock(&uuid_mutex);
-   device = device_list_add(path, disk_super);
+   device = device_list_add(path, disk_super_primary);
if (IS_ERR(device))
ret = PTR_ERR(device);
else
*fs_devices_ret = device->fs_devices;
mutex_unlock(&uuid_mutex);
 
-   btrfs_release_disk_super(page);
-
+error_kfree:
+   kfree(disk_super_primary);
 error_bdev_put:
blkdev_put(bdev, flags);
 
-- 
2.7.0

--
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 7/8] btrfs: verify checksum for all devices in mount context

2018-03-26 Thread Anand Jain
During mount context, we aren't verifying the superblock checksum
for all the devices, instead, we verify it only for the
struct btrfs_fs_device::latest_bdev. This patch fixes it
by moving the checksum verification code from the function open_ctree()
into the function btrfs_read_dev_one_super().

By doing this now we are verifying the superblock checksum
in the mount-context, device-replace and, device-delete context.

Signed-off-by: Anand Jain 
---
 fs/btrfs/disk-io.c | 35 +--
 1 file changed, 17 insertions(+), 18 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 6299ab18da5f..3cc50041c0b9 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2565,24 +2565,6 @@ int open_ctree(struct super_block *sb,
}
 
/*
-* We want to check superblock checksum, the type is stored inside.
-* Pass the whole disk block of size BTRFS_SUPER_INFO_SIZE (4k).
-*/
-   err = btrfs_check_super_csum(bh->b_data);
-   if (err) {
-   if (err == -EINVAL)
-   pr_err("BTRFS error (device %pg): "\
-   "unsupported checksum algorithm",
-   fs_devices->latest_bdev);
-   else
-   pr_err("BTRFS error (device %pg): "\
-   "superblock checksum mismatch",
-   fs_devices->latest_bdev);
-   brelse(bh);
-   goto fail_alloc;
-   }
-
-   /*
 * super_copy is zeroed at allocation time and we never touch the
 * following bytes up to INFO_SIZE, the checksum is calculated from
 * the whole block of INFO_SIZE
@@ -3128,6 +3110,7 @@ int btrfs_read_dev_one_super(struct block_device *bdev, 
int copy_num,
struct buffer_head *bh;
struct btrfs_super_block *super;
u64 bytenr;
+   int err;
 
bytenr = btrfs_sb_offset(copy_num);
if (bytenr + BTRFS_SUPER_INFO_SIZE >= i_size_read(bdev->bd_inode))
@@ -3148,6 +3131,22 @@ int btrfs_read_dev_one_super(struct block_device *bdev, 
int copy_num,
return -EINVAL;
}
 
+   /*
+* Check the superblock checksum, the type is stored inside.
+* Pass the whole disk block of size BTRFS_SUPER_INFO_SIZE (4k).
+*/
+   err = btrfs_check_super_csum(bh->b_data);
+   if (err) {
+   if (err == -EINVAL)
+   pr_err("BTRFS error (device %pg): unsupported checksum 
algorithm",
+   bdev);
+   else if (err == -EUCLEAN)
+   pr_err("BTRFS error (device %pg): superblock checksum 
mismatch",
+   bdev);
+   brelse(bh);
+   return err;
+   }
+
*bh_ret = bh;
return 0;
 }
-- 
2.7.0

--
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 6/8] btrfs: verify checksum when superblock is read for scan

2018-03-26 Thread Anand Jain
During the scan context, we aren't verifying the superblock-
checksum when read.
This patch fixes it by adding the checksum verification function
btrfs_check_super_csum() in the function btrfs_read_disk_super().
And makes device scan to error fail if the primary superblock csum
is wrong, whereas if the copy-superblock csum is wrong it will just
just report missmatch and continue mount/scan as usual. When the
mount is successful We anyway overwrite all superblocks upon unmount.

The context in which this will be called is - device scan, device ready,
and mount -o device option.

Test script:

 Corrupt primary superblock and check if device scan and mount
 fails:
 mkfs.btrfs -fq /dev/sdc
 dd if=/dev/urandom of=/dev/sdc ibs=1 obs=1 count=1 seek=64K
 btrfs dev scan
 mount /dev/sdb /btrfs

 Corrupt secondary superblock and check if device scan and mount
 is succcessful, check for the dmesg for errors.
 mkfs.btrfs -fq /dev/sdc
 dd if=/dev/urandom of=/dev/sdc ibs=1 obs=1 count=1 seek=64K
 btrfs dev scan
 mount /dev/sdb /btrfs

Signed-off-by: Anand Jain 
---
 fs/btrfs/volumes.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 45dd0674571b..384e503c83ff 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1149,6 +1149,7 @@ static int btrfs_read_disk_super(struct block_device 
*bdev, u64 bytenr,
 struct page **page,
 struct btrfs_super_block **disk_super)
 {
+   int err;
void *p;
pgoff_t index;
 
@@ -1177,6 +1178,20 @@ static int btrfs_read_disk_super(struct block_device 
*bdev, u64 bytenr,
/* align our pointer to the offset of the super block */
*disk_super = p + (bytenr & ~PAGE_MASK);
 
+   err = btrfs_check_super_csum((char *) *disk_super);
+   if (err) {
+   if (err == -EINVAL)
+   pr_err("BTRFS error (device %pg): "\
+   "unsupported checksum type, bytenr=%llu",
+   bdev, bytenr);
+   else
+   pr_err("BTRFS error (device %pg): "\
+   "superblock checksum failed, bytenr=%llu",
+   bdev, bytenr);
+   btrfs_release_disk_super(*page);
+   return err;
+   }
+
if (btrfs_super_bytenr(*disk_super) != bytenr ||
btrfs_super_magic(*disk_super) != BTRFS_MAGIC) {
btrfs_release_disk_super(*page);
-- 
2.7.0

--
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 4/8] btrfs: make btrfs_check_super_csum() non-static

2018-03-26 Thread Anand Jain
In preparation to add the superblock csum verification for the
scan context, make btrfs_check_super_csum() non-static.

Signed-off-by: Anand Jain 
---
 fs/btrfs/disk-io.c | 2 +-
 fs/btrfs/disk-io.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 8b4e602ed60a..6299ab18da5f 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -395,7 +395,7 @@ static int verify_parent_transid(struct extent_io_tree 
*io_tree,
  * Otherwise: -EINVAL  if csum type is not found
  *   -EUCLEAN if csum does not match
  */
-static int btrfs_check_super_csum(char *raw_disk_sb)
+int btrfs_check_super_csum(char *raw_disk_sb)
 {
struct btrfs_super_block *disk_sb =
(struct btrfs_super_block *)raw_disk_sb;
diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
index 70a88d61b547..c400cc68f913 100644
--- a/fs/btrfs/disk-io.h
+++ b/fs/btrfs/disk-io.h
@@ -69,6 +69,7 @@ int write_all_supers(struct btrfs_fs_info *fs_info, int 
max_mirrors);
 struct buffer_head *btrfs_read_dev_super(struct block_device *bdev);
 int btrfs_read_dev_one_super(struct block_device *bdev, int copy_num,
struct buffer_head **bh_ret);
+int btrfs_check_super_csum(char *raw_disk_sb);
 int btrfs_commit_super(struct btrfs_fs_info *fs_info);
 struct btrfs_root *btrfs_read_fs_root(struct btrfs_root *tree_root,
  struct btrfs_key *location);
-- 
2.7.0

--
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: wipe copies of the stale superblock beyond -b size

2018-03-26 Thread Anand Jain
During the mkfs.btrfs -b  btrfs_prepare_device() zeros all
the superblock bytenr locations only if the bytenr is below the
blockcount. The problem with this is that if the BTRFS is recreated
with a smaller size then we will leave the stale superblock in the disk
which shall confuse the recovery. As shown in the test case below.

 mkfs.btrfs -qf /dev/mapper/vg-lv
 mkfs.btrfs -qf -b1G /dev/mapper/vg-lv
 btrfs in dump-super -a /dev/mapper/vg-lv | grep '.fsid|superblock:'

 superblock: bytenr=65536, device=/dev/mapper/vg-lv
 dev_item.fsid  ebc67d01-7fc5-43f0-90b4-d1925002551e [match]
 superblock: bytenr=67108864, device=/dev/mapper/vg-lv
 dev_item.fsid  ebc67d01-7fc5-43f0-90b4-d1925002551e [match]
 superblock: bytenr=274877906944, device=/dev/mapper/vg-lv
 dev_item.fsid  b97a9206-593b-4933-a424-c6a6ee23fe7c [match]

So if we find a valid superblock zero it even if it's beyond the
blockcount.

Signed-off-by: Anand Jain 
---
 utils.c | 35 +++
 1 file changed, 35 insertions(+)

diff --git a/utils.c b/utils.c
index e9cb3a82fda6..6a9408b06e73 100644
--- a/utils.c
+++ b/utils.c
@@ -365,6 +365,41 @@ int btrfs_prepare_device(int fd, const char *file, u64 
*block_count_ret,
return 1;
}
 
+   /*
+* Check for the BTRFS SB copies up until btrfs_device_size() and zero
+* it. So that kernel (or user for the manual recovery) don't have to
+* confuse with the stale SB copy during recovery.
+*/
+   if (block_count != btrfs_device_size(fd, &st)) {
+   for (i = 1; i < BTRFS_SUPER_MIRROR_MAX; i++) {
+   struct btrfs_super_block *disk_super;
+   char buf[BTRFS_SUPER_INFO_SIZE];
+   disk_super = (struct btrfs_super_block *)buf;
+
+   /* Already zeroed above */
+   if (btrfs_sb_offset(i) < block_count)
+   continue;
+
+   /* Beyond actual disk size */
+   if (btrfs_sb_offset(i) >= btrfs_device_size(fd, &st))
+   continue;
+
+   /* Does not contain any stale SB */
+   if (btrfs_read_dev_super(fd, disk_super,
+btrfs_sb_offset(i), 0))
+   continue;
+
+   ret = zero_dev_clamped(fd, btrfs_sb_offset(i),
+   BTRFS_SUPER_INFO_SIZE,
+   btrfs_device_size(fd, &st));
+   if (ret < 0) {
+   error("failed to zero device '%s' bytenr %llu: 
%s",
+   file, btrfs_sb_offset(i), 
strerror(-ret));
+   return 1;
+   }
+   }
+   }
+
*block_count_ret = block_count;
return 0;
 }
-- 
2.7.0

--
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 0/8] Superblock read and verify cleanups

2018-03-26 Thread Anand Jain
Patch 1-4/8 are preparatory patches adds cleanups and nonstatic requisites.

Patch 5/8 makes sure that all copies of the superblock have the same fsid
when we scan the device.

Patch 6/8 verifies superblock csum when we read it in the scan context.

Patch 7/8 fixes a bug that we weren't verifying the superblock csum for
the non-latest_bdev.

And 8/8 patch drops the redundant invalidate_bdev() call during mount.

There is a btrfs-progs patch which is a kind of related, as its found that
we weren't wiping the non-overwritten superblock, so it could cause
confusion during the superblock recovery process. So the patch btrfs-progs
1/1 adds code to wipe superblock if we aren't overwriting it.

Now since kernel patch 5/8 checks if all the superblock copies are
pointing to the same fsid on the disk, so the scan will fail if without
the above 1/1 btrfs-progs, as in the example below [1]. However the simple
workaround is to wipe the superblock manually [2] or apply the btrfs-progs
patch below.

[1]
 mkfs.btrfs -qf /dev/sdb <-- 1T disk
 mkfs.btrfs -b 256M  /dev/sdb
 ERROR: device scan failed on /dev/sdb

[2]
 dd if=/dev/zero of= seek=274877906944 ibs=1 obs=1 count4K

Unfortunately, the error messages should have been failed to register
[3] device into the kernel to be more appropriate to the error.

[3]
ret = ioctl(fd, BTRFS_IOC_SCAN_DEV, &args);
if (ret < 0) {
error("device scan failed on '%s': %m", fname);
ret = -errno;
}


Patches 1-7/8 were sent independently before. And  I found few more things
to fix alongs the line, and since they are related, so I am sending these
all together. Also, as there are minor changes, like in pr_err strings,
and splitting the unrelated changes into a separate patch, so though I am
thankful for the received reviewed-by, I couldn't include them here. Sorry.

Finally, here I am including the function relations [4] so that it will help
to review the code. And this flow is before these patches were applied.

[4]
In the long term, I suggest deprecating ioctl args which pass device path
(where possible), like in delete-device/replace. And
btrfs_read_dev_one_super() should replace btrfs_read_disk_super()

delete-device/replace:
btrfs_rm_device() || btrfs_dev_replace_by_ioctl()
|_btrfs_find_device_by_devspec()
  |_btrfs_find_device_missing_or_by_path()
|_btrfs_find_device_by_path()
  |_btrfs_get_bdev_and_sb()
|_btrfs_read_dev_super()
  |_btrfs_read_dev_one_super()
|___bread()

btrfs_mount_root()
 |
 |_btrfs_parse_early_options (-o device only)
 | |_btrfs_scan_one_device
 |   |_btrfs_read_disk_super()
 | |_read_cache_page_gfp()
 |
 |_btrfs_scan_one_device(mount-arg-dev only)
 | |_btrfs_read_disk_super()
 |   |_read_cache_page_gfp()
 |
 |
 |_btrfs_open_devices(fsid:all)
 |  |_btrfs_open_one_device()
 ||_btrfs_get_bdev_and_sb()  <--- invalidate_bdev(fsid:all)
 |  |_btrfs_read_dev_super()
 ||_btrfs_read_dev_one_super()
 |  |___bread()
 |
 |_btrfs_fill_super()
   |_btrfs_open_ctree()   <-- invalidate_bdev(latest_bdev) <-- redundant
 |_btrfs_read_dev_super(latest_bdev only)
 | |_btrfs_read_dev_one_super(latest_bdev only)
 |   |___bread(latest_bdev)
 |
 |_btrfs_check_super_csum(latest_bdev only) [*]
 |
 |_btrfs_read_chunk_tree
 | |_read_one_dev()
 |   |_open_seed_devices()
 | |_btrfs_open_devices(fs_devices->seed only)

scan/ready
|
|_btrfs_scan_one_device(ioctl-arg-dev only)
   |_btrfs_read_disk_super()
 |_read_cache_page_gfp()


Anand Jain (8):
  btrfs: cleanup btrfs_check_super_csum() for better code flow
  btrfs: return required error from btrfs_check_super_csum
  btrfs: cleanup btrfs_read_disk_super() to return std error
  btrfs: make btrfs_check_super_csum() non static
  btrfs: check if the fsid in the primary sb and copy sb are same
  btrfs: verify checksum when superblock is read for scan
  btrfs: verify checksum for all devices in mount context
  btrfs: drop the redundant invalidate_bdev()

 fs/btrfs/disk-io.c | 72 +++---
 fs/btrfs/disk-io.h |  1 +
 fs/btrfs/volumes.c | 84 ++
 3 files changed, 102 insertions(+), 55 deletions(-)

Anand Jain (1):
  btrfs-progs: wipe copies of the stale superblock beyond -b size

 utils.c | 35 +++
 1 file changed, 35 insertions(+)

-- 
2.7.0

--
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 8/8] btrfs: drop the redundant invalidate_bdev()

2018-03-26 Thread Anand Jain
During the mount context btrfs_open_devices() calls invalidate_bdev()
for all the devices. So drop the invalidate_bdev() in open_ctree()
which is only for the btrfs_fs_devices::latest_bdev.

The call trace is as shown below.

btrfs_mount_root()
 |
 |_btrfs_parse_early_options (-o device only)
 | |_btrfs_scan_one_device
 |   |_btrfs_read_disk_super()
 | |_read_cache_page_gfp()
 |
 |_btrfs_scan_one_device(mount-arg-dev only)
 | |_btrfs_read_disk_super()
 |   |_read_cache_page_gfp()
 |
 |
 |_btrfs_open_devices(fsid:all)
 |  |_btrfs_open_one_device()
 ||_btrfs_get_bdev_and_sb()  <--- invalidate_bdev(fsid:all)
 |  |_btrfs_read_dev_super()
 ||_btrfs_read_dev_one_super()
 |  |___bread()
 |
 |_btrfs_fill_super()
   |_btrfs_open_ctree()   <-- invalidate_bdev(latest_bdev) <-- redundant
 |_btrfs_read_dev_super(latest_bdev only)
   |_btrfs_read_dev_one_super(latest_bdev only)
 |___bread(latest_bdev)

Signed-off-by: Anand Jain 
---
 fs/btrfs/disk-io.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 3cc50041c0b9..4f667c99dd16 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2553,8 +2553,6 @@ int open_ctree(struct super_block *sb,
 
__setup_root(tree_root, fs_info, BTRFS_ROOT_TREE_OBJECTID);
 
-   invalidate_bdev(fs_devices->latest_bdev);
-
/*
 * Read super block and check the signature bytes only
 */
-- 
2.7.0

--
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: remove BTRFS_CRC32_SIZE definition

2018-03-26 Thread Qu Wenruo


On 2018年03月26日 08:54, Misono Tomohiro wrote:
> On 2018/03/23 18:14, Qu Wenruo wrote:
>>
>>
>> On 2018年03月23日 16:20, Misono Tomohiro wrote:
>>> The kernel code no longer has BTRFS_CRC32_SIZE and only uses
>>> btrfs_csum_sizes[]. So, update the progs code as well.
>>>
>>> Suggested-by: Qu Wenruo 
>>> Signed-off-by: Tomohiro Misono 
>>> ---
>>>  convert/common.c |  2 +-
>>>  convert/main.c   |  2 +-
>>>  ctree.h  |  3 +--
>>>  image/main.c |  4 ++--
>>>  mkfs/common.c| 14 +++---
>>>  5 files changed, 12 insertions(+), 13 deletions(-)
>>>
>>> diff --git a/convert/common.c b/convert/common.c
>>> index 3860f3b9..2b944fd8 100644
>>> --- a/convert/common.c
>>> +++ b/convert/common.c
>>> @@ -219,7 +219,7 @@ static inline int write_temp_extent_buffer(int fd, 
>>> struct extent_buffer *buf,
>>>  {
>>> int ret;
>>>  
>>> -   csum_tree_block_size(buf, BTRFS_CRC32_SIZE, 0);
>>> +   csum_tree_block_size(buf, btrfs_csum_sizes[BTRFS_CSUM_TYPE_CRC32], 0);
>>
>> I'd say the normal kernel way to do this is like this, other than using
>> BTRFS_CSUM_TYPE_CRC32:
>>  u16 csum_size = btrfs_super_csum_size(fs_info->super_copy);
>>
>> Thanks,
>> Qu
> 
> 
> Thanks, but we cannot access fs_info or struct btrfs_super_block here (and 
> others in this diff).
> Should we pass the csum type parameter as an argument? Since currently the 
> only
> supported type is crc32, I'm not sure if we should write the code so generic 
> at this time.

Fair enough.

Reviewed-by: Qu Wenruo 

Thanks,
Qu
> 
> --
> 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
> 



signature.asc
Description: OpenPGP digital signature