check: allow '-e testid' to exclude a single test
[xfstests-dev.git] / dmapi / src / suite2 / src / check_dmapi.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2000-2001 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6
7 #include <sys/types.h>
8 #include <sys/stat.h>
9 #ifdef linux
10 #include <dmapi.h>
11 #else
12 #include <sys/dmi.h>
13 #endif
14
15 #include <fcntl.h>
16 #include <errno.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <unistd.h>
20 #include <strings.h>
21
22 #include <lib/hsm.h>
23 #include <lib/dmport.h>
24
25 #ifdef linux
26 #include <string.h>
27 #endif
28
29 /*---------------------------------------------------------------------------
30 Automated test of version of DMAPI libraries & kernels 
31
32 The command line is: 
33
34      check_dmapi [-v] 
35
36 where v is a verbose-output flag
37 ----------------------------------------------------------------------------*/
38 #ifdef linux
39 #define CREATE_DESTROY_OPCODE DM_DESTROY_SESSION
40 #define SET_DISP_OPCODE DM_SET_DISP
41 #else
42 #define CREATE_DESTROY_OPCODE 5
43 #define SET_DISP_OPCODE 46
44 #endif
45
46 #ifndef linux
47 extern  char    *sys_errlist[];
48 #endif
49 extern  int     optind;
50 extern  char    *optarg;
51
52 char    *Progname;
53
54 int     dmi(int, ...);
55
56 static void
57 usage(void)
58 {
59         int     i;
60
61         fprintf(stderr, "usage:\t%s [-v]\n"
62                 "\t(use the v switch for verbose output)\n", Progname);
63         exit(1);
64 }
65
66
67 int
68 main(
69         int     argc, 
70         char    **argv)
71 {
72         dm_sessid_t     old_sid = -1;
73         dm_sessid_t     sid;
74         void            *hanp;
75         size_t           hlen;
76         dm_token_t      token = DM_NO_TOKEN;
77         int             Vflag = 0;
78         char            *name = "old";
79         char            *junk = "test junk";
80         int             opt;
81         int             i;
82         int             kernel_status=-1;
83         int             library_status=-1L;
84         dm_size_t       retval;
85         struct stat     stat_buf;
86
87         if (Progname = strrchr(argv[0], '/')) {
88                 Progname++;
89         } else {
90                 Progname = argv[0];
91         }
92
93         /* Crack and validate the command line options. */
94
95         while ((opt = getopt(argc, argv, "v")) != EOF) {
96           switch (opt) {
97           case 'v':
98             Vflag++;
99             break;
100           case '?':
101             usage();
102           }
103         }
104         if (optind != argc)
105           usage();
106         
107
108         if (geteuid()!=0) {
109           printf("You are running as user #%d.  "
110                  "You must be root to run this diagnostic.\n", geteuid());
111           exit(1);
112         }
113
114         /*--------------------------
115          * RESOLVE KERNEL PRESENCE:
116          *--------------------------
117          */
118         if (dmi(CREATE_DESTROY_OPCODE, old_sid, junk, &sid) >= 0) {
119           printf("ERROR: invalid kernel create/destroy_session call "
120                  "succeeded!\n");
121           exit(1);
122         }
123         else if (errno==ENOPKG) {
124           kernel_status=0;
125         }
126         else if (errno==EINVAL){
127           if (Vflag) printf("(create/destroy_session call verifies "
128                             "that you have DMAPI in kernel)\n");
129         }
130         else {
131           printf("ERROR: kernel create/destroy_session call produced "
132                  "unexpected errno, (%d) %s\n", errno, strerror(errno));
133         }
134         
135         /*----------------------------------
136          * RESOLVE KERNEL STATUS IF PRESENT:
137          *----------------------------------
138          */
139         if (kernel_status==-1 &&
140             dmi(SET_DISP_OPCODE, 
141                 (dm_sessid_t) 0, 
142                 (void*) 0,
143                 (size_t) 0,
144                 (dm_token_t) 0,
145                 (dm_eventset_t) 0,
146                 (u_int) 0) >= 0) { 
147           printf("ERROR: invalid kernel set_disp call suceeded!\n");
148         }
149         else {
150           if (errno==ENOSYS) {
151             if (Vflag) 
152               printf("(kernel set_disp call indicates old kernel)\n");
153             kernel_status=1;
154           }
155           else if (errno==ENOPKG) {
156             if (Vflag) 
157               printf("(kernel set_disp call indicates no kernel)\n");
158             kernel_status=0;
159           }
160           else if (errno==EINVAL) {
161             if (Vflag)
162               printf("(kernel set_disp call indicates new kernel)\n");
163             kernel_status=2;
164           }
165           else {
166             printf("ERROR: kernel set_disp call failed: (%d) %s\n", 
167                    errno, strerror(errno));
168             exit(1);
169           }
170         }
171
172         /*-------------------------
173          * RESOLVE LIBRARY STATUS:
174          *-------------------------
175          */
176         if (dm_init_service(&name) == -1)  {
177           fprintf(stderr, "ERROR: can't initialize the DMAPI (%s).\n",
178                   strerror(errno));
179           library_status=0;
180         }
181         else if (strcmp(name, DM_VER_STR_CONTENTS)) {
182           if (Vflag) 
183             printf("(dm_init_service suggests that "
184                    "you have an old library)\n");
185           library_status=1;
186         }
187         else {
188           if (Vflag) 
189             printf("(dm_init_service suggests that "
190                    "you have a new library)\n");
191           library_status=2;
192         }
193         
194         if (Vflag) printf("(dm_init_service returned %s)\n", name);
195         
196         /*-------------------------
197          * MAKE A DIAGNOSIS:
198          *-------------------------
199          */
200
201         if (library_status==2 && kernel_status==2){
202           printf("DIAGNOSIS: Tests show a current version of "
203                  "DMAPI is installed.\n");
204         } 
205         else if (library_status==1 && kernel_status==1) {
206           printf("DIAGNOSIS: Tests show that you have an outdated "
207                  "installation of DMAPI.\nUpgrades to both kernel and "
208                  "library routines will be necessary.\n");
209         }
210         else if (library_status==0 && kernel_status==0) {
211           printf("DIAGNOSIS: Tests show that NO components of the DMAPI "
212                  "are installed!\nUpgrades to both kernel and "
213                  "library routines will be necessary.\n");
214         }
215         else {
216           printf("DIAGNOSIS: Tests show that:\n"
217                  "Your DMAPI kernel routines are ");
218           switch (kernel_status) {
219           case 0: printf ("missing (not installed).\n");
220              break;
221           case 1: printf ("outdated.\n");
222              break;
223           case 2: printf ("current.\n ");
224              break;
225           default: printf("[ERROR!].\n");
226           }
227           printf("Your DMAPI library is ");
228           switch (library_status) {
229           case 0: printf ("missing (not installed).\n");
230              break;
231           case 1: printf ("outdated.\n");
232              break;
233           case 2: printf ("current.\n");
234              break;
235           default: printf("[ERROR!].\n");
236           }
237         }
238 #ifndef linux
239         if (library_status!=2 || kernel_status!=2){
240           printf("Please install XFS patch 1907 (for IRIX 6.2) or "
241                  "patch 2287 (for IRIX 6.4).\n");
242         }
243 #endif
244 }
245
246  
247