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 static int mdc_cleanup(struct obd_device *obd, int flags);
46 extern int mds_queue_req(struct ptlrpc_request *);
47 /* Helper that implements most of mdc_getstatus and signal_completed_replay. */
48 /* XXX this should become mdc_get_info("key"), sending MDS_GET_INFO RPC */
49 static int send_getstatus(struct obd_import *imp, struct ll_fid *rootfid,
50 int level, int msg_flags)
52 struct ptlrpc_request *req;
53 struct mds_body *body;
54 int rc, size = sizeof(*body);
57 req = ptlrpc_prep_req(imp, MDS_GETSTATUS, 1, &size, NULL);
59 GOTO(out, rc = -ENOMEM);
61 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body));
62 req->rq_send_state = level;
63 req->rq_replen = lustre_msg_size(1, &size);
65 mdc_pack_req_body(req);
66 req->rq_reqmsg->flags |= msg_flags;
67 rc = ptlrpc_queue_wait(req);
70 body = lustre_swab_repbuf (req, 0, sizeof (*body),
71 lustre_swab_mds_body);
73 CERROR ("Can't extract mds_body\n");
74 GOTO (out, rc = -EPROTO);
77 memcpy(rootfid, &body->fid1, sizeof(*rootfid));
79 CDEBUG(D_NET, "root ino="LPU64", last_committed="LPU64
80 ", last_xid="LPU64"\n",
81 rootfid->id, req->rq_repmsg->last_committed,
82 req->rq_repmsg->last_xid);
87 ptlrpc_req_finished(req);
91 /* This should be mdc_get_info("rootfid") */
92 int mdc_getstatus(struct obd_export *exp, struct ll_fid *rootfid)
94 return send_getstatus(class_exp2cliimp(exp), rootfid, LUSTRE_IMP_FULL,
98 int mdc_getattr_common(struct obd_export *exp, unsigned int ea_size,
99 struct ptlrpc_request *req)
101 struct mds_body *body;
104 int size[2] = {sizeof(*body), 0};
108 /* request message already built */
111 size[bufcount++] = ea_size;
112 CDEBUG(D_INODE, "reserved %u bytes for MD/symlink in packet\n",
115 req->rq_replen = lustre_msg_size(bufcount, size);
117 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
118 rc = ptlrpc_queue_wait(req);
119 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
123 body = lustre_swab_repbuf (req, 0, sizeof (*body),
124 lustre_swab_mds_body);
126 CERROR ("Can't unpack mds_body\n");
130 CDEBUG(D_NET, "mode: %o\n", body->mode);
132 LASSERT_REPSWAB (req, 1);
133 if (body->eadatasize != 0) {
134 /* reply indicates presence of eadata; check it's there... */
135 eadata = lustre_msg_buf (req->rq_repmsg, 1, body->eadatasize);
136 if (eadata == NULL) {
137 CERROR ("Missing/short eadata\n");
145 int mdc_getattr(struct obd_export *exp, struct ll_fid *fid,
146 unsigned long valid, unsigned int ea_size,
147 struct ptlrpc_request **request)
149 struct ptlrpc_request *req;
150 struct mds_body *body;
151 int size = sizeof(*body);
155 /* XXX do we need to make another request here? We just did a getattr
156 * to do the lookup in the first place.
158 req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_GETATTR, 1, &size,
161 GOTO(out, rc = -ENOMEM);
163 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body));
164 memcpy(&body->fid1, fid, sizeof(*fid));
166 body->eadatasize = ea_size;
167 mdc_pack_req_body(req);
169 rc = mdc_getattr_common(exp, ea_size, req);
171 ptlrpc_req_finished (req);
179 int mdc_getattr_name(struct obd_export *exp, struct ll_fid *fid,
180 char *filename, int namelen, unsigned long valid,
181 unsigned int ea_size, struct ptlrpc_request **request)
183 struct ptlrpc_request *req;
184 struct mds_body *body;
185 int rc, size[2] = {sizeof(*body), namelen};
188 req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_GETATTR_NAME, 2,
191 GOTO(out, rc = -ENOMEM);
193 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body));
194 memcpy(&body->fid1, fid, sizeof(*fid));
196 body->eadatasize = ea_size;
197 mdc_pack_req_body(req);
199 LASSERT (strnlen (filename, namelen) == namelen - 1);
200 memcpy(lustre_msg_buf(req->rq_reqmsg, 1, namelen), filename, namelen);
202 rc = mdc_getattr_common(exp, ea_size, req);
204 ptlrpc_req_finished (req);
212 /* This should be called with both the request and the reply still packed. */
213 void mdc_store_inode_generation(struct ptlrpc_request *req, int reqoff,
216 struct mds_rec_create *rec =
217 lustre_msg_buf(req->rq_reqmsg, reqoff, sizeof(*rec));
218 struct mds_body *body =
219 lustre_msg_buf(req->rq_repmsg, repoff, sizeof(*body));
221 LASSERT (rec != NULL);
222 LASSERT (body != NULL);
224 memcpy(&rec->cr_replayfid, &body->fid1, sizeof rec->cr_replayfid);
225 DEBUG_REQ(D_HA, req, "storing generation %u for ino "LPU64,
226 rec->cr_replayfid.generation, rec->cr_replayfid.id);
229 int mdc_req2lustre_md(struct ptlrpc_request *req, int offset,
230 struct obd_export *exp,
231 struct lustre_md *md)
237 memset(md, 0, sizeof(*md));
239 md->body = lustre_msg_buf(req->rq_repmsg, offset, sizeof (*md->body));
240 LASSERT (md->body != NULL);
241 LASSERT_REPSWABBED (req, offset);
243 if (md->body->valid & OBD_MD_FLEASIZE) {
245 struct lov_mds_md *lmm;
247 LASSERT(S_ISREG(md->body->mode));
249 if (md->body->eadatasize == 0) {
250 CERROR ("OBD_MD_FLEASIZE set, but eadatasize 0\n");
253 lmmsize = md->body->eadatasize;
254 lmm = lustre_msg_buf(req->rq_repmsg, offset + 1, lmmsize);
255 LASSERT (lmm != NULL);
256 LASSERT_REPSWABBED (req, offset + 1);
258 rc = obd_unpackmd(exp, &md->lsm, lmm, lmmsize);
260 LASSERT (rc >= sizeof (*md->lsm));
267 static void mdc_commit_open(struct ptlrpc_request *req)
269 struct mdc_open_data *mod = req->rq_cb_data;
273 if (mod->mod_close_req != NULL)
274 mod->mod_close_req->rq_cb_data = NULL;
276 if (mod->mod_och != NULL)
277 mod->mod_och->och_mod = NULL;
279 OBD_FREE(mod, sizeof(*mod));
280 req->rq_cb_data = NULL;
283 static void mdc_replay_open(struct ptlrpc_request *req)
285 struct mdc_open_data *mod = req->rq_cb_data;
286 struct obd_client_handle *och;
287 struct ptlrpc_request *close_req;
288 struct lustre_handle old;
289 struct mds_body *body;
292 body = lustre_swab_repbuf(req, 1, sizeof(*body), lustre_swab_mds_body);
293 LASSERT (body != NULL);
296 DEBUG_REQ(D_ERROR, req,
297 "can't properly replay without open data");
304 struct lustre_handle *file_fh;
305 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
306 file_fh = &och->och_fh;
307 CDEBUG(D_HA, "updating handle from "LPX64" to "LPX64"\n",
308 file_fh->cookie, body->handle.cookie);
309 memcpy(&old, file_fh, sizeof(old));
310 memcpy(file_fh, &body->handle, sizeof(*file_fh));
313 close_req = mod->mod_close_req;
314 if (close_req != NULL) {
315 struct mds_body *close_body;
316 LASSERT(close_req->rq_reqmsg->opc == MDS_CLOSE);
317 close_body = lustre_msg_buf(close_req->rq_reqmsg, 0,
318 sizeof(*close_body));
320 LASSERT(!memcmp(&old, &close_body->handle, sizeof old));
321 DEBUG_REQ(D_HA, close_req, "updating close body with new fh");
322 memcpy(&close_body->handle, &body->handle,
323 sizeof(close_body->handle));
329 void mdc_set_open_replay_data(struct obd_client_handle *och,
330 struct ptlrpc_request *open_req)
332 struct mdc_open_data *mod;
333 struct mds_rec_create *rec =
334 lustre_msg_buf(open_req->rq_reqmsg, 2, sizeof(*rec));
335 struct mds_body *body =
336 lustre_msg_buf(open_req->rq_repmsg, 1, sizeof(*body));
338 LASSERT(rec != NULL);
339 /* outgoing messages always in my byte order */
340 LASSERT(body != NULL);
341 /* incoming message in my byte order (it's been swabbed) */
342 LASSERT_REPSWABBED(open_req, 1);
344 OBD_ALLOC(mod, sizeof(*mod));
346 DEBUG_REQ(D_ERROR, open_req, "can't allocate mdc_open_data");
352 mod->mod_open_req = open_req;
354 memcpy(&rec->cr_replayfid, &body->fid1, sizeof rec->cr_replayfid);
355 open_req->rq_replay_cb = mdc_replay_open;
356 open_req->rq_commit_cb = mdc_commit_open;
357 open_req->rq_cb_data = mod;
358 DEBUG_REQ(D_HA, open_req, "set up replay data");
361 void mdc_clear_open_replay_data(struct obd_client_handle *och)
363 struct mdc_open_data *mod = och->och_mod;
365 /* Don't free the structure now (it happens in mdc_commit_open, after
366 * we're sure we won't need to fix up the close request in the future),
367 * but make sure that replay doesn't poke at the och, which is about to
369 LASSERT(mod != LP_POISON);
375 static void mdc_commit_close(struct ptlrpc_request *req)
377 struct mdc_open_data *mod = req->rq_cb_data;
378 struct ptlrpc_request *open_req;
379 struct obd_import *imp = req->rq_import;
381 DEBUG_REQ(D_HA, req, "close req committed");
385 mod->mod_close_req = NULL;
386 req->rq_cb_data = NULL;
387 req->rq_commit_cb = NULL;
389 open_req = mod->mod_open_req;
390 LASSERT(open_req != NULL);
391 LASSERT(open_req != LP_POISON);
392 LASSERT(open_req->rq_type != LI_POISON);
394 DEBUG_REQ(D_HA, open_req, "open req balanced");
395 LASSERT(open_req->rq_transno != 0);
396 LASSERT(open_req->rq_import == imp);
398 /* We no longer want to preserve this for transno-unconditional
400 spin_lock(&open_req->rq_lock);
401 open_req->rq_replay = 0;
402 spin_unlock(&open_req->rq_lock);
405 static int mdc_close_interpret(struct ptlrpc_request *req, void *data, int rc)
407 union ptlrpc_async_args *aa = data;
408 struct mdc_rpc_lock *rpc_lock = aa->pointer_arg[0];
409 struct obd_device *obd = aa->pointer_arg[1];
411 if (rpc_lock == NULL) {
412 CERROR("called with NULL rpc_lock\n");
414 mdc_put_rpc_lock(rpc_lock, NULL);
415 LASSERTF(req->rq_async_args.pointer_arg[0] ==
416 obd->u.cli.cl_rpc_lock, "%p != %p\n",
417 req->rq_async_args.pointer_arg[0],
418 obd->u.cli.cl_rpc_lock);
419 aa->pointer_arg[0] = NULL;
421 wake_up(&req->rq_reply_waitq);
425 /* We can't use ptlrpc_check_reply, because we don't want to wake up for
426 * anything but a reply or an error. */
427 static int mdc_close_check_reply(struct ptlrpc_request *req)
432 spin_lock_irqsave(&req->rq_lock, flags);
433 if (PTLRPC_REQUEST_COMPLETE(req)) {
436 spin_unlock_irqrestore (&req->rq_lock, flags);
440 static int go_back_to_sleep(void *unused)
445 int mdc_close(struct obd_export *exp, struct obdo *obdo,
446 struct obd_client_handle *och, struct ptlrpc_request **request)
448 struct mds_body *body;
449 struct obd_device *obd = class_exp2obd(exp);
450 int reqsize = sizeof(*body);
451 int rc, repsize[3] = {sizeof(*body),
452 obd->u.cli.cl_max_mds_easize,
453 obd->u.cli.cl_max_mds_cookiesize};
454 struct ptlrpc_request *req;
455 struct mdc_open_data *mod;
456 struct l_wait_info lwi;
459 req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_CLOSE, 1, &reqsize,
462 GOTO(out, rc = -ENOMEM);
464 /* Ensure that this close's handle is fixed up during replay. */
465 LASSERT(och != NULL);
467 if (likely(mod != NULL)) {
468 mod->mod_close_req = req;
469 LASSERT(mod->mod_open_req->rq_type != LI_POISON);
470 DEBUG_REQ(D_HA, mod->mod_open_req, "matched open req %p",
473 CDEBUG(D_HA, "couldn't find open req; expecting close error\n");
476 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
477 mdc_pack_fid(&body->fid1, obdo->o_id, 0, obdo->o_mode);
478 memcpy(&body->handle, &och->och_fh, sizeof(body->handle));
479 body->size = obdo->o_size;
480 body->blocks = obdo->o_blocks;
481 body->flags = obdo->o_flags;
482 body->valid = obdo->o_valid;
484 req->rq_replen = lustre_msg_size(3, repsize);
485 req->rq_commit_cb = mdc_commit_close;
486 LASSERT(req->rq_cb_data == NULL);
487 req->rq_cb_data = mod;
489 /* We hand a ref to the rpcd here, so we need another one of our own. */
490 ptlrpc_request_addref(req);
492 mdc_get_rpc_lock(obd->u.cli.cl_rpc_lock, NULL);
493 req->rq_interpret_reply = mdc_close_interpret;
494 req->rq_async_args.pointer_arg[0] = obd->u.cli.cl_rpc_lock;
495 req->rq_async_args.pointer_arg[1] = obd;
496 ptlrpcd_add_req(req);
497 lwi = LWI_TIMEOUT_INTR(MAX(req->rq_timeout * HZ, 1), go_back_to_sleep,
499 rc = l_wait_event(req->rq_reply_waitq, mdc_close_check_reply(req),
501 if (req->rq_repmsg == NULL) {
502 CDEBUG(D_HA, "request failed to send: %p, %d\n", req,
504 rc = req->rq_status ? req->rq_status : -EIO;
505 } else if (rc == 0) {
506 rc = req->rq_repmsg->status;
507 if (req->rq_repmsg->type == PTL_RPC_MSG_ERR) {
508 DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, err "
512 } else if (mod == NULL) {
513 CERROR("Unexpected: can't find mdc_open_data, but the "
514 "close succeeded. Please tell CFS.\n");
516 if (!lustre_swab_repbuf(req, 0, sizeof(struct mds_body),
517 lustre_swab_mds_body)) {
518 CERROR("Error unpacking mds_body\n");
522 if (req->rq_async_args.pointer_arg[0] != NULL) {
523 CERROR("returned without dropping rpc_lock: rc %d\n", rc);
524 mdc_close_interpret(req, &req->rq_async_args, rc);
525 portals_debug_dumplog();
534 int mdc_done_writing(struct obd_export *exp, struct obdo *obdo)
536 struct ptlrpc_request *req;
537 struct mds_body *body;
538 int rc, size = sizeof(*body);
541 req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_DONE_WRITING, 1,
546 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
547 mdc_pack_fid(&body->fid1, obdo->o_id, 0, obdo->o_mode);
548 body->size = obdo->o_size;
549 body->blocks = obdo->o_blocks;
550 body->flags = obdo->o_flags;
551 body->valid = obdo->o_valid;
552 // memcpy(&body->handle, &och->och_fh, sizeof(body->handle));
554 req->rq_replen = lustre_msg_size(1, &size);
556 rc = ptlrpc_queue_wait(req);
557 ptlrpc_req_finished(req);
561 int mdc_readpage(struct obd_export *exp, struct ll_fid *mdc_fid, __u64 offset,
562 struct page *page, struct ptlrpc_request **request)
564 struct obd_import *imp = class_exp2cliimp(exp);
565 struct ptlrpc_request *req = NULL;
566 struct ptlrpc_bulk_desc *desc = NULL;
567 struct mds_body *body;
568 int rc, size = sizeof(*body);
571 CDEBUG(D_INODE, "inode: %ld\n", (long)mdc_fid->id);
573 req = ptlrpc_prep_req(imp, MDS_READPAGE, 1, &size, NULL);
575 GOTO(out, rc = -ENOMEM);
576 /* XXX FIXME bug 249 */
577 req->rq_request_portal = MDS_READPAGE_PORTAL;
579 desc = ptlrpc_prep_bulk_imp(req, 1, BULK_PUT_SINK, MDS_BULK_PORTAL);
581 GOTO(out, rc = -ENOMEM);
582 /* NB req now owns desc and will free it when it gets freed */
584 ptlrpc_prep_bulk_page(desc, page, 0, PAGE_CACHE_SIZE);
586 mdc_readdir_pack(req, offset, PAGE_CACHE_SIZE, mdc_fid);
588 req->rq_replen = lustre_msg_size(1, &size);
589 rc = ptlrpc_queue_wait(req);
592 body = lustre_swab_repbuf(req, 0, sizeof (*body),
593 lustre_swab_mds_body);
595 CERROR("Can't unpack mds_body\n");
596 GOTO(out, rc = -EPROTO);
599 if (req->rq_bulk->bd_nob_transferred != PAGE_CACHE_SIZE) {
600 CERROR ("Unexpected # bytes transferred: %d"
602 req->rq_bulk->bd_nob_transferred,
604 GOTO (out, rc = -EPROTO);
614 static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
615 void *karg, void *uarg)
617 struct obd_device *obd = exp->exp_obd;
618 struct obd_ioctl_data *data = karg;
619 struct obd_import *imp = obd->u.cli.cl_import;
620 struct llog_ctxt *ctxt;
624 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
627 if (!try_module_get(THIS_MODULE)) {
628 CERROR("Can't get module. Is it alive?");
633 case OBD_IOC_CLIENT_RECOVER:
634 rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1);
638 case IOC_OSC_SET_ACTIVE:
639 rc = ptlrpc_set_import_active(imp, data->ioc_offset);
641 case OBD_IOC_PARSE: {
642 ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT);
643 rc = class_config_parse_llog(ctxt, data->ioc_inlbuf1, NULL);
647 case OBD_IOC_LLOG_INFO:
648 case OBD_IOC_LLOG_PRINT: {
649 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
650 rc = llog_ioctl(ctxt, cmd, data);
656 CERROR("mdc_ioctl(): unrecognised ioctl %#x\n", cmd);
657 GOTO(out, rc = -ENOTTY);
660 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
663 module_put(THIS_MODULE);
669 int mdc_set_info(struct obd_export *exp, obd_count keylen,
670 void *key, obd_count vallen, void *val)
674 if (keylen == strlen("initial_recov") &&
675 memcmp(key, "initial_recov", strlen("initial_recov")) == 0) {
676 struct obd_import *imp = exp->exp_obd->u.cli.cl_import;
677 if (vallen != sizeof(int))
679 imp->imp_initial_recov = *(int *)val;
680 CDEBUG(D_HA, "%s: set imp_no_init_recov = %d\n",
681 exp->exp_obd->obd_name,
682 imp->imp_initial_recov);
689 static int mdc_statfs(struct obd_device *obd, struct obd_statfs *osfs,
690 unsigned long max_age)
692 struct ptlrpc_request *req;
693 struct obd_statfs *msfs;
694 int rc, size = sizeof(*msfs);
697 /* We could possibly pass max_age in the request (as an absolute
698 * timestamp or a "seconds.usec ago") so the target can avoid doing
699 * extra calls into the filesystem if that isn't necessary (e.g.
700 * during mount that would help a bit). Having relative timestamps
701 * is not so great if request processing is slow, while absolute
702 * timestamps are not ideal because they need time synchronization. */
703 req = ptlrpc_prep_req(obd->u.cli.cl_import, MDS_STATFS, 0, NULL, NULL);
707 req->rq_replen = lustre_msg_size(1, &size);
709 mdc_get_rpc_lock(obd->u.cli.cl_rpc_lock, NULL);
710 rc = ptlrpc_queue_wait(req);
711 mdc_put_rpc_lock(obd->u.cli.cl_rpc_lock, NULL);
716 msfs = lustre_swab_repbuf(req, 0, sizeof(*msfs),lustre_swab_obd_statfs);
718 CERROR("Can't unpack obd_statfs\n");
719 GOTO(out, rc = -EPROTO);
722 memcpy(osfs, msfs, sizeof (*msfs));
725 ptlrpc_req_finished(req);
730 static int mdc_pin(struct obd_export *exp, obd_id ino, __u32 gen, int type,
731 struct obd_client_handle *handle, int flag)
733 struct ptlrpc_request *req;
734 struct mds_body *body;
735 int rc, size = sizeof(*body);
738 req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_PIN, 1, &size, NULL);
742 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body));
743 mdc_pack_fid(&body->fid1, ino, gen, type);
746 req->rq_replen = lustre_msg_size(1, &size);
748 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
749 rc = ptlrpc_queue_wait(req);
750 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
752 CERROR("pin failed: %d\n", rc);
753 ptlrpc_req_finished(req);
757 body = lustre_swab_repbuf(req, 0, sizeof(*body), lustre_swab_mds_body);
759 ptlrpc_req_finished(req);
763 memcpy(&handle->och_fh, &body->handle, sizeof(body->handle));
764 handle->och_magic = OBD_CLIENT_HANDLE_MAGIC;
766 OBD_ALLOC(handle->och_mod, sizeof(*handle->och_mod));
767 if (handle->och_mod == NULL) {
768 DEBUG_REQ(D_ERROR, req, "can't allocate mdc_open_data");
771 handle->och_mod->mod_open_req = req; /* will be dropped by unpin */
776 static int mdc_unpin(struct obd_export *exp,
777 struct obd_client_handle *handle, int flag)
779 struct ptlrpc_request *req;
780 struct mds_body *body;
781 int rc, size = sizeof(*body);
784 if (handle->och_magic != OBD_CLIENT_HANDLE_MAGIC)
787 req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_CLOSE, 1, &size, NULL);
791 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
792 memcpy(&body->handle, &handle->och_fh, sizeof(body->handle));
795 req->rq_replen = lustre_msg_size(0, NULL);
796 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
797 rc = ptlrpc_queue_wait(req);
798 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
801 CERROR("unpin failed: %d\n", rc);
803 ptlrpc_req_finished(req);
804 ptlrpc_req_finished(handle->och_mod->mod_open_req);
805 OBD_FREE(handle->och_mod, sizeof(*handle->och_mod));
809 int mdc_sync(struct obd_export *exp, struct ll_fid *fid,
810 struct ptlrpc_request **request)
812 struct ptlrpc_request *req;
813 struct mds_body *body;
814 int size = sizeof(*body);
818 req = ptlrpc_prep_req(class_exp2cliimp(exp), MDS_SYNC, 1,&size,NULL);
820 RETURN(rc = -ENOMEM);
823 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body));
824 memcpy(&body->fid1, fid, sizeof(*fid));
825 mdc_pack_req_body(req);
828 req->rq_replen = lustre_msg_size(1, &size);
830 rc = ptlrpc_queue_wait(req);
831 if (rc || request == NULL)
832 ptlrpc_req_finished(req);
839 static int mdc_import_event(struct obd_device *obd,
840 struct obd_import *imp,
841 enum obd_import_event event)
845 LASSERT(imp->imp_obd == obd);
848 case IMP_EVENT_DISCON: {
851 case IMP_EVENT_INACTIVE: {
852 if (obd->obd_observer)
853 rc = obd_notify(obd->obd_observer, obd, 0);
856 case IMP_EVENT_INVALIDATE: {
857 struct ldlm_namespace *ns = obd->obd_namespace;
859 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
863 case IMP_EVENT_ACTIVE: {
864 if (obd->obd_observer)
865 rc = obd_notify(obd->obd_observer, obd, 1);
869 CERROR("Unknown import event %d\n", event);
875 static int mdc_setup(struct obd_device *obd, obd_count len, void *buf)
877 struct client_obd *cli = &obd->u.cli;
878 struct lprocfs_static_vars lvars;
882 OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
883 if (!cli->cl_rpc_lock)
885 mdc_init_rpc_lock(cli->cl_rpc_lock);
889 OBD_ALLOC(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
890 if (!cli->cl_setattr_lock)
891 GOTO(err_rpc_lock, rc = -ENOMEM);
892 mdc_init_rpc_lock(cli->cl_setattr_lock);
894 rc = client_obd_setup(obd, len, buf);
896 GOTO(err_setattr_lock, rc);
897 lprocfs_init_vars(mdc, &lvars);
898 lprocfs_obd_setup(obd, lvars.obd_vars);
900 rc = obd_llog_init(obd, obd, 0, NULL);
903 CERROR("failed to setup llogging subsystems\n");
909 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
911 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
916 int mdc_init_ea_size(struct obd_device *obd, char *lov_name)
918 struct client_obd *cli = &obd->u.cli;
919 struct obd_device *lov_obd;
920 struct obd_export *exp;
921 struct lustre_handle conn;
922 struct lov_desc desc;
926 lov_obd = class_name2obd(lov_name);
928 CERROR("MDC cannot locate LOV %s!\n", lov_name);
932 rc = obd_connect(&conn, lov_obd, &obd->obd_uuid);
934 CERROR("MDC failed connect to LOV %s (%d)\n", lov_name, rc);
937 exp = class_conn2export(&conn);
939 valsize = sizeof(desc);
940 rc = obd_get_info(exp, strlen("lovdesc") + 1, "lovdesc",
943 cli->cl_max_mds_easize = obd_size_diskmd(exp, NULL);
944 cli->cl_max_mds_cookiesize = desc.ld_tgt_count *
945 sizeof(struct llog_cookie);
947 obd_disconnect(exp, 0);
951 static int mdc_precleanup(struct obd_device *obd, int flags)
955 rc = obd_llog_finish(obd, 0);
957 CERROR("failed to cleanup llogging subsystems\n");
962 static int mdc_cleanup(struct obd_device *obd, int flags)
964 struct client_obd *cli = &obd->u.cli;
966 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
967 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
969 lprocfs_obd_cleanup(obd);
972 return client_obd_cleanup(obd, flags);
976 static int mdc_llog_init(struct obd_device *obd, struct obd_device *tgt,
977 int count, struct llog_catid *logid)
979 struct llog_ctxt *ctxt;
983 rc = llog_setup(obd, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
986 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
987 ctxt->loc_imp = obd->u.cli.cl_import;
993 static int mdc_llog_finish(struct obd_device *obd, int count)
998 rc = llog_cleanup(llog_get_context(obd, LLOG_CONFIG_REPL_CTXT));
1002 struct obd_ops mdc_obd_ops = {
1003 .o_owner = THIS_MODULE,
1004 .o_setup = mdc_setup,
1005 .o_precleanup = mdc_precleanup,
1006 .o_cleanup = mdc_cleanup,
1007 .o_connect = client_connect_import,
1008 .o_disconnect = client_disconnect_export,
1009 .o_iocontrol = mdc_iocontrol,
1010 .o_set_info = mdc_set_info,
1011 .o_statfs = mdc_statfs,
1013 .o_unpin = mdc_unpin,
1014 .o_import_event = mdc_import_event,
1015 .o_llog_init = mdc_llog_init,
1016 .o_llog_finish = mdc_llog_finish,
1019 int __init mdc_init(void)
1021 struct lprocfs_static_vars lvars;
1022 lprocfs_init_vars(mdc, &lvars);
1023 return class_register_type(&mdc_obd_ops, lvars.module_vars,
1028 static void /*__exit*/ mdc_exit(void)
1030 class_unregister_type(LUSTRE_MDC_NAME);
1033 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1034 MODULE_DESCRIPTION("Lustre Metadata Client");
1035 MODULE_LICENSE("GPL");
1037 EXPORT_SYMBOL(mdc_req2lustre_md);
1038 EXPORT_SYMBOL(mdc_change_cbdata);
1039 EXPORT_SYMBOL(mdc_getstatus);
1040 EXPORT_SYMBOL(mdc_getattr);
1041 EXPORT_SYMBOL(mdc_getattr_name);
1042 EXPORT_SYMBOL(mdc_create);
1043 EXPORT_SYMBOL(mdc_unlink);
1044 EXPORT_SYMBOL(mdc_rename);
1045 EXPORT_SYMBOL(mdc_link);
1046 EXPORT_SYMBOL(mdc_readpage);
1047 EXPORT_SYMBOL(mdc_setattr);
1048 EXPORT_SYMBOL(mdc_close);
1049 EXPORT_SYMBOL(mdc_done_writing);
1050 EXPORT_SYMBOL(mdc_sync);
1051 EXPORT_SYMBOL(mdc_set_open_replay_data);
1052 EXPORT_SYMBOL(mdc_clear_open_replay_data);
1053 EXPORT_SYMBOL(mdc_store_inode_generation);
1054 EXPORT_SYMBOL(mdc_init_ea_size);
1056 module_init(mdc_init);
1057 module_exit(mdc_exit);