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

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