Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Allow non-directories to be exported (issue 113)

Add test user/t16 which mounts a regular file and reads from it.
  • Loading branch information...
commit 024aa7a0432427e5384b2a981b03ee694c05de76 1 parent 7174154
Jim Garlick garlick authored
7 diod/ops.c
@@ -278,10 +278,9 @@ diod_attach (Npfid *fid, Npfid *afid, Npstr *aname)
278 278 np_uerror (errno);
279 279 goto error;
280 280 }
281   - if (!S_ISDIR (sb.st_mode)) {
282   - np_uerror (ENOTDIR);
283   - goto error;
284   - }
  281 + /* N.B. removed S_ISDIR (sb.st_mode) || return ENOTDIR check.
  282 + * Allow a regular file or a blcok device to be exported.
  283 + */
285 284 diod_ustat2qid (&sb, &qid);
286 285 if ((ret = np_create_rattach (&qid)) == NULL) {
287 286 np_uerror (ENOMEM);
2  tests/user/Makefile.am
@@ -13,7 +13,7 @@ TESTS_ENVIRONMENT += "PATH_DIOD=$(top_builddir)/diod/diod"
13 13 TESTS_ENVIRONMENT += "PATH_DIODCONF=$(top_builddir)/etc/diod.conf"
14 14 TESTS_ENVIRONMENT += "./runtest"
15 15
16   -TESTS = t01 t02 t03 t04 t05 t06 t07 t08 t09 t10 t11 t12 t13 t15
  16 +TESTS = t01 t02 t03 t04 t05 t06 t07 t08 t09 t10 t11 t12 t13 t15 t16
17 17
18 18 $(TESTS): exp.d
19 19
1  tests/user/README
@@ -21,6 +21,7 @@ t11(*) Attach to server with N threads, M users (N > M)
21 21 t12(+) Attach to user A's private server with user B
22 22 t13(*) Attach to server with N threads, M users (N < M)
23 23 t15 Check that flush works the way it ought to.
  24 +t16 Attach directly to a file and perform I/O
24 25
25 26
26 27 (*) requires root (else NOTRUN)
11 tests/user/runtest
... ... @@ -1,5 +1,7 @@
1 1 #!/bin/bash
2 2
  3 +umask 022
  4 +
3 5 PATH=/sbin:/usr/sbin:/bin:/usr/bin:$PATH
4 6 if [ $# -ne 1 ]; then
5 7 echo "Usage runtest test" 2>&1
@@ -13,6 +15,7 @@ if [ -z "$PATH_DIOD" ]; then
13 15 exit 1
14 16 fi
15 17
  18 +
16 19 # some tests require root, some require non-root
17 20 case $(basename $TEST) in
18 21 t12)
@@ -31,13 +34,17 @@ case $(basename $TEST) in
31 34 exit 77
32 35 fi
33 36 ;;
  37 + t16) # PATH_EXPDIR is a regular file for this test
  38 + umask 022
  39 + PATH_EXPDIR=$(mktemp) || exit 1
  40 + dd if=/dev/zero count=1 bs=1024k of=$PATH_EXPDIR oflag=append >/dev/null 2>&1
  41 + ;;
34 42 esac
35 43
36 44 rm -f $TEST.diod $TEST.out
37 45 ulimit -c unlimited
38 46
39   -umask 022
40   -PATH_EXPDIR=$(mktemp -d) || exit 1
  47 +test -n "$PATH_EXPDIR" || PATH_EXPDIR=$(mktemp -d) || exit 1
41 48 chmod 777 $PATH_EXPDIR
42 49 export PATH_EXPDIR
43 50
4 tests/user/t03
@@ -4,9 +4,9 @@ echo creating testfile
4 4 cp $PATH_DIOD $PATH_EXPDIR/testfile
5 5 tmpfile=`mktemp`
6 6 echo reading testfile
7   -./tread "$@" testfile $tmpfile
  7 +./tread "$@" $tmpfile testfile
8 8 echo comparing result
9   -if ! cmp $PATH_EXPDIR/testfile $tmpfile; then
  9 +if ! cmp $tmpfile $PATH_EXPDIR/testfile; then
10 10 echo results differ
11 11 exit 1
12 12 fi
2  tests/user/t04
@@ -2,6 +2,6 @@
2 2
3 3 tmpfile=`mktemp`
4 4 echo reading testfile
5   -./tread "$@" bogusfile $tmpfile || : # should fail
  5 +./tread "$@" $tmpfile bogusfile || : # should fail
6 6 rm -f $tmpfile
7 7 exit 0
15 tests/user/t16
... ... @@ -0,0 +1,15 @@
  1 +#!/bin/bash -e
  2 +
  3 +# In this test PATH_EXPDIR is a regular file
  4 +test -f $PATH_EXPDIR
  5 +
  6 +tmpfile=`mktemp`
  7 +echo reading mounted file
  8 +./tread "$@" $tmpfile
  9 +echo comparing result
  10 +if ! cmp $tmpfile $PATH_EXPDIR; then
  11 + echo results differ
  12 + exit 1
  13 +fi
  14 +rm -f $tmpfile
  15 +exit 0
4 tests/user/t16.exp
... ... @@ -0,0 +1,4 @@
  1 +reading mounted file
  2 +comparing result
  3 +conjoin: t16 exited with rc=0
  4 +conjoin: diod exited with rc=0
32 tests/user/tread.c
@@ -26,7 +26,8 @@
26 26 static void
27 27 usage (void)
28 28 {
29   - fprintf (stderr, "Usage: tread aname infile outfile\n");
  29 + fprintf (stderr, "Usage: tread aname outfile [infile]\n");
  30 + fprintf (stderr, " If no infile, try to read directly from aname\n");
30 31 exit (1);
31 32 }
32 33
@@ -55,28 +56,35 @@ int
55 56 main (int argc, char *argv[])
56 57 {
57 58 Npcfid *root, *fid;
58   - char *aname, *infile, *outfile;
  59 + char *aname, *outfile, *infile = NULL;
59 60 int fd;
60 61
61 62 diod_log_init (argv[0]);
62 63
63   - if (argc != 4)
  64 + if (argc != 4 && argc != 3)
64 65 usage ();
65 66 aname = argv[1];
66   - infile = argv[2];
67   - outfile = argv[3];
  67 + outfile = argv[2]; /* UNIX */
  68 + if (argc == 4)
  69 + infile = argv[3]; /* userland 9p */
68 70
69 71 if ((fd = open (outfile, O_WRONLY | O_CREAT, 0644)) < 0)
70 72 err_exit ("open");
71   -
72 73 if (!(root = npc_mount (0, 0, 65536+24, aname, diod_auth)))
73 74 errn_exit (np_rerror (), "npc_mount");
74   - if ((fid = npc_open_bypath (root, infile, O_RDONLY))) {
75   - _copy_from9 (fid, fd);
76   - if (npc_clunk (fid) < 0)
77   - errn (np_rerror (), "npc_clunk");
78   - } else
79   - errn (np_rerror (), "npc_open_bypath");
  75 + if (infile) {
  76 + if ((fid = npc_open_bypath (root, infile, O_RDONLY))) {
  77 + _copy_from9 (fid, fd);
  78 + if (npc_clunk (fid) < 0)
  79 + errn (np_rerror (), "npc_clunk");
  80 + } else
  81 + errn (np_rerror (), "npc_open_bypath");
  82 + } else {
  83 + if ((npc_open (root, O_RDONLY)) == 0) {
  84 + _copy_from9 (root, fd);
  85 + } else
  86 + errn (np_rerror (), "npc_open");
  87 + }
80 88 npc_umount (root);
81 89
82 90 if (close (fd) < 0)

0 comments on commit 024aa7a

Please sign in to comment.
Something went wrong with that request. Please try again.