From owner-svn-src-user@freebsd.org Wed Apr 4 11:05:36 2018 Return-Path: Delivered-To: svn-src-user@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 449F6F842C7 for ; Wed, 4 Apr 2018 11:05:36 +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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id EC45C73374; Wed, 4 Apr 2018 11:05:35 +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 E68BE12D71; Wed, 4 Apr 2018 11:05:35 +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 w34B5ZWd011495; Wed, 4 Apr 2018 11:05:35 GMT (envelope-from pho@FreeBSD.org) Received: (from pho@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w34B5Z65011494; Wed, 4 Apr 2018 11:05:35 GMT (envelope-from pho@FreeBSD.org) Message-Id: <201804041105.w34B5Z65011494@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pho set sender to pho@FreeBSD.org using -f From: Peter Holm Date: Wed, 4 Apr 2018 11:05:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r332005 - 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: 332005 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.25 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: Wed, 04 Apr 2018 11:05:36 -0000 Author: pho Date: Wed Apr 4 11:05:35 2018 New Revision: 332005 URL: https://svnweb.freebsd.org/changeset/base/332005 Log: Added a regression test for seekdir/telldir. Sponsored by: Dell EMC Isilon Added: user/pho/stress2/misc/seekdir.sh (contents, props changed) Added: user/pho/stress2/misc/seekdir.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/pho/stress2/misc/seekdir.sh Wed Apr 4 11:05:35 2018 (r332005) @@ -0,0 +1,160 @@ +#!/bin/sh + +# A regression test for seekdir/telldir +# submitted by julian@freebsd.org +# https://reviews.freebsd.org/D2410. +# Fixed by r282485 + +# $FreeBSD$ + +. ../default.cfg + +odir=`pwd` +cd /tmp +sed '1,/^EOF/d' < $odir/$0 > seekdir.c +rm -f /tmp/seekdir +mycc -o seekdir -O2 seekdir.c || exit 1 +rm -f seekdir.c +cd $odir + +mount | grep -q "$mntpoint " && umount -f $mntpoint +mount -o size=1g -t tmpfs tmpfs $mntpoint + +cd $mntpoint +mkdir test2 +/tmp/seekdir > /dev/null +[ `echo $mntpoint/test2/* | wc -w` -eq 1 ] || + { echo FAIL; status=1; } +cd $odir + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +rm -f /tmp/seekdir +exit $status +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define CHUNKSIZE 5 +#define TOTALFILES 40 + +static void +SeekDir(DIR *dirp, long loc) +{ + printf("Seeking back to location %ld\n", loc); + seekdir(dirp, loc); +} + +static long +TellDir(DIR *dirp) +{ + long loc; + + loc = telldir(dirp); + printf("telldir assigned location %ld\n", loc); + return (loc); +} + +int +main(int argc, char *argv[]) +{ + DIR *dirp; + int i; + int j; + long offset = 0, prev_offset = 0; + char *files[100]; + char filename[100]; + int fd; + struct dirent *dp = NULL; + + if (chdir("./test2") != 0) { + err(EX_OSERR, "chdir"); + } + + /*****************************************************/ + /* Put a set of sample files in the target directory */ + /*****************************************************/ + + for (i=1; i < TOTALFILES ; i++) + { + sprintf(filename, "file-%d", i); + fd = open(filename, O_CREAT, 0666); + if (fd == -1) { + err(EX_OSERR, "open"); + } + close(fd); + } + dirp = opendir("."); + offset = TellDir(dirp); + for (i = 0; i < 20; i++) + files[i] = malloc(20); + + /*******************************************************/ + /* enumerate and delete small sets of files, one group */ + /* at a time. */ + /*******************************************************/ + do { + + /*****************************************/ + /* Read in up to CHUNKSIZE file names */ + /* i will be the number of files we hold */ + /*****************************************/ + for (i = 0; i < CHUNKSIZE; i++) { + if ((dp = readdir(dirp)) != NULL) { + strcpy(files[i], dp->d_name); + + printf("readdir (%ld) returned file %s\n", + offset, files[i]); + + prev_offset = offset; + offset = TellDir(dirp); + + } else { + printf("readdir returned null\n"); + break; + } + } + + +/****************************************************************/ + /* Simuate the last entry not fitting into our (samba's) buffer */ + /* If we read someting in on the last slot, push it back */ + /* Pretend it didn't fit. This is approximately what SAMBA does.*/ +/****************************************************************/ + if (dp != NULL) { + /* Step back */ + SeekDir(dirp, prev_offset); + offset = TellDir(dirp); + i--; + printf("file %s returned\n", files[i]); + } + + /*****************************************/ + /* i is the number of names we have left.*/ + /* Delete them. */ + /*****************************************/ + for (j = 0; j < i; j++) { + if (*files[j] == '.') { + printf ("skipping %s\n", files[j]); + } else { + printf("Unlinking file %s\n", files[j]); + if (unlink(files[j]) != 0) { + err(EX_OSERR, "unlink"); + } + } + } + } while (dp != NULL); + + closedir(dirp); + //chdir(".."); + +}