diff mbox series

[7/7] xfs_property: add a new tool to administer fs properties

Message ID 172230940678.1543753.11215656166264361855.stgit@frogsfrogsfrogs (mailing list archive)
State Superseded, archived
Headers show
Series [1/7] libfrog: support editing filesystem property sets | expand

Commit Message

Darrick J. Wong July 30, 2024, 3:21 a.m. UTC
From: Darrick J. Wong <djwong@kernel.org>

Create a tool to list, get, set, and remove filesystem properties.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 man/man8/xfs_property.8 |   52 ++++++++++++++++++++++++++++++++
 spaceman/Makefile       |    3 +-
 spaceman/xfs_property   |   77 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 131 insertions(+), 1 deletion(-)
 create mode 100644 man/man8/xfs_property.8
 create mode 100755 spaceman/xfs_property

Comments

Christoph Hellwig July 30, 2024, 9:43 p.m. UTC | #1
On Mon, Jul 29, 2024 at 08:21:32PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> Create a tool to list, get, set, and remove filesystem properties.

Ok, so this wraps spaceman.  Can we make the property manipulation only
available through this interface to cause less confusion?
Darrick J. Wong July 30, 2024, 10:28 p.m. UTC | #2
On Tue, Jul 30, 2024 at 02:43:30PM -0700, Christoph Hellwig wrote:
> On Mon, Jul 29, 2024 at 08:21:32PM -0700, Darrick J. Wong wrote:
> > From: Darrick J. Wong <djwong@kernel.org>
> > 
> > Create a tool to list, get, set, and remove filesystem properties.
> 
> Ok, so this wraps spaceman.  Can we make the property manipulation only
> available through this interface to cause less confusion?

I think you're asking if I could make xfs_spaceman expose the
{list,get,set}fsprops commands and db expose the -Z flag to
attr_{get,set,list} when someone starts them up with -p xfs_property ?

If so, then yes, I can do that.

--D
Christoph Hellwig July 31, 2024, 3:42 p.m. UTC | #3
On Tue, Jul 30, 2024 at 03:28:15PM -0700, Darrick J. Wong wrote:
> I think you're asking if I could make xfs_spaceman expose the
> {list,get,set}fsprops commands and db expose the -Z flag to
> attr_{get,set,list} when someone starts them up with -p xfs_property ?

I was mostly concerned about spaceman.  I don't think it actually is so
bad, just a bit confusing.  But if we do xfs_io and xfs_db that's not
really an issue anyway.
Darrick J. Wong July 31, 2024, 5:56 p.m. UTC | #4
On Wed, Jul 31, 2024 at 08:42:41AM -0700, Christoph Hellwig wrote:
> On Tue, Jul 30, 2024 at 03:28:15PM -0700, Darrick J. Wong wrote:
> > I think you're asking if I could make xfs_spaceman expose the
> > {list,get,set}fsprops commands and db expose the -Z flag to
> > attr_{get,set,list} when someone starts them up with -p xfs_property ?
> 
> I was mostly concerned about spaceman.  I don't think it actually is so
> bad, just a bit confusing.  But if we do xfs_io and xfs_db that's not
> really an issue anyway.

Fair 'enough.  I'll see about switching spaceman -> io today.

--D
Dave Chinner Aug. 2, 2024, 12:25 a.m. UTC | #5
On Mon, Jul 29, 2024 at 08:21:32PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> Create a tool to list, get, set, and remove filesystem properties.
> 
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> ---
>  man/man8/xfs_property.8 |   52 ++++++++++++++++++++++++++++++++
>  spaceman/Makefile       |    3 +-
>  spaceman/xfs_property   |   77 +++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 131 insertions(+), 1 deletion(-)
>  create mode 100644 man/man8/xfs_property.8
>  create mode 100755 spaceman/xfs_property

Ah, there's the admin wrapper. :)

I should have read the whole patch set before commenting.

> diff --git a/man/man8/xfs_property.8 b/man/man8/xfs_property.8
> new file mode 100644
> index 000000000000..63245331bd86
> --- /dev/null
> +++ b/man/man8/xfs_property.8
> @@ -0,0 +1,52 @@
> +.TH xfs_property 8
> +.SH NAME
> +xfs_property \- examine and edit properties about an XFS filesystem
> +.SH SYNOPSIS
> +.B xfs_property
> +.I target
> +.B get
> +.IR name ...
> +.br
> +.B xfs_property
> +.I target
> +.B list [ \-v ]
> +.br
> +.B xfs_property
> +.I target
> +.B set
> +.IR name=value ...
> +.br
> +.B xfs_property
> +.I target
> +.B remove
> +.IR name ...
> +.br
> +.B xfs_property \-V
> +.SH DESCRIPTION
> +.B xfs_property
> +retrieves, lists, sets, or removes properties of an XFS filesystem.
> +Filesystem properties are root-controlled attributes set on the root directory
> +of the filesystem to enable the system administrator to coordinate with
> +userspace programs.
> +
> +.SH COMMANDS
> +.TP
> +.B get
> +.IR name ...
> +Prints the values of the given filesystem properties.
> +.TP
> +.B list
> +Lists the names of all filesystem properties.
> +If the
> +.B -v
> +flag is specified, prints the values as well.
> +.TP
> +.B set
> +.IR name = value ...
> +Sets the given filesystem properties to the specified values and prints what
> +was set.
> +.TP
> +.B
> +remove
> +.IR name ...
> +Unsets the given filesystem properties.

What does the -V option do? It's documented as existing, but not
explained.

Otherwise looks fine.

-Dave.
diff mbox series

Patch

diff --git a/man/man8/xfs_property.8 b/man/man8/xfs_property.8
new file mode 100644
index 000000000000..63245331bd86
--- /dev/null
+++ b/man/man8/xfs_property.8
@@ -0,0 +1,52 @@ 
+.TH xfs_property 8
+.SH NAME
+xfs_property \- examine and edit properties about an XFS filesystem
+.SH SYNOPSIS
+.B xfs_property
+.I target
+.B get
+.IR name ...
+.br
+.B xfs_property
+.I target
+.B list [ \-v ]
+.br
+.B xfs_property
+.I target
+.B set
+.IR name=value ...
+.br
+.B xfs_property
+.I target
+.B remove
+.IR name ...
+.br
+.B xfs_property \-V
+.SH DESCRIPTION
+.B xfs_property
+retrieves, lists, sets, or removes properties of an XFS filesystem.
+Filesystem properties are root-controlled attributes set on the root directory
+of the filesystem to enable the system administrator to coordinate with
+userspace programs.
+
+.SH COMMANDS
+.TP
+.B get
+.IR name ...
+Prints the values of the given filesystem properties.
+.TP
+.B list
+Lists the names of all filesystem properties.
+If the
+.B -v
+flag is specified, prints the values as well.
+.TP
+.B set
+.IR name = value ...
+Sets the given filesystem properties to the specified values and prints what
+was set.
+.TP
+.B
+remove
+.IR name ...
+Unsets the given filesystem properties.
diff --git a/spaceman/Makefile b/spaceman/Makefile
index 2688b37c770d..e914b921de8b 100644
--- a/spaceman/Makefile
+++ b/spaceman/Makefile
@@ -16,7 +16,7 @@  CFILES = \
 	init.c \
 	prealloc.c \
 	trim.c
-LSRCFILES = xfs_info.sh
+LSRCFILES = xfs_info.sh xfs_property
 
 LLDLIBS = $(LIBHANDLE) $(LIBXCMD) $(LIBFROG)
 LTDEPENDENCIES = $(LIBHANDLE) $(LIBXCMD) $(LIBFROG)
@@ -42,6 +42,7 @@  install: default
 	$(INSTALL) -m 755 -d $(PKG_SBIN_DIR)
 	$(LTINSTALL) -m 755 $(LTCOMMAND) $(PKG_SBIN_DIR)
 	$(INSTALL) -m 755 xfs_info.sh $(PKG_SBIN_DIR)/xfs_info
+	$(INSTALL) -m 755 xfs_property $(PKG_SBIN_DIR)/xfs_property
 install-dev:
 
 -include .dep
diff --git a/spaceman/xfs_property b/spaceman/xfs_property
new file mode 100755
index 000000000000..57185faa38db
--- /dev/null
+++ b/spaceman/xfs_property
@@ -0,0 +1,77 @@ 
+#!/bin/bash -f
+# SPDX-License-Identifier: GPL-2.0
+#
+# Copyright (c) 2024 Oracle.  All Rights Reserved.
+# Author: Darrick J. Wong <djwong@kernel.org>
+#
+
+OPTS=""
+USAGE="Usage: xfs_property [-V] [mountpoint|device|file] [list [-v]|get name...|set name=value...|remove name...]"
+
+# Try to find a loop device associated with a file.  We only want to return
+# one loopdev (multiple loop devices can attach to a single file) so we grab
+# the last line and return it if it's actually a block device.
+try_find_loop_dev_for_file() {
+	local x="$(losetup -O NAME -j "$1" 2> /dev/null | tail -n 1)"
+	test -b "${x}" && echo "${x}"
+}
+
+while getopts "V" c
+do
+	case $c in
+	V)	xfs_spaceman -p xfs_info -V
+		status=$?
+		exit ${status}
+		;;
+	*)	echo "${USAGE}" 1>&2
+		exit 2
+		;;
+	esac
+done
+set -- extra "$@"
+shift $OPTIND
+
+if [ $# -lt 2 ]; then
+	echo "${USAGE}" 1>&2
+	exit 2
+fi
+
+target="$1"
+shift
+subcommand="$1"
+shift
+
+db_args=()
+spaceman_args=()
+
+case "$subcommand" in
+"list")
+	vparam=
+	if [ $# -eq 1 ] && [ "$1" = "-v" ]; then
+		vparam=" -v"
+	fi
+	db_args+=('-c' "attr_list -Z${vparam}")
+	spaceman_args+=('-c' "listfsprops${vparam}")
+	;;
+"get"|"remove"|"set")
+	for arg in "$@"; do
+		db_args+=('-c' "attr_${subcommand} -Z ${arg/=/ }")
+		spaceman_args+=('-c' "${subcommand}fsprops ${arg}")
+	done
+	;;
+*)
+	echo "${USAGE}" 1>&2
+	exit 2
+esac
+
+# See if we can map the arg to a loop device
+loopdev="$(try_find_loop_dev_for_file "${target}")"
+test -n "${loopdev}" && target="${loopdev}"
+
+# If we find a mountpoint for the device, do a live query; otherwise try
+# reading the fs with xfs_db.
+if mountpt="$(findmnt -t xfs -f -n -o TARGET "${target}" 2> /dev/null)"; then
+	exec xfs_spaceman -p xfs_property "${spaceman_args[@]}" "${mountpt}"
+else
+	exec xfs_db -p xfs_property -x -c 'path /' "${db_args[@]}" "${target}"
+fi