1 /*
2  * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
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 the
12  * 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, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef UMOUNT2_H__
19 #define UMOUNT2_H__
20 
21 static inline int umount2_retry(const char *target, int flags)
22 {
23 	int i, ret;
24 
25 	for (i = 0; i < 50; i++) {
26 		ret = umount2(target, flags);
27 
28 		if (ret == 0 || errno != EBUSY)
29 			return ret;
30 
31 		tst_resm(TINFO, "umount('%s', %i) failed with EBUSY, try %2i...",
32 			 target, flags, i);
33 
34 		usleep(100000);
35 	}
36 
37 	tst_resm(TWARN, "Failed to umount('%s', %i) after 50 retries",
38 	         target, flags);
39 
40 	errno = EBUSY;
41 	return -1;
42 }
43 
44 #endif	/* UMOUNT2_H__ */
45