Skip to content

Commit cb638c2

Browse files
committed
io/ompio and fbtl: introduce a function to check for support of atomic ops
this is a new function in the fbtl framework. A default implementation is provided in the fbtl/base directory (which simply returns false), but an fbtl component can provide its own implementation. As of right now, the ime and pvfs2 components use the default from base, posix provides its own check_atomicity function. Signed-off-by: Edgar Gabriel <egabriel@central.uh.edu>
1 parent 0ce7792 commit cb638c2

File tree

8 files changed

+76
-18
lines changed

8 files changed

+76
-18
lines changed

ompi/mca/fbtl/base/base.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Copyright (c) 2004-2005 The Regents of the University of California.
1111
* All rights reserved.
1212
* Copyright (c) 2008 Cisco Systems, Inc. All rights reserved.
13-
* Copyright (c) 2008-2011 University of Houston. All rights reserved.
13+
* Copyright (c) 2008-2021 University of Houston. All rights reserved.
1414
* Copyright (c) 2018 Research Organization for Information Science
1515
* and Technology (RIST). All rights reserved.
1616
* $COPYRIGHT$
@@ -50,6 +50,8 @@ OMPI_DECLSPEC int mca_fbtl_base_find_available(bool enable_progress_threads,
5050
OMPI_DECLSPEC int mca_fbtl_base_init_file (struct ompio_file_t *file);
5151

5252
OMPI_DECLSPEC int mca_fbtl_base_get_param (struct ompio_file_t *file, int keyval);
53+
54+
OMPI_DECLSPEC bool mca_fbtl_base_check_atomicity (struct ompio_file_t *file);
5355
/*
5456
* Globals
5557
*/

ompi/mca/fbtl/base/fbtl_base_file_select.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* University of Stuttgart. All rights reserved.
1010
* Copyright (c) 2004-2005 The Regents of the University of California.
1111
* All rights reserved.
12-
* Copyright (c) 2008-2011 University of Houston. All rights reserved.
12+
* Copyright (c) 2008-2021 University of Houston. All rights reserved.
1313
* Copyright (c) 2018 Research Organization for Information Science
1414
* and Technology (RIST). All rights reserved.
1515
* $COPYRIGHT$
@@ -259,3 +259,13 @@ int mca_fbtl_base_file_select (struct ompio_file_t *file,
259259

260260
return err;
261261
}
262+
263+
264+
bool mca_fbtl_base_check_atomicity (struct ompio_file_t *file)
265+
{
266+
/* by default, return false. An fbtl can overwrite this setting
267+
** if they have support for atomic operations through locks or other
268+
** measures.
269+
*/
270+
return false;
271+
}

ompi/mca/fbtl/fbtl.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* University of Stuttgart. All rights reserved.
1111
* Copyright (c) 2004-2005 The Regents of the University of California.
1212
* All rights reserved.
13-
* Copyright (c) 2008-2014 University of Houston. All rights reserved.
13+
* Copyright (c) 2008-2021 University of Houston. All rights reserved.
1414
* Copyright (c) 2015 Los Alamos National Security, LLC. All rights
1515
* reserved.
1616
* Copyright (c) 2018 Research Organization for Information Science
@@ -135,6 +135,10 @@ typedef bool (*mca_fbtl_base_module_progress_fn_t)
135135

136136
typedef void (*mca_fbtl_base_module_request_free_fn_t)
137137
( struct mca_ompio_request_t *request);
138+
139+
typedef bool (*mca_fbtl_base_module_check_atomicity_fn_t)
140+
(struct ompio_file_t *file);
141+
138142
/*
139143
* ***********************************************************************
140144
* *************************** module structure *************************
@@ -150,12 +154,13 @@ struct mca_fbtl_base_module_1_0_0_t {
150154
mca_fbtl_base_module_finalize_1_0_0_fn_t fbtl_module_finalize;
151155

152156
/* FBTL function pointers */
153-
mca_fbtl_base_module_preadv_fn_t fbtl_preadv;
154-
mca_fbtl_base_module_ipreadv_fn_t fbtl_ipreadv;
155-
mca_fbtl_base_module_pwritev_fn_t fbtl_pwritev;
156-
mca_fbtl_base_module_ipwritev_fn_t fbtl_ipwritev;
157-
mca_fbtl_base_module_progress_fn_t fbtl_progress;
158-
mca_fbtl_base_module_request_free_fn_t fbtl_request_free;
157+
mca_fbtl_base_module_preadv_fn_t fbtl_preadv;
158+
mca_fbtl_base_module_ipreadv_fn_t fbtl_ipreadv;
159+
mca_fbtl_base_module_pwritev_fn_t fbtl_pwritev;
160+
mca_fbtl_base_module_ipwritev_fn_t fbtl_ipwritev;
161+
mca_fbtl_base_module_progress_fn_t fbtl_progress;
162+
mca_fbtl_base_module_request_free_fn_t fbtl_request_free;
163+
mca_fbtl_base_module_check_atomicity_fn_t fbtl_check_atomicity;
159164
};
160165
typedef struct mca_fbtl_base_module_1_0_0_t mca_fbtl_base_module_1_0_0_t;
161166
typedef mca_fbtl_base_module_1_0_0_t mca_fbtl_base_module_t;

ompi/mca/fbtl/ime/fbtl_ime.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "mpi.h"
1212

1313
#include "ompi/mca/fbtl/fbtl.h"
14+
#include "ompi/mca/fbtl/base/base.h"
1415
#include "ompi/mca/fbtl/ime/fbtl_ime.h"
1516

1617
/*
@@ -26,8 +27,8 @@ static mca_fbtl_base_module_1_0_0_t ime = {
2627
mca_fbtl_ime_pwritev, /* blocking write */
2728
mca_fbtl_ime_ipwritev, /* non-blocking write */
2829
mca_fbtl_ime_progress, /* module specific progress */
29-
mca_fbtl_ime_request_free /* free module specific data items on the request */
30-
};
30+
mca_fbtl_ime_request_free, /* free module specific data items on the request */
31+
mca_fbtl_base_check_atomicity /* check whether atomicity is supported on this fs */};
3132
/*
3233
* *******************************************************************
3334
* ************************* structure ends **************************
@@ -179,4 +180,4 @@ void mca_fbtl_ime_complete_cb (struct ime_aiocb *aiocb, int err, ssize_t bytes)
179180
{
180181
ssize_t *req_status = (ssize_t *) aiocb->user_context;
181182
*req_status = err == 0 ? bytes : FBTL_IME_REQ_ERROR;
182-
}
183+
}

ompi/mca/fbtl/posix/fbtl_posix.c

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@ static mca_fbtl_base_module_1_0_0_t posix = {
5858
#if defined (FBTL_POSIX_HAVE_AIO)
5959
mca_fbtl_posix_ipwritev, /* non-blocking write */
6060
mca_fbtl_posix_progress, /* module specific progress */
61-
mca_fbtl_posix_request_free /* free module specific data items on the request */
61+
mca_fbtl_posix_request_free, /* free module specific data items on the request */
6262
#else
6363
NULL, /* non-blocking write */
6464
NULL, /* module specific progress */
65-
NULL /* free module specific data items on the request */
65+
NULL, /* free module specific data items on the request */
6666
#endif
67+
mca_fbtl_posix_check_atomicity /* check whether atomicity is supported on this fs */
6768
};
6869
/*
6970
* *******************************************************************
@@ -291,3 +292,27 @@ void mca_fbtl_posix_request_free ( mca_ompio_request_t *req)
291292
#endif
292293
return;
293294
}
295+
296+
bool mca_fbtl_posix_check_atomicity ( ompio_file_t *file)
297+
{
298+
struct flock lock;
299+
300+
lock.l_type = F_WRLCK;
301+
lock.l_whence = SEEK_SET;
302+
lock.l_start = 0;
303+
lock.l_len = 0;
304+
lock.l_pid = 0;
305+
306+
if (fcntl(file->fd, F_GETLK, &lock) < 0)
307+
{
308+
#ifdef VERBOSE
309+
printf("Failed to get lock info for '%s': %s\n", filename, strerror(errno));
310+
#endif
311+
return false;
312+
}
313+
314+
#ifdef VERBOSE
315+
printf("Lock would have worked, l_type=%d\n", (int)lock.l_type);
316+
#endif
317+
return true;
318+
}

ompi/mca/fbtl/posix/fbtl_posix.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ ssize_t mca_fbtl_posix_ipwritev (ompio_file_t *file,
6464

6565
bool mca_fbtl_posix_progress ( mca_ompio_request_t *req);
6666
void mca_fbtl_posix_request_free ( mca_ompio_request_t *req);
67+
bool mca_fbtl_posix_check_atomicity ( ompio_file_t *file);
6768

6869
int mca_fbtl_posix_lock ( struct flock *lock, ompio_file_t *fh, int op,
6970
OMPI_MPI_OFFSET_TYPE iov_offset, off_t len, int flags,

ompi/mca/fbtl/pvfs2/fbtl_pvfs2.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "ompi_config.h"
2929
#include "mpi.h"
3030
#include "ompi/mca/fbtl/fbtl.h"
31+
#include "ompi/mca/fbtl/base/base.h"
3132
#include "ompi/mca/fbtl/pvfs2/fbtl_pvfs2.h"
3233

3334
/*
@@ -43,7 +44,8 @@ static mca_fbtl_base_module_1_0_0_t pvfs2 = {
4344
mca_fbtl_pvfs2_pwritev, /* blocking write */
4445
NULL, /* non-blocking write */
4546
NULL, /* module specific progress */
46-
NULL /* free module specific data items on the request */
47+
NULL, /* free module specific data items on the request */
48+
mca_fbtl_base_check_atomicity /* check whether atomicity is supported on this fs */
4749
};
4850
/*
4951
* *******************************************************************

ompi/mca/io/ompio/io_ompio_file_open.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ int mca_io_ompio_file_get_type_extent (ompi_file_t *fh,
311311
int mca_io_ompio_file_set_atomicity (ompi_file_t *fh,
312312
int flag)
313313
{
314-
int tmp;
314+
int tmp, ret = OMPI_SUCCESS;
315315
mca_common_ompio_data_t *data;
316316

317317
data = (mca_common_ompio_data_t *) fh->f_io_selected_data;
@@ -335,10 +335,22 @@ int mca_io_ompio_file_set_atomicity (ompi_file_t *fh,
335335
return OMPI_ERROR;
336336
}
337337

338-
data->ompio_fh.f_atomicity = flag;
338+
bool result;
339+
if ( flag ) {
340+
result = data->ompio_fh.f_fbtl->fbtl_check_atomicity(&data->ompio_fh);
341+
if ( result ) {
342+
data->ompio_fh.f_atomicity = flag;
343+
}
344+
else {
345+
ret = MPI_ERR_IO;
346+
}
347+
}
348+
else {
349+
data->ompio_fh.f_atomicity = flag;
350+
}
339351
OPAL_THREAD_UNLOCK(&fh->f_lock);
340352

341-
return OMPI_SUCCESS;
353+
return ret;
342354
}
343355

344356
int mca_io_ompio_file_get_atomicity (ompi_file_t *fh,

0 commit comments

Comments
 (0)