The commit is pushed to "branch-rh9-5.14.0-427.44.1.vz9.104.x-ovz" and will 
appear at g...@bitbucket.org:openvz/vzkernel.git
after rh9-5.14.0-427.44.1.vz9.104.1
------>
commit 09322ead7f935797e05c1762216f33605fa296d1
Author: Kirill Tkhai <ktk...@virtuozzo.com>
Date:   Mon Oct 25 15:49:51 2021 +0300

    xfs: Provide a balloon nipple for management
    
    A new ioctl() to open balloon file.
    
    Q: Why do we introduce ioctl, but not use generic open() and put there some
       extra checks for balloon file name?
    
    A: Let's imagine we've implemented that, have put ve_is_super() check in 
open()
       and, etc. But if host opens balloon file once, its dentry will stay in 
cache
       for a long time and we'll have to insert more checks in 
stat()/link()/etc -
       all syscalls which work via dentries => using ioctl looks less error 
prone.
    
    https://jira.sw.ru/browse/PSBM-133811
    
    Signed-off-by: Kirill Tkhai <ktk...@virtuozzo.com>
    
    +++
    xfs: Check alloc_file() results in xfs_open_balloon()
    
    Check for pointer validity before its dereference.
    
    Reported-by: Alexander Mikhalitsyn <alexander.mikhalit...@virtuozzo.com>
    Signed-off-by: Kirill Tkhai <ktk...@virtuozzo.com>
    
    Feature: fs/xfs: fast online shrink support
---
 fs/xfs/libxfs/xfs_fs.h |  1 +
 fs/xfs/xfs_ioctl.c     | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+)

diff --git a/fs/xfs/libxfs/xfs_fs.h b/fs/xfs/libxfs/xfs_fs.h
index 1cfd5bc6520a..2446d3c00665 100644
--- a/fs/xfs/libxfs/xfs_fs.h
+++ b/fs/xfs/libxfs/xfs_fs.h
@@ -833,6 +833,7 @@ struct xfs_scrub_metadata {
 #define XFS_IOC_INUMBERS            _IOR ('X', 128, struct xfs_inumbers_req)
 /*     XFS_IOC_GETFSUUID ---------- deprecated 140      */
 
+#define XFS_IOC_OPEN_BALLOON           _IO('X', 255)
 
 #ifndef HAVE_BBMACROS
 /*
diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
index 736510bc241b..c2899be29874 100644
--- a/fs/xfs/xfs_ioctl.c
+++ b/fs/xfs/xfs_ioctl.c
@@ -1861,6 +1861,63 @@ xfs_fs_eofblocks_from_user(
        return 0;
 }
 
+static int xfs_open_balloon(struct xfs_mount *mp, struct vfsmount *mnt)
+{
+       u64 balloon_ino = READ_ONCE(mp->m_balloon_ino);
+       struct xfs_inode *ip;
+       struct inode *inode;
+       int err, fd, ro;
+       struct file *filp;
+       struct dentry *de;
+       struct path path;
+       fmode_t mode;
+
+       if (!balloon_ino)
+               return -ENOENT;
+       ip = xfs_balloon_get(mp, balloon_ino, 0);
+       if (IS_ERR(ip))
+               return PTR_ERR(ip);
+       inode = VFS_I(ip);
+
+       err = fd = get_unused_fd_flags(0);
+       if (err < 0)
+               goto err_put_ip;
+
+       __iget(inode);
+       de = d_obtain_alias(inode);
+       err = PTR_ERR(de);
+       if (IS_ERR(de))
+               goto err_put_fd;
+
+       path.dentry = de;
+       path.mnt = mntget(mnt);
+       ro = mnt_want_write(path.mnt);
+       if (ro)
+               mode = O_RDONLY;
+       else
+               mode = O_RDWR;
+       filp = alloc_file(&path, mode, &xfs_file_operations);
+       if (!ro)
+               mnt_drop_write(path.mnt);
+       if (IS_ERR(filp)) {
+               err = PTR_ERR(filp);
+               goto err_put_path;
+       }
+
+       filp->f_flags |= O_LARGEFILE;
+       fd_install(fd, filp);
+       xfs_irele(ip);
+       return fd;
+
+err_put_path:
+       path_put(&path);
+err_put_fd:
+       put_unused_fd(fd);
+err_put_ip:
+       xfs_irele(ip);
+       return err;
+}
+
 /*
  * These long-unused ioctls were removed from the official ioctl API in 5.17,
  * but retain these definitions so that we can log warnings about them.
@@ -2149,6 +2206,12 @@ xfs_file_ioctl(
                return error;
        }
 
+        case XFS_IOC_OPEN_BALLOON:
+                if (!capable(CAP_SYS_ADMIN))
+                        return -EACCES;
+
+                return xfs_open_balloon(mp, filp->f_path.mnt);
+
        default:
                return -ENOTTY;
        }
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to