xfs/331: don't run this test if fallocate isn't supported
[xfstests-dev.git] / src / godown.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2004 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6
7 #include <syslog.h>
8 #include "global.h"
9
10 static char *xprogname;
11
12
13 static void
14 usage(void)
15 {
16         fprintf(stderr, "usage: %s [-f] [-v] mnt-dir\n", xprogname);
17 }
18
19 int
20 main(int argc, char *argv[])
21 {
22         int c;
23         int flag;
24         int flushlog_opt = 0;
25         int verbose_opt = 0;
26         struct stat st;
27         char *mnt_dir;
28         int fd;
29
30         xprogname = argv[0];
31
32         while ((c = getopt(argc, argv, "fv")) != -1) {
33                 switch (c) {
34                 case 'f':
35                         flushlog_opt = 1;
36                         break;
37                 case 'v':
38                         verbose_opt = 1;
39                         break;
40                 case '?':
41                         usage();
42                         return 1;
43                 }
44         }
45
46         /* process required cmd argument */
47         if (optind == argc-1) {
48                 mnt_dir = argv[optind];
49         }
50         else {
51                 usage();
52                 return 1;
53         }
54
55         if ((stat(mnt_dir, &st)) == -1) {
56                 fprintf(stderr, "%s: error on stat \"%s\": %s\n",
57                         xprogname, mnt_dir, strerror(errno));
58                 return 1;
59         }
60
61         if (!S_ISDIR(st.st_mode)) {
62                 fprintf(stderr, "%s: argument \"%s\" is not a directory\n",
63                         xprogname, mnt_dir);
64                 return 1;
65         }
66
67         
68 #if 0
69         {
70                 struct statvfs stvfs;
71                 if ((statvfs(mnt_dir, &stvfs)) == -1) {
72                         fprintf(stderr, "%s: error on statfs \"%s\": %s\n",
73                                 xprogname, mnt_dir, strerror(errno));
74                         return 1;
75                 }
76
77                 if (strcmp(stvfs.f_basetype, "xfs") != 0) {
78                         fprintf(stderr, "%s: filesys for \"%s\" is not XFS:\"%s\"\n",
79                                 xprogname, mnt_dir, stvfs.f_basetype);
80                         return 1;
81                 }
82         }
83 #endif
84
85
86         flag = (flushlog_opt ? XFS_FSOP_GOING_FLAGS_LOGFLUSH 
87                             : XFS_FSOP_GOING_FLAGS_NOLOGFLUSH);
88
89         if (verbose_opt) {
90                 printf("Opening \"%s\"\n", mnt_dir);
91         }
92         if ((fd = open(mnt_dir, O_RDONLY)) == -1) {
93                 fprintf(stderr, "%s: error on open of \"%s\": %s\n",
94                         xprogname, mnt_dir, strerror(errno));
95                 return 1;
96         }
97
98         if (verbose_opt) {
99                 printf("Calling XFS_IOC_GOINGDOWN\n");
100         }
101         syslog(LOG_WARNING, "xfstests-induced forced shutdown of %s:\n",
102                 mnt_dir);
103         if ((xfsctl(mnt_dir, fd, XFS_IOC_GOINGDOWN, &flag)) == -1) {
104                 fprintf(stderr, "%s: error on xfsctl(GOINGDOWN) of \"%s\": %s\n",
105                         xprogname, mnt_dir, strerror(errno));
106                 return 1;
107         }
108
109         close(fd);
110
111         return 0;
112 }