Skip to content

Commit c684010

Browse files
committed
xfs: expose errortag knobs via sysfs
Creates a /sys/fs/xfs/$dev/errortag/ directory to control the errortag values directly. This enables us to control the randomness values, rather than having to accept the defaults. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Brian Foster <[email protected]> Reviewed-by: Carlos Maiolino <[email protected]>
1 parent 31965ef commit c684010

File tree

3 files changed

+157
-1
lines changed

3 files changed

+157
-1
lines changed

fs/xfs/xfs_error.c

Lines changed: 155 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "xfs_trans_resv.h"
2323
#include "xfs_mount.h"
2424
#include "xfs_error.h"
25+
#include "xfs_sysfs.h"
2526

2627
#ifdef DEBUG
2728

@@ -56,6 +57,145 @@ static unsigned int xfs_errortag_random_default[] = {
5657
XFS_RANDOM_AG_RESV_CRITICAL,
5758
};
5859

60+
struct xfs_errortag_attr {
61+
struct attribute attr;
62+
unsigned int tag;
63+
};
64+
65+
static inline struct xfs_errortag_attr *
66+
to_attr(struct attribute *attr)
67+
{
68+
return container_of(attr, struct xfs_errortag_attr, attr);
69+
}
70+
71+
static inline struct xfs_mount *
72+
to_mp(struct kobject *kobject)
73+
{
74+
struct xfs_kobj *kobj = to_kobj(kobject);
75+
76+
return container_of(kobj, struct xfs_mount, m_errortag_kobj);
77+
}
78+
79+
STATIC ssize_t
80+
xfs_errortag_attr_store(
81+
struct kobject *kobject,
82+
struct attribute *attr,
83+
const char *buf,
84+
size_t count)
85+
{
86+
struct xfs_mount *mp = to_mp(kobject);
87+
struct xfs_errortag_attr *xfs_attr = to_attr(attr);
88+
int ret;
89+
unsigned int val;
90+
91+
if (strcmp(buf, "default") == 0) {
92+
val = xfs_errortag_random_default[xfs_attr->tag];
93+
} else {
94+
ret = kstrtouint(buf, 0, &val);
95+
if (ret)
96+
return ret;
97+
}
98+
99+
ret = xfs_errortag_set(mp, xfs_attr->tag, val);
100+
if (ret)
101+
return ret;
102+
return count;
103+
}
104+
105+
STATIC ssize_t
106+
xfs_errortag_attr_show(
107+
struct kobject *kobject,
108+
struct attribute *attr,
109+
char *buf)
110+
{
111+
struct xfs_mount *mp = to_mp(kobject);
112+
struct xfs_errortag_attr *xfs_attr = to_attr(attr);
113+
114+
return snprintf(buf, PAGE_SIZE, "%u\n",
115+
xfs_errortag_get(mp, xfs_attr->tag));
116+
}
117+
118+
static const struct sysfs_ops xfs_errortag_sysfs_ops = {
119+
.show = xfs_errortag_attr_show,
120+
.store = xfs_errortag_attr_store,
121+
};
122+
123+
#define XFS_ERRORTAG_ATTR_RW(_name, _tag) \
124+
static struct xfs_errortag_attr xfs_errortag_attr_##_name = { \
125+
.attr = {.name = __stringify(_name), \
126+
.mode = VERIFY_OCTAL_PERMISSIONS(S_IWUSR | S_IRUGO) }, \
127+
.tag = (_tag), \
128+
}
129+
130+
#define XFS_ERRORTAG_ATTR_LIST(_name) &xfs_errortag_attr_##_name.attr
131+
132+
XFS_ERRORTAG_ATTR_RW(noerror, XFS_ERRTAG_NOERROR);
133+
XFS_ERRORTAG_ATTR_RW(iflush1, XFS_ERRTAG_IFLUSH_1);
134+
XFS_ERRORTAG_ATTR_RW(iflush2, XFS_ERRTAG_IFLUSH_2);
135+
XFS_ERRORTAG_ATTR_RW(iflush3, XFS_ERRTAG_IFLUSH_3);
136+
XFS_ERRORTAG_ATTR_RW(iflush4, XFS_ERRTAG_IFLUSH_4);
137+
XFS_ERRORTAG_ATTR_RW(iflush5, XFS_ERRTAG_IFLUSH_5);
138+
XFS_ERRORTAG_ATTR_RW(iflush6, XFS_ERRTAG_IFLUSH_6);
139+
XFS_ERRORTAG_ATTR_RW(dareadbuf, XFS_ERRTAG_DA_READ_BUF);
140+
XFS_ERRORTAG_ATTR_RW(btree_chk_lblk, XFS_ERRTAG_BTREE_CHECK_LBLOCK);
141+
XFS_ERRORTAG_ATTR_RW(btree_chk_sblk, XFS_ERRTAG_BTREE_CHECK_SBLOCK);
142+
XFS_ERRORTAG_ATTR_RW(readagf, XFS_ERRTAG_ALLOC_READ_AGF);
143+
XFS_ERRORTAG_ATTR_RW(readagi, XFS_ERRTAG_IALLOC_READ_AGI);
144+
XFS_ERRORTAG_ATTR_RW(itobp, XFS_ERRTAG_ITOBP_INOTOBP);
145+
XFS_ERRORTAG_ATTR_RW(iunlink, XFS_ERRTAG_IUNLINK);
146+
XFS_ERRORTAG_ATTR_RW(iunlinkrm, XFS_ERRTAG_IUNLINK_REMOVE);
147+
XFS_ERRORTAG_ATTR_RW(dirinovalid, XFS_ERRTAG_DIR_INO_VALIDATE);
148+
XFS_ERRORTAG_ATTR_RW(bulkstat, XFS_ERRTAG_BULKSTAT_READ_CHUNK);
149+
XFS_ERRORTAG_ATTR_RW(logiodone, XFS_ERRTAG_IODONE_IOERR);
150+
XFS_ERRORTAG_ATTR_RW(stratread, XFS_ERRTAG_STRATREAD_IOERR);
151+
XFS_ERRORTAG_ATTR_RW(stratcmpl, XFS_ERRTAG_STRATCMPL_IOERR);
152+
XFS_ERRORTAG_ATTR_RW(diowrite, XFS_ERRTAG_DIOWRITE_IOERR);
153+
XFS_ERRORTAG_ATTR_RW(bmapifmt, XFS_ERRTAG_BMAPIFORMAT);
154+
XFS_ERRORTAG_ATTR_RW(free_extent, XFS_ERRTAG_FREE_EXTENT);
155+
XFS_ERRORTAG_ATTR_RW(rmap_finish_one, XFS_ERRTAG_RMAP_FINISH_ONE);
156+
XFS_ERRORTAG_ATTR_RW(refcount_continue_update, XFS_ERRTAG_REFCOUNT_CONTINUE_UPDATE);
157+
XFS_ERRORTAG_ATTR_RW(refcount_finish_one, XFS_ERRTAG_REFCOUNT_FINISH_ONE);
158+
XFS_ERRORTAG_ATTR_RW(bmap_finish_one, XFS_ERRTAG_BMAP_FINISH_ONE);
159+
XFS_ERRORTAG_ATTR_RW(ag_resv_critical, XFS_ERRTAG_AG_RESV_CRITICAL);
160+
161+
static struct attribute *xfs_errortag_attrs[] = {
162+
XFS_ERRORTAG_ATTR_LIST(noerror),
163+
XFS_ERRORTAG_ATTR_LIST(iflush1),
164+
XFS_ERRORTAG_ATTR_LIST(iflush2),
165+
XFS_ERRORTAG_ATTR_LIST(iflush3),
166+
XFS_ERRORTAG_ATTR_LIST(iflush4),
167+
XFS_ERRORTAG_ATTR_LIST(iflush5),
168+
XFS_ERRORTAG_ATTR_LIST(iflush6),
169+
XFS_ERRORTAG_ATTR_LIST(dareadbuf),
170+
XFS_ERRORTAG_ATTR_LIST(btree_chk_lblk),
171+
XFS_ERRORTAG_ATTR_LIST(btree_chk_sblk),
172+
XFS_ERRORTAG_ATTR_LIST(readagf),
173+
XFS_ERRORTAG_ATTR_LIST(readagi),
174+
XFS_ERRORTAG_ATTR_LIST(itobp),
175+
XFS_ERRORTAG_ATTR_LIST(iunlink),
176+
XFS_ERRORTAG_ATTR_LIST(iunlinkrm),
177+
XFS_ERRORTAG_ATTR_LIST(dirinovalid),
178+
XFS_ERRORTAG_ATTR_LIST(bulkstat),
179+
XFS_ERRORTAG_ATTR_LIST(logiodone),
180+
XFS_ERRORTAG_ATTR_LIST(stratread),
181+
XFS_ERRORTAG_ATTR_LIST(stratcmpl),
182+
XFS_ERRORTAG_ATTR_LIST(diowrite),
183+
XFS_ERRORTAG_ATTR_LIST(bmapifmt),
184+
XFS_ERRORTAG_ATTR_LIST(free_extent),
185+
XFS_ERRORTAG_ATTR_LIST(rmap_finish_one),
186+
XFS_ERRORTAG_ATTR_LIST(refcount_continue_update),
187+
XFS_ERRORTAG_ATTR_LIST(refcount_finish_one),
188+
XFS_ERRORTAG_ATTR_LIST(bmap_finish_one),
189+
XFS_ERRORTAG_ATTR_LIST(ag_resv_critical),
190+
NULL,
191+
};
192+
193+
struct kobj_type xfs_errortag_ktype = {
194+
.release = xfs_sysfs_release,
195+
.sysfs_ops = &xfs_errortag_sysfs_ops,
196+
.default_attrs = xfs_errortag_attrs,
197+
};
198+
59199
int
60200
xfs_errortag_init(
61201
struct xfs_mount *mp)
@@ -64,13 +204,16 @@ xfs_errortag_init(
64204
KM_SLEEP | KM_MAYFAIL);
65205
if (!mp->m_errortag)
66206
return -ENOMEM;
67-
return 0;
207+
208+
return xfs_sysfs_init(&mp->m_errortag_kobj, &xfs_errortag_ktype,
209+
&mp->m_kobj, "errortag");
68210
}
69211

70212
void
71213
xfs_errortag_del(
72214
struct xfs_mount *mp)
73215
{
216+
xfs_sysfs_del(&mp->m_errortag_kobj);
74217
kmem_free(mp->m_errortag);
75218
}
76219

@@ -95,6 +238,17 @@ xfs_errortag_test(
95238
return true;
96239
}
97240

241+
int
242+
xfs_errortag_get(
243+
struct xfs_mount *mp,
244+
unsigned int error_tag)
245+
{
246+
if (error_tag >= XFS_ERRTAG_MAX)
247+
return -EINVAL;
248+
249+
return mp->m_errortag[error_tag];
250+
}
251+
98252
int
99253
xfs_errortag_set(
100254
struct xfs_mount *mp,

fs/xfs/xfs_error.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ extern bool xfs_errortag_test(struct xfs_mount *mp, const char *expression,
138138
#define XFS_TEST_ERROR(expr, mp, tag, rf) \
139139
((expr) || xfs_errortag_test((mp), #expr, __FILE__, __LINE__, (tag)))
140140

141+
extern int xfs_errortag_get(struct xfs_mount *mp, unsigned int error_tag);
141142
extern int xfs_errortag_set(struct xfs_mount *mp, unsigned int error_tag,
142143
unsigned int tag_value);
143144
extern int xfs_errortag_add(struct xfs_mount *mp, unsigned int error_tag);

fs/xfs/xfs_mount.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ typedef struct xfs_mount {
204204
* error triggers. 1 = always, 2 = half the time, etc.
205205
*/
206206
unsigned int *m_errortag;
207+
struct xfs_kobj m_errortag_kobj;
207208

208209
/*
209210
* DEBUG mode instrumentation to test and/or trigger delayed allocation

0 commit comments

Comments
 (0)