]> git.proxmox.com Git - mirror_zfs-debian.git/blobdiff - lib/libzfs/libzfs_pool.c
Fix missing vdev names in zpool status output
[mirror_zfs-debian.git] / lib / libzfs / libzfs_pool.c
index bb184ed688dd0f444583fdd3ae4f39c384cb6cab..f61e6cf45c78790a1469b045bb0fc3cf6096b831 100644 (file)
@@ -235,6 +235,7 @@ zpool_get_prop(zpool_handle_t *zhp, zpool_prop_t prop, char *buf, size_t len,
 
                case ZPOOL_PROP_ALTROOT:
                case ZPOOL_PROP_CACHEFILE:
+               case ZPOOL_PROP_COMMENT:
                        if (zhp->zpool_props != NULL ||
                            zpool_get_all_props(zhp) == 0) {
                                (void) strlcpy(buf,
@@ -385,7 +386,7 @@ zpool_valid_proplist(libzfs_handle_t *hdl, const char *poolname,
        zpool_prop_t prop;
        char *strval;
        uint64_t intval;
-       char *slash;
+       char *slash, *check;
        struct stat64 statbuf;
        zpool_handle_t *zhp;
        nvlist_t *nvroot;
@@ -566,6 +567,26 @@ zpool_valid_proplist(libzfs_handle_t *hdl, const char *poolname,
                        *slash = '/';
                        break;
 
+               case ZPOOL_PROP_COMMENT:
+                       for (check = strval; *check != '\0'; check++) {
+                               if (!isprint(*check)) {
+                                       zfs_error_aux(hdl,
+                                           dgettext(TEXT_DOMAIN,
+                                           "comment may only have printable "
+                                           "characters"));
+                                       (void) zfs_error(hdl, EZFS_BADPROP,
+                                           errbuf);
+                                       goto error;
+                               }
+                       }
+                       if (strlen(strval) > ZPROP_MAX_COMMENT) {
+                               zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
+                                   "comment must not exceed %d characters"),
+                                   ZPROP_MAX_COMMENT);
+                               (void) zfs_error(hdl, EZFS_BADPROP, errbuf);
+                               goto error;
+                       }
+                       break;
                case ZPOOL_PROP_READONLY:
                        if (!flags.import) {
                                zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
@@ -2083,28 +2104,30 @@ zpool_get_physpath(zpool_handle_t *zhp, char *physpath, size_t phypath_size)
  * the disk to use the new unallocated space.
  */
 static int
-zpool_relabel_disk(libzfs_handle_t *hdl, const char *path)
+zpool_relabel_disk(libzfs_handle_t *hdl, const char *path, const char *msg)
 {
-       char errbuf[1024];
        int fd, error;
 
        if ((fd = open(path, O_RDWR|O_DIRECT)) < 0) {
                zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "cannot "
                    "relabel '%s': unable to open device: %d"), path, errno);
-               return (zfs_error(hdl, EZFS_OPENFAILED, errbuf));
+               return (zfs_error(hdl, EZFS_OPENFAILED, msg));
        }
 
        /*
         * It's possible that we might encounter an error if the device
         * does not have any unallocated space left. If so, we simply
         * ignore that error and continue on.
+        *
+        * Also, we don't call efi_rescan() - that would just return EBUSY.
+        * The module will do it for us in vdev_disk_open().
         */
        error = efi_use_whole_disk(fd);
        (void) close(fd);
        if (error && error != VT_ENOSPC) {
                zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "cannot "
                    "relabel '%s': unable to read disk capacity"), path);
-               return (zfs_error(hdl, EZFS_NOCAP, errbuf));
+               return (zfs_error(hdl, EZFS_NOCAP, msg));
        }
        return (0);
 }
@@ -2122,6 +2145,7 @@ zpool_vdev_online(zpool_handle_t *zhp, const char *path, int flags,
        nvlist_t *tgt;
        boolean_t avail_spare, l2cache, islog;
        libzfs_handle_t *hdl = zhp->zpool_hdl;
+       int error;
 
        if (flags & ZFS_ONLINE_EXPAND) {
                (void) snprintf(msg, sizeof (msg),
@@ -2143,13 +2167,10 @@ zpool_vdev_online(zpool_handle_t *zhp, const char *path, int flags,
 
        if (flags & ZFS_ONLINE_EXPAND ||
            zpool_get_prop_int(zhp, ZPOOL_PROP_AUTOEXPAND, NULL)) {
-               char *pathname = NULL;
                uint64_t wholedisk = 0;
 
                (void) nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_WHOLE_DISK,
                    &wholedisk);
-               verify(nvlist_lookup_string(tgt, ZPOOL_CONFIG_PATH,
-                   &pathname) == 0);
 
                /*
                 * XXX - L2ARC 1.0 devices can't support expansion.
@@ -2161,8 +2182,22 @@ zpool_vdev_online(zpool_handle_t *zhp, const char *path, int flags,
                }
 
                if (wholedisk) {
-                       pathname += strlen(DISK_ROOT) + 1;
-                       (void) zpool_relabel_disk(hdl, pathname);
+                       const char *fullpath = path;
+                       char buf[MAXPATHLEN];
+
+                       if (path[0] != '/') {
+                               error = zfs_resolve_shortname(path, buf,
+                                   sizeof(buf));
+                               if (error != 0)
+                                       return (zfs_error(hdl, EZFS_NODEVICE,
+                                           msg));
+
+                               fullpath = buf;
+                       }
+
+                       error = zpool_relabel_disk(hdl, fullpath, msg);
+                       if (error != 0)
+                               return (error);
                }
        }
 
@@ -3099,6 +3134,7 @@ zpool_vdev_name(libzfs_handle_t *hdl, zpool_handle_t *zhp, nvlist_t *nv,
        char *path, *devid, *type;
        uint64_t value;
        char buf[PATH_BUF_LEN];
+       char tmpbuf[PATH_BUF_LEN];
        vdev_stat_t *vs;
        uint_t vsc;
 
@@ -3171,13 +3207,12 @@ zpool_vdev_name(libzfs_handle_t *hdl, zpool_handle_t *zhp, nvlist_t *nv,
                 * If it's a raidz device, we need to stick in the parity level.
                 */
                if (strcmp(path, VDEV_TYPE_RAIDZ) == 0) {
-                       char tmpbuf[PATH_BUF_LEN];
 
                        verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NPARITY,
                            &value) == 0);
-                       (void) snprintf(tmpbuf, sizeof (tmpbuf), "%s%llu", path,
+                       (void) snprintf(buf, sizeof (buf), "%s%llu", path,
                            (u_longlong_t)value);
-                       path = tmpbuf;
+                       path = buf;
                }
 
                /*
@@ -3189,9 +3224,9 @@ zpool_vdev_name(libzfs_handle_t *hdl, zpool_handle_t *zhp, nvlist_t *nv,
 
                        verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_ID,
                            &id) == 0);
-                       (void) snprintf(buf, sizeof (buf), "%s-%llu", path,
-                           (u_longlong_t)id);
-                       path = buf;
+                       (void) snprintf(tmpbuf, sizeof (tmpbuf), "%s-%llu",
+                           path, (u_longlong_t)id);
+                       path = tmpbuf;
                }
        }
 
@@ -3836,7 +3871,7 @@ zpool_label_disk(libzfs_handle_t *hdl, zpool_handle_t *zhp, char *name)
        vtoc->efi_parts[8].p_size = resv;
        vtoc->efi_parts[8].p_tag = V_RESERVED;
 
-       if ((rval = efi_write(fd, vtoc)) != 0) {
+       if ((rval = efi_write(fd, vtoc)) != 0 || (rval = efi_rescan(fd)) != 0) {
                /*
                 * Some block drivers (like pcata) may not support EFI
                 * GPT labels.  Print out a helpful error message dir-