xfstests: add test 185, Dmapi Punch/Probe Alignment compared to xfsctl(FREESPACE),

tests PV 976771, by trying to punch a hole that's not page aligned but block aligned
Merge of master-melb:xfs-cmds:30582a by kenmcd.

  New QA test
This commit is contained in:
Niv Sardi
2008-02-27 03:20:18 +00:00
parent 13ac0e3cd5
commit 98df5b85a7
3 changed files with 342 additions and 0 deletions
+74
View File
@@ -0,0 +1,74 @@
#! /bin/sh
# FSQA Test No. 142
#
# Dmapi Punch/Probe Alignment compared to xfsctl(FREESPACE);
#
#-----------------------------------------------------------------------
# Copyright (c) 2006 Silicon Graphics, Inc. All Rights Reserved.
#-----------------------------------------------------------------------
#
# creator
owner=xaiki@sgi.com
seq=`basename $0`
echo "QA output created by $seq"
here=`pwd`
tmp=/tmp/$$
status=1 # failure is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15
_cleanup()
{
_cleanup_testdir
}
# get standard environment, filters and checks
. ./common.rc
. ./common.filter
. ./common.dmapi
# real QA test starts here
_supported_fs xfs
_supported_os Linux IRIX
_require_scratch
_scratch_mkfs_xfs -b size=512 >/dev/null 2>&1
_dmapi_scratch_mount
cat > $tmp.dmapi-param <<EOF
# length offset
16k 0 # page aligned
1k 0 # not page aligned
# random tests
1k 4k
4k 1k
1024k 512k
EOF
mkdir -p $SCRATCH_MNT/dmapi
f=$SCRATCH_MNT/dmapi/holly_file
e=${DMAPI_QASUITE1_DIR}cmd/probe_punch_xfsctl_hole
cat $tmp.dmapi-param | sed s/'\#.*'//g| grep . |while read l o; do
echo "======================================================="
echo "Testing with length = $l, offset = $o"
echo "Method: xfsctl"
dd if=/dev/zero bs=1024k count=3 of=$f >/dev/null 2>&1
$e -x -l$l -o$o $f
echo "Method: dmapi_probe"
dd if=/dev/zero bs=1024k count=3 of=$f >/dev/null 2>&1
$e -l$l -o$o $f
echo "Method: dmapi_punch"
$e -p -l$l -o$o $f
echo "======================================================="
done
rm -rf $tmp.dmapi-param
status=0
exit
+76
View File
@@ -0,0 +1,76 @@
QA output created by 185
=======================================================
Testing with length = 16k, offset = 0
Method: xfsctl
Running Punch hole with xfsctl(XFS_IOC_FREESP64) on /mnt/scratch/dmapi/holly_file with settings:
offset = '0', length = '16384', sid = '0'
ok.
Method: dmapi_probe
Running DMAPI probe hole on /mnt/scratch/dmapi/holly_file with settings:
offset = '0', length = '16384', sid = '0'
roffp is 0, rlenp is 16384
Method: dmapi_punch
Running DMAPI punch hole on /mnt/scratch/dmapi/holly_file with settings:
offset = '0', length = '16384', sid = '0'
roffp is 4200149, rlenp is 47820330485640
=======================================================
=======================================================
Testing with length = 1k, offset = 0
Method: xfsctl
Running Punch hole with xfsctl(XFS_IOC_FREESP64) on /mnt/scratch/dmapi/holly_file with settings:
offset = '0', length = '1024', sid = '0'
ok.
Method: dmapi_probe
Running DMAPI probe hole on /mnt/scratch/dmapi/holly_file with settings:
offset = '0', length = '1024', sid = '0'
roffp is 0, rlenp is 1024
Method: dmapi_punch
Running DMAPI punch hole on /mnt/scratch/dmapi/holly_file with settings:
offset = '0', length = '1024', sid = '0'
roffp is 4200149, rlenp is 47194545715080
=======================================================
=======================================================
Testing with length = 1k, offset = 4k
Method: xfsctl
Running Punch hole with xfsctl(XFS_IOC_FREESP64) on /mnt/scratch/dmapi/holly_file with settings:
offset = '4096', length = '1024', sid = '0'
ok.
Method: dmapi_probe
Running DMAPI probe hole on /mnt/scratch/dmapi/holly_file with settings:
offset = '4096', length = '1024', sid = '0'
roffp is 4096, rlenp is 1024
Method: dmapi_punch
Running DMAPI punch hole on /mnt/scratch/dmapi/holly_file with settings:
offset = '4096', length = '1024', sid = '0'
roffp is 4200149, rlenp is 47256598480776
=======================================================
=======================================================
Testing with length = 4k, offset = 1k
Method: xfsctl
Running Punch hole with xfsctl(XFS_IOC_FREESP64) on /mnt/scratch/dmapi/holly_file with settings:
offset = '1024', length = '4096', sid = '0'
ok.
Method: dmapi_probe
Running DMAPI probe hole on /mnt/scratch/dmapi/holly_file with settings:
offset = '1024', length = '4096', sid = '0'
roffp is 1024, rlenp is 4096
Method: dmapi_punch
Running DMAPI punch hole on /mnt/scratch/dmapi/holly_file with settings:
offset = '1024', length = '4096', sid = '0'
roffp is 4200149, rlenp is 47292581427080
=======================================================
=======================================================
Testing with length = 1024k, offset = 512k
Method: xfsctl
Running Punch hole with xfsctl(XFS_IOC_FREESP64) on /mnt/scratch/dmapi/holly_file with settings:
offset = '524288', length = '1048576', sid = '0'
ok.
Method: dmapi_probe
Running DMAPI probe hole on /mnt/scratch/dmapi/holly_file with settings:
offset = '524288', length = '1048576', sid = '0'
roffp is 524288, rlenp is 1048576
Method: dmapi_punch
Running DMAPI punch hole on /mnt/scratch/dmapi/holly_file with settings:
offset = '524288', length = '1048576', sid = '0'
roffp is 4200149, rlenp is 47016592795528
=======================================================
@@ -0,0 +1,192 @@
/*
* Copyright (c) 2000-2001 Silicon Graphics, Inc.
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it would be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <lib/hsm.h>
#include <getopt.h>
#include <string.h>
/*---------------------------------------------------------------------------
Test program used to test the DMAPI function dm_probe_hole(). The
command line is:
probe_hole [-o offset] [-l length] [-s sid] pathname
where pathname is the name of a file, offset is the offset of the start of
the proposed punch, and length is the length of the punch. sid is the
session ID whose events you you are interested in.
----------------------------------------------------------------------------*/
#ifndef linux
extern char *sys_errlist[];
#endif
extern int optind;
extern char *optarg;
char *Progname;
#define METHOD_DMAPI_PROBE 0
#define METHOD_DMAPI_PUNCH 1
#define METHOD_XFSCTL 2
char *methodmap[] = {"DMAPI probe hole",
"DMAPI punch hole",
"Punch hole with xfsctl(XFS_IOC_FREESP64)"};
static void
usage(void)
{
fprintf(stderr, "usage:\t%s [-x|-p] [-o offset] [-l length] "
"[-s sid] pathname\n", Progname);
exit(1);
}
int
xfsctl_punch_hole(
char *path,
dm_off_t offset,
dm_size_t length)
{
xfs_flock64_t flock;
int fd;
if ((fd = open(path, O_RDWR|O_CREAT)) < 0) {
perror(path);
exit(errno);
}
flock.l_whence = 0;
flock.l_start = offset;
flock.l_len = length;
if (xfsctl(path, fd, XFS_IOC_FREESP64, &flock)) {
fprintf(stderr, "can't XFS_IOC_FREESP64 %s: %s\n",
path, strerror(errno));
return errno;
}
close(fd);
printf("ok.\n");
return 0;
}
int
main(
int argc,
char **argv)
{
dm_sessid_t sid = DM_NO_SESSION;
char *pathname = NULL;
dm_off_t offset = 0;
dm_size_t length = 0;
dm_off_t roffp;
dm_size_t rlenp;
void *hanp;
size_t hlen;
char *name;
char *p;
int opt;
int method = METHOD_DMAPI_PROBE;
if (Progname = strrchr(argv[0], '/')) {
Progname++;
} else {
Progname = argv[0];
}
/* Crack and validate the command line options. */
while ((opt = getopt(argc, argv, "o:l:s:xp")) != EOF) {
switch (opt) {
case 'o':
offset = strtoll(optarg, &p, 10);
if (p && (*p == 'k' || *p == 'K'))
offset *= 1024;
break;
case 'l':
length = strtoll(optarg, &p, 10);
if (p && (*p == 'k' || *p == 'K'))
length *= 1024;
break;
case 's':
sid = atol(optarg);
break;
case 'x':
method = METHOD_XFSCTL;
break;
case 'p':
method = METHOD_DMAPI_PUNCH;
break;
case '?':
usage();
}
}
if (optind + 1 != argc)
usage();
pathname = argv[optind];
if (!pathname)
usage();
printf("Running %s on %s with settings:\n", methodmap[method], pathname);
printf(" offset = '%lld', length = '%lld', sid = '%lld'\n", offset, length, sid);
if (method == METHOD_XFSCTL)
return xfsctl_punch_hole(pathname, offset, length);
if (dm_init_service(&name) == -1) {
fprintf(stderr, "Can't initialize the DMAPI\n");
exit(1);
}
if (sid == DM_NO_SESSION)
find_test_session(&sid);
/* Get the file's handle. */
if (dm_path_to_handle(pathname, &hanp, &hlen)) {
fprintf(stderr, "can't get handle for file %s\n", pathname);
exit(1);
}
switch(method) {
case METHOD_DMAPI_PROBE:
if (dm_probe_hole(sid, hanp, hlen, DM_NO_TOKEN, offset, length,
&roffp, &rlenp)) {
fprintf(stderr, "dm_probe_hole failed, %s\n",
strerror(errno));
exit(1);
}
break;
case METHOD_DMAPI_PUNCH:
if (dm_punch_hole(sid, hanp, hlen, DM_NO_TOKEN, offset, length)) {
fprintf(stderr, "dm_punch_hole failed, %s\n",
strerror(errno));
exit(1);
}
break;
}
fprintf(stdout, "roffp is %lld, rlenp is %lld\n", roffp, rlenp);
dm_handle_free(hanp, hlen);
return 0;
}