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_gs.h>
43 #include "mdc_internal.h"
45 #define REQUEST_MINOR 244
47 static int mdc_cleanup(struct obd_device *obd, int flags);
49 extern int mds_queue_req(struct ptlrpc_request *);
50 /* Helper that implements most of mdc_getstatus and signal_completed_replay. */
51 /* XXX this should become mdc_get_info("key"), sending MDS_GET_INFO RPC */
52 static int send_getstatus(struct obd_import *imp, struct lustre_id *rootid,
53 int level, int msg_flags)
55 struct ptlrpc_request *req;
56 struct mds_body *body;
57 int rc, size[2] = {0, sizeof(*body)};
60 //size[0] = lustre_secdesc_size();
62 req = ptlrpc_prep_req(imp, LUSTRE_MDS_VERSION, MDS_GETSTATUS,
65 GOTO(out, rc = -ENOMEM);
67 //lustre_pack_secdesc(req, size[0]);
69 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof (*body));
70 req->rq_send_state = level;
71 req->rq_replen = lustre_msg_size(1, &size[1]);
73 req->rq_reqmsg->flags |= msg_flags;
74 rc = ptlrpc_queue_wait(req);
77 body = lustre_swab_repbuf (req, 0, sizeof (*body),
78 lustre_swab_mds_body);
80 CERROR ("Can't extract mds_body\n");
81 GOTO (out, rc = -EPROTO);
84 memcpy(rootid, &body->id1, sizeof(*rootid));
86 CDEBUG(D_NET, "root ino="LPU64", last_committed="LPU64
87 ", last_xid="LPU64"\n", rootid->li_stc.u.e3s.l3s_ino,
88 req->rq_repmsg->last_committed, req->rq_repmsg->last_xid);
93 ptlrpc_req_finished(req);
97 /* This should be mdc_get_info("rootid") */
98 int mdc_getstatus(struct obd_export *exp, struct lustre_id *rootid)
100 return send_getstatus(class_exp2cliimp(exp), rootid,
104 int mdc_getattr_common(struct obd_export *exp, unsigned int ea_size,
105 struct ptlrpc_request *req)
107 struct mds_body *body, *reqbody;
110 int repsize[2] = {sizeof(*body)};
114 /* request message already built */
117 repsize[bufcount++] = ea_size;
118 CDEBUG(D_INODE, "reserved %u bytes for MD/symlink in packet\n",
122 reqbody = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*reqbody));
123 LASSERT(!(reqbody->valid & OBD_MD_FLACL));
125 if (reqbody->valid & OBD_MD_FLKEY) {
126 repsize[bufcount++] = 5;
127 repsize[bufcount++] = sizeof(struct lustre_key);
130 req->rq_replen = lustre_msg_size(bufcount, repsize);
132 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
133 rc = ptlrpc_queue_wait(req);
134 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
138 body = lustre_swab_repbuf (req, 0, sizeof (*body),
139 lustre_swab_mds_body);
141 CERROR ("Can't unpack mds_body\n");
145 CDEBUG(D_NET, "mode: %o\n", body->mode);
147 LASSERT_REPSWAB (req, 1);
149 /* Skip the check if getxattr/listxattr are called with no buffers */
150 if ((reqbody->eadatasize != 0) &&
151 !(reqbody->valid & (OBD_MD_FLXATTR | OBD_MD_FLXATTRLIST))) {
152 /* reply indicates presence of eadata; check it's there... */
153 eadata = lustre_msg_buf (req->rq_repmsg, 1,
155 if (eadata == NULL) {
156 CERROR ("Missing/short eadata\n");
164 static int mdc_cancel_unused(struct obd_export *exp,
165 struct lov_stripe_md *lsm,
166 int flags, void *opaque)
168 struct obd_device *obd = class_exp2obd(exp);
171 RETURN(ldlm_cli_cancel_unused(obd->obd_namespace,
172 NULL, flags, opaque));
175 int mdc_getattr(struct obd_export *exp, struct lustre_id *id,
176 __u64 valid, const char *xattr_name,
177 const void *xattr_data, unsigned int xattr_datalen,
178 unsigned int ea_size, struct ptlrpc_request **request)
180 struct ptlrpc_request *req;
181 struct mds_body *body;
182 int xattr_namelen = xattr_name ? strlen(xattr_name) + 1 : 0;
183 int size[4] = {0, sizeof(*body)};
188 size[0] = lustre_secdesc_size();
190 if (valid & OBD_MD_FLXATTR) {
191 size[bufcount++] = xattr_namelen;
193 if (xattr_datalen > 0) {
195 size[bufcount++] = xattr_datalen;
198 LASSERT(!xattr_data && !xattr_datalen);
200 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
201 MDS_GETATTR, bufcount, size, NULL);
203 GOTO(out, rc = -ENOMEM);
205 lustre_pack_secdesc(req, size[0]);
207 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof (*body));
208 memcpy(&body->id1, id, sizeof(*id));
210 body->eadatasize = ea_size;
212 if (valid & OBD_MD_FLXATTR) {
213 memcpy(lustre_msg_buf(req->rq_reqmsg, 2, xattr_namelen),
214 xattr_name, xattr_namelen);
216 memcpy(lustre_msg_buf(req->rq_reqmsg, 3, xattr_datalen),
217 xattr_data, xattr_datalen);
220 rc = mdc_getattr_common(exp, ea_size, req);
222 ptlrpc_req_finished (req);
230 int mdc_access_check(struct obd_export *exp, struct lustre_id *id,
231 struct ptlrpc_request **request)
234 struct ptlrpc_request *req;
235 struct mds_body *body;
236 int size[2] = {0, sizeof(*body)};
240 size[0] = lustre_secdesc_size();
241 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
242 MDS_ACCESS_CHECK, 2, size, NULL);
244 GOTO(out, rc = -ENOMEM);
246 lustre_pack_secdesc(req, size[0]);
247 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof (*body));
248 memcpy(&body->id1, id, sizeof(*id));
250 req->rq_replen = lustre_msg_size(2, size);
251 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
252 rc = ptlrpc_queue_wait(req);
253 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
255 ptlrpc_req_finished (req);
258 body = lustre_swab_repbuf (req, 0, sizeof (*body),
259 lustre_swab_mds_body);
261 CERROR ("Can't unpack mds_body\n");
271 int mdc_getattr_lock(struct obd_export *exp, struct lustre_id *id,
272 char *filename, int namelen, __u64 valid,
273 unsigned int ea_size, struct ptlrpc_request **request)
275 struct ptlrpc_request *req;
276 struct mds_body *body;
277 int rc, size[3] = {0, sizeof(*body), namelen};
280 size[0] = lustre_secdesc_size();
282 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
283 MDS_GETATTR_LOCK, 3, size, NULL);
285 GOTO(out, rc = -ENOMEM);
287 lustre_pack_secdesc(req, size[0]);
289 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof (*body));
290 memcpy(&body->id1, id, sizeof(*id));
292 body->eadatasize = ea_size;
294 if (filename != NULL) {
295 LASSERT (strnlen (filename, namelen) == namelen - 1);
296 memcpy(lustre_msg_buf(req->rq_reqmsg, 2, namelen),
299 LASSERT(namelen == 1);
302 rc = mdc_getattr_common(exp, ea_size, req);
304 ptlrpc_req_finished (req);
312 /* This should be called with both the request and the reply still packed. */
313 int mdc_store_inode_generation(struct obd_export *exp,
314 struct ptlrpc_request *req,
315 int reqoff, int repoff)
317 struct mds_rec_create *rec =
318 lustre_msg_buf(req->rq_reqmsg, reqoff, sizeof(*rec));
319 struct mds_body *body =
320 lustre_msg_buf(req->rq_repmsg, repoff, sizeof(*body));
322 LASSERT (rec != NULL);
323 LASSERT (body != NULL);
325 memcpy(&rec->cr_replayid, &body->id1, sizeof(rec->cr_replayid));
326 DEBUG_REQ(D_HA, req, "storing generation for ino "DLID4,
327 OLID4(&rec->cr_replayid));
331 static int mdc_unpack_acl(struct obd_export *exp_lmv, struct ptlrpc_request *req,
332 unsigned int *offset, struct lustre_md *md)
334 struct posix_acl *acl;
335 struct mds_remote_perm *perm;
336 int size, acl_off = 0, rc = 0;
339 /* if anything wrong when unpacking md, we don't check acl
340 * stuff, for simplicity
342 if (md->body->valid & OBD_MD_FLACL) {
344 if (md->body->valid & OBD_MD_FLRMTACL) {
346 buf = lustre_swab_repbuf(req, acl_off++, sizeof(*perm),
347 lustre_swab_remote_perm);
349 CERROR("Can't unpack remote perm\n");
352 OBD_ALLOC(perm, sizeof(*perm));
355 memcpy(perm, buf, sizeof(*perm));
356 md->remote_perm = perm;
359 size = le32_to_cpu(*(__u32 *) lustre_msg_buf(
360 req->rq_repmsg, acl_off++, 4));
361 buf = lustre_msg_buf(req->rq_repmsg, acl_off++, size);
363 acl = posix_acl_from_xattr(buf, size);
367 CERROR("convert xattr to acl failed: %d\n", rc);
370 rc = posix_acl_valid(acl);
372 CERROR("acl valid error: %d\n", rc);
373 posix_acl_release(acl);
382 static int mdc_unpack_gskey(struct obd_export *exp_lmv, struct ptlrpc_request *req,
383 unsigned int *offset, struct lustre_md *md)
385 int key_off = 0, rc = 0, size = 0;
389 if (md->body->valid & OBD_MD_FLKEY) {
390 size = le32_to_cpu(*(__u32 *) lustre_msg_buf(req->rq_repmsg,
392 buf = lustre_msg_buf(req->rq_repmsg, key_off++, size);
394 CDEBUG(D_INFO, "buf %p key_off %d size %d \n",
396 md->key = (struct lustre_key *)buf;
401 int mdc_req2lustre_md(struct obd_export *exp_lmv, struct ptlrpc_request *req,
402 unsigned int offset, struct obd_export *exp_lov,
403 struct lustre_md *md)
405 struct lov_mds_md *lmm;
406 int rc = 0, reply_off;
410 memset(md, 0, sizeof(*md));
412 md->body = lustre_msg_buf(req->rq_repmsg, offset,
417 LASSERT_REPSWABBED(req, offset);
419 if (!(md->body->valid & OBD_MD_FLEASIZE) &&
420 !(md->body->valid & OBD_MD_FLDIREA))
423 if (S_ISREG(md->body->mode)) {
424 if (md->body->eadatasize == 0) {
425 CERROR("invalid EA size (0) is detected\n");
429 lmm = lustre_msg_buf(req->rq_repmsg, offset + 1,
430 md->body->eadatasize);
434 LASSERT(exp_lov != NULL);
436 rc = obd_unpackmd(exp_lov, &md->lsm, lmm,
437 md->body->eadatasize);
439 LASSERT(rc >= sizeof(*md->lsm));
442 } else if (S_ISDIR(md->body->mode)) {
443 /* dir can be non-splitted */
444 if (md->body->eadatasize == 0)
447 lmm = lustre_msg_buf(req->rq_repmsg, offset + 1,
448 md->body->eadatasize);
452 if (md->body->valid & OBD_MD_MEA) {
453 LASSERT(exp_lmv != NULL);
455 rc = obd_unpackmd(exp_lmv, (void *)&md->mea,
456 lmm, md->body->eadatasize);
458 LASSERT(rc >= sizeof(*md->mea));
463 LASSERT(S_ISCHR(md->body->mode) ||
464 S_ISBLK(md->body->mode) ||
465 S_ISFIFO(md->body->mode)||
466 S_ISLNK(md->body->mode) ||
467 S_ISSOCK(md->body->mode));
470 reply_off = (md->body->valid & OBD_MD_FLEASIZE) ?
471 (offset + 2) : (offset + 1);
472 rc = mdc_unpack_acl(exp_lmv, req, &reply_off, md);
474 CERROR("upack acl error %d \n", rc);
478 rc = mdc_unpack_gskey(exp_lmv, req, &reply_off, md);
485 static void mdc_commit_open(struct ptlrpc_request *req)
487 struct mdc_open_data *mod = req->rq_cb_data;
491 if (mod->mod_close_req != NULL)
492 mod->mod_close_req->rq_cb_data = NULL;
494 if (mod->mod_och != NULL)
495 mod->mod_och->och_mod = NULL;
497 OBD_FREE(mod, sizeof(*mod));
498 req->rq_cb_data = NULL;
499 LASSERT(atomic_read(&req->rq_refcount) > 1);
500 ptlrpc_req_finished(req);
503 static void mdc_replay_open(struct ptlrpc_request *req)
505 struct mdc_open_data *mod = req->rq_cb_data;
506 struct obd_client_handle *och;
507 struct ptlrpc_request *close_req;
508 struct lustre_handle old;
509 struct mds_body *body;
512 body = lustre_swab_repbuf(req, 1, sizeof(*body), lustre_swab_mds_body);
513 LASSERT (body != NULL);
516 DEBUG_REQ(D_ERROR, req,
517 "can't properly replay without open data");
524 struct lustre_handle *file_fh;
525 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
526 file_fh = &och->och_fh;
527 CDEBUG(D_HA, "updating handle from "LPX64" to "LPX64"\n",
528 file_fh->cookie, body->handle.cookie);
529 memcpy(&old, file_fh, sizeof(old));
530 memcpy(file_fh, &body->handle, sizeof(*file_fh));
533 close_req = mod->mod_close_req;
534 if (close_req != NULL) {
535 struct mds_body *close_body;
536 LASSERT(close_req->rq_reqmsg->opc == MDS_CLOSE);
537 close_body = lustre_msg_buf(close_req->rq_reqmsg,
539 sizeof(*close_body));
541 LASSERT(!memcmp(&old, &close_body->handle, sizeof old));
542 DEBUG_REQ(D_HA, close_req, "updating close body with new fh");
543 memcpy(&close_body->handle, &body->handle,
544 sizeof(close_body->handle));
550 int mdc_set_open_replay_data(struct obd_export *exp,
551 struct obd_client_handle *och,
552 struct ptlrpc_request *open_req)
554 struct mdc_open_data *mod;
555 struct mds_rec_create *rec;
556 struct mds_body *body;
558 rec = lustre_msg_buf(open_req->rq_reqmsg, MDS_REQ_INTENT_REC_OFF,
560 body = lustre_msg_buf(open_req->rq_repmsg, 1, sizeof(*body));
562 LASSERT(rec != NULL);
563 /* outgoing messages always in my byte order */
564 LASSERT(body != NULL);
565 /* incoming message in my byte order (it's been swabbed) */
566 LASSERT_REPSWABBED(open_req, 1);
568 OBD_ALLOC(mod, sizeof(*mod));
570 DEBUG_REQ(D_ERROR, open_req, "can't allocate mdc_open_data");
576 mod->mod_open_req = ptlrpc_request_addref(open_req);
578 memcpy(&rec->cr_replayid, &body->id1, sizeof rec->cr_replayid);
579 open_req->rq_replay_cb = mdc_replay_open;
580 open_req->rq_commit_cb = mdc_commit_open;
581 open_req->rq_cb_data = mod;
582 DEBUG_REQ(D_HA, open_req, "set up replay data");
586 int mdc_clear_open_replay_data(struct obd_export *exp,
587 struct obd_client_handle *och)
589 struct mdc_open_data *mod = och->och_mod;
591 /* Don't free the structure now (it happens in mdc_commit_open, after
592 * we're sure we won't need to fix up the close request in the future),
593 * but make sure that replay doesn't poke at the och, which is about to
595 LASSERT(mod != LP_POISON);
602 static void mdc_commit_close(struct ptlrpc_request *req)
604 struct mdc_open_data *mod = req->rq_cb_data;
605 struct obd_import *imp = req->rq_import;
606 struct ptlrpc_request *open_req;
608 DEBUG_REQ(D_HA, req, "close req committed");
612 mod->mod_close_req = NULL;
613 req->rq_cb_data = NULL;
614 req->rq_commit_cb = NULL;
616 open_req = mod->mod_open_req;
617 LASSERT(open_req != NULL);
618 LASSERT(open_req != LP_POISON);
619 LASSERT(open_req->rq_type != LI_POISON);
621 DEBUG_REQ(D_HA, open_req, "open req balanced");
622 if (open_req->rq_transno == 0) {
623 DEBUG_REQ(D_ERROR, open_req, "BUG 3892 open");
624 DEBUG_REQ(D_ERROR, req, "BUG 3892 close");
625 LASSERTF(open_req->rq_transno != 0, "BUG 3892\n");
627 LASSERT(open_req->rq_import == imp);
629 /* We no longer want to preserve this for transno-unconditional
631 spin_lock(&open_req->rq_lock);
632 open_req->rq_replay = 0;
633 spin_unlock(&open_req->rq_lock);
636 int mdc_close(struct obd_export *exp, struct obdo *oa,
637 struct obd_client_handle *och,
638 struct ptlrpc_request **request)
640 struct obd_device *obd = class_exp2obd(exp);
641 struct obd_import *imp = class_exp2cliimp(exp);
642 int reqsize[3] = {0, sizeof(struct mds_body),
643 obd->u.cli.cl_max_mds_cookiesize};
644 int rc, repsize[3] = {sizeof(struct mds_body),
645 obd->u.cli.cl_max_mds_easize,
646 obd->u.cli.cl_max_mds_cookiesize};
647 struct ptlrpc_request *req;
648 struct mdc_open_data *mod;
651 if (imp->imp_connection == NULL) {
652 CERROR("request on not connected import %s\n",
653 imp->imp_obd->obd_name);
657 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
658 MDS_CLOSE, 3, reqsize, NULL);
660 GOTO(out, rc = -ENOMEM);
661 req->rq_request_portal = MDS_CLOSE_PORTAL;
663 //reqsize[0] = lustre_secdesc_size();
664 //lustre_pack_secdesc(req, reqsize[0]);
666 /* Ensure that this close's handle is fixed up during replay. */
667 LASSERT(och != NULL);
669 if (likely(mod != NULL)) {
670 mod->mod_close_req = req;
671 LASSERT(mod->mod_open_req->rq_type != LI_POISON);
672 DEBUG_REQ(D_HA, mod->mod_open_req, "matched open");
674 CDEBUG(D_HA, "couldn't find open req; "
675 "expecting close error\n");
678 mdc_close_pack(req, 1, oa, oa->o_valid, och);
680 req->rq_replen = lustre_msg_size(3, repsize);
681 req->rq_commit_cb = mdc_commit_close;
682 LASSERT(req->rq_cb_data == NULL);
683 req->rq_cb_data = mod;
685 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
686 rc = ptlrpc_queue_wait(req);
687 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
689 if (req->rq_repmsg == NULL) {
690 CDEBUG(D_HA, "request failed to send: %p, %d\n", req,
693 rc = req->rq_status ? req->rq_status : -EIO;
694 } else if (rc == 0) {
695 rc = req->rq_repmsg->status;
696 if (req->rq_repmsg->type == PTL_RPC_MSG_ERR) {
697 DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, "
703 CERROR("Unexpected: can't find mdc_open_data, but "
704 "close succeeded. Please tell CFS.\n");
705 if (!lustre_swab_repbuf(req, 0, sizeof(struct mds_body),
706 lustre_swab_mds_body))
708 CERROR("Error unpacking mds_body\n");
720 int mdc_done_writing(struct obd_export *exp, struct obdo *obdo)
722 struct ptlrpc_request *req;
723 struct mds_body *body;
724 int rc, size[2] = {0, sizeof(*body)};
727 size[0] = lustre_secdesc_size();
729 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
730 MDS_DONE_WRITING, 2, size, NULL);
734 lustre_pack_secdesc(req, size[0]);
736 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF,
739 mdc_pack_id(&body->id1, obdo->o_id, 0, obdo->o_mode,
740 obdo->o_mds, obdo->o_fid);
742 body->size = obdo->o_size;
743 body->blocks = obdo->o_blocks;
744 body->flags = obdo->o_flags;
745 body->valid = obdo->o_valid;
747 req->rq_replen = lustre_msg_size(1, &size[1]);
749 rc = ptlrpc_queue_wait(req);
750 ptlrpc_req_finished(req);
754 int mdc_readpage(struct obd_export *exp,
755 struct lustre_id *id,
756 __u64 offset, struct page *page,
757 struct ptlrpc_request **request)
759 struct obd_import *imp = class_exp2cliimp(exp);
760 struct ptlrpc_request *req = NULL;
761 struct ptlrpc_bulk_desc *desc = NULL;
762 struct mds_body *body;
763 int rc, size[2] = {0, sizeof(*body)};
766 CDEBUG(D_INODE, "inode: %ld\n", (long)id->li_stc.u.e3s.l3s_ino);
768 size[0] = lustre_secdesc_size();
770 req = ptlrpc_prep_req(imp, LUSTRE_MDS_VERSION, MDS_READPAGE,
773 GOTO(out, rc = -ENOMEM);
774 /* XXX FIXME bug 249 */
775 req->rq_request_portal = MDS_READPAGE_PORTAL;
777 lustre_pack_secdesc(req, size[0]);
779 desc = ptlrpc_prep_bulk_imp(req, 1, BULK_PUT_SINK, MDS_BULK_PORTAL);
781 GOTO(out, rc = -ENOMEM);
782 /* NB req now owns desc and will free it when it gets freed */
784 ptlrpc_prep_bulk_page(desc, page, 0, PAGE_CACHE_SIZE);
785 mdc_readdir_pack(req, 1, offset, PAGE_CACHE_SIZE, id);
787 req->rq_replen = lustre_msg_size(1, &size[1]);
788 rc = ptlrpc_queue_wait(req);
791 body = lustre_swab_repbuf(req, 0, sizeof (*body),
792 lustre_swab_mds_body);
794 CERROR("Can't unpack mds_body\n");
795 GOTO(out, rc = -EPROTO);
798 if (req->rq_bulk->bd_nob_transferred != PAGE_CACHE_SIZE) {
799 CERROR ("Unexpected # bytes transferred: %d"
801 req->rq_bulk->bd_nob_transferred,
803 GOTO (out, rc = -EPROTO);
813 static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
814 void *karg, void *uarg)
816 struct obd_device *obd = exp->exp_obd;
817 struct obd_ioctl_data *data = karg;
818 struct obd_import *imp = obd->u.cli.cl_import;
819 struct llog_ctxt *ctxt;
823 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
826 if (!try_module_get(THIS_MODULE)) {
827 CERROR("Can't get module. Is it alive?");
832 case OBD_IOC_CLIENT_RECOVER:
833 rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1);
837 case IOC_OSC_SET_ACTIVE:
838 rc = ptlrpc_set_import_active(imp, data->ioc_offset);
840 case IOC_OSC_CTL_RECOVERY:
841 rc = ptlrpc_import_control_recovery(imp, data->ioc_offset);
843 case OBD_IOC_PARSE: {
844 ctxt = llog_get_context(&exp->exp_obd->obd_llogs,
845 LLOG_CONFIG_REPL_CTXT);
846 rc = class_config_process_llog(ctxt, data->ioc_inlbuf1, NULL);
850 case OBD_IOC_LLOG_INFO:
851 case OBD_IOC_LLOG_PRINT: {
852 ctxt = llog_get_context(&obd->obd_llogs, LLOG_CONFIG_REPL_CTXT);
853 rc = llog_ioctl(ctxt, cmd, data);
859 CERROR("mdc_ioctl(): unrecognised ioctl %#x\n", cmd);
860 GOTO(out, rc = -ENOTTY);
863 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
866 module_put(THIS_MODULE);
872 int mdc_set_info(struct obd_export *exp, obd_count keylen,
873 void *key, obd_count vallen, void *val)
877 if (keylen == strlen("initial_recov") &&
878 memcmp(key, "initial_recov", strlen("initial_recov")) == 0) {
879 struct obd_import *imp = exp->exp_obd->u.cli.cl_import;
880 if (vallen != sizeof(int))
882 imp->imp_initial_recov = *(int *)val;
883 CDEBUG(D_HA, "%s: set imp_no_init_recov = %d\n",
884 exp->exp_obd->obd_name,
885 imp->imp_initial_recov);
887 } else if ((keylen >= strlen("crypto_type")) &&
888 strcmp(key, "crypto_type") == 0) {
889 struct ptlrpc_request *req;
890 char *bufs[2] = {key, val};
891 int rc, size[2] = {keylen, vallen};
893 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
894 OST_SET_INFO, 2, size, bufs);
898 req->rq_replen = lustre_msg_size(0, NULL);
899 rc = ptlrpc_queue_wait(req);
900 ptlrpc_req_finished(req);
902 } else if (keylen >= strlen("inter_mds") && strcmp(key, "inter_mds") == 0) {
903 struct obd_import *imp = class_exp2cliimp(exp);
904 imp->imp_server_timeout = 1;
905 CDEBUG(D_OTHER, "%s: timeout / 2\n", exp->exp_obd->obd_name);
907 } else if (keylen == strlen("sec") &&
908 memcmp(key, "sec", keylen) == 0) {
909 struct client_obd *cli = &exp->exp_obd->u.cli;
911 cli->cl_sec_flavor = ptlrpcs_name2flavor(val);
912 if (cli->cl_sec_flavor == PTLRPCS_FLVR_INVALID) {
913 CERROR("unrecognized security type %s\n", (char*) val);
918 } else if (keylen == strlen("sec_flags") &&
919 memcmp(key, "sec_flags", keylen) == 0) {
920 struct client_obd *cli = &exp->exp_obd->u.cli;
922 cli->cl_sec_flags = *((unsigned long *) val);
924 } else if (keylen == strlen("flush_cred") &&
925 memcmp(key, "flush_cred", keylen) == 0) {
926 struct client_obd *cli = &exp->exp_obd->u.cli;
929 ptlrpcs_import_flush_current_creds(cli->cl_import);
931 } else if (keylen == strlen("async") && memcmp(key, "async", keylen) == 0) {
932 struct client_obd *cl = &exp->exp_obd->u.cli;
933 if (vallen != sizeof(int))
935 cl->cl_async = *(int *)val;
936 CDEBUG(D_HA, "%s: set async = %d\n",
937 exp->exp_obd->obd_name, cl->cl_async);
939 } else if (keylen == strlen("setext") && memcmp(key, "setext", keylen) == 0) {
940 struct ptlrpc_request *req;
941 char *bufs[2] = {key, val};
942 int rc, size[2] = {keylen, vallen};
944 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
945 OST_SET_INFO, 2, size, bufs);
949 req->rq_replen = lustre_msg_size(0, NULL);
950 rc = ptlrpc_queue_wait(req);
951 ptlrpc_req_finished(req);
953 } else if (keylen == 5 && strcmp(key, "audit") == 0) {
954 struct ptlrpc_request *req;
955 char *bufs[2] = {key, val};
956 int rc, size[2] = {keylen, vallen};
958 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
959 OST_SET_INFO, 2, size, bufs);
963 req->rq_replen = lustre_msg_size(0, NULL);
964 lustre_swab_reqbuf(req, 1, sizeof(struct audit_attr_msg),
965 lustre_swab_audit_attr);
966 rc = ptlrpc_queue_wait(req);
967 ptlrpc_req_finished(req);
970 } else if (keylen == strlen("ids") && memcmp(key, "ids", keylen) == 0) {
971 struct ptlrpc_request *req;
972 struct lustre_id *ids = (struct lustre_id *)val;
973 char *bufs[3] = {key, (char *)ids, (char *)(ids + 1)};
974 int rc, size[3] = {keylen, sizeof(struct lustre_id),
975 sizeof(struct lustre_id)};
977 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
978 OST_SET_INFO, 3, size, bufs);
982 req->rq_replen = lustre_msg_size(0, NULL);
983 rc = ptlrpc_queue_wait(req);
984 ptlrpc_req_finished(req);
990 static int mdc_statfs(struct obd_device *obd, struct obd_statfs *osfs,
991 unsigned long max_age)
993 struct obd_statfs *msfs;
994 struct ptlrpc_request *req;
995 int rc, size = sizeof(*msfs);
998 /* We could possibly pass max_age in the request (as an absolute
999 * timestamp or a "seconds.usec ago") so the target can avoid doing
1000 * extra calls into the filesystem if that isn't necessary (e.g.
1001 * during mount that would help a bit). Having relative timestamps
1002 * is not so great if request processing is slow, while absolute
1003 * timestamps are not ideal because they need time synchronization. */
1004 req = ptlrpc_prep_req(obd->u.cli.cl_import, LUSTRE_MDS_VERSION,
1005 MDS_STATFS, 0, NULL, NULL);
1009 req->rq_replen = lustre_msg_size(1, &size);
1011 mdc_get_rpc_lock(obd->u.cli.cl_rpc_lock, NULL);
1012 rc = ptlrpc_queue_wait(req);
1013 mdc_put_rpc_lock(obd->u.cli.cl_rpc_lock, NULL);
1016 /* this can be LMV fake import, whcih is not connected. */
1017 if (!req->rq_import->imp_connection)
1018 memset(osfs, 0, sizeof(*osfs));
1022 msfs = lustre_swab_repbuf(req, 0, sizeof(*msfs),
1023 lustre_swab_obd_statfs);
1025 CERROR("Can't unpack obd_statfs\n");
1026 GOTO(out, rc = -EPROTO);
1029 memcpy(osfs, msfs, sizeof (*msfs));
1032 ptlrpc_req_finished(req);
1036 static int mdc_pin(struct obd_export *exp, obd_id ino, __u32 gen, int type,
1037 struct obd_client_handle *handle, int flag)
1039 struct ptlrpc_request *req;
1040 struct mds_body *body;
1041 int rc, size[2] = {0, sizeof(*body)};
1044 //size[0] = lustre_secdesc_size();
1046 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1047 MDS_PIN, 2, size, NULL);
1051 //lustre_pack_secdesc(req, size[0]);
1053 body = lustre_msg_buf(req->rq_reqmsg,
1054 MDS_REQ_REC_OFF, sizeof(*body));
1056 /* FIXME-UMKA: here should be also mdsnum and fid. */
1057 mdc_pack_id(&body->id1, ino, gen, type, 0, 0);
1060 req->rq_replen = lustre_msg_size(1, &size[1]);
1062 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1063 rc = ptlrpc_queue_wait(req);
1064 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1066 CERROR("pin failed: %d\n", rc);
1067 ptlrpc_req_finished(req);
1071 body = lustre_swab_repbuf(req, 0, sizeof(*body), lustre_swab_mds_body);
1073 ptlrpc_req_finished(req);
1077 memcpy(&handle->och_fh, &body->handle, sizeof(body->handle));
1078 handle->och_magic = OBD_CLIENT_HANDLE_MAGIC;
1080 OBD_ALLOC(handle->och_mod, sizeof(*handle->och_mod));
1081 if (handle->och_mod == NULL) {
1082 DEBUG_REQ(D_ERROR, req, "can't allocate mdc_open_data");
1085 handle->och_mod->mod_open_req = req; /* will be dropped by unpin */
1090 static int mdc_unpin(struct obd_export *exp,
1091 struct obd_client_handle *handle, int flag)
1093 struct ptlrpc_request *req;
1094 struct mds_body *body;
1095 int rc, size[2] = {0, sizeof(*body)};
1098 if (handle->och_magic != OBD_CLIENT_HANDLE_MAGIC)
1101 //size[0] = lustre_secdesc_size();
1103 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1104 MDS_CLOSE, 2, size, NULL);
1108 //lustre_pack_secdesc(req, size[0]);
1110 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof(*body));
1111 memcpy(&body->handle, &handle->och_fh, sizeof(body->handle));
1114 req->rq_replen = lustre_msg_size(0, NULL);
1115 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1116 rc = ptlrpc_queue_wait(req);
1117 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1120 CERROR("unpin failed: %d\n", rc);
1122 ptlrpc_req_finished(req);
1123 ptlrpc_req_finished(handle->och_mod->mod_open_req);
1124 OBD_FREE(handle->och_mod, sizeof(*handle->och_mod));
1128 int mdc_sync(struct obd_export *exp, struct lustre_id *id,
1129 struct ptlrpc_request **request)
1131 struct ptlrpc_request *req;
1132 struct mds_body *body;
1133 int size[2] = {0, sizeof(*body)};
1137 //size[0] = lustre_secdesc_size();
1139 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1140 MDS_SYNC, 2, size, NULL);
1142 RETURN(rc = -ENOMEM);
1144 //lustre_pack_secdesc(req, size[0]);
1147 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF,
1149 memcpy(&body->id1, id, sizeof(*id));
1152 req->rq_replen = lustre_msg_size(1, &size[1]);
1154 rc = ptlrpc_queue_wait(req);
1155 if (rc || request == NULL)
1156 ptlrpc_req_finished(req);
1163 static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
1164 enum obd_import_event event)
1168 LASSERT(imp->imp_obd == obd);
1171 case IMP_EVENT_DISCON: {
1174 case IMP_EVENT_INACTIVE: {
1175 if (obd->obd_observer)
1176 rc = obd_notify(obd->obd_observer, obd, 0, 0);
1179 case IMP_EVENT_INVALIDATE: {
1180 struct ldlm_namespace *ns = obd->obd_namespace;
1182 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
1186 case IMP_EVENT_ACTIVE: {
1187 if (obd->obd_observer)
1188 rc = obd_notify(obd->obd_observer, obd, 1, 0);
1192 CERROR("Unknown import event %d\n", event);
1198 static int mdc_attach(struct obd_device *dev, obd_count len, void *data)
1200 struct lprocfs_static_vars lvars;
1202 lprocfs_init_vars(mdc, &lvars);
1203 return lprocfs_obd_attach(dev, lvars.obd_vars);
1206 static int mdc_detach(struct obd_device *dev)
1208 return lprocfs_obd_detach(dev);
1211 static int mdc_setup(struct obd_device *obd, obd_count len, void *buf)
1213 struct client_obd *cli = &obd->u.cli;
1217 OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1218 if (!cli->cl_rpc_lock)
1220 mdc_init_rpc_lock(cli->cl_rpc_lock);
1224 OBD_ALLOC(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1225 if (!cli->cl_setattr_lock)
1226 GOTO(err_rpc_lock, rc = -ENOMEM);
1227 mdc_init_rpc_lock(cli->cl_setattr_lock);
1229 OBD_ALLOC(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1230 if (!cli->cl_close_lock)
1231 GOTO(err_setattr_lock, rc = -ENOMEM);
1232 mdc_init_rpc_lock(cli->cl_close_lock);
1234 rc = client_obd_setup(obd, len, buf);
1236 GOTO(err_close_lock, rc);
1238 rc = obd_llog_init(obd, &obd->obd_llogs, obd, 0, NULL);
1240 mdc_cleanup(obd, 0);
1241 CERROR("failed to setup llogging subsystems\n");
1247 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1249 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1251 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1256 static int mdc_init_ea_size(struct obd_export *exp, int easize, int cookiesize)
1258 struct obd_device *obd = exp->exp_obd;
1259 struct client_obd *cli = &obd->u.cli;
1262 if (cli->cl_max_mds_easize < easize)
1263 cli->cl_max_mds_easize = easize;
1264 if (cli->cl_max_mds_cookiesize < cookiesize)
1265 cli->cl_max_mds_cookiesize = cookiesize;
1269 static int mdc_precleanup(struct obd_device *obd, int flags)
1273 rc = obd_llog_finish(obd, &obd->obd_llogs, 0);
1275 CERROR("failed to cleanup llogging subsystems\n");
1280 static int mdc_cleanup(struct obd_device *obd, int flags)
1282 struct client_obd *cli = &obd->u.cli;
1284 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1285 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1286 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1290 return client_obd_cleanup(obd, flags);
1294 static int mdc_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
1295 struct obd_device *tgt, int count,
1296 struct llog_catid *logid)
1298 struct llog_ctxt *ctxt;
1302 rc = obd_llog_setup(obd, llogs, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
1305 ctxt = llog_get_context(llogs, LLOG_CONFIG_REPL_CTXT);
1306 ctxt->loc_imp = obd->u.cli.cl_import;
1312 static int mdc_llog_finish(struct obd_device *obd,
1313 struct obd_llogs *llogs, int count)
1318 rc = obd_llog_cleanup(llog_get_context(llogs, LLOG_CONFIG_REPL_CTXT));
1321 static struct obd_device *mdc_get_real_obd(struct obd_export *exp,
1322 struct lustre_id *id)
1325 RETURN(exp->exp_obd);
1328 static int mdc_get_info(struct obd_export *exp, __u32 keylen,
1329 void *key, __u32 *valsize, void *val)
1331 struct ptlrpc_request *req;
1332 char *bufs[1] = {key};
1336 if (!valsize || !val)
1339 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
1340 struct obd_import *imp;
1341 struct obd_connect_data *data;
1343 imp = class_exp2cliimp(exp);
1349 if (imp->imp_state != LUSTRE_IMP_FULL) {
1350 CERROR("import state not full\n");
1354 data = &imp->imp_connect_data;
1355 if (data->ocd_connect_flags & OBD_CONNECT_REMOTE) {
1358 } else if (data->ocd_connect_flags & OBD_CONNECT_LOCAL) {
1362 CERROR("no remote flag set?\n");
1366 if ((keylen < strlen("mdsize") || strcmp(key, "mdsize") != 0) &&
1367 (keylen < strlen("mdsnum") || strcmp(key, "mdsnum") != 0) &&
1368 (keylen < strlen("lovdesc") || strcmp(key, "lovdesc") != 0) &&
1369 (keylen < strlen("getext") || strcmp(key, "getext") != 0) &&
1370 (keylen < strlen("rootid") || strcmp(key, "rootid") != 0) &&
1371 (keylen < strlen("auditid") || strcmp(key, "auditid") != 0))
1374 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1375 OST_GET_INFO, 1, (int *)&keylen, bufs);
1379 req->rq_replen = lustre_msg_size(1, (int *)valsize);
1380 rc = ptlrpc_queue_wait(req);
1384 if ((keylen >= strlen("rootid") && !strcmp(key, "rootid")) ||
1385 (keylen >= strlen("auditid") && !strcmp(key, "auditid"))) {
1386 struct lustre_id *reply;
1388 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
1389 lustre_swab_lustre_id);
1390 if (reply == NULL) {
1391 CERROR("Can't unpack %s\n", (char *)key);
1392 GOTO(out_req, rc = -EPROTO);
1395 *(struct lustre_id *)val = *reply;
1396 } else if (keylen >= strlen("lovdesc") && !strcmp(key, "lovdesc")) {
1397 struct lov_desc *reply;
1399 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
1400 lustre_swab_lov_desc);
1401 if (reply == NULL) {
1402 CERROR("Can't unpack %s\n", (char *)key);
1403 GOTO(out_req, rc = -EPROTO);
1406 *(struct lov_desc *)val = *reply;
1408 } else if (keylen >= strlen("getext") && !strcmp(key, "getext")) {
1409 struct fid_extent *reply;
1411 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
1412 lustre_swab_fid_extent);
1413 if (reply == NULL) {
1414 CERROR("Can't unpack %s\n", (char *)key);
1415 GOTO(out_req, rc = -EPROTO);
1418 *(struct fid_extent *)val = *reply;
1423 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
1424 lustre_swab_generic_32s);
1425 if (reply == NULL) {
1426 CERROR("Can't unpack %s\n", (char *)key);
1427 GOTO(out_req, rc = -EPROTO);
1429 *((__u32 *)val) = *reply;
1432 ptlrpc_req_finished(req);
1436 int mdc_obj_create(struct obd_export *exp, struct obdo *oa,
1437 void *acl, int acl_size,
1438 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1440 struct ptlrpc_request *request;
1441 struct ost_body *body;
1443 int rc, size[2] = { sizeof(*body), acl_size };
1448 request = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1449 OST_CREATE, 2, size, NULL);
1451 GOTO(out_req, rc = -ENOMEM);
1453 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
1454 memcpy(&body->oa, oa, sizeof(body->oa));
1457 acl_buf = lustre_msg_buf(request->rq_reqmsg, 1, acl_size);
1458 memcpy(acl_buf, acl, acl_size);
1461 request->rq_replen = lustre_msg_size(1, size);
1462 rc = ptlrpc_queue_wait(request);
1466 body = lustre_swab_repbuf(request, 0, sizeof(*body),
1467 lustre_swab_ost_body);
1469 CERROR ("can't unpack ost_body\n");
1470 GOTO (out_req, rc = -EPROTO);
1473 memcpy(oa, &body->oa, sizeof(*oa));
1475 /* store ino/generation for recovery */
1476 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
1477 body->oa.o_id = oa->o_id;
1478 body->oa.o_generation = oa->o_generation;
1479 body->oa.o_fid = oa->o_fid;
1480 body->oa.o_mds = oa->o_mds;
1482 CDEBUG(D_HA, "transno: "LPD64"\n", request->rq_repmsg->transno);
1485 ptlrpc_req_finished(request);
1489 int mdc_brw(int rw, struct obd_export *exp, struct obdo *oa,
1490 struct lov_stripe_md *ea, obd_count oa_bufs,
1491 struct brw_page *pgarr, struct obd_trans_info *oti)
1493 struct ptlrpc_bulk_desc *desc;
1494 struct niobuf_remote *niobuf;
1495 struct ptlrpc_request *req;
1496 struct obd_ioobj *ioobj;
1497 struct ost_body *body;
1501 opc = ((rw & OBD_BRW_WRITE) != 0) ? OST_WRITE : OST_READ;
1503 size[0] = sizeof(*body);
1504 size[1] = sizeof(*ioobj);
1505 size[2] = oa_bufs * sizeof(*niobuf);
1507 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION, opc,
1509 LASSERT(req != NULL);
1511 if (opc == OST_WRITE)
1512 desc = ptlrpc_prep_bulk_imp(req, oa_bufs, BULK_GET_SOURCE,
1515 desc = ptlrpc_prep_bulk_imp(req, oa_bufs, BULK_PUT_SINK,
1517 LASSERT(desc != NULL);
1519 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
1520 ioobj = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*ioobj));
1521 niobuf = lustre_msg_buf(req->rq_reqmsg, 2, oa_bufs * sizeof(*niobuf));
1523 memcpy(&body->oa, oa, sizeof(*oa));
1524 obdo_to_ioobj(oa, ioobj);
1525 ioobj->ioo_bufcnt = oa_bufs;
1527 for (i = 0; i < oa_bufs; i++, niobuf++) {
1528 struct brw_page *pg = &pgarr[i];
1530 LASSERT(pg->count > 0);
1531 LASSERT((pg->disk_offset & ~PAGE_MASK) + pg->count <= PAGE_SIZE);
1533 ptlrpc_prep_bulk_page(desc, pg->pg, pg->disk_offset & ~PAGE_MASK,
1536 niobuf->offset = pg->disk_offset;
1537 niobuf->len = pg->count;
1538 niobuf->flags = pg->flag;
1541 /* size[0] still sizeof (*body) */
1542 if (opc == OST_WRITE) {
1543 /* 1 RC per niobuf */
1544 size[1] = sizeof(__u32) * oa_bufs;
1545 req->rq_replen = lustre_msg_size(2, size);
1547 /* 1 RC for the whole I/O */
1548 req->rq_replen = lustre_msg_size(1, size);
1550 err = ptlrpc_queue_wait(req);
1553 ptlrpc_req_finished(req);
1557 static int mdc_valid_attrs(struct obd_export *exp,
1558 struct lustre_id *id)
1560 struct ldlm_res_id res_id = { .name = {0} };
1561 struct obd_device *obd = exp->exp_obd;
1562 struct lustre_handle lockh;
1563 ldlm_policy_data_t policy;
1567 res_id.name[0] = id_fid(id);
1568 res_id.name[1] = id_group(id);
1569 policy.l_inodebits.bits = MDS_INODELOCK_UPDATE;
1571 CDEBUG(D_INFO, "trying to match res "LPU64"\n",
1574 /* FIXME use LDLM_FL_TEST_LOCK instead */
1575 flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_CBPENDING;
1576 if (ldlm_lock_match(obd->obd_namespace, flags, &res_id,
1577 LDLM_IBITS, &policy, LCK_PR, &lockh)) {
1578 ldlm_lock_decref(&lockh, LCK_PR);
1582 if (ldlm_lock_match(obd->obd_namespace, flags, &res_id,
1583 LDLM_IBITS, &policy, LCK_PW, &lockh)) {
1584 ldlm_lock_decref(&lockh, LCK_PW);
1590 static int mdc_change_cbdata_name(struct obd_export *exp,
1591 struct lustre_id *pid,
1592 char *name, int len,
1593 struct lustre_id *cid,
1594 ldlm_iterator_t it, void *data)
1597 rc = mdc_change_cbdata(exp, cid, it, data);
1601 struct obd_ops mdc_obd_ops = {
1602 .o_owner = THIS_MODULE,
1603 .o_attach = mdc_attach,
1604 .o_detach = mdc_detach,
1605 .o_setup = mdc_setup,
1606 .o_precleanup = mdc_precleanup,
1607 .o_cleanup = mdc_cleanup,
1608 .o_add_conn = client_import_add_conn,
1609 .o_del_conn = client_import_del_conn,
1610 .o_connect = client_connect_import,
1611 .o_disconnect = client_disconnect_export,
1612 .o_iocontrol = mdc_iocontrol,
1613 .o_packmd = mdc_packmd,
1614 .o_unpackmd = mdc_unpackmd,
1615 .o_statfs = mdc_statfs,
1617 .o_unpin = mdc_unpin,
1618 .o_import_event = mdc_import_event,
1619 .o_llog_init = mdc_llog_init,
1620 .o_llog_finish = mdc_llog_finish,
1621 .o_create = mdc_obj_create,
1622 .o_set_info = mdc_set_info,
1623 .o_get_info = mdc_get_info,
1625 .o_cancel_unused = mdc_cancel_unused,
1626 .o_init_ea_size = mdc_init_ea_size,
1629 struct md_ops mdc_md_ops = {
1630 .m_getstatus = mdc_getstatus,
1631 .m_getattr = mdc_getattr,
1632 .m_close = mdc_close,
1633 .m_create = mdc_create,
1634 .m_done_writing = mdc_done_writing,
1635 .m_enqueue = mdc_enqueue,
1636 .m_getattr_lock = mdc_getattr_lock,
1637 .m_intent_lock = mdc_intent_lock,
1639 .m_rename = mdc_rename,
1640 .m_setattr = mdc_setattr,
1642 .m_readpage = mdc_readpage,
1643 .m_unlink = mdc_unlink,
1644 .m_valid_attrs = mdc_valid_attrs,
1645 .m_req2lustre_md = mdc_req2lustre_md,
1646 .m_set_open_replay_data = mdc_set_open_replay_data,
1647 .m_clear_open_replay_data = mdc_clear_open_replay_data,
1648 .m_store_inode_generation = mdc_store_inode_generation,
1649 .m_set_lock_data = mdc_set_lock_data,
1650 .m_get_real_obd = mdc_get_real_obd,
1651 .m_change_cbdata_name = mdc_change_cbdata_name,
1652 .m_change_cbdata = mdc_change_cbdata,
1653 .m_access_check = mdc_access_check,
1656 int __init mdc_init(void)
1658 struct lprocfs_static_vars lvars;
1660 lprocfs_init_vars(mdc, &lvars);
1661 return class_register_type(&mdc_obd_ops, &mdc_md_ops,
1662 lvars.module_vars, OBD_MDC_DEVICENAME);
1666 static void /*__exit*/ mdc_exit(void)
1668 class_unregister_type(OBD_MDC_DEVICENAME);
1671 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1672 MODULE_DESCRIPTION("Lustre Metadata Client");
1673 MODULE_LICENSE("GPL");
1675 EXPORT_SYMBOL(mdc_req2lustre_md);
1676 EXPORT_SYMBOL(mdc_change_cbdata);
1677 EXPORT_SYMBOL(mdc_getstatus);
1678 EXPORT_SYMBOL(mdc_getattr);
1679 EXPORT_SYMBOL(mdc_getattr_lock);
1680 EXPORT_SYMBOL(mdc_create);
1681 EXPORT_SYMBOL(mdc_unlink);
1682 EXPORT_SYMBOL(mdc_rename);
1683 EXPORT_SYMBOL(mdc_link);
1684 EXPORT_SYMBOL(mdc_readpage);
1685 EXPORT_SYMBOL(mdc_setattr);
1686 EXPORT_SYMBOL(mdc_close);
1687 EXPORT_SYMBOL(mdc_done_writing);
1688 EXPORT_SYMBOL(mdc_sync);
1689 EXPORT_SYMBOL(mdc_set_open_replay_data);
1690 EXPORT_SYMBOL(mdc_clear_open_replay_data);
1691 EXPORT_SYMBOL(mdc_store_inode_generation);
1693 module_init(mdc_init);
1694 module_exit(mdc_exit);