[BACK]Return to vdev_disk.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / external / cddl / osnet / dist / uts / common / fs / zfs

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/external/cddl/osnet/dist/uts/common/fs/zfs/vdev_disk.c between version 1.1.1.2 and 1.1.1.3

version 1.1.1.2, 2010/02/27 22:31:11 version 1.1.1.3, 2018/05/28 20:52:58
Line 19 
Line 19 
  * CDDL HEADER END   * CDDL HEADER END
  */   */
 /*  /*
  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.   * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.   * Copyright (c) 2012, 2015 by Delphix. All rights reserved.
    * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
    * Copyright (c) 2013 Joyent, Inc.  All rights reserved.
  */   */
   
 #include <sys/zfs_context.h>  #include <sys/zfs_context.h>
 #include <sys/spa.h>  #include <sys/spa_impl.h>
 #include <sys/refcount.h>  #include <sys/refcount.h>
 #include <sys/vdev_disk.h>  #include <sys/vdev_disk.h>
 #include <sys/vdev_impl.h>  #include <sys/vdev_impl.h>
 #include <sys/fs/zfs.h>  #include <sys/fs/zfs.h>
 #include <sys/zio.h>  #include <sys/zio.h>
 #include <sys/sunldi.h>  #include <sys/sunldi.h>
   #include <sys/efi_partition.h>
 #include <sys/fm/fs/zfs.h>  #include <sys/fm/fs/zfs.h>
   
 /*  /*
Line 39 
Line 42 
   
 extern ldi_ident_t zfs_li;  extern ldi_ident_t zfs_li;
   
 typedef struct vdev_disk_buf {  static void vdev_disk_close(vdev_t *);
         buf_t   vdb_buf;  
         zio_t   *vdb_io;  typedef struct vdev_disk_ldi_cb {
 } vdev_disk_buf_t;          list_node_t             lcb_next;
           ldi_callback_id_t       lcb_id;
   } vdev_disk_ldi_cb_t;
   
   static void
   vdev_disk_alloc(vdev_t *vd)
   {
           vdev_disk_t *dvd;
   
           dvd = vd->vdev_tsd = kmem_zalloc(sizeof (vdev_disk_t), KM_SLEEP);
           /*
            * Create the LDI event callback list.
            */
           list_create(&dvd->vd_ldi_cbs, sizeof (vdev_disk_ldi_cb_t),
               offsetof(vdev_disk_ldi_cb_t, lcb_next));
   }
   
   static void
   vdev_disk_free(vdev_t *vd)
   {
           vdev_disk_t *dvd = vd->vdev_tsd;
           vdev_disk_ldi_cb_t *lcb;
   
           if (dvd == NULL)
                   return;
   
           /*
            * We have already closed the LDI handle. Clean up the LDI event
            * callbacks and free vd->vdev_tsd.
            */
           while ((lcb = list_head(&dvd->vd_ldi_cbs)) != NULL) {
                   list_remove(&dvd->vd_ldi_cbs, lcb);
                   (void) ldi_ev_remove_callbacks(lcb->lcb_id);
                   kmem_free(lcb, sizeof (vdev_disk_ldi_cb_t));
           }
           list_destroy(&dvd->vd_ldi_cbs);
           kmem_free(dvd, sizeof (vdev_disk_t));
           vd->vdev_tsd = NULL;
   }
   
   /* ARGSUSED */
   static int
   vdev_disk_off_notify(ldi_handle_t lh, ldi_ev_cookie_t ecookie, void *arg,
       void *ev_data)
   {
           vdev_t *vd = (vdev_t *)arg;
           vdev_disk_t *dvd = vd->vdev_tsd;
   
           /*
            * Ignore events other than offline.
            */
           if (strcmp(ldi_ev_get_type(ecookie), LDI_EV_OFFLINE) != 0)
                   return (LDI_EV_SUCCESS);
   
           /*
            * All LDI handles must be closed for the state change to succeed, so
            * call on vdev_disk_close() to do this.
            *
            * We inform vdev_disk_close that it is being called from offline
            * notify context so it will defer cleanup of LDI event callbacks and
            * freeing of vd->vdev_tsd to the offline finalize or a reopen.
            */
           dvd->vd_ldi_offline = B_TRUE;
           vdev_disk_close(vd);
   
           /*
            * Now that the device is closed, request that the spa_async_thread
            * mark the device as REMOVED and notify FMA of the removal.
            */
           zfs_post_remove(vd->vdev_spa, vd);
           vd->vdev_remove_wanted = B_TRUE;
           spa_async_request(vd->vdev_spa, SPA_ASYNC_REMOVE);
   
           return (LDI_EV_SUCCESS);
   }
   
   /* ARGSUSED */
   static void
   vdev_disk_off_finalize(ldi_handle_t lh, ldi_ev_cookie_t ecookie,
       int ldi_result, void *arg, void *ev_data)
   {
           vdev_t *vd = (vdev_t *)arg;
   
           /*
            * Ignore events other than offline.
            */
           if (strcmp(ldi_ev_get_type(ecookie), LDI_EV_OFFLINE) != 0)
                   return;
   
           /*
            * We have already closed the LDI handle in notify.
            * Clean up the LDI event callbacks and free vd->vdev_tsd.
            */
           vdev_disk_free(vd);
   
           /*
            * Request that the vdev be reopened if the offline state change was
            * unsuccessful.
            */
           if (ldi_result != LDI_EV_SUCCESS) {
                   vd->vdev_probe_wanted = B_TRUE;
                   spa_async_request(vd->vdev_spa, SPA_ASYNC_PROBE);
           }
   }
   
   static ldi_ev_callback_t vdev_disk_off_callb = {
           .cb_vers = LDI_EV_CB_VERS,
           .cb_notify = vdev_disk_off_notify,
           .cb_finalize = vdev_disk_off_finalize
   };
   
   /* ARGSUSED */
   static void
   vdev_disk_dgrd_finalize(ldi_handle_t lh, ldi_ev_cookie_t ecookie,
       int ldi_result, void *arg, void *ev_data)
   {
           vdev_t *vd = (vdev_t *)arg;
   
           /*
            * Ignore events other than degrade.
            */
           if (strcmp(ldi_ev_get_type(ecookie), LDI_EV_DEGRADE) != 0)
                   return;
   
           /*
            * Degrade events always succeed. Mark the vdev as degraded.
            * This status is purely informative for the user.
            */
           (void) vdev_degrade(vd->vdev_spa, vd->vdev_guid, 0);
   }
   
   static ldi_ev_callback_t vdev_disk_dgrd_callb = {
           .cb_vers = LDI_EV_CB_VERS,
           .cb_notify = NULL,
           .cb_finalize = vdev_disk_dgrd_finalize
   };
   
   static void
   vdev_disk_hold(vdev_t *vd)
   {
           ddi_devid_t devid;
           char *minor;
   
           ASSERT(spa_config_held(vd->vdev_spa, SCL_STATE, RW_WRITER));
   
           /*
            * We must have a pathname, and it must be absolute.
            */
           if (vd->vdev_path == NULL || vd->vdev_path[0] != '/')
                   return;
   
           /*
            * Only prefetch path and devid info if the device has
            * never been opened.
            */
           if (vd->vdev_tsd != NULL)
                   return;
   
           if (vd->vdev_wholedisk == -1ULL) {
                   size_t len = strlen(vd->vdev_path) + 3;
                   char *buf = kmem_alloc(len, KM_SLEEP);
   
                   (void) snprintf(buf, len, "%ss0", vd->vdev_path);
   
                   (void) ldi_vp_from_name(buf, &vd->vdev_name_vp);
                   kmem_free(buf, len);
           }
   
           if (vd->vdev_name_vp == NULL)
                   (void) ldi_vp_from_name(vd->vdev_path, &vd->vdev_name_vp);
   
           if (vd->vdev_devid != NULL &&
               ddi_devid_str_decode(vd->vdev_devid, &devid, &minor) == 0) {
                   (void) ldi_vp_from_devid(devid, minor, &vd->vdev_devid_vp);
                   ddi_devid_str_free(minor);
                   ddi_devid_free(devid);
           }
   }
   
   static void
   vdev_disk_rele(vdev_t *vd)
   {
           ASSERT(spa_config_held(vd->vdev_spa, SCL_STATE, RW_WRITER));
   
           if (vd->vdev_name_vp) {
                   VN_RELE_ASYNC(vd->vdev_name_vp,
                       dsl_pool_vnrele_taskq(vd->vdev_spa->spa_dsl_pool));
                   vd->vdev_name_vp = NULL;
           }
           if (vd->vdev_devid_vp) {
                   VN_RELE_ASYNC(vd->vdev_devid_vp,
                       dsl_pool_vnrele_taskq(vd->vdev_spa->spa_dsl_pool));
                   vd->vdev_devid_vp = NULL;
           }
   }
   
   /*
    * We want to be loud in DEBUG kernels when DKIOCGMEDIAINFOEXT fails, or when
    * even a fallback to DKIOCGMEDIAINFO fails.
    */
   #ifdef DEBUG
   #define VDEV_DEBUG(...) cmn_err(CE_NOTE, __VA_ARGS__)
   #else
   #define VDEV_DEBUG(...) /* Nothing... */
   #endif
   
 static int  static int
 vdev_disk_open(vdev_t *vd, uint64_t *psize, uint64_t *ashift)  vdev_disk_open(vdev_t *vd, uint64_t *psize, uint64_t *max_psize,
       uint64_t *ashift)
 {  {
         spa_t *spa = vd->vdev_spa;          spa_t *spa = vd->vdev_spa;
         vdev_disk_t *dvd;          vdev_disk_t *dvd = vd->vdev_tsd;
         struct dk_minfo dkm;          ldi_ev_cookie_t ecookie;
           vdev_disk_ldi_cb_t *lcb;
           union {
                   struct dk_minfo_ext ude;
                   struct dk_minfo ud;
           } dks;
           struct dk_minfo_ext *dkmext = &dks.ude;
           struct dk_minfo *dkm = &dks.ud;
         int error;          int error;
         dev_t dev;          dev_t dev;
         int otyp;          int otyp;
           boolean_t validate_devid = B_FALSE;
           ddi_devid_t devid;
           uint64_t capacity = 0, blksz = 0, pbsize;
   
         /*          /*
          * We must have a pathname, and it must be absolute.           * We must have a pathname, and it must be absolute.
          */           */
         if (vd->vdev_path == NULL || vd->vdev_path[0] != '/') {          if (vd->vdev_path == NULL || vd->vdev_path[0] != '/') {
                 vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;                  vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
                 return (EINVAL);                  return (SET_ERROR(EINVAL));
         }          }
   
         /*          /*
          * Reopen the device if it's not currently open. Otherwise,           * Reopen the device if it's not currently open. Otherwise,
          * just update the physical size of the device.           * just update the physical size of the device.
          */           */
         if (vd->vdev_tsd != NULL) {          if (dvd != NULL) {
                 ASSERT(vd->vdev_reopening);                  if (dvd->vd_ldi_offline && dvd->vd_lh == NULL) {
                 dvd = vd->vdev_tsd;                          /*
                 goto skip_open;                           * If we are opening a device in its offline notify
                            * context, the LDI handle was just closed. Clean
                            * up the LDI event callbacks and free vd->vdev_tsd.
                            */
                           vdev_disk_free(vd);
                   } else {
                           ASSERT(vd->vdev_reopening);
                           goto skip_open;
                   }
         }          }
   
         dvd = vd->vdev_tsd = kmem_zalloc(sizeof (vdev_disk_t), KM_SLEEP);          /*
            * Create vd->vdev_tsd.
            */
           vdev_disk_alloc(vd);
           dvd = vd->vdev_tsd;
   
         /*          /*
          * When opening a disk device, we want to preserve the user's original           * When opening a disk device, we want to preserve the user's original
Line 94  vdev_disk_open(vdev_t *vd, uint64_t *psi
Line 324  vdev_disk_open(vdev_t *vd, uint64_t *psi
                 if (ddi_devid_str_decode(vd->vdev_devid, &dvd->vd_devid,                  if (ddi_devid_str_decode(vd->vdev_devid, &dvd->vd_devid,
                     &dvd->vd_minor) != 0) {                      &dvd->vd_minor) != 0) {
                         vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;                          vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
                         return (EINVAL);                          return (SET_ERROR(EINVAL));
                 }                  }
         }          }
   
         error = EINVAL;         /* presume failure */          error = EINVAL;         /* presume failure */
   
         if (vd->vdev_path != NULL) {          if (vd->vdev_path != NULL) {
                 ddi_devid_t devid;  
   
                 if (vd->vdev_wholedisk == -1ULL) {                  if (vd->vdev_wholedisk == -1ULL) {
                         size_t len = strlen(vd->vdev_path) + 3;                          size_t len = strlen(vd->vdev_path) + 3;
                         char *buf = kmem_alloc(len, KM_SLEEP);                          char *buf = kmem_alloc(len, KM_SLEEP);
                         ldi_handle_t lh;  
   
                         (void) snprintf(buf, len, "%ss0", vd->vdev_path);                          (void) snprintf(buf, len, "%ss0", vd->vdev_path);
   
                         if (ldi_open_by_name(buf, spa_mode(spa), kcred,                          error = ldi_open_by_name(buf, spa_mode(spa), kcred,
                             &lh, zfs_li) == 0) {                              &dvd->vd_lh, zfs_li);
                           if (error == 0) {
                                 spa_strfree(vd->vdev_path);                                  spa_strfree(vd->vdev_path);
                                 vd->vdev_path = buf;                                  vd->vdev_path = buf;
                                 vd->vdev_wholedisk = 1ULL;                                  vd->vdev_wholedisk = 1ULL;
                                 (void) ldi_close(lh, spa_mode(spa), kcred);  
                         } else {                          } else {
                                 kmem_free(buf, len);                                  kmem_free(buf, len);
                         }                          }
                 }                  }
   
                 error = ldi_open_by_name(vd->vdev_path, spa_mode(spa), kcred,                  /*
                     &dvd->vd_lh, zfs_li);                   * If we have not yet opened the device, try to open it by the
                    * specified path.
                    */
                   if (error != 0) {
                           error = ldi_open_by_name(vd->vdev_path, spa_mode(spa),
                               kcred, &dvd->vd_lh, zfs_li);
                   }
   
                 /*                  /*
                  * Compare the devid to the stored value.                   * Compare the devid to the stored value.
Line 130  vdev_disk_open(vdev_t *vd, uint64_t *psi
Line 364  vdev_disk_open(vdev_t *vd, uint64_t *psi
                 if (error == 0 && vd->vdev_devid != NULL &&                  if (error == 0 && vd->vdev_devid != NULL &&
                     ldi_get_devid(dvd->vd_lh, &devid) == 0) {                      ldi_get_devid(dvd->vd_lh, &devid) == 0) {
                         if (ddi_devid_compare(devid, dvd->vd_devid) != 0) {                          if (ddi_devid_compare(devid, dvd->vd_devid) != 0) {
                                 error = EINVAL;                                  error = SET_ERROR(EINVAL);
                                 (void) ldi_close(dvd->vd_lh, spa_mode(spa),                                  (void) ldi_close(dvd->vd_lh, spa_mode(spa),
                                     kcred);                                      kcred);
                                 dvd->vd_lh = NULL;                                  dvd->vd_lh = NULL;
Line 150  vdev_disk_open(vdev_t *vd, uint64_t *psi
Line 384  vdev_disk_open(vdev_t *vd, uint64_t *psi
          * If we were unable to open by path, or the devid check fails, open by           * If we were unable to open by path, or the devid check fails, open by
          * devid instead.           * devid instead.
          */           */
         if (error != 0 && vd->vdev_devid != NULL)          if (error != 0 && vd->vdev_devid != NULL) {
                 error = ldi_open_by_devid(dvd->vd_devid, dvd->vd_minor,                  error = ldi_open_by_devid(dvd->vd_devid, dvd->vd_minor,
                     spa_mode(spa), kcred, &dvd->vd_lh, zfs_li);                      spa_mode(spa), kcred, &dvd->vd_lh, zfs_li);
           }
   
         /*          /*
          * If all else fails, then try opening by physical path (if available)           * If all else fails, then try opening by physical path (if available)
Line 161  vdev_disk_open(vdev_t *vd, uint64_t *psi
Line 396  vdev_disk_open(vdev_t *vd, uint64_t *psi
          * level vdev validation will prevent us from opening the wrong device.           * level vdev validation will prevent us from opening the wrong device.
          */           */
         if (error) {          if (error) {
                   if (vd->vdev_devid != NULL)
                           validate_devid = B_TRUE;
   
                 if (vd->vdev_physpath != NULL &&                  if (vd->vdev_physpath != NULL &&
                     (dev = ddi_pathname_to_dev_t(vd->vdev_physpath)) != NODEV)                      (dev = ddi_pathname_to_dev_t(vd->vdev_physpath)) != NODEV)
                         error = ldi_open_by_dev(&dev, OTYP_BLK, spa_mode(spa),                          error = ldi_open_by_dev(&dev, OTYP_BLK, spa_mode(spa),
Line 182  vdev_disk_open(vdev_t *vd, uint64_t *psi
Line 420  vdev_disk_open(vdev_t *vd, uint64_t *psi
         }          }
   
         /*          /*
            * Now that the device has been successfully opened, update the devid
            * if necessary.
            */
           if (validate_devid && spa_writeable(spa) &&
               ldi_get_devid(dvd->vd_lh, &devid) == 0) {
                   if (ddi_devid_compare(devid, dvd->vd_devid) != 0) {
                           char *vd_devid;
   
                           vd_devid = ddi_devid_str_encode(devid, dvd->vd_minor);
                           zfs_dbgmsg("vdev %s: update devid from %s, "
                               "to %s", vd->vdev_path, vd->vdev_devid, vd_devid);
                           spa_strfree(vd->vdev_devid);
                           vd->vdev_devid = spa_strdup(vd_devid);
                           ddi_devid_str_free(vd_devid);
                   }
                   ddi_devid_free(devid);
           }
   
           /*
          * Once a device is opened, verify that the physical device path (if           * Once a device is opened, verify that the physical device path (if
          * available) is up to date.           * available) is up to date.
          */           */
Line 206  vdev_disk_open(vdev_t *vd, uint64_t *psi
Line 463  vdev_disk_open(vdev_t *vd, uint64_t *psi
                 kmem_free(physpath, MAXPATHLEN);                  kmem_free(physpath, MAXPATHLEN);
         }          }
   
           /*
            * Register callbacks for the LDI offline event.
            */
           if (ldi_ev_get_cookie(dvd->vd_lh, LDI_EV_OFFLINE, &ecookie) ==
               LDI_EV_SUCCESS) {
                   lcb = kmem_zalloc(sizeof (vdev_disk_ldi_cb_t), KM_SLEEP);
                   list_insert_tail(&dvd->vd_ldi_cbs, lcb);
                   (void) ldi_ev_register_callbacks(dvd->vd_lh, ecookie,
                       &vdev_disk_off_callb, (void *) vd, &lcb->lcb_id);
           }
   
           /*
            * Register callbacks for the LDI degrade event.
            */
           if (ldi_ev_get_cookie(dvd->vd_lh, LDI_EV_DEGRADE, &ecookie) ==
               LDI_EV_SUCCESS) {
                   lcb = kmem_zalloc(sizeof (vdev_disk_ldi_cb_t), KM_SLEEP);
                   list_insert_tail(&dvd->vd_ldi_cbs, lcb);
                   (void) ldi_ev_register_callbacks(dvd->vd_lh, ecookie,
                       &vdev_disk_dgrd_callb, (void *) vd, &lcb->lcb_id);
           }
 skip_open:  skip_open:
         /*          /*
          * Determine the actual size of the device.           * Determine the actual size of the device.
          */           */
         if (ldi_get_size(dvd->vd_lh, psize) != 0) {          if (ldi_get_size(dvd->vd_lh, psize) != 0) {
                 vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;                  vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
                 return (EINVAL);                  return (SET_ERROR(EINVAL));
         }          }
   
           *max_psize = *psize;
   
         /*          /*
          * If we own the whole disk, try to enable disk write caching.           * Determine the device's minimum transfer size.
          * We ignore errors because it's OK if we can't do it.           * If the ioctl isn't supported, assume DEV_BSIZE.
          */           */
           if ((error = ldi_ioctl(dvd->vd_lh, DKIOCGMEDIAINFOEXT,
               (intptr_t)dkmext, FKIOCTL, kcred, NULL)) == 0) {
                   capacity = dkmext->dki_capacity - 1;
                   blksz = dkmext->dki_lbsize;
                   pbsize = dkmext->dki_pbsize;
           } else if ((error = ldi_ioctl(dvd->vd_lh, DKIOCGMEDIAINFO,
               (intptr_t)dkm, FKIOCTL, kcred, NULL)) == 0) {
                   VDEV_DEBUG(
                       "vdev_disk_open(\"%s\"): fallback to DKIOCGMEDIAINFO\n",
                       vd->vdev_path);
                   capacity = dkm->dki_capacity - 1;
                   blksz = dkm->dki_lbsize;
                   pbsize = blksz;
           } else {
                   VDEV_DEBUG("vdev_disk_open(\"%s\"): "
                       "both DKIOCGMEDIAINFO{,EXT} calls failed, %d\n",
                       vd->vdev_path, error);
                   pbsize = DEV_BSIZE;
           }
   
           *ashift = highbit64(MAX(pbsize, SPA_MINBLOCKSIZE)) - 1;
   
         if (vd->vdev_wholedisk == 1) {          if (vd->vdev_wholedisk == 1) {
                 int wce = 1;                  int wce = 1;
   
                   if (error == 0) {
                           /*
                            * If we have the capability to expand, we'd have
                            * found out via success from DKIOCGMEDIAINFO{,EXT}.
                            * Adjust max_psize upward accordingly since we know
                            * we own the whole disk now.
                            */
                           *max_psize = capacity * blksz;
                   }
   
                   /*
                    * Since we own the whole disk, try to enable disk write
                    * caching.  We ignore errors because it's OK if we can't do it.
                    */
                 (void) ldi_ioctl(dvd->vd_lh, DKIOCSETWCE, (intptr_t)&wce,                  (void) ldi_ioctl(dvd->vd_lh, DKIOCSETWCE, (intptr_t)&wce,
                     FKIOCTL, kcred, NULL);                      FKIOCTL, kcred, NULL);
         }          }
   
         /*          /*
          * Determine the device's minimum transfer size.  
          * If the ioctl isn't supported, assume DEV_BSIZE.  
          */  
         if (ldi_ioctl(dvd->vd_lh, DKIOCGMEDIAINFO, (intptr_t)&dkm,  
             FKIOCTL, kcred, NULL) != 0)  
                 dkm.dki_lbsize = DEV_BSIZE;  
   
         *ashift = highbit(MAX(dkm.dki_lbsize, SPA_MINBLOCKSIZE)) - 1;  
   
         /*  
          * Clear the nowritecache bit, so that on a vdev_reopen() we will           * Clear the nowritecache bit, so that on a vdev_reopen() we will
          * try again.           * try again.
          */           */
Line 252  vdev_disk_close(vdev_t *vd)
Line 559  vdev_disk_close(vdev_t *vd)
         if (vd->vdev_reopening || dvd == NULL)          if (vd->vdev_reopening || dvd == NULL)
                 return;                  return;
   
         if (dvd->vd_minor != NULL)          if (dvd->vd_minor != NULL) {
                 ddi_devid_str_free(dvd->vd_minor);                  ddi_devid_str_free(dvd->vd_minor);
                   dvd->vd_minor = NULL;
           }
   
         if (dvd->vd_devid != NULL)          if (dvd->vd_devid != NULL) {
                 ddi_devid_free(dvd->vd_devid);                  ddi_devid_free(dvd->vd_devid);
                   dvd->vd_devid = NULL;
           }
   
         if (dvd->vd_lh != NULL)          if (dvd->vd_lh != NULL) {
                 (void) ldi_close(dvd->vd_lh, spa_mode(vd->vdev_spa), kcred);                  (void) ldi_close(dvd->vd_lh, spa_mode(vd->vdev_spa), kcred);
                   dvd->vd_lh = NULL;
           }
   
         kmem_free(dvd, sizeof (vdev_disk_t));          vd->vdev_delayed_close = B_FALSE;
         vd->vdev_tsd = NULL;          /*
            * If we closed the LDI handle due to an offline notify from LDI,
            * don't free vd->vdev_tsd or unregister the callbacks here;
            * the offline finalize callback or a reopen will take care of it.
            */
           if (dvd->vd_ldi_offline)
                   return;
   
           vdev_disk_free(vd);
 }  }
   
 int  int
 vdev_disk_physio(ldi_handle_t vd_lh, caddr_t data, size_t size,  vdev_disk_physio(vdev_t *vd, caddr_t data,
     uint64_t offset, int flags)      size_t size, uint64_t offset, int flags, boolean_t isdump)
   {
           vdev_disk_t *dvd = vd->vdev_tsd;
   
           /*
            * If the vdev is closed, it's likely in the REMOVED or FAULTED state.
            * Nothing to be done here but return failure.
            */
           if (dvd == NULL || (dvd->vd_ldi_offline && dvd->vd_lh == NULL))
                   return (EIO);
   
           ASSERT(vd->vdev_ops == &vdev_disk_ops);
   
           /*
            * If in the context of an active crash dump, use the ldi_dump(9F)
            * call instead of ldi_strategy(9F) as usual.
            */
           if (isdump) {
                   ASSERT3P(dvd, !=, NULL);
                   return (ldi_dump(dvd->vd_lh, data, lbtodb(offset),
                       lbtodb(size)));
           }
   
           return (vdev_disk_ldi_physio(dvd->vd_lh, data, size, offset, flags));
   }
   
   int
   vdev_disk_ldi_physio(ldi_handle_t vd_lh, caddr_t data,
       size_t size, uint64_t offset, int flags)
 {  {
         buf_t *bp;          buf_t *bp;
         int error = 0;          int error = 0;
   
         if (vd_lh == NULL)          if (vd_lh == NULL)
                 return (EINVAL);                  return (SET_ERROR(EINVAL));
   
         ASSERT(flags & B_READ || flags & B_WRITE);          ASSERT(flags & B_READ || flags & B_WRITE);
   
Line 287  vdev_disk_physio(ldi_handle_t vd_lh, cad
Line 636  vdev_disk_physio(ldi_handle_t vd_lh, cad
         error = ldi_strategy(vd_lh, bp);          error = ldi_strategy(vd_lh, bp);
         ASSERT(error == 0);          ASSERT(error == 0);
         if ((error = biowait(bp)) == 0 && bp->b_resid != 0)          if ((error = biowait(bp)) == 0 && bp->b_resid != 0)
                 error = EIO;                  error = SET_ERROR(EIO);
         freerbuf(bp);          freerbuf(bp);
   
         return (error);          return (error);
Line 296  vdev_disk_physio(ldi_handle_t vd_lh, cad
Line 645  vdev_disk_physio(ldi_handle_t vd_lh, cad
 static void  static void
 vdev_disk_io_intr(buf_t *bp)  vdev_disk_io_intr(buf_t *bp)
 {  {
         vdev_disk_buf_t *vdb = (vdev_disk_buf_t *)bp;          vdev_buf_t *vb = (vdev_buf_t *)bp;
         zio_t *zio = vdb->vdb_io;          zio_t *zio = vb->vb_io;
   
         /*          /*
          * The rest of the zio stack only deals with EIO, ECKSUM, and ENXIO.           * The rest of the zio stack only deals with EIO, ECKSUM, and ENXIO.
          * Rather than teach the rest of the stack about other error           * Rather than teach the rest of the stack about other error
          * possibilities (EFAULT, etc), we normalize the error value here.           * possibilities (EFAULT, etc), we normalize the error value here.
          */           */
         zio->io_error = (geterror(bp) != 0 ? EIO : 0);          zio->io_error = (geterror(bp) != 0 ? SET_ERROR(EIO) : 0);
   
         if (zio->io_error == 0 && bp->b_resid != 0)          if (zio->io_error == 0 && bp->b_resid != 0)
                 zio->io_error = EIO;                  zio->io_error = SET_ERROR(EIO);
   
         kmem_free(vdb, sizeof (vdev_disk_buf_t));          kmem_free(vb, sizeof (vdev_buf_t));
   
         zio_interrupt(zio);          zio_delay_interrupt(zio);
 }  }
   
 static void  static void
Line 335  vdev_disk_ioctl_done(void *zio_arg, int 
Line 684  vdev_disk_ioctl_done(void *zio_arg, int 
         zio_interrupt(zio);          zio_interrupt(zio);
 }  }
   
 static int  static void
 vdev_disk_io_start(zio_t *zio)  vdev_disk_io_start(zio_t *zio)
 {  {
         vdev_t *vd = zio->io_vd;          vdev_t *vd = zio->io_vd;
         vdev_disk_t *dvd = vd->vdev_tsd;          vdev_disk_t *dvd = vd->vdev_tsd;
         vdev_disk_buf_t *vdb;          vdev_buf_t *vb;
         struct dk_callback *dkc;          struct dk_callback *dkc;
         buf_t *bp;          buf_t *bp;
         int error;          int error;
   
           /*
            * If the vdev is closed, it's likely in the REMOVED or FAULTED state.
            * Nothing to be done here but return failure.
            */
           if (dvd == NULL || (dvd->vd_ldi_offline && dvd->vd_lh == NULL)) {
                   zio->io_error = SET_ERROR(ENXIO);
                   zio_interrupt(zio);
                   return;
           }
   
         if (zio->io_type == ZIO_TYPE_IOCTL) {          if (zio->io_type == ZIO_TYPE_IOCTL) {
                 /* XXPOLICY */                  /* XXPOLICY */
                 if (!vdev_readable(vd)) {                  if (!vdev_readable(vd)) {
                         zio->io_error = ENXIO;                          zio->io_error = SET_ERROR(ENXIO);
                         return (ZIO_PIPELINE_CONTINUE);                          zio_interrupt(zio);
                           return;
                 }                  }
   
                 switch (zio->io_cmd) {                  switch (zio->io_cmd) {
Line 360  vdev_disk_io_start(zio_t *zio)
Line 720  vdev_disk_io_start(zio_t *zio)
                                 break;                                  break;
   
                         if (vd->vdev_nowritecache) {                          if (vd->vdev_nowritecache) {
                                 zio->io_error = ENOTSUP;                                  zio->io_error = SET_ERROR(ENOTSUP);
                                 break;                                  break;
                         }                          }
   
Line 380  vdev_disk_io_start(zio_t *zio)
Line 740  vdev_disk_io_start(zio_t *zio)
                                  * and will call vdev_disk_ioctl_done()                                   * and will call vdev_disk_ioctl_done()
                                  * upon completion.                                   * upon completion.
                                  */                                   */
                                 return (ZIO_PIPELINE_STOP);                                  return;
                         }                          }
   
                         if (error == ENOTSUP || error == ENOTTY) {                          if (error == ENOTSUP || error == ENOTTY) {
Line 398  vdev_disk_io_start(zio_t *zio)
Line 758  vdev_disk_io_start(zio_t *zio)
                         break;                          break;
   
                 default:                  default:
                         zio->io_error = ENOTSUP;                          zio->io_error = SET_ERROR(ENOTSUP);
                 }                  }
   
                 return (ZIO_PIPELINE_CONTINUE);                  zio_execute(zio);
                   return;
         }          }
   
         vdb = kmem_alloc(sizeof (vdev_disk_buf_t), KM_SLEEP);          ASSERT(zio->io_type == ZIO_TYPE_READ || zio->io_type == ZIO_TYPE_WRITE);
           zio->io_target_timestamp = zio_handle_io_delay(zio);
   
           vb = kmem_alloc(sizeof (vdev_buf_t), KM_SLEEP);
   
         vdb->vdb_io = zio;          vb->vb_io = zio;
         bp = &vdb->vdb_buf;          bp = &vb->vb_buf;
   
         bioinit(bp);          bioinit(bp);
         bp->b_flags = B_BUSY | B_NOCACHE |          bp->b_flags = B_BUSY | B_NOCACHE |
Line 422  vdev_disk_io_start(zio_t *zio)
Line 786  vdev_disk_io_start(zio_t *zio)
   
         /* ldi_strategy() will return non-zero only on programming errors */          /* ldi_strategy() will return non-zero only on programming errors */
         VERIFY(ldi_strategy(dvd->vd_lh, bp) == 0);          VERIFY(ldi_strategy(dvd->vd_lh, bp) == 0);
   
         return (ZIO_PIPELINE_STOP);  
 }  }
   
 static void  static void
Line 452  vdev_disk_io_done(zio_t *zio)
Line 814  vdev_disk_io_done(zio_t *zio)
                         zfs_post_remove(zio->io_spa, vd);                          zfs_post_remove(zio->io_spa, vd);
                         vd->vdev_remove_wanted = B_TRUE;                          vd->vdev_remove_wanted = B_TRUE;
                         spa_async_request(zio->io_spa, SPA_ASYNC_REMOVE);                          spa_async_request(zio->io_spa, SPA_ASYNC_REMOVE);
                   } else if (!vd->vdev_delayed_close) {
                           vd->vdev_delayed_close = B_TRUE;
                 }                  }
         }          }
 }  }
Line 463  vdev_ops_t vdev_disk_ops = {
Line 827  vdev_ops_t vdev_disk_ops = {
         vdev_disk_io_start,          vdev_disk_io_start,
         vdev_disk_io_done,          vdev_disk_io_done,
         NULL,          NULL,
           vdev_disk_hold,
           vdev_disk_rele,
         VDEV_TYPE_DISK,         /* name of this vdev type */          VDEV_TYPE_DISK,         /* name of this vdev type */
         B_TRUE                  /* leaf vdev */          B_TRUE                  /* leaf vdev */
 };  };
Line 499  vdev_disk_read_rootlabel(char *devpath, 
Line 865  vdev_disk_read_rootlabel(char *devpath, 
   
         if (ldi_get_size(vd_lh, &s)) {          if (ldi_get_size(vd_lh, &s)) {
                 (void) ldi_close(vd_lh, FREAD, kcred);                  (void) ldi_close(vd_lh, FREAD, kcred);
                 return (EIO);                  return (SET_ERROR(EIO));
         }          }
   
         size = P2ALIGN_TYPED(s, sizeof (vdev_label_t), uint64_t);          size = P2ALIGN_TYPED(s, sizeof (vdev_label_t), uint64_t);
Line 511  vdev_disk_read_rootlabel(char *devpath, 
Line 877  vdev_disk_read_rootlabel(char *devpath, 
   
                 /* read vdev label */                  /* read vdev label */
                 offset = vdev_label_offset(size, l, 0);                  offset = vdev_label_offset(size, l, 0);
                 if (vdev_disk_physio(vd_lh, (caddr_t)label,                  if (vdev_disk_ldi_physio(vd_lh, (caddr_t)label,
                     VDEV_SKIP_SIZE + VDEV_PHYS_SIZE, offset, B_READ) != 0)                      VDEV_SKIP_SIZE + VDEV_PHYS_SIZE, offset, B_READ) != 0)
                         continue;                          continue;
   
Line 541  vdev_disk_read_rootlabel(char *devpath, 
Line 907  vdev_disk_read_rootlabel(char *devpath, 
         kmem_free(label, sizeof (vdev_label_t));          kmem_free(label, sizeof (vdev_label_t));
         (void) ldi_close(vd_lh, FREAD, kcred);          (void) ldi_close(vd_lh, FREAD, kcred);
         if (*config == NULL)          if (*config == NULL)
                 error = EIDRM;                  error = SET_ERROR(EIDRM);
   
         return (error);          return (error);
 }  }

Legend:
Removed from v.1.1.1.2  
changed lines
  Added in v.1.1.1.3

CVSweb <webmaster@jp.NetBSD.org>