Skip to content

Commit bcf68d6

Browse files
committed
move setting is_open inside of open call
1 parent 63966f2 commit bcf68d6

File tree

3 files changed

+36
-18
lines changed

3 files changed

+36
-18
lines changed

src/drivers/pncio/pncio_close.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ int PNCIO_File_close(PNCIO_File *fh)
2222
{
2323
int err = NC_NOERR;
2424

25-
err = close(fh->fd_sys);
26-
if (err != 0)
27-
err = ncmpii_error_posix2nc("close");
25+
if (fh->is_open) {
26+
err = close(fh->fd_sys);
27+
if (err != 0)
28+
err = ncmpii_error_posix2nc("close");
29+
}
2830

2931
if (fh->hints->ranklist != NULL)
3032
NCI_Free(fh->hints->ranklist);

src/drivers/pncio/pncio_lustre_open.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,7 @@ assert(mpi_io_mode & MPI_MODE_CREATE);
973973
err = ncmpii_error_posix2nc("Lustre set striping");
974974
goto err_out;
975975
}
976+
fd->is_open = 1;
976977

977978
/* Obtain Lustre file striping parameters actually set. */
978979
numOSTs = get_striping(fd->fd_sys, fd->filename, &pattern,
@@ -993,6 +994,7 @@ assert(mpi_io_mode & MPI_MODE_CREATE);
993994
err = ncmpii_error_posix2nc("open");
994995
goto err_out;
995996
}
997+
fd->is_open = 1;
996998

997999
char *env_str = getenv("MIMIC_STRIPE_SIZE");
9981000
if (env_str != NULL)
@@ -1028,6 +1030,7 @@ assert(mpi_io_mode & MPI_MODE_CREATE);
10281030
__FILE__,__LINE__, rank, fd->filename, strerror(errno));
10291031
return ncmpii_error_posix2nc("ioctl");
10301032
}
1033+
fd->is_open = 1;
10311034
}
10321035

10331036
/* construct cb_nodes rank list */
@@ -1080,6 +1083,7 @@ static int wkl=0; if (wkl == 0 && rank == 0) { printf("\nxxxx %s at %d: %s ----
10801083
err = ncmpii_error_posix2nc("open");
10811084
goto err_out;
10821085
}
1086+
fd->is_open = 1;
10831087

10841088
/* Only root obtains the striping information and bcast to all other
10851089
* processes.

src/drivers/pncio/pncio_open.c

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ if (rank == 0) { printf("\nxxxx %s at %d: ---- %s\n",__func__,__LINE__,fd->filen
139139
err = ncmpii_error_posix2nc("open");
140140
goto err_out;
141141
}
142+
fd->is_open = 1;
142143

143144
err_out:
144145
MPI_Bcast(stripin_info, 4, MPI_INT, 0, fd->comm);
@@ -154,6 +155,7 @@ if (rank == 0) { printf("\nxxxx %s at %d: ---- %s\n",__func__,__LINE__,fd->filen
154155
__func__,__LINE__, rank, fd->filename, strerror(errno));
155156
return ncmpii_error_posix2nc("ioctl");
156157
}
158+
fd->is_open = 1;
157159
}
158160

159161
/* construct cb_nodes rank list */
@@ -196,6 +198,7 @@ if (rank == 0) { printf("\nxxxx %s at %d: ---- %s\n",__func__,__LINE__,fd->filen
196198
err = ncmpii_error_posix2nc("open");
197199
goto err_out;
198200
}
201+
fd->is_open = 1;
199202

200203
/* Only root obtains the striping information and bcast to all other
201204
* processes.
@@ -233,7 +236,7 @@ int PNCIO_File_open(MPI_Comm comm,
233236
* called to check the file system type.
234237
*/
235238
char value[MPI_MAX_INFO_VAL + 1], int_str[16];
236-
int i, err, min_err;
239+
int i, err, min_err, status=NC_NOERR;
237240

238241
fd->comm = comm;
239242
fd->filename = filename; /* without file system type name prefix */
@@ -256,9 +259,13 @@ int PNCIO_File_open(MPI_Comm comm,
256259
else
257260
MPI_Info_dup(info, &fd->info);
258261

259-
err = PNCIO_File_SetInfo(fd, fd->info);
260-
if (err != NC_NOERR)
261-
return err;
262+
status = PNCIO_File_SetInfo(fd, fd->info);
263+
if (status != NC_NOERR && status != NC_EMULTIDEFINE_HINTS) {
264+
/* Inconsistent I/O hints is not a fatal error.
265+
* In PNCIO_File_SetInfo(), root's hints overwrite local's.
266+
*/
267+
goto err_out;
268+
}
262269

263270
#if defined(PNETCDF_PROFILING) && (PNETCDF_PROFILING == 1)
264271
for (i=0; i<NMEASURES; i++) {
@@ -269,6 +276,10 @@ int PNCIO_File_open(MPI_Comm comm,
269276

270277
assert(fd->file_system != PNCIO_FSTYPE_MPIIO);
271278

279+
/* TODO: When hint romio_no_indep_rw hint is set to true, only aggregators open
280+
* the file.
281+
* Note because fd->is_agg is set at the end of create/open call.
282+
*/
272283
if (fd->file_system == PNCIO_LUSTRE) {
273284
if (amode & MPI_MODE_CREATE)
274285
err = PNCIO_Lustre_create(fd, amode);
@@ -281,11 +292,10 @@ int PNCIO_File_open(MPI_Comm comm,
281292
else
282293
err = GEN_open(fd);
283294
}
284-
if (err != NC_NOERR) goto err_out;
285-
286-
/* TODO: when hint no_indep_rw hint is set to true, only aggregators open
287-
* the file */
288-
fd->is_open = 1;
295+
if (err != NC_NOERR) { /* fatal error */
296+
status = err;
297+
goto err_out;
298+
}
289299

290300
/* set file striping hints */
291301
snprintf(int_str, 16, "%d", fd->hints->striping_unit);
@@ -323,22 +333,24 @@ int PNCIO_File_open(MPI_Comm comm,
323333
/* collective buffer is used only by I/O aggregators only */
324334
if (fd->is_agg) {
325335
fd->io_buf = NCI_Calloc(1, fd->hints->cb_buffer_size);
326-
if (fd->io_buf == NULL)
327-
return NC_ENOMEM;
336+
if (fd->io_buf == NULL) /* fatal error */
337+
status = NC_ENOMEM;
328338
}
329339

330340
err_out:
331-
MPI_Allreduce(&err, &min_err, 1, MPI_INT, MPI_MIN, comm);
341+
MPI_Allreduce(&status, &min_err, 1, MPI_INT, MPI_MIN, comm);
332342
/* All NC errors are < 0 */
333-
if (min_err < 0) {
334-
if (err == 0) /* close file if opened successfully */
343+
344+
if (min_err != NC_NOERR) {
345+
if (status == NC_NOERR && fd->is_open)
346+
/* close file if opened successfully */
335347
close(fd->fd_sys);
336348
NCI_Free(fd->hints);
337349
if (fd->info != MPI_INFO_NULL)
338350
MPI_Info_free(&(fd->info));
339351
if (fd->io_buf != NULL)
340352
NCI_Free(fd->io_buf);
341353
}
342-
return err;
354+
return status;
343355
}
344356

0 commit comments

Comments
 (0)