/src/hdf5/src/H5VLnative_dataset.c
Line | Count | Source |
1 | | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
2 | | * Copyright by The HDF Group. * |
3 | | * All rights reserved. * |
4 | | * * |
5 | | * This file is part of HDF5. The full HDF5 copyright notice, including * |
6 | | * terms governing use, modification, and redistribution, is contained in * |
7 | | * the LICENSE file, which can be found at the root of the source code * |
8 | | * distribution tree, or in https://www.hdfgroup.org/licenses. * |
9 | | * If you do not have access to either file, you may request a copy from * |
10 | | * help@hdfgroup.org. * |
11 | | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
12 | | |
13 | | /* |
14 | | * Purpose: Dataset callbacks for the native VOL connector |
15 | | * |
16 | | */ |
17 | | |
18 | | /****************/ |
19 | | /* Module Setup */ |
20 | | /****************/ |
21 | | |
22 | | #define H5D_FRIEND /* Suppress error about including H5Dpkg */ |
23 | | |
24 | | /***********/ |
25 | | /* Headers */ |
26 | | /***********/ |
27 | | #include "H5private.h" /* Generic Functions */ |
28 | | #include "H5CXprivate.h" /* API Contexts */ |
29 | | #include "H5Dpkg.h" /* Datasets */ |
30 | | #include "H5Eprivate.h" /* Error handling */ |
31 | | #include "H5Fprivate.h" /* Files */ |
32 | | #include "H5Gprivate.h" /* Groups */ |
33 | | #include "H5Iprivate.h" /* IDs */ |
34 | | #include "H5MMprivate.h" /* Memory management */ |
35 | | #include "H5Pprivate.h" /* Property lists */ |
36 | | #include "H5Sprivate.h" /* Dataspaces */ |
37 | | #include "H5VLprivate.h" /* Virtual Object Layer */ |
38 | | |
39 | | #include "H5VLnative_private.h" /* Native VOL connector */ |
40 | | |
41 | | /****************/ |
42 | | /* Local Macros */ |
43 | | /****************/ |
44 | | |
45 | | /******************/ |
46 | | /* Local Typedefs */ |
47 | | /******************/ |
48 | | |
49 | | /********************/ |
50 | | /* Local Prototypes */ |
51 | | /********************/ |
52 | | |
53 | | /* Helper routines for read/write API calls */ |
54 | | static herr_t H5VL__native_dataset_io_setup(size_t count, void *obj[], hid_t mem_type_id[], |
55 | | hid_t mem_space_id[], hid_t file_space_id[], hid_t dxpl_id, |
56 | | H5_flexible_const_ptr_t buf[], H5D_dset_io_info_t *dinfo); |
57 | | static herr_t H5VL__native_dataset_io_cleanup(size_t count, hid_t mem_space_id[], hid_t file_space_id[], |
58 | | H5D_dset_io_info_t *dinfo); |
59 | | |
60 | | /*********************/ |
61 | | /* Package Variables */ |
62 | | /*********************/ |
63 | | |
64 | | /*****************************/ |
65 | | /* Library Private Variables */ |
66 | | /*****************************/ |
67 | | |
68 | | /*******************/ |
69 | | /* Local Variables */ |
70 | | /*******************/ |
71 | | |
72 | | /*------------------------------------------------------------------------- |
73 | | * Function: H5VL__native_dataset_io_setup |
74 | | * |
75 | | * Purpose: Set up file and memory dataspaces for dataset I/O operation |
76 | | * |
77 | | * Return: SUCCEED/FAIL |
78 | | * |
79 | | *------------------------------------------------------------------------- |
80 | | */ |
81 | | static herr_t |
82 | | H5VL__native_dataset_io_setup(size_t count, void *obj[], hid_t mem_type_id[], hid_t mem_space_id[], |
83 | | hid_t file_space_id[], hid_t dxpl_id, H5_flexible_const_ptr_t buf[], |
84 | | H5D_dset_io_info_t *dinfo) |
85 | 0 | { |
86 | 0 | H5F_shared_t *f_sh; |
87 | 0 | size_t i; |
88 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
89 | |
|
90 | 0 | FUNC_ENTER_PACKAGE |
91 | | |
92 | | /* Sanity checks */ |
93 | 0 | assert(dinfo); |
94 | | |
95 | | /* Get shared file */ |
96 | 0 | f_sh = H5F_SHARED(((H5D_t *)obj[0])->oloc.file); |
97 | | |
98 | | /* Iterate over datasets */ |
99 | 0 | for (i = 0; i < count; i++) { |
100 | | /* Initialize fields not set here to prevent use of uninitialized */ |
101 | 0 | memset(&dinfo[i].layout_ops, 0, sizeof(dinfo[i].layout_ops)); |
102 | 0 | memset(&dinfo[i].io_ops, 0, sizeof(dinfo[i].io_ops)); |
103 | 0 | memset(&dinfo[i].layout_io_info, 0, sizeof(dinfo[i].layout_io_info)); |
104 | 0 | memset(&dinfo[i].type_info, 0, sizeof(dinfo[i].type_info)); |
105 | 0 | dinfo[i].store = NULL; |
106 | 0 | dinfo[i].layout = NULL; |
107 | 0 | dinfo[i].nelmts = 0; |
108 | 0 | dinfo[i].skip_io = false; |
109 | | |
110 | | /* Set up dset */ |
111 | 0 | dinfo[i].dset = (H5D_t *)obj[i]; |
112 | 0 | assert(dinfo[i].dset); |
113 | | |
114 | | /* Check dataset's file pointer is valid */ |
115 | 0 | if (NULL == dinfo[i].dset->oloc.file) |
116 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "dataset is not associated with a file"); |
117 | 0 | if (f_sh != H5F_SHARED(dinfo[i].dset->oloc.file)) |
118 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_UNSUPPORTED, FAIL, |
119 | 0 | "different files detected in multi dataset I/O request"); |
120 | | |
121 | | /* Set up memory type */ |
122 | 0 | if (NULL == (dinfo[i].mem_type = (const H5T_t *)H5I_object_verify(mem_type_id[i], H5I_DATATYPE))) |
123 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_BADTYPE, FAIL, "invalid datatype"); |
124 | | |
125 | | /* Set up file dataspace */ |
126 | 0 | if (H5S_ALL == file_space_id[i]) |
127 | | /* Use dataspace for dataset */ |
128 | 0 | dinfo[i].file_space = dinfo[i].dset->shared->space; |
129 | 0 | else if (H5S_BLOCK == file_space_id[i]) |
130 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_BADTYPE, FAIL, "H5S_BLOCK is not allowed for file dataspace"); |
131 | 0 | else if (H5S_PLIST == file_space_id[i]) { |
132 | 0 | H5P_genplist_t *plist; /* Property list pointer */ |
133 | 0 | H5S_t *space; /* Dataspace to hold selection */ |
134 | | |
135 | | /* Get the plist structure */ |
136 | 0 | if (NULL == (plist = H5P_object_verify(dxpl_id, H5P_DATASET_XFER, true))) |
137 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_BADID, FAIL, "bad dataset transfer property list"); |
138 | | |
139 | | /* Get a pointer to the file space in the property list */ |
140 | 0 | if (H5P_peek(plist, H5D_XFER_DSET_IO_SEL_NAME, &space) < 0) |
141 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "error getting dataset I/O selection"); |
142 | | |
143 | | /* Use dataspace for dataset */ |
144 | 0 | dinfo[i].file_space = dinfo[i].dset->shared->space; |
145 | | |
146 | | /* Copy, but share, selection from property list to dataset's dataspace */ |
147 | 0 | if (H5S_SELECT_COPY(dinfo[i].file_space, space, true) < 0) |
148 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTCOPY, FAIL, "can't copy dataset I/O selection"); |
149 | 0 | } /* end else-if */ |
150 | 0 | else { |
151 | | /* Get the dataspace pointer */ |
152 | 0 | if (NULL == (dinfo[i].file_space = (H5S_t *)H5I_object_verify(file_space_id[i], H5I_DATASPACE))) |
153 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_BADTYPE, FAIL, "file_space_id is not a dataspace ID"); |
154 | 0 | } /* end else */ |
155 | | |
156 | | /* Get dataspace for memory buffer */ |
157 | 0 | if (H5S_ALL == mem_space_id[i]) |
158 | 0 | dinfo[i].mem_space = dinfo[i].file_space; |
159 | 0 | else if (H5S_BLOCK == mem_space_id[i]) { |
160 | 0 | hsize_t nelmts; /* # of selected elements in file */ |
161 | | |
162 | | /* Get the # of elements selected */ |
163 | 0 | nelmts = H5S_GET_SELECT_NPOINTS(dinfo[i].file_space); |
164 | | |
165 | | /* Check for any elements */ |
166 | 0 | if (nelmts > 0) { |
167 | | /* Create a 1-D dataspace of the same # of elements */ |
168 | 0 | if (NULL == (dinfo[i].mem_space = H5S_create_simple(1, &nelmts, NULL))) |
169 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTCREATE, FAIL, |
170 | 0 | "unable to create simple memory dataspace"); |
171 | 0 | } /* end if */ |
172 | 0 | else { |
173 | | /* Create a NULL dataspace of the same # of elements */ |
174 | 0 | if (NULL == (dinfo[i].mem_space = H5S_create(H5S_NULL))) |
175 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTCREATE, FAIL, "unable to create NULL memory dataspace"); |
176 | 0 | } /* end else */ |
177 | 0 | } /* end if */ |
178 | 0 | else if (H5S_PLIST == mem_space_id[i]) |
179 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_BADTYPE, FAIL, "H5S_PLIST is not allowed for memory dataspace"); |
180 | 0 | else { |
181 | | /* Get the dataspace pointer */ |
182 | 0 | if (NULL == (dinfo[i].mem_space = (H5S_t *)H5I_object_verify(mem_space_id[i], H5I_DATASPACE))) |
183 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "mem_space_id is not a dataspace ID"); |
184 | 0 | } /* end else */ |
185 | | |
186 | | /* Check for valid selections */ |
187 | 0 | if (H5S_SELECT_VALID(dinfo[i].file_space) != true) |
188 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, |
189 | 0 | "selection + offset not within extent for file dataspace"); |
190 | 0 | if (H5S_SELECT_VALID(dinfo[i].mem_space) != true) |
191 | 0 | HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, |
192 | 0 | "selection + offset not within extent for memory dataspace"); |
193 | | |
194 | | /* Set up buf */ |
195 | 0 | dinfo[i].buf = buf[i]; |
196 | 0 | } |
197 | | |
198 | 0 | done: |
199 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
200 | 0 | } /* end H5VL__native_dataset_io_setup() */ |
201 | | |
202 | | /*------------------------------------------------------------------------- |
203 | | * Function: H5VL__native_dataset_io_cleanup |
204 | | * |
205 | | * Purpose: Frees memory allocated by H5VL__native_dataset_io_setup() |
206 | | * |
207 | | * Return: SUCCEED/FAIL |
208 | | * |
209 | | *------------------------------------------------------------------------- |
210 | | */ |
211 | | static herr_t |
212 | | H5VL__native_dataset_io_cleanup(size_t count, hid_t mem_space_id[], hid_t file_space_id[], |
213 | | H5D_dset_io_info_t *dinfo) |
214 | 0 | { |
215 | 0 | size_t i; |
216 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
217 | |
|
218 | 0 | FUNC_ENTER_PACKAGE |
219 | | |
220 | | /* Sanity checks */ |
221 | 0 | assert(dinfo); |
222 | | |
223 | | /* Iterate over datasets */ |
224 | 0 | for (i = 0; i < count; i++) { |
225 | | /* Free memory dataspace if it was created. Use HDONE_ERROR in this function so we always |
226 | | * try to free everything we can. */ |
227 | 0 | if (H5S_BLOCK == mem_space_id[i] && dinfo[i].mem_space) |
228 | 0 | if (H5S_close(dinfo[i].mem_space) < 0) |
229 | 0 | HDONE_ERROR(H5E_DATASET, H5E_CANTRELEASE, FAIL, |
230 | 0 | "unable to release temporary memory dataspace for H5S_BLOCK"); |
231 | | |
232 | | /* Reset file dataspace selection if it was copied from the property list */ |
233 | 0 | if (H5S_PLIST == file_space_id[i] && dinfo[i].file_space) |
234 | 0 | if (H5S_select_all(dinfo[i].file_space, true) < 0) |
235 | 0 | HDONE_ERROR(H5E_DATASET, H5E_CANTRELEASE, FAIL, |
236 | 0 | "unable to release file dataspace selection for H5S_PLIST"); |
237 | 0 | } |
238 | |
|
239 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
240 | 0 | } /* end H5VL__native_dataset_io_cleanup() */ |
241 | | |
242 | | /*------------------------------------------------------------------------- |
243 | | * Function: H5VL__native_dataset_create |
244 | | * |
245 | | * Purpose: Handles the dataset create callback |
246 | | * |
247 | | * Return: Success: dataset pointer |
248 | | * Failure: NULL |
249 | | * |
250 | | *------------------------------------------------------------------------- |
251 | | */ |
252 | | void * |
253 | | H5VL__native_dataset_create(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t lcpl_id, |
254 | | hid_t type_id, hid_t space_id, hid_t dcpl_id, hid_t dapl_id, |
255 | | hid_t H5_ATTR_UNUSED dxpl_id, void H5_ATTR_UNUSED **req) |
256 | 0 | { |
257 | 0 | H5G_loc_t loc; /* Object location to insert dataset into */ |
258 | 0 | H5D_t *dset = NULL; /* New dataset's info */ |
259 | 0 | const H5S_t *space; /* Dataspace for dataset */ |
260 | 0 | void *ret_value; |
261 | |
|
262 | 0 | FUNC_ENTER_PACKAGE |
263 | | |
264 | | /* Check arguments */ |
265 | 0 | if (H5G_loc_real(obj, loc_params->obj_type, &loc) < 0) |
266 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file or file object"); |
267 | 0 | if (H5I_DATATYPE != H5I_get_type(type_id)) |
268 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a datatype ID"); |
269 | 0 | if (NULL == (space = (const H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE))) |
270 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a dataspace ID"); |
271 | | |
272 | | /* H5Dcreate_anon */ |
273 | 0 | if (NULL == name) { |
274 | | /* build and open the new dataset */ |
275 | 0 | if (NULL == (dset = H5D__create(loc.oloc->file, type_id, space, dcpl_id, dapl_id))) |
276 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, NULL, "unable to create dataset"); |
277 | 0 | } /* end if */ |
278 | | /* H5Dcreate2 */ |
279 | 0 | else { |
280 | | /* Create the new dataset & get its ID */ |
281 | 0 | if (NULL == (dset = H5D__create_named(&loc, name, type_id, space, lcpl_id, dcpl_id, dapl_id))) |
282 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, NULL, "unable to create dataset"); |
283 | 0 | } /* end else */ |
284 | | |
285 | 0 | ret_value = (void *)dset; |
286 | |
|
287 | 0 | done: |
288 | 0 | if (NULL == name) { |
289 | | /* Release the dataset's object header, if it was created */ |
290 | 0 | if (dset) { |
291 | 0 | H5O_loc_t *oloc; /* Object location for dataset */ |
292 | | |
293 | | /* Get the new dataset's object location */ |
294 | 0 | if (NULL == (oloc = H5D_oloc(dset))) |
295 | 0 | HDONE_ERROR(H5E_DATASET, H5E_CANTGET, NULL, "unable to get object location of dataset"); |
296 | | |
297 | | /* Decrement refcount on dataset's object header in memory */ |
298 | 0 | if (H5O_dec_rc_by_loc(oloc) < 0) |
299 | 0 | HDONE_ERROR(H5E_DATASET, H5E_CANTDEC, NULL, |
300 | 0 | "unable to decrement refcount on newly created object"); |
301 | 0 | } /* end if */ |
302 | 0 | } /* end if */ |
303 | |
|
304 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
305 | 0 | } /* end H5VL__native_dataset_create() */ |
306 | | |
307 | | /*------------------------------------------------------------------------- |
308 | | * Function: H5VL__native_dataset_open |
309 | | * |
310 | | * Purpose: Handles the dataset open callback |
311 | | * |
312 | | * Return: Success: dataset pointer |
313 | | * Failure: NULL |
314 | | * |
315 | | *------------------------------------------------------------------------- |
316 | | */ |
317 | | void * |
318 | | H5VL__native_dataset_open(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t dapl_id, |
319 | | hid_t H5_ATTR_UNUSED dxpl_id, void H5_ATTR_UNUSED **req) |
320 | 1 | { |
321 | 1 | H5D_t *dset = NULL; |
322 | 1 | H5G_loc_t loc; /* Object location of group */ |
323 | 1 | void *ret_value = NULL; |
324 | | |
325 | 1 | FUNC_ENTER_PACKAGE |
326 | | |
327 | 1 | if (H5G_loc_real(obj, loc_params->obj_type, &loc) < 0) |
328 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file or file object"); |
329 | | |
330 | | /* Open the dataset */ |
331 | 1 | if (NULL == (dset = H5D__open_name(&loc, name, dapl_id))) |
332 | 1 | HGOTO_ERROR(H5E_DATASET, H5E_CANTOPENOBJ, NULL, "unable to open dataset"); |
333 | | |
334 | 0 | ret_value = (void *)dset; |
335 | |
|
336 | 1 | done: |
337 | 1 | FUNC_LEAVE_NOAPI(ret_value) |
338 | 1 | } /* end H5VL__native_dataset_open() */ |
339 | | |
340 | | /*------------------------------------------------------------------------- |
341 | | * Function: H5VL__native_dataset_read |
342 | | * |
343 | | * Purpose: Handles the dataset read callback |
344 | | * |
345 | | * Return: SUCCEED/FAIL |
346 | | * |
347 | | *------------------------------------------------------------------------- |
348 | | */ |
349 | | herr_t |
350 | | H5VL__native_dataset_read(size_t count, void *obj[], hid_t mem_type_id[], hid_t mem_space_id[], |
351 | | hid_t file_space_id[], hid_t dxpl_id, void *buf[], void H5_ATTR_UNUSED **req) |
352 | 0 | { |
353 | 0 | H5D_dset_io_info_t dinfo_local; |
354 | 0 | H5D_dset_io_info_t *dinfo = &dinfo_local; |
355 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
356 | |
|
357 | 0 | FUNC_ENTER_PACKAGE |
358 | | |
359 | | /* Allocate dataset info array if necessary */ |
360 | 0 | if (count > 1) |
361 | 0 | if (NULL == (dinfo = (H5D_dset_io_info_t *)H5MM_malloc(count * sizeof(H5D_dset_io_info_t)))) |
362 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "couldn't allocate dset info array buffer"); |
363 | | |
364 | | /* Get file & memory dataspaces */ |
365 | 0 | if (H5VL__native_dataset_io_setup(count, obj, mem_type_id, mem_space_id, file_space_id, dxpl_id, |
366 | 0 | (H5_flexible_const_ptr_t *)buf, dinfo) < 0) |
367 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to set up file and memory dataspaces"); |
368 | | |
369 | | /* Set DXPL for operation */ |
370 | 0 | H5CX_set_dxpl(dxpl_id); |
371 | | |
372 | | /* Read raw data. Call H5D__read directly in single dset case. */ |
373 | 0 | if (H5D__read(count, dinfo) < 0) |
374 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "can't read data"); |
375 | | |
376 | 0 | done: |
377 | | /* Clean up */ |
378 | 0 | if (H5VL__native_dataset_io_cleanup(count, mem_space_id, file_space_id, dinfo) < 0) |
379 | 0 | HDONE_ERROR(H5E_DATASET, H5E_CANTRELEASE, FAIL, "unable to release dataset info"); |
380 | |
|
381 | 0 | if (dinfo != &dinfo_local) |
382 | 0 | H5MM_xfree(dinfo); |
383 | |
|
384 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
385 | 0 | } /* end H5VL__native_dataset_read() */ |
386 | | |
387 | | /*------------------------------------------------------------------------- |
388 | | * Function: H5VL__native_dataset_write |
389 | | * |
390 | | * Purpose: Handles the dataset write callback |
391 | | * |
392 | | * Return: SUCCEED/FAIL |
393 | | * |
394 | | *------------------------------------------------------------------------- |
395 | | */ |
396 | | herr_t |
397 | | H5VL__native_dataset_write(size_t count, void *obj[], hid_t mem_type_id[], hid_t mem_space_id[], |
398 | | hid_t file_space_id[], hid_t dxpl_id, const void *buf[], void H5_ATTR_UNUSED **req) |
399 | 0 | { |
400 | 0 | H5D_dset_io_info_t dinfo_local; |
401 | 0 | H5D_dset_io_info_t *dinfo = &dinfo_local; |
402 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
403 | |
|
404 | 0 | FUNC_ENTER_PACKAGE |
405 | | |
406 | | /* Allocate dataset info array if necessary */ |
407 | 0 | if (count > 1) |
408 | 0 | if (NULL == (dinfo = (H5D_dset_io_info_t *)H5MM_malloc(count * sizeof(H5D_dset_io_info_t)))) |
409 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "couldn't allocate dset info array buffer"); |
410 | | |
411 | | /* Get file & memory dataspaces */ |
412 | 0 | if (H5VL__native_dataset_io_setup(count, obj, mem_type_id, mem_space_id, file_space_id, dxpl_id, |
413 | 0 | (H5_flexible_const_ptr_t *)buf, dinfo) < 0) |
414 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to set up file and memory dataspaces"); |
415 | | |
416 | | /* Set DXPL for operation */ |
417 | 0 | H5CX_set_dxpl(dxpl_id); |
418 | | |
419 | | /* Write raw data. Call H5D__write directly in single dset case. */ |
420 | 0 | if (H5D__write(count, dinfo) < 0) |
421 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't write data"); |
422 | | |
423 | 0 | done: |
424 | | /* Clean up */ |
425 | 0 | if (H5VL__native_dataset_io_cleanup(count, mem_space_id, file_space_id, dinfo) < 0) |
426 | 0 | HDONE_ERROR(H5E_DATASET, H5E_CANTRELEASE, FAIL, "unable to release dataset info"); |
427 | |
|
428 | 0 | if (dinfo != &dinfo_local) |
429 | 0 | H5MM_xfree(dinfo); |
430 | |
|
431 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
432 | 0 | } /* end H5VL__native_dataset_write() */ |
433 | | |
434 | | /*------------------------------------------------------------------------- |
435 | | * Function: H5VL__native_dataset_get |
436 | | * |
437 | | * Purpose: Handles the dataset get callback |
438 | | * |
439 | | * Return: SUCCEED/FAIL |
440 | | * |
441 | | *------------------------------------------------------------------------- |
442 | | */ |
443 | | herr_t |
444 | | H5VL__native_dataset_get(void *obj, H5VL_dataset_get_args_t *args, hid_t H5_ATTR_UNUSED dxpl_id, |
445 | | void H5_ATTR_UNUSED **req) |
446 | 0 | { |
447 | 0 | H5D_t *dset = (H5D_t *)obj; |
448 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
449 | |
|
450 | 0 | FUNC_ENTER_PACKAGE |
451 | |
|
452 | 0 | switch (args->op_type) { |
453 | | /* H5Dget_space */ |
454 | 0 | case H5VL_DATASET_GET_SPACE: { |
455 | 0 | if ((args->args.get_space.space_id = H5D__get_space(dset)) < 0) |
456 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get space ID of dataset"); |
457 | | |
458 | 0 | break; |
459 | 0 | } |
460 | | |
461 | | /* H5Dget_space_status */ |
462 | 0 | case H5VL_DATASET_GET_SPACE_STATUS: { |
463 | 0 | if (H5D__get_space_status(dset, args->args.get_space_status.status) < 0) |
464 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to get space status"); |
465 | | |
466 | 0 | break; |
467 | 0 | } |
468 | | |
469 | | /* H5Dget_type */ |
470 | 0 | case H5VL_DATASET_GET_TYPE: { |
471 | 0 | if ((args->args.get_type.type_id = H5D__get_type(dset)) < 0) |
472 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get datatype ID of dataset"); |
473 | | |
474 | 0 | break; |
475 | 0 | } |
476 | | |
477 | | /* H5Dget_create_plist */ |
478 | 0 | case H5VL_DATASET_GET_DCPL: { |
479 | 0 | if ((args->args.get_dcpl.dcpl_id = H5D_get_create_plist(dset)) < 0) |
480 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get creation property list for dataset"); |
481 | | |
482 | 0 | break; |
483 | 0 | } |
484 | | |
485 | | /* H5Dget_access_plist */ |
486 | 0 | case H5VL_DATASET_GET_DAPL: { |
487 | 0 | if ((args->args.get_dapl.dapl_id = H5D_get_access_plist(dset)) < 0) |
488 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get access property list for dataset"); |
489 | | |
490 | 0 | break; |
491 | 0 | } |
492 | | |
493 | | /* H5Dget_storage_size */ |
494 | 0 | case H5VL_DATASET_GET_STORAGE_SIZE: { |
495 | 0 | if (H5D__get_storage_size(dset, args->args.get_storage_size.storage_size) < 0) |
496 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get size of dataset's storage"); |
497 | 0 | break; |
498 | 0 | } |
499 | | |
500 | 0 | default: |
501 | 0 | HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't get this type of information from dataset"); |
502 | 0 | } /* end switch */ |
503 | | |
504 | 0 | done: |
505 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
506 | 0 | } /* end H5VL__native_dataset_get() */ |
507 | | |
508 | | /*------------------------------------------------------------------------- |
509 | | * Function: H5VL__native_dataset_specific |
510 | | * |
511 | | * Purpose: Handles the dataset specific callback |
512 | | * |
513 | | * Return: SUCCEED/FAIL |
514 | | * |
515 | | *------------------------------------------------------------------------- |
516 | | */ |
517 | | herr_t |
518 | | H5VL__native_dataset_specific(void *obj, H5VL_dataset_specific_args_t *args, hid_t H5_ATTR_UNUSED dxpl_id, |
519 | | void H5_ATTR_UNUSED **req) |
520 | 0 | { |
521 | 0 | H5D_t *dset = (H5D_t *)obj; |
522 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
523 | |
|
524 | 0 | FUNC_ENTER_PACKAGE |
525 | |
|
526 | 0 | switch (args->op_type) { |
527 | | /* H5Dset_extent (H5Dextend - deprecated) */ |
528 | 0 | case H5VL_DATASET_SET_EXTENT: { |
529 | 0 | if (H5D__set_extent(dset, args->args.set_extent.size) < 0) |
530 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, FAIL, "unable to set extent of dataset"); |
531 | 0 | break; |
532 | 0 | } |
533 | | |
534 | | /* H5Dflush */ |
535 | 0 | case H5VL_DATASET_FLUSH: { |
536 | 0 | if (H5D__flush(dset, args->args.flush.dset_id) < 0) |
537 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTFLUSH, FAIL, "unable to flush dataset"); |
538 | | |
539 | 0 | break; |
540 | 0 | } |
541 | | |
542 | | /* H5Drefresh */ |
543 | 0 | case H5VL_DATASET_REFRESH: { |
544 | 0 | if (H5D__refresh(dset, args->args.refresh.dset_id) < 0) |
545 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTLOAD, FAIL, "unable to refresh dataset"); |
546 | | |
547 | 0 | break; |
548 | 0 | } |
549 | | |
550 | 0 | default: |
551 | 0 | HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "invalid specific operation"); |
552 | 0 | } /* end switch */ |
553 | | |
554 | 0 | done: |
555 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
556 | 0 | } /* end H5VL__native_dataset_specific() */ |
557 | | |
558 | | /*------------------------------------------------------------------------- |
559 | | * Function: H5VL__native_dataset_optional |
560 | | * |
561 | | * Purpose: Handles the dataset optional callback |
562 | | * |
563 | | * Return: SUCCEED/FAIL |
564 | | * |
565 | | *------------------------------------------------------------------------- |
566 | | */ |
567 | | herr_t |
568 | | H5VL__native_dataset_optional(void *obj, H5VL_optional_args_t *args, hid_t dxpl_id, void H5_ATTR_UNUSED **req) |
569 | 0 | { |
570 | 0 | H5D_t *dset = (H5D_t *)obj; /* Dataset */ |
571 | 0 | H5VL_native_dataset_optional_args_t *opt_args = args->args; /* Pointer to native operation's arguments */ |
572 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
573 | |
|
574 | 0 | FUNC_ENTER_PACKAGE |
575 | | |
576 | | /* Sanity checks */ |
577 | 0 | assert(dset); |
578 | | |
579 | | /* Set DXPL for operation */ |
580 | 0 | H5CX_set_dxpl(dxpl_id); |
581 | |
|
582 | 0 | switch (args->op_type) { |
583 | | /* H5Dformat_convert */ |
584 | 0 | case H5VL_NATIVE_DATASET_FORMAT_CONVERT: { |
585 | 0 | switch (dset->shared->layout.type) { |
586 | 0 | case H5D_CHUNKED: |
587 | | /* Convert the chunk indexing type to version 1 B-tree if not */ |
588 | 0 | if (dset->shared->layout.u.chunk.idx_type != H5D_CHUNK_IDX_BTREE) |
589 | 0 | if (H5D__format_convert(dset) < 0) |
590 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTLOAD, FAIL, |
591 | 0 | "unable to downgrade chunk indexing type for dataset"); |
592 | 0 | break; |
593 | | |
594 | 0 | case H5D_CONTIGUOUS: |
595 | 0 | case H5D_COMPACT: |
596 | | /* Downgrade the layout version to 3 if greater than 3 */ |
597 | 0 | if (dset->shared->layout.version > H5O_LAYOUT_VERSION_DEFAULT) |
598 | 0 | if (H5D__format_convert(dset) < 0) |
599 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTLOAD, FAIL, |
600 | 0 | "unable to downgrade layout version for dataset"); |
601 | 0 | break; |
602 | | |
603 | 0 | case H5D_VIRTUAL: |
604 | | /* Nothing to do even though layout is version 4 */ |
605 | 0 | break; |
606 | | |
607 | 0 | case H5D_LAYOUT_ERROR: |
608 | 0 | case H5D_NLAYOUTS: |
609 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid dataset layout type"); |
610 | | |
611 | 0 | default: |
612 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "unknown dataset layout type"); |
613 | 0 | } /* end switch */ |
614 | | |
615 | 0 | break; |
616 | 0 | } |
617 | | |
618 | | /* H5Dget_chunk_index_type */ |
619 | 0 | case H5VL_NATIVE_DATASET_GET_CHUNK_INDEX_TYPE: { |
620 | | /* Make sure the dataset is chunked */ |
621 | 0 | if (H5D_CHUNKED != dset->shared->layout.type) |
622 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a chunked dataset"); |
623 | | |
624 | | /* Get the chunk indexing type */ |
625 | 0 | *opt_args->get_chunk_idx_type.idx_type = dset->shared->layout.u.chunk.idx_type; |
626 | |
|
627 | 0 | break; |
628 | 0 | } |
629 | | |
630 | | /* H5Dget_chunk_storage_size */ |
631 | 0 | case H5VL_NATIVE_DATASET_GET_CHUNK_STORAGE_SIZE: { |
632 | 0 | H5VL_native_dataset_get_chunk_storage_size_t *gcss_args = &opt_args->get_chunk_storage_size; |
633 | | |
634 | | /* Make sure the dataset is chunked */ |
635 | 0 | if (H5D_CHUNKED != dset->shared->layout.type) |
636 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a chunked dataset"); |
637 | | |
638 | | /* Call private function */ |
639 | 0 | if (H5D__get_chunk_storage_size(dset, gcss_args->offset, gcss_args->size) < 0) |
640 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get storage size of chunk"); |
641 | | |
642 | 0 | break; |
643 | 0 | } |
644 | | |
645 | | /* H5Dget_num_chunks */ |
646 | 0 | case H5VL_NATIVE_DATASET_GET_NUM_CHUNKS: { |
647 | 0 | H5VL_native_dataset_get_num_chunks_t *gnc_args = &opt_args->get_num_chunks; |
648 | 0 | const H5S_t *space = NULL; |
649 | |
|
650 | 0 | assert(dset->shared); |
651 | 0 | assert(dset->shared->space); |
652 | | |
653 | | /* When default dataspace is given, use the dataset's dataspace */ |
654 | 0 | if (gnc_args->space_id == H5S_ALL) |
655 | 0 | space = dset->shared->space; |
656 | 0 | else /* otherwise, use the given space ID */ |
657 | 0 | if (NULL == (space = (const H5S_t *)H5I_object_verify(gnc_args->space_id, H5I_DATASPACE))) |
658 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a valid dataspace ID"); |
659 | | |
660 | | /* Make sure the dataset is chunked */ |
661 | 0 | if (H5D_CHUNKED != dset->shared->layout.type) |
662 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a chunked dataset"); |
663 | | |
664 | | /* Call private function */ |
665 | 0 | if (H5D__get_num_chunks(dset, space, gnc_args->nchunks) < 0) |
666 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get number of chunks"); |
667 | | |
668 | 0 | break; |
669 | 0 | } |
670 | | |
671 | | /* H5Dget_chunk_info */ |
672 | 0 | case H5VL_NATIVE_DATASET_GET_CHUNK_INFO_BY_IDX: { |
673 | 0 | H5VL_native_dataset_get_chunk_info_by_idx_t *gcibi_args = &opt_args->get_chunk_info_by_idx; |
674 | 0 | const H5S_t *space; |
675 | |
|
676 | 0 | assert(dset->shared); |
677 | 0 | assert(dset->shared->space); |
678 | | |
679 | | /* When default dataspace is given, use the dataset's dataspace */ |
680 | 0 | if (gcibi_args->space_id == H5S_ALL) |
681 | 0 | space = dset->shared->space; |
682 | 0 | else /* otherwise, use the given space ID */ |
683 | 0 | if (NULL == (space = (const H5S_t *)H5I_object_verify(gcibi_args->space_id, H5I_DATASPACE))) |
684 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a valid dataspace ID"); |
685 | | |
686 | | /* Make sure the dataset is chunked */ |
687 | 0 | if (H5D_CHUNKED != dset->shared->layout.type) |
688 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a chunked dataset"); |
689 | | |
690 | | /* Call private function */ |
691 | 0 | if (H5D__get_chunk_info(dset, space, gcibi_args->chk_index, gcibi_args->offset, |
692 | 0 | gcibi_args->filter_mask, gcibi_args->addr, gcibi_args->size) < 0) |
693 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get chunk info by index"); |
694 | | |
695 | 0 | break; |
696 | 0 | } |
697 | | |
698 | | /* H5Dget_chunk_info_by_coord */ |
699 | 0 | case H5VL_NATIVE_DATASET_GET_CHUNK_INFO_BY_COORD: { |
700 | 0 | H5VL_native_dataset_get_chunk_info_by_coord_t *gcibc_args = &opt_args->get_chunk_info_by_coord; |
701 | |
|
702 | 0 | assert(dset->shared); |
703 | | |
704 | | /* Make sure the dataset is chunked */ |
705 | 0 | if (H5D_CHUNKED != dset->shared->layout.type) |
706 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a chunked dataset"); |
707 | | |
708 | | /* Call private function */ |
709 | 0 | if (H5D__get_chunk_info_by_coord(dset, gcibc_args->offset, gcibc_args->filter_mask, |
710 | 0 | gcibc_args->addr, gcibc_args->size) < 0) |
711 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, |
712 | 0 | "can't get chunk info by its logical coordinates"); |
713 | | |
714 | 0 | break; |
715 | 0 | } |
716 | | |
717 | | /* H5Dread_chunk */ |
718 | 0 | case H5VL_NATIVE_DATASET_CHUNK_READ: { |
719 | 0 | H5VL_native_dataset_chunk_read_t *chunk_read_args = &opt_args->chunk_read; |
720 | 0 | hsize_t offset_copy[H5O_LAYOUT_NDIMS]; /* Internal copy of chunk offset */ |
721 | | |
722 | | /* Check arguments */ |
723 | 0 | if (NULL == dset->oloc.file) |
724 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "dataset is not associated with a file"); |
725 | 0 | if (H5D_CHUNKED != dset->shared->layout.type) |
726 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a chunked dataset"); |
727 | | |
728 | | /* Copy the user's offset array so we can be sure it's terminated properly. |
729 | | * (we don't want to mess with the user's buffer). |
730 | | */ |
731 | 0 | if (H5D__chunk_get_offset_copy(dset, chunk_read_args->offset, offset_copy) < 0) |
732 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTCOPY, FAIL, "failure to copy offset array"); |
733 | | |
734 | | /* Read the raw chunk */ |
735 | 0 | if (H5D__chunk_direct_read(dset, offset_copy, &chunk_read_args->filters, chunk_read_args->buf, |
736 | 0 | chunk_read_args->buf_size) < 0) |
737 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "can't read unprocessed chunk data"); |
738 | | |
739 | 0 | break; |
740 | 0 | } |
741 | | |
742 | | /* H5Dwrite_chunk */ |
743 | 0 | case H5VL_NATIVE_DATASET_CHUNK_WRITE: { |
744 | 0 | H5VL_native_dataset_chunk_write_t *chunk_write_args = &opt_args->chunk_write; |
745 | 0 | hsize_t offset_copy[H5O_LAYOUT_NDIMS]; /* Internal copy of chunk offset */ |
746 | | |
747 | | /* Check arguments */ |
748 | 0 | if (NULL == dset->oloc.file) |
749 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "dataset is not associated with a file"); |
750 | 0 | if (H5D_CHUNKED != dset->shared->layout.type) |
751 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a chunked dataset"); |
752 | | |
753 | | /* Copy the user's offset array so we can be sure it's terminated properly. |
754 | | * (we don't want to mess with the user's buffer). |
755 | | */ |
756 | 0 | if (H5D__chunk_get_offset_copy(dset, chunk_write_args->offset, offset_copy) < 0) |
757 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTCOPY, FAIL, "failure to copy offset array"); |
758 | | |
759 | | /* Write chunk */ |
760 | 0 | if (H5D__chunk_direct_write(dset, chunk_write_args->filters, offset_copy, chunk_write_args->size, |
761 | 0 | chunk_write_args->buf) < 0) |
762 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't write unprocessed chunk data"); |
763 | | |
764 | 0 | break; |
765 | 0 | } |
766 | | |
767 | | /* H5Dvlen_get_buf_size */ |
768 | 0 | case H5VL_NATIVE_DATASET_GET_VLEN_BUF_SIZE: { |
769 | 0 | H5VL_native_dataset_get_vlen_buf_size_t *gvbs_args = &opt_args->get_vlen_buf_size; |
770 | |
|
771 | 0 | if (H5D__vlen_get_buf_size(dset, gvbs_args->type_id, gvbs_args->space_id, gvbs_args->size) < 0) |
772 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get size of vlen buf needed"); |
773 | 0 | break; |
774 | 0 | } |
775 | | |
776 | | /* H5Dget_offset */ |
777 | 0 | case H5VL_NATIVE_DATASET_GET_OFFSET: { |
778 | | /* Get offset */ |
779 | 0 | *opt_args->get_offset.offset = H5D__get_offset(dset); |
780 | |
|
781 | 0 | break; |
782 | 0 | } |
783 | | |
784 | | /* H5Dchunk_iter */ |
785 | 0 | case H5VL_NATIVE_DATASET_CHUNK_ITER: { |
786 | | /* Sanity check */ |
787 | 0 | assert(dset->shared); |
788 | | |
789 | | /* Make sure the dataset is chunked */ |
790 | 0 | if (H5D_CHUNKED != dset->shared->layout.type) |
791 | 0 | HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a chunked dataset"); |
792 | | |
793 | | /* Call private function */ |
794 | 0 | if ((ret_value = H5D__chunk_iter(dset, opt_args->chunk_iter.op, opt_args->chunk_iter.op_data)) < |
795 | 0 | 0) |
796 | 0 | HERROR(H5E_DATASET, H5E_BADITER, "chunk iteration failed"); |
797 | |
|
798 | 0 | break; |
799 | 0 | } |
800 | | |
801 | 0 | default: |
802 | 0 | HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "invalid optional operation"); |
803 | 0 | } /* end switch */ |
804 | | |
805 | 0 | done: |
806 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
807 | 0 | } /* end H5VL__native_dataset_optional() */ |
808 | | |
809 | | /*------------------------------------------------------------------------- |
810 | | * Function: H5VL__native_dataset_close |
811 | | * |
812 | | * Purpose: Handles the dataset close callback |
813 | | * |
814 | | * Return: Success: SUCCEED |
815 | | * Failure: FAIL (dataset will not be closed) |
816 | | * |
817 | | *------------------------------------------------------------------------- |
818 | | */ |
819 | | herr_t |
820 | | H5VL__native_dataset_close(void *dset, hid_t H5_ATTR_UNUSED dxpl_id, void H5_ATTR_UNUSED **req) |
821 | 0 | { |
822 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
823 | |
|
824 | 0 | FUNC_ENTER_PACKAGE |
825 | |
|
826 | 0 | if (H5D_close((H5D_t *)dset) < 0) |
827 | 0 | HGOTO_ERROR(H5E_DATASET, H5E_CANTDEC, FAIL, "can't close dataset"); |
828 | | |
829 | 0 | done: |
830 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
831 | 0 | } /* end H5VL__native_dataset_close() */ |