Whamcloud - gitweb
d4b6deff4f48ee25f07d42c1f1a0cb14f11ddfb9
[fs/lustre-release.git] / lustre / mdc / mdc_request.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.sf.net/projects/lustre/
7  *
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.
11  *
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.
16  *
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.
20  *
21  */
22
23 #define EXPORT_SYMTAB
24 #define DEBUG_SUBSYSTEM S_MDC
25
26 #include <linux/module.h>
27 #include <linux/miscdevice.h>
28 #include <linux/lustre_mds.h>
29 #include <linux/lustre_lite.h>
30 #include <linux/lustre_dlm.h>
31 #include <linux/init.h>
32 #include <linux/lprocfs_status.h>
33
34 #define REQUEST_MINOR 244
35
36 extern int mds_queue_req(struct ptlrpc_request *);
37 extern struct lprocfs_vars status_var_nm_1[];
38 extern struct lprocfs_vars status_class_var[];
39
40 /* should become mdc_getinfo() */
41 int mdc_getstatus(struct lustre_handle *conn, struct ll_fid *rootfid)
42 {
43         struct ptlrpc_request *req;
44         struct mds_body *body;
45         int rc, size = sizeof(*body);
46         ENTRY;
47
48         req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_GETSTATUS, 1, &size,
49                               NULL);
50         if (!req)
51                 GOTO(out, rc = -ENOMEM);
52
53         body = lustre_msg_buf(req->rq_reqmsg, 0);
54         req->rq_level = LUSTRE_CONN_CON;
55         req->rq_replen = lustre_msg_size(1, &size);
56
57         mds_pack_req_body(req);
58         rc = ptlrpc_queue_wait(req);
59         rc = ptlrpc_check_status(req, rc);
60
61         if (!rc) {
62                 body = lustre_msg_buf(req->rq_repmsg, 0);
63                 mds_unpack_body(body);
64                 memcpy(rootfid, &body->fid1, sizeof(*rootfid));
65
66                 CDEBUG(D_NET, "root ino="LPU64", last_committed="LPU64
67                        ", last_xid="LPU64"\n",
68                        rootfid->id, req->rq_repmsg->last_committed,
69                        req->rq_repmsg->last_xid);
70         }
71
72         EXIT;
73  out:
74         ptlrpc_req_finished(req);
75         return rc;
76 }
77
78 int mdc_getlovinfo(struct obd_device *obd, struct lustre_handle *mdc_connh,
79                    struct ptlrpc_request **request)
80 {
81         struct ptlrpc_request *req;
82         struct mds_status_req *streq;
83         int rc, size[2] = {sizeof(*streq)};
84         ENTRY;
85
86         req = ptlrpc_prep_req(class_conn2cliimp(mdc_connh), MDS_GETLOVINFO, 1,
87                               size, NULL);
88         if (!req)
89                 GOTO(out, rc = -ENOMEM);
90
91         *request = req;
92         streq = lustre_msg_buf(req->rq_reqmsg, 0);
93         streq->flags = HTON__u32(MDS_STATUS_LOV);
94         streq->repbuf = HTON__u32(8192);
95
96         /* prepare for reply */
97         req->rq_level = LUSTRE_CONN_CON;
98         size[0] = 512;
99         size[1] = 8192;
100         req->rq_replen = lustre_msg_size(2, size);
101
102         rc = ptlrpc_queue_wait(req);
103         rc = ptlrpc_check_status(req, rc);
104
105  out:
106         RETURN(rc);
107 }
108
109
110 int mdc_getattr(struct lustre_handle *conn,
111                 obd_id ino, int type, unsigned long valid, size_t ea_size,
112                 struct ptlrpc_request **request)
113 {
114         struct ptlrpc_request *req;
115         struct mds_body *body;
116         int rc, size[2] = {sizeof(*body), 0}, bufcount = 1;
117         ENTRY;
118
119         req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_GETATTR, 1, size,
120                               NULL);
121         if (!req)
122                 GOTO(out, rc = -ENOMEM);
123
124         body = lustre_msg_buf(req->rq_reqmsg, 0);
125         ll_ino2fid(&body->fid1, ino, 0, type);
126         body->valid = valid;
127
128         if (ea_size) {
129                 size[bufcount] = ea_size;
130                 bufcount++;
131                 body->size = ea_size;
132                 CDEBUG(D_INODE, "reserving %d bytes for MD/symlink in packet\n",
133                        ea_size);
134         }
135         req->rq_replen = lustre_msg_size(bufcount, size);
136         mds_pack_req_body(req);
137
138         rc = ptlrpc_queue_wait(req);
139         rc = ptlrpc_check_status(req, rc);
140
141         if (!rc) {
142                 body = lustre_msg_buf(req->rq_repmsg, 0);
143                 mds_unpack_body(body);
144                 CDEBUG(D_NET, "mode: %o\n", body->mode);
145         }
146
147         EXIT;
148  out:
149         *request = req;
150         return rc;
151 }
152
153 void d_delete_aliases(struct inode *inode)
154 {
155         struct dentry *dentry = NULL;
156         struct list_head *tmp;
157         struct ll_sb_info *sbi = ll_i2sbi(inode);
158         ENTRY;
159
160         spin_lock(&dcache_lock);
161         list_for_each(tmp, &inode->i_dentry) {
162                 dentry = list_entry(tmp, struct dentry, d_alias);
163
164                 //                if (atomic_read(&dentry->d_count))
165                 //      continue;
166                 //if (!list_empty(&dentry->d_lru))
167                 //        continue;
168
169                 list_del_init(&dentry->d_hash);
170                 list_add(&dentry->d_hash, &sbi->ll_orphan_dentry_list);
171         }
172
173         spin_unlock(&dcache_lock);
174         EXIT;
175 }
176
177 static int mdc_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
178                             void *data, __u32 data_len, int flag)
179 {
180         int rc;
181         struct lustre_handle lockh;
182         ENTRY;
183
184         switch (flag) {
185         case LDLM_CB_BLOCKING:
186                 ldlm_lock2handle(lock, &lockh);
187                 rc = ldlm_cli_cancel(&lockh);
188                 if (rc < 0) {
189                         CDEBUG(D_INODE, "ldlm_cli_cancel: %d\n", rc);
190                         RETURN(rc);
191                 }
192                 break;
193         case LDLM_CB_CANCELING: {
194                 /* Invalidate all dentries associated with this inode */
195                 struct inode *inode = data;
196
197 #warning "FIXME: what tells us that 'inode' is valid at all?"
198                 if (inode->i_state & I_FREEING)
199                         break;
200
201                 LASSERT(inode != NULL);
202                 LASSERT(data_len == sizeof(*inode));
203
204                 if (S_ISDIR(inode->i_mode)) {
205                         CDEBUG(D_INODE, "invalidating inode %ld\n",
206                                inode->i_ino);
207
208                         ll_invalidate_inode_pages(inode);
209                 }
210
211                 if ( inode != inode->i_sb->s_root->d_inode ) {
212                         /* XXX should this igrab move up 12 lines? */
213                         LASSERT(igrab(inode) == inode);
214                         d_delete_aliases(inode);
215                         iput(inode);
216                 }
217                 break;
218         }
219         default:
220                 LBUG();
221         }
222
223         RETURN(0);
224 }
225
226 /* This should be called with both the request and the reply still packed. */
227 void mdc_store_inode_generation(struct ptlrpc_request *req, int reqoff,
228                                 int repoff)
229 {
230         struct mds_rec_create *rec = lustre_msg_buf(req->rq_reqmsg, reqoff);
231         struct mds_body *body = lustre_msg_buf(req->rq_repmsg, repoff);
232
233         memcpy(&rec->cr_replayfid, &body->fid1, sizeof rec->cr_replayfid);
234 }
235
236 int mdc_enqueue(struct lustre_handle *conn, int lock_type,
237                 struct lookup_intent *it, int lock_mode, struct inode *dir,
238                 struct dentry *de, struct lustre_handle *lockh,
239                 char *tgt, int tgtlen, void *data, int datalen)
240 {
241         struct ptlrpc_request *req;
242         struct obd_device *obddev = class_conn2obd(conn);
243         __u64 res_id[RES_NAME_SIZE] = {dir->i_ino, (__u64)dir->i_generation};
244         int size[6] = {sizeof(struct ldlm_request), sizeof(struct ldlm_intent)};
245         int rc, flags = LDLM_FL_HAS_INTENT;
246         int repsize[3] = {sizeof(struct ldlm_reply),
247                           sizeof(struct mds_body),
248                           obddev->u.cli.cl_max_mds_easize};
249         struct ldlm_reply *dlm_rep;
250         struct ldlm_intent *lit;
251         struct ldlm_request *lockreq;
252         ENTRY;
253
254         LDLM_DEBUG_NOLOCK("mdsintent %s dir %ld", ldlm_it2str(it->it_op),
255                           dir->i_ino);
256
257         if (it->it_op & (IT_MKDIR | IT_CREAT | IT_SYMLINK | IT_MKNOD)) {
258                 switch (it->it_op) {
259                 case IT_MKDIR:
260                         it->it_mode |= S_IFDIR;
261                         break;
262                 case (IT_CREAT|IT_OPEN):
263                 case IT_CREAT:
264                         it->it_mode |= S_IFREG;
265                         break;
266                 case IT_SYMLINK:
267                         it->it_mode |= S_IFLNK;
268                         break;
269                 }
270                 it->it_mode &= ~current->fs->umask;
271
272                 size[2] = sizeof(struct mds_rec_create);
273                 size[3] = de->d_name.len + 1;
274                 size[4] = tgtlen + 1;
275                 req = ptlrpc_prep_req(class_conn2cliimp(conn), LDLM_ENQUEUE, 5,
276                                       size, NULL);
277                 if (!req)
278                         RETURN(-ENOMEM);
279
280                 /* pack the intent */
281                 lit = lustre_msg_buf(req->rq_reqmsg, 1);
282                 lit->opc = NTOH__u64((__u64)it->it_op);
283
284                 /* pack the intended request */
285                 mds_create_pack(req, 2, dir, it->it_mode, 0, current->fsuid,
286                                 current->fsgid, CURRENT_TIME, de->d_name.name,
287                                 de->d_name.len, tgt, tgtlen);
288                 req->rq_replen = lustre_msg_size(3, repsize);
289         } else if (it->it_op == IT_RENAME2) {
290                 struct dentry *old_de = it->it_data;
291
292                 size[2] = sizeof(struct mds_rec_rename);
293                 size[3] = old_de->d_name.len + 1;
294                 size[4] = de->d_name.len + 1;
295                 req = ptlrpc_prep_req(class_conn2cliimp(conn), LDLM_ENQUEUE, 5,
296                                       size, NULL);
297                 if (!req)
298                         RETURN(-ENOMEM);
299
300                 /* pack the intent */
301                 lit = lustre_msg_buf(req->rq_reqmsg, 1);
302                 lit->opc = NTOH__u64((__u64)it->it_op);
303
304                 /* pack the intended request */
305                 mds_rename_pack(req, 2, old_de->d_parent->d_inode, dir,
306                                 old_de->d_name.name, old_de->d_name.len,
307                                 de->d_name.name, de->d_name.len);
308                 req->rq_replen = lustre_msg_size(3, repsize);
309         } else if (it->it_op == IT_LINK2) {
310                 struct dentry *old_de = it->it_data;
311
312                 size[2] = sizeof(struct mds_rec_link);
313                 size[3] = de->d_name.len + 1;
314                 req = ptlrpc_prep_req(class_conn2cliimp(conn), LDLM_ENQUEUE, 4,
315                                       size, NULL);
316                 if (!req)
317                         RETURN(-ENOMEM);
318
319                 /* pack the intent */
320                 lit = lustre_msg_buf(req->rq_reqmsg, 1);
321                 lit->opc = NTOH__u64((__u64)it->it_op);
322
323                 /* pack the intended request */
324                 mds_link_pack(req, 2, old_de->d_inode, dir,
325                               de->d_name.name, de->d_name.len);
326                 req->rq_replen = lustre_msg_size(3, repsize);
327         } else if (it->it_op == IT_UNLINK || it->it_op == IT_RMDIR) {
328                 size[2] = sizeof(struct mds_rec_unlink);
329                 size[3] = de->d_name.len + 1;
330                 req = ptlrpc_prep_req(class_conn2cliimp(conn), LDLM_ENQUEUE, 4,
331                                       size, NULL);
332                 if (!req)
333                         RETURN(-ENOMEM);
334
335                 /* pack the intent */
336                 lit = lustre_msg_buf(req->rq_reqmsg, 1);
337                 lit->opc = NTOH__u64((__u64)it->it_op);
338
339                 /* pack the intended request */
340                 mds_unlink_pack(req, 2, dir, NULL,
341                                 it->it_op == IT_UNLINK ? S_IFREG : S_IFDIR,
342                                 de->d_name.name, de->d_name.len);
343
344                 req->rq_replen = lustre_msg_size(3, repsize);
345         } else if (it->it_op & (IT_GETATTR | IT_RENAME | IT_LINK |
346                    IT_OPEN | IT_SETATTR | IT_LOOKUP | IT_READLINK)) {
347                 size[2] = sizeof(struct mds_body);
348                 size[3] = de->d_name.len + 1;
349
350                 req = ptlrpc_prep_req(class_conn2cliimp(conn), LDLM_ENQUEUE, 4,
351                                       size, NULL);
352                 if (!req)
353                         RETURN(-ENOMEM);
354
355                 /* pack the intent */
356                 lit = lustre_msg_buf(req->rq_reqmsg, 1);
357                 lit->opc = NTOH__u64((__u64)it->it_op);
358
359                 /* pack the intended request */
360                 mds_getattr_pack(req, 2, dir, de->d_name.name, de->d_name.len);
361
362                 /* get ready for the reply */
363                 req->rq_replen = lustre_msg_size(3, repsize);
364         } else if (it->it_op == IT_READDIR) {
365                 req = ptlrpc_prep_req(class_conn2cliimp(conn), LDLM_ENQUEUE, 1,
366                                       size, NULL);
367                 if (!req)
368                         RETURN(-ENOMEM);
369
370                 /* get ready for the reply */
371                 req->rq_replen = lustre_msg_size(1, repsize);
372         } else {
373                 LBUG();
374                 RETURN(-EINVAL);
375         }
376
377         rc = ldlm_cli_enqueue(conn, req, obddev->obd_namespace, NULL, res_id,
378                               lock_type, NULL, 0, lock_mode, &flags,
379                               ldlm_completion_ast, mdc_blocking_ast, data,
380                               datalen, lockh);
381
382         if (it->it_op != IT_READDIR) {
383                 /* XXX This should become a lustre_msg flag, but for now... */
384                 __u32 *opp = lustre_msg_buf(req->rq_reqmsg, 2);
385                 *opp |= REINT_REPLAYING;
386         }
387
388         if (rc == -ENOENT) {
389                 /* This can go when we're sure that this can never happen */
390                 LBUG();
391         }
392         if (rc == ELDLM_LOCK_ABORTED) {
393                 lock_mode = 0;
394                 memset(lockh, 0, sizeof(*lockh));
395                 /* rc = 0 */
396         } else if (rc != 0) {
397                 CERROR("ldlm_cli_enqueue: %d\n", rc);
398                 RETURN(rc);
399         } else {
400                 /* The server almost certainly gave us a lock other than the one
401                  * that we asked for.  If we already have a matching lock, then
402                  * cancel this one--we don't need two. */
403                 struct ldlm_lock *lock = ldlm_handle2lock(lockh);
404                 struct lustre_handle lockh2;
405                 LASSERT(lock);
406
407                 LDLM_DEBUG(lock, "matching against this");
408
409                 memcpy(&lockh2, lockh, sizeof(lockh2));
410                 if (ldlm_lock_match(NULL, NULL, LDLM_PLAIN, NULL, 0, LCK_NL,
411                                     &lockh2)) {
412                         /* We already have a lock; cancel the old one */
413                         ldlm_lock_decref(lockh, lock_mode);
414                         ldlm_cli_cancel(lockh);
415                         memcpy(lockh, &lockh2, sizeof(lockh2));
416                 }
417                 LDLM_LOCK_PUT(lock);
418         }
419
420         /* On replay, we don't want the lock granted. */
421         lockreq = lustre_msg_buf(req->rq_reqmsg, 0);
422         lockreq->lock_flags |= LDLM_FL_INTENT_ONLY;
423
424         dlm_rep = lustre_msg_buf(req->rq_repmsg, 0);
425         it->it_disposition = (int) dlm_rep->lock_policy_res1;
426         it->it_status = (int) dlm_rep->lock_policy_res2;
427         it->it_lock_mode = lock_mode;
428         it->it_data = req;
429
430         RETURN(0);
431 }
432
433 int mdc_cancel_unused(struct lustre_handle *conn, struct inode *inode,
434                       int flags)
435 {
436         __u64 res_id[RES_NAME_SIZE] = {inode->i_ino, inode->i_generation};
437         struct obd_device *obddev = class_conn2obd(conn);
438         ENTRY;
439         RETURN(ldlm_cli_cancel_unused(obddev->obd_namespace, res_id, flags));
440 }
441
442 struct replay_open_data {
443         struct lustre_handle *fh;
444 };
445
446 static void mdc_replay_open(struct ptlrpc_request *req)
447 {
448         int offset;
449         struct replay_open_data *saved;
450         struct mds_body *body = lustre_msg_buf(req->rq_repmsg, 0);
451
452         if (lustre_msg_get_op_flags(req->rq_reqmsg) & MDS_OPEN_HAS_EA)
453                 offset = 2;
454         else
455                 offset = 1;
456
457         saved = lustre_msg_buf(req->rq_reqmsg, offset);
458         mds_unpack_body(body);
459         CDEBUG(D_HA, "updating from "LPD64"/"LPD64" to "LPD64"/"LPD64"\n",
460                saved->fh->addr, saved->fh->cookie,
461                body->handle.addr, body->handle.cookie);
462         memcpy(saved->fh, &body->handle, sizeof(body->handle));
463 }
464
465 int mdc_open(struct lustre_handle *conn, obd_id ino, int type, int flags,
466              struct lov_mds_md *lmm, int lmm_size, struct lustre_handle *fh,
467              struct ptlrpc_request **request)
468 {
469         struct mds_body *body;
470         struct replay_open_data *replay_data;
471         int rc, size[3] = {sizeof(*body), sizeof(*replay_data)}, bufcount = 2;
472         struct ptlrpc_request *req;
473         ENTRY;
474
475         if (lmm && lmm_size) {
476                 bufcount = 3;
477                 size[2] = size[1]; /* shuffle the spare data along */
478                 size[1] = lmm_size;
479         }
480
481         req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_OPEN, bufcount, size,
482                               NULL);
483         if (!req)
484                 GOTO(out, rc = -ENOMEM);
485
486         req->rq_flags |= PTL_RPC_FL_REPLAY;
487         body = lustre_msg_buf(req->rq_reqmsg, 0);
488
489         ll_ino2fid(&body->fid1, ino, 0, type);
490         body->flags = HTON__u32(flags);
491         memcpy(&body->handle, fh, sizeof(body->handle));
492
493         if (lmm && lmm_size) {
494                 CDEBUG(D_INODE, "sending %u bytes MD for ino LPU64\n",
495                        lmm_size, ino);
496                 lustre_msg_set_op_flags(req->rq_reqmsg, MDS_OPEN_HAS_EA);
497                 memcpy(lustre_msg_buf(req->rq_reqmsg, 1), lmm, lmm_size);
498                 body->flags |= HTON__u32(OBD_MD_FLEASIZE);
499         }
500
501         req->rq_replen = lustre_msg_size(1, size);
502
503         rc = ptlrpc_queue_wait(req);
504         rc = ptlrpc_check_status(req, rc);
505         if (!rc) {
506                 body = lustre_msg_buf(req->rq_repmsg, 0);
507                 mds_unpack_body(body);
508                 memcpy(fh, &body->handle, sizeof(*fh));
509         }
510
511         /* If open is replayed, we need to fix up the fh. */
512         req->rq_replay_cb = mdc_replay_open;
513         replay_data = lustre_msg_buf(req->rq_reqmsg, lmm ? 2 : 1);
514         replay_data->fh = fh;
515
516         EXIT;
517  out:
518         *request = req;
519         return rc;
520 }
521
522 int mdc_close(struct lustre_handle *conn, obd_id ino, int type,
523               struct lustre_handle *fh, struct ptlrpc_request **request)
524 {
525         struct mds_body *body;
526         int rc, size = sizeof(*body);
527         struct ptlrpc_request *req;
528
529         req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_CLOSE, 1, &size,
530                               NULL);
531         if (!req)
532                 GOTO(out, rc = -ENOMEM);
533
534         body = lustre_msg_buf(req->rq_reqmsg, 0);
535         ll_ino2fid(&body->fid1, ino, 0, type);
536         memcpy(&body->handle, fh, sizeof(body->handle));
537
538         req->rq_replen = lustre_msg_size(0, NULL);
539
540         rc = ptlrpc_queue_wait(req);
541         rc = ptlrpc_check_status(req, rc);
542
543         EXIT;
544  out:
545         *request = req;
546         return rc;
547 }
548
549 int mdc_readpage(struct lustre_handle *conn, obd_id ino, int type, __u64 offset,
550                  char *addr, struct ptlrpc_request **request)
551 {
552         struct ptlrpc_connection *connection = 
553                 client_conn2cli(conn)->cl_import.imp_connection;
554         struct ptlrpc_request *req = NULL;
555         struct ptlrpc_bulk_desc *desc = NULL;
556         struct ptlrpc_bulk_page *bulk = NULL;
557         struct mds_body *body;
558         int rc, size = sizeof(*body);
559         ENTRY;
560
561         CDEBUG(D_INODE, "inode: %ld\n", (long)ino);
562
563         desc = ptlrpc_prep_bulk(connection);
564         if (desc == NULL)
565                 GOTO(out, rc = -ENOMEM);
566
567         req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_READPAGE, 1, &size,
568                               NULL);
569         if (!req)
570                 GOTO(out2, rc = -ENOMEM);
571
572         bulk = ptlrpc_prep_bulk_page(desc);
573         bulk->bp_buflen = PAGE_SIZE;
574         bulk->bp_buf = addr;
575         bulk->bp_xid = req->rq_xid;
576         desc->bd_portal = MDS_BULK_PORTAL;
577
578         rc = ptlrpc_register_bulk(desc);
579         if (rc) {
580                 CERROR("couldn't setup bulk sink: error %d.\n", rc);
581                 GOTO(out2, rc);
582         }
583
584         body = lustre_msg_buf(req->rq_reqmsg, 0);
585         body->fid1.id = ino;
586         body->fid1.f_type = type;
587         body->size = offset;
588
589         req->rq_replen = lustre_msg_size(1, &size);
590         rc = ptlrpc_queue_wait(req);
591         rc = ptlrpc_check_status(req, rc);
592         if (rc) {
593                 ptlrpc_abort_bulk(desc);
594                 GOTO(out2, rc);
595         } else {
596                 body = lustre_msg_buf(req->rq_repmsg, 0);
597                 mds_unpack_body(body);
598         }
599
600         EXIT;
601  out2:
602         ptlrpc_free_bulk(desc);
603  out:
604         *request = req;
605         return rc;
606 }
607
608 static int mdc_statfs(struct lustre_handle *conn, struct obd_statfs *osfs)
609 {
610         struct ptlrpc_request *req;
611         int rc, size = sizeof(*osfs);
612         ENTRY;
613
614         req = ptlrpc_prep_req(class_conn2cliimp(conn), MDS_STATFS, 0, NULL,
615                               NULL);
616         if (!req)
617                 RETURN(-ENOMEM);
618
619         req->rq_replen = lustre_msg_size(1, &size);
620
621         rc = ptlrpc_queue_wait(req);
622         rc = ptlrpc_check_status(req, rc);
623
624         if (rc)
625                 GOTO(out, rc);
626
627         obd_statfs_unpack(osfs, lustre_msg_buf(req->rq_repmsg, 0));
628
629         EXIT;
630 out:
631         ptlrpc_req_finished(req);
632
633         return rc;
634 }
635 int mdc_attach(struct obd_device *dev, obd_count len, void *data)
636 {
637         return lprocfs_reg_obd(dev, status_var_nm_1, dev);
638 }
639
640 int mdc_detach(struct obd_device *dev)
641 {
642         return lprocfs_dereg_obd(dev);
643 }
644 struct obd_ops mdc_obd_ops = {
645         o_attach: mdc_attach,
646         o_detach: mdc_detach,
647         o_setup:   client_obd_setup,
648         o_cleanup: client_obd_cleanup,
649         o_connect: client_obd_connect,
650         o_disconnect: client_obd_disconnect,
651         o_statfs: mdc_statfs,
652 };
653
654 static int __init ptlrpc_request_init(void)
655 {
656         return class_register_type(&mdc_obd_ops, status_class_var,
657                                    LUSTRE_MDC_NAME);
658 }
659
660 static void __exit ptlrpc_request_exit(void)
661 {
662         class_unregister_type(LUSTRE_MDC_NAME);
663 }
664
665 MODULE_AUTHOR("Cluster File Systems <info@clusterfs.com>");
666 MODULE_DESCRIPTION("Lustre Metadata Client v1.0");
667 MODULE_LICENSE("GPL");
668
669 EXPORT_SYMBOL(d_delete_aliases);
670 EXPORT_SYMBOL(mdc_getstatus);
671 EXPORT_SYMBOL(mdc_getlovinfo);
672 EXPORT_SYMBOL(mdc_enqueue);
673 EXPORT_SYMBOL(mdc_cancel_unused);
674 EXPORT_SYMBOL(mdc_getattr);
675 EXPORT_SYMBOL(mdc_create);
676 EXPORT_SYMBOL(mdc_unlink);
677 EXPORT_SYMBOL(mdc_rename);
678 EXPORT_SYMBOL(mdc_link);
679 EXPORT_SYMBOL(mdc_readpage);
680 EXPORT_SYMBOL(mdc_setattr);
681 EXPORT_SYMBOL(mdc_close);
682 EXPORT_SYMBOL(mdc_open);
683
684 EXPORT_SYMBOL(mdc_store_inode_generation);
685
686 module_init(ptlrpc_request_init);
687 module_exit(ptlrpc_request_exit);