Project

General

Profile

Bug #3693 ยป zfs_restore_object.patch

Andriy Gapon, 2013-04-04 02:45 PM

View differences:

usr/src/uts/common/fs/zfs/dmu_object.c Sun Mar 24 13:24:51 2013 -0800 โ†’ usr/src/uts/common/fs/zfs/dmu_object.c Thu Apr 04 11:39:20 2013 +0200
105 105

  
106 106
int
107 107
dmu_object_reclaim(objset_t *os, uint64_t object, dmu_object_type_t ot,
108
    int blocksize, dmu_object_type_t bonustype, int bonuslen)
108
    int blocksize, dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
109 109
{
110 110
	dnode_t *dn;
111
	dmu_tx_t *tx;
112 111
	int nblkptr;
113 112
	int err;
114 113

  
......
138 137
	 * be a new file instance.   We must clear out the previous file
139 138
	 * contents before we can change this type of metadata in the dnode.
140 139
	 */
141
	if (dn->dn_nblkptr > nblkptr || dn->dn_datablksz != blocksize) {
142
		err = dmu_free_long_range(os, object, 0, DMU_OBJECT_END);
143
		if (err)
144
			goto out;
145
	}
146

  
147
	tx = dmu_tx_create(os);
148
	dmu_tx_hold_bonus(tx, object);
149
	err = dmu_tx_assign(tx, TXG_WAIT);
150
	if (err) {
151
		dmu_tx_abort(tx);
152
		goto out;
153
	}
140
	if (dn->dn_nblkptr > nblkptr || dn->dn_datablksz != blocksize)
141
		dnode_free_range(dn, 0, DMU_OBJECT_END, tx);
154 142

  
155 143
	dnode_reallocate(dn, ot, blocksize, bonustype, bonuslen, tx);
156 144

  
157
	dmu_tx_commit(tx);
158
out:
159 145
	dnode_rele(dn, FTAG);
160 146

  
161 147
	return (err);
usr/src/uts/common/fs/zfs/dmu_send.c Sun Mar 24 13:24:51 2013 -0800 โ†’ usr/src/uts/common/fs/zfs/dmu_send.c Thu Apr 04 11:39:20 2013 +0200
1083 1083
static int
1084 1084
restore_object(struct restorearg *ra, objset_t *os, struct drr_object *drro)
1085 1085
{
1086
	int err;
1086
	int err, obj_err;
1087 1087
	dmu_tx_t *tx;
1088 1088
	void *data = NULL;
1089 1089

  
......
1099 1099
		return (SET_ERROR(EINVAL));
1100 1100
	}
1101 1101

  
1102
	err = dmu_object_info(os, drro->drr_object, NULL);
1102
	obj_err = dmu_object_info(os, drro->drr_object, NULL);
1103 1103

  
1104
	if (err != 0 && err != ENOENT)
1104
	if (obj_err != 0 && obj_err != ENOENT)
1105 1105
		return (SET_ERROR(EINVAL));
1106 1106

  
1107 1107
	if (drro->drr_bonuslen) {
......
1110 1110
			return (ra->err);
1111 1111
	}
1112 1112

  
1113
	if (err == ENOENT) {
1113
	tx = dmu_tx_create(os);
1114
	dmu_tx_hold_bonus(tx,
1115
	    obj_err == ENOENT ? DMU_NEW_OBJECT : drro->drr_object);
1116
	err = dmu_tx_assign(tx, TXG_WAIT);
1117
	if (err != 0) {
1118
		dmu_tx_abort(tx);
1119
		return (err);
1120
	}
1121

  
1122
	if (obj_err == ENOENT) {
1114 1123
		/* currently free, want to be allocated */
1115
		tx = dmu_tx_create(os);
1116
		dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
1117
		err = dmu_tx_assign(tx, TXG_WAIT);
1118
		if (err != 0) {
1119
			dmu_tx_abort(tx);
1120
			return (err);
1121
		}
1122 1124
		err = dmu_object_claim(os, drro->drr_object,
1123 1125
		    drro->drr_type, drro->drr_blksz,
1124 1126
		    drro->drr_bonustype, drro->drr_bonuslen, tx);
1125
		dmu_tx_commit(tx);
1126 1127
	} else {
1127 1128
		/* currently allocated, want to be allocated */
1128 1129
		err = dmu_object_reclaim(os, drro->drr_object,
1129 1130
		    drro->drr_type, drro->drr_blksz,
1130
		    drro->drr_bonustype, drro->drr_bonuslen);
1131
		    drro->drr_bonustype, drro->drr_bonuslen, tx);
1131 1132
	}
1132 1133
	if (err != 0) {
1134
		dmu_tx_commit(tx);
1133 1135
		return (SET_ERROR(EINVAL));
1134 1136
	}
1135 1137

  
1136
	tx = dmu_tx_create(os);
1137
	dmu_tx_hold_bonus(tx, drro->drr_object);
1138
	err = dmu_tx_assign(tx, TXG_WAIT);
1139
	if (err != 0) {
1140
		dmu_tx_abort(tx);
1141
		return (err);
1142
	}
1143

  
1144 1138
	dmu_object_set_checksum(os, drro->drr_object, drro->drr_checksumtype,
1145 1139
	    tx);
1146 1140
	dmu_object_set_compress(os, drro->drr_object, drro->drr_compress, tx);
usr/src/uts/common/fs/zfs/sys/dmu.h Sun Mar 24 13:24:51 2013 -0800 โ†’ usr/src/uts/common/fs/zfs/sys/dmu.h Thu Apr 04 11:39:20 2013 +0200
329 329
int dmu_object_claim(objset_t *os, uint64_t object, dmu_object_type_t ot,
330 330
    int blocksize, dmu_object_type_t bonus_type, int bonus_len, dmu_tx_t *tx);
331 331
int dmu_object_reclaim(objset_t *os, uint64_t object, dmu_object_type_t ot,
332
    int blocksize, dmu_object_type_t bonustype, int bonuslen);
332
    int blocksize, dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
333 333

  
334 334
/*
335 335
 * Free an object from this objset.
    (1-1/1)