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;
118 DEBUG_REQ(rc == -ENOENT ? D_INFO : D_ERROR , req,
119 "async getattr failed: rc = %d", rc);
123 body = lustre_swab_repbuf(req, 0, sizeof (*body), lustre_swab_mds_body);
125 CERROR ("Can't unpack mds_body\n");
129 if (!(body->valid & OBD_MD_CAPA)) {
130 CDEBUG(D_INFO, "MDS has disabled capability\n");
134 capa = lustre_swab_repbuf(req, 1, sizeof(*capa),
135 lustre_swab_lustre_capa);
136 if (capa == NULL && rc != 0) {
137 CERROR ("Can't unpack lustre_capa\n");
141 ocapa = capa_renew(capa, CLIENT_CAPA);
145 spin_lock(&capa_lock);
146 expiry = expiry_to_jiffies(capa->lc_expiry - capa_pre_expiry(capa));
147 CDEBUG(D_INFO, "expiry %lu vs timer %lu, base %p\n",
148 expiry, ll_capa_timer.expires, ll_capa_timer.base);
149 if (time_before(expiry, ll_capa_timer.expires) ||
150 !timer_pending(&ll_capa_timer)) {
151 mod_timer(&ll_capa_timer, expiry);
152 CDEBUG(D_INFO, "ll_capa_timer new expiry: %lu\n", expiry);
154 spin_unlock(&capa_lock);
159 int mdc_getattr_async(struct obd_export *exp, struct ptlrpc_request *req)
161 int repsize[2] = {sizeof(struct mds_body), sizeof(struct lustre_capa)};
164 req->rq_replen = lustre_msg_size(2, repsize);
165 req->rq_interpret_reply = mdc_interpret_getattr;
166 ptlrpcd_add_req(req);
171 int mdc_getattr_common(struct obd_export *exp, unsigned int ea_size,
172 struct ptlrpc_request *req)
174 struct mds_body *body, *reqbody;
177 int repsize[2] = {sizeof(*body)};
181 /* request message already built */
184 repsize[bufcount++] = ea_size;
185 CDEBUG(D_INODE, "reserved %u bytes for MD/symlink in packet\n",
189 reqbody = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*reqbody));
190 LASSERT(!(reqbody->valid & OBD_MD_FLACL));
192 if (reqbody->valid & OBD_MD_FLKEY) {
193 repsize[bufcount++] = 5;
194 repsize[bufcount++] = sizeof(struct lustre_key);
195 } else if (reqbody->valid & OBD_MD_CAPA) {
196 LASSERT(ea_size == 0);
197 repsize[bufcount++] = sizeof(struct lustre_capa);
200 req->rq_replen = lustre_msg_size(bufcount, repsize);
202 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
203 rc = ptlrpc_queue_wait(req);
204 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
208 body = lustre_swab_repbuf (req, 0, sizeof (*body),
209 lustre_swab_mds_body);
211 CERROR ("Can't unpack mds_body\n");
215 CDEBUG(D_NET, "mode: %o\n", body->mode);
217 LASSERT_REPSWAB (req, 1);
219 /* Skip the check if getxattr/listxattr are called with no buffers */
220 if ((reqbody->eadatasize != 0) &&
221 !(reqbody->valid & (OBD_MD_FLXATTR | OBD_MD_FLXATTRLIST))) {
222 /* reply indicates presence of eadata; check it's there... */
223 eadata = lustre_msg_buf (req->rq_repmsg, 1,
225 if (eadata == NULL) {
226 CERROR ("Missing/short eadata\n");
234 static int mdc_cancel_unused(struct obd_export *exp,
235 struct lov_stripe_md *lsm,
236 int flags, void *opaque)
238 struct obd_device *obd = class_exp2obd(exp);
241 RETURN(ldlm_cli_cancel_unused(obd->obd_namespace,
242 NULL, flags, opaque));
245 int mdc_getattr(struct obd_export *exp, struct lustre_id *id,
246 __u64 valid, const char *xattr_name,
247 const void *xattr_data, unsigned int xattr_datalen,
248 unsigned int ea_size, struct obd_capa *ocapa,
249 struct ptlrpc_request **request)
251 struct ptlrpc_request *req;
252 struct mds_body *body;
253 int xattr_namelen = xattr_name ? strlen(xattr_name) + 1 : 0;
254 int size[4] = {0, sizeof(*body)};
259 size[0] = lustre_secdesc_size();
261 if (valid & OBD_MD_FLXATTR) {
262 size[bufcount++] = xattr_namelen;
264 if (xattr_datalen > 0) {
266 size[bufcount++] = xattr_datalen;
268 } else if (valid & OBD_MD_CAPA) {
269 LASSERT(valid == OBD_MD_CAPA);
271 size[bufcount++] = sizeof(*ocapa);
273 LASSERT(!xattr_data && !xattr_datalen);
276 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
277 MDS_GETATTR, bufcount, size, NULL);
279 GOTO(out, rc = -ENOMEM);
281 lustre_pack_secdesc(req, size[0]);
283 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof (*body));
284 memcpy(&body->id1, id, sizeof(*id));
286 body->eadatasize = ea_size;
288 if (valid & OBD_MD_FLXATTR) {
289 memcpy(lustre_msg_buf(req->rq_reqmsg, 2, xattr_namelen),
290 xattr_name, xattr_namelen);
292 memcpy(lustre_msg_buf(req->rq_reqmsg, 3, xattr_datalen),
293 xattr_data, xattr_datalen);
296 if (valid & OBD_MD_CAPA) {
297 /* renew capability */
298 memcpy(&body->handle, &ocapa->c_handle, sizeof(body->handle));
299 memcpy(lustre_msg_buf(req->rq_reqmsg, 2, sizeof(ocapa->c_capa)),
300 &ocapa->c_capa, sizeof(ocapa->c_capa));
302 rc = mdc_getattr_async(exp, req);
303 req = NULL; /* ptlrpcd will finish request */
305 rc = mdc_getattr_common(exp, ea_size, req);
307 ptlrpc_req_finished (req);
316 int mdc_access_check(struct obd_export *exp, struct lustre_id *id,
317 struct ptlrpc_request **request)
320 struct ptlrpc_request *req;
321 struct mds_body *body;
322 int size[2] = {0, sizeof(*body)};
326 size[0] = lustre_secdesc_size();
327 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
328 MDS_ACCESS_CHECK, 2, size, NULL);
330 GOTO(out, rc = -ENOMEM);
332 lustre_pack_secdesc(req, size[0]);
333 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof (*body));
334 memcpy(&body->id1, id, sizeof(*id));
336 size[0] = sizeof(*body);
337 size[1] = sizeof(struct mds_remote_perm);
338 req->rq_replen = lustre_msg_size(2, size);
340 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
341 rc = ptlrpc_queue_wait(req);
342 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
344 ptlrpc_req_finished (req);
347 body = lustre_swab_repbuf (req, 0, sizeof (*body),
348 lustre_swab_mds_body);
350 CERROR ("Can't unpack mds_body\n");
360 int mdc_getattr_lock(struct obd_export *exp, struct lustre_id *id,
361 char *filename, int namelen, __u64 valid,
362 unsigned int ea_size, struct ptlrpc_request **request)
364 struct ptlrpc_request *req;
365 struct mds_body *body;
366 int rc, size[3] = {0, sizeof(*body), namelen};
369 size[0] = lustre_secdesc_size();
371 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
372 MDS_GETATTR_LOCK, 3, size, NULL);
374 GOTO(out, rc = -ENOMEM);
376 lustre_pack_secdesc(req, size[0]);
378 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof (*body));
379 memcpy(&body->id1, id, sizeof(*id));
381 body->eadatasize = ea_size;
383 if (filename != NULL) {
384 LASSERT (strnlen (filename, namelen) == namelen - 1);
385 memcpy(lustre_msg_buf(req->rq_reqmsg, 2, namelen),
388 LASSERT(namelen == 1);
391 rc = mdc_getattr_common(exp, ea_size, req);
393 ptlrpc_req_finished (req);
401 /* This should be called with both the request and the reply still packed. */
402 int mdc_store_inode_generation(struct obd_export *exp,
403 struct ptlrpc_request *req,
404 int reqoff, int repoff)
406 struct mds_rec_create *rec =
407 lustre_msg_buf(req->rq_reqmsg, reqoff, sizeof(*rec));
408 struct mds_body *body =
409 lustre_msg_buf(req->rq_repmsg, repoff, sizeof(*body));
411 LASSERT (rec != NULL);
412 LASSERT (body != NULL);
414 memcpy(&rec->cr_replayid, &body->id1, sizeof(rec->cr_replayid));
415 DEBUG_REQ(D_HA, req, "storing generation for ino "DLID4,
416 OLID4(&rec->cr_replayid));
421 int mdc_unpack_acl(struct obd_export *exp_lmv, struct ptlrpc_request *req,
422 unsigned int offset, struct lustre_md *md)
424 struct posix_acl *acl;
425 struct mds_remote_perm *perm;
430 if (!(md->body->valid & OBD_MD_FLACL))
433 if (md->body->valid & OBD_MD_FLRMTACL) {
434 offset++; /* first 'size' is not used */
436 buf = lustre_swab_repbuf(req, offset, sizeof(*perm),
437 lustre_swab_remote_perm);
439 CERROR("Can't unpack remote perm\n");
443 OBD_ALLOC(perm, sizeof(*perm));
446 memcpy(perm, buf, sizeof(*perm));
447 md->remote_perm = perm;
449 size = le32_to_cpu(*(__u32 *) lustre_msg_buf(
450 req->rq_repmsg, offset, 4));
451 buf = lustre_msg_buf(req->rq_repmsg, offset + 1, size);
453 acl = posix_acl_from_xattr(buf, size);
456 CERROR("convert xattr to acl failed: %d\n", rc);
459 rc = posix_acl_valid(acl);
461 CERROR("acl valid error: %d\n", rc);
462 posix_acl_release(acl);
473 static int mdc_unpack_gskey(struct obd_export *exp_lmv, struct ptlrpc_request *req,
474 unsigned int *offset, struct lustre_md *md)
476 int key_off = 0, rc = 0, size = 0;
480 if (md->body->valid & OBD_MD_FLKEY) {
481 size = le32_to_cpu(*(__u32 *) lustre_msg_buf(req->rq_repmsg,
483 buf = lustre_msg_buf(req->rq_repmsg, key_off++, size);
485 CDEBUG(D_INFO, "buf %p key_off %d size %d \n",
487 md->key = (struct lustre_key *)buf;
495 int mdc_req2lustre_md(struct obd_export *exp_lmv, struct ptlrpc_request *req,
496 unsigned int offset, struct obd_export *exp_lov,
497 struct lustre_md *md)
499 struct lov_mds_md *lmm;
500 int rc = 0, reply_off;
504 memset(md, 0, sizeof(*md));
506 md->body = lustre_msg_buf(req->rq_repmsg, offset,
511 LASSERT_REPSWABBED(req, offset);
513 if (!(md->body->valid & OBD_MD_FLEASIZE) &&
514 !(md->body->valid & OBD_MD_FLDIREA))
517 if (S_ISREG(md->body->mode)) {
518 if (md->body->eadatasize == 0) {
519 CERROR("invalid EA size (0) is detected\n");
523 lmm = lustre_msg_buf(req->rq_repmsg, offset + 1,
524 md->body->eadatasize);
528 LASSERT(exp_lov != NULL);
530 rc = obd_unpackmd(exp_lov, &md->lsm, lmm,
531 md->body->eadatasize);
533 LASSERT(rc >= sizeof(*md->lsm));
536 } else if (S_ISDIR(md->body->mode)) {
537 /* dir can be non-splitted */
538 if (md->body->eadatasize == 0)
541 lmm = lustre_msg_buf(req->rq_repmsg, offset + 1,
542 md->body->eadatasize);
546 if (md->body->valid & OBD_MD_MEA) {
547 LASSERT(exp_lmv != NULL);
549 rc = obd_unpackmd(exp_lmv, (void *)&md->mea,
550 lmm, md->body->eadatasize);
552 LASSERT(rc >= sizeof(*md->mea));
557 LASSERT(S_ISCHR(md->body->mode) ||
558 S_ISBLK(md->body->mode) ||
559 S_ISFIFO(md->body->mode)||
560 S_ISLNK(md->body->mode) ||
561 S_ISSOCK(md->body->mode));
564 /* if anything wrong when unpacking md, we don't check acl
565 * stuff, for simplicity
570 reply_off = (md->body->valid & OBD_MD_FLEASIZE) ?
571 (offset + 2) : (offset + 1);
572 rc = mdc_unpack_acl(exp_lmv, req, reply_off, md);
574 CERROR("upack acl error %d \n", rc);
579 rc = mdc_unpack_gskey(exp_lmv, req, &reply_off, md);
586 static void mdc_commit_open(struct ptlrpc_request *req)
588 struct mdc_open_data *mod = req->rq_cb_data;
592 if (mod->mod_close_req != NULL)
593 mod->mod_close_req->rq_cb_data = NULL;
595 if (mod->mod_och != NULL)
596 mod->mod_och->och_mod = NULL;
598 OBD_FREE(mod, sizeof(*mod));
599 req->rq_cb_data = NULL;
600 LASSERT(atomic_read(&req->rq_refcount) > 1);
601 ptlrpc_req_finished(req);
604 static void mdc_replay_open(struct ptlrpc_request *req)
606 struct mdc_open_data *mod = req->rq_cb_data;
607 struct obd_client_handle *och;
608 struct ptlrpc_request *close_req;
609 struct lustre_handle old;
610 struct mds_body *body;
613 body = lustre_swab_repbuf(req, 1, sizeof(*body), lustre_swab_mds_body);
614 LASSERT (body != NULL);
617 DEBUG_REQ(D_ERROR, req,
618 "can't properly replay without open data");
625 struct lustre_handle *file_fh;
626 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
627 file_fh = &och->och_fh;
628 CDEBUG(D_HA, "updating handle from "LPX64" to "LPX64"\n",
629 file_fh->cookie, body->handle.cookie);
630 memcpy(&old, file_fh, sizeof(old));
631 memcpy(file_fh, &body->handle, sizeof(*file_fh));
634 close_req = mod->mod_close_req;
635 if (close_req != NULL) {
636 struct mds_body *close_body;
637 LASSERT(close_req->rq_reqmsg->opc == MDS_CLOSE);
638 close_body = lustre_msg_buf(close_req->rq_reqmsg,
640 sizeof(*close_body));
642 LASSERT(!memcmp(&old, &close_body->handle, sizeof old));
643 DEBUG_REQ(D_HA, close_req, "updating close body with new fh");
644 memcpy(&close_body->handle, &body->handle,
645 sizeof(close_body->handle));
651 int mdc_set_open_replay_data(struct obd_export *exp,
652 struct obd_client_handle *och,
653 struct ptlrpc_request *open_req)
655 struct mdc_open_data *mod;
656 struct mds_rec_create *rec;
657 struct mds_body *body;
659 rec = lustre_msg_buf(open_req->rq_reqmsg, MDS_REQ_INTENT_REC_OFF,
661 body = lustre_msg_buf(open_req->rq_repmsg, 1, sizeof(*body));
663 LASSERT(rec != NULL);
664 /* outgoing messages always in my byte order */
665 LASSERT(body != NULL);
666 /* incoming message in my byte order (it's been swabbed) */
667 LASSERT_REPSWABBED(open_req, 1);
669 OBD_ALLOC(mod, sizeof(*mod));
671 DEBUG_REQ(D_ERROR, open_req, "can't allocate mdc_open_data");
677 mod->mod_open_req = ptlrpc_request_addref(open_req);
679 if (memcmp(&rec->cr_replayid, &body->id1, sizeof(rec->cr_replayid)))
680 CDEBUG(D_ERROR, DLID4" != "DLID4"\n", OLID4(&rec->cr_replayid),
682 LASSERT(id_ino(&rec->cr_replayid) != 0);
683 memcpy(&rec->cr_replayid, &body->id1, sizeof rec->cr_replayid);
684 memcpy(&rec->cr_ioepoch, &body->io_epoch, sizeof rec->cr_ioepoch);
685 open_req->rq_replay_cb = mdc_replay_open;
686 open_req->rq_commit_cb = mdc_commit_open;
687 open_req->rq_cb_data = mod;
688 DEBUG_REQ(D_HA, open_req, "set up replay data");
692 int mdc_clear_open_replay_data(struct obd_export *exp,
693 struct obd_client_handle *och)
695 struct mdc_open_data *mod = och->och_mod;
697 /* Don't free the structure now (it happens in mdc_commit_open, after
698 * we're sure we won't need to fix up the close request in the future),
699 * but make sure that replay doesn't poke at the och, which is about to
701 LASSERT(mod != LP_POISON);
708 static void mdc_commit_close(struct ptlrpc_request *req)
710 struct mdc_open_data *mod = req->rq_cb_data;
711 struct obd_import *imp = req->rq_import;
712 struct ptlrpc_request *open_req;
714 DEBUG_REQ(D_HA, req, "close req committed");
718 mod->mod_close_req = NULL;
719 req->rq_cb_data = NULL;
720 req->rq_commit_cb = NULL;
722 open_req = mod->mod_open_req;
723 LASSERT(open_req != NULL);
724 LASSERT(open_req != LP_POISON);
725 LASSERT(open_req->rq_type != LI_POISON);
727 DEBUG_REQ(D_HA, open_req, "open req balanced");
728 if (open_req->rq_transno == 0) {
729 DEBUG_REQ(D_ERROR, open_req, "BUG 3892 open");
730 DEBUG_REQ(D_ERROR, req, "BUG 3892 close");
731 LASSERTF(open_req->rq_transno != 0, "BUG 3892\n");
733 LASSERT(open_req->rq_import == imp);
735 /* We no longer want to preserve this for transno-unconditional
737 spin_lock(&open_req->rq_lock);
738 open_req->rq_replay = 0;
739 spin_unlock(&open_req->rq_lock);
742 int mdc_close(struct obd_export *exp, struct mdc_op_data *op_data,
743 struct obd_client_handle *och, struct ptlrpc_request **request)
745 struct obd_device *obd = class_exp2obd(exp);
746 struct obd_import *imp = class_exp2cliimp(exp);
747 int reqsize[3] = {0, sizeof(struct mds_body),
748 obd->u.cli.cl_max_mds_cookiesize};
749 int rc, repsize[3] = {sizeof(struct mds_body),
750 obd->u.cli.cl_max_mds_easize,
751 obd->u.cli.cl_max_mds_cookiesize};
752 struct ptlrpc_request *req;
753 struct mdc_open_data *mod;
756 if (imp->imp_connection == NULL) {
757 CERROR("request on not connected import %s\n",
758 imp->imp_obd->obd_name);
762 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
763 MDS_CLOSE, 3, reqsize, NULL);
765 GOTO(out, rc = -ENOMEM);
766 //req->rq_request_portal = MDS_CLOSE_PORTAL;
768 /* ensure that this close's handle is fixed up during replay. */
769 LASSERT(och != NULL);
771 if (likely(mod != NULL)) {
772 mod->mod_close_req = req;
773 LASSERT(mod->mod_open_req->rq_type != LI_POISON);
774 DEBUG_REQ(D_HA, mod->mod_open_req, "matched open");
776 CDEBUG(D_HA, "couldn't find open req; "
777 "expecting close error\n");
780 mdc_close_pack(req, 1, op_data, och);
782 req->rq_replen = lustre_msg_size(3, repsize);
783 req->rq_commit_cb = mdc_commit_close;
784 LASSERT(req->rq_cb_data == NULL);
785 req->rq_cb_data = mod;
787 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
788 rc = ptlrpc_queue_wait(req);
789 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
791 if (req->rq_repmsg == NULL) {
792 CDEBUG(D_HA, "request failed to send: %p, %d\n", req,
795 rc = req->rq_status ? req->rq_status : -EIO;
796 } else if (rc == 0) {
797 rc = req->rq_repmsg->status;
798 if (req->rq_repmsg->type == PTL_RPC_MSG_ERR) {
799 DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, "
805 CERROR("Unexpected: can't find mdc_open_data, but "
806 "close succeeded. Please tell CFS.\n");
807 if (!lustre_swab_repbuf(req, 0, sizeof(struct mds_body),
808 lustre_swab_mds_body))
810 CERROR("Error unpacking mds_body\n");
822 int mdc_done_writing(struct obd_export *exp, struct obdo *obdo)
824 struct ptlrpc_request *req;
825 struct mds_body *body;
826 int rc, size[2] = {0, sizeof(*body)};
829 size[0] = lustre_secdesc_size();
831 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
832 MDS_DONE_WRITING, 2, size, NULL);
836 lustre_pack_secdesc(req, size[0]);
838 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF,
841 mdc_pack_id(&body->id1, obdo->o_id, 0, obdo->o_mode,
842 obdo->o_mds, obdo->o_fid);
844 body->size = obdo->o_size;
845 body->blocks = obdo->o_blocks;
846 body->flags = obdo->o_flags;
847 body->valid = obdo->o_valid;
849 req->rq_replen = lustre_msg_size(1, &size[1]);
851 rc = ptlrpc_queue_wait(req);
852 ptlrpc_req_finished(req);
856 int mdc_readpage(struct obd_export *exp,
857 struct lustre_id *id,
858 __u64 offset, struct page *page,
859 struct ptlrpc_request **request)
861 struct obd_import *imp = class_exp2cliimp(exp);
862 struct ptlrpc_request *req = NULL;
863 struct ptlrpc_bulk_desc *desc = NULL;
864 struct mds_body *body;
865 int rc, size[2] = {0, sizeof(*body)};
868 CDEBUG(D_INODE, "inode: %ld\n", (long)id->li_stc.u.e3s.l3s_ino);
870 size[0] = lustre_secdesc_size();
872 req = ptlrpc_prep_req(imp, LUSTRE_MDS_VERSION, MDS_READPAGE,
875 GOTO(out, rc = -ENOMEM);
876 /* XXX FIXME bug 249 */
877 req->rq_request_portal = MDS_READPAGE_PORTAL;
879 lustre_pack_secdesc(req, size[0]);
881 desc = ptlrpc_prep_bulk_imp(req, 1, BULK_PUT_SINK, MDS_BULK_PORTAL);
883 GOTO(out, rc = -ENOMEM);
884 /* NB req now owns desc and will free it when it gets freed */
886 ptlrpc_prep_bulk_page(desc, page, 0, PAGE_CACHE_SIZE);
887 mdc_readdir_pack(req, 1, offset, PAGE_CACHE_SIZE, id);
889 req->rq_replen = lustre_msg_size(1, &size[1]);
890 rc = ptlrpc_queue_wait(req);
893 body = lustre_swab_repbuf(req, 0, sizeof (*body),
894 lustre_swab_mds_body);
896 CERROR("Can't unpack mds_body\n");
897 GOTO(out, rc = -EPROTO);
900 if (req->rq_bulk->bd_nob_transferred != PAGE_CACHE_SIZE) {
901 CERROR ("Unexpected # bytes transferred: %d"
903 req->rq_bulk->bd_nob_transferred,
905 GOTO (out, rc = -EPROTO);
915 static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
916 void *karg, void *uarg)
918 struct obd_device *obd = exp->exp_obd;
919 struct obd_ioctl_data *data = karg;
920 struct obd_import *imp = obd->u.cli.cl_import;
921 struct llog_ctxt *ctxt;
925 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
928 if (!try_module_get(THIS_MODULE)) {
929 CERROR("Can't get module. Is it alive?");
934 case OBD_IOC_CLIENT_RECOVER:
935 rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1);
939 case IOC_OSC_SET_ACTIVE:
940 rc = ptlrpc_set_import_active(imp, data->ioc_offset);
942 case IOC_OSC_CTL_RECOVERY:
943 rc = ptlrpc_import_control_recovery(imp, data->ioc_offset);
945 case OBD_IOC_PARSE: {
946 ctxt = llog_get_context(&exp->exp_obd->obd_llogs,
947 LLOG_CONFIG_REPL_CTXT);
948 rc = class_config_process_llog(ctxt, data->ioc_inlbuf1, NULL);
952 case OBD_IOC_LLOG_INFO:
953 case OBD_IOC_LLOG_PRINT: {
954 ctxt = llog_get_context(&obd->obd_llogs, LLOG_CONFIG_REPL_CTXT);
955 rc = llog_ioctl(ctxt, cmd, data);
961 CERROR("mdc_ioctl(): unrecognised ioctl %#x\n", cmd);
962 GOTO(out, rc = -ENOTTY);
965 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
968 module_put(THIS_MODULE);
974 int mdc_set_info(struct obd_export *exp, obd_count keylen,
975 void *key, obd_count vallen, void *val)
979 if (keylen == strlen("initial_recov") &&
980 memcmp(key, "initial_recov", strlen("initial_recov")) == 0) {
981 struct obd_import *imp = exp->exp_obd->u.cli.cl_import;
982 if (vallen != sizeof(int))
984 imp->imp_initial_recov = *(int *)val;
985 CDEBUG(D_HA, "%s: set imp_no_init_recov = %d\n",
986 exp->exp_obd->obd_name,
987 imp->imp_initial_recov);
989 } else if ((keylen >= strlen("crypto_type")) &&
990 strcmp(key, "crypto_type") == 0) {
991 struct ptlrpc_request *req;
992 char *bufs[2] = {key, val};
993 int rc, size[2] = {keylen, vallen};
995 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
996 OST_SET_INFO, 2, size, bufs);
1000 req->rq_replen = lustre_msg_size(0, NULL);
1001 rc = ptlrpc_queue_wait(req);
1002 ptlrpc_req_finished(req);
1004 } else if (keylen >= strlen("inter_mds") && strcmp(key, "inter_mds") == 0) {
1005 struct obd_import *imp = class_exp2cliimp(exp);
1006 imp->imp_server_timeout = 1;
1007 CDEBUG(D_OTHER, "%s: timeout / 2\n", exp->exp_obd->obd_name);
1009 } else if (keylen == strlen("sec") &&
1010 memcmp(key, "sec", keylen) == 0) {
1011 struct client_obd *cli = &exp->exp_obd->u.cli;
1013 cli->cl_sec_flavor = ptlrpcs_name2flavor(val);
1014 if (cli->cl_sec_flavor == PTLRPCS_FLVR_INVALID) {
1015 CERROR("unrecognized security type %s\n", (char*) val);
1020 } else if (keylen == strlen("sec_flags") &&
1021 memcmp(key, "sec_flags", keylen) == 0) {
1022 struct client_obd *cli = &exp->exp_obd->u.cli;
1024 cli->cl_sec_flags = *((unsigned long *) val);
1026 } else if (keylen == strlen("flush_cred") &&
1027 memcmp(key, "flush_cred", keylen) == 0) {
1028 struct client_obd *cli = &exp->exp_obd->u.cli;
1031 ptlrpcs_import_flush_current_creds(cli->cl_import);
1033 } else if (keylen == strlen("async") && memcmp(key, "async", keylen) == 0) {
1034 struct client_obd *cl = &exp->exp_obd->u.cli;
1035 if (vallen != sizeof(int))
1037 cl->cl_async = *(int *)val;
1038 CDEBUG(D_HA, "%s: set async = %d\n",
1039 exp->exp_obd->obd_name, cl->cl_async);
1041 } else if (keylen == strlen("setext") && memcmp(key, "setext", keylen) == 0) {
1042 struct ptlrpc_request *req;
1043 char *bufs[2] = {key, val};
1044 int rc, size[2] = {keylen, vallen};
1046 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1047 OST_SET_INFO, 2, size, bufs);
1051 req->rq_replen = lustre_msg_size(0, NULL);
1052 rc = ptlrpc_queue_wait(req);
1053 ptlrpc_req_finished(req);
1055 } else if (keylen == 5 && strcmp(key, "audit") == 0) {
1056 struct ptlrpc_request *req;
1057 char *bufs[2] = {key, val};
1058 int rc, size[2] = {keylen, vallen};
1060 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1061 OST_SET_INFO, 2, size, bufs);
1065 req->rq_replen = lustre_msg_size(0, NULL);
1066 lustre_swab_reqbuf(req, 1, sizeof(struct audit_attr_msg),
1067 lustre_swab_audit_attr);
1068 rc = ptlrpc_queue_wait(req);
1069 ptlrpc_req_finished(req);
1072 } else if (keylen == strlen("ids") && memcmp(key, "ids", keylen) == 0) {
1073 struct ptlrpc_request *req;
1074 struct lustre_id *ids = (struct lustre_id *)val;
1075 char *bufs[3] = {key, (char *)ids, (char *)(ids + 1)};
1076 int rc, size[3] = {keylen, sizeof(struct lustre_id),
1077 sizeof(struct lustre_id)};
1079 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1080 OST_SET_INFO, 3, size, bufs);
1084 req->rq_replen = lustre_msg_size(0, NULL);
1085 rc = ptlrpc_queue_wait(req);
1086 ptlrpc_req_finished(req);
1092 static int mdc_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1093 unsigned long max_age)
1095 struct obd_statfs *msfs;
1096 struct ptlrpc_request *req;
1097 int rc, size = sizeof(*msfs);
1100 /* We could possibly pass max_age in the request (as an absolute
1101 * timestamp or a "seconds.usec ago") so the target can avoid doing
1102 * extra calls into the filesystem if that isn't necessary (e.g.
1103 * during mount that would help a bit). Having relative timestamps
1104 * is not so great if request processing is slow, while absolute
1105 * timestamps are not ideal because they need time synchronization. */
1106 req = ptlrpc_prep_req(obd->u.cli.cl_import, LUSTRE_MDS_VERSION,
1107 MDS_STATFS, 0, NULL, NULL);
1111 req->rq_replen = lustre_msg_size(1, &size);
1113 mdc_get_rpc_lock(obd->u.cli.cl_rpc_lock, NULL);
1114 rc = ptlrpc_queue_wait(req);
1115 mdc_put_rpc_lock(obd->u.cli.cl_rpc_lock, NULL);
1118 /* this can be LMV fake import, whcih is not connected. */
1119 if (!req->rq_import->imp_connection)
1120 memset(osfs, 0, sizeof(*osfs));
1124 msfs = lustre_swab_repbuf(req, 0, sizeof(*msfs),
1125 lustre_swab_obd_statfs);
1127 CERROR("Can't unpack obd_statfs\n");
1128 GOTO(out, rc = -EPROTO);
1131 memcpy(osfs, msfs, sizeof (*msfs));
1134 ptlrpc_req_finished(req);
1138 static int mdc_pin(struct obd_export *exp, obd_id ino, __u32 gen, int type,
1139 struct obd_client_handle *handle, int flag)
1141 struct ptlrpc_request *req;
1142 struct mds_body *body;
1143 int rc, size[2] = {0, sizeof(*body)};
1146 //size[0] = lustre_secdesc_size();
1148 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1149 MDS_PIN, 2, size, NULL);
1153 //lustre_pack_secdesc(req, size[0]);
1155 body = lustre_msg_buf(req->rq_reqmsg,
1156 MDS_REQ_REC_OFF, sizeof(*body));
1158 /* FIXME-UMKA: here should be also mdsnum and fid. */
1159 mdc_pack_id(&body->id1, ino, gen, type, 0, 0);
1162 req->rq_replen = lustre_msg_size(1, &size[1]);
1164 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1165 rc = ptlrpc_queue_wait(req);
1166 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1168 CERROR("pin failed: %d\n", rc);
1169 ptlrpc_req_finished(req);
1173 body = lustre_swab_repbuf(req, 0, sizeof(*body), lustre_swab_mds_body);
1175 ptlrpc_req_finished(req);
1179 memcpy(&handle->och_fh, &body->handle, sizeof(body->handle));
1180 handle->och_magic = OBD_CLIENT_HANDLE_MAGIC;
1182 OBD_ALLOC(handle->och_mod, sizeof(*handle->och_mod));
1183 if (handle->och_mod == NULL) {
1184 DEBUG_REQ(D_ERROR, req, "can't allocate mdc_open_data");
1187 handle->och_mod->mod_open_req = req; /* will be dropped by unpin */
1192 static int mdc_unpin(struct obd_export *exp,
1193 struct obd_client_handle *handle, int flag)
1195 struct ptlrpc_request *req;
1196 struct mds_body *body;
1197 int rc, size[2] = {0, sizeof(*body)};
1200 if (handle->och_magic != OBD_CLIENT_HANDLE_MAGIC)
1203 //size[0] = lustre_secdesc_size();
1205 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1206 MDS_CLOSE, 2, size, NULL);
1210 //lustre_pack_secdesc(req, size[0]);
1212 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof(*body));
1213 memcpy(&body->handle, &handle->och_fh, sizeof(body->handle));
1216 req->rq_replen = lustre_msg_size(0, NULL);
1217 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1218 rc = ptlrpc_queue_wait(req);
1219 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1222 CERROR("unpin failed: %d\n", rc);
1224 ptlrpc_req_finished(req);
1225 ptlrpc_req_finished(handle->och_mod->mod_open_req);
1226 OBD_FREE(handle->och_mod, sizeof(*handle->och_mod));
1230 int mdc_sync(struct obd_export *exp, struct lustre_id *id,
1231 struct ptlrpc_request **request)
1233 struct ptlrpc_request *req;
1234 struct mds_body *body;
1235 int size[2] = {0, sizeof(*body)};
1239 //size[0] = lustre_secdesc_size();
1241 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1242 MDS_SYNC, 2, size, NULL);
1244 RETURN(rc = -ENOMEM);
1246 //lustre_pack_secdesc(req, size[0]);
1249 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF,
1251 memcpy(&body->id1, id, sizeof(*id));
1254 req->rq_replen = lustre_msg_size(1, &size[1]);
1256 rc = ptlrpc_queue_wait(req);
1257 if (rc || request == NULL)
1258 ptlrpc_req_finished(req);
1265 static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
1266 enum obd_import_event event)
1270 LASSERT(imp->imp_obd == obd);
1273 case IMP_EVENT_DISCON: {
1276 case IMP_EVENT_INACTIVE: {
1277 if (obd->obd_observer)
1278 rc = obd_notify(obd->obd_observer, obd, 0, 0);
1281 case IMP_EVENT_INVALIDATE: {
1282 struct ldlm_namespace *ns = obd->obd_namespace;
1284 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
1288 case IMP_EVENT_ACTIVE: {
1289 if (obd->obd_observer)
1290 rc = obd_notify(obd->obd_observer, obd, 1, 0);
1294 CERROR("Unknown import event %d\n", event);
1300 static int mdc_attach(struct obd_device *dev, obd_count len, void *data)
1302 struct lprocfs_static_vars lvars;
1304 lprocfs_init_vars(mdc, &lvars);
1305 return lprocfs_obd_attach(dev, lvars.obd_vars);
1308 static int mdc_detach(struct obd_device *dev)
1310 return lprocfs_obd_detach(dev);
1313 static int mdc_setup(struct obd_device *obd, obd_count len, void *buf)
1315 struct client_obd *cli = &obd->u.cli;
1319 OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1320 if (!cli->cl_rpc_lock)
1322 mdc_init_rpc_lock(cli->cl_rpc_lock);
1326 OBD_ALLOC(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1327 if (!cli->cl_setattr_lock)
1328 GOTO(err_rpc_lock, rc = -ENOMEM);
1329 mdc_init_rpc_lock(cli->cl_setattr_lock);
1331 OBD_ALLOC(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1332 if (!cli->cl_close_lock)
1333 GOTO(err_setattr_lock, rc = -ENOMEM);
1334 mdc_init_rpc_lock(cli->cl_close_lock);
1336 rc = client_obd_setup(obd, len, buf);
1338 GOTO(err_close_lock, rc);
1340 rc = obd_llog_init(obd, &obd->obd_llogs, obd, 0, NULL);
1342 mdc_cleanup(obd, 0);
1343 CERROR("failed to setup llogging subsystems\n");
1349 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1351 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1353 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1358 static int mdc_init_ea_size(struct obd_export *exp, int easize, int cookiesize)
1360 struct obd_device *obd = exp->exp_obd;
1361 struct client_obd *cli = &obd->u.cli;
1364 if (cli->cl_max_mds_easize < easize)
1365 cli->cl_max_mds_easize = easize;
1366 if (cli->cl_max_mds_cookiesize < cookiesize)
1367 cli->cl_max_mds_cookiesize = cookiesize;
1371 static int mdc_precleanup(struct obd_device *obd, int flags)
1375 rc = obd_llog_finish(obd, &obd->obd_llogs, 0);
1377 CERROR("failed to cleanup llogging subsystems\n");
1382 static int mdc_cleanup(struct obd_device *obd, int flags)
1384 struct client_obd *cli = &obd->u.cli;
1386 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1387 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1388 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1392 return client_obd_cleanup(obd, flags);
1396 static int mdc_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
1397 struct obd_device *tgt, int count,
1398 struct llog_catid *logid)
1400 struct llog_ctxt *ctxt;
1404 rc = obd_llog_setup(obd, llogs, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
1407 ctxt = llog_get_context(llogs, LLOG_CONFIG_REPL_CTXT);
1408 ctxt->loc_imp = obd->u.cli.cl_import;
1414 static int mdc_llog_finish(struct obd_device *obd,
1415 struct obd_llogs *llogs, int count)
1420 rc = obd_llog_cleanup(llog_get_context(llogs, LLOG_CONFIG_REPL_CTXT));
1424 static struct obd_device *mdc_get_real_obd(struct obd_export *exp,
1425 struct lustre_id *id)
1428 RETURN(exp->exp_obd);
1431 static int mdc_get_info(struct obd_export *exp, __u32 keylen,
1432 void *key, __u32 *valsize, void *val)
1434 struct ptlrpc_request *req;
1435 char *bufs[1] = {key};
1439 if (!valsize || !val)
1442 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
1443 struct obd_import *imp;
1444 struct obd_connect_data *data;
1446 imp = class_exp2cliimp(exp);
1452 if (imp->imp_state != LUSTRE_IMP_FULL) {
1453 CERROR("import state not full\n");
1457 data = &imp->imp_connect_data;
1458 if (data->ocd_connect_flags & OBD_CONNECT_REMOTE) {
1461 } else if (data->ocd_connect_flags & OBD_CONNECT_LOCAL) {
1465 CERROR("no remote flag set?\n");
1469 if ((keylen < strlen("mdsize") || strcmp(key, "mdsize") != 0) &&
1470 (keylen < strlen("mdsnum") || strcmp(key, "mdsnum") != 0) &&
1471 (keylen < strlen("lovdesc") || strcmp(key, "lovdesc") != 0) &&
1472 (keylen < strlen("getext") || strcmp(key, "getext") != 0) &&
1473 (keylen < strlen("rootid") || strcmp(key, "rootid") != 0) &&
1474 (keylen < strlen("auditid") || strcmp(key, "auditid") != 0))
1477 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1478 OST_GET_INFO, 1, (int *)&keylen, bufs);
1482 req->rq_replen = lustre_msg_size(1, (int *)valsize);
1483 rc = ptlrpc_queue_wait(req);
1487 if ((keylen >= strlen("rootid") && !strcmp(key, "rootid")) ||
1488 (keylen >= strlen("auditid") && !strcmp(key, "auditid"))) {
1489 struct lustre_id *reply;
1491 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
1492 lustre_swab_lustre_id);
1493 if (reply == NULL) {
1494 CERROR("Can't unpack %s\n", (char *)key);
1495 GOTO(out_req, rc = -EPROTO);
1498 *(struct lustre_id *)val = *reply;
1499 } else if (keylen >= strlen("lovdesc") && !strcmp(key, "lovdesc")) {
1500 struct lov_desc *reply;
1502 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
1503 lustre_swab_lov_desc);
1504 if (reply == NULL) {
1505 CERROR("Can't unpack %s\n", (char *)key);
1506 GOTO(out_req, rc = -EPROTO);
1509 *(struct lov_desc *)val = *reply;
1511 } else if (keylen >= strlen("getext") && !strcmp(key, "getext")) {
1512 struct fid_extent *reply;
1514 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
1515 lustre_swab_fid_extent);
1516 if (reply == NULL) {
1517 CERROR("Can't unpack %s\n", (char *)key);
1518 GOTO(out_req, rc = -EPROTO);
1521 *(struct fid_extent *)val = *reply;
1526 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
1527 lustre_swab_generic_32s);
1528 if (reply == NULL) {
1529 CERROR("Can't unpack %s\n", (char *)key);
1530 GOTO(out_req, rc = -EPROTO);
1532 *((__u32 *)val) = *reply;
1535 ptlrpc_req_finished(req);
1539 int mdc_obj_create(struct obd_export *exp, struct obdo *oa,
1540 void *acl, int acl_size, struct lov_stripe_md **ea,
1541 struct obd_trans_info *oti)
1543 struct ptlrpc_request *request;
1544 struct ost_body *body;
1546 int rc, size[2] = { sizeof(*body), acl_size };
1551 request = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1552 OST_CREATE, 2, size, NULL);
1554 GOTO(out_req, rc = -ENOMEM);
1556 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
1557 memcpy(&body->oa, oa, sizeof(body->oa));
1560 acl_buf = lustre_msg_buf(request->rq_reqmsg, 1, acl_size);
1561 memcpy(acl_buf, acl, acl_size);
1564 request->rq_replen = lustre_msg_size(1, size);
1565 rc = ptlrpc_queue_wait(request);
1569 body = lustre_swab_repbuf(request, 0, sizeof(*body),
1570 lustre_swab_ost_body);
1572 CERROR ("can't unpack ost_body\n");
1573 GOTO (out_req, rc = -EPROTO);
1576 memcpy(oa, &body->oa, sizeof(*oa));
1578 /* store ino/generation for recovery */
1579 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
1580 body->oa.o_id = oa->o_id;
1581 body->oa.o_generation = oa->o_generation;
1582 body->oa.o_fid = oa->o_fid;
1583 body->oa.o_mds = oa->o_mds;
1585 CDEBUG(D_HA, "transno: "LPD64"\n", request->rq_repmsg->transno);
1588 ptlrpc_req_finished(request);
1592 int mdc_brw(int rw, struct obd_export *exp, struct obdo *oa,
1593 struct lov_stripe_md *ea, obd_count oa_bufs,
1594 struct brw_page *pgarr, struct obd_trans_info *oti)
1596 struct ptlrpc_bulk_desc *desc;
1597 struct niobuf_remote *niobuf;
1598 struct ptlrpc_request *req;
1599 struct obd_ioobj *ioobj;
1600 struct ost_body *body;
1604 opc = ((rw & OBD_BRW_WRITE) != 0) ? OST_WRITE : OST_READ;
1606 size[0] = sizeof(*body);
1607 size[1] = sizeof(*ioobj);
1608 size[2] = oa_bufs * sizeof(*niobuf);
1610 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION, opc,
1612 LASSERT(req != NULL);
1614 if (opc == OST_WRITE)
1615 desc = ptlrpc_prep_bulk_imp(req, oa_bufs, BULK_GET_SOURCE,
1618 desc = ptlrpc_prep_bulk_imp(req, oa_bufs, BULK_PUT_SINK,
1620 LASSERT(desc != NULL);
1622 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
1623 ioobj = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*ioobj));
1624 niobuf = lustre_msg_buf(req->rq_reqmsg, 2, oa_bufs * sizeof(*niobuf));
1626 memcpy(&body->oa, oa, sizeof(*oa));
1627 obdo_to_ioobj(oa, ioobj);
1628 ioobj->ioo_bufcnt = oa_bufs;
1630 for (i = 0; i < oa_bufs; i++, niobuf++) {
1631 struct brw_page *pg = &pgarr[i];
1633 LASSERT(pg->count > 0);
1634 LASSERT((pg->disk_offset & ~PAGE_MASK) + pg->count <= PAGE_SIZE);
1636 ptlrpc_prep_bulk_page(desc, pg->pg, pg->disk_offset & ~PAGE_MASK,
1639 niobuf->offset = pg->disk_offset;
1640 niobuf->len = pg->count;
1641 niobuf->flags = pg->flag;
1644 /* size[0] still sizeof (*body) */
1645 if (opc == OST_WRITE) {
1646 /* 1 RC per niobuf */
1647 size[1] = sizeof(__u32) * oa_bufs;
1648 req->rq_replen = lustre_msg_size(2, size);
1650 /* 1 RC for the whole I/O */
1651 req->rq_replen = lustre_msg_size(1, size);
1653 err = ptlrpc_queue_wait(req);
1656 ptlrpc_req_finished(req);
1660 static int mdc_valid_attrs(struct obd_export *exp,
1661 struct lustre_id *id)
1663 struct ldlm_res_id res_id = { .name = {0} };
1664 struct obd_device *obd = exp->exp_obd;
1665 struct lustre_handle lockh;
1666 ldlm_policy_data_t policy;
1670 res_id.name[0] = id_fid(id);
1671 res_id.name[1] = id_group(id);
1672 policy.l_inodebits.bits = MDS_INODELOCK_UPDATE;
1674 CDEBUG(D_INFO, "trying to match res "LPU64"\n",
1677 /* FIXME use LDLM_FL_TEST_LOCK instead */
1678 flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_CBPENDING;
1679 if (ldlm_lock_match(obd->obd_namespace, flags, &res_id,
1680 LDLM_IBITS, &policy, LCK_PR, &lockh)) {
1681 ldlm_lock_decref(&lockh, LCK_PR);
1685 if (ldlm_lock_match(obd->obd_namespace, flags, &res_id,
1686 LDLM_IBITS, &policy, LCK_PW, &lockh)) {
1687 ldlm_lock_decref(&lockh, LCK_PW);
1693 static int mdc_change_cbdata_name(struct obd_export *exp,
1694 struct lustre_id *pid,
1695 char *name, int len,
1696 struct lustre_id *cid,
1697 ldlm_iterator_t it, void *data)
1700 rc = mdc_change_cbdata(exp, cid, it, data);
1704 struct obd_ops mdc_obd_ops = {
1705 .o_owner = THIS_MODULE,
1706 .o_attach = mdc_attach,
1707 .o_detach = mdc_detach,
1708 .o_setup = mdc_setup,
1709 .o_precleanup = mdc_precleanup,
1710 .o_cleanup = mdc_cleanup,
1711 .o_add_conn = client_import_add_conn,
1712 .o_del_conn = client_import_del_conn,
1713 .o_connect = client_connect_import,
1714 .o_disconnect = client_disconnect_export,
1715 .o_iocontrol = mdc_iocontrol,
1716 .o_packmd = mdc_packmd,
1717 .o_unpackmd = mdc_unpackmd,
1718 .o_statfs = mdc_statfs,
1720 .o_unpin = mdc_unpin,
1721 .o_import_event = mdc_import_event,
1722 .o_llog_init = mdc_llog_init,
1723 .o_llog_finish = mdc_llog_finish,
1724 .o_create = mdc_obj_create,
1725 .o_set_info = mdc_set_info,
1726 .o_get_info = mdc_get_info,
1728 .o_cancel_unused = mdc_cancel_unused,
1729 .o_init_ea_size = mdc_init_ea_size,
1732 struct md_ops mdc_md_ops = {
1733 .m_getstatus = mdc_getstatus,
1734 .m_getattr = mdc_getattr,
1735 .m_close = mdc_close,
1736 .m_create = mdc_create,
1737 .m_done_writing = mdc_done_writing,
1738 .m_enqueue = mdc_enqueue,
1739 .m_getattr_lock = mdc_getattr_lock,
1740 .m_intent_lock = mdc_intent_lock,
1742 .m_rename = mdc_rename,
1743 .m_setattr = mdc_setattr,
1745 .m_readpage = mdc_readpage,
1746 .m_unlink = mdc_unlink,
1747 .m_valid_attrs = mdc_valid_attrs,
1748 .m_req2lustre_md = mdc_req2lustre_md,
1749 .m_set_open_replay_data = mdc_set_open_replay_data,
1750 .m_clear_open_replay_data = mdc_clear_open_replay_data,
1751 .m_store_inode_generation = mdc_store_inode_generation,
1752 .m_set_lock_data = mdc_set_lock_data,
1753 .m_get_real_obd = mdc_get_real_obd,
1754 .m_change_cbdata_name = mdc_change_cbdata_name,
1755 .m_change_cbdata = mdc_change_cbdata,
1756 .m_access_check = mdc_access_check,
1759 int __init mdc_init(void)
1761 struct lprocfs_static_vars lvars;
1763 lprocfs_init_vars(mdc, &lvars);
1764 return class_register_type(&mdc_obd_ops, &mdc_md_ops,
1765 lvars.module_vars, OBD_MDC_DEVICENAME);
1769 static void /*__exit*/ mdc_exit(void)
1771 class_unregister_type(OBD_MDC_DEVICENAME);
1774 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1775 MODULE_DESCRIPTION("Lustre Metadata Client");
1776 MODULE_LICENSE("GPL");
1778 EXPORT_SYMBOL(mdc_req2lustre_md);
1779 EXPORT_SYMBOL(mdc_change_cbdata);
1780 EXPORT_SYMBOL(mdc_getstatus);
1781 EXPORT_SYMBOL(mdc_getattr);
1782 EXPORT_SYMBOL(mdc_getattr_lock);
1783 EXPORT_SYMBOL(mdc_create);
1784 EXPORT_SYMBOL(mdc_unlink);
1785 EXPORT_SYMBOL(mdc_rename);
1786 EXPORT_SYMBOL(mdc_link);
1787 EXPORT_SYMBOL(mdc_readpage);
1788 EXPORT_SYMBOL(mdc_setattr);
1789 EXPORT_SYMBOL(mdc_close);
1790 EXPORT_SYMBOL(mdc_done_writing);
1791 EXPORT_SYMBOL(mdc_sync);
1792 EXPORT_SYMBOL(mdc_set_open_replay_data);
1793 EXPORT_SYMBOL(mdc_clear_open_replay_data);
1794 EXPORT_SYMBOL(mdc_store_inode_generation);
1796 module_init(mdc_init);
1797 module_exit(mdc_exit);