summaryrefslogtreecommitdiffstats
path: root/src/H5FPclient.c
blob: e3b7d097143fb8cf7ddf9c44a6e60ea87a4415b0 (plain)
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
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by the Board of Trustees of the University of Illinois.         *
 * 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 files COPYING and Copyright.html.  COPYING can be found at the root   *
 * of the source code distribution tree; Copyright.html can be found at the  *
 * root level of an installed copy of the electronic HDF5 document set and   *
 * is linked from the top-level documents page.  It can also be found at     *
 * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html.  If you do not have     *
 * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#define H5S_PACKAGE             /*suppress error about including H5Spkg */
#define H5G_PACKAGE             /*suppress error about including H5Gpkg */

#include "H5private.h"          /* Generic Functions                    */
#include "H5Dprivate.h"         /* Dataset Functions                    */
#include "H5Eprivate.h"         /* Error Handling                       */
#include "H5Gpkg.h"             /* Group functions                      */
#include "H5Iprivate.h"         /* ID Functions                         */
#include "H5MMprivate.h"        /* Memory allocation                    */
#include "H5Oprivate.h"         /* Object Headers                       */
#include "H5Spkg.h"             /* Dataspace functions                  */
#include "H5TBprivate.h"        /* Threaded, Balanced, Binary Trees     */

#ifdef H5_HAVE_FPHDF5

#include "H5FPprivate.h"        /* Flexible Parallel Functions          */

/* Pablo mask */
#define PABLO_MASK      H5FPclient_mask

/* Is the interface initialized? */
static int interface_initialize_g = 0;
#define INTERFACE_INIT  NULL

/* local functions */
static unsigned H5FP_gen_request_id(void);
static herr_t   H5FP_update_file_cache(hid_t file_id, struct SAP_sync *sap_sync, uint8_t *msg);

/** Public Library (non-API) Functions **/

/*
 * Function:    H5FP_fill_fphdf5_struct
 * Purpose:     Nice function to fill in the H5O_fphdf5_t structure
 *              before transmission to the SAP.
 * Return:      Nothing:    Doesn't fail after asserts pass.
 * Programmer:  Bill Wendling, 13. November, 2002
 * Modifications:
 */
void
H5FP_fill_fphdf5_struct(H5O_fphdf5_t *fphdf5, uint8_t *oid, haddr_t header,
                        struct H5S_simple_t *sdim, H5T_t *dtype, time_t *mtime,
                        H5O_layout_t *layout, H5O_name_t *group, H5O_name_t *dataset,
                        struct H5P_genplist_t *plist)
{
    /* check args */
    assert(fphdf5);
    assert(oid);
    assert(sdim);
    assert(dtype);
    assert(layout);
    assert(plist);

    HDmemcpy(fphdf5->oid, oid, sizeof(fphdf5->oid));
    fphdf5->header = header;
    fphdf5->layout = layout;
    fphdf5->sdim = sdim;
    fphdf5->mtime = mtime;
    fphdf5->group = group;
    fphdf5->dset = dataset;
    fphdf5->dtype = dtype;
    fphdf5->plist = plist;
}

/*
 * Function:    H5FP_request_open
 * Purpose:     Request an open of a file from the SAP. You pass in the
 *              metadata string (MDATA) (the filename), it's length in
 *              (MD_LEN), and the type of the object you're trying to
 *              open (OBJ_TYPE). The request ID is returned in a pointer
 *              supplied by the user.
 *
 *              The so-called "captain" process is in charge of telling
 *              the SAP that the processes opened a file. All processes
 *              opening the file, though, should call this function so
 *              that they can get the file ID that the SAP assigns to it.
 *
 *              N.B. This could be expanded to handle the opening of more
 *              than just a file, if that becomes necessary. Right now,
 *              we are only keeping track of file opens.
 *
 * Return:      Success:    SUCCEED
 *              Failure:    FAIL
 * Programmer:  Bill Wendling, 28. August, 2002
 * Modifications:
 */
herr_t
H5FP_request_open(const char *mdata, int md_len, enum sap_obj_type obj_type,
                  unsigned *file_id, unsigned *req_id)
{
    struct SAP_request req;
    MPI_Status mpi_status;
    int ret_value = SUCCEED, mrc;

    FUNC_ENTER_NOAPI(H5FP_request_open, FAIL);

    /* check args */
    assert(mdata);
    assert(file_id);
    assert(req_id);

    HDmemset(&mpi_status, 0, sizeof(MPI_Status));

    if (H5FP_my_rank == H5FP_capt_rank) {
        HDmemset(&req, 0, sizeof(req));
        req.req_type = H5FP_REQ_OPEN;
        req.req_id = H5FP_gen_request_id();
        req.proc_rank = H5FP_my_rank;
        req.md_len = md_len;
        req.obj_type = obj_type;

        if ((mrc = MPI_Send(&req, 1, SAP_request_t, (int)H5FP_sap_rank,
                            H5FP_TAG_REQUEST, H5FP_SAP_COMM)) != MPI_SUCCESS)
            HMPI_GOTO_ERROR(FAIL, "MPI_Send failed", mrc);

        if (H5FP_send_metadata(mdata, md_len, (int)H5FP_sap_rank))
            HGOTO_ERROR(H5E_FPHDF5, H5E_CANTSENDMDATA, FAIL,
                        "can't send metadata to server");
    }

    if ((mrc = MPI_Recv(file_id, 1, MPI_UNSIGNED, (int)H5FP_sap_rank,
                        H5FP_TAG_FILE_ID, H5FP_SAP_COMM, &mpi_status)) != MPI_SUCCESS)
        HMPI_GOTO_ERROR(FAIL, "MPI_Send failed", mrc);

    printf("%u: New File ID == %u\n", H5FP_my_rank, *file_id);
    fflush(stdout);

done:
    *req_id = req.req_id;
    FUNC_LEAVE_NOAPI(ret_value);
}

/*
 * Function:    H5FP_request_lock
 * Purpose:     Request a lock on an object in a file from the SAP. The
 *              request ID is returned in a pointer supplied by the user.
 *              The status of the SAP is returned to the user in the
 *              supplied STATUS pointer.
 * Return:      Success:    SUCCEED
 *              Failure:    FAIL
 * Programmer:  Bill Wendling, 30. July, 2002
 * Modifications:
 */
herr_t
H5FP_request_lock(unsigned int sap_file_id, unsigned char *obj_oid,
                  enum sap_lock_type rw_lock, int last, unsigned *req_id,
                  enum sap_status *status)
{
    struct SAP_request req;
    int ret_value = SUCCEED, mrc;

    FUNC_ENTER_NOAPI(H5FP_request_lock, FAIL);

    assert(obj_oid);
    assert(req_id);
    assert(status);
    HDmemset(&req, 0, sizeof(req));

    *status = H5FP_STATUS_OK;
    req.req_type = last ? H5FP_REQ_LOCK_END : H5FP_REQ_LOCK;
    req.req_id = H5FP_gen_request_id();
    req.sap_file_id = sap_file_id;
    req.rw_lock = rw_lock;
    req.md_len = 0;
    req.proc_rank = H5FP_my_rank;
    H5FP_COPY_OID(req.oid, obj_oid);

    if ((mrc = MPI_Send(&req, 1, SAP_request_t, (int)H5FP_sap_rank,
                        H5FP_TAG_REQUEST, H5FP_SAP_COMM)) != MPI_SUCCESS)
        HMPI_GOTO_ERROR(FAIL, "MPI_Send failed", mrc);

    if (last) {
        /*
         * On the last lock in the lock-group to be acquired, we expect a
         * reply from the SAP
         */
        struct SAP_reply sap_reply;
        MPI_Status mpi_status;

        HDmemset(&mpi_status, 0, sizeof(mpi_status));

        if ((mrc = MPI_Recv(&sap_reply, 1, SAP_reply_t, (int)H5FP_sap_rank,
                            H5FP_TAG_REPLY, H5FP_SAP_COMM, &mpi_status)) != MPI_SUCCESS)
            HMPI_GOTO_ERROR(FAIL, "MPI_Recv failed", mrc);

        *status = sap_reply.status;

        if (sap_reply.status != H5FP_STATUS_LOCK_ACQUIRED)
            HGOTO_ERROR(H5E_RESOURCE, H5E_CANTLOCK, FAIL, "can't lock object on server");
    }

done:
    *req_id = req.req_id;
    FUNC_LEAVE_NOAPI(ret_value);
}

/*
 * Function:    H5FP_request_release_lock
 * Purpose:     Release a lock on the file from the SAP. Request a lock
 *              on an object in a file from the SAP. The request ID is
 *              returned in a pointer supplied by the user. The status
 *              of the SAP is returned to the user in the supplied STATUS
 *              pointer.
 * Return:      Success: The request ID.
 *              Failure: -1
 * Programmer:  Bill Wendling, 30. July, 2002
 * Modifications:
 */
herr_t
H5FP_request_release_lock(unsigned int sap_file_id, unsigned char *obj_oid,
                          int last, unsigned *req_id, enum sap_status *status)
{
    struct SAP_request req;
    herr_t ret_value = SUCCEED;
    int mrc;

    FUNC_ENTER_NOAPI(H5FP_request_release_lock, FAIL);

    assert(req_id);
    assert(status);

    HDmemset(&req, 0, sizeof(req));

    *status = H5FP_STATUS_OK;
    req.req_type = last ? H5FP_REQ_RELEASE_END : H5FP_REQ_RELEASE;
    req.req_id = H5FP_gen_request_id();
    req.sap_file_id = sap_file_id;
    req.md_len = 0;
    req.proc_rank = H5FP_my_rank;

    if (obj_oid)
        H5FP_COPY_OID(req.oid, obj_oid);
    else
        HDmemset(req.oid, '\0', sizeof(req.oid));

    if ((mrc = MPI_Send(&req, 1, SAP_request_t, (int)H5FP_sap_rank,
                        H5FP_TAG_REQUEST, H5FP_SAP_COMM)) != MPI_SUCCESS)
        HMPI_GOTO_ERROR(FAIL, "MPI_Send failed", mrc);

    if (last) {
        /*
         * On the last lock released in this lock-group, we expect a
         * reply from the SAP
         */
        struct SAP_reply sap_reply;
        MPI_Status mpi_status;

        HDmemset(&mpi_status, 0, sizeof(mpi_status));

        if ((mrc = MPI_Recv(&sap_reply, 1, SAP_reply_t, (int)H5FP_sap_rank,
                            H5FP_TAG_REPLY, H5FP_SAP_COMM, &mpi_status)) != MPI_SUCCESS)
            HMPI_GOTO_ERROR(FAIL, "MPI_Recv failed", mrc);

        *status = sap_reply.status;

        if (sap_reply.status != H5FP_STATUS_LOCK_RELEASED)
            HGOTO_ERROR(H5E_RESOURCE, H5E_CANTUNLOCK, FAIL, "can't unlock object on server");
    }

done:
    *req_id = req.req_id;
    FUNC_LEAVE_NOAPI(ret_value);
}

/*
 * Function:    H5FP_request_change
 * Purpose:     Tell the SAP that we want to change the structure of the file.
 *              Include the information the SAP will need to send to the
 *              other processes so that they can be synced with what you
 *              are doing. The request ID is returned in a pointer
 *              supplied by the user.
 * Return:      Success:    SUCCEED
 *              Failure:    FAIL
 * Programmer:  Bill Wendling, 02. August, 2002
 * Modifications:
 */
herr_t
H5FP_request_change(unsigned int sap_file_id, unsigned char *obj_oid,
                    enum sap_obj_type obj_type, enum sap_action action,
                    int mdata_len, const char *mdata, unsigned *req_id,
                    enum sap_status *status)
{
    struct SAP_reply sap_reply;
    MPI_Status mpi_status;
    struct SAP_request req;
    herr_t ret_value = SUCCEED;
    int mrc;

    FUNC_ENTER_NOAPI(H5FP_request_change, FAIL);

    assert(mdata);
    HDmemset(&req, 0, sizeof(req));

    req.req_type = H5FP_REQ_CHANGE;
    req.req_id = H5FP_gen_request_id();
    req.sap_file_id = sap_file_id;
    req.obj_type = obj_type;
    req.action = action;
    req.md_len = mdata_len;
    req.proc_rank = H5FP_my_rank;

    if (obj_oid)
        H5FP_COPY_OID(req.oid, obj_oid);
    else
        HDmemset(req.oid, '\0', sizeof(req.oid));

    if ((mrc = MPI_Send(&req, 1, SAP_request_t, (int)H5FP_sap_rank,
                        H5FP_TAG_REQUEST, H5FP_SAP_COMM)) != MPI_SUCCESS)
        HMPI_GOTO_ERROR(FAIL, "MPI_Send failed", mrc);

    /* The first MPI_Send will have been sent before this one will be read. */
    if (H5FP_send_metadata(mdata, mdata_len, (int)H5FP_sap_rank) != SUCCEED)
        HGOTO_ERROR(H5E_FPHDF5, H5E_CANTSENDMDATA, FAIL, "can't send metadata to server");

    HDmemset(&mpi_status, 0, sizeof(mpi_status));

    if ((mrc = MPI_Recv(&sap_reply, 1, SAP_reply_t, (int)H5FP_sap_rank,
                        H5FP_TAG_REPLY, H5FP_SAP_COMM, &mpi_status)) != MPI_SUCCESS)
        HMPI_GOTO_ERROR(FAIL, "MPI_Recv failed", mrc);

    *status = sap_reply.status;

    if (sap_reply.status != H5FP_STATUS_OK)
        HGOTO_ERROR(H5E_RESOURCE, H5E_CANTUNLOCK, FAIL, "can't register change with server");

done:
    *req_id = req.req_id;
    FUNC_LEAVE_NOAPI(ret_value);
}

#if 0
herr_t
H5FP_generate_message(fid_t fid, const char *dataset, const char *group,
                      H5D_t *dset, H5S_t *space, H5O_fphdf5_t *fphdf5 /* out */)
{
    hobj_ref_t gr_ref, ds_ref;
    H5O_efl_t efl;
    H5F_t *file = NULL;
    H5S_t *space = NULL;
    H5G_entry_t *ent = NULL;
    int i;
    herr_t ret_value = SUCCEED;

    FUNC_ENTER_NOAPI(H5FP_generate_message, FAIL);

    if ((file = H5I_object(file_id)) == NULL)
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid file identifier");

    if ((grp = H5G_open(file, group)) == NULL)
        HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "unable to open group");

    if ((ent = H5G_entof(grp)) == NULL)
        /* this will never be executed */
        HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "unable to get entry info of group");

    memcpy(fphdf5->oid, (void *)&ent->header, sizeof(ent->header));

    if ((loc = H5G_loc(did)) == NULL) {
        exit(1);
    }

    memcpy(ds_ref.oid, (void *)&loc->header, sizeof(loc->header));

    memcpy(fphdf5.oid, ds_ref.oid, sizeof(ds_ref.oid));
    fphdf5->header = dset->ent.header;
    fphdf5->layout = &dset->layout;
    fphdf5->sdim = &(space->extent.u.simple);
#if 0
    fphdf5->mtime = ;
#endif
    fphdf5->group = group;
    fphdf5->dset = dataset;
    fphdf5->dtype = dset->type;

    if ((fphdf5->plist = H5P_object_verify(dset->dcpl_id,
                                           H5P_DATASET_CREATE)) == NULL) {
        exit(1);
    }

    if (H5P_get(fphdf5->plist, H5D_CRT_EXT_FILE_LIST_NAME, &efl) < 0)
        HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get external file list");

    fphdf5->efl = &efl;

done:
    FUNC_LEAVE_NOAPI(ret_value);
}
#endif

/*
 * Function:    H5FP_request_sync
 * Purpose:     Tell the SAP that we want all of the structural changes
 *              made on the file that we don't know about. The request ID
 *              is returned in a pointer supplied by the user. The status
 *              of the SAP is returned to the user in the supplied STATUS
 *              pointer.
 * Return:      Success:    SUCCEED
 *              Failure:    FAIL
 * Programmer:  Bill Wendling, 02. August, 2002
 * Modifications:
 */
herr_t
H5FP_request_sync(unsigned int sap_file_id, hid_t hdf_file_id,
                  unsigned *req_id, enum sap_status *status)
{
    struct SAP_request req;
    herr_t ret_value = SUCCEED;
    int mrc;

    FUNC_ENTER_NOAPI(H5FP_request_sync, FAIL);

    assert(req_id);
    assert(status);

    HDmemset(&req, 0, sizeof(req));

    *status = H5FP_STATUS_OK;
    req.req_type = H5FP_REQ_SYNC;
    req.req_id = H5FP_gen_request_id();
    req.sap_file_id = sap_file_id;
    req.proc_rank = H5FP_my_rank;

    if ((mrc = MPI_Send(&req, 1, SAP_request_t, (int)H5FP_sap_rank,
                        H5FP_TAG_REQUEST, H5FP_SAP_COMM)) != MPI_SUCCESS)
        HMPI_GOTO_ERROR(FAIL, "MPI_Send failed", mrc);

    for (;;) {
        MPI_Status mpi_status;
        struct SAP_sync sap_sync;

        HDmemset(&mpi_status, 0, sizeof(mpi_status));

        if ((mrc = MPI_Recv(&sap_sync, 1, SAP_sync_t, (int)H5FP_sap_rank, H5FP_TAG_SYNC,
                            H5FP_SAP_COMM, &mpi_status)) != MPI_SUCCESS)
            HMPI_GOTO_ERROR(FAIL, "MPI_Recv failed", mrc);

        if (sap_sync.status != H5FP_STATUS_OK) {
            *status = sap_sync.status;
            HGOTO_DONE(FAIL);
        }

        /*
         * use the info in the SAP_sync_t structure to update the
         * metadata
         */
        if (sap_sync.md_len) {
            uint8_t *buf;

            if ((buf = (uint8_t *)HDcalloc((size_t)sap_sync.md_len + 1, 1)) == NULL)
                HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "out of memory");

            HDmemset(&mpi_status, 0, sizeof(mpi_status));

            if ((mrc = MPI_Recv(buf, sap_sync.md_len, MPI_BYTE, (int)H5FP_sap_rank,
                                H5FP_TAG_METADATA, H5FP_SAP_COMM, &mpi_status)) != MPI_SUCCESS) {
                HDfree(buf);
                HMPI_GOTO_ERROR(FAIL, "MPI_Recv failed", mrc);
            }

            /*
             * FIXME: perform whatever metadata updates we can with the
             * metadata returned from the SAP
             */
            if (H5FP_update_file_cache(hdf_file_id, &sap_sync, buf) != SUCCEED)
                HGOTO_DONE(FAIL);

            HDfree(buf);
        }

        if (sap_sync.last_msg)
            break;
    }

done:
    *req_id = req.req_id;
    FUNC_LEAVE_NOAPI(ret_value);
}

/*
 * Function:    H5FP_request_close
 * Purpose:     Tell the SAP that we want all of the structural changes
 *              made on the file and then close the file. The request ID
 *              is returned in a pointer passed to the function by the
 *              user.
 * Return:      Success:    SUCCEED
 *              Failure:    FAIL
 * Programmer:  Bill Wendling, 02. August, 2002
 * Modifications:
 */
herr_t
H5FP_request_close(unsigned sap_file_id, unsigned *req_id)
{
    struct SAP_request req;
    int ret_value = SUCCEED, mrc;

    FUNC_ENTER_NOAPI(H5FP_request_close, FAIL);

    HDmemset(&req, 0, sizeof(req));
    req.req_type = H5FP_REQ_CLOSE;
    req.req_id = H5FP_gen_request_id();
    req.sap_file_id = sap_file_id;
    req.proc_rank = H5FP_my_rank;

    if ((mrc = MPI_Send(&req, 1, SAP_request_t, (int)H5FP_sap_rank,
                        H5FP_TAG_REQUEST, H5FP_SAP_COMM)) != MPI_SUCCESS)
        HMPI_GOTO_ERROR(FAIL, "MPI_Send failed", mrc);

    *req_id = req.req_id;

done:
    FUNC_LEAVE_NOAPI(ret_value);
}

/** Private Functions **/

/*
 * Function:    H5FP_gen_request_id
 * Purpose:     Generate a unique request ID to send along with a
 *              message.
 * Return:      Integer >= 0 - Doesn't fail.
 * Programmer:  Bill Wendling, 30. July, 2002
 * Modifications:
 */
static unsigned
H5FP_gen_request_id()
{
    static unsigned int i = 0;

    FUNC_ENTER_NOINIT(H5FP_gen_request_id);
    FUNC_LEAVE_NOAPI(i++);
}

/*
 * Function:    H5FP_update_file_cache
 * Purpose:     Take the information returned by a "sync" call and update
 *              the file cache. The MSG parameter should be an encoded
 *              version of the H5O_fphdf5_t object.
 * Return:      Success:    SUCCEED
 *              Failure:    FAIL
 * Programmer:  Bill Wendling, 16. December, 2002
 * Modifications:
 */
static herr_t
H5FP_update_file_cache(hid_t file_id, struct SAP_sync *sap_sync, uint8_t *msg)
{
    herr_t ret_value = SUCCEED;
    H5G_entry_t *ent = NULL, *file_ent = NULL;
    H5O_fphdf5_t *fmeta = NULL;
    H5S_t *space = NULL;
    H5F_t *file = NULL;
    H5G_t *grp = NULL;
    H5D_t *dset = NULL;

    FUNC_ENTER_NOINIT(H5FP_update_file_cache);

    /* check args */
    assert(sap_sync);
    assert(msg);

    if ((file = H5I_object(file_id)) == NULL)
        HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid file identifier");

    if ((fmeta = H5O_FPHDF5[0].decode(file, msg, NULL)) == NULL)
        HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "out of memory");

    if ((file_ent = H5G_loc(file_id)) == NULL)
        HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "unable to open group");

    if ((grp = H5G_open(file_ent, fmeta->group->s)) == NULL)
        HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "unable to open group");

    switch (sap_sync->action) {
#ifdef OLD_WAY
    case H5FP_ACT_CREATE:
        if (sap_sync->obj_type == H5FP_OBJ_DATASET) {
            H5O_efl_t efl;

            if ((ent = H5MM_malloc(sizeof(H5G_entry_t))) == NULL)
                HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "out of memory");

            if ((space = H5S_create(H5S_SIMPLE)) == NULL)
                HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCREATE, FAIL,
                            "can't create simple dataspace");

            if (H5S_set_extent_simple(space, fmeta->sdim->rank,
                                      fmeta->sdim->size, fmeta->sdim->max) < 0)
                HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "can't set dimensions");

            if (H5D_update_entry_info(file, ent, H5G_entof(grp),
                                       fmeta->dset->s, space,
                                       fmeta->plist, fmeta->layout, fmeta->dtype,
                                       FALSE, fmeta->header) == FAIL)
                HGOTO_ERROR(H5E_FPHDF5, H5E_CANTINIT, FAIL, "can't update metadata cache");

            if (H5P_get(fmeta->plist, H5D_CRT_EXT_FILE_LIST_NAME, &efl) < 0)
                HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get external file list");

            if (H5D_update_external_storage_info(file, ent, &efl, fmeta->layout) == FAIL)
                HGOTO_ERROR(H5E_FPHDF5, H5E_CANTINIT, FAIL,
                            "can't update external file layout metadata cache");
        }

        break;

    case H5FP_ACT_EXTEND:
        if (sap_sync->obj_type == H5FP_OBJ_DATASET) {
            if ((dset = H5D_open(H5G_entof(grp), fmeta->dset->s)) == NULL)
                HGOTO_ERROR(H5E_SYM, H5E_CANTOPENOBJ, FAIL, "unable to open dataset");

            if (H5D_extend(dset, fmeta->sdim->size) != SUCCEED)
                HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to extend dataset");
        }

        break;
#endif /* OLD_WAY */

    case H5FP_ACT_DELETE:
    default:
        break;
    }

done:
    /* cleanup */
    if (fmeta)
        H5O_FPHDF5[0].free(fmeta);

    if (dset)
        H5D_close(dset);

    if (grp)
        H5G_close(grp);

    if (space)
        H5S_close(space);

    if (ret_value == FAIL)
        H5MM_xfree(ent);

    FUNC_LEAVE_NOAPI(ret_value);
}

#endif  /* H5_HAVE_FPHDF5 */