Print this page
NEX-3508 CLONE - Port NEX-2946 Add UNMAP/TRIM functionality to ZFS and illumos
Reviewed by: Josef Sipek <josef.sipek@nexenta.com>
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
Conflicts:
    usr/src/uts/common/io/scsi/targets/sd.c
    usr/src/uts/common/sys/scsi/targets/sddef.h

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/fs/zfs/vdev_root.c
          +++ new/usr/src/uts/common/fs/zfs/vdev_root.c
↓ open down ↓ 16 lines elided ↑ open up ↑
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
  24   24   */
  25   25  
  26   26  /*
  27      - * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
       27 + * Copyright (c) 2013 by Delphix. All rights reserved.
  28   28   */
  29   29  
  30   30  #include <sys/zfs_context.h>
  31   31  #include <sys/spa.h>
  32   32  #include <sys/vdev_impl.h>
  33   33  #include <sys/zio.h>
  34   34  #include <sys/fs/zfs.h>
  35   35  
  36   36  /*
  37   37   * Virtual device vector for the pool's root vdev.
  38   38   */
  39   39  
  40      -static uint64_t
  41      -vdev_root_core_tvds(vdev_t *vd)
  42      -{
  43      -        uint64_t tvds = 0;
  44      -
  45      -        for (uint64_t c = 0; c < vd->vdev_children; c++) {
  46      -                vdev_t *cvd = vd->vdev_child[c];
  47      -
  48      -                if (!cvd->vdev_ishole && !cvd->vdev_islog &&
  49      -                    cvd->vdev_ops != &vdev_indirect_ops) {
  50      -                        tvds++;
  51      -                }
  52      -        }
  53      -
  54      -        return (tvds);
  55      -}
  56      -
  57   40  /*
  58   41   * We should be able to tolerate one failure with absolutely no damage
  59   42   * to our metadata.  Two failures will take out space maps, a bunch of
  60   43   * indirect block trees, meta dnodes, dnodes, etc.  Probably not a happy
  61   44   * place to live.  When we get smarter, we can liberalize this policy.
  62   45   * e.g. If we haven't lost two consecutive top-level vdevs, then we are
  63   46   * probably fine.  Adding bean counters during alloc/free can make this
  64   47   * future guesswork more accurate.
  65   48   */
  66      -static boolean_t
  67      -too_many_errors(vdev_t *vd, uint64_t numerrors)
       49 +static int
       50 +too_many_errors(vdev_t *vd, int numerrors)
  68   51  {
  69      -        uint64_t tvds;
  70      -
  71      -        if (numerrors == 0)
  72      -                return (B_FALSE);
  73      -
  74      -        tvds = vdev_root_core_tvds(vd);
  75      -        ASSERT3U(numerrors, <=, tvds);
  76      -
  77      -        if (numerrors == tvds)
  78      -                return (B_TRUE);
  79      -
  80      -        return (numerrors > spa_missing_tvds_allowed(vd->vdev_spa));
       52 +        ASSERT3U(numerrors, <=, vd->vdev_children);
       53 +        return (numerrors > 0);
  81   54  }
  82   55  
  83   56  static int
  84   57  vdev_root_open(vdev_t *vd, uint64_t *asize, uint64_t *max_asize,
  85   58      uint64_t *ashift)
  86   59  {
  87      -        spa_t *spa = vd->vdev_spa;
  88   60          int lasterror = 0;
  89   61          int numerrors = 0;
  90   62  
  91   63          if (vd->vdev_children == 0) {
  92   64                  vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
  93   65                  return (SET_ERROR(EINVAL));
  94   66          }
  95   67  
  96   68          vdev_open_children(vd);
  97   69  
  98   70          for (int c = 0; c < vd->vdev_children; c++) {
  99   71                  vdev_t *cvd = vd->vdev_child[c];
 100   72  
 101   73                  if (cvd->vdev_open_error && !cvd->vdev_islog) {
 102   74                          lasterror = cvd->vdev_open_error;
 103   75                          numerrors++;
 104   76                  }
 105   77          }
 106   78  
 107      -        if (spa_load_state(spa) != SPA_LOAD_NONE)
 108      -                spa_set_missing_tvds(spa, numerrors);
 109      -
 110   79          if (too_many_errors(vd, numerrors)) {
 111   80                  vd->vdev_stat.vs_aux = VDEV_AUX_NO_REPLICAS;
 112   81                  return (lasterror);
 113   82          }
 114   83  
 115   84          *asize = 0;
 116   85          *max_asize = 0;
 117   86          *ashift = 0;
 118   87  
 119   88          return (0);
↓ open down ↓ 5 lines elided ↑ open up ↑
 125   94          for (int c = 0; c < vd->vdev_children; c++)
 126   95                  vdev_close(vd->vdev_child[c]);
 127   96  }
 128   97  
 129   98  static void
 130   99  vdev_root_state_change(vdev_t *vd, int faulted, int degraded)
 131  100  {
 132  101          if (too_many_errors(vd, faulted)) {
 133  102                  vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
 134  103                      VDEV_AUX_NO_REPLICAS);
 135      -        } else if (degraded || faulted) {
      104 +        } else if (degraded) {
 136  105                  vdev_set_state(vd, B_FALSE, VDEV_STATE_DEGRADED, VDEV_AUX_NONE);
 137  106          } else {
 138  107                  vdev_set_state(vd, B_FALSE, VDEV_STATE_HEALTHY, VDEV_AUX_NONE);
 139  108          }
 140  109  }
 141  110  
 142  111  vdev_ops_t vdev_root_ops = {
 143  112          vdev_root_open,
 144  113          vdev_root_close,
 145  114          vdev_default_asize,
 146  115          NULL,                   /* io_start - not applicable to the root */
 147  116          NULL,                   /* io_done - not applicable to the root */
 148  117          vdev_root_state_change,
 149  118          NULL,
 150  119          NULL,
 151  120          NULL,
 152  121          VDEV_TYPE_ROOT,         /* name of this vdev type */
 153  122          B_FALSE                 /* not a leaf vdev */
 154  123  };
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX