xfs: test attr_list_by_handle cursor iteration

Apparently the XFS attr_list_by_handle ioctl has never actually
copied the cursor contents back to user space, which means that
iteration has never worked.  Add a test case for this and see

"xfs: in _attrlist_by_handle, copy the cursor back to userspace".

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
This commit is contained in:
Darrick J. Wong
2016-08-04 19:03:51 -07:00
committed by Eryu Guan
parent 27516d43f4
commit 73f8e854f6
6 changed files with 191 additions and 1 deletions
+1
View File
@@ -38,6 +38,7 @@
/src/alloc /src/alloc
/src/append_reader /src/append_reader
/src/append_writer /src/append_writer
/src/attr-list-by-handle-cursor-test
/src/bstat /src/bstat
/src/bulkstat_unlink_test /src/bulkstat_unlink_test
/src/bulkstat_unlink_test_modified /src/bulkstat_unlink_test_modified
+2 -1
View File
@@ -20,7 +20,8 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \
bulkstat_unlink_test_modified t_dir_offset t_futimens t_immutable \ bulkstat_unlink_test_modified t_dir_offset t_futimens t_immutable \
stale_handle pwrite_mmap_blocked t_dir_offset2 seek_sanity_test \ stale_handle pwrite_mmap_blocked t_dir_offset2 seek_sanity_test \
seek_copy_test t_readdir_1 t_readdir_2 fsync-tester nsexec cloner \ seek_copy_test t_readdir_1 t_readdir_2 fsync-tester nsexec cloner \
renameat2 t_getcwd e4compact test-nextquota punch-alternating renameat2 t_getcwd e4compact test-nextquota punch-alternating \
attr-list-by-handle-cursor-test
SUBDIRS = SUBDIRS =
+118
View File
@@ -0,0 +1,118 @@
/*
* Copyright (C) 2016 Oracle. All Rights Reserved.
*
* Author: Darrick J. Wong <darrick.wong@oracle.com>
*
* 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; either version 2
* of the License, or (at your option) any later version.
*
* 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 <sys/types.h>
#include <sys/stat.h>
#include <attr/attributes.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <asm/types.h>
#include <xfs/xfs.h>
#include <xfs/handle.h>
#define ATTRBUFSZ 1024
#define BSTATBUF_NR 32
/* Read all the extended attributes of a file handle. */
void
read_handle_xattrs(
struct xfs_handle *handle)
{
struct attrlist_cursor cur;
char attrbuf[ATTRBUFSZ];
char *firstname = NULL;
struct attrlist *attrlist = (struct attrlist *)attrbuf;
struct attrlist_ent *ent;
int i;
int flags = 0;
int error;
memset(&cur, 0, sizeof(cur));
while ((error = attr_list_by_handle(handle, sizeof(*handle),
attrbuf, ATTRBUFSZ, flags,
&cur)) == 0) {
for (i = 0; i < attrlist->al_count; i++) {
ent = ATTR_ENTRY(attrlist, i);
if (i != 0)
continue;
if (firstname == NULL) {
firstname = malloc(ent->a_valuelen);
memcpy(firstname, ent->a_name, ent->a_valuelen);
} else {
if (memcmp(firstname, ent->a_name,
ent->a_valuelen) == 0)
fprintf(stderr,
"Saw duplicate xattr \"%s\", buggy XFS?\n",
ent->a_name);
else
fprintf(stderr,
"Test passes.\n");
goto out;
}
}
if (!attrlist->al_more)
break;
}
out:
if (firstname)
free(firstname);
if (error)
perror("attr_list_by_handle");
return;
}
int main(
int argc,
char *argv[])
{
struct xfs_handle *fshandle;
size_t fshandle_len;
struct xfs_handle *handle;
size_t handle_len;
int error;
if (argc != 2) {
fprintf(stderr, "Usage: %s filename\n", argv[0]);
return 1;
}
error = path_to_fshandle(argv[1], (void **)&fshandle, &fshandle_len);
if (error) {
perror("getting fshandle");
return 2;
}
error = path_to_handle(argv[1], (void **)&handle, &handle_len);
if (error) {
perror("getting handle");
return 3;
}
read_handle_xattrs(handle);
free_handle(handle, handle_len);
free_handle(fshandle, fshandle_len);
return 0;
}
Executable
+64
View File
@@ -0,0 +1,64 @@
#! /bin/bash
# FS QA Test No. 269
#
# Check that attr_list_by_handle copies the cursor back to userspace.
#
#-----------------------------------------------------------------------
# Copyright (c) 2016, Oracle and/or its affiliates. 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
#-----------------------------------------------------------------------
seq=`basename "$0"`
seqres="$RESULT_DIR/$seq"
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()
{
cd /
rm -rf "$tmp".* $TEST_DIR/fsmap $TEST_DIR/testout
}
# get standard environment, filters and checks
. ./common/rc
. ./common/filter
. ./common/attr
. ./common/populate
# real QA test starts here
_supported_os Linux
_require_scratch
_require_test_program "attr-list-by-handle-cursor-test"
rm -f "$seqres.full"
echo "Format and mount"
_scratch_mkfs > "$seqres.full" 2>&1
_scratch_mount
echo "Stuff file with xattrs"
mkdir $SCRATCH_MNT/foo
__populate_create_attr $SCRATCH_MNT/foo 100
echo "Run test program"
./src/attr-list-by-handle-cursor-test $SCRATCH_MNT/foo
# success, all done
status=0
exit
+5
View File
@@ -0,0 +1,5 @@
QA output created by 269
Format and mount
Stuff file with xattrs
Run test program
Test passes.
+1
View File
@@ -264,6 +264,7 @@
266 dump ioctl auto quick 266 dump ioctl auto quick
267 dump ioctl tape 267 dump ioctl tape
268 dump ioctl tape 268 dump ioctl tape
269 auto quick ioctl
278 repair auto 278 repair auto
279 auto mkfs 279 auto mkfs
281 dump ioctl auto quick 281 dump ioctl auto quick