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>
55 #include "mdc_internal.h"
57 #define REQUEST_MINOR 244
59 struct mdc_renew_capa_args {
60 struct obd_capa *ra_oc;
61 renew_capa_cb_t ra_cb;
64 static int mdc_cleanup(struct obd_device *obd);
66 static int mdc_unpack_capa(struct obd_export *exp, struct ptlrpc_request *req,
67 const struct req_msg_field *field,
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 static 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 static 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 static 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 static int mdc_setxattr(struct obd_export *exp, const struct lu_fid *fid,
422 struct obd_capa *oc, obd_valid valid,
423 const char *xattr_name,
424 const char *input, int input_size, int output_size,
425 int flags, __u32 suppgid,
426 struct ptlrpc_request **request)
428 return mdc_xattr_common(exp, &RQF_MDS_REINT_SETXATTR,
429 fid, oc, MDS_REINT, valid, xattr_name,
430 input, input_size, output_size, flags,
434 static int mdc_getxattr(struct obd_export *exp, const struct lu_fid *fid,
435 struct obd_capa *oc, obd_valid valid,
436 const char *xattr_name,
437 const char *input, int input_size, int output_size,
438 int flags, struct ptlrpc_request **request)
440 return mdc_xattr_common(exp, &RQF_MDS_GETXATTR,
441 fid, oc, MDS_GETXATTR, valid, xattr_name,
442 input, input_size, output_size, flags,
446 #ifdef CONFIG_FS_POSIX_ACL
447 static int mdc_unpack_acl(struct ptlrpc_request *req, struct lustre_md *md)
449 struct req_capsule *pill = &req->rq_pill;
450 struct mdt_body *body = md->body;
451 struct posix_acl *acl;
456 if (!body->mbo_aclsize)
459 buf = req_capsule_server_sized_get(pill, &RMF_ACL, body->mbo_aclsize);
464 acl = posix_acl_from_xattr(&init_user_ns, buf, body->mbo_aclsize);
469 CERROR("convert xattr to acl: %d\n", rc);
473 rc = posix_acl_valid(acl);
475 CERROR("validate acl: %d\n", rc);
476 posix_acl_release(acl);
484 #define mdc_unpack_acl(req, md) 0
487 int mdc_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
488 struct obd_export *dt_exp, struct obd_export *md_exp,
489 struct lustre_md *md)
491 struct req_capsule *pill = &req->rq_pill;
496 memset(md, 0, sizeof(*md));
498 md->body = req_capsule_server_get(pill, &RMF_MDT_BODY);
499 LASSERT(md->body != NULL);
501 if (md->body->mbo_valid & OBD_MD_FLEASIZE) {
503 struct lov_mds_md *lmm;
505 if (!S_ISREG(md->body->mbo_mode)) {
506 CDEBUG(D_INFO, "OBD_MD_FLEASIZE set, should be a "
507 "regular file, but is not\n");
508 GOTO(out, rc = -EPROTO);
511 if (md->body->mbo_eadatasize == 0) {
512 CDEBUG(D_INFO, "OBD_MD_FLEASIZE set, "
513 "but eadatasize 0\n");
514 GOTO(out, rc = -EPROTO);
517 lmmsize = md->body->mbo_eadatasize;
518 lmm = req_capsule_server_sized_get(pill, &RMF_MDT_MD, lmmsize);
520 GOTO(out, rc = -EPROTO);
522 rc = obd_unpackmd(dt_exp, &md->lsm, lmm, lmmsize);
526 if (rc < (typeof(rc))sizeof(*md->lsm)) {
527 CDEBUG(D_INFO, "lsm size too small: "
528 "rc < sizeof (*md->lsm) (%d < %d)\n",
529 rc, (int)sizeof(*md->lsm));
530 GOTO(out, rc = -EPROTO);
533 } else if (md->body->mbo_valid & OBD_MD_FLDIREA) {
535 struct lov_mds_md *lmv;
537 if (!S_ISDIR(md->body->mbo_mode)) {
538 CDEBUG(D_INFO, "OBD_MD_FLDIREA set, should be a "
539 "directory, but is not\n");
540 GOTO(out, rc = -EPROTO);
543 if (md->body->mbo_eadatasize == 0) {
544 CDEBUG(D_INFO, "OBD_MD_FLDIREA is set, "
545 "but eadatasize 0\n");
549 if (md->body->mbo_valid & OBD_MD_MEA) {
550 lmvsize = md->body->mbo_eadatasize;
551 lmv = req_capsule_server_sized_get(pill, &RMF_MDT_MD,
554 GOTO(out, rc = -EPROTO);
556 rc = obd_unpackmd(md_exp, (void *)&md->lmv, lmv,
561 if (rc < (typeof(rc))sizeof(*md->lmv)) {
562 CDEBUG(D_INFO, "size too small: "
563 "rc < sizeof(*md->lmv) (%d < %d)\n",
564 rc, (int)sizeof(*md->lmv));
565 GOTO(out, rc = -EPROTO);
571 if (md->body->mbo_valid & OBD_MD_FLRMTPERM) {
572 /* remote permission */
573 LASSERT(client_is_remote(exp));
574 md->remote_perm = req_capsule_server_swab_get(pill, &RMF_ACL,
575 lustre_swab_mdt_remote_perm);
576 if (!md->remote_perm)
577 GOTO(out, rc = -EPROTO);
578 } else if (md->body->mbo_valid & OBD_MD_FLACL) {
579 /* for ACL, it's possible that FLACL is set but aclsize is zero.
580 * only when aclsize != 0 there's an actual segment for ACL
583 if (md->body->mbo_aclsize) {
584 rc = mdc_unpack_acl(req, md);
587 #ifdef CONFIG_FS_POSIX_ACL
589 md->posix_acl = NULL;
593 if (md->body->mbo_valid & OBD_MD_FLMDSCAPA) {
594 struct obd_capa *oc = NULL;
596 rc = mdc_unpack_capa(NULL, req, &RMF_CAPA1, &oc);
602 if (md->body->mbo_valid & OBD_MD_FLOSSCAPA) {
603 struct obd_capa *oc = NULL;
605 rc = mdc_unpack_capa(NULL, req, &RMF_CAPA2, &oc);
615 capa_put(md->oss_capa);
619 capa_put(md->mds_capa);
622 #ifdef CONFIG_FS_POSIX_ACL
623 posix_acl_release(md->posix_acl);
626 obd_free_memmd(dt_exp, &md->lsm);
631 int mdc_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
638 * Handles both OPEN and SETATTR RPCs for OPEN-CLOSE and SETATTR-DONE_WRITING
641 void mdc_replay_open(struct ptlrpc_request *req)
643 struct md_open_data *mod = req->rq_cb_data;
644 struct ptlrpc_request *close_req;
645 struct obd_client_handle *och;
646 struct lustre_handle old;
647 struct mdt_body *body;
651 DEBUG_REQ(D_ERROR, req,
652 "Can't properly replay without open data.");
657 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
658 LASSERT(body != NULL);
662 struct lustre_handle *file_fh;
664 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
666 file_fh = &och->och_fh;
667 CDEBUG(D_HA, "updating handle from "LPX64" to "LPX64"\n",
668 file_fh->cookie, body->mbo_handle.cookie);
670 *file_fh = body->mbo_handle;
672 close_req = mod->mod_close_req;
673 if (close_req != NULL) {
674 __u32 opc = lustre_msg_get_opc(close_req->rq_reqmsg);
675 struct mdt_ioepoch *epoch;
677 LASSERT(opc == MDS_CLOSE || opc == MDS_DONE_WRITING);
678 epoch = req_capsule_client_get(&close_req->rq_pill,
683 LASSERT(!memcmp(&old, &epoch->handle, sizeof(old)));
684 DEBUG_REQ(D_HA, close_req, "updating close body with new fh");
685 epoch->handle = body->mbo_handle;
690 void mdc_commit_open(struct ptlrpc_request *req)
692 struct md_open_data *mod = req->rq_cb_data;
697 * No need to touch md_open_data::mod_och, it holds a reference on
698 * \var mod and will zero references to each other, \var mod will be
699 * freed after that when md_open_data::mod_och will put the reference.
703 * Do not let open request to disappear as it still may be needed
704 * for close rpc to happen (it may happen on evict only, otherwise
705 * ptlrpc_request::rq_replay does not let mdc_commit_open() to be
706 * called), just mark this rpc as committed to distinguish these 2
707 * cases, see mdc_close() for details. The open request reference will
708 * be put along with freeing \var mod.
710 ptlrpc_request_addref(req);
711 spin_lock(&req->rq_lock);
712 req->rq_committed = 1;
713 spin_unlock(&req->rq_lock);
714 req->rq_cb_data = NULL;
718 int mdc_set_open_replay_data(struct obd_export *exp,
719 struct obd_client_handle *och,
720 struct lookup_intent *it)
722 struct md_open_data *mod;
723 struct mdt_rec_create *rec;
724 struct mdt_body *body;
725 struct ptlrpc_request *open_req = it->d.lustre.it_data;
726 struct obd_import *imp = open_req->rq_import;
729 if (!open_req->rq_replay)
732 rec = req_capsule_client_get(&open_req->rq_pill, &RMF_REC_REINT);
733 body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY);
734 LASSERT(rec != NULL);
735 /* Incoming message in my byte order (it's been swabbed). */
736 /* Outgoing messages always in my byte order. */
737 LASSERT(body != NULL);
739 /* Only if the import is replayable, we set replay_open data */
740 if (och && imp->imp_replayable) {
741 mod = obd_mod_alloc();
743 DEBUG_REQ(D_ERROR, open_req,
744 "Can't allocate md_open_data");
749 * Take a reference on \var mod, to be freed on mdc_close().
750 * It protects \var mod from being freed on eviction (commit
751 * callback is called despite rq_replay flag).
752 * Another reference for \var och.
757 spin_lock(&open_req->rq_lock);
760 mod->mod_is_create = it_disposition(it, DISP_OPEN_CREATE) ||
761 it_disposition(it, DISP_OPEN_STRIPE);
762 mod->mod_open_req = open_req;
763 open_req->rq_cb_data = mod;
764 open_req->rq_commit_cb = mdc_commit_open;
765 spin_unlock(&open_req->rq_lock);
768 rec->cr_fid2 = body->mbo_fid1;
769 rec->cr_ioepoch = body->mbo_ioepoch;
770 rec->cr_old_handle.cookie = body->mbo_handle.cookie;
771 open_req->rq_replay_cb = mdc_replay_open;
772 if (!fid_is_sane(&body->mbo_fid1)) {
773 DEBUG_REQ(D_ERROR, open_req, "Saving replay request with "
778 DEBUG_REQ(D_RPCTRACE, open_req, "Set up open replay data");
782 static void mdc_free_open(struct md_open_data *mod)
786 if (mod->mod_is_create == 0 &&
787 imp_connect_disp_stripe(mod->mod_open_req->rq_import))
790 LASSERT(mod->mod_open_req->rq_replay == 0);
792 DEBUG_REQ(D_RPCTRACE, mod->mod_open_req, "free open request\n");
794 ptlrpc_request_committed(mod->mod_open_req, committed);
795 if (mod->mod_close_req)
796 ptlrpc_request_committed(mod->mod_close_req, committed);
799 int mdc_clear_open_replay_data(struct obd_export *exp,
800 struct obd_client_handle *och)
802 struct md_open_data *mod = och->och_mod;
806 * It is possible to not have \var mod in a case of eviction between
807 * lookup and ll_file_open().
812 LASSERT(mod != LP_POISON);
813 LASSERT(mod->mod_open_req != NULL);
823 /* Prepares the request for the replay by the given reply */
824 static void mdc_close_handle_reply(struct ptlrpc_request *req,
825 struct md_op_data *op_data, int rc) {
826 struct mdt_body *repbody;
827 struct mdt_ioepoch *epoch;
829 if (req && rc == -EAGAIN) {
830 repbody = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
831 epoch = req_capsule_client_get(&req->rq_pill, &RMF_MDT_EPOCH);
833 epoch->flags |= MF_SOM_AU;
834 if (repbody->mbo_valid & OBD_MD_FLGETATTRLOCK)
835 op_data->op_flags |= MF_GETATTR_LOCK;
839 static int mdc_close(struct obd_export *exp, struct md_op_data *op_data,
840 struct md_open_data *mod, struct ptlrpc_request **request)
842 struct obd_device *obd = class_exp2obd(exp);
843 struct ptlrpc_request *req;
844 struct req_format *req_fmt;
849 req_fmt = &RQF_MDS_CLOSE;
850 if (op_data->op_bias & MDS_HSM_RELEASE) {
851 req_fmt = &RQF_MDS_RELEASE_CLOSE;
853 /* allocate a FID for volatile file */
854 rc = mdc_fid_alloc(NULL, exp, &op_data->op_fid2, op_data);
856 CERROR("%s: "DFID" failed to allocate FID: %d\n",
857 obd->obd_name, PFID(&op_data->op_fid1), rc);
858 /* save the errcode and proceed to close */
864 req = ptlrpc_request_alloc(class_exp2cliimp(exp), req_fmt);
868 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
870 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_CLOSE);
872 ptlrpc_request_free(req);
876 /* To avoid a livelock (bug 7034), we need to send CLOSE RPCs to a
877 * portal whose threads are not taking any DLM locks and are therefore
878 * always progressing */
879 req->rq_request_portal = MDS_READPAGE_PORTAL;
880 ptlrpc_at_set_req_timeout(req);
882 /* Ensure that this close's handle is fixed up during replay. */
883 if (likely(mod != NULL)) {
884 LASSERTF(mod->mod_open_req != NULL &&
885 mod->mod_open_req->rq_type != LI_POISON,
886 "POISONED open %p!\n", mod->mod_open_req);
888 mod->mod_close_req = req;
890 DEBUG_REQ(D_HA, mod->mod_open_req, "matched open");
891 /* We no longer want to preserve this open for replay even
892 * though the open was committed. b=3632, b=3633 */
893 spin_lock(&mod->mod_open_req->rq_lock);
894 mod->mod_open_req->rq_replay = 0;
895 spin_unlock(&mod->mod_open_req->rq_lock);
897 CDEBUG(D_HA, "couldn't find open req; expecting close error\n");
900 mdc_close_pack(req, op_data);
902 req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER,
903 obd->u.cli.cl_default_mds_easize);
904 req_capsule_set_size(&req->rq_pill, &RMF_LOGCOOKIES, RCL_SERVER,
905 obd->u.cli.cl_default_mds_cookiesize);
907 ptlrpc_request_set_replen(req);
909 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
910 rc = ptlrpc_queue_wait(req);
911 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
913 if (req->rq_repmsg == NULL) {
914 CDEBUG(D_RPCTRACE, "request failed to send: %p, %d\n", req,
917 rc = req->rq_status ?: -EIO;
918 } else if (rc == 0 || rc == -EAGAIN) {
919 struct mdt_body *body;
921 rc = lustre_msg_get_status(req->rq_repmsg);
922 if (lustre_msg_get_type(req->rq_repmsg) == PTL_RPC_MSG_ERR) {
923 DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, err "
928 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
931 } else if (rc == -ESTALE) {
933 * it can be allowed error after 3633 if open was committed and
934 * server failed before close was sent. Let's check if mod
935 * exists and return no error in that case
938 DEBUG_REQ(D_HA, req, "Reset ESTALE = %d", rc);
939 LASSERT(mod->mod_open_req != NULL);
940 if (mod->mod_open_req->rq_committed)
947 mod->mod_close_req = NULL;
948 /* Since now, mod is accessed through open_req only,
949 * thus close req does not keep a reference on mod anymore. */
953 mdc_close_handle_reply(req, op_data, rc);
954 RETURN(rc < 0 ? rc : saved_rc);
957 static int mdc_done_writing(struct obd_export *exp, struct md_op_data *op_data,
958 struct md_open_data *mod)
960 struct obd_device *obd = class_exp2obd(exp);
961 struct ptlrpc_request *req;
965 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
966 &RQF_MDS_DONE_WRITING);
970 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
971 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_DONE_WRITING);
973 ptlrpc_request_free(req);
978 LASSERTF(mod->mod_open_req != NULL &&
979 mod->mod_open_req->rq_type != LI_POISON,
980 "POISONED setattr %p!\n", mod->mod_open_req);
982 mod->mod_close_req = req;
983 DEBUG_REQ(D_HA, mod->mod_open_req, "matched setattr");
984 /* We no longer want to preserve this setattr for replay even
985 * though the open was committed. b=3632, b=3633 */
986 spin_lock(&mod->mod_open_req->rq_lock);
987 mod->mod_open_req->rq_replay = 0;
988 spin_unlock(&mod->mod_open_req->rq_lock);
991 mdc_close_pack(req, op_data);
992 ptlrpc_request_set_replen(req);
994 mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
995 rc = ptlrpc_queue_wait(req);
996 mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
1000 * it can be allowed error after 3633 if open or setattr were
1001 * committed and server failed before close was sent.
1002 * Let's check if mod exists and return no error in that case
1005 LASSERT(mod->mod_open_req != NULL);
1006 if (mod->mod_open_req->rq_committed)
1013 mod->mod_close_req = NULL;
1014 LASSERT(mod->mod_open_req != NULL);
1017 /* Since now, mod is accessed through setattr req only,
1018 * thus DW req does not keep a reference on mod anymore. */
1022 mdc_close_handle_reply(req, op_data, rc);
1023 ptlrpc_req_finished(req);
1027 #ifdef HAVE_SPLIT_SUPPORT
1028 int mdc_sendpage(struct obd_export *exp, const struct lu_fid *fid,
1029 const struct page *page, int offset)
1031 struct ptlrpc_request *req;
1032 struct ptlrpc_bulk_desc *desc;
1036 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_WRITEPAGE);
1040 /* FIXME: capa doesn't support split yet */
1041 mdc_set_capa_size(req, &RMF_CAPA1, NULL);
1043 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_WRITEPAGE);
1045 ptlrpc_request_free(req);
1049 req->rq_request_portal = MDS_READPAGE_PORTAL;
1050 ptlrpc_at_set_req_timeout(req);
1052 desc = ptlrpc_prep_bulk_imp(req, 1, 1,BULK_GET_SOURCE, MDS_BULK_PORTAL);
1054 GOTO(out, rc = -ENOMEM);
1056 /* NB req now owns desc and will free it when it gets freed. */
1057 ptlrpc_prep_bulk_page(desc, (struct page *)page, 0, offset);
1058 mdc_readdir_pack(req, 0, offset, fid, NULL);
1060 ptlrpc_request_set_replen(req);
1061 rc = ptlrpc_queue_wait(req);
1065 rc = sptlrpc_cli_unwrap_bulk_write(req, req->rq_bulk);
1067 ptlrpc_req_finished(req);
1070 EXPORT_SYMBOL(mdc_sendpage);
1073 static int mdc_getpage(struct obd_export *exp, const struct lu_fid *fid,
1074 __u64 offset, struct obd_capa *oc,
1075 struct page **pages, int npages,
1076 struct ptlrpc_request **request)
1078 struct ptlrpc_request *req;
1079 struct ptlrpc_bulk_desc *desc;
1081 wait_queue_head_t waitq;
1083 struct l_wait_info lwi;
1088 init_waitqueue_head(&waitq);
1091 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_READPAGE);
1095 mdc_set_capa_size(req, &RMF_CAPA1, oc);
1097 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_READPAGE);
1099 ptlrpc_request_free(req);
1103 req->rq_request_portal = MDS_READPAGE_PORTAL;
1104 ptlrpc_at_set_req_timeout(req);
1106 desc = ptlrpc_prep_bulk_imp(req, npages, 1, BULK_PUT_SINK,
1109 ptlrpc_request_free(req);
1113 /* NB req now owns desc and will free it when it gets freed */
1114 for (i = 0; i < npages; i++)
1115 ptlrpc_prep_bulk_page_pin(desc, pages[i], 0, PAGE_CACHE_SIZE);
1117 mdc_readdir_pack(req, offset, PAGE_CACHE_SIZE * npages, fid, oc);
1119 ptlrpc_request_set_replen(req);
1120 rc = ptlrpc_queue_wait(req);
1122 ptlrpc_req_finished(req);
1123 if (rc != -ETIMEDOUT)
1127 if (!client_should_resend(resends, &exp->exp_obd->u.cli)) {
1128 CERROR("%s: too many resend retries: rc = %d\n",
1129 exp->exp_obd->obd_name, -EIO);
1132 lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(resends), NULL, NULL,
1134 l_wait_event(waitq, 0, &lwi);
1139 rc = sptlrpc_cli_unwrap_bulk_read(req, req->rq_bulk,
1140 req->rq_bulk->bd_nob_transferred);
1142 ptlrpc_req_finished(req);
1146 if (req->rq_bulk->bd_nob_transferred & ~LU_PAGE_MASK) {
1147 CERROR("%s: unexpected bytes transferred: %d (%ld expected)\n",
1148 exp->exp_obd->obd_name, req->rq_bulk->bd_nob_transferred,
1149 PAGE_CACHE_SIZE * npages);
1150 ptlrpc_req_finished(req);
1158 static void mdc_release_page(struct page *page, int remove)
1162 if (likely(page->mapping != NULL))
1163 truncate_complete_page(page->mapping, page);
1166 page_cache_release(page);
1169 static struct page *mdc_page_locate(struct address_space *mapping, __u64 *hash,
1170 __u64 *start, __u64 *end, int hash64)
1173 * Complement of hash is used as an index so that
1174 * radix_tree_gang_lookup() can be used to find a page with starting
1175 * hash _smaller_ than one we are looking for.
1177 unsigned long offset = hash_x_index(*hash, hash64);
1181 spin_lock_irq(&mapping->tree_lock);
1182 found = radix_tree_gang_lookup(&mapping->page_tree,
1183 (void **)&page, offset, 1);
1184 if (found > 0 && !radix_tree_exceptional_entry(page)) {
1185 struct lu_dirpage *dp;
1187 page_cache_get(page);
1188 spin_unlock_irq(&mapping->tree_lock);
1190 * In contrast to find_lock_page() we are sure that directory
1191 * page cannot be truncated (while DLM lock is held) and,
1192 * hence, can avoid restart.
1194 * In fact, page cannot be locked here at all, because
1195 * mdc_read_page_remote does synchronous io.
1197 wait_on_page_locked(page);
1198 if (PageUptodate(page)) {
1200 if (BITS_PER_LONG == 32 && hash64) {
1201 *start = le64_to_cpu(dp->ldp_hash_start) >> 32;
1202 *end = le64_to_cpu(dp->ldp_hash_end) >> 32;
1203 *hash = *hash >> 32;
1205 *start = le64_to_cpu(dp->ldp_hash_start);
1206 *end = le64_to_cpu(dp->ldp_hash_end);
1208 if (unlikely(*start == 1 && *hash == 0))
1211 LASSERTF(*start <= *hash, "start = "LPX64
1212 ",end = "LPX64",hash = "LPX64"\n",
1213 *start, *end, *hash);
1214 CDEBUG(D_VFSTRACE, "offset %lx ["LPX64" "LPX64"],"
1215 " hash "LPX64"\n", offset, *start, *end, *hash);
1218 mdc_release_page(page, 0);
1220 } else if (*end != *start && *hash == *end) {
1222 * upon hash collision, remove this page,
1223 * otherwise put page reference, and
1224 * mdc_read_page_remote() will issue RPC to
1225 * fetch the page we want.
1228 mdc_release_page(page,
1229 le32_to_cpu(dp->ldp_flags) & LDF_COLLIDE);
1233 page_cache_release(page);
1234 page = ERR_PTR(-EIO);
1237 spin_unlock_irq(&mapping->tree_lock);
1244 * Adjust a set of pages, each page containing an array of lu_dirpages,
1245 * so that each page can be used as a single logical lu_dirpage.
1247 * A lu_dirpage is laid out as follows, where s = ldp_hash_start,
1248 * e = ldp_hash_end, f = ldp_flags, p = padding, and each "ent" is a
1249 * struct lu_dirent. It has size up to LU_PAGE_SIZE. The ldp_hash_end
1250 * value is used as a cookie to request the next lu_dirpage in a
1251 * directory listing that spans multiple pages (two in this example):
1254 * .|--------v------- -----.
1255 * |s|e|f|p|ent|ent| ... |ent|
1256 * '--|-------------- -----' Each CFS_PAGE contains a single
1257 * '------. lu_dirpage.
1258 * .---------v------- -----.
1259 * |s|e|f|p|ent| 0 | ... | 0 |
1260 * '----------------- -----'
1262 * However, on hosts where the native VM page size (PAGE_CACHE_SIZE) is
1263 * larger than LU_PAGE_SIZE, a single host page may contain multiple
1264 * lu_dirpages. After reading the lu_dirpages from the MDS, the
1265 * ldp_hash_end of the first lu_dirpage refers to the one immediately
1266 * after it in the same CFS_PAGE (arrows simplified for brevity, but
1267 * in general e0==s1, e1==s2, etc.):
1269 * .-------------------- -----.
1270 * |s0|e0|f0|p|ent|ent| ... |ent|
1271 * |---v---------------- -----|
1272 * |s1|e1|f1|p|ent|ent| ... |ent|
1273 * |---v---------------- -----| Here, each CFS_PAGE contains
1274 * ... multiple lu_dirpages.
1275 * |---v---------------- -----|
1276 * |s'|e'|f'|p|ent|ent| ... |ent|
1277 * '---|---------------- -----'
1279 * .----------------------------.
1282 * This structure is transformed into a single logical lu_dirpage as follows:
1284 * - Replace e0 with e' so the request for the next lu_dirpage gets the page
1285 * labeled 'next CFS_PAGE'.
1287 * - Copy the LDF_COLLIDE flag from f' to f0 to correctly reflect whether
1288 * a hash collision with the next page exists.
1290 * - Adjust the lde_reclen of the ending entry of each lu_dirpage to span
1291 * to the first entry of the next lu_dirpage.
1293 #if PAGE_CACHE_SIZE > LU_PAGE_SIZE
1294 static void mdc_adjust_dirpages(struct page **pages, int cfs_pgs, int lu_pgs)
1298 for (i = 0; i < cfs_pgs; i++) {
1299 struct lu_dirpage *dp = kmap(pages[i]);
1300 struct lu_dirpage *first = dp;
1301 struct lu_dirent *end_dirent = NULL;
1302 struct lu_dirent *ent;
1303 __u64 hash_end = le64_to_cpu(dp->ldp_hash_end);
1304 __u32 flags = le32_to_cpu(dp->ldp_flags);
1306 while (--lu_pgs > 0) {
1307 ent = lu_dirent_start(dp);
1308 for (end_dirent = ent; ent != NULL;
1309 end_dirent = ent, ent = lu_dirent_next(ent));
1311 /* Advance dp to next lu_dirpage. */
1312 dp = (struct lu_dirpage *)((char *)dp + LU_PAGE_SIZE);
1314 /* Check if we've reached the end of the CFS_PAGE. */
1315 if (!((unsigned long)dp & ~CFS_PAGE_MASK))
1318 /* Save the hash and flags of this lu_dirpage. */
1319 hash_end = le64_to_cpu(dp->ldp_hash_end);
1320 flags = le32_to_cpu(dp->ldp_flags);
1322 /* Check if lu_dirpage contains no entries. */
1323 if (end_dirent == NULL)
1326 /* Enlarge the end entry lde_reclen from 0 to
1327 * first entry of next lu_dirpage. */
1328 LASSERT(le16_to_cpu(end_dirent->lde_reclen) == 0);
1329 end_dirent->lde_reclen =
1330 cpu_to_le16((char *)(dp->ldp_entries) -
1331 (char *)end_dirent);
1334 first->ldp_hash_end = hash_end;
1335 first->ldp_flags &= ~cpu_to_le32(LDF_COLLIDE);
1336 first->ldp_flags |= flags & cpu_to_le32(LDF_COLLIDE);
1340 LASSERTF(lu_pgs == 0, "left = %d\n", lu_pgs);
1343 #define mdc_adjust_dirpages(pages, cfs_pgs, lu_pgs) do {} while (0)
1344 #endif /* PAGE_CACHE_SIZE > LU_PAGE_SIZE */
1346 /* parameters for readdir page */
1347 struct readpage_param {
1348 struct md_op_data *rp_mod;
1351 struct obd_export *rp_exp;
1352 struct md_callback *rp_cb;
1356 * Read pages from server.
1358 * Page in MDS_READPAGE RPC is packed in LU_PAGE_SIZE, and each page contains
1359 * a header lu_dirpage which describes the start/end hash, and whether this
1360 * page is empty (contains no dir entry) or hash collide with next page.
1361 * After client receives reply, several pages will be integrated into dir page
1362 * in CFS_PAGE_SIZE (if CFS_PAGE_SIZE greater than LU_PAGE_SIZE), and the
1363 * lu_dirpage for this integrated page will be adjusted.
1365 static int mdc_read_page_remote(void *data, struct page *page0)
1367 struct readpage_param *rp = data;
1368 struct page **page_pool;
1370 struct lu_dirpage *dp;
1371 int rd_pgs = 0; /* number of pages read actually */
1373 struct md_op_data *op_data = rp->rp_mod;
1374 struct ptlrpc_request *req;
1375 int max_pages = op_data->op_max_pages;
1376 struct inode *inode;
1382 LASSERT(max_pages > 0 && max_pages <= PTLRPC_MAX_BRW_PAGES);
1383 inode = op_data->op_data;
1384 fid = &op_data->op_fid1;
1385 LASSERT(inode != NULL);
1387 OBD_ALLOC(page_pool, sizeof(page_pool[0]) * max_pages);
1388 if (page_pool != NULL) {
1389 page_pool[0] = page0;
1395 for (npages = 1; npages < max_pages; npages++) {
1396 page = page_cache_alloc_cold(inode->i_mapping);
1399 page_pool[npages] = page;
1402 rc = mdc_getpage(rp->rp_exp, fid, rp->rp_off, op_data->op_capa1,
1403 page_pool, npages, &req);
1407 rd_pgs = (req->rq_bulk->bd_nob_transferred +
1408 PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
1409 lu_pgs = req->rq_bulk->bd_nob_transferred >>
1411 LASSERT(!(req->rq_bulk->bd_nob_transferred & ~LU_PAGE_MASK));
1413 CDEBUG(D_INODE, "read %d(%d) pages\n", rd_pgs, lu_pgs);
1415 mdc_adjust_dirpages(page_pool, rd_pgs, lu_pgs);
1417 SetPageUptodate(page0);
1421 ptlrpc_req_finished(req);
1422 CDEBUG(D_CACHE, "read %d/%d pages\n", rd_pgs, npages);
1423 for (i = 1; i < npages; i++) {
1424 unsigned long offset;
1428 page = page_pool[i];
1430 if (rc < 0 || i >= rd_pgs) {
1431 page_cache_release(page);
1435 SetPageUptodate(page);
1438 hash = le64_to_cpu(dp->ldp_hash_start);
1441 offset = hash_x_index(hash, rp->rp_hash64);
1443 prefetchw(&page->flags);
1444 ret = add_to_page_cache_lru(page, inode->i_mapping, offset,
1449 CDEBUG(D_VFSTRACE, "page %lu add to page cache failed:"
1450 " rc = %d\n", offset, ret);
1451 page_cache_release(page);
1454 if (page_pool != &page0)
1455 OBD_FREE(page_pool, sizeof(page_pool[0]) * max_pages);
1461 * Read dir page from cache first, if it can not find it, read it from
1462 * server and add into the cache.
1464 * \param[in] exp MDC export
1465 * \param[in] op_data client MD stack parameters, transfering parameters
1466 * between different layers on client MD stack.
1467 * \param[in] cb_op callback required for ldlm lock enqueue during
1469 * \param[in] hash_offset the hash offset of the page to be read
1470 * \param[in] ppage the page to be read
1472 * retval = 0 get the page successfully
1473 * errno(<0) get the page failed
1475 static int mdc_read_page(struct obd_export *exp, struct md_op_data *op_data,
1476 struct md_callback *cb_op, __u64 hash_offset,
1477 struct page **ppage)
1479 struct lookup_intent it = { .it_op = IT_READDIR };
1481 struct inode *dir = op_data->op_data;
1482 struct address_space *mapping;
1483 struct lu_dirpage *dp;
1486 struct lustre_handle lockh;
1487 struct ptlrpc_request *enq_req = NULL;
1488 struct readpage_param rp_param;
1495 LASSERT(dir != NULL);
1496 mapping = dir->i_mapping;
1498 rc = mdc_intent_lock(exp, op_data, &it, &enq_req,
1499 cb_op->md_blocking_ast, 0);
1500 if (enq_req != NULL)
1501 ptlrpc_req_finished(enq_req);
1504 CERROR("%s: "DFID" lock enqueue fails: rc = %d\n",
1505 exp->exp_obd->obd_name, PFID(&op_data->op_fid1), rc);
1510 mdc_set_lock_data(exp, &it.d.lustre.it_lock_handle, dir, NULL);
1512 rp_param.rp_off = hash_offset;
1513 rp_param.rp_hash64 = op_data->op_cli_flags & CLI_HASH64;
1514 page = mdc_page_locate(mapping, &rp_param.rp_off, &start, &end,
1515 rp_param.rp_hash64);
1517 CERROR("%s: dir page locate: "DFID" at "LPU64": rc %ld\n",
1518 exp->exp_obd->obd_name, PFID(&op_data->op_fid1),
1519 rp_param.rp_off, PTR_ERR(page));
1520 GOTO(out_unlock, rc = PTR_ERR(page));
1521 } else if (page != NULL) {
1523 * XXX nikita: not entirely correct handling of a corner case:
1524 * suppose hash chain of entries with hash value HASH crosses
1525 * border between pages P0 and P1. First both P0 and P1 are
1526 * cached, seekdir() is called for some entry from the P0 part
1527 * of the chain. Later P0 goes out of cache. telldir(HASH)
1528 * happens and finds P1, as it starts with matching hash
1529 * value. Remaining entries from P0 part of the chain are
1530 * skipped. (Is that really a bug?)
1532 * Possible solutions: 0. don't cache P1 is such case, handle
1533 * it as an "overflow" page. 1. invalidate all pages at
1534 * once. 2. use HASH|1 as an index for P1.
1536 GOTO(hash_collision, page);
1539 rp_param.rp_exp = exp;
1540 rp_param.rp_mod = op_data;
1541 page = read_cache_page(mapping,
1542 hash_x_index(rp_param.rp_off,
1543 rp_param.rp_hash64),
1544 mdc_read_page_remote, &rp_param);
1546 CDEBUG(D_INFO, "%s: read cache page: "DFID" at "LPU64": %ld\n",
1547 exp->exp_obd->obd_name, PFID(&op_data->op_fid1),
1548 rp_param.rp_off, PTR_ERR(page));
1549 GOTO(out_unlock, rc = PTR_ERR(page));
1552 wait_on_page_locked(page);
1554 if (!PageUptodate(page)) {
1555 CERROR("%s: page not updated: "DFID" at "LPU64": rc %d\n",
1556 exp->exp_obd->obd_name, PFID(&op_data->op_fid1),
1557 rp_param.rp_off, -5);
1560 if (!PageChecked(page))
1561 SetPageChecked(page);
1562 if (PageError(page)) {
1563 CERROR("%s: page error: "DFID" at "LPU64": rc %d\n",
1564 exp->exp_obd->obd_name, PFID(&op_data->op_fid1),
1565 rp_param.rp_off, -5);
1570 dp = page_address(page);
1571 if (BITS_PER_LONG == 32 && rp_param.rp_hash64) {
1572 start = le64_to_cpu(dp->ldp_hash_start) >> 32;
1573 end = le64_to_cpu(dp->ldp_hash_end) >> 32;
1574 rp_param.rp_off = hash_offset >> 32;
1576 start = le64_to_cpu(dp->ldp_hash_start);
1577 end = le64_to_cpu(dp->ldp_hash_end);
1578 rp_param.rp_off = hash_offset;
1581 LASSERT(start == rp_param.rp_off);
1582 CWARN("Page-wide hash collision: %#lx\n", (unsigned long)end);
1583 #if BITS_PER_LONG == 32
1584 CWARN("Real page-wide hash collision at ["LPU64" "LPU64"] with "
1585 "hash "LPU64"\n", le64_to_cpu(dp->ldp_hash_start),
1586 le64_to_cpu(dp->ldp_hash_end), hash_offset);
1590 * Fetch whole overflow chain...
1598 lockh.cookie = it.d.lustre.it_lock_handle;
1599 ldlm_lock_decref(&lockh, it.d.lustre.it_lock_mode);
1600 it.d.lustre.it_lock_handle = 0;
1604 mdc_release_page(page, 1);
1610 static int mdc_statfs(const struct lu_env *env,
1611 struct obd_export *exp, struct obd_statfs *osfs,
1612 __u64 max_age, __u32 flags)
1614 struct obd_device *obd = class_exp2obd(exp);
1615 struct ptlrpc_request *req;
1616 struct obd_statfs *msfs;
1617 struct obd_import *imp = NULL;
1622 * Since the request might also come from lprocfs, so we need
1623 * sync this with client_disconnect_export Bug15684
1625 down_read(&obd->u.cli.cl_sem);
1626 if (obd->u.cli.cl_import)
1627 imp = class_import_get(obd->u.cli.cl_import);
1628 up_read(&obd->u.cli.cl_sem);
1632 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_STATFS,
1633 LUSTRE_MDS_VERSION, MDS_STATFS);
1635 GOTO(output, rc = -ENOMEM);
1637 ptlrpc_request_set_replen(req);
1639 if (flags & OBD_STATFS_NODELAY) {
1640 /* procfs requests not want stay in wait for avoid deadlock */
1641 req->rq_no_resend = 1;
1642 req->rq_no_delay = 1;
1645 rc = ptlrpc_queue_wait(req);
1647 /* check connection error first */
1648 if (imp->imp_connect_error)
1649 rc = imp->imp_connect_error;
1653 msfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
1655 GOTO(out, rc = -EPROTO);
1660 ptlrpc_req_finished(req);
1662 class_import_put(imp);
1666 static int mdc_ioc_fid2path(struct obd_export *exp, struct getinfo_fid2path *gf)
1668 __u32 keylen, vallen;
1672 if (gf->gf_pathlen > PATH_MAX)
1673 RETURN(-ENAMETOOLONG);
1674 if (gf->gf_pathlen < 2)
1677 /* Key is KEY_FID2PATH + getinfo_fid2path description */
1678 keylen = cfs_size_round(sizeof(KEY_FID2PATH)) + sizeof(*gf);
1679 OBD_ALLOC(key, keylen);
1682 memcpy(key, KEY_FID2PATH, sizeof(KEY_FID2PATH));
1683 memcpy(key + cfs_size_round(sizeof(KEY_FID2PATH)), gf, sizeof(*gf));
1685 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n",
1686 PFID(&gf->gf_fid), gf->gf_recno, gf->gf_linkno);
1688 if (!fid_is_sane(&gf->gf_fid))
1689 GOTO(out, rc = -EINVAL);
1691 /* Val is struct getinfo_fid2path result plus path */
1692 vallen = sizeof(*gf) + gf->gf_pathlen;
1694 rc = obd_get_info(NULL, exp, keylen, key, &vallen, gf, NULL);
1695 if (rc != 0 && rc != -EREMOTE)
1698 if (vallen <= sizeof(*gf))
1699 GOTO(out, rc = -EPROTO);
1700 else if (vallen > sizeof(*gf) + gf->gf_pathlen)
1701 GOTO(out, rc = -EOVERFLOW);
1703 CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n%s\n",
1704 PFID(&gf->gf_fid), gf->gf_recno, gf->gf_linkno, gf->gf_path);
1707 OBD_FREE(key, keylen);
1711 static int mdc_ioc_hsm_progress(struct obd_export *exp,
1712 struct hsm_progress_kernel *hpk)
1714 struct obd_import *imp = class_exp2cliimp(exp);
1715 struct hsm_progress_kernel *req_hpk;
1716 struct ptlrpc_request *req;
1720 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_HSM_PROGRESS,
1721 LUSTRE_MDS_VERSION, MDS_HSM_PROGRESS);
1723 GOTO(out, rc = -ENOMEM);
1725 mdc_pack_body(req, NULL, NULL, OBD_MD_FLRMTPERM, 0, -1, 0);
1727 /* Copy hsm_progress struct */
1728 req_hpk = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_PROGRESS);
1729 if (req_hpk == NULL)
1730 GOTO(out, rc = -EPROTO);
1733 req_hpk->hpk_errval = lustre_errno_hton(hpk->hpk_errval);
1735 ptlrpc_request_set_replen(req);
1737 rc = mdc_queue_wait(req);
1740 ptlrpc_req_finished(req);
1744 static int mdc_ioc_hsm_ct_register(struct obd_import *imp, __u32 archives)
1746 __u32 *archive_mask;
1747 struct ptlrpc_request *req;
1751 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_HSM_CT_REGISTER,
1753 MDS_HSM_CT_REGISTER);
1755 GOTO(out, rc = -ENOMEM);
1757 mdc_pack_body(req, NULL, NULL, OBD_MD_FLRMTPERM, 0, -1, 0);
1759 /* Copy hsm_progress struct */
1760 archive_mask = req_capsule_client_get(&req->rq_pill,
1761 &RMF_MDS_HSM_ARCHIVE);
1762 if (archive_mask == NULL)
1763 GOTO(out, rc = -EPROTO);
1765 *archive_mask = archives;
1767 ptlrpc_request_set_replen(req);
1769 rc = mdc_queue_wait(req);
1772 ptlrpc_req_finished(req);
1776 static int mdc_ioc_hsm_current_action(struct obd_export *exp,
1777 struct md_op_data *op_data)
1779 struct hsm_current_action *hca = op_data->op_data;
1780 struct hsm_current_action *req_hca;
1781 struct ptlrpc_request *req;
1785 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
1786 &RQF_MDS_HSM_ACTION);
1790 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
1792 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_ACTION);
1794 ptlrpc_request_free(req);
1798 mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
1799 OBD_MD_FLRMTPERM, 0, op_data->op_suppgids[0], 0);
1801 ptlrpc_request_set_replen(req);
1803 rc = mdc_queue_wait(req);
1807 req_hca = req_capsule_server_get(&req->rq_pill,
1808 &RMF_MDS_HSM_CURRENT_ACTION);
1809 if (req_hca == NULL)
1810 GOTO(out, rc = -EPROTO);
1816 ptlrpc_req_finished(req);
1820 static int mdc_ioc_hsm_ct_unregister(struct obd_import *imp)
1822 struct ptlrpc_request *req;
1826 req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_HSM_CT_UNREGISTER,
1828 MDS_HSM_CT_UNREGISTER);
1830 GOTO(out, rc = -ENOMEM);
1832 mdc_pack_body(req, NULL, NULL, OBD_MD_FLRMTPERM, 0, -1, 0);
1834 ptlrpc_request_set_replen(req);
1836 rc = mdc_queue_wait(req);
1839 ptlrpc_req_finished(req);
1843 static int mdc_ioc_hsm_state_get(struct obd_export *exp,
1844 struct md_op_data *op_data)
1846 struct hsm_user_state *hus = op_data->op_data;
1847 struct hsm_user_state *req_hus;
1848 struct ptlrpc_request *req;
1852 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
1853 &RQF_MDS_HSM_STATE_GET);
1857 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
1859 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_STATE_GET);
1861 ptlrpc_request_free(req);
1865 mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
1866 OBD_MD_FLRMTPERM, 0, op_data->op_suppgids[0], 0);
1868 ptlrpc_request_set_replen(req);
1870 rc = mdc_queue_wait(req);
1874 req_hus = req_capsule_server_get(&req->rq_pill, &RMF_HSM_USER_STATE);
1875 if (req_hus == NULL)
1876 GOTO(out, rc = -EPROTO);
1882 ptlrpc_req_finished(req);
1886 static int mdc_ioc_hsm_state_set(struct obd_export *exp,
1887 struct md_op_data *op_data)
1889 struct hsm_state_set *hss = op_data->op_data;
1890 struct hsm_state_set *req_hss;
1891 struct ptlrpc_request *req;
1895 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
1896 &RQF_MDS_HSM_STATE_SET);
1900 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
1902 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_STATE_SET);
1904 ptlrpc_request_free(req);
1908 mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
1909 OBD_MD_FLRMTPERM, 0, op_data->op_suppgids[0], 0);
1912 req_hss = req_capsule_client_get(&req->rq_pill, &RMF_HSM_STATE_SET);
1913 if (req_hss == NULL)
1914 GOTO(out, rc = -EPROTO);
1917 ptlrpc_request_set_replen(req);
1919 rc = mdc_queue_wait(req);
1924 ptlrpc_req_finished(req);
1928 static int mdc_ioc_hsm_request(struct obd_export *exp,
1929 struct hsm_user_request *hur)
1931 struct obd_import *imp = class_exp2cliimp(exp);
1932 struct ptlrpc_request *req;
1933 struct hsm_request *req_hr;
1934 struct hsm_user_item *req_hui;
1939 req = ptlrpc_request_alloc(imp, &RQF_MDS_HSM_REQUEST);
1941 GOTO(out, rc = -ENOMEM);
1943 req_capsule_set_size(&req->rq_pill, &RMF_MDS_HSM_USER_ITEM, RCL_CLIENT,
1944 hur->hur_request.hr_itemcount
1945 * sizeof(struct hsm_user_item));
1946 req_capsule_set_size(&req->rq_pill, &RMF_GENERIC_DATA, RCL_CLIENT,
1947 hur->hur_request.hr_data_len);
1949 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_REQUEST);
1951 ptlrpc_request_free(req);
1955 mdc_pack_body(req, NULL, NULL, OBD_MD_FLRMTPERM, 0, -1, 0);
1957 /* Copy hsm_request struct */
1958 req_hr = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_REQUEST);
1960 GOTO(out, rc = -EPROTO);
1961 *req_hr = hur->hur_request;
1963 /* Copy hsm_user_item structs */
1964 req_hui = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_USER_ITEM);
1965 if (req_hui == NULL)
1966 GOTO(out, rc = -EPROTO);
1967 memcpy(req_hui, hur->hur_user_item,
1968 hur->hur_request.hr_itemcount * sizeof(struct hsm_user_item));
1970 /* Copy opaque field */
1971 req_opaque = req_capsule_client_get(&req->rq_pill, &RMF_GENERIC_DATA);
1972 if (req_opaque == NULL)
1973 GOTO(out, rc = -EPROTO);
1974 memcpy(req_opaque, hur_data(hur), hur->hur_request.hr_data_len);
1976 ptlrpc_request_set_replen(req);
1978 rc = mdc_queue_wait(req);
1982 ptlrpc_req_finished(req);
1986 static struct kuc_hdr *changelog_kuc_hdr(char *buf, size_t len, __u32 flags)
1988 struct kuc_hdr *lh = (struct kuc_hdr *)buf;
1990 LASSERT(len <= KUC_CHANGELOG_MSG_MAXSIZE);
1992 lh->kuc_magic = KUC_MAGIC;
1993 lh->kuc_transport = KUC_TRANSPORT_CHANGELOG;
1994 lh->kuc_flags = flags;
1995 lh->kuc_msgtype = CL_RECORD;
1996 lh->kuc_msglen = len;
2000 struct changelog_show {
2002 enum changelog_send_flag cs_flags;
2005 struct obd_device *cs_obd;
2008 static inline char *cs_obd_name(struct changelog_show *cs)
2010 return cs->cs_obd->obd_name;
2013 static int changelog_kkuc_cb(const struct lu_env *env, struct llog_handle *llh,
2014 struct llog_rec_hdr *hdr, void *data)
2016 struct changelog_show *cs = data;
2017 struct llog_changelog_rec *rec = (struct llog_changelog_rec *)hdr;
2023 if (rec->cr_hdr.lrh_type != CHANGELOG_REC) {
2025 CERROR("%s: not a changelog rec %x/%d: rc = %d\n",
2026 cs_obd_name(cs), rec->cr_hdr.lrh_type,
2027 rec->cr.cr_type, rc);
2031 if (rec->cr.cr_index < cs->cs_startrec) {
2032 /* Skip entries earlier than what we are interested in */
2033 CDEBUG(D_HSM, "rec="LPU64" start="LPU64"\n",
2034 rec->cr.cr_index, cs->cs_startrec);
2038 CDEBUG(D_HSM, LPU64" %02d%-5s "LPU64" 0x%x t="DFID" p="DFID" %.*s\n",
2039 rec->cr.cr_index, rec->cr.cr_type,
2040 changelog_type2str(rec->cr.cr_type), rec->cr.cr_time,
2041 rec->cr.cr_flags & CLF_FLAGMASK,
2042 PFID(&rec->cr.cr_tfid), PFID(&rec->cr.cr_pfid),
2043 rec->cr.cr_namelen, changelog_rec_name(&rec->cr));
2045 len = sizeof(*lh) + changelog_rec_size(&rec->cr) + rec->cr.cr_namelen;
2047 /* Set up the message */
2048 lh = changelog_kuc_hdr(cs->cs_buf, len, cs->cs_flags);
2049 memcpy(lh + 1, &rec->cr, len - sizeof(*lh));
2051 rc = libcfs_kkuc_msg_put(cs->cs_fp, lh);
2052 CDEBUG(D_HSM, "kucmsg fp %p len %zu rc %d\n", cs->cs_fp, len, rc);
2057 static int mdc_changelog_send_thread(void *csdata)
2059 struct changelog_show *cs = csdata;
2060 struct llog_ctxt *ctxt = NULL;
2061 struct llog_handle *llh = NULL;
2062 struct kuc_hdr *kuch;
2063 enum llog_flag flags = LLOG_F_IS_CAT;
2066 CDEBUG(D_HSM, "changelog to fp=%p start "LPU64"\n",
2067 cs->cs_fp, cs->cs_startrec);
2069 OBD_ALLOC(cs->cs_buf, KUC_CHANGELOG_MSG_MAXSIZE);
2070 if (cs->cs_buf == NULL)
2071 GOTO(out, rc = -ENOMEM);
2073 /* Set up the remote catalog handle */
2074 ctxt = llog_get_context(cs->cs_obd, LLOG_CHANGELOG_REPL_CTXT);
2076 GOTO(out, rc = -ENOENT);
2077 rc = llog_open(NULL, ctxt, &llh, NULL, CHANGELOG_CATALOG,
2080 CERROR("%s: fail to open changelog catalog: rc = %d\n",
2081 cs_obd_name(cs), rc);
2085 if (cs->cs_flags & CHANGELOG_FLAG_JOBID)
2086 flags |= LLOG_F_EXT_JOBID;
2088 rc = llog_init_handle(NULL, llh, flags, NULL);
2090 CERROR("llog_init_handle failed %d\n", rc);
2094 rc = llog_cat_process(NULL, llh, changelog_kkuc_cb, cs, 0, 0);
2096 /* Send EOF no matter what our result */
2097 if ((kuch = changelog_kuc_hdr(cs->cs_buf, sizeof(*kuch),
2099 kuch->kuc_msgtype = CL_EOF;
2100 libcfs_kkuc_msg_put(cs->cs_fp, kuch);
2106 llog_cat_close(NULL, llh);
2108 llog_ctxt_put(ctxt);
2110 OBD_FREE(cs->cs_buf, KUC_CHANGELOG_MSG_MAXSIZE);
2115 static int mdc_ioc_changelog_send(struct obd_device *obd,
2116 struct ioc_changelog *icc)
2118 struct changelog_show *cs;
2119 struct task_struct *task;
2122 /* Freed in mdc_changelog_send_thread */
2128 cs->cs_startrec = icc->icc_recno;
2129 /* matching fput in mdc_changelog_send_thread */
2130 cs->cs_fp = fget(icc->icc_id);
2131 cs->cs_flags = icc->icc_flags;
2134 * New thread because we should return to user app before
2135 * writing into our pipe
2137 task = kthread_run(mdc_changelog_send_thread, cs,
2138 "mdc_clg_send_thread");
2141 CERROR("%s: cannot start changelog thread: rc = %d\n",
2142 cs_obd_name(cs), rc);
2146 CDEBUG(D_HSM, "%s: started changelog thread\n",
2153 static int mdc_ioc_hsm_ct_start(struct obd_export *exp,
2154 struct lustre_kernelcomm *lk);
2156 static int mdc_quotacheck(struct obd_device *unused, struct obd_export *exp,
2157 struct obd_quotactl *oqctl)
2159 struct client_obd *cli = &exp->exp_obd->u.cli;
2160 struct ptlrpc_request *req;
2161 struct obd_quotactl *body;
2165 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
2166 &RQF_MDS_QUOTACHECK, LUSTRE_MDS_VERSION,
2171 body = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
2174 ptlrpc_request_set_replen(req);
2176 /* the next poll will find -ENODATA, that means quotacheck is
2178 cli->cl_qchk_stat = -ENODATA;
2179 rc = ptlrpc_queue_wait(req);
2181 cli->cl_qchk_stat = rc;
2182 ptlrpc_req_finished(req);
2186 static int mdc_quota_poll_check(struct obd_export *exp,
2187 struct if_quotacheck *qchk)
2189 struct client_obd *cli = &exp->exp_obd->u.cli;
2193 qchk->obd_uuid = cli->cl_target_uuid;
2194 memcpy(qchk->obd_type, LUSTRE_MDS_NAME, strlen(LUSTRE_MDS_NAME));
2196 rc = cli->cl_qchk_stat;
2197 /* the client is not the previous one */
2198 if (rc == CL_NOT_QUOTACHECKED)
2203 static int mdc_quotactl(struct obd_device *unused, struct obd_export *exp,
2204 struct obd_quotactl *oqctl)
2206 struct ptlrpc_request *req;
2207 struct obd_quotactl *oqc;
2211 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
2212 &RQF_MDS_QUOTACTL, LUSTRE_MDS_VERSION,
2217 oqc = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL);
2220 ptlrpc_request_set_replen(req);
2221 ptlrpc_at_set_req_timeout(req);
2222 req->rq_no_resend = 1;
2224 rc = ptlrpc_queue_wait(req);
2226 CERROR("ptlrpc_queue_wait failed, rc: %d\n", rc);
2228 if (req->rq_repmsg &&
2229 (oqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL))) {
2232 CERROR ("Can't unpack obd_quotactl\n");
2235 ptlrpc_req_finished(req);
2240 static int mdc_ioc_swap_layouts(struct obd_export *exp,
2241 struct md_op_data *op_data)
2243 struct list_head cancels = LIST_HEAD_INIT(cancels);
2244 struct ptlrpc_request *req;
2246 struct mdc_swap_layouts *msl, *payload;
2249 msl = op_data->op_data;
2251 /* When the MDT will get the MDS_SWAP_LAYOUTS RPC the
2252 * first thing it will do is to cancel the 2 layout
2253 * locks hold by this client.
2254 * So the client must cancel its layout locks on the 2 fids
2255 * with the request RPC to avoid extra RPC round trips
2257 count = mdc_resource_get_unused(exp, &op_data->op_fid1, &cancels,
2258 LCK_EX, MDS_INODELOCK_LAYOUT |
2259 MDS_INODELOCK_XATTR);
2260 count += mdc_resource_get_unused(exp, &op_data->op_fid2, &cancels,
2261 LCK_EX, MDS_INODELOCK_LAYOUT |
2262 MDS_INODELOCK_XATTR);
2264 req = ptlrpc_request_alloc(class_exp2cliimp(exp),
2265 &RQF_MDS_SWAP_LAYOUTS);
2267 ldlm_lock_list_put(&cancels, l_bl_ast, count);
2271 mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
2272 mdc_set_capa_size(req, &RMF_CAPA2, op_data->op_capa2);
2274 rc = mdc_prep_elc_req(exp, req, MDS_SWAP_LAYOUTS, &cancels, count);
2276 ptlrpc_request_free(req);
2280 mdc_swap_layouts_pack(req, op_data);
2282 payload = req_capsule_client_get(&req->rq_pill, &RMF_SWAP_LAYOUTS);
2287 ptlrpc_request_set_replen(req);
2289 rc = ptlrpc_queue_wait(req);
2295 ptlrpc_req_finished(req);
2299 static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
2300 void *karg, void __user *uarg)
2302 struct obd_device *obd = exp->exp_obd;
2303 struct obd_ioctl_data *data = karg;
2304 struct obd_import *imp = obd->u.cli.cl_import;
2308 if (!try_module_get(THIS_MODULE)) {
2309 CERROR("%s: cannot get module '%s'\n", obd->obd_name,
2310 module_name(THIS_MODULE));
2314 case OBD_IOC_CHANGELOG_SEND:
2315 rc = mdc_ioc_changelog_send(obd, karg);
2317 case OBD_IOC_CHANGELOG_CLEAR: {
2318 struct ioc_changelog *icc = karg;
2319 struct changelog_setinfo cs =
2320 {.cs_recno = icc->icc_recno, .cs_id = icc->icc_id};
2321 rc = obd_set_info_async(NULL, exp, strlen(KEY_CHANGELOG_CLEAR),
2322 KEY_CHANGELOG_CLEAR, sizeof(cs), &cs,
2326 case OBD_IOC_FID2PATH:
2327 rc = mdc_ioc_fid2path(exp, karg);
2329 case LL_IOC_HSM_CT_START:
2330 rc = mdc_ioc_hsm_ct_start(exp, karg);
2331 /* ignore if it was already registered on this MDS. */
2335 case LL_IOC_HSM_PROGRESS:
2336 rc = mdc_ioc_hsm_progress(exp, karg);
2338 case LL_IOC_HSM_STATE_GET:
2339 rc = mdc_ioc_hsm_state_get(exp, karg);
2341 case LL_IOC_HSM_STATE_SET:
2342 rc = mdc_ioc_hsm_state_set(exp, karg);
2344 case LL_IOC_HSM_ACTION:
2345 rc = mdc_ioc_hsm_current_action(exp, karg);
2347 case LL_IOC_HSM_REQUEST:
2348 rc = mdc_ioc_hsm_request(exp, karg);
2350 case OBD_IOC_CLIENT_RECOVER:
2351 rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1, 0);
2355 case IOC_OSC_SET_ACTIVE:
2356 rc = ptlrpc_set_import_active(imp, data->ioc_offset);
2358 case OBD_IOC_POLL_QUOTACHECK:
2359 rc = mdc_quota_poll_check(exp, (struct if_quotacheck *)karg);
2361 case OBD_IOC_PING_TARGET:
2362 rc = ptlrpc_obd_ping(obd);
2365 * Normally IOC_OBD_STATFS, OBD_IOC_QUOTACTL iocontrol are handled by
2366 * LMV instead of MDC. But when the cluster is upgraded from 1.8,
2367 * there'd be no LMV layer thus we might be called here. Eventually
2368 * this code should be removed.
2371 case IOC_OBD_STATFS: {
2372 struct obd_statfs stat_buf = {0};
2374 if (*((__u32 *) data->ioc_inlbuf2) != 0)
2375 GOTO(out, rc = -ENODEV);
2378 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(obd),
2379 min((int)data->ioc_plen2,
2380 (int)sizeof(struct obd_uuid))))
2381 GOTO(out, rc = -EFAULT);
2383 rc = mdc_statfs(NULL, obd->obd_self_export, &stat_buf,
2384 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
2389 if (copy_to_user(data->ioc_pbuf1, &stat_buf,
2390 min((int) data->ioc_plen1,
2391 (int) sizeof(stat_buf))))
2392 GOTO(out, rc = -EFAULT);
2396 case OBD_IOC_QUOTACTL: {
2397 struct if_quotactl *qctl = karg;
2398 struct obd_quotactl *oqctl;
2400 OBD_ALLOC_PTR(oqctl);
2402 GOTO(out, rc = -ENOMEM);
2404 QCTL_COPY(oqctl, qctl);
2405 rc = obd_quotactl(exp, oqctl);
2407 QCTL_COPY(qctl, oqctl);
2408 qctl->qc_valid = QC_MDTIDX;
2409 qctl->obd_uuid = obd->u.cli.cl_target_uuid;
2412 OBD_FREE_PTR(oqctl);
2415 case LL_IOC_GET_CONNECT_FLAGS:
2416 if (copy_to_user(uarg, exp_connect_flags_ptr(exp),
2417 sizeof(*exp_connect_flags_ptr(exp))))
2418 GOTO(out, rc = -EFAULT);
2421 case LL_IOC_LOV_SWAP_LAYOUTS:
2422 rc = mdc_ioc_swap_layouts(exp, karg);
2425 CERROR("unrecognised ioctl: cmd = %#x\n", cmd);
2426 GOTO(out, rc = -ENOTTY);
2429 module_put(THIS_MODULE);
2434 static int mdc_get_info_rpc(struct obd_export *exp,
2435 obd_count keylen, void *key,
2436 int vallen, void *val)
2438 struct obd_import *imp = class_exp2cliimp(exp);
2439 struct ptlrpc_request *req;
2444 req = ptlrpc_request_alloc(imp, &RQF_MDS_GET_INFO);
2448 req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_KEY,
2449 RCL_CLIENT, keylen);
2450 req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_VALLEN,
2451 RCL_CLIENT, sizeof(__u32));
2453 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GET_INFO);
2455 ptlrpc_request_free(req);
2459 tmp = req_capsule_client_get(&req->rq_pill, &RMF_GETINFO_KEY);
2460 memcpy(tmp, key, keylen);
2461 tmp = req_capsule_client_get(&req->rq_pill, &RMF_GETINFO_VALLEN);
2462 memcpy(tmp, &vallen, sizeof(__u32));
2464 req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_VAL,
2465 RCL_SERVER, vallen);
2466 ptlrpc_request_set_replen(req);
2468 rc = ptlrpc_queue_wait(req);
2469 /* -EREMOTE means the get_info result is partial, and it needs to
2470 * continue on another MDT, see fid2path part in lmv_iocontrol */
2471 if (rc == 0 || rc == -EREMOTE) {
2472 tmp = req_capsule_server_get(&req->rq_pill, &RMF_GETINFO_VAL);
2473 memcpy(val, tmp, vallen);
2474 if (ptlrpc_rep_need_swab(req)) {
2475 if (KEY_IS(KEY_FID2PATH))
2476 lustre_swab_fid2path(val);
2479 ptlrpc_req_finished(req);
2484 static void lustre_swab_hai(struct hsm_action_item *h)
2486 __swab32s(&h->hai_len);
2487 __swab32s(&h->hai_action);
2488 lustre_swab_lu_fid(&h->hai_fid);
2489 lustre_swab_lu_fid(&h->hai_dfid);
2490 __swab64s(&h->hai_cookie);
2491 __swab64s(&h->hai_extent.offset);
2492 __swab64s(&h->hai_extent.length);
2493 __swab64s(&h->hai_gid);
2496 static void lustre_swab_hal(struct hsm_action_list *h)
2498 struct hsm_action_item *hai;
2501 __swab32s(&h->hal_version);
2502 __swab32s(&h->hal_count);
2503 __swab32s(&h->hal_archive_id);
2504 __swab64s(&h->hal_flags);
2506 for (i = 0; i < h->hal_count; i++, hai = hai_next(hai))
2507 lustre_swab_hai(hai);
2510 static void lustre_swab_kuch(struct kuc_hdr *l)
2512 __swab16s(&l->kuc_magic);
2513 /* __u8 l->kuc_transport */
2514 __swab16s(&l->kuc_msgtype);
2515 __swab16s(&l->kuc_msglen);
2518 static int mdc_ioc_hsm_ct_start(struct obd_export *exp,
2519 struct lustre_kernelcomm *lk)
2521 struct obd_import *imp = class_exp2cliimp(exp);
2522 __u32 archive = lk->lk_data;
2525 if (lk->lk_group != KUC_GRP_HSM) {
2526 CERROR("Bad copytool group %d\n", lk->lk_group);
2530 CDEBUG(D_HSM, "CT start r%d w%d u%d g%d f%#x\n", lk->lk_rfd, lk->lk_wfd,
2531 lk->lk_uid, lk->lk_group, lk->lk_flags);
2533 if (lk->lk_flags & LK_FLG_STOP) {
2534 /* Unregister with the coordinator */
2535 rc = mdc_ioc_hsm_ct_unregister(imp);
2537 rc = mdc_ioc_hsm_ct_register(imp, archive);
2544 * Send a message to any listening copytools
2545 * @param val KUC message (kuc_hdr + hsm_action_list)
2546 * @param len total length of message
2548 static int mdc_hsm_copytool_send(size_t len, void *val)
2550 struct kuc_hdr *lh = (struct kuc_hdr *)val;
2551 struct hsm_action_list *hal = (struct hsm_action_list *)(lh + 1);
2555 if (len < sizeof(*lh) + sizeof(*hal)) {
2556 CERROR("Short HSM message %zu < %zu\n", len,
2557 sizeof(*lh) + sizeof(*hal));
2560 if (lh->kuc_magic == __swab16(KUC_MAGIC)) {
2561 lustre_swab_kuch(lh);
2562 lustre_swab_hal(hal);
2563 } else if (lh->kuc_magic != KUC_MAGIC) {
2564 CERROR("Bad magic %x!=%x\n", lh->kuc_magic, KUC_MAGIC);
2568 CDEBUG(D_HSM, " Received message mg=%x t=%d m=%d l=%d actions=%d "
2570 lh->kuc_magic, lh->kuc_transport, lh->kuc_msgtype,
2571 lh->kuc_msglen, hal->hal_count, hal->hal_fsname);
2573 /* Broadcast to HSM listeners */
2574 rc = libcfs_kkuc_group_put(KUC_GRP_HSM, lh);
2580 * callback function passed to kuc for re-registering each HSM copytool
2581 * running on MDC, after MDT shutdown/recovery.
2582 * @param data copytool registration data
2583 * @param cb_arg callback argument (obd_import)
2585 static int mdc_hsm_ct_reregister(void *data, void *cb_arg)
2587 struct kkuc_ct_data *kcd = data;
2588 struct obd_import *imp = (struct obd_import *)cb_arg;
2591 if (kcd == NULL || kcd->kcd_magic != KKUC_CT_DATA_MAGIC)
2594 if (!obd_uuid_equals(&kcd->kcd_uuid, &imp->imp_obd->obd_uuid))
2597 CDEBUG(D_HA, "%s: recover copytool registration to MDT (archive=%#x)\n",
2598 imp->imp_obd->obd_name, kcd->kcd_archive);
2599 rc = mdc_ioc_hsm_ct_register(imp, kcd->kcd_archive);
2601 /* ignore error if the copytool is already registered */
2602 return (rc == -EEXIST) ? 0 : rc;
2606 * Re-establish all kuc contexts with MDT
2607 * after MDT shutdown/recovery.
2609 static int mdc_kuc_reregister(struct obd_import *imp)
2611 /* re-register HSM agents */
2612 return libcfs_kkuc_group_foreach(KUC_GRP_HSM, mdc_hsm_ct_reregister,
2616 static int mdc_set_info_async(const struct lu_env *env,
2617 struct obd_export *exp,
2618 obd_count keylen, void *key,
2619 obd_count vallen, void *val,
2620 struct ptlrpc_request_set *set)
2622 struct obd_import *imp = class_exp2cliimp(exp);
2626 if (KEY_IS(KEY_READ_ONLY)) {
2627 if (vallen != sizeof(int))
2630 spin_lock(&imp->imp_lock);
2631 if (*((int *)val)) {
2632 imp->imp_connect_flags_orig |= OBD_CONNECT_RDONLY;
2633 imp->imp_connect_data.ocd_connect_flags |=
2636 imp->imp_connect_flags_orig &= ~OBD_CONNECT_RDONLY;
2637 imp->imp_connect_data.ocd_connect_flags &=
2638 ~OBD_CONNECT_RDONLY;
2640 spin_unlock(&imp->imp_lock);
2642 rc = do_set_info_async(imp, MDS_SET_INFO, LUSTRE_MDS_VERSION,
2643 keylen, key, vallen, val, set);
2646 if (KEY_IS(KEY_SPTLRPC_CONF)) {
2647 sptlrpc_conf_client_adapt(exp->exp_obd);
2650 if (KEY_IS(KEY_FLUSH_CTX)) {
2651 sptlrpc_import_flush_my_ctx(imp);
2654 if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
2655 rc = do_set_info_async(imp, MDS_SET_INFO, LUSTRE_MDS_VERSION,
2656 keylen, key, vallen, val, set);
2659 if (KEY_IS(KEY_HSM_COPYTOOL_SEND)) {
2660 rc = mdc_hsm_copytool_send(vallen, val);
2664 CERROR("Unknown key %s\n", (char *)key);
2668 static int mdc_get_info(const struct lu_env *env, struct obd_export *exp,
2669 __u32 keylen, void *key, __u32 *vallen, void *val,
2670 struct lov_stripe_md *lsm)
2674 if (KEY_IS(KEY_MAX_EASIZE)) {
2675 __u32 mdsize, *max_easize;
2677 if (*vallen != sizeof(int))
2679 mdsize = *(__u32 *)val;
2680 if (mdsize > exp->exp_obd->u.cli.cl_max_mds_easize)
2681 exp->exp_obd->u.cli.cl_max_mds_easize = mdsize;
2683 *max_easize = exp->exp_obd->u.cli.cl_max_mds_easize;
2685 } else if (KEY_IS(KEY_DEFAULT_EASIZE)) {
2686 __u32 *default_easize;
2688 if (*vallen != sizeof(int))
2690 default_easize = val;
2691 *default_easize = exp->exp_obd->u.cli.cl_default_mds_easize;
2693 } else if (KEY_IS(KEY_MAX_COOKIESIZE)) {
2694 __u32 mdsize, *max_cookiesize;
2696 if (*vallen != sizeof(int))
2698 mdsize = *(int *)val;
2699 if (mdsize > exp->exp_obd->u.cli.cl_max_mds_cookiesize)
2700 exp->exp_obd->u.cli.cl_max_mds_cookiesize = mdsize;
2701 max_cookiesize = val;
2702 *max_cookiesize = exp->exp_obd->u.cli.cl_max_mds_cookiesize;
2704 } else if (KEY_IS(KEY_DEFAULT_COOKIESIZE)) {
2705 __u32 *default_cookiesize;
2707 if (*vallen != sizeof(int))
2709 default_cookiesize = val;
2710 *default_cookiesize =
2711 exp->exp_obd->u.cli.cl_default_mds_cookiesize;
2713 } else if (KEY_IS(KEY_CONN_DATA)) {
2714 struct obd_import *imp = class_exp2cliimp(exp);
2715 struct obd_connect_data *data = val;
2717 if (*vallen != sizeof(*data))
2720 *data = imp->imp_connect_data;
2722 } else if (KEY_IS(KEY_TGT_COUNT)) {
2723 *((__u32 *)val) = 1;
2727 rc = mdc_get_info_rpc(exp, keylen, key, *vallen, val);
2732 static int mdc_fsync(struct obd_export *exp, const struct lu_fid *fid,
2733 struct obd_capa *oc, struct ptlrpc_request **request)
2735 struct ptlrpc_request *req;
2740 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_SYNC);
2744 mdc_set_capa_size(req, &RMF_CAPA1, oc);
2746 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_SYNC);
2748 ptlrpc_request_free(req);
2752 mdc_pack_body(req, fid, oc, 0, 0, -1, 0);
2754 ptlrpc_request_set_replen(req);
2756 rc = ptlrpc_queue_wait(req);
2758 ptlrpc_req_finished(req);
2764 static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
2765 enum obd_import_event event)
2769 LASSERT(imp->imp_obd == obd);
2772 case IMP_EVENT_DISCON: {
2774 /* XXX Pass event up to OBDs stack. used only for FLD now */
2775 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_DISCON, NULL);
2779 case IMP_EVENT_INACTIVE: {
2780 struct client_obd *cli = &obd->u.cli;
2782 * Flush current sequence to make client obtain new one
2783 * from server in case of disconnect/reconnect.
2785 if (cli->cl_seq != NULL)
2786 seq_client_flush(cli->cl_seq);
2788 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_INACTIVE, NULL);
2791 case IMP_EVENT_INVALIDATE: {
2792 struct ldlm_namespace *ns = obd->obd_namespace;
2794 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
2798 case IMP_EVENT_ACTIVE:
2799 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_ACTIVE, NULL);
2800 /* redo the kuc registration after reconnecting */
2802 rc = mdc_kuc_reregister(imp);
2805 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_OCD, NULL);
2807 case IMP_EVENT_DEACTIVATE:
2808 case IMP_EVENT_ACTIVATE:
2811 CERROR("Unknown import event %x\n", event);
2817 int mdc_fid_alloc(const struct lu_env *env, struct obd_export *exp,
2818 struct lu_fid *fid, struct md_op_data *op_data)
2820 struct client_obd *cli = &exp->exp_obd->u.cli;
2821 struct lu_client_seq *seq = cli->cl_seq;
2823 RETURN(seq_client_alloc_fid(env, seq, fid));
2826 static struct obd_uuid *mdc_get_uuid(struct obd_export *exp)
2828 struct client_obd *cli = &exp->exp_obd->u.cli;
2829 return &cli->cl_target_uuid;
2833 * Determine whether the lock can be canceled before replaying it during
2834 * recovery, non zero value will be return if the lock can be canceled,
2835 * or zero returned for not
2837 static int mdc_cancel_weight(struct ldlm_lock *lock)
2839 if (lock->l_resource->lr_type != LDLM_IBITS)
2842 /* FIXME: if we ever get into a situation where there are too many
2843 * opened files with open locks on a single node, then we really
2844 * should replay these open locks to reget it */
2845 if (lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_OPEN)
2851 static int mdc_resource_inode_free(struct ldlm_resource *res)
2853 if (res->lr_lvb_inode)
2854 res->lr_lvb_inode = NULL;
2859 static struct ldlm_valblock_ops inode_lvbo = {
2860 .lvbo_free = mdc_resource_inode_free
2863 static int mdc_llog_init(struct obd_device *obd)
2865 struct obd_llog_group *olg = &obd->obd_olg;
2866 struct llog_ctxt *ctxt;
2871 rc = llog_setup(NULL, obd, olg, LLOG_CHANGELOG_REPL_CTXT, obd,
2876 ctxt = llog_group_get_ctxt(olg, LLOG_CHANGELOG_REPL_CTXT);
2877 llog_initiator_connect(ctxt);
2878 llog_ctxt_put(ctxt);
2883 static void mdc_llog_finish(struct obd_device *obd)
2885 struct llog_ctxt *ctxt;
2889 ctxt = llog_get_context(obd, LLOG_CHANGELOG_REPL_CTXT);
2891 llog_cleanup(NULL, ctxt);
2896 static int mdc_setup(struct obd_device *obd, struct lustre_cfg *cfg)
2898 struct client_obd *cli = &obd->u.cli;
2902 OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
2903 if (!cli->cl_rpc_lock)
2905 mdc_init_rpc_lock(cli->cl_rpc_lock);
2907 rc = ptlrpcd_addref();
2909 GOTO(err_rpc_lock, rc);
2911 OBD_ALLOC(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
2912 if (!cli->cl_close_lock)
2913 GOTO(err_ptlrpcd_decref, rc = -ENOMEM);
2914 mdc_init_rpc_lock(cli->cl_close_lock);
2916 rc = client_obd_setup(obd, cfg);
2918 GOTO(err_close_lock, rc);
2920 obd->obd_vars = lprocfs_mdc_obd_vars;
2921 lprocfs_obd_setup(obd);
2922 lprocfs_alloc_md_stats(obd, 0);
2924 sptlrpc_lprocfs_cliobd_attach(obd);
2925 ptlrpc_lprocfs_register_obd(obd);
2927 ns_register_cancel(obd->obd_namespace, mdc_cancel_weight);
2929 obd->obd_namespace->ns_lvbo = &inode_lvbo;
2931 rc = mdc_llog_init(obd);
2934 CERROR("failed to setup llogging subsystems\n");
2940 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
2944 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
2948 /* Initialize the default and maximum LOV EA and cookie sizes. This allows
2949 * us to make MDS RPCs with large enough reply buffers to hold a default
2950 * sized EA and cookie without having to calculate this (via a call into the
2951 * LOV + OSCs) each time we make an RPC. The maximum size is also tracked
2952 * but not used to avoid wastefully vmalloc()'ing large reply buffers when
2953 * a large number of stripes is possible. If a larger reply buffer is
2954 * required it will be reallocated in the ptlrpc layer due to overflow.
2956 static int mdc_init_ea_size(struct obd_export *exp, __u32 easize,
2957 __u32 def_easize, __u32 cookiesize,
2958 __u32 def_cookiesize)
2960 struct obd_device *obd = exp->exp_obd;
2961 struct client_obd *cli = &obd->u.cli;
2964 if (cli->cl_max_mds_easize < easize)
2965 cli->cl_max_mds_easize = easize;
2967 if (cli->cl_default_mds_easize < def_easize)
2968 cli->cl_default_mds_easize = def_easize;
2970 if (cli->cl_max_mds_cookiesize < cookiesize)
2971 cli->cl_max_mds_cookiesize = cookiesize;
2973 if (cli->cl_default_mds_cookiesize < def_cookiesize)
2974 cli->cl_default_mds_cookiesize = def_cookiesize;
2979 static int mdc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2985 case OBD_CLEANUP_EARLY:
2987 case OBD_CLEANUP_EXPORTS:
2988 /* Failsafe, ok if racy */
2989 if (obd->obd_type->typ_refcnt <= 1)
2990 libcfs_kkuc_group_rem(0, KUC_GRP_HSM, NULL);
2992 obd_cleanup_client_import(obd);
2993 ptlrpc_lprocfs_unregister_obd(obd);
2994 lprocfs_obd_cleanup(obd);
2995 lprocfs_free_md_stats(obd);
2996 mdc_llog_finish(obd);
3002 static int mdc_cleanup(struct obd_device *obd)
3004 struct client_obd *cli = &obd->u.cli;
3006 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
3007 OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
3011 return client_obd_cleanup(obd);
3014 static int mdc_process_config(struct obd_device *obd, obd_count len, void *buf)
3016 struct lustre_cfg *lcfg = buf;
3017 int rc = class_process_proc_param(PARAM_MDC, obd->obd_vars, lcfg, obd);
3018 return (rc > 0 ? 0: rc);
3022 /* get remote permission for current user on fid */
3023 static int mdc_get_remote_perm(struct obd_export *exp, const struct lu_fid *fid,
3024 struct obd_capa *oc, __u32 suppgid,
3025 struct ptlrpc_request **request)
3027 struct ptlrpc_request *req;
3031 LASSERT(client_is_remote(exp));
3034 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR);
3038 mdc_set_capa_size(req, &RMF_CAPA1, oc);
3040 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR);
3042 ptlrpc_request_free(req);
3046 mdc_pack_body(req, fid, oc, OBD_MD_FLRMTPERM, 0, suppgid, 0);
3048 req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER,
3049 sizeof(struct mdt_remote_perm));
3051 ptlrpc_request_set_replen(req);
3053 rc = ptlrpc_queue_wait(req);
3055 ptlrpc_req_finished(req);
3061 static int mdc_interpret_renew_capa(const struct lu_env *env,
3062 struct ptlrpc_request *req, void *args,
3065 struct mdc_renew_capa_args *ra = args;
3066 struct mdt_body *body = NULL;
3067 struct lustre_capa *capa;
3071 GOTO(out, capa = ERR_PTR(status));
3073 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
3075 GOTO(out, capa = ERR_PTR(-EFAULT));
3077 if ((body->mbo_valid & OBD_MD_FLOSSCAPA) == 0)
3078 GOTO(out, capa = ERR_PTR(-ENOENT));
3080 capa = req_capsule_server_get(&req->rq_pill, &RMF_CAPA2);
3082 GOTO(out, capa = ERR_PTR(-EFAULT));
3085 ra->ra_cb(ra->ra_oc, capa);
3089 static int mdc_renew_capa(struct obd_export *exp, struct obd_capa *oc,
3092 struct ptlrpc_request *req;
3093 struct mdc_renew_capa_args *ra;
3096 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_GETATTR,
3097 LUSTRE_MDS_VERSION, MDS_GETATTR);
3101 /* NB, OBD_MD_FLOSSCAPA is set here, but it doesn't necessarily mean the
3102 * capa to renew is oss capa.
3104 mdc_pack_body(req, &oc->c_capa.lc_fid, oc, OBD_MD_FLOSSCAPA, 0, -1, 0);
3105 ptlrpc_request_set_replen(req);
3107 CLASSERT(sizeof(*ra) <= sizeof(req->rq_async_args));
3108 ra = ptlrpc_req_async_args(req);
3111 req->rq_interpret_reply = mdc_interpret_renew_capa;
3112 ptlrpcd_add_req(req, PDL_POLICY_LOCAL, -1);
3116 static struct obd_ops mdc_obd_ops = {
3117 .o_owner = THIS_MODULE,
3118 .o_setup = mdc_setup,
3119 .o_precleanup = mdc_precleanup,
3120 .o_cleanup = mdc_cleanup,
3121 .o_add_conn = client_import_add_conn,
3122 .o_del_conn = client_import_del_conn,
3123 .o_connect = client_connect_import,
3124 .o_disconnect = client_disconnect_export,
3125 .o_iocontrol = mdc_iocontrol,
3126 .o_set_info_async = mdc_set_info_async,
3127 .o_statfs = mdc_statfs,
3128 .o_fid_init = client_fid_init,
3129 .o_fid_fini = client_fid_fini,
3130 .o_fid_alloc = mdc_fid_alloc,
3131 .o_import_event = mdc_import_event,
3132 .o_get_info = mdc_get_info,
3133 .o_process_config = mdc_process_config,
3134 .o_get_uuid = mdc_get_uuid,
3135 .o_quotactl = mdc_quotactl,
3136 .o_quotacheck = mdc_quotacheck
3139 static struct md_ops mdc_md_ops = {
3140 .m_getstatus = mdc_getstatus,
3141 .m_null_inode = mdc_null_inode,
3142 .m_find_cbdata = mdc_find_cbdata,
3143 .m_close = mdc_close,
3144 .m_create = mdc_create,
3145 .m_done_writing = mdc_done_writing,
3146 .m_enqueue = mdc_enqueue,
3147 .m_getattr = mdc_getattr,
3148 .m_getattr_name = mdc_getattr_name,
3149 .m_intent_lock = mdc_intent_lock,
3151 .m_rename = mdc_rename,
3152 .m_setattr = mdc_setattr,
3153 .m_setxattr = mdc_setxattr,
3154 .m_getxattr = mdc_getxattr,
3155 .m_fsync = mdc_fsync,
3156 .m_read_page = mdc_read_page,
3157 .m_unlink = mdc_unlink,
3158 .m_cancel_unused = mdc_cancel_unused,
3159 .m_init_ea_size = mdc_init_ea_size,
3160 .m_set_lock_data = mdc_set_lock_data,
3161 .m_lock_match = mdc_lock_match,
3162 .m_get_lustre_md = mdc_get_lustre_md,
3163 .m_free_lustre_md = mdc_free_lustre_md,
3164 .m_set_open_replay_data = mdc_set_open_replay_data,
3165 .m_clear_open_replay_data = mdc_clear_open_replay_data,
3166 .m_renew_capa = mdc_renew_capa,
3167 .m_unpack_capa = mdc_unpack_capa,
3168 .m_get_remote_perm = mdc_get_remote_perm,
3169 .m_intent_getattr_async = mdc_intent_getattr_async,
3170 .m_revalidate_lock = mdc_revalidate_lock
3173 static int __init mdc_init(void)
3175 return class_register_type(&mdc_obd_ops, &mdc_md_ops, true, NULL,
3176 LUSTRE_MDC_NAME, NULL);
3179 static void /*__exit*/ mdc_exit(void)
3181 class_unregister_type(LUSTRE_MDC_NAME);
3184 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
3185 MODULE_DESCRIPTION("Lustre Metadata Client");
3186 MODULE_LICENSE("GPL");
3188 module_init(mdc_init);
3189 module_exit(mdc_exit);