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"
59 #include <lustre/lustre_idl.h>
61 #define REQUEST_MINOR 244
63 static quota_interface_t *quota_interface;
64 extern quota_interface_t mdc_quota_interface;
66 static int mdc_cleanup(struct obd_device *obd);
68 int mdc_unpack_capa(struct obd_export *exp, struct ptlrpc_request *req,
69 const struct req_msg_field *field, struct obd_capa **oc)
71 struct lustre_capa *capa;
75 /* swabbed already in mdc_enqueue */
76 capa = req_capsule_server_get(&req->rq_pill, field);
80 c = alloc_capa(CAPA_SITE_CLIENT);
82 CDEBUG(D_INFO, "alloc capa failed!\n");
91 /* Helper that implements most of mdc_getstatus and signal_completed_replay. */
92 /* XXX this should become mdc_get_info("key"), sending MDS_GET_INFO RPC */
93 static int send_getstatus(struct obd_import *imp, struct lu_fid *rootfid,
94 struct obd_capa **pc, int level, int msg_flags)
96 struct ptlrpc_request *req;
97 struct mdt_body *body;
101 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_GETSTATUS,
102 LUSTRE_MDS_VERSION, MDS_GETSTATUS);
106 mdc_pack_body(req, NULL, NULL, 0, 0, -1, 0);
107 lustre_msg_add_flags(req->rq_reqmsg, msg_flags);
108 req->rq_send_state = level;
110 ptlrpc_request_set_replen(req);
112 rc = ptlrpc_queue_wait(req);
116 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
118 GOTO(out, rc = -EPROTO);
120 if (body->valid & OBD_MD_FLMDSCAPA) {
121 rc = mdc_unpack_capa(NULL, req, &RMF_CAPA1, pc);
126 *rootfid = body->fid1;
128 "root fid="DFID", last_committed="LPU64", last_xid="LPU64"\n",
130 lustre_msg_get_last_committed(req->rq_repmsg),
131 lustre_msg_get_last_xid(req->rq_repmsg));
134 ptlrpc_req_finished(req);
138 /* This should be mdc_get_info("rootfid") */
139 int mdc_getstatus(struct obd_export *exp, struct lu_fid *rootfid,
140 struct obd_capa **pc)
142 return send_getstatus(class_exp2cliimp(exp), rootfid, pc,
147 * This function now is known to always saying that it will receive 4 buffers
148 * from server. Even for cases when acl_size and md_size is zero, RPC header
149 * will contain 4 fields and RPC itself will contain zero size fields. This is
150 * because mdt_getattr*() _always_ returns 4 fields, but if acl is not needed
151 * and thus zero, it shrinks it, making zero size. The same story about
152 * md_size. And this is course of problem when client waits for smaller number
153 * of fields. This issue will be fixed later when client gets aware of RPC
156 static int mdc_getattr_common(struct obd_export *exp,
157 struct ptlrpc_request *req)
159 struct req_capsule *pill = &req->rq_pill;
160 struct mdt_body *body;
165 /* Request message already built. */
166 rc = ptlrpc_queue_wait(req);
170 /* sanity check for the reply */
171 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
175 CDEBUG(D_NET, "mode: %o\n", body->mode);
177 if (body->eadatasize != 0) {
178 eadata = req_capsule_server_sized_get(pill, &RMF_MDT_MD,
184 if (body->valid & OBD_MD_FLRMTPERM) {
185 struct mdt_remote_perm *perm;
187 LASSERT(client_is_remote(exp));
188 perm = req_capsule_server_swab_get(pill, &RMF_ACL,
189 lustre_swab_mdt_remote_perm);
194 if (body->valid & OBD_MD_FLMDSCAPA) {
195 struct lustre_capa *capa;
196 capa = req_capsule_server_get(pill, &RMF_CAPA1);
204 int mdc_getattr(struct obd_export *exp, const struct lu_fid *fid,
205 struct obd_capa *oc, obd_valid valid, int ea_size,
206 struct ptlrpc_request **request)
208 struct ptlrpc_request *req;
213 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR);
217 mdc_set_capa_size(req, &RMF_CAPA1, oc);
219 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR);
221 ptlrpc_request_free(req);
225 /* MDS_BFLAG_EXT_FLAGS: request "new" flags(bug 9486) */
226 mdc_pack_body(req, fid, oc, valid, ea_size, -1, MDS_BFLAG_EXT_FLAGS);
228 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER, ea_size);
229 if (valid & OBD_MD_FLRMTPERM) {
230 LASSERT(client_is_remote(exp));
231 req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER,
232 sizeof(struct mdt_remote_perm));
234 ptlrpc_request_set_replen(req);
236 rc = mdc_getattr_common(exp, req);
238 ptlrpc_req_finished(req);
244 int mdc_getattr_name(struct obd_export *exp, const struct lu_fid *fid,
245 struct obd_capa *oc, const char *filename, int namelen,
246 obd_valid valid, int ea_size, __u32 suppgid,
247 struct ptlrpc_request **request)
249 struct ptlrpc_request *req;
254 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
255 &RQF_MDS_GETATTR_NAME);
259 mdc_set_capa_size(req, &RMF_CAPA1, oc);
260 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT, namelen);
262 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR_NAME);
264 ptlrpc_request_free(req);
268 /* MDS_BFLAG_EXT_FLAGS: request "new" flags(bug 9486) */
269 mdc_pack_body(req, fid, oc, valid, ea_size, suppgid,
270 MDS_BFLAG_EXT_FLAGS);
273 char *name = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
274 LASSERT(strnlen(filename, namelen) == namelen - 1);
275 memcpy(name, filename, namelen);
278 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER, ea_size);
279 ptlrpc_request_set_replen(req);
281 rc = mdc_getattr_common(exp, req);
283 ptlrpc_req_finished(req);
289 static int mdc_is_subdir(struct obd_export *exp,
290 const struct lu_fid *pfid,
291 const struct lu_fid *cfid,
292 struct ptlrpc_request **request)
294 struct ptlrpc_request *req;
300 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
301 &RQF_MDS_IS_SUBDIR, LUSTRE_MDS_VERSION,
306 mdc_is_subdir_pack(req, pfid, cfid, 0);
307 ptlrpc_request_set_replen(req);
309 rc = ptlrpc_queue_wait(req);
310 if (rc && rc != -EREMOTE)
311 ptlrpc_req_finished(req);
317 static int mdc_xattr_common(struct obd_export *exp,const struct req_format *fmt,
318 const struct lu_fid *fid,
319 struct obd_capa *oc, int opcode, obd_valid valid,
320 const char *xattr_name, const char *input,
321 int input_size, int output_size, int flags,
322 __u32 suppgid, struct ptlrpc_request **request)
324 struct ptlrpc_request *req;
325 int xattr_namelen = 0;
331 req = ptlrpc_request_alloc(class_exp2cliimp(exp), fmt);
335 mdc_set_capa_size(req, &RMF_CAPA1, oc);
337 xattr_namelen = strlen(xattr_name) + 1;
338 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
343 req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_CLIENT,
347 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, opcode);
349 ptlrpc_request_free(req);
353 if (opcode == MDS_REINT) {
354 struct mdt_rec_setxattr *rec;
356 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
357 sizeof(struct mdt_rec_reint));
358 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
359 rec->sx_opcode = REINT_SETXATTR;
361 * cfs_curproc_fs{u,g}id() should replace
362 * current->fs{u,g}id for portability.
364 rec->sx_fsuid = current->fsuid;
365 rec->sx_fsgid = current->fsgid;
366 rec->sx_cap = cfs_curproc_cap_pack();
367 rec->sx_suppgid1 = suppgid;
368 rec->sx_suppgid2 = -1;
370 rec->sx_valid = valid | OBD_MD_FLCTIME;
371 rec->sx_time = cfs_time_current_sec();
372 rec->sx_size = output_size;
373 rec->sx_flags = flags;
375 mdc_pack_capa(req, &RMF_CAPA1, oc);
377 mdc_pack_body(req, fid, oc, valid, output_size, suppgid, flags);
381 tmp = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
382 memcpy(tmp, xattr_name, xattr_namelen);
385 tmp = req_capsule_client_get(&req->rq_pill, &RMF_EADATA);
386 memcpy(tmp, input, input_size);
389 if (req_capsule_has_field(&req->rq_pill, &RMF_EADATA, RCL_SERVER))
390 req_capsule_set_size(&req->rq_pill, &RMF_EADATA,
391 RCL_SERVER, output_size);
392 ptlrpc_request_set_replen(req);
395 if (opcode == MDS_REINT)
396 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
398 rc = ptlrpc_queue_wait(req);
400 if (opcode == MDS_REINT)
401 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
404 ptlrpc_req_finished(req);
410 int mdc_setxattr(struct obd_export *exp, const struct lu_fid *fid,
411 struct obd_capa *oc, obd_valid valid, const char *xattr_name,
412 const char *input, int input_size, int output_size,
413 int flags, __u32 suppgid, struct ptlrpc_request **request)
415 return mdc_xattr_common(exp, &RQF_MDS_REINT_SETXATTR,
416 fid, oc, MDS_REINT, valid, xattr_name,
417 input, input_size, output_size, flags,
421 int mdc_getxattr(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, struct ptlrpc_request **request)
426 return mdc_xattr_common(exp, &RQF_MDS_GETXATTR,
427 fid, oc, MDS_GETXATTR, valid, xattr_name,
428 input, input_size, output_size, flags,
432 #ifdef CONFIG_FS_POSIX_ACL
433 static int mdc_unpack_acl(struct ptlrpc_request *req, struct lustre_md *md)
435 struct req_capsule *pill = &req->rq_pill;
436 struct mdt_body *body = md->body;
437 struct posix_acl *acl;
445 buf = req_capsule_server_sized_get(pill, &RMF_ACL, body->aclsize);
450 acl = posix_acl_from_xattr(buf, body->aclsize);
453 CERROR("convert xattr to acl: %d\n", rc);
457 rc = posix_acl_valid(acl);
459 CERROR("validate acl: %d\n", rc);
460 posix_acl_release(acl);
468 #define mdc_unpack_acl(req, md) 0
471 int mdc_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
472 struct obd_export *dt_exp, struct obd_export *md_exp,
473 struct lustre_md *md)
475 struct req_capsule *pill = &req->rq_pill;
480 memset(md, 0, sizeof(*md));
482 md->body = req_capsule_server_get(pill, &RMF_MDT_BODY);
483 LASSERT(md->body != NULL);
485 if (md->body->valid & OBD_MD_FLEASIZE) {
487 struct lov_mds_md *lmm;
489 if (!S_ISREG(md->body->mode)) {
490 CDEBUG(D_INFO, "OBD_MD_FLEASIZE set, should be a "
491 "regular file, but is not\n");
492 GOTO(out, rc = -EPROTO);
495 if (md->body->eadatasize == 0) {
496 CDEBUG(D_INFO, "OBD_MD_FLEASIZE set, "
497 "but eadatasize 0\n");
498 GOTO(out, rc = -EPROTO);
500 lmmsize = md->body->eadatasize;
501 lmm = req_capsule_server_sized_get(pill, &RMF_MDT_MD, lmmsize);
503 GOTO(out, rc = -EPROTO);
505 rc = obd_unpackmd(dt_exp, &md->lsm, lmm, lmmsize);
509 if (rc < sizeof(*md->lsm)) {
510 CDEBUG(D_INFO, "lsm size too small: "
511 "rc < sizeof (*md->lsm) (%d < %d)\n",
512 rc, (int)sizeof(*md->lsm));
513 GOTO(out, rc = -EPROTO);
516 } else if (md->body->valid & OBD_MD_FLDIREA) {
518 struct lov_mds_md *lmv;
520 if(!S_ISDIR(md->body->mode)) {
521 CDEBUG(D_INFO, "OBD_MD_FLDIREA set, should be a "
522 "directory, but is not\n");
523 GOTO(out, rc = -EPROTO);
526 if (md->body->eadatasize == 0) {
527 CDEBUG(D_INFO, "OBD_MD_FLDIREA is set, "
528 "but eadatasize 0\n");
531 if (md->body->valid & OBD_MD_MEA) {
532 lmvsize = md->body->eadatasize;
533 lmv = req_capsule_server_sized_get(pill, &RMF_MDT_MD,
536 GOTO(out, rc = -EPROTO);
538 rc = obd_unpackmd(md_exp, (void *)&md->mea, lmv,
543 if (rc < sizeof(*md->mea)) {
544 CDEBUG(D_INFO, "size too small: "
545 "rc < sizeof(*md->mea) (%d < %d)\n",
546 rc, (int)sizeof(*md->mea));
547 GOTO(out, rc = -EPROTO);
553 if (md->body->valid & OBD_MD_FLRMTPERM) {
554 /* remote permission */
555 LASSERT(client_is_remote(exp));
556 md->remote_perm = req_capsule_server_swab_get(pill, &RMF_ACL,
557 lustre_swab_mdt_remote_perm);
558 if (!md->remote_perm)
559 GOTO(out, rc = -EPROTO);
561 else if (md->body->valid & OBD_MD_FLACL) {
562 /* for ACL, it's possible that FLACL is set but aclsize is zero.
563 * only when aclsize != 0 there's an actual segment for ACL
566 if (md->body->aclsize) {
567 rc = mdc_unpack_acl(req, md);
570 #ifdef CONFIG_FS_POSIX_ACL
572 md->posix_acl = NULL;
576 if (md->body->valid & OBD_MD_FLMDSCAPA) {
577 struct obd_capa *oc = NULL;
579 rc = mdc_unpack_capa(NULL, req, &RMF_CAPA1, &oc);
585 if (md->body->valid & OBD_MD_FLOSSCAPA) {
586 struct obd_capa *oc = NULL;
588 rc = mdc_unpack_capa(NULL, req, &RMF_CAPA2, &oc);
598 capa_put(md->oss_capa);
602 capa_put(md->mds_capa);
605 #ifdef CONFIG_FS_POSIX_ACL
606 posix_acl_release(md->posix_acl);
609 obd_free_memmd(dt_exp, &md->lsm);
614 int mdc_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
621 * Handles both OPEN and SETATTR RPCs for OPEN-CLOSE and SETATTR-DONE_WRITING
624 void mdc_replay_open(struct ptlrpc_request *req)
626 struct md_open_data *mod = req->rq_cb_data;
627 struct ptlrpc_request *close_req;
628 struct obd_client_handle *och;
629 struct lustre_handle old;
630 struct mdt_body *body;
634 DEBUG_REQ(D_ERROR, req,
635 "Can't properly replay without open data.");
640 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
641 LASSERT(body != NULL);
645 struct lustre_handle *file_fh;
647 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
649 file_fh = &och->och_fh;
650 CDEBUG(D_HA, "updating handle from "LPX64" to "LPX64"\n",
651 file_fh->cookie, body->handle.cookie);
653 *file_fh = body->handle;
655 close_req = mod->mod_close_req;
656 if (close_req != NULL) {
657 __u32 opc = lustre_msg_get_opc(close_req->rq_reqmsg);
658 struct mdt_epoch *epoch;
660 LASSERT(opc == MDS_CLOSE || opc == MDS_DONE_WRITING);
661 epoch = req_capsule_client_get(&close_req->rq_pill,
666 LASSERT(!memcmp(&old, &epoch->handle, sizeof(old)));
667 DEBUG_REQ(D_HA, close_req, "updating close body with new fh");
668 epoch->handle = body->handle;
673 void mdc_commit_open(struct ptlrpc_request *req)
675 struct md_open_data *mod = req->rq_cb_data;
679 if (mod->mod_close_req != NULL)
680 mod->mod_close_req->rq_cb_data = NULL;
682 if (mod->mod_och != NULL)
683 mod->mod_och->och_mod = NULL;
685 OBD_FREE(mod, sizeof(*mod));
686 req->rq_cb_data = NULL;
689 int mdc_set_open_replay_data(struct obd_export *exp,
690 struct obd_client_handle *och,
691 struct ptlrpc_request *open_req)
693 struct md_open_data *mod;
694 struct mdt_rec_create *rec;
695 struct mdt_body *body;
696 struct obd_import *imp = open_req->rq_import;
699 if (!open_req->rq_replay)
702 rec = req_capsule_client_get(&open_req->rq_pill, &RMF_REC_REINT);
703 body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY);
704 LASSERT(rec != NULL);
705 /* Incoming message in my byte order (it's been swabbed). */
706 /* Outgoing messages always in my byte order. */
707 LASSERT(body != NULL);
709 /* Only if the import is replayable, we set replay_open data */
710 if (och && imp->imp_replayable) {
713 DEBUG_REQ(D_ERROR, open_req,
714 "Can't allocate md_open_data");
718 spin_lock(&open_req->rq_lock);
721 mod->mod_open_req = open_req;
722 open_req->rq_cb_data = mod;
723 open_req->rq_commit_cb = mdc_commit_open;
724 spin_unlock(&open_req->rq_lock);
727 rec->cr_fid2 = body->fid1;
728 rec->cr_ioepoch = body->ioepoch;
729 rec->cr_old_handle.cookie = body->handle.cookie;
730 open_req->rq_replay_cb = mdc_replay_open;
731 if (!fid_is_sane(&body->fid1)) {
732 DEBUG_REQ(D_ERROR, open_req, "Saving replay request with "
737 DEBUG_REQ(D_RPCTRACE, open_req, "Set up open replay data");
741 int mdc_clear_open_replay_data(struct obd_export *exp,
742 struct obd_client_handle *och)
744 struct md_open_data *mod = och->och_mod;
748 * Don't free the structure now (it happens in mdc_commit_open(), after
749 * we're sure we won't need to fix up the close request in the future),
750 * but make sure that replay doesn't poke at the och, which is about to
753 LASSERT(mod != LP_POISON);
761 int mdc_close(struct obd_export *exp, struct md_op_data *op_data,
762 struct md_open_data *mod, struct ptlrpc_request **request)
764 struct obd_device *obd = class_exp2obd(exp);
765 struct ptlrpc_request *req;
770 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_CLOSE);
774 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
776 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_CLOSE);
778 ptlrpc_request_free(req);
782 /* To avoid a livelock (bug 7034), we need to send CLOSE RPCs to a
783 * portal whose threads are not taking any DLM locks and are therefore
784 * always progressing */
785 req->rq_request_portal = MDS_READPAGE_PORTAL;
786 ptlrpc_at_set_req_timeout(req);
788 /* Ensure that this close's handle is fixed up during replay. */
789 if (likely(mod != NULL)) {
790 LASSERTF(mod->mod_open_req->rq_type != LI_POISON,
791 "POISONED open %p!\n", mod->mod_open_req);
793 mod->mod_close_req = req;
794 DEBUG_REQ(D_HA, mod->mod_open_req, "matched open");
795 /* We no longer want to preserve this open for replay even
796 * though the open was committed. b=3632, b=3633 */
797 spin_lock(&mod->mod_open_req->rq_lock);
798 mod->mod_open_req->rq_replay = 0;
799 spin_unlock(&mod->mod_open_req->rq_lock);
801 CDEBUG(D_HA, "couldn't find open req; expecting close error\n");
804 mdc_close_pack(req, op_data);
806 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER,
807 obd->u.cli.cl_max_mds_easize);
808 req_capsule_set_size(&req->rq_pill, &RMF_LOGCOOKIES, RCL_SERVER,
809 obd->u.cli.cl_max_mds_cookiesize);
811 ptlrpc_request_set_replen(req);
813 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
814 rc = ptlrpc_queue_wait(req);
815 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
817 if (req->rq_repmsg == NULL) {
818 CDEBUG(D_RPCTRACE, "request failed to send: %p, %d\n", req,
821 rc = req->rq_status ?: -EIO;
822 } else if (rc == 0 || rc == -EAGAIN) {
823 struct mdt_body *body;
825 rc = lustre_msg_get_status(req->rq_repmsg);
826 if (lustre_msg_get_type(req->rq_repmsg) == PTL_RPC_MSG_ERR) {
827 DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, err "
831 } else if (mod == NULL) {
832 if (req->rq_import->imp_replayable)
833 CERROR("Unexpected: can't find md_open_data,"
834 "but close succeeded with replayable imp"
836 "http://bugzilla.lustre.org/\n");
839 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
848 int mdc_done_writing(struct obd_export *exp, struct md_op_data *op_data,
849 struct md_open_data *mod)
851 struct obd_device *obd = class_exp2obd(exp);
852 struct ptlrpc_request *req;
856 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
857 &RQF_MDS_DONE_WRITING);
861 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
862 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_DONE_WRITING);
864 ptlrpc_request_free(req);
869 LASSERTF(mod->mod_open_req->rq_type != LI_POISON,
870 "POISONED setattr %p!\n", mod->mod_open_req);
872 mod->mod_close_req = req;
873 DEBUG_REQ(D_HA, mod->mod_open_req, "matched setattr");
874 /* We no longer want to preserve this open for replay even
875 * though the open was committed. b=3632, b=3633 */
876 spin_lock(&mod->mod_open_req->rq_lock);
877 mod->mod_open_req->rq_replay = 0;
878 spin_unlock(&mod->mod_open_req->rq_lock);
881 mdc_close_pack(req, op_data);
882 ptlrpc_request_set_replen(req);
884 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
885 rc = ptlrpc_queue_wait(req);
886 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
888 ptlrpc_req_finished(req);
892 #ifdef HAVE_SPLIT_SUPPORT
893 int mdc_sendpage(struct obd_export *exp, const struct lu_fid *fid,
894 const struct page *page, int offset)
896 struct ptlrpc_request *req;
897 struct ptlrpc_bulk_desc *desc;
901 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_WRITEPAGE);
905 /* FIXME: capa doesn't support split yet */
906 mdc_set_capa_size(req, &RMF_CAPA1, NULL);
908 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_WRITEPAGE);
910 ptlrpc_request_free(req);
914 req->rq_request_portal = MDS_READPAGE_PORTAL;
915 ptlrpc_at_set_req_timeout(req);
917 desc = ptlrpc_prep_bulk_imp(req, 1, BULK_GET_SOURCE, MDS_BULK_PORTAL);
919 GOTO(out, rc = -ENOMEM);
921 /* NB req now owns desc and will free it when it gets freed. */
922 ptlrpc_prep_bulk_page(desc, (struct page *)page, 0, offset);
923 mdc_readdir_pack(req, 0, offset, fid, NULL);
925 ptlrpc_request_set_replen(req);
926 rc = ptlrpc_queue_wait(req);
930 rc = sptlrpc_cli_unwrap_bulk_write(req, req->rq_bulk);
932 ptlrpc_req_finished(req);
935 EXPORT_SYMBOL(mdc_sendpage);
938 int mdc_readpage(struct obd_export *exp, const struct lu_fid *fid,
939 struct obd_capa *oc, __u64 offset, struct page *page,
940 struct ptlrpc_request **request)
942 struct ptlrpc_request *req;
943 struct ptlrpc_bulk_desc *desc;
948 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_READPAGE);
952 mdc_set_capa_size(req, &RMF_CAPA1, oc);
954 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_READPAGE);
956 ptlrpc_request_free(req);
960 req->rq_request_portal = MDS_READPAGE_PORTAL;
961 ptlrpc_at_set_req_timeout(req);
963 desc = ptlrpc_prep_bulk_imp(req, 1, BULK_PUT_SINK, MDS_BULK_PORTAL);
965 ptlrpc_request_free(req);
969 /* NB req now owns desc and will free it when it gets freed */
970 ptlrpc_prep_bulk_page(desc, page, 0, CFS_PAGE_SIZE);
971 mdc_readdir_pack(req, offset, CFS_PAGE_SIZE, fid, oc);
973 ptlrpc_request_set_replen(req);
974 rc = ptlrpc_queue_wait(req);
976 ptlrpc_req_finished(req);
980 rc = sptlrpc_cli_unwrap_bulk_read(req, req->rq_bulk,
981 req->rq_bulk->bd_nob_transferred);
983 ptlrpc_req_finished(req);
987 if (req->rq_bulk->bd_nob_transferred != CFS_PAGE_SIZE) {
988 CERROR("Unexpected # bytes transferred: %d (%ld expected)\n",
989 req->rq_bulk->bd_nob_transferred, CFS_PAGE_SIZE);
990 ptlrpc_req_finished(req);
998 /* This routine is quite similar to mdt_ioc_fid2path() */
999 int mdc_ioc_fid2path(struct obd_export *exp, struct obd_ioctl_data *data)
1001 struct getinfo_fid2path *fp = NULL;
1002 int keylen = size_round(sizeof(KEY_FID2PATH)) + sizeof(*fp);
1003 int pathlen = data->ioc_plen1;
1004 __u32 vallen = pathlen + sizeof(*fp);
1005 int alloclen = keylen + vallen;
1009 if (pathlen > PATH_MAX)
1014 OBD_ALLOC(buf, alloclen);
1017 fp = buf + size_round(sizeof(KEY_FID2PATH));
1018 memcpy(buf, KEY_FID2PATH, sizeof(KEY_FID2PATH));
1019 memcpy(&fp->gf_fid, data->ioc_inlbuf1, sizeof(struct lu_fid));
1020 memcpy(&fp->gf_recno, data->ioc_inlbuf2, sizeof(fp->gf_recno));
1021 memcpy(&fp->gf_linkno, data->ioc_inlbuf3,
1022 sizeof(fp->gf_linkno));
1023 fp->gf_pathlen = pathlen;
1025 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
1026 PFID(&fp->gf_fid), fp->gf_recno, fp->gf_linkno);
1028 if (!fid_is_sane(&fp->gf_fid))
1029 GOTO(out, rc = -EINVAL);
1031 rc = obd_get_info(exp, keylen, buf, &vallen, fp, NULL);
1035 if (vallen < sizeof(*fp) + 1)
1036 GOTO(out, rc = -EPROTO);
1037 else if (vallen - sizeof(*fp) > pathlen)
1038 GOTO(out, rc = -EOVERFLOW);
1039 if (copy_to_user(data->ioc_pbuf1, fp->gf_path,
1041 GOTO(out, rc = -EFAULT);
1042 memcpy(data->ioc_inlbuf2, &fp->gf_recno, sizeof(fp->gf_recno));
1043 memcpy(data->ioc_inlbuf3, &fp->gf_linkno,
1044 sizeof(fp->gf_linkno));
1047 OBD_FREE(buf, alloclen);
1052 static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1053 void *karg, void *uarg)
1055 struct obd_device *obd = exp->exp_obd;
1056 struct obd_ioctl_data *data = karg;
1057 struct obd_import *imp = obd->u.cli.cl_import;
1058 struct llog_ctxt *ctxt;
1062 if (!try_module_get(THIS_MODULE)) {
1063 CERROR("Can't get module. Is it alive?");
1067 case OBD_IOC_CHANGELOG_CLEAR: {
1068 struct ioc_changelog_clear *icc = karg;
1069 struct changelog_setinfo cs =
1070 {icc->icc_recno, icc->icc_id};
1071 rc = obd_set_info_async(exp, strlen(KEY_CHANGELOG_CLEAR),
1072 KEY_CHANGELOG_CLEAR, sizeof(cs), &cs,
1076 case OBD_IOC_FID2PATH: {
1077 rc = mdc_ioc_fid2path(exp, data);
1080 case OBD_IOC_CLIENT_RECOVER:
1081 rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1);
1085 case IOC_OSC_SET_ACTIVE:
1086 rc = ptlrpc_set_import_active(imp, data->ioc_offset);
1088 case OBD_IOC_PARSE: {
1089 ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT);
1090 rc = class_config_parse_llog(ctxt, data->ioc_inlbuf1, NULL);
1091 llog_ctxt_put(ctxt);
1095 case OBD_IOC_LLOG_INFO:
1096 case OBD_IOC_LLOG_PRINT: {
1097 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
1098 rc = llog_ioctl(ctxt, cmd, data);
1099 llog_ctxt_put(ctxt);
1103 case OBD_IOC_POLL_QUOTACHECK:
1104 rc = lquota_poll_check(quota_interface, exp,
1105 (struct if_quotacheck *)karg);
1107 case OBD_IOC_PING_TARGET:
1108 rc = ptlrpc_obd_ping(obd);
1111 CERROR("mdc_ioctl(): unrecognised ioctl %#x\n", cmd);
1112 GOTO(out, rc = -ENOTTY);
1115 module_put(THIS_MODULE);
1120 static int do_set_info_async(struct obd_export *exp,
1121 obd_count keylen, void *key,
1122 obd_count vallen, void *val,
1123 struct ptlrpc_request_set *set)
1125 struct obd_import *imp = class_exp2cliimp(exp);
1126 struct ptlrpc_request *req;
1131 req = ptlrpc_request_alloc(imp, &RQF_MDS_SET_INFO);
1135 req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_KEY,
1136 RCL_CLIENT, keylen);
1137 req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_VAL,
1138 RCL_CLIENT, vallen);
1139 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_SET_INFO);
1141 ptlrpc_request_free(req);
1145 tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
1146 memcpy(tmp, key, keylen);
1147 tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_VAL);
1148 memcpy(tmp, val, vallen);
1150 ptlrpc_request_set_replen(req);
1153 ptlrpc_set_add_req(set, req);
1154 ptlrpc_check_set(NULL, set);
1156 rc = ptlrpc_queue_wait(req);
1157 ptlrpc_req_finished(req);
1163 int mdc_get_info_rpc(struct obd_export *exp,
1164 obd_count keylen, void *key,
1165 int vallen, void *val)
1167 struct obd_import *imp = class_exp2cliimp(exp);
1168 struct ptlrpc_request *req;
1173 req = ptlrpc_request_alloc(imp, &RQF_MDS_GET_INFO);
1177 req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_KEY,
1178 RCL_CLIENT, keylen);
1179 req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_VALLEN,
1180 RCL_CLIENT, sizeof(__u32));
1182 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GET_INFO);
1184 ptlrpc_request_free(req);
1188 tmp = req_capsule_client_get(&req->rq_pill, &RMF_GETINFO_KEY);
1189 memcpy(tmp, key, keylen);
1190 tmp = req_capsule_client_get(&req->rq_pill, &RMF_GETINFO_VALLEN);
1191 memcpy(tmp, &vallen, sizeof(__u32));
1193 req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_VAL,
1194 RCL_SERVER, vallen);
1195 ptlrpc_request_set_replen(req);
1197 rc = ptlrpc_queue_wait(req);
1199 tmp = req_capsule_server_get(&req->rq_pill, &RMF_GETINFO_VAL);
1200 memcpy(val, tmp, vallen);
1201 if (lustre_msg_swabbed(req->rq_repmsg)) {
1202 if (KEY_IS(KEY_FID2PATH)) {
1203 lustre_swab_fid2path(val);
1207 ptlrpc_req_finished(req);
1212 int mdc_set_info_async(struct obd_export *exp,
1213 obd_count keylen, void *key,
1214 obd_count vallen, void *val,
1215 struct ptlrpc_request_set *set)
1217 struct obd_import *imp = class_exp2cliimp(exp);
1221 if (KEY_IS(KEY_INIT_RECOV)) {
1222 if (vallen != sizeof(int))
1224 spin_lock(&imp->imp_lock);
1225 imp->imp_initial_recov = *(int *)val;
1226 spin_unlock(&imp->imp_lock);
1227 CDEBUG(D_HA, "%s: set imp_initial_recov = %d\n",
1228 exp->exp_obd->obd_name, imp->imp_initial_recov);
1231 /* Turn off initial_recov after we try all backup servers once */
1232 if (KEY_IS(KEY_INIT_RECOV_BACKUP)) {
1233 if (vallen != sizeof(int))
1235 spin_lock(&imp->imp_lock);
1236 imp->imp_initial_recov_bk = *(int *)val;
1237 if (imp->imp_initial_recov_bk)
1238 imp->imp_initial_recov = 1;
1239 spin_unlock(&imp->imp_lock);
1240 CDEBUG(D_HA, "%s: set imp_initial_recov_bk = %d\n",
1241 exp->exp_obd->obd_name, imp->imp_initial_recov_bk);
1244 if (KEY_IS(KEY_READ_ONLY)) {
1245 if (vallen != sizeof(int))
1248 spin_lock(&imp->imp_lock);
1249 if (*((int *)val)) {
1250 imp->imp_connect_flags_orig |= OBD_CONNECT_RDONLY;
1251 imp->imp_connect_data.ocd_connect_flags |= OBD_CONNECT_RDONLY;
1253 imp->imp_connect_flags_orig &= ~OBD_CONNECT_RDONLY;
1254 imp->imp_connect_data.ocd_connect_flags &= ~OBD_CONNECT_RDONLY;
1256 spin_unlock(&imp->imp_lock);
1258 rc = do_set_info_async(exp, keylen, key, vallen, val, set);
1261 if (KEY_IS(KEY_SPTLRPC_CONF)) {
1262 sptlrpc_conf_client_adapt(exp->exp_obd);
1265 if (KEY_IS(KEY_FLUSH_CTX)) {
1266 sptlrpc_import_flush_my_ctx(imp);
1269 if (KEY_IS(KEY_MDS_CONN)) {
1270 struct obd_import *imp = class_exp2cliimp(exp);
1272 /* mds-mds import */
1273 spin_lock(&imp->imp_lock);
1274 imp->imp_server_timeout = 1;
1275 spin_unlock(&imp->imp_lock);
1276 imp->imp_client->cli_request_portal = MDS_MDS_PORTAL;
1277 CDEBUG(D_OTHER, "%s: timeout / 2\n", exp->exp_obd->obd_name);
1280 if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
1281 rc = do_set_info_async(exp, keylen, key, vallen, val, set);
1288 int mdc_get_info(struct obd_export *exp, __u32 keylen, void *key,
1289 __u32 *vallen, void *val, struct lov_stripe_md *lsm)
1293 if (KEY_IS(KEY_MAX_EASIZE)) {
1294 int mdsize, *max_easize;
1296 if (*vallen != sizeof(int))
1298 mdsize = *(int*)val;
1299 if (mdsize > exp->exp_obd->u.cli.cl_max_mds_easize)
1300 exp->exp_obd->u.cli.cl_max_mds_easize = mdsize;
1302 *max_easize = exp->exp_obd->u.cli.cl_max_mds_easize;
1305 if (KEY_IS(KEY_CONN_DATA)) {
1306 struct obd_import *imp = class_exp2cliimp(exp);
1307 struct obd_connect_data *data = val;
1309 if (*vallen != sizeof(*data))
1312 *data = imp->imp_connect_data;
1316 rc = mdc_get_info_rpc(exp, keylen, key, *vallen, val);
1321 static int mdc_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1322 __u64 max_age, __u32 flags)
1324 struct ptlrpc_request *req;
1325 struct obd_statfs *msfs;
1326 struct obd_import *imp = NULL;
1331 /*Since the request might also come from lprocfs, so we need
1332 *sync this with client_disconnect_export Bug15684*/
1333 down_read(&obd->u.cli.cl_sem);
1334 if (obd->u.cli.cl_import)
1335 imp = class_import_get(obd->u.cli.cl_import);
1336 up_read(&obd->u.cli.cl_sem);
1340 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_STATFS,
1341 LUSTRE_MDS_VERSION, MDS_STATFS);
1343 GOTO(output, rc = -ENOMEM);
1345 ptlrpc_request_set_replen(req);
1347 if (flags & OBD_STATFS_NODELAY) {
1348 /* procfs requests not want stay in wait for avoid deadlock */
1349 req->rq_no_resend = 1;
1350 req->rq_no_delay = 1;
1353 rc = ptlrpc_queue_wait(req);
1355 /* check connection error first */
1356 if (imp->imp_connect_error)
1357 rc = imp->imp_connect_error;
1361 msfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
1363 GOTO(out, rc = -EPROTO);
1368 ptlrpc_req_finished(req);
1370 class_import_put(imp);
1374 static int mdc_pin(struct obd_export *exp, const struct lu_fid *fid,
1375 struct obd_capa *oc, struct obd_client_handle *handle,
1378 struct ptlrpc_request *req;
1379 struct mdt_body *body;
1383 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_PIN);
1387 mdc_set_capa_size(req, &RMF_CAPA1, oc);
1389 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_PIN);
1391 ptlrpc_request_free(req);
1395 mdc_pack_body(req, fid, oc, 0, 0, -1, flags);
1397 ptlrpc_request_set_replen(req);
1399 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1400 rc = ptlrpc_queue_wait(req);
1401 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1403 CERROR("Pin failed: %d\n", rc);
1407 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1409 GOTO(err_out, rc = -EPROTO);
1411 handle->och_fh = body->handle;
1412 handle->och_magic = OBD_CLIENT_HANDLE_MAGIC;
1414 OBD_ALLOC_PTR(handle->och_mod);
1415 if (handle->och_mod == NULL) {
1416 DEBUG_REQ(D_ERROR, req, "can't allocate md_open_data");
1417 GOTO(err_out, rc = -ENOMEM);
1419 handle->och_mod->mod_open_req = req; /* will be dropped by unpin */
1424 ptlrpc_req_finished(req);
1428 static int mdc_unpin(struct obd_export *exp, struct obd_client_handle *handle,
1431 struct ptlrpc_request *req;
1432 struct mdt_body *body;
1436 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_UNPIN,
1437 LUSTRE_MDS_VERSION, MDS_UNPIN);
1441 body = req_capsule_client_get(&req->rq_pill, &RMF_MDT_BODY);
1442 body->handle = handle->och_fh;
1445 ptlrpc_request_set_replen(req);
1447 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1448 rc = ptlrpc_queue_wait(req);
1449 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1452 CERROR("Unpin failed: %d\n", rc);
1454 ptlrpc_req_finished(req);
1455 ptlrpc_req_finished(handle->och_mod->mod_open_req);
1457 OBD_FREE(handle->och_mod, sizeof(*handle->och_mod));
1461 int mdc_sync(struct obd_export *exp, const struct lu_fid *fid,
1462 struct obd_capa *oc, struct ptlrpc_request **request)
1464 struct ptlrpc_request *req;
1469 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_SYNC);
1473 mdc_set_capa_size(req, &RMF_CAPA1, oc);
1475 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_SYNC);
1477 ptlrpc_request_free(req);
1481 mdc_pack_body(req, fid, oc, 0, 0, -1, 0);
1483 ptlrpc_request_set_replen(req);
1485 rc = ptlrpc_queue_wait(req);
1487 ptlrpc_req_finished(req);
1493 static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
1494 enum obd_import_event event)
1498 LASSERT(imp->imp_obd == obd);
1501 case IMP_EVENT_DISCON: {
1503 /* XXX Pass event up to OBDs stack. used only for FLD now */
1504 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_DISCON, NULL);
1508 case IMP_EVENT_INACTIVE: {
1509 struct client_obd *cli = &obd->u.cli;
1511 * Flush current sequence to make client obtain new one
1512 * from server in case of disconnect/reconnect.
1513 * If range is already empty then no need to flush it.
1515 if (cli->cl_seq != NULL &&
1516 !range_is_exhausted(&cli->cl_seq->lcs_space)) {
1517 seq_client_flush(cli->cl_seq);
1520 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_INACTIVE, NULL);
1523 case IMP_EVENT_INVALIDATE: {
1524 struct ldlm_namespace *ns = obd->obd_namespace;
1526 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
1530 case IMP_EVENT_ACTIVE: {
1531 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_ACTIVE, NULL);
1535 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_OCD, NULL);
1539 CERROR("Unknown import event %x\n", event);
1545 static int mdc_fid_init(struct obd_export *exp)
1547 struct client_obd *cli = &exp->exp_obd->u.cli;
1552 OBD_ALLOC_PTR(cli->cl_seq);
1553 if (cli->cl_seq == NULL)
1556 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
1558 GOTO(out_free_seq, rc = -ENOMEM);
1560 snprintf(prefix, MAX_OBD_NAME + 5, "srv-%s",
1561 exp->exp_obd->obd_name);
1563 /* Init client side sequence-manager */
1564 rc = seq_client_init(cli->cl_seq, exp,
1565 LUSTRE_SEQ_METADATA,
1567 OBD_FREE(prefix, MAX_OBD_NAME + 5);
1569 GOTO(out_free_seq, rc);
1573 OBD_FREE_PTR(cli->cl_seq);
1578 static int mdc_fid_fini(struct obd_export *exp)
1580 struct client_obd *cli = &exp->exp_obd->u.cli;
1583 if (cli->cl_seq != NULL) {
1584 seq_client_fini(cli->cl_seq);
1585 OBD_FREE_PTR(cli->cl_seq);
1592 int mdc_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
1593 struct md_op_data *op_data)
1595 struct client_obd *cli = &exp->exp_obd->u.cli;
1596 struct lu_client_seq *seq = cli->cl_seq;
1598 RETURN(seq_client_alloc_fid(seq, fid));
1601 /* XXX This method is used only to clear current fid seq
1602 * once fld/mds insert failed */
1603 static int mdc_fid_delete(struct obd_export *exp, const struct lu_fid *fid)
1605 struct client_obd *cli = &exp->exp_obd->u.cli;
1607 seq_client_flush(cli->cl_seq);
1611 struct obd_uuid *mdc_get_uuid(struct obd_export *exp) {
1612 struct client_obd *cli = &exp->exp_obd->u.cli;
1613 return &cli->cl_target_uuid;
1616 static int mdc_setup(struct obd_device *obd, struct lustre_cfg *cfg)
1618 struct client_obd *cli = &obd->u.cli;
1619 struct lprocfs_static_vars lvars = { 0 };
1623 OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1624 if (!cli->cl_rpc_lock)
1626 mdc_init_rpc_lock(cli->cl_rpc_lock);
1630 OBD_ALLOC(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1631 if (!cli->cl_setattr_lock)
1632 GOTO(err_rpc_lock, rc = -ENOMEM);
1633 mdc_init_rpc_lock(cli->cl_setattr_lock);
1635 OBD_ALLOC(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1636 if (!cli->cl_close_lock)
1637 GOTO(err_setattr_lock, rc = -ENOMEM);
1638 mdc_init_rpc_lock(cli->cl_close_lock);
1640 rc = client_obd_setup(obd, cfg);
1642 GOTO(err_close_lock, rc);
1643 lprocfs_mdc_init_vars(&lvars);
1644 lprocfs_obd_setup(obd, lvars.obd_vars);
1645 sptlrpc_lprocfs_cliobd_attach(obd);
1646 ptlrpc_lprocfs_register_obd(obd);
1648 rc = obd_llog_init(obd, &obd->obd_olg, obd, 0, NULL, NULL);
1651 CERROR("failed to setup llogging subsystems\n");
1657 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1659 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1661 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1666 /* Initialize the default and maximum LOV EA and cookie sizes. This allows
1667 * us to make MDS RPCs with large enough reply buffers to hold the
1668 * maximum-sized (= maximum striped) EA and cookie without having to
1669 * calculate this (via a call into the LOV + OSCs) each time we make an RPC. */
1670 static int mdc_init_ea_size(struct obd_export *exp, int easize,
1671 int def_easize, int cookiesize)
1673 struct obd_device *obd = exp->exp_obd;
1674 struct client_obd *cli = &obd->u.cli;
1677 if (cli->cl_max_mds_easize < easize)
1678 cli->cl_max_mds_easize = easize;
1680 if (cli->cl_default_mds_easize < def_easize)
1681 cli->cl_default_mds_easize = def_easize;
1683 if (cli->cl_max_mds_cookiesize < cookiesize)
1684 cli->cl_max_mds_cookiesize = cookiesize;
1689 static int mdc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
1695 case OBD_CLEANUP_EARLY:
1696 case OBD_CLEANUP_EXPORTS:
1697 /* If we set up but never connected, the
1698 client import will not have been cleaned. */
1699 if (obd->u.cli.cl_import) {
1700 struct obd_import *imp;
1701 down_write(&obd->u.cli.cl_sem);
1702 imp = obd->u.cli.cl_import;
1703 CERROR("client import never connected\n");
1704 ptlrpc_invalidate_import(imp);
1705 class_destroy_import(imp);
1706 up_write(&obd->u.cli.cl_sem);
1707 obd->u.cli.cl_import = NULL;
1709 rc = obd_llog_finish(obd, 0);
1711 CERROR("failed to cleanup llogging subsystems\n");
1717 static int mdc_cleanup(struct obd_device *obd)
1719 struct client_obd *cli = &obd->u.cli;
1721 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1722 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1723 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1725 ptlrpc_lprocfs_unregister_obd(obd);
1726 lprocfs_obd_cleanup(obd);
1729 return client_obd_cleanup(obd);
1733 static int mdc_llog_init(struct obd_device *obd, struct obd_llog_group *olg,
1734 struct obd_device *tgt, int count,
1735 struct llog_catid *logid, struct obd_uuid *uuid)
1737 struct llog_ctxt *ctxt;
1741 LASSERT(olg == &obd->obd_olg);
1743 rc = llog_setup(obd, olg, LLOG_LOVEA_REPL_CTXT, tgt, 0, NULL,
1747 ctxt = llog_get_context(obd, LLOG_LOVEA_REPL_CTXT);
1748 llog_initiator_connect(ctxt);
1749 llog_ctxt_put(ctxt);
1751 rc = llog_setup(obd, olg, LLOG_CHANGELOG_REPL_CTXT, tgt, 0, NULL,
1754 ctxt = llog_group_get_ctxt(olg, LLOG_CHANGELOG_REPL_CTXT);
1755 llog_initiator_connect(ctxt);
1756 llog_ctxt_put(ctxt);
1762 static int mdc_llog_finish(struct obd_device *obd, int count)
1764 struct llog_ctxt *ctxt;
1768 ctxt = llog_get_context(obd, LLOG_LOVEA_REPL_CTXT);
1770 rc = llog_cleanup(ctxt);
1772 ctxt = llog_get_context(obd, LLOG_CHANGELOG_REPL_CTXT);
1774 rc = llog_cleanup(ctxt);
1779 static int mdc_process_config(struct obd_device *obd, obd_count len, void *buf)
1781 struct lustre_cfg *lcfg = buf;
1782 struct lprocfs_static_vars lvars = { 0 };
1785 lprocfs_mdc_init_vars(&lvars);
1786 switch (lcfg->lcfg_command) {
1788 rc = class_process_proc_param(PARAM_MDC, lvars.obd_vars,
1798 /* get remote permission for current user on fid */
1799 int mdc_get_remote_perm(struct obd_export *exp, const struct lu_fid *fid,
1800 struct obd_capa *oc, __u32 suppgid,
1801 struct ptlrpc_request **request)
1803 struct ptlrpc_request *req;
1807 LASSERT(client_is_remote(exp));
1810 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR);
1814 mdc_set_capa_size(req, &RMF_CAPA1, oc);
1816 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR);
1818 ptlrpc_request_free(req);
1822 mdc_pack_body(req, fid, oc, OBD_MD_FLRMTPERM, 0, suppgid, 0);
1824 req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER,
1825 sizeof(struct mdt_remote_perm));
1827 ptlrpc_request_set_replen(req);
1829 rc = ptlrpc_queue_wait(req);
1831 ptlrpc_req_finished(req);
1837 static int mdc_interpret_renew_capa(const struct lu_env *env,
1838 struct ptlrpc_request *req, void *unused,
1841 struct obd_capa *oc = req->rq_async_args.pointer_arg[0];
1842 renew_capa_cb_t cb = req->rq_async_args.pointer_arg[1];
1843 struct mdt_body *body = NULL;
1844 struct lustre_capa *capa;
1848 GOTO(out, capa = ERR_PTR(status));
1850 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1852 GOTO(out, capa = ERR_PTR(-EFAULT));
1854 if ((body->valid & OBD_MD_FLOSSCAPA) == 0)
1855 GOTO(out, capa = ERR_PTR(-ENOENT));
1857 capa = req_capsule_server_get(&req->rq_pill, &RMF_CAPA2);
1859 GOTO(out, capa = ERR_PTR(-EFAULT));
1866 static int mdc_renew_capa(struct obd_export *exp, struct obd_capa *oc,
1869 struct ptlrpc_request *req;
1872 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_GETATTR,
1873 LUSTRE_MDS_VERSION, MDS_GETATTR);
1877 /* NB, OBD_MD_FLOSSCAPA is set here, but it doesn't necessarily mean the
1878 * capa to renew is oss capa.
1880 mdc_pack_body(req, &oc->c_capa.lc_fid, oc, OBD_MD_FLOSSCAPA, 0, -1, 0);
1881 ptlrpc_request_set_replen(req);
1883 req->rq_async_args.pointer_arg[0] = oc;
1884 req->rq_async_args.pointer_arg[1] = cb;
1885 req->rq_interpret_reply = mdc_interpret_renew_capa;
1886 ptlrpcd_add_req(req, PSCOPE_OTHER);
1890 static int mdc_connect(const struct lu_env *env,
1891 struct obd_export **exp,
1892 struct obd_device *obd, struct obd_uuid *cluuid,
1893 struct obd_connect_data *data,
1896 struct obd_import *imp = obd->u.cli.cl_import;
1898 /* mds-mds import features */
1899 if (data && (data->ocd_connect_flags & OBD_CONNECT_MDS_MDS)) {
1900 spin_lock(&imp->imp_lock);
1901 imp->imp_server_timeout = 1;
1902 spin_unlock(&imp->imp_lock);
1903 imp->imp_client->cli_request_portal = MDS_MDS_PORTAL;
1904 CDEBUG(D_OTHER, "%s: Set 'mds' portal and timeout\n",
1908 return client_connect_import(env, exp, obd, cluuid, data, NULL);
1911 struct obd_ops mdc_obd_ops = {
1912 .o_owner = THIS_MODULE,
1913 .o_setup = mdc_setup,
1914 .o_precleanup = mdc_precleanup,
1915 .o_cleanup = mdc_cleanup,
1916 .o_add_conn = client_import_add_conn,
1917 .o_del_conn = client_import_del_conn,
1918 .o_connect = mdc_connect,
1919 .o_disconnect = client_disconnect_export,
1920 .o_iocontrol = mdc_iocontrol,
1921 .o_set_info_async = mdc_set_info_async,
1922 .o_statfs = mdc_statfs,
1924 .o_unpin = mdc_unpin,
1925 .o_fid_init = mdc_fid_init,
1926 .o_fid_fini = mdc_fid_fini,
1927 .o_fid_alloc = mdc_fid_alloc,
1928 .o_fid_delete = mdc_fid_delete,
1929 .o_import_event = mdc_import_event,
1930 .o_llog_init = mdc_llog_init,
1931 .o_llog_finish = mdc_llog_finish,
1932 .o_get_info = mdc_get_info,
1933 .o_process_config = mdc_process_config,
1934 .o_get_uuid = mdc_get_uuid,
1937 struct md_ops mdc_md_ops = {
1938 .m_getstatus = mdc_getstatus,
1939 .m_change_cbdata = mdc_change_cbdata,
1940 .m_close = mdc_close,
1941 .m_create = mdc_create,
1942 .m_done_writing = mdc_done_writing,
1943 .m_enqueue = mdc_enqueue,
1944 .m_getattr = mdc_getattr,
1945 .m_getattr_name = mdc_getattr_name,
1946 .m_intent_lock = mdc_intent_lock,
1948 .m_is_subdir = mdc_is_subdir,
1949 .m_rename = mdc_rename,
1950 .m_setattr = mdc_setattr,
1951 .m_setxattr = mdc_setxattr,
1952 .m_getxattr = mdc_getxattr,
1954 .m_readpage = mdc_readpage,
1955 .m_unlink = mdc_unlink,
1956 .m_cancel_unused = mdc_cancel_unused,
1957 .m_init_ea_size = mdc_init_ea_size,
1958 .m_set_lock_data = mdc_set_lock_data,
1959 .m_lock_match = mdc_lock_match,
1960 .m_get_lustre_md = mdc_get_lustre_md,
1961 .m_free_lustre_md = mdc_free_lustre_md,
1962 .m_set_open_replay_data = mdc_set_open_replay_data,
1963 .m_clear_open_replay_data = mdc_clear_open_replay_data,
1964 .m_renew_capa = mdc_renew_capa,
1965 .m_unpack_capa = mdc_unpack_capa,
1966 .m_get_remote_perm = mdc_get_remote_perm,
1967 .m_intent_getattr_async = mdc_intent_getattr_async,
1968 .m_revalidate_lock = mdc_revalidate_lock
1971 int __init mdc_init(void)
1974 struct lprocfs_static_vars lvars = { 0 };
1975 lprocfs_mdc_init_vars(&lvars);
1977 request_module("lquota");
1978 quota_interface = PORTAL_SYMBOL_GET(mdc_quota_interface);
1979 init_obd_quota_ops(quota_interface, &mdc_obd_ops);
1981 rc = class_register_type(&mdc_obd_ops, &mdc_md_ops, lvars.module_vars,
1982 LUSTRE_MDC_NAME, NULL);
1983 if (rc && quota_interface)
1984 PORTAL_SYMBOL_PUT(mdc_quota_interface);
1990 static void /*__exit*/ mdc_exit(void)
1992 if (quota_interface)
1993 PORTAL_SYMBOL_PUT(mdc_quota_interface);
1995 class_unregister_type(LUSTRE_MDC_NAME);
1998 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
1999 MODULE_DESCRIPTION("Lustre Metadata Client");
2000 MODULE_LICENSE("GPL");
2002 module_init(mdc_init);
2003 module_exit(mdc_exit);