4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_MDC
39 # include <linux/module.h>
40 # include <linux/pagemap.h>
41 # include <linux/miscdevice.h>
42 # include <linux/init.h>
43 # include <linux/utsname.h>
45 #include <lustre_acl.h>
46 #include <obd_class.h>
47 #include <lustre_fid.h>
48 #include <lprocfs_status.h>
49 #include <lustre_param.h>
50 #include <lustre_log.h>
52 #include "mdc_internal.h"
54 #define REQUEST_MINOR 244
56 struct mdc_renew_capa_args {
57 struct obd_capa *ra_oc;
58 renew_capa_cb_t ra_cb;
61 static int mdc_cleanup(struct obd_device *obd);
63 int mdc_unpack_capa(struct obd_export *exp, struct ptlrpc_request *req,
64 const struct req_msg_field *field, struct obd_capa **oc)
66 struct lustre_capa *capa;
70 /* swabbed already in mdc_enqueue */
71 capa = req_capsule_server_get(&req->rq_pill, field);
75 c = alloc_capa(CAPA_SITE_CLIENT);
77 CDEBUG(D_INFO, "alloc capa failed!\n");
86 static inline int mdc_queue_wait(struct ptlrpc_request *req)
88 struct client_obd *cli = &req->rq_import->imp_obd->u.cli;
91 /* mdc_enter_request() ensures that this client has no more
92 * than cl_max_rpcs_in_flight RPCs simultaneously inf light
94 rc = mdc_enter_request(cli);
98 rc = ptlrpc_queue_wait(req);
99 mdc_exit_request(cli);
104 /* Helper that implements most of mdc_getstatus and signal_completed_replay. */
105 /* XXX this should become mdc_get_info("key"), sending MDS_GET_INFO RPC */
106 static int send_getstatus(struct obd_import *imp, struct lu_fid *rootfid,
107 struct obd_capa **pc, int level, int msg_flags)
109 struct ptlrpc_request *req;
110 struct mdt_body *body;
114 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_GETSTATUS,
115 LUSTRE_MDS_VERSION, MDS_GETSTATUS);
119 mdc_pack_body(req, NULL, NULL, 0, 0, -1, 0);
120 lustre_msg_add_flags(req->rq_reqmsg, msg_flags);
121 req->rq_send_state = level;
123 ptlrpc_request_set_replen(req);
125 rc = ptlrpc_queue_wait(req);
129 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
131 GOTO(out, rc = -EPROTO);
133 if (body->valid & OBD_MD_FLMDSCAPA) {
134 rc = mdc_unpack_capa(NULL, req, &RMF_CAPA1, pc);
139 *rootfid = body->fid1;
141 "root fid="DFID", last_committed="LPU64"\n",
143 lustre_msg_get_last_committed(req->rq_repmsg));
146 ptlrpc_req_finished(req);
150 /* This should be mdc_get_info("rootfid") */
151 int mdc_getstatus(struct obd_export *exp, struct lu_fid *rootfid,
152 struct obd_capa **pc)
154 return send_getstatus(class_exp2cliimp(exp), rootfid, pc,
159 * This function now is known to always saying that it will receive 4 buffers
160 * from server. Even for cases when acl_size and md_size is zero, RPC header
161 * will contain 4 fields and RPC itself will contain zero size fields. This is
162 * because mdt_getattr*() _always_ returns 4 fields, but if acl is not needed
163 * and thus zero, it shrinks it, making zero size. The same story about
164 * md_size. And this is course of problem when client waits for smaller number
165 * of fields. This issue will be fixed later when client gets aware of RPC
168 static int mdc_getattr_common(struct obd_export *exp,
169 struct ptlrpc_request *req)
171 struct req_capsule *pill = &req->rq_pill;
172 struct mdt_body *body;
177 /* Request message already built. */
178 rc = ptlrpc_queue_wait(req);
182 /* sanity check for the reply */
183 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
187 CDEBUG(D_NET, "mode: %o\n", body->mode);
189 if (body->eadatasize != 0) {
190 mdc_update_max_ea_from_body(exp, body);
192 eadata = req_capsule_server_sized_get(pill, &RMF_MDT_MD,
198 if (body->valid & OBD_MD_FLRMTPERM) {
199 struct mdt_remote_perm *perm;
201 LASSERT(client_is_remote(exp));
202 perm = req_capsule_server_swab_get(pill, &RMF_ACL,
203 lustre_swab_mdt_remote_perm);
208 if (body->valid & OBD_MD_FLMDSCAPA) {
209 struct lustre_capa *capa;
210 capa = req_capsule_server_get(pill, &RMF_CAPA1);
218 int mdc_getattr(struct obd_export *exp, struct md_op_data *op_data,
219 struct ptlrpc_request **request)
221 struct ptlrpc_request *req;
225 /* Single MDS without an LMV case */
226 if (op_data->op_flags & MF_GET_MDT_IDX) {
231 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR);
235 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
237 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR);
239 ptlrpc_request_free(req);
243 mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
244 op_data->op_valid, op_data->op_mode, -1, 0);
246 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER,
248 if (op_data->op_valid & OBD_MD_FLRMTPERM) {
249 LASSERT(client_is_remote(exp));
250 req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER,
251 sizeof(struct mdt_remote_perm));
253 ptlrpc_request_set_replen(req);
255 rc = mdc_getattr_common(exp, req);
257 ptlrpc_req_finished(req);
263 int mdc_getattr_name(struct obd_export *exp, struct md_op_data *op_data,
264 struct ptlrpc_request **request)
266 struct ptlrpc_request *req;
271 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
272 &RQF_MDS_GETATTR_NAME);
276 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
277 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
278 op_data->op_namelen + 1);
280 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR_NAME);
282 ptlrpc_request_free(req);
286 mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
287 op_data->op_valid, op_data->op_mode,
288 op_data->op_suppgids[0], 0);
290 if (op_data->op_name) {
291 char *name = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
292 LASSERT(strnlen(op_data->op_name, op_data->op_namelen) ==
293 op_data->op_namelen);
294 memcpy(name, op_data->op_name, op_data->op_namelen);
297 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER,
299 ptlrpc_request_set_replen(req);
301 rc = mdc_getattr_common(exp, req);
303 ptlrpc_req_finished(req);
309 static int mdc_is_subdir(struct obd_export *exp,
310 const struct lu_fid *pfid,
311 const struct lu_fid *cfid,
312 struct ptlrpc_request **request)
314 struct ptlrpc_request *req;
320 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
321 &RQF_MDS_IS_SUBDIR, LUSTRE_MDS_VERSION,
326 mdc_is_subdir_pack(req, pfid, cfid, 0);
327 ptlrpc_request_set_replen(req);
329 rc = ptlrpc_queue_wait(req);
330 if (rc && rc != -EREMOTE)
331 ptlrpc_req_finished(req);
337 static int mdc_xattr_common(struct obd_export *exp,const struct req_format *fmt,
338 const struct lu_fid *fid,
339 struct obd_capa *oc, int opcode, obd_valid valid,
340 const char *xattr_name, const char *input,
341 int input_size, int output_size, int flags,
342 __u32 suppgid, struct ptlrpc_request **request)
344 struct ptlrpc_request *req;
345 int xattr_namelen = 0;
351 req = ptlrpc_request_alloc(class_exp2cliimp(exp), fmt);
355 mdc_set_capa_size(req, &RMF_CAPA1, oc);
357 xattr_namelen = strlen(xattr_name) + 1;
358 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
363 req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_CLIENT,
367 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, opcode);
369 ptlrpc_request_free(req);
373 if (opcode == MDS_REINT) {
374 struct mdt_rec_setxattr *rec;
376 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
377 sizeof(struct mdt_rec_reint));
378 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
379 rec->sx_opcode = REINT_SETXATTR;
381 * cfs_curproc_fs{u,g}id() should replace
382 * current->fs{u,g}id for portability.
384 rec->sx_fsuid = current_fsuid();
385 rec->sx_fsgid = current_fsgid();
386 rec->sx_cap = cfs_curproc_cap_pack();
387 rec->sx_suppgid1 = suppgid;
388 rec->sx_suppgid2 = -1;
390 rec->sx_valid = valid | OBD_MD_FLCTIME;
391 rec->sx_time = cfs_time_current_sec();
392 rec->sx_size = output_size;
393 rec->sx_flags = flags;
395 mdc_pack_capa(req, &RMF_CAPA1, oc);
397 mdc_pack_body(req, fid, oc, valid, output_size, suppgid, flags);
401 tmp = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
402 memcpy(tmp, xattr_name, xattr_namelen);
405 tmp = req_capsule_client_get(&req->rq_pill, &RMF_EADATA);
406 memcpy(tmp, input, input_size);
409 if (req_capsule_has_field(&req->rq_pill, &RMF_EADATA, RCL_SERVER))
410 req_capsule_set_size(&req->rq_pill, &RMF_EADATA,
411 RCL_SERVER, output_size);
412 ptlrpc_request_set_replen(req);
415 if (opcode == MDS_REINT)
416 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
418 rc = ptlrpc_queue_wait(req);
420 if (opcode == MDS_REINT)
421 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
424 ptlrpc_req_finished(req);
430 int mdc_setxattr(struct obd_export *exp, const struct lu_fid *fid,
431 struct obd_capa *oc, obd_valid valid, const char *xattr_name,
432 const char *input, int input_size, int output_size,
433 int flags, __u32 suppgid, struct ptlrpc_request **request)
435 return mdc_xattr_common(exp, &RQF_MDS_REINT_SETXATTR,
436 fid, oc, MDS_REINT, valid, xattr_name,
437 input, input_size, output_size, flags,
441 int mdc_getxattr(struct obd_export *exp, const struct lu_fid *fid,
442 struct obd_capa *oc, obd_valid valid, const char *xattr_name,
443 const char *input, int input_size, int output_size,
444 int flags, struct ptlrpc_request **request)
446 return mdc_xattr_common(exp, &RQF_MDS_GETXATTR,
447 fid, oc, MDS_GETXATTR, valid, xattr_name,
448 input, input_size, output_size, flags,
452 #ifdef CONFIG_FS_POSIX_ACL
453 static int mdc_unpack_acl(struct ptlrpc_request *req, struct lustre_md *md)
455 struct req_capsule *pill = &req->rq_pill;
456 struct mdt_body *body = md->body;
457 struct posix_acl *acl;
465 buf = req_capsule_server_sized_get(pill, &RMF_ACL, body->aclsize);
470 acl = posix_acl_from_xattr(&init_user_ns, buf, body->aclsize);
473 CERROR("convert xattr to acl: %d\n", rc);
477 rc = posix_acl_valid(acl);
479 CERROR("validate acl: %d\n", rc);
480 posix_acl_release(acl);
488 #define mdc_unpack_acl(req, md) 0
491 int mdc_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
492 struct obd_export *dt_exp, struct obd_export *md_exp,
493 struct lustre_md *md)
495 struct req_capsule *pill = &req->rq_pill;
500 memset(md, 0, sizeof(*md));
502 md->body = req_capsule_server_get(pill, &RMF_MDT_BODY);
503 LASSERT(md->body != NULL);
505 if (md->body->valid & OBD_MD_FLEASIZE) {
507 struct lov_mds_md *lmm;
509 if (!S_ISREG(md->body->mode)) {
510 CDEBUG(D_INFO, "OBD_MD_FLEASIZE set, should be a "
511 "regular file, but is not\n");
512 GOTO(out, rc = -EPROTO);
515 if (md->body->eadatasize == 0) {
516 CDEBUG(D_INFO, "OBD_MD_FLEASIZE set, "
517 "but eadatasize 0\n");
518 GOTO(out, rc = -EPROTO);
520 lmmsize = md->body->eadatasize;
521 lmm = req_capsule_server_sized_get(pill, &RMF_MDT_MD, lmmsize);
523 GOTO(out, rc = -EPROTO);
525 rc = obd_unpackmd(dt_exp, &md->lsm, lmm, lmmsize);
529 if (rc < sizeof(*md->lsm)) {
530 CDEBUG(D_INFO, "lsm size too small: "
531 "rc < sizeof (*md->lsm) (%d < %d)\n",
532 rc, (int)sizeof(*md->lsm));
533 GOTO(out, rc = -EPROTO);
536 } else if (md->body->valid & OBD_MD_FLDIREA) {
538 struct lov_mds_md *lmv;
540 if(!S_ISDIR(md->body->mode)) {
541 CDEBUG(D_INFO, "OBD_MD_FLDIREA set, should be a "
542 "directory, but is not\n");
543 GOTO(out, rc = -EPROTO);
546 if (md->body->eadatasize == 0) {
547 CDEBUG(D_INFO, "OBD_MD_FLDIREA is set, "
548 "but eadatasize 0\n");
551 if (md->body->valid & OBD_MD_MEA) {
552 lmvsize = md->body->eadatasize;
553 lmv = req_capsule_server_sized_get(pill, &RMF_MDT_MD,
556 GOTO(out, rc = -EPROTO);
558 rc = obd_unpackmd(md_exp, (void *)&md->mea, lmv,
563 if (rc < sizeof(*md->mea)) {
564 CDEBUG(D_INFO, "size too small: "
565 "rc < sizeof(*md->mea) (%d < %d)\n",
566 rc, (int)sizeof(*md->mea));
567 GOTO(out, rc = -EPROTO);
573 if (md->body->valid & OBD_MD_FLRMTPERM) {
574 /* remote permission */
575 LASSERT(client_is_remote(exp));
576 md->remote_perm = req_capsule_server_swab_get(pill, &RMF_ACL,
577 lustre_swab_mdt_remote_perm);
578 if (!md->remote_perm)
579 GOTO(out, rc = -EPROTO);
581 else if (md->body->valid & OBD_MD_FLACL) {
582 /* for ACL, it's possible that FLACL is set but aclsize is zero.
583 * only when aclsize != 0 there's an actual segment for ACL
586 if (md->body->aclsize) {
587 rc = mdc_unpack_acl(req, md);
590 #ifdef CONFIG_FS_POSIX_ACL
592 md->posix_acl = NULL;
596 if (md->body->valid & OBD_MD_FLMDSCAPA) {
597 struct obd_capa *oc = NULL;
599 rc = mdc_unpack_capa(NULL, req, &RMF_CAPA1, &oc);
605 if (md->body->valid & OBD_MD_FLOSSCAPA) {
606 struct obd_capa *oc = NULL;
608 rc = mdc_unpack_capa(NULL, req, &RMF_CAPA2, &oc);
618 capa_put(md->oss_capa);
622 capa_put(md->mds_capa);
625 #ifdef CONFIG_FS_POSIX_ACL
626 posix_acl_release(md->posix_acl);
629 obd_free_memmd(dt_exp, &md->lsm);
634 int mdc_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
641 * Handles both OPEN and SETATTR RPCs for OPEN-CLOSE and SETATTR-DONE_WRITING
644 void mdc_replay_open(struct ptlrpc_request *req)
646 struct md_open_data *mod = req->rq_cb_data;
647 struct ptlrpc_request *close_req;
648 struct obd_client_handle *och;
649 struct lustre_handle old;
650 struct mdt_body *body;
654 DEBUG_REQ(D_ERROR, req,
655 "Can't properly replay without open data.");
660 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
661 LASSERT(body != NULL);
665 struct lustre_handle *file_fh;
667 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
669 file_fh = &och->och_fh;
670 CDEBUG(D_HA, "updating handle from "LPX64" to "LPX64"\n",
671 file_fh->cookie, body->handle.cookie);
673 *file_fh = body->handle;
675 close_req = mod->mod_close_req;
676 if (close_req != NULL) {
677 __u32 opc = lustre_msg_get_opc(close_req->rq_reqmsg);
678 struct mdt_ioepoch *epoch;
680 LASSERT(opc == MDS_CLOSE || opc == MDS_DONE_WRITING);
681 epoch = req_capsule_client_get(&close_req->rq_pill,
686 LASSERT(!memcmp(&old, &epoch->handle, sizeof(old)));
687 DEBUG_REQ(D_HA, close_req, "updating close body with new fh");
688 epoch->handle = body->handle;
693 void mdc_commit_open(struct ptlrpc_request *req)
695 struct md_open_data *mod = req->rq_cb_data;
700 * No need to touch md_open_data::mod_och, it holds a reference on
701 * \var mod and will zero references to each other, \var mod will be
702 * freed after that when md_open_data::mod_och will put the reference.
706 * Do not let open request to disappear as it still may be needed
707 * for close rpc to happen (it may happen on evict only, otherwise
708 * ptlrpc_request::rq_replay does not let mdc_commit_open() to be
709 * called), just mark this rpc as committed to distinguish these 2
710 * cases, see mdc_close() for details. The open request reference will
711 * be put along with freeing \var mod.
713 ptlrpc_request_addref(req);
714 spin_lock(&req->rq_lock);
715 req->rq_committed = 1;
716 spin_unlock(&req->rq_lock);
717 req->rq_cb_data = NULL;
721 int mdc_set_open_replay_data(struct obd_export *exp,
722 struct obd_client_handle *och,
723 struct ptlrpc_request *open_req)
725 struct md_open_data *mod;
726 struct mdt_rec_create *rec;
727 struct mdt_body *body;
728 struct obd_import *imp = open_req->rq_import;
731 if (!open_req->rq_replay)
734 rec = req_capsule_client_get(&open_req->rq_pill, &RMF_REC_REINT);
735 body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY);
736 LASSERT(rec != NULL);
737 /* Incoming message in my byte order (it's been swabbed). */
738 /* Outgoing messages always in my byte order. */
739 LASSERT(body != NULL);
741 /* Only if the import is replayable, we set replay_open data */
742 if (och && imp->imp_replayable) {
743 mod = obd_mod_alloc();
745 DEBUG_REQ(D_ERROR, open_req,
746 "Can't allocate md_open_data");
751 * Take a reference on \var mod, to be freed on mdc_close().
752 * It protects \var mod from being freed on eviction (commit
753 * callback is called despite rq_replay flag).
754 * Another reference for \var och.
759 spin_lock(&open_req->rq_lock);
762 mod->mod_open_req = open_req;
763 open_req->rq_cb_data = mod;
764 open_req->rq_commit_cb = mdc_commit_open;
765 spin_unlock(&open_req->rq_lock);
768 rec->cr_fid2 = body->fid1;
769 rec->cr_ioepoch = body->ioepoch;
770 rec->cr_old_handle.cookie = body->handle.cookie;
771 open_req->rq_replay_cb = mdc_replay_open;
772 if (!fid_is_sane(&body->fid1)) {
773 DEBUG_REQ(D_ERROR, open_req, "Saving replay request with "
778 DEBUG_REQ(D_RPCTRACE, open_req, "Set up open replay data");
782 int mdc_clear_open_replay_data(struct obd_export *exp,
783 struct obd_client_handle *och)
785 struct md_open_data *mod = och->och_mod;
789 * It is possible to not have \var mod in a case of eviction between
790 * lookup and ll_file_open().
795 LASSERT(mod != LP_POISON);
804 /* Prepares the request for the replay by the given reply */
805 static void mdc_close_handle_reply(struct ptlrpc_request *req,
806 struct md_op_data *op_data, int rc) {
807 struct mdt_body *repbody;
808 struct mdt_ioepoch *epoch;
810 if (req && rc == -EAGAIN) {
811 repbody = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
812 epoch = req_capsule_client_get(&req->rq_pill, &RMF_MDT_EPOCH);
814 epoch->flags |= MF_SOM_AU;
815 if (repbody->valid & OBD_MD_FLGETATTRLOCK)
816 op_data->op_flags |= MF_GETATTR_LOCK;
820 int mdc_close(struct obd_export *exp, struct md_op_data *op_data,
821 struct md_open_data *mod, struct ptlrpc_request **request)
823 struct obd_device *obd = class_exp2obd(exp);
824 struct ptlrpc_request *req;
829 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_CLOSE);
833 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
835 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_CLOSE);
837 ptlrpc_request_free(req);
841 /* To avoid a livelock (bug 7034), we need to send CLOSE RPCs to a
842 * portal whose threads are not taking any DLM locks and are therefore
843 * always progressing */
844 req->rq_request_portal = MDS_READPAGE_PORTAL;
845 ptlrpc_at_set_req_timeout(req);
847 /* Ensure that this close's handle is fixed up during replay. */
848 if (likely(mod != NULL)) {
849 LASSERTF(mod->mod_open_req != NULL &&
850 mod->mod_open_req->rq_type != LI_POISON,
851 "POISONED open %p!\n", mod->mod_open_req);
853 mod->mod_close_req = req;
855 DEBUG_REQ(D_HA, mod->mod_open_req, "matched open");
856 /* We no longer want to preserve this open for replay even
857 * though the open was committed. b=3632, b=3633 */
858 spin_lock(&mod->mod_open_req->rq_lock);
859 mod->mod_open_req->rq_replay = 0;
860 spin_unlock(&mod->mod_open_req->rq_lock);
862 CDEBUG(D_HA, "couldn't find open req; expecting close error\n");
865 mdc_close_pack(req, op_data);
867 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER,
868 obd->u.cli.cl_max_mds_easize);
869 req_capsule_set_size(&req->rq_pill, &RMF_LOGCOOKIES, RCL_SERVER,
870 obd->u.cli.cl_max_mds_cookiesize);
872 ptlrpc_request_set_replen(req);
874 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
875 rc = ptlrpc_queue_wait(req);
876 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
878 if (req->rq_repmsg == NULL) {
879 CDEBUG(D_RPCTRACE, "request failed to send: %p, %d\n", req,
882 rc = req->rq_status ?: -EIO;
883 } else if (rc == 0 || rc == -EAGAIN) {
884 struct mdt_body *body;
886 rc = lustre_msg_get_status(req->rq_repmsg);
887 if (lustre_msg_get_type(req->rq_repmsg) == PTL_RPC_MSG_ERR) {
888 DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, err "
893 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
896 } else if (rc == -ESTALE) {
898 * it can be allowed error after 3633 if open was committed and
899 * server failed before close was sent. Let's check if mod
900 * exists and return no error in that case
903 DEBUG_REQ(D_HA, req, "Reset ESTALE = %d", rc);
904 LASSERT(mod->mod_open_req != NULL);
905 if (mod->mod_open_req->rq_committed)
912 mod->mod_close_req = NULL;
913 /* Since now, mod is accessed through open_req only,
914 * thus close req does not keep a reference on mod anymore. */
918 mdc_close_handle_reply(req, op_data, rc);
922 int mdc_done_writing(struct obd_export *exp, struct md_op_data *op_data,
923 struct md_open_data *mod)
925 struct obd_device *obd = class_exp2obd(exp);
926 struct ptlrpc_request *req;
930 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
931 &RQF_MDS_DONE_WRITING);
935 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
936 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_DONE_WRITING);
938 ptlrpc_request_free(req);
943 LASSERTF(mod->mod_open_req != NULL &&
944 mod->mod_open_req->rq_type != LI_POISON,
945 "POISONED setattr %p!\n", mod->mod_open_req);
947 mod->mod_close_req = req;
948 DEBUG_REQ(D_HA, mod->mod_open_req, "matched setattr");
949 /* We no longer want to preserve this setattr for replay even
950 * though the open was committed. b=3632, b=3633 */
951 spin_lock(&mod->mod_open_req->rq_lock);
952 mod->mod_open_req->rq_replay = 0;
953 spin_unlock(&mod->mod_open_req->rq_lock);
956 mdc_close_pack(req, op_data);
957 ptlrpc_request_set_replen(req);
959 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
960 rc = ptlrpc_queue_wait(req);
961 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
965 * it can be allowed error after 3633 if open or setattr were
966 * committed and server failed before close was sent.
967 * Let's check if mod exists and return no error in that case
970 LASSERT(mod->mod_open_req != NULL);
971 if (mod->mod_open_req->rq_committed)
978 mod->mod_close_req = NULL;
979 /* Since now, mod is accessed through setattr req only,
980 * thus DW req does not keep a reference on mod anymore. */
984 mdc_close_handle_reply(req, op_data, rc);
985 ptlrpc_req_finished(req);
990 int mdc_readpage(struct obd_export *exp, struct md_op_data *op_data,
991 struct page **pages, struct ptlrpc_request **request)
993 struct ptlrpc_request *req;
994 struct ptlrpc_bulk_desc *desc;
996 wait_queue_head_t waitq;
998 struct l_wait_info lwi;
1003 init_waitqueue_head(&waitq);
1006 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_READPAGE);
1010 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
1012 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_READPAGE);
1014 ptlrpc_request_free(req);
1018 req->rq_request_portal = MDS_READPAGE_PORTAL;
1019 ptlrpc_at_set_req_timeout(req);
1021 desc = ptlrpc_prep_bulk_imp(req, op_data->op_npages, 1, BULK_PUT_SINK,
1024 ptlrpc_request_free(req);
1028 /* NB req now owns desc and will free it when it gets freed */
1029 for (i = 0; i < op_data->op_npages; i++)
1030 ptlrpc_prep_bulk_page_pin(desc, pages[i], 0, PAGE_CACHE_SIZE);
1032 mdc_readdir_pack(req, op_data->op_offset,
1033 PAGE_CACHE_SIZE * op_data->op_npages,
1034 &op_data->op_fid1, op_data->op_capa1);
1036 ptlrpc_request_set_replen(req);
1037 rc = ptlrpc_queue_wait(req);
1039 ptlrpc_req_finished(req);
1040 if (rc != -ETIMEDOUT)
1044 if (!client_should_resend(resends, &exp->exp_obd->u.cli)) {
1045 CERROR("too many resend retries, returning error\n");
1048 lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(resends), NULL, NULL, NULL);
1049 l_wait_event(waitq, 0, &lwi);
1054 rc = sptlrpc_cli_unwrap_bulk_read(req, req->rq_bulk,
1055 req->rq_bulk->bd_nob_transferred);
1057 ptlrpc_req_finished(req);
1061 if (req->rq_bulk->bd_nob_transferred & ~LU_PAGE_MASK) {
1062 CERROR("Unexpected # bytes transferred: %d (%ld expected)\n",
1063 req->rq_bulk->bd_nob_transferred,
1064 PAGE_CACHE_SIZE * op_data->op_npages);
1065 ptlrpc_req_finished(req);
1073 static int mdc_statfs(const struct lu_env *env,
1074 struct obd_export *exp, struct obd_statfs *osfs,
1075 __u64 max_age, __u32 flags)
1077 struct obd_device *obd = class_exp2obd(exp);
1078 struct ptlrpc_request *req;
1079 struct obd_statfs *msfs;
1080 struct obd_import *imp = NULL;
1085 * Since the request might also come from lprocfs, so we need
1086 * sync this with client_disconnect_export Bug15684
1088 down_read(&obd->u.cli.cl_sem);
1089 if (obd->u.cli.cl_import)
1090 imp = class_import_get(obd->u.cli.cl_import);
1091 up_read(&obd->u.cli.cl_sem);
1095 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_STATFS,
1096 LUSTRE_MDS_VERSION, MDS_STATFS);
1098 GOTO(output, rc = -ENOMEM);
1100 ptlrpc_request_set_replen(req);
1102 if (flags & OBD_STATFS_NODELAY) {
1103 /* procfs requests not want stay in wait for avoid deadlock */
1104 req->rq_no_resend = 1;
1105 req->rq_no_delay = 1;
1108 rc = ptlrpc_queue_wait(req);
1110 /* check connection error first */
1111 if (imp->imp_connect_error)
1112 rc = imp->imp_connect_error;
1116 msfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
1118 GOTO(out, rc = -EPROTO);
1123 ptlrpc_req_finished(req);
1125 class_import_put(imp);
1129 static int mdc_ioc_fid2path(struct obd_export *exp, struct getinfo_fid2path *gf)
1131 __u32 keylen, vallen;
1135 if (gf->gf_pathlen > PATH_MAX)
1136 RETURN(-ENAMETOOLONG);
1137 if (gf->gf_pathlen < 2)
1140 /* Key is KEY_FID2PATH + getinfo_fid2path description */
1141 keylen = cfs_size_round(sizeof(KEY_FID2PATH)) + sizeof(*gf);
1142 OBD_ALLOC(key, keylen);
1145 memcpy(key, KEY_FID2PATH, sizeof(KEY_FID2PATH));
1146 memcpy(key + cfs_size_round(sizeof(KEY_FID2PATH)), gf, sizeof(*gf));
1148 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
1149 PFID(&gf->gf_fid), gf->gf_recno, gf->gf_linkno);
1151 if (!fid_is_sane(&gf->gf_fid))
1152 GOTO(out, rc = -EINVAL);
1154 /* Val is struct getinfo_fid2path result plus path */
1155 vallen = sizeof(*gf) + gf->gf_pathlen;
1157 rc = obd_get_info(NULL, exp, keylen, key, &vallen, gf, NULL);
1158 if (rc != 0 && rc != -EREMOTE)
1161 if (vallen <= sizeof(*gf))
1162 GOTO(out, rc = -EPROTO);
1163 else if (vallen > sizeof(*gf) + gf->gf_pathlen)
1164 GOTO(out, rc = -EOVERFLOW);
1166 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n%s\n",
1167 PFID(&gf->gf_fid), gf->gf_recno, gf->gf_linkno, gf->gf_path);
1170 OBD_FREE(key, keylen);
1174 static int mdc_ioc_hsm_progress(struct obd_export *exp,
1175 struct hsm_progress_kernel *hpk)
1177 struct obd_import *imp = class_exp2cliimp(exp);
1178 struct hsm_progress_kernel *req_hpk;
1179 struct ptlrpc_request *req;
1183 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_HSM_PROGRESS,
1184 LUSTRE_MDS_VERSION, MDS_HSM_PROGRESS);
1186 GOTO(out, rc = -ENOMEM);
1188 mdc_pack_body(req, NULL, NULL, OBD_MD_FLRMTPERM, 0, 0, 0);
1190 /* Copy hsm_progress struct */
1191 req_hpk = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_PROGRESS);
1192 if (req_hpk == NULL)
1193 GOTO(out, rc = -EPROTO);
1197 ptlrpc_request_set_replen(req);
1199 rc = mdc_queue_wait(req);
1202 ptlrpc_req_finished(req);
1206 static int mdc_ioc_hsm_ct_register(struct obd_import *imp, __u32 archives)
1208 __u32 *archive_mask;
1209 struct ptlrpc_request *req;
1213 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_HSM_CT_REGISTER,
1215 MDS_HSM_CT_REGISTER);
1217 GOTO(out, rc = -ENOMEM);
1219 mdc_pack_body(req, NULL, NULL, OBD_MD_FLRMTPERM, 0, 0, 0);
1221 /* Copy hsm_progress struct */
1222 archive_mask = req_capsule_client_get(&req->rq_pill,
1223 &RMF_MDS_HSM_ARCHIVE);
1224 if (archive_mask == NULL)
1225 GOTO(out, rc = -EPROTO);
1227 *archive_mask = archives;
1229 ptlrpc_request_set_replen(req);
1231 rc = mdc_queue_wait(req);
1234 ptlrpc_req_finished(req);
1238 static int mdc_ioc_hsm_current_action(struct obd_export *exp,
1239 struct md_op_data *op_data)
1241 struct hsm_current_action *hca = op_data->op_data;
1242 struct hsm_current_action *req_hca;
1243 struct ptlrpc_request *req;
1247 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
1248 &RQF_MDS_HSM_ACTION);
1252 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
1254 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_ACTION);
1256 ptlrpc_request_free(req);
1260 mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
1261 OBD_MD_FLRMTPERM, 0, op_data->op_suppgids[0], 0);
1263 ptlrpc_request_set_replen(req);
1265 rc = mdc_queue_wait(req);
1269 req_hca = req_capsule_server_get(&req->rq_pill,
1270 &RMF_MDS_HSM_CURRENT_ACTION);
1271 if (req_hca == NULL)
1272 GOTO(out, rc = -EPROTO);
1278 ptlrpc_req_finished(req);
1282 static int mdc_ioc_hsm_ct_unregister(struct obd_import *imp)
1284 struct ptlrpc_request *req;
1288 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_HSM_CT_UNREGISTER,
1290 MDS_HSM_CT_UNREGISTER);
1292 GOTO(out, rc = -ENOMEM);
1294 mdc_pack_body(req, NULL, NULL, OBD_MD_FLRMTPERM, 0, 0, 0);
1296 ptlrpc_request_set_replen(req);
1298 rc = mdc_queue_wait(req);
1301 ptlrpc_req_finished(req);
1305 static int mdc_ioc_hsm_state_get(struct obd_export *exp,
1306 struct md_op_data *op_data)
1308 struct hsm_user_state *hus = op_data->op_data;
1309 struct hsm_user_state *req_hus;
1310 struct ptlrpc_request *req;
1314 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
1315 &RQF_MDS_HSM_STATE_GET);
1319 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
1321 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_STATE_GET);
1323 ptlrpc_request_free(req);
1327 mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
1328 OBD_MD_FLRMTPERM, 0, op_data->op_suppgids[0], 0);
1330 ptlrpc_request_set_replen(req);
1332 rc = mdc_queue_wait(req);
1336 req_hus = req_capsule_server_get(&req->rq_pill, &RMF_HSM_USER_STATE);
1337 if (req_hus == NULL)
1338 GOTO(out, rc = -EPROTO);
1344 ptlrpc_req_finished(req);
1348 static int mdc_ioc_hsm_state_set(struct obd_export *exp,
1349 struct md_op_data *op_data)
1351 struct hsm_state_set *hss = op_data->op_data;
1352 struct hsm_state_set *req_hss;
1353 struct ptlrpc_request *req;
1357 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
1358 &RQF_MDS_HSM_STATE_SET);
1362 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
1364 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_STATE_SET);
1366 ptlrpc_request_free(req);
1370 mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
1371 OBD_MD_FLRMTPERM, 0, op_data->op_suppgids[0], 0);
1374 req_hss = req_capsule_client_get(&req->rq_pill, &RMF_HSM_STATE_SET);
1375 if (req_hss == NULL)
1376 GOTO(out, rc = -EPROTO);
1379 ptlrpc_request_set_replen(req);
1381 rc = mdc_queue_wait(req);
1386 ptlrpc_req_finished(req);
1390 static int mdc_ioc_hsm_request(struct obd_export *exp,
1391 struct hsm_user_request *hur)
1393 struct obd_import *imp = class_exp2cliimp(exp);
1394 struct ptlrpc_request *req;
1395 struct hsm_request *req_hr;
1396 struct hsm_user_item *req_hui;
1401 req = ptlrpc_request_alloc(imp, &RQF_MDS_HSM_REQUEST);
1403 GOTO(out, rc = -ENOMEM);
1405 req_capsule_set_size(&req->rq_pill, &RMF_MDS_HSM_USER_ITEM, RCL_CLIENT,
1406 hur->hur_request.hr_itemcount
1407 * sizeof(struct hsm_user_item));
1408 req_capsule_set_size(&req->rq_pill, &RMF_GENERIC_DATA, RCL_CLIENT,
1409 hur->hur_request.hr_data_len);
1411 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_REQUEST);
1413 ptlrpc_request_free(req);
1417 mdc_pack_body(req, NULL, NULL, OBD_MD_FLRMTPERM, 0, 0, 0);
1419 /* Copy hsm_request struct */
1420 req_hr = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_REQUEST);
1422 GOTO(out, rc = -EPROTO);
1423 *req_hr = hur->hur_request;
1425 /* Copy hsm_user_item structs */
1426 req_hui = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_USER_ITEM);
1427 if (req_hui == NULL)
1428 GOTO(out, rc = -EPROTO);
1429 memcpy(req_hui, hur->hur_user_item,
1430 hur->hur_request.hr_itemcount * sizeof(struct hsm_user_item));
1432 /* Copy opaque field */
1433 req_opaque = req_capsule_client_get(&req->rq_pill, &RMF_GENERIC_DATA);
1434 if (req_opaque == NULL)
1435 GOTO(out, rc = -EPROTO);
1436 memcpy(req_opaque, hur_data(hur), hur->hur_request.hr_data_len);
1438 ptlrpc_request_set_replen(req);
1440 rc = mdc_queue_wait(req);
1444 ptlrpc_req_finished(req);
1448 static struct kuc_hdr *changelog_kuc_hdr(char *buf, int len, int flags)
1450 struct kuc_hdr *lh = (struct kuc_hdr *)buf;
1452 LASSERT(len <= CR_MAXSIZE);
1454 lh->kuc_magic = KUC_MAGIC;
1455 lh->kuc_transport = KUC_TRANSPORT_CHANGELOG;
1456 lh->kuc_flags = flags;
1457 lh->kuc_msgtype = CL_RECORD;
1458 lh->kuc_msglen = len;
1462 #define D_CHANGELOG 0
1464 struct changelog_show {
1469 struct obd_device *cs_obd;
1472 static int changelog_show_cb(const struct lu_env *env, struct llog_handle *llh,
1473 struct llog_rec_hdr *hdr, void *data)
1475 struct changelog_show *cs = data;
1476 struct llog_changelog_rec *rec = (struct llog_changelog_rec *)hdr;
1481 if ((rec->cr_hdr.lrh_type != CHANGELOG_REC) ||
1482 (rec->cr.cr_type >= CL_LAST)) {
1483 CERROR("Not a changelog rec %d/%d\n", rec->cr_hdr.lrh_type,
1488 if (rec->cr.cr_index < cs->cs_startrec) {
1489 /* Skip entries earlier than what we are interested in */
1490 CDEBUG(D_CHANGELOG, "rec="LPU64" start="LPU64"\n",
1491 rec->cr.cr_index, cs->cs_startrec);
1495 CDEBUG(D_CHANGELOG, LPU64" %02d%-5s "LPU64" 0x%x t="DFID" p="DFID
1496 " %.*s\n", rec->cr.cr_index, rec->cr.cr_type,
1497 changelog_type2str(rec->cr.cr_type), rec->cr.cr_time,
1498 rec->cr.cr_flags & CLF_FLAGMASK,
1499 PFID(&rec->cr.cr_tfid), PFID(&rec->cr.cr_pfid),
1500 rec->cr.cr_namelen, changelog_rec_name(&rec->cr));
1502 len = sizeof(*lh) + changelog_rec_size(&rec->cr) + rec->cr.cr_namelen;
1504 /* Set up the message */
1505 lh = changelog_kuc_hdr(cs->cs_buf, len, cs->cs_flags);
1506 memcpy(lh + 1, &rec->cr, len - sizeof(*lh));
1508 rc = libcfs_kkuc_msg_put(cs->cs_fp, lh);
1509 CDEBUG(D_CHANGELOG, "kucmsg fp %p len %d rc %d\n", cs->cs_fp, len,rc);
1514 static int mdc_changelog_send_thread(void *csdata)
1516 struct changelog_show *cs = csdata;
1517 struct llog_ctxt *ctxt = NULL;
1518 struct llog_handle *llh = NULL;
1519 struct kuc_hdr *kuch;
1522 CDEBUG(D_CHANGELOG, "changelog to fp=%p start "LPU64"\n",
1523 cs->cs_fp, cs->cs_startrec);
1525 OBD_ALLOC(cs->cs_buf, CR_MAXSIZE);
1526 if (cs->cs_buf == NULL)
1527 GOTO(out, rc = -ENOMEM);
1529 /* Set up the remote catalog handle */
1530 ctxt = llog_get_context(cs->cs_obd, LLOG_CHANGELOG_REPL_CTXT);
1532 GOTO(out, rc = -ENOENT);
1533 rc = llog_open(NULL, ctxt, &llh, NULL, CHANGELOG_CATALOG,
1536 CERROR("%s: fail to open changelog catalog: rc = %d\n",
1537 cs->cs_obd->obd_name, rc);
1540 rc = llog_init_handle(NULL, llh, LLOG_F_IS_CAT, NULL);
1542 CERROR("llog_init_handle failed %d\n", rc);
1546 rc = llog_cat_process(NULL, llh, changelog_show_cb, cs, 0, 0);
1548 /* Send EOF no matter what our result */
1549 if ((kuch = changelog_kuc_hdr(cs->cs_buf, sizeof(*kuch),
1551 kuch->kuc_msgtype = CL_EOF;
1552 libcfs_kkuc_msg_put(cs->cs_fp, kuch);
1558 llog_cat_close(NULL, llh);
1560 llog_ctxt_put(ctxt);
1562 OBD_FREE(cs->cs_buf, CR_MAXSIZE);
1567 static int mdc_ioc_changelog_send(struct obd_device *obd,
1568 struct ioc_changelog *icc)
1570 struct changelog_show *cs;
1573 /* Freed in mdc_changelog_send_thread */
1579 cs->cs_startrec = icc->icc_recno;
1580 /* matching fput in mdc_changelog_send_thread */
1581 cs->cs_fp = fget(icc->icc_id);
1582 cs->cs_flags = icc->icc_flags;
1585 * New thread because we should return to user app before
1586 * writing into our pipe
1588 rc = PTR_ERR(kthread_run(mdc_changelog_send_thread, cs,
1589 "mdc_clg_send_thread"));
1590 if (!IS_ERR_VALUE(rc)) {
1591 CDEBUG(D_CHANGELOG, "start changelog thread\n");
1595 CERROR("Failed to start changelog thread: %d\n", rc);
1600 static int mdc_ioc_hsm_ct_start(struct obd_export *exp,
1601 struct lustre_kernelcomm *lk);
1603 static int mdc_quotacheck(struct obd_device *unused, struct obd_export *exp,
1604 struct obd_quotactl *oqctl)
1606 struct client_obd *cli = &exp->exp_obd->u.cli;
1607 struct ptlrpc_request *req;
1608 struct obd_quotactl *body;
1612 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
1613 &RQF_MDS_QUOTACHECK, LUSTRE_MDS_VERSION,
1618 body = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1621 ptlrpc_request_set_replen(req);
1623 /* the next poll will find -ENODATA, that means quotacheck is
1625 cli->cl_qchk_stat = -ENODATA;
1626 rc = ptlrpc_queue_wait(req);
1628 cli->cl_qchk_stat = rc;
1629 ptlrpc_req_finished(req);
1633 static int mdc_quota_poll_check(struct obd_export *exp,
1634 struct if_quotacheck *qchk)
1636 struct client_obd *cli = &exp->exp_obd->u.cli;
1640 qchk->obd_uuid = cli->cl_target_uuid;
1641 memcpy(qchk->obd_type, LUSTRE_MDS_NAME, strlen(LUSTRE_MDS_NAME));
1643 rc = cli->cl_qchk_stat;
1644 /* the client is not the previous one */
1645 if (rc == CL_NOT_QUOTACHECKED)
1650 static int mdc_quotactl(struct obd_device *unused, struct obd_export *exp,
1651 struct obd_quotactl *oqctl)
1653 struct ptlrpc_request *req;
1654 struct obd_quotactl *oqc;
1658 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
1659 &RQF_MDS_QUOTACTL, LUSTRE_MDS_VERSION,
1664 oqc = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1667 ptlrpc_request_set_replen(req);
1668 ptlrpc_at_set_req_timeout(req);
1669 req->rq_no_resend = 1;
1671 rc = ptlrpc_queue_wait(req);
1673 CERROR("ptlrpc_queue_wait failed, rc: %d\n", rc);
1675 if (req->rq_repmsg &&
1676 (oqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL))) {
1679 CERROR ("Can't unpack obd_quotactl\n");
1682 ptlrpc_req_finished(req);
1687 static int mdc_ioc_swap_layouts(struct obd_export *exp,
1688 struct md_op_data *op_data)
1691 struct ptlrpc_request *req;
1693 struct mdc_swap_layouts *msl, *payload;
1696 msl = op_data->op_data;
1698 /* When the MDT will get the MDS_SWAP_LAYOUTS RPC the
1699 * first thing it will do is to cancel the 2 layout
1700 * locks hold by this client.
1701 * So the client must cancel its layout locks on the 2 fids
1702 * with the request RPC to avoid extra RPC round trips
1704 count = mdc_resource_get_unused(exp, &op_data->op_fid1, &cancels,
1705 LCK_CR, MDS_INODELOCK_LAYOUT);
1706 count += mdc_resource_get_unused(exp, &op_data->op_fid2, &cancels,
1707 LCK_CR, MDS_INODELOCK_LAYOUT);
1709 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
1710 &RQF_MDS_SWAP_LAYOUTS);
1712 ldlm_lock_list_put(&cancels, l_bl_ast, count);
1716 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
1717 mdc_set_capa_size(req, &RMF_CAPA2, op_data->op_capa2);
1719 rc = mdc_prep_elc_req(exp, req, MDS_SWAP_LAYOUTS, &cancels, count);
1721 ptlrpc_request_free(req);
1725 mdc_swap_layouts_pack(req, op_data);
1727 payload = req_capsule_client_get(&req->rq_pill, &RMF_SWAP_LAYOUTS);
1732 ptlrpc_request_set_replen(req);
1734 rc = ptlrpc_queue_wait(req);
1740 ptlrpc_req_finished(req);
1744 static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1745 void *karg, void *uarg)
1747 struct obd_device *obd = exp->exp_obd;
1748 struct obd_ioctl_data *data = karg;
1749 struct obd_import *imp = obd->u.cli.cl_import;
1750 struct llog_ctxt *ctxt;
1754 if (!try_module_get(THIS_MODULE)) {
1755 CERROR("Can't get module. Is it alive?");
1759 case OBD_IOC_CHANGELOG_SEND:
1760 rc = mdc_ioc_changelog_send(obd, karg);
1762 case OBD_IOC_CHANGELOG_CLEAR: {
1763 struct ioc_changelog *icc = karg;
1764 struct changelog_setinfo cs =
1765 {.cs_recno = icc->icc_recno, .cs_id = icc->icc_id};
1766 rc = obd_set_info_async(NULL, exp, strlen(KEY_CHANGELOG_CLEAR),
1767 KEY_CHANGELOG_CLEAR, sizeof(cs), &cs,
1771 case OBD_IOC_FID2PATH:
1772 rc = mdc_ioc_fid2path(exp, karg);
1774 case LL_IOC_HSM_CT_START:
1775 rc = mdc_ioc_hsm_ct_start(exp, karg);
1777 case LL_IOC_HSM_PROGRESS:
1778 rc = mdc_ioc_hsm_progress(exp, karg);
1780 case LL_IOC_HSM_STATE_GET:
1781 rc = mdc_ioc_hsm_state_get(exp, karg);
1783 case LL_IOC_HSM_STATE_SET:
1784 rc = mdc_ioc_hsm_state_set(exp, karg);
1785 case LL_IOC_HSM_ACTION:
1786 rc = mdc_ioc_hsm_current_action(exp, karg);
1788 case LL_IOC_HSM_REQUEST:
1789 rc = mdc_ioc_hsm_request(exp, karg);
1791 case OBD_IOC_CLIENT_RECOVER:
1792 rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1, 0);
1796 case IOC_OSC_SET_ACTIVE:
1797 rc = ptlrpc_set_import_active(imp, data->ioc_offset);
1799 case OBD_IOC_PARSE: {
1800 ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT);
1801 rc = class_config_parse_llog(NULL, ctxt, data->ioc_inlbuf1,
1803 llog_ctxt_put(ctxt);
1806 case OBD_IOC_LLOG_INFO:
1807 case OBD_IOC_LLOG_PRINT: {
1808 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
1809 rc = llog_ioctl(NULL, ctxt, cmd, data);
1810 llog_ctxt_put(ctxt);
1813 case OBD_IOC_POLL_QUOTACHECK:
1814 rc = mdc_quota_poll_check(exp, (struct if_quotacheck *)karg);
1816 case OBD_IOC_PING_TARGET:
1817 rc = ptlrpc_obd_ping(obd);
1820 * Normally IOC_OBD_STATFS, OBD_IOC_QUOTACTL iocontrol are handled by
1821 * LMV instead of MDC. But when the cluster is upgraded from 1.8,
1822 * there'd be no LMV layer thus we might be called here. Eventually
1823 * this code should be removed.
1826 case IOC_OBD_STATFS: {
1827 struct obd_statfs stat_buf = {0};
1829 if (*((__u32 *) data->ioc_inlbuf2) != 0)
1830 GOTO(out, rc = -ENODEV);
1833 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(obd),
1834 min((int) data->ioc_plen2,
1835 (int) sizeof(struct obd_uuid))))
1836 GOTO(out, rc = -EFAULT);
1838 rc = mdc_statfs(NULL, obd->obd_self_export, &stat_buf,
1839 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1844 if (copy_to_user(data->ioc_pbuf1, &stat_buf,
1845 min((int) data->ioc_plen1,
1846 (int) sizeof(stat_buf))))
1847 GOTO(out, rc = -EFAULT);
1851 case OBD_IOC_QUOTACTL: {
1852 struct if_quotactl *qctl = karg;
1853 struct obd_quotactl *oqctl;
1855 OBD_ALLOC_PTR(oqctl);
1859 QCTL_COPY(oqctl, qctl);
1860 rc = obd_quotactl(exp, oqctl);
1862 QCTL_COPY(qctl, oqctl);
1863 qctl->qc_valid = QC_MDTIDX;
1864 qctl->obd_uuid = obd->u.cli.cl_target_uuid;
1866 OBD_FREE_PTR(oqctl);
1869 case LL_IOC_GET_CONNECT_FLAGS: {
1870 if (copy_to_user(uarg,
1871 exp_connect_flags_ptr(exp),
1873 GOTO(out, rc = -EFAULT);
1877 case LL_IOC_LOV_SWAP_LAYOUTS: {
1878 rc = mdc_ioc_swap_layouts(exp, karg);
1882 CERROR("mdc_ioctl(): unrecognised ioctl %#x\n", cmd);
1883 GOTO(out, rc = -ENOTTY);
1886 module_put(THIS_MODULE);
1891 int mdc_get_info_rpc(struct obd_export *exp,
1892 obd_count keylen, void *key,
1893 int vallen, void *val)
1895 struct obd_import *imp = class_exp2cliimp(exp);
1896 struct ptlrpc_request *req;
1901 req = ptlrpc_request_alloc(imp, &RQF_MDS_GET_INFO);
1905 req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_KEY,
1906 RCL_CLIENT, keylen);
1907 req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_VALLEN,
1908 RCL_CLIENT, sizeof(__u32));
1910 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GET_INFO);
1912 ptlrpc_request_free(req);
1916 tmp = req_capsule_client_get(&req->rq_pill, &RMF_GETINFO_KEY);
1917 memcpy(tmp, key, keylen);
1918 tmp = req_capsule_client_get(&req->rq_pill, &RMF_GETINFO_VALLEN);
1919 memcpy(tmp, &vallen, sizeof(__u32));
1921 req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_VAL,
1922 RCL_SERVER, vallen);
1923 ptlrpc_request_set_replen(req);
1925 rc = ptlrpc_queue_wait(req);
1926 /* -EREMOTE means the get_info result is partial, and it needs to
1927 * continue on another MDT, see fid2path part in lmv_iocontrol */
1928 if (rc == 0 || rc == -EREMOTE) {
1929 tmp = req_capsule_server_get(&req->rq_pill, &RMF_GETINFO_VAL);
1930 memcpy(val, tmp, vallen);
1931 if (ptlrpc_rep_need_swab(req)) {
1932 if (KEY_IS(KEY_FID2PATH))
1933 lustre_swab_fid2path(val);
1936 ptlrpc_req_finished(req);
1941 static void lustre_swab_hai(struct hsm_action_item *h)
1943 __swab32s(&h->hai_len);
1944 __swab32s(&h->hai_action);
1945 lustre_swab_lu_fid(&h->hai_fid);
1946 lustre_swab_lu_fid(&h->hai_dfid);
1947 __swab64s(&h->hai_cookie);
1948 __swab64s(&h->hai_extent.offset);
1949 __swab64s(&h->hai_extent.length);
1950 __swab64s(&h->hai_gid);
1953 static void lustre_swab_hal(struct hsm_action_list *h)
1955 struct hsm_action_item *hai;
1958 __swab32s(&h->hal_version);
1959 __swab32s(&h->hal_count);
1960 __swab32s(&h->hal_archive_id);
1961 __swab64s(&h->hal_flags);
1963 for (i = 0; i < h->hal_count; i++) {
1964 lustre_swab_hai(hai);
1965 hai = hai_next(hai);
1969 static void lustre_swab_kuch(struct kuc_hdr *l)
1971 __swab16s(&l->kuc_magic);
1972 /* __u8 l->kuc_transport */
1973 __swab16s(&l->kuc_msgtype);
1974 __swab16s(&l->kuc_msglen);
1977 static int mdc_ioc_hsm_ct_start(struct obd_export *exp,
1978 struct lustre_kernelcomm *lk)
1980 struct obd_import *imp = class_exp2cliimp(exp);
1981 __u32 archive = lk->lk_data;
1984 if (lk->lk_group != KUC_GRP_HSM) {
1985 CERROR("Bad copytool group %d\n", lk->lk_group);
1989 CDEBUG(D_HSM, "CT start r%d w%d u%d g%d f%#x\n", lk->lk_rfd, lk->lk_wfd,
1990 lk->lk_uid, lk->lk_group, lk->lk_flags);
1992 if (lk->lk_flags & LK_FLG_STOP) {
1993 rc = libcfs_kkuc_group_rem(lk->lk_uid, lk->lk_group);
1994 /* Unregister with the coordinator */
1996 rc = mdc_ioc_hsm_ct_unregister(imp);
1998 struct file *fp = fget(lk->lk_wfd);
2000 rc = libcfs_kkuc_group_add(fp, lk->lk_uid, lk->lk_group,
2005 rc = mdc_ioc_hsm_ct_register(imp, archive);
2012 * Send a message to any listening copytools
2013 * @param val KUC message (kuc_hdr + hsm_action_list)
2014 * @param len total length of message
2016 static int mdc_hsm_copytool_send(int len, void *val)
2018 struct kuc_hdr *lh = (struct kuc_hdr *)val;
2019 struct hsm_action_list *hal = (struct hsm_action_list *)(lh + 1);
2023 if (len < sizeof(*lh) + sizeof(*hal)) {
2024 CERROR("Short HSM message %d < %d\n", len,
2025 (int) (sizeof(*lh) + sizeof(*hal)));
2028 if (lh->kuc_magic == __swab16(KUC_MAGIC)) {
2029 lustre_swab_kuch(lh);
2030 lustre_swab_hal(hal);
2031 } else if (lh->kuc_magic != KUC_MAGIC) {
2032 CERROR("Bad magic %x!=%x\n", lh->kuc_magic, KUC_MAGIC);
2036 CDEBUG(D_HSM, " Received message mg=%x t=%d m=%d l=%d actions=%d "
2038 lh->kuc_magic, lh->kuc_transport, lh->kuc_msgtype,
2039 lh->kuc_msglen, hal->hal_count, hal->hal_fsname);
2041 /* Broadcast to HSM listeners */
2042 rc = libcfs_kkuc_group_put(KUC_GRP_HSM, lh);
2048 * callback function passed to kuc for re-registering each HSM copytool
2049 * running on MDC, after MDT shutdown/recovery.
2050 * @param data archive id served by the copytool
2051 * @param cb_arg callback argument (obd_import)
2053 static int mdc_hsm_ct_reregister(__u32 data, void *cb_arg)
2055 struct obd_import *imp = (struct obd_import *)cb_arg;
2056 __u32 archive = data;
2059 CDEBUG(D_HA, "recover copytool registration to MDT (archive=%#x)\n",
2061 rc = mdc_ioc_hsm_ct_register(imp, archive);
2063 /* ignore error if the copytool is already registered */
2064 return ((rc != 0) && (rc != -EEXIST)) ? rc : 0;
2068 * Re-establish all kuc contexts with MDT
2069 * after MDT shutdown/recovery.
2071 static int mdc_kuc_reregister(struct obd_import *imp)
2073 /* re-register HSM agents */
2074 return libcfs_kkuc_group_foreach(KUC_GRP_HSM, mdc_hsm_ct_reregister,
2078 int mdc_set_info_async(const struct lu_env *env,
2079 struct obd_export *exp,
2080 obd_count keylen, void *key,
2081 obd_count vallen, void *val,
2082 struct ptlrpc_request_set *set)
2084 struct obd_import *imp = class_exp2cliimp(exp);
2088 if (KEY_IS(KEY_READ_ONLY)) {
2089 if (vallen != sizeof(int))
2092 spin_lock(&imp->imp_lock);
2093 if (*((int *)val)) {
2094 imp->imp_connect_flags_orig |= OBD_CONNECT_RDONLY;
2095 imp->imp_connect_data.ocd_connect_flags |=
2098 imp->imp_connect_flags_orig &= ~OBD_CONNECT_RDONLY;
2099 imp->imp_connect_data.ocd_connect_flags &=
2100 ~OBD_CONNECT_RDONLY;
2102 spin_unlock(&imp->imp_lock);
2104 rc = do_set_info_async(imp, MDS_SET_INFO, LUSTRE_MDS_VERSION,
2105 keylen, key, vallen, val, set);
2108 if (KEY_IS(KEY_SPTLRPC_CONF)) {
2109 sptlrpc_conf_client_adapt(exp->exp_obd);
2112 if (KEY_IS(KEY_FLUSH_CTX)) {
2113 sptlrpc_import_flush_my_ctx(imp);
2116 if (KEY_IS(KEY_MDS_CONN)) {
2117 /* mds-mds import */
2118 spin_lock(&imp->imp_lock);
2119 imp->imp_server_timeout = 1;
2120 spin_unlock(&imp->imp_lock);
2121 imp->imp_client->cli_request_portal = MDS_MDS_PORTAL;
2122 CDEBUG(D_OTHER, "%s: timeout / 2\n", exp->exp_obd->obd_name);
2125 if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
2126 rc = do_set_info_async(imp, MDS_SET_INFO, LUSTRE_MDS_VERSION,
2127 keylen, key, vallen, val, set);
2130 if (KEY_IS(KEY_HSM_COPYTOOL_SEND)) {
2131 rc = mdc_hsm_copytool_send(vallen, val);
2135 CERROR("Unknown key %s\n", (char *)key);
2139 int mdc_get_info(const struct lu_env *env, struct obd_export *exp,
2140 __u32 keylen, void *key, __u32 *vallen, void *val,
2141 struct lov_stripe_md *lsm)
2145 if (KEY_IS(KEY_MAX_EASIZE)) {
2146 int mdsize, *max_easize;
2148 if (*vallen != sizeof(int))
2150 mdsize = *(int*)val;
2151 if (mdsize > exp->exp_obd->u.cli.cl_max_mds_easize)
2152 exp->exp_obd->u.cli.cl_max_mds_easize = mdsize;
2154 *max_easize = exp->exp_obd->u.cli.cl_max_mds_easize;
2156 } else if (KEY_IS(KEY_CONN_DATA)) {
2157 struct obd_import *imp = class_exp2cliimp(exp);
2158 struct obd_connect_data *data = val;
2160 if (*vallen != sizeof(*data))
2163 *data = imp->imp_connect_data;
2165 } else if (KEY_IS(KEY_TGT_COUNT)) {
2170 rc = mdc_get_info_rpc(exp, keylen, key, *vallen, val);
2175 static int mdc_pin(struct obd_export *exp, const struct lu_fid *fid,
2176 struct obd_capa *oc, struct obd_client_handle *handle,
2179 struct ptlrpc_request *req;
2180 struct mdt_body *body;
2184 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_PIN);
2188 mdc_set_capa_size(req, &RMF_CAPA1, oc);
2190 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_PIN);
2192 ptlrpc_request_free(req);
2196 mdc_pack_body(req, fid, oc, 0, 0, -1, flags);
2198 ptlrpc_request_set_replen(req);
2200 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
2201 rc = ptlrpc_queue_wait(req);
2202 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
2204 CERROR("Pin failed: %d\n", rc);
2208 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
2210 GOTO(err_out, rc = -EPROTO);
2212 handle->och_fh = body->handle;
2213 handle->och_magic = OBD_CLIENT_HANDLE_MAGIC;
2215 handle->och_mod = obd_mod_alloc();
2216 if (handle->och_mod == NULL) {
2217 DEBUG_REQ(D_ERROR, req, "can't allocate md_open_data");
2218 GOTO(err_out, rc = -ENOMEM);
2220 handle->och_mod->mod_open_req = req; /* will be dropped by unpin */
2225 ptlrpc_req_finished(req);
2229 static int mdc_unpin(struct obd_export *exp, struct obd_client_handle *handle,
2232 struct ptlrpc_request *req;
2233 struct mdt_body *body;
2237 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_UNPIN,
2238 LUSTRE_MDS_VERSION, MDS_UNPIN);
2242 body = req_capsule_client_get(&req->rq_pill, &RMF_MDT_BODY);
2243 body->handle = handle->och_fh;
2246 ptlrpc_request_set_replen(req);
2248 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
2249 rc = ptlrpc_queue_wait(req);
2250 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
2253 CERROR("Unpin failed: %d\n", rc);
2255 ptlrpc_req_finished(req);
2256 ptlrpc_req_finished(handle->och_mod->mod_open_req);
2258 obd_mod_put(handle->och_mod);
2262 int mdc_sync(struct obd_export *exp, const struct lu_fid *fid,
2263 struct obd_capa *oc, struct ptlrpc_request **request)
2265 struct ptlrpc_request *req;
2270 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_SYNC);
2274 mdc_set_capa_size(req, &RMF_CAPA1, oc);
2276 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_SYNC);
2278 ptlrpc_request_free(req);
2282 mdc_pack_body(req, fid, oc, 0, 0, -1, 0);
2284 ptlrpc_request_set_replen(req);
2286 rc = ptlrpc_queue_wait(req);
2288 ptlrpc_req_finished(req);
2294 static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
2295 enum obd_import_event event)
2299 LASSERT(imp->imp_obd == obd);
2302 case IMP_EVENT_DISCON: {
2304 /* XXX Pass event up to OBDs stack. used only for FLD now */
2305 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_DISCON, NULL);
2309 case IMP_EVENT_INACTIVE: {
2310 struct client_obd *cli = &obd->u.cli;
2312 * Flush current sequence to make client obtain new one
2313 * from server in case of disconnect/reconnect.
2315 if (cli->cl_seq != NULL)
2316 seq_client_flush(cli->cl_seq);
2318 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_INACTIVE, NULL);
2321 case IMP_EVENT_INVALIDATE: {
2322 struct ldlm_namespace *ns = obd->obd_namespace;
2324 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
2328 case IMP_EVENT_ACTIVE:
2329 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_ACTIVE, NULL);
2330 /* restore re-establish kuc registration after reconnecting */
2332 rc = mdc_kuc_reregister(imp);
2335 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_OCD, NULL);
2337 case IMP_EVENT_DEACTIVATE:
2338 case IMP_EVENT_ACTIVATE:
2341 CERROR("Unknown import event %x\n", event);
2347 int mdc_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
2348 struct md_op_data *op_data)
2350 struct client_obd *cli = &exp->exp_obd->u.cli;
2351 struct lu_client_seq *seq = cli->cl_seq;
2353 RETURN(seq_client_alloc_fid(NULL, seq, fid));
2356 struct obd_uuid *mdc_get_uuid(struct obd_export *exp) {
2357 struct client_obd *cli = &exp->exp_obd->u.cli;
2358 return &cli->cl_target_uuid;
2362 * Determine whether the lock can be canceled before replaying it during
2363 * recovery, non zero value will be return if the lock can be canceled,
2364 * or zero returned for not
2366 static int mdc_cancel_for_recovery(struct ldlm_lock *lock)
2368 if (lock->l_resource->lr_type != LDLM_IBITS)
2371 /* FIXME: if we ever get into a situation where there are too many
2372 * opened files with open locks on a single node, then we really
2373 * should replay these open locks to reget it */
2374 if (lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_OPEN)
2380 static int mdc_resource_inode_free(struct ldlm_resource *res)
2382 if (res->lr_lvb_inode)
2383 res->lr_lvb_inode = NULL;
2388 struct ldlm_valblock_ops inode_lvbo = {
2389 lvbo_free: mdc_resource_inode_free
2392 static int mdc_setup(struct obd_device *obd, struct lustre_cfg *cfg)
2394 struct client_obd *cli = &obd->u.cli;
2395 struct lprocfs_static_vars lvars = { 0 };
2399 OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
2400 if (!cli->cl_rpc_lock)
2402 mdc_init_rpc_lock(cli->cl_rpc_lock);
2406 OBD_ALLOC(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
2407 if (!cli->cl_close_lock)
2408 GOTO(err_rpc_lock, rc = -ENOMEM);
2409 mdc_init_rpc_lock(cli->cl_close_lock);
2411 rc = client_obd_setup(obd, cfg);
2413 GOTO(err_close_lock, rc);
2414 lprocfs_mdc_init_vars(&lvars);
2415 lprocfs_obd_setup(obd, lvars.obd_vars);
2416 sptlrpc_lprocfs_cliobd_attach(obd);
2417 ptlrpc_lprocfs_register_obd(obd);
2419 ns_register_cancel(obd->obd_namespace, mdc_cancel_for_recovery);
2421 obd->obd_namespace->ns_lvbo = &inode_lvbo;
2423 rc = obd_llog_init(obd, &obd->obd_olg, obd, NULL);
2426 CERROR("failed to setup llogging subsystems\n");
2432 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
2434 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
2439 /* Initialize the default and maximum LOV EA and cookie sizes. This allows
2440 * us to make MDS RPCs with large enough reply buffers to hold the
2441 * maximum-sized (= maximum striped) EA and cookie without having to
2442 * calculate this (via a call into the LOV + OSCs) each time we make an RPC. */
2443 static int mdc_init_ea_size(struct obd_export *exp, int easize,
2444 int def_easize, int cookiesize)
2446 struct obd_device *obd = exp->exp_obd;
2447 struct client_obd *cli = &obd->u.cli;
2450 if (cli->cl_max_mds_easize < easize)
2451 cli->cl_max_mds_easize = easize;
2453 if (cli->cl_default_mds_easize < def_easize)
2454 cli->cl_default_mds_easize = def_easize;
2456 if (cli->cl_max_mds_cookiesize < cookiesize)
2457 cli->cl_max_mds_cookiesize = cookiesize;
2462 static int mdc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2468 case OBD_CLEANUP_EARLY:
2470 case OBD_CLEANUP_EXPORTS:
2471 /* Failsafe, ok if racy */
2472 if (obd->obd_type->typ_refcnt <= 1)
2473 libcfs_kkuc_group_rem(0, KUC_GRP_HSM);
2475 obd_cleanup_client_import(obd);
2476 ptlrpc_lprocfs_unregister_obd(obd);
2477 lprocfs_obd_cleanup(obd);
2479 rc = obd_llog_finish(obd, 0);
2481 CERROR("failed to cleanup llogging subsystems\n");
2487 static int mdc_cleanup(struct obd_device *obd)
2489 struct client_obd *cli = &obd->u.cli;
2491 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
2492 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
2496 return client_obd_cleanup(obd);
2500 static int mdc_llog_init(struct obd_device *obd, struct obd_llog_group *olg,
2501 struct obd_device *tgt, int *index)
2503 struct llog_ctxt *ctxt;
2508 LASSERT(olg == &obd->obd_olg);
2510 rc = llog_setup(NULL, obd, olg, LLOG_CHANGELOG_REPL_CTXT, tgt,
2515 ctxt = llog_group_get_ctxt(olg, LLOG_CHANGELOG_REPL_CTXT);
2516 llog_initiator_connect(ctxt);
2517 llog_ctxt_put(ctxt);
2522 static int mdc_llog_finish(struct obd_device *obd, int count)
2524 struct llog_ctxt *ctxt;
2528 ctxt = llog_get_context(obd, LLOG_CHANGELOG_REPL_CTXT);
2530 llog_cleanup(NULL, ctxt);
2535 static int mdc_process_config(struct obd_device *obd, obd_count len, void *buf)
2537 struct lustre_cfg *lcfg = buf;
2538 struct lprocfs_static_vars lvars = { 0 };
2541 lprocfs_mdc_init_vars(&lvars);
2542 switch (lcfg->lcfg_command) {
2544 rc = class_process_proc_param(PARAM_MDC, lvars.obd_vars,
2554 /* get remote permission for current user on fid */
2555 int mdc_get_remote_perm(struct obd_export *exp, const struct lu_fid *fid,
2556 struct obd_capa *oc, __u32 suppgid,
2557 struct ptlrpc_request **request)
2559 struct ptlrpc_request *req;
2563 LASSERT(client_is_remote(exp));
2566 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR);
2570 mdc_set_capa_size(req, &RMF_CAPA1, oc);
2572 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR);
2574 ptlrpc_request_free(req);
2578 mdc_pack_body(req, fid, oc, OBD_MD_FLRMTPERM, 0, suppgid, 0);
2580 req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER,
2581 sizeof(struct mdt_remote_perm));
2583 ptlrpc_request_set_replen(req);
2585 rc = ptlrpc_queue_wait(req);
2587 ptlrpc_req_finished(req);
2593 static int mdc_interpret_renew_capa(const struct lu_env *env,
2594 struct ptlrpc_request *req, void *args,
2597 struct mdc_renew_capa_args *ra = args;
2598 struct mdt_body *body = NULL;
2599 struct lustre_capa *capa;
2603 GOTO(out, capa = ERR_PTR(status));
2605 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
2607 GOTO(out, capa = ERR_PTR(-EFAULT));
2609 if ((body->valid & OBD_MD_FLOSSCAPA) == 0)
2610 GOTO(out, capa = ERR_PTR(-ENOENT));
2612 capa = req_capsule_server_get(&req->rq_pill, &RMF_CAPA2);
2614 GOTO(out, capa = ERR_PTR(-EFAULT));
2617 ra->ra_cb(ra->ra_oc, capa);
2621 static int mdc_renew_capa(struct obd_export *exp, struct obd_capa *oc,
2624 struct ptlrpc_request *req;
2625 struct mdc_renew_capa_args *ra;
2628 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_GETATTR,
2629 LUSTRE_MDS_VERSION, MDS_GETATTR);
2633 /* NB, OBD_MD_FLOSSCAPA is set here, but it doesn't necessarily mean the
2634 * capa to renew is oss capa.
2636 mdc_pack_body(req, &oc->c_capa.lc_fid, oc, OBD_MD_FLOSSCAPA, 0, -1, 0);
2637 ptlrpc_request_set_replen(req);
2639 CLASSERT(sizeof(*ra) <= sizeof(req->rq_async_args));
2640 ra = ptlrpc_req_async_args(req);
2643 req->rq_interpret_reply = mdc_interpret_renew_capa;
2644 ptlrpcd_add_req(req, PDL_POLICY_LOCAL, -1);
2648 static int mdc_connect(const struct lu_env *env,
2649 struct obd_export **exp,
2650 struct obd_device *obd, struct obd_uuid *cluuid,
2651 struct obd_connect_data *data,
2654 struct obd_import *imp = obd->u.cli.cl_import;
2656 /* mds-mds import features */
2657 if (data && (data->ocd_connect_flags & OBD_CONNECT_MDS_MDS)) {
2658 spin_lock(&imp->imp_lock);
2659 imp->imp_server_timeout = 1;
2660 spin_unlock(&imp->imp_lock);
2661 imp->imp_client->cli_request_portal = MDS_MDS_PORTAL;
2662 CDEBUG(D_OTHER, "%s: Set 'mds' portal and timeout\n",
2666 return client_connect_import(env, exp, obd, cluuid, data, NULL);
2669 struct obd_ops mdc_obd_ops = {
2670 .o_owner = THIS_MODULE,
2671 .o_setup = mdc_setup,
2672 .o_precleanup = mdc_precleanup,
2673 .o_cleanup = mdc_cleanup,
2674 .o_add_conn = client_import_add_conn,
2675 .o_del_conn = client_import_del_conn,
2676 .o_connect = mdc_connect,
2677 .o_disconnect = client_disconnect_export,
2678 .o_iocontrol = mdc_iocontrol,
2679 .o_set_info_async = mdc_set_info_async,
2680 .o_statfs = mdc_statfs,
2682 .o_unpin = mdc_unpin,
2683 .o_fid_init = client_fid_init,
2684 .o_fid_fini = client_fid_fini,
2685 .o_fid_alloc = mdc_fid_alloc,
2686 .o_import_event = mdc_import_event,
2687 .o_llog_init = mdc_llog_init,
2688 .o_llog_finish = mdc_llog_finish,
2689 .o_get_info = mdc_get_info,
2690 .o_process_config = mdc_process_config,
2691 .o_get_uuid = mdc_get_uuid,
2692 .o_quotactl = mdc_quotactl,
2693 .o_quotacheck = mdc_quotacheck
2696 struct md_ops mdc_md_ops = {
2697 .m_getstatus = mdc_getstatus,
2698 .m_null_inode = mdc_null_inode,
2699 .m_find_cbdata = mdc_find_cbdata,
2700 .m_close = mdc_close,
2701 .m_create = mdc_create,
2702 .m_done_writing = mdc_done_writing,
2703 .m_enqueue = mdc_enqueue,
2704 .m_getattr = mdc_getattr,
2705 .m_getattr_name = mdc_getattr_name,
2706 .m_intent_lock = mdc_intent_lock,
2708 .m_is_subdir = mdc_is_subdir,
2709 .m_rename = mdc_rename,
2710 .m_setattr = mdc_setattr,
2711 .m_setxattr = mdc_setxattr,
2712 .m_getxattr = mdc_getxattr,
2714 .m_readpage = mdc_readpage,
2715 .m_unlink = mdc_unlink,
2716 .m_cancel_unused = mdc_cancel_unused,
2717 .m_init_ea_size = mdc_init_ea_size,
2718 .m_set_lock_data = mdc_set_lock_data,
2719 .m_lock_match = mdc_lock_match,
2720 .m_get_lustre_md = mdc_get_lustre_md,
2721 .m_free_lustre_md = mdc_free_lustre_md,
2722 .m_set_open_replay_data = mdc_set_open_replay_data,
2723 .m_clear_open_replay_data = mdc_clear_open_replay_data,
2724 .m_renew_capa = mdc_renew_capa,
2725 .m_unpack_capa = mdc_unpack_capa,
2726 .m_get_remote_perm = mdc_get_remote_perm,
2727 .m_intent_getattr_async = mdc_intent_getattr_async,
2728 .m_revalidate_lock = mdc_revalidate_lock
2731 int __init mdc_init(void)
2734 struct lprocfs_static_vars lvars = { 0 };
2735 lprocfs_mdc_init_vars(&lvars);
2737 rc = class_register_type(&mdc_obd_ops, &mdc_md_ops, lvars.module_vars,
2738 LUSTRE_MDC_NAME, NULL);
2742 static void /*__exit*/ mdc_exit(void)
2744 class_unregister_type(LUSTRE_MDC_NAME);
2747 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2748 MODULE_DESCRIPTION("Lustre Metadata Client");
2749 MODULE_LICENSE("GPL");
2751 module_init(mdc_init);
2752 module_exit(mdc_exit);