[haiku-gsoc] Re: Some questions about Btrfs source code and suggestions.

  • From: Hy Che <cvghy116@xxxxxxxxx>
  • To: haiku-gsoc@xxxxxxxxxxxxx
  • Date: Mon, 5 Jun 2017 01:35:09 +0700

Hi,
Sorry for late respone, I was kinda lazy these days and I also need some
times to research.

On Wed, May 31, 2017 at 5:19 AM, Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
wrote:

What you see there is a read-only B+tree implementation. It has no need
for _Find() itself. However, since you are planning to make it writable at
some point, you'll probably need it. See BFS for a full blown B+tree
implementation (it's likely not binary compatible, though).

I don't know if BFS's B+tree is the same as BTRFS. B+tree in BTRFS doesn't
have links between leaves to avoid cow the whole tree, so in my opinion
tree manipulation is completely different, but I still look at BFS's source
for some points.

Locking is a complex topic that needs a lot of planning. But again, since
btrfs uses copy-on-write intensively, you might get away with surprisingly
few locks.
We basically have the usual POSIX locking mechanisms available in the
kernel. If you need more info, I'm sure we can dig out some useful article
about it :-)

If I understand correctly, those locks all have lock/unlock or up/down. I
just want to know in which situation it will be used or we have to lock
before all read/write operations and unlock it after that ?

I added a "cat" command for btrfs_shell in order to read file content. Here
it is
https://github.com/hyche/haiku/commit/1d7f3161a152c177b7137aa60aaec55e6d75c4a6
For now, It only has read-only operations and read a number of characters.
If I want to read whole file, do I have to read character one by one ?

Also, In Haiku, is there something that I can write to a cached block and
then it is written to disk ?
I need this to insert/remove a key from a node. I know file_cache, but it
is stuck for r/w file only.
for example
cached node* node = get_cached_block(..., b) // cached a number of
block_size bytes to memory of block b
write(node + key_offset, key_data) // write key_data to b + key_offset
address
write_block_to_disk(b) // some thing like this and the above

Since node size in btrfs is now greater than the block size,  so can we
cache continuos run of disk blocks ?
for example
get_cached_blocks(..., start_block, n) // cache n * block_size bytes start
at start_block

if not I think I have to create a new structure. Using cached to
insert/remove items is the only way I can think for now except writing
directly to disk, but if there is another way please tell.

Thanks,
Hy

Other related posts: