usr/src/uts/common/fs/zfs/zio.c
changeset 6523 c1d2a7f04573
parent 6245 1a2a7cfb9f26
child 6976 cae5f06df471
equal deleted inserted replaced
6522:26439431f254 6523:c1d2a7f04573
   794 /*
   794 /*
   795  * ==========================================================================
   795  * ==========================================================================
   796  * Initiate I/O, either sync or async
   796  * Initiate I/O, either sync or async
   797  * ==========================================================================
   797  * ==========================================================================
   798  */
   798  */
       
   799 static void
       
   800 zio_destroy(zio_t *zio)
       
   801 {
       
   802 	mutex_destroy(&zio->io_lock);
       
   803 	cv_destroy(&zio->io_cv);
       
   804 	if (zio->io_failed_vds != NULL) {
       
   805 		kmem_free(zio->io_failed_vds,
       
   806 		    zio->io_failed_vds_count * sizeof (vdev_t *));
       
   807 		zio->io_failed_vds = NULL;
       
   808 		zio->io_failed_vds_count = 0;
       
   809 	}
       
   810 	kmem_cache_free(zio_cache, zio);
       
   811 }
       
   812 
   799 int
   813 int
   800 zio_wait(zio_t *zio)
   814 zio_wait(zio_t *zio)
   801 {
   815 {
   802 	int error;
   816 	int error;
   803 
   817 
   811 	while (zio->io_stalled != ZIO_STAGE_DONE)
   825 	while (zio->io_stalled != ZIO_STAGE_DONE)
   812 		cv_wait(&zio->io_cv, &zio->io_lock);
   826 		cv_wait(&zio->io_cv, &zio->io_lock);
   813 	mutex_exit(&zio->io_lock);
   827 	mutex_exit(&zio->io_lock);
   814 
   828 
   815 	error = zio->io_error;
   829 	error = zio->io_error;
   816 	mutex_destroy(&zio->io_lock);
   830 	zio_destroy(zio);
   817 	cv_destroy(&zio->io_cv);
       
   818 	kmem_cache_free(zio_cache, zio);
       
   819 
   831 
   820 	return (error);
   832 	return (error);
   821 }
   833 }
   822 
   834 
   823 void
   835 void
   862 
   874 
   863 	return (rv);
   875 	return (rv);
   864 }
   876 }
   865 
   877 
   866 static void
   878 static void
       
   879 zio_add_failed_vdev(zio_t *pio, zio_t *zio)
       
   880 {
       
   881 	uint64_t oldcount = pio->io_failed_vds_count;
       
   882 	vdev_t **new_vds;
       
   883 	int i;
       
   884 
       
   885 	ASSERT(MUTEX_HELD(&pio->io_lock));
       
   886 
       
   887 	if (zio->io_vd == NULL)
       
   888 		return;
       
   889 
       
   890 	for (i = 0; i < oldcount; i++) {
       
   891 		if (pio->io_failed_vds[i] == zio->io_vd)
       
   892 			return;
       
   893 	}
       
   894 
       
   895 	new_vds = kmem_zalloc((oldcount + 1) * sizeof (vdev_t *), KM_SLEEP);
       
   896 	if (pio->io_failed_vds != NULL) {
       
   897 		bcopy(pio->io_failed_vds, new_vds,
       
   898 		    oldcount * sizeof (vdev_t *));
       
   899 		kmem_free(pio->io_failed_vds, oldcount * sizeof (vdev_t *));
       
   900 	}
       
   901 	pio->io_failed_vds = new_vds;
       
   902 	pio->io_failed_vds[oldcount] = zio->io_vd;
       
   903 	pio->io_failed_vds_count++;
       
   904 }
       
   905 
       
   906 static void
   867 zio_notify_parent(zio_t *zio, uint32_t stage, uint64_t *countp)
   907 zio_notify_parent(zio_t *zio, uint32_t stage, uint64_t *countp)
   868 {
   908 {
   869 	zio_t *pio = zio->io_parent;
   909 	zio_t *pio = zio->io_parent;
   870 
   910 
   871 	mutex_enter(&pio->io_lock);
   911 	mutex_enter(&pio->io_lock);
   872 	if (pio->io_error == 0 && !(zio->io_flags & ZIO_FLAG_DONT_PROPAGATE))
   912 	if (pio->io_error == 0 && !(zio->io_flags & ZIO_FLAG_DONT_PROPAGATE)) {
   873 		pio->io_error = zio->io_error;
   913 		pio->io_error = zio->io_error;
       
   914 		if (zio->io_error && zio->io_error != ENOTSUP)
       
   915 			zio_add_failed_vdev(pio, zio);
       
   916 	}
   874 	ASSERT3U(*countp, >, 0);
   917 	ASSERT3U(*countp, >, 0);
   875 	if (--*countp == 0 && pio->io_stalled == stage) {
   918 	if (--*countp == 0 && pio->io_stalled == stage) {
   876 		pio->io_stalled = 0;
   919 		pio->io_stalled = 0;
   877 		mutex_exit(&pio->io_lock);
   920 		mutex_exit(&pio->io_lock);
   878 		zio_execute(pio);
   921 		zio_execute(pio);
  1079 	cv_broadcast(&spa->spa_zio_cv);
  1122 	cv_broadcast(&spa->spa_zio_cv);
  1080 #endif
  1123 #endif
  1081 	mutex_exit(&spa->spa_zio_lock);
  1124 	mutex_exit(&spa->spa_zio_lock);
  1082 
  1125 
  1083 	return (ZIO_PIPELINE_STOP);
  1126 	return (ZIO_PIPELINE_STOP);
       
  1127 }
       
  1128 
       
  1129 static void
       
  1130 zio_handle_io_failure(zio_t *zio, vdev_t *vd)
       
  1131 {
       
  1132 	spa_t *spa = zio->io_spa;
       
  1133 	blkptr_t *bp = zio->io_bp;
       
  1134 	char *blkbuf;
       
  1135 
       
  1136 #ifdef ZFS_DEBUG
       
  1137 	blkbuf = kmem_alloc(BP_SPRINTF_LEN, KM_NOSLEEP);
       
  1138 	if (blkbuf) {
       
  1139 		sprintf_blkptr(blkbuf, BP_SPRINTF_LEN,
       
  1140 		    bp ? bp : &zio->io_bp_copy);
       
  1141 	}
       
  1142 	cmn_err(CE_WARN, "ZFS: %s (%s on %s off %llx: zio %p %s): error %d",
       
  1143 	    zio->io_error == ECKSUM ? "bad checksum" : "I/O failure",
       
  1144 	    zio_type_name[zio->io_type], vdev_description(vd),
       
  1145 	    (u_longlong_t)zio->io_offset, (void *)zio,
       
  1146 	    blkbuf ? blkbuf : "", zio->io_error);
       
  1147 	if (blkbuf)
       
  1148 		kmem_free(blkbuf, BP_SPRINTF_LEN);
       
  1149 #endif
       
  1150 
       
  1151 	if (spa_get_failmode(spa) == ZIO_FAILURE_MODE_PANIC) {
       
  1152 		fm_panic("Pool '%s' has encountered an uncorrectable I/O "
       
  1153 		    "failure and the failure mode property for this pool "
       
  1154 		    "is set to panic.", spa_name(spa));
       
  1155 	}
       
  1156 	zfs_ereport_post(FM_EREPORT_ZFS_IO_FAILURE, spa, NULL, NULL, 0, 0);
       
  1157 	vdev_set_state(vd, vd == spa->spa_root_vdev ? B_TRUE : B_FALSE,
       
  1158 	    VDEV_STATE_FAULTED, VDEV_AUX_IO_FAILURE);
  1084 }
  1159 }
  1085 
  1160 
  1086 static int
  1161 static int
  1087 zio_assess(zio_t *zio)
  1162 zio_assess(zio_t *zio)
  1088 {
  1163 {
  1162 		 *
  1237 		 *
  1163 		 * XXX - Need to differentiate between an ENOSPC as
  1238 		 * XXX - Need to differentiate between an ENOSPC as
  1164 		 * a result of vdev failures vs. a full pool.
  1239 		 * a result of vdev failures vs. a full pool.
  1165 		 */
  1240 		 */
  1166 		if (!(zio->io_flags & ZIO_FLAG_CANFAIL)) {
  1241 		if (!(zio->io_flags & ZIO_FLAG_CANFAIL)) {
  1167 			char *blkbuf;
  1242 			int i;
  1168 
  1243 
  1169 #ifdef ZFS_DEBUG
  1244 			for (i = 0; i < zio->io_failed_vds_count; i++) {
  1170 			blkbuf = kmem_alloc(BP_SPRINTF_LEN, KM_NOSLEEP);
  1245 				zio_handle_io_failure(zio,
  1171 			if (blkbuf) {
  1246 				    zio->io_failed_vds[i]);
  1172 				sprintf_blkptr(blkbuf, BP_SPRINTF_LEN,
       
  1173 				    bp ? bp : &zio->io_bp_copy);
       
  1174 			}
  1247 			}
  1175 			cmn_err(CE_WARN, "ZFS: %s (%s on %s off %llx: zio %p "
  1248 			if (zio->io_failed_vds_count == 0) {
  1176 			    "%s): error %d", zio->io_error == ECKSUM ?
  1249 				zio_handle_io_failure(zio,
  1177 			    "bad checksum" : "I/O failure",
  1250 				    vd ? vd : spa->spa_root_vdev);
  1178 			    zio_type_name[zio->io_type],
       
  1179 			    vdev_description(vd),
       
  1180 			    (u_longlong_t)zio->io_offset,
       
  1181 			    (void *)zio, blkbuf ? blkbuf : "", zio->io_error);
       
  1182 #endif
       
  1183 
       
  1184 			if (spa_get_failmode(spa) == ZIO_FAILURE_MODE_PANIC) {
       
  1185 				fm_panic("Pool '%s' has encountered an "
       
  1186 				    "uncorrectable I/O failure and the "
       
  1187 				    "failure mode property for this pool "
       
  1188 				    "is set to panic.", spa_name(spa));
       
  1189 			}
  1251 			}
  1190 			cmn_err(CE_WARN, "Pool '%s' has encountered "
  1252 			if (zio->io_failed_vds != NULL) {
  1191 			    "an uncorrectable I/O error. "
  1253 				kmem_free(zio->io_failed_vds,
  1192 			    "Manual intervention is required.", spa_name(spa));
  1254 				    zio->io_failed_vds_count *
       
  1255 				    sizeof (vdev_t *));
       
  1256 				zio->io_failed_vds = NULL;
       
  1257 				zio->io_failed_vds_count = 0;
       
  1258 			}
  1193 			return (zio_vdev_suspend_io(zio));
  1259 			return (zio_vdev_suspend_io(zio));
  1194 		}
  1260 		}
  1195 	}
  1261 	}
  1196 	ASSERT(!(zio->io_flags & ZIO_FLAG_WRITE_RETRY));
  1262 	ASSERT(!(zio->io_flags & ZIO_FLAG_WRITE_RETRY));
  1197 	ASSERT(zio->io_children_notready == 0);
  1263 	ASSERT(zio->io_children_notready == 0);
  1246 		ASSERT(zio->io_stage == ZIO_STAGE_DONE);
  1312 		ASSERT(zio->io_stage == ZIO_STAGE_DONE);
  1247 		zio->io_stalled = zio->io_stage;
  1313 		zio->io_stalled = zio->io_stage;
  1248 		cv_broadcast(&zio->io_cv);
  1314 		cv_broadcast(&zio->io_cv);
  1249 		mutex_exit(&zio->io_lock);
  1315 		mutex_exit(&zio->io_lock);
  1250 	} else {
  1316 	} else {
  1251 		mutex_destroy(&zio->io_lock);
  1317 		zio_destroy(zio);
  1252 		cv_destroy(&zio->io_cv);
       
  1253 		kmem_cache_free(zio_cache, zio);
       
  1254 	}
  1318 	}
  1255 
  1319 
  1256 	return (ZIO_PIPELINE_STOP);
  1320 	return (ZIO_PIPELINE_STOP);
  1257 }
  1321 }
  1258 
  1322