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 lustre_capa *capa = NULL;
110 unsigned long expiry;
114 DEBUG_REQ(D_ERROR, req,
115 "async getattr failed: rc = %d", rc);
119 body = lustre_swab_repbuf(req, 0, sizeof (*body), lustre_swab_mds_body);
121 CERROR ("Can't unpack mds_body\n");
125 if (!(body->valid & OBD_MD_CAPA)) {
126 CDEBUG(D_INFO, "MDS has disabled capability\n");
130 capa = lustre_swab_repbuf(req, 1, sizeof(*capa),
131 lustre_swab_lustre_capa);
132 if (capa == NULL && rc != 0) {
133 CERROR ("Can't unpack lustre_capa\n");
137 rc = capa_renew(capa, CLIENT_CAPA);
141 DEBUG_CAPA(D_INFO, capa, "capa renewal");
143 spin_lock(&capa_lock);
144 expiry = expiry_to_jiffies(capa->lc_expiry - capa_pre_expiry(capa));
145 if (time_before(expiry, ll_capa_timer.expires) ||
146 !timer_pending(&ll_capa_timer)) {
147 mod_timer(&ll_capa_timer, expiry);
148 CDEBUG(D_INFO, "ll_capa_timer new timer: %lu\n", expiry);
150 spin_unlock(&capa_lock);
155 int mdc_getattr_async(struct obd_export *exp, struct ptlrpc_request *req)
157 int repsize[2] = {sizeof(struct mds_body), sizeof(struct lustre_capa)};
160 req->rq_replen = lustre_msg_size(2, repsize);
161 req->rq_interpret_reply = mdc_interpret_getattr;
162 ptlrpcd_add_req(req);
167 int mdc_getattr_common(struct obd_export *exp, unsigned int ea_size,
168 struct ptlrpc_request *req)
170 struct mds_body *body, *reqbody;
173 int repsize[2] = {sizeof(*body)};
177 /* request message already built */
180 repsize[bufcount++] = ea_size;
181 CDEBUG(D_INODE, "reserved %u bytes for MD/symlink in packet\n",
185 reqbody = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*reqbody));
186 LASSERT(!(reqbody->valid & OBD_MD_FLACL));
188 if (reqbody->valid & OBD_MD_FLKEY) {
189 repsize[bufcount++] = 5;
190 repsize[bufcount++] = sizeof(struct lustre_key);
191 } else if (reqbody->valid & OBD_MD_CAPA) {
192 LASSERT(ea_size == 0);
193 repsize[bufcount++] = sizeof(struct lustre_capa);
196 req->rq_replen = lustre_msg_size(bufcount, repsize);
198 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
199 rc = ptlrpc_queue_wait(req);
200 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
204 body = lustre_swab_repbuf (req, 0, sizeof (*body),
205 lustre_swab_mds_body);
207 CERROR ("Can't unpack mds_body\n");
211 CDEBUG(D_NET, "mode: %o\n", body->mode);
213 LASSERT_REPSWAB (req, 1);
215 /* Skip the check if getxattr/listxattr are called with no buffers */
216 if ((reqbody->eadatasize != 0) &&
217 !(reqbody->valid & (OBD_MD_FLXATTR | OBD_MD_FLXATTRLIST))) {
218 /* reply indicates presence of eadata; check it's there... */
219 eadata = lustre_msg_buf (req->rq_repmsg, 1,
221 if (eadata == NULL) {
222 CERROR ("Missing/short eadata\n");
230 static int mdc_cancel_unused(struct obd_export *exp,
231 struct lov_stripe_md *lsm,
232 int flags, void *opaque)
234 struct obd_device *obd = class_exp2obd(exp);
237 RETURN(ldlm_cli_cancel_unused(obd->obd_namespace,
238 NULL, flags, opaque));
241 int mdc_getattr(struct obd_export *exp, struct lustre_id *id,
242 __u64 valid, const char *xattr_name,
243 const void *xattr_data, unsigned int xattr_datalen,
244 unsigned int ea_size, struct obd_capa *ocapa,
245 struct ptlrpc_request **request)
247 struct ptlrpc_request *req;
248 struct mds_body *body;
249 int xattr_namelen = xattr_name ? strlen(xattr_name) + 1 : 0;
250 int size[4] = {0, sizeof(*body)};
255 size[0] = lustre_secdesc_size();
257 if (valid & OBD_MD_FLXATTR) {
258 size[bufcount++] = xattr_namelen;
260 if (xattr_datalen > 0) {
262 size[bufcount++] = xattr_datalen;
264 } else if (valid & OBD_MD_CAPA) {
265 LASSERT(valid == OBD_MD_CAPA);
267 size[bufcount++] = sizeof(*ocapa);
269 LASSERT(!xattr_data && !xattr_datalen);
272 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
273 MDS_GETATTR, bufcount, size, NULL);
275 GOTO(out, rc = -ENOMEM);
277 lustre_pack_secdesc(req, size[0]);
279 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof (*body));
280 memcpy(&body->id1, id, sizeof(*id));
282 body->eadatasize = ea_size;
284 if (valid & OBD_MD_FLXATTR) {
285 memcpy(lustre_msg_buf(req->rq_reqmsg, 2, xattr_namelen),
286 xattr_name, xattr_namelen);
288 memcpy(lustre_msg_buf(req->rq_reqmsg, 3, xattr_datalen),
289 xattr_data, xattr_datalen);
292 if (valid & OBD_MD_CAPA) {
293 /* renew capability */
294 memcpy(&body->handle, &ocapa->c_handle, sizeof(body->handle));
295 memcpy(lustre_msg_buf(req->rq_reqmsg, 2, sizeof(ocapa->c_capa)),
296 &ocapa->c_capa, sizeof(ocapa->c_capa));
298 rc = mdc_getattr_async(exp, req);
299 req = NULL; /* ptlrpcd will finish request */
301 rc = mdc_getattr_common(exp, ea_size, req);
303 ptlrpc_req_finished (req);
312 int mdc_access_check(struct obd_export *exp, struct lustre_id *id,
313 struct ptlrpc_request **request)
316 struct ptlrpc_request *req;
317 struct mds_body *body;
318 int size[2] = {0, sizeof(*body)};
322 size[0] = lustre_secdesc_size();
323 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
324 MDS_ACCESS_CHECK, 2, size, NULL);
326 GOTO(out, rc = -ENOMEM);
328 lustre_pack_secdesc(req, size[0]);
329 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof (*body));
330 memcpy(&body->id1, id, sizeof(*id));
332 size[0] = sizeof(*body);
333 size[1] = sizeof(struct mds_remote_perm);
334 req->rq_replen = lustre_msg_size(2, size);
336 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
337 rc = ptlrpc_queue_wait(req);
338 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
340 ptlrpc_req_finished (req);
343 body = lustre_swab_repbuf (req, 0, sizeof (*body),
344 lustre_swab_mds_body);
346 CERROR ("Can't unpack mds_body\n");
356 int mdc_getattr_lock(struct obd_export *exp, struct lustre_id *id,
357 char *filename, int namelen, __u64 valid,
358 unsigned int ea_size, struct ptlrpc_request **request)
360 struct ptlrpc_request *req;
361 struct mds_body *body;
362 int rc, size[3] = {0, sizeof(*body), namelen};
365 size[0] = lustre_secdesc_size();
367 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
368 MDS_GETATTR_LOCK, 3, size, NULL);
370 GOTO(out, rc = -ENOMEM);
372 lustre_pack_secdesc(req, size[0]);
374 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof (*body));
375 memcpy(&body->id1, id, sizeof(*id));
377 body->eadatasize = ea_size;
379 if (filename != NULL) {
380 LASSERT (strnlen (filename, namelen) == namelen - 1);
381 memcpy(lustre_msg_buf(req->rq_reqmsg, 2, namelen),
384 LASSERT(namelen == 1);
387 rc = mdc_getattr_common(exp, ea_size, req);
389 ptlrpc_req_finished (req);
397 /* This should be called with both the request and the reply still packed. */
398 int mdc_store_inode_generation(struct obd_export *exp,
399 struct ptlrpc_request *req,
400 int reqoff, int repoff)
402 struct mds_rec_create *rec =
403 lustre_msg_buf(req->rq_reqmsg, reqoff, sizeof(*rec));
404 struct mds_body *body =
405 lustre_msg_buf(req->rq_repmsg, repoff, sizeof(*body));
407 LASSERT (rec != NULL);
408 LASSERT (body != NULL);
410 memcpy(&rec->cr_replayid, &body->id1, sizeof(rec->cr_replayid));
411 DEBUG_REQ(D_HA, req, "storing generation for ino "DLID4,
412 OLID4(&rec->cr_replayid));
416 int mdc_req2lustre_capa(struct ptlrpc_request *req, unsigned int offset,
417 struct lustre_capa **capa)
419 struct mds_body *body;
420 struct lustre_capa *lcapa;
422 body = lustre_msg_buf(req->rq_repmsg, offset, sizeof(*body));
426 if (!(body->valid & OBD_MD_CAPA)) {
431 lcapa = (struct lustre_capa *)lustre_swab_repbuf(req, offset + 1,
432 sizeof(*capa), lustre_swab_lustre_capa);
436 OBD_ALLOC(*capa, sizeof(**capa));
439 memcpy(*capa, lcapa, sizeof(**capa));
445 int mdc_unpack_acl(struct obd_export *exp_lmv, struct ptlrpc_request *req,
446 unsigned int offset, struct lustre_md *md)
448 struct posix_acl *acl;
449 struct mds_remote_perm *perm;
454 if (!(md->body->valid & OBD_MD_FLACL))
457 if (md->body->valid & OBD_MD_FLRMTACL) {
458 offset++; /* first 'size' is not used */
460 buf = lustre_swab_repbuf(req, offset, sizeof(*perm),
461 lustre_swab_remote_perm);
463 CERROR("Can't unpack remote perm\n");
467 OBD_ALLOC(perm, sizeof(*perm));
470 memcpy(perm, buf, sizeof(*perm));
471 md->remote_perm = perm;
473 size = le32_to_cpu(*(__u32 *) lustre_msg_buf(
474 req->rq_repmsg, offset, 4));
475 buf = lustre_msg_buf(req->rq_repmsg, offset + 1, size);
477 acl = posix_acl_from_xattr(buf, size);
480 CERROR("convert xattr to acl failed: %d\n", rc);
483 rc = posix_acl_valid(acl);
485 CERROR("acl valid error: %d\n", rc);
486 posix_acl_release(acl);
497 static int mdc_unpack_gskey(struct obd_export *exp_lmv, struct ptlrpc_request *req,
498 unsigned int *offset, struct lustre_md *md)
500 int key_off = 0, rc = 0, size = 0;
504 if (md->body->valid & OBD_MD_FLKEY) {
505 size = le32_to_cpu(*(__u32 *) lustre_msg_buf(req->rq_repmsg,
507 buf = lustre_msg_buf(req->rq_repmsg, key_off++, size);
509 CDEBUG(D_INFO, "buf %p key_off %d size %d \n",
511 md->key = (struct lustre_key *)buf;
519 int mdc_req2lustre_md(struct obd_export *exp_lmv, struct ptlrpc_request *req,
520 unsigned int offset, struct obd_export *exp_lov,
521 struct lustre_md *md)
523 struct lov_mds_md *lmm;
524 int rc = 0, reply_off;
528 memset(md, 0, sizeof(*md));
530 md->body = lustre_msg_buf(req->rq_repmsg, offset,
535 LASSERT_REPSWABBED(req, offset);
537 if (!(md->body->valid & OBD_MD_FLEASIZE) &&
538 !(md->body->valid & OBD_MD_FLDIREA))
541 if (S_ISREG(md->body->mode)) {
542 if (md->body->eadatasize == 0) {
543 CERROR("invalid EA size (0) is detected\n");
547 lmm = lustre_msg_buf(req->rq_repmsg, offset + 1,
548 md->body->eadatasize);
552 LASSERT(exp_lov != NULL);
554 rc = obd_unpackmd(exp_lov, &md->lsm, lmm,
555 md->body->eadatasize);
557 LASSERT(rc >= sizeof(*md->lsm));
560 } else if (S_ISDIR(md->body->mode)) {
561 /* dir can be non-splitted */
562 if (md->body->eadatasize == 0)
565 lmm = lustre_msg_buf(req->rq_repmsg, offset + 1,
566 md->body->eadatasize);
570 if (md->body->valid & OBD_MD_MEA) {
571 LASSERT(exp_lmv != NULL);
573 rc = obd_unpackmd(exp_lmv, (void *)&md->mea,
574 lmm, md->body->eadatasize);
576 LASSERT(rc >= sizeof(*md->mea));
581 LASSERT(S_ISCHR(md->body->mode) ||
582 S_ISBLK(md->body->mode) ||
583 S_ISFIFO(md->body->mode)||
584 S_ISLNK(md->body->mode) ||
585 S_ISSOCK(md->body->mode));
588 /* if anything wrong when unpacking md, we don't check acl
589 * stuff, for simplicity
594 reply_off = (md->body->valid & OBD_MD_FLEASIZE) ?
595 (offset + 2) : (offset + 1);
596 rc = mdc_unpack_acl(exp_lmv, req, reply_off, md);
598 CERROR("upack acl error %d \n", rc);
603 rc = mdc_unpack_gskey(exp_lmv, req, &reply_off, md);
610 static void mdc_commit_open(struct ptlrpc_request *req)
612 struct mdc_open_data *mod = req->rq_cb_data;
616 if (mod->mod_close_req != NULL)
617 mod->mod_close_req->rq_cb_data = NULL;
619 if (mod->mod_och != NULL)
620 mod->mod_och->och_mod = NULL;
622 OBD_FREE(mod, sizeof(*mod));
623 req->rq_cb_data = NULL;
624 LASSERT(atomic_read(&req->rq_refcount) > 1);
625 ptlrpc_req_finished(req);
628 static void mdc_replay_open(struct ptlrpc_request *req)
630 struct mdc_open_data *mod = req->rq_cb_data;
631 struct obd_client_handle *och;
632 struct ptlrpc_request *close_req;
633 struct lustre_handle old;
634 struct mds_body *body;
637 body = lustre_swab_repbuf(req, 1, sizeof(*body), lustre_swab_mds_body);
638 LASSERT (body != NULL);
641 DEBUG_REQ(D_ERROR, req,
642 "can't properly replay without open data");
649 struct lustre_handle *file_fh;
650 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
651 file_fh = &och->och_fh;
652 CDEBUG(D_HA, "updating handle from "LPX64" to "LPX64"\n",
653 file_fh->cookie, body->handle.cookie);
654 memcpy(&old, file_fh, sizeof(old));
655 memcpy(file_fh, &body->handle, sizeof(*file_fh));
658 close_req = mod->mod_close_req;
659 if (close_req != NULL) {
660 struct mds_body *close_body;
661 LASSERT(close_req->rq_reqmsg->opc == MDS_CLOSE);
662 close_body = lustre_msg_buf(close_req->rq_reqmsg,
664 sizeof(*close_body));
666 LASSERT(!memcmp(&old, &close_body->handle, sizeof old));
667 DEBUG_REQ(D_HA, close_req, "updating close body with new fh");
668 memcpy(&close_body->handle, &body->handle,
669 sizeof(close_body->handle));
675 int mdc_set_open_replay_data(struct obd_export *exp,
676 struct obd_client_handle *och,
677 struct ptlrpc_request *open_req)
679 struct mdc_open_data *mod;
680 struct mds_rec_create *rec;
681 struct mds_body *body;
683 rec = lustre_msg_buf(open_req->rq_reqmsg, MDS_REQ_INTENT_REC_OFF,
685 body = lustre_msg_buf(open_req->rq_repmsg, 1, sizeof(*body));
687 LASSERT(rec != NULL);
688 /* outgoing messages always in my byte order */
689 LASSERT(body != NULL);
690 /* incoming message in my byte order (it's been swabbed) */
691 LASSERT_REPSWABBED(open_req, 1);
693 OBD_ALLOC(mod, sizeof(*mod));
695 DEBUG_REQ(D_ERROR, open_req, "can't allocate mdc_open_data");
701 mod->mod_open_req = ptlrpc_request_addref(open_req);
703 memcpy(&rec->cr_replayid, &body->id1, sizeof rec->cr_replayid);
704 open_req->rq_replay_cb = mdc_replay_open;
705 open_req->rq_commit_cb = mdc_commit_open;
706 open_req->rq_cb_data = mod;
707 DEBUG_REQ(D_HA, open_req, "set up replay data");
711 int mdc_clear_open_replay_data(struct obd_export *exp,
712 struct obd_client_handle *och)
714 struct mdc_open_data *mod = och->och_mod;
716 /* Don't free the structure now (it happens in mdc_commit_open, after
717 * we're sure we won't need to fix up the close request in the future),
718 * but make sure that replay doesn't poke at the och, which is about to
720 LASSERT(mod != LP_POISON);
727 static void mdc_commit_close(struct ptlrpc_request *req)
729 struct mdc_open_data *mod = req->rq_cb_data;
730 struct obd_import *imp = req->rq_import;
731 struct ptlrpc_request *open_req;
733 DEBUG_REQ(D_HA, req, "close req committed");
737 mod->mod_close_req = NULL;
738 req->rq_cb_data = NULL;
739 req->rq_commit_cb = NULL;
741 open_req = mod->mod_open_req;
742 LASSERT(open_req != NULL);
743 LASSERT(open_req != LP_POISON);
744 LASSERT(open_req->rq_type != LI_POISON);
746 DEBUG_REQ(D_HA, open_req, "open req balanced");
747 if (open_req->rq_transno == 0) {
748 DEBUG_REQ(D_ERROR, open_req, "BUG 3892 open");
749 DEBUG_REQ(D_ERROR, req, "BUG 3892 close");
750 LASSERTF(open_req->rq_transno != 0, "BUG 3892\n");
752 LASSERT(open_req->rq_import == imp);
754 /* We no longer want to preserve this for transno-unconditional
756 spin_lock(&open_req->rq_lock);
757 open_req->rq_replay = 0;
758 spin_unlock(&open_req->rq_lock);
761 int mdc_close(struct obd_export *exp, struct mdc_op_data *op_data,
762 struct obd_client_handle *och, struct ptlrpc_request **request)
764 struct obd_device *obd = class_exp2obd(exp);
765 struct obd_import *imp = class_exp2cliimp(exp);
766 int reqsize[3] = {0, sizeof(struct mds_body),
767 obd->u.cli.cl_max_mds_cookiesize};
768 int rc, repsize[3] = {sizeof(struct mds_body),
769 obd->u.cli.cl_max_mds_easize,
770 obd->u.cli.cl_max_mds_cookiesize};
771 struct ptlrpc_request *req;
772 struct mdc_open_data *mod;
775 if (imp->imp_connection == NULL) {
776 CERROR("request on not connected import %s\n",
777 imp->imp_obd->obd_name);
781 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
782 MDS_CLOSE, 3, reqsize, NULL);
784 GOTO(out, rc = -ENOMEM);
785 req->rq_request_portal = MDS_CLOSE_PORTAL;
787 /* ensure that this close's handle is fixed up during replay. */
788 LASSERT(och != NULL);
790 if (likely(mod != NULL)) {
791 mod->mod_close_req = req;
792 LASSERT(mod->mod_open_req->rq_type != LI_POISON);
793 DEBUG_REQ(D_HA, mod->mod_open_req, "matched open");
795 CDEBUG(D_HA, "couldn't find open req; "
796 "expecting close error\n");
799 mdc_close_pack(req, 1, op_data, och);
801 req->rq_replen = lustre_msg_size(3, repsize);
802 req->rq_commit_cb = mdc_commit_close;
803 LASSERT(req->rq_cb_data == NULL);
804 req->rq_cb_data = mod;
806 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
807 rc = ptlrpc_queue_wait(req);
808 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
810 if (req->rq_repmsg == NULL) {
811 CDEBUG(D_HA, "request failed to send: %p, %d\n", req,
814 rc = req->rq_status ? req->rq_status : -EIO;
815 } else if (rc == 0) {
816 rc = req->rq_repmsg->status;
817 if (req->rq_repmsg->type == PTL_RPC_MSG_ERR) {
818 DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, "
824 CERROR("Unexpected: can't find mdc_open_data, but "
825 "close succeeded. Please tell CFS.\n");
826 if (!lustre_swab_repbuf(req, 0, sizeof(struct mds_body),
827 lustre_swab_mds_body))
829 CERROR("Error unpacking mds_body\n");
841 int mdc_done_writing(struct obd_export *exp, struct obdo *obdo)
843 struct ptlrpc_request *req;
844 struct mds_body *body;
845 int rc, size[2] = {0, sizeof(*body)};
848 size[0] = lustre_secdesc_size();
850 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
851 MDS_DONE_WRITING, 2, size, NULL);
855 lustre_pack_secdesc(req, size[0]);
857 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF,
860 mdc_pack_id(&body->id1, obdo->o_id, 0, obdo->o_mode,
861 obdo->o_mds, obdo->o_fid);
863 body->size = obdo->o_size;
864 body->blocks = obdo->o_blocks;
865 body->flags = obdo->o_flags;
866 body->valid = obdo->o_valid;
868 req->rq_replen = lustre_msg_size(1, &size[1]);
870 rc = ptlrpc_queue_wait(req);
871 ptlrpc_req_finished(req);
875 int mdc_readpage(struct obd_export *exp,
876 struct lustre_id *id,
877 __u64 offset, struct page *page,
878 struct ptlrpc_request **request)
880 struct obd_import *imp = class_exp2cliimp(exp);
881 struct ptlrpc_request *req = NULL;
882 struct ptlrpc_bulk_desc *desc = NULL;
883 struct mds_body *body;
884 int rc, size[2] = {0, sizeof(*body)};
887 CDEBUG(D_INODE, "inode: %ld\n", (long)id->li_stc.u.e3s.l3s_ino);
889 size[0] = lustre_secdesc_size();
891 req = ptlrpc_prep_req(imp, LUSTRE_MDS_VERSION, MDS_READPAGE,
894 GOTO(out, rc = -ENOMEM);
895 /* XXX FIXME bug 249 */
896 req->rq_request_portal = MDS_READPAGE_PORTAL;
898 lustre_pack_secdesc(req, size[0]);
900 desc = ptlrpc_prep_bulk_imp(req, 1, BULK_PUT_SINK, MDS_BULK_PORTAL);
902 GOTO(out, rc = -ENOMEM);
903 /* NB req now owns desc and will free it when it gets freed */
905 ptlrpc_prep_bulk_page(desc, page, 0, PAGE_CACHE_SIZE);
906 mdc_readdir_pack(req, 1, offset, PAGE_CACHE_SIZE, id);
908 req->rq_replen = lustre_msg_size(1, &size[1]);
909 rc = ptlrpc_queue_wait(req);
912 body = lustre_swab_repbuf(req, 0, sizeof (*body),
913 lustre_swab_mds_body);
915 CERROR("Can't unpack mds_body\n");
916 GOTO(out, rc = -EPROTO);
919 if (req->rq_bulk->bd_nob_transferred != PAGE_CACHE_SIZE) {
920 CERROR ("Unexpected # bytes transferred: %d"
922 req->rq_bulk->bd_nob_transferred,
924 GOTO (out, rc = -EPROTO);
934 static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
935 void *karg, void *uarg)
937 struct obd_device *obd = exp->exp_obd;
938 struct obd_ioctl_data *data = karg;
939 struct obd_import *imp = obd->u.cli.cl_import;
940 struct llog_ctxt *ctxt;
944 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
947 if (!try_module_get(THIS_MODULE)) {
948 CERROR("Can't get module. Is it alive?");
953 case OBD_IOC_CLIENT_RECOVER:
954 rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1);
958 case IOC_OSC_SET_ACTIVE:
959 rc = ptlrpc_set_import_active(imp, data->ioc_offset);
961 case IOC_OSC_CTL_RECOVERY:
962 rc = ptlrpc_import_control_recovery(imp, data->ioc_offset);
964 case OBD_IOC_PARSE: {
965 ctxt = llog_get_context(&exp->exp_obd->obd_llogs,
966 LLOG_CONFIG_REPL_CTXT);
967 rc = class_config_process_llog(ctxt, data->ioc_inlbuf1, NULL);
971 case OBD_IOC_LLOG_INFO:
972 case OBD_IOC_LLOG_PRINT: {
973 ctxt = llog_get_context(&obd->obd_llogs, LLOG_CONFIG_REPL_CTXT);
974 rc = llog_ioctl(ctxt, cmd, data);
980 CERROR("mdc_ioctl(): unrecognised ioctl %#x\n", cmd);
981 GOTO(out, rc = -ENOTTY);
984 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
987 module_put(THIS_MODULE);
993 int mdc_set_info(struct obd_export *exp, obd_count keylen,
994 void *key, obd_count vallen, void *val)
998 if (keylen == strlen("initial_recov") &&
999 memcmp(key, "initial_recov", strlen("initial_recov")) == 0) {
1000 struct obd_import *imp = exp->exp_obd->u.cli.cl_import;
1001 if (vallen != sizeof(int))
1003 imp->imp_initial_recov = *(int *)val;
1004 CDEBUG(D_HA, "%s: set imp_no_init_recov = %d\n",
1005 exp->exp_obd->obd_name,
1006 imp->imp_initial_recov);
1008 } else if ((keylen >= strlen("crypto_type")) &&
1009 strcmp(key, "crypto_type") == 0) {
1010 struct ptlrpc_request *req;
1011 char *bufs[2] = {key, val};
1012 int rc, size[2] = {keylen, vallen};
1014 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1015 OST_SET_INFO, 2, size, bufs);
1019 req->rq_replen = lustre_msg_size(0, NULL);
1020 rc = ptlrpc_queue_wait(req);
1021 ptlrpc_req_finished(req);
1023 } else if (keylen >= strlen("inter_mds") && strcmp(key, "inter_mds") == 0) {
1024 struct obd_import *imp = class_exp2cliimp(exp);
1025 imp->imp_server_timeout = 1;
1026 CDEBUG(D_OTHER, "%s: timeout / 2\n", exp->exp_obd->obd_name);
1028 } else if (keylen == strlen("sec") &&
1029 memcmp(key, "sec", keylen) == 0) {
1030 struct client_obd *cli = &exp->exp_obd->u.cli;
1032 cli->cl_sec_flavor = ptlrpcs_name2flavor(val);
1033 if (cli->cl_sec_flavor == PTLRPCS_FLVR_INVALID) {
1034 CERROR("unrecognized security type %s\n", (char*) val);
1039 } else if (keylen == strlen("sec_flags") &&
1040 memcmp(key, "sec_flags", keylen) == 0) {
1041 struct client_obd *cli = &exp->exp_obd->u.cli;
1043 cli->cl_sec_flags = *((unsigned long *) val);
1045 } else if (keylen == strlen("flush_cred") &&
1046 memcmp(key, "flush_cred", keylen) == 0) {
1047 struct client_obd *cli = &exp->exp_obd->u.cli;
1050 ptlrpcs_import_flush_current_creds(cli->cl_import);
1052 } else if (keylen == strlen("async") && memcmp(key, "async", keylen) == 0) {
1053 struct client_obd *cl = &exp->exp_obd->u.cli;
1054 if (vallen != sizeof(int))
1056 cl->cl_async = *(int *)val;
1057 CDEBUG(D_HA, "%s: set async = %d\n",
1058 exp->exp_obd->obd_name, cl->cl_async);
1060 } else if (keylen == strlen("setext") && memcmp(key, "setext", keylen) == 0) {
1061 struct ptlrpc_request *req;
1062 char *bufs[2] = {key, val};
1063 int rc, size[2] = {keylen, vallen};
1065 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1066 OST_SET_INFO, 2, size, bufs);
1070 req->rq_replen = lustre_msg_size(0, NULL);
1071 rc = ptlrpc_queue_wait(req);
1072 ptlrpc_req_finished(req);
1074 } else if (keylen == 5 && strcmp(key, "audit") == 0) {
1075 struct ptlrpc_request *req;
1076 char *bufs[2] = {key, val};
1077 int rc, size[2] = {keylen, vallen};
1079 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1080 OST_SET_INFO, 2, size, bufs);
1084 req->rq_replen = lustre_msg_size(0, NULL);
1085 lustre_swab_reqbuf(req, 1, sizeof(struct audit_attr_msg),
1086 lustre_swab_audit_attr);
1087 rc = ptlrpc_queue_wait(req);
1088 ptlrpc_req_finished(req);
1091 } else if (keylen == strlen("ids") && memcmp(key, "ids", keylen) == 0) {
1092 struct ptlrpc_request *req;
1093 struct lustre_id *ids = (struct lustre_id *)val;
1094 char *bufs[3] = {key, (char *)ids, (char *)(ids + 1)};
1095 int rc, size[3] = {keylen, sizeof(struct lustre_id),
1096 sizeof(struct lustre_id)};
1098 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1099 OST_SET_INFO, 3, size, bufs);
1103 req->rq_replen = lustre_msg_size(0, NULL);
1104 rc = ptlrpc_queue_wait(req);
1105 ptlrpc_req_finished(req);
1111 static int mdc_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1112 unsigned long max_age)
1114 struct obd_statfs *msfs;
1115 struct ptlrpc_request *req;
1116 int rc, size = sizeof(*msfs);
1119 /* We could possibly pass max_age in the request (as an absolute
1120 * timestamp or a "seconds.usec ago") so the target can avoid doing
1121 * extra calls into the filesystem if that isn't necessary (e.g.
1122 * during mount that would help a bit). Having relative timestamps
1123 * is not so great if request processing is slow, while absolute
1124 * timestamps are not ideal because they need time synchronization. */
1125 req = ptlrpc_prep_req(obd->u.cli.cl_import, LUSTRE_MDS_VERSION,
1126 MDS_STATFS, 0, NULL, NULL);
1130 req->rq_replen = lustre_msg_size(1, &size);
1132 mdc_get_rpc_lock(obd->u.cli.cl_rpc_lock, NULL);
1133 rc = ptlrpc_queue_wait(req);
1134 mdc_put_rpc_lock(obd->u.cli.cl_rpc_lock, NULL);
1137 /* this can be LMV fake import, whcih is not connected. */
1138 if (!req->rq_import->imp_connection)
1139 memset(osfs, 0, sizeof(*osfs));
1143 msfs = lustre_swab_repbuf(req, 0, sizeof(*msfs),
1144 lustre_swab_obd_statfs);
1146 CERROR("Can't unpack obd_statfs\n");
1147 GOTO(out, rc = -EPROTO);
1150 memcpy(osfs, msfs, sizeof (*msfs));
1153 ptlrpc_req_finished(req);
1157 static int mdc_pin(struct obd_export *exp, obd_id ino, __u32 gen, int type,
1158 struct obd_client_handle *handle, int flag)
1160 struct ptlrpc_request *req;
1161 struct mds_body *body;
1162 int rc, size[2] = {0, sizeof(*body)};
1165 //size[0] = lustre_secdesc_size();
1167 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1168 MDS_PIN, 2, size, NULL);
1172 //lustre_pack_secdesc(req, size[0]);
1174 body = lustre_msg_buf(req->rq_reqmsg,
1175 MDS_REQ_REC_OFF, sizeof(*body));
1177 /* FIXME-UMKA: here should be also mdsnum and fid. */
1178 mdc_pack_id(&body->id1, ino, gen, type, 0, 0);
1181 req->rq_replen = lustre_msg_size(1, &size[1]);
1183 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1184 rc = ptlrpc_queue_wait(req);
1185 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1187 CERROR("pin failed: %d\n", rc);
1188 ptlrpc_req_finished(req);
1192 body = lustre_swab_repbuf(req, 0, sizeof(*body), lustre_swab_mds_body);
1194 ptlrpc_req_finished(req);
1198 memcpy(&handle->och_fh, &body->handle, sizeof(body->handle));
1199 handle->och_magic = OBD_CLIENT_HANDLE_MAGIC;
1201 OBD_ALLOC(handle->och_mod, sizeof(*handle->och_mod));
1202 if (handle->och_mod == NULL) {
1203 DEBUG_REQ(D_ERROR, req, "can't allocate mdc_open_data");
1206 handle->och_mod->mod_open_req = req; /* will be dropped by unpin */
1211 static int mdc_unpin(struct obd_export *exp,
1212 struct obd_client_handle *handle, int flag)
1214 struct ptlrpc_request *req;
1215 struct mds_body *body;
1216 int rc, size[2] = {0, sizeof(*body)};
1219 if (handle->och_magic != OBD_CLIENT_HANDLE_MAGIC)
1222 //size[0] = lustre_secdesc_size();
1224 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1225 MDS_CLOSE, 2, size, NULL);
1229 //lustre_pack_secdesc(req, size[0]);
1231 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF, sizeof(*body));
1232 memcpy(&body->handle, &handle->och_fh, sizeof(body->handle));
1235 req->rq_replen = lustre_msg_size(0, NULL);
1236 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1237 rc = ptlrpc_queue_wait(req);
1238 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1241 CERROR("unpin failed: %d\n", rc);
1243 ptlrpc_req_finished(req);
1244 ptlrpc_req_finished(handle->och_mod->mod_open_req);
1245 OBD_FREE(handle->och_mod, sizeof(*handle->och_mod));
1249 int mdc_sync(struct obd_export *exp, struct lustre_id *id,
1250 struct ptlrpc_request **request)
1252 struct ptlrpc_request *req;
1253 struct mds_body *body;
1254 int size[2] = {0, sizeof(*body)};
1258 //size[0] = lustre_secdesc_size();
1260 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,
1261 MDS_SYNC, 2, size, NULL);
1263 RETURN(rc = -ENOMEM);
1265 //lustre_pack_secdesc(req, size[0]);
1268 body = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF,
1270 memcpy(&body->id1, id, sizeof(*id));
1273 req->rq_replen = lustre_msg_size(1, &size[1]);
1275 rc = ptlrpc_queue_wait(req);
1276 if (rc || request == NULL)
1277 ptlrpc_req_finished(req);
1284 static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
1285 enum obd_import_event event)
1289 LASSERT(imp->imp_obd == obd);
1292 case IMP_EVENT_DISCON: {
1295 case IMP_EVENT_INACTIVE: {
1296 if (obd->obd_observer)
1297 rc = obd_notify(obd->obd_observer, obd, 0, 0);
1300 case IMP_EVENT_INVALIDATE: {
1301 struct ldlm_namespace *ns = obd->obd_namespace;
1303 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
1307 case IMP_EVENT_ACTIVE: {
1308 if (obd->obd_observer)
1309 rc = obd_notify(obd->obd_observer, obd, 1, 0);
1313 CERROR("Unknown import event %d\n", event);
1319 static int mdc_attach(struct obd_device *dev, obd_count len, void *data)
1321 struct lprocfs_static_vars lvars;
1323 lprocfs_init_vars(mdc, &lvars);
1324 return lprocfs_obd_attach(dev, lvars.obd_vars);
1327 static int mdc_detach(struct obd_device *dev)
1329 return lprocfs_obd_detach(dev);
1332 static int mdc_setup(struct obd_device *obd, obd_count len, void *buf)
1334 struct client_obd *cli = &obd->u.cli;
1338 OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1339 if (!cli->cl_rpc_lock)
1341 mdc_init_rpc_lock(cli->cl_rpc_lock);
1345 OBD_ALLOC(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1346 if (!cli->cl_setattr_lock)
1347 GOTO(err_rpc_lock, rc = -ENOMEM);
1348 mdc_init_rpc_lock(cli->cl_setattr_lock);
1350 OBD_ALLOC(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1351 if (!cli->cl_close_lock)
1352 GOTO(err_setattr_lock, rc = -ENOMEM);
1353 mdc_init_rpc_lock(cli->cl_close_lock);
1355 rc = client_obd_setup(obd, len, buf);
1357 GOTO(err_close_lock, rc);
1359 rc = obd_llog_init(obd, &obd->obd_llogs, obd, 0, NULL);
1361 mdc_cleanup(obd, 0);
1362 CERROR("failed to setup llogging subsystems\n");
1368 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1370 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1372 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1377 static int mdc_init_ea_size(struct obd_export *exp, int easize, int cookiesize)
1379 struct obd_device *obd = exp->exp_obd;
1380 struct client_obd *cli = &obd->u.cli;
1383 if (cli->cl_max_mds_easize < easize)
1384 cli->cl_max_mds_easize = easize;
1385 if (cli->cl_max_mds_cookiesize < cookiesize)
1386 cli->cl_max_mds_cookiesize = cookiesize;
1390 static int mdc_precleanup(struct obd_device *obd, int flags)
1394 rc = obd_llog_finish(obd, &obd->obd_llogs, 0);
1396 CERROR("failed to cleanup llogging subsystems\n");
1401 static int mdc_cleanup(struct obd_device *obd, int flags)
1403 struct client_obd *cli = &obd->u.cli;
1405 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1406 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1407 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1411 return client_obd_cleanup(obd, flags);
1415 static int mdc_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
1416 struct obd_device *tgt, int count,
1417 struct llog_catid *logid)
1419 struct llog_ctxt *ctxt;
1423 rc = obd_llog_setup(obd, llogs, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
1426 ctxt = llog_get_context(llogs, LLOG_CONFIG_REPL_CTXT);
1427 ctxt->loc_imp = obd->u.cli.cl_import;
1433 static int mdc_llog_finish(struct obd_device *obd,
1434 struct obd_llogs *llogs, int count)
1439 rc = obd_llog_cleanup(llog_get_context(llogs, LLOG_CONFIG_REPL_CTXT));
1443 static struct obd_device *mdc_get_real_obd(struct obd_export *exp,
1444 struct lustre_id *id)
1447 RETURN(exp->exp_obd);
1450 static int mdc_get_info(struct obd_export *exp, __u32 keylen,
1451 void *key, __u32 *valsize, void *val)
1453 struct ptlrpc_request *req;
1454 char *bufs[1] = {key};
1458 if (!valsize || !val)
1461 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
1462 struct obd_import *imp;
1463 struct obd_connect_data *data;
1465 imp = class_exp2cliimp(exp);
1471 if (imp->imp_state != LUSTRE_IMP_FULL) {
1472 CERROR("import state not full\n");
1476 data = &imp->imp_connect_data;
1477 if (data->ocd_connect_flags & OBD_CONNECT_REMOTE) {
1480 } else if (data->ocd_connect_flags & OBD_CONNECT_LOCAL) {
1484 CERROR("no remote flag set?\n");
1488 if ((keylen < strlen("mdsize") || strcmp(key, "mdsize") != 0) &&
1489 (keylen < strlen("mdsnum") || strcmp(key, "mdsnum") != 0) &&
1490 (keylen < strlen("lovdesc") || strcmp(key, "lovdesc") != 0) &&
1491 (keylen < strlen("getext") || strcmp(key, "getext") != 0) &&
1492 (keylen < strlen("rootid") || strcmp(key, "rootid") != 0) &&
1493 (keylen < strlen("auditid") || strcmp(key, "auditid") != 0))
1496 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1497 OST_GET_INFO, 1, (int *)&keylen, bufs);
1501 req->rq_replen = lustre_msg_size(1, (int *)valsize);
1502 rc = ptlrpc_queue_wait(req);
1506 if ((keylen >= strlen("rootid") && !strcmp(key, "rootid")) ||
1507 (keylen >= strlen("auditid") && !strcmp(key, "auditid"))) {
1508 struct lustre_id *reply;
1510 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
1511 lustre_swab_lustre_id);
1512 if (reply == NULL) {
1513 CERROR("Can't unpack %s\n", (char *)key);
1514 GOTO(out_req, rc = -EPROTO);
1517 *(struct lustre_id *)val = *reply;
1518 } else if (keylen >= strlen("lovdesc") && !strcmp(key, "lovdesc")) {
1519 struct lov_desc *reply;
1521 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
1522 lustre_swab_lov_desc);
1523 if (reply == NULL) {
1524 CERROR("Can't unpack %s\n", (char *)key);
1525 GOTO(out_req, rc = -EPROTO);
1528 *(struct lov_desc *)val = *reply;
1530 } else if (keylen >= strlen("getext") && !strcmp(key, "getext")) {
1531 struct fid_extent *reply;
1533 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
1534 lustre_swab_fid_extent);
1535 if (reply == NULL) {
1536 CERROR("Can't unpack %s\n", (char *)key);
1537 GOTO(out_req, rc = -EPROTO);
1540 *(struct fid_extent *)val = *reply;
1545 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
1546 lustre_swab_generic_32s);
1547 if (reply == NULL) {
1548 CERROR("Can't unpack %s\n", (char *)key);
1549 GOTO(out_req, rc = -EPROTO);
1551 *((__u32 *)val) = *reply;
1554 ptlrpc_req_finished(req);
1558 int mdc_obj_create(struct obd_export *exp, struct obdo *oa,
1559 void *acl, int acl_size, struct lov_stripe_md **ea,
1560 struct obd_trans_info *oti)
1562 struct ptlrpc_request *request;
1563 struct ost_body *body;
1565 int rc, size[2] = { sizeof(*body), acl_size };
1570 request = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
1571 OST_CREATE, 2, size, NULL);
1573 GOTO(out_req, rc = -ENOMEM);
1575 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
1576 memcpy(&body->oa, oa, sizeof(body->oa));
1579 acl_buf = lustre_msg_buf(request->rq_reqmsg, 1, acl_size);
1580 memcpy(acl_buf, acl, acl_size);
1583 request->rq_replen = lustre_msg_size(1, size);
1584 rc = ptlrpc_queue_wait(request);
1588 body = lustre_swab_repbuf(request, 0, sizeof(*body),
1589 lustre_swab_ost_body);
1591 CERROR ("can't unpack ost_body\n");
1592 GOTO (out_req, rc = -EPROTO);
1595 memcpy(oa, &body->oa, sizeof(*oa));
1597 /* store ino/generation for recovery */
1598 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
1599 body->oa.o_id = oa->o_id;
1600 body->oa.o_generation = oa->o_generation;
1601 body->oa.o_fid = oa->o_fid;
1602 body->oa.o_mds = oa->o_mds;
1604 CDEBUG(D_HA, "transno: "LPD64"\n", request->rq_repmsg->transno);
1607 ptlrpc_req_finished(request);
1611 int mdc_brw(int rw, struct obd_export *exp, struct obdo *oa,
1612 struct lov_stripe_md *ea, obd_count oa_bufs,
1613 struct brw_page *pgarr, struct obd_trans_info *oti)
1615 struct ptlrpc_bulk_desc *desc;
1616 struct niobuf_remote *niobuf;
1617 struct ptlrpc_request *req;
1618 struct obd_ioobj *ioobj;
1619 struct ost_body *body;
1623 opc = ((rw & OBD_BRW_WRITE) != 0) ? OST_WRITE : OST_READ;
1625 size[0] = sizeof(*body);
1626 size[1] = sizeof(*ioobj);
1627 size[2] = oa_bufs * sizeof(*niobuf);
1629 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION, opc,
1631 LASSERT(req != NULL);
1633 if (opc == OST_WRITE)
1634 desc = ptlrpc_prep_bulk_imp(req, oa_bufs, BULK_GET_SOURCE,
1637 desc = ptlrpc_prep_bulk_imp(req, oa_bufs, BULK_PUT_SINK,
1639 LASSERT(desc != NULL);
1641 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
1642 ioobj = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*ioobj));
1643 niobuf = lustre_msg_buf(req->rq_reqmsg, 2, oa_bufs * sizeof(*niobuf));
1645 memcpy(&body->oa, oa, sizeof(*oa));
1646 obdo_to_ioobj(oa, ioobj);
1647 ioobj->ioo_bufcnt = oa_bufs;
1649 for (i = 0; i < oa_bufs; i++, niobuf++) {
1650 struct brw_page *pg = &pgarr[i];
1652 LASSERT(pg->count > 0);
1653 LASSERT((pg->disk_offset & ~PAGE_MASK) + pg->count <= PAGE_SIZE);
1655 ptlrpc_prep_bulk_page(desc, pg->pg, pg->disk_offset & ~PAGE_MASK,
1658 niobuf->offset = pg->disk_offset;
1659 niobuf->len = pg->count;
1660 niobuf->flags = pg->flag;
1663 /* size[0] still sizeof (*body) */
1664 if (opc == OST_WRITE) {
1665 /* 1 RC per niobuf */
1666 size[1] = sizeof(__u32) * oa_bufs;
1667 req->rq_replen = lustre_msg_size(2, size);
1669 /* 1 RC for the whole I/O */
1670 req->rq_replen = lustre_msg_size(1, size);
1672 err = ptlrpc_queue_wait(req);
1675 ptlrpc_req_finished(req);
1679 static int mdc_valid_attrs(struct obd_export *exp,
1680 struct lustre_id *id)
1682 struct ldlm_res_id res_id = { .name = {0} };
1683 struct obd_device *obd = exp->exp_obd;
1684 struct lustre_handle lockh;
1685 ldlm_policy_data_t policy;
1689 res_id.name[0] = id_fid(id);
1690 res_id.name[1] = id_group(id);
1691 policy.l_inodebits.bits = MDS_INODELOCK_UPDATE;
1693 CDEBUG(D_INFO, "trying to match res "LPU64"\n",
1696 /* FIXME use LDLM_FL_TEST_LOCK instead */
1697 flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_CBPENDING;
1698 if (ldlm_lock_match(obd->obd_namespace, flags, &res_id,
1699 LDLM_IBITS, &policy, LCK_PR, &lockh)) {
1700 ldlm_lock_decref(&lockh, LCK_PR);
1704 if (ldlm_lock_match(obd->obd_namespace, flags, &res_id,
1705 LDLM_IBITS, &policy, LCK_PW, &lockh)) {
1706 ldlm_lock_decref(&lockh, LCK_PW);
1712 static int mdc_change_cbdata_name(struct obd_export *exp,
1713 struct lustre_id *pid,
1714 char *name, int len,
1715 struct lustre_id *cid,
1716 ldlm_iterator_t it, void *data)
1719 rc = mdc_change_cbdata(exp, cid, it, data);
1723 struct obd_ops mdc_obd_ops = {
1724 .o_owner = THIS_MODULE,
1725 .o_attach = mdc_attach,
1726 .o_detach = mdc_detach,
1727 .o_setup = mdc_setup,
1728 .o_precleanup = mdc_precleanup,
1729 .o_cleanup = mdc_cleanup,
1730 .o_add_conn = client_import_add_conn,
1731 .o_del_conn = client_import_del_conn,
1732 .o_connect = client_connect_import,
1733 .o_disconnect = client_disconnect_export,
1734 .o_iocontrol = mdc_iocontrol,
1735 .o_packmd = mdc_packmd,
1736 .o_unpackmd = mdc_unpackmd,
1737 .o_statfs = mdc_statfs,
1739 .o_unpin = mdc_unpin,
1740 .o_import_event = mdc_import_event,
1741 .o_llog_init = mdc_llog_init,
1742 .o_llog_finish = mdc_llog_finish,
1743 .o_create = mdc_obj_create,
1744 .o_set_info = mdc_set_info,
1745 .o_get_info = mdc_get_info,
1747 .o_cancel_unused = mdc_cancel_unused,
1748 .o_init_ea_size = mdc_init_ea_size,
1751 struct md_ops mdc_md_ops = {
1752 .m_getstatus = mdc_getstatus,
1753 .m_getattr = mdc_getattr,
1754 .m_close = mdc_close,
1755 .m_create = mdc_create,
1756 .m_done_writing = mdc_done_writing,
1757 .m_enqueue = mdc_enqueue,
1758 .m_getattr_lock = mdc_getattr_lock,
1759 .m_intent_lock = mdc_intent_lock,
1761 .m_rename = mdc_rename,
1762 .m_setattr = mdc_setattr,
1764 .m_readpage = mdc_readpage,
1765 .m_unlink = mdc_unlink,
1766 .m_valid_attrs = mdc_valid_attrs,
1767 .m_req2lustre_md = mdc_req2lustre_md,
1768 .m_set_open_replay_data = mdc_set_open_replay_data,
1769 .m_clear_open_replay_data = mdc_clear_open_replay_data,
1770 .m_store_inode_generation = mdc_store_inode_generation,
1771 .m_set_lock_data = mdc_set_lock_data,
1772 .m_get_real_obd = mdc_get_real_obd,
1773 .m_change_cbdata_name = mdc_change_cbdata_name,
1774 .m_change_cbdata = mdc_change_cbdata,
1775 .m_access_check = mdc_access_check,
1778 int __init mdc_init(void)
1780 struct lprocfs_static_vars lvars;
1782 lprocfs_init_vars(mdc, &lvars);
1783 return class_register_type(&mdc_obd_ops, &mdc_md_ops,
1784 lvars.module_vars, OBD_MDC_DEVICENAME);
1788 static void /*__exit*/ mdc_exit(void)
1790 class_unregister_type(OBD_MDC_DEVICENAME);
1793 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1794 MODULE_DESCRIPTION("Lustre Metadata Client");
1795 MODULE_LICENSE("GPL");
1797 EXPORT_SYMBOL(mdc_req2lustre_md);
1798 EXPORT_SYMBOL(mdc_req2lustre_capa);
1799 EXPORT_SYMBOL(mdc_change_cbdata);
1800 EXPORT_SYMBOL(mdc_getstatus);
1801 EXPORT_SYMBOL(mdc_getattr);
1802 EXPORT_SYMBOL(mdc_getattr_lock);
1803 EXPORT_SYMBOL(mdc_create);
1804 EXPORT_SYMBOL(mdc_unlink);
1805 EXPORT_SYMBOL(mdc_rename);
1806 EXPORT_SYMBOL(mdc_link);
1807 EXPORT_SYMBOL(mdc_readpage);
1808 EXPORT_SYMBOL(mdc_setattr);
1809 EXPORT_SYMBOL(mdc_close);
1810 EXPORT_SYMBOL(mdc_done_writing);
1811 EXPORT_SYMBOL(mdc_sync);
1812 EXPORT_SYMBOL(mdc_set_open_replay_data);
1813 EXPORT_SYMBOL(mdc_clear_open_replay_data);
1814 EXPORT_SYMBOL(mdc_store_inode_generation);
1816 module_init(mdc_init);
1817 module_exit(mdc_exit);