mirror of
https://github.com/freebsd/freebsd-src
synced 2024-09-06 17:18:32 +00:00
Consolidate three copies of ZFS commands into a central location.
There's no reason to have multiple copies of lszfs and reloadbe. Consolidate them into one location. Also ldi_get_size is the same everywhere (except sparc64). Make it the same everywhere as the common definition is more general and will work on spar64.
This commit is contained in:
parent
18587b84c5
commit
4784aef9f5
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=329725
108
stand/common/zfs_cmd.c
Normal file
108
stand/common/zfs_cmd.c
Normal file
|
@ -0,0 +1,108 @@
|
|||
/*-
|
||||
* Copyright (c) 2018 Warner Losh <imp@freebd.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* MD bootstrap main() and assorted miscellaneous
|
||||
* commands.
|
||||
*/
|
||||
|
||||
#include <stand.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/disk.h>
|
||||
#include <sys/reboot.h>
|
||||
|
||||
#include "bootstrap.h"
|
||||
|
||||
#ifdef LOADER_ZFS_SUPPORT
|
||||
#include "../zfs/libzfs.h"
|
||||
#endif
|
||||
|
||||
COMMAND_SET(lszfs, "lszfs", "list child datasets of a zfs dataset",
|
||||
command_lszfs);
|
||||
|
||||
static int
|
||||
command_lszfs(int argc, char *argv[])
|
||||
{
|
||||
int err;
|
||||
|
||||
if (argc != 2) {
|
||||
command_errmsg = "a single dataset must be supplied";
|
||||
return (CMD_ERROR);
|
||||
}
|
||||
|
||||
err = zfs_list(argv[1]);
|
||||
if (err != 0) {
|
||||
command_errmsg = strerror(err);
|
||||
return (CMD_ERROR);
|
||||
}
|
||||
return (CMD_OK);
|
||||
}
|
||||
|
||||
COMMAND_SET(reloadbe, "reloadbe", "refresh the list of ZFS Boot Environments",
|
||||
command_reloadbe);
|
||||
|
||||
static int
|
||||
command_reloadbe(int argc, char *argv[])
|
||||
{
|
||||
int err;
|
||||
char *root;
|
||||
|
||||
if (argc > 2) {
|
||||
command_errmsg = "wrong number of arguments";
|
||||
return (CMD_ERROR);
|
||||
}
|
||||
|
||||
if (argc == 2) {
|
||||
err = zfs_bootenv(argv[1]);
|
||||
} else {
|
||||
root = getenv("zfs_be_root");
|
||||
if (root == NULL) {
|
||||
/* There does not appear to be a ZFS pool here, exit without error */
|
||||
return (CMD_OK);
|
||||
}
|
||||
err = zfs_bootenv(root);
|
||||
}
|
||||
|
||||
if (err != 0) {
|
||||
command_errmsg = strerror(err);
|
||||
return (CMD_ERROR);
|
||||
}
|
||||
|
||||
return (CMD_OK);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
ldi_get_size(void *priv)
|
||||
{
|
||||
int fd = (uintptr_t) priv;
|
||||
uint64_t size;
|
||||
|
||||
ioctl(fd, DIOCGMEDIASIZE, &size);
|
||||
return (size);
|
||||
}
|
|
@ -109,14 +109,4 @@ efi_zfs_probe(void)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t
|
||||
ldi_get_size(void *priv)
|
||||
{
|
||||
int fd = (uintptr_t) priv;
|
||||
uint64_t size;
|
||||
|
||||
ioctl(fd, DIOCGMEDIASIZE, &size);
|
||||
return (size);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -28,6 +28,7 @@ SRCS= autoload.c \
|
|||
LIBZFSBOOT= ${BOOTOBJ}/zfs/libzfsboot.a
|
||||
CFLAGS+= -I${ZFSSRC}
|
||||
CFLAGS+= -DEFI_ZFS_BOOT
|
||||
HAVE_ZFS= yes
|
||||
.endif
|
||||
|
||||
.if ${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} > 40201
|
||||
|
|
|
@ -747,61 +747,6 @@ command_mode(int argc, char *argv[])
|
|||
return (CMD_OK);
|
||||
}
|
||||
|
||||
#ifdef EFI_ZFS_BOOT
|
||||
COMMAND_SET(lszfs, "lszfs", "list child datasets of a zfs dataset",
|
||||
command_lszfs);
|
||||
|
||||
static int
|
||||
command_lszfs(int argc, char *argv[])
|
||||
{
|
||||
int err;
|
||||
|
||||
if (argc != 2) {
|
||||
command_errmsg = "wrong number of arguments";
|
||||
return (CMD_ERROR);
|
||||
}
|
||||
|
||||
err = zfs_list(argv[1]);
|
||||
if (err != 0) {
|
||||
command_errmsg = strerror(err);
|
||||
return (CMD_ERROR);
|
||||
}
|
||||
return (CMD_OK);
|
||||
}
|
||||
|
||||
COMMAND_SET(reloadbe, "reloadbe", "refresh the list of ZFS Boot Environments",
|
||||
command_reloadbe);
|
||||
|
||||
static int
|
||||
command_reloadbe(int argc, char *argv[])
|
||||
{
|
||||
int err;
|
||||
char *root;
|
||||
|
||||
if (argc > 2) {
|
||||
command_errmsg = "wrong number of arguments";
|
||||
return (CMD_ERROR);
|
||||
}
|
||||
|
||||
if (argc == 2) {
|
||||
err = zfs_bootenv(argv[1]);
|
||||
} else {
|
||||
root = getenv("zfs_be_root");
|
||||
if (root == NULL) {
|
||||
return (CMD_OK);
|
||||
}
|
||||
err = zfs_bootenv(root);
|
||||
}
|
||||
|
||||
if (err != 0) {
|
||||
command_errmsg = strerror(err);
|
||||
return (CMD_ERROR);
|
||||
}
|
||||
|
||||
return (CMD_OK);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LOADER_FDT_SUPPORT
|
||||
extern int command_fdt_internal(int argc, char *argv[]);
|
||||
|
||||
|
|
|
@ -374,63 +374,6 @@ command_heap(int argc, char *argv[])
|
|||
return(CMD_OK);
|
||||
}
|
||||
|
||||
#ifdef LOADER_ZFS_SUPPORT
|
||||
COMMAND_SET(lszfs, "lszfs", "list child datasets of a zfs dataset",
|
||||
command_lszfs);
|
||||
|
||||
static int
|
||||
command_lszfs(int argc, char *argv[])
|
||||
{
|
||||
int err;
|
||||
|
||||
if (argc != 2) {
|
||||
command_errmsg = "wrong number of arguments";
|
||||
return (CMD_ERROR);
|
||||
}
|
||||
|
||||
err = zfs_list(argv[1]);
|
||||
if (err != 0) {
|
||||
command_errmsg = strerror(err);
|
||||
return (CMD_ERROR);
|
||||
}
|
||||
|
||||
return (CMD_OK);
|
||||
}
|
||||
|
||||
COMMAND_SET(reloadbe, "reloadbe", "refresh the list of ZFS Boot Environments",
|
||||
command_reloadbe);
|
||||
|
||||
static int
|
||||
command_reloadbe(int argc, char *argv[])
|
||||
{
|
||||
int err;
|
||||
char *root;
|
||||
|
||||
if (argc > 2) {
|
||||
command_errmsg = "wrong number of arguments";
|
||||
return (CMD_ERROR);
|
||||
}
|
||||
|
||||
if (argc == 2) {
|
||||
err = zfs_bootenv(argv[1]);
|
||||
} else {
|
||||
root = getenv("zfs_be_root");
|
||||
if (root == NULL) {
|
||||
/* There does not appear to be a ZFS pool here, exit without error */
|
||||
return (CMD_OK);
|
||||
}
|
||||
err = zfs_bootenv(root);
|
||||
}
|
||||
|
||||
if (err != 0) {
|
||||
command_errmsg = strerror(err);
|
||||
return (CMD_ERROR);
|
||||
}
|
||||
|
||||
return (CMD_OK);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ISA bus access functions for PnP. */
|
||||
static int
|
||||
isa_inb(int port)
|
||||
|
@ -464,14 +407,4 @@ i386_zfs_probe(void)
|
|||
zfs_probe_dev(devname, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t
|
||||
ldi_get_size(void *priv)
|
||||
{
|
||||
int fd = (uintptr_t) priv;
|
||||
uint64_t size;
|
||||
|
||||
ioctl(fd, DIOCGMEDIASIZE, &size);
|
||||
return (size);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -130,7 +130,8 @@ CFLAGS+= -DLOADER_MBR_SUPPORT
|
|||
CFLAGS+= -DLOADER_ZFS_SUPPORT
|
||||
CFLAGS+= -I${ZFSSRC}
|
||||
CFLAGS+= -I${SYSDIR}/cddl/boot/zfs
|
||||
.if ${MACHINE} == "amd64"
|
||||
SRCS+= zfs_cmd.c
|
||||
.if ${MACHINE_CPUARCH} == "amd64" && ${DO32:U0} == 1
|
||||
# Have to override to use 32-bit version of zfs library...
|
||||
# kinda lame to select that there XXX
|
||||
LIBZFSBOOT= ${BOOTOBJ}/zfs32/libzfsboot.a
|
||||
|
|
|
@ -19,6 +19,10 @@ NEWVERSWHAT?= "bootstrap loader" sparc64
|
|||
VERSION_FILE= ${.CURDIR}/../loader/version
|
||||
INSTALLFLAGS= -b
|
||||
|
||||
.if ${MK_ZFS} != "no"
|
||||
HAVE_ZFS= yes
|
||||
.endif
|
||||
|
||||
# Architecture-specific loader code
|
||||
.PATH: ${BOOTSRC}/sparc64/loader
|
||||
SRCS= locore.S main.c vers.c
|
||||
|
|
|
@ -735,15 +735,6 @@ tlb_init_sun4u(void)
|
|||
|
||||
#ifdef LOADER_ZFS_SUPPORT
|
||||
|
||||
/* Set by sparc64_zfs_probe to provide partition size. */
|
||||
static size_t part_size;
|
||||
|
||||
uint64_t
|
||||
ldi_get_size(void *priv __unused)
|
||||
{
|
||||
return ((uint64_t)part_size);
|
||||
}
|
||||
|
||||
static void
|
||||
sparc64_zfs_probe(void)
|
||||
{
|
||||
|
@ -799,7 +790,6 @@ sparc64_zfs_probe(void)
|
|||
if (part == 2 || vtoc.part[part].tag !=
|
||||
VTOC_TAG_FREEBSD_ZFS)
|
||||
continue;
|
||||
part_size = vtoc.map[part].nblks;
|
||||
(void)sprintf(devname, "%s:%c", alias, part + 'a');
|
||||
/* Get the GUID of the ZFS pool on the boot device. */
|
||||
if (strcmp(devname, bootpath) == 0)
|
||||
|
@ -948,7 +938,7 @@ static const char *const page_sizes[] = {
|
|||
|
||||
static void
|
||||
pmap_print_tte_sun4u(tte_t tag, tte_t tte)
|
||||
{
|
||||
|
||||
|
||||
printf("%s %s ",
|
||||
page_sizes[(tte >> TD_SIZE_SHIFT) & TD_SIZE_MASK],
|
||||
|
|
|
@ -218,70 +218,7 @@ userboot_zfs_probe(void)
|
|||
userboot_zfs_found = 1;
|
||||
}
|
||||
}
|
||||
|
||||
COMMAND_SET(lszfs, "lszfs", "list child datasets of a zfs dataset",
|
||||
command_lszfs);
|
||||
|
||||
static int
|
||||
command_lszfs(int argc, char *argv[])
|
||||
{
|
||||
int err;
|
||||
|
||||
if (argc != 2) {
|
||||
command_errmsg = "a single dataset must be supplied";
|
||||
return (CMD_ERROR);
|
||||
}
|
||||
|
||||
err = zfs_list(argv[1]);
|
||||
if (err != 0) {
|
||||
command_errmsg = strerror(err);
|
||||
return (CMD_ERROR);
|
||||
}
|
||||
return (CMD_OK);
|
||||
}
|
||||
|
||||
COMMAND_SET(reloadbe, "reloadbe", "refresh the list of ZFS Boot Environments",
|
||||
command_reloadbe);
|
||||
|
||||
static int
|
||||
command_reloadbe(int argc, char *argv[])
|
||||
{
|
||||
int err;
|
||||
char *root;
|
||||
|
||||
if (argc > 2) {
|
||||
command_errmsg = "wrong number of arguments";
|
||||
return (CMD_ERROR);
|
||||
}
|
||||
|
||||
if (argc == 2) {
|
||||
err = zfs_bootenv(argv[1]);
|
||||
} else {
|
||||
root = getenv("zfs_be_root");
|
||||
if (root == NULL) {
|
||||
return (CMD_OK);
|
||||
}
|
||||
err = zfs_bootenv(root);
|
||||
}
|
||||
|
||||
if (err != 0) {
|
||||
command_errmsg = strerror(err);
|
||||
return (CMD_ERROR);
|
||||
}
|
||||
|
||||
return (CMD_OK);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
ldi_get_size(void *priv)
|
||||
{
|
||||
int fd = (uintptr_t) priv;
|
||||
uint64_t size;
|
||||
|
||||
ioctl(fd, DIOCGMEDIASIZE, &size);
|
||||
return (size);
|
||||
}
|
||||
#endif /* USERBOOT_ZFS_SUPPORT */
|
||||
#endif
|
||||
|
||||
COMMAND_SET(quit, "quit", "exit the loader", command_quit);
|
||||
|
||||
|
|
Loading…
Reference in a new issue