1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2004 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.sf.net/projects/lustre/
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 # define EXPORT_SYMTAB
25 #define DEBUG_SUBSYSTEM S_MDC
28 # include <linux/module.h>
29 # include <linux/pagemap.h>
30 # include <linux/miscdevice.h>
31 # include <linux/init.h>
33 # include <liblustre.h>
36 #include <linux/obd_class.h>
37 #include <linux/lustre_mds.h>
38 #include <linux/lustre_dlm.h>
39 #include <linux/lustre_sec.h>
40 #include <linux/lprocfs_status.h>
41 #include <linux/lustre_acl.h>
42 #include <linux/lustre_lite.h>
43 #include <linux/lustre_gs.h>
44 #include "mdc_internal.h"
46 #define REQUEST_MINOR 244
48 static int mdc_cleanup(struct obd_device *obd, int flags);
50 extern int mds_queue_req(struct ptlrpc_request *);
51 /* Helper that implements most of mdc_getstatus and signal_completed_replay. */
52 /* XXX this should become mdc_get_info("key"), sending MDS_GET_INFO RPC */
53 static int send_getstatus(struct obd_import *imp, struct lustre_id *rootid,
54 int level, int msg_flags)
56 struct ptlrpc_request *req;
57 struct mds_body *body;
58 int rc, size[2] = {0, sizeof(*body)};
61 //size[0] = lustre_secdesc_size();
63 req = ptlrpc_prep_req(imp, LUSTRE_MDS_VERSION, MDS_GETSTATUS,
66 GOTO(out, rc = -ENOMEM);
68 //lustre_pack_secdesc(req, size[0]);
70 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof (*body));
71 req->rq_send_state = level;
72 req->rq_replen = lustre_msg_size(1, &size[1]);
74 req->rq_reqmsg->flags |= msg_flags;
75 rc = ptlrpc_queue_wait(req);
78 body = lustre_swab_repbuf (req, 0, sizeof (*body),
79 lustre_swab_mds_body);
81 CERROR ("Can't extract mds_body\n");
82 GOTO (out, rc = -EPROTO);
85 memcpy(rootid, &body->id1, sizeof(*rootid));
87 CDEBUG(D_NET, "root ino="LPU64", last_committed="LPU64
88 ", last_xid="LPU64"\n", rootid->li_stc.u.e3s.l3s_ino,
89 req->rq_repmsg->last_committed, req->rq_repmsg->last_xid);
94 ptlrpc_req_finished(req);
98 /* This should be mdc_get_info("rootid") */
99 int mdc_getstatus(struct obd_export *exp, struct lustre_id *rootid)
101 return send_getstatus(class_exp2cliimp(exp), rootid,
106 mdc_interpret_getattr(struct ptlrpc_request *req, void *unused, int rc)
108 struct mds_body *body = NULL;
109 struct obd_capa *ocapa;
110 struct lustre_capa *capa = NULL;
111 unsigned long expiry;
115 DEBUG_REQ(D_WARNING, req,
116 "async getattr failed: rc = %d", rc);
120 body = lustre_swab_repbuf(req, 0, sizeof (*body), lustre_swab_mds_body);
122 CERROR ("Can't unpack mds_body\n");
126 if (!(body->valid & OBD_MD_CAPA)) {
127 CDEBUG(D_INFO, "MDS has disabled capability\n");
131 capa = lustre_swab_repbuf(req, 1, sizeof(*capa),
132 lustre_swab_lustre_capa);
133 if (capa == NULL && rc != 0) {
134 CERROR ("Can't unpack lustre_capa\n");
138 ocapa = capa_renew(capa, CLIENT_CAPA);
142 spin_lock(&capa_lock);
143 expiry = expiry_to_jiffies(capa->lc_expiry - capa_pre_expiry(capa));
144 if (time_before(expiry, ll_capa_timer.expires) ||
145 !timer_pending(&ll_capa_timer)) {
146 mod_timer(&ll_capa_timer, expiry);
147 CDEBUG(D_INFO, "ll_capa_timer new timer: %lu\n", expiry);
149 spin_unlock(&capa_lock);
154 int mdc_getattr_async(struct obd_export *exp, struct ptlrpc_request *req)
156 int repsize[2] = {sizeof(struct mds_body), sizeof(struct lustre_capa)};
159 req->rq_replen = lustre_msg_size(2, repsize);
160 req->rq_interpret_reply = mdc_interpret_getattr;
161 ptlrpcd_add_req(req);
166 int mdc_getattr_common(struct obd_export *exp, unsigned int ea_size,
167 struct ptlrpc_request *req)
169 struct mds_body *body, *reqbody;
172 int repsize[2] = {sizeof(*body)};
176 /* request message already built */
179 repsize[bufcount++] = ea_size;
180 CDEBUG(D_INODE, "reserved %u bytes for MD/symlink in packet\n",
184 reqbody = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*reqbody));
185 LASSERT(!(reqbody->valid & OBD_MD_FLACL));
187 if (reqbody->valid & OBD_MD_FLKEY) {
188 repsize[bufcount++] = 5;
189 repsize[bufcount++] = sizeof(struct lustre_key);
190 } else if (reqbody->valid & OBD_MD_CAPA) {
191 LASSERT(ea_size == 0);
192 repsize[bufcount++] = sizeof(struct lustre_capa);
195 req->rq_replen = lustre_msg_size(bufcount, repsize);
197 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
198 rc = ptlrpc_queue_wait(req);
199 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
203 body = lustre_swab_repbuf (req, 0, sizeof (*body),
204 lustre_swab_mds_body);
206 CERROR ("Can't unpack mds_body\n");
210 CDEBUG(D_NET, "mode: %o\n", body->mode);
212 LASSERT_REPSWAB (req, 1);
214 /* Skip the check if getxattr/listxattr are called with no buffers */
215 if ((reqbody->eadatasize != 0) &&
216 !(reqbody->valid & (OBD_MD_FLXATTR | OBD_MD_FLXATTRLIST))) {
217 /* reply indicates presence of eadata; check it's there... */
218 eadata = lustre_msg_buf (req->rq_repmsg, 1,
220 if (eadata == NULL) {
221 CERROR ("Missing/short eadata\n");
229 static int mdc_cancel_unused(struct obd_export *exp,
230 struct lov_stripe_md *lsm,
231 int flags, void *opaque)
233 struct obd_device *obd = class_exp2obd(exp);
236 RETURN(ldlm_cli_cancel_unused(obd->obd_namespace,
237 NULL, flags, opaque));
240 int mdc_getattr(struct obd_export *exp, struct lustre_id *id,
241 __u64 valid, const char *xattr_name,
242 const void *xattr_data, unsigned int xattr_datalen,
243 unsigned int ea_size, struct obd_capa *ocapa,
244 struct ptlrpc_request **request)
246 struct ptlrpc_request *req;
247 struct mds_body *body;
248 int xattr_namelen = xattr_name ? strlen(xattr_name) + 1 : 0;
249 int size[4] = {0, sizeof(*body)};
254 size[0] = lustre_secdesc_size();
256 if (valid & OBD_MD_FLXATTR) {
257 size[bufcount++] = xattr_namelen;
259 if (xattr_datalen > 0) {
261 size[bufcount++] = xattr_datalen;
263 } else if (valid & OBD_MD_CAPA) {
264 LASSERT(valid == OBD_MD_CAPA);
266 size[bufcount++] = sizeof(*ocapa);
268 LASSERT(!xattr_data && !xattr_datalen);
271 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
272 MDS_GETATTR, bufcount, size, NULL);
274 GOTO(out, rc = -ENOMEM);
276 lustre_pack_secdesc(req, size[0]);
278 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof (*body));
279 memcpy(&body->id1, id, sizeof(*id));
281 body->eadatasize = ea_size;
283 if (valid & OBD_MD_FLXATTR) {
284 memcpy(lustre_msg_buf(req->rq_reqmsg, 2, xattr_namelen),
285 xattr_name, xattr_namelen);
287 memcpy(lustre_msg_buf(req->rq_reqmsg, 3, xattr_datalen),
288 xattr_data, xattr_datalen);
291 if (valid & OBD_MD_CAPA) {
292 /* renew capability */
293 memcpy(&body->handle, &ocapa->c_handle, sizeof(body->handle));
294 memcpy(lustre_msg_buf(req->rq_reqmsg, 2, sizeof(ocapa->c_capa)),
295 &ocapa->c_capa, sizeof(ocapa->c_capa));
297 rc = mdc_getattr_async(exp, req);
298 req = NULL; /* ptlrpcd will finish request */
300 rc = mdc_getattr_common(exp, ea_size, req);
302 ptlrpc_req_finished (req);
311 int mdc_access_check(struct obd_export *exp, struct lustre_id *id,
312 struct ptlrpc_request **request)
315 struct ptlrpc_request *req;
316 struct mds_body *body;
317 int size[2] = {0, sizeof(*body)};
321 size[0] = lustre_secdesc_size();
322 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
323 MDS_ACCESS_CHECK, 2, size, NULL);
325 GOTO(out, rc = -ENOMEM);
327 lustre_pack_secdesc(req, size[0]);
328 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof (*body));
329 memcpy(&body->id1, id, sizeof(*id));
331 size[0] = sizeof(*body);
332 size[1] = sizeof(struct mds_remote_perm);
333 req->rq_replen = lustre_msg_size(2, size);
335 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
336 rc = ptlrpc_queue_wait(req);
337 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
339 ptlrpc_req_finished (req);
342 body = lustre_swab_repbuf (req, 0, sizeof (*body),
343 lustre_swab_mds_body);
345 CERROR ("Can't unpack mds_body\n");
355 int mdc_getattr_lock(struct obd_export *exp, struct lustre_id *id,
356 char *filename, int namelen, __u64 valid,
357 unsigned int ea_size, struct ptlrpc_request **request)
359 struct ptlrpc_request *req;
360 struct mds_body *body;
361 int rc, size[3] = {0, sizeof(*body), namelen};
364 size[0] = lustre_secdesc_size();
366 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
367 MDS_GETATTR_LOCK, 3, size, NULL);
369 GOTO(out, rc = -ENOMEM);
371 lustre_pack_secdesc(req, size[0]);
373 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof (*body));
374 memcpy(&body->id1, id, sizeof(*id));
376 body->eadatasize = ea_size;
378 if (filename != NULL) {
379 LASSERT (strnlen (filename, namelen) == namelen - 1);
380 memcpy(lustre_msg_buf(req->rq_reqmsg, 2, namelen),
383 LASSERT(namelen == 1);
386 rc = mdc_getattr_common(exp, ea_size, req);
388 ptlrpc_req_finished (req);
396 /* This should be called with both the request and the reply still packed. */
397 int mdc_store_inode_generation(struct obd_export *exp,
398 struct ptlrpc_request *req,
399 int reqoff, int repoff)
401 struct mds_rec_create *rec =
402 lustre_msg_buf(req->rq_reqmsg, reqoff, sizeof(*rec));
403 struct mds_body *body =
404 lustre_msg_buf(req->rq_repmsg, repoff, sizeof(*body));
406 LASSERT (rec != NULL);
407 LASSERT (body != NULL);
409 memcpy(&rec->cr_replayid, &body->id1, sizeof(rec->cr_replayid));
410 DEBUG_REQ(D_HA, req, "storing generation for ino "DLID4,
411 OLID4(&rec->cr_replayid));
416 int mdc_unpack_acl(struct obd_export *exp_lmv, struct ptlrpc_request *req,
417 unsigned int offset, struct lustre_md *md)
419 struct posix_acl *acl;
420 struct mds_remote_perm *perm;
425 if (!(md->body->valid & OBD_MD_FLACL))
428 if (md->body->valid & OBD_MD_FLRMTACL) {
429 offset++; /* first 'size' is not used */
431 buf = lustre_swab_repbuf(req, offset, sizeof(*perm),
432 lustre_swab_remote_perm);
434 CERROR("Can't unpack remote perm\n");
438 OBD_ALLOC(perm, sizeof(*perm));
441 memcpy(perm, buf, sizeof(*perm));
442 md->remote_perm = perm;
444 size = le32_to_cpu(*(__u32 *) lustre_msg_buf(
445 req->rq_repmsg, offset, 4));
446 buf = lustre_msg_buf(req->rq_repmsg, offset + 1, size);
448 acl = posix_acl_from_xattr(buf, size);
451 CERROR("convert xattr to acl failed: %d\n", rc);
454 rc = posix_acl_valid(acl);
456 CERROR("acl valid error: %d\n", rc);
457 posix_acl_release(acl);
468 static int mdc_unpack_gskey(struct obd_export *exp_lmv, struct ptlrpc_request *req,
469 unsigned int *offset, struct lustre_md *md)
471 int key_off = 0, rc = 0, size = 0;
475 if (md->body->valid & OBD_MD_FLKEY) {
476 size = le32_to_cpu(*(__u32 *) lustre_msg_buf(req->rq_repmsg,
478 buf = lustre_msg_buf(req->rq_repmsg, key_off++, size);
480 CDEBUG(D_INFO, "buf %p key_off %d size %d \n",
482 md->key = (struct lustre_key *)buf;
490 int mdc_req2lustre_md(struct obd_export *exp_lmv, struct ptlrpc_request *req,
491 unsigned int offset, struct obd_export *exp_lov,
492 struct lustre_md *md)
494 struct lov_mds_md *lmm;
495 int rc = 0, reply_off;
499 memset(md, 0, sizeof(*md));
501 md->body = lustre_msg_buf(req->rq_repmsg, offset,
506 LASSERT_REPSWABBED(req, offset);
508 if (!(md->body->valid & OBD_MD_FLEASIZE) &&
509 !(md->body->valid & OBD_MD_FLDIREA))
512 if (S_ISREG(md->body->mode)) {
513 if (md->body->eadatasize == 0) {
514 CERROR("invalid EA size (0) is detected\n");
518 lmm = lustre_msg_buf(req->rq_repmsg, offset + 1,
519 md->body->eadatasize);
523 LASSERT(exp_lov != NULL);
525 rc = obd_unpackmd(exp_lov, &md->lsm, lmm,
526 md->body->eadatasize);
528 LASSERT(rc >= sizeof(*md->lsm));
531 } else if (S_ISDIR(md->body->mode)) {
532 /* dir can be non-splitted */
533 if (md->body->eadatasize == 0)
536 lmm = lustre_msg_buf(req->rq_repmsg, offset + 1,
537 md->body->eadatasize);
541 if (md->body->valid & OBD_MD_MEA) {
542 LASSERT(exp_lmv != NULL);
544 rc = obd_unpackmd(exp_lmv, (void *)&md->mea,
545 lmm, md->body->eadatasize);
547 LASSERT(rc >= sizeof(*md->mea));
552 LASSERT(S_ISCHR(md->body->mode) ||
553 S_ISBLK(md->body->mode) ||
554 S_ISFIFO(md->body->mode)||
555 S_ISLNK(md->body->mode) ||
556 S_ISSOCK(md->body->mode));
559 /* if anything wrong when unpacking md, we don't check acl
560 * stuff, for simplicity
565 reply_off = (md->body->valid & OBD_MD_FLEASIZE) ?
566 (offset + 2) : (offset + 1);
567 rc = mdc_unpack_acl(exp_lmv, req, reply_off, md);
569 CERROR("upack acl error %d \n", rc);
574 rc = mdc_unpack_gskey(exp_lmv, req, &reply_off, md);
581 static void mdc_commit_open(struct ptlrpc_request *req)
583 struct mdc_open_data *mod = req->rq_cb_data;
587 if (mod->mod_close_req != NULL)
588 mod->mod_close_req->rq_cb_data = NULL;
590 if (mod->mod_och != NULL)
591 mod->mod_och->och_mod = NULL;
593 OBD_FREE(mod, sizeof(*mod));
594 req->rq_cb_data = NULL;
595 LASSERT(atomic_read(&req->rq_refcount) > 1);
596 ptlrpc_req_finished(req);
599 static void mdc_replay_open(struct ptlrpc_request *req)
601 struct mdc_open_data *mod = req->rq_cb_data;
602 struct obd_client_handle *och;
603 struct ptlrpc_request *close_req;
604 struct lustre_handle old;
605 struct mds_body *body;
608 body = lustre_swab_repbuf(req, 1, sizeof(*body), lustre_swab_mds_body);
609 LASSERT (body != NULL);
612 DEBUG_REQ(D_ERROR, req,
613 "can't properly replay without open data");
620 struct lustre_handle *file_fh;
621 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
622 file_fh = &och->och_fh;
623 CDEBUG(D_HA, "updating handle from "LPX64" to "LPX64"\n",
624 file_fh->cookie, body->handle.cookie);
625 memcpy(&old, file_fh, sizeof(old));
626 memcpy(file_fh, &body->handle, sizeof(*file_fh));
629 close_req = mod->mod_close_req;
630 if (close_req != NULL) {
631 struct mds_body *close_body;
632 LASSERT(close_req->rq_reqmsg->opc == MDS_CLOSE);
633 close_body = lustre_msg_buf(close_req->rq_reqmsg,
635 sizeof(*close_body));
637 LASSERT(!memcmp(&old, &close_body->handle, sizeof old));
638 DEBUG_REQ(D_HA, close_req, "updating close body with new fh");
639 memcpy(&close_body->handle, &body->handle,
640 sizeof(close_body->handle));
646 int mdc_set_open_replay_data(struct obd_export *exp,
647 struct obd_client_handle *och,
648 struct ptlrpc_request *open_req)
650 struct mdc_open_data *mod;
651 struct mds_rec_create *rec;
652 struct mds_body *body;
654 rec = lustre_msg_buf(open_req->rq_reqmsg, MDS_REQ_INTENT_REC_OFF,
656 body = lustre_msg_buf(open_req->rq_repmsg, 1, sizeof(*body));
658 LASSERT(rec != NULL);
659 /* outgoing messages always in my byte order */
660 LASSERT(body != NULL);
661 /* incoming message in my byte order (it's been swabbed) */
662 LASSERT_REPSWABBED(open_req, 1);
664 OBD_ALLOC(mod, sizeof(*mod));
666 DEBUG_REQ(D_ERROR, open_req, "can't allocate mdc_open_data");
672 mod->mod_open_req = ptlrpc_request_addref(open_req);
674 memcpy(&rec->cr_replayid, &body->id1, sizeof rec->cr_replayid);
675 memcpy(&rec->cr_ioepoch, &body->io_epoch, sizeof rec->cr_ioepoch);
676 open_req->rq_replay_cb = mdc_replay_open;
677 open_req->rq_commit_cb = mdc_commit_open;
678 open_req->rq_cb_data = mod;
679 DEBUG_REQ(D_HA, open_req, "set up replay data");
683 int mdc_clear_open_replay_data(struct obd_export *exp,
684 struct obd_client_handle *och)
686 struct mdc_open_data *mod = och->och_mod;
688 /* Don't free the structure now (it happens in mdc_commit_open, after
689 * we're sure we won't need to fix up the close request in the future),
690 * but make sure that replay doesn't poke at the och, which is about to
692 LASSERT(mod != LP_POISON);
699 static void mdc_commit_close(struct ptlrpc_request *req)
701 struct mdc_open_data *mod = req->rq_cb_data;
702 struct obd_import *imp = req->rq_import;
703 struct ptlrpc_request *open_req;
705 DEBUG_REQ(D_HA, req, "close req committed");
709 mod->mod_close_req = NULL;
710 req->rq_cb_data = NULL;
711 req->rq_commit_cb = NULL;
713 open_req = mod->mod_open_req;
714 LASSERT(open_req != NULL);
715 LASSERT(open_req != LP_POISON);
716 LASSERT(open_req->rq_type != LI_POISON);
718 DEBUG_REQ(D_HA, open_req, "open req balanced");
719 if (open_req->rq_transno == 0) {
720 DEBUG_REQ(D_ERROR, open_req, "BUG 3892 open");
721 DEBUG_REQ(D_ERROR, req, "BUG 3892 close");
722 LASSERTF(open_req->rq_transno != 0, "BUG 3892\n");
724 LASSERT(open_req->rq_import == imp);
726 /* We no longer want to preserve this for transno-unconditional
728 spin_lock(&open_req->rq_lock);
729 open_req->rq_replay = 0;
730 spin_unlock(&open_req->rq_lock);
733 int mdc_close(struct obd_export *exp, struct mdc_op_data *op_data,
734 struct obd_client_handle *och, struct ptlrpc_request **request)
736 struct obd_device *obd = class_exp2obd(exp);
737 struct obd_import *imp = class_exp2cliimp(exp);
738 int reqsize[3] = {0, sizeof(struct mds_body),
739 obd->u.cli.cl_max_mds_cookiesize};
740 int rc, repsize[3] = {sizeof(struct mds_body),
741 obd->u.cli.cl_max_mds_easize,
742 obd->u.cli.cl_max_mds_cookiesize};
743 struct ptlrpc_request *req;
744 struct mdc_open_data *mod;
747 if (imp->imp_connection == NULL) {
748 CERROR("request on not connected import %s\n",
749 imp->imp_obd->obd_name);
753 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
754 MDS_CLOSE, 3, reqsize, NULL);
756 GOTO(out, rc = -ENOMEM);
757 req->rq_request_portal = MDS_CLOSE_PORTAL;
759 /* ensure that this close's handle is fixed up during replay. */
760 LASSERT(och != NULL);
762 if (likely(mod != NULL)) {
763 mod->mod_close_req = req;
764 LASSERT(mod->mod_open_req->rq_type != LI_POISON);
765 DEBUG_REQ(D_HA, mod->mod_open_req, "matched open");
767 CDEBUG(D_HA, "couldn't find open req; "
768 "expecting close error\n");
771 mdc_close_pack(req, 1, op_data, och);
773 req->rq_replen = lustre_msg_size(3, repsize);
774 req->rq_commit_cb = mdc_commit_close;
775 LASSERT(req->rq_cb_data == NULL);
776 req->rq_cb_data = mod;
778 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
779 rc = ptlrpc_queue_wait(req);
780 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
782 if (req->rq_repmsg == NULL) {
783 CDEBUG(D_HA, "request failed to send: %p, %d\n", req,
786 rc = req->rq_status ? req->rq_status : -EIO;
787 } else if (rc == 0) {
788 rc = req->rq_repmsg->status;
789 if (req->rq_repmsg->type == PTL_RPC_MSG_ERR) {
790 DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, "
796 CERROR("Unexpected: can't find mdc_open_data, but "
797 "close succeeded. Please tell CFS.\n");
798 if (!lustre_swab_repbuf(req, 0, sizeof(struct mds_body),
799 lustre_swab_mds_body))
801 CERROR("Error unpacking mds_body\n");
813 int mdc_done_writing(struct obd_export *exp, struct obdo *obdo)
815 struct ptlrpc_request *req;
816 struct mds_body *body;
817 int rc, size[2] = {0, sizeof(*body)};
820 size[0] = lustre_secdesc_size();
822 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
823 MDS_DONE_WRITING, 2, size, NULL);
827 lustre_pack_secdesc(req, size[0]);
829 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF,
832 mdc_pack_id(&body->id1, obdo->o_id, 0, obdo->o_mode,
833 obdo->o_mds, obdo->o_fid);
835 body->size = obdo->o_size;
836 body->blocks = obdo->o_blocks;
837 body->flags = obdo->o_flags;
838 body->valid = obdo->o_valid;
840 req->rq_replen = lustre_msg_size(1, &size[1]);
842 rc = ptlrpc_queue_wait(req);
843 ptlrpc_req_finished(req);
847 int mdc_readpage(struct obd_export *exp,
848 struct lustre_id *id,
849 __u64 offset, struct page *page,
850 struct ptlrpc_request **request)
852 struct obd_import *imp = class_exp2cliimp(exp);
853 struct ptlrpc_request *req = NULL;
854 struct ptlrpc_bulk_desc *desc = NULL;
855 struct mds_body *body;
856 int rc, size[2] = {0, sizeof(*body)};
859 CDEBUG(D_INODE, "inode: %ld\n", (long)id->li_stc.u.e3s.l3s_ino);
861 size[0] = lustre_secdesc_size();
863 req = ptlrpc_prep_req(imp, LUSTRE_MDS_VERSION, MDS_READPAGE,
866 GOTO(out, rc = -ENOMEM);
867 /* XXX FIXME bug 249 */
868 req->rq_request_portal = MDS_READPAGE_PORTAL;
870 lustre_pack_secdesc(req, size[0]);
872 desc = ptlrpc_prep_bulk_imp(req, 1, BULK_PUT_SINK, MDS_BULK_PORTAL);
874 GOTO(out, rc = -ENOMEM);
875 /* NB req now owns desc and will free it when it gets freed */
877 ptlrpc_prep_bulk_page(desc, page, 0, PAGE_CACHE_SIZE);
878 mdc_readdir_pack(req, 1, offset, PAGE_CACHE_SIZE, id);
880 req->rq_replen = lustre_msg_size(1, &size[1]);
881 rc = ptlrpc_queue_wait(req);
884 body = lustre_swab_repbuf(req, 0, sizeof (*body),
885 lustre_swab_mds_body);
887 CERROR("Can't unpack mds_body\n");
888 GOTO(out, rc = -EPROTO);
891 if (req->rq_bulk->bd_nob_transferred != PAGE_CACHE_SIZE) {
892 CERROR ("Unexpected # bytes transferred: %d"
894 req->rq_bulk->bd_nob_transferred,
896 GOTO (out, rc = -EPROTO);
906 static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
907 void *karg, void *uarg)
909 struct obd_device *obd = exp->exp_obd;
910 struct obd_ioctl_data *data = karg;
911 struct obd_import *imp = obd->u.cli.cl_import;
912 struct llog_ctxt *ctxt;
916 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
919 if (!try_module_get(THIS_MODULE)) {
920 CERROR("Can't get module. Is it alive?");
925 case OBD_IOC_CLIENT_RECOVER:
926 rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1);
930 case IOC_OSC_SET_ACTIVE:
931 rc = ptlrpc_set_import_active(imp, data->ioc_offset);
933 case IOC_OSC_CTL_RECOVERY:
934 rc = ptlrpc_import_control_recovery(imp, data->ioc_offset);
936 case OBD_IOC_PARSE: {
937 ctxt = llog_get_context(&exp->exp_obd->obd_llogs,
938 LLOG_CONFIG_REPL_CTXT);
939 rc = class_config_process_llog(ctxt, data->ioc_inlbuf1, NULL);
943 case OBD_IOC_LLOG_INFO:
944 case OBD_IOC_LLOG_PRINT: {
945 ctxt = llog_get_context(&obd->obd_llogs, LLOG_CONFIG_REPL_CTXT);
946 rc = llog_ioctl(ctxt, cmd, data);
952 CERROR("mdc_ioctl(): unrecognised ioctl %#x\n", cmd);
953 GOTO(out, rc = -ENOTTY);
956 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
959 module_put(THIS_MODULE);
965 int mdc_set_info(struct obd_export *exp, obd_count keylen,
966 void *key, obd_count vallen, void *val)
970 if (keylen == strlen("initial_recov") &&
971 memcmp(key, "initial_recov", strlen("initial_recov")) == 0) {
972 struct obd_import *imp = exp->exp_obd->u.cli.cl_import;
973 if (vallen != sizeof(int))
975 imp->imp_initial_recov = *(int *)val;
976 CDEBUG(D_HA, "%s: set imp_no_init_recov = %d\n",
977 exp->exp_obd->obd_name,
978 imp->imp_initial_recov);
980 } else if ((keylen >= strlen("crypto_type")) &&
981 strcmp(key, "crypto_type") == 0) {
982 struct ptlrpc_request *req;
983 char *bufs[2] = {key, val};
984 int rc, size[2] = {keylen, vallen};
986 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
987 OST_SET_INFO, 2, size, bufs);
991 req->rq_replen = lustre_msg_size(0, NULL);
992 rc = ptlrpc_queue_wait(req);
993 ptlrpc_req_finished(req);
995 } else if (keylen >= strlen("inter_mds") && strcmp(key, "inter_mds") == 0) {
996 struct obd_import *imp = class_exp2cliimp(exp);
997 imp->imp_server_timeout = 1;
998 CDEBUG(D_OTHER, "%s: timeout / 2\n", exp->exp_obd->obd_name);
1000 } else if (keylen == strlen("sec") &&
1001 memcmp(key, "sec", keylen) == 0) {
1002 struct client_obd *cli = &exp->exp_obd->u.cli;
1004 cli->cl_sec_flavor = ptlrpcs_name2flavor(val);
1005 if (cli->cl_sec_flavor == PTLRPCS_FLVR_INVALID) {
1006 CERROR("unrecognized security type %s\n", (char*) val);
1011 } else if (keylen == strlen("sec_flags") &&
1012 memcmp(key, "sec_flags", keylen) == 0) {
1013 struct client_obd *cli = &exp->exp_obd->u.cli;
1015 cli->cl_sec_flags = *((unsigned long *) val);
1017 } else if (keylen == strlen("flush_cred") &&
1018 memcmp(key, "flush_cred", keylen) == 0) {
1019 struct client_obd *cli = &exp->exp_obd->u.cli;
1022 ptlrpcs_import_flush_current_creds(cli->cl_import);
1024 } else if (keylen == strlen("async") && memcmp(key, "async", keylen) == 0) {
1025 struct client_obd *cl = &exp->exp_obd->u.cli;
1026 if (vallen != sizeof(int))
1028 cl->cl_async = *(int *)val;
1029 CDEBUG(D_HA, "%s: set async = %d\n",
1030 exp->exp_obd->obd_name, cl->cl_async);
1032 } else if (keylen == strlen("setext") && memcmp(key, "setext", keylen) == 0) {
1033 struct ptlrpc_request *req;
1034 char *bufs[2] = {key, val};
1035 int rc, size[2] = {keylen, vallen};
1037 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1038 OST_SET_INFO, 2, size, bufs);
1042 req->rq_replen = lustre_msg_size(0, NULL);
1043 rc = ptlrpc_queue_wait(req);
1044 ptlrpc_req_finished(req);
1046 } else if (keylen == 5 && strcmp(key, "audit") == 0) {
1047 struct ptlrpc_request *req;
1048 char *bufs[2] = {key, val};
1049 int rc, size[2] = {keylen, vallen};
1051 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1052 OST_SET_INFO, 2, size, bufs);
1056 req->rq_replen = lustre_msg_size(0, NULL);
1057 lustre_swab_reqbuf(req, 1, sizeof(struct audit_attr_msg),
1058 lustre_swab_audit_attr);
1059 rc = ptlrpc_queue_wait(req);
1060 ptlrpc_req_finished(req);
1063 } else if (keylen == strlen("ids") && memcmp(key, "ids", keylen) == 0) {
1064 struct ptlrpc_request *req;
1065 struct lustre_id *ids = (struct lustre_id *)val;
1066 char *bufs[3] = {key, (char *)ids, (char *)(ids + 1)};
1067 int rc, size[3] = {keylen, sizeof(struct lustre_id),
1068 sizeof(struct lustre_id)};
1070 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1071 OST_SET_INFO, 3, size, bufs);
1075 req->rq_replen = lustre_msg_size(0, NULL);
1076 rc = ptlrpc_queue_wait(req);
1077 ptlrpc_req_finished(req);
1083 static int mdc_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1084 unsigned long max_age)
1086 struct obd_statfs *msfs;
1087 struct ptlrpc_request *req;
1088 int rc, size = sizeof(*msfs);
1091 /* We could possibly pass max_age in the request (as an absolute
1092 * timestamp or a "seconds.usec ago") so the target can avoid doing
1093 * extra calls into the filesystem if that isn't necessary (e.g.
1094 * during mount that would help a bit). Having relative timestamps
1095 * is not so great if request processing is slow, while absolute
1096 * timestamps are not ideal because they need time synchronization. */
1097 req = ptlrpc_prep_req(obd->u.cli.cl_import, LUSTRE_MDS_VERSION,
1098 MDS_STATFS, 0, NULL, NULL);
1102 req->rq_replen = lustre_msg_size(1, &size);
1104 mdc_get_rpc_lock(obd->u.cli.cl_rpc_lock, NULL);
1105 rc = ptlrpc_queue_wait(req);
1106 mdc_put_rpc_lock(obd->u.cli.cl_rpc_lock, NULL);
1109 /* this can be LMV fake import, whcih is not connected. */
1110 if (!req->rq_import->imp_connection)
1111 memset(osfs, 0, sizeof(*osfs));
1115 msfs = lustre_swab_repbuf(req, 0, sizeof(*msfs),
1116 lustre_swab_obd_statfs);
1118 CERROR("Can't unpack obd_statfs\n");
1119 GOTO(out, rc = -EPROTO);
1122 memcpy(osfs, msfs, sizeof (*msfs));
1125 ptlrpc_req_finished(req);
1129 static int mdc_pin(struct obd_export *exp, obd_id ino, __u32 gen, int type,
1130 struct obd_client_handle *handle, int flag)
1132 struct ptlrpc_request *req;
1133 struct mds_body *body;
1134 int rc, size[2] = {0, sizeof(*body)};
1137 //size[0] = lustre_secdesc_size();
1139 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1140 MDS_PIN, 2, size, NULL);
1144 //lustre_pack_secdesc(req, size[0]);
1146 body = lustre_msg_buf(req->rq_reqmsg,
1147 MDS_REQ_REC_OFF, sizeof(*body));
1149 /* FIXME-UMKA: here should be also mdsnum and fid. */
1150 mdc_pack_id(&body->id1, ino, gen, type, 0, 0);
1153 req->rq_replen = lustre_msg_size(1, &size[1]);
1155 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1156 rc = ptlrpc_queue_wait(req);
1157 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1159 CERROR("pin failed: %d\n", rc);
1160 ptlrpc_req_finished(req);
1164 body = lustre_swab_repbuf(req, 0, sizeof(*body), lustre_swab_mds_body);
1166 ptlrpc_req_finished(req);
1170 memcpy(&handle->och_fh, &body->handle, sizeof(body->handle));
1171 handle->och_magic = OBD_CLIENT_HANDLE_MAGIC;
1173 OBD_ALLOC(handle->och_mod, sizeof(*handle->och_mod));
1174 if (handle->och_mod == NULL) {
1175 DEBUG_REQ(D_ERROR, req, "can't allocate mdc_open_data");
1178 handle->och_mod->mod_open_req = req; /* will be dropped by unpin */
1183 static int mdc_unpin(struct obd_export *exp,
1184 struct obd_client_handle *handle, int flag)
1186 struct ptlrpc_request *req;
1187 struct mds_body *body;
1188 int rc, size[2] = {0, sizeof(*body)};
1191 if (handle->och_magic != OBD_CLIENT_HANDLE_MAGIC)
1194 //size[0] = lustre_secdesc_size();
1196 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1197 MDS_CLOSE, 2, size, NULL);
1201 //lustre_pack_secdesc(req, size[0]);
1203 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof(*body));
1204 memcpy(&body->handle, &handle->och_fh, sizeof(body->handle));
1207 req->rq_replen = lustre_msg_size(0, NULL);
1208 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1209 rc = ptlrpc_queue_wait(req);
1210 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1213 CERROR("unpin failed: %d\n", rc);
1215 ptlrpc_req_finished(req);
1216 ptlrpc_req_finished(handle->och_mod->mod_open_req);
1217 OBD_FREE(handle->och_mod, sizeof(*handle->och_mod));
1221 int mdc_sync(struct obd_export *exp, struct lustre_id *id,
1222 struct ptlrpc_request **request)
1224 struct ptlrpc_request *req;
1225 struct mds_body *body;
1226 int size[2] = {0, sizeof(*body)};
1230 //size[0] = lustre_secdesc_size();
1232 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1233 MDS_SYNC, 2, size, NULL);
1235 RETURN(rc = -ENOMEM);
1237 //lustre_pack_secdesc(req, size[0]);
1240 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF,
1242 memcpy(&body->id1, id, sizeof(*id));
1245 req->rq_replen = lustre_msg_size(1, &size[1]);
1247 rc = ptlrpc_queue_wait(req);
1248 if (rc || request == NULL)
1249 ptlrpc_req_finished(req);
1256 static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
1257 enum obd_import_event event)
1261 LASSERT(imp->imp_obd == obd);
1264 case IMP_EVENT_DISCON: {
1267 case IMP_EVENT_INACTIVE: {
1268 if (obd->obd_observer)
1269 rc = obd_notify(obd->obd_observer, obd, 0, 0);
1272 case IMP_EVENT_INVALIDATE: {
1273 struct ldlm_namespace *ns = obd->obd_namespace;
1275 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
1279 case IMP_EVENT_ACTIVE: {
1280 if (obd->obd_observer)
1281 rc = obd_notify(obd->obd_observer, obd, 1, 0);
1285 CERROR("Unknown import event %d\n", event);
1291 static int mdc_attach(struct obd_device *dev, obd_count len, void *data)
1293 struct lprocfs_static_vars lvars;
1295 lprocfs_init_vars(mdc, &lvars);
1296 return lprocfs_obd_attach(dev, lvars.obd_vars);
1299 static int mdc_detach(struct obd_device *dev)
1301 return lprocfs_obd_detach(dev);
1304 static int mdc_setup(struct obd_device *obd, obd_count len, void *buf)
1306 struct client_obd *cli = &obd->u.cli;
1310 OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1311 if (!cli->cl_rpc_lock)
1313 mdc_init_rpc_lock(cli->cl_rpc_lock);
1317 OBD_ALLOC(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1318 if (!cli->cl_setattr_lock)
1319 GOTO(err_rpc_lock, rc = -ENOMEM);
1320 mdc_init_rpc_lock(cli->cl_setattr_lock);
1322 OBD_ALLOC(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1323 if (!cli->cl_close_lock)
1324 GOTO(err_setattr_lock, rc = -ENOMEM);
1325 mdc_init_rpc_lock(cli->cl_close_lock);
1327 rc = client_obd_setup(obd, len, buf);
1329 GOTO(err_close_lock, rc);
1331 rc = obd_llog_init(obd, &obd->obd_llogs, obd, 0, NULL);
1333 mdc_cleanup(obd, 0);
1334 CERROR("failed to setup llogging subsystems\n");
1340 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1342 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1344 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1349 static int mdc_init_ea_size(struct obd_export *exp, int easize, int cookiesize)
1351 struct obd_device *obd = exp->exp_obd;
1352 struct client_obd *cli = &obd->u.cli;
1355 if (cli->cl_max_mds_easize < easize)
1356 cli->cl_max_mds_easize = easize;
1357 if (cli->cl_max_mds_cookiesize < cookiesize)
1358 cli->cl_max_mds_cookiesize = cookiesize;
1362 static int mdc_precleanup(struct obd_device *obd, int flags)
1366 rc = obd_llog_finish(obd, &obd->obd_llogs, 0);
1368 CERROR("failed to cleanup llogging subsystems\n");
1373 static int mdc_cleanup(struct obd_device *obd, int flags)
1375 struct client_obd *cli = &obd->u.cli;
1377 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1378 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1379 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1383 return client_obd_cleanup(obd, flags);
1387 static int mdc_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
1388 struct obd_device *tgt, int count,
1389 struct llog_catid *logid)
1391 struct llog_ctxt *ctxt;
1395 rc = obd_llog_setup(obd, llogs, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
1398 ctxt = llog_get_context(llogs, LLOG_CONFIG_REPL_CTXT);
1399 ctxt->loc_imp = obd->u.cli.cl_import;
1405 static int mdc_llog_finish(struct obd_device *obd,
1406 struct obd_llogs *llogs, int count)
1411 rc = obd_llog_cleanup(llog_get_context(llogs, LLOG_CONFIG_REPL_CTXT));
1415 static struct obd_device *mdc_get_real_obd(struct obd_export *exp,
1416 struct lustre_id *id)
1419 RETURN(exp->exp_obd);
1422 static int mdc_get_info(struct obd_export *exp, __u32 keylen,
1423 void *key, __u32 *valsize, void *val)
1425 struct ptlrpc_request *req;
1426 char *bufs[1] = {key};
1430 if (!valsize || !val)
1433 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
1434 struct obd_import *imp;
1435 struct obd_connect_data *data;
1437 imp = class_exp2cliimp(exp);
1443 if (imp->imp_state != LUSTRE_IMP_FULL) {
1444 CERROR("import state not full\n");
1448 data = &imp->imp_connect_data;
1449 if (data->ocd_connect_flags & OBD_CONNECT_REMOTE) {
1452 } else if (data->ocd_connect_flags & OBD_CONNECT_LOCAL) {
1456 CERROR("no remote flag set?\n");
1460 if ((keylen < strlen("mdsize") || strcmp(key, "mdsize") != 0) &&
1461 (keylen < strlen("mdsnum") || strcmp(key, "mdsnum") != 0) &&
1462 (keylen < strlen("lovdesc") || strcmp(key, "lovdesc") != 0) &&
1463 (keylen < strlen("getext") || strcmp(key, "getext") != 0) &&
1464 (keylen < strlen("rootid") || strcmp(key, "rootid") != 0) &&
1465 (keylen < strlen("auditid") || strcmp(key, "auditid") != 0))
1468 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1469 OST_GET_INFO, 1, (int *)&keylen, bufs);
1473 req->rq_replen = lustre_msg_size(1, (int *)valsize);
1474 rc = ptlrpc_queue_wait(req);
1478 if ((keylen >= strlen("rootid") && !strcmp(key, "rootid")) ||
1479 (keylen >= strlen("auditid") && !strcmp(key, "auditid"))) {
1480 struct lustre_id *reply;
1482 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
1483 lustre_swab_lustre_id);
1484 if (reply == NULL) {
1485 CERROR("Can't unpack %s\n", (char *)key);
1486 GOTO(out_req, rc = -EPROTO);
1489 *(struct lustre_id *)val = *reply;
1490 } else if (keylen >= strlen("lovdesc") && !strcmp(key, "lovdesc")) {
1491 struct lov_desc *reply;
1493 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
1494 lustre_swab_lov_desc);
1495 if (reply == NULL) {
1496 CERROR("Can't unpack %s\n", (char *)key);
1497 GOTO(out_req, rc = -EPROTO);
1500 *(struct lov_desc *)val = *reply;
1502 } else if (keylen >= strlen("getext") && !strcmp(key, "getext")) {
1503 struct fid_extent *reply;
1505 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
1506 lustre_swab_fid_extent);
1507 if (reply == NULL) {
1508 CERROR("Can't unpack %s\n", (char *)key);
1509 GOTO(out_req, rc = -EPROTO);
1512 *(struct fid_extent *)val = *reply;
1517 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
1518 lustre_swab_generic_32s);
1519 if (reply == NULL) {
1520 CERROR("Can't unpack %s\n", (char *)key);
1521 GOTO(out_req, rc = -EPROTO);
1523 *((__u32 *)val) = *reply;
1526 ptlrpc_req_finished(req);
1530 int mdc_obj_create(struct obd_export *exp, struct obdo *oa,
1531 void *acl, int acl_size, struct lov_stripe_md **ea,
1532 struct obd_trans_info *oti)
1534 struct ptlrpc_request *request;
1535 struct ost_body *body;
1537 int rc, size[2] = { sizeof(*body), acl_size };
1542 request = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1543 OST_CREATE, 2, size, NULL);
1545 GOTO(out_req, rc = -ENOMEM);
1547 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
1548 memcpy(&body->oa, oa, sizeof(body->oa));
1551 acl_buf = lustre_msg_buf(request->rq_reqmsg, 1, acl_size);
1552 memcpy(acl_buf, acl, acl_size);
1555 request->rq_replen = lustre_msg_size(1, size);
1556 rc = ptlrpc_queue_wait(request);
1560 body = lustre_swab_repbuf(request, 0, sizeof(*body),
1561 lustre_swab_ost_body);
1563 CERROR ("can't unpack ost_body\n");
1564 GOTO (out_req, rc = -EPROTO);
1567 memcpy(oa, &body->oa, sizeof(*oa));
1569 /* store ino/generation for recovery */
1570 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
1571 body->oa.o_id = oa->o_id;
1572 body->oa.o_generation = oa->o_generation;
1573 body->oa.o_fid = oa->o_fid;
1574 body->oa.o_mds = oa->o_mds;
1576 CDEBUG(D_HA, "transno: "LPD64"\n", request->rq_repmsg->transno);
1579 ptlrpc_req_finished(request);
1583 int mdc_brw(int rw, struct obd_export *exp, struct obdo *oa,
1584 struct lov_stripe_md *ea, obd_count oa_bufs,
1585 struct brw_page *pgarr, struct obd_trans_info *oti)
1587 struct ptlrpc_bulk_desc *desc;
1588 struct niobuf_remote *niobuf;
1589 struct ptlrpc_request *req;
1590 struct obd_ioobj *ioobj;
1591 struct ost_body *body;
1595 opc = ((rw & OBD_BRW_WRITE) != 0) ? OST_WRITE : OST_READ;
1597 size[0] = sizeof(*body);
1598 size[1] = sizeof(*ioobj);
1599 size[2] = oa_bufs * sizeof(*niobuf);
1601 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION, opc,
1603 LASSERT(req != NULL);
1605 if (opc == OST_WRITE)
1606 desc = ptlrpc_prep_bulk_imp(req, oa_bufs, BULK_GET_SOURCE,
1609 desc = ptlrpc_prep_bulk_imp(req, oa_bufs, BULK_PUT_SINK,
1611 LASSERT(desc != NULL);
1613 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
1614 ioobj = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*ioobj));
1615 niobuf = lustre_msg_buf(req->rq_reqmsg, 2, oa_bufs * sizeof(*niobuf));
1617 memcpy(&body->oa, oa, sizeof(*oa));
1618 obdo_to_ioobj(oa, ioobj);
1619 ioobj->ioo_bufcnt = oa_bufs;
1621 for (i = 0; i < oa_bufs; i++, niobuf++) {
1622 struct brw_page *pg = &pgarr[i];
1624 LASSERT(pg->count > 0);
1625 LASSERT((pg->disk_offset & ~PAGE_MASK) + pg->count <= PAGE_SIZE);
1627 ptlrpc_prep_bulk_page(desc, pg->pg, pg->disk_offset & ~PAGE_MASK,
1630 niobuf->offset = pg->disk_offset;
1631 niobuf->len = pg->count;
1632 niobuf->flags = pg->flag;
1635 /* size[0] still sizeof (*body) */
1636 if (opc == OST_WRITE) {
1637 /* 1 RC per niobuf */
1638 size[1] = sizeof(__u32) * oa_bufs;
1639 req->rq_replen = lustre_msg_size(2, size);
1641 /* 1 RC for the whole I/O */
1642 req->rq_replen = lustre_msg_size(1, size);
1644 err = ptlrpc_queue_wait(req);
1647 ptlrpc_req_finished(req);
1651 static int mdc_valid_attrs(struct obd_export *exp,
1652 struct lustre_id *id)
1654 struct ldlm_res_id res_id = { .name = {0} };
1655 struct obd_device *obd = exp->exp_obd;
1656 struct lustre_handle lockh;
1657 ldlm_policy_data_t policy;
1661 res_id.name[0] = id_fid(id);
1662 res_id.name[1] = id_group(id);
1663 policy.l_inodebits.bits = MDS_INODELOCK_UPDATE;
1665 CDEBUG(D_INFO, "trying to match res "LPU64"\n",
1668 /* FIXME use LDLM_FL_TEST_LOCK instead */
1669 flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_CBPENDING;
1670 if (ldlm_lock_match(obd->obd_namespace, flags, &res_id,
1671 LDLM_IBITS, &policy, LCK_PR, &lockh)) {
1672 ldlm_lock_decref(&lockh, LCK_PR);
1676 if (ldlm_lock_match(obd->obd_namespace, flags, &res_id,
1677 LDLM_IBITS, &policy, LCK_PW, &lockh)) {
1678 ldlm_lock_decref(&lockh, LCK_PW);
1684 static int mdc_change_cbdata_name(struct obd_export *exp,
1685 struct lustre_id *pid,
1686 char *name, int len,
1687 struct lustre_id *cid,
1688 ldlm_iterator_t it, void *data)
1691 rc = mdc_change_cbdata(exp, cid, it, data);
1695 struct obd_ops mdc_obd_ops = {
1696 .o_owner = THIS_MODULE,
1697 .o_attach = mdc_attach,
1698 .o_detach = mdc_detach,
1699 .o_setup = mdc_setup,
1700 .o_precleanup = mdc_precleanup,
1701 .o_cleanup = mdc_cleanup,
1702 .o_add_conn = client_import_add_conn,
1703 .o_del_conn = client_import_del_conn,
1704 .o_connect = client_connect_import,
1705 .o_disconnect = client_disconnect_export,
1706 .o_iocontrol = mdc_iocontrol,
1707 .o_packmd = mdc_packmd,
1708 .o_unpackmd = mdc_unpackmd,
1709 .o_statfs = mdc_statfs,
1711 .o_unpin = mdc_unpin,
1712 .o_import_event = mdc_import_event,
1713 .o_llog_init = mdc_llog_init,
1714 .o_llog_finish = mdc_llog_finish,
1715 .o_create = mdc_obj_create,
1716 .o_set_info = mdc_set_info,
1717 .o_get_info = mdc_get_info,
1719 .o_cancel_unused = mdc_cancel_unused,
1720 .o_init_ea_size = mdc_init_ea_size,
1723 struct md_ops mdc_md_ops = {
1724 .m_getstatus = mdc_getstatus,
1725 .m_getattr = mdc_getattr,
1726 .m_close = mdc_close,
1727 .m_create = mdc_create,
1728 .m_done_writing = mdc_done_writing,
1729 .m_enqueue = mdc_enqueue,
1730 .m_getattr_lock = mdc_getattr_lock,
1731 .m_intent_lock = mdc_intent_lock,
1733 .m_rename = mdc_rename,
1734 .m_setattr = mdc_setattr,
1736 .m_readpage = mdc_readpage,
1737 .m_unlink = mdc_unlink,
1738 .m_valid_attrs = mdc_valid_attrs,
1739 .m_req2lustre_md = mdc_req2lustre_md,
1740 .m_set_open_replay_data = mdc_set_open_replay_data,
1741 .m_clear_open_replay_data = mdc_clear_open_replay_data,
1742 .m_store_inode_generation = mdc_store_inode_generation,
1743 .m_set_lock_data = mdc_set_lock_data,
1744 .m_get_real_obd = mdc_get_real_obd,
1745 .m_change_cbdata_name = mdc_change_cbdata_name,
1746 .m_change_cbdata = mdc_change_cbdata,
1747 .m_access_check = mdc_access_check,
1750 int __init mdc_init(void)
1752 struct lprocfs_static_vars lvars;
1754 lprocfs_init_vars(mdc, &lvars);
1755 return class_register_type(&mdc_obd_ops, &mdc_md_ops,
1756 lvars.module_vars, OBD_MDC_DEVICENAME);
1760 static void /*__exit*/ mdc_exit(void)
1762 class_unregister_type(OBD_MDC_DEVICENAME);
1765 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1766 MODULE_DESCRIPTION("Lustre Metadata Client");
1767 MODULE_LICENSE("GPL");
1769 EXPORT_SYMBOL(mdc_req2lustre_md);
1770 EXPORT_SYMBOL(mdc_change_cbdata);
1771 EXPORT_SYMBOL(mdc_getstatus);
1772 EXPORT_SYMBOL(mdc_getattr);
1773 EXPORT_SYMBOL(mdc_getattr_lock);
1774 EXPORT_SYMBOL(mdc_create);
1775 EXPORT_SYMBOL(mdc_unlink);
1776 EXPORT_SYMBOL(mdc_rename);
1777 EXPORT_SYMBOL(mdc_link);
1778 EXPORT_SYMBOL(mdc_readpage);
1779 EXPORT_SYMBOL(mdc_setattr);
1780 EXPORT_SYMBOL(mdc_close);
1781 EXPORT_SYMBOL(mdc_done_writing);
1782 EXPORT_SYMBOL(mdc_sync);
1783 EXPORT_SYMBOL(mdc_set_open_replay_data);
1784 EXPORT_SYMBOL(mdc_clear_open_replay_data);
1785 EXPORT_SYMBOL(mdc_store_inode_generation);
1787 module_init(mdc_init);
1788 module_exit(mdc_exit);