1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2003 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.
23 # define EXPORT_SYMTAB
25 #define DEBUG_SUBSYSTEM S_MDC
28 # include <linux/module.h>
29 # include <linux/pagemap.h>
30 # include <linux/miscdevice.h>
31 # include <linux/init.h>
33 # include <liblustre.h>
36 #include <linux/obd_class.h>
37 #include <linux/lustre_mds.h>
38 #include <linux/lustre_dlm.h>
39 #include <linux/lprocfs_status.h>
40 #include "mdc_internal.h"
42 #define REQUEST_MINOR 244
44 extern int mds_queue_req(struct ptlrpc_request *);
45 /* Helper that implements most of mdc_getstatus and signal_completed_replay. */
46 /* XXX this should become mdc_get_info("key"), sending MDS_GET_INFO RPC */
47 static int send_getstatus(struct obd_import *imp, struct ll_fid *rootfid,
48 int level, int msg_flags)
50 struct ptlrpc_request *req;
51 struct mds_body *body;
52 int rc, size = sizeof(*body);
55 req = ptlrpc_prep_req(imp, MDS_GETSTATUS, 1, &size, NULL);
57 GOTO(out, rc = -ENOMEM);
59 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body));
60 req->rq_send_state = level;
61 req->rq_replen = lustre_msg_size(1, &size);
63 mdc_pack_req_body(req);
64 req->rq_reqmsg->flags |= msg_flags;
65 rc = ptlrpc_queue_wait(req);
68 body = lustre_swab_repbuf (req, 0, sizeof (*body),
69 lustre_swab_mds_body);
71 CERROR ("Can't extract mds_body\n");
72 GOTO (out, rc = -EPROTO);
75 memcpy(rootfid, &body->fid1, sizeof(*rootfid));
77 CDEBUG(D_NET, "root ino="LPU64", last_committed="LPU64
78 ", last_xid="LPU64"\n",
79 rootfid->id, req->rq_repmsg->last_committed,
80 req->rq_repmsg->last_xid);
85 ptlrpc_req_finished(req);
89 /* This should be mdc_get_info("rootfid") */
90 int mdc_getstatus(struct obd_export *exp, struct ll_fid *rootfid)
92 return send_getstatus(class_exp2cliimp(exp), rootfid, LUSTRE_IMP_FULL,
96 int mdc_getattr_common(struct obd_export *exp, unsigned int ea_size,
97 struct ptlrpc_request *req)
99 struct mds_body *body;
102 int size[2] = {sizeof(*body), 0};
106 /* request message already built */
109 size[bufcount++] = ea_size;
110 CDEBUG(D_INODE, "reserved %u bytes for MD/symlink in packet\n",
113 req->rq_replen = lustre_msg_size(bufcount, size);
115 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
116 rc = ptlrpc_queue_wait(req);
117 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
121 body = lustre_swab_repbuf (req, 0, sizeof (*body),
122 lustre_swab_mds_body);
124 CERROR ("Can't unpack mds_body\n");
128 CDEBUG(D_NET, "mode: %o\n", body->mode);
130 LASSERT_REPSWAB (req, 1);
131 if (body->eadatasize != 0) {
132 /* reply indicates presence of eadata; check it's there... */
133 eadata = lustre_msg_buf (req->rq_repmsg, 1, body->eadatasize);
134 if (eadata == NULL) {
135 CERROR ("Missing/short eadata\n");
143 int mdc_getattr(struct obd_export *exp, struct ll_fid *fid,
144 unsigned long valid, unsigned int ea_size,
145 struct ptlrpc_request **request)
147 struct ptlrpc_request *req;
148 struct mds_body *body;
149 int size = sizeof(*body);
153 /* XXX do we need to make another request here? We just did a getattr
154 * to do the lookup in the first place.
156 req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_GETATTR, 1, &size,
159 GOTO(out, rc = -ENOMEM);
161 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body));
162 memcpy(&body->fid1, fid, sizeof(*fid));
164 body->eadatasize = ea_size;
165 mdc_pack_req_body(req);
167 rc = mdc_getattr_common(exp, ea_size, req);
169 ptlrpc_req_finished (req);
177 int mdc_getattr_name(struct obd_export *exp, struct ll_fid *fid,
178 char *filename, int namelen, unsigned long valid,
179 unsigned int ea_size, struct ptlrpc_request **request)
181 struct ptlrpc_request *req;
182 struct mds_body *body;
183 int rc, size[2] = {sizeof(*body), namelen};
186 req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_GETATTR_NAME, 2,
189 GOTO(out, rc = -ENOMEM);
191 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body));
192 memcpy(&body->fid1, fid, sizeof(*fid));
194 body->eadatasize = ea_size;
195 mdc_pack_req_body(req);
197 LASSERT (strnlen (filename, namelen) == namelen - 1);
198 memcpy(lustre_msg_buf(req->rq_reqmsg, 1, namelen), filename, namelen);
200 rc = mdc_getattr_common(exp, ea_size, req);
202 ptlrpc_req_finished (req);
210 /* This should be called with both the request and the reply still packed. */
211 void mdc_store_inode_generation(struct ptlrpc_request *req, int reqoff,
214 struct mds_rec_create *rec =
215 lustre_msg_buf(req->rq_reqmsg, reqoff, sizeof(*rec));
216 struct mds_body *body =
217 lustre_msg_buf(req->rq_repmsg, repoff, sizeof(*body));
219 LASSERT (rec != NULL);
220 LASSERT (body != NULL);
222 memcpy(&rec->cr_replayfid, &body->fid1, sizeof rec->cr_replayfid);
223 DEBUG_REQ(D_HA, req, "storing generation %u for ino "LPU64,
224 rec->cr_replayfid.generation, rec->cr_replayfid.id);
227 int mdc_req2lustre_md(struct ptlrpc_request *req, int offset,
228 struct obd_export *exp,
229 struct lustre_md *md)
235 memset(md, 0, sizeof(*md));
237 md->body = lustre_msg_buf(req->rq_repmsg, offset, sizeof (*md->body));
238 LASSERT (md->body != NULL);
239 LASSERT_REPSWABBED (req, offset);
241 if (md->body->valid & OBD_MD_FLEASIZE) {
243 struct lov_mds_md *lmm;
245 LASSERT(S_ISREG(md->body->mode));
247 if (md->body->eadatasize == 0) {
248 CERROR ("OBD_MD_FLEASIZE set, but eadatasize 0\n");
251 lmmsize = md->body->eadatasize;
252 lmm = lustre_msg_buf(req->rq_repmsg, offset + 1, lmmsize);
253 LASSERT (lmm != NULL);
254 LASSERT_REPSWABBED (req, offset + 1);
256 rc = obd_unpackmd(exp, &md->lsm, lmm, lmmsize);
258 LASSERT (rc >= sizeof (*md->lsm));
265 static void mdc_commit_open(struct ptlrpc_request *req)
267 struct mdc_open_data *mod = req->rq_cb_data;
271 if (mod->mod_close_req != NULL)
272 mod->mod_close_req->rq_cb_data = NULL;
274 if (mod->mod_och != NULL)
275 mod->mod_och->och_mod = NULL;
277 OBD_FREE(mod, sizeof(*mod));
278 req->rq_cb_data = NULL;
281 static void mdc_replay_open(struct ptlrpc_request *req)
283 struct mdc_open_data *mod = req->rq_cb_data;
284 struct obd_client_handle *och;
285 struct ptlrpc_request *close_req;
286 struct lustre_handle old;
287 struct mds_body *body;
290 body = lustre_swab_repbuf(req, 1, sizeof(*body), lustre_swab_mds_body);
291 LASSERT (body != NULL);
294 DEBUG_REQ(D_ERROR, req,
295 "can't properly replay without open data");
302 struct lustre_handle *file_fh;
303 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
304 file_fh = &och->och_fh;
305 CDEBUG(D_HA, "updating handle from "LPX64" to "LPX64"\n",
306 file_fh->cookie, body->handle.cookie);
307 memcpy(&old, file_fh, sizeof(old));
308 memcpy(file_fh, &body->handle, sizeof(*file_fh));
311 close_req = mod->mod_close_req;
312 if (close_req != NULL) {
313 struct mds_body *close_body;
314 LASSERT(close_req->rq_reqmsg->opc == MDS_CLOSE);
315 close_body = lustre_msg_buf(close_req->rq_reqmsg, 0,
316 sizeof(*close_body));
318 LASSERT(!memcmp(&old, &close_body->handle, sizeof old));
319 DEBUG_REQ(D_HA, close_req, "updating close body with new fh");
320 memcpy(&close_body->handle, &body->handle,
321 sizeof(close_body->handle));
327 void mdc_set_open_replay_data(struct obd_client_handle *och,
328 struct ptlrpc_request *open_req)
330 struct mdc_open_data *mod;
331 struct mds_rec_create *rec =
332 lustre_msg_buf(open_req->rq_reqmsg, 2, sizeof(*rec));
333 struct mds_body *body =
334 lustre_msg_buf(open_req->rq_repmsg, 1, sizeof(*body));
336 LASSERT(rec != NULL);
337 /* outgoing messages always in my byte order */
338 LASSERT(body != NULL);
339 /* incoming message in my byte order (it's been swabbed) */
340 LASSERT_REPSWABBED(open_req, 1);
342 OBD_ALLOC(mod, sizeof(*mod));
344 DEBUG_REQ(D_ERROR, open_req, "can't allocate mdc_open_data");
350 mod->mod_open_req = open_req;
352 memcpy(&rec->cr_replayfid, &body->fid1, sizeof rec->cr_replayfid);
353 open_req->rq_replay_cb = mdc_replay_open;
354 open_req->rq_commit_cb = mdc_commit_open;
355 open_req->rq_cb_data = mod;
356 DEBUG_REQ(D_HA, open_req, "set up replay data");
359 void mdc_clear_open_replay_data(struct obd_client_handle *och)
361 struct mdc_open_data *mod = och->och_mod;
363 /* Don't free the structure now (it happens in mdc_commit_open, after
364 * we're sure we won't need to fix up the close request in the future),
365 * but make sure that replay doesn't poke at the och, which is about to
367 LASSERT(mod != (void *)0x5a5a5a5a);
373 static void mdc_commit_close(struct ptlrpc_request *req)
375 struct mdc_open_data *mod = req->rq_cb_data;
376 struct ptlrpc_request *open_req;
377 struct obd_import *imp = req->rq_import;
379 DEBUG_REQ(D_HA, req, "close req committed");
383 mod->mod_close_req = NULL;
384 req->rq_cb_data = NULL;
385 req->rq_commit_cb = NULL;
387 open_req = mod->mod_open_req;
388 LASSERT(open_req != NULL);
389 LASSERT(open_req != (void *)0x5a5a5a5a);
391 DEBUG_REQ(D_HA, open_req, "open req balanced");
392 LASSERT(open_req->rq_transno != 0);
393 LASSERT(open_req->rq_import == imp);
395 /* We no longer want to preserve this for transno-unconditional
397 spin_lock(&open_req->rq_lock);
398 open_req->rq_replay = 0;
399 spin_unlock(&open_req->rq_lock);
402 static int mdc_close_interpret(struct ptlrpc_request *req, void *data, int rc)
404 union ptlrpc_async_args *aa = data;
405 struct mdc_rpc_lock *rpc_lock = aa->pointer_arg[0];
406 mdc_put_rpc_lock(rpc_lock, NULL);
407 wake_up(&req->rq_reply_waitq);
411 /* We can't use ptlrpc_check_reply, because we don't want to wake up for
412 * anything but a reply or an error. */
413 static int mdc_close_check_reply(struct ptlrpc_request *req)
418 spin_lock_irqsave(&req->rq_lock, flags);
419 if (req->rq_replied || req->rq_err)
421 spin_unlock_irqrestore (&req->rq_lock, flags);
425 static int go_back_to_sleep(void *unused)
430 int mdc_close(struct obd_export *exp, struct obdo *obdo,
431 struct obd_client_handle *och, struct ptlrpc_request **request)
433 struct mds_body *body;
434 struct obd_device *obd = class_exp2obd(exp);
435 int reqsize = sizeof(*body);
436 int rc, repsize[3] = {sizeof(*body),
437 obd->u.cli.cl_max_mds_easize,
438 obd->u.cli.cl_max_mds_cookiesize};
439 struct ptlrpc_request *req;
440 struct mdc_open_data *mod;
441 struct l_wait_info lwi;
442 struct mdc_rpc_lock *rpc_lock = obd->u.cli.cl_rpc_lock;
445 req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_CLOSE, 1, &reqsize,
448 GOTO(out, rc = -ENOMEM);
450 /* Ensure that this close's handle is fixed up during replay. */
451 LASSERT(och != NULL);
453 if (likely(mod != NULL)) {
454 mod->mod_close_req = req;
455 DEBUG_REQ(D_HA, mod->mod_open_req, "matched open req %p",
458 CDEBUG(D_HA, "couldn't find open req; expecting close error\n");
461 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
462 mdc_pack_fid(&body->fid1, obdo->o_id, 0, obdo->o_mode);
463 memcpy(&body->handle, &och->och_fh, sizeof(body->handle));
464 body->size = obdo->o_size;
465 body->blocks = obdo->o_blocks;
466 body->flags = obdo->o_flags;
467 body->valid = obdo->o_valid;
469 req->rq_replen = lustre_msg_size(3, repsize);
470 req->rq_commit_cb = mdc_commit_close;
471 LASSERT(req->rq_cb_data == NULL);
472 req->rq_cb_data = mod;
474 /* We hand a ref to the rpcd here, so we need another one of our own. */
475 ptlrpc_request_addref(req);
477 mdc_get_rpc_lock(rpc_lock, NULL);
478 req->rq_interpret_reply = mdc_close_interpret;
479 req->rq_async_args.pointer_arg[0] = rpc_lock;
480 ptlrpcd_add_req(req);
481 lwi = LWI_TIMEOUT_INTR(MAX(req->rq_timeout * HZ, 1), go_back_to_sleep,
483 rc = l_wait_event(req->rq_reply_waitq, mdc_close_check_reply(req),
486 if (mod == NULL && rc == 0)
487 CERROR("Unexpected: can't find mdc_open_data, but the close "
488 "succeeded. Please tell CFS.\n");
491 rc = req->rq_repmsg->status;
492 if (req->rq_repmsg->type == PTL_RPC_MSG_ERR) {
493 DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR");
505 int mdc_done_writing(struct obd_export *exp, struct obdo *obdo)
507 struct ptlrpc_request *req;
508 struct mds_body *body;
509 int rc, size = sizeof(*body);
512 req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_DONE_WRITING, 1,
517 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
518 mdc_pack_fid(&body->fid1, obdo->o_id, 0, obdo->o_mode);
519 body->size = obdo->o_size;
520 body->blocks = obdo->o_blocks;
521 body->flags = obdo->o_flags;
522 body->valid = obdo->o_valid;
523 // memcpy(&body->handle, &och->och_fh, sizeof(body->handle));
525 req->rq_replen = lustre_msg_size(1, &size);
527 rc = ptlrpc_queue_wait(req);
528 ptlrpc_req_finished(req);
532 int mdc_readpage(struct obd_export *exp, struct ll_fid *mdc_fid, __u64 offset,
533 struct page *page, struct ptlrpc_request **request)
535 struct obd_import *imp = class_exp2cliimp(exp);
536 struct ptlrpc_request *req = NULL;
537 struct ptlrpc_bulk_desc *desc = NULL;
538 struct mds_body *body;
539 int rc, size = sizeof(*body);
542 CDEBUG(D_INODE, "inode: %ld\n", (long)mdc_fid->id);
544 req = ptlrpc_prep_req(imp, MDS_READPAGE, 1, &size, NULL);
546 GOTO(out, rc = -ENOMEM);
547 /* XXX FIXME bug 249 */
548 req->rq_request_portal = MDS_READPAGE_PORTAL;
550 desc = ptlrpc_prep_bulk_imp(req, BULK_PUT_SINK, MDS_BULK_PORTAL);
552 GOTO(out, rc = -ENOMEM);
553 /* NB req now owns desc and will free it when it gets freed */
555 rc = ptlrpc_prep_bulk_page(desc, page, 0, PAGE_CACHE_SIZE);
559 mdc_readdir_pack(req, offset, PAGE_CACHE_SIZE, mdc_fid);
561 req->rq_replen = lustre_msg_size(1, &size);
562 rc = ptlrpc_queue_wait(req);
565 LASSERT(desc->bd_page_count == 1);
566 body = lustre_swab_repbuf(req, 0, sizeof(*body),
567 lustre_swab_mds_body);
569 CERROR("Can't unpack mds_body\n");
570 GOTO(out, rc = -EPROTO);
580 static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
581 void *karg, void *uarg)
583 struct obd_device *obd = exp->exp_obd;
584 struct obd_ioctl_data *data = karg;
585 struct obd_import *imp = obd->u.cli.cl_import;
586 struct llog_ctxt *ctxt;
591 case OBD_IOC_CLIENT_RECOVER:
592 rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1);
596 case IOC_OSC_SET_ACTIVE:
597 RETURN(ptlrpc_set_import_active(imp, data->ioc_offset));
598 case OBD_IOC_PARSE: {
599 ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT);
600 rc = class_config_parse_llog(ctxt, data->ioc_inlbuf1, NULL);
604 case OBD_IOC_LLOG_INFO:
605 case OBD_IOC_LLOG_PRINT: {
606 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
607 rc = llog_ioctl(ctxt, cmd, data);
613 CERROR("osc_ioctl(): unrecognised ioctl %#x\n", cmd);
618 static int mdc_statfs(struct obd_device *obd, struct obd_statfs *osfs,
619 unsigned long max_age)
621 struct ptlrpc_request *req;
622 struct obd_statfs *msfs;
623 int rc, size = sizeof(*msfs);
626 /* We could possibly pass max_age in the request (as an absolute
627 * timestamp or a "seconds.usec ago") so the target can avoid doing
628 * extra calls into the filesystem if that isn't necessary (e.g.
629 * during mount that would help a bit). Having relative timestamps
630 * is not so great if request processing is slow, while absolute
631 * timestamps are not ideal because they need time synchronization. */
632 req = ptlrpc_prep_req(obd->u.cli.cl_import, MDS_STATFS, 0, NULL, NULL);
636 req->rq_replen = lustre_msg_size(1, &size);
638 mdc_get_rpc_lock(obd->u.cli.cl_rpc_lock, NULL);
639 rc = ptlrpc_queue_wait(req);
640 mdc_put_rpc_lock(obd->u.cli.cl_rpc_lock, NULL);
645 msfs = lustre_swab_repbuf(req, 0, sizeof(*msfs),lustre_swab_obd_statfs);
647 CERROR("Can't unpack obd_statfs\n");
648 GOTO(out, rc = -EPROTO);
651 memcpy(osfs, msfs, sizeof (*msfs));
654 ptlrpc_req_finished(req);
659 static int mdc_pin(struct obd_export *exp, obd_id ino, __u32 gen, int type,
660 struct obd_client_handle *handle, int flag)
662 struct ptlrpc_request *req;
663 struct mds_body *body;
664 int rc, size = sizeof(*body);
667 req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_PIN, 1, &size, NULL);
671 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body));
672 mdc_pack_fid(&body->fid1, ino, gen, type);
675 req->rq_replen = lustre_msg_size(1, &size);
677 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
678 rc = ptlrpc_queue_wait(req);
679 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
681 CERROR("pin failed: %d\n", rc);
682 ptlrpc_req_finished(req);
686 body = lustre_swab_repbuf(req, 0, sizeof(*body), lustre_swab_mds_body);
688 ptlrpc_req_finished(req);
692 memcpy(&handle->och_fh, &body->handle, sizeof(body->handle));
693 handle->och_magic = OBD_CLIENT_HANDLE_MAGIC;
695 OBD_ALLOC(handle->och_mod, sizeof(*handle->och_mod));
696 if (handle->och_mod == NULL) {
697 DEBUG_REQ(D_ERROR, req, "can't allocate mdc_open_data");
700 handle->och_mod->mod_open_req = req; /* will be dropped by unpin */
705 static int mdc_unpin(struct obd_export *exp,
706 struct obd_client_handle *handle, int flag)
708 struct ptlrpc_request *req;
709 struct mds_body *body;
710 int rc, size = sizeof(*body);
713 if (handle->och_magic != OBD_CLIENT_HANDLE_MAGIC)
716 req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_CLOSE, 1, &size, NULL);
720 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
721 memcpy(&body->handle, &handle->och_fh, sizeof(body->handle));
724 req->rq_replen = lustre_msg_size(0, NULL);
725 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
726 rc = ptlrpc_queue_wait(req);
727 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
730 CERROR("unpin failed: %d\n", rc);
732 ptlrpc_req_finished(req);
733 ptlrpc_req_finished(handle->och_mod->mod_open_req);
734 OBD_FREE(handle->och_mod, sizeof(*handle->och_mod));
738 int mdc_sync(struct obd_export *exp, struct ll_fid *fid,
739 struct ptlrpc_request **request)
741 struct ptlrpc_request *req;
742 struct mds_body *body;
743 int size = sizeof(*body);
747 req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_SYNC, 1,&size,NULL);
749 RETURN(rc = -ENOMEM);
752 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body));
753 memcpy(&body->fid1, fid, sizeof(*fid));
754 mdc_pack_req_body(req);
757 req->rq_replen = lustre_msg_size(1, &size);
759 rc = ptlrpc_queue_wait(req);
760 if (rc || request == NULL)
761 ptlrpc_req_finished(req);
768 static int mdc_attach(struct obd_device *dev, obd_count len, void *data)
770 struct lprocfs_static_vars lvars;
772 lprocfs_init_vars(mdc, &lvars);
773 return lprocfs_obd_attach(dev, lvars.obd_vars);
776 static int mdc_detach(struct obd_device *dev)
778 return lprocfs_obd_detach(dev);
781 static int mdc_setup(struct obd_device *obd, obd_count len, void *buf)
783 struct client_obd *cli = &obd->u.cli;
787 OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
788 if (!cli->cl_rpc_lock)
790 mdc_init_rpc_lock(cli->cl_rpc_lock);
794 OBD_ALLOC(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
795 if (!cli->cl_setattr_lock)
796 GOTO(out_free_rpc, rc = -ENOMEM);
797 mdc_init_rpc_lock(cli->cl_setattr_lock);
799 rc = client_obd_setup(obd, len, buf);
801 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
803 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
810 int mdc_postsetup(struct obd_device *obd)
813 rc = obd_llog_init(obd, obd, 0, NULL);
815 CERROR("failed to setup llogging subsystems\n");
820 int mdc_init_ea_size(struct obd_device *obd, char *lov_name)
822 struct client_obd *cli = &obd->u.cli;
823 struct obd_device *lov_obd;
824 struct obd_export *exp;
825 struct lustre_handle conn;
826 struct lov_desc desc;
830 lov_obd = class_name2obd(lov_name);
832 CERROR("MDC cannot locate LOV %s!\n", lov_name);
836 rc = obd_connect(&conn, lov_obd, &obd->obd_uuid);
838 CERROR("MDC failed connect to LOV %s (%d)\n", lov_name, rc);
841 exp = class_conn2export(&conn);
843 valsize = sizeof(desc);
844 rc = obd_get_info(exp, strlen("lovdesc") + 1, "lovdesc",
847 cli->cl_max_mds_easize = obd_size_diskmd(exp, NULL);
848 cli->cl_max_mds_cookiesize = desc.ld_tgt_count *
849 sizeof(struct llog_cookie);
851 obd_disconnect(exp, 0);
855 static int mdc_precleanup(struct obd_device *obd, int flags)
859 rc = obd_llog_finish(obd, 0);
861 CERROR("failed to cleanup llogging subsystems\n");
866 static int mdc_cleanup(struct obd_device *obd, int flags)
868 struct client_obd *cli = &obd->u.cli;
870 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
871 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
875 return client_obd_cleanup(obd, flags);
879 static int mdc_llog_init(struct obd_device *obd, struct obd_device *tgt,
880 int count, struct llog_logid *logid)
882 struct llog_ctxt *ctxt;
886 rc = llog_setup(obd, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
889 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
890 ctxt->loc_imp = obd->u.cli.cl_import;
896 static int mdc_llog_finish(struct obd_device *obd, int count)
901 rc = llog_cleanup(llog_get_context(obd, LLOG_CONFIG_REPL_CTXT));
905 struct obd_ops mdc_obd_ops = {
906 o_owner: THIS_MODULE,
907 o_attach: mdc_attach,
908 o_detach: mdc_detach,
910 o_postsetup: mdc_postsetup,
911 o_precleanup: mdc_precleanup,
912 o_cleanup: mdc_cleanup,
913 o_connect: client_connect_import,
914 o_disconnect: client_disconnect_export,
915 o_iocontrol: mdc_iocontrol,
916 o_statfs: mdc_statfs,
919 o_llog_init: mdc_llog_init,
920 o_llog_finish: mdc_llog_finish,
923 int __init mdc_init(void)
925 struct lprocfs_static_vars lvars;
926 lprocfs_init_vars(mdc, &lvars);
927 return class_register_type(&mdc_obd_ops, lvars.module_vars,
931 static void /*__exit*/ mdc_exit(void)
933 class_unregister_type(LUSTRE_MDC_NAME);
937 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
938 MODULE_DESCRIPTION("Lustre Metadata Client");
939 MODULE_LICENSE("GPL");
941 EXPORT_SYMBOL(mdc_req2lustre_md);
942 EXPORT_SYMBOL(mdc_change_cbdata);
943 EXPORT_SYMBOL(mdc_getstatus);
944 EXPORT_SYMBOL(mdc_getattr);
945 EXPORT_SYMBOL(mdc_getattr_name);
946 EXPORT_SYMBOL(mdc_create);
947 EXPORT_SYMBOL(mdc_unlink);
948 EXPORT_SYMBOL(mdc_rename);
949 EXPORT_SYMBOL(mdc_link);
950 EXPORT_SYMBOL(mdc_readpage);
951 EXPORT_SYMBOL(mdc_setattr);
952 EXPORT_SYMBOL(mdc_close);
953 EXPORT_SYMBOL(mdc_done_writing);
954 EXPORT_SYMBOL(mdc_sync);
955 EXPORT_SYMBOL(mdc_set_open_replay_data);
956 EXPORT_SYMBOL(mdc_clear_open_replay_data);
957 EXPORT_SYMBOL(mdc_store_inode_generation);
958 EXPORT_SYMBOL(mdc_init_ea_size);
960 module_init(mdc_init);
961 module_exit(mdc_exit);