[Devel] [PATCH vz9 09/10] xfs: Provide a balloon nipple for management
Konstantin Khorenko
khorenko at virtuozzo.com
Thu Nov 28 19:51:53 MSK 2024
From: Kirill Tkhai <ktkhai at virtuozzo.com>
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>
+++
xfs: Check alloc_file() results in xfs_open_balloon()
Check for pointer validity before its dereference.
Reported-by: Alexander Mikhalitsyn <alexander.mikhalitsyn at virtuozzo.com>
Signed-off-by: Kirill Tkhai <ktkhai at 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;
}
--
2.43.5
More information about the Devel
mailing list