1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
6 * This file is part of Portals, http://www.sf.net/projects/lustre/
8 * Portals is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Portals is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Portals; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <linux/config.h>
26 #include <linux/module.h>
27 #include <linux/kernel.h>
29 #include <linux/string.h>
30 #include <linux/stat.h>
31 #include <linux/errno.h>
32 #include <linux/locks.h>
33 #include <linux/unistd.h>
35 #include <asm/system.h>
36 #include <asm/uaccess.h>
37 #include <linux/module.h>
40 #include <linux/stat.h>
41 #include <asm/uaccess.h>
42 #include <asm/segment.h>
43 #include <linux/miscdevice.h>
45 #define DEBUG_SUBSYSTEM S_MDC
47 #include <linux/obd_support.h>
48 #include <linux/lustre_lib.h>
49 #include <linux/lustre_idl.h>
50 #include <linux/lustre_mds.h>
52 #define REQUEST_MINOR 244
54 extern int mds_queue_req(struct ptlrpc_request *);
57 int mdc_getattr(struct ptlrpc_client *peer, ino_t ino, int type, int valid,
58 struct mds_rep **rep, struct ptlrep_hdr **hdr)
60 struct ptlrpc_request *request;
63 request = ptlrpc_prep_req(peer, MDS_GETATTR, 0, NULL, 0, NULL);
65 CERROR("llight request: cannot pack\n");
69 ll_ino2fid(&request->rq_req.mds->fid1, ino, 0, type);
71 request->rq_req.mds->valid = valid;
73 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
75 rc = ptlrpc_queue_wait(request, peer);
77 CERROR("llight request: error in handling %d\n", rc);
81 CDEBUG(0, "mode: %o\n", request->rq_rep.mds->mode);
84 *rep = request->rq_rep.mds;
87 *hdr = request->rq_rephdr;
91 ptlrpc_free_req(request);
95 int mdc_readpage(struct ptlrpc_client *peer, ino_t ino, int type, __u64 offset,
96 char *addr, struct mds_rep **rep, struct ptlrep_hdr **hdr)
98 struct ptlrpc_request *request;
102 niobuf.addr = (__u64) (long) addr;
104 CDEBUG(D_INODE, "inode: %ld\n", ino);
106 request = ptlrpc_prep_req(peer, MDS_READPAGE, 0, NULL,
107 sizeof(struct niobuf), (char *)&niobuf);
109 CERROR("mdc request: cannot pack\n");
113 request->rq_req.mds->fid1.id = ino;
114 request->rq_req.mds->fid1.f_type = type;
115 request->rq_req.mds->size = offset;
116 request->rq_req.mds->tgtlen = sizeof(niobuf);
118 //request->rq_bulklen = PAGE_SIZE;
119 //request->rq_bulkbuf = (void *)(long)niobuf.addr;
120 request->rq_bulk_portal = MDS_BULK_PORTAL;
122 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
124 rc = ptlrpc_queue_wait(request, peer);
126 CERROR("mdc request: error in handling %d\n", rc);
130 CDEBUG(0, "mode: %o\n", request->rq_rep.mds->mode);
133 *rep = request->rq_rep.mds;
136 *hdr = request->rq_rephdr;
140 ptlrpc_free_req(request);
144 int mdc_reint(struct ptlrpc_client *peer, struct ptlrpc_request *request)
148 rc = ptlrpc_queue_wait(request, peer);
150 CERROR("mdc request: error in handling %d\n", rc);
156 int mdc_create_client(char *uuid, struct ptlrpc_client *cl)
160 memset(cl, 0, sizeof(*cl));
162 cl->cli_rep_unpack = mds_unpack_rep;
163 cl->cli_req_pack = mds_pack_req;
164 err = kportal_uuid_to_peer("mds", &cl->cli_server);
166 cl->cli_request_portal = MDS_REQUEST_PORTAL;
167 cl->cli_reply_portal = MDS_REPLY_PORTAL;
170 cl->cli_enqueue = mds_queue_req;
175 static int request_ioctl(struct inode *inode, struct file *file,
176 unsigned int cmd, unsigned long arg)
179 struct ptlrpc_client peer;
183 if (MINOR(inode->i_rdev) != REQUEST_MINOR) {
188 if ( _IOC_TYPE(cmd) != IOC_REQUEST_TYPE ||
189 _IOC_NR(cmd) < IOC_REQUEST_MIN_NR ||
190 _IOC_NR(cmd) > IOC_REQUEST_MAX_NR ) {
191 CDEBUG(D_IOCTL, "invalid ioctl ( type %d, nr %d, size %d )\n",
192 _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd));
197 err = mdc_create_client("mds", &peer);
199 CERROR("cannot create client");
204 case IOC_REQUEST_GETATTR: {
205 struct ptlrep_hdr *hdr = NULL;
206 CERROR("-- getting attr for ino 2\n");
207 err = mdc_getattr(&peer, 2, S_IFDIR, ~0, NULL, &hdr);
209 /* FIXME: there must be a better way to get the size */
210 OBD_FREE(hdr, sizeof(struct ptlrep_hdr) +
211 sizeof(struct mds_rep));
213 CERROR("-- done err %d\n", err);
217 case IOC_REQUEST_READPAGE: {
218 struct ptlrep_hdr *hdr = NULL;
220 OBD_ALLOC(buf, PAGE_SIZE);
225 CERROR("-- readpage 0 for ino 2\n");
226 err = mdc_readpage(&peer, 2, S_IFDIR, 0, buf, NULL, &hdr);
227 CERROR("-- done err %d\n", err);
229 CERROR("-- status: %d\n", hdr->status);
232 OBD_FREE(hdr, sizeof(struct ptlrep_hdr) +
233 sizeof(struct mds_rep));
235 OBD_FREE(buf, PAGE_SIZE);
239 case IOC_REQUEST_SETATTR: {
241 struct ptlrep_hdr *hdr;
245 iattr.ia_mode = 040777;
247 iattr.ia_valid = ATTR_MODE | ATTR_ATIME;
249 err = mdc_setattr(&peer, &inode, &iattr, NULL, &hdr);
250 CERROR("-- done err %d\n", err);
252 CERROR("-- status: %d\n", hdr->status);
255 OBD_FREE(hdr, sizeof(struct ptlrep_hdr) +
256 sizeof(struct mds_rep));
261 case IOC_REQUEST_CREATE: {
263 struct ptlrep_hdr *hdr;
267 iattr.ia_mode = 040777;
269 iattr.ia_valid = ATTR_MODE | ATTR_ATIME;
271 err = mdc_create(&peer, &inode,
272 "foofile", strlen("foofile"),
273 NULL, 0, 0100707, 47114711,
274 11, 47, 0, NULL, &hdr);
275 CERROR("-- done err %d\n", err);
277 CERROR("-- status: %d\n", hdr->status);
280 OBD_FREE(hdr, sizeof(struct ptlrep_hdr) +
281 sizeof(struct mds_rep));
295 static struct file_operations requestdev_fops = {
296 ioctl: request_ioctl,
300 static struct miscdevice request_dev = {
307 static int __init ptlrpc_request_init(void)
309 misc_register(&request_dev);
314 static void __exit ptlrpc_request_exit(void)
316 misc_deregister(&request_dev);
319 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
320 MODULE_DESCRIPTION("Lustre MDS Request Tester v1.0");
321 MODULE_LICENSE("GPL");
323 EXPORT_SYMBOL(mdc_create_client);
324 EXPORT_SYMBOL(mdc_create);
325 EXPORT_SYMBOL(mdc_unlink);
326 EXPORT_SYMBOL(mdc_rename);
327 EXPORT_SYMBOL(mdc_link);
328 EXPORT_SYMBOL(mdc_getattr);
329 EXPORT_SYMBOL(mdc_readpage);
330 EXPORT_SYMBOL(mdc_setattr);
332 module_init(ptlrpc_request_init);
333 module_exit(ptlrpc_request_exit);