Module Name: src Committed By: bouyer Date: Fri Jan 28 18:38:08 UTC 2011
Modified Files: src/tests/fs/ffs [bouyer-quota2]: Makefile Added Files: src/tests/fs/ffs [bouyer-quota2]: quotas_common.sh t_getquota.sh src/tests/fs/ffs/clients [bouyer-quota2]: Makefile quota_rumpops.c Log Message: Add rump versions of quota utilities, to be used by tests. Add a test which figures if we can retrieve quota values from the kernel. To generate a diff of this commit: cvs rdiff -u -r1.14.2.1 -r1.14.2.2 src/tests/fs/ffs/Makefile cvs rdiff -u -r0 -r1.1.2.1 src/tests/fs/ffs/quotas_common.sh \ src/tests/fs/ffs/t_getquota.sh cvs rdiff -u -r0 -r1.1.2.1 src/tests/fs/ffs/clients/Makefile \ src/tests/fs/ffs/clients/quota_rumpops.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/fs/ffs/Makefile diff -u src/tests/fs/ffs/Makefile:1.14.2.1 src/tests/fs/ffs/Makefile:1.14.2.2 --- src/tests/fs/ffs/Makefile:1.14.2.1 Thu Jan 20 14:25:04 2011 +++ src/tests/fs/ffs/Makefile Fri Jan 28 18:38:07 2011 @@ -1,16 +1,23 @@ -# $NetBSD: Makefile,v 1.14.2.1 2011/01/20 14:25:04 bouyer Exp $ +# $NetBSD: Makefile,v 1.14.2.2 2011/01/28 18:38:07 bouyer Exp $ # .include <bsd.own.mk> +SUBDIR= clients + TESTSDIR= ${TESTSBASE}/fs/ffs WARNS= 4 -PROGS= h_quota2_server +PROGS= h_quota2_server SRCS.h_quota2_server= h_quota2_server.c MAN.h_quota2_server= # empty BINDIR.h_quota2_server= ${TESTSDIR} +.for name in t_getquota +TESTS_SH+= ${name} +TESTS_SH_SRC_${name}= quotas_common.sh ${name}.sh +.endfor + TESTS_C+= t_fifos TESTS_C+= t_snapshot TESTS_C+= t_snapshot_log Added files: Index: src/tests/fs/ffs/quotas_common.sh diff -u /dev/null src/tests/fs/ffs/quotas_common.sh:1.1.2.1 --- /dev/null Fri Jan 28 18:38:08 2011 +++ src/tests/fs/ffs/quotas_common.sh Fri Jan 28 18:38:07 2011 @@ -0,0 +1,51 @@ +# $NetBSD: quotas_common.sh,v 1.1.2.1 2011/01/28 18:38:07 bouyer Exp $ + +create_with_quotas() +{ + local endian=$1; shift + local vers=$1; shift + local type=$1; shift + local op; + if [ ${type} = "both" ]; then + op="-q user -q group" + else + op="-q ${type}" + fi + atf_check -o ignore -e ignore newfs ${op} \ + -B ${endian} -O ${vers} -s 4000 -F ${IMG} + #atf_check -o ignore -e ignore $(atf_get_srcdir)/h_quota2_server \ + # ${IMG} ${RUMP_SERVER} + $(atf_get_srcdir)/h_quota2_server ${IMG} ${RUMP_SERVER} & +} + +# from tests/ipf/h_common.sh via tests/sbin/resize_ffs +test_case() +{ + local name="${1}"; shift + local check_function="${1}"; shift + local descr="${1}"; shift + + atf_test_case "${name}" cleanup + + eval "${name}_head() { \ + atf_set "descr" "${descr}" + }" + eval "${name}_body() { \ + ${check_function} " "${@}" "; \ + }" + eval "${name}_cleanup() { \ + atf_check -s exit:1 -o ignore -e ignore rump.halt; \ + }" + tests="${tests} ${name}" +} + +atf_init_test_cases() +{ + IMG=fsimage + DIR=target + RUMP_SERVER=unix:///tmp/test + export RUMP_SERVER + for i in ${tests}; do + atf_add_test_case $i + done +} Index: src/tests/fs/ffs/t_getquota.sh diff -u /dev/null src/tests/fs/ffs/t_getquota.sh:1.1.2.1 --- /dev/null Fri Jan 28 18:38:08 2011 +++ src/tests/fs/ffs/t_getquota.sh Fri Jan 28 18:38:07 2011 @@ -0,0 +1,101 @@ +# $NetBSD: t_getquota.sh,v 1.1.2.1 2011/01/28 18:38:07 bouyer Exp $ +# +# Copyright (c) 2011 Manuel Bouyer +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +for e in le be; do + for v in 1 2; do + for q in "user" "group"; do + test_case get_${e}_${v}_${q} get_quota \ + "get quota with ${q} enabled" ${e} ${v} ${q} + done + test_case get_${e}_${v}_"both" get_quota \ + "get quota with both enabled" ${e} ${v} "both" + done +done + +get_quota() +{ + create_with_quotas $* + local q=$3 + local expect + local fail + + case ${q} in + user) + expect=u + fail=g + ;; + group) + expect=g + fail=u + ;; + both) + expect="u g" + fail="" + ;; + *) + atf_fail "wrong quota type" + ;; + esac + +#check that we can get the expected quota + for q in ${expect} ; do + atf_check -s exit:0 \ +-o "match:/mnt 0 - - 1 - -" \ +-o "match:Disk quotas for .*: $" \ + $(atf_get_srcdir)/rump_quota -${q} -v + atf_check -s exit:0 \ +-o "match:-- 0 - - 1 - -" \ + $(atf_get_srcdir)/rump_repquota -${q} /mnt + done + +#check that we do not get positive reply for non-expected quota + for q in ${fail} ; do + atf_check -s exit:0 -o "not-match:/mnt" \ + -o "not-match:Disk quotas for .*: $" \ + -o "match:Disk quotas for .*: none$" \ + $(atf_get_srcdir)/rump_quota -${q} -v + atf_check -s exit:0 \ +-o "not-match:-- 0 - - 1 - -" \ + $(atf_get_srcdir)/rump_repquota -${q} /mnt + done + atf_check -s exit:0 rump.halt + wait $! +# check that the quota inode creation didn't corrupt the filesystem + atf_check -s exit:0 -o "match:already clean" \ + -o "match:Phase 6 - Check Quotas" \ + fsck_ffs -nf -F ${IMG} +} + +quota_enabled_both() +{ + create_with_quotas $* + +# check that the quota inode creation didn't corrupt the filesystem + atf_check -s exit:0 -o "match:already clean" -o "match:3 files" \ + -o "match:Phase 6 - Check Quotas" \ + fsck_ffs -nf -F ${IMG} +} Index: src/tests/fs/ffs/clients/Makefile diff -u /dev/null src/tests/fs/ffs/clients/Makefile:1.1.2.1 --- /dev/null Fri Jan 28 18:38:08 2011 +++ src/tests/fs/ffs/clients/Makefile Fri Jan 28 18:38:08 2011 @@ -0,0 +1,36 @@ +# $NetBSD: Makefile,v 1.1.2.1 2011/01/28 18:38:08 bouyer Exp $ +# + +.include <bsd.own.mk> + +TESTSDIR= ${TESTSBASE}/fs/ffs +WARNS= 4 + +PROGS= rump_quota rump_repquota + +.PATH: ${NETBSDSRCDIR}/usr.bin/quota +SRCS.rump_quota= quota.c printquota.c quota_rumpops.c +SRCS.rump_repquota= printquota.c quota_rumpops.c +CPPFLAGS.quota.c+= -I${NETBSDSRCDIR}/sys -I${NETBSDSRCDIR}/usr.bin/quota +CPPFLAGS.printquota.c+= -I${NETBSDSRCDIR}/sys -I${NETBSDSRCDIR}/usr.bin/quota + +.PATH: ${NETBSDSRCDIR}/usr.sbin/repquota +SRCS.rump_repquota+= repquota.c +CPPFLAGS.repquota.c+= -I${NETBSDSRCDIR}/sys -I${NETBSDSRCDIR}/usr.bin/quota + +.PATH: ${NETBSDSRCDIR}/sys/ufs/ufs +SRCS.rump_quota+= quota2_prop.c +SRCS.rump_repquota+= quota2_prop.c +CPPFLAGS.quota2_prop.c+=-I${NETBSDSRCDIR}/sys -I${NETBSDSRCDIR}/usr.bin/quota + +DPADD.rump_quota= ${LIBRPCSVC} ${LIBPROP} ${LIBRUMPCLIENT} +LDADD.rump_quota= -lrpcsvc -lprop -lrumpclient +MAN.rump_quota= # empty +BINDIR.rump_quota= ${TESTSDIR} + +DPADD.rump_repquota= ${LIBRPCSVC} ${LIBPROP} ${LIBRUMPCLIENT} +LDADD.rump_repquota= -lrpcsvc -lprop -lrumpclient +MAN.rump_repquota= # empty +BINDIR.rump_repquota= ${TESTSDIR} + +.include <bsd.test.mk> Index: src/tests/fs/ffs/clients/quota_rumpops.c diff -u /dev/null src/tests/fs/ffs/clients/quota_rumpops.c:1.1.2.1 --- /dev/null Fri Jan 28 18:38:08 2011 +++ src/tests/fs/ffs/clients/quota_rumpops.c Fri Jan 28 18:38:08 2011 @@ -0,0 +1,89 @@ +/* $NetBSD: quota_rumpops.c,v 1.1.2.1 2011/01/28 18:38:08 bouyer Exp $ */ + +/* + * Copyright (c) 2010 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +#ifndef lint +__RCSID("$NetBSD: quota_rumpops.c,v 1.1.2.1 2011/01/28 18:38:08 bouyer Exp $"); +#endif /* !lint */ + +#include <stdio.h> +#include <err.h> +#include <sys/types.h> +#include <sys/quota.h> +#include <sys/statvfs.h> + +#include <rump/rump.h> +#include <rump/rump_syscalls.h> +#include <rump/rumpclient.h> + +#ifdef DEBUGJACK +#define DPRINTF(x) mydprintf x +static void +mydprintf(const char *fmt, ...) +{ + va_list ap; + + if (ISDUP2D(STDERR_FILENO)) + return; + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); +} + +#else +#define DPRINTF(x) +#endif + +static void __attribute__((constructor)) +rcinit(void) +{ + DPRINTF("rcinit\n"); + if (rumpclient_init() == -1) + err(1, "rump client init"); +} + +int __quotactl50(const char *, struct plistref *); +int +__quotactl50(const char * mnt, struct plistref *p) +{ + int error; + error = rump_sys_quotactl(mnt, p); + DPRINTF(("quotactl <- %d\n", error)); + return error; +} + +int +getvfsstat(struct statvfs *buf, size_t bufsize, int flags) +{ + int error; + + error = rump_sys_getvfsstat(buf, bufsize, flags); + DPRINTF(("getvfsstat <- %d\n", error)); + return error; +}