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;
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 req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER,
230 sizeof(struct mdt_remote_perm));
231 ptlrpc_request_set_replen(req);
233 rc = mdc_getattr_common(exp, req);
235 ptlrpc_req_finished(req);
241 int mdc_getattr_name(struct obd_export *exp, const struct lu_fid *fid,
242 struct obd_capa *oc, const char *filename, int namelen,
243 obd_valid valid, int ea_size, __u32 suppgid,
244 struct ptlrpc_request **request)
246 struct ptlrpc_request *req;
251 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
252 &RQF_MDS_GETATTR_NAME);
256 mdc_set_capa_size(req, &RMF_CAPA1, oc);
257 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT, namelen);
259 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR_NAME);
261 ptlrpc_request_free(req);
265 /* MDS_BFLAG_EXT_FLAGS: request "new" flags(bug 9486) */
266 mdc_pack_body(req, fid, oc, valid, ea_size, suppgid,
267 MDS_BFLAG_EXT_FLAGS);
270 char *name = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
271 LASSERT(strnlen(filename, namelen) == namelen - 1);
272 memcpy(name, filename, namelen);
275 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER, ea_size);
276 ptlrpc_request_set_replen(req);
278 rc = mdc_getattr_common(exp, req);
280 ptlrpc_req_finished(req);
286 static int mdc_is_subdir(struct obd_export *exp,
287 const struct lu_fid *pfid,
288 const struct lu_fid *cfid,
289 struct ptlrpc_request **request)
291 struct ptlrpc_request *req;
297 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
298 &RQF_MDS_IS_SUBDIR, LUSTRE_MDS_VERSION,
303 mdc_is_subdir_pack(req, pfid, cfid, 0);
304 ptlrpc_request_set_replen(req);
306 rc = ptlrpc_queue_wait(req);
307 if (rc && rc != -EREMOTE)
308 ptlrpc_req_finished(req);
314 static int mdc_xattr_common(struct obd_export *exp,const struct req_format *fmt,
315 const struct lu_fid *fid,
316 struct obd_capa *oc, int opcode, obd_valid valid,
317 const char *xattr_name, const char *input,
318 int input_size, int output_size, int flags,
319 __u32 suppgid, struct ptlrpc_request **request)
321 struct ptlrpc_request *req;
322 int xattr_namelen = 0;
328 req = ptlrpc_request_alloc(class_exp2cliimp(exp), fmt);
332 mdc_set_capa_size(req, &RMF_CAPA1, oc);
334 xattr_namelen = strlen(xattr_name) + 1;
335 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
340 req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_CLIENT,
344 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, opcode);
346 ptlrpc_request_free(req);
350 if (opcode == MDS_REINT) {
351 struct mdt_rec_setxattr *rec;
353 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
354 sizeof(struct mdt_rec_reint));
355 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
356 rec->sx_opcode = REINT_SETXATTR;
358 * cfs_curproc_fs{u,g}id() should replace
359 * current->fs{u,g}id for portability.
361 rec->sx_fsuid = current->fsuid;
362 rec->sx_fsgid = current->fsgid;
363 rec->sx_cap = current->cap_effective;
364 rec->sx_suppgid1 = suppgid;
365 rec->sx_suppgid1 = -1;
367 rec->sx_valid = valid;
368 rec->sx_size = output_size;
369 rec->sx_flags = flags;
371 mdc_pack_capa(req, &RMF_CAPA1, oc);
373 mdc_pack_body(req, fid, oc, valid, output_size, suppgid, flags);
377 tmp = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
378 memcpy(tmp, xattr_name, xattr_namelen);
381 tmp = req_capsule_client_get(&req->rq_pill, &RMF_EADATA);
382 memcpy(tmp, input, input_size);
385 if (req_capsule_has_field(&req->rq_pill, &RMF_EADATA, RCL_SERVER))
386 req_capsule_set_size(&req->rq_pill, &RMF_EADATA,
387 RCL_SERVER, output_size);
388 ptlrpc_request_set_replen(req);
391 if (opcode == MDS_REINT)
392 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
394 rc = ptlrpc_queue_wait(req);
396 if (opcode == MDS_REINT)
397 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
400 ptlrpc_req_finished(req);
406 int mdc_setxattr(struct obd_export *exp, const struct lu_fid *fid,
407 struct obd_capa *oc, obd_valid valid, const char *xattr_name,
408 const char *input, int input_size, int output_size,
409 int flags, __u32 suppgid, struct ptlrpc_request **request)
411 return mdc_xattr_common(exp, &RQF_MDS_REINT_SETXATTR,
412 fid, oc, MDS_REINT, valid, xattr_name,
413 input, input_size, output_size, flags,
417 int mdc_getxattr(struct obd_export *exp, const struct lu_fid *fid,
418 struct obd_capa *oc, obd_valid valid, const char *xattr_name,
419 const char *input, int input_size, int output_size,
420 int flags, struct ptlrpc_request **request)
422 return mdc_xattr_common(exp, &RQF_MDS_GETXATTR,
423 fid, oc, MDS_GETXATTR, valid, xattr_name,
424 input, input_size, output_size, flags,
428 #ifdef CONFIG_FS_POSIX_ACL
429 static int mdc_unpack_acl(struct ptlrpc_request *req, struct lustre_md *md)
431 struct req_capsule *pill = &req->rq_pill;
432 struct mdt_body *body = md->body;
433 struct posix_acl *acl;
441 buf = req_capsule_server_sized_get(pill, &RMF_ACL, body->aclsize);
446 acl = posix_acl_from_xattr(buf, body->aclsize);
449 CERROR("convert xattr to acl: %d\n", rc);
453 rc = posix_acl_valid(acl);
455 CERROR("validate acl: %d\n", rc);
456 posix_acl_release(acl);
464 #define mdc_unpack_acl(req, md) 0
467 int mdc_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
468 struct obd_export *dt_exp, struct obd_export *md_exp,
469 struct lustre_md *md)
471 struct req_capsule *pill = &req->rq_pill;
476 memset(md, 0, sizeof(*md));
478 md->body = req_capsule_server_get(pill, &RMF_MDT_BODY);
479 LASSERT(md->body != NULL);
481 if (md->body->valid & OBD_MD_FLEASIZE) {
483 struct lov_mds_md *lmm;
485 if (!S_ISREG(md->body->mode)) {
486 CDEBUG(D_INFO, "OBD_MD_FLEASIZE set, should be a "
487 "regular file, but is not\n");
488 GOTO(out, rc = -EPROTO);
491 if (md->body->eadatasize == 0) {
492 CDEBUG(D_INFO, "OBD_MD_FLEASIZE set, "
493 "but eadatasize 0\n");
494 GOTO(out, rc = -EPROTO);
496 lmmsize = md->body->eadatasize;
497 lmm = req_capsule_server_sized_get(pill, &RMF_MDT_MD, lmmsize);
499 GOTO(out, rc = -EPROTO);
501 rc = obd_unpackmd(dt_exp, &md->lsm, lmm, lmmsize);
505 if (rc < sizeof(*md->lsm)) {
506 CDEBUG(D_INFO, "lsm size too small: "
507 "rc < sizeof (*md->lsm) (%d < "LPSZ")\n",
508 rc, sizeof(*md->lsm));
509 GOTO(out, rc = -EPROTO);
512 } else if (md->body->valid & OBD_MD_FLDIREA) {
514 struct lov_mds_md *lmv;
516 if(!S_ISDIR(md->body->mode)) {
517 CDEBUG(D_INFO, "OBD_MD_FLDIREA set, should be a "
518 "directory, but is not\n");
519 GOTO(out, rc = -EPROTO);
522 if (md->body->eadatasize == 0) {
523 CDEBUG(D_INFO, "OBD_MD_FLDIREA is set, "
524 "but eadatasize 0\n");
527 if (md->body->valid & OBD_MD_MEA) {
528 lmvsize = md->body->eadatasize;
529 lmv = req_capsule_server_sized_get(pill, &RMF_MDT_MD,
532 GOTO(out, rc = -EPROTO);
534 rc = obd_unpackmd(md_exp, (void *)&md->mea, lmv,
539 if (rc < sizeof(*md->mea)) {
540 CDEBUG(D_INFO, "size too small: "
541 "rc < sizeof(*md->mea) (%d < %d)\n",
542 rc, sizeof(*md->mea));
543 GOTO(out, rc = -EPROTO);
549 if (md->body->valid & OBD_MD_FLRMTPERM) {
550 /* remote permission */
551 md->remote_perm = req_capsule_server_get(pill, &RMF_ACL);
552 if (!md->remote_perm)
553 GOTO(out, rc = -EPROTO);
555 else if (md->body->valid & OBD_MD_FLACL) {
556 /* for ACL, it's possible that FLACL is set but aclsize is zero.
557 * only when aclsize != 0 there's an actual segment for ACL
560 if (md->body->aclsize) {
561 rc = mdc_unpack_acl(req, md);
564 #ifdef CONFIG_FS_POSIX_ACL
566 md->posix_acl = NULL;
570 if (md->body->valid & OBD_MD_FLMDSCAPA) {
571 struct obd_capa *oc = mdc_unpack_capa(req, &RMF_CAPA1);
574 GOTO(out, rc = PTR_ERR(oc));
578 if (md->body->valid & OBD_MD_FLOSSCAPA) {
579 struct obd_capa *oc = mdc_unpack_capa(req, &RMF_CAPA2);
582 GOTO(out, rc = PTR_ERR(oc));
590 free_capa(md->oss_capa);
592 free_capa(md->mds_capa);
593 #ifdef CONFIG_FS_POSIX_ACL
594 posix_acl_release(md->posix_acl);
597 obd_free_memmd(dt_exp, &md->lsm);
602 int mdc_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
608 static void mdc_replay_open(struct ptlrpc_request *req)
610 struct md_open_data *mod = req->rq_cb_data;
611 struct ptlrpc_request *cur, *tmp;
612 struct obd_client_handle *och;
613 struct lustre_handle old;
614 struct mdt_body *body;
618 DEBUG_REQ(D_ERROR, req,
619 "Can't properly replay without open data.");
624 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
625 LASSERT(body != NULL);
629 struct lustre_handle *file_fh;
631 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
633 file_fh = &och->och_fh;
634 CDEBUG(D_HA, "updating handle from "LPX64" to "LPX64"\n",
635 file_fh->cookie, body->handle.cookie);
637 *file_fh = body->handle;
639 list_for_each_entry_safe(cur, tmp, &mod->mod_replay_list, rq_mod_list) {
640 int opc = lustre_msg_get_opc(cur->rq_reqmsg);
641 struct mdt_epoch *epoch = NULL;
643 if (opc == MDS_CLOSE || opc == MDS_DONE_WRITING) {
644 epoch = req_capsule_client_get(&cur->rq_pill,
647 DEBUG_REQ(D_HA, cur, "updating %s body with new fh",
648 opc == MDS_CLOSE ? "CLOSE" : "DONE_WRITING");
649 } else if (opc == MDS_REINT) {
650 struct mdt_rec_setattr *rec;
652 /* Check this is REINT_SETATTR. */
653 rec = req_capsule_client_get(&cur->rq_pill,
655 LASSERT(rec && rec->sa_opcode == REINT_SETATTR);
657 epoch = req_capsule_client_get(&cur->rq_pill,
660 DEBUG_REQ(D_HA, cur, "updating REINT_SETATTR body "
665 LASSERT(!memcmp(&old, &epoch->handle,
667 epoch->handle = body->handle;
673 void mdc_commit_delayed(struct ptlrpc_request *req)
675 struct md_open_data *mod = req->rq_cb_data;
676 struct ptlrpc_request *cur, *tmp;
678 DEBUG_REQ(D_HA, req, "req committed");
683 req->rq_cb_data = NULL;
684 req->rq_commit_cb = NULL;
685 list_del_init(&req->rq_mod_list);
686 if (req->rq_sequence) {
687 list_for_each_entry_safe(cur, tmp, &mod->mod_replay_list,
689 LASSERT(cur != LP_POISON);
690 LASSERT(cur->rq_type != LI_POISON);
691 DEBUG_REQ(D_HA, cur, "req balanced");
692 LASSERT(cur->rq_transno != 0);
693 LASSERT(cur->rq_import == req->rq_import);
695 /* We no longer want to preserve this for transno-
696 * unconditional replay. */
697 spin_lock(&cur->rq_lock);
699 spin_unlock(&cur->rq_lock);
703 if (list_empty(&mod->mod_replay_list)) {
704 if (mod->mod_och != NULL)
705 mod->mod_och->och_mod = NULL;
711 int mdc_set_open_replay_data(struct obd_export *exp,
712 struct obd_client_handle *och,
713 struct ptlrpc_request *open_req)
715 struct md_open_data *mod;
716 struct mdt_rec_create *rec;
717 struct mdt_body *body;
718 struct obd_import *imp = open_req->rq_import;
721 rec = req_capsule_client_get(&open_req->rq_pill, &RMF_REC_REINT);
722 body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY);
723 LASSERT(rec != NULL);
724 /* Incoming message in my byte order (it's been swabbed). */
725 /* Outgoing messages always in my byte order. */
726 LASSERT(body != NULL);
728 /*Only the import is replayable, we set replay_open data */
729 if (och && imp->imp_replayable) {
732 DEBUG_REQ(D_ERROR, open_req,
733 "Can't allocate md_open_data");
736 CFS_INIT_LIST_HEAD(&mod->mod_replay_list);
738 spin_lock(&open_req->rq_lock);
739 if (!open_req->rq_replay) {
740 OBD_FREE(mod, sizeof(*mod));
741 spin_unlock(&open_req->rq_lock);
747 open_req->rq_cb_data = mod;
748 list_add_tail(&open_req->rq_mod_list, &mod->mod_replay_list);
749 open_req->rq_commit_cb = mdc_commit_delayed;
750 spin_unlock(&open_req->rq_lock);
753 rec->cr_fid2 = body->fid1;
754 rec->cr_ioepoch = body->ioepoch;
755 rec->cr_old_handle.cookie = body->handle.cookie;
756 open_req->rq_replay_cb = mdc_replay_open;
757 if (!fid_is_sane(&body->fid1)) {
758 DEBUG_REQ(D_ERROR, open_req, "Saving replay request with "
763 DEBUG_REQ(D_RPCTRACE, open_req, "Set up open replay data");
767 int mdc_clear_open_replay_data(struct obd_export *exp,
768 struct obd_client_handle *och)
770 struct md_open_data *mod = och->och_mod;
774 * Don't free the structure now (it happens in mdc_commit_delayed(),
775 * after the last request is removed from its replay list),
776 * but make sure that replay doesn't poke at the och, which is about to
779 LASSERT(mod != LP_POISON);
787 int mdc_close(struct obd_export *exp, struct md_op_data *op_data,
788 struct md_open_data *mod, struct ptlrpc_request **request)
790 struct obd_device *obd = class_exp2obd(exp);
791 struct ptlrpc_request *req;
796 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_CLOSE);
800 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
802 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_CLOSE);
804 ptlrpc_request_free(req);
808 /* To avoid a livelock (bug 7034), we need to send CLOSE RPCs to a
809 * portal whose threads are not taking any DLM locks and are therefore
810 * always progressing */
811 /* XXX FIXME bug 249 */
812 req->rq_request_portal = MDS_READPAGE_PORTAL;
814 /* Ensure that this close's handle is fixed up during replay. */
815 if (likely(mod != NULL))
816 list_add_tail(&req->rq_mod_list, &mod->mod_replay_list);
818 CDEBUG(D_HA, "couldn't find open req; expecting close error\n");
820 mdc_close_pack(req, op_data);
822 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER,
823 obd->u.cli.cl_max_mds_easize);
824 req_capsule_set_size(&req->rq_pill, &RMF_LOGCOOKIES, RCL_SERVER,
825 obd->u.cli.cl_max_mds_cookiesize);
827 ptlrpc_request_set_replen(req);
829 req->rq_commit_cb = mdc_commit_delayed;
831 LASSERT(req->rq_cb_data == NULL);
832 req->rq_cb_data = mod;
834 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
835 rc = ptlrpc_queue_wait(req);
836 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
838 if (req->rq_repmsg == NULL) {
839 CDEBUG(D_RPCTRACE, "request failed to send: %p, %d\n", req,
842 rc = req->rq_status ?: -EIO;
843 } else if (rc == 0 || rc == -EAGAIN) {
844 struct mdt_body *body;
846 rc = lustre_msg_get_status(req->rq_repmsg);
847 if (lustre_msg_get_type(req->rq_repmsg) == PTL_RPC_MSG_ERR) {
848 DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, err "
852 } else if (mod == NULL) {
853 if (req->rq_import->imp_replayable)
854 CERROR("Unexpected: can't find md_open_data,"
855 "but close succeeded with replayable imp"
856 "Please tell CFS.\n");
859 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
865 if (rc != 0 && rc != -EAGAIN && req && req->rq_commit_cb)
866 req->rq_commit_cb(req);
872 int mdc_done_writing(struct obd_export *exp, struct md_op_data *op_data,
873 struct md_open_data *mod)
875 struct obd_device *obd = class_exp2obd(exp);
876 struct ptlrpc_request *req;
880 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
881 &RQF_MDS_DONE_WRITING);
885 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
886 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_DONE_WRITING);
888 ptlrpc_request_free(req);
892 /* XXX: add DONE_WRITING request to och -- when Size-on-MDS
893 * recovery will be ready. */
894 mdc_close_pack(req, op_data);
895 ptlrpc_request_set_replen(req);
897 req->rq_cb_data = mod;
898 req->rq_commit_cb = mdc_commit_delayed;
899 if (likely(mod != NULL))
900 list_add_tail(&req->rq_mod_list, &mod->mod_replay_list);
902 CDEBUG(D_HA, "couldn't find open req; expecting close error\n");
904 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
905 rc = ptlrpc_queue_wait(req);
906 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
908 /* Close the open replay sequence if an error occured or no SOM
909 * attribute update is needed. */
911 ptlrpc_close_replay_seq(req);
913 if (rc && rc != -EAGAIN && req->rq_commit_cb)
914 req->rq_commit_cb(req);
916 ptlrpc_req_finished(req);
920 #ifdef HAVE_SPLIT_SUPPORT
921 int mdc_sendpage(struct obd_export *exp, const struct lu_fid *fid,
922 const struct page *page, int offset)
924 struct ptlrpc_request *req;
925 struct ptlrpc_bulk_desc *desc;
929 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_WRITEPAGE);
933 /* FIXME: capa doesn't support split yet */
934 mdc_set_capa_size(req, &RMF_CAPA1, NULL);
936 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_WRITEPAGE);
938 ptlrpc_request_free(req);
942 req->rq_request_portal = MDS_READPAGE_PORTAL;
944 desc = ptlrpc_prep_bulk_imp(req, 1, BULK_GET_SOURCE, MDS_BULK_PORTAL);
946 GOTO(out, rc = -ENOMEM);
948 /* NB req now owns desc and will free it when it gets freed. */
949 ptlrpc_prep_bulk_page(desc, (struct page *)page, 0, offset);
950 mdc_readdir_pack(req, 0, offset, fid, NULL);
952 ptlrpc_request_set_replen(req);
953 rc = ptlrpc_queue_wait(req);
956 ptlrpc_req_finished(req);
959 EXPORT_SYMBOL(mdc_sendpage);
962 int mdc_readpage(struct obd_export *exp, const struct lu_fid *fid,
963 struct obd_capa *oc, __u64 offset, struct page *page,
964 struct ptlrpc_request **request)
966 struct ptlrpc_request *req;
967 struct ptlrpc_bulk_desc *desc;
972 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_READPAGE);
976 mdc_set_capa_size(req, &RMF_CAPA1, oc);
978 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_READPAGE);
980 ptlrpc_request_free(req);
984 /* XXX FIXME bug 249 */
985 req->rq_request_portal = MDS_READPAGE_PORTAL;
986 desc = ptlrpc_prep_bulk_imp(req, 1, BULK_PUT_SINK, MDS_BULK_PORTAL);
988 ptlrpc_request_free(req);
992 /* NB req now owns desc and will free it when it gets freed */
993 ptlrpc_prep_bulk_page(desc, page, 0, CFS_PAGE_SIZE);
994 mdc_readdir_pack(req, offset, CFS_PAGE_SIZE, fid, oc);
996 ptlrpc_request_set_replen(req);
997 rc = ptlrpc_queue_wait(req);
999 ptlrpc_req_finished(req);
1003 if (req->rq_bulk->bd_nob_transferred != CFS_PAGE_SIZE) {
1004 CERROR("Unexpected # bytes transferred: %d (%ld expected)\n",
1005 req->rq_bulk->bd_nob_transferred, CFS_PAGE_SIZE);
1006 ptlrpc_req_finished(req);
1014 static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1015 void *karg, void *uarg)
1017 struct obd_device *obd = exp->exp_obd;
1018 struct obd_ioctl_data *data = karg;
1019 struct obd_import *imp = obd->u.cli.cl_import;
1020 struct llog_ctxt *ctxt;
1024 if (!try_module_get(THIS_MODULE)) {
1025 CERROR("Can't get module. Is it alive?");
1029 case OBD_IOC_CLIENT_RECOVER:
1030 rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1);
1034 case IOC_OSC_SET_ACTIVE:
1035 rc = ptlrpc_set_import_active(imp, data->ioc_offset);
1037 case OBD_IOC_PARSE: {
1038 ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT);
1039 rc = class_config_parse_llog(ctxt, data->ioc_inlbuf1, NULL);
1040 llog_ctxt_put(ctxt);
1044 case OBD_IOC_LLOG_INFO:
1045 case OBD_IOC_LLOG_PRINT: {
1046 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
1047 rc = llog_ioctl(ctxt, cmd, data);
1048 llog_ctxt_put(ctxt);
1052 case OBD_IOC_POLL_QUOTACHECK:
1053 rc = lquota_poll_check(quota_interface, exp,
1054 (struct if_quotacheck *)karg);
1057 CERROR("mdc_ioctl(): unrecognised ioctl %#x\n", cmd);
1058 GOTO(out, rc = -ENOTTY);
1061 module_put(THIS_MODULE);
1066 static int do_set_info_async(struct obd_export *exp,
1067 obd_count keylen, void *key,
1068 obd_count vallen, void *val,
1069 struct ptlrpc_request_set *set)
1071 struct obd_import *imp = class_exp2cliimp(exp);
1072 struct ptlrpc_request *req;
1077 if (vallen != sizeof(int))
1080 spin_lock(&imp->imp_lock);
1081 if (*((int *)val)) {
1082 imp->imp_connect_flags_orig |= OBD_CONNECT_RDONLY;
1083 imp->imp_connect_data.ocd_connect_flags |= OBD_CONNECT_RDONLY;
1085 imp->imp_connect_flags_orig &= ~OBD_CONNECT_RDONLY;
1086 imp->imp_connect_data.ocd_connect_flags &= ~OBD_CONNECT_RDONLY;
1088 spin_unlock(&imp->imp_lock);
1090 req = ptlrpc_request_alloc(imp, &RQF_MDS_SET_INFO);
1094 req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_KEY,
1095 RCL_CLIENT, keylen);
1096 req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_VAL,
1097 RCL_CLIENT, vallen);
1098 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_SET_INFO);
1100 ptlrpc_request_free(req);
1104 tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1105 memcpy(tmp, key, keylen);
1106 tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_VAL);
1107 memcpy(tmp, val, vallen);
1109 ptlrpc_request_set_replen(req);
1112 ptlrpc_set_add_req(set, req);
1113 ptlrpc_check_set(set);
1115 rc = ptlrpc_queue_wait(req);
1116 ptlrpc_req_finished(req);
1122 int mdc_set_info_async(struct obd_export *exp,
1123 obd_count keylen, void *key,
1124 obd_count vallen, void *val,
1125 struct ptlrpc_request_set *set)
1127 struct obd_import *imp = class_exp2cliimp(exp);
1131 if (KEY_IS(KEY_INIT_RECOV)) {
1132 if (vallen != sizeof(int))
1134 spin_lock(&imp->imp_lock);
1135 imp->imp_initial_recov = *(int *)val;
1136 spin_unlock(&imp->imp_lock);
1137 CDEBUG(D_HA, "%s: set imp_initial_recov = %d\n",
1138 exp->exp_obd->obd_name, imp->imp_initial_recov);
1141 /* Turn off initial_recov after we try all backup servers once */
1142 if (KEY_IS(KEY_INIT_RECOV_BACKUP)) {
1143 if (vallen != sizeof(int))
1145 spin_lock(&imp->imp_lock);
1146 imp->imp_initial_recov_bk = *(int *)val;
1147 if (imp->imp_initial_recov_bk)
1148 imp->imp_initial_recov = 1;
1149 spin_unlock(&imp->imp_lock);
1150 CDEBUG(D_HA, "%s: set imp_initial_recov_bk = %d\n",
1151 exp->exp_obd->obd_name, imp->imp_initial_recov_bk);
1154 if (KEY_IS(KEY_READ_ONLY)) {
1155 rc = do_set_info_async(exp, keylen, key, vallen, val, set);
1158 if (KEY_IS(KEY_FLUSH_CTX)) {
1159 sptlrpc_import_flush_my_ctx(imp);
1162 if (KEY_IS(KEY_MDS_CONN)) {
1163 struct obd_import *imp = class_exp2cliimp(exp);
1165 /* mds-mds import */
1166 spin_lock(&imp->imp_lock);
1167 imp->imp_server_timeout = 1;
1168 spin_unlock(&imp->imp_lock);
1169 imp->imp_client->cli_request_portal = MDS_MDS_PORTAL;
1170 CDEBUG(D_OTHER|D_WARNING, "%s: timeout / 2\n", exp->exp_obd->obd_name);
1177 int mdc_get_info(struct obd_export *exp, __u32 keylen, void *key,
1178 __u32 *vallen, void *val)
1182 if (KEY_IS(KEY_MAX_EASIZE)) {
1183 int mdsize, *max_easize;
1185 if (*vallen != sizeof(int))
1187 mdsize = *(int*)val;
1188 if (mdsize > exp->exp_obd->u.cli.cl_max_mds_easize)
1189 exp->exp_obd->u.cli.cl_max_mds_easize = mdsize;
1191 *max_easize = exp->exp_obd->u.cli.cl_max_mds_easize;
1194 if (KEY_IS(KEY_CONN_DATA)) {
1195 struct obd_import *imp = class_exp2cliimp(exp);
1196 struct obd_connect_data *data = val;
1198 if (*vallen != sizeof(*data))
1201 *data = imp->imp_connect_data;
1208 static int mdc_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1211 struct ptlrpc_request *req;
1212 struct obd_statfs *msfs;
1216 req = ptlrpc_request_alloc_pack(obd->u.cli.cl_import, &RQF_MDS_STATFS,
1217 LUSTRE_MDS_VERSION, MDS_STATFS);
1221 ptlrpc_request_set_replen(req);
1223 rc = ptlrpc_queue_wait(req);
1225 /* check connection error first */
1226 if (obd->u.cli.cl_import->imp_connect_error)
1227 rc = obd->u.cli.cl_import->imp_connect_error;
1231 msfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
1233 GOTO(out, rc = -EPROTO);
1238 ptlrpc_req_finished(req);
1242 static int mdc_pin(struct obd_export *exp, const struct lu_fid *fid,
1243 struct obd_capa *oc, struct obd_client_handle *handle,
1246 struct ptlrpc_request *req;
1247 struct mdt_body *body;
1251 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_PIN);
1255 mdc_set_capa_size(req, &RMF_CAPA1, oc);
1257 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_PIN);
1259 ptlrpc_request_free(req);
1263 mdc_pack_body(req, fid, oc, 0, 0, -1, flags);
1265 ptlrpc_request_set_replen(req);
1267 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1268 rc = ptlrpc_queue_wait(req);
1269 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1271 CERROR("Pin failed: %d\n", rc);
1275 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1277 GOTO(err_out, rc = -EPROTO);
1279 handle->och_fh = body->handle;
1280 handle->och_magic = OBD_CLIENT_HANDLE_MAGIC;
1282 OBD_ALLOC_PTR(handle->och_mod);
1283 if (handle->och_mod == NULL) {
1284 DEBUG_REQ(D_ERROR, req, "can't allocate mdc_open_data");
1285 GOTO(err_out, rc = -ENOMEM);
1287 /* will be dropped by unpin */
1288 CFS_INIT_LIST_HEAD(&handle->och_mod->mod_replay_list);
1289 list_add_tail(&req->rq_mod_list, &handle->och_mod->mod_replay_list);
1294 ptlrpc_req_finished(req);
1298 static int mdc_unpin(struct obd_export *exp, struct obd_client_handle *handle,
1301 struct ptlrpc_request *req;
1302 struct mdt_body *body;
1306 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_UNPIN,
1307 LUSTRE_MDS_VERSION, MDS_UNPIN);
1311 body = req_capsule_client_get(&req->rq_pill, &RMF_MDT_BODY);
1312 body->handle = handle->och_fh;
1315 ptlrpc_request_set_replen(req);
1317 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1318 rc = ptlrpc_queue_wait(req);
1319 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1322 CERROR("Unpin failed: %d\n", rc);
1324 ptlrpc_req_finished(req);
1326 LASSERT(!list_empty(&handle->och_mod->mod_replay_list));
1327 req = list_entry(handle->och_mod->mod_replay_list.next,
1328 typeof(*req), rq_mod_list);
1329 list_del_init(&req->rq_mod_list);
1330 ptlrpc_req_finished(req);
1331 LASSERT(list_empty(&handle->och_mod->mod_replay_list));
1333 OBD_FREE(handle->och_mod, sizeof(*handle->och_mod));
1337 int mdc_sync(struct obd_export *exp, const struct lu_fid *fid,
1338 struct obd_capa *oc, struct ptlrpc_request **request)
1340 struct ptlrpc_request *req;
1345 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_SYNC);
1349 mdc_set_capa_size(req, &RMF_CAPA1, oc);
1351 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_SYNC);
1353 ptlrpc_request_free(req);
1357 mdc_pack_body(req, fid, oc, 0, 0, -1, 0);
1359 ptlrpc_request_set_replen(req);
1361 rc = ptlrpc_queue_wait(req);
1363 ptlrpc_req_finished(req);
1369 static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
1370 enum obd_import_event event)
1374 LASSERT(imp->imp_obd == obd);
1377 case IMP_EVENT_DISCON: {
1379 /* XXX Pass event up to OBDs stack. used only for FLD now */
1380 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_DISCON, NULL);
1384 case IMP_EVENT_INACTIVE: {
1385 struct client_obd *cli = &obd->u.cli;
1387 * Flush current sequence to make client obtain new one
1388 * from server in case of disconnect/reconnect.
1389 * If range is already empty then no need to flush it.
1391 if (cli->cl_seq != NULL &&
1392 !range_is_exhausted(&cli->cl_seq->lcs_space)) {
1393 seq_client_flush(cli->cl_seq);
1396 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_INACTIVE, NULL);
1399 case IMP_EVENT_INVALIDATE: {
1400 struct ldlm_namespace *ns = obd->obd_namespace;
1402 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
1406 case IMP_EVENT_ACTIVE: {
1407 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_ACTIVE, NULL);
1411 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_OCD, NULL);
1415 CERROR("Unknown import event %x\n", event);
1421 static int mdc_fid_init(struct obd_export *exp)
1423 struct client_obd *cli = &exp->exp_obd->u.cli;
1428 OBD_ALLOC_PTR(cli->cl_seq);
1429 if (cli->cl_seq == NULL)
1432 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
1434 GOTO(out_free_seq, rc = -ENOMEM);
1436 snprintf(prefix, MAX_OBD_NAME + 5, "srv-%s",
1437 exp->exp_obd->obd_name);
1439 /* Init client side sequence-manager */
1440 rc = seq_client_init(cli->cl_seq, exp,
1441 LUSTRE_SEQ_METADATA,
1443 OBD_FREE(prefix, MAX_OBD_NAME + 5);
1445 GOTO(out_free_seq, rc);
1449 OBD_FREE_PTR(cli->cl_seq);
1454 static int mdc_fid_fini(struct obd_export *exp)
1456 struct client_obd *cli = &exp->exp_obd->u.cli;
1459 if (cli->cl_seq != NULL) {
1460 seq_client_fini(cli->cl_seq);
1461 OBD_FREE_PTR(cli->cl_seq);
1468 int mdc_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
1469 struct md_op_data *op_data)
1471 struct client_obd *cli = &exp->exp_obd->u.cli;
1472 struct lu_client_seq *seq = cli->cl_seq;
1474 RETURN(seq_client_alloc_fid(seq, fid));
1477 /* XXX This method is used only to clear current fid seq
1478 * once fld/mds insert failed */
1479 static int mdc_fid_delete(struct obd_export *exp, const struct lu_fid *fid)
1481 struct client_obd *cli = &exp->exp_obd->u.cli;
1483 seq_client_flush(cli->cl_seq);
1487 static int mdc_setup(struct obd_device *obd, struct lustre_cfg *cfg)
1489 struct client_obd *cli = &obd->u.cli;
1490 struct lprocfs_static_vars lvars = { 0 };
1494 OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1495 if (!cli->cl_rpc_lock)
1497 mdc_init_rpc_lock(cli->cl_rpc_lock);
1501 OBD_ALLOC(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1502 if (!cli->cl_setattr_lock)
1503 GOTO(err_rpc_lock, rc = -ENOMEM);
1504 mdc_init_rpc_lock(cli->cl_setattr_lock);
1506 OBD_ALLOC(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1507 if (!cli->cl_close_lock)
1508 GOTO(err_setattr_lock, rc = -ENOMEM);
1509 mdc_init_rpc_lock(cli->cl_close_lock);
1511 rc = client_obd_setup(obd, cfg);
1513 GOTO(err_close_lock, rc);
1514 lprocfs_mdc_init_vars(&lvars);
1515 lprocfs_obd_setup(obd, lvars.obd_vars);
1516 sptlrpc_lprocfs_cliobd_attach(obd);
1517 ptlrpc_lprocfs_register_obd(obd);
1519 rc = obd_llog_init(obd, OBD_LLOG_GROUP, obd, 0, NULL, NULL);
1522 CERROR("failed to setup llogging subsystems\n");
1528 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1530 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1532 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1537 /* Initialize the default and maximum LOV EA and cookie sizes. This allows
1538 * us to make MDS RPCs with large enough reply buffers to hold the
1539 * maximum-sized (= maximum striped) EA and cookie without having to
1540 * calculate this (via a call into the LOV + OSCs) each time we make an RPC. */
1541 int mdc_init_ea_size(struct obd_export *exp, int easize,
1542 int def_easize, int cookiesize)
1544 struct obd_device *obd = exp->exp_obd;
1545 struct client_obd *cli = &obd->u.cli;
1548 if (cli->cl_max_mds_easize < easize)
1549 cli->cl_max_mds_easize = easize;
1551 if (cli->cl_default_mds_easize < def_easize)
1552 cli->cl_default_mds_easize = def_easize;
1554 if (cli->cl_max_mds_cookiesize < cookiesize)
1555 cli->cl_max_mds_cookiesize = cookiesize;
1560 static int mdc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
1566 case OBD_CLEANUP_EARLY:
1567 case OBD_CLEANUP_EXPORTS:
1568 /* If we set up but never connected, the
1569 client import will not have been cleaned. */
1570 if (obd->u.cli.cl_import) {
1571 struct obd_import *imp;
1572 imp = obd->u.cli.cl_import;
1573 CERROR("client import never connected\n");
1574 ptlrpc_invalidate_import(imp);
1575 ptlrpc_free_rq_pool(imp->imp_rq_pool);
1576 class_destroy_import(imp);
1577 obd->u.cli.cl_import = NULL;
1580 case OBD_CLEANUP_SELF_EXP:
1581 rc = obd_llog_finish(obd, 0);
1583 CERROR("failed to cleanup llogging subsystems\n");
1584 case OBD_CLEANUP_OBD:
1590 static int mdc_cleanup(struct obd_device *obd)
1592 struct client_obd *cli = &obd->u.cli;
1594 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1595 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1596 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1598 ptlrpc_lprocfs_unregister_obd(obd);
1599 lprocfs_obd_cleanup(obd);
1602 return client_obd_cleanup(obd);
1606 static int mdc_llog_init(struct obd_device *obd, int group,
1607 struct obd_device *tgt, int count,
1608 struct llog_catid *logid, struct obd_uuid *uuid)
1610 struct llog_ctxt *ctxt;
1611 struct obd_llog_group *olg = &obd->obd_olg;
1615 LASSERT(group == OBD_LLOG_GROUP);
1616 LASSERT(olg->olg_group == group);
1618 rc = llog_setup(obd, olg, LLOG_LOVEA_REPL_CTXT, tgt, 0,
1619 NULL, &llog_client_ops);
1621 ctxt = llog_get_context(obd, LLOG_LOVEA_REPL_CTXT);
1622 llog_initiator_connect(ctxt);
1623 llog_ctxt_put(ctxt);
1629 static int mdc_llog_finish(struct obd_device *obd, int count)
1631 struct llog_ctxt *ctxt;
1635 ctxt = llog_get_context(obd, LLOG_LOVEA_REPL_CTXT);
1637 rc = llog_cleanup(ctxt);
1642 static int mdc_process_config(struct obd_device *obd, obd_count len, void *buf)
1644 struct lustre_cfg *lcfg = buf;
1645 struct lprocfs_static_vars lvars = { 0 };
1648 lprocfs_mdc_init_vars(&lvars);
1650 switch (lcfg->lcfg_command) {
1651 case LCFG_SPTLRPC_CONF:
1652 rc = sptlrpc_cliobd_process_config(obd, lcfg);
1655 rc = class_process_proc_param(PARAM_MDC, lvars.obd_vars,
1663 /* get remote permission for current user on fid */
1664 int mdc_get_remote_perm(struct obd_export *exp, const struct lu_fid *fid,
1665 struct obd_capa *oc, __u32 suppgid,
1666 struct ptlrpc_request **request)
1668 struct ptlrpc_request *req;
1673 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR);
1677 mdc_set_capa_size(req, &RMF_CAPA1, oc);
1679 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR);
1681 ptlrpc_request_free(req);
1685 mdc_pack_body(req, fid, oc, OBD_MD_FLRMTPERM, 0, suppgid, 0);
1687 ptlrpc_request_set_replen(req);
1689 rc = ptlrpc_queue_wait(req);
1691 ptlrpc_req_finished(req);
1697 static int mdc_interpret_renew_capa(struct ptlrpc_request *req, void *unused,
1700 struct obd_capa *oc = req->rq_async_args.pointer_arg[0];
1701 renew_capa_cb_t cb = req->rq_async_args.pointer_arg[1];
1702 struct mdt_body *body = NULL;
1703 struct lustre_capa *capa;
1707 GOTO(out, capa = ERR_PTR(status));
1709 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1711 GOTO(out, capa = ERR_PTR(-EFAULT));
1713 if ((body->valid & OBD_MD_FLOSSCAPA) == 0)
1714 GOTO(out, capa = ERR_PTR(-ENOENT));
1716 capa = req_capsule_server_get(&req->rq_pill, &RMF_CAPA2);
1718 GOTO(out, capa = ERR_PTR(-EFAULT));
1725 static int mdc_renew_capa(struct obd_export *exp, struct obd_capa *oc,
1728 struct ptlrpc_request *req;
1731 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_GETATTR,
1732 LUSTRE_MDS_VERSION, MDS_GETATTR);
1736 /* NB, OBD_MD_FLOSSCAPA is set here, but it doesn't necessarily mean the
1737 * capa to renew is oss capa.
1739 mdc_pack_body(req, &oc->c_capa.lc_fid, oc, OBD_MD_FLOSSCAPA, 0, -1, 0);
1740 ptlrpc_request_set_replen(req);
1742 req->rq_async_args.pointer_arg[0] = oc;
1743 req->rq_async_args.pointer_arg[1] = cb;
1744 req->rq_interpret_reply = mdc_interpret_renew_capa;
1745 ptlrpcd_add_req(req);
1749 static int mdc_connect(const struct lu_env *env,
1750 struct lustre_handle *dlm_handle,
1751 struct obd_device *obd, struct obd_uuid *cluuid,
1752 struct obd_connect_data *data)
1754 struct obd_import *imp = obd->u.cli.cl_import;
1756 /* mds-mds import features */
1757 if (data && (data->ocd_connect_flags & OBD_CONNECT_MDS_MDS)) {
1758 spin_lock(&imp->imp_lock);
1759 imp->imp_server_timeout = 1;
1760 spin_unlock(&imp->imp_lock);
1761 imp->imp_client->cli_request_portal = MDS_MDS_PORTAL;
1762 CDEBUG(D_OTHER, "%s: Set 'mds' portal and timeout\n",
1766 return client_connect_import(env, dlm_handle, obd, cluuid, data);
1769 struct obd_ops mdc_obd_ops = {
1770 .o_owner = THIS_MODULE,
1771 .o_setup = mdc_setup,
1772 .o_precleanup = mdc_precleanup,
1773 .o_cleanup = mdc_cleanup,
1774 .o_add_conn = client_import_add_conn,
1775 .o_del_conn = client_import_del_conn,
1776 .o_connect = mdc_connect,
1777 .o_disconnect = client_disconnect_export,
1778 .o_iocontrol = mdc_iocontrol,
1779 .o_set_info_async = mdc_set_info_async,
1780 .o_statfs = mdc_statfs,
1782 .o_unpin = mdc_unpin,
1783 .o_fid_init = mdc_fid_init,
1784 .o_fid_fini = mdc_fid_fini,
1785 .o_fid_alloc = mdc_fid_alloc,
1786 .o_fid_delete = mdc_fid_delete,
1787 .o_import_event = mdc_import_event,
1788 .o_llog_init = mdc_llog_init,
1789 .o_llog_finish = mdc_llog_finish,
1790 .o_get_info = mdc_get_info,
1791 .o_process_config = mdc_process_config,
1794 struct md_ops mdc_md_ops = {
1795 .m_getstatus = mdc_getstatus,
1796 .m_change_cbdata = mdc_change_cbdata,
1797 .m_close = mdc_close,
1798 .m_create = mdc_create,
1799 .m_done_writing = mdc_done_writing,
1800 .m_enqueue = mdc_enqueue,
1801 .m_getattr = mdc_getattr,
1802 .m_getattr_name = mdc_getattr_name,
1803 .m_intent_lock = mdc_intent_lock,
1805 .m_is_subdir = mdc_is_subdir,
1806 .m_rename = mdc_rename,
1807 .m_setattr = mdc_setattr,
1808 .m_setxattr = mdc_setxattr,
1809 .m_getxattr = mdc_getxattr,
1811 .m_readpage = mdc_readpage,
1812 .m_unlink = mdc_unlink,
1813 .m_cancel_unused = mdc_cancel_unused,
1814 .m_init_ea_size = mdc_init_ea_size,
1815 .m_set_lock_data = mdc_set_lock_data,
1816 .m_lock_match = mdc_lock_match,
1817 .m_get_lustre_md = mdc_get_lustre_md,
1818 .m_free_lustre_md = mdc_free_lustre_md,
1819 .m_set_open_replay_data = mdc_set_open_replay_data,
1820 .m_clear_open_replay_data = mdc_clear_open_replay_data,
1821 .m_get_remote_perm = mdc_get_remote_perm,
1822 .m_renew_capa = mdc_renew_capa
1825 extern quota_interface_t mdc_quota_interface;
1827 int __init mdc_init(void)
1830 struct lprocfs_static_vars lvars = { 0 };
1831 lprocfs_mdc_init_vars(&lvars);
1833 request_module("lquota");
1834 quota_interface = PORTAL_SYMBOL_GET(mdc_quota_interface);
1835 init_obd_quota_ops(quota_interface, &mdc_obd_ops);
1837 rc = class_register_type(&mdc_obd_ops, &mdc_md_ops, lvars.module_vars,
1838 LUSTRE_MDC_NAME, NULL);
1839 if (rc && quota_interface)
1840 PORTAL_SYMBOL_PUT(mdc_quota_interface);
1846 static void /*__exit*/ mdc_exit(void)
1848 if (quota_interface)
1849 PORTAL_SYMBOL_PUT(mdc_quota_interface);
1851 class_unregister_type(LUSTRE_MDC_NAME);
1854 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1855 MODULE_DESCRIPTION("Lustre Metadata Client");
1856 MODULE_LICENSE("GPL");
1858 module_init(mdc_init);
1859 module_exit(mdc_exit);