fs/xfs/xfs_error.c

Source file repositories/reference/linux-study-clean/fs/xfs/xfs_error.c

File Facts

System
Linux kernel
Corpus path
fs/xfs/xfs_error.c
Extension
.c
Size
8546 bytes
Lines
386
Domain
Core OS
Bucket
VFS And Filesystem Core
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

struct xfs_errortag_attr {
	struct attribute	attr;
	unsigned int		tag;
};

static inline struct xfs_errortag_attr *
to_attr(struct attribute *attr)
{
	return container_of(attr, struct xfs_errortag_attr, attr);
}

static inline struct xfs_mount *
to_mp(struct kobject *kobject)
{
	struct xfs_kobj *kobj = to_kobj(kobject);

	return container_of(kobj, struct xfs_mount, m_errortag_kobj);
}

STATIC ssize_t
xfs_errortag_attr_store(
	struct kobject		*kobject,
	struct attribute	*attr,
	const char		*buf,
	size_t			count)
{
	struct xfs_mount	*mp = to_mp(kobject);
	unsigned int		error_tag = to_attr(attr)->tag;
	unsigned int		val;
	int			ret;

	if (strcmp(buf, "default") == 0) {
		val = xfs_errortag_random_default[error_tag];
	} else {
		ret = kstrtouint(buf, 0, &val);
		if (ret)
			return ret;
	}

	WRITE_ONCE(mp->m_errortag[error_tag], val);
	return count;
}

STATIC ssize_t
xfs_errortag_attr_show(
	struct kobject		*kobject,
	struct attribute	*attr,
	char			*buf)
{
	struct xfs_mount	*mp = to_mp(kobject);

	return snprintf(buf, PAGE_SIZE, "%u\n",
			READ_ONCE(mp->m_errortag[to_attr(attr)->tag]));
}

static const struct sysfs_ops xfs_errortag_sysfs_ops = {
	.show = xfs_errortag_attr_show,
	.store = xfs_errortag_attr_store,
};

#define XFS_ERRTAG(_tag, _name, _default)				\
static struct xfs_errortag_attr xfs_errortag_attr_##_name = {		\
	.attr = {.name = __stringify(_name),				\
		 .mode = VERIFY_OCTAL_PERMISSIONS(S_IWUSR | S_IRUGO) },	\
	.tag	= XFS_ERRTAG_##_tag,					\
};
#include "xfs_errortag.h"
XFS_ERRTAGS
#undef XFS_ERRTAG

#define XFS_ERRTAG(_tag, _name, _default) \
	&xfs_errortag_attr_##_name.attr,
#include "xfs_errortag.h"
static struct attribute *xfs_errortag_attrs[] = {
	XFS_ERRTAGS
	NULL
};
ATTRIBUTE_GROUPS(xfs_errortag);
#undef XFS_ERRTAG

/* -1 because XFS_ERRTAG_DROP_WRITES got removed, + 1 for NULL termination */
static_assert(ARRAY_SIZE(xfs_errortag_attrs) == XFS_ERRTAG_MAX);

static const struct kobj_type xfs_errortag_ktype = {
	.release = xfs_sysfs_release,
	.sysfs_ops = &xfs_errortag_sysfs_ops,
	.default_groups = xfs_errortag_groups,
};

int

Annotation

Implementation Notes