On 2018/8/14 上午1:37, David Sterba wrote:
> On Mon, Aug 06, 2018 at 02:17:54PM +0800, Qu Wenruo wrote:
>>> - u64 objectid;
>>
>> Off topic crazy idea here.
>>
>> I think it is a little crazy, but it should save a lot of objectid
>> related modification:
>>
>> diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
>> index 118346aceea9..e6d70f2309a3 100644
>> --- a/fs/btrfs/ctree.h
>> +++ b/fs/btrfs/ctree.h
>> @@ -1166,7 +1166,10 @@ struct btrfs_root {
>>
>> unsigned long state;
>> struct btrfs_root_item root_item;
>> - struct btrfs_key root_key;
>> + union {
>> + struct btrfs_key root_key;
>> + u64 objectid;
>> + };
>> struct btrfs_fs_info *fs_info;
>> struct extent_io_tree dirty_log_pages;
>>
>> @@ -1198,7 +1201,6 @@ struct btrfs_root {
>> int last_log_commit;
>> pid_t log_start_pid;
>>
>> - u64 objectid;
>> u64 last_trans;
>>
>> u32 type;
>>
>> I'm not sure if this is a really crazy idea or a dirty hack to reduce
>> some modification.
>
> Be wary of such tricks. This might make you feel good for a moment how
> good your C knowlege is, and also might save a few keystrokes. And a few
> years later this costs somebody a week of debugging a mysterious memory
> corrupption under circumstances not imagined right now.
Yep, that's why I'm calling this a "crazy idea" for the same reason.
Just wondering if there is any better way to do it without using a
trick, like anonymous structure inside btrfs_root?
(Purely to improve my C skill if possible)
Anyway, I'm completely OK with current patch.
Thanks,
Qu
>
> Try to write understandable code. If there is a reason to use tricks,
> like the struct page has to do for performance reasons, then it must be
> documented and justified.
>
Attachment:
signature.asc
Description: OpenPGP digital signature
