diff mbox series

[v4,3/6] powerpc/fadump: reorganize /sys/kernel/fadump_* sysfs files

Message ID 20191206122434.29587-4-sourabhjain@linux.ibm.com (mailing list archive)
State Superseded
Headers show
Series reorganize and add FADump sysfs files | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success Successfully applied on branch powerpc/merge (567dea0e848944848650d7fd27699e2de5d49353)
snowpatch_ozlabs/checkpatch success total: 0 errors, 0 warnings, 0 checks, 123 lines checked
snowpatch_ozlabs/needsstable success Patch has no Fixes tags

Commit Message

Sourabh Jain Dec. 6, 2019, 12:24 p.m. UTC
As the number of FADump sysfs files increases it is hard to manage all of
them inside /sys/kernel directory. It's better to have all the FADump
related sysfs files in a dedicated directory /sys/kernel/fadump. But in
order to maintain backward compatibility a symlink has been added for every
sysfs that has moved to new location.

As the FADump sysfs files are now part of a dedicated directory there is no
need to prefix their name with fadump_, hence sysfs file names are also
updated. For example fadump_enabled sysfs file is now referred as enabled.

Also consolidate ABI documentation for all the FADump sysfs files in a
single file Documentation/ABI/testing/sysfs-kernel-fadump.

Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com>
---
 Documentation/ABI/testing/sysfs-kernel-fadump | 33 ++++++++++
 arch/powerpc/kernel/fadump.c                  | 66 ++++++++++++++-----
 2 files changed, 83 insertions(+), 16 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-kernel-fadump

Comments

Greg KH Dec. 6, 2019, 12:45 p.m. UTC | #1
On Fri, Dec 06, 2019 at 05:54:31PM +0530, Sourabh Jain wrote:
> +static struct kobj_attribute release_attr = __ATTR(release_mem,
>  						0200, NULL,
>  						fadump_release_memory_store);
> -static struct kobj_attribute fadump_attr = __ATTR(fadump_enabled,
> +static struct kobj_attribute enable_attr = __ATTR(enabled,
>  						0444, fadump_enabled_show,
>  						NULL);

__ATTR_RO()?

> -static struct kobj_attribute fadump_register_attr = __ATTR(fadump_registered,
> +static struct kobj_attribute register_attr = __ATTR(registered,
>  						0644, fadump_register_show,
>  						fadump_register_store);

__ATTR_RW()?

And then use an ATTRIBUTE_GROUP() macro to create a group so that you
then can do:

> @@ -1452,11 +1450,47 @@ static void fadump_init_files(void)
>  		printk(KERN_ERR "fadump: unable to create debugfs file"
>  				" fadump_region\n");
>  
> +	rc = sysfs_create_file(fadump_kobj, &enable_attr.attr);
> +	if (rc)
> +		pr_err("unable to create enabled sysfs file (%d)\n",
> +		       rc);
> +	rc = sysfs_create_file(fadump_kobj, &register_attr.attr);
> +	if (rc)
> +		pr_err("unable to create registered sysfs file (%d)\n",
> +		       rc);
> +	if (fw_dump.dump_active) {
> +		rc = sysfs_create_file(fadump_kobj, &release_attr.attr);
> +		if (rc)
> +			pr_err("unable to create release_mem sysfs file (%d)\n",
> +			       rc);
> +	}

a single call to sysfs_create_groups() here instead of trying to unwind
the mess if something went wrong.

thanks,

greg k-h
Sourabh Jain Dec. 6, 2019, 7:13 p.m. UTC | #2
On 12/6/19 6:15 PM, Greg KH wrote:
> On Fri, Dec 06, 2019 at 05:54:31PM +0530, Sourabh Jain wrote:
>> +static struct kobj_attribute release_attr = __ATTR(release_mem,
>>  						0200, NULL,
>>  						fadump_release_memory_store);
>> -static struct kobj_attribute fadump_attr = __ATTR(fadump_enabled,
>> +static struct kobj_attribute enable_attr = __ATTR(enabled,
>>  						0444, fadump_enabled_show,
>>  						NULL);
> 
> __ATTR_RO()?
> 
>> -static struct kobj_attribute fadump_register_attr = __ATTR(fadump_registered,
>> +static struct kobj_attribute register_attr = __ATTR(registered,
>>  						0644, fadump_register_show,
>>  						fadump_register_store);
> 
> __ATTR_RW()?

Thanks I was not aware of these macros.

> 
> And then use an ATTRIBUTE_GROUP() macro to create a group so that you
> then can do:
> 
>> @@ -1452,11 +1450,47 @@ static void fadump_init_files(void)
>>  		printk(KERN_ERR "fadump: unable to create debugfs file"
>>  				" fadump_region\n");
>>  
>> +	rc = sysfs_create_file(fadump_kobj, &enable_attr.attr);
>> +	if (rc)
>> +		pr_err("unable to create enabled sysfs file (%d)\n",
>> +		       rc);
>> +	rc = sysfs_create_file(fadump_kobj, &register_attr.attr);
>> +	if (rc)
>> +		pr_err("unable to create registered sysfs file (%d)\n",
>> +		       rc);
>> +	if (fw_dump.dump_active) {
>> +		rc = sysfs_create_file(fadump_kobj, &release_attr.attr);
>> +		if (rc)
>> +			pr_err("unable to create release_mem sysfs file (%d)\n",
>> +			       rc);
>> +	}
> 
> a single call to sysfs_create_groups() here instead of trying to unwind
> the mess if something went wrong.
> 

Sure, I will replace the individual calls with a single group call.

Thanks,
Sourabh Jain
diff mbox series

Patch

diff --git a/Documentation/ABI/testing/sysfs-kernel-fadump b/Documentation/ABI/testing/sysfs-kernel-fadump
new file mode 100644
index 000000000000..5d988b919e81
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-kernel-fadump
@@ -0,0 +1,33 @@ 
+What:		/sys/kernel/fadump/*
+Date:		Dec 2019
+Contact:	linuxppc-dev@lists.ozlabs.org
+Description:
+		The /sys/kernel/fadump/* is a collection of FADump sysfs
+		file provide information about the configuration status
+		of Firmware Assisted Dump (FADump).
+
+What:		/sys/kernel/fadump/enabled
+Date:		Dec 2019
+Contact:	linuxppc-dev@lists.ozlabs.org
+Description:	read only
+		Primarily used to identify whether the FADump is enabled in
+		the kernel or not.
+User:		Kdump service
+
+What:		/sys/kernel/fadump/registered
+Date:		Dec 2019
+Contact:	linuxppc-dev@lists.ozlabs.org
+Description:	read/write
+		Helps to control the dump collect feature from userspace.
+		Setting 1 to this file enables the system to collect the
+		dump and 0 to disable it.
+User:		Kdump service
+
+What:		/sys/kernel/fadump/release_mem
+Date:		Dec 2019
+Contact:	linuxppc-dev@lists.ozlabs.org
+Description:	write only
+		This is a special sysfs file and only available when
+		the system is booted to capture the vmcore using FADump.
+		It is used to release the memory reserved by FADump to
+		save the crash dump.
diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
index ed59855430b9..41a3cda81791 100644
--- a/arch/powerpc/kernel/fadump.c
+++ b/arch/powerpc/kernel/fadump.c
@@ -1418,13 +1418,16 @@  static int fadump_region_show(struct seq_file *m, void *private)
 	return 0;
 }
 
-static struct kobj_attribute fadump_release_attr = __ATTR(fadump_release_mem,
+struct kobject *fadump_kobj;
+EXPORT_SYMBOL_GPL(fadump_kobj);
+
+static struct kobj_attribute release_attr = __ATTR(release_mem,
 						0200, NULL,
 						fadump_release_memory_store);
-static struct kobj_attribute fadump_attr = __ATTR(fadump_enabled,
+static struct kobj_attribute enable_attr = __ATTR(enabled,
 						0444, fadump_enabled_show,
 						NULL);
-static struct kobj_attribute fadump_register_attr = __ATTR(fadump_registered,
+static struct kobj_attribute register_attr = __ATTR(registered,
 						0644, fadump_register_show,
 						fadump_register_store);
 
@@ -1435,16 +1438,11 @@  static void fadump_init_files(void)
 	struct dentry *debugfs_file;
 	int rc = 0;
 
-	rc = sysfs_create_file(kernel_kobj, &fadump_attr.attr);
-	if (rc)
-		printk(KERN_ERR "fadump: unable to create sysfs file"
-			" fadump_enabled (%d)\n", rc);
-
-	rc = sysfs_create_file(kernel_kobj, &fadump_register_attr.attr);
-	if (rc)
-		printk(KERN_ERR "fadump: unable to create sysfs file"
-			" fadump_registered (%d)\n", rc);
-
+	fadump_kobj = kobject_create_and_add("fadump", kernel_kobj);
+	if (!fadump_kobj) {
+		pr_err("failed to create fadump kobject\n");
+		return;
+	}
 	debugfs_file = debugfs_create_file("fadump_region", 0444,
 					powerpc_debugfs_root, NULL,
 					&fadump_region_fops);
@@ -1452,11 +1450,47 @@  static void fadump_init_files(void)
 		printk(KERN_ERR "fadump: unable to create debugfs file"
 				" fadump_region\n");
 
+	rc = sysfs_create_file(fadump_kobj, &enable_attr.attr);
+	if (rc)
+		pr_err("unable to create enabled sysfs file (%d)\n",
+		       rc);
+	rc = sysfs_create_file(fadump_kobj, &register_attr.attr);
+	if (rc)
+		pr_err("unable to create registered sysfs file (%d)\n",
+		       rc);
+	if (fw_dump.dump_active) {
+		rc = sysfs_create_file(fadump_kobj, &release_attr.attr);
+		if (rc)
+			pr_err("unable to create release_mem sysfs file (%d)\n",
+			       rc);
+	}
+
+	/* The FADump sysfs are moved from kernel_kobj to fadump_kobj need to
+	 * create symlink at old location to maintain backward compatibility.
+	 *
+	 *      - fadump_enabled -> fadump/enabled
+	 *      - fadump_registered -> fadump/registered
+	 *      - fadump_release_mem -> fadump/release_mem
+	 */
+	rc = create_sysfs_symlink_entry_to_kobj(kernel_kobj, fadump_kobj,
+						"enabled", "fadump_enabled");
+	if (rc)
+		pr_err("unable to create fadump_enabled symlink (%d)\n", rc);
+
+	rc = create_sysfs_symlink_entry_to_kobj(kernel_kobj, fadump_kobj,
+						"registered",
+						"fadump_registered");
+	if (rc)
+		pr_err("unable to create fadump_registered symlink (%d)\n", rc);
+
 	if (fw_dump.dump_active) {
-		rc = sysfs_create_file(kernel_kobj, &fadump_release_attr.attr);
+		rc = create_sysfs_symlink_entry_to_kobj(kernel_kobj,
+							fadump_kobj,
+							"release_mem",
+							"fadump_release_mem");
 		if (rc)
-			printk(KERN_ERR "fadump: unable to create sysfs file"
-				" fadump_release_mem (%d)\n", rc);
+			pr_err("unable to create fadump_release_mem symlink (%d)\n",
+			       rc);
 	}
 	return;
 }