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 "../include/lustre_acl.h"
46 #include "../include/obd_class.h"
47 #include "../include/lustre_fid.h"
48 #include "../include/lprocfs_status.h"
49 #include "../include/lustre_param.h"
50 #include "../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 static 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;
69 /* swabbed already in mdc_enqueue */
70 capa = req_capsule_server_get(&req->rq_pill, field);
74 c = alloc_capa(CAPA_SITE_CLIENT);
76 CDEBUG(D_INFO, "alloc capa failed!\n");
85 static inline int mdc_queue_wait(struct ptlrpc_request *req)
87 struct client_obd *cli = &req->rq_import->imp_obd->u.cli;
90 /* mdc_enter_request() ensures that this client has no more
91 * than cl_max_rpcs_in_flight RPCs simultaneously inf light
93 rc = mdc_enter_request(cli);
97 rc = ptlrpc_queue_wait(req);
98 mdc_exit_request(cli);
103 /* Helper that implements most of mdc_getstatus and signal_completed_replay. */
104 /* XXX this should become mdc_get_info("key"), sending MDS_GET_INFO RPC */
105 static int send_getstatus(struct obd_import *imp, struct lu_fid *rootfid,
106 struct obd_capa **pc, int level, int msg_flags)
108 struct ptlrpc_request *req;
109 struct mdt_body *body;
112 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_GETSTATUS,
113 LUSTRE_MDS_VERSION, MDS_GETSTATUS);
117 mdc_pack_body(req, NULL, NULL, 0, 0, -1, 0);
118 lustre_msg_add_flags(req->rq_reqmsg, msg_flags);
119 req->rq_send_state = level;
121 ptlrpc_request_set_replen(req);
123 rc = ptlrpc_queue_wait(req);
127 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
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=%llu\n",
143 lustre_msg_get_last_committed(req->rq_repmsg));
145 ptlrpc_req_finished(req);
149 /* This should be mdc_get_info("rootfid") */
150 static int mdc_getstatus(struct obd_export *exp, struct lu_fid *rootfid,
151 struct obd_capa **pc)
153 return send_getstatus(class_exp2cliimp(exp), rootfid, pc,
158 * This function now is known to always saying that it will receive 4 buffers
159 * from server. Even for cases when acl_size and md_size is zero, RPC header
160 * will contain 4 fields and RPC itself will contain zero size fields. This is
161 * because mdt_getattr*() _always_ returns 4 fields, but if acl is not needed
162 * and thus zero, it shrinks it, making zero size. The same story about
163 * md_size. And this is course of problem when client waits for smaller number
164 * of fields. This issue will be fixed later when client gets aware of RPC
167 static int mdc_getattr_common(struct obd_export *exp,
168 struct ptlrpc_request *req)
170 struct req_capsule *pill = &req->rq_pill;
171 struct mdt_body *body;
175 /* Request message already built. */
176 rc = ptlrpc_queue_wait(req);
180 /* sanity check for the reply */
181 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
185 CDEBUG(D_NET, "mode: %o\n", body->mode);
187 if (body->eadatasize != 0) {
188 mdc_update_max_ea_from_body(exp, body);
190 eadata = req_capsule_server_sized_get(pill, &RMF_MDT_MD,
196 if (body->valid & OBD_MD_FLRMTPERM) {
197 struct mdt_remote_perm *perm;
199 LASSERT(client_is_remote(exp));
200 perm = req_capsule_server_swab_get(pill, &RMF_ACL,
201 lustre_swab_mdt_remote_perm);
206 if (body->valid & OBD_MD_FLMDSCAPA) {
207 struct lustre_capa *capa;
209 capa = req_capsule_server_get(pill, &RMF_CAPA1);
217 static int mdc_getattr(struct obd_export *exp, struct md_op_data *op_data,
218 struct ptlrpc_request **request)
220 struct ptlrpc_request *req;
223 /* Single MDS without an LMV case */
224 if (op_data->op_flags & MF_GET_MDT_IDX) {
229 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR);
233 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
235 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR);
237 ptlrpc_request_free(req);
241 mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
242 op_data->op_valid, op_data->op_mode, -1, 0);
244 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER,
246 if (op_data->op_valid & OBD_MD_FLRMTPERM) {
247 LASSERT(client_is_remote(exp));
248 req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER,
249 sizeof(struct mdt_remote_perm));
251 ptlrpc_request_set_replen(req);
253 rc = mdc_getattr_common(exp, req);
255 ptlrpc_req_finished(req);
261 static int mdc_getattr_name(struct obd_export *exp, struct md_op_data *op_data,
262 struct ptlrpc_request **request)
264 struct ptlrpc_request *req;
268 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
269 &RQF_MDS_GETATTR_NAME);
273 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
274 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
275 op_data->op_namelen + 1);
277 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR_NAME);
279 ptlrpc_request_free(req);
283 mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
284 op_data->op_valid, op_data->op_mode,
285 op_data->op_suppgids[0], 0);
287 if (op_data->op_name) {
288 char *name = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
290 LASSERT(strnlen(op_data->op_name, op_data->op_namelen) ==
291 op_data->op_namelen);
292 memcpy(name, op_data->op_name, op_data->op_namelen);
295 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER,
297 ptlrpc_request_set_replen(req);
299 rc = mdc_getattr_common(exp, req);
301 ptlrpc_req_finished(req);
307 static int mdc_is_subdir(struct obd_export *exp,
308 const struct lu_fid *pfid,
309 const struct lu_fid *cfid,
310 struct ptlrpc_request **request)
312 struct ptlrpc_request *req;
316 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
317 &RQF_MDS_IS_SUBDIR, LUSTRE_MDS_VERSION,
322 mdc_is_subdir_pack(req, pfid, cfid, 0);
323 ptlrpc_request_set_replen(req);
325 rc = ptlrpc_queue_wait(req);
326 if (rc && rc != -EREMOTE)
327 ptlrpc_req_finished(req);
333 static int mdc_xattr_common(struct obd_export *exp,
334 const struct req_format *fmt,
335 const struct lu_fid *fid,
336 struct obd_capa *oc, int opcode, u64 valid,
337 const char *xattr_name, const char *input,
338 int input_size, int output_size, int flags,
339 __u32 suppgid, struct ptlrpc_request **request)
341 struct ptlrpc_request *req;
342 int xattr_namelen = 0;
347 req = ptlrpc_request_alloc(class_exp2cliimp(exp), fmt);
351 mdc_set_capa_size(req, &RMF_CAPA1, oc);
353 xattr_namelen = strlen(xattr_name) + 1;
354 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
359 req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_CLIENT,
363 /* Flush local XATTR locks to get rid of a possible cancel RPC */
364 if (opcode == MDS_REINT && fid_is_sane(fid) &&
365 exp->exp_connect_data.ocd_ibits_known & MDS_INODELOCK_XATTR) {
369 /* Without that packing would fail */
371 req_capsule_set_size(&req->rq_pill, &RMF_EADATA,
374 count = mdc_resource_get_unused(exp, fid,
376 MDS_INODELOCK_XATTR);
378 rc = mdc_prep_elc_req(exp, req, MDS_REINT, &cancels, count);
380 ptlrpc_request_free(req);
384 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, opcode);
386 ptlrpc_request_free(req);
391 if (opcode == MDS_REINT) {
392 struct mdt_rec_setxattr *rec;
394 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
395 sizeof(struct mdt_rec_reint));
396 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
397 rec->sx_opcode = REINT_SETXATTR;
398 rec->sx_fsuid = from_kuid(&init_user_ns, current_fsuid());
399 rec->sx_fsgid = from_kgid(&init_user_ns, current_fsgid());
400 rec->sx_cap = cfs_curproc_cap_pack();
401 rec->sx_suppgid1 = suppgid;
402 rec->sx_suppgid2 = -1;
404 rec->sx_valid = valid | OBD_MD_FLCTIME;
405 rec->sx_time = get_seconds();
406 rec->sx_size = output_size;
407 rec->sx_flags = flags;
409 mdc_pack_capa(req, &RMF_CAPA1, oc);
411 mdc_pack_body(req, fid, oc, valid, output_size, suppgid, flags);
415 tmp = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
416 memcpy(tmp, xattr_name, xattr_namelen);
419 tmp = req_capsule_client_get(&req->rq_pill, &RMF_EADATA);
420 memcpy(tmp, input, input_size);
423 if (req_capsule_has_field(&req->rq_pill, &RMF_EADATA, RCL_SERVER))
424 req_capsule_set_size(&req->rq_pill, &RMF_EADATA,
425 RCL_SERVER, output_size);
426 ptlrpc_request_set_replen(req);
429 if (opcode == MDS_REINT)
430 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
432 rc = ptlrpc_queue_wait(req);
434 if (opcode == MDS_REINT)
435 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
438 ptlrpc_req_finished(req);
444 static int mdc_setxattr(struct obd_export *exp, const struct lu_fid *fid,
445 struct obd_capa *oc, u64 valid, const char *xattr_name,
446 const char *input, int input_size, int output_size,
447 int flags, __u32 suppgid, struct ptlrpc_request **request)
449 return mdc_xattr_common(exp, &RQF_MDS_REINT_SETXATTR,
450 fid, oc, MDS_REINT, valid, xattr_name,
451 input, input_size, output_size, flags,
455 static int mdc_getxattr(struct obd_export *exp, const struct lu_fid *fid,
456 struct obd_capa *oc, u64 valid, const char *xattr_name,
457 const char *input, int input_size, int output_size,
458 int flags, struct ptlrpc_request **request)
460 return mdc_xattr_common(exp, &RQF_MDS_GETXATTR,
461 fid, oc, MDS_GETXATTR, valid, xattr_name,
462 input, input_size, output_size, flags,
466 #ifdef CONFIG_FS_POSIX_ACL
467 static int mdc_unpack_acl(struct ptlrpc_request *req, struct lustre_md *md)
469 struct req_capsule *pill = &req->rq_pill;
470 struct mdt_body *body = md->body;
471 struct posix_acl *acl;
478 buf = req_capsule_server_sized_get(pill, &RMF_ACL, body->aclsize);
483 acl = posix_acl_from_xattr(&init_user_ns, buf, body->aclsize);
489 CERROR("convert xattr to acl: %d\n", rc);
493 rc = posix_acl_valid(acl);
495 CERROR("validate acl: %d\n", rc);
496 posix_acl_release(acl);
504 #define mdc_unpack_acl(req, md) 0
507 int mdc_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
508 struct obd_export *dt_exp, struct obd_export *md_exp,
509 struct lustre_md *md)
511 struct req_capsule *pill = &req->rq_pill;
515 memset(md, 0, sizeof(*md));
517 md->body = req_capsule_server_get(pill, &RMF_MDT_BODY);
518 LASSERT(md->body != NULL);
520 if (md->body->valid & OBD_MD_FLEASIZE) {
522 struct lov_mds_md *lmm;
524 if (!S_ISREG(md->body->mode)) {
526 "OBD_MD_FLEASIZE set, should be a regular file, but is not\n");
531 if (md->body->eadatasize == 0) {
533 "OBD_MD_FLEASIZE set, but eadatasize 0\n");
537 lmmsize = md->body->eadatasize;
538 lmm = req_capsule_server_sized_get(pill, &RMF_MDT_MD, lmmsize);
544 rc = obd_unpackmd(dt_exp, &md->lsm, lmm, lmmsize);
548 if (rc < sizeof(*md->lsm)) {
550 "lsm size too small: rc < sizeof (*md->lsm) (%d < %d)\n",
551 rc, (int)sizeof(*md->lsm));
556 } else if (md->body->valid & OBD_MD_FLDIREA) {
558 struct lov_mds_md *lmv;
560 if (!S_ISDIR(md->body->mode)) {
562 "OBD_MD_FLDIREA set, should be a directory, but is not\n");
567 if (md->body->eadatasize == 0) {
569 "OBD_MD_FLDIREA is set, but eadatasize 0\n");
572 if (md->body->valid & OBD_MD_MEA) {
573 lmvsize = md->body->eadatasize;
574 lmv = req_capsule_server_sized_get(pill, &RMF_MDT_MD,
581 rc = obd_unpackmd(md_exp, (void *)&md->mea, lmv,
586 if (rc < sizeof(*md->mea)) {
588 "size too small: rc < sizeof(*md->mea) (%d < %d)\n",
589 rc, (int)sizeof(*md->mea));
597 if (md->body->valid & OBD_MD_FLRMTPERM) {
598 /* remote permission */
599 LASSERT(client_is_remote(exp));
600 md->remote_perm = req_capsule_server_swab_get(pill, &RMF_ACL,
601 lustre_swab_mdt_remote_perm);
602 if (!md->remote_perm) {
606 } else if (md->body->valid & OBD_MD_FLACL) {
607 /* for ACL, it's possible that FLACL is set but aclsize is zero.
608 * only when aclsize != 0 there's an actual segment for ACL
611 if (md->body->aclsize) {
612 rc = mdc_unpack_acl(req, md);
615 #ifdef CONFIG_FS_POSIX_ACL
617 md->posix_acl = NULL;
621 if (md->body->valid & OBD_MD_FLMDSCAPA) {
622 struct obd_capa *oc = NULL;
624 rc = mdc_unpack_capa(NULL, req, &RMF_CAPA1, &oc);
630 if (md->body->valid & OBD_MD_FLOSSCAPA) {
631 struct obd_capa *oc = NULL;
633 rc = mdc_unpack_capa(NULL, req, &RMF_CAPA2, &oc);
642 capa_put(md->oss_capa);
646 capa_put(md->mds_capa);
649 #ifdef CONFIG_FS_POSIX_ACL
650 posix_acl_release(md->posix_acl);
653 obd_free_memmd(dt_exp, &md->lsm);
658 int mdc_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
664 * Handles both OPEN and SETATTR RPCs for OPEN-CLOSE and SETATTR-DONE_WRITING
667 void mdc_replay_open(struct ptlrpc_request *req)
669 struct md_open_data *mod = req->rq_cb_data;
670 struct ptlrpc_request *close_req;
671 struct obd_client_handle *och;
672 struct lustre_handle old;
673 struct mdt_body *body;
676 DEBUG_REQ(D_ERROR, req,
677 "Can't properly replay without open data.");
681 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
682 LASSERT(body != NULL);
686 struct lustre_handle *file_fh;
688 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
690 file_fh = &och->och_fh;
691 CDEBUG(D_HA, "updating handle from %#llx to %#llx\n",
692 file_fh->cookie, body->handle.cookie);
694 *file_fh = body->handle;
696 close_req = mod->mod_close_req;
697 if (close_req != NULL) {
698 __u32 opc = lustre_msg_get_opc(close_req->rq_reqmsg);
699 struct mdt_ioepoch *epoch;
701 LASSERT(opc == MDS_CLOSE || opc == MDS_DONE_WRITING);
702 epoch = req_capsule_client_get(&close_req->rq_pill,
707 LASSERT(!memcmp(&old, &epoch->handle, sizeof(old)));
708 DEBUG_REQ(D_HA, close_req, "updating close body with new fh");
709 epoch->handle = body->handle;
713 void mdc_commit_open(struct ptlrpc_request *req)
715 struct md_open_data *mod = req->rq_cb_data;
721 * No need to touch md_open_data::mod_och, it holds a reference on
722 * \var mod and will zero references to each other, \var mod will be
723 * freed after that when md_open_data::mod_och will put the reference.
727 * Do not let open request to disappear as it still may be needed
728 * for close rpc to happen (it may happen on evict only, otherwise
729 * ptlrpc_request::rq_replay does not let mdc_commit_open() to be
730 * called), just mark this rpc as committed to distinguish these 2
731 * cases, see mdc_close() for details. The open request reference will
732 * be put along with freeing \var mod.
734 ptlrpc_request_addref(req);
735 spin_lock(&req->rq_lock);
736 req->rq_committed = 1;
737 spin_unlock(&req->rq_lock);
738 req->rq_cb_data = NULL;
742 int mdc_set_open_replay_data(struct obd_export *exp,
743 struct obd_client_handle *och,
744 struct lookup_intent *it)
746 struct md_open_data *mod;
747 struct mdt_rec_create *rec;
748 struct mdt_body *body;
749 struct ptlrpc_request *open_req = it->d.lustre.it_data;
750 struct obd_import *imp = open_req->rq_import;
752 if (!open_req->rq_replay)
755 rec = req_capsule_client_get(&open_req->rq_pill, &RMF_REC_REINT);
756 body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY);
757 LASSERT(rec != NULL);
758 /* Incoming message in my byte order (it's been swabbed). */
759 /* Outgoing messages always in my byte order. */
760 LASSERT(body != NULL);
762 /* Only if the import is replayable, we set replay_open data */
763 if (och && imp->imp_replayable) {
764 mod = obd_mod_alloc();
766 DEBUG_REQ(D_ERROR, open_req,
767 "Can't allocate md_open_data");
772 * Take a reference on \var mod, to be freed on mdc_close().
773 * It protects \var mod from being freed on eviction (commit
774 * callback is called despite rq_replay flag).
775 * Another reference for \var och.
780 spin_lock(&open_req->rq_lock);
783 mod->mod_is_create = it_disposition(it, DISP_OPEN_CREATE) ||
784 it_disposition(it, DISP_OPEN_STRIPE);
785 mod->mod_open_req = open_req;
786 open_req->rq_cb_data = mod;
787 open_req->rq_commit_cb = mdc_commit_open;
788 spin_unlock(&open_req->rq_lock);
791 rec->cr_fid2 = body->fid1;
792 rec->cr_ioepoch = body->ioepoch;
793 rec->cr_old_handle.cookie = body->handle.cookie;
794 open_req->rq_replay_cb = mdc_replay_open;
795 if (!fid_is_sane(&body->fid1)) {
796 DEBUG_REQ(D_ERROR, open_req,
797 "Saving replay request with insane fid");
801 DEBUG_REQ(D_RPCTRACE, open_req, "Set up open replay data");
805 static void mdc_free_open(struct md_open_data *mod)
809 if (mod->mod_is_create == 0 &&
810 imp_connect_disp_stripe(mod->mod_open_req->rq_import))
813 LASSERT(mod->mod_open_req->rq_replay == 0);
815 DEBUG_REQ(D_RPCTRACE, mod->mod_open_req, "free open request\n");
817 ptlrpc_request_committed(mod->mod_open_req, committed);
818 if (mod->mod_close_req)
819 ptlrpc_request_committed(mod->mod_close_req, committed);
822 int mdc_clear_open_replay_data(struct obd_export *exp,
823 struct obd_client_handle *och)
825 struct md_open_data *mod = och->och_mod;
828 * It is possible to not have \var mod in a case of eviction between
829 * lookup and ll_file_open().
834 LASSERT(mod != LP_POISON);
835 LASSERT(mod->mod_open_req != NULL);
845 /* Prepares the request for the replay by the given reply */
846 static void mdc_close_handle_reply(struct ptlrpc_request *req,
847 struct md_op_data *op_data, int rc) {
848 struct mdt_body *repbody;
849 struct mdt_ioepoch *epoch;
851 if (req && rc == -EAGAIN) {
852 repbody = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
853 epoch = req_capsule_client_get(&req->rq_pill, &RMF_MDT_EPOCH);
855 epoch->flags |= MF_SOM_AU;
856 if (repbody->valid & OBD_MD_FLGETATTRLOCK)
857 op_data->op_flags |= MF_GETATTR_LOCK;
861 static int mdc_close(struct obd_export *exp, struct md_op_data *op_data,
862 struct md_open_data *mod, struct ptlrpc_request **request)
864 struct obd_device *obd = class_exp2obd(exp);
865 struct ptlrpc_request *req;
866 struct req_format *req_fmt;
871 req_fmt = &RQF_MDS_CLOSE;
872 if (op_data->op_bias & MDS_HSM_RELEASE) {
873 req_fmt = &RQF_MDS_RELEASE_CLOSE;
875 /* allocate a FID for volatile file */
876 rc = mdc_fid_alloc(exp, &op_data->op_fid2, op_data);
878 CERROR("%s: "DFID" failed to allocate FID: %d\n",
879 obd->obd_name, PFID(&op_data->op_fid1), rc);
880 /* save the errcode and proceed to close */
886 req = ptlrpc_request_alloc(class_exp2cliimp(exp), req_fmt);
890 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
892 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_CLOSE);
894 ptlrpc_request_free(req);
898 /* To avoid a livelock (bug 7034), we need to send CLOSE RPCs to a
899 * portal whose threads are not taking any DLM locks and are therefore
900 * always progressing */
901 req->rq_request_portal = MDS_READPAGE_PORTAL;
902 ptlrpc_at_set_req_timeout(req);
904 /* Ensure that this close's handle is fixed up during replay. */
905 if (likely(mod != NULL)) {
906 LASSERTF(mod->mod_open_req != NULL &&
907 mod->mod_open_req->rq_type != LI_POISON,
908 "POISONED open %p!\n", mod->mod_open_req);
910 mod->mod_close_req = req;
912 DEBUG_REQ(D_HA, mod->mod_open_req, "matched open");
913 /* We no longer want to preserve this open for replay even
914 * though the open was committed. b=3632, b=3633 */
915 spin_lock(&mod->mod_open_req->rq_lock);
916 mod->mod_open_req->rq_replay = 0;
917 spin_unlock(&mod->mod_open_req->rq_lock);
920 "couldn't find open req; expecting close error\n");
923 mdc_close_pack(req, op_data);
925 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER,
926 obd->u.cli.cl_default_mds_easize);
927 req_capsule_set_size(&req->rq_pill, &RMF_LOGCOOKIES, RCL_SERVER,
928 obd->u.cli.cl_default_mds_cookiesize);
930 ptlrpc_request_set_replen(req);
932 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
933 rc = ptlrpc_queue_wait(req);
934 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
936 if (req->rq_repmsg == NULL) {
937 CDEBUG(D_RPCTRACE, "request failed to send: %p, %d\n", req,
940 rc = req->rq_status ?: -EIO;
941 } else if (rc == 0 || rc == -EAGAIN) {
942 struct mdt_body *body;
944 rc = lustre_msg_get_status(req->rq_repmsg);
945 if (lustre_msg_get_type(req->rq_repmsg) == PTL_RPC_MSG_ERR) {
946 DEBUG_REQ(D_ERROR, req,
947 "type == PTL_RPC_MSG_ERR, err = %d", rc);
951 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
954 } else if (rc == -ESTALE) {
956 * it can be allowed error after 3633 if open was committed and
957 * server failed before close was sent. Let's check if mod
958 * exists and return no error in that case
961 DEBUG_REQ(D_HA, req, "Reset ESTALE = %d", rc);
962 LASSERT(mod->mod_open_req != NULL);
963 if (mod->mod_open_req->rq_committed)
970 mod->mod_close_req = NULL;
971 /* Since now, mod is accessed through open_req only,
972 * thus close req does not keep a reference on mod anymore. */
976 mdc_close_handle_reply(req, op_data, rc);
977 return rc < 0 ? rc : saved_rc;
980 static int mdc_done_writing(struct obd_export *exp, struct md_op_data *op_data,
981 struct md_open_data *mod)
983 struct obd_device *obd = class_exp2obd(exp);
984 struct ptlrpc_request *req;
987 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
988 &RQF_MDS_DONE_WRITING);
992 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
993 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_DONE_WRITING);
995 ptlrpc_request_free(req);
1000 LASSERTF(mod->mod_open_req != NULL &&
1001 mod->mod_open_req->rq_type != LI_POISON,
1002 "POISONED setattr %p!\n", mod->mod_open_req);
1004 mod->mod_close_req = req;
1005 DEBUG_REQ(D_HA, mod->mod_open_req, "matched setattr");
1006 /* We no longer want to preserve this setattr for replay even
1007 * though the open was committed. b=3632, b=3633 */
1008 spin_lock(&mod->mod_open_req->rq_lock);
1009 mod->mod_open_req->rq_replay = 0;
1010 spin_unlock(&mod->mod_open_req->rq_lock);
1013 mdc_close_pack(req, op_data);
1014 ptlrpc_request_set_replen(req);
1016 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
1017 rc = ptlrpc_queue_wait(req);
1018 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
1020 if (rc == -ESTALE) {
1022 * it can be allowed error after 3633 if open or setattr were
1023 * committed and server failed before close was sent.
1024 * Let's check if mod exists and return no error in that case
1027 LASSERT(mod->mod_open_req != NULL);
1028 if (mod->mod_open_req->rq_committed)
1035 mod->mod_close_req = NULL;
1036 LASSERT(mod->mod_open_req != NULL);
1039 /* Since now, mod is accessed through setattr req only,
1040 * thus DW req does not keep a reference on mod anymore. */
1044 mdc_close_handle_reply(req, op_data, rc);
1045 ptlrpc_req_finished(req);
1050 static int mdc_readpage(struct obd_export *exp, struct md_op_data *op_data,
1051 struct page **pages, struct ptlrpc_request **request)
1053 struct ptlrpc_request *req;
1054 struct ptlrpc_bulk_desc *desc;
1056 wait_queue_head_t waitq;
1058 struct l_wait_info lwi;
1062 init_waitqueue_head(&waitq);
1065 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_READPAGE);
1069 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
1071 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_READPAGE);
1073 ptlrpc_request_free(req);
1077 req->rq_request_portal = MDS_READPAGE_PORTAL;
1078 ptlrpc_at_set_req_timeout(req);
1080 desc = ptlrpc_prep_bulk_imp(req, op_data->op_npages, 1, BULK_PUT_SINK,
1083 ptlrpc_request_free(req);
1087 /* NB req now owns desc and will free it when it gets freed */
1088 for (i = 0; i < op_data->op_npages; i++)
1089 ptlrpc_prep_bulk_page_pin(desc, pages[i], 0, PAGE_CACHE_SIZE);
1091 mdc_readdir_pack(req, op_data->op_offset,
1092 PAGE_CACHE_SIZE * op_data->op_npages,
1093 &op_data->op_fid1, op_data->op_capa1);
1095 ptlrpc_request_set_replen(req);
1096 rc = ptlrpc_queue_wait(req);
1098 ptlrpc_req_finished(req);
1099 if (rc != -ETIMEDOUT)
1103 if (!client_should_resend(resends, &exp->exp_obd->u.cli)) {
1104 CERROR("too many resend retries, returning error\n");
1107 lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(resends),
1109 l_wait_event(waitq, 0, &lwi);
1114 rc = sptlrpc_cli_unwrap_bulk_read(req, req->rq_bulk,
1115 req->rq_bulk->bd_nob_transferred);
1117 ptlrpc_req_finished(req);
1121 if (req->rq_bulk->bd_nob_transferred & ~LU_PAGE_MASK) {
1122 CERROR("Unexpected # bytes transferred: %d (%ld expected)\n",
1123 req->rq_bulk->bd_nob_transferred,
1124 PAGE_CACHE_SIZE * op_data->op_npages);
1125 ptlrpc_req_finished(req);
1133 static int mdc_statfs(const struct lu_env *env,
1134 struct obd_export *exp, struct obd_statfs *osfs,
1135 __u64 max_age, __u32 flags)
1137 struct obd_device *obd = class_exp2obd(exp);
1138 struct ptlrpc_request *req;
1139 struct obd_statfs *msfs;
1140 struct obd_import *imp = NULL;
1144 * Since the request might also come from lprocfs, so we need
1145 * sync this with client_disconnect_export Bug15684
1147 down_read(&obd->u.cli.cl_sem);
1148 if (obd->u.cli.cl_import)
1149 imp = class_import_get(obd->u.cli.cl_import);
1150 up_read(&obd->u.cli.cl_sem);
1154 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_STATFS,
1155 LUSTRE_MDS_VERSION, MDS_STATFS);
1161 ptlrpc_request_set_replen(req);
1163 if (flags & OBD_STATFS_NODELAY) {
1164 /* procfs requests not want stay in wait for avoid deadlock */
1165 req->rq_no_resend = 1;
1166 req->rq_no_delay = 1;
1169 rc = ptlrpc_queue_wait(req);
1171 /* check connection error first */
1172 if (imp->imp_connect_error)
1173 rc = imp->imp_connect_error;
1177 msfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
1185 ptlrpc_req_finished(req);
1187 class_import_put(imp);
1191 static int mdc_ioc_fid2path(struct obd_export *exp, struct getinfo_fid2path *gf)
1193 __u32 keylen, vallen;
1197 if (gf->gf_pathlen > PATH_MAX)
1198 return -ENAMETOOLONG;
1199 if (gf->gf_pathlen < 2)
1202 /* Key is KEY_FID2PATH + getinfo_fid2path description */
1203 keylen = cfs_size_round(sizeof(KEY_FID2PATH)) + sizeof(*gf);
1204 OBD_ALLOC(key, keylen);
1207 memcpy(key, KEY_FID2PATH, sizeof(KEY_FID2PATH));
1208 memcpy(key + cfs_size_round(sizeof(KEY_FID2PATH)), gf, sizeof(*gf));
1210 CDEBUG(D_IOCTL, "path get "DFID" from %llu #%d\n",
1211 PFID(&gf->gf_fid), gf->gf_recno, gf->gf_linkno);
1213 if (!fid_is_sane(&gf->gf_fid)) {
1218 /* Val is struct getinfo_fid2path result plus path */
1219 vallen = sizeof(*gf) + gf->gf_pathlen;
1221 rc = obd_get_info(NULL, exp, keylen, key, &vallen, gf, NULL);
1222 if (rc != 0 && rc != -EREMOTE)
1225 if (vallen <= sizeof(*gf)) {
1228 } else if (vallen > sizeof(*gf) + gf->gf_pathlen) {
1233 CDEBUG(D_IOCTL, "path get "DFID" from %llu #%d\n%s\n",
1234 PFID(&gf->gf_fid), gf->gf_recno, gf->gf_linkno, gf->gf_path);
1237 OBD_FREE(key, keylen);
1241 static int mdc_ioc_hsm_progress(struct obd_export *exp,
1242 struct hsm_progress_kernel *hpk)
1244 struct obd_import *imp = class_exp2cliimp(exp);
1245 struct hsm_progress_kernel *req_hpk;
1246 struct ptlrpc_request *req;
1249 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_HSM_PROGRESS,
1250 LUSTRE_MDS_VERSION, MDS_HSM_PROGRESS);
1256 mdc_pack_body(req, NULL, NULL, OBD_MD_FLRMTPERM, 0, 0, 0);
1258 /* Copy hsm_progress struct */
1259 req_hpk = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_PROGRESS);
1260 if (req_hpk == NULL) {
1266 req_hpk->hpk_errval = lustre_errno_hton(hpk->hpk_errval);
1268 ptlrpc_request_set_replen(req);
1270 rc = mdc_queue_wait(req);
1273 ptlrpc_req_finished(req);
1277 static int mdc_ioc_hsm_ct_register(struct obd_import *imp, __u32 archives)
1279 __u32 *archive_mask;
1280 struct ptlrpc_request *req;
1283 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_HSM_CT_REGISTER,
1285 MDS_HSM_CT_REGISTER);
1291 mdc_pack_body(req, NULL, NULL, OBD_MD_FLRMTPERM, 0, 0, 0);
1293 /* Copy hsm_progress struct */
1294 archive_mask = req_capsule_client_get(&req->rq_pill,
1295 &RMF_MDS_HSM_ARCHIVE);
1296 if (archive_mask == NULL) {
1301 *archive_mask = archives;
1303 ptlrpc_request_set_replen(req);
1305 rc = mdc_queue_wait(req);
1308 ptlrpc_req_finished(req);
1312 static int mdc_ioc_hsm_current_action(struct obd_export *exp,
1313 struct md_op_data *op_data)
1315 struct hsm_current_action *hca = op_data->op_data;
1316 struct hsm_current_action *req_hca;
1317 struct ptlrpc_request *req;
1320 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
1321 &RQF_MDS_HSM_ACTION);
1325 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
1327 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_ACTION);
1329 ptlrpc_request_free(req);
1333 mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
1334 OBD_MD_FLRMTPERM, 0, op_data->op_suppgids[0], 0);
1336 ptlrpc_request_set_replen(req);
1338 rc = mdc_queue_wait(req);
1342 req_hca = req_capsule_server_get(&req->rq_pill,
1343 &RMF_MDS_HSM_CURRENT_ACTION);
1344 if (req_hca == NULL) {
1352 ptlrpc_req_finished(req);
1356 static int mdc_ioc_hsm_ct_unregister(struct obd_import *imp)
1358 struct ptlrpc_request *req;
1361 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_HSM_CT_UNREGISTER,
1363 MDS_HSM_CT_UNREGISTER);
1369 mdc_pack_body(req, NULL, NULL, OBD_MD_FLRMTPERM, 0, 0, 0);
1371 ptlrpc_request_set_replen(req);
1373 rc = mdc_queue_wait(req);
1376 ptlrpc_req_finished(req);
1380 static int mdc_ioc_hsm_state_get(struct obd_export *exp,
1381 struct md_op_data *op_data)
1383 struct hsm_user_state *hus = op_data->op_data;
1384 struct hsm_user_state *req_hus;
1385 struct ptlrpc_request *req;
1388 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
1389 &RQF_MDS_HSM_STATE_GET);
1393 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
1395 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_STATE_GET);
1397 ptlrpc_request_free(req);
1401 mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
1402 OBD_MD_FLRMTPERM, 0, op_data->op_suppgids[0], 0);
1404 ptlrpc_request_set_replen(req);
1406 rc = mdc_queue_wait(req);
1410 req_hus = req_capsule_server_get(&req->rq_pill, &RMF_HSM_USER_STATE);
1411 if (req_hus == NULL) {
1419 ptlrpc_req_finished(req);
1423 static int mdc_ioc_hsm_state_set(struct obd_export *exp,
1424 struct md_op_data *op_data)
1426 struct hsm_state_set *hss = op_data->op_data;
1427 struct hsm_state_set *req_hss;
1428 struct ptlrpc_request *req;
1431 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
1432 &RQF_MDS_HSM_STATE_SET);
1436 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
1438 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_STATE_SET);
1440 ptlrpc_request_free(req);
1444 mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
1445 OBD_MD_FLRMTPERM, 0, op_data->op_suppgids[0], 0);
1448 req_hss = req_capsule_client_get(&req->rq_pill, &RMF_HSM_STATE_SET);
1449 if (req_hss == NULL) {
1455 ptlrpc_request_set_replen(req);
1457 rc = mdc_queue_wait(req);
1461 ptlrpc_req_finished(req);
1465 static int mdc_ioc_hsm_request(struct obd_export *exp,
1466 struct hsm_user_request *hur)
1468 struct obd_import *imp = class_exp2cliimp(exp);
1469 struct ptlrpc_request *req;
1470 struct hsm_request *req_hr;
1471 struct hsm_user_item *req_hui;
1475 req = ptlrpc_request_alloc(imp, &RQF_MDS_HSM_REQUEST);
1481 req_capsule_set_size(&req->rq_pill, &RMF_MDS_HSM_USER_ITEM, RCL_CLIENT,
1482 hur->hur_request.hr_itemcount
1483 * sizeof(struct hsm_user_item));
1484 req_capsule_set_size(&req->rq_pill, &RMF_GENERIC_DATA, RCL_CLIENT,
1485 hur->hur_request.hr_data_len);
1487 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_REQUEST);
1489 ptlrpc_request_free(req);
1493 mdc_pack_body(req, NULL, NULL, OBD_MD_FLRMTPERM, 0, 0, 0);
1495 /* Copy hsm_request struct */
1496 req_hr = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_REQUEST);
1497 if (req_hr == NULL) {
1501 *req_hr = hur->hur_request;
1503 /* Copy hsm_user_item structs */
1504 req_hui = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_USER_ITEM);
1505 if (req_hui == NULL) {
1509 memcpy(req_hui, hur->hur_user_item,
1510 hur->hur_request.hr_itemcount * sizeof(struct hsm_user_item));
1512 /* Copy opaque field */
1513 req_opaque = req_capsule_client_get(&req->rq_pill, &RMF_GENERIC_DATA);
1514 if (req_opaque == NULL) {
1518 memcpy(req_opaque, hur_data(hur), hur->hur_request.hr_data_len);
1520 ptlrpc_request_set_replen(req);
1522 rc = mdc_queue_wait(req);
1526 ptlrpc_req_finished(req);
1530 static struct kuc_hdr *changelog_kuc_hdr(char *buf, int len, int flags)
1532 struct kuc_hdr *lh = (struct kuc_hdr *)buf;
1534 LASSERT(len <= KUC_CHANGELOG_MSG_MAXSIZE);
1536 lh->kuc_magic = KUC_MAGIC;
1537 lh->kuc_transport = KUC_TRANSPORT_CHANGELOG;
1538 lh->kuc_flags = flags;
1539 lh->kuc_msgtype = CL_RECORD;
1540 lh->kuc_msglen = len;
1544 #define D_CHANGELOG 0
1546 struct changelog_show {
1551 struct obd_device *cs_obd;
1554 static int changelog_kkuc_cb(const struct lu_env *env, struct llog_handle *llh,
1555 struct llog_rec_hdr *hdr, void *data)
1557 struct changelog_show *cs = data;
1558 struct llog_changelog_rec *rec = (struct llog_changelog_rec *)hdr;
1562 if (rec->cr_hdr.lrh_type != CHANGELOG_REC) {
1564 CERROR("%s: not a changelog rec %x/%d: rc = %d\n",
1565 cs->cs_obd->obd_name, rec->cr_hdr.lrh_type,
1566 rec->cr.cr_type, rc);
1570 if (rec->cr.cr_index < cs->cs_startrec) {
1571 /* Skip entries earlier than what we are interested in */
1572 CDEBUG(D_CHANGELOG, "rec=%llu start=%llu\n",
1573 rec->cr.cr_index, cs->cs_startrec);
1577 CDEBUG(D_CHANGELOG, "%llu %02d%-5s %llu 0x%x t="DFID" p="DFID
1578 " %.*s\n", rec->cr.cr_index, rec->cr.cr_type,
1579 changelog_type2str(rec->cr.cr_type), rec->cr.cr_time,
1580 rec->cr.cr_flags & CLF_FLAGMASK,
1581 PFID(&rec->cr.cr_tfid), PFID(&rec->cr.cr_pfid),
1582 rec->cr.cr_namelen, changelog_rec_name(&rec->cr));
1584 len = sizeof(*lh) + changelog_rec_size(&rec->cr) + rec->cr.cr_namelen;
1586 /* Set up the message */
1587 lh = changelog_kuc_hdr(cs->cs_buf, len, cs->cs_flags);
1588 memcpy(lh + 1, &rec->cr, len - sizeof(*lh));
1590 rc = libcfs_kkuc_msg_put(cs->cs_fp, lh);
1591 CDEBUG(D_CHANGELOG, "kucmsg fp %p len %d rc %d\n", cs->cs_fp, len, rc);
1596 static int mdc_changelog_send_thread(void *csdata)
1598 struct changelog_show *cs = csdata;
1599 struct llog_ctxt *ctxt = NULL;
1600 struct llog_handle *llh = NULL;
1601 struct kuc_hdr *kuch;
1604 CDEBUG(D_CHANGELOG, "changelog to fp=%p start %llu\n",
1605 cs->cs_fp, cs->cs_startrec);
1607 OBD_ALLOC(cs->cs_buf, KUC_CHANGELOG_MSG_MAXSIZE);
1608 if (cs->cs_buf == NULL) {
1613 /* Set up the remote catalog handle */
1614 ctxt = llog_get_context(cs->cs_obd, LLOG_CHANGELOG_REPL_CTXT);
1619 rc = llog_open(NULL, ctxt, &llh, NULL, CHANGELOG_CATALOG,
1622 CERROR("%s: fail to open changelog catalog: rc = %d\n",
1623 cs->cs_obd->obd_name, rc);
1626 rc = llog_init_handle(NULL, llh, LLOG_F_IS_CAT, NULL);
1628 CERROR("llog_init_handle failed %d\n", rc);
1632 rc = llog_cat_process(NULL, llh, changelog_kkuc_cb, cs, 0, 0);
1634 /* Send EOF no matter what our result */
1635 kuch = changelog_kuc_hdr(cs->cs_buf, sizeof(*kuch), cs->cs_flags);
1637 kuch->kuc_msgtype = CL_EOF;
1638 libcfs_kkuc_msg_put(cs->cs_fp, kuch);
1644 llog_cat_close(NULL, llh);
1646 llog_ctxt_put(ctxt);
1648 OBD_FREE(cs->cs_buf, KUC_CHANGELOG_MSG_MAXSIZE);
1653 static int mdc_ioc_changelog_send(struct obd_device *obd,
1654 struct ioc_changelog *icc)
1656 struct changelog_show *cs;
1659 /* Freed in mdc_changelog_send_thread */
1665 cs->cs_startrec = icc->icc_recno;
1666 /* matching fput in mdc_changelog_send_thread */
1667 cs->cs_fp = fget(icc->icc_id);
1668 cs->cs_flags = icc->icc_flags;
1671 * New thread because we should return to user app before
1672 * writing into our pipe
1674 rc = PTR_ERR(kthread_run(mdc_changelog_send_thread, cs,
1675 "mdc_clg_send_thread"));
1676 if (!IS_ERR_VALUE(rc)) {
1677 CDEBUG(D_CHANGELOG, "start changelog thread\n");
1681 CERROR("Failed to start changelog thread: %d\n", rc);
1686 static int mdc_ioc_hsm_ct_start(struct obd_export *exp,
1687 struct lustre_kernelcomm *lk);
1689 static int mdc_quotacheck(struct obd_device *unused, struct obd_export *exp,
1690 struct obd_quotactl *oqctl)
1692 struct client_obd *cli = &exp->exp_obd->u.cli;
1693 struct ptlrpc_request *req;
1694 struct obd_quotactl *body;
1697 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
1698 &RQF_MDS_QUOTACHECK, LUSTRE_MDS_VERSION,
1703 body = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1706 ptlrpc_request_set_replen(req);
1708 /* the next poll will find -ENODATA, that means quotacheck is
1710 cli->cl_qchk_stat = -ENODATA;
1711 rc = ptlrpc_queue_wait(req);
1713 cli->cl_qchk_stat = rc;
1714 ptlrpc_req_finished(req);
1718 static int mdc_quota_poll_check(struct obd_export *exp,
1719 struct if_quotacheck *qchk)
1721 struct client_obd *cli = &exp->exp_obd->u.cli;
1724 qchk->obd_uuid = cli->cl_target_uuid;
1725 memcpy(qchk->obd_type, LUSTRE_MDS_NAME, strlen(LUSTRE_MDS_NAME));
1727 rc = cli->cl_qchk_stat;
1728 /* the client is not the previous one */
1729 if (rc == CL_NOT_QUOTACHECKED)
1734 static int mdc_quotactl(struct obd_device *unused, struct obd_export *exp,
1735 struct obd_quotactl *oqctl)
1737 struct ptlrpc_request *req;
1738 struct obd_quotactl *oqc;
1741 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
1742 &RQF_MDS_QUOTACTL, LUSTRE_MDS_VERSION,
1747 oqc = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1750 ptlrpc_request_set_replen(req);
1751 ptlrpc_at_set_req_timeout(req);
1752 req->rq_no_resend = 1;
1754 rc = ptlrpc_queue_wait(req);
1756 CERROR("ptlrpc_queue_wait failed, rc: %d\n", rc);
1758 if (req->rq_repmsg) {
1759 oqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
1763 CERROR("Can't unpack obd_quotactl\n");
1767 CERROR("Can't unpack obd_quotactl\n");
1770 ptlrpc_req_finished(req);
1775 static int mdc_ioc_swap_layouts(struct obd_export *exp,
1776 struct md_op_data *op_data)
1779 struct ptlrpc_request *req;
1781 struct mdc_swap_layouts *msl, *payload;
1783 msl = op_data->op_data;
1785 /* When the MDT will get the MDS_SWAP_LAYOUTS RPC the
1786 * first thing it will do is to cancel the 2 layout
1787 * locks hold by this client.
1788 * So the client must cancel its layout locks on the 2 fids
1789 * with the request RPC to avoid extra RPC round trips
1791 count = mdc_resource_get_unused(exp, &op_data->op_fid1, &cancels,
1792 LCK_CR, MDS_INODELOCK_LAYOUT);
1793 count += mdc_resource_get_unused(exp, &op_data->op_fid2, &cancels,
1794 LCK_CR, MDS_INODELOCK_LAYOUT);
1796 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
1797 &RQF_MDS_SWAP_LAYOUTS);
1799 ldlm_lock_list_put(&cancels, l_bl_ast, count);
1803 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
1804 mdc_set_capa_size(req, &RMF_CAPA2, op_data->op_capa2);
1806 rc = mdc_prep_elc_req(exp, req, MDS_SWAP_LAYOUTS, &cancels, count);
1808 ptlrpc_request_free(req);
1812 mdc_swap_layouts_pack(req, op_data);
1814 payload = req_capsule_client_get(&req->rq_pill, &RMF_SWAP_LAYOUTS);
1819 ptlrpc_request_set_replen(req);
1821 rc = ptlrpc_queue_wait(req);
1826 ptlrpc_req_finished(req);
1830 static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1831 void *karg, void *uarg)
1833 struct obd_device *obd = exp->exp_obd;
1834 struct obd_ioctl_data *data = karg;
1835 struct obd_import *imp = obd->u.cli.cl_import;
1838 if (!try_module_get(THIS_MODULE)) {
1839 CERROR("Can't get module. Is it alive?");
1843 case OBD_IOC_CHANGELOG_SEND:
1844 rc = mdc_ioc_changelog_send(obd, karg);
1846 case OBD_IOC_CHANGELOG_CLEAR: {
1847 struct ioc_changelog *icc = karg;
1848 struct changelog_setinfo cs = {
1849 .cs_recno = icc->icc_recno,
1850 .cs_id = icc->icc_id
1853 rc = obd_set_info_async(NULL, exp, strlen(KEY_CHANGELOG_CLEAR),
1854 KEY_CHANGELOG_CLEAR, sizeof(cs), &cs,
1858 case OBD_IOC_FID2PATH:
1859 rc = mdc_ioc_fid2path(exp, karg);
1861 case LL_IOC_HSM_CT_START:
1862 rc = mdc_ioc_hsm_ct_start(exp, karg);
1863 /* ignore if it was already registered on this MDS. */
1867 case LL_IOC_HSM_PROGRESS:
1868 rc = mdc_ioc_hsm_progress(exp, karg);
1870 case LL_IOC_HSM_STATE_GET:
1871 rc = mdc_ioc_hsm_state_get(exp, karg);
1873 case LL_IOC_HSM_STATE_SET:
1874 rc = mdc_ioc_hsm_state_set(exp, karg);
1876 case LL_IOC_HSM_ACTION:
1877 rc = mdc_ioc_hsm_current_action(exp, karg);
1879 case LL_IOC_HSM_REQUEST:
1880 rc = mdc_ioc_hsm_request(exp, karg);
1882 case OBD_IOC_CLIENT_RECOVER:
1883 rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1, 0);
1888 case IOC_OSC_SET_ACTIVE:
1889 rc = ptlrpc_set_import_active(imp, data->ioc_offset);
1891 case OBD_IOC_POLL_QUOTACHECK:
1892 rc = mdc_quota_poll_check(exp, (struct if_quotacheck *)karg);
1894 case OBD_IOC_PING_TARGET:
1895 rc = ptlrpc_obd_ping(obd);
1898 * Normally IOC_OBD_STATFS, OBD_IOC_QUOTACTL iocontrol are handled by
1899 * LMV instead of MDC. But when the cluster is upgraded from 1.8,
1900 * there'd be no LMV layer thus we might be called here. Eventually
1901 * this code should be removed.
1904 case IOC_OBD_STATFS: {
1905 struct obd_statfs stat_buf = {0};
1907 if (*((__u32 *) data->ioc_inlbuf2) != 0) {
1913 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(obd),
1914 min_t(size_t, data->ioc_plen2,
1915 sizeof(struct obd_uuid)))) {
1920 rc = mdc_statfs(NULL, obd->obd_self_export, &stat_buf,
1921 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1926 if (copy_to_user(data->ioc_pbuf1, &stat_buf,
1927 min_t(size_t, data->ioc_plen1,
1928 sizeof(stat_buf)))) {
1936 case OBD_IOC_QUOTACTL: {
1937 struct if_quotactl *qctl = karg;
1938 struct obd_quotactl *oqctl;
1940 OBD_ALLOC_PTR(oqctl);
1941 if (oqctl == NULL) {
1946 QCTL_COPY(oqctl, qctl);
1947 rc = obd_quotactl(exp, oqctl);
1949 QCTL_COPY(qctl, oqctl);
1950 qctl->qc_valid = QC_MDTIDX;
1951 qctl->obd_uuid = obd->u.cli.cl_target_uuid;
1954 OBD_FREE_PTR(oqctl);
1957 case LL_IOC_GET_CONNECT_FLAGS:
1958 if (copy_to_user(uarg, exp_connect_flags_ptr(exp),
1959 sizeof(*exp_connect_flags_ptr(exp)))) {
1966 case LL_IOC_LOV_SWAP_LAYOUTS:
1967 rc = mdc_ioc_swap_layouts(exp, karg);
1970 CERROR("unrecognised ioctl: cmd = %#x\n", cmd);
1975 module_put(THIS_MODULE);
1980 static int mdc_get_info_rpc(struct obd_export *exp,
1981 u32 keylen, void *key,
1982 int vallen, void *val)
1984 struct obd_import *imp = class_exp2cliimp(exp);
1985 struct ptlrpc_request *req;
1989 req = ptlrpc_request_alloc(imp, &RQF_MDS_GET_INFO);
1993 req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_KEY,
1994 RCL_CLIENT, keylen);
1995 req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_VALLEN,
1996 RCL_CLIENT, sizeof(__u32));
1998 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GET_INFO);
2000 ptlrpc_request_free(req);
2004 tmp = req_capsule_client_get(&req->rq_pill, &RMF_GETINFO_KEY);
2005 memcpy(tmp, key, keylen);
2006 tmp = req_capsule_client_get(&req->rq_pill, &RMF_GETINFO_VALLEN);
2007 memcpy(tmp, &vallen, sizeof(__u32));
2009 req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_VAL,
2010 RCL_SERVER, vallen);
2011 ptlrpc_request_set_replen(req);
2013 rc = ptlrpc_queue_wait(req);
2014 /* -EREMOTE means the get_info result is partial, and it needs to
2015 * continue on another MDT, see fid2path part in lmv_iocontrol */
2016 if (rc == 0 || rc == -EREMOTE) {
2017 tmp = req_capsule_server_get(&req->rq_pill, &RMF_GETINFO_VAL);
2018 memcpy(val, tmp, vallen);
2019 if (ptlrpc_rep_need_swab(req)) {
2020 if (KEY_IS(KEY_FID2PATH))
2021 lustre_swab_fid2path(val);
2024 ptlrpc_req_finished(req);
2029 static void lustre_swab_hai(struct hsm_action_item *h)
2031 __swab32s(&h->hai_len);
2032 __swab32s(&h->hai_action);
2033 lustre_swab_lu_fid(&h->hai_fid);
2034 lustre_swab_lu_fid(&h->hai_dfid);
2035 __swab64s(&h->hai_cookie);
2036 __swab64s(&h->hai_extent.offset);
2037 __swab64s(&h->hai_extent.length);
2038 __swab64s(&h->hai_gid);
2041 static void lustre_swab_hal(struct hsm_action_list *h)
2043 struct hsm_action_item *hai;
2046 __swab32s(&h->hal_version);
2047 __swab32s(&h->hal_count);
2048 __swab32s(&h->hal_archive_id);
2049 __swab64s(&h->hal_flags);
2051 for (i = 0; i < h->hal_count; i++, hai = hai_next(hai))
2052 lustre_swab_hai(hai);
2055 static void lustre_swab_kuch(struct kuc_hdr *l)
2057 __swab16s(&l->kuc_magic);
2058 /* __u8 l->kuc_transport */
2059 __swab16s(&l->kuc_msgtype);
2060 __swab16s(&l->kuc_msglen);
2063 static int mdc_ioc_hsm_ct_start(struct obd_export *exp,
2064 struct lustre_kernelcomm *lk)
2066 struct obd_import *imp = class_exp2cliimp(exp);
2067 __u32 archive = lk->lk_data;
2070 if (lk->lk_group != KUC_GRP_HSM) {
2071 CERROR("Bad copytool group %d\n", lk->lk_group);
2075 CDEBUG(D_HSM, "CT start r%d w%d u%d g%d f%#x\n", lk->lk_rfd, lk->lk_wfd,
2076 lk->lk_uid, lk->lk_group, lk->lk_flags);
2078 if (lk->lk_flags & LK_FLG_STOP) {
2079 /* Unregister with the coordinator */
2080 rc = mdc_ioc_hsm_ct_unregister(imp);
2082 rc = mdc_ioc_hsm_ct_register(imp, archive);
2089 * Send a message to any listening copytools
2090 * @param val KUC message (kuc_hdr + hsm_action_list)
2091 * @param len total length of message
2093 static int mdc_hsm_copytool_send(int len, void *val)
2095 struct kuc_hdr *lh = (struct kuc_hdr *)val;
2096 struct hsm_action_list *hal = (struct hsm_action_list *)(lh + 1);
2099 if (len < sizeof(*lh) + sizeof(*hal)) {
2100 CERROR("Short HSM message %d < %d\n", len,
2101 (int) (sizeof(*lh) + sizeof(*hal)));
2104 if (lh->kuc_magic == __swab16(KUC_MAGIC)) {
2105 lustre_swab_kuch(lh);
2106 lustre_swab_hal(hal);
2107 } else if (lh->kuc_magic != KUC_MAGIC) {
2108 CERROR("Bad magic %x!=%x\n", lh->kuc_magic, KUC_MAGIC);
2113 "Received message mg=%x t=%d m=%d l=%d actions=%d on %s\n",
2114 lh->kuc_magic, lh->kuc_transport, lh->kuc_msgtype,
2115 lh->kuc_msglen, hal->hal_count, hal->hal_fsname);
2117 /* Broadcast to HSM listeners */
2118 rc = libcfs_kkuc_group_put(KUC_GRP_HSM, lh);
2124 * callback function passed to kuc for re-registering each HSM copytool
2125 * running on MDC, after MDT shutdown/recovery.
2126 * @param data archive id served by the copytool
2127 * @param cb_arg callback argument (obd_import)
2129 static int mdc_hsm_ct_reregister(__u32 data, void *cb_arg)
2131 struct obd_import *imp = (struct obd_import *)cb_arg;
2132 __u32 archive = data;
2135 CDEBUG(D_HA, "recover copytool registration to MDT (archive=%#x)\n",
2137 rc = mdc_ioc_hsm_ct_register(imp, archive);
2139 /* ignore error if the copytool is already registered */
2140 return ((rc != 0) && (rc != -EEXIST)) ? rc : 0;
2144 * Re-establish all kuc contexts with MDT
2145 * after MDT shutdown/recovery.
2147 static int mdc_kuc_reregister(struct obd_import *imp)
2149 /* re-register HSM agents */
2150 return libcfs_kkuc_group_foreach(KUC_GRP_HSM, mdc_hsm_ct_reregister,
2154 static int mdc_set_info_async(const struct lu_env *env,
2155 struct obd_export *exp,
2156 u32 keylen, void *key,
2157 u32 vallen, void *val,
2158 struct ptlrpc_request_set *set)
2160 struct obd_import *imp = class_exp2cliimp(exp);
2163 if (KEY_IS(KEY_READ_ONLY)) {
2164 if (vallen != sizeof(int))
2167 spin_lock(&imp->imp_lock);
2168 if (*((int *)val)) {
2169 imp->imp_connect_flags_orig |= OBD_CONNECT_RDONLY;
2170 imp->imp_connect_data.ocd_connect_flags |=
2173 imp->imp_connect_flags_orig &= ~OBD_CONNECT_RDONLY;
2174 imp->imp_connect_data.ocd_connect_flags &=
2175 ~OBD_CONNECT_RDONLY;
2177 spin_unlock(&imp->imp_lock);
2179 rc = do_set_info_async(imp, MDS_SET_INFO, LUSTRE_MDS_VERSION,
2180 keylen, key, vallen, val, set);
2183 if (KEY_IS(KEY_SPTLRPC_CONF)) {
2184 sptlrpc_conf_client_adapt(exp->exp_obd);
2187 if (KEY_IS(KEY_FLUSH_CTX)) {
2188 sptlrpc_import_flush_my_ctx(imp);
2191 if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
2192 rc = do_set_info_async(imp, MDS_SET_INFO, LUSTRE_MDS_VERSION,
2193 keylen, key, vallen, val, set);
2196 if (KEY_IS(KEY_HSM_COPYTOOL_SEND)) {
2197 rc = mdc_hsm_copytool_send(vallen, val);
2201 CERROR("Unknown key %s\n", (char *)key);
2205 static int mdc_get_info(const struct lu_env *env, struct obd_export *exp,
2206 __u32 keylen, void *key, __u32 *vallen, void *val,
2207 struct lov_stripe_md *lsm)
2211 if (KEY_IS(KEY_MAX_EASIZE)) {
2212 int mdsize, *max_easize;
2214 if (*vallen != sizeof(int))
2216 mdsize = *(int *)val;
2217 if (mdsize > exp->exp_obd->u.cli.cl_max_mds_easize)
2218 exp->exp_obd->u.cli.cl_max_mds_easize = mdsize;
2220 *max_easize = exp->exp_obd->u.cli.cl_max_mds_easize;
2222 } else if (KEY_IS(KEY_DEFAULT_EASIZE)) {
2223 int *default_easize;
2225 if (*vallen != sizeof(int))
2227 default_easize = val;
2228 *default_easize = exp->exp_obd->u.cli.cl_default_mds_easize;
2230 } else if (KEY_IS(KEY_MAX_COOKIESIZE)) {
2231 int mdsize, *max_cookiesize;
2233 if (*vallen != sizeof(int))
2235 mdsize = *(int *)val;
2236 if (mdsize > exp->exp_obd->u.cli.cl_max_mds_cookiesize)
2237 exp->exp_obd->u.cli.cl_max_mds_cookiesize = mdsize;
2238 max_cookiesize = val;
2239 *max_cookiesize = exp->exp_obd->u.cli.cl_max_mds_cookiesize;
2241 } else if (KEY_IS(KEY_DEFAULT_COOKIESIZE)) {
2242 int *default_cookiesize;
2244 if (*vallen != sizeof(int))
2246 default_cookiesize = val;
2247 *default_cookiesize =
2248 exp->exp_obd->u.cli.cl_default_mds_cookiesize;
2250 } else if (KEY_IS(KEY_CONN_DATA)) {
2251 struct obd_import *imp = class_exp2cliimp(exp);
2252 struct obd_connect_data *data = val;
2254 if (*vallen != sizeof(*data))
2257 *data = imp->imp_connect_data;
2259 } else if (KEY_IS(KEY_TGT_COUNT)) {
2264 rc = mdc_get_info_rpc(exp, keylen, key, *vallen, val);
2269 static int mdc_sync(struct obd_export *exp, const struct lu_fid *fid,
2270 struct obd_capa *oc, struct ptlrpc_request **request)
2272 struct ptlrpc_request *req;
2276 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_SYNC);
2280 mdc_set_capa_size(req, &RMF_CAPA1, oc);
2282 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_SYNC);
2284 ptlrpc_request_free(req);
2288 mdc_pack_body(req, fid, oc, 0, 0, -1, 0);
2290 ptlrpc_request_set_replen(req);
2292 rc = ptlrpc_queue_wait(req);
2294 ptlrpc_req_finished(req);
2300 static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
2301 enum obd_import_event event)
2305 LASSERT(imp->imp_obd == obd);
2308 case IMP_EVENT_DISCON: {
2310 /* XXX Pass event up to OBDs stack. used only for FLD now */
2311 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_DISCON, NULL);
2315 case IMP_EVENT_INACTIVE: {
2316 struct client_obd *cli = &obd->u.cli;
2318 * Flush current sequence to make client obtain new one
2319 * from server in case of disconnect/reconnect.
2321 if (cli->cl_seq != NULL)
2322 seq_client_flush(cli->cl_seq);
2324 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_INACTIVE, NULL);
2327 case IMP_EVENT_INVALIDATE: {
2328 struct ldlm_namespace *ns = obd->obd_namespace;
2330 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
2334 case IMP_EVENT_ACTIVE:
2335 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_ACTIVE, NULL);
2336 /* redo the kuc registration after reconnecting */
2338 rc = mdc_kuc_reregister(imp);
2341 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_OCD, NULL);
2343 case IMP_EVENT_DEACTIVATE:
2344 case IMP_EVENT_ACTIVATE:
2347 CERROR("Unknown import event %x\n", event);
2353 int mdc_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
2354 struct md_op_data *op_data)
2356 struct client_obd *cli = &exp->exp_obd->u.cli;
2357 struct lu_client_seq *seq = cli->cl_seq;
2359 return seq_client_alloc_fid(NULL, seq, fid);
2362 static struct obd_uuid *mdc_get_uuid(struct obd_export *exp)
2364 struct client_obd *cli = &exp->exp_obd->u.cli;
2366 return &cli->cl_target_uuid;
2370 * Determine whether the lock can be canceled before replaying it during
2371 * recovery, non zero value will be return if the lock can be canceled,
2372 * or zero returned for not
2374 static int mdc_cancel_for_recovery(struct ldlm_lock *lock)
2376 if (lock->l_resource->lr_type != LDLM_IBITS)
2379 /* FIXME: if we ever get into a situation where there are too many
2380 * opened files with open locks on a single node, then we really
2381 * should replay these open locks to reget it */
2382 if (lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_OPEN)
2388 static int mdc_resource_inode_free(struct ldlm_resource *res)
2390 if (res->lr_lvb_inode)
2391 res->lr_lvb_inode = NULL;
2396 static struct ldlm_valblock_ops inode_lvbo = {
2397 .lvbo_free = mdc_resource_inode_free,
2400 static int mdc_llog_init(struct obd_device *obd)
2402 struct obd_llog_group *olg = &obd->obd_olg;
2403 struct llog_ctxt *ctxt;
2406 rc = llog_setup(NULL, obd, olg, LLOG_CHANGELOG_REPL_CTXT, obd,
2411 ctxt = llog_group_get_ctxt(olg, LLOG_CHANGELOG_REPL_CTXT);
2412 llog_initiator_connect(ctxt);
2413 llog_ctxt_put(ctxt);
2418 static void mdc_llog_finish(struct obd_device *obd)
2420 struct llog_ctxt *ctxt;
2422 ctxt = llog_get_context(obd, LLOG_CHANGELOG_REPL_CTXT);
2424 llog_cleanup(NULL, ctxt);
2427 static int mdc_setup(struct obd_device *obd, struct lustre_cfg *cfg)
2429 struct client_obd *cli = &obd->u.cli;
2430 struct lprocfs_static_vars lvars = { NULL };
2433 OBD_ALLOC(cli->cl_rpc_lock, sizeof(*cli->cl_rpc_lock));
2434 if (!cli->cl_rpc_lock)
2436 mdc_init_rpc_lock(cli->cl_rpc_lock);
2440 OBD_ALLOC(cli->cl_close_lock, sizeof(*cli->cl_close_lock));
2441 if (!cli->cl_close_lock) {
2445 mdc_init_rpc_lock(cli->cl_close_lock);
2447 rc = client_obd_setup(obd, cfg);
2449 goto err_close_lock;
2450 lprocfs_mdc_init_vars(&lvars);
2451 lprocfs_obd_setup(obd, lvars.obd_vars);
2452 sptlrpc_lprocfs_cliobd_attach(obd);
2453 ptlrpc_lprocfs_register_obd(obd);
2455 ns_register_cancel(obd->obd_namespace, mdc_cancel_for_recovery);
2457 obd->obd_namespace->ns_lvbo = &inode_lvbo;
2459 rc = mdc_llog_init(obd);
2462 CERROR("failed to setup llogging subsystems\n");
2468 OBD_FREE(cli->cl_close_lock, sizeof(*cli->cl_close_lock));
2470 OBD_FREE(cli->cl_rpc_lock, sizeof(*cli->cl_rpc_lock));
2475 /* Initialize the default and maximum LOV EA and cookie sizes. This allows
2476 * us to make MDS RPCs with large enough reply buffers to hold a default
2477 * sized EA and cookie without having to calculate this (via a call into the
2478 * LOV + OSCs) each time we make an RPC. The maximum size is also tracked
2479 * but not used to avoid wastefully vmalloc()'ing large reply buffers when
2480 * a large number of stripes is possible. If a larger reply buffer is
2481 * required it will be reallocated in the ptlrpc layer due to overflow.
2483 static int mdc_init_ea_size(struct obd_export *exp, int easize,
2484 int def_easize, int cookiesize, int def_cookiesize)
2486 struct obd_device *obd = exp->exp_obd;
2487 struct client_obd *cli = &obd->u.cli;
2489 if (cli->cl_max_mds_easize < easize)
2490 cli->cl_max_mds_easize = easize;
2492 if (cli->cl_default_mds_easize < def_easize)
2493 cli->cl_default_mds_easize = def_easize;
2495 if (cli->cl_max_mds_cookiesize < cookiesize)
2496 cli->cl_max_mds_cookiesize = cookiesize;
2498 if (cli->cl_default_mds_cookiesize < def_cookiesize)
2499 cli->cl_default_mds_cookiesize = def_cookiesize;
2504 static int mdc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2507 case OBD_CLEANUP_EARLY:
2509 case OBD_CLEANUP_EXPORTS:
2510 /* Failsafe, ok if racy */
2511 if (obd->obd_type->typ_refcnt <= 1)
2512 libcfs_kkuc_group_rem(0, KUC_GRP_HSM);
2514 obd_cleanup_client_import(obd);
2515 ptlrpc_lprocfs_unregister_obd(obd);
2516 lprocfs_obd_cleanup(obd);
2518 mdc_llog_finish(obd);
2524 static int mdc_cleanup(struct obd_device *obd)
2526 struct client_obd *cli = &obd->u.cli;
2528 OBD_FREE(cli->cl_rpc_lock, sizeof(*cli->cl_rpc_lock));
2529 OBD_FREE(cli->cl_close_lock, sizeof(*cli->cl_close_lock));
2533 return client_obd_cleanup(obd);
2536 static int mdc_process_config(struct obd_device *obd, u32 len, void *buf)
2538 struct lustre_cfg *lcfg = buf;
2539 struct lprocfs_static_vars lvars = { NULL };
2542 lprocfs_mdc_init_vars(&lvars);
2543 switch (lcfg->lcfg_command) {
2545 rc = class_process_proc_param(PARAM_MDC, lvars.obd_vars,
2555 /* get remote permission for current user on fid */
2556 static int mdc_get_remote_perm(struct obd_export *exp, const struct lu_fid *fid,
2557 struct obd_capa *oc, __u32 suppgid,
2558 struct ptlrpc_request **request)
2560 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;
2602 capa = ERR_PTR(status);
2606 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
2608 capa = ERR_PTR(-EFAULT);
2612 if ((body->valid & OBD_MD_FLOSSCAPA) == 0) {
2613 capa = ERR_PTR(-ENOENT);
2617 capa = req_capsule_server_get(&req->rq_pill, &RMF_CAPA2);
2619 capa = ERR_PTR(-EFAULT);
2623 ra->ra_cb(ra->ra_oc, capa);
2627 static int mdc_renew_capa(struct obd_export *exp, struct obd_capa *oc,
2630 struct ptlrpc_request *req;
2631 struct mdc_renew_capa_args *ra;
2633 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_GETATTR,
2634 LUSTRE_MDS_VERSION, MDS_GETATTR);
2638 /* NB, OBD_MD_FLOSSCAPA is set here, but it doesn't necessarily mean the
2639 * capa to renew is oss capa.
2641 mdc_pack_body(req, &oc->c_capa.lc_fid, oc, OBD_MD_FLOSSCAPA, 0, -1, 0);
2642 ptlrpc_request_set_replen(req);
2644 CLASSERT(sizeof(*ra) <= sizeof(req->rq_async_args));
2645 ra = ptlrpc_req_async_args(req);
2648 req->rq_interpret_reply = mdc_interpret_renew_capa;
2649 ptlrpcd_add_req(req, PDL_POLICY_LOCAL, -1);
2653 static struct obd_ops mdc_obd_ops = {
2654 .o_owner = THIS_MODULE,
2655 .o_setup = mdc_setup,
2656 .o_precleanup = mdc_precleanup,
2657 .o_cleanup = mdc_cleanup,
2658 .o_add_conn = client_import_add_conn,
2659 .o_del_conn = client_import_del_conn,
2660 .o_connect = client_connect_import,
2661 .o_disconnect = client_disconnect_export,
2662 .o_iocontrol = mdc_iocontrol,
2663 .o_set_info_async = mdc_set_info_async,
2664 .o_statfs = mdc_statfs,
2665 .o_fid_init = client_fid_init,
2666 .o_fid_fini = client_fid_fini,
2667 .o_fid_alloc = mdc_fid_alloc,
2668 .o_import_event = mdc_import_event,
2669 .o_get_info = mdc_get_info,
2670 .o_process_config = mdc_process_config,
2671 .o_get_uuid = mdc_get_uuid,
2672 .o_quotactl = mdc_quotactl,
2673 .o_quotacheck = mdc_quotacheck
2676 static struct md_ops mdc_md_ops = {
2677 .m_getstatus = mdc_getstatus,
2678 .m_null_inode = mdc_null_inode,
2679 .m_find_cbdata = mdc_find_cbdata,
2680 .m_close = mdc_close,
2681 .m_create = mdc_create,
2682 .m_done_writing = mdc_done_writing,
2683 .m_enqueue = mdc_enqueue,
2684 .m_getattr = mdc_getattr,
2685 .m_getattr_name = mdc_getattr_name,
2686 .m_intent_lock = mdc_intent_lock,
2688 .m_is_subdir = mdc_is_subdir,
2689 .m_rename = mdc_rename,
2690 .m_setattr = mdc_setattr,
2691 .m_setxattr = mdc_setxattr,
2692 .m_getxattr = mdc_getxattr,
2694 .m_readpage = mdc_readpage,
2695 .m_unlink = mdc_unlink,
2696 .m_cancel_unused = mdc_cancel_unused,
2697 .m_init_ea_size = mdc_init_ea_size,
2698 .m_set_lock_data = mdc_set_lock_data,
2699 .m_lock_match = mdc_lock_match,
2700 .m_get_lustre_md = mdc_get_lustre_md,
2701 .m_free_lustre_md = mdc_free_lustre_md,
2702 .m_set_open_replay_data = mdc_set_open_replay_data,
2703 .m_clear_open_replay_data = mdc_clear_open_replay_data,
2704 .m_renew_capa = mdc_renew_capa,
2705 .m_unpack_capa = mdc_unpack_capa,
2706 .m_get_remote_perm = mdc_get_remote_perm,
2707 .m_intent_getattr_async = mdc_intent_getattr_async,
2708 .m_revalidate_lock = mdc_revalidate_lock
2711 static int __init mdc_init(void)
2713 struct lprocfs_static_vars lvars = { NULL };
2715 lprocfs_mdc_init_vars(&lvars);
2717 return class_register_type(&mdc_obd_ops, &mdc_md_ops, lvars.module_vars,
2718 LUSTRE_MDC_NAME, NULL);
2721 static void /*__exit*/ mdc_exit(void)
2723 class_unregister_type(LUSTRE_MDC_NAME);
2726 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2727 MODULE_DESCRIPTION("Lustre Metadata Client");
2728 MODULE_LICENSE("GPL");
2730 module_init(mdc_init);
2731 module_exit(mdc_exit);