| 1317 | } |
| 1318 | |
| 1319 | int |
| 1320 | zap_update(objset_t *os, uint64_t zapobj, const char *name, |
| 1321 | int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx) |
| 1322 | { |
| 1323 | zap_t *zap; |
| 1324 | const uint64_t *intval = val; |
| 1325 | |
| 1326 | int err = |
| 1327 | zap_lockdir(os, zapobj, tx, RW_WRITER, TRUE, TRUE, FTAG, &zap); |
| 1328 | if (err != 0) |
| 1329 | return (err); |
| 1330 | zap_name_t *zn = zap_name_alloc(zap, name, 0); |
| 1331 | if (zn == NULL) { |
| 1332 | zap_unlockdir(zap, FTAG); |
| 1333 | return (SET_ERROR(ENOTSUP)); |
| 1334 | } |
| 1335 | if (!zap->zap_ismicro) { |
| 1336 | err = fzap_update(zn, integer_size, num_integers, val, |
| 1337 | FTAG, tx); |
| 1338 | zap = zn->zn_zap; /* fzap_update() may change zap */ |
| 1339 | } else if (integer_size != 8 || num_integers != 1 || |
| 1340 | strlen(name) >= MZAP_NAME_LEN) { |
| 1341 | dprintf("upgrading obj %llu: intsz=%u numint=%llu name=%s\n", |
| 1342 | zapobj, integer_size, num_integers, name); |
| 1343 | err = mzap_upgrade(&zn->zn_zap, FTAG, tx, 0); |
| 1344 | if (err == 0) { |
| 1345 | err = fzap_update(zn, integer_size, num_integers, |
| 1346 | val, FTAG, tx); |
| 1347 | } |
| 1348 | zap = zn->zn_zap; /* fzap_update() may change zap */ |
| 1349 | } else { |
| 1350 | mzap_ent_t *mze = mze_find(zn); |
| 1351 | if (mze != NULL) { |
| 1352 | MZE_PHYS(zap, mze)->mze_value = *intval; |
| 1353 | } else { |
| 1354 | mzap_addent(zn, *intval); |
| 1355 | } |
| 1356 | } |
| 1357 | ASSERT(zap == zn->zn_zap); |
| 1358 | zap_name_free(zn); |
| 1359 | if (zap != NULL) /* may be NULL if fzap_upgrade() failed */ |
| 1360 | zap_unlockdir(zap, FTAG); |
| 1361 | return (err); |
| 1362 | } |
| 1363 | |
| 1364 | int |
| 1365 | zap_update_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key, |