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, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_MDC
39 #include <linux/module.h>
40 #include <linux/pagemap.h>
41 #include <linux/miscdevice.h>
42 #include <linux/init.h>
43 #include <linux/utsname.h>
45 #include <lustre_acl.h>
46 #include <lustre_ioctl.h>
47 #include <obd_class.h>
48 #include <lustre_lmv.h>
49 #include <lustre_fid.h>
50 #include <lprocfs_status.h>
51 #include <lustre_param.h>
52 #include <lustre_log.h>
53 #include <cl_object.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 /* obd_get_request_slot() ensures that this client has no more
96 * than cl_max_rpcs_in_flight RPCs simultaneously inf light
98 rc = obd_get_request_slot(cli);
102 rc = ptlrpc_queue_wait(req);
103 obd_put_request_slot(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->mbo_valid & OBD_MD_FLMDSCAPA) {
138 rc = mdc_unpack_capa(NULL, req, &RMF_CAPA1, pc);
143 *rootfid = body->mbo_fid1;
144 CDEBUG(D_NET, "root fid="DFID", last_committed="LPU64"\n",
145 PFID(rootfid), lustre_msg_get_last_committed(req->rq_repmsg));
148 ptlrpc_req_finished(req);
152 /* This should be mdc_get_info("rootfid") */
153 int mdc_getstatus(struct obd_export *exp, struct lu_fid *rootfid,
154 struct obd_capa **pc)
156 return send_getstatus(class_exp2cliimp(exp), rootfid, pc,
161 * This function now is known to always saying that it will receive 4 buffers
162 * from server. Even for cases when acl_size and md_size is zero, RPC header
163 * will contain 4 fields and RPC itself will contain zero size fields. This is
164 * because mdt_getattr*() _always_ returns 4 fields, but if acl is not needed
165 * and thus zero, it shrinks it, making zero size. The same story about
166 * md_size. And this is course of problem when client waits for smaller number
167 * of fields. This issue will be fixed later when client gets aware of RPC
170 static int mdc_getattr_common(struct obd_export *exp,
171 struct ptlrpc_request *req)
173 struct req_capsule *pill = &req->rq_pill;
174 struct mdt_body *body;
179 /* Request message already built. */
180 rc = ptlrpc_queue_wait(req);
184 /* sanity check for the reply */
185 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
189 CDEBUG(D_NET, "mode: %o\n", body->mbo_mode);
191 mdc_update_max_ea_from_body(exp, body);
192 if (body->mbo_eadatasize != 0) {
193 eadata = req_capsule_server_sized_get(pill, &RMF_MDT_MD,
194 body->mbo_eadatasize);
199 if (body->mbo_valid & OBD_MD_FLRMTPERM) {
200 struct mdt_remote_perm *perm;
202 LASSERT(client_is_remote(exp));
203 perm = req_capsule_server_swab_get(pill, &RMF_ACL,
204 lustre_swab_mdt_remote_perm);
209 if (body->mbo_valid & OBD_MD_FLMDSCAPA) {
210 struct lustre_capa *capa;
211 capa = req_capsule_server_get(pill, &RMF_CAPA1);
219 int mdc_getattr(struct obd_export *exp, struct md_op_data *op_data,
220 struct ptlrpc_request **request)
222 struct ptlrpc_request *req;
226 /* Single MDS without an LMV case */
227 if (op_data->op_flags & MF_GET_MDT_IDX) {
232 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR);
236 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
238 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR);
240 ptlrpc_request_free(req);
244 mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
245 op_data->op_valid, op_data->op_mode, -1, 0);
247 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER,
249 if (op_data->op_valid & OBD_MD_FLRMTPERM) {
250 LASSERT(client_is_remote(exp));
251 req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER,
252 sizeof(struct mdt_remote_perm));
254 ptlrpc_request_set_replen(req);
256 rc = mdc_getattr_common(exp, req);
258 ptlrpc_req_finished(req);
264 int mdc_getattr_name(struct obd_export *exp, struct md_op_data *op_data,
265 struct ptlrpc_request **request)
267 struct ptlrpc_request *req;
272 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
273 &RQF_MDS_GETATTR_NAME);
277 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
278 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
279 op_data->op_namelen + 1);
281 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR_NAME);
283 ptlrpc_request_free(req);
287 mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
288 op_data->op_valid, op_data->op_mode,
289 op_data->op_suppgids[0], 0);
291 if (op_data->op_name) {
292 char *name = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
293 LASSERT(strnlen(op_data->op_name, op_data->op_namelen) ==
294 op_data->op_namelen);
295 memcpy(name, op_data->op_name, op_data->op_namelen);
298 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER,
300 ptlrpc_request_set_replen(req);
302 rc = mdc_getattr_common(exp, req);
304 ptlrpc_req_finished(req);
310 static int mdc_xattr_common(struct obd_export *exp,const struct req_format *fmt,
311 const struct lu_fid *fid,
312 struct obd_capa *oc, int opcode, obd_valid valid,
313 const char *xattr_name, const char *input,
314 int input_size, int output_size, int flags,
315 __u32 suppgid, struct ptlrpc_request **request)
317 struct ptlrpc_request *req;
318 int xattr_namelen = 0;
324 req = ptlrpc_request_alloc(class_exp2cliimp(exp), fmt);
328 mdc_set_capa_size(req, &RMF_CAPA1, oc);
330 xattr_namelen = strlen(xattr_name) + 1;
331 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
336 req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_CLIENT,
340 /* Flush local XATTR locks to get rid of a possible cancel RPC */
341 if (opcode == MDS_REINT && fid_is_sane(fid) &&
342 exp->exp_connect_data.ocd_ibits_known & MDS_INODELOCK_XATTR) {
343 struct list_head cancels = LIST_HEAD_INIT(cancels);
346 /* Without that packing would fail */
348 req_capsule_set_size(&req->rq_pill, &RMF_EADATA,
351 count = mdc_resource_get_unused(exp, fid,
353 MDS_INODELOCK_XATTR);
355 rc = mdc_prep_elc_req(exp, req, MDS_REINT, &cancels, count);
357 ptlrpc_request_free(req);
361 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, opcode);
363 ptlrpc_request_free(req);
368 if (opcode == MDS_REINT) {
369 struct mdt_rec_setxattr *rec;
371 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
372 sizeof(struct mdt_rec_reint));
373 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
374 rec->sx_opcode = REINT_SETXATTR;
375 rec->sx_fsuid = from_kuid(&init_user_ns, current_fsuid());
376 rec->sx_fsgid = from_kgid(&init_user_ns, current_fsgid());
377 rec->sx_cap = cfs_curproc_cap_pack();
378 rec->sx_suppgid1 = suppgid;
379 rec->sx_suppgid2 = -1;
381 rec->sx_valid = valid | OBD_MD_FLCTIME;
382 rec->sx_time = cfs_time_current_sec();
383 rec->sx_size = output_size;
384 rec->sx_flags = flags;
386 mdc_pack_capa(req, &RMF_CAPA1, oc);
388 mdc_pack_body(req, fid, oc, valid, output_size, suppgid, flags);
392 tmp = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
393 memcpy(tmp, xattr_name, xattr_namelen);
396 tmp = req_capsule_client_get(&req->rq_pill, &RMF_EADATA);
397 memcpy(tmp, input, input_size);
400 if (req_capsule_has_field(&req->rq_pill, &RMF_EADATA, RCL_SERVER))
401 req_capsule_set_size(&req->rq_pill, &RMF_EADATA,
402 RCL_SERVER, output_size);
403 ptlrpc_request_set_replen(req);
406 if (opcode == MDS_REINT)
407 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
409 rc = ptlrpc_queue_wait(req);
411 if (opcode == MDS_REINT)
412 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
415 ptlrpc_req_finished(req);
421 int mdc_setxattr(struct obd_export *exp, const struct lu_fid *fid,
422 struct obd_capa *oc, obd_valid valid, const char *xattr_name,
423 const char *input, int input_size, int output_size,
424 int flags, __u32 suppgid, struct ptlrpc_request **request)
426 return mdc_xattr_common(exp, &RQF_MDS_REINT_SETXATTR,
427 fid, oc, MDS_REINT, valid, xattr_name,
428 input, input_size, output_size, flags,
432 int mdc_getxattr(struct obd_export *exp, const struct lu_fid *fid,
433 struct obd_capa *oc, obd_valid valid, const char *xattr_name,
434 const char *input, int input_size, int output_size,
435 int flags, struct ptlrpc_request **request)
437 return mdc_xattr_common(exp, &RQF_MDS_GETXATTR,
438 fid, oc, MDS_GETXATTR, valid, xattr_name,
439 input, input_size, output_size, flags,
443 #ifdef CONFIG_FS_POSIX_ACL
444 static int mdc_unpack_acl(struct ptlrpc_request *req, struct lustre_md *md)
446 struct req_capsule *pill = &req->rq_pill;
447 struct mdt_body *body = md->body;
448 struct posix_acl *acl;
453 if (!body->mbo_aclsize)
456 buf = req_capsule_server_sized_get(pill, &RMF_ACL, body->mbo_aclsize);
461 acl = posix_acl_from_xattr(&init_user_ns, buf, body->mbo_aclsize);
466 CERROR("convert xattr to acl: %d\n", rc);
470 rc = posix_acl_valid(acl);
472 CERROR("validate acl: %d\n", rc);
473 posix_acl_release(acl);
481 #define mdc_unpack_acl(req, md) 0
484 int mdc_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
485 struct obd_export *dt_exp, struct obd_export *md_exp,
486 struct lustre_md *md)
488 struct req_capsule *pill = &req->rq_pill;
493 memset(md, 0, sizeof(*md));
495 md->body = req_capsule_server_get(pill, &RMF_MDT_BODY);
496 LASSERT(md->body != NULL);
498 if (md->body->mbo_valid & OBD_MD_FLEASIZE) {
500 struct lov_mds_md *lmm;
502 if (!S_ISREG(md->body->mbo_mode)) {
503 CDEBUG(D_INFO, "OBD_MD_FLEASIZE set, should be a "
504 "regular file, but is not\n");
505 GOTO(out, rc = -EPROTO);
508 if (md->body->mbo_eadatasize == 0) {
509 CDEBUG(D_INFO, "OBD_MD_FLEASIZE set, "
510 "but eadatasize 0\n");
511 GOTO(out, rc = -EPROTO);
514 lmmsize = md->body->mbo_eadatasize;
515 lmm = req_capsule_server_sized_get(pill, &RMF_MDT_MD, lmmsize);
517 GOTO(out, rc = -EPROTO);
519 rc = obd_unpackmd(dt_exp, &md->lsm, lmm, lmmsize);
523 if (rc < sizeof(*md->lsm)) {
524 CDEBUG(D_INFO, "lsm size too small: "
525 "rc < sizeof (*md->lsm) (%d < %d)\n",
526 rc, (int)sizeof(*md->lsm));
527 GOTO(out, rc = -EPROTO);
530 } else if (md->body->mbo_valid & OBD_MD_FLDIREA) {
532 struct lov_mds_md *lmv;
534 if (!S_ISDIR(md->body->mbo_mode)) {
535 CDEBUG(D_INFO, "OBD_MD_FLDIREA set, should be a "
536 "directory, but is not\n");
537 GOTO(out, rc = -EPROTO);
540 if (md->body->mbo_eadatasize == 0) {
541 CDEBUG(D_INFO, "OBD_MD_FLDIREA is set, "
542 "but eadatasize 0\n");
546 if (md->body->mbo_valid & OBD_MD_MEA) {
547 lmvsize = md->body->mbo_eadatasize;
548 lmv = req_capsule_server_sized_get(pill, &RMF_MDT_MD,
551 GOTO(out, rc = -EPROTO);
553 rc = obd_unpackmd(md_exp, (void *)&md->lmv, lmv,
558 if (rc < sizeof(*md->lmv)) {
559 CDEBUG(D_INFO, "size too small: "
560 "rc < sizeof(*md->lmv) (%d < %d)\n",
561 rc, (int)sizeof(*md->lmv));
562 GOTO(out, rc = -EPROTO);
568 if (md->body->mbo_valid & OBD_MD_FLRMTPERM) {
569 /* remote permission */
570 LASSERT(client_is_remote(exp));
571 md->remote_perm = req_capsule_server_swab_get(pill, &RMF_ACL,
572 lustre_swab_mdt_remote_perm);
573 if (!md->remote_perm)
574 GOTO(out, rc = -EPROTO);
575 } else if (md->body->mbo_valid & OBD_MD_FLACL) {
576 /* for ACL, it's possible that FLACL is set but aclsize is zero.
577 * only when aclsize != 0 there's an actual segment for ACL
580 if (md->body->mbo_aclsize) {
581 rc = mdc_unpack_acl(req, md);
584 #ifdef CONFIG_FS_POSIX_ACL
586 md->posix_acl = NULL;
590 if (md->body->mbo_valid & OBD_MD_FLMDSCAPA) {
591 struct obd_capa *oc = NULL;
593 rc = mdc_unpack_capa(NULL, req, &RMF_CAPA1, &oc);
599 if (md->body->mbo_valid & OBD_MD_FLOSSCAPA) {
600 struct obd_capa *oc = NULL;
602 rc = mdc_unpack_capa(NULL, req, &RMF_CAPA2, &oc);
612 capa_put(md->oss_capa);
616 capa_put(md->mds_capa);
619 #ifdef CONFIG_FS_POSIX_ACL
620 posix_acl_release(md->posix_acl);
623 obd_free_memmd(dt_exp, &md->lsm);
628 int mdc_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
635 * Handles both OPEN and SETATTR RPCs for OPEN-CLOSE and SETATTR-DONE_WRITING
638 void mdc_replay_open(struct ptlrpc_request *req)
640 struct md_open_data *mod = req->rq_cb_data;
641 struct ptlrpc_request *close_req;
642 struct obd_client_handle *och;
643 struct lustre_handle old;
644 struct mdt_body *body;
648 DEBUG_REQ(D_ERROR, req,
649 "Can't properly replay without open data.");
654 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
655 LASSERT(body != NULL);
659 struct lustre_handle *file_fh;
661 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
663 file_fh = &och->och_fh;
664 CDEBUG(D_HA, "updating handle from "LPX64" to "LPX64"\n",
665 file_fh->cookie, body->mbo_handle.cookie);
667 *file_fh = body->mbo_handle;
669 close_req = mod->mod_close_req;
670 if (close_req != NULL) {
671 __u32 opc = lustre_msg_get_opc(close_req->rq_reqmsg);
672 struct mdt_ioepoch *epoch;
674 LASSERT(opc == MDS_CLOSE || opc == MDS_DONE_WRITING);
675 epoch = req_capsule_client_get(&close_req->rq_pill,
680 LASSERT(!memcmp(&old, &epoch->handle, sizeof(old)));
681 DEBUG_REQ(D_HA, close_req, "updating close body with new fh");
682 epoch->handle = body->mbo_handle;
687 void mdc_commit_open(struct ptlrpc_request *req)
689 struct md_open_data *mod = req->rq_cb_data;
694 * No need to touch md_open_data::mod_och, it holds a reference on
695 * \var mod and will zero references to each other, \var mod will be
696 * freed after that when md_open_data::mod_och will put the reference.
700 * Do not let open request to disappear as it still may be needed
701 * for close rpc to happen (it may happen on evict only, otherwise
702 * ptlrpc_request::rq_replay does not let mdc_commit_open() to be
703 * called), just mark this rpc as committed to distinguish these 2
704 * cases, see mdc_close() for details. The open request reference will
705 * be put along with freeing \var mod.
707 ptlrpc_request_addref(req);
708 spin_lock(&req->rq_lock);
709 req->rq_committed = 1;
710 spin_unlock(&req->rq_lock);
711 req->rq_cb_data = NULL;
715 int mdc_set_open_replay_data(struct obd_export *exp,
716 struct obd_client_handle *och,
717 struct lookup_intent *it)
719 struct md_open_data *mod;
720 struct mdt_rec_create *rec;
721 struct mdt_body *body;
722 struct ptlrpc_request *open_req = it->d.lustre.it_data;
723 struct obd_import *imp = open_req->rq_import;
726 if (!open_req->rq_replay)
729 rec = req_capsule_client_get(&open_req->rq_pill, &RMF_REC_REINT);
730 body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY);
731 LASSERT(rec != NULL);
732 /* Incoming message in my byte order (it's been swabbed). */
733 /* Outgoing messages always in my byte order. */
734 LASSERT(body != NULL);
736 /* Only if the import is replayable, we set replay_open data */
737 if (och && imp->imp_replayable) {
738 mod = obd_mod_alloc();
740 DEBUG_REQ(D_ERROR, open_req,
741 "Can't allocate md_open_data");
746 * Take a reference on \var mod, to be freed on mdc_close().
747 * It protects \var mod from being freed on eviction (commit
748 * callback is called despite rq_replay flag).
749 * Another reference for \var och.
754 spin_lock(&open_req->rq_lock);
757 mod->mod_is_create = it_disposition(it, DISP_OPEN_CREATE) ||
758 it_disposition(it, DISP_OPEN_STRIPE);
759 mod->mod_open_req = open_req;
760 open_req->rq_cb_data = mod;
761 open_req->rq_commit_cb = mdc_commit_open;
762 spin_unlock(&open_req->rq_lock);
765 rec->cr_fid2 = body->mbo_fid1;
766 rec->cr_ioepoch = body->mbo_ioepoch;
767 rec->cr_old_handle.cookie = body->mbo_handle.cookie;
768 open_req->rq_replay_cb = mdc_replay_open;
769 if (!fid_is_sane(&body->mbo_fid1)) {
770 DEBUG_REQ(D_ERROR, open_req, "Saving replay request with "
775 DEBUG_REQ(D_RPCTRACE, open_req, "Set up open replay data");
779 static void mdc_free_open(struct md_open_data *mod)
783 if (mod->mod_is_create == 0 &&
784 imp_connect_disp_stripe(mod->mod_open_req->rq_import))
787 LASSERT(mod->mod_open_req->rq_replay == 0);
789 DEBUG_REQ(D_RPCTRACE, mod->mod_open_req, "free open request\n");
791 ptlrpc_request_committed(mod->mod_open_req, committed);
792 if (mod->mod_close_req)
793 ptlrpc_request_committed(mod->mod_close_req, committed);
796 int mdc_clear_open_replay_data(struct obd_export *exp,
797 struct obd_client_handle *och)
799 struct md_open_data *mod = och->och_mod;
803 * It is possible to not have \var mod in a case of eviction between
804 * lookup and ll_file_open().
809 LASSERT(mod != LP_POISON);
810 LASSERT(mod->mod_open_req != NULL);
820 /* Prepares the request for the replay by the given reply */
821 static void mdc_close_handle_reply(struct ptlrpc_request *req,
822 struct md_op_data *op_data, int rc) {
823 struct mdt_body *repbody;
824 struct mdt_ioepoch *epoch;
826 if (req && rc == -EAGAIN) {
827 repbody = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
828 epoch = req_capsule_client_get(&req->rq_pill, &RMF_MDT_EPOCH);
830 epoch->flags |= MF_SOM_AU;
831 if (repbody->mbo_valid & OBD_MD_FLGETATTRLOCK)
832 op_data->op_flags |= MF_GETATTR_LOCK;
836 int mdc_close(struct obd_export *exp, struct md_op_data *op_data,
837 struct md_open_data *mod, struct ptlrpc_request **request)
839 struct obd_device *obd = class_exp2obd(exp);
840 struct ptlrpc_request *req;
841 struct req_format *req_fmt;
846 req_fmt = &RQF_MDS_CLOSE;
847 if (op_data->op_bias & MDS_HSM_RELEASE) {
848 req_fmt = &RQF_MDS_RELEASE_CLOSE;
850 /* allocate a FID for volatile file */
851 rc = mdc_fid_alloc(NULL, exp, &op_data->op_fid2, op_data);
853 CERROR("%s: "DFID" failed to allocate FID: %d\n",
854 obd->obd_name, PFID(&op_data->op_fid1), rc);
855 /* save the errcode and proceed to close */
861 req = ptlrpc_request_alloc(class_exp2cliimp(exp), req_fmt);
865 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
867 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_CLOSE);
869 ptlrpc_request_free(req);
873 /* To avoid a livelock (bug 7034), we need to send CLOSE RPCs to a
874 * portal whose threads are not taking any DLM locks and are therefore
875 * always progressing */
876 req->rq_request_portal = MDS_READPAGE_PORTAL;
877 ptlrpc_at_set_req_timeout(req);
879 /* Ensure that this close's handle is fixed up during replay. */
880 if (likely(mod != NULL)) {
881 LASSERTF(mod->mod_open_req != NULL &&
882 mod->mod_open_req->rq_type != LI_POISON,
883 "POISONED open %p!\n", mod->mod_open_req);
885 mod->mod_close_req = req;
887 DEBUG_REQ(D_HA, mod->mod_open_req, "matched open");
888 /* We no longer want to preserve this open for replay even
889 * though the open was committed. b=3632, b=3633 */
890 spin_lock(&mod->mod_open_req->rq_lock);
891 mod->mod_open_req->rq_replay = 0;
892 spin_unlock(&mod->mod_open_req->rq_lock);
894 CDEBUG(D_HA, "couldn't find open req; expecting close error\n");
897 mdc_close_pack(req, op_data);
899 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER,
900 obd->u.cli.cl_default_mds_easize);
901 req_capsule_set_size(&req->rq_pill, &RMF_LOGCOOKIES, RCL_SERVER,
902 obd->u.cli.cl_default_mds_cookiesize);
904 ptlrpc_request_set_replen(req);
906 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
907 rc = ptlrpc_queue_wait(req);
908 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
910 if (req->rq_repmsg == NULL) {
911 CDEBUG(D_RPCTRACE, "request failed to send: %p, %d\n", req,
914 rc = req->rq_status ?: -EIO;
915 } else if (rc == 0 || rc == -EAGAIN) {
916 struct mdt_body *body;
918 rc = lustre_msg_get_status(req->rq_repmsg);
919 if (lustre_msg_get_type(req->rq_repmsg) == PTL_RPC_MSG_ERR) {
920 DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, err "
925 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
928 } else if (rc == -ESTALE) {
930 * it can be allowed error after 3633 if open was committed and
931 * server failed before close was sent. Let's check if mod
932 * exists and return no error in that case
935 DEBUG_REQ(D_HA, req, "Reset ESTALE = %d", rc);
936 LASSERT(mod->mod_open_req != NULL);
937 if (mod->mod_open_req->rq_committed)
944 mod->mod_close_req = NULL;
945 /* Since now, mod is accessed through open_req only,
946 * thus close req does not keep a reference on mod anymore. */
950 mdc_close_handle_reply(req, op_data, rc);
951 RETURN(rc < 0 ? rc : saved_rc);
954 int mdc_done_writing(struct obd_export *exp, struct md_op_data *op_data,
955 struct md_open_data *mod)
957 struct obd_device *obd = class_exp2obd(exp);
958 struct ptlrpc_request *req;
962 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
963 &RQF_MDS_DONE_WRITING);
967 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
968 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_DONE_WRITING);
970 ptlrpc_request_free(req);
975 LASSERTF(mod->mod_open_req != NULL &&
976 mod->mod_open_req->rq_type != LI_POISON,
977 "POISONED setattr %p!\n", mod->mod_open_req);
979 mod->mod_close_req = req;
980 DEBUG_REQ(D_HA, mod->mod_open_req, "matched setattr");
981 /* We no longer want to preserve this setattr for replay even
982 * though the open was committed. b=3632, b=3633 */
983 spin_lock(&mod->mod_open_req->rq_lock);
984 mod->mod_open_req->rq_replay = 0;
985 spin_unlock(&mod->mod_open_req->rq_lock);
988 mdc_close_pack(req, op_data);
989 ptlrpc_request_set_replen(req);
991 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
992 rc = ptlrpc_queue_wait(req);
993 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
997 * it can be allowed error after 3633 if open or setattr were
998 * committed and server failed before close was sent.
999 * Let's check if mod exists and return no error in that case
1002 LASSERT(mod->mod_open_req != NULL);
1003 if (mod->mod_open_req->rq_committed)
1010 mod->mod_close_req = NULL;
1011 LASSERT(mod->mod_open_req != NULL);
1014 /* Since now, mod is accessed through setattr req only,
1015 * thus DW req does not keep a reference on mod anymore. */
1019 mdc_close_handle_reply(req, op_data, rc);
1020 ptlrpc_req_finished(req);
1024 #ifdef HAVE_SPLIT_SUPPORT
1025 int mdc_sendpage(struct obd_export *exp, const struct lu_fid *fid,
1026 const struct page *page, int offset)
1028 struct ptlrpc_request *req;
1029 struct ptlrpc_bulk_desc *desc;
1033 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_WRITEPAGE);
1037 /* FIXME: capa doesn't support split yet */
1038 mdc_set_capa_size(req, &RMF_CAPA1, NULL);
1040 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_WRITEPAGE);
1042 ptlrpc_request_free(req);
1046 req->rq_request_portal = MDS_READPAGE_PORTAL;
1047 ptlrpc_at_set_req_timeout(req);
1049 desc = ptlrpc_prep_bulk_imp(req, 1, 1,BULK_GET_SOURCE, MDS_BULK_PORTAL);
1051 GOTO(out, rc = -ENOMEM);
1053 /* NB req now owns desc and will free it when it gets freed. */
1054 ptlrpc_prep_bulk_page(desc, (struct page *)page, 0, offset);
1055 mdc_readdir_pack(req, 0, offset, fid, NULL);
1057 ptlrpc_request_set_replen(req);
1058 rc = ptlrpc_queue_wait(req);
1062 rc = sptlrpc_cli_unwrap_bulk_write(req, req->rq_bulk);
1064 ptlrpc_req_finished(req);
1067 EXPORT_SYMBOL(mdc_sendpage);
1070 static int mdc_getpage(struct obd_export *exp, const struct lu_fid *fid,
1071 __u64 offset, struct obd_capa *oc,
1072 struct page **pages, int npages,
1073 struct ptlrpc_request **request)
1075 struct ptlrpc_request *req;
1076 struct ptlrpc_bulk_desc *desc;
1078 wait_queue_head_t waitq;
1080 struct l_wait_info lwi;
1085 init_waitqueue_head(&waitq);
1088 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_READPAGE);
1092 mdc_set_capa_size(req, &RMF_CAPA1, oc);
1094 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_READPAGE);
1096 ptlrpc_request_free(req);
1100 req->rq_request_portal = MDS_READPAGE_PORTAL;
1101 ptlrpc_at_set_req_timeout(req);
1103 desc = ptlrpc_prep_bulk_imp(req, npages, 1, BULK_PUT_SINK,
1106 ptlrpc_request_free(req);
1110 /* NB req now owns desc and will free it when it gets freed */
1111 for (i = 0; i < npages; i++)
1112 ptlrpc_prep_bulk_page_pin(desc, pages[i], 0, PAGE_CACHE_SIZE);
1114 mdc_readdir_pack(req, offset, PAGE_CACHE_SIZE * npages, fid, oc);
1116 ptlrpc_request_set_replen(req);
1117 rc = ptlrpc_queue_wait(req);
1119 ptlrpc_req_finished(req);
1120 if (rc != -ETIMEDOUT)
1124 if (!client_should_resend(resends, &exp->exp_obd->u.cli)) {
1125 CERROR("%s: too many resend retries: rc = %d\n",
1126 exp->exp_obd->obd_name, -EIO);
1129 lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(resends), NULL, NULL,
1131 l_wait_event(waitq, 0, &lwi);
1136 rc = sptlrpc_cli_unwrap_bulk_read(req, req->rq_bulk,
1137 req->rq_bulk->bd_nob_transferred);
1139 ptlrpc_req_finished(req);
1143 if (req->rq_bulk->bd_nob_transferred & ~LU_PAGE_MASK) {
1144 CERROR("%s: unexpected bytes transferred: %d (%ld expected)\n",
1145 exp->exp_obd->obd_name, req->rq_bulk->bd_nob_transferred,
1146 PAGE_CACHE_SIZE * npages);
1147 ptlrpc_req_finished(req);
1155 static void mdc_release_page(struct page *page, int remove)
1159 if (likely(page->mapping != NULL))
1160 truncate_complete_page(page->mapping, page);
1163 page_cache_release(page);
1166 static struct page *mdc_page_locate(struct address_space *mapping, __u64 *hash,
1167 __u64 *start, __u64 *end, int hash64)
1170 * Complement of hash is used as an index so that
1171 * radix_tree_gang_lookup() can be used to find a page with starting
1172 * hash _smaller_ than one we are looking for.
1174 unsigned long offset = hash_x_index(*hash, hash64);
1178 spin_lock_irq(&mapping->tree_lock);
1179 found = radix_tree_gang_lookup(&mapping->page_tree,
1180 (void **)&page, offset, 1);
1181 if (found > 0 && !radix_tree_exceptional_entry(page)) {
1182 struct lu_dirpage *dp;
1184 page_cache_get(page);
1185 spin_unlock_irq(&mapping->tree_lock);
1187 * In contrast to find_lock_page() we are sure that directory
1188 * page cannot be truncated (while DLM lock is held) and,
1189 * hence, can avoid restart.
1191 * In fact, page cannot be locked here at all, because
1192 * mdc_read_page_remote does synchronous io.
1194 wait_on_page_locked(page);
1195 if (PageUptodate(page)) {
1197 if (BITS_PER_LONG == 32 && hash64) {
1198 *start = le64_to_cpu(dp->ldp_hash_start) >> 32;
1199 *end = le64_to_cpu(dp->ldp_hash_end) >> 32;
1200 *hash = *hash >> 32;
1202 *start = le64_to_cpu(dp->ldp_hash_start);
1203 *end = le64_to_cpu(dp->ldp_hash_end);
1205 if (unlikely(*start == 1 && *hash == 0))
1208 LASSERTF(*start <= *hash, "start = "LPX64
1209 ",end = "LPX64",hash = "LPX64"\n",
1210 *start, *end, *hash);
1211 CDEBUG(D_VFSTRACE, "offset %lx ["LPX64" "LPX64"],"
1212 " hash "LPX64"\n", offset, *start, *end, *hash);
1215 mdc_release_page(page, 0);
1217 } else if (*end != *start && *hash == *end) {
1219 * upon hash collision, remove this page,
1220 * otherwise put page reference, and
1221 * mdc_read_page_remote() will issue RPC to
1222 * fetch the page we want.
1225 mdc_release_page(page,
1226 le32_to_cpu(dp->ldp_flags) & LDF_COLLIDE);
1230 page_cache_release(page);
1231 page = ERR_PTR(-EIO);
1234 spin_unlock_irq(&mapping->tree_lock);
1241 * Adjust a set of pages, each page containing an array of lu_dirpages,
1242 * so that each page can be used as a single logical lu_dirpage.
1244 * A lu_dirpage is laid out as follows, where s = ldp_hash_start,
1245 * e = ldp_hash_end, f = ldp_flags, p = padding, and each "ent" is a
1246 * struct lu_dirent. It has size up to LU_PAGE_SIZE. The ldp_hash_end
1247 * value is used as a cookie to request the next lu_dirpage in a
1248 * directory listing that spans multiple pages (two in this example):
1251 * .|--------v------- -----.
1252 * |s|e|f|p|ent|ent| ... |ent|
1253 * '--|-------------- -----' Each CFS_PAGE contains a single
1254 * '------. lu_dirpage.
1255 * .---------v------- -----.
1256 * |s|e|f|p|ent| 0 | ... | 0 |
1257 * '----------------- -----'
1259 * However, on hosts where the native VM page size (PAGE_CACHE_SIZE) is
1260 * larger than LU_PAGE_SIZE, a single host page may contain multiple
1261 * lu_dirpages. After reading the lu_dirpages from the MDS, the
1262 * ldp_hash_end of the first lu_dirpage refers to the one immediately
1263 * after it in the same CFS_PAGE (arrows simplified for brevity, but
1264 * in general e0==s1, e1==s2, etc.):
1266 * .-------------------- -----.
1267 * |s0|e0|f0|p|ent|ent| ... |ent|
1268 * |---v---------------- -----|
1269 * |s1|e1|f1|p|ent|ent| ... |ent|
1270 * |---v---------------- -----| Here, each CFS_PAGE contains
1271 * ... multiple lu_dirpages.
1272 * |---v---------------- -----|
1273 * |s'|e'|f'|p|ent|ent| ... |ent|
1274 * '---|---------------- -----'
1276 * .----------------------------.
1279 * This structure is transformed into a single logical lu_dirpage as follows:
1281 * - Replace e0 with e' so the request for the next lu_dirpage gets the page
1282 * labeled 'next CFS_PAGE'.
1284 * - Copy the LDF_COLLIDE flag from f' to f0 to correctly reflect whether
1285 * a hash collision with the next page exists.
1287 * - Adjust the lde_reclen of the ending entry of each lu_dirpage to span
1288 * to the first entry of the next lu_dirpage.
1290 #if PAGE_CACHE_SIZE > LU_PAGE_SIZE
1291 static void mdc_adjust_dirpages(struct page **pages, int cfs_pgs, int lu_pgs)
1295 for (i = 0; i < cfs_pgs; i++) {
1296 struct lu_dirpage *dp = kmap(pages[i]);
1297 struct lu_dirpage *first = dp;
1298 struct lu_dirent *end_dirent = NULL;
1299 struct lu_dirent *ent;
1300 __u64 hash_end = le64_to_cpu(dp->ldp_hash_end);
1301 __u32 flags = le32_to_cpu(dp->ldp_flags);
1303 while (--lu_pgs > 0) {
1304 ent = lu_dirent_start(dp);
1305 for (end_dirent = ent; ent != NULL;
1306 end_dirent = ent, ent = lu_dirent_next(ent));
1308 /* Advance dp to next lu_dirpage. */
1309 dp = (struct lu_dirpage *)((char *)dp + LU_PAGE_SIZE);
1311 /* Check if we've reached the end of the CFS_PAGE. */
1312 if (!((unsigned long)dp & ~CFS_PAGE_MASK))
1315 /* Save the hash and flags of this lu_dirpage. */
1316 hash_end = le64_to_cpu(dp->ldp_hash_end);
1317 flags = le32_to_cpu(dp->ldp_flags);
1319 /* Check if lu_dirpage contains no entries. */
1320 if (end_dirent == NULL)
1323 /* Enlarge the end entry lde_reclen from 0 to
1324 * first entry of next lu_dirpage. */
1325 LASSERT(le16_to_cpu(end_dirent->lde_reclen) == 0);
1326 end_dirent->lde_reclen =
1327 cpu_to_le16((char *)(dp->ldp_entries) -
1328 (char *)end_dirent);
1331 first->ldp_hash_end = hash_end;
1332 first->ldp_flags &= ~cpu_to_le32(LDF_COLLIDE);
1333 first->ldp_flags |= flags & cpu_to_le32(LDF_COLLIDE);
1337 LASSERTF(lu_pgs == 0, "left = %d\n", lu_pgs);
1340 #define mdc_adjust_dirpages(pages, cfs_pgs, lu_pgs) do {} while (0)
1341 #endif /* PAGE_CACHE_SIZE > LU_PAGE_SIZE */
1343 /* parameters for readdir page */
1344 struct readpage_param {
1345 struct md_op_data *rp_mod;
1348 struct obd_export *rp_exp;
1349 struct md_callback *rp_cb;
1353 * Read pages from server.
1355 * Page in MDS_READPAGE RPC is packed in LU_PAGE_SIZE, and each page contains
1356 * a header lu_dirpage which describes the start/end hash, and whether this
1357 * page is empty (contains no dir entry) or hash collide with next page.
1358 * After client receives reply, several pages will be integrated into dir page
1359 * in CFS_PAGE_SIZE (if CFS_PAGE_SIZE greater than LU_PAGE_SIZE), and the
1360 * lu_dirpage for this integrated page will be adjusted.
1362 static int mdc_read_page_remote(void *data, struct page *page0)
1364 struct readpage_param *rp = data;
1365 struct page **page_pool;
1367 struct lu_dirpage *dp;
1368 int rd_pgs = 0; /* number of pages read actually */
1370 struct md_op_data *op_data = rp->rp_mod;
1371 struct ptlrpc_request *req;
1372 int max_pages = op_data->op_max_pages;
1373 struct inode *inode;
1379 LASSERT(max_pages > 0 && max_pages <= PTLRPC_MAX_BRW_PAGES);
1380 inode = op_data->op_data;
1381 fid = &op_data->op_fid1;
1382 LASSERT(inode != NULL);
1384 OBD_ALLOC(page_pool, sizeof(page_pool[0]) * max_pages);
1385 if (page_pool != NULL) {
1386 page_pool[0] = page0;
1392 for (npages = 1; npages < max_pages; npages++) {
1393 page = page_cache_alloc_cold(inode->i_mapping);
1396 page_pool[npages] = page;
1399 rc = mdc_getpage(rp->rp_exp, fid, rp->rp_off, op_data->op_capa1,
1400 page_pool, npages, &req);
1404 rd_pgs = (req->rq_bulk->bd_nob_transferred +
1405 PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
1406 lu_pgs = req->rq_bulk->bd_nob_transferred >>
1408 LASSERT(!(req->rq_bulk->bd_nob_transferred & ~LU_PAGE_MASK));
1410 CDEBUG(D_INODE, "read %d(%d)/%d pages\n", rd_pgs, lu_pgs,
1411 op_data->op_npages);
1413 mdc_adjust_dirpages(page_pool, rd_pgs, lu_pgs);
1415 SetPageUptodate(page0);
1419 ptlrpc_req_finished(req);
1420 CDEBUG(D_CACHE, "read %d/%d pages\n", rd_pgs, npages);
1421 for (i = 1; i < npages; i++) {
1422 unsigned long offset;
1426 page = page_pool[i];
1428 if (rc < 0 || i >= rd_pgs) {
1429 page_cache_release(page);
1433 SetPageUptodate(page);
1436 hash = le64_to_cpu(dp->ldp_hash_start);
1439 offset = hash_x_index(hash, rp->rp_hash64);
1441 prefetchw(&page->flags);
1442 ret = add_to_page_cache_lru(page, inode->i_mapping, offset,
1447 CDEBUG(D_VFSTRACE, "page %lu add to page cache failed:"
1448 " rc = %d\n", offset, ret);
1449 page_cache_release(page);
1452 if (page_pool != &page0)
1453 OBD_FREE(page_pool, sizeof(page_pool[0]) * max_pages);
1459 * Read dir page from cache first, if it can not find it, read it from
1460 * server and add into the cache.
1462 * \param[in] exp MDC export
1463 * \param[in] op_data client MD stack parameters, transfering parameters
1464 * between different layers on client MD stack.
1465 * \param[in] cb_op callback required for ldlm lock enqueue during
1467 * \param[in] hash_offset the hash offset of the page to be read
1468 * \param[in] ppage the page to be read
1470 * retval = 0 get the page successfully
1471 * errno(<0) get the page failed
1473 static int mdc_read_page(struct obd_export *exp, struct md_op_data *op_data,
1474 struct md_callback *cb_op, __u64 hash_offset,
1475 struct page **ppage)
1477 struct lookup_intent it = { .it_op = IT_READDIR };
1479 struct inode *dir = op_data->op_data;
1480 struct address_space *mapping;
1481 struct lu_dirpage *dp;
1484 struct lustre_handle lockh;
1485 struct ptlrpc_request *enq_req = NULL;
1486 struct readpage_param rp_param;
1493 LASSERT(dir != NULL);
1494 mapping = dir->i_mapping;
1496 rc = mdc_intent_lock(exp, op_data, &it, &enq_req,
1497 cb_op->md_blocking_ast, 0);
1498 if (enq_req != NULL)
1499 ptlrpc_req_finished(enq_req);
1502 CERROR("%s: "DFID" lock enqueue fails: rc = %d\n",
1503 exp->exp_obd->obd_name, PFID(&op_data->op_fid1), rc);
1508 mdc_set_lock_data(exp, &it.d.lustre.it_lock_handle, dir, NULL);
1510 rp_param.rp_off = hash_offset;
1511 rp_param.rp_hash64 = op_data->op_cli_flags & CLI_HASH64;
1512 page = mdc_page_locate(mapping, &rp_param.rp_off, &start, &end,
1513 rp_param.rp_hash64);
1515 CERROR("%s: dir page locate: "DFID" at "LPU64": rc %ld\n",
1516 exp->exp_obd->obd_name, PFID(&op_data->op_fid1),
1517 rp_param.rp_off, PTR_ERR(page));
1518 GOTO(out_unlock, rc = PTR_ERR(page));
1519 } else if (page != NULL) {
1521 * XXX nikita: not entirely correct handling of a corner case:
1522 * suppose hash chain of entries with hash value HASH crosses
1523 * border between pages P0 and P1. First both P0 and P1 are
1524 * cached, seekdir() is called for some entry from the P0 part
1525 * of the chain. Later P0 goes out of cache. telldir(HASH)
1526 * happens and finds P1, as it starts with matching hash
1527 * value. Remaining entries from P0 part of the chain are
1528 * skipped. (Is that really a bug?)
1530 * Possible solutions: 0. don't cache P1 is such case, handle
1531 * it as an "overflow" page. 1. invalidate all pages at
1532 * once. 2. use HASH|1 as an index for P1.
1534 GOTO(hash_collision, page);
1537 rp_param.rp_exp = exp;
1538 rp_param.rp_mod = op_data;
1539 page = read_cache_page(mapping,
1540 hash_x_index(rp_param.rp_off,
1541 rp_param.rp_hash64),
1542 mdc_read_page_remote, &rp_param);
1544 CERROR("%s: read cache page: "DFID" at "LPU64": rc %ld\n",
1545 exp->exp_obd->obd_name, PFID(&op_data->op_fid1),
1546 rp_param.rp_off, PTR_ERR(page));
1547 GOTO(out_unlock, rc = PTR_ERR(page));
1550 wait_on_page_locked(page);
1552 if (!PageUptodate(page)) {
1553 CERROR("%s: page not updated: "DFID" at "LPU64": rc %d\n",
1554 exp->exp_obd->obd_name, PFID(&op_data->op_fid1),
1555 rp_param.rp_off, -5);
1558 if (!PageChecked(page))
1559 SetPageChecked(page);
1560 if (PageError(page)) {
1561 CERROR("%s: page error: "DFID" at "LPU64": rc %d\n",
1562 exp->exp_obd->obd_name, PFID(&op_data->op_fid1),
1563 rp_param.rp_off, -5);
1568 dp = page_address(page);
1569 if (BITS_PER_LONG == 32 && rp_param.rp_hash64) {
1570 start = le64_to_cpu(dp->ldp_hash_start) >> 32;
1571 end = le64_to_cpu(dp->ldp_hash_end) >> 32;
1572 rp_param.rp_off = hash_offset >> 32;
1574 start = le64_to_cpu(dp->ldp_hash_start);
1575 end = le64_to_cpu(dp->ldp_hash_end);
1576 rp_param.rp_off = hash_offset;
1579 LASSERT(start == rp_param.rp_off);
1580 CWARN("Page-wide hash collision: %#lx\n", (unsigned long)end);
1581 #if BITS_PER_LONG == 32
1582 CWARN("Real page-wide hash collision at ["LPU64" "LPU64"] with "
1583 "hash "LPU64"\n", le64_to_cpu(dp->ldp_hash_start),
1584 le64_to_cpu(dp->ldp_hash_end), hash_offset);
1588 * Fetch whole overflow chain...
1596 lockh.cookie = it.d.lustre.it_lock_handle;
1597 ldlm_lock_decref(&lockh, it.d.lustre.it_lock_mode);
1598 it.d.lustre.it_lock_handle = 0;
1602 mdc_release_page(page, 1);
1608 static int mdc_statfs(const struct lu_env *env,
1609 struct obd_export *exp, struct obd_statfs *osfs,
1610 __u64 max_age, __u32 flags)
1612 struct obd_device *obd = class_exp2obd(exp);
1613 struct ptlrpc_request *req;
1614 struct obd_statfs *msfs;
1615 struct obd_import *imp = NULL;
1620 * Since the request might also come from lprocfs, so we need
1621 * sync this with client_disconnect_export Bug15684
1623 down_read(&obd->u.cli.cl_sem);
1624 if (obd->u.cli.cl_import)
1625 imp = class_import_get(obd->u.cli.cl_import);
1626 up_read(&obd->u.cli.cl_sem);
1630 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_STATFS,
1631 LUSTRE_MDS_VERSION, MDS_STATFS);
1633 GOTO(output, rc = -ENOMEM);
1635 ptlrpc_request_set_replen(req);
1637 if (flags & OBD_STATFS_NODELAY) {
1638 /* procfs requests not want stay in wait for avoid deadlock */
1639 req->rq_no_resend = 1;
1640 req->rq_no_delay = 1;
1643 rc = ptlrpc_queue_wait(req);
1645 /* check connection error first */
1646 if (imp->imp_connect_error)
1647 rc = imp->imp_connect_error;
1651 msfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
1653 GOTO(out, rc = -EPROTO);
1658 ptlrpc_req_finished(req);
1660 class_import_put(imp);
1664 static int mdc_ioc_fid2path(struct obd_export *exp, struct getinfo_fid2path *gf)
1666 __u32 keylen, vallen;
1670 if (gf->gf_pathlen > PATH_MAX)
1671 RETURN(-ENAMETOOLONG);
1672 if (gf->gf_pathlen < 2)
1675 /* Key is KEY_FID2PATH + getinfo_fid2path description */
1676 keylen = cfs_size_round(sizeof(KEY_FID2PATH)) + sizeof(*gf);
1677 OBD_ALLOC(key, keylen);
1680 memcpy(key, KEY_FID2PATH, sizeof(KEY_FID2PATH));
1681 memcpy(key + cfs_size_round(sizeof(KEY_FID2PATH)), gf, sizeof(*gf));
1683 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
1684 PFID(&gf->gf_fid), gf->gf_recno, gf->gf_linkno);
1686 if (!fid_is_sane(&gf->gf_fid))
1687 GOTO(out, rc = -EINVAL);
1689 /* Val is struct getinfo_fid2path result plus path */
1690 vallen = sizeof(*gf) + gf->gf_pathlen;
1692 rc = obd_get_info(NULL, exp, keylen, key, &vallen, gf, NULL);
1693 if (rc != 0 && rc != -EREMOTE)
1696 if (vallen <= sizeof(*gf))
1697 GOTO(out, rc = -EPROTO);
1698 else if (vallen > sizeof(*gf) + gf->gf_pathlen)
1699 GOTO(out, rc = -EOVERFLOW);
1701 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n%s\n",
1702 PFID(&gf->gf_fid), gf->gf_recno, gf->gf_linkno, gf->gf_path);
1705 OBD_FREE(key, keylen);
1709 static int mdc_ioc_hsm_progress(struct obd_export *exp,
1710 struct hsm_progress_kernel *hpk)
1712 struct obd_import *imp = class_exp2cliimp(exp);
1713 struct hsm_progress_kernel *req_hpk;
1714 struct ptlrpc_request *req;
1718 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_HSM_PROGRESS,
1719 LUSTRE_MDS_VERSION, MDS_HSM_PROGRESS);
1721 GOTO(out, rc = -ENOMEM);
1723 mdc_pack_body(req, NULL, NULL, OBD_MD_FLRMTPERM, 0, -1, 0);
1725 /* Copy hsm_progress struct */
1726 req_hpk = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_PROGRESS);
1727 if (req_hpk == NULL)
1728 GOTO(out, rc = -EPROTO);
1731 req_hpk->hpk_errval = lustre_errno_hton(hpk->hpk_errval);
1733 ptlrpc_request_set_replen(req);
1735 rc = mdc_queue_wait(req);
1738 ptlrpc_req_finished(req);
1742 static int mdc_ioc_hsm_ct_register(struct obd_import *imp, __u32 archives)
1744 __u32 *archive_mask;
1745 struct ptlrpc_request *req;
1749 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_HSM_CT_REGISTER,
1751 MDS_HSM_CT_REGISTER);
1753 GOTO(out, rc = -ENOMEM);
1755 mdc_pack_body(req, NULL, NULL, OBD_MD_FLRMTPERM, 0, -1, 0);
1757 /* Copy hsm_progress struct */
1758 archive_mask = req_capsule_client_get(&req->rq_pill,
1759 &RMF_MDS_HSM_ARCHIVE);
1760 if (archive_mask == NULL)
1761 GOTO(out, rc = -EPROTO);
1763 *archive_mask = archives;
1765 ptlrpc_request_set_replen(req);
1767 rc = mdc_queue_wait(req);
1770 ptlrpc_req_finished(req);
1774 static int mdc_ioc_hsm_current_action(struct obd_export *exp,
1775 struct md_op_data *op_data)
1777 struct hsm_current_action *hca = op_data->op_data;
1778 struct hsm_current_action *req_hca;
1779 struct ptlrpc_request *req;
1783 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
1784 &RQF_MDS_HSM_ACTION);
1788 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
1790 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_ACTION);
1792 ptlrpc_request_free(req);
1796 mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
1797 OBD_MD_FLRMTPERM, 0, op_data->op_suppgids[0], 0);
1799 ptlrpc_request_set_replen(req);
1801 rc = mdc_queue_wait(req);
1805 req_hca = req_capsule_server_get(&req->rq_pill,
1806 &RMF_MDS_HSM_CURRENT_ACTION);
1807 if (req_hca == NULL)
1808 GOTO(out, rc = -EPROTO);
1814 ptlrpc_req_finished(req);
1818 static int mdc_ioc_hsm_ct_unregister(struct obd_import *imp)
1820 struct ptlrpc_request *req;
1824 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_HSM_CT_UNREGISTER,
1826 MDS_HSM_CT_UNREGISTER);
1828 GOTO(out, rc = -ENOMEM);
1830 mdc_pack_body(req, NULL, NULL, OBD_MD_FLRMTPERM, 0, -1, 0);
1832 ptlrpc_request_set_replen(req);
1834 rc = mdc_queue_wait(req);
1837 ptlrpc_req_finished(req);
1841 static int mdc_ioc_hsm_state_get(struct obd_export *exp,
1842 struct md_op_data *op_data)
1844 struct hsm_user_state *hus = op_data->op_data;
1845 struct hsm_user_state *req_hus;
1846 struct ptlrpc_request *req;
1850 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
1851 &RQF_MDS_HSM_STATE_GET);
1855 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
1857 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_STATE_GET);
1859 ptlrpc_request_free(req);
1863 mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
1864 OBD_MD_FLRMTPERM, 0, op_data->op_suppgids[0], 0);
1866 ptlrpc_request_set_replen(req);
1868 rc = mdc_queue_wait(req);
1872 req_hus = req_capsule_server_get(&req->rq_pill, &RMF_HSM_USER_STATE);
1873 if (req_hus == NULL)
1874 GOTO(out, rc = -EPROTO);
1880 ptlrpc_req_finished(req);
1884 static int mdc_ioc_hsm_state_set(struct obd_export *exp,
1885 struct md_op_data *op_data)
1887 struct hsm_state_set *hss = op_data->op_data;
1888 struct hsm_state_set *req_hss;
1889 struct ptlrpc_request *req;
1893 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
1894 &RQF_MDS_HSM_STATE_SET);
1898 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
1900 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_STATE_SET);
1902 ptlrpc_request_free(req);
1906 mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
1907 OBD_MD_FLRMTPERM, 0, op_data->op_suppgids[0], 0);
1910 req_hss = req_capsule_client_get(&req->rq_pill, &RMF_HSM_STATE_SET);
1911 if (req_hss == NULL)
1912 GOTO(out, rc = -EPROTO);
1915 ptlrpc_request_set_replen(req);
1917 rc = mdc_queue_wait(req);
1922 ptlrpc_req_finished(req);
1926 static int mdc_ioc_hsm_request(struct obd_export *exp,
1927 struct hsm_user_request *hur)
1929 struct obd_import *imp = class_exp2cliimp(exp);
1930 struct ptlrpc_request *req;
1931 struct hsm_request *req_hr;
1932 struct hsm_user_item *req_hui;
1937 req = ptlrpc_request_alloc(imp, &RQF_MDS_HSM_REQUEST);
1939 GOTO(out, rc = -ENOMEM);
1941 req_capsule_set_size(&req->rq_pill, &RMF_MDS_HSM_USER_ITEM, RCL_CLIENT,
1942 hur->hur_request.hr_itemcount
1943 * sizeof(struct hsm_user_item));
1944 req_capsule_set_size(&req->rq_pill, &RMF_GENERIC_DATA, RCL_CLIENT,
1945 hur->hur_request.hr_data_len);
1947 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_REQUEST);
1949 ptlrpc_request_free(req);
1953 mdc_pack_body(req, NULL, NULL, OBD_MD_FLRMTPERM, 0, -1, 0);
1955 /* Copy hsm_request struct */
1956 req_hr = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_REQUEST);
1958 GOTO(out, rc = -EPROTO);
1959 *req_hr = hur->hur_request;
1961 /* Copy hsm_user_item structs */
1962 req_hui = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_USER_ITEM);
1963 if (req_hui == NULL)
1964 GOTO(out, rc = -EPROTO);
1965 memcpy(req_hui, hur->hur_user_item,
1966 hur->hur_request.hr_itemcount * sizeof(struct hsm_user_item));
1968 /* Copy opaque field */
1969 req_opaque = req_capsule_client_get(&req->rq_pill, &RMF_GENERIC_DATA);
1970 if (req_opaque == NULL)
1971 GOTO(out, rc = -EPROTO);
1972 memcpy(req_opaque, hur_data(hur), hur->hur_request.hr_data_len);
1974 ptlrpc_request_set_replen(req);
1976 rc = mdc_queue_wait(req);
1980 ptlrpc_req_finished(req);
1984 static struct kuc_hdr *changelog_kuc_hdr(char *buf, int len, int flags)
1986 struct kuc_hdr *lh = (struct kuc_hdr *)buf;
1988 LASSERT(len <= KUC_CHANGELOG_MSG_MAXSIZE);
1990 lh->kuc_magic = KUC_MAGIC;
1991 lh->kuc_transport = KUC_TRANSPORT_CHANGELOG;
1992 lh->kuc_flags = flags;
1993 lh->kuc_msgtype = CL_RECORD;
1994 lh->kuc_msglen = len;
1998 struct changelog_show {
2003 struct obd_device *cs_obd;
2006 static int changelog_kkuc_cb(const struct lu_env *env, struct llog_handle *llh,
2007 struct llog_rec_hdr *hdr, void *data)
2009 struct changelog_show *cs = data;
2010 struct llog_changelog_rec *rec = (struct llog_changelog_rec *)hdr;
2015 if (rec->cr_hdr.lrh_type != CHANGELOG_REC) {
2017 CERROR("%s: not a changelog rec %x/%d: rc = %d\n",
2018 cs->cs_obd->obd_name, rec->cr_hdr.lrh_type,
2019 rec->cr.cr_type, rc);
2023 if (rec->cr.cr_index < cs->cs_startrec) {
2024 /* Skip entries earlier than what we are interested in */
2025 CDEBUG(D_HSM, "rec="LPU64" start="LPU64"\n",
2026 rec->cr.cr_index, cs->cs_startrec);
2030 CDEBUG(D_HSM, LPU64" %02d%-5s "LPU64" 0x%x t="DFID" p="DFID" %.*s\n",
2031 rec->cr.cr_index, rec->cr.cr_type,
2032 changelog_type2str(rec->cr.cr_type), rec->cr.cr_time,
2033 rec->cr.cr_flags & CLF_FLAGMASK,
2034 PFID(&rec->cr.cr_tfid), PFID(&rec->cr.cr_pfid),
2035 rec->cr.cr_namelen, changelog_rec_name(&rec->cr));
2037 len = sizeof(*lh) + changelog_rec_size(&rec->cr) + rec->cr.cr_namelen;
2039 /* Set up the message */
2040 lh = changelog_kuc_hdr(cs->cs_buf, len, cs->cs_flags);
2041 memcpy(lh + 1, &rec->cr, len - sizeof(*lh));
2043 rc = libcfs_kkuc_msg_put(cs->cs_fp, lh);
2044 CDEBUG(D_HSM, "kucmsg fp %p len %d rc %d\n", cs->cs_fp, len, rc);
2049 static int mdc_changelog_send_thread(void *csdata)
2051 struct changelog_show *cs = csdata;
2052 struct llog_ctxt *ctxt = NULL;
2053 struct llog_handle *llh = NULL;
2054 struct kuc_hdr *kuch;
2057 CDEBUG(D_HSM, "changelog to fp=%p start "LPU64"\n",
2058 cs->cs_fp, cs->cs_startrec);
2060 OBD_ALLOC(cs->cs_buf, KUC_CHANGELOG_MSG_MAXSIZE);
2061 if (cs->cs_buf == NULL)
2062 GOTO(out, rc = -ENOMEM);
2064 /* Set up the remote catalog handle */
2065 ctxt = llog_get_context(cs->cs_obd, LLOG_CHANGELOG_REPL_CTXT);
2067 GOTO(out, rc = -ENOENT);
2068 rc = llog_open(NULL, ctxt, &llh, NULL, CHANGELOG_CATALOG,
2071 CERROR("%s: fail to open changelog catalog: rc = %d\n",
2072 cs->cs_obd->obd_name, rc);
2075 rc = llog_init_handle(NULL, llh, LLOG_F_IS_CAT, NULL);
2077 CERROR("llog_init_handle failed %d\n", rc);
2081 rc = llog_cat_process(NULL, llh, changelog_kkuc_cb, cs, 0, 0);
2083 /* Send EOF no matter what our result */
2084 if ((kuch = changelog_kuc_hdr(cs->cs_buf, sizeof(*kuch),
2086 kuch->kuc_msgtype = CL_EOF;
2087 libcfs_kkuc_msg_put(cs->cs_fp, kuch);
2093 llog_cat_close(NULL, llh);
2095 llog_ctxt_put(ctxt);
2097 OBD_FREE(cs->cs_buf, KUC_CHANGELOG_MSG_MAXSIZE);
2102 static int mdc_ioc_changelog_send(struct obd_device *obd,
2103 struct ioc_changelog *icc)
2105 struct changelog_show *cs;
2106 struct task_struct *task;
2109 /* Freed in mdc_changelog_send_thread */
2115 cs->cs_startrec = icc->icc_recno;
2116 /* matching fput in mdc_changelog_send_thread */
2117 cs->cs_fp = fget(icc->icc_id);
2118 cs->cs_flags = icc->icc_flags;
2121 * New thread because we should return to user app before
2122 * writing into our pipe
2124 task = kthread_run(mdc_changelog_send_thread, cs,
2125 "mdc_clg_send_thread");
2128 CERROR("%s: cannot start changelog thread: rc = %d\n",
2133 CDEBUG(D_HSM, "%s: started changelog thread\n", obd->obd_name);
2139 static int mdc_ioc_hsm_ct_start(struct obd_export *exp,
2140 struct lustre_kernelcomm *lk);
2142 static int mdc_quotacheck(struct obd_device *unused, struct obd_export *exp,
2143 struct obd_quotactl *oqctl)
2145 struct client_obd *cli = &exp->exp_obd->u.cli;
2146 struct ptlrpc_request *req;
2147 struct obd_quotactl *body;
2151 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
2152 &RQF_MDS_QUOTACHECK, LUSTRE_MDS_VERSION,
2157 body = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
2160 ptlrpc_request_set_replen(req);
2162 /* the next poll will find -ENODATA, that means quotacheck is
2164 cli->cl_qchk_stat = -ENODATA;
2165 rc = ptlrpc_queue_wait(req);
2167 cli->cl_qchk_stat = rc;
2168 ptlrpc_req_finished(req);
2172 static int mdc_quota_poll_check(struct obd_export *exp,
2173 struct if_quotacheck *qchk)
2175 struct client_obd *cli = &exp->exp_obd->u.cli;
2179 qchk->obd_uuid = cli->cl_target_uuid;
2180 memcpy(qchk->obd_type, LUSTRE_MDS_NAME, strlen(LUSTRE_MDS_NAME));
2182 rc = cli->cl_qchk_stat;
2183 /* the client is not the previous one */
2184 if (rc == CL_NOT_QUOTACHECKED)
2189 static int mdc_quotactl(struct obd_device *unused, struct obd_export *exp,
2190 struct obd_quotactl *oqctl)
2192 struct ptlrpc_request *req;
2193 struct obd_quotactl *oqc;
2197 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
2198 &RQF_MDS_QUOTACTL, LUSTRE_MDS_VERSION,
2203 oqc = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
2206 ptlrpc_request_set_replen(req);
2207 ptlrpc_at_set_req_timeout(req);
2208 req->rq_no_resend = 1;
2210 rc = ptlrpc_queue_wait(req);
2212 CERROR("ptlrpc_queue_wait failed, rc: %d\n", rc);
2214 if (req->rq_repmsg &&
2215 (oqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL))) {
2218 CERROR ("Can't unpack obd_quotactl\n");
2221 ptlrpc_req_finished(req);
2226 static int mdc_ioc_swap_layouts(struct obd_export *exp,
2227 struct md_op_data *op_data)
2229 struct list_head cancels = LIST_HEAD_INIT(cancels);
2230 struct ptlrpc_request *req;
2232 struct mdc_swap_layouts *msl, *payload;
2235 msl = op_data->op_data;
2237 /* When the MDT will get the MDS_SWAP_LAYOUTS RPC the
2238 * first thing it will do is to cancel the 2 layout
2239 * locks hold by this client.
2240 * So the client must cancel its layout locks on the 2 fids
2241 * with the request RPC to avoid extra RPC round trips
2243 count = mdc_resource_get_unused(exp, &op_data->op_fid1, &cancels,
2244 LCK_EX, MDS_INODELOCK_LAYOUT |
2245 MDS_INODELOCK_XATTR);
2246 count += mdc_resource_get_unused(exp, &op_data->op_fid2, &cancels,
2247 LCK_EX, MDS_INODELOCK_LAYOUT |
2248 MDS_INODELOCK_XATTR);
2250 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
2251 &RQF_MDS_SWAP_LAYOUTS);
2253 ldlm_lock_list_put(&cancels, l_bl_ast, count);
2257 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
2258 mdc_set_capa_size(req, &RMF_CAPA2, op_data->op_capa2);
2260 rc = mdc_prep_elc_req(exp, req, MDS_SWAP_LAYOUTS, &cancels, count);
2262 ptlrpc_request_free(req);
2266 mdc_swap_layouts_pack(req, op_data);
2268 payload = req_capsule_client_get(&req->rq_pill, &RMF_SWAP_LAYOUTS);
2273 ptlrpc_request_set_replen(req);
2275 rc = ptlrpc_queue_wait(req);
2281 ptlrpc_req_finished(req);
2285 static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
2286 void *karg, void __user *uarg)
2288 struct obd_device *obd = exp->exp_obd;
2289 struct obd_ioctl_data *data = karg;
2290 struct obd_import *imp = obd->u.cli.cl_import;
2294 if (!try_module_get(THIS_MODULE)) {
2295 CERROR("%s: cannot get module '%s'\n", obd->obd_name,
2296 module_name(THIS_MODULE));
2300 case OBD_IOC_CHANGELOG_SEND:
2301 rc = mdc_ioc_changelog_send(obd, karg);
2303 case OBD_IOC_CHANGELOG_CLEAR: {
2304 struct ioc_changelog *icc = karg;
2305 struct changelog_setinfo cs =
2306 {.cs_recno = icc->icc_recno, .cs_id = icc->icc_id};
2307 rc = obd_set_info_async(NULL, exp, strlen(KEY_CHANGELOG_CLEAR),
2308 KEY_CHANGELOG_CLEAR, sizeof(cs), &cs,
2312 case OBD_IOC_FID2PATH:
2313 rc = mdc_ioc_fid2path(exp, karg);
2315 case LL_IOC_HSM_CT_START:
2316 rc = mdc_ioc_hsm_ct_start(exp, karg);
2317 /* ignore if it was already registered on this MDS. */
2321 case LL_IOC_HSM_PROGRESS:
2322 rc = mdc_ioc_hsm_progress(exp, karg);
2324 case LL_IOC_HSM_STATE_GET:
2325 rc = mdc_ioc_hsm_state_get(exp, karg);
2327 case LL_IOC_HSM_STATE_SET:
2328 rc = mdc_ioc_hsm_state_set(exp, karg);
2330 case LL_IOC_HSM_ACTION:
2331 rc = mdc_ioc_hsm_current_action(exp, karg);
2333 case LL_IOC_HSM_REQUEST:
2334 rc = mdc_ioc_hsm_request(exp, karg);
2336 case OBD_IOC_CLIENT_RECOVER:
2337 rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1, 0);
2341 case IOC_OSC_SET_ACTIVE:
2342 rc = ptlrpc_set_import_active(imp, data->ioc_offset);
2344 case OBD_IOC_POLL_QUOTACHECK:
2345 rc = mdc_quota_poll_check(exp, (struct if_quotacheck *)karg);
2347 case OBD_IOC_PING_TARGET:
2348 rc = ptlrpc_obd_ping(obd);
2351 * Normally IOC_OBD_STATFS, OBD_IOC_QUOTACTL iocontrol are handled by
2352 * LMV instead of MDC. But when the cluster is upgraded from 1.8,
2353 * there'd be no LMV layer thus we might be called here. Eventually
2354 * this code should be removed.
2357 case IOC_OBD_STATFS: {
2358 struct obd_statfs stat_buf = {0};
2360 if (*((__u32 *) data->ioc_inlbuf2) != 0)
2361 GOTO(out, rc = -ENODEV);
2364 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(obd),
2365 min((int)data->ioc_plen2,
2366 (int)sizeof(struct obd_uuid))))
2367 GOTO(out, rc = -EFAULT);
2369 rc = mdc_statfs(NULL, obd->obd_self_export, &stat_buf,
2370 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
2375 if (copy_to_user(data->ioc_pbuf1, &stat_buf,
2376 min((int) data->ioc_plen1,
2377 (int) sizeof(stat_buf))))
2378 GOTO(out, rc = -EFAULT);
2382 case OBD_IOC_QUOTACTL: {
2383 struct if_quotactl *qctl = karg;
2384 struct obd_quotactl *oqctl;
2386 OBD_ALLOC_PTR(oqctl);
2388 GOTO(out, rc = -ENOMEM);
2390 QCTL_COPY(oqctl, qctl);
2391 rc = obd_quotactl(exp, oqctl);
2393 QCTL_COPY(qctl, oqctl);
2394 qctl->qc_valid = QC_MDTIDX;
2395 qctl->obd_uuid = obd->u.cli.cl_target_uuid;
2398 OBD_FREE_PTR(oqctl);
2401 case LL_IOC_GET_CONNECT_FLAGS:
2402 if (copy_to_user(uarg, exp_connect_flags_ptr(exp),
2403 sizeof(*exp_connect_flags_ptr(exp))))
2404 GOTO(out, rc = -EFAULT);
2407 case LL_IOC_LOV_SWAP_LAYOUTS:
2408 rc = mdc_ioc_swap_layouts(exp, karg);
2411 CERROR("unrecognised ioctl: cmd = %#x\n", cmd);
2412 GOTO(out, rc = -ENOTTY);
2415 module_put(THIS_MODULE);
2420 int mdc_get_info_rpc(struct obd_export *exp,
2421 obd_count keylen, void *key,
2422 int vallen, void *val)
2424 struct obd_import *imp = class_exp2cliimp(exp);
2425 struct ptlrpc_request *req;
2430 req = ptlrpc_request_alloc(imp, &RQF_MDS_GET_INFO);
2434 req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_KEY,
2435 RCL_CLIENT, keylen);
2436 req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_VALLEN,
2437 RCL_CLIENT, sizeof(__u32));
2439 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GET_INFO);
2441 ptlrpc_request_free(req);
2445 tmp = req_capsule_client_get(&req->rq_pill, &RMF_GETINFO_KEY);
2446 memcpy(tmp, key, keylen);
2447 tmp = req_capsule_client_get(&req->rq_pill, &RMF_GETINFO_VALLEN);
2448 memcpy(tmp, &vallen, sizeof(__u32));
2450 req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_VAL,
2451 RCL_SERVER, vallen);
2452 ptlrpc_request_set_replen(req);
2454 rc = ptlrpc_queue_wait(req);
2455 /* -EREMOTE means the get_info result is partial, and it needs to
2456 * continue on another MDT, see fid2path part in lmv_iocontrol */
2457 if (rc == 0 || rc == -EREMOTE) {
2458 tmp = req_capsule_server_get(&req->rq_pill, &RMF_GETINFO_VAL);
2459 memcpy(val, tmp, vallen);
2460 if (ptlrpc_rep_need_swab(req)) {
2461 if (KEY_IS(KEY_FID2PATH))
2462 lustre_swab_fid2path(val);
2465 ptlrpc_req_finished(req);
2470 static void lustre_swab_hai(struct hsm_action_item *h)
2472 __swab32s(&h->hai_len);
2473 __swab32s(&h->hai_action);
2474 lustre_swab_lu_fid(&h->hai_fid);
2475 lustre_swab_lu_fid(&h->hai_dfid);
2476 __swab64s(&h->hai_cookie);
2477 __swab64s(&h->hai_extent.offset);
2478 __swab64s(&h->hai_extent.length);
2479 __swab64s(&h->hai_gid);
2482 static void lustre_swab_hal(struct hsm_action_list *h)
2484 struct hsm_action_item *hai;
2487 __swab32s(&h->hal_version);
2488 __swab32s(&h->hal_count);
2489 __swab32s(&h->hal_archive_id);
2490 __swab64s(&h->hal_flags);
2492 for (i = 0; i < h->hal_count; i++, hai = hai_next(hai))
2493 lustre_swab_hai(hai);
2496 static void lustre_swab_kuch(struct kuc_hdr *l)
2498 __swab16s(&l->kuc_magic);
2499 /* __u8 l->kuc_transport */
2500 __swab16s(&l->kuc_msgtype);
2501 __swab16s(&l->kuc_msglen);
2504 static int mdc_ioc_hsm_ct_start(struct obd_export *exp,
2505 struct lustre_kernelcomm *lk)
2507 struct obd_import *imp = class_exp2cliimp(exp);
2508 __u32 archive = lk->lk_data;
2511 if (lk->lk_group != KUC_GRP_HSM) {
2512 CERROR("Bad copytool group %d\n", lk->lk_group);
2516 CDEBUG(D_HSM, "CT start r%d w%d u%d g%d f%#x\n", lk->lk_rfd, lk->lk_wfd,
2517 lk->lk_uid, lk->lk_group, lk->lk_flags);
2519 if (lk->lk_flags & LK_FLG_STOP) {
2520 /* Unregister with the coordinator */
2521 rc = mdc_ioc_hsm_ct_unregister(imp);
2523 rc = mdc_ioc_hsm_ct_register(imp, archive);
2530 * Send a message to any listening copytools
2531 * @param val KUC message (kuc_hdr + hsm_action_list)
2532 * @param len total length of message
2534 static int mdc_hsm_copytool_send(int len, void *val)
2536 struct kuc_hdr *lh = (struct kuc_hdr *)val;
2537 struct hsm_action_list *hal = (struct hsm_action_list *)(lh + 1);
2541 if (len < sizeof(*lh) + sizeof(*hal)) {
2542 CERROR("Short HSM message %d < %d\n", len,
2543 (int) (sizeof(*lh) + sizeof(*hal)));
2546 if (lh->kuc_magic == __swab16(KUC_MAGIC)) {
2547 lustre_swab_kuch(lh);
2548 lustre_swab_hal(hal);
2549 } else if (lh->kuc_magic != KUC_MAGIC) {
2550 CERROR("Bad magic %x!=%x\n", lh->kuc_magic, KUC_MAGIC);
2554 CDEBUG(D_HSM, " Received message mg=%x t=%d m=%d l=%d actions=%d "
2556 lh->kuc_magic, lh->kuc_transport, lh->kuc_msgtype,
2557 lh->kuc_msglen, hal->hal_count, hal->hal_fsname);
2559 /* Broadcast to HSM listeners */
2560 rc = libcfs_kkuc_group_put(KUC_GRP_HSM, lh);
2566 * callback function passed to kuc for re-registering each HSM copytool
2567 * running on MDC, after MDT shutdown/recovery.
2568 * @param data copytool registration data
2569 * @param cb_arg callback argument (obd_import)
2571 static int mdc_hsm_ct_reregister(void *data, void *cb_arg)
2573 struct kkuc_ct_data *kcd = data;
2574 struct obd_import *imp = (struct obd_import *)cb_arg;
2577 if (kcd == NULL || kcd->kcd_magic != KKUC_CT_DATA_MAGIC)
2580 if (!obd_uuid_equals(&kcd->kcd_uuid, &imp->imp_obd->obd_uuid))
2583 CDEBUG(D_HA, "%s: recover copytool registration to MDT (archive=%#x)\n",
2584 imp->imp_obd->obd_name, kcd->kcd_archive);
2585 rc = mdc_ioc_hsm_ct_register(imp, kcd->kcd_archive);
2587 /* ignore error if the copytool is already registered */
2588 return (rc == -EEXIST) ? 0 : rc;
2592 * Re-establish all kuc contexts with MDT
2593 * after MDT shutdown/recovery.
2595 static int mdc_kuc_reregister(struct obd_import *imp)
2597 /* re-register HSM agents */
2598 return libcfs_kkuc_group_foreach(KUC_GRP_HSM, mdc_hsm_ct_reregister,
2602 int mdc_set_info_async(const struct lu_env *env,
2603 struct obd_export *exp,
2604 obd_count keylen, void *key,
2605 obd_count vallen, void *val,
2606 struct ptlrpc_request_set *set)
2608 struct obd_import *imp = class_exp2cliimp(exp);
2612 if (KEY_IS(KEY_READ_ONLY)) {
2613 if (vallen != sizeof(int))
2616 spin_lock(&imp->imp_lock);
2617 if (*((int *)val)) {
2618 imp->imp_connect_flags_orig |= OBD_CONNECT_RDONLY;
2619 imp->imp_connect_data.ocd_connect_flags |=
2622 imp->imp_connect_flags_orig &= ~OBD_CONNECT_RDONLY;
2623 imp->imp_connect_data.ocd_connect_flags &=
2624 ~OBD_CONNECT_RDONLY;
2626 spin_unlock(&imp->imp_lock);
2628 rc = do_set_info_async(imp, MDS_SET_INFO, LUSTRE_MDS_VERSION,
2629 keylen, key, vallen, val, set);
2632 if (KEY_IS(KEY_SPTLRPC_CONF)) {
2633 sptlrpc_conf_client_adapt(exp->exp_obd);
2636 if (KEY_IS(KEY_FLUSH_CTX)) {
2637 sptlrpc_import_flush_my_ctx(imp);
2640 if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
2641 rc = do_set_info_async(imp, MDS_SET_INFO, LUSTRE_MDS_VERSION,
2642 keylen, key, vallen, val, set);
2645 if (KEY_IS(KEY_HSM_COPYTOOL_SEND)) {
2646 rc = mdc_hsm_copytool_send(vallen, val);
2650 CERROR("Unknown key %s\n", (char *)key);
2654 int mdc_get_info(const struct lu_env *env, struct obd_export *exp,
2655 __u32 keylen, void *key, __u32 *vallen, void *val,
2656 struct lov_stripe_md *lsm)
2660 if (KEY_IS(KEY_MAX_EASIZE)) {
2661 int mdsize, *max_easize;
2663 if (*vallen != sizeof(int))
2665 mdsize = *(int *)val;
2666 if (mdsize > exp->exp_obd->u.cli.cl_max_mds_easize)
2667 exp->exp_obd->u.cli.cl_max_mds_easize = mdsize;
2669 *max_easize = exp->exp_obd->u.cli.cl_max_mds_easize;
2671 } else if (KEY_IS(KEY_DEFAULT_EASIZE)) {
2672 int *default_easize;
2674 if (*vallen != sizeof(int))
2676 default_easize = val;
2677 *default_easize = exp->exp_obd->u.cli.cl_default_mds_easize;
2679 } else if (KEY_IS(KEY_MAX_COOKIESIZE)) {
2680 int mdsize, *max_cookiesize;
2682 if (*vallen != sizeof(int))
2684 mdsize = *(int *)val;
2685 if (mdsize > exp->exp_obd->u.cli.cl_max_mds_cookiesize)
2686 exp->exp_obd->u.cli.cl_max_mds_cookiesize = mdsize;
2687 max_cookiesize = val;
2688 *max_cookiesize = exp->exp_obd->u.cli.cl_max_mds_cookiesize;
2690 } else if (KEY_IS(KEY_DEFAULT_COOKIESIZE)) {
2691 int *default_cookiesize;
2693 if (*vallen != sizeof(int))
2695 default_cookiesize = val;
2696 *default_cookiesize =
2697 exp->exp_obd->u.cli.cl_default_mds_cookiesize;
2699 } else if (KEY_IS(KEY_CONN_DATA)) {
2700 struct obd_import *imp = class_exp2cliimp(exp);
2701 struct obd_connect_data *data = val;
2703 if (*vallen != sizeof(*data))
2706 *data = imp->imp_connect_data;
2708 } else if (KEY_IS(KEY_TGT_COUNT)) {
2713 rc = mdc_get_info_rpc(exp, keylen, key, *vallen, val);
2718 int mdc_fsync(struct obd_export *exp, const struct lu_fid *fid,
2719 struct obd_capa *oc, struct ptlrpc_request **request)
2721 struct ptlrpc_request *req;
2726 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_SYNC);
2730 mdc_set_capa_size(req, &RMF_CAPA1, oc);
2732 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_SYNC);
2734 ptlrpc_request_free(req);
2738 mdc_pack_body(req, fid, oc, 0, 0, -1, 0);
2740 ptlrpc_request_set_replen(req);
2742 rc = ptlrpc_queue_wait(req);
2744 ptlrpc_req_finished(req);
2750 static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
2751 enum obd_import_event event)
2755 LASSERT(imp->imp_obd == obd);
2758 case IMP_EVENT_DISCON: {
2760 /* XXX Pass event up to OBDs stack. used only for FLD now */
2761 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_DISCON, NULL);
2765 case IMP_EVENT_INACTIVE: {
2766 struct client_obd *cli = &obd->u.cli;
2768 * Flush current sequence to make client obtain new one
2769 * from server in case of disconnect/reconnect.
2771 if (cli->cl_seq != NULL)
2772 seq_client_flush(cli->cl_seq);
2774 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_INACTIVE, NULL);
2777 case IMP_EVENT_INVALIDATE: {
2778 struct ldlm_namespace *ns = obd->obd_namespace;
2780 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
2784 case IMP_EVENT_ACTIVE:
2785 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_ACTIVE, NULL);
2786 /* redo the kuc registration after reconnecting */
2788 rc = mdc_kuc_reregister(imp);
2791 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_OCD, NULL);
2793 case IMP_EVENT_DEACTIVATE:
2794 case IMP_EVENT_ACTIVATE:
2797 CERROR("Unknown import event %x\n", event);
2803 int mdc_fid_alloc(const struct lu_env *env, struct obd_export *exp,
2804 struct lu_fid *fid, struct md_op_data *op_data)
2806 struct client_obd *cli = &exp->exp_obd->u.cli;
2807 struct lu_client_seq *seq = cli->cl_seq;
2809 RETURN(seq_client_alloc_fid(env, seq, fid));
2812 struct obd_uuid *mdc_get_uuid(struct obd_export *exp) {
2813 struct client_obd *cli = &exp->exp_obd->u.cli;
2814 return &cli->cl_target_uuid;
2818 * Determine whether the lock can be canceled before replaying it during
2819 * recovery, non zero value will be return if the lock can be canceled,
2820 * or zero returned for not
2822 static int mdc_cancel_weight(struct ldlm_lock *lock)
2824 if (lock->l_resource->lr_type != LDLM_IBITS)
2827 /* FIXME: if we ever get into a situation where there are too many
2828 * opened files with open locks on a single node, then we really
2829 * should replay these open locks to reget it */
2830 if (lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_OPEN)
2836 static int mdc_resource_inode_free(struct ldlm_resource *res)
2838 if (res->lr_lvb_inode)
2839 res->lr_lvb_inode = NULL;
2844 struct ldlm_valblock_ops inode_lvbo = {
2845 .lvbo_free = mdc_resource_inode_free
2848 static int mdc_setup(struct obd_device *obd, struct lustre_cfg *cfg)
2850 struct client_obd *cli = &obd->u.cli;
2854 OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
2855 if (!cli->cl_rpc_lock)
2857 mdc_init_rpc_lock(cli->cl_rpc_lock);
2859 rc = ptlrpcd_addref();
2861 GOTO(err_rpc_lock, rc);
2863 OBD_ALLOC(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
2864 if (!cli->cl_close_lock)
2865 GOTO(err_ptlrpcd_decref, rc = -ENOMEM);
2866 mdc_init_rpc_lock(cli->cl_close_lock);
2868 rc = client_obd_setup(obd, cfg);
2870 GOTO(err_close_lock, rc);
2872 obd->obd_vars = lprocfs_mdc_obd_vars;
2873 lprocfs_obd_setup(obd);
2874 lprocfs_alloc_md_stats(obd, 0);
2876 sptlrpc_lprocfs_cliobd_attach(obd);
2877 ptlrpc_lprocfs_register_obd(obd);
2879 ns_register_cancel(obd->obd_namespace, mdc_cancel_weight);
2881 obd->obd_namespace->ns_lvbo = &inode_lvbo;
2883 rc = obd_llog_init(obd, &obd->obd_olg, obd, NULL);
2886 CERROR("failed to setup llogging subsystems\n");
2892 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
2896 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
2900 /* Initialize the default and maximum LOV EA and cookie sizes. This allows
2901 * us to make MDS RPCs with large enough reply buffers to hold a default
2902 * sized EA and cookie without having to calculate this (via a call into the
2903 * LOV + OSCs) each time we make an RPC. The maximum size is also tracked
2904 * but not used to avoid wastefully vmalloc()'ing large reply buffers when
2905 * a large number of stripes is possible. If a larger reply buffer is
2906 * required it will be reallocated in the ptlrpc layer due to overflow.
2908 static int mdc_init_ea_size(struct obd_export *exp, int easize,
2909 int def_easize, int cookiesize, int def_cookiesize)
2911 struct obd_device *obd = exp->exp_obd;
2912 struct client_obd *cli = &obd->u.cli;
2915 if (cli->cl_max_mds_easize < easize)
2916 cli->cl_max_mds_easize = easize;
2918 if (cli->cl_default_mds_easize < def_easize)
2919 cli->cl_default_mds_easize = def_easize;
2921 if (cli->cl_max_mds_cookiesize < cookiesize)
2922 cli->cl_max_mds_cookiesize = cookiesize;
2924 if (cli->cl_default_mds_cookiesize < def_cookiesize)
2925 cli->cl_default_mds_cookiesize = def_cookiesize;
2930 static int mdc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2936 case OBD_CLEANUP_EARLY:
2938 case OBD_CLEANUP_EXPORTS:
2939 /* Failsafe, ok if racy */
2940 if (obd->obd_type->typ_refcnt <= 1)
2941 libcfs_kkuc_group_rem(0, KUC_GRP_HSM, NULL);
2943 obd_cleanup_client_import(obd);
2944 ptlrpc_lprocfs_unregister_obd(obd);
2945 lprocfs_obd_cleanup(obd);
2946 lprocfs_free_md_stats(obd);
2948 rc = obd_llog_finish(obd, 0);
2950 CERROR("failed to cleanup llogging subsystems\n");
2956 static int mdc_cleanup(struct obd_device *obd)
2958 struct client_obd *cli = &obd->u.cli;
2960 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
2961 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
2965 return client_obd_cleanup(obd);
2969 static int mdc_llog_init(struct obd_device *obd, struct obd_llog_group *olg,
2970 struct obd_device *tgt, int *index)
2972 struct llog_ctxt *ctxt;
2977 LASSERT(olg == &obd->obd_olg);
2979 rc = llog_setup(NULL, obd, olg, LLOG_CHANGELOG_REPL_CTXT, tgt,
2984 ctxt = llog_group_get_ctxt(olg, LLOG_CHANGELOG_REPL_CTXT);
2985 llog_initiator_connect(ctxt);
2986 llog_ctxt_put(ctxt);
2991 static int mdc_llog_finish(struct obd_device *obd, int count)
2993 struct llog_ctxt *ctxt;
2997 ctxt = llog_get_context(obd, LLOG_CHANGELOG_REPL_CTXT);
2999 llog_cleanup(NULL, ctxt);
3004 static int mdc_process_config(struct obd_device *obd, obd_count len, void *buf)
3006 struct lustre_cfg *lcfg = buf;
3007 int rc = class_process_proc_param(PARAM_MDC, obd->obd_vars, lcfg, obd);
3008 return (rc > 0 ? 0: rc);
3012 /* get remote permission for current user on fid */
3013 int mdc_get_remote_perm(struct obd_export *exp, const struct lu_fid *fid,
3014 struct obd_capa *oc, __u32 suppgid,
3015 struct ptlrpc_request **request)
3017 struct ptlrpc_request *req;
3021 LASSERT(client_is_remote(exp));
3024 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR);
3028 mdc_set_capa_size(req, &RMF_CAPA1, oc);
3030 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR);
3032 ptlrpc_request_free(req);
3036 mdc_pack_body(req, fid, oc, OBD_MD_FLRMTPERM, 0, suppgid, 0);
3038 req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER,
3039 sizeof(struct mdt_remote_perm));
3041 ptlrpc_request_set_replen(req);
3043 rc = ptlrpc_queue_wait(req);
3045 ptlrpc_req_finished(req);
3051 static int mdc_interpret_renew_capa(const struct lu_env *env,
3052 struct ptlrpc_request *req, void *args,
3055 struct mdc_renew_capa_args *ra = args;
3056 struct mdt_body *body = NULL;
3057 struct lustre_capa *capa;
3061 GOTO(out, capa = ERR_PTR(status));
3063 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
3065 GOTO(out, capa = ERR_PTR(-EFAULT));
3067 if ((body->mbo_valid & OBD_MD_FLOSSCAPA) == 0)
3068 GOTO(out, capa = ERR_PTR(-ENOENT));
3070 capa = req_capsule_server_get(&req->rq_pill, &RMF_CAPA2);
3072 GOTO(out, capa = ERR_PTR(-EFAULT));
3075 ra->ra_cb(ra->ra_oc, capa);
3079 static int mdc_renew_capa(struct obd_export *exp, struct obd_capa *oc,
3082 struct ptlrpc_request *req;
3083 struct mdc_renew_capa_args *ra;
3086 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_GETATTR,
3087 LUSTRE_MDS_VERSION, MDS_GETATTR);
3091 /* NB, OBD_MD_FLOSSCAPA is set here, but it doesn't necessarily mean the
3092 * capa to renew is oss capa.
3094 mdc_pack_body(req, &oc->c_capa.lc_fid, oc, OBD_MD_FLOSSCAPA, 0, -1, 0);
3095 ptlrpc_request_set_replen(req);
3097 CLASSERT(sizeof(*ra) <= sizeof(req->rq_async_args));
3098 ra = ptlrpc_req_async_args(req);
3101 req->rq_interpret_reply = mdc_interpret_renew_capa;
3102 ptlrpcd_add_req(req, PDL_POLICY_LOCAL, -1);
3106 struct obd_ops mdc_obd_ops = {
3107 .o_owner = THIS_MODULE,
3108 .o_setup = mdc_setup,
3109 .o_precleanup = mdc_precleanup,
3110 .o_cleanup = mdc_cleanup,
3111 .o_add_conn = client_import_add_conn,
3112 .o_del_conn = client_import_del_conn,
3113 .o_connect = client_connect_import,
3114 .o_disconnect = client_disconnect_export,
3115 .o_iocontrol = mdc_iocontrol,
3116 .o_set_info_async = mdc_set_info_async,
3117 .o_statfs = mdc_statfs,
3118 .o_fid_init = client_fid_init,
3119 .o_fid_fini = client_fid_fini,
3120 .o_fid_alloc = mdc_fid_alloc,
3121 .o_import_event = mdc_import_event,
3122 .o_llog_init = mdc_llog_init,
3123 .o_llog_finish = mdc_llog_finish,
3124 .o_get_info = mdc_get_info,
3125 .o_process_config = mdc_process_config,
3126 .o_get_uuid = mdc_get_uuid,
3127 .o_quotactl = mdc_quotactl,
3128 .o_quotacheck = mdc_quotacheck
3131 struct md_ops mdc_md_ops = {
3132 .m_getstatus = mdc_getstatus,
3133 .m_null_inode = mdc_null_inode,
3134 .m_find_cbdata = mdc_find_cbdata,
3135 .m_close = mdc_close,
3136 .m_create = mdc_create,
3137 .m_done_writing = mdc_done_writing,
3138 .m_enqueue = mdc_enqueue,
3139 .m_getattr = mdc_getattr,
3140 .m_getattr_name = mdc_getattr_name,
3141 .m_intent_lock = mdc_intent_lock,
3143 .m_rename = mdc_rename,
3144 .m_setattr = mdc_setattr,
3145 .m_setxattr = mdc_setxattr,
3146 .m_getxattr = mdc_getxattr,
3147 .m_fsync = mdc_fsync,
3148 .m_read_page = mdc_read_page,
3149 .m_unlink = mdc_unlink,
3150 .m_cancel_unused = mdc_cancel_unused,
3151 .m_init_ea_size = mdc_init_ea_size,
3152 .m_set_lock_data = mdc_set_lock_data,
3153 .m_lock_match = mdc_lock_match,
3154 .m_get_lustre_md = mdc_get_lustre_md,
3155 .m_free_lustre_md = mdc_free_lustre_md,
3156 .m_set_open_replay_data = mdc_set_open_replay_data,
3157 .m_clear_open_replay_data = mdc_clear_open_replay_data,
3158 .m_renew_capa = mdc_renew_capa,
3159 .m_unpack_capa = mdc_unpack_capa,
3160 .m_get_remote_perm = mdc_get_remote_perm,
3161 .m_intent_getattr_async = mdc_intent_getattr_async,
3162 .m_revalidate_lock = mdc_revalidate_lock
3165 int __init mdc_init(void)
3167 return class_register_type(&mdc_obd_ops, &mdc_md_ops, true, NULL,
3168 LUSTRE_MDC_NAME, NULL);
3171 static void /*__exit*/ mdc_exit(void)
3173 class_unregister_type(LUSTRE_MDC_NAME);
3176 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
3177 MODULE_DESCRIPTION("Lustre Metadata Client");
3178 MODULE_LICENSE("GPL");
3180 module_init(mdc_init);
3181 module_exit(mdc_exit);