From owner-svn-src-user@freebsd.org Sun Dec 8 06:35:26 2019 Return-Path: Delivered-To: svn-src-user@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 055E71DA2CA for ; Sun, 8 Dec 2019 06:35:26 +0000 (UTC) (envelope-from pho@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47VxQj6R1vz3DXk; Sun, 8 Dec 2019 06:35:25 +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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C19532622B; Sun, 8 Dec 2019 06:35:25 +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 xB86ZPsB092644; Sun, 8 Dec 2019 06:35:25 GMT (envelope-from pho@FreeBSD.org) Received: (from pho@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id xB86ZPbI092643; Sun, 8 Dec 2019 06:35:25 GMT (envelope-from pho@FreeBSD.org) Message-Id: <201912080635.xB86ZPbI092643@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pho set sender to pho@FreeBSD.org using -f From: Peter Holm Date: Sun, 8 Dec 2019 06:35:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r355525 - user/pho/stress2/misc X-SVN-Group: user X-SVN-Commit-Author: pho X-SVN-Commit-Paths: user/pho/stress2/misc X-SVN-Commit-Revision: 355525 X-SVN-Commit-Repository: base 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.29 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: Sun, 08 Dec 2019 06:35:26 -0000 Author: pho Date: Sun Dec 8 06:35:25 2019 New Revision: 355525 URL: https://svnweb.freebsd.org/changeset/base/355525 Log: Added a regression test. Added: user/pho/stress2/misc/ufssuspend.sh (contents, props changed) Added: user/pho/stress2/misc/ufssuspend.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/pho/stress2/misc/ufssuspend.sh Sun Dec 8 06:35:25 2019 (r355525) @@ -0,0 +1,133 @@ +#!/bin/sh + +# ioctl(g_ufs_suspend_handle, UFSSUSPEND, &statfsp->f_fsid) test scenario. + +# Bug 230220 - UFS: the freezing ioctl (i.e.UFSSUSPEND) causes panic or EBUSY +# "panic: devfs_set_cdevpriv failed" seen. +# Test scenario by Dexuan Cui +# Fixed by r337055. + +# $FreeBSD$ + +[ `id -u` -ne 0 ] && echo "Must be root!" && exit 1 +. ../default.cfg + +cat > /tmp/ufssuspend.c < +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int g_ufs_suspend_handle = -1; +static const char *dev = "/dev"; + +static int +freeze(void) +{ + struct statfs *mntbuf, *statfsp; + int mntsize; + int error = 0; + int i; + + g_ufs_suspend_handle = open(_PATH_UFSSUSPEND, O_RDWR); + if (g_ufs_suspend_handle == -1) { + printf("unable to open %s", _PATH_UFSSUSPEND); + return (errno); + } + + mntsize = getmntinfo(&mntbuf, MNT_NOWAIT); + if (mntsize == 0) { + printf("There is no mount information\n"); + return (EINVAL); + } + + for (i = mntsize - 1; i >= 0; --i) { + statfsp = &mntbuf[i]; + + if (strncmp(statfsp->f_mntonname, dev, strlen(dev)) == 0) + continue; /* skip to freeze '/dev' */ + + if (statfsp->f_flags & MNT_RDONLY) + continue; /* skip to freeze RDONLY partition */ + + if (strncmp(statfsp->f_fstypename, "ufs", 3) != 0) + continue; /* so far, only UFS can be frozen */ + + printf("suspending fs: %s\n", statfsp->f_mntonname); + error = ioctl(g_ufs_suspend_handle, UFSSUSPEND, &statfsp->f_fsid); + if (error != 0) { + printf("error: %d\n", errno); + error = errno; + } else { + printf("Successfully suspend fs: %s\n", statfsp->f_mntonname); + } + } + + return (error); +} + +/** + * closing the opened handle will thaw the FS. + */ +static int +thaw(void) +{ + int error = 0; + + if (g_ufs_suspend_handle != -1) { + error = close(g_ufs_suspend_handle); + if (!error) { + g_ufs_suspend_handle = -1; + printf("Successfully thaw the fs\n"); + } else { + error = errno; + printf("Fail to thaw the fs: " + "%d %s\n", errno, strerror(errno)); + } + } else { + printf("The fs has already been thawed\n\n"); + } + + return (error); +} + +int +main(void) +{ + int error; + + error = freeze(); + printf("freeze: err=%d\n", error); + + error = thaw(); + printf("thaw: err=%d\n", error); + + return 0; +} +EOF + +mycc -o /tmp/ufssuspend -Wall -Wextra -O2 -g /tmp/ufssuspend.c || exit 1 +rm /tmp/ufssuspend.c + +cd /tmp +./ufssuspend > /dev/null +s=$? +rm /tmp/ufssuspend +exit $s