View | Details | Raw Unified | Return to bug 204622 | Differences between
and this patch

Collapse All | Expand All

(-)cddl/contrib/opensolaris/cmd/zpool/zpool.8 (-1 / +28 lines)
Lines 119-124 Link Here
119
.Ar ...
119
.Ar ...
120
.Nm
120
.Nm
121
.Cm labelclear
121
.Cm labelclear
122
.Op Fl b | Fl e | Fl i Ar index
123
.Op Fl c
124
.Op Fl m
122
.Op Fl f
125
.Op Fl f
123
.Ar device
126
.Ar device
124
.Nm
127
.Nm
Lines 1341-1346 Link Here
1341
.It Xo
1344
.It Xo
1342
.Nm
1345
.Nm
1343
.Cm labelclear
1346
.Cm labelclear
1347
.Op Fl b | Fl e | Fl i Ar index
1348
.Op Fl c
1349
.Op Fl m
1344
.Op Fl f
1350
.Op Fl f
1345
.Ar device
1351
.Ar device
1346
.Xc
1352
.Xc
Lines 1351-1358 Link Here
1351
.Ar device .
1357
.Ar device .
1352
The
1358
The
1353
.Ar device
1359
.Ar device
1354
must not be part of an active pool configuration.
1360
must not be part of an active pool configuration. Options
1361
.Fl b ,
1362
.Fl e
1363
and
1364
.Fl i
1365
can be used for clearing specific labels. They are mutually exclusive and the
1366
last one will supersede others, if any.
1355
.Bl -tag -width indent
1367
.Bl -tag -width indent
1368
.It Fl b
1369
Only remove ZFS labels located at the beginning of
1370
.Ar device .
1371
.It Fl e
1372
Only remove ZFS labels located at the end of
1373
.Ar device .
1374
.It Fl i Ar index
1375
Remove a single label entry located at position
1376
.Ar index .
1377
.It Fl c
1378
Check label integrity before doing anything.
1379
.It Fl m
1380
Perform minimal operation needed to invalidate a label instead of blindly
1381
erasing every single byte. This reduces (but does not annihilate) the risks of
1382
overriding important on-disk data.
1356
.It Fl f
1383
.It Fl f
1357
Treat exported or foreign devices as inactive.
1384
Treat exported or foreign devices as inactive.
1358
.El
1385
.El
(-)cddl/contrib/opensolaris/cmd/zpool/zpool_main.c (-3 / +36 lines)
Lines 37-42 Link Here
37
#include <libgen.h>
37
#include <libgen.h>
38
#include <libintl.h>
38
#include <libintl.h>
39
#include <libuutil.h>
39
#include <libuutil.h>
40
#include <limits.h>
40
#include <locale.h>
41
#include <locale.h>
41
#include <stdio.h>
42
#include <stdio.h>
42
#include <stdlib.h>
43
#include <stdlib.h>
Lines 49-54 Link Here
49
#include <sys/time.h>
50
#include <sys/time.h>
50
#include <zfs_prop.h>
51
#include <zfs_prop.h>
51
#include <sys/fs/zfs.h>
52
#include <sys/fs/zfs.h>
53
#include <sys/vdev_impl.h>
52
#include <sys/stat.h>
54
#include <sys/stat.h>
53
55
54
#include <libzfs.h>
56
#include <libzfs.h>
Lines 235-241 Link Here
235
		return (gettext("\tiostat [-v] [-T d|u] [pool] ... [interval "
237
		return (gettext("\tiostat [-v] [-T d|u] [pool] ... [interval "
236
		    "[count]]\n"));
238
		    "[count]]\n"));
237
	case HELP_LABELCLEAR:
239
	case HELP_LABELCLEAR:
238
		return (gettext("\tlabelclear [-f] <vdev>\n"));
240
		return (gettext("\tlabelclear [-b | -e | -i index] [-c] [-m] [-f] "
241
		    "<vdev>\n"));
239
	case HELP_LIST:
242
	case HELP_LIST:
240
		return (gettext("\tlist [-Hpv] [-o property[,...]] "
243
		return (gettext("\tlist [-Hpv] [-o property[,...]] "
241
		    "[-T d|u] [pool] ... [interval [count]]\n"));
244
		    "[-T d|u] [pool] ... [interval [count]]\n"));
Lines 638-647 Link Here
638
	pool_state_t state;
641
	pool_state_t state;
639
	boolean_t inuse = B_FALSE;
642
	boolean_t inuse = B_FALSE;
640
	boolean_t force = B_FALSE;
643
	boolean_t force = B_FALSE;
644
	boolean_t check = B_FALSE;
645
	boolean_t cherry = B_FALSE;
646
	unsigned int start = 0, n = VDEV_LABELS;
647
	char *end = NULL;
648
	long long index = 0;
641
649
642
	/* check options */
650
	/* check options */
643
	while ((c = getopt(argc, argv, "f")) != -1) {
651
	while ((c = getopt(argc, argv, "bei:cmf")) != -1) {
644
		switch (c) {
652
		switch (c) {
653
		case 'b':
654
			start = 0;
655
			n = VDEV_LABELS / 2;
656
			break;
657
		case 'e':
658
			start = VDEV_LABELS / 2;
659
			n = VDEV_LABELS / 2;
660
			break;
661
		case 'i':
662
                	index = strtoll(optarg, &end, 10);
663
                	if((end == optarg) || (*end != '\0') ||
664
                	    (index < 0) || (index >= VDEV_LABELS)) {
665
				(void) fprintf(stderr, 
666
				    gettext("Invalid index value provided\n"));
667
				return (B_FALSE);
668
			}
669
			start = (unsigned int)index;
670
			n = 1;
671
			break;
672
		case 'c':
673
			check = B_TRUE;
674
			break;
675
		case 'm':
676
			cherry = B_TRUE;
677
			break;
645
		case 'f':
678
		case 'f':
646
			force = B_TRUE;
679
			force = B_TRUE;
647
			break;
680
			break;
Lines 729-735 Link Here
729
	}
762
	}
730
763
731
wipe_label:
764
wipe_label:
732
	if (zpool_clear_label(fd) != 0) {
765
	if (zpool_clear_n_labels(fd, start, n, check, cherry) != 0) {
733
		(void) fprintf(stderr,
766
		(void) fprintf(stderr,
734
		    gettext("Label clear failed on vdev %s\n"), vdev);
767
		    gettext("Label clear failed on vdev %s\n"), vdev);
735
		ret = 1;
768
		ret = 1;
(-)cddl/contrib/opensolaris/lib/libzfs/common/libzfs.h (+1 lines)
Lines 768-773 Link Here
768
 * Label manipulation.
768
 * Label manipulation.
769
 */
769
 */
770
extern int zpool_read_label(int, nvlist_t **);
770
extern int zpool_read_label(int, nvlist_t **);
771
extern int zpool_clear_n_labels(int, unsigned int, unsigned int, boolean_t, boolean_t);
771
extern int zpool_clear_label(int);
772
extern int zpool_clear_label(int);
772
773
773
/* is this zvol valid for use as a dump device? */
774
/* is this zvol valid for use as a dump device? */
(-)cddl/contrib/opensolaris/lib/libzfs/common/libzfs_import.c (-13 / +45 lines)
Lines 1099-1136 Link Here
1099
}
1099
}
1100
1100
1101
/*
1101
/*
1102
 * Given a file descriptor, clear (zero) the label information.  This function
1102
 * Given a file descriptor, a starting label and a number of labels to clear,
1103
 * is used in the appliance stack as part of the ZFS sysevent module and
1103
 * clear (zero) the label information.
1104
 * to implement the "zpool labelclear" command.
1105
 */
1104
 */
1106
int
1105
int
1107
zpool_clear_label(int fd)
1106
zpool_clear_n_labels(int fd, unsigned int start, unsigned int n,
1107
    boolean_t check, boolean_t cherry)
1108
{
1108
{
1109
	struct stat64 statbuf;
1109
	struct stat64 statbuf;
1110
	int l;
1110
	unsigned int l, end;
1111
	vdev_label_t *label;
1111
	vdev_label_t label;
1112
	uint64_t size;
1112
	uint64_t size;
1113
1113
1114
	char *buf = label.vl_vdev_phys.vp_nvlist;
1115
	size_t buflen = sizeof (label.vl_vdev_phys.vp_nvlist);
1116
1114
	if (fstat64(fd, &statbuf) == -1)
1117
	if (fstat64(fd, &statbuf) == -1)
1115
		return (0);
1118
		return (0);
1116
	size = P2ALIGN_TYPED(statbuf.st_size, sizeof (vdev_label_t), uint64_t);
1119
	size = P2ALIGN_TYPED(statbuf.st_size, sizeof (vdev_label_t), uint64_t);
1117
1120
1118
	if ((label = calloc(sizeof (vdev_label_t), 1)) == NULL)
1121
	end = start + n;
1122
	if (end > VDEV_LABELS)
1119
		return (-1);
1123
		return (-1);
1120
1124
1121
	for (l = 0; l < VDEV_LABELS; l++) {
1125
	for (l = start; l < end; l++) {
1122
		if (pwrite64(fd, label, sizeof (vdev_label_t),
1126
		if ((check == B_TRUE) || (cherry == B_TRUE)) {
1123
		    label_offset(size, l)) != sizeof (vdev_label_t)) {
1127
                	if (pread64(fd, &label, sizeof (vdev_label_t),
1124
			free(label);
1128
                	    label_offset(size, l)) != sizeof (vdev_label_t))
1129
				return (-1);
1130
1131
			if (check == B_TRUE) {
1132
				nvlist_t *config = NULL;
1133
				if (nvlist_unpack(buf, buflen, &config, 0) != 0)
1134
					return (-1);
1135
				nvlist_free(config);
1136
			}
1137
		}
1138
1139
		if (cherry == B_TRUE) {
1140
			if (nvlist_invalidate(buf) != 0)
1141
				return (-1);
1142
		} else {
1143
			memset(&label, 0, sizeof (vdev_label_t));
1144
		}
1145
1146
		if (pwrite64(fd, &label, sizeof (vdev_label_t),
1147
		    label_offset(size, l)) != sizeof (vdev_label_t))
1125
			return (-1);
1148
			return (-1);
1126
		}
1127
	}
1149
	}
1128
1150
1129
	free(label);
1130
	return (0);
1151
	return (0);
1131
}
1152
}
1132
1153
1133
/*
1154
/*
1155
 * Given a file descriptor, clear (zero) the label information.  This function
1156
 * is used in the appliance stack as part of the ZFS sysevent module and
1157
 * to implement the "zpool labelclear" command.
1158
 */
1159
int
1160
zpool_clear_label(int fd)
1161
{
1162
	return (zpool_clear_n_labels(fd, 0, VDEV_LABELS, B_FALSE, B_FALSE));
1163
}
1164
1165
/*
1134
 * Given a list of directories to search, find all pools stored on disk.  This
1166
 * Given a list of directories to search, find all pools stored on disk.  This
1135
 * includes partial pools which are not available to import.  If no args are
1167
 * includes partial pools which are not available to import.  If no args are
1136
 * given (argc is 0), then the default directory (/dev/dsk) is searched.
1168
 * given (argc is 0), then the default directory (/dev/dsk) is searched.
(-)sys/cddl/contrib/opensolaris/common/nvpair/opensolaris_nvpair.c (+12 lines)
Lines 2336-2341 Link Here
2336
}
2336
}
2337
2337
2338
int
2338
int
2339
nvlist_invalidate(char *buf)
2340
{
2341
	if (buf == NULL)
2342
		return (EINVAL);
2343
2344
	nvs_header_t *nvh = (void *)buf;
2345
	nvh->nvh_encoding = NV_ENCODE_NONE;
2346
2347
	return (0);
2348
}
2349
2350
int
2339
nvlist_size(nvlist_t *nvl, size_t *size, int encoding)
2351
nvlist_size(nvlist_t *nvl, size_t *size, int encoding)
2340
{
2352
{
2341
	return (nvlist_common(nvl, NULL, size, encoding, NVS_OP_GETSIZE));
2353
	return (nvlist_common(nvl, NULL, size, encoding, NVS_OP_GETSIZE));
(-)sys/cddl/contrib/opensolaris/uts/common/sys/nvpair.h (+2 lines)
Lines 97-102 Link Here
97
#define	NV_VERSION	0
97
#define	NV_VERSION	0
98
98
99
/* nvlist pack encoding */
99
/* nvlist pack encoding */
100
#define	NV_ENCODE_NONE		(-1)
100
#define	NV_ENCODE_NATIVE	0
101
#define	NV_ENCODE_NATIVE	0
101
#define	NV_ENCODE_XDR		1
102
#define	NV_ENCODE_XDR		1
102
103
Lines 152-157 Link Here
152
/* list management */
153
/* list management */
153
int nvlist_alloc(nvlist_t **, uint_t, int);
154
int nvlist_alloc(nvlist_t **, uint_t, int);
154
void nvlist_free(nvlist_t *);
155
void nvlist_free(nvlist_t *);
156
int nvlist_invalidate(char *);
155
int nvlist_size(nvlist_t *, size_t *, int);
157
int nvlist_size(nvlist_t *, size_t *, int);
156
int nvlist_pack(nvlist_t *, char **, size_t *, int, int);
158
int nvlist_pack(nvlist_t *, char **, size_t *, int, int);
157
int nvlist_unpack(char *, size_t, nvlist_t **, int);
159
int nvlist_unpack(char *, size_t, nvlist_t **, int);

Return to bug 204622