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

📄 sanity.c

📁 非常经典的一个分布式系统
💻 C
📖 第 1 页 / 共 4 页
字号:
        snprintf(file, MAX_PATH_LENGTH, "%s/test_t54_file", lustre_path);        t_echo_create(file, "fcntl should return 0 when succeed");        fd = open(file, O_RDWR);        if (fd < 0) {                printf("\nerror open file: %s\n", strerror(errno));                return(-1);        }        lock.l_type   = F_WRLCK;        lock.l_start  = 0;        lock.l_whence = 0;        lock.l_len    = 1;        if ((err = t_fcntl(fd, F_SETLKW, &lock)) != 0) {                fprintf(stderr, "fcntl returned: %d (%s)\n",                         err, strerror(err));                close(fd);                t_unlink(file);                return (-1);        }        lock.l_type   = F_UNLCK;        t_fcntl(fd, F_SETLKW, &lock);        close(fd);        t_unlink(file);        LEAVE();}/* for O_DIRECTORY */#ifndef _GNU_SOURCE#define _GNU_SOURCE#endif#define STRIPE_SIZE       (2048 * 2048)#define STRIPE_OFFSET           0#define STRIPE_COUNT            1int t55(char *name){        char path[MAX_PATH_LENGTH] = "";        char file[MAX_PATH_LENGTH] = "";        struct lov_user_md *lum = NULL;        struct lov_user_ost_data *lo = NULL;        int index, fd, buflen, rc;        ENTRY("setstripe/getstripe");        snprintf(path, MAX_PATH_LENGTH, "%s/test_t55", lustre_path);        snprintf(file, MAX_PATH_LENGTH, "%s/test_t55/file_t55", lustre_path);              buflen = sizeof(struct lov_user_md);        buflen += STRIPE_COUNT * sizeof(struct lov_user_ost_data);        lum = (struct lov_user_md *)malloc(buflen);        if (!lum) {                printf("out of memory!\n");                return -1;        }        memset(lum, 0, buflen);        t_mkdir(path);        rc = llapi_file_create(path, STRIPE_SIZE, STRIPE_OFFSET,                               STRIPE_COUNT, LOV_PATTERN_RAID0);        if (rc) {                printf("llapi_file_create failed: rc = %d (%s) \n",                       rc, strerror(-rc));                t_rmdir(path);                free(lum);                return -1;        }        fd = open(file, O_CREAT | O_RDWR, 0644);        if (fd < 0) {                printf("open file(%s) failed: rc = %d (%s) \n)",                       file, fd, strerror(errno));                t_rmdir(path);                free(lum);                return -1;        }                lum->lmm_magic = LOV_USER_MAGIC;        lum->lmm_stripe_count = STRIPE_COUNT;        rc = ioctl(fd, LL_IOC_LOV_GETSTRIPE, lum);        if (rc) {                printf("dir:ioctl(LL_IOC_LOV_GETSTRIPE) failed: rc = %d(%s)\n",                       rc, strerror(errno));                close(fd);                t_unlink(file);                t_rmdir(path);                free(lum);                return -1;        }        close(fd);        if (opt_verbose) {                printf("lmm_magic:          0x%08X\n",  lum->lmm_magic);                printf("lmm_object_id:      "LPX64"\n", lum->lmm_object_id);                printf("lmm_object_gr:      "LPX64"\n", lum->lmm_object_gr);                printf("lmm_stripe_count:   %u\n", (int)lum->lmm_stripe_count);                printf("lmm_stripe_size:    %u\n",      lum->lmm_stripe_size);                printf("lmm_stripe_pattern: %x\n",      lum->lmm_pattern);                        for (index = 0; index < lum->lmm_stripe_count; index++) {                        lo = lum->lmm_objects + index;                        printf("object %d:\n", index);                        printf("\tobject_gr:    "LPX64"\n", lo->l_object_gr);                        printf("\tobject_id:    "LPX64"\n", lo->l_object_id);                        printf("\tost_gen:      %#x\n", lo->l_ost_gen);                        printf("\tost_idx:      %u\n", lo->l_ost_idx);                }        }        if (lum->lmm_magic != LOV_USER_MAGIC ||            lum->lmm_pattern != LOV_PATTERN_RAID0 ||            lum->lmm_stripe_size != STRIPE_SIZE ||            lum->lmm_objects[0].l_ost_idx != STRIPE_OFFSET ||            lum->lmm_stripe_count != STRIPE_COUNT) {                printf("incorrect striping information!\n");                t_unlink(file);                t_rmdir(path);                free(lum);                return -1;        }        t_unlink(file);        /* setstripe on regular file */        rc = llapi_file_create(file, STRIPE_SIZE, STRIPE_OFFSET,                               STRIPE_COUNT, LOV_PATTERN_RAID0);        if (rc) {                printf("llapi_file_create failed: rc = %d (%s) \n",                       rc, strerror(-rc));                t_unlink(file);                t_rmdir(path);                free(lum);                return -1;        }        fd = open(file, O_RDWR, 0644);        if (fd < 0) {                printf("failed to open(%s): rc = %d (%s)\n",                        file, fd, strerror(errno));                t_unlink(file);                t_rmdir(path);                free(lum);                return -1;        }        lum->lmm_magic = LOV_USER_MAGIC;        lum->lmm_stripe_count = STRIPE_COUNT;        rc = ioctl(fd, LL_IOC_LOV_GETSTRIPE, lum);        if (rc) {                printf("file:ioctl(LL_IOC_LOV_GETSTRIPE) failed: rc = %d(%s)\n",                       rc, strerror(errno));                close(fd);                t_unlink(file);                t_rmdir(path);                free(lum);                return -1;        }        close(fd);        if (opt_verbose) {                printf("lmm_magic:          0x%08X\n",  lum->lmm_magic);                printf("lmm_object_id:      "LPX64"\n", lum->lmm_object_id);                printf("lmm_object_gr:      "LPX64"\n", lum->lmm_object_gr);                printf("lmm_stripe_count:   %u\n", (int)lum->lmm_stripe_count);                printf("lmm_stripe_size:    %u\n",      lum->lmm_stripe_size);                printf("lmm_stripe_pattern: %x\n",      lum->lmm_pattern);                        for (index = 0; index < lum->lmm_stripe_count; index++) {                        lo = lum->lmm_objects + index;                        printf("object %d:\n", index);                        printf("\tobject_gr:    "LPX64"\n", lo->l_object_gr);                        printf("\tobject_id:    "LPX64"\n", lo->l_object_id);                        printf("\tost_gen:      %#x\n", lo->l_ost_gen);                        printf("\tost_idx:      %u\n", lo->l_ost_idx);                }        }        if (lum->lmm_magic != LOV_USER_MAGIC ||            lum->lmm_pattern != LOV_PATTERN_RAID0 ||            lum->lmm_stripe_size != STRIPE_SIZE ||            lum->lmm_objects[0].l_ost_idx != STRIPE_OFFSET ||            lum->lmm_stripe_count != STRIPE_COUNT) {                printf("incorrect striping information!\n");                t_unlink(file);                t_rmdir(path);                free(lum);                return -1;        }        t_unlink(file);        t_rmdir(path);        free(lum);        LEAVE();}/* * getdirentries should return -1 and set errno to EINVAL when the size * specified as an argument is too small to contain at least one entry * (see bugzilla ticket 12229) */int t56(char *name){        int fd;        size_t nbytes;        off_t basep = 0;        ssize_t rc = 0;        struct dirent dir;        ENTRY("getdirentries should fail if nbytes is too small");        /* Set count to be very small.  The result should be EINVAL */        nbytes = 8;        /* open the directory and call getdirentries */        fd = t_opendir(lustre_path);        rc = getdirentries(fd, (char *)&dir, nbytes, &basep);        if (rc != -1) {                printf("Test failed: getdirentries returned %ld\n", rc);                t_close(fd);                return -1;        }        if (errno != EINVAL) {                printf("Test failed: getdirentries returned %ld but errno is set"                                " to %d (should be EINVAL)\n", rc, errno);                t_close(fd);                return -1;        }        t_close(fd);        LEAVE();}extern void __liblustre_setup_(void);extern void __liblustre_cleanup_(void);void usage(char *cmd){        printf("\n"               "usage: %s [--only {test}] --target mgsnid:/fsname\n",               cmd);        printf("       %s --dumpfile dumpfile\n", cmd);        exit(-1);}struct testlist {        int (*test)(char *name);        char *name;} testlist[] = {        { t1, "1" },        { t2, "2" },        { t3, "3" },        { t4, "4" },        { t6, "6" },        { t6b, "6b" },        { t7, "7" },        { t8, "8" },        { t9, "9" },        { t10, "10" },        { t11, "11" },        { t12, "12" },        { t13, "13" },        { t14, "14" },        { t15, "15" },        { t16, "16" },        { t17, "17" },        { t18, "18" },        { t18b, "t8b" },        { t19, "19" },        { t20, "20" },        { t21, "21" },        { t22, "22" },        { t23, "23" },        { t50, "50" },        { t50b, "50b" },        { t51, "51" },        { t53, "53" },        { t54, "54" },        { t55, "55" },        { t56, "56" },        { NULL, NULL }};int main(int argc, char * const argv[]){        struct testlist *test;        int opt_index, c, rc = 0, numonly = 0;        char *only[100];        static struct option long_opts[] = {                {"dumpfile", 1, 0, 'd'},                {"only", 1, 0, 'o'},                {"target", 1, 0, 't'},                {"verbose", 1, 0, 'v'},                {0, 0, 0, 0}        };        while ((c = getopt_long(argc, argv, "d:o:t:v", long_opts, &opt_index)) != -1) {                switch (c) {                case 'd':                        setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);                        break;                case 'o':                        if (numonly == 0)                                printf("Only running test(s): ");                        printf("%s ", optarg);                        only[numonly++] = optarg;                        break;                case 't':                        setenv(ENV_LUSTRE_MNTTGT, optarg, 1);                        break;                case 'v':                        opt_verbose++;                        break;                default:                        usage(argv[0]);                        break;                }        }        if (getenv(ENV_LUSTRE_MNTTGT) == NULL &&            getenv(ENV_LUSTRE_DUMPFILE) == NULL)                usage(argv[0]);        if (optind != argc)                usage(argv[0]);        printf("\n");        __liblustre_setup_();        buf_size = _npages * PAGE_SIZE;        if (opt_verbose)                printf("allocating %d bytes buffer\n", buf_size);        buf_alloc = calloc(1, buf_size);        if (buf_alloc == NULL) {                fprintf(stderr, "error allocating %d\n", buf_size);                exit(-ENOMEM);        }        for (test = testlist; test->test != NULL; test++) {                int run = 1, i;                if (numonly > 0) {                        int len;                        run = 0;                        len = strlen(test->name);                        for (i = 0; i < numonly; i++) {                                int olen = strlen(only[i]);                                if (len < olen)                                        continue;                                if (strncmp(only[i], test->name, olen) == 0) {                                        switch(test->name[olen]) {                                        case '0': case '1': case '2': case '3':                                        case '4': case '5': case '6': case '7':                                        case '8': case '9':                                                break;                                        default:                                                run = 1;                                                break;                                        }                                }                        }                }                if (run && (rc = (test->test)(test->name)) != 0)                        break;        }        free(buf_alloc);        printf("liblustre is about to shutdown\n");        __liblustre_cleanup_();        printf("complete successfully\n");        return rc;}

⌨️ 快捷键说明

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