Skip to content

Commit 8b85dc4

Browse files
author
Darrick J. Wong
committed
xfs: check if an open file is on the health monitored fs
Create a new ioctl for the healthmon file that checks that a given fd points to the same filesystem that the healthmon file is monitoring. This allows xfs_healer to check that when it reopens a mountpoint to perform repairs, the file that it gets matches the filesystem that generated the corruption report. (Note that xfs_healer doesn't maintain an open fd to a filesystem that it's monitoring so that it doesn't pin the mount.) Signed-off-by: "Darrick J. Wong" <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de>
1 parent c0e719c commit 8b85dc4

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

fs/xfs/libxfs/xfs_fs.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,15 @@ struct xfs_health_monitor {
11511151
/* Initial return format version */
11521152
#define XFS_HEALTH_MONITOR_FMT_V0 (0)
11531153

1154+
/*
1155+
* Check that a given fd points to the same filesystem that the health monitor
1156+
* is monitoring.
1157+
*/
1158+
struct xfs_health_file_on_monitored_fs {
1159+
__s32 fd;
1160+
__u32 flags; /* zero for now */
1161+
};
1162+
11541163
/*
11551164
* ioctl commands that are used by Linux filesystems
11561165
*/
@@ -1191,7 +1200,8 @@ struct xfs_health_monitor {
11911200
#define XFS_IOC_SCRUBV_METADATA _IOWR('X', 64, struct xfs_scrub_vec_head)
11921201
#define XFS_IOC_RTGROUP_GEOMETRY _IOWR('X', 65, struct xfs_rtgroup_geometry)
11931202
#define XFS_IOC_HEALTH_MONITOR _IOW ('X', 68, struct xfs_health_monitor)
1194-
1203+
#define XFS_IOC_HEALTH_FD_ON_MONITORED_FS \
1204+
_IOW ('X', 69, struct xfs_health_file_on_monitored_fs)
11951205
/*
11961206
* ioctl commands that replace IRIX syssgi()'s
11971207
*/

fs/xfs/xfs_healthmon.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,38 @@ xfs_healthmon_reconfigure(
10901090
return 0;
10911091
}
10921092

1093+
/* Does the fd point to the same filesystem as the one we're monitoring? */
1094+
STATIC long
1095+
xfs_healthmon_file_on_monitored_fs(
1096+
struct file *file,
1097+
unsigned int cmd,
1098+
void __user *arg)
1099+
{
1100+
struct xfs_health_file_on_monitored_fs hms;
1101+
struct xfs_healthmon *hm = file->private_data;
1102+
struct inode *hms_inode;
1103+
1104+
if (copy_from_user(&hms, arg, sizeof(hms)))
1105+
return -EFAULT;
1106+
1107+
if (hms.flags)
1108+
return -EINVAL;
1109+
1110+
CLASS(fd, hms_fd)(hms.fd);
1111+
if (fd_empty(hms_fd))
1112+
return -EBADF;
1113+
1114+
hms_inode = file_inode(fd_file(hms_fd));
1115+
mutex_lock(&hm->lock);
1116+
if (hm->mount_cookie != (uintptr_t)hms_inode->i_sb) {
1117+
mutex_unlock(&hm->lock);
1118+
return -ESTALE;
1119+
}
1120+
1121+
mutex_unlock(&hm->lock);
1122+
return 0;
1123+
}
1124+
10931125
/* Handle ioctls for the health monitoring thread. */
10941126
STATIC long
10951127
xfs_healthmon_ioctl(
@@ -1102,6 +1134,8 @@ xfs_healthmon_ioctl(
11021134
switch (cmd) {
11031135
case XFS_IOC_HEALTH_MONITOR:
11041136
return xfs_healthmon_reconfigure(file, cmd, arg);
1137+
case XFS_IOC_HEALTH_FD_ON_MONITORED_FS:
1138+
return xfs_healthmon_file_on_monitored_fs(file, cmd, arg);
11051139
default:
11061140
break;
11071141
}

0 commit comments

Comments
 (0)