author | Matthew Ahrens <matt@delphix.com> |
Sat, 05 Nov 2011 17:34:13 -0700 | |
changeset 13509 | 04570f5cbeca |
parent 12798 | f6c8601080b4 |
child 13512 | 060607df0c9d |
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 |
/* |
|
12070
01261b276236
6940770 panic in sa_find_idx_tab() after receiving into pool when version shouldn't have allowed it
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11976
diff
changeset
|
23 |
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. |
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
24 |
* Copyright (c) 2011 by Delphix. All rights reserved. |
5367 | 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, |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12296
diff
changeset
|
55 |
int, const char *, nvlist_t *, avl_tree_t *, char **, int, uint64_t *); |
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 specific to "zfs send" |
|
776 |
*/ |
|
777 |
typedef struct send_dump_data { |
|
778 |
/* these are all just the short snapname (the part after the @) */ |
|
779 |
const char *fromsnap; |
|
780 |
const char *tosnap; |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
781 |
char prevsnap[ZFS_MAXNAMELEN]; |
12798
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
782 |
uint64_t prevsnap_obj; |
5367 | 783 |
boolean_t seenfrom, seento, replicate, doall, fromorigin; |
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
784 |
boolean_t verbose, noop, parsable; |
5367 | 785 |
int outfd; |
786 |
boolean_t err; |
|
787 |
nvlist_t *fss; |
|
788 |
avl_tree_t *fsavl; |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
789 |
snapfilter_cb_t *filter_cb; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
790 |
void *filter_cb_arg; |
12296
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
12282
diff
changeset
|
791 |
nvlist_t *debugnv; |
12798
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
792 |
char holdtag[ZFS_MAXNAMELEN]; |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
793 |
int cleanup_fd; |
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
794 |
uint64_t size; |
5367 | 795 |
} send_dump_data_t; |
796 |
||
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
797 |
static int |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
798 |
estimate_ioctl(zfs_handle_t *zhp, uint64_t fromsnap_obj, |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
799 |
boolean_t fromorigin, uint64_t *sizep) |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
800 |
{ |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
801 |
zfs_cmd_t zc = { 0 }; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
802 |
libzfs_handle_t *hdl = zhp->zfs_hdl; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
803 |
|
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
804 |
assert(zhp->zfs_type == ZFS_TYPE_SNAPSHOT); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
805 |
assert(fromsnap_obj == 0 || !fromorigin); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
806 |
|
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
807 |
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
808 |
zc.zc_obj = fromorigin; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
809 |
zc.zc_sendobj = zfs_prop_get_int(zhp, ZFS_PROP_OBJSETID); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
810 |
zc.zc_fromobj = fromsnap_obj; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
811 |
zc.zc_guid = 1; /* estimate flag */ |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
812 |
|
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
813 |
if (zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_SEND, &zc) != 0) { |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
814 |
char errbuf[1024]; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
815 |
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
816 |
"warning: cannot estimate space for '%s'"), zhp->zfs_name); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
817 |
|
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
818 |
switch (errno) { |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
819 |
case EXDEV: |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
820 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
821 |
"not an earlier snapshot from the same fs")); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
822 |
return (zfs_error(hdl, EZFS_CROSSTARGET, errbuf)); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
823 |
|
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
824 |
case ENOENT: |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
825 |
if (zfs_dataset_exists(hdl, zc.zc_name, |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
826 |
ZFS_TYPE_SNAPSHOT)) { |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
827 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
828 |
"incremental source (@%s) does not exist"), |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
829 |
zc.zc_value); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
830 |
} |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
831 |
return (zfs_error(hdl, EZFS_NOENT, errbuf)); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
832 |
|
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
833 |
case EDQUOT: |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
834 |
case EFBIG: |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
835 |
case EIO: |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
836 |
case ENOLINK: |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
837 |
case ENOSPC: |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
838 |
case ENOSTR: |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
839 |
case ENXIO: |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
840 |
case EPIPE: |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
841 |
case ERANGE: |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
842 |
case EFAULT: |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
843 |
case EROFS: |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
844 |
zfs_error_aux(hdl, strerror(errno)); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
845 |
return (zfs_error(hdl, EZFS_BADBACKUP, errbuf)); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
846 |
|
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
847 |
default: |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
848 |
return (zfs_standard_error(hdl, errno, errbuf)); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
849 |
} |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
850 |
} |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
851 |
|
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
852 |
*sizep = zc.zc_objset_type; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
853 |
|
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
854 |
return (0); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
855 |
} |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
856 |
|
5367 | 857 |
/* |
858 |
* Dumps a backup of the given snapshot (incremental from fromsnap if it's not |
|
859 |
* NULL) to the file descriptor specified by outfd. |
|
860 |
*/ |
|
861 |
static int |
|
12798
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
862 |
dump_ioctl(zfs_handle_t *zhp, const char *fromsnap, uint64_t fromsnap_obj, |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
863 |
boolean_t fromorigin, int outfd, nvlist_t *debugnv) |
5367 | 864 |
{ |
865 |
zfs_cmd_t zc = { 0 }; |
|
866 |
libzfs_handle_t *hdl = zhp->zfs_hdl; |
|
12296
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
12282
diff
changeset
|
867 |
nvlist_t *thisdbg; |
5367 | 868 |
|
869 |
assert(zhp->zfs_type == ZFS_TYPE_SNAPSHOT); |
|
12798
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
870 |
assert(fromsnap_obj == 0 || !fromorigin); |
5367 | 871 |
|
872 |
(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); |
|
873 |
zc.zc_cookie = outfd; |
|
874 |
zc.zc_obj = fromorigin; |
|
12798
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
875 |
zc.zc_sendobj = zfs_prop_get_int(zhp, ZFS_PROP_OBJSETID); |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
876 |
zc.zc_fromobj = fromsnap_obj; |
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
|
877 |
|
12296
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
12282
diff
changeset
|
878 |
VERIFY(0 == nvlist_alloc(&thisdbg, NV_UNIQUE_NAME, 0)); |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
12282
diff
changeset
|
879 |
if (fromsnap && fromsnap[0] != '\0') { |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
12282
diff
changeset
|
880 |
VERIFY(0 == nvlist_add_string(thisdbg, |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
12282
diff
changeset
|
881 |
"fromsnap", fromsnap)); |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
12282
diff
changeset
|
882 |
} |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
12282
diff
changeset
|
883 |
|
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
884 |
if (zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_SEND, &zc) != 0) { |
5367 | 885 |
char errbuf[1024]; |
886 |
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, |
|
887 |
"warning: cannot send '%s'"), zhp->zfs_name); |
|
888 |
||
12296
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
12282
diff
changeset
|
889 |
VERIFY(0 == nvlist_add_uint64(thisdbg, "error", errno)); |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
12282
diff
changeset
|
890 |
if (debugnv) { |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
12282
diff
changeset
|
891 |
VERIFY(0 == nvlist_add_nvlist(debugnv, |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
12282
diff
changeset
|
892 |
zhp->zfs_name, thisdbg)); |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
12282
diff
changeset
|
893 |
} |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
12282
diff
changeset
|
894 |
nvlist_free(thisdbg); |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
12282
diff
changeset
|
895 |
|
5367 | 896 |
switch (errno) { |
897 |
case EXDEV: |
|
898 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
899 |
"not an earlier snapshot from the same fs")); |
|
900 |
return (zfs_error(hdl, EZFS_CROSSTARGET, errbuf)); |
|
901 |
||
902 |
case ENOENT: |
|
903 |
if (zfs_dataset_exists(hdl, zc.zc_name, |
|
904 |
ZFS_TYPE_SNAPSHOT)) { |
|
905 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
906 |
"incremental source (@%s) does not exist"), |
|
907 |
zc.zc_value); |
|
908 |
} |
|
909 |
return (zfs_error(hdl, EZFS_NOENT, errbuf)); |
|
910 |
||
911 |
case EDQUOT: |
|
912 |
case EFBIG: |
|
913 |
case EIO: |
|
914 |
case ENOLINK: |
|
915 |
case ENOSPC: |
|
916 |
case ENOSTR: |
|
917 |
case ENXIO: |
|
918 |
case EPIPE: |
|
919 |
case ERANGE: |
|
920 |
case EFAULT: |
|
921 |
case EROFS: |
|
922 |
zfs_error_aux(hdl, strerror(errno)); |
|
923 |
return (zfs_error(hdl, EZFS_BADBACKUP, errbuf)); |
|
924 |
||
925 |
default: |
|
926 |
return (zfs_standard_error(hdl, errno, errbuf)); |
|
927 |
} |
|
928 |
} |
|
929 |
||
12296
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
12282
diff
changeset
|
930 |
if (debugnv) |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
12282
diff
changeset
|
931 |
VERIFY(0 == nvlist_add_nvlist(debugnv, zhp->zfs_name, thisdbg)); |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
12282
diff
changeset
|
932 |
nvlist_free(thisdbg); |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
12282
diff
changeset
|
933 |
|
5367 | 934 |
return (0); |
935 |
} |
|
936 |
||
937 |
static int |
|
12798
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
938 |
hold_for_send(zfs_handle_t *zhp, send_dump_data_t *sdd) |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
939 |
{ |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
940 |
zfs_handle_t *pzhp; |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
941 |
int error = 0; |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
942 |
char *thissnap; |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
943 |
|
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
944 |
assert(zhp->zfs_type == ZFS_TYPE_SNAPSHOT); |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
945 |
|
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
946 |
if (sdd->noop) |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
947 |
return (0); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
948 |
|
12798
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
949 |
/* |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
950 |
* zfs_send() only opens a cleanup_fd for sends that need it, |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
951 |
* e.g. replication and doall. |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
952 |
*/ |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
953 |
if (sdd->cleanup_fd == -1) |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
954 |
return (0); |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
955 |
|
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
956 |
thissnap = strchr(zhp->zfs_name, '@') + 1; |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
957 |
*(thissnap - 1) = '\0'; |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
958 |
pzhp = zfs_open(zhp->zfs_hdl, zhp->zfs_name, ZFS_TYPE_DATASET); |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
959 |
*(thissnap - 1) = '@'; |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
960 |
|
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
961 |
/* |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
962 |
* It's OK if the parent no longer exists. The send code will |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
963 |
* handle that error. |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
964 |
*/ |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
965 |
if (pzhp) { |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
966 |
error = zfs_hold(pzhp, thissnap, sdd->holdtag, |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
967 |
B_FALSE, B_TRUE, B_TRUE, sdd->cleanup_fd, |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
968 |
zfs_prop_get_int(zhp, ZFS_PROP_OBJSETID), |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
969 |
zfs_prop_get_int(zhp, ZFS_PROP_CREATETXG)); |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
970 |
zfs_close(pzhp); |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
971 |
} |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
972 |
|
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
973 |
return (error); |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
974 |
} |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
975 |
|
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
976 |
static int |
5367 | 977 |
dump_snapshot(zfs_handle_t *zhp, void *arg) |
978 |
{ |
|
979 |
send_dump_data_t *sdd = arg; |
|
12798
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
980 |
char *thissnap; |
5367 | 981 |
int err; |
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
982 |
boolean_t isfromsnap, istosnap, fromorigin; |
12282
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
983 |
boolean_t exclude = B_FALSE; |
5367 | 984 |
|
985 |
thissnap = strchr(zhp->zfs_name, '@') + 1; |
|
12282
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
986 |
isfromsnap = (sdd->fromsnap != NULL && |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
987 |
strcmp(sdd->fromsnap, thissnap) == 0); |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
988 |
|
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
989 |
if (!sdd->seenfrom && isfromsnap) { |
12798
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
990 |
err = hold_for_send(zhp, sdd); |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
991 |
if (err == 0) { |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
992 |
sdd->seenfrom = B_TRUE; |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
993 |
(void) strcpy(sdd->prevsnap, thissnap); |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
994 |
sdd->prevsnap_obj = zfs_prop_get_int(zhp, |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
995 |
ZFS_PROP_OBJSETID); |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
996 |
} else if (err == ENOENT) { |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
997 |
err = 0; |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
998 |
} |
5367 | 999 |
zfs_close(zhp); |
12798
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1000 |
return (err); |
5367 | 1001 |
} |
1002 |
||
1003 |
if (sdd->seento || !sdd->seenfrom) { |
|
1004 |
zfs_close(zhp); |
|
1005 |
return (0); |
|
1006 |
} |
|
1007 |
||
12282
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1008 |
istosnap = (strcmp(sdd->tosnap, thissnap) == 0); |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1009 |
if (istosnap) |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1010 |
sdd->seento = B_TRUE; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1011 |
|
12282
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1012 |
if (!sdd->doall && !isfromsnap && !istosnap) { |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1013 |
if (sdd->replicate) { |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1014 |
char *snapname; |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1015 |
nvlist_t *snapprops; |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1016 |
/* |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1017 |
* Filter out all intermediate snapshots except origin |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1018 |
* snapshots needed to replicate clones. |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1019 |
*/ |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1020 |
nvlist_t *nvfs = fsavl_find(sdd->fsavl, |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1021 |
zhp->zfs_dmustats.dds_guid, &snapname); |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1022 |
|
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1023 |
VERIFY(0 == nvlist_lookup_nvlist(nvfs, |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1024 |
"snapprops", &snapprops)); |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1025 |
VERIFY(0 == nvlist_lookup_nvlist(snapprops, |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1026 |
thissnap, &snapprops)); |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1027 |
exclude = !nvlist_exists(snapprops, "is_clone_origin"); |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1028 |
} else { |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1029 |
exclude = B_TRUE; |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1030 |
} |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1031 |
} |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1032 |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1033 |
/* |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1034 |
* 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
|
1035 |
* this snapshot will be sent. |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1036 |
*/ |
12282
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1037 |
if (exclude || (sdd->filter_cb != NULL && |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1038 |
sdd->filter_cb(zhp, sdd->filter_cb_arg) == B_FALSE)) { |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1039 |
/* |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1040 |
* This snapshot is filtered out. Don't send it, and don't |
12798
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1041 |
* set prevsnap_obj, so it will be as if this snapshot didn't |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1042 |
* 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
|
1043 |
* 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
|
1044 |
* 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
|
1045 |
* non-incremental send. |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1046 |
*/ |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1047 |
zfs_close(zhp); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1048 |
return (0); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1049 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1050 |
|
12798
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1051 |
err = hold_for_send(zhp, sdd); |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1052 |
if (err) { |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1053 |
if (err == ENOENT) |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1054 |
err = 0; |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1055 |
zfs_close(zhp); |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1056 |
return (err); |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1057 |
} |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1058 |
|
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1059 |
fromorigin = sdd->prevsnap[0] == '\0' && |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1060 |
(sdd->fromorigin || sdd->replicate); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1061 |
|
5367 | 1062 |
if (sdd->verbose) { |
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1063 |
uint64_t size; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1064 |
err = estimate_ioctl(zhp, sdd->prevsnap_obj, |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1065 |
fromorigin, &size); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1066 |
|
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1067 |
if (sdd->parsable) { |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1068 |
if (sdd->prevsnap[0] != '\0') { |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1069 |
(void) fprintf(stderr, "incremental\t%s\t%s", |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1070 |
sdd->prevsnap, zhp->zfs_name); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1071 |
} else { |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1072 |
(void) fprintf(stderr, "full\t%s", |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1073 |
zhp->zfs_name); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1074 |
} |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1075 |
} else { |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1076 |
(void) fprintf(stderr, dgettext(TEXT_DOMAIN, |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1077 |
"send from @%s to %s"), |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1078 |
sdd->prevsnap, zhp->zfs_name); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1079 |
} |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1080 |
if (err == 0) { |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1081 |
if (sdd->parsable) { |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1082 |
(void) fprintf(stderr, "\t%llu\n", |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1083 |
(longlong_t)size); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1084 |
} else { |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1085 |
char buf[16]; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1086 |
zfs_nicenum(size, buf, sizeof (buf)); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1087 |
(void) fprintf(stderr, dgettext(TEXT_DOMAIN, |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1088 |
" estimated size is %s\n"), buf); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1089 |
} |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1090 |
sdd->size += size; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1091 |
} else { |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1092 |
(void) fprintf(stderr, "\n"); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1093 |
} |
5367 | 1094 |
} |
1095 |
||
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1096 |
if (!sdd->noop) { |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1097 |
err = dump_ioctl(zhp, sdd->prevsnap, sdd->prevsnap_obj, |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1098 |
fromorigin, sdd->outfd, sdd->debugnv); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1099 |
} |
12798
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1100 |
|
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1101 |
(void) strcpy(sdd->prevsnap, thissnap); |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1102 |
sdd->prevsnap_obj = zfs_prop_get_int(zhp, ZFS_PROP_OBJSETID); |
5367 | 1103 |
zfs_close(zhp); |
1104 |
return (err); |
|
1105 |
} |
|
1106 |
||
1107 |
static int |
|
1108 |
dump_filesystem(zfs_handle_t *zhp, void *arg) |
|
1109 |
{ |
|
1110 |
int rv = 0; |
|
1111 |
send_dump_data_t *sdd = arg; |
|
1112 |
boolean_t missingfrom = B_FALSE; |
|
1113 |
zfs_cmd_t zc = { 0 }; |
|
1114 |
||
1115 |
(void) snprintf(zc.zc_name, sizeof (zc.zc_name), "%s@%s", |
|
1116 |
zhp->zfs_name, sdd->tosnap); |
|
1117 |
if (ioctl(zhp->zfs_hdl->libzfs_fd, ZFS_IOC_OBJSET_STATS, &zc) != 0) { |
|
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1118 |
(void) fprintf(stderr, dgettext(TEXT_DOMAIN, |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1119 |
"WARNING: could not send %s@%s: does not exist\n"), |
5367 | 1120 |
zhp->zfs_name, sdd->tosnap); |
1121 |
sdd->err = B_TRUE; |
|
1122 |
return (0); |
|
1123 |
} |
|
1124 |
||
1125 |
if (sdd->replicate && sdd->fromsnap) { |
|
1126 |
/* |
|
1127 |
* If this fs does not have fromsnap, and we're doing |
|
1128 |
* recursive, we need to send a full stream from the |
|
1129 |
* beginning (or an incremental from the origin if this |
|
1130 |
* is a clone). If we're doing non-recursive, then let |
|
1131 |
* them get the error. |
|
1132 |
*/ |
|
1133 |
(void) snprintf(zc.zc_name, sizeof (zc.zc_name), "%s@%s", |
|
1134 |
zhp->zfs_name, sdd->fromsnap); |
|
1135 |
if (ioctl(zhp->zfs_hdl->libzfs_fd, |
|
1136 |
ZFS_IOC_OBJSET_STATS, &zc) != 0) { |
|
1137 |
missingfrom = B_TRUE; |
|
1138 |
} |
|
1139 |
} |
|
1140 |
||
12282
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1141 |
sdd->seenfrom = sdd->seento = sdd->prevsnap[0] = 0; |
12798
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1142 |
sdd->prevsnap_obj = 0; |
12282
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1143 |
if (sdd->fromsnap == NULL || missingfrom) |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1144 |
sdd->seenfrom = B_TRUE; |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1145 |
|
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1146 |
rv = zfs_iter_snapshots_sorted(zhp, dump_snapshot, arg); |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1147 |
if (!sdd->seenfrom) { |
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1148 |
(void) fprintf(stderr, dgettext(TEXT_DOMAIN, |
12282
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1149 |
"WARNING: could not send %s@%s:\n" |
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1150 |
"incremental source (%s@%s) does not exist\n"), |
12282
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1151 |
zhp->zfs_name, sdd->tosnap, |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1152 |
zhp->zfs_name, sdd->fromsnap); |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1153 |
sdd->err = B_TRUE; |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1154 |
} else if (!sdd->seento) { |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1155 |
if (sdd->fromsnap) { |
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1156 |
(void) fprintf(stderr, dgettext(TEXT_DOMAIN, |
5367 | 1157 |
"WARNING: could not send %s@%s:\n" |
12282
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1158 |
"incremental source (%s@%s) " |
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1159 |
"is not earlier than it\n"), |
5367 | 1160 |
zhp->zfs_name, sdd->tosnap, |
1161 |
zhp->zfs_name, sdd->fromsnap); |
|
12282
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1162 |
} else { |
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1163 |
(void) fprintf(stderr, dgettext(TEXT_DOMAIN, |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1164 |
"WARNING: " |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1165 |
"could not send %s@%s: does not exist\n"), |
12282
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1166 |
zhp->zfs_name, sdd->tosnap); |
5367 | 1167 |
} |
12282
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1168 |
sdd->err = B_TRUE; |
5367 | 1169 |
} |
1170 |
||
1171 |
return (rv); |
|
1172 |
} |
|
1173 |
||
1174 |
static int |
|
1175 |
dump_filesystems(zfs_handle_t *rzhp, void *arg) |
|
1176 |
{ |
|
1177 |
send_dump_data_t *sdd = arg; |
|
1178 |
nvpair_t *fspair; |
|
1179 |
boolean_t needagain, progress; |
|
1180 |
||
1181 |
if (!sdd->replicate) |
|
1182 |
return (dump_filesystem(rzhp, sdd)); |
|
1183 |
||
12282
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1184 |
/* Mark the clone origin snapshots. */ |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1185 |
for (fspair = nvlist_next_nvpair(sdd->fss, NULL); fspair; |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1186 |
fspair = nvlist_next_nvpair(sdd->fss, fspair)) { |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1187 |
nvlist_t *nvfs; |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1188 |
uint64_t origin_guid = 0; |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1189 |
|
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1190 |
VERIFY(0 == nvpair_value_nvlist(fspair, &nvfs)); |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1191 |
(void) nvlist_lookup_uint64(nvfs, "origin", &origin_guid); |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1192 |
if (origin_guid != 0) { |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1193 |
char *snapname; |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1194 |
nvlist_t *origin_nv = fsavl_find(sdd->fsavl, |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1195 |
origin_guid, &snapname); |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1196 |
if (origin_nv != NULL) { |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1197 |
nvlist_t *snapprops; |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1198 |
VERIFY(0 == nvlist_lookup_nvlist(origin_nv, |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1199 |
"snapprops", &snapprops)); |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1200 |
VERIFY(0 == nvlist_lookup_nvlist(snapprops, |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1201 |
snapname, &snapprops)); |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1202 |
VERIFY(0 == nvlist_add_boolean( |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1203 |
snapprops, "is_clone_origin")); |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1204 |
} |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1205 |
} |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1206 |
} |
5367 | 1207 |
again: |
1208 |
needagain = progress = B_FALSE; |
|
1209 |
for (fspair = nvlist_next_nvpair(sdd->fss, NULL); fspair; |
|
1210 |
fspair = nvlist_next_nvpair(sdd->fss, fspair)) { |
|
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1211 |
nvlist_t *fslist, *parent_nv; |
5367 | 1212 |
char *fsname; |
1213 |
zfs_handle_t *zhp; |
|
1214 |
int err; |
|
1215 |
uint64_t origin_guid = 0; |
|
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1216 |
uint64_t parent_guid = 0; |
5367 | 1217 |
|
1218 |
VERIFY(nvpair_value_nvlist(fspair, &fslist) == 0); |
|
1219 |
if (nvlist_lookup_boolean(fslist, "sent") == 0) |
|
1220 |
continue; |
|
1221 |
||
1222 |
VERIFY(nvlist_lookup_string(fslist, "name", &fsname) == 0); |
|
1223 |
(void) nvlist_lookup_uint64(fslist, "origin", &origin_guid); |
|
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1224 |
(void) nvlist_lookup_uint64(fslist, "parentfromsnap", |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1225 |
&parent_guid); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1226 |
|
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1227 |
if (parent_guid != 0) { |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1228 |
parent_nv = fsavl_find(sdd->fsavl, parent_guid, NULL); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1229 |
if (!nvlist_exists(parent_nv, "sent")) { |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1230 |
/* parent has not been sent; skip this one */ |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1231 |
needagain = B_TRUE; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1232 |
continue; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1233 |
} |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1234 |
} |
5367 | 1235 |
|
12282
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1236 |
if (origin_guid != 0) { |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1237 |
nvlist_t *origin_nv = fsavl_find(sdd->fsavl, |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1238 |
origin_guid, NULL); |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1239 |
if (origin_nv != NULL && |
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1240 |
!nvlist_exists(origin_nv, "sent")) { |
12282
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1241 |
/* |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1242 |
* origin has not been sent yet; |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1243 |
* skip this clone. |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1244 |
*/ |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1245 |
needagain = B_TRUE; |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1246 |
continue; |
a121efaf294e
6946467 'zfs send -Ri' should include clone origin snapshots in the specified interval
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
12141
diff
changeset
|
1247 |
} |
5367 | 1248 |
} |
1249 |
||
1250 |
zhp = zfs_open(rzhp->zfs_hdl, fsname, ZFS_TYPE_DATASET); |
|
6476 | 1251 |
if (zhp == NULL) |
1252 |
return (-1); |
|
5367 | 1253 |
err = dump_filesystem(zhp, sdd); |
1254 |
VERIFY(nvlist_add_boolean(fslist, "sent") == 0); |
|
1255 |
progress = B_TRUE; |
|
1256 |
zfs_close(zhp); |
|
1257 |
if (err) |
|
1258 |
return (err); |
|
1259 |
} |
|
1260 |
if (needagain) { |
|
1261 |
assert(progress); |
|
1262 |
goto again; |
|
1263 |
} |
|
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1264 |
|
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1265 |
/* clean out the sent flags in case we reuse this fss */ |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1266 |
for (fspair = nvlist_next_nvpair(sdd->fss, NULL); fspair; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1267 |
fspair = nvlist_next_nvpair(sdd->fss, fspair)) { |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1268 |
nvlist_t *fslist; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1269 |
|
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1270 |
VERIFY(nvpair_value_nvlist(fspair, &fslist) == 0); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1271 |
(void) nvlist_remove_all(fslist, "sent"); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1272 |
} |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1273 |
|
5367 | 1274 |
return (0); |
1275 |
} |
|
1276 |
||
1277 |
/* |
|
10200
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
1278 |
* 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
|
1279 |
* |
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
1280 |
* 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
|
1281 |
* '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
|
1282 |
* - 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
|
1283 |
* - 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
|
1284 |
* 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
|
1285 |
* is TRUE. |
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
1286 |
* |
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
1287 |
* 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
|
1288 |
* 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
|
1289 |
* 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
|
1290 |
* 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
|
1291 |
* case too. If "props" is set, send properties. |
5367 | 1292 |
*/ |
1293 |
int |
|
1294 |
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
|
1295 |
sendflags_t flags, int outfd, snapfilter_cb_t filter_func, |
12296
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
12282
diff
changeset
|
1296 |
void *cb_arg, nvlist_t **debugnvp) |
5367 | 1297 |
{ |
1298 |
char errbuf[1024]; |
|
1299 |
send_dump_data_t sdd = { 0 }; |
|
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1300 |
int err = 0; |
5367 | 1301 |
nvlist_t *fss = NULL; |
1302 |
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
|
1303 |
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
|
1304 |
int spa_version; |
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1305 |
boolean_t holdsnaps = B_FALSE; |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1306 |
pthread_t tid; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1307 |
int pipefd[2]; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1308 |
dedup_arg_t dda = { 0 }; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1309 |
int featureflags = 0; |
11935
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
1310 |
|
5367 | 1311 |
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, |
1312 |
"cannot send '%s'"), zhp->zfs_name); |
|
1313 |
||
1314 |
if (fromsnap && fromsnap[0] == '\0') { |
|
1315 |
zfs_error_aux(zhp->zfs_hdl, dgettext(TEXT_DOMAIN, |
|
1316 |
"zero-length incremental source")); |
|
1317 |
return (zfs_error(zhp->zfs_hdl, EZFS_NOENT, errbuf)); |
|
1318 |
} |
|
1319 |
||
12798
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1320 |
if (zhp->zfs_type == ZFS_TYPE_FILESYSTEM) { |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1321 |
uint64_t version; |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1322 |
version = zfs_prop_get_int(zhp, ZFS_PROP_VERSION); |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1323 |
if (version >= ZPL_VERSION_SA) { |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1324 |
featureflags |= DMU_BACKUP_FEATURE_SA_SPILL; |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1325 |
} |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1326 |
} |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1327 |
|
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1328 |
if (!flags.noop && zfs_spa_version(zhp, &spa_version) == 0 && |
12798
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1329 |
spa_version >= SPA_VERSION_USERREFS && |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1330 |
(flags.doall || flags.replicate)) |
10735
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1331 |
holdsnaps = B_TRUE; |
336fb268ea6f
6885860 zfs send shouldn't require support for snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10602
diff
changeset
|
1332 |
|
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1333 |
if (flags.dedup && !flags.noop) { |
11381
c77e4d2b2e75
6907006 zfs over-the-wire dedup recalculates checksums unnecessarily
Lori Alt <Lori.Alt@Sun.COM>
parents:
11022
diff
changeset
|
1334 |
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
|
1335 |
DMU_BACKUP_FEATURE_DEDUPPROPS); |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1336 |
if (err = pipe(pipefd)) { |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1337 |
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
|
1338 |
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
|
1339 |
errbuf)); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1340 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1341 |
dda.outputfd = outfd; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1342 |
dda.inputfd = pipefd[1]; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1343 |
dda.dedup_hdl = zhp->zfs_hdl; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1344 |
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
|
1345 |
(void) close(pipefd[0]); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1346 |
(void) close(pipefd[1]); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1347 |
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
|
1348 |
return (zfs_error(zhp->zfs_hdl, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1349 |
EZFS_THREADCREATEFAILED, errbuf)); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1350 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1351 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1352 |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1353 |
if (flags.replicate || flags.doall || flags.props) { |
5367 | 1354 |
dmu_replay_record_t drr = { 0 }; |
1355 |
char *packbuf = NULL; |
|
1356 |
size_t buflen = 0; |
|
1357 |
zio_cksum_t zc = { 0 }; |
|
1358 |
||
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1359 |
if (flags.replicate || flags.props) { |
5367 | 1360 |
nvlist_t *hdrnv; |
1361 |
||
1362 |
VERIFY(0 == nvlist_alloc(&hdrnv, NV_UNIQUE_NAME, 0)); |
|
1363 |
if (fromsnap) { |
|
1364 |
VERIFY(0 == nvlist_add_string(hdrnv, |
|
1365 |
"fromsnap", fromsnap)); |
|
1366 |
} |
|
1367 |
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
|
1368 |
if (!flags.replicate) { |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1369 |
VERIFY(0 == nvlist_add_boolean(hdrnv, |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1370 |
"not_recursive")); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1371 |
} |
5367 | 1372 |
|
1373 |
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
|
1374 |
fromsnap, tosnap, flags.replicate, &fss, &fsavl); |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12296
diff
changeset
|
1375 |
if (err) |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1376 |
goto err_out; |
5367 | 1377 |
VERIFY(0 == nvlist_add_nvlist(hdrnv, "fss", fss)); |
1378 |
err = nvlist_pack(hdrnv, &packbuf, &buflen, |
|
1379 |
NV_ENCODE_XDR, 0); |
|
12296
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
12282
diff
changeset
|
1380 |
if (debugnvp) |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
12282
diff
changeset
|
1381 |
*debugnvp = hdrnv; |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
12282
diff
changeset
|
1382 |
else |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
12282
diff
changeset
|
1383 |
nvlist_free(hdrnv); |
5367 | 1384 |
if (err) { |
1385 |
fsavl_destroy(fsavl); |
|
1386 |
nvlist_free(fss); |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1387 |
goto stderr_out; |
5367 | 1388 |
} |
1389 |
} |
|
1390 |
||
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1391 |
if (!flags.noop) { |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1392 |
/* write first begin record */ |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1393 |
drr.drr_type = DRR_BEGIN; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1394 |
drr.drr_u.drr_begin.drr_magic = DMU_BACKUP_MAGIC; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1395 |
DMU_SET_STREAM_HDRTYPE(drr.drr_u.drr_begin. |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1396 |
drr_versioninfo, DMU_COMPOUNDSTREAM); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1397 |
DMU_SET_FEATUREFLAGS(drr.drr_u.drr_begin. |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1398 |
drr_versioninfo, featureflags); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1399 |
(void) snprintf(drr.drr_u.drr_begin.drr_toname, |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1400 |
sizeof (drr.drr_u.drr_begin.drr_toname), |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1401 |
"%s@%s", zhp->zfs_name, tosnap); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1402 |
drr.drr_payloadlen = buflen; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1403 |
err = cksum_and_write(&drr, sizeof (drr), &zc, outfd); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1404 |
|
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1405 |
/* write header nvlist */ |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1406 |
if (err != -1 && packbuf != NULL) { |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1407 |
err = cksum_and_write(packbuf, buflen, &zc, |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1408 |
outfd); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1409 |
} |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1410 |
free(packbuf); |
5367 | 1411 |
if (err == -1) { |
1412 |
fsavl_destroy(fsavl); |
|
1413 |
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
|
1414 |
err = errno; |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1415 |
goto stderr_out; |
5367 | 1416 |
} |
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1417 |
|
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1418 |
/* write end record */ |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1419 |
if (err != -1) { |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1420 |
bzero(&drr, sizeof (drr)); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1421 |
drr.drr_type = DRR_END; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1422 |
drr.drr_u.drr_end.drr_checksum = zc; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1423 |
err = write(outfd, &drr, sizeof (drr)); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1424 |
if (err == -1) { |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1425 |
fsavl_destroy(fsavl); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1426 |
nvlist_free(fss); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1427 |
err = errno; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1428 |
goto stderr_out; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1429 |
} |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1430 |
} |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1431 |
if (err != -1) |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1432 |
err = 0; |
5367 | 1433 |
} |
1434 |
} |
|
1435 |
||
1436 |
/* dump each stream */ |
|
1437 |
sdd.fromsnap = fromsnap; |
|
1438 |
sdd.tosnap = tosnap; |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1439 |
if (flags.dedup) |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1440 |
sdd.outfd = pipefd[0]; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1441 |
else |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1442 |
sdd.outfd = outfd; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1443 |
sdd.replicate = flags.replicate; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1444 |
sdd.doall = flags.doall; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1445 |
sdd.fromorigin = flags.fromorigin; |
5367 | 1446 |
sdd.fss = fss; |
1447 |
sdd.fsavl = fsavl; |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1448 |
sdd.verbose = flags.verbose; |
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1449 |
sdd.parsable = flags.parsable; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1450 |
sdd.noop = flags.noop; |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1451 |
sdd.filter_cb = filter_func; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1452 |
sdd.filter_cb_arg = cb_arg; |
12296
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
12282
diff
changeset
|
1453 |
if (debugnvp) |
7cf402a7f374
6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents:
12282
diff
changeset
|
1454 |
sdd.debugnv = *debugnvp; |
12798
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1455 |
if (holdsnaps) { |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1456 |
++holdseq; |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1457 |
(void) snprintf(sdd.holdtag, sizeof (sdd.holdtag), |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1458 |
".send-%d-%llu", getpid(), (u_longlong_t)holdseq); |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1459 |
sdd.cleanup_fd = open(ZFS_DEV, O_RDWR|O_EXCL); |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1460 |
if (sdd.cleanup_fd < 0) { |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1461 |
err = errno; |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1462 |
goto stderr_out; |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1463 |
} |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1464 |
} else { |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1465 |
sdd.cleanup_fd = -1; |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1466 |
} |
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1467 |
if (flags.verbose) { |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1468 |
/* |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1469 |
* Do a verbose no-op dry run to get all the verbose output |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1470 |
* before generating any data. Then do a non-verbose real |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1471 |
* run to generate the streams. |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1472 |
*/ |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1473 |
sdd.noop = B_TRUE; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1474 |
err = dump_filesystems(zhp, &sdd); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1475 |
sdd.noop = flags.noop; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1476 |
sdd.verbose = B_FALSE; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1477 |
if (flags.parsable) { |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1478 |
(void) fprintf(stderr, "size\t%llu\n", |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1479 |
(longlong_t)sdd.size); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1480 |
} else { |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1481 |
char buf[16]; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1482 |
zfs_nicenum(sdd.size, buf, sizeof (buf)); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1483 |
(void) fprintf(stderr, dgettext(TEXT_DOMAIN, |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1484 |
"total estimated size is %s\n"), buf); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1485 |
} |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1486 |
} |
5367 | 1487 |
err = dump_filesystems(zhp, &sdd); |
1488 |
fsavl_destroy(fsavl); |
|
1489 |
nvlist_free(fss); |
|
1490 |
||
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1491 |
if (flags.dedup) { |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1492 |
(void) close(pipefd[0]); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1493 |
(void) pthread_join(tid, NULL); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1494 |
} |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1495 |
|
12798
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1496 |
if (sdd.cleanup_fd != -1) { |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1497 |
VERIFY(0 == close(sdd.cleanup_fd)); |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1498 |
sdd.cleanup_fd = -1; |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12296
diff
changeset
|
1499 |
} |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12296
diff
changeset
|
1500 |
|
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1501 |
if (!flags.noop && (flags.replicate || flags.doall || flags.props)) { |
5367 | 1502 |
/* |
1503 |
* write final end record. NB: want to do this even if |
|
1504 |
* there was some error, because it might not be totally |
|
1505 |
* failed. |
|
1506 |
*/ |
|
1507 |
dmu_replay_record_t drr = { 0 }; |
|
1508 |
drr.drr_type = DRR_END; |
|
1509 |
if (write(outfd, &drr, sizeof (drr)) == -1) { |
|
1510 |
return (zfs_standard_error(zhp->zfs_hdl, |
|
1511 |
errno, errbuf)); |
|
1512 |
} |
|
1513 |
} |
|
1514 |
||
1515 |
return (err || sdd.err); |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1516 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1517 |
stderr_out: |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1518 |
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
|
1519 |
err_out: |
12798
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1520 |
if (sdd.cleanup_fd != -1) |
f6c8601080b4
6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12527
diff
changeset
|
1521 |
VERIFY(0 == close(sdd.cleanup_fd)); |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1522 |
if (flags.dedup) { |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1523 |
(void) pthread_cancel(tid); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1524 |
(void) pthread_join(tid, NULL); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1525 |
(void) close(pipefd[0]); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1526 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
1527 |
return (err); |
5367 | 1528 |
} |
1529 |
||
1530 |
/* |
|
1531 |
* Routines specific to "zfs recv" |
|
1532 |
*/ |
|
1533 |
||
1534 |
static int |
|
1535 |
recv_read(libzfs_handle_t *hdl, int fd, void *buf, int ilen, |
|
1536 |
boolean_t byteswap, zio_cksum_t *zc) |
|
1537 |
{ |
|
1538 |
char *cp = buf; |
|
1539 |
int rv; |
|
1540 |
int len = ilen; |
|
1541 |
||
1542 |
do { |
|
1543 |
rv = read(fd, cp, len); |
|
1544 |
cp += rv; |
|
1545 |
len -= rv; |
|
1546 |
} while (rv > 0); |
|
1547 |
||
1548 |
if (rv < 0 || len != 0) { |
|
1549 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
1550 |
"failed to read from stream")); |
|
1551 |
return (zfs_error(hdl, EZFS_BADSTREAM, dgettext(TEXT_DOMAIN, |
|
1552 |
"cannot receive"))); |
|
1553 |
} |
|
1554 |
||
1555 |
if (zc) { |
|
1556 |
if (byteswap) |
|
1557 |
fletcher_4_incremental_byteswap(buf, ilen, zc); |
|
1558 |
else |
|
1559 |
fletcher_4_incremental_native(buf, ilen, zc); |
|
1560 |
} |
|
1561 |
return (0); |
|
1562 |
} |
|
1563 |
||
1564 |
static int |
|
1565 |
recv_read_nvlist(libzfs_handle_t *hdl, int fd, int len, nvlist_t **nvp, |
|
1566 |
boolean_t byteswap, zio_cksum_t *zc) |
|
1567 |
{ |
|
1568 |
char *buf; |
|
1569 |
int err; |
|
1570 |
||
1571 |
buf = zfs_alloc(hdl, len); |
|
1572 |
if (buf == NULL) |
|
1573 |
return (ENOMEM); |
|
1574 |
||
1575 |
err = recv_read(hdl, fd, buf, len, byteswap, zc); |
|
1576 |
if (err != 0) { |
|
1577 |
free(buf); |
|
1578 |
return (err); |
|
1579 |
} |
|
1580 |
||
1581 |
err = nvlist_unpack(buf, len, nvp, 0); |
|
1582 |
free(buf); |
|
1583 |
if (err != 0) { |
|
1584 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "invalid " |
|
1585 |
"stream (malformed nvlist)")); |
|
1586 |
return (EINVAL); |
|
1587 |
} |
|
1588 |
return (0); |
|
1589 |
} |
|
1590 |
||
1591 |
static int |
|
1592 |
recv_rename(libzfs_handle_t *hdl, const char *name, const char *tryname, |
|
1593 |
int baselen, char *newname, recvflags_t flags) |
|
1594 |
{ |
|
1595 |
static int seq; |
|
1596 |
zfs_cmd_t zc = { 0 }; |
|
1597 |
int err; |
|
6047
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1598 |
prop_changelist_t *clp; |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1599 |
zfs_handle_t *zhp; |
5367 | 1600 |
|
6047
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1601 |
zhp = zfs_open(hdl, name, ZFS_TYPE_DATASET); |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1602 |
if (zhp == NULL) |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1603 |
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
|
1604 |
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
|
1605 |
flags.force ? MS_FORCE : 0); |
6047
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1606 |
zfs_close(zhp); |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1607 |
if (clp == NULL) |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1608 |
return (-1); |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1609 |
err = changelist_prefix(clp); |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1610 |
if (err) |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1611 |
return (err); |
5367 | 1612 |
|
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10200
diff
changeset
|
1613 |
zc.zc_objset_type = DMU_OST_ZFS; |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10200
diff
changeset
|
1614 |
(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
|
1615 |
|
5367 | 1616 |
if (tryname) { |
1617 |
(void) strcpy(newname, tryname); |
|
1618 |
||
1619 |
(void) strlcpy(zc.zc_value, tryname, sizeof (zc.zc_value)); |
|
1620 |
||
1621 |
if (flags.verbose) { |
|
1622 |
(void) printf("attempting rename %s to %s\n", |
|
1623 |
zc.zc_name, zc.zc_value); |
|
1624 |
} |
|
1625 |
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
|
1626 |
if (err == 0) |
5367 | 1627 |
changelist_rename(clp, name, tryname); |
1628 |
} else { |
|
1629 |
err = ENOENT; |
|
1630 |
} |
|
1631 |
||
1632 |
if (err != 0 && strncmp(name+baselen, "recv-", 5) != 0) { |
|
1633 |
seq++; |
|
1634 |
||
1635 |
(void) strncpy(newname, name, baselen); |
|
1636 |
(void) snprintf(newname+baselen, ZFS_MAXNAMELEN-baselen, |
|
1637 |
"recv-%u-%u", getpid(), seq); |
|
1638 |
(void) strlcpy(zc.zc_value, newname, sizeof (zc.zc_value)); |
|
1639 |
||
1640 |
if (flags.verbose) { |
|
1641 |
(void) printf("failed - trying rename %s to %s\n", |
|
1642 |
zc.zc_name, zc.zc_value); |
|
1643 |
} |
|
1644 |
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
|
1645 |
if (err == 0) |
5367 | 1646 |
changelist_rename(clp, name, newname); |
1647 |
if (err && flags.verbose) { |
|
1648 |
(void) printf("failed (%u) - " |
|
1649 |
"will try again on next pass\n", errno); |
|
1650 |
} |
|
1651 |
err = EAGAIN; |
|
1652 |
} else if (flags.verbose) { |
|
1653 |
if (err == 0) |
|
1654 |
(void) printf("success\n"); |
|
1655 |
else |
|
1656 |
(void) printf("failed (%u)\n", errno); |
|
1657 |
} |
|
1658 |
||
6047
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1659 |
(void) changelist_postfix(clp); |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1660 |
changelist_free(clp); |
5367 | 1661 |
|
1662 |
return (err); |
|
1663 |
} |
|
1664 |
||
1665 |
static int |
|
1666 |
recv_destroy(libzfs_handle_t *hdl, const char *name, int baselen, |
|
1667 |
char *newname, recvflags_t flags) |
|
1668 |
{ |
|
1669 |
zfs_cmd_t zc = { 0 }; |
|
6047
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1670 |
int err = 0; |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1671 |
prop_changelist_t *clp; |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1672 |
zfs_handle_t *zhp; |
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10200
diff
changeset
|
1673 |
boolean_t defer = B_FALSE; |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10200
diff
changeset
|
1674 |
int spa_version; |
6047
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1675 |
|
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1676 |
zhp = zfs_open(hdl, name, ZFS_TYPE_DATASET); |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1677 |
if (zhp == NULL) |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1678 |
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
|
1679 |
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
|
1680 |
flags.force ? MS_FORCE : 0); |
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10200
diff
changeset
|
1681 |
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
|
1682 |
zfs_spa_version(zhp, &spa_version) == 0 && |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10200
diff
changeset
|
1683 |
spa_version >= SPA_VERSION_USERREFS) |
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10200
diff
changeset
|
1684 |
defer = B_TRUE; |
6047
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1685 |
zfs_close(zhp); |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1686 |
if (clp == NULL) |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1687 |
return (-1); |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1688 |
err = changelist_prefix(clp); |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1689 |
if (err) |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1690 |
return (err); |
5367 | 1691 |
|
1692 |
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
|
1693 |
zc.zc_defer_destroy = defer; |
5367 | 1694 |
(void) strlcpy(zc.zc_name, name, sizeof (zc.zc_name)); |
1695 |
||
1696 |
if (flags.verbose) |
|
1697 |
(void) printf("attempting destroy %s\n", zc.zc_name); |
|
1698 |
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
|
1699 |
if (err == 0) { |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1700 |
if (flags.verbose) |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1701 |
(void) printf("success\n"); |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1702 |
changelist_remove(clp, zc.zc_name); |
5367 | 1703 |
} |
1704 |
||
6047
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1705 |
(void) changelist_postfix(clp); |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1706 |
changelist_free(clp); |
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1707 |
|
10242
c40d075fbca6
PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents:
10200
diff
changeset
|
1708 |
/* |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1709 |
* 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
|
1710 |
* 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
|
1711 |
*/ |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1712 |
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
|
1713 |
ZFS_TYPE_SNAPSHOT))) { |
6047
235fee4665e7
6598604 BAD TRAP while set property to multiple filesystems
ahrens
parents:
5896
diff
changeset
|
1714 |
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
|
1715 |
} |
5367 | 1716 |
|
1717 |
return (err); |
|
1718 |
} |
|
1719 |
||
1720 |
typedef struct guid_to_name_data { |
|
1721 |
uint64_t guid; |
|
1722 |
char *name; |
|
1723 |
} guid_to_name_data_t; |
|
1724 |
||
1725 |
static int |
|
1726 |
guid_to_name_cb(zfs_handle_t *zhp, void *arg) |
|
1727 |
{ |
|
1728 |
guid_to_name_data_t *gtnd = arg; |
|
1729 |
int err; |
|
1730 |
||
1731 |
if (zhp->zfs_dmustats.dds_guid == gtnd->guid) { |
|
1732 |
(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
|
1733 |
zfs_close(zhp); |
5367 | 1734 |
return (EEXIST); |
1735 |
} |
|
1736 |
err = zfs_iter_children(zhp, guid_to_name_cb, gtnd); |
|
1737 |
zfs_close(zhp); |
|
1738 |
return (err); |
|
1739 |
} |
|
1740 |
||
1741 |
static int |
|
1742 |
guid_to_name(libzfs_handle_t *hdl, const char *parent, uint64_t guid, |
|
1743 |
char *name) |
|
1744 |
{ |
|
1745 |
/* exhaustive search all local snapshots */ |
|
1746 |
guid_to_name_data_t gtnd; |
|
1747 |
int err = 0; |
|
1748 |
zfs_handle_t *zhp; |
|
1749 |
char *cp; |
|
1750 |
||
1751 |
gtnd.guid = guid; |
|
1752 |
gtnd.name = name; |
|
1753 |
||
1754 |
if (strchr(parent, '@') == NULL) { |
|
1755 |
zhp = make_dataset_handle(hdl, parent); |
|
1756 |
if (zhp != NULL) { |
|
1757 |
err = zfs_iter_children(zhp, guid_to_name_cb, >nd); |
|
1758 |
zfs_close(zhp); |
|
1759 |
if (err == EEXIST) |
|
1760 |
return (0); |
|
1761 |
} |
|
1762 |
} |
|
1763 |
||
1764 |
cp = strchr(parent, '/'); |
|
1765 |
if (cp) |
|
1766 |
*cp = '\0'; |
|
1767 |
zhp = make_dataset_handle(hdl, parent); |
|
1768 |
if (cp) |
|
1769 |
*cp = '/'; |
|
1770 |
||
1771 |
if (zhp) { |
|
1772 |
err = zfs_iter_children(zhp, guid_to_name_cb, >nd); |
|
1773 |
zfs_close(zhp); |
|
1774 |
} |
|
1775 |
||
1776 |
return (err == EEXIST ? 0 : ENOENT); |
|
1777 |
||
1778 |
} |
|
1779 |
||
1780 |
/* |
|
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1781 |
* Return +1 if guid1 is before guid2, 0 if they are the same, and -1 if |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1782 |
* guid1 is after guid2. |
5367 | 1783 |
*/ |
6476 | 1784 |
static int |
5367 | 1785 |
created_before(libzfs_handle_t *hdl, avl_tree_t *avl, |
1786 |
uint64_t guid1, uint64_t guid2) |
|
1787 |
{ |
|
1788 |
nvlist_t *nvfs; |
|
1789 |
char *fsname, *snapname; |
|
1790 |
char buf[ZFS_MAXNAMELEN]; |
|
6476 | 1791 |
int rv; |
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1792 |
zfs_handle_t *guid1hdl, *guid2hdl; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1793 |
uint64_t create1, create2; |
5367 | 1794 |
|
1795 |
if (guid2 == 0) |
|
6476 | 1796 |
return (0); |
5367 | 1797 |
if (guid1 == 0) |
6476 | 1798 |
return (1); |
5367 | 1799 |
|
1800 |
nvfs = fsavl_find(avl, guid1, &snapname); |
|
1801 |
VERIFY(0 == nvlist_lookup_string(nvfs, "name", &fsname)); |
|
1802 |
(void) snprintf(buf, sizeof (buf), "%s@%s", fsname, snapname); |
|
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1803 |
guid1hdl = zfs_open(hdl, buf, ZFS_TYPE_SNAPSHOT); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1804 |
if (guid1hdl == NULL) |
6476 | 1805 |
return (-1); |
5367 | 1806 |
|
1807 |
nvfs = fsavl_find(avl, guid2, &snapname); |
|
1808 |
VERIFY(0 == nvlist_lookup_string(nvfs, "name", &fsname)); |
|
1809 |
(void) snprintf(buf, sizeof (buf), "%s@%s", fsname, snapname); |
|
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1810 |
guid2hdl = zfs_open(hdl, buf, ZFS_TYPE_SNAPSHOT); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1811 |
if (guid2hdl == NULL) { |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1812 |
zfs_close(guid1hdl); |
6476 | 1813 |
return (-1); |
1814 |
} |
|
5367 | 1815 |
|
13509
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1816 |
create1 = zfs_prop_get_int(guid1hdl, ZFS_PROP_CREATETXG); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1817 |
create2 = zfs_prop_get_int(guid2hdl, ZFS_PROP_CREATETXG); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1818 |
|
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1819 |
if (create1 < create2) |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1820 |
rv = -1; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1821 |
else if (create1 > create2) |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1822 |
rv = +1; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1823 |
else |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1824 |
rv = 0; |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1825 |
|
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1826 |
zfs_close(guid1hdl); |
04570f5cbeca
1644 add ZFS "clones" property
Matthew Ahrens <matt@delphix.com>
parents:
12798
diff
changeset
|
1827 |
zfs_close(guid2hdl); |
5367 | 1828 |
|
1829 |
return (rv); |
|
1830 |
} |
|
1831 |
||
1832 |
static int |
|
1833 |
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
|
1834 |
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
|
1835 |
nvlist_t *renamed) |
5367 | 1836 |
{ |
1837 |
nvlist_t *local_nv; |
|
1838 |
avl_tree_t *local_avl; |
|
1839 |
nvpair_t *fselem, *nextfselem; |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
1840 |
char *fromsnap; |
5367 | 1841 |
char newname[ZFS_MAXNAMELEN]; |
1842 |
int error; |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1843 |
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
|
1844 |
char *s1, *s2; |
5367 | 1845 |
|
1846 |
VERIFY(0 == nvlist_lookup_string(stream_nv, "fromsnap", &fromsnap)); |
|
1847 |
||
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1848 |
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
|
1849 |
ENOENT); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1850 |
|
5367 | 1851 |
if (flags.dryrun) |
1852 |
return (0); |
|
1853 |
||
1854 |
again: |
|
1855 |
needagain = progress = B_FALSE; |
|
1856 |
||
1857 |
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
|
1858 |
recursive, &local_nv, &local_avl)) != 0) |
5367 | 1859 |
return (error); |
1860 |
||
1861 |
/* |
|
1862 |
* Process deletes and renames |
|
1863 |
*/ |
|
1864 |
for (fselem = nvlist_next_nvpair(local_nv, NULL); |
|
1865 |
fselem; fselem = nextfselem) { |
|
1866 |
nvlist_t *nvfs, *snaps; |
|
1867 |
nvlist_t *stream_nvfs = NULL; |
|
1868 |
nvpair_t *snapelem, *nextsnapelem; |
|
1869 |
uint64_t fromguid = 0; |
|
1870 |
uint64_t originguid = 0; |
|
1871 |
uint64_t stream_originguid = 0; |
|
1872 |
uint64_t parent_fromsnap_guid, stream_parent_fromsnap_guid; |
|
1873 |
char *fsname, *stream_fsname; |
|
1874 |
||
1875 |
nextfselem = nvlist_next_nvpair(local_nv, fselem); |
|
1876 |
||
1877 |
VERIFY(0 == nvpair_value_nvlist(fselem, &nvfs)); |
|
1878 |
VERIFY(0 == nvlist_lookup_nvlist(nvfs, "snaps", &snaps)); |
|
1879 |
VERIFY(0 == nvlist_lookup_string(nvfs, "name", &fsname)); |
|
1880 |
VERIFY(0 == nvlist_lookup_uint64(nvfs, "parentfromsnap", |
|
1881 |
&parent_fromsnap_guid)); |
|
1882 |
(void) nvlist_lookup_uint64(nvfs, "origin", &originguid); |
|
1883 |
||
1884 |
/* |
|
1885 |
* First find the stream's fs, so we can check for |
|
1886 |
* a different origin (due to "zfs promote") |
|
1887 |
*/ |
|
1888 |
for (snapelem = nvlist_next_nvpair(snaps, NULL); |
|
1889 |
snapelem; snapelem = nvlist_next_nvpair(snaps, snapelem)) { |
|
1890 |
uint64_t thisguid; |
|
1891 |
||
1892 |
VERIFY(0 == nvpair_value_uint64(snapelem, &thisguid)); |
|
1893 |
stream_nvfs = fsavl_find(stream_avl, thisguid, NULL); |
|
1894 |
||
1895 |
if (stream_nvfs != NULL) |
|
1896 |
break; |
|
1897 |
} |
|
1898 |
||
1899 |
/* check for promote */ |
|
1900 |
(void) nvlist_lookup_uint64(stream_nvfs, "origin", |
|
1901 |
&stream_originguid); |
|
1902 |
if (stream_nvfs && originguid != stream_originguid) { |
|
6476 | 1903 |
switch (created_before(hdl, local_avl, |
1904 |
stream_originguid, originguid)) { |
|
1905 |
case 1: { |
|
5367 | 1906 |
/* promote it! */ |
1907 |
zfs_cmd_t zc = { 0 }; |
|
1908 |
nvlist_t *origin_nvfs; |
|
1909 |
char *origin_fsname; |
|
1910 |
||
1911 |
if (flags.verbose) |
|
1912 |
(void) printf("promoting %s\n", fsname); |
|
1913 |
||
1914 |
origin_nvfs = fsavl_find(local_avl, originguid, |
|
1915 |
NULL); |
|
1916 |
VERIFY(0 == nvlist_lookup_string(origin_nvfs, |
|
1917 |
"name", &origin_fsname)); |
|
1918 |
(void) strlcpy(zc.zc_value, origin_fsname, |
|
1919 |
sizeof (zc.zc_value)); |
|
1920 |
(void) strlcpy(zc.zc_name, fsname, |
|
1921 |
sizeof (zc.zc_name)); |
|
1922 |
error = zfs_ioctl(hdl, ZFS_IOC_PROMOTE, &zc); |
|
1923 |
if (error == 0) |
|
1924 |
progress = B_TRUE; |
|
6476 | 1925 |
break; |
1926 |
} |
|
1927 |
default: |
|
1928 |
break; |
|
1929 |
case -1: |
|
1930 |
fsavl_destroy(local_avl); |
|
1931 |
nvlist_free(local_nv); |
|
1932 |
return (-1); |
|
5367 | 1933 |
} |
1934 |
/* |
|
1935 |
* We had/have the wrong origin, therefore our |
|
1936 |
* list of snapshots is wrong. Need to handle |
|
1937 |
* them on the next pass. |
|
1938 |
*/ |
|
1939 |
needagain = B_TRUE; |
|
1940 |
continue; |
|
1941 |
} |
|
1942 |
||
1943 |
for (snapelem = nvlist_next_nvpair(snaps, NULL); |
|
1944 |
snapelem; snapelem = nextsnapelem) { |
|
1945 |
uint64_t thisguid; |
|
1946 |
char *stream_snapname; |
|
7265 | 1947 |
nvlist_t *found, *props; |
5367 | 1948 |
|
1949 |
nextsnapelem = nvlist_next_nvpair(snaps, snapelem); |
|
1950 |
||
1951 |
VERIFY(0 == nvpair_value_uint64(snapelem, &thisguid)); |
|
1952 |
found = fsavl_find(stream_avl, thisguid, |
|
1953 |
&stream_snapname); |
|
1954 |
||
1955 |
/* check for delete */ |
|
1956 |
if (found == NULL) { |
|
1957 |
char name[ZFS_MAXNAMELEN]; |
|
1958 |
||
1959 |
if (!flags.force) |
|
1960 |
continue; |
|
1961 |
||
1962 |
(void) snprintf(name, sizeof (name), "%s@%s", |
|
1963 |
fsname, nvpair_name(snapelem)); |
|
1964 |
||
1965 |
error = recv_destroy(hdl, name, |
|
1966 |
strlen(fsname)+1, newname, flags); |
|
1967 |
if (error) |
|
1968 |
needagain = B_TRUE; |
|
1969 |
else |
|
1970 |
progress = B_TRUE; |
|
1971 |
continue; |
|
1972 |
} |
|
1973 |
||
1974 |
stream_nvfs = found; |
|
1975 |
||
7265 | 1976 |
if (0 == nvlist_lookup_nvlist(stream_nvfs, "snapprops", |
1977 |
&props) && 0 == nvlist_lookup_nvlist(props, |
|
1978 |
stream_snapname, &props)) { |
|
1979 |
zfs_cmd_t zc = { 0 }; |
|
1980 |
||
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
1981 |
zc.zc_cookie = B_TRUE; /* received */ |
7273
6baaca4d907c
6701797 want user properties on snapshots (fix lint)
ahrens
parents:
7265
diff
changeset
|
1982 |
(void) snprintf(zc.zc_name, sizeof (zc.zc_name), |
7265 | 1983 |
"%s@%s", fsname, nvpair_name(snapelem)); |
1984 |
if (zcmd_write_src_nvlist(hdl, &zc, |
|
1985 |
props) == 0) { |
|
1986 |
(void) zfs_ioctl(hdl, |
|
1987 |
ZFS_IOC_SET_PROP, &zc); |
|
1988 |
zcmd_free_nvlists(&zc); |
|
1989 |
} |
|
1990 |
} |
|
1991 |
||
5367 | 1992 |
/* check for different snapname */ |
1993 |
if (strcmp(nvpair_name(snapelem), |
|
1994 |
stream_snapname) != 0) { |
|
1995 |
char name[ZFS_MAXNAMELEN]; |
|
1996 |
char tryname[ZFS_MAXNAMELEN]; |
|
1997 |
||
1998 |
(void) snprintf(name, sizeof (name), "%s@%s", |
|
1999 |
fsname, nvpair_name(snapelem)); |
|
2000 |
(void) snprintf(tryname, sizeof (name), "%s@%s", |
|
2001 |
fsname, stream_snapname); |
|
2002 |
||
2003 |
error = recv_rename(hdl, name, tryname, |
|
2004 |
strlen(fsname)+1, newname, flags); |
|
2005 |
if (error) |
|
2006 |
needagain = B_TRUE; |
|
2007 |
else |
|
2008 |
progress = B_TRUE; |
|
2009 |
} |
|
2010 |
||
2011 |
if (strcmp(stream_snapname, fromsnap) == 0) |
|
2012 |
fromguid = thisguid; |
|
2013 |
} |
|
2014 |
||
2015 |
/* check for delete */ |
|
2016 |
if (stream_nvfs == NULL) { |
|
2017 |
if (!flags.force) |
|
2018 |
continue; |
|
2019 |
||
2020 |
error = recv_destroy(hdl, fsname, strlen(tofs)+1, |
|
2021 |
newname, flags); |
|
2022 |
if (error) |
|
2023 |
needagain = B_TRUE; |
|
2024 |
else |
|
2025 |
progress = B_TRUE; |
|
2026 |
continue; |
|
2027 |
} |
|
2028 |
||
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2029 |
if (fromguid == 0) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2030 |
if (flags.verbose) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2031 |
(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
|
2032 |
"fromsnap (%s in stream); must have " |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2033 |
"been deleted locally; ignoring\n", |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2034 |
fsname, fromsnap); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2035 |
} |
5367 | 2036 |
continue; |
2037 |
} |
|
2038 |
||
2039 |
VERIFY(0 == nvlist_lookup_string(stream_nvfs, |
|
2040 |
"name", &stream_fsname)); |
|
2041 |
VERIFY(0 == nvlist_lookup_uint64(stream_nvfs, |
|
2042 |
"parentfromsnap", &stream_parent_fromsnap_guid)); |
|
2043 |
||
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
|
2044 |
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
|
2045 |
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
|
2046 |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2047 |
/* |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2048 |
* 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
|
2049 |
* 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
|
2050 |
* datasets beneath it. |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2051 |
*/ |
5367 | 2052 |
if ((stream_parent_fromsnap_guid != 0 && |
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2053 |
parent_fromsnap_guid != 0 && |
5367 | 2054 |
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
|
2055 |
((flags.isprefix || strcmp(tofs, fsname) != 0) && |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2056 |
(s1 != NULL) && (s2 != NULL) && strcmp(s1, s2) != 0)) { |
5367 | 2057 |
nvlist_t *parent; |
2058 |
char tryname[ZFS_MAXNAMELEN]; |
|
2059 |
||
2060 |
parent = fsavl_find(local_avl, |
|
2061 |
stream_parent_fromsnap_guid, NULL); |
|
2062 |
/* |
|
2063 |
* NB: parent might not be found if we used the |
|
2064 |
* tosnap for stream_parent_fromsnap_guid, |
|
2065 |
* because the parent is a newly-created fs; |
|
2066 |
* we'll be able to rename it after we recv the |
|
2067 |
* new fs. |
|
2068 |
*/ |
|
2069 |
if (parent != NULL) { |
|
2070 |
char *pname; |
|
2071 |
||
2072 |
VERIFY(0 == nvlist_lookup_string(parent, "name", |
|
2073 |
&pname)); |
|
2074 |
(void) snprintf(tryname, sizeof (tryname), |
|
2075 |
"%s%s", pname, strrchr(stream_fsname, '/')); |
|
2076 |
} else { |
|
2077 |
tryname[0] = '\0'; |
|
2078 |
if (flags.verbose) { |
|
2079 |
(void) printf("local fs %s new parent " |
|
2080 |
"not found\n", fsname); |
|
2081 |
} |
|
2082 |
} |
|
2083 |
||
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2084 |
newname[0] = '\0'; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2085 |
|
5367 | 2086 |
error = recv_rename(hdl, fsname, tryname, |
2087 |
strlen(tofs)+1, newname, flags); |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2088 |
|
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2089 |
if (renamed != NULL && newname[0] != '\0') { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2090 |
VERIFY(0 == nvlist_add_boolean(renamed, |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2091 |
newname)); |
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 |
|
5367 | 2094 |
if (error) |
2095 |
needagain = B_TRUE; |
|
2096 |
else |
|
2097 |
progress = B_TRUE; |
|
2098 |
} |
|
2099 |
} |
|
2100 |
||
2101 |
fsavl_destroy(local_avl); |
|
2102 |
nvlist_free(local_nv); |
|
2103 |
||
2104 |
if (needagain && progress) { |
|
2105 |
/* do another pass to fix up temporary names */ |
|
2106 |
if (flags.verbose) |
|
2107 |
(void) printf("another pass:\n"); |
|
2108 |
goto again; |
|
2109 |
} |
|
2110 |
||
2111 |
return (needagain); |
|
2112 |
} |
|
2113 |
||
2114 |
static int |
|
2115 |
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
|
2116 |
recvflags_t flags, dmu_replay_record_t *drr, zio_cksum_t *zc, |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12296
diff
changeset
|
2117 |
char **top_zfs, int cleanup_fd, uint64_t *action_handlep) |
5367 | 2118 |
{ |
2119 |
nvlist_t *stream_nv = NULL; |
|
2120 |
avl_tree_t *stream_avl = NULL; |
|
2121 |
char *fromsnap = NULL; |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2122 |
char *cp; |
5367 | 2123 |
char tofs[ZFS_MAXNAMELEN]; |
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2124 |
char sendfs[ZFS_MAXNAMELEN]; |
5367 | 2125 |
char errbuf[1024]; |
2126 |
dmu_replay_record_t drre; |
|
2127 |
int error; |
|
2128 |
boolean_t anyerr = B_FALSE; |
|
6479 | 2129 |
boolean_t softerr = B_FALSE; |
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2130 |
boolean_t recursive; |
5367 | 2131 |
|
2132 |
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, |
|
2133 |
"cannot receive")); |
|
2134 |
||
2135 |
assert(drr->drr_type == DRR_BEGIN); |
|
2136 |
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
|
2137 |
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
|
2138 |
DMU_COMPOUNDSTREAM); |
5367 | 2139 |
|
2140 |
/* |
|
2141 |
* Read in the nvlist from the stream. |
|
2142 |
*/ |
|
2143 |
if (drr->drr_payloadlen != 0) { |
|
2144 |
error = recv_read_nvlist(hdl, fd, drr->drr_payloadlen, |
|
2145 |
&stream_nv, flags.byteswap, zc); |
|
2146 |
if (error) { |
|
2147 |
error = zfs_error(hdl, EZFS_BADSTREAM, errbuf); |
|
2148 |
goto out; |
|
2149 |
} |
|
2150 |
} |
|
2151 |
||
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2152 |
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
|
2153 |
ENOENT); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2154 |
|
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2155 |
if (recursive && strchr(destname, '@')) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2156 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2157 |
"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
|
2158 |
error = zfs_error(hdl, EZFS_BADSTREAM, errbuf); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2159 |
goto out; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2160 |
} |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2161 |
|
5367 | 2162 |
/* |
2163 |
* Read in the end record and verify checksum. |
|
2164 |
*/ |
|
2165 |
if (0 != (error = recv_read(hdl, fd, &drre, sizeof (drre), |
|
2166 |
flags.byteswap, NULL))) |
|
2167 |
goto out; |
|
2168 |
if (flags.byteswap) { |
|
2169 |
drre.drr_type = BSWAP_32(drre.drr_type); |
|
2170 |
drre.drr_u.drr_end.drr_checksum.zc_word[0] = |
|
2171 |
BSWAP_64(drre.drr_u.drr_end.drr_checksum.zc_word[0]); |
|
2172 |
drre.drr_u.drr_end.drr_checksum.zc_word[1] = |
|
2173 |
BSWAP_64(drre.drr_u.drr_end.drr_checksum.zc_word[1]); |
|
2174 |
drre.drr_u.drr_end.drr_checksum.zc_word[2] = |
|
2175 |
BSWAP_64(drre.drr_u.drr_end.drr_checksum.zc_word[2]); |
|
2176 |
drre.drr_u.drr_end.drr_checksum.zc_word[3] = |
|
2177 |
BSWAP_64(drre.drr_u.drr_end.drr_checksum.zc_word[3]); |
|
2178 |
} |
|
2179 |
if (drre.drr_type != DRR_END) { |
|
2180 |
error = zfs_error(hdl, EZFS_BADSTREAM, errbuf); |
|
2181 |
goto out; |
|
2182 |
} |
|
2183 |
if (!ZIO_CHECKSUM_EQUAL(drre.drr_u.drr_end.drr_checksum, *zc)) { |
|
2184 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
2185 |
"incorrect header checksum")); |
|
2186 |
error = zfs_error(hdl, EZFS_BADSTREAM, errbuf); |
|
2187 |
goto out; |
|
2188 |
} |
|
2189 |
||
2190 |
(void) nvlist_lookup_string(stream_nv, "fromsnap", &fromsnap); |
|
2191 |
||
2192 |
if (drr->drr_payloadlen != 0) { |
|
2193 |
nvlist_t *stream_fss; |
|
2194 |
||
2195 |
VERIFY(0 == nvlist_lookup_nvlist(stream_nv, "fss", |
|
2196 |
&stream_fss)); |
|
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2197 |
if ((stream_avl = fsavl_create(stream_fss)) == NULL) { |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2198 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2199 |
"couldn't allocate avl tree")); |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2200 |
error = zfs_error(hdl, EZFS_NOMEM, errbuf); |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2201 |
goto out; |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2202 |
} |
5367 | 2203 |
|
2204 |
if (fromsnap != NULL) { |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2205 |
nvlist_t *renamed = NULL; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2206 |
nvpair_t *pair = NULL; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2207 |
|
5367 | 2208 |
(void) strlcpy(tofs, destname, ZFS_MAXNAMELEN); |
2209 |
if (flags.isprefix) { |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2210 |
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
|
2211 |
int i; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2212 |
|
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2213 |
if (flags.istail) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2214 |
cp = strrchr(drrb->drr_toname, '/'); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2215 |
if (cp == NULL) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2216 |
(void) strlcat(tofs, "/", |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2217 |
ZFS_MAXNAMELEN); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2218 |
i = 0; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2219 |
} else { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2220 |
i = (cp - drrb->drr_toname); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2221 |
} |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2222 |
} else { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2223 |
i = strcspn(drrb->drr_toname, "/@"); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2224 |
} |
5367 | 2225 |
/* zfs_receive_one() will create_parents() */ |
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2226 |
(void) strlcat(tofs, &drrb->drr_toname[i], |
5367 | 2227 |
ZFS_MAXNAMELEN); |
2228 |
*strchr(tofs, '@') = '\0'; |
|
2229 |
} |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2230 |
|
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2231 |
if (recursive && !flags.dryrun && !flags.nomount) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2232 |
VERIFY(0 == nvlist_alloc(&renamed, |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2233 |
NV_UNIQUE_NAME, 0)); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2234 |
} |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2235 |
|
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2236 |
softerr = recv_incremental_replication(hdl, tofs, flags, |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2237 |
stream_nv, stream_avl, renamed); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2238 |
|
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2239 |
/* Unmount renamed filesystems before receiving. */ |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2240 |
while ((pair = nvlist_next_nvpair(renamed, |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2241 |
pair)) != NULL) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2242 |
zfs_handle_t *zhp; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2243 |
prop_changelist_t *clp = NULL; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2244 |
|
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2245 |
zhp = zfs_open(hdl, nvpair_name(pair), |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2246 |
ZFS_TYPE_FILESYSTEM); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2247 |
if (zhp != NULL) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2248 |
clp = changelist_gather(zhp, |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2249 |
ZFS_PROP_MOUNTPOINT, 0, 0); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2250 |
zfs_close(zhp); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2251 |
if (clp != NULL) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2252 |
softerr |= |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2253 |
changelist_prefix(clp); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2254 |
changelist_free(clp); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2255 |
} |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2256 |
} |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2257 |
} |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2258 |
|
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2259 |
nvlist_free(renamed); |
5367 | 2260 |
} |
2261 |
} |
|
2262 |
||
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2263 |
/* |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2264 |
* 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
|
2265 |
* 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
|
2266 |
* zfs_receive_one(). |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2267 |
*/ |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2268 |
(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
|
2269 |
ZFS_MAXNAMELEN); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2270 |
if ((cp = strchr(sendfs, '@')) != NULL) |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2271 |
*cp = '\0'; |
5367 | 2272 |
|
2273 |
/* Finally, receive each contained stream */ |
|
2274 |
do { |
|
2275 |
/* |
|
2276 |
* we should figure out if it has a recoverable |
|
2277 |
* error, in which case do a recv_skip() and drive on. |
|
2278 |
* Note, if we fail due to already having this guid, |
|
2279 |
* zfs_receive_one() will take care of it (ie, |
|
2280 |
* recv_skip() and return 0). |
|
2281 |
*/ |
|
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
|
2282 |
error = zfs_receive_impl(hdl, destname, flags, fd, |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12296
diff
changeset
|
2283 |
sendfs, stream_nv, stream_avl, top_zfs, cleanup_fd, |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12296
diff
changeset
|
2284 |
action_handlep); |
5367 | 2285 |
if (error == ENODATA) { |
2286 |
error = 0; |
|
2287 |
break; |
|
2288 |
} |
|
2289 |
anyerr |= error; |
|
2290 |
} while (error == 0); |
|
2291 |
||
2292 |
if (drr->drr_payloadlen != 0 && fromsnap != NULL) { |
|
2293 |
/* |
|
2294 |
* Now that we have the fs's they sent us, try the |
|
2295 |
* renames again. |
|
2296 |
*/ |
|
6479 | 2297 |
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
|
2298 |
stream_nv, stream_avl, NULL); |
5367 | 2299 |
} |
2300 |
||
2301 |
out: |
|
2302 |
fsavl_destroy(stream_avl); |
|
2303 |
if (stream_nv) |
|
2304 |
nvlist_free(stream_nv); |
|
6479 | 2305 |
if (softerr) |
2306 |
error = -2; |
|
5367 | 2307 |
if (anyerr) |
2308 |
error = -1; |
|
2309 |
return (error); |
|
2310 |
} |
|
2311 |
||
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2312 |
static void |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2313 |
trunc_prop_errs(int truncated) |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2314 |
{ |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2315 |
ASSERT(truncated != 0); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2316 |
|
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2317 |
if (truncated == 1) |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2318 |
(void) fprintf(stderr, dgettext(TEXT_DOMAIN, |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2319 |
"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
|
2320 |
else |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2321 |
(void) fprintf(stderr, dgettext(TEXT_DOMAIN, |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2322 |
"%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
|
2323 |
} |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2324 |
|
5367 | 2325 |
static int |
2326 |
recv_skip(libzfs_handle_t *hdl, int fd, boolean_t byteswap) |
|
2327 |
{ |
|
2328 |
dmu_replay_record_t *drr; |
|
2329 |
void *buf = malloc(1<<20); |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2330 |
char errbuf[1024]; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2331 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2332 |
(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
|
2333 |
"cannot receive:")); |
5367 | 2334 |
|
2335 |
/* XXX would be great to use lseek if possible... */ |
|
2336 |
drr = buf; |
|
2337 |
||
2338 |
while (recv_read(hdl, fd, drr, sizeof (dmu_replay_record_t), |
|
2339 |
byteswap, NULL) == 0) { |
|
2340 |
if (byteswap) |
|
2341 |
drr->drr_type = BSWAP_32(drr->drr_type); |
|
2342 |
||
2343 |
switch (drr->drr_type) { |
|
2344 |
case DRR_BEGIN: |
|
2345 |
/* 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
|
2346 |
if (drr->drr_payloadlen != 0) { |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2347 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2348 |
"invalid substream header")); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2349 |
return (zfs_error(hdl, EZFS_BADSTREAM, errbuf)); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2350 |
} |
5367 | 2351 |
break; |
2352 |
||
2353 |
case DRR_END: |
|
2354 |
free(buf); |
|
2355 |
return (0); |
|
2356 |
||
2357 |
case DRR_OBJECT: |
|
2358 |
if (byteswap) { |
|
2359 |
drr->drr_u.drr_object.drr_bonuslen = |
|
2360 |
BSWAP_32(drr->drr_u.drr_object. |
|
2361 |
drr_bonuslen); |
|
2362 |
} |
|
2363 |
(void) recv_read(hdl, fd, buf, |
|
2364 |
P2ROUNDUP(drr->drr_u.drr_object.drr_bonuslen, 8), |
|
2365 |
B_FALSE, NULL); |
|
2366 |
break; |
|
2367 |
||
2368 |
case DRR_WRITE: |
|
2369 |
if (byteswap) { |
|
2370 |
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
|
2371 |
BSWAP_64(drr->drr_u.drr_write.drr_length); |
5367 | 2372 |
} |
2373 |
(void) recv_read(hdl, fd, buf, |
|
2374 |
drr->drr_u.drr_write.drr_length, B_FALSE, NULL); |
|
2375 |
break; |
|
11935
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
2376 |
case DRR_SPILL: |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
2377 |
if (byteswap) { |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
2378 |
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
|
2379 |
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
|
2380 |
} |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
2381 |
(void) recv_read(hdl, fd, buf, |
538c866aaac6
6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11834
diff
changeset
|
2382 |
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
|
2383 |
break; |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2384 |
case DRR_WRITE_BYREF: |
5367 | 2385 |
case DRR_FREEOBJECTS: |
2386 |
case DRR_FREE: |
|
2387 |
break; |
|
2388 |
||
2389 |
default: |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2390 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2391 |
"invalid record type")); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2392 |
return (zfs_error(hdl, EZFS_BADSTREAM, errbuf)); |
5367 | 2393 |
} |
2394 |
} |
|
2395 |
||
2396 |
free(buf); |
|
2397 |
return (-1); |
|
2398 |
} |
|
2399 |
||
2400 |
/* |
|
2401 |
* Restores a backup of tosnap from the file descriptor specified by infd. |
|
2402 |
*/ |
|
2403 |
static int |
|
2404 |
zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap, |
|
2405 |
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
|
2406 |
dmu_replay_record_t *drr_noswap, const char *sendfs, |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12296
diff
changeset
|
2407 |
nvlist_t *stream_nv, avl_tree_t *stream_avl, char **top_zfs, int cleanup_fd, |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12296
diff
changeset
|
2408 |
uint64_t *action_handlep) |
5367 | 2409 |
{ |
2410 |
zfs_cmd_t zc = { 0 }; |
|
2411 |
time_t begin_time; |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2412 |
int ioctl_err, ioctl_errno, err; |
5367 | 2413 |
char *cp; |
2414 |
struct drr_begin *drrb = &drr->drr_u.drr_begin; |
|
2415 |
char errbuf[1024]; |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2416 |
char prop_errbuf[1024]; |
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2417 |
const char *chopprefix; |
5367 | 2418 |
boolean_t newfs = B_FALSE; |
2419 |
boolean_t stream_wantsnewfs; |
|
2420 |
uint64_t parent_snapguid = 0; |
|
2421 |
prop_changelist_t *clp = NULL; |
|
7265 | 2422 |
nvlist_t *snapprops_nvlist = NULL; |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2423 |
zprop_errflags_t prop_errflags; |
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2424 |
boolean_t recursive; |
5367 | 2425 |
|
2426 |
begin_time = time(NULL); |
|
2427 |
||
2428 |
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, |
|
2429 |
"cannot receive")); |
|
2430 |
||
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2431 |
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
|
2432 |
ENOENT); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2433 |
|
5367 | 2434 |
if (stream_avl != NULL) { |
7265 | 2435 |
char *snapname; |
2436 |
nvlist_t *fs = fsavl_find(stream_avl, drrb->drr_toguid, |
|
2437 |
&snapname); |
|
5367 | 2438 |
nvlist_t *props; |
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2439 |
int ret; |
5367 | 2440 |
|
2441 |
(void) nvlist_lookup_uint64(fs, "parentfromsnap", |
|
2442 |
&parent_snapguid); |
|
2443 |
err = nvlist_lookup_nvlist(fs, "props", &props); |
|
2444 |
if (err) |
|
2445 |
VERIFY(0 == nvlist_alloc(&props, NV_UNIQUE_NAME, 0)); |
|
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2446 |
|
5367 | 2447 |
if (flags.canmountoff) { |
2448 |
VERIFY(0 == nvlist_add_uint64(props, |
|
2449 |
zfs_prop_to_name(ZFS_PROP_CANMOUNT), 0)); |
|
2450 |
} |
|
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2451 |
ret = zcmd_write_src_nvlist(hdl, &zc, props); |
5367 | 2452 |
if (err) |
2453 |
nvlist_free(props); |
|
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2454 |
|
7265 | 2455 |
if (0 == nvlist_lookup_nvlist(fs, "snapprops", &props)) { |
2456 |
VERIFY(0 == nvlist_lookup_nvlist(props, |
|
2457 |
snapname, &snapprops_nvlist)); |
|
2458 |
} |
|
2459 |
||
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2460 |
if (ret != 0) |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2461 |
return (-1); |
5367 | 2462 |
} |
2463 |
||
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2464 |
cp = NULL; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2465 |
|
5367 | 2466 |
/* |
2467 |
* Determine how much of the snapshot name stored in the stream |
|
2468 |
* we are going to tack on to the name they specified on the |
|
2469 |
* command line, and how much we are going to chop off. |
|
2470 |
* |
|
2471 |
* If they specified a snapshot, chop the entire name stored in |
|
2472 |
* the stream. |
|
2473 |
*/ |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2474 |
if (flags.istail) { |
5367 | 2475 |
/* |
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2476 |
* 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
|
2477 |
* the tail of the sent snapshot path. |
5367 | 2478 |
*/ |
2479 |
if (strchr(tosnap, '@')) { |
|
2480 |
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
|
2481 |
"argument - snapshot not allowed with -e")); |
5367 | 2482 |
return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf)); |
2483 |
} |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2484 |
|
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2485 |
chopprefix = strrchr(sendfs, '/'); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2486 |
|
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2487 |
if (chopprefix == NULL) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2488 |
/* |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2489 |
* 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
|
2490 |
* prepend a path separator. |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2491 |
*/ |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2492 |
int len = strlen(drrb->drr_toname); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2493 |
cp = malloc(len + 2); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2494 |
cp[0] = '/'; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2495 |
(void) strcpy(&cp[1], drrb->drr_toname); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2496 |
chopprefix = cp; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2497 |
} else { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2498 |
chopprefix = drrb->drr_toname + (chopprefix - sendfs); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2499 |
} |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2500 |
} else if (flags.isprefix) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2501 |
/* |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2502 |
* 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
|
2503 |
* 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
|
2504 |
* (all but the pool name). |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2505 |
*/ |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2506 |
if (strchr(tosnap, '@')) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2507 |
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
|
2508 |
"argument - snapshot not allowed with -d")); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2509 |
return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf)); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2510 |
} |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2511 |
|
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2512 |
chopprefix = strchr(drrb->drr_toname, '/'); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2513 |
if (chopprefix == NULL) |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2514 |
chopprefix = strchr(drrb->drr_toname, '@'); |
5367 | 2515 |
} else if (strchr(tosnap, '@') == NULL) { |
2516 |
/* |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2517 |
* 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
|
2518 |
* tack on everything after the fs specified by 'zfs send'. |
5367 | 2519 |
*/ |
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2520 |
chopprefix = drrb->drr_toname + strlen(sendfs); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2521 |
} else { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2522 |
/* 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
|
2523 |
if (recursive) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2524 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2525 |
"cannot specify snapshot name for multi-snapshot " |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2526 |
"stream")); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2527 |
return (zfs_error(hdl, EZFS_BADSTREAM, errbuf)); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2528 |
} |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2529 |
chopprefix = drrb->drr_toname + strlen(drrb->drr_toname); |
5367 | 2530 |
} |
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2531 |
|
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2532 |
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
|
2533 |
ASSERT(chopprefix > drrb->drr_toname); |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2534 |
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
|
2535 |
ASSERT(chopprefix[0] == '/' || chopprefix[0] == '@' || |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2536 |
chopprefix[0] == '\0'); |
5367 | 2537 |
|
2538 |
/* |
|
2539 |
* Determine name of destination snapshot, store in zc_value. |
|
2540 |
*/ |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2541 |
(void) strcpy(zc.zc_top_ds, tosnap); |
5367 | 2542 |
(void) strcpy(zc.zc_value, tosnap); |
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2543 |
(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
|
2544 |
free(cp); |
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2545 |
if (!zfs_name_valid(zc.zc_value, ZFS_TYPE_SNAPSHOT)) { |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2546 |
zcmd_free_nvlists(&zc); |
5367 | 2547 |
return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf)); |
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2548 |
} |
5367 | 2549 |
|
2550 |
/* |
|
2551 |
* Determine the name of the origin snapshot, store in zc_string. |
|
2552 |
*/ |
|
2553 |
if (drrb->drr_flags & DRR_FLAG_CLONE) { |
|
2554 |
if (guid_to_name(hdl, tosnap, |
|
2555 |
drrb->drr_fromguid, zc.zc_string) != 0) { |
|
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2556 |
zcmd_free_nvlists(&zc); |
5367 | 2557 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
2558 |
"local origin for clone %s does not exist"), |
|
2559 |
zc.zc_value); |
|
2560 |
return (zfs_error(hdl, EZFS_NOENT, errbuf)); |
|
2561 |
} |
|
2562 |
if (flags.verbose) |
|
2563 |
(void) printf("found clone origin %s\n", zc.zc_string); |
|
2564 |
} |
|
2565 |
||
2566 |
stream_wantsnewfs = (drrb->drr_fromguid == NULL || |
|
2567 |
(drrb->drr_flags & DRR_FLAG_CLONE)); |
|
2568 |
||
2569 |
if (stream_wantsnewfs) { |
|
2570 |
/* |
|
2571 |
* if the parent fs does not exist, look for it based on |
|
2572 |
* the parent snap GUID |
|
2573 |
*/ |
|
2574 |
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, |
|
2575 |
"cannot receive new filesystem stream")); |
|
2576 |
||
2577 |
(void) strcpy(zc.zc_name, zc.zc_value); |
|
2578 |
cp = strrchr(zc.zc_name, '/'); |
|
2579 |
if (cp) |
|
2580 |
*cp = '\0'; |
|
2581 |
if (cp && |
|
2582 |
!zfs_dataset_exists(hdl, zc.zc_name, ZFS_TYPE_DATASET)) { |
|
2583 |
char suffix[ZFS_MAXNAMELEN]; |
|
2584 |
(void) strcpy(suffix, strrchr(zc.zc_value, '/')); |
|
2585 |
if (guid_to_name(hdl, tosnap, parent_snapguid, |
|
2586 |
zc.zc_value) == 0) { |
|
2587 |
*strchr(zc.zc_value, '@') = '\0'; |
|
2588 |
(void) strcat(zc.zc_value, suffix); |
|
2589 |
} |
|
2590 |
} |
|
2591 |
} else { |
|
2592 |
/* |
|
2593 |
* if the fs does not exist, look for it based on the |
|
2594 |
* fromsnap GUID |
|
2595 |
*/ |
|
2596 |
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, |
|
2597 |
"cannot receive incremental stream")); |
|
2598 |
||
2599 |
(void) strcpy(zc.zc_name, zc.zc_value); |
|
2600 |
*strchr(zc.zc_name, '@') = '\0'; |
|
2601 |
||
11976
3791e5495b0d
6931963 zfs_receive_004_neg test regression results in no reported error for invalid incremental receive
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11935
diff
changeset
|
2602 |
/* |
3791e5495b0d
6931963 zfs_receive_004_neg test regression results in no reported error for invalid incremental receive
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11935
diff
changeset
|
2603 |
* If the exact receive path was specified and this is the |
3791e5495b0d
6931963 zfs_receive_004_neg test regression results in no reported error for invalid incremental receive
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11935
diff
changeset
|
2604 |
* topmost path in the stream, then if the fs does not exist we |
3791e5495b0d
6931963 zfs_receive_004_neg test regression results in no reported error for invalid incremental receive
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11935
diff
changeset
|
2605 |
* should look no further. |
3791e5495b0d
6931963 zfs_receive_004_neg test regression results in no reported error for invalid incremental receive
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11935
diff
changeset
|
2606 |
*/ |
3791e5495b0d
6931963 zfs_receive_004_neg test regression results in no reported error for invalid incremental receive
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11935
diff
changeset
|
2607 |
if ((flags.isprefix || (*(chopprefix = drrb->drr_toname + |
3791e5495b0d
6931963 zfs_receive_004_neg test regression results in no reported error for invalid incremental receive
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11935
diff
changeset
|
2608 |
strlen(sendfs)) != '\0' && *chopprefix != '@')) && |
3791e5495b0d
6931963 zfs_receive_004_neg test regression results in no reported error for invalid incremental receive
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11935
diff
changeset
|
2609 |
!zfs_dataset_exists(hdl, zc.zc_name, ZFS_TYPE_DATASET)) { |
5367 | 2610 |
char snap[ZFS_MAXNAMELEN]; |
2611 |
(void) strcpy(snap, strchr(zc.zc_value, '@')); |
|
2612 |
if (guid_to_name(hdl, tosnap, drrb->drr_fromguid, |
|
2613 |
zc.zc_value) == 0) { |
|
2614 |
*strchr(zc.zc_value, '@') = '\0'; |
|
2615 |
(void) strcat(zc.zc_value, snap); |
|
2616 |
} |
|
2617 |
} |
|
2618 |
} |
|
2619 |
||
2620 |
(void) strcpy(zc.zc_name, zc.zc_value); |
|
2621 |
*strchr(zc.zc_name, '@') = '\0'; |
|
2622 |
||
2623 |
if (zfs_dataset_exists(hdl, zc.zc_name, ZFS_TYPE_DATASET)) { |
|
2624 |
zfs_handle_t *zhp; |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2625 |
|
5367 | 2626 |
/* |
2627 |
* Destination fs exists. Therefore this should either |
|
2628 |
* be an incremental, or the stream specifies a new fs |
|
2629 |
* (full stream or clone) and they want us to blow it |
|
2630 |
* away (and have therefore specified -F and removed any |
|
2631 |
* snapshots). |
|
2632 |
*/ |
|
2633 |
if (stream_wantsnewfs) { |
|
2634 |
if (!flags.force) { |
|
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2635 |
zcmd_free_nvlists(&zc); |
5367 | 2636 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
2637 |
"destination '%s' exists\n" |
|
2638 |
"must specify -F to overwrite it"), |
|
2639 |
zc.zc_name); |
|
2640 |
return (zfs_error(hdl, EZFS_EXISTS, errbuf)); |
|
2641 |
} |
|
2642 |
if (ioctl(hdl->libzfs_fd, ZFS_IOC_SNAPSHOT_LIST_NEXT, |
|
2643 |
&zc) == 0) { |
|
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2644 |
zcmd_free_nvlists(&zc); |
5367 | 2645 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
2646 |
"destination has snapshots (eg. %s)\n" |
|
2647 |
"must destroy them to overwrite it"), |
|
2648 |
zc.zc_name); |
|
2649 |
return (zfs_error(hdl, EZFS_EXISTS, errbuf)); |
|
2650 |
} |
|
2651 |
} |
|
2652 |
||
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2653 |
if ((zhp = zfs_open(hdl, zc.zc_name, |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2654 |
ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME)) == NULL) { |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2655 |
zcmd_free_nvlists(&zc); |
5367 | 2656 |
return (-1); |
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2657 |
} |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2658 |
|
5367 | 2659 |
if (stream_wantsnewfs && |
2660 |
zhp->zfs_dmustats.dds_origin[0]) { |
|
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2661 |
zcmd_free_nvlists(&zc); |
5367 | 2662 |
zfs_close(zhp); |
2663 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
2664 |
"destination '%s' is a clone\n" |
|
2665 |
"must destroy it to overwrite it"), |
|
2666 |
zc.zc_name); |
|
2667 |
return (zfs_error(hdl, EZFS_EXISTS, errbuf)); |
|
2668 |
} |
|
2669 |
||
2670 |
if (!flags.dryrun && zhp->zfs_type == ZFS_TYPE_FILESYSTEM && |
|
2671 |
stream_wantsnewfs) { |
|
2672 |
/* 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
|
2673 |
clp = changelist_gather(zhp, ZFS_PROP_NAME, 0, 0); |
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2674 |
if (clp == NULL) { |
10200
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
2675 |
zfs_close(zhp); |
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2676 |
zcmd_free_nvlists(&zc); |
5367 | 2677 |
return (-1); |
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2678 |
} |
5367 | 2679 |
if (changelist_prefix(clp) != 0) { |
2680 |
changelist_free(clp); |
|
10200
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
2681 |
zfs_close(zhp); |
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2682 |
zcmd_free_nvlists(&zc); |
5367 | 2683 |
return (-1); |
2684 |
} |
|
2685 |
} |
|
2686 |
zfs_close(zhp); |
|
2687 |
} else { |
|
2688 |
/* |
|
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2689 |
* Destination filesystem does not exist. Therefore we better |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2690 |
* 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
|
2691 |
* a clone). It would therefore be invalid if the user |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2692 |
* 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
|
2693 |
* contained no slash character). |
5367 | 2694 |
*/ |
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2695 |
if (!stream_wantsnewfs || |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2696 |
(cp = strrchr(zc.zc_name, '/')) == NULL) { |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2697 |
zcmd_free_nvlists(&zc); |
5367 | 2698 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
2699 |
"destination '%s' does not exist"), zc.zc_name); |
|
2700 |
return (zfs_error(hdl, EZFS_NOENT, errbuf)); |
|
2701 |
} |
|
2702 |
||
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2703 |
/* |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2704 |
* Trim off the final dataset component so we perform the |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2705 |
* recvbackup ioctl to the filesystems's parent. |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2706 |
*/ |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2707 |
*cp = '\0'; |
5367 | 2708 |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2709 |
if (flags.isprefix && !flags.istail && !flags.dryrun && |
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2710 |
create_parents(hdl, zc.zc_value, strlen(tosnap)) != 0) { |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2711 |
zcmd_free_nvlists(&zc); |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2712 |
return (zfs_error(hdl, EZFS_BADRESTORE, errbuf)); |
5367 | 2713 |
} |
2714 |
||
2715 |
newfs = B_TRUE; |
|
2716 |
} |
|
2717 |
||
2718 |
zc.zc_begin_record = drr_noswap->drr_u.drr_begin; |
|
2719 |
zc.zc_cookie = infd; |
|
2720 |
zc.zc_guid = flags.force; |
|
2721 |
if (flags.verbose) { |
|
2722 |
(void) printf("%s %s stream of %s into %s\n", |
|
2723 |
flags.dryrun ? "would receive" : "receiving", |
|
2724 |
drrb->drr_fromguid ? "incremental" : "full", |
|
2725 |
drrb->drr_toname, zc.zc_value); |
|
2726 |
(void) fflush(stdout); |
|
2727 |
} |
|
2728 |
||
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2729 |
if (flags.dryrun) { |
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2730 |
zcmd_free_nvlists(&zc); |
5367 | 2731 |
return (recv_skip(hdl, infd, flags.byteswap)); |
5896
1e0712e8dd8b
6627877 zfs receive coredump with invalid destination name
ahl
parents:
5765
diff
changeset
|
2732 |
} |
5367 | 2733 |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2734 |
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
|
2735 |
zc.zc_nvlist_dst_size = sizeof (prop_errbuf); |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12296
diff
changeset
|
2736 |
zc.zc_cleanup_fd = cleanup_fd; |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12296
diff
changeset
|
2737 |
zc.zc_action_handle = *action_handlep; |
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2738 |
|
5367 | 2739 |
err = ioctl_err = zfs_ioctl(hdl, ZFS_IOC_RECV, &zc); |
2740 |
ioctl_errno = errno; |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2741 |
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
|
2742 |
|
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2743 |
if (err == 0) { |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2744 |
nvlist_t *prop_errors; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2745 |
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
|
2746 |
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
|
2747 |
|
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2748 |
nvpair_t *prop_err = NULL; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2749 |
|
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2750 |
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
|
2751 |
prop_err)) != NULL) { |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2752 |
char tbuf[1024]; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2753 |
zfs_prop_t prop; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2754 |
int intval; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2755 |
|
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2756 |
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
|
2757 |
(void) nvpair_value_int32(prop_err, &intval); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2758 |
if (strcmp(nvpair_name(prop_err), |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2759 |
ZPROP_N_MORE_ERRORS) == 0) { |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2760 |
trunc_prop_errs(intval); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2761 |
break; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2762 |
} else { |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2763 |
(void) snprintf(tbuf, sizeof (tbuf), |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2764 |
dgettext(TEXT_DOMAIN, |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2765 |
"cannot receive %s property on %s"), |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2766 |
nvpair_name(prop_err), zc.zc_name); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2767 |
zfs_setprop_error(hdl, prop, intval, tbuf); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2768 |
} |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2769 |
} |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2770 |
nvlist_free(prop_errors); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2771 |
} |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2772 |
|
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2773 |
zc.zc_nvlist_dst = 0; |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2774 |
zc.zc_nvlist_dst_size = 0; |
7265 | 2775 |
zcmd_free_nvlists(&zc); |
2776 |
||
2777 |
if (err == 0 && snapprops_nvlist) { |
|
2778 |
zfs_cmd_t zc2 = { 0 }; |
|
2779 |
||
7273
6baaca4d907c
6701797 want user properties on snapshots (fix lint)
ahrens
parents:
7265
diff
changeset
|
2780 |
(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
|
2781 |
zc2.zc_cookie = B_TRUE; /* received */ |
7265 | 2782 |
if (zcmd_write_src_nvlist(hdl, &zc2, snapprops_nvlist) == 0) { |
2783 |
(void) zfs_ioctl(hdl, ZFS_IOC_SET_PROP, &zc2); |
|
2784 |
zcmd_free_nvlists(&zc2); |
|
2785 |
} |
|
2786 |
} |
|
2787 |
||
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2788 |
if (err && (ioctl_errno == ENOENT || ioctl_errno == EEXIST)) { |
5367 | 2789 |
/* |
2790 |
* It may be that this snapshot already exists, |
|
2791 |
* in which case we want to consume & ignore it |
|
2792 |
* rather than failing. |
|
2793 |
*/ |
|
2794 |
avl_tree_t *local_avl; |
|
2795 |
nvlist_t *local_nv, *fs; |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
2796 |
cp = strchr(zc.zc_value, '@'); |
5367 | 2797 |
|
2798 |
/* |
|
2799 |
* XXX Do this faster by just iterating over snaps in |
|
2800 |
* this fs. Also if zc_value does not exist, we will |
|
2801 |
* get a strange "does not exist" error message. |
|
2802 |
*/ |
|
2803 |
*cp = '\0'; |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2804 |
if (gather_nvlist(hdl, zc.zc_value, NULL, NULL, B_FALSE, |
5367 | 2805 |
&local_nv, &local_avl) == 0) { |
2806 |
*cp = '@'; |
|
2807 |
fs = fsavl_find(local_avl, drrb->drr_toguid, NULL); |
|
2808 |
fsavl_destroy(local_avl); |
|
2809 |
nvlist_free(local_nv); |
|
2810 |
||
2811 |
if (fs != NULL) { |
|
2812 |
if (flags.verbose) { |
|
2813 |
(void) printf("snap %s already exists; " |
|
2814 |
"ignoring\n", zc.zc_value); |
|
2815 |
} |
|
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2816 |
err = ioctl_err = recv_skip(hdl, infd, |
5367 | 2817 |
flags.byteswap); |
2818 |
} |
|
2819 |
} |
|
2820 |
*cp = '@'; |
|
2821 |
} |
|
2822 |
||
2823 |
if (ioctl_err != 0) { |
|
2824 |
switch (ioctl_errno) { |
|
2825 |
case ENODEV: |
|
2826 |
cp = strchr(zc.zc_value, '@'); |
|
2827 |
*cp = '\0'; |
|
2828 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
2829 |
"most recent snapshot of %s does not\n" |
|
2830 |
"match incremental source"), zc.zc_value); |
|
2831 |
(void) zfs_error(hdl, EZFS_BADRESTORE, errbuf); |
|
2832 |
*cp = '@'; |
|
2833 |
break; |
|
2834 |
case ETXTBSY: |
|
2835 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
2836 |
"destination %s has been modified\n" |
|
2837 |
"since most recent snapshot"), zc.zc_name); |
|
2838 |
(void) zfs_error(hdl, EZFS_BADRESTORE, errbuf); |
|
2839 |
break; |
|
2840 |
case EEXIST: |
|
2841 |
cp = strchr(zc.zc_value, '@'); |
|
2842 |
if (newfs) { |
|
2843 |
/* it's the containing fs that exists */ |
|
2844 |
*cp = '\0'; |
|
2845 |
} |
|
2846 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
2847 |
"destination already exists")); |
|
2848 |
(void) zfs_error_fmt(hdl, EZFS_EXISTS, |
|
2849 |
dgettext(TEXT_DOMAIN, "cannot restore to %s"), |
|
2850 |
zc.zc_value); |
|
2851 |
*cp = '@'; |
|
2852 |
break; |
|
2853 |
case EINVAL: |
|
2854 |
(void) zfs_error(hdl, EZFS_BADSTREAM, errbuf); |
|
2855 |
break; |
|
2856 |
case ECKSUM: |
|
2857 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
|
2858 |
"invalid stream (checksum mismatch)")); |
|
2859 |
(void) zfs_error(hdl, EZFS_BADSTREAM, errbuf); |
|
2860 |
break; |
|
12070
01261b276236
6940770 panic in sa_find_idx_tab() after receiving into pool when version shouldn't have allowed it
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11976
diff
changeset
|
2861 |
case ENOTSUP: |
01261b276236
6940770 panic in sa_find_idx_tab() after receiving into pool when version shouldn't have allowed it
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11976
diff
changeset
|
2862 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
01261b276236
6940770 panic in sa_find_idx_tab() after receiving into pool when version shouldn't have allowed it
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11976
diff
changeset
|
2863 |
"pool must be upgraded to receive this stream.")); |
01261b276236
6940770 panic in sa_find_idx_tab() after receiving into pool when version shouldn't have allowed it
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11976
diff
changeset
|
2864 |
(void) zfs_error(hdl, EZFS_BADVERSION, errbuf); |
01261b276236
6940770 panic in sa_find_idx_tab() after receiving into pool when version shouldn't have allowed it
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents:
11976
diff
changeset
|
2865 |
break; |
12141
4a4721b90d68
6916981 zfs recv needs better messaging when quota exceeded
John Harres <John.Harres@Sun.COM>
parents:
12070
diff
changeset
|
2866 |
case EDQUOT: |
4a4721b90d68
6916981 zfs recv needs better messaging when quota exceeded
John Harres <John.Harres@Sun.COM>
parents:
12070
diff
changeset
|
2867 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
4a4721b90d68
6916981 zfs recv needs better messaging when quota exceeded
John Harres <John.Harres@Sun.COM>
parents:
12070
diff
changeset
|
2868 |
"destination %s space quota exceeded"), zc.zc_name); |
4a4721b90d68
6916981 zfs recv needs better messaging when quota exceeded
John Harres <John.Harres@Sun.COM>
parents:
12070
diff
changeset
|
2869 |
(void) zfs_error(hdl, EZFS_BADRESTORE, errbuf); |
4a4721b90d68
6916981 zfs recv needs better messaging when quota exceeded
John Harres <John.Harres@Sun.COM>
parents:
12070
diff
changeset
|
2870 |
break; |
5367 | 2871 |
default: |
2872 |
(void) zfs_standard_error(hdl, ioctl_errno, errbuf); |
|
2873 |
} |
|
2874 |
} |
|
2875 |
||
2876 |
/* |
|
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
|
2877 |
* 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
|
2878 |
* 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
|
2879 |
* receive (indicated by stream_avl being non-NULL). |
5367 | 2880 |
*/ |
2881 |
cp = strchr(zc.zc_value, '@'); |
|
2882 |
if (cp && (ioctl_err == 0 || !newfs)) { |
|
2883 |
zfs_handle_t *h; |
|
2884 |
||
2885 |
*cp = '\0'; |
|
2886 |
h = zfs_open(hdl, zc.zc_value, |
|
2887 |
ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME); |
|
6476 | 2888 |
if (h != NULL) { |
5367 | 2889 |
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
|
2890 |
*cp = '@'; |
10200
636e9ab433b8
6858551 zfs receive did not mount all filesystems
Lori Alt <Lori.Alt@Sun.COM>
parents:
10195
diff
changeset
|
2891 |
} 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
|
2892 |
/* |
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 |
* 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
|
2894 |
* 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
|
2895 |
*/ |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
2896 |
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
|
2897 |
*top_zfs = zfs_strdup(hdl, zc.zc_value); |
5367 | 2898 |
} |
6476 | 2899 |
zfs_close(h); |
5367 | 2900 |
} |
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
|
2901 |
*cp = '@'; |
5367 | 2902 |
} |
2903 |
||
2904 |
if (clp) { |
|
2905 |
err |= changelist_postfix(clp); |
|
2906 |
changelist_free(clp); |
|
2907 |
} |
|
2908 |
||
11022
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2909 |
if (prop_errflags & ZPROP_ERR_NOCLEAR) { |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2910 |
(void) fprintf(stderr, dgettext(TEXT_DOMAIN, "Warning: " |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2911 |
"failed to clear unreceived properties on %s"), |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2912 |
zc.zc_name); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2913 |
(void) fprintf(stderr, "\n"); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2914 |
} |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2915 |
if (prop_errflags & ZPROP_ERR_NORESTORE) { |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2916 |
(void) fprintf(stderr, dgettext(TEXT_DOMAIN, "Warning: " |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2917 |
"failed to restore original properties on %s"), |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2918 |
zc.zc_name); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2919 |
(void) fprintf(stderr, "\n"); |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2920 |
} |
63ab26072e41
PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11007
diff
changeset
|
2921 |
|
5367 | 2922 |
if (err || ioctl_err) |
2923 |
return (-1); |
|
2924 |
||
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12296
diff
changeset
|
2925 |
*action_handlep = zc.zc_action_handle; |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12296
diff
changeset
|
2926 |
|
5367 | 2927 |
if (flags.verbose) { |
2928 |
char buf1[64]; |
|
2929 |
char buf2[64]; |
|
2930 |
uint64_t bytes = zc.zc_cookie; |
|
2931 |
time_t delta = time(NULL) - begin_time; |
|
2932 |
if (delta == 0) |
|
2933 |
delta = 1; |
|
2934 |
zfs_nicenum(bytes, buf1, sizeof (buf1)); |
|
2935 |
zfs_nicenum(bytes/delta, buf2, sizeof (buf1)); |
|
2936 |
||
2937 |
(void) printf("received %sB stream in %lu seconds (%sB/sec)\n", |
|
2938 |
buf1, delta, buf2); |
|
2939 |
} |
|
2940 |
||
2941 |
return (0); |
|
2942 |
} |
|
2943 |
||
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
|
2944 |
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
|
2945 |
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
|
2946 |
int infd, const char *sendfs, nvlist_t *stream_nv, avl_tree_t *stream_avl, |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12296
diff
changeset
|
2947 |
char **top_zfs, int cleanup_fd, uint64_t *action_handlep) |
5367 | 2948 |
{ |
2949 |
int err; |
|
2950 |
dmu_replay_record_t drr, drr_noswap; |
|
2951 |
struct drr_begin *drrb = &drr.drr_u.drr_begin; |
|
2952 |
char errbuf[1024]; |
|
2953 |
zio_cksum_t zcksum = { 0 }; |
|
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2954 |
uint64_t featureflags; |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
2955 |
int hdrtype; |
5367 | 2956 |
|
2957 |
(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, |
|
2958 |
"cannot receive")); |
|
2959 |
||
2960 |
if (flags.isprefix && |
|
2961 |
!zfs_dataset_exists(hdl, tosnap, ZFS_TYPE_DATASET)) { |
|
2962 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "specified fs " |
|
2963 |
"(%s) does not exist"), tosnap); |
|
2964 |
return (zfs_error(hdl, EZFS_NOENT, errbuf)); |
|
2965 |
} |
|
2966 |
||
2967 |
/* read in the BEGIN record */ |
|
2968 |
if (0 != (err = recv_read(hdl, infd, &drr, sizeof (drr), B_FALSE, |
|
2969 |
&zcksum))) |
|
2970 |
return (err); |
|
2971 |
||
2972 |
if (drr.drr_type == DRR_END || drr.drr_type == BSWAP_32(DRR_END)) { |
|
2973 |
/* It's the double end record at the end of a package */ |
|
2974 |
return (ENODATA); |
|
2975 |
} |
|
2976 |
||
2977 |
/* the kernel needs the non-byteswapped begin record */ |
|
2978 |
drr_noswap = drr; |
|
2979 |
||
5446 | 2980 |
flags.byteswap = B_FALSE; |
5367 | 2981 |
if (drrb->drr_magic == BSWAP_64(DMU_BACKUP_MAGIC)) { |
2982 |
/* |
|
2983 |
* We computed the checksum in the wrong byteorder in |
|
2984 |
* recv_read() above; do it again correctly. |
|
2985 |
*/ |
|
2986 |
bzero(&zcksum, sizeof (zio_cksum_t)); |
|
2987 |
fletcher_4_incremental_byteswap(&drr, sizeof (drr), &zcksum); |
|
2988 |
flags.byteswap = B_TRUE; |
|
2989 |
||
2990 |
drr.drr_type = BSWAP_32(drr.drr_type); |
|
2991 |
drr.drr_payloadlen = BSWAP_32(drr.drr_payloadlen); |
|
2992 |
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
|
2993 |
drrb->drr_versioninfo = BSWAP_64(drrb->drr_versioninfo); |
5367 | 2994 |
drrb->drr_creation_time = BSWAP_64(drrb->drr_creation_time); |
2995 |
drrb->drr_type = BSWAP_32(drrb->drr_type); |
|
2996 |
drrb->drr_flags = BSWAP_32(drrb->drr_flags); |
|
2997 |
drrb->drr_toguid = BSWAP_64(drrb->drr_toguid); |
|
2998 |
drrb->drr_fromguid = BSWAP_64(drrb->drr_fromguid); |
|
2999 |
} |
|
3000 |
||
3001 |
if (drrb->drr_magic != DMU_BACKUP_MAGIC || drr.drr_type != DRR_BEGIN) { |
|
3002 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "invalid " |
|
3003 |
"stream (bad magic number)")); |
|
3004 |
return (zfs_error(hdl, EZFS_BADSTREAM, errbuf)); |
|
3005 |
} |
|
3006 |
||
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
3007 |
featureflags = DMU_GET_FEATUREFLAGS(drrb->drr_versioninfo); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
3008 |
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
|
3009 |
|
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
3010 |
if (!DMU_STREAM_SUPPORTED(featureflags) || |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
3011 |
(hdrtype != DMU_SUBSTREAM && hdrtype != DMU_COMPOUNDSTREAM)) { |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
3012 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
3013 |
"stream has unsupported feature, feature flags = %lx"), |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
3014 |
featureflags); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
3015 |
return (zfs_error(hdl, EZFS_BADSTREAM, errbuf)); |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
3016 |
} |
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
3017 |
|
5367 | 3018 |
if (strchr(drrb->drr_toname, '@') == NULL) { |
3019 |
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "invalid " |
|
3020 |
"stream (bad snapshot name)")); |
|
3021 |
return (zfs_error(hdl, EZFS_BADSTREAM, errbuf)); |
|
3022 |
} |
|
3023 |
||
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
3024 |
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
|
3025 |
char nonpackage_sendfs[ZFS_MAXNAMELEN]; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
3026 |
if (sendfs == NULL) { |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
3027 |
/* |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
3028 |
* 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
|
3029 |
* the fs specified by 'zfs send'. |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
3030 |
*/ |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
3031 |
char *cp; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
3032 |
(void) strlcpy(nonpackage_sendfs, |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
3033 |
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
|
3034 |
if ((cp = strchr(nonpackage_sendfs, '@')) != NULL) |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
3035 |
*cp = '\0'; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
3036 |
sendfs = nonpackage_sendfs; |
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
3037 |
} |
5367 | 3038 |
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
|
3039 |
&drr, &drr_noswap, sendfs, stream_nv, stream_avl, |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12296
diff
changeset
|
3040 |
top_zfs, cleanup_fd, action_handlep)); |
11976
3791e5495b0d
6931963 zfs_receive_004_neg test regression results in no reported error for invalid incremental receive
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11935
diff
changeset
|
3041 |
} else { |
11007
216d8396182e
PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents:
10960
diff
changeset
|
3042 |
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
|
3043 |
DMU_COMPOUNDSTREAM); |
5367 | 3044 |
return (zfs_receive_package(hdl, infd, tosnap, flags, |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12296
diff
changeset
|
3045 |
&drr, &zcksum, top_zfs, cleanup_fd, action_handlep)); |
5367 | 3046 |
} |
3047 |
} |
|
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
|
3048 |
|
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
3049 |
/* |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
3050 |
* 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
|
3051 |
* 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
|
3052 |
* 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
|
3053 |
* (-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
|
3054 |
*/ |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
3055 |
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
|
3056 |
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
|
3057 |
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
|
3058 |
{ |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
3059 |
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
|
3060 |
int err; |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12296
diff
changeset
|
3061 |
int cleanup_fd; |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12296
diff
changeset
|
3062 |
uint64_t action_handle = 0; |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12296
diff
changeset
|
3063 |
|
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12296
diff
changeset
|
3064 |
cleanup_fd = open(ZFS_DEV, O_RDWR|O_EXCL); |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12296
diff
changeset
|
3065 |
VERIFY(cleanup_fd >= 0); |
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
|
3066 |
|
11834
4a7103a82983
6921421 zfs receive: recursive restore fails
Tom Erickson <Tom.Erickson@Sun.COM>
parents:
11814
diff
changeset
|
3067 |
err = zfs_receive_impl(hdl, tosnap, flags, infd, NULL, NULL, |
12527
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12296
diff
changeset
|
3068 |
stream_avl, &top_zfs, cleanup_fd, &action_handle); |
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12296
diff
changeset
|
3069 |
|
693dd2cad55f
6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents:
12296
diff
changeset
|
3070 |
VERIFY(0 == close(cleanup_fd)); |
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
|
3071 |
|
8584
327a1b6dd944
6794452 zfs receive can't restore a root pool
Lori Alt <Lori.Alt@Sun.COM>
parents:
7366
diff
changeset
|
3072 |
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
|
3073 |
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
|
3074 |
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
|
3075 |
|
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
3076 |
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
|
3077 |
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
|
3078 |
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
|
3079 |
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
|
3080 |
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
|
3081 |
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
|
3082 |
/* 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
|
3083 |
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
|
3084 |
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
|
3085 |
} |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
3086 |
} |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
3087 |
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
|
3088 |
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
|
3089 |
} |
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
3090 |
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
|
3091 |
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
|
3092 |
|
33de5956afbb
6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents:
7273
diff
changeset
|
3093 |
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
|
3094 |
} |