zhack.c revision 7fdd916c474ea52896c671bbe7b56ba34a1ca132
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2013 by Delphix. All rights reserved.
* Copyright (c) 2013 Steven Hartland. All rights reserved.
*/
/*
* zhack is a debugging tool that can write changes to ZFS pool using libzpool
* for testing purposes. Altering pools with zhack is unsupported and may
* result in corrupted pools.
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <sys/zfs_context.h>
#include <sys/spa_impl.h>
#include <sys/zfs_znode.h>
#include <sys/dsl_synctask.h>
#include <sys/dmu_objset.h>
#include <sys/dsl_pool.h>
#include <sys/zio_checksum.h>
#include <sys/zio_compress.h>
#include <sys/zfeature.h>
#include <libzfs.h>
extern boolean_t zfeature_checks_disable;
const char cmdname[] = "zhack";
static importargs_t g_importargs;
static char *g_pool;
static boolean_t g_readonly;
static void
usage(void)
{
"Usage: %s [-c cachefile] [-d dir] <subcommand> <args> ...\n"
"where <subcommand> <args> is one of the following:\n"
"\n", cmdname);
" feature stat <pool>\n"
" print information about enabled features\n"
" feature enable [-d desc] <pool> <feature>\n"
" add a new enabled feature to the pool\n"
" -d <desc> sets the feature's description\n"
" feature ref [-md] <pool> <feature>\n"
" change the refcount on the given feature\n"
" -d decrease instead of increase the refcount\n"
" -m add the feature to the label if increasing refcount\n"
"\n"
" <feature> : should be a feature guid\n");
exit(1);
}
static void
{
}
exit(1);
}
/* ARGSUSED */
static int
{
/*
* Is it a valid type of object to track?
*/
return (ENOENT);
abort();
/* NOTREACHED */
}
/*
* Target is the dataset whose pool we want to open.
*/
static void
{
int error;
char *sepp;
const char *name;
g_zfs = libzfs_init();
/*
* If we only want readonly access, it's OK if we find
* a potentially-active (ie, imported into the kernel) pool from the
* default cachefile.
*/
return;
}
*sepp = '\0';
if (nvlist_empty(pools)) {
if (!g_importargs.can_be_active) {
"active; run " "\"zpool export %s\" "
}
}
"available\n", g_pool);
}
if (readonly) {
}
error = 0;
if (error)
}
static void
{
int err;
if (err != 0)
}
}
static void
{
zap_cursor_advance(&zc)) {
(void) printf("\t%s = %llu\n",
} else {
char val[1024];
}
}
}
static void
{
(void) printf("label config:\n");
}
}
static void
{
char *target;
argc--;
argv++;
if (argc < 1) {
usage();
}
}
static void
{
"guid=%s can_readonly=%u",
}
static void
{
char c;
/*
* Features are not added to the pool's label until their refcounts
* are incremented, so fi_mos can just be left as false for now.
*/
optind = 1;
switch (c) {
case 'r':
break;
case 'd':
break;
default:
usage();
break;
}
}
if (argc < 2) {
usage();
}
}
static void
{
}
static void
{
}
static void
{
char c;
char *target;
/*
* fi_desc does not matter here because it was written to disk
* when the feature was enabled, but we need to properly set the
* feature for read or write based on the information we read off
* disk later.
*/
optind = 1;
switch (c) {
case 'm':
break;
case 'd':
break;
default:
usage();
break;
}
}
if (argc < 2) {
usage();
}
"refcount");
} else {
}
}
static int
{
char *subcommand;
argc--;
argv++;
if (argc == 0) {
"error: no feature operation specified\n");
usage();
}
subcommand = argv[0];
} else {
usage();
}
return (0);
}
#define MAX_NUM_PATHS 1024
int
{
extern void zfs_prop_init(void);
char *path[MAX_NUM_PATHS];
const char *subcommand;
int rv = 0;
char c;
switch (c) {
case 'c':
break;
case 'd':
break;
default:
usage();
break;
}
}
optind = 1;
if (argc == 0) {
usage();
}
subcommand = argv[0];
} else {
usage();
}
"changes may not be committed to disk\n");
}
kernel_fini();
return (rv);
}