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	: event_an.c
21  *
22  * VARIATIONS	: 34
23  *
24  * EVENTS TESTED: DM_EVENT_POSTCREATE
25  * 		  DM_EVENT_POSTREMOVE
26  * 		  DM_EVENT_POSTRENAME
27  * 		  DM_EVENT_POSTSYMLINK
28  * 		  DM_EVENT_POSTLINK
29  */
30 #include <string.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <errno.h>
34 #include <pthread.h>
35 #include <unistd.h>
36 #include <sys/stat.h>
37 #include <sys/mount.h>
38 #include <fcntl.h>
39 #include "dm_test.h"
40 
41 pthread_t tid;
42 dm_sessid_t sid;
43 char dmMsgBuf[4096];
44 char command[4096];
45 char *mountPt;
46 char *deviceNm;
47 char DummyFile[FILENAME_MAX];
48 char DummyFile2[FILENAME_MAX];
49 char DummySubdir[FILENAME_MAX];
50 char DummySubdir2[FILENAME_MAX];
51 char DummyLink[FILENAME_MAX];
52 char DummySubdir2File[FILENAME_MAX];
53 char DummySubdir2Subdir[FILENAME_MAX];
54 
55 /* Variables for thread communications */
56 dm_eventtype_t eventExpected;
57 dm_eventtype_t eventReceived;
58 dm_response_t eventResponse;
59 void *hanp1, *hanp2, *ahanp1, *ahanp2;
60 size_t hlen1, hlen2, ahlen1, ahlen2;
61 char name1[FILENAME_MAX], name2[FILENAME_MAX], aname1[FILENAME_MAX],
62     aname2[FILENAME_MAX];
63 dm_mode_t mode, amode;
64 int aretcode;
65 
66 void *Thread(void *);
67 
main(int argc,char ** argv)68 int main(int argc, char **argv)
69 {
70 
71 	char *varstr;
72 	int rc;
73 	int varStatus;
74 	char *szSessionInfo = "dm_test session info";
75 	dm_eventset_t events;
76 	void *fshanp, *dhanp;
77 	size_t fshlen, dhlen;
78 
79 	DMOPT_PARSE(argc, argv);
80 	DMLOG_START();
81 
82 	DMEV_ZERO(events);
83 	DMEV_SET(DM_EVENT_MOUNT, events);
84 
85 	/* CANNOT DO ANYTHING WITHOUT SUCCESSFUL INITIALIZATION!!! */
86 	if ((rc = dm_init_service(&varstr)) != 0) {
87 		DMLOG_PRINT(DMLVL_ERR,
88 			    "dm_init_service failed! (rc = %d, errno = %d)\n",
89 			    rc, errno);
90 		DM_EXIT();
91 	} else if ((rc = dm_create_session(DM_NO_SESSION, szSessionInfo, &sid))
92 		   == -1) {
93 		DMLOG_PRINT(DMLVL_ERR,
94 			    "dm_create_session failed! (rc = %d, errno = %d)\n",
95 			    rc, errno);
96 		DM_EXIT();
97 	} else
98 	    if ((rc =
99 		 dm_set_disp(sid, DM_GLOBAL_HANP, DM_GLOBAL_HLEN, DM_NO_TOKEN,
100 			     &events, DM_EVENT_MAX)) == -1) {
101 		DMLOG_PRINT(DMLVL_ERR,
102 			    "dm_set_disp failed! (rc = %d, errno = %d)\n", rc,
103 			    errno);
104 		dm_destroy_session(sid);
105 		DM_EXIT();
106 	} else if ((rc = pthread_create(&tid, NULL, Thread, NULL)) != 0) {
107 		DMLOG_PRINT(DMLVL_ERR,
108 			    "pthread_create failed! (rc = %d, errno = %d)\n",
109 			    rc, errno);
110 		dm_destroy_session(sid);
111 		DM_EXIT();
112 	} else if ((rc = dmimpl_mount(&mountPt, &deviceNm)) == -1) {
113 		DMLOG_PRINT(DMLVL_ERR,
114 			    "dmimpl_mount failed! (rc = %d, errno = %d)\n", rc,
115 			    errno);
116 		dm_destroy_session(sid);
117 		DM_EXIT();
118 	} else {
119 		sprintf(DummyFile, "%s/%s", mountPt, DUMMY_FILE);
120 		sprintf(DummyFile2, "%s/%s", mountPt, DUMMY_FILE2);
121 		sprintf(DummySubdir, "%s/%s", mountPt, DUMMY_SUBDIR);
122 		sprintf(DummySubdir2, "%s/%s", mountPt, DUMMY_SUBDIR2);
123 		sprintf(DummyLink, "%s/%s", mountPt, DUMMY_LINK);
124 		sprintf(DummySubdir2File, "%s/%s", mountPt, DUMMY_SUBDIR2_FILE);
125 		sprintf(DummySubdir2Subdir, "%s/%s", mountPt,
126 			DUMMY_SUBDIR2_SUBDIR);
127 
128 		remove(DummySubdir2File);
129 		rmdir(DummySubdir2Subdir);
130 		remove(DummyFile);
131 		remove(DummyFile2);
132 		unlink(DummyLink);
133 		rmdir(DummySubdir);
134 		rmdir(DummySubdir2);
135 	}
136 
137 	DMLOG_PRINT(DMLVL_DEBUG,
138 		    "Starting DMAPI asynchronous namespace event tests\n");
139 
140 	/*
141 	 *  First batch of tests will be with events enabled on file system,
142 	 *  so set up events on fs accordingly
143 	 */
144 	rc = dm_path_to_fshandle(mountPt, &fshanp, &fshlen);
145 	if (rc == -1) {
146 		DMLOG_PRINT(DMLVL_ERR,
147 			    "dm_path_to_handle(fs) failed! (rc = %d, errno = %d)\n",
148 			    rc, errno);
149 		dm_destroy_session(sid);
150 		DM_EXIT();
151 	}
152 
153 	DMEV_ZERO(events);
154 	DMEV_SET(DM_EVENT_PREUNMOUNT, events);
155 	DMEV_SET(DM_EVENT_UNMOUNT, events);
156 	DMEV_SET(DM_EVENT_CREATE, events);
157 	DMEV_SET(DM_EVENT_POSTCREATE, events);
158 	DMEV_SET(DM_EVENT_REMOVE, events);
159 	DMEV_SET(DM_EVENT_POSTREMOVE, events);
160 	DMEV_SET(DM_EVENT_RENAME, events);
161 	DMEV_SET(DM_EVENT_POSTRENAME, events);
162 	DMEV_SET(DM_EVENT_SYMLINK, events);
163 	DMEV_SET(DM_EVENT_POSTSYMLINK, events);
164 	DMEV_SET(DM_EVENT_LINK, events);
165 	DMEV_SET(DM_EVENT_POSTLINK, events);
166 	rc = dm_set_eventlist(sid, fshanp, fshlen, DM_NO_TOKEN, &events,
167 			      DM_EVENT_MAX);
168 	if (rc == -1) {
169 		DMLOG_PRINT(DMLVL_ERR,
170 			    "dm_set_eventlist(fs) failed! (rc = %d, errno = %d)\n",
171 			    rc, errno);
172 		dm_destroy_session(sid);
173 		DM_EXIT();
174 	}
175 
176 	/*
177 	 * TEST    : mkdir - enabled on fs
178 	 * EXPECTED: DM_EVENT_POSTCREATE
179 	 */
180 	if (DMVAR_EXEC(DIR_ASYNC_NAMESP_EVENT_BASE + 1)) {
181 		dm_ino_t ino1, ino2;
182 
183 		/* Variation set up */
184 		eventExpected = DM_EVENT_POSTCREATE;
185 		eventReceived = DM_EVENT_INVALID;
186 		eventResponse = DM_RESP_CONTINUE;
187 
188 		/* Variation */
189 		EVENT_DELIVERY_DELAY;
190 		DMLOG_PRINT(DMLVL_DEBUG, "mkdir(%s)\n", DummySubdir);
191 		rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE);
192 		DMLOG_PRINT(DMLVL_DEBUG, "mkdir(%s) returned %d\n", DummySubdir,
193 			    rc);
194 		EVENT_DELIVERY_DELAY;
195 		if ((varStatus =
196 		     DMVAR_CHKPASSEXP(0, rc, eventExpected,
197 				      eventReceived)) == DMSTAT_PASS) {
198 			struct stat statfs;
199 
200 			rc = dm_handle_to_ino(ahanp1, ahlen1, &ino1);
201 			rc |= dm_handle_to_ino(ahanp2, ahlen2, &ino2);
202 			rc |= stat(DummySubdir, &statfs);
203 			if (rc == -1) {
204 				DMLOG_PRINT(DMLVL_ERR,
205 					    "Unable to obtain inode!\n");
206 				varStatus = DMSTAT_FAIL;
207 			} else if (ino1 != ROOT_INODE) {
208 				DMLOG_PRINT(DMLVL_ERR,
209 					    "Parent handle NOT root! (%lld vs %d)\n",
210 					    ino1, ROOT_INODE);
211 				varStatus = DMSTAT_FAIL;
212 			} else if (ino2 != statfs.st_ino) {
213 				DMLOG_PRINT(DMLVL_ERR,
214 					    "Entry handle NOT correct! (%lld vs %d)\n",
215 					    ino2, statfs.st_ino);
216 				varStatus = DMSTAT_FAIL;
217 			} else if (strcmp(aname1, DUMMY_SUBDIR) != 0) {
218 				DMLOG_PRINT(DMLVL_ERR,
219 					    "Entry name NOT correct! (%s vs %s)\n",
220 					    aname1, DUMMY_SUBDIR);
221 				varStatus = DMSTAT_FAIL;
222 			} else if (dm_handle_cmp(hanp1, hlen1, ahanp1, ahlen1)
223 				   != 0) {
224 				DMLOG_PRINT(DMLVL_ERR,
225 					    "Parent handles NOT same!\n");
226 				varStatus = DMSTAT_FAIL;
227 			} else if (strcmp(name1, aname1) != 0) {
228 				DMLOG_PRINT(DMLVL_ERR,
229 					    "Entry names NOT same! (%s vs %s)\n",
230 					    name1, aname1);
231 				varStatus = DMSTAT_FAIL;
232 			} else if (amode != statfs.st_mode) {
233 				DMLOG_PRINT(DMLVL_ERR,
234 					    "Modes NOT same! (%d vs %d)\n",
235 					    amode, statfs.st_mode);
236 				varStatus = DMSTAT_FAIL;
237 			} else if (aretcode != 0) {
238 				DMLOG_PRINT(DMLVL_ERR,
239 					    "Return codes NOT same! (%d vs %d)\n",
240 					    mode, amode);
241 				varStatus = DMSTAT_FAIL;
242 			}
243 		}
244 		DMVAR_END(varStatus);
245 
246 		/* Variation clean up */
247 		EVENT_DELIVERY_DELAY;
248 		rc = rmdir(DummySubdir);
249 		EVENT_DELIVERY_DELAY;
250 		if (rc == -1) {
251 			DMLOG_PRINT(DMLVL_DEBUG,
252 				    "Unable to clean up variation! (errno = %d)\n",
253 				    errno);
254 		}
255 	}
256 
257 	/*
258 	 * TEST    : rmdir - enabled on fs
259 	 * EXPECTED: DM_EVENT_POSTREMOVE
260 	 */
261 	if (DMVAR_EXEC(DIR_ASYNC_NAMESP_EVENT_BASE + 2)) {
262 		dm_ino_t ino;
263 		struct stat statfs;
264 
265 		/* Variation set up */
266 		eventExpected = DM_EVENT_POSTREMOVE;
267 		eventReceived = DM_EVENT_INVALID;
268 		eventResponse = DM_RESP_CONTINUE;
269 		EVENT_DELIVERY_DELAY;
270 		if ((rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE)) == -1) {
271 			/* No clean up */
272 		} else if ((rc = stat(DummySubdir, &statfs)) == -1) {
273 			rmdir(DummySubdir);
274 		}
275 		if (rc == -1) {
276 			DMLOG_PRINT(DMLVL_DEBUG,
277 				    "Unable to set up variation! (errno = %d)\n",
278 				    errno);
279 			DMVAR_SKIP();
280 		} else {
281 			/* Variation */
282 			EVENT_DELIVERY_DELAY;
283 			DMLOG_PRINT(DMLVL_DEBUG, "rmdir(%s)\n", DummySubdir);
284 			rc = rmdir(DummySubdir);
285 			DMLOG_PRINT(DMLVL_DEBUG, "rmdir(%s) returned %d\n",
286 				    DummySubdir, rc);
287 			EVENT_DELIVERY_DELAY;
288 			if ((varStatus =
289 			     DMVAR_CHKPASSEXP(0, rc, eventExpected,
290 					      eventReceived)) == DMSTAT_PASS) {
291 				rc = dm_handle_to_ino(ahanp1, ahlen1, &ino);
292 				if (rc == -1) {
293 					DMLOG_PRINT(DMLVL_ERR,
294 						    "Unable to obtain inode!\n");
295 					varStatus = DMSTAT_FAIL;
296 				} else if (ino != ROOT_INODE) {
297 					DMLOG_PRINT(DMLVL_ERR,
298 						    "Parent handle NOT root! (%lld vs %d)\n",
299 						    ino, ROOT_INODE);
300 					varStatus = DMSTAT_FAIL;
301 				} else if (strcmp(aname1, DUMMY_SUBDIR) != 0) {
302 					DMLOG_PRINT(DMLVL_ERR,
303 						    "Entry name NOT correct! (%s vs %s)\n",
304 						    aname1, DUMMY_SUBDIR);
305 					varStatus = DMSTAT_FAIL;
306 				} else
307 				    if (dm_handle_cmp
308 					(hanp1, hlen1, ahanp1, ahlen1) != 0) {
309 					DMLOG_PRINT(DMLVL_ERR,
310 						    "Parent handles NOT same!\n");
311 					varStatus = DMSTAT_FAIL;
312 				} else if (strcmp(name1, aname1) != 0) {
313 					DMLOG_PRINT(DMLVL_ERR,
314 						    "Entry names NOT same! (%s vs %s)\n",
315 						    name1, aname1);
316 					varStatus = DMSTAT_FAIL;
317 				} else if (amode != statfs.st_mode) {
318 					DMLOG_PRINT(DMLVL_ERR,
319 						    "Modes NOT same! (%d vs %d)\n",
320 						    amode, statfs.st_mode);
321 					varStatus = DMSTAT_FAIL;
322 				} else if (aretcode != 0) {
323 					DMLOG_PRINT(DMLVL_ERR,
324 						    "Return codes NOT same! (%d vs %d)\n",
325 						    mode, amode);
326 					varStatus = DMSTAT_FAIL;
327 				}
328 			}
329 			DMVAR_END(varStatus);
330 
331 			/* Variation clean up */
332 		}
333 	}
334 
335 	/*
336 	 * TEST    : mv - enabled on fs
337 	 * EXPECTED: DM_EVENT_POSTRENAME
338 	 */
339 	if (DMVAR_EXEC(DIR_ASYNC_NAMESP_EVENT_BASE + 3)) {
340 		dm_ino_t ino1, ino2;
341 
342 		/* Variation set up */
343 		eventExpected = DM_EVENT_POSTRENAME;
344 		eventReceived = DM_EVENT_INVALID;
345 		eventResponse = DM_RESP_CONTINUE;
346 		sprintf(command, "mv %s %s", DummySubdir, DummySubdir2);
347 		EVENT_DELIVERY_DELAY;
348 		rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE);
349 		if (rc == -1) {
350 			DMLOG_PRINT(DMLVL_DEBUG,
351 				    "Unable to set up variation! (errno = %d)\n",
352 				    errno);
353 			DMVAR_SKIP();
354 		} else {
355 			/* Variation */
356 			EVENT_DELIVERY_DELAY;
357 			DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s)\n",
358 				    DummySubdir, DummySubdir2);
359 			rc = system(command);
360 			DMLOG_PRINT(DMLVL_DEBUG,
361 				    "system(mv %s %s) returned %d\n",
362 				    DummySubdir, DummySubdir2, rc);
363 			EVENT_DELIVERY_DELAY;
364 			if ((varStatus =
365 			     DMVAR_CHKPASSEXP(0, rc, eventExpected,
366 					      eventReceived)) == DMSTAT_PASS) {
367 				rc = dm_handle_to_ino(ahanp1, ahlen1, &ino1);
368 				rc |= dm_handle_to_ino(ahanp2, ahlen2, &ino2);
369 				if (rc == -1) {
370 					DMLOG_PRINT(DMLVL_ERR,
371 						    "Unable to obtain inode!\n");
372 					varStatus = DMSTAT_FAIL;
373 				} else if (ino1 != ROOT_INODE) {
374 					DMLOG_PRINT(DMLVL_ERR,
375 						    "Old parent handle NOT root! (%lld vs %d)\n",
376 						    ino1, ROOT_INODE);
377 					varStatus = DMSTAT_FAIL;
378 				} else if (ino2 != ROOT_INODE) {
379 					DMLOG_PRINT(DMLVL_ERR,
380 						    "New parent handle NOT root! (%lld vs %d)\n",
381 						    ino2, ROOT_INODE);
382 					varStatus = DMSTAT_FAIL;
383 				} else
384 				    if (dm_handle_cmp
385 					(ahanp1, ahlen1, ahanp2, ahlen2) != 0) {
386 					DMLOG_PRINT(DMLVL_ERR,
387 						    "Old parent handle NOT equal to new parent handle!\n");
388 					varStatus = DMSTAT_FAIL;
389 				} else
390 				    if (dm_handle_cmp
391 					(hanp1, hlen1, ahanp1, ahlen1) != 0) {
392 					DMLOG_PRINT(DMLVL_ERR,
393 						    "Old parent handles NOT same!\n");
394 					varStatus = DMSTAT_FAIL;
395 				} else
396 				    if (dm_handle_cmp
397 					(hanp2, hlen2, ahanp2, ahlen2) != 0) {
398 					DMLOG_PRINT(DMLVL_ERR,
399 						    "New parent handles NOT same!\n");
400 					varStatus = DMSTAT_FAIL;
401 				} else if (strcmp(aname1, DUMMY_SUBDIR) != 0) {
402 					DMLOG_PRINT(DMLVL_ERR,
403 						    "Old entry name NOT correct! (%s vs %s)\n",
404 						    name1, DUMMY_SUBDIR);
405 					varStatus = DMSTAT_FAIL;
406 				} else if (strcmp(aname2, DUMMY_SUBDIR2) != 0) {
407 					DMLOG_PRINT(DMLVL_ERR,
408 						    "New entry name NOT correct! (%s vs %s)\n",
409 						    name2, DUMMY_SUBDIR2);
410 					varStatus = DMSTAT_FAIL;
411 				} else if (strcmp(name1, aname1) != 0) {
412 					DMLOG_PRINT(DMLVL_ERR,
413 						    "Old entry name NOT same! (%s vs %s)\n",
414 						    name1, aname1);
415 					varStatus = DMSTAT_FAIL;
416 				} else if (strcmp(name2, aname2) != 0) {
417 					DMLOG_PRINT(DMLVL_ERR,
418 						    "New entry name NOT same! (%s vs %s)\n",
419 						    name2, aname2);
420 					varStatus = DMSTAT_FAIL;
421 				} else if (aretcode != 0) {
422 					DMLOG_PRINT(DMLVL_ERR,
423 						    "Return codes NOT same! (%d vs %d)\n",
424 						    mode, amode);
425 					varStatus = DMSTAT_FAIL;
426 				}
427 			}
428 			DMVAR_END(varStatus);
429 
430 			/* Variation clean up */
431 			EVENT_DELIVERY_DELAY;
432 			rc = rmdir(DummySubdir2);
433 			EVENT_DELIVERY_DELAY;
434 			if (rc == -1) {
435 				DMLOG_PRINT(DMLVL_DEBUG,
436 					    "Unable to clean up variation! (errno = %d)\n",
437 					    errno);
438 			}
439 		}
440 	}
441 
442 	/*
443 	 * TEST    : symlink - enabled on fs
444 	 * EXPECTED: DM_EVENT_POSTSYMLINK
445 	 */
446 	if (DMVAR_EXEC(DIR_ASYNC_NAMESP_EVENT_BASE + 4)) {
447 		dm_ino_t ino1, ino2;
448 
449 		/* Variation set up */
450 		eventExpected = DM_EVENT_POSTSYMLINK;
451 		eventReceived = DM_EVENT_INVALID;
452 		eventResponse = DM_RESP_CONTINUE;
453 		EVENT_DELIVERY_DELAY;
454 		rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE);
455 		if (rc == -1) {
456 			DMLOG_PRINT(DMLVL_DEBUG,
457 				    "Unable to set up variation! (errno = %d)\n",
458 				    errno);
459 			DMVAR_SKIP();
460 		} else {
461 			/* Variation */
462 			EVENT_DELIVERY_DELAY;
463 			DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s)\n",
464 				    DummySubdir, DummySubdir2);
465 			rc = symlink(DummySubdir, DummySubdir2);
466 			DMLOG_PRINT(DMLVL_DEBUG,
467 				    "symlink(%s, %s) returned %d\n",
468 				    DummySubdir, DummySubdir2, rc);
469 			EVENT_DELIVERY_DELAY;
470 			if ((varStatus =
471 			     DMVAR_CHKPASSEXP(0, rc, eventExpected,
472 					      eventReceived)) == DMSTAT_PASS) {
473 				struct stat statfs;
474 
475 				rc = dm_handle_to_ino(ahanp1, ahlen1, &ino1);
476 				rc |= dm_handle_to_ino(ahanp2, ahlen2, &ino2);
477 				rc |= lstat(DummySubdir2, &statfs);
478 				if (rc == -1) {
479 					DMLOG_PRINT(DMLVL_ERR,
480 						    "Unable to obtain inode!\n");
481 					varStatus = DMSTAT_FAIL;
482 				} else if (ino1 != ROOT_INODE) {
483 					DMLOG_PRINT(DMLVL_ERR,
484 						    "Parent handle NOT root! (%lld vs %d)\n",
485 						    ino1, ROOT_INODE);
486 					varStatus = DMSTAT_FAIL;
487 				} else if (ino2 != statfs.st_ino) {
488 					DMLOG_PRINT(DMLVL_ERR,
489 						    "Entry handle NOT correct! (%lld vs %d)\n",
490 						    ino2, statfs.st_ino);
491 					varStatus = DMSTAT_FAIL;
492 				} else
493 				    if (dm_handle_cmp
494 					(hanp1, hlen1, ahanp1, ahlen1) != 0) {
495 					DMLOG_PRINT(DMLVL_ERR,
496 						    "Parent handles NOT same!\n");
497 					varStatus = DMSTAT_FAIL;
498 				} else if (strcmp(aname1, DUMMY_SUBDIR2) != 0) {
499 					DMLOG_PRINT(DMLVL_ERR,
500 						    "Symlink entry name NOT correct! (%s vs %s)\n",
501 						    aname1, DUMMY_SUBDIR2);
502 					varStatus = DMSTAT_FAIL;
503 				} else if (strcmp(aname2, DummySubdir) != 0) {
504 					DMLOG_PRINT(DMLVL_ERR,
505 						    "Symlink contents NOT correct! (%s vs %s)\n",
506 						    aname2, DummySubdir);
507 					varStatus = DMSTAT_FAIL;
508 				} else if (strcmp(name1, aname1) != 0) {
509 					DMLOG_PRINT(DMLVL_ERR,
510 						    "Symlink entry names NOT same! (%s vs %s)\n",
511 						    name1, aname1);
512 					varStatus = DMSTAT_FAIL;
513 				} else if (strcmp(name2, aname2) != 0) {
514 					DMLOG_PRINT(DMLVL_ERR,
515 						    "Symlink contents NOT same! (%s vs %s)\n",
516 						    name2, aname2);
517 					varStatus = DMSTAT_FAIL;
518 				} else if (aretcode != 0) {
519 					DMLOG_PRINT(DMLVL_ERR,
520 						    "Return codes NOT same! (%d vs %d)\n",
521 						    mode, amode);
522 					varStatus = DMSTAT_FAIL;
523 				}
524 			}
525 			DMVAR_END(varStatus);
526 
527 			/* Variation clean up */
528 			EVENT_DELIVERY_DELAY;
529 			rc = unlink(DummySubdir2);
530 			rc |= rmdir(DummySubdir);
531 			EVENT_DELIVERY_DELAY;
532 			if (rc == -1) {
533 				DMLOG_PRINT(DMLVL_DEBUG,
534 					    "Unable to clean up variation! (errno = %d)\n",
535 					    errno);
536 			}
537 		}
538 	}
539 
540 	/*
541 	 * TEST    : link - enabled on fs
542 	 * EXPECTED: DM_EVENT_POSTLINK
543 	 */
544 	if (DMVAR_EXEC(DIR_ASYNC_NAMESP_EVENT_BASE + 5)) {
545 #ifdef DIRECTORY_LINKS
546 		dm_ino_t ino, ino1, ino2;
547 		void *hanp;
548 		size_t hlen;
549 
550 		/* Variation set up */
551 		eventExpected = DM_EVENT_POSTLINK;
552 		eventReceived = DM_EVENT_INVALID;
553 		eventResponse = DM_RESP_CONTINUE;
554 		EVENT_DELIVERY_DELAY;
555 		rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE);
556 		if (rc == -1) {
557 			DMLOG_PRINT(DMLVL_DEBUG,
558 				    "Unable to set up variation! (errno = %d)\n",
559 				    errno);
560 			DMVAR_SKIP();
561 		} else {
562 			/* Variation */
563 			EVENT_DELIVERY_DELAY;
564 			DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s)\n", DummySubdir,
565 				    DummyLink);
566 			rc = link(DummySubdir, DummyLink);
567 			DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s) returned %d\n",
568 				    DummySubdir, DummyLink, rc);
569 			EVENT_DELIVERY_DELAY;
570 			if ((varStatus =
571 			     DMVAR_CHKPASSEXP(0, rc, eventExpected,
572 					      eventReceived)) == DMSTAT_PASS) {
573 				rc = dm_handle_to_ino(hanp1, hlen1, &ino1);
574 				rc |= dm_handle_to_ino(hanp2, hlen2, &ino2);
575 				rc |= dm_handle_to_ino(hanp, hlen, &ino);
576 				if (rc == -1) {
577 					DMLOG_PRINT(DMLVL_ERR,
578 						    "Unable to obtain inode!\n");
579 					varStatus = DMSTAT_FAIL;
580 				} else if (ino1 != ROOT_INODE) {
581 					DMLOG_PRINT(DMLVL_ERR,
582 						    "Parent handle NOT root! (%d vs %d)\n",
583 						    ino1, ROOT_INODE);
584 					varStatus = DMSTAT_FAIL;
585 				} else if (ino2 != ino) {
586 					DMLOG_PRINT(DMLVL_ERR,
587 						    "Source link handle NOT correct! (%d vs %d)\n",
588 						    ino2, ino);
589 					varStatus = DMSTAT_FAIL;
590 				} else if (strcmp(name1, DUMMY_LINK) != 0) {
591 					DMLOG_PRINT(DMLVL_ERR,
592 						    "Target entry name NOT correct! (%s vs %s)\n",
593 						    name1, DUMMY_LINK);
594 					varStatus = DMSTAT_FAIL;
595 				}
596 			}
597 			DMVAR_END(varStatus);
598 
599 			/* Variation clean up */
600 			EVENT_DELIVERY_DELAY;
601 			rc = rmdir(DummySubdir);
602 			rc |= unlink(DummyLink);
603 			if (rc == -1) {
604 				DMLOG_PRINT(DMLVL_DEBUG,
605 					    "Unable to clean up variation! (errno = %d)\n",
606 					    errno);
607 			}
608 			dm_handle_free(hanp, hlen);
609 		}
610 #else
611 		DMLOG_PRINT(DMLVL_WARN,
612 			    "Test case not built with DIRECTORY_LINKS defined\n");
613 		DMVAR_SKIP();
614 #endif
615 	}
616 
617 	/*
618 	 * TEST    : open - enabled on fs
619 	 * EXPECTED: DM_EVENT_POSTCREATE
620 	 */
621 	if (DMVAR_EXEC(FILE_ASYNC_NAMESP_EVENT_BASE + 1)) {
622 		int fd;
623 		dm_ino_t ino1, ino2;
624 
625 		/* Variation set up */
626 		eventExpected = DM_EVENT_POSTCREATE;
627 		eventReceived = DM_EVENT_INVALID;
628 		eventResponse = DM_RESP_CONTINUE;
629 
630 		/* Variation */
631 		EVENT_DELIVERY_DELAY;
632 		DMLOG_PRINT(DMLVL_DEBUG, "open(%s)\n", DummyFile);
633 		fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE);
634 		DMLOG_PRINT(DMLVL_DEBUG, "open(%s) returned %d\n", DummyFile,
635 			    rc);
636 		rc = (fd == -1) ? -1 : 0;
637 		EVENT_DELIVERY_DELAY;
638 		if ((varStatus =
639 		     DMVAR_CHKPASSEXP(0, rc, eventExpected,
640 				      eventReceived)) == DMSTAT_PASS) {
641 			struct stat statfs;
642 
643 			rc = dm_handle_to_ino(ahanp1, ahlen1, &ino1);
644 			rc |= dm_handle_to_ino(ahanp2, ahlen2, &ino2);
645 			rc |= stat(DummyFile, &statfs);
646 			if (rc == -1) {
647 				DMLOG_PRINT(DMLVL_ERR,
648 					    "Unable to obtain inode!\n");
649 				varStatus = DMSTAT_FAIL;
650 			} else if (ino1 != ROOT_INODE) {
651 				DMLOG_PRINT(DMLVL_ERR,
652 					    "Parent handle NOT root! (%lld vs %d)\n",
653 					    ino1, ROOT_INODE);
654 				varStatus = DMSTAT_FAIL;
655 			} else if (ino2 != statfs.st_ino) {
656 				DMLOG_PRINT(DMLVL_ERR,
657 					    "Entry handle NOT correct! (%lld vs %d)\n",
658 					    ino2, statfs.st_ino);
659 				varStatus = DMSTAT_FAIL;
660 			} else if (strcmp(aname1, DUMMY_FILE) != 0) {
661 				DMLOG_PRINT(DMLVL_ERR,
662 					    "Entry name NOT correct! (%s vs %s)\n",
663 					    aname1, DUMMY_FILE);
664 				varStatus = DMSTAT_FAIL;
665 			} else if (dm_handle_cmp(hanp1, hlen1, ahanp1, ahlen1)
666 				   != 0) {
667 				DMLOG_PRINT(DMLVL_ERR,
668 					    "Parent handles NOT same!\n");
669 				varStatus = DMSTAT_FAIL;
670 			} else if (strcmp(name1, aname1) != 0) {
671 				DMLOG_PRINT(DMLVL_ERR,
672 					    "Entry names NOT same! (%s vs %s)\n",
673 					    name1, aname1);
674 				varStatus = DMSTAT_FAIL;
675 			} else if (amode != statfs.st_mode) {
676 				DMLOG_PRINT(DMLVL_ERR,
677 					    "Modes NOT same! (%d vs %d)\n",
678 					    amode, statfs.st_mode);
679 				varStatus = DMSTAT_FAIL;
680 			} else if (aretcode != 0) {
681 				DMLOG_PRINT(DMLVL_ERR,
682 					    "Return codes NOT same! (%d vs %d)\n",
683 					    mode, amode);
684 				varStatus = DMSTAT_FAIL;
685 			}
686 		}
687 		DMVAR_END(varStatus);
688 
689 		/* Variation clean up */
690 		EVENT_DELIVERY_DELAY;
691 		rc = close(fd);
692 		rc |= remove(DummyFile);
693 		EVENT_DELIVERY_DELAY;
694 		if (rc == -1) {
695 			DMLOG_PRINT(DMLVL_DEBUG,
696 				    "Unable to clean up variation! (errno = %d)\n",
697 				    errno);
698 		}
699 	}
700 
701 	/*
702 	 * TEST    : remove - enabled on fs
703 	 * EXPECTED: DM_EVENT_POSTREMOVE
704 	 */
705 	if (DMVAR_EXEC(FILE_ASYNC_NAMESP_EVENT_BASE + 2)) {
706 		int fd;
707 		dm_ino_t ino;
708 		struct stat statfs;
709 
710 		/* Variation set up */
711 		eventExpected = DM_EVENT_POSTREMOVE;
712 		eventReceived = DM_EVENT_INVALID;
713 		eventResponse = DM_RESP_CONTINUE;
714 		EVENT_DELIVERY_DELAY;
715 		if ((fd =
716 		     open(DummyFile, O_RDWR | O_CREAT,
717 			  DUMMY_FILE_RW_MODE)) == -1) {
718 			/* No clean up */
719 		} else if (((rc = close(fd)) == -1) ||
720 			   ((rc = stat(DummyFile, &statfs)) == -1)) {
721 			remove(DummyFile);
722 		}
723 		if (fd == -1 || rc == -1) {
724 			DMLOG_PRINT(DMLVL_DEBUG,
725 				    "Unable to set up variation! (errno = %d)\n",
726 				    errno);
727 			DMVAR_SKIP();
728 		} else {
729 			/* Variation */
730 			EVENT_DELIVERY_DELAY;
731 			DMLOG_PRINT(DMLVL_DEBUG, "remove(%s)\n", DummyFile);
732 			rc = remove(DummyFile);
733 			DMLOG_PRINT(DMLVL_DEBUG, "remove(%s) returned %d\n",
734 				    DummyFile, rc);
735 			EVENT_DELIVERY_DELAY;
736 			if ((varStatus =
737 			     DMVAR_CHKPASSEXP(0, rc, eventExpected,
738 					      eventReceived)) == DMSTAT_PASS) {
739 				rc = dm_handle_to_ino(ahanp1, ahlen1, &ino);
740 				if (rc == -1) {
741 					DMLOG_PRINT(DMLVL_ERR,
742 						    "Unable to obtain inode!\n");
743 					varStatus = DMSTAT_FAIL;
744 				} else if (ino != ROOT_INODE) {
745 					DMLOG_PRINT(DMLVL_ERR,
746 						    "Parent handle NOT root! (%lld vs %d)\n",
747 						    ino, ROOT_INODE);
748 					varStatus = DMSTAT_FAIL;
749 				} else if (strcmp(aname1, DUMMY_FILE) != 0) {
750 					DMLOG_PRINT(DMLVL_ERR,
751 						    "Entry name NOT correct! (%s vs %s)\n",
752 						    aname1, DUMMY_FILE);
753 					varStatus = DMSTAT_FAIL;
754 				} else
755 				    if (dm_handle_cmp
756 					(hanp1, hlen1, ahanp1, ahlen1) != 0) {
757 					DMLOG_PRINT(DMLVL_ERR,
758 						    "Parent handles NOT same!\n");
759 					varStatus = DMSTAT_FAIL;
760 				} else if (strcmp(name1, aname1) != 0) {
761 					DMLOG_PRINT(DMLVL_ERR,
762 						    "Entry names NOT same! (%s vs %s)\n",
763 						    name1, aname1);
764 					varStatus = DMSTAT_FAIL;
765 				} else if (amode != statfs.st_mode) {
766 					DMLOG_PRINT(DMLVL_ERR,
767 						    "Modes NOT same! (%d vs %d)\n",
768 						    amode, statfs.st_mode);
769 					varStatus = DMSTAT_FAIL;
770 				} else if (aretcode != 0) {
771 					DMLOG_PRINT(DMLVL_ERR,
772 						    "Return codes NOT same! (%d vs %d)\n",
773 						    mode, amode);
774 					varStatus = DMSTAT_FAIL;
775 				}
776 			}
777 			DMVAR_END(varStatus);
778 
779 			/* Variation clean up */
780 		}
781 	}
782 
783 	/*
784 	 * TEST    : mv - enabled on fs
785 	 * EXPECTED: DM_EVENT_POSTRENAME
786 	 */
787 	if (DMVAR_EXEC(FILE_ASYNC_NAMESP_EVENT_BASE + 3)) {
788 		int fd;
789 		dm_ino_t ino1, ino2;
790 
791 		/* Variation set up */
792 		eventExpected = DM_EVENT_POSTRENAME;
793 		eventReceived = DM_EVENT_INVALID;
794 		eventResponse = DM_RESP_CONTINUE;
795 		sprintf(command, "mv %s %s", DummyFile, DummyFile2);
796 		EVENT_DELIVERY_DELAY;
797 		if ((fd =
798 		     open(DummyFile, O_RDWR | O_CREAT,
799 			  DUMMY_FILE_RW_MODE)) == -1) {
800 			/* No clean up */
801 		} else if ((rc = close(fd)) == -1) {
802 			remove(DummyFile);
803 		}
804 		if (fd == -1 || rc == -1) {
805 			DMLOG_PRINT(DMLVL_DEBUG,
806 				    "Unable to set up variation! (errno = %d)\n",
807 				    errno);
808 			DMVAR_SKIP();
809 		} else {
810 			/* Variation */
811 			EVENT_DELIVERY_DELAY;
812 			DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s)\n",
813 				    DummyFile, DummyFile2);
814 			rc = system(command);
815 			DMLOG_PRINT(DMLVL_DEBUG,
816 				    "system(mv %s %s) returned %d\n", DummyFile,
817 				    DummyFile2, rc);
818 			EVENT_DELIVERY_DELAY;
819 			if ((varStatus =
820 			     DMVAR_CHKPASSEXP(0, rc, eventExpected,
821 					      eventReceived)) == DMSTAT_PASS) {
822 				rc = dm_handle_to_ino(ahanp1, ahlen1, &ino1);
823 				rc |= dm_handle_to_ino(ahanp2, ahlen2, &ino2);
824 				if (rc == -1) {
825 					DMLOG_PRINT(DMLVL_ERR,
826 						    "Unable to obtain inode!\n");
827 					varStatus = DMSTAT_FAIL;
828 				} else if (ino1 != ROOT_INODE) {
829 					DMLOG_PRINT(DMLVL_ERR,
830 						    "Old parent handle NOT root! (%lld vs %d)\n",
831 						    ino1, ROOT_INODE);
832 					varStatus = DMSTAT_FAIL;
833 				} else if (ino2 != ROOT_INODE) {
834 					DMLOG_PRINT(DMLVL_ERR,
835 						    "New parent handle NOT root! (%lld vs %d)\n",
836 						    ino2, ROOT_INODE);
837 					varStatus = DMSTAT_FAIL;
838 				} else
839 				    if (dm_handle_cmp
840 					(ahanp1, ahlen1, ahanp2, ahlen2) != 0) {
841 					DMLOG_PRINT(DMLVL_ERR,
842 						    "Old parent handle NOT equal to new parent handle!\n");
843 					varStatus = DMSTAT_FAIL;
844 				} else
845 				    if (dm_handle_cmp
846 					(hanp1, hlen1, ahanp1, ahlen1) != 0) {
847 					DMLOG_PRINT(DMLVL_ERR,
848 						    "Old parent handles NOT same!\n");
849 					varStatus = DMSTAT_FAIL;
850 				} else
851 				    if (dm_handle_cmp
852 					(hanp2, hlen2, ahanp2, ahlen2) != 0) {
853 					DMLOG_PRINT(DMLVL_ERR,
854 						    "New parent handles NOT same!\n");
855 					varStatus = DMSTAT_FAIL;
856 				} else if (strcmp(aname1, DUMMY_FILE) != 0) {
857 					DMLOG_PRINT(DMLVL_ERR,
858 						    "Old entry name NOT correct! (%s vs %s)\n",
859 						    name1, DUMMY_FILE);
860 					varStatus = DMSTAT_FAIL;
861 				} else if (strcmp(aname2, DUMMY_FILE2) != 0) {
862 					DMLOG_PRINT(DMLVL_ERR,
863 						    "New entry name NOT correct! (%s vs %s)\n",
864 						    name2, DUMMY_FILE2);
865 					varStatus = DMSTAT_FAIL;
866 				} else if (strcmp(name1, aname1) != 0) {
867 					DMLOG_PRINT(DMLVL_ERR,
868 						    "Old entry name NOT same! (%s vs %s)\n",
869 						    name1, aname1);
870 					varStatus = DMSTAT_FAIL;
871 				} else if (strcmp(name2, aname2) != 0) {
872 					DMLOG_PRINT(DMLVL_ERR,
873 						    "New entry name NOT same! (%s vs %s)\n",
874 						    name2, aname2);
875 					varStatus = DMSTAT_FAIL;
876 				} else if (aretcode != 0) {
877 					DMLOG_PRINT(DMLVL_ERR,
878 						    "Return codes NOT same! (%d vs %d)\n",
879 						    mode, amode);
880 					varStatus = DMSTAT_FAIL;
881 				}
882 			}
883 			DMVAR_END(varStatus);
884 
885 			/* Variation clean up */
886 			EVENT_DELIVERY_DELAY;
887 			rc = remove(DummyFile2);
888 			EVENT_DELIVERY_DELAY;
889 			if (rc == -1) {
890 				DMLOG_PRINT(DMLVL_DEBUG,
891 					    "Unable to clean up variation! (errno = %d)\n",
892 					    errno);
893 			}
894 		}
895 	}
896 
897 	/*
898 	 * TEST    : symlink - enabled on fs
899 	 * EXPECTED: DM_EVENT_POSTSYMLINK
900 	 */
901 	if (DMVAR_EXEC(FILE_ASYNC_NAMESP_EVENT_BASE + 4)) {
902 		int fd;
903 		dm_ino_t ino1, ino2;
904 
905 		/* Variation set up */
906 		eventExpected = DM_EVENT_POSTSYMLINK;
907 		eventReceived = DM_EVENT_INVALID;
908 		eventResponse = DM_RESP_CONTINUE;
909 		EVENT_DELIVERY_DELAY;
910 		if ((fd =
911 		     open(DummyFile, O_RDWR | O_CREAT,
912 			  DUMMY_FILE_RW_MODE)) == -1) {
913 			/* No clean up */
914 		} else if ((rc = close(fd)) == -1) {
915 			remove(DummyFile);
916 		}
917 		if (fd == -1 || rc == -1) {
918 			DMLOG_PRINT(DMLVL_DEBUG,
919 				    "Unable to set up variation! (errno = %d)\n",
920 				    errno);
921 			DMVAR_SKIP();
922 		} else {
923 			/* Variation */
924 			EVENT_DELIVERY_DELAY;
925 			DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s)\n", DummyFile,
926 				    DummyLink);
927 			rc = symlink(DummyFile, DummyLink);
928 			DMLOG_PRINT(DMLVL_DEBUG,
929 				    "symlink(%s, %s) returned %d\n", DummyFile,
930 				    DummyLink, rc);
931 			EVENT_DELIVERY_DELAY;
932 			if ((varStatus =
933 			     DMVAR_CHKPASSEXP(0, rc, eventExpected,
934 					      eventReceived)) == DMSTAT_PASS) {
935 				struct stat statfs;
936 
937 				rc = dm_handle_to_ino(ahanp1, ahlen1, &ino1);
938 				rc |= dm_handle_to_ino(ahanp2, ahlen2, &ino2);
939 				rc |= lstat(DummyLink, &statfs);
940 				if (rc == -1) {
941 					DMLOG_PRINT(DMLVL_ERR,
942 						    "Unable to obtain inode!\n");
943 					varStatus = DMSTAT_FAIL;
944 				} else if (ino1 != ROOT_INODE) {
945 					DMLOG_PRINT(DMLVL_ERR,
946 						    "Parent handle NOT root! (%lld vs %d)\n",
947 						    ino1, ROOT_INODE);
948 					varStatus = DMSTAT_FAIL;
949 				} else if (ino2 != statfs.st_ino) {
950 					DMLOG_PRINT(DMLVL_ERR,
951 						    "Entry handle NOT correct! (%lld vs %d)\n",
952 						    ino2, statfs.st_ino);
953 					varStatus = DMSTAT_FAIL;
954 				} else
955 				    if (dm_handle_cmp
956 					(hanp1, hlen1, ahanp1, ahlen1) != 0) {
957 					DMLOG_PRINT(DMLVL_ERR,
958 						    "Parent handles NOT same!\n");
959 					varStatus = DMSTAT_FAIL;
960 				} else if (strcmp(aname1, DUMMY_LINK) != 0) {
961 					DMLOG_PRINT(DMLVL_ERR,
962 						    "Symlink entry name NOT correct! (%s vs %s)\n",
963 						    aname1, DUMMY_LINK);
964 					varStatus = DMSTAT_FAIL;
965 				} else if (strcmp(aname2, DummyFile) != 0) {
966 					DMLOG_PRINT(DMLVL_ERR,
967 						    "Symlink contents NOT correct! (%s vs %s)\n",
968 						    aname2, DummyFile);
969 					varStatus = DMSTAT_FAIL;
970 				} else if (strcmp(name1, aname1) != 0) {
971 					DMLOG_PRINT(DMLVL_ERR,
972 						    "Symlink entry names NOT same! (%s vs %s)\n",
973 						    name1, aname1);
974 					varStatus = DMSTAT_FAIL;
975 				} else if (strcmp(name2, aname2) != 0) {
976 					DMLOG_PRINT(DMLVL_ERR,
977 						    "Symlink contents NOT same! (%s vs %s)\n",
978 						    name2, aname2);
979 					varStatus = DMSTAT_FAIL;
980 				} else if (aretcode != 0) {
981 					DMLOG_PRINT(DMLVL_ERR,
982 						    "Return codes NOT same! (%d vs %d)\n",
983 						    mode, amode);
984 					varStatus = DMSTAT_FAIL;
985 				}
986 			}
987 			DMVAR_END(varStatus);
988 
989 			/* Variation clean up */
990 			EVENT_DELIVERY_DELAY;
991 			rc = unlink(DummyLink);
992 			rc |= remove(DummyFile);
993 			EVENT_DELIVERY_DELAY;
994 			if (rc == -1) {
995 				DMLOG_PRINT(DMLVL_DEBUG,
996 					    "Unable to clean up variation! (errno = %d)\n",
997 					    errno);
998 			}
999 		}
1000 	}
1001 
1002 	/*
1003 	 * TEST    : link - enabled on fs
1004 	 * EXPECTED: DM_EVENT_POSTLINK
1005 	 */
1006 	if (DMVAR_EXEC(FILE_ASYNC_NAMESP_EVENT_BASE + 5)) {
1007 		dm_ino_t ino, ino1, ino2;
1008 		void *hanp;
1009 		size_t hlen;
1010 		int fd;
1011 
1012 		/* Variation set up */
1013 		eventExpected = DM_EVENT_POSTLINK;
1014 		eventReceived = DM_EVENT_INVALID;
1015 		eventResponse = DM_RESP_CONTINUE;
1016 		EVENT_DELIVERY_DELAY;
1017 		if ((fd =
1018 		     open(DummyFile, O_RDWR | O_CREAT,
1019 			  DUMMY_FILE_RW_MODE)) == -1) {
1020 			/* No clean up */
1021 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
1022 			close(fd);
1023 			remove(DummyFile);
1024 		}
1025 		if (fd == -1 || rc == -1) {
1026 			DMLOG_PRINT(DMLVL_DEBUG,
1027 				    "Unable to set up variation! (errno = %d)\n",
1028 				    errno);
1029 			DMVAR_SKIP();
1030 		} else {
1031 			/* Variation */
1032 			EVENT_DELIVERY_DELAY;
1033 			DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s)\n", DummyFile,
1034 				    DummyLink);
1035 			rc = link(DummyFile, DummyLink);
1036 			DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s) returned %d\n",
1037 				    DummyFile, DummyLink, rc);
1038 			EVENT_DELIVERY_DELAY;
1039 			if ((varStatus =
1040 			     DMVAR_CHKPASSEXP(0, rc, eventExpected,
1041 					      eventReceived)) == DMSTAT_PASS) {
1042 				rc = dm_handle_to_ino(hanp1, hlen1, &ino1);
1043 				rc |= dm_handle_to_ino(hanp2, hlen2, &ino2);
1044 				rc |= dm_handle_to_ino(hanp, hlen, &ino);
1045 				if (rc == -1) {
1046 					DMLOG_PRINT(DMLVL_ERR,
1047 						    "Unable to obtain inode!\n");
1048 					varStatus = DMSTAT_FAIL;
1049 				} else if (ino1 != ROOT_INODE) {
1050 					DMLOG_PRINT(DMLVL_ERR,
1051 						    "Parent handle NOT root! (%d vs %d)\n",
1052 						    ino1, ROOT_INODE);
1053 					varStatus = DMSTAT_FAIL;
1054 				} else if (ino2 != ino) {
1055 					DMLOG_PRINT(DMLVL_ERR,
1056 						    "Source link handle NOT correct! (%d vs %d)\n",
1057 						    ino2, ino);
1058 					varStatus = DMSTAT_FAIL;
1059 				} else if (strcmp(name1, DUMMY_LINK) != 0) {
1060 					DMLOG_PRINT(DMLVL_ERR,
1061 						    "Target entry name NOT correct! (%s vs %s)\n",
1062 						    name1, DUMMY_LINK);
1063 					varStatus = DMSTAT_FAIL;
1064 				}
1065 			}
1066 			DMVAR_END(varStatus);
1067 
1068 			/* Variation clean up */
1069 			EVENT_DELIVERY_DELAY;
1070 			rc = close(fd);
1071 			rc |= remove(DummyFile);
1072 			rc |= remove(DummyLink);
1073 			if (rc == -1) {
1074 				DMLOG_PRINT(DMLVL_DEBUG,
1075 					    "Unable to clean up variation! (errno = %d)\n",
1076 					    errno);
1077 			}
1078 			dm_handle_free(hanp, hlen);
1079 		}
1080 	}
1081 
1082 	/* Wait for all pending messages to be handled */
1083 	EVENT_DELIVERY_DELAY_LOOP;
1084 
1085 	/*
1086 	 *  Next batch of tests will be with events enabled on directory, so
1087 	 *  clear events on fs and set up events on dir accordingly
1088 	 */
1089 	rc = dm_path_to_fshandle(mountPt, &fshanp, &fshlen);
1090 	if (rc == -1) {
1091 		DMLOG_PRINT(DMLVL_ERR,
1092 			    "dm_path_to_handle failed! (rc = %d, errno = %d)\n",
1093 			    rc, errno);
1094 		dm_destroy_session(sid);
1095 		DM_EXIT();
1096 	}
1097 
1098 	DMEV_ZERO(events);
1099 	DMEV_SET(DM_EVENT_PREUNMOUNT, events);
1100 	DMEV_SET(DM_EVENT_UNMOUNT, events);
1101 	rc = dm_set_eventlist(sid, fshanp, fshlen, DM_NO_TOKEN, &events,
1102 			      DM_EVENT_MAX);
1103 	if (rc == -1) {
1104 		DMLOG_PRINT(DMLVL_ERR,
1105 			    "dm_set_eventlist(fs) failed! (rc = %d, errno = %d)\n",
1106 			    rc, errno);
1107 		dm_destroy_session(sid);
1108 		DM_EXIT();
1109 	}
1110 
1111 	rc = dm_path_to_handle(mountPt, &dhanp, &dhlen);
1112 	if (rc == -1) {
1113 		DMLOG_PRINT(DMLVL_ERR,
1114 			    "dm_path_to_handle failed! (rc = %d, errno = %d)\n",
1115 			    rc, errno);
1116 		dm_destroy_session(sid);
1117 		DM_EXIT();
1118 	}
1119 
1120 	DMEV_ZERO(events);
1121 	DMEV_SET(DM_EVENT_CREATE, events);
1122 	DMEV_SET(DM_EVENT_POSTCREATE, events);
1123 	DMEV_SET(DM_EVENT_REMOVE, events);
1124 	DMEV_SET(DM_EVENT_POSTREMOVE, events);
1125 	DMEV_SET(DM_EVENT_RENAME, events);
1126 	DMEV_SET(DM_EVENT_POSTRENAME, events);
1127 	DMEV_SET(DM_EVENT_SYMLINK, events);
1128 	DMEV_SET(DM_EVENT_POSTSYMLINK, events);
1129 	DMEV_SET(DM_EVENT_LINK, events);
1130 	DMEV_SET(DM_EVENT_POSTLINK, events);
1131 	rc = dm_set_eventlist(sid, dhanp, dhlen, DM_NO_TOKEN, &events,
1132 			      DM_EVENT_MAX);
1133 	if (rc == -1) {
1134 		DMLOG_PRINT(DMLVL_ERR,
1135 			    "dm_set_eventlist(dir) failed! (rc = %d, errno = %d)\n",
1136 			    rc, errno);
1137 		dm_destroy_session(sid);
1138 		DM_EXIT();
1139 	}
1140 
1141 	/*
1142 	 * TEST    : mkdir - enabled on directory
1143 	 * EXPECTED: DM_EVENT_POSTCREATE
1144 	 */
1145 	if (DMVAR_EXEC(DIR_ASYNC_NAMESP_EVENT_BASE + 6)) {
1146 		dm_ino_t ino1, ino2;
1147 
1148 		/* Variation set up */
1149 		eventExpected = DM_EVENT_POSTCREATE;
1150 		eventReceived = DM_EVENT_INVALID;
1151 		eventResponse = DM_RESP_CONTINUE;
1152 
1153 		/* Variation */
1154 		EVENT_DELIVERY_DELAY;
1155 		DMLOG_PRINT(DMLVL_DEBUG, "mkdir(%s)\n", DummySubdir);
1156 		rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE);
1157 		DMLOG_PRINT(DMLVL_DEBUG, "mkdir(%s) returned %d\n", DummySubdir,
1158 			    rc);
1159 		EVENT_DELIVERY_DELAY;
1160 		if ((varStatus =
1161 		     DMVAR_CHKPASSEXP(0, rc, eventExpected,
1162 				      eventReceived)) == DMSTAT_PASS) {
1163 			struct stat statfs;
1164 
1165 			rc = dm_handle_to_ino(ahanp1, ahlen1, &ino1);
1166 			rc |= dm_handle_to_ino(ahanp2, ahlen2, &ino2);
1167 			rc |= stat(DummySubdir, &statfs);
1168 			if (rc == -1) {
1169 				DMLOG_PRINT(DMLVL_ERR,
1170 					    "Unable to obtain inode!\n");
1171 				varStatus = DMSTAT_FAIL;
1172 			} else if (ino1 != ROOT_INODE) {
1173 				DMLOG_PRINT(DMLVL_ERR,
1174 					    "Parent handle NOT root! (%lld vs %d)\n",
1175 					    ino1, ROOT_INODE);
1176 				varStatus = DMSTAT_FAIL;
1177 			} else if (ino2 != statfs.st_ino) {
1178 				DMLOG_PRINT(DMLVL_ERR,
1179 					    "Entry handle NOT correct! (%lld vs %d)\n",
1180 					    ino2, statfs.st_ino);
1181 				varStatus = DMSTAT_FAIL;
1182 			} else if (strcmp(aname1, DUMMY_SUBDIR) != 0) {
1183 				DMLOG_PRINT(DMLVL_ERR,
1184 					    "Entry name NOT correct! (%s vs %s)\n",
1185 					    aname1, DUMMY_SUBDIR);
1186 				varStatus = DMSTAT_FAIL;
1187 			} else if (dm_handle_cmp(hanp1, hlen1, ahanp1, ahlen1)
1188 				   != 0) {
1189 				DMLOG_PRINT(DMLVL_ERR,
1190 					    "Parent handles NOT same!\n");
1191 				varStatus = DMSTAT_FAIL;
1192 			} else if (strcmp(name1, aname1) != 0) {
1193 				DMLOG_PRINT(DMLVL_ERR,
1194 					    "Entry names NOT same! (%s vs %s)\n",
1195 					    name1, aname1);
1196 				varStatus = DMSTAT_FAIL;
1197 			} else if (amode != statfs.st_mode) {
1198 				DMLOG_PRINT(DMLVL_ERR,
1199 					    "Modes NOT same! (%d vs %d)\n",
1200 					    amode, statfs.st_mode);
1201 				varStatus = DMSTAT_FAIL;
1202 			} else if (aretcode != 0) {
1203 				DMLOG_PRINT(DMLVL_ERR,
1204 					    "Return codes NOT same! (%d vs %d)\n",
1205 					    mode, amode);
1206 				varStatus = DMSTAT_FAIL;
1207 			}
1208 		}
1209 		DMVAR_END(varStatus);
1210 
1211 		/* Variation clean up */
1212 		EVENT_DELIVERY_DELAY;
1213 		rc = rmdir(DummySubdir);
1214 		EVENT_DELIVERY_DELAY;
1215 		if (rc == -1) {
1216 			DMLOG_PRINT(DMLVL_DEBUG,
1217 				    "Unable to clean up variation! (errno = %d)\n",
1218 				    errno);
1219 		}
1220 	}
1221 
1222 	/*
1223 	 * TEST    : rmdir - enabled on directory
1224 	 * EXPECTED: DM_EVENT_POSTREMOVE
1225 	 */
1226 	if (DMVAR_EXEC(DIR_ASYNC_NAMESP_EVENT_BASE + 7)) {
1227 		dm_ino_t ino;
1228 		struct stat statfs;
1229 
1230 		/* Variation set up */
1231 		eventExpected = DM_EVENT_POSTREMOVE;
1232 		eventReceived = DM_EVENT_INVALID;
1233 		eventResponse = DM_RESP_CONTINUE;
1234 		EVENT_DELIVERY_DELAY;
1235 		if ((rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE)) == -1) {
1236 			/* No clean up */
1237 		} else if ((rc = stat(DummySubdir, &statfs)) == -1) {
1238 			rmdir(DummySubdir);
1239 		}
1240 		if (rc == -1) {
1241 			DMLOG_PRINT(DMLVL_DEBUG,
1242 				    "Unable to set up variation! (errno = %d)\n",
1243 				    errno);
1244 			DMVAR_SKIP();
1245 		} else {
1246 			/* Variation */
1247 			EVENT_DELIVERY_DELAY;
1248 			DMLOG_PRINT(DMLVL_DEBUG, "rmdir(%s)\n", DummySubdir);
1249 			rc = rmdir(DummySubdir);
1250 			DMLOG_PRINT(DMLVL_DEBUG, "rmdir(%s) returned %d\n",
1251 				    DummySubdir, rc);
1252 			EVENT_DELIVERY_DELAY;
1253 			if ((varStatus =
1254 			     DMVAR_CHKPASSEXP(0, rc, eventExpected,
1255 					      eventReceived)) == DMSTAT_PASS) {
1256 				rc = dm_handle_to_ino(ahanp1, ahlen1, &ino);
1257 				if (rc == -1) {
1258 					DMLOG_PRINT(DMLVL_ERR,
1259 						    "Unable to obtain inode!\n");
1260 					varStatus = DMSTAT_FAIL;
1261 				} else if (ino != ROOT_INODE) {
1262 					DMLOG_PRINT(DMLVL_ERR,
1263 						    "Parent handle NOT root! (%lld vs %d)\n",
1264 						    ino, ROOT_INODE);
1265 					varStatus = DMSTAT_FAIL;
1266 				} else if (strcmp(aname1, DUMMY_SUBDIR) != 0) {
1267 					DMLOG_PRINT(DMLVL_ERR,
1268 						    "Entry name NOT correct! (%s vs %s)\n",
1269 						    aname1, DUMMY_SUBDIR);
1270 					varStatus = DMSTAT_FAIL;
1271 				} else
1272 				    if (dm_handle_cmp
1273 					(hanp1, hlen1, ahanp1, ahlen1) != 0) {
1274 					DMLOG_PRINT(DMLVL_ERR,
1275 						    "Parent handles NOT same!\n");
1276 					varStatus = DMSTAT_FAIL;
1277 				} else if (strcmp(name1, aname1) != 0) {
1278 					DMLOG_PRINT(DMLVL_ERR,
1279 						    "Entry names NOT same! (%s vs %s)\n",
1280 						    name1, aname1);
1281 					varStatus = DMSTAT_FAIL;
1282 				} else if (amode != statfs.st_mode) {
1283 					DMLOG_PRINT(DMLVL_ERR,
1284 						    "Modes NOT same! (%d vs %d)\n",
1285 						    amode, statfs.st_mode);
1286 					varStatus = DMSTAT_FAIL;
1287 				} else if (aretcode != 0) {
1288 					DMLOG_PRINT(DMLVL_ERR,
1289 						    "Return codes NOT same! (%d vs %d)\n",
1290 						    mode, amode);
1291 					varStatus = DMSTAT_FAIL;
1292 				}
1293 			}
1294 			DMVAR_END(varStatus);
1295 
1296 			/* Variation clean up */
1297 		}
1298 	}
1299 
1300 	/*
1301 	 * TEST    : mv - enabled on source and destination directory
1302 	 * EXPECTED: DM_EVENT_POSTRENAME
1303 	 */
1304 	if (DMVAR_EXEC(DIR_ASYNC_NAMESP_EVENT_BASE + 8)) {
1305 		dm_ino_t ino1, ino2;
1306 
1307 		/* Variation set up */
1308 		eventExpected = DM_EVENT_POSTRENAME;
1309 		eventReceived = DM_EVENT_INVALID;
1310 		eventResponse = DM_RESP_CONTINUE;
1311 		sprintf(command, "mv %s %s", DummySubdir, DummySubdir2);
1312 		EVENT_DELIVERY_DELAY;
1313 		rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE);
1314 		if (rc == -1) {
1315 			DMLOG_PRINT(DMLVL_DEBUG,
1316 				    "Unable to set up variation! (errno = %d)\n",
1317 				    errno);
1318 			DMVAR_SKIP();
1319 		} else {
1320 			/* Variation */
1321 			EVENT_DELIVERY_DELAY;
1322 			DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s)\n",
1323 				    DummySubdir, DummySubdir2);
1324 			rc = system(command);
1325 			DMLOG_PRINT(DMLVL_DEBUG,
1326 				    "system(mv %s %s) returned %d\n",
1327 				    DummySubdir, DummySubdir2, rc);
1328 			EVENT_DELIVERY_DELAY;
1329 			if ((varStatus =
1330 			     DMVAR_CHKPASSEXP(0, rc, eventExpected,
1331 					      eventReceived)) == DMSTAT_PASS) {
1332 				rc = dm_handle_to_ino(ahanp1, ahlen1, &ino1);
1333 				rc |= dm_handle_to_ino(ahanp2, ahlen2, &ino2);
1334 				if (rc == -1) {
1335 					DMLOG_PRINT(DMLVL_ERR,
1336 						    "Unable to obtain inode!\n");
1337 					varStatus = DMSTAT_FAIL;
1338 				} else if (ino1 != ROOT_INODE) {
1339 					DMLOG_PRINT(DMLVL_ERR,
1340 						    "Old parent handle NOT root! (%lld vs %d)\n",
1341 						    ino1, ROOT_INODE);
1342 					varStatus = DMSTAT_FAIL;
1343 				} else if (ino2 != ROOT_INODE) {
1344 					DMLOG_PRINT(DMLVL_ERR,
1345 						    "New parent handle NOT root! (%lld vs %d)\n",
1346 						    ino2, ROOT_INODE);
1347 					varStatus = DMSTAT_FAIL;
1348 				} else
1349 				    if (dm_handle_cmp
1350 					(ahanp1, ahlen1, ahanp2, ahlen2) != 0) {
1351 					DMLOG_PRINT(DMLVL_ERR,
1352 						    "Old parent handle NOT equal to new parent handle!\n");
1353 					varStatus = DMSTAT_FAIL;
1354 				} else
1355 				    if (dm_handle_cmp
1356 					(hanp1, hlen1, ahanp1, ahlen1) != 0) {
1357 					DMLOG_PRINT(DMLVL_ERR,
1358 						    "Old parent handles NOT same!\n");
1359 					varStatus = DMSTAT_FAIL;
1360 				} else
1361 				    if (dm_handle_cmp
1362 					(hanp2, hlen2, ahanp2, ahlen2) != 0) {
1363 					DMLOG_PRINT(DMLVL_ERR,
1364 						    "New parent handles NOT same!\n");
1365 					varStatus = DMSTAT_FAIL;
1366 				} else if (strcmp(aname1, DUMMY_SUBDIR) != 0) {
1367 					DMLOG_PRINT(DMLVL_ERR,
1368 						    "Old entry name NOT correct! (%s vs %s)\n",
1369 						    name1, DUMMY_SUBDIR);
1370 					varStatus = DMSTAT_FAIL;
1371 				} else if (strcmp(aname2, DUMMY_SUBDIR2) != 0) {
1372 					DMLOG_PRINT(DMLVL_ERR,
1373 						    "New entry name NOT correct! (%s vs %s)\n",
1374 						    name2, DUMMY_SUBDIR2);
1375 					varStatus = DMSTAT_FAIL;
1376 				} else if (strcmp(name1, aname1) != 0) {
1377 					DMLOG_PRINT(DMLVL_ERR,
1378 						    "Old entry name NOT same! (%s vs %s)\n",
1379 						    name1, aname1);
1380 					varStatus = DMSTAT_FAIL;
1381 				} else if (strcmp(name2, aname2) != 0) {
1382 					DMLOG_PRINT(DMLVL_ERR,
1383 						    "New entry name NOT same! (%s vs %s)\n",
1384 						    name2, aname2);
1385 					varStatus = DMSTAT_FAIL;
1386 				} else if (aretcode != 0) {
1387 					DMLOG_PRINT(DMLVL_ERR,
1388 						    "Return codes NOT same! (%d vs %d)\n",
1389 						    mode, amode);
1390 					varStatus = DMSTAT_FAIL;
1391 				}
1392 			}
1393 			DMVAR_END(varStatus);
1394 
1395 			/* Variation clean up */
1396 			EVENT_DELIVERY_DELAY;
1397 			rc = rmdir(DummySubdir2);
1398 			EVENT_DELIVERY_DELAY;
1399 			if (rc == -1) {
1400 				DMLOG_PRINT(DMLVL_DEBUG,
1401 					    "Unable to clean up variation! (errno = %d)\n",
1402 					    errno);
1403 			}
1404 		}
1405 	}
1406 
1407 	/*
1408 	 * TEST    : mv - enabled on source directory
1409 	 * EXPECTED: DM_EVENT_POSTRENAME
1410 	 */
1411 	if (DMVAR_EXEC(DIR_ASYNC_NAMESP_EVENT_BASE + 9)) {
1412 		void *dhanp;
1413 		size_t dhlen;
1414 		dm_ino_t ino1, ino2, dino;
1415 
1416 		/* Variation set up */
1417 		eventExpected = DM_EVENT_POSTRENAME;
1418 		eventReceived = DM_EVENT_INVALID;
1419 		eventResponse = DM_RESP_CONTINUE;
1420 		sprintf(command, "mv %s %s", DummySubdir, DummySubdir2Subdir);
1421 		EVENT_DELIVERY_DELAY;
1422 		if ((rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE)) == -1) {
1423 			/* No clean up */
1424 		} else if ((rc = mkdir(DummySubdir2, DUMMY_DIR_RW_MODE)) == -1) {
1425 			rmdir(DummySubdir);
1426 		} else
1427 		    if ((rc =
1428 			 dm_path_to_handle(DummySubdir2, &dhanp,
1429 					   &dhlen)) == -1) {
1430 			rmdir(DummySubdir2);
1431 			rmdir(DummySubdir);
1432 		} else if ((rc = dm_handle_to_ino(dhanp, dhlen, &dino)) == -1) {
1433 			dm_handle_free(dhanp, dhlen);
1434 			rmdir(DummySubdir2);
1435 			rmdir(DummySubdir);
1436 		}
1437 		if (rc == -1) {
1438 			DMLOG_PRINT(DMLVL_DEBUG,
1439 				    "Unable to set up variation! (errno = %d)\n",
1440 				    errno);
1441 			DMVAR_SKIP();
1442 		} else {
1443 			/* Variation */
1444 			EVENT_DELIVERY_DELAY;
1445 			DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s)\n",
1446 				    DummySubdir, DummySubdir2Subdir);
1447 			rc = system(command);
1448 			DMLOG_PRINT(DMLVL_DEBUG,
1449 				    "system(mv %s %s) returned %d\n",
1450 				    DummySubdir, DummySubdir2Subdir, rc);
1451 			EVENT_DELIVERY_DELAY;
1452 			if ((varStatus =
1453 			     DMVAR_CHKPASSEXP(0, rc, eventExpected,
1454 					      eventReceived)) == DMSTAT_PASS) {
1455 				rc = dm_handle_to_ino(ahanp1, ahlen1, &ino1);
1456 				rc |= dm_handle_to_ino(ahanp2, ahlen2, &ino2);
1457 				if (rc == -1) {
1458 					DMLOG_PRINT(DMLVL_ERR,
1459 						    "Unable to obtain inode!\n");
1460 					varStatus = DMSTAT_FAIL;
1461 				} else if (ino1 != ROOT_INODE) {
1462 					DMLOG_PRINT(DMLVL_ERR,
1463 						    "Old parent handle NOT root! (%lld vs %d)\n",
1464 						    ino1, ROOT_INODE);
1465 					varStatus = DMSTAT_FAIL;
1466 				} else if (ino2 != dino) {
1467 					DMLOG_PRINT(DMLVL_ERR,
1468 						    "New parent handle NOT correct! (%lld vs %d)\n",
1469 						    ino2, dino);
1470 					varStatus = DMSTAT_FAIL;
1471 				} else
1472 				    if (dm_handle_cmp
1473 					(hanp1, hlen1, ahanp1, ahlen1) != 0) {
1474 					DMLOG_PRINT(DMLVL_ERR,
1475 						    "Old parent handles NOT same!\n");
1476 					varStatus = DMSTAT_FAIL;
1477 				} else
1478 				    if (dm_handle_cmp
1479 					(hanp2, hlen2, ahanp2, ahlen2) != 0) {
1480 					DMLOG_PRINT(DMLVL_ERR,
1481 						    "New parent handles NOT same!\n");
1482 					varStatus = DMSTAT_FAIL;
1483 				} else if (strcmp(aname1, DUMMY_SUBDIR) != 0) {
1484 					DMLOG_PRINT(DMLVL_ERR,
1485 						    "Old entry name NOT correct! (%s vs %s)\n",
1486 						    name1, DUMMY_SUBDIR);
1487 					varStatus = DMSTAT_FAIL;
1488 				} else if (strcmp(aname2, DUMMY_SUBDIR) != 0) {
1489 					DMLOG_PRINT(DMLVL_ERR,
1490 						    "New entry name NOT correct! (%s vs %s)\n",
1491 						    name2, DUMMY_SUBDIR);
1492 					varStatus = DMSTAT_FAIL;
1493 				} else if (strcmp(name1, aname1) != 0) {
1494 					DMLOG_PRINT(DMLVL_ERR,
1495 						    "Old entry name NOT same! (%s vs %s)\n",
1496 						    name1, aname1);
1497 					varStatus = DMSTAT_FAIL;
1498 				} else if (strcmp(name2, aname2) != 0) {
1499 					DMLOG_PRINT(DMLVL_ERR,
1500 						    "New entry name NOT same! (%s vs %s)\n",
1501 						    name2, aname2);
1502 					varStatus = DMSTAT_FAIL;
1503 				} else if (aretcode != 0) {
1504 					DMLOG_PRINT(DMLVL_ERR,
1505 						    "Return codes NOT same! (%d vs %d)\n",
1506 						    mode, amode);
1507 					varStatus = DMSTAT_FAIL;
1508 				}
1509 			}
1510 			DMVAR_END(varStatus);
1511 
1512 			/* Variation clean up */
1513 			EVENT_DELIVERY_DELAY;
1514 			rc = rmdir(DummySubdir2Subdir);
1515 			rc |= rmdir(DummySubdir2);
1516 			EVENT_DELIVERY_DELAY;
1517 			if (rc == -1) {
1518 				DMLOG_PRINT(DMLVL_DEBUG,
1519 					    "Unable to clean up variation! (errno = %d)\n",
1520 					    errno);
1521 			}
1522 			dm_handle_free(dhanp, dhlen);
1523 		}
1524 	}
1525 
1526 	/*
1527 	 * TEST    : mv - enabled on destination directory
1528 	 * EXPECTED: DM_EVENT_POSTRENAME
1529 	 */
1530 	if (DMVAR_EXEC(DIR_ASYNC_NAMESP_EVENT_BASE + 10)) {
1531 		void *dhanp;
1532 		size_t dhlen;
1533 		dm_ino_t ino1, ino2, dino;
1534 
1535 		/* Variation set up */
1536 		eventExpected = DM_EVENT_POSTRENAME;
1537 		eventReceived = DM_EVENT_INVALID;
1538 		eventResponse = DM_RESP_CONTINUE;
1539 		sprintf(command, "mv %s %s", DummySubdir2Subdir, DummySubdir);
1540 		EVENT_DELIVERY_DELAY;
1541 		if ((rc = mkdir(DummySubdir2, DUMMY_DIR_RW_MODE)) == -1) {
1542 			/* No clean up */
1543 		} else if ((rc = mkdir(DummySubdir2Subdir, DUMMY_DIR_RW_MODE))
1544 			   == -1) {
1545 			rmdir(DummySubdir2);
1546 		} else
1547 		    if ((rc =
1548 			 dm_path_to_handle(DummySubdir2, &dhanp,
1549 					   &dhlen)) == -1) {
1550 			rmdir(DummySubdir2Subdir);
1551 			rmdir(DummySubdir2);
1552 		} else if ((rc = dm_handle_to_ino(dhanp, dhlen, &dino)) == -1) {
1553 			dm_handle_free(dhanp, dhlen);
1554 			rmdir(DummySubdir2Subdir);
1555 			rmdir(DummySubdir2);
1556 		}
1557 		if (rc == -1) {
1558 			DMLOG_PRINT(DMLVL_DEBUG,
1559 				    "Unable to set up variation! (errno = %d)\n",
1560 				    errno);
1561 			DMVAR_SKIP();
1562 		} else {
1563 			/* Variation */
1564 			EVENT_DELIVERY_DELAY;
1565 			DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s)\n",
1566 				    DummySubdir2Subdir, DummySubdir);
1567 			rc = system(command);
1568 			DMLOG_PRINT(DMLVL_DEBUG,
1569 				    "system(mv %s %s) returned %d\n",
1570 				    DummySubdir2Subdir, DummySubdir, rc);
1571 			EVENT_DELIVERY_DELAY;
1572 			if ((varStatus =
1573 			     DMVAR_CHKPASSEXP(0, rc, eventExpected,
1574 					      eventReceived)) == DMSTAT_PASS) {
1575 				rc = dm_handle_to_ino(ahanp1, ahlen1, &ino1);
1576 				rc |= dm_handle_to_ino(ahanp2, ahlen2, &ino2);
1577 				if (rc == -1) {
1578 					DMLOG_PRINT(DMLVL_ERR,
1579 						    "Unable to obtain inode!\n");
1580 					varStatus = DMSTAT_FAIL;
1581 				} else if (ino1 != dino) {
1582 					DMLOG_PRINT(DMLVL_ERR,
1583 						    "Old parent handle NOT correct! (%lld vs %d)\n",
1584 						    ino1, dino);
1585 					varStatus = DMSTAT_FAIL;
1586 				} else if (ino2 != ROOT_INODE) {
1587 					DMLOG_PRINT(DMLVL_ERR,
1588 						    "New parent handle NOT root! (%lld vs %d)\n",
1589 						    ino2, ROOT_INODE);
1590 					varStatus = DMSTAT_FAIL;
1591 				} else
1592 				    if (dm_handle_cmp
1593 					(hanp1, hlen1, ahanp1, ahlen1) != 0) {
1594 					DMLOG_PRINT(DMLVL_ERR,
1595 						    "Old parent handles NOT same!\n");
1596 					varStatus = DMSTAT_FAIL;
1597 				} else
1598 				    if (dm_handle_cmp
1599 					(hanp2, hlen2, ahanp2, ahlen2) != 0) {
1600 					DMLOG_PRINT(DMLVL_ERR,
1601 						    "New parent handles NOT same!\n");
1602 					varStatus = DMSTAT_FAIL;
1603 				} else if (strcmp(aname1, DUMMY_SUBDIR) != 0) {
1604 					DMLOG_PRINT(DMLVL_ERR,
1605 						    "Old entry name NOT correct! (%s vs %s)\n",
1606 						    name1, DUMMY_SUBDIR);
1607 					varStatus = DMSTAT_FAIL;
1608 				} else if (strcmp(aname2, DUMMY_SUBDIR) != 0) {
1609 					DMLOG_PRINT(DMLVL_ERR,
1610 						    "New entry name NOT correct! (%s vs %s)\n",
1611 						    name2, DUMMY_SUBDIR);
1612 					varStatus = DMSTAT_FAIL;
1613 				} else if (strcmp(name1, aname1) != 0) {
1614 					DMLOG_PRINT(DMLVL_ERR,
1615 						    "Old entry name NOT same! (%s vs %s)\n",
1616 						    name1, aname1);
1617 					varStatus = DMSTAT_FAIL;
1618 				} else if (strcmp(name2, aname2) != 0) {
1619 					DMLOG_PRINT(DMLVL_ERR,
1620 						    "New entry name NOT same! (%s vs %s)\n",
1621 						    name2, aname2);
1622 					varStatus = DMSTAT_FAIL;
1623 				} else if (aretcode != 0) {
1624 					DMLOG_PRINT(DMLVL_ERR,
1625 						    "Return codes NOT same! (%d vs %d)\n",
1626 						    mode, amode);
1627 					varStatus = DMSTAT_FAIL;
1628 				}
1629 			}
1630 			DMVAR_END(varStatus);
1631 
1632 			/* Variation clean up */
1633 			EVENT_DELIVERY_DELAY;
1634 			rc = rmdir(DummySubdir2);
1635 			rc |= rmdir(DummySubdir);
1636 			EVENT_DELIVERY_DELAY;
1637 			if (rc == -1) {
1638 				DMLOG_PRINT(DMLVL_DEBUG,
1639 					    "Unable to clean up variation! (errno = %d)\n",
1640 					    errno);
1641 			}
1642 			dm_handle_free(dhanp, dhlen);
1643 		}
1644 	}
1645 
1646 	/*
1647 	 * TEST    : symlink - enabled on directory
1648 	 * EXPECTED: DM_EVENT_POSTSYMLINK
1649 	 */
1650 	if (DMVAR_EXEC(DIR_ASYNC_NAMESP_EVENT_BASE + 11)) {
1651 		dm_ino_t ino1, ino2;
1652 
1653 		/* Variation set up */
1654 		eventExpected = DM_EVENT_POSTSYMLINK;
1655 		eventReceived = DM_EVENT_INVALID;
1656 		eventResponse = DM_RESP_CONTINUE;
1657 		EVENT_DELIVERY_DELAY;
1658 		rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE);
1659 		if (rc == -1) {
1660 			DMLOG_PRINT(DMLVL_DEBUG,
1661 				    "Unable to set up variation! (errno = %d)\n",
1662 				    errno);
1663 			DMVAR_SKIP();
1664 		} else {
1665 			/* Variation */
1666 			EVENT_DELIVERY_DELAY;
1667 			DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s)\n",
1668 				    DummySubdir, DummySubdir2);
1669 			rc = symlink(DummySubdir, DummySubdir2);
1670 			DMLOG_PRINT(DMLVL_DEBUG,
1671 				    "symlink(%s, %s) returned %d\n",
1672 				    DummySubdir, DummySubdir2, rc);
1673 			EVENT_DELIVERY_DELAY;
1674 			if ((varStatus =
1675 			     DMVAR_CHKPASSEXP(0, rc, eventExpected,
1676 					      eventReceived)) == DMSTAT_PASS) {
1677 				struct stat statfs;
1678 
1679 				rc = dm_handle_to_ino(ahanp1, ahlen1, &ino1);
1680 				rc |= dm_handle_to_ino(ahanp2, ahlen2, &ino2);
1681 				rc |= lstat(DummySubdir2, &statfs);
1682 				if (rc == -1) {
1683 					DMLOG_PRINT(DMLVL_ERR,
1684 						    "Unable to obtain inode!\n");
1685 					varStatus = DMSTAT_FAIL;
1686 				} else if (ino1 != ROOT_INODE) {
1687 					DMLOG_PRINT(DMLVL_ERR,
1688 						    "Parent handle NOT root! (%lld vs %d)\n",
1689 						    ino1, ROOT_INODE);
1690 					varStatus = DMSTAT_FAIL;
1691 				} else if (ino2 != statfs.st_ino) {
1692 					DMLOG_PRINT(DMLVL_ERR,
1693 						    "Entry handle NOT correct! (%lld vs %d)\n",
1694 						    ino2, statfs.st_ino);
1695 					varStatus = DMSTAT_FAIL;
1696 				} else
1697 				    if (dm_handle_cmp
1698 					(hanp1, hlen1, ahanp1, ahlen1) != 0) {
1699 					DMLOG_PRINT(DMLVL_ERR,
1700 						    "Parent handles NOT same!\n");
1701 					varStatus = DMSTAT_FAIL;
1702 				} else if (strcmp(aname1, DUMMY_SUBDIR2) != 0) {
1703 					DMLOG_PRINT(DMLVL_ERR,
1704 						    "Symlink entry name NOT correct! (%s vs %s)\n",
1705 						    aname1, DUMMY_SUBDIR2);
1706 					varStatus = DMSTAT_FAIL;
1707 				} else if (strcmp(aname2, DummySubdir) != 0) {
1708 					DMLOG_PRINT(DMLVL_ERR,
1709 						    "Symlink contents NOT correct! (%s vs %s)\n",
1710 						    aname2, DummySubdir);
1711 					varStatus = DMSTAT_FAIL;
1712 				} else if (strcmp(name1, aname1) != 0) {
1713 					DMLOG_PRINT(DMLVL_ERR,
1714 						    "Symlink entry names NOT same! (%s vs %s)\n",
1715 						    name1, aname1);
1716 					varStatus = DMSTAT_FAIL;
1717 				} else if (strcmp(name2, aname2) != 0) {
1718 					DMLOG_PRINT(DMLVL_ERR,
1719 						    "Symlink contents NOT same! (%s vs %s)\n",
1720 						    name2, aname2);
1721 					varStatus = DMSTAT_FAIL;
1722 				} else if (aretcode != 0) {
1723 					DMLOG_PRINT(DMLVL_ERR,
1724 						    "Return codes NOT same! (%d vs %d)\n",
1725 						    mode, amode);
1726 					varStatus = DMSTAT_FAIL;
1727 				}
1728 			}
1729 			DMVAR_END(varStatus);
1730 
1731 			/* Variation clean up */
1732 			EVENT_DELIVERY_DELAY;
1733 			rc = unlink(DummySubdir2);
1734 			rc |= rmdir(DummySubdir);
1735 			EVENT_DELIVERY_DELAY;
1736 			if (rc == -1) {
1737 				DMLOG_PRINT(DMLVL_DEBUG,
1738 					    "Unable to clean up variation! (errno = %d)\n",
1739 					    errno);
1740 			}
1741 		}
1742 	}
1743 
1744 	/*
1745 	 * TEST    : link - enabled on directory
1746 	 * EXPECTED: DM_EVENT_POSTLINK
1747 	 */
1748 	if (DMVAR_EXEC(DIR_ASYNC_NAMESP_EVENT_BASE + 12)) {
1749 #ifdef DIRECTORY_LINKS
1750 		dm_ino_t ino, ino1, ino2;
1751 		void *hanp;
1752 		size_t hlen;
1753 
1754 		/* Variation set up */
1755 		eventExpected = DM_EVENT_POSTLINK;
1756 		eventReceived = DM_EVENT_INVALID;
1757 		eventResponse = DM_RESP_CONTINUE;
1758 		EVENT_DELIVERY_DELAY;
1759 		rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE);
1760 		if (rc == -1) {
1761 			DMLOG_PRINT(DMLVL_DEBUG,
1762 				    "Unable to set up variation! (errno = %d)\n",
1763 				    errno);
1764 			DMVAR_SKIP();
1765 		} else {
1766 			/* Variation */
1767 			EVENT_DELIVERY_DELAY;
1768 			DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s)\n", DummySubdir,
1769 				    DummyLink);
1770 			rc = link(DummySubdir, DummyLink);
1771 			DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s) returned %d\n",
1772 				    DummySubdir, DummyLink, rc);
1773 			EVENT_DELIVERY_DELAY;
1774 			if ((varStatus =
1775 			     DMVAR_CHKPASSEXP(0, rc, eventExpected,
1776 					      eventReceived)) == DMSTAT_PASS) {
1777 				rc = dm_handle_to_ino(hanp1, hlen1, &ino1);
1778 				rc |= dm_handle_to_ino(hanp2, hlen2, &ino2);
1779 				rc |= dm_handle_to_ino(hanp, hlen, &ino);
1780 				if (rc == -1) {
1781 					DMLOG_PRINT(DMLVL_ERR,
1782 						    "Unable to obtain inode!\n");
1783 					varStatus = DMSTAT_FAIL;
1784 				} else if (ino1 != ROOT_INODE) {
1785 					DMLOG_PRINT(DMLVL_ERR,
1786 						    "Parent handle NOT root! (%d vs %d)\n",
1787 						    ino1, ROOT_INODE);
1788 					varStatus = DMSTAT_FAIL;
1789 				} else if (ino2 != ino) {
1790 					DMLOG_PRINT(DMLVL_ERR,
1791 						    "Source link handle NOT correct! (%d vs %d)\n",
1792 						    ino2, ino);
1793 					varStatus = DMSTAT_FAIL;
1794 				} else if (strcmp(name1, DUMMY_LINK) != 0) {
1795 					DMLOG_PRINT(DMLVL_ERR,
1796 						    "Target entry name NOT correct! (%s vs %s)\n",
1797 						    name1, DUMMY_LINK);
1798 					varStatus = DMSTAT_FAIL;
1799 				}
1800 			}
1801 			DMVAR_END(varStatus);
1802 
1803 			/* Variation clean up */
1804 			EVENT_DELIVERY_DELAY;
1805 			rc = rmdir(DummySubdir);
1806 			rc |= unlink(DummyLink);
1807 			if (rc == -1) {
1808 				DMLOG_PRINT(DMLVL_DEBUG,
1809 					    "Unable to clean up variation! (errno = %d)\n",
1810 					    errno);
1811 			}
1812 			dm_handle_free(hanp, hlen);
1813 		}
1814 #else
1815 		DMLOG_PRINT(DMLVL_WARN,
1816 			    "Test case not built with DIRECTORY_LINKS defined\n");
1817 		DMVAR_SKIP();
1818 #endif
1819 	}
1820 
1821 	/*
1822 	 * TEST    : open - enabled on directory
1823 	 * EXPECTED: DM_EVENT_POSTCREATE
1824 	 */
1825 	if (DMVAR_EXEC(FILE_ASYNC_NAMESP_EVENT_BASE + 6)) {
1826 		int fd;
1827 		dm_ino_t ino1, ino2;
1828 
1829 		/* Variation set up */
1830 		eventExpected = DM_EVENT_POSTCREATE;
1831 		eventReceived = DM_EVENT_INVALID;
1832 		eventResponse = DM_RESP_CONTINUE;
1833 
1834 		/* Variation */
1835 		EVENT_DELIVERY_DELAY;
1836 		DMLOG_PRINT(DMLVL_DEBUG, "open(%s)\n", DummyFile);
1837 		fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE);
1838 		DMLOG_PRINT(DMLVL_DEBUG, "open(%s) returned %d\n", DummyFile,
1839 			    rc);
1840 		rc = (fd == -1) ? -1 : 0;
1841 		EVENT_DELIVERY_DELAY;
1842 		if ((varStatus =
1843 		     DMVAR_CHKPASSEXP(0, rc, eventExpected,
1844 				      eventReceived)) == DMSTAT_PASS) {
1845 			struct stat statfs;
1846 
1847 			rc = dm_handle_to_ino(ahanp1, ahlen1, &ino1);
1848 			rc |= dm_handle_to_ino(ahanp2, ahlen2, &ino2);
1849 			rc |= stat(DummyFile, &statfs);
1850 			if (rc == -1) {
1851 				DMLOG_PRINT(DMLVL_ERR,
1852 					    "Unable to obtain inode!\n");
1853 				varStatus = DMSTAT_FAIL;
1854 			} else if (ino1 != ROOT_INODE) {
1855 				DMLOG_PRINT(DMLVL_ERR,
1856 					    "Parent handle NOT root! (%lld vs %d)\n",
1857 					    ino1, ROOT_INODE);
1858 				varStatus = DMSTAT_FAIL;
1859 			} else if (ino2 != statfs.st_ino) {
1860 				DMLOG_PRINT(DMLVL_ERR,
1861 					    "Entry handle NOT correct! (%lld vs %d)\n",
1862 					    ino2, statfs.st_ino);
1863 				varStatus = DMSTAT_FAIL;
1864 			} else if (strcmp(aname1, DUMMY_FILE) != 0) {
1865 				DMLOG_PRINT(DMLVL_ERR,
1866 					    "Entry name NOT correct! (%s vs %s)\n",
1867 					    aname1, DUMMY_FILE);
1868 				varStatus = DMSTAT_FAIL;
1869 			} else if (dm_handle_cmp(hanp1, hlen1, ahanp1, ahlen1)
1870 				   != 0) {
1871 				DMLOG_PRINT(DMLVL_ERR,
1872 					    "Parent handles NOT same!\n");
1873 				varStatus = DMSTAT_FAIL;
1874 			} else if (strcmp(name1, aname1) != 0) {
1875 				DMLOG_PRINT(DMLVL_ERR,
1876 					    "Entry names NOT same! (%s vs %s)\n",
1877 					    name1, aname1);
1878 				varStatus = DMSTAT_FAIL;
1879 			} else if (amode != statfs.st_mode) {
1880 				DMLOG_PRINT(DMLVL_ERR,
1881 					    "Modes NOT same! (%d vs %d)\n",
1882 					    amode, statfs.st_mode);
1883 				varStatus = DMSTAT_FAIL;
1884 			} else if (aretcode != 0) {
1885 				DMLOG_PRINT(DMLVL_ERR,
1886 					    "Return codes NOT same! (%d vs %d)\n",
1887 					    mode, amode);
1888 				varStatus = DMSTAT_FAIL;
1889 			}
1890 		}
1891 		DMVAR_END(varStatus);
1892 
1893 		/* Variation clean up */
1894 		EVENT_DELIVERY_DELAY;
1895 		rc = close(fd);
1896 		rc |= remove(DummyFile);
1897 		EVENT_DELIVERY_DELAY;
1898 		if (rc == -1) {
1899 			DMLOG_PRINT(DMLVL_DEBUG,
1900 				    "Unable to clean up variation! (errno = %d)\n",
1901 				    errno);
1902 		}
1903 	}
1904 
1905 	/*
1906 	 * TEST    : remove - enabled on directory
1907 	 * EXPECTED: DM_EVENT_POSTREMOVE
1908 	 */
1909 	if (DMVAR_EXEC(FILE_ASYNC_NAMESP_EVENT_BASE + 7)) {
1910 		int fd;
1911 		dm_ino_t ino;
1912 		struct stat statfs;
1913 
1914 		/* Variation set up */
1915 		eventExpected = DM_EVENT_POSTREMOVE;
1916 		eventReceived = DM_EVENT_INVALID;
1917 		eventResponse = DM_RESP_CONTINUE;
1918 		EVENT_DELIVERY_DELAY;
1919 		if ((fd =
1920 		     open(DummyFile, O_RDWR | O_CREAT,
1921 			  DUMMY_FILE_RW_MODE)) == -1) {
1922 			/* No clean up */
1923 		} else if (((rc = close(fd)) == -1) ||
1924 			   ((rc = stat(DummyFile, &statfs)) == -1)) {
1925 			remove(DummyFile);
1926 		}
1927 		if (fd == -1 || rc == -1) {
1928 			DMLOG_PRINT(DMLVL_DEBUG,
1929 				    "Unable to set up variation! (errno = %d)\n",
1930 				    errno);
1931 			DMVAR_SKIP();
1932 		} else {
1933 			/* Variation */
1934 			EVENT_DELIVERY_DELAY;
1935 			DMLOG_PRINT(DMLVL_DEBUG, "remove(%s)\n", DummyFile);
1936 			rc = remove(DummyFile);
1937 			DMLOG_PRINT(DMLVL_DEBUG, "remove(%s) returned %d\n",
1938 				    DummyFile, rc);
1939 			EVENT_DELIVERY_DELAY;
1940 			if ((varStatus =
1941 			     DMVAR_CHKPASSEXP(0, rc, eventExpected,
1942 					      eventReceived)) == DMSTAT_PASS) {
1943 				rc = dm_handle_to_ino(ahanp1, ahlen1, &ino);
1944 				if (rc == -1) {
1945 					DMLOG_PRINT(DMLVL_ERR,
1946 						    "Unable to obtain inode!\n");
1947 					varStatus = DMSTAT_FAIL;
1948 				} else if (ino != ROOT_INODE) {
1949 					DMLOG_PRINT(DMLVL_ERR,
1950 						    "Parent handle NOT root! (%lld vs %d)\n",
1951 						    ino, ROOT_INODE);
1952 					varStatus = DMSTAT_FAIL;
1953 				} else if (strcmp(aname1, DUMMY_FILE) != 0) {
1954 					DMLOG_PRINT(DMLVL_ERR,
1955 						    "Entry name NOT correct! (%s vs %s)\n",
1956 						    aname1, DUMMY_FILE);
1957 					varStatus = DMSTAT_FAIL;
1958 				} else
1959 				    if (dm_handle_cmp
1960 					(hanp1, hlen1, ahanp1, ahlen1) != 0) {
1961 					DMLOG_PRINT(DMLVL_ERR,
1962 						    "Parent handles NOT same!\n");
1963 					varStatus = DMSTAT_FAIL;
1964 				} else if (strcmp(name1, aname1) != 0) {
1965 					DMLOG_PRINT(DMLVL_ERR,
1966 						    "Entry names NOT same! (%s vs %s)\n",
1967 						    name1, aname1);
1968 					varStatus = DMSTAT_FAIL;
1969 				} else if (amode != statfs.st_mode) {
1970 					DMLOG_PRINT(DMLVL_ERR,
1971 						    "Modes NOT same! (%d vs %d)\n",
1972 						    amode, statfs.st_mode);
1973 					varStatus = DMSTAT_FAIL;
1974 				} else if (aretcode != 0) {
1975 					DMLOG_PRINT(DMLVL_ERR,
1976 						    "Return codes NOT same! (%d vs %d)\n",
1977 						    mode, amode);
1978 					varStatus = DMSTAT_FAIL;
1979 				}
1980 			}
1981 			DMVAR_END(varStatus);
1982 
1983 			/* Variation clean up */
1984 		}
1985 	}
1986 
1987 	/*
1988 	 * TEST    : mv - enabled on source and destination directory
1989 	 * EXPECTED: DM_EVENT_POSTRENAME
1990 	 */
1991 	if (DMVAR_EXEC(FILE_ASYNC_NAMESP_EVENT_BASE + 8)) {
1992 		int fd;
1993 		dm_ino_t ino1, ino2;
1994 
1995 		/* Variation set up */
1996 		eventExpected = DM_EVENT_POSTRENAME;
1997 		eventReceived = DM_EVENT_INVALID;
1998 		eventResponse = DM_RESP_CONTINUE;
1999 		sprintf(command, "mv %s %s", DummyFile, DummyFile2);
2000 		EVENT_DELIVERY_DELAY;
2001 		if ((fd =
2002 		     open(DummyFile, O_RDWR | O_CREAT,
2003 			  DUMMY_FILE_RW_MODE)) == -1) {
2004 			/* No clean up */
2005 		} else if ((rc = close(fd)) == -1) {
2006 			remove(DummyFile);
2007 		}
2008 		if (fd == -1 || rc == -1) {
2009 			DMLOG_PRINT(DMLVL_DEBUG,
2010 				    "Unable to set up variation! (errno = %d)\n",
2011 				    errno);
2012 			DMVAR_SKIP();
2013 		} else {
2014 			/* Variation */
2015 			EVENT_DELIVERY_DELAY;
2016 			DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s)\n",
2017 				    DummyFile, DummyFile2);
2018 			rc = system(command);
2019 			DMLOG_PRINT(DMLVL_DEBUG,
2020 				    "system(mv %s %s) returned %d\n", DummyFile,
2021 				    DummyFile2, rc);
2022 			EVENT_DELIVERY_DELAY;
2023 			if ((varStatus =
2024 			     DMVAR_CHKPASSEXP(0, rc, eventExpected,
2025 					      eventReceived)) == DMSTAT_PASS) {
2026 				rc = dm_handle_to_ino(ahanp1, ahlen1, &ino1);
2027 				rc |= dm_handle_to_ino(ahanp2, ahlen2, &ino2);
2028 				if (rc == -1) {
2029 					DMLOG_PRINT(DMLVL_ERR,
2030 						    "Unable to obtain inode!\n");
2031 					varStatus = DMSTAT_FAIL;
2032 				} else if (ino1 != ROOT_INODE) {
2033 					DMLOG_PRINT(DMLVL_ERR,
2034 						    "Old parent handle NOT root! (%lld vs %d)\n",
2035 						    ino1, ROOT_INODE);
2036 					varStatus = DMSTAT_FAIL;
2037 				} else if (ino2 != ROOT_INODE) {
2038 					DMLOG_PRINT(DMLVL_ERR,
2039 						    "New parent handle NOT root! (%lld vs %d)\n",
2040 						    ino2, ROOT_INODE);
2041 					varStatus = DMSTAT_FAIL;
2042 				} else
2043 				    if (dm_handle_cmp
2044 					(ahanp1, ahlen1, ahanp2, ahlen2) != 0) {
2045 					DMLOG_PRINT(DMLVL_ERR,
2046 						    "Old parent handle NOT equal to new parent handle!\n");
2047 					varStatus = DMSTAT_FAIL;
2048 				} else
2049 				    if (dm_handle_cmp
2050 					(hanp1, hlen1, ahanp1, ahlen1) != 0) {
2051 					DMLOG_PRINT(DMLVL_ERR,
2052 						    "Old parent handles NOT same!\n");
2053 					varStatus = DMSTAT_FAIL;
2054 				} else
2055 				    if (dm_handle_cmp
2056 					(hanp2, hlen2, ahanp2, ahlen2) != 0) {
2057 					DMLOG_PRINT(DMLVL_ERR,
2058 						    "New parent handles NOT same!\n");
2059 					varStatus = DMSTAT_FAIL;
2060 				} else if (strcmp(aname1, DUMMY_FILE) != 0) {
2061 					DMLOG_PRINT(DMLVL_ERR,
2062 						    "Old entry name NOT correct! (%s vs %s)\n",
2063 						    name1, DUMMY_FILE);
2064 					varStatus = DMSTAT_FAIL;
2065 				} else if (strcmp(aname2, DUMMY_FILE2) != 0) {
2066 					DMLOG_PRINT(DMLVL_ERR,
2067 						    "New entry name NOT correct! (%s vs %s)\n",
2068 						    name2, DUMMY_FILE2);
2069 					varStatus = DMSTAT_FAIL;
2070 				} else if (strcmp(name1, aname1) != 0) {
2071 					DMLOG_PRINT(DMLVL_ERR,
2072 						    "Old entry name NOT same! (%s vs %s)\n",
2073 						    name1, aname1);
2074 					varStatus = DMSTAT_FAIL;
2075 				} else if (strcmp(name2, aname2) != 0) {
2076 					DMLOG_PRINT(DMLVL_ERR,
2077 						    "New entry name NOT same! (%s vs %s)\n",
2078 						    name2, aname2);
2079 					varStatus = DMSTAT_FAIL;
2080 				} else if (aretcode != 0) {
2081 					DMLOG_PRINT(DMLVL_ERR,
2082 						    "Return codes NOT same! (%d vs %d)\n",
2083 						    mode, amode);
2084 					varStatus = DMSTAT_FAIL;
2085 				}
2086 			}
2087 			DMVAR_END(varStatus);
2088 
2089 			/* Variation clean up */
2090 			EVENT_DELIVERY_DELAY;
2091 			rc = remove(DummyFile2);
2092 			EVENT_DELIVERY_DELAY;
2093 			if (rc == -1) {
2094 				DMLOG_PRINT(DMLVL_DEBUG,
2095 					    "Unable to clean up variation! (errno = %d)\n",
2096 					    errno);
2097 			}
2098 		}
2099 	}
2100 
2101 	/*
2102 	 * TEST    : mv - enabled on source directory
2103 	 * EXPECTED: DM_EVENT_POSTRENAME
2104 	 */
2105 	if (DMVAR_EXEC(FILE_ASYNC_NAMESP_EVENT_BASE + 9)) {
2106 		int fd;
2107 		void *dhanp;
2108 		size_t dhlen;
2109 		dm_ino_t ino1, ino2, dino;
2110 
2111 		/* Variation set up */
2112 		eventExpected = DM_EVENT_POSTRENAME;
2113 		eventReceived = DM_EVENT_INVALID;
2114 		eventResponse = DM_RESP_CONTINUE;
2115 		sprintf(command, "mv %s %s", DummyFile, DummySubdir2File);
2116 		EVENT_DELIVERY_DELAY;
2117 		if ((fd =
2118 		     open(DummyFile, O_RDWR | O_CREAT,
2119 			  DUMMY_FILE_RW_MODE)) == -1) {
2120 			/* No clean up */
2121 		} else if (((rc = close(fd)) == -1) ||
2122 			   ((rc =
2123 			     mkdir(DummySubdir2, DUMMY_DIR_RW_MODE)) == -1)) {
2124 			remove(DummyFile);
2125 		} else
2126 		    if ((rc =
2127 			 dm_path_to_handle(DummySubdir2, &dhanp,
2128 					   &dhlen)) == -1) {
2129 			rmdir(DummySubdir2);
2130 			remove(DummyFile);
2131 		} else if ((rc = dm_handle_to_ino(dhanp, dhlen, &dino)) == -1) {
2132 			dm_handle_free(dhanp, dhlen);
2133 			rmdir(DummySubdir2);
2134 			remove(DummyFile);
2135 		}
2136 		if (fd == -1 || rc == -1) {
2137 			DMLOG_PRINT(DMLVL_DEBUG,
2138 				    "Unable to set up variation! (errno = %d)\n",
2139 				    errno);
2140 			DMVAR_SKIP();
2141 		} else {
2142 			/* Variation */
2143 			EVENT_DELIVERY_DELAY;
2144 			DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s)\n",
2145 				    DummyFile, DummySubdir2File);
2146 			rc = system(command);
2147 			DMLOG_PRINT(DMLVL_DEBUG,
2148 				    "system(mv %s %s) returned %d\n", DummyFile,
2149 				    DummySubdir2File, rc);
2150 			EVENT_DELIVERY_DELAY;
2151 			if ((varStatus =
2152 			     DMVAR_CHKPASSEXP(0, rc, eventExpected,
2153 					      eventReceived)) == DMSTAT_PASS) {
2154 				rc = dm_handle_to_ino(ahanp1, ahlen1, &ino1);
2155 				rc |= dm_handle_to_ino(ahanp2, ahlen2, &ino2);
2156 				if (rc == -1) {
2157 					DMLOG_PRINT(DMLVL_ERR,
2158 						    "Unable to obtain inode!\n");
2159 					varStatus = DMSTAT_FAIL;
2160 				} else if (ino1 != ROOT_INODE) {
2161 					DMLOG_PRINT(DMLVL_ERR,
2162 						    "Old parent handle NOT root! (%lld vs %d)\n",
2163 						    ino1, ROOT_INODE);
2164 					varStatus = DMSTAT_FAIL;
2165 				} else if (ino2 != dino) {
2166 					DMLOG_PRINT(DMLVL_ERR,
2167 						    "New parent handle NOT correct! (%lld vs %d)\n",
2168 						    ino2, dino);
2169 					varStatus = DMSTAT_FAIL;
2170 				} else
2171 				    if (dm_handle_cmp
2172 					(hanp1, hlen1, ahanp1, ahlen1) != 0) {
2173 					DMLOG_PRINT(DMLVL_ERR,
2174 						    "Old parent handles NOT same!\n");
2175 					varStatus = DMSTAT_FAIL;
2176 				} else
2177 				    if (dm_handle_cmp
2178 					(hanp2, hlen2, ahanp2, ahlen2) != 0) {
2179 					DMLOG_PRINT(DMLVL_ERR,
2180 						    "New parent handles NOT same!\n");
2181 					varStatus = DMSTAT_FAIL;
2182 				} else if (strcmp(aname1, DUMMY_FILE) != 0) {
2183 					DMLOG_PRINT(DMLVL_ERR,
2184 						    "Old entry name NOT correct! (%s vs %s)\n",
2185 						    name1, DUMMY_FILE);
2186 					varStatus = DMSTAT_FAIL;
2187 				} else if (strcmp(aname2, DUMMY_FILE) != 0) {
2188 					DMLOG_PRINT(DMLVL_ERR,
2189 						    "New entry name NOT correct! (%s vs %s)\n",
2190 						    name2, DUMMY_FILE);
2191 					varStatus = DMSTAT_FAIL;
2192 				} else if (strcmp(name1, aname1) != 0) {
2193 					DMLOG_PRINT(DMLVL_ERR,
2194 						    "Old entry name NOT same! (%s vs %s)\n",
2195 						    name1, aname1);
2196 					varStatus = DMSTAT_FAIL;
2197 				} else if (strcmp(name2, aname2) != 0) {
2198 					DMLOG_PRINT(DMLVL_ERR,
2199 						    "New entry name NOT same! (%s vs %s)\n",
2200 						    name2, aname2);
2201 					varStatus = DMSTAT_FAIL;
2202 				} else if (aretcode != 0) {
2203 					DMLOG_PRINT(DMLVL_ERR,
2204 						    "Return codes NOT same! (%d vs %d)\n",
2205 						    mode, amode);
2206 					varStatus = DMSTAT_FAIL;
2207 				}
2208 			}
2209 			DMVAR_END(varStatus);
2210 
2211 			/* Variation clean up */
2212 			EVENT_DELIVERY_DELAY;
2213 			rc = remove(DummySubdir2File);
2214 			rc |= rmdir(DummySubdir2);
2215 			EVENT_DELIVERY_DELAY;
2216 			if (rc == -1) {
2217 				DMLOG_PRINT(DMLVL_DEBUG,
2218 					    "Unable to clean up variation! (errno = %d)\n",
2219 					    errno);
2220 			}
2221 		}
2222 	}
2223 
2224 	/*
2225 	 * TEST    : mv - enabled on destination directory
2226 	 * EXPECTED: DM_EVENT_POSTRENAME
2227 	 */
2228 	if (DMVAR_EXEC(FILE_ASYNC_NAMESP_EVENT_BASE + 10)) {
2229 		int fd;
2230 		void *dhanp;
2231 		size_t dhlen;
2232 		dm_ino_t ino1, ino2, dino;
2233 
2234 		/* Variation set up */
2235 		eventExpected = DM_EVENT_POSTRENAME;
2236 		eventReceived = DM_EVENT_INVALID;
2237 		eventResponse = DM_RESP_CONTINUE;
2238 		sprintf(command, "mv %s %s", DummySubdir2File, DummyFile);
2239 		EVENT_DELIVERY_DELAY;
2240 		if ((rc = mkdir(DummySubdir2, DUMMY_DIR_RW_MODE)) == -1) {
2241 			/* No clean up */
2242 		} else
2243 		    if ((fd =
2244 			 open(DummySubdir2File, O_RDWR | O_CREAT,
2245 			      DUMMY_FILE_RW_MODE)) == -1) {
2246 			rmdir(DummySubdir2);
2247 		} else if ((rc = close(fd)) == -1) {
2248 			remove(DummySubdir2File);
2249 			rmdir(DummySubdir2);
2250 		} else
2251 		    if ((rc =
2252 			 dm_path_to_handle(DummySubdir2, &dhanp,
2253 					   &dhlen)) == -1) {
2254 			remove(DummySubdir2File);
2255 			rmdir(DummySubdir2);
2256 		} else if ((rc = dm_handle_to_ino(dhanp, dhlen, &dino)) == -1) {
2257 			dm_handle_free(dhanp, dhlen);
2258 			remove(DummySubdir2File);
2259 			rmdir(DummySubdir2);
2260 		}
2261 		if (fd == -1 || rc == -1) {
2262 			DMLOG_PRINT(DMLVL_DEBUG,
2263 				    "Unable to set up variation! (errno = %d)\n",
2264 				    errno);
2265 			DMVAR_SKIP();
2266 		} else {
2267 			/* Variation */
2268 			EVENT_DELIVERY_DELAY;
2269 			DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s)\n",
2270 				    DummySubdir2File, DummyFile);
2271 			rc = system(command);
2272 			DMLOG_PRINT(DMLVL_DEBUG,
2273 				    "system(mv %s %s) returned %d\n",
2274 				    DummySubdir2File, DummyFile, rc);
2275 			EVENT_DELIVERY_DELAY;
2276 			if ((varStatus =
2277 			     DMVAR_CHKPASSEXP(0, rc, eventExpected,
2278 					      eventReceived)) == DMSTAT_PASS) {
2279 				rc = dm_handle_to_ino(ahanp1, ahlen1, &ino1);
2280 				rc |= dm_handle_to_ino(ahanp2, ahlen2, &ino2);
2281 				if (rc == -1) {
2282 					DMLOG_PRINT(DMLVL_ERR,
2283 						    "Unable to obtain inode!\n");
2284 					varStatus = DMSTAT_FAIL;
2285 				} else if (ino1 != dino) {
2286 					DMLOG_PRINT(DMLVL_ERR,
2287 						    "Old parent handle NOT correct! (%lld vs %d)\n",
2288 						    ino1, dino);
2289 					varStatus = DMSTAT_FAIL;
2290 				} else if (ino2 != ROOT_INODE) {
2291 					DMLOG_PRINT(DMLVL_ERR,
2292 						    "New parent handle NOT root! (%lld vs %d)\n",
2293 						    ino2, ROOT_INODE);
2294 					varStatus = DMSTAT_FAIL;
2295 				} else
2296 				    if (dm_handle_cmp
2297 					(hanp1, hlen1, ahanp1, ahlen1) != 0) {
2298 					DMLOG_PRINT(DMLVL_ERR,
2299 						    "Old parent handles NOT same!\n");
2300 					varStatus = DMSTAT_FAIL;
2301 				} else
2302 				    if (dm_handle_cmp
2303 					(hanp2, hlen2, ahanp2, ahlen2) != 0) {
2304 					DMLOG_PRINT(DMLVL_ERR,
2305 						    "New parent handles NOT same!\n");
2306 					varStatus = DMSTAT_FAIL;
2307 				} else if (strcmp(aname1, DUMMY_FILE) != 0) {
2308 					DMLOG_PRINT(DMLVL_ERR,
2309 						    "Old entry name NOT correct! (%s vs %s)\n",
2310 						    name1, DUMMY_FILE);
2311 					varStatus = DMSTAT_FAIL;
2312 				} else if (strcmp(aname2, DUMMY_FILE) != 0) {
2313 					DMLOG_PRINT(DMLVL_ERR,
2314 						    "New entry name NOT correct! (%s vs %s)\n",
2315 						    name2, DUMMY_FILE);
2316 					varStatus = DMSTAT_FAIL;
2317 				} else if (strcmp(name1, aname1) != 0) {
2318 					DMLOG_PRINT(DMLVL_ERR,
2319 						    "Old entry name NOT same! (%s vs %s)\n",
2320 						    name1, aname1);
2321 					varStatus = DMSTAT_FAIL;
2322 				} else if (strcmp(name2, aname2) != 0) {
2323 					DMLOG_PRINT(DMLVL_ERR,
2324 						    "New entry name NOT same! (%s vs %s)\n",
2325 						    name2, aname2);
2326 					varStatus = DMSTAT_FAIL;
2327 				} else if (aretcode != 0) {
2328 					DMLOG_PRINT(DMLVL_ERR,
2329 						    "Return codes NOT same! (%d vs %d)\n",
2330 						    mode, amode);
2331 					varStatus = DMSTAT_FAIL;
2332 				}
2333 			}
2334 			DMVAR_END(varStatus);
2335 
2336 			/* Variation clean up */
2337 			EVENT_DELIVERY_DELAY;
2338 			rc = remove(DummyFile);
2339 			rc |= rmdir(DummySubdir2);
2340 			EVENT_DELIVERY_DELAY;
2341 			if (rc == -1) {
2342 				DMLOG_PRINT(DMLVL_DEBUG,
2343 					    "Unable to clean up variation! (errno = %d)\n",
2344 					    errno);
2345 			}
2346 		}
2347 	}
2348 
2349 	/*
2350 	 * TEST    : symlink - enabled on directory
2351 	 * EXPECTED: DM_EVENT_POSTSYMLINK
2352 	 */
2353 	if (DMVAR_EXEC(FILE_ASYNC_NAMESP_EVENT_BASE + 11)) {
2354 		int fd;
2355 		dm_ino_t ino1, ino2;
2356 
2357 		/* Variation set up */
2358 		eventExpected = DM_EVENT_POSTSYMLINK;
2359 		eventReceived = DM_EVENT_INVALID;
2360 		eventResponse = DM_RESP_CONTINUE;
2361 		EVENT_DELIVERY_DELAY;
2362 		if ((fd =
2363 		     open(DummyFile, O_RDWR | O_CREAT,
2364 			  DUMMY_FILE_RW_MODE)) == -1) {
2365 			/* No clean up */
2366 		} else if ((rc = close(fd)) == -1) {
2367 			remove(DummyFile);
2368 		}
2369 		if (fd == -1 || rc == -1) {
2370 			DMLOG_PRINT(DMLVL_DEBUG,
2371 				    "Unable to set up variation! (errno = %d)\n",
2372 				    errno);
2373 			DMVAR_SKIP();
2374 		} else {
2375 			/* Variation */
2376 			EVENT_DELIVERY_DELAY;
2377 			DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s)\n", DummyFile,
2378 				    DummyLink);
2379 			rc = symlink(DummyFile, DummyLink);
2380 			DMLOG_PRINT(DMLVL_DEBUG,
2381 				    "symlink(%s, %s) returned %d\n", DummyFile,
2382 				    DummyLink, rc);
2383 			EVENT_DELIVERY_DELAY;
2384 			if ((varStatus =
2385 			     DMVAR_CHKPASSEXP(0, rc, eventExpected,
2386 					      eventReceived)) == DMSTAT_PASS) {
2387 				struct stat statfs;
2388 
2389 				rc = dm_handle_to_ino(ahanp1, ahlen1, &ino1);
2390 				rc |= dm_handle_to_ino(ahanp2, ahlen2, &ino2);
2391 				rc |= lstat(DummyLink, &statfs);
2392 				if (rc == -1) {
2393 					DMLOG_PRINT(DMLVL_ERR,
2394 						    "Unable to obtain inode!\n");
2395 					varStatus = DMSTAT_FAIL;
2396 				} else if (ino1 != ROOT_INODE) {
2397 					DMLOG_PRINT(DMLVL_ERR,
2398 						    "Parent handle NOT root! (%lld vs %d)\n",
2399 						    ino1, ROOT_INODE);
2400 					varStatus = DMSTAT_FAIL;
2401 				} else if (ino2 != statfs.st_ino) {
2402 					DMLOG_PRINT(DMLVL_ERR,
2403 						    "Entry handle NOT correct! (%lld vs %d)\n",
2404 						    ino2, statfs.st_ino);
2405 					varStatus = DMSTAT_FAIL;
2406 				} else
2407 				    if (dm_handle_cmp
2408 					(hanp1, hlen1, ahanp1, ahlen1) != 0) {
2409 					DMLOG_PRINT(DMLVL_ERR,
2410 						    "Parent handles NOT same!\n");
2411 					varStatus = DMSTAT_FAIL;
2412 				} else if (strcmp(aname1, DUMMY_LINK) != 0) {
2413 					DMLOG_PRINT(DMLVL_ERR,
2414 						    "Symlink entry name NOT correct! (%s vs %s)\n",
2415 						    aname1, DUMMY_LINK);
2416 					varStatus = DMSTAT_FAIL;
2417 				} else if (strcmp(aname2, DummyFile) != 0) {
2418 					DMLOG_PRINT(DMLVL_ERR,
2419 						    "Symlink contents NOT correct! (%s vs %s)\n",
2420 						    aname2, DummyFile);
2421 					varStatus = DMSTAT_FAIL;
2422 				} else if (strcmp(name1, aname1) != 0) {
2423 					DMLOG_PRINT(DMLVL_ERR,
2424 						    "Symlink entry names NOT same! (%s vs %s)\n",
2425 						    name1, aname1);
2426 					varStatus = DMSTAT_FAIL;
2427 				} else if (strcmp(name2, aname2) != 0) {
2428 					DMLOG_PRINT(DMLVL_ERR,
2429 						    "Symlink contents NOT same! (%s vs %s)\n",
2430 						    name2, aname2);
2431 					varStatus = DMSTAT_FAIL;
2432 				} else if (aretcode != 0) {
2433 					DMLOG_PRINT(DMLVL_ERR,
2434 						    "Return codes NOT same! (%d vs %d)\n",
2435 						    mode, amode);
2436 					varStatus = DMSTAT_FAIL;
2437 				}
2438 			}
2439 			DMVAR_END(varStatus);
2440 
2441 			/* Variation clean up */
2442 			EVENT_DELIVERY_DELAY;
2443 			rc = unlink(DummyLink);
2444 			rc |= remove(DummyFile);
2445 			EVENT_DELIVERY_DELAY;
2446 			if (rc == -1) {
2447 				DMLOG_PRINT(DMLVL_DEBUG,
2448 					    "Unable to clean up variation! (errno = %d)\n",
2449 					    errno);
2450 			}
2451 		}
2452 	}
2453 
2454 	/*
2455 	 * TEST    : link - enabled on directory
2456 	 * EXPECTED: DM_EVENT_POSTLINK
2457 	 */
2458 	if (DMVAR_EXEC(FILE_ASYNC_NAMESP_EVENT_BASE + 12)) {
2459 		dm_ino_t ino, ino1, ino2;
2460 		void *hanp;
2461 		size_t hlen;
2462 		int fd;
2463 
2464 		/* Variation set up */
2465 		eventExpected = DM_EVENT_POSTLINK;
2466 		eventReceived = DM_EVENT_INVALID;
2467 		eventResponse = DM_RESP_CONTINUE;
2468 		EVENT_DELIVERY_DELAY;
2469 		if ((fd =
2470 		     open(DummyFile, O_RDWR | O_CREAT,
2471 			  DUMMY_FILE_RW_MODE)) == -1) {
2472 			/* No clean up */
2473 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
2474 			close(fd);
2475 			remove(DummyFile);
2476 		}
2477 		if (fd == -1 || rc == -1) {
2478 			DMLOG_PRINT(DMLVL_DEBUG,
2479 				    "Unable to set up variation! (errno = %d)\n",
2480 				    errno);
2481 			DMVAR_SKIP();
2482 		} else {
2483 			/* Variation */
2484 			EVENT_DELIVERY_DELAY;
2485 			DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s)\n", DummyFile,
2486 				    DummyLink);
2487 			rc = link(DummyFile, DummyLink);
2488 			DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s) returned %d\n",
2489 				    DummyFile, DummyLink, rc);
2490 			EVENT_DELIVERY_DELAY;
2491 			if ((varStatus =
2492 			     DMVAR_CHKPASSEXP(0, rc, eventExpected,
2493 					      eventReceived)) == DMSTAT_PASS) {
2494 				rc = dm_handle_to_ino(hanp1, hlen1, &ino1);
2495 				rc |= dm_handle_to_ino(hanp2, hlen2, &ino2);
2496 				rc |= dm_handle_to_ino(hanp, hlen, &ino);
2497 				if (rc == -1) {
2498 					DMLOG_PRINT(DMLVL_ERR,
2499 						    "Unable to obtain inode!\n");
2500 					varStatus = DMSTAT_FAIL;
2501 				} else if (ino1 != ROOT_INODE) {
2502 					DMLOG_PRINT(DMLVL_ERR,
2503 						    "Parent handle NOT root! (%d vs %d)\n",
2504 						    ino1, ROOT_INODE);
2505 					varStatus = DMSTAT_FAIL;
2506 				} else if (ino2 != ino) {
2507 					DMLOG_PRINT(DMLVL_ERR,
2508 						    "Source link handle NOT correct! (%d vs %d)\n",
2509 						    ino2, ino);
2510 					varStatus = DMSTAT_FAIL;
2511 				} else if (strcmp(name1, DUMMY_LINK) != 0) {
2512 					DMLOG_PRINT(DMLVL_ERR,
2513 						    "Target entry name NOT correct! (%s vs %s)\n",
2514 						    name1, DUMMY_LINK);
2515 					varStatus = DMSTAT_FAIL;
2516 				}
2517 			}
2518 			DMVAR_END(varStatus);
2519 
2520 			/* Variation clean up */
2521 			EVENT_DELIVERY_DELAY;
2522 			rc = close(fd);
2523 			rc |= remove(DummyFile);
2524 			rc |= remove(DummyLink);
2525 			if (rc == -1) {
2526 				DMLOG_PRINT(DMLVL_DEBUG,
2527 					    "Unable to clean up variation! (errno = %d)\n",
2528 					    errno);
2529 			}
2530 			dm_handle_free(hanp, hlen);
2531 		}
2532 	}
2533 
2534 	/* Wait for all pending messages to be handled */
2535 	EVENT_DELIVERY_DELAY_LOOP;
2536 
2537 	/*
2538 	 *  Last batch of tests will be with events disabled, so clear events
2539 	 *  on dir
2540 	 */
2541 	DMEV_ZERO(events);
2542 	rc = dm_set_eventlist(sid, dhanp, dhlen, DM_NO_TOKEN, &events,
2543 			      DM_EVENT_MAX);
2544 	if (rc == -1) {
2545 		DMLOG_PRINT(DMLVL_ERR,
2546 			    "dm_set_eventlist(dir) failed! (rc = %d, errno = %d)\n",
2547 			    rc, errno);
2548 		dm_destroy_session(sid);
2549 		DM_EXIT();
2550 	}
2551 
2552 	/*
2553 	 * TEST    : mkdir - disabled
2554 	 * EXPECTED: no event
2555 	 */
2556 	if (DMVAR_EXEC(DIR_ASYNC_NAMESP_EVENT_BASE + 13)) {
2557 
2558 		/* Variation set up */
2559 		eventExpected = DM_EVENT_INVALID;
2560 		eventReceived = DM_EVENT_INVALID;
2561 		eventResponse = DM_RESP_CONTINUE;
2562 
2563 		/* Variation */
2564 		EVENT_DELIVERY_DELAY;
2565 		DMLOG_PRINT(DMLVL_DEBUG, "mkdir(%s)\n", DummySubdir);
2566 		rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE);
2567 		DMLOG_PRINT(DMLVL_DEBUG, "mkdir(%s) returned %d\n", DummySubdir,
2568 			    rc);
2569 		EVENT_DELIVERY_DELAY;
2570 		DMVAR_END(DMVAR_CHKPASSEXP
2571 			  (0, rc, eventExpected, eventReceived));
2572 
2573 		/* Variation clean up */
2574 		EVENT_DELIVERY_DELAY;
2575 		rc = rmdir(DummySubdir);
2576 		EVENT_DELIVERY_DELAY;
2577 		if (rc == -1) {
2578 			DMLOG_PRINT(DMLVL_DEBUG,
2579 				    "Unable to clean up variation! (errno = %d)\n",
2580 				    errno);
2581 		}
2582 	}
2583 
2584 	/*
2585 	 * TEST    : rmdir - disabled
2586 	 * EXPECTED: no event
2587 	 */
2588 	if (DMVAR_EXEC(DIR_ASYNC_NAMESP_EVENT_BASE + 14)) {
2589 
2590 		/* Variation set up */
2591 		eventExpected = DM_EVENT_INVALID;
2592 		eventReceived = DM_EVENT_INVALID;
2593 		eventResponse = DM_RESP_CONTINUE;
2594 		EVENT_DELIVERY_DELAY;
2595 		rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE);
2596 		if (rc == -1) {
2597 			DMLOG_PRINT(DMLVL_DEBUG,
2598 				    "Unable to set up variation! (errno = %d)\n",
2599 				    errno);
2600 			DMVAR_SKIP();
2601 		} else {
2602 			/* Variation */
2603 			EVENT_DELIVERY_DELAY;
2604 			DMLOG_PRINT(DMLVL_DEBUG, "rmdir(%s)\n", DummySubdir);
2605 			rc = rmdir(DummySubdir);
2606 			DMLOG_PRINT(DMLVL_DEBUG, "rmdir(%s) returned %d\n",
2607 				    DummySubdir, rc);
2608 			EVENT_DELIVERY_DELAY;
2609 			DMVAR_END(DMVAR_CHKPASSEXP
2610 				  (0, rc, eventExpected, eventReceived));
2611 
2612 			/* Variation clean up */
2613 		}
2614 	}
2615 
2616 	/*
2617 	 * TEST    : mv - disabled
2618 	 * EXPECTED: no event
2619 	 */
2620 	if (DMVAR_EXEC(DIR_ASYNC_NAMESP_EVENT_BASE + 15)) {
2621 
2622 		/* Variation set up */
2623 		eventExpected = DM_EVENT_INVALID;
2624 		eventReceived = DM_EVENT_INVALID;
2625 		eventResponse = DM_RESP_CONTINUE;
2626 		sprintf(command, "mv %s %s", DummySubdir, DummySubdir2);
2627 		EVENT_DELIVERY_DELAY;
2628 		rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE);
2629 		if (rc == -1) {
2630 			DMLOG_PRINT(DMLVL_DEBUG,
2631 				    "Unable to set up variation! (errno = %d)\n",
2632 				    errno);
2633 			DMVAR_SKIP();
2634 		} else {
2635 			/* Variation */
2636 			EVENT_DELIVERY_DELAY;
2637 			DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s)\n",
2638 				    DummySubdir, DummySubdir2);
2639 			rc = system(command);
2640 			DMLOG_PRINT(DMLVL_DEBUG,
2641 				    "system(mv %s %s) returned %d\n",
2642 				    DummySubdir, DummySubdir2, rc);
2643 			EVENT_DELIVERY_DELAY;
2644 			DMVAR_END(DMVAR_CHKPASSEXP
2645 				  (0, rc, eventExpected, eventReceived));
2646 
2647 			/* Variation clean up */
2648 			EVENT_DELIVERY_DELAY;
2649 			rc = rmdir(DummySubdir2);
2650 			EVENT_DELIVERY_DELAY;
2651 			if (rc == -1) {
2652 				DMLOG_PRINT(DMLVL_DEBUG,
2653 					    "Unable to clean up variation! (errno = %d)\n",
2654 					    errno);
2655 			}
2656 		}
2657 	}
2658 
2659 	/*
2660 	 * TEST    : symlink - disabled
2661 	 * EXPECTED: no event
2662 	 */
2663 	if (DMVAR_EXEC(DIR_ASYNC_NAMESP_EVENT_BASE + 16)) {
2664 
2665 		/* Variation set up */
2666 		eventExpected = DM_EVENT_INVALID;
2667 		eventReceived = DM_EVENT_INVALID;
2668 		eventResponse = DM_RESP_CONTINUE;
2669 		EVENT_DELIVERY_DELAY;
2670 		rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE);
2671 		if (rc == -1) {
2672 			DMLOG_PRINT(DMLVL_DEBUG,
2673 				    "Unable to set up variation! (errno = %d)\n",
2674 				    errno);
2675 			DMVAR_SKIP();
2676 		} else {
2677 			/* Variation */
2678 			EVENT_DELIVERY_DELAY;
2679 			DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s)\n",
2680 				    DummySubdir, DummySubdir2);
2681 			rc = symlink(DummySubdir, DummySubdir2);
2682 			DMLOG_PRINT(DMLVL_DEBUG,
2683 				    "symlink(%s, %s) returned %d\n",
2684 				    DummySubdir, DummySubdir2, rc);
2685 			EVENT_DELIVERY_DELAY;
2686 			DMVAR_END(DMVAR_CHKPASSEXP
2687 				  (0, rc, eventExpected, eventReceived));
2688 
2689 			/* Variation clean up */
2690 			EVENT_DELIVERY_DELAY;
2691 			rc = unlink(DummySubdir2);
2692 			rc |= rmdir(DummySubdir);
2693 			EVENT_DELIVERY_DELAY;
2694 			if (rc == -1) {
2695 				DMLOG_PRINT(DMLVL_DEBUG,
2696 					    "Unable to clean up variation! (errno = %d)\n",
2697 					    errno);
2698 			}
2699 		}
2700 	}
2701 
2702 	/*
2703 	 * TEST    : link - disabled
2704 	 * EXPECTED: no event
2705 	 */
2706 	if (DMVAR_EXEC(DIR_ASYNC_NAMESP_EVENT_BASE + 17)) {
2707 #ifdef DIRECTORY_LINKS
2708 		void *hanp;
2709 		size_t hlen;
2710 
2711 		/* Variation set up */
2712 		eventExpected = DM_EVENT_INVALID;
2713 		eventReceived = DM_EVENT_INVALID;
2714 		eventResponse = DM_RESP_CONTINUE;
2715 		EVENT_DELIVERY_DELAY;
2716 		rc = mkdir(DummySubdir, DUMMY_DIR_RW_MODE);
2717 		if (rc == -1) {
2718 			DMLOG_PRINT(DMLVL_DEBUG,
2719 				    "Unable to set up variation! (errno = %d)\n",
2720 				    errno);
2721 			DMVAR_SKIP();
2722 		} else {
2723 			/* Variation */
2724 			EVENT_DELIVERY_DELAY;
2725 			DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s)\n", DummySubdir,
2726 				    DummyLink);
2727 			rc = link(DummySubdir, DummyLink);
2728 			DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s) returned %d\n",
2729 				    DummySubdir, DummyLink, rc);
2730 			EVENT_DELIVERY_DELAY;
2731 			DMVAR_END(DMVAR_CHKPASSEXP
2732 				  (0, rc, eventExpected, eventReceived));
2733 
2734 			/* Variation clean up */
2735 			EVENT_DELIVERY_DELAY;
2736 			rc = rmdir(DummySubdir);
2737 			rc |= unlink(DummyLink);
2738 			if (rc == -1) {
2739 				DMLOG_PRINT(DMLVL_DEBUG,
2740 					    "Unable to clean up variation! (errno = %d)\n",
2741 					    errno);
2742 			}
2743 			dm_handle_free(hanp, hlen);
2744 		}
2745 #else
2746 		DMLOG_PRINT(DMLVL_WARN,
2747 			    "Test case not built with DIRECTORY_LINKS defined\n");
2748 		DMVAR_SKIP();
2749 #endif
2750 	}
2751 
2752 	/*
2753 	 * TEST    : open - disabled
2754 	 * EXPECTED: no event
2755 	 */
2756 	if (DMVAR_EXEC(FILE_ASYNC_NAMESP_EVENT_BASE + 13)) {
2757 		int fd;
2758 
2759 		/* Variation set up */
2760 		eventExpected = DM_EVENT_INVALID;
2761 		eventReceived = DM_EVENT_INVALID;
2762 		eventResponse = DM_RESP_CONTINUE;
2763 
2764 		/* Variation */
2765 		EVENT_DELIVERY_DELAY;
2766 		DMLOG_PRINT(DMLVL_DEBUG, "open(%s)\n", DummyFile);
2767 		fd = open(DummyFile, O_RDWR | O_CREAT, DUMMY_FILE_RW_MODE);
2768 		DMLOG_PRINT(DMLVL_DEBUG, "open(%s) returned %d\n", DummyFile,
2769 			    rc);
2770 		rc = (fd == -1) ? -1 : 0;
2771 		EVENT_DELIVERY_DELAY;
2772 		DMVAR_END(DMVAR_CHKPASSEXP
2773 			  (0, rc, eventExpected, eventReceived));
2774 
2775 		/* Variation clean up */
2776 		EVENT_DELIVERY_DELAY;
2777 		rc = close(fd);
2778 		rc |= remove(DummyFile);
2779 		EVENT_DELIVERY_DELAY;
2780 		if (rc == -1) {
2781 			DMLOG_PRINT(DMLVL_DEBUG,
2782 				    "Unable to clean up variation! (errno = %d)\n",
2783 				    errno);
2784 		}
2785 	}
2786 
2787 	/*
2788 	 * TEST    : remove - disabled
2789 	 * EXPECTED: no event
2790 	 */
2791 	if (DMVAR_EXEC(FILE_ASYNC_NAMESP_EVENT_BASE + 14)) {
2792 		int fd;
2793 
2794 		/* Variation set up */
2795 		eventExpected = DM_EVENT_INVALID;
2796 		eventReceived = DM_EVENT_INVALID;
2797 		eventResponse = DM_RESP_CONTINUE;
2798 		EVENT_DELIVERY_DELAY;
2799 		if ((fd =
2800 		     open(DummyFile, O_RDWR | O_CREAT,
2801 			  DUMMY_FILE_RW_MODE)) == -1) {
2802 			/* No clean up */
2803 		} else if ((rc = close(fd)) == -1) {
2804 			remove(DummyFile);
2805 		}
2806 		if (fd == -1 || rc == -1) {
2807 			DMLOG_PRINT(DMLVL_DEBUG,
2808 				    "Unable to set up variation! (errno = %d)\n",
2809 				    errno);
2810 			DMVAR_SKIP();
2811 		} else {
2812 			/* Variation */
2813 			EVENT_DELIVERY_DELAY;
2814 			DMLOG_PRINT(DMLVL_DEBUG, "remove(%s)\n", DummyFile);
2815 			rc = remove(DummyFile);
2816 			DMLOG_PRINT(DMLVL_DEBUG, "remove(%s) returned %d\n",
2817 				    DummyFile, rc);
2818 			EVENT_DELIVERY_DELAY;
2819 			DMVAR_END(DMVAR_CHKPASSEXP
2820 				  (0, rc, eventExpected, eventReceived));
2821 
2822 			/* Variation clean up */
2823 		}
2824 	}
2825 
2826 	/*
2827 	 * TEST    : mv - disabled
2828 	 * EXPECTED: no event
2829 	 */
2830 	if (DMVAR_EXEC(FILE_ASYNC_NAMESP_EVENT_BASE + 15)) {
2831 		int fd;
2832 
2833 		/* Variation set up */
2834 		eventExpected = DM_EVENT_INVALID;
2835 		eventReceived = DM_EVENT_INVALID;
2836 		eventResponse = DM_RESP_CONTINUE;
2837 		sprintf(command, "mv %s %s", DummyFile, DummyFile2);
2838 		EVENT_DELIVERY_DELAY;
2839 		if ((fd =
2840 		     open(DummyFile, O_RDWR | O_CREAT,
2841 			  DUMMY_FILE_RW_MODE)) == -1) {
2842 			/* No clean up */
2843 		} else if ((rc = close(fd)) == -1) {
2844 			remove(DummyFile);
2845 		}
2846 		if (fd == -1 || rc == -1) {
2847 			DMLOG_PRINT(DMLVL_DEBUG,
2848 				    "Unable to set up variation! (errno = %d)\n",
2849 				    errno);
2850 			DMVAR_SKIP();
2851 		} else {
2852 			/* Variation */
2853 			EVENT_DELIVERY_DELAY;
2854 			DMLOG_PRINT(DMLVL_DEBUG, "system(mv %s %s)\n",
2855 				    DummyFile, DummyFile2);
2856 			rc = system(command);
2857 			DMLOG_PRINT(DMLVL_DEBUG,
2858 				    "system(mv %s %s) returned %d\n", DummyFile,
2859 				    DummyFile2, rc);
2860 			EVENT_DELIVERY_DELAY;
2861 			DMVAR_END(DMVAR_CHKPASSEXP
2862 				  (0, rc, eventExpected, eventReceived));
2863 
2864 			/* Variation clean up */
2865 			EVENT_DELIVERY_DELAY;
2866 			rc = remove(DummyFile2);
2867 			EVENT_DELIVERY_DELAY;
2868 			if (rc == -1) {
2869 				DMLOG_PRINT(DMLVL_DEBUG,
2870 					    "Unable to clean up variation! (errno = %d)\n",
2871 					    errno);
2872 			}
2873 		}
2874 	}
2875 
2876 	/*
2877 	 * TEST    : symlink - disabled
2878 	 * EXPECTED: no event
2879 	 */
2880 	if (DMVAR_EXEC(FILE_ASYNC_NAMESP_EVENT_BASE + 16)) {
2881 		int fd;
2882 
2883 		/* Variation set up */
2884 		eventExpected = DM_EVENT_INVALID;
2885 		eventReceived = DM_EVENT_INVALID;
2886 		eventResponse = DM_RESP_CONTINUE;
2887 		EVENT_DELIVERY_DELAY;
2888 		if ((fd =
2889 		     open(DummyFile, O_RDWR | O_CREAT,
2890 			  DUMMY_FILE_RW_MODE)) == -1) {
2891 			/* No clean up */
2892 		} else if ((rc = close(fd)) == -1) {
2893 			remove(DummyFile);
2894 		}
2895 		if (fd == -1 || rc == -1) {
2896 			DMLOG_PRINT(DMLVL_DEBUG,
2897 				    "Unable to set up variation! (errno = %d)\n",
2898 				    errno);
2899 			DMVAR_SKIP();
2900 		} else {
2901 			/* Variation */
2902 			EVENT_DELIVERY_DELAY;
2903 			DMLOG_PRINT(DMLVL_DEBUG, "symlink(%s, %s)\n", DummyFile,
2904 				    DummyLink);
2905 			rc = symlink(DummyFile, DummyLink);
2906 			DMLOG_PRINT(DMLVL_DEBUG,
2907 				    "symlink(%s, %s) returned %d\n", DummyFile,
2908 				    DummyLink, rc);
2909 			EVENT_DELIVERY_DELAY;
2910 			DMVAR_END(DMVAR_CHKPASSEXP
2911 				  (0, rc, eventExpected, eventReceived));
2912 
2913 			/* Variation clean up */
2914 			EVENT_DELIVERY_DELAY;
2915 			rc = unlink(DummyLink);
2916 			rc |= remove(DummyFile);
2917 			EVENT_DELIVERY_DELAY;
2918 			if (rc == -1) {
2919 				DMLOG_PRINT(DMLVL_DEBUG,
2920 					    "Unable to clean up variation! (errno = %d)\n",
2921 					    errno);
2922 			}
2923 		}
2924 	}
2925 
2926 	/*
2927 	 * TEST    : link - disabled
2928 	 * EXPECTED: no event
2929 	 */
2930 	if (DMVAR_EXEC(FILE_ASYNC_NAMESP_EVENT_BASE + 17)) {
2931 		void *hanp;
2932 		size_t hlen;
2933 		int fd;
2934 
2935 		/* Variation set up */
2936 		eventExpected = DM_EVENT_INVALID;
2937 		eventReceived = DM_EVENT_INVALID;
2938 		eventResponse = DM_RESP_CONTINUE;
2939 		EVENT_DELIVERY_DELAY;
2940 		if ((fd =
2941 		     open(DummyFile, O_RDWR | O_CREAT,
2942 			  DUMMY_FILE_RW_MODE)) == -1) {
2943 			/* No clean up */
2944 		} else if ((rc = dm_fd_to_handle(fd, &hanp, &hlen)) == -1) {
2945 			close(fd);
2946 			remove(DummyFile);
2947 		}
2948 		if (fd == -1 || rc == -1) {
2949 			DMLOG_PRINT(DMLVL_DEBUG,
2950 				    "Unable to set up variation! (errno = %d)\n",
2951 				    errno);
2952 			DMVAR_SKIP();
2953 		} else {
2954 			/* Variation */
2955 			EVENT_DELIVERY_DELAY;
2956 			DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s)\n", DummyFile,
2957 				    DummyLink);
2958 			rc = link(DummyFile, DummyLink);
2959 			DMLOG_PRINT(DMLVL_DEBUG, "link(%s, %s) returned %d\n",
2960 				    DummyFile, DummyLink, rc);
2961 			EVENT_DELIVERY_DELAY;
2962 			DMVAR_END(DMVAR_CHKPASSEXP
2963 				  (0, rc, eventExpected, eventReceived));
2964 
2965 			/* Variation clean up */
2966 			EVENT_DELIVERY_DELAY;
2967 			rc = close(fd);
2968 			rc |= remove(DummyFile);
2969 			rc |= remove(DummyLink);
2970 			if (rc == -1) {
2971 				DMLOG_PRINT(DMLVL_DEBUG,
2972 					    "Unable to clean up variation! (errno = %d)\n",
2973 					    errno);
2974 			}
2975 			dm_handle_free(hanp, hlen);
2976 		}
2977 	}
2978 
2979 	rc = umount(mountPt);
2980 	if (rc == -1) {
2981 		DMLOG_PRINT(DMLVL_ERR, "umount failed! (rc = %d, errno = %d)\n",
2982 			    rc, errno);
2983 	}
2984 
2985 	pthread_join(tid, NULL);
2986 
2987 	rc = dm_destroy_session(sid);
2988 	if (rc == -1) {
2989 		DMLOG_PRINT(DMLVL_ERR,
2990 			    "dm_destroy_session failed! (rc = %d, errno = %d)\n",
2991 			    rc, errno);
2992 	}
2993 
2994 	DMLOG_STOP();
2995 
2996 	tst_exit();
2997 }
2998 
Thread(void * parm)2999 void *Thread(void *parm)
3000 {
3001 	int rc;
3002 	size_t dmMsgBufLen;
3003 	dm_eventmsg_t *dmMsg;
3004 	int bMounted = DM_FALSE;
3005 	int type;
3006 	dm_token_t token;
3007 	dm_eventset_t events;
3008 	dm_response_t response;
3009 
3010 	do {
3011 		/* Loop until message received (wait could be interrupted) */
3012 		do {
3013 			DMLOG_PRINT(DMLVL_DEBUG, "Waiting for event...\n");
3014 			dmMsgBufLen = 0;
3015 
3016 			rc = dm_get_events(sid, 1, DM_EV_WAIT, sizeof(dmMsgBuf),
3017 					   dmMsgBuf, &dmMsgBufLen);
3018 			DMLOG_PRINT(DMLVL_DEBUG,
3019 				    "... dm_get_events returned %d (errno %d)\n",
3020 				    rc, errno);
3021 		} while ((rc == -1) && (errno == EINTR) && (dmMsgBufLen == 0));
3022 
3023 		if (rc) {
3024 			DMLOG_PRINT(DMLVL_ERR,
3025 				    "dm_get_events failed with rc = %d, errno = %d\n",
3026 				    rc, errno);
3027 			dm_destroy_session(sid);
3028 			DM_EXIT();
3029 		} else {
3030 			dmMsg = (dm_eventmsg_t *) dmMsgBuf;
3031 			token = dmMsg->ev_token;
3032 			type = dmMsg->ev_type;
3033 
3034 			DMLOG_PRINT(DMLVL_DEBUG, "Received message %d\n", type);
3035 		}
3036 
3037 		if (type == DM_EVENT_MOUNT) {
3038 			/* SPECIAL CASE: need to set disposition, events and response */
3039 			dm_mount_event_t *me =
3040 			    DM_GET_VALUE(dmMsg, ev_data, dm_mount_event_t *);
3041 			void *lhanp = DM_GET_VALUE(me, me_handle1, void *);
3042 			size_t lhlen = DM_GET_LEN(me, me_handle1);
3043 
3044 			DMLOG_PRINT(DMLVL_DEBUG, "Message is DM_EVENT_MOUNT\n");
3045 			DMLOG_PRINT(DMLVL_DEBUG, "  Mode: %x\n", me->me_mode);
3046 			DMLOG_PRINT(DMLVL_DEBUG, "  File system handle: %p\n",
3047 				    lhanp);
3048 			DMLOG_PRINT(DMLVL_DEBUG,
3049 				    "  File system handle length: %d\n", lhlen);
3050 			DMLOG_PRINT(DMLVL_DEBUG, "  Mountpoint handle: %p\n",
3051 				    DM_GET_VALUE(me, me_handle2, void *));
3052 			DMLOG_PRINT(DMLVL_DEBUG,
3053 				    "  Mountpoint handle length: %d\n",
3054 				    DM_GET_LEN(me, me_handle2));
3055 			DMLOG_PRINT(DMLVL_DEBUG, "  Mountpoint path: %s\n",
3056 				    DM_GET_VALUE(me, me_name1, char *));
3057 			DMLOG_PRINT(DMLVL_DEBUG, "  Media designator: %s\n",
3058 				    DM_GET_VALUE(me, me_name2, char *));
3059 			DMLOG_PRINT(DMLVL_DEBUG, "  Root handle: %p\n",
3060 				    DM_GET_VALUE(me, me_roothandle, void *));
3061 			DMLOG_PRINT(DMLVL_DEBUG, "  Root handle length: %d\n",
3062 				    DM_GET_LEN(me, me_roothandle));
3063 
3064 			bMounted = dm_handle_is_valid(lhanp, lhlen);
3065 
3066 			rc = dm_request_right(sid, lhanp, lhlen, token,
3067 					      DM_RR_WAIT, DM_RIGHT_EXCL);
3068 			if (rc == -1) {
3069 				DMLOG_PRINT(DMLVL_ERR,
3070 					    "dm_request_right failed! (rc = %d, errno = %d)\n",
3071 					    rc, errno);
3072 				dm_destroy_session(sid);
3073 				DM_EXIT();
3074 			}
3075 
3076 			DMEV_ZERO(events);
3077 			DMEV_SET(DM_EVENT_PREUNMOUNT, events);
3078 			DMEV_SET(DM_EVENT_UNMOUNT, events);
3079 			DMEV_SET(DM_EVENT_CREATE, events);
3080 			DMEV_SET(DM_EVENT_POSTCREATE, events);
3081 			DMEV_SET(DM_EVENT_REMOVE, events);
3082 			DMEV_SET(DM_EVENT_POSTREMOVE, events);
3083 			DMEV_SET(DM_EVENT_RENAME, events);
3084 			DMEV_SET(DM_EVENT_POSTRENAME, events);
3085 			DMEV_SET(DM_EVENT_SYMLINK, events);
3086 			DMEV_SET(DM_EVENT_POSTSYMLINK, events);
3087 			DMEV_SET(DM_EVENT_LINK, events);
3088 			DMEV_SET(DM_EVENT_POSTLINK, events);
3089 			rc = dm_set_disp(sid, lhanp, lhlen, token, &events,
3090 					 DM_EVENT_MAX);
3091 			if (rc == -1) {
3092 				DMLOG_PRINT(DMLVL_ERR,
3093 					    "dm_set_disp failed! (rc = %d, errno = %d)\n",
3094 					    rc, errno);
3095 				dm_destroy_session(sid);
3096 				DM_EXIT();
3097 			}
3098 
3099 			rc = dm_release_right(sid, lhanp, lhlen, token);
3100 			if (rc == -1) {
3101 				DMLOG_PRINT(DMLVL_ERR,
3102 					    "dm_request_right failed! (rc = %d, errno = %d)\n",
3103 					    rc, errno);
3104 				dm_destroy_session(sid);
3105 				DM_EXIT();
3106 			}
3107 
3108 			response = DM_RESP_CONTINUE;
3109 		} else if (type == DM_EVENT_PREUNMOUNT) {
3110 			/* SPECIAL CASE: need to set response */
3111 			dm_namesp_event_t *nse =
3112 			    DM_GET_VALUE(dmMsg, ev_data, dm_namesp_event_t *);
3113 
3114 			DMLOG_PRINT(DMLVL_DEBUG,
3115 				    "Message is DM_EVENT_PREUNMOUNT\n");
3116 			DMLOG_PRINT(DMLVL_DEBUG, "  Unmount mode: %x\n",
3117 				    nse->ne_mode);
3118 			DMLOG_PRINT(DMLVL_DEBUG, "  File system handle: %p\n",
3119 				    DM_GET_VALUE(nse, ne_handle1, void *));
3120 			DMLOG_PRINT(DMLVL_DEBUG,
3121 				    "  File system handle length: %d\n",
3122 				    DM_GET_LEN(nse, ne_handle1));
3123 			DMLOG_PRINT(DMLVL_DEBUG,
3124 				    "  Root directory handle: %p\n",
3125 				    DM_GET_VALUE(nse, ne_handle2, void *));
3126 			DMLOG_PRINT(DMLVL_DEBUG,
3127 				    "  Root directory handle length: %d\n",
3128 				    DM_GET_LEN(nse, ne_handle2));
3129 
3130 			response = DM_RESP_CONTINUE;
3131 		} else if (type == DM_EVENT_UNMOUNT) {
3132 			/* SPECIAL CASE: need to set response and bMounted */
3133 			dm_namesp_event_t *nse =
3134 			    DM_GET_VALUE(dmMsg, ev_data, dm_namesp_event_t *);
3135 
3136 			DMLOG_PRINT(DMLVL_DEBUG,
3137 				    "Message is DM_EVENT_UNMOUNT\n");
3138 			DMLOG_PRINT(DMLVL_DEBUG, "  Unmount mode: %x\n",
3139 				    nse->ne_mode);
3140 			DMLOG_PRINT(DMLVL_DEBUG, "  File system handle: %p\n",
3141 				    DM_GET_VALUE(nse, ne_handle1, void *));
3142 			DMLOG_PRINT(DMLVL_DEBUG,
3143 				    "  File system handle length: %d\n",
3144 				    DM_GET_LEN(nse, ne_handle1));
3145 			DMLOG_PRINT(DMLVL_DEBUG, "  Return code: %x\n",
3146 				    nse->ne_retcode);
3147 			if (nse->ne_retcode == 0) {
3148 				bMounted = DM_FALSE;
3149 			}
3150 
3151 			response = DM_RESP_CONTINUE;
3152 		} else {
3153 			eventReceived = type;
3154 			response = eventResponse;
3155 
3156 			switch (type) {
3157 			case DM_EVENT_CREATE:
3158 				{
3159 					dm_namesp_event_t *nse =
3160 					    DM_GET_VALUE(dmMsg, ev_data,
3161 							 dm_namesp_event_t *);
3162 					mode = nse->ne_mode;
3163 					hanp1 =
3164 					    DM_GET_VALUE(nse, ne_handle1,
3165 							 void *);
3166 					hlen1 = DM_GET_LEN(nse, ne_handle1);
3167 					strcpy(name1,
3168 					       DM_GET_VALUE(nse, ne_name1,
3169 							    char *));
3170 
3171 					DMLOG_PRINT(DMLVL_DEBUG,
3172 						    "Message is DM_EVENT_CREATE\n");
3173 					DMLOG_PRINT(DMLVL_DEBUG, "  Mode: %x\n",
3174 						    mode);
3175 					DMLOG_PRINT(DMLVL_DEBUG,
3176 						    "  Parent handle: %p\n",
3177 						    hanp1);
3178 					DMLOG_PRINT(DMLVL_DEBUG,
3179 						    "  Parent handle length: %d\n",
3180 						    hlen1);
3181 					DMLOG_PRINT(DMLVL_DEBUG,
3182 						    "  Entry name: %s\n",
3183 						    name1);
3184 
3185 					break;
3186 				}
3187 
3188 			case DM_EVENT_POSTCREATE:
3189 				{
3190 					dm_namesp_event_t *nse =
3191 					    DM_GET_VALUE(dmMsg, ev_data,
3192 							 dm_namesp_event_t *);
3193 					amode = nse->ne_mode;
3194 					ahanp1 =
3195 					    DM_GET_VALUE(nse, ne_handle1,
3196 							 void *);
3197 					ahlen1 = DM_GET_LEN(nse, ne_handle1);
3198 					ahanp2 =
3199 					    DM_GET_VALUE(nse, ne_handle2,
3200 							 void *);
3201 					ahlen2 = DM_GET_LEN(nse, ne_handle2);
3202 					strcpy(aname1,
3203 					       DM_GET_VALUE(nse, ne_name1,
3204 							    char *));
3205 					aretcode = nse->ne_retcode;
3206 
3207 					DMLOG_PRINT(DMLVL_DEBUG,
3208 						    "Message is DM_EVENT_POSTCREATE\n");
3209 					DMLOG_PRINT(DMLVL_DEBUG, "  Mode: %x\n",
3210 						    amode);
3211 					DMLOG_PRINT(DMLVL_DEBUG,
3212 						    "  Parent handle: %p\n",
3213 						    ahanp1);
3214 					DMLOG_PRINT(DMLVL_DEBUG,
3215 						    "  Parent handle length: %d\n",
3216 						    ahlen1);
3217 					DMLOG_PRINT(DMLVL_DEBUG,
3218 						    "  Entry handle: %p\n",
3219 						    ahanp2);
3220 					DMLOG_PRINT(DMLVL_DEBUG,
3221 						    "  Entry handle length: %d\n",
3222 						    ahlen2);
3223 					DMLOG_PRINT(DMLVL_DEBUG,
3224 						    "  Entry name: %s\n",
3225 						    aname1);
3226 					DMLOG_PRINT(DMLVL_DEBUG,
3227 						    "  Return code: %x\n",
3228 						    aretcode);
3229 
3230 					response = DM_RESP_INVALID;
3231 					break;
3232 				}
3233 
3234 			case DM_EVENT_REMOVE:
3235 				{
3236 					dm_namesp_event_t *nse =
3237 					    DM_GET_VALUE(dmMsg, ev_data,
3238 							 dm_namesp_event_t *);
3239 					mode = nse->ne_mode;
3240 					hanp1 =
3241 					    DM_GET_VALUE(nse, ne_handle1,
3242 							 void *);
3243 					hlen1 = DM_GET_LEN(nse, ne_handle1);
3244 					strcpy(name1,
3245 					       DM_GET_VALUE(nse, ne_name1,
3246 							    char *));
3247 
3248 					DMLOG_PRINT(DMLVL_DEBUG,
3249 						    "Message is DM_EVENT_REMOVE\n");
3250 					DMLOG_PRINT(DMLVL_DEBUG, "  Mode: %x\n",
3251 						    mode);
3252 					DMLOG_PRINT(DMLVL_DEBUG,
3253 						    "  Parent handle: %p\n",
3254 						    hanp1);
3255 					DMLOG_PRINT(DMLVL_DEBUG,
3256 						    "  Parent handle length: %d\n",
3257 						    hlen1);
3258 					DMLOG_PRINT(DMLVL_DEBUG,
3259 						    "  Entry name: %s\n",
3260 						    name1);
3261 
3262 					break;
3263 				}
3264 
3265 			case DM_EVENT_POSTREMOVE:
3266 				{
3267 					dm_namesp_event_t *nse =
3268 					    DM_GET_VALUE(dmMsg, ev_data,
3269 							 dm_namesp_event_t *);
3270 					amode = nse->ne_mode;
3271 					ahanp1 =
3272 					    DM_GET_VALUE(nse, ne_handle1,
3273 							 void *);
3274 					ahlen1 = DM_GET_LEN(nse, ne_handle1);
3275 					strcpy(aname1,
3276 					       DM_GET_VALUE(nse, ne_name1,
3277 							    char *));
3278 					aretcode = nse->ne_retcode;
3279 
3280 					DMLOG_PRINT(DMLVL_DEBUG,
3281 						    "Message is DM_EVENT_POSTREMOVE\n");
3282 					DMLOG_PRINT(DMLVL_DEBUG, "  Mode: %x\n",
3283 						    amode);
3284 					DMLOG_PRINT(DMLVL_DEBUG,
3285 						    "  Parent handle: %p\n",
3286 						    ahanp1);
3287 					DMLOG_PRINT(DMLVL_DEBUG,
3288 						    "  Parent handle length: %d\n",
3289 						    ahlen1);
3290 					DMLOG_PRINT(DMLVL_DEBUG,
3291 						    "  Entry name: %s\n",
3292 						    aname1);
3293 					DMLOG_PRINT(DMLVL_DEBUG,
3294 						    "  Return code: %x\n",
3295 						    aretcode);
3296 
3297 					response = DM_RESP_INVALID;
3298 					break;
3299 				}
3300 
3301 			case DM_EVENT_RENAME:
3302 				{
3303 					dm_namesp_event_t *nse =
3304 					    DM_GET_VALUE(dmMsg, ev_data,
3305 							 dm_namesp_event_t *);
3306 					hanp1 =
3307 					    DM_GET_VALUE(nse, ne_handle1,
3308 							 void *);
3309 					hlen1 = DM_GET_LEN(nse, ne_handle1);
3310 					hanp2 =
3311 					    DM_GET_VALUE(nse, ne_handle2,
3312 							 void *);
3313 					hlen2 = DM_GET_LEN(nse, ne_handle2);
3314 					strcpy(name1,
3315 					       DM_GET_VALUE(nse, ne_name1,
3316 							    char *));
3317 					strcpy(name2,
3318 					       DM_GET_VALUE(nse, ne_name2,
3319 							    char *));
3320 
3321 					DMLOG_PRINT(DMLVL_DEBUG,
3322 						    "Message is DM_EVENT_RENAME\n");
3323 					DMLOG_PRINT(DMLVL_DEBUG,
3324 						    "  Old parent handle: %p\n",
3325 						    hanp1);
3326 					DMLOG_PRINT(DMLVL_DEBUG,
3327 						    "  Old parent handle length: %d\n",
3328 						    hlen1);
3329 					DMLOG_PRINT(DMLVL_DEBUG,
3330 						    "  New parent handle: %p\n",
3331 						    hanp2);
3332 					DMLOG_PRINT(DMLVL_DEBUG,
3333 						    "  New parent handle length: %d\n",
3334 						    hlen2);
3335 					DMLOG_PRINT(DMLVL_DEBUG,
3336 						    "  Old entry name: %s\n",
3337 						    name1);
3338 					DMLOG_PRINT(DMLVL_DEBUG,
3339 						    "  New entry name: %s\n",
3340 						    name2);
3341 
3342 					break;
3343 				}
3344 
3345 			case DM_EVENT_POSTRENAME:
3346 				{
3347 					dm_namesp_event_t *nse =
3348 					    DM_GET_VALUE(dmMsg, ev_data,
3349 							 dm_namesp_event_t *);
3350 					ahanp1 =
3351 					    DM_GET_VALUE(nse, ne_handle1,
3352 							 void *);
3353 					ahlen1 = DM_GET_LEN(nse, ne_handle1);
3354 					ahanp2 =
3355 					    DM_GET_VALUE(nse, ne_handle2,
3356 							 void *);
3357 					ahlen2 = DM_GET_LEN(nse, ne_handle2);
3358 					strcpy(aname1,
3359 					       DM_GET_VALUE(nse, ne_name1,
3360 							    char *));
3361 					strcpy(aname2,
3362 					       DM_GET_VALUE(nse, ne_name2,
3363 							    char *));
3364 					aretcode = nse->ne_retcode;
3365 
3366 					DMLOG_PRINT(DMLVL_DEBUG,
3367 						    "Message is DM_EVENT_POSTRENAME\n");
3368 					DMLOG_PRINT(DMLVL_DEBUG,
3369 						    "  Old parent handle: %p\n",
3370 						    ahanp1);
3371 					DMLOG_PRINT(DMLVL_DEBUG,
3372 						    "  Old parent handle length: %d\n",
3373 						    ahlen1);
3374 					DMLOG_PRINT(DMLVL_DEBUG,
3375 						    "  New parent handle: %p\n",
3376 						    ahanp2);
3377 					DMLOG_PRINT(DMLVL_DEBUG,
3378 						    "  New parent handle length: %d\n",
3379 						    ahlen2);
3380 					DMLOG_PRINT(DMLVL_DEBUG,
3381 						    "  Old entry name: %s\n",
3382 						    aname1);
3383 					DMLOG_PRINT(DMLVL_DEBUG,
3384 						    "  New entry name: %s\n",
3385 						    aname2);
3386 					DMLOG_PRINT(DMLVL_DEBUG,
3387 						    "  Return code: %x\n",
3388 						    aretcode);
3389 
3390 					response = DM_RESP_INVALID;
3391 					break;
3392 				}
3393 
3394 			case DM_EVENT_SYMLINK:
3395 				{
3396 					dm_namesp_event_t *nse =
3397 					    DM_GET_VALUE(dmMsg, ev_data,
3398 							 dm_namesp_event_t *);
3399 					hanp1 =
3400 					    DM_GET_VALUE(nse, ne_handle1,
3401 							 void *);
3402 					hlen1 = DM_GET_LEN(nse, ne_handle1);
3403 					strcpy(name1,
3404 					       DM_GET_VALUE(nse, ne_name1,
3405 							    char *));
3406 					strcpy(name2,
3407 					       DM_GET_VALUE(nse, ne_name2,
3408 							    char *));
3409 
3410 					DMLOG_PRINT(DMLVL_DEBUG,
3411 						    "Message is DM_EVENT_SYMLINK\n");
3412 					DMLOG_PRINT(DMLVL_DEBUG,
3413 						    "  Parent handle: %p\n",
3414 						    hanp1);
3415 					DMLOG_PRINT(DMLVL_DEBUG,
3416 						    "  Parent handle length: %d\n",
3417 						    hlen1);
3418 					DMLOG_PRINT(DMLVL_DEBUG,
3419 						    "  Symlink entry name: %s\n",
3420 						    name1);
3421 					DMLOG_PRINT(DMLVL_DEBUG,
3422 						    "  Symlink contents: %s\n",
3423 						    name2);
3424 
3425 					break;
3426 				}
3427 
3428 			case DM_EVENT_POSTSYMLINK:
3429 				{
3430 					dm_namesp_event_t *nse =
3431 					    DM_GET_VALUE(dmMsg, ev_data,
3432 							 dm_namesp_event_t *);
3433 					ahanp1 =
3434 					    DM_GET_VALUE(nse, ne_handle1,
3435 							 void *);
3436 					ahlen1 = DM_GET_LEN(nse, ne_handle1);
3437 					ahanp2 =
3438 					    DM_GET_VALUE(nse, ne_handle2,
3439 							 void *);
3440 					ahlen2 = DM_GET_LEN(nse, ne_handle2);
3441 					strcpy(aname1,
3442 					       DM_GET_VALUE(nse, ne_name1,
3443 							    char *));
3444 					strcpy(aname2,
3445 					       DM_GET_VALUE(nse, ne_name2,
3446 							    char *));
3447 					aretcode = nse->ne_retcode;
3448 
3449 					DMLOG_PRINT(DMLVL_DEBUG,
3450 						    "Message is DM_EVENT_POSTSYMLINK\n");
3451 					DMLOG_PRINT(DMLVL_DEBUG,
3452 						    "  Parent handle: %p\n",
3453 						    ahanp1);
3454 					DMLOG_PRINT(DMLVL_DEBUG,
3455 						    "  Parent handle length: %d\n",
3456 						    ahlen1);
3457 					DMLOG_PRINT(DMLVL_DEBUG,
3458 						    "  Entry handle: %p\n",
3459 						    ahanp2);
3460 					DMLOG_PRINT(DMLVL_DEBUG,
3461 						    "  Entry handle length: %d\n",
3462 						    ahlen2);
3463 					DMLOG_PRINT(DMLVL_DEBUG,
3464 						    "  Symlink entry name: %s\n",
3465 						    aname1);
3466 					DMLOG_PRINT(DMLVL_DEBUG,
3467 						    "  Symlink contents: %s\n",
3468 						    aname2);
3469 					DMLOG_PRINT(DMLVL_DEBUG,
3470 						    "  Return code: %x\n",
3471 						    aretcode);
3472 
3473 					response = DM_RESP_INVALID;
3474 					break;
3475 				}
3476 
3477 			case DM_EVENT_LINK:
3478 				{
3479 					dm_namesp_event_t *nse =
3480 					    DM_GET_VALUE(dmMsg, ev_data,
3481 							 dm_namesp_event_t *);
3482 					hanp1 =
3483 					    DM_GET_VALUE(nse, ne_handle1,
3484 							 void *);
3485 					hlen1 = DM_GET_LEN(nse, ne_handle1);
3486 					hanp2 =
3487 					    DM_GET_VALUE(nse, ne_handle2,
3488 							 void *);
3489 					hlen2 = DM_GET_LEN(nse, ne_handle2);
3490 					strcpy(name1,
3491 					       DM_GET_VALUE(nse, ne_name1,
3492 							    char *));
3493 
3494 					DMLOG_PRINT(DMLVL_DEBUG,
3495 						    "Message is DM_EVENT_LINK\n");
3496 					DMLOG_PRINT(DMLVL_DEBUG,
3497 						    "  Parent handle: %p\n",
3498 						    hanp1);
3499 					DMLOG_PRINT(DMLVL_DEBUG,
3500 						    "  Parent handle length: %d\n",
3501 						    hlen1);
3502 					DMLOG_PRINT(DMLVL_DEBUG,
3503 						    "  Source link handle: %p\n",
3504 						    hanp2);
3505 					DMLOG_PRINT(DMLVL_DEBUG,
3506 						    "  Source link handle length: %d\n",
3507 						    hlen2);
3508 					DMLOG_PRINT(DMLVL_DEBUG,
3509 						    "  Target entry name: %s\n",
3510 						    name1);
3511 
3512 					break;
3513 				}
3514 
3515 			case DM_EVENT_POSTLINK:
3516 				{
3517 					dm_namesp_event_t *nse =
3518 					    DM_GET_VALUE(dmMsg, ev_data,
3519 							 dm_namesp_event_t *);
3520 					ahanp1 =
3521 					    DM_GET_VALUE(nse, ne_handle1,
3522 							 void *);
3523 					ahlen1 = DM_GET_LEN(nse, ne_handle1);
3524 					ahanp2 =
3525 					    DM_GET_VALUE(nse, ne_handle2,
3526 							 void *);
3527 					ahlen2 = DM_GET_LEN(nse, ne_handle2);
3528 					strcpy(aname1,
3529 					       DM_GET_VALUE(nse, ne_name1,
3530 							    char *));
3531 					aretcode = nse->ne_retcode;
3532 
3533 					DMLOG_PRINT(DMLVL_DEBUG,
3534 						    "Message is DM_EVENT_POSTLINK\n");
3535 					DMLOG_PRINT(DMLVL_DEBUG,
3536 						    "  Parent handle: %p\n",
3537 						    ahanp1);
3538 					DMLOG_PRINT(DMLVL_DEBUG,
3539 						    "  Parent handle length: %d\n",
3540 						    ahlen1);
3541 					DMLOG_PRINT(DMLVL_DEBUG,
3542 						    "  Source link handle: %p\n",
3543 						    ahanp2);
3544 					DMLOG_PRINT(DMLVL_DEBUG,
3545 						    "  Source link handle length: %d\n",
3546 						    ahlen2);
3547 					DMLOG_PRINT(DMLVL_DEBUG,
3548 						    "  Target entry name: %s\n",
3549 						    aname1);
3550 					DMLOG_PRINT(DMLVL_DEBUG,
3551 						    "  Return code: %x\n",
3552 						    aretcode);
3553 
3554 					response = DM_RESP_INVALID;
3555 					break;
3556 				}
3557 
3558 			default:
3559 				{
3560 					DMLOG_PRINT(DMLVL_ERR,
3561 						    "Message is unexpected!\n");
3562 					response = DM_RESP_ABORT;
3563 					break;
3564 				}
3565 			}
3566 		}
3567 
3568 		if (response != DM_RESP_INVALID) {
3569 			DMLOG_PRINT(DMLVL_DEBUG,
3570 				    "Responding to message %d with %d\n", type,
3571 				    response);
3572 			rc = dm_respond_event(sid, token, response,
3573 					      response ==
3574 					      DM_RESP_ABORT ? ABORT_ERRNO : 0,
3575 					      0, NULL);
3576 		}
3577 	} while (bMounted);
3578 
3579 	pthread_exit(0);
3580 }
3581