[v3,07/14] btrfs-progs: Doc/mkfs: Add extra condition for rootdir option
diff mbox

Message ID 20170918072139.6300-8-quwenruo.btrfs@gmx.com
State New
Headers show

Commit Message

Qu Wenruo Sept. 18, 2017, 7:21 a.m. UTC
Add extra limitation explained for --rootdir option, including:
1) Size limitation
   Now I decide to follow "mkfs.ext4 -d" behavior, so user is
   responsible to make sure the block device/file is large enough.

2) Read permission
   If user can't read the content, mkfs will just fail.
   So user is also responsible to make sure to have enough privilege.

3) Extra warning about the behavior change
   Since we we don't shrink fs the create file image, add such warning
   in documentation.

Signed-off-by: Qu Wenruo <quwenruo.btrfs@gmx.com>
---
 Documentation/mkfs.btrfs.asciidoc | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Anand Jain Sept. 22, 2017, 9:24 a.m. UTC | #1
> +WARNING: Before v4.14 btrfs-progs, *--rootdir* will shrink the filesystem,
> +prevent user to make use of the remaining space.
> +In v4.14 btrfs-progs, this behavior is changed, and will not shrink the fs.
> +The result should be the same as `mkfs`, `mount` and then `cp -r`. +

  Hmm well. Shrink to fit exactly to the size of the given 
files-and-directory is indeed a nice feature. Which would help to create 
a golden-image btrfs seed device. Its not popular as of now, but at some 
point it may in the cloud environment.

  Replacing this feature instead of creating a new option is not a good 
idea indeed. I missed something ?

Thanks, Anand

> +Also, if destination file/block device does not exist, *--rootdir* will not
> +create the image file, to make it follow the normal mkfs behavior.


--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Qu Wenruo Sept. 22, 2017, 10:39 a.m. UTC | #2
As I already stated in an other thread, if you want to shrink, do it in another command line tool.
Do one thing and do it simple. (Although Btrfs itself is already out of the UNIX way)

It may be offline shrink/balance. But not to further complexing the --rootdir option now.

And you also said that, the shrink feature is not a popular feature *NOW*, then I don't think it's worthy to implment it *NOW* either.
Implement future feature in the future please.

And further more, even following the existing shrink behavior, you still need to truncate the file all by yourself.
Which is no better than creating a good sized file and then mkfs on it.

Thanks,
Qu

Sent: Friday, September 22, 2017 at 5:24 PM
From: "Anand Jain" <anand.jain@oracle.com>
To: "Qu Wenruo" <quwenruo.btrfs@gmx.com>, linux-btrfs@vger.kernel.org
Cc: dsterba@suse.cz
Subject: Re: [PATCH v3 07/14] btrfs-progs: Doc/mkfs: Add extra condition for rootdir option

> +WARNING: Before v4.14 btrfs-progs, *--rootdir* will shrink the filesystem,
> +prevent user to make use of the remaining space.
> +In v4.14 btrfs-progs, this behavior is changed, and will not shrink the fs.
> +The result should be the same as `mkfs`, `mount` and then `cp -r`. +

Hmm well. Shrink to fit exactly to the size of the given
files-and-directory is indeed a nice feature. Which would help to create
a golden-image btrfs seed device. Its not popular as of now, but at some
point it may in the cloud environment.

Replacing this feature instead of creating a new option is not a good
idea indeed. I missed something ?

Thanks, Anand

> +Also, if destination file/block device does not exist, *--rootdir* will not
> +create the image file, to make it follow the normal mkfs behavior.


--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Austin S. Hemmelgarn Sept. 22, 2017, 11:38 a.m. UTC | #3
On 2017-09-22 06:39, Qu Wenruo wrote:
> As I already stated in an other thread, if you want to shrink, do it in another command line tool.
> Do one thing and do it simple. (Although Btrfs itself is already out of the UNIX way)
Unless I'm reading the code wrong, the shrinking isn't happening in a 
second pass, so this _is_ doing one thing, and it appears to be doing it 
as simply as possible (although arguably not correctly because of the 
1MB reserved area being used).
> 
> It may be offline shrink/balance. But not to further complexing the --rootdir option now. >
> And you also said that, the shrink feature is not a popular feature *NOW*, then I don't think it's worthy to implment it *NOW* either.
> Implement future feature in the future please.
I'm not sure about you, but I could have sworn that he meant seed 
devices weren't a popular feature right now, not that the shrinking is. 
As a general rule, the whole option of pre-loading a filesystem with 
data as you're creating it is not a popular feature, because most 
sysadmins are much more willing to trust adding data after the 
filesystem is created.

Personally, given the existence of seed devices, I would absolutely 
expect there to be a quick and easy way to generate a minimalistic image 
using a single command (because realistic usage of seed devices implies 
minimalistic images).  I agree that it shouldn't be the default 
behavior, but I don't think it needs to be removed completely.  The main 
issues here are that it wasn't documented well (like many other things 
in BTRFS), and it didn't generate a filesystem that was properly 
compliant with the on-disk format (because it used space in the 1MB 
reserved area at the beginning of the FS).  Fixing those issues in no 
way requires removing the feature.
> 
> And further more, even following the existing shrink behavior, you still need to truncate the file all by yourself.
> Which is no better than creating a good sized file and then mkfs on it.
Only if you pre-create the file.  If the file doesn't exist, it gets 
created at the appropriate size.  That's part of why the chunk 
allocations are screwed up and stuff gets put in the first 1MB, it 
generates the FS on-the-fly and writes it out as it's generating it.
> 
> Thanks,
> Qu
> 
> Sent: Friday, September 22, 2017 at 5:24 PM
> From: "Anand Jain" <anand.jain@oracle.com>
> To: "Qu Wenruo" <quwenruo.btrfs@gmx.com>, linux-btrfs@vger.kernel.org
> Cc: dsterba@suse.cz
> Subject: Re: [PATCH v3 07/14] btrfs-progs: Doc/mkfs: Add extra condition for rootdir option
> 
>> +WARNING: Before v4.14 btrfs-progs, *--rootdir* will shrink the filesystem,
>> +prevent user to make use of the remaining space.
>> +In v4.14 btrfs-progs, this behavior is changed, and will not shrink the fs.
>> +The result should be the same as `mkfs`, `mount` and then `cp -r`. +
> 
> Hmm well. Shrink to fit exactly to the size of the given
> files-and-directory is indeed a nice feature. Which would help to create
> a golden-image btrfs seed device. Its not popular as of now, but at some
> point it may in the cloud environment.
> 
> Replacing this feature instead of creating a new option is not a good
> idea indeed. I missed something ?
> 
> Thanks, Anand
> 
>> +Also, if destination file/block device does not exist, *--rootdir* will not
>> +create the image file, to make it follow the normal mkfs behavior.

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Qu Wenruo Sept. 22, 2017, 12:32 p.m. UTC | #4
On 2017年09月22日 19:38, Austin S. Hemmelgarn wrote:
> On 2017-09-22 06:39, Qu Wenruo wrote:
>> As I already stated in an other thread, if you want to shrink, do it 
>> in another command line tool.
>> Do one thing and do it simple. (Although Btrfs itself is already out 
>> of the UNIX way)
> Unless I'm reading the code wrong, the shrinking isn't happening in a 
> second pass, so this _is_ doing one thing, and it appears to be doing it 
> as simply as possible (although arguably not correctly because of the 
> 1MB reserved area being used).

If you're referring to my V1 implementation of shrink, that's doing 
*one* thing.

But the original shrinking code? Nope, or we won't have the custom chunk 
allocator at all.


What I really mean is, if one wants to shrink, at least don't couple the 
shrink code into "mkfs.btrfs".

Do shrink in its own tool/subcommand, not in a really unrelated tool.

>>
>> It may be offline shrink/balance. But not to further complexing the 
>> --rootdir option now. >
>> And you also said that, the shrink feature is not a popular feature 
>> *NOW*, then I don't think it's worthy to implment it *NOW* either.
>> Implement future feature in the future please.
> I'm not sure about you, but I could have sworn that he meant seed 
> devices weren't a popular feature right now,

Oh, sorry for my misunderstanding.

> not that the shrinking is. 
> As a general rule, the whole option of pre-loading a filesystem with 
> data as you're creating it is not a popular feature, because most 
> sysadmins are much more willing to trust adding data after the 
> filesystem is created.
> 
> Personally, given the existence of seed devices, I would absolutely 
> expect there to be a quick and easy way to generate a minimalistic image 
> using a single command (because realistic usage of seed devices implies 
> minimalistic images).  I agree that it shouldn't be the default 
> behavior, but I don't think it needs to be removed completely.

Just like I said in cover letter, even for ext*, it's provided by 
genext2fs, not mke2fs.

I totally understand end-user really want a do-it-all solution.
But from developers' view, the old UNIX way is better to maintain code 
clean and easy to read.


In fact, you can even create your script to do the old behavior if you 
don't care that the result may not fully take use of the space, just by:

1) Calculate the size of the whole directory
    "du" command can do it easily, and it does things better than us! For
    years!

2) Multiple the value according to the meta/data profile
    Take care of small files, which will be inlined.
    And don't forget size for data checksum.
    (BTW, there is no way to change the behavor of inlined data and data
     checksum for mkfs. unlike btrfs-convert)


3) Create a file with size calculated by step 2)

4) Execute "mkfs.btrfs -d <dir> <created file>"

>  The main 
> issues here are that it wasn't documented well (like many other things 
> in BTRFS), and it didn't generate a filesystem that was properly 
> compliant with the on-disk format (because it used space in the 1MB 
> reserved area at the beginning of the FS).  Fixing those issues in no 
> way requires removing the feature.

Yes, 1MB can be fixed easily (although not properly). But the whole 
customized chunk allocator is the real problem.
The almost dead code is always bug-prone. Replace it with updated 
generic chunk allocator is the way to avoid later whac-a-mole, and 
should be done asap.

>>
>> And further more, even following the existing shrink behavior, you 
>> still need to truncate the file all by yourself.
>> Which is no better than creating a good sized file and then mkfs on it.
> Only if you pre-create the file.  If the file doesn't exist, it gets 
> created at the appropriate size.  That's part of why the chunk 
> allocations are screwed up and stuff gets put in the first 1MB, it 
> generates the FS on-the-fly and writes it out as it's generating it.

Nope, even you created the file in advance, it will still occupy the 
first 1M.

BTW, you can get back the size calculation for shrink, but you will soon 
find that it's just the start of a new nightmare.
Because there is no easy way to calculate the real metadata usage.

The result (and the old calculator) will be no better than guessing it.
(Well, just multiply the dir size by 2 will never go wrong)


Thanks,
Qu

>>
>> Thanks,
>> Qu
>>
>> Sent: Friday, September 22, 2017 at 5:24 PM
>> From: "Anand Jain" <anand.jain@oracle.com>
>> To: "Qu Wenruo" <quwenruo.btrfs@gmx.com>, linux-btrfs@vger.kernel.org
>> Cc: dsterba@suse.cz
>> Subject: Re: [PATCH v3 07/14] btrfs-progs: Doc/mkfs: Add extra 
>> condition for rootdir option
>>
>>> +WARNING: Before v4.14 btrfs-progs, *--rootdir* will shrink the 
>>> filesystem,
>>> +prevent user to make use of the remaining space.
>>> +In v4.14 btrfs-progs, this behavior is changed, and will not shrink 
>>> the fs.
>>> +The result should be the same as `mkfs`, `mount` and then `cp -r`. +
>>
>> Hmm well. Shrink to fit exactly to the size of the given
>> files-and-directory is indeed a nice feature. Which would help to create
>> a golden-image btrfs seed device. Its not popular as of now, but at some
>> point it may in the cloud environment.
>>
>> Replacing this feature instead of creating a new option is not a good
>> idea indeed. I missed something ?
>>
>> Thanks, Anand
>>
>>> +Also, if destination file/block device does not exist, *--rootdir* 
>>> will not
>>> +create the image file, to make it follow the normal mkfs behavior.
> 
> -- 
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Austin S. Hemmelgarn Sept. 22, 2017, 1:33 p.m. UTC | #5
On 2017-09-22 08:32, Qu Wenruo wrote:
> On 2017年09月22日 19:38, Austin S. Hemmelgarn wrote:
>> On 2017-09-22 06:39, Qu Wenruo wrote:
>>> As I already stated in an other thread, if you want to shrink, do it 
>>> in another command line tool.
>>> Do one thing and do it simple. (Although Btrfs itself is already out 
>>> of the UNIX way)
>> Unless I'm reading the code wrong, the shrinking isn't happening in a 
>> second pass, so this _is_ doing one thing, and it appears to be doing 
>> it as simply as possible (although arguably not correctly because of 
>> the 1MB reserved area being used).
> 
> If you're referring to my V1 implementation of shrink, that's doing 
> *one* thing.
> 
> But the original shrinking code? Nope, or we won't have the custom chunk 
> allocator at all.
> 
> What I really mean is, if one wants to shrink, at least don't couple the 
> shrink code into "mkfs.btrfs".
> 
> Do shrink in its own tool/subcommand, not in a really unrelated tool.
There are two cases for shrinking a filesystem:
1. You're resizing it to move to a smaller disk (or speed up copying to 
another disk).
2. You're generating a filesystem image that needs to be as small as 
possible.

Case 1 is obviously unrelated to creating a filesystem.  Case 2 however 
is kind of integral to the creation of the filesystem image itself by 
definition, especially for a CoW filesystem because it's not possible to 
shrink to the absolute smallest size due to the GlobalReserve and other 
things.

Similarly, there are two primary use cases for pre-loading the 
filesystem with data:
1. Avoiding a copy when reprovisioning storage on a system.  For 
example, splitting a directory out to a new filesystem, you could use 
the -r option to avoid having to copy the data after mounting the 
filesystem.
2. Creating base images for systems.

The first case shouldn't need the shrinking functionality, but the 
second is a very common use case together with the second usage for 
shrinking a filesystem.
> 
>>>
>>> It may be offline shrink/balance. But not to further complexing the 
>>> --rootdir option now. >
>>> And you also said that, the shrink feature is not a popular feature 
>>> *NOW*, then I don't think it's worthy to implment it *NOW* either.
>>> Implement future feature in the future please.
>> I'm not sure about you, but I could have sworn that he meant seed 
>> devices weren't a popular feature right now,
> 
> Oh, sorry for my misunderstanding.
> 
>> not that the shrinking is. As a general rule, the whole option of 
>> pre-loading a filesystem with data as you're creating it is not a 
>> popular feature, because most sysadmins are much more willing to trust 
>> adding data after the filesystem is created.
>>
>> Personally, given the existence of seed devices, I would absolutely 
>> expect there to be a quick and easy way to generate a minimalistic 
>> image using a single command (because realistic usage of seed devices 
>> implies minimalistic images).  I agree that it shouldn't be the 
>> default behavior, but I don't think it needs to be removed completely.
> 
> Just like I said in cover letter, even for ext*, it's provided by 
> genext2fs, not mke2fs.
Then maybe this should get split out into a separate tool instead of 
just removing it completely?  There is obviously at least some interest 
in this functionality.
> 
> I totally understand end-user really want a do-it-all solution.
> But from developers' view, the old UNIX way is better to maintain code 
> clean and easy to read.
What the code is doing should have near zero impact on readability.  If 
it did, then the BTRFS code in general is already way beyond most people.
> 
> 
> In fact, you can even create your script to do the old behavior if you 
> don't care that the result may not fully take use of the space, just by:
> 
> 1) Calculate the size of the whole directory
>     "du" command can do it easily, and it does things better than us! For
>     years!
Um, no it actually doesn't do things better in all cases.  it doesn't 
account for extended attributes, or metadata usage, or any number of 
other things that factor into how much space a file or directory will 
take up on BTRFS.  It's good enough for finding what's using most of 
your space, but it's not reliable for determining how much space you 
need to store that data (especially once you throw in in-line compression).
> 
> 2) Multiple the value according to the meta/data profile
>     Take care of small files, which will be inlined.
>     And don't forget size for data checksum.
>     (BTW, there is no way to change the behavor of inlined data and data
>      checksum for mkfs. unlike btrfs-convert)
This is where the issue lies.  It's not possible for a person to 
calculate this with reasonable accuracy, and you arguably can't even do 
it for certain programmatically without some serious work.
> 
> 3) Create a file with size calculated by step 2)
> 
> 4) Execute "mkfs.btrfs -d <dir> <created file>"
> 
>>   The main issues here are that it wasn't documented well (like many 
>> other things in BTRFS), and it didn't generate a filesystem that was 
>> properly compliant with the on-disk format (because it used space in 
>> the 1MB reserved area at the beginning of the FS).  Fixing those 
>> issues in no way requires removing the feature.
> 
> Yes, 1MB can be fixed easily (although not properly). But the whole 
> customized chunk allocator is the real problem.
> The almost dead code is always bug-prone. Replace it with updated 
> generic chunk allocator is the way to avoid later whac-a-mole, and 
> should be done asap.
Agreed, but that doesn't preclude having the option to keep the 
generated image to the minimum size.
> 
>>>
>>> And further more, even following the existing shrink behavior, you 
>>> still need to truncate the file all by yourself.
>>> Which is no better than creating a good sized file and then mkfs on it.
>> Only if you pre-create the file.  If the file doesn't exist, it gets 
>> created at the appropriate size.  That's part of why the chunk 
>> allocations are screwed up and stuff gets put in the first 1MB, it 
>> generates the FS on-the-fly and writes it out as it's generating it.
> 
> Nope, even you created the file in advance, it will still occupy the 
> first 1M.
Because it doesn't assume that the file is there to begin with.  It's 
not trying O_CREAT and falling back to some different code if that 
fails.  The code assumes that the file won't be there, and handles 
things accordingly albeit incorrectly (it should seek past the first 
1MB, write the initial SB, and then start chunk allocation).  IOW, the 
code takes a shortcut in that it doesn't check for the file, and the 
rest is written to account for that by assuming there wasn't a file. 
The lack of truncation just means it doesn't try to trim things down by 
itself if the file is already there (it assumes that you knew what you 
were doing).

Put differently, I'm fairly certain that the current -r option removes 
the total size check unless the target is a device (although it may 
remove the check there too and just fail when it tries to write past the 
end of the device), and will thus extend existing files to the required 
size to hold the data.
> 
> BTW, you can get back the size calculation for shrink, but you will soon 
> find that it's just the start of a new nightmare.
> Because there is no easy way to calculate the real metadata usage.
> 
> The result (and the old calculator) will be no better than guessing it.
> (Well, just multiply the dir size by 2 will never go wrong)
No, it can go wrong depending on what you count as part of the size.
> 
> 
> Thanks,
> Qu
> 
>>>
>>> Thanks,
>>> Qu
>>>
>>> Sent: Friday, September 22, 2017 at 5:24 PM
>>> From: "Anand Jain" <anand.jain@oracle.com>
>>> To: "Qu Wenruo" <quwenruo.btrfs@gmx.com>, linux-btrfs@vger.kernel.org
>>> Cc: dsterba@suse.cz
>>> Subject: Re: [PATCH v3 07/14] btrfs-progs: Doc/mkfs: Add extra 
>>> condition for rootdir option
>>>
>>>> +WARNING: Before v4.14 btrfs-progs, *--rootdir* will shrink the 
>>>> filesystem,
>>>> +prevent user to make use of the remaining space.
>>>> +In v4.14 btrfs-progs, this behavior is changed, and will not shrink 
>>>> the fs.
>>>> +The result should be the same as `mkfs`, `mount` and then `cp -r`. +
>>>
>>> Hmm well. Shrink to fit exactly to the size of the given
>>> files-and-directory is indeed a nice feature. Which would help to create
>>> a golden-image btrfs seed device. Its not popular as of now, but at some
>>> point it may in the cloud environment.
>>>
>>> Replacing this feature instead of creating a new option is not a good
>>> idea indeed. I missed something ?
>>>
>>> Thanks, Anand
>>>
>>>> +Also, if destination file/block device does not exist, *--rootdir* 
>>>> will not
>>>> +create the image file, to make it follow the normal mkfs behavior.
>>
>> -- 
>> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
>> the body of a message to majordomo@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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Qu Wenruo Sept. 22, 2017, 3:07 p.m. UTC | #6
On 2017年09月22日 21:33, Austin S. Hemmelgarn wrote:
> On 2017-09-22 08:32, Qu Wenruo wrote:
>> On 2017年09月22日 19:38, Austin S. Hemmelgarn wrote:
>>> On 2017-09-22 06:39, Qu Wenruo wrote:
>>>> As I already stated in an other thread, if you want to shrink, do it 
>>>> in another command line tool.
>>>> Do one thing and do it simple. (Although Btrfs itself is already out 
>>>> of the UNIX way)
>>> Unless I'm reading the code wrong, the shrinking isn't happening in a 
>>> second pass, so this _is_ doing one thing, and it appears to be doing 
>>> it as simply as possible (although arguably not correctly because of 
>>> the 1MB reserved area being used).
>>
>> If you're referring to my V1 implementation of shrink, that's doing 
>> *one* thing.
>>
>> But the original shrinking code? Nope, or we won't have the custom 
>> chunk allocator at all.
>>
>> What I really mean is, if one wants to shrink, at least don't couple 
>> the shrink code into "mkfs.btrfs".
>>
>> Do shrink in its own tool/subcommand, not in a really unrelated tool.
> There are two cases for shrinking a filesystem:
> 1. You're resizing it to move to a smaller disk (or speed up copying to 
> another disk).
> 2. You're generating a filesystem image that needs to be as small as 
> possible.

I would argue there is no meaning of creating *smallest* image. (Of 
course it exists)

We could put tons of code to implement, and more (or less) test cases to 
verify it.

But the demand doesn't validate the effort.

All my points are clear for this patchset:
I know I removed one function, and my reason is:
1) No or little usage
    And it's anti intuition.
2) Dead code (not tested nor well documented)
3) Possible workaround

I can add several extra reasons as I stated before, but number of 
reasons won't validate anything anyway.

Building software is always trading one thing for another.
I understand there may be some need for this function, but it doesn't 
validate the cost.

And I think the fact that until recently a mail reported about the 
shrinking behavior has already backed up my point.

Thanks,
Qu

> 
> Case 1 is obviously unrelated to creating a filesystem.  Case 2 however 
> is kind of integral to the creation of the filesystem image itself by 
> definition, especially for a CoW filesystem because it's not possible to 
> shrink to the absolute smallest size due to the GlobalReserve and other 
> things.
> 
> Similarly, there are two primary use cases for pre-loading the 
> filesystem with data:
> 1. Avoiding a copy when reprovisioning storage on a system.  For 
> example, splitting a directory out to a new filesystem, you could use 
> the -r option to avoid having to copy the data after mounting the 
> filesystem.
> 2. Creating base images for systems.
> 
> The first case shouldn't need the shrinking functionality, but the 
> second is a very common use case together with the second usage for 
> shrinking a filesystem.
>>
>>>>
>>>> It may be offline shrink/balance. But not to further complexing the 
>>>> --rootdir option now. >
>>>> And you also said that, the shrink feature is not a popular feature 
>>>> *NOW*, then I don't think it's worthy to implment it *NOW* either.
>>>> Implement future feature in the future please.
>>> I'm not sure about you, but I could have sworn that he meant seed 
>>> devices weren't a popular feature right now,
>>
>> Oh, sorry for my misunderstanding.
>>
>>> not that the shrinking is. As a general rule, the whole option of 
>>> pre-loading a filesystem with data as you're creating it is not a 
>>> popular feature, because most sysadmins are much more willing to 
>>> trust adding data after the filesystem is created.
>>>
>>> Personally, given the existence of seed devices, I would absolutely 
>>> expect there to be a quick and easy way to generate a minimalistic 
>>> image using a single command (because realistic usage of seed devices 
>>> implies minimalistic images).  I agree that it shouldn't be the 
>>> default behavior, but I don't think it needs to be removed completely.
>>
>> Just like I said in cover letter, even for ext*, it's provided by 
>> genext2fs, not mke2fs.
> Then maybe this should get split out into a separate tool instead of 
> just removing it completely?  There is obviously at least some interest 
> in this functionality.
>>
>> I totally understand end-user really want a do-it-all solution.
>> But from developers' view, the old UNIX way is better to maintain code 
>> clean and easy to read.
> What the code is doing should have near zero impact on readability.  If 
> it did, then the BTRFS code in general is already way beyond most people.
>>
>>
>> In fact, you can even create your script to do the old behavior if you 
>> don't care that the result may not fully take use of the space, just by:
>>
>> 1) Calculate the size of the whole directory
>>     "du" command can do it easily, and it does things better than us! For
>>     years!
> Um, no it actually doesn't do things better in all cases.  it doesn't 
> account for extended attributes, or metadata usage, or any number of 
> other things that factor into how much space a file or directory will 
> take up on BTRFS.  It's good enough for finding what's using most of 
> your space, but it's not reliable for determining how much space you 
> need to store that data (especially once you throw in in-line compression).
>>
>> 2) Multiple the value according to the meta/data profile
>>     Take care of small files, which will be inlined.
>>     And don't forget size for data checksum.
>>     (BTW, there is no way to change the behavor of inlined data and data
>>      checksum for mkfs. unlike btrfs-convert)
> This is where the issue lies.  It's not possible for a person to 
> calculate this with reasonable accuracy, and you arguably can't even do 
> it for certain programmatically without some serious work.
>>
>> 3) Create a file with size calculated by step 2)
>>
>> 4) Execute "mkfs.btrfs -d <dir> <created file>"
>>
>>>   The main issues here are that it wasn't documented well (like many 
>>> other things in BTRFS), and it didn't generate a filesystem that was 
>>> properly compliant with the on-disk format (because it used space in 
>>> the 1MB reserved area at the beginning of the FS).  Fixing those 
>>> issues in no way requires removing the feature.
>>
>> Yes, 1MB can be fixed easily (although not properly). But the whole 
>> customized chunk allocator is the real problem.
>> The almost dead code is always bug-prone. Replace it with updated 
>> generic chunk allocator is the way to avoid later whac-a-mole, and 
>> should be done asap.
> Agreed, but that doesn't preclude having the option to keep the 
> generated image to the minimum size.
>>
>>>>
>>>> And further more, even following the existing shrink behavior, you 
>>>> still need to truncate the file all by yourself.
>>>> Which is no better than creating a good sized file and then mkfs on it.
>>> Only if you pre-create the file.  If the file doesn't exist, it gets 
>>> created at the appropriate size.  That's part of why the chunk 
>>> allocations are screwed up and stuff gets put in the first 1MB, it 
>>> generates the FS on-the-fly and writes it out as it's generating it.
>>
>> Nope, even you created the file in advance, it will still occupy the 
>> first 1M.
> Because it doesn't assume that the file is there to begin with.  It's 
> not trying O_CREAT and falling back to some different code if that 
> fails.  The code assumes that the file won't be there, and handles 
> things accordingly albeit incorrectly (it should seek past the first 
> 1MB, write the initial SB, and then start chunk allocation).  IOW, the 
> code takes a shortcut in that it doesn't check for the file, and the 
> rest is written to account for that by assuming there wasn't a file. The 
> lack of truncation just means it doesn't try to trim things down by 
> itself if the file is already there (it assumes that you knew what you 
> were doing).
> 
> Put differently, I'm fairly certain that the current -r option removes 
> the total size check unless the target is a device (although it may 
> remove the check there too and just fail when it tries to write past the 
> end of the device), and will thus extend existing files to the required 
> size to hold the data.
>>
>> BTW, you can get back the size calculation for shrink, but you will 
>> soon find that it's just the start of a new nightmare.
>> Because there is no easy way to calculate the real metadata usage.
>>
>> The result (and the old calculator) will be no better than guessing it.
>> (Well, just multiply the dir size by 2 will never go wrong)
> No, it can go wrong depending on what you count as part of the size.
>>
>>
>> Thanks,
>> Qu
>>
>>>>
>>>> Thanks,
>>>> Qu
>>>>
>>>> Sent: Friday, September 22, 2017 at 5:24 PM
>>>> From: "Anand Jain" <anand.jain@oracle.com>
>>>> To: "Qu Wenruo" <quwenruo.btrfs@gmx.com>, linux-btrfs@vger.kernel.org
>>>> Cc: dsterba@suse.cz
>>>> Subject: Re: [PATCH v3 07/14] btrfs-progs: Doc/mkfs: Add extra 
>>>> condition for rootdir option
>>>>
>>>>> +WARNING: Before v4.14 btrfs-progs, *--rootdir* will shrink the 
>>>>> filesystem,
>>>>> +prevent user to make use of the remaining space.
>>>>> +In v4.14 btrfs-progs, this behavior is changed, and will not 
>>>>> shrink the fs.
>>>>> +The result should be the same as `mkfs`, `mount` and then `cp -r`. +
>>>>
>>>> Hmm well. Shrink to fit exactly to the size of the given
>>>> files-and-directory is indeed a nice feature. Which would help to 
>>>> create
>>>> a golden-image btrfs seed device. Its not popular as of now, but at 
>>>> some
>>>> point it may in the cloud environment.
>>>>
>>>> Replacing this feature instead of creating a new option is not a good
>>>> idea indeed. I missed something ?
>>>>
>>>> Thanks, Anand
>>>>
>>>>> +Also, if destination file/block device does not exist, *--rootdir* 
>>>>> will not
>>>>> +create the image file, to make it follow the normal mkfs behavior.
>>>
>>> -- 
>>> To unsubscribe from this list: send the line "unsubscribe 
>>> linux-btrfs" in
>>> the body of a message to majordomo@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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Anand Jain Sept. 24, 2017, 10:10 a.m. UTC | #7
> All my points are clear for this patchset:
> I know I removed one function, and my reason is:
> 1) No or little usage
>     And it's anti intuition.
> 2) Dead code (not tested nor well documented)
> 3) Possible workaround
> 
> I can add several extra reasons as I stated before, but number of 
> reasons won't validate anything anyway.

  End user convenience wins over the developer's technical difficulties.

  Pls don't remove this feature, it needs fix such as #2 (above) to 
improve on #1 (above) as in your list.

Thanks, Anand
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Goffredo Baroncelli Sept. 24, 2017, 2:08 p.m. UTC | #8
On 09/24/2017 12:10 PM, Anand Jain wrote:
> 
> 
>> All my points are clear for this patchset:
>> I know I removed one function, and my reason is:
>> 1) No or little usage
>>     And it's anti intuition.
>> 2) Dead code (not tested nor well documented)
>> 3) Possible workaround
>>
>> I can add several extra reasons as I stated before, but number of reasons won't validate anything anyway.
> 
>  End user convenience wins over the developer's technical difficulties.

Sorry, but I have to agree with Qu; there is no a big demand (other than Austin) for this functionality; even you stated that "...at some point it may..."; until now the UI is quite unfriendly (we should use a big enough device, and then cut it by hand on the basis of the output of mkfs.btrfs)...

I fear that this is another feature which increase the complexity of btrfs (and tools) with little or none usage....

The work of Qu is a nice cleanup; I hope that this will be the direction which BTRFS will takes: removing of "strange/unused" features improving the reliability of the others.

BR
G.Baroncelli



> 
>  Pls don't remove this feature, it needs fix such as #2 (above) to improve on #1 (above) as in your list.
> 
> Thanks, Anand
> -- 
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
Austin S. Hemmelgarn Sept. 25, 2017, 11:15 a.m. UTC | #9
On 2017-09-24 10:08, Goffredo Baroncelli wrote:
> On 09/24/2017 12:10 PM, Anand Jain wrote:
>>
>>
>>> All my points are clear for this patchset:
>>> I know I removed one function, and my reason is:
>>> 1) No or little usage
>>>      And it's anti intuition.
>>> 2) Dead code (not tested nor well documented)
>>> 3) Possible workaround
>>>
>>> I can add several extra reasons as I stated before, but number of reasons won't validate anything anyway.
>>
>>   End user convenience wins over the developer's technical difficulties.
> 
> Sorry, but I have to agree with Qu; there is no a big demand (other than Austin) for this functionality; even you stated that "...at some point it may..."; until now the UI is quite unfriendly (we should use a big enough device, and then cut it by hand on the basis of the output of mkfs.btrfs)...
I will comment that I agree that it should not be the default.  It's not 
intuitive for most people, and as you say it's a niche feature.  Just 
removing it completely though with the above argument sounds very much 
like trying to meet quotas for coding.
> 
> I fear that this is another feature which increase the complexity of btrfs (and tools) with little or none usage....
On average?  It only increases the complexity of mkfs once there's a fix 
for the (theoretically trivial to fix) issue with it ignoring the fact 
that the first 1MB of space is supposed to be untouched by BTRFS.
> 
> The work of Qu is a nice cleanup; I hope that this will be the direction which BTRFS will takes: removing of "strange/unused" features improving the reliability of the others.
The two are not inherently interdependent, and that argument doesn't 
exactly hold up to scrutiny considering that mkfs is already perfectly 
reliable even with this feature, and it does not compromise the 
reliability of other features (again, once you fix the usage of the 
reserved area at the beginning of the image).
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Austin S. Hemmelgarn Sept. 25, 2017, 11:53 a.m. UTC | #10
On 2017-09-22 11:07, Qu Wenruo wrote:
> 
> 
> On 2017年09月22日 21:33, Austin S. Hemmelgarn wrote:
>> On 2017-09-22 08:32, Qu Wenruo wrote:
>>> On 2017年09月22日 19:38, Austin S. Hemmelgarn wrote:
>>>> On 2017-09-22 06:39, Qu Wenruo wrote:
>>>>> As I already stated in an other thread, if you want to shrink, do 
>>>>> it in another command line tool.
>>>>> Do one thing and do it simple. (Although Btrfs itself is already 
>>>>> out of the UNIX way)
>>>> Unless I'm reading the code wrong, the shrinking isn't happening in 
>>>> a second pass, so this _is_ doing one thing, and it appears to be 
>>>> doing it as simply as possible (although arguably not correctly 
>>>> because of the 1MB reserved area being used).
>>>
>>> If you're referring to my V1 implementation of shrink, that's doing 
>>> *one* thing.
>>>
>>> But the original shrinking code? Nope, or we won't have the custom 
>>> chunk allocator at all.
>>>
>>> What I really mean is, if one wants to shrink, at least don't couple 
>>> the shrink code into "mkfs.btrfs".
>>>
>>> Do shrink in its own tool/subcommand, not in a really unrelated tool.
>> There are two cases for shrinking a filesystem:
>> 1. You're resizing it to move to a smaller disk (or speed up copying 
>> to another disk).
>> 2. You're generating a filesystem image that needs to be as small as 
>> possible.
> 
> I would argue there is no meaning of creating *smallest* image. (Of 
> course it exists).
There is an exact meaning given the on-disk layout.  It's an image whose 
size is equal to the sum of:
1. 1MB (for the reserved space at the beginning).
2. However many superblocks it should have given the size.
3. The total amount of file data and extended attribute data to be 
included, rounding up for block size
4. The exact amount of metadata space needed to represent the tree from 
3, also rounding up for block size.
5. The exact amount of system chunk space needed to handle 3 and 4, plus 
enough room to allocate at least one more chunk of each type (to 
ultimately allow for resizing the filesystem if desired).
6. Exactly enough reserved metadata space to resize the FS.
> 
> We could put tons of code to implement, and more (or less) test cases to 
> verify it.
> 
> But the demand doesn't validate the effort.
And how much effort has been put into ripping this out completely 
together with the other fixes?  How much more would it have been to just 
move it to another option and fix the reserved area usage?
> 
> All my points are clear for this patchset:
> I know I removed one function, and my reason is:
> 1) No or little usage
>     And it's anti intuition.
So split it to a separate tool (mkimage maybe?), and fix mkfs to behave 
sensibly.  I absolutely agree on the fact that it's non-intuitive.  It 
should either be it's own option (with a dependency on -r being passed 
of course), or a separate tool if you're so worried about mkfs being too 
complex.

As to usage, given the current data, there is no proof that I'm the only 
one using it, but there is also no proof that anybody other than me is 
using it, which means that you can't reasonably base an argument on 
actual usage of this option, since you can't prove anything about usage. 
  All you know is that you have one person who uses it, and one who was 
confused by it (but appears to want to use it in a different way).  It's 
a niche use case though, and when dealing with something like this, 
there is a threshold of usage below which you won't see much in the way 
of discussion of the option on the list, since only a reasonably small 
percentage of BTRFS users are actually subscribed.

> 2) Dead code (not tested nor well documented)
<rant>It _IS NOT_ dead code.  It is absolutely reachable from code 
external to itself.  It's potentially unused code, but that is not the 
same thing as dead code.</rant>

That aside, I can fix up the documentation, and I've actually tested it 
reasonably thoroughly (I use it every month or so when I update stuff I 
have using seed devices, and it also gets used by my testing 
infrastructure when generating images pre-loaded with files for tests to 
save time).  I'll agree it hasn't been rigorously tested, but it does 
appear to work as (not) advertised, even when used in odd ways.

> 3) Possible workaround
There are three options for workarounds, and both of them are sub-par to 
this even aside from the reduced simplicity it offers to userspace:
1. Resize after mkfs.  This is impractical both because there is no 
offline resize (having to mount the FS RW prior to use as a seed device 
means that you don't have a guaranteed reproducible image, which is a 
pretty common request for container usage there days), and it will end 
up with wasted space (the smallest possible filesystem created through a 
resize is consistently larger (by more than 1MB) than what the -r option 
to mkfs generates).
2. Use a binary search to determine the smallest size to a reasonable 
margin.  This is impractical simply because it takes too long, and again 
can't reliably get the smallest possible image.
3. Attempt to compute the smallest possible image without using a binary 
search, pre-create the file, and then call mkfs.  This is non-trivial 
without knowledge of the internal workings of mkfs, and is liable to 
break when something changes in mkfs (unless you want to consider the 
block-level layout generated by the --rootdir option to be part of the 
ABI and something that shouldn't change, but that is something you would 
need to discuss with the other developers).

IOW, this is like saying that duct tape is a workaround for not having 
super glue.  It will technically work, but not anywhere near as well.
> 
> I can add several extra reasons as I stated before, but number of 
> reasons won't validate anything anyway.
> 
> Building software is always trading one thing for another.
> I understand there may be some need for this function, but it doesn't 
> validate the cost.
> 
> And I think the fact that until recently a mail reported about the 
> shrinking behavior has already backed up my point.
The only information it gives is that until now nobody who tried that 
option either cared enough to complain about it, or needed it to behave 
any other way.

IOW, as stated above, given the current data, there is no proof that I'm 
the only one using it, but there is also no proof that anybody other 
than me is using it, which means that you can't reasonably base your 
argument on actual usage of this option.
> 
> Thanks,
> Qu
> 
>>
>> Case 1 is obviously unrelated to creating a filesystem.  Case 2 
>> however is kind of integral to the creation of the filesystem image 
>> itself by definition, especially for a CoW filesystem because it's not 
>> possible to shrink to the absolute smallest size due to the 
>> GlobalReserve and other things.
>>
>> Similarly, there are two primary use cases for pre-loading the 
>> filesystem with data:
>> 1. Avoiding a copy when reprovisioning storage on a system.  For 
>> example, splitting a directory out to a new filesystem, you could use 
>> the -r option to avoid having to copy the data after mounting the 
>> filesystem.
>> 2. Creating base images for systems.
>>
>> The first case shouldn't need the shrinking functionality, but the 
>> second is a very common use case together with the second usage for 
>> shrinking a filesystem.
>>>
>>>>>
>>>>> It may be offline shrink/balance. But not to further complexing the 
>>>>> --rootdir option now. >
>>>>> And you also said that, the shrink feature is not a popular feature 
>>>>> *NOW*, then I don't think it's worthy to implment it *NOW* either.
>>>>> Implement future feature in the future please.
>>>> I'm not sure about you, but I could have sworn that he meant seed 
>>>> devices weren't a popular feature right now,
>>>
>>> Oh, sorry for my misunderstanding.
>>>
>>>> not that the shrinking is. As a general rule, the whole option of 
>>>> pre-loading a filesystem with data as you're creating it is not a 
>>>> popular feature, because most sysadmins are much more willing to 
>>>> trust adding data after the filesystem is created.
>>>>
>>>> Personally, given the existence of seed devices, I would absolutely 
>>>> expect there to be a quick and easy way to generate a minimalistic 
>>>> image using a single command (because realistic usage of seed 
>>>> devices implies minimalistic images).  I agree that it shouldn't be 
>>>> the default behavior, but I don't think it needs to be removed 
>>>> completely.
>>>
>>> Just like I said in cover letter, even for ext*, it's provided by 
>>> genext2fs, not mke2fs.
>> Then maybe this should get split out into a separate tool instead of 
>> just removing it completely?  There is obviously at least some 
>> interest in this functionality.
>>>
>>> I totally understand end-user really want a do-it-all solution.
>>> But from developers' view, the old UNIX way is better to maintain 
>>> code clean and easy to read.
>> What the code is doing should have near zero impact on readability.  
>> If it did, then the BTRFS code in general is already way beyond most 
>> people.
>>>
>>>
>>> In fact, you can even create your script to do the old behavior if 
>>> you don't care that the result may not fully take use of the space, 
>>> just by:
>>>
>>> 1) Calculate the size of the whole directory
>>>     "du" command can do it easily, and it does things better than us! 
>>> For
>>>     years!
>> Um, no it actually doesn't do things better in all cases.  it doesn't 
>> account for extended attributes, or metadata usage, or any number of 
>> other things that factor into how much space a file or directory will 
>> take up on BTRFS.  It's good enough for finding what's using most of 
>> your space, but it's not reliable for determining how much space you 
>> need to store that data (especially once you throw in in-line 
>> compression).
>>>
>>> 2) Multiple the value according to the meta/data profile
>>>     Take care of small files, which will be inlined.
>>>     And don't forget size for data checksum.
>>>     (BTW, there is no way to change the behavor of inlined data and data
>>>      checksum for mkfs. unlike btrfs-convert)
>> This is where the issue lies.  It's not possible for a person to 
>> calculate this with reasonable accuracy, and you arguably can't even 
>> do it for certain programmatically without some serious work.
>>>
>>> 3) Create a file with size calculated by step 2)
>>>
>>> 4) Execute "mkfs.btrfs -d <dir> <created file>"
>>>
>>>>   The main issues here are that it wasn't documented well (like many 
>>>> other things in BTRFS), and it didn't generate a filesystem that was 
>>>> properly compliant with the on-disk format (because it used space in 
>>>> the 1MB reserved area at the beginning of the FS).  Fixing those 
>>>> issues in no way requires removing the feature.
>>>
>>> Yes, 1MB can be fixed easily (although not properly). But the whole 
>>> customized chunk allocator is the real problem.
>>> The almost dead code is always bug-prone. Replace it with updated 
>>> generic chunk allocator is the way to avoid later whac-a-mole, and 
>>> should be done asap.
>> Agreed, but that doesn't preclude having the option to keep the 
>> generated image to the minimum size.
>>>
>>>>>
>>>>> And further more, even following the existing shrink behavior, you 
>>>>> still need to truncate the file all by yourself.
>>>>> Which is no better than creating a good sized file and then mkfs on 
>>>>> it.
>>>> Only if you pre-create the file.  If the file doesn't exist, it gets 
>>>> created at the appropriate size.  That's part of why the chunk 
>>>> allocations are screwed up and stuff gets put in the first 1MB, it 
>>>> generates the FS on-the-fly and writes it out as it's generating it.
>>>
>>> Nope, even you created the file in advance, it will still occupy the 
>>> first 1M.
>> Because it doesn't assume that the file is there to begin with.  It's 
>> not trying O_CREAT and falling back to some different code if that 
>> fails.  The code assumes that the file won't be there, and handles 
>> things accordingly albeit incorrectly (it should seek past the first 
>> 1MB, write the initial SB, and then start chunk allocation).  IOW, the 
>> code takes a shortcut in that it doesn't check for the file, and the 
>> rest is written to account for that by assuming there wasn't a file. 
>> The lack of truncation just means it doesn't try to trim things down 
>> by itself if the file is already there (it assumes that you knew what 
>> you were doing).
>>
>> Put differently, I'm fairly certain that the current -r option removes 
>> the total size check unless the target is a device (although it may 
>> remove the check there too and just fail when it tries to write past 
>> the end of the device), and will thus extend existing files to the 
>> required size to hold the data.
>>>
>>> BTW, you can get back the size calculation for shrink, but you will 
>>> soon find that it's just the start of a new nightmare.
>>> Because there is no easy way to calculate the real metadata usage.
>>>
>>> The result (and the old calculator) will be no better than guessing it.
>>> (Well, just multiply the dir size by 2 will never go wrong)
>> No, it can go wrong depending on what you count as part of the size.
>>>
>>>
>>> Thanks,
>>> Qu
>>>
>>>>>
>>>>> Thanks,
>>>>> Qu
>>>>>
>>>>> Sent: Friday, September 22, 2017 at 5:24 PM
>>>>> From: "Anand Jain" <anand.jain@oracle.com>
>>>>> To: "Qu Wenruo" <quwenruo.btrfs@gmx.com>, linux-btrfs@vger.kernel.org
>>>>> Cc: dsterba@suse.cz
>>>>> Subject: Re: [PATCH v3 07/14] btrfs-progs: Doc/mkfs: Add extra 
>>>>> condition for rootdir option
>>>>>
>>>>>> +WARNING: Before v4.14 btrfs-progs, *--rootdir* will shrink the 
>>>>>> filesystem,
>>>>>> +prevent user to make use of the remaining space.
>>>>>> +In v4.14 btrfs-progs, this behavior is changed, and will not 
>>>>>> shrink the fs.
>>>>>> +The result should be the same as `mkfs`, `mount` and then `cp -r`. +
>>>>>
>>>>> Hmm well. Shrink to fit exactly to the size of the given
>>>>> files-and-directory is indeed a nice feature. Which would help to 
>>>>> create
>>>>> a golden-image btrfs seed device. Its not popular as of now, but at 
>>>>> some
>>>>> point it may in the cloud environment.
>>>>>
>>>>> Replacing this feature instead of creating a new option is not a good
>>>>> idea indeed. I missed something ?
>>>>>
>>>>> Thanks, Anand
>>>>>
>>>>>> +Also, if destination file/block device does not exist, 
>>>>>> *--rootdir* will not
>>>>>> +create the image file, to make it follow the normal mkfs behavior.
>>>>
>>>> -- 
>>>> To unsubscribe from this list: send the line "unsubscribe 
>>>> linux-btrfs" in
>>>> the body of a message to majordomo@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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Sterba Sept. 27, 2017, 4:20 p.m. UTC | #11
On Mon, Sep 25, 2017 at 07:15:30AM -0400, Austin S. Hemmelgarn wrote:
> On 2017-09-24 10:08, Goffredo Baroncelli wrote:
> > On 09/24/2017 12:10 PM, Anand Jain wrote:

A lot of points in this thread, let me address them here.

I don't want to remove --rootdir functionality, the fix that's being
proposed removes the minimalization -- feature that was not well known,
but I understand it's useful (and already used).

I'd like to fix that in another way, eg. as an option to mkfs or a
separate tool.

I'm not worried about adding more code or code complexity. If we do it
right it's not a problem in the long run. But people for some reason
like to delete other people's code or functionality.

Regarding guessing number of users, this is always hard. So if there's
one vocal enough to let us know about the usecase, it's IMHO good time
to explore the it, code-wise and documentation-wise, and fix it or
improve.

So, what next. I'd like to get rid of the custom chunk allocator, namely
because of the known 1MB area misuse and duplication.

Implementing the minimalization might need some preparatory work and I
don't have a realistic ETA now. Ideally we'd fix both problems in one
version, as I'd rather avoid "temporary" solution to drop the
minimalization with the promise to put it back later.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Qu Wenruo Sept. 28, 2017, midnight UTC | #12
On 2017年09月28日 00:20, David Sterba wrote:
> On Mon, Sep 25, 2017 at 07:15:30AM -0400, Austin S. Hemmelgarn wrote:
>> On 2017-09-24 10:08, Goffredo Baroncelli wrote:
>>> On 09/24/2017 12:10 PM, Anand Jain wrote:
> 
> A lot of points in this thread, let me address them here.
> 
> I don't want to remove --rootdir functionality, the fix that's being
> proposed removes the minimalization -- feature that was not well known,
> but I understand it's useful (and already used).
> 
> I'd like to fix that in another way, eg. as an option to mkfs or a
> separate tool.
> 
> I'm not worried about adding more code or code complexity. If we do it
> right it's not a problem in the long run. But people for some reason
> like to delete other people's code or functionality.
> 
> Regarding guessing number of users, this is always hard. So if there's
> one vocal enough to let us know about the usecase, it's IMHO good time
> to explore the it, code-wise and documentation-wise, and fix it or
> improve.
> 
> So, what next. I'd like to get rid of the custom chunk allocator, namely
> because of the known 1MB area misuse and duplication.
> 
> Implementing the minimalization might need some preparatory work and I
> don't have a realistic ETA now.

Well, if using over-reserve-then-shrink method, it could be done, 
without much hassle.

However ETA maybe delayed to middle of Oct, as I'm going to enjoy my 
holiday during 1st Oct to 7th Oct.

Thanks,
Qu

> Ideally we'd fix both problems in one
> version, as I'd rather avoid "temporary" solution to drop the
> minimalization with the promise to put it back later.
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Austin S. Hemmelgarn Sept. 29, 2017, 11:30 a.m. UTC | #13
On 2017-09-27 20:00, Qu Wenruo wrote:
> 
> 
> On 2017年09月28日 00:20, David Sterba wrote:
>> On Mon, Sep 25, 2017 at 07:15:30AM -0400, Austin S. Hemmelgarn wrote:
>>> On 2017-09-24 10:08, Goffredo Baroncelli wrote:
>>>> On 09/24/2017 12:10 PM, Anand Jain wrote:
>>
>> A lot of points in this thread, let me address them here.
>>
>> I don't want to remove --rootdir functionality, the fix that's being
>> proposed removes the minimalization -- feature that was not well known,
>> but I understand it's useful (and already used).
>>
>> I'd like to fix that in another way, eg. as an option to mkfs or a
>> separate tool.
>>
>> I'm not worried about adding more code or code complexity. If we do it
>> right it's not a problem in the long run. But people for some reason
>> like to delete other people's code or functionality.
>>
>> Regarding guessing number of users, this is always hard. So if there's
>> one vocal enough to let us know about the usecase, it's IMHO good time
>> to explore the it, code-wise and documentation-wise, and fix it or
>> improve.
>>
>> So, what next. I'd like to get rid of the custom chunk allocator, namely
>> because of the known 1MB area misuse and duplication.
>>
>> Implementing the minimalization might need some preparatory work and I
>> don't have a realistic ETA now.
> 
> Well, if using over-reserve-then-shrink method, it could be done, 
> without much hassle.
It _should_ be possible to compute the exact size required though.  As 
outlined in one of my other replies, an absolute minimal filesystem 
should in theory consist of the following space usage:
1. 1MB (for the reserved space at the beginning).
2. However many superblocks it should have given the size.
3. The total amount of file data and extended attribute data to be 
included, rounding up for block size
4. The exact amount of metadata space needed to represent the tree from 
3, also rounding up for block size.
5. The exact amount of system chunk space needed to handle 3 and 4, plus 
enough room to allocate at least one more chunk of each type (to 
ultimately allow for resizing the filesystem if desired).
6. Exactly enough reserved metadata space to resize the FS 
(alternatively, the standard space for the GlobalReserve, which should 
be enough and then some).

Computing this is non-trivial for a human, and even with a computer 
requires knowledge of how the chunk allocator is implemented.  mkfs 
should have that knowledge though, so in theory it is reasonably well 
positioned to just compute this, allocate that much space, and then 
generate the filesystem.  The complaints I have about trying to do this 
manually in two passes are that:
1. Computing the above by hand is not easy.
2. Computing it by hand and then running mkfs on the resultant file 
doesn't work most of the time.

As a result, I would think this could easily be handled in the following 
steps:
1. Scan the contents of the --rootdir option to determine total size needed.
2. Compute the required allocation and allocate it.
3. Generate the filesystem image.

This has an inherent TOCTOU race, but it's one that a lot of archiving 
tools (tar being a prime example) already have, and it's not likely that 
people will hit it since you're not likely to be using a changing 
directory for --rootdir.
> 
> However ETA maybe delayed to middle of Oct, as I'm going to enjoy my 
> holiday during 1st Oct to 7th Oct.
Entirely understandable, enjoy your time off!

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Goffredo Baroncelli Sept. 29, 2017, 4:57 p.m. UTC | #14
On 09/28/2017 02:00 AM, Qu Wenruo wrote:
> 
> 
> On 2017年09月28日 00:20, David Sterba wrote:
>> On Mon, Sep 25, 2017 at 07:15:30AM -0400, Austin S. Hemmelgarn wrote:
>>> On 2017-09-24 10:08, Goffredo Baroncelli wrote:
>>>> On 09/24/2017 12:10 PM, Anand Jain wrote:
>>
>> A lot of points in this thread, let me address them here.
>>
>> I don't want to remove --rootdir functionality, the fix that's being
>> proposed removes the minimalization -- feature that was not well known,
>> but I understand it's useful (and already used).
>>
>> I'd like to fix that in another way, eg. as an option to mkfs or a
>> separate tool.
>>
>> I'm not worried about adding more code or code complexity. If we do it
>> right it's not a problem in the long run. But people for some reason
>> like to delete other people's code or functionality.
>>
>> Regarding guessing number of users, this is always hard. So if there's
>> one vocal enough to let us know about the usecase, it's IMHO good time
>> to explore the it, code-wise and documentation-wise, and fix it or
>> improve.
>>
>> So, what next. I'd like to get rid of the custom chunk allocator, namely
>> because of the known 1MB area misuse and duplication.
>>
>> Implementing the minimalization might need some preparatory work and I
>> don't have a realistic ETA now.
> 
> Well, if using over-reserve-then-shrink method, it could be done, without much hassle.

What about doing it on a file instead of a device ? As sparse file, it would be less expensive to enlarge then shrink. I think that who need to build a filesystem with "shrink", doesn't need to create it on a real block device
> 
> However ETA maybe delayed to middle of Oct, as I'm going to enjoy my holiday during 1st Oct to 7th Oct.
> 
> Thanks,
> Qu
> 
>> Ideally we'd fix both problems in one
>> version, as I'd rather avoid "temporary" solution to drop the
>> minimalization with the promise to put it back later.
>>
> -- 
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
Qu Wenruo Sept. 30, 2017, 3:33 a.m. UTC | #15
On 2017年09月30日 00:57, Goffredo Baroncelli wrote:
> On 09/28/2017 02:00 AM, Qu Wenruo wrote:
>>
>>
>> On 2017年09月28日 00:20, David Sterba wrote:
>>> On Mon, Sep 25, 2017 at 07:15:30AM -0400, Austin S. Hemmelgarn wrote:
>>>> On 2017-09-24 10:08, Goffredo Baroncelli wrote:
>>>>> On 09/24/2017 12:10 PM, Anand Jain wrote:
>>>
>>> A lot of points in this thread, let me address them here.
>>>
>>> I don't want to remove --rootdir functionality, the fix that's being
>>> proposed removes the minimalization -- feature that was not well known,
>>> but I understand it's useful (and already used).
>>>
>>> I'd like to fix that in another way, eg. as an option to mkfs or a
>>> separate tool.
>>>
>>> I'm not worried about adding more code or code complexity. If we do it
>>> right it's not a problem in the long run. But people for some reason
>>> like to delete other people's code or functionality.
>>>
>>> Regarding guessing number of users, this is always hard. So if there's
>>> one vocal enough to let us know about the usecase, it's IMHO good time
>>> to explore the it, code-wise and documentation-wise, and fix it or
>>> improve.
>>>
>>> So, what next. I'd like to get rid of the custom chunk allocator, namely
>>> because of the known 1MB area misuse and duplication.
>>>
>>> Implementing the minimalization might need some preparatory work and I
>>> don't have a realistic ETA now.
>>
>> Well, if using over-reserve-then-shrink method, it could be done, without much hassle.
> 
> What about doing it on a file instead of a device ? As sparse file, it would be less expensive to enlarge then shrink. I think that who need to build a filesystem with "shrink", doesn't need to create it on a real block device

For device, nothing different, just v3 patchset will handle it.

For file, sparse file of course.

Thanks,
Qu

>>
>> However ETA maybe delayed to middle of Oct, as I'm going to enjoy my holiday during 1st Oct to 7th Oct.
>>
>> Thanks,
>> Qu
>>
>>> Ideally we'd fix both problems in one
>>> version, as I'd rather avoid "temporary" solution to drop the
>>> minimalization with the promise to put it back later.
>>>
>> -- 
>> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
>> the body of a message to majordomo@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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Austin S. Hemmelgarn Oct. 2, 2017, 11:47 a.m. UTC | #16
On 2017-09-29 23:33, Qu Wenruo wrote:
> 
> 
> On 2017年09月30日 00:57, Goffredo Baroncelli wrote:
>> On 09/28/2017 02:00 AM, Qu Wenruo wrote:
>>>
>>>
>>> On 2017年09月28日 00:20, David Sterba wrote:
>>>> On Mon, Sep 25, 2017 at 07:15:30AM -0400, Austin S. Hemmelgarn wrote:
>>>>> On 2017-09-24 10:08, Goffredo Baroncelli wrote:
>>>>>> On 09/24/2017 12:10 PM, Anand Jain wrote:
>>>>
>>>> A lot of points in this thread, let me address them here.
>>>>
>>>> I don't want to remove --rootdir functionality, the fix that's being
>>>> proposed removes the minimalization -- feature that was not well known,
>>>> but I understand it's useful (and already used).
>>>>
>>>> I'd like to fix that in another way, eg. as an option to mkfs or a
>>>> separate tool.
>>>>
>>>> I'm not worried about adding more code or code complexity. If we do it
>>>> right it's not a problem in the long run. But people for some reason
>>>> like to delete other people's code or functionality.
>>>>
>>>> Regarding guessing number of users, this is always hard. So if there's
>>>> one vocal enough to let us know about the usecase, it's IMHO good time
>>>> to explore the it, code-wise and documentation-wise, and fix it or
>>>> improve.
>>>>
>>>> So, what next. I'd like to get rid of the custom chunk allocator, 
>>>> namely
>>>> because of the known 1MB area misuse and duplication.
>>>>
>>>> Implementing the minimalization might need some preparatory work and I
>>>> don't have a realistic ETA now.
>>>
>>> Well, if using over-reserve-then-shrink method, it could be done, 
>>> without much hassle.
>>
>> What about doing it on a file instead of a device ? As sparse file, it 
>> would be less expensive to enlarge then shrink. I think that who need 
>> to build a filesystem with "shrink", doesn't need to create it on a 
>> real block device
> 
> For device, nothing different, just v3 patchset will handle it.
Agreed on this point.
> 
> For file, sparse file of course.
But not on this one.  Unless the image gets properly compacted, a sparse 
file will only help when you're just storing the image on a filesystem. 
It doesn't really help at all for when you need to put it on a physical 
device afterwards (except possibly if you're using thin provisioning). 
The reason I (at least) am complaining about losing this feature isn't 
about having space efficiency when storing image files on a filesystem, 
it's about time efficiency in transferring the image either to a device 
after generation (if you're going to multiple devices, it makes more 
sense to just generate an image file instead of writing directly to the 
first device in most cases), or to another system where it will 
ultimately be written to a device.

As a more specific example, look at how installation of Linux 
(preferably Raspbian) is typically done on a Raspberry Pi.  You have a 
base SD-card image that is designed to fit on a 1G SD card, and the root 
filesystem then gets resized automatically on first boot to fill the 
card.  You still need to copy that whole 1G of data to a _slow_ SD card 
before you can do anything with it, because you can't assume the card is 
empty and do sparse writes (and very few tools used for writing out disk 
images can do sparse writes).  You also have to copy all that data to 
download the image, and while they're distributed compressed, 
compressing runs of empty space still takes space.  If that instead used 
image generation similar to the current behavior of the --rootdir 
option, a reasonable amount of time would be saved in most steps, simply 
because the image was smaller (the 1G image has 300MB or more of empty 
space in it).

As another example, when dealing with seed devices, it makes just as 
much if not more sense if you're using LVM to store the data to create 
an LV that is exactly as large as needed for the seed device, and no 
bigger.  Using sparse files similarly doesn't work for that unless 
you're using thin provisioning and don't mind LVM complaining all the 
time about over-provisioning your space.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Goffredo Baroncelli Oct. 2, 2017, 6:47 p.m. UTC | #17
On 10/02/2017 01:47 PM, Austin S. Hemmelgarn wrote:
>>>
>>> What about doing it on a file instead of a device ? As sparse file, it would be less expensive to enlarge then shrink. I think that who need to build a filesystem with "shrink", doesn't need to create it on a real block device
>>
>> For device, nothing different, just v3 patchset will handle it.
> Agreed on this point.
>>
>> For file, sparse file of course.
> But not on this one.  Unless the image gets properly compacted, a sparse file will only help when you're just storing the image on a filesystem.

I think that you have misunderstood my proposal... My suggestion is to create the image using a file, and after image creation compact it, and then cut it at the end. So you don't have to care about the space needing during the process (before the shrinking).

Today mkfs.btrfs fails to create an image on an empty file

ghigo@venice:/tmp$ mkdir test
ghigo@venice:/tmp$ mkdir test/test1
ghigo@venice:/tmp$ touch test/test1/file
ghigo@venice:/tmp$ mkfs.btrfs --root test disk.img
btrfs-progs v4.12
See http://btrfs.wiki.kernel.org for more information.

ERROR: failed to check size for disk.img: No such file or directory
ghigo@venice:/tmp$ touch disk.img
ghigo@venice:/tmp$ mkfs.btrfs --root test disk.img
btrfs-progs v4.12
See http://btrfs.wiki.kernel.org for more information.

ERROR: 'disk.img' is too small to make a usable filesystem
ERROR: minimum size for each btrfs device is 41943040

you have to create a big enough

ghigo@venice:/tmp$ truncate -s 10G disk.img 
ghigo@venice:/tmp$ mkfs.btrfs --root test disk.img
btrfs-progs v4.12
See http://btrfs.wiki.kernel.org for more information.
[...]


BR

Patch
diff mbox

diff --git a/Documentation/mkfs.btrfs.asciidoc b/Documentation/mkfs.btrfs.asciidoc
index d53d9e26..645a2881 100644
--- a/Documentation/mkfs.btrfs.asciidoc
+++ b/Documentation/mkfs.btrfs.asciidoc
@@ -106,6 +106,19 @@  Please see the mount option 'discard' for that in `btrfs`(5).
 *-r|--rootdir <rootdir>*::
 Populate the toplevel subvolume with files from 'rootdir'.  This does not
 require root permissions and does not mount the filesystem.
++
+With this option, only one device can be specified.
++
+NOTE: User should make sure the block device/file has large enough space to
+contain the source directory and has enough previllege to read source directory.
+Or mkfs will just fail.
++
+WARNING: Before v4.14 btrfs-progs, *--rootdir* will shrink the filesystem,
+prevent user to make use of the remaining space.
+In v4.14 btrfs-progs, this behavior is changed, and will not shrink the fs.
+The result should be the same as `mkfs`, `mount` and then `cp -r`. +
+Also, if destination file/block device does not exist, *--rootdir* will not
+create the image file, to make it follow the normal mkfs behavior.
 
 *-O|--features <feature1>[,<feature2>...]*::
 A list of filesystem features turned on at mkfs time. Not all features are