Re: [Question] Unlinking original file of bind mounted file.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Dec 30, 2022 at 05:08:31PM +0900, Yun Levi wrote:
> Hello fs-devel folks,
> 
> I have a few questions about below situation's handling.
> 
> ======================================================
> 1. mount --bind {somefile} {target}
> 2. rm -f {somefile}
> =======================================================
> 
> when it happens, the step (2)'s operation is working -- it removes.
> But, the inode of {somefile} is live with i_nlink = 0 with an orphan
> state of ext4_inode_info in ext4-fs.
> 
> IIUC, because ext4-inode-entry is removed in the disk via ext4_unlink,
> and it seems possible
> the inode_entry which is freed by unlink in step(2) will be used again
> when a new file is created.

No, that's not correct.  Here's how to think about Unix files (not just
ext4, going all the way back to the 1970s).  Each inode has a reference
count.  All kinds of things hold a reference count to an inode; some of
the more common ones are a name in a directory, an open file, a mmap of
that open file, passing a file descriptor through a unix socket, etc, etc.

Unlink removes a name from a directory.  That causes the reference count
to be decreased, but the inode will only be released if that causes the
reference count to drop to 0.  If the file is open, or it has multiple
names, it won't be removed.

mount --bind obviously isn't traditional Unix, but it fits in the same
paradigm.  It causes a new reference count to be taken on the inode.
So you can remove the original name that was used to create the link,
and that causes i_nlink to drop to 0, but the in-memory refcount is
still positive, so the inode will not be reused.




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux