]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Fix "out of memory" error
authorBrian Behlendorf <behlendorf1@llnl.gov>
Fri, 12 Jan 2024 20:35:29 +0000 (12:35 -0800)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Mon, 29 Jan 2024 22:53:29 +0000 (14:53 -0800)
Drop the no_memory() call from zpool_in_use() when reading the
label fails and instead return the error to the caller.  This
prevents a misleading "internal error: out of memory" error
when the label can't be read.  This will result in is_spare()
returning B_FALSE instead of aborting, which is already safely
handled.

Furthermore, on Linux it's possible for EREMOTEIO to returned
by an NVMe device if the device has been low-level formatted
and not rescanned.  In this case we want to fallback to the
legacy scanning method and read any of the labels we can.

Reviewed-by: Brian Atkinson <batkinson@lanl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #13538
Closes #15747

lib/libzfs/libzfs_import.c
lib/libzutil/zutil_import.c

index 2a7c5a76a0a60ab973690584f1779356eef77528..e2d40a7b3bfb243014e74b6c4ae3b2ce905c7ae7 100644 (file)
@@ -291,10 +291,8 @@ zpool_in_use(libzfs_handle_t *hdl, int fd, pool_state_t *state, char **namestr,
 
        *inuse = B_FALSE;
 
-       if (zpool_read_label(fd, &config, NULL) != 0) {
-               (void) no_memory(hdl);
+       if (zpool_read_label(fd, &config, NULL) != 0)
                return (-1);
-       }
 
        if (config == NULL)
                return (0);
index 19d8a4742813be80c57ba19898980d16b85e1172..bafe50e5f90ea1869fced1d58e486dd18aef7108 100644 (file)
@@ -1056,10 +1056,21 @@ zpool_read_label(int fd, nvlist_t **config, int *num_labels)
                                case EINVAL:
                                        break;
                                case EINPROGRESS:
-                                       // This shouldn't be possible to
-                                       // encounter, die if we do.
+                                       /*
+                                        * This shouldn't be possible to
+                                        * encounter, die if we do.
+                                        */
                                        ASSERT(B_FALSE);
                                        zfs_fallthrough;
+                               case EREMOTEIO:
+                                       /*
+                                        * May be returned by an NVMe device
+                                        * which is visible in /dev/ but due
+                                        * to a low-level format change, or
+                                        * other error, needs to be rescanned.
+                                        * Try the slow method.
+                                        */
+                                       zfs_fallthrough;
                                case EOPNOTSUPP:
                                case ENOSYS:
                                        do_slow = B_TRUE;