1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 # define EXPORT_SYMTAB
40 #define DEBUG_SUBSYSTEM S_MDC
43 # include <linux/module.h>
44 # include <linux/pagemap.h>
45 # include <linux/miscdevice.h>
46 # include <linux/init.h>
48 # include <liblustre.h>
51 #include <lustre_acl.h>
52 #include <obd_class.h>
53 #include <lustre_dlm.h>
54 #include <lustre_fid.h>
55 #include <md_object.h>
56 #include <lprocfs_status.h>
57 #include <lustre_param.h>
58 #include "mdc_internal.h"
59 #include <lustre/lustre_idl.h>
61 #define REQUEST_MINOR 244
63 static quota_interface_t *quota_interface;
64 extern quota_interface_t mdc_quota_interface;
66 static int mdc_cleanup(struct obd_device *obd);
68 int mdc_unpack_capa(struct obd_export *exp, struct ptlrpc_request *req,
69 const struct req_msg_field *field, struct obd_capa **oc)
71 struct lustre_capa *capa;
75 /* swabbed already in mdc_enqueue */
76 capa = req_capsule_server_get(&req->rq_pill, field);
80 c = alloc_capa(CAPA_SITE_CLIENT);
82 CDEBUG(D_INFO, "alloc capa failed!\n");
91 /* Helper that implements most of mdc_getstatus and signal_completed_replay. */
92 /* XXX this should become mdc_get_info("key"), sending MDS_GET_INFO RPC */
93 static int send_getstatus(struct obd_import *imp, struct lu_fid *rootfid,
94 struct obd_capa **pc, int level, int msg_flags)
96 struct ptlrpc_request *req;
97 struct mdt_body *body;
101 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_GETSTATUS,
102 LUSTRE_MDS_VERSION, MDS_GETSTATUS);
106 mdc_pack_body(req, NULL, NULL, 0, 0, -1, 0);
107 lustre_msg_add_flags(req->rq_reqmsg, msg_flags);
108 req->rq_send_state = level;
110 ptlrpc_request_set_replen(req);
112 rc = ptlrpc_queue_wait(req);
116 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
118 GOTO(out, rc = -EPROTO);
120 if (body->valid & OBD_MD_FLMDSCAPA) {
121 rc = mdc_unpack_capa(NULL, req, &RMF_CAPA1, pc);
126 *rootfid = body->fid1;
128 "root fid="DFID", last_committed="LPU64"\n",
130 lustre_msg_get_last_committed(req->rq_repmsg));
133 ptlrpc_req_finished(req);
137 /* This should be mdc_get_info("rootfid") */
138 int mdc_getstatus(struct obd_export *exp, struct lu_fid *rootfid,
139 struct obd_capa **pc)
141 return send_getstatus(class_exp2cliimp(exp), rootfid, pc,
146 * This function now is known to always saying that it will receive 4 buffers
147 * from server. Even for cases when acl_size and md_size is zero, RPC header
148 * will contain 4 fields and RPC itself will contain zero size fields. This is
149 * because mdt_getattr*() _always_ returns 4 fields, but if acl is not needed
150 * and thus zero, it shrinks it, making zero size. The same story about
151 * md_size. And this is course of problem when client waits for smaller number
152 * of fields. This issue will be fixed later when client gets aware of RPC
155 static int mdc_getattr_common(struct obd_export *exp,
156 struct ptlrpc_request *req)
158 struct req_capsule *pill = &req->rq_pill;
159 struct mdt_body *body;
164 /* Request message already built. */
165 rc = ptlrpc_queue_wait(req);
169 /* sanity check for the reply */
170 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
174 CDEBUG(D_NET, "mode: %o\n", body->mode);
176 if (body->eadatasize != 0) {
177 mdc_update_max_ea_from_body(exp, body);
179 eadata = req_capsule_server_sized_get(pill, &RMF_MDT_MD,
185 if (body->valid & OBD_MD_FLRMTPERM) {
186 struct mdt_remote_perm *perm;
188 LASSERT(client_is_remote(exp));
189 perm = req_capsule_server_swab_get(pill, &RMF_ACL,
190 lustre_swab_mdt_remote_perm);
195 if (body->valid & OBD_MD_FLMDSCAPA) {
196 struct lustre_capa *capa;
197 capa = req_capsule_server_get(pill, &RMF_CAPA1);
205 int mdc_getattr(struct obd_export *exp, const struct lu_fid *fid,
206 struct obd_capa *oc, obd_valid valid, int ea_size,
207 struct ptlrpc_request **request)
209 struct ptlrpc_request *req;
214 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR);
218 mdc_set_capa_size(req, &RMF_CAPA1, oc);
220 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR);
222 ptlrpc_request_free(req);
226 /* MDS_BFLAG_EXT_FLAGS: request "new" flags(bug 9486) */
227 mdc_pack_body(req, fid, oc, valid, ea_size, -1, MDS_BFLAG_EXT_FLAGS);
229 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER, ea_size);
230 if (valid & OBD_MD_FLRMTPERM) {
231 LASSERT(client_is_remote(exp));
232 req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER,
233 sizeof(struct mdt_remote_perm));
235 ptlrpc_request_set_replen(req);
237 rc = mdc_getattr_common(exp, req);
239 ptlrpc_req_finished(req);
245 int mdc_getattr_name(struct obd_export *exp, const struct lu_fid *fid,
246 struct obd_capa *oc, const char *filename, int namelen,
247 obd_valid valid, int ea_size, __u32 suppgid,
248 struct ptlrpc_request **request)
250 struct ptlrpc_request *req;
255 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
256 &RQF_MDS_GETATTR_NAME);
260 mdc_set_capa_size(req, &RMF_CAPA1, oc);
261 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT, namelen);
263 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR_NAME);
265 ptlrpc_request_free(req);
269 /* MDS_BFLAG_EXT_FLAGS: request "new" flags(bug 9486) */
270 mdc_pack_body(req, fid, oc, valid, ea_size, suppgid,
271 MDS_BFLAG_EXT_FLAGS);
274 char *name = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
275 LASSERT(strnlen(filename, namelen) == namelen - 1);
276 memcpy(name, filename, namelen);
279 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER, ea_size);
280 ptlrpc_request_set_replen(req);
282 rc = mdc_getattr_common(exp, req);
284 ptlrpc_req_finished(req);
290 static int mdc_is_subdir(struct obd_export *exp,
291 const struct lu_fid *pfid,
292 const struct lu_fid *cfid,
293 struct ptlrpc_request **request)
295 struct ptlrpc_request *req;
301 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
302 &RQF_MDS_IS_SUBDIR, LUSTRE_MDS_VERSION,
307 mdc_is_subdir_pack(req, pfid, cfid, 0);
308 ptlrpc_request_set_replen(req);
310 rc = ptlrpc_queue_wait(req);
311 if (rc && rc != -EREMOTE)
312 ptlrpc_req_finished(req);
318 static int mdc_xattr_common(struct obd_export *exp,const struct req_format *fmt,
319 const struct lu_fid *fid,
320 struct obd_capa *oc, int opcode, obd_valid valid,
321 const char *xattr_name, const char *input,
322 int input_size, int output_size, int flags,
323 __u32 suppgid, struct ptlrpc_request **request)
325 struct ptlrpc_request *req;
326 int xattr_namelen = 0;
332 req = ptlrpc_request_alloc(class_exp2cliimp(exp), fmt);
336 mdc_set_capa_size(req, &RMF_CAPA1, oc);
338 xattr_namelen = strlen(xattr_name) + 1;
339 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
344 req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_CLIENT,
348 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, opcode);
350 ptlrpc_request_free(req);
354 if (opcode == MDS_REINT) {
355 struct mdt_rec_setxattr *rec;
357 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
358 sizeof(struct mdt_rec_reint));
359 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
360 rec->sx_opcode = REINT_SETXATTR;
362 * cfs_curproc_fs{u,g}id() should replace
363 * current->fs{u,g}id for portability.
365 rec->sx_fsuid = current->fsuid;
366 rec->sx_fsgid = current->fsgid;
367 rec->sx_cap = cfs_curproc_cap_pack();
368 rec->sx_suppgid1 = suppgid;
369 rec->sx_suppgid2 = -1;
371 rec->sx_valid = valid | OBD_MD_FLCTIME;
372 rec->sx_time = cfs_time_current_sec();
373 rec->sx_size = output_size;
374 rec->sx_flags = flags;
376 mdc_pack_capa(req, &RMF_CAPA1, oc);
378 mdc_pack_body(req, fid, oc, valid, output_size, suppgid, flags);
382 tmp = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
383 memcpy(tmp, xattr_name, xattr_namelen);
386 tmp = req_capsule_client_get(&req->rq_pill, &RMF_EADATA);
387 memcpy(tmp, input, input_size);
390 if (req_capsule_has_field(&req->rq_pill, &RMF_EADATA, RCL_SERVER))
391 req_capsule_set_size(&req->rq_pill, &RMF_EADATA,
392 RCL_SERVER, output_size);
393 ptlrpc_request_set_replen(req);
396 if (opcode == MDS_REINT)
397 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
399 rc = ptlrpc_queue_wait(req);
401 if (opcode == MDS_REINT)
402 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
405 ptlrpc_req_finished(req);
411 int mdc_setxattr(struct obd_export *exp, const struct lu_fid *fid,
412 struct obd_capa *oc, obd_valid valid, const char *xattr_name,
413 const char *input, int input_size, int output_size,
414 int flags, __u32 suppgid, struct ptlrpc_request **request)
416 return mdc_xattr_common(exp, &RQF_MDS_REINT_SETXATTR,
417 fid, oc, MDS_REINT, valid, xattr_name,
418 input, input_size, output_size, flags,
422 int mdc_getxattr(struct obd_export *exp, const struct lu_fid *fid,
423 struct obd_capa *oc, obd_valid valid, const char *xattr_name,
424 const char *input, int input_size, int output_size,
425 int flags, struct ptlrpc_request **request)
427 return mdc_xattr_common(exp, &RQF_MDS_GETXATTR,
428 fid, oc, MDS_GETXATTR, valid, xattr_name,
429 input, input_size, output_size, flags,
433 #ifdef CONFIG_FS_POSIX_ACL
434 static int mdc_unpack_acl(struct ptlrpc_request *req, struct lustre_md *md)
436 struct req_capsule *pill = &req->rq_pill;
437 struct mdt_body *body = md->body;
438 struct posix_acl *acl;
446 buf = req_capsule_server_sized_get(pill, &RMF_ACL, body->aclsize);
451 acl = posix_acl_from_xattr(buf, body->aclsize);
454 CERROR("convert xattr to acl: %d\n", rc);
458 rc = posix_acl_valid(acl);
460 CERROR("validate acl: %d\n", rc);
461 posix_acl_release(acl);
469 #define mdc_unpack_acl(req, md) 0
472 int mdc_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
473 struct obd_export *dt_exp, struct obd_export *md_exp,
474 struct lustre_md *md)
476 struct req_capsule *pill = &req->rq_pill;
481 memset(md, 0, sizeof(*md));
483 md->body = req_capsule_server_get(pill, &RMF_MDT_BODY);
484 LASSERT(md->body != NULL);
486 if (md->body->valid & OBD_MD_FLEASIZE) {
488 struct lov_mds_md *lmm;
490 if (!S_ISREG(md->body->mode)) {
491 CDEBUG(D_INFO, "OBD_MD_FLEASIZE set, should be a "
492 "regular file, but is not\n");
493 GOTO(out, rc = -EPROTO);
496 if (md->body->eadatasize == 0) {
497 CDEBUG(D_INFO, "OBD_MD_FLEASIZE set, "
498 "but eadatasize 0\n");
499 GOTO(out, rc = -EPROTO);
501 lmmsize = md->body->eadatasize;
502 lmm = req_capsule_server_sized_get(pill, &RMF_MDT_MD, lmmsize);
504 GOTO(out, rc = -EPROTO);
506 rc = obd_unpackmd(dt_exp, &md->lsm, lmm, lmmsize);
510 if (rc < sizeof(*md->lsm)) {
511 CDEBUG(D_INFO, "lsm size too small: "
512 "rc < sizeof (*md->lsm) (%d < %d)\n",
513 rc, (int)sizeof(*md->lsm));
514 GOTO(out, rc = -EPROTO);
517 } else if (md->body->valid & OBD_MD_FLDIREA) {
519 struct lov_mds_md *lmv;
521 if(!S_ISDIR(md->body->mode)) {
522 CDEBUG(D_INFO, "OBD_MD_FLDIREA set, should be a "
523 "directory, but is not\n");
524 GOTO(out, rc = -EPROTO);
527 if (md->body->eadatasize == 0) {
528 CDEBUG(D_INFO, "OBD_MD_FLDIREA is set, "
529 "but eadatasize 0\n");
532 if (md->body->valid & OBD_MD_MEA) {
533 lmvsize = md->body->eadatasize;
534 lmv = req_capsule_server_sized_get(pill, &RMF_MDT_MD,
537 GOTO(out, rc = -EPROTO);
539 rc = obd_unpackmd(md_exp, (void *)&md->mea, lmv,
544 if (rc < sizeof(*md->mea)) {
545 CDEBUG(D_INFO, "size too small: "
546 "rc < sizeof(*md->mea) (%d < %d)\n",
547 rc, (int)sizeof(*md->mea));
548 GOTO(out, rc = -EPROTO);
554 if (md->body->valid & OBD_MD_FLRMTPERM) {
555 /* remote permission */
556 LASSERT(client_is_remote(exp));
557 md->remote_perm = req_capsule_server_swab_get(pill, &RMF_ACL,
558 lustre_swab_mdt_remote_perm);
559 if (!md->remote_perm)
560 GOTO(out, rc = -EPROTO);
562 else if (md->body->valid & OBD_MD_FLACL) {
563 /* for ACL, it's possible that FLACL is set but aclsize is zero.
564 * only when aclsize != 0 there's an actual segment for ACL
567 if (md->body->aclsize) {
568 rc = mdc_unpack_acl(req, md);
571 #ifdef CONFIG_FS_POSIX_ACL
573 md->posix_acl = NULL;
577 if (md->body->valid & OBD_MD_FLMDSCAPA) {
578 struct obd_capa *oc = NULL;
580 rc = mdc_unpack_capa(NULL, req, &RMF_CAPA1, &oc);
586 if (md->body->valid & OBD_MD_FLOSSCAPA) {
587 struct obd_capa *oc = NULL;
589 rc = mdc_unpack_capa(NULL, req, &RMF_CAPA2, &oc);
599 capa_put(md->oss_capa);
603 capa_put(md->mds_capa);
606 #ifdef CONFIG_FS_POSIX_ACL
607 posix_acl_release(md->posix_acl);
610 obd_free_memmd(dt_exp, &md->lsm);
615 int mdc_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
622 * Handles both OPEN and SETATTR RPCs for OPEN-CLOSE and SETATTR-DONE_WRITING
625 void mdc_replay_open(struct ptlrpc_request *req)
627 struct md_open_data *mod = req->rq_cb_data;
628 struct ptlrpc_request *close_req;
629 struct obd_client_handle *och;
630 struct lustre_handle old;
631 struct mdt_body *body;
635 DEBUG_REQ(D_ERROR, req,
636 "Can't properly replay without open data.");
641 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
642 LASSERT(body != NULL);
646 struct lustre_handle *file_fh;
648 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
650 file_fh = &och->och_fh;
651 CDEBUG(D_HA, "updating handle from "LPX64" to "LPX64"\n",
652 file_fh->cookie, body->handle.cookie);
654 *file_fh = body->handle;
656 close_req = mod->mod_close_req;
657 if (close_req != NULL) {
658 __u32 opc = lustre_msg_get_opc(close_req->rq_reqmsg);
659 struct mdt_ioepoch *epoch;
661 LASSERT(opc == MDS_CLOSE || opc == MDS_DONE_WRITING);
662 epoch = req_capsule_client_get(&close_req->rq_pill,
667 LASSERT(!memcmp(&old, &epoch->handle, sizeof(old)));
668 DEBUG_REQ(D_HA, close_req, "updating close body with new fh");
669 epoch->handle = body->handle;
674 void mdc_commit_open(struct ptlrpc_request *req)
676 struct md_open_data *mod = req->rq_cb_data;
681 * No need to touch md_open_data::mod_och, it holds a reference on
682 * \var mod and will zero references to each other, \var mod will be
683 * freed after that when md_open_data::mod_och will put the reference.
687 * Do not let open request to disappear as it still may be needed
688 * for close rpc to happen (it may happen on evict only, otherwise
689 * ptlrpc_request::rq_replay does not let mdc_commit_open() to be
690 * called), just mark this rpc as committed to distinguish these 2
691 * cases, see mdc_close() for details. The open request reference will
692 * be put along with freeing \var mod.
694 ptlrpc_request_addref(req);
695 spin_lock(&req->rq_lock);
696 req->rq_committed = 1;
697 spin_unlock(&req->rq_lock);
698 req->rq_cb_data = NULL;
702 int mdc_set_open_replay_data(struct obd_export *exp,
703 struct obd_client_handle *och,
704 struct ptlrpc_request *open_req)
706 struct md_open_data *mod;
707 struct mdt_rec_create *rec;
708 struct mdt_body *body;
709 struct obd_import *imp = open_req->rq_import;
712 if (!open_req->rq_replay)
715 rec = req_capsule_client_get(&open_req->rq_pill, &RMF_REC_REINT);
716 body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY);
717 LASSERT(rec != NULL);
718 /* Incoming message in my byte order (it's been swabbed). */
719 /* Outgoing messages always in my byte order. */
720 LASSERT(body != NULL);
722 /* Only if the import is replayable, we set replay_open data */
723 if (och && imp->imp_replayable) {
724 mod = obd_mod_alloc();
726 DEBUG_REQ(D_ERROR, open_req,
727 "Can't allocate md_open_data");
732 * Take a reference on \var mod, to be freed on mdc_close().
733 * It protects \var mod from being freed on eviction (commit
734 * callback is called despite rq_replay flag).
735 * Another reference for \var och.
740 spin_lock(&open_req->rq_lock);
743 mod->mod_open_req = open_req;
744 open_req->rq_cb_data = mod;
745 open_req->rq_commit_cb = mdc_commit_open;
746 spin_unlock(&open_req->rq_lock);
749 rec->cr_fid2 = body->fid1;
750 rec->cr_ioepoch = body->ioepoch;
751 rec->cr_old_handle.cookie = body->handle.cookie;
752 open_req->rq_replay_cb = mdc_replay_open;
753 if (!fid_is_sane(&body->fid1)) {
754 DEBUG_REQ(D_ERROR, open_req, "Saving replay request with "
759 DEBUG_REQ(D_RPCTRACE, open_req, "Set up open replay data");
763 int mdc_clear_open_replay_data(struct obd_export *exp,
764 struct obd_client_handle *och)
766 struct md_open_data *mod = och->och_mod;
769 LASSERT(mod != LP_POISON && mod != NULL);
778 /* Prepares the request for the replay by the given reply */
779 static void mdc_close_handle_reply(struct ptlrpc_request *req,
780 struct md_op_data *op_data, int rc) {
781 struct mdt_body *repbody;
782 struct mdt_ioepoch *epoch;
784 if (req && rc == -EAGAIN) {
785 repbody = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
786 epoch = req_capsule_client_get(&req->rq_pill, &RMF_MDT_EPOCH);
788 epoch->flags |= MF_SOM_AU;
789 if (repbody->valid & OBD_MD_FLGETATTRLOCK)
790 op_data->op_flags |= MF_GETATTR_LOCK;
794 int mdc_close(struct obd_export *exp, struct md_op_data *op_data,
795 struct md_open_data *mod, struct ptlrpc_request **request)
797 struct obd_device *obd = class_exp2obd(exp);
798 struct ptlrpc_request *req;
803 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_CLOSE);
807 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
809 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_CLOSE);
811 ptlrpc_request_free(req);
815 /* To avoid a livelock (bug 7034), we need to send CLOSE RPCs to a
816 * portal whose threads are not taking any DLM locks and are therefore
817 * always progressing */
818 req->rq_request_portal = MDS_READPAGE_PORTAL;
819 ptlrpc_at_set_req_timeout(req);
821 /* Ensure that this close's handle is fixed up during replay. */
822 if (likely(mod != NULL)) {
823 LASSERTF(mod->mod_open_req != NULL &&
824 mod->mod_open_req->rq_type != LI_POISON,
825 "POISONED open %p!\n", mod->mod_open_req);
827 mod->mod_close_req = req;
829 DEBUG_REQ(D_HA, mod->mod_open_req, "matched open");
830 /* We no longer want to preserve this open for replay even
831 * though the open was committed. b=3632, b=3633 */
832 spin_lock(&mod->mod_open_req->rq_lock);
833 mod->mod_open_req->rq_replay = 0;
834 spin_unlock(&mod->mod_open_req->rq_lock);
836 CDEBUG(D_HA, "couldn't find open req; expecting close error\n");
839 mdc_close_pack(req, op_data);
841 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER,
842 obd->u.cli.cl_max_mds_easize);
843 req_capsule_set_size(&req->rq_pill, &RMF_LOGCOOKIES, RCL_SERVER,
844 obd->u.cli.cl_max_mds_cookiesize);
846 ptlrpc_request_set_replen(req);
848 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
849 rc = ptlrpc_queue_wait(req);
850 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
852 if (req->rq_repmsg == NULL) {
853 CDEBUG(D_RPCTRACE, "request failed to send: %p, %d\n", req,
856 rc = req->rq_status ?: -EIO;
857 } else if (rc == 0 || rc == -EAGAIN) {
858 struct mdt_body *body;
860 rc = lustre_msg_get_status(req->rq_repmsg);
861 if (lustre_msg_get_type(req->rq_repmsg) == PTL_RPC_MSG_ERR) {
862 DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, err "
867 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
870 } else if (rc == -ESTALE) {
872 * it can be allowed error after 3633 if open was committed and
873 * server failed before close was sent. Let's check if mod
874 * exists and return no error in that case
877 LASSERT(mod->mod_open_req != NULL);
878 if (mod->mod_open_req->rq_committed)
885 mod->mod_close_req = NULL;
886 /* Since now, mod is accessed through open_req only,
887 * thus close req does not keep a reference on mod anymore. */
891 mdc_close_handle_reply(req, op_data, rc);
895 int mdc_done_writing(struct obd_export *exp, struct md_op_data *op_data,
896 struct md_open_data *mod)
898 struct obd_device *obd = class_exp2obd(exp);
899 struct ptlrpc_request *req;
903 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
904 &RQF_MDS_DONE_WRITING);
908 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
909 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_DONE_WRITING);
911 ptlrpc_request_free(req);
916 LASSERTF(mod->mod_open_req != NULL &&
917 mod->mod_open_req->rq_type != LI_POISON,
918 "POISONED setattr %p!\n", mod->mod_open_req);
920 mod->mod_close_req = req;
921 DEBUG_REQ(D_HA, mod->mod_open_req, "matched setattr");
922 /* We no longer want to preserve this setattr for replay even
923 * though the open was committed. b=3632, b=3633 */
924 spin_lock(&mod->mod_open_req->rq_lock);
925 mod->mod_open_req->rq_replay = 0;
926 spin_unlock(&mod->mod_open_req->rq_lock);
929 mdc_close_pack(req, op_data);
930 ptlrpc_request_set_replen(req);
932 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
933 rc = ptlrpc_queue_wait(req);
934 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
938 * it can be allowed error after 3633 if open or setattr were
939 * committed and server failed before close was sent.
940 * Let's check if mod exists and return no error in that case
943 LASSERT(mod->mod_open_req != NULL);
944 if (mod->mod_open_req->rq_committed)
951 mod->mod_close_req = NULL;
952 /* Since now, mod is accessed through setattr req only,
953 * thus DW req does not keep a reference on mod anymore. */
957 mdc_close_handle_reply(req, op_data, rc);
958 ptlrpc_req_finished(req);
962 #ifdef HAVE_SPLIT_SUPPORT
963 int mdc_sendpage(struct obd_export *exp, const struct lu_fid *fid,
964 const struct page *page, int offset)
966 struct ptlrpc_request *req;
967 struct ptlrpc_bulk_desc *desc;
971 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_WRITEPAGE);
975 /* FIXME: capa doesn't support split yet */
976 mdc_set_capa_size(req, &RMF_CAPA1, NULL);
978 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_WRITEPAGE);
980 ptlrpc_request_free(req);
984 req->rq_request_portal = MDS_READPAGE_PORTAL;
985 ptlrpc_at_set_req_timeout(req);
987 desc = ptlrpc_prep_bulk_imp(req, 1, BULK_GET_SOURCE, MDS_BULK_PORTAL);
989 GOTO(out, rc = -ENOMEM);
991 /* NB req now owns desc and will free it when it gets freed. */
992 ptlrpc_prep_bulk_page(desc, (struct page *)page, 0, offset);
993 mdc_readdir_pack(req, 0, offset, fid, NULL);
995 ptlrpc_request_set_replen(req);
996 rc = ptlrpc_queue_wait(req);
1000 rc = sptlrpc_cli_unwrap_bulk_write(req, req->rq_bulk);
1002 ptlrpc_req_finished(req);
1005 EXPORT_SYMBOL(mdc_sendpage);
1008 int mdc_readpage(struct obd_export *exp, const struct lu_fid *fid,
1009 struct obd_capa *oc, __u64 offset, struct page *page,
1010 struct ptlrpc_request **request)
1012 struct ptlrpc_request *req;
1013 struct ptlrpc_bulk_desc *desc;
1018 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_READPAGE);
1022 mdc_set_capa_size(req, &RMF_CAPA1, oc);
1024 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_READPAGE);
1026 ptlrpc_request_free(req);
1030 req->rq_request_portal = MDS_READPAGE_PORTAL;
1031 ptlrpc_at_set_req_timeout(req);
1033 desc = ptlrpc_prep_bulk_imp(req, 1, BULK_PUT_SINK, MDS_BULK_PORTAL);
1035 ptlrpc_request_free(req);
1039 /* NB req now owns desc and will free it when it gets freed */
1040 ptlrpc_prep_bulk_page(desc, page, 0, CFS_PAGE_SIZE);
1041 mdc_readdir_pack(req, offset, CFS_PAGE_SIZE, fid, oc);
1043 ptlrpc_request_set_replen(req);
1044 rc = ptlrpc_queue_wait(req);
1046 ptlrpc_req_finished(req);
1050 rc = sptlrpc_cli_unwrap_bulk_read(req, req->rq_bulk,
1051 req->rq_bulk->bd_nob_transferred);
1053 ptlrpc_req_finished(req);
1057 if (req->rq_bulk->bd_nob_transferred != CFS_PAGE_SIZE) {
1058 CERROR("Unexpected # bytes transferred: %d (%ld expected)\n",
1059 req->rq_bulk->bd_nob_transferred, CFS_PAGE_SIZE);
1060 ptlrpc_req_finished(req);
1068 static int mdc_ioc_fid2path(struct obd_export *exp, struct getinfo_fid2path *gf)
1070 __u32 keylen, vallen;
1074 if (gf->gf_pathlen > PATH_MAX)
1075 RETURN(-ENAMETOOLONG);
1076 if (gf->gf_pathlen < 2)
1079 /* Key is KEY_FID2PATH + getinfo_fid2path description */
1080 keylen = size_round(sizeof(KEY_FID2PATH)) + sizeof(*gf);
1081 OBD_ALLOC(key, keylen);
1084 memcpy(key, KEY_FID2PATH, sizeof(KEY_FID2PATH));
1085 memcpy(key + size_round(sizeof(KEY_FID2PATH)), gf, sizeof(*gf));
1087 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
1088 PFID(&gf->gf_fid), gf->gf_recno, gf->gf_linkno);
1090 if (!fid_is_sane(&gf->gf_fid))
1091 GOTO(out, rc = -EINVAL);
1093 /* Val is struct getinfo_fid2path result plus path */
1094 vallen = sizeof(*gf) + gf->gf_pathlen;
1096 rc = obd_get_info(exp, keylen, key, &vallen, gf, NULL);
1100 if (vallen <= sizeof(*gf))
1101 GOTO(out, rc = -EPROTO);
1102 else if (vallen > sizeof(*gf) + gf->gf_pathlen)
1103 GOTO(out, rc = -EOVERFLOW);
1105 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n%s\n",
1106 PFID(&gf->gf_fid), gf->gf_recno, gf->gf_linkno, gf->gf_path);
1109 OBD_FREE(key, keylen);
1113 static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1114 void *karg, void *uarg)
1116 struct obd_device *obd = exp->exp_obd;
1117 struct obd_ioctl_data *data = karg;
1118 struct obd_import *imp = obd->u.cli.cl_import;
1119 struct llog_ctxt *ctxt;
1123 if (!try_module_get(THIS_MODULE)) {
1124 CERROR("Can't get module. Is it alive?");
1128 case OBD_IOC_CHANGELOG_CLEAR: {
1129 struct ioc_changelog_clear *icc = karg;
1130 struct changelog_setinfo cs =
1131 {icc->icc_recno, icc->icc_id};
1132 rc = obd_set_info_async(exp, strlen(KEY_CHANGELOG_CLEAR),
1133 KEY_CHANGELOG_CLEAR, sizeof(cs), &cs,
1137 case OBD_IOC_FID2PATH: {
1138 rc = mdc_ioc_fid2path(exp, karg);
1141 case OBD_IOC_CLIENT_RECOVER:
1142 rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1);
1146 case IOC_OSC_SET_ACTIVE:
1147 rc = ptlrpc_set_import_active(imp, data->ioc_offset);
1149 case OBD_IOC_PARSE: {
1150 ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT);
1151 rc = class_config_parse_llog(ctxt, data->ioc_inlbuf1, NULL);
1152 llog_ctxt_put(ctxt);
1156 case OBD_IOC_LLOG_INFO:
1157 case OBD_IOC_LLOG_PRINT: {
1158 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
1159 rc = llog_ioctl(ctxt, cmd, data);
1160 llog_ctxt_put(ctxt);
1164 case OBD_IOC_POLL_QUOTACHECK:
1165 rc = lquota_poll_check(quota_interface, exp,
1166 (struct if_quotacheck *)karg);
1168 case OBD_IOC_PING_TARGET:
1169 rc = ptlrpc_obd_ping(obd);
1172 CERROR("mdc_ioctl(): unrecognised ioctl %#x\n", cmd);
1173 GOTO(out, rc = -ENOTTY);
1176 module_put(THIS_MODULE);
1181 int mdc_get_info_rpc(struct obd_export *exp,
1182 obd_count keylen, void *key,
1183 int vallen, void *val)
1185 struct obd_import *imp = class_exp2cliimp(exp);
1186 struct ptlrpc_request *req;
1191 req = ptlrpc_request_alloc(imp, &RQF_MDS_GET_INFO);
1195 req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_KEY,
1196 RCL_CLIENT, keylen);
1197 req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_VALLEN,
1198 RCL_CLIENT, sizeof(__u32));
1200 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GET_INFO);
1202 ptlrpc_request_free(req);
1206 tmp = req_capsule_client_get(&req->rq_pill, &RMF_GETINFO_KEY);
1207 memcpy(tmp, key, keylen);
1208 tmp = req_capsule_client_get(&req->rq_pill, &RMF_GETINFO_VALLEN);
1209 memcpy(tmp, &vallen, sizeof(__u32));
1211 req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_VAL,
1212 RCL_SERVER, vallen);
1213 ptlrpc_request_set_replen(req);
1215 rc = ptlrpc_queue_wait(req);
1217 tmp = req_capsule_server_get(&req->rq_pill, &RMF_GETINFO_VAL);
1218 memcpy(val, tmp, vallen);
1219 if (ptlrpc_rep_need_swab(req)) {
1220 if (KEY_IS(KEY_FID2PATH)) {
1221 lustre_swab_fid2path(val);
1225 ptlrpc_req_finished(req);
1230 static void lustre_swab_hai(struct hsm_action_item *h)
1232 __swab32s(&h->hai_len);
1233 __swab32s(&h->hai_action);
1234 lustre_swab_lu_fid(&h->hai_fid);
1235 __swab64s(&h->hai_cookie);
1236 __swab64s(&h->hai_extent_start);
1237 __swab64s(&h->hai_extent_end);
1238 __swab64s(&h->hai_gid);
1241 static void lustre_swab_hal(struct hsm_action_list *h)
1243 struct hsm_action_item *hai;
1246 __swab32s(&h->hal_version);
1247 __swab32s(&h->hal_count);
1248 __swab32s(&h->hal_archive_num);
1250 for (i = 0; i < h->hal_count; i++) {
1251 lustre_swab_hai(hai);
1252 hai = hai_next(hai);
1257 * Send a message to any listening copytools, nonblocking
1258 * @param val LNL message (lnl_hdr + hsm_action_list)
1259 * @param len total length of message
1261 static int mdc_hsm_copytool_send(int len, void *val)
1263 struct lnl_hdr *lh = (struct lnl_hdr *)val;
1264 struct hsm_action_list *hal = (struct hsm_action_list *)(lh + 1);
1268 if (len < sizeof(*lh) + sizeof(*hal)) {
1269 CERROR("Short HSM message %d < %d\n", len,
1270 (int) (sizeof(*lh) + sizeof(*hal)));
1273 if (lh->lnl_magic == __swab16(LNL_MAGIC)) {
1274 lustre_swab_lnlh(lh);
1275 lustre_swab_hal(hal);
1276 } else if (lh->lnl_magic != LNL_MAGIC) {
1277 CERROR("Bad magic %x!=%x\n", lh->lnl_magic, LNL_MAGIC);
1281 CDEBUG(D_IOCTL, " Received message mg=%x t=%d m=%d l=%d actions=%d\n",
1282 lh->lnl_magic, lh->lnl_transport, lh->lnl_msgtype,
1283 lh->lnl_msglen, hal->hal_count);
1285 /* Broadcast to HSM listeners */
1286 rc = libcfs_klnl_msg_put(0, LNL_GRP_HSM, lh);
1291 int mdc_set_info_async(struct obd_export *exp,
1292 obd_count keylen, void *key,
1293 obd_count vallen, void *val,
1294 struct ptlrpc_request_set *set)
1296 struct obd_import *imp = class_exp2cliimp(exp);
1300 if (KEY_IS(KEY_INIT_RECOV)) {
1301 if (vallen != sizeof(int))
1303 spin_lock(&imp->imp_lock);
1304 imp->imp_initial_recov = *(int *)val;
1305 spin_unlock(&imp->imp_lock);
1306 CDEBUG(D_HA, "%s: set imp_initial_recov = %d\n",
1307 exp->exp_obd->obd_name, imp->imp_initial_recov);
1310 /* Turn off initial_recov after we try all backup servers once */
1311 if (KEY_IS(KEY_INIT_RECOV_BACKUP)) {
1312 if (vallen != sizeof(int))
1314 spin_lock(&imp->imp_lock);
1315 imp->imp_initial_recov_bk = *(int *)val;
1316 if (imp->imp_initial_recov_bk)
1317 imp->imp_initial_recov = 1;
1318 spin_unlock(&imp->imp_lock);
1319 CDEBUG(D_HA, "%s: set imp_initial_recov_bk = %d\n",
1320 exp->exp_obd->obd_name, imp->imp_initial_recov_bk);
1323 if (KEY_IS(KEY_READ_ONLY)) {
1324 if (vallen != sizeof(int))
1327 spin_lock(&imp->imp_lock);
1328 if (*((int *)val)) {
1329 imp->imp_connect_flags_orig |= OBD_CONNECT_RDONLY;
1330 imp->imp_connect_data.ocd_connect_flags |= OBD_CONNECT_RDONLY;
1332 imp->imp_connect_flags_orig &= ~OBD_CONNECT_RDONLY;
1333 imp->imp_connect_data.ocd_connect_flags &= ~OBD_CONNECT_RDONLY;
1335 spin_unlock(&imp->imp_lock);
1337 rc = target_set_info_rpc(imp, MDS_SET_INFO,
1338 keylen, key, vallen, val, set);
1341 if (KEY_IS(KEY_SPTLRPC_CONF)) {
1342 sptlrpc_conf_client_adapt(exp->exp_obd);
1345 if (KEY_IS(KEY_FLUSH_CTX)) {
1346 sptlrpc_import_flush_my_ctx(imp);
1349 if (KEY_IS(KEY_MDS_CONN)) {
1350 /* mds-mds import */
1351 spin_lock(&imp->imp_lock);
1352 imp->imp_server_timeout = 1;
1353 spin_unlock(&imp->imp_lock);
1354 imp->imp_client->cli_request_portal = MDS_MDS_PORTAL;
1355 CDEBUG(D_OTHER, "%s: timeout / 2\n", exp->exp_obd->obd_name);
1358 if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
1359 rc = target_set_info_rpc(imp, MDS_SET_INFO,
1360 keylen, key, vallen, val, set);
1363 if (KEY_IS(KEY_HSM_COPYTOOL_SEND)) {
1364 rc = mdc_hsm_copytool_send(vallen, val);
1371 int mdc_get_info(struct obd_export *exp, __u32 keylen, void *key,
1372 __u32 *vallen, void *val, struct lov_stripe_md *lsm)
1376 if (KEY_IS(KEY_MAX_EASIZE)) {
1377 int mdsize, *max_easize;
1379 if (*vallen != sizeof(int))
1381 mdsize = *(int*)val;
1382 if (mdsize > exp->exp_obd->u.cli.cl_max_mds_easize)
1383 exp->exp_obd->u.cli.cl_max_mds_easize = mdsize;
1385 *max_easize = exp->exp_obd->u.cli.cl_max_mds_easize;
1388 if (KEY_IS(KEY_CONN_DATA)) {
1389 struct obd_import *imp = class_exp2cliimp(exp);
1390 struct obd_connect_data *data = val;
1392 if (*vallen != sizeof(*data))
1395 *data = imp->imp_connect_data;
1399 rc = mdc_get_info_rpc(exp, keylen, key, *vallen, val);
1404 static int mdc_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1405 __u64 max_age, __u32 flags)
1407 struct ptlrpc_request *req;
1408 struct obd_statfs *msfs;
1409 struct obd_import *imp = NULL;
1414 /*Since the request might also come from lprocfs, so we need
1415 *sync this with client_disconnect_export Bug15684*/
1416 down_read(&obd->u.cli.cl_sem);
1417 if (obd->u.cli.cl_import)
1418 imp = class_import_get(obd->u.cli.cl_import);
1419 up_read(&obd->u.cli.cl_sem);
1423 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_STATFS,
1424 LUSTRE_MDS_VERSION, MDS_STATFS);
1426 GOTO(output, rc = -ENOMEM);
1428 ptlrpc_request_set_replen(req);
1430 if (flags & OBD_STATFS_NODELAY) {
1431 /* procfs requests not want stay in wait for avoid deadlock */
1432 req->rq_no_resend = 1;
1433 req->rq_no_delay = 1;
1436 rc = ptlrpc_queue_wait(req);
1438 /* check connection error first */
1439 if (imp->imp_connect_error)
1440 rc = imp->imp_connect_error;
1444 msfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
1446 GOTO(out, rc = -EPROTO);
1451 ptlrpc_req_finished(req);
1453 class_import_put(imp);
1457 static int mdc_pin(struct obd_export *exp, const struct lu_fid *fid,
1458 struct obd_capa *oc, struct obd_client_handle *handle,
1461 struct ptlrpc_request *req;
1462 struct mdt_body *body;
1466 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_PIN);
1470 mdc_set_capa_size(req, &RMF_CAPA1, oc);
1472 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_PIN);
1474 ptlrpc_request_free(req);
1478 mdc_pack_body(req, fid, oc, 0, 0, -1, flags);
1480 ptlrpc_request_set_replen(req);
1482 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1483 rc = ptlrpc_queue_wait(req);
1484 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1486 CERROR("Pin failed: %d\n", rc);
1490 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1492 GOTO(err_out, rc = -EPROTO);
1494 handle->och_fh = body->handle;
1495 handle->och_magic = OBD_CLIENT_HANDLE_MAGIC;
1497 handle->och_mod = obd_mod_alloc();
1498 if (handle->och_mod == NULL) {
1499 DEBUG_REQ(D_ERROR, req, "can't allocate md_open_data");
1500 GOTO(err_out, rc = -ENOMEM);
1502 handle->och_mod->mod_open_req = req; /* will be dropped by unpin */
1507 ptlrpc_req_finished(req);
1511 static int mdc_unpin(struct obd_export *exp, struct obd_client_handle *handle,
1514 struct ptlrpc_request *req;
1515 struct mdt_body *body;
1519 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_UNPIN,
1520 LUSTRE_MDS_VERSION, MDS_UNPIN);
1524 body = req_capsule_client_get(&req->rq_pill, &RMF_MDT_BODY);
1525 body->handle = handle->och_fh;
1528 ptlrpc_request_set_replen(req);
1530 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1531 rc = ptlrpc_queue_wait(req);
1532 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1535 CERROR("Unpin failed: %d\n", rc);
1537 ptlrpc_req_finished(req);
1538 ptlrpc_req_finished(handle->och_mod->mod_open_req);
1540 obd_mod_put(handle->och_mod);
1544 int mdc_sync(struct obd_export *exp, const struct lu_fid *fid,
1545 struct obd_capa *oc, struct ptlrpc_request **request)
1547 struct ptlrpc_request *req;
1552 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_SYNC);
1556 mdc_set_capa_size(req, &RMF_CAPA1, oc);
1558 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_SYNC);
1560 ptlrpc_request_free(req);
1564 mdc_pack_body(req, fid, oc, 0, 0, -1, 0);
1566 ptlrpc_request_set_replen(req);
1568 rc = ptlrpc_queue_wait(req);
1570 ptlrpc_req_finished(req);
1576 static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
1577 enum obd_import_event event)
1581 LASSERT(imp->imp_obd == obd);
1584 case IMP_EVENT_DISCON: {
1586 /* XXX Pass event up to OBDs stack. used only for FLD now */
1587 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_DISCON, NULL);
1591 case IMP_EVENT_INACTIVE: {
1592 struct client_obd *cli = &obd->u.cli;
1594 * Flush current sequence to make client obtain new one
1595 * from server in case of disconnect/reconnect.
1596 * If range is already empty then no need to flush it.
1598 if (cli->cl_seq != NULL &&
1599 !range_is_exhausted(&cli->cl_seq->lcs_space)) {
1600 seq_client_flush(cli->cl_seq);
1603 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_INACTIVE, NULL);
1606 case IMP_EVENT_INVALIDATE: {
1607 struct ldlm_namespace *ns = obd->obd_namespace;
1609 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
1613 case IMP_EVENT_ACTIVE: {
1614 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_ACTIVE, NULL);
1618 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_OCD, NULL);
1622 CERROR("Unknown import event %x\n", event);
1628 static int mdc_fid_init(struct obd_export *exp)
1630 struct client_obd *cli = &exp->exp_obd->u.cli;
1635 OBD_ALLOC_PTR(cli->cl_seq);
1636 if (cli->cl_seq == NULL)
1639 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
1641 GOTO(out_free_seq, rc = -ENOMEM);
1643 snprintf(prefix, MAX_OBD_NAME + 5, "srv-%s",
1644 exp->exp_obd->obd_name);
1646 /* Init client side sequence-manager */
1647 rc = seq_client_init(cli->cl_seq, exp,
1648 LUSTRE_SEQ_METADATA,
1650 OBD_FREE(prefix, MAX_OBD_NAME + 5);
1652 GOTO(out_free_seq, rc);
1656 OBD_FREE_PTR(cli->cl_seq);
1661 static int mdc_fid_fini(struct obd_export *exp)
1663 struct client_obd *cli = &exp->exp_obd->u.cli;
1666 if (cli->cl_seq != NULL) {
1667 seq_client_fini(cli->cl_seq);
1668 OBD_FREE_PTR(cli->cl_seq);
1675 int mdc_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
1676 struct md_op_data *op_data)
1678 struct client_obd *cli = &exp->exp_obd->u.cli;
1679 struct lu_client_seq *seq = cli->cl_seq;
1681 RETURN(seq_client_alloc_fid(seq, fid));
1684 /* XXX This method is used only to clear current fid seq
1685 * once fld/mds insert failed */
1686 static int mdc_fid_delete(struct obd_export *exp, const struct lu_fid *fid)
1688 struct client_obd *cli = &exp->exp_obd->u.cli;
1690 seq_client_flush(cli->cl_seq);
1694 struct obd_uuid *mdc_get_uuid(struct obd_export *exp) {
1695 struct client_obd *cli = &exp->exp_obd->u.cli;
1696 return &cli->cl_target_uuid;
1699 static int mdc_setup(struct obd_device *obd, struct lustre_cfg *cfg)
1701 struct client_obd *cli = &obd->u.cli;
1702 struct lprocfs_static_vars lvars = { 0 };
1706 OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1707 if (!cli->cl_rpc_lock)
1709 mdc_init_rpc_lock(cli->cl_rpc_lock);
1713 OBD_ALLOC(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1714 if (!cli->cl_setattr_lock)
1715 GOTO(err_rpc_lock, rc = -ENOMEM);
1716 mdc_init_rpc_lock(cli->cl_setattr_lock);
1718 OBD_ALLOC(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1719 if (!cli->cl_close_lock)
1720 GOTO(err_setattr_lock, rc = -ENOMEM);
1721 mdc_init_rpc_lock(cli->cl_close_lock);
1723 rc = client_obd_setup(obd, cfg);
1725 GOTO(err_close_lock, rc);
1726 lprocfs_mdc_init_vars(&lvars);
1727 lprocfs_obd_setup(obd, lvars.obd_vars);
1728 sptlrpc_lprocfs_cliobd_attach(obd);
1729 ptlrpc_lprocfs_register_obd(obd);
1731 rc = obd_llog_init(obd, &obd->obd_olg, obd, NULL);
1734 CERROR("failed to setup llogging subsystems\n");
1738 libcfs_klnl_start(LNL_TRANSPORT_HSM);
1739 libcfs_klnl_start(LNL_TRANSPORT_CHANGELOG);
1744 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1746 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1748 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1753 /* Initialize the default and maximum LOV EA and cookie sizes. This allows
1754 * us to make MDS RPCs with large enough reply buffers to hold the
1755 * maximum-sized (= maximum striped) EA and cookie without having to
1756 * calculate this (via a call into the LOV + OSCs) each time we make an RPC. */
1757 static int mdc_init_ea_size(struct obd_export *exp, int easize,
1758 int def_easize, int cookiesize)
1760 struct obd_device *obd = exp->exp_obd;
1761 struct client_obd *cli = &obd->u.cli;
1764 if (cli->cl_max_mds_easize < easize)
1765 cli->cl_max_mds_easize = easize;
1767 if (cli->cl_default_mds_easize < def_easize)
1768 cli->cl_default_mds_easize = def_easize;
1770 if (cli->cl_max_mds_cookiesize < cookiesize)
1771 cli->cl_max_mds_cookiesize = cookiesize;
1776 static int mdc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
1782 case OBD_CLEANUP_EARLY:
1783 case OBD_CLEANUP_EXPORTS:
1784 /* If we set up but never connected, the
1785 client import will not have been cleaned. */
1786 if (obd->u.cli.cl_import) {
1787 struct obd_import *imp;
1788 down_write(&obd->u.cli.cl_sem);
1789 imp = obd->u.cli.cl_import;
1790 CERROR("client import never connected\n");
1791 ptlrpc_invalidate_import(imp);
1792 class_destroy_import(imp);
1793 up_write(&obd->u.cli.cl_sem);
1794 obd->u.cli.cl_import = NULL;
1796 rc = obd_llog_finish(obd, 0);
1798 CERROR("failed to cleanup llogging subsystems\n");
1804 static int mdc_cleanup(struct obd_device *obd)
1806 struct client_obd *cli = &obd->u.cli;
1808 libcfs_klnl_stop(LNL_TRANSPORT_HSM, LNL_GRP_HSM);
1809 libcfs_klnl_stop(LNL_TRANSPORT_CHANGELOG, 0);
1811 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
1812 OBD_FREE(cli->cl_setattr_lock, sizeof (*cli->cl_setattr_lock));
1813 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
1815 ptlrpc_lprocfs_unregister_obd(obd);
1816 lprocfs_obd_cleanup(obd);
1819 return client_obd_cleanup(obd);
1823 static int mdc_llog_init(struct obd_device *obd, struct obd_llog_group *olg,
1824 struct obd_device *tgt, int *index)
1826 struct llog_ctxt *ctxt;
1830 LASSERT(olg == &obd->obd_olg);
1832 rc = llog_setup(obd, olg, LLOG_LOVEA_REPL_CTXT, tgt, 0, NULL,
1837 ctxt = llog_get_context(obd, LLOG_LOVEA_REPL_CTXT);
1838 llog_initiator_connect(ctxt);
1839 llog_ctxt_put(ctxt);
1841 rc = llog_setup(obd, olg, LLOG_CHANGELOG_REPL_CTXT, tgt, 0, NULL,
1844 ctxt = llog_group_get_ctxt(olg, LLOG_CHANGELOG_REPL_CTXT);
1845 llog_initiator_connect(ctxt);
1846 llog_ctxt_put(ctxt);
1852 static int mdc_llog_finish(struct obd_device *obd, int count)
1854 struct llog_ctxt *ctxt;
1858 ctxt = llog_get_context(obd, LLOG_LOVEA_REPL_CTXT);
1860 rc = llog_cleanup(ctxt);
1862 ctxt = llog_get_context(obd, LLOG_CHANGELOG_REPL_CTXT);
1864 rc = llog_cleanup(ctxt);
1869 static int mdc_process_config(struct obd_device *obd, obd_count len, void *buf)
1871 struct lustre_cfg *lcfg = buf;
1872 struct lprocfs_static_vars lvars = { 0 };
1875 lprocfs_mdc_init_vars(&lvars);
1876 switch (lcfg->lcfg_command) {
1878 rc = class_process_proc_param(PARAM_MDC, lvars.obd_vars,
1888 /* get remote permission for current user on fid */
1889 int mdc_get_remote_perm(struct obd_export *exp, const struct lu_fid *fid,
1890 struct obd_capa *oc, __u32 suppgid,
1891 struct ptlrpc_request **request)
1893 struct ptlrpc_request *req;
1897 LASSERT(client_is_remote(exp));
1900 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR);
1904 mdc_set_capa_size(req, &RMF_CAPA1, oc);
1906 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR);
1908 ptlrpc_request_free(req);
1912 mdc_pack_body(req, fid, oc, OBD_MD_FLRMTPERM, 0, suppgid, 0);
1914 req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER,
1915 sizeof(struct mdt_remote_perm));
1917 ptlrpc_request_set_replen(req);
1919 rc = ptlrpc_queue_wait(req);
1921 ptlrpc_req_finished(req);
1927 static int mdc_interpret_renew_capa(const struct lu_env *env,
1928 struct ptlrpc_request *req, void *unused,
1931 struct obd_capa *oc = req->rq_async_args.pointer_arg[0];
1932 renew_capa_cb_t cb = req->rq_async_args.pointer_arg[1];
1933 struct mdt_body *body = NULL;
1934 struct lustre_capa *capa;
1938 GOTO(out, capa = ERR_PTR(status));
1940 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1942 GOTO(out, capa = ERR_PTR(-EFAULT));
1944 if ((body->valid & OBD_MD_FLOSSCAPA) == 0)
1945 GOTO(out, capa = ERR_PTR(-ENOENT));
1947 capa = req_capsule_server_get(&req->rq_pill, &RMF_CAPA2);
1949 GOTO(out, capa = ERR_PTR(-EFAULT));
1956 static int mdc_renew_capa(struct obd_export *exp, struct obd_capa *oc,
1959 struct ptlrpc_request *req;
1962 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_GETATTR,
1963 LUSTRE_MDS_VERSION, MDS_GETATTR);
1967 /* NB, OBD_MD_FLOSSCAPA is set here, but it doesn't necessarily mean the
1968 * capa to renew is oss capa.
1970 mdc_pack_body(req, &oc->c_capa.lc_fid, oc, OBD_MD_FLOSSCAPA, 0, -1, 0);
1971 ptlrpc_request_set_replen(req);
1973 req->rq_async_args.pointer_arg[0] = oc;
1974 req->rq_async_args.pointer_arg[1] = cb;
1975 req->rq_interpret_reply = mdc_interpret_renew_capa;
1976 ptlrpcd_add_req(req, PSCOPE_OTHER);
1980 static int mdc_connect(const struct lu_env *env,
1981 struct obd_export **exp,
1982 struct obd_device *obd, struct obd_uuid *cluuid,
1983 struct obd_connect_data *data,
1986 struct obd_import *imp = obd->u.cli.cl_import;
1988 /* mds-mds import features */
1989 if (data && (data->ocd_connect_flags & OBD_CONNECT_MDS_MDS)) {
1990 spin_lock(&imp->imp_lock);
1991 imp->imp_server_timeout = 1;
1992 spin_unlock(&imp->imp_lock);
1993 imp->imp_client->cli_request_portal = MDS_MDS_PORTAL;
1994 CDEBUG(D_OTHER, "%s: Set 'mds' portal and timeout\n",
1998 return client_connect_import(env, exp, obd, cluuid, data, NULL);
2001 struct obd_ops mdc_obd_ops = {
2002 .o_owner = THIS_MODULE,
2003 .o_setup = mdc_setup,
2004 .o_precleanup = mdc_precleanup,
2005 .o_cleanup = mdc_cleanup,
2006 .o_add_conn = client_import_add_conn,
2007 .o_del_conn = client_import_del_conn,
2008 .o_connect = mdc_connect,
2009 .o_disconnect = client_disconnect_export,
2010 .o_iocontrol = mdc_iocontrol,
2011 .o_set_info_async = mdc_set_info_async,
2012 .o_statfs = mdc_statfs,
2014 .o_unpin = mdc_unpin,
2015 .o_fid_init = mdc_fid_init,
2016 .o_fid_fini = mdc_fid_fini,
2017 .o_fid_alloc = mdc_fid_alloc,
2018 .o_fid_delete = mdc_fid_delete,
2019 .o_import_event = mdc_import_event,
2020 .o_llog_init = mdc_llog_init,
2021 .o_llog_finish = mdc_llog_finish,
2022 .o_get_info = mdc_get_info,
2023 .o_process_config = mdc_process_config,
2024 .o_get_uuid = mdc_get_uuid,
2027 struct md_ops mdc_md_ops = {
2028 .m_getstatus = mdc_getstatus,
2029 .m_change_cbdata = mdc_change_cbdata,
2030 .m_close = mdc_close,
2031 .m_create = mdc_create,
2032 .m_done_writing = mdc_done_writing,
2033 .m_enqueue = mdc_enqueue,
2034 .m_getattr = mdc_getattr,
2035 .m_getattr_name = mdc_getattr_name,
2036 .m_intent_lock = mdc_intent_lock,
2038 .m_is_subdir = mdc_is_subdir,
2039 .m_rename = mdc_rename,
2040 .m_setattr = mdc_setattr,
2041 .m_setxattr = mdc_setxattr,
2042 .m_getxattr = mdc_getxattr,
2044 .m_readpage = mdc_readpage,
2045 .m_unlink = mdc_unlink,
2046 .m_cancel_unused = mdc_cancel_unused,
2047 .m_init_ea_size = mdc_init_ea_size,
2048 .m_set_lock_data = mdc_set_lock_data,
2049 .m_lock_match = mdc_lock_match,
2050 .m_get_lustre_md = mdc_get_lustre_md,
2051 .m_free_lustre_md = mdc_free_lustre_md,
2052 .m_set_open_replay_data = mdc_set_open_replay_data,
2053 .m_clear_open_replay_data = mdc_clear_open_replay_data,
2054 .m_renew_capa = mdc_renew_capa,
2055 .m_unpack_capa = mdc_unpack_capa,
2056 .m_get_remote_perm = mdc_get_remote_perm,
2057 .m_intent_getattr_async = mdc_intent_getattr_async,
2058 .m_revalidate_lock = mdc_revalidate_lock
2061 int __init mdc_init(void)
2064 struct lprocfs_static_vars lvars = { 0 };
2065 lprocfs_mdc_init_vars(&lvars);
2067 request_module("lquota");
2068 quota_interface = PORTAL_SYMBOL_GET(mdc_quota_interface);
2069 init_obd_quota_ops(quota_interface, &mdc_obd_ops);
2071 rc = class_register_type(&mdc_obd_ops, &mdc_md_ops, lvars.module_vars,
2072 LUSTRE_MDC_NAME, NULL);
2073 if (rc && quota_interface)
2074 PORTAL_SYMBOL_PUT(mdc_quota_interface);
2080 static void /*__exit*/ mdc_exit(void)
2082 if (quota_interface)
2083 PORTAL_SYMBOL_PUT(mdc_quota_interface);
2085 class_unregister_type(LUSTRE_MDC_NAME);
2088 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2089 MODULE_DESCRIPTION("Lustre Metadata Client");
2090 MODULE_LICENSE("GPL");
2092 module_init(mdc_init);
2093 module_exit(mdc_exit);