1f08c3bdfSopenharmony_ci/* 2f08c3bdfSopenharmony_ci * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz> 3f08c3bdfSopenharmony_ci * 4f08c3bdfSopenharmony_ci * This program is free software: you can redistribute it and/or modify 5f08c3bdfSopenharmony_ci * it under the terms of the GNU General Public License as published by 6f08c3bdfSopenharmony_ci * the Free Software Foundation, either version 2 of the License, or 7f08c3bdfSopenharmony_ci * (at your option) any later version. 8f08c3bdfSopenharmony_ci * 9f08c3bdfSopenharmony_ci * This program is distributed in the hope that it will be useful, 10f08c3bdfSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 11f08c3bdfSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12f08c3bdfSopenharmony_ci * GNU General Public License for more details. 13f08c3bdfSopenharmony_ci * 14f08c3bdfSopenharmony_ci * You should have received a copy of the GNU General Public License 15f08c3bdfSopenharmony_ci * along with this program. If not, see <http://www.gnu.org/licenses/>. 16f08c3bdfSopenharmony_ci */ 17f08c3bdfSopenharmony_ci 18f08c3bdfSopenharmony_ci#ifndef UMOUNT2_H__ 19f08c3bdfSopenharmony_ci#define UMOUNT2_H__ 20f08c3bdfSopenharmony_ci 21f08c3bdfSopenharmony_cistatic inline int umount2_retry(const char *target, int flags) 22f08c3bdfSopenharmony_ci{ 23f08c3bdfSopenharmony_ci int i, ret; 24f08c3bdfSopenharmony_ci 25f08c3bdfSopenharmony_ci for (i = 0; i < 50; i++) { 26f08c3bdfSopenharmony_ci ret = umount2(target, flags); 27f08c3bdfSopenharmony_ci 28f08c3bdfSopenharmony_ci if (ret == 0 || errno != EBUSY) 29f08c3bdfSopenharmony_ci return ret; 30f08c3bdfSopenharmony_ci 31f08c3bdfSopenharmony_ci tst_resm(TINFO, "umount('%s', %i) failed with EBUSY, try %2i...", 32f08c3bdfSopenharmony_ci target, flags, i); 33f08c3bdfSopenharmony_ci 34f08c3bdfSopenharmony_ci usleep(100000); 35f08c3bdfSopenharmony_ci } 36f08c3bdfSopenharmony_ci 37f08c3bdfSopenharmony_ci tst_resm(TWARN, "Failed to umount('%s', %i) after 50 retries", 38f08c3bdfSopenharmony_ci target, flags); 39f08c3bdfSopenharmony_ci 40f08c3bdfSopenharmony_ci errno = EBUSY; 41f08c3bdfSopenharmony_ci return -1; 42f08c3bdfSopenharmony_ci} 43f08c3bdfSopenharmony_ci 44f08c3bdfSopenharmony_ci#endif /* UMOUNT2_H__ */ 45