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

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