Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/bouyer-quota2]: src/tests/fs/ffs Check that the kernel enforces the quot...



details:   https://anonhg.NetBSD.org/src/rev/8caca4bc8a29
branches:  bouyer-quota2
changeset: 761104:8caca4bc8a29
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Wed Feb 02 19:17:08 2011 +0000

description:
Check that the kernel enforces the quota limits and grace times.

diffstat:

 tests/fs/ffs/Makefile         |   10 +-
 tests/fs/ffs/clients/Makefile |   14 +-
 tests/fs/ffs/h_quota2_tests.c |  313 ++++++++++++++++++++++++++++++++++++++++++
 tests/fs/ffs/quotas_common.sh |    7 +-
 tests/fs/ffs/t_getquota.sh    |    4 +-
 tests/fs/ffs/t_quotalimit.sh  |  229 ++++++++++++++++++++++++++++++
 tests/fs/ffs/t_setquota.sh    |    8 +-
 7 files changed, 573 insertions(+), 12 deletions(-)

diffs (truncated from 697 to 300 lines):

diff -r ee236102549e -r 8caca4bc8a29 tests/fs/ffs/Makefile
--- a/tests/fs/ffs/Makefile     Mon Jan 31 22:04:26 2011 +0000
+++ b/tests/fs/ffs/Makefile     Wed Feb 02 19:17:08 2011 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.14.2.3 2011/01/30 12:37:34 bouyer Exp $
+#      $NetBSD: Makefile,v 1.14.2.4 2011/02/02 19:17:08 bouyer Exp $
 #
 
 .include <bsd.own.mk>
@@ -8,12 +8,16 @@
 TESTSDIR=      ${TESTSBASE}/fs/ffs
 WARNS=         4
 
-PROGS=                 h_quota2_server 
+PROGS=                 h_quota2_server h_quota2_tests
 SRCS.h_quota2_server=  h_quota2_server.c
 MAN.h_quota2_server=   # empty
 BINDIR.h_quota2_server=        ${TESTSDIR}
 
-.for name in t_getquota t_setquota
+SRCS.h_quota2_tests=   h_quota2_tests.c
+MAN.h_quota2_tests=    # empty
+BINDIR.h_quota2_tests= ${TESTSDIR}
+
+.for name in t_getquota t_setquota t_quotalimit
 TESTS_SH+=     ${name}
 TESTS_SH_SRC_${name}=  quotas_common.sh ${name}.sh
 .endfor
diff -r ee236102549e -r 8caca4bc8a29 tests/fs/ffs/clients/Makefile
--- a/tests/fs/ffs/clients/Makefile     Mon Jan 31 22:04:26 2011 +0000
+++ b/tests/fs/ffs/clients/Makefile     Wed Feb 02 19:17:08 2011 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.1.2.3 2011/01/30 00:27:56 bouyer Exp $
+#      $NetBSD: Makefile,v 1.1.2.4 2011/02/02 19:17:09 bouyer Exp $
 #
 
 .include <bsd.own.mk>
@@ -6,7 +6,7 @@
 TESTSDIR=      ${TESTSBASE}/fs/ffs
 WARNS=         4
 
-PROGS=                 rump_quota rump_repquota rump_edquota
+PROGS=                 rump_quota rump_repquota rump_edquota rump_quotactl
 
 .PATH: ${NETBSDSRCDIR}/usr.bin/quota
 SRCS.rump_quota=       quota.c printquota.c getvfsquota.c quota_rumpops.c
@@ -24,10 +24,15 @@
 SRCS.rump_edquota+=    edquota.c
 CPPFLAGS.edquota.c+=   -I${NETBSDSRCDIR}/sys -I${NETBSDSRCDIR}/usr.bin/quota
 
+.PATH: ${NETBSDSRCDIR}/usr.sbin/quotactl
+SRCS.rump_quotactl+=   quotactl.c quota_rumpops.c
+CPPFLAGS.quotactl.c+=  -I${NETBSDSRCDIR}/sys
+
 .PATH:  ${NETBSDSRCDIR}/sys/ufs/ufs 
 SRCS.rump_quota+=      quota2_prop.c
 SRCS.rump_repquota+=   quota2_prop.c quota1_subr.c
 SRCS.rump_edquota+=    quota2_prop.c quota1_subr.c
+SRCS.rump_quotactl+=   quota2_prop.c
 CPPFLAGS.quota2_prop.c+=-I${NETBSDSRCDIR}/sys
 CPPFLAGS.quota1_subr.c+=-I${NETBSDSRCDIR}/sys
 
@@ -46,4 +51,9 @@
 MAN.rump_edquota=      # empty
 BINDIR.rump_edquota=   ${TESTSDIR}
 
+DPADD.rump_quotactl=   ${LIBRPCSVC} ${LIBPROP} ${LIBRUMPCLIENT}
+LDADD.rump_quotactl=   -lrpcsvc -lprop -lrumpclient
+MAN.rump_quotactl=     # empty
+BINDIR.rump_quotactl=  ${TESTSDIR}
+
 .include <bsd.test.mk>
diff -r ee236102549e -r 8caca4bc8a29 tests/fs/ffs/h_quota2_tests.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fs/ffs/h_quota2_tests.c     Wed Feb 02 19:17:08 2011 +0000
@@ -0,0 +1,313 @@
+/*     $NetBSD: h_quota2_tests.c,v 1.1.2.1 2011/02/02 19:17:08 bouyer Exp $    */
+
+/*
+ * rump server for advanced quota tests
+ * this one includes functions to run against the filesystem before
+ * starting to handle rump requests from clients.
+ */
+
+#include "../common/h_fsmacros.h"
+
+#include <err.h>
+#include <semaphore.h>
+#include <sys/types.h>
+#include <sys/mount.h>
+
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <ufs/ufs/ufsmount.h>
+
+#include <rump/rump.h>
+#include <rump/rump_syscalls.h>
+
+#include "../../h_macros.h"
+
+int background = 0;
+
+#define TEST_NONROOT_ID 1
+
+static int
+quota_test0(void)
+{
+       static char buf[512];
+       int fd;
+       int error;
+       rump_sys_chown(".", TEST_NONROOT_ID, TEST_NONROOT_ID);
+       if (rump_sys_setegid(TEST_NONROOT_ID) != 0) {
+               error = errno;
+               perror("rump_sys_setegid");
+               return error;
+       }
+       if (rump_sys_seteuid(TEST_NONROOT_ID) != 0) {
+               error = errno;
+               perror("rump_sys_seteuid");
+               return error;
+       }
+       fd = rump_sys_open("test_fillup", O_CREAT | O_RDWR, 0644);
+       if (fd < 0) {
+               error = errno;
+               perror("rump_sys_open");
+       } else {
+               while (rump_sys_write(fd, buf, sizeof(buf)) == sizeof(buf))
+                       error = 0;
+               error = errno;
+       }
+       rump_sys_close(fd);
+       rump_sys_seteuid(0);
+       rump_sys_setegid(0);
+       return error;
+}
+
+static int
+quota_test1(void)
+{
+       static char buf[512];
+       int fd;
+       int error;
+       rump_sys_chown(".", TEST_NONROOT_ID, TEST_NONROOT_ID);
+       if (rump_sys_setegid(TEST_NONROOT_ID) != 0) {
+               error = errno;
+               perror("rump_sys_setegid");
+               return error;
+       }
+       if (rump_sys_seteuid(TEST_NONROOT_ID) != 0) {
+               error = errno;
+               perror("rump_sys_seteuid");
+               return error;
+       }
+       fd = rump_sys_open("test_fillup", O_CREAT | O_RDWR, 0644);
+       if (fd < 0) {
+               error = errno;
+               perror("rump_sys_open");
+       } else {
+               /*
+                * write up to the soft limit, wait a bit, an try to
+                * keep on writing
+                */
+               int i;
+
+               /* write 1.5k: with the directory this makes 2K */
+               for (i = 0; i < 3; i++) {
+                       error = rump_sys_write(fd, buf, sizeof(buf));
+                       if (error != sizeof(buf))
+                               err(1, "write failed early");
+               }
+               sleep(2);
+               /* now try to write an extra .5k */
+               if (rump_sys_write(fd, buf, sizeof(buf)) != sizeof(buf))
+                       error = errno;
+               else
+                       error = 0;
+       }
+       rump_sys_close(fd);
+       rump_sys_seteuid(0);
+       rump_sys_setegid(0);
+       return error;
+}
+
+static int
+quota_test2(void)
+{
+       static char buf[512];
+       int fd;
+       int error;
+       int i;
+       rump_sys_chown(".", TEST_NONROOT_ID, TEST_NONROOT_ID);
+       if (rump_sys_setegid(TEST_NONROOT_ID) != 0) {
+               error = errno;
+               perror("rump_sys_setegid");
+               return error;
+       }
+       if (rump_sys_seteuid(TEST_NONROOT_ID) != 0) {
+               error = errno;
+               perror("rump_sys_seteuid");
+               return error;
+       }
+
+       for (i = 0; ; i++) {
+               sprintf(buf, "file%d", i);
+               fd = rump_sys_open(buf, O_CREAT | O_RDWR, 0644);
+               if (fd < 0)
+                       break;
+               sprintf(buf, "test file no %d", i);
+               rump_sys_write(fd, buf, strlen(buf));
+               rump_sys_close(fd);
+       }
+       error = errno;
+       
+       rump_sys_close(fd);
+       rump_sys_seteuid(0);
+       rump_sys_setegid(0);
+       return error;
+}
+
+static int
+quota_test3(void)
+{
+       static char buf[512];
+       int fd;
+       int error;
+       int i;
+       rump_sys_chown(".", TEST_NONROOT_ID, TEST_NONROOT_ID);
+       if (rump_sys_setegid(TEST_NONROOT_ID) != 0) {
+               error = errno;
+               perror("rump_sys_setegid");
+               return error;
+       }
+       if (rump_sys_seteuid(TEST_NONROOT_ID) != 0) {
+               error = errno;
+               perror("rump_sys_seteuid");
+               return error;
+       }
+
+       /*
+        * create files up to the soft limit: one less as we already own the
+        * root directory
+        */
+       for (i = 0; i < 3; i++) {
+               sprintf(buf, "file%d", i);
+               fd = rump_sys_open(buf, O_EXCL| O_CREAT | O_RDWR, 0644);
+               if (fd < 0)
+                       err(1, "file create failed early");
+               sprintf(buf, "test file no %d", i);
+               rump_sys_write(fd, buf, strlen(buf));
+               rump_sys_close(fd);
+       }
+       /* now create an extra file after grace time: this should fail */
+       sleep(2);
+       sprintf(buf, "file%d", i);
+       fd = rump_sys_open(buf, O_EXCL| O_CREAT | O_RDWR, 0644);
+       if (fd < 0)
+               error = errno;
+       else
+               error = 0;
+       
+       rump_sys_close(fd);
+       rump_sys_seteuid(0);
+       rump_sys_setegid(0);
+       return error;
+}
+
+struct quota_test {
+       int (*func)(void);
+       const char *desc;
+};
+
+struct quota_test quota_tests[] = {
+       { quota_test0, "write up to hard limit"},
+       { quota_test1, "write beyond the soft limit after grace time"},
+       { quota_test2, "create file up to hard limit"},
+       { quota_test3, "create file beyond the soft limit after grace time"},
+};
+
+static void
+usage(void)
+{
+       fprintf(stderr, "usage: %s [-b] test# diskimage bindurl\n",
+           getprogname());
+       exit(1);
+}
+
+static void
+die(const char *reason, int error)
+{
+
+       warnx("%s: %s", reason, strerror(error));
+       if (background)
+               rump_daemonize_done(error);
+       exit(1);
+}
+
+static sem_t sigsem;
+static void
+sigreboot(int sig)



Home | Main Index | Thread Index | Old Index