Skip to contentSkip to conversation

ubifs: allow userspace to map mounts to volumes

PATCH Superseded Rabin Vincent 2 participants 2 messages May 24, 2017 – May 25, 2017

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ubifs: allow userspace to map mounts to volumes

From: Rabin Vincent <[email protected]>

There currently appears to be no way for userspace to find out the underlying volume number for a mounted ubifs file system, since ubifs uses anonymous block devices. The volume name is present in /proc/mounts but UBI volumes can be renamed after the volume has been mounted.

To remedy this, provide a directory in /sys/fs/ubifs named after the underlying anonymous block device's number (obtainable by userspace via stat(2)) and provide a link named "ubi" to the underlying UBI volume.

 # mount | head -1
 ubi0:rootfs on / type ubifs (rw,relatime)
 # ubirename /dev/ubi0 rootfs foo
 # mount | head -1
 ubi0:rootfs on / type ubifs (rw,relatime)
 # stat /
   File: /
   Size: 1520      	Blocks: 0          IO Block: 4096   directory
 Device: dh/13d	Inode: 1           Links: 18
 ...
 # ls -l /sys/fs/ubifs/
 drwxr-xr-x    2 root     root             0 May 23 09:57 0:13
 drwxr-xr-x    2 root     root             0 May 23 09:57 0:17
 # ls -l /sys/fs/ubifs/0\:13/
 lrwxrwxrwx    1 root     root             0 May 23 11:45 ubi
   -> ../../../devices/virtual/ubi/ubi0/ubi0_10
---
 Documentation/ABI/testing/sysfs-fs-ubifs |  6 +++
 drivers/mtd/ubi/kapi.c                   | 12 ++++++
 fs/ubifs/Makefile                        |  2 +-
 fs/ubifs/super.c                         | 16 +++++++-
 fs/ubifs/sysfs.c                         | 66 ++++++++++++++++++++++++++++++++
 fs/ubifs/sysfs.h                         | 11 ++++++
 fs/ubifs/ubifs.h                         |  7 ++++
 include/linux/mtd/ubi.h                  |  3 ++
 8 files changed, 121 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-fs-ubifs
 create mode 100644 fs/ubifs/sysfs.c
 create mode 100644 fs/ubifs/sysfs.h
Documentation/ABI/testing/sysfs-fs-ubifs new file +6 -0
new file mode 100644
index 0000000..1735859
@@ -0,0 +1,6 @@
+What:		/sys/fs/ubifs/<disk>/ubi
+Date:		May 2017
+Description:
+		This symbolic link points to the file system's underlying UBI
+		volume.  The <disk> is the major:minor numbers of the anonymous
+		block device backing the file system.
drivers/mtd/ubi/kapi.c +12 -0
index d4b2e87..aa766d9 100644
@@ -107,6 +107,18 @@ void ubi_get_volume_info(struct ubi_volume_desc *desc,
 EXPORT_SYMBOL_GPL(ubi_get_volume_info);
 
 /**
+ * ubi_volume_kobject - get kobject for a UBI volume.
+ * @desc: volume descriptor
+ *
+ * Retrieves a pointer to the struct kobject underlying the UBI volume.
+ * The caller must hold a reference to the UBI volume.
+ */
+struct kobject *ubi_volume_kobj(struct ubi_volume_desc *desc)
+{
+	return &desc->vol->dev.kobj;
+}
+
+/**
  * ubi_open_volume - open UBI volume.
  * @ubi_num: UBI device number
  * @vol_id: volume ID
fs/ubifs/Makefile +1 -1
index 6f3251c..7bf4689 100644
@@ -4,5 +4,5 @@ ubifs-y += shrinker.o journal.o file.o dir.o super.o sb.o io.o
 ubifs-y += tnc.o master.o scan.o replay.o log.o commit.o gc.o orphan.o
 ubifs-y += budget.o find.o tnc_commit.o compress.o lpt.o lprops.o
 ubifs-y += recovery.o ioctl.o lpt_commit.o tnc_misc.o xattr.o debug.o
-ubifs-y += misc.o
+ubifs-y += sysfs.o misc.o
 ubifs-$(CONFIG_UBIFS_FS_ENCRYPTION) += crypto.o
fs/ubifs/super.c +15 -1
index cf4cc99..fdcfefe 100644
@@ -1164,6 +1164,10 @@ static int mount_ubifs(struct ubifs_info *c)
 	if (err)
 		return err;
 
+	err = ubifs_sysfs_register(c);
+	if (err)
+		goto out_debugging;
+
 	err = check_volume_empty(c);
 	if (err)
 		goto out_free;
@@ -1496,6 +1500,8 @@ static int mount_ubifs(struct ubifs_info *c)
 	vfree(c->ileb_buf);
 	vfree(c->sbuf);
 	kfree(c->bottom_up_buf);
+	ubifs_sysfs_unregister(c);
+out_debugging:
 	ubifs_debugging_exit(c);
 	return err;
 }
@@ -1536,6 +1542,7 @@ static void ubifs_umount(struct ubifs_info *c)
 	vfree(c->sbuf);
 	kfree(c->bottom_up_buf);
 	ubifs_debugging_exit(c);
+	ubifs_sysfs_unregister(c);
 }
 
 /**
@@ -2271,14 +2278,20 @@ static int __init ubifs_init(void)
 	if (err)
 		goto out_compr;
 
+	err = ubifs_sysfs_init();
+	if (err)
+		goto out_dbg;
+
 	err = register_filesystem(&ubifs_fs_type);
 	if (err) {
 		pr_err("UBIFS error (pid %d): cannot register file system, error %d",
 		       current->pid, err);
-		goto out_dbg;
+		goto out_sysfs;
 	}
 	return 0;
 
+out_sysfs:
+	ubifs_sysfs_exit();
 out_dbg:
 	dbg_debugfs_exit();
 out_compr:
@@ -2308,6 +2321,7 @@ static void __exit ubifs_exit(void)
 	rcu_barrier();
 	kmem_cache_destroy(ubifs_inode_slab);
 	unregister_filesystem(&ubifs_fs_type);
+	ubifs_sysfs_exit();
 }
 module_exit(ubifs_exit);
 
fs/ubifs/sysfs.c new file +66 -0

66 lines not on this page · raw message

fs/ubifs/sysfs.h new file +11 -0
new file mode 100644
index 0000000..4b7e70b
@@ -0,0 +1,11 @@
+#ifndef __UBIFS_SYSFS_H__
+#define __UBIFS_SYSFS_H__
+
+struct ubifs_info;
+
+int ubifs_sysfs_init(void);
+void ubifs_sysfs_exit(void);
+int ubifs_sysfs_register(struct ubifs_info *c);
+void ubifs_sysfs_unregister(struct ubifs_info *c);
+
+#endif
fs/ubifs/ubifs.h +7 -0
index 298b4d8..3a3154f 100644
@@ -43,7 +43,10 @@
 #else
 #include <linux/fscrypt_notsupp.h>
 #endif
+#include <linux/sysfs.h>
+#include <linux/completion.h>
 #include <linux/random.h>
+#include "sysfs.h"
 #include "ubifs-media.h"
 
 /* Version of this UBIFS implementation */
@@ -1216,6 +1219,8 @@ struct ubifs_debug_info;
  * @mount_opts: UBIFS-specific mount options
  *
  * @dbg: debugging-related information
+ * @kobj: kobject for /sys/fs/ubifs/
+ * @kobj_unregister: completion to unregister sysfs kobject
  */
 struct ubifs_info {
 	struct super_block *vfs_sb;
@@ -1446,6 +1451,8 @@ struct ubifs_info {
 	struct ubifs_mount_opts mount_opts;
 
 	struct ubifs_debug_info *dbg;
+	struct kobject kobj;
+	struct completion kobj_unregister;
 };
 
 extern struct list_head ubifs_infos;
include/linux/mtd/ubi.h +3 -0
index 1e271cb..d35e84f 100644
@@ -26,6 +26,8 @@
 #include <linux/scatterlist.h>
 #include <mtd/ubi-user.h>
 
+struct kobject;
+
 /* All voumes/LEBs */
 #define UBI_ALL -1
 
@@ -241,6 +243,7 @@ struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode);
 struct ubi_volume_desc *ubi_open_volume_nm(int ubi_num, const char *name,
 					   int mode);
 struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode);
+struct kobject *ubi_volume_kobj(struct ubi_volume_desc *desc);
 
 int ubi_register_volume_notifier(struct notifier_block *nb,
 				 int ignore_existing);
Signature · 1 line
2.1.4
#1 lore raw
url: https://github.com/0day-ci/linux/commits/Rabin-Vincent/ubifs-allow-userspace-to-map-mounts-to-volumes/20170525-014923 config: i386-allmodconfig (attached as .config) compiler: gcc-6 (Debian…

Hi Rabin,

[auto build test ERROR on linus/master]
[also build test ERROR on v4.12-rc2 next-20170524]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Rabin-Vincent/ubifs-allow-userspace-to-map-mounts-to-volumes/20170525-014923
config: i386-allmodconfig (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce:

        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

>> ERROR: "ubi_volume_kobj" [fs/ubifs/ubifs.ko] undefined!

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation