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
40 # include <linux/module.h>
41 # include <linux/pagemap.h>
42 # include <linux/miscdevice.h>
43 # include <linux/init.h>
45 # include <liblustre.h>
48 #include <lustre_acl.h>
49 #include <obd_class.h>
50 #include <lustre_fid.h>
51 #include <md_object.h>
52 #include <lprocfs_status.h>
53 #include <lustre_param.h>
54 #include <lustre_log.h>
56 #include "mdc_internal.h"
58 #define REQUEST_MINOR 244
60 struct mdc_renew_capa_args {
61 struct obd_capa *ra_oc;
62 renew_capa_cb_t ra_cb;
65 static int mdc_cleanup(struct obd_device *obd);
67 int mdc_unpack_capa(struct obd_export *exp, struct ptlrpc_request *req,
68 const struct req_msg_field *field, struct obd_capa **oc)
70 struct lustre_capa *capa;
74 /* swabbed already in mdc_enqueue */
75 capa = req_capsule_server_get(&req->rq_pill, field);
79 c = alloc_capa(CAPA_SITE_CLIENT);
81 CDEBUG(D_INFO, "alloc capa failed!\n");
90 static inline int mdc_queue_wait(struct ptlrpc_request *req)
92 struct client_obd *cli = &req->rq_import->imp_obd->u.cli;
95 /* mdc_enter_request() ensures that this client has no more
96 * than cl_max_rpcs_in_flight RPCs simultaneously inf light
98 rc = mdc_enter_request(cli);
102 rc = ptlrpc_queue_wait(req);
103 mdc_exit_request(cli);
108 /* Helper that implements most of mdc_getstatus and signal_completed_replay. */
109 /* XXX this should become mdc_get_info("key"), sending MDS_GET_INFO RPC */
110 static int send_getstatus(struct obd_import *imp, struct lu_fid *rootfid,
111 struct obd_capa **pc, int level, int msg_flags)
113 struct ptlrpc_request *req;
114 struct mdt_body *body;
118 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_GETSTATUS,
119 LUSTRE_MDS_VERSION, MDS_GETSTATUS);
123 mdc_pack_body(req, NULL, NULL, 0, 0, -1, 0);
124 lustre_msg_add_flags(req->rq_reqmsg, msg_flags);
125 req->rq_send_state = level;
127 ptlrpc_request_set_replen(req);
129 rc = ptlrpc_queue_wait(req);
133 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
135 GOTO(out, rc = -EPROTO);
137 if (body->valid & OBD_MD_FLMDSCAPA) {
138 rc = mdc_unpack_capa(NULL, req, &RMF_CAPA1, pc);
143 *rootfid = body->fid1;
145 "root fid="DFID", last_committed="LPU64"\n",
147 lustre_msg_get_last_committed(req->rq_repmsg));
150 ptlrpc_req_finished(req);
154 /* This should be mdc_get_info("rootfid") */
155 int mdc_getstatus(struct obd_export *exp, struct lu_fid *rootfid,
156 struct obd_capa **pc)
158 return send_getstatus(class_exp2cliimp(exp), rootfid, pc,
163 * This function now is known to always saying that it will receive 4 buffers
164 * from server. Even for cases when acl_size and md_size is zero, RPC header
165 * will contain 4 fields and RPC itself will contain zero size fields. This is
166 * because mdt_getattr*() _always_ returns 4 fields, but if acl is not needed
167 * and thus zero, it shrinks it, making zero size. The same story about
168 * md_size. And this is course of problem when client waits for smaller number
169 * of fields. This issue will be fixed later when client gets aware of RPC
172 static int mdc_getattr_common(struct obd_export *exp,
173 struct ptlrpc_request *req)
175 struct req_capsule *pill = &req->rq_pill;
176 struct mdt_body *body;
181 /* Request message already built. */
182 rc = ptlrpc_queue_wait(req);
186 /* sanity check for the reply */
187 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
191 CDEBUG(D_NET, "mode: %o\n", body->mode);
193 if (body->eadatasize != 0) {
194 mdc_update_max_ea_from_body(exp, body);
196 eadata = req_capsule_server_sized_get(pill, &RMF_MDT_MD,
202 if (body->valid & OBD_MD_FLRMTPERM) {
203 struct mdt_remote_perm *perm;
205 LASSERT(client_is_remote(exp));
206 perm = req_capsule_server_swab_get(pill, &RMF_ACL,
207 lustre_swab_mdt_remote_perm);
212 if (body->valid & OBD_MD_FLMDSCAPA) {
213 struct lustre_capa *capa;
214 capa = req_capsule_server_get(pill, &RMF_CAPA1);
222 int mdc_getattr(struct obd_export *exp, struct md_op_data *op_data,
223 struct ptlrpc_request **request)
225 struct ptlrpc_request *req;
230 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR);
234 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
236 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR);
238 ptlrpc_request_free(req);
242 mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
243 op_data->op_valid, op_data->op_mode, -1, 0);
245 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER,
247 if (op_data->op_valid & OBD_MD_FLRMTPERM) {
248 LASSERT(client_is_remote(exp));
249 req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER,
250 sizeof(struct mdt_remote_perm));
252 ptlrpc_request_set_replen(req);
254 rc = mdc_getattr_common(exp, req);
256 ptlrpc_req_finished(req);
262 int mdc_getattr_name(struct obd_export *exp, struct md_op_data *op_data,
263 struct ptlrpc_request **request)
265 struct ptlrpc_request *req;
270 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
271 &RQF_MDS_GETATTR_NAME);
275 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
276 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
277 op_data->op_namelen + 1);
279 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR_NAME);
281 ptlrpc_request_free(req);
285 mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
286 op_data->op_valid, op_data->op_mode,
287 op_data->op_suppgids[0], 0);
289 if (op_data->op_name) {
290 char *name = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
291 LASSERT(strnlen(op_data->op_name, op_data->op_namelen) ==
292 op_data->op_namelen);
293 memcpy(name, op_data->op_name, op_data->op_namelen);
296 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER,
298 ptlrpc_request_set_replen(req);
300 rc = mdc_getattr_common(exp, req);
302 ptlrpc_req_finished(req);
308 static int mdc_is_subdir(struct obd_export *exp,
309 const struct lu_fid *pfid,
310 const struct lu_fid *cfid,
311 struct ptlrpc_request **request)
313 struct ptlrpc_request *req;
319 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
320 &RQF_MDS_IS_SUBDIR, LUSTRE_MDS_VERSION,
325 mdc_is_subdir_pack(req, pfid, cfid, 0);
326 ptlrpc_request_set_replen(req);
328 rc = ptlrpc_queue_wait(req);
329 if (rc && rc != -EREMOTE)
330 ptlrpc_req_finished(req);
336 static int mdc_xattr_common(struct obd_export *exp,const struct req_format *fmt,
337 const struct lu_fid *fid,
338 struct obd_capa *oc, int opcode, obd_valid valid,
339 const char *xattr_name, const char *input,
340 int input_size, int output_size, int flags,
341 __u32 suppgid, struct ptlrpc_request **request)
343 struct ptlrpc_request *req;
344 int xattr_namelen = 0;
350 req = ptlrpc_request_alloc(class_exp2cliimp(exp), fmt);
354 mdc_set_capa_size(req, &RMF_CAPA1, oc);
356 xattr_namelen = strlen(xattr_name) + 1;
357 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
362 req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_CLIENT,
366 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, opcode);
368 ptlrpc_request_free(req);
372 if (opcode == MDS_REINT) {
373 struct mdt_rec_setxattr *rec;
375 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
376 sizeof(struct mdt_rec_reint));
377 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
378 rec->sx_opcode = REINT_SETXATTR;
380 * cfs_curproc_fs{u,g}id() should replace
381 * current->fs{u,g}id for portability.
383 rec->sx_fsuid = cfs_curproc_fsuid();
384 rec->sx_fsgid = cfs_curproc_fsgid();
385 rec->sx_cap = cfs_curproc_cap_pack();
386 rec->sx_suppgid1 = suppgid;
387 rec->sx_suppgid2 = -1;
389 rec->sx_valid = valid | OBD_MD_FLCTIME;
390 rec->sx_time = cfs_time_current_sec();
391 rec->sx_size = output_size;
392 rec->sx_flags = flags;
394 mdc_pack_capa(req, &RMF_CAPA1, oc);
396 mdc_pack_body(req, fid, oc, valid, output_size, suppgid, flags);
400 tmp = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
401 memcpy(tmp, xattr_name, xattr_namelen);
404 tmp = req_capsule_client_get(&req->rq_pill, &RMF_EADATA);
405 memcpy(tmp, input, input_size);
408 if (req_capsule_has_field(&req->rq_pill, &RMF_EADATA, RCL_SERVER))
409 req_capsule_set_size(&req->rq_pill, &RMF_EADATA,
410 RCL_SERVER, output_size);
411 ptlrpc_request_set_replen(req);
414 if (opcode == MDS_REINT)
415 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
417 rc = ptlrpc_queue_wait(req);
419 if (opcode == MDS_REINT)
420 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
423 ptlrpc_req_finished(req);
429 int mdc_setxattr(struct obd_export *exp, const struct lu_fid *fid,
430 struct obd_capa *oc, obd_valid valid, const char *xattr_name,
431 const char *input, int input_size, int output_size,
432 int flags, __u32 suppgid, struct ptlrpc_request **request)
434 return mdc_xattr_common(exp, &RQF_MDS_REINT_SETXATTR,
435 fid, oc, MDS_REINT, valid, xattr_name,
436 input, input_size, output_size, flags,
440 int mdc_getxattr(struct obd_export *exp, const struct lu_fid *fid,
441 struct obd_capa *oc, obd_valid valid, const char *xattr_name,
442 const char *input, int input_size, int output_size,
443 int flags, struct ptlrpc_request **request)
445 return mdc_xattr_common(exp, &RQF_MDS_GETXATTR,
446 fid, oc, MDS_GETXATTR, valid, xattr_name,
447 input, input_size, output_size, flags,
451 #ifdef CONFIG_FS_POSIX_ACL
452 static int mdc_unpack_acl(struct ptlrpc_request *req, struct lustre_md *md)
454 struct req_capsule *pill = &req->rq_pill;
455 struct mdt_body *body = md->body;
456 struct posix_acl *acl;
464 buf = req_capsule_server_sized_get(pill, &RMF_ACL, body->aclsize);
469 acl = posix_acl_from_xattr(buf, body->aclsize);
472 CERROR("convert xattr to acl: %d\n", rc);
476 rc = posix_acl_valid(acl);
478 CERROR("validate acl: %d\n", rc);
479 posix_acl_release(acl);
487 #define mdc_unpack_acl(req, md) 0
490 int mdc_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
491 struct obd_export *dt_exp, struct obd_export *md_exp,
492 struct lustre_md *md)
494 struct req_capsule *pill = &req->rq_pill;
499 memset(md, 0, sizeof(*md));
501 md->body = req_capsule_server_get(pill, &RMF_MDT_BODY);
502 LASSERT(md->body != NULL);
504 if (md->body->valid & OBD_MD_FLEASIZE) {
506 struct lov_mds_md *lmm;
508 if (!S_ISREG(md->body->mode)) {
509 CDEBUG(D_INFO, "OBD_MD_FLEASIZE set, should be a "
510 "regular file, but is not\n");
511 GOTO(out, rc = -EPROTO);
514 if (md->body->eadatasize == 0) {
515 CDEBUG(D_INFO, "OBD_MD_FLEASIZE set, "
516 "but eadatasize 0\n");
517 GOTO(out, rc = -EPROTO);
519 lmmsize = md->body->eadatasize;
520 lmm = req_capsule_server_sized_get(pill, &RMF_MDT_MD, lmmsize);
522 GOTO(out, rc = -EPROTO);
524 rc = obd_unpackmd(dt_exp, &md->lsm, lmm, lmmsize);
528 if (rc < sizeof(*md->lsm)) {
529 CDEBUG(D_INFO, "lsm size too small: "
530 "rc < sizeof (*md->lsm) (%d < %d)\n",
531 rc, (int)sizeof(*md->lsm));
532 GOTO(out, rc = -EPROTO);
535 } else if (md->body->valid & OBD_MD_FLDIREA) {
537 struct lov_mds_md *lmv;
539 if(!S_ISDIR(md->body->mode)) {
540 CDEBUG(D_INFO, "OBD_MD_FLDIREA set, should be a "
541 "directory, but is not\n");
542 GOTO(out, rc = -EPROTO);
545 if (md->body->eadatasize == 0) {
546 CDEBUG(D_INFO, "OBD_MD_FLDIREA is set, "
547 "but eadatasize 0\n");
550 if (md->body->valid & OBD_MD_MEA) {
551 lmvsize = md->body->eadatasize;
552 lmv = req_capsule_server_sized_get(pill, &RMF_MDT_MD,
555 GOTO(out, rc = -EPROTO);
557 rc = obd_unpackmd(md_exp, (void *)&md->mea, lmv,
562 if (rc < sizeof(*md->mea)) {
563 CDEBUG(D_INFO, "size too small: "
564 "rc < sizeof(*md->mea) (%d < %d)\n",
565 rc, (int)sizeof(*md->mea));
566 GOTO(out, rc = -EPROTO);
572 if (md->body->valid & OBD_MD_FLRMTPERM) {
573 /* remote permission */
574 LASSERT(client_is_remote(exp));
575 md->remote_perm = req_capsule_server_swab_get(pill, &RMF_ACL,
576 lustre_swab_mdt_remote_perm);
577 if (!md->remote_perm)
578 GOTO(out, rc = -EPROTO);
580 else if (md->body->valid & OBD_MD_FLACL) {
581 /* for ACL, it's possible that FLACL is set but aclsize is zero.
582 * only when aclsize != 0 there's an actual segment for ACL
585 if (md->body->aclsize) {
586 rc = mdc_unpack_acl(req, md);
589 #ifdef CONFIG_FS_POSIX_ACL
591 md->posix_acl = NULL;
595 if (md->body->valid & OBD_MD_FLMDSCAPA) {
596 struct obd_capa *oc = NULL;
598 rc = mdc_unpack_capa(NULL, req, &RMF_CAPA1, &oc);
604 if (md->body->valid & OBD_MD_FLOSSCAPA) {
605 struct obd_capa *oc = NULL;
607 rc = mdc_unpack_capa(NULL, req, &RMF_CAPA2, &oc);
617 capa_put(md->oss_capa);
621 capa_put(md->mds_capa);
624 #ifdef CONFIG_FS_POSIX_ACL
625 posix_acl_release(md->posix_acl);
628 obd_free_memmd(dt_exp, &md->lsm);
633 int mdc_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
640 * Handles both OPEN and SETATTR RPCs for OPEN-CLOSE and SETATTR-DONE_WRITING
643 void mdc_replay_open(struct ptlrpc_request *req)
645 struct md_open_data *mod = req->rq_cb_data;
646 struct ptlrpc_request *close_req;
647 struct obd_client_handle *och;
648 struct lustre_handle old;
649 struct mdt_body *body;
653 DEBUG_REQ(D_ERROR, req,
654 "Can't properly replay without open data.");
659 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
660 LASSERT(body != NULL);
664 struct lustre_handle *file_fh;
666 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
668 file_fh = &och->och_fh;
669 CDEBUG(D_HA, "updating handle from "LPX64" to "LPX64"\n",
670 file_fh->cookie, body->handle.cookie);
672 *file_fh = body->handle;
674 close_req = mod->mod_close_req;
675 if (close_req != NULL) {
676 __u32 opc = lustre_msg_get_opc(close_req->rq_reqmsg);
677 struct mdt_ioepoch *epoch;
679 LASSERT(opc == MDS_CLOSE || opc == MDS_DONE_WRITING);
680 epoch = req_capsule_client_get(&close_req->rq_pill,
685 LASSERT(!memcmp(&old, &epoch->handle, sizeof(old)));
686 DEBUG_REQ(D_HA, close_req, "updating close body with new fh");
687 epoch->handle = body->handle;
692 void mdc_commit_open(struct ptlrpc_request *req)
694 struct md_open_data *mod = req->rq_cb_data;
699 * No need to touch md_open_data::mod_och, it holds a reference on
700 * \var mod and will zero references to each other, \var mod will be
701 * freed after that when md_open_data::mod_och will put the reference.
705 * Do not let open request to disappear as it still may be needed
706 * for close rpc to happen (it may happen on evict only, otherwise
707 * ptlrpc_request::rq_replay does not let mdc_commit_open() to be
708 * called), just mark this rpc as committed to distinguish these 2
709 * cases, see mdc_close() for details. The open request reference will
710 * be put along with freeing \var mod.
712 ptlrpc_request_addref(req);
713 spin_lock(&req->rq_lock);
714 req->rq_committed = 1;
715 spin_unlock(&req->rq_lock);
716 req->rq_cb_data = NULL;
720 int mdc_set_open_replay_data(struct obd_export *exp,
721 struct obd_client_handle *och,
722 struct ptlrpc_request *open_req)
724 struct md_open_data *mod;
725 struct mdt_rec_create *rec;
726 struct mdt_body *body;
727 struct obd_import *imp = open_req->rq_import;
730 if (!open_req->rq_replay)
733 rec = req_capsule_client_get(&open_req->rq_pill, &RMF_REC_REINT);
734 body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY);
735 LASSERT(rec != NULL);
736 /* Incoming message in my byte order (it's been swabbed). */
737 /* Outgoing messages always in my byte order. */
738 LASSERT(body != NULL);
740 /* Only if the import is replayable, we set replay_open data */
741 if (och && imp->imp_replayable) {
742 mod = obd_mod_alloc();
744 DEBUG_REQ(D_ERROR, open_req,
745 "Can't allocate md_open_data");
750 * Take a reference on \var mod, to be freed on mdc_close().
751 * It protects \var mod from being freed on eviction (commit
752 * callback is called despite rq_replay flag).
753 * Another reference for \var och.
758 spin_lock(&open_req->rq_lock);
761 mod->mod_open_req = open_req;
762 open_req->rq_cb_data = mod;
763 open_req->rq_commit_cb = mdc_commit_open;
764 spin_unlock(&open_req->rq_lock);
767 rec->cr_fid2 = body->fid1;
768 rec->cr_ioepoch = body->ioepoch;
769 rec->cr_old_handle.cookie = body->handle.cookie;
770 open_req->rq_replay_cb = mdc_replay_open;
771 if (!fid_is_sane(&body->fid1)) {
772 DEBUG_REQ(D_ERROR, open_req, "Saving replay request with "
777 DEBUG_REQ(D_RPCTRACE, open_req, "Set up open replay data");
781 int mdc_clear_open_replay_data(struct obd_export *exp,
782 struct obd_client_handle *och)
784 struct md_open_data *mod = och->och_mod;
788 * It is possible to not have \var mod in a case of eviction between
789 * lookup and ll_file_open().
794 LASSERT(mod != LP_POISON);
803 /* Prepares the request for the replay by the given reply */
804 static void mdc_close_handle_reply(struct ptlrpc_request *req,
805 struct md_op_data *op_data, int rc) {
806 struct mdt_body *repbody;
807 struct mdt_ioepoch *epoch;
809 if (req && rc == -EAGAIN) {
810 repbody = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
811 epoch = req_capsule_client_get(&req->rq_pill, &RMF_MDT_EPOCH);
813 epoch->flags |= MF_SOM_AU;
814 if (repbody->valid & OBD_MD_FLGETATTRLOCK)
815 op_data->op_flags |= MF_GETATTR_LOCK;
819 int mdc_close(struct obd_export *exp, struct md_op_data *op_data,
820 struct md_open_data *mod, struct ptlrpc_request **request)
822 struct obd_device *obd = class_exp2obd(exp);
823 struct ptlrpc_request *req;
828 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_CLOSE);
832 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
834 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_CLOSE);
836 ptlrpc_request_free(req);
840 /* To avoid a livelock (bug 7034), we need to send CLOSE RPCs to a
841 * portal whose threads are not taking any DLM locks and are therefore
842 * always progressing */
843 req->rq_request_portal = MDS_READPAGE_PORTAL;
844 ptlrpc_at_set_req_timeout(req);
846 /* Ensure that this close's handle is fixed up during replay. */
847 if (likely(mod != NULL)) {
848 LASSERTF(mod->mod_open_req != NULL &&
849 mod->mod_open_req->rq_type != LI_POISON,
850 "POISONED open %p!\n", mod->mod_open_req);
852 mod->mod_close_req = req;
854 DEBUG_REQ(D_HA, mod->mod_open_req, "matched open");
855 /* We no longer want to preserve this open for replay even
856 * though the open was committed. b=3632, b=3633 */
857 spin_lock(&mod->mod_open_req->rq_lock);
858 mod->mod_open_req->rq_replay = 0;
859 spin_unlock(&mod->mod_open_req->rq_lock);
861 CDEBUG(D_HA, "couldn't find open req; expecting close error\n");
864 mdc_close_pack(req, op_data);
866 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER,
867 obd->u.cli.cl_max_mds_easize);
868 req_capsule_set_size(&req->rq_pill, &RMF_LOGCOOKIES, RCL_SERVER,
869 obd->u.cli.cl_max_mds_cookiesize);
871 ptlrpc_request_set_replen(req);
873 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
874 rc = ptlrpc_queue_wait(req);
875 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
877 if (req->rq_repmsg == NULL) {
878 CDEBUG(D_RPCTRACE, "request failed to send: %p, %d\n", req,
881 rc = req->rq_status ?: -EIO;
882 } else if (rc == 0 || rc == -EAGAIN) {
883 struct mdt_body *body;
885 rc = lustre_msg_get_status(req->rq_repmsg);
886 if (lustre_msg_get_type(req->rq_repmsg) == PTL_RPC_MSG_ERR) {
887 DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, err "
892 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
895 } else if (rc == -ESTALE) {
897 * it can be allowed error after 3633 if open was committed and
898 * server failed before close was sent. Let's check if mod
899 * exists and return no error in that case
902 DEBUG_REQ(D_HA, req, "Reset ESTALE = %d", rc);
903 LASSERT(mod->mod_open_req != NULL);
904 if (mod->mod_open_req->rq_committed)
911 mod->mod_close_req = NULL;
912 /* Since now, mod is accessed through open_req only,
913 * thus close req does not keep a reference on mod anymore. */
917 mdc_close_handle_reply(req, op_data, rc);
921 int mdc_done_writing(struct obd_export *exp, struct md_op_data *op_data,
922 struct md_open_data *mod)
924 struct obd_device *obd = class_exp2obd(exp);
925 struct ptlrpc_request *req;
929 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
930 &RQF_MDS_DONE_WRITING);
934 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
935 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_DONE_WRITING);
937 ptlrpc_request_free(req);
942 LASSERTF(mod->mod_open_req != NULL &&
943 mod->mod_open_req->rq_type != LI_POISON,
944 "POISONED setattr %p!\n", mod->mod_open_req);
946 mod->mod_close_req = req;
947 DEBUG_REQ(D_HA, mod->mod_open_req, "matched setattr");
948 /* We no longer want to preserve this setattr for replay even
949 * though the open was committed. b=3632, b=3633 */
950 spin_lock(&mod->mod_open_req->rq_lock);
951 mod->mod_open_req->rq_replay = 0;
952 spin_unlock(&mod->mod_open_req->rq_lock);
955 mdc_close_pack(req, op_data);
956 ptlrpc_request_set_replen(req);
958 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
959 rc = ptlrpc_queue_wait(req);
960 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
964 * it can be allowed error after 3633 if open or setattr were
965 * committed and server failed before close was sent.
966 * Let's check if mod exists and return no error in that case
969 LASSERT(mod->mod_open_req != NULL);
970 if (mod->mod_open_req->rq_committed)
977 mod->mod_close_req = NULL;
978 /* Since now, mod is accessed through setattr req only,
979 * thus DW req does not keep a reference on mod anymore. */
983 mdc_close_handle_reply(req, op_data, rc);
984 ptlrpc_req_finished(req);
988 #ifdef HAVE_SPLIT_SUPPORT
989 int mdc_sendpage(struct obd_export *exp, const struct lu_fid *fid,
990 const struct page *page, int offset)
992 struct ptlrpc_request *req;
993 struct ptlrpc_bulk_desc *desc;
997 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_WRITEPAGE);
1001 /* FIXME: capa doesn't support split yet */
1002 mdc_set_capa_size(req, &RMF_CAPA1, NULL);
1004 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_WRITEPAGE);
1006 ptlrpc_request_free(req);
1010 req->rq_request_portal = MDS_READPAGE_PORTAL;
1011 ptlrpc_at_set_req_timeout(req);
1013 desc = ptlrpc_prep_bulk_imp(req, 1, 1,BULK_GET_SOURCE, MDS_BULK_PORTAL);
1015 GOTO(out, rc = -ENOMEM);
1017 /* NB req now owns desc and will free it when it gets freed. */
1018 ptlrpc_prep_bulk_page(desc, (struct page *)page, 0, offset);
1019 mdc_readdir_pack(req, 0, offset, fid, NULL);
1021 ptlrpc_request_set_replen(req);
1022 rc = ptlrpc_queue_wait(req);
1026 rc = sptlrpc_cli_unwrap_bulk_write(req, req->rq_bulk);
1028 ptlrpc_req_finished(req);
1031 EXPORT_SYMBOL(mdc_sendpage);
1034 int mdc_readpage(struct obd_export *exp, struct md_op_data *op_data,
1035 struct page **pages, struct ptlrpc_request **request)
1037 struct ptlrpc_request *req;
1038 struct ptlrpc_bulk_desc *desc;
1042 struct l_wait_info lwi;
1047 cfs_waitq_init(&waitq);
1050 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_READPAGE);
1054 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
1056 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_READPAGE);
1058 ptlrpc_request_free(req);
1062 req->rq_request_portal = MDS_READPAGE_PORTAL;
1063 ptlrpc_at_set_req_timeout(req);
1065 desc = ptlrpc_prep_bulk_imp(req, op_data->op_npages, 1, BULK_PUT_SINK,
1068 ptlrpc_request_free(req);
1072 /* NB req now owns desc and will free it when it gets freed */
1073 for (i = 0; i < op_data->op_npages; i++)
1074 ptlrpc_prep_bulk_page_pin(desc, pages[i], 0, CFS_PAGE_SIZE);
1076 mdc_readdir_pack(req, op_data->op_offset,
1077 CFS_PAGE_SIZE * op_data->op_npages,
1078 &op_data->op_fid1, op_data->op_capa1);
1080 ptlrpc_request_set_replen(req);
1081 rc = ptlrpc_queue_wait(req);
1083 ptlrpc_req_finished(req);
1084 if (rc != -ETIMEDOUT)
1088 if (!client_should_resend(resends, &exp->exp_obd->u.cli)) {
1089 CERROR("too many resend retries, returning error\n");
1092 lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(resends), NULL, NULL, NULL);
1093 l_wait_event(waitq, 0, &lwi);
1098 rc = sptlrpc_cli_unwrap_bulk_read(req, req->rq_bulk,
1099 req->rq_bulk->bd_nob_transferred);
1101 ptlrpc_req_finished(req);
1105 if (req->rq_bulk->bd_nob_transferred & ~LU_PAGE_MASK) {
1106 CERROR("Unexpected # bytes transferred: %d (%ld expected)\n",
1107 req->rq_bulk->bd_nob_transferred,
1108 CFS_PAGE_SIZE * op_data->op_npages);
1109 ptlrpc_req_finished(req);
1117 static int mdc_statfs(const struct lu_env *env,
1118 struct obd_export *exp, struct obd_statfs *osfs,
1119 __u64 max_age, __u32 flags)
1121 struct obd_device *obd = class_exp2obd(exp);
1122 struct ptlrpc_request *req;
1123 struct obd_statfs *msfs;
1124 struct obd_import *imp = NULL;
1129 * Since the request might also come from lprocfs, so we need
1130 * sync this with client_disconnect_export Bug15684
1132 down_read(&obd->u.cli.cl_sem);
1133 if (obd->u.cli.cl_import)
1134 imp = class_import_get(obd->u.cli.cl_import);
1135 up_read(&obd->u.cli.cl_sem);
1139 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_STATFS,
1140 LUSTRE_MDS_VERSION, MDS_STATFS);
1142 GOTO(output, rc = -ENOMEM);
1144 ptlrpc_request_set_replen(req);
1146 if (flags & OBD_STATFS_NODELAY) {
1147 /* procfs requests not want stay in wait for avoid deadlock */
1148 req->rq_no_resend = 1;
1149 req->rq_no_delay = 1;
1152 rc = ptlrpc_queue_wait(req);
1154 /* check connection error first */
1155 if (imp->imp_connect_error)
1156 rc = imp->imp_connect_error;
1160 msfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
1162 GOTO(out, rc = -EPROTO);
1167 ptlrpc_req_finished(req);
1169 class_import_put(imp);
1173 static int mdc_ioc_fid2path(struct obd_export *exp, struct getinfo_fid2path *gf)
1175 __u32 keylen, vallen;
1179 if (gf->gf_pathlen > PATH_MAX)
1180 RETURN(-ENAMETOOLONG);
1181 if (gf->gf_pathlen < 2)
1184 /* Key is KEY_FID2PATH + getinfo_fid2path description */
1185 keylen = cfs_size_round(sizeof(KEY_FID2PATH)) + sizeof(*gf);
1186 OBD_ALLOC(key, keylen);
1189 memcpy(key, KEY_FID2PATH, sizeof(KEY_FID2PATH));
1190 memcpy(key + cfs_size_round(sizeof(KEY_FID2PATH)), gf, sizeof(*gf));
1192 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
1193 PFID(&gf->gf_fid), gf->gf_recno, gf->gf_linkno);
1195 if (!fid_is_sane(&gf->gf_fid))
1196 GOTO(out, rc = -EINVAL);
1198 /* Val is struct getinfo_fid2path result plus path */
1199 vallen = sizeof(*gf) + gf->gf_pathlen;
1201 rc = obd_get_info(NULL, exp, keylen, key, &vallen, gf, NULL);
1202 if (rc != 0 && rc != -EREMOTE)
1205 if (vallen <= sizeof(*gf))
1206 GOTO(out, rc = -EPROTO);
1207 else if (vallen > sizeof(*gf) + gf->gf_pathlen)
1208 GOTO(out, rc = -EOVERFLOW);
1210 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n%s\n",
1211 PFID(&gf->gf_fid), gf->gf_recno, gf->gf_linkno, gf->gf_path);
1214 OBD_FREE(key, keylen);
1218 static int mdc_ioc_hsm_progress(struct obd_export *exp,
1219 struct hsm_progress_kernel *hpk)
1221 struct obd_import *imp = class_exp2cliimp(exp);
1222 struct hsm_progress_kernel *req_hpk;
1223 struct ptlrpc_request *req;
1227 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_HSM_PROGRESS,
1228 LUSTRE_MDS_VERSION, MDS_HSM_PROGRESS);
1230 GOTO(out, rc = -ENOMEM);
1232 /* Copy hsm_progress struct */
1233 req_hpk = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_PROGRESS);
1237 ptlrpc_request_set_replen(req);
1239 rc = mdc_queue_wait(req);
1242 ptlrpc_req_finished(req);
1246 static int mdc_ioc_hsm_ct_register(struct obd_import *imp, __u32 archives)
1248 __u32 *archive_mask;
1249 struct ptlrpc_request *req;
1253 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_HSM_CT_REGISTER,
1255 MDS_HSM_CT_REGISTER);
1257 GOTO(out, rc = -ENOMEM);
1259 /* Copy hsm_progress struct */
1260 archive_mask = req_capsule_client_get(&req->rq_pill,
1261 &RMF_MDS_HSM_ARCHIVE);
1262 LASSERT(archive_mask);
1263 *archive_mask = archives;
1265 ptlrpc_request_set_replen(req);
1267 rc = mdc_queue_wait(req);
1270 ptlrpc_req_finished(req);
1274 static int mdc_ioc_hsm_current_action(struct obd_export *exp,
1275 struct md_op_data *op_data)
1277 struct hsm_current_action *hca = op_data->op_data;
1278 struct hsm_current_action *req_hca;
1279 struct ptlrpc_request *req;
1283 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
1284 &RQF_MDS_HSM_ACTION);
1288 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
1290 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_ACTION);
1292 ptlrpc_request_free(req);
1296 mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
1297 OBD_MD_FLRMTPERM, 0, op_data->op_suppgids[0], 0);
1299 ptlrpc_request_set_replen(req);
1301 rc = mdc_queue_wait(req);
1305 req_hca = req_capsule_server_get(&req->rq_pill,
1306 &RMF_MDS_HSM_CURRENT_ACTION);
1307 if (req_hca == NULL)
1308 GOTO(out, rc = -EPROTO);
1314 ptlrpc_req_finished(req);
1318 static int mdc_ioc_hsm_ct_unregister(struct obd_import *imp)
1320 struct ptlrpc_request *req;
1324 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_HSM_CT_UNREGISTER,
1326 MDS_HSM_CT_UNREGISTER);
1328 GOTO(out, rc = -ENOMEM);
1330 ptlrpc_request_set_replen(req);
1332 rc = mdc_queue_wait(req);
1335 ptlrpc_req_finished(req);
1339 static int mdc_ioc_hsm_state_get(struct obd_export *exp,
1340 struct md_op_data *op_data)
1342 struct hsm_user_state *hus = op_data->op_data;
1343 struct hsm_user_state *req_hus;
1344 struct ptlrpc_request *req;
1348 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
1349 &RQF_MDS_HSM_STATE_GET);
1353 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
1355 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_STATE_GET);
1357 ptlrpc_request_free(req);
1361 mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
1362 OBD_MD_FLRMTPERM, 0, op_data->op_suppgids[0], 0);
1364 ptlrpc_request_set_replen(req);
1366 rc = mdc_queue_wait(req);
1370 req_hus = req_capsule_server_get(&req->rq_pill, &RMF_HSM_USER_STATE);
1371 if (req_hus == NULL)
1372 GOTO(out, rc = -EPROTO);
1378 ptlrpc_req_finished(req);
1382 static int mdc_ioc_hsm_state_set(struct obd_export *exp,
1383 struct md_op_data *op_data)
1385 struct hsm_state_set *hss = op_data->op_data;
1386 struct hsm_state_set *req_hss;
1387 struct ptlrpc_request *req;
1391 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
1392 &RQF_MDS_HSM_STATE_SET);
1396 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
1398 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_STATE_SET);
1400 ptlrpc_request_free(req);
1404 mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
1405 OBD_MD_FLRMTPERM, 0, op_data->op_suppgids[0], 0);
1408 req_hss = req_capsule_client_get(&req->rq_pill, &RMF_HSM_STATE_SET);
1412 ptlrpc_request_set_replen(req);
1414 rc = mdc_queue_wait(req);
1419 ptlrpc_req_finished(req);
1423 static int mdc_ioc_hsm_request(struct obd_export *exp,
1424 struct hsm_user_request *hur)
1426 struct obd_import *imp = class_exp2cliimp(exp);
1427 struct ptlrpc_request *req;
1428 struct hsm_request *req_hr;
1429 struct hsm_user_item *req_hui;
1434 req = ptlrpc_request_alloc(imp, &RQF_MDS_HSM_REQUEST);
1436 GOTO(out, rc = -ENOMEM);
1438 req_capsule_set_size(&req->rq_pill, &RMF_MDS_HSM_USER_ITEM, RCL_CLIENT,
1439 hur->hur_request.hr_itemcount
1440 * sizeof(struct hsm_user_item));
1441 req_capsule_set_size(&req->rq_pill, &RMF_GENERIC_DATA, RCL_CLIENT,
1442 hur->hur_request.hr_data_len);
1444 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_REQUEST);
1446 ptlrpc_request_free(req);
1450 mdc_pack_body(req, NULL, NULL, OBD_MD_FLRMTPERM, 0, 0, 0);
1452 /* Copy hsm_request struct */
1453 req_hr = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_REQUEST);
1455 *req_hr = hur->hur_request;
1457 /* Copy hsm_user_item structs */
1458 req_hui = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_USER_ITEM);
1460 memcpy(req_hui, hur->hur_user_item,
1461 hur->hur_request.hr_itemcount * sizeof(struct hsm_user_item));
1463 /* Copy opaque field */
1464 req_opaque = req_capsule_client_get(&req->rq_pill, &RMF_GENERIC_DATA);
1465 LASSERT(req_opaque);
1466 memcpy(req_opaque, hur_data(hur), hur->hur_request.hr_data_len);
1468 ptlrpc_request_set_replen(req);
1470 rc = mdc_queue_wait(req);
1474 ptlrpc_req_finished(req);
1478 static struct kuc_hdr *changelog_kuc_hdr(char *buf, int len, int flags)
1480 struct kuc_hdr *lh = (struct kuc_hdr *)buf;
1482 LASSERT(len <= CR_MAXSIZE);
1484 lh->kuc_magic = KUC_MAGIC;
1485 lh->kuc_transport = KUC_TRANSPORT_CHANGELOG;
1486 lh->kuc_flags = flags;
1487 lh->kuc_msgtype = CL_RECORD;
1488 lh->kuc_msglen = len;
1492 #define D_CHANGELOG 0
1494 struct changelog_show {
1499 struct obd_device *cs_obd;
1502 static int changelog_show_cb(const struct lu_env *env, struct llog_handle *llh,
1503 struct llog_rec_hdr *hdr, void *data)
1505 struct changelog_show *cs = data;
1506 struct llog_changelog_rec *rec = (struct llog_changelog_rec *)hdr;
1511 if ((rec->cr_hdr.lrh_type != CHANGELOG_REC) ||
1512 (rec->cr.cr_type >= CL_LAST)) {
1513 CERROR("Not a changelog rec %d/%d\n", rec->cr_hdr.lrh_type,
1518 if (rec->cr.cr_index < cs->cs_startrec) {
1519 /* Skip entries earlier than what we are interested in */
1520 CDEBUG(D_CHANGELOG, "rec="LPU64" start="LPU64"\n",
1521 rec->cr.cr_index, cs->cs_startrec);
1525 CDEBUG(D_CHANGELOG, LPU64" %02d%-5s "LPU64" 0x%x t="DFID" p="DFID
1526 " %.*s\n", rec->cr.cr_index, rec->cr.cr_type,
1527 changelog_type2str(rec->cr.cr_type), rec->cr.cr_time,
1528 rec->cr.cr_flags & CLF_FLAGMASK,
1529 PFID(&rec->cr.cr_tfid), PFID(&rec->cr.cr_pfid),
1530 rec->cr.cr_namelen, changelog_rec_name(&rec->cr));
1532 len = sizeof(*lh) + changelog_rec_size(&rec->cr) + rec->cr.cr_namelen;
1534 /* Set up the message */
1535 lh = changelog_kuc_hdr(cs->cs_buf, len, cs->cs_flags);
1536 memcpy(lh + 1, &rec->cr, len - sizeof(*lh));
1538 rc = libcfs_kkuc_msg_put(cs->cs_fp, lh);
1539 CDEBUG(D_CHANGELOG, "kucmsg fp %p len %d rc %d\n", cs->cs_fp, len,rc);
1544 static int mdc_changelog_send_thread(void *csdata)
1546 struct changelog_show *cs = csdata;
1547 struct llog_ctxt *ctxt = NULL;
1548 struct llog_handle *llh = NULL;
1549 struct kuc_hdr *kuch;
1552 CDEBUG(D_CHANGELOG, "changelog to fp=%p start "LPU64"\n",
1553 cs->cs_fp, cs->cs_startrec);
1556 * It's important to daemonize here to close unused FDs.
1557 * The write fd from pipe is already opened by the caller,
1558 * so it's fine to clear all files here
1560 cfs_daemonize("mdc_clg_send_thread");
1562 OBD_ALLOC(cs->cs_buf, CR_MAXSIZE);
1563 if (cs->cs_buf == NULL)
1564 GOTO(out, rc = -ENOMEM);
1566 /* Set up the remote catalog handle */
1567 ctxt = llog_get_context(cs->cs_obd, LLOG_CHANGELOG_REPL_CTXT);
1569 GOTO(out, rc = -ENOENT);
1570 rc = llog_open(NULL, ctxt, &llh, NULL, CHANGELOG_CATALOG,
1573 CERROR("%s: fail to open changelog catalog: rc = %d\n",
1574 cs->cs_obd->obd_name, rc);
1577 rc = llog_init_handle(NULL, llh, LLOG_F_IS_CAT, NULL);
1579 CERROR("llog_init_handle failed %d\n", rc);
1583 rc = llog_cat_process(NULL, llh, changelog_show_cb, cs, 0, 0);
1585 /* Send EOF no matter what our result */
1586 if ((kuch = changelog_kuc_hdr(cs->cs_buf, sizeof(*kuch),
1588 kuch->kuc_msgtype = CL_EOF;
1589 libcfs_kkuc_msg_put(cs->cs_fp, kuch);
1595 llog_cat_close(NULL, llh);
1597 llog_ctxt_put(ctxt);
1599 OBD_FREE(cs->cs_buf, CR_MAXSIZE);
1601 /* detach from parent process so we get cleaned up */
1602 cfs_daemonize("cl_send");
1606 static int mdc_ioc_changelog_send(struct obd_device *obd,
1607 struct ioc_changelog *icc)
1609 struct changelog_show *cs;
1612 /* Freed in mdc_changelog_send_thread */
1618 cs->cs_startrec = icc->icc_recno;
1619 /* matching fput in mdc_changelog_send_thread */
1620 cs->cs_fp = fget(icc->icc_id);
1621 cs->cs_flags = icc->icc_flags;
1623 /* New thread because we should return to user app before
1624 writing into our pipe */
1625 rc = cfs_create_thread(mdc_changelog_send_thread, cs, CFS_DAEMON_FLAGS);
1627 CDEBUG(D_CHANGELOG, "start changelog thread: %d\n", rc);
1631 CERROR("Failed to start changelog thread: %d\n", rc);
1636 static int mdc_ioc_hsm_ct_start(struct obd_export *exp,
1637 struct lustre_kernelcomm *lk);
1639 static int mdc_quotacheck(struct obd_device *unused, struct obd_export *exp,
1640 struct obd_quotactl *oqctl)
1642 struct client_obd *cli = &exp->exp_obd->u.cli;
1643 struct ptlrpc_request *req;
1644 struct obd_quotactl *body;
1648 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
1649 &RQF_MDS_QUOTACHECK, LUSTRE_MDS_VERSION,
1654 body = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1657 ptlrpc_request_set_replen(req);
1659 /* the next poll will find -ENODATA, that means quotacheck is
1661 cli->cl_qchk_stat = -ENODATA;
1662 rc = ptlrpc_queue_wait(req);
1664 cli->cl_qchk_stat = rc;
1665 ptlrpc_req_finished(req);
1669 static int mdc_quota_poll_check(struct obd_export *exp,
1670 struct if_quotacheck *qchk)
1672 struct client_obd *cli = &exp->exp_obd->u.cli;
1676 qchk->obd_uuid = cli->cl_target_uuid;
1677 memcpy(qchk->obd_type, LUSTRE_MDS_NAME, strlen(LUSTRE_MDS_NAME));
1679 rc = cli->cl_qchk_stat;
1680 /* the client is not the previous one */
1681 if (rc == CL_NOT_QUOTACHECKED)
1686 static int mdc_quotactl(struct obd_device *unused, struct obd_export *exp,
1687 struct obd_quotactl *oqctl)
1689 struct ptlrpc_request *req;
1690 struct obd_quotactl *oqc;
1694 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
1695 &RQF_MDS_QUOTACTL, LUSTRE_MDS_VERSION,
1700 oqc = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1703 ptlrpc_request_set_replen(req);
1704 ptlrpc_at_set_req_timeout(req);
1705 req->rq_no_resend = 1;
1707 rc = ptlrpc_queue_wait(req);
1709 CERROR("ptlrpc_queue_wait failed, rc: %d\n", rc);
1711 if (req->rq_repmsg &&
1712 (oqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL))) {
1715 CERROR ("Can't unpack obd_quotactl\n");
1718 ptlrpc_req_finished(req);
1723 static int mdc_ioc_swap_layouts(struct obd_export *exp,
1724 struct md_op_data *op_data)
1726 CFS_LIST_HEAD(cancels);
1727 struct ptlrpc_request *req;
1729 struct mdc_swap_layouts *msl, *payload;
1732 msl = op_data->op_data;
1734 /* When the MDT will get the MDS_SWAP_LAYOUTS RPC the
1735 * first thing it will do is to cancel the 2 layout
1736 * locks hold by this client.
1737 * So the client must cancel its layout locks on the 2 fids
1738 * with the request RPC to avoid extra RPC round trips
1740 count = mdc_resource_get_unused(exp, &op_data->op_fid1, &cancels,
1741 LCK_CR, MDS_INODELOCK_LAYOUT);
1742 count += mdc_resource_get_unused(exp, &op_data->op_fid2, &cancels,
1743 LCK_CR, MDS_INODELOCK_LAYOUT);
1745 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
1746 &RQF_MDS_SWAP_LAYOUTS);
1748 ldlm_lock_list_put(&cancels, l_bl_ast, count);
1752 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
1753 mdc_set_capa_size(req, &RMF_CAPA2, op_data->op_capa2);
1755 rc = mdc_prep_elc_req(exp, req, MDS_SWAP_LAYOUTS, &cancels, count);
1757 ptlrpc_request_free(req);
1761 mdc_swap_layouts_pack(req, op_data);
1763 payload = req_capsule_client_get(&req->rq_pill, &RMF_SWAP_LAYOUTS);
1768 ptlrpc_request_set_replen(req);
1770 rc = ptlrpc_queue_wait(req);
1776 ptlrpc_req_finished(req);
1780 static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1781 void *karg, void *uarg)
1783 struct obd_device *obd = exp->exp_obd;
1784 struct obd_ioctl_data *data = karg;
1785 struct obd_import *imp = obd->u.cli.cl_import;
1786 struct llog_ctxt *ctxt;
1790 if (!cfs_try_module_get(THIS_MODULE)) {
1791 CERROR("Can't get module. Is it alive?");
1795 case OBD_IOC_CHANGELOG_SEND:
1796 rc = mdc_ioc_changelog_send(obd, karg);
1798 case OBD_IOC_CHANGELOG_CLEAR: {
1799 struct ioc_changelog *icc = karg;
1800 struct changelog_setinfo cs =
1801 {.cs_recno = icc->icc_recno, .cs_id = icc->icc_id};
1802 rc = obd_set_info_async(NULL, exp, strlen(KEY_CHANGELOG_CLEAR),
1803 KEY_CHANGELOG_CLEAR, sizeof(cs), &cs,
1807 case OBD_IOC_FID2PATH:
1808 rc = mdc_ioc_fid2path(exp, karg);
1810 case LL_IOC_HSM_CT_START:
1811 rc = mdc_ioc_hsm_ct_start(exp, karg);
1813 case LL_IOC_HSM_PROGRESS:
1814 rc = mdc_ioc_hsm_progress(exp, karg);
1816 case LL_IOC_HSM_STATE_GET:
1817 rc = mdc_ioc_hsm_state_get(exp, karg);
1819 case LL_IOC_HSM_STATE_SET:
1820 rc = mdc_ioc_hsm_state_set(exp, karg);
1821 case LL_IOC_HSM_ACTION:
1822 rc = mdc_ioc_hsm_current_action(exp, karg);
1824 case LL_IOC_HSM_REQUEST:
1825 rc = mdc_ioc_hsm_request(exp, karg);
1827 case OBD_IOC_CLIENT_RECOVER:
1828 rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1, 0);
1832 case IOC_OSC_SET_ACTIVE:
1833 rc = ptlrpc_set_import_active(imp, data->ioc_offset);
1835 case OBD_IOC_PARSE: {
1836 ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT);
1837 rc = class_config_parse_llog(NULL, ctxt, data->ioc_inlbuf1,
1839 llog_ctxt_put(ctxt);
1843 case OBD_IOC_LLOG_INFO:
1844 case OBD_IOC_LLOG_PRINT: {
1845 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
1846 rc = llog_ioctl(NULL, ctxt, cmd, data);
1847 llog_ctxt_put(ctxt);
1851 case OBD_IOC_POLL_QUOTACHECK:
1852 rc = mdc_quota_poll_check(exp, (struct if_quotacheck *)karg);
1854 case OBD_IOC_PING_TARGET:
1855 rc = ptlrpc_obd_ping(obd);
1858 * Normally IOC_OBD_STATFS, OBD_IOC_QUOTACTL iocontrol are handled by
1859 * LMV instead of MDC. But when the cluster is upgraded from 1.8,
1860 * there'd be no LMV layer thus we might be called here. Eventually
1861 * this code should be removed.
1864 case IOC_OBD_STATFS: {
1865 struct obd_statfs stat_buf = {0};
1867 if (*((__u32 *) data->ioc_inlbuf2) != 0)
1868 GOTO(out, rc = -ENODEV);
1871 if (cfs_copy_to_user(data->ioc_pbuf2, obd2cli_tgt(obd),
1872 min((int) data->ioc_plen2,
1873 (int) sizeof(struct obd_uuid))))
1874 GOTO(out, rc = -EFAULT);
1876 rc = mdc_statfs(NULL, obd->obd_self_export, &stat_buf,
1877 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1882 if (cfs_copy_to_user(data->ioc_pbuf1, &stat_buf,
1883 min((int) data->ioc_plen1,
1884 (int) sizeof(stat_buf))))
1885 GOTO(out, rc = -EFAULT);
1889 case OBD_IOC_QUOTACTL: {
1890 struct if_quotactl *qctl = karg;
1891 struct obd_quotactl *oqctl;
1893 OBD_ALLOC_PTR(oqctl);
1897 QCTL_COPY(oqctl, qctl);
1898 rc = obd_quotactl(exp, oqctl);
1900 QCTL_COPY(qctl, oqctl);
1901 qctl->qc_valid = QC_MDTIDX;
1902 qctl->obd_uuid = obd->u.cli.cl_target_uuid;
1904 OBD_FREE_PTR(oqctl);
1907 case LL_IOC_GET_CONNECT_FLAGS: {
1908 if (cfs_copy_to_user(uarg,
1909 exp_connect_flags_ptr(exp),
1911 GOTO(out, rc = -EFAULT);
1915 case LL_IOC_LOV_SWAP_LAYOUTS: {
1916 rc = mdc_ioc_swap_layouts(exp, karg);
1920 CERROR("mdc_ioctl(): unrecognised ioctl %#x\n", cmd);
1921 GOTO(out, rc = -ENOTTY);
1924 cfs_module_put(THIS_MODULE);
1929 int mdc_get_info_rpc(struct obd_export *exp,
1930 obd_count keylen, void *key,
1931 int vallen, void *val)
1933 struct obd_import *imp = class_exp2cliimp(exp);
1934 struct ptlrpc_request *req;
1939 req = ptlrpc_request_alloc(imp, &RQF_MDS_GET_INFO);
1943 req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_KEY,
1944 RCL_CLIENT, keylen);
1945 req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_VALLEN,
1946 RCL_CLIENT, sizeof(__u32));
1948 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GET_INFO);
1950 ptlrpc_request_free(req);
1954 tmp = req_capsule_client_get(&req->rq_pill, &RMF_GETINFO_KEY);
1955 memcpy(tmp, key, keylen);
1956 tmp = req_capsule_client_get(&req->rq_pill, &RMF_GETINFO_VALLEN);
1957 memcpy(tmp, &vallen, sizeof(__u32));
1959 req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_VAL,
1960 RCL_SERVER, vallen);
1961 ptlrpc_request_set_replen(req);
1963 rc = ptlrpc_queue_wait(req);
1964 /* -EREMOTE means the get_info result is partial, and it needs to
1965 * continue on another MDT, see fid2path part in lmv_iocontrol */
1966 if (rc == 0 || rc == -EREMOTE) {
1967 tmp = req_capsule_server_get(&req->rq_pill, &RMF_GETINFO_VAL);
1968 memcpy(val, tmp, vallen);
1969 if (ptlrpc_rep_need_swab(req)) {
1970 if (KEY_IS(KEY_FID2PATH))
1971 lustre_swab_fid2path(val);
1974 ptlrpc_req_finished(req);
1979 static void lustre_swab_hai(struct hsm_action_item *h)
1981 __swab32s(&h->hai_len);
1982 __swab32s(&h->hai_action);
1983 lustre_swab_lu_fid(&h->hai_fid);
1984 lustre_swab_lu_fid(&h->hai_dfid);
1985 __swab64s(&h->hai_cookie);
1986 __swab64s(&h->hai_extent.offset);
1987 __swab64s(&h->hai_extent.length);
1988 __swab64s(&h->hai_gid);
1991 static void lustre_swab_hal(struct hsm_action_list *h)
1993 struct hsm_action_item *hai;
1996 __swab32s(&h->hal_version);
1997 __swab32s(&h->hal_count);
1998 __swab32s(&h->hal_archive_id);
1999 __swab64s(&h->hal_flags);
2001 for (i = 0; i < h->hal_count; i++) {
2002 lustre_swab_hai(hai);
2003 hai = hai_next(hai);
2007 static void lustre_swab_kuch(struct kuc_hdr *l)
2009 __swab16s(&l->kuc_magic);
2010 /* __u8 l->kuc_transport */
2011 __swab16s(&l->kuc_msgtype);
2012 __swab16s(&l->kuc_msglen);
2015 static int mdc_ioc_hsm_ct_start(struct obd_export *exp,
2016 struct lustre_kernelcomm *lk)
2018 struct obd_import *imp = class_exp2cliimp(exp);
2019 __u32 archive = lk->lk_data;
2022 if (lk->lk_group != KUC_GRP_HSM) {
2023 CERROR("Bad copytool group %d\n", lk->lk_group);
2027 CDEBUG(D_HSM, "CT start r%d w%d u%d g%d f%#x\n", lk->lk_rfd, lk->lk_wfd,
2028 lk->lk_uid, lk->lk_group, lk->lk_flags);
2030 if (lk->lk_flags & LK_FLG_STOP) {
2031 rc = libcfs_kkuc_group_rem(lk->lk_uid, lk->lk_group);
2032 /* Unregister with the coordinator */
2034 rc = mdc_ioc_hsm_ct_unregister(imp);
2036 struct file *fp = fget(lk->lk_wfd);
2038 rc = libcfs_kkuc_group_add(fp, lk->lk_uid, lk->lk_group,
2043 rc = mdc_ioc_hsm_ct_register(imp, archive);
2050 * Send a message to any listening copytools
2051 * @param val KUC message (kuc_hdr + hsm_action_list)
2052 * @param len total length of message
2054 static int mdc_hsm_copytool_send(int len, void *val)
2056 struct kuc_hdr *lh = (struct kuc_hdr *)val;
2057 struct hsm_action_list *hal = (struct hsm_action_list *)(lh + 1);
2061 if (len < sizeof(*lh) + sizeof(*hal)) {
2062 CERROR("Short HSM message %d < %d\n", len,
2063 (int) (sizeof(*lh) + sizeof(*hal)));
2066 if (lh->kuc_magic == __swab16(KUC_MAGIC)) {
2067 lustre_swab_kuch(lh);
2068 lustre_swab_hal(hal);
2069 } else if (lh->kuc_magic != KUC_MAGIC) {
2070 CERROR("Bad magic %x!=%x\n", lh->kuc_magic, KUC_MAGIC);
2074 CDEBUG(D_HSM, " Received message mg=%x t=%d m=%d l=%d actions=%d "
2076 lh->kuc_magic, lh->kuc_transport, lh->kuc_msgtype,
2077 lh->kuc_msglen, hal->hal_count, hal->hal_fsname);
2079 /* Broadcast to HSM listeners */
2080 rc = libcfs_kkuc_group_put(KUC_GRP_HSM, lh);
2086 * callback function passed to kuc for re-registering each HSM copytool
2087 * running on MDC, after MDT shutdown/recovery.
2088 * @param data archive id served by the copytool
2089 * @param cb_arg callback argument (obd_import)
2091 static int mdc_hsm_ct_reregister(__u32 data, void *cb_arg)
2093 struct obd_import *imp = (struct obd_import *)cb_arg;
2094 __u32 archive = data;
2097 CDEBUG(D_HA, "recover copytool registration to MDT (archive=%#x)\n",
2099 rc = mdc_ioc_hsm_ct_register(imp, archive);
2101 /* ignore error if the copytool is already registered */
2102 return ((rc != 0) && (rc != -EEXIST)) ? rc : 0;
2106 * Re-establish all kuc contexts with MDT
2107 * after MDT shutdown/recovery.
2109 static int mdc_kuc_reregister(struct obd_import *imp)
2111 /* re-register HSM agents */
2112 return libcfs_kkuc_group_foreach(KUC_GRP_HSM, mdc_hsm_ct_reregister,
2116 int mdc_set_info_async(const struct lu_env *env,
2117 struct obd_export *exp,
2118 obd_count keylen, void *key,
2119 obd_count vallen, void *val,
2120 struct ptlrpc_request_set *set)
2122 struct obd_import *imp = class_exp2cliimp(exp);
2126 if (KEY_IS(KEY_READ_ONLY)) {
2127 if (vallen != sizeof(int))
2130 spin_lock(&imp->imp_lock);
2131 if (*((int *)val)) {
2132 imp->imp_connect_flags_orig |= OBD_CONNECT_RDONLY;
2133 imp->imp_connect_data.ocd_connect_flags |=
2136 imp->imp_connect_flags_orig &= ~OBD_CONNECT_RDONLY;
2137 imp->imp_connect_data.ocd_connect_flags &=
2138 ~OBD_CONNECT_RDONLY;
2140 spin_unlock(&imp->imp_lock);
2142 rc = do_set_info_async(imp, MDS_SET_INFO, LUSTRE_MDS_VERSION,
2143 keylen, key, vallen, val, set);
2146 if (KEY_IS(KEY_SPTLRPC_CONF)) {
2147 sptlrpc_conf_client_adapt(exp->exp_obd);
2150 if (KEY_IS(KEY_FLUSH_CTX)) {
2151 sptlrpc_import_flush_my_ctx(imp);
2154 if (KEY_IS(KEY_MDS_CONN)) {
2155 /* mds-mds import */
2156 spin_lock(&imp->imp_lock);
2157 imp->imp_server_timeout = 1;
2158 spin_unlock(&imp->imp_lock);
2159 imp->imp_client->cli_request_portal = MDS_MDS_PORTAL;
2160 CDEBUG(D_OTHER, "%s: timeout / 2\n", exp->exp_obd->obd_name);
2163 if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
2164 rc = do_set_info_async(imp, MDS_SET_INFO, LUSTRE_MDS_VERSION,
2165 keylen, key, vallen, val, set);
2168 if (KEY_IS(KEY_HSM_COPYTOOL_SEND)) {
2169 rc = mdc_hsm_copytool_send(vallen, val);
2173 CERROR("Unknown key %s\n", (char *)key);
2177 int mdc_get_info(const struct lu_env *env, struct obd_export *exp,
2178 __u32 keylen, void *key, __u32 *vallen, void *val,
2179 struct lov_stripe_md *lsm)
2183 if (KEY_IS(KEY_MAX_EASIZE)) {
2184 int mdsize, *max_easize;
2186 if (*vallen != sizeof(int))
2188 mdsize = *(int*)val;
2189 if (mdsize > exp->exp_obd->u.cli.cl_max_mds_easize)
2190 exp->exp_obd->u.cli.cl_max_mds_easize = mdsize;
2192 *max_easize = exp->exp_obd->u.cli.cl_max_mds_easize;
2194 } else if (KEY_IS(KEY_CONN_DATA)) {
2195 struct obd_import *imp = class_exp2cliimp(exp);
2196 struct obd_connect_data *data = val;
2198 if (*vallen != sizeof(*data))
2201 *data = imp->imp_connect_data;
2203 } else if (KEY_IS(KEY_TGT_COUNT)) {
2208 rc = mdc_get_info_rpc(exp, keylen, key, *vallen, val);
2213 static int mdc_pin(struct obd_export *exp, const struct lu_fid *fid,
2214 struct obd_capa *oc, struct obd_client_handle *handle,
2217 struct ptlrpc_request *req;
2218 struct mdt_body *body;
2222 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_PIN);
2226 mdc_set_capa_size(req, &RMF_CAPA1, oc);
2228 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_PIN);
2230 ptlrpc_request_free(req);
2234 mdc_pack_body(req, fid, oc, 0, 0, -1, flags);
2236 ptlrpc_request_set_replen(req);
2238 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
2239 rc = ptlrpc_queue_wait(req);
2240 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
2242 CERROR("Pin failed: %d\n", rc);
2246 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
2248 GOTO(err_out, rc = -EPROTO);
2250 handle->och_fh = body->handle;
2251 handle->och_magic = OBD_CLIENT_HANDLE_MAGIC;
2253 handle->och_mod = obd_mod_alloc();
2254 if (handle->och_mod == NULL) {
2255 DEBUG_REQ(D_ERROR, req, "can't allocate md_open_data");
2256 GOTO(err_out, rc = -ENOMEM);
2258 handle->och_mod->mod_open_req = req; /* will be dropped by unpin */
2263 ptlrpc_req_finished(req);
2267 static int mdc_unpin(struct obd_export *exp, struct obd_client_handle *handle,
2270 struct ptlrpc_request *req;
2271 struct mdt_body *body;
2275 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_UNPIN,
2276 LUSTRE_MDS_VERSION, MDS_UNPIN);
2280 body = req_capsule_client_get(&req->rq_pill, &RMF_MDT_BODY);
2281 body->handle = handle->och_fh;
2284 ptlrpc_request_set_replen(req);
2286 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
2287 rc = ptlrpc_queue_wait(req);
2288 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
2291 CERROR("Unpin failed: %d\n", rc);
2293 ptlrpc_req_finished(req);
2294 ptlrpc_req_finished(handle->och_mod->mod_open_req);
2296 obd_mod_put(handle->och_mod);
2300 int mdc_sync(struct obd_export *exp, const struct lu_fid *fid,
2301 struct obd_capa *oc, struct ptlrpc_request **request)
2303 struct ptlrpc_request *req;
2308 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_SYNC);
2312 mdc_set_capa_size(req, &RMF_CAPA1, oc);
2314 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_SYNC);
2316 ptlrpc_request_free(req);
2320 mdc_pack_body(req, fid, oc, 0, 0, -1, 0);
2322 ptlrpc_request_set_replen(req);
2324 rc = ptlrpc_queue_wait(req);
2326 ptlrpc_req_finished(req);
2332 static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
2333 enum obd_import_event event)
2337 LASSERT(imp->imp_obd == obd);
2340 case IMP_EVENT_DISCON: {
2342 /* XXX Pass event up to OBDs stack. used only for FLD now */
2343 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_DISCON, NULL);
2347 case IMP_EVENT_INACTIVE: {
2348 struct client_obd *cli = &obd->u.cli;
2350 * Flush current sequence to make client obtain new one
2351 * from server in case of disconnect/reconnect.
2353 if (cli->cl_seq != NULL)
2354 seq_client_flush(cli->cl_seq);
2356 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_INACTIVE, NULL);
2359 case IMP_EVENT_INVALIDATE: {
2360 struct ldlm_namespace *ns = obd->obd_namespace;
2362 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
2366 case IMP_EVENT_ACTIVE:
2367 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_ACTIVE, NULL);
2368 /* restore re-establish kuc registration after reconnecting */
2370 rc = mdc_kuc_reregister(imp);
2373 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_OCD, NULL);
2375 case IMP_EVENT_DEACTIVATE:
2376 case IMP_EVENT_ACTIVATE:
2379 CERROR("Unknown import event %x\n", event);
2385 int mdc_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
2386 struct md_op_data *op_data)
2388 struct client_obd *cli = &exp->exp_obd->u.cli;
2389 struct lu_client_seq *seq = cli->cl_seq;
2391 RETURN(seq_client_alloc_fid(NULL, seq, fid));
2394 struct obd_uuid *mdc_get_uuid(struct obd_export *exp) {
2395 struct client_obd *cli = &exp->exp_obd->u.cli;
2396 return &cli->cl_target_uuid;
2400 * Determine whether the lock can be canceled before replaying it during
2401 * recovery, non zero value will be return if the lock can be canceled,
2402 * or zero returned for not
2404 static int mdc_cancel_for_recovery(struct ldlm_lock *lock)
2406 if (lock->l_resource->lr_type != LDLM_IBITS)
2409 /* FIXME: if we ever get into a situation where there are too many
2410 * opened files with open locks on a single node, then we really
2411 * should replay these open locks to reget it */
2412 if (lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_OPEN)
2418 static int mdc_resource_inode_free(struct ldlm_resource *res)
2420 if (res->lr_lvb_inode)
2421 res->lr_lvb_inode = NULL;
2426 struct ldlm_valblock_ops inode_lvbo = {
2427 lvbo_free: mdc_resource_inode_free
2430 static int mdc_setup(struct obd_device *obd, struct lustre_cfg *cfg)
2432 struct client_obd *cli = &obd->u.cli;
2433 struct lprocfs_static_vars lvars = { 0 };
2437 OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
2438 if (!cli->cl_rpc_lock)
2440 mdc_init_rpc_lock(cli->cl_rpc_lock);
2444 OBD_ALLOC(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
2445 if (!cli->cl_close_lock)
2446 GOTO(err_rpc_lock, rc = -ENOMEM);
2447 mdc_init_rpc_lock(cli->cl_close_lock);
2449 rc = client_obd_setup(obd, cfg);
2451 GOTO(err_close_lock, rc);
2452 lprocfs_mdc_init_vars(&lvars);
2453 lprocfs_obd_setup(obd, lvars.obd_vars);
2454 sptlrpc_lprocfs_cliobd_attach(obd);
2455 ptlrpc_lprocfs_register_obd(obd);
2457 ns_register_cancel(obd->obd_namespace, mdc_cancel_for_recovery);
2459 obd->obd_namespace->ns_lvbo = &inode_lvbo;
2461 rc = obd_llog_init(obd, &obd->obd_olg, obd, NULL);
2464 CERROR("failed to setup llogging subsystems\n");
2470 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
2472 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
2477 /* Initialize the default and maximum LOV EA and cookie sizes. This allows
2478 * us to make MDS RPCs with large enough reply buffers to hold the
2479 * maximum-sized (= maximum striped) EA and cookie without having to
2480 * calculate this (via a call into the LOV + OSCs) each time we make an RPC. */
2481 static int mdc_init_ea_size(struct obd_export *exp, int easize,
2482 int def_easize, int cookiesize)
2484 struct obd_device *obd = exp->exp_obd;
2485 struct client_obd *cli = &obd->u.cli;
2488 if (cli->cl_max_mds_easize < easize)
2489 cli->cl_max_mds_easize = easize;
2491 if (cli->cl_default_mds_easize < def_easize)
2492 cli->cl_default_mds_easize = def_easize;
2494 if (cli->cl_max_mds_cookiesize < cookiesize)
2495 cli->cl_max_mds_cookiesize = cookiesize;
2500 static int mdc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2506 case OBD_CLEANUP_EARLY:
2508 case OBD_CLEANUP_EXPORTS:
2509 /* Failsafe, ok if racy */
2510 if (obd->obd_type->typ_refcnt <= 1)
2511 libcfs_kkuc_group_rem(0, KUC_GRP_HSM);
2513 obd_cleanup_client_import(obd);
2514 ptlrpc_lprocfs_unregister_obd(obd);
2515 lprocfs_obd_cleanup(obd);
2517 rc = obd_llog_finish(obd, 0);
2519 CERROR("failed to cleanup llogging subsystems\n");
2525 static int mdc_cleanup(struct obd_device *obd)
2527 struct client_obd *cli = &obd->u.cli;
2529 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
2530 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
2534 return client_obd_cleanup(obd);
2538 static int mdc_llog_init(struct obd_device *obd, struct obd_llog_group *olg,
2539 struct obd_device *tgt, int *index)
2541 struct llog_ctxt *ctxt;
2546 LASSERT(olg == &obd->obd_olg);
2548 rc = llog_setup(NULL, obd, olg, LLOG_CHANGELOG_REPL_CTXT, tgt,
2553 ctxt = llog_group_get_ctxt(olg, LLOG_CHANGELOG_REPL_CTXT);
2554 llog_initiator_connect(ctxt);
2555 llog_ctxt_put(ctxt);
2560 static int mdc_llog_finish(struct obd_device *obd, int count)
2562 struct llog_ctxt *ctxt;
2566 ctxt = llog_get_context(obd, LLOG_CHANGELOG_REPL_CTXT);
2568 llog_cleanup(NULL, ctxt);
2573 static int mdc_process_config(struct obd_device *obd, obd_count len, void *buf)
2575 struct lustre_cfg *lcfg = buf;
2576 struct lprocfs_static_vars lvars = { 0 };
2579 lprocfs_mdc_init_vars(&lvars);
2580 switch (lcfg->lcfg_command) {
2582 rc = class_process_proc_param(PARAM_MDC, lvars.obd_vars,
2592 /* get remote permission for current user on fid */
2593 int mdc_get_remote_perm(struct obd_export *exp, const struct lu_fid *fid,
2594 struct obd_capa *oc, __u32 suppgid,
2595 struct ptlrpc_request **request)
2597 struct ptlrpc_request *req;
2601 LASSERT(client_is_remote(exp));
2604 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR);
2608 mdc_set_capa_size(req, &RMF_CAPA1, oc);
2610 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR);
2612 ptlrpc_request_free(req);
2616 mdc_pack_body(req, fid, oc, OBD_MD_FLRMTPERM, 0, suppgid, 0);
2618 req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER,
2619 sizeof(struct mdt_remote_perm));
2621 ptlrpc_request_set_replen(req);
2623 rc = ptlrpc_queue_wait(req);
2625 ptlrpc_req_finished(req);
2631 static int mdc_interpret_renew_capa(const struct lu_env *env,
2632 struct ptlrpc_request *req, void *args,
2635 struct mdc_renew_capa_args *ra = args;
2636 struct mdt_body *body = NULL;
2637 struct lustre_capa *capa;
2641 GOTO(out, capa = ERR_PTR(status));
2643 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
2645 GOTO(out, capa = ERR_PTR(-EFAULT));
2647 if ((body->valid & OBD_MD_FLOSSCAPA) == 0)
2648 GOTO(out, capa = ERR_PTR(-ENOENT));
2650 capa = req_capsule_server_get(&req->rq_pill, &RMF_CAPA2);
2652 GOTO(out, capa = ERR_PTR(-EFAULT));
2655 ra->ra_cb(ra->ra_oc, capa);
2659 static int mdc_renew_capa(struct obd_export *exp, struct obd_capa *oc,
2662 struct ptlrpc_request *req;
2663 struct mdc_renew_capa_args *ra;
2666 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_GETATTR,
2667 LUSTRE_MDS_VERSION, MDS_GETATTR);
2671 /* NB, OBD_MD_FLOSSCAPA is set here, but it doesn't necessarily mean the
2672 * capa to renew is oss capa.
2674 mdc_pack_body(req, &oc->c_capa.lc_fid, oc, OBD_MD_FLOSSCAPA, 0, -1, 0);
2675 ptlrpc_request_set_replen(req);
2677 CLASSERT(sizeof(*ra) <= sizeof(req->rq_async_args));
2678 ra = ptlrpc_req_async_args(req);
2681 req->rq_interpret_reply = mdc_interpret_renew_capa;
2682 ptlrpcd_add_req(req, PDL_POLICY_LOCAL, -1);
2686 static int mdc_connect(const struct lu_env *env,
2687 struct obd_export **exp,
2688 struct obd_device *obd, struct obd_uuid *cluuid,
2689 struct obd_connect_data *data,
2692 struct obd_import *imp = obd->u.cli.cl_import;
2694 /* mds-mds import features */
2695 if (data && (data->ocd_connect_flags & OBD_CONNECT_MDS_MDS)) {
2696 spin_lock(&imp->imp_lock);
2697 imp->imp_server_timeout = 1;
2698 spin_unlock(&imp->imp_lock);
2699 imp->imp_client->cli_request_portal = MDS_MDS_PORTAL;
2700 CDEBUG(D_OTHER, "%s: Set 'mds' portal and timeout\n",
2704 return client_connect_import(env, exp, obd, cluuid, data, NULL);
2707 struct obd_ops mdc_obd_ops = {
2708 .o_owner = THIS_MODULE,
2709 .o_setup = mdc_setup,
2710 .o_precleanup = mdc_precleanup,
2711 .o_cleanup = mdc_cleanup,
2712 .o_add_conn = client_import_add_conn,
2713 .o_del_conn = client_import_del_conn,
2714 .o_connect = mdc_connect,
2715 .o_disconnect = client_disconnect_export,
2716 .o_iocontrol = mdc_iocontrol,
2717 .o_set_info_async = mdc_set_info_async,
2718 .o_statfs = mdc_statfs,
2720 .o_unpin = mdc_unpin,
2721 .o_fid_init = client_fid_init,
2722 .o_fid_fini = client_fid_fini,
2723 .o_fid_alloc = mdc_fid_alloc,
2724 .o_import_event = mdc_import_event,
2725 .o_llog_init = mdc_llog_init,
2726 .o_llog_finish = mdc_llog_finish,
2727 .o_get_info = mdc_get_info,
2728 .o_process_config = mdc_process_config,
2729 .o_get_uuid = mdc_get_uuid,
2730 .o_quotactl = mdc_quotactl,
2731 .o_quotacheck = mdc_quotacheck
2734 struct md_ops mdc_md_ops = {
2735 .m_getstatus = mdc_getstatus,
2736 .m_null_inode = mdc_null_inode,
2737 .m_find_cbdata = mdc_find_cbdata,
2738 .m_close = mdc_close,
2739 .m_create = mdc_create,
2740 .m_done_writing = mdc_done_writing,
2741 .m_enqueue = mdc_enqueue,
2742 .m_getattr = mdc_getattr,
2743 .m_getattr_name = mdc_getattr_name,
2744 .m_intent_lock = mdc_intent_lock,
2746 .m_is_subdir = mdc_is_subdir,
2747 .m_rename = mdc_rename,
2748 .m_setattr = mdc_setattr,
2749 .m_setxattr = mdc_setxattr,
2750 .m_getxattr = mdc_getxattr,
2752 .m_readpage = mdc_readpage,
2753 .m_unlink = mdc_unlink,
2754 .m_cancel_unused = mdc_cancel_unused,
2755 .m_init_ea_size = mdc_init_ea_size,
2756 .m_set_lock_data = mdc_set_lock_data,
2757 .m_lock_match = mdc_lock_match,
2758 .m_get_lustre_md = mdc_get_lustre_md,
2759 .m_free_lustre_md = mdc_free_lustre_md,
2760 .m_set_open_replay_data = mdc_set_open_replay_data,
2761 .m_clear_open_replay_data = mdc_clear_open_replay_data,
2762 .m_renew_capa = mdc_renew_capa,
2763 .m_unpack_capa = mdc_unpack_capa,
2764 .m_get_remote_perm = mdc_get_remote_perm,
2765 .m_intent_getattr_async = mdc_intent_getattr_async,
2766 .m_revalidate_lock = mdc_revalidate_lock
2769 int __init mdc_init(void)
2772 struct lprocfs_static_vars lvars = { 0 };
2773 lprocfs_mdc_init_vars(&lvars);
2775 rc = class_register_type(&mdc_obd_ops, &mdc_md_ops, lvars.module_vars,
2776 LUSTRE_MDC_NAME, NULL);
2781 static void /*__exit*/ mdc_exit(void)
2783 class_unregister_type(LUSTRE_MDC_NAME);
2786 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2787 MODULE_DESCRIPTION("Lustre Metadata Client");
2788 MODULE_LICENSE("GPL");
2790 module_init(mdc_init);
2791 module_exit(mdc_exit);