1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2012 STRATO AG. All rights reserved.
24 */
25
26 #ifndef _SYS_FAR_IMPL_H
27 #define _SYS_FAR_IMPL_H
28
29 #include <sys/inttypes.h>
30 #include <sys/types.h>
31 #include <sys/cmn_err.h>
32 #include <sys/spa.h>
33 #include <sys/arc.h>
34 #include <sys/dsl_dataset.h>
35 #include <sys/dnode.h>
36 #include <sys/sa.h>
37 #include <sys/avl.h>
38 #include <sys/dmu_impl.h>
39
40 #define FAR_NO_INO 0
41
42 enum pass {
43 PASS_LINK,
44 PASS_UNLINK
45 };
46
47 typedef struct _far_count_elem {
48 avl_node_t fce_avl_node;
49 uint64_t fce_ino;
50 uint64_t fce_count;
51 uint64_t fce_aux;
52 } far_count_elem_t;
53
54 typedef struct _far_counter {
55 avl_tree_t fc_avl;
56 char *fc_name;
57 } far_counter_t;
58
59 typedef struct blklevel {
60 uint64_t bl_blk;
61 int bl_nslots;
62 blkptr_t *bl_bp;
63 arc_buf_t *bl_buf;
64 } blklevel_t;
65
66 typedef struct _far {
67 enum pass f_pass;
68 struct _far_ops *f_ops;
69 far_counter_t f_del_dir_cnt;
70 far_counter_t f_put_back_cnt;
71 far_counter_t f_link_add_cnt;
72 uint64_t f_current_ino;
73 struct _far_path *f_current_path;
74 int f_alloc_len;
75 uint8_t *f_buf;
76 int f_size;
77 struct vnode *f_vp; /* file to which we are reporting */
78 offset_t *f_offp;
79 int f_err; /* error that stopped diff search */
80 dsl_dataset_t *f_fromds;
81 dsl_dataset_t *f_tods;
82 objset_t *f_fromsnap;
83 objset_t *f_tosnap;
84 dnode_phys_t *f_dnp;
85 blklevel_t *f_bl;
86 blklevel_t *f_filebl;
87 uint64_t f_fromtxg;
88 sa_attr_type_t *f_from_sa_table;
89 sa_attr_type_t *f_to_sa_table;
90 uint64_t f_shares_dir;
91 dmu_sendarg_t f_dmu_sendarg;
92 } far_t;
93
94 typedef struct _far_ops {
95 int (*far_dir_add)(far_t *f, uint64_t ino);
96 int (*far_dir_del)(far_t *f, uint64_t ino);
97 int (*far_dir_mod)(far_t *f, uint64_t ino);
98 int (*far_dirent_add)(void *far_enump, char *name, uint64_t ino);
99 int (*far_dirent_del)(void *far_enump, char *name, uint64_t ino);
100 int (*far_dirent_mod)(void *far_enump, char *name,
101 uint64_t ino_old, uint64_t ino_new);
102 int (*far_dirent_unmod)(void *far_enump, char *name, uint64_t ino);
103 int (*far_file_add)(far_t *f, uint64_t ino);
104 int (*far_file_del)(far_t *f, uint64_t ino);
105 int (*far_file_mod)(far_t *f, uint64_t ino);
106 int (*far_file_data)(void *far_filep, void *data, uint64_t off,
107 uint64_t len);
108 } far_ops_t;
109
110 typedef struct _far_path {
111 struct _far_path *fp_next;
112 int fp_len;
113 int fp_total_len;
114 char fp_buf[0];
115 } far_path_t;
116
117 typedef struct _far_dirent {
118 char *fd_name;
119 uint64_t fd_parent_ino;
120 struct _far_dirent *fd_prev;
121 } far_dirent_t;
122
123 typedef enum _far_which {
124 FAR_UNDEF,
125 FAR_OLD,
126 FAR_NEW
127 } far_which_t;
128
129 typedef struct _far_time {
130 uint64_t st_sec;
131 uint64_t st_nsec;
132 } far_time_t;
133
134 #define FI_ATTR_ATIME (1 << 0)
135 #define FI_ATTR_MTIME (1 << 1)
136 #define FI_ATTR_CTIME (1 << 2)
137 #define FI_ATTR_OTIME (1 << 3)
138 #define FI_ATTR_MODE (1 << 4)
139 #define FI_ATTR_SIZE (1 << 5)
140 #define FI_ATTR_NENTRIES (1 << 5)
141 #define FI_ATTR_PARENT (1 << 6)
142 #define FI_ATTR_LINKS (1 << 7)
143 #define FI_ATTR_RDEV (1 << 8)
144 #define FI_ATTR_UID (1 << 9)
145 #define FI_ATTR_GID (1 << 10)
146 #define FI_ATTR_GEN (1 << 11)
147 /* XXX TODO xattr, acl, dacl */
148
149 #undef si_uid /* XXX defined in siginfo.h */
150 #undef si_gid /* XXX defined in siginfo.h */
151 typedef struct _far_info {
152 uint64_t si_nlinks;
153 uint64_t si_parent;
154 union {
155 uint64_t si_nentries;
156 uint64_t si_size;
157 };
158 far_time_t si_atime;
159 far_time_t si_mtime;
160 far_time_t si_ctime;
161 far_time_t si_otime;
162 uint64_t si_mode;
163 /* XXX TODO xattr */
164 uint64_t si_rdev;
165 uint64_t si_uid;
166 uint64_t si_gid;
167 uint64_t si_gen;
168 } far_info_t;
169
170 int far_start(far_t *f, far_ops_t **);
171 int far_start2(far_t *f, far_ops_t **);
172 int far_abort(far_t *f);
173 int far_end(far_t *f);
174
175 int far_dirent_add_file(far_t *f, far_dirent_t *dirent,
176 uint64_t ino, uint64_t mode, int exists);
177 void far_path_free(far_path_t *fp);
178
179 int far_get_info(far_t *f, uint64_t dnobj, far_which_t which,
180 far_info_t *sp, uint64_t flags);
181
182 typedef int (*far_file_cb_t)(void *ctx, void *data, int len);
183 int far_file_contents(far_t *f, uint64_t dnobj, void *ctx);
184 int far_dir_contents(far_t *f, uint64_t dnobj, void *ctx);
185 int far_find_entry(far_t *f, uint64_t dirobj, uint64_t dnobj,
186 far_which_t which, char **name);
187 void far_free_name(char *name);
188 int far_lookup_entry(far_t *f, uint64_t dirobj, char *name,
189 far_which_t which, uint64_t *dnobj);
190 int far_write(far_t *f, const uint8_t *data, int len);
191 int far_get_uuid(far_t *f, far_which_t which, uint8_t data[16]);
192 int far_get_ctransid(far_t *f, far_which_t which,
193 uint64_t *ctransid);
194 int far_get_snapname(far_t *f, far_which_t which,
195 char **name, int *len);
196 int far_read_symlink(far_t *f, uint64_t dnobj, far_which_t which,
197 char **target, int *plen);
198
199 int far_send_start(far_t *f);
200 int far_send_create_file(far_t *f, far_dirent_t *dirent, uint64_t ino,
201 int devise_tempname, far_path_t **path_ret);
202 int far_send_link(far_t *f, far_dirent_t *new_dirent, uint64_t ino,
203 uint64_t old_parent_ino, far_which_t which,
204 int devise_tempname);
205 int far_send_mkdir(far_t *f, far_dirent_t *dirent, uint64_t ino,
206 int devise_tempname);
207 int far_send_rename(far_t *f, far_dirent_t *dirent, uint64_t ino,
208 uint64_t old_parent_ino, int devise_tempname);
209 int far_send_rename_from_tempname(far_t *f, far_dirent_t *dirent,
210 uint64_t ino, uint64_t old);
211 int far_send_unlink(far_t *f, far_dirent_t *dirent, uint64_t ino);
212 int far_send_rmdir(far_t *f, far_dirent_t *dirent, uint64_t ino);
213 /* TODO: make **path *path or do we really still alloc it? */
214 int far_send_file_data(far_t *f,
215 far_path_t **path, far_dirent_t *dirent,
216 uint64_t ino, uint64_t off, uint64_t len, void *data);
217 int far_send_mtime_update(far_t *f, far_dirent_t *dirent, uint64_t ino);
218 int far_send_truncate(far_t *f, far_dirent_t *dirent, uint64_t ino,
219 uint64_t new_size);
220 int far_send_chown(far_t *f, far_dirent_t *dirent, uint64_t ino,
221 uint64_t new_uid, uint64_t new_gid);
222 int far_send_chmod(far_t *f, far_dirent_t *dirent, uint64_t ino,
223 uint64_t new_mode);
224 int far_send_end(far_t *f);
225 int far_count_init(far_counter_t *fc, char *name);
226 void far_count_destroy(far_counter_t *fc);
227 int far_add_count(far_counter_t *fc, uint64_t ino, uint64_t inc,
228 uint64_t aux, uint64_t *new_count, uint64_t *old_aux);
229 void far_free_count(far_counter_t *fc, uint64_t ino);
230 int far_get_count(far_counter_t *fc, uint64_t ino, uint64_t *new_count,
231 uint64_t *old_aux);
232 int far_count_fini(far_counter_t *fc);
233
234 void far_send_init(far_t *f);
235 void far_send_fini(far_t *f);
236
237 #endif /* _SYS_FAR_IMPL_H */