Skip to content

Commit

Permalink
1748 desire support for reguid in zfs
Browse files Browse the repository at this point in the history
Reviewed by: George Wilson <[email protected]>
Reviewed by: Igor Kozhukhov <[email protected]>
Reviewed by: Alexander Eremin <[email protected]>
Reviewed by: Alexander Stetsenko <[email protected]>
Approved by: Richard Lowe <[email protected]>
  • Loading branch information
Garrett D'Amore committed Nov 11, 2011
1 parent 193e336 commit e9103aa
Show file tree
Hide file tree
Showing 16 changed files with 234 additions and 17 deletions.
4 changes: 4 additions & 0 deletions usr/src/cmd/truss/codes.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

/*
* Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011 by Delphix. All rights reserved.
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
*/

/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
Expand Down Expand Up @@ -1248,6 +1250,8 @@ const struct ioc {
"zfs_cmd_t" },
{ (uint_t)ZFS_IOC_OBJ_TO_STATS, "ZFS_IOC_OBJ_TO_STATS",
"zfs_cmd_t" },
{ (uint_t)ZFS_IOC_POOL_REGUID, "ZFS_IOC_POOL_REGUID",
"zfs_cmd_t" },

/* kssl ioctls */
{ (uint_t)KSSL_ADD_ENTRY, "KSSL_ADD_ENTRY",
Expand Down
55 changes: 54 additions & 1 deletion usr/src/cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
* Copyright (c) 2011 by Delphix. All rights reserved.
*/

#include <assert.h>
Expand Down Expand Up @@ -65,6 +66,8 @@ static int zpool_do_online(int, char **);
static int zpool_do_offline(int, char **);
static int zpool_do_clear(int, char **);

static int zpool_do_reguid(int, char **);

static int zpool_do_attach(int, char **);
static int zpool_do_detach(int, char **);
static int zpool_do_replace(int, char **);
Expand Down Expand Up @@ -122,7 +125,8 @@ typedef enum {
HELP_UPGRADE,
HELP_GET,
HELP_SET,
HELP_SPLIT
HELP_SPLIT,
HELP_REGUID
} zpool_help_t;


Expand Down Expand Up @@ -166,6 +170,7 @@ static zpool_command_t command_table[] = {
{ "import", zpool_do_import, HELP_IMPORT },
{ "export", zpool_do_export, HELP_EXPORT },
{ "upgrade", zpool_do_upgrade, HELP_UPGRADE },
{ "reguid", zpool_do_reguid, HELP_REGUID },
{ NULL },
{ "history", zpool_do_history, HELP_HISTORY },
{ "get", zpool_do_get, HELP_GET },
Expand Down Expand Up @@ -244,6 +249,8 @@ get_usage(zpool_help_t idx) {
return (gettext("\tsplit [-n] [-R altroot] [-o mntopts]\n"
"\t [-o property=value] <pool> <newpool> "
"[<device> ...]\n"));
case HELP_REGUID:
return (gettext("\treguid <pool>\n"));
}

abort();
Expand Down Expand Up @@ -3193,6 +3200,52 @@ zpool_do_clear(int argc, char **argv)
return (ret);
}

/*
* zpool reguid <pool>
*/
int
zpool_do_reguid(int argc, char **argv)
{
int c;
char *poolname;
zpool_handle_t *zhp;
int ret = 0;

/* check options */
while ((c = getopt(argc, argv, "")) != -1) {
switch (c) {
case '?':
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
optopt);
usage(B_FALSE);
}
}

argc -= optind;
argv += optind;

/* get pool name and check number of arguments */
if (argc < 1) {
(void) fprintf(stderr, gettext("missing pool name\n"));
usage(B_FALSE);
}

if (argc > 1) {
(void) fprintf(stderr, gettext("too many arguments\n"));
usage(B_FALSE);
}

poolname = argv[0];
if ((zhp = zpool_open(g_zfs, poolname)) == NULL)
return (1);

ret = zpool_reguid(zhp);

zpool_close(zhp);
return (ret);
}


typedef struct scrub_cbdata {
int cb_type;
int cb_argc;
Expand Down
36 changes: 35 additions & 1 deletion usr/src/cmd/ztest/ztest.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011 by Delphix. All rights reserved.
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
*/

/*
Expand Down Expand Up @@ -257,6 +258,7 @@ ztest_func_t ztest_vdev_LUN_growth;
ztest_func_t ztest_vdev_add_remove;
ztest_func_t ztest_vdev_aux_add_remove;
ztest_func_t ztest_split_pool;
ztest_func_t ztest_reguid;

uint64_t zopt_always = 0ULL * NANOSEC; /* all the time */
uint64_t zopt_incessant = 1ULL * NANOSEC / 10; /* every 1/10 second */
Expand Down Expand Up @@ -287,6 +289,7 @@ ztest_info_t ztest_info[] = {
{ ztest_fault_inject, 1, &zopt_sometimes },
{ ztest_ddt_repair, 1, &zopt_sometimes },
{ ztest_dmu_snapshot_hold, 1, &zopt_sometimes },
{ ztest_reguid, 1, &zopt_sometimes },
{ ztest_spa_rename, 1, &zopt_rarely },
{ ztest_scrub, 1, &zopt_rarely },
{ ztest_dsl_dataset_promote_busy, 1, &zopt_rarely },
Expand Down Expand Up @@ -323,6 +326,7 @@ typedef struct ztest_shared {
uint64_t zs_vdev_aux;
uint64_t zs_alloc;
uint64_t zs_space;
uint64_t zs_guid;
mutex_t zs_vdev_lock;
rwlock_t zs_name_lock;
ztest_info_t zs_info[ZTEST_FUNCS];
Expand Down Expand Up @@ -4641,7 +4645,7 @@ ztest_ddt_repair(ztest_ds_t *zd, uint64_t id)

object = od[0].od_object;
blocksize = od[0].od_blocksize;
pattern = spa_guid(spa) ^ dmu_objset_fsid_guid(os);
pattern = zs->zs_guid ^ dmu_objset_fsid_guid(os);

ASSERT(object != 0);

Expand Down Expand Up @@ -4711,6 +4715,31 @@ ztest_scrub(ztest_ds_t *zd, uint64_t id)
(void) spa_scan(spa, POOL_SCAN_SCRUB);
}

/*
* Change the guid for the pool.
*/
/* ARGSUSED */
void
ztest_reguid(ztest_ds_t *zd, uint64_t id)
{
ztest_shared_t *zs = ztest_shared;
spa_t *spa = zs->zs_spa;
uint64_t orig, load;

orig = spa_guid(spa);
load = spa_load_guid(spa);
if (spa_change_guid(spa) != 0)
return;

if (zopt_verbose >= 3) {
(void) printf("Changed guid old %llu -> %llu\n",
(u_longlong_t)orig, (u_longlong_t)spa_guid(spa));
}

VERIFY3U(orig, !=, spa_guid(spa));
VERIFY3U(load, ==, spa_load_guid(spa));
}

/*
* Rename the pool to a different name and then rename it back.
*/
Expand Down Expand Up @@ -5139,6 +5168,7 @@ ztest_run(ztest_shared_t *zs)
{
thread_t *tid;
spa_t *spa;
objset_t *os;
thread_t resume_tid;
int error;

Expand Down Expand Up @@ -5170,6 +5200,10 @@ ztest_run(ztest_shared_t *zs)
spa->spa_debug = B_TRUE;
zs->zs_spa = spa;

VERIFY3U(0, ==, dmu_objset_hold(zs->zs_pool, FTAG, &os));
zs->zs_guid = dmu_objset_fsid_guid(os);
dmu_objset_rele(os, FTAG);

spa->spa_dedup_ditto = 2 * ZIO_DEDUPDITTO_MIN;

/*
Expand Down
4 changes: 3 additions & 1 deletion usr/src/lib/libzfs/common/libzfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2010 Nexenta Systems, Inc. All rights reserved.
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
* Copyright (c) 2011 by Delphix. All rights reserved.
*/

#ifndef _LIBZFS_H
Expand Down Expand Up @@ -230,6 +231,7 @@ typedef struct splitflags {
*/
extern int zpool_scan(zpool_handle_t *, pool_scan_func_t);
extern int zpool_clear(zpool_handle_t *, const char *, nvlist_t *);
extern int zpool_reguid(zpool_handle_t *);

extern int zpool_vdev_online(zpool_handle_t *, const char *, int,
vdev_state_t *);
Expand Down
22 changes: 22 additions & 0 deletions usr/src/lib/libzfs/common/libzfs_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
* Copyright (c) 2011 by Delphix. All rights reserved.
*/

#include <ctype.h>
Expand Down Expand Up @@ -2966,6 +2968,26 @@ zpool_vdev_clear(zpool_handle_t *zhp, uint64_t guid)
return (zpool_standard_error(hdl, errno, msg));
}

/*
* Change the GUID for a pool.
*/
int
zpool_reguid(zpool_handle_t *zhp)
{
char msg[1024];
libzfs_handle_t *hdl = zhp->zpool_hdl;
zfs_cmd_t zc = { 0 };

(void) snprintf(msg, sizeof (msg),
dgettext(TEXT_DOMAIN, "cannot reguid '%s'"), zhp->zpool_name);

(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
if (zfs_ioctl(hdl, ZFS_IOC_POOL_REGUID, &zc) == 0)
return (0);

return (zpool_standard_error(hdl, errno, msg));
}

/*
* Convert from a devid string to a path.
*/
Expand Down
4 changes: 3 additions & 1 deletion usr/src/lib/libzfs/common/mapfile-vers
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
# CDDL HEADER END
#
# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright 2010 Nexenta Systems, Inc. All rights reserved.
# Copyright 2011 Nexenta Systems, Inc. All rights reserved.
# Copyright (c) 2011 by Delphix. All rights reserved.
#
# MAPFILE HEADER START
#
Expand Down Expand Up @@ -199,6 +200,7 @@ SYMBOL_VERSION SUNWprivate_1.1 {
zpool_prop_values;
zpool_read_label;
zpool_refresh_stats;
zpool_reguid;
zpool_scan;
zpool_search_import;
zpool_set_history_str;
Expand Down
19 changes: 18 additions & 1 deletion usr/src/man/man1m/zpool.1m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
.\" 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 or http://www.opensolaris.org/os/licensing.
.\" 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]
.TH ZPOOL 1M "Sep 21, 2009"
.\" Copyright 2011 Nexenta Systems, Inc. All rights reserved.
.TH ZPOOL 1M "Oct 25, 2011"
.SH NAME
zpool \- configures ZFS storage pools
.SH SYNOPSIS
Expand Down Expand Up @@ -95,6 +96,11 @@ zpool \- configures ZFS storage pools
\fBzpool online\fR \fIpool\fR \fIdevice\fR ...
.fi

.LP
.nf
\fBzpool reguid\fR \fIpool\fR
.fi

.LP
.nf
\fBzpool remove\fR \fIpool\fR \fIdevice\fR ...
Expand Down Expand Up @@ -1436,6 +1442,17 @@ become available to the pool.

.RE

.sp
.ne 2
.na
\fB\fBzpool reguid\fR \fIpool\fR
.ad
.sp .6
.RS 4n
Generates a new unique identifier for the pool. You must ensure that all devices in this pool are online and
healthy before performing this action.
.RE

.sp
.ne 2
.na
Expand Down
10 changes: 6 additions & 4 deletions usr/src/uts/common/fs/zfs/arc.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*/
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
* Copyright (c) 2011 by Delphix. All rights reserved.
*/

/*
Expand Down Expand Up @@ -1217,7 +1219,7 @@ arc_buf_alloc(spa_t *spa, int size, void *tag, arc_buf_contents_t type)
ASSERT(BUF_EMPTY(hdr));
hdr->b_size = size;
hdr->b_type = type;
hdr->b_spa = spa_guid(spa);
hdr->b_spa = spa_load_guid(spa);
hdr->b_state = arc_anon;
hdr->b_arc_access = 0;
buf = kmem_cache_alloc(buf_cache, KM_PUSHPAGE);
Expand Down Expand Up @@ -1919,7 +1921,7 @@ arc_flush(spa_t *spa)
uint64_t guid = 0;

if (spa)
guid = spa_guid(spa);
guid = spa_load_guid(spa);

while (list_head(&arc_mru->arcs_list[ARC_BUFC_DATA])) {
(void) arc_evict(arc_mru, guid, -1, FALSE, ARC_BUFC_DATA);
Expand Down Expand Up @@ -2676,7 +2678,7 @@ arc_read_nolock(zio_t *pio, spa_t *spa, const blkptr_t *bp,
arc_buf_t *buf;
kmutex_t *hash_lock;
zio_t *rzio;
uint64_t guid = spa_guid(spa);
uint64_t guid = spa_load_guid(spa);

top:
hdr = buf_hash_find(guid, BP_IDENTITY(bp), BP_PHYSICAL_BIRTH(bp),
Expand Down Expand Up @@ -4234,7 +4236,7 @@ l2arc_write_buffers(spa_t *spa, l2arc_dev_t *dev, uint64_t target_sz)
boolean_t have_lock, full;
l2arc_write_callback_t *cb;
zio_t *pio, *wzio;
uint64_t guid = spa_guid(spa);
uint64_t guid = spa_load_guid(spa);

ASSERT(dev->l2ad_vdev != NULL);

Expand Down
Loading

0 comments on commit e9103aa

Please sign in to comment.