[Devel] [PATCH RH9 4/4] xfs: Provide a balloon nipple for management

Kirill Tkhai ktkhai at virtuozzo.com
Fri Oct 22 19:40:45 MSK 2021


A new ioctl() to open balloon file.

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