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)  * sysfs.c - sysfs support implementation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright (C) 2005-2014 Nippon Telegraph and Telephone Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Copyright (C) 2014 HGST, Inc., a Western Digital Company.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * Written by Vyacheslav Dubeyko <Vyacheslav.Dubeyko@hgst.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #include <linux/kobject.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include "nilfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include "mdt.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include "sufile.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include "cpfile.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include "sysfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) /* /sys/fs/<nilfs>/ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) static struct kset *nilfs_kset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #define NILFS_SHOW_TIME(time_t_val, buf) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) 		struct tm res; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) 		int count = 0; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) 		time64_to_tm(time_t_val, 0, &res); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) 		res.tm_year += 1900; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) 		res.tm_mon += 1; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) 		count = scnprintf(buf, PAGE_SIZE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) 				    "%ld-%.2d-%.2d %.2d:%.2d:%.2d\n", \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) 				    res.tm_year, res.tm_mon, res.tm_mday, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) 				    res.tm_hour, res.tm_min, res.tm_sec);\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) 		count; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #define NILFS_DEV_INT_GROUP_OPS(name, parent_name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) static ssize_t nilfs_##name##_attr_show(struct kobject *kobj, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) 					struct attribute *attr, char *buf) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 	struct the_nilfs *nilfs = container_of(kobj->parent, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 						struct the_nilfs, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 						ns_##parent_name##_kobj); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 	struct nilfs_##name##_attr *a = container_of(attr, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 						struct nilfs_##name##_attr, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 						attr); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 	return a->show ? a->show(a, nilfs, buf) : 0; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) static ssize_t nilfs_##name##_attr_store(struct kobject *kobj, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 					 struct attribute *attr, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 					 const char *buf, size_t len) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 	struct the_nilfs *nilfs = container_of(kobj->parent, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 						struct the_nilfs, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 						ns_##parent_name##_kobj); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 	struct nilfs_##name##_attr *a = container_of(attr, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 						struct nilfs_##name##_attr, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 						attr); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 	return a->store ? a->store(a, nilfs, buf, len) : 0; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) static const struct sysfs_ops nilfs_##name##_attr_ops = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 	.show	= nilfs_##name##_attr_show, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 	.store	= nilfs_##name##_attr_store, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) #define NILFS_DEV_INT_GROUP_TYPE(name, parent_name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) static void nilfs_##name##_attr_release(struct kobject *kobj) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 	struct nilfs_sysfs_##parent_name##_subgroups *subgroups = container_of(kobj, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 						struct nilfs_sysfs_##parent_name##_subgroups, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 						sg_##name##_kobj); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 	complete(&subgroups->sg_##name##_kobj_unregister); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) static struct kobj_type nilfs_##name##_ktype = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 	.default_attrs	= nilfs_##name##_attrs, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 	.sysfs_ops	= &nilfs_##name##_attr_ops, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 	.release	= nilfs_##name##_attr_release, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) #define NILFS_DEV_INT_GROUP_FNS(name, parent_name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) static int nilfs_sysfs_create_##name##_group(struct the_nilfs *nilfs) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 	struct kobject *parent; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 	struct kobject *kobj; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	struct completion *kobj_unregister; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 	struct nilfs_sysfs_##parent_name##_subgroups *subgroups; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	int err; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 	subgroups = nilfs->ns_##parent_name##_subgroups; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 	kobj = &subgroups->sg_##name##_kobj; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 	kobj_unregister = &subgroups->sg_##name##_kobj_unregister; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	parent = &nilfs->ns_##parent_name##_kobj; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 	kobj->kset = nilfs_kset; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 	init_completion(kobj_unregister); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 	err = kobject_init_and_add(kobj, &nilfs_##name##_ktype, parent, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 				    #name); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 	if (err) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 		kobject_put(kobj); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 	return err; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) static void nilfs_sysfs_delete_##name##_group(struct the_nilfs *nilfs) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 	kobject_put(&nilfs->ns_##parent_name##_subgroups->sg_##name##_kobj); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) /************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104)  *                        NILFS snapshot attrs                          *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105)  ************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) nilfs_snapshot_inodes_count_show(struct nilfs_snapshot_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 				 struct nilfs_root *root, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	return snprintf(buf, PAGE_SIZE, "%llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 			(unsigned long long)atomic64_read(&root->inodes_count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) nilfs_snapshot_blocks_count_show(struct nilfs_snapshot_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 				 struct nilfs_root *root, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	return snprintf(buf, PAGE_SIZE, "%llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 			(unsigned long long)atomic64_read(&root->blocks_count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) static const char snapshot_readme_str[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	"The group contains details about mounted snapshot.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	"(1) inodes_count\n\tshow number of inodes for snapshot.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	"(2) blocks_count\n\tshow number of blocks for snapshot.\n\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) nilfs_snapshot_README_show(struct nilfs_snapshot_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 			    struct nilfs_root *root, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	return snprintf(buf, PAGE_SIZE, snapshot_readme_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) NILFS_SNAPSHOT_RO_ATTR(inodes_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) NILFS_SNAPSHOT_RO_ATTR(blocks_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) NILFS_SNAPSHOT_RO_ATTR(README);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) static struct attribute *nilfs_snapshot_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	NILFS_SNAPSHOT_ATTR_LIST(inodes_count),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	NILFS_SNAPSHOT_ATTR_LIST(blocks_count),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	NILFS_SNAPSHOT_ATTR_LIST(README),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) static ssize_t nilfs_snapshot_attr_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 					struct attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	struct nilfs_root *root =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 			container_of(kobj, struct nilfs_root, snapshot_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	struct nilfs_snapshot_attr *a =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 			container_of(attr, struct nilfs_snapshot_attr, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	return a->show ? a->show(a, root, buf) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) static ssize_t nilfs_snapshot_attr_store(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 					 struct attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 					 const char *buf, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 	struct nilfs_root *root =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 			container_of(kobj, struct nilfs_root, snapshot_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	struct nilfs_snapshot_attr *a =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 			container_of(attr, struct nilfs_snapshot_attr, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	return a->store ? a->store(a, root, buf, len) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) static void nilfs_snapshot_attr_release(struct kobject *kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 	struct nilfs_root *root = container_of(kobj, struct nilfs_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 						snapshot_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	complete(&root->snapshot_kobj_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) static const struct sysfs_ops nilfs_snapshot_attr_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	.show	= nilfs_snapshot_attr_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	.store	= nilfs_snapshot_attr_store,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) static struct kobj_type nilfs_snapshot_ktype = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	.default_attrs	= nilfs_snapshot_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	.sysfs_ops	= &nilfs_snapshot_attr_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	.release	= nilfs_snapshot_attr_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) int nilfs_sysfs_create_snapshot_group(struct nilfs_root *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	struct the_nilfs *nilfs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	struct kobject *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	nilfs = root->nilfs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	parent = &nilfs->ns_dev_subgroups->sg_mounted_snapshots_kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	root->snapshot_kobj.kset = nilfs_kset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	init_completion(&root->snapshot_kobj_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	if (root->cno == NILFS_CPTREE_CURRENT_CNO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 		err = kobject_init_and_add(&root->snapshot_kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 					    &nilfs_snapshot_ktype,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 					    &nilfs->ns_dev_kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 					    "current_checkpoint");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 		err = kobject_init_and_add(&root->snapshot_kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 					    &nilfs_snapshot_ktype,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 					    parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 					    "%llu", root->cno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 		kobject_put(&root->snapshot_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) void nilfs_sysfs_delete_snapshot_group(struct nilfs_root *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	kobject_put(&root->snapshot_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) /************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222)  *                    NILFS mounted snapshots attrs                     *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223)  ************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) static const char mounted_snapshots_readme_str[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	"The mounted_snapshots group contains group for\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	"every mounted snapshot.\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) nilfs_mounted_snapshots_README_show(struct nilfs_mounted_snapshots_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 				    struct the_nilfs *nilfs, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	return snprintf(buf, PAGE_SIZE, mounted_snapshots_readme_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) NILFS_MOUNTED_SNAPSHOTS_RO_ATTR(README);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) static struct attribute *nilfs_mounted_snapshots_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	NILFS_MOUNTED_SNAPSHOTS_ATTR_LIST(README),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) NILFS_DEV_INT_GROUP_OPS(mounted_snapshots, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) NILFS_DEV_INT_GROUP_TYPE(mounted_snapshots, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) NILFS_DEV_INT_GROUP_FNS(mounted_snapshots, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) /************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248)  *                      NILFS checkpoints attrs                         *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249)  ************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) nilfs_checkpoints_checkpoints_number_show(struct nilfs_checkpoints_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 					    struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 					    char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	__u64 ncheckpoints;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	struct nilfs_cpstat cpstat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	down_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	err = nilfs_cpfile_get_stat(nilfs->ns_cpfile, &cpstat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	up_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 		nilfs_err(nilfs->ns_sb, "unable to get checkpoint stat: err=%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 			  err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	ncheckpoints = cpstat.cs_ncps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	return snprintf(buf, PAGE_SIZE, "%llu\n", ncheckpoints);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) nilfs_checkpoints_snapshots_number_show(struct nilfs_checkpoints_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 					struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 					char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	__u64 nsnapshots;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	struct nilfs_cpstat cpstat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	down_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	err = nilfs_cpfile_get_stat(nilfs->ns_cpfile, &cpstat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	up_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 		nilfs_err(nilfs->ns_sb, "unable to get checkpoint stat: err=%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 			  err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	nsnapshots = cpstat.cs_nsss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	return snprintf(buf, PAGE_SIZE, "%llu\n", nsnapshots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) nilfs_checkpoints_last_seg_checkpoint_show(struct nilfs_checkpoints_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 					    struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 					    char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	__u64 last_cno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	spin_lock(&nilfs->ns_last_segment_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	last_cno = nilfs->ns_last_cno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	spin_unlock(&nilfs->ns_last_segment_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	return snprintf(buf, PAGE_SIZE, "%llu\n", last_cno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) nilfs_checkpoints_next_checkpoint_show(struct nilfs_checkpoints_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 					struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 					char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	__u64 cno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	down_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	cno = nilfs->ns_cno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	up_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	return snprintf(buf, PAGE_SIZE, "%llu\n", cno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) static const char checkpoints_readme_str[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	"The checkpoints group contains attributes that describe\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	"details about volume's checkpoints.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	"(1) checkpoints_number\n\tshow number of checkpoints on volume.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	"(2) snapshots_number\n\tshow number of snapshots on volume.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	"(3) last_seg_checkpoint\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	"\tshow checkpoint number of the latest segment.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	"(4) next_checkpoint\n\tshow next checkpoint number.\n\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) nilfs_checkpoints_README_show(struct nilfs_checkpoints_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 				struct the_nilfs *nilfs, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	return snprintf(buf, PAGE_SIZE, checkpoints_readme_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) NILFS_CHECKPOINTS_RO_ATTR(checkpoints_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) NILFS_CHECKPOINTS_RO_ATTR(snapshots_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) NILFS_CHECKPOINTS_RO_ATTR(last_seg_checkpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) NILFS_CHECKPOINTS_RO_ATTR(next_checkpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) NILFS_CHECKPOINTS_RO_ATTR(README);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) static struct attribute *nilfs_checkpoints_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	NILFS_CHECKPOINTS_ATTR_LIST(checkpoints_number),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	NILFS_CHECKPOINTS_ATTR_LIST(snapshots_number),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	NILFS_CHECKPOINTS_ATTR_LIST(last_seg_checkpoint),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 	NILFS_CHECKPOINTS_ATTR_LIST(next_checkpoint),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	NILFS_CHECKPOINTS_ATTR_LIST(README),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) NILFS_DEV_INT_GROUP_OPS(checkpoints, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) NILFS_DEV_INT_GROUP_TYPE(checkpoints, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) NILFS_DEV_INT_GROUP_FNS(checkpoints, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) /************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361)  *                        NILFS segments attrs                          *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362)  ************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) nilfs_segments_segments_number_show(struct nilfs_segments_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 				     struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 				     char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 	return snprintf(buf, PAGE_SIZE, "%lu\n", nilfs->ns_nsegments);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) nilfs_segments_blocks_per_segment_show(struct nilfs_segments_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 					struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 					char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	return snprintf(buf, PAGE_SIZE, "%lu\n", nilfs->ns_blocks_per_segment);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) nilfs_segments_clean_segments_show(struct nilfs_segments_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 				    struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 				    char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 	unsigned long ncleansegs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	down_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	ncleansegs = nilfs_sufile_get_ncleansegs(nilfs->ns_sufile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	up_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	return snprintf(buf, PAGE_SIZE, "%lu\n", ncleansegs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) nilfs_segments_dirty_segments_show(struct nilfs_segments_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 				    struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 				    char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	struct nilfs_sustat sustat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	down_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	err = nilfs_sufile_get_stat(nilfs->ns_sufile, &sustat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	up_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 		nilfs_err(nilfs->ns_sb, "unable to get segment stat: err=%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 			  err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 	return snprintf(buf, PAGE_SIZE, "%llu\n", sustat.ss_ndirtysegs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) static const char segments_readme_str[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 	"The segments group contains attributes that describe\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	"details about volume's segments.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	"(1) segments_number\n\tshow number of segments on volume.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	"(2) blocks_per_segment\n\tshow number of blocks in segment.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	"(3) clean_segments\n\tshow count of clean segments.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	"(4) dirty_segments\n\tshow count of dirty segments.\n\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) nilfs_segments_README_show(struct nilfs_segments_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 			    struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 			    char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	return snprintf(buf, PAGE_SIZE, segments_readme_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) NILFS_SEGMENTS_RO_ATTR(segments_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) NILFS_SEGMENTS_RO_ATTR(blocks_per_segment);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) NILFS_SEGMENTS_RO_ATTR(clean_segments);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) NILFS_SEGMENTS_RO_ATTR(dirty_segments);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) NILFS_SEGMENTS_RO_ATTR(README);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) static struct attribute *nilfs_segments_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	NILFS_SEGMENTS_ATTR_LIST(segments_number),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	NILFS_SEGMENTS_ATTR_LIST(blocks_per_segment),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	NILFS_SEGMENTS_ATTR_LIST(clean_segments),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	NILFS_SEGMENTS_ATTR_LIST(dirty_segments),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	NILFS_SEGMENTS_ATTR_LIST(README),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) NILFS_DEV_INT_GROUP_OPS(segments, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) NILFS_DEV_INT_GROUP_TYPE(segments, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) NILFS_DEV_INT_GROUP_FNS(segments, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) /************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450)  *                        NILFS segctor attrs                           *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451)  ************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) nilfs_segctor_last_pseg_block_show(struct nilfs_segctor_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 				    struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 				    char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	sector_t last_pseg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	spin_lock(&nilfs->ns_last_segment_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	last_pseg = nilfs->ns_last_pseg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	spin_unlock(&nilfs->ns_last_segment_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	return snprintf(buf, PAGE_SIZE, "%llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 			(unsigned long long)last_pseg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) nilfs_segctor_last_seg_sequence_show(struct nilfs_segctor_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 					struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 					char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	u64 last_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	spin_lock(&nilfs->ns_last_segment_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	last_seq = nilfs->ns_last_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	spin_unlock(&nilfs->ns_last_segment_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	return snprintf(buf, PAGE_SIZE, "%llu\n", last_seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) nilfs_segctor_last_seg_checkpoint_show(struct nilfs_segctor_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 					struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 					char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 	__u64 last_cno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	spin_lock(&nilfs->ns_last_segment_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	last_cno = nilfs->ns_last_cno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	spin_unlock(&nilfs->ns_last_segment_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	return snprintf(buf, PAGE_SIZE, "%llu\n", last_cno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) nilfs_segctor_current_seg_sequence_show(struct nilfs_segctor_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 					struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 					char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	u64 seg_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	down_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	seg_seq = nilfs->ns_seg_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	up_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	return snprintf(buf, PAGE_SIZE, "%llu\n", seg_seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) nilfs_segctor_current_last_full_seg_show(struct nilfs_segctor_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 					 struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 					 char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	__u64 segnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	down_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	segnum = nilfs->ns_segnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	up_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	return snprintf(buf, PAGE_SIZE, "%llu\n", segnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) nilfs_segctor_next_full_seg_show(struct nilfs_segctor_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 				 struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 				 char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	__u64 nextnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	down_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	nextnum = nilfs->ns_nextnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	up_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	return snprintf(buf, PAGE_SIZE, "%llu\n", nextnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) nilfs_segctor_next_pseg_offset_show(struct nilfs_segctor_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 					struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 					char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 	unsigned long pseg_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	down_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	pseg_offset = nilfs->ns_pseg_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	up_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	return snprintf(buf, PAGE_SIZE, "%lu\n", pseg_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) nilfs_segctor_next_checkpoint_show(struct nilfs_segctor_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 					struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 					char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	__u64 cno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	down_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	cno = nilfs->ns_cno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	up_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	return snprintf(buf, PAGE_SIZE, "%llu\n", cno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) nilfs_segctor_last_seg_write_time_show(struct nilfs_segctor_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 					struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 					char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	time64_t ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	down_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	ctime = nilfs->ns_ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	up_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	return NILFS_SHOW_TIME(ctime, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) nilfs_segctor_last_seg_write_time_secs_show(struct nilfs_segctor_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 					    struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 					    char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	time64_t ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	down_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	ctime = nilfs->ns_ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	up_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	return snprintf(buf, PAGE_SIZE, "%llu\n", ctime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) nilfs_segctor_last_nongc_write_time_show(struct nilfs_segctor_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 					 struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 					 char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	time64_t nongc_ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	down_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	nongc_ctime = nilfs->ns_nongc_ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	up_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	return NILFS_SHOW_TIME(nongc_ctime, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) nilfs_segctor_last_nongc_write_time_secs_show(struct nilfs_segctor_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 						struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 						char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	time64_t nongc_ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	down_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	nongc_ctime = nilfs->ns_nongc_ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	up_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	return snprintf(buf, PAGE_SIZE, "%llu\n", nongc_ctime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) nilfs_segctor_dirty_data_blocks_count_show(struct nilfs_segctor_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 					    struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 					    char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	u32 ndirtyblks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	down_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	ndirtyblks = atomic_read(&nilfs->ns_ndirtyblks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	up_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	return snprintf(buf, PAGE_SIZE, "%u\n", ndirtyblks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) static const char segctor_readme_str[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	"The segctor group contains attributes that describe\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	"segctor thread activity details.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	"(1) last_pseg_block\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	"\tshow start block number of the latest segment.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	"(2) last_seg_sequence\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	"\tshow sequence value of the latest segment.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	"(3) last_seg_checkpoint\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	"\tshow checkpoint number of the latest segment.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	"(4) current_seg_sequence\n\tshow segment sequence counter.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	"(5) current_last_full_seg\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	"\tshow index number of the latest full segment.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	"(6) next_full_seg\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	"\tshow index number of the full segment index to be used next.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	"(7) next_pseg_offset\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	"\tshow offset of next partial segment in the current full segment.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	"(8) next_checkpoint\n\tshow next checkpoint number.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	"(9) last_seg_write_time\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	"\tshow write time of the last segment in human-readable format.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	"(10) last_seg_write_time_secs\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	"\tshow write time of the last segment in seconds.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	"(11) last_nongc_write_time\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	"\tshow write time of the last segment not for cleaner operation "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	"in human-readable format.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	"(12) last_nongc_write_time_secs\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	"\tshow write time of the last segment not for cleaner operation "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	"in seconds.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	"(13) dirty_data_blocks_count\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	"\tshow number of dirty data blocks.\n\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) nilfs_segctor_README_show(struct nilfs_segctor_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 			  struct the_nilfs *nilfs, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	return snprintf(buf, PAGE_SIZE, segctor_readme_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) NILFS_SEGCTOR_RO_ATTR(last_pseg_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) NILFS_SEGCTOR_RO_ATTR(last_seg_sequence);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) NILFS_SEGCTOR_RO_ATTR(last_seg_checkpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) NILFS_SEGCTOR_RO_ATTR(current_seg_sequence);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) NILFS_SEGCTOR_RO_ATTR(current_last_full_seg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) NILFS_SEGCTOR_RO_ATTR(next_full_seg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) NILFS_SEGCTOR_RO_ATTR(next_pseg_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) NILFS_SEGCTOR_RO_ATTR(next_checkpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) NILFS_SEGCTOR_RO_ATTR(last_seg_write_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) NILFS_SEGCTOR_RO_ATTR(last_seg_write_time_secs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) NILFS_SEGCTOR_RO_ATTR(last_nongc_write_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) NILFS_SEGCTOR_RO_ATTR(last_nongc_write_time_secs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) NILFS_SEGCTOR_RO_ATTR(dirty_data_blocks_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) NILFS_SEGCTOR_RO_ATTR(README);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) static struct attribute *nilfs_segctor_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	NILFS_SEGCTOR_ATTR_LIST(last_pseg_block),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	NILFS_SEGCTOR_ATTR_LIST(last_seg_sequence),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 	NILFS_SEGCTOR_ATTR_LIST(last_seg_checkpoint),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 	NILFS_SEGCTOR_ATTR_LIST(current_seg_sequence),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	NILFS_SEGCTOR_ATTR_LIST(current_last_full_seg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	NILFS_SEGCTOR_ATTR_LIST(next_full_seg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	NILFS_SEGCTOR_ATTR_LIST(next_pseg_offset),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	NILFS_SEGCTOR_ATTR_LIST(next_checkpoint),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	NILFS_SEGCTOR_ATTR_LIST(last_seg_write_time),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	NILFS_SEGCTOR_ATTR_LIST(last_seg_write_time_secs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	NILFS_SEGCTOR_ATTR_LIST(last_nongc_write_time),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	NILFS_SEGCTOR_ATTR_LIST(last_nongc_write_time_secs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	NILFS_SEGCTOR_ATTR_LIST(dirty_data_blocks_count),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	NILFS_SEGCTOR_ATTR_LIST(README),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) NILFS_DEV_INT_GROUP_OPS(segctor, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) NILFS_DEV_INT_GROUP_TYPE(segctor, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) NILFS_DEV_INT_GROUP_FNS(segctor, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) /************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711)  *                        NILFS superblock attrs                        *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712)  ************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) nilfs_superblock_sb_write_time_show(struct nilfs_superblock_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 				     struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 				     char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	time64_t sbwtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	down_read(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	sbwtime = nilfs->ns_sbwtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	up_read(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	return NILFS_SHOW_TIME(sbwtime, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) nilfs_superblock_sb_write_time_secs_show(struct nilfs_superblock_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 					 struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 					 char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	time64_t sbwtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	down_read(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	sbwtime = nilfs->ns_sbwtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	up_read(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	return snprintf(buf, PAGE_SIZE, "%llu\n", sbwtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) nilfs_superblock_sb_write_count_show(struct nilfs_superblock_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 				      struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 				      char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	unsigned int sbwcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	down_read(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 	sbwcount = nilfs->ns_sbwcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	up_read(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	return snprintf(buf, PAGE_SIZE, "%u\n", sbwcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) nilfs_superblock_sb_update_frequency_show(struct nilfs_superblock_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 					    struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 					    char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 	unsigned int sb_update_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	down_read(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	sb_update_freq = nilfs->ns_sb_update_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	up_read(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	return snprintf(buf, PAGE_SIZE, "%u\n", sb_update_freq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) nilfs_superblock_sb_update_frequency_store(struct nilfs_superblock_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 					    struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 					    const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	err = kstrtouint(skip_spaces(buf), 0, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 		nilfs_err(nilfs->ns_sb, "unable to convert string: err=%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 			  err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	if (val < NILFS_SB_FREQ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 		val = NILFS_SB_FREQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 		nilfs_warn(nilfs->ns_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 			   "superblock update frequency cannot be lesser than 10 seconds");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	down_write(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	nilfs->ns_sb_update_freq = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	up_write(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) static const char sb_readme_str[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	"The superblock group contains attributes that describe\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	"superblock's details.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	"(1) sb_write_time\n\tshow previous write time of super block "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	"in human-readable format.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	"(2) sb_write_time_secs\n\tshow previous write time of super block "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	"in seconds.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	"(3) sb_write_count\n\tshow write count of super block.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	"(4) sb_update_frequency\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	"\tshow/set interval of periodical update of superblock (in seconds).\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	"\tYou can set preferable frequency of superblock update by command:\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	"\t'echo <val> > /sys/fs/<nilfs>/<dev>/superblock/sb_update_frequency'\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) nilfs_superblock_README_show(struct nilfs_superblock_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 				struct the_nilfs *nilfs, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	return snprintf(buf, PAGE_SIZE, sb_readme_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) NILFS_SUPERBLOCK_RO_ATTR(sb_write_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) NILFS_SUPERBLOCK_RO_ATTR(sb_write_time_secs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) NILFS_SUPERBLOCK_RO_ATTR(sb_write_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) NILFS_SUPERBLOCK_RW_ATTR(sb_update_frequency);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) NILFS_SUPERBLOCK_RO_ATTR(README);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) static struct attribute *nilfs_superblock_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	NILFS_SUPERBLOCK_ATTR_LIST(sb_write_time),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	NILFS_SUPERBLOCK_ATTR_LIST(sb_write_time_secs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	NILFS_SUPERBLOCK_ATTR_LIST(sb_write_count),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	NILFS_SUPERBLOCK_ATTR_LIST(sb_update_frequency),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	NILFS_SUPERBLOCK_ATTR_LIST(README),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) NILFS_DEV_INT_GROUP_OPS(superblock, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) NILFS_DEV_INT_GROUP_TYPE(superblock, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) NILFS_DEV_INT_GROUP_FNS(superblock, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) /************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838)  *                        NILFS device attrs                            *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839)  ************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) ssize_t nilfs_dev_revision_show(struct nilfs_dev_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 				struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 				char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	struct nilfs_super_block **sbp = nilfs->ns_sbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	u32 major = le32_to_cpu(sbp[0]->s_rev_level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	u16 minor = le16_to_cpu(sbp[0]->s_minor_rev_level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	return snprintf(buf, PAGE_SIZE, "%d.%d\n", major, minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) ssize_t nilfs_dev_blocksize_show(struct nilfs_dev_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 				 struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 				 char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	return snprintf(buf, PAGE_SIZE, "%u\n", nilfs->ns_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) ssize_t nilfs_dev_device_size_show(struct nilfs_dev_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 				    struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 				    char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	struct nilfs_super_block **sbp = nilfs->ns_sbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	u64 dev_size = le64_to_cpu(sbp[0]->s_dev_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	return snprintf(buf, PAGE_SIZE, "%llu\n", dev_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) ssize_t nilfs_dev_free_blocks_show(struct nilfs_dev_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 				   struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 				   char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	sector_t free_blocks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	nilfs_count_free_blocks(nilfs, &free_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	return snprintf(buf, PAGE_SIZE, "%llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 			(unsigned long long)free_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) ssize_t nilfs_dev_uuid_show(struct nilfs_dev_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 			    struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 			    char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	struct nilfs_super_block **sbp = nilfs->ns_sbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	return snprintf(buf, PAGE_SIZE, "%pUb\n", sbp[0]->s_uuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) ssize_t nilfs_dev_volume_name_show(struct nilfs_dev_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 				    struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 				    char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	struct nilfs_super_block **sbp = nilfs->ns_sbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	return scnprintf(buf, sizeof(sbp[0]->s_volume_name), "%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 			 sbp[0]->s_volume_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) static const char dev_readme_str[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	"The <device> group contains attributes that describe file system\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	"partition's details.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	"(1) revision\n\tshow NILFS file system revision.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	"(2) blocksize\n\tshow volume block size in bytes.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	"(3) device_size\n\tshow volume size in bytes.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	"(4) free_blocks\n\tshow count of free blocks on volume.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	"(5) uuid\n\tshow volume's UUID.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	"(6) volume_name\n\tshow volume's name.\n\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) static ssize_t nilfs_dev_README_show(struct nilfs_dev_attr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 				     struct the_nilfs *nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 				     char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	return snprintf(buf, PAGE_SIZE, dev_readme_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) NILFS_DEV_RO_ATTR(revision);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) NILFS_DEV_RO_ATTR(blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) NILFS_DEV_RO_ATTR(device_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) NILFS_DEV_RO_ATTR(free_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) NILFS_DEV_RO_ATTR(uuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) NILFS_DEV_RO_ATTR(volume_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) NILFS_DEV_RO_ATTR(README);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) static struct attribute *nilfs_dev_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	NILFS_DEV_ATTR_LIST(revision),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	NILFS_DEV_ATTR_LIST(blocksize),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	NILFS_DEV_ATTR_LIST(device_size),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	NILFS_DEV_ATTR_LIST(free_blocks),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	NILFS_DEV_ATTR_LIST(uuid),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	NILFS_DEV_ATTR_LIST(volume_name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	NILFS_DEV_ATTR_LIST(README),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) static ssize_t nilfs_dev_attr_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 				    struct attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	struct the_nilfs *nilfs = container_of(kobj, struct the_nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 						ns_dev_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	struct nilfs_dev_attr *a = container_of(attr, struct nilfs_dev_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 						attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	return a->show ? a->show(a, nilfs, buf) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) static ssize_t nilfs_dev_attr_store(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 				    struct attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 				    const char *buf, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	struct the_nilfs *nilfs = container_of(kobj, struct the_nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 						ns_dev_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	struct nilfs_dev_attr *a = container_of(attr, struct nilfs_dev_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 						attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	return a->store ? a->store(a, nilfs, buf, len) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) static void nilfs_dev_attr_release(struct kobject *kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	struct the_nilfs *nilfs = container_of(kobj, struct the_nilfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 						ns_dev_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	complete(&nilfs->ns_dev_kobj_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) static const struct sysfs_ops nilfs_dev_attr_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	.show	= nilfs_dev_attr_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	.store	= nilfs_dev_attr_store,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) static struct kobj_type nilfs_dev_ktype = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	.default_attrs	= nilfs_dev_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 	.sysfs_ops	= &nilfs_dev_attr_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	.release	= nilfs_dev_attr_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) int nilfs_sysfs_create_device_group(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	struct the_nilfs *nilfs = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	size_t devgrp_size = sizeof(struct nilfs_sysfs_dev_subgroups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 	nilfs->ns_dev_subgroups = kzalloc(devgrp_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	if (unlikely(!nilfs->ns_dev_subgroups)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 		err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 		nilfs_err(sb, "unable to allocate memory for device group");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 		goto failed_create_device_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	nilfs->ns_dev_kobj.kset = nilfs_kset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	init_completion(&nilfs->ns_dev_kobj_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	err = kobject_init_and_add(&nilfs->ns_dev_kobj, &nilfs_dev_ktype, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 				    "%s", sb->s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 		goto cleanup_dev_kobject;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	err = nilfs_sysfs_create_mounted_snapshots_group(nilfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 		goto cleanup_dev_kobject;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	err = nilfs_sysfs_create_checkpoints_group(nilfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 		goto delete_mounted_snapshots_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	err = nilfs_sysfs_create_segments_group(nilfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 		goto delete_checkpoints_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	err = nilfs_sysfs_create_superblock_group(nilfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 		goto delete_segments_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	err = nilfs_sysfs_create_segctor_group(nilfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 		goto delete_superblock_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) delete_superblock_group:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	nilfs_sysfs_delete_superblock_group(nilfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) delete_segments_group:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	nilfs_sysfs_delete_segments_group(nilfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) delete_checkpoints_group:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	nilfs_sysfs_delete_checkpoints_group(nilfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) delete_mounted_snapshots_group:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	nilfs_sysfs_delete_mounted_snapshots_group(nilfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) cleanup_dev_kobject:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	kobject_put(&nilfs->ns_dev_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 	kfree(nilfs->ns_dev_subgroups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) failed_create_device_group:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) void nilfs_sysfs_delete_device_group(struct the_nilfs *nilfs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	nilfs_sysfs_delete_mounted_snapshots_group(nilfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	nilfs_sysfs_delete_checkpoints_group(nilfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	nilfs_sysfs_delete_segments_group(nilfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	nilfs_sysfs_delete_superblock_group(nilfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	nilfs_sysfs_delete_segctor_group(nilfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	kobject_del(&nilfs->ns_dev_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	kobject_put(&nilfs->ns_dev_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	kfree(nilfs->ns_dev_subgroups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) /************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057)  *                        NILFS feature attrs                           *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058)  ************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) static ssize_t nilfs_feature_revision_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 					    struct attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	return snprintf(buf, PAGE_SIZE, "%d.%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 			NILFS_CURRENT_REV, NILFS_MINOR_REV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) static const char features_readme_str[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	"The features group contains attributes that describe NILFS file\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	"system driver features.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	"(1) revision\n\tshow current revision of NILFS file system driver.\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) static ssize_t nilfs_feature_README_show(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 					 struct attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 					 char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	return snprintf(buf, PAGE_SIZE, features_readme_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) NILFS_FEATURE_RO_ATTR(revision);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) NILFS_FEATURE_RO_ATTR(README);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) static struct attribute *nilfs_feature_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	NILFS_FEATURE_ATTR_LIST(revision),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	NILFS_FEATURE_ATTR_LIST(README),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) static const struct attribute_group nilfs_feature_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	.name = "features",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	.attrs = nilfs_feature_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) int __init nilfs_sysfs_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	nilfs_kset = kset_create_and_add(NILFS_ROOT_GROUP_NAME, NULL, fs_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	if (!nilfs_kset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 		err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 		nilfs_err(NULL, "unable to create sysfs entry: err=%d", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 		goto failed_sysfs_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	err = sysfs_create_group(&nilfs_kset->kobj, &nilfs_feature_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	if (unlikely(err)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 		nilfs_err(NULL, "unable to create feature group: err=%d", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 		goto cleanup_sysfs_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) cleanup_sysfs_init:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	kset_unregister(nilfs_kset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) failed_sysfs_init:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) void nilfs_sysfs_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 	sysfs_remove_group(&nilfs_kset->kobj, &nilfs_feature_attr_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	kset_unregister(nilfs_kset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) }