1.1 --- a/tests/dstest_file_readdir_concurrent.cc Thu Jan 27 23:45:17 2022 +0100
1.2 +++ b/tests/dstest_file_readdir_concurrent.cc Sun Feb 06 18:05:23 2022 +0100
1.3 @@ -1,7 +1,7 @@
1.4 /*
1.5 * Test directory reading operations, exploring concurrency issues.
1.6 *
1.7 - * Copyright (C) 2020, 2021 Paul Boddie <paul@boddie.org.uk>
1.8 + * Copyright (C) 2020, 2021, 2022 Paul Boddie <paul@boddie.org.uk>
1.9 *
1.10 * This program is free software; you can redistribute it and/or
1.11 * modify it under the terms of the GNU General Public License as
1.12 @@ -31,95 +31,19 @@
1.13
1.14
1.15
1.16 -static file_t *open_directory(char *filename, bool have_uid, sys_uid_t uid)
1.17 -{
1.18 - /* With a user, open a user-specific file opener. */
1.19 -
1.20 - if (have_uid)
1.21 - {
1.22 - l4_cap_idx_t opener = client_open_for_user((user_t) {uid, uid, 0022});
1.23 -
1.24 - if (l4_is_invalid_cap(opener))
1.25 - {
1.26 - printf("Could not obtain opener for file.\n");
1.27 - return NULL;
1.28 - }
1.29 -
1.30 - /* Invoke the open method to receive the file reference. */
1.31 -
1.32 - return client_opendir_using(filename, opener);
1.33 - }
1.34 - else
1.35 - {
1.36 - return client_opendir(filename);
1.37 - }
1.38 -}
1.39 -
1.40 -static file_t *open_file(char *filename, bool have_uid, sys_uid_t uid)
1.41 -{
1.42 - /* With a user, open a user-specific file opener. */
1.43 -
1.44 - if (have_uid)
1.45 - {
1.46 - l4_cap_idx_t opener = client_open_for_user((user_t) {uid, uid, 0022});
1.47 -
1.48 - if (l4_is_invalid_cap(opener))
1.49 - {
1.50 - printf("Could not obtain opener for file.\n");
1.51 - return NULL;
1.52 - }
1.53 -
1.54 - /* Invoke the open method to receive the file reference. */
1.55 -
1.56 - return client_open_using(filename, O_RDWR | O_CREAT, opener);
1.57 - }
1.58 - else
1.59 - {
1.60 - return client_open(filename, O_RDWR | O_CREAT);
1.61 - }
1.62 -}
1.63 -
1.64 -static long remove_file(char *filename, bool have_uid, sys_uid_t uid)
1.65 -{
1.66 - /* With a user, open a user-specific file opener. */
1.67 -
1.68 - if (have_uid)
1.69 - {
1.70 - l4_cap_idx_t opener = client_open_for_user((user_t) {uid, uid, 0022});
1.71 -
1.72 - if (l4_is_invalid_cap(opener))
1.73 - {
1.74 - printf("Could not obtain opener for file.\n");
1.75 - return -L4_EIO;
1.76 - }
1.77 -
1.78 - /* Invoke the remove method to remove the file. */
1.79 -
1.80 - return client_remove_using(filename, opener);
1.81 - }
1.82 - else
1.83 - {
1.84 - return client_remove(filename);
1.85 - }
1.86 -}
1.87 -
1.88 -
1.89 -
1.90 int main(int argc, char *argv[])
1.91 {
1.92 if (argc < 2)
1.93 {
1.94 - printf("Need a directory name and an optional user identifier (if used with a filesystem).\n");
1.95 + printf("Need a directory name.\n");
1.96 return 1;
1.97 }
1.98
1.99 char *filename = argv[1];
1.100 - bool have_uid = (argc > 2) && strlen(argv[2]);
1.101 - sys_uid_t uid = have_uid ? atoi(argv[2]) : 0;
1.102
1.103 printf("Opening %s...\n", filename);
1.104
1.105 - file_t *reader = open_directory(filename, have_uid, uid);
1.106 + file_t *reader = client_opendir(filename);
1.107
1.108 if (reader == NULL)
1.109 {
1.110 @@ -147,7 +71,7 @@
1.111 {
1.112 sprintf(buffer, "%s/file-%d.txt", filename, filenum++);
1.113
1.114 - file_t *file = open_file(buffer, have_uid, uid);
1.115 + file_t *file = client_open(buffer, O_RDWR | O_CREAT);
1.116
1.117 if (file == NULL)
1.118 {
1.119 @@ -172,7 +96,7 @@
1.120
1.121 /* Re-read, counting files. */
1.122
1.123 - reader = open_directory(filename, have_uid, uid);
1.124 + reader = client_opendir(filename);
1.125
1.126 if (reader == NULL)
1.127 {
1.128 @@ -196,7 +120,7 @@
1.129 {
1.130 sprintf(buffer, "%s/file-%d.txt", filename, filenum++);
1.131
1.132 - long err = remove_file(buffer, have_uid, uid);
1.133 + long err = client_remove(buffer);
1.134
1.135 if (err)
1.136 {
1.137 @@ -207,7 +131,7 @@
1.138
1.139 /* Re-read, counting files. */
1.140
1.141 - reader = open_directory(filename, have_uid, uid);
1.142 + reader = client_opendir(filename);
1.143
1.144 if (reader == NULL)
1.145 {