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 1350-1355 Link Here
1350
.It Xo
1353
.It Xo
1351
.Nm
1354
.Nm
1352
.Cm labelclear
1355
.Cm labelclear
1356
.Op Fl b | Fl e | Fl i Ar index
1357
.Op Fl c
1358
.Op Fl m
1353
.Op Fl f
1359
.Op Fl f
1354
.Ar device
1360
.Ar device
1355
.Xc
1361
.Xc
Lines 1360-1367 Link Here
1360
.Ar device .
1366
.Ar device .
1361
The
1367
The
1362
.Ar device
1368
.Ar device
1363
must not be part of an active pool configuration.
1369
must not be part of an active pool configuration. Options
1370
.Fl b ,
1371
.Fl e
1372
and
1373
.Fl i
1374
can be used for clearing specific labels. They are mutually exclusive and the
1375
last one will supersede others, if any.
1364
.Bl -tag -width indent
1376
.Bl -tag -width indent
1377
.It Fl b
1378
Only remove ZFS labels located at the beginning of
1379
.Ar device .
1380
.It Fl e
1381
Only remove ZFS labels located at the end of
1382
.Ar device .
1383
.It Fl i Ar index
1384
Remove a single label entry located at position
1385
.Ar index .
1386
.It Fl c
1387
Check label integrity before doing anything.
1388
.It Fl m
1389
Perform minimal operation needed to invalidate a label instead of blindly
1390
erasing every single byte. This reduces (but does not annihilate) the risks of
1391
overriding important on-disk data.
1365
.It Fl f
1392
.It Fl f
1366
Treat exported or foreign devices as inactive.
1393
Treat exported or foreign devices as inactive.
1367
.El
1394
.El
(-)cddl/contrib/opensolaris/cmd/zpool/zpool_main.c (-5 / +42 lines)
Lines 38-43 Link Here
38
#include <libgen.h>
38
#include <libgen.h>
39
#include <libintl.h>
39
#include <libintl.h>
40
#include <libuutil.h>
40
#include <libuutil.h>
41
#include <limits.h>
41
#include <locale.h>
42
#include <locale.h>
42
#include <stdio.h>
43
#include <stdio.h>
43
#include <stdlib.h>
44
#include <stdlib.h>
Lines 50-55 Link Here
50
#include <sys/time.h>
51
#include <sys/time.h>
51
#include <zfs_prop.h>
52
#include <zfs_prop.h>
52
#include <sys/fs/zfs.h>
53
#include <sys/fs/zfs.h>
54
#include <sys/vdev_impl.h>
53
#include <sys/stat.h>
55
#include <sys/stat.h>
54
56
55
#include <libzfs.h>
57
#include <libzfs.h>
Lines 236-242 Link Here
236
		return (gettext("\tiostat [-v] [-T d|u] [pool] ... [interval "
238
		return (gettext("\tiostat [-v] [-T d|u] [pool] ... [interval "
237
		    "[count]]\n"));
239
		    "[count]]\n"));
238
	case HELP_LABELCLEAR:
240
	case HELP_LABELCLEAR:
239
		return (gettext("\tlabelclear [-f] <vdev>\n"));
241
		return (gettext("\tlabelclear [-b | -e | -i index] [-c] [-m] "
242
		    "[-f] <vdev>\n"));
240
	case HELP_LIST:
243
	case HELP_LIST:
241
		return (gettext("\tlist [-Hpv] [-o property[,...]] "
244
		return (gettext("\tlist [-Hpv] [-o property[,...]] "
242
		    "[-T d|u] [pool] ... [interval [count]]\n"));
245
		    "[-T d|u] [pool] ... [interval [count]]\n"));
Lines 645-654 Link Here
645
	pool_state_t state;
648
	pool_state_t state;
646
	boolean_t inuse = B_FALSE;
649
	boolean_t inuse = B_FALSE;
647
	boolean_t force = B_FALSE;
650
	boolean_t force = B_FALSE;
651
	boolean_t check = B_FALSE;
652
	boolean_t cherry = B_FALSE;
653
	unsigned int start = 0, n = VDEV_LABELS;
654
	char *end = NULL;
655
	long long index = 0;
648
656
649
	/* check options */
657
	/* check options */
650
	while ((c = getopt(argc, argv, "f")) != -1) {
658
	while ((c = getopt(argc, argv, "bei:cmf")) != -1) {
651
		switch (c) {
659
		switch (c) {
660
		case 'b':
661
			start = 0;
662
			n = VDEV_LABELS / 2;
663
			break;
664
		case 'e':
665
			start = VDEV_LABELS / 2;
666
			n = VDEV_LABELS / 2;
667
			break;
668
		case 'i':
669
			index = strtoll(optarg, &end, 10);
670
			if((end == optarg) || (*end != '\0') ||
671
			    (index < 0) || (index >= VDEV_LABELS)) {
672
				(void) fprintf(stderr, 
673
				    gettext("Invalid index value provided\n"));
674
				return (1);
675
			}
676
			start = (unsigned int)index;
677
			n = 1;
678
			break;
679
		case 'c':
680
			check = B_TRUE;
681
			break;
682
		case 'm':
683
			cherry = B_TRUE;
684
			break;
652
		case 'f':
685
		case 'f':
653
			force = B_TRUE;
686
			force = B_TRUE;
654
			break;
687
			break;
Lines 705-712 Link Here
705
	}
738
	}
706
739
707
	if (zpool_read_label(fd, &config) != 0 || config == NULL) {
740
	if (zpool_read_label(fd, &config) != 0 || config == NULL) {
708
		(void) fprintf(stderr,
741
		if (force)
709
		    gettext("failed to read label from %s\n"), vdev);
742
			goto wipe_label;
743
		(void) fprintf(stderr, gettext(
744
		    "use '-f' to override the following error:\n"
745
		    "failed to read label from \"%s\"\n"),
746
		     vdev);
710
		return (1);
747
		return (1);
711
	}
748
	}
712
	nvlist_free(config);
749
	nvlist_free(config);
Lines 759-765 Link Here
759
	}
796
	}
760
797
761
wipe_label:
798
wipe_label:
762
	ret = zpool_clear_label(fd);
799
	ret = zpool_clear_n_labels(fd, start, n, check, cherry);
763
	if (ret != 0) {
800
	if (ret != 0) {
764
		(void) fprintf(stderr,
801
		(void) fprintf(stderr,
765
		    gettext("failed to clear label for %s\n"), vdev);
802
		    gettext("failed to clear label for %s\n"), vdev);
(-)cddl/contrib/opensolaris/lib/libzfs/common/libzfs.h (+1 lines)
Lines 769-774 Link Here
769
 * Label manipulation.
769
 * Label manipulation.
770
 */
770
 */
771
extern int zpool_read_label(int, nvlist_t **);
771
extern int zpool_read_label(int, nvlist_t **);
772
extern int zpool_clear_n_labels(int, unsigned int, unsigned int, boolean_t, boolean_t);
772
extern int zpool_clear_label(int);
773
extern int zpool_clear_label(int);
773
774
774
/* is this zvol valid for use as a dump device? */
775
/* is this zvol valid for use as a dump device? */
(-)cddl/contrib/opensolaris/lib/libzfs/common/libzfs_import.c (-11 / +43 lines)
Lines 1099-1134 Link Here
1099
}
1099
}
1100
1100
1101
/*
1101
/*
1102
 * Given a file descriptor, clear (zero) the label information.
1102
 * Given a file descriptor, a starting label and a number of labels to clear,
1103
 * clear (zero) the label information.
1103
 */
1104
 */
1104
int
1105
int
1105
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)
1106
{
1108
{
1107
	struct stat64 statbuf;
1109
	struct stat64 statbuf;
1108
	int l;
1110
	unsigned int l, end;
1109
	vdev_label_t *label;
1111
	vdev_label_t label;
1110
	uint64_t size;
1112
	uint64_t size;
1111
1113
1114
	char *buf = label.vl_vdev_phys.vp_nvlist;
1115
	size_t buflen = sizeof (label.vl_vdev_phys.vp_nvlist);
1116
1112
	if (fstat64(fd, &statbuf) == -1)
1117
	if (fstat64(fd, &statbuf) == -1)
1113
		return (0);
1118
		return (0);
1114
	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);
1115
1120
1116
	if ((label = calloc(sizeof (vdev_label_t), 1)) == NULL)
1121
	end = start + n;
1122
	if (end > VDEV_LABELS)
1117
		return (-1);
1123
		return (-1);
1118
1124
1119
	for (l = 0; l < VDEV_LABELS; l++) {
1125
	for (l = start; l < end; l++) {
1120
		if (pwrite64(fd, label, sizeof (vdev_label_t),
1126
		if ((check == B_TRUE) || (cherry == B_TRUE)) {
1121
		    label_offset(size, l)) != sizeof (vdev_label_t)) {
1127
			if (pread64(fd, &label, sizeof (vdev_label_t),
1122
			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))
1123
			return (-1);
1148
			return (-1);
1124
		}
1125
	}
1149
	}
1126
1150
1127
	free(label);
1128
	return (0);
1151
	return (0);
1129
}
1152
}
1130
1153
1131
/*
1154
/*
1155
 * Given a file descriptor, clear (zero) the label information.
1156
 */
1157
int
1158
zpool_clear_label(int fd)
1159
{
1160
	return (zpool_clear_n_labels(fd, 0, VDEV_LABELS, B_FALSE, B_FALSE));
1161
}
1162
1163
/*
1132
 * Given a list of directories to search, find all pools stored on disk.  This
1164
 * Given a list of directories to search, find all pools stored on disk.  This
1133
 * includes partial pools which are not available to import.  If no args are
1165
 * includes partial pools which are not available to import.  If no args are
1134
 * given (argc is 0), then the default directory (/dev/dsk) is searched.
1166
 * given (argc is 0), then the default directory (/dev/dsk) is searched.
(-)sys/cddl/contrib/opensolaris/common/nvpair/opensolaris_nvpair.c (+12 lines)
Lines 2335-2340 Link Here
2335
}
2335
}
2336
2336
2337
int
2337
int
2338
nvlist_invalidate(char *buf)
2339
{
2340
	if (buf == NULL)
2341
		return (EINVAL);
2342
2343
	nvs_header_t *nvh = (void *)buf;
2344
	nvh->nvh_encoding = NV_ENCODE_INVALID;
2345
2346
	return (0);
2347
}
2348
2349
int
2338
nvlist_size(nvlist_t *nvl, size_t *size, int encoding)
2350
nvlist_size(nvlist_t *nvl, size_t *size, int encoding)
2339
{
2351
{
2340
	return (nvlist_common(nvl, NULL, size, encoding, NVS_OP_GETSIZE));
2352
	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_INVALID	(-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