[BACK]Return to t_nullpts.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / tests / fs / ptyfs

File: [cvs.NetBSD.org] / src / tests / fs / ptyfs / t_nullpts.c (download)

Revision 1.5, Mon Jan 10 11:11:04 2011 UTC (11 years, 4 months ago) by hannken
Branch: MAIN
CVS Tags: yamt-pagecache-tag8, yamt-pagecache-base9, yamt-pagecache-base8, yamt-pagecache-base7, yamt-pagecache-base6, yamt-pagecache-base5, yamt-pagecache-base4, yamt-pagecache-base3, yamt-pagecache-base2, yamt-pagecache-base, yamt-pagecache, tls-maxphys-base, tls-maxphys, tls-earlyentropy-base, tls-earlyentropy, riastradh-xf86-video-intel-2-7-1-pre-2-21-15, riastradh-drm2-base3, riastradh-drm2-base2, riastradh-drm2-base1, riastradh-drm2-base, riastradh-drm2, pgoyette-localcount-base, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-localcount-20160806, pgoyette-localcount-20160726, netbsd-7-nhusb-base-20170116, netbsd-7-nhusb-base, netbsd-7-nhusb, netbsd-7-base, netbsd-7-2-RELEASE, netbsd-7-1-RELEASE, netbsd-7-1-RC2, netbsd-7-1-RC1, netbsd-7-1-2-RELEASE, netbsd-7-1-1-RELEASE, netbsd-7-1, netbsd-7-0-RELEASE, netbsd-7-0-RC3, netbsd-7-0-RC2, netbsd-7-0-RC1, netbsd-7-0-2-RELEASE, netbsd-7-0-1-RELEASE, netbsd-7-0, netbsd-7, netbsd-6-base, netbsd-6-1-RELEASE, netbsd-6-1-RC4, netbsd-6-1-RC3, netbsd-6-1-RC2, netbsd-6-1-RC1, netbsd-6-1-5-RELEASE, netbsd-6-1-4-RELEASE, netbsd-6-1-3-RELEASE, netbsd-6-1-2-RELEASE, netbsd-6-1-1-RELEASE, netbsd-6-1, netbsd-6-0-RELEASE, netbsd-6-0-RC2, netbsd-6-0-RC1, netbsd-6-0-6-RELEASE, netbsd-6-0-5-RELEASE, netbsd-6-0-4-RELEASE, netbsd-6-0-3-RELEASE, netbsd-6-0-2-RELEASE, netbsd-6-0-1-RELEASE, netbsd-6-0, netbsd-6, matt-nb6-plus-nbase, matt-nb6-plus-base, matt-nb6-plus, localcount-20160914, cherry-xenmp-base, cherry-xenmp, bouyer-quota2-nbase, bouyer-quota2-base, bouyer-quota2, agc-symver-base, agc-symver
Branch point for: pgoyette-localcount
Changes since 1.4: +3 -4 lines

Add layer_revoke() that adjusts the lower vnode use count to be at least as
high as the upper vnode count before passing down the VOP_REVOKE().

This way vclean() check for active (vp->v_usecount > 1) vnodes gets it right.

Should fix PR kern/43456.

/*	$NetBSD: t_nullpts.c,v 1.5 2011/01/10 11:11:04 hannken Exp $	*/

#include <sys/types.h>
#include <sys/mount.h>
#include <sys/ioctl.h>

#include <atf-c.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>

#include <rump/rump.h>
#include <rump/rump_syscalls.h>

#include <fs/ptyfs/ptyfs.h>
#include <miscfs/nullfs/null.h>

#include "../../h_macros.h"

static void
mountptyfs(const char *mp, int flags)
{
	struct ptyfs_args args;

	if (rump_sys_mkdir(mp, 0777) == -1) {
		if (errno != EEXIST)
			atf_tc_fail_errno("null create %s", mp);
	}
	memset(&args, 0, sizeof(args));
	args.version = PTYFS_ARGSVERSION;
	args.mode = 0777;
	if (rump_sys_mount(MOUNT_PTYFS, mp, flags, &args, sizeof(args)) == -1)
		atf_tc_fail_errno("could not mount ptyfs");
}

static void
mountnull(const char *what, const char *mp, int flags)
{
	struct null_args nargs;

	if (rump_sys_mkdir(what, 0777) == -1) {
		if (errno != EEXIST)
			atf_tc_fail_errno("null create %s", what);
	}
	if (rump_sys_mkdir(mp, 0777) == -1) {
		if (errno != EEXIST)
			atf_tc_fail_errno("null create %s", mp);
	}
	memset(&nargs, 0, sizeof(nargs));
	nargs.nulla_target = __UNCONST(what);
	if (rump_sys_mount(MOUNT_NULL, mp, flags, &nargs, sizeof(nargs)) == -1)
		atf_tc_fail_errno("could not mount nullfs");
}

ATF_TC(nullrevoke);
ATF_TC_HEAD(nullrevoke, tc)
{
	atf_tc_set_md_var(tc, "descr", "null mount ptyfs and revoke");
}

ATF_TC_BODY(nullrevoke, tc)
{
	char path[MAXPATHLEN];
	struct ptmget ptg;
	int ptm;

	rump_init();

	/*
	 * mount /dev/pts
	 */
	mountptyfs("/dev/pts", 0);

	/*
	 * null mount /dev/pts to /null/dev/pts
	 */
	if (rump_sys_mkdir("/null", 0777) == -1) {
		if (errno != EEXIST)
			atf_tc_fail_errno("null create /null");
	}
	if (rump_sys_mkdir("/null/dev", 0777) == -1) {
		if (errno != EEXIST)
			atf_tc_fail_errno("null create /null/dev");
	}

	mountnull("/dev/pts", "/null/dev/pts", 0);

	/*
	 * get slave/master pair.
	 */
	ptm = rump_sys_open("/dev/ptm", O_RDWR);
	if (rump_sys_ioctl(ptm, TIOCPTMGET, &ptg) == -1)
		atf_tc_fail_errno("get pty");

	/*
	 * Build nullfs path to slave.
	 */
	strcpy(path, "/null");
	strcat(path, ptg.sn);

	/*
	 * Open slave tty via nullfs.
	 */
	if (rump_sys_open(path, O_RDWR) == -1)
		atf_tc_fail_errno("slave null open");

	/*
	 * Close slave opened with /dev/ptm.  Need purely non-null refs to it.
	 */
	rump_sys_close(ptg.sfd);

	/* revoke slave tty. */
	rump_sys_revoke(path);

	/* done */
}

ATF_TP_ADD_TCS(tp)
{

	ATF_TP_ADD_TC(tp, nullrevoke);

	return atf_no_error();
}