Print this page
re #13850 Refactor ZFS config discovery IOCs to libzfs_core patterns
re #9110 rb2713 - zdb dies with arithmetic exception
re #8346 rb2639 KT disk failures


   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.

  23  * Copyright (c) 2016 by Delphix. All rights reserved.
  24  * Copyright 2017 RackTop Systems.
  25  */
  26 
  27 #include <assert.h>
  28 #include <sys/zfs_context.h>
  29 #include <sys/avl.h>
  30 #include <string.h>
  31 #include <stdio.h>
  32 #include <stdlib.h>
  33 #include <sys/spa.h>
  34 #include <sys/fs/zfs.h>
  35 #include <sys/refcount.h>
  36 #include <dlfcn.h>
  37 
  38 extern void nicenum(uint64_t num, char *buf, size_t);
  39 
  40 /*
  41  * Routines needed by more than one client of libzpool.
  42  */
  43 
  44 static void
  45 show_vdev_stats(const char *desc, const char *ctype, nvlist_t *nv, int indent)
  46 {
  47         vdev_stat_t *vs;
  48         vdev_stat_t v0 = { 0 };
  49         uint64_t sec;
  50         uint64_t is_log = 0;
  51         nvlist_t **child;
  52         uint_t c, children;
  53         char used[6], avail[6];
  54         char rops[6], wops[6], rbytes[6], wbytes[6], rerr[6], werr[6], cerr[6];

  55         char *prefix = "";
  56 
  57         if (indent == 0 && desc != NULL) {
  58                 (void) printf("                           "
  59                     " capacity   operations   bandwidth  ---- errors ----\n");

  60                 (void) printf("description                "
  61                     "used avail  read write  read write  read write cksum\n");

  62         }
  63 
  64         if (desc != NULL) {
  65                 (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_IS_LOG, &is_log);
  66 
  67                 if (is_log)
  68                         prefix = "log ";
  69 
  70                 if (nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS,
  71                     (uint64_t **)&vs, &c) != 0)
  72                         vs = &v0;
  73 
  74                 sec = MAX(1, vs->vs_timestamp / NANOSEC);


  75 
  76                 nicenum(vs->vs_alloc, used, sizeof (used));
  77                 nicenum(vs->vs_space - vs->vs_alloc, avail, sizeof (avail));
  78                 nicenum(vs->vs_ops[ZIO_TYPE_READ] / sec, rops, sizeof (rops));
  79                 nicenum(vs->vs_ops[ZIO_TYPE_WRITE] / sec, wops, sizeof (wops));
  80                 nicenum(vs->vs_bytes[ZIO_TYPE_READ] / sec, rbytes,
  81                     sizeof (rbytes));
  82                 nicenum(vs->vs_bytes[ZIO_TYPE_WRITE] / sec, wbytes,
  83                     sizeof (wbytes));




  84                 nicenum(vs->vs_read_errors, rerr, sizeof (rerr));
  85                 nicenum(vs->vs_write_errors, werr, sizeof (werr));
  86                 nicenum(vs->vs_checksum_errors, cerr, sizeof (cerr));
  87 
  88                 (void) printf("%*s%s%*s%*s%*s %5s %5s %5s %5s %5s %5s %5s\n",

  89                     indent, "",
  90                     prefix,
  91                     indent + strlen(prefix) - 25 - (vs->vs_space ? 0 : 12),
  92                     desc,
  93                     vs->vs_space ? 6 : 0, vs->vs_space ? used : "",
  94                     vs->vs_space ? 6 : 0, vs->vs_space ? avail : "",
  95                     rops, wops, rbytes, wbytes, rerr, werr, cerr);

  96         }
  97 
  98         if (nvlist_lookup_nvlist_array(nv, ctype, &child, &children) != 0)
  99                 return;
 100 
 101         for (c = 0; c < children; c++) {
 102                 nvlist_t *cnv = child[c];
 103                 char *cname, *tname;
 104                 uint64_t np;
 105                 if (nvlist_lookup_string(cnv, ZPOOL_CONFIG_PATH, &cname) &&
 106                     nvlist_lookup_string(cnv, ZPOOL_CONFIG_TYPE, &cname))
 107                         cname = "<unknown>";
 108                 tname = calloc(1, strlen(cname) + 2);
 109                 (void) strcpy(tname, cname);
 110                 if (nvlist_lookup_uint64(cnv, ZPOOL_CONFIG_NPARITY, &np) == 0)
 111                         tname[strlen(tname)] = '0' + np;
 112                 show_vdev_stats(tname, ctype, cnv, indent + 2);
 113                 free(tname);
 114         }
 115 }




   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
  24  * Copyright (c) 2016 by Delphix. All rights reserved.
  25  * Copyright 2017 RackTop Systems.
  26  */
  27 
  28 #include <assert.h>
  29 #include <sys/zfs_context.h>
  30 #include <sys/avl.h>
  31 #include <string.h>
  32 #include <stdio.h>
  33 #include <stdlib.h>
  34 #include <sys/spa.h>
  35 #include <sys/fs/zfs.h>
  36 #include <sys/refcount.h>
  37 #include <dlfcn.h>
  38 
  39 extern void nicenum(uint64_t num, char *buf, size_t);
  40 
  41 /*
  42  * Routines needed by more than one client of libzpool.
  43  */
  44 
  45 static void
  46 show_vdev_stats(const char *desc, const char *ctype, nvlist_t *nv, int indent)
  47 {
  48         vdev_stat_t *vs;
  49         vdev_stat_t v0 = { 0 };
  50         uint64_t sec, ops_rd, ops_wr;
  51         uint64_t is_log = 0;
  52         nvlist_t **child;
  53         uint_t c, children;
  54         char used[6], avail[6];
  55         char rops[6], wops[6], rbytes[6], wbytes[6], rerr[6], werr[6], cerr[6];
  56         char riotime[8], wiotime[8];
  57         char *prefix = "";
  58 
  59         if (indent == 0 && desc != NULL) {
  60                 (void) printf("                           "
  61                     " capacity   operations   bandwidth   --- latency ---  "
  62                     "---- errors ----\n");
  63                 (void) printf("description                "
  64                     "used avail  read write  read write     read    write  "
  65                     "read write cksum\n");
  66         }
  67 
  68         if (desc != NULL) {
  69                 (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_IS_LOG, &is_log);
  70 
  71                 if (is_log)
  72                         prefix = "log ";
  73 
  74                 if (nvlist_lookup_uint64_array(nv, ZPOOL_CONFIG_VDEV_STATS,
  75                     (uint64_t **)&vs, &c) != 0)
  76                         vs = &v0;
  77 
  78                 sec = MAX(1, vs->vs_timestamp / NANOSEC);
  79                 ops_rd = MAX(1, vs->vs_ops[ZIO_TYPE_READ]);
  80                 ops_wr = MAX(1, vs->vs_ops[ZIO_TYPE_WRITE]);
  81 
  82                 nicenum(vs->vs_alloc, used, sizeof (used));
  83                 nicenum(vs->vs_space - vs->vs_alloc, avail, sizeof (avail));
  84                 nicenum(vs->vs_ops[ZIO_TYPE_READ] / sec, rops, sizeof (rops));
  85                 nicenum(vs->vs_ops[ZIO_TYPE_WRITE] / sec, wops, sizeof (wops));
  86                 nicenum(vs->vs_bytes[ZIO_TYPE_READ] / sec, rbytes,
  87                     sizeof (rbytes));
  88                 nicenum(vs->vs_bytes[ZIO_TYPE_WRITE] / sec, wbytes,
  89                     sizeof (wbytes));
  90                 nicenum(vs->vs_iotime[ZIO_TYPE_READ] / ops_rd, riotime,
  91                     sizeof (riotime));
  92                 nicenum(vs->vs_iotime[ZIO_TYPE_WRITE] / ops_wr, wiotime,
  93                     sizeof (wiotime));
  94                 nicenum(vs->vs_read_errors, rerr, sizeof (rerr));
  95                 nicenum(vs->vs_write_errors, werr, sizeof (werr));
  96                 nicenum(vs->vs_checksum_errors, cerr, sizeof (cerr));
  97 
  98                 (void) printf(
  99                     "%*s%s%*s%*s%*s %5s %5s %5s %5s %8s %8s %5s %5s %5s\n",
 100                     indent, "",
 101                     prefix,
 102                     indent + strlen(prefix) - 25 - (vs->vs_space ? 0 : 12),
 103                     desc,
 104                     vs->vs_space ? 6 : 0, vs->vs_space ? used : "",
 105                     vs->vs_space ? 6 : 0, vs->vs_space ? avail : "",
 106                     rops, wops, rbytes, wbytes, riotime, wiotime, rerr, werr,
 107                     cerr);
 108         }
 109 
 110         if (nvlist_lookup_nvlist_array(nv, ctype, &child, &children) != 0)
 111                 return;
 112 
 113         for (c = 0; c < children; c++) {
 114                 nvlist_t *cnv = child[c];
 115                 char *cname, *tname;
 116                 uint64_t np;
 117                 if (nvlist_lookup_string(cnv, ZPOOL_CONFIG_PATH, &cname) &&
 118                     nvlist_lookup_string(cnv, ZPOOL_CONFIG_TYPE, &cname))
 119                         cname = "<unknown>";
 120                 tname = calloc(1, strlen(cname) + 2);
 121                 (void) strcpy(tname, cname);
 122                 if (nvlist_lookup_uint64(cnv, ZPOOL_CONFIG_NPARITY, &np) == 0)
 123                         tname[strlen(tname)] = '0' + np;
 124                 show_vdev_stats(tname, ctype, cnv, indent + 2);
 125                 free(tname);
 126         }
 127 }