static void do_join(char *name) { dlm_lshandle_t *dh; uint32_t flags = 0; if (opt_excl) flags |= DLM_LSFL_NEWEXCL; if (opt_fs) flags |= DLM_LSFL_FS; printf("Joining lockspace \"%s\" permission %o %s\n", name, create_mode, flags ? flag_str(flags) : ""); fflush(stdout); dh = dlm_new_lockspace(name, create_mode, flags); if (!dh) { fprintf(stderr, "dlm_new_lockspace %s error %d\n", name, errno); exit(-1); } dlm_close_lockspace(dh); /* there's no autofree so the ls should stay around */ printf("done\n"); }
int main(int argc, char *argv[]) { uint32_t major, minor, patch; struct lk *lk; int i, rv, maxi = 0, quit = 0; srandom(time(NULL)); decode_arguments(argc, argv); if (maxn < maxr) { printf("number of resources must be >= number of locks\n"); return -1; } if (maxn % maxr) { printf("number of locks must be multiple of number of resources\n"); return -1; } printf("maxn = %d\n", maxn); printf("maxr = %d\n", maxr); printf("locks per resource = %d\n", maxn / maxr); signal(SIGTERM, sigterm_handler); client_init(); locks = malloc(maxn * sizeof(struct lk)); if (!locks) { printf("no mem for %d locks\n", maxn); return 0; } memset(locks, 0, sizeof(*locks)); lk = locks; for (i = 0; i < maxn; i++) { lk->id = i; lk->grmode = -1; lk->rqmode = -1; lk++; } rv = dlm_kernel_version(&major, &minor, &patch); if (rv < 0) { printf("can't detect dlm in kernel %d\n", errno); return -1; } printf("dlm kernel version: %u.%u.%u\n", major, minor, patch); dlm_library_version(&major, &minor, &patch); printf("dlm library version: %u.%u.%u\n", major, minor, patch); if (openclose_ls) { printf("dlm_open_lockspace...\n"); dh = dlm_open_lockspace("test"); if (!dh) { printf("dlm_open_lockspace error %lu %d\n", (unsigned long)dh, errno); return -ENOTCONN; } } else { printf("dlm_new_lockspace...\n"); dh = dlm_new_lockspace("test", 0600, timewarn ? DLM_LSFL_TIMEWARN : 0); if (!dh) { printf("dlm_new_lockspace error %lu %d\n", (unsigned long)dh, errno); return -ENOTCONN; } } rv = dlm_ls_get_fd(dh); if (rv < 0) { printf("dlm_ls_get_fd error %d %d\n", rv, errno); dlm_release_lockspace("test", dh, 1); return rv; } libdlm_fd = rv; client_add(libdlm_fd, &maxi); if (opt_cmd) { process_command(&quit); goto out; } client_add(STDIN_FILENO, &maxi); printf("Type EXIT to finish, help for usage\n"); while (1) { rv = poll(pollfd, maxi + 1, -1); if (rv < 0 && errno == EINTR) continue; if (rv < 0) printf("poll error %d errno %d\n", rv, errno); for (i = 0; i <= maxi; i++) { if (client[i].fd < 0) continue; if (pollfd[i].revents & POLLIN) { if (pollfd[i].fd == libdlm_fd) process_libdlm(); else if (pollfd[i].fd == STDIN_FILENO) process_command(&quit); } if (pollfd[i].revents & (POLLHUP | POLLERR | POLLNVAL)) client_dead(i); } if (quit && all_unlocks_done()) break; } out: if (openclose_ls) { printf("dlm_close_lockspace\n"); rv = dlm_close_lockspace(dh); if (rv < 0) printf("dlm_close_lockspace error %d %d\n", rv, errno); } else { printf("dlm_release_lockspace\n"); rv = dlm_release_lockspace("test", dh, 1); if (rv < 0) printf("dlm_release_lockspace error %d %d\n", rv, errno); } return 0; }