1 /*
2 * Copyright (c) International Business Machines Corp., 2004
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
12 * the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 /*
20 * TEST CASE : mount.c
21 *
22 * VARIATIONS : 12
23 *
24 * API'S TESTED : dm_get_mountinfo
25 */
26 #include <string.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <errno.h>
30 #include <pthread.h>
31 #include <unistd.h>
32 #include <sys/stat.h>
33 #include <sys/mount.h>
34 #include <fcntl.h>
35 #include "dm_test.h"
36
37 #define MOUNTEVENT_LEN 100
38
39 pthread_t tid;
40 dm_sessid_t sid;
41 char dmMsgBuf[4096];
42 char *mountPt;
43 char *deviceNm;
44 char DummyFile[FILENAME_MAX];
45 char DummySubdir[FILENAME_MAX];
46 dm_mount_event_t *me_ptr;
47 dm_size_t me_len;
48
49 void *Thread(void *);
50
main(int argc,char ** argv)51 int main(int argc, char **argv)
52 {
53
54 char *szFuncName;
55 char *varstr;
56 int rc;
57 char *szSessionInfo = "dm_test session info";
58 dm_eventset_t events;
59
60 DMOPT_PARSE(argc, argv);
61 DMLOG_START();
62
63 DMEV_ZERO(events);
64 DMEV_SET(DM_EVENT_MOUNT, events);
65
66 /* CANNOT DO ANYTHING WITHOUT SUCCESSFUL INITIALIZATION!!! */
67 if ((rc = dm_init_service(&varstr)) != 0) {
68 DMLOG_PRINT(DMLVL_ERR,
69 "dm_init_service failed! (rc = %d, errno = %d)\n",
70 rc, errno);
71 DM_EXIT();
72 } else if ((rc = dm_create_session(DM_NO_SESSION, szSessionInfo, &sid))
73 == -1) {
74 DMLOG_PRINT(DMLVL_ERR,
75 "dm_create_session failed! (rc = %d, errno = %d)\n",
76 rc, errno);
77 DM_EXIT();
78 } else
79 if ((rc =
80 dm_set_disp(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, DM_NO_TOKEN,
81 &events, DM_EVENT_MAX)) == -1) {
82 DMLOG_PRINT(DMLVL_ERR,
83 "dm_set_disp failed! (rc = %d, errno = %d)\n", rc,
84 errno);
85 dm_destroy_session(sid);
86 DM_EXIT();
87 } else if ((rc = pthread_create(&tid, NULL, Thread, NULL)) != 0) {
88 DMLOG_PRINT(DMLVL_ERR,
89 "pthread_create failed! (rc = %d, errno = %d)\n",
90 rc, errno);
91 dm_destroy_session(sid);
92 DM_EXIT();
93 } else if ((rc = dmimpl_mount(&mountPt, &deviceNm)) == -1) {
94 DMLOG_PRINT(DMLVL_ERR,
95 "dmimpl_mount failed! (rc = %d, errno = %d)\n", rc,
96 errno);
97 dm_destroy_session(sid);
98 DM_EXIT();
99 } else {
100 sprintf(DummyFile, "%s/%s", mountPt, DUMMY_FILE);
101 sprintf(DummySubdir, "%s/%s", mountPt, DUMMY_SUBDIR);
102
103 remove(DummyFile);
104 rmdir(DummySubdir);
105 }
106
107 DMLOG_PRINT(DMLVL_DEBUG, "Starting DMAPI mount tests\n");
108
109 szFuncName = "dm_set_dmattr";
110
111 /*
112 * TEST : dm_get_mountinfo - invalid sid
113 * EXPECTED: rc = -1, errno = EINVAL
114 */
115 if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 1)) {
116 int fd;
117 void *hanp;
118 size_t hlen;
119 char buf[MOUNTEVENT_LEN];
120 size_t rlen;
121
122 /* Variation set up */
123 if ((fd =
124 open(DummyFile, O_RDWR | O_CREAT,
125 DUMMY_FILE_RW_MODE)) == -1) {
126 /* No clean up */
127 } else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen))
128 == -1) {
129 close(fd);
130 remove(DummyFile);
131 }
132 if (fd == -1 || rc == -1) {
133 DMLOG_PRINT(DMLVL_DEBUG,
134 "Unable to set up variation! (errno = %d)\n",
135 errno);
136 DMVAR_SKIP();
137 } else {
138 /* Variation */
139 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid sid)\n",
140 szFuncName);
141 rc = dm_get_mountinfo(INVALID_ADDR, hanp, hlen,
142 DM_NO_TOKEN, sizeof(buf), buf,
143 &rlen);
144 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
145
146 /* Variation clean up */
147 rc = close(fd);
148 rc |= remove(DummyFile);
149 if (rc == -1) {
150 DMLOG_PRINT(DMLVL_DEBUG,
151 "Unable to clean up variation! (errno = %d)\n",
152 errno);
153 }
154 dm_handle_free(hanp, hlen);
155 }
156 }
157
158 /*
159 * TEST : dm_get_mountinfo - invalid hanp
160 * EXPECTED: rc = -1, errno = EFAULT
161 */
162 if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 2)) {
163 int fd;
164 void *hanp;
165 size_t hlen;
166 char buf[MOUNTEVENT_LEN];
167 size_t rlen;
168
169 /* Variation set up */
170 if ((fd =
171 open(DummyFile, O_RDWR | O_CREAT,
172 DUMMY_FILE_RW_MODE)) == -1) {
173 /* No clean up */
174 } else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen))
175 == -1) {
176 close(fd);
177 remove(DummyFile);
178 }
179 if (fd == -1 || rc == -1) {
180 DMLOG_PRINT(DMLVL_DEBUG,
181 "Unable to set up variation! (errno = %d)\n",
182 errno);
183 DMVAR_SKIP();
184 } else {
185 /* Variation */
186 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hanp)\n",
187 szFuncName);
188 rc = dm_get_mountinfo(sid, (void *)INVALID_ADDR, hlen,
189 DM_NO_TOKEN, sizeof(buf), buf,
190 &rlen);
191 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT);
192
193 /* Variation clean up */
194 rc = close(fd);
195 rc |= remove(DummyFile);
196 if (rc == -1) {
197 DMLOG_PRINT(DMLVL_DEBUG,
198 "Unable to clean up variation! (errno = %d)\n",
199 errno);
200 }
201 dm_handle_free(hanp, hlen);
202 }
203 }
204
205 /*
206 * TEST : dm_get_mountinfo - invalid hlen
207 * EXPECTED: rc = -1, errno = EBADF
208 */
209 if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 3)) {
210 int fd;
211 void *hanp;
212 size_t hlen;
213 char buf[MOUNTEVENT_LEN];
214 size_t rlen;
215
216 /* Variation set up */
217 if ((fd =
218 open(DummyFile, O_RDWR | O_CREAT,
219 DUMMY_FILE_RW_MODE)) == -1) {
220 /* No clean up */
221 } else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen))
222 == -1) {
223 close(fd);
224 remove(DummyFile);
225 }
226 if (fd == -1 || rc == -1) {
227 DMLOG_PRINT(DMLVL_DEBUG,
228 "Unable to set up variation! (errno = %d)\n",
229 errno);
230 DMVAR_SKIP();
231 } else {
232 /* Variation */
233 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid hlen)\n",
234 szFuncName);
235 rc = dm_get_mountinfo(sid, hanp, INVALID_ADDR,
236 DM_NO_TOKEN, sizeof(buf), buf,
237 &rlen);
238 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF);
239
240 /* Variation clean up */
241 rc = close(fd);
242 rc |= remove(DummyFile);
243 if (rc == -1) {
244 DMLOG_PRINT(DMLVL_DEBUG,
245 "Unable to clean up variation! (errno = %d)\n",
246 errno);
247 }
248 dm_handle_free(hanp, hlen);
249 }
250 }
251
252 /*
253 * TEST : dm_get_mountinfo - invalid token
254 * EXPECTED: rc = -1, errno = EINVAL
255 */
256 if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 4)) {
257 int fd;
258 void *hanp;
259 size_t hlen;
260 char buf[MOUNTEVENT_LEN];
261 size_t rlen;
262
263 /* Variation set up */
264 if ((fd =
265 open(DummyFile, O_RDWR | O_CREAT,
266 DUMMY_FILE_RW_MODE)) == -1) {
267 /* No clean up */
268 } else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen))
269 == -1) {
270 close(fd);
271 remove(DummyFile);
272 }
273 if (fd == -1 || rc == -1) {
274 DMLOG_PRINT(DMLVL_DEBUG,
275 "Unable to set up variation! (errno = %d)\n",
276 errno);
277 DMVAR_SKIP();
278 } else {
279 /* Variation */
280 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid token)\n",
281 szFuncName);
282 rc = dm_get_mountinfo(sid, hanp, hlen, INVALID_ADDR,
283 sizeof(buf), buf, &rlen);
284 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
285
286 /* Variation clean up */
287 rc = close(fd);
288 rc |= remove(DummyFile);
289 if (rc == -1) {
290 DMLOG_PRINT(DMLVL_DEBUG,
291 "Unable to clean up variation! (errno = %d)\n",
292 errno);
293 }
294 dm_handle_free(hanp, hlen);
295 }
296 }
297
298 /*
299 * TEST : dm_get_mountinfo - invalid buflen
300 * EXPECTED: rc = -1, errno = E2BIG
301 */
302 if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 5)) {
303 int fd;
304 void *hanp;
305 size_t hlen;
306 char buf[MOUNTEVENT_LEN];
307 size_t rlen;
308
309 /* Variation set up */
310 if ((fd =
311 open(DummyFile, O_RDWR | O_CREAT,
312 DUMMY_FILE_RW_MODE)) == -1) {
313 /* No clean up */
314 } else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen))
315 == -1) {
316 close(fd);
317 remove(DummyFile);
318 }
319 if (fd == -1 || rc == -1) {
320 DMLOG_PRINT(DMLVL_DEBUG,
321 "Unable to set up variation! (errno = %d)\n",
322 errno);
323 DMVAR_SKIP();
324 } else {
325 /* Variation */
326 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid buflen)\n",
327 szFuncName);
328 rc = dm_get_mountinfo(sid, hanp, hlen, DM_NO_TOKEN, 0,
329 buf, &rlen);
330 if (rc == -1) {
331 if (errno == E2BIG) {
332 DMLOG_PRINT(DMLVL_DEBUG, "rlen = %d\n",
333 rlen);
334 if (rlen == me_len) {
335 DMLOG_PRINT(DMLVL_DEBUG,
336 "%s passed with expected rc = %d and expected errno = %d\n",
337 szFuncName, -1,
338 E2BIG);
339 DMVAR_PASS();
340 } else {
341 DMLOG_PRINT(DMLVL_ERR,
342 "%s failed with expected rc = %d and expected errno = %d but unexpected rlen (%d vs %d)\n",
343 szFuncName, -1,
344 E2BIG, rlen,
345 me_len);
346 DMVAR_FAIL();
347 }
348 } else {
349 DMLOG_PRINT(DMLVL_ERR,
350 "%s failed with expected rc = %d but unexpected errno = %d\n",
351 szFuncName, -1, errno);
352 DMVAR_FAIL();
353 }
354 } else {
355 DMLOG_PRINT(DMLVL_ERR,
356 "%s failed with unexpected rc = %d\n",
357 szFuncName, rc);
358 DMVAR_FAIL();
359 }
360
361 /* Variation clean up */
362 rc = close(fd);
363 rc |= remove(DummyFile);
364 if (rc == -1) {
365 DMLOG_PRINT(DMLVL_DEBUG,
366 "Unable to clean up variation! (errno = %d)\n",
367 errno);
368 }
369 dm_handle_free(hanp, hlen);
370 }
371 }
372
373 /*
374 * TEST : dm_get_mountinfo - invalid bufp
375 * EXPECTED: rc = -1, errno = EFAULT
376 */
377 if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 6)) {
378 int fd;
379 void *hanp;
380 size_t hlen;
381 char buf[MOUNTEVENT_LEN];
382 size_t rlen;
383
384 /* Variation set up */
385 if ((fd =
386 open(DummyFile, O_RDWR | O_CREAT,
387 DUMMY_FILE_RW_MODE)) == -1) {
388 /* No clean up */
389 } else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen))
390 == -1) {
391 close(fd);
392 remove(DummyFile);
393 }
394 if (fd == -1 || rc == -1) {
395 DMLOG_PRINT(DMLVL_DEBUG,
396 "Unable to set up variation! (errno = %d)\n",
397 errno);
398 DMVAR_SKIP();
399 } else {
400 /* Variation */
401 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid bufp)\n",
402 szFuncName);
403 rc = dm_get_mountinfo(sid, hanp, hlen, DM_NO_TOKEN,
404 sizeof(buf), (void *)INVALID_ADDR,
405 &rlen);
406 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT);
407
408 /* Variation clean up */
409 rc = close(fd);
410 rc |= remove(DummyFile);
411 if (rc == -1) {
412 DMLOG_PRINT(DMLVL_DEBUG,
413 "Unable to clean up variation! (errno = %d)\n",
414 errno);
415 }
416 dm_handle_free(hanp, hlen);
417 }
418 }
419
420 /*
421 * TEST : dm_get_mountinfo - invalid rlenp
422 * EXPECTED: rc = -1, errno = EFAULT
423 */
424 if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 7)) {
425 int fd;
426 void *hanp;
427 size_t hlen;
428 char buf[MOUNTEVENT_LEN];
429
430 /* Variation set up */
431 if ((fd =
432 open(DummyFile, O_RDWR | O_CREAT,
433 DUMMY_FILE_RW_MODE)) == -1) {
434 /* No clean up */
435 } else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen))
436 == -1) {
437 close(fd);
438 remove(DummyFile);
439 }
440 if (fd == -1 || rc == -1) {
441 DMLOG_PRINT(DMLVL_DEBUG,
442 "Unable to set up variation! (errno = %d)\n",
443 errno);
444 DMVAR_SKIP();
445 } else {
446 /* Variation */
447 DMLOG_PRINT(DMLVL_DEBUG, "%s(invalid rlenp)\n",
448 szFuncName);
449 rc = dm_get_mountinfo(sid, hanp, hlen, DM_NO_TOKEN,
450 sizeof(buf), buf,
451 (size_t *) INVALID_ADDR);
452 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EFAULT);
453
454 /* Variation clean up */
455 rc = close(fd);
456 rc |= remove(DummyFile);
457 if (rc == -1) {
458 DMLOG_PRINT(DMLVL_DEBUG,
459 "Unable to clean up variation! (errno = %d)\n",
460 errno);
461 }
462 dm_handle_free(hanp, hlen);
463 }
464 }
465
466 /*
467 * TEST : dm_get_mountinfo - valid
468 * EXPECTED: rc = 0
469 */
470 if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 8)) {
471 int fd;
472 void *hanp;
473 size_t hlen;
474 char buf[MOUNTEVENT_LEN];
475 size_t rlen;
476
477 /* Variation set up */
478 if ((fd =
479 open(DummyFile, O_RDWR | O_CREAT,
480 DUMMY_FILE_RW_MODE)) == -1) {
481 /* No clean up */
482 } else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen))
483 == -1) {
484 close(fd);
485 remove(DummyFile);
486 }
487 if (fd == -1 || rc == -1) {
488 DMLOG_PRINT(DMLVL_DEBUG,
489 "Unable to set up variation! (errno = %d)\n",
490 errno);
491 DMVAR_SKIP();
492 } else {
493 /* Variation */
494 DMLOG_PRINT(DMLVL_DEBUG, "%s(valid)\n", szFuncName);
495 rc = dm_get_mountinfo(sid, hanp, hlen, DM_NO_TOKEN,
496 sizeof(buf), buf, &rlen);
497 if (rc == 0) {
498 DMLOG_PRINT(DMLVL_DEBUG, "rlen = %d\n", rlen);
499 if (rlen == me_len) {
500 if (memcmp(buf, me_ptr, rlen) == 0) {
501 DMLOG_PRINT(DMLVL_DEBUG,
502 "%s passed with expected rc = %d\n",
503 szFuncName, 0);
504 DMVAR_PASS();
505 } else {
506 DMLOG_PRINT(DMLVL_ERR,
507 "%s failed with expected rc = %d but mount info not same\n",
508 szFuncName, 0);
509 DMVAR_FAIL();
510 }
511 } else {
512 DMLOG_PRINT(DMLVL_ERR,
513 "%s failed with expected rc = %d but mount info len not same (%d vs %d)\n",
514 szFuncName, 0, rlen,
515 me_len);
516 DMVAR_FAIL();
517 }
518 } else {
519 DMLOG_PRINT(DMLVL_ERR,
520 "%s failed with unexpected rc = %d (errno = %d)\n",
521 szFuncName, rc, errno);
522 DMVAR_FAIL();
523 }
524
525 /* Variation clean up */
526 rc = close(fd);
527 rc |= remove(DummyFile);
528 if (rc == -1) {
529 DMLOG_PRINT(DMLVL_DEBUG,
530 "Unable to clean up variation! (errno = %d)\n",
531 errno);
532 }
533 }
534 }
535
536 /*
537 * TEST : dm_get_mountinfo - DM_NO_SESSION sid
538 * EXPECTED: rc = -1, errno = EINVAL
539 */
540 if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 9)) {
541 int fd;
542 void *hanp;
543 size_t hlen;
544 char buf[MOUNTEVENT_LEN];
545 size_t rlen;
546
547 /* Variation set up */
548 if ((fd =
549 open(DummyFile, O_RDWR | O_CREAT,
550 DUMMY_FILE_RW_MODE)) == -1) {
551 /* No clean up */
552 } else if ((rc = dm_path_to_fshandle(DummyFile, &hanp, &hlen))
553 == -1) {
554 close(fd);
555 remove(DummyFile);
556 }
557 if (fd == -1 || rc == -1) {
558 DMLOG_PRINT(DMLVL_DEBUG,
559 "Unable to set up variation! (errno = %d)\n",
560 errno);
561 DMVAR_SKIP();
562 } else {
563 /* Variation */
564 DMLOG_PRINT(DMLVL_DEBUG, "%s(DM_NO_SESSION sid)\n",
565 szFuncName);
566 rc = dm_get_mountinfo(DM_NO_SESSION, hanp, hlen,
567 DM_NO_TOKEN, sizeof(buf), buf,
568 &rlen);
569 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
570
571 /* Variation clean up */
572 rc = close(fd);
573 rc |= remove(DummyFile);
574 if (rc == -1) {
575 DMLOG_PRINT(DMLVL_DEBUG,
576 "Unable to clean up variation! (errno = %d)\n",
577 errno);
578 }
579 dm_handle_free(hanp, hlen);
580 }
581 }
582
583 /*
584 * TEST : dm_get_mountinfo - global handle
585 * EXPECTED: rc = -1, errno = EBADF
586 */
587 if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 10)) {
588 char buf[MOUNTEVENT_LEN];
589 size_t rlen;
590
591 /* Variation set up */
592
593 /* Variation */
594 DMLOG_PRINT(DMLVL_DEBUG, "%s(global handle)\n", szFuncName);
595 rc = dm_get_mountinfo(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN,
596 DM_NO_TOKEN, sizeof(buf), buf, &rlen);
597 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EBADF);
598
599 /* Variation clean up */
600 }
601
602 /*
603 * TEST : dm_get_mountinfo - file handle
604 * EXPECTED: rc = -1, errno = EINVAL
605 */
606 if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 11)) {
607 int fd;
608 void *hanp;
609 size_t hlen;
610 char buf[MOUNTEVENT_LEN];
611 size_t rlen;
612
613 /* Variation set up */
614 if ((fd =
615 open(DummyFile, O_RDWR | O_CREAT,
616 DUMMY_FILE_RW_MODE)) == -1) {
617 /* No clean up */
618 } else if ((rc = dm_path_to_handle(DummyFile, &hanp, &hlen)) ==
619 -1) {
620 close(fd);
621 remove(DummyFile);
622 }
623 if (fd == -1 || rc == -1) {
624 DMLOG_PRINT(DMLVL_DEBUG,
625 "Unable to set up variation! (errno = %d)\n",
626 errno);
627 DMVAR_SKIP();
628 } else {
629 /* Variation */
630 DMLOG_PRINT(DMLVL_DEBUG, "%s(file handle)\n",
631 szFuncName);
632 rc = dm_get_mountinfo(sid, hanp, hlen, DM_NO_TOKEN,
633 sizeof(buf), buf, &rlen);
634 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
635
636 /* Variation clean up */
637 rc = close(fd);
638 rc |= remove(DummyFile);
639 if (rc == -1) {
640 DMLOG_PRINT(DMLVL_DEBUG,
641 "Unable to clean up variation! (errno = %d)\n",
642 errno);
643 }
644 dm_handle_free(hanp, hlen);
645 }
646 }
647
648 /*
649 * TEST : dm_get_mountinfo - dir handle
650 * EXPECTED: rc = -1, errno = EINVAL
651 */
652 if (DMVAR_EXEC(GET_MOUNTINFO_BASE + 12)) {
653 void *hanp;
654 size_t hlen;
655 char buf[MOUNTEVENT_LEN];
656 size_t rlen;
657
658 /* Variation set up */
659 if ((rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE)) == -1) {
660 /* No clean up */
661 } else if ((rc = dm_path_to_handle(DummySubdir, &hanp, &hlen))
662 == -1) {
663 rmdir(DummySubdir);
664 }
665 if (rc == -1) {
666 DMLOG_PRINT(DMLVL_DEBUG,
667 "Unable to set up variation! (errno = %d)\n",
668 errno);
669 DMVAR_SKIP();
670 } else {
671 /* Variation */
672 DMLOG_PRINT(DMLVL_DEBUG, "%s(dir handle)\n",
673 szFuncName);
674 rc = dm_get_mountinfo(sid, hanp, hlen, DM_NO_TOKEN,
675 sizeof(buf), buf, &rlen);
676 DMVAR_ENDFAILEXP(szFuncName, -1, rc, EINVAL);
677
678 /* Variation clean up */
679 rc = rmdir(DummySubdir);
680 if (rc == -1) {
681 DMLOG_PRINT(DMLVL_DEBUG,
682 "Unable to clean up variation! (errno = %d)\n",
683 errno);
684 }
685 dm_handle_free(hanp, hlen);
686 }
687 }
688
689 if (me_ptr != NULL) {
690 free(me_ptr);
691 }
692
693 rc = umount(mountPt);
694 if (rc == -1) {
695 DMLOG_PRINT(DMLVL_ERR, "umount failed! (rc = %d, errno = %d)\n",
696 rc, errno);
697 }
698
699 pthread_join(tid, NULL);
700
701 rc = dm_destroy_session(sid);
702 if (rc == -1) {
703 DMLOG_PRINT(DMLVL_ERR,
704 "dm_destroy_session failed! (rc = %d, errno = %d)\n",
705 rc, errno);
706 }
707
708 DMLOG_STOP();
709
710 tst_exit();
711 }
712
Thread(void * parm)713 void *Thread(void *parm)
714 {
715 int rc;
716 size_t dmMsgBufLen;
717 dm_eventmsg_t *dmMsg;
718 int bMounted = DM_FALSE;
719 dm_eventtype_t type;
720 dm_token_t token;
721 dm_eventset_t events;
722 dm_response_t response;
723
724 do {
725 /* Loop until message received (wait could be interrupted) */
726 do {
727 DMLOG_PRINT(DMLVL_DEBUG, "Waiting for event...\n");
728 dmMsgBufLen = 0;
729
730 rc = dm_get_events(sid, 1, DM_EV_WAIT, sizeof(dmMsgBuf),
731 dmMsgBuf, &dmMsgBufLen);
732 DMLOG_PRINT(DMLVL_DEBUG,
733 "... dm_get_events returned %d (errno %d)\n",
734 rc, errno);
735 } while ((rc == -1) && (errno == EINTR) && (dmMsgBufLen == 0));
736
737 if (rc) {
738 DMLOG_PRINT(DMLVL_ERR,
739 "dm_get_events failed with rc = %d, errno = %d\n",
740 rc, errno);
741 dm_destroy_session(sid);
742 DM_EXIT();
743 } else {
744 dmMsg = (dm_eventmsg_t *) dmMsgBuf;
745 token = dmMsg->ev_token;
746 type = dmMsg->ev_type;
747
748 DMLOG_PRINT(DMLVL_DEBUG, "Received message %d\n", type);
749 }
750
751 if (type == DM_EVENT_MOUNT) {
752 /* SPECIAL CASE: need to set disposition, events and response */
753 dm_mount_event_t *me =
754 DM_GET_VALUE(dmMsg, ev_data, dm_mount_event_t *);
755 void *hanp = DM_GET_VALUE(me, me_handle1, void *);
756 size_t hlen = DM_GET_LEN(me, me_handle1);
757
758 DMLOG_PRINT(DMLVL_DEBUG, "Message is DM_EVENT_MOUNT\n");
759 DMLOG_PRINT(DMLVL_DEBUG, " Mode: %x\n", me->me_mode);
760 DMLOG_PRINT(DMLVL_DEBUG, " File system handle: %p\n",
761 hanp);
762 DMLOG_PRINT(DMLVL_DEBUG,
763 " File system handle length: %d\n", hlen);
764 DMLOG_PRINT(DMLVL_DEBUG, " Mountpoint handle: %p\n",
765 DM_GET_VALUE(me, me_handle2, void *));
766 DMLOG_PRINT(DMLVL_DEBUG,
767 " Mountpoint handle length: %d\n",
768 DM_GET_LEN(me, me_handle2));
769 DMLOG_PRINT(DMLVL_DEBUG, " Mountpoint path: %s\n",
770 DM_GET_VALUE(me, me_name1, char *));
771 DMLOG_PRINT(DMLVL_DEBUG, " Media designator: %s\n",
772 DM_GET_VALUE(me, me_name2, char *));
773 DMLOG_PRINT(DMLVL_DEBUG, " Root handle: %p\n",
774 DM_GET_VALUE(me, me_roothandle, void *));
775 DMLOG_PRINT(DMLVL_DEBUG, " Root handle length: %d\n",
776 DM_GET_LEN(me, me_roothandle));
777
778 bMounted = dm_handle_is_valid(hanp, hlen);
779
780 rc = dm_request_right(sid, hanp, hlen, token,
781 DM_RR_WAIT, DM_RIGHT_EXCL);
782 if (rc == -1) {
783 DMLOG_PRINT(DMLVL_ERR,
784 "dm_request_right failed! (rc = %d, errno = %d)\n",
785 rc, errno);
786 dm_destroy_session(sid);
787 DM_EXIT();
788 }
789
790 DMEV_ZERO(events);
791 DMEV_SET(DM_EVENT_PREUNMOUNT, events);
792 DMEV_SET(DM_EVENT_UNMOUNT, events);
793 rc = dm_set_disp(sid, hanp, hlen, token, &events,
794 DM_EVENT_MAX);
795 if (rc == -1) {
796 DMLOG_PRINT(DMLVL_ERR,
797 "dm_set_disp failed! (rc = %d, errno = %d)\n",
798 rc, errno);
799 dm_destroy_session(sid);
800 DM_EXIT();
801 }
802
803 rc = dm_set_eventlist(sid, hanp, hlen, token, &events,
804 DM_EVENT_MAX);
805 if (rc == -1) {
806 DMLOG_PRINT(DMLVL_ERR,
807 "dm_set_eventlist failed! (rc = %d, errno = %d)\n",
808 rc, errno);
809 dm_destroy_session(sid);
810 DM_EXIT();
811 }
812
813 rc = dm_release_right(sid, hanp, hlen, token);
814 if (rc == -1) {
815 DMLOG_PRINT(DMLVL_ERR,
816 "dm_request_right failed! (rc = %d, errno = %d)\n",
817 rc, errno);
818 dm_destroy_session(sid);
819 DM_EXIT();
820 }
821
822 me_len =
823 me->me_roothandle.vd_offset +
824 me->me_roothandle.vd_length;
825 if ((me_ptr = malloc(me_len)) == NULL) {
826 DMLOG_PRINT(DMLVL_ERR,
827 "malloc failed! (errno = %d)\n",
828 errno);
829 dm_destroy_session(sid);
830 DM_EXIT();
831 }
832 memcpy(me_ptr, me, me_len);
833
834 response = DM_RESP_CONTINUE;
835 } else if (type == DM_EVENT_UNMOUNT) {
836 dm_namesp_event_t *nse =
837 DM_GET_VALUE(dmMsg, ev_data, dm_namesp_event_t *);
838 if (nse->ne_retcode == 0) {
839 bMounted = DM_FALSE;
840 }
841
842 response = DM_RESP_CONTINUE;
843 } else {
844 switch (type) {
845 case DM_EVENT_PREUNMOUNT:
846 response = DM_RESP_CONTINUE;
847 break;
848
849 default:
850 {
851 DMLOG_PRINT(DMLVL_ERR,
852 "Message is unexpected!\n");
853 response = DM_RESP_ABORT;
854 break;
855 }
856 }
857 }
858
859 if (response != DM_RESP_INVALID) {
860 DMLOG_PRINT(DMLVL_DEBUG,
861 "Responding to message %d with %d\n", type,
862 response);
863 rc = dm_respond_event(sid, token, response,
864 response ==
865 DM_RESP_ABORT ? ABORT_ERRNO : 0,
866 0, NULL);
867 }
868 } while (bMounted);
869
870 pthread_exit(0);
871 }
872