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 Lustre, http://www.sf.net/projects/lustre/
8 * Lustre 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 * Lustre 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 Lustre; 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 ptlrpc_request **req)
62 struct ptlrpc_request *request;
66 request = ptlrpc_prep_req(cl, MDS_GETATTR, 0, NULL, 0, NULL);
68 CERROR("llight request: cannot pack\n");
69 GOTO(out, rc = -ENOMEM);
72 ll_ino2fid(&request->rq_req.mds->fid1, ino, 0, type);
74 request->rq_req.mds->valid = valid;
76 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
78 rc = ptlrpc_queue_wait(cl, request);
79 rc = ptlrpc_check_status(request, rc);
82 CDEBUG(D_NET, "mode: %o\n", request->rq_rep.mds->mode);
90 int mdc_open(struct ptlrpc_client *cl, ino_t ino, int type, int flags,
91 __u64 *fh, struct ptlrpc_request **req)
93 struct ptlrpc_request *request;
96 request = ptlrpc_prep_req(cl, MDS_OPEN, 0, NULL, 0, NULL);
98 CERROR("llight request: cannot pack\n");
103 ll_ino2fid(&request->rq_req.mds->fid1, ino, 0, type);
104 request->rq_req.mds->flags = HTON__u32(flags);
106 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
108 rc = ptlrpc_queue_wait(cl, request);
109 rc = ptlrpc_check_status(request, rc);
112 CERROR("llight request: error in handling %d\n", rc);
116 *fh = request->rq_rep.mds->objid;
123 int mdc_close(struct ptlrpc_client *cl, ino_t ino, int type, __u64 fh,
124 struct ptlrpc_request **req)
126 struct ptlrpc_request *request;
129 request = ptlrpc_prep_req(cl, MDS_CLOSE, 0, NULL, 0, NULL);
131 CERROR("llight request: cannot pack\n");
136 ll_ino2fid(&request->rq_req.mds->fid1, ino, 0, type);
137 request->rq_req.mds->objid = fh;
139 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
141 rc = ptlrpc_queue_wait(cl, request);
142 rc = ptlrpc_check_status(request, rc);
145 CERROR("llight request: error in handling %d\n", rc);
154 int mdc_readpage(struct ptlrpc_client *cl, ino_t ino, int type, __u64 offset,
155 char *addr, struct ptlrpc_request **req)
157 struct ptlrpc_request *request = NULL;
158 struct ptlrpc_bulk_desc *bulk = NULL;
159 struct niobuf niobuf;
162 niobuf.addr = (__u64) (long) addr;
164 CDEBUG(D_INODE, "inode: %ld\n", ino);
166 bulk = ptlrpc_prep_bulk(&cl->cli_server);
168 CERROR("%s: cannot init bulk desc\n", __FUNCTION__);
173 request = ptlrpc_prep_req(cl, MDS_READPAGE, 0, NULL,
174 sizeof(struct niobuf), (char *)&niobuf);
176 CERROR("%s: cannot pack\n", __FUNCTION__);
181 bulk->b_buflen = PAGE_SIZE;
182 bulk->b_buf = (void *)(long)niobuf.addr;
183 bulk->b_portal = MDS_BULK_PORTAL;
184 bulk->b_xid = request->rq_xid;
186 rc = ptlrpc_register_bulk(bulk);
188 CERROR("%s: couldn't setup bulk sink: error %d.\n",
193 request->rq_req.mds->fid1.id = ino;
194 request->rq_req.mds->fid1.f_type = type;
195 request->rq_req.mds->size = offset;
196 request->rq_req.mds->tgtlen = sizeof(niobuf);
197 request->rq_replen = sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
199 rc = ptlrpc_queue_wait(cl, request);
201 CERROR("mdc request: error in handling %d\n", rc);
202 ptlrpc_abort_bulk(bulk);
206 CDEBUG(D_INODE, "mode: %o\n", request->rq_rep.mds->mode);
211 OBD_FREE(bulk, sizeof(*bulk));
215 static int request_ioctl(struct inode *inode, struct file *file,
216 unsigned int cmd, unsigned long arg)
219 struct ptlrpc_client cl;
220 struct ptlrpc_request *request;
224 if (MINOR(inode->i_rdev) != REQUEST_MINOR)
227 if (_IOC_TYPE(cmd) != IOC_REQUEST_TYPE ||
228 _IOC_NR(cmd) < IOC_REQUEST_MIN_NR ||
229 _IOC_NR(cmd) > IOC_REQUEST_MAX_NR ) {
230 CDEBUG(D_IOCTL, "invalid ioctl ( type %d, nr %d, size %d )\n",
231 _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd));
235 err = ptlrpc_connect_client(-1, "mds",
236 MDS_REQUEST_PORTAL, MDC_REPLY_PORTAL,
237 mds_pack_req, mds_unpack_rep, &cl);
239 CERROR("cannot create client\n");
244 case IOC_REQUEST_GETATTR: {
245 CERROR("-- getting attr for ino %lu\n", arg);
246 err = mdc_getattr(&cl, arg, S_IFDIR, ~0, &request);
247 CERROR("-- done err %d\n", err);
252 case IOC_REQUEST_READPAGE: {
254 OBD_ALLOC(buf, PAGE_SIZE);
259 CERROR("-- readpage 0 for ino %lu\n", arg);
260 err = mdc_readpage(&cl, arg, S_IFDIR, 0, buf, &request);
261 CERROR("-- done err %d\n", err);
262 OBD_FREE(buf, PAGE_SIZE);
267 case IOC_REQUEST_SETATTR: {
272 inode.i_generation = 0;
273 iattr.ia_mode = 040777;
275 iattr.ia_valid = ATTR_MODE | ATTR_ATIME;
277 err = mdc_setattr(&cl, &inode, &iattr, &request);
278 CERROR("-- done err %d\n", err);
283 case IOC_REQUEST_CREATE: {
288 inode.i_generation = 0;
289 iattr.ia_mode = 040777;
291 iattr.ia_valid = ATTR_MODE | ATTR_ATIME;
293 err = mdc_create(&cl, &inode,
294 "foofile", strlen("foofile"),
295 NULL, 0, 0100707, 47114711,
296 11, 47, 0, &request);
297 CERROR("-- done err %d\n", err);
302 case IOC_REQUEST_OPEN: {
304 copy_from_user(&ino, (__u64 *)arg, sizeof(ino));
305 CERROR("-- opening ino %llu\n", ino);
306 err = mdc_open(&cl, ino, S_IFDIR, O_RDONLY, &fh, &request);
307 copy_to_user((__u64 *)arg, &fh, sizeof(fh));
308 CERROR("-- done err %d (fh=%Lu)\n", err, fh);
313 case IOC_REQUEST_CLOSE: {
314 CERROR("-- closing ino 2, filehandle %lu\n", arg);
315 err = mdc_close(&cl, 2, S_IFDIR, arg, &request);
316 CERROR("-- done err %d\n", err);
326 ptlrpc_free_req(request);
332 static struct file_operations requestdev_fops = {
333 ioctl: request_ioctl,
336 static struct miscdevice request_dev = {
342 static int __init ptlrpc_request_init(void)
344 misc_register(&request_dev);
348 static void __exit ptlrpc_request_exit(void)
350 misc_deregister(&request_dev);
353 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
354 MODULE_DESCRIPTION("Lustre MDS Request Tester v1.0");
355 MODULE_LICENSE("GPL");
357 EXPORT_SYMBOL(mdc_create);
358 EXPORT_SYMBOL(mdc_unlink);
359 EXPORT_SYMBOL(mdc_rename);
360 EXPORT_SYMBOL(mdc_link);
361 EXPORT_SYMBOL(mdc_getattr);
362 EXPORT_SYMBOL(mdc_readpage);
363 EXPORT_SYMBOL(mdc_setattr);
364 EXPORT_SYMBOL(mdc_close);
365 EXPORT_SYMBOL(mdc_open);
367 module_init(ptlrpc_request_init);
368 module_exit(ptlrpc_request_exit);