[PATCH RFC] Fix panic on zap_count(os, object, &count) != 0
Xin Li
delphij at delphij.net
Tue Jan 8 21:08:50 UTC 2013
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Hi,
I'd like to port ZFS on Linux changeset
e8fd45a0f975c6b8ae8cd644714fc21f14fac2bf. We were able to create a
pool with damage at lab that panics the system when doing zpool import
- -F -X -f, and this change fixes that.
Any objections?
Cheers,
- --
Xin LI <delphij at delphij.net> https://www.delphij.net/
FreeBSD - The Power to Serve! Live free or die
-----BEGIN PGP SIGNATURE-----
iQEcBAEBCAAGBQJQ7IrfAAoJEG80Jeu8UPuzBR8H+wZUozdz35LsPiVfrTvHFwmo
HGKgS2T6bpQmmvOkuJhvFbvS0B2+ZElsgn+qamkCdZ5A3Er5VaAkt9VM0FDNGvOG
M49lYJzC/J9vn+B0QCZFwLw5cXEzcAXa+zE5j6v6SYv2sgESDKo04u745paRtC+P
zLK1mtUPWhQdn3PMYBOYF+2dvcFY5XkNgXaerJWJs2LQpjeV1hzQH0Wy/cJ3J0lY
dp/eUybTxqafw8uTfwIre/tNPowxYOmDWo+Ht1bflKFZ3NCSxpGZLYxs69Fl5pO8
OeFrcwpoHRXxY8oMrZ424FO3+l3MPjdDozNT3ciNilBs+KfMypPjKsMmb+w50zw=
=rfqC
-----END PGP SIGNATURE-----
-------------- next part --------------
Index: cddl/contrib/opensolaris/cmd/zdb/zdb.c
===================================================================
--- cddl/contrib/opensolaris/cmd/zdb/zdb.c (revision 245136)
+++ cddl/contrib/opensolaris/cmd/zdb/zdb.c (working copy)
@@ -704,7 +704,9 @@ dump_ddt(ddt_t *ddt, enum ddt_type type, enum ddt_
return;
ASSERT(error == 0);
- if ((count = ddt_object_count(ddt, type, class)) == 0)
+ error = ddt_object_count(ddt, type, class, &count);
+ ASSERT(error == 0);
+ if (count == 0)
return;
dspace = doi.doi_physical_blocks_512 << 9;
Index: sys/cddl/contrib/opensolaris/uts/common/fs/zfs/ddt.c
===================================================================
--- sys/cddl/contrib/opensolaris/uts/common/fs/zfs/ddt.c (revision 245136)
+++ sys/cddl/contrib/opensolaris/uts/common/fs/zfs/ddt.c (working copy)
@@ -89,12 +89,13 @@ ddt_object_destroy(ddt_t *ddt, enum ddt_type type,
spa_t *spa = ddt->ddt_spa;
objset_t *os = ddt->ddt_os;
uint64_t *objectp = &ddt->ddt_object[type][class];
+ uint64_t count;
char name[DDT_NAMELEN];
ddt_object_name(ddt, type, class, name);
ASSERT(*objectp != 0);
- ASSERT(ddt_object_count(ddt, type, class) == 0);
+ VERIFY(ddt_object_count(ddt, type, class, &count) == 0 && count == 0);
ASSERT(ddt_histogram_empty(&ddt->ddt_histogram[type][class]));
VERIFY(zap_remove(os, DMU_POOL_DIRECTORY_OBJECT, name, tx) == 0);
VERIFY(zap_remove(os, spa->spa_ddt_stat_object, name, tx) == 0);
@@ -109,6 +110,7 @@ ddt_object_load(ddt_t *ddt, enum ddt_type type, en
{
ddt_object_t *ddo = &ddt->ddt_object_stats[type][class];
dmu_object_info_t doi;
+ uint64_t count;
char name[DDT_NAMELEN];
int error;
@@ -129,7 +131,11 @@ ddt_object_load(ddt_t *ddt, enum ddt_type type, en
*/
VERIFY(ddt_object_info(ddt, type, class, &doi) == 0);
- ddo->ddo_count = ddt_object_count(ddt, type, class);
+ error = ddt_object_count(ddt, type, class, &count);
+ if (error)
+ return error;
+
+ ddo->ddo_count = count;
ddo->ddo_dspace = doi.doi_physical_blocks_512 << 9;
ddo->ddo_mspace = doi.doi_fill_count * doi.doi_data_block_size;
@@ -143,6 +149,7 @@ ddt_object_sync(ddt_t *ddt, enum ddt_type type, en
{
ddt_object_t *ddo = &ddt->ddt_object_stats[type][class];
dmu_object_info_t doi;
+ uint64_t count;
char name[DDT_NAMELEN];
ddt_object_name(ddt, type, class, name);
@@ -155,8 +162,9 @@ ddt_object_sync(ddt_t *ddt, enum ddt_type type, en
* Cache DDT statistics; this is the only time they'll change.
*/
VERIFY(ddt_object_info(ddt, type, class, &doi) == 0);
+ VERIFY(ddt_object_count(ddt, type, class, &count) == 0);
- ddo->ddo_count = ddt_object_count(ddt, type, class);
+ ddo->ddo_count = count;
ddo->ddo_dspace = doi.doi_physical_blocks_512 << 9;
ddo->ddo_mspace = doi.doi_fill_count * doi.doi_data_block_size;
}
@@ -213,13 +221,13 @@ ddt_object_walk(ddt_t *ddt, enum ddt_type type, en
ddt->ddt_object[type][class], dde, walk));
}
-uint64_t
-ddt_object_count(ddt_t *ddt, enum ddt_type type, enum ddt_class class)
+int
+ddt_object_count(ddt_t *ddt, enum ddt_type type, enum ddt_class class, uint64_t *count)
{
ASSERT(ddt_object_exists(ddt, type, class));
return (ddt_ops[type]->ddt_op_count(ddt->ddt_os,
- ddt->ddt_object[type][class]));
+ ddt->ddt_object[type][class], count));
}
int
@@ -1079,11 +1087,13 @@ ddt_sync_table(ddt_t *ddt, dmu_tx_t *tx, uint64_t
}
for (enum ddt_type type = 0; type < DDT_TYPES; type++) {
- uint64_t count = 0;
+ uint64_t add, count = 0;
for (enum ddt_class class = 0; class < DDT_CLASSES; class++) {
if (ddt_object_exists(ddt, type, class)) {
ddt_object_sync(ddt, type, class, tx);
- count += ddt_object_count(ddt, type, class);
+ VERIFY(ddt_object_count(ddt, type, class,
+ &add) == 0);
+ count += add;
}
}
for (enum ddt_class class = 0; class < DDT_CLASSES; class++) {
Index: sys/cddl/contrib/opensolaris/uts/common/fs/zfs/ddt_zap.c
===================================================================
--- sys/cddl/contrib/opensolaris/uts/common/fs/zfs/ddt_zap.c (revision 245136)
+++ sys/cddl/contrib/opensolaris/uts/common/fs/zfs/ddt_zap.c (working copy)
@@ -133,14 +133,11 @@ ddt_zap_walk(objset_t *os, uint64_t object, ddt_en
return (error);
}
-static uint64_t
-ddt_zap_count(objset_t *os, uint64_t object)
+static int
+ddt_zap_count(objset_t *os, uint64_t object, uint64_t *count)
{
- uint64_t count = 0;
- VERIFY(zap_count(os, object, &count) == 0);
-
- return (count);
+ return (zap_count(os, object, count));
}
const ddt_ops_t ddt_zap_ops = {
Index: sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/ddt.h
===================================================================
--- sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/ddt.h (revision 245136)
+++ sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/ddt.h (working copy)
@@ -163,7 +163,7 @@ typedef struct ddt_ops {
dmu_tx_t *tx);
int (*ddt_op_walk)(objset_t *os, uint64_t object, ddt_entry_t *dde,
uint64_t *walk);
- uint64_t (*ddt_op_count)(objset_t *os, uint64_t object);
+ int (*ddt_op_count)(objset_t *os, uint64_t object, uint64_t *count);
} ddt_ops_t;
#define DDT_NAMELEN 80
@@ -172,8 +172,8 @@ extern void ddt_object_name(ddt_t *ddt, enum ddt_t
enum ddt_class cls, char *name);
extern int ddt_object_walk(ddt_t *ddt, enum ddt_type type,
enum ddt_class cls, uint64_t *walk, ddt_entry_t *dde);
-extern uint64_t ddt_object_count(ddt_t *ddt, enum ddt_type type,
- enum ddt_class cls);
+extern int ddt_object_count(ddt_t *ddt, enum ddt_type type,
+ enum ddt_class class, uint64_t *count);
extern int ddt_object_info(ddt_t *ddt, enum ddt_type type,
enum ddt_class cls, dmu_object_info_t *);
extern boolean_t ddt_object_exists(ddt_t *ddt, enum ddt_type type,
More information about the zfs-devel
mailing list