1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/conf/dstest_file_readdir_concurrent.cfg Wed Oct 13 00:51:40 2021 +0200
1.3 @@ -0,0 +1,51 @@
1.4 +-- vim:set ft=lua:
1.5 +
1.6 +local L4 = require("L4");
1.7 +
1.8 +local l = L4.default_loader;
1.9 +
1.10 +local pipe_server = l:new_channel();
1.11 +
1.12 +l:startv({
1.13 + caps = {
1.14 + server = pipe_server:svr(),
1.15 + },
1.16 + log = { "pipes", "r" },
1.17 + },
1.18 + "rom/dstest_pipe_server", "10");
1.19 +
1.20 +local block_server = l:new_channel();
1.21 +
1.22 +l:startv({
1.23 + caps = {
1.24 + server = block_server:svr(),
1.25 + },
1.26 + log = { "blocksvr", "r" },
1.27 + },
1.28 + "rom/dstest_block_server", "10");
1.29 +
1.30 +local ext2svr = l:new_channel();
1.31 +
1.32 +l:startv({
1.33 + caps = {
1.34 + blocksvr = block_server,
1.35 + pipes = pipe_server,
1.36 + ext2svr = ext2svr:svr(),
1.37 + },
1.38 + log = { "ext2svr", "y" },
1.39 + },
1.40 + "rom/dstest_ext2_server", "blocksvr", "rom/e2test.fs", "10", "ext2svr");
1.41 +
1.42 +-- Obtain user filesystems with umask 0022 (18).
1.43 +
1.44 +local open_for_user = 6;
1.45 +local ext2svr_paulb = L4.cast(L4.Proto.Factory, ext2svr):create(open_for_user, 1000, 1000, 18);
1.46 +
1.47 +l:startv({
1.48 + caps = {
1.49 + server = ext2svr_paulb,
1.50 + },
1.51 + log = { "client", "g" },
1.52 + },
1.53 + -- program, directory to read
1.54 + "rom/dstest_file_readdir_concurrent", "home/paulb/many");
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/conf/dstest_file_readdir_concurrent.list Wed Oct 13 00:51:40 2021 +0200
2.3 @@ -0,0 +1,28 @@
2.4 +entry dstest_file_readdir_concurrent
2.5 +roottask moe rom/dstest_file_readdir_concurrent.cfg
2.6 +module dstest_file_readdir_concurrent.cfg
2.7 +module e2test.fs
2.8 +module l4re
2.9 +module ned
2.10 +module dstest_file_readdir_concurrent
2.11 +module dstest_ext2_server
2.12 +module dstest_block_server
2.13 +module dstest_pipe_server
2.14 +module lib4re-c.so
2.15 +module lib4re-c-util.so
2.16 +module lib4re.so
2.17 +module lib4re-util.so
2.18 +module libc_be_l4refile.so
2.19 +module libc_be_l4re.so
2.20 +module libc_be_socket_noop.so
2.21 +module libc_support_misc.so
2.22 +module libdl.so
2.23 +module libipc.so
2.24 +module libl4sys-direct.so
2.25 +module libl4sys.so
2.26 +module libl4util.so
2.27 +module libld-l4.so
2.28 +module libpthread.so
2.29 +module libstdc++.so
2.30 +module libsupc++.so
2.31 +module libuc_c.so
3.1 --- a/tests/Makefile Wed Oct 13 00:50:33 2021 +0200
3.2 +++ b/tests/Makefile Wed Oct 13 00:51:40 2021 +0200
3.3 @@ -7,6 +7,7 @@
3.4 dstest_file_client \
3.5 dstest_file_monitor \
3.6 dstest_file_readdir \
3.7 + dstest_file_readdir_concurrent \
3.8 dstest_host_client \
3.9 dstest_pipe_client \
3.10 dstest_test_client
3.11 @@ -25,6 +26,8 @@
3.12
3.13 SRC_CC_dstest_file_readdir = dstest_file_readdir.cc
3.14
3.15 +SRC_CC_dstest_file_readdir_concurrent = dstest_file_readdir_concurrent.cc
3.16 +
3.17 SRC_CC_dstest_host_client = dstest_host_client.cc
3.18
3.19 SRC_CC_dstest_pipe_client = dstest_pipe_client.cc
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/tests/dstest_file_readdir_concurrent.cc Wed Oct 13 00:51:40 2021 +0200
4.3 @@ -0,0 +1,161 @@
4.4 +/*
4.5 + * Test directory reading operations, exploring concurrency issues.
4.6 + *
4.7 + * Copyright (C) 2020, 2021 Paul Boddie <paul@boddie.org.uk>
4.8 + *
4.9 + * This program is free software; you can redistribute it and/or
4.10 + * modify it under the terms of the GNU General Public License as
4.11 + * published by the Free Software Foundation; either version 2 of
4.12 + * the License, or (at your option) any later version.
4.13 + *
4.14 + * This program is distributed in the hope that it will be useful,
4.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4.17 + * GNU General Public License for more details.
4.18 + *
4.19 + * You should have received a copy of the GNU General Public License
4.20 + * along with this program; if not, write to the Free Software
4.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
4.22 + * Boston, MA 02110-1301, USA
4.23 + */
4.24 +
4.25 +#include <l4/re/env.h>
4.26 +#include <l4/sys/err.h>
4.27 +
4.28 +#include <stdio.h>
4.29 +#include <string.h>
4.30 +#include <stdlib.h>
4.31 +
4.32 +#include <fsclient/client.h>
4.33 +#include <systypes/fcntl.h>
4.34 +
4.35 +
4.36 +
4.37 +static file_t *open_directory(char *filename, bool have_uid, sys_uid_t uid)
4.38 +{
4.39 + /* With a user, open a user-specific file opener. */
4.40 +
4.41 + if (have_uid)
4.42 + {
4.43 + l4_cap_idx_t opener = client_open_for_user((user_t) {uid, uid, 0022});
4.44 +
4.45 + if (l4_is_invalid_cap(opener))
4.46 + {
4.47 + printf("Could not obtain opener for file.\n");
4.48 + return NULL;
4.49 + }
4.50 +
4.51 + /* Invoke the open method to receive the file reference. */
4.52 +
4.53 + return client_opendir_using(filename, opener);
4.54 + }
4.55 + else
4.56 + {
4.57 + return client_opendir(filename);
4.58 + }
4.59 +}
4.60 +
4.61 +static file_t *open_file(char *filename, bool have_uid, sys_uid_t uid)
4.62 +{
4.63 + /* With a user, open a user-specific file opener. */
4.64 +
4.65 + if (have_uid)
4.66 + {
4.67 + l4_cap_idx_t opener = client_open_for_user((user_t) {uid, uid, 0022});
4.68 +
4.69 + if (l4_is_invalid_cap(opener))
4.70 + {
4.71 + printf("Could not obtain opener for file.\n");
4.72 + return NULL;
4.73 + }
4.74 +
4.75 + /* Invoke the open method to receive the file reference. */
4.76 +
4.77 + return client_open_using(filename, O_RDWR | O_CREAT, opener);
4.78 + }
4.79 + else
4.80 + {
4.81 + return client_open(filename, O_RDWR | O_CREAT);
4.82 + }
4.83 +}
4.84 +
4.85 +
4.86 +
4.87 +int main(int argc, char *argv[])
4.88 +{
4.89 + if (argc < 2)
4.90 + {
4.91 + printf("Need a directory name and an optional user identifier (if used with a filesystem).\n");
4.92 + return 1;
4.93 + }
4.94 +
4.95 + char *filename = argv[1];
4.96 + bool have_uid = (argc > 2) && strlen(argv[2]);
4.97 + sys_uid_t uid = have_uid ? atoi(argv[2]) : 0;
4.98 +
4.99 + printf("Opening %s...\n", filename);
4.100 +
4.101 + file_t *reader = open_directory(filename, have_uid, uid);
4.102 +
4.103 + if (reader == NULL)
4.104 + {
4.105 + printf("Could not read from directory.\n");
4.106 + return 1;
4.107 + }
4.108 +
4.109 + printf("Reading...\n");
4.110 +
4.111 + struct dirent *dirent;
4.112 + int filenum = 1000, remaining = 100;
4.113 + char buffer[strlen(filename) + strlen("/file-XXXX.txt") + 10];
4.114 + int found = 0;
4.115 +
4.116 + while ((dirent = client_readdir(reader)) != NULL)
4.117 + {
4.118 + free(dirent);
4.119 + found++;
4.120 +
4.121 + /* Create files while getting the listing. */
4.122 +
4.123 + if (remaining)
4.124 + {
4.125 + sprintf(buffer, "%s/file-%d.txt", filename, filenum++);
4.126 +
4.127 + file_t *file = open_file(buffer, have_uid, uid);
4.128 +
4.129 + if (file == NULL)
4.130 + {
4.131 + printf("Could not open file: %s\n", buffer);
4.132 + return 1;
4.133 + }
4.134 +
4.135 + remaining--;
4.136 + }
4.137 + }
4.138 +
4.139 + printf("Files found: %d\n", found);
4.140 +
4.141 + /* Re-read, counting files. */
4.142 +
4.143 + reader = open_directory(filename, have_uid, uid);
4.144 +
4.145 + if (reader == NULL)
4.146 + {
4.147 + printf("Could not read from directory.\n");
4.148 + return 1;
4.149 + }
4.150 +
4.151 + found = 0;
4.152 +
4.153 + while ((dirent = client_readdir(reader)) != NULL)
4.154 + {
4.155 + free(dirent);
4.156 + found++;
4.157 + }
4.158 +
4.159 + printf("Files found: %d\n", found);
4.160 +
4.161 + return 0;
4.162 +}
4.163 +
4.164 +// vim: tabstop=2 expandtab shiftwidth=2