1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2001 Silicon Graphics, Inc.
17 Test that the new session ID is correctly returned to the caller on
18 dm_create_session when the oldsid parameter is not DM_NO_SESSION.
20 Test to make sure that DM_NO_TOKEN does not work if the session ID
23 Both are needed so that session assumption works correctly. The
24 test creates a session, queries the session, assumes the session,
25 then attempts to check the event list of the old session ID while
28 The only parameter is the pathname of a DMAPI filesystem. If it is
29 working correctly, you should get the error message:
33 Any message containing the word FAILURE indicates a problem.
37 dm_sessid_t sid = DM_NO_SESSION; /* session ID of original session */
38 dm_sessid_t newsid = DM_NO_SESSION; /* session ID after session resumed */
39 dm_eventset_t eventlist;
46 char buffer[DM_SESSION_INFO_LEN];
55 fprintf(stderr, "usage:\t%s filesystem\n", Progname);
59 /* Initialize the DMAPI interface and obtain a session ID, then verify
60 that the filesystem supports DMAPI.
63 if (setup_dmapi(&sid))
66 if (dm_path_to_handle(argv[1], &hanp, &hlen)) {
67 perror("FAILURE: can't get handle for filesystem");
71 /* Query the session just to make sure things are working okay. */
73 if (dm_query_session(sid, sizeof(buffer), buffer, &rlen)) {
74 errno_msg("FAILURE: can't query the original session ID %d",
78 fprintf(stdout, "Initial session ID: %d\n", sid);
79 fprintf(stdout, "Initial session message length: '%zd'\n", rlen);
81 fprintf(stdout, "Initial session message: '%s'\n", buffer);
84 /* Now try to assume the session. */
86 if (dm_create_session(sid, "this is a new message", &newsid)) {
87 fprintf(stderr, "FAILURE: can't assume session %d\n", sid);
91 /* Now query the new session. */
93 if (dm_query_session(newsid, sizeof(buffer), buffer, &rlen)) {
94 errno_msg("FAILURE: can't query the assumed session ID %d",
98 fprintf(stdout, "Assumed session ID: %d\n", newsid);
99 fprintf(stdout, "Assumed session message length: '%zd'\n", rlen);
101 fprintf(stdout, "Assumed session message: '%s'\n", buffer);
104 /* Get rid of the new session as we are done with it. */
106 if (dm_destroy_session(newsid)) {
107 fprintf(stderr, "FAILURE: Can't shut down assumed session %d\n",
112 /* Now verify that DM_NO_TOKEN will not work with the old session ID,
113 which is now invalid.
116 DMEV_ZERO(eventlist);
118 if (dm_get_eventlist(sid, hanp, hlen, DM_NO_TOKEN, DM_EVENT_MAX,
119 &eventlist, &nelem) == 0) {
120 fprintf(stderr, "FAILURE: dm_get_eventlist() worked when it "
121 "should have failed!\n");
124 if (errno != ESRCH) {
126 if (errno != EINVAL) {
128 errno_msg("FAILURE: unexpected errno");
131 fprintf(stdout, "SUCCESS!\n");