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 the Lustre file system, http://www.lustre.org
7 * Lustre is a trademark of Cluster File Systems, Inc.
9 * You may have signed or agreed to another license before downloading
10 * this software. If so, you are bound by the terms and conditions
11 * of that agreement, and the following does not apply to you. See the
12 * LICENSE file included with this distribution for more information.
14 * If you did not agree to a different license, then this copy of Lustre
15 * is open source software; you can redistribute it and/or modify it
16 * under the terms of version 2 of the GNU General Public License as
17 * published by the Free Software Foundation.
19 * In either case, Lustre is distributed in the hope that it will be
20 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
21 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * license text for more details.
26 # define EXPORT_SYMTAB
28 #define DEBUG_SUBSYSTEM S_MDC
31 # include <linux/module.h>
32 # include <linux/pagemap.h>
33 # include <linux/miscdevice.h>
34 # include <linux/init.h>
36 # include <liblustre.h>
39 #include <linux/lustre_acl.h>
40 #include <obd_class.h>
41 #include <lustre_dlm.h>
42 #include <lustre_fid.h>
43 #include <md_object.h>
44 #include <lprocfs_status.h>
45 #include <lustre_param.h>
46 #include "mdc_internal.h"
48 static quota_interface_t *quota_interface;
50 #define REQUEST_MINOR 244
52 static quota_interface_t *quota_interface;
53 extern quota_interface_t mdc_quota_interface;
55 static int mdc_cleanup(struct obd_device *obd);
57 static struct obd_capa *mdc_unpack_capa(struct ptlrpc_request *req,
58 const struct req_msg_field *field)
60 struct lustre_capa *capa;
63 /* swabbed already in mdc_enqueue */
64 capa = req_capsule_server_get(&req->rq_pill, field);
66 return ERR_PTR(-EPROTO);
68 oc = alloc_capa(CAPA_SITE_CLIENT);
70 CDEBUG(D_INFO, "alloc capa failed!\n");
71 return ERR_PTR(-ENOMEM);
78 /* Helper that implements most of mdc_getstatus and signal_completed_replay. */
79 /* XXX this should become mdc_get_info("key"), sending MDS_GET_INFO RPC */
80 static int send_getstatus(struct obd_import *imp, struct lu_fid *rootfid,
81 struct obd_capa **pc, int level, int msg_flags)
83 struct ptlrpc_request *req;
84 struct mdt_body *body;
88 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_GETSTATUS,
89 LUSTRE_MDS_VERSION, MDS_GETSTATUS);
93 mdc_pack_body(req, NULL, NULL, 0, 0, -1, 0);
94 lustre_msg_add_flags(req->rq_reqmsg, msg_flags);
95 req->rq_send_state = level;
97 ptlrpc_request_set_replen(req);
99 rc = ptlrpc_queue_wait(req);
103 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
105 GOTO(out, rc = -EPROTO);
107 if (body->valid & OBD_MD_FLMDSCAPA) {
110 oc = mdc_unpack_capa(req, &RMF_CAPA1);
112 GOTO(out, rc = PTR_ERR(oc));
116 *rootfid = body->fid1;
118 "root fid="DFID", last_committed="LPU64", last_xid="LPU64"\n",
120 lustre_msg_get_last_committed(req->rq_repmsg),
121 lustre_msg_get_last_xid(req->rq_repmsg));
124 ptlrpc_req_finished(req);
128 /* This should be mdc_get_info("rootfid") */
129 int mdc_getstatus(struct obd_export *exp, struct lu_fid *rootfid,
130 struct obd_capa **pc)
132 return send_getstatus(class_exp2cliimp(exp), rootfid, pc,
137 * This function now is known to always saying that it will receive 4 buffers
138 * from server. Even for cases when acl_size and md_size is zero, RPC header
139 * willcontain 4 fields and RPC itself will contain zero size fields. This is
140 * because mdt_getattr*() _always_ returns 4 fields, but if acl is not needed
141 * and thus zero, it shirinks it, making zero size. The same story about
142 * md_size. And this is course of problem when client waits for smaller number
143 * of fields. This issue will be fixed later when client gets awar of RPC
146 static int mdc_getattr_common(struct obd_export *exp,
147 struct ptlrpc_request *req)
149 struct req_capsule *pill = &req->rq_pill;
150 struct mdt_body *body;
155 /* Request message already built. */
156 rc = ptlrpc_queue_wait(req);
160 /* sanity check for the reply */
161 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
165 CDEBUG(D_NET, "mode: %o\n", body->mode);
167 if (body->eadatasize != 0) {
168 eadata = req_capsule_server_sized_get(pill, &RMF_MDT_MD,
174 if (body->valid & OBD_MD_FLMODEASIZE) {
175 struct client_obd *cli = &exp->exp_obd->u.cli;
177 if (cli->cl_max_mds_easize < body->max_mdsize)
178 cli->cl_max_mds_easize = body->max_mdsize;
179 if (cli->cl_max_mds_cookiesize < body->max_cookiesize)
180 cli->cl_max_mds_cookiesize = body->max_cookiesize;
183 if (body->valid & OBD_MD_FLRMTPERM) {
184 struct mdt_remote_perm *perm;
185 perm = req_capsule_server_get(pill, &RMF_ACL);
190 if (body->valid & OBD_MD_FLMDSCAPA) {
191 struct lustre_capa *capa;
192 capa = req_capsule_server_get(pill, &RMF_CAPA1);
200 int mdc_getattr(struct obd_export *exp, const struct lu_fid *fid,
201 struct obd_capa *oc, obd_valid valid, int ea_size,
202 struct ptlrpc_request **request)
204 struct ptlrpc_request *req;
209 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR);
213 mdc_set_capa_size(req, &RMF_CAPA1, oc);
215 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR);
217 ptlrpc_request_free(req);
221 /* MDS_BFLAG_EXT_FLAGS: request "new" flags(bug 9486) */
222 mdc_pack_body(req, fid, oc, valid, ea_size, -1, MDS_BFLAG_EXT_FLAGS);
224 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER, ea_size);
225 if (valid & OBD_MD_FLRMTPERM)
226 req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER,
227 sizeof(struct mdt_remote_perm));
228 ptlrpc_request_set_replen(req);
230 rc = mdc_getattr_common(exp, req);
232 ptlrpc_req_finished(req);
238 int mdc_getattr_name(struct obd_export *exp, const struct lu_fid *fid,
239 struct obd_capa *oc, const char *filename, int namelen,
240 obd_valid valid, int ea_size, __u32 suppgid,
241 struct ptlrpc_request **request)
243 struct ptlrpc_request *req;
248 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
249 &RQF_MDS_GETATTR_NAME);
253 mdc_set_capa_size(req, &RMF_CAPA1, oc);
254 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT, namelen);
256 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR_NAME);
258 ptlrpc_request_free(req);
262 /* MDS_BFLAG_EXT_FLAGS: request "new" flags(bug 9486) */
263 mdc_pack_body(req, fid, oc, valid, ea_size, suppgid,
264 MDS_BFLAG_EXT_FLAGS);
267 char *name = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
268 LASSERT(strnlen(filename, namelen) == namelen - 1);
269 memcpy(name, filename, namelen);
272 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER, ea_size);
273 ptlrpc_request_set_replen(req);
275 rc = mdc_getattr_common(exp, req);
277 ptlrpc_req_finished(req);
283 static int mdc_is_subdir(struct obd_export *exp,
284 const struct lu_fid *pfid,
285 const struct lu_fid *cfid,
286 struct ptlrpc_request **request)
288 struct ptlrpc_request *req;
294 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
295 &RQF_MDS_IS_SUBDIR, LUSTRE_MDS_VERSION,
300 mdc_is_subdir_pack(req, pfid, cfid, 0);
301 ptlrpc_request_set_replen(req);
303 rc = ptlrpc_queue_wait(req);
304 if (rc && rc != -EREMOTE)
305 ptlrpc_req_finished(req);
311 static int mdc_xattr_common(struct obd_export *exp,const struct req_format *fmt,
312 const struct lu_fid *fid,
313 struct obd_capa *oc, int opcode, obd_valid valid,
314 const char *xattr_name, const char *input,
315 int input_size, int output_size, int flags,
316 __u32 suppgid, struct ptlrpc_request **request)
318 struct ptlrpc_request *req;
319 int xattr_namelen = 0;
325 req = ptlrpc_request_alloc(class_exp2cliimp(exp), fmt);
329 mdc_set_capa_size(req, &RMF_CAPA1, oc);
331 xattr_namelen = strlen(xattr_name) + 1;
332 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
337 req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_CLIENT,
341 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, opcode);
343 ptlrpc_request_free(req);
347 if (opcode == MDS_REINT) {
348 struct mdt_rec_setxattr *rec;
350 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
351 sizeof(struct mdt_rec_reint));
352 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
353 rec->sx_opcode = REINT_SETXATTR;
355 * cfs_curproc_fs{u,g}id() should replace
356 * current->fs{u,g}id for portability.
358 rec->sx_fsuid = current->fsuid;
359 rec->sx_fsgid = current->fsgid;
360 rec->sx_cap = current->cap_effective;
361 rec->sx_suppgid1 = suppgid;
362 rec->sx_suppgid1 = -1;
364 rec->sx_valid = valid;
365 rec->sx_size = output_size;
366 rec->sx_flags = flags;
368 mdc_pack_capa(req, &RMF_CAPA1, oc);
370 mdc_pack_body(req, fid, oc, valid, output_size, suppgid, flags);
374 tmp = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
375 memcpy(tmp, xattr_name, xattr_namelen);
378 tmp = req_capsule_client_get(&req->rq_pill, &RMF_EADATA);
379 memcpy(tmp, input, input_size);
382 if (req_capsule_has_field(&req->rq_pill, &RMF_EADATA, RCL_SERVER))
383 req_capsule_set_size(&req->rq_pill, &RMF_EADATA,
384 RCL_SERVER, output_size);
385 ptlrpc_request_set_replen(req);
388 if (opcode == MDS_REINT)
389 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
391 rc = ptlrpc_queue_wait(req);
393 if (opcode == MDS_REINT)
394 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
397 ptlrpc_req_finished(req);
403 int mdc_setxattr(struct obd_export *exp, const struct lu_fid *fid,
404 struct obd_capa *oc, obd_valid valid, const char *xattr_name,
405 const char *input, int input_size, int output_size,
406 int flags, __u32 suppgid, struct ptlrpc_request **request)
408 return mdc_xattr_common(exp, &RQF_MDS_REINT_SETXATTR,
409 fid, oc, MDS_REINT, valid, xattr_name,
410 input, input_size, output_size, flags,
414 int mdc_getxattr(struct obd_export *exp, const struct lu_fid *fid,
415 struct obd_capa *oc, obd_valid valid, const char *xattr_name,
416 const char *input, int input_size, int output_size,
417 int flags, struct ptlrpc_request **request)
419 return mdc_xattr_common(exp, &RQF_MDS_GETXATTR,
420 fid, oc, MDS_GETXATTR, valid, xattr_name,
421 input, input_size, output_size, flags,
425 #ifdef CONFIG_FS_POSIX_ACL
426 static int mdc_unpack_acl(struct ptlrpc_request *req, struct lustre_md *md)
428 struct req_capsule *pill = &req->rq_pill;
429 struct mdt_body *body = md->body;
430 struct posix_acl *acl;
438 buf = req_capsule_server_sized_get(pill, &RMF_ACL, body->aclsize);
443 acl = posix_acl_from_xattr(buf, body->aclsize);
446 CERROR("convert xattr to acl: %d\n", rc);
450 rc = posix_acl_valid(acl);
452 CERROR("validate acl: %d\n", rc);
453 posix_acl_release(acl);
461 #define mdc_unpack_acl(req, md) 0
464 int mdc_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
465 struct obd_export *dt_exp, struct obd_export *md_exp,
466 struct lustre_md *md)
468 struct req_capsule *pill = &req->rq_pill;
473 memset(md, 0, sizeof(*md));
475 md->body = req_capsule_server_get(pill, &RMF_MDT_BODY);
476 LASSERT(md->body != NULL);
478 if (md->body->valid & OBD_MD_FLEASIZE) {
480 struct lov_mds_md *lmm;
482 if (!S_ISREG(md->body->mode)) {
483 CDEBUG(D_INFO, "OBD_MD_FLEASIZE set, should be a "
484 "regular file, but is not\n");
485 GOTO(out, rc = -EPROTO);
488 if (md->body->eadatasize == 0) {
489 CDEBUG(D_INFO, "OBD_MD_FLEASIZE set, "
490 "but eadatasize 0\n");
491 GOTO(out, rc = -EPROTO);
493 lmmsize = md->body->eadatasize;
494 lmm = req_capsule_server_sized_get(pill, &RMF_MDT_MD, lmmsize);
496 GOTO(out, rc = -EPROTO);
498 rc = obd_unpackmd(dt_exp, &md->lsm, lmm, lmmsize);
502 if (rc < sizeof(*md->lsm)) {
503 CDEBUG(D_INFO, "lsm size too small: "
504 "rc < sizeof (*md->lsm) (%d < "LPSZ")\n",
505 rc, sizeof(*md->lsm));
506 GOTO(out, rc = -EPROTO);
509 } else if (md->body->valid & OBD_MD_FLDIREA) {
511 struct lov_mds_md *lmv;
513 if(!S_ISDIR(md->body->mode)) {
514 CDEBUG(D_INFO, "OBD_MD_FLDIREA set, should be a "
515 "directory, but is not\n");
516 GOTO(out, rc = -EPROTO);
519 if (md->body->eadatasize == 0) {
520 CDEBUG(D_INFO, "OBD_MD_FLDIREA is set, "
521 "but eadatasize 0\n");
524 if (md->body->valid & OBD_MD_MEA) {
525 lmvsize = md->body->eadatasize;
526 lmv = req_capsule_server_sized_get(pill, &RMF_MDT_MD,
529 GOTO(out, rc = -EPROTO);
531 rc = obd_unpackmd(md_exp, (void *)&md->mea, lmv,
536 if (rc < sizeof(*md->mea)) {
537 CDEBUG(D_INFO, "size too small: "
538 "rc < sizeof(*md->mea) (%d < %d)\n",
539 rc, sizeof(*md->mea));
540 GOTO(out, rc = -EPROTO);
546 if (md->body->valid & OBD_MD_FLRMTPERM) {
547 /* remote permission */
548 md->remote_perm = req_capsule_server_get(pill, &RMF_ACL);
549 if (!md->remote_perm)
550 GOTO(out, rc = -EPROTO);
552 else if (md->body->valid & OBD_MD_FLACL) {
553 /* for ACL, it's possible that FLACL is set but aclsize is zero.
554 * only when aclsize != 0 there's an actual segment for ACL
557 if (md->body->aclsize) {
558 rc = mdc_unpack_acl(req, md);
561 #ifdef CONFIG_FS_POSIX_ACL
563 md->posix_acl = NULL;
567 if (md->body->valid & OBD_MD_FLMDSCAPA) {
568 struct obd_capa *oc = mdc_unpack_capa(req, &RMF_CAPA1);
571 GOTO(out, rc = PTR_ERR(oc));
575 if (md->body->valid & OBD_MD_FLOSSCAPA) {
576 struct obd_capa *oc = mdc_unpack_capa(req, &RMF_CAPA2);
579 GOTO(out, rc = PTR_ERR(oc));
587 free_capa(md->oss_capa);
589 free_capa(md->mds_capa);
590 #ifdef CONFIG_FS_POSIX_ACL
591 posix_acl_release(md->posix_acl);
594 obd_free_memmd(dt_exp, &md->lsm);
599 int mdc_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
605 static void mdc_replay_open(struct ptlrpc_request *req)
607 struct md_open_data *mod = req->rq_cb_data;
608 struct ptlrpc_request *cur, *tmp;
609 struct obd_client_handle *och;
610 struct lustre_handle old;
611 struct mdt_body *body;
615 DEBUG_REQ(D_ERROR, req,
616 "Can't properly replay without open data.");
621 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
622 LASSERT(body != NULL);
626 struct lustre_handle *file_fh;
628 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
630 file_fh = &och->och_fh;
631 CDEBUG(D_HA, "updating handle from "LPX64" to "LPX64"\n",
632 file_fh->cookie, body->handle.cookie);
634 *file_fh = body->handle;
636 list_for_each_entry_safe(cur, tmp, &mod->mod_replay_list, rq_mod_list) {
637 int opc = lustre_msg_get_opc(cur->rq_reqmsg);
638 struct mdt_epoch *epoch = NULL;
640 if (opc == MDS_CLOSE || opc == MDS_DONE_WRITING) {
641 epoch = req_capsule_client_get(&cur->rq_pill,
644 DEBUG_REQ(D_HA, cur, "updating %s body with new fh",
645 opc == MDS_CLOSE ? "CLOSE" : "DONE_WRITING");
646 } else if (opc == MDS_REINT) {
647 struct mdt_rec_setattr *rec;
649 /* Check this is REINT_SETATTR. */
650 rec = req_capsule_client_get(&cur->rq_pill,
652 LASSERT(rec && rec->sa_opcode == REINT_SETATTR);
654 epoch = req_capsule_client_get(&cur->rq_pill,
657 DEBUG_REQ(D_HA, cur, "updating REINT_SETATTR body "
662 LASSERT(!memcmp(&old, &epoch->handle,
664 epoch->handle = body->handle;
670 void mdc_commit_delayed(struct ptlrpc_request *req)
672 struct md_open_data *mod = req->rq_cb_data;
673 struct ptlrpc_request *cur, *tmp;
675 DEBUG_REQ(D_HA, req, "req committed");
680 req->rq_cb_data = NULL;
681 req->rq_commit_cb = NULL;
682 list_del_init(&req->rq_mod_list);
683 if (req->rq_sequence) {
684 list_for_each_entry_safe(cur, tmp, &mod->mod_replay_list,
686 LASSERT(cur != LP_POISON);
687 LASSERT(cur->rq_type != LI_POISON);
688 DEBUG_REQ(D_HA, cur, "req balanced");
689 LASSERT(cur->rq_transno != 0);
690 LASSERT(cur->rq_import == req->rq_import);
692 /* We no longer want to preserve this for transno-
693 * unconditional replay. */
694 spin_lock(&cur->rq_lock);
696 spin_unlock(&cur->rq_lock);
700 if (list_empty(&mod->mod_replay_list)) {
701 if (mod->mod_och != NULL)
702 mod->mod_och->och_mod = NULL;
708 int mdc_set_open_replay_data(struct obd_export *exp,
709 struct obd_client_handle *och,
710 struct ptlrpc_request *open_req)
712 struct md_open_data *mod;
713 struct mdt_rec_create *rec;
714 struct mdt_body *body;
715 struct obd_import *imp = open_req->rq_import;
718 rec = req_capsule_client_get(&open_req->rq_pill, &RMF_REC_REINT);
719 body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY);
720 LASSERT(rec != NULL);
721 /* Incoming message in my byte order (it's been swabbed). */
722 /* Outgoing messages always in my byte order. */
723 LASSERT(body != NULL);
725 /*Only the import is replayable, we set replay_open data */
726 if (och && imp->imp_replayable) {
729 DEBUG_REQ(D_ERROR, open_req,
730 "Can't allocate md_open_data");
733 CFS_INIT_LIST_HEAD(&mod->mod_replay_list);
735 spin_lock(&open_req->rq_lock);
736 if (!open_req->rq_replay) {
737 OBD_FREE(mod, sizeof(*mod));
738 spin_unlock(&open_req->rq_lock);
744 open_req->rq_cb_data = mod;
745 list_add_tail(&open_req->rq_mod_list, &mod->mod_replay_list);
746 open_req->rq_commit_cb = mdc_commit_delayed;
747 spin_unlock(&open_req->rq_lock);
750 rec->cr_fid2 = body->fid1;
751 rec->cr_ioepoch = body->ioepoch;
752 rec->cr_old_handle.cookie = body->handle.cookie;
753 open_req->rq_replay_cb = mdc_replay_open;
754 if (!fid_is_sane(&body->fid1)) {
755 DEBUG_REQ(D_ERROR, open_req, "Saving replay request with "
760 DEBUG_REQ(D_RPCTRACE, open_req, "Set up open replay data");
764 int mdc_clear_open_replay_data(struct obd_export *exp,
765 struct obd_client_handle *och)
767 struct md_open_data *mod = och->och_mod;
771 * Don't free the structure now (it happens in mdc_commit_delayed(),
772 * after the last request is removed from its replay list),
773 * but make sure that replay doesn't poke at the och, which is about to
776 LASSERT(mod != LP_POISON);
784 int mdc_close(struct obd_export *exp, struct md_op_data *op_data,
785 struct md_open_data *mod, struct ptlrpc_request **request)
787 struct obd_device *obd = class_exp2obd(exp);
788 struct ptlrpc_request *req;
793 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_CLOSE);
797 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
799 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_CLOSE);
801 ptlrpc_request_free(req);
805 /* To avoid a livelock (bug 7034), we need to send CLOSE RPCs to a
806 * portal whose threads are not taking any DLM locks and are therefore
807 * always progressing */
808 /* XXX FIXME bug 249 */
809 req->rq_request_portal = MDS_READPAGE_PORTAL;
811 /* Ensure that this close's handle is fixed up during replay. */
812 if (likely(mod != NULL))
813 list_add_tail(&req->rq_mod_list, &mod->mod_replay_list);
815 CDEBUG(D_HA, "couldn't find open req; expecting close error\n");
817 mdc_close_pack(req, op_data);
818 ptlrpc_request_set_replen(req);
819 req->rq_commit_cb = mdc_commit_delayed;
821 LASSERT(req->rq_cb_data == NULL);
822 req->rq_cb_data = mod;
824 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
825 rc = ptlrpc_queue_wait(req);
826 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
828 if (req->rq_repmsg == NULL) {
829 CDEBUG(D_RPCTRACE, "request failed to send: %p, %d\n", req,
832 rc = req->rq_status ?: -EIO;
833 } else if (rc == 0 || rc == -EAGAIN) {
834 struct mdt_body *body;
836 rc = lustre_msg_get_status(req->rq_repmsg);
837 if (lustre_msg_get_type(req->rq_repmsg) == PTL_RPC_MSG_ERR) {
838 DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, err "
842 } else if (mod == NULL) {
843 if (req->rq_import->imp_replayable)
844 CERROR("Unexpected: can't find md_open_data,"
845 "but close succeeded with replayable imp"
846 "Please tell CFS.\n");
849 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
855 if (rc != 0 && rc != -EAGAIN && req && req->rq_commit_cb)
856 req->rq_commit_cb(req);
862 int mdc_done_writing(struct obd_export *exp, struct md_op_data *op_data,
863 struct md_open_data *mod)
865 struct obd_device *obd = class_exp2obd(exp);
866 struct ptlrpc_request *req;
870 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
871 &RQF_MDS_DONE_WRITING);
875 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
876 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_DONE_WRITING);
878 ptlrpc_request_free(req);
882 /* XXX: add DONE_WRITING request to och -- when Size-on-MDS
883 * recovery will be ready. */
884 mdc_close_pack(req, op_data);
885 ptlrpc_request_set_replen(req);
887 req->rq_cb_data = mod;
888 req->rq_commit_cb = mdc_commit_delayed;
889 if (likely(mod != NULL))
890 list_add_tail(&req->rq_mod_list, &mod->mod_replay_list);
892 CDEBUG(D_HA, "couldn't find open req; expecting close error\n");
894 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
895 rc = ptlrpc_queue_wait(req);
896 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
898 /* Close the open replay sequence if an error occured or no SOM
899 * attribute update is needed. */
901 ptlrpc_close_replay_seq(req);
903 if (rc && rc != -EAGAIN && req->rq_commit_cb)
904 req->rq_commit_cb(req);
906 ptlrpc_req_finished(req);
910 #ifdef HAVE_SPLIT_SUPPORT
911 int mdc_sendpage(struct obd_export *exp, const struct lu_fid *fid,
912 const struct page *page, int offset)
914 struct ptlrpc_request *req;
915 struct ptlrpc_bulk_desc *desc;
919 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_WRITEPAGE);
923 /* FIXME: capa doesn't support split yet */
924 mdc_set_capa_size(req, &RMF_CAPA1, NULL);
926 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_WRITEPAGE);
928 ptlrpc_request_free(req);
932 req->rq_request_portal = MDS_READPAGE_PORTAL;
934 desc = ptlrpc_prep_bulk_imp(req, 1, BULK_GET_SOURCE, MDS_BULK_PORTAL);
936 GOTO(out, rc = -ENOMEM);
938 /* NB req now owns desc and will free it when it gets freed. */
939 ptlrpc_prep_bulk_page(desc, (struct page *)page, 0, offset);
940 mdc_readdir_pack(req, 0, offset, fid, NULL);
942 ptlrpc_request_set_replen(req);
943 rc = ptlrpc_queue_wait(req);
946 ptlrpc_req_finished(req);
949 EXPORT_SYMBOL(mdc_sendpage);
952 int mdc_readpage(struct obd_export *exp, const struct lu_fid *fid,
953 struct obd_capa *oc, __u64 offset, struct page *page,
954 struct ptlrpc_request **request)
956 struct ptlrpc_request *req;
957 struct ptlrpc_bulk_desc *desc;
962 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_READPAGE);
966 mdc_set_capa_size(req, &RMF_CAPA1, oc);
968 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_READPAGE);
970 ptlrpc_request_free(req);
974 /* XXX FIXME bug 249 */
975 req->rq_request_portal = MDS_READPAGE_PORTAL;
976 desc = ptlrpc_prep_bulk_imp(req, 1, BULK_PUT_SINK, MDS_BULK_PORTAL);
978 ptlrpc_request_free(req);
982 /* NB req now owns desc and will free it when it gets freed */
983 ptlrpc_prep_bulk_page(desc, page, 0, CFS_PAGE_SIZE);
984 mdc_readdir_pack(req, offset, CFS_PAGE_SIZE, fid, oc);
986 ptlrpc_request_set_replen(req);
987 rc = ptlrpc_queue_wait(req);
989 ptlrpc_req_finished(req);
993 if (req->rq_bulk->bd_nob_transferred != CFS_PAGE_SIZE) {
994 CERROR("Unexpected # bytes transferred: %d (%ld expected)\n",
995 req->rq_bulk->bd_nob_transferred, CFS_PAGE_SIZE);
996 ptlrpc_req_finished(req);
1004 static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1005 void *karg, void *uarg)
1007 struct obd_device *obd = exp->exp_obd;
1008 struct obd_ioctl_data *data = karg;
1009 struct obd_import *imp = obd->u.cli.cl_import;
1010 struct llog_ctxt *ctxt;
1014 if (!try_module_get(THIS_MODULE)) {
1015 CERROR("Can't get module. Is it alive?");
1019 case OBD_IOC_CLIENT_RECOVER:
1020 rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1);
1024 case IOC_OSC_SET_ACTIVE:
1025 rc = ptlrpc_set_import_active(imp, data->ioc_offset);
1027 case OBD_IOC_PARSE: {
1028 ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT);
1029 rc = class_config_parse_llog(ctxt, data->ioc_inlbuf1, NULL);
1033 case OBD_IOC_LLOG_INFO:
1034 case OBD_IOC_LLOG_PRINT: {
1035 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
1036 rc = llog_ioctl(ctxt, cmd, data);
1041 case OBD_IOC_POLL_QUOTACHECK:
1042 rc = lquota_poll_check(quota_interface, exp,
1043 (struct if_quotacheck *)karg);
1046 CERROR("mdc_ioctl(): unrecognised ioctl %#x\n", cmd);
1047 GOTO(out, rc = -ENOTTY);
1050 module_put(THIS_MODULE);
1055 static int do_set_info_async(struct obd_export *exp,
1056 obd_count keylen, void *key,
1057 obd_count vallen, void *val,
1058 struct ptlrpc_request_set *set)
1060 struct obd_import *imp = class_exp2cliimp(exp);
1061 struct ptlrpc_request *req;
1066 if (vallen != sizeof(int))
1069 spin_lock(&imp->imp_lock);
1070 if (*((int *)val)) {
1071 imp->imp_connect_flags_orig |= OBD_CONNECT_RDONLY;
1072 imp->imp_connect_data.ocd_connect_flags |= OBD_CONNECT_RDONLY;
1074 imp->imp_connect_flags_orig &= ~OBD_CONNECT_RDONLY;
1075 imp->imp_connect_data.ocd_connect_flags &= ~OBD_CONNECT_RDONLY;
1077 spin_unlock(&imp->imp_lock);
1079 req = ptlrpc_request_alloc(imp, &RQF_MDS_SET_INFO);
1083 req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_KEY,
1084 RCL_CLIENT, keylen);
1085 req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_VAL,
1086 RCL_CLIENT, vallen);
1087 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_SET_INFO);
1089 ptlrpc_request_free(req);
1093 tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1094 memcpy(tmp, key, keylen);
1095 tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_VAL);
1096 memcpy(tmp, val, vallen);
1098 ptlrpc_request_set_replen(req);
1101 ptlrpc_set_add_req(set, req);
1102 ptlrpc_check_set(set);
1104 rc = ptlrpc_queue_wait(req);
1105 ptlrpc_req_finished(req);
1111 int mdc_set_info_async(struct obd_export *exp,
1112 obd_count keylen, void *key,
1113 obd_count vallen, void *val,
1114 struct ptlrpc_request_set *set)
1116 struct obd_import *imp = class_exp2cliimp(exp);
1120 if (KEY_IS(KEY_INIT_RECOV)) {
1121 if (vallen != sizeof(int))
1123 spin_lock(&imp->imp_lock);
1124 imp->imp_initial_recov = *(int *)val;
1125 spin_unlock(&imp->imp_lock);
1126 CDEBUG(D_HA, "%s: set imp_initial_recov = %d\n",
1127 exp->exp_obd->obd_name, imp->imp_initial_recov);
1130 /* Turn off initial_recov after we try all backup servers once */
1131 if (KEY_IS(KEY_INIT_RECOV_BACKUP)) {
1132 if (vallen != sizeof(int))
1134 spin_lock(&imp->imp_lock);
1135 imp->imp_initial_recov_bk = *(int *)val;
1136 if (imp->imp_initial_recov_bk)
1137 imp->imp_initial_recov = 1;
1138 spin_unlock(&imp->imp_lock);
1139 CDEBUG(D_HA, "%s: set imp_initial_recov_bk = %d\n",
1140 exp->exp_obd->obd_name, imp->imp_initial_recov_bk);
1143 if (KEY_IS(KEY_READ_ONLY)) {
1144 rc = do_set_info_async(exp, keylen, key, vallen, val, set);
1147 if (KEY_IS(KEY_FLUSH_CTX)) {
1148 sptlrpc_import_flush_my_ctx(imp);
1151 if (KEY_IS(KEY_MDS_CONN)) {
1152 struct obd_import *imp = class_exp2cliimp(exp);
1154 /* mds-mds import */
1155 spin_lock(&imp->imp_lock);
1156 imp->imp_server_timeout = 1;
1157 spin_unlock(&imp->imp_lock);
1158 imp->imp_client->cli_request_portal = MDS_MDS_PORTAL;
1159 CDEBUG(D_OTHER|D_WARNING, "%s: timeout / 2\n", exp->exp_obd->obd_name);
1166 int mdc_get_info(struct obd_export *exp, __u32 keylen, void *key,
1167 __u32 *vallen, void *val)
1171 if (KEY_IS(KEY_MAX_EASIZE)) {
1172 int mdsize, *max_easize;
1174 if (*vallen != sizeof(int))
1176 mdsize = *(int*)val;
1177 if (mdsize > exp->exp_obd->u.cli.cl_max_mds_easize)
1178 exp->exp_obd->u.cli.cl_max_mds_easize = mdsize;
1180 *max_easize = exp->exp_obd->u.cli.cl_max_mds_easize;
1183 if (KEY_IS(KEY_CONN_DATA)) {
1184 struct obd_import *imp = class_exp2cliimp(exp);
1185 struct obd_connect_data *data = val;
1187 if (*vallen != sizeof(*data))
1190 *data = imp->imp_connect_data;
1197 static int mdc_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1200 struct ptlrpc_request *req;
1201 struct obd_statfs *msfs;
1205 req = ptlrpc_request_alloc_pack(obd->u.cli.cl_import, &RQF_MDS_STATFS,
1206 LUSTRE_MDS_VERSION, MDS_STATFS);
1210 ptlrpc_request_set_replen(req);
1212 rc = ptlrpc_queue_wait(req);
1214 /* check connection error first */
1215 if (obd->u.cli.cl_import->imp_connect_error)
1216 rc = obd->u.cli.cl_import->imp_connect_error;
1220 msfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
1222 GOTO(out, rc = -EPROTO);
1227 ptlrpc_req_finished(req);
1231 static int mdc_pin(struct obd_export *exp, const struct lu_fid *fid,
1232 struct obd_capa *oc, struct obd_client_handle *handle,
1235 struct ptlrpc_request *req;
1236 struct mdt_body *body;
1240 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_PIN);
1244 mdc_set_capa_size(req, &RMF_CAPA1, oc);
1246 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_PIN);
1248 ptlrpc_request_free(req);
1252 mdc_pack_body(req, fid, oc, 0, 0, -1, flags);
1254 ptlrpc_request_set_replen(req);
1256 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1257 rc = ptlrpc_queue_wait(req);
1258 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1260 CERROR("Pin failed: %d\n", rc);
1264 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1266 GOTO(err_out, rc = -EPROTO);
1268 handle->och_fh = body->handle;
1269 handle->och_magic = OBD_CLIENT_HANDLE_MAGIC;
1271 OBD_ALLOC_PTR(handle->och_mod);
1272 if (handle->och_mod == NULL) {
1273 DEBUG_REQ(D_ERROR, req, "can't allocate mdc_open_data");
1274 GOTO(err_out, rc = -ENOMEM);
1276 /* will be dropped by unpin */
1277 CFS_INIT_LIST_HEAD(&handle->och_mod->mod_replay_list);
1278 list_add_tail(&req->rq_mod_list, &handle->och_mod->mod_replay_list);
1283 ptlrpc_req_finished(req);
1287 static int mdc_unpin(struct obd_export *exp, struct obd_client_handle *handle,
1290 struct ptlrpc_request *req;
1291 struct mdt_body *body;
1295 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_UNPIN,
1296 LUSTRE_MDS_VERSION, MDS_UNPIN);
1300 body = req_capsule_client_get(&req->rq_pill, &RMF_MDT_BODY);
1301 body->handle = handle->och_fh;
1304 ptlrpc_request_set_replen(req);
1306 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1307 rc = ptlrpc_queue_wait(req);
1308 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1311 CERROR("Unpin failed: %d\n", rc);
1313 ptlrpc_req_finished(req);
1315 LASSERT(!list_empty(&handle->och_mod->mod_replay_list));
1316 req = list_entry(handle->och_mod->mod_replay_list.next,
1317 typeof(*req), rq_mod_list);
1318 list_del_init(&req->rq_mod_list);
1319 ptlrpc_req_finished(req);
1320 LASSERT(list_empty(&handle->och_mod->mod_replay_list));
1322 OBD_FREE(handle->och_mod, sizeof(*handle->och_mod));
1326 int mdc_sync(struct obd_export *exp, const struct lu_fid *fid,
1327 struct obd_capa *oc, struct ptlrpc_request **request)
1329 struct ptlrpc_request *req;
1334 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_SYNC);
1338 mdc_set_capa_size(req, &RMF_CAPA1, oc);
1340 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_SYNC);
1342 ptlrpc_request_free(req);
1346 mdc_pack_body(req, fid, oc, 0, 0, -1, 0);
1348 ptlrpc_request_set_replen(req);
1350 rc = ptlrpc_queue_wait(req);
1352 ptlrpc_req_finished(req);
1358 static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
1359 enum obd_import_event event)
1363 LASSERT(imp->imp_obd == obd);
1366 case IMP_EVENT_DISCON: {
1368 /* XXX Pass event up to OBDs stack. used only for FLD now */
1369 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_DISCON, NULL);
1373 case IMP_EVENT_INACTIVE: {
1374 struct client_obd *cli = &obd->u.cli;
1376 * Flush current sequence to make client obtain new one
1377 * from server in case of disconnect/reconnect.
1378 * If range is already empty then no need to flush it.
1380 if (cli->cl_seq != NULL &&
1381 !range_is_exhausted(&cli->cl_seq->lcs_space)) {
1382 seq_client_flush(cli->cl_seq);
1385 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_INACTIVE, NULL);
1388 case IMP_EVENT_INVALIDATE: {
1389 struct ldlm_namespace *ns = obd->obd_namespace;
1391 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
1395 case IMP_EVENT_ACTIVE: {
1396 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_ACTIVE, NULL);
1400 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_OCD, NULL);
1404 CERROR("Unknown import event %x\n", event);
1410 static int mdc_fid_init(struct obd_export *exp)
1412 struct client_obd *cli = &exp->exp_obd->u.cli;
1417 OBD_ALLOC_PTR(cli->cl_seq);
1418 if (cli->cl_seq == NULL)
1421 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
1423 GOTO(out_free_seq, rc = -ENOMEM);
1425 snprintf(prefix, MAX_OBD_NAME + 5, "srv-%s",
1426 exp->exp_obd->obd_name);
1428 /* Init client side sequence-manager */
1429 rc = seq_client_init(cli->cl_seq, exp,
1430 LUSTRE_SEQ_METADATA,
1432 OBD_FREE(prefix, MAX_OBD_NAME + 5);
1434 GOTO(out_free_seq, rc);
1438 OBD_FREE_PTR(cli->cl_seq);
1443 static int mdc_fid_fini(struct obd_export *exp)
1445 struct client_obd *cli = &exp->exp_obd->u.cli;
1448 if (cli->cl_seq != NULL) {
1449 seq_client_fini(cli->cl_seq);
1450 OBD_FREE_PTR(cli->cl_seq);
1457 int mdc_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
1458 struct md_op_data *op_data)
1460 struct client_obd *cli = &exp->exp_obd->u.cli;
1461 struct lu_client_seq *seq = cli->cl_seq;
1463 RETURN(seq_client_alloc_fid(seq, fid));
1466 /* XXX This method is used only to clear current fid seq
1467 * once fld/mds insert failed */
1468 static int mdc_fid_delete(struct obd_export *exp, const struct lu_fid *fid)
1470 struct client_obd *cli = &exp->exp_obd->u.cli;
1472 seq_client_flush(cli->cl_seq);
1476 static int mdc_setup(struct obd_device *obd, struct lustre_cfg *cfg)
1478 struct client_obd *cli = &obd->u.cli;
1479 struct lprocfs_static_vars lvars = { 0 };
1483 OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1484 if (!cli->cl_rpc_lock)
1486 mdc_init_rpc_lock(cli->cl_rpc_lock);
1490 OBD_ALLOC(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1491 if (!cli->cl_setattr_lock)
1492 GOTO(err_rpc_lock, rc = -ENOMEM);
1493 mdc_init_rpc_lock(cli->cl_setattr_lock);
1495 OBD_ALLOC(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1496 if (!cli->cl_close_lock)
1497 GOTO(err_setattr_lock, rc = -ENOMEM);
1498 mdc_init_rpc_lock(cli->cl_close_lock);
1500 rc = client_obd_setup(obd, cfg);
1502 GOTO(err_close_lock, rc);
1503 lprocfs_mdc_init_vars(&lvars);
1504 lprocfs_obd_setup(obd, lvars.obd_vars);
1505 sptlrpc_lprocfs_cliobd_attach(obd);
1506 ptlrpc_lprocfs_register_obd(obd);
1508 rc = obd_llog_init(obd, NULL, obd, 0, NULL, NULL);
1511 CERROR("failed to setup llogging subsystems\n");
1517 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1519 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1521 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1526 /* Initialize the default and maximum LOV EA and cookie sizes. This allows
1527 * us to make MDS RPCs with large enough reply buffers to hold the
1528 * maximum-sized (= maximum striped) EA and cookie without having to
1529 * calculate this (via a call into the LOV + OSCs) each time we make an RPC. */
1530 int mdc_init_ea_size(struct obd_export *exp, int easize,
1531 int def_easize, int cookiesize)
1533 struct obd_device *obd = exp->exp_obd;
1534 struct client_obd *cli = &obd->u.cli;
1537 if (cli->cl_max_mds_easize < easize)
1538 cli->cl_max_mds_easize = easize;
1540 if (cli->cl_default_mds_easize < def_easize)
1541 cli->cl_default_mds_easize = def_easize;
1543 if (cli->cl_max_mds_cookiesize < cookiesize)
1544 cli->cl_max_mds_cookiesize = cookiesize;
1549 static int mdc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
1555 case OBD_CLEANUP_EARLY:
1556 case OBD_CLEANUP_EXPORTS:
1557 /* If we set up but never connected, the
1558 client import will not have been cleaned. */
1559 if (obd->u.cli.cl_import) {
1560 struct obd_import *imp;
1561 imp = obd->u.cli.cl_import;
1562 CERROR("client import never connected\n");
1563 ptlrpc_invalidate_import(imp);
1564 ptlrpc_free_rq_pool(imp->imp_rq_pool);
1565 class_destroy_import(imp);
1566 obd->u.cli.cl_import = NULL;
1569 case OBD_CLEANUP_SELF_EXP:
1570 rc = obd_llog_finish(obd, 0);
1572 CERROR("failed to cleanup llogging subsystems\n");
1573 case OBD_CLEANUP_OBD:
1579 static int mdc_cleanup(struct obd_device *obd)
1581 struct client_obd *cli = &obd->u.cli;
1583 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1584 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1585 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1587 ptlrpc_lprocfs_unregister_obd(obd);
1588 lprocfs_obd_cleanup(obd);
1591 return client_obd_cleanup(obd);
1595 static int mdc_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
1596 struct obd_device *tgt, int count,
1597 struct llog_catid *logid, struct obd_uuid *uuid)
1599 struct llog_ctxt *ctxt;
1603 rc = llog_setup(obd, llogs, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
1606 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
1607 ctxt->loc_imp = obd->u.cli.cl_import;
1610 rc = llog_setup(obd, llogs, LLOG_LOVEA_REPL_CTXT, tgt, 0, NULL,
1613 ctxt = llog_get_context(obd, LLOG_LOVEA_REPL_CTXT);
1614 ctxt->loc_imp = obd->u.cli.cl_import;
1620 static int mdc_llog_finish(struct obd_device *obd, int count)
1625 rc = llog_cleanup(llog_get_context(obd, LLOG_LOVEA_REPL_CTXT));
1627 CERROR("can not cleanup LLOG_CONFIG_REPL_CTXT rc %d\n", rc);
1629 rc = llog_cleanup(llog_get_context(obd, LLOG_CONFIG_REPL_CTXT));
1633 static int mdc_process_config(struct obd_device *obd, obd_count len, void *buf)
1635 struct lustre_cfg *lcfg = buf;
1636 struct lprocfs_static_vars lvars = { 0 };
1639 lprocfs_mdc_init_vars(&lvars);
1641 switch (lcfg->lcfg_command) {
1642 case LCFG_SPTLRPC_CONF:
1643 rc = sptlrpc_cliobd_process_config(obd, lcfg);
1646 rc = class_process_proc_param(PARAM_MDC, lvars.obd_vars,
1654 /* get remote permission for current user on fid */
1655 int mdc_get_remote_perm(struct obd_export *exp, const struct lu_fid *fid,
1656 struct obd_capa *oc, __u32 suppgid,
1657 struct ptlrpc_request **request)
1659 struct ptlrpc_request *req;
1664 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR);
1668 mdc_set_capa_size(req, &RMF_CAPA1, oc);
1670 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR);
1672 ptlrpc_request_free(req);
1676 mdc_pack_body(req, fid, oc, OBD_MD_FLRMTPERM, 0, suppgid, 0);
1678 ptlrpc_request_set_replen(req);
1680 rc = ptlrpc_queue_wait(req);
1682 ptlrpc_req_finished(req);
1688 static int mdc_interpret_renew_capa(struct ptlrpc_request *req, void *unused,
1691 struct obd_capa *oc = req->rq_async_args.pointer_arg[0];
1692 renew_capa_cb_t cb = req->rq_async_args.pointer_arg[1];
1693 struct mdt_body *body = NULL;
1694 struct lustre_capa *capa;
1698 GOTO(out, capa = ERR_PTR(status));
1700 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1702 GOTO(out, capa = ERR_PTR(-EFAULT));
1704 if ((body->valid & OBD_MD_FLOSSCAPA) == 0)
1705 GOTO(out, capa = ERR_PTR(-ENOENT));
1707 capa = req_capsule_server_get(&req->rq_pill, &RMF_CAPA2);
1709 GOTO(out, capa = ERR_PTR(-EFAULT));
1716 static int mdc_renew_capa(struct obd_export *exp, struct obd_capa *oc,
1719 struct ptlrpc_request *req;
1722 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_GETATTR,
1723 LUSTRE_MDS_VERSION, MDS_GETATTR);
1727 /* NB, OBD_MD_FLOSSCAPA is set here, but it doesn't necessarily mean the
1728 * capa to renew is oss capa.
1730 mdc_pack_body(req, &oc->c_capa.lc_fid, oc, OBD_MD_FLOSSCAPA, 0, -1, 0);
1731 ptlrpc_request_set_replen(req);
1733 req->rq_async_args.pointer_arg[0] = oc;
1734 req->rq_async_args.pointer_arg[1] = cb;
1735 req->rq_interpret_reply = mdc_interpret_renew_capa;
1736 ptlrpcd_add_req(req);
1740 static int mdc_connect(const struct lu_env *env,
1741 struct lustre_handle *dlm_handle,
1742 struct obd_device *obd, struct obd_uuid *cluuid,
1743 struct obd_connect_data *data)
1745 struct obd_import *imp = obd->u.cli.cl_import;
1747 /* mds-mds import features */
1748 if (data && (data->ocd_connect_flags & OBD_CONNECT_MDS_MDS)) {
1749 spin_lock(&imp->imp_lock);
1750 imp->imp_server_timeout = 1;
1751 spin_unlock(&imp->imp_lock);
1752 imp->imp_client->cli_request_portal = MDS_MDS_PORTAL;
1753 CDEBUG(D_OTHER, "%s: Set 'mds' portal and timeout\n",
1757 return client_connect_import(env, dlm_handle, obd, cluuid, data);
1760 struct obd_ops mdc_obd_ops = {
1761 .o_owner = THIS_MODULE,
1762 .o_setup = mdc_setup,
1763 .o_precleanup = mdc_precleanup,
1764 .o_cleanup = mdc_cleanup,
1765 .o_add_conn = client_import_add_conn,
1766 .o_del_conn = client_import_del_conn,
1767 .o_connect = mdc_connect,
1768 .o_disconnect = client_disconnect_export,
1769 .o_iocontrol = mdc_iocontrol,
1770 .o_set_info_async = mdc_set_info_async,
1771 .o_statfs = mdc_statfs,
1773 .o_unpin = mdc_unpin,
1774 .o_fid_init = mdc_fid_init,
1775 .o_fid_fini = mdc_fid_fini,
1776 .o_fid_alloc = mdc_fid_alloc,
1777 .o_fid_delete = mdc_fid_delete,
1778 .o_import_event = mdc_import_event,
1779 .o_llog_init = mdc_llog_init,
1780 .o_llog_finish = mdc_llog_finish,
1781 .o_get_info = mdc_get_info,
1782 .o_process_config = mdc_process_config,
1785 struct md_ops mdc_md_ops = {
1786 .m_getstatus = mdc_getstatus,
1787 .m_change_cbdata = mdc_change_cbdata,
1788 .m_close = mdc_close,
1789 .m_create = mdc_create,
1790 .m_done_writing = mdc_done_writing,
1791 .m_enqueue = mdc_enqueue,
1792 .m_getattr = mdc_getattr,
1793 .m_getattr_name = mdc_getattr_name,
1794 .m_intent_lock = mdc_intent_lock,
1796 .m_is_subdir = mdc_is_subdir,
1797 .m_rename = mdc_rename,
1798 .m_setattr = mdc_setattr,
1799 .m_setxattr = mdc_setxattr,
1800 .m_getxattr = mdc_getxattr,
1802 .m_readpage = mdc_readpage,
1803 .m_unlink = mdc_unlink,
1804 .m_cancel_unused = mdc_cancel_unused,
1805 .m_init_ea_size = mdc_init_ea_size,
1806 .m_set_lock_data = mdc_set_lock_data,
1807 .m_lock_match = mdc_lock_match,
1808 .m_get_lustre_md = mdc_get_lustre_md,
1809 .m_free_lustre_md = mdc_free_lustre_md,
1810 .m_set_open_replay_data = mdc_set_open_replay_data,
1811 .m_clear_open_replay_data = mdc_clear_open_replay_data,
1812 .m_get_remote_perm = mdc_get_remote_perm,
1813 .m_renew_capa = mdc_renew_capa
1816 extern quota_interface_t mdc_quota_interface;
1818 int __init mdc_init(void)
1821 struct lprocfs_static_vars lvars = { 0 };
1822 lprocfs_mdc_init_vars(&lvars);
1824 request_module("lquota");
1825 quota_interface = PORTAL_SYMBOL_GET(mdc_quota_interface);
1826 init_obd_quota_ops(quota_interface, &mdc_obd_ops);
1828 rc = class_register_type(&mdc_obd_ops, &mdc_md_ops, lvars.module_vars,
1829 LUSTRE_MDC_NAME, NULL);
1830 if (rc && quota_interface)
1831 PORTAL_SYMBOL_PUT(mdc_quota_interface);
1837 static void /*__exit*/ mdc_exit(void)
1839 if (quota_interface)
1840 PORTAL_SYMBOL_PUT(mdc_quota_interface);
1842 class_unregister_type(LUSTRE_MDC_NAME);
1845 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1846 MODULE_DESCRIPTION("Lustre Metadata Client");
1847 MODULE_LICENSE("GPL");
1849 module_init(mdc_init);
1850 module_exit(mdc_exit);