15cabbc6Prashanth Sreenivasa/*
25cabbc6Prashanth Sreenivasa * CDDL HEADER START
35cabbc6Prashanth Sreenivasa *
45cabbc6Prashanth Sreenivasa * This file and its contents are supplied under the terms of the
55cabbc6Prashanth Sreenivasa * Common Development and Distribution License ("CDDL"), version 1.0.
65cabbc6Prashanth Sreenivasa * You may only use this file in accordance with the terms of version
75cabbc6Prashanth Sreenivasa * 1.0 of the CDDL.
85cabbc6Prashanth Sreenivasa *
95cabbc6Prashanth Sreenivasa * A full copy of the text of the CDDL should have accompanied this
105cabbc6Prashanth Sreenivasa * source.  A copy of the CDDL is also available via the Internet at
115cabbc6Prashanth Sreenivasa * http://www.illumos.org/license/CDDL.
125cabbc6Prashanth Sreenivasa *
135cabbc6Prashanth Sreenivasa * CDDL HEADER END
145cabbc6Prashanth Sreenivasa */
155cabbc6Prashanth Sreenivasa
165cabbc6Prashanth Sreenivasa/*
178671400Serapheim Dimitropoulos * Copyright (c) 2014, 2017 by Delphix. All rights reserved.
185cabbc6Prashanth Sreenivasa */
195cabbc6Prashanth Sreenivasa
205cabbc6Prashanth Sreenivasa#ifndef _SYS_VDEV_REMOVAL_H
215cabbc6Prashanth Sreenivasa#define	_SYS_VDEV_REMOVAL_H
225cabbc6Prashanth Sreenivasa
235cabbc6Prashanth Sreenivasa#include <sys/spa.h>
245cabbc6Prashanth Sreenivasa#include <sys/bpobj.h>
255cabbc6Prashanth Sreenivasa#include <sys/vdev_indirect_mapping.h>
265cabbc6Prashanth Sreenivasa#include <sys/vdev_indirect_births.h>
275cabbc6Prashanth Sreenivasa
285cabbc6Prashanth Sreenivasa#ifdef	__cplusplus
295cabbc6Prashanth Sreenivasaextern "C" {
305cabbc6Prashanth Sreenivasa#endif
315cabbc6Prashanth Sreenivasa
325cabbc6Prashanth Sreenivasatypedef struct spa_vdev_removal {
333a4b1beMatthew Ahrens	uint64_t	svr_vdev_id;
345cabbc6Prashanth Sreenivasa	uint64_t	svr_max_offset_to_sync[TXG_SIZE];
355cabbc6Prashanth Sreenivasa	/* Thread performing a vdev removal. */
365cabbc6Prashanth Sreenivasa	kthread_t	*svr_thread;
375cabbc6Prashanth Sreenivasa	/* Segments left to copy from the current metaslab. */
385cabbc6Prashanth Sreenivasa	range_tree_t	*svr_allocd_segs;
395cabbc6Prashanth Sreenivasa	kmutex_t	svr_lock;
405cabbc6Prashanth Sreenivasa	kcondvar_t	svr_cv;
415cabbc6Prashanth Sreenivasa	boolean_t	svr_thread_exit;
425cabbc6Prashanth Sreenivasa
435cabbc6Prashanth Sreenivasa	/*
445cabbc6Prashanth Sreenivasa	 * New mappings to write out each txg.
455cabbc6Prashanth Sreenivasa	 */
465cabbc6Prashanth Sreenivasa	list_t		svr_new_segments[TXG_SIZE];
475cabbc6Prashanth Sreenivasa
485cabbc6Prashanth Sreenivasa	/*
495cabbc6Prashanth Sreenivasa	 * Ranges that were freed while a mapping was in flight.  This is
505cabbc6Prashanth Sreenivasa	 * a subset of the ranges covered by vdev_im_new_segments.
515cabbc6Prashanth Sreenivasa	 */
525cabbc6Prashanth Sreenivasa	range_tree_t	*svr_frees[TXG_SIZE];
535cabbc6Prashanth Sreenivasa
545cabbc6Prashanth Sreenivasa	/*
555cabbc6Prashanth Sreenivasa	 * Number of bytes which we have finished our work for
565cabbc6Prashanth Sreenivasa	 * in each txg.  This could be data copied (which will be part of
575cabbc6Prashanth Sreenivasa	 * the mappings in vdev_im_new_segments), or data freed before
585cabbc6Prashanth Sreenivasa	 * we got around to copying it.
595cabbc6Prashanth Sreenivasa	 */
605cabbc6Prashanth Sreenivasa	uint64_t	svr_bytes_done[TXG_SIZE];
615cabbc6Prashanth Sreenivasa
625cabbc6Prashanth Sreenivasa	/* List of leaf zap objects to be unlinked */
635cabbc6Prashanth Sreenivasa	nvlist_t	*svr_zaplist;
645cabbc6Prashanth Sreenivasa} spa_vdev_removal_t;
655cabbc6Prashanth Sreenivasa
665cabbc6Prashanth Sreenivasatypedef struct spa_condensing_indirect {
675cabbc6Prashanth Sreenivasa	/*
685cabbc6Prashanth Sreenivasa	 * New mappings to write out each txg.
695cabbc6Prashanth Sreenivasa	 */
705cabbc6Prashanth Sreenivasa	list_t		sci_new_mapping_entries[TXG_SIZE];
715cabbc6Prashanth Sreenivasa
725cabbc6Prashanth Sreenivasa	vdev_indirect_mapping_t *sci_new_mapping;
735cabbc6Prashanth Sreenivasa} spa_condensing_indirect_t;
745cabbc6Prashanth Sreenivasa
755cabbc6Prashanth Sreenivasaextern int spa_remove_init(spa_t *);
765cabbc6Prashanth Sreenivasaextern void spa_restart_removal(spa_t *);
775cabbc6Prashanth Sreenivasaextern int spa_condense_init(spa_t *);
785cabbc6Prashanth Sreenivasaextern void spa_condense_fini(spa_t *);
79667ec66Serapheim Dimitropoulosextern void spa_start_indirect_condensing_thread(spa_t *);
805cabbc6Prashanth Sreenivasaextern void spa_vdev_condense_suspend(spa_t *);
815cabbc6Prashanth Sreenivasaextern int spa_vdev_remove(spa_t *, uint64_t, boolean_t);
828671400Serapheim Dimitropoulosextern void free_from_removing_vdev(vdev_t *, uint64_t, uint64_t);
835cabbc6Prashanth Sreenivasaextern int spa_removal_get_stats(spa_t *, pool_removal_stat_t *);
845cabbc6Prashanth Sreenivasaextern void svr_sync(spa_t *spa, dmu_tx_t *tx);
855cabbc6Prashanth Sreenivasaextern void spa_vdev_remove_suspend(spa_t *);
865cabbc6Prashanth Sreenivasaextern int spa_vdev_remove_cancel(spa_t *);
875cabbc6Prashanth Sreenivasaextern void spa_vdev_removal_destroy(spa_vdev_removal_t *svr);
885cabbc6Prashanth Sreenivasa
89cfd63e1Matthew Ahrensextern int vdev_removal_max_span;
90cfd63e1Matthew Ahrensextern int zfs_remove_max_segment;
91cfd63e1Matthew Ahrens
925cabbc6Prashanth Sreenivasa#ifdef	__cplusplus
935cabbc6Prashanth Sreenivasa}
945cabbc6Prashanth Sreenivasa#endif
955cabbc6Prashanth Sreenivasa
965cabbc6Prashanth Sreenivasa#endif	/* _SYS_VDEV_REMOVAL_H */
97