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,
60 struct lustre_capa *capa;
63 /* swabbed already in mdc_enqueue */
64 capa = lustre_msg_buf(req->rq_repmsg, offset, sizeof(*capa));
66 CERROR("missing capa at offset %d failed!\n", offset);
67 return ERR_PTR(-EFAULT);
70 oc = alloc_capa(CAPA_SITE_CLIENT);
72 CERROR("alloc capa failed!\n");
73 return ERR_PTR(-ENOMEM);
80 /* Helper that implements most of mdc_getstatus and signal_completed_replay. */
81 /* XXX this should become mdc_get_info("key"), sending MDS_GET_INFO RPC */
82 static int send_getstatus(struct obd_import *imp, struct lu_fid *rootfid,
83 struct obd_capa **pc, int level, int msg_flags)
85 struct ptlrpc_request *req;
86 struct mdt_body *body;
87 int rc, size[3] = { sizeof(struct ptlrpc_body),
89 sizeof(struct lustre_capa) };
92 req = ptlrpc_prep_req(imp, LUSTRE_MDS_VERSION, MDS_GETSTATUS, 2, size,
95 GOTO(out, rc = -ENOMEM);
97 req->rq_send_state = level;
98 ptlrpc_req_set_repsize(req, 3, size);
100 mdc_pack_req_body(req, REQ_REC_OFF, 0, NULL, NULL, 0, 0);
101 lustre_msg_add_flags(req->rq_reqmsg, msg_flags);
102 rc = ptlrpc_queue_wait(req);
105 body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body),
106 lustre_swab_mdt_body);
108 CERROR ("Can't extract mdt_body\n");
109 GOTO (out, rc = -EPROTO);
112 *rootfid = body->fid1;
114 if (body->valid & OBD_MD_FLMDSCAPA) {
117 oc = mdc_unpack_capa(req, REPLY_REC_OFF + 1);
119 GOTO(out, rc = PTR_ERR(oc));
123 CDEBUG(D_NET, "root fid="DFID", last_committed="LPU64
124 ", last_xid="LPU64"\n",
126 lustre_msg_get_last_committed(req->rq_repmsg),
127 lustre_msg_get_last_xid(req->rq_repmsg));
132 ptlrpc_req_finished(req);
136 /* This should be mdc_get_info("rootfid") */
137 int mdc_getstatus(struct obd_export *exp, struct lu_fid *rootfid,
138 struct obd_capa **pc)
140 return send_getstatus(class_exp2cliimp(exp), rootfid, pc,
145 * This function now is known to always saying that it will receive 4 buffers
146 * from server. Even for cases when acl_size and md_size is zero, RPC header
147 * willcontain 4 fields and RPC itself will contain zero size fields. This is
148 * because mdt_getattr*() _always_ returns 4 fields, but if acl is not needed
149 * and thus zero, it shirinks it, making zero size. The same story about
150 * md_size. And this is course of problem when client waits for smaller number
151 * of fields. This issue will be fixed later when client gets awar of RPC
154 static int mdc_getattr_common(struct obd_export *exp, unsigned int ea_size,
155 unsigned int acl_size, int mdscapa,
156 struct ptlrpc_request *req)
158 struct mdt_body *body;
160 int size[5] = { sizeof(struct ptlrpc_body),
164 sizeof(struct lustre_capa) };
168 /* Request message already built. */
170 CDEBUG(D_INODE, "reserved %u bytes for MD/symlink in packet\n",
173 CDEBUG(D_INODE, "reserved %u bytes for ACL\n", acl_size);
175 ptlrpc_req_set_repsize(req, 5, size);
177 rc = ptlrpc_queue_wait(req);
181 body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body),
182 lustre_swab_mdt_body);
184 CERROR ("Can't unpack mdt_body\n");
188 CDEBUG(D_NET, "mode: %o\n", body->mode);
190 offset = REPLY_REC_OFF + 1;
191 LASSERT_REPSWAB(req, offset);
192 if (body->eadatasize != 0) {
193 /* reply indicates presence of eadata; check it's there... */
194 eadata = lustre_msg_buf(req->rq_repmsg, offset++,
196 if (eadata == NULL) {
197 CERROR ("Missing/short eadata\n");
202 if (body->valid & OBD_MD_FLMODEASIZE) {
203 struct client_obd *cli = &exp->exp_obd->u.cli;
205 if (cli->cl_max_mds_easize < body->max_mdsize)
206 cli->cl_max_mds_easize = body->max_mdsize;
207 if (cli->cl_max_mds_cookiesize < body->max_cookiesize)
208 cli->cl_max_mds_cookiesize = body->max_cookiesize;
211 offset += !!body->aclsize;
213 if (body->valid & OBD_MD_FLMDSCAPA) {
214 struct lustre_capa *capa;
217 capa = lustre_unpack_capa(req->rq_repmsg, offset++);
219 CERROR("Missing/short client MDS capability\n");
227 int mdc_getattr(struct obd_export *exp, const struct lu_fid *fid,
228 struct obd_capa *oc, obd_valid valid, int ea_size,
229 struct ptlrpc_request **request)
231 struct ptlrpc_request *req;
232 int size[3] = { sizeof(struct ptlrpc_body), sizeof(struct mdt_body) };
233 int acl_size = 0, rc;
236 size[REQ_REC_OFF + 1] = oc ? sizeof(struct lustre_capa) : 0;
239 * XXX: Do we need to make another request here? We just did a getattr
240 * to do the lookup in the first place.
242 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
243 MDS_GETATTR, 3, size, NULL);
245 GOTO(out, rc = -ENOMEM);
247 mdc_pack_req_body(req, REQ_REC_OFF, valid, fid, oc, ea_size,
248 MDS_BFLAG_EXT_FLAGS/*request "new" flags(bug 9486)*/);
250 if (valid & OBD_MD_FLRMTPERM)
251 acl_size = sizeof(struct mdt_remote_perm);
253 /* Currently only root inode will call us with FLACL */
254 else if (valid & OBD_MD_FLACL)
255 acl_size = LUSTRE_POSIX_ACL_MAX_SIZE;
257 rc = mdc_getattr_common(exp, ea_size, acl_size,
258 !!(valid & OBD_MD_FLMDSCAPA), req);
260 ptlrpc_req_finished (req);
268 int mdc_getattr_name(struct obd_export *exp, const struct lu_fid *fid,
269 struct obd_capa *oc, const char *filename, int namelen,
270 obd_valid valid, int ea_size,
271 struct ptlrpc_request **request)
273 struct ptlrpc_request *req;
274 struct mdt_body *body;
275 int size[4] = { sizeof(struct ptlrpc_body), sizeof(*body), 0, namelen};
279 size[REQ_REC_OFF + 1] = oc ? sizeof(struct lustre_capa) : 0;
281 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
282 MDS_GETATTR_NAME, 4, size, NULL);
284 GOTO(out, rc = -ENOMEM);
286 mdc_pack_req_body(req, REQ_REC_OFF, valid, fid, oc, ea_size,
287 MDS_BFLAG_EXT_FLAGS/*request "new" flags(bug 9486)*/);
290 LASSERT(strnlen(filename, namelen) == namelen - 1);
291 memcpy(lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2, namelen),
295 rc = mdc_getattr_common(exp, ea_size, 0, !!(valid & OBD_MD_FLMDSCAPA),
298 ptlrpc_req_finished (req);
306 static int mdc_is_subdir(struct obd_export *exp, const struct lu_fid *pfid,
307 const struct lu_fid *cfid, struct ptlrpc_request **request)
309 int size[2] = { sizeof(struct ptlrpc_body),
310 sizeof(struct mdt_body) };
311 struct ptlrpc_request *req;
312 struct mdt_body *body;
316 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
317 MDS_IS_SUBDIR, 2, size, NULL);
319 GOTO(out, rc = -ENOMEM);
321 mdc_is_subdir_pack(req, REQ_REC_OFF, pfid, cfid, 0);
323 ptlrpc_req_set_repsize(req, 2, size);
324 rc = ptlrpc_queue_wait(req);
325 if (rc != 0 && rc != -EREMOTE)
328 body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body),
329 lustre_swab_mdt_body);
331 CERROR ("Can't unpack mdt_body\n");
332 GOTO(out, rc = -EPROTO);
341 int mdc_xattr_common(struct obd_export *exp, const struct lu_fid *fid,
343 int opcode, obd_valid valid, const char *xattr_name,
344 const char *input, int input_size, int output_size,
345 int flags, struct ptlrpc_request **request)
347 struct ptlrpc_request *req;
348 int size[5] = { sizeof(struct ptlrpc_body), sizeof(struct mdt_body) };
349 int bufcnt = 3, offset = REQ_REC_OFF + 2;
350 int rc, xattr_namelen = 0, remote_acl = 0;
354 size[REQ_REC_OFF + 1] = oc ? sizeof(struct lustre_capa) : 0;
356 xattr_namelen = strlen(xattr_name) + 1;
357 size[bufcnt++] = xattr_namelen;
361 size[bufcnt++] = input_size;
364 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
365 opcode, bufcnt, size, NULL);
367 GOTO(out, rc = -ENOMEM);
370 mdc_pack_req_body(req, REQ_REC_OFF, valid, fid, oc, output_size, flags);
374 tmp = lustre_msg_buf(req->rq_reqmsg, offset++, xattr_namelen);
375 memcpy(tmp, xattr_name, xattr_namelen);
376 if (!strcmp(xattr_name, XATTR_NAME_LUSTRE_ACL))
380 tmp = lustre_msg_buf(req->rq_reqmsg, offset++, input_size);
381 memcpy(tmp, input, input_size);
385 if (opcode == MDS_GETXATTR) {
386 size[REPLY_REC_OFF] = sizeof(struct mdt_body);
392 /* we do this even output_size is 0, because server is doing that */
393 size[bufcnt++] = output_size;
394 ptlrpc_req_set_repsize(req, bufcnt, size);
397 /* NB: set remote acl doesn't need hold rpc lock, because it just
398 * send command to MDS, and when it's executed on mountpoint on MDS,
399 * another mdc_xattr_common() will be invoked there. */
400 if (opcode == MDS_SETXATTR && !remote_acl)
401 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
403 rc = ptlrpc_queue_wait(req);
405 if (opcode == MDS_SETXATTR && !remote_acl)
406 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
411 if (opcode == MDS_GETXATTR) {
412 struct mdt_body * body = lustre_swab_repbuf(req, REPLY_REC_OFF,
413 sizeof(*body), lustre_swab_mdt_body);
415 CERROR ("Can't unpack mdt_body\n");
416 GOTO(err_out, rc = -EPROTO);
423 ptlrpc_req_finished(req);
428 int mdc_setxattr(struct obd_export *exp, const struct lu_fid *fid,
429 struct obd_capa *oc, obd_valid valid, const char *xattr_name,
430 const char *input, int input_size, int output_size, int flags,
431 struct ptlrpc_request **request)
433 return mdc_xattr_common(exp, fid, oc, MDS_SETXATTR, valid, xattr_name,
434 input, input_size, output_size, flags, request);
437 int mdc_getxattr(struct obd_export *exp, const struct lu_fid *fid,
438 struct obd_capa *oc, obd_valid valid, const char *xattr_name,
439 const char *input, int input_size, int output_size, int flags,
440 struct ptlrpc_request **request)
442 return mdc_xattr_common(exp, fid, oc, MDS_GETXATTR, valid, xattr_name,
443 input, input_size, output_size, flags, request);
446 #ifdef CONFIG_FS_POSIX_ACL
448 int mdc_unpack_acl(struct obd_export *exp, struct ptlrpc_request *req,
449 struct lustre_md *md, unsigned int offset)
451 struct mdt_body *body = md->body;
452 struct posix_acl *acl;
459 buf = lustre_msg_buf(req->rq_repmsg, offset, body->aclsize);
461 CERROR("aclsize %u, bufcount %u, bufsize %u\n",
462 body->aclsize, lustre_msg_bufcount(req->rq_repmsg),
463 (lustre_msg_bufcount(req->rq_repmsg) <= offset) ?
464 -1 : lustre_msg_buflen(req->rq_repmsg, offset));
468 acl = posix_acl_from_xattr(buf, body->aclsize);
471 CERROR("convert xattr to acl: %d\n", rc);
475 rc = posix_acl_valid(acl);
477 CERROR("validate acl: %d\n", rc);
478 posix_acl_release(acl);
486 #define mdc_unpack_acl(exp, req, md, offset) 0
489 int mdc_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
490 int offset, struct obd_export *dt_exp,
491 struct obd_export *md_exp,
492 struct lustre_md *md)
498 memset(md, 0, sizeof(*md));
500 md->body = lustre_msg_buf(req->rq_repmsg, offset, sizeof (*md->body));
501 LASSERT (md->body != NULL);
502 LASSERT_REPSWABBED(req, offset);
505 if (md->body->valid & OBD_MD_FLEASIZE) {
507 struct lov_mds_md *lmm;
509 LASSERT(S_ISREG(md->body->mode));
511 if (md->body->eadatasize == 0) {
512 CERROR("OBD_MD_FLEASIZE set, but eadatasize 0\n");
515 lmmsize = md->body->eadatasize;
516 lmm = lustre_msg_buf(req->rq_repmsg, offset, lmmsize);
517 LASSERT (lmm != NULL);
518 LASSERT_REPSWABBED(req, offset);
520 rc = obd_unpackmd(dt_exp, &md->lsm, lmm, lmmsize);
524 LASSERT (rc >= sizeof (*md->lsm));
526 } else if (md->body->valid & OBD_MD_FLDIREA) {
528 struct lov_mds_md *lmv;
530 LASSERT(S_ISDIR(md->body->mode));
532 if (md->body->eadatasize == 0) {
533 CERROR("OBD_MD_FLEASIZE is set, but eadatasize 0\n");
536 if (md->body->valid & OBD_MD_MEA) {
537 lmvsize = md->body->eadatasize;
538 lmv = lustre_msg_buf(req->rq_repmsg, offset, lmvsize);
539 LASSERT (lmv != NULL);
540 LASSERT_REPSWABBED(req, offset);
542 rc = obd_unpackmd(md_exp, (void *)&md->mea, lmv,
547 LASSERT (rc >= sizeof (*md->mea));
553 /* remote permission */
554 if (md->body->valid & OBD_MD_FLRMTPERM) {
555 md->remote_perm = lustre_msg_buf(req->rq_repmsg, offset++,
556 sizeof(struct mdt_remote_perm));
557 LASSERT(md->remote_perm);
560 /* for ACL, it's possible that FLACL is set but aclsize is zero. only
561 * when aclsize != 0 there's an actual segment for ACL in reply
563 else if (md->body->valid & OBD_MD_FLACL) {
564 if (md->body->aclsize) {
565 rc = mdc_unpack_acl(dt_exp, req, md, offset++);
568 #ifdef CONFIG_FS_POSIX_ACL
570 md->posix_acl = NULL;
575 if (md->body->valid & OBD_MD_FLMDSCAPA) {
576 struct obd_capa *oc = mdc_unpack_capa(req, offset++);
579 GOTO(out, rc = PTR_ERR(oc));
583 if (md->body->valid & OBD_MD_FLOSSCAPA) {
584 struct obd_capa *oc = mdc_unpack_capa(req, offset++);
587 GOTO(out, rc = PTR_ERR(oc));
595 free_capa(md->oss_capa);
597 free_capa(md->mds_capa);
598 #ifdef CONFIG_FS_POSIX_ACL
599 posix_acl_release(md->posix_acl);
602 obd_free_memmd(dt_exp, &md->lsm);
607 int mdc_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
613 static void mdc_commit_open(struct ptlrpc_request *req)
615 struct mdc_open_data *mod = req->rq_cb_data;
619 if (mod->mod_close_req != NULL)
620 mod->mod_close_req->rq_cb_data = NULL;
622 if (mod->mod_och != NULL)
623 mod->mod_och->och_mod = NULL;
625 OBD_FREE(mod, sizeof(*mod));
626 req->rq_cb_data = NULL;
629 static void mdc_replay_open(struct ptlrpc_request *req)
631 struct mdc_open_data *mod = req->rq_cb_data;
632 struct ptlrpc_request *close_req;
633 struct obd_client_handle *och;
634 struct lustre_handle old;
635 struct mdt_body *body;
639 DEBUG_REQ(D_ERROR, req,
640 "Can't properly replay without open data.");
645 body = lustre_swab_repbuf(req, DLM_REPLY_REC_OFF, sizeof(*body),
646 lustre_swab_mdt_body);
650 struct lustre_handle *file_fh;
652 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
653 LASSERT(body != NULL);
655 file_fh = &och->och_fh;
656 CDEBUG(D_HA, "updating handle from "LPX64" to "LPX64"\n",
657 file_fh->cookie, body->handle.cookie);
658 memcpy(&old, file_fh, sizeof(old));
659 memcpy(file_fh, &body->handle, sizeof(*file_fh));
661 close_req = mod->mod_close_req;
662 if (close_req != NULL) {
663 struct mdt_epoch *epoch;
665 LASSERT(lustre_msg_get_opc(close_req->rq_reqmsg) == MDS_CLOSE);
666 LASSERT(body != NULL);
668 epoch = lustre_msg_buf(close_req->rq_reqmsg, REQ_REC_OFF,
672 LASSERT(!memcmp(&old, &epoch->handle, sizeof(old)));
673 DEBUG_REQ(D_HA, close_req, "updating close body with new fh");
674 memcpy(&epoch->handle, &body->handle, sizeof(epoch->handle));
679 int mdc_set_open_replay_data(struct obd_export *exp,
680 struct obd_client_handle *och,
681 struct ptlrpc_request *open_req)
683 struct mdc_open_data *mod;
684 struct mdt_rec_create *rec = lustre_msg_buf(open_req->rq_reqmsg,
687 struct mdt_body *body = lustre_msg_buf(open_req->rq_repmsg,
690 struct obd_import *imp = open_req->rq_import;
693 LASSERT(rec != NULL);
695 /* Incoming message in my byte order (it's been swabbed). */
696 LASSERT_REPSWABBED(open_req, DLM_REPLY_REC_OFF);
698 /* Outgoing messages always in my byte order. */
699 LASSERT(body != NULL);
701 /*Only the import is replayable, we set replay_open data */
702 if (och && imp->imp_replayable) {
703 OBD_ALLOC(mod, sizeof(*mod));
705 DEBUG_REQ(D_ERROR, open_req,
706 "Can't allocate mdc_open_data");
710 spin_lock(&open_req->rq_lock);
711 if (!open_req->rq_replay) {
712 OBD_FREE(mod, sizeof(*mod));
713 spin_unlock(&open_req->rq_lock);
719 open_req->rq_cb_data = mod;
720 mod->mod_open_req = open_req;
721 open_req->rq_commit_cb = mdc_commit_open;
722 spin_unlock(&open_req->rq_lock);
725 rec->cr_fid2 = body->fid1;
726 rec->cr_ioepoch = body->ioepoch;
727 rec->cr_old_handle.cookie = body->handle.cookie;
728 open_req->rq_replay_cb = mdc_replay_open;
729 if (!fid_is_sane(&body->fid1)) {
730 DEBUG_REQ(D_ERROR, open_req, "Saving replay request with "
735 DEBUG_REQ(D_HA, open_req, "Set up open replay data");
739 int mdc_clear_open_replay_data(struct obd_export *exp,
740 struct obd_client_handle *och)
742 struct mdc_open_data *mod = och->och_mod;
746 * Don't free the structure now (it happens in mdc_commit_open(), after
747 * we're sure we won't need to fix up the close request in the future),
748 * but make sure that replay doesn't poke at the och, which is about to
751 LASSERT(mod != LP_POISON);
759 static void mdc_commit_close(struct ptlrpc_request *req)
761 struct mdc_open_data *mod = req->rq_cb_data;
762 struct ptlrpc_request *open_req;
763 struct obd_import *imp = req->rq_import;
765 DEBUG_REQ(D_HA, req, "close req committed");
769 mod->mod_close_req = NULL;
770 req->rq_cb_data = NULL;
771 req->rq_commit_cb = NULL;
773 open_req = mod->mod_open_req;
774 LASSERT(open_req != NULL);
775 LASSERT(open_req != LP_POISON);
776 LASSERT(open_req->rq_type != LI_POISON);
778 DEBUG_REQ(D_HA, open_req, "open req balanced");
779 LASSERT(open_req->rq_transno != 0);
780 LASSERT(open_req->rq_import == imp);
783 * We no longer want to preserve this for transno-unconditional
784 * replay. Decref open req here as well.
786 spin_lock(&open_req->rq_lock);
787 open_req->rq_replay = 0;
788 spin_unlock(&open_req->rq_lock);
791 int mdc_close(struct obd_export *exp, struct md_op_data *op_data,
792 struct obd_client_handle *och, struct ptlrpc_request **request)
794 struct obd_device *obd = class_exp2obd(exp);
795 int reqsize[4] = { sizeof(struct ptlrpc_body),
796 sizeof(struct mdt_epoch),
797 sizeof(struct mdt_rec_setattr)};
798 int repsize[4] = { sizeof(struct ptlrpc_body),
799 sizeof(struct mdt_body),
800 obd->u.cli.cl_max_mds_easize,
801 obd->u.cli.cl_max_mds_cookiesize };
802 struct ptlrpc_request *req;
803 struct mdc_open_data *mod;
807 reqsize[REQ_REC_OFF + 2] = op_data->op_capa1 ?
808 sizeof(struct lustre_capa) : 0;
809 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
810 MDS_CLOSE, 4, reqsize, NULL);
812 GOTO(out, rc = -ENOMEM);
814 /* To avoid a livelock (bug 7034), we need to send CLOSE RPCs to a
815 * portal whose threads are not taking any DLM locks and are therefore
816 * always progressing */
817 /* XXX FIXME bug 249 */
818 req->rq_request_portal = MDS_READPAGE_PORTAL;
820 /* Ensure that this close's handle is fixed up during replay. */
821 LASSERT(och != NULL);
822 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
824 if (likely(mod != NULL)) {
825 if (mod->mod_open_req->rq_type == LI_POISON) {
826 CERROR("LBUG POISONED open %p!\n", mod->mod_open_req);
828 ptlrpc_req_finished(req);
830 GOTO(out, rc = -EIO);
832 mod->mod_close_req = req;
833 DEBUG_REQ(D_HA, mod->mod_open_req, "matched open");
835 CDEBUG(D_HA, "couldn't find open req; expecting close error\n");
838 mdc_close_pack(req, REQ_REC_OFF, op_data);
839 ptlrpc_req_set_repsize(req, 4, repsize);
840 req->rq_commit_cb = mdc_commit_close;
841 LASSERT(req->rq_cb_data == NULL);
842 req->rq_cb_data = mod;
844 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
845 rc = ptlrpc_queue_wait(req);
846 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
848 if (req->rq_repmsg == NULL) {
849 CDEBUG(D_HA, "request failed to send: %p, %d\n", req,
852 rc = req->rq_status ? req->rq_status : -EIO;
853 } else if (rc == 0 || rc == -EAGAIN) {
854 rc = lustre_msg_get_status(req->rq_repmsg);
855 if (lustre_msg_get_type(req->rq_repmsg) == PTL_RPC_MSG_ERR) {
856 DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, err "
860 } else if (mod == NULL) {
861 if (req->rq_import->imp_replayable)
862 CERROR("Unexpected: can't find mdc_open_data,"
863 "but close succeeded with replayable imp"
864 "Please tell CFS.\n");
866 if (!lustre_swab_repbuf(req, REPLY_REC_OFF,
867 sizeof(struct mdt_body),
868 lustre_swab_mdt_body)) {
869 CERROR("Error unpacking mdt_body\n");
877 if (rc != 0 && rc != -EAGAIN && req && req->rq_commit_cb)
878 req->rq_commit_cb(req);
883 int mdc_done_writing(struct obd_export *exp, struct md_op_data *op_data,
884 struct obd_client_handle *och)
886 struct obd_device *obd = class_exp2obd(exp);
887 struct ptlrpc_request *req;
888 int size[4] = { sizeof(struct ptlrpc_body),
889 sizeof(struct mdt_epoch),
890 sizeof(struct mdt_rec_setattr)};
891 int repsize[2] = { sizeof(struct ptlrpc_body),
892 sizeof(struct mdt_body)};
896 if (op_data->op_capa1)
897 size[REQ_REC_OFF + 2] = sizeof(struct lustre_capa);
898 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
899 MDS_DONE_WRITING, 4, size, NULL);
903 /* XXX: add DONE_WRITING request to och -- when Size-on-MDS
904 * recovery will be ready. */
905 mdc_close_pack(req, REQ_REC_OFF, op_data);
907 ptlrpc_req_set_repsize(req, 2, repsize);
908 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
909 rc = ptlrpc_queue_wait(req);
910 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
911 ptlrpc_req_finished(req);
915 #ifdef HAVE_SPLIT_SUPPORT
916 int mdc_sendpage(struct obd_export *exp, const struct lu_fid *fid,
917 const struct page *page, int offset)
919 int rc, size[3] = { sizeof(struct ptlrpc_body), sizeof(struct mdt_body) };
920 struct obd_import *imp = class_exp2cliimp(exp);
921 struct ptlrpc_bulk_desc *desc = NULL;
922 struct ptlrpc_request *req = NULL;
925 CDEBUG(D_INODE, "object: "DFID"\n", PFID(fid));
927 req = ptlrpc_prep_req(imp, LUSTRE_MDS_VERSION, MDS_WRITEPAGE, 3,
930 GOTO(out, rc = -ENOMEM);
932 req->rq_request_portal = MDS_READPAGE_PORTAL;
934 desc = ptlrpc_prep_bulk_imp(req, 1, BULK_GET_SOURCE, MDS_BULK_PORTAL);
936 GOTO(out, rc = -ENOMEM);
938 /* NB req now owns desc and will free it when it gets freed. */
939 ptlrpc_prep_bulk_page(desc, (struct page *)page, 0, offset);
940 mdc_readdir_pack(req, REQ_REC_OFF, 0, offset, fid, NULL);
942 ptlrpc_req_set_repsize(req, 2, size);
943 rc = ptlrpc_queue_wait(req);
947 ptlrpc_req_finished(req);
950 EXPORT_SYMBOL(mdc_sendpage);
953 int mdc_readpage(struct obd_export *exp, const struct lu_fid *fid,
954 struct obd_capa *oc, __u64 offset, struct page *page,
955 struct ptlrpc_request **request)
957 int rc, size[3] = { sizeof(struct ptlrpc_body), sizeof(struct mdt_body) };
958 struct obd_import *imp = class_exp2cliimp(exp);
959 struct ptlrpc_bulk_desc *desc = NULL;
960 struct ptlrpc_request *req = NULL;
961 struct mdt_body *body;
964 CDEBUG(D_INODE, "object: "DFID"\n", PFID(fid));
966 size[REQ_REC_OFF + 1] = oc ? sizeof(struct lustre_capa) : 0;
967 req = ptlrpc_prep_req(imp, LUSTRE_MDS_VERSION, MDS_READPAGE, 3, size,
970 GOTO(out, rc = -ENOMEM);
972 /* XXX FIXME bug 249 */
973 req->rq_request_portal = MDS_READPAGE_PORTAL;
975 desc = ptlrpc_prep_bulk_imp(req, 1, BULK_PUT_SINK, MDS_BULK_PORTAL);
977 GOTO(out, rc = -ENOMEM);
979 /* NB req now owns desc and will free it when it gets freed */
980 ptlrpc_prep_bulk_page(desc, page, 0, CFS_PAGE_SIZE);
981 mdc_readdir_pack(req, REQ_REC_OFF, offset, CFS_PAGE_SIZE, fid, oc);
983 ptlrpc_req_set_repsize(req, 2, size);
984 rc = ptlrpc_queue_wait(req);
987 body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body),
988 lustre_swab_mdt_body);
990 CERROR("Can't unpack mdt_body\n");
991 GOTO(out, rc = -EPROTO);
994 if (req->rq_bulk->bd_nob_transferred != CFS_PAGE_SIZE) {
995 CERROR ("Unexpected # bytes transferred: %d"
997 req->rq_bulk->bd_nob_transferred,
999 GOTO(out, rc = -EPROTO);
1009 static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1010 void *karg, void *uarg)
1012 struct obd_device *obd = exp->exp_obd;
1013 struct obd_ioctl_data *data = karg;
1014 struct obd_import *imp = obd->u.cli.cl_import;
1015 struct llog_ctxt *ctxt;
1019 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1022 if (!try_module_get(THIS_MODULE)) {
1023 CERROR("Can't get module. Is it alive?");
1028 case OBD_IOC_CLIENT_RECOVER:
1029 rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1);
1033 case IOC_OSC_SET_ACTIVE:
1034 rc = ptlrpc_set_import_active(imp, data->ioc_offset);
1036 case OBD_IOC_PARSE: {
1037 ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT);
1038 rc = class_config_parse_llog(ctxt, data->ioc_inlbuf1, NULL);
1042 case OBD_IOC_LLOG_INFO:
1043 case OBD_IOC_LLOG_PRINT: {
1044 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
1045 rc = llog_ioctl(ctxt, cmd, data);
1050 case OBD_IOC_POLL_QUOTACHECK:
1051 rc = lquota_poll_check(quota_interface, exp,
1052 (struct if_quotacheck *)karg);
1055 CERROR("mdc_ioctl(): unrecognised ioctl %#x\n", cmd);
1056 GOTO(out, rc = -ENOTTY);
1059 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1062 module_put(THIS_MODULE);
1068 int mdc_set_info_async(struct obd_export *exp, obd_count keylen,
1069 void *key, obd_count vallen, void *val,
1070 struct ptlrpc_request_set *set)
1072 struct obd_import *imp = class_exp2cliimp(exp);
1075 if (KEY_IS(KEY_INIT_RECOV)) {
1076 if (vallen != sizeof(int))
1078 spin_lock(&imp->imp_lock);
1079 imp->imp_initial_recov = *(int *)val;
1080 spin_unlock(&imp->imp_lock);
1081 CDEBUG(D_HA, "%s: set imp_initial_recov = %d\n",
1082 exp->exp_obd->obd_name, imp->imp_initial_recov);
1085 /* Turn off initial_recov after we try all backup servers once */
1086 if (KEY_IS(KEY_INIT_RECOV_BACKUP)) {
1087 if (vallen != sizeof(int))
1089 spin_lock(&imp->imp_lock);
1090 imp->imp_initial_recov_bk = *(int *)val;
1091 if (imp->imp_initial_recov_bk)
1092 imp->imp_initial_recov = 1;
1093 spin_unlock(&imp->imp_lock);
1094 CDEBUG(D_HA, "%s: set imp_initial_recov_bk = %d\n",
1095 exp->exp_obd->obd_name, imp->imp_initial_recov_bk);
1098 if (KEY_IS(KEY_READ_ONLY)) {
1099 struct ptlrpc_request *req;
1100 int size[3] = { sizeof(struct ptlrpc_body), keylen, vallen };
1101 char *bufs[3] = { NULL, key, val };
1103 if (vallen != sizeof(int))
1106 spin_lock(&imp->imp_lock);
1107 if (*((int *)val)) {
1108 imp->imp_connect_flags_orig |= OBD_CONNECT_RDONLY;
1109 imp->imp_connect_data.ocd_connect_flags |=
1112 imp->imp_connect_flags_orig &= ~OBD_CONNECT_RDONLY;
1113 imp->imp_connect_data.ocd_connect_flags &=
1114 ~OBD_CONNECT_RDONLY;
1116 spin_unlock(&imp->imp_lock);
1118 req = ptlrpc_prep_req(imp, LUSTRE_MDS_VERSION, MDS_SET_INFO,
1123 ptlrpc_req_set_repsize(req, 1, NULL);
1126 ptlrpc_set_add_req(set, req);
1127 ptlrpc_check_set(set);
1129 rc = ptlrpc_queue_wait(req);
1130 ptlrpc_req_finished(req);
1135 if (KEY_IS(KEY_FLUSH_CTX)) {
1136 sptlrpc_import_flush_my_ctx(imp);
1139 if (KEY_IS(KEY_MDS_CONN)) {
1140 struct obd_import *imp = class_exp2cliimp(exp);
1142 /* mds-mds import */
1143 spin_lock(&imp->imp_lock);
1144 imp->imp_server_timeout = 1;
1145 spin_unlock(&imp->imp_lock);
1146 imp->imp_client->cli_request_portal = MDS_MDS_PORTAL;
1147 CDEBUG(D_OTHER|D_WARNING, "%s: timeout / 2\n", exp->exp_obd->obd_name);
1154 int mdc_get_info(struct obd_export *exp, __u32 keylen, void *key,
1155 __u32 *vallen, void *val)
1159 if (KEY_IS(KEY_MAX_EASIZE)) {
1160 int mdsize, *max_easize;
1162 if (*vallen != sizeof(int))
1164 mdsize = *(int*)val;
1165 if (mdsize > exp->exp_obd->u.cli.cl_max_mds_easize)
1166 exp->exp_obd->u.cli.cl_max_mds_easize = mdsize;
1168 *max_easize = exp->exp_obd->u.cli.cl_max_mds_easize;
1171 if (KEY_IS(KEY_CONN_DATA)) {
1172 struct obd_import *imp = class_exp2cliimp(exp);
1173 struct obd_connect_data *data = val;
1175 if (*vallen != sizeof(*data))
1178 *data = imp->imp_connect_data;
1185 static int mdc_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1188 struct ptlrpc_request *req;
1189 struct obd_statfs *msfs;
1190 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*msfs) };
1193 /* We could possibly pass max_age in the request (as an absolute
1194 * timestamp or a "seconds.usec ago") so the target can avoid doing
1195 * extra calls into the filesystem if that isn't necessary (e.g.
1196 * during mount that would help a bit). Having relative timestamps
1197 * is not so great if request processing is slow, while absolute
1198 * timestamps are not ideal because they need time synchronization. */
1199 req = ptlrpc_prep_req(obd->u.cli.cl_import, LUSTRE_MDS_VERSION,
1200 MDS_STATFS, 1, NULL, NULL);
1204 ptlrpc_req_set_repsize(req, 2, size);
1206 rc = ptlrpc_queue_wait(req);
1209 /* check connection error first */
1210 if (obd->u.cli.cl_import->imp_connect_error)
1211 rc = obd->u.cli.cl_import->imp_connect_error;
1216 msfs = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*msfs),
1217 lustre_swab_obd_statfs);
1219 CERROR("Can't unpack obd_statfs\n");
1220 GOTO(out, rc = -EPROTO);
1223 memcpy(osfs, msfs, sizeof(*msfs));
1226 ptlrpc_req_finished(req);
1231 static int mdc_pin(struct obd_export *exp, const struct lu_fid *fid,
1232 struct obd_capa *oc,
1233 struct obd_client_handle *handle, int flag)
1235 struct ptlrpc_request *req;
1236 struct mdt_body *body;
1237 int rc, size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) };
1240 size[REQ_REC_OFF + 1] = oc ? sizeof(struct lustre_capa) : 0;
1241 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1242 MDS_PIN, 3, size, NULL);
1246 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof (*body));
1249 mdc_pack_capa(req, REQ_REC_OFF + 1, oc);
1251 ptlrpc_req_set_repsize(req, 2, size);
1253 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1254 rc = ptlrpc_queue_wait(req);
1255 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1257 CERROR("pin failed: %d\n", rc);
1258 ptlrpc_req_finished(req);
1262 body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body),
1263 lustre_swab_mdt_body);
1265 ptlrpc_req_finished(req);
1269 memcpy(&handle->och_fh, &body->handle, sizeof(body->handle));
1270 handle->och_magic = OBD_CLIENT_HANDLE_MAGIC;
1272 OBD_ALLOC(handle->och_mod, sizeof(*handle->och_mod));
1273 if (handle->och_mod == NULL) {
1274 DEBUG_REQ(D_ERROR, req, "can't allocate mdc_open_data");
1277 handle->och_mod->mod_open_req = req; /* will be dropped by unpin */
1282 static int mdc_unpin(struct obd_export *exp,
1283 struct obd_client_handle *handle, int flag)
1285 struct ptlrpc_request *req;
1286 struct mdt_body *body;
1287 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
1290 if (handle->och_magic != OBD_CLIENT_HANDLE_MAGIC)
1293 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1294 MDS_CLOSE, 2, size, NULL);
1298 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
1299 memcpy(&body->handle, &handle->och_fh, sizeof(body->handle));
1302 ptlrpc_req_set_repsize(req, 1, NULL);
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);
1308 CERROR("unpin failed: %d\n", rc);
1310 ptlrpc_req_finished(req);
1311 ptlrpc_req_finished(handle->och_mod->mod_open_req);
1312 OBD_FREE(handle->och_mod, sizeof(*handle->och_mod));
1316 int mdc_sync(struct obd_export *exp, const struct lu_fid *fid,
1317 struct obd_capa *oc, struct ptlrpc_request **request)
1319 struct ptlrpc_request *req;
1320 int size[3] = { sizeof(struct ptlrpc_body), sizeof(struct mdt_body) };
1324 size[REQ_REC_OFF + 1] = oc ? sizeof(struct lustre_capa) : 0;
1325 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1326 MDS_SYNC, 3, size, NULL);
1328 RETURN(rc = -ENOMEM);
1330 mdc_pack_req_body(req, REQ_REC_OFF, 0, fid, oc, 0, 0);
1332 ptlrpc_req_set_repsize(req, 2, size);
1334 rc = ptlrpc_queue_wait(req);
1335 if (rc || request == NULL)
1336 ptlrpc_req_finished(req);
1343 static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
1344 enum obd_import_event event)
1348 LASSERT(imp->imp_obd == obd);
1351 case IMP_EVENT_DISCON: {
1353 /* XXX Pass event up to OBDs stack. used only for FLD now */
1354 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_DISCON, NULL);
1358 case IMP_EVENT_INACTIVE: {
1359 struct client_obd *cli = &obd->u.cli;
1361 * Flush current sequence to make client obtain new one
1362 * from server in case of disconnect/reconnect.
1363 * If range is already empty then no need to flush it.
1365 if (cli->cl_seq != NULL &&
1366 !range_is_exhausted(&cli->cl_seq->lcs_space)) {
1367 seq_client_flush(cli->cl_seq);
1370 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_INACTIVE, NULL);
1373 case IMP_EVENT_INVALIDATE: {
1374 struct ldlm_namespace *ns = obd->obd_namespace;
1376 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
1380 case IMP_EVENT_ACTIVE: {
1381 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_ACTIVE, NULL);
1385 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_OCD, NULL);
1389 CERROR("Unknown import event %x\n", event);
1395 static int mdc_fid_init(struct obd_export *exp)
1397 struct client_obd *cli = &exp->exp_obd->u.cli;
1402 OBD_ALLOC_PTR(cli->cl_seq);
1403 if (cli->cl_seq == NULL)
1406 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
1408 GOTO(out_free_seq, rc = -ENOMEM);
1410 snprintf(prefix, MAX_OBD_NAME + 5, "srv-%s",
1411 exp->exp_obd->obd_name);
1413 /* Init client side sequence-manager */
1414 rc = seq_client_init(cli->cl_seq, exp,
1415 LUSTRE_SEQ_METADATA,
1417 OBD_FREE(prefix, MAX_OBD_NAME + 5);
1419 GOTO(out_free_seq, rc);
1423 OBD_FREE_PTR(cli->cl_seq);
1428 static int mdc_fid_fini(struct obd_export *exp)
1430 struct client_obd *cli = &exp->exp_obd->u.cli;
1433 if (cli->cl_seq != NULL) {
1434 seq_client_fini(cli->cl_seq);
1435 OBD_FREE_PTR(cli->cl_seq);
1442 int mdc_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
1443 struct md_op_data *op_data)
1445 struct client_obd *cli = &exp->exp_obd->u.cli;
1446 struct lu_client_seq *seq = cli->cl_seq;
1448 RETURN(seq_client_alloc_fid(seq, fid));
1451 /* XXX This method is used only to clear current fid seq
1452 * once fld/mds insert failed */
1453 static int mdc_fid_delete(struct obd_export *exp, const struct lu_fid *fid)
1455 struct client_obd *cli = &exp->exp_obd->u.cli;
1457 seq_client_flush(cli->cl_seq);
1461 static int mdc_setup(struct obd_device *obd, struct lustre_cfg *cfg)
1463 struct client_obd *cli = &obd->u.cli;
1464 struct lprocfs_static_vars lvars;
1468 OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1469 if (!cli->cl_rpc_lock)
1471 mdc_init_rpc_lock(cli->cl_rpc_lock);
1475 OBD_ALLOC(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1476 if (!cli->cl_setattr_lock)
1477 GOTO(err_rpc_lock, rc = -ENOMEM);
1478 mdc_init_rpc_lock(cli->cl_setattr_lock);
1480 OBD_ALLOC(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1481 if (!cli->cl_close_lock)
1482 GOTO(err_setattr_lock, rc = -ENOMEM);
1483 mdc_init_rpc_lock(cli->cl_close_lock);
1485 rc = client_obd_setup(obd, cfg);
1487 GOTO(err_close_lock, rc);
1488 lprocfs_init_vars(mdc, &lvars);
1489 lprocfs_obd_setup(obd, lvars.obd_vars);
1491 rc = obd_llog_init(obd, NULL, obd, 0, NULL, NULL);
1494 CERROR("failed to setup llogging subsystems\n");
1500 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1502 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1504 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1509 /* Initialize the default and maximum LOV EA and cookie sizes. This allows
1510 * us to make MDS RPCs with large enough reply buffers to hold the
1511 * maximum-sized (= maximum striped) EA and cookie without having to
1512 * calculate this (via a call into the LOV + OSCs) each time we make an RPC. */
1513 int mdc_init_ea_size(struct obd_export *exp, int easize,
1514 int def_easize, int cookiesize)
1516 struct obd_device *obd = exp->exp_obd;
1517 struct client_obd *cli = &obd->u.cli;
1520 if (cli->cl_max_mds_easize < easize)
1521 cli->cl_max_mds_easize = easize;
1523 if (cli->cl_default_mds_easize < def_easize)
1524 cli->cl_default_mds_easize = def_easize;
1526 if (cli->cl_max_mds_cookiesize < cookiesize)
1527 cli->cl_max_mds_cookiesize = cookiesize;
1532 static int mdc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
1538 case OBD_CLEANUP_EARLY:
1539 case OBD_CLEANUP_EXPORTS:
1540 /* If we set up but never connected, the
1541 client import will not have been cleaned. */
1542 if (obd->u.cli.cl_import) {
1543 struct obd_import *imp;
1544 imp = obd->u.cli.cl_import;
1545 CERROR("client import never connected\n");
1546 ptlrpc_invalidate_import(imp);
1547 ptlrpc_free_rq_pool(imp->imp_rq_pool);
1548 class_destroy_import(imp);
1549 obd->u.cli.cl_import = NULL;
1552 case OBD_CLEANUP_SELF_EXP:
1553 rc = obd_llog_finish(obd, 0);
1555 CERROR("failed to cleanup llogging subsystems\n");
1556 case OBD_CLEANUP_OBD:
1562 static int mdc_cleanup(struct obd_device *obd)
1564 struct client_obd *cli = &obd->u.cli;
1566 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1567 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1568 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1570 lprocfs_obd_cleanup(obd);
1573 return client_obd_cleanup(obd);
1577 static int mdc_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
1578 struct obd_device *tgt,
1579 int count, struct llog_catid *logid,
1580 struct obd_uuid *uuid)
1582 struct llog_ctxt *ctxt;
1586 rc = llog_setup(obd, llogs, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
1589 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
1590 ctxt->loc_imp = obd->u.cli.cl_import;
1593 rc = llog_setup(obd, llogs, LLOG_LOVEA_REPL_CTXT, tgt, 0, NULL,
1596 ctxt = llog_get_context(obd, LLOG_LOVEA_REPL_CTXT);
1597 ctxt->loc_imp = obd->u.cli.cl_import;
1603 static int mdc_llog_finish(struct obd_device *obd, int count)
1608 rc = llog_cleanup(llog_get_context(obd, LLOG_LOVEA_REPL_CTXT));
1610 CERROR("can not cleanup LLOG_CONFIG_REPL_CTXT rc %d\n", rc);
1612 rc = llog_cleanup(llog_get_context(obd, LLOG_CONFIG_REPL_CTXT));
1616 static int mdc_process_config(struct obd_device *obd, obd_count len, void *buf)
1618 struct lustre_cfg *lcfg = buf;
1619 struct lprocfs_static_vars lvars;
1622 lprocfs_init_vars(mdc, &lvars);
1624 rc = class_process_proc_param(PARAM_MDC, lvars.obd_vars, lcfg, obd);
1628 /* get remote permission for current user on fid */
1629 int mdc_get_remote_perm(struct obd_export *exp, const struct lu_fid *fid,
1630 struct obd_capa *oc, struct ptlrpc_request **request)
1632 struct ptlrpc_request *req;
1633 struct mdt_body *body;
1634 struct mdt_remote_perm *perm;
1635 int size[5] = { sizeof(struct ptlrpc_body), sizeof(*body) };
1639 size[REQ_REC_OFF + 1] = oc ? sizeof(struct lustre_capa) : 0;
1642 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1643 MDS_GETATTR, 3, size, NULL);
1647 mdc_pack_req_body(req, REQ_REC_OFF, OBD_MD_FLRMTPERM, fid, oc, 0, 0);
1649 size[REPLY_REC_OFF + 1] = sizeof(*perm);
1650 ptlrpc_req_set_repsize(req, 5, size);
1651 rc = ptlrpc_queue_wait(req);
1653 ptlrpc_req_finished(req);
1657 body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body),
1658 lustre_swab_mdt_body);
1660 LASSERT(body->valid & OBD_MD_FLRMTPERM);
1662 perm = lustre_swab_repbuf(req, REPLY_REC_OFF + 1, sizeof(*perm),
1663 lustre_swab_mdt_remote_perm);
1670 static int mdc_interpret_renew_capa(struct ptlrpc_request *req, void *unused,
1673 struct obd_capa *oc = req->rq_async_args.pointer_arg[0];
1674 renew_capa_cb_t cb = req->rq_async_args.pointer_arg[1];
1675 struct mdt_body *body = NULL;
1676 struct lustre_capa *capa;
1680 GOTO(out, capa = ERR_PTR(status));
1682 body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body),
1683 lustre_swab_mdt_body);
1685 GOTO(out, capa = ERR_PTR(-EFAULT));
1687 if ((body->valid & OBD_MD_FLOSSCAPA) == 0)
1688 GOTO(out, capa = ERR_PTR(-ENOENT));
1690 capa = lustre_unpack_capa(req->rq_repmsg, REPLY_REC_OFF + 1);
1692 GOTO(out, capa = ERR_PTR(-EFAULT));
1699 static int mdc_renew_capa(struct obd_export *exp, struct obd_capa *oc,
1702 struct ptlrpc_request *req;
1703 int size[5] = { sizeof(struct ptlrpc_body),
1704 sizeof(struct mdt_body),
1705 sizeof(struct lustre_capa) };
1708 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1709 MDS_GETATTR, 3, size, NULL);
1713 mdc_pack_req_body(req, REQ_REC_OFF, OBD_MD_FLOSSCAPA,
1714 &oc->c_capa.lc_fid, oc, 0, 0);
1716 ptlrpc_req_set_repsize(req, 5, size);
1717 req->rq_async_args.pointer_arg[0] = oc;
1718 req->rq_async_args.pointer_arg[1] = cb;
1719 req->rq_interpret_reply = mdc_interpret_renew_capa;
1720 ptlrpcd_add_req(req);
1725 static int mdc_connect(const struct lu_env *env,
1726 struct lustre_handle *dlm_handle,
1727 struct obd_device *obd, struct obd_uuid *cluuid,
1728 struct obd_connect_data *data) {
1729 struct obd_import *imp = obd->u.cli.cl_import;
1731 /* mds-mds import features */
1732 if (data && (data->ocd_connect_flags & OBD_CONNECT_MDS_MDS)) {
1733 spin_lock(&imp->imp_lock);
1734 imp->imp_server_timeout = 1;
1735 spin_unlock(&imp->imp_lock);
1736 imp->imp_client->cli_request_portal = MDS_MDS_PORTAL;
1737 CDEBUG(D_OTHER, "%s: Set 'mds' portal and timeout\n",
1741 return client_connect_import(env, dlm_handle, obd, cluuid, data);
1744 struct obd_ops mdc_obd_ops = {
1745 .o_owner = THIS_MODULE,
1746 .o_setup = mdc_setup,
1747 .o_precleanup = mdc_precleanup,
1748 .o_cleanup = mdc_cleanup,
1749 .o_add_conn = client_import_add_conn,
1750 .o_del_conn = client_import_del_conn,
1751 .o_connect = mdc_connect,
1752 .o_disconnect = client_disconnect_export,
1753 .o_iocontrol = mdc_iocontrol,
1754 .o_set_info_async = mdc_set_info_async,
1755 .o_statfs = mdc_statfs,
1757 .o_unpin = mdc_unpin,
1758 .o_fid_init = mdc_fid_init,
1759 .o_fid_fini = mdc_fid_fini,
1760 .o_fid_alloc = mdc_fid_alloc,
1761 .o_fid_delete = mdc_fid_delete,
1762 .o_import_event = mdc_import_event,
1763 .o_llog_init = mdc_llog_init,
1764 .o_llog_finish = mdc_llog_finish,
1765 .o_get_info = mdc_get_info,
1766 .o_process_config = mdc_process_config,
1769 struct md_ops mdc_md_ops = {
1770 .m_getstatus = mdc_getstatus,
1771 .m_change_cbdata = mdc_change_cbdata,
1772 .m_close = mdc_close,
1773 .m_create = mdc_create,
1774 .m_done_writing = mdc_done_writing,
1775 .m_enqueue = mdc_enqueue,
1776 .m_getattr = mdc_getattr,
1777 .m_getattr_name = mdc_getattr_name,
1778 .m_intent_lock = mdc_intent_lock,
1780 .m_is_subdir = mdc_is_subdir,
1781 .m_rename = mdc_rename,
1782 .m_setattr = mdc_setattr,
1783 .m_setxattr = mdc_setxattr,
1784 .m_getxattr = mdc_getxattr,
1786 .m_readpage = mdc_readpage,
1787 .m_unlink = mdc_unlink,
1788 .m_cancel_unused = mdc_cancel_unused,
1789 .m_init_ea_size = mdc_init_ea_size,
1790 .m_set_lock_data = mdc_set_lock_data,
1791 .m_lock_match = mdc_lock_match,
1792 .m_get_lustre_md = mdc_get_lustre_md,
1793 .m_free_lustre_md = mdc_free_lustre_md,
1794 .m_set_open_replay_data = mdc_set_open_replay_data,
1795 .m_clear_open_replay_data = mdc_clear_open_replay_data,
1796 .m_get_remote_perm = mdc_get_remote_perm,
1797 .m_renew_capa = mdc_renew_capa
1800 extern quota_interface_t mdc_quota_interface;
1802 int __init mdc_init(void)
1805 struct lprocfs_static_vars lvars;
1806 lprocfs_init_vars(mdc, &lvars);
1808 request_module("lquota");
1809 quota_interface = PORTAL_SYMBOL_GET(mdc_quota_interface);
1810 init_obd_quota_ops(quota_interface, &mdc_obd_ops);
1812 rc = class_register_type(&mdc_obd_ops, &mdc_md_ops, lvars.module_vars,
1813 LUSTRE_MDC_NAME, NULL);
1814 if (rc && quota_interface)
1815 PORTAL_SYMBOL_PUT(mdc_quota_interface);
1821 static void /*__exit*/ mdc_exit(void)
1823 if (quota_interface)
1824 PORTAL_SYMBOL_PUT(mdc_quota_interface);
1826 class_unregister_type(LUSTRE_MDC_NAME);
1829 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1830 MODULE_DESCRIPTION("Lustre Metadata Client");
1831 MODULE_LICENSE("GPL");
1833 module_init(mdc_init);
1834 module_exit(mdc_exit);