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_open(struct ptlrpc_client *peer, ino_t ino, int type, int flags,
96 __u64 *fh, struct mds_rep **rep, struct ptlrep_hdr **hdr)
98 struct ptlrpc_request *request;
101 request = ptlrpc_prep_req(peer, MDS_OPEN, 0, NULL, 0, NULL);
103 CERROR("llight request: cannot pack\n");
107 ll_ino2fid(&request->rq_req.mds->fid1, ino, 0, type);
108 request->rq_req.mds->flags = flags;
110 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
112 rc = ptlrpc_queue_wait(request, peer);
114 CERROR("llight request: error in handling %d\n", rc);
119 *rep = request->rq_rep.mds;
122 *hdr = request->rq_rephdr;
124 *fh = request->rq_rep.mds->objid;
127 ptlrpc_free_req(request);
132 int mdc_close(struct ptlrpc_client *peer, ino_t ino, int type, __u64 fh,
133 struct mds_rep **rep, struct ptlrep_hdr **hdr)
135 struct ptlrpc_request *request;
138 request = ptlrpc_prep_req(peer, MDS_CLOSE, 0, NULL, 0, NULL);
140 CERROR("llight request: cannot pack\n");
144 ll_ino2fid(&request->rq_req.mds->fid1, ino, 0, type);
145 request->rq_req.mds->objid = fh;
147 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
149 rc = ptlrpc_queue_wait(request, peer);
151 CERROR("llight request: error in handling %d\n", rc);
156 *rep = request->rq_rep.mds;
159 *hdr = request->rq_rephdr;
163 ptlrpc_free_req(request);
167 int mdc_readpage(struct ptlrpc_client *peer, ino_t ino, int type, __u64 offset,
168 char *addr, struct mds_rep **rep, struct ptlrep_hdr **hdr)
170 struct ptlrpc_request *request;
171 struct niobuf niobuf;
174 niobuf.addr = (__u64) (long) addr;
176 CDEBUG(D_INODE, "inode: %ld\n", ino);
178 request = ptlrpc_prep_req(peer, MDS_READPAGE, 0, NULL,
179 sizeof(struct niobuf), (char *)&niobuf);
181 CERROR("mdc request: cannot pack\n");
185 request->rq_req.mds->fid1.id = ino;
186 request->rq_req.mds->fid1.f_type = type;
187 request->rq_req.mds->size = offset;
188 request->rq_req.mds->tgtlen = sizeof(niobuf);
190 request->rq_bulklen = PAGE_SIZE;
191 request->rq_bulkbuf = (void *)(long)niobuf.addr;
192 request->rq_bulk_portal = MDS_BULK_PORTAL;
194 sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep);
196 rc = ptlrpc_queue_wait(request, peer);
198 CERROR("mdc request: error in handling %d\n", rc);
202 CDEBUG(0, "mode: %o\n", request->rq_rep.mds->mode);
205 *rep = request->rq_rep.mds;
208 *hdr = request->rq_rephdr;
212 ptlrpc_free_req(request);
216 int mdc_reint(struct ptlrpc_client *peer, struct ptlrpc_request *request)
220 rc = ptlrpc_queue_wait(request, peer);
222 CERROR("mdc request: error in handling %d\n", rc);
228 int mdc_create_client(char *uuid, struct ptlrpc_client *cl)
232 memset(cl, 0, sizeof(*cl));
234 cl->cli_rep_unpack = mds_unpack_rep;
235 cl->cli_req_pack = mds_pack_req;
236 err = kportal_uuid_to_peer("mds", &cl->cli_server);
238 cl->cli_request_portal = MDS_REQUEST_PORTAL;
239 cl->cli_reply_portal = MDS_REPLY_PORTAL;
242 cl->cli_enqueue = mds_queue_req;
247 static int request_ioctl(struct inode *inode, struct file *file,
248 unsigned int cmd, unsigned long arg)
251 struct ptlrpc_client peer;
255 if (MINOR(inode->i_rdev) != REQUEST_MINOR) {
260 if ( _IOC_TYPE(cmd) != IOC_REQUEST_TYPE ||
261 _IOC_NR(cmd) < IOC_REQUEST_MIN_NR ||
262 _IOC_NR(cmd) > IOC_REQUEST_MAX_NR ) {
263 CDEBUG(D_IOCTL, "invalid ioctl ( type %d, nr %d, size %d )\n",
264 _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd));
269 err = mdc_create_client("mds", &peer);
271 CERROR("cannot create client");
276 case IOC_REQUEST_GETATTR: {
277 struct ptlrep_hdr *hdr = NULL;
278 CERROR("-- getting attr for ino 2\n");
279 err = mdc_getattr(&peer, 2, S_IFDIR, ~0, NULL, &hdr);
281 /* FIXME: there must be a better way to get the size */
282 OBD_FREE(hdr, sizeof(struct ptlrep_hdr) +
283 sizeof(struct mds_rep));
285 CERROR("-- done err %d\n", err);
289 case IOC_REQUEST_READPAGE: {
290 struct ptlrep_hdr *hdr = NULL;
292 OBD_ALLOC(buf, PAGE_SIZE);
297 CERROR("-- readpage 0 for ino 2\n");
298 err = mdc_readpage(&peer, 2, S_IFDIR, 0, buf, NULL, &hdr);
299 CERROR("-- done err %d\n", err);
301 CERROR("-- status: %d\n", hdr->status);
304 OBD_FREE(hdr, sizeof(struct ptlrep_hdr) +
305 sizeof(struct mds_rep));
307 OBD_FREE(buf, PAGE_SIZE);
311 case IOC_REQUEST_SETATTR: {
313 struct ptlrep_hdr *hdr;
317 iattr.ia_mode = 040777;
319 iattr.ia_valid = ATTR_MODE | ATTR_ATIME;
321 err = mdc_setattr(&peer, &inode, &iattr, NULL, &hdr);
322 CERROR("-- done err %d\n", err);
324 CERROR("-- status: %d\n", hdr->status);
327 OBD_FREE(hdr, sizeof(struct ptlrep_hdr) +
328 sizeof(struct mds_rep));
333 case IOC_REQUEST_CREATE: {
335 struct ptlrep_hdr *hdr;
339 iattr.ia_mode = 040777;
341 iattr.ia_valid = ATTR_MODE | ATTR_ATIME;
343 err = mdc_create(&peer, &inode,
344 "foofile", strlen("foofile"),
345 NULL, 0, 0100707, 47114711,
346 11, 47, 0, NULL, &hdr);
347 CERROR("-- done err %d\n", err);
349 CERROR("-- status: %d\n", hdr->status);
352 OBD_FREE(hdr, sizeof(struct ptlrep_hdr) +
353 sizeof(struct mds_rep));
367 static struct file_operations requestdev_fops = {
368 ioctl: request_ioctl,
372 static struct miscdevice request_dev = {
379 static int __init ptlrpc_request_init(void)
381 misc_register(&request_dev);
386 static void __exit ptlrpc_request_exit(void)
388 misc_deregister(&request_dev);
391 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
392 MODULE_DESCRIPTION("Lustre MDS Request Tester v1.0");
393 MODULE_LICENSE("GPL");
395 EXPORT_SYMBOL(mdc_create_client);
396 EXPORT_SYMBOL(mdc_create);
397 EXPORT_SYMBOL(mdc_unlink);
398 EXPORT_SYMBOL(mdc_rename);
399 EXPORT_SYMBOL(mdc_link);
400 EXPORT_SYMBOL(mdc_getattr);
401 EXPORT_SYMBOL(mdc_readpage);
402 EXPORT_SYMBOL(mdc_setattr);
404 module_init(ptlrpc_request_init);
405 module_exit(ptlrpc_request_exit);