Changeset View
Changeset View
Standalone View
Standalone View
sbin/nvmecontrol/opts.h
- This file was copied from sbin/nvmecontrol/reset.c.
/*- | /*- | ||||
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD | * Copyright (c) 2019 Netflix, Inc | ||||
* | |||||
* Copyright (C) 2012-2013 Intel Corporation | |||||
* All rights reserved. | * All rights reserved. | ||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
* modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | ||||
* are met: | * are met: | ||||
* 1. Redistributions of source code must retain the above copyright | * 1. Redistributions of source code must retain the above copyright | ||||
* notice, this list of conditions and the following disclaimer. | * notice, this list of conditions and the following disclaimer. | ||||
* 2. Redistributions in binary form must reproduce the above copyright | * 2. Redistributions in binary form must reproduce the above copyright | ||||
* notice, this list of conditions and the following disclaimer in the | * notice, this list of conditions and the following disclaimer in the | ||||
* documentation and/or other materials provided with the distribution. | * documentation and/or other materials provided with the distribution. | ||||
* | * | ||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | * 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 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
* SUCH DAMAGE. | * SUCH DAMAGE. | ||||
* | |||||
* $FreeBSD$ | |||||
*/ | */ | ||||
#include <sys/cdefs.h> | #ifndef ARG_H | ||||
__FBSDID("$FreeBSD$"); | #define ARG_H | ||||
#include <sys/param.h> | /* | ||||
#include <sys/ioccom.h> | * Regularized parsing of simple arguments built on top of getopt_long. | ||||
*/ | |||||
#include <err.h> | typedef enum arg_type { | ||||
#include <fcntl.h> | arg_none = 0, | ||||
#include <stdio.h> | arg_uint8, | ||||
#include <stdlib.h> | arg_uint16, | ||||
#include <string.h> | arg_uint32, | ||||
#include <unistd.h> | arg_string, | ||||
arg_path, | |||||
} arg_type; | |||||
#include "nvmecontrol.h" | struct args { | ||||
const char *long_arg; | |||||
int short_arg; | |||||
arg_type at; | |||||
void *ptr; | |||||
const char *descr; | |||||
}; | |||||
#define RESET_USAGE \ | int arg_parse(int argc, char * const * argv, const char *desc, const struct args *); | ||||
"reset <controller id>\n" | #endif /* ARG_H */ | ||||
static void | |||||
reset(const struct nvme_function *nf, int argc, char *argv[]) | |||||
{ | |||||
int ch, fd; | |||||
while ((ch = getopt(argc, argv, "")) != -1) { | |||||
switch ((char)ch) { | |||||
default: | |||||
usage(nf); | |||||
} | |||||
} | |||||
/* Check that a controller was specified. */ | |||||
if (optind >= argc) | |||||
usage(nf); | |||||
open_dev(argv[optind], &fd, 1, 1); | |||||
if (ioctl(fd, NVME_RESET_CONTROLLER) < 0) | |||||
err(1, "reset request to %s failed", argv[optind]); | |||||
exit(0); | |||||
} | |||||
NVME_COMMAND(top, reset, reset, RESET_USAGE); |