diff mbox series

[RFC,17/20] famfs: Add module stuff

Message ID e633fb92d3c20ba446e60c2c161cf07074aef374.1708709155.git.john@groves.net (mailing list archive)
State Superseded, archived
Headers show
Series Introduce the famfs shared-memory file system | expand

Commit Message

John Groves Feb. 23, 2024, 5:42 p.m. UTC
This commit introduces the module init and exit machinery for famfs.

Signed-off-by: John Groves <john@groves.net>
---
 fs/famfs/famfs_inode.c | 44 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

Comments

Jonathan Cameron Feb. 26, 2024, 1:47 p.m. UTC | #1
On Fri, 23 Feb 2024 11:42:01 -0600
John Groves <John@Groves.net> wrote:

> This commit introduces the module init and exit machinery for famfs.
> 
> Signed-off-by: John Groves <john@groves.net>
I'd prefer to see this from the start with the functionality of the module
built up as you go + build logic in place.  Makes it easy to spot places
where the patches aren't appropriately self constrained. 
> ---
>  fs/famfs/famfs_inode.c | 44 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 44 insertions(+)
> 
> diff --git a/fs/famfs/famfs_inode.c b/fs/famfs/famfs_inode.c
> index ab46ec50b70d..0d659820e8ff 100644
> --- a/fs/famfs/famfs_inode.c
> +++ b/fs/famfs/famfs_inode.c
> @@ -462,4 +462,48 @@ static struct file_system_type famfs_fs_type = {
>  	.fs_flags	  = FS_USERNS_MOUNT,
>  };
>  
> +/*****************************************************************************************
> + * Module stuff

I'd drop these drivers structure comments. They add little beyond
a high possibility of being wrong after the code has evolved a bit.

> + */
> +static struct kobject *famfs_kobj;
> +
> +static int __init init_famfs_fs(void)
> +{
> +	int rc;
> +
> +#if defined(CONFIG_DEV_DAX_IOMAP)
> +	pr_notice("%s: Your kernel supports famfs on /dev/dax\n", __func__);
> +#else
> +	pr_notice("%s: Your kernel does not support famfs on /dev/dax\n", __func__);
> +#endif
> +	famfs_kobj = kobject_create_and_add(MODULE_NAME, fs_kobj);
> +	if (!famfs_kobj) {
> +		pr_warn("Failed to create kobject\n");
> +		return -ENOMEM;
> +	}
> +
> +	rc = sysfs_create_group(famfs_kobj, &famfs_attr_group);
> +	if (rc) {
> +		kobject_put(famfs_kobj);
> +		pr_warn("%s: Failed to create sysfs group\n", __func__);
> +		return rc;
> +	}
> +
> +	return register_filesystem(&famfs_fs_type);

If this fails, do we not leak the kobj and sysfs groups?

> +}
> +
> +static void
> +__exit famfs_exit(void)
> +{
> +	sysfs_remove_group(famfs_kobj,  &famfs_attr_group);
> +	kobject_put(famfs_kobj);
> +	unregister_filesystem(&famfs_fs_type);
> +	pr_info("%s: unregistered\n", __func__);
> +}
> +
> +
> +fs_initcall(init_famfs_fs);
> +module_exit(famfs_exit);
> +
> +MODULE_AUTHOR("John Groves, Micron Technology");
>  MODULE_LICENSE("GPL");
John Groves Feb. 27, 2024, 10:15 p.m. UTC | #2
On 24/02/26 01:47PM, Jonathan Cameron wrote:
> On Fri, 23 Feb 2024 11:42:01 -0600
> John Groves <John@Groves.net> wrote:
> 
> > This commit introduces the module init and exit machinery for famfs.
> > 
> > Signed-off-by: John Groves <john@groves.net>
> I'd prefer to see this from the start with the functionality of the module
> built up as you go + build logic in place.  Makes it easy to spot places
> where the patches aren't appropriately self constrained. 
> > ---
> >  fs/famfs/famfs_inode.c | 44 ++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 44 insertions(+)
> > 
> > diff --git a/fs/famfs/famfs_inode.c b/fs/famfs/famfs_inode.c
> > index ab46ec50b70d..0d659820e8ff 100644
> > --- a/fs/famfs/famfs_inode.c
> > +++ b/fs/famfs/famfs_inode.c
> > @@ -462,4 +462,48 @@ static struct file_system_type famfs_fs_type = {
> >  	.fs_flags	  = FS_USERNS_MOUNT,
> >  };
> >  
> > +/*****************************************************************************************
> > + * Module stuff
> 
> I'd drop these drivers structure comments. They add little beyond
> a high possibility of being wrong after the code has evolved a bit.

Probably will do with the module-ops-up refactor for v2

> 
> > + */
> > +static struct kobject *famfs_kobj;
> > +
> > +static int __init init_famfs_fs(void)
> > +{
> > +	int rc;
> > +
> > +#if defined(CONFIG_DEV_DAX_IOMAP)
> > +	pr_notice("%s: Your kernel supports famfs on /dev/dax\n", __func__);
> > +#else
> > +	pr_notice("%s: Your kernel does not support famfs on /dev/dax\n", __func__);
> > +#endif
> > +	famfs_kobj = kobject_create_and_add(MODULE_NAME, fs_kobj);
> > +	if (!famfs_kobj) {
> > +		pr_warn("Failed to create kobject\n");
> > +		return -ENOMEM;
> > +	}
> > +
> > +	rc = sysfs_create_group(famfs_kobj, &famfs_attr_group);
> > +	if (rc) {
> > +		kobject_put(famfs_kobj);
> > +		pr_warn("%s: Failed to create sysfs group\n", __func__);
> > +		return rc;
> > +	}
> > +
> > +	return register_filesystem(&famfs_fs_type);
> 
> If this fails, do we not leak the kobj and sysfs groups?

Good catch, thanks! Fixed for now- but the kobj is also likely to go away. Will
endeavor to get it right...

Thanks,
John
diff mbox series

Patch

diff --git a/fs/famfs/famfs_inode.c b/fs/famfs/famfs_inode.c
index ab46ec50b70d..0d659820e8ff 100644
--- a/fs/famfs/famfs_inode.c
+++ b/fs/famfs/famfs_inode.c
@@ -462,4 +462,48 @@  static struct file_system_type famfs_fs_type = {
 	.fs_flags	  = FS_USERNS_MOUNT,
 };
 
+/*****************************************************************************************
+ * Module stuff
+ */
+static struct kobject *famfs_kobj;
+
+static int __init init_famfs_fs(void)
+{
+	int rc;
+
+#if defined(CONFIG_DEV_DAX_IOMAP)
+	pr_notice("%s: Your kernel supports famfs on /dev/dax\n", __func__);
+#else
+	pr_notice("%s: Your kernel does not support famfs on /dev/dax\n", __func__);
+#endif
+	famfs_kobj = kobject_create_and_add(MODULE_NAME, fs_kobj);
+	if (!famfs_kobj) {
+		pr_warn("Failed to create kobject\n");
+		return -ENOMEM;
+	}
+
+	rc = sysfs_create_group(famfs_kobj, &famfs_attr_group);
+	if (rc) {
+		kobject_put(famfs_kobj);
+		pr_warn("%s: Failed to create sysfs group\n", __func__);
+		return rc;
+	}
+
+	return register_filesystem(&famfs_fs_type);
+}
+
+static void
+__exit famfs_exit(void)
+{
+	sysfs_remove_group(famfs_kobj,  &famfs_attr_group);
+	kobject_put(famfs_kobj);
+	unregister_filesystem(&famfs_fs_type);
+	pr_info("%s: unregistered\n", __func__);
+}
+
+
+fs_initcall(init_famfs_fs);
+module_exit(famfs_exit);
+
+MODULE_AUTHOR("John Groves, Micron Technology");
 MODULE_LICENSE("GPL");