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/obd_class.h>
49 #include <linux/lustre_lib.h>
50 #include <linux/lustre_idl.h>
51 #include <linux/lustre_mds.h>
53 #define REQUEST_MINOR 244
55 extern int mds_queue_req(struct ptlrpc_request *);
58 int mdc_getattr(struct ptlrpc_client *cl, ino_t ino, int type, int valid,
59 struct mds_rep **rep, struct ptlrep_hdr **hdr)
61 struct ptlrpc_request *request;
64 request = ptlrpc_prep_req(cl, MDS_GETATTR, 0, NULL, 0, NULL);
66 CERROR("llight request: cannot pack\n");
70 ll_ino2fid(&request->rq_req.mds->fid1, ino, 0, type);
72 request->rq_req.mds->valid = valid;
74 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
76 rc = ptlrpc_queue_wait(cl, request);
78 CERROR("llight request: error in handling %d\n", rc);
82 CDEBUG(0, "mode: %o\n", request->rq_rep.mds->mode);
85 *rep = request->rq_rep.mds;
88 *hdr = request->rq_rephdr;
92 ptlrpc_free_req(request);
96 int mdc_open(struct ptlrpc_client *cl, ino_t ino, int type, int flags,
97 __u64 *fh, struct mds_rep **rep, struct ptlrep_hdr **hdr)
99 struct ptlrpc_request *request;
102 request = ptlrpc_prep_req(cl, MDS_OPEN, 0, NULL, 0, NULL);
104 CERROR("llight request: cannot pack\n");
108 ll_ino2fid(&request->rq_req.mds->fid1, ino, 0, type);
109 request->rq_req.mds->flags = flags;
111 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
113 rc = ptlrpc_queue_wait(cl, request);
115 CERROR("llight request: error in handling %d\n", rc);
120 *rep = request->rq_rep.mds;
123 *hdr = request->rq_rephdr;
125 *fh = request->rq_rep.mds->objid;
128 ptlrpc_free_req(request);
133 int mdc_close(struct ptlrpc_client *cl, ino_t ino, int type, __u64 fh,
134 struct mds_rep **rep, struct ptlrep_hdr **hdr)
136 struct ptlrpc_request *request;
139 request = ptlrpc_prep_req(cl, MDS_CLOSE, 0, NULL, 0, NULL);
141 CERROR("llight request: cannot pack\n");
145 ll_ino2fid(&request->rq_req.mds->fid1, ino, 0, type);
146 request->rq_req.mds->objid = fh;
148 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
150 rc = ptlrpc_queue_wait(cl, request);
152 CERROR("llight request: error in handling %d\n", rc);
157 *rep = request->rq_rep.mds;
160 *hdr = request->rq_rephdr;
164 ptlrpc_free_req(request);
168 int mdc_readpage(struct ptlrpc_client *cl, ino_t ino, int type, __u64 offset,
169 char *addr, struct mds_rep **rep, struct ptlrep_hdr **hdr)
171 struct ptlrpc_request *request;
172 struct ptlrpc_bulk_desc *bulk;
173 struct niobuf niobuf;
176 niobuf.addr = (__u64) (long) addr;
178 CDEBUG(D_INODE, "inode: %ld\n", ino);
180 bulk = ptlrpc_prep_bulk(&cl->cli_server);
182 CERROR("%s: cannot init bulk desc\n", __FUNCTION__);
186 request = ptlrpc_prep_req(cl, MDS_READPAGE, 0, NULL,
187 sizeof(struct niobuf), (char *)&niobuf);
189 OBD_FREE(bulk, sizeof(*bulk));
190 CERROR("%s: cannot pack\n", __FUNCTION__);
194 bulk->b_buflen = PAGE_SIZE;
195 bulk->b_buf = (void *)(long)niobuf.addr;
196 bulk->b_portal = MDS_BULK_PORTAL;
197 bulk->b_xid = request->rq_xid;
199 rc = ptlrpc_register_bulk(bulk);
201 CERROR("%s: couldn't setup bulk sink: error %d.\n",
206 request->rq_req.mds->fid1.id = ino;
207 request->rq_req.mds->fid1.f_type = type;
208 request->rq_req.mds->size = offset;
209 request->rq_req.mds->tgtlen = sizeof(niobuf);
210 request->rq_replen = sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
212 rc = ptlrpc_queue_wait(cl, request);
214 CERROR("mdc request: error in handling %d\n", rc);
218 CDEBUG(D_INODE, "mode: %o\n", request->rq_rep.mds->mode);
221 *rep = request->rq_rep.mds;
224 *hdr = request->rq_rephdr;
228 ptlrpc_free_req(request);
229 OBD_FREE(bulk, sizeof(*bulk));
233 int mdc_reint(struct ptlrpc_client *cl, struct ptlrpc_request *request)
237 rc = ptlrpc_queue_wait(cl, request);
239 CERROR("mdc request: error in handling %d\n", rc);
245 static int request_ioctl(struct inode *inode, struct file *file,
246 unsigned int cmd, unsigned long arg)
249 struct ptlrpc_client cl;
253 if (MINOR(inode->i_rdev) != REQUEST_MINOR) {
258 if ( _IOC_TYPE(cmd) != IOC_REQUEST_TYPE ||
259 _IOC_NR(cmd) < IOC_REQUEST_MIN_NR ||
260 _IOC_NR(cmd) > IOC_REQUEST_MAX_NR ) {
261 CDEBUG(D_IOCTL, "invalid ioctl ( type %d, nr %d, size %d )\n",
262 _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd));
267 /* XXX complete this to get debugging working again */
270 CERROR("cannot create client");
275 case IOC_REQUEST_GETATTR: {
276 struct ptlrep_hdr *hdr = NULL;
277 CERROR("-- getting attr for ino 2\n");
278 err = mdc_getattr(&cl, 2, S_IFDIR, ~0, NULL, &hdr);
280 /* FIXME: there must be a better way to get the size */
281 OBD_FREE(hdr, sizeof(struct ptlrep_hdr) +
282 sizeof(struct mds_rep));
284 CERROR("-- done err %d\n", err);
288 case IOC_REQUEST_READPAGE: {
289 struct ptlrep_hdr *hdr = NULL;
291 OBD_ALLOC(buf, PAGE_SIZE);
296 CERROR("-- readpage 0 for ino 2\n");
297 err = mdc_readpage(&cl, 2, S_IFDIR, 0, buf, NULL, &hdr);
298 CERROR("-- done err %d\n", err);
300 CERROR("-- status: %d\n", hdr->status);
303 OBD_FREE(hdr, sizeof(struct ptlrep_hdr) +
304 sizeof(struct mds_rep));
306 OBD_FREE(buf, PAGE_SIZE);
310 case IOC_REQUEST_SETATTR: {
312 struct ptlrep_hdr *hdr;
316 iattr.ia_mode = 040777;
318 iattr.ia_valid = ATTR_MODE | ATTR_ATIME;
320 err = mdc_setattr(&cl, &inode, &iattr, NULL, &hdr);
321 CERROR("-- done err %d\n", err);
323 CERROR("-- status: %d\n", hdr->status);
326 OBD_FREE(hdr, sizeof(struct ptlrep_hdr) +
327 sizeof(struct mds_rep));
332 case IOC_REQUEST_CREATE: {
334 struct ptlrep_hdr *hdr;
338 iattr.ia_mode = 040777;
340 iattr.ia_valid = ATTR_MODE | ATTR_ATIME;
342 err = mdc_create(&cl, &inode,
343 "foofile", strlen("foofile"),
344 NULL, 0, 0100707, 47114711,
345 11, 47, 0, NULL, &hdr);
346 CERROR("-- done err %d\n", err);
348 CERROR("-- status: %d\n", hdr->status);
351 OBD_FREE(hdr, sizeof(struct ptlrep_hdr) +
352 sizeof(struct mds_rep));
366 static struct file_operations requestdev_fops = {
367 ioctl: request_ioctl,
371 static struct miscdevice request_dev = {
378 static int __init ptlrpc_request_init(void)
380 misc_register(&request_dev);
385 static void __exit ptlrpc_request_exit(void)
387 misc_deregister(&request_dev);
390 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
391 MODULE_DESCRIPTION("Lustre MDS Request Tester v1.0");
392 MODULE_LICENSE("GPL");
394 EXPORT_SYMBOL(mdc_create);
395 EXPORT_SYMBOL(mdc_unlink);
396 EXPORT_SYMBOL(mdc_rename);
397 EXPORT_SYMBOL(mdc_link);
398 EXPORT_SYMBOL(mdc_getattr);
399 EXPORT_SYMBOL(mdc_readpage);
400 EXPORT_SYMBOL(mdc_setattr);
402 module_init(ptlrpc_request_init);
403 module_exit(ptlrpc_request_exit);