int main(int argc, char **argv) { int i; dm_attrlist_t bufp[1024]; void *dmhandle=NULL; size_t dmhandle_len=0; int ret; dm_sessid_t sid = DM_NO_SESSION; dm_attrname_t attrname; size_t rlen; if(argc<3) { fprintf(stderr,"Usage: %s <file name> <attribute name>\n", argv[0]); return 1; } if(strlen(argv[2])>DM_ATTR_NAME_SIZE-1) { fprintf(stderr,"Usage: %s <file name> <attribute name>\n", argv[0]); fprintf(stderr,"<attribute name> must be %d characters long at maximum\n", DM_ATTR_NAME_SIZE-1); return 1; } if (dm_create_session(DM_NO_SESSION, "dmattr", &sid)!=0) { fprintf(stderr,"dm_create_session: failed, %s\n", strerror(errno)); return 1; } if (dm_path_to_handle(argv[1], &dmhandle, &dmhandle_len) != 0) { fprintf(stderr,"dm_path_to_handle: failed, %s\n", strerror(errno)); dm_destroy_session(sid); return 1; } memset((void *)&attrname.an_chars[0], 0, DM_ATTR_NAME_SIZE); memcpy((void *)&attrname.an_chars[0], argv[2], strlen(argv[2])); ret = dm_get_dmattr(sid, dmhandle, dmhandle_len, DM_NO_TOKEN, &attrname, sizeof(bufp), bufp, &rlen); if(ret==-1) { fprintf(stderr,"dm_get_dmattr: failed, %s\n", strerror(errno)); dm_handle_free(dmhandle, dmhandle_len); dm_destroy_session(sid); return 1; } for(i=0;i<rlen;i++) { unsigned char c=((unsigned char*)bufp)[i]; printf("%02x",c); } printf("\n"); dm_handle_free(dmhandle, dmhandle_len); dm_destroy_session(sid); return 0; }
/* see if a file is offline return -1 on failure. Set *offline to true/false according to offline status */ static int is_offline(char *fname, time_t now, bool *offline) { struct stat st; void *handle=NULL; size_t handle_len=0; size_t rlen; int ret; dm_attrname_t dmAttrName; /* keep some state between calls, to save on session creation calls */ static struct dmapi_state { dm_sessid_t sid; void *handle; size_t handle_len; } state; if (state.sid == 0) { /* create a new session if needed */ if (dm_create_session(DM_NO_SESSION, "samba", &state.sid) != 0) { return -1; } } /* try shortcut methods first */ if (stat(fname, &st) != 0) { return -1; } /* if the file has more than FILE_IS_ONLINE_RATIO of blocks available, then assume its not offline (it may not be 100%, as it could be sparse) */ if (512 * (off_t)st.st_blocks > st.st_size * FILE_IS_ONLINE_RATIO) { *offline = false; return 0; } /* go the slow DMAPI route */ if (dm_path_to_handle(fname, &handle, &handle_len) != 0) { return -1; } memset(&dmAttrName, 0, sizeof(dmAttrName)); strcpy((char *)&dmAttrName.an_chars[0], "IBMObj"); ret = dm_get_dmattr(state.sid, handle, handle_len, DM_NO_TOKEN, &dmAttrName, 0, NULL, &rlen); /* its offline if the IBMObj attribute exists */ *offline = (ret == 0 || (ret == -1 && errno == E2BIG)); dm_handle_free(handle, handle_len); return 0; }
int opaque_to_handle( char *name, void **hanpp, size_t *hlenp) { if (atohan(name, hanpp, hlenp)) { /* not a handle */ } else if (dm_handle_is_valid(*hanpp, *hlenp) == DM_FALSE) { dm_handle_free(*hanpp, *hlenp); /* not a handle */ } else { return(0); } /* Perhaps it is a pathname */ if (dm_path_to_handle(name, hanpp, hlenp)) { return(errno); } return(0); }
int main( int argc, char **argv) { dm_sessid_t sid = DM_NO_SESSION; void *hanp; size_t hlen; dm_fileattr_t fileattr; u_int mask = 0; char *pathname; char *name; int opt; if (Progname = strrchr(argv[0], '/')) { Progname++; } else { Progname = argv[0]; } opterr = 0; while ((opt = getopt(argc, argv, "M:u:g:a:m:c:d:S:s:")) != EOF) { switch (opt) { case 'M': mask |= DM_AT_MODE; fileattr.fa_mode = strtol (optarg, NULL, 8); break; case 'u': mask |= DM_AT_UID; fileattr.fa_uid = atol(optarg); break; case 'g': mask |= DM_AT_GID; fileattr.fa_gid = atol(optarg); break; case 'a': mask |= DM_AT_ATIME; if (get_absolute_date(optarg, &fileattr.FA_ATIME)) break; if (get_relative_date(optarg, &fileattr.FA_ATIME)) break; usage(); case 'm': mask |= DM_AT_MTIME; if (get_absolute_date(optarg, &fileattr.FA_MTIME)) break; if (get_relative_date(optarg, &fileattr.FA_MTIME)) break; usage(); case 'c': mask |= DM_AT_CTIME; if (get_absolute_date(optarg, &fileattr.FA_CTIME)) break; if (get_relative_date(optarg, &fileattr.FA_CTIME)) break; usage(); case 'd': mask |= DM_AT_DTIME; if (get_absolute_date(optarg, &fileattr.FA_DTIME)) break; if (get_relative_date(optarg, &fileattr.FA_DTIME)) break; usage(); case 'S': mask |= DM_AT_SIZE; fileattr.fa_size = 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 inititalize the DMAPI\n"); exit(1); } if (sid == DM_NO_SESSION) find_test_session(&sid); if (dm_path_to_handle(pathname, &hanp, &hlen)) { fprintf(stderr, "dm_path_to_handle failed, %s\n", strerror(errno)); exit(1); } if (dm_set_fileattr(sid, hanp, hlen, DM_NO_TOKEN, mask, &fileattr)) { fprintf(stderr, "dm_set_fileattr failed, %s\n", strerror(errno)); exit(1); } exit(0); }
int main(int argc, char **argv) { char *varstr; int rc; int varStatus; 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(DummyFile2, "%s/%s", mountPt, DUMMY_FILE2); sprintf(DummySubdir, "%s/%s", mountPt, DUMMY_SUBDIR); sprintf(DummySubdir2, "%s/%s", mountPt, DUMMY_SUBDIR2); sprintf(DummyLink, "%s/%s", mountPt, DUMMY_LINK); remove(DummyFile); remove(DummyFile2); unlink(DummyLink); rmdir(DummySubdir); rmdir(DummySubdir2); } DMLOG_PRINT(DMLVL_DEBUG, "Starting DMAPI synchronous namespace event tests\n") ; /* * TEST : mkdir - DM_RESP_CONTINUE * EXPECTED: DM_EVENT_CREATE */ if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 1)) { dm_ino_t ino; /* Variation set up */ eventExpected = DM_EVENT_CREATE; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; /* Variation */ EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "mkdir(%s)\n", DummySubdir); rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE); DMLOG_PRINT(DMLVL_DEBUG, "mkdir(%s) returned %d\n", DummySubdir, rc); if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_SUBDIR) != 0) { DMLOG_PRINT(DMLVL_ERR, "Entry name NOT correct! (%s vs %s)\n", name1, DUMMY_SUBDIR); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ EVENT_DELIVERY_DELAY; rc = rmdir(DummySubdir); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } /* * TEST : mkdir - DM_RESP_ABORT * EXPECTED: DM_EVENT_CREATE */ if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 2)) { dm_ino_t ino; /* Variation set up */ eventExpected = DM_EVENT_CREATE; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_ABORT; /* Variation */ EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "mkdir(%s)\n", DummySubdir); rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE); DMLOG_PRINT(DMLVL_DEBUG, "mkdir(%s) returned %d\n", DummySubdir, rc); if ((varStatus = DMVAR_CHKFAILEXP(-1, rc, ABORT_ERRNO, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_SUBDIR) != 0) { DMLOG_PRINT(DMLVL_ERR, "Entry name NOT correct! (%s vs %s)\n", name1, DUMMY_SUBDIR); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ } /* * TEST : rmdir - DM_RESP_CONTINUE * EXPECTED: DM_EVENT_REMOVE */ if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 3)) { dm_ino_t ino; /* Variation set up */ eventExpected = DM_EVENT_REMOVE; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "rmdir(%s)\n", DummySubdir); rc = rmdir(DummySubdir); DMLOG_PRINT(DMLVL_DEBUG, "rmdir(%s) returned %d\n", DummySubdir, rc); if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_SUBDIR) != 0) { DMLOG_PRINT(DMLVL_ERR, "Entry name NOT correct! (%s vs %s)\n", name1, DUMMY_SUBDIR); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ } } /* * TEST : rmdir - DM_RESP_ABORT * EXPECTED: DM_EVENT_REMOVE */ if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 4)) { dm_ino_t ino; /* Variation set up */ eventExpected = DM_EVENT_REMOVE; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ eventResponse = DM_RESP_ABORT; EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "rmdir(%s)\n", DummySubdir); rc = rmdir(DummySubdir); DMLOG_PRINT(DMLVL_DEBUG, "rmdir(%s) returned %d\n", DummySubdir, rc); if ((varStatus = DMVAR_CHKFAILEXP(-1, rc, ABORT_ERRNO, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_SUBDIR) != 0) { DMLOG_PRINT(DMLVL_ERR, "Entry name NOT correct! (%s vs %s)\n", name1, DUMMY_SUBDIR); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; rc = rmdir(DummySubdir); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : mv - DM_RESP_CONTINUE * EXPECTED: DM_EVENT_RENAME */ if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 5)) { dm_ino_t ino1, ino2; /* Variation set up */ eventExpected = DM_EVENT_RENAME; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; sprintf(command, "mv %s %s", DummySubdir, DummySubdir2); EVENT_DELIVERY_DELAY; rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s)\n", DummySubdir, DummySubdir2); rc = system(command); DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s) returned %d\n", DummySubdir, DummySubdir2, rc); if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino1); rc |= dm_handle_to_ino(hanp2, hlen2, &ino2); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino1 != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Old parent handle NOT root! (%lld vs %d)\n", ino1, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (ino2 != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "New parent handle NOT root! (%lld vs %d)\n", ino2, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (dm_handle_cmp(hanp1, hlen1, hanp2, hlen2) != 0) { DMLOG_PRINT(DMLVL_ERR, "Old parent handle NOT equal to new parent handle!\n"); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_SUBDIR) != 0) { DMLOG_PRINT(DMLVL_ERR, "Old entry name NOT correct! (%s vs %s)\n", name1, DUMMY_SUBDIR); varStatus = DMSTAT_FAIL; } else if (strcmp(name2, DUMMY_SUBDIR2) != 0) { DMLOG_PRINT(DMLVL_ERR, "New entry name NOT correct! (%s vs %s)\n", name2, DUMMY_SUBDIR2); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ EVENT_DELIVERY_DELAY; rc = rmdir(DummySubdir2); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : mv - DM_RESP_ABORT * EXPECTED: DM_EVENT_RENAME */ if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 6)) { dm_ino_t ino1, ino2; /* Variation set up */ eventExpected = DM_EVENT_RENAME; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; sprintf(command, "mv %s %s", DummySubdir, DummySubdir2); EVENT_DELIVERY_DELAY; rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ eventResponse = DM_RESP_ABORT; EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s)\n", DummySubdir, DummySubdir2); rc = system(command); DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s) returned %d\n", DummySubdir, DummySubdir2, rc); if ((varStatus = (rc == 0 ? DMSTAT_FAIL : DMSTAT_PASS)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino1); rc |= dm_handle_to_ino(hanp2, hlen2, &ino2); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino1 != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Old parent handle NOT root! (%lld vs %d)\n", ino1, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (ino2 != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "New parent handle NOT root! (%lld vs %d)\n", ino2, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (dm_handle_cmp(hanp1, hlen1, hanp2, hlen2) != 0) { DMLOG_PRINT(DMLVL_ERR, "Old parent handle NOT equal to new parent handle!\n"); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_SUBDIR) != 0) { DMLOG_PRINT(DMLVL_ERR, "Old entry name NOT correct! (%s vs %s)\n", name1, DUMMY_SUBDIR); varStatus = DMSTAT_FAIL; } else if (strcmp(name2, DUMMY_SUBDIR2) != 0) { DMLOG_PRINT(DMLVL_ERR, "New entry name NOT correct! (%s vs %s)\n", name2, DUMMY_SUBDIR2); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; rc = rmdir(DummySubdir); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : symlink - DM_RESP_CONTINUE * EXPECTED: DM_EVENT_SYMLINK */ if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 7)) { dm_ino_t ino; /* Variation set up */ eventExpected = DM_EVENT_SYMLINK; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s)\n", DummySubdir, DummySubdir2); rc = symlink(DummySubdir, DummySubdir2); DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s) returned %d\n", DummySubdir, DummySubdir2, rc); if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_SUBDIR2) != 0) { DMLOG_PRINT(DMLVL_ERR, "Symlink entry name NOT correct! (%s vs %s)\n", name1, DUMMY_SUBDIR2); varStatus = DMSTAT_FAIL; } else if (strcmp(name2, DummySubdir) != 0) { DMLOG_PRINT(DMLVL_ERR, "Symlink contents NOT correct! (%s vs %s)\n", name2, DummySubdir); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ EVENT_DELIVERY_DELAY; rc = unlink(DummySubdir2); rc |= rmdir(DummySubdir); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : symlink - DM_RESP_ABORT * EXPECTED: DM_EVENT_SYMLINK */ if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 8)) { dm_ino_t ino; /* Variation set up */ eventExpected = DM_EVENT_SYMLINK; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ eventResponse = DM_RESP_ABORT; EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s)\n", DummySubdir, DummySubdir2); rc = symlink(DummySubdir, DummySubdir2); DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s) returned %d\n", DummySubdir, DummySubdir2, rc); EVENT_DELIVERY_DELAY; if ((varStatus = DMVAR_CHKFAILEXP(-1, rc, ABORT_ERRNO, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_SUBDIR2) != 0) { DMLOG_PRINT(DMLVL_ERR, "Symlink entry name NOT correct! (%s vs %s)\n", name1, DUMMY_SUBDIR2); varStatus = DMSTAT_FAIL; } else if (strcmp(name2, DummySubdir) != 0) { DMLOG_PRINT(DMLVL_ERR, "Symlink contents NOT correct! (%s vs %s)\n", name2, DummySubdir); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; rc = rmdir(DummySubdir); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : link - DM_RESP_CONTINUE * EXPECTED: DM_EVENT_LINK */ if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 9)) { #ifdef DIRECTORY_LINKS dm_ino_t ino1, ino2, ino3; void *hanp; size_t hlen; /* Variation set up */ eventExpected = DM_EVENT_LINK; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; 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 */ EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s)\n", DummySubdir, DummyLink); rc = link(DummySubdir, DummyLink); DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s) returned %d\n", DummySubdir, DummyLink, rc); if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino1); rc |= dm_handle_to_ino(hanp2, hlen2, &ino2); rc |= dm_handle_to_ino(hanp, hlen, &ino3); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino1 != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino1, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (ino2 != ino3) { DMLOG_PRINT(DMLVL_ERR, "Source link handle NOT correct! (%lld vs %lld)\n", ino2, ino3); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_LINK) != 0) { DMLOG_PRINT(DMLVL_ERR, "Target entry name NOT correct! (%s vs %s)\n", name1, DUMMY_LINK); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ EVENT_DELIVERY_DELAY; rc = rmdir(DummySubdir); rc |= unlink(DummyLink); 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 DIRECTORY_LINKS defined\n"); DMVAR_SKIP(); #endif } /* * TEST : link - DM_RESP_ABORT * EXPECTED: DM_EVENT_LINK */ if (DMVAR_EXEC(DIR_SYNC_NAMESP_EVENT_BASE + 10)) { #ifdef DIRECTORY_LINKS dm_ino_t ino1, ino2, ino3; void *hanp; size_t hlen; /* Variation set up */ eventExpected = DM_EVENT_LINK; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; 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 */ eventResponse = DM_RESP_ABORT; EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s)\n", DummySubdir, DummyLink); rc = link(DummySubdir, DummyLink); DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s) returned %d\n", DummySubdir, DummyLink, rc); if ((varStatus = DMVAR_CHKFAILEXP(-1, rc, ABORT_ERRNO, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino1); rc |= dm_handle_to_ino(hanp2, hlen2, &ino2); rc |= dm_handle_to_ino(hanp, hlen, &ino3); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino1 != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino1, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (ino2 != ino3) { DMLOG_PRINT(DMLVL_ERR, "Source link handle NOT correct! (%lld vs %lld)\n", ino2, ino3); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_LINK) != 0) { DMLOG_PRINT(DMLVL_ERR, "Target entry name NOT correct! (%s vs %s)\n", name1, DUMMY_LINK); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; rc = rmdir(DummySubdir); 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 DIRECTORY_LINKS defined\n"); DMVAR_SKIP(); #endif } /* * TEST : open * EXPECTED: DM_EVENT_CREATE, DM_RESP_CONTINUE */ if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 1)) { int fd; dm_ino_t ino; /* Variation set up */ eventExpected = DM_EVENT_CREATE; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; /* Variation */ EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "open(%s)\n", DummyFile); fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE); DMLOG_PRINT(DMLVL_DEBUG, "open(%s) returned %d\n", DummyFile, fd); rc = (fd == -1) ? -1 : 0; if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_FILE) != 0) { DMLOG_PRINT(DMLVL_ERR, "Entry name NOT correct! (%s %s)\n", name1, DUMMY_SUBDIR); 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); } } /* * TEST : open * EXPECTED: DM_EVENT_CREATE, DM_RESP_ABORT */ if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 2)) { dm_ino_t ino; int fd; /* Variation set up */ eventExpected = DM_EVENT_CREATE; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_ABORT; /* Variation */ EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "open(%s)\n", DummyFile); fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE); DMLOG_PRINT(DMLVL_DEBUG, "open(%s) returned %d\n", DummyFile, fd); if ((varStatus = DMVAR_CHKFAILEXP(-1, fd, ABORT_ERRNO, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_FILE) != 0) { DMLOG_PRINT(DMLVL_ERR, "Entry name NOT correct! (%s vs %s)\n", name1, DUMMY_FILE); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ } /* * TEST : remove * EXPECTED: DM_EVENT_REMOVE, DM_RESP_CONTINUE */ if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 3)) { dm_ino_t ino; int fd; /* Variation set up */ eventExpected = DM_EVENT_REMOVE; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) != -1) { rc = close(fd); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "remove(%s)\n", DummyFile); rc = remove(DummyFile); DMLOG_PRINT(DMLVL_DEBUG, "remove(%s) returned %d\n", DummyFile, rc); if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_FILE) != 0) { DMLOG_PRINT(DMLVL_ERR, "Entry name NOT correct! (%s vs %s)\n", name1, DUMMY_FILE); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ } } /* * TEST : remove * EXPECTED: DM_EVENT_REMOVE, DM_RESP_ABORT */ if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 4)) { dm_ino_t ino; int fd; /* Variation set up */ eventExpected = DM_EVENT_REMOVE; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) != -1) { rc = close(fd); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ eventResponse = DM_RESP_ABORT; EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "remove(%s)\n", DummyFile); rc = remove(DummyFile); DMLOG_PRINT(DMLVL_DEBUG, "remove(%s) returned %d\n", DummyFile, rc); if ((varStatus = DMVAR_CHKFAILEXP(-1, rc, ABORT_ERRNO, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_FILE) != 0) { DMLOG_PRINT(DMLVL_ERR, "Entry name NOT correct! (%s vs %s)\n", name1, DUMMY_FILE); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; rc = remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : mv * EXPECTED: DM_EVENT_RENAME, DM_RESP_CONTINUE */ if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 5)) { dm_ino_t ino1, ino2; int fd; /* Variation set up */ eventExpected = DM_EVENT_RENAME; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; sprintf(command, "mv %s %s", DummyFile, DummyFile2); EVENT_DELIVERY_DELAY; if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) != -1) { rc = close(fd); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s)\n", DummyFile, DummyFile2); rc = system(command); DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s) returned %d\n", DummyFile, DummyFile2, rc); if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino1); rc |= dm_handle_to_ino(hanp2, hlen2, &ino2); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino1 != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Old parent handle NOT root! (%lld vs %d)\n", ino1, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (ino2 != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "New parent handle NOT root! (%lld vs %d)\n", ino2, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (dm_handle_cmp(hanp1, hlen1, hanp2, hlen2) != 0) { DMLOG_PRINT(DMLVL_ERR, "Old parent handle NOT equal to new parent handle!\n"); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_FILE) != 0) { DMLOG_PRINT(DMLVL_ERR, "Old entry name NOT correct! (%s vs %s)\n", name1, DUMMY_FILE); varStatus = DMSTAT_FAIL; } else if (strcmp(name2, DUMMY_FILE2) != 0) { DMLOG_PRINT(DMLVL_ERR, "New entry name NOT correct! (%s vs %s)\n", name2, DUMMY_FILE2); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ EVENT_DELIVERY_DELAY; rc = remove(DummyFile2); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); } } } /* * TEST : mv * EXPECTED: DM_EVENT_RENAME, DM_RESP_ABORT */ if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 6)) { dm_ino_t ino1, ino2; int fd; /* Variation set up */ eventExpected = DM_EVENT_RENAME; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; sprintf(command, "mv %s %s", DummyFile, DummyFile2); EVENT_DELIVERY_DELAY; if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) != -1) { rc = close(fd); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ eventResponse = DM_RESP_ABORT; EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s)\n", DummyFile, DummyFile2); rc = system(command); DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s) returned %d\n", DummyFile, DummyFile2, rc); if ((varStatus = (rc == 0 ? DMSTAT_FAIL : DMSTAT_PASS)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino1); rc |= dm_handle_to_ino(hanp2, hlen2, &ino2); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino1 != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Old parent handle NOT root! (%lld vs %d)\n", ino1, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (ino2 != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "New parent handle NOT root! (%lld vs %d)\n", ino2, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (dm_handle_cmp(hanp1, hlen1, hanp2, hlen2) != 0) { DMLOG_PRINT(DMLVL_ERR, "Old parent handle NOT equal to new parent handle!\n"); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_FILE) != 0) { DMLOG_PRINT(DMLVL_ERR, "Old entry name NOT correct! (%s vs %s)\n", name1, DUMMY_FILE); varStatus = DMSTAT_FAIL; } else if (strcmp(name2, DUMMY_FILE2) != 0) { DMLOG_PRINT(DMLVL_ERR, "New entry name NOT correct! (%s vs %s)\n", name2, DUMMY_FILE2); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; rc = remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : symlink * EXPECTED: DM_EVENT_SYMLINK, DM_RESP_CONTINUE */ if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 7)) { dm_ino_t ino; int fd; /* Variation set up */ eventExpected = DM_EVENT_SYMLINK; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) != -1) { rc = close(fd); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s)\n", DummyFile, DummyLink); rc = symlink(DummyFile, DummyLink); DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s) returned %d\n", DummyFile, DummyLink, rc); if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_LINK) != 0) { DMLOG_PRINT(DMLVL_ERR, "Symlink entry name NOT correct! (%s vs %s)\n", name1, DUMMY_LINK); varStatus = DMSTAT_FAIL; } else if (strcmp(name2, DummyFile) != 0) { DMLOG_PRINT(DMLVL_ERR, "Symlink contents NOT correct! (%s vs %s)\n", name2, DummyFile); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ EVENT_DELIVERY_DELAY; rc = unlink(DummyLink); rc |= remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : symlink * EXPECTED: DM_EVENT_SYMLINK, DM_RESP_ABORT */ if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 8)) { dm_ino_t ino; int fd; /* Variation set up */ eventExpected = DM_EVENT_SYMLINK; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; if ((fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE)) != -1) { rc = close(fd); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ eventResponse = DM_RESP_ABORT; EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s)\n", DummyFile, DummyLink); rc = symlink(DummyFile, DummyLink); DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s) returned %d\n", DummyFile, DummyLink, rc); if ((varStatus = DMVAR_CHKFAILEXP(-1, rc, ABORT_ERRNO, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_LINK) != 0) { DMLOG_PRINT(DMLVL_ERR, "Symlink entry name NOT correct! (%s vs %s)\n", name1, DUMMY_LINK); varStatus = DMSTAT_FAIL; } else if (strcmp(name2, DummyFile) != 0) { DMLOG_PRINT(DMLVL_ERR, "Symlink contents NOT correct! (%s vs %s)\n", name2, DummyFile); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; rc = remove(DummyFile); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } } } /* * TEST : link * EXPECTED: DM_EVENT_LINK, DM_RESP_CONTINUE */ if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 9)) { dm_ino_t ino1, ino2, ino3; void *hanp; size_t hlen; int fd; /* Variation set up */ eventExpected = DM_EVENT_LINK; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; if ((fd = open(DummyFile, 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); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s)\n", DummyFile, DummyLink); rc = link(DummyFile, DummyLink); DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s) returned %d\n", DummyFile, DummyLink, rc); if ((varStatus = DMVAR_CHKPASSEXP(0, rc, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino1); rc |= dm_handle_to_ino(hanp2, hlen2, &ino2); rc |= dm_handle_to_ino(hanp, hlen, &ino3); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino1 != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino1, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (ino2 != ino3) { DMLOG_PRINT(DMLVL_ERR, "Source link handle NOT correct! (%lld vs %lld)\n", ino2, ino3); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_LINK) != 0) { DMLOG_PRINT(DMLVL_ERR, "Target entry name NOT correct! (%s vs %s)\n", name1, DUMMY_LINK); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ EVENT_DELIVERY_DELAY; rc = close(fd); rc |= remove(DummyFile); rc |= remove(DummyLink); if (rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to clean up variation! (errno = %d)\n", errno); } dm_handle_free(hanp, hlen); } } /* * TEST : link * EXPECTED: DM_EVENT_LINK, DM_RESP_ABORT */ if (DMVAR_EXEC(FILE_SYNC_NAMESP_EVENT_BASE + 10)) { dm_ino_t ino1, ino2, ino3; void *hanp; size_t hlen; int fd; /* Variation set up */ eventExpected = DM_EVENT_LINK; eventReceived = DM_EVENT_INVALID; eventResponse = DM_RESP_CONTINUE; EVENT_DELIVERY_DELAY; if ((fd = open(DummyFile, 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); } if (fd == -1 || rc == -1) { DMLOG_PRINT(DMLVL_DEBUG, "Unable to set up variation! (errno = %d)\n", errno); DMVAR_SKIP(); } else { /* Variation */ eventResponse = DM_RESP_ABORT; EVENT_DELIVERY_DELAY; DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s)\n", DummyFile, DummyLink); rc = link(DummyFile, DummyLink); DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s) returned %d\n", DummyFile, DummyLink, rc); if ((varStatus = DMVAR_CHKFAILEXP(-1, rc, ABORT_ERRNO, eventExpected, eventReceived)) == DMSTAT_PASS) { rc = dm_handle_to_ino(hanp1, hlen1, &ino1); rc |= dm_handle_to_ino(hanp2, hlen2, &ino2); rc |= dm_handle_to_ino(hanp, hlen, &ino3); if (rc == -1) { DMLOG_PRINT(DMLVL_ERR, "Unable to obtain inode!\n"); varStatus = DMSTAT_FAIL; } else if (ino1 != ROOT_INODE) { DMLOG_PRINT(DMLVL_ERR, "Parent handle NOT root! (%lld vs %d)\n", ino1, ROOT_INODE); varStatus = DMSTAT_FAIL; } else if (ino2 != ino3) { DMLOG_PRINT(DMLVL_ERR, "Source link handle NOT correct! (%lld vs %lld)\n", ino2, ino3); varStatus = DMSTAT_FAIL; } else if (strcmp(name1, DUMMY_LINK) != 0) { DMLOG_PRINT(DMLVL_ERR, "Target entry name NOT correct! (%s vs %s)\n", name1, DUMMY_LINK); varStatus = DMSTAT_FAIL; } } DMVAR_END(varStatus); /* Variation clean up */ eventResponse = DM_RESP_CONTINUE; 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); } } 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(); tst_exit(); }
int main( int argc, char *argv[]) { int c; int error; int mr_flag, alloc_flag, handle_flag, event_flag; void *hanp; size_t hlen; char *filename; dm_sessid_t sid; Progname = argv[0]; mr_flag = alloc_flag = handle_flag = event_flag = 0; while ((c = getopt(argc, argv, "maeh")) != EOF) { switch (c) { case 'm': mr_flag = 1; break; case 'a': alloc_flag = 1; break; case 'e': event_flag = 1; break; case 'h': handle_flag = 1; break; case '?': default: usage(Progname); exit(1); } } if (optind >= argc) { usage(Progname); exit(1); } filename = argv[optind]; if (filename == NULL) { usage(Progname); exit(1); } /* * Set up our link to the DMAPI, and get a handle for * the file we want to query */ error = setup_dmapi(&sid); if (error) exit(1); if (dm_path_to_handle(filename, &hanp, &hlen) == -1) { printf("Can't get handle for path %s", filename); error = 1; goto out; } printf("File %s:\n", filename); if (mr_flag) { error = mr_info(sid, hanp, hlen); if (error) { error = 1; goto out; } } if (alloc_flag) { error = alloc_info(sid, hanp, hlen); if (error) { error = 1; goto out; } } if (event_flag) { error = event_info(sid, hanp, hlen); if (error) { error = 1; goto out; } } if (handle_flag) { error = handle_info(sid, hanp, hlen); if (error) { error = 1; goto out; } } out: if (dm_destroy_session(sid)) { errno_msg("Can't shut down session"); error = 1; } return(error); }
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) { dm_region_t region = { 0, 0, 0 }; dm_region_t checkregion = { 0, 0, 0 }; dm_sessid_t sid = DM_NO_SESSION; char *dir_name = NULL; char *ls_path = NULL; char object[128]; char command[128]; u_int exactflag; u_int nelem_read = 0; void *hanp; size_t hlen; char *name; int opt; int i; int Vflag = 0; dm_token_t test_token = DM_NO_TOKEN; if (Progname = strrchr(argv[0], '/')) { Progname++; } else { Progname = argv[0]; } /* Crack and validate the command line options. */ while ((opt = getopt(argc, argv, "vo:l:s:")) != EOF) { switch (opt) { case 'v': Vflag++; break; case 'o': region.rg_offset = atol(optarg); break; case 'l': region.rg_size = atol(optarg); break; case 's': sid = atol(optarg); break; case '?': usage(); } } if (optind + 2 > argc) usage(); ls_path = argv[optind]; dir_name = 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); /***********************************************\ |* Beginning the testing of set/get_region... *| \***********************************************/ printf("Region test beginning...\n"); sprintf(object, "%s/VeryLongUnlikelyFilename.REGIONTEST", dir_name); sprintf(command, "cp %s %s \n", ls_path, object); system(command); /* Get the test file's handle. */ if (dm_path_to_handle(object, &hanp, &hlen)) { fprintf(stderr, "can't get handle for file %s\n", object); exit(1); } /* Loop over all possible region flag combinations, * setting and getting. See what works! */ for (i = 0; i < 8; i++) { region.rg_flags = reg_flags[i]; if (dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, NELEM, ®ion, &exactflag)) { fprintf(stderr, "dm_set_region failed, %s\n", ERR_NAME); continue; } if (exactflag != DM_TRUE){ fprintf(stdout, "oops...exactflag was false!\n"); } if (dm_get_region(sid, hanp, hlen, DM_NO_TOKEN, NELEM, &checkregion, &nelem_read)) { fprintf(stderr, "dm_get_region failed, %s\n", ERR_NAME); continue; } if (region.rg_flags != checkregion.rg_flags) { fprintf(stdout, "set region flags %d, but found %d\n", region.rg_flags, checkregion.rg_flags); } else if (Vflag) { fprintf(stdout, "Test #%d okay\n", i); } } /*************************************\ |* Correct-input testing complete. *| |* Beginning improper-input testing. *| \*************************************/ printf("\t(errno subtests beginning...)\n"); region.rg_flags = 7; /**** SET tests ****/ /*---------------------------------------------------------*/ ERRTEST(E2BIG, "set", dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, 2, ®ion, &exactflag)) ERRTEST(E2BIG, "set", dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, -1, ®ion, &exactflag)) /*---------------------------------------------------------*/ EXCLTEST("set", hanp, hlen, test_token, dm_set_region(sid, hanp, hlen, test_token, NELEM, ®ion, &exactflag)) /*---------------------------------------------------------*/ ERRTEST(EFAULT, "set", dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, NELEM, (dm_region_t*)(-1000), &exactflag)) ERRTEST(EFAULT, "set", dm_set_region(sid, hanp, hlen, DM_NO_TOKEN, NELEM, ®ion, (dm_boolean_t*)(-1000))) /*---------------------------------------------------------*/ ERRTEST(EINVAL, "set (bad session id)", dm_set_region(-100, hanp, hlen, DM_NO_TOKEN, NELEM, ®ion, &exactflag)) /*---------------------------------------------------------*/ /**** GET tests ****/ /*---------------------------------------------------------*/ ERRTEST (E2BIG, "get", dm_get_region(sid, hanp, hlen, DM_NO_TOKEN, 0, &checkregion, &nelem_read)) /*---------------------------------------------------------*/ ERRTEST(EFAULT, "get (bad handle)", dm_get_region(sid, NULL, hlen, DM_NO_TOKEN, NELEM, &checkregion, &nelem_read)) /*---------------------------------------------------------*/ ERRTEST(EFAULT, "get (bad regbufp)", dm_get_region(sid, hanp, hlen, DM_NO_TOKEN, NELEM, (dm_region_t *)(-1000), &nelem_read)) /*---------------------------------------------------------*/ ERRTEST(EFAULT, "get (bad nelemp)", dm_get_region(sid, hanp, hlen, DM_NO_TOKEN, NELEM, &checkregion, (u_int *)(-1000))) /*---------------------------------------------------------*/ SHAREDTEST("get", hanp, hlen, test_token, dm_get_region(sid, hanp, hlen, test_token, NELEM, &checkregion, &nelem_read)) /*---------------------------------------------------------*/ ERRTEST(EINVAL, "get", dm_get_region(-100, hanp, hlen, DM_NO_TOKEN, NELEM, &checkregion, &nelem_read)) /*---------------------------------------------------------*/ printf("\t(errno subtests complete)\n"); /**********************************\ |* End of improper-input testing. *| \**********************************/ sprintf(command, "rm %s \n", object); system(command); printf("Region test complete.\n"); /***********************************\ |* End of set/get_region testing. *| \***********************************/ dm_handle_free(hanp, hlen); exit(0); }
/* migrate one file */ static int hsm_migrate(const char *path) { int ret; void *hanp = NULL; size_t hlen = 0; dm_attrname_t attrname; uint8_t buf[0x1000]; size_t rlen; struct stat st; struct hsm_attr h; dm_region_t region; dm_boolean_t exactFlag; off_t ofs; int retval = 1; struct hsm_store_handle *handle; dmapi.token = DM_NO_TOKEN; ret = dm_path_to_handle(discard_const(path), &hanp, &hlen); if (ret != 0) { printf("dm_path_to_handle failed for %s - %s\n", path, strerror(errno)); exit(1); } /* we create a user event which we use to gain exclusive rights on the file */ ret = dm_create_userevent(dmapi.sid, 0, NULL, &dmapi.token); if (ret != 0) { printf("dm_create_userevent failed for %s - %s\n", path, strerror(errno)); exit(1); } /* getting an exclusive right first guarantees that two migrate commands don't happen at the same time on the same file, and also guarantees that a recall isn't happening at the same time. We then downgrade to a shared right immediately, which still gives the same guarantee, but means that any reads on the file can proceeed while we are saving away the data during the migrate */ ret = dm_request_right(dmapi.sid, hanp, hlen, dmapi.token, DM_RR_WAIT, DM_RIGHT_EXCL); if (ret != 0) { printf("dm_request_right failed for %s - %s\n", path, strerror(errno)); goto respond; } /* now downgrade the right - reads on the file can then proceed during the expensive migration step */ ret = dm_downgrade_right(dmapi.sid, hanp, hlen, dmapi.token); if (ret != 0) { printf("dm_downgrade_right failed for %s - %s\n", path, strerror(errno)); goto respond; } memset(attrname.an_chars, 0, DM_ATTR_NAME_SIZE); strncpy((char*)attrname.an_chars, HSM_ATTRNAME, DM_ATTR_NAME_SIZE); /* get any existing attribute on the file */ ret = dm_get_dmattr(dmapi.sid, hanp, hlen, dmapi.token, &attrname, sizeof(h), &h, &rlen); if (ret != 0 && errno != ENOENT) { printf("dm_get_dmattr failed for %s - %s\n", path, strerror(errno)); goto respond; } /* check it is valid */ if (ret == 0) { if (strncmp(h.magic, HSM_MAGIC, sizeof(h.magic)) != 0) { printf("Bad magic '%*.*s'\n", (int)sizeof(h.magic), (int)sizeof(h.magic), h.magic); exit(1); } if (h.state == HSM_STATE_START) { /* a migration has died on this file */ printf("Continuing migration of partly migrated file\n"); hsm_store_remove(store_ctx, h.device, h.inode); } else { /* it is either fully migrated, or waiting recall */ printf("Not migrating already migrated file %s\n", path); goto respond; } } if (lstat(path, &st) != 0) { printf("failed to stat %s - %s\n", path, strerror(errno)); goto respond; } if (!S_ISREG(st.st_mode)) { printf("Not migrating non-regular file %s\n", path); goto respond; } if (st.st_size == 0) { printf("Not migrating file '%s' of size 0\n", path); goto respond; } /* open up the store file */ handle = hsm_store_open(store_ctx, st.st_dev, st.st_ino, false); if (handle == NULL) { printf("Failed to open store file for %s - %s\n", path, strerror(errno)); goto respond; } /* read the file data and store it away */ ofs = 0; while ((ret = dm_read_invis(dmapi.sid, hanp, hlen, dmapi.token, ofs, sizeof(buf), buf)) > 0) { if (hsm_store_write(handle, buf, ret) != 0) { printf("Failed to write to store for %s - %s\n", path, strerror(errno)); hsm_store_close(handle); hsm_store_remove(store_ctx, st.st_dev, st.st_ino); goto respond; } ofs += ret; } if (ret == -1) { printf("failed dm_read_invis on %s - %s\n", path, strerror(errno)); hsm_store_close(handle); hsm_store_remove(store_ctx, st.st_dev, st.st_ino); goto respond; } hsm_store_close(handle); /* now upgrade to a exclusive right on the file before we change the dmattr and punch holes in the file. */ ret = dm_upgrade_right(dmapi.sid, hanp, hlen, dmapi.token); if (ret != 0) { printf("dm_upgrade_right failed for %s - %s\n", path, strerror(errno)); goto respond; } strncpy(h.magic, HSM_MAGIC, sizeof(h.magic)); h.size = st.st_size; h.migrate_time = time(NULL); h.device = st.st_dev; h.inode = st.st_ino; h.state = HSM_STATE_START; /* mark the file as starting to migrate */ ret = dm_set_dmattr(dmapi.sid, hanp, hlen, dmapi.token, &attrname, 0, sizeof(h), (void*)&h); if (ret == -1) { printf("failed dm_set_dmattr on %s - %s\n", path, strerror(errno)); hsm_store_remove(store_ctx, st.st_dev, st.st_ino); goto respond; } /* mark the whole file as offline, including parts beyond EOF */ region.rg_offset = 0; region.rg_size = 0; /* zero means the whole file */ region.rg_flags = DM_REGION_WRITE | DM_REGION_READ; ret = dm_set_region(dmapi.sid, hanp, hlen, dmapi.token, 1, ®ion, &exactFlag); if (ret == -1) { printf("failed dm_set_region on %s - %s\n", path, strerror(errno)); hsm_store_remove(store_ctx, st.st_dev, st.st_ino); goto respond; } /* this dm_get_dmattr() is not strictly necessary - it is just paranoia */ ret = dm_get_dmattr(dmapi.sid, hanp, hlen, dmapi.token, &attrname, sizeof(h), &h, &rlen); if (ret != 0) { printf("ERROR: Abandoning partial migrate - attribute gone!?\n"); goto respond; } if (h.state != HSM_STATE_START) { printf("ERROR: Abandoning partial migrate - state=%d\n", h.state); goto respond; } ret = dm_punch_hole(dmapi.sid, hanp, hlen, dmapi.token, 0, st.st_size); if (ret == -1) { printf("failed dm_punch_hole on %s - %s\n", path, strerror(errno)); hsm_store_remove(store_ctx, st.st_dev, st.st_ino); goto respond; } h.state = HSM_STATE_MIGRATED; /* mark the file as fully migrated */ ret = dm_set_dmattr(dmapi.sid, hanp, hlen, dmapi.token, &attrname, 0, sizeof(h), (void*)&h); if (ret == -1) { printf("failed dm_set_dmattr on %s - %s\n", path, strerror(errno)); hsm_store_remove(store_ctx, st.st_dev, st.st_ino); goto respond; } printf("Migrated file '%s' of size %d\n", path, (int)st.st_size); retval = 0; respond: /* destroy our userevent */ ret = dm_respond_event(dmapi.sid, dmapi.token, DM_RESP_CONTINUE, 0, 0, NULL); if (ret == -1) { printf("failed dm_respond_event on %s - %s\n", path, strerror(errno)); exit(1); } dmapi.token = DM_NO_TOKEN; dm_handle_free(hanp, hlen); return retval; }
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) { dm_sessid_t sid = DM_NO_SESSION; char *pathname = NULL; dm_off_t offset = 0; dm_size_t length = 0; dm_off_t roffp; dm_size_t rlenp; void *hanp; size_t hlen; 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, "o:l:s:")) != EOF) { switch (opt) { case 'o': offset = atol(optarg); break; case 'l': length = 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_handle(pathname, &hanp, &hlen)) { fprintf(stderr, "can't get handle for file %s\n", pathname); exit(1); } if (dm_probe_hole(sid, hanp, hlen, DM_NO_TOKEN, offset, length, &roffp, &rlenp)) { fprintf(stderr, "dm_probe_hole failed, %s\n", strerror(errno)); exit(1); } fprintf(stdout, "roffp is %lld, rlenp is %llu\n", (long long) roffp, (unsigned long long) rlenp); dm_handle_free(hanp, hlen); exit(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)) }
static bool tsmsm_is_offline(struct vfs_handle_struct *handle, const struct smb_filename *fname, SMB_STRUCT_STAT *stbuf) { struct tsmsm_struct *tsmd = (struct tsmsm_struct *) handle->data; const dm_sessid_t *dmsession_id; void *dmhandle = NULL; size_t dmhandle_len = 0; size_t rlen; dm_attrname_t dmname; int ret, lerrno; bool offline; char *buf = NULL; size_t buflen; NTSTATUS status; char *path; status = get_full_smb_filename(talloc_tos(), fname, &path); if (!NT_STATUS_IS_OK(status)) { errno = map_errno_from_nt_status(status); return false; } /* if the file has more than FILE_IS_ONLINE_RATIO of blocks available, then assume it is not offline (it may not be 100%, as it could be sparse) */ if (512 * stbuf->st_ex_blocks >= stbuf->st_ex_size * tsmd->online_ratio) { DEBUG(10,("%s not offline: st_blocks=%llu st_size=%llu " "online_ratio=%.2f\n", path, (unsigned long long)stbuf->st_ex_blocks, (unsigned long long)stbuf->st_ex_size, tsmd->online_ratio)); return false; } dmsession_id = dmapi_get_current_session(); if (dmsession_id == NULL) { DEBUG(2, ("tsmsm_is_offline: no DMAPI session available? " "Assume file is online.\n")); return false; } /* using POSIX capabilities does not work here. It's a slow path, so * become_root() is just as good anyway (tridge) */ /* Also, AIX has DMAPI but no POSIX capablities support. In this case, * we need to be root to do DMAPI manipulations. */ become_root(); /* go the slow DMAPI route */ if (dm_path_to_handle((char*)path, &dmhandle, &dmhandle_len) != 0) { DEBUG(2,("dm_path_to_handle failed - assuming offline (%s) - %s\n", path, strerror(errno))); offline = true; goto done; } memset(&dmname, 0, sizeof(dmname)); strlcpy((char *)&dmname.an_chars[0], tsmd->attrib_name, sizeof(dmname.an_chars)); if (tsmd->attrib_value != NULL) { buflen = strlen(tsmd->attrib_value); } else { buflen = 1; } buf = talloc_zero_size(tsmd, buflen); if (buf == NULL) { DEBUG(0,("out of memory in tsmsm_is_offline -- assuming online (%s)\n", path)); errno = ENOMEM; offline = false; goto done; } do { lerrno = 0; ret = dm_get_dmattr(*dmsession_id, dmhandle, dmhandle_len, DM_NO_TOKEN, &dmname, buflen, buf, &rlen); if (ret == -1 && errno == EINVAL) { DEBUG(0, ("Stale DMAPI session, re-creating it.\n")); lerrno = EINVAL; if (dmapi_new_session()) { dmsession_id = dmapi_get_current_session(); } else { DEBUG(0, ("Unable to re-create DMAPI session, assuming offline (%s) - %s\n", path, strerror(errno))); offline = true; dm_handle_free(dmhandle, dmhandle_len); goto done; } } } while (ret == -1 && lerrno == EINVAL); /* check if we need a specific attribute value */ if (tsmd->attrib_value != NULL) { offline = (ret == 0 && rlen == buflen && memcmp(buf, tsmd->attrib_value, buflen) == 0); } else { /* its offline if the specified DMAPI attribute exists */ offline = (ret == 0 || (ret == -1 && errno == E2BIG)); } DEBUG(10,("dm_get_dmattr %s ret=%d (%s)\n", path, ret, strerror(errno))); ret = 0; dm_handle_free(dmhandle, dmhandle_len); done: talloc_free(buf); unbecome_root(); return offline; }
int main( int argc, char **argv) { dm_sessid_t sid = DM_NO_SESSION; dm_attrloc_t loc = 0; char *dirpath; char buffer[100]; void *bufp; size_t buflen = 10000; u_int mask; size_t rlenp; void *hanp; size_t hlen; char *name; int opt; int i; int ret; int oneline = 0; int quiet = 0; if (Progname = strrchr(argv[0], '/')) { Progname++; } else { Progname = argv[0]; } /* Crack and validate the command line options. */ while ((opt = getopt(argc, argv, "b:l:s:1q")) != EOF) { switch (opt) { case 'b': buflen = atol(optarg); break; case 'l': loc = atol(optarg); break; case 's': sid = atol(optarg); break; case '1': oneline = 1; break; case 'q': quiet = 1; break; case '?': usage(); } } if (optind + 1 != argc) usage(); dirpath = 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 directory's handle. */ if (dm_path_to_handle(dirpath, &hanp, &hlen)) { fprintf(stderr, "can't get handle for file %s, %s\n", dirpath, strerror(errno)); exit(1); } if ((bufp = malloc(buflen == 0 ? 1 : buflen)) == NULL) { fprintf(stderr, "malloc failed, %s\n", strerror(errno)); exit(1); } mask = DM_AT_HANDLE|DM_AT_EMASK|DM_AT_PMANR|DM_AT_PATTR|DM_AT_DTIME|DM_AT_CFLAG|DM_AT_STAT; do { memset(bufp, 0, buflen); if ((ret = dm_get_dirattrs(sid, hanp, hlen, DM_NO_TOKEN, mask, &loc, buflen, bufp, &rlenp)) < 0) { fprintf(stderr, "dm_get_dirattrs failed, %s\n", strerror(errno)); exit(1); } if (!quiet) { fprintf(stdout, "ret = %d, rlenp is %d, loc is %lld\n", ret, rlenp, loc); } if (rlenp > 0) { dm_stat_t *statp; statp = (dm_stat_t *)bufp; while (statp != NULL) { hantoa((char *)statp + statp->dt_handle.vd_offset, statp->dt_handle.vd_length, buffer); if (oneline) { fprintf(stdout, "%s %s\n", (char *)statp + statp->dt_compname.vd_offset, buffer); } else { fprintf(stdout, "handle %s\n", buffer); fprintf(stdout, "name %s\n", (char *)statp + statp->dt_compname.vd_offset); print_line(statp); } statp = DM_STEP_TO_NEXT(statp, dm_stat_t *); } } else if ((ret == 1) && (rlenp == 0) && (!quiet)) { fprintf(stderr, "buflen is too short to hold anything\n"); exit(1); } } while (ret != 0);
int main( int argc, char **argv) { dm_sessid_t sid = DM_NO_SESSION; dm_off_t startoff = 0; /* starting offset */ u_int nelem = 100; char *pathname; void *hanp; size_t hlen; dm_stat_t sbuf; char *name; int opt; if (Progname = strrchr(argv[0], '/')) { Progname++; } else { Progname = argv[0]; } /* Crack and validate the command line options. */ while ((opt = getopt(argc, argv, "Dn:o:s:")) != EOF) { switch(opt) { case 'D': Dflag++; break; case 'n': nelem = atol(optarg); break; case 'o': startoff = atoll(optarg); break; case 's': sid = atol(optarg); break; case '?': usage(); } } if (optind + 1 != argc) usage(); pathname = argv[optind]; if (dm_init_service(&name)) { fprintf(stderr, "dm_init_service failed, %s\n", strerror(errno)); exit(1); } if (sid == DM_NO_SESSION) find_test_session(&sid); /* Get the file's handle and verify that it is a regular file. */ if (dm_path_to_handle(pathname, &hanp, &hlen)) { fprintf(stderr, "can't get handle for %s\n", pathname); exit(1); } if (dm_get_fileattr(sid, hanp, hlen, DM_NO_TOKEN, DM_AT_STAT, &sbuf)) { fprintf(stderr, "dm_get_fileattr failed\n"); exit(1); } if (!S_ISREG(sbuf.dt_mode)) { fprintf(stderr, "%s is not a regular file\n", pathname); exit(1); } /* Print the allocation. */ if (print_alloc(sid, hanp, hlen, pathname, startoff, nelem)) exit(1); dm_handle_free(hanp, hlen); exit(0); }