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. |