H5VLpassthru_ext.c 124 KB
Newer Older
Huihuo Zheng's avatar
ssd_vol    
Huihuo Zheng committed
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
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * 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 COPYING file, which can be found at the root of the source code       *
 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
 * If you do not have access to either file, you may request a copy from     *
 * help@hdfgroup.org.                                                        *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*
 * Purpose:     This is a "pass through" VOL connector, which forwards each
 *              VOL callback to an underlying connector.
 *
 *              It is designed as an example VOL connector for developers to
 *              use when creating new connectors, especially connectors that
 *              are outside of the HDF5 library.  As such, it should _NOT_
 *              include _any_ private HDF5 header files.  This connector should
 *              therefore only make public HDF5 API calls and use standard C /
 *              POSIX calls.
 *
 *              Note that the HDF5 error stack must be preserved on code paths
 *              that could be invoked when the underlying VOL connector's
 *              callback can fail.
 *
 */


/* Header files needed */
/* Do NOT include private HDF5 files here! */
#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Public HDF5 file */
#include "hdf5.h"
#include "H5Dio_cache.h"
/* This connector's header */
#include "H5VLpassthru_ext.h"

#include <pthread.h>
#include "mpi.h"
#include "stdlib.h"
#include "string.h"
#include "unistd.h"
// POSIX I/O
#include "sys/stat.h"
#include <fcntl.h>
#include "H5Dio_cache.h"

// Memory map
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/statvfs.h>
Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
61
62
//debug
#include "debug.h"
Huihuo Zheng's avatar
ssd_vol    
Huihuo Zheng committed
63
#define  PAGESIZE sysconf(_SC_PAGE_SIZE)
Huihuo Zheng's avatar
test    
Huihuo Zheng committed
64
65
66
#ifndef SUCCEED
#define SUCCEED 0
#endif
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
67
extern SSD_INFO SSD; 
Huihuo Zheng's avatar
ssd_vol    
Huihuo Zheng committed
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**********/
/* Macros */
/**********/

/* Whether to display log messge when callback is invoked */
/* (Uncomment to enable) */
/* #define ENABLE_EXT_PASSTHRU_LOGGING */

/* Hack for missing va_copy() in old Visual Studio editions
 * (from H5win2_defs.h - used on VS2012 and earlier)
 */
#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER < 1800)
#define va_copy(D,S)      ((D) = (S))
#endif

/************/
/* Typedefs */
/************/
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
86
87
void *H5Dread_pthread_func_vol(void *args);
void *H5Dwrite_pthread_func_vol(void *args);
Huihuo Zheng's avatar
ssd_vol    
Huihuo Zheng committed
88
89
90
91
/* The pass through VOL info object */
typedef struct H5VL_pass_through_ext_t {
    hid_t  under_vol_id;        /* ID for underlying VOL connector */
    void   *under_object;       /* Info object for underlying VOL connector */
Huihuo Zheng's avatar
Huihuo Zheng committed
92
    H5Dread_cache_metadata *H5DRMM;
Huihuo Zheng's avatar
theta    
Huihuo Zheng committed
93
    H5Dwrite_cache_metadata *H5DWMM;
Huihuo Zheng's avatar
Huihuo Zheng committed
94
    bool read_cache;
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
95
    bool write_cache;
Huihuo Zheng's avatar
Huihuo Zheng committed
96
    int num_request_dataset; 
Huihuo Zheng's avatar
ssd_vol    
Huihuo Zheng committed
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
} H5VL_pass_through_ext_t;

/* The pass through VOL wrapper context */
typedef struct H5VL_pass_through_ext_wrap_ctx_t {
    hid_t under_vol_id;         /* VOL ID for under VOL */
    void *under_wrap_ctx;       /* Object wrapping context for under VOL */
} H5VL_pass_through_ext_wrap_ctx_t;


/********************* */
/* Function prototypes */
/********************* */
/* Helper routines */
static herr_t H5VL_pass_through_ext_file_specific_reissue(void *obj, hid_t connector_id,
    H5VL_file_specific_t specific_type, hid_t dxpl_id, void **req, ...);
static herr_t H5VL_pass_through_ext_request_specific_reissue(void *obj, hid_t connector_id,
    H5VL_request_specific_t specific_type, ...);
static herr_t H5VL_pass_through_ext_link_create_reissue(H5VL_link_create_type_t create_type,
    void *obj, const H5VL_loc_params_t *loc_params, hid_t connector_id,
    hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req, ...);
static H5VL_pass_through_ext_t *H5VL_pass_through_ext_new_obj(void *under_obj,
    hid_t under_vol_id);
static herr_t H5VL_pass_through_ext_free_obj(H5VL_pass_through_ext_t *obj);

/* "Management" callbacks */
static herr_t H5VL_pass_through_ext_init(hid_t vipl_id);
static herr_t H5VL_pass_through_ext_term(void);

/* VOL info callbacks */
static void *H5VL_pass_through_ext_info_copy(const void *info);
static herr_t H5VL_pass_through_ext_info_cmp(int *cmp_value, const void *info1, const void *info2);
static herr_t H5VL_pass_through_ext_info_free(void *info);
static herr_t H5VL_pass_through_ext_info_to_str(const void *info, char **str);
static herr_t H5VL_pass_through_ext_str_to_info(const char *str, void **info);

/* VOL object wrap / retrieval callbacks */
static void *H5VL_pass_through_ext_get_object(const void *obj);
static herr_t H5VL_pass_through_ext_get_wrap_ctx(const void *obj, void **wrap_ctx);
static void *H5VL_pass_through_ext_wrap_object(void *obj, H5I_type_t obj_type,
    void *wrap_ctx);
static void *H5VL_pass_through_ext_unwrap_object(void *obj);
static herr_t H5VL_pass_through_ext_free_wrap_ctx(void *obj);

/* Attribute callbacks */
static void *H5VL_pass_through_ext_attr_create(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t type_id, hid_t space_id, hid_t acpl_id, hid_t aapl_id, hid_t dxpl_id, void **req);
static void *H5VL_pass_through_ext_attr_open(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t aapl_id, hid_t dxpl_id, void **req);
static herr_t H5VL_pass_through_ext_attr_read(void *attr, hid_t mem_type_id, void *buf, hid_t dxpl_id, void **req);
static herr_t H5VL_pass_through_ext_attr_write(void *attr, hid_t mem_type_id, const void *buf, hid_t dxpl_id, void **req);
static herr_t H5VL_pass_through_ext_attr_get(void *obj, H5VL_attr_get_t get_type, hid_t dxpl_id, void **req, va_list arguments);
static herr_t H5VL_pass_through_ext_attr_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_attr_specific_t specific_type, hid_t dxpl_id, void **req, va_list arguments);
static herr_t H5VL_pass_through_ext_attr_optional(void *obj, H5VL_attr_optional_t opt_type, hid_t dxpl_id, void **req, va_list arguments);
static herr_t H5VL_pass_through_ext_attr_close(void *attr, hid_t dxpl_id, void **req);

/* Dataset callbacks */
static void *H5VL_pass_through_ext_dataset_create(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t lcpl_id, hid_t type_id, hid_t space_id, hid_t dcpl_id, hid_t dapl_id, hid_t dxpl_id, void **req);
static void *H5VL_pass_through_ext_dataset_open(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t dapl_id, hid_t dxpl_id, void **req);
static herr_t H5VL_pass_through_ext_dataset_read(void *dset, hid_t mem_type_id, hid_t mem_space_id,
                                    hid_t file_space_id, hid_t plist_id, void *buf, void **req);
static herr_t H5VL_pass_through_ext_dataset_write(void *dset, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t plist_id, const void *buf, void **req);
static herr_t H5VL_pass_through_ext_dataset_get(void *dset, H5VL_dataset_get_t get_type, hid_t dxpl_id, void **req, va_list arguments);
static herr_t H5VL_pass_through_ext_dataset_specific(void *obj, H5VL_dataset_specific_t specific_type, hid_t dxpl_id, void **req, va_list arguments);
static herr_t H5VL_pass_through_ext_dataset_optional(void *obj, H5VL_dataset_optional_t opt_type, hid_t dxpl_id, void **req, va_list arguments);
static herr_t H5VL_pass_through_ext_dataset_close(void *dset, hid_t dxpl_id, void **req);

/* Datatype callbacks */
static void *H5VL_pass_through_ext_datatype_commit(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t type_id, hid_t lcpl_id, hid_t tcpl_id, hid_t tapl_id, hid_t dxpl_id, void **req);
static void *H5VL_pass_through_ext_datatype_open(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t tapl_id, hid_t dxpl_id, void **req);
static herr_t H5VL_pass_through_ext_datatype_get(void *dt, H5VL_datatype_get_t get_type, hid_t dxpl_id, void **req, va_list arguments);
static herr_t H5VL_pass_through_ext_datatype_specific(void *obj, H5VL_datatype_specific_t specific_type, hid_t dxpl_id, void **req, va_list arguments);
static herr_t H5VL_pass_through_ext_datatype_optional(void *obj, H5VL_datatype_optional_t opt_type, hid_t dxpl_id, void **req, va_list arguments);
static herr_t H5VL_pass_through_ext_datatype_close(void *dt, hid_t dxpl_id, void **req);

/* File callbacks */
static void *H5VL_pass_through_ext_file_create(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id, hid_t dxpl_id, void **req);
static void *H5VL_pass_through_ext_file_open(const char *name, unsigned flags, hid_t fapl_id, hid_t dxpl_id, void **req);
static herr_t H5VL_pass_through_ext_file_get(void *file, H5VL_file_get_t get_type, hid_t dxpl_id, void **req, va_list arguments);
static herr_t H5VL_pass_through_ext_file_specific(void *file, H5VL_file_specific_t specific_type, hid_t dxpl_id, void **req, va_list arguments);
static herr_t H5VL_pass_through_ext_file_optional(void *file, H5VL_file_optional_t opt_type, hid_t dxpl_id, void **req, va_list arguments);
static herr_t H5VL_pass_through_ext_file_close(void *file, hid_t dxpl_id, void **req);

/* Group callbacks */
static void *H5VL_pass_through_ext_group_create(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t lcpl_id, hid_t gcpl_id, hid_t gapl_id, hid_t dxpl_id, void **req);
static void *H5VL_pass_through_ext_group_open(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t gapl_id, hid_t dxpl_id, void **req);
static herr_t H5VL_pass_through_ext_group_get(void *obj, H5VL_group_get_t get_type, hid_t dxpl_id, void **req, va_list arguments);
static herr_t H5VL_pass_through_ext_group_specific(void *obj, H5VL_group_specific_t specific_type, hid_t dxpl_id, void **req, va_list arguments);
static herr_t H5VL_pass_through_ext_group_optional(void *obj, H5VL_group_optional_t opt_type, hid_t dxpl_id, void **req, va_list arguments);
static herr_t H5VL_pass_through_ext_group_close(void *grp, hid_t dxpl_id, void **req);

/* Link callbacks */
static herr_t H5VL_pass_through_ext_link_create(H5VL_link_create_type_t create_type, void *obj, const H5VL_loc_params_t *loc_params, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req, va_list arguments);
static herr_t H5VL_pass_through_ext_link_copy(void *src_obj, const H5VL_loc_params_t *loc_params1, void *dst_obj, const H5VL_loc_params_t *loc_params2, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req);
static herr_t H5VL_pass_through_ext_link_move(void *src_obj, const H5VL_loc_params_t *loc_params1, void *dst_obj, const H5VL_loc_params_t *loc_params2, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req);
static herr_t H5VL_pass_through_ext_link_get(void *obj, const H5VL_loc_params_t *loc_params, H5VL_link_get_t get_type, hid_t dxpl_id, void **req, va_list arguments);
static herr_t H5VL_pass_through_ext_link_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_link_specific_t specific_type, hid_t dxpl_id, void **req, va_list arguments);
static herr_t H5VL_pass_through_ext_link_optional(void *obj, H5VL_link_optional_t opt_type, hid_t dxpl_id, void **req, va_list arguments);

/* Object callbacks */
static void *H5VL_pass_through_ext_object_open(void *obj, const H5VL_loc_params_t *loc_params, H5I_type_t *opened_type, hid_t dxpl_id, void **req);
static herr_t H5VL_pass_through_ext_object_copy(void *src_obj, const H5VL_loc_params_t *src_loc_params, const char *src_name, void *dst_obj, const H5VL_loc_params_t *dst_loc_params, const char *dst_name, hid_t ocpypl_id, hid_t lcpl_id, hid_t dxpl_id, void **req);
static herr_t H5VL_pass_through_ext_object_get(void *obj, const H5VL_loc_params_t *loc_params, H5VL_object_get_t get_type, hid_t dxpl_id, void **req, va_list arguments);
static herr_t H5VL_pass_through_ext_object_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_object_specific_t specific_type, hid_t dxpl_id, void **req, va_list arguments);
static herr_t H5VL_pass_through_ext_object_optional(void *obj, H5VL_object_optional_t opt_type, hid_t dxpl_id, void **req, va_list arguments);

/* Container/connector introspection callbacks */
static herr_t H5VL_pass_through_ext_introspect_get_conn_cls(void *obj, H5VL_get_conn_lvl_t lvl, const H5VL_class_t **conn_cls);
static herr_t H5VL_pass_through_ext_introspect_opt_query(void *obj, H5VL_subclass_t cls, int opt_type, hbool_t *supported);

/* Async request callbacks */
static herr_t H5VL_pass_through_ext_request_wait(void *req, uint64_t timeout, H5ES_status_t *status);
static herr_t H5VL_pass_through_ext_request_notify(void *obj, H5VL_request_notify_t cb, void *ctx);
static herr_t H5VL_pass_through_ext_request_cancel(void *req);
static herr_t H5VL_pass_through_ext_request_specific(void *req, H5VL_request_specific_t specific_type, va_list arguments);
static herr_t H5VL_pass_through_ext_request_optional(void *req, H5VL_request_optional_t opt_type, va_list arguments);
static herr_t H5VL_pass_through_ext_request_free(void *req);

/* Blob callbacks */
static herr_t H5VL_pass_through_ext_blob_put(void *obj, const void *buf, size_t size, void *blob_id, void *ctx);
static herr_t H5VL_pass_through_ext_blob_get(void *obj, const void *blob_id, void *buf, size_t size, void *ctx);
static herr_t H5VL_pass_through_ext_blob_specific(void *obj, void *blob_id, H5VL_blob_specific_t specific_type, va_list arguments);
static herr_t H5VL_pass_through_ext_blob_optional(void *obj, void *blob_id, H5VL_blob_optional_t opt_type, va_list arguments);

/* Token callbacks */
static herr_t H5VL_pass_through_ext_token_cmp(void *obj, const H5O_token_t *token1, const H5O_token_t *token2, int *cmp_value);
static herr_t H5VL_pass_through_ext_token_to_str(void *obj, H5I_type_t obj_type, const H5O_token_t *token, char **token_str);
static herr_t H5VL_pass_through_ext_token_from_str(void *obj, H5I_type_t obj_type, const char *token_str, H5O_token_t *token);

/* Generic optional callback */
static herr_t H5VL_pass_through_ext_optional(void *obj, int op_type, hid_t dxpl_id, void **req, va_list arguments);

/*******************/
/* Local variables */
/*******************/

/* Pass through VOL connector class struct */
static const H5VL_class_t H5VL_pass_through_ext_g = {
    H5VL_PASSTHRU_EXT_VERSION,                          /* version      */
    (H5VL_class_value_t)H5VL_PASSTHRU_EXT_VALUE,        /* value        */
    H5VL_PASSTHRU_EXT_NAME,                             /* name         */
    0,                                              /* capability flags */
    H5VL_pass_through_ext_init,                         /* initialize   */
    H5VL_pass_through_ext_term,                         /* terminate    */
    {                                           /* info_cls */
        sizeof(H5VL_pass_through_ext_info_t),           /* size    */
        H5VL_pass_through_ext_info_copy,                /* copy    */
        H5VL_pass_through_ext_info_cmp,                 /* compare */
        H5VL_pass_through_ext_info_free,                /* free    */
        H5VL_pass_through_ext_info_to_str,              /* to_str  */
        H5VL_pass_through_ext_str_to_info               /* from_str */
    },
    {                                           /* wrap_cls */
        H5VL_pass_through_ext_get_object,               /* get_object   */
        H5VL_pass_through_ext_get_wrap_ctx,             /* get_wrap_ctx */
        H5VL_pass_through_ext_wrap_object,              /* wrap_object  */
        H5VL_pass_through_ext_unwrap_object,            /* unwrap_object */
        H5VL_pass_through_ext_free_wrap_ctx             /* free_wrap_ctx */
    },
    {                                           /* attribute_cls */
        H5VL_pass_through_ext_attr_create,              /* create */
        H5VL_pass_through_ext_attr_open,                /* open */
        H5VL_pass_through_ext_attr_read,                /* read */
        H5VL_pass_through_ext_attr_write,               /* write */
        H5VL_pass_through_ext_attr_get,                 /* get */
        H5VL_pass_through_ext_attr_specific,            /* specific */
        H5VL_pass_through_ext_attr_optional,            /* optional */
        H5VL_pass_through_ext_attr_close                /* close */
    },
    {                                           /* dataset_cls */
        H5VL_pass_through_ext_dataset_create,           /* create */
        H5VL_pass_through_ext_dataset_open,             /* open */
        H5VL_pass_through_ext_dataset_read,             /* read */
        H5VL_pass_through_ext_dataset_write,            /* write */
        H5VL_pass_through_ext_dataset_get,              /* get */
        H5VL_pass_through_ext_dataset_specific,         /* specific */
        H5VL_pass_through_ext_dataset_optional,         /* optional */
        H5VL_pass_through_ext_dataset_close             /* close */
    },
    {                                           /* datatype_cls */
        H5VL_pass_through_ext_datatype_commit,          /* commit */
        H5VL_pass_through_ext_datatype_open,            /* open */
        H5VL_pass_through_ext_datatype_get,             /* get_size */
        H5VL_pass_through_ext_datatype_specific,        /* specific */
        H5VL_pass_through_ext_datatype_optional,        /* optional */
        H5VL_pass_through_ext_datatype_close            /* close */
    },
    {                                           /* file_cls */
        H5VL_pass_through_ext_file_create,              /* create */
        H5VL_pass_through_ext_file_open,                /* open */
        H5VL_pass_through_ext_file_get,                 /* get */
        H5VL_pass_through_ext_file_specific,            /* specific */
        H5VL_pass_through_ext_file_optional,            /* optional */
        H5VL_pass_through_ext_file_close                /* close */
    },
    {                                           /* group_cls */
        H5VL_pass_through_ext_group_create,             /* create */
        H5VL_pass_through_ext_group_open,               /* open */
        H5VL_pass_through_ext_group_get,                /* get */
        H5VL_pass_through_ext_group_specific,           /* specific */
        H5VL_pass_through_ext_group_optional,           /* optional */
        H5VL_pass_through_ext_group_close               /* close */
    },
    {                                           /* link_cls */
        H5VL_pass_through_ext_link_create,              /* create */
        H5VL_pass_through_ext_link_copy,                /* copy */
        H5VL_pass_through_ext_link_move,                /* move */
        H5VL_pass_through_ext_link_get,                 /* get */
        H5VL_pass_through_ext_link_specific,            /* specific */
        H5VL_pass_through_ext_link_optional             /* optional */
    },
    {                                           /* object_cls */
        H5VL_pass_through_ext_object_open,              /* open */
        H5VL_pass_through_ext_object_copy,              /* copy */
        H5VL_pass_through_ext_object_get,               /* get */
        H5VL_pass_through_ext_object_specific,          /* specific */
        H5VL_pass_through_ext_object_optional           /* optional */
    },
    {                                           /* introspect_cls */
        H5VL_pass_through_ext_introspect_get_conn_cls,  /* get_conn_cls */
        H5VL_pass_through_ext_introspect_opt_query,     /* opt_query */
    },
    {                                           /* request_cls */
        H5VL_pass_through_ext_request_wait,             /* wait */
        H5VL_pass_through_ext_request_notify,           /* notify */
        H5VL_pass_through_ext_request_cancel,           /* cancel */
        H5VL_pass_through_ext_request_specific,         /* specific */
        H5VL_pass_through_ext_request_optional,         /* optional */
        H5VL_pass_through_ext_request_free              /* free */
    },
    {                                           /* blob_cls */
        H5VL_pass_through_ext_blob_put,                 /* put */
        H5VL_pass_through_ext_blob_get,                 /* get */
        H5VL_pass_through_ext_blob_specific,            /* specific */
        H5VL_pass_through_ext_blob_optional             /* optional */
    },
    {                                           /* token_cls */
        H5VL_pass_through_ext_token_cmp,                /* cmp */
        H5VL_pass_through_ext_token_to_str,             /* to_str */
        H5VL_pass_through_ext_token_from_str              /* from_str */
    },
    H5VL_pass_through_ext_optional                  /* optional */
};

/* The connector identification number, initialized at runtime */
static hid_t H5VL_PASSTHRU_EXT_g = H5I_INVALID_HID;
H5PL_type_t H5PLget_plugin_type(void) {return H5PL_TYPE_VOL;}
const void *H5PLget_plugin_info(void) {return &H5VL_pass_through_ext_g;}

/*-------------------------------------------------------------------------
 * Function:    H5VL__pass_through_new_obj
 *
 * Purpose:     Create a new pass through object for an underlying object
 *
 * Return:      Success:    Pointer to the new pass through object
 *              Failure:    NULL
 *
 * Programmer:  Quincey Koziol
 *              Monday, December 3, 2018
 *
 *-------------------------------------------------------------------------
 */
static H5VL_pass_through_ext_t *
H5VL_pass_through_ext_new_obj(void *under_obj, hid_t under_vol_id)
{
    H5VL_pass_through_ext_t *new_obj;

    new_obj = (H5VL_pass_through_ext_t *)calloc(1, sizeof(H5VL_pass_through_ext_t));
    new_obj->under_object = under_obj;
    new_obj->under_vol_id = under_vol_id;
    H5Iinc_ref(new_obj->under_vol_id);

    return new_obj;
} /* end H5VL__pass_through_new_obj() */


/*-------------------------------------------------------------------------
 * Function:    H5VL__pass_through_free_obj
 *
 * Purpose:     Release a pass through object
 *
 * Note:	Take care to preserve the current HDF5 error stack
 *		when calling HDF5 API calls.
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 * Programmer:  Quincey Koziol
 *              Monday, December 3, 2018
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_free_obj(H5VL_pass_through_ext_t *obj)
{
    hid_t err_id;

    err_id = H5Eget_current_stack();

    H5Idec_ref(obj->under_vol_id);

    H5Eset_current_stack(err_id);

    free(obj);

    return 0;
} /* end H5VL__pass_through_free_obj() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_register
 *
 * Purpose:     Register the pass-through VOL connector and retrieve an ID
 *              for it.
 *
 * Return:      Success:    The ID for the pass-through VOL connector
 *              Failure:    -1
 *
 * Programmer:  Quincey Koziol
 *              Wednesday, November 28, 2018
 *
 *-------------------------------------------------------------------------
 */
hid_t
H5VL_pass_through_ext_register(void)
{
    /* Singleton register the pass-through VOL connector ID */
    if(H5VL_PASSTHRU_EXT_g < 0)
        H5VL_PASSTHRU_EXT_g = H5VLregister_connector(&H5VL_pass_through_ext_g, H5P_DEFAULT);

    return H5VL_PASSTHRU_EXT_g;
} /* end H5VL_pass_through_ext_register() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_init
 *
 * Purpose:     Initialize this VOL connector, performing any necessary
 *              operations for the connector that will apply to all containers
 *              accessed with the connector.
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_init(hid_t vipl_id)
{
Huihuo Zheng's avatar
Huihuo Zheng committed
443
444
445
  int rank; 
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  if (rank==io_node()) printf("%s:%d: Pass_through VOL is called.\n", __func__, __LINE__);
Huihuo Zheng's avatar
ssd_vol    
Huihuo Zheng committed
446
#ifdef ENABLE_EXT_PASSTHRU_LOGGING
Huihuo Zheng's avatar
Huihuo Zheng committed
447
  if (rank==io_node()) printf("------- EXT PASS THROUGH VOL INIT\n");
Huihuo Zheng's avatar
ssd_vol    
Huihuo Zheng committed
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
#endif

    /* Shut compiler up about unused parameter */
    vipl_id = vipl_id;

    return 0;
} /* end H5VL_pass_through_ext_init() */


/*---------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_term
 *
 * Purpose:     Terminate this VOL connector, performing any necessary
 *              operations for the connector that release connector-wide
 *              resources (usually created / initialized with the 'init'
 *              callback).
 *
 * Return:      Success:    0
 *              Failure:    (Can't fail)
 *
 *---------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_term(void)
{
#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL TERM\n");
#endif

    /* Reset VOL ID */
    H5VL_PASSTHRU_EXT_g = H5I_INVALID_HID;

    return 0;
} /* end H5VL_pass_through_ext_term() */


/*---------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_info_copy
 *
 * Purpose:     Duplicate the connector's info object.
 *
 * Returns:     Success:    New connector info object
 *              Failure:    NULL
 *
 *---------------------------------------------------------------------------
 */
static void *
H5VL_pass_through_ext_info_copy(const void *_info)
{
    const H5VL_pass_through_ext_info_t *info = (const H5VL_pass_through_ext_info_t *)_info;
    H5VL_pass_through_ext_info_t *new_info;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL INFO Copy\n");
#endif

    /* Allocate new VOL info struct for the pass through connector */
    new_info = (H5VL_pass_through_ext_info_t *)calloc(1, sizeof(H5VL_pass_through_ext_info_t));

    /* Increment reference count on underlying VOL ID, and copy the VOL info */
    new_info->under_vol_id = info->under_vol_id;
    H5Iinc_ref(new_info->under_vol_id);
    if(info->under_vol_info)
        H5VLcopy_connector_info(new_info->under_vol_id, &(new_info->under_vol_info), info->under_vol_info);

    return new_info;
} /* end H5VL_pass_through_ext_info_copy() */


/*---------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_info_cmp
 *
 * Purpose:     Compare two of the connector's info objects, setting *cmp_value,
 *              following the same rules as strcmp().
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 *---------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_info_cmp(int *cmp_value, const void *_info1, const void *_info2)
{
    const H5VL_pass_through_ext_info_t *info1 = (const H5VL_pass_through_ext_info_t *)_info1;
    const H5VL_pass_through_ext_info_t *info2 = (const H5VL_pass_through_ext_info_t *)_info2;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL INFO Compare\n");
#endif

    /* Sanity checks */
    assert(info1);
    assert(info2);

    /* Initialize comparison value */
    *cmp_value = 0;

    /* Compare under VOL connector classes */
    H5VLcmp_connector_cls(cmp_value, info1->under_vol_id, info2->under_vol_id);
    if(*cmp_value != 0)
        return 0;

    /* Compare under VOL connector info objects */
    H5VLcmp_connector_info(cmp_value, info1->under_vol_id, info1->under_vol_info, info2->under_vol_info);
    if(*cmp_value != 0)
        return 0;

    return 0;
} /* end H5VL_pass_through_ext_info_cmp() */


/*---------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_info_free
 *
 * Purpose:     Release an info object for the connector.
 *
 * Note:	Take care to preserve the current HDF5 error stack
 *		when calling HDF5 API calls.
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 *---------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_info_free(void *_info)
{
    H5VL_pass_through_ext_info_t *info = (H5VL_pass_through_ext_info_t *)_info;
    hid_t err_id;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL INFO Free\n");
#endif

    err_id = H5Eget_current_stack();

    /* Release underlying VOL ID and info */
    if(info->under_vol_info)
        H5VLfree_connector_info(info->under_vol_id, info->under_vol_info);
    H5Idec_ref(info->under_vol_id);

    H5Eset_current_stack(err_id);

    /* Free pass through info object itself */
    free(info);

    return 0;
} /* end H5VL_pass_through_ext_info_free() */


/*---------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_info_to_str
 *
 * Purpose:     Serialize an info object for this connector into a string
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 *---------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_info_to_str(const void *_info, char **str)
{
    const H5VL_pass_through_ext_info_t *info = (const H5VL_pass_through_ext_info_t *)_info;
    H5VL_class_value_t under_value = (H5VL_class_value_t)-1;
    char *under_vol_string = NULL;
    size_t under_vol_str_len = 0;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL INFO To String\n");
#endif

    /* Get value and string for underlying VOL connector */
    H5VLget_value(info->under_vol_id, &under_value);
    H5VLconnector_info_to_str(info->under_vol_info, info->under_vol_id, &under_vol_string);

    /* Determine length of underlying VOL info string */
    if(under_vol_string)
        under_vol_str_len = strlen(under_vol_string);

    /* Allocate space for our info */
    *str = (char *)H5allocate_memory(32 + under_vol_str_len, (hbool_t)0);
    assert(*str);

    /* Encode our info
     * Normally we'd use snprintf() here for a little extra safety, but that
     * call had problems on Windows until recently. So, to be as platform-independent
     * as we can, we're using sprintf() instead.
     */
    sprintf(*str, "under_vol=%u;under_info={%s}", (unsigned)under_value, (under_vol_string ? under_vol_string : ""));

    return 0;
} /* end H5VL_pass_through_ext_info_to_str() */


/*---------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_str_to_info
 *
 * Purpose:     Deserialize a string into an info object for this connector.
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 *---------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_str_to_info(const char *str, void **_info)
{
    H5VL_pass_through_ext_info_t *info;
    unsigned under_vol_value;
    const char *under_vol_info_start, *under_vol_info_end;
    hid_t under_vol_id;
    void *under_vol_info = NULL;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL INFO String To Info\n");
#endif

    /* Retrieve the underlying VOL connector value and info */
    sscanf(str, "under_vol=%u;", &under_vol_value);
    under_vol_id = H5VLregister_connector_by_value((H5VL_class_value_t)under_vol_value, H5P_DEFAULT);
    under_vol_info_start = strchr(str, '{');
    under_vol_info_end = strrchr(str, '}');
    assert(under_vol_info_end > under_vol_info_start);
    if(under_vol_info_end != (under_vol_info_start + 1)) {
        char *under_vol_info_str;

        under_vol_info_str = (char *)malloc((size_t)(under_vol_info_end - under_vol_info_start));
        memcpy(under_vol_info_str, under_vol_info_start + 1, (size_t)((under_vol_info_end - under_vol_info_start) - 1));
        *(under_vol_info_str + (under_vol_info_end - under_vol_info_start)) = '\0';

        H5VLconnector_str_to_info(under_vol_info_str, under_vol_id, &under_vol_info);

        free(under_vol_info_str);
    } /* end else */

    /* Allocate new pass-through VOL connector info and set its fields */
    info = (H5VL_pass_through_ext_info_t *)calloc(1, sizeof(H5VL_pass_through_ext_info_t));
    info->under_vol_id = under_vol_id;
    info->under_vol_info = under_vol_info;

    /* Set return value */
    *_info = info;

    return 0;
} /* end H5VL_pass_through_ext_str_to_info() */


/*---------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_get_object
 *
 * Purpose:     Retrieve the 'data' for a VOL object.
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 *---------------------------------------------------------------------------
 */
static void *
H5VL_pass_through_ext_get_object(const void *obj)
{
    const H5VL_pass_through_ext_t *o = (const H5VL_pass_through_ext_t *)obj;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL Get object\n");
#endif

    return H5VLget_object(o->under_object, o->under_vol_id);
} /* end H5VL_pass_through_ext_get_object() */


/*---------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_get_wrap_ctx
 *
 * Purpose:     Retrieve a "wrapper context" for an object
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 *---------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_get_wrap_ctx(const void *obj, void **wrap_ctx)
{
    const H5VL_pass_through_ext_t *o = (const H5VL_pass_through_ext_t *)obj;
    H5VL_pass_through_ext_wrap_ctx_t *new_wrap_ctx;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL WRAP CTX Get\n");
#endif

    /* Allocate new VOL object wrapping context for the pass through connector */
    new_wrap_ctx = (H5VL_pass_through_ext_wrap_ctx_t *)calloc(1, sizeof(H5VL_pass_through_ext_wrap_ctx_t));

    /* Increment reference count on underlying VOL ID, and copy the VOL info */
    new_wrap_ctx->under_vol_id = o->under_vol_id;
    H5Iinc_ref(new_wrap_ctx->under_vol_id);
    H5VLget_wrap_ctx(o->under_object, o->under_vol_id, &new_wrap_ctx->under_wrap_ctx);

    /* Set wrap context to return */
    *wrap_ctx = new_wrap_ctx;

    return 0;
} /* end H5VL_pass_through_ext_get_wrap_ctx() */


/*---------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_wrap_object
 *
 * Purpose:     Use a "wrapper context" to wrap a data object
 *
 * Return:      Success:    Pointer to wrapped object
 *              Failure:    NULL
 *
 *---------------------------------------------------------------------------
 */
static void *
H5VL_pass_through_ext_wrap_object(void *obj, H5I_type_t obj_type, void *_wrap_ctx)
{
    H5VL_pass_through_ext_wrap_ctx_t *wrap_ctx = (H5VL_pass_through_ext_wrap_ctx_t *)_wrap_ctx;
    H5VL_pass_through_ext_t *new_obj;
    void *under;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL WRAP Object\n");
#endif

    /* Wrap the object with the underlying VOL */
    under = H5VLwrap_object(obj, obj_type, wrap_ctx->under_vol_id, wrap_ctx->under_wrap_ctx);
    if(under)
        new_obj = H5VL_pass_through_ext_new_obj(under, wrap_ctx->under_vol_id);
    else
        new_obj = NULL;

    return new_obj;
} /* end H5VL_pass_through_ext_wrap_object() */


/*---------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_unwrap_object
 *
 * Purpose:     Unwrap a wrapped object, discarding the wrapper, but returning
 *		underlying object.
 *
 * Return:      Success:    Pointer to unwrapped object
 *              Failure:    NULL
 *
 *---------------------------------------------------------------------------
 */
static void *
H5VL_pass_through_ext_unwrap_object(void *obj)
{
    H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)obj;
    void *under;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL UNWRAP Object\n");
#endif

    /* Unrap the object with the underlying VOL */
    under = H5VLunwrap_object(o->under_object, o->under_vol_id);

    if(under)
        H5VL_pass_through_ext_free_obj(o);

    return under;
} /* end H5VL_pass_through_ext_unwrap_object() */


/*---------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_free_wrap_ctx
 *
 * Purpose:     Release a "wrapper context" for an object
 *
 * Note:	Take care to preserve the current HDF5 error stack
 *		when calling HDF5 API calls.
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 *---------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_free_wrap_ctx(void *_wrap_ctx)
{
    H5VL_pass_through_ext_wrap_ctx_t *wrap_ctx = (H5VL_pass_through_ext_wrap_ctx_t *)_wrap_ctx;
    hid_t err_id;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL WRAP CTX Free\n");
#endif

    err_id = H5Eget_current_stack();

    /* Release underlying VOL ID and wrap context */
    if(wrap_ctx->under_wrap_ctx)
        H5VLfree_wrap_ctx(wrap_ctx->under_wrap_ctx, wrap_ctx->under_vol_id);
    H5Idec_ref(wrap_ctx->under_vol_id);

    H5Eset_current_stack(err_id);

    /* Free pass through wrap context object itself */
    free(wrap_ctx);

    return 0;
} /* end H5VL_pass_through_ext_free_wrap_ctx() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_attr_create
 *
 * Purpose:     Creates an attribute on an object.
 *
 * Return:      Success:    Pointer to attribute object
 *              Failure:    NULL
 *
 *-------------------------------------------------------------------------
 */
static void *
H5VL_pass_through_ext_attr_create(void *obj, const H5VL_loc_params_t *loc_params,
    const char *name, hid_t type_id, hid_t space_id, hid_t acpl_id,
    hid_t aapl_id, hid_t dxpl_id, void **req)
{
    H5VL_pass_through_ext_t *attr;
    H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)obj;
    void *under;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL ATTRIBUTE Create\n");
#endif

    under = H5VLattr_create(o->under_object, loc_params, o->under_vol_id, name, type_id, space_id, acpl_id, aapl_id, dxpl_id, req);
    if(under) {
        attr = H5VL_pass_through_ext_new_obj(under, o->under_vol_id);

        /* Check for async request */
        if(req && *req)
            *req = H5VL_pass_through_ext_new_obj(*req, o->under_vol_id);
    } /* end if */
    else
        attr = NULL;

    return (void*)attr;
} /* end H5VL_pass_through_ext_attr_create() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_attr_open
 *
 * Purpose:     Opens an attribute on an object.
 *
 * Return:      Success:    Pointer to attribute object
 *              Failure:    NULL
 *
 *-------------------------------------------------------------------------
 */
static void *
H5VL_pass_through_ext_attr_open(void *obj, const H5VL_loc_params_t *loc_params,
    const char *name, hid_t aapl_id, hid_t dxpl_id, void **req)
{
    H5VL_pass_through_ext_t *attr;
    H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)obj;
    void *under;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL ATTRIBUTE Open\n");
#endif

    under = H5VLattr_open(o->under_object, loc_params, o->under_vol_id, name, aapl_id, dxpl_id, req);
    if(under) {
        attr = H5VL_pass_through_ext_new_obj(under, o->under_vol_id);

        /* Check for async request */
        if(req && *req)
            *req = H5VL_pass_through_ext_new_obj(*req, o->under_vol_id);
    } /* end if */
    else
        attr = NULL;

    return (void *)attr;
} /* end H5VL_pass_through_ext_attr_open() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_attr_read
 *
 * Purpose:     Reads data from attribute.
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_attr_read(void *attr, hid_t mem_type_id, void *buf,
    hid_t dxpl_id, void **req)
{
    H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)attr;
    herr_t ret_value;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL ATTRIBUTE Read\n");
#endif

    ret_value = H5VLattr_read(o->under_object, o->under_vol_id, mem_type_id, buf, dxpl_id, req);

    /* Check for async request */
    if(req && *req)
        *req = H5VL_pass_through_ext_new_obj(*req, o->under_vol_id);

    return ret_value;
} /* end H5VL_pass_through_ext_attr_read() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_attr_write
 *
 * Purpose:     Writes data to attribute.
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_attr_write(void *attr, hid_t mem_type_id, const void *buf,
    hid_t dxpl_id, void **req)
{
    H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)attr;
    herr_t ret_value;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL ATTRIBUTE Write\n");
#endif

    ret_value = H5VLattr_write(o->under_object, o->under_vol_id, mem_type_id, buf, dxpl_id, req);

    /* Check for async request */
    if(req && *req)
        *req = H5VL_pass_through_ext_new_obj(*req, o->under_vol_id);

    return ret_value;
} /* end H5VL_pass_through_ext_attr_write() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_attr_get
 *
 * Purpose:     Gets information about an attribute
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_attr_get(void *obj, H5VL_attr_get_t get_type, hid_t dxpl_id,
    void **req, va_list arguments)
{
    H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)obj;
    herr_t ret_value;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL ATTRIBUTE Get\n");
#endif

    ret_value = H5VLattr_get(o->under_object, o->under_vol_id, get_type, dxpl_id, req, arguments);

    /* Check for async request */
    if(req && *req)
        *req = H5VL_pass_through_ext_new_obj(*req, o->under_vol_id);

    return ret_value;
} /* end H5VL_pass_through_ext_attr_get() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_attr_specific
 *
 * Purpose:     Specific operation on attribute
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_attr_specific(void *obj, const H5VL_loc_params_t *loc_params,
    H5VL_attr_specific_t specific_type, hid_t dxpl_id, void **req, va_list arguments)
{
    H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)obj;
    herr_t ret_value;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL ATTRIBUTE Specific\n");
#endif

    ret_value = H5VLattr_specific(o->under_object, loc_params, o->under_vol_id, specific_type, dxpl_id, req, arguments);

    /* Check for async request */
    if(req && *req)
        *req = H5VL_pass_through_ext_new_obj(*req, o->under_vol_id);

    return ret_value;
} /* end H5VL_pass_through_ext_attr_specific() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_attr_optional
 *
 * Purpose:     Perform a connector-specific operation on an attribute
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_attr_optional(void *obj, H5VL_attr_optional_t opt_type,
    hid_t dxpl_id, void **req, va_list arguments)
{
    H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)obj;
    herr_t ret_value;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL ATTRIBUTE Optional\n");
#endif

    ret_value = H5VLattr_optional(o->under_object, o->under_vol_id, opt_type, dxpl_id, req, arguments);

    /* Check for async request */
    if(req && *req)
        *req = H5VL_pass_through_ext_new_obj(*req, o->under_vol_id);

    return ret_value;
} /* end H5VL_pass_through_ext_attr_optional() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_attr_close
 *
 * Purpose:     Closes an attribute.
 *
 * Return:      Success:    0
 *              Failure:    -1, attr not closed.
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_attr_close(void *attr, hid_t dxpl_id, void **req)
{
    H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)attr;
    herr_t ret_value;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL ATTRIBUTE Close\n");
#endif

    ret_value = H5VLattr_close(o->under_object, o->under_vol_id, dxpl_id, req);

    /* Check for async request */
    if(req && *req)
        *req = H5VL_pass_through_ext_new_obj(*req, o->under_vol_id);

    /* Release our wrapper, if underlying attribute was closed */
    if(ret_value >= 0)
        H5VL_pass_through_ext_free_obj(o);

    return ret_value;
} /* end H5VL_pass_through_ext_attr_close() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_dataset_create
 *
 * Purpose:     Creates a dataset in a container
 *
 * Return:      Success:    Pointer to a dataset object
 *              Failure:    NULL
 *
 *-------------------------------------------------------------------------
 */
static void *
H5VL_pass_through_ext_dataset_create(void *obj, const H5VL_loc_params_t *loc_params,
    const char *name, hid_t lcpl_id, hid_t type_id, hid_t space_id,
    hid_t dcpl_id, hid_t dapl_id, hid_t dxpl_id, void **req)
{
    H5VL_pass_through_ext_t *dset;
    H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)obj;
    void *under;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL DATASET Create\n");
#endif

    under = H5VLdataset_create(o->under_object, loc_params, o->under_vol_id, name, lcpl_id, type_id, space_id, dcpl_id,  dapl_id, dxpl_id, req);
    if(under) {
        dset = H5VL_pass_through_ext_new_obj(under, o->under_vol_id);

        /* Check for async request */
        if(req && *req)
            *req = H5VL_pass_through_ext_new_obj(*req, o->under_vol_id);
    } /* end if */
    else
        dset = NULL;
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
1153
1154
1155
    if (o->write_cache) {
      dset->H5DWMM = o->H5DWMM;
      dset->write_cache = o->write_cache;
Huihuo Zheng's avatar
Huihuo Zheng committed
1156
      dset->num_request_dataset = 0;
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
1157
    }
Huihuo Zheng's avatar
ssd_vol    
Huihuo Zheng committed
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
    return (void *)dset;
} /* end H5VL_pass_through_ext_dataset_create() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_dataset_open
 *
 * Purpose:     Opens a dataset in a container
 *
 * Return:      Success:    Pointer to a dataset object
 *              Failure:    NULL
 *
 *-------------------------------------------------------------------------
 */
static void *
H5VL_pass_through_ext_dataset_open(void *obj, const H5VL_loc_params_t *loc_params,
    const char *name, hid_t dapl_id, hid_t dxpl_id, void **req)
{
    H5VL_pass_through_ext_t *dset;
    H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)obj;
    void *under;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL DATASET Open\n");
#endif

    under = H5VLdataset_open(o->under_object, loc_params, o->under_vol_id, name, dapl_id, dxpl_id, req);
    if(under) {
        dset = H5VL_pass_through_ext_new_obj(under, o->under_vol_id);

        /* Check for async request */
        if(req && *req)
            *req = H5VL_pass_through_ext_new_obj(*req, o->under_vol_id);
    } /* end if */
    else
        dset = NULL;
Huihuo Zheng's avatar
theta    
Huihuo Zheng committed
1194

Huihuo Zheng's avatar
ssd_vol    
Huihuo Zheng committed
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
    return (void *)dset;
} /* end H5VL_pass_through_ext_dataset_open() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_dataset_read
 *
 * Purpose:     Reads data elements from a dataset into a buffer.
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_dataset_read(void *dset, hid_t mem_type_id, hid_t mem_space_id,
    hid_t file_space_id, hid_t plist_id, void *buf, void **req)
{
    H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)dset;
    herr_t ret_value;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL DATASET Read\n");
#endif

    ret_value = H5VLdataset_read(o->under_object, o->under_vol_id, mem_type_id, mem_space_id, file_space_id, plist_id, buf, req);

    /* Check for async request */
    if(req && *req)
        *req = H5VL_pass_through_ext_new_obj(*req, o->under_vol_id);

    return ret_value;
} /* end H5VL_pass_through_ext_dataset_read() */

Huihuo Zheng's avatar
write    
Huihuo Zheng committed
1229
1230
1231
1232
1233
1234


void *H5Dwrite_pthread_func_vol(void *arg) {
  // this is to us the H5DWMM as an input
  H5Dwrite_cache_metadata *wmm = (H5Dwrite_cache_metadata*) arg;
  pthread_mutex_lock(&wmm->io.request_lock);
Huihuo Zheng's avatar
Huihuo Zheng committed
1235
  bool loop = (wmm->io.num_request>=0);
Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
1236
  bool empty = (wmm->io.num_request==0);
Huihuo Zheng's avatar
Huihuo Zheng committed
1237
1238
  pthread_mutex_unlock(&wmm->io.request_lock);  
  while (loop) {
Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
1239
1240
    if (!empty) {
      thread_data_t *task = wmm->io.current_request;
Huihuo Zheng's avatar
Huihuo Zheng committed
1241

Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
1242
1243
1244
1245
1246
      if (wmm->mpi.rank== io_node() && debug_level()>1) {
	printf("\n===================================\n");
	printf("pthread: Executing I/O task %d\n", task->id);
      }
      task->buf = mmap(NULL, task->size, PROT_READ, MAP_SHARED, wmm->mmap.fd, task->offset);
Huihuo Zheng's avatar
Huihuo Zheng committed
1247
      msync(task->buf, task->size, MS_SYNC);
Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
1248
1249
      H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)task->dataset_obj;
      hbool_t acquired=false;
Huihuo Zheng's avatar
Huihuo Zheng committed
1250
1251
      while(!acquired)
	H5TSmutex_acquire(&acquired);
Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
1252
1253
      if (wmm->mpi.rank== io_node() && debug_level()>1) printf("pthread: acquired global mutex\n");
      H5VLrestore_lib_state(task->h5_state);
Huihuo Zheng's avatar
fixed    
Huihuo Zheng committed
1254
      void **req;
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
1255
#ifdef THETA
Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
1256
1257
      wmm->mmap.tmp_buf = malloc(task->size);
      memcpy(wmm->mmap.tmp_buf, task->buf, task->size);
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
1258
      H5VLdataset_write(o->under_object, o->under_vol_id,
Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
1259
1260
			task->mem_type_id, task->mem_space_id,
			task->file_space_id, task->xfer_plist_id,
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
1261
1262
1263
1264
			wmm->mmap.tmp_buf, req);
      free(wmm->mmap.tmp_buf);
#else
      H5VLdataset_write(o->under_object, o->under_vol_id,
Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
1265
1266
1267
			task->mem_type_id, task->mem_space_id,
			task->file_space_id, task->xfer_plist_id,
			task->buf, req);
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
1268
#endif
Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
1269
1270
1271
1272
1273
1274
      if (wmm->mpi.rank==io_node() && debug_level()>1) printf("pthread: I/O task %d is done!\n", task->id);
      munmap(task->buf, task->size);
      H5Sclose(task->mem_space_id);
      H5Sclose(task->file_space_id);
      H5Pclose(task->xfer_plist_id);
      H5Tclose(task->mem_type_id);
1275
      H5VLreset_lib_state();
Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
1276
      H5VLfree_lib_state(task->h5_state);
Huihuo Zheng's avatar
Huihuo Zheng committed
1277
      H5TSmutex_release();
Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
1278
1279
1280
1281
1282
      if (wmm->mpi.rank==io_node() && debug_level()>1) printf("pthread: global mutex_released\n");
      if (wmm->mpi.rank== io_node() && debug_level()>1) {
	printf("===================================\n");
      }
      pthread_mutex_lock(&wmm->io.request_lock);
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
1283
1284
      wmm->io.current_request=wmm->io.current_request->next;
      wmm->io.num_request--;
Huihuo Zheng's avatar
Huihuo Zheng committed
1285
      o->num_request_dataset--;
Huihuo Zheng's avatar
test    
Huihuo Zheng committed
1286
      pthread_mutex_unlock(&wmm->io.request_lock);
Huihuo Zheng's avatar
Huihuo Zheng committed
1287
1288
1289
    }
    pthread_mutex_lock(&wmm->io.request_lock);
    loop = (wmm->io.num_request>=0);
Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
1290
    empty = (wmm->io.num_request==0);
Huihuo Zheng's avatar
Huihuo Zheng committed
1291
    pthread_mutex_unlock(&wmm->io.request_lock);  
Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
1292
    if (empty) {
Huihuo Zheng's avatar
Huihuo Zheng committed
1293
      pthread_mutex_lock(&wmm->io.request_lock);
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
1294
1295
      pthread_cond_signal(&wmm->io.master_cond);
      pthread_cond_wait(&wmm->io.io_cond, &wmm->io.request_lock);
Huihuo Zheng's avatar
Huihuo Zheng committed
1296
      pthread_mutex_unlock(&wmm->io.request_lock);  
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
1297
    }
Huihuo Zheng's avatar
hellp    
Huihuo Zheng committed
1298
1299
    pthread_mutex_lock(&wmm->io.request_lock);
    loop = (wmm->io.num_request>=0);
Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
1300
    empty = (wmm->io.num_request==0);
Huihuo Zheng's avatar
hellp    
Huihuo Zheng committed
1301
    pthread_mutex_unlock(&wmm->io.request_lock);  
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
1302
1303
1304
1305
  }
  return NULL; 
}

Huihuo Zheng's avatar
ssd_vol    
Huihuo Zheng committed
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316

/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_dataset_write
 *
 * Purpose:     Writes data elements from a buffer into a dataset.
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 *-------------------------------------------------------------------------
 */
Huihuo Zheng's avatar
Huihuo Zheng committed
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
herr_t H5Ssel_gather_write(hid_t space, hid_t tid, const void *buf, int fd, hsize_t offset) {
  unsigned flags;
  size_t elmt_size =  H5Tget_size(tid);
  hid_t iter = H5Ssel_iter_create(space, elmt_size, flags);
  size_t maxseq = H5Sget_select_npoints(space);
  size_t maxbytes = maxseq*elmt_size;
  size_t nseq, nbytes;
  size_t *len = (size_t*)malloc(maxseq*sizeof(size_t));
  hsize_t *off = (hsize_t*)malloc(maxseq*sizeof(hsize_t));
  H5Ssel_iter_get_seq_list(iter, maxseq, maxbytes, &nseq, &nbytes, off, len);
Huihuo Zheng's avatar
Huihuo Zheng committed
1327
1328
  hsize_t off_contig=0;
  char *p = (char*) buf; 
Huihuo Zheng's avatar
Huihuo Zheng committed
1329
1330
1331
1332
  //double t = 0.0; 
  //double w = 0.0; 
  //MPI_Barrier(MPI_COMM_WORLD);
  //double t1 = MPI_Wtime();
Huihuo Zheng's avatar
Huihuo Zheng committed
1333
  for(int i=0; i<nseq; i++) {
Huihuo Zheng's avatar
Huihuo Zheng committed
1334
    //w += len[i];
Huihuo Zheng's avatar
Huihuo Zheng committed
1335
1336
    int err = pwrite(fd, &p[off[i]], len[i], offset+off_contig);
    off_contig += len[i];
Huihuo Zheng's avatar
Huihuo Zheng committed
1337
  }
Huihuo Zheng's avatar
Huihuo Zheng committed
1338
  fsync(fd);
Huihuo Zheng's avatar
Huihuo Zheng committed
1339
1340
1341
1342
1343
1344
  //MPI_Barrier(MPI_COMM_WORLD);
  //t += MPI_Wtime() - t1; 
  //double wt; 
  //w = w/t/1024/1024;
  //MPI_Allreduce(&w, &wt, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
  //printf("wt: %f\n", wt);
Huihuo Zheng's avatar
Huihuo Zheng committed
1345
1346
1347
  return 0;
}

Huihuo Zheng's avatar
ssd_vol    
Huihuo Zheng committed
1348
1349
1350
1351
1352
1353
1354
1355
1356
static herr_t
H5VL_pass_through_ext_dataset_write(void *dset, hid_t mem_type_id, hid_t mem_space_id,
    hid_t file_space_id, hid_t plist_id, const void *buf, void **req)
{
    H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)dset;
    herr_t ret_value;
#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL DATASET Write\n");
#endif
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
1357
1358
    if (o->write_cache) {
      hsize_t size = get_buf_size(mem_space_id, mem_type_id);
Huihuo Zheng's avatar
Huihuo Zheng committed
1359
      H5TSmutex_release();
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
1360
1361
1362
1363
1364
1365
      if (o->H5DWMM->ssd->mspace_per_rank_left < size) {
	pthread_mutex_lock(&o->H5DWMM->io.request_lock);
	while(o->H5DWMM->io.num_request>0)  {
	  pthread_cond_signal(&o->H5DWMM->io.io_cond);
	  pthread_cond_wait(&o->H5DWMM->io.master_cond, &o->H5DWMM->io.request_lock);
	}
Huihuo Zheng's avatar
Huihuo Zheng committed
1366
	pthread_mutex_unlock(&o->H5DWMM->io.request_lock);
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
1367
1368
1369
1370
	o->H5DWMM->ssd->offset = 0;
	o->H5DWMM->ssd->mspace_per_rank_left = o->H5DWMM->ssd->mspace_per_rank_total;
	o->H5DWMM->ssd->mspace_left = o->H5DWMM->ssd->mspace_total; 
      }
Huihuo Zheng's avatar
Huihuo Zheng committed
1371
      //MPI_Barrier(o->H5DWMM->mpi.comm);
Huihuo Zheng's avatar
Huihuo Zheng committed
1372
      H5Ssel_gather_write(mem_space_id, mem_type_id, buf, o->H5DWMM->mmap.fd, o->H5DWMM->ssd->offset);
Huihuo Zheng's avatar
Huihuo Zheng committed
1373
      //MPI_Barrier(o->H5DWMM->mpi.comm);
Huihuo Zheng's avatar
Huihuo Zheng committed
1374
1375
1376
1377
      o->H5DWMM->io.request_list->offset = o->H5DWMM->ssd->offset; 
      o->H5DWMM->ssd->offset += (size/PAGESIZE+1)*PAGESIZE;
      o->H5DWMM->ssd->mspace_per_rank_left = o->H5DWMM->ssd->mspace_per_rank_total
	- o->H5DWMM->ssd->offset*o->H5DWMM->mpi.ppn;
Huihuo Zheng's avatar
ssd_vol    
Huihuo Zheng committed
1378
#ifdef __APPLE__
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
1379
      fcntl(o->H5DWMM->mmap.fd, F_NOCACHE, 1);
Huihuo Zheng's avatar
ssd_vol    
Huihuo Zheng committed
1380
#else
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
1381
      fsync(o->H5DWMM->mmap.fd);
Huihuo Zheng's avatar
ssd_vol    
Huihuo Zheng committed
1382
#endif
Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
1383
1384
      o->H5DWMM->io.request_list->dataset_obj = dset; 
      // retrieve current library state;
1385
      H5VLretrieve_lib_state(&o->H5DWMM->io.request_list->h5_state);
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
1386
      o->H5DWMM->io.request_list->mem_type_id = H5Tcopy(mem_type_id);
Huihuo Zheng's avatar
Huihuo Zheng committed
1387
1388
      hsize_t ldims[1] = {H5Sget_select_npoints(mem_space_id)};
      o->H5DWMM->io.request_list->mem_space_id = H5Screate_simple(1, ldims, NULL);
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
1389
1390
1391
1392
      o->H5DWMM->io.request_list->file_space_id = H5Scopy(file_space_id);
      o->H5DWMM->io.request_list->xfer_plist_id = H5Pcopy(plist_id);
      o->H5DWMM->io.request_list->size = size; 
      o->H5DWMM->io.request_list->next = (thread_data_t*) malloc(sizeof(thread_data_t));
Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
1393
      if (o->H5DWMM->mpi.rank==io_node() && debug_level()>1) printf("added task %d to the list;\n", o->H5DWMM->io.request_list->id);
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
1394
1395
      o->H5DWMM->io.request_list->next->id = o->H5DWMM->io.request_list->id + 1;
      o->H5DWMM->io.request_list = o->H5DWMM->io.request_list->next;
Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
1396
      // waken up the Background thread
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
1397
1398
      pthread_mutex_lock(&o->H5DWMM->io.request_lock);
      o->H5DWMM->io.num_request++;
Huihuo Zheng's avatar
Huihuo Zheng committed
1399
      o->num_request_dataset++;
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
1400
1401
      pthread_cond_signal(&o->H5DWMM->io.io_cond);// wake up I/O thread rightawayx
      pthread_mutex_unlock(&o->H5DWMM->io.request_lock);
Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
1402
      //
Huihuo Zheng's avatar
test    
Huihuo Zheng committed
1403
      ret_value=SUCCEED;
Huihuo Zheng's avatar
Huihuo Zheng committed
1404
1405
1406
      hbool_t acq=false;
      while(!acq)
	H5TSmutex_acquire(&acq);
Huihuo Zheng's avatar
Huihuo Zheng committed
1407
1408
    } else {
      ret_value = H5VLdataset_write(o->under_object, o->under_vol_id, mem_type_id, mem_space_id, file_space_id, plist_id, buf, req);
Huihuo Zheng's avatar
test    
Huihuo Zheng committed
1409
1410
      if(req && *req)
        *req = H5VL_pass_through_ext_new_obj(*req, o->under_vol_id);
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
1411
    }
Huihuo Zheng's avatar
ssd_vol    
Huihuo Zheng committed
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
    /* Check for async request */
    return ret_value;
} /* end H5VL_pass_through_ext_dataset_write() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_dataset_get
 *
 * Purpose:     Gets information about a dataset
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_dataset_get(void *dset, H5VL_dataset_get_t get_type,
    hid_t dxpl_id, void **req, va_list arguments)
{
    H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)dset;
    herr_t ret_value;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL DATASET Get\n");
#endif

    ret_value = H5VLdataset_get(o->under_object, o->under_vol_id, get_type, dxpl_id, req, arguments);

    /* Check for async request */
    if(req && *req)
        *req = H5VL_pass_through_ext_new_obj(*req, o->under_vol_id);

    return ret_value;
} /* end H5VL_pass_through_ext_dataset_get() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_dataset_specific
 *
 * Purpose:     Specific operation on a dataset
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_dataset_specific(void *obj, H5VL_dataset_specific_t specific_type,
    hid_t dxpl_id, void **req, va_list arguments)
{
    H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)obj;
    hid_t under_vol_id;
    herr_t ret_value;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL H5Dspecific\n");
#endif

    // Save copy of underlying VOL connector ID and prov helper, in case of
    // refresh destroying the current object
    under_vol_id = o->under_vol_id;

    ret_value = H5VLdataset_specific(o->under_object, o->under_vol_id, specific_type, dxpl_id, req, arguments);

    /* Check for async request */
    if(req && *req)
        *req = H5VL_pass_through_ext_new_obj(*req, under_vol_id);

    return ret_value;
} /* end H5VL_pass_through_ext_dataset_specific() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_dataset_optional
 *
 * Purpose:     Perform a connector-specific operation on a dataset
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_dataset_optional(void *obj, H5VL_dataset_optional_t opt_type,
    hid_t dxpl_id, void **req, va_list arguments)
{
    H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)obj;
    herr_t ret_value;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL DATASET Optional\n");
#endif

    ret_value = H5VLdataset_optional(o->under_object, o->under_vol_id, opt_type, dxpl_id, req, arguments);

    /* Check for async request */
    if(req && *req)
        *req = H5VL_pass_through_ext_new_obj(*req, o->under_vol_id);

    return ret_value;
} /* end H5VL_pass_through_ext_dataset_optional() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_dataset_close
 *
 * Purpose:     Closes a dataset.
 *
 * Return:      Success:    0
 *              Failure:    -1, dataset not closed.
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_dataset_close(void *dset, hid_t dxpl_id, void **req)
{
    H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)dset;
    herr_t ret_value;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL DATASET Close\n");
#endif
Huihuo Zheng's avatar
Huihuo Zheng committed
1534

Huihuo Zheng's avatar
Huihuo Zheng committed
1535
    if (o->write_cache) {
Huihuo Zheng's avatar
Huihuo Zheng committed
1536
      H5TSmutex_release();
Huihuo Zheng's avatar
Huihuo Zheng committed
1537
      pthread_mutex_lock(&o->H5DWMM->io.request_lock);
Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
1538
      while(o->num_request_dataset>0) {
Huihuo Zheng's avatar
Huihuo Zheng committed
1539
1540
1541
1542
	pthread_cond_signal(&o->H5DWMM->io.io_cond);
	pthread_cond_wait(&o->H5DWMM->io.master_cond, &o->H5DWMM->io.request_lock);
      }
      pthread_mutex_unlock(&o->H5DWMM->io.request_lock);
Huihuo Zheng's avatar
Huihuo Zheng committed
1543
1544
1545
      hbool_t acq=false; 
      while(!acq)
	H5TSmutex_acquire(&acq);
Huihuo Zheng's avatar
Huihuo Zheng committed
1546
    }
Huihuo Zheng's avatar
Huihuo Zheng committed
1547

Huihuo Zheng's avatar
ssd_vol    
Huihuo Zheng committed
1548
    ret_value = H5VLdataset_close(o->under_object, o->under_vol_id, dxpl_id, req);
Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
1549
    
Huihuo Zheng's avatar
ssd_vol    
Huihuo Zheng committed
1550
1551
1552
1553
1554
    /* Check for async request */
    if(req && *req)
        *req = H5VL_pass_through_ext_new_obj(*req, o->under_vol_id);

    /* Release our wrapper, if underlying dataset was closed */
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
1555
1556
    if(ret_value >= 0) 
      H5VL_pass_through_ext_free_obj(o);
Huihuo Zheng's avatar
ssd_vol    
Huihuo Zheng committed
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
    return ret_value;
} /* end H5VL_pass_through_ext_dataset_close() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_datatype_commit
 *
 * Purpose:     Commits a datatype inside a container.
 *
 * Return:      Success:    Pointer to datatype object
 *              Failure:    NULL
 *
 *-------------------------------------------------------------------------
 */
static void *
H5VL_pass_through_ext_datatype_commit(void *obj, const H5VL_loc_params_t *loc_params,
    const char *name, hid_t type_id, hid_t lcpl_id, hid_t tcpl_id, hid_t tapl_id,
    hid_t dxpl_id, void **req)
{
    H5VL_pass_through_ext_t *dt;
    H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)obj;
    void *under;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL DATATYPE Commit\n");
#endif

    under = H5VLdatatype_commit(o->under_object, loc_params, o->under_vol_id, name, type_id, lcpl_id, tcpl_id, tapl_id, dxpl_id, req);
    if(under) {
        dt = H5VL_pass_through_ext_new_obj(under, o->under_vol_id);

        /* Check for async request */
        if(req && *req)
            *req = H5VL_pass_through_ext_new_obj(*req, o->under_vol_id);
    } /* end if */
    else
        dt = NULL;

    return (void *)dt;
} /* end H5VL_pass_through_ext_datatype_commit() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_datatype_open
 *
 * Purpose:     Opens a named datatype inside a container.
 *
 * Return:      Success:    Pointer to datatype object
 *              Failure:    NULL
 *
 *-------------------------------------------------------------------------
 */
static void *
H5VL_pass_through_ext_datatype_open(void *obj, const H5VL_loc_params_t *loc_params,
    const char *name, hid_t tapl_id, hid_t dxpl_id, void **req)
{
    H5VL_pass_through_ext_t *dt;
    H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)obj;
    void *under;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL DATATYPE Open\n");
#endif

    under = H5VLdatatype_open(o->under_object, loc_params, o->under_vol_id, name, tapl_id, dxpl_id, req);
    if(under) {
        dt = H5VL_pass_through_ext_new_obj(under, o->under_vol_id);

        /* Check for async request */
        if(req && *req)
            *req = H5VL_pass_through_ext_new_obj(*req, o->under_vol_id);
    } /* end if */
    else
        dt = NULL;

    return (void *)dt;
} /* end H5VL_pass_through_ext_datatype_open() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_datatype_get
 *
 * Purpose:     Get information about a datatype
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_datatype_get(void *dt, H5VL_datatype_get_t get_type,
    hid_t dxpl_id, void **req, va_list arguments)
{
    H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)dt;
    herr_t ret_value;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL DATATYPE Get\n");
#endif

    ret_value = H5VLdatatype_get(o->under_object, o->under_vol_id, get_type, dxpl_id, req, arguments);

    /* Check for async request */
    if(req && *req)
        *req = H5VL_pass_through_ext_new_obj(*req, o->under_vol_id);

    return ret_value;
} /* end H5VL_pass_through_ext_datatype_get() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_datatype_specific
 *
 * Purpose:     Specific operations for datatypes
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_datatype_specific(void *obj, H5VL_datatype_specific_t specific_type,
    hid_t dxpl_id, void **req, va_list arguments)
{
    H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)obj;
    hid_t under_vol_id;
    herr_t ret_value;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL DATATYPE Specific\n");
#endif

    // Save copy of underlying VOL connector ID and prov helper, in case of
    // refresh destroying the current object
    under_vol_id = o->under_vol_id;

    ret_value = H5VLdatatype_specific(o->under_object, o->under_vol_id, specific_type, dxpl_id, req, arguments);

    /* Check for async request */
    if(req && *req)
        *req = H5VL_pass_through_ext_new_obj(*req, under_vol_id);

    return ret_value;
} /* end H5VL_pass_through_ext_datatype_specific() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_datatype_optional
 *
 * Purpose:     Perform a connector-specific operation on a datatype
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_datatype_optional(void *obj, H5VL_datatype_optional_t opt_type,
    hid_t dxpl_id, void **req, va_list arguments)
{
    H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)obj;
    herr_t ret_value;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL DATATYPE Optional\n");
#endif

    ret_value = H5VLdatatype_optional(o->under_object, o->under_vol_id, opt_type, dxpl_id, req, arguments);

    /* Check for async request */
    if(req && *req)
        *req = H5VL_pass_through_ext_new_obj(*req, o->under_vol_id);

    return ret_value;
} /* end H5VL_pass_through_ext_datatype_optional() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_datatype_close
 *
 * Purpose:     Closes a datatype.
 *
 * Return:      Success:    0
 *              Failure:    -1, datatype not closed.
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_datatype_close(void *dt, hid_t dxpl_id, void **req)
{
    H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)dt;
    herr_t ret_value;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL DATATYPE Close\n");
#endif

    assert(o->under_object);

    ret_value = H5VLdatatype_close(o->under_object, o->under_vol_id, dxpl_id, req);

    /* Check for async request */
    if(req && *req)
        *req = H5VL_pass_through_ext_new_obj(*req, o->under_vol_id);

    /* Release our wrapper, if underlying datatype was closed */
    if(ret_value >= 0)
        H5VL_pass_through_ext_free_obj(o);

    return ret_value;
} /* end H5VL_pass_through_ext_datatype_close() */

Huihuo Zheng's avatar
Huihuo Zheng committed
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
char *get_fname(const char *path) {
  char *ssc;
  int l = 0;
  char *pp = (char *) malloc(255); 
  strcpy(pp, path);
  ssc = strstr(pp, "/");
  do {
    l = strlen(ssc) + 1;
    pp= &pp[strlen(path)-l+2];
    ssc = strstr(pp, "/");
  } while(ssc);
  return pp; 
}

Huihuo Zheng's avatar
ssd_vol    
Huihuo Zheng committed
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830

/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_file_create
 *
 * Purpose:     Creates a container using this connector
 *
 * Return:      Success:    Pointer to a file object
 *              Failure:    NULL
 *
 *-------------------------------------------------------------------------
 */
static void *
H5VL_pass_through_ext_file_create(const char *name, unsigned flags, hid_t fcpl_id,
    hid_t fapl_id, hid_t dxpl_id, void **req)
{
    H5VL_pass_through_ext_info_t *info;
    H5VL_pass_through_ext_t *file;
    hid_t under_fapl_id;
    void *under;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL FILE Create\n");
#endif
    /* Get copy of our VOL info from FAPL */
    H5Pget_vol_info(fapl_id, (void **)&info);

    /* Make sure we have info about the underlying VOL to be used */
    if (!info)
        return NULL;

    /* Copy the FAPL */
    under_fapl_id = H5Pcopy(fapl_id);

    /* Set the VOL ID and info for the underlying FAPL */
    H5Pset_vol(under_fapl_id, info->under_vol_id, info->under_vol_info);

    /* Open the file with the underlying VOL connector */
    under = H5VLfile_create(name, flags, fcpl_id, under_fapl_id, dxpl_id, req);

    if(under) {
        file = H5VL_pass_through_ext_new_obj(under, info->under_vol_id);

        /* Check for async request */
        if(req && *req)
            *req = H5VL_pass_through_ext_new_obj(*req, info->under_vol_id);
    } /* end if */
    else
        file = NULL;
Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
1831
1832
1833
1834
1835
    
    file->write_cache = true;
    if (getenv("SSD_CACHE"))
      if (strcmp(getenv("SSD_CACHE"), "no")==0)
	file->write_cache=false;
Huihuo Zheng's avatar
test    
Huihuo Zheng committed
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
    if (file->write_cache) {
      srand(time(NULL));   // Initialization, should only be called once.
      file->H5DWMM = (H5Dwrite_cache_metadata*) malloc(sizeof(H5Dwrite_cache_metadata));
      file->H5DWMM->io.num_request = 0; 
      pthread_cond_init(&file->H5DWMM->io.io_cond, NULL);
      pthread_cond_init(&file->H5DWMM->io.master_cond, NULL);
      pthread_mutex_init(&file->H5DWMM->io.request_lock, NULL);
      setH5SSD(&SSD);
      file->H5DWMM->ssd = &SSD;
      MPI_Comm comm, comm_dup;
      MPI_Info mpi_info;
      H5Pget_fapl_mpio(fapl_id, &comm, &mpi_info);
      MPI_Comm_dup(comm, &file->H5DWMM->mpi.comm);
      MPI_Comm_rank(comm, &file->H5DWMM->mpi.rank);
      MPI_Comm_size(comm, &file->H5DWMM->mpi.nproc);
      MPI_Comm_split_type(file->H5DWMM->mpi.comm, MPI_COMM_TYPE_SHARED, 0, MPI_INFO_NULL, &file->H5DWMM->mpi.node_comm);
      MPI_Comm_rank(file->H5DWMM->mpi.node_comm, &file->H5DWMM->mpi.local_rank);
      MPI_Comm_size(file->H5DWMM->mpi.node_comm, &file->H5DWMM->mpi.ppn);
      strcpy(file->H5DWMM->mmap.fname, file->H5DWMM->ssd->path);
Huihuo Zheng's avatar
Huihuo Zheng committed
1855
1856
      strcat(file->H5DWMM->mmap.fname, "/cache-");
      //strcat(file->H5DWMM->mmap.fname, get_fname(name));
Huihuo Zheng's avatar
test    
Huihuo Zheng committed
1857
1858
1859
1860
1861
1862
      char rnd[255];
      sprintf(rnd, "%d", rand());
      strcat(file->H5DWMM->mmap.fname, rnd);
      strcat(file->H5DWMM->mmap.fname, "-"); 
      sprintf(rnd, "%d", file->H5DWMM->mpi.rank);
      strcat(file->H5DWMM->mmap.fname, rnd);
Huihuo Zheng's avatar
Huihuo Zheng committed
1863
      strcat(file->H5DWMM->mmap.fname, "_mmapf.dat");
Huihuo Zheng's avatar
test    
Huihuo Zheng committed
1864
1865
1866
      file->H5DWMM->io.request_list = (thread_data_t*) malloc(sizeof(thread_data_t)); 
      file->H5DWMM->ssd->mspace_per_rank_total = file->H5DWMM->ssd->mspace_total / file->H5DWMM->mpi.ppn;
      file->H5DWMM->ssd->mspace_per_rank_left = file->H5DWMM->ssd->mspace_per_rank_total;
Huihuo Zheng's avatar
Huihuo Zheng committed
1867
      if (debug_level()>1 && io_node()==file->H5DWMM->mpi.rank) {
Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
1868
1869
	printf("**Using node local storage as a cache\n");
	printf("**path: %s\n", file->H5DWMM->ssd->path);
Huihuo Zheng's avatar
Huihuo Zheng committed
1870
	printf("**fname: %20s\n", file->H5DWMM->mmap.fname);
Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
1871
      }
Huihuo Zheng's avatar
test    
Huihuo Zheng committed
1872
1873
1874
1875
1876
1877
1878
      file->H5DWMM->mmap.fd = open(file->H5DWMM->mmap.fname, O_RDWR | O_CREAT | O_TRUNC, 0644);
      int rc = pthread_create(&file->H5DWMM->io.pthread, NULL, H5Dwrite_pthread_func_vol, file->H5DWMM);
      pthread_mutex_lock(&file->H5DWMM->io.request_lock);
      file->H5DWMM->io.request_list->id = 0; 
      file->H5DWMM->io.current_request = file->H5DWMM->io.request_list; 
      file->H5DWMM->io.first_request = file->H5DWMM->io.request_list; 
      pthread_mutex_unlock(&file->H5DWMM->io.request_lock);
Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
1879
      
Huihuo Zheng's avatar
test    
Huihuo Zheng committed
1880
    }
Huihuo Zheng's avatar
debug    
Huihuo Zheng committed
1881
1882
1883
1884
1885
    /* Close underlying FAPL */
    H5Pclose(under_fapl_id);

    /* Release copy of our VOL info */
    H5VL_pass_through_ext_info_free(info);
Huihuo Zheng's avatar
ssd_vol    
Huihuo Zheng committed
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
    return (void *)file;
} /* end H5VL_pass_through_ext_file_create() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_file_open
 *
 * Purpose:     Opens a container created with this connector
 *
 * Return:      Success:    Pointer to a file object
 *              Failure:    NULL
 *
 *-------------------------------------------------------------------------
 */
static void *
H5VL_pass_through_ext_file_open(const char *name, unsigned flags, hid_t fapl_id,
    hid_t dxpl_id, void **req)
{
    H5VL_pass_through_ext_info_t *info;
    H5VL_pass_through_ext_t *file;
    hid_t under_fapl_id;
    void *under;
    printf("%s:%d: Pass_through VOL is called.\n", __func__, __LINE__);
#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL FILE Open\n");
#endif

    /* Get copy of our VOL info from FAPL */
    H5Pget_vol_info(fapl_id, (void **)&info);

    /* Make sure we have info about the underlying VOL to be used */
    if (!info)
        return NULL;

    /* Copy the FAPL */
    under_fapl_id = H5Pcopy(fapl_id);

    /* Set the VOL ID and info for the underlying FAPL */
    H5Pset_vol(under_fapl_id, info->under_vol_id, info->under_vol_info);

    /* Open the file with the underlying VOL connector */
    under = H5VLfile_open(name, flags, under_fapl_id, dxpl_id, req);
    if(under) {
        file = H5VL_pass_through_ext_new_obj(under, info->under_vol_id);

        /* Check for async request */
        if(req && *req)
            *req = H5VL_pass_through_ext_new_obj(*req, info->under_vol_id);
    } /* end if */
    else
        file = NULL;

    /* Close underlying FAPL */
    H5Pclose(under_fapl_id);
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
1940
    
Huihuo Zheng's avatar
ssd_vol    
Huihuo Zheng committed
1941
    H5VL_pass_through_ext_info_free(info);
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
1942

Huihuo Zheng's avatar
Huihuo Zheng committed
1943
1944
1945
    if (getenv("SSD_CACHE")) {
      file->read_cache = true;
    }
Huihuo Zheng's avatar
ssd_vol    
Huihuo Zheng committed
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
    return (void *)file;
} /* end H5VL_pass_through_ext_file_open() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_file_get
 *
 * Purpose:     Get info about a file
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_file_get(void *file, H5VL_file_get_t get_type, hid_t dxpl_id,
    void **req, va_list arguments)
{
    H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)file;
    herr_t ret_value;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL FILE Get\n");
#endif

    ret_value = H5VLfile_get(o->under_object, o->under_vol_id, get_type, dxpl_id, req, arguments);

    /* Check for async request */
    if(req && *req)
        *req = H5VL_pass_through_ext_new_obj(*req, o->under_vol_id);

    return ret_value;
} /* end H5VL_pass_through_ext_file_get() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_file_specific_reissue
 *
 * Purpose:     Re-wrap vararg arguments into a va_list and reissue the
 *              file specific callback to the underlying VOL connector.
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_file_specific_reissue(void *obj, hid_t connector_id,
    H5VL_file_specific_t specific_type, hid_t dxpl_id, void **req, ...)
{
    va_list arguments;
    herr_t ret_value;

    va_start(arguments, req);
    ret_value = H5VLfile_specific(obj, connector_id, specific_type, dxpl_id, req, arguments);
    va_end(arguments);

    return ret_value;
} /* end H5VL_pass_through_ext_file_specific_reissue() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_file_specific
 *
 * Purpose:     Specific operation on file
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_file_specific(void *file, H5VL_file_specific_t specific_type,
    hid_t dxpl_id, void **req, va_list arguments)
{
    H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)file;
    hid_t under_vol_id = -1;
    herr_t ret_value;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL FILE Specific\n");
#endif

    /* Unpack arguments to get at the child file pointer when mounting a file */
    if(specific_type == H5VL_FILE_MOUNT) {
        H5I_type_t loc_type;
        const char *name;
        H5VL_pass_through_ext_t *child_file;
        hid_t plist_id;

        /* Retrieve parameters for 'mount' operation, so we can unwrap the child file */
        loc_type = (H5I_type_t)va_arg(arguments, int); /* enum work-around */
        name = va_arg(arguments, const char *);
        child_file = (H5VL_pass_through_ext_t *)va_arg(arguments, void *);
        plist_id = va_arg(arguments, hid_t);

        /* Keep the correct underlying VOL ID for possible async request token */
        under_vol_id = o->under_vol_id;

        /* Re-issue 'file specific' call, using the unwrapped pieces */
        ret_value = H5VL_pass_through_ext_file_specific_reissue(o->under_object, o->under_vol_id, specific_type, dxpl_id, req, (int)loc_type, name, child_file->under_object, plist_id);
    } /* end if */
    else if(specific_type == H5VL_FILE_IS_ACCESSIBLE || specific_type == H5VL_FILE_DELETE) {
        H5VL_pass_through_ext_info_t *info;
        hid_t fapl_id, under_fapl_id;
        const char *name;
        htri_t *ret;

        /* Get the arguments for the 'is accessible' check */
        fapl_id = va_arg(arguments, hid_t);
        name    = va_arg(arguments, const char *);
        ret     = va_arg(arguments, htri_t *);

        /* Get copy of our VOL info from FAPL */
        H5Pget_vol_info(fapl_id, (void **)&info);

        /* Make sure we have info about the underlying VOL to be used */
        if (!info)
            return (-1);

        /* Copy the FAPL */
        under_fapl_id = H5Pcopy(fapl_id);

        /* Set the VOL ID and info for the underlying FAPL */
        H5Pset_vol(under_fapl_id, info->under_vol_id, info->under_vol_info);

        /* Keep the correct underlying VOL ID for possible async request token */
        under_vol_id = info->under_vol_id;

        /* Re-issue 'file specific' call */
        ret_value = H5VL_pass_through_ext_file_specific_reissue(NULL, info->under_vol_id, specific_type, dxpl_id, req, under_fapl_id, name, ret);

        /* Close underlying FAPL */
        H5Pclose(under_fapl_id);

        /* Release copy of our VOL info */
        H5VL_pass_through_ext_info_free(info);
    } /* end else-if */
    else {
        va_list my_arguments;

        /* Make a copy of the argument list for later, if reopening */
        if(specific_type == H5VL_FILE_REOPEN)
            va_copy(my_arguments, arguments);

        /* Keep the correct underlying VOL ID for possible async request token */
        under_vol_id = o->under_vol_id;

        ret_value = H5VLfile_specific(o->under_object, o->under_vol_id, specific_type, dxpl_id, req, arguments);

        /* Wrap file struct pointer, if we reopened one */
        if(specific_type == H5VL_FILE_REOPEN) {
            if(ret_value >= 0) {
                void      **ret = va_arg(my_arguments, void **);

                if(ret && *ret)
                    *ret = H5VL_pass_through_ext_new_obj(*ret, o->under_vol_id);
            } /* end if */

            /* Finish use of copied vararg list */
            va_end(my_arguments);
        } /* end if */
    } /* end else */

    /* Check for async request */
    if(req && *req)
        *req = H5VL_pass_through_ext_new_obj(*req, under_vol_id);

    return ret_value;
} /* end H5VL_pass_through_ext_file_specific() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_file_optional
 *
 * Purpose:     Perform a connector-specific operation on a file
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_file_optional(void *file, H5VL_file_optional_t opt_type,
    hid_t dxpl_id, void **req, va_list arguments)
{
    H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)file;
    herr_t ret_value;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL File Optional\n");
#endif

    ret_value = H5VLfile_optional(o->under_object, o->under_vol_id, opt_type, dxpl_id, req, arguments);

    /* Check for async request */
    if(req && *req)
        *req = H5VL_pass_through_ext_new_obj(*req, o->under_vol_id);

    return ret_value;
} /* end H5VL_pass_through_ext_file_optional() */


/*-------------------------------------------------------------------------
 * Function:    H5VL_pass_through_ext_file_close
 *
 * Purpose:     Closes a file.
 *
 * Return:      Success:    0
 *              Failure:    -1, file not closed.
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5VL_pass_through_ext_file_close(void *file, hid_t dxpl_id, void **req)
{
    H5VL_pass_through_ext_t *o = (H5VL_pass_through_ext_t *)file;
    herr_t ret_value;

#ifdef ENABLE_EXT_PASSTHRU_LOGGING
    printf("------- EXT PASS THROUGH VOL FILE Close\n");
#endif
Huihuo Zheng's avatar
Huihuo Zheng committed
2168
    
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
2169
    if (o->write_cache) {
Huihuo Zheng's avatar
Huihuo Zheng committed
2170
      H5TSmutex_release();
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
2171
      pthread_mutex_lock(&o->H5DWMM->io.request_lock);
Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
2172
      bool empty = (o->H5DWMM->io.num_request>0);
Huihuo Zheng's avatar
hellp    
Huihuo Zheng committed
2173
      pthread_mutex_unlock(&o->H5DWMM->io.request_lock);
Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
2174
      while(!empty)  {
Huihuo Zheng's avatar
hellp    
Huihuo Zheng committed
2175
	pthread_mutex_lock(&o->H5DWMM->io.request_lock);
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
2176
2177
	pthread_cond_signal(&o->H5DWMM->io.io_cond);
	pthread_cond_wait(&o->H5DWMM->io.master_cond, &o->H5DWMM->io.request_lock);
Huihuo Zheng's avatar
SSD    
Huihuo Zheng committed
2178
	empty = (o->H5DWMM->io.num_request==0);
Huihuo Zheng's avatar
hellp    
Huihuo Zheng committed
2179
	pthread_mutex_unlock(&o->H5DWMM->io.request_lock);
Huihuo Zheng's avatar
write    
Huihuo Zheng committed
2180
2181
2182
2183
2184
      }
      pthread_mutex_lock(&o->H5DWMM->io.request_lock);
      o->H5DWMM->io.num_request=-1;
      pthread_cond_signal(&o->H5DWMM->io.io_cond);
      pthread_mutex_unlock(&o->H5DWMM->io