| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include "adio.h" |
| 7 |
|
| 8 |
#include "ad_lustre.h" |
| 9 |
|
| 10 |
#ifdef HAVE_UNISTD_H |
| 11 |
#include <unistd.h> |
| 12 |
#endif |
| 13 |
|
| 14 |
#include <stdint.h> |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
#ifndef LL_IOC_LADVISE |
| 27 |
#define LL_IOC_LADVISE _IOR('f', 250, struct llapi_lu_ladvise) |
| 28 |
|
| 29 |
enum lu_ladvise_type { |
| 30 |
LU_LADVISE_INVALID = 0, |
| 31 |
LU_LADVISE_WILLREAD = 1, |
| 32 |
LU_LADVISE_DONTNEED = 2, |
| 33 |
LU_LADVISE_LOCKNOEXPAND = 3, |
| 34 |
LU_LADVISE_LOCKAHEAD = 4, |
| 35 |
LU_LADVISE_MAX |
| 36 |
}; |
| 37 |
|
| 38 |
#define LU_LADVISE_NAMES { \ |
| 39 |
[LU_LADVISE_WILLREAD] = "willread", \ |
| 40 |
[LU_LADVISE_DONTNEED] = "dontneed", \ |
| 41 |
[LU_LADVISE_LOCKNOEXPAND] = "locknoexpand", \ |
| 42 |
[LU_LADVISE_LOCKAHEAD] = "lockahead", \ |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
struct llapi_lu_ladvise { |
| 49 |
__u16 lla_advice; |
| 50 |
__u16 lla_value1; |
| 51 |
__u32 lla_value2; |
| 52 |
__u64 lla_start; |
| 53 |
__u64 lla_end; |
| 54 |
__u32 lla_value3; |
| 55 |
__u32 lla_value4; |
| 56 |
}; |
| 57 |
enum ladvise_flag { |
| 58 |
LF_ASYNC = 0x00000001, |
| 59 |
LF_UNSET = 0x00000002, |
| 60 |
|
| 61 |
LF_NONBLOCK = 0x00000003, |
| 62 |
}; |
| 63 |
|
| 64 |
#define LADVISE_MAGIC 0x1ADF1CE0 |
| 65 |
|
| 66 |
#define LF_LOCKNOEXPAND_MASK LF_UNSET |
| 67 |
#define LF_LOCKAHEAD_MASK LF_NONBLOCK |
| 68 |
|
| 69 |
#define LF_DEFAULT_MASK LF_ASYNC |
| 70 |
|
| 71 |
#define LF_MASK (LF_ASYNC | LF_UNSET | LF_NONBLOCK) |
| 72 |
|
| 73 |
#define lla_lockahead_mode lla_value1 |
| 74 |
#define lla_peradvice_flags lla_value2 |
| 75 |
#define lla_lockahead_result lla_value3 |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
struct llapi_ladvise_hdr { |
| 81 |
__u32 lah_magic; |
| 82 |
__u32 lah_count; |
| 83 |
__u64 lah_flags; |
| 84 |
__u32 lah_value1; |
| 85 |
__u32 lah_value2; |
| 86 |
__u64 lah_value3; |
| 87 |
struct llapi_lu_ladvise lah_advise[0]; |
| 88 |
}; |
| 89 |
|
| 90 |
#define LAH_COUNT_MAX (1024) |
| 91 |
|
| 92 |
enum lock_mode_user { |
| 93 |
MODE_READ_USER = 1, |
| 94 |
MODE_WRITE_USER, |
| 95 |
MODE_MAX_USER, |
| 96 |
}; |
| 97 |
|
| 98 |
#define LOCK_MODE_NAMES { \ |
| 99 |
[MODE_READ_USER] = "READ",\ |
| 100 |
[MODE_WRITE_USER] = "WRITE"\ |
| 101 |
} |
| 102 |
|
| 103 |
enum lockahead_results { |
| 104 |
LLA_RESULT_SENT = 0, |
| 105 |
LLA_RESULT_DIFFERENT, |
| 106 |
LLA_RESULT_SAME, |
| 107 |
}; |
| 108 |
#endif |
| 109 |
|
| 110 |
|
| 111 |
int llapi_ladvise_lock(ADIO_File fd, unsigned long long flags, int num_advise, |
| 112 |
ADIO_Offset * offset, int stripe_size, int num_extents, |
| 113 |
ADIO_Offset step_size) |
| 114 |
{ |
| 115 |
struct llapi_ladvise_hdr *ladvise_hdr; |
| 116 |
int rc; |
| 117 |
int i; |
| 118 |
enum lock_mode_user mode = 0; |
| 119 |
|
| 120 |
if (num_advise < 1 || num_advise >= LAH_COUNT_MAX) { |
| 121 |
errno = EINVAL; |
| 122 |
|
| 123 |
|
| 124 |
return -1; |
| 125 |
} |
| 126 |
|
| 127 |
ladvise_hdr = |
| 128 |
ADIOI_Malloc(sizeof(struct llapi_ladvise_hdr) + |
| 129 |
sizeof(struct llapi_lu_ladvise) * num_advise); |
| 130 |
|
| 131 |
if (ladvise_hdr == NULL) { |
| 132 |
errno = ENOMEM; |
| 133 |
|
| 134 |
return -1; |
| 135 |
} |
| 136 |
ladvise_hdr->lah_magic = LADVISE_MAGIC; |
| 137 |
ladvise_hdr->lah_count = num_advise; |
| 138 |
ladvise_hdr->lah_flags = flags & LF_MASK; |
| 139 |
ladvise_hdr->lah_value1 = 0; |
| 140 |
ladvise_hdr->lah_value2 = 0; |
| 141 |
ladvise_hdr->lah_value3 = 0; |
| 142 |
|
| 143 |
if (fd->hints->fs_hints.lustre.lock_ahead_write) |
| 144 |
mode = MODE_WRITE_USER; |
| 145 |
else if (fd->hints->fs_hints.lustre.lock_ahead_read) |
| 146 |
mode = MODE_READ_USER; |
| 147 |
else |
| 148 |
MPI_Abort(MPI_COMM_WORLD, 1); |
| 149 |
|
| 150 |
for (i = 0; i < num_extents; ++i) { |
| 151 |
ladvise_hdr->lah_advise[i].lla_advice = LU_LADVISE_LOCKAHEAD; |
| 152 |
ladvise_hdr->lah_advise[i].lla_lockahead_mode = mode; |
| 153 |
ladvise_hdr->lah_advise[i].lla_peradvice_flags = flags | LF_ASYNC; |
| 154 |
ladvise_hdr->lah_advise[i].lla_start = *offset; |
| 155 |
ladvise_hdr->lah_advise[i].lla_end = *offset + stripe_size - 1;; |
| 156 |
ladvise_hdr->lah_advise[i].lla_value3 = 0; |
| 157 |
ladvise_hdr->lah_advise[i].lla_value4 = 0; |
| 158 |
ladvise_hdr->lah_advise[i].lla_lockahead_result = 0; |
| 159 |
*offset += step_size; |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
rc = ioctl(fd->fd_sys, LL_IOC_LADVISE, ladvise_hdr); |
| 164 |
|
| 165 |
if (rc < 0) { |
| 166 |
ADIOI_Free(ladvise_hdr); |
| 167 |
|
| 168 |
return -1; |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
fd->hints->fs_hints.lustre.lock_ahead_start_extent = ladvise_hdr->lah_advise[0].lla_start; |
| 175 |
fd->hints->fs_hints.lustre.lock_ahead_end_extent = |
| 176 |
ladvise_hdr->lah_advise[num_extents - 1].lla_end; |
| 177 |
|
| 178 |
|
| 179 |
#ifdef LOCK_AHEAD_DEBUG |
| 180 |
|
| 181 |
for (i = 0; i < num_extents; ++i) { |
| 182 |
if (ladvise_hdr->lah_advise[i].lla_lockahead_result) { |
| 183 |
fprintf(stderr, "%s(%d) " |
| 184 |
"lock ahead extent[%4.4d] {%ld,%ld} stripe {%ld,%ld} error %d\n", |
| 185 |
__func__, __LINE__, |
| 186 |
i, |
| 187 |
(long int) ladvise_hdr->lah_advise[i].lla_start, |
| 188 |
(long int) ladvise_hdr->lah_advise[i].lla_end, |
| 189 |
(long int) ladvise_hdr->lah_advise[i].lla_start / stripe_size, |
| 190 |
(long int) ladvise_hdr->lah_advise[i].lla_end / stripe_size, |
| 191 |
ladvise_hdr->lah_advise[i].lla_lockahead_result); |
| 192 |
} |
| 193 |
} |
| 194 |
|
| 195 |
#endif |
| 196 |
ADIOI_Free(ladvise_hdr); |
| 197 |
|
| 198 |
return 0; |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
int ADIOI_LUSTRE_request_only_lock_ioctl(ADIO_File fd) |
| 212 |
{ |
| 213 |
int err = 0; |
| 214 |
|
| 215 |
struct llapi_ladvise_hdr *noexpand_hdr; |
| 216 |
noexpand_hdr = ADIOI_Malloc(sizeof(struct llapi_ladvise_hdr) + sizeof(struct llapi_lu_ladvise)); |
| 217 |
if (!noexpand_hdr) { |
| 218 |
err = -ENOMEM; |
| 219 |
goto out; |
| 220 |
} |
| 221 |
|
| 222 |
noexpand_hdr->lah_magic = LADVISE_MAGIC; |
| 223 |
noexpand_hdr->lah_count = 1; |
| 224 |
noexpand_hdr->lah_flags = 0; |
| 225 |
noexpand_hdr->lah_value1 = 0; |
| 226 |
noexpand_hdr->lah_value2 = 0; |
| 227 |
noexpand_hdr->lah_value3 = 0; |
| 228 |
noexpand_hdr->lah_advise[0].lla_advice = LU_LADVISE_LOCKNOEXPAND; |
| 229 |
noexpand_hdr->lah_advise[0].lla_peradvice_flags = 0; |
| 230 |
|
| 231 |
noexpand_hdr->lah_advise[0].lla_value1 = 0; |
| 232 |
noexpand_hdr->lah_advise[0].lla_start = 0; |
| 233 |
noexpand_hdr->lah_advise[0].lla_end = 0; |
| 234 |
noexpand_hdr->lah_advise[0].lla_value3 = 0; |
| 235 |
noexpand_hdr->lah_advise[0].lla_value4 = 0; |
| 236 |
|
| 237 |
int rc = ioctl(fd->fd_sys, LL_IOC_LADVISE, noexpand_hdr); |
| 238 |
if (rc < 0) { |
| 239 |
ADIOI_Free(noexpand_hdr); |
| 240 |
|
| 241 |
return -1; |
| 242 |
} |
| 243 |
|
| 244 |
ADIOI_Free(noexpand_hdr); |
| 245 |
|
| 246 |
|
| 247 |
out: |
| 248 |
|
| 249 |
return err; |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
int ADIOI_LUSTRE_clear_locks(ADIO_File fd) |
| 255 |
{ |
| 256 |
int err = 0; |
| 257 |
int id; |
| 258 |
|
| 259 |
if (!fd->my_cb_nodes_index) { |
| 260 |
srand(time(NULL)); |
| 261 |
id = rand(); |
| 262 |
err = ioctl(fd->fd_sys, LL_IOC_GROUP_LOCK, id); |
| 263 |
err = ioctl(fd->fd_sys, LL_IOC_GROUP_UNLOCK, id); |
| 264 |
} |
| 265 |
return err; |
| 266 |
} |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
void ADIOI_LUSTRE_lock_ahead_ioctl(ADIO_File fd, int avail_cb_nodes, ADIO_Offset next_offset, |
| 271 |
int *error_code) |
| 272 |
{ |
| 273 |
|
| 274 |
int err = 0; |
| 275 |
int num_extents = fd->hints->fs_hints.lustre.lock_ahead_num_extents; |
| 276 |
int flags = fd->hints->fs_hints.lustre.lock_ahead_flags; |
| 277 |
ADIO_Offset offset = 0, step_size = 0; |
| 278 |
int stripe_size = fd->hints->striping_unit; |
| 279 |
|
| 280 |
int agg_idx = fd->my_cb_nodes_index; |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
if (agg_idx < 0) { |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
return; |
| 292 |
} |
| 293 |
#ifdef LOCK_AHEAD_DEBUG |
| 294 |
{ |
| 295 |
|
| 296 |
int rank_index; |
| 297 |
rank_index = (int) ((next_offset / stripe_size) % avail_cb_nodes); |
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
if (agg_idx != rank_index) { |
| 307 |
fprintf(stderr, "%s(%d) rank[%d] file system %d " |
| 308 |
"lock ahead debug R(%d)/W(%d), " |
| 309 |
"aggregator %d(%d)/%d(%d), " |
| 310 |
"offset %lld, start offset %lld, stripe %lld " |
| 311 |
"num_extents %d\n", |
| 312 |
__func__, __LINE__, |
| 313 |
fd->hints->ranklist[agg_idx], |
| 314 |
fd->file_system, |
| 315 |
fd->hints->fs_hints.lustre.lock_ahead_read, |
| 316 |
fd->hints->fs_hints.lustre.lock_ahead_write, |
| 317 |
agg_idx, rank_index, |
| 318 |
avail_cb_nodes, fd->hints->cb_nodes, |
| 319 |
(long long) next_offset, (long long) (next_offset / stripe_size * stripe_size), |
| 320 |
(long long) next_offset / stripe_size, num_extents); |
| 321 |
} |
| 322 |
|
| 323 |
if (agg_idx >= avail_cb_nodes) { |
| 324 |
fprintf(stderr, "%s(%d) file system %d " |
| 325 |
"lock ahead debug R(%d)/W(%d), " |
| 326 |
"aggregator %d(%d)/%d(%d), " |
| 327 |
"num_extents %d\n", |
| 328 |
__func__, __LINE__, fd->file_system, |
| 329 |
fd->hints->fs_hints.lustre.lock_ahead_read, |
| 330 |
fd->hints->fs_hints.lustre.lock_ahead_write, |
| 331 |
agg_idx, rank_index, avail_cb_nodes, fd->hints->cb_nodes, num_extents); |
| 332 |
MPI_Abort(MPI_COMM_WORLD, 1); |
| 333 |
} |
| 334 |
} |
| 335 |
#endif |
| 336 |
|
| 337 |
|
| 338 |
if (fd->access_mode & ADIO_RDONLY) { |
| 339 |
|
| 340 |
fd->hints->fs_hints.lustre.lock_ahead_write = 0; |
| 341 |
|
| 342 |
|
| 343 |
if (!(fd->hints->fs_hints.lustre.lock_ahead_read)) { |
| 344 |
fd->hints->fs_hints.lustre.lock_ahead_start_extent = 0; |
| 345 |
fd->hints->fs_hints.lustre.lock_ahead_end_extent = INT64_MAX; |
| 346 |
return; |
| 347 |
} |
| 348 |
} |
| 349 |
if (fd->access_mode & ADIO_WRONLY) { |
| 350 |
|
| 351 |
fd->hints->fs_hints.lustre.lock_ahead_read = 0; |
| 352 |
|
| 353 |
|
| 354 |
if (!(fd->hints->fs_hints.lustre.lock_ahead_write)) { |
| 355 |
fd->hints->fs_hints.lustre.lock_ahead_start_extent = 0; |
| 356 |
fd->hints->fs_hints.lustre.lock_ahead_end_extent = INT64_MAX; |
| 357 |
return; |
| 358 |
} |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
step_size = (ADIO_Offset) avail_cb_nodes *stripe_size; |
| 363 |
|
| 364 |
if (next_offset == 0) { |
| 365 |
offset = (ADIO_Offset) agg_idx *stripe_size; |
| 366 |
} else |
| 367 |
offset = next_offset / stripe_size * stripe_size; |
| 368 |
|
| 369 |
err = llapi_ladvise_lock(fd, flags, num_extents, &offset, stripe_size, num_extents, step_size); |
| 370 |
|
| 371 |
|
| 372 |
if (err == -1) { |
| 373 |
#ifdef LOCK_AHEAD_DEBUG |
| 374 |
fprintf(stderr, "%s(%d) file system %d " |
| 375 |
"lock ahead failure R(%d)/W(%d), " |
| 376 |
"aggregator %d/%d, " |
| 377 |
"next offset %lld, stripe %lld, " |
| 378 |
"last offset %lld, stripe %lld, " |
| 379 |
"step %lld, stripe size %lld " |
| 380 |
"num_extents %d\n", |
| 381 |
__func__, __LINE__, fd->file_system, |
| 382 |
fd->hints->fs_hints.lustre.lock_ahead_read, |
| 383 |
fd->hints->fs_hints.lustre.lock_ahead_write, |
| 384 |
agg_idx, |
| 385 |
avail_cb_nodes, |
| 386 |
(long long) next_offset, (long long) next_offset / stripe_size, |
| 387 |
(long long) offset, (long long) offset / stripe_size, |
| 388 |
(long long) step_size, (long long) stripe_size, num_extents); |
| 389 |
#endif |
| 390 |
fd->hints->fs_hints.lustre.lock_ahead_read = 0; |
| 391 |
fd->hints->fs_hints.lustre.lock_ahead_write = 0; |
| 392 |
fd->hints->fs_hints.lustre.lock_ahead_start_extent = 0; |
| 393 |
fd->hints->fs_hints.lustre.lock_ahead_end_extent = INT64_MAX; |
| 394 |
|
| 395 |
*error_code = ADIOI_Err_create_code("ADIOI_LUSTRE_lock_ahead_ioctl", fd->filename, errno); |
| 396 |
if (agg_idx == 0) { |
| 397 |
fprintf(stderr, "%s: ioctl(LL_IOC_LADVISE) \'%s\'\n", __func__, strerror(errno)); |
| 398 |
} |
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
} |
| 404 |
|
| 405 |
|
| 406 |
return; |
| 407 |
} |