Skip to content

Commit

Permalink
Have mount tests also poke at rename across directories.
Browse files Browse the repository at this point in the history
  • Loading branch information
garlick committed Mar 12, 2010
1 parent 4399d22 commit 4722a94
Show file tree
Hide file tree
Showing 14 changed files with 181 additions and 31 deletions.
31 changes: 26 additions & 5 deletions diod/ops.c
Expand Up @@ -1191,17 +1191,38 @@ diod_wstat(Npfid *fid, Npstat *st)
}
if (_fidstat (f) < 0)
goto done;
if (st->name.len != 0) {
np_werror ("Rename via wstat is deprecated in 9P2000.h", EIO);
msg ("diod_wstat: rejecting deprecated wstat rename");
goto done;
}
if (!(ret = np_create_rwstat())) {
np_uerror (ENOMEM);
msg ("diod_wstat: out of memory");
goto done;
}

/* rename */
if (st->name.len != 0) {
char *p = strrchr(f->path, '/');
char *npath;

if (!p)
p = f->path + strlen(f->path);
if (!(npath = malloc(st->name.len + (p - f->path) + 2))) {
msg ("diod_wstat: out of memory");
goto done;
}
memcpy(npath, f->path, p - f->path);
npath[p - f->path] = '/';
memcpy(npath + (p - f->path) + 1, st->name.str, st->name.len);
npath[(p - f->path) + 1 + st->name.len] = 0;
if (strcmp(npath, f->path) != 0) {
if (rename(f->path, npath) < 0) {
np_uerror (errno);
free (npath);
goto done;
}
free (f->path);
f->path = npath;
}
}

/* chmod */
if (st->mode != (u32)~0) {
mode_t umode = _np2umode(st->mode, &st->extension);
Expand Down
12 changes: 7 additions & 5 deletions test/Makefile.am
@@ -1,12 +1,13 @@
check_PROGRAMS = tsetuid tsetfsuid tsetfsuidsupp tsuppgrp tfcntl tstatfs
check_PROGRAMS = \
tsetuid tsetfsuid tsetfsuidsupp tsuppgrp tfcntl tstatfs trename

TESTS_ENVIRONMENT = env
TESTS_ENVIRONMENT += "PATH_DIOD=$(top_builddir)/diod/diod"
TESTS_ENVIRONMENT += "PATH_DIODCTL=$(top_builddir)/diodctl/diodctl"
TESTS_ENVIRONMENT += "PATH_DIODMOUNT=$(top_builddir)/diodmount/diodmount"
TESTS_ENVIRONMENT += "PATH_DIODCONF=$(top_builddir)/etc/diod.conf"
TESTS_ENVIRONMENT += "PATH_MNTDIR=$(shell readlink -f $(top_builddir)/test/mnt.d)"
TESTS_ENVIRONMENT += "PATH_EXPDIR=$(shell readlink -f $(top_builddir)/test/exp.d)"
TESTS_ENVIRONMENT += "PATH_MNTDIR=$(shell readlink -f mnt.d)"
TESTS_ENVIRONMENT += "PATH_EXPDIR=$(shell readlink -f exp.d)"

TESTS = \
t00-pthreads-setfsuid \
Expand All @@ -23,9 +24,9 @@ TESTS = \
t11-mount-9P2000.L \
t12-mount-9P2000.H

$(TESTS): $(top_builddir)/test/mnt.d $(top_builddir)/test/exp.d
$(TESTS): mnt.d exp.d

$(top_builddir)/test/mnt.d $(top_builddir)/test/exp.d:
mnt.d exp.d:
mkdir -p $@

CLEANFILES = *.out *.diff
Expand All @@ -48,6 +49,7 @@ tsetfsuid_SOURCES = tsetfsuid.c $(common_sources)
tsetfsuidsupp_SOURCES = tsetfsuidsupp.c $(common_sources)
tfcntl_SOURCES = tfcntl.c $(common_sources)
tstatfs_SOURCES = tstatfs.c $(common_sources)
trename_SOURCES = trename.c $(common_sources)

clean: clean-am
rmdir $(top_builddir)/test/mnt.d $(top_builddir)/test/exp.d
46 changes: 36 additions & 10 deletions test/Makefile.in
Expand Up @@ -37,7 +37,8 @@ build_triplet = @build@
host_triplet = @host@
target_triplet = @target@
check_PROGRAMS = tsetuid$(EXEEXT) tsetfsuid$(EXEEXT) \
tsetfsuidsupp$(EXEEXT) tsuppgrp$(EXEEXT) tfcntl$(EXEEXT)
tsetfsuidsupp$(EXEEXT) tsuppgrp$(EXEEXT) tfcntl$(EXEEXT) \
tstatfs$(EXEEXT) trename$(EXEEXT)
subdir = test
DIST_COMMON = README $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
Expand All @@ -61,6 +62,14 @@ tfcntl_DEPENDENCIES = $(top_builddir)/common/libdiod.a \
$(top_builddir)/liblsd/liblsd.a $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
am_trename_OBJECTS = trename.$(OBJEXT) $(am__objects_1)
trename_OBJECTS = $(am_trename_OBJECTS)
trename_LDADD = $(LDADD)
trename_DEPENDENCIES = $(top_builddir)/common/libdiod.a \
$(top_builddir)/npfs/libnpfs/libnpfs.a \
$(top_builddir)/liblsd/liblsd.a $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
am_tsetfsuid_OBJECTS = tsetfsuid.$(OBJEXT) $(am__objects_1)
tsetfsuid_OBJECTS = $(am_tsetfsuid_OBJECTS)
tsetfsuid_LDADD = $(LDADD)
Expand All @@ -85,6 +94,14 @@ tsetuid_DEPENDENCIES = $(top_builddir)/common/libdiod.a \
$(top_builddir)/liblsd/liblsd.a $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
am_tstatfs_OBJECTS = tstatfs.$(OBJEXT) $(am__objects_1)
tstatfs_OBJECTS = $(am_tstatfs_OBJECTS)
tstatfs_LDADD = $(LDADD)
tstatfs_DEPENDENCIES = $(top_builddir)/common/libdiod.a \
$(top_builddir)/npfs/libnpfs/libnpfs.a \
$(top_builddir)/liblsd/liblsd.a $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
am_tsuppgrp_OBJECTS = tsuppgrp.$(OBJEXT) $(am__objects_1)
tsuppgrp_OBJECTS = $(am_tsuppgrp_OBJECTS)
tsuppgrp_LDADD = $(LDADD)
Expand All @@ -100,12 +117,12 @@ COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
SOURCES = $(tfcntl_SOURCES) $(tsetfsuid_SOURCES) \
$(tsetfsuidsupp_SOURCES) $(tsetuid_SOURCES) \
$(tsuppgrp_SOURCES)
DIST_SOURCES = $(tfcntl_SOURCES) $(tsetfsuid_SOURCES) \
$(tsetfsuidsupp_SOURCES) $(tsetuid_SOURCES) \
SOURCES = $(tfcntl_SOURCES) $(trename_SOURCES) $(tsetfsuid_SOURCES) \
$(tsetfsuidsupp_SOURCES) $(tsetuid_SOURCES) $(tstatfs_SOURCES) \
$(tsuppgrp_SOURCES)
DIST_SOURCES = $(tfcntl_SOURCES) $(trename_SOURCES) \
$(tsetfsuid_SOURCES) $(tsetfsuidsupp_SOURCES) \
$(tsetuid_SOURCES) $(tstatfs_SOURCES) $(tsuppgrp_SOURCES)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
Expand Down Expand Up @@ -231,8 +248,8 @@ TESTS_ENVIRONMENT = env "PATH_DIOD=$(top_builddir)/diod/diod" \
"PATH_DIODCTL=$(top_builddir)/diodctl/diodctl" \
"PATH_DIODMOUNT=$(top_builddir)/diodmount/diodmount" \
"PATH_DIODCONF=$(top_builddir)/etc/diod.conf" \
"PATH_MNTDIR=$(shell readlink -f $(top_builddir)/test/mnt.d)" \
"PATH_EXPDIR=$(shell readlink -f $(top_builddir)/test/exp.d)"
"PATH_MNTDIR=$(shell readlink -f mnt.d)" "PATH_EXPDIR=$(shell \
readlink -f exp.d)"
TESTS = \
t00-pthreads-setfsuid \
t01-setfsuid-setgroups \
Expand Down Expand Up @@ -266,6 +283,7 @@ tsetfsuid_SOURCES = tsetfsuid.c $(common_sources)
tsetfsuidsupp_SOURCES = tsetfsuidsupp.c $(common_sources)
tfcntl_SOURCES = tfcntl.c $(common_sources)
tstatfs_SOURCES = tstatfs.c $(common_sources)
trename_SOURCES = trename.c $(common_sources)
all: all-am

.SUFFIXES:
Expand Down Expand Up @@ -305,6 +323,9 @@ clean-checkPROGRAMS:
tfcntl$(EXEEXT): $(tfcntl_OBJECTS) $(tfcntl_DEPENDENCIES)
@rm -f tfcntl$(EXEEXT)
$(LINK) $(tfcntl_LDFLAGS) $(tfcntl_OBJECTS) $(tfcntl_LDADD) $(LIBS)
trename$(EXEEXT): $(trename_OBJECTS) $(trename_DEPENDENCIES)
@rm -f trename$(EXEEXT)
$(LINK) $(trename_LDFLAGS) $(trename_OBJECTS) $(trename_LDADD) $(LIBS)
tsetfsuid$(EXEEXT): $(tsetfsuid_OBJECTS) $(tsetfsuid_DEPENDENCIES)
@rm -f tsetfsuid$(EXEEXT)
$(LINK) $(tsetfsuid_LDFLAGS) $(tsetfsuid_OBJECTS) $(tsetfsuid_LDADD) $(LIBS)
Expand All @@ -314,6 +335,9 @@ tsetfsuidsupp$(EXEEXT): $(tsetfsuidsupp_OBJECTS) $(tsetfsuidsupp_DEPENDENCIES)
tsetuid$(EXEEXT): $(tsetuid_OBJECTS) $(tsetuid_DEPENDENCIES)
@rm -f tsetuid$(EXEEXT)
$(LINK) $(tsetuid_LDFLAGS) $(tsetuid_OBJECTS) $(tsetuid_LDADD) $(LIBS)
tstatfs$(EXEEXT): $(tstatfs_OBJECTS) $(tstatfs_DEPENDENCIES)
@rm -f tstatfs$(EXEEXT)
$(LINK) $(tstatfs_LDFLAGS) $(tstatfs_OBJECTS) $(tstatfs_LDADD) $(LIBS)
tsuppgrp$(EXEEXT): $(tsuppgrp_OBJECTS) $(tsuppgrp_DEPENDENCIES)
@rm -f tsuppgrp$(EXEEXT)
$(LINK) $(tsuppgrp_LDFLAGS) $(tsuppgrp_OBJECTS) $(tsuppgrp_LDADD) $(LIBS)
Expand All @@ -325,9 +349,11 @@ distclean-compile:
-rm -f *.tab.c

@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tfcntl.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/trename.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tsetfsuid.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tsetfsuidsupp.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tsetuid.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tstatfs.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tsuppgrp.Po@am__quote@

.c.o:
Expand Down Expand Up @@ -583,9 +609,9 @@ uninstall-am: uninstall-info-am
uninstall-am uninstall-info-am


$(TESTS): $(top_builddir)/test/mnt.d $(top_builddir)/test/exp.d
$(TESTS): mnt.d exp.d

$(top_builddir)/test/mnt.d $(top_builddir)/test/exp.d:
mnt.d exp.d:
mkdir -p $@

clean: clean-am
Expand Down
6 changes: 4 additions & 2 deletions test/t04.exp
Expand Up @@ -2,5 +2,7 @@ tfcntl: proc0: locking bytes 0-64
tfcntl: proc0: locking bytes 32-64
tfcntl: proc1: locking bytes 0-64
tfcntl: proc2: locking bytes 32-64
tfcntl: proc0(child): locking bytes 32-64
tfcntl: proc0(child): : Resource temporarily unavailable
tfcntl: child0: locking bytes 32-64
tfcntl: child0: fcntl F_SETLK: Resource temporarily unavailable
tfcntl: child1: locking bytes 32-64
tfcntl: child1: fcntl F_SETLK: Resource temporarily unavailable
1 change: 1 addition & 0 deletions test/t09-mount-9P2000
Expand Up @@ -11,6 +11,7 @@ doit ()
-n localhost:$PATH_EXPDIR $PATH_MNTDIR
echo running statfs comparison
./tstatfs $PATH_EXPDIR $PATH_MNTDIR || : # should fail

echo unmounting
umount $PATH_MNTDIR
echo waiting for diod to terminate
Expand Down
1 change: 1 addition & 0 deletions test/t09.exp
Expand Up @@ -7,5 +7,6 @@ f_bfree differs
f_bavail differs
f_files differs
f_ffree differs
6 differences
unmounting
waiting for diod to terminate
11 changes: 11 additions & 0 deletions test/t10-mount-9P2000.u
Expand Up @@ -11,6 +11,17 @@ doit ()
-n localhost:$PATH_EXPDIR $PATH_MNTDIR
echo running statfs comparison
./tstatfs $PATH_EXPDIR $PATH_MNTDIR || : # should fail

echo trying rename
touch $PATH_MNTDIR/a
./trename $PATH_MNTDIR/a $PATH_MNTDIR/b

echo trying rename to new directory
mkdir -p $PATH_MNTDIR/dir
./trename $PATH_MNTDIR/b $PATH_MNTDIR/dir/c || : # should fail
rm $PATH_MNTDIR/b
rmdir $PATH_MNTDIR/dir

echo unmounting
umount $PATH_MNTDIR
echo waiting for diod to terminate
Expand Down
4 changes: 4 additions & 0 deletions test/t10.exp
Expand Up @@ -7,5 +7,9 @@ f_bfree differs
f_bavail differs
f_files differs
f_ffree differs
6 differences
trying rename
trying rename to new directory
rename: Invalid cross-device link
unmounting
waiting for diod to terminate
11 changes: 11 additions & 0 deletions test/t11-mount-9P2000.L
Expand Up @@ -11,6 +11,17 @@ doit ()
-n localhost:$PATH_EXPDIR $PATH_MNTDIR
echo running statfs comparison
./tstatfs $PATH_EXPDIR $PATH_MNTDIR || : # should succeed

echo trying rename
touch $PATH_MNTDIR/a
./trename $PATH_MNTDIR/a $PATH_MNTDIR/b

echo trying rename to new directory
mkdir -p $PATH_MNTDIR/dir
./trename $PATH_MNTDIR/b $PATH_MNTDIR/dir/c
rm -f $PATH_MNTDIR/dir/c
rmdir $PATH_MNTDIR/dir

echo unmounting
umount $PATH_MNTDIR
echo waiting for diod to terminate
Expand Down
3 changes: 3 additions & 0 deletions test/t11.exp
@@ -1,5 +1,8 @@
starting diod
mounting
running statfs comparison
0 differences
trying rename
trying rename to new directory
unmounting
waiting for diod to terminate
11 changes: 11 additions & 0 deletions test/t12-mount-9P2000.H
Expand Up @@ -11,6 +11,17 @@ doit ()
-n localhost:$PATH_EXPDIR $PATH_MNTDIR
echo running statfs comparison
./tstatfs $PATH_EXPDIR $PATH_MNTDIR || : # should succeed

echo trying rename
touch $PATH_MNTDIR/a
./trename $PATH_MNTDIR/a $PATH_MNTDIR/b

echo trying rename to new directory
mkdir -p $PATH_MNTDIR/dir
./trename $PATH_MNTDIR/b $PATH_MNTDIR/dir/c
rm -f $PATH_MNTDIR/dir/c
rmdir $PATH_MNTDIR/dir

echo unmounting
umount $PATH_MNTDIR
echo waiting for diod to terminate
Expand Down
3 changes: 3 additions & 0 deletions test/t12.exp
@@ -1,5 +1,8 @@
starting diod
mounting
running statfs comparison
0 differences
trying rename
trying rename to new directory
unmounting
waiting for diod to terminate

0 comments on commit 4722a94

Please sign in to comment.