From owner-svn-src-user@freebsd.org Fri Mar 24 10:24:07 2017 Return-Path: Delivered-To: svn-src-user@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 967EFCA2A13 for ; Fri, 24 Mar 2017 10:24:07 +0000 (UTC) (envelope-from pho@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7123E1696; Fri, 24 Mar 2017 10:24:07 +0000 (UTC) (envelope-from pho@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v2OAO6K1038594; Fri, 24 Mar 2017 10:24:06 GMT (envelope-from pho@FreeBSD.org) Received: (from pho@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v2OAO6Eq038593; Fri, 24 Mar 2017 10:24:06 GMT (envelope-from pho@FreeBSD.org) Message-Id: <201703241024.v2OAO6Eq038593@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pho set sender to pho@FreeBSD.org using -f From: Peter Holm Date: Fri, 24 Mar 2017 10:24:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r315897 - user/pho/stress2/lib X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Mar 2017 10:24:07 -0000 Author: pho Date: Fri Mar 24 10:24:06 2017 New Revision: 315897 URL: https://svnweb.freebsd.org/changeset/base/315897 Log: Try harder to open lock file. Fix code style while here. Sponsored by: Dell EMC Isilon Modified: user/pho/stress2/lib/resources.c Modified: user/pho/stress2/lib/resources.c ============================================================================== --- user/pho/stress2/lib/resources.c Fri Mar 24 09:37:00 2017 (r315896) +++ user/pho/stress2/lib/resources.c Fri Mar 24 10:24:06 2017 (r315897) @@ -72,7 +72,8 @@ inodes(void) buf.f_ffree = 9999; flags = buf.f_flags & MNT_VISFLAGMASK; if (op->verbose > 2) - printf("Free inodes on %s (%s): %jd\n", path, buf.f_mntonname, buf.f_ffree); + printf("Free inodes on %s (%s): %jd\n", path, + buf.f_mntonname, buf.f_ffree); return (buf.f_ffree); } @@ -91,11 +92,13 @@ df(void) if (statfs(path, &buf) < 0) err(1, "statfs(%s)", path); if (buf.f_bavail > (int64_t)buf.f_blocks || buf.f_bavail < 0) { - warnx("Corrupt statfs(%s). f_bavail = %jd!", path, buf.f_bavail); + warnx("Corrupt statfs(%s). f_bavail = %jd!", path, + buf.f_bavail); buf.f_bavail = 100; } if (op->verbose > 2) - printf("Free space on %s: %jd Mb\n", path, buf.f_bavail * buf.f_bsize / 1024 / 1024); + printf("Free space on %s: %jd Mb\n", path, buf.f_bavail * + buf.f_bsize / 1024 / 1024); return (buf.f_bavail * buf.f_bsize); } @@ -157,36 +160,45 @@ void cleanupdf() void getdf(int64_t *block, int64_t *inode) { - int i; + int i, j; char buf[128]; snprintf(lockpath, sizeof(lockpath), "%s/lock", op->cd); - for (i = 0; i < 10000; i++) { - if ((lockfd = open(lockpath, - O_CREAT | O_TRUNC | O_WRONLY | O_EXCL, 0644)) != -1) + for (j = 0; j < 2; j++) { + for (i = 0; i < 10000; i++) { + if ((lockfd = open(lockpath, + O_CREAT | O_TRUNC | O_WRONLY | + O_EXCL, 0644)) != -1) + break; + usleep(10000); /* sleep 1/100 sec */ + if (i > 0 && i % 1000 == 0) + fprintf(stderr, "%s is waiting for lock file" + " %s\n", + getprogname(), lockpath); + } + if (lockfd != -1) break; - usleep(10000); /* sleep 1/100 sec */ - if (i > 0 && i % 1000 == 0) - fprintf(stderr, "%s is waiting for lock file %s\n", - getprogname(), lockpath); + fprintf(stderr, "%s. Removing stale %s\n", getprogname(), + lockpath); + unlink(lockpath); } - fprintf(stderr, "%s. Removing stale %s\n", getprogname(), lockpath); - unlink(lockpath); if (lockfd == -1) - errx(1, "%s. Can not create %s\n", getprogname(), lockpath); + errx(1, "%s. Can not create %s\n", getprogname(), lockpath); snprintf(dfpath, sizeof(dfpath), "%s/df", op->cd); if ((dffd = open(dfpath, O_RDWR, 0644)) == -1) { if ((dffd = open(dfpath, O_CREAT | O_TRUNC | O_WRONLY, 0644)) == -1) { unlink(lockpath); - err(1, "creat(%s) %s:%d", dfpath, __FILE__, __LINE__); + err(1, "creat(%s) %s:%d", dfpath, __FILE__, + __LINE__); } atexit(cleanupdf); *block = df(); *inode = inodes(); snprintf(buf, sizeof(buf), "%jd %jd", *block, *inode); - if (write(dffd, buf, strlen(buf) + 1) != (ssize_t)strlen(buf) +1) + if (write(dffd, buf, strlen(buf) + 1) != + (ssize_t)strlen(buf) +1) err(1, "write df. %s:%d", __FILE__, __LINE__); } else { if (read(dffd, buf, sizeof(buf)) < 1) { @@ -207,7 +219,8 @@ reservedf(int64_t blks, int64_t inos) int64_t blocks, inodes; if ((dffd = open(dfpath, O_RDWR, 0644)) == -1) { - warn("open(%s) %s:%d. %s", dfpath, __FILE__, __LINE__, getprogname()); + warn("open(%s) %s:%d. %s", dfpath, __FILE__, __LINE__, + getprogname()); goto err; } if (read(dffd, buf, sizeof(buf)) < 1) { @@ -218,13 +231,15 @@ reservedf(int64_t blks, int64_t inos) if (op->verbose > 2) printf("%-8s: reservefd(%9jdK, %6jd) out of (%9jdK, %6jd)\n", - getprogname(), blks/1024, inos, blocks/1024, inodes); + getprogname(), blks/1024, inos, blocks/1024, + inodes); blocks -= blks; inodes -= inos; snprintf(buf, sizeof(buf), "%jd %jd", blocks, inodes); if (blocks < 0 || inodes < 0) - printf("******************************** %s: %s\n", getprogname(), buf); + printf("******************************** %s: %s\n", + getprogname(), buf); if (lseek(dffd, 0, 0) == -1) err(1, "lseek. %s:%d", __FILE__, __LINE__); if (write(dffd, buf, strlen(buf) + 1) != (ssize_t)strlen(buf) +1)