Debian Codegraph @

src/mpi/romio/adio/ad_lustre/ad_lustre_open.c

raw symbols SCIP
1 /*
2 * Copyright (C) by Argonne National Laboratory
3 * See COPYRIGHT in top-level directory
4 */
5
6 #include "ad_lustre.h"
7
8 /* what is the basis for this define?
9 * what happens if there are more than 1k UUIDs? */
10
11 #define MAX_LOV_UUID_COUNT 1000
12
13 int ADIOI_LUSTRE_clear_locks(ADIO_File fd); /* in ad_lustre_lock.c */
14 int ADIOI_LUSTRE_request_only_lock_ioctl(ADIO_File fd); /* in ad_lustre_lock.c */
15
16 void ADIOI_LUSTRE_Open(ADIO_File fd, int *error_code)
17 {
18 int perm, old_mask, amode, amode_direct, root;
19 int lumlen, myrank, flag, set_layout = 0, err;
20 struct lov_user_md *lum = NULL;
21 char *value;
22 ADIO_Offset str_factor = -1, str_unit = 0, start_iodev = -1;
23 size_t value_sz = (MPI_MAX_INFO_VAL + 1) * sizeof(char);
24
25 #if defined(MPICH) || !defined(PRINT_ERR_MSG)
26 static char myname[] = "ADIOI_LUSTRE_OPEN";
27 #endif
28
29 MPI_Comm_rank(fd->comm, &myrank);
30
31 if (fd->perm == ADIO_PERM_NULL) {
32 old_mask = umask(022);
33 umask(old_mask);
34 perm = old_mask ^ 0666;
35 } else
36 perm = fd->perm;
37
38 amode = 0;
39 if (fd->access_mode & ADIO_CREATE)
40 amode = amode | O_CREAT;
41 if (fd->access_mode & ADIO_RDONLY)
42 amode = amode | O_RDONLY;
43 if (fd->access_mode & ADIO_WRONLY)
44 amode = amode | O_WRONLY;
45 if (fd->access_mode & ADIO_RDWR)
46 amode = amode | O_RDWR;
47 if (fd->access_mode & ADIO_EXCL)
48 amode = amode | O_EXCL;
49
50 amode_direct = amode | O_DIRECT;
51
52 /* odd length here because lov_user_md contains some fixed data and
53 * then a list of 'lmm_objects' representing stripe */
54 lumlen = sizeof(struct lov_user_md) + MAX_LOV_UUID_COUNT * sizeof(struct lov_user_ost_data);
55 lum = (struct lov_user_md *) ADIOI_Calloc(1, lumlen);
56
57 value = (char *) ADIOI_Malloc(value_sz);
58 /* we already validated in LUSTRE_SetInfo that these are going to be the same */
59 if (fd->info != MPI_INFO_NULL) {
60 /* striping information */
61 ADIOI_Info_get(fd->info, "striping_unit", MPI_MAX_INFO_VAL, value, &flag);
62 if (flag)
63 str_unit = atoll(value);
64
65 ADIOI_Info_get(fd->info, "striping_factor", MPI_MAX_INFO_VAL, value, &flag);
66 if (flag)
67 str_factor = atoll(value);
68
69 ADIOI_Info_get(fd->info, "start_iodevice", MPI_MAX_INFO_VAL, value, &flag);
70 if (flag)
71 start_iodev = atoll(value);
72 }
73 if ((str_factor > 0) || (str_unit > 0) || (start_iodev >= 0))
74 set_layout = 1;
75
76 /* if hints were set, we need to delay creation of any lustre objects.
77 * However, if we open the file with O_LOV_DELAY_CREATE and don't call the
78 * follow-up ioctl, subsequent writes will fail */
79 if (myrank == 0 && set_layout)
80 amode = amode | O_LOV_DELAY_CREATE;
81
82 fd->fd_sys = open(fd->filename, amode, perm);
83 if (fd->fd_sys == -1)
84 goto fn_exit;
85
86 root = (fd->hints->ranklist == NULL) ? 0 : fd->hints->ranklist[0];
87
88 /* we can only set these hints on new files */
89 /* It was strange and buggy to open the file in the hint path. Instead,
90 * we'll apply the file tunings at open time */
91 if ((amode & O_CREAT) && set_layout) {
92 /* if user has specified striping info, first aggregator tries to set
93 * it */
94 if (myrank == root || fd->comm == MPI_COMM_SELF) {
95 lum->lmm_magic = LOV_USER_MAGIC;
96 lum->lmm_pattern = 0;
97 /* crude check for overflow of lustre internal datatypes.
98 * Silently cap to large value if user provides a value
99 * larger than lustre supports */
100 if (str_unit > UINT_MAX)
101 lum->lmm_stripe_size = UINT_MAX;
102 else
103 /* cast from 64 to 32 ok: we checked/set above */
104 lum->lmm_stripe_size = (unsigned int) str_unit;
105
106 if (str_factor > USHRT_MAX)
107 lum->lmm_stripe_count = USHRT_MAX;
108 else
109 lum->lmm_stripe_count = str_factor;
110
111 if (start_iodev > USHRT_MAX)
112 lum->lmm_stripe_offset = USHRT_MAX;
113 else
114 lum->lmm_stripe_offset = start_iodev;
115 err = ioctl(fd->fd_sys, LL_IOC_LOV_SETSTRIPE, lum);
116 if (err == -1 && errno != EEXIST) {
117 fprintf(stderr, "Failure to set stripe info %s \n", strerror(errno));
118 /* not a fatal error, but user might care to know */
119 }
120 } /* End of striping parameters validation */
121 }
122
123 /* Pascal Deveze reports that, even though we pass a
124 * "GETSTRIPE" (read) flag to the ioctl, if some of the values of this
125 * struct are uninitialized, the call can give an error. zero it out in case
126 * there are other members that must be initialized and in case
127 * lov_user_md struct changes in future */
128 memset(lum, 0, lumlen);
129 lum->lmm_magic = LOV_USER_MAGIC;
130 if (myrank == root || fd->comm == MPI_COMM_SELF) {
131 /* only one rank needs to consult the file for striping information.
132 * In fact, only the i/o aggregators are in this path: we'll distribute
133 * stripe information to all processes in ad_opencoll.c and save them
134 * as hints in the generic hint processing code */
135 err = ioctl(fd->fd_sys, LL_IOC_LOV_GETSTRIPE, (void *) lum);
136 if (!err) {
137 fd->hints->striping_unit = lum->lmm_stripe_size;
138 fd->hints->striping_factor = lum->lmm_stripe_count;
139 fd->hints->start_iodevice = lum->lmm_stripe_offset;
140 }
141 }
142
143 if (fd->access_mode & ADIO_APPEND)
144 fd->fp_ind = fd->fp_sys_posn = lseek(fd->fd_sys, 0, SEEK_END);
145
146 fd->fd_direct = -1;
147 if (fd->direct_write || fd->direct_read) {
148 fd->fd_direct = open(fd->filename, amode_direct, perm);
149 if (fd->fd_direct != -1) {
150 fd->d_mem = fd->d_miniosz = (1 << 12);
151 } else {
152 perror("cannot open file with O_Direct");
153 fd->direct_write = fd->direct_read = 0;
154 }
155 }
156 #ifdef HAVE_LUSTRE_LOCKAHEAD
157 if (fd->hints->fs_hints.lustre.lock_ahead_read || fd->hints->fs_hints.lustre.lock_ahead_write) {
158 ADIOI_LUSTRE_clear_locks(fd);
159 ADIOI_LUSTRE_request_only_lock_ioctl(fd);
160 }
161 #endif
162
163
164 fn_exit:
165 ADIOI_Free(lum);
166 ADIOI_Free(value);
167 /* --BEGIN ERROR HANDLING-- */
168 if (fd->fd_sys == -1 || ((fd->fd_direct == -1) && (fd->direct_write || fd->direct_read))) {
169 *error_code = ADIOI_Err_create_code(myname, fd->filename, errno);
170 }
171 /* --END ERROR HANDLING-- */
172 else
173 *error_code = MPI_SUCCESS;
174
175 }