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 int mdc_cleanup(struct obd_device *obd);
54 extern int mds_queue_req(struct ptlrpc_request *);
56 static inline struct obd_capa *mdc_unpack_capa(struct ptlrpc_request *req,
59 struct lustre_capa *capa;
62 /* swabbed already in mdc_enqueue */
63 capa = lustre_msg_buf(req->rq_repmsg, offset, sizeof(*capa));
65 CERROR("missing capa at offset %d failed!\n", offset);
66 return ERR_PTR(-EFAULT);
69 oc = alloc_capa(CAPA_SITE_CLIENT);
71 CERROR("alloc capa failed!\n");
72 return ERR_PTR(-ENOMEM);
79 /* Helper that implements most of mdc_getstatus and signal_completed_replay. */
80 /* XXX this should become mdc_get_info("key"), sending MDS_GET_INFO RPC */
81 static int send_getstatus(struct obd_import *imp, struct lu_fid *rootfid,
82 struct obd_capa **pc, int level, int msg_flags)
84 struct ptlrpc_request *req;
85 struct mdt_body *body;
86 int rc, size[3] = { sizeof(struct ptlrpc_body),
88 sizeof(struct lustre_capa) };
91 req = ptlrpc_prep_req(imp, LUSTRE_MDS_VERSION, MDS_GETSTATUS, 2, size,
94 GOTO(out, rc = -ENOMEM);
96 req->rq_send_state = level;
97 ptlrpc_req_set_repsize(req, 3, size);
99 mdc_pack_req_body(req, REQ_REC_OFF, 0, NULL, NULL, 0, 0);
100 lustre_msg_add_flags(req->rq_reqmsg, msg_flags);
101 rc = ptlrpc_queue_wait(req);
104 body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body),
105 lustre_swab_mdt_body);
107 CERROR ("Can't extract mdt_body\n");
108 GOTO (out, rc = -EPROTO);
111 *rootfid = body->fid1;
113 if (body->valid & OBD_MD_FLMDSCAPA) {
116 oc = mdc_unpack_capa(req, REPLY_REC_OFF + 1);
118 GOTO(out, rc = PTR_ERR(oc));
122 CDEBUG(D_NET, "root fid="DFID", last_committed="LPU64
123 ", last_xid="LPU64"\n",
125 lustre_msg_get_last_committed(req->rq_repmsg),
126 lustre_msg_get_last_xid(req->rq_repmsg));
131 ptlrpc_req_finished(req);
135 /* This should be mdc_get_info("rootfid") */
136 int mdc_getstatus(struct obd_export *exp, struct lu_fid *rootfid,
137 struct obd_capa **pc)
139 return send_getstatus(class_exp2cliimp(exp), rootfid, pc,
144 * This function now is known to always saying that it will receive 4 buffers
145 * from server. Even for cases when acl_size and md_size is zero, RPC header
146 * willcontain 4 fields and RPC itself will contain zero size fields. This is
147 * because mdt_getattr*() _always_ returns 4 fields, but if acl is not needed
148 * and thus zero, it shirinks it, making zero size. The same story about
149 * md_size. And this is course of problem when client waits for smaller number
150 * of fields. This issue will be fixed later when client gets awar of RPC
153 static int mdc_getattr_common(struct obd_export *exp, unsigned int ea_size,
154 unsigned int acl_size, int mdscapa,
155 struct ptlrpc_request *req)
157 struct mdt_body *body;
159 int size[5] = { sizeof(struct ptlrpc_body),
166 /* Request message already built. */
168 CDEBUG(D_INODE, "reserved %u bytes for MD/symlink in packet\n",
171 CDEBUG(D_INODE, "reserved %u bytes for ACL\n", acl_size);
173 size[REPLY_REC_OFF + 2] = sizeof(struct lustre_capa);
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;
237 size[REQ_REC_OFF + 1] = sizeof(struct lustre_capa);
240 * XXX do we need to make another request here? We just did a getattr
241 * to do the lookup in the first place.
243 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
244 MDS_GETATTR, 3, size, NULL);
246 GOTO(out, rc = -ENOMEM);
248 mdc_pack_req_body(req, REQ_REC_OFF, valid, fid, oc, ea_size,
249 MDS_BFLAG_EXT_FLAGS/*request "new" flags(bug 9486)*/);
251 /* currently only root inode will call us with FLACL */
252 if (valid & OBD_MD_FLACL)
253 acl_size = LUSTRE_POSIX_ACL_MAX_SIZE;
255 rc = mdc_getattr_common(exp, ea_size, acl_size,
256 !!(valid & OBD_MD_FLMDSCAPA), req);
258 ptlrpc_req_finished (req);
266 int mdc_getattr_name(struct obd_export *exp, const struct lu_fid *fid,
267 struct obd_capa *oc, const char *filename, int namelen,
268 obd_valid valid, int ea_size,
269 struct ptlrpc_request **request)
271 struct ptlrpc_request *req;
272 struct mdt_body *body;
273 int size[4] = { sizeof(struct ptlrpc_body), sizeof(*body), 0, namelen};
278 size[REQ_REC_OFF + 1] = sizeof(struct lustre_capa);
280 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
281 MDS_GETATTR_NAME, 4, size, NULL);
283 GOTO(out, rc = -ENOMEM);
285 mdc_pack_req_body(req, REQ_REC_OFF, valid, fid, oc, ea_size,
286 MDS_BFLAG_EXT_FLAGS/*request "new" flags(bug 9486)*/);
288 LASSERT(strnlen(filename, namelen) == namelen - 1);
289 memcpy(lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 2, namelen),
292 rc = mdc_getattr_common(exp, ea_size, 0, !!(valid & OBD_MD_FLMDSCAPA),
295 ptlrpc_req_finished (req);
303 int mdc_is_subdir(struct obd_export *exp, const struct lu_fid *pfid,
304 const struct lu_fid *cfid,
305 struct obd_capa *pc, struct obd_capa *cc,
306 struct ptlrpc_request **request)
308 int size[4] = { sizeof(struct ptlrpc_body),
309 sizeof(struct mdt_body) };
310 struct ptlrpc_request *req;
311 struct mdt_body *body;
316 size[REQ_REC_OFF + 1] = sizeof(struct lustre_capa);
318 size[REQ_REC_OFF + 2] = sizeof(struct lustre_capa);
320 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
321 MDS_IS_SUBDIR, 4, size, NULL);
323 GOTO(out, rc = -ENOMEM);
325 mdc_is_subdir_pack(req, REQ_REC_OFF, pfid, cfid, pc, cc, 0);
327 ptlrpc_req_set_repsize(req, 2, size);
328 rc = ptlrpc_queue_wait(req);
332 body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body),
333 lustre_swab_mdt_body);
335 CERROR ("Can't unpack mdt_body\n");
336 GOTO(out, rc = -EPROTO);
345 int mdc_xattr_common(struct obd_export *exp, const struct lu_fid *fid,
347 int opcode, obd_valid valid, const char *xattr_name,
348 const char *input, int input_size, int output_size,
349 int flags, struct ptlrpc_request **request)
351 struct ptlrpc_request *req;
352 int size[5] = { sizeof(struct ptlrpc_body), sizeof(struct mdt_body) };
353 int bufcnt = 3, offset = REQ_REC_OFF + 2;
354 int rc, xattr_namelen = 0, remote_acl = 0;
359 size[REQ_REC_OFF + 1] = sizeof(struct lustre_capa);
361 xattr_namelen = strlen(xattr_name) + 1;
362 size[bufcnt++] = xattr_namelen;
366 size[bufcnt++] = input_size;
369 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
370 opcode, bufcnt, size, NULL);
372 GOTO(out, rc = -ENOMEM);
375 mdc_pack_req_body(req, REQ_REC_OFF, valid, fid, oc, output_size, flags);
379 tmp = lustre_msg_buf(req->rq_reqmsg, offset++, xattr_namelen);
380 memcpy(tmp, xattr_name, xattr_namelen);
381 if (!strcmp(xattr_name, XATTR_NAME_LUSTRE_ACL))
385 tmp = lustre_msg_buf(req->rq_reqmsg, offset++, input_size);
386 memcpy(tmp, input, input_size);
390 if (opcode == MDS_GETXATTR) {
391 size[REPLY_REC_OFF] = sizeof(struct mdt_body);
397 /* we do this even output_size is 0, because server is doing that */
398 size[bufcnt++] = output_size;
399 ptlrpc_req_set_repsize(req, bufcnt, size);
402 /* NB: set remote acl doesn't need hold rpc lock, because it just
403 * send command to MDS, and when it's executed on mountpoint on MDS,
404 * another mdc_xattr_common() will be invoked there. */
405 if (opcode == MDS_SETXATTR && !remote_acl)
406 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
408 rc = ptlrpc_queue_wait(req);
410 if (opcode == MDS_SETXATTR && !remote_acl)
411 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
416 if (opcode == MDS_GETXATTR) {
417 struct mdt_body * body = lustre_swab_repbuf(req, REPLY_REC_OFF,
418 sizeof(*body), lustre_swab_mdt_body);
420 CERROR ("Can't unpack mdt_body\n");
421 GOTO(err_out, rc = -EPROTO);
428 ptlrpc_req_finished(req);
433 int mdc_setxattr(struct obd_export *exp, const struct lu_fid *fid,
434 struct obd_capa *oc, obd_valid valid, const char *xattr_name,
435 const char *input, int input_size, int output_size, int flags,
436 struct ptlrpc_request **request)
438 return mdc_xattr_common(exp, fid, oc, MDS_SETXATTR, valid, xattr_name,
439 input, input_size, output_size, flags, request);
442 int mdc_getxattr(struct obd_export *exp, const struct lu_fid *fid,
443 struct obd_capa *oc, obd_valid valid, const char *xattr_name,
444 const char *input, int input_size, int output_size, int flags,
445 struct ptlrpc_request **request)
447 return mdc_xattr_common(exp, fid, oc, MDS_GETXATTR, valid, xattr_name,
448 input, input_size, output_size, flags, request);
451 #ifdef CONFIG_FS_POSIX_ACL
453 int mdc_unpack_acl(struct obd_export *exp, struct ptlrpc_request *req,
454 struct lustre_md *md, unsigned int offset)
456 struct mdt_body *body = md->body;
457 struct posix_acl *acl;
464 buf = lustre_msg_buf(req->rq_repmsg, offset, body->aclsize);
466 CERROR("aclsize %u, bufcount %u, bufsize %u\n",
467 body->aclsize, lustre_msg_bufcount(req->rq_repmsg),
468 (lustre_msg_bufcount(req->rq_repmsg) <= offset) ?
469 -1 : lustre_msg_buflen(req->rq_repmsg, offset));
473 acl = posix_acl_from_xattr(buf, body->aclsize);
476 CERROR("convert xattr to acl: %d\n", rc);
480 rc = posix_acl_valid(acl);
482 CERROR("validate acl: %d\n", rc);
483 posix_acl_release(acl);
491 #define mdc_unpack_acl(exp, req, md, offset) 0
494 int mdc_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
495 int offset, struct obd_export *dt_exp,
496 struct obd_export *md_exp,
497 struct lustre_md *md)
503 memset(md, 0, sizeof(*md));
505 md->body = lustre_msg_buf(req->rq_repmsg, offset, sizeof (*md->body));
506 LASSERT (md->body != NULL);
507 LASSERT_REPSWABBED(req, offset);
510 if (md->body->valid & OBD_MD_FLEASIZE) {
512 struct lov_mds_md *lmm;
514 LASSERT(S_ISREG(md->body->mode));
516 if (md->body->eadatasize == 0) {
517 CERROR("OBD_MD_FLEASIZE set, but eadatasize 0\n");
520 lmmsize = md->body->eadatasize;
521 lmm = lustre_msg_buf(req->rq_repmsg, offset, lmmsize);
522 LASSERT (lmm != NULL);
523 LASSERT_REPSWABBED(req, offset);
525 rc = obd_unpackmd(dt_exp, &md->lsm, lmm, lmmsize);
529 LASSERT (rc >= sizeof (*md->lsm));
531 } else if (md->body->valid & OBD_MD_FLDIREA) {
533 struct lov_mds_md *lmv;
534 LASSERT(S_ISDIR(md->body->mode));
536 if (md->body->eadatasize == 0) {
537 CERROR("OBD_MD_FLEASIZE set, but eadatasize 0\n");
540 if (md->body->valid & OBD_MD_MEA) {
541 lmvsize = md->body->eadatasize;
542 lmv = lustre_msg_buf(req->rq_repmsg, offset, lmvsize);
543 LASSERT (lmv != NULL);
544 LASSERT_REPSWABBED(req, offset);
546 rc = obd_unpackmd(md_exp, (void *)&md->mea, lmv,
551 LASSERT (rc >= sizeof (*md->mea));
557 /* for ACL, it's possible that FLACL is set but aclsize is zero. only
558 * when aclsize != 0 there's an actual segment for ACL in reply
560 if ((md->body->valid & OBD_MD_FLACL) && md->body->aclsize) {
561 rc = mdc_unpack_acl(dt_exp, req, md, offset++);
566 /* remote permission */
567 if (md->body->valid & OBD_MD_FLRMTPERM) {
568 md->remote_perm = lustre_msg_buf(req->rq_repmsg, offset++,
569 sizeof(struct mdt_remote_perm));
570 LASSERT(md->remote_perm);
573 if (md->body->valid & OBD_MD_FLMDSCAPA) {
574 struct obd_capa *oc = mdc_unpack_capa(req, offset++);
577 GOTO(out, rc = PTR_ERR(oc));
581 if (md->body->valid & OBD_MD_FLOSSCAPA) {
582 struct obd_capa *oc = mdc_unpack_capa(req, offset++);
585 GOTO(out, rc = PTR_ERR(oc));
593 free_capa(md->oss_capa);
595 free_capa(md->mds_capa);
596 #ifdef CONFIG_FS_POSIX_ACL
597 posix_acl_release(md->posix_acl);
600 obd_free_memmd(dt_exp, &md->lsm);
605 int mdc_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
609 obd_free_memmd(exp, &md->lsm);
611 #ifdef CONFIG_FS_POSIX_ACL
613 posix_acl_release(md->posix_acl);
614 md->posix_acl = NULL;
620 static void mdc_commit_open(struct ptlrpc_request *req)
622 struct mdc_open_data *mod = req->rq_cb_data;
626 if (mod->mod_close_req != NULL)
627 mod->mod_close_req->rq_cb_data = NULL;
629 if (mod->mod_och != NULL)
630 mod->mod_och->och_mod = NULL;
632 OBD_FREE(mod, sizeof(*mod));
633 req->rq_cb_data = NULL;
636 static void mdc_replay_open(struct ptlrpc_request *req)
638 struct mdc_open_data *mod = req->rq_cb_data;
639 struct obd_client_handle *och;
640 struct ptlrpc_request *close_req;
641 struct lustre_handle old;
642 struct mdt_body *body;
646 DEBUG_REQ(D_ERROR, req,
647 "Can't properly replay without open data.");
652 body = lustre_swab_repbuf(req, DLM_REPLY_REC_OFF, sizeof(*body),
653 lustre_swab_mdt_body);
657 struct lustre_handle *file_fh;
659 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
660 LASSERT(body != NULL);
662 file_fh = &och->och_fh;
663 CDEBUG(D_HA, "updating handle from "LPX64" to "LPX64"\n",
664 file_fh->cookie, body->handle.cookie);
665 memcpy(&old, file_fh, sizeof(old));
666 memcpy(file_fh, &body->handle, sizeof(*file_fh));
669 close_req = mod->mod_close_req;
670 if (close_req != NULL) {
671 struct mdt_epoch *epoch;
673 LASSERT(lustre_msg_get_opc(close_req->rq_reqmsg) == MDS_CLOSE);
674 LASSERT(body != NULL);
676 epoch = lustre_msg_buf(close_req->rq_reqmsg, REQ_REC_OFF,
680 LASSERT(!memcmp(&old, &epoch->handle, sizeof old));
681 DEBUG_REQ(D_HA, close_req, "updating close body with new fh");
682 memcpy(&epoch->handle, &body->handle,
683 sizeof(epoch->handle));
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 mdc_open_data *mod;
694 struct mdt_rec_create *rec = lustre_msg_buf(open_req->rq_reqmsg,
697 struct mdt_body *body = lustre_msg_buf(open_req->rq_repmsg,
702 /* incoming message in my byte order (it's been swabbed) */
703 LASSERT(rec != NULL);
704 LASSERT_REPSWABBED(open_req, DLM_REPLY_REC_OFF);
705 /* outgoing messages always in my byte order */
706 LASSERT(body != NULL);
709 OBD_ALLOC(mod, sizeof(*mod));
711 DEBUG_REQ(D_ERROR, open_req, "can't allocate mdc_open_data");
717 mod->mod_open_req = open_req;
718 open_req->rq_cb_data = mod;
719 open_req->rq_commit_cb = mdc_commit_open;
722 rec->cr_fid2 = body->fid1;
723 rec->cr_ioepoch = body->ioepoch;
724 open_req->rq_replay_cb = mdc_replay_open;
725 if (!fid_is_sane(&body->fid1)) {
726 DEBUG_REQ(D_ERROR, open_req, "saving replay request with "
731 DEBUG_REQ(D_HA, open_req, "set up replay data");
735 int mdc_clear_open_replay_data(struct obd_export *exp,
736 struct obd_client_handle *och)
738 struct mdc_open_data *mod = och->och_mod;
741 /* Don't free the structure now (it happens in mdc_commit_open, after
742 * we're sure we won't need to fix up the close request in the future),
743 * but make sure that replay doesn't poke at the och, which is about to
745 LASSERT(mod != LP_POISON);
752 static void mdc_commit_close(struct ptlrpc_request *req)
754 struct mdc_open_data *mod = req->rq_cb_data;
755 struct ptlrpc_request *open_req;
756 struct obd_import *imp = req->rq_import;
758 DEBUG_REQ(D_HA, req, "close req committed");
762 mod->mod_close_req = NULL;
763 req->rq_cb_data = NULL;
764 req->rq_commit_cb = NULL;
766 open_req = mod->mod_open_req;
767 LASSERT(open_req != NULL);
768 LASSERT(open_req != LP_POISON);
769 LASSERT(open_req->rq_type != LI_POISON);
771 DEBUG_REQ(D_HA, open_req, "open req balanced");
772 LASSERT(open_req->rq_transno != 0);
773 LASSERT(open_req->rq_import == imp);
775 /* We no longer want to preserve this for transno-unconditional
777 spin_lock(&open_req->rq_lock);
778 open_req->rq_replay = 0;
779 spin_unlock(&open_req->rq_lock);
782 int mdc_close(struct obd_export *exp, struct md_op_data *op_data,
783 struct obd_client_handle *och, struct ptlrpc_request **request)
785 struct obd_device *obd = class_exp2obd(exp);
786 int reqsize[4] = { sizeof(struct ptlrpc_body),
787 sizeof(struct mdt_epoch),
788 sizeof(struct mdt_rec_setattr)};
789 int repsize[4] = { sizeof(struct ptlrpc_body),
790 sizeof(struct mdt_body),
791 obd->u.cli.cl_max_mds_easize,
792 obd->u.cli.cl_max_mds_cookiesize };
793 struct ptlrpc_request *req;
794 struct mdc_open_data *mod;
798 if (op_data->mod_capa1)
799 reqsize[REQ_REC_OFF + 2] = sizeof(struct lustre_capa);
800 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
801 MDS_CLOSE, 4, reqsize, NULL);
803 GOTO(out, rc = -ENOMEM);
805 /* To avoid a livelock (bug 7034), we need to send CLOSE RPCs to a
806 * portal whose threads are not taking any DLM locks and are therefore
807 * always progressing */
808 /* XXX FIXME bug 249 */
809 req->rq_request_portal = MDS_READPAGE_PORTAL;
811 /* Ensure that this close's handle is fixed up during replay. */
812 LASSERT(och != NULL);
813 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
815 if (likely(mod != NULL)) {
816 mod->mod_close_req = req;
817 if (mod->mod_open_req->rq_type == LI_POISON) {
818 /* FIXME This should be an ASSERT, but until we
819 figure out why it can be poisoned here, give
820 a reasonable return. bug 6155 */
821 CERROR("LBUG POISONED open %p!\n", mod->mod_open_req);
822 ptlrpc_req_finished(req);
824 GOTO(out, rc = -EIO);
826 DEBUG_REQ(D_HA, mod->mod_open_req, "matched open");
828 CDEBUG(D_HA, "couldn't find open req; expecting close error\n");
831 mdc_close_pack(req, REQ_REC_OFF, op_data);
832 ptlrpc_req_set_repsize(req, 4, repsize);
833 req->rq_commit_cb = mdc_commit_close;
834 LASSERT(req->rq_cb_data == NULL);
835 req->rq_cb_data = mod;
837 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
838 rc = ptlrpc_queue_wait(req);
839 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
841 if (req->rq_repmsg == NULL) {
842 CDEBUG(D_HA, "request failed to send: %p, %d\n", req,
845 rc = req->rq_status ? req->rq_status : -EIO;
846 } else if (rc == 0) {
847 rc = lustre_msg_get_status(req->rq_repmsg);
848 if (lustre_msg_get_type(req->rq_repmsg) == PTL_RPC_MSG_ERR) {
849 DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, err "
853 } else if (mod == NULL) {
854 CERROR("Unexpected: can't find mdc_open_data, but the "
855 "close succeeded. Please tell CFS.\n");
857 if (!lustre_swab_repbuf(req, REPLY_REC_OFF,
858 sizeof(struct mdt_body),
859 lustre_swab_mdt_body)) {
860 CERROR("Error unpacking mdt_body\n");
868 if (rc != 0 && req && req->rq_commit_cb)
869 req->rq_commit_cb(req);
874 int mdc_done_writing(struct obd_export *exp, struct md_op_data *op_data,
875 struct obd_client_handle *och)
877 struct ptlrpc_request *req;
878 int size[4] = { sizeof(struct ptlrpc_body),
879 sizeof(struct mdt_epoch),
880 sizeof(struct mdt_rec_setattr)};
881 int repsize[2] = { sizeof(struct ptlrpc_body),
882 sizeof(struct mdt_body)};
886 if (op_data->mod_capa1)
887 size[REQ_REC_OFF + 2] = sizeof(struct lustre_capa);
888 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
889 MDS_DONE_WRITING, 4, size, NULL);
893 /* XXX: add DONE_WRITING request to och -- when Size-on-MDS
894 * recovery will be ready. */
895 mdc_close_pack(req, REQ_REC_OFF, op_data);
897 ptlrpc_req_set_repsize(req, 2, repsize);
898 rc = ptlrpc_queue_wait(req);
899 ptlrpc_req_finished(req);
903 #ifdef HAVE_SPLIT_SUPPORT
904 int mdc_sendpage(struct obd_export *exp, const struct lu_fid *fid,
905 const struct page *page, int offset)
907 struct obd_import *imp = class_exp2cliimp(exp);
908 struct ptlrpc_request *req = NULL;
909 struct ptlrpc_bulk_desc *desc = NULL;
910 struct mdt_body *body;
911 int rc, size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) };
914 CDEBUG(D_INODE, "object: "DFID"\n", PFID(fid));
916 req = ptlrpc_prep_req(imp, LUSTRE_MDS_VERSION, MDS_WRITEPAGE, 3, size,
919 GOTO(out, rc = -ENOMEM);
921 req->rq_request_portal = MDS_READPAGE_PORTAL;
923 desc = ptlrpc_prep_bulk_imp(req, 1, BULK_GET_SOURCE, MDS_BULK_PORTAL);
925 GOTO(out, rc = -ENOMEM);
926 /* NB req now owns desc and will free it when it gets freed */
927 ptlrpc_prep_bulk_page(desc, (struct page*)page, 0, offset);
929 mdc_readdir_pack(req, REQ_REC_OFF, 0, offset, fid, NULL);
931 ptlrpc_req_set_repsize(req, 2, size);
932 rc = ptlrpc_queue_wait(req);
934 ptlrpc_req_finished(req);
937 EXPORT_SYMBOL(mdc_sendpage);
940 int mdc_readpage(struct obd_export *exp, const struct lu_fid *fid,
941 struct obd_capa *oc, __u64 offset, struct page *page,
942 struct ptlrpc_request **request)
944 struct obd_import *imp = class_exp2cliimp(exp);
945 struct ptlrpc_request *req = NULL;
946 struct ptlrpc_bulk_desc *desc = NULL;
947 struct mdt_body *body;
948 int rc, size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) };
951 CDEBUG(D_INODE, "object: "DFID"\n", PFID(fid));
954 size[REQ_REC_OFF + 1] = sizeof(struct lustre_capa);
955 req = ptlrpc_prep_req(imp, LUSTRE_MDS_VERSION, MDS_READPAGE, 3, size,
958 GOTO(out, rc = -ENOMEM);
960 /* XXX FIXME bug 249 */
961 req->rq_request_portal = MDS_READPAGE_PORTAL;
963 desc = ptlrpc_prep_bulk_imp(req, 1, BULK_PUT_SINK, MDS_BULK_PORTAL);
965 GOTO(out, rc = -ENOMEM);
966 /* NB req now owns desc and will free it when it gets freed */
968 ptlrpc_prep_bulk_page(desc, page, 0, PAGE_CACHE_SIZE);
970 mdc_readdir_pack(req, REQ_REC_OFF, offset, PAGE_CACHE_SIZE, fid, oc);
972 ptlrpc_req_set_repsize(req, 2, size);
973 rc = ptlrpc_queue_wait(req);
975 if (rc == 0 || rc == -ERANGE) {
976 body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body),
977 lustre_swab_mdt_body);
979 CERROR("Can't unpack mdt_body\n");
980 GOTO(out, rc = -EPROTO);
983 if (req->rq_bulk->bd_nob_transferred != PAGE_CACHE_SIZE) {
984 CERROR ("Unexpected # bytes transferred: %d"
986 req->rq_bulk->bd_nob_transferred,
988 GOTO (out, rc = -EPROTO);
998 static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
999 void *karg, void *uarg)
1001 struct obd_device *obd = exp->exp_obd;
1002 struct obd_ioctl_data *data = karg;
1003 struct obd_import *imp = obd->u.cli.cl_import;
1004 struct llog_ctxt *ctxt;
1008 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1011 if (!try_module_get(THIS_MODULE)) {
1012 CERROR("Can't get module. Is it alive?");
1017 case OBD_IOC_CLIENT_RECOVER:
1018 rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1);
1022 case IOC_OSC_SET_ACTIVE:
1023 rc = ptlrpc_set_import_active(imp, data->ioc_offset);
1025 case OBD_IOC_PARSE: {
1026 ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT);
1027 rc = class_config_parse_llog(ctxt, data->ioc_inlbuf1, NULL);
1031 case OBD_IOC_LLOG_INFO:
1032 case OBD_IOC_LLOG_PRINT: {
1033 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
1034 rc = llog_ioctl(ctxt, cmd, data);
1039 case OBD_IOC_POLL_QUOTACHECK:
1040 rc = lquota_poll_check(quota_interface, exp,
1041 (struct if_quotacheck *)karg);
1044 CERROR("mdc_ioctl(): unrecognised ioctl %#x\n", cmd);
1045 GOTO(out, rc = -ENOTTY);
1048 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1051 module_put(THIS_MODULE);
1057 int mdc_set_info_async(struct obd_export *exp, obd_count keylen,
1058 void *key, obd_count vallen, void *val,
1059 struct ptlrpc_request_set *set)
1061 struct obd_import *imp = class_exp2cliimp(exp);
1064 if (KEY_IS(KEY_INIT_RECOV)) {
1065 if (vallen != sizeof(int))
1067 imp->imp_initial_recov = *(int *)val;
1068 CDEBUG(D_HA, "%s: set imp_initial_recov = %d\n",
1069 exp->exp_obd->obd_name, imp->imp_initial_recov);
1072 /* Turn off initial_recov after we try all backup servers once */
1073 if (KEY_IS(KEY_INIT_RECOV_BACKUP)) {
1074 if (vallen != sizeof(int))
1076 imp->imp_initial_recov_bk = *(int *)val;
1077 if (imp->imp_initial_recov_bk)
1078 imp->imp_initial_recov = 1;
1079 CDEBUG(D_HA, "%s: set imp_initial_recov_bk = %d\n",
1080 exp->exp_obd->obd_name, imp->imp_initial_recov_bk);
1083 if (KEY_IS("read-only")) {
1084 struct ptlrpc_request *req;
1085 int size[3] = { sizeof(struct ptlrpc_body), keylen, vallen };
1086 char *bufs[3] = { NULL, key, val };
1088 if (vallen != sizeof(int))
1091 if (*((int *)val)) {
1092 imp->imp_connect_flags_orig |= OBD_CONNECT_RDONLY;
1093 imp->imp_connect_data.ocd_connect_flags |=
1096 imp->imp_connect_flags_orig &= ~OBD_CONNECT_RDONLY;
1097 imp->imp_connect_data.ocd_connect_flags &=
1098 ~OBD_CONNECT_RDONLY;
1101 req = ptlrpc_prep_req(imp, LUSTRE_MDS_VERSION, MDS_SET_INFO,
1106 ptlrpc_req_set_repsize(req, 1, NULL);
1109 ptlrpc_set_add_req(set, req);
1110 ptlrpc_check_set(set);
1112 rc = ptlrpc_queue_wait(req);
1113 ptlrpc_req_finished(req);
1119 if (KEY_IS(KEY_FLUSH_CTX)) {
1120 sptlrpc_import_flush_my_ctx(imp);
1127 int mdc_get_info(struct obd_export *exp, __u32 keylen, void *key,
1128 __u32 *vallen, void *val)
1132 if (KEY_IS(KEY_MAX_EASIZE)) {
1133 int mdsize, *max_easize;
1135 if (*vallen != sizeof(int))
1137 mdsize = *(int*)val;
1138 if (mdsize > exp->exp_obd->u.cli.cl_max_mds_easize)
1139 exp->exp_obd->u.cli.cl_max_mds_easize = mdsize;
1141 *max_easize = exp->exp_obd->u.cli.cl_max_mds_easize;
1144 if (KEY_IS(KEY_CONN_DATA)) {
1145 struct obd_import *imp = class_exp2cliimp(exp);
1146 struct obd_connect_data *data = val;
1148 if (*vallen != sizeof(*data))
1151 *data = imp->imp_connect_data;
1158 static int mdc_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1161 struct ptlrpc_request *req;
1162 struct obd_statfs *msfs;
1163 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*msfs) };
1166 /* We could possibly pass max_age in the request (as an absolute
1167 * timestamp or a "seconds.usec ago") so the target can avoid doing
1168 * extra calls into the filesystem if that isn't necessary (e.g.
1169 * during mount that would help a bit). Having relative timestamps
1170 * is not so great if request processing is slow, while absolute
1171 * timestamps are not ideal because they need time synchronization. */
1172 req = ptlrpc_prep_req(obd->u.cli.cl_import, LUSTRE_MDS_VERSION,
1173 MDS_STATFS, 1, NULL, NULL);
1177 ptlrpc_req_set_repsize(req, 2, size);
1179 rc = ptlrpc_queue_wait(req);
1184 msfs = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*msfs),
1185 lustre_swab_obd_statfs);
1187 CERROR("Can't unpack obd_statfs\n");
1188 GOTO(out, rc = -EPROTO);
1191 memcpy(osfs, msfs, sizeof(*msfs));
1194 ptlrpc_req_finished(req);
1199 static int mdc_pin(struct obd_export *exp, const struct lu_fid *fid,
1200 struct obd_capa *oc,
1201 struct obd_client_handle *handle, int flag)
1203 struct ptlrpc_request *req;
1204 struct mdt_body *body;
1205 int rc, size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) };
1209 size[REQ_REC_OFF + 1] = sizeof(struct lustre_capa);
1210 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1211 MDS_PIN, 3, size, NULL);
1215 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof (*body));
1218 mdc_pack_capa(req, REQ_REC_OFF + 1, oc);
1220 ptlrpc_req_set_repsize(req, 2, size);
1222 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1223 rc = ptlrpc_queue_wait(req);
1224 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1226 CERROR("pin failed: %d\n", rc);
1227 ptlrpc_req_finished(req);
1231 body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body),
1232 lustre_swab_mdt_body);
1234 ptlrpc_req_finished(req);
1238 memcpy(&handle->och_fh, &body->handle, sizeof(body->handle));
1239 handle->och_magic = OBD_CLIENT_HANDLE_MAGIC;
1241 OBD_ALLOC(handle->och_mod, sizeof(*handle->och_mod));
1242 if (handle->och_mod == NULL) {
1243 DEBUG_REQ(D_ERROR, req, "can't allocate mdc_open_data");
1246 handle->och_mod->mod_open_req = req; /* will be dropped by unpin */
1251 static int mdc_unpin(struct obd_export *exp,
1252 struct obd_client_handle *handle, int flag)
1254 struct ptlrpc_request *req;
1255 struct mdt_body *body;
1256 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
1259 if (handle->och_magic != OBD_CLIENT_HANDLE_MAGIC)
1262 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1263 MDS_CLOSE, 2, size, NULL);
1267 body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));
1268 memcpy(&body->handle, &handle->och_fh, sizeof(body->handle));
1271 ptlrpc_req_set_repsize(req, 1, NULL);
1272 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1273 rc = ptlrpc_queue_wait(req);
1274 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1277 CERROR("unpin failed: %d\n", rc);
1279 ptlrpc_req_finished(req);
1280 ptlrpc_req_finished(handle->och_mod->mod_open_req);
1281 OBD_FREE(handle->och_mod, sizeof(*handle->och_mod));
1285 int mdc_sync(struct obd_export *exp, const struct lu_fid *fid,
1286 struct obd_capa *oc,
1287 struct ptlrpc_request **request)
1289 struct ptlrpc_request *req;
1290 int size[3] = { sizeof(struct ptlrpc_body), sizeof(struct mdt_body) };
1295 size[REQ_REC_OFF + 1] = sizeof(struct lustre_capa);
1296 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1297 MDS_SYNC, 3, size, NULL);
1299 RETURN(rc = -ENOMEM);
1301 mdc_pack_req_body(req, REQ_REC_OFF, 0, fid, oc, 0, 0);
1303 ptlrpc_req_set_repsize(req, 2, size);
1305 rc = ptlrpc_queue_wait(req);
1306 if (rc || request == NULL)
1307 ptlrpc_req_finished(req);
1314 static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
1315 enum obd_import_event event)
1319 LASSERT(imp->imp_obd == obd);
1322 case IMP_EVENT_DISCON: {
1325 case IMP_EVENT_INACTIVE: {
1326 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_INACTIVE, NULL);
1329 case IMP_EVENT_INVALIDATE: {
1330 struct ldlm_namespace *ns = obd->obd_namespace;
1332 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
1336 case IMP_EVENT_ACTIVE: {
1337 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_ACTIVE, NULL);
1341 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_OCD, NULL);
1345 CERROR("Unknown import event %x\n", event);
1351 static int mdc_fid_init(struct obd_export *exp)
1353 struct client_obd *cli = &exp->exp_obd->u.cli;
1358 OBD_ALLOC_PTR(cli->cl_seq);
1359 if (cli->cl_seq == NULL)
1362 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
1364 GOTO(out_free_seq, rc = -ENOMEM);
1366 snprintf(prefix, MAX_OBD_NAME + 5, "srv-%s",
1367 exp->exp_obd->obd_name);
1369 /* init client side sequence-manager */
1370 rc = seq_client_init(cli->cl_seq, exp,
1371 LUSTRE_SEQ_METADATA,
1373 OBD_FREE(prefix, MAX_OBD_NAME + 5);
1375 GOTO(out_free_seq, rc);
1377 /* pre-allocate meta-sequence */
1378 rc = seq_client_alloc_meta(cli->cl_seq, NULL);
1380 CERROR("can't allocate new mata-sequence, "
1382 GOTO(out_free_seq, rc);
1387 OBD_FREE_PTR(cli->cl_seq);
1392 static int mdc_fid_fini(struct obd_export *exp)
1394 struct client_obd *cli = &exp->exp_obd->u.cli;
1397 if (cli->cl_seq != NULL) {
1398 seq_client_fini(cli->cl_seq);
1399 OBD_FREE_PTR(cli->cl_seq);
1406 static int mdc_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
1407 struct lu_placement_hint *hint)
1409 struct client_obd *cli = &exp->exp_obd->u.cli;
1410 struct lu_client_seq *seq = cli->cl_seq;
1413 RETURN(seq_client_alloc_fid(seq, fid));
1416 static int mdc_setup(struct obd_device *obd, struct lustre_cfg *cfg)
1418 struct client_obd *cli = &obd->u.cli;
1419 struct lprocfs_static_vars lvars;
1423 OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1424 if (!cli->cl_rpc_lock)
1426 mdc_init_rpc_lock(cli->cl_rpc_lock);
1430 OBD_ALLOC(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1431 if (!cli->cl_setattr_lock)
1432 GOTO(err_rpc_lock, rc = -ENOMEM);
1433 mdc_init_rpc_lock(cli->cl_setattr_lock);
1435 OBD_ALLOC(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1436 if (!cli->cl_close_lock)
1437 GOTO(err_setattr_lock, rc = -ENOMEM);
1438 mdc_init_rpc_lock(cli->cl_close_lock);
1440 rc = client_obd_setup(obd, cfg);
1442 GOTO(err_close_lock, rc);
1443 lprocfs_init_vars(mdc, &lvars);
1444 lprocfs_obd_setup(obd, lvars.obd_vars);
1446 rc = obd_llog_init(obd, NULL, obd, 0, NULL, NULL);
1449 CERROR("failed to setup llogging subsystems\n");
1455 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1457 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1459 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1464 /* Initialize the default and maximum LOV EA and cookie sizes. This allows
1465 * us to make MDS RPCs with large enough reply buffers to hold the
1466 * maximum-sized (= maximum striped) EA and cookie without having to
1467 * calculate this (via a call into the LOV + OSCs) each time we make an RPC. */
1468 int mdc_init_ea_size(struct obd_export *exp, int easize,
1469 int def_easize, int cookiesize)
1471 struct obd_device *obd = exp->exp_obd;
1472 struct client_obd *cli = &obd->u.cli;
1475 if (cli->cl_max_mds_easize < easize)
1476 cli->cl_max_mds_easize = easize;
1478 if (cli->cl_default_mds_easize < def_easize)
1479 cli->cl_default_mds_easize = def_easize;
1481 if (cli->cl_max_mds_cookiesize < cookiesize)
1482 cli->cl_max_mds_cookiesize = cookiesize;
1487 static int mdc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
1493 case OBD_CLEANUP_EARLY:
1494 case OBD_CLEANUP_EXPORTS:
1496 case OBD_CLEANUP_SELF_EXP:
1497 rc = obd_llog_finish(obd, 0);
1499 CERROR("failed to cleanup llogging subsystems\n");
1500 case OBD_CLEANUP_OBD:
1506 static int mdc_cleanup(struct obd_device *obd)
1508 struct client_obd *cli = &obd->u.cli;
1510 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1511 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1512 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1514 lprocfs_obd_cleanup(obd);
1517 return client_obd_cleanup(obd);
1521 static int mdc_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
1522 struct obd_device *tgt,
1523 int count, struct llog_catid *logid,
1524 struct obd_uuid *uuid)
1526 struct llog_ctxt *ctxt;
1530 rc = llog_setup(obd, llogs, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
1533 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
1534 ctxt->loc_imp = obd->u.cli.cl_import;
1537 rc = llog_setup(obd, llogs, LLOG_LOVEA_REPL_CTXT, tgt, 0, NULL,
1540 ctxt = llog_get_context(obd, LLOG_LOVEA_REPL_CTXT);
1541 ctxt->loc_imp = obd->u.cli.cl_import;
1547 static int mdc_llog_finish(struct obd_device *obd, int count)
1552 rc = llog_cleanup(llog_get_context(obd, LLOG_LOVEA_REPL_CTXT));
1554 CERROR("can not cleanup LLOG_CONFIG_REPL_CTXT rc %d\n", rc);
1556 rc = llog_cleanup(llog_get_context(obd, LLOG_CONFIG_REPL_CTXT));
1560 static int mdc_process_config(struct obd_device *obd, obd_count len, void *buf)
1562 struct lustre_cfg *lcfg = buf;
1563 struct lprocfs_static_vars lvars;
1566 lprocfs_init_vars(mdc, &lvars);
1568 rc = class_process_proc_param(PARAM_MDC, lvars.obd_vars, lcfg, obd);
1572 /* get remote permission for current user on fid */
1573 int mdc_get_remote_perm(struct obd_export *exp, const struct lu_fid *fid,
1574 struct obd_capa *oc, struct ptlrpc_request **request)
1576 struct ptlrpc_request *req;
1577 struct mdt_body *body;
1578 struct mdt_remote_perm *perm;
1579 int size[5] = { sizeof(struct ptlrpc_body), sizeof(*body) };
1584 size[REQ_REC_OFF + 1] = sizeof(struct lustre_capa);
1587 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1588 MDS_GETATTR, 3, size, NULL);
1592 mdc_pack_req_body(req, REQ_REC_OFF, OBD_MD_FLRMTPERM, fid, oc, 0, 0);
1594 size[REPLY_REC_OFF + 1] = sizeof(*perm);
1595 ptlrpc_req_set_repsize(req, 5, size);
1596 rc = ptlrpc_queue_wait(req);
1598 ptlrpc_req_finished(req);
1602 body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body),
1603 lustre_swab_mdt_body);
1605 LASSERT(body->valid & OBD_MD_FLRMTPERM);
1607 perm = lustre_swab_repbuf(req, REPLY_REC_OFF + 1, sizeof(*perm),
1608 lustre_swab_mdt_remote_perm);
1615 static int mdc_renew_capa(struct obd_export *exp, struct obd_capa *oc,
1618 struct ptlrpc_request *req;
1619 int size[2] = { sizeof(struct ptlrpc_body),
1620 sizeof(struct lustre_capa) };
1621 int repsize[3] = { sizeof(struct ptlrpc_body),
1622 sizeof(struct mdt_body),
1623 sizeof(struct lustre_capa) };
1626 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1627 MDS_RENEW_CAPA, 2, size, NULL);
1631 mdc_pack_capa(req, REQ_REC_OFF, oc);
1633 ptlrpc_req_set_repsize(req, 3, repsize);
1634 req->rq_interpret_reply = cb;
1635 ptlrpcd_add_req(req);
1640 struct obd_ops mdc_obd_ops = {
1641 .o_owner = THIS_MODULE,
1642 .o_setup = mdc_setup,
1643 .o_precleanup = mdc_precleanup,
1644 .o_cleanup = mdc_cleanup,
1645 .o_add_conn = client_import_add_conn,
1646 .o_del_conn = client_import_del_conn,
1647 .o_connect = client_connect_import,
1648 .o_disconnect = client_disconnect_export,
1649 .o_iocontrol = mdc_iocontrol,
1650 .o_set_info_async = mdc_set_info_async,
1651 .o_statfs = mdc_statfs,
1653 .o_unpin = mdc_unpin,
1654 .o_fid_init = mdc_fid_init,
1655 .o_fid_fini = mdc_fid_fini,
1656 .o_fid_alloc = mdc_fid_alloc,
1657 .o_import_event = mdc_import_event,
1658 .o_llog_init = mdc_llog_init,
1659 .o_llog_finish = mdc_llog_finish,
1660 .o_get_info = mdc_get_info,
1661 .o_process_config = mdc_process_config,
1664 struct md_ops mdc_md_ops = {
1665 .m_getstatus = mdc_getstatus,
1666 .m_change_cbdata = mdc_change_cbdata,
1667 .m_close = mdc_close,
1668 .m_create = mdc_create,
1669 .m_done_writing = mdc_done_writing,
1670 .m_enqueue = mdc_enqueue,
1671 .m_getattr = mdc_getattr,
1672 .m_getattr_name = mdc_getattr_name,
1673 .m_intent_lock = mdc_intent_lock,
1675 .m_is_subdir = mdc_is_subdir,
1676 .m_rename = mdc_rename,
1677 .m_setattr = mdc_setattr,
1678 .m_setxattr = mdc_setxattr,
1679 .m_getxattr = mdc_getxattr,
1681 .m_readpage = mdc_readpage,
1682 .m_unlink = mdc_unlink,
1683 .m_cancel_unused = mdc_cancel_unused,
1684 .m_init_ea_size = mdc_init_ea_size,
1685 .m_set_lock_data = mdc_set_lock_data,
1686 .m_lock_match = mdc_lock_match,
1687 .m_get_lustre_md = mdc_get_lustre_md,
1688 .m_free_lustre_md = mdc_free_lustre_md,
1689 .m_set_open_replay_data = mdc_set_open_replay_data,
1690 .m_clear_open_replay_data = mdc_clear_open_replay_data,
1691 .m_get_remote_perm = mdc_get_remote_perm,
1692 .m_renew_capa = mdc_renew_capa
1695 extern quota_interface_t mdc_quota_interface;
1697 int __init mdc_init(void)
1700 struct lprocfs_static_vars lvars;
1701 lprocfs_init_vars(mdc, &lvars);
1703 request_module("lquota");
1704 quota_interface = PORTAL_SYMBOL_GET(mdc_quota_interface);
1705 init_obd_quota_ops(quota_interface, &mdc_obd_ops);
1707 rc = class_register_type(&mdc_obd_ops, &mdc_md_ops, lvars.module_vars,
1708 LUSTRE_MDC_NAME, NULL);
1709 if (rc && quota_interface)
1710 PORTAL_SYMBOL_PUT(mdc_quota_interface);
1716 static void /*__exit*/ mdc_exit(void)
1718 if (quota_interface)
1719 PORTAL_SYMBOL_PUT(mdc_quota_interface);
1721 class_unregister_type(LUSTRE_MDC_NAME);
1724 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1725 MODULE_DESCRIPTION("Lustre Metadata Client");
1726 MODULE_LICENSE("GPL");
1728 module_init(mdc_init);
1729 module_exit(mdc_exit);