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 static quota_interface_t *quota_interface;
62 #define REQUEST_MINOR 244
64 static quota_interface_t *quota_interface;
65 extern quota_interface_t mdc_quota_interface;
67 static int mdc_cleanup(struct obd_device *obd);
69 static struct obd_capa *mdc_unpack_capa(struct ptlrpc_request *req,
70 const struct req_msg_field *field)
72 struct lustre_capa *capa;
75 /* swabbed already in mdc_enqueue */
76 capa = req_capsule_server_get(&req->rq_pill, field);
78 return ERR_PTR(-EPROTO);
80 oc = alloc_capa(CAPA_SITE_CLIENT);
82 CDEBUG(D_INFO, "alloc capa failed!\n");
83 return ERR_PTR(-ENOMEM);
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) {
122 oc = mdc_unpack_capa(req, &RMF_CAPA1);
124 GOTO(out, rc = PTR_ERR(oc));
128 *rootfid = body->fid1;
130 "root fid="DFID", last_committed="LPU64", last_xid="LPU64"\n",
132 lustre_msg_get_last_committed(req->rq_repmsg),
133 lustre_msg_get_last_xid(req->rq_repmsg));
136 ptlrpc_req_finished(req);
140 /* This should be mdc_get_info("rootfid") */
141 int mdc_getstatus(struct obd_export *exp, struct lu_fid *rootfid,
142 struct obd_capa **pc)
144 return send_getstatus(class_exp2cliimp(exp), rootfid, pc,
149 * This function now is known to always saying that it will receive 4 buffers
150 * from server. Even for cases when acl_size and md_size is zero, RPC header
151 * will contain 4 fields and RPC itself will contain zero size fields. This is
152 * because mdt_getattr*() _always_ returns 4 fields, but if acl is not needed
153 * and thus zero, it shirinks it, making zero size. The same story about
154 * md_size. And this is course of problem when client waits for smaller number
155 * of fields. This issue will be fixed later when client gets aware of RPC
158 static int mdc_getattr_common(struct obd_export *exp,
159 struct ptlrpc_request *req)
161 struct req_capsule *pill = &req->rq_pill;
162 struct mdt_body *body;
167 /* Request message already built. */
168 rc = ptlrpc_queue_wait(req);
172 /* sanity check for the reply */
173 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
177 CDEBUG(D_NET, "mode: %o\n", body->mode);
179 if (body->eadatasize != 0) {
180 eadata = req_capsule_server_sized_get(pill, &RMF_MDT_MD,
186 if (body->valid & OBD_MD_FLMODEASIZE) {
187 struct client_obd *cli = &exp->exp_obd->u.cli;
189 if (cli->cl_max_mds_easize < body->max_mdsize)
190 cli->cl_max_mds_easize = body->max_mdsize;
191 if (cli->cl_max_mds_cookiesize < body->max_cookiesize)
192 cli->cl_max_mds_cookiesize = body->max_cookiesize;
195 if (body->valid & OBD_MD_FLRMTPERM) {
196 struct mdt_remote_perm *perm;
198 LASSERT(client_is_remote(exp));
199 perm = req_capsule_server_swab_get(pill, &RMF_ACL,
200 lustre_swab_mdt_remote_perm);
205 if (body->valid & OBD_MD_FLMDSCAPA) {
206 struct lustre_capa *capa;
207 capa = req_capsule_server_get(pill, &RMF_CAPA1);
215 int mdc_getattr(struct obd_export *exp, const struct lu_fid *fid,
216 struct obd_capa *oc, obd_valid valid, int ea_size,
217 struct ptlrpc_request **request)
219 struct ptlrpc_request *req;
224 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR);
228 mdc_set_capa_size(req, &RMF_CAPA1, oc);
230 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR);
232 ptlrpc_request_free(req);
236 /* MDS_BFLAG_EXT_FLAGS: request "new" flags(bug 9486) */
237 mdc_pack_body(req, fid, oc, valid, ea_size, -1, MDS_BFLAG_EXT_FLAGS);
239 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER, ea_size);
240 if (valid & OBD_MD_FLRMTPERM) {
241 LASSERT(client_is_remote(exp));
242 req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER,
243 sizeof(struct mdt_remote_perm));
245 ptlrpc_request_set_replen(req);
247 rc = mdc_getattr_common(exp, req);
249 ptlrpc_req_finished(req);
255 int mdc_getattr_name(struct obd_export *exp, const struct lu_fid *fid,
256 struct obd_capa *oc, const char *filename, int namelen,
257 obd_valid valid, int ea_size, __u32 suppgid,
258 struct ptlrpc_request **request)
260 struct ptlrpc_request *req;
265 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
266 &RQF_MDS_GETATTR_NAME);
270 mdc_set_capa_size(req, &RMF_CAPA1, oc);
271 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT, namelen);
273 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR_NAME);
275 ptlrpc_request_free(req);
279 /* MDS_BFLAG_EXT_FLAGS: request "new" flags(bug 9486) */
280 mdc_pack_body(req, fid, oc, valid, ea_size, suppgid,
281 MDS_BFLAG_EXT_FLAGS);
284 char *name = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
285 LASSERT(strnlen(filename, namelen) == namelen - 1);
286 memcpy(name, filename, namelen);
289 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER, ea_size);
290 ptlrpc_request_set_replen(req);
292 rc = mdc_getattr_common(exp, req);
294 ptlrpc_req_finished(req);
300 static int mdc_is_subdir(struct obd_export *exp,
301 const struct lu_fid *pfid,
302 const struct lu_fid *cfid,
303 struct ptlrpc_request **request)
305 struct ptlrpc_request *req;
311 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
312 &RQF_MDS_IS_SUBDIR, LUSTRE_MDS_VERSION,
317 mdc_is_subdir_pack(req, pfid, cfid, 0);
318 ptlrpc_request_set_replen(req);
320 rc = ptlrpc_queue_wait(req);
321 if (rc && rc != -EREMOTE)
322 ptlrpc_req_finished(req);
328 static int mdc_xattr_common(struct obd_export *exp,const struct req_format *fmt,
329 const struct lu_fid *fid,
330 struct obd_capa *oc, int opcode, obd_valid valid,
331 const char *xattr_name, const char *input,
332 int input_size, int output_size, int flags,
333 __u32 suppgid, struct ptlrpc_request **request)
335 struct ptlrpc_request *req;
336 int xattr_namelen = 0;
342 req = ptlrpc_request_alloc(class_exp2cliimp(exp), fmt);
346 mdc_set_capa_size(req, &RMF_CAPA1, oc);
348 xattr_namelen = strlen(xattr_name) + 1;
349 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
354 req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_CLIENT,
358 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, opcode);
360 ptlrpc_request_free(req);
364 if (opcode == MDS_REINT) {
365 struct mdt_rec_setxattr *rec;
367 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
368 sizeof(struct mdt_rec_reint));
369 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
370 rec->sx_opcode = REINT_SETXATTR;
372 * cfs_curproc_fs{u,g}id() should replace
373 * current->fs{u,g}id for portability.
375 rec->sx_fsuid = current->fsuid;
376 rec->sx_fsgid = current->fsgid;
377 rec->sx_cap = cfs_curproc_cap_pack();
378 rec->sx_suppgid1 = suppgid;
379 rec->sx_suppgid2 = -1;
381 rec->sx_valid = valid | OBD_MD_FLCTIME;
382 rec->sx_time = cfs_time_current_sec();
383 rec->sx_size = output_size;
384 rec->sx_flags = flags;
386 mdc_pack_capa(req, &RMF_CAPA1, oc);
388 mdc_pack_body(req, fid, oc, valid, output_size, suppgid, flags);
392 tmp = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
393 memcpy(tmp, xattr_name, xattr_namelen);
396 tmp = req_capsule_client_get(&req->rq_pill, &RMF_EADATA);
397 memcpy(tmp, input, input_size);
400 if (req_capsule_has_field(&req->rq_pill, &RMF_EADATA, RCL_SERVER))
401 req_capsule_set_size(&req->rq_pill, &RMF_EADATA,
402 RCL_SERVER, output_size);
403 ptlrpc_request_set_replen(req);
406 if (opcode == MDS_REINT)
407 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
409 rc = ptlrpc_queue_wait(req);
411 if (opcode == MDS_REINT)
412 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
415 ptlrpc_req_finished(req);
421 int mdc_setxattr(struct obd_export *exp, const struct lu_fid *fid,
422 struct obd_capa *oc, obd_valid valid, const char *xattr_name,
423 const char *input, int input_size, int output_size,
424 int flags, __u32 suppgid, struct ptlrpc_request **request)
426 return mdc_xattr_common(exp, &RQF_MDS_REINT_SETXATTR,
427 fid, oc, MDS_REINT, valid, xattr_name,
428 input, input_size, output_size, flags,
432 int mdc_getxattr(struct obd_export *exp, const struct lu_fid *fid,
433 struct obd_capa *oc, obd_valid valid, const char *xattr_name,
434 const char *input, int input_size, int output_size,
435 int flags, struct ptlrpc_request **request)
437 return mdc_xattr_common(exp, &RQF_MDS_GETXATTR,
438 fid, oc, MDS_GETXATTR, valid, xattr_name,
439 input, input_size, output_size, flags,
443 #ifdef CONFIG_FS_POSIX_ACL
444 static int mdc_unpack_acl(struct ptlrpc_request *req, struct lustre_md *md)
446 struct req_capsule *pill = &req->rq_pill;
447 struct mdt_body *body = md->body;
448 struct posix_acl *acl;
456 buf = req_capsule_server_sized_get(pill, &RMF_ACL, body->aclsize);
461 acl = posix_acl_from_xattr(buf, body->aclsize);
464 CERROR("convert xattr to acl: %d\n", rc);
468 rc = posix_acl_valid(acl);
470 CERROR("validate acl: %d\n", rc);
471 posix_acl_release(acl);
479 #define mdc_unpack_acl(req, md) 0
482 int mdc_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
483 struct obd_export *dt_exp, struct obd_export *md_exp,
484 struct lustre_md *md)
486 struct req_capsule *pill = &req->rq_pill;
491 memset(md, 0, sizeof(*md));
493 md->body = req_capsule_server_get(pill, &RMF_MDT_BODY);
494 LASSERT(md->body != NULL);
496 if (md->body->valid & OBD_MD_FLEASIZE) {
498 struct lov_mds_md *lmm;
500 if (!S_ISREG(md->body->mode)) {
501 CDEBUG(D_INFO, "OBD_MD_FLEASIZE set, should be a "
502 "regular file, but is not\n");
503 GOTO(out, rc = -EPROTO);
506 if (md->body->eadatasize == 0) {
507 CDEBUG(D_INFO, "OBD_MD_FLEASIZE set, "
508 "but eadatasize 0\n");
509 GOTO(out, rc = -EPROTO);
511 lmmsize = md->body->eadatasize;
512 lmm = req_capsule_server_sized_get(pill, &RMF_MDT_MD, lmmsize);
514 GOTO(out, rc = -EPROTO);
516 rc = obd_unpackmd(dt_exp, &md->lsm, lmm, lmmsize);
520 if (rc < sizeof(*md->lsm)) {
521 CDEBUG(D_INFO, "lsm size too small: "
522 "rc < sizeof (*md->lsm) (%d < %d)\n",
523 rc, (int)sizeof(*md->lsm));
524 GOTO(out, rc = -EPROTO);
527 } else if (md->body->valid & OBD_MD_FLDIREA) {
529 struct lov_mds_md *lmv;
531 if(!S_ISDIR(md->body->mode)) {
532 CDEBUG(D_INFO, "OBD_MD_FLDIREA set, should be a "
533 "directory, but is not\n");
534 GOTO(out, rc = -EPROTO);
537 if (md->body->eadatasize == 0) {
538 CDEBUG(D_INFO, "OBD_MD_FLDIREA is set, "
539 "but eadatasize 0\n");
542 if (md->body->valid & OBD_MD_MEA) {
543 lmvsize = md->body->eadatasize;
544 lmv = req_capsule_server_sized_get(pill, &RMF_MDT_MD,
547 GOTO(out, rc = -EPROTO);
549 rc = obd_unpackmd(md_exp, (void *)&md->mea, lmv,
554 if (rc < sizeof(*md->mea)) {
555 CDEBUG(D_INFO, "size too small: "
556 "rc < sizeof(*md->mea) (%d < %d)\n",
557 rc, (int)sizeof(*md->mea));
558 GOTO(out, rc = -EPROTO);
564 if (md->body->valid & OBD_MD_FLRMTPERM) {
565 /* remote permission */
566 LASSERT(client_is_remote(exp));
567 md->remote_perm = req_capsule_server_swab_get(pill, &RMF_ACL,
568 lustre_swab_mdt_remote_perm);
569 if (!md->remote_perm)
570 GOTO(out, rc = -EPROTO);
572 else if (md->body->valid & OBD_MD_FLACL) {
573 /* for ACL, it's possible that FLACL is set but aclsize is zero.
574 * only when aclsize != 0 there's an actual segment for ACL
577 if (md->body->aclsize) {
578 rc = mdc_unpack_acl(req, md);
581 #ifdef CONFIG_FS_POSIX_ACL
583 md->posix_acl = NULL;
587 if (md->body->valid & OBD_MD_FLMDSCAPA) {
588 struct obd_capa *oc = mdc_unpack_capa(req, &RMF_CAPA1);
591 GOTO(out, rc = PTR_ERR(oc));
595 if (md->body->valid & OBD_MD_FLOSSCAPA) {
596 struct obd_capa *oc = mdc_unpack_capa(req, &RMF_CAPA2);
599 GOTO(out, rc = PTR_ERR(oc));
607 free_capa(md->oss_capa);
609 free_capa(md->mds_capa);
610 #ifdef CONFIG_FS_POSIX_ACL
611 posix_acl_release(md->posix_acl);
614 obd_free_memmd(dt_exp, &md->lsm);
619 int mdc_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
625 static void mdc_replay_open(struct ptlrpc_request *req)
627 struct md_open_data *mod = req->rq_cb_data;
628 struct ptlrpc_request *cur, *tmp;
629 struct obd_client_handle *och;
630 struct lustre_handle old;
631 struct mdt_body *body;
635 DEBUG_REQ(D_ERROR, req,
636 "Can't properly replay without open data.");
641 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
642 LASSERT(body != NULL);
646 struct lustre_handle *file_fh;
648 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
650 file_fh = &och->och_fh;
651 CDEBUG(D_HA, "updating handle from "LPX64" to "LPX64"\n",
652 file_fh->cookie, body->handle.cookie);
654 *file_fh = body->handle;
656 list_for_each_entry_safe(cur, tmp, &mod->mod_replay_list, rq_mod_list) {
657 int opc = lustre_msg_get_opc(cur->rq_reqmsg);
658 struct mdt_epoch *epoch = NULL;
660 if (opc == MDS_CLOSE || opc == MDS_DONE_WRITING) {
661 epoch = req_capsule_client_get(&cur->rq_pill,
664 DEBUG_REQ(D_HA, cur, "updating %s body with new fh",
665 opc == MDS_CLOSE ? "CLOSE" : "DONE_WRITING");
666 } else if (opc == MDS_REINT) {
667 struct mdt_rec_setattr *rec;
669 /* Check this is REINT_SETATTR. */
670 rec = req_capsule_client_get(&cur->rq_pill,
672 LASSERT(rec && rec->sa_opcode == REINT_SETATTR);
674 epoch = req_capsule_client_get(&cur->rq_pill,
677 DEBUG_REQ(D_HA, cur, "updating REINT_SETATTR body "
682 LASSERT(!memcmp(&old, &epoch->handle,
684 epoch->handle = body->handle;
690 void mdc_commit_delayed(struct ptlrpc_request *req)
692 struct md_open_data *mod = req->rq_cb_data;
693 struct ptlrpc_request *cur, *tmp;
695 DEBUG_REQ(D_HA, req, "req committed");
700 req->rq_cb_data = NULL;
701 req->rq_commit_cb = NULL;
702 list_del_init(&req->rq_mod_list);
703 if (req->rq_sequence) {
704 list_for_each_entry_safe(cur, tmp, &mod->mod_replay_list,
706 LASSERT(cur != LP_POISON);
707 LASSERT(cur->rq_type != LI_POISON);
708 DEBUG_REQ(D_HA, cur, "req balanced");
709 LASSERT(cur->rq_transno != 0);
710 LASSERT(cur->rq_import == req->rq_import);
712 /* We no longer want to preserve this for transno-
713 * unconditional replay. */
714 spin_lock(&cur->rq_lock);
716 spin_unlock(&cur->rq_lock);
720 if (list_empty(&mod->mod_replay_list)) {
721 if (mod->mod_och != NULL)
722 mod->mod_och->och_mod = NULL;
728 int mdc_set_open_replay_data(struct obd_export *exp,
729 struct obd_client_handle *och,
730 struct ptlrpc_request *open_req)
732 struct md_open_data *mod;
733 struct mdt_rec_create *rec;
734 struct mdt_body *body;
735 struct obd_import *imp = open_req->rq_import;
738 if (!open_req->rq_replay)
741 rec = req_capsule_client_get(&open_req->rq_pill, &RMF_REC_REINT);
742 body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY);
743 LASSERT(rec != NULL);
744 /* Incoming message in my byte order (it's been swabbed). */
745 /* Outgoing messages always in my byte order. */
746 LASSERT(body != NULL);
748 /* Only if the import is replayable, we set replay_open data */
749 if (och && imp->imp_replayable) {
752 DEBUG_REQ(D_ERROR, open_req,
753 "Can't allocate md_open_data");
756 CFS_INIT_LIST_HEAD(&mod->mod_replay_list);
758 spin_lock(&open_req->rq_lock);
761 open_req->rq_cb_data = mod;
762 list_add_tail(&open_req->rq_mod_list, &mod->mod_replay_list);
763 open_req->rq_commit_cb = mdc_commit_delayed;
764 spin_unlock(&open_req->rq_lock);
767 rec->cr_fid2 = body->fid1;
768 rec->cr_ioepoch = body->ioepoch;
769 rec->cr_old_handle.cookie = body->handle.cookie;
770 open_req->rq_replay_cb = mdc_replay_open;
771 if (!fid_is_sane(&body->fid1)) {
772 DEBUG_REQ(D_ERROR, open_req, "Saving replay request with "
777 DEBUG_REQ(D_RPCTRACE, open_req, "Set up open replay data");
781 int mdc_clear_open_replay_data(struct obd_export *exp,
782 struct obd_client_handle *och)
784 struct md_open_data *mod = och->och_mod;
788 * Don't free the structure now (it happens in mdc_commit_delayed(),
789 * after the last request is removed from its replay list),
790 * but make sure that replay doesn't poke at the och, which is about to
793 LASSERT(mod != LP_POISON);
801 int mdc_close(struct obd_export *exp, struct md_op_data *op_data,
802 struct md_open_data *mod, struct ptlrpc_request **request)
804 struct obd_device *obd = class_exp2obd(exp);
805 struct ptlrpc_request *req;
810 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_CLOSE);
814 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
816 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_CLOSE);
818 ptlrpc_request_free(req);
822 /* To avoid a livelock (bug 7034), we need to send CLOSE RPCs to a
823 * portal whose threads are not taking any DLM locks and are therefore
824 * always progressing */
825 req->rq_request_portal = MDS_READPAGE_PORTAL;
826 ptlrpc_at_set_req_timeout(req);
828 /* Ensure that this close's handle is fixed up during replay. */
829 if (likely(mod != NULL))
830 list_add_tail(&req->rq_mod_list, &mod->mod_replay_list);
832 CDEBUG(D_HA, "couldn't find open req; expecting close error\n");
834 mdc_close_pack(req, op_data);
836 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER,
837 obd->u.cli.cl_max_mds_easize);
838 req_capsule_set_size(&req->rq_pill, &RMF_LOGCOOKIES, RCL_SERVER,
839 obd->u.cli.cl_max_mds_cookiesize);
841 ptlrpc_request_set_replen(req);
843 req->rq_commit_cb = mdc_commit_delayed;
845 LASSERT(req->rq_cb_data == NULL);
846 req->rq_cb_data = mod;
848 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
849 rc = ptlrpc_queue_wait(req);
850 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
852 if (req->rq_repmsg == NULL) {
853 CDEBUG(D_RPCTRACE, "request failed to send: %p, %d\n", req,
856 rc = req->rq_status ?: -EIO;
857 } else if (rc == 0 || rc == -EAGAIN) {
858 struct mdt_body *body;
860 rc = lustre_msg_get_status(req->rq_repmsg);
861 if (lustre_msg_get_type(req->rq_repmsg) == PTL_RPC_MSG_ERR) {
862 DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, err "
866 } else if (mod == NULL) {
867 if (req->rq_import->imp_replayable)
868 CERROR("Unexpected: can't find md_open_data,"
869 "but close succeeded with replayable imp"
871 "http://bugzilla.lustre.org/\n");
874 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
880 if (rc != 0 && rc != -EAGAIN && req && req->rq_commit_cb)
881 req->rq_commit_cb(req);
887 int mdc_done_writing(struct obd_export *exp, struct md_op_data *op_data,
888 struct md_open_data *mod)
890 struct obd_device *obd = class_exp2obd(exp);
891 struct ptlrpc_request *req;
895 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
896 &RQF_MDS_DONE_WRITING);
900 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
901 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_DONE_WRITING);
903 ptlrpc_request_free(req);
907 /* XXX: add DONE_WRITING request to och -- when Size-on-MDS
908 * recovery will be ready. */
909 mdc_close_pack(req, op_data);
910 ptlrpc_request_set_replen(req);
912 req->rq_cb_data = mod;
913 req->rq_commit_cb = mdc_commit_delayed;
914 if (likely(mod != NULL))
915 list_add_tail(&req->rq_mod_list, &mod->mod_replay_list);
917 CDEBUG(D_HA, "couldn't find open req; expecting close error\n");
919 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
920 rc = ptlrpc_queue_wait(req);
921 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
923 /* Close the open replay sequence if an error occured or no SOM
924 * attribute update is needed. */
926 ptlrpc_close_replay_seq(req);
928 if (rc && rc != -EAGAIN && req->rq_commit_cb)
929 req->rq_commit_cb(req);
931 ptlrpc_req_finished(req);
935 #ifdef HAVE_SPLIT_SUPPORT
936 int mdc_sendpage(struct obd_export *exp, const struct lu_fid *fid,
937 const struct page *page, int offset)
939 struct ptlrpc_request *req;
940 struct ptlrpc_bulk_desc *desc;
944 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_WRITEPAGE);
948 /* FIXME: capa doesn't support split yet */
949 mdc_set_capa_size(req, &RMF_CAPA1, NULL);
951 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_WRITEPAGE);
953 ptlrpc_request_free(req);
957 req->rq_request_portal = MDS_READPAGE_PORTAL;
958 ptlrpc_at_set_req_timeout(req);
960 desc = ptlrpc_prep_bulk_imp(req, 1, BULK_GET_SOURCE, MDS_BULK_PORTAL);
962 GOTO(out, rc = -ENOMEM);
964 /* NB req now owns desc and will free it when it gets freed. */
965 ptlrpc_prep_bulk_page(desc, (struct page *)page, 0, offset);
966 mdc_readdir_pack(req, 0, offset, fid, NULL);
968 ptlrpc_request_set_replen(req);
969 rc = ptlrpc_queue_wait(req);
972 ptlrpc_req_finished(req);
975 EXPORT_SYMBOL(mdc_sendpage);
978 int mdc_readpage(struct obd_export *exp, const struct lu_fid *fid,
979 struct obd_capa *oc, __u64 offset, struct page *page,
980 struct ptlrpc_request **request)
982 struct ptlrpc_request *req;
983 struct ptlrpc_bulk_desc *desc;
988 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_READPAGE);
992 mdc_set_capa_size(req, &RMF_CAPA1, oc);
994 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_READPAGE);
996 ptlrpc_request_free(req);
1000 req->rq_request_portal = MDS_READPAGE_PORTAL;
1001 ptlrpc_at_set_req_timeout(req);
1003 desc = ptlrpc_prep_bulk_imp(req, 1, BULK_PUT_SINK, MDS_BULK_PORTAL);
1005 ptlrpc_request_free(req);
1009 /* NB req now owns desc and will free it when it gets freed */
1010 ptlrpc_prep_bulk_page(desc, page, 0, CFS_PAGE_SIZE);
1011 mdc_readdir_pack(req, offset, CFS_PAGE_SIZE, fid, oc);
1013 ptlrpc_request_set_replen(req);
1014 rc = ptlrpc_queue_wait(req);
1016 ptlrpc_req_finished(req);
1020 if (req->rq_bulk->bd_nob_transferred != CFS_PAGE_SIZE) {
1021 CERROR("Unexpected # bytes transferred: %d (%ld expected)\n",
1022 req->rq_bulk->bd_nob_transferred, CFS_PAGE_SIZE);
1023 ptlrpc_req_finished(req);
1031 static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1032 void *karg, void *uarg)
1034 struct obd_device *obd = exp->exp_obd;
1035 struct obd_ioctl_data *data = karg;
1036 struct obd_import *imp = obd->u.cli.cl_import;
1037 struct llog_ctxt *ctxt;
1041 if (!try_module_get(THIS_MODULE)) {
1042 CERROR("Can't get module. Is it alive?");
1046 case OBD_IOC_CLIENT_RECOVER:
1047 rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1);
1051 case IOC_OSC_SET_ACTIVE:
1052 rc = ptlrpc_set_import_active(imp, data->ioc_offset);
1054 case OBD_IOC_PARSE: {
1055 ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT);
1056 rc = class_config_parse_llog(ctxt, data->ioc_inlbuf1, NULL);
1057 llog_ctxt_put(ctxt);
1061 case OBD_IOC_LLOG_INFO:
1062 case OBD_IOC_LLOG_PRINT: {
1063 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
1064 rc = llog_ioctl(ctxt, cmd, data);
1065 llog_ctxt_put(ctxt);
1069 case OBD_IOC_POLL_QUOTACHECK:
1070 rc = lquota_poll_check(quota_interface, exp,
1071 (struct if_quotacheck *)karg);
1074 CERROR("mdc_ioctl(): unrecognised ioctl %#x\n", cmd);
1075 GOTO(out, rc = -ENOTTY);
1078 module_put(THIS_MODULE);
1083 static int do_set_info_async(struct obd_export *exp,
1084 obd_count keylen, void *key,
1085 obd_count vallen, void *val,
1086 struct ptlrpc_request_set *set)
1088 struct obd_import *imp = class_exp2cliimp(exp);
1089 struct ptlrpc_request *req;
1094 if (vallen != sizeof(int))
1097 spin_lock(&imp->imp_lock);
1098 if (*((int *)val)) {
1099 imp->imp_connect_flags_orig |= OBD_CONNECT_RDONLY;
1100 imp->imp_connect_data.ocd_connect_flags |= OBD_CONNECT_RDONLY;
1102 imp->imp_connect_flags_orig &= ~OBD_CONNECT_RDONLY;
1103 imp->imp_connect_data.ocd_connect_flags &= ~OBD_CONNECT_RDONLY;
1105 spin_unlock(&imp->imp_lock);
1107 req = ptlrpc_request_alloc(imp, &RQF_MDS_SET_INFO);
1111 req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_KEY,
1112 RCL_CLIENT, keylen);
1113 req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_VAL,
1114 RCL_CLIENT, vallen);
1115 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_SET_INFO);
1117 ptlrpc_request_free(req);
1121 tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1122 memcpy(tmp, key, keylen);
1123 tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_VAL);
1124 memcpy(tmp, val, vallen);
1126 ptlrpc_request_set_replen(req);
1129 ptlrpc_set_add_req(set, req);
1130 ptlrpc_check_set(NULL, set);
1132 rc = ptlrpc_queue_wait(req);
1133 ptlrpc_req_finished(req);
1139 int mdc_set_info_async(struct obd_export *exp,
1140 obd_count keylen, void *key,
1141 obd_count vallen, void *val,
1142 struct ptlrpc_request_set *set)
1144 struct obd_import *imp = class_exp2cliimp(exp);
1148 if (KEY_IS(KEY_INIT_RECOV)) {
1149 if (vallen != sizeof(int))
1151 spin_lock(&imp->imp_lock);
1152 imp->imp_initial_recov = *(int *)val;
1153 spin_unlock(&imp->imp_lock);
1154 CDEBUG(D_HA, "%s: set imp_initial_recov = %d\n",
1155 exp->exp_obd->obd_name, imp->imp_initial_recov);
1158 /* Turn off initial_recov after we try all backup servers once */
1159 if (KEY_IS(KEY_INIT_RECOV_BACKUP)) {
1160 if (vallen != sizeof(int))
1162 spin_lock(&imp->imp_lock);
1163 imp->imp_initial_recov_bk = *(int *)val;
1164 if (imp->imp_initial_recov_bk)
1165 imp->imp_initial_recov = 1;
1166 spin_unlock(&imp->imp_lock);
1167 CDEBUG(D_HA, "%s: set imp_initial_recov_bk = %d\n",
1168 exp->exp_obd->obd_name, imp->imp_initial_recov_bk);
1171 if (KEY_IS(KEY_READ_ONLY)) {
1172 rc = do_set_info_async(exp, keylen, key, vallen, val, set);
1175 if (KEY_IS(KEY_FLUSH_CTX)) {
1176 sptlrpc_import_flush_my_ctx(imp);
1179 if (KEY_IS(KEY_MDS_CONN)) {
1180 struct obd_import *imp = class_exp2cliimp(exp);
1182 /* mds-mds import */
1183 spin_lock(&imp->imp_lock);
1184 imp->imp_server_timeout = 1;
1185 spin_unlock(&imp->imp_lock);
1186 imp->imp_client->cli_request_portal = MDS_MDS_PORTAL;
1187 CDEBUG(D_OTHER|D_WARNING, "%s: timeout / 2\n", exp->exp_obd->obd_name);
1194 int mdc_get_info(struct obd_export *exp, __u32 keylen, void *key,
1195 __u32 *vallen, void *val, struct lov_stripe_md *lsm)
1199 if (KEY_IS(KEY_MAX_EASIZE)) {
1200 int mdsize, *max_easize;
1202 if (*vallen != sizeof(int))
1204 mdsize = *(int*)val;
1205 if (mdsize > exp->exp_obd->u.cli.cl_max_mds_easize)
1206 exp->exp_obd->u.cli.cl_max_mds_easize = mdsize;
1208 *max_easize = exp->exp_obd->u.cli.cl_max_mds_easize;
1211 if (KEY_IS(KEY_CONN_DATA)) {
1212 struct obd_import *imp = class_exp2cliimp(exp);
1213 struct obd_connect_data *data = val;
1215 if (*vallen != sizeof(*data))
1218 *data = imp->imp_connect_data;
1225 static int mdc_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1226 __u64 max_age, __u32 flags)
1228 struct ptlrpc_request *req;
1229 struct obd_statfs *msfs;
1230 struct obd_import *imp = NULL;
1235 /*Since the request might also come from lprocfs, so we need
1236 *sync this with client_disconnect_export Bug15684*/
1237 down_read(&obd->u.cli.cl_sem);
1238 if (obd->u.cli.cl_import)
1239 imp = class_import_get(obd->u.cli.cl_import);
1240 up_read(&obd->u.cli.cl_sem);
1244 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_STATFS,
1245 LUSTRE_MDS_VERSION, MDS_STATFS);
1247 GOTO(output, rc = -ENOMEM);
1249 ptlrpc_request_set_replen(req);
1251 if (flags & OBD_STATFS_NODELAY) {
1252 /* procfs requests not want stay in wait for avoid deadlock */
1253 req->rq_no_resend = 1;
1254 req->rq_no_delay = 1;
1257 rc = ptlrpc_queue_wait(req);
1259 /* check connection error first */
1260 if (imp->imp_connect_error)
1261 rc = imp->imp_connect_error;
1265 msfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
1267 GOTO(out, rc = -EPROTO);
1272 ptlrpc_req_finished(req);
1274 class_import_put(imp);
1278 static int mdc_pin(struct obd_export *exp, const struct lu_fid *fid,
1279 struct obd_capa *oc, struct obd_client_handle *handle,
1282 struct ptlrpc_request *req;
1283 struct mdt_body *body;
1287 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_PIN);
1291 mdc_set_capa_size(req, &RMF_CAPA1, oc);
1293 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_PIN);
1295 ptlrpc_request_free(req);
1299 mdc_pack_body(req, fid, oc, 0, 0, -1, flags);
1301 ptlrpc_request_set_replen(req);
1303 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1304 rc = ptlrpc_queue_wait(req);
1305 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1307 CERROR("Pin failed: %d\n", rc);
1311 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1313 GOTO(err_out, rc = -EPROTO);
1315 handle->och_fh = body->handle;
1316 handle->och_magic = OBD_CLIENT_HANDLE_MAGIC;
1318 OBD_ALLOC_PTR(handle->och_mod);
1319 if (handle->och_mod == NULL) {
1320 DEBUG_REQ(D_ERROR, req, "can't allocate mdc_open_data");
1321 GOTO(err_out, rc = -ENOMEM);
1323 /* will be dropped by unpin */
1324 CFS_INIT_LIST_HEAD(&handle->och_mod->mod_replay_list);
1325 list_add_tail(&req->rq_mod_list, &handle->och_mod->mod_replay_list);
1330 ptlrpc_req_finished(req);
1334 static int mdc_unpin(struct obd_export *exp, struct obd_client_handle *handle,
1337 struct ptlrpc_request *req;
1338 struct mdt_body *body;
1342 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_UNPIN,
1343 LUSTRE_MDS_VERSION, MDS_UNPIN);
1347 body = req_capsule_client_get(&req->rq_pill, &RMF_MDT_BODY);
1348 body->handle = handle->och_fh;
1351 ptlrpc_request_set_replen(req);
1353 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1354 rc = ptlrpc_queue_wait(req);
1355 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1358 CERROR("Unpin failed: %d\n", rc);
1360 ptlrpc_req_finished(req);
1362 LASSERT(!list_empty(&handle->och_mod->mod_replay_list));
1363 req = list_entry(handle->och_mod->mod_replay_list.next,
1364 typeof(*req), rq_mod_list);
1365 list_del_init(&req->rq_mod_list);
1366 ptlrpc_req_finished(req);
1367 LASSERT(list_empty(&handle->och_mod->mod_replay_list));
1369 OBD_FREE(handle->och_mod, sizeof(*handle->och_mod));
1373 int mdc_sync(struct obd_export *exp, const struct lu_fid *fid,
1374 struct obd_capa *oc, struct ptlrpc_request **request)
1376 struct ptlrpc_request *req;
1381 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_SYNC);
1385 mdc_set_capa_size(req, &RMF_CAPA1, oc);
1387 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_SYNC);
1389 ptlrpc_request_free(req);
1393 mdc_pack_body(req, fid, oc, 0, 0, -1, 0);
1395 ptlrpc_request_set_replen(req);
1397 rc = ptlrpc_queue_wait(req);
1399 ptlrpc_req_finished(req);
1405 static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
1406 enum obd_import_event event)
1410 LASSERT(imp->imp_obd == obd);
1413 case IMP_EVENT_DISCON: {
1415 /* XXX Pass event up to OBDs stack. used only for FLD now */
1416 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_DISCON, NULL);
1420 case IMP_EVENT_INACTIVE: {
1421 struct client_obd *cli = &obd->u.cli;
1423 * Flush current sequence to make client obtain new one
1424 * from server in case of disconnect/reconnect.
1425 * If range is already empty then no need to flush it.
1427 if (cli->cl_seq != NULL &&
1428 !range_is_exhausted(&cli->cl_seq->lcs_space)) {
1429 seq_client_flush(cli->cl_seq);
1432 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_INACTIVE, NULL);
1435 case IMP_EVENT_INVALIDATE: {
1436 struct ldlm_namespace *ns = obd->obd_namespace;
1438 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
1442 case IMP_EVENT_ACTIVE: {
1443 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_ACTIVE, NULL);
1447 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_OCD, NULL);
1451 CERROR("Unknown import event %x\n", event);
1457 static int mdc_fid_init(struct obd_export *exp)
1459 struct client_obd *cli = &exp->exp_obd->u.cli;
1464 OBD_ALLOC_PTR(cli->cl_seq);
1465 if (cli->cl_seq == NULL)
1468 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
1470 GOTO(out_free_seq, rc = -ENOMEM);
1472 snprintf(prefix, MAX_OBD_NAME + 5, "srv-%s",
1473 exp->exp_obd->obd_name);
1475 /* Init client side sequence-manager */
1476 rc = seq_client_init(cli->cl_seq, exp,
1477 LUSTRE_SEQ_METADATA,
1479 OBD_FREE(prefix, MAX_OBD_NAME + 5);
1481 GOTO(out_free_seq, rc);
1485 OBD_FREE_PTR(cli->cl_seq);
1490 static int mdc_fid_fini(struct obd_export *exp)
1492 struct client_obd *cli = &exp->exp_obd->u.cli;
1495 if (cli->cl_seq != NULL) {
1496 seq_client_fini(cli->cl_seq);
1497 OBD_FREE_PTR(cli->cl_seq);
1504 int mdc_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
1505 struct md_op_data *op_data)
1507 struct client_obd *cli = &exp->exp_obd->u.cli;
1508 struct lu_client_seq *seq = cli->cl_seq;
1510 RETURN(seq_client_alloc_fid(seq, fid));
1513 /* XXX This method is used only to clear current fid seq
1514 * once fld/mds insert failed */
1515 static int mdc_fid_delete(struct obd_export *exp, const struct lu_fid *fid)
1517 struct client_obd *cli = &exp->exp_obd->u.cli;
1519 seq_client_flush(cli->cl_seq);
1523 struct obd_uuid *mdc_get_uuid(struct obd_export *exp) {
1524 struct client_obd *cli = &exp->exp_obd->u.cli;
1525 return &cli->cl_target_uuid;
1528 static int mdc_setup(struct obd_device *obd, struct lustre_cfg *cfg)
1530 struct client_obd *cli = &obd->u.cli;
1531 struct lprocfs_static_vars lvars = { 0 };
1535 OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1536 if (!cli->cl_rpc_lock)
1538 mdc_init_rpc_lock(cli->cl_rpc_lock);
1542 OBD_ALLOC(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1543 if (!cli->cl_setattr_lock)
1544 GOTO(err_rpc_lock, rc = -ENOMEM);
1545 mdc_init_rpc_lock(cli->cl_setattr_lock);
1547 OBD_ALLOC(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1548 if (!cli->cl_close_lock)
1549 GOTO(err_setattr_lock, rc = -ENOMEM);
1550 mdc_init_rpc_lock(cli->cl_close_lock);
1552 rc = client_obd_setup(obd, cfg);
1554 GOTO(err_close_lock, rc);
1555 lprocfs_mdc_init_vars(&lvars);
1556 lprocfs_obd_setup(obd, lvars.obd_vars);
1557 sptlrpc_lprocfs_cliobd_attach(obd);
1558 ptlrpc_lprocfs_register_obd(obd);
1560 rc = obd_llog_init(obd, &obd->obd_olg, obd, 0, NULL, NULL);
1563 CERROR("failed to setup llogging subsystems\n");
1569 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1571 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1573 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1578 /* Initialize the default and maximum LOV EA and cookie sizes. This allows
1579 * us to make MDS RPCs with large enough reply buffers to hold the
1580 * maximum-sized (= maximum striped) EA and cookie without having to
1581 * calculate this (via a call into the LOV + OSCs) each time we make an RPC. */
1582 static int mdc_init_ea_size(struct obd_export *exp, int easize,
1583 int def_easize, int cookiesize)
1585 struct obd_device *obd = exp->exp_obd;
1586 struct client_obd *cli = &obd->u.cli;
1589 if (cli->cl_max_mds_easize < easize)
1590 cli->cl_max_mds_easize = easize;
1592 if (cli->cl_default_mds_easize < def_easize)
1593 cli->cl_default_mds_easize = def_easize;
1595 if (cli->cl_max_mds_cookiesize < cookiesize)
1596 cli->cl_max_mds_cookiesize = cookiesize;
1601 static int mdc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
1607 case OBD_CLEANUP_EARLY:
1608 case OBD_CLEANUP_EXPORTS:
1609 /* If we set up but never connected, the
1610 client import will not have been cleaned. */
1611 if (obd->u.cli.cl_import) {
1612 struct obd_import *imp;
1613 imp = obd->u.cli.cl_import;
1614 CERROR("client import never connected\n");
1615 ptlrpc_invalidate_import(imp);
1616 ptlrpc_free_rq_pool(imp->imp_rq_pool);
1617 class_destroy_import(imp);
1618 obd->u.cli.cl_import = NULL;
1620 rc = obd_llog_finish(obd, 0);
1622 CERROR("failed to cleanup llogging subsystems\n");
1628 static int mdc_cleanup(struct obd_device *obd)
1630 struct client_obd *cli = &obd->u.cli;
1632 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1633 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1634 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1636 ptlrpc_lprocfs_unregister_obd(obd);
1637 lprocfs_obd_cleanup(obd);
1640 return client_obd_cleanup(obd);
1644 static int mdc_llog_init(struct obd_device *obd, struct obd_llog_group *olg,
1645 struct obd_device *tgt, int count,
1646 struct llog_catid *logid, struct obd_uuid *uuid)
1648 struct llog_ctxt *ctxt;
1652 LASSERT(olg == &obd->obd_olg);
1654 rc = llog_setup(obd, olg, LLOG_LOVEA_REPL_CTXT, tgt, 0,
1655 NULL, &llog_client_ops);
1657 ctxt = llog_get_context(obd, LLOG_LOVEA_REPL_CTXT);
1658 llog_initiator_connect(ctxt);
1659 llog_ctxt_put(ctxt);
1665 static int mdc_llog_finish(struct obd_device *obd, int count)
1667 struct llog_ctxt *ctxt;
1671 ctxt = llog_get_context(obd, LLOG_LOVEA_REPL_CTXT);
1673 rc = llog_cleanup(ctxt);
1678 static int mdc_process_config(struct obd_device *obd, obd_count len, void *buf)
1680 struct lustre_cfg *lcfg = buf;
1681 struct lprocfs_static_vars lvars = { 0 };
1684 lprocfs_mdc_init_vars(&lvars);
1686 switch (lcfg->lcfg_command) {
1687 case LCFG_SPTLRPC_CONF:
1688 rc = sptlrpc_cliobd_process_config(obd, lcfg);
1691 rc = class_process_proc_param(PARAM_MDC, lvars.obd_vars,
1699 /* get remote permission for current user on fid */
1700 int mdc_get_remote_perm(struct obd_export *exp, const struct lu_fid *fid,
1701 struct obd_capa *oc, __u32 suppgid,
1702 struct ptlrpc_request **request)
1704 struct ptlrpc_request *req;
1708 LASSERT(client_is_remote(exp));
1711 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR);
1715 mdc_set_capa_size(req, &RMF_CAPA1, oc);
1717 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR);
1719 ptlrpc_request_free(req);
1723 mdc_pack_body(req, fid, oc, OBD_MD_FLRMTPERM, 0, suppgid, 0);
1725 req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER,
1726 sizeof(struct mdt_remote_perm));
1728 ptlrpc_request_set_replen(req);
1730 rc = ptlrpc_queue_wait(req);
1732 ptlrpc_req_finished(req);
1738 static int mdc_interpret_renew_capa(const struct lu_env *env,
1739 struct ptlrpc_request *req, void *unused,
1742 struct obd_capa *oc = req->rq_async_args.pointer_arg[0];
1743 renew_capa_cb_t cb = req->rq_async_args.pointer_arg[1];
1744 struct mdt_body *body = NULL;
1745 struct lustre_capa *capa;
1749 GOTO(out, capa = ERR_PTR(status));
1751 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1753 GOTO(out, capa = ERR_PTR(-EFAULT));
1755 if ((body->valid & OBD_MD_FLOSSCAPA) == 0)
1756 GOTO(out, capa = ERR_PTR(-ENOENT));
1758 capa = req_capsule_server_get(&req->rq_pill, &RMF_CAPA2);
1760 GOTO(out, capa = ERR_PTR(-EFAULT));
1767 static int mdc_renew_capa(struct obd_export *exp, struct obd_capa *oc,
1770 struct ptlrpc_request *req;
1773 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_GETATTR,
1774 LUSTRE_MDS_VERSION, MDS_GETATTR);
1778 /* NB, OBD_MD_FLOSSCAPA is set here, but it doesn't necessarily mean the
1779 * capa to renew is oss capa.
1781 mdc_pack_body(req, &oc->c_capa.lc_fid, oc, OBD_MD_FLOSSCAPA, 0, -1, 0);
1782 ptlrpc_request_set_replen(req);
1784 req->rq_async_args.pointer_arg[0] = oc;
1785 req->rq_async_args.pointer_arg[1] = cb;
1786 req->rq_interpret_reply = mdc_interpret_renew_capa;
1787 ptlrpcd_add_req(req);
1791 static int mdc_connect(const struct lu_env *env,
1792 struct lustre_handle *dlm_handle,
1793 struct obd_device *obd, struct obd_uuid *cluuid,
1794 struct obd_connect_data *data,
1797 struct obd_import *imp = obd->u.cli.cl_import;
1799 /* mds-mds import features */
1800 if (data && (data->ocd_connect_flags & OBD_CONNECT_MDS_MDS)) {
1801 spin_lock(&imp->imp_lock);
1802 imp->imp_server_timeout = 1;
1803 spin_unlock(&imp->imp_lock);
1804 imp->imp_client->cli_request_portal = MDS_MDS_PORTAL;
1805 CDEBUG(D_OTHER, "%s: Set 'mds' portal and timeout\n",
1809 return client_connect_import(env, dlm_handle, obd, cluuid, data, NULL);
1812 struct obd_ops mdc_obd_ops = {
1813 .o_owner = THIS_MODULE,
1814 .o_setup = mdc_setup,
1815 .o_precleanup = mdc_precleanup,
1816 .o_cleanup = mdc_cleanup,
1817 .o_add_conn = client_import_add_conn,
1818 .o_del_conn = client_import_del_conn,
1819 .o_connect = mdc_connect,
1820 .o_disconnect = client_disconnect_export,
1821 .o_iocontrol = mdc_iocontrol,
1822 .o_set_info_async = mdc_set_info_async,
1823 .o_statfs = mdc_statfs,
1825 .o_unpin = mdc_unpin,
1826 .o_fid_init = mdc_fid_init,
1827 .o_fid_fini = mdc_fid_fini,
1828 .o_fid_alloc = mdc_fid_alloc,
1829 .o_fid_delete = mdc_fid_delete,
1830 .o_import_event = mdc_import_event,
1831 .o_llog_init = mdc_llog_init,
1832 .o_llog_finish = mdc_llog_finish,
1833 .o_get_info = mdc_get_info,
1834 .o_process_config = mdc_process_config,
1835 .o_get_uuid = mdc_get_uuid,
1838 struct md_ops mdc_md_ops = {
1839 .m_getstatus = mdc_getstatus,
1840 .m_change_cbdata = mdc_change_cbdata,
1841 .m_close = mdc_close,
1842 .m_create = mdc_create,
1843 .m_done_writing = mdc_done_writing,
1844 .m_enqueue = mdc_enqueue,
1845 .m_getattr = mdc_getattr,
1846 .m_getattr_name = mdc_getattr_name,
1847 .m_intent_lock = mdc_intent_lock,
1849 .m_is_subdir = mdc_is_subdir,
1850 .m_rename = mdc_rename,
1851 .m_setattr = mdc_setattr,
1852 .m_setxattr = mdc_setxattr,
1853 .m_getxattr = mdc_getxattr,
1855 .m_readpage = mdc_readpage,
1856 .m_unlink = mdc_unlink,
1857 .m_cancel_unused = mdc_cancel_unused,
1858 .m_init_ea_size = mdc_init_ea_size,
1859 .m_set_lock_data = mdc_set_lock_data,
1860 .m_lock_match = mdc_lock_match,
1861 .m_get_lustre_md = mdc_get_lustre_md,
1862 .m_free_lustre_md = mdc_free_lustre_md,
1863 .m_set_open_replay_data = mdc_set_open_replay_data,
1864 .m_clear_open_replay_data = mdc_clear_open_replay_data,
1865 .m_renew_capa = mdc_renew_capa,
1866 .m_get_remote_perm = mdc_get_remote_perm,
1867 .m_intent_getattr_async = mdc_intent_getattr_async,
1868 .m_revalidate_lock = mdc_revalidate_lock
1871 extern quota_interface_t mdc_quota_interface;
1873 int __init mdc_init(void)
1876 struct lprocfs_static_vars lvars = { 0 };
1877 lprocfs_mdc_init_vars(&lvars);
1879 request_module("lquota");
1880 quota_interface = PORTAL_SYMBOL_GET(mdc_quota_interface);
1881 init_obd_quota_ops(quota_interface, &mdc_obd_ops);
1883 rc = class_register_type(&mdc_obd_ops, &mdc_md_ops, lvars.module_vars,
1884 LUSTRE_MDC_NAME, NULL);
1885 if (rc && quota_interface)
1886 PORTAL_SYMBOL_PUT(mdc_quota_interface);
1892 static void /*__exit*/ mdc_exit(void)
1894 if (quota_interface)
1895 PORTAL_SYMBOL_PUT(mdc_quota_interface);
1897 class_unregister_type(LUSTRE_MDC_NAME);
1900 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
1901 MODULE_DESCRIPTION("Lustre Metadata Client");
1902 MODULE_LICENSE("GPL");
1904 module_init(mdc_init);
1905 module_exit(mdc_exit);