[Devel] [PATCH RHEL7 COMMIT] ve/fs: Port diff-ve-fs-allow-to-remove-swapfile-hardlinks

Konstantin Khorenko khorenko at virtuozzo.com
Wed Jun 24 05:32:53 PDT 2015


The commit is pushed to "branch-rh7-3.10.0-123.1.2-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-123.1.2.vz7.5.17
------>
commit 69f096fc9c4c78cfbd0dab66a52cc2238446cd67
Author: Vladimir Davydov <vdavydov at parallels.com>
Date:   Wed Jun 24 16:32:53 2015 +0400

    ve/fs: Port diff-ve-fs-allow-to-remove-swapfile-hardlinks
    
    Author: Maxim Patlasov
    Email: MPatlasov at parallels.com
    Subject: fs: allow to remove swapfile hardlinks
    Date: Tue, 11 Mar 2014 20:33:12 +0400
    
    There is nothing wrong to allow unlink(2) on a swapfile unless this is the last
    link (i_nlink == 1).
    
    The patch is useful for sharing a ploop image (which uses the same
    S_SWAPFILE flag for protection against truncate as swapfiles) among several
    containers by hardlinks. Otherwise, CT destroy would fail due to inability
    to unlink image file.
    
    >>>> Nice.
    >>>> Why it's not done in upstream?
    >>>> I mean, is there any reason against it?
    >>>
    >>> No, I think. They had solved the problem of lost swapfile by the
    >>> simplest patch: disable any unlink.
    >>>
    >>
    >> Are you going to suggest to patch to the upstream?
    >> Or it's just our local usage scenario?
    >
    > It's our own invention -- to use S_SWAPFILE for protection ploop images
    > from truncation. Ordinary loop block-device doesn't use it. Nobody else
    > (except swapfiles) uses it. So its our local usage from which nobody
    > else can get a benefit (until we didn't push ploop upstream in some form).
    
    https://jira.sw.ru/browse/PSBM-25310
    
    Signed-off-by: Maxim Patlasov <MPatlasov at parallels.com>
    
    =============================================================================
    
    Related to https://jira.sw.ru/browse/PSBM-33650
    
    Signed-off-by: Vladimir Davydov <vdavydov at parallels.com>
---
 fs/namei.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/namei.c b/fs/namei.c
index 7bea210..dc156ed 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -2458,7 +2458,8 @@ static int may_delete(struct inode *dir,struct dentry *victim,int isdir)
 	if (IS_APPEND(dir))
 		return -EPERM;
 	if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
-	    IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
+	    IS_IMMUTABLE(victim->d_inode) ||
+	    (IS_SWAPFILE(victim->d_inode) && victim->d_inode->i_nlink == 1))
 		return -EPERM;
 	if (isdir) {
 		if (!S_ISDIR(victim->d_inode->i_mode))



More information about the Devel mailing list