Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reinstate the old zpool read label logic as a fallback. #12040

Merged
merged 1 commit into from
May 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 101 additions & 3 deletions lib/libzutil/zutil_import.c
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,83 @@ label_offset(uint64_t size, int l)
0 : size - VDEV_LABELS * sizeof (vdev_label_t)));
}

/*
* The same description applies as to zpool_read_label below,
* except here we do it without aio, presumably because an aio call
* errored out in a way we think not using it could circumvent.
*/
static int
zpool_read_label_slow(int fd, nvlist_t **config, int *num_labels)
{
struct stat64 statbuf;
int l, count = 0;
vdev_phys_t *label;
nvlist_t *expected_config = NULL;
uint64_t expected_guid = 0, size;
int error;

*config = NULL;

if (fstat64_blk(fd, &statbuf) == -1)
return (0);
size = P2ALIGN_TYPED(statbuf.st_size, sizeof (vdev_label_t), uint64_t);

error = posix_memalign((void **)&label, PAGESIZE, sizeof (*label));
if (error)
return (-1);

for (l = 0; l < VDEV_LABELS; l++) {
uint64_t state, guid, txg;
off_t offset = label_offset(size, l) + VDEV_SKIP_SIZE;

if (pread64(fd, label, sizeof (vdev_phys_t),
offset) != sizeof (vdev_phys_t))
continue;

if (nvlist_unpack(label->vp_nvlist,
sizeof (label->vp_nvlist), config, 0) != 0)
continue;

if (nvlist_lookup_uint64(*config, ZPOOL_CONFIG_GUID,
&guid) != 0 || guid == 0) {
nvlist_free(*config);
continue;
}

if (nvlist_lookup_uint64(*config, ZPOOL_CONFIG_POOL_STATE,
&state) != 0 || state > POOL_STATE_L2CACHE) {
nvlist_free(*config);
continue;
}

if (state != POOL_STATE_SPARE && state != POOL_STATE_L2CACHE &&
(nvlist_lookup_uint64(*config, ZPOOL_CONFIG_POOL_TXG,
&txg) != 0 || txg == 0)) {
nvlist_free(*config);
continue;
}

if (expected_guid) {
if (expected_guid == guid)
count++;

nvlist_free(*config);
} else {
expected_config = *config;
expected_guid = guid;
count++;
}
}

if (num_labels != NULL)
*num_labels = count;

free(label);
*config = expected_config;

return (0);
}

/*
* Given a file descriptor, read the label information and return an nvlist
* describing the configuration, if there is one. The number of valid
Expand Down Expand Up @@ -929,6 +1006,8 @@ zpool_read_label(int fd, nvlist_t **config, int *num_labels)

if (lio_listio(LIO_WAIT, aiocbps, VDEV_LABELS, NULL) != 0) {
int saved_errno = errno;
boolean_t do_slow = B_FALSE;
error = -1;

if (errno == EAGAIN || errno == EINTR || errno == EIO) {
/*
Expand All @@ -937,14 +1016,33 @@ zpool_read_label(int fd, nvlist_t **config, int *num_labels)
*/
for (l = 0; l < VDEV_LABELS; l++) {
errno = 0;
int r = aio_error(&aiocbs[l]);
if (r != EINVAL)
switch (aio_error(&aiocbs[l])) {
case EINVAL:
break;
rincebrain marked this conversation as resolved.
Show resolved Hide resolved
case EINPROGRESS:
// This shouldn't be possible to
// encounter, die if we do.
ASSERT(B_FALSE);
case EOPNOTSUPP:
case ENOSYS:
do_slow = B_TRUE;
case 0:
default:
(void) aio_return(&aiocbs[l]);
}
}
rincebrain marked this conversation as resolved.
Show resolved Hide resolved
}
if (do_slow) {
/*
* At least some IO involved access unsafe-for-AIO
* files. Let's try again, without AIO this time.
*/
error = zpool_read_label_slow(fd, config, num_labels);
saved_errno = errno;
}
free(labels);
errno = saved_errno;
return (-1);
return (error);
rincebrain marked this conversation as resolved.
Show resolved Hide resolved
}

for (l = 0; l < VDEV_LABELS; l++) {
Expand Down