Motr  M0
m0t1fs_fwait_test_helper.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Seagate Technology LLC and/or its Affiliates
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * For any questions about this software or licensing,
17  * please email opensource@seagate.com or cortx-questions@seagate.com.
18  *
19  */
20 
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <fcntl.h>
26 #include <unistd.h>
27 #include <limits.h>
28 #include <errno.h>
29 #include <string.h>
30 #include <sys/ioctl.h>
31 
32 #include "m0t1fs/m0t1fs_ioctl.h"
33 
34 #define PASS "pass"
35 #define FAIL "fail"
36 
41 {
42  int rv;
43  char *str = "Hello World";
44 
45  /* write some data */
46  rv = write(fd, str, strlen(str));
47 
48  /* Try and fwait on the file */
49  rv = ioctl(fd, M0_M0T1FS_FWAIT);
50  fprintf(stderr, "ioctl returned:%d\n", rv);
51 
52  return rv == 0;
53 }
54 
59 {
60  int rv;
61 
62  rv = ioctl(fd, M0_M0T1FS_FWAIT + 1);
63  return rv < 0 && ENOTTY == errno;
64 }
65 
69 int test_wrong_fd(void)
70 {
71  int rv;
72 
73  rv = ioctl(666, M0_M0T1FS_FWAIT);
74  return rv < 0 && EBADF == errno;
75 }
76 
77 int main(int argc, char **argv)
78 {
79  int rv;
80  int fd;
81  char object_name[PATH_MAX];
82 
83  /* check we were told the mount point */
84  if (argc != 2){
85  fprintf(stderr, "Usage: %s /path/to/mount/point\n", argv[0]);
86  exit(1);
87  }
88 
89  /* Build a path for our to-create object */
90  rv = snprintf(object_name, sizeof(object_name), "%s/0:11234151",
91  argv[1]);
92  if (rv >= sizeof(object_name)) {
93  fprintf(stderr, "Path overflow\n");
94  exit(1);
95  }
96 
97  /* Creat the object*/
98  fd = creat(object_name, 0600);
99  if (fd >= 0) {
100  do {
101  /* Run the tests */
102  rv = test_fwait_write(fd);
103  fprintf(stderr, "test_fwait_write: %s\n",
104  rv ? PASS:FAIL);
105  if (!rv)
106  break;
107 
108  rv = test_wrong_cmd(fd);
109  fprintf(stderr, "test_wrong_cmd: %s\n",
110  rv ? PASS:FAIL);
111  if (!rv)
112  break;
113 
114  rv = test_wrong_fd();
115  fprintf(stderr, "test_wrong_fd: %s\n",
116  rv ? PASS:FAIL);
117  /* fall through */
118  } while(0);
119  } else {
120  fprintf(stderr, "Failed to creat %s: %s\n",
121  object_name, strerror(errno));
122  exit(1);
123  }
124 
125  if (rv)
126  return 0;
127  else
128  exit(1);
129 }
int main(int argc, char **argv)
#define PASS
int test_fwait_write(int fd)
#define FAIL
int test_wrong_fd(void)
int test_wrong_cmd(int fd)
struct m0t1fs_filedata * fd
Definition: dir.c:1030
#define M0_M0T1FS_FWAIT
Definition: m0t1fs_ioctl.h:33