1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 # define EXPORT_SYMTAB
40 #define DEBUG_SUBSYSTEM S_MDC
43 # include <linux/module.h>
44 # include <linux/pagemap.h>
45 # include <linux/miscdevice.h>
46 # include <linux/init.h>
48 # include <liblustre.h>
51 #include <obd_class.h>
52 #include <lustre_dlm.h>
53 #include <lprocfs_status.h>
54 #include <lustre_param.h>
55 #include "mdc_internal.h"
57 static quota_interface_t *quota_interface;
59 #define REQUEST_MINOR 244
61 static quota_interface_t *quota_interface;
62 extern quota_interface_t mdc_quota_interface;
64 static int mdc_cleanup(struct obd_device *obd);
66 extern int mds_queue_req(struct ptlrpc_request *);
67 /* Helper that implements most of mdc_getstatus and signal_completed_replay. */
68 /* XXX this should become mdc_get_info("key"), sending MDS_GET_INFO RPC */
69 static int send_getstatus(struct obd_export *exp, struct ll_fid *rootfid,
70 int level, int msg_flags)
72 struct ptlrpc_request *req;
73 struct mds_body *body;
74 __u32 size[3] = { sizeof(struct ptlrpc_body),
75 sizeof(struct mdt_body),
76 sizeof(struct lustre_capa) };
80 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION, MDS_GETSTATUS, 2, size,
83 GOTO(out, rc = -ENOMEM);
85 req->rq_export = class_export_get(exp);
86 req->rq_send_state = level;
87 ptlrpc_req_set_repsize(req, 3, size);
89 mdc_pack_req_body(req, REQ_REC_OFF, 0, NULL, 0, 0);
90 lustre_msg_add_flags(req->rq_reqmsg, msg_flags);
91 rc = ptlrpc_queue_wait(req);
94 body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body),
95 lustre_swab_mds_body);
97 CERROR ("Can't extract mds_body\n");
98 GOTO (out, rc = -EPROTO);
101 memcpy(rootfid, &body->fid1, sizeof(*rootfid));
103 CDEBUG(D_NET, "root ino="LPU64", last_committed="LPU64
104 ", last_xid="LPU64"\n",
106 lustre_msg_get_last_committed(req->rq_repmsg),
107 lustre_msg_get_last_xid(req->rq_repmsg));
112 ptlrpc_req_finished(req);
116 /* This should be mdc_get_info("ROOT") */
117 int mdc_getstatus(struct obd_export *exp, struct ll_fid *rootfid)
119 return send_getstatus(exp, rootfid, LUSTRE_IMP_FULL, 0);
123 int mdc_getattr_common(struct obd_export *exp, unsigned int ea_size,
124 unsigned int acl_size, struct ptlrpc_request *req)
126 struct obd_device *obddev = class_exp2obd(exp);
127 struct mds_body *body;
129 __u32 size[6] = { sizeof(struct ptlrpc_body),
130 sizeof(struct mdt_body) };
131 int bufcount = 2, rc;
134 /* request message already built */
136 size[bufcount++] = ea_size;
137 CDEBUG(D_INODE, "reserved %u bytes for MD/symlink in packet\n",
141 size[bufcount++] = acl_size;
142 CDEBUG(D_INODE, "reserved %u bytes for ACL\n", acl_size);
145 if (mdc_exp_is_2_0_server(exp)) {
149 ptlrpc_req_set_repsize(req, bufcount, size);
151 mdc_enter_request(&obddev->u.cli);
152 rc = ptlrpc_queue_wait(req);
153 mdc_exit_request(&obddev->u.cli);
157 body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body),
158 lustre_swab_mds_body);
160 CERROR ("Can't unpack mds_body\n");
164 CDEBUG(D_NET, "mode: %o\n", body->mode);
166 lustre_set_rep_swabbed(req, REPLY_REC_OFF + 1);
167 if (body->eadatasize != 0) {
168 /* reply indicates presence of eadata; check it's there... */
169 eadata = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1,
171 if (eadata == NULL) {
172 CERROR ("Missing/short eadata\n");
180 int mdc_getattr(struct obd_export *exp, struct ll_fid *fid,
181 obd_valid valid, unsigned int ea_size,
182 struct ptlrpc_request **request)
184 struct ptlrpc_request *req;
185 __u32 size[2] = { sizeof(struct ptlrpc_body),
186 sizeof(struct mdt_body) };
187 int acl_size = 0, rc;
190 /* XXX do we need to make another request here? We just did a getattr
191 * to do the lookup in the first place.
193 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
194 MDS_GETATTR, 2, size, NULL);
196 GOTO(out, rc = -ENOMEM);
198 req->rq_export = class_export_get(exp);
199 mdc_pack_req_body(req, REQ_REC_OFF, valid, fid, ea_size,
200 MDS_BFLAG_EXT_FLAGS/*request "new" flags(bug 9486)*/);
202 /* currently only root inode will call us with FLACL */
203 if (valid & OBD_MD_FLACL)
204 acl_size = LUSTRE_POSIX_ACL_MAX_SIZE;
206 rc = mdc_getattr_common(exp, ea_size, acl_size, req);
208 ptlrpc_req_finished (req);
216 int mdc_getattr_name(struct obd_export *exp, struct ll_fid *fid,
217 const char *filename, int namelen, unsigned long valid,
218 unsigned int ea_size, struct ptlrpc_request **request)
220 struct ptlrpc_request *req;
221 __u32 size[4] = { [MSG_PTLRPC_BODY_OFF] = sizeof(struct ptlrpc_body),
222 [REQ_REC_OFF] = sizeof(struct mdt_body),
223 [REQ_REC_OFF + 1] = namelen };
226 int nameoffset = REQ_REC_OFF + 1;
229 if (mdc_exp_is_2_0_server(exp)) {
230 size[REQ_REC_OFF + 1] = 0;
231 size[REQ_REC_OFF + 2] = namelen;
236 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
237 MDS_GETATTR_NAME, bufcount, size, NULL);
239 GOTO(out, rc = -ENOMEM);
241 req->rq_export = class_export_get(exp);
242 mdc_pack_req_body(req, REQ_REC_OFF, valid, fid, ea_size,
243 MDS_BFLAG_EXT_FLAGS/*request "new" flags(bug 9486)*/);
245 LASSERT(strnlen(filename, namelen) == namelen - 1);
246 memcpy(lustre_msg_buf(req->rq_reqmsg, nameoffset, namelen),
249 rc = mdc_getattr_common(exp, ea_size, 0, req);
251 ptlrpc_req_finished (req);
260 int mdc_xattr_common(struct obd_export *exp, struct ll_fid *fid,
261 int opcode, obd_valid valid, const char *xattr_name,
262 const char *input, int input_size, int output_size,
263 int flags, struct ptlrpc_request **request)
265 struct obd_device *obddev = class_exp2obd(exp);
266 struct ptlrpc_request *req;
267 __u32 size[5] = { [MSG_PTLRPC_BODY_OFF] = sizeof(struct ptlrpc_body),
268 [REQ_REC_OFF] = sizeof(struct mdt_body),
269 [REQ_REC_OFF + 1] = 0, /* capa */
270 [REQ_REC_OFF + 2] = 0, /* name */
271 [REQ_REC_OFF + 3] = 0 };
272 int rc, xattr_namelen = 0, bufcnt = 2, offset = REQ_REC_OFF + 1;
276 if (mdc_exp_is_2_0_server(exp)) {
279 if (opcode == MDS_SETXATTR) {
280 size[REQ_REC_OFF] = sizeof (struct mdt_rec_setxattr);
286 xattr_namelen = strlen(xattr_name) + 1;
287 size[bufcnt++] = xattr_namelen;
291 size[bufcnt++] = input_size;
294 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
295 opcode, bufcnt, size, NULL);
297 GOTO(out, rc = -ENOMEM);
299 req->rq_export = class_export_get(exp);
301 if (opcode == MDS_REINT && mdc_exp_is_2_0_server(exp)) {
302 struct mdt_rec_setxattr *rec;
303 rec = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF,
304 sizeof(struct mdt_rec_setxattr));
305 rec->sx_opcode = REINT_SETXATTR;
306 rec->sx_fsuid = current->fsuid;
307 rec->sx_fsgid = current->fsgid;
308 rec->sx_cap = cfs_curproc_cap_pack();
309 rec->sx_suppgid1 = -1;
310 rec->sx_suppgid2 = -1;
311 rec->sx_fid = *((struct lu_fid*)fid);
312 rec->sx_valid = valid;
313 rec->sx_size = output_size;
314 rec->sx_flags = flags;
317 mdc_pack_req_body(req, REQ_REC_OFF, valid, fid, output_size, flags);
321 tmp = lustre_msg_buf(req->rq_reqmsg, offset++, xattr_namelen);
322 memcpy(tmp, xattr_name, xattr_namelen);
325 tmp = lustre_msg_buf(req->rq_reqmsg, offset++, input_size);
326 memcpy(tmp, input, input_size);
329 size[REPLY_REC_OFF] = sizeof(struct mdt_body);
330 if (mdc_exp_is_2_0_server(exp)) {
334 if (opcode == MDS_GETXATTR) {
342 /* we do this even output_size is 0, because server is doing that */
343 size[bufcnt++] = output_size;
344 ptlrpc_req_set_repsize(req, bufcnt, size);
347 if (opcode == MDS_SETXATTR || opcode == MDS_REINT)
348 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
350 mdc_enter_request(&obddev->u.cli);
352 rc = ptlrpc_queue_wait(req);
354 if (opcode == MDS_SETXATTR || opcode == MDS_REINT)
355 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
357 mdc_exit_request(&obddev->u.cli);
362 if (opcode == MDS_GETXATTR) {
363 struct mds_body * body = lustre_swab_repbuf(req, REPLY_REC_OFF,
365 lustre_swab_mds_body);
367 CERROR ("Can't unpack mds_body\n");
368 GOTO(err_out, rc = -EPROTO);
375 ptlrpc_req_finished(req);
380 int mdc_setxattr(struct obd_export *exp, struct ll_fid *fid,
381 obd_valid valid, const char *xattr_name,
382 const char *input, int input_size,
383 int output_size, int flags,
384 struct ptlrpc_request **request)
386 return mdc_xattr_common(exp, fid, MDS_SETXATTR, valid, xattr_name,
387 input, input_size, output_size, flags, request);
390 int mdc_getxattr(struct obd_export *exp, struct ll_fid *fid,
391 obd_valid valid, const char *xattr_name,
392 const char *input, int input_size,
393 int output_size, struct ptlrpc_request **request)
395 return mdc_xattr_common(exp, fid, MDS_GETXATTR, valid, xattr_name,
396 input, input_size, output_size, 0, request);
399 /* For the fid-less server */
400 static void mdc_store_inode_generation_18(struct ptlrpc_request *req,
401 int reqoff, int repoff)
403 struct mds_rec_create *rec = lustre_msg_buf(req->rq_reqmsg, reqoff,
405 struct mds_body *body = lustre_msg_buf(req->rq_repmsg, repoff,
408 LASSERT (rec != NULL);
409 LASSERT (body != NULL);
411 memcpy(&rec->cr_replayfid, &body->fid1, sizeof rec->cr_replayfid);
412 if (body->fid1.id == 0) {
413 DEBUG_REQ(D_ERROR, req, "saving replay request with id = 0 "
414 "gen = %u", body->fid1.generation);
418 DEBUG_REQ(D_INODE, req, "storing generation %u for ino "LPU64,
419 rec->cr_replayfid.generation, rec->cr_replayfid.id);
422 static void mdc_store_inode_generation_20(struct ptlrpc_request *req,
423 int reqoff, int repoff)
425 struct mdt_rec_create *rec = lustre_msg_buf(req->rq_reqmsg, reqoff,
427 struct mdt_body *body = lustre_msg_buf(req->rq_repmsg, repoff,
430 LASSERT (rec != NULL);
431 LASSERT (body != NULL);
433 rec->cr_fid2 = body->fid1;
434 rec->cr_ioepoch = body->ioepoch;
435 rec->cr_old_handle.cookie = body->handle.cookie;
437 if (!fid_is_sane(&body->fid1)) {
438 DEBUG_REQ(D_ERROR, req, "saving replay request with"
443 DEBUG_REQ(D_INODE, req, "storing generation %u for ino "LPU64,
444 rec->cr_fid1.f_oid, rec->cr_fid2.f_seq);
447 /* This should be called with both the request and the reply still packed. */
448 void mdc_store_inode_generation(struct ptlrpc_request *req, int reqoff,
451 if (mdc_req_is_2_0_server(req))
452 mdc_store_inode_generation_20(req, reqoff, repoff);
454 mdc_store_inode_generation_18(req, reqoff, repoff);
457 #ifdef CONFIG_FS_POSIX_ACL
459 int mdc_unpack_acl(struct obd_export *exp, struct ptlrpc_request *req,
460 struct lustre_md *md, unsigned int offset)
462 struct mds_body *body = md->body;
463 struct posix_acl *acl;
470 buf = lustre_msg_buf(req->rq_repmsg, offset, body->aclsize);
472 CERROR("aclsize %u, bufcount %u, bufsize %u\n",
473 body->aclsize, lustre_msg_bufcount(req->rq_repmsg),
474 (lustre_msg_bufcount(req->rq_repmsg) <= offset) ?
475 -1 : lustre_msg_buflen(req->rq_repmsg, offset));
479 acl = posix_acl_from_xattr(buf, body->aclsize);
482 CERROR("convert xattr to acl: %d\n", rc);
486 rc = posix_acl_valid(acl);
488 CERROR("validate acl: %d\n", rc);
489 posix_acl_release(acl);
497 #define mdc_unpack_acl(exp, req, md, offset) 0
500 int mdc_req2lustre_md(struct ptlrpc_request *req, int offset,
501 struct obd_export *exp,
502 struct lustre_md *md)
505 int iop = mdc_req_is_2_0_server(req);
509 memset(md, 0, sizeof(*md));
511 md->body = lustre_msg_buf(req->rq_repmsg, offset, sizeof (*md->body));
512 LASSERT (md->body != NULL);
513 LASSERT(lustre_rep_swabbed(req, offset));
516 if (md->body->valid & OBD_MD_FLEASIZE) {
518 struct lov_mds_md *lmm;
520 if (!S_ISREG(md->body->mode)) {
521 CERROR("OBD_MD_FLEASIZE set, should be a regular file, "
523 GOTO(err_out, rc = -EPROTO);
526 if (md->body->eadatasize == 0) {
527 CERROR ("OBD_MD_FLEASIZE set, but eadatasize 0\n");
528 GOTO(err_out, rc = -EPROTO);
530 lmmsize = md->body->eadatasize;
531 lmm = lustre_msg_buf(req->rq_repmsg, offset, lmmsize);
533 CERROR ("incorrect message: lmm == 0\n");
534 GOTO(err_out, rc = -EPROTO);
536 LASSERT(lustre_rep_swabbed(req, offset));
538 rc = obd_unpackmd(exp, &md->lsm, lmm, lmmsize);
542 if (rc < sizeof(*md->lsm)) {
543 CERROR ("lsm size too small: rc < sizeof (*md->lsm) "
544 "(%d < %d)\n", rc, (int)sizeof(*md->lsm));
545 GOTO(err_out, rc = -EPROTO);
551 } else if (md->body->valid & OBD_MD_FLDIREA) {
552 if(!S_ISDIR(md->body->mode)) {
553 CERROR("OBD_MD_FLDIREA set, should be a directory, but "
555 GOTO(err_out, rc = -EPROTO);
563 /* for ACL, it's possible that FLACL is set but aclsize is zero.
564 * only when aclsize != 0 there's an actual segment for ACL in
567 if ((md->body->valid & OBD_MD_FLACL) && md->body->aclsize) {
568 rc = mdc_unpack_acl(exp, req, md, offset);
578 obd_free_memmd(exp, &md->lsm);
582 void mdc_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
585 obd_free_memmd(exp, &md->lsm);
587 #ifdef CONFIG_FS_POSIX_ACL
589 posix_acl_release(md->posix_acl);
590 md->posix_acl = NULL;
595 static void mdc_commit_open(struct ptlrpc_request *req)
597 struct mdc_open_data *mod = req->rq_cb_data;
601 if (mod->mod_close_req != NULL)
602 mod->mod_close_req->rq_cb_data = NULL;
604 if (mod->mod_och != NULL)
605 mod->mod_och->och_mod = NULL;
608 req->rq_cb_data = NULL;
611 static void mdc_replay_open(struct ptlrpc_request *req)
613 struct mdc_open_data *mod = req->rq_cb_data;
614 struct obd_client_handle *och;
615 struct ptlrpc_request *close_req;
616 struct lustre_handle old;
617 struct mds_body *body;
620 body = lustre_swab_repbuf(req, DLM_REPLY_REC_OFF, sizeof(*body),
621 lustre_swab_mds_body);
622 LASSERT (body != NULL);
625 DEBUG_REQ(D_ERROR, req,
626 "can't properly replay without open data");
630 DEBUG_REQ(D_HA, req, "mdc open data found");
634 struct lustre_handle *file_fh;
635 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
636 file_fh = &och->och_fh;
637 CDEBUG(D_RPCTRACE, "updating handle from "LPX64" to "LPX64"\n",
638 file_fh->cookie, body->handle.cookie);
640 *file_fh = body->handle;
643 close_req = mod->mod_close_req;
645 if (close_req != NULL) {
646 LASSERT(lustre_msg_get_opc(close_req->rq_reqmsg) == MDS_CLOSE);
647 if (mdc_req_is_2_0_server(close_req)) {
648 struct mdt_epoch *epoch = NULL;
650 epoch = lustre_msg_buf(close_req->rq_reqmsg,
651 REQ_REC_OFF, sizeof(*epoch));
654 LASSERT(!memcmp(&old, &epoch->handle,
656 DEBUG_REQ(D_RPCTRACE, close_req,
657 "updating close with new fh");
658 epoch->handle = body->handle;
660 struct mds_body *close_body = NULL;
662 close_body = lustre_msg_buf(close_req->rq_reqmsg,
664 sizeof(*close_body));
666 LASSERT(!memcmp(&old, &close_body->handle,
668 DEBUG_REQ(D_RPCTRACE, close_req,
669 "updating close with new fh");
670 close_body->handle = body->handle;
677 static void mdc_set_open_replay_data_20(struct obd_client_handle *och,
678 struct ptlrpc_request *open_req)
680 struct mdc_open_data *mod;
681 struct obd_import *imp = open_req->rq_import;
682 struct mdt_rec_create *rec = lustre_msg_buf(open_req->rq_reqmsg,
685 struct mdt_body *body = lustre_msg_buf(open_req->rq_repmsg,
689 /* If request is not eligible for replay, just bail out */
690 if (!open_req->rq_replay)
693 /* incoming message in my byte order (it's been swabbed) */
694 LASSERT(rec != NULL);
695 LASSERT(lustre_rep_swabbed(open_req, DLM_REPLY_REC_OFF));
696 /* outgoing messages always in my byte order */
697 LASSERT(body != NULL);
699 /* Only if the import is replayable, we set replay_open data */
700 if (och && imp->imp_replayable) {
703 DEBUG_REQ(D_ERROR, open_req,
704 "can't allocate mdc_open_data");
708 spin_lock(&open_req->rq_lock);
711 mod->mod_open_req = open_req;
712 open_req->rq_cb_data = mod;
713 open_req->rq_commit_cb = mdc_commit_open;
714 spin_unlock(&open_req->rq_lock);
717 rec->cr_fid2 = body->fid1;
718 rec->cr_ioepoch = body->ioepoch;
719 rec->cr_old_handle.cookie = body->handle.cookie;
720 open_req->rq_replay_cb = mdc_replay_open;
721 if (!fid_is_sane(&body->fid1)) {
722 DEBUG_REQ(D_ERROR, open_req, "saving replay request with "
727 DEBUG_REQ(D_RPCTRACE, open_req, "set up replay data");
730 static void mdc_set_open_replay_data_18(struct obd_client_handle *och,
731 struct ptlrpc_request *open_req)
733 struct mdc_open_data *mod;
734 struct mds_rec_create *rec = lustre_msg_buf(open_req->rq_reqmsg,
737 struct mds_body *body = lustre_msg_buf(open_req->rq_repmsg,
741 /* If request is not eligible for replay, just bail out */
742 if (!open_req->rq_replay)
745 /* incoming message in my byte order (it's been swabbed) */
746 LASSERT(rec != NULL);
747 LASSERT(lustre_rep_swabbed(open_req, DLM_REPLY_REC_OFF));
748 /* outgoing messages always in my byte order */
749 LASSERT(body != NULL);
752 OBD_ALLOC(mod, sizeof(*mod));
754 DEBUG_REQ(D_ERROR, open_req, "can't allocate mdc_open_data");
758 spin_lock(&open_req->rq_lock);
761 mod->mod_open_req = open_req;
762 open_req->rq_cb_data = mod;
763 open_req->rq_commit_cb = mdc_commit_open;
764 spin_unlock(&open_req->rq_lock);
767 memcpy(&rec->cr_replayfid, &body->fid1, sizeof rec->cr_replayfid);
768 open_req->rq_replay_cb = mdc_replay_open;
769 if (body->fid1.id == 0) {
770 DEBUG_REQ(D_ERROR, open_req, "saving replay request with "
771 "id = 0 gen = %u", body->fid1.generation);
775 DEBUG_REQ(D_RPCTRACE, open_req, "set up replay data");
778 void mdc_set_open_replay_data(struct obd_client_handle *och,
779 struct ptlrpc_request *open_req)
781 if (mdc_req_is_2_0_server(open_req))
782 mdc_set_open_replay_data_20(och, open_req);
784 mdc_set_open_replay_data_18(och, open_req);
787 void mdc_clear_open_replay_data(struct obd_client_handle *och)
789 struct mdc_open_data *mod = och->och_mod;
791 /* Don't free the structure now (it happens in mdc_commit_open, after
792 * we're sure we won't need to fix up the close request in the future),
793 * but make sure that replay doesn't poke at the och, which is about to
795 LASSERT(mod != LP_POISON);
801 int mdc_close(struct obd_export *exp, struct mdc_op_data *data, struct obdo *oa,
802 struct obd_client_handle *och, struct ptlrpc_request **request)
804 struct obd_device *obd = class_exp2obd(exp);
805 __u32 reqsize[4] = { sizeof(struct ptlrpc_body),
806 sizeof(struct mdt_body) };
807 __u32 repsize[6] = { sizeof(struct ptlrpc_body),
808 sizeof(struct mdt_body),
809 obd->u.cli.cl_max_mds_easize,
810 obd->u.cli.cl_max_mds_cookiesize,
811 sizeof(struct lustre_capa),
812 sizeof(struct lustre_capa) };
814 struct ptlrpc_request *req;
818 if (mdc_exp_is_2_0_server(exp)) {
819 reqsize[1] = sizeof(struct mdt_epoch);
820 reqsize[2] = sizeof(struct mdt_rec_create);
821 reqsize[3] = 0; /* capa */
824 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
825 MDS_CLOSE, bufcount, reqsize, NULL);
827 GOTO(out, rc = -ENOMEM);
828 req->rq_export = class_export_get(exp);
830 /* To avoid a livelock (bug 7034), we need to send CLOSE RPCs to a
831 * portal whose threads are not taking any DLM locks and are therefore
832 * always progressing */
833 req->rq_request_portal = MDS_READPAGE_PORTAL;
834 ptlrpc_at_set_req_timeout(req);
836 /* Ensure that this close's handle is fixed up during replay. */
837 LASSERT(och != NULL);
838 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
839 if (likely(och->och_mod != NULL)) {
840 struct ptlrpc_request *open_req = och->och_mod->mod_open_req;
842 if (open_req->rq_type == LI_POISON) {
843 CERROR("LBUG POISONED open %p!\n", open_req);
845 ptlrpc_req_finished(req);
847 GOTO(out, rc = -EIO);
849 och->och_mod->mod_close_req = req;
850 DEBUG_REQ(D_RPCTRACE, req, "close req");
851 DEBUG_REQ(D_RPCTRACE, open_req, "clear open replay");
853 /* We no longer want to preserve this open for replay even
854 * though the open was committed. b=3632, b=3633 */
855 spin_lock(&open_req->rq_lock);
856 open_req->rq_replay = 0;
857 spin_unlock(&open_req->rq_lock);
859 CDEBUG(D_RPCTRACE, "couldn't find open req; expecting error\n");
862 mdc_close_pack(req, REQ_REC_OFF, data, oa, oa->o_valid, och);
864 ptlrpc_req_set_repsize(req, 6, repsize);
866 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
867 rc = ptlrpc_queue_wait(req);
868 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
870 if (req->rq_repmsg == NULL) {
871 CDEBUG(D_RPCTRACE, "request failed to send: %p, %d\n", req,
874 rc = req->rq_status ? req->rq_status : -EIO;
875 } else if (rc == 0) {
876 rc = lustre_msg_get_status(req->rq_repmsg);
877 if (lustre_msg_get_type(req->rq_repmsg) == PTL_RPC_MSG_ERR) {
878 DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, err "
882 } else if (och->och_mod == NULL) {
883 CERROR("Unexpected: can't find mdc_open_data, but the "
884 "close succeeded. Please tell <http://bugzilla.lustre.org/>.\n");
886 if (!lustre_swab_repbuf(req, REPLY_REC_OFF,
887 sizeof(struct mds_body),
888 lustre_swab_mds_body)) {
889 CERROR("Error unpacking mds_body\n");
897 if (rc != 0 && req && req->rq_commit_cb)
898 req->rq_commit_cb(req);
903 int mdc_done_writing(struct obd_export *exp, struct mdc_op_data *data,
906 struct ptlrpc_request *req;
907 struct mds_body *body;
908 __u32 size[2] = { sizeof(struct ptlrpc_body),
909 sizeof(struct mdt_body) };
913 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
914 MDS_DONE_WRITING, 2, size, NULL);
918 req->rq_export = class_export_get(exp);
919 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
920 body->fid1 = data->fid1;
921 body->size = obdo->o_size;
922 body->blocks = obdo->o_blocks;
923 body->flags = obdo->o_flags;
924 body->valid = obdo->o_valid;
925 // memcpy(&body->handle, &och->och_fh, sizeof(body->handle));
927 ptlrpc_req_set_repsize(req, 2, size);
929 rc = ptlrpc_queue_wait(req);
930 ptlrpc_req_finished(req);
934 int mdc_readpage(struct obd_export *exp, struct ll_fid *fid, __u64 offset,
935 struct page *page, struct ptlrpc_request **request)
937 struct obd_import *imp = class_exp2cliimp(exp);
938 struct ptlrpc_request *req = NULL;
939 struct ptlrpc_bulk_desc *desc = NULL;
940 struct mds_body *body;
941 __u32 size[2] = { sizeof(struct ptlrpc_body),
942 sizeof(struct mdt_body) };
946 CDEBUG(D_INODE, "inode: "LPU64"\n", fid->id);
948 req = ptlrpc_prep_req(imp, LUSTRE_MDS_VERSION, MDS_READPAGE, 2, size,
951 GOTO(out, rc = -ENOMEM);
953 req->rq_export = class_export_get(exp);
954 req->rq_request_portal = MDS_READPAGE_PORTAL;
955 ptlrpc_at_set_req_timeout(req);
957 desc = ptlrpc_prep_bulk_imp(req, 1, BULK_PUT_SINK, MDS_BULK_PORTAL);
959 GOTO(out, rc = -ENOMEM);
960 /* NB req now owns desc and will free it when it gets freed */
962 ptlrpc_prep_bulk_page(desc, page, 0, CFS_PAGE_SIZE);
964 mdc_readdir_pack(req, REQ_REC_OFF, offset, CFS_PAGE_SIZE, fid);
966 ptlrpc_req_set_repsize(req, 2, size);
967 rc = ptlrpc_queue_wait(req);
970 body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body),
971 lustre_swab_mds_body);
973 CERROR("Can't unpack mds_body\n");
974 GOTO(out, rc = -EPROTO);
977 if (req->rq_bulk->bd_nob_transferred != CFS_PAGE_SIZE) {
978 CERROR ("Unexpected # bytes transferred: %d"
980 req->rq_bulk->bd_nob_transferred,
982 GOTO (out, rc = -EPROTO);
993 static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
994 void *karg, void *uarg)
996 struct obd_device *obd = exp->exp_obd;
997 struct obd_ioctl_data *data = karg;
998 struct obd_import *imp = obd->u.cli.cl_import;
999 struct llog_ctxt *ctxt;
1003 if (!try_module_get(THIS_MODULE)) {
1004 CERROR("Can't get module. Is it alive?");
1008 case OBD_IOC_CLIENT_RECOVER:
1009 rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1);
1013 case IOC_OSC_SET_ACTIVE:
1014 rc = ptlrpc_set_import_active(imp, data->ioc_offset);
1016 case OBD_IOC_PARSE: {
1017 ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT);
1018 rc = class_config_parse_llog(ctxt, data->ioc_inlbuf1, NULL);
1019 llog_ctxt_put(ctxt);
1023 case OBD_IOC_LLOG_INFO:
1024 case OBD_IOC_LLOG_PRINT: {
1025 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
1026 rc = llog_ioctl(ctxt, cmd, data);
1027 llog_ctxt_put(ctxt);
1031 case OBD_IOC_POLL_QUOTACHECK:
1032 rc = lquota_poll_check(quota_interface, exp,
1033 (struct if_quotacheck *)karg);
1035 case OBD_IOC_PING_TARGET:
1036 rc = ptlrpc_obd_ping(obd);
1039 CERROR("mdc_ioctl(): unrecognised ioctl %#x\n", cmd);
1040 GOTO(out, rc = -ENOTTY);
1043 module_put(THIS_MODULE);
1047 int mdc_set_info_async(struct obd_export *exp, obd_count keylen,
1048 void *key, obd_count vallen, void *val,
1049 struct ptlrpc_request_set *set)
1051 struct obd_import *imp = class_exp2cliimp(exp);
1054 if (KEY_IS(KEY_INIT_RECOV)) {
1055 if (vallen != sizeof(int))
1057 spin_lock(&imp->imp_lock);
1058 imp->imp_initial_recov = *(int *)val;
1059 spin_unlock(&imp->imp_lock);
1061 CDEBUG(D_HA, "%s: set imp_initial_recov = %d\n",
1062 exp->exp_obd->obd_name, imp->imp_initial_recov);
1065 /* Turn off initial_recov after we try all backup servers once */
1066 if (KEY_IS(KEY_INIT_RECOV_BACKUP)) {
1067 if (vallen != sizeof(int))
1070 spin_lock(&imp->imp_lock);
1071 imp->imp_initial_recov_bk = *(int *)val;
1072 if (imp->imp_initial_recov_bk)
1073 imp->imp_initial_recov = 1;
1074 spin_unlock(&imp->imp_lock);
1076 CDEBUG(D_HA, "%s: set imp_initial_recov_bk = %d\n",
1077 exp->exp_obd->obd_name, imp->imp_initial_recov_bk);
1080 /* Accept the broken "read-only" key for 1.6.6 servers. b=17493 */
1081 if (KEY_IS(KEY_READONLY) || KEY_IS(KEY_READONLY_166COMPAT)) {
1082 struct ptlrpc_request *req;
1083 __u32 size[3] = { sizeof(struct ptlrpc_body), keylen, vallen };
1084 char *bufs[3] = { NULL, key, val };
1086 if (vallen != sizeof(int))
1089 if (*((int *)val)) {
1090 imp->imp_connect_flags_orig |= OBD_CONNECT_RDONLY;
1091 imp->imp_connect_data.ocd_connect_flags |=
1094 imp->imp_connect_flags_orig &= ~OBD_CONNECT_RDONLY;
1095 imp->imp_connect_data.ocd_connect_flags &=
1096 ~OBD_CONNECT_RDONLY;
1099 req = ptlrpc_prep_req(imp, LUSTRE_MDS_VERSION, MDS_SET_INFO,
1104 req->rq_export = class_export_get(exp);
1105 ptlrpc_req_set_repsize(req, 1, NULL);
1108 ptlrpc_set_add_req(set, req);
1109 ptlrpc_check_set(set);
1111 rc = ptlrpc_queue_wait(req);
1112 ptlrpc_req_finished(req);
1121 int mdc_get_info(struct obd_export *exp, __u32 keylen, void *key,
1122 __u32 *vallen, void *val, struct lov_stripe_md *lsm)
1126 if (KEY_IS(KEY_MAX_EASIZE)) {
1127 int mdsize, *max_easize;
1129 if (*vallen != sizeof(int))
1131 mdsize = *(int*)val;
1132 if (mdsize > exp->exp_obd->u.cli.cl_max_mds_easize)
1133 exp->exp_obd->u.cli.cl_max_mds_easize = mdsize;
1135 *max_easize = exp->exp_obd->u.cli.cl_max_mds_easize;
1141 static int mdc_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1142 __u64 max_age, __u32 flags)
1144 struct ptlrpc_request *req;
1145 struct obd_statfs *msfs;
1146 struct obd_import *imp = NULL;
1147 __u32 size[2] = { sizeof(struct ptlrpc_body), sizeof(*msfs) };
1151 /*Since the request might also come from lprocfs, so we need
1152 *sync this with client_disconnect_export Bug15684*/
1153 down_read(&obd->u.cli.cl_sem);
1154 if (obd->u.cli.cl_import)
1155 imp = class_import_get(obd->u.cli.cl_import);
1156 up_read(&obd->u.cli.cl_sem);
1161 /* We could possibly pass max_age in the request (as an absolute
1162 * timestamp or a "seconds.usec ago") so the target can avoid doing
1163 * extra calls into the filesystem if that isn't necessary (e.g.
1164 * during mount that would help a bit). Having relative timestamps
1165 * is not so great if request processing is slow, while absolute
1166 * timestamps are not ideal because they need time synchronization. */
1167 req = ptlrpc_prep_req(imp, LUSTRE_MDS_VERSION, MDS_STATFS, 1, NULL,
1170 GOTO(output, rc = -ENOMEM);
1172 ptlrpc_req_set_repsize(req, 2, size);
1174 if (flags & OBD_STATFS_NODELAY) {
1175 /* procfs requests not want stay in wait for avoid deadlock */
1176 req->rq_no_resend = 1;
1177 req->rq_no_delay = 1;
1180 rc = ptlrpc_queue_wait(req);
1185 msfs = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*msfs),
1186 lustre_swab_obd_statfs);
1188 CERROR("Can't unpack obd_statfs\n");
1189 GOTO(out, rc = -EPROTO);
1192 memcpy(osfs, msfs, sizeof(*msfs));
1195 ptlrpc_req_finished(req);
1197 class_import_put(imp);
1201 static int mdc_pin(struct obd_export *exp, struct ll_fid *fid,
1202 struct obd_client_handle *handle, int flag)
1204 struct ptlrpc_request *req;
1205 struct mds_body *body;
1206 __u32 size[3] = { sizeof(struct ptlrpc_body),
1207 sizeof(struct mdt_body), 0 };
1212 if (mdc_exp_is_2_0_server(exp))
1214 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1215 MDS_PIN, bufcount, size, NULL);
1219 req->rq_export = class_export_get(exp);
1220 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
1224 ptlrpc_req_set_repsize(req, 2, size);
1226 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1227 rc = ptlrpc_queue_wait(req);
1228 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1230 CERROR("pin failed: %d\n", rc);
1231 ptlrpc_req_finished(req);
1235 body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body),
1236 lustre_swab_mds_body);
1238 ptlrpc_req_finished(req);
1242 memcpy(&handle->och_fh, &body->handle, sizeof(body->handle));
1243 handle->och_magic = OBD_CLIENT_HANDLE_MAGIC;
1245 OBD_ALLOC(handle->och_mod, sizeof(*handle->och_mod));
1246 if (handle->och_mod == NULL) {
1247 DEBUG_REQ(D_ERROR, req, "can't allocate mdc_open_data");
1250 handle->och_mod->mod_open_req = req; /* will be dropped by unpin */
1255 static int mdc_unpin(struct obd_export *exp,
1256 struct obd_client_handle *handle, int flag)
1258 struct ptlrpc_request *req;
1259 struct mds_body *body;
1260 __u32 size[2] = { sizeof(struct ptlrpc_body),
1261 sizeof(struct mdt_body) };
1265 if (handle->och_magic != OBD_CLIENT_HANDLE_MAGIC)
1268 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1269 MDS_CLOSE, 2, size, NULL);
1273 req->rq_export = class_export_get(exp);
1274 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
1275 memcpy(&body->handle, &handle->och_fh, sizeof(body->handle));
1278 ptlrpc_req_set_repsize(req, 1, NULL);
1279 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1280 rc = ptlrpc_queue_wait(req);
1281 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1284 CERROR("unpin failed: %d\n", rc);
1286 ptlrpc_req_finished(req);
1287 ptlrpc_req_finished(handle->och_mod->mod_open_req);
1288 OBD_FREE(handle->och_mod, sizeof(*handle->och_mod));
1292 int mdc_sync(struct obd_export *exp, struct ll_fid *fid,
1293 struct ptlrpc_request **request)
1295 struct ptlrpc_request *req;
1296 __u32 size[3] = { sizeof(struct ptlrpc_body),
1297 sizeof(struct mdt_body), 0 };
1303 if (mdc_exp_is_2_0_server(exp))
1305 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1306 MDS_SYNC, bufcount, size, NULL);
1308 RETURN(rc = -ENOMEM);
1310 req->rq_export = class_export_get(exp);
1311 mdc_pack_req_body(req, REQ_REC_OFF, 0, fid, 0, 0);
1313 ptlrpc_req_set_repsize(req, 2, size);
1315 rc = ptlrpc_queue_wait(req);
1316 if (rc || request == NULL)
1317 ptlrpc_req_finished(req);
1324 static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
1325 enum obd_import_event event)
1329 LASSERT(imp->imp_obd == obd);
1332 case IMP_EVENT_DISCON: {
1333 ptlrpc_import_setasync(imp, -obd->obd_namespace->ns_max_unused);
1336 case IMP_EVENT_INACTIVE: {
1337 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_INACTIVE, NULL);
1340 case IMP_EVENT_INVALIDATE: {
1341 struct ldlm_namespace *ns = obd->obd_namespace;
1343 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
1347 case IMP_EVENT_ACTIVE: {
1348 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_ACTIVE, NULL);
1352 ptlrpc_import_setasync(imp, obd->obd_namespace->ns_max_unused);
1356 CERROR("Unknown import event %x\n", event);
1362 static int mdc_setup(struct obd_device *obd, obd_count len, void *buf)
1364 struct client_obd *cli = &obd->u.cli;
1365 struct lprocfs_static_vars lvars = { 0 };
1369 OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1370 if (!cli->cl_rpc_lock)
1372 mdc_init_rpc_lock(cli->cl_rpc_lock);
1376 OBD_ALLOC(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1377 if (!cli->cl_setattr_lock)
1378 GOTO(err_rpc_lock, rc = -ENOMEM);
1379 mdc_init_rpc_lock(cli->cl_setattr_lock);
1381 OBD_ALLOC(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1382 if (!cli->cl_close_lock)
1383 GOTO(err_setattr_lock, rc = -ENOMEM);
1384 mdc_init_rpc_lock(cli->cl_close_lock);
1386 rc = client_obd_setup(obd, len, buf);
1388 GOTO(err_close_lock, rc);
1389 lprocfs_mdc_init_vars(&lvars);
1390 if (lprocfs_obd_setup(obd, lvars.obd_vars) == 0)
1391 ptlrpc_lprocfs_register_obd(obd);
1393 rc = obd_llog_init(obd, obd, 0, NULL, NULL);
1396 CERROR("failed to setup llogging subsystems\n");
1402 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1404 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1406 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1411 /* Initialize the default and maximum LOV EA and cookie sizes. This allows
1412 * us to make MDS RPCs with large enough reply buffers to hold the
1413 * maximum-sized (= maximum striped) EA and cookie without having to
1414 * calculate this (via a call into the LOV + OSCs) each time we make an RPC. */
1415 int mdc_init_ea_size(struct obd_export *mdc_exp, struct obd_export *lov_exp)
1417 struct obd_device *obd = mdc_exp->exp_obd;
1418 struct client_obd *cli = &obd->u.cli;
1419 struct lov_stripe_md lsm = { .lsm_magic = LOV_MAGIC_V3 };
1420 struct lov_desc desc;
1421 __u32 valsize = sizeof(desc);
1426 rc = obd_get_info(lov_exp, sizeof(KEY_LOVDESC), KEY_LOVDESC,
1427 &valsize, &desc, NULL);
1431 stripes = min(desc.ld_tgt_count, (__u32)LOV_MAX_STRIPE_COUNT);
1432 lsm.lsm_stripe_count = stripes;
1433 size = obd_size_diskmd(lov_exp, &lsm);
1435 if (cli->cl_max_mds_easize < size)
1436 cli->cl_max_mds_easize = size;
1438 lsm.lsm_stripe_count = desc.ld_default_stripe_count;
1439 size = obd_size_diskmd(lov_exp, &lsm);
1441 if (cli->cl_default_mds_easize < size)
1442 cli->cl_default_mds_easize = size;
1444 size = stripes * sizeof(struct llog_cookie);
1445 if (cli->cl_max_mds_cookiesize < size)
1446 cli->cl_max_mds_cookiesize = size;
1448 CDEBUG(D_HA, "updating max_mdsize/max_cookiesize: %d/%d\n",
1449 cli->cl_max_mds_easize, cli->cl_max_mds_cookiesize);
1454 static int mdc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
1460 case OBD_CLEANUP_EARLY:
1461 case OBD_CLEANUP_EXPORTS:
1462 /* If we set up but never connected, the
1463 client import will not have been cleaned. */
1464 if (obd->u.cli.cl_import) {
1465 struct obd_import *imp;
1466 down_write(&obd->u.cli.cl_sem);
1467 imp = obd->u.cli.cl_import;
1468 CERROR("client import never connected\n");
1469 ptlrpc_invalidate_import(imp);
1470 class_destroy_import(imp);
1471 up_write(&obd->u.cli.cl_sem);
1472 obd->u.cli.cl_import = NULL;
1474 rc = obd_llog_finish(obd, 0);
1476 CERROR("failed to cleanup llogging subsystems\n");
1478 case OBD_CLEANUP_SELF_EXP:
1480 case OBD_CLEANUP_OBD:
1486 static int mdc_cleanup(struct obd_device *obd)
1488 struct client_obd *cli = &obd->u.cli;
1490 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1491 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1492 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1494 ptlrpc_lprocfs_unregister_obd(obd);
1495 lprocfs_obd_cleanup(obd);
1498 return client_obd_cleanup(obd);
1502 static int mdc_llog_init(struct obd_device *obd, struct obd_device *tgt,
1503 int count, struct llog_catid *logid,
1504 struct obd_uuid *uuid)
1506 struct llog_ctxt *ctxt;
1510 rc = llog_setup(obd, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
1513 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
1514 llog_initiator_connect(ctxt);
1515 llog_ctxt_put(ctxt);
1518 rc = llog_setup(obd, LLOG_LOVEA_REPL_CTXT, tgt, 0, NULL,
1521 ctxt = llog_get_context(obd, LLOG_LOVEA_REPL_CTXT);
1522 llog_initiator_connect(ctxt);
1523 llog_ctxt_put(ctxt);
1525 GOTO(err_cleanup, rc);
1530 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
1533 ctxt = llog_get_context(obd, LLOG_LOVEA_REPL_CTXT);
1539 static int mdc_llog_finish(struct obd_device *obd, int count)
1541 struct llog_ctxt *ctxt;
1545 ctxt = llog_get_context(obd, LLOG_LOVEA_REPL_CTXT);
1547 rc = llog_cleanup(ctxt);
1549 CERROR("Can not cleanup LLOG_CONFIG_REPL_CTXT "
1553 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
1555 rc = llog_cleanup(ctxt);
1559 static int mdc_process_config(struct obd_device *obd, obd_count len, void *buf)
1561 struct lustre_cfg *lcfg = buf;
1562 struct lprocfs_static_vars lvars = { 0 };
1565 lprocfs_mdc_init_vars(&lvars);
1567 rc = class_process_proc_param(PARAM_MDC, lvars.obd_vars, lcfg, obd);
1571 static int mdc_fid_init(struct obd_export *exp)
1573 struct client_obd *cli;
1578 cli = &exp->exp_obd->u.cli;
1580 OBD_ALLOC_PTR(cli->cl_seq);
1581 if (cli->cl_seq == NULL)
1584 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
1586 GOTO(out_free_seq, rc = -ENOMEM);
1588 snprintf(prefix, MAX_OBD_NAME + 5, "srv-%s", exp->exp_obd->obd_name);
1590 /* Init client side sequence-manager */
1591 rc = seq_client_init(cli->cl_seq, exp,
1592 LUSTRE_SEQ_METADATA,
1593 LUSTRE_SEQ_MAX_WIDTH,
1595 OBD_FREE(prefix, MAX_OBD_NAME + 5);
1597 GOTO(out_free_seq, rc);
1602 OBD_FREE_PTR(cli->cl_seq);
1607 static int mdc_fid_fini(struct obd_export *exp)
1609 struct client_obd *cli = &exp->exp_obd->u.cli;
1612 if (cli->cl_seq != NULL) {
1613 LASSERT(cli->cl_seq->lcs_exp == exp);
1614 seq_client_fini(cli->cl_seq);
1615 OBD_FREE_PTR(cli->cl_seq);
1622 struct obd_ops mdc_obd_ops = {
1623 .o_owner = THIS_MODULE,
1624 .o_setup = mdc_setup,
1625 .o_precleanup = mdc_precleanup,
1626 .o_cleanup = mdc_cleanup,
1627 .o_add_conn = client_import_add_conn,
1628 .o_del_conn = client_import_del_conn,
1629 .o_connect = client_connect_import,
1630 .o_disconnect = client_disconnect_export,
1631 .o_fid_init = mdc_fid_init,
1632 .o_fid_fini = mdc_fid_fini,
1633 .o_iocontrol = mdc_iocontrol,
1634 .o_set_info_async = mdc_set_info_async,
1635 .o_get_info = mdc_get_info,
1636 .o_statfs = mdc_statfs,
1638 .o_unpin = mdc_unpin,
1639 .o_import_event = mdc_import_event,
1640 .o_llog_init = mdc_llog_init,
1641 .o_llog_finish = mdc_llog_finish,
1642 .o_process_config = mdc_process_config,
1645 int __init mdc_init(void)
1648 struct lprocfs_static_vars lvars = { 0 };
1649 lprocfs_mdc_init_vars(&lvars);
1650 request_module("lquota");
1651 quota_interface = PORTAL_SYMBOL_GET(mdc_quota_interface);
1652 init_obd_quota_ops(quota_interface, &mdc_obd_ops);
1654 rc = class_register_type(&mdc_obd_ops, lvars.module_vars,
1656 if (rc && quota_interface)
1657 PORTAL_SYMBOL_PUT(mdc_quota_interface);
1663 static void /*__exit*/ mdc_exit(void)
1665 if (quota_interface)
1666 PORTAL_SYMBOL_PUT(mdc_quota_interface);
1668 class_unregister_type(LUSTRE_MDC_NAME);
1671 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
1672 MODULE_DESCRIPTION("Lustre Metadata Client");
1673 MODULE_LICENSE("GPL");
1675 EXPORT_SYMBOL(mdc_req2lustre_md);
1676 EXPORT_SYMBOL(mdc_free_lustre_md);
1677 EXPORT_SYMBOL(mdc_change_cbdata);
1678 EXPORT_SYMBOL(mdc_getstatus);
1679 EXPORT_SYMBOL(mdc_getattr);
1680 EXPORT_SYMBOL(mdc_getattr_name);
1681 EXPORT_SYMBOL(mdc_create);
1682 EXPORT_SYMBOL(mdc_unlink);
1683 EXPORT_SYMBOL(mdc_rename);
1684 EXPORT_SYMBOL(mdc_link);
1685 EXPORT_SYMBOL(mdc_readpage);
1686 EXPORT_SYMBOL(mdc_setattr);
1687 EXPORT_SYMBOL(mdc_close);
1688 EXPORT_SYMBOL(mdc_done_writing);
1689 EXPORT_SYMBOL(mdc_sync);
1690 EXPORT_SYMBOL(mdc_set_open_replay_data);
1691 EXPORT_SYMBOL(mdc_clear_open_replay_data);
1692 EXPORT_SYMBOL(mdc_store_inode_generation);
1693 EXPORT_SYMBOL(mdc_init_ea_size);
1694 EXPORT_SYMBOL(mdc_getxattr);
1695 EXPORT_SYMBOL(mdc_setxattr);
1697 module_init(mdc_init);
1698 module_exit(mdc_exit);