Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zpool: Add slot power control, print power status #15662

Merged
merged 1 commit into from
Dec 21, 2023

Conversation

tonyhutter
Copy link
Contributor

@tonyhutter tonyhutter commented Dec 11, 2023

Motivation and Context

Use zpool commands to control enclosure and NVMe slot power. Sometimes it's useful to power off the slot to a misbehaving drive.

Description

Add zpool flags to control the slot power to drives. This assumes your SAS or NVMe enclosure supports slot power control via sysfs.

The new -0|-1 flags are added to zpool offline|online|clear:

    zpool offline -0 <pool> <device>    Turn off device slot power
    zpool online -1 <pool> <device>     Turn on device slot power
    zpool clear -1 <pool> [device]      Turn on device slot power

If the ZPOOL_AUTO_POWER_ON_SLOT env var is set, then the -1 is automatically implied for zpool online and zpool clear and does not need to be passed.

Also add a zpool status -1 option to print the slot power status as a new column.

Note: This also adds a FOR_EACH_VDEV()/FOR_EACH_LEAF_VDEV() macro that makes iterating over vdevs a lot easier.

How Has This Been Tested?

Tested locally on NVMe and SAS enclosures.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist:

@behlendorf behlendorf added the Status: Code Review Needed Ready for review and testing label Dec 11, 2023
@behlendorf behlendorf self-requested a review December 12, 2023 00:19
man/man8/zpool-clear.8 Show resolved Hide resolved
cmd/zpool/zpool_main.c Outdated Show resolved Hide resolved
cmd/zpool/zpool_main.c Outdated Show resolved Hide resolved
cmd/zpool/zpool_main.c Outdated Show resolved Hide resolved
cmd/zpool/zpool_main.c Outdated Show resolved Hide resolved
cmd/zpool/zpool_main.c Outdated Show resolved Hide resolved
cmd/zpool/zpool_main.c Outdated Show resolved Hide resolved
cmd/zpool/zpool_main.c Outdated Show resolved Hide resolved
cmd/zpool/zpool_main.c Outdated Show resolved Hide resolved
lib/libzutil/os/linux/zutil_import_os.c Outdated Show resolved Hide resolved
@allanjude
Copy link
Contributor

I think the command line interface could be clearer, like --power or something, since on/off is implied by online vs offline (or maybe --power=[on|off] for clear?), rather than just -1 and -0

@AllKind
Copy link
Contributor

AllKind commented Dec 13, 2023

I'd second that.
Unfortunately zfs does not use --long-options.

	online [-e] <pool> <device> ...
	offline [-f] [-t] <pool> <device> ...
	clear [-nF] <pool> [device]
	status [-c [script1,script2,...]] [-igLpPstvxD]  [-T d|u] [pool] ... 

Obvious -pP is taken by status, -e (engergy) by online.
Maybe -w (for watt - as the closest?).

@robn
Copy link
Member

robn commented Dec 13, 2023

Unfortunately zfs does not use --long-options.

A few commands do. Not hard to add it in to those that don't.

@AllKind
Copy link
Contributor

AllKind commented Dec 14, 2023

Ok, should have said zpool clear, offline, online, status...

@tonyhutter
Copy link
Contributor Author

I think the command line interface could be clearer, like --power or something

What would the short name for --power be?

Maybe -w (for watt - as the closest?).

If we want to later add power control to zpool remove (which is possible) then -w is not going to work, since it is already taken for zpool remove. -w is also used by zpool iostat.

@robn
Copy link
Member

robn commented Dec 14, 2023

What would the short name for --power be?

Does it need one? Depends how niche this feature is, I suppose.

@tonyhutter
Copy link
Contributor Author

What would the short name for --power be?

Does it need one? Depends how niche this feature is, I suppose.

I suppose not. We have short names for all the other long args, but there's nothing set in stone that we have to have them.

@robn
Copy link
Member

robn commented Dec 14, 2023

There's one we don't: zpool import --rewind-to-checkpoint. Just in case you didn't want to be the one setting the precedent 😉

@tonyhutter
Copy link
Contributor Author

@robn thanks, that settles it then - I'll add it as --power.

@tonyhutter tonyhutter force-pushed the zpool_clear_slot3 branch 2 times, most recently from 5a98c53 to e05bbc5 Compare December 16, 2023 00:44
cmd/zpool/zpool_main.c Outdated Show resolved Hide resolved
cmd/zpool/zpool_main.c Outdated Show resolved Hide resolved
cmd/zpool/zpool_main.c Outdated Show resolved Hide resolved
cmd/zpool/zpool_main.c Outdated Show resolved Hide resolved
cmd/zpool/zpool_main.c Outdated Show resolved Hide resolved
cmd/zpool/zpool_main.c Outdated Show resolved Hide resolved
cmd/zpool/zpool_main.c Outdated Show resolved Hide resolved
cmd/zpool/zpool_main.c Outdated Show resolved Hide resolved
cmd/zpool/zpool_main.c Outdated Show resolved Hide resolved
man/man8/zpool-status.8 Outdated Show resolved Hide resolved
@tonyhutter tonyhutter force-pushed the zpool_clear_slot3 branch 2 times, most recently from 21110fc to 1dad982 Compare December 18, 2023 19:54
@tonyhutter
Copy link
Contributor Author

All the changes requested have been pushed in. I'm still looking into some build warnings on Centos 7 and FreeBSD.

@tonyhutter tonyhutter force-pushed the zpool_clear_slot3 branch 2 times, most recently from 4bd224b to 5ce6434 Compare December 20, 2023 01:40
@tonyhutter
Copy link
Contributor Author

I think this is ready to go. The checkstyle failure does not appear for me when I run make checkstyle on F39, so I'm not sure what's going on with that.

cmd/zpool/os/linux/zpool_vdev_os.c Outdated Show resolved Hide resolved
man/man8/zpool.8 Outdated Show resolved Hide resolved
man/man8/zpool.8 Show resolved Hide resolved
include/libzutil.h Show resolved Hide resolved
Add `zpool` flags to control the slot power to drives.  This assumes
your SAS or NVMe enclosure supports slot power control via sysfs.

The new `--power` flag is added to `zpool offline|online|clear`:

    zpool offline --power <pool> <device>    Turn off device slot power
    zpool online --power <pool> <device>     Turn on device slot power
    zpool clear --power <pool> [device]      Turn on device slot power

If the ZPOOL_AUTO_POWER_ON_SLOT env var is set, then the '-1' is
automatically implied for `zpool online` and `zpool clear` and does
not need to be passed.

zpool status also gets a --power option to print the slot power status.

Signed-off-by: Tony Hutter <hutter2@llnl.gov>
@tonyhutter
Copy link
Contributor Author

My latest push uses the ABI files from the checkabi artifacts, which resolves the errors.

@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels Dec 21, 2023
@behlendorf behlendorf merged commit a9520e6 into openzfs:master Dec 21, 2023
23 of 24 checks passed
@mmatuska mmatuska mentioned this pull request Jan 30, 2024
13 tasks
ixhamza pushed a commit to truenas/zfs that referenced this pull request Jan 30, 2024
Add `zpool` flags to control the slot power to drives.  This assumes
your SAS or NVMe enclosure supports slot power control via sysfs.

The new `--power` flag is added to `zpool offline|online|clear`:

    zpool offline --power <pool> <device>    Turn off device slot power
    zpool online --power <pool> <device>     Turn on device slot power
    zpool clear --power <pool> [device]      Turn on device slot power

If the ZPOOL_AUTO_POWER_ON_SLOT env var is set, then the '--power'
option is automatically implied for `zpool online` and `zpool clear`
and does not need to be passed.

zpool status also gets a --power option to print the slot power status.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Mart Frauenlob <AllKind@fastest.cc>
Signed-off-by: Tony Hutter <hutter2@llnl.gov>
Closes openzfs#15662
@mmatuska mmatuska mentioned this pull request Feb 10, 2024
13 tasks
behlendorf pushed a commit that referenced this pull request Feb 13, 2024
Add `zpool` flags to control the slot power to drives.  This assumes
your SAS or NVMe enclosure supports slot power control via sysfs.

The new `--power` flag is added to `zpool offline|online|clear`:

    zpool offline --power <pool> <device>    Turn off device slot power
    zpool online --power <pool> <device>     Turn on device slot power
    zpool clear --power <pool> [device]      Turn on device slot power

If the ZPOOL_AUTO_POWER_ON_SLOT env var is set, then the '--power'
option is automatically implied for `zpool online` and `zpool clear`
and does not need to be passed.

zpool status also gets a --power option to print the slot power status.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Mart Frauenlob <AllKind@fastest.cc>
Signed-off-by: Tony Hutter <hutter2@llnl.gov>
Closes #15662
lundman pushed a commit to openzfsonwindows/openzfs that referenced this pull request Mar 13, 2024
Add `zpool` flags to control the slot power to drives.  This assumes
your SAS or NVMe enclosure supports slot power control via sysfs.

The new `--power` flag is added to `zpool offline|online|clear`:

    zpool offline --power <pool> <device>    Turn off device slot power
    zpool online --power <pool> <device>     Turn on device slot power
    zpool clear --power <pool> [device]      Turn on device slot power

If the ZPOOL_AUTO_POWER_ON_SLOT env var is set, then the '--power'
option is automatically implied for `zpool online` and `zpool clear`
and does not need to be passed.

zpool status also gets a --power option to print the slot power status.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Mart Frauenlob <AllKind@fastest.cc>
Signed-off-by: Tony Hutter <hutter2@llnl.gov>
Closes openzfs#15662
lundman pushed a commit to openzfsonwindows/openzfs that referenced this pull request Mar 13, 2024
Add `zpool` flags to control the slot power to drives.  This assumes
your SAS or NVMe enclosure supports slot power control via sysfs.

The new `--power` flag is added to `zpool offline|online|clear`:

    zpool offline --power <pool> <device>    Turn off device slot power
    zpool online --power <pool> <device>     Turn on device slot power
    zpool clear --power <pool> [device]      Turn on device slot power

If the ZPOOL_AUTO_POWER_ON_SLOT env var is set, then the '--power'
option is automatically implied for `zpool online` and `zpool clear`
and does not need to be passed.

zpool status also gets a --power option to print the slot power status.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Mart Frauenlob <AllKind@fastest.cc>
Signed-off-by: Tony Hutter <hutter2@llnl.gov>
Closes openzfs#15662
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Accepted Ready to integrate (reviewed, tested)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants