forked from HDFGroup/hdf5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathH5Adense.c
1835 lines (1554 loc) · 78.9 KB
/
H5Adense.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the LICENSE file, which can be found at the root of the source code *
* distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* [email protected]. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*-------------------------------------------------------------------------
*
* Created: H5Adense.c
*
* Purpose: Routines for operating on "dense" attribute storage
* for an object.
*
*-------------------------------------------------------------------------
*/
/****************/
/* Module Setup */
/****************/
#include "H5Amodule.h" /* This source code file is part of the H5A module */
#define H5O_FRIEND /*suppress error about including H5Opkg */
/***********/
/* Headers */
/***********/
#include "H5private.h" /* Generic Functions */
#include "H5Apkg.h" /* Attributes */
#include "H5Eprivate.h" /* Error handling */
#include "H5FLprivate.h" /* Free Lists */
#include "H5MMprivate.h" /* Memory management */
#include "H5Opkg.h" /* Object headers */
#include "H5SMprivate.h" /* Shared object header messages */
#include "H5WBprivate.h" /* Wrapped Buffers */
/****************/
/* Local Macros */
/****************/
/* v2 B-tree creation macros for 'name' field index */
#define H5A_NAME_BT2_NODE_SIZE 512
#define H5A_NAME_BT2_MERGE_PERC 40
#define H5A_NAME_BT2_SPLIT_PERC 100
/* v2 B-tree creation macros for 'corder' field index */
#define H5A_CORDER_BT2_NODE_SIZE 512
#define H5A_CORDER_BT2_MERGE_PERC 40
#define H5A_CORDER_BT2_SPLIT_PERC 100
/* Size of stack buffer for serialized attributes */
#define H5A_ATTR_BUF_SIZE 128
/******************/
/* Local Typedefs */
/******************/
/*
* Data exchange structure for dense attribute storage. This structure is
* passed through the v2 B-tree layer when modifying the attribute data value.
*/
typedef struct H5A_bt2_od_wrt_t {
/* downward */
H5F_t *f; /* Pointer to file that fractal heap is in */
H5HF_t *fheap; /* Fractal heap handle to operate on */
H5HF_t *shared_fheap; /* Fractal heap handle for shared messages */
H5A_t *attr; /* Attribute to write */
haddr_t corder_bt2_addr; /* v2 B-tree address of creation order index */
} H5A_bt2_od_wrt_t;
/*
* Data exchange structure to pass through the v2 B-tree layer for the
* H5B2_iterate function when iterating over densely stored attributes.
*/
typedef struct {
/* downward (internal) */
H5F_t *f; /* Pointer to file that fractal heap is in */
H5HF_t *fheap; /* Fractal heap handle */
H5HF_t *shared_fheap; /* Fractal heap handle for shared messages */
hsize_t count; /* # of attributes examined */
/* downward (from application) */
hid_t loc_id; /* Object ID for application callback */
hsize_t skip; /* Number of attributes to skip */
const H5A_attr_iter_op_t *attr_op; /* Callback for each attribute */
void *op_data; /* Callback data for each attribute */
/* upward */
int op_ret; /* Return value from callback */
} H5A_bt2_ud_it_t;
/*
* Data exchange structure to pass through the fractal heap layer for the
* H5HF_op function when copying an attribute stored in densely stored attributes.
* (or the shared message heap)
*/
typedef struct {
/* downward (internal) */
H5F_t *f; /* Pointer to file that fractal heap is in */
const H5A_dense_bt2_name_rec_t *record; /* v2 B-tree record for attribute */
/* upward */
H5A_t *attr; /* Copy of attribute */
} H5A_fh_ud_cp_t;
/*
* Data exchange structure for dense attribute storage. This structure is
* passed through the v2 B-tree layer when removing attributes.
*/
typedef struct H5A_bt2_ud_rm_t {
/* downward */
H5A_bt2_ud_common_t common; /* Common info for B-tree user data (must be first) */
haddr_t corder_bt2_addr; /* v2 B-tree address of creation order index */
} H5A_bt2_ud_rm_t;
/*
* Data exchange structure for dense attribute storage. This structure is
* passed through the v2 B-tree layer when removing attributes by index.
*/
typedef struct H5A_bt2_ud_rmbi_t {
/* downward */
H5F_t *f; /* Pointer to file that fractal heap is in */
H5HF_t *fheap; /* Fractal heap handle */
H5HF_t *shared_fheap; /* Fractal heap handle for shared messages */
H5_index_t idx_type; /* Index type for operation */
haddr_t other_bt2_addr; /* v2 B-tree address of "other" index */
} H5A_bt2_ud_rmbi_t;
/********************/
/* Package Typedefs */
/********************/
/********************/
/* Local Prototypes */
/********************/
/*********************/
/* Package Variables */
/*********************/
/*****************************/
/* Library Private Variables */
/*****************************/
/*******************/
/* Local Variables */
/*******************/
/*-------------------------------------------------------------------------
* Function: H5A__dense_create
*
* Purpose: Creates dense attribute storage structures for an object
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
herr_t
H5A__dense_create(H5F_t *f, H5O_ainfo_t *ainfo)
{
H5HF_create_t fheap_cparam; /* Fractal heap creation parameters */
H5B2_create_t bt2_cparam; /* v2 B-tree creation parameters */
H5HF_t *fheap = NULL; /* Fractal heap handle */
H5B2_t *bt2_name = NULL; /* v2 B-tree handle for names */
H5B2_t *bt2_corder = NULL; /* v2 B-tree handle for creation order */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Check arguments */
assert(f);
assert(ainfo);
/* Set fractal heap creation parameters */
/* XXX: Give some control of these to applications? */
memset(&fheap_cparam, 0, sizeof(fheap_cparam));
fheap_cparam.managed.width = H5O_FHEAP_MAN_WIDTH;
fheap_cparam.managed.start_block_size = H5O_FHEAP_MAN_START_BLOCK_SIZE;
fheap_cparam.managed.max_direct_size = H5O_FHEAP_MAN_MAX_DIRECT_SIZE;
fheap_cparam.managed.max_index = H5O_FHEAP_MAN_MAX_INDEX;
fheap_cparam.managed.start_root_rows = H5O_FHEAP_MAN_START_ROOT_ROWS;
fheap_cparam.checksum_dblocks = H5O_FHEAP_CHECKSUM_DBLOCKS;
fheap_cparam.max_man_size = H5O_FHEAP_MAX_MAN_SIZE;
/* Create fractal heap for storing attributes */
if (NULL == (fheap = H5HF_create(f, &fheap_cparam)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "unable to create fractal heap");
/* Retrieve the heap's address in the file */
if (H5HF_get_heap_addr(fheap, &ainfo->fheap_addr) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTGETSIZE, FAIL, "can't get fractal heap address");
#ifndef NDEBUG
{
size_t fheap_id_len; /* Fractal heap ID length */
/* Retrieve the heap's ID length in the file */
if (H5HF_get_id_len(fheap, &fheap_id_len) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTGETSIZE, FAIL, "can't get fractal heap ID length");
assert(fheap_id_len == H5O_FHEAP_ID_LEN);
}
#endif /* NDEBUG */
/* Create the name index v2 B-tree */
memset(&bt2_cparam, 0, sizeof(bt2_cparam));
bt2_cparam.cls = H5A_BT2_NAME;
bt2_cparam.node_size = (size_t)H5A_NAME_BT2_NODE_SIZE;
bt2_cparam.rrec_size = 4 + /* Name's hash value */
4 + /* Creation order index */
1 + /* Message flags */
H5O_FHEAP_ID_LEN; /* Fractal heap ID */
bt2_cparam.split_percent = H5A_NAME_BT2_SPLIT_PERC;
bt2_cparam.merge_percent = H5A_NAME_BT2_MERGE_PERC;
if (NULL == (bt2_name = H5B2_create(f, &bt2_cparam, NULL)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "unable to create v2 B-tree for name index");
/* Retrieve the v2 B-tree's address in the file */
if (H5B2_get_addr(bt2_name, &ainfo->name_bt2_addr) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't get v2 B-tree address for name index");
/* Check if we should create a creation order index v2 B-tree */
if (ainfo->index_corder) {
/* Create the creation order index v2 B-tree */
memset(&bt2_cparam, 0, sizeof(bt2_cparam));
bt2_cparam.cls = H5A_BT2_CORDER;
bt2_cparam.node_size = (size_t)H5A_CORDER_BT2_NODE_SIZE;
bt2_cparam.rrec_size = 4 + /* Creation order index */
1 + /* Message flags */
H5O_FHEAP_ID_LEN; /* Fractal heap ID */
bt2_cparam.split_percent = H5A_CORDER_BT2_SPLIT_PERC;
bt2_cparam.merge_percent = H5A_CORDER_BT2_MERGE_PERC;
if (NULL == (bt2_corder = H5B2_create(f, &bt2_cparam, NULL)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "unable to create v2 B-tree for creation order index");
/* Retrieve the v2 B-tree's address in the file */
if (H5B2_get_addr(bt2_corder, &ainfo->corder_bt2_addr) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't get v2 B-tree address for creation order index");
} /* end if */
done:
/* Release resources */
if (fheap && H5HF_close(fheap) < 0)
HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, FAIL, "can't close fractal heap");
if (bt2_name && H5B2_close(bt2_name) < 0)
HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, FAIL, "can't close v2 B-tree for name index");
if (bt2_corder && H5B2_close(bt2_corder) < 0)
HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, FAIL, "can't close v2 B-tree for creation order index");
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5A__dense_create() */
/*-------------------------------------------------------------------------
* Function: H5A__dense_fnd_cb
*
* Purpose: Callback when an attribute is located in an index
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
static herr_t
H5A__dense_fnd_cb(const H5A_t *attr, bool *took_ownership, void *_user_attr)
{
const H5A_t **user_attr = (const H5A_t **)_user_attr; /* User data from v2 B-tree attribute lookup */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Check arguments */
assert(attr);
assert(user_attr);
assert(took_ownership);
/*
* If there is an attribute already stored in "user_attr",
* we need to free the dynamially allocated spaces for the
* attribute, otherwise we got infinite loop closing library due to
* outstanding allocation. (HDFFV-10659)
*
* This callback is used by H5A__dense_remove() to close/free the
* attribute stored in "user_attr" (via H5O__msg_free_real()) after
* the attribute node is deleted from the name index v2 B-tree.
* The issue is:
* When deleting the attribute node from the B-tree,
* if the attribute is found in the intermediate B-tree nodes,
* which may be merged/redistributed, we need to free the dynamically
* allocated spaces for the intermediate decoded attribute.
*/
if (*user_attr != NULL) {
H5A_t *old_attr = *(H5A_t **)_user_attr;
/* Free any dynamically allocated items */
if (old_attr->shared)
if (H5A__shared_free(old_attr) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTRELEASE, FAIL, "can't release attribute info");
old_attr = H5FL_FREE(H5A_t, old_attr);
} /* end if */
/* Take over attribute ownership */
*user_attr = attr;
*took_ownership = true;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5A__dense_fnd_cb() */
/*-------------------------------------------------------------------------
* Function: H5A__dense_open
*
* Purpose: Open an attribute in dense storage structures for an object
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
H5A_t *
H5A__dense_open(H5F_t *f, const H5O_ainfo_t *ainfo, const char *name)
{
H5A_bt2_ud_common_t udata; /* User data for v2 B-tree modify */
H5HF_t *fheap = NULL; /* Fractal heap handle */
H5HF_t *shared_fheap = NULL; /* Fractal heap handle for shared header messages */
H5B2_t *bt2_name = NULL; /* v2 B-tree handle for name index */
htri_t attr_sharable; /* Flag indicating attributes are shareable */
bool attr_exists; /* Attribute exists in v2 B-tree */
H5A_t *ret_value = NULL; /* Return value */
FUNC_ENTER_PACKAGE
/* Check arguments */
assert(f);
assert(ainfo);
assert(name);
/* Open the fractal heap */
if (NULL == (fheap = H5HF_open(f, ainfo->fheap_addr)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, NULL, "unable to open fractal heap");
/* Check if attributes are shared in this file */
if ((attr_sharable = H5SM_type_shared(f, H5O_ATTR_ID)) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, NULL, "can't determine if attributes are shared");
/* Get handle for shared message heap, if attributes are shareable */
if (attr_sharable) {
haddr_t shared_fheap_addr; /* Address of fractal heap to use */
/* Retrieve the address of the shared message's fractal heap */
if (H5SM_get_fheap_addr(f, H5O_ATTR_ID, &shared_fheap_addr) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, NULL, "can't get shared message heap address");
/* Check if there are any shared messages currently */
if (H5_addr_defined(shared_fheap_addr)) {
/* Open the fractal heap for shared header messages */
if (NULL == (shared_fheap = H5HF_open(f, shared_fheap_addr)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, NULL, "unable to open fractal heap");
} /* end if */
} /* end if */
/* Open the name index v2 B-tree */
if (NULL == (bt2_name = H5B2_open(f, ainfo->name_bt2_addr, NULL)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, NULL, "unable to open v2 B-tree for name index");
/* Create the "udata" information for v2 B-tree record find */
udata.f = f;
udata.fheap = fheap;
udata.shared_fheap = shared_fheap;
udata.name = name;
udata.name_hash = H5_checksum_lookup3(name, strlen(name), 0);
udata.flags = 0;
udata.corder = 0;
udata.found_op = H5A__dense_fnd_cb; /* v2 B-tree comparison callback */
udata.found_op_data = &ret_value;
/* Find & copy the attribute in the 'name' index */
attr_exists = false;
if (H5B2_find(bt2_name, &udata, &attr_exists, NULL, NULL) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_NOTFOUND, NULL, "can't search for attribute in name index");
if (attr_exists == false)
HGOTO_ERROR(H5E_ATTR, H5E_NOTFOUND, NULL, "can't locate attribute in name index");
done:
/* Release resources */
if (shared_fheap && H5HF_close(shared_fheap) < 0)
HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, NULL, "can't close fractal heap");
if (fheap && H5HF_close(fheap) < 0)
HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, NULL, "can't close fractal heap");
if (bt2_name && H5B2_close(bt2_name) < 0)
HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, NULL, "can't close v2 B-tree for name index");
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5A__dense_open() */
/*-------------------------------------------------------------------------
* Function: H5A__dense_insert
*
* Purpose: Insert an attribute into dense storage structures for an object
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
herr_t
H5A__dense_insert(H5F_t *f, const H5O_ainfo_t *ainfo, H5A_t *attr)
{
H5A_bt2_ud_ins_t udata; /* User data for v2 B-tree insertion */
H5HF_t *fheap = NULL; /* Fractal heap handle for attributes */
H5HF_t *shared_fheap = NULL; /* Fractal heap handle for shared header messages */
H5B2_t *bt2_name = NULL; /* v2 B-tree handle for name index */
H5B2_t *bt2_corder = NULL; /* v2 B-tree handle for creation order index */
H5WB_t *wb = NULL; /* Wrapped buffer for attribute data */
uint8_t attr_buf[H5A_ATTR_BUF_SIZE]; /* Buffer for serializing message */
unsigned mesg_flags = 0; /* Flags for storing message */
htri_t attr_sharable; /* Flag indicating attributes are shareable */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Check arguments */
assert(f);
assert(ainfo);
assert(attr);
/* Check if attributes are shared in this file */
if ((attr_sharable = H5SM_type_shared(f, H5O_ATTR_ID)) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't determine if attributes are shared");
/* Get handle for shared message heap, if attributes are shareable */
if (attr_sharable) {
haddr_t shared_fheap_addr; /* Address of fractal heap to use */
htri_t shared_mesg; /* Should this message be stored in the Shared Message table? */
/* Check if message is already shared */
if ((shared_mesg = H5O_msg_is_shared(H5O_ATTR_ID, attr)) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "error determining if message is shared");
else if (shared_mesg > 0)
/* Mark the message as shared */
mesg_flags |= H5O_MSG_FLAG_SHARED;
else {
/* Should this attribute be written as a SOHM? */
if (H5SM_try_share(f, NULL, 0, H5O_ATTR_ID, attr, &mesg_flags) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_WRITEERROR, FAIL, "error determining if message should be shared");
/* Attributes can't be "unique be shareable" yet */
assert(!(mesg_flags & H5O_MSG_FLAG_SHAREABLE));
} /* end else */
/* Retrieve the address of the shared message's fractal heap */
if (H5SM_get_fheap_addr(f, H5O_ATTR_ID, &shared_fheap_addr) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't get shared message heap address");
/* Check if there are any shared messages currently */
if (H5_addr_defined(shared_fheap_addr)) {
/* Open the fractal heap for shared header messages */
if (NULL == (shared_fheap = H5HF_open(f, shared_fheap_addr)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to open fractal heap");
} /* end if */
} /* end if */
/* Open the fractal heap */
if (NULL == (fheap = H5HF_open(f, ainfo->fheap_addr)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to open fractal heap");
/* Check for inserting shared attribute */
if (mesg_flags & H5O_MSG_FLAG_SHARED) {
/* Sanity check */
assert(attr_sharable);
/* Use heap ID for shared message heap */
udata.id = attr->sh_loc.u.heap_id;
} /* end if */
else {
void *attr_ptr; /* Pointer to serialized message */
size_t attr_size; /* Size of serialized attribute in the heap */
/* Find out the size of buffer needed for serialized message */
if ((attr_size = H5O_msg_raw_size(f, H5O_ATTR_ID, false, attr)) == 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTGETSIZE, FAIL, "can't get message size");
/* Wrap the local buffer for serialized attributes */
if (NULL == (wb = H5WB_wrap(attr_buf, sizeof(attr_buf))))
HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "can't wrap buffer");
/* Get a pointer to a buffer that's large enough for attribute */
if (NULL == (attr_ptr = H5WB_actual(wb, attr_size)))
HGOTO_ERROR(H5E_ATTR, H5E_NOSPACE, FAIL, "can't get actual buffer");
/* Create serialized form of attribute or shared message */
if (H5O_msg_encode(f, H5O_ATTR_ID, false, (unsigned char *)attr_ptr, attr) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTENCODE, FAIL, "can't encode attribute");
/* Insert the serialized attribute into the fractal heap */
/* (sets the heap ID in the user data) */
if (H5HF_insert(fheap, attr_size, attr_ptr, &udata.id) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTINSERT, FAIL, "unable to insert attribute into fractal heap");
} /* end else */
/* Open the name index v2 B-tree */
if (NULL == (bt2_name = H5B2_open(f, ainfo->name_bt2_addr, NULL)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to open v2 B-tree for name index");
/* Create the callback information for v2 B-tree record insertion */
udata.common.f = f;
udata.common.fheap = fheap;
udata.common.shared_fheap = shared_fheap;
udata.common.name = attr->shared->name;
udata.common.name_hash = H5_checksum_lookup3(attr->shared->name, strlen(attr->shared->name), 0);
H5_CHECKED_ASSIGN(udata.common.flags, uint8_t, mesg_flags, unsigned);
udata.common.corder = attr->shared->crt_idx;
udata.common.found_op = NULL;
udata.common.found_op_data = NULL;
/* udata.id already set */
/* Insert attribute into 'name' tracking v2 B-tree */
if (H5B2_insert(bt2_name, &udata) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTINSERT, FAIL, "unable to insert record into v2 B-tree");
/* Check if we should create a creation order index v2 B-tree record */
if (ainfo->index_corder) {
/* Open the creation order index v2 B-tree */
assert(H5_addr_defined(ainfo->corder_bt2_addr));
if (NULL == (bt2_corder = H5B2_open(f, ainfo->corder_bt2_addr, NULL)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to open v2 B-tree for creation order index");
/* Insert the record into the creation order index v2 B-tree */
if (H5B2_insert(bt2_corder, &udata) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTINSERT, FAIL, "unable to insert record into v2 B-tree");
} /* end if */
done:
/* Release resources */
if (shared_fheap && H5HF_close(shared_fheap) < 0)
HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, FAIL, "can't close fractal heap");
if (fheap && H5HF_close(fheap) < 0)
HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, FAIL, "can't close fractal heap");
if (bt2_name && H5B2_close(bt2_name) < 0)
HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, FAIL, "can't close v2 B-tree for name index");
if (bt2_corder && H5B2_close(bt2_corder) < 0)
HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, FAIL, "can't close v2 B-tree for creation order index");
if (wb && H5WB_unwrap(wb) < 0)
HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, FAIL, "can't close wrapped buffer");
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5A__dense_insert() */
/*-------------------------------------------------------------------------
* Function: H5A__dense_write_bt2_cb2
*
* Purpose: v2 B-tree 'modify' callback to update the record for a creation
* order index
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
static herr_t
H5A__dense_write_bt2_cb2(void *_record, void *_op_data, bool *changed)
{
H5A_dense_bt2_corder_rec_t *record = (H5A_dense_bt2_corder_rec_t *)_record; /* Record from B-tree */
H5O_fheap_id_t *new_heap_id = (H5O_fheap_id_t *)_op_data; /* "op data" from v2 B-tree modify */
FUNC_ENTER_PACKAGE_NOERR
/* Check arguments */
assert(record);
assert(new_heap_id);
/* Update record's heap ID */
record->id = *new_heap_id;
/* Note that the record changed */
*changed = true;
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5A__dense_write_bt2_cb2() */
/*-------------------------------------------------------------------------
* Function: H5A__dense_write_bt2_cb
*
* Purpose: v2 B-tree 'modify' callback to update the data for an attribute
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
static herr_t
H5A__dense_write_bt2_cb(void *_record, void *_op_data, bool *changed)
{
H5A_dense_bt2_name_rec_t *record = (H5A_dense_bt2_name_rec_t *)_record; /* Record from B-tree */
H5A_bt2_od_wrt_t *op_data = (H5A_bt2_od_wrt_t *)_op_data; /* "op data" from v2 B-tree modify */
H5B2_t *bt2_corder = NULL; /* v2 B-tree handle for creation order index */
H5WB_t *wb = NULL; /* Wrapped buffer for attribute data */
uint8_t attr_buf[H5A_ATTR_BUF_SIZE]; /* Buffer for serializing attribute */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Check arguments */
assert(record);
assert(op_data);
/* Check for modifying shared attribute */
if (record->flags & H5O_MSG_FLAG_SHARED) {
/* Update the shared attribute in the SOHM info */
if (H5O__attr_update_shared(op_data->f, NULL, op_data->attr, NULL) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTUPDATE, FAIL, "unable to update attribute in shared storage");
/* Update record's heap ID */
record->id = op_data->attr->sh_loc.u.heap_id;
/* Check if we need to modify the creation order index with new heap ID */
if (H5_addr_defined(op_data->corder_bt2_addr)) {
H5A_bt2_ud_common_t udata; /* User data for v2 B-tree modify */
/* Open the creation order index v2 B-tree */
if (NULL == (bt2_corder = H5B2_open(op_data->f, op_data->corder_bt2_addr, NULL)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL,
"unable to open v2 B-tree for creation order index");
/* Create the "udata" information for v2 B-tree record modify */
udata.f = op_data->f;
udata.fheap = NULL;
udata.shared_fheap = NULL;
udata.name = NULL;
udata.name_hash = 0;
udata.flags = 0;
udata.corder = op_data->attr->shared->crt_idx;
udata.found_op = NULL;
udata.found_op_data = NULL;
/* Modify record for creation order index */
if (H5B2_modify(bt2_corder, &udata, false, H5A__dense_write_bt2_cb2,
&op_data->attr->sh_loc.u.heap_id) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTINSERT, FAIL, "unable to modify record in v2 B-tree");
} /* end if */
/* Note that the record changed */
*changed = true;
} /* end if */
else {
void *attr_ptr; /* Pointer to serialized message */
size_t attr_size; /* Size of serialized attribute in the heap */
/* Find out the size of buffer needed for serialized attribute */
if ((attr_size = H5O_msg_raw_size(op_data->f, H5O_ATTR_ID, false, op_data->attr)) == 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTGETSIZE, FAIL, "can't get attribute size");
/* Wrap the local buffer for serialized attributes */
if (NULL == (wb = H5WB_wrap(attr_buf, sizeof(attr_buf))))
HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "can't wrap buffer");
/* Get a pointer to a buffer that's large enough for attribute */
if (NULL == (attr_ptr = H5WB_actual(wb, attr_size)))
HGOTO_ERROR(H5E_ATTR, H5E_NOSPACE, FAIL, "can't get actual buffer");
/* Create serialized form of attribute */
if (H5O_msg_encode(op_data->f, H5O_ATTR_ID, false, (unsigned char *)attr_ptr, op_data->attr) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTENCODE, FAIL, "can't encode attribute");
/* Sanity check */
#ifndef NDEBUG
{
size_t obj_len; /* Length of existing encoded attribute */
if (H5HF_get_obj_len(op_data->fheap, &record->id, &obj_len) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTGETSIZE, FAIL, "can't get object size");
assert(obj_len == attr_size);
}
#endif /* NDEBUG */
/* Update existing attribute in heap */
/* (might be more efficient as fractal heap 'op' callback, but leave that for later -QAK) */
if (H5HF_write(op_data->fheap, &record->id, changed, attr_ptr) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTUPDATE, FAIL, "unable to update attribute in heap");
} /* end else */
done:
/* Release resources */
if (bt2_corder && H5B2_close(bt2_corder) < 0)
HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, FAIL, "can't close v2 B-tree for creation order index");
if (wb && H5WB_unwrap(wb) < 0)
HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, FAIL, "can't close wrapped buffer");
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5A__dense_write_bt2_cb() */
/*-------------------------------------------------------------------------
* Function: H5A__dense_write
*
* Purpose: Modify an attribute in dense storage structures for an object
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
herr_t
H5A__dense_write(H5F_t *f, const H5O_ainfo_t *ainfo, H5A_t *attr)
{
H5A_bt2_ud_common_t udata; /* User data for v2 B-tree modify */
H5A_bt2_od_wrt_t op_data; /* "Op data" for v2 B-tree modify */
H5HF_t *fheap = NULL; /* Fractal heap handle */
H5HF_t *shared_fheap = NULL; /* Fractal heap handle for shared header messages */
H5B2_t *bt2_name = NULL; /* v2 B-tree handle for name index */
htri_t attr_sharable; /* Flag indicating attributes are shareable */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Check arguments */
assert(f);
assert(ainfo);
assert(H5_addr_defined(ainfo->fheap_addr));
assert(H5_addr_defined(ainfo->name_bt2_addr));
assert(attr);
/* Check if attributes are shared in this file */
if ((attr_sharable = H5SM_type_shared(f, H5O_ATTR_ID)) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't determine if attributes are shared");
/* Get handle for shared message heap, if attributes are shareable */
if (attr_sharable) {
haddr_t shared_fheap_addr; /* Address of fractal heap to use */
/* Retrieve the address of the shared message's fractal heap */
if (H5SM_get_fheap_addr(f, H5O_ATTR_ID, &shared_fheap_addr) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't get shared message heap address");
/* Check if there are any shared messages currently */
if (H5_addr_defined(shared_fheap_addr)) {
/* Open the fractal heap for shared header messages */
if (NULL == (shared_fheap = H5HF_open(f, shared_fheap_addr)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to open fractal heap");
} /* end if */
} /* end if */
/* Open the fractal heap */
if (NULL == (fheap = H5HF_open(f, ainfo->fheap_addr)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to open fractal heap");
/* Open the name index v2 B-tree */
if (NULL == (bt2_name = H5B2_open(f, ainfo->name_bt2_addr, NULL)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to open v2 B-tree for name index");
/* Create the "udata" information for v2 B-tree record modify */
udata.f = f;
udata.fheap = fheap;
udata.shared_fheap = shared_fheap;
udata.name = attr->shared->name;
udata.name_hash = H5_checksum_lookup3(attr->shared->name, strlen(attr->shared->name), 0);
udata.flags = 0;
udata.corder = 0;
udata.found_op = NULL;
udata.found_op_data = NULL;
/* Create the "op_data" for the v2 B-tree record 'modify' callback */
op_data.f = f;
op_data.fheap = fheap;
op_data.shared_fheap = shared_fheap;
op_data.attr = attr;
op_data.corder_bt2_addr = ainfo->corder_bt2_addr;
/* Modify attribute through 'name' tracking v2 B-tree */
if (H5B2_modify(bt2_name, &udata, false, H5A__dense_write_bt2_cb, &op_data) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTINSERT, FAIL, "unable to modify record in v2 B-tree");
done:
/* Release resources */
if (shared_fheap && H5HF_close(shared_fheap) < 0)
HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, FAIL, "can't close fractal heap");
if (fheap && H5HF_close(fheap) < 0)
HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, FAIL, "can't close fractal heap");
if (bt2_name && H5B2_close(bt2_name) < 0)
HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, FAIL, "can't close v2 B-tree for name index");
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5A__dense_write() */
/*-------------------------------------------------------------------------
* Function: H5A__dense_copy_fh_cb
*
* Purpose: Callback for fractal heap operator, to make copy of attribute
* for calling routine
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
static herr_t
H5A__dense_copy_fh_cb(const void *obj, size_t obj_len, void *_udata)
{
H5A_fh_ud_cp_t *udata = (H5A_fh_ud_cp_t *)_udata; /* User data for fractal heap 'op' callback */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Decode attribute information & keep a copy */
/* (we make a copy instead of calling the user/library callback directly in
* this routine because this fractal heap 'op' callback routine is called
* with the direct block protected and if the callback routine invokes an
* HDF5 routine, it could attempt to re-protect that direct block for the
* heap, causing the HDF5 routine called to fail)
*/
if (NULL == (udata->attr = (H5A_t *)H5O_msg_decode(udata->f, NULL, H5O_ATTR_ID, obj_len,
(const unsigned char *)obj)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTDECODE, FAIL, "can't decode attribute");
/* Set the creation order index for the attribute */
udata->attr->shared->crt_idx = udata->record->corder;
/* Check whether we should "reconstitute" the shared message info */
if (udata->record->flags & H5O_MSG_FLAG_SHARED)
H5SM_reconstitute(&(udata->attr->sh_loc), udata->f, H5O_ATTR_ID, udata->record->id);
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5A__dense_copy_fh_cb() */
/*-------------------------------------------------------------------------
* Function: H5A__dense_rename
*
* Purpose: Rename an attribute in dense storage structures for an object
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
herr_t
H5A__dense_rename(H5F_t *f, const H5O_ainfo_t *ainfo, const char *old_name, const char *new_name)
{
H5A_bt2_ud_common_t udata; /* User data for v2 B-tree modify */
H5HF_t *fheap = NULL; /* Fractal heap handle */
H5HF_t *shared_fheap = NULL; /* Fractal heap handle for shared header messages */
H5B2_t *bt2_name = NULL; /* v2 B-tree handle for name index */
H5B2_t *bt2_corder = NULL; /* v2 B-tree handle for creation order ndex */
H5A_t *attr_copy = NULL; /* Copy of attribute to rename */
htri_t attr_sharable; /* Flag indicating attributes are shareable */
htri_t shared_mesg; /* Should this message be stored in the Shared Message table? */
bool attr_exists; /* Attribute exists in v2 B-tree */
H5O_ainfo_t tainfo = *ainfo; /* Copy of ainfo */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Check arguments */
assert(f);
assert(ainfo);
assert(old_name);
assert(new_name);
/* Check if attributes are shared in this file */
if ((attr_sharable = H5SM_type_shared(f, H5O_ATTR_ID)) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't determine if attributes are shared");
/* Get handle for shared message heap, if attributes are shareable */
if (attr_sharable) {
haddr_t shared_fheap_addr; /* Address of fractal heap to use */
/* Retrieve the address of the shared message's fractal heap */
if (H5SM_get_fheap_addr(f, H5O_ATTR_ID, &shared_fheap_addr) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't get shared message heap address");
/* Check if there are any shared messages currently */
if (H5_addr_defined(shared_fheap_addr)) {
/* Open the fractal heap for shared header messages */
if (NULL == (shared_fheap = H5HF_open(f, shared_fheap_addr)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to open fractal heap");
} /* end if */
} /* end if */
/* Open the fractal heap */
if (NULL == (fheap = H5HF_open(f, ainfo->fheap_addr)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to open fractal heap");
/* Open the name index v2 B-tree */
if (NULL == (bt2_name = H5B2_open(f, ainfo->name_bt2_addr, NULL)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to open v2 B-tree for name index");
/* Create the "udata" information for v2 B-tree record modify */
udata.f = f;
udata.fheap = fheap;
udata.shared_fheap = shared_fheap;
udata.name = old_name;
udata.name_hash = H5_checksum_lookup3(old_name, strlen(old_name), 0);
udata.flags = 0;
udata.corder = 0;
udata.found_op = H5A__dense_fnd_cb; /* v2 B-tree comparison callback */
udata.found_op_data = &attr_copy;
/* Get copy of attribute through 'name' tracking v2 B-tree */
attr_exists = false;
if (H5B2_find(bt2_name, &udata, &attr_exists, NULL, NULL) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_NOTFOUND, FAIL, "can't search for attribute in name index");
if (attr_exists == false)
HGOTO_ERROR(H5E_ATTR, H5E_NOTFOUND, FAIL, "can't locate attribute in name index");
assert(attr_copy);
/* Check if message is already shared */
if ((shared_mesg = H5O_msg_is_shared(H5O_ATTR_ID, attr_copy)) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "error determining if message is shared");
else if (shared_mesg > 0) {
/* Reset shared status of copy */
/* (so it will get shared again if necessary) */
attr_copy->sh_loc.type = H5O_SHARE_TYPE_UNSHARED;
} /* end if */
/* Change name of attribute */
H5MM_xfree(attr_copy->shared->name);
attr_copy->shared->name = H5MM_xstrdup(new_name);
/* Recompute the version to encode the attribute with */
if (H5A__set_version(f, attr_copy) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "unable to update attribute version");
/* Need to remove the attribute from the creation order index v2 B-tree */
if (ainfo->index_corder) {
bool corder_attr_exists; /* Attribute exists in v2 B-tree */
/* Open the creation order index v2 B-tree */
assert(H5_addr_defined(ainfo->corder_bt2_addr));
if (NULL == (bt2_corder = H5B2_open(f, ainfo->corder_bt2_addr, NULL)))
HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to open v2 B-tree for creation index");
/* Set up the creation order to search for */
udata.corder = attr_copy->shared->crt_idx;
corder_attr_exists = false;
if (H5B2_find(bt2_corder, &udata, &corder_attr_exists, NULL, NULL) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_NOTFOUND, FAIL, "can't search for attribute in name index");
if (corder_attr_exists) {
H5A_bt2_ud_rm_t rm_udata;
/* Set up the creation order in user data for the v2 B-tree 'record remove' callback */
rm_udata.common.corder = attr_copy->shared->crt_idx;
/* Remove the record from the creation order index v2 B-tree */
if (H5B2_remove(bt2_corder, &rm_udata, NULL, NULL) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTREMOVE, FAIL,
"unable to remove attribute from creation order index v2 B-tree");
}
}
/* Insert renamed attribute back into dense storage */
/* (Possibly making it shared) */
if (H5A__dense_insert(f, ainfo, attr_copy) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTINSERT, FAIL, "unable to add to dense storage");
/* Was this attribute shared? */
if ((shared_mesg = H5O_msg_is_shared(H5O_ATTR_ID, attr_copy)) > 0) {
hsize_t attr_rc; /* Attribute's ref count in shared message storage */
/* Retrieve ref count for shared attribute */
if (H5SM_get_refcount(f, H5O_ATTR_ID, &attr_copy->sh_loc, &attr_rc) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't retrieve shared message ref count");
/* If the newly shared attribute needs to share "ownership" of the shared
* components (ie. its reference count is 1), increment the reference
* count on any shared components of the attribute, so that they won't
* be removed from the file. (Essentially a "copy on write" operation).
*
* *ick* -QAK, 2007/01/08
*/
if (attr_rc == 1) {
/* Increment reference count on attribute components */
if (H5O__attr_link(f, NULL, attr_copy) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_LINKCOUNT, FAIL, "unable to adjust attribute link count");
} /* end if */
} /* end if */
else if (shared_mesg == 0) {
/* Increment reference count on attribute components */
/* (so that they aren't deleted when the attribute is removed shortly) */
if (H5O__attr_link(f, NULL, attr_copy) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_LINKCOUNT, FAIL, "unable to adjust attribute link count");
} /* end if */
else if (shared_mesg < 0)
HGOTO_ERROR(H5E_ATTR, H5E_WRITEERROR, FAIL, "error determining if message should be shared");
/* Deactivate the field so that H5A__dense_remove() won't delete the new renamed attribute
that was just added to the creation order index v2 B-tree via H5A__dense_insert() */
tainfo.corder_bt2_addr = HADDR_UNDEF;
/* Only delete the old attribute (before rename) from the name index v2 B-tree */
if (H5A__dense_remove(f, (const H5O_ainfo_t *)&tainfo, old_name) < 0)
HGOTO_ERROR(H5E_ATTR, H5E_CANTDELETE, FAIL, "unable to delete attribute in dense storage");
done:
/* Release resources */
if (shared_fheap && H5HF_close(shared_fheap) < 0)
HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, FAIL, "can't close fractal heap");
if (fheap && H5HF_close(fheap) < 0)
HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, FAIL, "can't close fractal heap");
if (bt2_name && H5B2_close(bt2_name) < 0)
HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, FAIL, "can't close v2 B-tree for name index");
if (bt2_corder && H5B2_close(bt2_corder) < 0)
HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, FAIL, "can't close v2 B-tree for creation order index");
if (attr_copy)
H5O_msg_free(H5O_ATTR_ID, attr_copy);