Blame SOURCES/xfsprogs-4.17.0-xfs_io-add-label-command.patch

89952e
From cfa10b0f972005b38ed294bca66cebf2f65298ec Mon Sep 17 00:00:00 2001
89952e
From: Eric Sandeen <sandeen@redhat.com>
89952e
Date: Thu, 24 May 2018 14:48:33 -0500
89952e
Subject: [PATCH] xfs_io: add label command
89952e
89952e
This adds an online get/set/clear label command to xfs_io.
89952e
89952e
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
89952e
Reviewed-by: Dave Chinner <dchinner@redhat.com>
89952e
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
89952e
---
89952e
 io/Makefile       |   6 +--
89952e
 io/init.c         |   1 +
89952e
 io/io.h           |   1 +
89952e
 io/label.c        | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
89952e
 man/man8/xfs_io.8 |  13 +++++++
89952e
 5 files changed, 126 insertions(+), 3 deletions(-)
89952e
 create mode 100644 io/label.c
89952e
89952e
Index: xfsprogs-4.5.0/io/Makefile
89952e
===================================================================
89952e
--- xfsprogs-4.5.0.orig/io/Makefile
89952e
+++ xfsprogs-4.5.0/io/Makefile
89952e
@@ -9,7 +9,7 @@ LTCOMMAND = xfs_io
89952e
 LSRCFILES = xfs_bmap.sh xfs_freeze.sh xfs_mkfile.sh
89952e
 HFILES = init.h io.h
89952e
 CFILES = init.c \
89952e
-	attr.c bmap.c file.c freeze.c fsync.c getrusage.c imap.c link.c \
89952e
+	attr.c bmap.c file.c freeze.c fsync.c getrusage.c imap.c label.c link.c \
89952e
 	mmap.c open.c parent.c pread.c prealloc.c pwrite.c seek.c shutdown.c \
89952e
 	sync.c truncate.c reflink.c
89952e
 
89952e
Index: xfsprogs-4.5.0/io/init.c
89952e
===================================================================
89952e
--- xfsprogs-4.5.0.orig/io/init.c
89952e
+++ xfsprogs-4.5.0/io/init.c
89952e
@@ -65,6 +65,7 @@ init_commands(void)
89952e
 	help_init();
89952e
 	imap_init();
89952e
 	inject_init();
89952e
+	label_init();
89952e
 	seek_init();
89952e
 	madvise_init();
89952e
 	mincore_init();
89952e
Index: xfsprogs-4.5.0/io/io.h
89952e
===================================================================
89952e
--- xfsprogs-4.5.0.orig/io/io.h
89952e
+++ xfsprogs-4.5.0/io/io.h
89952e
@@ -102,6 +102,7 @@ extern void		getrusage_init(void);
89952e
 extern void		help_init(void);
89952e
 extern void		imap_init(void);
89952e
 extern void		inject_init(void);
89952e
+extern void		label_init(void);
89952e
 extern void		mmap_init(void);
89952e
 extern void		open_init(void);
89952e
 extern void		parent_init(void);
89952e
Index: xfsprogs-4.5.0/io/label.c
89952e
===================================================================
89952e
--- /dev/null
89952e
+++ xfsprogs-4.5.0/io/label.c
89952e
@@ -0,0 +1,108 @@
89952e
+/*
89952e
+ * Copyright (c) 2018 Red Hat, Inc.
89952e
+ * All Rights Reserved.
89952e
+ *
89952e
+ * This program is free software; you can redistribute it and/or
89952e
+ * modify it under the terms of the GNU General Public License as
89952e
+ * published by the Free Software Foundation.
89952e
+ *
89952e
+ * This program is distributed in the hope that it would be useful,
89952e
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
89952e
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
89952e
+ * GNU General Public License for more details.
89952e
+ *
89952e
+ * You should have received a copy of the GNU General Public License
89952e
+ * along with this program; if not, write the Free Software Foundation,
89952e
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
89952e
+ */
89952e
+
89952e
+#include <sys/ioctl.h>
89952e
+#include <sys/mount.h>
89952e
+#include "platform_defs.h"
89952e
+#include "libxfs.h"
89952e
+#include "path.h"
89952e
+#include "command.h"
89952e
+#include "init.h"
89952e
+#include "io.h"
89952e
+
89952e
+#ifndef FS_IOC_GETFSLABEL
89952e
+/* Max chars for the interface; fs limits may differ */
89952e
+#define FSLABEL_MAX 256
89952e
+#define FS_IOC_GETFSLABEL		_IOR(0x94, 49, char[FSLABEL_MAX])
89952e
+#define FS_IOC_SETFSLABEL		_IOW(0x94, 50, char[FSLABEL_MAX])
89952e
+#endif
89952e
+
89952e
+static cmdinfo_t label_cmd;
89952e
+
89952e
+static void
89952e
+label_help(void)
89952e
+{
89952e
+	printf(_(
89952e
+"\n"
89952e
+" Manipulate or query the filesystem label while mounted.\n"
89952e
+"\n"
89952e
+" With no arguments, displays the current filesystem label.\n"
89952e
+" -s newlabel -- set the filesystem label to newlabel\n"
89952e
+" -c          -- clear the filesystem label (sets to NULL string)\n"
89952e
+"\n"));
89952e
+}
89952e
+
89952e
+static int
89952e
+label_f(
89952e
+	int		argc,
89952e
+	char		**argv)
89952e
+{
89952e
+	int		c;
89952e
+	int		error;
89952e
+	char		label[FSLABEL_MAX];
89952e
+
89952e
+	if (argc == 1) {
89952e
+		memset(label, 0, sizeof(label));
89952e
+		error = ioctl(file->fd, FS_IOC_GETFSLABEL, &label);
89952e
+		goto out;
89952e
+	}
89952e
+
89952e
+	while ((c = getopt(argc, argv, "cs:")) != EOF) {
89952e
+		switch (c) {
89952e
+		case 'c':
89952e
+			label[0] = '\0';
89952e
+			break;
89952e
+		case 's':
89952e
+			strncpy(label, optarg, sizeof(label));
89952e
+			break;
89952e
+		default:
89952e
+			return command_usage(&label_cmd);
89952e
+		}
89952e
+	}
89952e
+
89952e
+	/* Check for trailing arguments */
89952e
+	if (argc != optind)
89952e
+		return command_usage(&label_cmd);
89952e
+
89952e
+	error = ioctl(file->fd, FS_IOC_SETFSLABEL, label);
89952e
+out:
89952e
+	if (error) {
89952e
+		perror("label");
89952e
+		exitcode = 1;
89952e
+	} else {
89952e
+		printf("label = \"%s\"\n", label);
89952e
+	}
89952e
+
89952e
+	return 0;
89952e
+}
89952e
+
89952e
+void
89952e
+label_init(void)
89952e
+{
89952e
+	label_cmd.name = "label";
89952e
+	label_cmd.cfunc = label_f;
89952e
+	label_cmd.argmin = 0;
89952e
+	label_cmd.argmax = 3;
89952e
+	label_cmd.args = _("[-s label|-c]");
89952e
+	label_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
89952e
+	label_cmd.oneline =
89952e
+		_("query, set, or clear the filesystem label while mounted");
89952e
+	label_cmd.help = label_help;
89952e
+
89952e
+	add_command(&label_cmd);
89952e
+}
89952e
Index: xfsprogs-4.5.0/man/man8/xfs_io.8
89952e
===================================================================
89952e
--- xfsprogs-4.5.0.orig/man/man8/xfs_io.8
89952e
+++ xfsprogs-4.5.0/man/man8/xfs_io.8
89952e
@@ -812,7 +812,19 @@ verbose output will be printed.
89952e
 .IP
89952e
 .B [NOTE: Not currently operational on Linux.]
89952e
 .PD
89952e
-
89952e
+.TP
89952e
+.BI "label" " " "[ -c | -s " label " ] "
89952e
+On filesystems that support online label manipulation, get, set, or clear the
89952e
+filesystem label.  With no options, print the current filesystem label.  The
89952e
+.B \-c
89952e
+option clears the filesystem label by setting it to the null string.  The
89952e
+.BI "\-s " label
89952e
+option sets the filesystem label to
89952e
+.IR label .
89952e
+If the label is longer than the filesystem will accept,
89952e
+.B xfs_io
89952e
+will print an error message.  XFS filesystem labels can be at most 12
89952e
+characters long.
89952e
 .SH SEE ALSO
89952e
 .BR mkfs.xfs (8),
89952e
 .BR xfsctl (3),