All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2 0/5] xfs: online label
@ 2018-05-14 17:30 Eric Sandeen
  2018-05-14 17:35 ` [PATCH V2 1/5] fs: copy BTRFS_IOC_[SG]ET_FSLABEL to vfs Eric Sandeen
                   ` (4 more replies)
  0 siblings, 5 replies; 20+ messages in thread
From: Eric Sandeen @ 2018-05-14 17:30 UTC (permalink / raw)
  To: linux-xfs

resend of the whole series; broke out btrfs changes from vfs change
(can send btrfs changes (much) later), made my own backup super update
function to just avoid collision with dchinner, and changed the max length
handling a bit so we don't have 256-byte arrays on the stack.

xfs list only for now 'cause I probably did something wrong in xfs land
and don't want to subject everyone else to it.  ;)

Thanks,
-Eric

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

* [PATCH V2 1/5] fs: copy BTRFS_IOC_[SG]ET_FSLABEL to vfs
  2018-05-14 17:30 [PATCH V2 0/5] xfs: online label Eric Sandeen
@ 2018-05-14 17:35 ` Eric Sandeen
  2018-05-14 17:37   ` Darrick J. Wong
  2018-05-14 17:36 ` [PATCH 2/4] xfs: New function for secondary superblock updates Eric Sandeen
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 20+ messages in thread
From: Eric Sandeen @ 2018-05-14 17:35 UTC (permalink / raw)
  To: Eric Sandeen, linux-xfs

This retains 256 chars as the maximum size through the interface, which
is the btrfs limit and AFAIK exceeds any other filesystem's maximum
label size.

This just copies the ioctl for now and leaves it in place for btrfs
for the time being.  A later patch will allow btrfs to use the new
common ioctl definition, but it may be sent after this is merged.

(Note, Reviewed-by's were originally given for the combined vfs+btrfs
patch, some license taken here.)

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Reviewed-by: David Sterba <dsterba@suse.com>
---
 Documentation/ioctl/ioctl-number.txt | 3 ++-
 include/uapi/linux/fs.h              | 8 ++++++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/Documentation/ioctl/ioctl-number.txt b/Documentation/ioctl/ioctl-number.txt
index 7f7413e597f3..27c1b7b78504 100644
--- a/Documentation/ioctl/ioctl-number.txt
+++ b/Documentation/ioctl/ioctl-number.txt
@@ -296,7 +296,8 @@ Code  Seq#(hex)	Include File		Comments
 0x90	00	drivers/cdrom/sbpcd.h
 0x92	00-0F	drivers/usb/mon/mon_bin.c
 0x93	60-7F	linux/auto_fs.h
-0x94	all	fs/btrfs/ioctl.h
+0x94	all	fs/btrfs/ioctl.h	Btrfs filesystem
+		and linux/fs.h		some lifted to vfs/generic
 0x97	00-7F	fs/ceph/ioctl.h		Ceph file system
 0x99	00-0F				537-Addinboard driver
 					<mailto:buk@buks.ipn.de>
diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
index d2a8313fabd7..9d132f8f2df8 100644
--- a/include/uapi/linux/fs.h
+++ b/include/uapi/linux/fs.h
@@ -242,6 +242,8 @@ struct fsxattr {
 #define FICLONERANGE	_IOW(0x94, 13, struct file_clone_range)
 #define FIDEDUPERANGE	_IOWR(0x94, 54, struct file_dedupe_range)
 
+#define FSLABEL_MAX 256	/* Max chars for the interface; each fs may differ */
+
 #define	FS_IOC_GETFLAGS			_IOR('f', 1, long)
 #define	FS_IOC_SETFLAGS			_IOW('f', 2, long)
 #define	FS_IOC_GETVERSION		_IOR('v', 1, long)
@@ -251,8 +253,10 @@ struct fsxattr {
 #define FS_IOC32_SETFLAGS		_IOW('f', 2, int)
 #define FS_IOC32_GETVERSION		_IOR('v', 1, int)
 #define FS_IOC32_SETVERSION		_IOW('v', 2, int)
-#define FS_IOC_FSGETXATTR		_IOR ('X', 31, struct fsxattr)
-#define FS_IOC_FSSETXATTR		_IOW ('X', 32, struct fsxattr)
+#define FS_IOC_FSGETXATTR		_IOR('X', 31, struct fsxattr)
+#define FS_IOC_FSSETXATTR		_IOW('X', 32, struct fsxattr)
+#define FS_IOC_GETFSLABEL		_IOR(0x94, 49, char[FSLABEL_MAX])
+#define FS_IOC_SETFSLABEL		_IOW(0x94, 50, char[FSLABEL_MAX])
 
 /*
  * File system encryption support
-- 
2.17.0


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

* [PATCH 2/4] xfs: New function for secondary superblock updates
  2018-05-14 17:30 [PATCH V2 0/5] xfs: online label Eric Sandeen
  2018-05-14 17:35 ` [PATCH V2 1/5] fs: copy BTRFS_IOC_[SG]ET_FSLABEL to vfs Eric Sandeen
@ 2018-05-14 17:36 ` Eric Sandeen
  2018-05-15 20:17   ` Darrick J. Wong
  2018-05-14 17:39 ` [PATCH 3/5 V2] xfs: implement online get/set fs label Eric Sandeen
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 20+ messages in thread
From: Eric Sandeen @ 2018-05-14 17:36 UTC (permalink / raw)
  To: Eric Sandeen, linux-xfs

Relabel must update all secondary superblocks, as offline relabel does.

This is essentially a simpler copy of the current growfs code, which is
undergoing an independent refactor; we can see about merging stuff back
together after all this work is done.  In the meantime, this is a fairly
small, simple bit of code to facilitate the online label work.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
 fs/xfs/xfs_fsops.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/xfs/xfs_fsops.h |  1 +
 2 files changed, 49 insertions(+)

diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c
index 523792768080..1aaa93051f78 100644
--- a/fs/xfs/xfs_fsops.c
+++ b/fs/xfs/xfs_fsops.c
@@ -71,6 +71,54 @@ xfs_growfs_get_hdr_buf(
 	return bp;
 }
 
+/*
+ * Copy the contents of the primary super to all backup supers.
+ * Not currently used for growfs, as it only looks at existing supers.
+ */
+int
+xfs_update_secondary_supers(
+	xfs_mount_t		*mp)
+{
+	int			error, saved_error;
+	xfs_agnumber_t		agno;
+	xfs_buf_t		*bp;
+
+	error = saved_error = 0;
+
+	for (agno = 1; agno < mp->m_sb.sb_agcount; agno++) {
+		error = xfs_trans_read_buf(mp, NULL, mp->m_ddev_targp,
+			  XFS_AGB_TO_DADDR(mp, agno, XFS_SB_BLOCK(mp)),
+			  XFS_FSS_TO_BB(mp, 1), 0, &bp, &xfs_sb_buf_ops);
+		/*
+		 * If we get an error reading or writing alternate superblocks,
+		 * continue.  xfs_repair chooses the "best" superblock based
+		 * on most matches; if we break early, we'll leave more
+		 * superblocks un-updated than updated, and xfs_repair may
+		 * pick them over the properly-updated primary.
+		 */
+		if (error) {
+			xfs_warn(mp,
+		"error %d reading secondary superblock for ag %d",
+				error, agno);
+			saved_error = error;
+			continue;
+		}
+		xfs_sb_to_disk(XFS_BUF_TO_SBP(bp), &mp->m_sb);
+
+		error = xfs_bwrite(bp);
+		xfs_buf_relse(bp);
+		if (error) {
+			xfs_warn(mp,
+		"write error %d updating secondary superblock for ag %d",
+				error, agno);
+			saved_error = error;
+			continue;
+		}
+	}
+
+	return saved_error ? saved_error : error;
+}
+
 static int
 xfs_growfs_data_private(
 	xfs_mount_t		*mp,		/* mount point for filesystem */
diff --git a/fs/xfs/xfs_fsops.h b/fs/xfs/xfs_fsops.h
index 20484ed5e919..257d3018bc39 100644
--- a/fs/xfs/xfs_fsops.h
+++ b/fs/xfs/xfs_fsops.h
@@ -18,6 +18,7 @@
 #ifndef __XFS_FSOPS_H__
 #define	__XFS_FSOPS_H__
 
+extern int xfs_update_secondary_supers(xfs_mount_t *mp);
 extern int xfs_growfs_data(xfs_mount_t *mp, xfs_growfs_data_t *in);
 extern int xfs_growfs_log(xfs_mount_t *mp, xfs_growfs_log_t *in);
 extern int xfs_fs_counts(xfs_mount_t *mp, xfs_fsop_counts_t *cnt);
-- 
2.17.0


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

* Re: [PATCH V2 1/5] fs: copy BTRFS_IOC_[SG]ET_FSLABEL to vfs
  2018-05-14 17:35 ` [PATCH V2 1/5] fs: copy BTRFS_IOC_[SG]ET_FSLABEL to vfs Eric Sandeen
@ 2018-05-14 17:37   ` Darrick J. Wong
  0 siblings, 0 replies; 20+ messages in thread
From: Darrick J. Wong @ 2018-05-14 17:37 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: linux-xfs

On Mon, May 14, 2018 at 12:35:18PM -0500, Eric Sandeen wrote:
> This retains 256 chars as the maximum size through the interface, which
> is the btrfs limit and AFAIK exceeds any other filesystem's maximum
> label size.
> 
> This just copies the ioctl for now and leaves it in place for btrfs
> for the time being.  A later patch will allow btrfs to use the new
> common ioctl definition, but it may be sent after this is merged.
> 
> (Note, Reviewed-by's were originally given for the combined vfs+btrfs
> patch, some license taken here.)
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> Reviewed-by: Andreas Dilger <adilger@dilger.ca>
> Reviewed-by: David Sterba <dsterba@suse.com>

Looks ok, having decided not to fuss about whitespace this time:
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

--D

> ---
>  Documentation/ioctl/ioctl-number.txt | 3 ++-
>  include/uapi/linux/fs.h              | 8 ++++++--
>  2 files changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/ioctl/ioctl-number.txt b/Documentation/ioctl/ioctl-number.txt
> index 7f7413e597f3..27c1b7b78504 100644
> --- a/Documentation/ioctl/ioctl-number.txt
> +++ b/Documentation/ioctl/ioctl-number.txt
> @@ -296,7 +296,8 @@ Code  Seq#(hex)	Include File		Comments
>  0x90	00	drivers/cdrom/sbpcd.h
>  0x92	00-0F	drivers/usb/mon/mon_bin.c
>  0x93	60-7F	linux/auto_fs.h
> -0x94	all	fs/btrfs/ioctl.h
> +0x94	all	fs/btrfs/ioctl.h	Btrfs filesystem
> +		and linux/fs.h		some lifted to vfs/generic
>  0x97	00-7F	fs/ceph/ioctl.h		Ceph file system
>  0x99	00-0F				537-Addinboard driver
>  					<mailto:buk@buks.ipn.de>
> diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
> index d2a8313fabd7..9d132f8f2df8 100644
> --- a/include/uapi/linux/fs.h
> +++ b/include/uapi/linux/fs.h
> @@ -242,6 +242,8 @@ struct fsxattr {
>  #define FICLONERANGE	_IOW(0x94, 13, struct file_clone_range)
>  #define FIDEDUPERANGE	_IOWR(0x94, 54, struct file_dedupe_range)
>  
> +#define FSLABEL_MAX 256	/* Max chars for the interface; each fs may differ */
> +
>  #define	FS_IOC_GETFLAGS			_IOR('f', 1, long)
>  #define	FS_IOC_SETFLAGS			_IOW('f', 2, long)
>  #define	FS_IOC_GETVERSION		_IOR('v', 1, long)
> @@ -251,8 +253,10 @@ struct fsxattr {
>  #define FS_IOC32_SETFLAGS		_IOW('f', 2, int)
>  #define FS_IOC32_GETVERSION		_IOR('v', 1, int)
>  #define FS_IOC32_SETVERSION		_IOW('v', 2, int)
> -#define FS_IOC_FSGETXATTR		_IOR ('X', 31, struct fsxattr)
> -#define FS_IOC_FSSETXATTR		_IOW ('X', 32, struct fsxattr)
> +#define FS_IOC_FSGETXATTR		_IOR('X', 31, struct fsxattr)
> +#define FS_IOC_FSSETXATTR		_IOW('X', 32, struct fsxattr)
> +#define FS_IOC_GETFSLABEL		_IOR(0x94, 49, char[FSLABEL_MAX])
> +#define FS_IOC_SETFSLABEL		_IOW(0x94, 50, char[FSLABEL_MAX])
>  
>  /*
>   * File system encryption support
> -- 
> 2.17.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH 3/5 V2] xfs: implement online get/set fs label
  2018-05-14 17:30 [PATCH V2 0/5] xfs: online label Eric Sandeen
  2018-05-14 17:35 ` [PATCH V2 1/5] fs: copy BTRFS_IOC_[SG]ET_FSLABEL to vfs Eric Sandeen
  2018-05-14 17:36 ` [PATCH 2/4] xfs: New function for secondary superblock updates Eric Sandeen
@ 2018-05-14 17:39 ` Eric Sandeen
  2018-05-15  1:07   ` Darrick J. Wong
  2018-05-14 17:42 ` [PATCH 4/5] btrfs: use common label ioctl definitions Eric Sandeen
  2018-05-14 17:43 ` [PATCH 5/5] xfs_io: add label command Eric Sandeen
  4 siblings, 1 reply; 20+ messages in thread
From: Eric Sandeen @ 2018-05-14 17:39 UTC (permalink / raw)
  To: Eric Sandeen, linux-xfs

The GET ioctl is trivial, just return the current label.

The SET ioctl is more involved:
It transactionally modifies the superblock to write a new filesystem
label to the primary super.

A new variant of xfs_sync_sb then writes the superblock buffer
immediately to disk so that the change is visible from userspace.

It then invalidates any page cache that userspace might have previously
read on the block device so that i.e. blkid can see the change
immediately, and updates all secondary superblocks as userspace relable
does.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

V2, rework the max length handling a bit, add comments re: userspace,
do the blkdev flush at the end, sleep for growfs lock, add locking around
getlabel, add define for max label length ...

 fs/xfs/libxfs/xfs_format.h |  7 +++-
 fs/xfs/libxfs/xfs_sb.c     | 30 +++++++++++++
 fs/xfs/libxfs/xfs_sb.h     |  1 +
 fs/xfs/xfs_ioctl.c         | 86 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 122 insertions(+), 2 deletions(-)

diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
index 42956d8d95ed..c1cb29a5f4f6 100644
--- a/fs/xfs/libxfs/xfs_format.h
+++ b/fs/xfs/libxfs/xfs_format.h
@@ -98,6 +98,9 @@ struct xfs_ifork;
 	 XFS_SB_VERSION2_PROJID32BIT	| \
 	 XFS_SB_VERSION2_FTYPE)
 
+/* Maximum size of the xfs filesystem label, no terminating NULL */
+#define XFSLABEL_MAX			12
+
 /*
  * Superblock - in core version.  Must match the ondisk version below.
  * Must be padded to 64 bit alignment.
@@ -122,7 +125,7 @@ typedef struct xfs_sb {
 	uint16_t	sb_sectsize;	/* volume sector size, bytes */
 	uint16_t	sb_inodesize;	/* inode size, bytes */
 	uint16_t	sb_inopblock;	/* inodes per block */
-	char		sb_fname[12];	/* file system name */
+	char		sb_fname[XFSLABEL_MAX]; /* file system name */
 	uint8_t		sb_blocklog;	/* log2 of sb_blocksize */
 	uint8_t		sb_sectlog;	/* log2 of sb_sectsize */
 	uint8_t		sb_inodelog;	/* log2 of sb_inodesize */
@@ -213,7 +216,7 @@ typedef struct xfs_dsb {
 	__be16		sb_sectsize;	/* volume sector size, bytes */
 	__be16		sb_inodesize;	/* inode size, bytes */
 	__be16		sb_inopblock;	/* inodes per block */
-	char		sb_fname[12];	/* file system name */
+	char		sb_fname[XFSLABEL_MAX]; /* file system name */
 	__u8		sb_blocklog;	/* log2 of sb_blocksize */
 	__u8		sb_sectlog;	/* log2 of sb_sectsize */
 	__u8		sb_inodelog;	/* log2 of sb_inodesize */
diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c
index d9b94bd5f689..0bc0a40764e1 100644
--- a/fs/xfs/libxfs/xfs_sb.c
+++ b/fs/xfs/libxfs/xfs_sb.c
@@ -888,6 +888,36 @@ xfs_sync_sb(
 	return xfs_trans_commit(tp);
 }
 
+/*
+ * Same behavior as xfs_sync_sb, except that it is always synchronous and it
+ * also writes the superblock buffer to disk sector 0 immediately.
+ */
+int
+xfs_sync_sb_buf(
+	struct xfs_mount	*mp)
+{
+	struct xfs_trans	*tp;
+	int			error;
+
+	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_sb, 0, 0, 0, &tp);
+	if (error)
+		return error;
+
+	xfs_log_sb(tp);
+	xfs_trans_bhold(tp, mp->m_sb_bp);
+	xfs_trans_set_sync(tp);
+	error = xfs_trans_commit(tp);
+	if (error)
+		goto out;
+	/*
+	 * write out the sb buffer to get the changes to disk
+	 */
+	error = xfs_bwrite(mp->m_sb_bp);
+out:
+	xfs_buf_relse(mp->m_sb_bp);
+	return error;
+}
+
 int
 xfs_fs_geometry(
 	struct xfs_sb		*sbp,
diff --git a/fs/xfs/libxfs/xfs_sb.h b/fs/xfs/libxfs/xfs_sb.h
index 63dcd2a1a657..226827281760 100644
--- a/fs/xfs/libxfs/xfs_sb.h
+++ b/fs/xfs/libxfs/xfs_sb.h
@@ -29,6 +29,7 @@ extern int	xfs_initialize_perag_data(struct xfs_mount *, xfs_agnumber_t);
 
 extern void	xfs_log_sb(struct xfs_trans *tp);
 extern int	xfs_sync_sb(struct xfs_mount *mp, bool wait);
+extern int	xfs_sync_sb_buf(struct xfs_mount *mp);
 extern void	xfs_sb_mount_common(struct xfs_mount *mp, struct xfs_sb *sbp);
 extern void	xfs_sb_from_disk(struct xfs_sb *to, struct xfs_dsb *from);
 extern void	xfs_sb_to_disk(struct xfs_dsb *to, struct xfs_sb *from);
diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
index 89fb1eb80aae..5e7116ff3dd3 100644
--- a/fs/xfs/xfs_ioctl.c
+++ b/fs/xfs/xfs_ioctl.c
@@ -1811,6 +1811,88 @@ xfs_ioc_swapext(
 	return error;
 }
 
+static int
+xfs_ioc_getlabel(
+	struct xfs_mount	*mp,
+	char			__user *user_label)
+{
+	struct xfs_sb		*sbp = &mp->m_sb;
+	char			label[XFSLABEL_MAX + 1];
+
+	/* Paranoia */
+	BUILD_BUG_ON(sizeof(sbp->sb_fname) > FSLABEL_MAX);
+
+	spin_lock(&mp->m_sb_lock);
+	strncpy(label, sbp->sb_fname, sizeof(sbp->sb_fname));
+	spin_unlock(&mp->m_sb_lock);
+
+	/* xfs on-disk label is 12 chars, be sure we send a null to user */
+	label[XFSLABEL_MAX] = '\0';
+	if (copy_to_user(user_label, label, sizeof(sbp->sb_fname)))
+		return -EFAULT;
+	return 0;
+}
+
+static int
+xfs_ioc_setlabel(
+	struct file		*filp,
+	struct xfs_mount	*mp,
+	char			__user *newlabel)
+{
+	struct xfs_sb		*sbp = &mp->m_sb;
+	char			label[XFSLABEL_MAX + 1];
+	size_t			len;
+	int			error;
+
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+	/*
+	 * The generic ioctl allows up to FSLABEL_MAX chars, but XFS is much
+	 * smaller, at 12 bytes.  We copy one more to be sure we find the
+	 * (required) NULL character to test the incoming label length.
+	 * NB: The on disk label doesn't need to be null terminated.
+	 */
+	if (copy_from_user(label, newlabel, XFSLABEL_MAX + 1))
+		return -EFAULT;
+	len = strnlen(label, XFSLABEL_MAX + 1);
+	if (len > sizeof(sbp->sb_fname))
+		return -EINVAL;
+
+	error = mnt_want_write_file(filp);
+	if (error)
+		return error;
+
+	spin_lock(&mp->m_sb_lock);
+	memset(sbp->sb_fname, 0, sizeof(sbp->sb_fname));
+	strncpy(sbp->sb_fname, label, sizeof(sbp->sb_fname));
+	spin_unlock(&mp->m_sb_lock);
+
+	/*
+	 * Now we do several things to satisfy userspace.
+	 * In addition to normal logging of the primary superblock, we also
+	 * immediately write these changes to sector zero for the primary, then
+	 * update all backup supers (as xfs_db does for a label change), then
+	 * invalidate the block device page cache.  This is so that any prior
+	 * buffered reads from userspace (i.e. from blkid) are invalidated,
+	 * and userspace will see the newly-written label.
+	 */
+	error = xfs_sync_sb_buf(mp);
+	if (error)
+		goto out;
+	/*
+	 * growfs also updates backup supers so lock against that.
+	 */
+	mutex_lock(&mp->m_growlock);
+	error = xfs_update_secondary_supers(mp);
+	mutex_unlock(&mp->m_growlock);
+
+	invalidate_bdev(mp->m_ddev_targp->bt_bdev);
+
+out:
+	mnt_drop_write_file(filp);
+	return error;
+}
+
 /*
  * Note: some of the ioctl's return positive numbers as a
  * byte count indicating success, such as readlink_by_handle.
@@ -1834,6 +1916,10 @@ xfs_file_ioctl(
 	switch (cmd) {
 	case FITRIM:
 		return xfs_ioc_trim(mp, arg);
+	case FS_IOC_GETFSLABEL:
+		return xfs_ioc_getlabel(mp, arg);
+	case FS_IOC_SETFSLABEL:
+		return xfs_ioc_setlabel(filp, mp, arg);
 	case XFS_IOC_ALLOCSP:
 	case XFS_IOC_FREESP:
 	case XFS_IOC_RESVSP:
-- 
2.17.0



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

* [PATCH 4/5] btrfs: use common label ioctl definitions
  2018-05-14 17:30 [PATCH V2 0/5] xfs: online label Eric Sandeen
                   ` (2 preceding siblings ...)
  2018-05-14 17:39 ` [PATCH 3/5 V2] xfs: implement online get/set fs label Eric Sandeen
@ 2018-05-14 17:42 ` Eric Sandeen
  2018-05-14 21:41   ` Darrick J. Wong
  2018-05-14 17:43 ` [PATCH 5/5] xfs_io: add label command Eric Sandeen
  4 siblings, 1 reply; 20+ messages in thread
From: Eric Sandeen @ 2018-05-14 17:42 UTC (permalink / raw)
  To: Eric Sandeen, linux-xfs

Use the new common online get/set label get/set definitions.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

Mostly for reference; this can be sent explicitly to the btrfs list
after the common definitions are in place.  Happy to do that so btrfs
changes won't go through the xfs tree.

 fs/btrfs/ioctl.c           | 8 ++++----
 include/uapi/linux/btrfs.h | 6 ++----
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 632e26d6f7ce..8feea790bd00 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -5444,6 +5444,10 @@ long btrfs_ioctl(struct file *file, unsigned int
 		return btrfs_ioctl_setflags(file, argp);
 	case FS_IOC_GETVERSION:
 		return btrfs_ioctl_getversion(file, argp);
+	case FS_IOC_GETFSLABEL:
+		return btrfs_ioctl_get_fslabel(file, argp);
+	case FS_IOC_SETFSLABEL:
+		return btrfs_ioctl_set_fslabel(file, argp);
 	case FITRIM:
 		return btrfs_ioctl_fitrim(file, argp);
 	case BTRFS_IOC_SNAP_CREATE:
@@ -5555,10 +5559,6 @@ long btrfs_ioctl(struct file *file, unsigned int
 		return btrfs_ioctl_quota_rescan_wait(file, argp);
 	case BTRFS_IOC_DEV_REPLACE:
 		return btrfs_ioctl_dev_replace(fs_info, argp);
-	case BTRFS_IOC_GET_FSLABEL:
-		return btrfs_ioctl_get_fslabel(file, argp);
-	case BTRFS_IOC_SET_FSLABEL:
-		return btrfs_ioctl_set_fslabel(file, argp);
 	case BTRFS_IOC_GET_SUPPORTED_FEATURES:
 		return btrfs_ioctl_get_supported_features(argp);
 	case BTRFS_IOC_GET_FEATURES:
diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h
index c8d99b9ca550..af29cc9032a2 100644
--- a/include/uapi/linux/btrfs.h
+++ b/include/uapi/linux/btrfs.h
@@ -823,10 +823,8 @@ enum btrfs_err_code {
 #define BTRFS_IOC_QUOTA_RESCAN_STATUS _IOR(BTRFS_IOCTL_MAGIC, 45, \
 			       struct btrfs_ioctl_quota_rescan_args)
 #define BTRFS_IOC_QUOTA_RESCAN_WAIT _IO(BTRFS_IOCTL_MAGIC, 46)
-#define BTRFS_IOC_GET_FSLABEL _IOR(BTRFS_IOCTL_MAGIC, 49, \
-				   char[BTRFS_LABEL_SIZE])
-#define BTRFS_IOC_SET_FSLABEL _IOW(BTRFS_IOCTL_MAGIC, 50, \
-				   char[BTRFS_LABEL_SIZE])
+#define BTRFS_IOC_GET_FSLABEL 	FS_IOC_GETFSLABEL
+#define BTRFS_IOC_SET_FSLABEL	FS_IOC_SETFSLABEL
 #define BTRFS_IOC_GET_DEV_STATS _IOWR(BTRFS_IOCTL_MAGIC, 52, \
 				      struct btrfs_ioctl_get_dev_stats)
 #define BTRFS_IOC_DEV_REPLACE _IOWR(BTRFS_IOCTL_MAGIC, 53, \
-- 
2.17.0



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

* [PATCH 5/5] xfs_io: add label command
  2018-05-14 17:30 [PATCH V2 0/5] xfs: online label Eric Sandeen
                   ` (3 preceding siblings ...)
  2018-05-14 17:42 ` [PATCH 4/5] btrfs: use common label ioctl definitions Eric Sandeen
@ 2018-05-14 17:43 ` Eric Sandeen
  2018-05-15  4:32   ` Dave Chinner
  2018-05-15 15:32   ` [PATCH 5/5 V2] " Eric Sandeen
  4 siblings, 2 replies; 20+ messages in thread
From: Eric Sandeen @ 2018-05-14 17:43 UTC (permalink / raw)
  To: Eric Sandeen, linux-xfs

This adds a get/set label command to xfs_io.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

diff --git a/io/Makefile b/io/Makefile
index 88e4751..b40156d 100644
--- a/io/Makefile
+++ b/io/Makefile
@@ -10,9 +10,9 @@ LSRCFILES = xfs_bmap.sh xfs_freeze.sh xfs_mkfile.sh
 HFILES = init.h io.h
 CFILES = init.c \
 	attr.c bmap.c cowextsize.c encrypt.c file.c freeze.c fsync.c \
-	getrusage.c imap.c link.c mmap.c open.c parent.c pread.c prealloc.c \
-	pwrite.c reflink.c scrub.c seek.c shutdown.c stat.c swapext.c sync.c \
-	truncate.c utimes.c
+	getrusage.c imap.c label.c link.c mmap.c open.c parent.c pread.c \
+	prealloc.c pwrite.c reflink.c scrub.c seek.c shutdown.c stat.c \
+	swapext.c sync.c truncate.c utimes.c
 
 LLDLIBS = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG) $(LIBPTHREAD)
 LTDEPENDENCIES = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG)
diff --git a/io/init.c b/io/init.c
index 0336c96..612962e 100644
--- a/io/init.c
+++ b/io/init.c
@@ -72,6 +72,7 @@ init_commands(void)
 	help_init();
 	imap_init();
 	inject_init();
+	label_init();
 	log_writes_init();
 	madvise_init();
 	mincore_init();
diff --git a/io/io.h b/io/io.h
index a267636..7f8197c 100644
--- a/io/io.h
+++ b/io/io.h
@@ -109,6 +109,7 @@ extern void		getrusage_init(void);
 extern void		help_init(void);
 extern void		imap_init(void);
 extern void		inject_init(void);
+extern void		label_init(void);
 extern void		mmap_init(void);
 extern void		open_init(void);
 extern void		parent_init(void);
diff --git a/io/label.c b/io/label.c
new file mode 100644
index 0000000..acab67f
--- /dev/null
+++ b/io/label.c
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2018 Red Hat, Inc.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <sys/ioctl.h>
+#include <sys/mount.h>
+#include "platform_defs.h"
+#include "libxfs.h"
+#include "path.h"
+#include "command.h"
+#include "init.h"
+#include "io.h"
+
+#ifndef FS_IOC_GET_FSLABEL
+/* Max chars for the interface; fs limits may differ */
+#define FSLABEL_MAX 256
+#define FS_IOC_GET_FSLABEL		_IOR(0x94, 49, char[FSLABEL_MAX])
+#define FS_IOC_SET_FSLABEL		_IOW(0x94, 50, char[FSLABEL_MAX])
+#endif
+
+static cmdinfo_t label_cmd;
+
+static int
+label_f(
+	int		argc,
+	char		**argv)
+{
+	int		error;
+	char		label[FSLABEL_MAX];
+
+	if (argc == 1) {
+		memset(&label, 0, sizeof(label));
+		error = ioctl(file->fd, FS_IOC_GET_FSLABEL, &label);
+	} else {
+		strncpy(label, argv[1], sizeof(label));
+		error = ioctl(file->fd, FS_IOC_SET_FSLABEL, &label);
+	}
+
+	if (error)
+		perror("label");
+	else
+		printf("label = \"%s\"\n", label);
+
+	return error;
+}
+
+void
+label_init(void)
+{
+	label_cmd.name = "label";
+	label_cmd.cfunc = label_f;
+	label_cmd.argmin = 0;
+	label_cmd.argmax = 1;
+	label_cmd.args = _("[label]");
+	label_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
+	label_cmd.oneline =
+		_("query or set the filesystem label while mounted");
+
+	add_command(&label_cmd);
+}
diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
index c3ab532..52b983d 100644
--- a/man/man8/xfs_io.8
+++ b/man/man8/xfs_io.8
@@ -1175,6 +1175,16 @@ This is intended to be equivalent to the shell command:
 See the
 .B log_writes
 command.
+.TP
+.BI "label" " " [ " label " ]
+On  filesystems  that  support  online label manipulation, set or get the
+filesystem label.  With no options, get the current filesystem label.
+With one option, set the filesystem label to
+.IR label .
+If the label is longer than the filesystem will accept,
+.B xfs_io
+will print an error message.  XFS filesystem labels can be at most 12
+characters long.
 .SH SEE ALSO
 .BR mkfs.xfs (8),
 .BR xfsctl (3),

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

* Re: [PATCH 4/5] btrfs: use common label ioctl definitions
  2018-05-14 17:42 ` [PATCH 4/5] btrfs: use common label ioctl definitions Eric Sandeen
@ 2018-05-14 21:41   ` Darrick J. Wong
  0 siblings, 0 replies; 20+ messages in thread
From: Darrick J. Wong @ 2018-05-14 21:41 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: Eric Sandeen, linux-xfs

On Mon, May 14, 2018 at 12:42:10PM -0500, Eric Sandeen wrote:
> Use the new common online get/set label get/set definitions.
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
> 
> Mostly for reference; this can be sent explicitly to the btrfs list
> after the common definitions are in place.  Happy to do that so btrfs
> changes won't go through the xfs tree.
> 
>  fs/btrfs/ioctl.c           | 8 ++++----
>  include/uapi/linux/btrfs.h | 6 ++----
>  2 files changed, 6 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 632e26d6f7ce..8feea790bd00 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -5444,6 +5444,10 @@ long btrfs_ioctl(struct file *file, unsigned int
>  		return btrfs_ioctl_setflags(file, argp);
>  	case FS_IOC_GETVERSION:
>  		return btrfs_ioctl_getversion(file, argp);
> +	case FS_IOC_GETFSLABEL:
> +		return btrfs_ioctl_get_fslabel(file, argp);
> +	case FS_IOC_SETFSLABEL:
> +		return btrfs_ioctl_set_fslabel(file, argp);
>  	case FITRIM:
>  		return btrfs_ioctl_fitrim(file, argp);
>  	case BTRFS_IOC_SNAP_CREATE:
> @@ -5555,10 +5559,6 @@ long btrfs_ioctl(struct file *file, unsigned int
>  		return btrfs_ioctl_quota_rescan_wait(file, argp);
>  	case BTRFS_IOC_DEV_REPLACE:
>  		return btrfs_ioctl_dev_replace(fs_info, argp);
> -	case BTRFS_IOC_GET_FSLABEL:
> -		return btrfs_ioctl_get_fslabel(file, argp);
> -	case BTRFS_IOC_SET_FSLABEL:
> -		return btrfs_ioctl_set_fslabel(file, argp);
>  	case BTRFS_IOC_GET_SUPPORTED_FEATURES:
>  		return btrfs_ioctl_get_supported_features(argp);
>  	case BTRFS_IOC_GET_FEATURES:
> diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h
> index c8d99b9ca550..af29cc9032a2 100644
> --- a/include/uapi/linux/btrfs.h
> +++ b/include/uapi/linux/btrfs.h
> @@ -823,10 +823,8 @@ enum btrfs_err_code {
>  #define BTRFS_IOC_QUOTA_RESCAN_STATUS _IOR(BTRFS_IOCTL_MAGIC, 45, \
>  			       struct btrfs_ioctl_quota_rescan_args)
>  #define BTRFS_IOC_QUOTA_RESCAN_WAIT _IO(BTRFS_IOCTL_MAGIC, 46)
> -#define BTRFS_IOC_GET_FSLABEL _IOR(BTRFS_IOCTL_MAGIC, 49, \
> -				   char[BTRFS_LABEL_SIZE])
> -#define BTRFS_IOC_SET_FSLABEL _IOW(BTRFS_IOCTL_MAGIC, 50, \
> -				   char[BTRFS_LABEL_SIZE])
> +#define BTRFS_IOC_GET_FSLABEL 	FS_IOC_GETFSLABEL

Looks ok other than the space after '_GET_FSLABEL'...

Acked-by: Darrick J. Wong <darrick.wong@oracle.com>

--D

> +#define BTRFS_IOC_SET_FSLABEL	FS_IOC_SETFSLABEL
>  #define BTRFS_IOC_GET_DEV_STATS _IOWR(BTRFS_IOCTL_MAGIC, 52, \
>  				      struct btrfs_ioctl_get_dev_stats)
>  #define BTRFS_IOC_DEV_REPLACE _IOWR(BTRFS_IOCTL_MAGIC, 53, \
> -- 
> 2.17.0
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 3/5 V2] xfs: implement online get/set fs label
  2018-05-14 17:39 ` [PATCH 3/5 V2] xfs: implement online get/set fs label Eric Sandeen
@ 2018-05-15  1:07   ` Darrick J. Wong
  2018-05-16  1:04     ` Darrick J. Wong
  0 siblings, 1 reply; 20+ messages in thread
From: Darrick J. Wong @ 2018-05-15  1:07 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: Eric Sandeen, linux-xfs

On Mon, May 14, 2018 at 12:39:19PM -0500, Eric Sandeen wrote:
> The GET ioctl is trivial, just return the current label.
> 
> The SET ioctl is more involved:
> It transactionally modifies the superblock to write a new filesystem
> label to the primary super.
> 
> A new variant of xfs_sync_sb then writes the superblock buffer
> immediately to disk so that the change is visible from userspace.
> 
> It then invalidates any page cache that userspace might have previously
> read on the block device so that i.e. blkid can see the change
> immediately, and updates all secondary superblocks as userspace relable
> does.
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>

Looks ok, to me....
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

--D

> ---
> 
> V2, rework the max length handling a bit, add comments re: userspace,
> do the blkdev flush at the end, sleep for growfs lock, add locking around
> getlabel, add define for max label length ...
> 
>  fs/xfs/libxfs/xfs_format.h |  7 +++-
>  fs/xfs/libxfs/xfs_sb.c     | 30 +++++++++++++
>  fs/xfs/libxfs/xfs_sb.h     |  1 +
>  fs/xfs/xfs_ioctl.c         | 86 ++++++++++++++++++++++++++++++++++++++
>  4 files changed, 122 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
> index 42956d8d95ed..c1cb29a5f4f6 100644
> --- a/fs/xfs/libxfs/xfs_format.h
> +++ b/fs/xfs/libxfs/xfs_format.h
> @@ -98,6 +98,9 @@ struct xfs_ifork;
>  	 XFS_SB_VERSION2_PROJID32BIT	| \
>  	 XFS_SB_VERSION2_FTYPE)
>  
> +/* Maximum size of the xfs filesystem label, no terminating NULL */
> +#define XFSLABEL_MAX			12
> +
>  /*
>   * Superblock - in core version.  Must match the ondisk version below.
>   * Must be padded to 64 bit alignment.
> @@ -122,7 +125,7 @@ typedef struct xfs_sb {
>  	uint16_t	sb_sectsize;	/* volume sector size, bytes */
>  	uint16_t	sb_inodesize;	/* inode size, bytes */
>  	uint16_t	sb_inopblock;	/* inodes per block */
> -	char		sb_fname[12];	/* file system name */
> +	char		sb_fname[XFSLABEL_MAX]; /* file system name */
>  	uint8_t		sb_blocklog;	/* log2 of sb_blocksize */
>  	uint8_t		sb_sectlog;	/* log2 of sb_sectsize */
>  	uint8_t		sb_inodelog;	/* log2 of sb_inodesize */
> @@ -213,7 +216,7 @@ typedef struct xfs_dsb {
>  	__be16		sb_sectsize;	/* volume sector size, bytes */
>  	__be16		sb_inodesize;	/* inode size, bytes */
>  	__be16		sb_inopblock;	/* inodes per block */
> -	char		sb_fname[12];	/* file system name */
> +	char		sb_fname[XFSLABEL_MAX]; /* file system name */
>  	__u8		sb_blocklog;	/* log2 of sb_blocksize */
>  	__u8		sb_sectlog;	/* log2 of sb_sectsize */
>  	__u8		sb_inodelog;	/* log2 of sb_inodesize */
> diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c
> index d9b94bd5f689..0bc0a40764e1 100644
> --- a/fs/xfs/libxfs/xfs_sb.c
> +++ b/fs/xfs/libxfs/xfs_sb.c
> @@ -888,6 +888,36 @@ xfs_sync_sb(
>  	return xfs_trans_commit(tp);
>  }
>  
> +/*
> + * Same behavior as xfs_sync_sb, except that it is always synchronous and it
> + * also writes the superblock buffer to disk sector 0 immediately.
> + */
> +int
> +xfs_sync_sb_buf(
> +	struct xfs_mount	*mp)
> +{
> +	struct xfs_trans	*tp;
> +	int			error;
> +
> +	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_sb, 0, 0, 0, &tp);
> +	if (error)
> +		return error;
> +
> +	xfs_log_sb(tp);
> +	xfs_trans_bhold(tp, mp->m_sb_bp);
> +	xfs_trans_set_sync(tp);
> +	error = xfs_trans_commit(tp);
> +	if (error)
> +		goto out;
> +	/*
> +	 * write out the sb buffer to get the changes to disk
> +	 */
> +	error = xfs_bwrite(mp->m_sb_bp);
> +out:
> +	xfs_buf_relse(mp->m_sb_bp);
> +	return error;
> +}
> +
>  int
>  xfs_fs_geometry(
>  	struct xfs_sb		*sbp,
> diff --git a/fs/xfs/libxfs/xfs_sb.h b/fs/xfs/libxfs/xfs_sb.h
> index 63dcd2a1a657..226827281760 100644
> --- a/fs/xfs/libxfs/xfs_sb.h
> +++ b/fs/xfs/libxfs/xfs_sb.h
> @@ -29,6 +29,7 @@ extern int	xfs_initialize_perag_data(struct xfs_mount *, xfs_agnumber_t);
>  
>  extern void	xfs_log_sb(struct xfs_trans *tp);
>  extern int	xfs_sync_sb(struct xfs_mount *mp, bool wait);
> +extern int	xfs_sync_sb_buf(struct xfs_mount *mp);
>  extern void	xfs_sb_mount_common(struct xfs_mount *mp, struct xfs_sb *sbp);
>  extern void	xfs_sb_from_disk(struct xfs_sb *to, struct xfs_dsb *from);
>  extern void	xfs_sb_to_disk(struct xfs_dsb *to, struct xfs_sb *from);
> diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
> index 89fb1eb80aae..5e7116ff3dd3 100644
> --- a/fs/xfs/xfs_ioctl.c
> +++ b/fs/xfs/xfs_ioctl.c
> @@ -1811,6 +1811,88 @@ xfs_ioc_swapext(
>  	return error;
>  }
>  
> +static int
> +xfs_ioc_getlabel(
> +	struct xfs_mount	*mp,
> +	char			__user *user_label)
> +{
> +	struct xfs_sb		*sbp = &mp->m_sb;
> +	char			label[XFSLABEL_MAX + 1];
> +
> +	/* Paranoia */
> +	BUILD_BUG_ON(sizeof(sbp->sb_fname) > FSLABEL_MAX);
> +
> +	spin_lock(&mp->m_sb_lock);
> +	strncpy(label, sbp->sb_fname, sizeof(sbp->sb_fname));
> +	spin_unlock(&mp->m_sb_lock);
> +
> +	/* xfs on-disk label is 12 chars, be sure we send a null to user */
> +	label[XFSLABEL_MAX] = '\0';
> +	if (copy_to_user(user_label, label, sizeof(sbp->sb_fname)))
> +		return -EFAULT;
> +	return 0;
> +}
> +
> +static int
> +xfs_ioc_setlabel(
> +	struct file		*filp,
> +	struct xfs_mount	*mp,
> +	char			__user *newlabel)
> +{
> +	struct xfs_sb		*sbp = &mp->m_sb;
> +	char			label[XFSLABEL_MAX + 1];
> +	size_t			len;
> +	int			error;
> +
> +	if (!capable(CAP_SYS_ADMIN))
> +		return -EPERM;
> +	/*
> +	 * The generic ioctl allows up to FSLABEL_MAX chars, but XFS is much
> +	 * smaller, at 12 bytes.  We copy one more to be sure we find the
> +	 * (required) NULL character to test the incoming label length.
> +	 * NB: The on disk label doesn't need to be null terminated.
> +	 */
> +	if (copy_from_user(label, newlabel, XFSLABEL_MAX + 1))
> +		return -EFAULT;
> +	len = strnlen(label, XFSLABEL_MAX + 1);
> +	if (len > sizeof(sbp->sb_fname))
> +		return -EINVAL;
> +
> +	error = mnt_want_write_file(filp);
> +	if (error)
> +		return error;
> +
> +	spin_lock(&mp->m_sb_lock);
> +	memset(sbp->sb_fname, 0, sizeof(sbp->sb_fname));
> +	strncpy(sbp->sb_fname, label, sizeof(sbp->sb_fname));
> +	spin_unlock(&mp->m_sb_lock);
> +
> +	/*
> +	 * Now we do several things to satisfy userspace.
> +	 * In addition to normal logging of the primary superblock, we also
> +	 * immediately write these changes to sector zero for the primary, then
> +	 * update all backup supers (as xfs_db does for a label change), then
> +	 * invalidate the block device page cache.  This is so that any prior
> +	 * buffered reads from userspace (i.e. from blkid) are invalidated,
> +	 * and userspace will see the newly-written label.
> +	 */
> +	error = xfs_sync_sb_buf(mp);
> +	if (error)
> +		goto out;
> +	/*
> +	 * growfs also updates backup supers so lock against that.
> +	 */
> +	mutex_lock(&mp->m_growlock);
> +	error = xfs_update_secondary_supers(mp);
> +	mutex_unlock(&mp->m_growlock);
> +
> +	invalidate_bdev(mp->m_ddev_targp->bt_bdev);
> +
> +out:
> +	mnt_drop_write_file(filp);
> +	return error;
> +}
> +
>  /*
>   * Note: some of the ioctl's return positive numbers as a
>   * byte count indicating success, such as readlink_by_handle.
> @@ -1834,6 +1916,10 @@ xfs_file_ioctl(
>  	switch (cmd) {
>  	case FITRIM:
>  		return xfs_ioc_trim(mp, arg);
> +	case FS_IOC_GETFSLABEL:
> +		return xfs_ioc_getlabel(mp, arg);
> +	case FS_IOC_SETFSLABEL:
> +		return xfs_ioc_setlabel(filp, mp, arg);
>  	case XFS_IOC_ALLOCSP:
>  	case XFS_IOC_FREESP:
>  	case XFS_IOC_RESVSP:
> -- 
> 2.17.0
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 5/5] xfs_io: add label command
  2018-05-14 17:43 ` [PATCH 5/5] xfs_io: add label command Eric Sandeen
@ 2018-05-15  4:32   ` Dave Chinner
  2018-05-15 15:06     ` Eric Sandeen
  2018-05-15 15:32   ` [PATCH 5/5 V2] " Eric Sandeen
  1 sibling, 1 reply; 20+ messages in thread
From: Dave Chinner @ 2018-05-15  4:32 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: linux-xfs

On Mon, May 14, 2018 at 12:43:20PM -0500, Eric Sandeen wrote:
> This adds a get/set label command to xfs_io.
....
> +static int
> +label_f(
> +	int		argc,
> +	char		**argv)
> +{
> +	int		error;
> +	char		label[FSLABEL_MAX];
> +
> +	if (argc == 1) {
> +		memset(&label, 0, sizeof(label));
> +		error = ioctl(file->fd, FS_IOC_GET_FSLABEL, &label);
> +	} else {
> +		strncpy(label, argv[1], sizeof(label));
> +		error = ioctl(file->fd, FS_IOC_SET_FSLABEL, &label);
> +	}
> +
> +	if (error)
> +		perror("label");

Need to set exitcode = 1 here so that xfs_io fails with a non-zero
exit status....

> +	else
> +		printf("label = \"%s\"\n", label);
> +
> +	return error;

Because this isn't the exit status - this is the "continue
processing the next command" return value. i.e. return 0 if we want
to continue, non-zero if we want to abort further CLI processing....

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

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

* Re: [PATCH 5/5] xfs_io: add label command
  2018-05-15  4:32   ` Dave Chinner
@ 2018-05-15 15:06     ` Eric Sandeen
  2018-05-16  0:57       ` Dave Chinner
  0 siblings, 1 reply; 20+ messages in thread
From: Eric Sandeen @ 2018-05-15 15:06 UTC (permalink / raw)
  To: Dave Chinner, Eric Sandeen; +Cc: linux-xfs



On 5/14/18 11:32 PM, Dave Chinner wrote:
> On Mon, May 14, 2018 at 12:43:20PM -0500, Eric Sandeen wrote:
>> This adds a get/set label command to xfs_io.
> ....
>> +static int
>> +label_f(
>> +	int		argc,
>> +	char		**argv)
>> +{
>> +	int		error;
>> +	char		label[FSLABEL_MAX];
>> +
>> +	if (argc == 1) {
>> +		memset(&label, 0, sizeof(label));
>> +		error = ioctl(file->fd, FS_IOC_GET_FSLABEL, &label);
>> +	} else {
>> +		strncpy(label, argv[1], sizeof(label));
>> +		error = ioctl(file->fd, FS_IOC_SET_FSLABEL, &label);
>> +	}
>> +
>> +	if (error)
>> +		perror("label");
> 
> Need to set exitcode = 1 here so that xfs_io fails with a non-zero
> exit status....
> 
>> +	else
>> +		printf("label = \"%s\"\n", label);
>> +
>> +	return error;
> 
> Because this isn't the exit status - this is the "continue
> processing the next command" return value. i.e. return 0 if we want
> to continue, non-zero if we want to abort further CLI processing....

Hm, ok.  Today we only set exitcode for bmap, fiemap, freeze/thaw, and
imap.  It's really consistently used at all, and needs an audit I guess.

Maybe we should add an io_error() which sets it automatically, or something.

Anyway, I can add it here.

-Eric

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

* [PATCH 5/5 V2] xfs_io: add label command
  2018-05-14 17:43 ` [PATCH 5/5] xfs_io: add label command Eric Sandeen
  2018-05-15  4:32   ` Dave Chinner
@ 2018-05-15 15:32   ` Eric Sandeen
  2018-05-15 20:12     ` Darrick J. Wong
  2018-05-17 15:22     ` [PATCH 5/5 V3] " Eric Sandeen
  1 sibling, 2 replies; 20+ messages in thread
From: Eric Sandeen @ 2018-05-15 15:32 UTC (permalink / raw)
  To: Eric Sandeen, linux-xfs

This adds a get/set label command to xfs_io.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

V2: Set exitcode rather than error return on ioctl failure
     fix ioctl definitions o_O :)

diff --git a/io/Makefile b/io/Makefile
index 88e47517..b40156da 100644
--- a/io/Makefile
+++ b/io/Makefile
@@ -10,9 +10,9 @@ LSRCFILES = xfs_bmap.sh xfs_freeze.sh xfs_mkfile.sh
  HFILES = init.h io.h
  CFILES = init.c \
  	attr.c bmap.c cowextsize.c encrypt.c file.c freeze.c fsync.c \
-	getrusage.c imap.c link.c mmap.c open.c parent.c pread.c prealloc.c \
-	pwrite.c reflink.c scrub.c seek.c shutdown.c stat.c swapext.c sync.c \
-	truncate.c utimes.c
+	getrusage.c imap.c label.c link.c mmap.c open.c parent.c pread.c \
+	prealloc.c pwrite.c reflink.c scrub.c seek.c shutdown.c stat.c \
+	swapext.c sync.c truncate.c utimes.c
  
  LLDLIBS = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG) $(LIBPTHREAD)
  LTDEPENDENCIES = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG)
diff --git a/io/init.c b/io/init.c
index 0336c962..612962e8 100644
--- a/io/init.c
+++ b/io/init.c
@@ -72,6 +72,7 @@ init_commands(void)
  	help_init();
  	imap_init();
  	inject_init();
+	label_init();
  	log_writes_init();
  	madvise_init();
  	mincore_init();
diff --git a/io/io.h b/io/io.h
index a2676361..7f8197ca 100644
--- a/io/io.h
+++ b/io/io.h
@@ -109,6 +109,7 @@ extern void		getrusage_init(void);
  extern void		help_init(void);
  extern void		imap_init(void);
  extern void		inject_init(void);
+extern void		label_init(void);
  extern void		mmap_init(void);
  extern void		open_init(void);
  extern void		parent_init(void);
diff --git a/io/label.c b/io/label.c
new file mode 100644
index 00000000..7eeab324
--- /dev/null
+++ b/io/label.c
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2018 Red Hat, Inc.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <sys/ioctl.h>
+#include <sys/mount.h>
+#include "platform_defs.h"
+#include "libxfs.h"
+#include "path.h"
+#include "command.h"
+#include "init.h"
+#include "io.h"
+
+#ifndef FS_IOC_GETFSLABEL
+/* Max chars for the interface; fs limits may differ */
+#define FSLABEL_MAX 256
+#define FS_IOC_GETFSLABEL		_IOR(0x94, 49, char[FSLABEL_MAX])
+#define FS_IOC_SETFSLABEL		_IOW(0x94, 50, char[FSLABEL_MAX])
+#endif
+
+static cmdinfo_t label_cmd;
+
+static int
+label_f(
+	int		argc,
+	char		**argv)
+{
+	int		error;
+	char		label[FSLABEL_MAX];
+
+	if (argc == 1) {
+		memset(label, 0, sizeof(label));
+		error = ioctl(file->fd, FS_IOC_GETFSLABEL, &label);
+	} else {
+		strncpy(label, argv[1], sizeof(label));
+		error = ioctl(file->fd, FS_IOC_SETFSLABEL, label);
+	}
+
+	if (error) {
+		perror("label");
+		exitcode = 1;
+	} else
+		printf("label = \"%s\"\n", label);
+
+	return 0;
+}
+
+void
+label_init(void)
+{
+	label_cmd.name = "label";
+	label_cmd.cfunc = label_f;
+	label_cmd.argmin = 0;
+	label_cmd.argmax = 1;
+	label_cmd.args = _("[label]");
+	label_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
+	label_cmd.oneline =
+		_("query or set the filesystem label while mounted");
+
+	add_command(&label_cmd);
+}
diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
index c3ab532d..52b983d5 100644
--- a/man/man8/xfs_io.8
+++ b/man/man8/xfs_io.8
@@ -1175,6 +1175,16 @@ This is intended to be equivalent to the shell command:
  See the
  .B log_writes
  command.
+.TP
+.BI "label" " " [ " label " ]
+On  filesystems  that  support  online label manipulation, set or get the
+filesystem label.  With no options, get the current filesystem label.
+With one option, set the filesystem label to
+.IR label .
+If the label is longer than the filesystem will accept,
+.B xfs_io
+will print an error message.  XFS filesystem labels can be at most 12
+characters long, excluding any terminating NULL.
  .SH SEE ALSO
  .BR mkfs.xfs (8),
  .BR xfsctl (3),



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

* Re: [PATCH 5/5 V2] xfs_io: add label command
  2018-05-15 15:32   ` [PATCH 5/5 V2] " Eric Sandeen
@ 2018-05-15 20:12     ` Darrick J. Wong
  2018-05-17 15:22     ` [PATCH 5/5 V3] " Eric Sandeen
  1 sibling, 0 replies; 20+ messages in thread
From: Darrick J. Wong @ 2018-05-15 20:12 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: Eric Sandeen, linux-xfs

On Tue, May 15, 2018 at 10:32:22AM -0500, Eric Sandeen wrote:
> This adds a get/set label command to xfs_io.
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
> 
> V2: Set exitcode rather than error return on ioctl failure
>     fix ioctl definitions o_O :)
> 
> diff --git a/io/Makefile b/io/Makefile
> index 88e47517..b40156da 100644
> --- a/io/Makefile
> +++ b/io/Makefile
> @@ -10,9 +10,9 @@ LSRCFILES = xfs_bmap.sh xfs_freeze.sh xfs_mkfile.sh
>  HFILES = init.h io.h
>  CFILES = init.c \
>  	attr.c bmap.c cowextsize.c encrypt.c file.c freeze.c fsync.c \
> -	getrusage.c imap.c link.c mmap.c open.c parent.c pread.c prealloc.c \
> -	pwrite.c reflink.c scrub.c seek.c shutdown.c stat.c swapext.c sync.c \
> -	truncate.c utimes.c
> +	getrusage.c imap.c label.c link.c mmap.c open.c parent.c pread.c \
> +	prealloc.c pwrite.c reflink.c scrub.c seek.c shutdown.c stat.c \
> +	swapext.c sync.c truncate.c utimes.c
>  LLDLIBS = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG) $(LIBPTHREAD)
>  LTDEPENDENCIES = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG)
> diff --git a/io/init.c b/io/init.c
> index 0336c962..612962e8 100644
> --- a/io/init.c
> +++ b/io/init.c
> @@ -72,6 +72,7 @@ init_commands(void)
>  	help_init();
>  	imap_init();
>  	inject_init();
> +	label_init();
>  	log_writes_init();
>  	madvise_init();
>  	mincore_init();
> diff --git a/io/io.h b/io/io.h
> index a2676361..7f8197ca 100644
> --- a/io/io.h
> +++ b/io/io.h
> @@ -109,6 +109,7 @@ extern void		getrusage_init(void);
>  extern void		help_init(void);
>  extern void		imap_init(void);
>  extern void		inject_init(void);
> +extern void		label_init(void);
>  extern void		mmap_init(void);
>  extern void		open_init(void);
>  extern void		parent_init(void);
> diff --git a/io/label.c b/io/label.c
> new file mode 100644
> index 00000000..7eeab324
> --- /dev/null
> +++ b/io/label.c
> @@ -0,0 +1,75 @@
> +/*
> + * Copyright (c) 2018 Red Hat, Inc.
> + * All Rights Reserved.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it would be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write the Free Software Foundation,
> + * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
> + */
> +
> +#include <sys/ioctl.h>
> +#include <sys/mount.h>
> +#include "platform_defs.h"
> +#include "libxfs.h"
> +#include "path.h"
> +#include "command.h"
> +#include "init.h"
> +#include "io.h"
> +
> +#ifndef FS_IOC_GETFSLABEL
> +/* Max chars for the interface; fs limits may differ */
> +#define FSLABEL_MAX 256
> +#define FS_IOC_GETFSLABEL		_IOR(0x94, 49, char[FSLABEL_MAX])
> +#define FS_IOC_SETFSLABEL		_IOW(0x94, 50, char[FSLABEL_MAX])
> +#endif
> +
> +static cmdinfo_t label_cmd;
> +
> +static int
> +label_f(
> +	int		argc,
> +	char		**argv)
> +{
> +	int		error;
> +	char		label[FSLABEL_MAX];
> +
> +	if (argc == 1) {
> +		memset(label, 0, sizeof(label));
> +		error = ioctl(file->fd, FS_IOC_GETFSLABEL, &label);
> +	} else {
> +		strncpy(label, argv[1], sizeof(label));
> +		error = ioctl(file->fd, FS_IOC_SETFSLABEL, label);
> +	}
> +
> +	if (error) {
> +		perror("label");
> +		exitcode = 1;
> +	} else
> +		printf("label = \"%s\"\n", label);
> +
> +	return 0;
> +}
> +
> +void
> +label_init(void)
> +{
> +	label_cmd.name = "label";
> +	label_cmd.cfunc = label_f;
> +	label_cmd.argmin = 0;
> +	label_cmd.argmax = 1;
> +	label_cmd.args = _("[label]");
> +	label_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
> +	label_cmd.oneline =
> +		_("query or set the filesystem label while mounted");
> +
> +	add_command(&label_cmd);
> +}
> diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
> index c3ab532d..52b983d5 100644
> --- a/man/man8/xfs_io.8
> +++ b/man/man8/xfs_io.8
> @@ -1175,6 +1175,16 @@ This is intended to be equivalent to the shell command:
>  See the
>  .B log_writes
>  command.
> +.TP
> +.BI "label" " " [ " label " ]
> +On  filesystems  that  support  online label manipulation, set or get the

Only need one space between wor... oh there I go about whitespace again. :)

Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

--D


> +filesystem label.  With no options, get the current filesystem label.
> +With one option, set the filesystem label to
> +.IR label .
> +If the label is longer than the filesystem will accept,
> +.B xfs_io
> +will print an error message.  XFS filesystem labels can be at most 12
> +characters long, excluding any terminating NULL.
>  .SH SEE ALSO
>  .BR mkfs.xfs (8),
>  .BR xfsctl (3),
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 2/4] xfs: New function for secondary superblock updates
  2018-05-14 17:36 ` [PATCH 2/4] xfs: New function for secondary superblock updates Eric Sandeen
@ 2018-05-15 20:17   ` Darrick J. Wong
  0 siblings, 0 replies; 20+ messages in thread
From: Darrick J. Wong @ 2018-05-15 20:17 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: linux-xfs

On Mon, May 14, 2018 at 12:36:36PM -0500, Eric Sandeen wrote:
> Relabel must update all secondary superblocks, as offline relabel does.
> 
> This is essentially a simpler copy of the current growfs code, which is
> undergoing an independent refactor; we can see about merging stuff back
> together after all this work is done.  In the meantime, this is a fairly
> small, simple bit of code to facilitate the online label work.
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
>  fs/xfs/xfs_fsops.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++
>  fs/xfs/xfs_fsops.h |  1 +
>  2 files changed, 49 insertions(+)
> 
> diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c
> index 523792768080..1aaa93051f78 100644
> --- a/fs/xfs/xfs_fsops.c
> +++ b/fs/xfs/xfs_fsops.c
> @@ -71,6 +71,54 @@ xfs_growfs_get_hdr_buf(
>  	return bp;
>  }
>  
> +/*
> + * Copy the contents of the primary super to all backup supers.
> + * Not currently used for growfs, as it only looks at existing supers.
> + */
> +int
> +xfs_update_secondary_supers(
> +	xfs_mount_t		*mp)
> +{
> +	int			error, saved_error;
> +	xfs_agnumber_t		agno;
> +	xfs_buf_t		*bp;
> +
> +	error = saved_error = 0;
> +
> +	for (agno = 1; agno < mp->m_sb.sb_agcount; agno++) {
> +		error = xfs_trans_read_buf(mp, NULL, mp->m_ddev_targp,
> +			  XFS_AGB_TO_DADDR(mp, agno, XFS_SB_BLOCK(mp)),
> +			  XFS_FSS_TO_BB(mp, 1), 0, &bp, &xfs_sb_buf_ops);

This whole thing /should/ use the new xfs_sb_read_secondary() helper,
but between Dave's growfs refactor, this series, and secondary sb online
repair I think I prefer to land all three and immediately clean up all
three common use cases.

Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

--D

> +		/*
> +		 * If we get an error reading or writing alternate superblocks,
> +		 * continue.  xfs_repair chooses the "best" superblock based
> +		 * on most matches; if we break early, we'll leave more
> +		 * superblocks un-updated than updated, and xfs_repair may
> +		 * pick them over the properly-updated primary.
> +		 */
> +		if (error) {
> +			xfs_warn(mp,
> +		"error %d reading secondary superblock for ag %d",
> +				error, agno);
> +			saved_error = error;
> +			continue;
> +		}
> +		xfs_sb_to_disk(XFS_BUF_TO_SBP(bp), &mp->m_sb);
> +
> +		error = xfs_bwrite(bp);
> +		xfs_buf_relse(bp);
> +		if (error) {
> +			xfs_warn(mp,
> +		"write error %d updating secondary superblock for ag %d",
> +				error, agno);
> +			saved_error = error;
> +			continue;
> +		}
> +	}
> +
> +	return saved_error ? saved_error : error;
> +}
> +
>  static int
>  xfs_growfs_data_private(
>  	xfs_mount_t		*mp,		/* mount point for filesystem */
> diff --git a/fs/xfs/xfs_fsops.h b/fs/xfs/xfs_fsops.h
> index 20484ed5e919..257d3018bc39 100644
> --- a/fs/xfs/xfs_fsops.h
> +++ b/fs/xfs/xfs_fsops.h
> @@ -18,6 +18,7 @@
>  #ifndef __XFS_FSOPS_H__
>  #define	__XFS_FSOPS_H__
>  
> +extern int xfs_update_secondary_supers(xfs_mount_t *mp);
>  extern int xfs_growfs_data(xfs_mount_t *mp, xfs_growfs_data_t *in);
>  extern int xfs_growfs_log(xfs_mount_t *mp, xfs_growfs_log_t *in);
>  extern int xfs_fs_counts(xfs_mount_t *mp, xfs_fsop_counts_t *cnt);
> -- 
> 2.17.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 5/5] xfs_io: add label command
  2018-05-15 15:06     ` Eric Sandeen
@ 2018-05-16  0:57       ` Dave Chinner
  0 siblings, 0 replies; 20+ messages in thread
From: Dave Chinner @ 2018-05-16  0:57 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: Eric Sandeen, linux-xfs

On Tue, May 15, 2018 at 10:06:53AM -0500, Eric Sandeen wrote:
> 
> 
> On 5/14/18 11:32 PM, Dave Chinner wrote:
> >On Mon, May 14, 2018 at 12:43:20PM -0500, Eric Sandeen wrote:
> >>This adds a get/set label command to xfs_io.
> >....
> >>+static int
> >>+label_f(
> >>+	int		argc,
> >>+	char		**argv)
> >>+{
> >>+	int		error;
> >>+	char		label[FSLABEL_MAX];
> >>+
> >>+	if (argc == 1) {
> >>+		memset(&label, 0, sizeof(label));
> >>+		error = ioctl(file->fd, FS_IOC_GET_FSLABEL, &label);
> >>+	} else {
> >>+		strncpy(label, argv[1], sizeof(label));
> >>+		error = ioctl(file->fd, FS_IOC_SET_FSLABEL, &label);
> >>+	}
> >>+
> >>+	if (error)
> >>+		perror("label");
> >
> >Need to set exitcode = 1 here so that xfs_io fails with a non-zero
> >exit status....
> >
> >>+	else
> >>+		printf("label = \"%s\"\n", label);
> >>+
> >>+	return error;
> >
> >Because this isn't the exit status - this is the "continue
> >processing the next command" return value. i.e. return 0 if we want
> >to continue, non-zero if we want to abort further CLI processing....
> 
> Hm, ok.  Today we only set exitcode for bmap, fiemap, freeze/thaw, and
> imap.  It's really consistently used at all, and needs an audit I guess.

You mean the audit I did 6 months ago?

https://www.spinics.net/lists/linux-xfs/msg13605.html

(which is why I know what the exitcode rules are. :)

The patch is still sitting around somewhere here....

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

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

* Re: [PATCH 3/5 V2] xfs: implement online get/set fs label
  2018-05-15  1:07   ` Darrick J. Wong
@ 2018-05-16  1:04     ` Darrick J. Wong
  0 siblings, 0 replies; 20+ messages in thread
From: Darrick J. Wong @ 2018-05-16  1:04 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: Eric Sandeen, linux-xfs

On Mon, May 14, 2018 at 06:07:24PM -0700, Darrick J. Wong wrote:
> On Mon, May 14, 2018 at 12:39:19PM -0500, Eric Sandeen wrote:
> > The GET ioctl is trivial, just return the current label.
> > 
> > The SET ioctl is more involved:
> > It transactionally modifies the superblock to write a new filesystem
> > label to the primary super.
> > 
> > A new variant of xfs_sync_sb then writes the superblock buffer
> > immediately to disk so that the change is visible from userspace.
> > 
> > It then invalidates any page cache that userspace might have previously
> > read on the block device so that i.e. blkid can see the change
> > immediately, and updates all secondary superblocks as userspace relable
> > does.
> > 
> > Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> 
> Looks ok, to me....
> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
> 
> --D
> 
> > ---
> > 
> > V2, rework the max length handling a bit, add comments re: userspace,
> > do the blkdev flush at the end, sleep for growfs lock, add locking around
> > getlabel, add define for max label length ...
> > 
> >  fs/xfs/libxfs/xfs_format.h |  7 +++-
> >  fs/xfs/libxfs/xfs_sb.c     | 30 +++++++++++++
> >  fs/xfs/libxfs/xfs_sb.h     |  1 +
> >  fs/xfs/xfs_ioctl.c         | 86 ++++++++++++++++++++++++++++++++++++++
> >  4 files changed, 122 insertions(+), 2 deletions(-)
> > 
> > diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
> > index 42956d8d95ed..c1cb29a5f4f6 100644
> > --- a/fs/xfs/libxfs/xfs_format.h
> > +++ b/fs/xfs/libxfs/xfs_format.h
> > @@ -98,6 +98,9 @@ struct xfs_ifork;
> >  	 XFS_SB_VERSION2_PROJID32BIT	| \
> >  	 XFS_SB_VERSION2_FTYPE)
> >  
> > +/* Maximum size of the xfs filesystem label, no terminating NULL */
> > +#define XFSLABEL_MAX			12
> > +
> >  /*
> >   * Superblock - in core version.  Must match the ondisk version below.
> >   * Must be padded to 64 bit alignment.
> > @@ -122,7 +125,7 @@ typedef struct xfs_sb {
> >  	uint16_t	sb_sectsize;	/* volume sector size, bytes */
> >  	uint16_t	sb_inodesize;	/* inode size, bytes */
> >  	uint16_t	sb_inopblock;	/* inodes per block */
> > -	char		sb_fname[12];	/* file system name */
> > +	char		sb_fname[XFSLABEL_MAX]; /* file system name */
> >  	uint8_t		sb_blocklog;	/* log2 of sb_blocksize */
> >  	uint8_t		sb_sectlog;	/* log2 of sb_sectsize */
> >  	uint8_t		sb_inodelog;	/* log2 of sb_inodesize */
> > @@ -213,7 +216,7 @@ typedef struct xfs_dsb {
> >  	__be16		sb_sectsize;	/* volume sector size, bytes */
> >  	__be16		sb_inodesize;	/* inode size, bytes */
> >  	__be16		sb_inopblock;	/* inodes per block */
> > -	char		sb_fname[12];	/* file system name */
> > +	char		sb_fname[XFSLABEL_MAX]; /* file system name */
> >  	__u8		sb_blocklog;	/* log2 of sb_blocksize */
> >  	__u8		sb_sectlog;	/* log2 of sb_sectsize */
> >  	__u8		sb_inodelog;	/* log2 of sb_inodesize */
> > diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c
> > index d9b94bd5f689..0bc0a40764e1 100644
> > --- a/fs/xfs/libxfs/xfs_sb.c
> > +++ b/fs/xfs/libxfs/xfs_sb.c
> > @@ -888,6 +888,36 @@ xfs_sync_sb(
> >  	return xfs_trans_commit(tp);
> >  }
> >  
> > +/*
> > + * Same behavior as xfs_sync_sb, except that it is always synchronous and it
> > + * also writes the superblock buffer to disk sector 0 immediately.
> > + */
> > +int
> > +xfs_sync_sb_buf(
> > +	struct xfs_mount	*mp)
> > +{
> > +	struct xfs_trans	*tp;
> > +	int			error;
> > +
> > +	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_sb, 0, 0, 0, &tp);
> > +	if (error)
> > +		return error;
> > +
> > +	xfs_log_sb(tp);
> > +	xfs_trans_bhold(tp, mp->m_sb_bp);
> > +	xfs_trans_set_sync(tp);
> > +	error = xfs_trans_commit(tp);
> > +	if (error)
> > +		goto out;
> > +	/*
> > +	 * write out the sb buffer to get the changes to disk
> > +	 */
> > +	error = xfs_bwrite(mp->m_sb_bp);
> > +out:
> > +	xfs_buf_relse(mp->m_sb_bp);
> > +	return error;
> > +}
> > +
> >  int
> >  xfs_fs_geometry(
> >  	struct xfs_sb		*sbp,
> > diff --git a/fs/xfs/libxfs/xfs_sb.h b/fs/xfs/libxfs/xfs_sb.h
> > index 63dcd2a1a657..226827281760 100644
> > --- a/fs/xfs/libxfs/xfs_sb.h
> > +++ b/fs/xfs/libxfs/xfs_sb.h
> > @@ -29,6 +29,7 @@ extern int	xfs_initialize_perag_data(struct xfs_mount *, xfs_agnumber_t);
> >  
> >  extern void	xfs_log_sb(struct xfs_trans *tp);
> >  extern int	xfs_sync_sb(struct xfs_mount *mp, bool wait);
> > +extern int	xfs_sync_sb_buf(struct xfs_mount *mp);
> >  extern void	xfs_sb_mount_common(struct xfs_mount *mp, struct xfs_sb *sbp);
> >  extern void	xfs_sb_from_disk(struct xfs_sb *to, struct xfs_dsb *from);
> >  extern void	xfs_sb_to_disk(struct xfs_dsb *to, struct xfs_sb *from);
> > diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
> > index 89fb1eb80aae..5e7116ff3dd3 100644
> > --- a/fs/xfs/xfs_ioctl.c
> > +++ b/fs/xfs/xfs_ioctl.c
> > @@ -1811,6 +1811,88 @@ xfs_ioc_swapext(
> >  	return error;
> >  }
> >  
> > +static int
> > +xfs_ioc_getlabel(
> > +	struct xfs_mount	*mp,
> > +	char			__user *user_label)
> > +{
> > +	struct xfs_sb		*sbp = &mp->m_sb;
> > +	char			label[XFSLABEL_MAX + 1];
> > +
> > +	/* Paranoia */
> > +	BUILD_BUG_ON(sizeof(sbp->sb_fname) > FSLABEL_MAX);
> > +
> > +	spin_lock(&mp->m_sb_lock);
> > +	strncpy(label, sbp->sb_fname, sizeof(sbp->sb_fname));
> > +	spin_unlock(&mp->m_sb_lock);
> > +
> > +	/* xfs on-disk label is 12 chars, be sure we send a null to user */
> > +	label[XFSLABEL_MAX] = '\0';
> > +	if (copy_to_user(user_label, label, sizeof(sbp->sb_fname)))
> > +		return -EFAULT;
> > +	return 0;
> > +}
> > +
> > +static int
> > +xfs_ioc_setlabel(
> > +	struct file		*filp,
> > +	struct xfs_mount	*mp,
> > +	char			__user *newlabel)
> > +{
> > +	struct xfs_sb		*sbp = &mp->m_sb;
> > +	char			label[XFSLABEL_MAX + 1];
> > +	size_t			len;
> > +	int			error;
> > +
> > +	if (!capable(CAP_SYS_ADMIN))
> > +		return -EPERM;
> > +	/*
> > +	 * The generic ioctl allows up to FSLABEL_MAX chars, but XFS is much
> > +	 * smaller, at 12 bytes.  We copy one more to be sure we find the
> > +	 * (required) NULL character to test the incoming label length.
> > +	 * NB: The on disk label doesn't need to be null terminated.
> > +	 */
> > +	if (copy_from_user(label, newlabel, XFSLABEL_MAX + 1))
> > +		return -EFAULT;
> > +	len = strnlen(label, XFSLABEL_MAX + 1);
> > +	if (len > sizeof(sbp->sb_fname))
> > +		return -EINVAL;
> > +
> > +	error = mnt_want_write_file(filp);
> > +	if (error)
> > +		return error;
> > +
> > +	spin_lock(&mp->m_sb_lock);
> > +	memset(sbp->sb_fname, 0, sizeof(sbp->sb_fname));
> > +	strncpy(sbp->sb_fname, label, sizeof(sbp->sb_fname));
> > +	spin_unlock(&mp->m_sb_lock);
> > +
> > +	/*
> > +	 * Now we do several things to satisfy userspace.
> > +	 * In addition to normal logging of the primary superblock, we also
> > +	 * immediately write these changes to sector zero for the primary, then
> > +	 * update all backup supers (as xfs_db does for a label change), then
> > +	 * invalidate the block device page cache.  This is so that any prior
> > +	 * buffered reads from userspace (i.e. from blkid) are invalidated,
> > +	 * and userspace will see the newly-written label.
> > +	 */
> > +	error = xfs_sync_sb_buf(mp);
> > +	if (error)
> > +		goto out;
> > +	/*
> > +	 * growfs also updates backup supers so lock against that.
> > +	 */
> > +	mutex_lock(&mp->m_growlock);
> > +	error = xfs_update_secondary_supers(mp);

FWIW I'll merge this series after Dave's growfs thing, change this call
to xfs_update_secondary_sbs(), and drop the patch adding
xfs_update_secondary_supers.

--D

> > +	mutex_unlock(&mp->m_growlock);
> > +
> > +	invalidate_bdev(mp->m_ddev_targp->bt_bdev);
> > +
> > +out:
> > +	mnt_drop_write_file(filp);
> > +	return error;
> > +}
> > +
> >  /*
> >   * Note: some of the ioctl's return positive numbers as a
> >   * byte count indicating success, such as readlink_by_handle.
> > @@ -1834,6 +1916,10 @@ xfs_file_ioctl(
> >  	switch (cmd) {
> >  	case FITRIM:
> >  		return xfs_ioc_trim(mp, arg);
> > +	case FS_IOC_GETFSLABEL:
> > +		return xfs_ioc_getlabel(mp, arg);
> > +	case FS_IOC_SETFSLABEL:
> > +		return xfs_ioc_setlabel(filp, mp, arg);
> >  	case XFS_IOC_ALLOCSP:
> >  	case XFS_IOC_FREESP:
> >  	case XFS_IOC_RESVSP:
> > -- 
> > 2.17.0
> > 
> > 
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH 5/5 V3] xfs_io: add label command
  2018-05-15 15:32   ` [PATCH 5/5 V2] " Eric Sandeen
  2018-05-15 20:12     ` Darrick J. Wong
@ 2018-05-17 15:22     ` Eric Sandeen
  2018-05-17 21:56       ` Dave Chinner
  1 sibling, 1 reply; 20+ messages in thread
From: Eric Sandeen @ 2018-05-17 15:22 UTC (permalink / raw)
  To: Eric Sandeen, linux-xfs

This adds an online get/set/clear label command to xfs_io.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

V2: Set exitcode rather than error return on ioctl failure
     fix ioctl definitions o_O

V3: add option parsing to handle -s (set) and -c (clear)

diff --git a/io/Makefile b/io/Makefile
index 88e47517..b40156da 100644
--- a/io/Makefile
+++ b/io/Makefile
@@ -10,9 +10,9 @@ LSRCFILES = xfs_bmap.sh xfs_freeze.sh xfs_mkfile.sh
  HFILES = init.h io.h
  CFILES = init.c \
  	attr.c bmap.c cowextsize.c encrypt.c file.c freeze.c fsync.c \
-	getrusage.c imap.c link.c mmap.c open.c parent.c pread.c prealloc.c \
-	pwrite.c reflink.c scrub.c seek.c shutdown.c stat.c swapext.c sync.c \
-	truncate.c utimes.c
+	getrusage.c imap.c label.c link.c mmap.c open.c parent.c pread.c \
+	prealloc.c pwrite.c reflink.c scrub.c seek.c shutdown.c stat.c \
+	swapext.c sync.c truncate.c utimes.c
  
  LLDLIBS = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG) $(LIBPTHREAD)
  LTDEPENDENCIES = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG)
diff --git a/io/init.c b/io/init.c
index 0336c962..612962e8 100644
--- a/io/init.c
+++ b/io/init.c
@@ -72,6 +72,7 @@ init_commands(void)
  	help_init();
  	imap_init();
  	inject_init();
+	label_init();
  	log_writes_init();
  	madvise_init();
  	mincore_init();
diff --git a/io/io.h b/io/io.h
index a2676361..7f8197ca 100644
--- a/io/io.h
+++ b/io/io.h
@@ -109,6 +109,7 @@ extern void		getrusage_init(void);
  extern void		help_init(void);
  extern void		imap_init(void);
  extern void		inject_init(void);
+extern void		label_init(void);
  extern void		mmap_init(void);
  extern void		open_init(void);
  extern void		parent_init(void);
diff --git a/io/label.c b/io/label.c
new file mode 100644
index 00000000..0d163548
--- /dev/null
+++ b/io/label.c
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2018 Red Hat, Inc.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <sys/ioctl.h>
+#include <sys/mount.h>
+#include "platform_defs.h"
+#include "libxfs.h"
+#include "path.h"
+#include "command.h"
+#include "init.h"
+#include "io.h"
+
+#ifndef FS_IOC_GETFSLABEL
+/* Max chars for the interface; fs limits may differ */
+#define FSLABEL_MAX 256
+#define FS_IOC_GETFSLABEL		_IOR(0x94, 49, char[FSLABEL_MAX])
+#define FS_IOC_SETFSLABEL		_IOW(0x94, 50, char[FSLABEL_MAX])
+#endif
+
+static cmdinfo_t label_cmd;
+
+static void
+label_help(void)
+{
+	printf(_(
+"\n"
+" Manipulate or query the filesystem label while mounted.\n"
+"\n"
+" With no arguments, displays the current filesystem label.\n"
+" -s newlabel -- set the filesystem label to newlabel\n"
+" -c          -- clear the filesystem label (sets to NULL string)\n"
+"\n"));
+}
+
+static int
+label_f(
+	int		argc,
+	char		**argv)
+{
+	int		c;
+	int		error;
+	char		label[FSLABEL_MAX];
+
+	if (argc == 1) {
+		memset(label, 0, sizeof(label));
+		error = ioctl(file->fd, FS_IOC_GETFSLABEL, &label);
+		goto out;
+	}
+
+	while ((c = getopt(argc, argv, "cs:")) != EOF) {
+		switch (c) {
+		case 'c':
+			label[0] = '\0';
+			break;
+		case 's':
+			strncpy(label, optarg, sizeof(label));
+			break;
+		default:
+			return command_usage(&label_cmd);
+		}
+	}
+
+	/* Check for trailing arguments */
+	if (argc != optind)
+		return command_usage(&label_cmd);
+
+	error = ioctl(file->fd, FS_IOC_SETFSLABEL, label);
+out:
+	if (error) {
+		perror("label");
+		exitcode = 1;
+	} else {
+		printf("label = \"%s\"\n", label);
+	}
+
+	return 0;
+}
+
+void
+label_init(void)
+{
+	label_cmd.name = "label";
+	label_cmd.cfunc = label_f;
+	label_cmd.argmin = 0;
+	label_cmd.argmax = 3;
+	label_cmd.args = _("[-s label|-c]");
+	label_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
+	label_cmd.oneline =
+		_("query, set, or clear the filesystem label while mounted");
+	label_cmd.help = label_help;
+
+	add_command(&label_cmd);
+}
diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
index c3ab532d..82ea8c1a 100644
--- a/man/man8/xfs_io.8
+++ b/man/man8/xfs_io.8
@@ -1175,6 +1175,19 @@ This is intended to be equivalent to the shell command:
  See the
  .B log_writes
  command.
+.TP
+.BI "label" " " "[ -c | -s " label " ] "
+On filesystems that support online label manipulation, get, set, or clear the
+filesystem label.  With no options, print the current filesystem label.  The
+.B \-c
+option clears the filesystem label by setting it to the null string.  The
+.BI "\-s " label
+option sets the filesystem label to
+.IR label .
+If the label is longer than the filesystem will accept,
+.B xfs_io
+will print an error message.  XFS filesystem labels can be at most 12
+characters long.
  .SH SEE ALSO
  .BR mkfs.xfs (8),
  .BR xfsctl (3),


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

* Re: [PATCH 5/5 V3] xfs_io: add label command
  2018-05-17 15:22     ` [PATCH 5/5 V3] " Eric Sandeen
@ 2018-05-17 21:56       ` Dave Chinner
  0 siblings, 0 replies; 20+ messages in thread
From: Dave Chinner @ 2018-05-17 21:56 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: Eric Sandeen, linux-xfs

On Thu, May 17, 2018 at 10:22:09AM -0500, Eric Sandeen wrote:
> This adds an online get/set/clear label command to xfs_io.
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
> +static int
> +label_f(
> +	int		argc,
> +	char		**argv)
> +{
> +	int		c;
> +	int		error;
> +	char		label[FSLABEL_MAX];
> +
> +	if (argc == 1) {
> +		memset(label, 0, sizeof(label));
> +		error = ioctl(file->fd, FS_IOC_GETFSLABEL, &label);
> +		goto out;
> +	}
> +
> +	while ((c = getopt(argc, argv, "cs:")) != EOF) {
> +		switch (c) {
> +		case 'c':
> +			label[0] = '\0';
> +			break;
> +		case 's':
> +			strncpy(label, optarg, sizeof(label));
> +			break;
> +		default:

			exitcode = 1
			;
> +			return command_usage(&label_cmd);
> +		}
> +	}
> +
> +	/* Check for trailing arguments */
> +	if (argc != optind)

		exitcode = 1

> +		return command_usage(&label_cmd);
> +
> +	error = ioctl(file->fd, FS_IOC_SETFSLABEL, label);
> +out:
> +	if (error) {
> +		perror("label");
> +		exitcode = 1;
> +	} else {
> +		printf("label = \"%s\"\n", label);
> +	}
> +
> +	return 0;

Otherwise looks OK.

Reviewed-by: Dave Chinner <dchinner@redhat.com>
-- 
Dave Chinner
david@fromorbit.com

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

* Re: [PATCH 5/5] xfs_io: add label command
  2018-04-30 15:48 ` [PATCH 5/5] xfs_io: add label command Eric Sandeen
@ 2018-05-02 14:37   ` Darrick J. Wong
  0 siblings, 0 replies; 20+ messages in thread
From: Darrick J. Wong @ 2018-05-02 14:37 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: linux-xfs

On Mon, Apr 30, 2018 at 10:48:54AM -0500, Eric Sandeen wrote:
> This adds a get/set label command to xfs_io.
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
> 
> diff --git a/io/Makefile b/io/Makefile
> index 88e4751..b40156d 100644
> --- a/io/Makefile
> +++ b/io/Makefile
> @@ -10,9 +10,9 @@ LSRCFILES = xfs_bmap.sh xfs_freeze.sh xfs_mkfile.sh
>  HFILES = init.h io.h
>  CFILES = init.c \
>  	attr.c bmap.c cowextsize.c encrypt.c file.c freeze.c fsync.c \
> -	getrusage.c imap.c link.c mmap.c open.c parent.c pread.c prealloc.c \
> -	pwrite.c reflink.c scrub.c seek.c shutdown.c stat.c swapext.c sync.c \
> -	truncate.c utimes.c
> +	getrusage.c imap.c label.c link.c mmap.c open.c parent.c pread.c \
> +	prealloc.c pwrite.c reflink.c scrub.c seek.c shutdown.c stat.c \
> +	swapext.c sync.c truncate.c utimes.c
>  
>  LLDLIBS = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG) $(LIBPTHREAD)
>  LTDEPENDENCIES = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG)
> diff --git a/io/init.c b/io/init.c
> index 0336c96..612962e 100644
> --- a/io/init.c
> +++ b/io/init.c
> @@ -72,6 +72,7 @@ init_commands(void)
>  	help_init();
>  	imap_init();
>  	inject_init();
> +	label_init();
>  	log_writes_init();
>  	madvise_init();
>  	mincore_init();
> diff --git a/io/io.h b/io/io.h
> index a267636..7f8197c 100644
> --- a/io/io.h
> +++ b/io/io.h
> @@ -109,6 +109,7 @@ extern void		getrusage_init(void);
>  extern void		help_init(void);
>  extern void		imap_init(void);
>  extern void		inject_init(void);
> +extern void		label_init(void);
>  extern void		mmap_init(void);
>  extern void		open_init(void);
>  extern void		parent_init(void);
> diff --git a/io/label.c b/io/label.c
> new file mode 100644
> index 0000000..acab67f
> --- /dev/null
> +++ b/io/label.c
> @@ -0,0 +1,74 @@
> +/*
> + * Copyright (c) 2018 Red Hat, Inc.
> + * All Rights Reserved.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it would be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write the Free Software Foundation,
> + * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
> + */
> +
> +#include <sys/ioctl.h>
> +#include <sys/mount.h>
> +#include "platform_defs.h"
> +#include "libxfs.h"
> +#include "path.h"
> +#include "command.h"
> +#include "init.h"
> +#include "io.h"
> +
> +#ifndef FS_IOC_GET_FSLABEL
> +/* Max chars for the interface; fs limits may differ */
> +#define FSLABEL_MAX 256
> +#define FS_IOC_GET_FSLABEL		_IOR(0x94, 49, char[FSLABEL_MAX])
> +#define FS_IOC_SET_FSLABEL		_IOW(0x94, 50, char[FSLABEL_MAX])
> +#endif
> +
> +static cmdinfo_t label_cmd;
> +
> +static int
> +label_f(
> +	int		argc,
> +	char		**argv)
> +{
> +	int		error;
> +	char		label[FSLABEL_MAX];
> +
> +	if (argc == 1) {
> +		memset(&label, 0, sizeof(label));
> +		error = ioctl(file->fd, FS_IOC_GET_FSLABEL, &label);
> +	} else {
> +		strncpy(label, argv[1], sizeof(label));
> +		error = ioctl(file->fd, FS_IOC_SET_FSLABEL, &label);
> +	}
> +
> +	if (error)
> +		perror("label");
> +	else
> +		printf("label = \"%s\"\n", label);
> +
> +	return error;
> +}
> +
> +void
> +label_init(void)
> +{
> +	label_cmd.name = "label";
> +	label_cmd.cfunc = label_f;
> +	label_cmd.argmin = 0;
> +	label_cmd.argmax = 1;
> +	label_cmd.args = _("[label]");
> +	label_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
> +	label_cmd.oneline =
> +		_("query or set the filesystem label while mounted");
> +
> +	add_command(&label_cmd);
> +}
> diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
> index c3ab532..52b983d 100644
> --- a/man/man8/xfs_io.8
> +++ b/man/man8/xfs_io.8
> @@ -1175,6 +1175,16 @@ This is intended to be equivalent to the shell command:
>  See the
>  .B log_writes
>  command.
> +.TP
> +.BI "label" " " [ " label " ]
> +On  filesystems  that  support  online label manipulation, set or get the
> +filesystem label.  With no options, get the current filesystem label.
> +With one option, set the filesystem label to
> +.IR label .
> +If the label is longer than the filesystem will accept,
> +.B xfs_io
> +will print an error message.  XFS filesystem labels can be at most 12
> +characters long.

Needs proper ioctl_[gs]etlabel manpage documenting the semantics of this
new xfs ioctl, though that should be sent to mkerrisk/linux-api so we
don't have to maintain it. :)

--D

>  .SH SEE ALSO
>  .BR mkfs.xfs (8),
>  .BR xfsctl (3),
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH 5/5] xfs_io: add label command
  2018-04-30 15:40 [PATCH 0/5] xfs: add online relabel capabilities Eric Sandeen
@ 2018-04-30 15:48 ` Eric Sandeen
  2018-05-02 14:37   ` Darrick J. Wong
  0 siblings, 1 reply; 20+ messages in thread
From: Eric Sandeen @ 2018-04-30 15:48 UTC (permalink / raw)
  To: linux-xfs

This adds a get/set label command to xfs_io.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

diff --git a/io/Makefile b/io/Makefile
index 88e4751..b40156d 100644
--- a/io/Makefile
+++ b/io/Makefile
@@ -10,9 +10,9 @@ LSRCFILES = xfs_bmap.sh xfs_freeze.sh xfs_mkfile.sh
 HFILES = init.h io.h
 CFILES = init.c \
 	attr.c bmap.c cowextsize.c encrypt.c file.c freeze.c fsync.c \
-	getrusage.c imap.c link.c mmap.c open.c parent.c pread.c prealloc.c \
-	pwrite.c reflink.c scrub.c seek.c shutdown.c stat.c swapext.c sync.c \
-	truncate.c utimes.c
+	getrusage.c imap.c label.c link.c mmap.c open.c parent.c pread.c \
+	prealloc.c pwrite.c reflink.c scrub.c seek.c shutdown.c stat.c \
+	swapext.c sync.c truncate.c utimes.c
 
 LLDLIBS = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG) $(LIBPTHREAD)
 LTDEPENDENCIES = $(LIBXCMD) $(LIBHANDLE) $(LIBFROG)
diff --git a/io/init.c b/io/init.c
index 0336c96..612962e 100644
--- a/io/init.c
+++ b/io/init.c
@@ -72,6 +72,7 @@ init_commands(void)
 	help_init();
 	imap_init();
 	inject_init();
+	label_init();
 	log_writes_init();
 	madvise_init();
 	mincore_init();
diff --git a/io/io.h b/io/io.h
index a267636..7f8197c 100644
--- a/io/io.h
+++ b/io/io.h
@@ -109,6 +109,7 @@ extern void		getrusage_init(void);
 extern void		help_init(void);
 extern void		imap_init(void);
 extern void		inject_init(void);
+extern void		label_init(void);
 extern void		mmap_init(void);
 extern void		open_init(void);
 extern void		parent_init(void);
diff --git a/io/label.c b/io/label.c
new file mode 100644
index 0000000..acab67f
--- /dev/null
+++ b/io/label.c
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2018 Red Hat, Inc.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <sys/ioctl.h>
+#include <sys/mount.h>
+#include "platform_defs.h"
+#include "libxfs.h"
+#include "path.h"
+#include "command.h"
+#include "init.h"
+#include "io.h"
+
+#ifndef FS_IOC_GET_FSLABEL
+/* Max chars for the interface; fs limits may differ */
+#define FSLABEL_MAX 256
+#define FS_IOC_GET_FSLABEL		_IOR(0x94, 49, char[FSLABEL_MAX])
+#define FS_IOC_SET_FSLABEL		_IOW(0x94, 50, char[FSLABEL_MAX])
+#endif
+
+static cmdinfo_t label_cmd;
+
+static int
+label_f(
+	int		argc,
+	char		**argv)
+{
+	int		error;
+	char		label[FSLABEL_MAX];
+
+	if (argc == 1) {
+		memset(&label, 0, sizeof(label));
+		error = ioctl(file->fd, FS_IOC_GET_FSLABEL, &label);
+	} else {
+		strncpy(label, argv[1], sizeof(label));
+		error = ioctl(file->fd, FS_IOC_SET_FSLABEL, &label);
+	}
+
+	if (error)
+		perror("label");
+	else
+		printf("label = \"%s\"\n", label);
+
+	return error;
+}
+
+void
+label_init(void)
+{
+	label_cmd.name = "label";
+	label_cmd.cfunc = label_f;
+	label_cmd.argmin = 0;
+	label_cmd.argmax = 1;
+	label_cmd.args = _("[label]");
+	label_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
+	label_cmd.oneline =
+		_("query or set the filesystem label while mounted");
+
+	add_command(&label_cmd);
+}
diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8
index c3ab532..52b983d 100644
--- a/man/man8/xfs_io.8
+++ b/man/man8/xfs_io.8
@@ -1175,6 +1175,16 @@ This is intended to be equivalent to the shell command:
 See the
 .B log_writes
 command.
+.TP
+.BI "label" " " [ " label " ]
+On  filesystems  that  support  online label manipulation, set or get the
+filesystem label.  With no options, get the current filesystem label.
+With one option, set the filesystem label to
+.IR label .
+If the label is longer than the filesystem will accept,
+.B xfs_io
+will print an error message.  XFS filesystem labels can be at most 12
+characters long.
 .SH SEE ALSO
 .BR mkfs.xfs (8),
 .BR xfsctl (3),


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

end of thread, other threads:[~2018-05-17 21:56 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-14 17:30 [PATCH V2 0/5] xfs: online label Eric Sandeen
2018-05-14 17:35 ` [PATCH V2 1/5] fs: copy BTRFS_IOC_[SG]ET_FSLABEL to vfs Eric Sandeen
2018-05-14 17:37   ` Darrick J. Wong
2018-05-14 17:36 ` [PATCH 2/4] xfs: New function for secondary superblock updates Eric Sandeen
2018-05-15 20:17   ` Darrick J. Wong
2018-05-14 17:39 ` [PATCH 3/5 V2] xfs: implement online get/set fs label Eric Sandeen
2018-05-15  1:07   ` Darrick J. Wong
2018-05-16  1:04     ` Darrick J. Wong
2018-05-14 17:42 ` [PATCH 4/5] btrfs: use common label ioctl definitions Eric Sandeen
2018-05-14 21:41   ` Darrick J. Wong
2018-05-14 17:43 ` [PATCH 5/5] xfs_io: add label command Eric Sandeen
2018-05-15  4:32   ` Dave Chinner
2018-05-15 15:06     ` Eric Sandeen
2018-05-16  0:57       ` Dave Chinner
2018-05-15 15:32   ` [PATCH 5/5 V2] " Eric Sandeen
2018-05-15 20:12     ` Darrick J. Wong
2018-05-17 15:22     ` [PATCH 5/5 V3] " Eric Sandeen
2018-05-17 21:56       ` Dave Chinner
  -- strict thread matches above, loose matches on Subject: below --
2018-04-30 15:40 [PATCH 0/5] xfs: add online relabel capabilities Eric Sandeen
2018-04-30 15:48 ` [PATCH 5/5] xfs_io: add label command Eric Sandeen
2018-05-02 14:37   ` Darrick J. Wong

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.