2012-12-14 03:24:15 +04:00
|
|
|
/*
|
|
|
|
* 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
|
2022-07-12 00:16:13 +03:00
|
|
|
* or https://opensource.org/licenses/CDDL-1.0.
|
2012-12-14 03:24:15 +04:00
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2015-07-24 19:53:55 +03:00
|
|
|
* Copyright (c) 2011, 2015 by Delphix. All rights reserved.
|
2013-05-25 06:06:23 +04:00
|
|
|
* Copyright (c) 2013 Steven Hartland. All rights reserved.
|
2012-12-14 03:24:15 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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>
|
2021-11-11 22:26:18 +03:00
|
|
|
#include <sys/stat.h>
|
2012-12-14 03:24:15 +04:00
|
|
|
#include <sys/zfs_context.h>
|
|
|
|
#include <sys/spa.h>
|
|
|
|
#include <sys/spa_impl.h>
|
|
|
|
#include <sys/dmu.h>
|
|
|
|
#include <sys/zap.h>
|
|
|
|
#include <sys/zfs_znode.h>
|
|
|
|
#include <sys/dsl_synctask.h>
|
|
|
|
#include <sys/vdev.h>
|
2021-11-11 22:26:18 +03:00
|
|
|
#include <sys/vdev_impl.h>
|
2012-12-14 03:24:15 +04:00
|
|
|
#include <sys/fs/zfs.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>
|
2013-09-04 16:00:57 +04:00
|
|
|
#include <sys/dmu_tx.h>
|
2021-05-15 12:53:14 +03:00
|
|
|
#include <zfeature_common.h>
|
2018-11-05 22:22:33 +03:00
|
|
|
#include <libzutil.h>
|
2012-12-14 03:24:15 +04:00
|
|
|
|
|
|
|
static importargs_t g_importargs;
|
|
|
|
static char *g_pool;
|
|
|
|
static boolean_t g_readonly;
|
|
|
|
|
2022-03-23 18:51:00 +03:00
|
|
|
static __attribute__((noreturn)) void
|
2012-12-14 03:24:15 +04:00
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
(void) fprintf(stderr,
|
2022-01-15 02:37:55 +03:00
|
|
|
"Usage: zhack [-c cachefile] [-d dir] <subcommand> <args> ...\n"
|
2012-12-14 03:24:15 +04:00
|
|
|
"where <subcommand> <args> is one of the following:\n"
|
2022-01-15 02:37:55 +03:00
|
|
|
"\n");
|
2012-12-14 03:24:15 +04:00
|
|
|
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
" feature stat <pool>\n"
|
|
|
|
" print information about enabled features\n"
|
2016-08-31 04:56:36 +03:00
|
|
|
" feature enable [-r] [-d desc] <pool> <feature>\n"
|
2012-12-14 03:24:15 +04:00
|
|
|
" add a new enabled feature to the pool\n"
|
|
|
|
" -d <desc> sets the feature's description\n"
|
2016-08-31 04:56:36 +03:00
|
|
|
" -r set read-only compatible flag for feature\n"
|
2012-12-14 03:24:15 +04:00
|
|
|
" 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"
|
2021-11-11 22:26:18 +03:00
|
|
|
" <feature> : should be a feature guid\n"
|
|
|
|
"\n"
|
|
|
|
" label repair <device>\n"
|
|
|
|
" repair corrupted label checksums\n"
|
|
|
|
"\n"
|
|
|
|
" <device> : path to vdev\n");
|
2012-12-14 03:24:15 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-23 18:51:00 +03:00
|
|
|
static __attribute__((format(printf, 3, 4))) __attribute__((noreturn)) void
|
2022-04-19 21:49:30 +03:00
|
|
|
fatal(spa_t *spa, const void *tag, const char *fmt, ...)
|
2012-12-14 03:24:15 +04:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2013-10-05 02:13:23 +04:00
|
|
|
if (spa != NULL) {
|
|
|
|
spa_close(spa, tag);
|
|
|
|
(void) spa_export(g_pool, NULL, B_TRUE, B_FALSE);
|
|
|
|
}
|
|
|
|
|
2012-12-14 03:24:15 +04:00
|
|
|
va_start(ap, fmt);
|
2022-01-15 02:37:55 +03:00
|
|
|
(void) fputs("zhack: ", stderr);
|
2012-12-14 03:24:15 +04:00
|
|
|
(void) vfprintf(stderr, fmt, ap);
|
|
|
|
va_end(ap);
|
2022-01-15 02:37:55 +03:00
|
|
|
(void) fputc('\n', stderr);
|
2012-12-14 03:24:15 +04:00
|
|
|
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
File incorrectly zeroed when receiving incremental stream that toggles -L
Background:
By increasing the recordsize property above the default of 128KB, a
filesystem may have "large" blocks. By default, a send stream of such a
filesystem does not contain large WRITE records, instead it decreases
objects' block sizes to 128KB and splits the large blocks into 128KB
blocks, allowing the large-block filesystem to be received by a system
that does not support the `large_blocks` feature. A send stream
generated by `zfs send -L` (or `--large-block`) preserves the large
block size on the receiving system, by using large WRITE records.
When receiving an incremental send stream for a filesystem with large
blocks, if the send stream's -L flag was toggled, a bug is encountered
in which the file's contents are incorrectly zeroed out. The contents
of any blocks that were not modified by this send stream will be lost.
"Toggled" means that the previous send used `-L`, but this incremental
does not use `-L` (-L to no-L); or that the previous send did not use
`-L`, but this incremental does use `-L` (no-L to -L).
Changes:
This commit addresses the problem with several changes to the semantics
of zfs send/receive:
1. "-L to no-L" incrementals are rejected. If the previous send used
`-L`, but this incremental does not use `-L`, the `zfs receive` will
fail with this error message:
incremental send stream requires -L (--large-block), to match
previous receive.
2. "no-L to -L" incrementals are handled correctly, preserving the
smaller (128KB) block size of any already-received files that used large
blocks on the sending system but were split by `zfs send` without the
`-L` flag.
3. A new send stream format flag is added, `SWITCH_TO_LARGE_BLOCKS`.
This feature indicates that we can correctly handle "no-L to -L"
incrementals. This flag is currently not set on any send streams. In
the future, we intend for incremental send streams of snapshots that
have large blocks to use `-L` by default, and these streams will also
have the `SWITCH_TO_LARGE_BLOCKS` feature set. This ensures that streams
from the default use of `zfs send` won't encounter the bug mentioned
above, because they can't be received by software with the bug.
Implementation notes:
To facilitate accessing the ZPL's generation number,
`zfs_space_delta_cb()` has been renamed to `zpl_get_file_info()` and
restructured to fill in a struct with ZPL-specific info including owner
and generation.
In the "no-L to -L" case, if this is a compressed send stream (from
`zfs send -cL`), large WRITE records that are being written to small
(128KB) blocksize files need to be decompressed so that they can be
written split up into multiple blocks. The zio pipeline will recompress
each smaller block individually.
A new test case, `send-L_toggle`, is added, which tests the "no-L to -L"
case and verifies that we get an error for the "-L to no-L" case.
Reviewed-by: Paul Dagnelie <pcd@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
Closes #6224
Closes #10383
2020-06-09 20:41:01 +03:00
|
|
|
space_delta_cb(dmu_object_type_t bonustype, const void *data,
|
|
|
|
zfs_file_info_t *zoi)
|
2012-12-14 03:24:15 +04:00
|
|
|
{
|
2021-12-11 02:56:00 +03:00
|
|
|
(void) data, (void) zoi;
|
|
|
|
|
2012-12-14 03:24:15 +04:00
|
|
|
/*
|
|
|
|
* Is it a valid type of object to track?
|
|
|
|
*/
|
|
|
|
if (bonustype != DMU_OT_ZNODE && bonustype != DMU_OT_SA)
|
|
|
|
return (ENOENT);
|
|
|
|
(void) fprintf(stderr, "modifying object that needs user accounting");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Target is the dataset whose pool we want to open.
|
|
|
|
*/
|
|
|
|
static void
|
Multi-modifier protection (MMP)
Add multihost=on|off pool property to control MMP. When enabled
a new thread writes uberblocks to the last slot in each label, at a
set frequency, to indicate to other hosts the pool is actively imported.
These uberblocks are the last synced uberblock with an updated
timestamp. Property defaults to off.
During tryimport, find the "best" uberblock (newest txg and timestamp)
repeatedly, checking for change in the found uberblock. Include the
results of the activity test in the config returned by tryimport.
These results are reported to user in "zpool import".
Allow the user to control the period between MMP writes, and the
duration of the activity test on import, via a new module parameter
zfs_multihost_interval. The period is specified in milliseconds. The
activity test duration is calculated from this value, and from the
mmp_delay in the "best" uberblock found initially.
Add a kstat interface to export statistics about Multiple Modifier
Protection (MMP) updates. Include the last synced txg number, the
timestamp, the delay since the last MMP update, the VDEV GUID, the VDEV
label that received the last MMP update, and the VDEV path. Abbreviated
output below.
$ cat /proc/spl/kstat/zfs/mypool/multihost
31 0 0x01 10 880 105092382393521 105144180101111
txg timestamp mmp_delay vdev_guid vdev_label vdev_path
20468 261337 250274925 68396651780 3 /dev/sda
20468 261339 252023374 6267402363293 1 /dev/sdc
20468 261340 252000858 6698080955233 1 /dev/sdx
20468 261341 251980635 783892869810 2 /dev/sdy
20468 261342 253385953 8923255792467 3 /dev/sdd
20468 261344 253336622 042125143176 0 /dev/sdab
20468 261345 253310522 1200778101278 2 /dev/sde
20468 261346 253286429 0950576198362 2 /dev/sdt
20468 261347 253261545 96209817917 3 /dev/sds
20468 261349 253238188 8555725937673 3 /dev/sdb
Add a new tunable zfs_multihost_history to specify the number of MMP
updates to store history for. By default it is set to zero meaning that
no MMP statistics are stored.
When using ztest to generate activity, for automated tests of the MMP
function, some test functions interfere with the test. For example, the
pool is exported to run zdb and then imported again. Add a new ztest
function, "-M", to alter ztest behavior to prevent this.
Add new tests to verify the new functionality. Tests provided by
Giuseppe Di Natale.
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Giuseppe Di Natale <dinatale2@llnl.gov>
Reviewed-by: Ned Bass <bass6@llnl.gov>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Olaf Faaland <faaland1@llnl.gov>
Closes #745
Closes #6279
2017-07-08 06:20:35 +03:00
|
|
|
zhack_import(char *target, boolean_t readonly)
|
2012-12-14 03:24:15 +04:00
|
|
|
{
|
|
|
|
nvlist_t *config;
|
|
|
|
nvlist_t *props;
|
Multi-modifier protection (MMP)
Add multihost=on|off pool property to control MMP. When enabled
a new thread writes uberblocks to the last slot in each label, at a
set frequency, to indicate to other hosts the pool is actively imported.
These uberblocks are the last synced uberblock with an updated
timestamp. Property defaults to off.
During tryimport, find the "best" uberblock (newest txg and timestamp)
repeatedly, checking for change in the found uberblock. Include the
results of the activity test in the config returned by tryimport.
These results are reported to user in "zpool import".
Allow the user to control the period between MMP writes, and the
duration of the activity test on import, via a new module parameter
zfs_multihost_interval. The period is specified in milliseconds. The
activity test duration is calculated from this value, and from the
mmp_delay in the "best" uberblock found initially.
Add a kstat interface to export statistics about Multiple Modifier
Protection (MMP) updates. Include the last synced txg number, the
timestamp, the delay since the last MMP update, the VDEV GUID, the VDEV
label that received the last MMP update, and the VDEV path. Abbreviated
output below.
$ cat /proc/spl/kstat/zfs/mypool/multihost
31 0 0x01 10 880 105092382393521 105144180101111
txg timestamp mmp_delay vdev_guid vdev_label vdev_path
20468 261337 250274925 68396651780 3 /dev/sda
20468 261339 252023374 6267402363293 1 /dev/sdc
20468 261340 252000858 6698080955233 1 /dev/sdx
20468 261341 251980635 783892869810 2 /dev/sdy
20468 261342 253385953 8923255792467 3 /dev/sdd
20468 261344 253336622 042125143176 0 /dev/sdab
20468 261345 253310522 1200778101278 2 /dev/sde
20468 261346 253286429 0950576198362 2 /dev/sdt
20468 261347 253261545 96209817917 3 /dev/sds
20468 261349 253238188 8555725937673 3 /dev/sdb
Add a new tunable zfs_multihost_history to specify the number of MMP
updates to store history for. By default it is set to zero meaning that
no MMP statistics are stored.
When using ztest to generate activity, for automated tests of the MMP
function, some test functions interfere with the test. For example, the
pool is exported to run zdb and then imported again. Add a new ztest
function, "-M", to alter ztest behavior to prevent this.
Add new tests to verify the new functionality. Tests provided by
Giuseppe Di Natale.
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Giuseppe Di Natale <dinatale2@llnl.gov>
Reviewed-by: Ned Bass <bass6@llnl.gov>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Olaf Faaland <faaland1@llnl.gov>
Closes #745
Closes #6279
2017-07-08 06:20:35 +03:00
|
|
|
int error;
|
2012-12-14 03:24:15 +04:00
|
|
|
|
2019-11-21 20:32:57 +03:00
|
|
|
kernel_init(readonly ? SPA_MODE_READ :
|
|
|
|
(SPA_MODE_READ | SPA_MODE_WRITE));
|
2012-12-14 03:24:15 +04:00
|
|
|
|
|
|
|
dmu_objset_register_type(DMU_OST_ZFS, space_delta_cb);
|
|
|
|
|
|
|
|
g_readonly = readonly;
|
|
|
|
g_importargs.can_be_active = readonly;
|
|
|
|
g_pool = strdup(target);
|
|
|
|
|
2018-11-05 22:22:33 +03:00
|
|
|
error = zpool_find_config(NULL, target, &config, &g_importargs,
|
|
|
|
&libzpool_config_ops);
|
Multi-modifier protection (MMP)
Add multihost=on|off pool property to control MMP. When enabled
a new thread writes uberblocks to the last slot in each label, at a
set frequency, to indicate to other hosts the pool is actively imported.
These uberblocks are the last synced uberblock with an updated
timestamp. Property defaults to off.
During tryimport, find the "best" uberblock (newest txg and timestamp)
repeatedly, checking for change in the found uberblock. Include the
results of the activity test in the config returned by tryimport.
These results are reported to user in "zpool import".
Allow the user to control the period between MMP writes, and the
duration of the activity test on import, via a new module parameter
zfs_multihost_interval. The period is specified in milliseconds. The
activity test duration is calculated from this value, and from the
mmp_delay in the "best" uberblock found initially.
Add a kstat interface to export statistics about Multiple Modifier
Protection (MMP) updates. Include the last synced txg number, the
timestamp, the delay since the last MMP update, the VDEV GUID, the VDEV
label that received the last MMP update, and the VDEV path. Abbreviated
output below.
$ cat /proc/spl/kstat/zfs/mypool/multihost
31 0 0x01 10 880 105092382393521 105144180101111
txg timestamp mmp_delay vdev_guid vdev_label vdev_path
20468 261337 250274925 68396651780 3 /dev/sda
20468 261339 252023374 6267402363293 1 /dev/sdc
20468 261340 252000858 6698080955233 1 /dev/sdx
20468 261341 251980635 783892869810 2 /dev/sdy
20468 261342 253385953 8923255792467 3 /dev/sdd
20468 261344 253336622 042125143176 0 /dev/sdab
20468 261345 253310522 1200778101278 2 /dev/sde
20468 261346 253286429 0950576198362 2 /dev/sdt
20468 261347 253261545 96209817917 3 /dev/sds
20468 261349 253238188 8555725937673 3 /dev/sdb
Add a new tunable zfs_multihost_history to specify the number of MMP
updates to store history for. By default it is set to zero meaning that
no MMP statistics are stored.
When using ztest to generate activity, for automated tests of the MMP
function, some test functions interfere with the test. For example, the
pool is exported to run zdb and then imported again. Add a new ztest
function, "-M", to alter ztest behavior to prevent this.
Add new tests to verify the new functionality. Tests provided by
Giuseppe Di Natale.
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Giuseppe Di Natale <dinatale2@llnl.gov>
Reviewed-by: Ned Bass <bass6@llnl.gov>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Olaf Faaland <faaland1@llnl.gov>
Closes #745
Closes #6279
2017-07-08 06:20:35 +03:00
|
|
|
if (error)
|
2018-11-05 22:22:33 +03:00
|
|
|
fatal(NULL, FTAG, "cannot import '%s'", target);
|
2012-12-14 03:24:15 +04:00
|
|
|
|
|
|
|
props = NULL;
|
|
|
|
if (readonly) {
|
|
|
|
VERIFY(nvlist_alloc(&props, NV_UNIQUE_NAME, 0) == 0);
|
|
|
|
VERIFY(nvlist_add_uint64(props,
|
|
|
|
zpool_prop_to_name(ZPOOL_PROP_READONLY), 1) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
zfeature_checks_disable = B_TRUE;
|
2017-07-15 02:32:55 +03:00
|
|
|
error = spa_import(target, config, props,
|
|
|
|
(readonly ? ZFS_IMPORT_SKIP_MMP : ZFS_IMPORT_NORMAL));
|
2020-12-23 20:52:24 +03:00
|
|
|
fnvlist_free(config);
|
2012-12-14 03:24:15 +04:00
|
|
|
zfeature_checks_disable = B_FALSE;
|
|
|
|
if (error == EEXIST)
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
if (error)
|
Multi-modifier protection (MMP)
Add multihost=on|off pool property to control MMP. When enabled
a new thread writes uberblocks to the last slot in each label, at a
set frequency, to indicate to other hosts the pool is actively imported.
These uberblocks are the last synced uberblock with an updated
timestamp. Property defaults to off.
During tryimport, find the "best" uberblock (newest txg and timestamp)
repeatedly, checking for change in the found uberblock. Include the
results of the activity test in the config returned by tryimport.
These results are reported to user in "zpool import".
Allow the user to control the period between MMP writes, and the
duration of the activity test on import, via a new module parameter
zfs_multihost_interval. The period is specified in milliseconds. The
activity test duration is calculated from this value, and from the
mmp_delay in the "best" uberblock found initially.
Add a kstat interface to export statistics about Multiple Modifier
Protection (MMP) updates. Include the last synced txg number, the
timestamp, the delay since the last MMP update, the VDEV GUID, the VDEV
label that received the last MMP update, and the VDEV path. Abbreviated
output below.
$ cat /proc/spl/kstat/zfs/mypool/multihost
31 0 0x01 10 880 105092382393521 105144180101111
txg timestamp mmp_delay vdev_guid vdev_label vdev_path
20468 261337 250274925 68396651780 3 /dev/sda
20468 261339 252023374 6267402363293 1 /dev/sdc
20468 261340 252000858 6698080955233 1 /dev/sdx
20468 261341 251980635 783892869810 2 /dev/sdy
20468 261342 253385953 8923255792467 3 /dev/sdd
20468 261344 253336622 042125143176 0 /dev/sdab
20468 261345 253310522 1200778101278 2 /dev/sde
20468 261346 253286429 0950576198362 2 /dev/sdt
20468 261347 253261545 96209817917 3 /dev/sds
20468 261349 253238188 8555725937673 3 /dev/sdb
Add a new tunable zfs_multihost_history to specify the number of MMP
updates to store history for. By default it is set to zero meaning that
no MMP statistics are stored.
When using ztest to generate activity, for automated tests of the MMP
function, some test functions interfere with the test. For example, the
pool is exported to run zdb and then imported again. Add a new ztest
function, "-M", to alter ztest behavior to prevent this.
Add new tests to verify the new functionality. Tests provided by
Giuseppe Di Natale.
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Giuseppe Di Natale <dinatale2@llnl.gov>
Reviewed-by: Ned Bass <bass6@llnl.gov>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Olaf Faaland <faaland1@llnl.gov>
Closes #745
Closes #6279
2017-07-08 06:20:35 +03:00
|
|
|
fatal(NULL, FTAG, "can't import '%s': %s", target,
|
2013-10-05 02:13:23 +04:00
|
|
|
strerror(error));
|
2012-12-14 03:24:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-04-19 21:49:30 +03:00
|
|
|
zhack_spa_open(char *target, boolean_t readonly, const void *tag, spa_t **spa)
|
2012-12-14 03:24:15 +04:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
Multi-modifier protection (MMP)
Add multihost=on|off pool property to control MMP. When enabled
a new thread writes uberblocks to the last slot in each label, at a
set frequency, to indicate to other hosts the pool is actively imported.
These uberblocks are the last synced uberblock with an updated
timestamp. Property defaults to off.
During tryimport, find the "best" uberblock (newest txg and timestamp)
repeatedly, checking for change in the found uberblock. Include the
results of the activity test in the config returned by tryimport.
These results are reported to user in "zpool import".
Allow the user to control the period between MMP writes, and the
duration of the activity test on import, via a new module parameter
zfs_multihost_interval. The period is specified in milliseconds. The
activity test duration is calculated from this value, and from the
mmp_delay in the "best" uberblock found initially.
Add a kstat interface to export statistics about Multiple Modifier
Protection (MMP) updates. Include the last synced txg number, the
timestamp, the delay since the last MMP update, the VDEV GUID, the VDEV
label that received the last MMP update, and the VDEV path. Abbreviated
output below.
$ cat /proc/spl/kstat/zfs/mypool/multihost
31 0 0x01 10 880 105092382393521 105144180101111
txg timestamp mmp_delay vdev_guid vdev_label vdev_path
20468 261337 250274925 68396651780 3 /dev/sda
20468 261339 252023374 6267402363293 1 /dev/sdc
20468 261340 252000858 6698080955233 1 /dev/sdx
20468 261341 251980635 783892869810 2 /dev/sdy
20468 261342 253385953 8923255792467 3 /dev/sdd
20468 261344 253336622 042125143176 0 /dev/sdab
20468 261345 253310522 1200778101278 2 /dev/sde
20468 261346 253286429 0950576198362 2 /dev/sdt
20468 261347 253261545 96209817917 3 /dev/sds
20468 261349 253238188 8555725937673 3 /dev/sdb
Add a new tunable zfs_multihost_history to specify the number of MMP
updates to store history for. By default it is set to zero meaning that
no MMP statistics are stored.
When using ztest to generate activity, for automated tests of the MMP
function, some test functions interfere with the test. For example, the
pool is exported to run zdb and then imported again. Add a new ztest
function, "-M", to alter ztest behavior to prevent this.
Add new tests to verify the new functionality. Tests provided by
Giuseppe Di Natale.
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Giuseppe Di Natale <dinatale2@llnl.gov>
Reviewed-by: Ned Bass <bass6@llnl.gov>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Olaf Faaland <faaland1@llnl.gov>
Closes #745
Closes #6279
2017-07-08 06:20:35 +03:00
|
|
|
zhack_import(target, readonly);
|
2012-12-14 03:24:15 +04:00
|
|
|
|
|
|
|
zfeature_checks_disable = B_TRUE;
|
|
|
|
err = spa_open(target, spa, tag);
|
|
|
|
zfeature_checks_disable = B_FALSE;
|
|
|
|
|
|
|
|
if (err != 0)
|
2013-10-05 02:13:23 +04:00
|
|
|
fatal(*spa, FTAG, "cannot open '%s': %s", target,
|
|
|
|
strerror(err));
|
2012-12-14 03:24:15 +04:00
|
|
|
if (spa_version(*spa) < SPA_VERSION_FEATURES) {
|
2013-10-05 02:13:23 +04:00
|
|
|
fatal(*spa, FTAG, "'%s' has version %d, features not enabled",
|
|
|
|
target, (int)spa_version(*spa));
|
2012-12-14 03:24:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dump_obj(objset_t *os, uint64_t obj, const char *name)
|
|
|
|
{
|
|
|
|
zap_cursor_t zc;
|
|
|
|
zap_attribute_t za;
|
|
|
|
|
|
|
|
(void) printf("%s_obj:\n", name);
|
|
|
|
|
|
|
|
for (zap_cursor_init(&zc, os, obj);
|
|
|
|
zap_cursor_retrieve(&zc, &za) == 0;
|
|
|
|
zap_cursor_advance(&zc)) {
|
|
|
|
if (za.za_integer_length == 8) {
|
|
|
|
ASSERT(za.za_num_integers == 1);
|
|
|
|
(void) printf("\t%s = %llu\n",
|
|
|
|
za.za_name, (u_longlong_t)za.za_first_integer);
|
|
|
|
} else {
|
|
|
|
ASSERT(za.za_integer_length == 1);
|
|
|
|
char val[1024];
|
|
|
|
VERIFY(zap_lookup(os, obj, za.za_name,
|
|
|
|
1, sizeof (val), val) == 0);
|
|
|
|
(void) printf("\t%s = %s\n", za.za_name, val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
zap_cursor_fini(&zc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dump_mos(spa_t *spa)
|
|
|
|
{
|
|
|
|
nvlist_t *nv = spa->spa_label_features;
|
|
|
|
nvpair_t *pair;
|
|
|
|
|
|
|
|
(void) printf("label config:\n");
|
|
|
|
for (pair = nvlist_next_nvpair(nv, NULL);
|
|
|
|
pair != NULL;
|
|
|
|
pair = nvlist_next_nvpair(nv, pair)) {
|
|
|
|
(void) printf("\t%s\n", nvpair_name(pair));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
zhack_do_feature_stat(int argc, char **argv)
|
|
|
|
{
|
|
|
|
spa_t *spa;
|
|
|
|
objset_t *os;
|
|
|
|
char *target;
|
|
|
|
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
|
|
|
|
if (argc < 1) {
|
|
|
|
(void) fprintf(stderr, "error: missing pool name\n");
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
target = argv[0];
|
|
|
|
|
|
|
|
zhack_spa_open(target, B_TRUE, FTAG, &spa);
|
|
|
|
os = spa->spa_meta_objset;
|
|
|
|
|
|
|
|
dump_obj(os, spa->spa_feat_for_read_obj, "for_read");
|
|
|
|
dump_obj(os, spa->spa_feat_for_write_obj, "for_write");
|
|
|
|
dump_obj(os, spa->spa_feat_desc_obj, "descriptions");
|
2013-12-09 22:37:51 +04:00
|
|
|
if (spa_feature_is_active(spa, SPA_FEATURE_ENABLED_TXG)) {
|
|
|
|
dump_obj(os, spa->spa_feat_enabled_txg_obj, "enabled_txg");
|
|
|
|
}
|
2012-12-14 03:24:15 +04:00
|
|
|
dump_mos(spa);
|
|
|
|
|
|
|
|
spa_close(spa, FTAG);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-10-08 21:13:05 +04:00
|
|
|
zhack_feature_enable_sync(void *arg, dmu_tx_t *tx)
|
2012-12-14 03:24:15 +04:00
|
|
|
{
|
2013-09-04 16:00:57 +04:00
|
|
|
spa_t *spa = dmu_tx_pool(tx)->dp_spa;
|
|
|
|
zfeature_info_t *feature = arg;
|
2012-12-14 03:24:15 +04:00
|
|
|
|
2013-10-08 21:13:05 +04:00
|
|
|
feature_enable_sync(spa, feature, tx);
|
|
|
|
|
2013-08-28 15:45:09 +04:00
|
|
|
spa_history_log_internal(spa, "zhack enable feature", tx,
|
2015-07-24 19:53:55 +03:00
|
|
|
"name=%s flags=%u",
|
|
|
|
feature->fi_guid, feature->fi_flags);
|
2012-12-14 03:24:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
zhack_do_feature_enable(int argc, char **argv)
|
|
|
|
{
|
2018-01-09 22:14:45 +03:00
|
|
|
int c;
|
2012-12-14 03:24:15 +04:00
|
|
|
char *desc, *target;
|
|
|
|
spa_t *spa;
|
|
|
|
objset_t *mos;
|
|
|
|
zfeature_info_t feature;
|
2022-01-15 02:37:55 +03:00
|
|
|
const spa_feature_t nodeps[] = { SPA_FEATURE_NONE };
|
2012-12-14 03:24:15 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
desc = NULL;
|
|
|
|
feature.fi_uname = "zhack";
|
2015-07-24 19:53:55 +03:00
|
|
|
feature.fi_flags = 0;
|
2012-12-14 03:24:15 +04:00
|
|
|
feature.fi_depends = nodeps;
|
2013-12-09 22:37:51 +04:00
|
|
|
feature.fi_feature = SPA_FEATURE_NONE;
|
2012-12-14 03:24:15 +04:00
|
|
|
|
|
|
|
optind = 1;
|
2016-08-31 04:56:36 +03:00
|
|
|
while ((c = getopt(argc, argv, "+rd:")) != -1) {
|
2012-12-14 03:24:15 +04:00
|
|
|
switch (c) {
|
|
|
|
case 'r':
|
2015-07-24 19:53:55 +03:00
|
|
|
feature.fi_flags |= ZFEATURE_FLAG_READONLY_COMPAT;
|
2012-12-14 03:24:15 +04:00
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
desc = strdup(optarg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (desc == NULL)
|
|
|
|
desc = strdup("zhack injected");
|
|
|
|
feature.fi_desc = desc;
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
(void) fprintf(stderr, "error: missing feature or pool name\n");
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
target = argv[0];
|
|
|
|
feature.fi_guid = argv[1];
|
|
|
|
|
|
|
|
if (!zfeature_is_valid_guid(feature.fi_guid))
|
2013-10-05 02:13:23 +04:00
|
|
|
fatal(NULL, FTAG, "invalid feature guid: %s", feature.fi_guid);
|
2012-12-14 03:24:15 +04:00
|
|
|
|
|
|
|
zhack_spa_open(target, B_FALSE, FTAG, &spa);
|
|
|
|
mos = spa->spa_meta_objset;
|
|
|
|
|
2016-05-17 21:44:50 +03:00
|
|
|
if (zfeature_is_supported(feature.fi_guid))
|
2021-06-05 15:18:37 +03:00
|
|
|
fatal(spa, FTAG, "'%s' is a real feature, will not enable",
|
|
|
|
feature.fi_guid);
|
2012-12-14 03:24:15 +04:00
|
|
|
if (0 == zap_contains(mos, spa->spa_feat_desc_obj, feature.fi_guid))
|
2013-10-05 02:13:23 +04:00
|
|
|
fatal(spa, FTAG, "feature already enabled: %s",
|
|
|
|
feature.fi_guid);
|
2012-12-14 03:24:15 +04:00
|
|
|
|
2013-09-04 16:00:57 +04:00
|
|
|
VERIFY0(dsl_sync_task(spa_name(spa), NULL,
|
2014-11-03 23:28:43 +03:00
|
|
|
zhack_feature_enable_sync, &feature, 5, ZFS_SPACE_CHECK_NORMAL));
|
2012-12-14 03:24:15 +04:00
|
|
|
|
|
|
|
spa_close(spa, FTAG);
|
|
|
|
|
|
|
|
free(desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-09-04 16:00:57 +04:00
|
|
|
feature_incr_sync(void *arg, dmu_tx_t *tx)
|
2012-12-14 03:24:15 +04:00
|
|
|
{
|
2013-09-04 16:00:57 +04:00
|
|
|
spa_t *spa = dmu_tx_pool(tx)->dp_spa;
|
|
|
|
zfeature_info_t *feature = arg;
|
2013-10-08 21:13:05 +04:00
|
|
|
uint64_t refcount;
|
2012-12-14 03:24:15 +04:00
|
|
|
|
2013-12-09 22:37:51 +04:00
|
|
|
VERIFY0(feature_get_refcount_from_disk(spa, feature, &refcount));
|
2013-10-08 21:13:05 +04:00
|
|
|
feature_sync(spa, feature, refcount + 1, tx);
|
2013-08-28 15:45:09 +04:00
|
|
|
spa_history_log_internal(spa, "zhack feature incr", tx,
|
|
|
|
"name=%s", feature->fi_guid);
|
2012-12-14 03:24:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-09-04 16:00:57 +04:00
|
|
|
feature_decr_sync(void *arg, dmu_tx_t *tx)
|
2012-12-14 03:24:15 +04:00
|
|
|
{
|
2013-09-04 16:00:57 +04:00
|
|
|
spa_t *spa = dmu_tx_pool(tx)->dp_spa;
|
|
|
|
zfeature_info_t *feature = arg;
|
2013-10-08 21:13:05 +04:00
|
|
|
uint64_t refcount;
|
2012-12-14 03:24:15 +04:00
|
|
|
|
2013-12-09 22:37:51 +04:00
|
|
|
VERIFY0(feature_get_refcount_from_disk(spa, feature, &refcount));
|
2013-10-08 21:13:05 +04:00
|
|
|
feature_sync(spa, feature, refcount - 1, tx);
|
2013-08-28 15:45:09 +04:00
|
|
|
spa_history_log_internal(spa, "zhack feature decr", tx,
|
|
|
|
"name=%s", feature->fi_guid);
|
2012-12-14 03:24:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
zhack_do_feature_ref(int argc, char **argv)
|
|
|
|
{
|
2018-01-09 22:14:45 +03:00
|
|
|
int c;
|
2012-12-14 03:24:15 +04:00
|
|
|
char *target;
|
|
|
|
boolean_t decr = B_FALSE;
|
|
|
|
spa_t *spa;
|
|
|
|
objset_t *mos;
|
|
|
|
zfeature_info_t feature;
|
2022-01-15 02:37:55 +03:00
|
|
|
const spa_feature_t nodeps[] = { SPA_FEATURE_NONE };
|
2012-12-14 03:24:15 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
feature.fi_uname = "zhack";
|
2015-07-24 19:53:55 +03:00
|
|
|
feature.fi_flags = 0;
|
2012-12-14 03:24:15 +04:00
|
|
|
feature.fi_desc = NULL;
|
|
|
|
feature.fi_depends = nodeps;
|
2013-12-09 22:37:51 +04:00
|
|
|
feature.fi_feature = SPA_FEATURE_NONE;
|
2012-12-14 03:24:15 +04:00
|
|
|
|
|
|
|
optind = 1;
|
2016-08-31 04:56:36 +03:00
|
|
|
while ((c = getopt(argc, argv, "+md")) != -1) {
|
2012-12-14 03:24:15 +04:00
|
|
|
switch (c) {
|
|
|
|
case 'm':
|
2015-07-24 19:53:55 +03:00
|
|
|
feature.fi_flags |= ZFEATURE_FLAG_MOS;
|
2012-12-14 03:24:15 +04:00
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
decr = B_TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (argc < 2) {
|
|
|
|
(void) fprintf(stderr, "error: missing feature or pool name\n");
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
target = argv[0];
|
|
|
|
feature.fi_guid = argv[1];
|
|
|
|
|
|
|
|
if (!zfeature_is_valid_guid(feature.fi_guid))
|
2013-10-05 02:13:23 +04:00
|
|
|
fatal(NULL, FTAG, "invalid feature guid: %s", feature.fi_guid);
|
2012-12-14 03:24:15 +04:00
|
|
|
|
|
|
|
zhack_spa_open(target, B_FALSE, FTAG, &spa);
|
|
|
|
mos = spa->spa_meta_objset;
|
|
|
|
|
2013-10-08 21:13:05 +04:00
|
|
|
if (zfeature_is_supported(feature.fi_guid)) {
|
|
|
|
fatal(spa, FTAG,
|
2021-06-05 15:18:37 +03:00
|
|
|
"'%s' is a real feature, will not change refcount",
|
|
|
|
feature.fi_guid);
|
2013-10-08 21:13:05 +04:00
|
|
|
}
|
2012-12-14 03:24:15 +04:00
|
|
|
|
|
|
|
if (0 == zap_contains(mos, spa->spa_feat_for_read_obj,
|
|
|
|
feature.fi_guid)) {
|
2015-07-24 19:53:55 +03:00
|
|
|
feature.fi_flags &= ~ZFEATURE_FLAG_READONLY_COMPAT;
|
2012-12-14 03:24:15 +04:00
|
|
|
} else if (0 == zap_contains(mos, spa->spa_feat_for_write_obj,
|
|
|
|
feature.fi_guid)) {
|
2015-07-24 19:53:55 +03:00
|
|
|
feature.fi_flags |= ZFEATURE_FLAG_READONLY_COMPAT;
|
2012-12-14 03:24:15 +04:00
|
|
|
} else {
|
2013-10-05 02:13:23 +04:00
|
|
|
fatal(spa, FTAG, "feature is not enabled: %s", feature.fi_guid);
|
2012-12-14 03:24:15 +04:00
|
|
|
}
|
|
|
|
|
2013-10-08 21:13:05 +04:00
|
|
|
if (decr) {
|
|
|
|
uint64_t count;
|
2013-12-09 22:37:51 +04:00
|
|
|
if (feature_get_refcount_from_disk(spa, &feature,
|
2015-10-02 02:39:25 +03:00
|
|
|
&count) == 0 && count == 0) {
|
2013-10-08 21:13:05 +04:00
|
|
|
fatal(spa, FTAG, "feature refcount already 0: %s",
|
|
|
|
feature.fi_guid);
|
|
|
|
}
|
|
|
|
}
|
2012-12-14 03:24:15 +04:00
|
|
|
|
2013-09-04 16:00:57 +04:00
|
|
|
VERIFY0(dsl_sync_task(spa_name(spa), NULL,
|
2014-11-03 23:28:43 +03:00
|
|
|
decr ? feature_decr_sync : feature_incr_sync, &feature,
|
|
|
|
5, ZFS_SPACE_CHECK_NORMAL));
|
2012-12-14 03:24:15 +04:00
|
|
|
|
|
|
|
spa_close(spa, FTAG);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
zhack_do_feature(int argc, char **argv)
|
|
|
|
{
|
|
|
|
char *subcommand;
|
|
|
|
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
if (argc == 0) {
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
"error: no feature operation specified\n");
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
subcommand = argv[0];
|
|
|
|
if (strcmp(subcommand, "stat") == 0) {
|
|
|
|
zhack_do_feature_stat(argc, argv);
|
|
|
|
} else if (strcmp(subcommand, "enable") == 0) {
|
|
|
|
zhack_do_feature_enable(argc, argv);
|
|
|
|
} else if (strcmp(subcommand, "ref") == 0) {
|
|
|
|
zhack_do_feature_ref(argc, argv);
|
|
|
|
} else {
|
|
|
|
(void) fprintf(stderr, "error: unknown subcommand: %s\n",
|
|
|
|
subcommand);
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2021-11-11 22:26:18 +03:00
|
|
|
static int
|
|
|
|
zhack_repair_label_cksum(int argc, char **argv)
|
|
|
|
{
|
|
|
|
zio_checksum_info_t *ci = &zio_checksum_table[ZIO_CHECKSUM_LABEL];
|
|
|
|
const char *cfg_keys[] = { ZPOOL_CONFIG_VERSION,
|
|
|
|
ZPOOL_CONFIG_POOL_STATE, ZPOOL_CONFIG_GUID };
|
2022-02-25 16:26:54 +03:00
|
|
|
boolean_t labels_repaired[VDEV_LABELS] = {0};
|
2021-11-11 22:26:18 +03:00
|
|
|
boolean_t repaired = B_FALSE;
|
2022-02-25 16:26:54 +03:00
|
|
|
vdev_label_t labels[VDEV_LABELS] = {{{0}}};
|
2021-11-11 22:26:18 +03:00
|
|
|
struct stat st;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
abd_init();
|
|
|
|
|
|
|
|
argc -= 1;
|
|
|
|
argv += 1;
|
|
|
|
|
|
|
|
if (argc < 1) {
|
|
|
|
(void) fprintf(stderr, "error: missing device\n");
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((fd = open(argv[0], O_RDWR)) == -1)
|
|
|
|
fatal(NULL, FTAG, "cannot open '%s': %s", argv[0],
|
|
|
|
strerror(errno));
|
|
|
|
|
|
|
|
if (stat(argv[0], &st) != 0)
|
|
|
|
fatal(NULL, FTAG, "cannot stat '%s': %s", argv[0],
|
|
|
|
strerror(errno));
|
|
|
|
|
|
|
|
for (int l = 0; l < VDEV_LABELS; l++) {
|
|
|
|
uint64_t label_offset, offset;
|
|
|
|
zio_cksum_t expected_cksum;
|
|
|
|
zio_cksum_t actual_cksum;
|
|
|
|
zio_cksum_t verifier;
|
|
|
|
zio_eck_t *eck;
|
|
|
|
nvlist_t *cfg;
|
|
|
|
int byteswap;
|
|
|
|
uint64_t val;
|
|
|
|
ssize_t err;
|
|
|
|
|
|
|
|
vdev_label_t *vl = &labels[l];
|
|
|
|
|
|
|
|
label_offset = vdev_label_offset(st.st_size, l, 0);
|
|
|
|
err = pread64(fd, vl, sizeof (vdev_label_t), label_offset);
|
|
|
|
if (err == -1) {
|
|
|
|
(void) fprintf(stderr, "error: cannot read "
|
|
|
|
"label %d: %s\n", l, strerror(errno));
|
|
|
|
continue;
|
|
|
|
} else if (err != sizeof (vdev_label_t)) {
|
|
|
|
(void) fprintf(stderr, "error: bad label %d read size "
|
|
|
|
"\n", l);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = nvlist_unpack(vl->vl_vdev_phys.vp_nvlist,
|
|
|
|
VDEV_PHYS_SIZE - sizeof (zio_eck_t), &cfg, 0);
|
|
|
|
if (err) {
|
|
|
|
(void) fprintf(stderr, "error: cannot unpack nvlist "
|
|
|
|
"label %d\n", l);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < ARRAY_SIZE(cfg_keys); i++) {
|
|
|
|
err = nvlist_lookup_uint64(cfg, cfg_keys[i], &val);
|
|
|
|
if (err) {
|
|
|
|
(void) fprintf(stderr, "error: label %d: "
|
|
|
|
"cannot find nvlist key %s\n",
|
|
|
|
l, cfg_keys[i]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void *data = (char *)vl + offsetof(vdev_label_t, vl_vdev_phys);
|
|
|
|
eck = (zio_eck_t *)((char *)(data) + VDEV_PHYS_SIZE) - 1;
|
|
|
|
|
|
|
|
offset = label_offset + offsetof(vdev_label_t, vl_vdev_phys);
|
|
|
|
ZIO_SET_CHECKSUM(&verifier, offset, 0, 0, 0);
|
|
|
|
|
|
|
|
byteswap = (eck->zec_magic == BSWAP_64(ZEC_MAGIC));
|
|
|
|
if (byteswap)
|
|
|
|
byteswap_uint64_array(&verifier, sizeof (zio_cksum_t));
|
|
|
|
|
|
|
|
expected_cksum = eck->zec_cksum;
|
|
|
|
eck->zec_cksum = verifier;
|
|
|
|
|
|
|
|
abd_t *abd = abd_get_from_buf(data, VDEV_PHYS_SIZE);
|
|
|
|
ci->ci_func[byteswap](abd, VDEV_PHYS_SIZE, NULL, &actual_cksum);
|
|
|
|
abd_free(abd);
|
|
|
|
|
|
|
|
if (byteswap)
|
|
|
|
byteswap_uint64_array(&expected_cksum,
|
|
|
|
sizeof (zio_cksum_t));
|
|
|
|
|
|
|
|
if (ZIO_CHECKSUM_EQUAL(actual_cksum, expected_cksum))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
eck->zec_cksum = actual_cksum;
|
|
|
|
|
|
|
|
err = pwrite64(fd, data, VDEV_PHYS_SIZE, offset);
|
|
|
|
if (err == -1) {
|
|
|
|
(void) fprintf(stderr, "error: cannot write "
|
|
|
|
"label %d: %s\n", l, strerror(errno));
|
|
|
|
continue;
|
|
|
|
} else if (err != VDEV_PHYS_SIZE) {
|
|
|
|
(void) fprintf(stderr, "error: bad write size "
|
|
|
|
"label %d\n", l);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
fsync(fd);
|
|
|
|
|
|
|
|
labels_repaired[l] = B_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
abd_fini();
|
|
|
|
|
|
|
|
for (int l = 0; l < VDEV_LABELS; l++) {
|
|
|
|
(void) printf("label %d: %s\n", l,
|
|
|
|
labels_repaired[l] ? "repaired" : "skipped");
|
|
|
|
repaired |= labels_repaired[l];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (repaired)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
zhack_do_label(int argc, char **argv)
|
|
|
|
{
|
|
|
|
char *subcommand;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
if (argc == 0) {
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
"error: no label operation specified\n");
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
subcommand = argv[0];
|
|
|
|
if (strcmp(subcommand, "repair") == 0) {
|
|
|
|
err = zhack_repair_label_cksum(argc, argv);
|
|
|
|
} else {
|
|
|
|
(void) fprintf(stderr, "error: unknown subcommand: %s\n",
|
|
|
|
subcommand);
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
2012-12-14 03:24:15 +04:00
|
|
|
#define MAX_NUM_PATHS 1024
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
extern void zfs_prop_init(void);
|
|
|
|
|
|
|
|
char *path[MAX_NUM_PATHS];
|
|
|
|
const char *subcommand;
|
|
|
|
int rv = 0;
|
2018-01-09 22:14:45 +03:00
|
|
|
int c;
|
2012-12-14 03:24:15 +04:00
|
|
|
|
|
|
|
g_importargs.path = path;
|
|
|
|
|
|
|
|
dprintf_setup(&argc, argv);
|
|
|
|
zfs_prop_init();
|
|
|
|
|
2016-08-31 04:56:36 +03:00
|
|
|
while ((c = getopt(argc, argv, "+c:d:")) != -1) {
|
2012-12-14 03:24:15 +04:00
|
|
|
switch (c) {
|
|
|
|
case 'c':
|
|
|
|
g_importargs.cachefile = optarg;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
assert(g_importargs.paths < MAX_NUM_PATHS);
|
|
|
|
g_importargs.path[g_importargs.paths++] = optarg;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
optind = 1;
|
|
|
|
|
|
|
|
if (argc == 0) {
|
|
|
|
(void) fprintf(stderr, "error: no command specified\n");
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
subcommand = argv[0];
|
|
|
|
|
|
|
|
if (strcmp(subcommand, "feature") == 0) {
|
|
|
|
rv = zhack_do_feature(argc, argv);
|
2021-11-11 22:26:18 +03:00
|
|
|
} else if (strcmp(subcommand, "label") == 0) {
|
|
|
|
return (zhack_do_label(argc, argv));
|
2012-12-14 03:24:15 +04:00
|
|
|
} else {
|
|
|
|
(void) fprintf(stderr, "error: unknown subcommand: %s\n",
|
|
|
|
subcommand);
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
2013-10-05 02:13:23 +04:00
|
|
|
if (!g_readonly && spa_export(g_pool, NULL, B_TRUE, B_FALSE) != 0) {
|
|
|
|
fatal(NULL, FTAG, "pool export failed; "
|
2012-12-14 03:24:15 +04:00
|
|
|
"changes may not be committed to disk\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
kernel_fini();
|
|
|
|
|
|
|
|
return (rv);
|
|
|
|
}
|