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_INFO, 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 CDEBUG(D_INFO, "expiry %lu vs timer %lu, base %p\n",
145 expiry, ll_capa_timer.expires, ll_capa_timer.base);
146 if (time_before(expiry, ll_capa_timer.expires) ||
147 !timer_pending(&ll_capa_timer)) {
148 mod_timer(&ll_capa_timer, expiry);
149 CDEBUG(D_INFO, "ll_capa_timer new expiry: %lu\n", expiry);
151 spin_unlock(&capa_lock);
156 int mdc_getattr_async(struct obd_export *exp, struct ptlrpc_request *req)
158 int repsize[2] = {sizeof(struct mds_body), sizeof(struct lustre_capa)};
161 req->rq_replen = lustre_msg_size(2, repsize);
162 req->rq_interpret_reply = mdc_interpret_getattr;
163 ptlrpcd_add_req(req);
168 int mdc_getattr_common(struct obd_export *exp, unsigned int ea_size,
169 struct ptlrpc_request *req)
171 struct mds_body *body, *reqbody;
174 int repsize[2] = {sizeof(*body)};
178 /* request message already built */
181 repsize[bufcount++] = ea_size;
182 CDEBUG(D_INODE, "reserved %u bytes for MD/symlink in packet\n",
186 reqbody = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*reqbody));
187 LASSERT(!(reqbody->valid & OBD_MD_FLACL));
189 if (reqbody->valid & OBD_MD_FLKEY) {
190 repsize[bufcount++] = 5;
191 repsize[bufcount++] = sizeof(struct lustre_key);
192 } else if (reqbody->valid & OBD_MD_CAPA) {
193 LASSERT(ea_size == 0);
194 repsize[bufcount++] = sizeof(struct lustre_capa);
197 req->rq_replen = lustre_msg_size(bufcount, repsize);
199 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
200 rc = ptlrpc_queue_wait(req);
201 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
205 body = lustre_swab_repbuf (req, 0, sizeof (*body),
206 lustre_swab_mds_body);
208 CERROR ("Can't unpack mds_body\n");
212 CDEBUG(D_NET, "mode: %o\n", body->mode);
214 LASSERT_REPSWAB (req, 1);
216 /* Skip the check if getxattr/listxattr are called with no buffers */
217 if ((reqbody->eadatasize != 0) &&
218 !(reqbody->valid & (OBD_MD_FLXATTR | OBD_MD_FLXATTRLIST))) {
219 /* reply indicates presence of eadata; check it's there... */
220 eadata = lustre_msg_buf (req->rq_repmsg, 1,
222 if (eadata == NULL) {
223 CERROR ("Missing/short eadata\n");
231 static int mdc_cancel_unused(struct obd_export *exp,
232 struct lov_stripe_md *lsm,
233 int flags, void *opaque)
235 struct obd_device *obd = class_exp2obd(exp);
238 RETURN(ldlm_cli_cancel_unused(obd->obd_namespace,
239 NULL, flags, opaque));
242 int mdc_getattr(struct obd_export *exp, struct lustre_id *id,
243 __u64 valid, const char *xattr_name,
244 const void *xattr_data, unsigned int xattr_datalen,
245 unsigned int ea_size, struct obd_capa *ocapa,
246 struct ptlrpc_request **request)
248 struct ptlrpc_request *req;
249 struct mds_body *body;
250 int xattr_namelen = xattr_name ? strlen(xattr_name) + 1 : 0;
251 int size[4] = {0, sizeof(*body)};
256 size[0] = lustre_secdesc_size();
258 if (valid & OBD_MD_FLXATTR) {
259 size[bufcount++] = xattr_namelen;
261 if (xattr_datalen > 0) {
263 size[bufcount++] = xattr_datalen;
265 } else if (valid & OBD_MD_CAPA) {
266 LASSERT(valid == OBD_MD_CAPA);
268 size[bufcount++] = sizeof(*ocapa);
270 LASSERT(!xattr_data && !xattr_datalen);
273 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
274 MDS_GETATTR, bufcount, size, NULL);
276 GOTO(out, rc = -ENOMEM);
278 lustre_pack_secdesc(req, size[0]);
280 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof (*body));
281 memcpy(&body->id1, id, sizeof(*id));
283 body->eadatasize = ea_size;
285 if (valid & OBD_MD_FLXATTR) {
286 memcpy(lustre_msg_buf(req->rq_reqmsg, 2, xattr_namelen),
287 xattr_name, xattr_namelen);
289 memcpy(lustre_msg_buf(req->rq_reqmsg, 3, xattr_datalen),
290 xattr_data, xattr_datalen);
293 if (valid & OBD_MD_CAPA) {
294 /* renew capability */
295 memcpy(&body->handle, &ocapa->c_handle, sizeof(body->handle));
296 memcpy(lustre_msg_buf(req->rq_reqmsg, 2, sizeof(ocapa->c_capa)),
297 &ocapa->c_capa, sizeof(ocapa->c_capa));
299 rc = mdc_getattr_async(exp, req);
300 req = NULL; /* ptlrpcd will finish request */
302 rc = mdc_getattr_common(exp, ea_size, req);
304 ptlrpc_req_finished (req);
313 int mdc_access_check(struct obd_export *exp, struct lustre_id *id,
314 struct ptlrpc_request **request)
317 struct ptlrpc_request *req;
318 struct mds_body *body;
319 int size[2] = {0, sizeof(*body)};
323 size[0] = lustre_secdesc_size();
324 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
325 MDS_ACCESS_CHECK, 2, size, NULL);
327 GOTO(out, rc = -ENOMEM);
329 lustre_pack_secdesc(req, size[0]);
330 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof (*body));
331 memcpy(&body->id1, id, sizeof(*id));
333 size[0] = sizeof(*body);
334 size[1] = sizeof(struct mds_remote_perm);
335 req->rq_replen = lustre_msg_size(2, size);
337 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
338 rc = ptlrpc_queue_wait(req);
339 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
341 ptlrpc_req_finished (req);
344 body = lustre_swab_repbuf (req, 0, sizeof (*body),
345 lustre_swab_mds_body);
347 CERROR ("Can't unpack mds_body\n");
357 int mdc_getattr_lock(struct obd_export *exp, struct lustre_id *id,
358 char *filename, int namelen, __u64 valid,
359 unsigned int ea_size, struct ptlrpc_request **request)
361 struct ptlrpc_request *req;
362 struct mds_body *body;
363 int rc, size[3] = {0, sizeof(*body), namelen};
366 size[0] = lustre_secdesc_size();
368 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
369 MDS_GETATTR_LOCK, 3, size, NULL);
371 GOTO(out, rc = -ENOMEM);
373 lustre_pack_secdesc(req, size[0]);
375 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof (*body));
376 memcpy(&body->id1, id, sizeof(*id));
378 body->eadatasize = ea_size;
380 if (filename != NULL) {
381 LASSERT (strnlen (filename, namelen) == namelen - 1);
382 memcpy(lustre_msg_buf(req->rq_reqmsg, 2, namelen),
385 LASSERT(namelen == 1);
388 rc = mdc_getattr_common(exp, ea_size, req);
390 ptlrpc_req_finished (req);
398 /* This should be called with both the request and the reply still packed. */
399 int mdc_store_inode_generation(struct obd_export *exp,
400 struct ptlrpc_request *req,
401 int reqoff, int repoff)
403 struct mds_rec_create *rec =
404 lustre_msg_buf(req->rq_reqmsg, reqoff, sizeof(*rec));
405 struct mds_body *body =
406 lustre_msg_buf(req->rq_repmsg, repoff, sizeof(*body));
408 LASSERT (rec != NULL);
409 LASSERT (body != NULL);
411 memcpy(&rec->cr_replayid, &body->id1, sizeof(rec->cr_replayid));
412 DEBUG_REQ(D_HA, req, "storing generation for ino "DLID4,
413 OLID4(&rec->cr_replayid));
418 int mdc_unpack_acl(struct obd_export *exp_lmv, struct ptlrpc_request *req,
419 unsigned int offset, struct lustre_md *md)
421 struct posix_acl *acl;
422 struct mds_remote_perm *perm;
427 if (!(md->body->valid & OBD_MD_FLACL))
430 if (md->body->valid & OBD_MD_FLRMTACL) {
431 offset++; /* first 'size' is not used */
433 buf = lustre_swab_repbuf(req, offset, sizeof(*perm),
434 lustre_swab_remote_perm);
436 CERROR("Can't unpack remote perm\n");
440 OBD_ALLOC(perm, sizeof(*perm));
443 memcpy(perm, buf, sizeof(*perm));
444 md->remote_perm = perm;
446 size = le32_to_cpu(*(__u32 *) lustre_msg_buf(
447 req->rq_repmsg, offset, 4));
448 buf = lustre_msg_buf(req->rq_repmsg, offset + 1, size);
450 acl = posix_acl_from_xattr(buf, size);
453 CERROR("convert xattr to acl failed: %d\n", rc);
456 rc = posix_acl_valid(acl);
458 CERROR("acl valid error: %d\n", rc);
459 posix_acl_release(acl);
470 static int mdc_unpack_gskey(struct obd_export *exp_lmv, struct ptlrpc_request *req,
471 unsigned int *offset, struct lustre_md *md)
473 int key_off = 0, rc = 0, size = 0;
477 if (md->body->valid & OBD_MD_FLKEY) {
478 size = le32_to_cpu(*(__u32 *) lustre_msg_buf(req->rq_repmsg,
480 buf = lustre_msg_buf(req->rq_repmsg, key_off++, size);
482 CDEBUG(D_INFO, "buf %p key_off %d size %d \n",
484 md->key = (struct lustre_key *)buf;
492 int mdc_req2lustre_md(struct obd_export *exp_lmv, struct ptlrpc_request *req,
493 unsigned int offset, struct obd_export *exp_lov,
494 struct lustre_md *md)
496 struct lov_mds_md *lmm;
497 int rc = 0, reply_off;
501 memset(md, 0, sizeof(*md));
503 md->body = lustre_msg_buf(req->rq_repmsg, offset,
508 LASSERT_REPSWABBED(req, offset);
510 if (!(md->body->valid & OBD_MD_FLEASIZE) &&
511 !(md->body->valid & OBD_MD_FLDIREA))
514 if (S_ISREG(md->body->mode)) {
515 if (md->body->eadatasize == 0) {
516 CERROR("invalid EA size (0) is detected\n");
520 lmm = lustre_msg_buf(req->rq_repmsg, offset + 1,
521 md->body->eadatasize);
525 LASSERT(exp_lov != NULL);
527 rc = obd_unpackmd(exp_lov, &md->lsm, lmm,
528 md->body->eadatasize);
530 LASSERT(rc >= sizeof(*md->lsm));
533 } else if (S_ISDIR(md->body->mode)) {
534 /* dir can be non-splitted */
535 if (md->body->eadatasize == 0)
538 lmm = lustre_msg_buf(req->rq_repmsg, offset + 1,
539 md->body->eadatasize);
543 if (md->body->valid & OBD_MD_MEA) {
544 LASSERT(exp_lmv != NULL);
546 rc = obd_unpackmd(exp_lmv, (void *)&md->mea,
547 lmm, md->body->eadatasize);
549 LASSERT(rc >= sizeof(*md->mea));
554 LASSERT(S_ISCHR(md->body->mode) ||
555 S_ISBLK(md->body->mode) ||
556 S_ISFIFO(md->body->mode)||
557 S_ISLNK(md->body->mode) ||
558 S_ISSOCK(md->body->mode));
561 /* if anything wrong when unpacking md, we don't check acl
562 * stuff, for simplicity
567 reply_off = (md->body->valid & OBD_MD_FLEASIZE) ?
568 (offset + 2) : (offset + 1);
569 rc = mdc_unpack_acl(exp_lmv, req, reply_off, md);
571 CERROR("upack acl error %d \n", rc);
576 rc = mdc_unpack_gskey(exp_lmv, req, &reply_off, md);
583 static void mdc_commit_open(struct ptlrpc_request *req)
585 struct mdc_open_data *mod = req->rq_cb_data;
589 if (mod->mod_close_req != NULL)
590 mod->mod_close_req->rq_cb_data = NULL;
592 if (mod->mod_och != NULL)
593 mod->mod_och->och_mod = NULL;
595 OBD_FREE(mod, sizeof(*mod));
596 req->rq_cb_data = NULL;
597 LASSERT(atomic_read(&req->rq_refcount) > 1);
598 ptlrpc_req_finished(req);
601 static void mdc_replay_open(struct ptlrpc_request *req)
603 struct mdc_open_data *mod = req->rq_cb_data;
604 struct obd_client_handle *och;
605 struct ptlrpc_request *close_req;
606 struct lustre_handle old;
607 struct mds_body *body;
610 body = lustre_swab_repbuf(req, 1, sizeof(*body), lustre_swab_mds_body);
611 LASSERT (body != NULL);
614 DEBUG_REQ(D_ERROR, req,
615 "can't properly replay without open data");
622 struct lustre_handle *file_fh;
623 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
624 file_fh = &och->och_fh;
625 CDEBUG(D_HA, "updating handle from "LPX64" to "LPX64"\n",
626 file_fh->cookie, body->handle.cookie);
627 memcpy(&old, file_fh, sizeof(old));
628 memcpy(file_fh, &body->handle, sizeof(*file_fh));
631 close_req = mod->mod_close_req;
632 if (close_req != NULL) {
633 struct mds_body *close_body;
634 LASSERT(close_req->rq_reqmsg->opc == MDS_CLOSE);
635 close_body = lustre_msg_buf(close_req->rq_reqmsg,
637 sizeof(*close_body));
639 LASSERT(!memcmp(&old, &close_body->handle, sizeof old));
640 DEBUG_REQ(D_HA, close_req, "updating close body with new fh");
641 memcpy(&close_body->handle, &body->handle,
642 sizeof(close_body->handle));
648 int mdc_set_open_replay_data(struct obd_export *exp,
649 struct obd_client_handle *och,
650 struct ptlrpc_request *open_req)
652 struct mdc_open_data *mod;
653 struct mds_rec_create *rec;
654 struct mds_body *body;
656 rec = lustre_msg_buf(open_req->rq_reqmsg, MDS_REQ_INTENT_REC_OFF,
658 body = lustre_msg_buf(open_req->rq_repmsg, 1, sizeof(*body));
660 LASSERT(rec != NULL);
661 /* outgoing messages always in my byte order */
662 LASSERT(body != NULL);
663 /* incoming message in my byte order (it's been swabbed) */
664 LASSERT_REPSWABBED(open_req, 1);
666 OBD_ALLOC(mod, sizeof(*mod));
668 DEBUG_REQ(D_ERROR, open_req, "can't allocate mdc_open_data");
674 mod->mod_open_req = ptlrpc_request_addref(open_req);
676 memcpy(&rec->cr_replayid, &body->id1, sizeof rec->cr_replayid);
677 memcpy(&rec->cr_ioepoch, &body->io_epoch, sizeof rec->cr_ioepoch);
678 open_req->rq_replay_cb = mdc_replay_open;
679 open_req->rq_commit_cb = mdc_commit_open;
680 open_req->rq_cb_data = mod;
681 DEBUG_REQ(D_HA, open_req, "set up replay data");
685 int mdc_clear_open_replay_data(struct obd_export *exp,
686 struct obd_client_handle *och)
688 struct mdc_open_data *mod = och->och_mod;
690 /* Don't free the structure now (it happens in mdc_commit_open, after
691 * we're sure we won't need to fix up the close request in the future),
692 * but make sure that replay doesn't poke at the och, which is about to
694 LASSERT(mod != LP_POISON);
701 static void mdc_commit_close(struct ptlrpc_request *req)
703 struct mdc_open_data *mod = req->rq_cb_data;
704 struct obd_import *imp = req->rq_import;
705 struct ptlrpc_request *open_req;
707 DEBUG_REQ(D_HA, req, "close req committed");
711 mod->mod_close_req = NULL;
712 req->rq_cb_data = NULL;
713 req->rq_commit_cb = NULL;
715 open_req = mod->mod_open_req;
716 LASSERT(open_req != NULL);
717 LASSERT(open_req != LP_POISON);
718 LASSERT(open_req->rq_type != LI_POISON);
720 DEBUG_REQ(D_HA, open_req, "open req balanced");
721 if (open_req->rq_transno == 0) {
722 DEBUG_REQ(D_ERROR, open_req, "BUG 3892 open");
723 DEBUG_REQ(D_ERROR, req, "BUG 3892 close");
724 LASSERTF(open_req->rq_transno != 0, "BUG 3892\n");
726 LASSERT(open_req->rq_import == imp);
728 /* We no longer want to preserve this for transno-unconditional
730 spin_lock(&open_req->rq_lock);
731 open_req->rq_replay = 0;
732 spin_unlock(&open_req->rq_lock);
735 int mdc_close(struct obd_export *exp, struct mdc_op_data *op_data,
736 struct obd_client_handle *och, struct ptlrpc_request **request)
738 struct obd_device *obd = class_exp2obd(exp);
739 struct obd_import *imp = class_exp2cliimp(exp);
740 int reqsize[3] = {0, sizeof(struct mds_body),
741 obd->u.cli.cl_max_mds_cookiesize};
742 int rc, repsize[3] = {sizeof(struct mds_body),
743 obd->u.cli.cl_max_mds_easize,
744 obd->u.cli.cl_max_mds_cookiesize};
745 struct ptlrpc_request *req;
746 struct mdc_open_data *mod;
749 if (imp->imp_connection == NULL) {
750 CERROR("request on not connected import %s\n",
751 imp->imp_obd->obd_name);
755 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
756 MDS_CLOSE, 3, reqsize, NULL);
758 GOTO(out, rc = -ENOMEM);
759 //req->rq_request_portal = MDS_CLOSE_PORTAL;
761 /* ensure that this close's handle is fixed up during replay. */
762 LASSERT(och != NULL);
764 if (likely(mod != NULL)) {
765 mod->mod_close_req = req;
766 LASSERT(mod->mod_open_req->rq_type != LI_POISON);
767 DEBUG_REQ(D_HA, mod->mod_open_req, "matched open");
769 CDEBUG(D_HA, "couldn't find open req; "
770 "expecting close error\n");
773 mdc_close_pack(req, 1, op_data, och);
775 req->rq_replen = lustre_msg_size(3, repsize);
776 req->rq_commit_cb = mdc_commit_close;
777 LASSERT(req->rq_cb_data == NULL);
778 req->rq_cb_data = mod;
780 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
781 rc = ptlrpc_queue_wait(req);
782 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
784 if (req->rq_repmsg == NULL) {
785 CDEBUG(D_HA, "request failed to send: %p, %d\n", req,
788 rc = req->rq_status ? req->rq_status : -EIO;
789 } else if (rc == 0) {
790 rc = req->rq_repmsg->status;
791 if (req->rq_repmsg->type == PTL_RPC_MSG_ERR) {
792 DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, "
798 CERROR("Unexpected: can't find mdc_open_data, but "
799 "close succeeded. Please tell CFS.\n");
800 if (!lustre_swab_repbuf(req, 0, sizeof(struct mds_body),
801 lustre_swab_mds_body))
803 CERROR("Error unpacking mds_body\n");
815 int mdc_done_writing(struct obd_export *exp, struct obdo *obdo)
817 struct ptlrpc_request *req;
818 struct mds_body *body;
819 int rc, size[2] = {0, sizeof(*body)};
822 size[0] = lustre_secdesc_size();
824 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
825 MDS_DONE_WRITING, 2, size, NULL);
829 lustre_pack_secdesc(req, size[0]);
831 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF,
834 mdc_pack_id(&body->id1, obdo->o_id, 0, obdo->o_mode,
835 obdo->o_mds, obdo->o_fid);
837 body->size = obdo->o_size;
838 body->blocks = obdo->o_blocks;
839 body->flags = obdo->o_flags;
840 body->valid = obdo->o_valid;
842 req->rq_replen = lustre_msg_size(1, &size[1]);
844 rc = ptlrpc_queue_wait(req);
845 ptlrpc_req_finished(req);
849 int mdc_readpage(struct obd_export *exp,
850 struct lustre_id *id,
851 __u64 offset, struct page *page,
852 struct ptlrpc_request **request)
854 struct obd_import *imp = class_exp2cliimp(exp);
855 struct ptlrpc_request *req = NULL;
856 struct ptlrpc_bulk_desc *desc = NULL;
857 struct mds_body *body;
858 int rc, size[2] = {0, sizeof(*body)};
861 CDEBUG(D_INODE, "inode: %ld\n", (long)id->li_stc.u.e3s.l3s_ino);
863 size[0] = lustre_secdesc_size();
865 req = ptlrpc_prep_req(imp, LUSTRE_MDS_VERSION, MDS_READPAGE,
868 GOTO(out, rc = -ENOMEM);
869 /* XXX FIXME bug 249 */
870 req->rq_request_portal = MDS_READPAGE_PORTAL;
872 lustre_pack_secdesc(req, size[0]);
874 desc = ptlrpc_prep_bulk_imp(req, 1, BULK_PUT_SINK, MDS_BULK_PORTAL);
876 GOTO(out, rc = -ENOMEM);
877 /* NB req now owns desc and will free it when it gets freed */
879 ptlrpc_prep_bulk_page(desc, page, 0, PAGE_CACHE_SIZE);
880 mdc_readdir_pack(req, 1, offset, PAGE_CACHE_SIZE, id);
882 req->rq_replen = lustre_msg_size(1, &size[1]);
883 rc = ptlrpc_queue_wait(req);
886 body = lustre_swab_repbuf(req, 0, sizeof (*body),
887 lustre_swab_mds_body);
889 CERROR("Can't unpack mds_body\n");
890 GOTO(out, rc = -EPROTO);
893 if (req->rq_bulk->bd_nob_transferred != PAGE_CACHE_SIZE) {
894 CERROR ("Unexpected # bytes transferred: %d"
896 req->rq_bulk->bd_nob_transferred,
898 GOTO (out, rc = -EPROTO);
908 static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
909 void *karg, void *uarg)
911 struct obd_device *obd = exp->exp_obd;
912 struct obd_ioctl_data *data = karg;
913 struct obd_import *imp = obd->u.cli.cl_import;
914 struct llog_ctxt *ctxt;
918 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
921 if (!try_module_get(THIS_MODULE)) {
922 CERROR("Can't get module. Is it alive?");
927 case OBD_IOC_CLIENT_RECOVER:
928 rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1);
932 case IOC_OSC_SET_ACTIVE:
933 rc = ptlrpc_set_import_active(imp, data->ioc_offset);
935 case IOC_OSC_CTL_RECOVERY:
936 rc = ptlrpc_import_control_recovery(imp, data->ioc_offset);
938 case OBD_IOC_PARSE: {
939 ctxt = llog_get_context(&exp->exp_obd->obd_llogs,
940 LLOG_CONFIG_REPL_CTXT);
941 rc = class_config_process_llog(ctxt, data->ioc_inlbuf1, NULL);
945 case OBD_IOC_LLOG_INFO:
946 case OBD_IOC_LLOG_PRINT: {
947 ctxt = llog_get_context(&obd->obd_llogs, LLOG_CONFIG_REPL_CTXT);
948 rc = llog_ioctl(ctxt, cmd, data);
954 CERROR("mdc_ioctl(): unrecognised ioctl %#x\n", cmd);
955 GOTO(out, rc = -ENOTTY);
958 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
961 module_put(THIS_MODULE);
967 int mdc_set_info(struct obd_export *exp, obd_count keylen,
968 void *key, obd_count vallen, void *val)
972 if (keylen == strlen("initial_recov") &&
973 memcmp(key, "initial_recov", strlen("initial_recov")) == 0) {
974 struct obd_import *imp = exp->exp_obd->u.cli.cl_import;
975 if (vallen != sizeof(int))
977 imp->imp_initial_recov = *(int *)val;
978 CDEBUG(D_HA, "%s: set imp_no_init_recov = %d\n",
979 exp->exp_obd->obd_name,
980 imp->imp_initial_recov);
982 } else if ((keylen >= strlen("crypto_type")) &&
983 strcmp(key, "crypto_type") == 0) {
984 struct ptlrpc_request *req;
985 char *bufs[2] = {key, val};
986 int rc, size[2] = {keylen, vallen};
988 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
989 OST_SET_INFO, 2, size, bufs);
993 req->rq_replen = lustre_msg_size(0, NULL);
994 rc = ptlrpc_queue_wait(req);
995 ptlrpc_req_finished(req);
997 } else if (keylen >= strlen("inter_mds") && strcmp(key, "inter_mds") == 0) {
998 struct obd_import *imp = class_exp2cliimp(exp);
999 imp->imp_server_timeout = 1;
1000 CDEBUG(D_OTHER, "%s: timeout / 2\n", exp->exp_obd->obd_name);
1002 } else if (keylen == strlen("sec") &&
1003 memcmp(key, "sec", keylen) == 0) {
1004 struct client_obd *cli = &exp->exp_obd->u.cli;
1006 cli->cl_sec_flavor = ptlrpcs_name2flavor(val);
1007 if (cli->cl_sec_flavor == PTLRPCS_FLVR_INVALID) {
1008 CERROR("unrecognized security type %s\n", (char*) val);
1013 } else if (keylen == strlen("sec_flags") &&
1014 memcmp(key, "sec_flags", keylen) == 0) {
1015 struct client_obd *cli = &exp->exp_obd->u.cli;
1017 cli->cl_sec_flags = *((unsigned long *) val);
1019 } else if (keylen == strlen("flush_cred") &&
1020 memcmp(key, "flush_cred", keylen) == 0) {
1021 struct client_obd *cli = &exp->exp_obd->u.cli;
1024 ptlrpcs_import_flush_current_creds(cli->cl_import);
1026 } else if (keylen == strlen("async") && memcmp(key, "async", keylen) == 0) {
1027 struct client_obd *cl = &exp->exp_obd->u.cli;
1028 if (vallen != sizeof(int))
1030 cl->cl_async = *(int *)val;
1031 CDEBUG(D_HA, "%s: set async = %d\n",
1032 exp->exp_obd->obd_name, cl->cl_async);
1034 } else if (keylen == strlen("setext") && memcmp(key, "setext", keylen) == 0) {
1035 struct ptlrpc_request *req;
1036 char *bufs[2] = {key, val};
1037 int rc, size[2] = {keylen, vallen};
1039 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1040 OST_SET_INFO, 2, size, bufs);
1044 req->rq_replen = lustre_msg_size(0, NULL);
1045 rc = ptlrpc_queue_wait(req);
1046 ptlrpc_req_finished(req);
1048 } else if (keylen == 5 && strcmp(key, "audit") == 0) {
1049 struct ptlrpc_request *req;
1050 char *bufs[2] = {key, val};
1051 int rc, size[2] = {keylen, vallen};
1053 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1054 OST_SET_INFO, 2, size, bufs);
1058 req->rq_replen = lustre_msg_size(0, NULL);
1059 lustre_swab_reqbuf(req, 1, sizeof(struct audit_attr_msg),
1060 lustre_swab_audit_attr);
1061 rc = ptlrpc_queue_wait(req);
1062 ptlrpc_req_finished(req);
1065 } else if (keylen == strlen("ids") && memcmp(key, "ids", keylen) == 0) {
1066 struct ptlrpc_request *req;
1067 struct lustre_id *ids = (struct lustre_id *)val;
1068 char *bufs[3] = {key, (char *)ids, (char *)(ids + 1)};
1069 int rc, size[3] = {keylen, sizeof(struct lustre_id),
1070 sizeof(struct lustre_id)};
1072 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1073 OST_SET_INFO, 3, size, bufs);
1077 req->rq_replen = lustre_msg_size(0, NULL);
1078 rc = ptlrpc_queue_wait(req);
1079 ptlrpc_req_finished(req);
1085 static int mdc_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1086 unsigned long max_age)
1088 struct obd_statfs *msfs;
1089 struct ptlrpc_request *req;
1090 int rc, size = sizeof(*msfs);
1093 /* We could possibly pass max_age in the request (as an absolute
1094 * timestamp or a "seconds.usec ago") so the target can avoid doing
1095 * extra calls into the filesystem if that isn't necessary (e.g.
1096 * during mount that would help a bit). Having relative timestamps
1097 * is not so great if request processing is slow, while absolute
1098 * timestamps are not ideal because they need time synchronization. */
1099 req = ptlrpc_prep_req(obd->u.cli.cl_import, LUSTRE_MDS_VERSION,
1100 MDS_STATFS, 0, NULL, NULL);
1104 req->rq_replen = lustre_msg_size(1, &size);
1106 mdc_get_rpc_lock(obd->u.cli.cl_rpc_lock, NULL);
1107 rc = ptlrpc_queue_wait(req);
1108 mdc_put_rpc_lock(obd->u.cli.cl_rpc_lock, NULL);
1111 /* this can be LMV fake import, whcih is not connected. */
1112 if (!req->rq_import->imp_connection)
1113 memset(osfs, 0, sizeof(*osfs));
1117 msfs = lustre_swab_repbuf(req, 0, sizeof(*msfs),
1118 lustre_swab_obd_statfs);
1120 CERROR("Can't unpack obd_statfs\n");
1121 GOTO(out, rc = -EPROTO);
1124 memcpy(osfs, msfs, sizeof (*msfs));
1127 ptlrpc_req_finished(req);
1131 static int mdc_pin(struct obd_export *exp, obd_id ino, __u32 gen, int type,
1132 struct obd_client_handle *handle, int flag)
1134 struct ptlrpc_request *req;
1135 struct mds_body *body;
1136 int rc, size[2] = {0, sizeof(*body)};
1139 //size[0] = lustre_secdesc_size();
1141 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1142 MDS_PIN, 2, size, NULL);
1146 //lustre_pack_secdesc(req, size[0]);
1148 body = lustre_msg_buf(req->rq_reqmsg,
1149 MDS_REQ_REC_OFF, sizeof(*body));
1151 /* FIXME-UMKA: here should be also mdsnum and fid. */
1152 mdc_pack_id(&body->id1, ino, gen, type, 0, 0);
1155 req->rq_replen = lustre_msg_size(1, &size[1]);
1157 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1158 rc = ptlrpc_queue_wait(req);
1159 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1161 CERROR("pin failed: %d\n", rc);
1162 ptlrpc_req_finished(req);
1166 body = lustre_swab_repbuf(req, 0, sizeof(*body), lustre_swab_mds_body);
1168 ptlrpc_req_finished(req);
1172 memcpy(&handle->och_fh, &body->handle, sizeof(body->handle));
1173 handle->och_magic = OBD_CLIENT_HANDLE_MAGIC;
1175 OBD_ALLOC(handle->och_mod, sizeof(*handle->och_mod));
1176 if (handle->och_mod == NULL) {
1177 DEBUG_REQ(D_ERROR, req, "can't allocate mdc_open_data");
1180 handle->och_mod->mod_open_req = req; /* will be dropped by unpin */
1185 static int mdc_unpin(struct obd_export *exp,
1186 struct obd_client_handle *handle, int flag)
1188 struct ptlrpc_request *req;
1189 struct mds_body *body;
1190 int rc, size[2] = {0, sizeof(*body)};
1193 if (handle->och_magic != OBD_CLIENT_HANDLE_MAGIC)
1196 //size[0] = lustre_secdesc_size();
1198 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1199 MDS_CLOSE, 2, size, NULL);
1203 //lustre_pack_secdesc(req, size[0]);
1205 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof(*body));
1206 memcpy(&body->handle, &handle->och_fh, sizeof(body->handle));
1209 req->rq_replen = lustre_msg_size(0, NULL);
1210 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1211 rc = ptlrpc_queue_wait(req);
1212 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1215 CERROR("unpin failed: %d\n", rc);
1217 ptlrpc_req_finished(req);
1218 ptlrpc_req_finished(handle->och_mod->mod_open_req);
1219 OBD_FREE(handle->och_mod, sizeof(*handle->och_mod));
1223 int mdc_sync(struct obd_export *exp, struct lustre_id *id,
1224 struct ptlrpc_request **request)
1226 struct ptlrpc_request *req;
1227 struct mds_body *body;
1228 int size[2] = {0, sizeof(*body)};
1232 //size[0] = lustre_secdesc_size();
1234 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1235 MDS_SYNC, 2, size, NULL);
1237 RETURN(rc = -ENOMEM);
1239 //lustre_pack_secdesc(req, size[0]);
1242 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF,
1244 memcpy(&body->id1, id, sizeof(*id));
1247 req->rq_replen = lustre_msg_size(1, &size[1]);
1249 rc = ptlrpc_queue_wait(req);
1250 if (rc || request == NULL)
1251 ptlrpc_req_finished(req);
1258 static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
1259 enum obd_import_event event)
1263 LASSERT(imp->imp_obd == obd);
1266 case IMP_EVENT_DISCON: {
1269 case IMP_EVENT_INACTIVE: {
1270 if (obd->obd_observer)
1271 rc = obd_notify(obd->obd_observer, obd, 0, 0);
1274 case IMP_EVENT_INVALIDATE: {
1275 struct ldlm_namespace *ns = obd->obd_namespace;
1277 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
1281 case IMP_EVENT_ACTIVE: {
1282 if (obd->obd_observer)
1283 rc = obd_notify(obd->obd_observer, obd, 1, 0);
1287 CERROR("Unknown import event %d\n", event);
1293 static int mdc_attach(struct obd_device *dev, obd_count len, void *data)
1295 struct lprocfs_static_vars lvars;
1297 lprocfs_init_vars(mdc, &lvars);
1298 return lprocfs_obd_attach(dev, lvars.obd_vars);
1301 static int mdc_detach(struct obd_device *dev)
1303 return lprocfs_obd_detach(dev);
1306 static int mdc_setup(struct obd_device *obd, obd_count len, void *buf)
1308 struct client_obd *cli = &obd->u.cli;
1312 OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1313 if (!cli->cl_rpc_lock)
1315 mdc_init_rpc_lock(cli->cl_rpc_lock);
1319 OBD_ALLOC(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1320 if (!cli->cl_setattr_lock)
1321 GOTO(err_rpc_lock, rc = -ENOMEM);
1322 mdc_init_rpc_lock(cli->cl_setattr_lock);
1324 OBD_ALLOC(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1325 if (!cli->cl_close_lock)
1326 GOTO(err_setattr_lock, rc = -ENOMEM);
1327 mdc_init_rpc_lock(cli->cl_close_lock);
1329 rc = client_obd_setup(obd, len, buf);
1331 GOTO(err_close_lock, rc);
1333 rc = obd_llog_init(obd, &obd->obd_llogs, obd, 0, NULL);
1335 mdc_cleanup(obd, 0);
1336 CERROR("failed to setup llogging subsystems\n");
1342 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1344 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1346 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1351 static int mdc_init_ea_size(struct obd_export *exp, int easize, int cookiesize)
1353 struct obd_device *obd = exp->exp_obd;
1354 struct client_obd *cli = &obd->u.cli;
1357 if (cli->cl_max_mds_easize < easize)
1358 cli->cl_max_mds_easize = easize;
1359 if (cli->cl_max_mds_cookiesize < cookiesize)
1360 cli->cl_max_mds_cookiesize = cookiesize;
1364 static int mdc_precleanup(struct obd_device *obd, int flags)
1368 rc = obd_llog_finish(obd, &obd->obd_llogs, 0);
1370 CERROR("failed to cleanup llogging subsystems\n");
1375 static int mdc_cleanup(struct obd_device *obd, int flags)
1377 struct client_obd *cli = &obd->u.cli;
1379 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1380 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1381 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1385 return client_obd_cleanup(obd, flags);
1389 static int mdc_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
1390 struct obd_device *tgt, int count,
1391 struct llog_catid *logid)
1393 struct llog_ctxt *ctxt;
1397 rc = obd_llog_setup(obd, llogs, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
1400 ctxt = llog_get_context(llogs, LLOG_CONFIG_REPL_CTXT);
1401 ctxt->loc_imp = obd->u.cli.cl_import;
1407 static int mdc_llog_finish(struct obd_device *obd,
1408 struct obd_llogs *llogs, int count)
1413 rc = obd_llog_cleanup(llog_get_context(llogs, LLOG_CONFIG_REPL_CTXT));
1417 static struct obd_device *mdc_get_real_obd(struct obd_export *exp,
1418 struct lustre_id *id)
1421 RETURN(exp->exp_obd);
1424 static int mdc_get_info(struct obd_export *exp, __u32 keylen,
1425 void *key, __u32 *valsize, void *val)
1427 struct ptlrpc_request *req;
1428 char *bufs[1] = {key};
1432 if (!valsize || !val)
1435 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
1436 struct obd_import *imp;
1437 struct obd_connect_data *data;
1439 imp = class_exp2cliimp(exp);
1445 if (imp->imp_state != LUSTRE_IMP_FULL) {
1446 CERROR("import state not full\n");
1450 data = &imp->imp_connect_data;
1451 if (data->ocd_connect_flags & OBD_CONNECT_REMOTE) {
1454 } else if (data->ocd_connect_flags & OBD_CONNECT_LOCAL) {
1458 CERROR("no remote flag set?\n");
1462 if ((keylen < strlen("mdsize") || strcmp(key, "mdsize") != 0) &&
1463 (keylen < strlen("mdsnum") || strcmp(key, "mdsnum") != 0) &&
1464 (keylen < strlen("lovdesc") || strcmp(key, "lovdesc") != 0) &&
1465 (keylen < strlen("getext") || strcmp(key, "getext") != 0) &&
1466 (keylen < strlen("rootid") || strcmp(key, "rootid") != 0) &&
1467 (keylen < strlen("auditid") || strcmp(key, "auditid") != 0))
1470 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1471 OST_GET_INFO, 1, (int *)&keylen, bufs);
1475 req->rq_replen = lustre_msg_size(1, (int *)valsize);
1476 rc = ptlrpc_queue_wait(req);
1480 if ((keylen >= strlen("rootid") && !strcmp(key, "rootid")) ||
1481 (keylen >= strlen("auditid") && !strcmp(key, "auditid"))) {
1482 struct lustre_id *reply;
1484 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
1485 lustre_swab_lustre_id);
1486 if (reply == NULL) {
1487 CERROR("Can't unpack %s\n", (char *)key);
1488 GOTO(out_req, rc = -EPROTO);
1491 *(struct lustre_id *)val = *reply;
1492 } else if (keylen >= strlen("lovdesc") && !strcmp(key, "lovdesc")) {
1493 struct lov_desc *reply;
1495 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
1496 lustre_swab_lov_desc);
1497 if (reply == NULL) {
1498 CERROR("Can't unpack %s\n", (char *)key);
1499 GOTO(out_req, rc = -EPROTO);
1502 *(struct lov_desc *)val = *reply;
1504 } else if (keylen >= strlen("getext") && !strcmp(key, "getext")) {
1505 struct fid_extent *reply;
1507 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
1508 lustre_swab_fid_extent);
1509 if (reply == NULL) {
1510 CERROR("Can't unpack %s\n", (char *)key);
1511 GOTO(out_req, rc = -EPROTO);
1514 *(struct fid_extent *)val = *reply;
1519 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
1520 lustre_swab_generic_32s);
1521 if (reply == NULL) {
1522 CERROR("Can't unpack %s\n", (char *)key);
1523 GOTO(out_req, rc = -EPROTO);
1525 *((__u32 *)val) = *reply;
1528 ptlrpc_req_finished(req);
1532 int mdc_obj_create(struct obd_export *exp, struct obdo *oa,
1533 void *acl, int acl_size, struct lov_stripe_md **ea,
1534 struct obd_trans_info *oti)
1536 struct ptlrpc_request *request;
1537 struct ost_body *body;
1539 int rc, size[2] = { sizeof(*body), acl_size };
1544 request = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1545 OST_CREATE, 2, size, NULL);
1547 GOTO(out_req, rc = -ENOMEM);
1549 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
1550 memcpy(&body->oa, oa, sizeof(body->oa));
1553 acl_buf = lustre_msg_buf(request->rq_reqmsg, 1, acl_size);
1554 memcpy(acl_buf, acl, acl_size);
1557 request->rq_replen = lustre_msg_size(1, size);
1558 rc = ptlrpc_queue_wait(request);
1562 body = lustre_swab_repbuf(request, 0, sizeof(*body),
1563 lustre_swab_ost_body);
1565 CERROR ("can't unpack ost_body\n");
1566 GOTO (out_req, rc = -EPROTO);
1569 memcpy(oa, &body->oa, sizeof(*oa));
1571 /* store ino/generation for recovery */
1572 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
1573 body->oa.o_id = oa->o_id;
1574 body->oa.o_generation = oa->o_generation;
1575 body->oa.o_fid = oa->o_fid;
1576 body->oa.o_mds = oa->o_mds;
1578 CDEBUG(D_HA, "transno: "LPD64"\n", request->rq_repmsg->transno);
1581 ptlrpc_req_finished(request);
1585 int mdc_brw(int rw, struct obd_export *exp, struct obdo *oa,
1586 struct lov_stripe_md *ea, obd_count oa_bufs,
1587 struct brw_page *pgarr, struct obd_trans_info *oti)
1589 struct ptlrpc_bulk_desc *desc;
1590 struct niobuf_remote *niobuf;
1591 struct ptlrpc_request *req;
1592 struct obd_ioobj *ioobj;
1593 struct ost_body *body;
1597 opc = ((rw & OBD_BRW_WRITE) != 0) ? OST_WRITE : OST_READ;
1599 size[0] = sizeof(*body);
1600 size[1] = sizeof(*ioobj);
1601 size[2] = oa_bufs * sizeof(*niobuf);
1603 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION, opc,
1605 LASSERT(req != NULL);
1607 if (opc == OST_WRITE)
1608 desc = ptlrpc_prep_bulk_imp(req, oa_bufs, BULK_GET_SOURCE,
1611 desc = ptlrpc_prep_bulk_imp(req, oa_bufs, BULK_PUT_SINK,
1613 LASSERT(desc != NULL);
1615 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
1616 ioobj = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*ioobj));
1617 niobuf = lustre_msg_buf(req->rq_reqmsg, 2, oa_bufs * sizeof(*niobuf));
1619 memcpy(&body->oa, oa, sizeof(*oa));
1620 obdo_to_ioobj(oa, ioobj);
1621 ioobj->ioo_bufcnt = oa_bufs;
1623 for (i = 0; i < oa_bufs; i++, niobuf++) {
1624 struct brw_page *pg = &pgarr[i];
1626 LASSERT(pg->count > 0);
1627 LASSERT((pg->disk_offset & ~PAGE_MASK) + pg->count <= PAGE_SIZE);
1629 ptlrpc_prep_bulk_page(desc, pg->pg, pg->disk_offset & ~PAGE_MASK,
1632 niobuf->offset = pg->disk_offset;
1633 niobuf->len = pg->count;
1634 niobuf->flags = pg->flag;
1637 /* size[0] still sizeof (*body) */
1638 if (opc == OST_WRITE) {
1639 /* 1 RC per niobuf */
1640 size[1] = sizeof(__u32) * oa_bufs;
1641 req->rq_replen = lustre_msg_size(2, size);
1643 /* 1 RC for the whole I/O */
1644 req->rq_replen = lustre_msg_size(1, size);
1646 err = ptlrpc_queue_wait(req);
1649 ptlrpc_req_finished(req);
1653 static int mdc_valid_attrs(struct obd_export *exp,
1654 struct lustre_id *id)
1656 struct ldlm_res_id res_id = { .name = {0} };
1657 struct obd_device *obd = exp->exp_obd;
1658 struct lustre_handle lockh;
1659 ldlm_policy_data_t policy;
1663 res_id.name[0] = id_fid(id);
1664 res_id.name[1] = id_group(id);
1665 policy.l_inodebits.bits = MDS_INODELOCK_UPDATE;
1667 CDEBUG(D_INFO, "trying to match res "LPU64"\n",
1670 /* FIXME use LDLM_FL_TEST_LOCK instead */
1671 flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_CBPENDING;
1672 if (ldlm_lock_match(obd->obd_namespace, flags, &res_id,
1673 LDLM_IBITS, &policy, LCK_PR, &lockh)) {
1674 ldlm_lock_decref(&lockh, LCK_PR);
1678 if (ldlm_lock_match(obd->obd_namespace, flags, &res_id,
1679 LDLM_IBITS, &policy, LCK_PW, &lockh)) {
1680 ldlm_lock_decref(&lockh, LCK_PW);
1686 static int mdc_change_cbdata_name(struct obd_export *exp,
1687 struct lustre_id *pid,
1688 char *name, int len,
1689 struct lustre_id *cid,
1690 ldlm_iterator_t it, void *data)
1693 rc = mdc_change_cbdata(exp, cid, it, data);
1697 struct obd_ops mdc_obd_ops = {
1698 .o_owner = THIS_MODULE,
1699 .o_attach = mdc_attach,
1700 .o_detach = mdc_detach,
1701 .o_setup = mdc_setup,
1702 .o_precleanup = mdc_precleanup,
1703 .o_cleanup = mdc_cleanup,
1704 .o_add_conn = client_import_add_conn,
1705 .o_del_conn = client_import_del_conn,
1706 .o_connect = client_connect_import,
1707 .o_disconnect = client_disconnect_export,
1708 .o_iocontrol = mdc_iocontrol,
1709 .o_packmd = mdc_packmd,
1710 .o_unpackmd = mdc_unpackmd,
1711 .o_statfs = mdc_statfs,
1713 .o_unpin = mdc_unpin,
1714 .o_import_event = mdc_import_event,
1715 .o_llog_init = mdc_llog_init,
1716 .o_llog_finish = mdc_llog_finish,
1717 .o_create = mdc_obj_create,
1718 .o_set_info = mdc_set_info,
1719 .o_get_info = mdc_get_info,
1721 .o_cancel_unused = mdc_cancel_unused,
1722 .o_init_ea_size = mdc_init_ea_size,
1725 struct md_ops mdc_md_ops = {
1726 .m_getstatus = mdc_getstatus,
1727 .m_getattr = mdc_getattr,
1728 .m_close = mdc_close,
1729 .m_create = mdc_create,
1730 .m_done_writing = mdc_done_writing,
1731 .m_enqueue = mdc_enqueue,
1732 .m_getattr_lock = mdc_getattr_lock,
1733 .m_intent_lock = mdc_intent_lock,
1735 .m_rename = mdc_rename,
1736 .m_setattr = mdc_setattr,
1738 .m_readpage = mdc_readpage,
1739 .m_unlink = mdc_unlink,
1740 .m_valid_attrs = mdc_valid_attrs,
1741 .m_req2lustre_md = mdc_req2lustre_md,
1742 .m_set_open_replay_data = mdc_set_open_replay_data,
1743 .m_clear_open_replay_data = mdc_clear_open_replay_data,
1744 .m_store_inode_generation = mdc_store_inode_generation,
1745 .m_set_lock_data = mdc_set_lock_data,
1746 .m_get_real_obd = mdc_get_real_obd,
1747 .m_change_cbdata_name = mdc_change_cbdata_name,
1748 .m_change_cbdata = mdc_change_cbdata,
1749 .m_access_check = mdc_access_check,
1752 int __init mdc_init(void)
1754 struct lprocfs_static_vars lvars;
1756 lprocfs_init_vars(mdc, &lvars);
1757 return class_register_type(&mdc_obd_ops, &mdc_md_ops,
1758 lvars.module_vars, OBD_MDC_DEVICENAME);
1762 static void /*__exit*/ mdc_exit(void)
1764 class_unregister_type(OBD_MDC_DEVICENAME);
1767 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1768 MODULE_DESCRIPTION("Lustre Metadata Client");
1769 MODULE_LICENSE("GPL");
1771 EXPORT_SYMBOL(mdc_req2lustre_md);
1772 EXPORT_SYMBOL(mdc_change_cbdata);
1773 EXPORT_SYMBOL(mdc_getstatus);
1774 EXPORT_SYMBOL(mdc_getattr);
1775 EXPORT_SYMBOL(mdc_getattr_lock);
1776 EXPORT_SYMBOL(mdc_create);
1777 EXPORT_SYMBOL(mdc_unlink);
1778 EXPORT_SYMBOL(mdc_rename);
1779 EXPORT_SYMBOL(mdc_link);
1780 EXPORT_SYMBOL(mdc_readpage);
1781 EXPORT_SYMBOL(mdc_setattr);
1782 EXPORT_SYMBOL(mdc_close);
1783 EXPORT_SYMBOL(mdc_done_writing);
1784 EXPORT_SYMBOL(mdc_sync);
1785 EXPORT_SYMBOL(mdc_set_open_replay_data);
1786 EXPORT_SYMBOL(mdc_clear_open_replay_data);
1787 EXPORT_SYMBOL(mdc_store_inode_generation);
1789 module_init(mdc_init);
1790 module_exit(mdc_exit);