Skip to content

Commit 36fd6e8

Browse files
committed
xfs: create an ioctl to scrub AG metadata
Create an ioctl that can be used to scrub internal filesystem metadata. The new ioctl takes the metadata type, an (optional) AG number, an (optional) inode number and generation, and a flags argument. This will be used by the upcoming XFS online scrub tool. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Dave Chinner <[email protected]>
1 parent 91fb9af commit 36fd6e8

File tree

10 files changed

+292
-0
lines changed

10 files changed

+292
-0
lines changed

fs/xfs/Kconfig

+17
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,23 @@ config XFS_RT
7171

7272
If unsure, say N.
7373

74+
config XFS_ONLINE_SCRUB
75+
bool "XFS online metadata check support"
76+
default n
77+
depends on XFS_FS
78+
help
79+
If you say Y here you will be able to check metadata on a
80+
mounted XFS filesystem. This feature is intended to reduce
81+
filesystem downtime by supplementing xfs_repair. The key
82+
advantage here is to look for problems proactively so that
83+
they can be dealt with in a controlled manner.
84+
85+
This feature is considered EXPERIMENTAL. Use with caution!
86+
87+
See the xfs_scrub man page in section 8 for additional information.
88+
89+
If unsure, say N.
90+
7491
config XFS_WARN
7592
bool "XFS Verbose Warnings"
7693
depends on XFS_FS && !XFS_DEBUG

fs/xfs/Makefile

+11
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,14 @@ xfs-$(CONFIG_XFS_POSIX_ACL) += xfs_acl.o
135135
xfs-$(CONFIG_SYSCTL) += xfs_sysctl.o
136136
xfs-$(CONFIG_COMPAT) += xfs_ioctl32.o
137137
xfs-$(CONFIG_EXPORTFS_BLOCK_OPS) += xfs_pnfs.o
138+
139+
# online scrub/repair
140+
ifeq ($(CONFIG_XFS_ONLINE_SCRUB),y)
141+
142+
# Tracepoints like to blow up, so build that before everything else
143+
144+
xfs-y += $(addprefix scrub/, \
145+
trace.o \
146+
scrub.o \
147+
)
148+
endif

fs/xfs/libxfs/xfs_fs.h

+53
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,58 @@ typedef struct xfs_swapext
468468
#define XFS_FSOP_GOING_FLAGS_LOGFLUSH 0x1 /* flush log but not data */
469469
#define XFS_FSOP_GOING_FLAGS_NOLOGFLUSH 0x2 /* don't flush log nor data */
470470

471+
/* metadata scrubbing */
472+
struct xfs_scrub_metadata {
473+
__u32 sm_type; /* What to check? */
474+
__u32 sm_flags; /* flags; see below. */
475+
__u64 sm_ino; /* inode number. */
476+
__u32 sm_gen; /* inode generation. */
477+
__u32 sm_agno; /* ag number. */
478+
__u64 sm_reserved[5]; /* pad to 64 bytes */
479+
};
480+
481+
/*
482+
* Metadata types and flags for scrub operation.
483+
*/
484+
485+
/* Scrub subcommands. */
486+
487+
/* Number of scrub subcommands. */
488+
#define XFS_SCRUB_TYPE_NR 0
489+
490+
/* i: Repair this metadata. */
491+
#define XFS_SCRUB_IFLAG_REPAIR (1 << 0)
492+
493+
/* o: Metadata object needs repair. */
494+
#define XFS_SCRUB_OFLAG_CORRUPT (1 << 1)
495+
496+
/*
497+
* o: Metadata object could be optimized. It's not corrupt, but
498+
* we could improve on it somehow.
499+
*/
500+
#define XFS_SCRUB_OFLAG_PREEN (1 << 2)
501+
502+
/* o: Cross-referencing failed. */
503+
#define XFS_SCRUB_OFLAG_XFAIL (1 << 3)
504+
505+
/* o: Metadata object disagrees with cross-referenced metadata. */
506+
#define XFS_SCRUB_OFLAG_XCORRUPT (1 << 4)
507+
508+
/* o: Scan was not complete. */
509+
#define XFS_SCRUB_OFLAG_INCOMPLETE (1 << 5)
510+
511+
/* o: Metadata object looked funny but isn't corrupt. */
512+
#define XFS_SCRUB_OFLAG_WARNING (1 << 6)
513+
514+
#define XFS_SCRUB_FLAGS_IN (XFS_SCRUB_IFLAG_REPAIR)
515+
#define XFS_SCRUB_FLAGS_OUT (XFS_SCRUB_OFLAG_CORRUPT | \
516+
XFS_SCRUB_OFLAG_PREEN | \
517+
XFS_SCRUB_OFLAG_XFAIL | \
518+
XFS_SCRUB_OFLAG_XCORRUPT | \
519+
XFS_SCRUB_OFLAG_INCOMPLETE | \
520+
XFS_SCRUB_OFLAG_WARNING)
521+
#define XFS_SCRUB_FLAGS_ALL (XFS_SCRUB_FLAGS_IN | XFS_SCRUB_FLAGS_OUT)
522+
471523
/*
472524
* ioctl limits
473525
*/
@@ -511,6 +563,7 @@ typedef struct xfs_swapext
511563
#define XFS_IOC_ZERO_RANGE _IOW ('X', 57, struct xfs_flock64)
512564
#define XFS_IOC_FREE_EOFBLOCKS _IOR ('X', 58, struct xfs_fs_eofblocks)
513565
/* XFS_IOC_GETFSMAP ------ hoisted 59 */
566+
#define XFS_IOC_SCRUB_METADATA _IOWR('X', 60, struct xfs_scrub_metadata)
514567

515568
/*
516569
* ioctl commands that replace IRIX syssgi()'s

fs/xfs/scrub/scrub.c

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (C) 2017 Oracle. All Rights Reserved.
3+
*
4+
* Author: Darrick J. Wong <[email protected]>
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU General Public License
8+
* as published by the Free Software Foundation; either version 2
9+
* of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it would be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
#include "xfs.h"
21+
#include "xfs_fs.h"
22+
#include "xfs_shared.h"
23+
#include "xfs_format.h"
24+
#include "xfs_trans_resv.h"
25+
#include "xfs_mount.h"
26+
#include "xfs_defer.h"
27+
#include "xfs_btree.h"
28+
#include "xfs_bit.h"
29+
#include "xfs_log_format.h"
30+
#include "xfs_trans.h"
31+
#include "xfs_sb.h"
32+
#include "xfs_inode.h"
33+
#include "xfs_alloc.h"
34+
#include "xfs_alloc_btree.h"
35+
#include "xfs_bmap.h"
36+
#include "xfs_bmap_btree.h"
37+
#include "xfs_ialloc.h"
38+
#include "xfs_ialloc_btree.h"
39+
#include "xfs_refcount.h"
40+
#include "xfs_refcount_btree.h"
41+
#include "xfs_rmap.h"
42+
#include "xfs_rmap_btree.h"
43+
#include "scrub/xfs_scrub.h"
44+
#include "scrub/scrub.h"
45+
#include "scrub/trace.h"
46+
47+
/* Dispatch metadata scrubbing. */
48+
int
49+
xfs_scrub_metadata(
50+
struct xfs_inode *ip,
51+
struct xfs_scrub_metadata *sm)
52+
{
53+
return -EOPNOTSUPP;
54+
}

fs/xfs/scrub/scrub.h

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (C) 2017 Oracle. All Rights Reserved.
3+
*
4+
* Author: Darrick J. Wong <[email protected]>
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU General Public License
8+
* as published by the Free Software Foundation; either version 2
9+
* of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it would be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
#ifndef __XFS_SCRUB_SCRUB_H__
21+
#define __XFS_SCRUB_SCRUB_H__
22+
23+
/* Metadata scrubbers */
24+
25+
#endif /* __XFS_SCRUB_SCRUB_H__ */

fs/xfs/scrub/trace.c

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (C) 2017 Oracle. All Rights Reserved.
3+
*
4+
* Author: Darrick J. Wong <[email protected]>
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU General Public License
8+
* as published by the Free Software Foundation; either version 2
9+
* of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it would be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
#include "xfs.h"
21+
#include "xfs_fs.h"
22+
#include "xfs_shared.h"
23+
#include "xfs_format.h"
24+
#include "xfs_log_format.h"
25+
#include "xfs_trans_resv.h"
26+
#include "xfs_mount.h"
27+
#include "xfs_defer.h"
28+
#include "xfs_da_format.h"
29+
#include "xfs_defer.h"
30+
#include "xfs_inode.h"
31+
#include "xfs_btree.h"
32+
#include "xfs_trans.h"
33+
#include "scrub/xfs_scrub.h"
34+
#include "scrub/scrub.h"
35+
36+
/*
37+
* We include this last to have the helpers above available for the trace
38+
* event implementations.
39+
*/
40+
#define CREATE_TRACE_POINTS
41+
#include "scrub/trace.h"

fs/xfs/scrub/trace.h

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (C) 2017 Oracle. All Rights Reserved.
3+
*
4+
* Author: Darrick J. Wong <[email protected]>
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU General Public License
8+
* as published by the Free Software Foundation; either version 2
9+
* of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it would be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
#undef TRACE_SYSTEM
21+
#define TRACE_SYSTEM xfs_scrub
22+
23+
#if !defined(_TRACE_XFS_SCRUB_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
24+
#define _TRACE_XFS_SCRUB_TRACE_H
25+
26+
#include <linux/tracepoint.h>
27+
28+
#endif /* _TRACE_XFS_SCRUB_TRACE_H */
29+
30+
#undef TRACE_INCLUDE_PATH
31+
#define TRACE_INCLUDE_PATH .
32+
#define TRACE_INCLUDE_FILE scrub/trace
33+
#include <trace/define_trace.h>

fs/xfs/scrub/xfs_scrub.h

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (C) 2017 Oracle. All Rights Reserved.
3+
*
4+
* Author: Darrick J. Wong <[email protected]>
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU General Public License
8+
* as published by the Free Software Foundation; either version 2
9+
* of the License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it would be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19+
*/
20+
#ifndef __XFS_SCRUB_H__
21+
#define __XFS_SCRUB_H__
22+
23+
#ifndef CONFIG_XFS_ONLINE_SCRUB
24+
# define xfs_scrub_metadata(ip, sm) (-ENOTTY)
25+
#else
26+
int xfs_scrub_metadata(struct xfs_inode *ip, struct xfs_scrub_metadata *sm);
27+
#endif /* CONFIG_XFS_ONLINE_SCRUB */
28+
29+
#endif /* __XFS_SCRUB_H__ */

fs/xfs/xfs_ioctl.c

+28
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "xfs_btree.h"
4545
#include <linux/fsmap.h>
4646
#include "xfs_fsmap.h"
47+
#include "scrub/xfs_scrub.h"
4748

4849
#include <linux/capability.h>
4950
#include <linux/cred.h>
@@ -1701,6 +1702,30 @@ xfs_ioc_getfsmap(
17011702
return 0;
17021703
}
17031704

1705+
STATIC int
1706+
xfs_ioc_scrub_metadata(
1707+
struct xfs_inode *ip,
1708+
void __user *arg)
1709+
{
1710+
struct xfs_scrub_metadata scrub;
1711+
int error;
1712+
1713+
if (!capable(CAP_SYS_ADMIN))
1714+
return -EPERM;
1715+
1716+
if (copy_from_user(&scrub, arg, sizeof(scrub)))
1717+
return -EFAULT;
1718+
1719+
error = xfs_scrub_metadata(ip, &scrub);
1720+
if (error)
1721+
return error;
1722+
1723+
if (copy_to_user(arg, &scrub, sizeof(scrub)))
1724+
return -EFAULT;
1725+
1726+
return 0;
1727+
}
1728+
17041729
int
17051730
xfs_ioc_swapext(
17061731
xfs_swapext_t *sxp)
@@ -1882,6 +1907,9 @@ xfs_file_ioctl(
18821907
case FS_IOC_GETFSMAP:
18831908
return xfs_ioc_getfsmap(ip, arg);
18841909

1910+
case XFS_IOC_SCRUB_METADATA:
1911+
return xfs_ioc_scrub_metadata(ip, arg);
1912+
18851913
case XFS_IOC_FD_TO_HANDLE:
18861914
case XFS_IOC_PATH_TO_HANDLE:
18871915
case XFS_IOC_PATH_TO_FSHANDLE: {

fs/xfs/xfs_ioctl32.c

+1
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ xfs_file_compat_ioctl(
556556
case XFS_IOC_ERROR_INJECTION:
557557
case XFS_IOC_ERROR_CLEARALL:
558558
case FS_IOC_GETFSMAP:
559+
case XFS_IOC_SCRUB_METADATA:
559560
return xfs_file_ioctl(filp, cmd, p);
560561
#ifndef BROKEN_X86_ALIGNMENT
561562
/* These are handled fine if no alignment issues */

0 commit comments

Comments
 (0)