[Devel] [PATCH RHEL9 COMMIT] xfs: Provide a balloon nipple for management
Konstantin Khorenko
khorenko at virtuozzo.com
Mon Oct 25 15:49:51 MSK 2021
The commit is pushed to "branch-rh9-5.14.vz9.1.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-4.vz9.10.16
------>
commit 771859c09e8337d904945526d69e611b57593725
Author: Kirill Tkhai <ktkhai at 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 <ktkhai at virtuozzo.com>
---
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 bde2b4c64dbe..2293e1b757b3 100644
--- a/fs/xfs/libxfs/xfs_fs.h
+++ b/fs/xfs/libxfs/xfs_fs.h
@@ -839,6 +839,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 16039ea10ac9..1282d9412f92 100644
--- a/fs/xfs/xfs_ioctl.c
+++ b/fs/xfs/xfs_ioctl.c
@@ -1935,6 +1935,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;
+ 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);
+ err = mnt_want_write(path.mnt);
+ if (err)
+ mode = O_RDONLY;
+ else
+ mode = O_RDWR;
+ filp = alloc_file(&path, mode, &xfs_file_operations);
+ if (filp->f_mode & FMODE_WRITE)
+ 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;
+}
+
/*
* Note: some of the ioctl's return positive numbers as a
* byte count indicating success, such as readlink_by_handle.
@@ -2216,6 +2273,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;
}
More information about the Devel
mailing list