Skip to content

Commit d96eb2b

Browse files
Dan McDonaldbehlendorf
authored andcommitted
Illumos #1693: persistent 'comment' field for a zpool
Reviewed by: George Wilson <gwilson@zfsmail.com> Reviewed by: Eric Schrock <eric.schrock@delphix.com> Approved by: Richard Lowe <richlowe@richlowe.net> References: https://www.illumos.org/issues/1693 Ported by: Martin Matuska <martin@matuska.org> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes #678
1 parent ee5fd0b commit d96eb2b

File tree

10 files changed

+143
-28
lines changed

10 files changed

+143
-28
lines changed

cmd/zpool/zpool_main.c

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,7 @@ show_import(nvlist_t *config)
13431343
const char *health;
13441344
uint_t vsc;
13451345
int namewidth;
1346+
char *comment;
13461347

13471348
verify(nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME,
13481349
&name) == 0);
@@ -1359,9 +1360,9 @@ show_import(nvlist_t *config)
13591360

13601361
reason = zpool_import_status(config, &msgid);
13611362

1362-
(void) printf(gettext(" pool: %s\n"), name);
1363-
(void) printf(gettext(" id: %llu\n"), (u_longlong_t)guid);
1364-
(void) printf(gettext(" state: %s"), health);
1363+
(void) printf(gettext(" pool: %s\n"), name);
1364+
(void) printf(gettext(" id: %llu\n"), (u_longlong_t)guid);
1365+
(void) printf(gettext(" state: %s"), health);
13651366
if (pool_state == POOL_STATE_DESTROYED)
13661367
(void) printf(gettext(" (DESTROYED)"));
13671368
(void) printf("\n");
@@ -1370,58 +1371,59 @@ show_import(nvlist_t *config)
13701371
case ZPOOL_STATUS_MISSING_DEV_R:
13711372
case ZPOOL_STATUS_MISSING_DEV_NR:
13721373
case ZPOOL_STATUS_BAD_GUID_SUM:
1373-
(void) printf(gettext("status: One or more devices are missing "
1374-
"from the system.\n"));
1374+
(void) printf(gettext(" status: One or more devices are "
1375+
"missing from the system.\n"));
13751376
break;
13761377

13771378
case ZPOOL_STATUS_CORRUPT_LABEL_R:
13781379
case ZPOOL_STATUS_CORRUPT_LABEL_NR:
1379-
(void) printf(gettext("status: One or more devices contains "
1380+
(void) printf(gettext(" status: One or more devices contains "
13801381
"corrupted data.\n"));
13811382
break;
13821383

13831384
case ZPOOL_STATUS_CORRUPT_DATA:
1384-
(void) printf(gettext("status: The pool data is corrupted.\n"));
1385+
(void) printf(
1386+
gettext(" status: The pool data is corrupted.\n"));
13851387
break;
13861388

13871389
case ZPOOL_STATUS_OFFLINE_DEV:
1388-
(void) printf(gettext("status: One or more devices "
1390+
(void) printf(gettext(" status: One or more devices "
13891391
"are offlined.\n"));
13901392
break;
13911393

13921394
case ZPOOL_STATUS_CORRUPT_POOL:
1393-
(void) printf(gettext("status: The pool metadata is "
1395+
(void) printf(gettext(" status: The pool metadata is "
13941396
"corrupted.\n"));
13951397
break;
13961398

13971399
case ZPOOL_STATUS_VERSION_OLDER:
1398-
(void) printf(gettext("status: The pool is formatted using an "
1400+
(void) printf(gettext(" status: The pool is formatted using an "
13991401
"older on-disk version.\n"));
14001402
break;
14011403

14021404
case ZPOOL_STATUS_VERSION_NEWER:
1403-
(void) printf(gettext("status: The pool is formatted using an "
1405+
(void) printf(gettext(" status: The pool is formatted using an "
14041406
"incompatible version.\n"));
14051407
break;
14061408

14071409
case ZPOOL_STATUS_HOSTID_MISMATCH:
1408-
(void) printf(gettext("status: The pool was last accessed by "
1410+
(void) printf(gettext(" status: The pool was last accessed by "
14091411
"another system.\n"));
14101412
break;
14111413

14121414
case ZPOOL_STATUS_FAULTED_DEV_R:
14131415
case ZPOOL_STATUS_FAULTED_DEV_NR:
1414-
(void) printf(gettext("status: One or more devices are "
1416+
(void) printf(gettext(" status: One or more devices are "
14151417
"faulted.\n"));
14161418
break;
14171419

14181420
case ZPOOL_STATUS_BAD_LOG:
1419-
(void) printf(gettext("status: An intent log record cannot be "
1421+
(void) printf(gettext(" status: An intent log record cannot be "
14201422
"read.\n"));
14211423
break;
14221424

14231425
case ZPOOL_STATUS_RESILVERING:
1424-
(void) printf(gettext("status: One or more devices were being "
1426+
(void) printf(gettext(" status: One or more devices were being "
14251427
"resilvered.\n"));
14261428
break;
14271429

@@ -1437,43 +1439,47 @@ show_import(nvlist_t *config)
14371439
*/
14381440
if (vs->vs_state == VDEV_STATE_HEALTHY) {
14391441
if (reason == ZPOOL_STATUS_VERSION_OLDER)
1440-
(void) printf(gettext("action: The pool can be "
1442+
(void) printf(gettext(" action: The pool can be "
14411443
"imported using its name or numeric identifier, "
14421444
"though\n\tsome features will not be available "
14431445
"without an explicit 'zpool upgrade'.\n"));
14441446
else if (reason == ZPOOL_STATUS_HOSTID_MISMATCH)
1445-
(void) printf(gettext("action: The pool can be "
1447+
(void) printf(gettext(" action: The pool can be "
14461448
"imported using its name or numeric "
14471449
"identifier and\n\tthe '-f' flag.\n"));
14481450
else
1449-
(void) printf(gettext("action: The pool can be "
1451+
(void) printf(gettext(" action: The pool can be "
14501452
"imported using its name or numeric "
14511453
"identifier.\n"));
14521454
} else if (vs->vs_state == VDEV_STATE_DEGRADED) {
1453-
(void) printf(gettext("action: The pool can be imported "
1455+
(void) printf(gettext(" action: The pool can be imported "
14541456
"despite missing or damaged devices. The\n\tfault "
14551457
"tolerance of the pool may be compromised if imported.\n"));
14561458
} else {
14571459
switch (reason) {
14581460
case ZPOOL_STATUS_VERSION_NEWER:
1459-
(void) printf(gettext("action: The pool cannot be "
1461+
(void) printf(gettext(" action: The pool cannot be "
14601462
"imported. Access the pool on a system running "
14611463
"newer\n\tsoftware, or recreate the pool from "
14621464
"backup.\n"));
14631465
break;
14641466
case ZPOOL_STATUS_MISSING_DEV_R:
14651467
case ZPOOL_STATUS_MISSING_DEV_NR:
14661468
case ZPOOL_STATUS_BAD_GUID_SUM:
1467-
(void) printf(gettext("action: The pool cannot be "
1469+
(void) printf(gettext(" action: The pool cannot be "
14681470
"imported. Attach the missing\n\tdevices and try "
14691471
"again.\n"));
14701472
break;
14711473
default:
1472-
(void) printf(gettext("action: The pool cannot be "
1474+
(void) printf(gettext(" action: The pool cannot be "
14731475
"imported due to damaged devices or data.\n"));
14741476
}
14751477
}
14761478

1479+
/* Print the comment attached to the pool. */
1480+
if (nvlist_lookup_string(config, ZPOOL_CONFIG_COMMENT, &comment) == 0)
1481+
(void) printf(gettext("comment: %s\n"), comment);
1482+
14771483
/*
14781484
* If the state is "closed" or "can't open", and the aux state
14791485
* is "corrupt data":
@@ -1494,7 +1500,7 @@ show_import(nvlist_t *config)
14941500
(void) printf(gettext(" see: http://zfsonlinux.org/msg/%s\n"),
14951501
msgid);
14961502

1497-
(void) printf(gettext("config:\n\n"));
1503+
(void) printf(gettext(" config:\n\n"));
14981504

14991505
namewidth = max_width(NULL, nvroot, 0, 0);
15001506
if (namewidth < 10)

include/sys/fs/zfs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,13 @@ typedef enum {
167167
ZPOOL_PROP_ALLOCATED,
168168
ZPOOL_PROP_READONLY,
169169
ZPOOL_PROP_ASHIFT,
170+
ZPOOL_PROP_COMMENT,
170171
ZPOOL_NUM_PROPS
171172
} zpool_prop_t;
172173

174+
/* Small enough to not hog a whole line of printout in zpool(1M). */
175+
#define ZPROP_MAX_COMMENT 32
176+
173177
#define ZPROP_CONT -2
174178
#define ZPROP_INVAL -1
175179

@@ -500,6 +504,7 @@ typedef struct zpool_rewind_policy {
500504
#define ZPOOL_CONFIG_SPLIT_LIST "guid_list"
501505
#define ZPOOL_CONFIG_REMOVING "removing"
502506
#define ZPOOL_CONFIG_RESILVERING "resilvering"
507+
#define ZPOOL_CONFIG_COMMENT "comment"
503508
#define ZPOOL_CONFIG_SUSPENDED "suspended" /* not stored on disk */
504509
#define ZPOOL_CONFIG_TIMESTAMP "timestamp" /* not stored on disk */
505510
#define ZPOOL_CONFIG_BOOTFS "bootfs" /* not stored on disk */

include/sys/spa_impl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ struct spa {
112112
* Fields protected by spa_namespace_lock.
113113
*/
114114
char spa_name[MAXNAMELEN]; /* pool name */
115+
char *spa_comment; /* comment */
115116
avl_node_t spa_avl; /* node in spa_namespace_avl */
116117
nvlist_t *spa_config; /* last synced config */
117118
nvlist_t *spa_config_syncing; /* currently syncing config */

include/sys/zfs_context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include <sys/zfs_debug.h>
6161
#include <sys/fm/fs/zfs.h>
6262
#include <sys/sunddi.h>
63+
#include <sys/ctype.h>
6364
#include <linux/dcache_compat.h>
6465

6566
#else /* _KERNEL */
@@ -92,6 +93,7 @@
9293
#include <atomic.h>
9394
#include <dirent.h>
9495
#include <time.h>
96+
#include <ctype.h>
9597
#include <sys/note.h>
9698
#include <sys/types.h>
9799
#include <sys/cred.h>

lib/libzfs/libzfs_import.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
*/
2121
/*
2222
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23+
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24+
* Copyright (c) 2011 by Delphix. All rights reserved.
2325
*/
2426

2527
/*
@@ -441,7 +443,7 @@ get_configs(libzfs_handle_t *hdl, pool_list_t *pl, boolean_t active_ok)
441443
uint_t i, nspares, nl2cache;
442444
boolean_t config_seen;
443445
uint64_t best_txg;
444-
char *name, *hostname;
446+
char *name, *hostname, *comment;
445447
uint64_t version, guid;
446448
uint_t children = 0;
447449
nvlist_t **child = NULL;
@@ -530,6 +532,7 @@ get_configs(libzfs_handle_t *hdl, pool_list_t *pl, boolean_t active_ok)
530532
* version
531533
* pool guid
532534
* name
535+
* comment (if available)
533536
* pool state
534537
* hostid (if available)
535538
* hostname (if available)
@@ -551,11 +554,24 @@ get_configs(libzfs_handle_t *hdl, pool_list_t *pl, boolean_t active_ok)
551554
if (nvlist_add_string(config,
552555
ZPOOL_CONFIG_POOL_NAME, name) != 0)
553556
goto nomem;
557+
558+
/*
559+
* COMMENT is optional, don't bail if it's not
560+
* there, instead, set it to NULL.
561+
*/
562+
if (nvlist_lookup_string(tmp,
563+
ZPOOL_CONFIG_COMMENT, &comment) != 0)
564+
comment = NULL;
565+
else if (nvlist_add_string(config,
566+
ZPOOL_CONFIG_COMMENT, comment) != 0)
567+
goto nomem;
568+
554569
verify(nvlist_lookup_uint64(tmp,
555570
ZPOOL_CONFIG_POOL_STATE, &state) == 0);
556571
if (nvlist_add_uint64(config,
557572
ZPOOL_CONFIG_POOL_STATE, state) != 0)
558573
goto nomem;
574+
559575
hostid = 0;
560576
if (nvlist_lookup_uint64(tmp,
561577
ZPOOL_CONFIG_HOSTID, &hostid) == 0) {

lib/libzfs/libzfs_pool.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ zpool_get_prop(zpool_handle_t *zhp, zpool_prop_t prop, char *buf, size_t len,
235235

236236
case ZPOOL_PROP_ALTROOT:
237237
case ZPOOL_PROP_CACHEFILE:
238+
case ZPOOL_PROP_COMMENT:
238239
if (zhp->zpool_props != NULL ||
239240
zpool_get_all_props(zhp) == 0) {
240241
(void) strlcpy(buf,
@@ -385,7 +386,7 @@ zpool_valid_proplist(libzfs_handle_t *hdl, const char *poolname,
385386
zpool_prop_t prop;
386387
char *strval;
387388
uint64_t intval;
388-
char *slash;
389+
char *slash, *check;
389390
struct stat64 statbuf;
390391
zpool_handle_t *zhp;
391392
nvlist_t *nvroot;
@@ -566,6 +567,26 @@ zpool_valid_proplist(libzfs_handle_t *hdl, const char *poolname,
566567
*slash = '/';
567568
break;
568569

570+
case ZPOOL_PROP_COMMENT:
571+
for (check = strval; *check != '\0'; check++) {
572+
if (!isprint(*check)) {
573+
zfs_error_aux(hdl,
574+
dgettext(TEXT_DOMAIN,
575+
"comment may only have printable "
576+
"characters"));
577+
(void) zfs_error(hdl, EZFS_BADPROP,
578+
errbuf);
579+
goto error;
580+
}
581+
}
582+
if (strlen(strval) > ZPROP_MAX_COMMENT) {
583+
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
584+
"comment must not exceed %d characters"),
585+
ZPROP_MAX_COMMENT);
586+
(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
587+
goto error;
588+
}
589+
break;
569590
case ZPOOL_PROP_READONLY:
570591
if (!flags.import) {
571592
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,

man/man8/zpool.8

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'\" te
22
.\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
3+
.\" Copyright 2011 Nexenta Systems, Inc. All rights reserved.
34
.\" 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.
45
.\" 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
56
.\" fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6-
.\" Copyright 2011 Nexenta Systems, Inc. All rights reserved.
7-
.TH zpool 8 "10 July 2012" "ZFS pool 28, filesystem 5" "System Administration Commands"
7+
.TH zpool 8 "2 August 2012" "ZFS pool 28, filesystem 5" "System Administration Commands"
88
.SH NAME
99
zpool \- configures ZFS storage pools
1010
.SH SYNOPSIS
@@ -461,6 +461,17 @@ Amount of storage available within the pool. This property can also be referred
461461
Percentage of pool space used. This property can also be referred to by its shortened column name, "cap".
462462
.RE
463463

464+
.sp
465+
.ne 2
466+
.mk
467+
.na
468+
\fB\fBcomment\fR\fR
469+
.ad
470+
.RS 20n
471+
.rt
472+
A text string consisting of printable ASCII characters that will be stored such that it is available even if the pool becomes faulted. An administrator can provide additional information about a pool using this property.
473+
.RE
474+
464475
.sp
465476
.ne 2
466477
.mk

module/zcommon/zpool_prop.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
*/
2121
/*
2222
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
23+
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24+
* Copyright (c) 2011 by Delphix. All rights reserved.
2325
*/
2426

2527
#include <sys/zio.h>
@@ -69,6 +71,8 @@ zpool_prop_init(void)
6971
ZFS_TYPE_POOL, "<filesystem>", "BOOTFS");
7072
zprop_register_string(ZPOOL_PROP_CACHEFILE, "cachefile", NULL,
7173
PROP_DEFAULT, ZFS_TYPE_POOL, "<file> | none", "CACHEFILE");
74+
zprop_register_string(ZPOOL_PROP_COMMENT, "comment", NULL,
75+
PROP_DEFAULT, ZFS_TYPE_POOL, "<comment-string>", "COMMENT");
7276

7377
/* readonly number properties */
7478
zprop_register_number(ZPOOL_PROP_SIZE, "size", 0, PROP_READONLY,

0 commit comments

Comments
 (0)