278 off = idx & ((1<<(bs-3))-1);
279
280 err = dmu_buf_hold(zap->zap_objset, zap->zap_object,
281 (tbl->zt_blk + blk) << bs, FTAG, &db, DMU_READ_NO_PREFETCH);
282 if (err)
283 return (err);
284 *valp = ((uint64_t *)db->db_data)[off];
285 dmu_buf_rele(db, FTAG);
286
287 if (tbl->zt_nextblk != 0) {
288 /*
289 * read the nextblk for the sake of i/o error checking,
290 * so that zap_table_load() will catch errors for
291 * zap_table_store.
292 */
293 blk = (idx*2) >> (bs-3);
294
295 err = dmu_buf_hold(zap->zap_objset, zap->zap_object,
296 (tbl->zt_nextblk + blk) << bs, FTAG, &db,
297 DMU_READ_NO_PREFETCH);
298 dmu_buf_rele(db, FTAG);
299 }
300 return (err);
301 }
302
303 /*
304 * Routines for growing the ptrtbl.
305 */
306
307 static void
308 zap_ptrtbl_transfer(const uint64_t *src, uint64_t *dst, int n)
309 {
310 int i;
311 for (i = 0; i < n; i++) {
312 uint64_t lb = src[i];
313 dst[2*i+0] = lb;
314 dst[2*i+1] = lb;
315 }
316 }
317
975 for (zap_cursor_init(&zc, os, zapobj);
976 (err = zap_cursor_retrieve(&zc, za)) == 0;
977 zap_cursor_advance(&zc)) {
978 if ((za->za_first_integer & mask) == (value & mask)) {
979 (void) strcpy(name, za->za_name);
980 break;
981 }
982 }
983 zap_cursor_fini(&zc);
984 kmem_free(za, sizeof (zap_attribute_t));
985 return (err);
986 }
987
988 int
989 zap_join(objset_t *os, uint64_t fromobj, uint64_t intoobj, dmu_tx_t *tx)
990 {
991 zap_cursor_t zc;
992 zap_attribute_t za;
993 int err;
994
995 for (zap_cursor_init(&zc, os, fromobj);
996 zap_cursor_retrieve(&zc, &za) == 0;
997 (void) zap_cursor_advance(&zc)) {
998 if (za.za_integer_length != 8 || za.za_num_integers != 1)
999 return (SET_ERROR(EINVAL));
1000 err = zap_add(os, intoobj, za.za_name,
1001 8, 1, &za.za_first_integer, tx);
1002 if (err)
1003 return (err);
1004 }
1005 zap_cursor_fini(&zc);
1006 return (0);
1007 }
1008
1009 int
1010 zap_join_key(objset_t *os, uint64_t fromobj, uint64_t intoobj,
1011 uint64_t value, dmu_tx_t *tx)
1012 {
1013 zap_cursor_t zc;
1014 zap_attribute_t za;
1015 int err;
1016
1017 for (zap_cursor_init(&zc, os, fromobj);
1018 zap_cursor_retrieve(&zc, &za) == 0;
1019 (void) zap_cursor_advance(&zc)) {
1020 if (za.za_integer_length != 8 || za.za_num_integers != 1)
1021 return (SET_ERROR(EINVAL));
1022 err = zap_add(os, intoobj, za.za_name,
1023 8, 1, &value, tx);
1024 if (err)
1025 return (err);
1026 }
1027 zap_cursor_fini(&zc);
1028 return (0);
1029 }
1030
1031 int
1032 zap_join_increment(objset_t *os, uint64_t fromobj, uint64_t intoobj,
1033 dmu_tx_t *tx)
1034 {
1035 zap_cursor_t zc;
1036 zap_attribute_t za;
1037 int err;
1038
1039 for (zap_cursor_init(&zc, os, fromobj);
1040 zap_cursor_retrieve(&zc, &za) == 0;
1041 (void) zap_cursor_advance(&zc)) {
1042 uint64_t delta = 0;
1043
1044 if (za.za_integer_length != 8 || za.za_num_integers != 1)
1045 return (SET_ERROR(EINVAL));
1046
1047 err = zap_lookup(os, intoobj, za.za_name, 8, 1, &delta);
1048 if (err != 0 && err != ENOENT)
1049 return (err);
1050 delta += za.za_first_integer;
1051 err = zap_update(os, intoobj, za.za_name, 8, 1, &delta, tx);
1052 if (err)
1053 return (err);
1054 }
1055 zap_cursor_fini(&zc);
1056 return (0);
1057 }
1058
1059 int
1060 zap_add_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx)
1061 {
1062 char name[20];
1063
1064 (void) snprintf(name, sizeof (name), "%llx", (longlong_t)value);
1065 return (zap_add(os, obj, name, 8, 1, &value, tx));
1066 }
1067
1068 int
1069 zap_remove_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx)
1070 {
1071 char name[20];
1072
1073 (void) snprintf(name, sizeof (name), "%llx", (longlong_t)value);
1074 return (zap_remove(os, obj, name, tx));
1075 }
1076
|
278 off = idx & ((1<<(bs-3))-1);
279
280 err = dmu_buf_hold(zap->zap_objset, zap->zap_object,
281 (tbl->zt_blk + blk) << bs, FTAG, &db, DMU_READ_NO_PREFETCH);
282 if (err)
283 return (err);
284 *valp = ((uint64_t *)db->db_data)[off];
285 dmu_buf_rele(db, FTAG);
286
287 if (tbl->zt_nextblk != 0) {
288 /*
289 * read the nextblk for the sake of i/o error checking,
290 * so that zap_table_load() will catch errors for
291 * zap_table_store.
292 */
293 blk = (idx*2) >> (bs-3);
294
295 err = dmu_buf_hold(zap->zap_objset, zap->zap_object,
296 (tbl->zt_nextblk + blk) << bs, FTAG, &db,
297 DMU_READ_NO_PREFETCH);
298 if (err == 0)
299 dmu_buf_rele(db, FTAG);
300 }
301 return (err);
302 }
303
304 /*
305 * Routines for growing the ptrtbl.
306 */
307
308 static void
309 zap_ptrtbl_transfer(const uint64_t *src, uint64_t *dst, int n)
310 {
311 int i;
312 for (i = 0; i < n; i++) {
313 uint64_t lb = src[i];
314 dst[2*i+0] = lb;
315 dst[2*i+1] = lb;
316 }
317 }
318
976 for (zap_cursor_init(&zc, os, zapobj);
977 (err = zap_cursor_retrieve(&zc, za)) == 0;
978 zap_cursor_advance(&zc)) {
979 if ((za->za_first_integer & mask) == (value & mask)) {
980 (void) strcpy(name, za->za_name);
981 break;
982 }
983 }
984 zap_cursor_fini(&zc);
985 kmem_free(za, sizeof (zap_attribute_t));
986 return (err);
987 }
988
989 int
990 zap_join(objset_t *os, uint64_t fromobj, uint64_t intoobj, dmu_tx_t *tx)
991 {
992 zap_cursor_t zc;
993 zap_attribute_t za;
994 int err;
995
996 err = 0;
997 for (zap_cursor_init(&zc, os, fromobj);
998 zap_cursor_retrieve(&zc, &za) == 0;
999 (void) zap_cursor_advance(&zc)) {
1000 if (za.za_integer_length != 8 || za.za_num_integers != 1) {
1001 err = SET_ERROR(EINVAL);
1002 break;
1003 }
1004 err = zap_add(os, intoobj, za.za_name,
1005 8, 1, &za.za_first_integer, tx);
1006 if (err)
1007 break;
1008 }
1009 zap_cursor_fini(&zc);
1010 return (err);
1011 }
1012
1013 int
1014 zap_join_key(objset_t *os, uint64_t fromobj, uint64_t intoobj,
1015 uint64_t value, dmu_tx_t *tx)
1016 {
1017 zap_cursor_t zc;
1018 zap_attribute_t za;
1019 int err;
1020
1021 err = 0;
1022 for (zap_cursor_init(&zc, os, fromobj);
1023 zap_cursor_retrieve(&zc, &za) == 0;
1024 (void) zap_cursor_advance(&zc)) {
1025 if (za.za_integer_length != 8 || za.za_num_integers != 1) {
1026 err = SET_ERROR(EINVAL);
1027 break;
1028 }
1029 err = zap_add(os, intoobj, za.za_name,
1030 8, 1, &value, tx);
1031 if (err)
1032 break;
1033 }
1034 zap_cursor_fini(&zc);
1035 return (err);
1036 }
1037
1038 int
1039 zap_join_increment(objset_t *os, uint64_t fromobj, uint64_t intoobj,
1040 dmu_tx_t *tx)
1041 {
1042 zap_cursor_t zc;
1043 zap_attribute_t za;
1044 int err;
1045
1046 err = 0;
1047 for (zap_cursor_init(&zc, os, fromobj);
1048 zap_cursor_retrieve(&zc, &za) == 0;
1049 (void) zap_cursor_advance(&zc)) {
1050 uint64_t delta = 0;
1051
1052 if (za.za_integer_length != 8 || za.za_num_integers != 1) {
1053 err = SET_ERROR(EINVAL);
1054 break;
1055 }
1056
1057 err = zap_lookup(os, intoobj, za.za_name, 8, 1, &delta);
1058 if (err != 0 && err != ENOENT)
1059 break;
1060 delta += za.za_first_integer;
1061 err = zap_update(os, intoobj, za.za_name, 8, 1, &delta, tx);
1062 if (err)
1063 break;
1064 }
1065 zap_cursor_fini(&zc);
1066 return (err);
1067 }
1068
1069 int
1070 zap_add_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx)
1071 {
1072 char name[20];
1073
1074 (void) snprintf(name, sizeof (name), "%llx", (longlong_t)value);
1075 return (zap_add(os, obj, name, 8, 1, &value, tx));
1076 }
1077
1078 int
1079 zap_remove_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx)
1080 {
1081 char name[20];
1082
1083 (void) snprintf(name, sizeof (name), "%llx", (longlong_t)value);
1084 return (zap_remove(os, obj, name, tx));
1085 }
1086
|