reboot: sysfs improvements
cover reboot: sysfs improvements
From: Matteo Croce <[email protected]>
Some improvements to the sysfs reboot interface: hide not working settings and support machines with known reboot quirks.
Matteo Croce (2):
reboot: allow to override reboot type if quirks are found
reboot: hide from sysfs not applicable settings
kernel/reboot.c | 58 ++++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 22 deletions(-)
Signature · 1 line
2.28.0
PATCH 1/2 reboot: allow to override reboot type if quirks are found
From: Matteo Croce <[email protected]>
On some machines a quirk can force a specific reboot type. Quirks are found during a DMI scan, the list of machines which need special reboot handling is defined in reboot_dmi_table.
The kernel command line reboot= option overrides this via a global variable reboot_default, so that the reboot type requested in the command line is really performed.
This was not true when setting the reboot type via the new sysfs interface. Fix this by setting reboot_default upon the first change, like reboot_setup() does for the command line.
--- kernel/reboot.c | 6 ++++++ 1 file changed, 6 insertions(+)
kernel/reboot.c +6 -0
@@ -656,6 +656,8 @@ static ssize_t mode_store(struct kobject *kobj, struct kobj_attribute *attr,else return -EINVAL ; + reboot_default =0 ; +return count; }static struct kobj_attribute reboot_mode_attr =__ATTR_RW (mode);
@@ -710,6 +712,8 @@ static ssize_t type_store(struct kobject *kobj, struct kobj_attribute *attr,else return -EINVAL ; + reboot_default =0 ; +return count; }static struct kobj_attribute reboot_type_attr =__ATTR_RW (type);
@@ -735,6 +739,7 @@ static ssize_t cpu_store(struct kobject *kobj, struct kobj_attribute *attr,if (cpunum >=num_possible_cpus ())return -ERANGE ; + reboot_default =0 ; reboot_cpu = cpunum;return count;
@@ -756,6 +761,7 @@ static ssize_t force_store(struct kobject *kobj, struct kobj_attribute *attr,if (kstrtobool (buf, &res))return -EINVAL ; + reboot_default =0 ; reboot_force = res;return count;
Signature · 1 line
2.28.0
PATCH 2/2 reboot: hide from sysfs not applicable settings
In reply to Matteo CroceFrom: Matteo Croce <[email protected]>
Not all the reboot settings from both the kernel command line or sysfs interface are available to all platforms.
Filter out reboot_type and reboot_force which are x86 only, and also remove reboot_cpu on kernels without SMP support.
This saves some space, and avoid confusing the user with settings which will have no effect.
--- kernel/reboot.c | 54 ++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 23 deletions(-)
kernel/reboot.c +31 -23
@@ -662,6 +662,29 @@ static ssize_t mode_store(struct kobject *kobj, struct kobj_attribute *attr, }static struct kobj_attribute reboot_mode_attr =__ATTR_RW (mode); +#ifdef CONFIG_X86 +static ssize_t force_show (struct kobject *kobj,struct kobj_attribute *attr,char *buf) +{ +return sprintf (buf,"%d\n" , reboot_force); +} +static ssize_t force_store (struct kobject *kobj,struct kobj_attribute *attr, +const char *buf,size_t count) +{ +bool res; + +if (!capable (CAP_SYS_BOOT )) +return -EPERM ; + +if (kstrtobool (buf, &res)) +return -EINVAL ; + + reboot_default =0 ; + reboot_force = res; + +return count; +} +static struct kobj_attribute reboot_force_attr =__ATTR_RW (force); +static ssize_t type_show (struct kobject *kobj,struct kobj_attribute *attr,char *buf) {const char *val;
@@ -717,7 +740,9 @@ static ssize_t type_store(struct kobject *kobj, struct kobj_attribute *attr,return count; }static struct kobj_attribute reboot_type_attr =__ATTR_RW (type); +#endif +#ifdef CONFIG_SMP static ssize_t cpu_show (struct kobject *kobj,struct kobj_attribute *attr,char *buf) {return sprintf (buf,"%d\n" , reboot_cpu);
@@ -745,34 +770,17 @@ static ssize_t cpu_store(struct kobject *kobj, struct kobj_attribute *attr,return count; }static struct kobj_attribute reboot_cpu_attr =__ATTR_RW (cpu); - -static ssize_t force_show (struct kobject *kobj,struct kobj_attribute *attr,char *buf) -{ -return sprintf (buf,"%d\n" , reboot_force); -} -static ssize_t force_store (struct kobject *kobj,struct kobj_attribute *attr, -const char *buf,size_t count) -{ -bool res; - -if (!capable (CAP_SYS_BOOT )) -return -EPERM ; - -if (kstrtobool (buf, &res)) -return -EINVAL ; - - reboot_default =0 ; - reboot_force = res; - -return count; -} -static struct kobj_attribute reboot_force_attr =__ATTR_RW (force); +#endif static struct attribute *reboot_attrs[] = { &reboot_mode_attr.attr, +#ifdef CONFIG_X86 + &reboot_force_attr.attr, &reboot_type_attr.attr, +#endif +#ifdef CONFIG_SMP &reboot_cpu_attr.attr, - &reboot_force_attr.attr, +#endifNULL , };
Signature · 1 line
2.28.0
Re: [PATCH 1/2] reboot: allow to override reboot type if quirks are found
In reply to Matteo CroceQuoted 6 lines · Matteo Croce
From: Matteo Croce <[email protected]>
On some machines a quirk can force a specific reboot type. Quirks are found during a DMI scan, the list of machines which need special reboot handling is defined in
reboot_dmi_table.
Quoted 7 lines
The kernel command line reboot= option overrides this via a global variable
reboot_default, so that the reboot type requested in the command line is really performed.This was not true when setting the reboot type via the new sysfs interface. Fix this by setting
reboot_defaultupon the first change, likereboot_setup()does for the command line.
Strictly speaking this is not necessary. The quirks are proceed in core_initcall() while the sysfs interface is created in late_initcall(). By other words, the quirks are uses before the default can be modified by the sysfs interface.
On the other hand, it does not harm. Better be on the safe side for eventual future changes.
Best Regards,
Petr
Re: [PATCH 2/2] reboot: hide from sysfs not applicable settings
In reply to Matteo CroceQuoted 5 lines · Matteo Croce
From: Matteo Croce <[email protected]>
Not all the reboot settings from both the kernel command line or sysfs interface are available to all platforms.
Quoted 7 lines
Filter out
reboot_typeandreboot_forcewhich are x86 only, and also removereboot_cpuon kernels without SMP support.This saves some space, and avoid confusing the user with settings which will have no effect.
Signed-off-by Matteo Croce <[email protected]>
Looks good to be.
Best Regards,
Petr