Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F161487468
D12495.id33417.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D12495.id33417.diff
View Options
Index: cddl/contrib/opensolaris/lib/libzfs/common/libzfs_import.c
===================================================================
--- cddl/contrib/opensolaris/lib/libzfs/common/libzfs_import.c
+++ cddl/contrib/opensolaris/lib/libzfs/common/libzfs_import.c
@@ -42,6 +42,7 @@
* using our derived config, and record the results.
*/
+#include <aio.h>
#include <ctype.h>
#include <devid.h>
#include <dirent.h>
@@ -919,13 +920,17 @@
* Given a file descriptor, read the label information and return an nvlist
* describing the configuration, if there is one.
* returns the number of valid labels found
+ * If a label is found, returns it via config. The caller is responsible for
+ * freeing it.
*/
int
zpool_read_all_labels(int fd, nvlist_t **config)
{
struct stat64 statbuf;
+ struct aiocb aiocbs[VDEV_LABELS];
+ struct aiocb *aiocbps[VDEV_LABELS];
int l;
- vdev_label_t *label;
+ vdev_label_t *labels;
uint64_t state, txg, size;
int nlabels = 0;
@@ -935,19 +940,39 @@
return (0);
size = P2ALIGN_TYPED(statbuf.st_size, sizeof (vdev_label_t), uint64_t);
- if ((label = malloc(sizeof (vdev_label_t))) == NULL)
+ if ((labels = calloc(VDEV_LABELS, sizeof (vdev_label_t))) == NULL)
return (0);
+ memset(aiocbs, 0, sizeof(aiocbs));
for (l = 0; l < VDEV_LABELS; l++) {
+ aiocbs[l].aio_fildes = fd;
+ aiocbs[l].aio_offset = label_offset(size, l);
+ aiocbs[l].aio_buf = &labels[l];
+ aiocbs[l].aio_nbytes = sizeof(vdev_label_t);
+ aiocbs[l].aio_lio_opcode = LIO_READ;
+ aiocbps[l] = &aiocbs[l];
+ }
+
+ if (lio_listio(LIO_WAIT, aiocbps, VDEV_LABELS, NULL) != 0) {
+ if (errno == EAGAIN || errno == EINTR || errno == EIO) {
+ for (l = 0; l < VDEV_LABELS; l++) {
+ errno = 0;
+ int r = aio_error(&aiocbs[l]);
+ if (r != EINVAL)
+ (void)aio_return(&aiocbs[l]);
+ }
+ }
+ return (0);
+ }
+
+ for (l = 0; l < VDEV_LABELS; l++) {
nvlist_t *temp = NULL;
- /* TODO: use aio_read so we can read al 4 labels in parallel */
- if (pread64(fd, label, sizeof (vdev_label_t),
- label_offset(size, l)) != sizeof (vdev_label_t))
+ if (aio_return(&aiocbs[l]) != sizeof(vdev_label_t))
continue;
- if (nvlist_unpack(label->vl_vdev_phys.vp_nvlist,
- sizeof (label->vl_vdev_phys.vp_nvlist), &temp, 0) != 0)
+ if (nvlist_unpack(labels[l].vl_vdev_phys.vp_nvlist,
+ sizeof (labels[l].vl_vdev_phys.vp_nvlist), &temp, 0) != 0)
continue;
if (nvlist_lookup_uint64(temp, ZPOOL_CONFIG_POOL_STATE,
@@ -970,7 +995,7 @@
nlabels++;
}
- free(label);
+ free(labels);
return (nlabels);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Jul 5, 6:02 AM (3 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34695539
Default Alt Text
D12495.id33417.diff (2 KB)
Attached To
Mode
D12495: Optimize zpool_read_all_labels with AIO
Attached
Detach File
Event Timeline
Log In to Comment