MCPcopy Create free account
hub / github.com/F-Stack/f-stack / vdev_trim_change_state

Function vdev_trim_change_state

freebsd/contrib/openzfs/module/zfs/vdev_trim.c:268–357  ·  view source on GitHub ↗

* Update the on-disk state of a manual TRIM. This is called to request * that a TRIM be started/suspended/canceled, or to change one of the * TRIM options (partial, secure, rate). */

Source from the content-addressed store, hash-verified

266 * TRIM options (partial, secure, rate).
267 */
268static void
269vdev_trim_change_state(vdev_t *vd, vdev_trim_state_t new_state,
270 uint64_t rate, boolean_t partial, boolean_t secure)
271{
272 ASSERT(MUTEX_HELD(&vd->vdev_trim_lock));
273 spa_t *spa = vd->vdev_spa;
274
275 if (new_state == vd->vdev_trim_state)
276 return;
277
278 /*
279 * Copy the vd's guid, this will be freed by the sync task.
280 */
281 uint64_t *guid = kmem_zalloc(sizeof (uint64_t), KM_SLEEP);
282 *guid = vd->vdev_guid;
283
284 /*
285 * If we're suspending, then preserve the original start time.
286 */
287 if (vd->vdev_trim_state != VDEV_TRIM_SUSPENDED) {
288 vd->vdev_trim_action_time = gethrestime_sec();
289 }
290
291 /*
292 * If we're activating, then preserve the requested rate and trim
293 * method. Setting the last offset and rate to UINT64_MAX is used
294 * as a sentinel to indicate they should be reset to default values.
295 */
296 if (new_state == VDEV_TRIM_ACTIVE) {
297 if (vd->vdev_trim_state == VDEV_TRIM_COMPLETE ||
298 vd->vdev_trim_state == VDEV_TRIM_CANCELED) {
299 vd->vdev_trim_last_offset = UINT64_MAX;
300 vd->vdev_trim_rate = UINT64_MAX;
301 vd->vdev_trim_partial = UINT64_MAX;
302 vd->vdev_trim_secure = UINT64_MAX;
303 }
304
305 if (rate != 0)
306 vd->vdev_trim_rate = rate;
307
308 if (partial != 0)
309 vd->vdev_trim_partial = partial;
310
311 if (secure != 0)
312 vd->vdev_trim_secure = secure;
313 }
314
315 vdev_trim_state_t old_state = vd->vdev_trim_state;
316 boolean_t resumed = (old_state == VDEV_TRIM_SUSPENDED);
317 vd->vdev_trim_state = new_state;
318
319 dmu_tx_t *tx = dmu_tx_create_dd(spa_get_dsl(spa)->dp_mos_dir);
320 VERIFY0(dmu_tx_assign(tx, TXG_WAIT));
321 dsl_sync_task_nowait(spa_get_dsl(spa), vdev_trim_zap_update_sync,
322 guid, tx);
323
324 switch (new_state) {
325 case VDEV_TRIM_ACTIVE:

Callers 5

vdev_trim_threadFunction · 0.85
vdev_trimFunction · 0.85
vdev_trim_stopFunction · 0.85
vdev_trim_l2arc_threadFunction · 0.85
vdev_trim_l2arcFunction · 0.85

Calls 10

dmu_tx_create_ddFunction · 0.85
spa_get_dslFunction · 0.85
dmu_tx_assignFunction · 0.85
dsl_sync_task_nowaitFunction · 0.85
spa_event_notifyFunction · 0.85
spa_history_log_internalFunction · 0.85
dmu_tx_commitFunction · 0.85
spa_notify_waitersFunction · 0.85
gethrestime_secFunction · 0.50
panicFunction · 0.50

Tested by

no test coverage detected