// finalize initialization void finalize_init() { // if filesystem is not mounted go ahead if(!filesystem_is_mounted()) { if(global_state==0) { printf("File system is not mounted, final step of initialization is delayed\n"); global_state=1; } return; } // get filesystem handle if (dm_path_to_fshandle(fsname, &fs_hanp, &fs_hlen) == -1) { fprintf(stderr, "dm_path_to_fshandle, %d/%s\n", errno, strerror(errno)); exit(1); } // setup event disposition for read, write and truncate events printf("Setting disposition for READ, WRITE and TRUNCATE DMAPI events\n"); set_events(fs_hanp, fs_hlen); // recover existing tokens (if any) printf("Recovering existing tokens for MOUNT, READ, WRITE and TRUNCATE events\n"); token_recovery(DM_EVENT_MOUNT); token_recovery(DM_EVENT_READ); token_recovery(DM_EVENT_WRITE); token_recovery(DM_EVENT_TRUNCATE); global_state=2; printf("Initialization finished\n"); }
int main( int argc, char **argv) { char *name; int fd; void *fshanp; size_t fshlen; char buffer[100]; if (argc != 2) { fprintf(stderr, "usage: %s path\n", argv[0]); exit(1); } Progname = argv[0]; (void)dm_init_service(&name); if (dm_path_to_fshandle(argv[1], &fshanp, &fshlen) != 0) { fprintf(stderr, "dm_path_to_fshandle failed, %s\n", strerror(errno)); } hantoa(fshanp, fshlen, buffer); if ((fd = open(argv[1], O_RDONLY)) < 0) { fprintf(stderr, "Open of %s failed, %s\n", argv[1], strerror(errno)); exit(1); } fprintf(stdout, "fshandle %s, %s\n", buffer, argv[1]); exit(0); }
int main( int argc, char **argv) { #ifdef __sgi xfs_fsop_geom_t geom; char *uuid_str; u_int status; #endif char *name; int fd; void *fshanp; size_t fshlen; char buffer[100]; if (argc != 2) { fprintf(stderr, "usage: %s path\n", argv[0]); exit(1); } Progname = argv[0]; (void)dm_init_service(&name); if (dm_path_to_fshandle(argv[1], &fshanp, &fshlen) != 0) { fprintf(stderr, "dm_path_to_fshandle failed, %s\n", strerror(errno)); } hantoa(fshanp, fshlen, buffer); if ((fd = open(argv[1], O_RDONLY)) < 0) { fprintf(stderr, "Open of %s failed, %s\n", argv[1], strerror(errno)); exit(1); } #ifdef __sgi syssgi(SGI_XFS_FSOPERATIONS, fd, XFS_FS_GEOMETRY, NULL, &geom); uuid_to_string(&geom.uuid, &uuid_str, &status); fprintf(stdout, "fshandle %s, uuid %s, %s\n", buffer, uuid_str, argv[1]); #endif fprintf(stdout, "fshandle %s, %s\n", buffer, argv[1]); exit(0); }
int main( int argc, char **argv) { dm_sessid_t sid = DM_NO_SESSION; char *pathname; void *bufp = NULL; size_t buflen = 10000; size_t rlenp; void *fshanp; size_t fshlen; char *name; int opt; Progname = strrchr(argv[0], '/'); if (Progname) { Progname++; } else { Progname = argv[0]; } /* Crack and validate the command line options. */ while ((opt = getopt(argc, argv, "b:s:")) != EOF) { switch (opt) { case 'b': buflen = atol(optarg); break; case 's': sid = atol(optarg); break; case '?': usage(); } } if (optind + 1 != argc) usage(); pathname = argv[optind++]; if (dm_init_service(&name) == -1) { fprintf(stderr, "Can't initialize the DMAPI\n"); exit(1); } if (sid == DM_NO_SESSION) find_test_session(&sid); /* Get the file's handle. */ if (dm_path_to_fshandle(pathname, &fshanp, &fshlen)) { fprintf(stderr, "can't get fshandle for file %s, %s\n", pathname, strerror(errno)); exit(1); } if (buflen > 0) { if ((bufp = malloc(buflen)) == NULL) { fprintf(stderr, "malloc failed, %s\n", strerror(errno)); exit(1); } } if (dm_get_mountinfo(sid, fshanp, fshlen, DM_NO_TOKEN, buflen, bufp, &rlenp)) { if (errno == E2BIG) { fprintf(stderr, "dm_get_mountinfo buffer too small, " "should be %zd bytes\n", rlenp); } else { fprintf(stderr, "dm_get_mountinfo failed, %s\n", strerror(errno)); } exit(1); } fprintf(stdout, "rlenp is %zd\n", rlenp); print_one_mount_event(bufp); dm_handle_free(fshanp, fshlen); exit(0); }
int main( int argc, char *argv[]) { int c; int error; dm_off_t size; char *fsname; dm_sessid_t sid; void *fs_hanp; size_t fs_hlen; char *sizep = "0"; Progname = argv[0]; size = 0; while ((c = getopt(argc, argv, "s:")) != EOF) { switch (c) { case 's': sizep = optarg; break; case '?': default: usage(Progname); exit(1); } } if (optind >= argc) { usage(Progname); exit(1); } /* * Verify the input size string is legit */ error = verify_size(sizep, &size); if (error) exit(1); fsname = argv[optind]; /* * Now we have our filesystem name and possibly a size threshold * to look for. Init the dmapi, and get a filesystem handle so * we can scan the filesystem */ error = setup_dmapi(&sid); if (error) exit(1); if (dm_path_to_fshandle(fsname, &fs_hanp, &fs_hlen) == -1) { errno_msg("Can't get filesystem handle"); exit(1); } /* * Get the attributes of all files in the filesystem */ error = scan_fs(sid, fs_hanp, fs_hlen, size); if (error) exit(1); /* * We're done, so we can shut down our session. */ if (dm_destroy_session(sid) == -1) { errno_msg("Can't close session"); exit(1); } return(0); }
void DoTest() { int rc; char *szFuncName; DMLOG_PRINT(DMLVL_DEBUG, "Starting DMAPI persistent managed regions test\n") ; szFuncName = "dm_get_region"; /* * TEST : dm_get_region - persistent, Part II * EXPECTED: rc = 0, nelem = 5 */ if (DMVAR_EXEC(GET_REGION_BASE + 1)) { int fd; void *hanp; size_t hlen; u_int nelem; dm_region_t regbuf[PMR_NUM_REGIONS]; int varStatus; int i; /* Variation set up */ if ((fd = open(DummyFile, O_RDWR)) == -1) { /* No clean up */ } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(persistent, Part II)\n", szFuncName); rc = dm_get_region(sid, hanp, hlen, DM_NO_TOKEN, sizeof(regbuf)/sizeof(dm_region_t), regbuf, &nelem); if (rc == 0) { DMLOG_PRINT(DMLVL_DEBUG, "nelem = %d\n", nelem); } varStatus = DMSTAT_PASS; if (rc != 0) { DMLOG_PRINT(DMLVL_ERR, "%s returned unexpected rc = %d (errno = %d)\n", szFuncName, rc, errno); varStatus = DMSTAT_FAIL; } else if (nelem != PMR_NUM_REGIONS) { DMLOG_PRINT(DMLVL_ERR, "Number of regions NOT correct! (%d vs %d)\n", nelem, PMR_NUM_REGIONS); varStatus = DMSTAT_FAIL; } else { DMLOG_PRINT(DMLVL_DEBUG, "%s returned expected rc = %d\n", szFuncName, rc, errno); DMLOG_PRINT(DMLVL_DEBUG, "nelem = %d\n", rc, errno); LogRegions(regbuf, nelem); for (i = 0; i < PMR_NUM_REGIONS; i++) { if (regbuf[i].rg_offset != dm_PMR_regbuf[i].rg_offset) { DMLOG_PRINT(DMLVL_ERR, "region %d offset NOT correct! (%lld vs %d)\n", i, regbuf[i].rg_offset, dm_PMR_regbuf[i].rg_offset); varStatus = DMSTAT_FAIL; } if (regbuf[i].rg_size != dm_PMR_regbuf[i].rg_size) { DMLOG_PRINT(DMLVL_ERR, "region %d size NOT correct! (%lld vs %d)\n", i, regbuf[i].rg_size, dm_PMR_regbuf[i].rg_size); varStatus = DMSTAT_FAIL; } if (regbuf[i].rg_flags != dm_PMR_regbuf[i].rg_flags) { DMLOG_PRINT(DMLVL_ERR, "region %d flags NOT correct! (%lld vs %d)\n", i, regbuf[i].rg_flags, dm_PMR_regbuf[i].rg_flags); varStatus = DMSTAT_FAIL; } } } DMVAR_END(varStatus); /* Variation clean up */ EVENT_DELIVERY_DELAY; rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_region - invalid sid * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(GET_REGION_BASE + 2)) { int fd; void *hanp; size_t hlen; u_int nelemin, nelemout; dm_region_t regbuf; dm_boolean_t exactflag; /* Variation set up */ nelemin = 1; memset(®buf, 0, sizeof(regbuf)); sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if ((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, &exactflag)) == -1) { close(fd); remove(DummyFile); dm_handle_free(hanp, hlen); } if (rc == -1 || fd == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n", szFuncName); rc = dm_get_region(INVALID_ADDR, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, &nelemout); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_region - invalid hanp * EXPECTED: rc = -1, errno = EFAULT */ if (DMVAR_EXEC(GET_REGION_BASE + 3)) { int fd; void *hanp; size_t hlen; u_int nelemin, nelemout; dm_region_t regbuf; dm_boolean_t exactflag; /* Variation set up */ nelemin = 1; memset(®buf, 0, sizeof(regbuf)); sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if ((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, &exactflag)) == -1) { close(fd); remove(DummyFile); dm_handle_free(hanp, hlen); } if (rc == -1 || fd == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hanp)\n", szFuncName); rc = dm_get_region(sid, (void *)INVALID_ADDR, hlen, DM_NO_TOKEN, nelemin, ®buf, &nelemout); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_region - invalid hlen * EXPECTED: rc = -1, errno = EBADF */ if (DMVAR_EXEC(GET_REGION_BASE + 4)) { int fd; void *hanp; size_t hlen; u_int nelemin, nelemout; dm_region_t regbuf; dm_boolean_t exactflag; /* Variation set up */ nelemin = 1; memset(®buf, 0, sizeof(regbuf)); sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if ((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, &exactflag)) == -1) { close(fd); remove(DummyFile); dm_handle_free(hanp, hlen); } if (rc == -1 || fd == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hlen)\n", szFuncName); rc = dm_get_region(sid, hanp, INVALID_ADDR, DM_NO_TOKEN, nelemin, ®buf, &nelemout); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_region - invalid token * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(GET_REGION_BASE + 5)) { int fd; void *hanp; size_t hlen; u_int nelemin, nelemout; dm_region_t regbuf; dm_boolean_t exactflag; /* Variation set up */ nelemin = 1; memset(®buf, 0, sizeof(regbuf)); sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if ((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, &exactflag)) == -1) { close(fd); remove(DummyFile); dm_handle_free(hanp, hlen); } if (rc == -1 || fd == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid token)\n", szFuncName); rc = dm_get_region(sid, hanp, hlen, INVALID_ADDR, nelemin, ®buf, &nelemout); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_region - invalid regbufp * EXPECTED: rc = -1, errno = EFAULT */ if (DMVAR_EXEC(GET_REGION_BASE + 6)) { int fd; void *hanp; size_t hlen; u_int nelemin, nelemout; dm_region_t regbuf; dm_boolean_t exactflag; /* Variation set up */ nelemin = 1; memset(®buf, 0, sizeof(regbuf)); sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if ((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, &exactflag)) == -1) { close(fd); remove(DummyFile); dm_handle_free(hanp, hlen); } if (rc == -1 || fd == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid regbufp)\n", szFuncName); rc = dm_get_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, (dm_region_t *)INVALID_ADDR, &nelemout); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_region - invalid nelemp * EXPECTED: rc = -1, errno = EFAULT */ if (DMVAR_EXEC(GET_REGION_BASE + 7)) { int fd; void *hanp; size_t hlen; u_int nelemin; dm_region_t regbuf; dm_boolean_t exactflag; /* Variation set up */ nelemin = 1; memset(®buf, 0, sizeof(regbuf)); sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if ((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, &exactflag)) == -1) { close(fd); remove(DummyFile); dm_handle_free(hanp, hlen); } if (rc == -1 || fd == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid nelemp)\n", szFuncName); rc = dm_get_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, (u_int *)INVALID_ADDR); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_region - DM_SO_SESSION sid * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(GET_REGION_BASE + 8)) { int fd; void *hanp; size_t hlen; u_int nelemin, nelemout; dm_region_t regbuf; dm_boolean_t exactflag; /* Variation set up */ nelemin = 1; memset(®buf, 0, sizeof(regbuf)); sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if ((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, &exactflag)) == -1) { close(fd); remove(DummyFile); dm_handle_free(hanp, hlen); } if (rc == -1 || fd == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n", szFuncName); rc = dm_get_region(DM_NO_SESSION, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, &nelemout); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_region - global handle * EXPECTED: rc = -1, errno = EBADF */ if (DMVAR_EXEC(GET_REGION_BASE + 9)) { int fd; void *hanp; size_t hlen; u_int nelemin, nelemout; dm_region_t regbuf; dm_boolean_t exactflag; /* Variation set up */ nelemin = 1; memset(®buf, 0, sizeof(regbuf)); sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if ((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, &exactflag)) == -1) { close(fd); remove(DummyFile); dm_handle_free(hanp, hlen); } if (rc == -1 || fd == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(global handle)\n", szFuncName); rc = dm_get_region(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, DM_NO_TOKEN, nelemin, ®buf, &nelemout); if (rc == -1 && errno == EBADF) { DMLOG_PRINT(DMLVL_DEBUG, "nelem = %d\n", nelemout); } DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_region - directory handle * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(GET_REGION_BASE + 10)) { void *hanp; size_t hlen; u_int nelemin, nelemout; dm_region_t regbuf; /* Variation set up */ nelemin = 1; memset(®buf, 0, sizeof(regbuf)); if ((rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE)) == -1) { /* No clean up */ } else if ((rc = dm_path_to_handle(DummySubdir, &hanp, &hlen)) == -1) { rmdir(DummySubdir); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(dir handle)\n", szFuncName); rc = dm_get_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, &nelemout); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ rc = rmdir(DummySubdir); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_region - fs handle * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(GET_REGION_BASE + 11)) { void *hanp; size_t hlen; u_int nelemin, nelemout; dm_region_t regbuf; /* Variation set up */ nelemin = 1; memset(®buf, 0, sizeof(regbuf)); if ((rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE)) == -1) { /* No clean up */ } else if ((rc = dm_path_to_fshandle(DummySubdir, &hanp, &hlen)) == -1) { rmdir(DummySubdir); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(fs handle)\n", szFuncName); rc = dm_get_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, &nelemout); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ rc = rmdir(DummySubdir); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_region - nelem 0 * EXPECTED: rc = 0 */ if (DMVAR_EXEC(GET_REGION_BASE + 11)) { int fd; void *hanp; size_t hlen; u_int nelemin, nelemout; dm_region_t regbuf; /* Variation set up */ nelemin = 0; sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } if (rc == -1 || fd == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(nelem 0)\n", szFuncName); rc = dm_get_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®buf, &nelemout); if (rc == 0) { DMLOG_PRINT(DMLVL_DEBUG, "nelem = %d\n", nelemout); if (nelemin == nelemout) { DMLOG_PRINT(DMLVL_DEBUG, "%s passed with expected rc = %d\n", szFuncName, 0); DMVAR_PASS(); } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d but unexpected nelemp (%d vs %d)\n", szFuncName, 0, nelemin, nelemout); DMVAR_FAIL(); } } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with unexpected rc = %d (errno = %d)\n", szFuncName, rc, errno); DMVAR_FAIL(); } /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_region - nelem 1 * EXPECTED: rc = 0 */ if (DMVAR_EXEC(GET_REGION_BASE + 12)) { int fd; void *hanp; size_t hlen; u_int nelemin, nelemout; dm_region_t regbufin, regbufout; dm_boolean_t exactflag; /* Variation set up */ nelemin = 1; memset(®bufin, 0, sizeof(regbufin)); sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if ((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®bufin, &exactflag)) == -1) { close(fd); remove(DummyFile); dm_handle_free(hanp, hlen); } if (rc == -1 || fd == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(nelem 1)\n", szFuncName); rc = dm_get_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, ®bufout, &nelemout); if (rc == 0) { DMLOG_PRINT(DMLVL_DEBUG, "nelem = %d\n", nelemout); if (nelemin == nelemout) { if (memcmp(®bufin, ®bufout, sizeof(dm_region_t)) == 0) { DMLOG_PRINT(DMLVL_DEBUG, "%s passed with expected rc = %d\n", szFuncName, 0); DMVAR_PASS(); } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d but unexpected regions\n", szFuncName, 0); DMLOG_PRINT(DMLVL_DEBUG, "Region in:\n"); LogRegions(®bufin, nelemin); DMLOG_PRINT(DMLVL_DEBUG, "Region out:\n"); LogRegions(®bufout, nelemout); DMVAR_FAIL(); } } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d but unexpected nelemp (%d vs %d)\n", szFuncName, 0, nelemin, nelemout); DMVAR_FAIL(); } } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with unexpected rc = %d (errno = %d)\n", szFuncName, rc, errno); DMVAR_FAIL(); } /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_region - nelem 2 * EXPECTED: rc = 0 */ if (DMVAR_EXEC(GET_REGION_BASE + 13)) { #ifdef MULTIPLE_REGIONS int fd; void *hanp; size_t hlen; u_int nelemin, nelemout; dm_region_t regbufin[2], regbufout[2]; dm_boolean_t exactflag; /* Variation set up */ nelemin = 2; regbufin[0].rg_offset = 0; regbufin[0].rg_size = 1000; regbufin[0].rg_flags = DM_REGION_READ; regbufin[1].rg_offset = 2000; regbufin[1].rg_size = 1000; regbufin[1].rg_flags = DM_REGION_WRITE; sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if ((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, regbufin, &exactflag)) == -1) { close(fd); remove(DummyFile); dm_handle_free(hanp, hlen); } if (rc == -1 || fd == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(nelem 2)\n", szFuncName); rc = dm_get_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, regbufout, &nelemout); if (rc == 0) { DMLOG_PRINT(DMLVL_DEBUG, "nelem = %d\n", nelemout); if (nelemin == nelemout) { if (memcmp(®bufin, ®bufout, sizeof(dm_region_t)) == 0) { DMLOG_PRINT(DMLVL_DEBUG, "%s passed with expected rc = %d\n", szFuncName, 0); DMVAR_PASS(); } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d but unexpected regions\n", szFuncName, 0); DMLOG_PRINT(DMLVL_DEBUG, "Region in:\n"); LogRegions(regbufin, nelemin); DMLOG_PRINT(DMLVL_DEBUG, "Region out:\n"); LogRegions(regbufout, nelemout); DMVAR_FAIL(); } } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d but unexpected nelemp (%d vs %d)\n", szFuncName, 0, nelemin, nelemout); DMVAR_FAIL(); } } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with unexpected rc = %d (errno = %d)\n", szFuncName, rc, errno); DMVAR_FAIL(); } /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } #else DMLOG_PRINT(DMLVL_WARN, "Test case not built with MULTIPLE_REGIONS defined\n"); DMVAR_SKIP(); #endif } /* * TEST : dm_get_region - regbuf too small * EXPECTED: rc = -1, errno = E2BIG */ if (DMVAR_EXEC(GET_REGION_BASE + 14)) { int fd; void *hanp; size_t hlen; u_int nelemin, nelemout; dm_region_t regbufin[2], regbufout[1]; dm_boolean_t exactflag; /* Variation set up */ #ifdef MULTIPLE_REGIONS nelemin = 2; regbufin[0].rg_offset = 0; regbufin[0].rg_size = 1000; regbufin[0].rg_flags = DM_REGION_READ; regbufin[1].rg_offset = 2000; regbufin[1].rg_size = 1000; regbufin[1].rg_flags = DM_REGION_WRITE; #else nelemin = 1; regbufin[0].rg_offset = 0; regbufin[0].rg_size = 1000; regbufin[0].rg_flags = DM_REGION_READ; #endif sprintf(command, "cp %s %s", DUMMY_FILE, DummyFile); if ((rc = system(command)) == -1) { /* No clean up */ } else if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { remove(DummyFile); } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } else if ((rc = dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin, regbufin, &exactflag)) == -1) { close(fd); remove(DummyFile); dm_handle_free(hanp, hlen); } if (rc == -1 || fd == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(regbuf too small)\n", szFuncName); rc = dm_get_region(sid, hanp, hlen, DM_NO_TOKEN, nelemin-1, regbufout, &nelemout); if (rc == -1) { if (errno == E2BIG) { DMLOG_PRINT(DMLVL_DEBUG, "nelem = %d\n", nelemout); if (nelemout == nelemin) { DMLOG_PRINT(DMLVL_DEBUG, "%s passed with expected rc = %d and expected errno = %d\n", szFuncName, rc, errno); DMVAR_PASS(); } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d and expected errno = %d but unexpected nelemp (%d vs %d)\n", szFuncName, rc, errno, nelemout, nelemin); DMVAR_FAIL(); } } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d but unexpected errno = %d\n", szFuncName, rc, errno); DMVAR_FAIL(); } } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with unexpected rc = %d\n", szFuncName, rc); DMVAR_FAIL(); } /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } }
int main( int argc, char **argv) { dm_sessid_t sid, oldsid, targetsid, *newsidp, *sidbufp; dm_token_t token, *tokenp, *rtokenp, *tokenbufp; dm_attrname_t *attrnamep; dm_off_t off, *offp, *roffp; dm_extent_t *extentp; dm_inherit_t *inheritbufp; dm_stat_t *statp; dm_size_t len, *dmrlenp, *retvalp; dm_attrloc_t *locp; dm_eventset_t *eventsetp; dm_config_t flagname; dm_region_t *regbufp; dm_response_t response; dm_right_t right, *rightp; dm_igen_t igen, *igenp; dm_msgtype_t msgtype; dm_fileattr_t *attrp; dm_boolean_t enable, *exactflagp; dm_timestruct_t *delay; mode_t mode; size_t hlen, dirhlen, hlen1, hlen2, targhlen, *fshlenp, *hlenp; size_t msglen, buflen, *rlenp; u_int nelem, mask, maxmsgs, uflags, *nelemp, maxevent; void *hanp, *dirhanp, *hanp1, *hanp2, *targhanp; void *msgdatap, *bufp, **hanpp, *respbufp, **fshanpp; dm_fsid_t fsid, *fsidp; dm_ino_t ino, *inop; char *cname, *sessinfop, *path, *pathbufp, **versionstrpp; int flags, fd, setdtime, reterror; u_int urc; int rc; dm_ssize_t ssrc; /* Definitions per the prototypes in dmport.h, in the same order. */ rc = dm_clear_inherit(sid, hanp, hlen, token, attrnamep); rc = dm_create_by_handle(sid, dirhanp, dirhlen, token, hanp, hlen, cname); rc = dm_create_session(oldsid, sessinfop, newsidp); rc = dm_create_userevent(sid, msglen, msgdatap, tokenp); rc = dm_destroy_session(sid); rc = dm_downgrade_right(sid, hanp, hlen, token); rc = dm_fd_to_handle(fd, hanpp, hlenp); rc = dm_find_eventmsg(sid, token, buflen, bufp, rlenp); rc = dm_get_allocinfo(sid, hanp, hlen, token, offp, nelem, extentp, nelemp); rc = dm_get_bulkall(sid, hanp, hlen, token, mask, attrnamep, locp, buflen, bufp, rlenp); rc = dm_get_bulkattr(sid, hanp, hlen, token, mask, locp, buflen, bufp, rlenp); rc = dm_get_config(hanp, hlen, flagname, retvalp); rc = dm_get_config_events(hanp, hlen, nelem, eventsetp, nelemp); rc = dm_get_dirattrs(sid, hanp, hlen, token, mask, locp, buflen, bufp, rlenp); rc = dm_get_dmattr(sid, hanp, hlen, token, attrnamep, buflen, bufp, rlenp); rc = dm_get_eventlist(sid, hanp, hlen, token, nelem, eventsetp, nelemp); rc = dm_get_events(sid, maxmsgs, flags, buflen, bufp, rlenp); rc = dm_get_fileattr(sid, hanp, hlen, token, mask, statp); rc = dm_get_mountinfo(sid, hanp, hlen, token, buflen, bufp, rlenp); rc = dm_get_region(sid, hanp, hlen, token, nelem, regbufp, nelemp); rc = dm_getall_disp(sid, buflen, bufp, rlenp); rc = dm_getall_dmattr(sid, hanp, hlen, token, buflen, bufp, rlenp); rc = dm_getall_inherit(sid, hanp, hlen, token, nelem, inheritbufp, nelemp); rc = dm_getall_sessions(nelem, sidbufp, nelemp); rc = dm_getall_tokens(sid, nelem, tokenbufp, nelemp); rc = dm_handle_cmp(hanp1, hlen1, hanp2, hlen2); dm_handle_free(hanp, hlen); urc = dm_handle_hash(hanp, hlen); rc = dm_handle_is_valid(hanp, hlen); rc = dm_handle_to_fshandle(hanp, hlen, fshanpp, fshlenp); rc = dm_handle_to_fsid(hanp, hlen, fsidp); rc = dm_handle_to_igen(hanp, hlen, igenp); rc = dm_handle_to_ino(hanp, hlen, inop); rc = dm_handle_to_path(dirhanp, dirhlen, targhanp, targhlen, buflen, pathbufp, rlenp); rc = dm_init_attrloc(sid, hanp, hlen, token, locp); rc = dm_init_service(versionstrpp); rc = dm_make_handle(&fsid, &ino, &igen, hanpp, hlenp); rc = dm_make_fshandle(&fsid, hanpp, hlenp); rc = dm_mkdir_by_handle(sid, dirhanp, dirhlen, token, hanp, hlen, cname); rc = dm_move_event(sid, token, targetsid, rtokenp); rc = dm_obj_ref_hold(sid, token, hanp, hlen); rc = dm_obj_ref_query(sid, token, hanp, hlen); rc = dm_obj_ref_rele(sid, token, hanp, hlen); rc = dm_path_to_fshandle(path, hanpp, hlenp); rc = dm_path_to_handle(path, hanpp, hlenp); rc = dm_pending(sid, token, delay); rc = dm_probe_hole(sid, hanp, hlen, token, off, len, roffp, dmrlenp); rc = dm_punch_hole(sid, hanp, hlen, token, off, len); rc = dm_query_right(sid, hanp, hlen, token, rightp); rc = dm_query_session(sid, buflen, bufp, rlenp); ssrc = dm_read_invis(sid, hanp, hlen, token, off, len, bufp); rc = dm_release_right(sid, hanp, hlen, token); rc = dm_remove_dmattr(sid, hanp, hlen, token, setdtime, attrnamep); rc = dm_request_right(sid, hanp, hlen, token, uflags, right); rc = dm_respond_event(sid, token, response, reterror, buflen, respbufp); rc = dm_send_msg(sid, msgtype, buflen, bufp); rc = dm_set_disp(sid, hanp, hlen, token, eventsetp, maxevent); rc = dm_set_dmattr(sid, hanp, hlen, token, attrnamep, setdtime, buflen, bufp); rc = dm_set_eventlist(sid, hanp, hlen, token, eventsetp, maxevent); rc = dm_set_fileattr(sid, hanp, hlen, token, mask, attrp); rc = dm_set_inherit(sid, hanp, hlen, token, attrnamep, mode); rc = dm_set_region(sid, hanp, hlen, token, nelem, regbufp, exactflagp); rc = dm_set_return_on_destroy(sid, hanp, hlen, token, attrnamep, enable); rc = dm_symlink_by_handle(sid, dirhanp, dirhlen, token, hanp, hlen, cname, path); rc = dm_sync_by_handle(sid, hanp, hlen, token); rc = dm_upgrade_right(sid, hanp, hlen, token); ssrc = dm_write_invis(sid, hanp, hlen, flags, token, off, len, bufp); exit(0); }
int main( int argc, char *argv[]) { int c; int error; char *fsname, *logfile; dm_sessid_t sid; void *fs_hanp; size_t fs_hlen; Progname = argv[0]; fsname = NULL; logfile = NULL; while ((c = getopt(argc, argv, "vl:")) != EOF) { switch (c) { case 'v': Verbose = 1; break; case 'l': logfile = optarg; break; case '?': default: usage(Progname); exit(1); } } if (optind >= argc) { usage(Progname); exit(1); } fsname = argv[optind]; if (fsname == NULL) { usage(Progname); exit(1); } /* * If no logfile name is specified, we'll just send * all output to some file in /tmp */ if (logfile == NULL) logfile = LOG_DEFAULT; /* * Now we have our filesystem name and possibly a size threshold * to look for. Init the dmapi, and get a filesystem handle so * we can set up our events */ error = setup_dmapi(&sid); if (error) exit(1); if (dm_path_to_fshandle(fsname, &fs_hanp, &fs_hlen) == -1) { errno_msg("Can't get filesystem handle"); exit(1); } /* * Turn ourselves into a daemon */ error = mk_daemon(logfile); if (error) exit(1); /* * Set the event disposition so that our session will receive * the managed region events (read, write, and truncate) */ error = set_events(sid, fs_hanp, fs_hlen); if (error) exit(1); /* * Now wait forever for messages, spawning kids to * do the actual work */ event_loop(sid); return(0); }
int main(int argc, char **argv) { char *szFuncName; char *varstr; int rc; char *szSessionInfo = "dm_test session info"; dm_eventset_t events; DMOPT_PARSE(argc, argv); DMLOG_START(); DMEV_ZERO(events); DMEV_SET(DM_EVENT_MOUNT, events); /* CANNOT DO ANYTHING WITHOUT SUCCESSFUL INITIALIZATION!!! */ if ((rc = dm_init_service(&varstr)) != 0) { DMLOG_PRINT(DMLVL_ERR, "dm_init_service failed! (rc = %d, errno = %d)\n", rc, errno); DM_EXIT(); } else if ((rc = dm_create_session(DM_NO_SESSION, szSessionInfo, &sid)) == -1) { DMLOG_PRINT(DMLVL_ERR, "dm_create_session failed! (rc = %d, errno = %d)\n", rc, errno); DM_EXIT(); } else if ((rc = dm_set_disp(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, DM_NO_TOKEN, &events, DM_EVENT_MAX)) == -1) { DMLOG_PRINT(DMLVL_ERR, "dm_set_disp failed! (rc = %d, errno = %d)\n", rc, errno); dm_destroy_session(sid); DM_EXIT(); } else if ((rc = pthread_create(&tid, NULL, Thread, NULL)) != 0) { DMLOG_PRINT(DMLVL_ERR, "pthread_create failed! (rc = %d, errno = %d)\n", rc, errno); dm_destroy_session(sid); DM_EXIT(); } else if ((rc = dmimpl_mount(&mountPt, &deviceNm)) == -1) { DMLOG_PRINT(DMLVL_ERR, "dmimpl_mount failed! (rc = %d, errno = %d)\n", rc, errno); dm_destroy_session(sid); DM_EXIT(); } else { sprintf(DummyFile, "%s/%s", mountPt, DUMMY_FILE); sprintf(DummySubdir, "%s/%s", mountPt, DUMMY_SUBDIR); remove(DummyFile); rmdir(DummySubdir); } DMLOG_PRINT(DMLVL_DEBUG, "Starting DMAPI mount tests\n") ; szFuncName = "dm_set_dmattr"; /* * TEST : dm_get_mountinfo - invalid sid * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 1)) { int fd; void *hanp; size_t hlen; char buf[MOUNTEVENT_LEN]; size_t rlen; /* Variation set up */ if ((fd = open(DummyFile, O_RDWR | O_CREAT)) == -1) { /* No clean up */ } else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n", szFuncName); rc = dm_get_mountinfo(INVALID_ADDR, hanp, hlen, DM_NO_TOKEN, sizeof(buf), buf, &rlen); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_mountinfo - invalid hanp * EXPECTED: rc = -1, errno = EFAULT */ if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 2)) { int fd; void *hanp; size_t hlen; char buf[MOUNTEVENT_LEN]; size_t rlen; /* Variation set up */ if ((fd = open(DummyFile, O_RDWR | O_CREAT)) == -1) { /* No clean up */ } else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hanp)\n", szFuncName); rc = dm_get_mountinfo(sid, (void *)INVALID_ADDR, hlen, DM_NO_TOKEN, sizeof(buf), buf, &rlen); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_mountinfo - invalid hlen * EXPECTED: rc = -1, errno = EBADF */ if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 3)) { int fd; void *hanp; size_t hlen; char buf[MOUNTEVENT_LEN]; size_t rlen; /* Variation set up */ if ((fd = open(DummyFile, O_RDWR | O_CREAT)) == -1) { /* No clean up */ } else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hlen)\n", szFuncName); rc = dm_get_mountinfo(sid, hanp, INVALID_ADDR, DM_NO_TOKEN, sizeof(buf), buf, &rlen); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_mountinfo - invalid token * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 4)) { int fd; void *hanp; size_t hlen; char buf[MOUNTEVENT_LEN]; size_t rlen; /* Variation set up */ if ((fd = open(DummyFile, O_RDWR | O_CREAT)) == -1) { /* No clean up */ } else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid token)\n", szFuncName); rc = dm_get_mountinfo(sid, hanp, hlen, INVALID_ADDR, sizeof(buf), buf, &rlen); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_mountinfo - invalid buflen * EXPECTED: rc = -1, errno = E2BIG */ if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 5)) { int fd; void *hanp; size_t hlen; char buf[MOUNTEVENT_LEN]; size_t rlen; /* Variation set up */ if ((fd = open(DummyFile, O_RDWR | O_CREAT)) == -1) { /* No clean up */ } else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid buflen)\n", szFuncName); rc = dm_get_mountinfo(sid, hanp, hlen, DM_NO_TOKEN, 0, buf, &rlen); if (rc == -1) { if (errno == E2BIG) { DMLOG_PRINT(DMLVL_DEBUG, "rlen = %d\n", rlen); if (rlen == me_len) { DMLOG_PRINT(DMLVL_DEBUG, "%s passed with expected rc = %d and expected errno = %d\n", szFuncName, -1, E2BIG); DMVAR_PASS(); } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d and expected errno = %d but unexpected rlen (%d vs %d)\n", szFuncName, -1, E2BIG, rlen, me_len); DMVAR_FAIL(); } } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d but unexpected errno = %d\n", szFuncName, -1, errno); DMVAR_FAIL(); } } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with unexpected rc = %d\n", szFuncName, rc); DMVAR_FAIL(); } /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_mountinfo - invalid bufp * EXPECTED: rc = -1, errno = EFAULT */ if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 6)) { int fd; void *hanp; size_t hlen; char buf[MOUNTEVENT_LEN]; size_t rlen; /* Variation set up */ if ((fd = open(DummyFile, O_RDWR | O_CREAT)) == -1) { /* No clean up */ } else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid bufp)\n", szFuncName); rc = dm_get_mountinfo(sid, hanp, hlen, DM_NO_TOKEN, sizeof(buf), (void *)INVALID_ADDR, &rlen); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_mountinfo - invalid rlenp * EXPECTED: rc = -1, errno = EFAULT */ if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 7)) { int fd; void *hanp; size_t hlen; char buf[MOUNTEVENT_LEN]; /* Variation set up */ if ((fd = open(DummyFile, O_RDWR | O_CREAT)) == -1) { /* No clean up */ } else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid rlenp)\n", szFuncName); rc = dm_get_mountinfo(sid, hanp, hlen, DM_NO_TOKEN, sizeof(buf), buf, (size_t *)INVALID_ADDR); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_mountinfo - valid * EXPECTED: rc = 0 */ if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 8)) { int fd; void *hanp; size_t hlen; char buf[MOUNTEVENT_LEN]; size_t rlen; /* Variation set up */ if ((fd = open(DummyFile, O_RDWR | O_CREAT)) == -1) { /* No clean up */ } else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(valid)\n", szFuncName); rc = dm_get_mountinfo(sid, hanp, hlen, DM_NO_TOKEN, sizeof(buf), buf, &rlen); if (rc == 0) { DMLOG_PRINT(DMLVL_DEBUG, "rlen = %d\n", rlen); if (rlen == me_len) { if (memcmp(buf, me_ptr, rlen) == 0) { DMLOG_PRINT(DMLVL_DEBUG, "%s passed with expected rc = %d\n", szFuncName, 0); DMVAR_PASS(); } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d but mount info not same\n", szFuncName, 0); DMVAR_FAIL(); } } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d but mount info len not same (%d vs %d)\n", szFuncName, 0, rlen, me_len); DMVAR_FAIL(); } } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with unexpected rc = %d (errno = %d)\n", szFuncName, rc, errno); DMVAR_FAIL(); } /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_get_mountinfo - DM_NO_SESSION sid * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 9)) { int fd; void *hanp; size_t hlen; char buf[MOUNTEVENT_LEN]; size_t rlen; /* Variation set up */ if ((fd = open(DummyFile, O_RDWR | O_CREAT)) == -1) { /* No clean up */ } else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n", szFuncName); rc = dm_get_mountinfo(DM_NO_SESSION, hanp, hlen, DM_NO_TOKEN, sizeof(buf), buf, &rlen); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_mountinfo - global handle * EXPECTED: rc = -1, errno = EBADF */ if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 10)) { char buf[MOUNTEVENT_LEN]; size_t rlen; /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(global handle)\n", szFuncName); rc = dm_get_mountinfo(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, DM_NO_TOKEN, sizeof(buf), buf, &rlen); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); /* Variation clean up */ } /* * TEST : dm_get_mountinfo - file handle * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 11)) { int fd; void *hanp; size_t hlen; char buf[MOUNTEVENT_LEN]; size_t rlen; /* Variation set up */ if ((fd = open(DummyFile, O_RDWR | O_CREAT)) == -1) { /* No clean up */ } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) == -1) { close(fd); remove(DummyFile); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(file handle)\n", szFuncName); rc = dm_get_mountinfo(sid, hanp, hlen, DM_NO_TOKEN, sizeof(buf), buf, &rlen); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ rc = close(fd); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_mountinfo - dir handle * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 12)) { void *hanp; size_t hlen; char buf[MOUNTEVENT_LEN]; size_t rlen; /* Variation set up */ if ((rc = mkdir(DummySubdir, O_RDWR | O_CREAT)) == -1) { /* No clean up */ } else if ((rc = dm_path_to_handle(DummySubdir, &hanp, &hlen)) == -1) { rmdir(DummySubdir); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(dir handle)\n", szFuncName); rc = dm_get_mountinfo(sid, hanp, hlen, DM_NO_TOKEN, sizeof(buf), buf, &rlen); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ rc = rmdir(DummySubdir); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } if (me_ptr != NULL) { free(me_ptr); } rc = umount(mountPt); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "umount failed! (rc = %d, errno = %d)\n", rc, errno); } pthread_join(tid, NULL); rc = dm_destroy_session(sid); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "dm_destroy_session failed! (rc = %d, errno = %d)\n", rc, errno); } DMLOG_STOP(); return 0; }
int main( int argc, char **argv) { char *pathname; char *name; void *hanp1, *hanp2, *hanp3, *fshanp1, *fshanp2, *fshanp3; size_t hlen1, hlen2, hlen3, fshlen1, fshlen2, fshlen3; u_int hash1, hash2, hash3, fshash1, fshash2, fshash3; dm_fsid_t fsid; dm_ino_t ino; dm_igen_t igen; char buffer[100]; char buffer1[100]; char fsbuffer1[100]; char buffer2[100]; char fsbuffer2[100]; char buffer3[100]; char fsbuffer3[100]; int fd; if (Progname = strrchr(argv[0], '/')) { Progname++; } else { Progname = argv[0]; } if (argc != 2) { fprintf(stderr, "usage: %s path\n", argv[0]); exit(1); } pathname = argv[1]; (void)dm_init_service(&name); if (dm_path_to_handle(pathname, &hanp1, &hlen1) != 0) { fprintf(stderr, "dm_path_to_handle failed, %s\n", strerror(errno)); exit(1); } hash1 = dm_handle_hash(hanp1, hlen1); hantoa(hanp1, hlen1, buffer1); fprintf(stdout, " han1: hash %u value %s (dm_path_to_handle)\n", hash1, buffer1); if (dm_handle_is_valid(hanp1, hlen1) == DM_FALSE) { fprintf(stderr, "ERROR: han1 is not valid\n"); } if (dm_path_to_fshandle(pathname, &fshanp1, &fshlen1) != 0) { fprintf(stderr, "dm_path_to_fshandle failed, %s\n", strerror(errno)); exit(1); } fshash1 = dm_handle_hash(fshanp1, fshlen1); hantoa(fshanp1, fshlen1, fsbuffer1); fprintf(stdout, "fshan1: hash %u value %s (dm_path_to_fshandle\n", fshash1, fsbuffer1); if (dm_handle_is_valid(fshanp1, fshlen1) == DM_FALSE) { fprintf(stderr, "ERROR: fshan1 is not valid\n"); } if ((fd = open(pathname, O_RDONLY)) < 0) { fprintf(stderr, "open of %s failed, %s\n", pathname, strerror(errno)); exit(1); } if (dm_fd_to_handle(fd, &hanp2, &hlen2) != 0) { fprintf(stderr, "dm_fd_to_handle failed, %s\n", strerror(errno)); exit(1); } (void)close(fd); hash2 = dm_handle_hash(hanp2, hlen2); hantoa(hanp2, hlen2, buffer2); fprintf(stdout, " han2: hash %u value %s (dm_fd_to_handle)\n", hash2, buffer2); if (dm_handle_is_valid(hanp2, hlen2) == DM_FALSE) { fprintf(stderr, "ERROR: han2 is not valid\n"); } if (dm_handle_to_fshandle(hanp2, hlen2, &fshanp2, &fshlen2) != 0) { fprintf(stderr, "dm_handle_to_fshandle failed, %s\n", strerror(errno)); exit(1); } fshash2 = dm_handle_hash(fshanp2, fshlen2); hantoa(fshanp2, fshlen2, fsbuffer2); fprintf(stdout, "fshan2: hash %u value %s (dm_handle_to_fshandle)\n", fshash2, fsbuffer2); if (dm_handle_is_valid(fshanp2, fshlen2) == DM_FALSE) { fprintf(stderr, "ERROR: fshan2 is not valid\n"); } if (dm_handle_cmp(hanp1, hlen1, hanp2, hlen2)) { fprintf(stderr, "ERROR: han1 and han2 differ in dm_handle_cmp\n"); } if (strcmp(buffer1, buffer2)) { fprintf(stderr, "ERROR: han1 and han2 differ in strcmp\n"); } if (hash1 != hash2) { fprintf(stderr, "ERROR: hash1 and hash2 differ\n"); } if (dm_handle_cmp(fshanp1, fshlen1, fshanp2, fshlen2)) { fprintf(stderr, "ERROR: fshan1 and fshan2 differ in dm_handle_cmp\n"); } if (strcmp(fsbuffer1, fsbuffer2)) { fprintf(stderr, "ERROR: fshan1 and fshan2 differ in strcmp\n"); } if (fshash1 != fshash2) { fprintf(stderr, "ERROR: fshash1 and fshash2 differ\n"); } /* Break the handle into its component parts and display them. Use hantoa() instead of printing the parts directly because some are 32 bits on Veritas and 64 bits on SGI. */ if (dm_handle_to_fsid(hanp1, hlen1, &fsid) != 0) { fprintf(stderr, "dm_handle_to_fsid failed, %s\n", strerror(errno)); exit(1); } hantoa(&fsid, sizeof(fsid), buffer); fprintf(stdout, "fsid %s (dm_handle_to_fsid)\n", buffer); if (dm_handle_to_ino(hanp1, hlen1, &ino) != 0) { fprintf(stderr, "dm_handle_to_ino failed, %s\n", strerror(errno)); exit(1); } hantoa(&ino, sizeof(ino), buffer); fprintf(stdout, "ino %s (dm_handle_to_ino)\n", buffer); if (dm_handle_to_igen(hanp1, hlen1, &igen) != 0) { fprintf(stderr, "dm_handle_to_igen failed, %s\n", strerror(errno)); exit(1); } hantoa(&igen, sizeof(igen), buffer); fprintf(stdout, "igen %s (dm_handle_to_igen)\n", buffer); /* Now use the parts to remake the handle and verify we get the same answer. */ if (dm_make_handle(&fsid, &ino, &igen, &hanp3, &hlen3) != 0) { fprintf(stderr, "dm_make_handle failed, %s\n", strerror(errno)); exit(1); } hash3 = dm_handle_hash(hanp3, hlen3); hantoa(hanp3, hlen3, buffer3); fprintf(stdout, " han3: hash %u value %s (dm_make_handle)\n", hash3, buffer3); if (dm_handle_is_valid(hanp3, hlen3) == DM_FALSE) { fprintf(stderr, "ERROR: han3 is not valid\n"); } if (dm_handle_cmp(hanp1, hlen1, hanp3, hlen3)) { fprintf(stderr, "ERROR: hanp1 and hanp3 differ in dm_handle_cmp\n"); } if (strcmp(buffer1, buffer3)) { fprintf(stderr, "ERROR: hanp1 and hanp3 differ in strcmp\n"); } if (hash1 != hash3) { fprintf(stderr, "ERROR: hash1 and hash3 differ\n"); } if (dm_make_fshandle(&fsid, &fshanp3, &fshlen3) != 0) { fprintf(stderr, "dm_make_fshandle failed, %s\n", strerror(errno)); exit(1); } fshash3 = dm_handle_hash(fshanp3, fshlen3); hantoa(fshanp3, fshlen3, fsbuffer3); fprintf(stdout, "fshan3: hash %u value %s (dm_make_fshandle)\n", fshash3, fsbuffer3); if (dm_handle_is_valid(fshanp3, fshlen3) == DM_FALSE) { fprintf(stderr, "ERROR: fshan3 is not valid\n"); } if (dm_handle_cmp(fshanp1, fshlen1, fshanp3, fshlen3)) { fprintf(stderr, "ERROR: fshan1 and fshan3 differ in dm_handle_cmp\n"); } if (strcmp(fsbuffer1, fsbuffer3)) { fprintf(stderr, "ERROR: fshan1 and fshan3 differ in strcmp\n"); } if (fshash1 != fshash3) { fprintf(stderr, "ERROR: fshash1 and fshash3 differ\n"); } dm_handle_free(hanp1, hlen1); dm_handle_free(hanp2, hlen2); dm_handle_free(hanp3, hlen3); dm_handle_free(fshanp1, fshlen1); dm_handle_free(fshanp2, fshlen2); dm_handle_free(fshanp3, fshlen3); exit(0); }
int main(int argc, char **argv) { char *szFuncName; char *varstr; int rc; int i; DMOPT_PARSE(argc, argv); DMLOG_START(); /* CANNOT DO ANYTHING WITHOUT SUCCESSFUL INITIALIZATION AND NO PREEXISTING FILES!!! */ if ((rc = dm_init_service(&varstr)) != 0) { DMLOG_PRINT(DMLVL_ERR, "dm_init_service failed! (rc = %d, errno = %d)\n", rc, errno); DM_EXIT(); } DMLOG_PRINT(DMLVL_DEBUG, "Starting DMAPI configuration tests\n"); szFuncName = "dm_get_config"; /* * TEST : dm_get_config - invalid hanp * EXPECTED: rc = -1, errno = EFAULT */ if (DMVAR_EXEC(GET_CONFIG_BASE + 1)) { int fd; void *hanp; size_t hlen; dm_size_t retval; /* Variation set up */ if ((fd = open(DUMMY_FILE, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { /* No clean up */ } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DUMMY_FILE); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hanp)\n", szFuncName); rc = dm_get_config((void *)INVALID_ADDR, hlen, DM_CONFIG_BULKALL, &retval); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); /* Variation clean up */ rc = close(fd); rc |= remove(DUMMY_FILE); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_config - invalid hlen * EXPECTED: rc = -1, errno = EBADF */ if (DMVAR_EXEC(GET_CONFIG_BASE + 2)) { int fd; void *hanp; size_t hlen; dm_size_t retval; /* Variation set up */ if ((fd = open(DUMMY_FILE, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { /* No clean up */ } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DUMMY_FILE); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hlen)\n", szFuncName); rc = dm_get_config(hanp, INVALID_ADDR, DM_CONFIG_BULKALL, &retval); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); /* Variation clean up */ rc = close(fd); rc |= remove(DUMMY_FILE); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_config - invalid flagname * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(GET_CONFIG_BASE + 3)) { int fd; void *hanp; size_t hlen; dm_size_t retval; /* Variation set up */ if ((fd = open(DUMMY_FILE, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { /* No clean up */ } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DUMMY_FILE); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid flagname)\n", szFuncName); rc = dm_get_config(hanp, hlen, INVALID_ADDR, &retval); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ rc = close(fd); rc |= remove(DUMMY_FILE); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_config - invalid retvalp * EXPECTED: rc = -1, errno = EFAULT */ if (DMVAR_EXEC(GET_CONFIG_BASE + 4)) { int fd; void *hanp; size_t hlen; /* Variation set up */ if ((fd = open(DUMMY_FILE, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { /* No clean up */ } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DUMMY_FILE); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid retvalp)\n", szFuncName); rc = dm_get_config(hanp, hlen, DM_CONFIG_BULKALL, (dm_size_t *) INVALID_ADDR); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); /* Variation clean up */ rc = close(fd); rc |= remove(DUMMY_FILE); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_config - global handle * EXPECTED: rc = -1, errno = EBADF */ if (DMVAR_EXEC(GET_CONFIG_BASE + 5)) { dm_size_t retval; /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(global handle)\n", szFuncName); rc = dm_get_config(DM_GLOBAL_HANP, DM_GLOBAL_HLEN, DM_CONFIG_BULKALL, &retval); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); /* Variation clean up */ } /* * TEST : dm_get_config - file handle * EXPECTED: rc = 0 */ if (DMVAR_EXEC(GET_CONFIG_BASE + 6)) { int fd; void *hanp; size_t hlen; dm_size_t retval; /* Variation set up */ if ((fd = open(DUMMY_FILE, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { /* No clean up */ } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DUMMY_FILE); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(file handle)\n", szFuncName); rc = dm_get_config(hanp, hlen, DM_CONFIG_BULKALL, &retval); DMVAR_ENDPASSEXP(szFuncName, 0, rc); /* Variation clean up */ rc = close(fd); rc |= remove(DUMMY_FILE); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_config - directory handle * EXPECTED: rc = 0 */ if (DMVAR_EXEC(GET_CONFIG_BASE + 7)) { int fd; void *hanp; size_t hlen; dm_size_t retval; /* Variation set up */ if ((rc = mkdir(DUMMY_SUBDIR, DUMMY_DIR_RW_MODE)) == -1) { /* No clean up */ } else if ((rc = dm_path_to_handle(DUMMY_SUBDIR, &hanp, &hlen)) == -1) { rmdir(DUMMY_SUBDIR); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(dir handle)\n", szFuncName); rc = dm_get_config(hanp, hlen, DM_CONFIG_BULKALL, &retval); DMVAR_ENDPASSEXP(szFuncName, 0, rc); /* Variation clean up */ rc = rmdir(DUMMY_SUBDIR); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_config - fs handle * EXPECTED: rc = 0 */ if (DMVAR_EXEC(GET_CONFIG_BASE + 8)) { int fd; void *hanp; size_t hlen; dm_size_t retval; /* Variation set up */ if ((fd = open(DUMMY_FILE, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { /* No clean up */ } else if ((rc = dm_path_to_fshandle(DUMMY_FILE, &hanp, &hlen)) == -1) { close(fd); remove(DUMMY_FILE); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(fs handle)\n", szFuncName); rc = dm_get_config(hanp, hlen, DM_CONFIG_BULKALL, &retval); DMVAR_ENDPASSEXP(szFuncName, 0, rc); /* Variation clean up */ rc = close(fd); rc |= remove(DUMMY_FILE); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_config - invalidated handle * EXPECTED: rc = -1, errno = EBADF */ if (DMVAR_EXEC(GET_CONFIG_BASE + 9)) { int fd; void *hanp; size_t hlen; dm_size_t retval; /* Variation set up */ if ((fd = open(DUMMY_FILE, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { /* No clean up */ } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DUMMY_FILE); } else if ((rc = close(fd)) == -1) { dm_handle_free(hanp, hlen); remove(DUMMY_FILE); } else if ((rc = remove(DUMMY_FILE)) == -1) { dm_handle_free(hanp, hlen); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalidated handle)\n", szFuncName); rc = dm_get_config(hanp, hlen, DM_CONFIG_BULKALL, &retval); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); /* Variation clean up */ dm_handle_free(hanp, hlen); } } /* * TEST : dm_get_config * EXPECTED: rc = 0 */ for (i = 1; i < CONFIG_MAX; i++) { if (DMVAR_EXEC(GET_CONFIG_BASE + 9 + i)) { int fd; void *hanp; size_t hlen; dm_size_t retval; /* Variation set up */ if ((fd = open(DUMMY_FILE, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) == -1) { /* No clean up */ } else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) { close(fd); remove(DUMMY_FILE); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(%s)\n", szFuncName, dmimpl_expectedResults[i].name); rc = dm_get_config(hanp, hlen, i, &retval); if (rc == 0) { if (retval == dmimpl_expectedResults[i].result) { DMLOG_PRINT(DMLVL_DEBUG, "%s passed with expected rc = %d\n", szFuncName, 0); DMVAR_PASS(); } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d but unexpected retval (%lld vs %lld)\n", szFuncName, 0, retval, dmimpl_expectedResults [i].result); DMVAR_FAIL(); } } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with unexpected rc = %d (errno = %d)\n", szFuncName, rc, errno); DMVAR_FAIL(); } /* Variation clean up */ rc = close(fd); rc |= remove(DUMMY_FILE); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } } DMLOG_STOP(); tst_exit(); }
int main( int argc, char *argv[]) { int c; int error; char *fsname; dm_sessid_t sid; void *fs_hanp; size_t fs_hlen; dm_attrname_t dmattr; size_t bufsz = 65536; dm_attrname_t *dmattrp = NULL; int verbose = V_PRINT; Progname = argv[0]; memset(&dmattr, 0, sizeof(dmattr)); while ((c = getopt(argc, argv, "a:b:vq")) != EOF) { switch (c) { case 'a': if (strlen(optarg) > (DM_ATTR_NAME_SIZE-1)){ printf("Arg for -a too long\n"); exit(1); } strcpy((char*)dmattr.an_chars, optarg); dmattrp = &dmattr; break; case 'b': bufsz = atoi(optarg); break; case 'v': verbose |= V_VERBOSE; break; case 'q': verbose &= ~V_PRINT; break; case '?': default: usage(Progname); exit(1); } } if (optind >= argc) { usage(Progname); exit(1); } fsname = argv[optind]; /* * Now we have our filesystem name and possibly a size threshold * to look for. Init the dmapi, and get a filesystem handle so * we can scan the filesystem */ error = setup_dmapi(&sid); if (error) exit(1); if (dm_path_to_fshandle(fsname, &fs_hanp, &fs_hlen) == -1) { errno_msg("Can't get filesystem handle"); exit(1); } /* * Get the attributes of all files in the filesystem */ error = scan_fs(sid, fs_hanp, fs_hlen, dmattrp, bufsz, verbose); if (error) exit(1); /* * We're done, so we can shut down our session. */ if (dm_destroy_session(sid) == -1) { errno_msg("Can't close session"); exit(1); } return(0); }
int main(int argc, char **argv) { dm_sessid_t sid = DM_NO_SESSION; dm_token_t token[NUM_TOKENS]; dm_token_t test_token; void *fs_hanp; size_t fs_hlen; void *dir_hanp; size_t dir_hlen; void *ap; size_t alen; void *bp; size_t blen; void *cp; size_t clen; char *name; char *ls_path; char *pathname; char fname_a[100]; char fname_b[100]; char fname_c[100]; char command[150]; int opt; int i=0; if (Progname = strrchr(argv[0], '/')) { Progname++; } else { Progname = argv[0]; } opterr = 0; while ((opt = getopt(argc, argv, "vn:s:")) != EOF) { switch (opt) { case 'v': Vflag++; break; case 's': sid = atol(optarg); break; case '?': usage(); } } if (optind + 2 != argc) { usage(); } ls_path = argv[optind]; pathname = argv[optind+1]; if (dm_init_service(&name) == -1) { fprintf(stderr, "Can't inititalize the DMAPI\n"); exit(1); } if (sid == DM_NO_SESSION) find_test_session(&sid); printf("Beginning access rights testing...\n"); sprintf(fname_a, "%s/DMAPI_rights_test_file_a", pathname); sprintf(command, "cp %s %s\n", ls_path, fname_a); system(command); if (dm_path_to_handle(fname_a, &ap, &alen)) { fprintf(stderr, "ERROR: can't get handle for %s; %s\n", fname_a, ERR_NAME); goto abort_test; } sprintf(fname_b, "%s/DMAPI_rights_test_file_b", pathname); sprintf(command, "cp %s %s\n", ls_path, fname_b); system(command); if (dm_path_to_handle(fname_b, &bp, &blen)) { fprintf(stderr, "ERROR: can't get handle for %s; %s\n", fname_b, ERR_NAME); goto abort_test; } sprintf(fname_c, "%s/DMAPI_rights_test_file_c", pathname); sprintf(command, "cp %s %s\n", ls_path, fname_c); system(command); if (dm_path_to_handle(fname_c, &cp, &clen)) { fprintf(stderr, "ERROR: can't get handle for %s; %s\n", fname_c, ERR_NAME); goto abort_test; } if (dm_path_to_fshandle(pathname, &fs_hanp, &fs_hlen)) { fprintf(stderr, "ERROR: can't get handle for %s; %s\n", pathname, ERR_NAME); goto abort_test; } sprintf(pathname, "%s/DMAPI_rights_test_dir", pathname); sprintf(command, "mkdir %s\n", pathname); system(command); if (dm_path_to_handle(pathname, &dir_hanp, &dir_hlen)) { fprintf(stderr, "ERROR: can't get handle for %s; %s\n", pathname, ERR_NAME); goto abort_test; } /* Test remaining functions for appropriate * right requirements... *------------------------------------------------------------*/ { dm_off_t off = (dm_off_t)0; dm_extent_t extent; u_int nelem_ret; SHAREDTEST("get_allocinfo", ap, alen, test_token, dm_get_allocinfo(sid, ap, alen, test_token, &off, 1, &extent, &nelem_ret)) } /*------------------------------------------------------------*/ { void *bufp=(void*)malloc(5*sizeof(dm_attrlist_t)); size_t rlen; SHAREDTEST("getall_dmattr", ap, alen, test_token, dm_getall_dmattr(sid, ap, alen, test_token, 5, bufp, &rlen)) } /*------------------------------------------------------------*/ { dm_attrloc_t loc; SHAREDTEST("init_attrloc", dir_hanp, dir_hlen, test_token, dm_init_attrloc(sid, dir_hanp, dir_hlen, test_token, &loc)) } /*------------------------------------------------------------*/ #if 0 mkdir_by_handle is NOT SUPPORTED in current SGI DMAPI { SHAREDTEST("mkdir_by_handle", fs_hanp, fs_hlen, test_token, dm_mkdir_by_handle(sid, fs_hanp, fs_hlen, test_token, dir_hanp, dir_hlen, "FUBAR_DIR")) } #endif /*------------------------------------------------------------*/ { dm_eventset_t eventset; DMEV_ZERO(eventset); EXCLTEST("set_disp", fs_hanp, fs_hlen, test_token, dm_set_disp(sid, fs_hanp, fs_hlen, test_token, &eventset, DM_EVENT_MAX)) }
void DoTest(dm_token_t token, void *hanp, size_t hlen) { char *szFuncName; int rc; DMLOG_PRINT(DMLVL_DEBUG, "Starting DMAPI rights tests\n") ; szFuncName = "dm_request_right"; /* * TEST : dm_request_right - invalid sid * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 1)) { /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n", szFuncName); rc = dm_request_right(INVALID_ADDR, hanp, hlen, token, 0, DM_RIGHT_SHARED); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ } /* * TEST : dm_request_right - invalid hanp * EXPECTED: rc = -1, errno = EFAULT */ if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 2)) { /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hanp)\n", szFuncName); rc = dm_request_right(sid, (void *)INVALID_ADDR, hlen, token, 0, DM_RIGHT_SHARED); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); /* Variation clean up */ } /* * TEST : dm_request_right - invalid hlen * EXPECTED: rc = -1, errno = EBADF */ if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 3)) { /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hlen)\n", szFuncName); rc = dm_request_right(sid, hanp, INVALID_ADDR, token, 0, DM_RIGHT_SHARED); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); /* Variation clean up */ } /* * TEST : dm_request_right - invalid token * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 4)) { /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid token)\n", szFuncName); rc = dm_request_right(sid, hanp, hlen, INVALID_ADDR, 0, DM_RIGHT_SHARED); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ } /* * TEST : dm_request_right - invalid right * EXPECTED: rc = -1, errno = EINVAL * * This variation uncovered XFS BUG #29 (0 returned instead of -1 and * errno EINVAL) */ if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 5)) { /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid right)\n", szFuncName); rc = dm_request_right(sid, hanp, hlen, token, 0, INVALID_ADDR); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ } /* * TEST : dm_request_right - DM_NO_TOKEN * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 6)) { /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_TOKEN)\n", szFuncName); rc = dm_request_right(sid, hanp, hlen, DM_NO_TOKEN, 0, DM_RIGHT_SHARED); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ } /* * TEST : dm_request_right - DM_RIGHT_SHARED from DM_RIGHT_NULL * EXPECTED: rc = 0 */ if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 7)) { /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_NULL -> DM_RIGHT_SHARED)\n", szFuncName); rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_SHARED); DMVAR_ENDPASSEXP(szFuncName, 0, rc); /* Variation clean up */ rc = dm_release_right(sid, hanp, hlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } /* * TEST : dm_request_right - DM_RIGHT_EXCL from DM_RIGHT_NULL * EXPECTED: rc = 0 */ if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 8)) { /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_NULL -> DM_RIGHT_EXCL)\n", szFuncName); rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_EXCL); DMVAR_ENDPASSEXP(szFuncName, 0, rc); /* Variation clean up */ rc = dm_release_right(sid, hanp, hlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } /* * TEST : dm_request_right - DM_RIGHT_SHARED from DM_RIGHT_SHARED * EXPECTED: rc = 0 */ if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 9)) { /* Variation set up */ rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_SHARED); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_SHARED -> DM_RIGHT_SHARED)\n", szFuncName); rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_SHARED); DMVAR_ENDPASSEXP(szFuncName, 0, rc); /* Variation clean up */ rc = dm_release_right(sid, hanp, hlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_request_right - DM_RIGHT_EXCL from DM_RIGHT_SHARED, * DM_RR_WAIT clear * EXPECTED: rc = 0 */ if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 10)) { /* Variation set up */ rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_SHARED); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_SHARED -> DM_RIGHT_EXCL, DM_RR_WAIT clear)\n", szFuncName); rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_EXCL); DMVAR_ENDPASSEXP(szFuncName, 0, rc); /* Variation clean up */ rc = dm_release_right(sid, hanp, hlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_request_right - DM_RIGHT_EXCL from DM_RIGHT_SHARED, * DM_RR_WAIT set * EXPECTED: rc = -1, errno = EACCES * * This variation uncovered XFS BUG #30 (0 returned instead of -1 and * errno EACCES) */ if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 11)) { /* Variation set up */ rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_SHARED); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_SHARED -> DM_RIGHT_EXCL, DM_RR_WAIT set)\n", szFuncName); rc = dm_request_right(sid, hanp, hlen, token, DM_RR_WAIT, DM_RIGHT_EXCL); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EACCES); /* Variation clean up */ rc = dm_release_right(sid, hanp, hlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_request_right - DM_RIGHT_EXCL from DM_RIGHT_EXCL * EXPECTED: rc = 0 */ if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 12)) { /* Variation set up */ rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_EXCL); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_EXCL -> DM_RIGHT_EXCL)\n", szFuncName); rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_SHARED); DMVAR_ENDPASSEXP(szFuncName, 0, rc); /* Variation clean up */ rc = dm_release_right(sid, hanp, hlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_request_right - DM_RIGHT_SHARED from DM_RIGHT_EXCL * EXPECTED: rc = 0 */ if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 13)) { /* Variation set up */ rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_EXCL); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_EXCL -> DM_RIGHT_SHARED)\n", szFuncName); rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_SHARED); DMVAR_ENDPASSEXP(szFuncName, 0, rc); /* Variation clean up */ rc = dm_release_right(sid, hanp, hlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_request_right - DM_NO_SESSION sid * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 14)) { /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n", szFuncName); rc = dm_request_right(DM_NO_SESSION, hanp, hlen, token, 0, DM_RIGHT_SHARED); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ } /* * TEST : dm_request_right - global handle * EXPECTED: rc = -1, errno = EBADF */ if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 15)) { /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(global handle)\n", szFuncName); rc = dm_request_right(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, token, 0, DM_RIGHT_SHARED); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); /* Variation clean up */ } /* * TEST : dm_request_right - file handle * EXPECTED: rc = 0 */ if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 16)) { void *fhanp; size_t fhlen; /* Variation set up */ rc = dm_fd_to_handle(fd_f, &fhanp, &fhlen); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(file handle)\n", szFuncName); rc = dm_request_right(sid, fhanp, fhlen, token, 0, DM_RIGHT_SHARED); DMVAR_ENDPASSEXP(szFuncName, 0, rc); /* Variation clean up */ rc = dm_release_right(sid, fhanp, fhlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(fhanp, fhlen); } } /* * TEST : dm_request_right - fs handle * EXPECTED: rc = 0 */ if (DMVAR_EXEC(REQUEST_RIGHT_BASE + 17)) { void *fshanp; size_t fshlen; /* Variation set up */ rc = dm_path_to_fshandle(DummyFile, &fshanp, &fshlen); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(fs handle)\n", szFuncName); rc = dm_request_right(sid, fshanp, fshlen, token, 0, DM_RIGHT_SHARED); DMVAR_ENDPASSEXP(szFuncName, 0, rc); /* Variation clean up */ rc = dm_release_right(sid, fshanp, fshlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(fshanp, fshlen); } } szFuncName = "dm_release_right"; /* * TEST : dm_release_right - invalid sid * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(RELEASE_RIGHT_BASE + 1)) { /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n", szFuncName); rc = dm_release_right(INVALID_ADDR, hanp, hlen, token); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ } /* * TEST : dm_release_right - invalid hanp * EXPECTED: rc = -1, errno = EFAULT */ if (DMVAR_EXEC(RELEASE_RIGHT_BASE + 2)) { /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hanp)\n", szFuncName); rc = dm_release_right(sid, (void *)INVALID_ADDR, hlen, token); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); /* Variation clean up */ } /* * TEST : dm_release_right - invalid hlen * EXPECTED: rc = -1, errno = EBADF */ if (DMVAR_EXEC(RELEASE_RIGHT_BASE + 3)) { /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hlen)\n", szFuncName); rc = dm_release_right(sid, hanp, INVALID_ADDR, token); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); /* Variation clean up */ } /* * TEST : dm_release_right - invalid token * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(RELEASE_RIGHT_BASE + 4)) { /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid token)\n", szFuncName); rc = dm_release_right(sid, hanp, hlen, INVALID_ADDR); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ } /* * TEST : dm_release_right - DM_NO_TOKEN * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(RELEASE_RIGHT_BASE + 5)) { /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_TOKEN)\n", szFuncName); rc = dm_release_right(sid, hanp, hlen, DM_NO_TOKEN); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ } /* * TEST : dm_release_right - DM_RIGHT_NULL * EXPECTED: rc = -1, errno = EACCES */ if (DMVAR_EXEC(RELEASE_RIGHT_BASE + 6)) { /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_NULL)\n", szFuncName); rc = dm_release_right(sid, hanp, hlen, token); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EACCES); /* Variation clean up */ } /* * TEST : dm_release_right - DM_RIGHT_SHARED * EXPECTED: rc = 0 */ if (DMVAR_EXEC(RELEASE_RIGHT_BASE + 7)) { /* Variation set up */ rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_SHARED); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_SHARED)\n", szFuncName); rc = dm_release_right(sid, hanp, hlen, token); DMVAR_ENDPASSEXP(szFuncName, 0, rc); /* Variation clean up */ } } /* * TEST : dm_release_right - DM_RIGHT_EXCL * EXPECTED: rc = 0 */ if (DMVAR_EXEC(RELEASE_RIGHT_BASE + 8)) { /* Variation set up */ rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_EXCL); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_EXCL)\n", szFuncName); rc = dm_release_right(sid, hanp, hlen, token); DMVAR_ENDPASSEXP(szFuncName, 0, rc); /* Variation clean up */ } } /* * TEST : dm_release_right - DM_NO_SESSION sid * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(RELEASE_RIGHT_BASE + 9)) { /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n", szFuncName); rc = dm_release_right(DM_NO_SESSION, hanp, hlen, token); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ } /* * TEST : dm_release_right - global handle * EXPECTED: rc = -1, errno = EBADF */ if (DMVAR_EXEC(RELEASE_RIGHT_BASE + 10)) { /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(global handle)\n", szFuncName); rc = dm_release_right(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, token); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); /* Variation clean up */ } /* * TEST : dm_release_right - file handle * EXPECTED: rc = 0 */ if (DMVAR_EXEC(RELEASE_RIGHT_BASE + 11)) { void *fhanp; size_t fhlen; /* Variation set up */ if ((rc == dm_fd_to_handle(fd_f, &fhanp, &fhlen)) == -1) { /* No clean up */ } else if ((rc = dm_request_right(sid, fhanp, fhlen, token, 0, DM_RIGHT_SHARED)) == -1) { dm_handle_free(fhanp, fhlen); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(file handle)\n", szFuncName); rc = dm_release_right(sid, fhanp, fhlen, token); DMVAR_ENDPASSEXP(szFuncName, 0, rc); /* Variation clean up */ dm_handle_free(fhanp, fhlen); } } /* * TEST : dm_release_right - fs handle * EXPECTED: rc = 0 */ if (DMVAR_EXEC(RELEASE_RIGHT_BASE + 12)) { void *fshanp; size_t fshlen; /* Variation set up */ if ((rc == dm_path_to_fshandle(DummyFile, &fshanp, &fshlen)) == -1) { /* No clean up */ } else if ((rc = dm_request_right(sid, fshanp, fshlen, token, 0, DM_RIGHT_SHARED)) == -1) { dm_handle_free(fshanp, fshlen); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(fs handle)\n", szFuncName); rc = dm_release_right(sid, fshanp, fshlen, token); DMVAR_ENDPASSEXP(szFuncName, 0, rc); /* Variation clean up */ dm_handle_free(fshanp, fshlen); } } szFuncName = "dm_query_right"; /* * TEST : dm_query_right - invalid sid * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(QUERY_RIGHT_BASE + 1)) { dm_right_t right; /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n", szFuncName); rc = dm_query_right(INVALID_ADDR, hanp, hlen, token, &right); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ } /* * TEST : dm_query_right - invalid hanp * EXPECTED: rc = -1, errno = EFAULT */ if (DMVAR_EXEC(QUERY_RIGHT_BASE + 2)) { dm_right_t right; /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hanp)\n", szFuncName); rc = dm_query_right(sid, (void *)INVALID_ADDR, hlen, token, &right); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); /* Variation clean up */ } /* * TEST : dm_query_right - invalid hlen * EXPECTED: rc = -1, errno = EBADF */ if (DMVAR_EXEC(QUERY_RIGHT_BASE + 3)) { dm_right_t right; /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hlen)\n", szFuncName); rc = dm_query_right(sid, hanp, INVALID_ADDR, token, &right); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); /* Variation clean up */ } /* * TEST : dm_query_right - invalid token * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(QUERY_RIGHT_BASE + 4)) { dm_right_t right; /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid token)\n", szFuncName); rc = dm_query_right(sid, hanp, hlen, INVALID_ADDR, &right); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ } /* * TEST : dm_query_right - invalid rightp * EXPECTED: rc = -1, errno = EFAULT */ if (DMVAR_EXEC(QUERY_RIGHT_BASE + 5)) { /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid rightp)\n", szFuncName); rc = dm_query_right(sid, hanp, hlen, token, (dm_right_t *)INVALID_ADDR); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); /* Variation clean up */ } /* * TEST : dm_query_right - DM_NO_TOKEN * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(QUERY_RIGHT_BASE + 6)) { dm_right_t right; /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_TOKEN)\n", szFuncName); rc = dm_query_right(sid, hanp, hlen, DM_NO_TOKEN, &right); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ } /* * TEST : dm_query_right - DM_RIGHT_SHARED * EXPECTED: rc = 0 */ if (DMVAR_EXEC(QUERY_RIGHT_BASE + 7)) { dm_right_t right; /* Variation set up */ rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_SHARED); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_SHARED)\n", szFuncName); rc = dm_query_right(sid, hanp, hlen, token, &right); if (rc == 0) { if (right == DM_RIGHT_SHARED) { DMLOG_PRINT(DMLVL_DEBUG, "%s passed with expected rc = %d\n", szFuncName, 0); DMVAR_PASS(); } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d but unexpected right (%d vs %d)\n", szFuncName, 0, right, DM_RIGHT_SHARED); DMVAR_FAIL(); } } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with unexpected rc = %d (errno = %d)\n", szFuncName, rc, errno); DMVAR_FAIL(); } /* Variation clean up */ rc = dm_release_right(sid, hanp, hlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_query_right - DM_RIGHT_EXCL * EXPECTED: rc = 0 */ if (DMVAR_EXEC(QUERY_RIGHT_BASE + 8)) { dm_right_t right; /* Variation set up */ rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_EXCL); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_SHARED)\n", szFuncName); rc = dm_query_right(sid, hanp, hlen, token, &right); if (rc == 0) { if (right == DM_RIGHT_EXCL) { DMLOG_PRINT(DMLVL_DEBUG, "%s passed with expected rc = %d\n", szFuncName, 0); DMVAR_PASS(); } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d but unexpected right (%d vs %d)\n", szFuncName, 0, right, DM_RIGHT_EXCL); DMVAR_FAIL(); } } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with unexpected rc = %d (errno = %d)\n", szFuncName, rc, errno); DMVAR_FAIL(); } /* Variation clean up */ rc = dm_release_right(sid, hanp, hlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_query_right - DM_NO_SESSION sid * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(QUERY_RIGHT_BASE + 9)) { dm_right_t right; /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n", szFuncName); rc = dm_query_right(DM_NO_SESSION, hanp, hlen, token, &right); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ } /* * TEST : dm_query_right - global handle * EXPECTED: rc = -1, errno = EBADF */ if (DMVAR_EXEC(QUERY_RIGHT_BASE + 10)) { dm_right_t right; /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(global handle)\n", szFuncName); rc = dm_query_right(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, token, &right); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); /* Variation clean up */ } /* * TEST : dm_query_right - file handle * EXPECTED: rc = 0 */ if (DMVAR_EXEC(QUERY_RIGHT_BASE + 11)) { void *fhanp; size_t fhlen; dm_right_t right; /* Variation set up */ if ((rc = dm_fd_to_handle(fd_f, &fhanp, &fhlen)) == -1) { /* No clean up */ } else if ((rc = dm_request_right(sid, fhanp, fhlen, token, 0, DM_RIGHT_SHARED)) == -1) { dm_handle_free(fhanp, fhlen); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(file handle)\n", szFuncName); rc = dm_query_right(sid, fhanp, fhlen, token, &right); if (rc == 0) { if (right == DM_RIGHT_SHARED) { DMLOG_PRINT(DMLVL_DEBUG, "%s passed with expected rc = %d\n", szFuncName, 0); DMVAR_PASS(); } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d but unexpected right (%d vs %d)\n", szFuncName, 0, right, DM_RIGHT_SHARED); DMVAR_FAIL(); } } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with unexpected rc = %d (errno = %d)\n", szFuncName, rc, errno); DMVAR_FAIL(); } /* Variation clean up */ rc = dm_release_right(sid, fhanp, fhlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(fhanp, fhlen); } } /* * TEST : dm_query_right - fs handle * EXPECTED: rc = 0 */ if (DMVAR_EXEC(QUERY_RIGHT_BASE + 12)) { void *fshanp; size_t fshlen; dm_right_t right; /* Variation set up */ if ((rc = dm_path_to_fshandle(DummyFile, &fshanp, &fshlen)) == -1) { /* No clean up */ } else if ((rc = dm_request_right(sid, fshanp, fshlen, token, 0, DM_RIGHT_SHARED)) == -1) { dm_handle_free(fshanp, fshlen); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(fs handle)\n", szFuncName); rc = dm_query_right(sid, fshanp, fshlen, token, &right); if (rc == 0) { if (right == DM_RIGHT_SHARED) { DMLOG_PRINT(DMLVL_DEBUG, "%s passed with expected rc = %d\n", szFuncName, 0); DMVAR_PASS(); } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with expected rc = %d but unexpected right (%d vs %d)\n", szFuncName, 0, right, DM_RIGHT_SHARED); DMVAR_FAIL(); } } else { DMLOG_PRINT(DMLVL_ERR, "%s failed with unexpected rc = %d (errno = %d)\n", szFuncName, rc, errno); DMVAR_FAIL(); } /* Variation clean up */ rc = dm_release_right(sid, fshanp, fshlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(fshanp, fshlen); } } szFuncName = "dm_upgrade_right"; /* * TEST : dm_upgrade_right - invalid sid * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(UPGRADE_RIGHT_BASE + 1)) { /* Variation set up */ rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_SHARED); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n", szFuncName); rc = dm_upgrade_right(INVALID_ADDR, hanp, hlen, token); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ rc = dm_release_right(sid, hanp, hlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_upgrade_right - invalid hanp * EXPECTED: rc = -1, errno = EFAULT */ if (DMVAR_EXEC(UPGRADE_RIGHT_BASE + 2)) { /* Variation set up */ rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_SHARED); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hanp)\n", szFuncName); rc = dm_upgrade_right(sid, (void *)INVALID_ADDR, hlen, token); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); /* Variation clean up */ rc = dm_release_right(sid, hanp, hlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_upgrade_right - invalid hlen * EXPECTED: rc = -1, errno = EBADF */ if (DMVAR_EXEC(UPGRADE_RIGHT_BASE + 3)) { /* Variation set up */ rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_SHARED); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hlen)\n", szFuncName); rc = dm_upgrade_right(sid, hanp, INVALID_ADDR, token); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); /* Variation clean up */ rc = dm_release_right(sid, hanp, hlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_upgrade_right - invalid token * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(UPGRADE_RIGHT_BASE + 4)) { /* Variation set up */ rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_SHARED); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid token)\n", szFuncName); rc = dm_upgrade_right(sid, hanp, hlen, INVALID_ADDR); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ rc = dm_release_right(sid, hanp, hlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_upgrade_right - DM_RIGHT_NULL * EXPECTED: rc = -1, errno = EPERM * * This variation uncovered XFS BUG #31 (EACCES returned instead of * EPERM) */ if (DMVAR_EXEC(UPGRADE_RIGHT_BASE + 5)) { /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_NULL)\n", szFuncName); rc = dm_upgrade_right(sid, hanp, hlen, token); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EPERM); /* Variation clean up */ } /* * TEST : dm_upgrade_right - DM_RIGHT_SHARED * EXPECTED: rc = 0 */ if (DMVAR_EXEC(UPGRADE_RIGHT_BASE + 6)) { /* Variation set up */ rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_SHARED); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_SHARED)\n", szFuncName); rc = dm_upgrade_right(sid, hanp, hlen, token); DMVAR_ENDPASSEXP(szFuncName, 0, rc); /* Variation clean up */ rc = dm_release_right(sid, hanp, hlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_upgrade_right - DM_RIGHT_EXCL * EXPECTED: rc = 0 */ if (DMVAR_EXEC(UPGRADE_RIGHT_BASE + 7)) { /* Variation set up */ rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_EXCL); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_EXCL)\n", szFuncName); rc = dm_upgrade_right(sid, hanp, hlen, token); DMVAR_ENDPASSEXP(szFuncName, 0, rc); /* Variation clean up */ rc = dm_release_right(sid, hanp, hlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_upgrade_right - DM_NO_SESSION sid * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(UPGRADE_RIGHT_BASE + 8)) { /* Variation set up */ rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_SHARED); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n", szFuncName); rc = dm_upgrade_right(DM_NO_SESSION, hanp, hlen, token); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ rc = dm_release_right(sid, hanp, hlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_upgrade_right - global handle * EXPECTED: rc = -1, errno = EBADF */ if (DMVAR_EXEC(UPGRADE_RIGHT_BASE + 9)) { /* Variation set up */ rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_SHARED); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(global handle)\n", szFuncName); rc = dm_upgrade_right(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, token); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); /* Variation clean up */ rc = dm_release_right(sid, hanp, hlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_upgrade_right - file handle * EXPECTED: rc = 0 */ if (DMVAR_EXEC(UPGRADE_RIGHT_BASE + 10)) { void *fhanp; size_t fhlen; /* Variation set up */ if ((rc = dm_fd_to_handle(fd_f, &fhanp, &fhlen)) == -1) { /* No clean up */ } else if ((rc = dm_request_right(sid, fhanp, fhlen, token, 0, DM_RIGHT_SHARED)) == -1) { dm_handle_free(fhanp, fhlen); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(file handle)\n", szFuncName); rc = dm_upgrade_right(sid, fhanp, fhlen, token); DMVAR_ENDPASSEXP(szFuncName, 0, rc); /* Variation clean up */ rc = dm_release_right(sid, fhanp, fhlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(fhanp, fhlen); } } /* * TEST : dm_upgrade_right - fs handle * EXPECTED: rc = 0 */ if (DMVAR_EXEC(UPGRADE_RIGHT_BASE + 11)) { void *fshanp; size_t fshlen; /* Variation set up */ if ((rc = dm_path_to_fshandle(DummyFile, &fshanp, &fshlen)) == -1) { /* No clean up */ } else if ((rc = dm_request_right(sid, fshanp, fshlen, token, 0, DM_RIGHT_SHARED)) == -1) { dm_handle_free(fshanp, fshlen); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(fs handle)\n", szFuncName); rc = dm_upgrade_right(sid, fshanp, fshlen, token); DMVAR_ENDPASSEXP(szFuncName, 0, rc); /* Variation clean up */ rc = dm_release_right(sid, fshanp, fshlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(fshanp, fshlen); } } szFuncName = "dm_downgrade_right"; /* * TEST : dm_downgrade_right - invalid sid * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(DOWNGRADE_RIGHT_BASE + 1)) { /* Variation set up */ rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_SHARED); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n", szFuncName); rc = dm_downgrade_right(INVALID_ADDR, hanp, hlen, token); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ rc = dm_release_right(sid, hanp, hlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_downgrade_right - invalid hanp * EXPECTED: rc = -1, errno = EFAULT */ if (DMVAR_EXEC(DOWNGRADE_RIGHT_BASE + 2)) { /* Variation set up */ rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_SHARED); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hanp)\n", szFuncName); rc = dm_downgrade_right(sid, (void *)INVALID_ADDR, hlen, token); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT); /* Variation clean up */ rc = dm_release_right(sid, hanp, hlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_downgrade_right - invalid hlen * EXPECTED: rc = -1, errno = EBADF */ if (DMVAR_EXEC(DOWNGRADE_RIGHT_BASE + 3)) { /* Variation set up */ rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_SHARED); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hlen)\n", szFuncName); rc = dm_downgrade_right(sid, hanp, INVALID_ADDR, token); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); /* Variation clean up */ rc = dm_release_right(sid, hanp, hlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_downgrade_right - invalid token * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(DOWNGRADE_RIGHT_BASE + 4)) { /* Variation set up */ rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_SHARED); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid token)\n", szFuncName); rc = dm_downgrade_right(sid, hanp, hlen, INVALID_ADDR); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ rc = dm_release_right(sid, hanp, hlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_downgrade_right - DM_RIGHT_NULL * EXPECTED: rc = -1, errno = EPERM * * This variation uncovered XFS BUG #32 (EACCES returned instead of * EPERM) */ if (DMVAR_EXEC(DOWNGRADE_RIGHT_BASE + 5)) { /* Variation set up */ /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_NULL)\n", szFuncName); rc = dm_downgrade_right(sid, hanp, hlen, token); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EPERM); /* Variation clean up */ } /* * TEST : dm_downgrade_right - DM_RIGHT_SHARED * EXPECTED: rc = -1, errno = EPERM */ if (DMVAR_EXEC(DOWNGRADE_RIGHT_BASE + 6)) { /* Variation set up */ rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_SHARED); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_SHARED)\n", szFuncName); rc = dm_downgrade_right(sid, hanp, hlen, token); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EPERM); /* Variation clean up */ rc = dm_release_right(sid, hanp, hlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_downgrade_right - DM_RIGHT_EXCL * EXPECTED: rc = 0 */ if (DMVAR_EXEC(DOWNGRADE_RIGHT_BASE + 7)) { /* Variation set up */ rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_EXCL); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_RIGHT_EXCL)\n", szFuncName); rc = dm_downgrade_right(sid, hanp, hlen, token); DMVAR_ENDPASSEXP(szFuncName, 0, rc); /* Variation clean up */ rc = dm_release_right(sid, hanp, hlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_downgrade_right - DM_NO_SESSION sid * EXPECTED: rc = -1, errno = EINVAL */ if (DMVAR_EXEC(DOWNGRADE_RIGHT_BASE + 8)) { /* Variation set up */ rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_SHARED); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n", szFuncName); rc = dm_downgrade_right(DM_NO_SESSION, hanp, hlen, token); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL); /* Variation clean up */ rc = dm_release_right(sid, hanp, hlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_downgrade_right - global handle * EXPECTED: rc = -1, errno = EBADF */ if (DMVAR_EXEC(DOWNGRADE_RIGHT_BASE + 9)) { /* Variation set up */ rc = dm_request_right(sid, hanp, hlen, token, 0, DM_RIGHT_SHARED); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n", szFuncName); rc = dm_downgrade_right(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, token); DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF); /* Variation clean up */ rc = dm_release_right(sid, hanp, hlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : dm_downgrade_right - file handle * EXPECTED: rc = 0 */ if (DMVAR_EXEC(DOWNGRADE_RIGHT_BASE + 10)) { void *fhanp; size_t fhlen; /* Variation set up */ if ((rc = dm_fd_to_handle(fd_f, &fhanp, &fhlen)) == -1) { /* No clean up */ } else if ((rc = dm_request_right(sid, fhanp, fhlen, token, 0, DM_RIGHT_EXCL)) == -1) { dm_handle_free(fhanp, fhlen); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(file handle)\n", szFuncName); rc = dm_downgrade_right(sid, fhanp, fhlen, token); DMVAR_ENDPASSEXP(szFuncName, 0, rc); /* Variation clean up */ rc = dm_release_right(sid, fhanp, fhlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(fhanp, fhlen); } } /* * TEST : dm_downgrade_right - fs handle * EXPECTED: rc = 0 */ if (DMVAR_EXEC(DOWNGRADE_RIGHT_BASE + 11)) { void *fshanp; size_t fshlen; /* Variation set up */ if ((rc = dm_path_to_fshandle(DummyFile, &fshanp, &fshlen)) == -1) { /* No clean up */ } else if ((rc = dm_request_right(sid, fshanp, fshlen, token, 0, DM_RIGHT_EXCL)) == -1) { dm_handle_free(fshanp, fshlen); } if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ DMLOG_PRINT(DMLVL_DEBUG, "%s(fs handle)\n", szFuncName); rc = dm_downgrade_right(sid, fshanp, fshlen, token); DMVAR_ENDPASSEXP(szFuncName, 0, rc); /* Variation clean up */ rc = dm_release_right(sid, fshanp, fshlen, token); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(fshanp, fshlen); } } }