⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parallel_grouplock.c

📁 lustre 1.6.5 source code
💻 C
📖 第 1 页 / 共 3 页
字号:
                        }                        usleep(100);                        MPI_Test(&req1, &flag1, MPI_STATUS_IGNORE);                        MPI_Test(&req2, &flag2, MPI_STATUS_IGNORE);                } while (!(flag1 && flag2));        }        if ( rank == 1 || rank == 2) {                if ((rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid)) == -1) {                        sprintf(errmsg, "ioctl GROUP_UNLOCK of file %s return %d",                                filename, rc);                        FAIL(errmsg);                }        }        MPI_Barrier(MPI_COMM_WORLD);}/* * process1 attempts CW(gid=1) -- granted * process2 attempts PW -- blocked * process2 attempts CW(gid=2) -- blocked * process3 attempts CW(gid=2) -- blocked * process1 releases CW(gid=1) *   process2's CW(gid=2) should be granted *   process3's CW(gid=2) should be granted * * after process1 release CW(gid=1), there are two pathes: *   path 1. process2 get PW *   path 2. process3 get CW(gid=2) * * green: Also about test6 - by definition if P* and CW lock are waiting, *        CW lock have bigger priority and should be granted first when it becomes *        possible. So after process1 releases its CW lock, process3 should always *        get CW lock, and when it will release it, process 2 will proceed with read *        and then with getting CW lock * * XXX This test does not make any sence at all the way it is described right * now, hence disabled. */void grouplock_test6(char *filename, int fd, char *errmsg){}/* Just test some error paths with invalid requests */void grouplock_errorstest(char *filename, int fd, char *errmsg){        int gid = 1;        int rc;        /* To not do lots of separate tests with lots of fd opening/closing,           different parts of this test are performed in different processes */                   if (rank == 0 || rank == 1 ) {                if ((rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid)) == -1) {                        sprintf(errmsg, "ioctl GROUP_LOCK of file %s return %d",                                filename, rc);                        FAIL(errmsg);                }        }        /* second group lock on same fd, same gid */        if (rank == 0) {                if ((rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid)) == -1) {                        if (errno != EINVAL) {                                sprintf(errmsg, "Double GROUP lock failed with errno %d instead of EINVAL\n", errno);                                FAIL(errmsg);                        }                 } else {                        FAIL("Taking second GROUP lock on same fd succeed\n");                }        }        /* second group lock on same fd, different gid */        if (rank == 1) {                if ((rc = ioctl(fd, LL_IOC_GROUP_LOCK, gid + 1)) == -1) {                        if (errno != EINVAL) {                                sprintf(errmsg, "Double GROUP lock different gid failed with errno %d instead of EINVAL\n", errno);                                FAIL(errmsg);                        }                 } else {                        FAIL("Taking second GROUP lock on same fd, different gid, succeed\n");                }        }        /* GROUP unlock with wrong gid */        if (rank == 0 || rank == 1) {                if ((rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid + 1)) == -1) {                        if (errno != EINVAL) {                                sprintf(errmsg, "GROUP unlock with wrong gid failed with errno %d instead of EINVAL\n",                                        errno);                                FAIL(errmsg);                        }                 } else {                        FAIL("GROUP unlock with wrong gid succeed\n");                }        }        if (rank == 0 || rank == 1) {                if ((rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid)) == -1) {                        sprintf(errmsg, "ioctl GROUP_UNLOCK of file %s return %d",                                filename, rc);                        FAIL(errmsg);                }        }        /* unlock of never locked fd */        if (rank == 2) {                if ((rc = ioctl(fd, LL_IOC_GROUP_UNLOCK, gid)) == -1) {                        if (errno != EINVAL) {                                sprintf(errmsg, "GROUP unlock on never locked fd failed with errno %d instead of EINVAL\n",                                        errno);                                FAIL(errmsg);                        }                 } else {                        FAIL("GROUP unlock on never locked fd succeed\n");                }        }}void grouplock_file(char *name, int items){        int i, fd;        char filename[MAX_FILENAME_LEN];        char errmsg[MAX_FILENAME_LEN+20];        sprintf(filename, "%s/%s", testdir, name);        if (items == 4) {                if ((fd = open(filename, O_RDWR | O_NONBLOCK)) == -1) {                        sprintf(errmsg, "open of file %s", filename);                        FAIL(errmsg);                }        } else if ((fd = open(filename, O_RDWR)) == -1) {                sprintf(errmsg, "open of file %s", filename);                FAIL(errmsg);        }        MPI_Barrier(MPI_COMM_WORLD);        switch (items) {        case 1:                grouplock_test1(filename, fd, errmsg);                break;        case 2:                grouplock_test2(filename, fd, errmsg);                break;        case 3:                grouplock_test3(filename, fd, errmsg);                break;        case 4:                grouplock_test4(filename, fd, errmsg);                break;        case 5:                grouplock_test5(filename, fd, errmsg);                break;        case 6:                grouplock_test6(filename, fd, errmsg);                break;        case 7:                grouplock_errorstest(filename, fd, errmsg);                break;        default:                sprintf(errmsg, "wrong test case number %d (should be <= %d)",                        items, LPGL_TEST_ITEMS);                FAIL(errmsg);        }        MPI_Barrier(MPI_COMM_WORLD);        if (close(fd) == -1) {                sprintf(errmsg, "close of file %s", filename);                FAIL(errmsg);        }}void parallel_grouplock(void){        int i;        for (i = 1;i <= LPGL_TEST_ITEMS;++i) {                begin("setup");                create_file("parallel_grouplock", LPGL_FILEN, 0);                end("setup");                begin("test");                grouplock_file("parallel_grouplock", i);                end("test");                begin("cleanup");                remove_file("parallel_grouplock");                end("cleanup");        }}void usage(char *proc){        int i;        if (rank == 0) {                printf("Usage: %s [-h] -d <testdir>\n", proc);                printf("           [-n \"13\"] [-v] [-V #] [-g]\n");                printf("\t-h: prints this help message\n");                printf("\t-d: the directory in which the tests will run\n");                printf("\t-n: repeat test # times\n");                printf("\t-v: increase the verbositly level by 1\n");                printf("\t-V: select a specific verbosity level\n");                printf("\t-g: debug mode\n");        }        MPI_Initialized(&i);        if (i) MPI_Finalize();        exit(0);}int main(int argc, char *argv[]){        char c;        int i, iterations = 1;        int tr = 1;        /* Check for -h parameter before MPI_Init so the binary can be           called directly, without, for instance, mpirun */        for (i = 1; i < argc; ++i) {                if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help"))                        usage(argv[0]);        }        MPI_Init(&argc, &argv);        MPI_Comm_rank(MPI_COMM_WORLD, &rank);        MPI_Comm_size(MPI_COMM_WORLD, &size);//        MPI_Comm_set_attr(MPI_COMM_WORLD, MPI_WTIME_IS_GLOBAL, &tr);        /* Parse command line options */        while (1) {                c = getopt(argc, argv, "d:ghn:vV:");                if (c == -1)                        break;                switch (c) {                case 'd':                        testdir = optarg;                        break;                case 'g':                        debug = 1;                        break;                case 'h':                        usage(argv[0]);                        break;                case 'n':                        iterations = atoi(optarg);                        break;                case 'v':                        verbose += 1;                        break;                case 'V':                        verbose = atoi(optarg);                        break;                }        }        if (rank == 0)                printf("%s is running with %d process(es) %s\n",                       argv[0], size, debug ? "in DEBUG mode" : "\b\b");        if (size < MAX_GLHOST) {                fprintf(stderr, "Error: "                        "should be at least four processes to run the test!\n");                MPI_Abort(MPI_COMM_WORLD, 2);        }        if (testdir == NULL && rank == 0) {                fprintf(stderr, "Please specify a test directory! (\"%s -h\" for help)\n",                       argv[0]);                MPI_Abort(MPI_COMM_WORLD, 2);        }        lp_gethostname();        for (i = 0; i < iterations; ++i) {                if (rank == 0)                        printf("%s: Running test #%s(iter %d)\n",                               timestamp(), argv[0], i);                parallel_grouplock();                MPI_Barrier(MPI_COMM_WORLD);        }        if (rank == 0) {                printf("%s: All tests passed!\n", timestamp());        }        MPI_Finalize();        return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -