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 <lustre_acl.h>
52 #include <obd_class.h>
53 #include <lustre_dlm.h>
54 #include <lustre_fid.h>
55 #include <md_object.h>
56 #include <lprocfs_status.h>
57 #include <lustre_param.h>
58 #include "mdc_internal.h"
60 #define REQUEST_MINOR 244
62 static quota_interface_t *quota_interface;
63 extern quota_interface_t mdc_quota_interface;
65 static int mdc_cleanup(struct obd_device *obd);
67 int mdc_unpack_capa(struct obd_export *exp, struct ptlrpc_request *req,
68 const struct req_msg_field *field, struct obd_capa **oc)
70 struct lustre_capa *capa;
74 /* swabbed already in mdc_enqueue */
75 capa = req_capsule_server_get(&req->rq_pill, field);
79 c = alloc_capa(CAPA_SITE_CLIENT);
81 CDEBUG(D_INFO, "alloc capa failed!\n");
90 /* Helper that implements most of mdc_getstatus and signal_completed_replay. */
91 /* XXX this should become mdc_get_info("key"), sending MDS_GET_INFO RPC */
92 static int send_getstatus(struct obd_import *imp, struct lu_fid *rootfid,
93 struct obd_capa **pc, int level, int msg_flags)
95 struct ptlrpc_request *req;
96 struct mdt_body *body;
100 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_GETSTATUS,
101 LUSTRE_MDS_VERSION, MDS_GETSTATUS);
105 mdc_pack_body(req, NULL, NULL, 0, 0, -1, 0);
106 lustre_msg_add_flags(req->rq_reqmsg, msg_flags);
107 req->rq_send_state = level;
109 ptlrpc_request_set_replen(req);
111 rc = ptlrpc_queue_wait(req);
115 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
117 GOTO(out, rc = -EPROTO);
119 if (body->valid & OBD_MD_FLMDSCAPA) {
120 rc = mdc_unpack_capa(NULL, req, &RMF_CAPA1, pc);
125 *rootfid = body->fid1;
127 "root fid="DFID", last_committed="LPU64", last_xid="LPU64"\n",
129 lustre_msg_get_last_committed(req->rq_repmsg),
130 lustre_msg_get_last_xid(req->rq_repmsg));
133 ptlrpc_req_finished(req);
137 /* This should be mdc_get_info("rootfid") */
138 int mdc_getstatus(struct obd_export *exp, struct lu_fid *rootfid,
139 struct obd_capa **pc)
141 return send_getstatus(class_exp2cliimp(exp), rootfid, pc,
146 * This function now is known to always saying that it will receive 4 buffers
147 * from server. Even for cases when acl_size and md_size is zero, RPC header
148 * will contain 4 fields and RPC itself will contain zero size fields. This is
149 * because mdt_getattr*() _always_ returns 4 fields, but if acl is not needed
150 * and thus zero, it shrinks it, making zero size. The same story about
151 * md_size. And this is course of problem when client waits for smaller number
152 * of fields. This issue will be fixed later when client gets aware of RPC
155 static int mdc_getattr_common(struct obd_export *exp,
156 struct ptlrpc_request *req)
158 struct req_capsule *pill = &req->rq_pill;
159 struct mdt_body *body;
164 /* Request message already built. */
165 rc = ptlrpc_queue_wait(req);
169 /* sanity check for the reply */
170 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
174 CDEBUG(D_NET, "mode: %o\n", body->mode);
176 if (body->eadatasize != 0) {
177 eadata = req_capsule_server_sized_get(pill, &RMF_MDT_MD,
183 if (body->valid & OBD_MD_FLRMTPERM) {
184 struct mdt_remote_perm *perm;
186 LASSERT(client_is_remote(exp));
187 perm = req_capsule_server_swab_get(pill, &RMF_ACL,
188 lustre_swab_mdt_remote_perm);
193 if (body->valid & OBD_MD_FLMDSCAPA) {
194 struct lustre_capa *capa;
195 capa = req_capsule_server_get(pill, &RMF_CAPA1);
203 int mdc_getattr(struct obd_export *exp, const struct lu_fid *fid,
204 struct obd_capa *oc, obd_valid valid, int ea_size,
205 struct ptlrpc_request **request)
207 struct ptlrpc_request *req;
212 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR);
216 mdc_set_capa_size(req, &RMF_CAPA1, oc);
218 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR);
220 ptlrpc_request_free(req);
224 /* MDS_BFLAG_EXT_FLAGS: request "new" flags(bug 9486) */
225 mdc_pack_body(req, fid, oc, valid, ea_size, -1, MDS_BFLAG_EXT_FLAGS);
227 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER, ea_size);
228 if (valid & OBD_MD_FLRMTPERM) {
229 LASSERT(client_is_remote(exp));
230 req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER,
231 sizeof(struct mdt_remote_perm));
233 ptlrpc_request_set_replen(req);
235 rc = mdc_getattr_common(exp, req);
237 ptlrpc_req_finished(req);
243 int mdc_getattr_name(struct obd_export *exp, const struct lu_fid *fid,
244 struct obd_capa *oc, const char *filename, int namelen,
245 obd_valid valid, int ea_size, __u32 suppgid,
246 struct ptlrpc_request **request)
248 struct ptlrpc_request *req;
253 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
254 &RQF_MDS_GETATTR_NAME);
258 mdc_set_capa_size(req, &RMF_CAPA1, oc);
259 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT, namelen);
261 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR_NAME);
263 ptlrpc_request_free(req);
267 /* MDS_BFLAG_EXT_FLAGS: request "new" flags(bug 9486) */
268 mdc_pack_body(req, fid, oc, valid, ea_size, suppgid,
269 MDS_BFLAG_EXT_FLAGS);
272 char *name = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
273 LASSERT(strnlen(filename, namelen) == namelen - 1);
274 memcpy(name, filename, namelen);
277 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER, ea_size);
278 ptlrpc_request_set_replen(req);
280 rc = mdc_getattr_common(exp, req);
282 ptlrpc_req_finished(req);
288 static int mdc_is_subdir(struct obd_export *exp,
289 const struct lu_fid *pfid,
290 const struct lu_fid *cfid,
291 struct ptlrpc_request **request)
293 struct ptlrpc_request *req;
299 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
300 &RQF_MDS_IS_SUBDIR, LUSTRE_MDS_VERSION,
305 mdc_is_subdir_pack(req, pfid, cfid, 0);
306 ptlrpc_request_set_replen(req);
308 rc = ptlrpc_queue_wait(req);
309 if (rc && rc != -EREMOTE)
310 ptlrpc_req_finished(req);
316 static int mdc_xattr_common(struct obd_export *exp,const struct req_format *fmt,
317 const struct lu_fid *fid,
318 struct obd_capa *oc, int opcode, obd_valid valid,
319 const char *xattr_name, const char *input,
320 int input_size, int output_size, int flags,
321 __u32 suppgid, struct ptlrpc_request **request)
323 struct ptlrpc_request *req;
324 int xattr_namelen = 0;
330 req = ptlrpc_request_alloc(class_exp2cliimp(exp), fmt);
334 mdc_set_capa_size(req, &RMF_CAPA1, oc);
336 xattr_namelen = strlen(xattr_name) + 1;
337 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
342 req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_CLIENT,
346 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, opcode);
348 ptlrpc_request_free(req);
352 if (opcode == MDS_REINT) {
353 struct mdt_rec_setxattr *rec;
355 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
356 sizeof(struct mdt_rec_reint));
357 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
358 rec->sx_opcode = REINT_SETXATTR;
360 * cfs_curproc_fs{u,g}id() should replace
361 * current->fs{u,g}id for portability.
363 rec->sx_fsuid = current->fsuid;
364 rec->sx_fsgid = current->fsgid;
365 rec->sx_cap = cfs_curproc_cap_pack();
366 rec->sx_suppgid1 = suppgid;
367 rec->sx_suppgid2 = -1;
369 rec->sx_valid = valid | OBD_MD_FLCTIME;
370 rec->sx_time = cfs_time_current_sec();
371 rec->sx_size = output_size;
372 rec->sx_flags = flags;
374 mdc_pack_capa(req, &RMF_CAPA1, oc);
376 mdc_pack_body(req, fid, oc, valid, output_size, suppgid, flags);
380 tmp = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
381 memcpy(tmp, xattr_name, xattr_namelen);
384 tmp = req_capsule_client_get(&req->rq_pill, &RMF_EADATA);
385 memcpy(tmp, input, input_size);
388 if (req_capsule_has_field(&req->rq_pill, &RMF_EADATA, RCL_SERVER))
389 req_capsule_set_size(&req->rq_pill, &RMF_EADATA,
390 RCL_SERVER, output_size);
391 ptlrpc_request_set_replen(req);
394 if (opcode == MDS_REINT)
395 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
397 rc = ptlrpc_queue_wait(req);
399 if (opcode == MDS_REINT)
400 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
403 ptlrpc_req_finished(req);
409 int mdc_setxattr(struct obd_export *exp, const struct lu_fid *fid,
410 struct obd_capa *oc, obd_valid valid, const char *xattr_name,
411 const char *input, int input_size, int output_size,
412 int flags, __u32 suppgid, struct ptlrpc_request **request)
414 return mdc_xattr_common(exp, &RQF_MDS_REINT_SETXATTR,
415 fid, oc, MDS_REINT, valid, xattr_name,
416 input, input_size, output_size, flags,
420 int mdc_getxattr(struct obd_export *exp, const struct lu_fid *fid,
421 struct obd_capa *oc, obd_valid valid, const char *xattr_name,
422 const char *input, int input_size, int output_size,
423 int flags, struct ptlrpc_request **request)
425 return mdc_xattr_common(exp, &RQF_MDS_GETXATTR,
426 fid, oc, MDS_GETXATTR, valid, xattr_name,
427 input, input_size, output_size, flags,
431 #ifdef CONFIG_FS_POSIX_ACL
432 static int mdc_unpack_acl(struct ptlrpc_request *req, struct lustre_md *md)
434 struct req_capsule *pill = &req->rq_pill;
435 struct mdt_body *body = md->body;
436 struct posix_acl *acl;
444 buf = req_capsule_server_sized_get(pill, &RMF_ACL, body->aclsize);
449 acl = posix_acl_from_xattr(buf, body->aclsize);
452 CERROR("convert xattr to acl: %d\n", rc);
456 rc = posix_acl_valid(acl);
458 CERROR("validate acl: %d\n", rc);
459 posix_acl_release(acl);
467 #define mdc_unpack_acl(req, md) 0
470 int mdc_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
471 struct obd_export *dt_exp, struct obd_export *md_exp,
472 struct lustre_md *md)
474 struct req_capsule *pill = &req->rq_pill;
479 memset(md, 0, sizeof(*md));
481 md->body = req_capsule_server_get(pill, &RMF_MDT_BODY);
482 LASSERT(md->body != NULL);
484 if (md->body->valid & OBD_MD_FLEASIZE) {
486 struct lov_mds_md *lmm;
488 if (!S_ISREG(md->body->mode)) {
489 CDEBUG(D_INFO, "OBD_MD_FLEASIZE set, should be a "
490 "regular file, but is not\n");
491 GOTO(out, rc = -EPROTO);
494 if (md->body->eadatasize == 0) {
495 CDEBUG(D_INFO, "OBD_MD_FLEASIZE set, "
496 "but eadatasize 0\n");
497 GOTO(out, rc = -EPROTO);
499 lmmsize = md->body->eadatasize;
500 lmm = req_capsule_server_sized_get(pill, &RMF_MDT_MD, lmmsize);
502 GOTO(out, rc = -EPROTO);
504 rc = obd_unpackmd(dt_exp, &md->lsm, lmm, lmmsize);
508 if (rc < sizeof(*md->lsm)) {
509 CDEBUG(D_INFO, "lsm size too small: "
510 "rc < sizeof (*md->lsm) (%d < %d)\n",
511 rc, (int)sizeof(*md->lsm));
512 GOTO(out, rc = -EPROTO);
515 } else if (md->body->valid & OBD_MD_FLDIREA) {
517 struct lov_mds_md *lmv;
519 if(!S_ISDIR(md->body->mode)) {
520 CDEBUG(D_INFO, "OBD_MD_FLDIREA set, should be a "
521 "directory, but is not\n");
522 GOTO(out, rc = -EPROTO);
525 if (md->body->eadatasize == 0) {
526 CDEBUG(D_INFO, "OBD_MD_FLDIREA is set, "
527 "but eadatasize 0\n");
530 if (md->body->valid & OBD_MD_MEA) {
531 lmvsize = md->body->eadatasize;
532 lmv = req_capsule_server_sized_get(pill, &RMF_MDT_MD,
535 GOTO(out, rc = -EPROTO);
537 rc = obd_unpackmd(md_exp, (void *)&md->mea, lmv,
542 if (rc < sizeof(*md->mea)) {
543 CDEBUG(D_INFO, "size too small: "
544 "rc < sizeof(*md->mea) (%d < %d)\n",
545 rc, (int)sizeof(*md->mea));
546 GOTO(out, rc = -EPROTO);
552 if (md->body->valid & OBD_MD_FLRMTPERM) {
553 /* remote permission */
554 LASSERT(client_is_remote(exp));
555 md->remote_perm = req_capsule_server_swab_get(pill, &RMF_ACL,
556 lustre_swab_mdt_remote_perm);
557 if (!md->remote_perm)
558 GOTO(out, rc = -EPROTO);
560 else if (md->body->valid & OBD_MD_FLACL) {
561 /* for ACL, it's possible that FLACL is set but aclsize is zero.
562 * only when aclsize != 0 there's an actual segment for ACL
565 if (md->body->aclsize) {
566 rc = mdc_unpack_acl(req, md);
569 #ifdef CONFIG_FS_POSIX_ACL
571 md->posix_acl = NULL;
575 if (md->body->valid & OBD_MD_FLMDSCAPA) {
576 struct obd_capa *oc = NULL;
578 rc = mdc_unpack_capa(NULL, req, &RMF_CAPA1, &oc);
584 if (md->body->valid & OBD_MD_FLOSSCAPA) {
585 struct obd_capa *oc = NULL;
587 rc = mdc_unpack_capa(NULL, req, &RMF_CAPA2, &oc);
597 capa_put(md->oss_capa);
601 capa_put(md->mds_capa);
604 #ifdef CONFIG_FS_POSIX_ACL
605 posix_acl_release(md->posix_acl);
608 obd_free_memmd(dt_exp, &md->lsm);
613 int mdc_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
619 static void mdc_replay_open(struct ptlrpc_request *req)
621 struct md_open_data *mod = req->rq_cb_data;
622 struct ptlrpc_request *cur, *tmp;
623 struct obd_client_handle *och;
624 struct lustre_handle old;
625 struct mdt_body *body;
629 DEBUG_REQ(D_ERROR, req,
630 "Can't properly replay without open data.");
635 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
636 LASSERT(body != NULL);
640 struct lustre_handle *file_fh;
642 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
644 file_fh = &och->och_fh;
645 CDEBUG(D_HA, "updating handle from "LPX64" to "LPX64"\n",
646 file_fh->cookie, body->handle.cookie);
648 *file_fh = body->handle;
650 list_for_each_entry_safe(cur, tmp, &mod->mod_replay_list, rq_mod_list) {
651 int opc = lustre_msg_get_opc(cur->rq_reqmsg);
652 struct mdt_epoch *epoch = NULL;
654 if (opc == MDS_CLOSE || opc == MDS_DONE_WRITING) {
655 epoch = req_capsule_client_get(&cur->rq_pill,
658 DEBUG_REQ(D_HA, cur, "updating %s body with new fh",
659 opc == MDS_CLOSE ? "CLOSE" : "DONE_WRITING");
660 } else if (opc == MDS_REINT) {
661 struct mdt_rec_setattr *rec;
663 /* Check this is REINT_SETATTR. */
664 rec = req_capsule_client_get(&cur->rq_pill,
666 LASSERT(rec && rec->sa_opcode == REINT_SETATTR);
668 epoch = req_capsule_client_get(&cur->rq_pill,
671 DEBUG_REQ(D_HA, cur, "updating REINT_SETATTR body "
676 LASSERT(!memcmp(&old, &epoch->handle,
678 epoch->handle = body->handle;
684 void mdc_commit_delayed(struct ptlrpc_request *req)
686 struct md_open_data *mod = req->rq_cb_data;
687 struct ptlrpc_request *cur, *tmp;
689 DEBUG_REQ(D_HA, req, "req committed");
694 req->rq_cb_data = NULL;
695 req->rq_commit_cb = NULL;
696 list_del_init(&req->rq_mod_list);
697 if (req->rq_sequence) {
698 list_for_each_entry_safe(cur, tmp, &mod->mod_replay_list,
700 LASSERT(cur != LP_POISON);
701 LASSERT(cur->rq_type != LI_POISON);
702 DEBUG_REQ(D_HA, cur, "req balanced");
703 LASSERT(cur->rq_transno != 0);
704 LASSERT(cur->rq_import == req->rq_import);
706 /* We no longer want to preserve this for transno-
707 * unconditional replay. */
708 spin_lock(&cur->rq_lock);
710 spin_unlock(&cur->rq_lock);
714 if (list_empty(&mod->mod_replay_list)) {
715 if (mod->mod_och != NULL)
716 mod->mod_och->och_mod = NULL;
722 int mdc_set_open_replay_data(struct obd_export *exp,
723 struct obd_client_handle *och,
724 struct ptlrpc_request *open_req)
726 struct md_open_data *mod;
727 struct mdt_rec_create *rec;
728 struct mdt_body *body;
729 struct obd_import *imp = open_req->rq_import;
732 if (!open_req->rq_replay)
735 rec = req_capsule_client_get(&open_req->rq_pill, &RMF_REC_REINT);
736 body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY);
737 LASSERT(rec != NULL);
738 /* Incoming message in my byte order (it's been swabbed). */
739 /* Outgoing messages always in my byte order. */
740 LASSERT(body != NULL);
742 /* Only if the import is replayable, we set replay_open data */
743 if (och && imp->imp_replayable) {
746 DEBUG_REQ(D_ERROR, open_req,
747 "Can't allocate md_open_data");
750 CFS_INIT_LIST_HEAD(&mod->mod_replay_list);
752 spin_lock(&open_req->rq_lock);
755 open_req->rq_cb_data = mod;
756 list_add_tail(&open_req->rq_mod_list, &mod->mod_replay_list);
757 open_req->rq_commit_cb = mdc_commit_delayed;
758 spin_unlock(&open_req->rq_lock);
761 rec->cr_fid2 = body->fid1;
762 rec->cr_ioepoch = body->ioepoch;
763 rec->cr_old_handle.cookie = body->handle.cookie;
764 open_req->rq_replay_cb = mdc_replay_open;
765 if (!fid_is_sane(&body->fid1)) {
766 DEBUG_REQ(D_ERROR, open_req, "Saving replay request with "
771 DEBUG_REQ(D_RPCTRACE, open_req, "Set up open replay data");
775 int mdc_clear_open_replay_data(struct obd_export *exp,
776 struct obd_client_handle *och)
778 struct md_open_data *mod = och->och_mod;
782 * Don't free the structure now (it happens in mdc_commit_delayed(),
783 * after the last request is removed from its replay list),
784 * but make sure that replay doesn't poke at the och, which is about to
787 LASSERT(mod != LP_POISON);
795 int mdc_close(struct obd_export *exp, struct md_op_data *op_data,
796 struct md_open_data *mod, struct ptlrpc_request **request)
798 struct obd_device *obd = class_exp2obd(exp);
799 struct ptlrpc_request *req;
804 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_CLOSE);
808 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
810 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_CLOSE);
812 ptlrpc_request_free(req);
816 /* To avoid a livelock (bug 7034), we need to send CLOSE RPCs to a
817 * portal whose threads are not taking any DLM locks and are therefore
818 * always progressing */
819 req->rq_request_portal = MDS_READPAGE_PORTAL;
820 ptlrpc_at_set_req_timeout(req);
822 /* Ensure that this close's handle is fixed up during replay. */
823 if (likely(mod != NULL))
824 list_add_tail(&req->rq_mod_list, &mod->mod_replay_list);
826 CDEBUG(D_HA, "couldn't find open req; expecting close error\n");
828 mdc_close_pack(req, op_data);
830 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER,
831 obd->u.cli.cl_max_mds_easize);
832 req_capsule_set_size(&req->rq_pill, &RMF_LOGCOOKIES, RCL_SERVER,
833 obd->u.cli.cl_max_mds_cookiesize);
835 ptlrpc_request_set_replen(req);
837 req->rq_commit_cb = mdc_commit_delayed;
839 LASSERT(req->rq_cb_data == NULL);
840 req->rq_cb_data = mod;
842 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
843 rc = ptlrpc_queue_wait(req);
844 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
846 if (req->rq_repmsg == NULL) {
847 CDEBUG(D_RPCTRACE, "request failed to send: %p, %d\n", req,
850 rc = req->rq_status ?: -EIO;
851 } else if (rc == 0 || rc == -EAGAIN) {
852 struct mdt_body *body;
854 rc = lustre_msg_get_status(req->rq_repmsg);
855 if (lustre_msg_get_type(req->rq_repmsg) == PTL_RPC_MSG_ERR) {
856 DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, err "
860 } else if (mod == NULL) {
861 if (req->rq_import->imp_replayable)
862 CERROR("Unexpected: can't find md_open_data,"
863 "but close succeeded with replayable imp"
865 "http://bugzilla.lustre.org/\n");
868 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
874 if (rc != 0 && rc != -EAGAIN && req && req->rq_commit_cb)
875 req->rq_commit_cb(req);
881 int mdc_done_writing(struct obd_export *exp, struct md_op_data *op_data,
882 struct md_open_data *mod)
884 struct obd_device *obd = class_exp2obd(exp);
885 struct ptlrpc_request *req;
889 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
890 &RQF_MDS_DONE_WRITING);
894 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
895 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_DONE_WRITING);
897 ptlrpc_request_free(req);
901 /* XXX: add DONE_WRITING request to och -- when Size-on-MDS
902 * recovery will be ready. */
903 mdc_close_pack(req, op_data);
904 ptlrpc_request_set_replen(req);
906 req->rq_cb_data = mod;
907 req->rq_commit_cb = mdc_commit_delayed;
908 if (likely(mod != NULL))
909 list_add_tail(&req->rq_mod_list, &mod->mod_replay_list);
911 CDEBUG(D_HA, "couldn't find open req; expecting close error\n");
913 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
914 rc = ptlrpc_queue_wait(req);
915 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
917 /* Close the open replay sequence if an error occured or no SOM
918 * attribute update is needed. */
920 ptlrpc_close_replay_seq(req);
922 if (rc && rc != -EAGAIN && req->rq_commit_cb)
923 req->rq_commit_cb(req);
925 ptlrpc_req_finished(req);
929 #ifdef HAVE_SPLIT_SUPPORT
930 int mdc_sendpage(struct obd_export *exp, const struct lu_fid *fid,
931 const struct page *page, int offset)
933 struct ptlrpc_request *req;
934 struct ptlrpc_bulk_desc *desc;
938 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_WRITEPAGE);
942 /* FIXME: capa doesn't support split yet */
943 mdc_set_capa_size(req, &RMF_CAPA1, NULL);
945 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_WRITEPAGE);
947 ptlrpc_request_free(req);
951 req->rq_request_portal = MDS_READPAGE_PORTAL;
952 ptlrpc_at_set_req_timeout(req);
954 desc = ptlrpc_prep_bulk_imp(req, 1, BULK_GET_SOURCE, MDS_BULK_PORTAL);
956 GOTO(out, rc = -ENOMEM);
958 /* NB req now owns desc and will free it when it gets freed. */
959 ptlrpc_prep_bulk_page(desc, (struct page *)page, 0, offset);
960 mdc_readdir_pack(req, 0, offset, fid, NULL);
962 ptlrpc_request_set_replen(req);
963 rc = ptlrpc_queue_wait(req);
967 rc = sptlrpc_cli_unwrap_bulk_write(req, req->rq_bulk);
969 ptlrpc_req_finished(req);
972 EXPORT_SYMBOL(mdc_sendpage);
975 int mdc_readpage(struct obd_export *exp, const struct lu_fid *fid,
976 struct obd_capa *oc, __u64 offset, struct page *page,
977 struct ptlrpc_request **request)
979 struct ptlrpc_request *req;
980 struct ptlrpc_bulk_desc *desc;
985 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_READPAGE);
989 mdc_set_capa_size(req, &RMF_CAPA1, oc);
991 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_READPAGE);
993 ptlrpc_request_free(req);
997 req->rq_request_portal = MDS_READPAGE_PORTAL;
998 ptlrpc_at_set_req_timeout(req);
1000 desc = ptlrpc_prep_bulk_imp(req, 1, BULK_PUT_SINK, MDS_BULK_PORTAL);
1002 ptlrpc_request_free(req);
1006 /* NB req now owns desc and will free it when it gets freed */
1007 ptlrpc_prep_bulk_page(desc, page, 0, CFS_PAGE_SIZE);
1008 mdc_readdir_pack(req, offset, CFS_PAGE_SIZE, fid, oc);
1010 ptlrpc_request_set_replen(req);
1011 rc = ptlrpc_queue_wait(req);
1013 ptlrpc_req_finished(req);
1017 rc = sptlrpc_cli_unwrap_bulk_read(req, req->rq_bulk,
1018 req->rq_bulk->bd_nob_transferred);
1020 ptlrpc_req_finished(req);
1024 if (req->rq_bulk->bd_nob_transferred != CFS_PAGE_SIZE) {
1025 CERROR("Unexpected # bytes transferred: %d (%ld expected)\n",
1026 req->rq_bulk->bd_nob_transferred, CFS_PAGE_SIZE);
1027 ptlrpc_req_finished(req);
1035 static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1036 void *karg, void *uarg)
1038 struct obd_device *obd = exp->exp_obd;
1039 struct obd_ioctl_data *data = karg;
1040 struct obd_import *imp = obd->u.cli.cl_import;
1041 struct llog_ctxt *ctxt;
1045 if (!try_module_get(THIS_MODULE)) {
1046 CERROR("Can't get module. Is it alive?");
1050 case OBD_IOC_CHANGELOG_CLEAR: {
1051 struct changelog_setinfo cs =
1052 {data->ioc_u64_1, data->ioc_u32_1};
1053 rc = obd_set_info_async(exp, strlen(KEY_CHANGELOG_CLEAR),
1054 KEY_CHANGELOG_CLEAR, sizeof(cs), &cs,
1058 case OBD_IOC_CLIENT_RECOVER:
1059 rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1);
1063 case IOC_OSC_SET_ACTIVE:
1064 rc = ptlrpc_set_import_active(imp, data->ioc_offset);
1066 case OBD_IOC_PARSE: {
1067 ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT);
1068 rc = class_config_parse_llog(ctxt, data->ioc_inlbuf1, NULL);
1069 llog_ctxt_put(ctxt);
1073 case OBD_IOC_LLOG_INFO:
1074 case OBD_IOC_LLOG_PRINT: {
1075 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
1076 rc = llog_ioctl(ctxt, cmd, data);
1077 llog_ctxt_put(ctxt);
1081 case OBD_IOC_POLL_QUOTACHECK:
1082 rc = lquota_poll_check(quota_interface, exp,
1083 (struct if_quotacheck *)karg);
1085 case OBD_IOC_PING_TARGET:
1086 rc = ptlrpc_obd_ping(obd);
1089 CERROR("mdc_ioctl(): unrecognised ioctl %#x\n", cmd);
1090 GOTO(out, rc = -ENOTTY);
1093 module_put(THIS_MODULE);
1098 static int do_set_info_async(struct obd_export *exp,
1099 obd_count keylen, void *key,
1100 obd_count vallen, void *val,
1101 struct ptlrpc_request_set *set)
1103 struct obd_import *imp = class_exp2cliimp(exp);
1104 struct ptlrpc_request *req;
1109 req = ptlrpc_request_alloc(imp, &RQF_MDS_SET_INFO);
1113 req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_KEY,
1114 RCL_CLIENT, keylen);
1115 req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_VAL,
1116 RCL_CLIENT, vallen);
1117 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_SET_INFO);
1119 ptlrpc_request_free(req);
1123 tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1124 memcpy(tmp, key, keylen);
1125 tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_VAL);
1126 memcpy(tmp, val, vallen);
1128 ptlrpc_request_set_replen(req);
1131 ptlrpc_set_add_req(set, req);
1132 ptlrpc_check_set(NULL, set);
1134 rc = ptlrpc_queue_wait(req);
1135 ptlrpc_req_finished(req);
1141 int mdc_set_info_async(struct obd_export *exp,
1142 obd_count keylen, void *key,
1143 obd_count vallen, void *val,
1144 struct ptlrpc_request_set *set)
1146 struct obd_import *imp = class_exp2cliimp(exp);
1150 if (KEY_IS(KEY_INIT_RECOV)) {
1151 if (vallen != sizeof(int))
1153 spin_lock(&imp->imp_lock);
1154 imp->imp_initial_recov = *(int *)val;
1155 spin_unlock(&imp->imp_lock);
1156 CDEBUG(D_HA, "%s: set imp_initial_recov = %d\n",
1157 exp->exp_obd->obd_name, imp->imp_initial_recov);
1160 /* Turn off initial_recov after we try all backup servers once */
1161 if (KEY_IS(KEY_INIT_RECOV_BACKUP)) {
1162 if (vallen != sizeof(int))
1164 spin_lock(&imp->imp_lock);
1165 imp->imp_initial_recov_bk = *(int *)val;
1166 if (imp->imp_initial_recov_bk)
1167 imp->imp_initial_recov = 1;
1168 spin_unlock(&imp->imp_lock);
1169 CDEBUG(D_HA, "%s: set imp_initial_recov_bk = %d\n",
1170 exp->exp_obd->obd_name, imp->imp_initial_recov_bk);
1173 if (KEY_IS(KEY_READ_ONLY)) {
1174 if (vallen != sizeof(int))
1177 spin_lock(&imp->imp_lock);
1178 if (*((int *)val)) {
1179 imp->imp_connect_flags_orig |= OBD_CONNECT_RDONLY;
1180 imp->imp_connect_data.ocd_connect_flags |= OBD_CONNECT_RDONLY;
1182 imp->imp_connect_flags_orig &= ~OBD_CONNECT_RDONLY;
1183 imp->imp_connect_data.ocd_connect_flags &= ~OBD_CONNECT_RDONLY;
1185 spin_unlock(&imp->imp_lock);
1187 rc = do_set_info_async(exp, keylen, key, vallen, val, set);
1190 if (KEY_IS(KEY_SPTLRPC_CONF)) {
1191 sptlrpc_conf_client_adapt(exp->exp_obd);
1194 if (KEY_IS(KEY_FLUSH_CTX)) {
1195 sptlrpc_import_flush_my_ctx(imp);
1198 if (KEY_IS(KEY_MDS_CONN)) {
1199 struct obd_import *imp = class_exp2cliimp(exp);
1201 /* mds-mds import */
1202 spin_lock(&imp->imp_lock);
1203 imp->imp_server_timeout = 1;
1204 spin_unlock(&imp->imp_lock);
1205 imp->imp_client->cli_request_portal = MDS_MDS_PORTAL;
1206 CDEBUG(D_OTHER, "%s: timeout / 2\n", exp->exp_obd->obd_name);
1209 if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
1210 rc = do_set_info_async(exp, keylen, key, vallen, val, set);
1217 int mdc_get_info(struct obd_export *exp, __u32 keylen, void *key,
1218 __u32 *vallen, void *val, struct lov_stripe_md *lsm)
1222 if (KEY_IS(KEY_MAX_EASIZE)) {
1223 int mdsize, *max_easize;
1225 if (*vallen != sizeof(int))
1227 mdsize = *(int*)val;
1228 if (mdsize > exp->exp_obd->u.cli.cl_max_mds_easize)
1229 exp->exp_obd->u.cli.cl_max_mds_easize = mdsize;
1231 *max_easize = exp->exp_obd->u.cli.cl_max_mds_easize;
1234 if (KEY_IS(KEY_CONN_DATA)) {
1235 struct obd_import *imp = class_exp2cliimp(exp);
1236 struct obd_connect_data *data = val;
1238 if (*vallen != sizeof(*data))
1241 *data = imp->imp_connect_data;
1248 static int mdc_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1249 __u64 max_age, __u32 flags)
1251 struct ptlrpc_request *req;
1252 struct obd_statfs *msfs;
1253 struct obd_import *imp = NULL;
1258 /*Since the request might also come from lprocfs, so we need
1259 *sync this with client_disconnect_export Bug15684*/
1260 down_read(&obd->u.cli.cl_sem);
1261 if (obd->u.cli.cl_import)
1262 imp = class_import_get(obd->u.cli.cl_import);
1263 up_read(&obd->u.cli.cl_sem);
1267 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_STATFS,
1268 LUSTRE_MDS_VERSION, MDS_STATFS);
1270 GOTO(output, rc = -ENOMEM);
1272 ptlrpc_request_set_replen(req);
1274 if (flags & OBD_STATFS_NODELAY) {
1275 /* procfs requests not want stay in wait for avoid deadlock */
1276 req->rq_no_resend = 1;
1277 req->rq_no_delay = 1;
1280 rc = ptlrpc_queue_wait(req);
1282 /* check connection error first */
1283 if (imp->imp_connect_error)
1284 rc = imp->imp_connect_error;
1288 msfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
1290 GOTO(out, rc = -EPROTO);
1295 ptlrpc_req_finished(req);
1297 class_import_put(imp);
1301 static int mdc_pin(struct obd_export *exp, const struct lu_fid *fid,
1302 struct obd_capa *oc, struct obd_client_handle *handle,
1305 struct ptlrpc_request *req;
1306 struct mdt_body *body;
1310 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_PIN);
1314 mdc_set_capa_size(req, &RMF_CAPA1, oc);
1316 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_PIN);
1318 ptlrpc_request_free(req);
1322 mdc_pack_body(req, fid, oc, 0, 0, -1, flags);
1324 ptlrpc_request_set_replen(req);
1326 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1327 rc = ptlrpc_queue_wait(req);
1328 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1330 CERROR("Pin failed: %d\n", rc);
1334 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1336 GOTO(err_out, rc = -EPROTO);
1338 handle->och_fh = body->handle;
1339 handle->och_magic = OBD_CLIENT_HANDLE_MAGIC;
1341 OBD_ALLOC_PTR(handle->och_mod);
1342 if (handle->och_mod == NULL) {
1343 DEBUG_REQ(D_ERROR, req, "can't allocate mdc_open_data");
1344 GOTO(err_out, rc = -ENOMEM);
1346 /* will be dropped by unpin */
1347 CFS_INIT_LIST_HEAD(&handle->och_mod->mod_replay_list);
1348 list_add_tail(&req->rq_mod_list, &handle->och_mod->mod_replay_list);
1353 ptlrpc_req_finished(req);
1357 static int mdc_unpin(struct obd_export *exp, struct obd_client_handle *handle,
1360 struct ptlrpc_request *req;
1361 struct mdt_body *body;
1365 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_UNPIN,
1366 LUSTRE_MDS_VERSION, MDS_UNPIN);
1370 body = req_capsule_client_get(&req->rq_pill, &RMF_MDT_BODY);
1371 body->handle = handle->och_fh;
1374 ptlrpc_request_set_replen(req);
1376 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1377 rc = ptlrpc_queue_wait(req);
1378 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1381 CERROR("Unpin failed: %d\n", rc);
1383 ptlrpc_req_finished(req);
1385 LASSERT(!list_empty(&handle->och_mod->mod_replay_list));
1386 req = list_entry(handle->och_mod->mod_replay_list.next,
1387 typeof(*req), rq_mod_list);
1388 list_del_init(&req->rq_mod_list);
1389 ptlrpc_req_finished(req);
1390 LASSERT(list_empty(&handle->och_mod->mod_replay_list));
1392 OBD_FREE(handle->och_mod, sizeof(*handle->och_mod));
1396 int mdc_sync(struct obd_export *exp, const struct lu_fid *fid,
1397 struct obd_capa *oc, struct ptlrpc_request **request)
1399 struct ptlrpc_request *req;
1404 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_SYNC);
1408 mdc_set_capa_size(req, &RMF_CAPA1, oc);
1410 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_SYNC);
1412 ptlrpc_request_free(req);
1416 mdc_pack_body(req, fid, oc, 0, 0, -1, 0);
1418 ptlrpc_request_set_replen(req);
1420 rc = ptlrpc_queue_wait(req);
1422 ptlrpc_req_finished(req);
1428 static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
1429 enum obd_import_event event)
1433 LASSERT(imp->imp_obd == obd);
1436 case IMP_EVENT_DISCON: {
1438 /* XXX Pass event up to OBDs stack. used only for FLD now */
1439 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_DISCON, NULL);
1443 case IMP_EVENT_INACTIVE: {
1444 struct client_obd *cli = &obd->u.cli;
1446 * Flush current sequence to make client obtain new one
1447 * from server in case of disconnect/reconnect.
1448 * If range is already empty then no need to flush it.
1450 if (cli->cl_seq != NULL &&
1451 !range_is_exhausted(&cli->cl_seq->lcs_space)) {
1452 seq_client_flush(cli->cl_seq);
1455 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_INACTIVE, NULL);
1458 case IMP_EVENT_INVALIDATE: {
1459 struct ldlm_namespace *ns = obd->obd_namespace;
1461 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
1465 case IMP_EVENT_ACTIVE: {
1466 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_ACTIVE, NULL);
1470 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_OCD, NULL);
1474 CERROR("Unknown import event %x\n", event);
1480 static int mdc_fid_init(struct obd_export *exp)
1482 struct client_obd *cli = &exp->exp_obd->u.cli;
1487 OBD_ALLOC_PTR(cli->cl_seq);
1488 if (cli->cl_seq == NULL)
1491 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
1493 GOTO(out_free_seq, rc = -ENOMEM);
1495 snprintf(prefix, MAX_OBD_NAME + 5, "srv-%s",
1496 exp->exp_obd->obd_name);
1498 /* Init client side sequence-manager */
1499 rc = seq_client_init(cli->cl_seq, exp,
1500 LUSTRE_SEQ_METADATA,
1502 OBD_FREE(prefix, MAX_OBD_NAME + 5);
1504 GOTO(out_free_seq, rc);
1508 OBD_FREE_PTR(cli->cl_seq);
1513 static int mdc_fid_fini(struct obd_export *exp)
1515 struct client_obd *cli = &exp->exp_obd->u.cli;
1518 if (cli->cl_seq != NULL) {
1519 seq_client_fini(cli->cl_seq);
1520 OBD_FREE_PTR(cli->cl_seq);
1527 int mdc_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
1528 struct md_op_data *op_data)
1530 struct client_obd *cli = &exp->exp_obd->u.cli;
1531 struct lu_client_seq *seq = cli->cl_seq;
1533 RETURN(seq_client_alloc_fid(seq, fid));
1536 /* XXX This method is used only to clear current fid seq
1537 * once fld/mds insert failed */
1538 static int mdc_fid_delete(struct obd_export *exp, const struct lu_fid *fid)
1540 struct client_obd *cli = &exp->exp_obd->u.cli;
1542 seq_client_flush(cli->cl_seq);
1546 struct obd_uuid *mdc_get_uuid(struct obd_export *exp) {
1547 struct client_obd *cli = &exp->exp_obd->u.cli;
1548 return &cli->cl_target_uuid;
1551 static int mdc_setup(struct obd_device *obd, struct lustre_cfg *cfg)
1553 struct client_obd *cli = &obd->u.cli;
1554 struct lprocfs_static_vars lvars = { 0 };
1558 OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1559 if (!cli->cl_rpc_lock)
1561 mdc_init_rpc_lock(cli->cl_rpc_lock);
1565 OBD_ALLOC(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1566 if (!cli->cl_setattr_lock)
1567 GOTO(err_rpc_lock, rc = -ENOMEM);
1568 mdc_init_rpc_lock(cli->cl_setattr_lock);
1570 OBD_ALLOC(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1571 if (!cli->cl_close_lock)
1572 GOTO(err_setattr_lock, rc = -ENOMEM);
1573 mdc_init_rpc_lock(cli->cl_close_lock);
1575 rc = client_obd_setup(obd, cfg);
1577 GOTO(err_close_lock, rc);
1578 lprocfs_mdc_init_vars(&lvars);
1579 lprocfs_obd_setup(obd, lvars.obd_vars);
1580 sptlrpc_lprocfs_cliobd_attach(obd);
1581 ptlrpc_lprocfs_register_obd(obd);
1583 rc = obd_llog_init(obd, &obd->obd_olg, obd, 0, NULL, NULL);
1586 CERROR("failed to setup llogging subsystems\n");
1592 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1594 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1596 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1601 /* Initialize the default and maximum LOV EA and cookie sizes. This allows
1602 * us to make MDS RPCs with large enough reply buffers to hold the
1603 * maximum-sized (= maximum striped) EA and cookie without having to
1604 * calculate this (via a call into the LOV + OSCs) each time we make an RPC. */
1605 static int mdc_init_ea_size(struct obd_export *exp, int easize,
1606 int def_easize, int cookiesize)
1608 struct obd_device *obd = exp->exp_obd;
1609 struct client_obd *cli = &obd->u.cli;
1612 if (cli->cl_max_mds_easize < easize)
1613 cli->cl_max_mds_easize = easize;
1615 if (cli->cl_default_mds_easize < def_easize)
1616 cli->cl_default_mds_easize = def_easize;
1618 if (cli->cl_max_mds_cookiesize < cookiesize)
1619 cli->cl_max_mds_cookiesize = cookiesize;
1624 static int mdc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
1630 case OBD_CLEANUP_EARLY:
1631 case OBD_CLEANUP_EXPORTS:
1632 /* If we set up but never connected, the
1633 client import will not have been cleaned. */
1634 if (obd->u.cli.cl_import) {
1635 struct obd_import *imp;
1636 down_write(&obd->u.cli.cl_sem);
1637 imp = obd->u.cli.cl_import;
1638 CERROR("client import never connected\n");
1639 ptlrpc_invalidate_import(imp);
1640 class_destroy_import(imp);
1641 up_write(&obd->u.cli.cl_sem);
1642 obd->u.cli.cl_import = NULL;
1644 rc = obd_llog_finish(obd, 0);
1646 CERROR("failed to cleanup llogging subsystems\n");
1652 static int mdc_cleanup(struct obd_device *obd)
1654 struct client_obd *cli = &obd->u.cli;
1656 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1657 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1658 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1660 ptlrpc_lprocfs_unregister_obd(obd);
1661 lprocfs_obd_cleanup(obd);
1664 return client_obd_cleanup(obd);
1668 static int mdc_llog_init(struct obd_device *obd, struct obd_llog_group *olg,
1669 struct obd_device *tgt, int count,
1670 struct llog_catid *logid, struct obd_uuid *uuid)
1672 struct llog_ctxt *ctxt;
1676 LASSERT(olg == &obd->obd_olg);
1678 rc = llog_setup(obd, olg, LLOG_LOVEA_REPL_CTXT, tgt, 0, NULL,
1682 ctxt = llog_get_context(obd, LLOG_LOVEA_REPL_CTXT);
1683 llog_initiator_connect(ctxt);
1684 llog_ctxt_put(ctxt);
1686 rc = llog_setup(obd, olg, LLOG_CHANGELOG_REPL_CTXT, tgt, 0, NULL,
1689 ctxt = llog_group_get_ctxt(olg, LLOG_CHANGELOG_REPL_CTXT);
1690 llog_initiator_connect(ctxt);
1691 llog_ctxt_put(ctxt);
1697 static int mdc_llog_finish(struct obd_device *obd, int count)
1699 struct llog_ctxt *ctxt;
1703 ctxt = llog_get_context(obd, LLOG_LOVEA_REPL_CTXT);
1705 rc = llog_cleanup(ctxt);
1707 ctxt = llog_get_context(obd, LLOG_CHANGELOG_REPL_CTXT);
1709 rc = llog_cleanup(ctxt);
1714 static int mdc_process_config(struct obd_device *obd, obd_count len, void *buf)
1716 struct lustre_cfg *lcfg = buf;
1717 struct lprocfs_static_vars lvars = { 0 };
1720 lprocfs_mdc_init_vars(&lvars);
1721 switch (lcfg->lcfg_command) {
1723 rc = class_process_proc_param(PARAM_MDC, lvars.obd_vars,
1733 /* get remote permission for current user on fid */
1734 int mdc_get_remote_perm(struct obd_export *exp, const struct lu_fid *fid,
1735 struct obd_capa *oc, __u32 suppgid,
1736 struct ptlrpc_request **request)
1738 struct ptlrpc_request *req;
1742 LASSERT(client_is_remote(exp));
1745 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR);
1749 mdc_set_capa_size(req, &RMF_CAPA1, oc);
1751 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR);
1753 ptlrpc_request_free(req);
1757 mdc_pack_body(req, fid, oc, OBD_MD_FLRMTPERM, 0, suppgid, 0);
1759 req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER,
1760 sizeof(struct mdt_remote_perm));
1762 ptlrpc_request_set_replen(req);
1764 rc = ptlrpc_queue_wait(req);
1766 ptlrpc_req_finished(req);
1772 static int mdc_interpret_renew_capa(const struct lu_env *env,
1773 struct ptlrpc_request *req, void *unused,
1776 struct obd_capa *oc = req->rq_async_args.pointer_arg[0];
1777 renew_capa_cb_t cb = req->rq_async_args.pointer_arg[1];
1778 struct mdt_body *body = NULL;
1779 struct lustre_capa *capa;
1783 GOTO(out, capa = ERR_PTR(status));
1785 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1787 GOTO(out, capa = ERR_PTR(-EFAULT));
1789 if ((body->valid & OBD_MD_FLOSSCAPA) == 0)
1790 GOTO(out, capa = ERR_PTR(-ENOENT));
1792 capa = req_capsule_server_get(&req->rq_pill, &RMF_CAPA2);
1794 GOTO(out, capa = ERR_PTR(-EFAULT));
1801 static int mdc_renew_capa(struct obd_export *exp, struct obd_capa *oc,
1804 struct ptlrpc_request *req;
1807 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_GETATTR,
1808 LUSTRE_MDS_VERSION, MDS_GETATTR);
1812 /* NB, OBD_MD_FLOSSCAPA is set here, but it doesn't necessarily mean the
1813 * capa to renew is oss capa.
1815 mdc_pack_body(req, &oc->c_capa.lc_fid, oc, OBD_MD_FLOSSCAPA, 0, -1, 0);
1816 ptlrpc_request_set_replen(req);
1818 req->rq_async_args.pointer_arg[0] = oc;
1819 req->rq_async_args.pointer_arg[1] = cb;
1820 req->rq_interpret_reply = mdc_interpret_renew_capa;
1821 ptlrpcd_add_req(req, PSCOPE_OTHER);
1825 static int mdc_connect(const struct lu_env *env,
1826 struct obd_export **exp,
1827 struct obd_device *obd, struct obd_uuid *cluuid,
1828 struct obd_connect_data *data,
1831 struct obd_import *imp = obd->u.cli.cl_import;
1833 /* mds-mds import features */
1834 if (data && (data->ocd_connect_flags & OBD_CONNECT_MDS_MDS)) {
1835 spin_lock(&imp->imp_lock);
1836 imp->imp_server_timeout = 1;
1837 spin_unlock(&imp->imp_lock);
1838 imp->imp_client->cli_request_portal = MDS_MDS_PORTAL;
1839 CDEBUG(D_OTHER, "%s: Set 'mds' portal and timeout\n",
1843 return client_connect_import(env, exp, obd, cluuid, data, NULL);
1846 struct obd_ops mdc_obd_ops = {
1847 .o_owner = THIS_MODULE,
1848 .o_setup = mdc_setup,
1849 .o_precleanup = mdc_precleanup,
1850 .o_cleanup = mdc_cleanup,
1851 .o_add_conn = client_import_add_conn,
1852 .o_del_conn = client_import_del_conn,
1853 .o_connect = mdc_connect,
1854 .o_disconnect = client_disconnect_export,
1855 .o_iocontrol = mdc_iocontrol,
1856 .o_set_info_async = mdc_set_info_async,
1857 .o_statfs = mdc_statfs,
1859 .o_unpin = mdc_unpin,
1860 .o_fid_init = mdc_fid_init,
1861 .o_fid_fini = mdc_fid_fini,
1862 .o_fid_alloc = mdc_fid_alloc,
1863 .o_fid_delete = mdc_fid_delete,
1864 .o_import_event = mdc_import_event,
1865 .o_llog_init = mdc_llog_init,
1866 .o_llog_finish = mdc_llog_finish,
1867 .o_get_info = mdc_get_info,
1868 .o_process_config = mdc_process_config,
1869 .o_get_uuid = mdc_get_uuid,
1872 struct md_ops mdc_md_ops = {
1873 .m_getstatus = mdc_getstatus,
1874 .m_change_cbdata = mdc_change_cbdata,
1875 .m_close = mdc_close,
1876 .m_create = mdc_create,
1877 .m_done_writing = mdc_done_writing,
1878 .m_enqueue = mdc_enqueue,
1879 .m_getattr = mdc_getattr,
1880 .m_getattr_name = mdc_getattr_name,
1881 .m_intent_lock = mdc_intent_lock,
1883 .m_is_subdir = mdc_is_subdir,
1884 .m_rename = mdc_rename,
1885 .m_setattr = mdc_setattr,
1886 .m_setxattr = mdc_setxattr,
1887 .m_getxattr = mdc_getxattr,
1889 .m_readpage = mdc_readpage,
1890 .m_unlink = mdc_unlink,
1891 .m_cancel_unused = mdc_cancel_unused,
1892 .m_init_ea_size = mdc_init_ea_size,
1893 .m_set_lock_data = mdc_set_lock_data,
1894 .m_lock_match = mdc_lock_match,
1895 .m_get_lustre_md = mdc_get_lustre_md,
1896 .m_free_lustre_md = mdc_free_lustre_md,
1897 .m_set_open_replay_data = mdc_set_open_replay_data,
1898 .m_clear_open_replay_data = mdc_clear_open_replay_data,
1899 .m_renew_capa = mdc_renew_capa,
1900 .m_unpack_capa = mdc_unpack_capa,
1901 .m_get_remote_perm = mdc_get_remote_perm,
1902 .m_intent_getattr_async = mdc_intent_getattr_async,
1903 .m_revalidate_lock = mdc_revalidate_lock
1906 int __init mdc_init(void)
1909 struct lprocfs_static_vars lvars = { 0 };
1910 lprocfs_mdc_init_vars(&lvars);
1912 request_module("lquota");
1913 quota_interface = PORTAL_SYMBOL_GET(mdc_quota_interface);
1914 init_obd_quota_ops(quota_interface, &mdc_obd_ops);
1916 rc = class_register_type(&mdc_obd_ops, &mdc_md_ops, lvars.module_vars,
1917 LUSTRE_MDC_NAME, NULL);
1918 if (rc && quota_interface)
1919 PORTAL_SYMBOL_PUT(mdc_quota_interface);
1925 static void /*__exit*/ mdc_exit(void)
1927 if (quota_interface)
1928 PORTAL_SYMBOL_PUT(mdc_quota_interface);
1930 class_unregister_type(LUSTRE_MDC_NAME);
1933 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
1934 MODULE_DESCRIPTION("Lustre Metadata Client");
1935 MODULE_LICENSE("GPL");
1937 module_init(mdc_init);
1938 module_exit(mdc_exit);