Linux Audio

Check our new training course

Loading...
v4.10.11
  1/*
  2 * Copyright (c) 2014 Red Hat, Inc.
  3 * All Rights Reserved.
  4 *
  5 * This program is free software; you can redistribute it and/or
  6 * modify it under the terms of the GNU General Public License as
  7 * published by the Free Software Foundation.
  8 *
  9 * This program is distributed in the hope that it would be useful,
 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12 * GNU General Public License for more details.
 13 *
 14 * You should have received a copy of the GNU General Public License
 15 * along with this program; if not, write the Free Software Foundation,
 16 * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 17 */
 18
 19#include "xfs.h"
 20#include "xfs_shared.h"
 21#include "xfs_format.h"
 22#include "xfs_log_format.h"
 23#include "xfs_trans_resv.h"
 24#include "xfs_sysfs.h"
 25#include "xfs_log.h"
 26#include "xfs_log_priv.h"
 27#include "xfs_stats.h"
 28#include "xfs_mount.h"
 29
 30struct xfs_sysfs_attr {
 31	struct attribute attr;
 32	ssize_t (*show)(struct kobject *kobject, char *buf);
 33	ssize_t (*store)(struct kobject *kobject, const char *buf,
 34			 size_t count);
 35};
 36
 37static inline struct xfs_sysfs_attr *
 38to_attr(struct attribute *attr)
 39{
 40	return container_of(attr, struct xfs_sysfs_attr, attr);
 41}
 42
 43#define XFS_SYSFS_ATTR_RW(name) \
 44	static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_RW(name)
 45#define XFS_SYSFS_ATTR_RO(name) \
 46	static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_RO(name)
 47#define XFS_SYSFS_ATTR_WO(name) \
 48	static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_WO(name)
 49
 50#define ATTR_LIST(name) &xfs_sysfs_attr_##name.attr
 51
 52STATIC ssize_t
 53xfs_sysfs_object_show(
 54	struct kobject		*kobject,
 55	struct attribute	*attr,
 56	char			*buf)
 57{
 58	struct xfs_sysfs_attr *xfs_attr = to_attr(attr);
 59
 60	return xfs_attr->show ? xfs_attr->show(kobject, buf) : 0;
 61}
 62
 63STATIC ssize_t
 64xfs_sysfs_object_store(
 65	struct kobject		*kobject,
 66	struct attribute	*attr,
 67	const char		*buf,
 68	size_t			count)
 69{
 70	struct xfs_sysfs_attr *xfs_attr = to_attr(attr);
 71
 72	return xfs_attr->store ? xfs_attr->store(kobject, buf, count) : 0;
 73}
 74
 75static const struct sysfs_ops xfs_sysfs_ops = {
 76	.show = xfs_sysfs_object_show,
 77	.store = xfs_sysfs_object_store,
 78};
 79
 80/*
 81 * xfs_mount kobject. The mp kobject also serves as the per-mount parent object
 82 * that is identified by the fsname under sysfs.
 83 */
 84
 85static inline struct xfs_mount *
 86to_mp(struct kobject *kobject)
 87{
 88	struct xfs_kobj *kobj = to_kobj(kobject);
 89
 90	return container_of(kobj, struct xfs_mount, m_kobj);
 91}
 92
 93#ifdef DEBUG
 94
 95STATIC ssize_t
 96fail_writes_store(
 97	struct kobject		*kobject,
 98	const char		*buf,
 99	size_t			count)
100{
101	struct xfs_mount	*mp = to_mp(kobject);
102	int			ret;
103	int			val;
104
105	ret = kstrtoint(buf, 0, &val);
106	if (ret)
107		return ret;
108
109	if (val == 1)
110		mp->m_fail_writes = true;
111	else if (val == 0)
112		mp->m_fail_writes = false;
113	else
114		return -EINVAL;
115
116	return count;
117}
118
119STATIC ssize_t
120fail_writes_show(
121	struct kobject		*kobject,
122	char			*buf)
123{
124	struct xfs_mount	*mp = to_mp(kobject);
125
126	return snprintf(buf, PAGE_SIZE, "%d\n", mp->m_fail_writes ? 1 : 0);
127}
128XFS_SYSFS_ATTR_RW(fail_writes);
129
130#endif /* DEBUG */
131
132static struct attribute *xfs_mp_attrs[] = {
133#ifdef DEBUG
134	ATTR_LIST(fail_writes),
135#endif
136	NULL,
137};
138
139struct kobj_type xfs_mp_ktype = {
140	.release = xfs_sysfs_release,
141	.sysfs_ops = &xfs_sysfs_ops,
142	.default_attrs = xfs_mp_attrs,
143};
144
145#ifdef DEBUG
146/* debug */
147
148STATIC ssize_t
149log_recovery_delay_store(
150	struct kobject	*kobject,
151	const char	*buf,
152	size_t		count)
153{
154	int		ret;
155	int		val;
156
157	ret = kstrtoint(buf, 0, &val);
158	if (ret)
159		return ret;
160
161	if (val < 0 || val > 60)
162		return -EINVAL;
163
164	xfs_globals.log_recovery_delay = val;
165
166	return count;
167}
168
169STATIC ssize_t
170log_recovery_delay_show(
171	struct kobject	*kobject,
172	char		*buf)
173{
174	return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.log_recovery_delay);
175}
176XFS_SYSFS_ATTR_RW(log_recovery_delay);
177
178static struct attribute *xfs_dbg_attrs[] = {
179	ATTR_LIST(log_recovery_delay),
180	NULL,
181};
182
183struct kobj_type xfs_dbg_ktype = {
184	.release = xfs_sysfs_release,
185	.sysfs_ops = &xfs_sysfs_ops,
186	.default_attrs = xfs_dbg_attrs,
187};
188
189#endif /* DEBUG */
190
191/* stats */
192
193static inline struct xstats *
194to_xstats(struct kobject *kobject)
195{
196	struct xfs_kobj *kobj = to_kobj(kobject);
197
198	return container_of(kobj, struct xstats, xs_kobj);
199}
200
201STATIC ssize_t
202stats_show(
203	struct kobject	*kobject,
204	char		*buf)
205{
206	struct xstats	*stats = to_xstats(kobject);
207
208	return xfs_stats_format(stats->xs_stats, buf);
209}
210XFS_SYSFS_ATTR_RO(stats);
211
212STATIC ssize_t
213stats_clear_store(
214	struct kobject	*kobject,
215	const char	*buf,
216	size_t		count)
217{
218	int		ret;
219	int		val;
220	struct xstats	*stats = to_xstats(kobject);
221
222	ret = kstrtoint(buf, 0, &val);
223	if (ret)
224		return ret;
225
226	if (val != 1)
227		return -EINVAL;
228
229	xfs_stats_clearall(stats->xs_stats);
230	return count;
231}
232XFS_SYSFS_ATTR_WO(stats_clear);
233
234static struct attribute *xfs_stats_attrs[] = {
235	ATTR_LIST(stats),
236	ATTR_LIST(stats_clear),
237	NULL,
238};
239
240struct kobj_type xfs_stats_ktype = {
241	.release = xfs_sysfs_release,
242	.sysfs_ops = &xfs_sysfs_ops,
243	.default_attrs = xfs_stats_attrs,
244};
245
246/* xlog */
247
248static inline struct xlog *
249to_xlog(struct kobject *kobject)
250{
251	struct xfs_kobj *kobj = to_kobj(kobject);
252
253	return container_of(kobj, struct xlog, l_kobj);
254}
255
256STATIC ssize_t
257log_head_lsn_show(
258	struct kobject	*kobject,
259	char		*buf)
260{
261	int cycle;
262	int block;
263	struct xlog *log = to_xlog(kobject);
264
265	spin_lock(&log->l_icloglock);
266	cycle = log->l_curr_cycle;
267	block = log->l_curr_block;
268	spin_unlock(&log->l_icloglock);
269
270	return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block);
271}
272XFS_SYSFS_ATTR_RO(log_head_lsn);
273
274STATIC ssize_t
275log_tail_lsn_show(
276	struct kobject	*kobject,
277	char		*buf)
278{
279	int cycle;
280	int block;
281	struct xlog *log = to_xlog(kobject);
282
283	xlog_crack_atomic_lsn(&log->l_tail_lsn, &cycle, &block);
284	return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block);
285}
286XFS_SYSFS_ATTR_RO(log_tail_lsn);
287
288STATIC ssize_t
289reserve_grant_head_show(
290	struct kobject	*kobject,
291	char		*buf)
292
293{
294	int cycle;
295	int bytes;
296	struct xlog *log = to_xlog(kobject);
297
298	xlog_crack_grant_head(&log->l_reserve_head.grant, &cycle, &bytes);
299	return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes);
300}
301XFS_SYSFS_ATTR_RO(reserve_grant_head);
302
303STATIC ssize_t
304write_grant_head_show(
305	struct kobject	*kobject,
306	char		*buf)
307{
308	int cycle;
309	int bytes;
310	struct xlog *log = to_xlog(kobject);
311
312	xlog_crack_grant_head(&log->l_write_head.grant, &cycle, &bytes);
313	return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes);
314}
315XFS_SYSFS_ATTR_RO(write_grant_head);
316
317#ifdef DEBUG
318STATIC ssize_t
319log_badcrc_factor_store(
320	struct kobject	*kobject,
321	const char	*buf,
322	size_t		count)
323{
324	struct xlog	*log = to_xlog(kobject);
325	int		ret;
326	uint32_t	val;
327
328	ret = kstrtouint(buf, 0, &val);
329	if (ret)
330		return ret;
331
332	log->l_badcrc_factor = val;
333
334	return count;
335}
336
337STATIC ssize_t
338log_badcrc_factor_show(
339	struct kobject	*kobject,
340	char		*buf)
341{
342	struct xlog	*log = to_xlog(kobject);
343
344	return snprintf(buf, PAGE_SIZE, "%d\n", log->l_badcrc_factor);
345}
346
347XFS_SYSFS_ATTR_RW(log_badcrc_factor);
348#endif	/* DEBUG */
349
350static struct attribute *xfs_log_attrs[] = {
351	ATTR_LIST(log_head_lsn),
352	ATTR_LIST(log_tail_lsn),
353	ATTR_LIST(reserve_grant_head),
354	ATTR_LIST(write_grant_head),
355#ifdef DEBUG
356	ATTR_LIST(log_badcrc_factor),
357#endif
358	NULL,
359};
360
361struct kobj_type xfs_log_ktype = {
362	.release = xfs_sysfs_release,
363	.sysfs_ops = &xfs_sysfs_ops,
364	.default_attrs = xfs_log_attrs,
365};
366
367/*
368 * Metadata IO error configuration
369 *
370 * The sysfs structure here is:
371 *	...xfs/<dev>/error/<class>/<errno>/<error_attrs>
372 *
373 * where <class> allows us to discriminate between data IO and metadata IO,
374 * and any other future type of IO (e.g. special inode or directory error
375 * handling) we care to support.
376 */
377static inline struct xfs_error_cfg *
378to_error_cfg(struct kobject *kobject)
379{
380	struct xfs_kobj *kobj = to_kobj(kobject);
381	return container_of(kobj, struct xfs_error_cfg, kobj);
382}
383
384static inline struct xfs_mount *
385err_to_mp(struct kobject *kobject)
386{
387	struct xfs_kobj *kobj = to_kobj(kobject);
388	return container_of(kobj, struct xfs_mount, m_error_kobj);
389}
390
391static ssize_t
392max_retries_show(
393	struct kobject	*kobject,
394	char		*buf)
395{
396	int		retries;
397	struct xfs_error_cfg *cfg = to_error_cfg(kobject);
398
399	if (cfg->max_retries == XFS_ERR_RETRY_FOREVER)
400		retries = -1;
401	else
402		retries = cfg->max_retries;
403
404	return snprintf(buf, PAGE_SIZE, "%d\n", retries);
405}
406
407static ssize_t
408max_retries_store(
409	struct kobject	*kobject,
410	const char	*buf,
411	size_t		count)
412{
413	struct xfs_error_cfg *cfg = to_error_cfg(kobject);
414	int		ret;
415	int		val;
416
417	ret = kstrtoint(buf, 0, &val);
418	if (ret)
419		return ret;
420
421	if (val < -1)
422		return -EINVAL;
423
424	if (val == -1)
425		cfg->max_retries = XFS_ERR_RETRY_FOREVER;
426	else
427		cfg->max_retries = val;
428	return count;
429}
430XFS_SYSFS_ATTR_RW(max_retries);
431
432static ssize_t
433retry_timeout_seconds_show(
434	struct kobject	*kobject,
435	char		*buf)
436{
437	int		timeout;
438	struct xfs_error_cfg *cfg = to_error_cfg(kobject);
439
440	if (cfg->retry_timeout == XFS_ERR_RETRY_FOREVER)
441		timeout = -1;
442	else
443		timeout = jiffies_to_msecs(cfg->retry_timeout) / MSEC_PER_SEC;
444
445	return snprintf(buf, PAGE_SIZE, "%d\n", timeout);
446}
447
448static ssize_t
449retry_timeout_seconds_store(
450	struct kobject	*kobject,
451	const char	*buf,
452	size_t		count)
453{
454	struct xfs_error_cfg *cfg = to_error_cfg(kobject);
455	int		ret;
456	int		val;
457
458	ret = kstrtoint(buf, 0, &val);
459	if (ret)
460		return ret;
461
462	/* 1 day timeout maximum, -1 means infinite */
463	if (val < -1 || val > 86400)
464		return -EINVAL;
465
466	if (val == -1)
467		cfg->retry_timeout = XFS_ERR_RETRY_FOREVER;
468	else {
469		cfg->retry_timeout = msecs_to_jiffies(val * MSEC_PER_SEC);
470		ASSERT(msecs_to_jiffies(val * MSEC_PER_SEC) < LONG_MAX);
471	}
472	return count;
473}
474XFS_SYSFS_ATTR_RW(retry_timeout_seconds);
475
476static ssize_t
477fail_at_unmount_show(
478	struct kobject	*kobject,
479	char		*buf)
480{
481	struct xfs_mount	*mp = err_to_mp(kobject);
482
483	return snprintf(buf, PAGE_SIZE, "%d\n", mp->m_fail_unmount);
484}
485
486static ssize_t
487fail_at_unmount_store(
488	struct kobject	*kobject,
489	const char	*buf,
490	size_t		count)
491{
492	struct xfs_mount	*mp = err_to_mp(kobject);
493	int		ret;
494	int		val;
495
496	ret = kstrtoint(buf, 0, &val);
497	if (ret)
498		return ret;
499
500	if (val < 0 || val > 1)
501		return -EINVAL;
502
503	mp->m_fail_unmount = val;
504	return count;
505}
506XFS_SYSFS_ATTR_RW(fail_at_unmount);
507
508static struct attribute *xfs_error_attrs[] = {
509	ATTR_LIST(max_retries),
510	ATTR_LIST(retry_timeout_seconds),
511	NULL,
512};
513
514
515static struct kobj_type xfs_error_cfg_ktype = {
516	.release = xfs_sysfs_release,
517	.sysfs_ops = &xfs_sysfs_ops,
518	.default_attrs = xfs_error_attrs,
519};
520
521static struct kobj_type xfs_error_ktype = {
522	.release = xfs_sysfs_release,
523	.sysfs_ops = &xfs_sysfs_ops,
524};
525
526/*
527 * Error initialization tables. These need to be ordered in the same
528 * order as the enums used to index the array. All class init tables need to
529 * define a "default" behaviour as the first entry, all other entries can be
530 * empty.
531 */
532struct xfs_error_init {
533	char		*name;
534	int		max_retries;
535	int		retry_timeout;	/* in seconds */
536};
537
538static const struct xfs_error_init xfs_error_meta_init[XFS_ERR_ERRNO_MAX] = {
539	{ .name = "default",
540	  .max_retries = XFS_ERR_RETRY_FOREVER,
541	  .retry_timeout = XFS_ERR_RETRY_FOREVER,
542	},
543	{ .name = "EIO",
544	  .max_retries = XFS_ERR_RETRY_FOREVER,
545	  .retry_timeout = XFS_ERR_RETRY_FOREVER,
546	},
547	{ .name = "ENOSPC",
548	  .max_retries = XFS_ERR_RETRY_FOREVER,
549	  .retry_timeout = XFS_ERR_RETRY_FOREVER,
550	},
551	{ .name = "ENODEV",
552	  .max_retries = 0,	/* We can't recover from devices disappearing */
553	  .retry_timeout = 0,
554	},
555};
556
557static int
558xfs_error_sysfs_init_class(
559	struct xfs_mount	*mp,
560	int			class,
561	const char		*parent_name,
562	struct xfs_kobj		*parent_kobj,
563	const struct xfs_error_init init[])
564{
565	struct xfs_error_cfg	*cfg;
566	int			error;
567	int			i;
568
569	ASSERT(class < XFS_ERR_CLASS_MAX);
570
571	error = xfs_sysfs_init(parent_kobj, &xfs_error_ktype,
572				&mp->m_error_kobj, parent_name);
573	if (error)
574		return error;
575
576	for (i = 0; i < XFS_ERR_ERRNO_MAX; i++) {
577		cfg = &mp->m_error_cfg[class][i];
578		error = xfs_sysfs_init(&cfg->kobj, &xfs_error_cfg_ktype,
579					parent_kobj, init[i].name);
580		if (error)
581			goto out_error;
582
583		cfg->max_retries = init[i].max_retries;
584		if (init[i].retry_timeout == XFS_ERR_RETRY_FOREVER)
585			cfg->retry_timeout = XFS_ERR_RETRY_FOREVER;
586		else
587			cfg->retry_timeout = msecs_to_jiffies(
588					init[i].retry_timeout * MSEC_PER_SEC);
589	}
590	return 0;
591
592out_error:
593	/* unwind the entries that succeeded */
594	for (i--; i >= 0; i--) {
595		cfg = &mp->m_error_cfg[class][i];
596		xfs_sysfs_del(&cfg->kobj);
597	}
598	xfs_sysfs_del(parent_kobj);
599	return error;
600}
601
602int
603xfs_error_sysfs_init(
604	struct xfs_mount	*mp)
605{
606	int			error;
607
608	/* .../xfs/<dev>/error/ */
609	error = xfs_sysfs_init(&mp->m_error_kobj, &xfs_error_ktype,
610				&mp->m_kobj, "error");
611	if (error)
612		return error;
613
614	error = sysfs_create_file(&mp->m_error_kobj.kobject,
615				  ATTR_LIST(fail_at_unmount));
616
617	if (error)
618		goto out_error;
619
620	/* .../xfs/<dev>/error/metadata/ */
621	error = xfs_error_sysfs_init_class(mp, XFS_ERR_METADATA,
622				"metadata", &mp->m_error_meta_kobj,
623				xfs_error_meta_init);
624	if (error)
625		goto out_error;
626
627	return 0;
628
629out_error:
630	xfs_sysfs_del(&mp->m_error_kobj);
631	return error;
632}
633
634void
635xfs_error_sysfs_del(
636	struct xfs_mount	*mp)
637{
638	struct xfs_error_cfg	*cfg;
639	int			i, j;
640
641	for (i = 0; i < XFS_ERR_CLASS_MAX; i++) {
642		for (j = 0; j < XFS_ERR_ERRNO_MAX; j++) {
643			cfg = &mp->m_error_cfg[i][j];
644
645			xfs_sysfs_del(&cfg->kobj);
646		}
647	}
648	xfs_sysfs_del(&mp->m_error_meta_kobj);
649	xfs_sysfs_del(&mp->m_error_kobj);
650}
651
652struct xfs_error_cfg *
653xfs_error_get_cfg(
654	struct xfs_mount	*mp,
655	int			error_class,
656	int			error)
657{
658	struct xfs_error_cfg	*cfg;
659
660	if (error < 0)
661		error = -error;
662
663	switch (error) {
664	case EIO:
665		cfg = &mp->m_error_cfg[error_class][XFS_ERR_EIO];
666		break;
667	case ENOSPC:
668		cfg = &mp->m_error_cfg[error_class][XFS_ERR_ENOSPC];
669		break;
670	case ENODEV:
671		cfg = &mp->m_error_cfg[error_class][XFS_ERR_ENODEV];
672		break;
673	default:
674		cfg = &mp->m_error_cfg[error_class][XFS_ERR_DEFAULT];
675		break;
676	}
677
678	return cfg;
679}
v4.6
  1/*
  2 * Copyright (c) 2014 Red Hat, Inc.
  3 * All Rights Reserved.
  4 *
  5 * This program is free software; you can redistribute it and/or
  6 * modify it under the terms of the GNU General Public License as
  7 * published by the Free Software Foundation.
  8 *
  9 * This program is distributed in the hope that it would be useful,
 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12 * GNU General Public License for more details.
 13 *
 14 * You should have received a copy of the GNU General Public License
 15 * along with this program; if not, write the Free Software Foundation,
 16 * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 17 */
 18
 19#include "xfs.h"
 20#include "xfs_sysfs.h"
 21#include "xfs_format.h"
 22#include "xfs_log_format.h"
 23#include "xfs_trans_resv.h"
 
 24#include "xfs_log.h"
 25#include "xfs_log_priv.h"
 26#include "xfs_stats.h"
 27#include "xfs_mount.h"
 28
 29struct xfs_sysfs_attr {
 30	struct attribute attr;
 31	ssize_t (*show)(struct kobject *kobject, char *buf);
 32	ssize_t (*store)(struct kobject *kobject, const char *buf,
 33			 size_t count);
 34};
 35
 36static inline struct xfs_sysfs_attr *
 37to_attr(struct attribute *attr)
 38{
 39	return container_of(attr, struct xfs_sysfs_attr, attr);
 40}
 41
 42#define XFS_SYSFS_ATTR_RW(name) \
 43	static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_RW(name)
 44#define XFS_SYSFS_ATTR_RO(name) \
 45	static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_RO(name)
 46#define XFS_SYSFS_ATTR_WO(name) \
 47	static struct xfs_sysfs_attr xfs_sysfs_attr_##name = __ATTR_WO(name)
 48
 49#define ATTR_LIST(name) &xfs_sysfs_attr_##name.attr
 50
 51STATIC ssize_t
 52xfs_sysfs_object_show(
 53	struct kobject		*kobject,
 54	struct attribute	*attr,
 55	char			*buf)
 56{
 57	struct xfs_sysfs_attr *xfs_attr = to_attr(attr);
 58
 59	return xfs_attr->show ? xfs_attr->show(kobject, buf) : 0;
 60}
 61
 62STATIC ssize_t
 63xfs_sysfs_object_store(
 64	struct kobject		*kobject,
 65	struct attribute	*attr,
 66	const char		*buf,
 67	size_t			count)
 68{
 69	struct xfs_sysfs_attr *xfs_attr = to_attr(attr);
 70
 71	return xfs_attr->store ? xfs_attr->store(kobject, buf, count) : 0;
 72}
 73
 74static const struct sysfs_ops xfs_sysfs_ops = {
 75	.show = xfs_sysfs_object_show,
 76	.store = xfs_sysfs_object_store,
 77};
 78
 79/*
 80 * xfs_mount kobject. The mp kobject also serves as the per-mount parent object
 81 * that is identified by the fsname under sysfs.
 82 */
 83
 84static inline struct xfs_mount *
 85to_mp(struct kobject *kobject)
 86{
 87	struct xfs_kobj *kobj = to_kobj(kobject);
 88
 89	return container_of(kobj, struct xfs_mount, m_kobj);
 90}
 91
 92#ifdef DEBUG
 93
 94STATIC ssize_t
 95fail_writes_store(
 96	struct kobject		*kobject,
 97	const char		*buf,
 98	size_t			count)
 99{
100	struct xfs_mount	*mp = to_mp(kobject);
101	int			ret;
102	int			val;
103
104	ret = kstrtoint(buf, 0, &val);
105	if (ret)
106		return ret;
107
108	if (val == 1)
109		mp->m_fail_writes = true;
110	else if (val == 0)
111		mp->m_fail_writes = false;
112	else
113		return -EINVAL;
114
115	return count;
116}
117
118STATIC ssize_t
119fail_writes_show(
120	struct kobject		*kobject,
121	char			*buf)
122{
123	struct xfs_mount	*mp = to_mp(kobject);
124
125	return snprintf(buf, PAGE_SIZE, "%d\n", mp->m_fail_writes ? 1 : 0);
126}
127XFS_SYSFS_ATTR_RW(fail_writes);
128
129#endif /* DEBUG */
130
131static struct attribute *xfs_mp_attrs[] = {
132#ifdef DEBUG
133	ATTR_LIST(fail_writes),
134#endif
135	NULL,
136};
137
138struct kobj_type xfs_mp_ktype = {
139	.release = xfs_sysfs_release,
140	.sysfs_ops = &xfs_sysfs_ops,
141	.default_attrs = xfs_mp_attrs,
142};
143
144#ifdef DEBUG
145/* debug */
146
147STATIC ssize_t
148log_recovery_delay_store(
149	struct kobject	*kobject,
150	const char	*buf,
151	size_t		count)
152{
153	int		ret;
154	int		val;
155
156	ret = kstrtoint(buf, 0, &val);
157	if (ret)
158		return ret;
159
160	if (val < 0 || val > 60)
161		return -EINVAL;
162
163	xfs_globals.log_recovery_delay = val;
164
165	return count;
166}
167
168STATIC ssize_t
169log_recovery_delay_show(
170	struct kobject	*kobject,
171	char		*buf)
172{
173	return snprintf(buf, PAGE_SIZE, "%d\n", xfs_globals.log_recovery_delay);
174}
175XFS_SYSFS_ATTR_RW(log_recovery_delay);
176
177static struct attribute *xfs_dbg_attrs[] = {
178	ATTR_LIST(log_recovery_delay),
179	NULL,
180};
181
182struct kobj_type xfs_dbg_ktype = {
183	.release = xfs_sysfs_release,
184	.sysfs_ops = &xfs_sysfs_ops,
185	.default_attrs = xfs_dbg_attrs,
186};
187
188#endif /* DEBUG */
189
190/* stats */
191
192static inline struct xstats *
193to_xstats(struct kobject *kobject)
194{
195	struct xfs_kobj *kobj = to_kobj(kobject);
196
197	return container_of(kobj, struct xstats, xs_kobj);
198}
199
200STATIC ssize_t
201stats_show(
202	struct kobject	*kobject,
203	char		*buf)
204{
205	struct xstats	*stats = to_xstats(kobject);
206
207	return xfs_stats_format(stats->xs_stats, buf);
208}
209XFS_SYSFS_ATTR_RO(stats);
210
211STATIC ssize_t
212stats_clear_store(
213	struct kobject	*kobject,
214	const char	*buf,
215	size_t		count)
216{
217	int		ret;
218	int		val;
219	struct xstats	*stats = to_xstats(kobject);
220
221	ret = kstrtoint(buf, 0, &val);
222	if (ret)
223		return ret;
224
225	if (val != 1)
226		return -EINVAL;
227
228	xfs_stats_clearall(stats->xs_stats);
229	return count;
230}
231XFS_SYSFS_ATTR_WO(stats_clear);
232
233static struct attribute *xfs_stats_attrs[] = {
234	ATTR_LIST(stats),
235	ATTR_LIST(stats_clear),
236	NULL,
237};
238
239struct kobj_type xfs_stats_ktype = {
240	.release = xfs_sysfs_release,
241	.sysfs_ops = &xfs_sysfs_ops,
242	.default_attrs = xfs_stats_attrs,
243};
244
245/* xlog */
246
247static inline struct xlog *
248to_xlog(struct kobject *kobject)
249{
250	struct xfs_kobj *kobj = to_kobj(kobject);
251
252	return container_of(kobj, struct xlog, l_kobj);
253}
254
255STATIC ssize_t
256log_head_lsn_show(
257	struct kobject	*kobject,
258	char		*buf)
259{
260	int cycle;
261	int block;
262	struct xlog *log = to_xlog(kobject);
263
264	spin_lock(&log->l_icloglock);
265	cycle = log->l_curr_cycle;
266	block = log->l_curr_block;
267	spin_unlock(&log->l_icloglock);
268
269	return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block);
270}
271XFS_SYSFS_ATTR_RO(log_head_lsn);
272
273STATIC ssize_t
274log_tail_lsn_show(
275	struct kobject	*kobject,
276	char		*buf)
277{
278	int cycle;
279	int block;
280	struct xlog *log = to_xlog(kobject);
281
282	xlog_crack_atomic_lsn(&log->l_tail_lsn, &cycle, &block);
283	return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, block);
284}
285XFS_SYSFS_ATTR_RO(log_tail_lsn);
286
287STATIC ssize_t
288reserve_grant_head_show(
289	struct kobject	*kobject,
290	char		*buf)
291
292{
293	int cycle;
294	int bytes;
295	struct xlog *log = to_xlog(kobject);
296
297	xlog_crack_grant_head(&log->l_reserve_head.grant, &cycle, &bytes);
298	return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes);
299}
300XFS_SYSFS_ATTR_RO(reserve_grant_head);
301
302STATIC ssize_t
303write_grant_head_show(
304	struct kobject	*kobject,
305	char		*buf)
306{
307	int cycle;
308	int bytes;
309	struct xlog *log = to_xlog(kobject);
310
311	xlog_crack_grant_head(&log->l_write_head.grant, &cycle, &bytes);
312	return snprintf(buf, PAGE_SIZE, "%d:%d\n", cycle, bytes);
313}
314XFS_SYSFS_ATTR_RO(write_grant_head);
315
316#ifdef DEBUG
317STATIC ssize_t
318log_badcrc_factor_store(
319	struct kobject	*kobject,
320	const char	*buf,
321	size_t		count)
322{
323	struct xlog	*log = to_xlog(kobject);
324	int		ret;
325	uint32_t	val;
326
327	ret = kstrtouint(buf, 0, &val);
328	if (ret)
329		return ret;
330
331	log->l_badcrc_factor = val;
332
333	return count;
334}
335
336STATIC ssize_t
337log_badcrc_factor_show(
338	struct kobject	*kobject,
339	char		*buf)
340{
341	struct xlog	*log = to_xlog(kobject);
342
343	return snprintf(buf, PAGE_SIZE, "%d\n", log->l_badcrc_factor);
344}
345
346XFS_SYSFS_ATTR_RW(log_badcrc_factor);
347#endif	/* DEBUG */
348
349static struct attribute *xfs_log_attrs[] = {
350	ATTR_LIST(log_head_lsn),
351	ATTR_LIST(log_tail_lsn),
352	ATTR_LIST(reserve_grant_head),
353	ATTR_LIST(write_grant_head),
354#ifdef DEBUG
355	ATTR_LIST(log_badcrc_factor),
356#endif
357	NULL,
358};
359
360struct kobj_type xfs_log_ktype = {
361	.release = xfs_sysfs_release,
362	.sysfs_ops = &xfs_sysfs_ops,
363	.default_attrs = xfs_log_attrs,
364};