Whamcloud - gitweb
file jbd-2.4.19-pre1-jcberr.patch was initially added on branch b_devel.
[fs/lustre-release.git] / lustre / liblustre / libtest.c
1 #include <stdio.h>
2 #include <netinet/in.h>
3 #include <sys/socket.h>
4 #include <arpa/inet.h>
5
6 #include <portals/api-support.h> /* needed for ptpctl.h */
7 #include <portals/ptlctl.h>     /* needed for parse_dump */
8
9
10 #include <liblustre.h>
11 #include <linux/obd.h>
12 #include <linux/obd_class.h>
13 #include <portals/procbridge.h>
14
15 struct ldlm_namespace;
16 struct ldlm_res_id;
17 struct obd_import;
18
19 extern int ldlm_cli_cancel_unused(struct ldlm_namespace *ns, struct ldlm_res_id *res_id, int flags);
20 extern int ldlm_namespace_cleanup(struct ldlm_namespace *ns, int local_only);
21 extern int ldlm_replay_locks(struct obd_import *imp);
22
23 void *inter_module_get(char *arg)
24 {
25         if (!strcmp(arg, "tcpnal_ni"))
26                 return &tcpnal_ni;
27         else if (!strcmp(arg, "ldlm_cli_cancel_unused"))
28                 return ldlm_cli_cancel_unused;
29         else if (!strcmp(arg, "ldlm_namespace_cleanup"))
30                 return ldlm_namespace_cleanup;
31         else if (!strcmp(arg, "ldlm_replay_locks"))
32                 return ldlm_replay_locks;
33         else
34                 return NULL;
35 }
36
37 ptl_handle_ni_t         tcpnal_ni;
38
39 struct pingcli_args {
40         ptl_nid_t mynid;
41         ptl_nid_t nid;
42         ptl_pid_t port;
43         int count;
44         int size;
45 };
46
47 struct task_struct *current;
48
49 struct obd_class_user_state ocus;
50
51 /* portals interfaces */
52 ptl_handle_ni_t *
53 kportal_get_ni (int nal)
54 {
55         return &tcpnal_ni;
56 }
57
58 inline void
59 kportal_put_ni (int nal)
60 {
61         return;
62 }
63
64 void init_current(int argc, char **argv)
65
66         current = malloc(sizeof(*current));
67         strncpy(current->comm, argv[0], sizeof(current->comm));
68         current->pid = getpid();
69
70 }
71
72 ptl_nid_t tcpnal_mynid;
73
74 int init_lib_portals(struct pingcli_args *args)
75 {
76         int rc;
77
78         PtlInit();
79         tcpnal_mynid = args->mynid;
80         rc = PtlNIInit(procbridge_interface, 0, 0, 0, &tcpnal_ni);
81         if (rc != 0) {
82                 CERROR("ksocknal: PtlNIInit failed: error %d\n", rc);
83                 PtlFini();
84                 RETURN (rc);
85         }
86         PtlNIDebug(tcpnal_ni, ~0);
87         return rc;
88 }
89
90 extern int class_handle_ioctl(struct obd_class_user_state *ocus, unsigned int cmd, unsigned long arg);
91
92
93 int lib_ioctl(int dev_id, int opc, void * ptr)
94 {
95
96         if (dev_id == OBD_DEV_ID) {
97                 struct obd_ioctl_data *ioc = ptr;
98                 class_handle_ioctl(&ocus, opc, (unsigned long)ptr);
99
100                 /* you _may_ need to call obd_ioctl_unpack or some
101                    other verification function if you want to use ioc
102                    directly here */
103                 printf ("processing ioctl cmd: %x buf len: %d\n", 
104                         opc,  ioc->ioc_len);
105         }
106         return (0);
107 }
108
109 int main(int argc, char **argv) 
110 {
111         struct pingcli_args *args;
112         args= malloc(sizeof(*args));
113         if (!args) { 
114                 printf("Malloc error\n");
115                 exit(1);
116         }
117
118         args->mynid   = ntohl (inet_addr (argv[1]));
119         INIT_LIST_HEAD(&ocus.ocus_conns);
120
121         init_current(argc, argv);
122         init_obdclass();
123         init_lib_portals(args);
124         ptlrpc_init();
125         ldlm_init();
126         mdc_init();
127         lov_init();
128         osc_init();
129         echo_client_init();
130
131         parse_dump("/tmp/DUMP_FILE", lib_ioctl);
132
133         printf("Hello\n");
134         return 0;
135 }
136