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 ptlrpc_request *open_req;
606 struct obd_import *imp = req->rq_import;
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 == 5 && strcmp(key, "audit") == 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 lustre_swab_reqbuf(req, 1, sizeof(struct audit_attr_msg),
951 lustre_swab_audit_attr);
952 rc = ptlrpc_queue_wait(req);
953 ptlrpc_req_finished(req);
956 } else if (keylen == strlen("ids") && memcmp(key, "ids", keylen) == 0) {
957 struct ptlrpc_request *req;
958 struct lustre_id *ids = (struct lustre_id *)val;
959 char *bufs[3] = {key, (char *)ids, (char *)(ids + 1)};
960 int rc, size[3] = {keylen, sizeof(struct lustre_id),
961 sizeof(struct lustre_id)};
963 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
964 OST_SET_INFO, 3, size, bufs);
968 req->rq_replen = lustre_msg_size(0, NULL);
969 rc = ptlrpc_queue_wait(req);
970 ptlrpc_req_finished(req);
976 static int mdc_statfs(struct obd_device *obd, struct obd_statfs *osfs,
977 unsigned long max_age)
979 struct obd_statfs *msfs;
980 struct ptlrpc_request *req;
981 int rc, size = sizeof(*msfs);
984 /* We could possibly pass max_age in the request (as an absolute
985 * timestamp or a "seconds.usec ago") so the target can avoid doing
986 * extra calls into the filesystem if that isn't necessary (e.g.
987 * during mount that would help a bit). Having relative timestamps
988 * is not so great if request processing is slow, while absolute
989 * timestamps are not ideal because they need time synchronization. */
990 req = ptlrpc_prep_req(obd->u.cli.cl_import, LUSTRE_MDS_VERSION,
991 MDS_STATFS, 0, NULL, NULL);
995 req->rq_replen = lustre_msg_size(1, &size);
997 mdc_get_rpc_lock(obd->u.cli.cl_rpc_lock, NULL);
998 rc = ptlrpc_queue_wait(req);
999 mdc_put_rpc_lock(obd->u.cli.cl_rpc_lock, NULL);
1002 /* this can be LMV fake import, whcih is not connected. */
1003 if (!req->rq_import->imp_connection)
1004 memset(osfs, 0, sizeof(*osfs));
1008 msfs = lustre_swab_repbuf(req, 0, sizeof(*msfs),
1009 lustre_swab_obd_statfs);
1011 CERROR("Can't unpack obd_statfs\n");
1012 GOTO(out, rc = -EPROTO);
1015 memcpy(osfs, msfs, sizeof (*msfs));
1018 ptlrpc_req_finished(req);
1022 static int mdc_pin(struct obd_export *exp, obd_id ino, __u32 gen, int type,
1023 struct obd_client_handle *handle, int flag)
1025 struct ptlrpc_request *req;
1026 struct mds_body *body;
1027 int rc, size[2] = {0, sizeof(*body)};
1030 //size[0] = lustre_secdesc_size();
1032 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1033 MDS_PIN, 2, size, NULL);
1037 //lustre_pack_secdesc(req, size[0]);
1039 body = lustre_msg_buf(req->rq_reqmsg,
1040 MDS_REQ_REC_OFF, sizeof(*body));
1042 /* FIXME-UMKA: here should be also mdsnum and fid. */
1043 mdc_pack_id(&body->id1, ino, gen, type, 0, 0);
1046 req->rq_replen = lustre_msg_size(1, &size[1]);
1048 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1049 rc = ptlrpc_queue_wait(req);
1050 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1052 CERROR("pin failed: %d\n", rc);
1053 ptlrpc_req_finished(req);
1057 body = lustre_swab_repbuf(req, 0, sizeof(*body), lustre_swab_mds_body);
1059 ptlrpc_req_finished(req);
1063 memcpy(&handle->och_fh, &body->handle, sizeof(body->handle));
1064 handle->och_magic = OBD_CLIENT_HANDLE_MAGIC;
1066 OBD_ALLOC(handle->och_mod, sizeof(*handle->och_mod));
1067 if (handle->och_mod == NULL) {
1068 DEBUG_REQ(D_ERROR, req, "can't allocate mdc_open_data");
1071 handle->och_mod->mod_open_req = req; /* will be dropped by unpin */
1076 static int mdc_unpin(struct obd_export *exp,
1077 struct obd_client_handle *handle, int flag)
1079 struct ptlrpc_request *req;
1080 struct mds_body *body;
1081 int rc, size[2] = {0, sizeof(*body)};
1084 if (handle->och_magic != OBD_CLIENT_HANDLE_MAGIC)
1087 //size[0] = lustre_secdesc_size();
1089 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1090 MDS_CLOSE, 2, size, NULL);
1094 //lustre_pack_secdesc(req, size[0]);
1096 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof(*body));
1097 memcpy(&body->handle, &handle->och_fh, sizeof(body->handle));
1100 req->rq_replen = lustre_msg_size(0, NULL);
1101 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1102 rc = ptlrpc_queue_wait(req);
1103 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1106 CERROR("unpin failed: %d\n", rc);
1108 ptlrpc_req_finished(req);
1109 ptlrpc_req_finished(handle->och_mod->mod_open_req);
1110 OBD_FREE(handle->och_mod, sizeof(*handle->och_mod));
1114 int mdc_sync(struct obd_export *exp, struct lustre_id *id,
1115 struct ptlrpc_request **request)
1117 struct ptlrpc_request *req;
1118 struct mds_body *body;
1119 int size[2] = {0, sizeof(*body)};
1123 //size[0] = lustre_secdesc_size();
1125 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1126 MDS_SYNC, 2, size, NULL);
1128 RETURN(rc = -ENOMEM);
1130 //lustre_pack_secdesc(req, size[0]);
1133 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF,
1135 memcpy(&body->id1, id, sizeof(*id));
1138 req->rq_replen = lustre_msg_size(1, &size[1]);
1140 rc = ptlrpc_queue_wait(req);
1141 if (rc || request == NULL)
1142 ptlrpc_req_finished(req);
1149 static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
1150 enum obd_import_event event)
1154 LASSERT(imp->imp_obd == obd);
1157 case IMP_EVENT_DISCON: {
1160 case IMP_EVENT_INACTIVE: {
1161 if (obd->obd_observer)
1162 rc = obd_notify(obd->obd_observer, obd, 0, 0);
1165 case IMP_EVENT_INVALIDATE: {
1166 struct ldlm_namespace *ns = obd->obd_namespace;
1168 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
1172 case IMP_EVENT_ACTIVE: {
1173 if (obd->obd_observer)
1174 rc = obd_notify(obd->obd_observer, obd, 1, 0);
1178 CERROR("Unknown import event %d\n", event);
1184 static int mdc_attach(struct obd_device *dev, obd_count len, void *data)
1186 struct lprocfs_static_vars lvars;
1188 lprocfs_init_vars(mdc, &lvars);
1189 return lprocfs_obd_attach(dev, lvars.obd_vars);
1192 static int mdc_detach(struct obd_device *dev)
1194 return lprocfs_obd_detach(dev);
1197 static int mdc_setup(struct obd_device *obd, obd_count len, void *buf)
1199 struct client_obd *cli = &obd->u.cli;
1203 OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1204 if (!cli->cl_rpc_lock)
1206 mdc_init_rpc_lock(cli->cl_rpc_lock);
1210 OBD_ALLOC(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1211 if (!cli->cl_setattr_lock)
1212 GOTO(err_rpc_lock, rc = -ENOMEM);
1213 mdc_init_rpc_lock(cli->cl_setattr_lock);
1215 OBD_ALLOC(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1216 if (!cli->cl_close_lock)
1217 GOTO(err_setattr_lock, rc = -ENOMEM);
1218 mdc_init_rpc_lock(cli->cl_close_lock);
1220 rc = client_obd_setup(obd, len, buf);
1222 GOTO(err_close_lock, rc);
1224 rc = obd_llog_init(obd, &obd->obd_llogs, obd, 0, NULL);
1226 mdc_cleanup(obd, 0);
1227 CERROR("failed to setup llogging subsystems\n");
1233 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1235 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1237 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1242 static int mdc_init_ea_size(struct obd_export *exp, int easize, int cookiesize)
1244 struct obd_device *obd = exp->exp_obd;
1245 struct client_obd *cli = &obd->u.cli;
1248 if (cli->cl_max_mds_easize < easize)
1249 cli->cl_max_mds_easize = easize;
1250 if (cli->cl_max_mds_cookiesize < cookiesize)
1251 cli->cl_max_mds_cookiesize = cookiesize;
1255 static int mdc_precleanup(struct obd_device *obd, int flags)
1259 rc = obd_llog_finish(obd, &obd->obd_llogs, 0);
1261 CERROR("failed to cleanup llogging subsystems\n");
1266 static int mdc_cleanup(struct obd_device *obd, int flags)
1268 struct client_obd *cli = &obd->u.cli;
1270 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1271 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1272 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1276 return client_obd_cleanup(obd, flags);
1280 static int mdc_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
1281 struct obd_device *tgt, int count,
1282 struct llog_catid *logid)
1284 struct llog_ctxt *ctxt;
1288 rc = obd_llog_setup(obd, llogs, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
1291 ctxt = llog_get_context(llogs, LLOG_CONFIG_REPL_CTXT);
1292 ctxt->loc_imp = obd->u.cli.cl_import;
1298 static int mdc_llog_finish(struct obd_device *obd,
1299 struct obd_llogs *llogs, int count)
1304 rc = obd_llog_cleanup(llog_get_context(llogs, LLOG_CONFIG_REPL_CTXT));
1307 static struct obd_device *mdc_get_real_obd(struct obd_export *exp,
1308 struct lustre_id *id)
1311 RETURN(exp->exp_obd);
1314 static int mdc_get_info(struct obd_export *exp, __u32 keylen,
1315 void *key, __u32 *valsize, void *val)
1317 struct ptlrpc_request *req;
1318 char *bufs[1] = {key};
1322 if (!valsize || !val)
1325 if (keylen == strlen("remote_flag") && !strcmp(key, "remote_flag")) {
1326 struct obd_import *imp;
1327 struct obd_connect_data *data;
1329 imp = class_exp2cliimp(exp);
1335 if (imp->imp_state != LUSTRE_IMP_FULL) {
1336 CERROR("import state not full\n");
1340 data = &imp->imp_connect_data;
1341 if (data->ocd_connect_flags & OBD_CONNECT_REMOTE) {
1344 } else if (data->ocd_connect_flags & OBD_CONNECT_LOCAL) {
1348 CERROR("no remote flag set?\n");
1352 if ((keylen < strlen("mdsize") || strcmp(key, "mdsize") != 0) &&
1353 (keylen < strlen("mdsnum") || strcmp(key, "mdsnum") != 0) &&
1354 (keylen < strlen("rootid") || strcmp(key, "rootid") != 0) &&
1355 (keylen < strlen("auditid") || strcmp(key, "auditid") != 0))
1358 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1359 OST_GET_INFO, 1, (int *)&keylen, bufs);
1363 req->rq_replen = lustre_msg_size(1, (int *)valsize);
1364 rc = ptlrpc_queue_wait(req);
1368 if ((keylen >= strlen("rootid") && !strcmp(key, "rootid")) ||
1369 (keylen >= strlen("auditid") && !strcmp(key, "auditid"))) {
1370 struct lustre_id *reply;
1372 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
1373 lustre_swab_lustre_id);
1374 if (reply == NULL) {
1375 CERROR("Can't unpack %s\n", (char *)key);
1376 GOTO(out_req, rc = -EPROTO);
1379 *(struct lustre_id *)val = *reply;
1380 } else if (keylen >= strlen("lovdesc") && !strcmp(key, "lovdesc")) {
1381 struct lov_desc *reply;
1383 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
1384 lustre_swab_lov_desc);
1385 if (reply == NULL) {
1386 CERROR("Can't unpack %s\n", (char *)key);
1387 GOTO(out_req, rc = -EPROTO);
1390 *(struct lov_desc *)val = *reply;
1395 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
1396 lustre_swab_generic_32s);
1397 if (reply == NULL) {
1398 CERROR("Can't unpack %s\n", (char *)key);
1399 GOTO(out_req, rc = -EPROTO);
1401 *((__u32 *)val) = *reply;
1404 ptlrpc_req_finished(req);
1408 int mdc_obj_create(struct obd_export *exp, struct obdo *oa,
1409 void *acl, int acl_size,
1410 struct lov_stripe_md **ea, struct obd_trans_info *oti)
1412 struct ptlrpc_request *request;
1413 struct ost_body *body;
1415 int rc, size[2] = { sizeof(*body), acl_size };
1420 request = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1421 OST_CREATE, 2, size, NULL);
1423 GOTO(out_req, rc = -ENOMEM);
1425 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
1426 memcpy(&body->oa, oa, sizeof(body->oa));
1429 acl_buf = lustre_msg_buf(request->rq_reqmsg, 1, acl_size);
1430 memcpy(acl_buf, acl, acl_size);
1433 request->rq_replen = lustre_msg_size(1, size);
1434 rc = ptlrpc_queue_wait(request);
1438 body = lustre_swab_repbuf(request, 0, sizeof(*body),
1439 lustre_swab_ost_body);
1441 CERROR ("can't unpack ost_body\n");
1442 GOTO (out_req, rc = -EPROTO);
1445 memcpy(oa, &body->oa, sizeof(*oa));
1447 /* store ino/generation for recovery */
1448 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
1449 body->oa.o_id = oa->o_id;
1450 body->oa.o_generation = oa->o_generation;
1451 body->oa.o_fid = oa->o_fid;
1452 body->oa.o_mds = oa->o_mds;
1454 CDEBUG(D_HA, "transno: "LPD64"\n", request->rq_repmsg->transno);
1457 ptlrpc_req_finished(request);
1461 int mdc_brw(int rw, struct obd_export *exp, struct obdo *oa,
1462 struct lov_stripe_md *ea, obd_count oa_bufs,
1463 struct brw_page *pgarr, struct obd_trans_info *oti)
1465 struct ptlrpc_bulk_desc *desc;
1466 struct niobuf_remote *niobuf;
1467 struct ptlrpc_request *req;
1468 struct obd_ioobj *ioobj;
1469 struct ost_body *body;
1473 opc = ((rw & OBD_BRW_WRITE) != 0) ? OST_WRITE : OST_READ;
1475 size[0] = sizeof(*body);
1476 size[1] = sizeof(*ioobj);
1477 size[2] = oa_bufs * sizeof(*niobuf);
1479 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION, opc,
1481 LASSERT(req != NULL);
1483 if (opc == OST_WRITE)
1484 desc = ptlrpc_prep_bulk_imp(req, oa_bufs, BULK_GET_SOURCE,
1487 desc = ptlrpc_prep_bulk_imp(req, oa_bufs, BULK_PUT_SINK,
1489 LASSERT(desc != NULL);
1491 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
1492 ioobj = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*ioobj));
1493 niobuf = lustre_msg_buf(req->rq_reqmsg, 2, oa_bufs * sizeof(*niobuf));
1495 memcpy(&body->oa, oa, sizeof(*oa));
1496 obdo_to_ioobj(oa, ioobj);
1497 ioobj->ioo_bufcnt = oa_bufs;
1499 for (i = 0; i < oa_bufs; i++, niobuf++) {
1500 struct brw_page *pg = &pgarr[i];
1502 LASSERT(pg->count > 0);
1503 LASSERT((pg->disk_offset & ~PAGE_MASK) + pg->count <= PAGE_SIZE);
1505 ptlrpc_prep_bulk_page(desc, pg->pg, pg->disk_offset & ~PAGE_MASK,
1508 niobuf->offset = pg->disk_offset;
1509 niobuf->len = pg->count;
1510 niobuf->flags = pg->flag;
1513 /* size[0] still sizeof (*body) */
1514 if (opc == OST_WRITE) {
1515 /* 1 RC per niobuf */
1516 size[1] = sizeof(__u32) * oa_bufs;
1517 req->rq_replen = lustre_msg_size(2, size);
1519 /* 1 RC for the whole I/O */
1520 req->rq_replen = lustre_msg_size(1, size);
1522 err = ptlrpc_queue_wait(req);
1525 ptlrpc_req_finished(req);
1529 static int mdc_valid_attrs(struct obd_export *exp,
1530 struct lustre_id *id)
1532 struct ldlm_res_id res_id = { .name = {0} };
1533 struct obd_device *obd = exp->exp_obd;
1534 struct lustre_handle lockh;
1535 ldlm_policy_data_t policy;
1539 res_id.name[0] = id_fid(id);
1540 res_id.name[1] = id_group(id);
1541 policy.l_inodebits.bits = MDS_INODELOCK_UPDATE;
1543 CDEBUG(D_INFO, "trying to match res "LPU64"\n",
1546 /* FIXME use LDLM_FL_TEST_LOCK instead */
1547 flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_CBPENDING;
1548 if (ldlm_lock_match(obd->obd_namespace, flags, &res_id,
1549 LDLM_IBITS, &policy, LCK_PR, &lockh)) {
1550 ldlm_lock_decref(&lockh, LCK_PR);
1554 if (ldlm_lock_match(obd->obd_namespace, flags, &res_id,
1555 LDLM_IBITS, &policy, LCK_PW, &lockh)) {
1556 ldlm_lock_decref(&lockh, LCK_PW);
1562 static int mdc_change_cbdata_name(struct obd_export *exp,
1563 struct lustre_id *pid,
1564 char *name, int len,
1565 struct lustre_id *cid,
1566 ldlm_iterator_t it, void *data)
1569 rc = mdc_change_cbdata(exp, cid, it, data);
1573 struct obd_ops mdc_obd_ops = {
1574 .o_owner = THIS_MODULE,
1575 .o_attach = mdc_attach,
1576 .o_detach = mdc_detach,
1577 .o_setup = mdc_setup,
1578 .o_precleanup = mdc_precleanup,
1579 .o_cleanup = mdc_cleanup,
1580 .o_add_conn = client_import_add_conn,
1581 .o_del_conn = client_import_del_conn,
1582 .o_connect = client_connect_import,
1583 .o_disconnect = client_disconnect_export,
1584 .o_iocontrol = mdc_iocontrol,
1585 .o_packmd = mdc_packmd,
1586 .o_unpackmd = mdc_unpackmd,
1587 .o_statfs = mdc_statfs,
1589 .o_unpin = mdc_unpin,
1590 .o_import_event = mdc_import_event,
1591 .o_llog_init = mdc_llog_init,
1592 .o_llog_finish = mdc_llog_finish,
1593 .o_create = mdc_obj_create,
1594 .o_set_info = mdc_set_info,
1595 .o_get_info = mdc_get_info,
1597 .o_cancel_unused = mdc_cancel_unused,
1598 .o_init_ea_size = mdc_init_ea_size,
1601 struct md_ops mdc_md_ops = {
1602 .m_getstatus = mdc_getstatus,
1603 .m_getattr = mdc_getattr,
1604 .m_close = mdc_close,
1605 .m_create = mdc_create,
1606 .m_done_writing = mdc_done_writing,
1607 .m_enqueue = mdc_enqueue,
1608 .m_getattr_lock = mdc_getattr_lock,
1609 .m_intent_lock = mdc_intent_lock,
1611 .m_rename = mdc_rename,
1612 .m_setattr = mdc_setattr,
1614 .m_readpage = mdc_readpage,
1615 .m_unlink = mdc_unlink,
1616 .m_valid_attrs = mdc_valid_attrs,
1617 .m_req2lustre_md = mdc_req2lustre_md,
1618 .m_set_open_replay_data = mdc_set_open_replay_data,
1619 .m_clear_open_replay_data = mdc_clear_open_replay_data,
1620 .m_store_inode_generation = mdc_store_inode_generation,
1621 .m_set_lock_data = mdc_set_lock_data,
1622 .m_get_real_obd = mdc_get_real_obd,
1623 .m_change_cbdata_name = mdc_change_cbdata_name,
1624 .m_change_cbdata = mdc_change_cbdata,
1625 .m_access_check = mdc_access_check,
1628 int __init mdc_init(void)
1630 struct lprocfs_static_vars lvars;
1632 lprocfs_init_vars(mdc, &lvars);
1633 return class_register_type(&mdc_obd_ops, &mdc_md_ops,
1634 lvars.module_vars, OBD_MDC_DEVICENAME);
1638 static void /*__exit*/ mdc_exit(void)
1640 class_unregister_type(OBD_MDC_DEVICENAME);
1643 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1644 MODULE_DESCRIPTION("Lustre Metadata Client");
1645 MODULE_LICENSE("GPL");
1647 EXPORT_SYMBOL(mdc_req2lustre_md);
1648 EXPORT_SYMBOL(mdc_change_cbdata);
1649 EXPORT_SYMBOL(mdc_getstatus);
1650 EXPORT_SYMBOL(mdc_getattr);
1651 EXPORT_SYMBOL(mdc_getattr_lock);
1652 EXPORT_SYMBOL(mdc_create);
1653 EXPORT_SYMBOL(mdc_unlink);
1654 EXPORT_SYMBOL(mdc_rename);
1655 EXPORT_SYMBOL(mdc_link);
1656 EXPORT_SYMBOL(mdc_readpage);
1657 EXPORT_SYMBOL(mdc_setattr);
1658 EXPORT_SYMBOL(mdc_close);
1659 EXPORT_SYMBOL(mdc_done_writing);
1660 EXPORT_SYMBOL(mdc_sync);
1661 EXPORT_SYMBOL(mdc_set_open_replay_data);
1662 EXPORT_SYMBOL(mdc_clear_open_replay_data);
1663 EXPORT_SYMBOL(mdc_store_inode_generation);
1665 module_init(mdc_init);
1666 module_exit(mdc_exit);