linux-nilfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] nilfs2: add support for some common ioctls
@ 2024-08-15  7:44 Ryusuke Konishi
  2024-08-15  7:44 ` [PATCH 1/4] nilfs2: add support for FS_IOC_GETUUID Ryusuke Konishi
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Ryusuke Konishi @ 2024-08-15  7:44 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-nilfs, linux-kernel

Hi Andrew, please queue this series for the next cycle.

This series adds support for common ioctls to nilfs2 for getting the
volume UUID and the relative path of an FS instance within the sysfs
namespace, and also implements ioctls for nilfs2 to get and set the
volume label.

Thanks,
Ryusuke Konishi

Ryusuke Konishi (4):
  nilfs2: add support for FS_IOC_GETUUID
  nilfs2: add support for FS_IOC_GETFSSYSFSPATH
  nilfs2: add support for FS_IOC_GETFSLABEL
  nilfs2: add support for FS_IOC_SETFSLABEL

 fs/nilfs2/ioctl.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++
 fs/nilfs2/nilfs.h | 12 +++++++
 fs/nilfs2/super.c |  4 +++
 3 files changed, 108 insertions(+)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] nilfs2: add support for FS_IOC_GETUUID
  2024-08-15  7:44 [PATCH 0/4] nilfs2: add support for some common ioctls Ryusuke Konishi
@ 2024-08-15  7:44 ` Ryusuke Konishi
  2024-08-15  7:44 ` [PATCH 2/4] nilfs2: add support for FS_IOC_GETFSSYSFSPATH Ryusuke Konishi
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Ryusuke Konishi @ 2024-08-15  7:44 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-nilfs, linux-kernel

Expose the UUID of a file system instance using the super_set_uuid
helper and support the FS_IOC_GETUUID ioctl.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
---
 fs/nilfs2/super.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c
index e835e1f5a712..167050b3ce7e 100644
--- a/fs/nilfs2/super.c
+++ b/fs/nilfs2/super.c
@@ -1063,6 +1063,9 @@ nilfs_fill_super(struct super_block *sb, struct fs_context *fc)
 	if (err)
 		goto failed_nilfs;
 
+	super_set_uuid(sb, nilfs->ns_sbp[0]->s_uuid,
+		       sizeof(nilfs->ns_sbp[0]->s_uuid));
+
 	cno = nilfs_last_cno(nilfs);
 	err = nilfs_attach_checkpoint(sb, cno, true, &fsroot);
 	if (err) {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] nilfs2: add support for FS_IOC_GETFSSYSFSPATH
  2024-08-15  7:44 [PATCH 0/4] nilfs2: add support for some common ioctls Ryusuke Konishi
  2024-08-15  7:44 ` [PATCH 1/4] nilfs2: add support for FS_IOC_GETUUID Ryusuke Konishi
@ 2024-08-15  7:44 ` Ryusuke Konishi
  2024-08-15  7:44 ` [PATCH 3/4] nilfs2: add support for FS_IOC_GETFSLABEL Ryusuke Konishi
  2024-08-15  7:44 ` [PATCH 4/4] nilfs2: add support for FS_IOC_SETFSLABEL Ryusuke Konishi
  3 siblings, 0 replies; 5+ messages in thread
From: Ryusuke Konishi @ 2024-08-15  7:44 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-nilfs, linux-kernel

Use the standard helper super_set_sysfs_name_bdev() to give the sysfs
subpath of the filesystem for the FS_IOC_GETFSSYSFSPATH ioctl.

For nilfs2, it will output "nilfs2/<dev>".

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
---
 fs/nilfs2/super.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c
index 167050b3ce7e..76e35e6773d1 100644
--- a/fs/nilfs2/super.c
+++ b/fs/nilfs2/super.c
@@ -1065,6 +1065,7 @@ nilfs_fill_super(struct super_block *sb, struct fs_context *fc)
 
 	super_set_uuid(sb, nilfs->ns_sbp[0]->s_uuid,
 		       sizeof(nilfs->ns_sbp[0]->s_uuid));
+	super_set_sysfs_name_bdev(sb);
 
 	cno = nilfs_last_cno(nilfs);
 	err = nilfs_attach_checkpoint(sb, cno, true, &fsroot);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] nilfs2: add support for FS_IOC_GETFSLABEL
  2024-08-15  7:44 [PATCH 0/4] nilfs2: add support for some common ioctls Ryusuke Konishi
  2024-08-15  7:44 ` [PATCH 1/4] nilfs2: add support for FS_IOC_GETUUID Ryusuke Konishi
  2024-08-15  7:44 ` [PATCH 2/4] nilfs2: add support for FS_IOC_GETFSSYSFSPATH Ryusuke Konishi
@ 2024-08-15  7:44 ` Ryusuke Konishi
  2024-08-15  7:44 ` [PATCH 4/4] nilfs2: add support for FS_IOC_SETFSLABEL Ryusuke Konishi
  3 siblings, 0 replies; 5+ messages in thread
From: Ryusuke Konishi @ 2024-08-15  7:44 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-nilfs, linux-kernel

Implement support for FS_IOC_GETFSLABEL ioctl to read filesystem
label.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
---
 fs/nilfs2/ioctl.c | 27 +++++++++++++++++++++++++++
 fs/nilfs2/nilfs.h | 12 ++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c
index 8be471ce4f19..b5c6a50d6d5d 100644
--- a/fs/nilfs2/ioctl.c
+++ b/fs/nilfs2/ioctl.c
@@ -17,6 +17,7 @@
 #include <linux/mount.h>	/* mnt_want_write_file(), mnt_drop_write_file() */
 #include <linux/buffer_head.h>
 #include <linux/fileattr.h>
+#include <linux/string.h>
 #include "nilfs.h"
 #include "segment.h"
 #include "bmap.h"
@@ -1266,6 +1267,29 @@ static int nilfs_ioctl_set_suinfo(struct inode *inode, struct file *filp,
 	return ret;
 }
 
+/**
+ * nilfs_ioctl_get_fslabel - get the volume name of the file system
+ * @sb:   super block instance
+ * @argp: pointer to userspace memory where the volume name should be stored
+ *
+ * Return: 0 on success, %-EFAULT if copying to userspace memory fails.
+ */
+static int nilfs_ioctl_get_fslabel(struct super_block *sb, void __user *argp)
+{
+	struct the_nilfs *nilfs = sb->s_fs_info;
+	char label[NILFS_MAX_VOLUME_NAME + 1];
+
+	BUILD_BUG_ON(NILFS_MAX_VOLUME_NAME >= FSLABEL_MAX);
+
+	down_read(&nilfs->ns_sem);
+	memtostr_pad(label, nilfs->ns_sbp[0]->s_volume_name);
+	up_read(&nilfs->ns_sem);
+
+	if (copy_to_user(argp, label, sizeof(label)))
+		return -EFAULT;
+	return 0;
+}
+
 long nilfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
 	struct inode *inode = file_inode(filp);
@@ -1308,6 +1332,8 @@ long nilfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 		return nilfs_ioctl_set_alloc_range(inode, argp);
 	case FITRIM:
 		return nilfs_ioctl_trim_fs(inode, argp);
+	case FS_IOC_GETFSLABEL:
+		return nilfs_ioctl_get_fslabel(inode->i_sb, argp);
 	default:
 		return -ENOTTY;
 	}
@@ -1334,6 +1360,7 @@ long nilfs_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 	case NILFS_IOCTL_RESIZE:
 	case NILFS_IOCTL_SET_ALLOC_RANGE:
 	case FITRIM:
+	case FS_IOC_GETFSLABEL:
 		break;
 	default:
 		return -ENOIOCTLCMD;
diff --git a/fs/nilfs2/nilfs.h b/fs/nilfs2/nilfs.h
index 4017f7856440..3097490b6621 100644
--- a/fs/nilfs2/nilfs.h
+++ b/fs/nilfs2/nilfs.h
@@ -103,6 +103,18 @@ enum {
 	NILFS_SB_COMMIT_ALL	/* Commit both super blocks */
 };
 
+/**
+ * define NILFS_MAX_VOLUME_NAME - maximum number of characters (bytes) in a
+ *                                file system volume name
+ *
+ * Defined by the size of the volume name field in the on-disk superblocks.
+ * This volume name does not include the terminating NULL byte if the string
+ * length matches the field size, so use (NILFS_MAX_VOLUME_NAME + 1) for the
+ * size of the buffer that requires a NULL byte termination.
+ */
+#define NILFS_MAX_VOLUME_NAME  \
+	sizeof_field(struct nilfs_super_block, s_volume_name)
+
 /*
  * Macros to check inode numbers
  */
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] nilfs2: add support for FS_IOC_SETFSLABEL
  2024-08-15  7:44 [PATCH 0/4] nilfs2: add support for some common ioctls Ryusuke Konishi
                   ` (2 preceding siblings ...)
  2024-08-15  7:44 ` [PATCH 3/4] nilfs2: add support for FS_IOC_GETFSLABEL Ryusuke Konishi
@ 2024-08-15  7:44 ` Ryusuke Konishi
  3 siblings, 0 replies; 5+ messages in thread
From: Ryusuke Konishi @ 2024-08-15  7:44 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-nilfs, linux-kernel

Implement support for FS_IOC_SETFSLABEL ioctl to write filesystem
label.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
---
 fs/nilfs2/ioctl.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)

diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c
index b5c6a50d6d5d..297989e51ee6 100644
--- a/fs/nilfs2/ioctl.c
+++ b/fs/nilfs2/ioctl.c
@@ -1290,6 +1290,68 @@ static int nilfs_ioctl_get_fslabel(struct super_block *sb, void __user *argp)
 	return 0;
 }
 
+/**
+ * nilfs_ioctl_set_fslabel - set the volume name of the file system
+ * @sb:   super block instance
+ * @filp: file object
+ * @argp: pointer to userspace memory that contains the volume name
+ *
+ * Return: 0 on success, or the following negative error code on failure.
+ * * %-EFAULT	- Error copying input data.
+ * * %-EINVAL	- Label length exceeds record size in superblock.
+ * * %-EIO	- I/O error.
+ * * %-EPERM	- Operation not permitted (insufficient permissions).
+ * * %-EROFS	- Read only file system.
+ */
+static int nilfs_ioctl_set_fslabel(struct super_block *sb, struct file *filp,
+				   void __user *argp)
+{
+	char label[NILFS_MAX_VOLUME_NAME + 1];
+	struct the_nilfs *nilfs = sb->s_fs_info;
+	struct nilfs_super_block **sbp;
+	size_t len;
+	int ret;
+
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+
+	ret = mnt_want_write_file(filp);
+	if (ret)
+		return ret;
+
+	if (copy_from_user(label, argp, NILFS_MAX_VOLUME_NAME + 1)) {
+		ret = -EFAULT;
+		goto out_drop_write;
+	}
+
+	len = strnlen(label, NILFS_MAX_VOLUME_NAME + 1);
+	if (len > NILFS_MAX_VOLUME_NAME) {
+		nilfs_err(sb, "unable to set label with more than %zu bytes",
+			  NILFS_MAX_VOLUME_NAME);
+		ret = -EINVAL;
+		goto out_drop_write;
+	}
+
+	down_write(&nilfs->ns_sem);
+	sbp = nilfs_prepare_super(sb, false);
+	if (unlikely(!sbp)) {
+		ret = -EIO;
+		goto out_unlock;
+	}
+
+	strtomem_pad(sbp[0]->s_volume_name, label, 0);
+	if (sbp[1])
+		strtomem_pad(sbp[1]->s_volume_name, label, 0);
+
+	ret = nilfs_commit_super(sb, NILFS_SB_COMMIT_ALL);
+
+out_unlock:
+	up_write(&nilfs->ns_sem);
+out_drop_write:
+	mnt_drop_write_file(filp);
+	return ret;
+}
+
 long nilfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
 	struct inode *inode = file_inode(filp);
@@ -1334,6 +1396,8 @@ long nilfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 		return nilfs_ioctl_trim_fs(inode, argp);
 	case FS_IOC_GETFSLABEL:
 		return nilfs_ioctl_get_fslabel(inode->i_sb, argp);
+	case FS_IOC_SETFSLABEL:
+		return nilfs_ioctl_set_fslabel(inode->i_sb, filp, argp);
 	default:
 		return -ENOTTY;
 	}
@@ -1361,6 +1425,7 @@ long nilfs_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 	case NILFS_IOCTL_SET_ALLOC_RANGE:
 	case FITRIM:
 	case FS_IOC_GETFSLABEL:
+	case FS_IOC_SETFSLABEL:
 		break;
 	default:
 		return -ENOIOCTLCMD;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-08-15  7:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-15  7:44 [PATCH 0/4] nilfs2: add support for some common ioctls Ryusuke Konishi
2024-08-15  7:44 ` [PATCH 1/4] nilfs2: add support for FS_IOC_GETUUID Ryusuke Konishi
2024-08-15  7:44 ` [PATCH 2/4] nilfs2: add support for FS_IOC_GETFSSYSFSPATH Ryusuke Konishi
2024-08-15  7:44 ` [PATCH 3/4] nilfs2: add support for FS_IOC_GETFSLABEL Ryusuke Konishi
2024-08-15  7:44 ` [PATCH 4/4] nilfs2: add support for FS_IOC_SETFSLABEL Ryusuke Konishi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).