xref: /freebsd/sys/contrib/openzfs/include/sys/dmu_recv.h (revision 22649d4dba730d46244fd2dff4fd174903c8379f)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * This file and its contents are supplied under the terms of the
4  * Common Development and Distribution License ("CDDL"), version 1.0.
5  * You may only use this file in accordance with the terms of version
6  * 1.0 of the CDDL.
7  *
8  * A full copy of the text of the CDDL should have accompanied this
9  * source.  A copy of the CDDL is also available via the Internet at
10  * https://opensource.org/license/CDDL-1.0.
11  */
12 
13 /*
14  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
15  * Copyright (c) 2012, 2020 by Delphix. All rights reserved.
16  * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
17  * Copyright (c) 2013, Joyent, Inc. All rights reserved.
18  * Copyright (c) 2019 Datto Inc.
19  */
20 
21 #ifndef _DMU_RECV_H
22 #define	_DMU_RECV_H
23 
24 #include <sys/inttypes.h>
25 #include <sys/types.h>
26 #include <sys/dsl_bookmark.h>
27 #include <sys/dsl_dataset.h>
28 #include <sys/spa.h>
29 #include <sys/objlist.h>
30 #include <sys/zfs_ioctl.h>
31 
32 extern const char *const recv_clone_name;
33 
34 typedef struct dmu_recv_cookie {
35 	struct dsl_dataset *drc_ds;
36 	struct dmu_replay_record *drc_drr_begin;
37 	struct drr_begin *drc_drrb;
38 	const char *drc_tofs;
39 	const char *drc_tosnap;
40 	boolean_t drc_newfs;
41 	boolean_t drc_byteswap;
42 	uint64_t drc_featureflags;
43 	boolean_t drc_force;
44 	boolean_t drc_heal;
45 	boolean_t drc_resumable;
46 	boolean_t drc_should_save;
47 	boolean_t drc_raw;
48 	boolean_t drc_clone;
49 	boolean_t drc_spill;
50 	/* This non-raw incremental diverges the ivset of a raw lineage. */
51 	boolean_t drc_ivset_diverged;
52 	nvlist_t *drc_keynvl;
53 	uint64_t drc_fromsnapobj;
54 	uint64_t drc_ivset_guid;
55 	void *drc_owner;
56 	cred_t *drc_cred;
57 	nvlist_t *drc_begin_nvl;
58 	nvlist_t *drc_errors;
59 
60 	objset_t *drc_os;
61 	zfs_file_t *drc_fp; /* The file to read the stream from */
62 	uint64_t drc_voff; /* The current offset in the stream */
63 	uint64_t drc_bytes_read;
64 	/*
65 	 * A record that has had its payload read in, but hasn't yet been handed
66 	 * off to the worker thread.
67 	 */
68 	struct receive_record_arg *drc_rrd;
69 	/* A record that has had its header read in, but not its payload. */
70 	struct receive_record_arg *drc_next_rrd;
71 	zio_cksum_t drc_cksum;
72 	zio_cksum_t drc_prev_cksum;
73 	/* Sorted list of objects not to issue prefetches for. */
74 	objlist_t *drc_ignore_objlist;
75 } dmu_recv_cookie_t;
76 
77 int dmu_recv_begin(const char *, const char *, dmu_replay_record_t *,
78     boolean_t, boolean_t, boolean_t, nvlist_t *, nvlist_t *, const char *,
79     dmu_recv_cookie_t *, zfs_file_t *, offset_t *);
80 int dmu_recv_stream(dmu_recv_cookie_t *, offset_t *);
81 int dmu_recv_end(dmu_recv_cookie_t *, void *);
82 boolean_t dmu_objset_is_receiving(objset_t *);
83 
84 /*
85  * Receive stream record validators.  spa may be NULL to validate against the
86  * largest supported pool limits (for userland tools such as zstream).  errbuf
87  * is optional; when provided it receives a short description on failure.
88  *
89  * Size fields that exceed a pool or on-wire maximum return ERANGE; other
90  * malformed or inconsistent records return EINVAL.  Callers of lzc_receive*
91  * may therefore observe ERANGE where older OpenZFS modules returned EINVAL
92  * for the same oversized record.
93  */
94 #define	RECV_CHECK_ERRBUFLEN	256
95 
96 int recv_check_drr_object(const struct drr_object *, spa_t *, boolean_t raw,
97     boolean_t spill, uint64_t featureflags, char *errbuf, size_t errbuflen);
98 int recv_check_drr_free(const struct drr_free *, char *errbuf,
99     size_t errbuflen);
100 int recv_check_drr_freeobjects(const struct drr_freeobjects *, char *errbuf,
101     size_t errbuflen);
102 int recv_check_drr_object_range(const struct drr_object_range *, boolean_t raw,
103     char *errbuf, size_t errbuflen);
104 int recv_check_drr_spill(const struct drr_spill *, spa_t *, boolean_t raw,
105     uint64_t featureflags, char *errbuf, size_t errbuflen);
106 int recv_check_drr_write(const struct drr_write *, spa_t *, boolean_t raw,
107     uint64_t featureflags, char *errbuf, size_t errbuflen);
108 int recv_check_drr_write_embedded(const struct drr_write_embedded *, spa_t *,
109     boolean_t raw, uint64_t featureflags, char *errbuf, size_t errbuflen);
110 
111 #endif /* _DMU_RECV_H */
112