author | Mark Shellenbaum <Mark.Shellenbaum@Sun.COM> |
Tue, 16 Mar 2010 09:43:38 -0600 | |
changeset 11935 | 538c866aaac6 |
parent 11834 | 4a7103a82983 |
child 11976 | 3791e5495b0d |
permissions | -rw-r--r-- |
5367 | 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 |
/* |
|
11461
5113530c9d30
PSARC 2009/663 zfs receive -e
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11381
diff
changeset
|
23 |
* Copyright 2010 Sun Microsystems, Inc. All rights reserved. |
5367 | 24 |
* Use is subject to license terms. |
25 |
*/ |
|
26 |
||
27 |
#include <assert.h> |
|
28 |
#include <ctype.h> |
|
29 |
#include <errno.h> |
|
30 |
#include <libintl.h> |
|
31 |
#include <stdio.h> |
|
32 |
#include <stdlib.h> |
|
33 |
#include <strings.h> |
|
34 |
#include <unistd.h> |
|
35 |
#include <stddef.h> |
|
36 |
#include <fcntl.h> |
|
37 |
#include <sys/mount.h> |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
38 |
#include <pthread.h> |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
39 |
#include <umem.h> |
5367 | 40 |
|
41 |
#include <libzfs.h> |
|
42 |
||
43 |
#include "zfs_namecheck.h" |
|
44 |
#include "zfs_prop.h" |
|
10602
21d184667b7e
6399128 want tool to examine backup files (zstreamdump)
Lori Alt <Lori.Alt@Sun.COM>
parents:
10588
diff
changeset
|
45 |
#include "zfs_fletcher.h" |
5367 | 46 |
#include "libzfs_impl.h" |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
47 |
#include <sha2.h> |
11381
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
48 |
#include <sys/zio_checksum.h> |
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
49 |
#include <sys/ddt.h> |
5367 | 50 |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
51 |
/* in libzfs_dataset.c */ |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
52 |
extern void zfs_setprop_error(libzfs_handle_t *, zfs_prop_t, int, char *); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
53 |
|
7366
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
54 |
static int zfs_receive_impl(libzfs_handle_t *, const char *, recvflags_t, |
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
55 |
int, const char *, nvlist_t *, avl_tree_t *, char **); |
7366
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
56 |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
57 |
static const zio_cksum_t zero_cksum = { 0 }; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
58 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
59 |
typedef struct dedup_arg { |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
60 |
int inputfd; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
61 |
int outputfd; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
62 |
libzfs_handle_t *dedup_hdl; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
63 |
} dedup_arg_t; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
64 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
65 |
typedef struct dataref { |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
66 |
uint64_t ref_guid; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
67 |
uint64_t ref_object; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
68 |
uint64_t ref_offset; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
69 |
} dataref_t; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
70 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
71 |
typedef struct dedup_entry { |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
72 |
struct dedup_entry *dde_next; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
73 |
zio_cksum_t dde_chksum; |
11381
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
74 |
uint64_t dde_prop; |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
75 |
dataref_t dde_ref; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
76 |
} dedup_entry_t; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
77 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
78 |
#define MAX_DDT_PHYSMEM_PERCENT 20 |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
79 |
#define SMALLEST_POSSIBLE_MAX_DDT_MB 128 |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
80 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
81 |
typedef struct dedup_table { |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
82 |
dedup_entry_t **dedup_hash_array; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
83 |
umem_cache_t *ddecache; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
84 |
uint64_t max_ddt_size; /* max dedup table size in bytes */ |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
85 |
uint64_t cur_ddt_size; /* current dedup table size in bytes */ |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
86 |
uint64_t ddt_count; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
87 |
int numhashbits; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
88 |
boolean_t ddt_full; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
89 |
} dedup_table_t; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
90 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
91 |
static int |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
92 |
high_order_bit(uint64_t n) |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
93 |
{ |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
94 |
int count; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
95 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
96 |
for (count = 0; n != 0; count++) |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
97 |
n >>= 1; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
98 |
return (count); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
99 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
100 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
101 |
static size_t |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
102 |
ssread(void *buf, size_t len, FILE *stream) |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
103 |
{ |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
104 |
size_t outlen; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
105 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
106 |
if ((outlen = fread(buf, len, 1, stream)) == 0) |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
107 |
return (0); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
108 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
109 |
return (outlen); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
110 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
111 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
112 |
static void |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
113 |
ddt_hash_append(libzfs_handle_t *hdl, dedup_table_t *ddt, dedup_entry_t **ddepp, |
11381
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
114 |
zio_cksum_t *cs, uint64_t prop, dataref_t *dr) |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
115 |
{ |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
116 |
dedup_entry_t *dde; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
117 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
118 |
if (ddt->cur_ddt_size >= ddt->max_ddt_size) { |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
119 |
if (ddt->ddt_full == B_FALSE) { |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
120 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
121 |
"Dedup table full. Deduplication will continue " |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
122 |
"with existing table entries")); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
123 |
ddt->ddt_full = B_TRUE; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
124 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
125 |
return; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
126 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
127 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
128 |
if ((dde = umem_cache_alloc(ddt->ddecache, UMEM_DEFAULT)) |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
129 |
!= NULL) { |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
130 |
assert(*ddepp == NULL); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
131 |
dde->dde_next = NULL; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
132 |
dde->dde_chksum = *cs; |
11381
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
133 |
dde->dde_prop = prop; |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
134 |
dde->dde_ref = *dr; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
135 |
*ddepp = dde; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
136 |
ddt->cur_ddt_size += sizeof (dedup_entry_t); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
137 |
ddt->ddt_count++; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
138 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
139 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
140 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
141 |
/* |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
142 |
* Using the specified dedup table, do a lookup for an entry with |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
143 |
* the checksum cs. If found, return the block's reference info |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
144 |
* in *dr. Otherwise, insert a new entry in the dedup table, using |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
145 |
* the reference information specified by *dr. |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
146 |
* |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
147 |
* return value: true - entry was found |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
148 |
* false - entry was not found |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
149 |
*/ |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
150 |
static boolean_t |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
151 |
ddt_update(libzfs_handle_t *hdl, dedup_table_t *ddt, zio_cksum_t *cs, |
11381
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
152 |
uint64_t prop, dataref_t *dr) |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
153 |
{ |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
154 |
uint32_t hashcode; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
155 |
dedup_entry_t **ddepp; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
156 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
157 |
hashcode = BF64_GET(cs->zc_word[0], 0, ddt->numhashbits); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
158 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
159 |
for (ddepp = &(ddt->dedup_hash_array[hashcode]); *ddepp != NULL; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
160 |
ddepp = &((*ddepp)->dde_next)) { |
11381
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
161 |
if (ZIO_CHECKSUM_EQUAL(((*ddepp)->dde_chksum), *cs) && |
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
162 |
(*ddepp)->dde_prop == prop) { |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
163 |
*dr = (*ddepp)->dde_ref; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
164 |
return (B_TRUE); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
165 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
166 |
} |
11381
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
167 |
ddt_hash_append(hdl, ddt, ddepp, cs, prop, dr); |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
168 |
return (B_FALSE); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
169 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
170 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
171 |
static int |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
172 |
cksum_and_write(const void *buf, uint64_t len, zio_cksum_t *zc, int outfd) |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
173 |
{ |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
174 |
fletcher_4_incremental_native(buf, len, zc); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
175 |
return (write(outfd, buf, len)); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
176 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
177 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
178 |
/* |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
179 |
* This function is started in a separate thread when the dedup option |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
180 |
* has been requested. The main send thread determines the list of |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
181 |
* snapshots to be included in the send stream and makes the ioctl calls |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
182 |
* for each one. But instead of having the ioctl send the output to the |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
183 |
* the output fd specified by the caller of zfs_send()), the |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
184 |
* ioctl is told to direct the output to a pipe, which is read by the |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
185 |
* alternate thread running THIS function. This function does the |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
186 |
* dedup'ing by: |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
187 |
* 1. building a dedup table (the DDT) |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
188 |
* 2. doing checksums on each data block and inserting a record in the DDT |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
189 |
* 3. looking for matching checksums, and |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
190 |
* 4. sending a DRR_WRITE_BYREF record instead of a write record whenever |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
191 |
* a duplicate block is found. |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
192 |
* The output of this function then goes to the output fd requested |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
193 |
* by the caller of zfs_send(). |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
194 |
*/ |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
195 |
static void * |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
196 |
cksummer(void *arg) |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
197 |
{ |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
198 |
dedup_arg_t *dda = arg; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
199 |
char *buf = malloc(1<<20); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
200 |
dmu_replay_record_t thedrr; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
201 |
dmu_replay_record_t *drr = &thedrr; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
202 |
struct drr_begin *drrb = &thedrr.drr_u.drr_begin; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
203 |
struct drr_end *drre = &thedrr.drr_u.drr_end; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
204 |
struct drr_object *drro = &thedrr.drr_u.drr_object; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
205 |
struct drr_write *drrw = &thedrr.drr_u.drr_write; |
11935
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
206 |
struct drr_spill *drrs = &thedrr.drr_u.drr_spill; |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
207 |
FILE *ofp; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
208 |
int outfd; |
11381
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
209 |
dmu_replay_record_t wbr_drr = {0}; |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
210 |
struct drr_write_byref *wbr_drrr = &wbr_drr.drr_u.drr_write_byref; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
211 |
dedup_table_t ddt; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
212 |
zio_cksum_t stream_cksum; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
213 |
uint64_t physmem = sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGESIZE); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
214 |
uint64_t numbuckets; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
215 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
216 |
ddt.max_ddt_size = |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
217 |
MAX((physmem * MAX_DDT_PHYSMEM_PERCENT)/100, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
218 |
SMALLEST_POSSIBLE_MAX_DDT_MB<<20); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
219 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
220 |
numbuckets = ddt.max_ddt_size/(sizeof (dedup_entry_t)); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
221 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
222 |
/* |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
223 |
* numbuckets must be a power of 2. Increase number to |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
224 |
* a power of 2 if necessary. |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
225 |
*/ |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
226 |
if (!ISP2(numbuckets)) |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
227 |
numbuckets = 1 << high_order_bit(numbuckets); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
228 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
229 |
ddt.dedup_hash_array = calloc(numbuckets, sizeof (dedup_entry_t *)); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
230 |
ddt.ddecache = umem_cache_create("dde", sizeof (dedup_entry_t), 0, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
231 |
NULL, NULL, NULL, NULL, NULL, 0); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
232 |
ddt.cur_ddt_size = numbuckets * sizeof (dedup_entry_t *); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
233 |
ddt.numhashbits = high_order_bit(numbuckets) - 1; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
234 |
ddt.ddt_full = B_FALSE; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
235 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
236 |
/* Initialize the write-by-reference block. */ |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
237 |
wbr_drr.drr_type = DRR_WRITE_BYREF; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
238 |
wbr_drr.drr_payloadlen = 0; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
239 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
240 |
outfd = dda->outputfd; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
241 |
ofp = fdopen(dda->inputfd, "r"); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
242 |
while (ssread(drr, sizeof (dmu_replay_record_t), ofp) != 0) { |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
243 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
244 |
switch (drr->drr_type) { |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
245 |
case DRR_BEGIN: |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
246 |
{ |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
247 |
int fflags; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
248 |
ZIO_SET_CHECKSUM(&stream_cksum, 0, 0, 0, 0); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
249 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
250 |
/* set the DEDUP feature flag for this stream */ |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
251 |
fflags = DMU_GET_FEATUREFLAGS(drrb->drr_versioninfo); |
11381
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
252 |
fflags |= (DMU_BACKUP_FEATURE_DEDUP | |
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
253 |
DMU_BACKUP_FEATURE_DEDUPPROPS); |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
254 |
DMU_SET_FEATUREFLAGS(drrb->drr_versioninfo, fflags); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
255 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
256 |
if (cksum_and_write(drr, sizeof (dmu_replay_record_t), |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
257 |
&stream_cksum, outfd) == -1) |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
258 |
goto out; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
259 |
if (DMU_GET_STREAM_HDRTYPE(drrb->drr_versioninfo) == |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
260 |
DMU_COMPOUNDSTREAM && drr->drr_payloadlen != 0) { |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
261 |
int sz = drr->drr_payloadlen; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
262 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
263 |
if (sz > 1<<20) { |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
264 |
free(buf); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
265 |
buf = malloc(sz); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
266 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
267 |
(void) ssread(buf, sz, ofp); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
268 |
if (ferror(stdin)) |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
269 |
perror("fread"); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
270 |
if (cksum_and_write(buf, sz, &stream_cksum, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
271 |
outfd) == -1) |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
272 |
goto out; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
273 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
274 |
break; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
275 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
276 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
277 |
case DRR_END: |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
278 |
{ |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
279 |
/* use the recalculated checksum */ |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
280 |
ZIO_SET_CHECKSUM(&drre->drr_checksum, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
281 |
stream_cksum.zc_word[0], stream_cksum.zc_word[1], |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
282 |
stream_cksum.zc_word[2], stream_cksum.zc_word[3]); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
283 |
if ((write(outfd, drr, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
284 |
sizeof (dmu_replay_record_t))) == -1) |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
285 |
goto out; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
286 |
break; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
287 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
288 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
289 |
case DRR_OBJECT: |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
290 |
{ |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
291 |
if (cksum_and_write(drr, sizeof (dmu_replay_record_t), |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
292 |
&stream_cksum, outfd) == -1) |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
293 |
goto out; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
294 |
if (drro->drr_bonuslen > 0) { |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
295 |
(void) ssread(buf, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
296 |
P2ROUNDUP((uint64_t)drro->drr_bonuslen, 8), |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
297 |
ofp); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
298 |
if (cksum_and_write(buf, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
299 |
P2ROUNDUP((uint64_t)drro->drr_bonuslen, 8), |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
300 |
&stream_cksum, outfd) == -1) |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
301 |
goto out; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
302 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
303 |
break; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
304 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
305 |
|
11935
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
306 |
case DRR_SPILL: |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
307 |
{ |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
308 |
if (cksum_and_write(drr, sizeof (dmu_replay_record_t), |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
309 |
&stream_cksum, outfd) == -1) |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
310 |
goto out; |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
311 |
(void) ssread(buf, drrs->drr_length, ofp); |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
312 |
if (cksum_and_write(buf, drrs->drr_length, |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
313 |
&stream_cksum, outfd) == -1) |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
314 |
goto out; |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
315 |
break; |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
316 |
} |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
317 |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
318 |
case DRR_FREEOBJECTS: |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
319 |
{ |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
320 |
if (cksum_and_write(drr, sizeof (dmu_replay_record_t), |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
321 |
&stream_cksum, outfd) == -1) |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
322 |
goto out; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
323 |
break; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
324 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
325 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
326 |
case DRR_WRITE: |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
327 |
{ |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
328 |
dataref_t dataref; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
329 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
330 |
(void) ssread(buf, drrw->drr_length, ofp); |
11381
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
331 |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
332 |
/* |
11381
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
333 |
* Use the existing checksum if it's dedup-capable, |
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
334 |
* else calculate a SHA256 checksum for it. |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
335 |
*/ |
11381
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
336 |
|
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
337 |
if (ZIO_CHECKSUM_EQUAL(drrw->drr_key.ddk_cksum, |
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
338 |
zero_cksum) || |
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
339 |
!DRR_IS_DEDUP_CAPABLE(drrw->drr_checksumflags)) { |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
340 |
SHA256_CTX ctx; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
341 |
zio_cksum_t tmpsha256; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
342 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
343 |
SHA256Init(&ctx); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
344 |
SHA256Update(&ctx, buf, drrw->drr_length); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
345 |
SHA256Final(&tmpsha256, &ctx); |
11381
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
346 |
drrw->drr_key.ddk_cksum.zc_word[0] = |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
347 |
BE_64(tmpsha256.zc_word[0]); |
11381
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
348 |
drrw->drr_key.ddk_cksum.zc_word[1] = |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
349 |
BE_64(tmpsha256.zc_word[1]); |
11381
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
350 |
drrw->drr_key.ddk_cksum.zc_word[2] = |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
351 |
BE_64(tmpsha256.zc_word[2]); |
11381
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
352 |
drrw->drr_key.ddk_cksum.zc_word[3] = |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
353 |
BE_64(tmpsha256.zc_word[3]); |
11381
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
354 |
drrw->drr_checksumtype = ZIO_CHECKSUM_SHA256; |
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
355 |
drrw->drr_checksumflags = DRR_CHECKSUM_DEDUP; |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
356 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
357 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
358 |
dataref.ref_guid = drrw->drr_toguid; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
359 |
dataref.ref_object = drrw->drr_object; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
360 |
dataref.ref_offset = drrw->drr_offset; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
361 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
362 |
if (ddt_update(dda->dedup_hdl, &ddt, |
11381
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
363 |
&drrw->drr_key.ddk_cksum, drrw->drr_key.ddk_prop, |
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
364 |
&dataref)) { |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
365 |
/* block already present in stream */ |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
366 |
wbr_drrr->drr_object = drrw->drr_object; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
367 |
wbr_drrr->drr_offset = drrw->drr_offset; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
368 |
wbr_drrr->drr_length = drrw->drr_length; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
369 |
wbr_drrr->drr_toguid = drrw->drr_toguid; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
370 |
wbr_drrr->drr_refguid = dataref.ref_guid; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
371 |
wbr_drrr->drr_refobject = |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
372 |
dataref.ref_object; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
373 |
wbr_drrr->drr_refoffset = |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
374 |
dataref.ref_offset; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
375 |
|
11381
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
376 |
wbr_drrr->drr_checksumtype = |
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
377 |
drrw->drr_checksumtype; |
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
378 |
wbr_drrr->drr_checksumflags = |
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
379 |
drrw->drr_checksumtype; |
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
380 |
wbr_drrr->drr_key.ddk_cksum = |
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
381 |
drrw->drr_key.ddk_cksum; |
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
382 |
wbr_drrr->drr_key.ddk_prop = |
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
383 |
drrw->drr_key.ddk_prop; |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
384 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
385 |
if (cksum_and_write(&wbr_drr, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
386 |
sizeof (dmu_replay_record_t), &stream_cksum, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
387 |
outfd) == -1) |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
388 |
goto out; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
389 |
} else { |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
390 |
/* block not previously seen */ |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
391 |
if (cksum_and_write(drr, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
392 |
sizeof (dmu_replay_record_t), &stream_cksum, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
393 |
outfd) == -1) |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
394 |
goto out; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
395 |
if (cksum_and_write(buf, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
396 |
drrw->drr_length, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
397 |
&stream_cksum, outfd) == -1) |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
398 |
goto out; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
399 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
400 |
break; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
401 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
402 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
403 |
case DRR_FREE: |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
404 |
{ |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
405 |
if (cksum_and_write(drr, sizeof (dmu_replay_record_t), |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
406 |
&stream_cksum, outfd) == -1) |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
407 |
goto out; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
408 |
break; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
409 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
410 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
411 |
default: |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
412 |
(void) printf("INVALID record type 0x%x\n", |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
413 |
drr->drr_type); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
414 |
/* should never happen, so assert */ |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
415 |
assert(B_FALSE); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
416 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
417 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
418 |
out: |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
419 |
umem_cache_destroy(ddt.ddecache); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
420 |
free(ddt.dedup_hash_array); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
421 |
free(buf); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
422 |
(void) fclose(ofp); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
423 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
424 |
return (NULL); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
425 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
426 |
|
5367 | 427 |
/* |
428 |
* Routines for dealing with the AVL tree of fs-nvlists |
|
429 |
*/ |
|
430 |
typedef struct fsavl_node { |
|
431 |
avl_node_t fn_node; |
|
432 |
nvlist_t *fn_nvfs; |
|
433 |
char *fn_snapname; |
|
434 |
uint64_t fn_guid; |
|
435 |
} fsavl_node_t; |
|
436 |
||
437 |
static int |
|
438 |
fsavl_compare(const void *arg1, const void *arg2) |
|
439 |
{ |
|
440 |
const fsavl_node_t *fn1 = arg1; |
|
441 |
const fsavl_node_t *fn2 = arg2; |
|
442 |
||
443 |
if (fn1->fn_guid > fn2->fn_guid) |
|
444 |
return (+1); |
|
445 |
else if (fn1->fn_guid < fn2->fn_guid) |
|
446 |
return (-1); |
|
447 |
else |
|
448 |
return (0); |
|
449 |
} |
|
450 |
||
451 |
/* |
|
452 |
* Given the GUID of a snapshot, find its containing filesystem and |
|
453 |
* (optionally) name. |
|
454 |
*/ |
|
455 |
static nvlist_t * |
|
456 |
fsavl_find(avl_tree_t *avl, uint64_t snapguid, char **snapname) |
|
457 |
{ |
|
458 |
fsavl_node_t fn_find; |
|
459 |
fsavl_node_t *fn; |
|
460 |
||
461 |
fn_find.fn_guid = snapguid; |
|
462 |
||
463 |
fn = avl_find(avl, &fn_find, NULL); |
|
464 |
if (fn) { |
|
465 |
if (snapname) |
|
466 |
*snapname = fn->fn_snapname; |
|
467 |
return (fn->fn_nvfs); |
|
468 |
} |
|
469 |
return (NULL); |
|
470 |
} |
|
471 |
||
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
472 |
static void |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
473 |
fsavl_destroy(avl_tree_t *avl) |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
474 |
{ |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
475 |
fsavl_node_t *fn; |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
476 |
void *cookie; |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
477 |
|
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
478 |
if (avl == NULL) |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
479 |
return; |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
480 |
|
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
481 |
cookie = NULL; |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
482 |
while ((fn = avl_destroy_nodes(avl, &cookie)) != NULL) |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
483 |
free(fn); |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
484 |
avl_destroy(avl); |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
485 |
free(avl); |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
486 |
} |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
487 |
|
10200
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
488 |
/* |
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
489 |
* Given an nvlist, produce an avl tree of snapshots, ordered by guid |
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
490 |
*/ |
5367 | 491 |
static avl_tree_t * |
492 |
fsavl_create(nvlist_t *fss) |
|
493 |
{ |
|
494 |
avl_tree_t *fsavl; |
|
495 |
nvpair_t *fselem = NULL; |
|
496 |
||
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
497 |
if ((fsavl = malloc(sizeof (avl_tree_t))) == NULL) |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
498 |
return (NULL); |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
499 |
|
5367 | 500 |
avl_create(fsavl, fsavl_compare, sizeof (fsavl_node_t), |
501 |
offsetof(fsavl_node_t, fn_node)); |
|
502 |
||
503 |
while ((fselem = nvlist_next_nvpair(fss, fselem)) != NULL) { |
|
504 |
nvlist_t *nvfs, *snaps; |
|
505 |
nvpair_t *snapelem = NULL; |
|
506 |
||
507 |
VERIFY(0 == nvpair_value_nvlist(fselem, &nvfs)); |
|
508 |
VERIFY(0 == nvlist_lookup_nvlist(nvfs, "snaps", &snaps)); |
|
509 |
||
510 |
while ((snapelem = |
|
511 |
nvlist_next_nvpair(snaps, snapelem)) != NULL) { |
|
512 |
fsavl_node_t *fn; |
|
513 |
uint64_t guid; |
|
514 |
||
515 |
VERIFY(0 == nvpair_value_uint64(snapelem, &guid)); |
|
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
516 |
if ((fn = malloc(sizeof (fsavl_node_t))) == NULL) { |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
517 |
fsavl_destroy(fsavl); |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
518 |
return (NULL); |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
519 |
} |
5367 | 520 |
fn->fn_nvfs = nvfs; |
521 |
fn->fn_snapname = nvpair_name(snapelem); |
|
522 |
fn->fn_guid = guid; |
|
523 |
||
524 |
/* |
|
525 |
* Note: if there are multiple snaps with the |
|
526 |
* same GUID, we ignore all but one. |
|
527 |
*/ |
|
528 |
if (avl_find(fsavl, fn, NULL) == NULL) |
|
529 |
avl_add(fsavl, fn); |
|
530 |
else |
|
531 |
free(fn); |
|
532 |
} |
|
533 |
} |
|
534 |
||
535 |
return (fsavl); |
|
536 |
} |
|
537 |
||
538 |
/* |
|
539 |
* Routines for dealing with the giant nvlist of fs-nvlists, etc. |
|
540 |
*/ |
|
541 |
typedef struct send_data { |
|
542 |
uint64_t parent_fromsnap_guid; |
|
543 |
nvlist_t *parent_snaps; |
|
544 |
nvlist_t *fss; |
|
7265 | 545 |
nvlist_t *snapprops; |
5367 | 546 |
const char *fromsnap; |
547 |
const char *tosnap; |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
548 |
boolean_t recursive; |
5367 | 549 |
|
550 |
/* |
|
551 |
* The header nvlist is of the following format: |
|
552 |
* { |
|
553 |
* "tosnap" -> string |
|
554 |
* "fromsnap" -> string (if incremental) |
|
555 |
* "fss" -> { |
|
556 |
* id -> { |
|
557 |
* |
|
558 |
* "name" -> string (full name; for debugging) |
|
559 |
* "parentfromsnap" -> number (guid of fromsnap in parent) |
|
560 |
* |
|
561 |
* "props" -> { name -> value (only if set here) } |
|
562 |
* "snaps" -> { name (lastname) -> number (guid) } |
|
7265 | 563 |
* "snapprops" -> { name (lastname) -> { name -> value } } |
5367 | 564 |
* |
565 |
* "origin" -> number (guid) (if clone) |
|
566 |
* "sent" -> boolean (not on-disk) |
|
567 |
* } |
|
568 |
* } |
|
569 |
* } |
|
570 |
* |
|
571 |
*/ |
|
572 |
} send_data_t; |
|
573 |
||
7265 | 574 |
static void send_iterate_prop(zfs_handle_t *zhp, nvlist_t *nv); |
575 |
||
5367 | 576 |
static int |
577 |
send_iterate_snap(zfs_handle_t *zhp, void *arg) |
|
578 |
{ |
|
579 |
send_data_t *sd = arg; |
|
580 |
uint64_t guid = zhp->zfs_dmustats.dds_guid; |
|
581 |
char *snapname; |
|
7265 | 582 |
nvlist_t *nv; |
5367 | 583 |
|
584 |
snapname = strrchr(zhp->zfs_name, '@')+1; |
|
585 |
||
586 |
VERIFY(0 == nvlist_add_uint64(sd->parent_snaps, snapname, guid)); |
|
587 |
/* |
|
588 |
* NB: if there is no fromsnap here (it's a newly created fs in |
|
589 |
* an incremental replication), we will substitute the tosnap. |
|
590 |
*/ |
|
591 |
if ((sd->fromsnap && strcmp(snapname, sd->fromsnap) == 0) || |
|
592 |
(sd->parent_fromsnap_guid == 0 && sd->tosnap && |
|
593 |
strcmp(snapname, sd->tosnap) == 0)) { |
|
594 |
sd->parent_fromsnap_guid = guid; |
|
595 |
} |
|
596 |
||
7265 | 597 |
VERIFY(0 == nvlist_alloc(&nv, NV_UNIQUE_NAME, 0)); |
598 |
send_iterate_prop(zhp, nv); |
|
599 |
VERIFY(0 == nvlist_add_nvlist(sd->snapprops, snapname, nv)); |
|
600 |
nvlist_free(nv); |
|
601 |
||
5367 | 602 |
zfs_close(zhp); |
603 |
return (0); |
|
604 |
} |
|
605 |
||
606 |
static void |
|
607 |
send_iterate_prop(zfs_handle_t *zhp, nvlist_t *nv) |
|
608 |
{ |
|
609 |
nvpair_t *elem = NULL; |
|
610 |
||
611 |
while ((elem = nvlist_next_nvpair(zhp->zfs_props, elem)) != NULL) { |
|
612 |
char *propname = nvpair_name(elem); |
|
613 |
zfs_prop_t prop = zfs_name_to_prop(propname); |
|
614 |
nvlist_t *propnv; |
|
615 |
||
10960
dcc7d6f9faa8
6897978 zfs send should ignore unknown properties
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
10735
diff
changeset
|
616 |
if (!zfs_prop_user(propname)) { |
dcc7d6f9faa8
6897978 zfs send should ignore unknown properties
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
10735
diff
changeset
|
617 |
/* |
dcc7d6f9faa8
6897978 zfs send should ignore unknown properties
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
10735
diff
changeset
|
618 |
* Realistically, this should never happen. However, |
dcc7d6f9faa8
6897978 zfs send should ignore unknown properties
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
10735
diff
changeset
|
619 |
* we want the ability to add DSL properties without |
dcc7d6f9faa8
6897978 zfs send should ignore unknown properties
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
10735
diff
changeset
|
620 |
* needing to make incompatible version changes. We |
dcc7d6f9faa8
6897978 zfs send should ignore unknown properties
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
10735
diff
changeset
|
621 |
* need to ignore unknown properties to allow older |
dcc7d6f9faa8
6897978 zfs send should ignore unknown properties
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
10735
diff
changeset
|
622 |
* software to still send datasets containing these |
dcc7d6f9faa8
6897978 zfs send should ignore unknown properties
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
10735
diff
changeset
|
623 |
* properties, with the unknown properties elided. |
dcc7d6f9faa8
6897978 zfs send should ignore unknown properties
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
10735
diff
changeset
|
624 |
*/ |
dcc7d6f9faa8
6897978 zfs send should ignore unknown properties
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
10735
diff
changeset
|
625 |
if (prop == ZPROP_INVAL) |
dcc7d6f9faa8
6897978 zfs send should ignore unknown properties
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
10735
diff
changeset
|
626 |
continue; |
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8584
diff
changeset
|
627 |
|
10960
dcc7d6f9faa8
6897978 zfs send should ignore unknown properties
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
10735
diff
changeset
|
628 |
if (zfs_prop_readonly(prop)) |
dcc7d6f9faa8
6897978 zfs send should ignore unknown properties
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
10735
diff
changeset
|
629 |
continue; |
dcc7d6f9faa8
6897978 zfs send should ignore unknown properties
Eric Schrock <Eric.Schrock@Sun.COM>
parents:
10735
diff
changeset
|
630 |
} |
5367 | 631 |
|
632 |
verify(nvpair_value_nvlist(elem, &propnv) == 0); |
|
10195
f194519c90bf
6853862 refquota property not send over with zfs send -R
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9396
diff
changeset
|
633 |
if (prop == ZFS_PROP_QUOTA || prop == ZFS_PROP_RESERVATION || |
f194519c90bf
6853862 refquota property not send over with zfs send -R
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9396
diff
changeset
|
634 |
prop == ZFS_PROP_REFQUOTA || |
f194519c90bf
6853862 refquota property not send over with zfs send -R
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents:
9396
diff
changeset
|
635 |
prop == ZFS_PROP_REFRESERVATION) { |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
636 |
char *source; |
5367 | 637 |
uint64_t value; |
638 |
verify(nvlist_lookup_uint64(propnv, |
|
639 |
ZPROP_VALUE, &value) == 0); |
|
7265 | 640 |
if (zhp->zfs_type == ZFS_TYPE_SNAPSHOT) |
641 |
continue; |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
642 |
/* |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
643 |
* May have no source before SPA_VERSION_RECVD_PROPS, |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
644 |
* but is still modifiable. |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
645 |
*/ |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
646 |
if (nvlist_lookup_string(propnv, |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
647 |
ZPROP_SOURCE, &source) == 0) { |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
648 |
if ((strcmp(source, zhp->zfs_name) != 0) && |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
649 |
(strcmp(source, |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
650 |
ZPROP_SOURCE_VAL_RECVD) != 0)) |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
651 |
continue; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
652 |
} |
5367 | 653 |
} else { |
654 |
char *source; |
|
655 |
if (nvlist_lookup_string(propnv, |
|
656 |
ZPROP_SOURCE, &source) != 0) |
|
657 |
continue; |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
658 |
if ((strcmp(source, zhp->zfs_name) != 0) && |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
659 |
(strcmp(source, ZPROP_SOURCE_VAL_RECVD) != 0)) |
5367 | 660 |
continue; |
661 |
} |
|
662 |
||
663 |
if (zfs_prop_user(propname) || |
|
664 |
zfs_prop_get_type(prop) == PROP_TYPE_STRING) { |
|
665 |
char *value; |
|
666 |
verify(nvlist_lookup_string(propnv, |
|
667 |
ZPROP_VALUE, &value) == 0); |
|
668 |
VERIFY(0 == nvlist_add_string(nv, propname, value)); |
|
669 |
} else { |
|
670 |
uint64_t value; |
|
671 |
verify(nvlist_lookup_uint64(propnv, |
|
672 |
ZPROP_VALUE, &value) == 0); |
|
673 |
VERIFY(0 == nvlist_add_uint64(nv, propname, value)); |
|
674 |
} |
|
675 |
} |
|
676 |
} |
|
677 |
||
10200
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
678 |
/* |
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
679 |
* recursively generate nvlists describing datasets. See comment |
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
680 |
* for the data structure send_data_t above for description of contents |
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
681 |
* of the nvlist. |
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
682 |
*/ |
5367 | 683 |
static int |
684 |
send_iterate_fs(zfs_handle_t *zhp, void *arg) |
|
685 |
{ |
|
686 |
send_data_t *sd = arg; |
|
687 |
nvlist_t *nvfs, *nv; |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
688 |
int rv = 0; |
5367 | 689 |
uint64_t parent_fromsnap_guid_save = sd->parent_fromsnap_guid; |
690 |
uint64_t guid = zhp->zfs_dmustats.dds_guid; |
|
691 |
char guidstring[64]; |
|
692 |
||
693 |
VERIFY(0 == nvlist_alloc(&nvfs, NV_UNIQUE_NAME, 0)); |
|
694 |
VERIFY(0 == nvlist_add_string(nvfs, "name", zhp->zfs_name)); |
|
695 |
VERIFY(0 == nvlist_add_uint64(nvfs, "parentfromsnap", |
|
696 |
sd->parent_fromsnap_guid)); |
|
697 |
||
698 |
if (zhp->zfs_dmustats.dds_origin[0]) { |
|
699 |
zfs_handle_t *origin = zfs_open(zhp->zfs_hdl, |
|
700 |
zhp->zfs_dmustats.dds_origin, ZFS_TYPE_SNAPSHOT); |
|
701 |
if (origin == NULL) |
|
702 |
return (-1); |
|
703 |
VERIFY(0 == nvlist_add_uint64(nvfs, "origin", |
|
704 |
origin->zfs_dmustats.dds_guid)); |
|
705 |
} |
|
706 |
||
707 |
/* iterate over props */ |
|
708 |
VERIFY(0 == nvlist_alloc(&nv, NV_UNIQUE_NAME, 0)); |
|
709 |
send_iterate_prop(zhp, nv); |
|
710 |
VERIFY(0 == nvlist_add_nvlist(nvfs, "props", nv)); |
|
711 |
nvlist_free(nv); |
|
712 |
||
713 |
/* iterate over snaps, and set sd->parent_fromsnap_guid */ |
|
714 |
sd->parent_fromsnap_guid = 0; |
|
715 |
VERIFY(0 == nvlist_alloc(&sd->parent_snaps, NV_UNIQUE_NAME, 0)); |
|
7265 | 716 |
VERIFY(0 == nvlist_alloc(&sd->snapprops, NV_UNIQUE_NAME, 0)); |
5367 | 717 |
(void) zfs_iter_snapshots(zhp, send_iterate_snap, sd); |
718 |
VERIFY(0 == nvlist_add_nvlist(nvfs, "snaps", sd->parent_snaps)); |
|
7265 | 719 |
VERIFY(0 == nvlist_add_nvlist(nvfs, "snapprops", sd->snapprops)); |
5367 | 720 |
nvlist_free(sd->parent_snaps); |
7265 | 721 |
nvlist_free(sd->snapprops); |
5367 | 722 |
|
723 |
/* add this fs to nvlist */ |
|
724 |
(void) snprintf(guidstring, sizeof (guidstring), |
|
725 |
"0x%llx", (longlong_t)guid); |
|
726 |
VERIFY(0 == nvlist_add_nvlist(sd->fss, guidstring, nvfs)); |
|
727 |
nvlist_free(nvfs); |
|
728 |
||
729 |
/* iterate over children */ |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
730 |
if (sd->recursive) |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
731 |
rv = zfs_iter_filesystems(zhp, send_iterate_fs, sd); |
5367 | 732 |
|
733 |
sd->parent_fromsnap_guid = parent_fromsnap_guid_save; |
|
734 |
||
735 |
zfs_close(zhp); |
|
736 |
return (rv); |
|
737 |
} |
|
738 |
||
739 |
static int |
|
740 |
gather_nvlist(libzfs_handle_t *hdl, const char *fsname, const char *fromsnap, |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
741 |
const char *tosnap, boolean_t recursive, nvlist_t **nvlp, avl_tree_t **avlp) |
5367 | 742 |
{ |
743 |
zfs_handle_t *zhp; |
|
744 |
send_data_t sd = { 0 }; |
|
745 |
int error; |
|
746 |
||
747 |
zhp = zfs_open(hdl, fsname, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME); |
|
748 |
if (zhp == NULL) |
|
749 |
return (EZFS_BADTYPE); |
|
750 |
||
751 |
VERIFY(0 == nvlist_alloc(&sd.fss, NV_UNIQUE_NAME, 0)); |
|
752 |
sd.fromsnap = fromsnap; |
|
753 |
sd.tosnap = tosnap; |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
754 |
sd.recursive = recursive; |
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
755 |
|
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
756 |
if ((error = send_iterate_fs(zhp, &sd)) != 0) { |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
757 |
nvlist_free(sd.fss); |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
758 |
if (avlp != NULL) |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
759 |
*avlp = NULL; |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
760 |
*nvlp = NULL; |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
761 |
return (error); |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
762 |
} |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
763 |
|
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
764 |
if (avlp != NULL && (*avlp = fsavl_create(sd.fss)) == NULL) { |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
765 |
nvlist_free(sd.fss); |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
766 |
*nvlp = NULL; |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
767 |
return (EZFS_NOMEM); |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
768 |
} |
5367 | 769 |
|
770 |
*nvlp = sd.fss; |
|
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
771 |
return (0); |
5367 | 772 |
} |
773 |
||
774 |
/* |
|
775 |
* Routines for dealing with the sorted snapshot functionality |
|
776 |
*/ |
|
777 |
typedef struct zfs_node { |
|
778 |
zfs_handle_t *zn_handle; |
|
779 |
avl_node_t zn_avlnode; |
|
780 |
} zfs_node_t; |
|
781 |
||
782 |
static int |
|
783 |
zfs_sort_snaps(zfs_handle_t *zhp, void *data) |
|
784 |
{ |
|
785 |
avl_tree_t *avl = data; |
|
786 |
zfs_node_t *node = zfs_alloc(zhp->zfs_hdl, sizeof (zfs_node_t)); |
|
787 |
||
788 |
node->zn_handle = zhp; |
|
789 |
avl_add(avl, node); |
|
790 |
return (0); |
|
791 |
} |
|
792 |
||
793 |
/* ARGSUSED */ |
|
794 |
static int |
|
795 |
zfs_snapshot_compare(const void *larg, const void *rarg) |
|
796 |
{ |
|
797 |
zfs_handle_t *l = ((zfs_node_t *)larg)->zn_handle; |
|
798 |
zfs_handle_t *r = ((zfs_node_t *)rarg)->zn_handle; |
|
799 |
uint64_t lcreate, rcreate; |
|
800 |
||
801 |
/* |
|
802 |
* Sort them according to creation time. We use the hidden |
|
803 |
* CREATETXG property to get an absolute ordering of snapshots. |
|
804 |
*/ |
|
805 |
lcreate = zfs_prop_get_int(l, ZFS_PROP_CREATETXG); |
|
806 |
rcreate = zfs_prop_get_int(r, ZFS_PROP_CREATETXG); |
|
807 |
||
808 |
if (lcreate < rcreate) |
|
809 |
return (-1); |
|
810 |
else if (lcreate > rcreate) |
|
811 |
return (+1); |
|
812 |
else |
|
813 |
return (0); |
|
814 |
} |
|
815 |
||
10342
108f0058f837
6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents:
10302
diff
changeset
|
816 |
int |
5367 | 817 |
zfs_iter_snapshots_sorted(zfs_handle_t *zhp, zfs_iter_f callback, void *data) |
818 |
{ |
|
819 |
int ret = 0; |
|
820 |
zfs_node_t *node; |
|
821 |
avl_tree_t avl; |
|
822 |
void *cookie = NULL; |
|
823 |
||
824 |
avl_create(&avl, zfs_snapshot_compare, |
|
825 |
sizeof (zfs_node_t), offsetof(zfs_node_t, zn_avlnode)); |
|
826 |
||
827 |
ret = zfs_iter_snapshots(zhp, zfs_sort_snaps, &avl); |
|
828 |
||
829 |
for (node = avl_first(&avl); node != NULL; node = AVL_NEXT(&avl, node)) |
|
830 |
ret |= callback(node->zn_handle, data); |
|
831 |
||
832 |
while ((node = avl_destroy_nodes(&avl, &cookie)) != NULL) |
|
833 |
free(node); |
|
834 |
||
835 |
avl_destroy(&avl); |
|
836 |
||
837 |
return (ret); |
|
838 |
} |
|
839 |
||
840 |
/* |
|
841 |
* Routines specific to "zfs send" |
|
842 |
*/ |
|
843 |
typedef struct send_dump_data { |
|
844 |
/* these are all just the short snapname (the part after the @) */ |
|
845 |
const char *fromsnap; |
|
846 |
const char *tosnap; |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
847 |
char prevsnap[ZFS_MAXNAMELEN]; |
5367 | 848 |
boolean_t seenfrom, seento, replicate, doall, fromorigin; |
849 |
boolean_t verbose; |
|
850 |
int outfd; |
|
851 |
boolean_t err; |
|
852 |
nvlist_t *fss; |
|
853 |
avl_tree_t *fsavl; |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
854 |
snapfilter_cb_t *filter_cb; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
855 |
void *filter_cb_arg; |
5367 | 856 |
} send_dump_data_t; |
857 |
||
858 |
/* |
|
859 |
* Dumps a backup of the given snapshot (incremental from fromsnap if it's not |
|
860 |
* NULL) to the file descriptor specified by outfd. |
|
861 |
*/ |
|
862 |
static int |
|
863 |
dump_ioctl(zfs_handle_t *zhp, const char *fromsnap, boolean_t fromorigin, |
|
11668
707c4515580e
6885979 zfs_send -R fails to send snapshots that get renamed during the operation
Chris Kirby <Chris.Kirby@sun.com>
parents:
11546
diff
changeset
|
864 |
int outfd, boolean_t enoent_ok, boolean_t *got_enoent) |
5367 | 865 |
{ |
866 |
zfs_cmd_t zc = { 0 }; |
|
867 |
libzfs_handle_t *hdl = zhp->zfs_hdl; |
|
868 |
||
869 |
assert(zhp->zfs_type == ZFS_TYPE_SNAPSHOT); |
|
870 |
assert(fromsnap == NULL || fromsnap[0] == '\0' || !fromorigin); |
|
871 |
||
872 |
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); |
|
873 |
if (fromsnap) |
|
5765
86c482ef4a34
6646545 Condvars in tx_cpu aren't being initialized/destroyed
ek110237
parents:
5446
diff
changeset
|
874 |
(void) strlcpy(zc.zc_value, fromsnap, sizeof (zc.zc_value)); |
5367 | 875 |
zc.zc_cookie = outfd; |
876 |
zc.zc_obj = fromorigin; |
|
877 |
||
11668
707c4515580e
6885979 zfs_send -R fails to send snapshots that get renamed during the operation
Chris Kirby <Chris.Kirby@sun.com>
parents:
11546
diff
changeset
|
878 |
*got_enoent = B_FALSE; |
707c4515580e
6885979 zfs_send -R fails to send snapshots that get renamed during the operation
Chris Kirby <Chris.Kirby@sun.com>
parents:
11546
diff
changeset
|
879 |
|
5367 | 880 |
if (ioctl(zhp->zfs_hdl->libzfs_fd, ZFS_IOC_SEND, &zc) != 0) { |
881 |
char errbuf[1024]; |
|
882 |
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, |
|
883 |
"warning: cannot send '%s'"), zhp->zfs_name); |
|
884 |
||
885 |
switch (errno) { |
|
886 |
||
887 |
case EXDEV: |
|
888 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
889 |
"not an earlier snapshot from the same fs")); |
|
890 |
return (zfs_error(hdl, EZFS_CROSSTARGET, errbuf)); |
|
891 |
||
892 |
case ENOENT: |
|
11668
707c4515580e
6885979 zfs_send -R fails to send snapshots that get renamed during the operation
Chris Kirby <Chris.Kirby@sun.com>
parents:
11546
diff
changeset
|
893 |
if (enoent_ok) { |
707c4515580e
6885979 zfs_send -R fails to send snapshots that get renamed during the operation
Chris Kirby <Chris.Kirby@sun.com>
parents:
11546
diff
changeset
|
894 |
*got_enoent = B_TRUE; |
707c4515580e
6885979 zfs_send -R fails to send snapshots that get renamed during the operation
Chris Kirby <Chris.Kirby@sun.com>
parents:
11546
diff
changeset
|
895 |
return (0); |
707c4515580e
6885979 zfs_send -R fails to send snapshots that get renamed during the operation
Chris Kirby <Chris.Kirby@sun.com>
parents:
11546
diff
changeset
|
896 |
} |
5367 | 897 |
if (zfs_dataset_exists(hdl, zc.zc_name, |
898 |
ZFS_TYPE_SNAPSHOT)) { |
|
899 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
900 |
"incremental source (@%s) does not exist"), |
|
901 |
zc.zc_value); |
|
902 |
} |
|
903 |
return (zfs_error(hdl, EZFS_NOENT, errbuf)); |
|
904 |
||
905 |
case EDQUOT: |
|
906 |
case EFBIG: |
|
907 |
case EIO: |
|
908 |
case ENOLINK: |
|
909 |
case ENOSPC: |
|
910 |
case ENOSTR: |
|
911 |
case ENXIO: |
|
912 |
case EPIPE: |
|
913 |
case ERANGE: |
|
914 |
case EFAULT: |
|
915 |
case EROFS: |
|
916 |
zfs_error_aux(hdl, strerror(errno)); |
|
917 |
return (zfs_error(hdl, EZFS_BADBACKUP, errbuf)); |
|
918 |
||
919 |
default: |
|
920 |
return (zfs_standard_error(hdl, errno, errbuf)); |
|
921 |
} |
|
922 |
} |
|
923 |
||
924 |
return (0); |
|
925 |
} |
|
926 |
||
927 |
static int |
|
928 |
dump_snapshot(zfs_handle_t *zhp, void *arg) |
|
929 |
{ |
|
930 |
send_dump_data_t *sdd = arg; |
|
931 |
const char *thissnap; |
|
932 |
int err; |
|
11668
707c4515580e
6885979 zfs_send -R fails to send snapshots that get renamed during the operation
Chris Kirby <Chris.Kirby@sun.com>
parents:
11546
diff
changeset
|
933 |
boolean_t got_enoent; |
5367 | 934 |
|
935 |
thissnap = strchr(zhp->zfs_name, '@') + 1; |
|
936 |
||
937 |
if (sdd->fromsnap && !sdd->seenfrom && |
|
938 |
strcmp(sdd->fromsnap, thissnap) == 0) { |
|
939 |
sdd->seenfrom = B_TRUE; |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
940 |
(void) strcpy(sdd->prevsnap, thissnap); |
5367 | 941 |
zfs_close(zhp); |
942 |
return (0); |
|
943 |
} |
|
944 |
||
945 |
if (sdd->seento || !sdd->seenfrom) { |
|
946 |
zfs_close(zhp); |
|
947 |
return (0); |
|
948 |
} |
|
949 |
||
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
950 |
if (strcmp(sdd->tosnap, thissnap) == 0) |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
951 |
sdd->seento = B_TRUE; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
952 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
953 |
/* |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
954 |
* If a filter function exists, call it to determine whether |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
955 |
* this snapshot will be sent. |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
956 |
*/ |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
957 |
if (sdd->filter_cb != NULL && |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
958 |
sdd->filter_cb(zhp, sdd->filter_cb_arg) == B_FALSE) { |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
959 |
/* |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
960 |
* This snapshot is filtered out. Don't send it, and don't |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
961 |
* set prevsnap, so it will be as if this snapshot didn't |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
962 |
* exist, and the next accepted snapshot will be sent as |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
963 |
* an incremental from the last accepted one, or as the |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
964 |
* first (and full) snapshot in the case of a replication, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
965 |
* non-incremental send. |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
966 |
*/ |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
967 |
zfs_close(zhp); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
968 |
return (0); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
969 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
970 |
|
5367 | 971 |
/* send it */ |
972 |
if (sdd->verbose) { |
|
973 |
(void) fprintf(stderr, "sending from @%s to %s\n", |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
974 |
sdd->prevsnap, zhp->zfs_name); |
5367 | 975 |
} |
976 |
||
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
977 |
err = dump_ioctl(zhp, sdd->prevsnap, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
978 |
sdd->prevsnap[0] == '\0' && (sdd->fromorigin || sdd->replicate), |
11668
707c4515580e
6885979 zfs_send -R fails to send snapshots that get renamed during the operation
Chris Kirby <Chris.Kirby@sun.com>
parents:
11546
diff
changeset
|
979 |
sdd->outfd, B_TRUE, &got_enoent); |
5367 | 980 |
|
11668
707c4515580e
6885979 zfs_send -R fails to send snapshots that get renamed during the operation
Chris Kirby <Chris.Kirby@sun.com>
parents:
11546
diff
changeset
|
981 |
if (got_enoent) |
707c4515580e
6885979 zfs_send -R fails to send snapshots that get renamed during the operation
Chris Kirby <Chris.Kirby@sun.com>
parents:
11546
diff
changeset
|
982 |
err = 0; |
707c4515580e
6885979 zfs_send -R fails to send snapshots that get renamed during the operation
Chris Kirby <Chris.Kirby@sun.com>
parents:
11546
diff
changeset
|
983 |
else |
707c4515580e
6885979 zfs_send -R fails to send snapshots that get renamed during the operation
Chris Kirby <Chris.Kirby@sun.com>
parents:
11546
diff
changeset
|
984 |
(void) strcpy(sdd->prevsnap, thissnap); |
5367 | 985 |
zfs_close(zhp); |
986 |
return (err); |
|
987 |
} |
|
988 |
||
989 |
static int |
|
990 |
dump_filesystem(zfs_handle_t *zhp, void *arg) |
|
991 |
{ |
|
992 |
int rv = 0; |
|
993 |
send_dump_data_t *sdd = arg; |
|
994 |
boolean_t missingfrom = B_FALSE; |
|
995 |
zfs_cmd_t zc = { 0 }; |
|
996 |
||
997 |
(void) snprintf(zc.zc_name, sizeof (zc.zc_name), "%s@%s", |
|
998 |
zhp->zfs_name, sdd->tosnap); |
|
999 |
if (ioctl(zhp->zfs_hdl->libzfs_fd, ZFS_IOC_OBJSET_STATS, &zc) != 0) { |
|
1000 |
(void) fprintf(stderr, "WARNING: " |
|
1001 |
"could not send %s@%s: does not exist\n", |
|
1002 |
zhp->zfs_name, sdd->tosnap); |
|
1003 |
sdd->err = B_TRUE; |
|
1004 |
return (0); |
|
1005 |
} |
|
1006 |
||
1007 |
if (sdd->replicate && sdd->fromsnap) { |
|
1008 |
/* |
|
1009 |
* If this fs does not have fromsnap, and we're doing |
|
1010 |
* recursive, we need to send a full stream from the |
|
1011 |
* beginning (or an incremental from the origin if this |
|
1012 |
* is a clone). If we're doing non-recursive, then let |
|
1013 |
* them get the error. |
|
1014 |
*/ |
|
1015 |
(void) snprintf(zc.zc_name, sizeof (zc.zc_name), "%s@%s", |
|
1016 |
zhp->zfs_name, sdd->fromsnap); |
|
1017 |
if (ioctl(zhp->zfs_hdl->libzfs_fd, |
|
1018 |
ZFS_IOC_OBJSET_STATS, &zc) != 0) { |
|
1019 |
missingfrom = B_TRUE; |
|
1020 |
} |
|
1021 |
} |
|
1022 |
||
1023 |
if (sdd->doall) { |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1024 |
sdd->seenfrom = sdd->seento = sdd->prevsnap[0] = 0; |
5367 | 1025 |
if (sdd->fromsnap == NULL || missingfrom) |
1026 |
sdd->seenfrom = B_TRUE; |
|
1027 |
||
1028 |
rv = zfs_iter_snapshots_sorted(zhp, dump_snapshot, arg); |
|
1029 |
if (!sdd->seenfrom) { |
|
1030 |
(void) fprintf(stderr, |
|
1031 |
"WARNING: could not send %s@%s:\n" |
|
1032 |
"incremental source (%s@%s) does not exist\n", |
|
1033 |
zhp->zfs_name, sdd->tosnap, |
|
1034 |
zhp->zfs_name, sdd->fromsnap); |
|
1035 |
sdd->err = B_TRUE; |
|
1036 |
} else if (!sdd->seento) { |
|
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8584
diff
changeset
|
1037 |
if (sdd->fromsnap) { |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8584
diff
changeset
|
1038 |
(void) fprintf(stderr, |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8584
diff
changeset
|
1039 |
"WARNING: could not send %s@%s:\n" |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8584
diff
changeset
|
1040 |
"incremental source (%s@%s) " |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8584
diff
changeset
|
1041 |
"is not earlier than it\n", |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8584
diff
changeset
|
1042 |
zhp->zfs_name, sdd->tosnap, |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8584
diff
changeset
|
1043 |
zhp->zfs_name, sdd->fromsnap); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8584
diff
changeset
|
1044 |
} else { |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8584
diff
changeset
|
1045 |
(void) fprintf(stderr, "WARNING: " |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8584
diff
changeset
|
1046 |
"could not send %s@%s: does not exist\n", |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8584
diff
changeset
|
1047 |
zhp->zfs_name, sdd->tosnap); |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8584
diff
changeset
|
1048 |
} |
5367 | 1049 |
sdd->err = B_TRUE; |
1050 |
} |
|
1051 |
} else { |
|
1052 |
zfs_handle_t *snapzhp; |
|
1053 |
char snapname[ZFS_MAXNAMELEN]; |
|
1054 |
||
1055 |
(void) snprintf(snapname, sizeof (snapname), "%s@%s", |
|
1056 |
zfs_get_name(zhp), sdd->tosnap); |
|
1057 |
snapzhp = zfs_open(zhp->zfs_hdl, snapname, ZFS_TYPE_SNAPSHOT); |
|
6476 | 1058 |
if (snapzhp == NULL) { |
1059 |
rv = -1; |
|
1060 |
} else { |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1061 |
if (sdd->filter_cb == NULL || |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1062 |
sdd->filter_cb(snapzhp, sdd->filter_cb_arg) == |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1063 |
B_TRUE) { |
11668
707c4515580e
6885979 zfs_send -R fails to send snapshots that get renamed during the operation
Chris Kirby <Chris.Kirby@sun.com>
parents:
11546
diff
changeset
|
1064 |
boolean_t got_enoent; |
707c4515580e
6885979 zfs_send -R fails to send snapshots that get renamed during the operation
Chris Kirby <Chris.Kirby@sun.com>
parents:
11546
diff
changeset
|
1065 |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1066 |
rv = dump_ioctl(snapzhp, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1067 |
missingfrom ? NULL : sdd->fromsnap, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1068 |
sdd->fromorigin || missingfrom, |
11668
707c4515580e
6885979 zfs_send -R fails to send snapshots that get renamed during the operation
Chris Kirby <Chris.Kirby@sun.com>
parents:
11546
diff
changeset
|
1069 |
sdd->outfd, B_FALSE, &got_enoent); |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1070 |
} |
6476 | 1071 |
sdd->seento = B_TRUE; |
1072 |
zfs_close(snapzhp); |
|
1073 |
} |
|
5367 | 1074 |
} |
1075 |
||
1076 |
return (rv); |
|
1077 |
} |
|
1078 |
||
1079 |
static int |
|
1080 |
dump_filesystems(zfs_handle_t *rzhp, void *arg) |
|
1081 |
{ |
|
1082 |
send_dump_data_t *sdd = arg; |
|
1083 |
nvpair_t *fspair; |
|
1084 |
boolean_t needagain, progress; |
|
1085 |
||
1086 |
if (!sdd->replicate) |
|
1087 |
return (dump_filesystem(rzhp, sdd)); |
|
1088 |
||
1089 |
again: |
|
1090 |
needagain = progress = B_FALSE; |
|
1091 |
for (fspair = nvlist_next_nvpair(sdd->fss, NULL); fspair; |
|
1092 |
fspair = nvlist_next_nvpair(sdd->fss, fspair)) { |
|
1093 |
nvlist_t *fslist; |
|
1094 |
char *fsname; |
|
1095 |
zfs_handle_t *zhp; |
|
1096 |
int err; |
|
1097 |
uint64_t origin_guid = 0; |
|
1098 |
nvlist_t *origin_nv; |
|
1099 |
||
1100 |
VERIFY(nvpair_value_nvlist(fspair, &fslist) == 0); |
|
1101 |
if (nvlist_lookup_boolean(fslist, "sent") == 0) |
|
1102 |
continue; |
|
1103 |
||
1104 |
VERIFY(nvlist_lookup_string(fslist, "name", &fsname) == 0); |
|
1105 |
(void) nvlist_lookup_uint64(fslist, "origin", &origin_guid); |
|
1106 |
||
1107 |
origin_nv = fsavl_find(sdd->fsavl, origin_guid, NULL); |
|
1108 |
if (origin_nv && |
|
1109 |
nvlist_lookup_boolean(origin_nv, "sent") == ENOENT) { |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1110 |
/* |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1111 |
* origin has not been sent yet; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1112 |
* skip this clone. |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1113 |
*/ |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1114 |
needagain = B_TRUE; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1115 |
continue; |
5367 | 1116 |
} |
1117 |
||
1118 |
zhp = zfs_open(rzhp->zfs_hdl, fsname, ZFS_TYPE_DATASET); |
|
6476 | 1119 |
if (zhp == NULL) |
1120 |
return (-1); |
|
5367 | 1121 |
err = dump_filesystem(zhp, sdd); |
1122 |
VERIFY(nvlist_add_boolean(fslist, "sent") == 0); |
|
1123 |
progress = B_TRUE; |
|
1124 |
zfs_close(zhp); |
|
1125 |
if (err) |
|
1126 |
return (err); |
|
1127 |
} |
|
1128 |
if (needagain) { |
|
1129 |
assert(progress); |
|
1130 |
goto again; |
|
1131 |
} |
|
1132 |
return (0); |
|
1133 |
} |
|
1134 |
||
1135 |
/* |
|
10200
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
1136 |
* Generate a send stream for the dataset identified by the argument zhp. |
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
1137 |
* |
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
1138 |
* The content of the send stream is the snapshot identified by |
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
1139 |
* 'tosnap'. Incremental streams are requested in two ways: |
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
1140 |
* - from the snapshot identified by "fromsnap" (if non-null) or |
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
1141 |
* - from the origin of the dataset identified by zhp, which must |
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
1142 |
* be a clone. In this case, "fromsnap" is null and "fromorigin" |
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
1143 |
* is TRUE. |
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
1144 |
* |
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
1145 |
* The send stream is recursive (i.e. dumps a hierarchy of snapshots) and |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1146 |
* uses a special header (with a hdrtype field of DMU_COMPOUNDSTREAM) |
10200
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
1147 |
* if "replicate" is set. If "doall" is set, dump all the intermediate |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1148 |
* snapshots. The DMU_COMPOUNDSTREAM header is used in the "doall" |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1149 |
* case too. If "props" is set, send properties. |
5367 | 1150 |
*/ |
1151 |
int |
|
1152 |
zfs_send(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap, |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1153 |
sendflags_t flags, int outfd, snapfilter_cb_t filter_func, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1154 |
void *cb_arg) |
5367 | 1155 |
{ |
1156 |
char errbuf[1024]; |
|
1157 |
send_dump_data_t sdd = { 0 }; |
|
1158 |
int err; |
|
1159 |
nvlist_t *fss = NULL; |
|
1160 |
avl_tree_t *fsavl = NULL; |
|
10342
108f0058f837
6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents:
10302
diff
changeset
|
1161 |
char holdtag[128]; |
108f0058f837
6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents:
10302
diff
changeset
|
1162 |
static uint64_t holdseq; |
10735
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1163 |
int spa_version; |
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1164 |
boolean_t holdsnaps = B_FALSE; |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1165 |
pthread_t tid; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1166 |
int pipefd[2]; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1167 |
dedup_arg_t dda = { 0 }; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1168 |
int featureflags = 0; |
5367 | 1169 |
|
11935
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
1170 |
if (zhp->zfs_type == ZFS_TYPE_FILESYSTEM) { |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
1171 |
uint64_t version; |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
1172 |
version = zfs_prop_get_int(zhp, ZFS_PROP_VERSION); |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
1173 |
if (version >= ZPL_VERSION_SA) { |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
1174 |
featureflags |= DMU_BACKUP_FEATURE_SA_SPILL; |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
1175 |
} |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
1176 |
} |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
1177 |
|
5367 | 1178 |
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, |
1179 |
"cannot send '%s'"), zhp->zfs_name); |
|
1180 |
||
1181 |
if (fromsnap && fromsnap[0] == '\0') { |
|
1182 |
zfs_error_aux(zhp->zfs_hdl, dgettext(TEXT_DOMAIN, |
|
1183 |
"zero-length incremental source")); |
|
1184 |
return (zfs_error(zhp->zfs_hdl, EZFS_NOENT, errbuf)); |
|
1185 |
} |
|
1186 |
||
10735
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1187 |
if (zfs_spa_version(zhp, &spa_version) == 0 && |
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1188 |
spa_version >= SPA_VERSION_USERREFS) |
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1189 |
holdsnaps = B_TRUE; |
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1190 |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1191 |
if (flags.dedup) { |
11381
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
1192 |
featureflags |= (DMU_BACKUP_FEATURE_DEDUP | |
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
1193 |
DMU_BACKUP_FEATURE_DEDUPPROPS); |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1194 |
if (err = pipe(pipefd)) { |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1195 |
zfs_error_aux(zhp->zfs_hdl, strerror(errno)); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1196 |
return (zfs_error(zhp->zfs_hdl, EZFS_PIPEFAILED, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1197 |
errbuf)); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1198 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1199 |
dda.outputfd = outfd; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1200 |
dda.inputfd = pipefd[1]; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1201 |
dda.dedup_hdl = zhp->zfs_hdl; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1202 |
if (err = pthread_create(&tid, NULL, cksummer, &dda)) { |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1203 |
(void) close(pipefd[0]); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1204 |
(void) close(pipefd[1]); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1205 |
zfs_error_aux(zhp->zfs_hdl, strerror(errno)); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1206 |
return (zfs_error(zhp->zfs_hdl, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1207 |
EZFS_THREADCREATEFAILED, errbuf)); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1208 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1209 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1210 |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1211 |
if (flags.replicate || flags.doall || flags.props) { |
5367 | 1212 |
dmu_replay_record_t drr = { 0 }; |
1213 |
char *packbuf = NULL; |
|
1214 |
size_t buflen = 0; |
|
1215 |
zio_cksum_t zc = { 0 }; |
|
1216 |
||
10735
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1217 |
if (holdsnaps) { |
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1218 |
(void) snprintf(holdtag, sizeof (holdtag), |
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1219 |
".send-%d-%llu", getpid(), (u_longlong_t)holdseq); |
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1220 |
++holdseq; |
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1221 |
err = zfs_hold_range(zhp, fromsnap, tosnap, |
11814
09d130965476
6505339 dsl_pool_close() needs to call txg_list_destroy(&dp->dp_sync_tasks) to be nice
Chris Kirby <Chris.Kirby@sun.com>
parents:
11668
diff
changeset
|
1222 |
holdtag, flags.replicate, B_TRUE, filter_func, |
09d130965476
6505339 dsl_pool_close() needs to call txg_list_destroy(&dp->dp_sync_tasks) to be nice
Chris Kirby <Chris.Kirby@sun.com>
parents:
11668
diff
changeset
|
1223 |
cb_arg); |
10735
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1224 |
if (err) |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1225 |
goto err_out; |
10735
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1226 |
} |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1227 |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1228 |
if (flags.replicate || flags.props) { |
5367 | 1229 |
nvlist_t *hdrnv; |
1230 |
||
1231 |
VERIFY(0 == nvlist_alloc(&hdrnv, NV_UNIQUE_NAME, 0)); |
|
1232 |
if (fromsnap) { |
|
1233 |
VERIFY(0 == nvlist_add_string(hdrnv, |
|
1234 |
"fromsnap", fromsnap)); |
|
1235 |
} |
|
1236 |
VERIFY(0 == nvlist_add_string(hdrnv, "tosnap", tosnap)); |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1237 |
if (!flags.replicate) { |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1238 |
VERIFY(0 == nvlist_add_boolean(hdrnv, |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1239 |
"not_recursive")); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1240 |
} |
5367 | 1241 |
|
1242 |
err = gather_nvlist(zhp->zfs_hdl, zhp->zfs_name, |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1243 |
fromsnap, tosnap, flags.replicate, &fss, &fsavl); |
10342
108f0058f837
6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents:
10302
diff
changeset
|
1244 |
if (err) { |
10735
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1245 |
if (holdsnaps) { |
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1246 |
(void) zfs_release_range(zhp, fromsnap, |
11546
42ea6be8961b
6915111 zfs_iter_snapshots() can miss snapshots
Chris Kirby <Chris.Kirby@sun.com>
parents:
11515
diff
changeset
|
1247 |
tosnap, holdtag, flags.replicate); |
10735
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1248 |
} |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1249 |
goto err_out; |
10342
108f0058f837
6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents:
10302
diff
changeset
|
1250 |
} |
5367 | 1251 |
VERIFY(0 == nvlist_add_nvlist(hdrnv, "fss", fss)); |
1252 |
err = nvlist_pack(hdrnv, &packbuf, &buflen, |
|
1253 |
NV_ENCODE_XDR, 0); |
|
1254 |
nvlist_free(hdrnv); |
|
1255 |
if (err) { |
|
1256 |
fsavl_destroy(fsavl); |
|
1257 |
nvlist_free(fss); |
|
10735
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1258 |
if (holdsnaps) { |
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1259 |
(void) zfs_release_range(zhp, fromsnap, |
11546
42ea6be8961b
6915111 zfs_iter_snapshots() can miss snapshots
Chris Kirby <Chris.Kirby@sun.com>
parents:
11515
diff
changeset
|
1260 |
tosnap, holdtag, flags.replicate); |
10735
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1261 |
} |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1262 |
goto stderr_out; |
5367 | 1263 |
} |
1264 |
} |
|
1265 |
||
1266 |
/* write first begin record */ |
|
1267 |
drr.drr_type = DRR_BEGIN; |
|
1268 |
drr.drr_u.drr_begin.drr_magic = DMU_BACKUP_MAGIC; |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1269 |
DMU_SET_STREAM_HDRTYPE(drr.drr_u.drr_begin.drr_versioninfo, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1270 |
DMU_COMPOUNDSTREAM); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1271 |
DMU_SET_FEATUREFLAGS(drr.drr_u.drr_begin.drr_versioninfo, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1272 |
featureflags); |
5367 | 1273 |
(void) snprintf(drr.drr_u.drr_begin.drr_toname, |
1274 |
sizeof (drr.drr_u.drr_begin.drr_toname), |
|
1275 |
"%s@%s", zhp->zfs_name, tosnap); |
|
1276 |
drr.drr_payloadlen = buflen; |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1277 |
err = cksum_and_write(&drr, sizeof (drr), &zc, outfd); |
5367 | 1278 |
|
1279 |
/* write header nvlist */ |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1280 |
if (err != -1 && packbuf != NULL) { |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1281 |
err = cksum_and_write(packbuf, buflen, &zc, outfd); |
5367 | 1282 |
} |
1283 |
free(packbuf); |
|
1284 |
if (err == -1) { |
|
1285 |
fsavl_destroy(fsavl); |
|
1286 |
nvlist_free(fss); |
|
10735
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1287 |
if (holdsnaps) { |
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1288 |
(void) zfs_release_range(zhp, fromsnap, tosnap, |
11546
42ea6be8961b
6915111 zfs_iter_snapshots() can miss snapshots
Chris Kirby <Chris.Kirby@sun.com>
parents:
11515
diff
changeset
|
1289 |
holdtag, flags.replicate); |
10735
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1290 |
} |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1291 |
err = errno; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1292 |
goto stderr_out; |
5367 | 1293 |
} |
1294 |
||
1295 |
/* write end record */ |
|
1296 |
if (err != -1) { |
|
1297 |
bzero(&drr, sizeof (drr)); |
|
1298 |
drr.drr_type = DRR_END; |
|
1299 |
drr.drr_u.drr_end.drr_checksum = zc; |
|
1300 |
err = write(outfd, &drr, sizeof (drr)); |
|
1301 |
if (err == -1) { |
|
1302 |
fsavl_destroy(fsavl); |
|
1303 |
nvlist_free(fss); |
|
11668
707c4515580e
6885979 zfs_send -R fails to send snapshots that get renamed during the operation
Chris Kirby <Chris.Kirby@sun.com>
parents:
11546
diff
changeset
|
1304 |
err = errno; |
10735
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1305 |
if (holdsnaps) { |
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1306 |
(void) zfs_release_range(zhp, fromsnap, |
11546
42ea6be8961b
6915111 zfs_iter_snapshots() can miss snapshots
Chris Kirby <Chris.Kirby@sun.com>
parents:
11515
diff
changeset
|
1307 |
tosnap, holdtag, flags.replicate); |
10735
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1308 |
} |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1309 |
goto stderr_out; |
5367 | 1310 |
} |
1311 |
} |
|
1312 |
} |
|
1313 |
||
1314 |
/* dump each stream */ |
|
1315 |
sdd.fromsnap = fromsnap; |
|
1316 |
sdd.tosnap = tosnap; |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1317 |
if (flags.dedup) |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1318 |
sdd.outfd = pipefd[0]; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1319 |
else |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1320 |
sdd.outfd = outfd; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1321 |
sdd.replicate = flags.replicate; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1322 |
sdd.doall = flags.doall; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1323 |
sdd.fromorigin = flags.fromorigin; |
5367 | 1324 |
sdd.fss = fss; |
1325 |
sdd.fsavl = fsavl; |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1326 |
sdd.verbose = flags.verbose; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1327 |
sdd.filter_cb = filter_func; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1328 |
sdd.filter_cb_arg = cb_arg; |
5367 | 1329 |
err = dump_filesystems(zhp, &sdd); |
1330 |
fsavl_destroy(fsavl); |
|
1331 |
nvlist_free(fss); |
|
1332 |
||
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1333 |
if (flags.dedup) { |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1334 |
(void) close(pipefd[0]); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1335 |
(void) pthread_join(tid, NULL); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1336 |
} |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1337 |
|
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1338 |
if (flags.replicate || flags.doall || flags.props) { |
5367 | 1339 |
/* |
1340 |
* write final end record. NB: want to do this even if |
|
1341 |
* there was some error, because it might not be totally |
|
1342 |
* failed. |
|
1343 |
*/ |
|
1344 |
dmu_replay_record_t drr = { 0 }; |
|
1345 |
drr.drr_type = DRR_END; |
|
10735
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1346 |
if (holdsnaps) { |
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1347 |
(void) zfs_release_range(zhp, fromsnap, tosnap, |
11546
42ea6be8961b
6915111 zfs_iter_snapshots() can miss snapshots
Chris Kirby <Chris.Kirby@sun.com>
parents:
11515
diff
changeset
|
1348 |
holdtag, flags.replicate); |
10735
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1349 |
} |
5367 | 1350 |
if (write(outfd, &drr, sizeof (drr)) == -1) { |
1351 |
return (zfs_standard_error(zhp->zfs_hdl, |
|
1352 |
errno, errbuf)); |
|
1353 |
} |
|
1354 |
} |
|
1355 |
||
1356 |
return (err || sdd.err); |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1357 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1358 |
stderr_out: |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1359 |
err = zfs_standard_error(zhp->zfs_hdl, err, errbuf); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1360 |
err_out: |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1361 |
if (flags.dedup) { |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1362 |
(void) pthread_cancel(tid); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1363 |
(void) pthread_join(tid, NULL); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1364 |
(void) close(pipefd[0]); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1365 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1366 |
return (err); |
5367 | 1367 |
} |
1368 |
||
1369 |
/* |
|
1370 |
* Routines specific to "zfs recv" |
|
1371 |
*/ |
|
1372 |
||
1373 |
static int |
|
1374 |
recv_read(libzfs_handle_t *hdl, int fd, void *buf, int ilen, |
|
1375 |
boolean_t byteswap, zio_cksum_t *zc) |
|
1376 |
{ |
|
1377 |
char *cp = buf; |
|
1378 |
int rv; |
|
1379 |
int len = ilen; |
|
1380 |
||
1381 |
do { |
|
1382 |
rv = read(fd, cp, len); |
|
1383 |
cp += rv; |
|
1384 |
len -= rv; |
|
1385 |
} while (rv > 0); |
|
1386 |
||
1387 |
if (rv < 0 || len != 0) { |
|
1388 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
1389 |
"failed to read from stream")); |
|
1390 |
return (zfs_error(hdl, EZFS_BADSTREAM, dgettext(TEXT_DOMAIN, |
|
1391 |
"cannot receive"))); |
|
1392 |
} |
|
1393 |
||
1394 |
if (zc) { |
|
1395 |
if (byteswap) |
|
1396 |
fletcher_4_incremental_byteswap(buf, ilen, zc); |
|
1397 |
else |
|
1398 |
fletcher_4_incremental_native(buf, ilen, zc); |
|
1399 |
} |
|
1400 |
return (0); |
|
1401 |
} |
|
1402 |
||
1403 |
static int |
|
1404 |
recv_read_nvlist(libzfs_handle_t *hdl, int fd, int len, nvlist_t **nvp, |
|
1405 |
boolean_t byteswap, zio_cksum_t *zc) |
|
1406 |
{ |
|
1407 |
char *buf; |
|
1408 |
int err; |
|
1409 |
||
1410 |
buf = zfs_alloc(hdl, len); |
|
1411 |
if (buf == NULL) |
|
1412 |
return (ENOMEM); |
|
1413 |
||
1414 |
err = recv_read(hdl, fd, buf, len, byteswap, zc); |
|
1415 |
if (err != 0) { |
|
1416 |
free(buf); |
|
1417 |
return (err); |
|
1418 |
} |
|
1419 |
||
1420 |
err = nvlist_unpack(buf, len, nvp, 0); |
|
1421 |
free(buf); |
|
1422 |
if (err != 0) { |
|
1423 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "invalid " |
|
1424 |
"stream (malformed nvlist)")); |
|
1425 |
return (EINVAL); |
|
1426 |
} |
|
1427 |
return (0); |
|
1428 |
} |
|
1429 |
||
1430 |
static int |
|
1431 |
recv_rename(libzfs_handle_t *hdl, const char *name, const char *tryname, |
|
1432 |
int baselen, char *newname, recvflags_t flags) |
|
1433 |
{ |
|
1434 |
static int seq; |
|
1435 |
zfs_cmd_t zc = { 0 }; |
|
1436 |
int err; |
|
6047
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1437 |
prop_changelist_t *clp; |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1438 |
zfs_handle_t *zhp; |
5367 | 1439 |
|
6047
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1440 |
zhp = zfs_open(hdl, name, ZFS_TYPE_DATASET); |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1441 |
if (zhp == NULL) |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1442 |
return (-1); |
7366
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
1443 |
clp = changelist_gather(zhp, ZFS_PROP_NAME, 0, |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
1444 |
flags.force ? MS_FORCE : 0); |
6047
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1445 |
zfs_close(zhp); |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1446 |
if (clp == NULL) |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1447 |
return (-1); |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1448 |
err = changelist_prefix(clp); |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1449 |
if (err) |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1450 |
return (err); |
5367 | 1451 |
|
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10200
diff
changeset
|
1452 |
zc.zc_objset_type = DMU_OST_ZFS; |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10200
diff
changeset
|
1453 |
(void) strlcpy(zc.zc_name, name, sizeof (zc.zc_name)); |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10200
diff
changeset
|
1454 |
|
5367 | 1455 |
if (tryname) { |
1456 |
(void) strcpy(newname, tryname); |
|
1457 |
||
1458 |
(void) strlcpy(zc.zc_value, tryname, sizeof (zc.zc_value)); |
|
1459 |
||
1460 |
if (flags.verbose) { |
|
1461 |
(void) printf("attempting rename %s to %s\n", |
|
1462 |
zc.zc_name, zc.zc_value); |
|
1463 |
} |
|
1464 |
err = ioctl(hdl->libzfs_fd, ZFS_IOC_RENAME, &zc); |
|
6047
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1465 |
if (err == 0) |
5367 | 1466 |
changelist_rename(clp, name, tryname); |
1467 |
} else { |
|
1468 |
err = ENOENT; |
|
1469 |
} |
|
1470 |
||
1471 |
if (err != 0 && strncmp(name+baselen, "recv-", 5) != 0) { |
|
1472 |
seq++; |
|
1473 |
||
1474 |
(void) strncpy(newname, name, baselen); |
|
1475 |
(void) snprintf(newname+baselen, ZFS_MAXNAMELEN-baselen, |
|
1476 |
"recv-%u-%u", getpid(), seq); |
|
1477 |
(void) strlcpy(zc.zc_value, newname, sizeof (zc.zc_value)); |
|
1478 |
||
1479 |
if (flags.verbose) { |
|
1480 |
(void) printf("failed - trying rename %s to %s\n", |
|
1481 |
zc.zc_name, zc.zc_value); |
|
1482 |
} |
|
1483 |
err = ioctl(hdl->libzfs_fd, ZFS_IOC_RENAME, &zc); |
|
6047
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1484 |
if (err == 0) |
5367 | 1485 |
changelist_rename(clp, name, newname); |
1486 |
if (err && flags.verbose) { |
|
1487 |
(void) printf("failed (%u) - " |
|
1488 |
"will try again on next pass\n", errno); |
|
1489 |
} |
|
1490 |
err = EAGAIN; |
|
1491 |
} else if (flags.verbose) { |
|
1492 |
if (err == 0) |
|
1493 |
(void) printf("success\n"); |
|
1494 |
else |
|
1495 |
(void) printf("failed (%u)\n", errno); |
|
1496 |
} |
|
1497 |
||
6047
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1498 |
(void) changelist_postfix(clp); |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1499 |
changelist_free(clp); |
5367 | 1500 |
|
1501 |
return (err); |
|
1502 |
} |
|
1503 |
||
1504 |
static int |
|
1505 |
recv_destroy(libzfs_handle_t *hdl, const char *name, int baselen, |
|
1506 |
char *newname, recvflags_t flags) |
|
1507 |
{ |
|
1508 |
zfs_cmd_t zc = { 0 }; |
|
6047
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1509 |
int err = 0; |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1510 |
prop_changelist_t *clp; |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1511 |
zfs_handle_t *zhp; |
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10200
diff
changeset
|
1512 |
boolean_t defer = B_FALSE; |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10200
diff
changeset
|
1513 |
int spa_version; |
6047
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1514 |
|
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1515 |
zhp = zfs_open(hdl, name, ZFS_TYPE_DATASET); |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1516 |
if (zhp == NULL) |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1517 |
return (-1); |
7366
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
1518 |
clp = changelist_gather(zhp, ZFS_PROP_NAME, 0, |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
1519 |
flags.force ? MS_FORCE : 0); |
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10200
diff
changeset
|
1520 |
if (zfs_get_type(zhp) == ZFS_TYPE_SNAPSHOT && |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10200
diff
changeset
|
1521 |
zfs_spa_version(zhp, &spa_version) == 0 && |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10200
diff
changeset
|
1522 |
spa_version >= SPA_VERSION_USERREFS) |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10200
diff
changeset
|
1523 |
defer = B_TRUE; |
6047
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1524 |
zfs_close(zhp); |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1525 |
if (clp == NULL) |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1526 |
return (-1); |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1527 |
err = changelist_prefix(clp); |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1528 |
if (err) |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1529 |
return (err); |
5367 | 1530 |
|
1531 |
zc.zc_objset_type = DMU_OST_ZFS; |
|
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10200
diff
changeset
|
1532 |
zc.zc_defer_destroy = defer; |
5367 | 1533 |
(void) strlcpy(zc.zc_name, name, sizeof (zc.zc_name)); |
1534 |
||
1535 |
if (flags.verbose) |
|
1536 |
(void) printf("attempting destroy %s\n", zc.zc_name); |
|
1537 |
err = ioctl(hdl->libzfs_fd, ZFS_IOC_DESTROY, &zc); |
|
6047
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1538 |
if (err == 0) { |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1539 |
if (flags.verbose) |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1540 |
(void) printf("success\n"); |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1541 |
changelist_remove(clp, zc.zc_name); |
5367 | 1542 |
} |
1543 |
||
6047
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1544 |
(void) changelist_postfix(clp); |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1545 |
changelist_free(clp); |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1546 |
|
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10200
diff
changeset
|
1547 |
/* |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1548 |
* Deferred destroy might destroy the snapshot or only mark it to be |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1549 |
* destroyed later, and it returns success in either case. |
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10200
diff
changeset
|
1550 |
*/ |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1551 |
if (err != 0 || (defer && zfs_dataset_exists(hdl, name, |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1552 |
ZFS_TYPE_SNAPSHOT))) { |
6047
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1553 |
err = recv_rename(hdl, name, NULL, baselen, newname, flags); |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1554 |
} |
5367 | 1555 |
|
1556 |
return (err); |
|
1557 |
} |
|
1558 |
||
1559 |
typedef struct guid_to_name_data { |
|
1560 |
uint64_t guid; |
|
1561 |
char *name; |
|
1562 |
} guid_to_name_data_t; |
|
1563 |
||
1564 |
static int |
|
1565 |
guid_to_name_cb(zfs_handle_t *zhp, void *arg) |
|
1566 |
{ |
|
1567 |
guid_to_name_data_t *gtnd = arg; |
|
1568 |
int err; |
|
1569 |
||
1570 |
if (zhp->zfs_dmustats.dds_guid == gtnd->guid) { |
|
1571 |
(void) strcpy(gtnd->name, zhp->zfs_name); |
|
11515
a122949107d4
6908211 'zfs inherit -S volsize <volume>' core dumps
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11461
diff
changeset
|
1572 |
zfs_close(zhp); |
5367 | 1573 |
return (EEXIST); |
1574 |
} |
|
1575 |
err = zfs_iter_children(zhp, guid_to_name_cb, gtnd); |
|
1576 |
zfs_close(zhp); |
|
1577 |
return (err); |
|
1578 |
} |
|
1579 |
||
1580 |
static int |
|
1581 |
guid_to_name(libzfs_handle_t *hdl, const char *parent, uint64_t guid, |
|
1582 |
char *name) |
|
1583 |
{ |
|
1584 |
/* exhaustive search all local snapshots */ |
|
1585 |
guid_to_name_data_t gtnd; |
|
1586 |
int err = 0; |
|
1587 |
zfs_handle_t *zhp; |
|
1588 |
char *cp; |
|
1589 |
||
1590 |
gtnd.guid = guid; |
|
1591 |
gtnd.name = name; |
|
1592 |
||
1593 |
if (strchr(parent, '@') == NULL) { |
|
1594 |
zhp = make_dataset_handle(hdl, parent); |
|
1595 |
if (zhp != NULL) { |
|
1596 |
err = zfs_iter_children(zhp, guid_to_name_cb, >nd); |
|
1597 |
zfs_close(zhp); |
|
1598 |
if (err == EEXIST) |
|
1599 |
return (0); |
|
1600 |
} |
|
1601 |
} |
|
1602 |
||
1603 |
cp = strchr(parent, '/'); |
|
1604 |
if (cp) |
|
1605 |
*cp = '\0'; |
|
1606 |
zhp = make_dataset_handle(hdl, parent); |
|
1607 |
if (cp) |
|
1608 |
*cp = '/'; |
|
1609 |
||
1610 |
if (zhp) { |
|
1611 |
err = zfs_iter_children(zhp, guid_to_name_cb, >nd); |
|
1612 |
zfs_close(zhp); |
|
1613 |
} |
|
1614 |
||
1615 |
return (err == EEXIST ? 0 : ENOENT); |
|
1616 |
||
1617 |
} |
|
1618 |
||
1619 |
/* |
|
1620 |
* Return true if dataset guid1 is created before guid2. |
|
1621 |
*/ |
|
6476 | 1622 |
static int |
5367 | 1623 |
created_before(libzfs_handle_t *hdl, avl_tree_t *avl, |
1624 |
uint64_t guid1, uint64_t guid2) |
|
1625 |
{ |
|
1626 |
nvlist_t *nvfs; |
|
1627 |
char *fsname, *snapname; |
|
1628 |
char buf[ZFS_MAXNAMELEN]; |
|
6476 | 1629 |
int rv; |
5367 | 1630 |
zfs_node_t zn1, zn2; |
1631 |
||
1632 |
if (guid2 == 0) |
|
6476 | 1633 |
return (0); |
5367 | 1634 |
if (guid1 == 0) |
6476 | 1635 |
return (1); |
5367 | 1636 |
|
1637 |
nvfs = fsavl_find(avl, guid1, &snapname); |
|
1638 |
VERIFY(0 == nvlist_lookup_string(nvfs, "name", &fsname)); |
|
1639 |
(void) snprintf(buf, sizeof (buf), "%s@%s", fsname, snapname); |
|
1640 |
zn1.zn_handle = zfs_open(hdl, buf, ZFS_TYPE_SNAPSHOT); |
|
6476 | 1641 |
if (zn1.zn_handle == NULL) |
1642 |
return (-1); |
|
5367 | 1643 |
|
1644 |
nvfs = fsavl_find(avl, guid2, &snapname); |
|
1645 |
VERIFY(0 == nvlist_lookup_string(nvfs, "name", &fsname)); |
|
1646 |
(void) snprintf(buf, sizeof (buf), "%s@%s", fsname, snapname); |
|
1647 |
zn2.zn_handle = zfs_open(hdl, buf, ZFS_TYPE_SNAPSHOT); |
|
6476 | 1648 |
if (zn2.zn_handle == NULL) { |
1649 |
zfs_close(zn2.zn_handle); |
|
1650 |
return (-1); |
|
1651 |
} |
|
5367 | 1652 |
|
1653 |
rv = (zfs_snapshot_compare(&zn1, &zn2) == -1); |
|
1654 |
||
1655 |
zfs_close(zn1.zn_handle); |
|
1656 |
zfs_close(zn2.zn_handle); |
|
1657 |
||
1658 |
return (rv); |
|
1659 |
} |
|
1660 |
||
1661 |
static int |
|
1662 |
recv_incremental_replication(libzfs_handle_t *hdl, const char *tofs, |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1663 |
recvflags_t flags, nvlist_t *stream_nv, avl_tree_t *stream_avl, |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1664 |
nvlist_t *renamed) |
5367 | 1665 |
{ |
1666 |
nvlist_t *local_nv; |
|
1667 |
avl_tree_t *local_avl; |
|
1668 |
nvpair_t *fselem, *nextfselem; |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1669 |
char *fromsnap; |
5367 | 1670 |
char newname[ZFS_MAXNAMELEN]; |
1671 |
int error; |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1672 |
boolean_t needagain, progress, recursive; |
10299
80845694147f
6696858 zfs receive of incremental replication stream can dereference NULL pointer and crash
Prabahar Jeyaram <Prabahar.Jeyaram@Sun.COM>
parents:
10242
diff
changeset
|
1673 |
char *s1, *s2; |
5367 | 1674 |
|
1675 |
VERIFY(0 == nvlist_lookup_string(stream_nv, "fromsnap", &fromsnap)); |
|
1676 |
||
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1677 |
recursive = (nvlist_lookup_boolean(stream_nv, "not_recursive") == |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1678 |
ENOENT); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1679 |
|
5367 | 1680 |
if (flags.dryrun) |
1681 |
return (0); |
|
1682 |
||
1683 |
again: |
|
1684 |
needagain = progress = B_FALSE; |
|
1685 |
||
1686 |
if ((error = gather_nvlist(hdl, tofs, fromsnap, NULL, |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1687 |
recursive, &local_nv, &local_avl)) != 0) |
5367 | 1688 |
return (error); |
1689 |
||
1690 |
/* |
|
1691 |
* Process deletes and renames |
|
1692 |
*/ |
|
1693 |
for (fselem = nvlist_next_nvpair(local_nv, NULL); |
|
1694 |
fselem; fselem = nextfselem) { |
|
1695 |
nvlist_t *nvfs, *snaps; |
|
1696 |
nvlist_t *stream_nvfs = NULL; |
|
1697 |
nvpair_t *snapelem, *nextsnapelem; |
|
1698 |
uint64_t fromguid = 0; |
|
1699 |
uint64_t originguid = 0; |
|
1700 |
uint64_t stream_originguid = 0; |
|
1701 |
uint64_t parent_fromsnap_guid, stream_parent_fromsnap_guid; |
|
1702 |
char *fsname, *stream_fsname; |
|
1703 |
||
1704 |
nextfselem = nvlist_next_nvpair(local_nv, fselem); |
|
1705 |
||
1706 |
VERIFY(0 == nvpair_value_nvlist(fselem, &nvfs)); |
|
1707 |
VERIFY(0 == nvlist_lookup_nvlist(nvfs, "snaps", &snaps)); |
|
1708 |
VERIFY(0 == nvlist_lookup_string(nvfs, "name", &fsname)); |
|
1709 |
VERIFY(0 == nvlist_lookup_uint64(nvfs, "parentfromsnap", |
|
1710 |
&parent_fromsnap_guid)); |
|
1711 |
(void) nvlist_lookup_uint64(nvfs, "origin", &originguid); |
|
1712 |
||
1713 |
/* |
|
1714 |
* First find the stream's fs, so we can check for |
|
1715 |
* a different origin (due to "zfs promote") |
|
1716 |
*/ |
|
1717 |
for (snapelem = nvlist_next_nvpair(snaps, NULL); |
|
1718 |
snapelem; snapelem = nvlist_next_nvpair(snaps, snapelem)) { |
|
1719 |
uint64_t thisguid; |
|
1720 |
||
1721 |
VERIFY(0 == nvpair_value_uint64(snapelem, &thisguid)); |
|
1722 |
stream_nvfs = fsavl_find(stream_avl, thisguid, NULL); |
|
1723 |
||
1724 |
if (stream_nvfs != NULL) |
|
1725 |
break; |
|
1726 |
} |
|
1727 |
||
1728 |
/* check for promote */ |
|
1729 |
(void) nvlist_lookup_uint64(stream_nvfs, "origin", |
|
1730 |
&stream_originguid); |
|
1731 |
if (stream_nvfs && originguid != stream_originguid) { |
|
6476 | 1732 |
switch (created_before(hdl, local_avl, |
1733 |
stream_originguid, originguid)) { |
|
1734 |
case 1: { |
|
5367 | 1735 |
/* promote it! */ |
1736 |
zfs_cmd_t zc = { 0 }; |
|
1737 |
nvlist_t *origin_nvfs; |
|
1738 |
char *origin_fsname; |
|
1739 |
||
1740 |
if (flags.verbose) |
|
1741 |
(void) printf("promoting %s\n", fsname); |
|
1742 |
||
1743 |
origin_nvfs = fsavl_find(local_avl, originguid, |
|
1744 |
NULL); |
|
1745 |
VERIFY(0 == nvlist_lookup_string(origin_nvfs, |
|
1746 |
"name", &origin_fsname)); |
|
1747 |
(void) strlcpy(zc.zc_value, origin_fsname, |
|
1748 |
sizeof (zc.zc_value)); |
|
1749 |
(void) strlcpy(zc.zc_name, fsname, |
|
1750 |
sizeof (zc.zc_name)); |
|
1751 |
error = zfs_ioctl(hdl, ZFS_IOC_PROMOTE, &zc); |
|
1752 |
if (error == 0) |
|
1753 |
progress = B_TRUE; |
|
6476 | 1754 |
break; |
1755 |
} |
|
1756 |
default: |
|
1757 |
break; |
|
1758 |
case -1: |
|
1759 |
fsavl_destroy(local_avl); |
|
1760 |
nvlist_free(local_nv); |
|
1761 |
return (-1); |
|
5367 | 1762 |
} |
1763 |
/* |
|
1764 |
* We had/have the wrong origin, therefore our |
|
1765 |
* list of snapshots is wrong. Need to handle |
|
1766 |
* them on the next pass. |
|
1767 |
*/ |
|
1768 |
needagain = B_TRUE; |
|
1769 |
continue; |
|
1770 |
} |
|
1771 |
||
1772 |
for (snapelem = nvlist_next_nvpair(snaps, NULL); |
|
1773 |
snapelem; snapelem = nextsnapelem) { |
|
1774 |
uint64_t thisguid; |
|
1775 |
char *stream_snapname; |
|
7265 | 1776 |
nvlist_t *found, *props; |
5367 | 1777 |
|
1778 |
nextsnapelem = nvlist_next_nvpair(snaps, snapelem); |
|
1779 |
||
1780 |
VERIFY(0 == nvpair_value_uint64(snapelem, &thisguid)); |
|
1781 |
found = fsavl_find(stream_avl, thisguid, |
|
1782 |
&stream_snapname); |
|
1783 |
||
1784 |
/* check for delete */ |
|
1785 |
if (found == NULL) { |
|
1786 |
char name[ZFS_MAXNAMELEN]; |
|
1787 |
||
1788 |
if (!flags.force) |
|
1789 |
continue; |
|
1790 |
||
1791 |
(void) snprintf(name, sizeof (name), "%s@%s", |
|
1792 |
fsname, nvpair_name(snapelem)); |
|
1793 |
||
1794 |
error = recv_destroy(hdl, name, |
|
1795 |
strlen(fsname)+1, newname, flags); |
|
1796 |
if (error) |
|
1797 |
needagain = B_TRUE; |
|
1798 |
else |
|
1799 |
progress = B_TRUE; |
|
1800 |
continue; |
|
1801 |
} |
|
1802 |
||
1803 |
stream_nvfs = found; |
|
1804 |
||
7265 | 1805 |
if (0 == nvlist_lookup_nvlist(stream_nvfs, "snapprops", |
1806 |
&props) && 0 == nvlist_lookup_nvlist(props, |
|
1807 |
stream_snapname, &props)) { |
|
1808 |
zfs_cmd_t zc = { 0 }; |
|
1809 |
||
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1810 |
zc.zc_cookie = B_TRUE; /* received */ |
7273
6baaca4d907c
6701797 want user properties on snapshots (fix lint)
ahrens
parents:
7265
diff
changeset
|
1811 |
(void) snprintf(zc.zc_name, sizeof (zc.zc_name), |
7265 | 1812 |
"%s@%s", fsname, nvpair_name(snapelem)); |
1813 |
if (zcmd_write_src_nvlist(hdl, &zc, |
|
1814 |
props) == 0) { |
|
1815 |
(void) zfs_ioctl(hdl, |
|
1816 |
ZFS_IOC_SET_PROP, &zc); |
|
1817 |
zcmd_free_nvlists(&zc); |
|
1818 |
} |
|
1819 |
} |
|
1820 |
||
5367 | 1821 |
/* check for different snapname */ |
1822 |
if (strcmp(nvpair_name(snapelem), |
|
1823 |
stream_snapname) != 0) { |
|
1824 |
char name[ZFS_MAXNAMELEN]; |
|
1825 |
char tryname[ZFS_MAXNAMELEN]; |
|
1826 |
||
1827 |
(void) snprintf(name, sizeof (name), "%s@%s", |
|
1828 |
fsname, nvpair_name(snapelem)); |
|
1829 |
(void) snprintf(tryname, sizeof (name), "%s@%s", |
|
1830 |
fsname, stream_snapname); |
|
1831 |
||
1832 |
error = recv_rename(hdl, name, tryname, |
|
1833 |
strlen(fsname)+1, newname, flags); |
|
1834 |
if (error) |
|
1835 |
needagain = B_TRUE; |
|
1836 |
else |
|
1837 |
progress = B_TRUE; |
|
1838 |
} |
|
1839 |
||
1840 |
if (strcmp(stream_snapname, fromsnap) == 0) |
|
1841 |
fromguid = thisguid; |
|
1842 |
} |
|
1843 |
||
1844 |
/* check for delete */ |
|
1845 |
if (stream_nvfs == NULL) { |
|
1846 |
if (!flags.force) |
|
1847 |
continue; |
|
1848 |
||
1849 |
error = recv_destroy(hdl, fsname, strlen(tofs)+1, |
|
1850 |
newname, flags); |
|
1851 |
if (error) |
|
1852 |
needagain = B_TRUE; |
|
1853 |
else |
|
1854 |
progress = B_TRUE; |
|
1855 |
continue; |
|
1856 |
} |
|
1857 |
||
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1858 |
if (fromguid == 0) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1859 |
if (flags.verbose) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1860 |
(void) printf("local fs %s does not have " |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1861 |
"fromsnap (%s in stream); must have " |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1862 |
"been deleted locally; ignoring\n", |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1863 |
fsname, fromsnap); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1864 |
} |
5367 | 1865 |
continue; |
1866 |
} |
|
1867 |
||
1868 |
VERIFY(0 == nvlist_lookup_string(stream_nvfs, |
|
1869 |
"name", &stream_fsname)); |
|
1870 |
VERIFY(0 == nvlist_lookup_uint64(stream_nvfs, |
|
1871 |
"parentfromsnap", &stream_parent_fromsnap_guid)); |
|
1872 |
||
10302
a9e3d1987706
6696858 zfs receive of incremental replication stream can dereference NULL pointer and crash (fix lint)
Prabahar Jeyaram <Prabahar.Jeyaram@Sun.COM>
parents:
10299
diff
changeset
|
1873 |
s1 = strrchr(fsname, '/'); |
a9e3d1987706
6696858 zfs receive of incremental replication stream can dereference NULL pointer and crash (fix lint)
Prabahar Jeyaram <Prabahar.Jeyaram@Sun.COM>
parents:
10299
diff
changeset
|
1874 |
s2 = strrchr(stream_fsname, '/'); |
a9e3d1987706
6696858 zfs receive of incremental replication stream can dereference NULL pointer and crash (fix lint)
Prabahar Jeyaram <Prabahar.Jeyaram@Sun.COM>
parents:
10299
diff
changeset
|
1875 |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1876 |
/* |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1877 |
* Check for rename. If the exact receive path is specified, it |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1878 |
* does not count as a rename, but we still need to check the |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1879 |
* datasets beneath it. |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1880 |
*/ |
5367 | 1881 |
if ((stream_parent_fromsnap_guid != 0 && |
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1882 |
parent_fromsnap_guid != 0 && |
5367 | 1883 |
stream_parent_fromsnap_guid != parent_fromsnap_guid) || |
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1884 |
((flags.isprefix || strcmp(tofs, fsname) != 0) && |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1885 |
(s1 != NULL) && (s2 != NULL) && strcmp(s1, s2) != 0)) { |
5367 | 1886 |
nvlist_t *parent; |
1887 |
char tryname[ZFS_MAXNAMELEN]; |
|
1888 |
||
1889 |
parent = fsavl_find(local_avl, |
|
1890 |
stream_parent_fromsnap_guid, NULL); |
|
1891 |
/* |
|
1892 |
* NB: parent might not be found if we used the |
|
1893 |
* tosnap for stream_parent_fromsnap_guid, |
|
1894 |
* because the parent is a newly-created fs; |
|
1895 |
* we'll be able to rename it after we recv the |
|
1896 |
* new fs. |
|
1897 |
*/ |
|
1898 |
if (parent != NULL) { |
|
1899 |
char *pname; |
|
1900 |
||
1901 |
VERIFY(0 == nvlist_lookup_string(parent, "name", |
|
1902 |
&pname)); |
|
1903 |
(void) snprintf(tryname, sizeof (tryname), |
|
1904 |
"%s%s", pname, strrchr(stream_fsname, '/')); |
|
1905 |
} else { |
|
1906 |
tryname[0] = '\0'; |
|
1907 |
if (flags.verbose) { |
|
1908 |
(void) printf("local fs %s new parent " |
|
1909 |
"not found\n", fsname); |
|
1910 |
} |
|
1911 |
} |
|
1912 |
||
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1913 |
newname[0] = '\0'; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1914 |
|
5367 | 1915 |
error = recv_rename(hdl, fsname, tryname, |
1916 |
strlen(tofs)+1, newname, flags); |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1917 |
|
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1918 |
if (renamed != NULL && newname[0] != '\0') { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1919 |
VERIFY(0 == nvlist_add_boolean(renamed, |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1920 |
newname)); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1921 |
} |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1922 |
|
5367 | 1923 |
if (error) |
1924 |
needagain = B_TRUE; |
|
1925 |
else |
|
1926 |
progress = B_TRUE; |
|
1927 |
} |
|
1928 |
} |
|
1929 |
||
1930 |
fsavl_destroy(local_avl); |
|
1931 |
nvlist_free(local_nv); |
|
1932 |
||
1933 |
if (needagain && progress) { |
|
1934 |
/* do another pass to fix up temporary names */ |
|
1935 |
if (flags.verbose) |
|
1936 |
(void) printf("another pass:\n"); |
|
1937 |
goto again; |
|
1938 |
} |
|
1939 |
||
1940 |
return (needagain); |
|
1941 |
} |
|
1942 |
||
1943 |
static int |
|
1944 |
zfs_receive_package(libzfs_handle_t *hdl, int fd, const char *destname, |
|
7366
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
1945 |
recvflags_t flags, dmu_replay_record_t *drr, zio_cksum_t *zc, |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
1946 |
char **top_zfs) |
5367 | 1947 |
{ |
1948 |
nvlist_t *stream_nv = NULL; |
|
1949 |
avl_tree_t *stream_avl = NULL; |
|
1950 |
char *fromsnap = NULL; |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1951 |
char *cp; |
5367 | 1952 |
char tofs[ZFS_MAXNAMELEN]; |
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1953 |
char sendfs[ZFS_MAXNAMELEN]; |
5367 | 1954 |
char errbuf[1024]; |
1955 |
dmu_replay_record_t drre; |
|
1956 |
int error; |
|
1957 |
boolean_t anyerr = B_FALSE; |
|
6479 | 1958 |
boolean_t softerr = B_FALSE; |
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1959 |
boolean_t recursive; |
5367 | 1960 |
|
1961 |
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, |
|
1962 |
"cannot receive")); |
|
1963 |
||
1964 |
assert(drr->drr_type == DRR_BEGIN); |
|
1965 |
assert(drr->drr_u.drr_begin.drr_magic == DMU_BACKUP_MAGIC); |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1966 |
assert(DMU_GET_STREAM_HDRTYPE(drr->drr_u.drr_begin.drr_versioninfo) == |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1967 |
DMU_COMPOUNDSTREAM); |
5367 | 1968 |
|
1969 |
/* |
|
1970 |
* Read in the nvlist from the stream. |
|
1971 |
*/ |
|
1972 |
if (drr->drr_payloadlen != 0) { |
|
1973 |
error = recv_read_nvlist(hdl, fd, drr->drr_payloadlen, |
|
1974 |
&stream_nv, flags.byteswap, zc); |
|
1975 |
if (error) { |
|
1976 |
error = zfs_error(hdl, EZFS_BADSTREAM, errbuf); |
|
1977 |
goto out; |
|
1978 |
} |
|
1979 |
} |
|
1980 |
||
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1981 |
recursive = (nvlist_lookup_boolean(stream_nv, "not_recursive") == |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1982 |
ENOENT); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1983 |
|
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1984 |
if (recursive && strchr(destname, '@')) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1985 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1986 |
"cannot specify snapshot name for multi-snapshot stream")); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1987 |
error = zfs_error(hdl, EZFS_BADSTREAM, errbuf); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1988 |
goto out; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1989 |
} |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1990 |
|
5367 | 1991 |
/* |
1992 |
* Read in the end record and verify checksum. |
|
1993 |
*/ |
|
1994 |
if (0 != (error = recv_read(hdl, fd, &drre, sizeof (drre), |
|
1995 |
flags.byteswap, NULL))) |
|
1996 |
goto out; |
|
1997 |
if (flags.byteswap) { |
|
1998 |
drre.drr_type = BSWAP_32(drre.drr_type); |
|
1999 |
drre.drr_u.drr_end.drr_checksum.zc_word[0] = |
|
2000 |
BSWAP_64(drre.drr_u.drr_end.drr_checksum.zc_word[0]); |
|
2001 |
drre.drr_u.drr_end.drr_checksum.zc_word[1] = |
|
2002 |
BSWAP_64(drre.drr_u.drr_end.drr_checksum.zc_word[1]); |
|
2003 |
drre.drr_u.drr_end.drr_checksum.zc_word[2] = |
|
2004 |
BSWAP_64(drre.drr_u.drr_end.drr_checksum.zc_word[2]); |
|
2005 |
drre.drr_u.drr_end.drr_checksum.zc_word[3] = |
|
2006 |
BSWAP_64(drre.drr_u.drr_end.drr_checksum.zc_word[3]); |
|
2007 |
} |
|
2008 |
if (drre.drr_type != DRR_END) { |
|
2009 |
error = zfs_error(hdl, EZFS_BADSTREAM, errbuf); |
|
2010 |
goto out; |
|
2011 |
} |
|
2012 |
if (!ZIO_CHECKSUM_EQUAL(drre.drr_u.drr_end.drr_checksum, *zc)) { |
|
2013 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
2014 |
"incorrect header checksum")); |
|
2015 |
error = zfs_error(hdl, EZFS_BADSTREAM, errbuf); |
|
2016 |
goto out; |
|
2017 |
} |
|
2018 |
||
2019 |
(void) nvlist_lookup_string(stream_nv, "fromsnap", &fromsnap); |
|
2020 |
||
2021 |
if (drr->drr_payloadlen != 0) { |
|
2022 |
nvlist_t *stream_fss; |
|
2023 |
||
2024 |
VERIFY(0 == nvlist_lookup_nvlist(stream_nv, "fss", |
|
2025 |
&stream_fss)); |
|
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2026 |
if ((stream_avl = fsavl_create(stream_fss)) == NULL) { |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2027 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2028 |
"couldn't allocate avl tree")); |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2029 |
error = zfs_error(hdl, EZFS_NOMEM, errbuf); |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2030 |
goto out; |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2031 |
} |
5367 | 2032 |
|
2033 |
if (fromsnap != NULL) { |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2034 |
nvlist_t *renamed = NULL; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2035 |
nvpair_t *pair = NULL; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2036 |
|
5367 | 2037 |
(void) strlcpy(tofs, destname, ZFS_MAXNAMELEN); |
2038 |
if (flags.isprefix) { |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2039 |
struct drr_begin *drrb = &drr->drr_u.drr_begin; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2040 |
int i; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2041 |
|
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2042 |
if (flags.istail) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2043 |
cp = strrchr(drrb->drr_toname, '/'); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2044 |
if (cp == NULL) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2045 |
(void) strlcat(tofs, "/", |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2046 |
ZFS_MAXNAMELEN); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2047 |
i = 0; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2048 |
} else { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2049 |
i = (cp - drrb->drr_toname); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2050 |
} |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2051 |
} else { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2052 |
i = strcspn(drrb->drr_toname, "/@"); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2053 |
} |
5367 | 2054 |
/* zfs_receive_one() will create_parents() */ |
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2055 |
(void) strlcat(tofs, &drrb->drr_toname[i], |
5367 | 2056 |
ZFS_MAXNAMELEN); |
2057 |
*strchr(tofs, '@') = '\0'; |
|
2058 |
} |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2059 |
|
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2060 |
if (recursive && !flags.dryrun && !flags.nomount) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2061 |
VERIFY(0 == nvlist_alloc(&renamed, |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2062 |
NV_UNIQUE_NAME, 0)); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2063 |
} |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2064 |
|
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2065 |
softerr = recv_incremental_replication(hdl, tofs, flags, |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2066 |
stream_nv, stream_avl, renamed); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2067 |
|
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2068 |
/* Unmount renamed filesystems before receiving. */ |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2069 |
while ((pair = nvlist_next_nvpair(renamed, |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2070 |
pair)) != NULL) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2071 |
zfs_handle_t *zhp; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2072 |
prop_changelist_t *clp = NULL; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2073 |
|
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2074 |
zhp = zfs_open(hdl, nvpair_name(pair), |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2075 |
ZFS_TYPE_FILESYSTEM); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2076 |
if (zhp != NULL) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2077 |
clp = changelist_gather(zhp, |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2078 |
ZFS_PROP_MOUNTPOINT, 0, 0); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2079 |
zfs_close(zhp); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2080 |
if (clp != NULL) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2081 |
softerr |= |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2082 |
changelist_prefix(clp); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2083 |
changelist_free(clp); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2084 |
} |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2085 |
} |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2086 |
} |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2087 |
|
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2088 |
nvlist_free(renamed); |
5367 | 2089 |
} |
2090 |
} |
|
2091 |
||
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2092 |
/* |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2093 |
* Get the fs specified by the first path in the stream (the top level |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2094 |
* specified by 'zfs send') and pass it to each invocation of |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2095 |
* zfs_receive_one(). |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2096 |
*/ |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2097 |
(void) strlcpy(sendfs, drr->drr_u.drr_begin.drr_toname, |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2098 |
ZFS_MAXNAMELEN); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2099 |
if ((cp = strchr(sendfs, '@')) != NULL) |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2100 |
*cp = '\0'; |
5367 | 2101 |
|
2102 |
/* Finally, receive each contained stream */ |
|
2103 |
do { |
|
2104 |
/* |
|
2105 |
* we should figure out if it has a recoverable |
|
2106 |
* error, in which case do a recv_skip() and drive on. |
|
2107 |
* Note, if we fail due to already having this guid, |
|
2108 |
* zfs_receive_one() will take care of it (ie, |
|
2109 |
* recv_skip() and return 0). |
|
2110 |
*/ |
|
7366
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2111 |
error = zfs_receive_impl(hdl, destname, flags, fd, |
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2112 |
sendfs, stream_nv, stream_avl, top_zfs); |
5367 | 2113 |
if (error == ENODATA) { |
2114 |
error = 0; |
|
2115 |
break; |
|
2116 |
} |
|
2117 |
anyerr |= error; |
|
2118 |
} while (error == 0); |
|
2119 |
||
2120 |
if (drr->drr_payloadlen != 0 && fromsnap != NULL) { |
|
2121 |
/* |
|
2122 |
* Now that we have the fs's they sent us, try the |
|
2123 |
* renames again. |
|
2124 |
*/ |
|
6479 | 2125 |
softerr = recv_incremental_replication(hdl, tofs, flags, |
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2126 |
stream_nv, stream_avl, NULL); |
5367 | 2127 |
} |
2128 |
||
2129 |
out: |
|
2130 |
fsavl_destroy(stream_avl); |
|
2131 |
if (stream_nv) |
|
2132 |
nvlist_free(stream_nv); |
|
6479 | 2133 |
if (softerr) |
2134 |
error = -2; |
|
5367 | 2135 |
if (anyerr) |
2136 |
error = -1; |
|
2137 |
return (error); |
|
2138 |
} |
|
2139 |
||
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2140 |
static void |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2141 |
trunc_prop_errs(int truncated) |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2142 |
{ |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2143 |
ASSERT(truncated != 0); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2144 |
|
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2145 |
if (truncated == 1) |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2146 |
(void) fprintf(stderr, dgettext(TEXT_DOMAIN, |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2147 |
"1 more property could not be set\n")); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2148 |
else |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2149 |
(void) fprintf(stderr, dgettext(TEXT_DOMAIN, |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2150 |
"%d more properties could not be set\n"), truncated); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2151 |
} |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2152 |
|
5367 | 2153 |
static int |
2154 |
recv_skip(libzfs_handle_t *hdl, int fd, boolean_t byteswap) |
|
2155 |
{ |
|
2156 |
dmu_replay_record_t *drr; |
|
2157 |
void *buf = malloc(1<<20); |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2158 |
char errbuf[1024]; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2159 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2160 |
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2161 |
"cannot receive:")); |
5367 | 2162 |
|
2163 |
/* XXX would be great to use lseek if possible... */ |
|
2164 |
drr = buf; |
|
2165 |
||
2166 |
while (recv_read(hdl, fd, drr, sizeof (dmu_replay_record_t), |
|
2167 |
byteswap, NULL) == 0) { |
|
2168 |
if (byteswap) |
|
2169 |
drr->drr_type = BSWAP_32(drr->drr_type); |
|
2170 |
||
2171 |
switch (drr->drr_type) { |
|
2172 |
case DRR_BEGIN: |
|
2173 |
/* NB: not to be used on v2 stream packages */ |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2174 |
if (drr->drr_payloadlen != 0) { |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2175 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2176 |
"invalid substream header")); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2177 |
return (zfs_error(hdl, EZFS_BADSTREAM, errbuf)); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2178 |
} |
5367 | 2179 |
break; |
2180 |
||
2181 |
case DRR_END: |
|
2182 |
free(buf); |
|
2183 |
return (0); |
|
2184 |
||
2185 |
case DRR_OBJECT: |
|
2186 |
if (byteswap) { |
|
2187 |
drr->drr_u.drr_object.drr_bonuslen = |
|
2188 |
BSWAP_32(drr->drr_u.drr_object. |
|
2189 |
drr_bonuslen); |
|
2190 |
} |
|
2191 |
(void) recv_read(hdl, fd, buf, |
|
2192 |
P2ROUNDUP(drr->drr_u.drr_object.drr_bonuslen, 8), |
|
2193 |
B_FALSE, NULL); |
|
2194 |
break; |
|
2195 |
||
2196 |
case DRR_WRITE: |
|
2197 |
if (byteswap) { |
|
2198 |
drr->drr_u.drr_write.drr_length = |
|
7366
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2199 |
BSWAP_64(drr->drr_u.drr_write.drr_length); |
5367 | 2200 |
} |
2201 |
(void) recv_read(hdl, fd, buf, |
|
2202 |
drr->drr_u.drr_write.drr_length, B_FALSE, NULL); |
|
2203 |
break; |
|
11935
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
2204 |
case DRR_SPILL: |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
2205 |
if (byteswap) { |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
2206 |
drr->drr_u.drr_write.drr_length = |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
2207 |
BSWAP_64(drr->drr_u.drr_spill.drr_length); |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
2208 |
} |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
2209 |
(void) recv_read(hdl, fd, buf, |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
2210 |
drr->drr_u.drr_spill.drr_length, B_FALSE, NULL); |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
2211 |
break; |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2212 |
case DRR_WRITE_BYREF: |
5367 | 2213 |
case DRR_FREEOBJECTS: |
2214 |
case DRR_FREE: |
|
2215 |
break; |
|
2216 |
||
2217 |
default: |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2218 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2219 |
"invalid record type")); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2220 |
return (zfs_error(hdl, EZFS_BADSTREAM, errbuf)); |
5367 | 2221 |
} |
2222 |
} |
|
2223 |
||
2224 |
free(buf); |
|
2225 |
return (-1); |
|
2226 |
} |
|
2227 |
||
2228 |
/* |
|
2229 |
* Restores a backup of tosnap from the file descriptor specified by infd. |
|
2230 |
*/ |
|
2231 |
static int |
|
2232 |
zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap, |
|
2233 |
recvflags_t flags, dmu_replay_record_t *drr, |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2234 |
dmu_replay_record_t *drr_noswap, const char *sendfs, |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2235 |
nvlist_t *stream_nv, avl_tree_t *stream_avl, char **top_zfs) |
5367 | 2236 |
{ |
2237 |
zfs_cmd_t zc = { 0 }; |
|
2238 |
time_t begin_time; |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2239 |
int ioctl_err, ioctl_errno, err; |
5367 | 2240 |
char *cp; |
2241 |
struct drr_begin *drrb = &drr->drr_u.drr_begin; |
|
2242 |
char errbuf[1024]; |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2243 |
char prop_errbuf[1024]; |
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2244 |
const char *chopprefix; |
5367 | 2245 |
boolean_t newfs = B_FALSE; |
2246 |
boolean_t stream_wantsnewfs; |
|
2247 |
uint64_t parent_snapguid = 0; |
|
2248 |
prop_changelist_t *clp = NULL; |
|
7265 | 2249 |
nvlist_t *snapprops_nvlist = NULL; |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2250 |
zprop_errflags_t prop_errflags; |
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2251 |
boolean_t recursive; |
5367 | 2252 |
|
2253 |
begin_time = time(NULL); |
|
2254 |
||
2255 |
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, |
|
2256 |
"cannot receive")); |
|
2257 |
||
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2258 |
recursive = (nvlist_lookup_boolean(stream_nv, "not_recursive") == |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2259 |
ENOENT); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2260 |
|
5367 | 2261 |
if (stream_avl != NULL) { |
7265 | 2262 |
char *snapname; |
2263 |
nvlist_t *fs = fsavl_find(stream_avl, drrb->drr_toguid, |
|
2264 |
&snapname); |
|
5367 | 2265 |
nvlist_t *props; |
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2266 |
int ret; |
5367 | 2267 |
|
2268 |
(void) nvlist_lookup_uint64(fs, "parentfromsnap", |
|
2269 |
&parent_snapguid); |
|
2270 |
err = nvlist_lookup_nvlist(fs, "props", &props); |
|
2271 |
if (err) |
|
2272 |
VERIFY(0 == nvlist_alloc(&props, NV_UNIQUE_NAME, 0)); |
|
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2273 |
|
5367 | 2274 |
if (flags.canmountoff) { |
2275 |
VERIFY(0 == nvlist_add_uint64(props, |
|
2276 |
zfs_prop_to_name(ZFS_PROP_CANMOUNT), 0)); |
|
2277 |
} |
|
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2278 |
ret = zcmd_write_src_nvlist(hdl, &zc, props); |
5367 | 2279 |
if (err) |
2280 |
nvlist_free(props); |
|
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2281 |
|
7265 | 2282 |
if (0 == nvlist_lookup_nvlist(fs, "snapprops", &props)) { |
2283 |
VERIFY(0 == nvlist_lookup_nvlist(props, |
|
2284 |
snapname, &snapprops_nvlist)); |
|
2285 |
} |
|
2286 |
||
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2287 |
if (ret != 0) |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2288 |
return (-1); |
5367 | 2289 |
} |
2290 |
||
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2291 |
cp = NULL; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2292 |
|
5367 | 2293 |
/* |
2294 |
* Determine how much of the snapshot name stored in the stream |
|
2295 |
* we are going to tack on to the name they specified on the |
|
2296 |
* command line, and how much we are going to chop off. |
|
2297 |
* |
|
2298 |
* If they specified a snapshot, chop the entire name stored in |
|
2299 |
* the stream. |
|
2300 |
*/ |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2301 |
if (flags.istail) { |
5367 | 2302 |
/* |
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2303 |
* A filesystem was specified with -e. We want to tack on only |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2304 |
* the tail of the sent snapshot path. |
5367 | 2305 |
*/ |
2306 |
if (strchr(tosnap, '@')) { |
|
2307 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "invalid " |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2308 |
"argument - snapshot not allowed with -e")); |
5367 | 2309 |
return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf)); |
2310 |
} |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2311 |
|
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2312 |
chopprefix = strrchr(sendfs, '/'); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2313 |
|
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2314 |
if (chopprefix == NULL) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2315 |
/* |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2316 |
* The tail is the poolname, so we need to |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2317 |
* prepend a path separator. |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2318 |
*/ |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2319 |
int len = strlen(drrb->drr_toname); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2320 |
cp = malloc(len + 2); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2321 |
cp[0] = '/'; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2322 |
(void) strcpy(&cp[1], drrb->drr_toname); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2323 |
chopprefix = cp; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2324 |
} else { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2325 |
chopprefix = drrb->drr_toname + (chopprefix - sendfs); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2326 |
} |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2327 |
} else if (flags.isprefix) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2328 |
/* |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2329 |
* A filesystem was specified with -d. We want to tack on |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2330 |
* everything but the first element of the sent snapshot path |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2331 |
* (all but the pool name). |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2332 |
*/ |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2333 |
if (strchr(tosnap, '@')) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2334 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "invalid " |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2335 |
"argument - snapshot not allowed with -d")); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2336 |
return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf)); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2337 |
} |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2338 |
|
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2339 |
chopprefix = strchr(drrb->drr_toname, '/'); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2340 |
if (chopprefix == NULL) |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2341 |
chopprefix = strchr(drrb->drr_toname, '@'); |
5367 | 2342 |
} else if (strchr(tosnap, '@') == NULL) { |
2343 |
/* |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2344 |
* If a filesystem was specified without -d or -e, we want to |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2345 |
* tack on everything after the fs specified by 'zfs send'. |
5367 | 2346 |
*/ |
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2347 |
chopprefix = drrb->drr_toname + strlen(sendfs); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2348 |
} else { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2349 |
/* A snapshot was specified as an exact path (no -d or -e). */ |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2350 |
if (recursive) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2351 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2352 |
"cannot specify snapshot name for multi-snapshot " |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2353 |
"stream")); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2354 |
return (zfs_error(hdl, EZFS_BADSTREAM, errbuf)); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2355 |
} |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2356 |
chopprefix = drrb->drr_toname + strlen(drrb->drr_toname); |
5367 | 2357 |
} |
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2358 |
|
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2359 |
ASSERT(strstr(drrb->drr_toname, sendfs) == drrb->drr_toname); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2360 |
ASSERT(chopprefix > drrb->drr_toname); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2361 |
ASSERT(chopprefix <= drrb->drr_toname + strlen(drrb->drr_toname)); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2362 |
ASSERT(chopprefix[0] == '/' || chopprefix[0] == '@' || |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2363 |
chopprefix[0] == '\0'); |
5367 | 2364 |
|
2365 |
/* |
|
2366 |
* Determine name of destination snapshot, store in zc_value. |
|
2367 |
*/ |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2368 |
(void) strcpy(zc.zc_top_ds, tosnap); |
5367 | 2369 |
(void) strcpy(zc.zc_value, tosnap); |
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2370 |
(void) strncat(zc.zc_value, chopprefix, sizeof (zc.zc_value)); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2371 |
free(cp); |
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2372 |
if (!zfs_name_valid(zc.zc_value, ZFS_TYPE_SNAPSHOT)) { |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2373 |
zcmd_free_nvlists(&zc); |
5367 | 2374 |
return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf)); |
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2375 |
} |
5367 | 2376 |
|
2377 |
/* |
|
2378 |
* Determine the name of the origin snapshot, store in zc_string. |
|
2379 |
*/ |
|
2380 |
if (drrb->drr_flags & DRR_FLAG_CLONE) { |
|
2381 |
if (guid_to_name(hdl, tosnap, |
|
2382 |
drrb->drr_fromguid, zc.zc_string) != 0) { |
|
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2383 |
zcmd_free_nvlists(&zc); |
5367 | 2384 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
2385 |
"local origin for clone %s does not exist"), |
|
2386 |
zc.zc_value); |
|
2387 |
return (zfs_error(hdl, EZFS_NOENT, errbuf)); |
|
2388 |
} |
|
2389 |
if (flags.verbose) |
|
2390 |
(void) printf("found clone origin %s\n", zc.zc_string); |
|
2391 |
} |
|
2392 |
||
2393 |
stream_wantsnewfs = (drrb->drr_fromguid == NULL || |
|
2394 |
(drrb->drr_flags & DRR_FLAG_CLONE)); |
|
2395 |
||
2396 |
if (stream_wantsnewfs) { |
|
2397 |
/* |
|
2398 |
* if the parent fs does not exist, look for it based on |
|
2399 |
* the parent snap GUID |
|
2400 |
*/ |
|
2401 |
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, |
|
2402 |
"cannot receive new filesystem stream")); |
|
2403 |
||
2404 |
(void) strcpy(zc.zc_name, zc.zc_value); |
|
2405 |
cp = strrchr(zc.zc_name, '/'); |
|
2406 |
if (cp) |
|
2407 |
*cp = '\0'; |
|
2408 |
if (cp && |
|
2409 |
!zfs_dataset_exists(hdl, zc.zc_name, ZFS_TYPE_DATASET)) { |
|
2410 |
char suffix[ZFS_MAXNAMELEN]; |
|
2411 |
(void) strcpy(suffix, strrchr(zc.zc_value, '/')); |
|
2412 |
if (guid_to_name(hdl, tosnap, parent_snapguid, |
|
2413 |
zc.zc_value) == 0) { |
|
2414 |
*strchr(zc.zc_value, '@') = '\0'; |
|
2415 |
(void) strcat(zc.zc_value, suffix); |
|
2416 |
} |
|
2417 |
} |
|
2418 |
} else { |
|
2419 |
/* |
|
2420 |
* if the fs does not exist, look for it based on the |
|
2421 |
* fromsnap GUID |
|
2422 |
*/ |
|
2423 |
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, |
|
2424 |
"cannot receive incremental stream")); |
|
2425 |
||
2426 |
(void) strcpy(zc.zc_name, zc.zc_value); |
|
2427 |
*strchr(zc.zc_name, '@') = '\0'; |
|
2428 |
||
2429 |
if (!zfs_dataset_exists(hdl, zc.zc_name, ZFS_TYPE_DATASET)) { |
|
2430 |
char snap[ZFS_MAXNAMELEN]; |
|
2431 |
(void) strcpy(snap, strchr(zc.zc_value, '@')); |
|
2432 |
if (guid_to_name(hdl, tosnap, drrb->drr_fromguid, |
|
2433 |
zc.zc_value) == 0) { |
|
2434 |
*strchr(zc.zc_value, '@') = '\0'; |
|
2435 |
(void) strcat(zc.zc_value, snap); |
|
2436 |
} |
|
2437 |
} |
|
2438 |
} |
|
2439 |
||
2440 |
(void) strcpy(zc.zc_name, zc.zc_value); |
|
2441 |
*strchr(zc.zc_name, '@') = '\0'; |
|
2442 |
||
2443 |
if (zfs_dataset_exists(hdl, zc.zc_name, ZFS_TYPE_DATASET)) { |
|
2444 |
zfs_handle_t *zhp; |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2445 |
|
5367 | 2446 |
/* |
2447 |
* Destination fs exists. Therefore this should either |
|
2448 |
* be an incremental, or the stream specifies a new fs |
|
2449 |
* (full stream or clone) and they want us to blow it |
|
2450 |
* away (and have therefore specified -F and removed any |
|
2451 |
* snapshots). |
|
2452 |
*/ |
|
2453 |
if (stream_wantsnewfs) { |
|
2454 |
if (!flags.force) { |
|
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2455 |
zcmd_free_nvlists(&zc); |
5367 | 2456 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
2457 |
"destination '%s' exists\n" |
|
2458 |
"must specify -F to overwrite it"), |
|
2459 |
zc.zc_name); |
|
2460 |
return (zfs_error(hdl, EZFS_EXISTS, errbuf)); |
|
2461 |
} |
|
2462 |
if (ioctl(hdl->libzfs_fd, ZFS_IOC_SNAPSHOT_LIST_NEXT, |
|
2463 |
&zc) == 0) { |
|
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2464 |
zcmd_free_nvlists(&zc); |
5367 | 2465 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
2466 |
"destination has snapshots (eg. %s)\n" |
|
2467 |
"must destroy them to overwrite it"), |
|
2468 |
zc.zc_name); |
|
2469 |
return (zfs_error(hdl, EZFS_EXISTS, errbuf)); |
|
2470 |
} |
|
2471 |
} |
|
2472 |
||
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2473 |
if ((zhp = zfs_open(hdl, zc.zc_name, |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2474 |
ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME)) == NULL) { |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2475 |
zcmd_free_nvlists(&zc); |
5367 | 2476 |
return (-1); |
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2477 |
} |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2478 |
|
5367 | 2479 |
if (stream_wantsnewfs && |
2480 |
zhp->zfs_dmustats.dds_origin[0]) { |
|
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2481 |
zcmd_free_nvlists(&zc); |
5367 | 2482 |
zfs_close(zhp); |
2483 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
2484 |
"destination '%s' is a clone\n" |
|
2485 |
"must destroy it to overwrite it"), |
|
2486 |
zc.zc_name); |
|
2487 |
return (zfs_error(hdl, EZFS_EXISTS, errbuf)); |
|
2488 |
} |
|
2489 |
||
2490 |
if (!flags.dryrun && zhp->zfs_type == ZFS_TYPE_FILESYSTEM && |
|
2491 |
stream_wantsnewfs) { |
|
2492 |
/* We can't do online recv in this case */ |
|
7366
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2493 |
clp = changelist_gather(zhp, ZFS_PROP_NAME, 0, 0); |
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2494 |
if (clp == NULL) { |
10200
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
2495 |
zfs_close(zhp); |
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2496 |
zcmd_free_nvlists(&zc); |
5367 | 2497 |
return (-1); |
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2498 |
} |
5367 | 2499 |
if (changelist_prefix(clp) != 0) { |
2500 |
changelist_free(clp); |
|
10200
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
2501 |
zfs_close(zhp); |
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2502 |
zcmd_free_nvlists(&zc); |
5367 | 2503 |
return (-1); |
2504 |
} |
|
2505 |
} |
|
2506 |
zfs_close(zhp); |
|
2507 |
} else { |
|
2508 |
/* |
|
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2509 |
* Destination filesystem does not exist. Therefore we better |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2510 |
* be creating a new filesystem (either from a full backup, or |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2511 |
* a clone). It would therefore be invalid if the user |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2512 |
* specified only the pool name (i.e. if the destination name |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2513 |
* contained no slash character). |
5367 | 2514 |
*/ |
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2515 |
if (!stream_wantsnewfs || |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2516 |
(cp = strrchr(zc.zc_name, '/')) == NULL) { |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2517 |
zcmd_free_nvlists(&zc); |
5367 | 2518 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
2519 |
"destination '%s' does not exist"), zc.zc_name); |
|
2520 |
return (zfs_error(hdl, EZFS_NOENT, errbuf)); |
|
2521 |
} |
|
2522 |
||
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2523 |
/* |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2524 |
* Trim off the final dataset component so we perform the |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2525 |
* recvbackup ioctl to the filesystems's parent. |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2526 |
*/ |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2527 |
*cp = '\0'; |
5367 | 2528 |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2529 |
if (flags.isprefix && !flags.istail && !flags.dryrun && |
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2530 |
create_parents(hdl, zc.zc_value, strlen(tosnap)) != 0) { |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2531 |
zcmd_free_nvlists(&zc); |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2532 |
return (zfs_error(hdl, EZFS_BADRESTORE, errbuf)); |
5367 | 2533 |
} |
2534 |
||
2535 |
newfs = B_TRUE; |
|
2536 |
} |
|
2537 |
||
2538 |
zc.zc_begin_record = drr_noswap->drr_u.drr_begin; |
|
2539 |
zc.zc_cookie = infd; |
|
2540 |
zc.zc_guid = flags.force; |
|
2541 |
if (flags.verbose) { |
|
2542 |
(void) printf("%s %s stream of %s into %s\n", |
|
2543 |
flags.dryrun ? "would receive" : "receiving", |
|
2544 |
drrb->drr_fromguid ? "incremental" : "full", |
|
2545 |
drrb->drr_toname, zc.zc_value); |
|
2546 |
(void) fflush(stdout); |
|
2547 |
} |
|
2548 |
||
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2549 |
if (flags.dryrun) { |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2550 |
zcmd_free_nvlists(&zc); |
5367 | 2551 |
return (recv_skip(hdl, infd, flags.byteswap)); |
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2552 |
} |
5367 | 2553 |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2554 |
zc.zc_nvlist_dst = (uint64_t)(uintptr_t)prop_errbuf; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2555 |
zc.zc_nvlist_dst_size = sizeof (prop_errbuf); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2556 |
|
5367 | 2557 |
err = ioctl_err = zfs_ioctl(hdl, ZFS_IOC_RECV, &zc); |
2558 |
ioctl_errno = errno; |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2559 |
prop_errflags = (zprop_errflags_t)zc.zc_obj; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2560 |
|
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2561 |
if (err == 0) { |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2562 |
nvlist_t *prop_errors; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2563 |
VERIFY(0 == nvlist_unpack((void *)(uintptr_t)zc.zc_nvlist_dst, |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2564 |
zc.zc_nvlist_dst_size, &prop_errors, 0)); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2565 |
|
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2566 |
nvpair_t *prop_err = NULL; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2567 |
|
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2568 |
while ((prop_err = nvlist_next_nvpair(prop_errors, |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2569 |
prop_err)) != NULL) { |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2570 |
char tbuf[1024]; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2571 |
zfs_prop_t prop; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2572 |
int intval; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2573 |
|
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2574 |
prop = zfs_name_to_prop(nvpair_name(prop_err)); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2575 |
(void) nvpair_value_int32(prop_err, &intval); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2576 |
if (strcmp(nvpair_name(prop_err), |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2577 |
ZPROP_N_MORE_ERRORS) == 0) { |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2578 |
trunc_prop_errs(intval); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2579 |
break; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2580 |
} else { |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2581 |
(void) snprintf(tbuf, sizeof (tbuf), |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2582 |
dgettext(TEXT_DOMAIN, |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2583 |
"cannot receive %s property on %s"), |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2584 |
nvpair_name(prop_err), zc.zc_name); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2585 |
zfs_setprop_error(hdl, prop, intval, tbuf); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2586 |
} |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2587 |
} |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2588 |
nvlist_free(prop_errors); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2589 |
} |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2590 |
|
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2591 |
zc.zc_nvlist_dst = 0; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2592 |
zc.zc_nvlist_dst_size = 0; |
7265 | 2593 |
zcmd_free_nvlists(&zc); |
2594 |
||
2595 |
if (err == 0 && snapprops_nvlist) { |
|
2596 |
zfs_cmd_t zc2 = { 0 }; |
|
2597 |
||
7273
6baaca4d907c
6701797 want user properties on snapshots (fix lint)
ahrens
parents:
7265
diff
changeset
|
2598 |
(void) strcpy(zc2.zc_name, zc.zc_value); |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2599 |
zc2.zc_cookie = B_TRUE; /* received */ |
7265 | 2600 |
if (zcmd_write_src_nvlist(hdl, &zc2, snapprops_nvlist) == 0) { |
2601 |
(void) zfs_ioctl(hdl, ZFS_IOC_SET_PROP, &zc2); |
|
2602 |
zcmd_free_nvlists(&zc2); |
|
2603 |
} |
|
2604 |
} |
|
2605 |
||
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2606 |
if (err && (ioctl_errno == ENOENT || ioctl_errno == EEXIST)) { |
5367 | 2607 |
/* |
2608 |
* It may be that this snapshot already exists, |
|
2609 |
* in which case we want to consume & ignore it |
|
2610 |
* rather than failing. |
|
2611 |
*/ |
|
2612 |
avl_tree_t *local_avl; |
|
2613 |
nvlist_t *local_nv, *fs; |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2614 |
cp = strchr(zc.zc_value, '@'); |
5367 | 2615 |
|
2616 |
/* |
|
2617 |
* XXX Do this faster by just iterating over snaps in |
|
2618 |
* this fs. Also if zc_value does not exist, we will |
|
2619 |
* get a strange "does not exist" error message. |
|
2620 |
*/ |
|
2621 |
*cp = '\0'; |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2622 |
if (gather_nvlist(hdl, zc.zc_value, NULL, NULL, B_FALSE, |
5367 | 2623 |
&local_nv, &local_avl) == 0) { |
2624 |
*cp = '@'; |
|
2625 |
fs = fsavl_find(local_avl, drrb->drr_toguid, NULL); |
|
2626 |
fsavl_destroy(local_avl); |
|
2627 |
nvlist_free(local_nv); |
|
2628 |
||
2629 |
if (fs != NULL) { |
|
2630 |
if (flags.verbose) { |
|
2631 |
(void) printf("snap %s already exists; " |
|
2632 |
"ignoring\n", zc.zc_value); |
|
2633 |
} |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2634 |
err = ioctl_err = recv_skip(hdl, infd, |
5367 | 2635 |
flags.byteswap); |
2636 |
} |
|
2637 |
} |
|
2638 |
*cp = '@'; |
|
2639 |
} |
|
2640 |
||
2641 |
if (ioctl_err != 0) { |
|
2642 |
switch (ioctl_errno) { |
|
2643 |
case ENODEV: |
|
2644 |
cp = strchr(zc.zc_value, '@'); |
|
2645 |
*cp = '\0'; |
|
2646 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
2647 |
"most recent snapshot of %s does not\n" |
|
2648 |
"match incremental source"), zc.zc_value); |
|
2649 |
(void) zfs_error(hdl, EZFS_BADRESTORE, errbuf); |
|
2650 |
*cp = '@'; |
|
2651 |
break; |
|
2652 |
case ETXTBSY: |
|
2653 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
2654 |
"destination %s has been modified\n" |
|
2655 |
"since most recent snapshot"), zc.zc_name); |
|
2656 |
(void) zfs_error(hdl, EZFS_BADRESTORE, errbuf); |
|
2657 |
break; |
|
2658 |
case EEXIST: |
|
2659 |
cp = strchr(zc.zc_value, '@'); |
|
2660 |
if (newfs) { |
|
2661 |
/* it's the containing fs that exists */ |
|
2662 |
*cp = '\0'; |
|
2663 |
} |
|
2664 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
2665 |
"destination already exists")); |
|
2666 |
(void) zfs_error_fmt(hdl, EZFS_EXISTS, |
|
2667 |
dgettext(TEXT_DOMAIN, "cannot restore to %s"), |
|
2668 |
zc.zc_value); |
|
2669 |
*cp = '@'; |
|
2670 |
break; |
|
2671 |
case EINVAL: |
|
2672 |
(void) zfs_error(hdl, EZFS_BADSTREAM, errbuf); |
|
2673 |
break; |
|
2674 |
case ECKSUM: |
|
2675 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
2676 |
"invalid stream (checksum mismatch)")); |
|
2677 |
(void) zfs_error(hdl, EZFS_BADSTREAM, errbuf); |
|
2678 |
break; |
|
2679 |
default: |
|
2680 |
(void) zfs_standard_error(hdl, ioctl_errno, errbuf); |
|
2681 |
} |
|
2682 |
} |
|
2683 |
||
2684 |
/* |
|
10588
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10342
diff
changeset
|
2685 |
* Mount the target filesystem (if created). Also mount any |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10342
diff
changeset
|
2686 |
* children of the target filesystem if we did a replication |
dc03f981ea18
6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents:
10342
diff
changeset
|
2687 |
* receive (indicated by stream_avl being non-NULL). |
5367 | 2688 |
*/ |
2689 |
cp = strchr(zc.zc_value, '@'); |
|
2690 |
if (cp && (ioctl_err == 0 || !newfs)) { |
|
2691 |
zfs_handle_t *h; |
|
2692 |
||
2693 |
*cp = '\0'; |
|
2694 |
h = zfs_open(hdl, zc.zc_value, |
|
2695 |
ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME); |
|
6476 | 2696 |
if (h != NULL) { |
5367 | 2697 |
if (h->zfs_type == ZFS_TYPE_VOLUME) { |
7366
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2698 |
*cp = '@'; |
10200
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
2699 |
} else if (newfs || stream_avl) { |
7366
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2700 |
/* |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2701 |
* Track the first/top of hierarchy fs, |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2702 |
* for mounting and sharing later. |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2703 |
*/ |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2704 |
if (top_zfs && *top_zfs == NULL) |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2705 |
*top_zfs = zfs_strdup(hdl, zc.zc_value); |
5367 | 2706 |
} |
6476 | 2707 |
zfs_close(h); |
5367 | 2708 |
} |
7366
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2709 |
*cp = '@'; |
5367 | 2710 |
} |
2711 |
||
2712 |
if (clp) { |
|
2713 |
err |= changelist_postfix(clp); |
|
2714 |
changelist_free(clp); |
|
2715 |
} |
|
2716 |
||
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2717 |
if (prop_errflags & ZPROP_ERR_NOCLEAR) { |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2718 |
(void) fprintf(stderr, dgettext(TEXT_DOMAIN, "Warning: " |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2719 |
"failed to clear unreceived properties on %s"), |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2720 |
zc.zc_name); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2721 |
(void) fprintf(stderr, "\n"); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2722 |
} |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2723 |
if (prop_errflags & ZPROP_ERR_NORESTORE) { |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2724 |
(void) fprintf(stderr, dgettext(TEXT_DOMAIN, "Warning: " |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2725 |
"failed to restore original properties on %s"), |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2726 |
zc.zc_name); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2727 |
(void) fprintf(stderr, "\n"); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2728 |
} |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2729 |
|
5367 | 2730 |
if (err || ioctl_err) |
2731 |
return (-1); |
|
2732 |
||
2733 |
if (flags.verbose) { |
|
2734 |
char buf1[64]; |
|
2735 |
char buf2[64]; |
|
2736 |
uint64_t bytes = zc.zc_cookie; |
|
2737 |
time_t delta = time(NULL) - begin_time; |
|
2738 |
if (delta == 0) |
|
2739 |
delta = 1; |
|
2740 |
zfs_nicenum(bytes, buf1, sizeof (buf1)); |
|
2741 |
zfs_nicenum(bytes/delta, buf2, sizeof (buf1)); |
|
2742 |
||
2743 |
(void) printf("received %sB stream in %lu seconds (%sB/sec)\n", |
|
2744 |
buf1, delta, buf2); |
|
2745 |
} |
|
2746 |
||
2747 |
return (0); |
|
2748 |
} |
|
2749 |
||
7366
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2750 |
static int |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2751 |
zfs_receive_impl(libzfs_handle_t *hdl, const char *tosnap, recvflags_t flags, |
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2752 |
int infd, const char *sendfs, nvlist_t *stream_nv, avl_tree_t *stream_avl, |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2753 |
char **top_zfs) |
5367 | 2754 |
{ |
2755 |
int err; |
|
2756 |
dmu_replay_record_t drr, drr_noswap; |
|
2757 |
struct drr_begin *drrb = &drr.drr_u.drr_begin; |
|
2758 |
char errbuf[1024]; |
|
2759 |
zio_cksum_t zcksum = { 0 }; |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2760 |
uint64_t featureflags; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2761 |
int hdrtype; |
5367 | 2762 |
|
2763 |
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, |
|
2764 |
"cannot receive")); |
|
2765 |
||
2766 |
if (flags.isprefix && |
|
2767 |
!zfs_dataset_exists(hdl, tosnap, ZFS_TYPE_DATASET)) { |
|
2768 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "specified fs " |
|
2769 |
"(%s) does not exist"), tosnap); |
|
2770 |
return (zfs_error(hdl, EZFS_NOENT, errbuf)); |
|
2771 |
} |
|
2772 |
||
2773 |
/* read in the BEGIN record */ |
|
2774 |
if (0 != (err = recv_read(hdl, infd, &drr, sizeof (drr), B_FALSE, |
|
2775 |
&zcksum))) |
|
2776 |
return (err); |
|
2777 |
||
2778 |
if (drr.drr_type == DRR_END || drr.drr_type == BSWAP_32(DRR_END)) { |
|
2779 |
/* It's the double end record at the end of a package */ |
|
2780 |
return (ENODATA); |
|
2781 |
} |
|
2782 |
||
2783 |
/* the kernel needs the non-byteswapped begin record */ |
|
2784 |
drr_noswap = drr; |
|
2785 |
||
5446 | 2786 |
flags.byteswap = B_FALSE; |
5367 | 2787 |
if (drrb->drr_magic == BSWAP_64(DMU_BACKUP_MAGIC)) { |
2788 |
/* |
|
2789 |
* We computed the checksum in the wrong byteorder in |
|
2790 |
* recv_read() above; do it again correctly. |
|
2791 |
*/ |
|
2792 |
bzero(&zcksum, sizeof (zio_cksum_t)); |
|
2793 |
fletcher_4_incremental_byteswap(&drr, sizeof (drr), &zcksum); |
|
2794 |
flags.byteswap = B_TRUE; |
|
2795 |
||
2796 |
drr.drr_type = BSWAP_32(drr.drr_type); |
|
2797 |
drr.drr_payloadlen = BSWAP_32(drr.drr_payloadlen); |
|
2798 |
drrb->drr_magic = BSWAP_64(drrb->drr_magic); |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2799 |
drrb->drr_versioninfo = BSWAP_64(drrb->drr_versioninfo); |
5367 | 2800 |
drrb->drr_creation_time = BSWAP_64(drrb->drr_creation_time); |
2801 |
drrb->drr_type = BSWAP_32(drrb->drr_type); |
|
2802 |
drrb->drr_flags = BSWAP_32(drrb->drr_flags); |
|
2803 |
drrb->drr_toguid = BSWAP_64(drrb->drr_toguid); |
|
2804 |
drrb->drr_fromguid = BSWAP_64(drrb->drr_fromguid); |
|
2805 |
} |
|
2806 |
||
2807 |
if (drrb->drr_magic != DMU_BACKUP_MAGIC || drr.drr_type != DRR_BEGIN) { |
|
2808 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "invalid " |
|
2809 |
"stream (bad magic number)")); |
|
2810 |
return (zfs_error(hdl, EZFS_BADSTREAM, errbuf)); |
|
2811 |
} |
|
2812 |
||
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2813 |
featureflags = DMU_GET_FEATUREFLAGS(drrb->drr_versioninfo); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2814 |
hdrtype = DMU_GET_STREAM_HDRTYPE(drrb->drr_versioninfo); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2815 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2816 |
if (!DMU_STREAM_SUPPORTED(featureflags) || |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2817 |
(hdrtype != DMU_SUBSTREAM && hdrtype != DMU_COMPOUNDSTREAM)) { |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2818 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2819 |
"stream has unsupported feature, feature flags = %lx"), |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2820 |
featureflags); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2821 |
return (zfs_error(hdl, EZFS_BADSTREAM, errbuf)); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2822 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2823 |
|
5367 | 2824 |
if (strchr(drrb->drr_toname, '@') == NULL) { |
2825 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "invalid " |
|
2826 |
"stream (bad snapshot name)")); |
|
2827 |
return (zfs_error(hdl, EZFS_BADSTREAM, errbuf)); |
|
2828 |
} |
|
2829 |
||
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2830 |
if (DMU_GET_STREAM_HDRTYPE(drrb->drr_versioninfo) == DMU_SUBSTREAM) { |
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2831 |
char nonpackage_sendfs[ZFS_MAXNAMELEN]; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2832 |
if (sendfs == NULL) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2833 |
/* |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2834 |
* We were not called from zfs_receive_package(). Get |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2835 |
* the fs specified by 'zfs send'. |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2836 |
*/ |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2837 |
char *cp; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2838 |
(void) strlcpy(nonpackage_sendfs, |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2839 |
drr.drr_u.drr_begin.drr_toname, ZFS_MAXNAMELEN); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2840 |
if ((cp = strchr(nonpackage_sendfs, '@')) != NULL) |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2841 |
*cp = '\0'; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2842 |
sendfs = nonpackage_sendfs; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2843 |
} |
5367 | 2844 |
return (zfs_receive_one(hdl, infd, tosnap, flags, |
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2845 |
&drr, &drr_noswap, sendfs, stream_nv, stream_avl, |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2846 |
top_zfs)); |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2847 |
} else { /* must be DMU_COMPOUNDSTREAM */ |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2848 |
assert(DMU_GET_STREAM_HDRTYPE(drrb->drr_versioninfo) == |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2849 |
DMU_COMPOUNDSTREAM); |
5367 | 2850 |
return (zfs_receive_package(hdl, infd, tosnap, flags, |
7366
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2851 |
&drr, &zcksum, top_zfs)); |
5367 | 2852 |
} |
2853 |
} |
|
7366
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2854 |
|
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2855 |
/* |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2856 |
* Restores a backup of tosnap from the file descriptor specified by infd. |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2857 |
* Return 0 on total success, -2 if some things couldn't be |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2858 |
* destroyed/renamed/promoted, -1 if some things couldn't be received. |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2859 |
* (-1 will override -2). |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2860 |
*/ |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2861 |
int |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2862 |
zfs_receive(libzfs_handle_t *hdl, const char *tosnap, recvflags_t flags, |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2863 |
int infd, avl_tree_t *stream_avl) |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2864 |
{ |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2865 |
char *top_zfs = NULL; |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2866 |
int err; |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2867 |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2868 |
err = zfs_receive_impl(hdl, tosnap, flags, infd, NULL, NULL, |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2869 |
stream_avl, &top_zfs); |
7366
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2870 |
|
8584
327a1b6dd944
6794452 zfs receive can't restore a root pool
Lori Alt <Lori.Alt@Sun.COM>
parents:
7366
diff
changeset
|
2871 |
if (err == 0 && !flags.nomount && top_zfs) { |
7366
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2872 |
zfs_handle_t *zhp; |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2873 |
prop_changelist_t *clp; |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2874 |
|
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2875 |
zhp = zfs_open(hdl, top_zfs, ZFS_TYPE_FILESYSTEM); |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2876 |
if (zhp != NULL) { |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2877 |
clp = changelist_gather(zhp, ZFS_PROP_MOUNTPOINT, |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2878 |
CL_GATHER_MOUNT_ALWAYS, 0); |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2879 |
zfs_close(zhp); |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2880 |
if (clp != NULL) { |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2881 |
/* mount and share received datasets */ |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2882 |
err = changelist_postfix(clp); |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2883 |
changelist_free(clp); |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2884 |
} |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2885 |
} |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2886 |
if (zhp == NULL || clp == NULL || err) |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2887 |
err = -1; |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2888 |
} |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2889 |
if (top_zfs) |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2890 |
free(top_zfs); |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2891 |
|
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2892 |
return (err); |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2893 |
} |