Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright 2021 Google LLC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/kobject.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <uapi/linux/incrementalfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include "sysfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "data_mgmt.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "vfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * Define sys/fs/incrementalfs & sys/fs/incrementalfs/features
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #define INCFS_NODE_FEATURES "features"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define INCFS_NODE_INSTANCES "instances"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) static struct kobject *sysfs_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static struct kobject *features_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static struct kobject *instances_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define DECLARE_FEATURE_FLAG(name)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	static ssize_t name##_show(struct kobject *kobj,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 			 struct kobj_attribute *attr, char *buff)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	return sysfs_emit(buff, "supported\n");				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) }									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static struct kobj_attribute name##_attr = __ATTR_RO(name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) DECLARE_FEATURE_FLAG(corefs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) DECLARE_FEATURE_FLAG(zstd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) DECLARE_FEATURE_FLAG(v2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static struct attribute *attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	&corefs_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	&zstd_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	&v2_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static const struct attribute_group attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	.attrs = attributes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) int __init incfs_init_sysfs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	int res = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	sysfs_root = kobject_create_and_add(INCFS_NAME, fs_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	if (!sysfs_root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	instances_node = kobject_create_and_add(INCFS_NODE_INSTANCES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 						sysfs_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	if (!instances_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		goto err_put_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	features_node = kobject_create_and_add(INCFS_NODE_FEATURES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 						sysfs_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	if (!features_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		goto err_put_instances;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	res = sysfs_create_group(features_node, &attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		goto err_put_features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) err_put_features:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	kobject_put(features_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) err_put_instances:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	kobject_put(instances_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) err_put_root:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	kobject_put(sysfs_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) void incfs_cleanup_sysfs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	if (features_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		sysfs_remove_group(features_node, &attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		kobject_put(features_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	kobject_put(instances_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	kobject_put(sysfs_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  * Define sys/fs/incrementalfs/instances/<name>/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  *****************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) #define __DECLARE_STATUS_FLAG(name)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) static ssize_t name##_show(struct kobject *kobj,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			 struct kobj_attribute *attr, char *buff)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	struct incfs_sysfs_node *node = container_of(kobj,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			struct incfs_sysfs_node, isn_sysfs_node);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	return sysfs_emit(buff, "%d\n", node->isn_mi->mi_##name);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static struct kobj_attribute name##_attr = __ATTR_RO(name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #define __DECLARE_STATUS_FLAG64(name)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static ssize_t name##_show(struct kobject *kobj,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			 struct kobj_attribute *attr, char *buff)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	struct incfs_sysfs_node *node = container_of(kobj,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			struct incfs_sysfs_node, isn_sysfs_node);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	return sysfs_emit(buff, "%lld\n", node->isn_mi->mi_##name);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static struct kobj_attribute name##_attr = __ATTR_RO(name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) __DECLARE_STATUS_FLAG(reads_failed_timed_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) __DECLARE_STATUS_FLAG(reads_failed_hash_verification);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) __DECLARE_STATUS_FLAG(reads_failed_other);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) __DECLARE_STATUS_FLAG(reads_delayed_pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) __DECLARE_STATUS_FLAG64(reads_delayed_pending_us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) __DECLARE_STATUS_FLAG(reads_delayed_min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) __DECLARE_STATUS_FLAG64(reads_delayed_min_us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static struct attribute *mount_attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	&reads_failed_timed_out_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	&reads_failed_hash_verification_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	&reads_failed_other_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	&reads_delayed_pending_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	&reads_delayed_pending_us_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	&reads_delayed_min_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	&reads_delayed_min_us_attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) static void incfs_sysfs_release(struct kobject *kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	struct incfs_sysfs_node *node = container_of(kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 				struct incfs_sysfs_node, isn_sysfs_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	complete(&node->isn_completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static const struct attribute_group mount_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	.attrs = mount_attributes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static struct kobj_type incfs_kobj_node_ktype = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	.sysfs_ops	= &kobj_sysfs_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	.release	= &incfs_sysfs_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) struct incfs_sysfs_node *incfs_add_sysfs_node(const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 					      struct mount_info *mi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	struct incfs_sysfs_node *node = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	if (!name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	node = kzalloc(sizeof(*node), GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	if (!node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	node->isn_mi = mi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	init_completion(&node->isn_completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	kobject_init(&node->isn_sysfs_node, &incfs_kobj_node_ktype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	error = kobject_add(&node->isn_sysfs_node, instances_node, "%s", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	error = sysfs_create_group(&node->isn_sysfs_node, &mount_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	return node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	 * Note kobject_put always calls release, so incfs_sysfs_release will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	 * free node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	kobject_put(&node->isn_sysfs_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	return ERR_PTR(error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) void incfs_free_sysfs_node(struct incfs_sysfs_node *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	if (!node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	sysfs_remove_group(&node->isn_sysfs_node, &mount_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	kobject_put(&node->isn_sysfs_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	wait_for_completion_interruptible(&node->isn_completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	kfree(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }