linux-nova icon indicating copy to clipboard operation
linux-nova copied to clipboard

Inconsistent attributes of symlink before and after umount

Open iaoing opened this issue 1 year ago • 0 comments

Issue

The attributes, size and blocks, of a symlink are inconsistent before and after umount. After the symlink, they are a number. After a successful umount and remount, they become another number.

Reproduce

insmod fs_raw.ko metadata_csum=1 data_csum=1 data_parity=1 dram_struct_csum=1
mount -t NOVA -o init,data_cow,dbgmask=255 /dev/pmem0 /mnt/pmem0
touch /mnt/pmem0/foo
# create the link
ln -s /mnt/pmem0/foo /mnt/pmem0/bar
stat /mnt/pmem0/bar
# the output:
#  File: /mnt/pmem0/bar -> /mnt/pmem0/foo
#  Size: 14        	Blocks: 0          IO Block: 4096   symbolic link
umount /mnt/pmem0
mount -t NOVA -o data_cow,dbgmask=255 /dev/pmem0 /mnt/pmem0
# after the remount, stat it again
stat /mnt/pmem0/bar
# the output:
#  File: /mnt/pmem0/bar -> /mnt/pmem0/foo
#  Size: 15        	Blocks: 1          IO Block: 4096   symbolic link

Reason:

When allocating a new inode for a symlink, thei_size set to inode is len = strlen(symname), and the i_block is set as 0, as below code snippets show: https://github.com/NVSL/linux-nova/blob/976a4d1f3d5282863b23aa834e02012167be6ee2/fs/nova/namei.c#L268-L270 https://github.com/NVSL/linux-nova/blob/976a4d1f3d5282863b23aa834e02012167be6ee2/fs/nova/inode.c#L1082-L1087

When appending a file write entry to the symlink pi, a new data block is allocated and the written size is set as len + 1. https://github.com/NVSL/linux-nova/blob/976a4d1f3d5282863b23aa834e02012167be6ee2/fs/nova/symlink.c#L63-L64

Consequently, before a umount, the i_size and i_blocks are strlen(/mnt/pmem0/foo) and 0. After a remount, the i_size and i_blocks becomestrlen(/mnt/pmem0/foo) + 1 and 1.

Fix:

Set the correct i_size and i_blocks, 'len+1' and '1', when creating a symlink.

iaoing avatar Jan 10 '24 00:01 iaoing