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, 2015, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_MDC
39 # include <linux/module.h>
40 # include <linux/pagemap.h>
41 # include <linux/miscdevice.h>
42 # include <linux/init.h>
43 # include <linux/utsname.h>
45 #include "../include/lustre_acl.h"
46 #include "../include/obd_class.h"
47 #include "../include/lustre_fid.h"
48 #include "../include/lprocfs_status.h"
49 #include "../include/lustre_param.h"
50 #include "../include/lustre_log.h"
51 #include "../include/lustre_kernelcomm.h"
53 #include "mdc_internal.h"
55 #define REQUEST_MINOR 244
57 static int mdc_cleanup(struct obd_device
*obd
);
59 static inline int mdc_queue_wait(struct ptlrpc_request
*req
)
61 struct client_obd
*cli
= &req
->rq_import
->imp_obd
->u
.cli
;
64 /* mdc_enter_request() ensures that this client has no more
65 * than cl_max_rpcs_in_flight RPCs simultaneously inf light
68 rc
= mdc_enter_request(cli
);
72 rc
= ptlrpc_queue_wait(req
);
73 mdc_exit_request(cli
);
78 static int mdc_getstatus(struct obd_export
*exp
, struct lu_fid
*rootfid
)
80 struct ptlrpc_request
*req
;
81 struct mdt_body
*body
;
84 req
= ptlrpc_request_alloc_pack(class_exp2cliimp(exp
),
86 LUSTRE_MDS_VERSION
, MDS_GETSTATUS
);
90 mdc_pack_body(req
, NULL
, 0, 0, -1, 0);
91 req
->rq_send_state
= LUSTRE_IMP_FULL
;
93 ptlrpc_request_set_replen(req
);
95 rc
= ptlrpc_queue_wait(req
);
99 body
= req_capsule_server_get(&req
->rq_pill
, &RMF_MDT_BODY
);
105 *rootfid
= body
->fid1
;
107 "root fid="DFID
", last_committed=%llu\n",
109 lustre_msg_get_last_committed(req
->rq_repmsg
));
111 ptlrpc_req_finished(req
);
116 * This function now is known to always saying that it will receive 4 buffers
117 * from server. Even for cases when acl_size and md_size is zero, RPC header
118 * will contain 4 fields and RPC itself will contain zero size fields. This is
119 * because mdt_getattr*() _always_ returns 4 fields, but if acl is not needed
120 * and thus zero, it shrinks it, making zero size. The same story about
121 * md_size. And this is course of problem when client waits for smaller number
122 * of fields. This issue will be fixed later when client gets aware of RPC
125 static int mdc_getattr_common(struct obd_export
*exp
,
126 struct ptlrpc_request
*req
)
128 struct req_capsule
*pill
= &req
->rq_pill
;
129 struct mdt_body
*body
;
133 /* Request message already built. */
134 rc
= ptlrpc_queue_wait(req
);
138 /* sanity check for the reply */
139 body
= req_capsule_server_get(pill
, &RMF_MDT_BODY
);
143 CDEBUG(D_NET
, "mode: %o\n", body
->mode
);
145 if (body
->eadatasize
!= 0) {
146 mdc_update_max_ea_from_body(exp
, body
);
148 eadata
= req_capsule_server_sized_get(pill
, &RMF_MDT_MD
,
154 if (body
->valid
& OBD_MD_FLRMTPERM
) {
155 struct mdt_remote_perm
*perm
;
157 LASSERT(client_is_remote(exp
));
158 perm
= req_capsule_server_swab_get(pill
, &RMF_ACL
,
159 lustre_swab_mdt_remote_perm
);
167 static int mdc_getattr(struct obd_export
*exp
, struct md_op_data
*op_data
,
168 struct ptlrpc_request
**request
)
170 struct ptlrpc_request
*req
;
173 /* Single MDS without an LMV case */
174 if (op_data
->op_flags
& MF_GET_MDT_IDX
) {
179 req
= ptlrpc_request_alloc(class_exp2cliimp(exp
), &RQF_MDS_GETATTR
);
183 rc
= ptlrpc_request_pack(req
, LUSTRE_MDS_VERSION
, MDS_GETATTR
);
185 ptlrpc_request_free(req
);
189 mdc_pack_body(req
, &op_data
->op_fid1
, op_data
->op_valid
,
190 op_data
->op_mode
, -1, 0);
192 req_capsule_set_size(&req
->rq_pill
, &RMF_MDT_MD
, RCL_SERVER
,
194 if (op_data
->op_valid
& OBD_MD_FLRMTPERM
) {
195 LASSERT(client_is_remote(exp
));
196 req_capsule_set_size(&req
->rq_pill
, &RMF_ACL
, RCL_SERVER
,
197 sizeof(struct mdt_remote_perm
));
199 ptlrpc_request_set_replen(req
);
201 rc
= mdc_getattr_common(exp
, req
);
203 ptlrpc_req_finished(req
);
209 static int mdc_getattr_name(struct obd_export
*exp
, struct md_op_data
*op_data
,
210 struct ptlrpc_request
**request
)
212 struct ptlrpc_request
*req
;
216 req
= ptlrpc_request_alloc(class_exp2cliimp(exp
),
217 &RQF_MDS_GETATTR_NAME
);
221 req_capsule_set_size(&req
->rq_pill
, &RMF_NAME
, RCL_CLIENT
,
222 op_data
->op_namelen
+ 1);
224 rc
= ptlrpc_request_pack(req
, LUSTRE_MDS_VERSION
, MDS_GETATTR_NAME
);
226 ptlrpc_request_free(req
);
230 mdc_pack_body(req
, &op_data
->op_fid1
, op_data
->op_valid
,
231 op_data
->op_mode
, op_data
->op_suppgids
[0], 0);
233 if (op_data
->op_name
) {
234 char *name
= req_capsule_client_get(&req
->rq_pill
, &RMF_NAME
);
236 LASSERT(strnlen(op_data
->op_name
, op_data
->op_namelen
) ==
237 op_data
->op_namelen
);
238 memcpy(name
, op_data
->op_name
, op_data
->op_namelen
);
241 req_capsule_set_size(&req
->rq_pill
, &RMF_MDT_MD
, RCL_SERVER
,
243 ptlrpc_request_set_replen(req
);
245 rc
= mdc_getattr_common(exp
, req
);
247 ptlrpc_req_finished(req
);
253 static int mdc_is_subdir(struct obd_export
*exp
,
254 const struct lu_fid
*pfid
,
255 const struct lu_fid
*cfid
,
256 struct ptlrpc_request
**request
)
258 struct ptlrpc_request
*req
;
262 req
= ptlrpc_request_alloc_pack(class_exp2cliimp(exp
),
263 &RQF_MDS_IS_SUBDIR
, LUSTRE_MDS_VERSION
,
268 mdc_is_subdir_pack(req
, pfid
, cfid
, 0);
269 ptlrpc_request_set_replen(req
);
271 rc
= ptlrpc_queue_wait(req
);
272 if (rc
&& rc
!= -EREMOTE
)
273 ptlrpc_req_finished(req
);
279 static int mdc_xattr_common(struct obd_export
*exp
,
280 const struct req_format
*fmt
,
281 const struct lu_fid
*fid
,
282 int opcode
, u64 valid
,
283 const char *xattr_name
, const char *input
,
284 int input_size
, int output_size
, int flags
,
285 __u32 suppgid
, struct ptlrpc_request
**request
)
287 struct ptlrpc_request
*req
;
288 int xattr_namelen
= 0;
293 req
= ptlrpc_request_alloc(class_exp2cliimp(exp
), fmt
);
298 xattr_namelen
= strlen(xattr_name
) + 1;
299 req_capsule_set_size(&req
->rq_pill
, &RMF_NAME
, RCL_CLIENT
,
304 req_capsule_set_size(&req
->rq_pill
, &RMF_EADATA
, RCL_CLIENT
,
308 /* Flush local XATTR locks to get rid of a possible cancel RPC */
309 if (opcode
== MDS_REINT
&& fid_is_sane(fid
) &&
310 exp
->exp_connect_data
.ocd_ibits_known
& MDS_INODELOCK_XATTR
) {
314 /* Without that packing would fail */
316 req_capsule_set_size(&req
->rq_pill
, &RMF_EADATA
,
319 count
= mdc_resource_get_unused(exp
, fid
,
321 MDS_INODELOCK_XATTR
);
323 rc
= mdc_prep_elc_req(exp
, req
, MDS_REINT
, &cancels
, count
);
325 ptlrpc_request_free(req
);
329 rc
= ptlrpc_request_pack(req
, LUSTRE_MDS_VERSION
, opcode
);
331 ptlrpc_request_free(req
);
336 if (opcode
== MDS_REINT
) {
337 struct mdt_rec_setxattr
*rec
;
339 CLASSERT(sizeof(struct mdt_rec_setxattr
) ==
340 sizeof(struct mdt_rec_reint
));
341 rec
= req_capsule_client_get(&req
->rq_pill
, &RMF_REC_REINT
);
342 rec
->sx_opcode
= REINT_SETXATTR
;
343 rec
->sx_fsuid
= from_kuid(&init_user_ns
, current_fsuid());
344 rec
->sx_fsgid
= from_kgid(&init_user_ns
, current_fsgid());
345 rec
->sx_cap
= cfs_curproc_cap_pack();
346 rec
->sx_suppgid1
= suppgid
;
347 rec
->sx_suppgid2
= -1;
349 rec
->sx_valid
= valid
| OBD_MD_FLCTIME
;
350 rec
->sx_time
= ktime_get_real_seconds();
351 rec
->sx_size
= output_size
;
352 rec
->sx_flags
= flags
;
355 mdc_pack_body(req
, fid
, valid
, output_size
, suppgid
, flags
);
359 tmp
= req_capsule_client_get(&req
->rq_pill
, &RMF_NAME
);
360 memcpy(tmp
, xattr_name
, xattr_namelen
);
363 tmp
= req_capsule_client_get(&req
->rq_pill
, &RMF_EADATA
);
364 memcpy(tmp
, input
, input_size
);
367 if (req_capsule_has_field(&req
->rq_pill
, &RMF_EADATA
, RCL_SERVER
))
368 req_capsule_set_size(&req
->rq_pill
, &RMF_EADATA
,
369 RCL_SERVER
, output_size
);
370 ptlrpc_request_set_replen(req
);
373 if (opcode
== MDS_REINT
)
374 mdc_get_rpc_lock(exp
->exp_obd
->u
.cli
.cl_rpc_lock
, NULL
);
376 rc
= ptlrpc_queue_wait(req
);
378 if (opcode
== MDS_REINT
)
379 mdc_put_rpc_lock(exp
->exp_obd
->u
.cli
.cl_rpc_lock
, NULL
);
382 ptlrpc_req_finished(req
);
388 static int mdc_setxattr(struct obd_export
*exp
, const struct lu_fid
*fid
,
389 u64 valid
, const char *xattr_name
,
390 const char *input
, int input_size
, int output_size
,
391 int flags
, __u32 suppgid
,
392 struct ptlrpc_request
**request
)
394 return mdc_xattr_common(exp
, &RQF_MDS_REINT_SETXATTR
,
395 fid
, MDS_REINT
, valid
, xattr_name
,
396 input
, input_size
, output_size
, flags
,
400 static int mdc_getxattr(struct obd_export
*exp
, const struct lu_fid
*fid
,
401 u64 valid
, const char *xattr_name
,
402 const char *input
, int input_size
, int output_size
,
403 int flags
, struct ptlrpc_request
**request
)
405 return mdc_xattr_common(exp
, &RQF_MDS_GETXATTR
,
406 fid
, MDS_GETXATTR
, valid
, xattr_name
,
407 input
, input_size
, output_size
, flags
,
411 #ifdef CONFIG_FS_POSIX_ACL
412 static int mdc_unpack_acl(struct ptlrpc_request
*req
, struct lustre_md
*md
)
414 struct req_capsule
*pill
= &req
->rq_pill
;
415 struct mdt_body
*body
= md
->body
;
416 struct posix_acl
*acl
;
423 buf
= req_capsule_server_sized_get(pill
, &RMF_ACL
, body
->aclsize
);
428 acl
= posix_acl_from_xattr(&init_user_ns
, buf
, body
->aclsize
);
434 CERROR("convert xattr to acl: %d\n", rc
);
438 rc
= posix_acl_valid(acl
);
440 CERROR("validate acl: %d\n", rc
);
441 posix_acl_release(acl
);
449 #define mdc_unpack_acl(req, md) 0
452 static int mdc_get_lustre_md(struct obd_export
*exp
,
453 struct ptlrpc_request
*req
,
454 struct obd_export
*dt_exp
,
455 struct obd_export
*md_exp
,
456 struct lustre_md
*md
)
458 struct req_capsule
*pill
= &req
->rq_pill
;
462 memset(md
, 0, sizeof(*md
));
464 md
->body
= req_capsule_server_get(pill
, &RMF_MDT_BODY
);
466 if (md
->body
->valid
& OBD_MD_FLEASIZE
) {
468 struct lov_mds_md
*lmm
;
470 if (!S_ISREG(md
->body
->mode
)) {
472 "OBD_MD_FLEASIZE set, should be a regular file, but is not\n");
477 if (md
->body
->eadatasize
== 0) {
479 "OBD_MD_FLEASIZE set, but eadatasize 0\n");
483 lmmsize
= md
->body
->eadatasize
;
484 lmm
= req_capsule_server_sized_get(pill
, &RMF_MDT_MD
, lmmsize
);
490 rc
= obd_unpackmd(dt_exp
, &md
->lsm
, lmm
, lmmsize
);
494 if (rc
< sizeof(*md
->lsm
)) {
496 "lsm size too small: rc < sizeof (*md->lsm) (%d < %d)\n",
497 rc
, (int)sizeof(*md
->lsm
));
502 } else if (md
->body
->valid
& OBD_MD_FLDIREA
) {
504 struct lov_mds_md
*lmv
;
506 if (!S_ISDIR(md
->body
->mode
)) {
508 "OBD_MD_FLDIREA set, should be a directory, but is not\n");
513 if (md
->body
->eadatasize
== 0) {
515 "OBD_MD_FLDIREA is set, but eadatasize 0\n");
518 if (md
->body
->valid
& OBD_MD_MEA
) {
519 lmvsize
= md
->body
->eadatasize
;
520 lmv
= req_capsule_server_sized_get(pill
, &RMF_MDT_MD
,
527 rc
= obd_unpackmd(md_exp
, (void *)&md
->mea
, lmv
,
532 if (rc
< sizeof(*md
->mea
)) {
534 "size too small: rc < sizeof(*md->mea) (%d < %d)\n",
535 rc
, (int)sizeof(*md
->mea
));
543 if (md
->body
->valid
& OBD_MD_FLRMTPERM
) {
544 /* remote permission */
545 LASSERT(client_is_remote(exp
));
546 md
->remote_perm
= req_capsule_server_swab_get(pill
, &RMF_ACL
,
547 lustre_swab_mdt_remote_perm
);
548 if (!md
->remote_perm
) {
552 } else if (md
->body
->valid
& OBD_MD_FLACL
) {
553 /* for ACL, it's possible that FLACL is set but aclsize is zero.
554 * only when aclsize != 0 there's an actual segment for ACL
557 if (md
->body
->aclsize
) {
558 rc
= mdc_unpack_acl(req
, md
);
561 #ifdef CONFIG_FS_POSIX_ACL
563 md
->posix_acl
= NULL
;
570 #ifdef CONFIG_FS_POSIX_ACL
571 posix_acl_release(md
->posix_acl
);
574 obd_free_memmd(dt_exp
, &md
->lsm
);
579 static int mdc_free_lustre_md(struct obd_export
*exp
, struct lustre_md
*md
)
585 * Handles both OPEN and SETATTR RPCs for OPEN-CLOSE and SETATTR-DONE_WRITING
588 void mdc_replay_open(struct ptlrpc_request
*req
)
590 struct md_open_data
*mod
= req
->rq_cb_data
;
591 struct ptlrpc_request
*close_req
;
592 struct obd_client_handle
*och
;
593 struct lustre_handle old
;
594 struct mdt_body
*body
;
597 DEBUG_REQ(D_ERROR
, req
,
598 "Can't properly replay without open data.");
602 body
= req_capsule_server_get(&req
->rq_pill
, &RMF_MDT_BODY
);
606 struct lustre_handle
*file_fh
;
608 LASSERT(och
->och_magic
== OBD_CLIENT_HANDLE_MAGIC
);
610 file_fh
= &och
->och_fh
;
611 CDEBUG(D_HA
, "updating handle from %#llx to %#llx\n",
612 file_fh
->cookie
, body
->handle
.cookie
);
614 *file_fh
= body
->handle
;
616 close_req
= mod
->mod_close_req
;
618 __u32 opc
= lustre_msg_get_opc(close_req
->rq_reqmsg
);
619 struct mdt_ioepoch
*epoch
;
621 LASSERT(opc
== MDS_CLOSE
|| opc
== MDS_DONE_WRITING
);
622 epoch
= req_capsule_client_get(&close_req
->rq_pill
,
627 LASSERT(!memcmp(&old
, &epoch
->handle
, sizeof(old
)));
628 DEBUG_REQ(D_HA
, close_req
, "updating close body with new fh");
629 epoch
->handle
= body
->handle
;
633 void mdc_commit_open(struct ptlrpc_request
*req
)
635 struct md_open_data
*mod
= req
->rq_cb_data
;
641 * No need to touch md_open_data::mod_och, it holds a reference on
642 * \var mod and will zero references to each other, \var mod will be
643 * freed after that when md_open_data::mod_och will put the reference.
647 * Do not let open request to disappear as it still may be needed
648 * for close rpc to happen (it may happen on evict only, otherwise
649 * ptlrpc_request::rq_replay does not let mdc_commit_open() to be
650 * called), just mark this rpc as committed to distinguish these 2
651 * cases, see mdc_close() for details. The open request reference will
652 * be put along with freeing \var mod.
654 ptlrpc_request_addref(req
);
655 spin_lock(&req
->rq_lock
);
656 req
->rq_committed
= 1;
657 spin_unlock(&req
->rq_lock
);
658 req
->rq_cb_data
= NULL
;
662 int mdc_set_open_replay_data(struct obd_export
*exp
,
663 struct obd_client_handle
*och
,
664 struct lookup_intent
*it
)
666 struct md_open_data
*mod
;
667 struct mdt_rec_create
*rec
;
668 struct mdt_body
*body
;
669 struct ptlrpc_request
*open_req
= it
->d
.lustre
.it_data
;
670 struct obd_import
*imp
= open_req
->rq_import
;
672 if (!open_req
->rq_replay
)
675 rec
= req_capsule_client_get(&open_req
->rq_pill
, &RMF_REC_REINT
);
676 body
= req_capsule_server_get(&open_req
->rq_pill
, &RMF_MDT_BODY
);
678 /* Incoming message in my byte order (it's been swabbed). */
679 /* Outgoing messages always in my byte order. */
682 /* Only if the import is replayable, we set replay_open data */
683 if (och
&& imp
->imp_replayable
) {
684 mod
= obd_mod_alloc();
686 DEBUG_REQ(D_ERROR
, open_req
,
687 "Can't allocate md_open_data");
692 * Take a reference on \var mod, to be freed on mdc_close().
693 * It protects \var mod from being freed on eviction (commit
694 * callback is called despite rq_replay flag).
695 * Another reference for \var och.
700 spin_lock(&open_req
->rq_lock
);
703 mod
->mod_is_create
= it_disposition(it
, DISP_OPEN_CREATE
) ||
704 it_disposition(it
, DISP_OPEN_STRIPE
);
705 mod
->mod_open_req
= open_req
;
706 open_req
->rq_cb_data
= mod
;
707 open_req
->rq_commit_cb
= mdc_commit_open
;
708 spin_unlock(&open_req
->rq_lock
);
711 rec
->cr_fid2
= body
->fid1
;
712 rec
->cr_ioepoch
= body
->ioepoch
;
713 rec
->cr_old_handle
.cookie
= body
->handle
.cookie
;
714 open_req
->rq_replay_cb
= mdc_replay_open
;
715 if (!fid_is_sane(&body
->fid1
)) {
716 DEBUG_REQ(D_ERROR
, open_req
,
717 "Saving replay request with insane fid");
721 DEBUG_REQ(D_RPCTRACE
, open_req
, "Set up open replay data");
725 static void mdc_free_open(struct md_open_data
*mod
)
729 if (mod
->mod_is_create
== 0 &&
730 imp_connect_disp_stripe(mod
->mod_open_req
->rq_import
))
733 LASSERT(mod
->mod_open_req
->rq_replay
== 0);
735 DEBUG_REQ(D_RPCTRACE
, mod
->mod_open_req
, "free open request\n");
737 ptlrpc_request_committed(mod
->mod_open_req
, committed
);
738 if (mod
->mod_close_req
)
739 ptlrpc_request_committed(mod
->mod_close_req
, committed
);
742 static int mdc_clear_open_replay_data(struct obd_export
*exp
,
743 struct obd_client_handle
*och
)
745 struct md_open_data
*mod
= och
->och_mod
;
748 * It is possible to not have \var mod in a case of eviction between
749 * lookup and ll_file_open().
754 LASSERT(mod
!= LP_POISON
);
755 LASSERT(mod
->mod_open_req
);
765 /* Prepares the request for the replay by the given reply */
766 static void mdc_close_handle_reply(struct ptlrpc_request
*req
,
767 struct md_op_data
*op_data
, int rc
) {
768 struct mdt_body
*repbody
;
769 struct mdt_ioepoch
*epoch
;
771 if (req
&& rc
== -EAGAIN
) {
772 repbody
= req_capsule_server_get(&req
->rq_pill
, &RMF_MDT_BODY
);
773 epoch
= req_capsule_client_get(&req
->rq_pill
, &RMF_MDT_EPOCH
);
775 epoch
->flags
|= MF_SOM_AU
;
776 if (repbody
->valid
& OBD_MD_FLGETATTRLOCK
)
777 op_data
->op_flags
|= MF_GETATTR_LOCK
;
781 static int mdc_close(struct obd_export
*exp
, struct md_op_data
*op_data
,
782 struct md_open_data
*mod
, struct ptlrpc_request
**request
)
784 struct obd_device
*obd
= class_exp2obd(exp
);
785 struct ptlrpc_request
*req
;
786 struct req_format
*req_fmt
;
790 req_fmt
= &RQF_MDS_CLOSE
;
791 if (op_data
->op_bias
& MDS_HSM_RELEASE
) {
792 req_fmt
= &RQF_MDS_RELEASE_CLOSE
;
794 /* allocate a FID for volatile file */
795 rc
= mdc_fid_alloc(exp
, &op_data
->op_fid2
, op_data
);
797 CERROR("%s: "DFID
" failed to allocate FID: %d\n",
798 obd
->obd_name
, PFID(&op_data
->op_fid1
), rc
);
799 /* save the errcode and proceed to close */
805 req
= ptlrpc_request_alloc(class_exp2cliimp(exp
), req_fmt
);
809 rc
= ptlrpc_request_pack(req
, LUSTRE_MDS_VERSION
, MDS_CLOSE
);
811 ptlrpc_request_free(req
);
815 /* To avoid a livelock (bug 7034), we need to send CLOSE RPCs to a
816 * portal whose threads are not taking any DLM locks and are therefore
819 req
->rq_request_portal
= MDS_READPAGE_PORTAL
;
820 ptlrpc_at_set_req_timeout(req
);
822 /* Ensure that this close's handle is fixed up during replay. */
824 LASSERTF(mod
->mod_open_req
&&
825 mod
->mod_open_req
->rq_type
!= LI_POISON
,
826 "POISONED open %p!\n", mod
->mod_open_req
);
828 mod
->mod_close_req
= req
;
830 DEBUG_REQ(D_HA
, mod
->mod_open_req
, "matched open");
831 /* We no longer want to preserve this open for replay even
832 * though the open was committed. b=3632, b=3633
834 spin_lock(&mod
->mod_open_req
->rq_lock
);
835 mod
->mod_open_req
->rq_replay
= 0;
836 spin_unlock(&mod
->mod_open_req
->rq_lock
);
839 "couldn't find open req; expecting close error\n");
842 mdc_close_pack(req
, op_data
);
844 req_capsule_set_size(&req
->rq_pill
, &RMF_MDT_MD
, RCL_SERVER
,
845 obd
->u
.cli
.cl_default_mds_easize
);
846 req_capsule_set_size(&req
->rq_pill
, &RMF_LOGCOOKIES
, RCL_SERVER
,
847 obd
->u
.cli
.cl_default_mds_cookiesize
);
849 ptlrpc_request_set_replen(req
);
851 mdc_get_rpc_lock(obd
->u
.cli
.cl_close_lock
, NULL
);
852 rc
= ptlrpc_queue_wait(req
);
853 mdc_put_rpc_lock(obd
->u
.cli
.cl_close_lock
, NULL
);
855 if (!req
->rq_repmsg
) {
856 CDEBUG(D_RPCTRACE
, "request failed to send: %p, %d\n", req
,
859 rc
= req
->rq_status
?: -EIO
;
860 } else if (rc
== 0 || rc
== -EAGAIN
) {
861 struct mdt_body
*body
;
863 rc
= lustre_msg_get_status(req
->rq_repmsg
);
864 if (lustre_msg_get_type(req
->rq_repmsg
) == PTL_RPC_MSG_ERR
) {
865 DEBUG_REQ(D_ERROR
, req
,
866 "type == PTL_RPC_MSG_ERR, err = %d", rc
);
870 body
= req_capsule_server_get(&req
->rq_pill
, &RMF_MDT_BODY
);
873 } else if (rc
== -ESTALE
) {
875 * it can be allowed error after 3633 if open was committed and
876 * server failed before close was sent. Let's check if mod
877 * exists and return no error in that case
880 DEBUG_REQ(D_HA
, req
, "Reset ESTALE = %d", rc
);
881 if (mod
->mod_open_req
->rq_committed
)
888 mod
->mod_close_req
= NULL
;
889 /* Since now, mod is accessed through open_req only,
890 * thus close req does not keep a reference on mod anymore.
895 mdc_close_handle_reply(req
, op_data
, rc
);
896 return rc
< 0 ? rc
: saved_rc
;
899 static int mdc_done_writing(struct obd_export
*exp
, struct md_op_data
*op_data
,
900 struct md_open_data
*mod
)
902 struct obd_device
*obd
= class_exp2obd(exp
);
903 struct ptlrpc_request
*req
;
906 req
= ptlrpc_request_alloc(class_exp2cliimp(exp
),
907 &RQF_MDS_DONE_WRITING
);
911 rc
= ptlrpc_request_pack(req
, LUSTRE_MDS_VERSION
, MDS_DONE_WRITING
);
913 ptlrpc_request_free(req
);
918 LASSERTF(mod
->mod_open_req
&&
919 mod
->mod_open_req
->rq_type
!= LI_POISON
,
920 "POISONED setattr %p!\n", mod
->mod_open_req
);
922 mod
->mod_close_req
= req
;
923 DEBUG_REQ(D_HA
, mod
->mod_open_req
, "matched setattr");
924 /* We no longer want to preserve this setattr for replay even
925 * though the open was committed. b=3632, b=3633
927 spin_lock(&mod
->mod_open_req
->rq_lock
);
928 mod
->mod_open_req
->rq_replay
= 0;
929 spin_unlock(&mod
->mod_open_req
->rq_lock
);
932 mdc_close_pack(req
, op_data
);
933 ptlrpc_request_set_replen(req
);
935 mdc_get_rpc_lock(obd
->u
.cli
.cl_close_lock
, NULL
);
936 rc
= ptlrpc_queue_wait(req
);
937 mdc_put_rpc_lock(obd
->u
.cli
.cl_close_lock
, NULL
);
941 * it can be allowed error after 3633 if open or setattr were
942 * committed and server failed before close was sent.
943 * Let's check if mod exists and return no error in that case
946 if (mod
->mod_open_req
->rq_committed
)
953 mod
->mod_close_req
= NULL
;
954 LASSERT(mod
->mod_open_req
);
957 /* Since now, mod is accessed through setattr req only,
958 * thus DW req does not keep a reference on mod anymore.
963 mdc_close_handle_reply(req
, op_data
, rc
);
964 ptlrpc_req_finished(req
);
968 static int mdc_readpage(struct obd_export
*exp
, struct md_op_data
*op_data
,
969 struct page
**pages
, struct ptlrpc_request
**request
)
971 struct ptlrpc_request
*req
;
972 struct ptlrpc_bulk_desc
*desc
;
974 wait_queue_head_t waitq
;
976 struct l_wait_info lwi
;
980 init_waitqueue_head(&waitq
);
983 req
= ptlrpc_request_alloc(class_exp2cliimp(exp
), &RQF_MDS_READPAGE
);
987 rc
= ptlrpc_request_pack(req
, LUSTRE_MDS_VERSION
, MDS_READPAGE
);
989 ptlrpc_request_free(req
);
993 req
->rq_request_portal
= MDS_READPAGE_PORTAL
;
994 ptlrpc_at_set_req_timeout(req
);
996 desc
= ptlrpc_prep_bulk_imp(req
, op_data
->op_npages
, 1, BULK_PUT_SINK
,
999 ptlrpc_request_free(req
);
1003 /* NB req now owns desc and will free it when it gets freed */
1004 for (i
= 0; i
< op_data
->op_npages
; i
++)
1005 ptlrpc_prep_bulk_page_pin(desc
, pages
[i
], 0, PAGE_SIZE
);
1007 mdc_readdir_pack(req
, op_data
->op_offset
,
1008 PAGE_SIZE
* op_data
->op_npages
,
1011 ptlrpc_request_set_replen(req
);
1012 rc
= ptlrpc_queue_wait(req
);
1014 ptlrpc_req_finished(req
);
1015 if (rc
!= -ETIMEDOUT
)
1019 if (!client_should_resend(resends
, &exp
->exp_obd
->u
.cli
)) {
1020 CERROR("too many resend retries, returning error\n");
1023 lwi
= LWI_TIMEOUT_INTR(cfs_time_seconds(resends
),
1025 l_wait_event(waitq
, 0, &lwi
);
1030 rc
= sptlrpc_cli_unwrap_bulk_read(req
, req
->rq_bulk
,
1031 req
->rq_bulk
->bd_nob_transferred
);
1033 ptlrpc_req_finished(req
);
1037 if (req
->rq_bulk
->bd_nob_transferred
& ~LU_PAGE_MASK
) {
1038 CERROR("Unexpected # bytes transferred: %d (%ld expected)\n",
1039 req
->rq_bulk
->bd_nob_transferred
,
1040 PAGE_SIZE
* op_data
->op_npages
);
1041 ptlrpc_req_finished(req
);
1049 static int mdc_statfs(const struct lu_env
*env
,
1050 struct obd_export
*exp
, struct obd_statfs
*osfs
,
1051 __u64 max_age
, __u32 flags
)
1053 struct obd_device
*obd
= class_exp2obd(exp
);
1054 struct ptlrpc_request
*req
;
1055 struct obd_statfs
*msfs
;
1056 struct obd_import
*imp
= NULL
;
1060 * Since the request might also come from lprocfs, so we need
1061 * sync this with client_disconnect_export Bug15684
1063 down_read(&obd
->u
.cli
.cl_sem
);
1064 if (obd
->u
.cli
.cl_import
)
1065 imp
= class_import_get(obd
->u
.cli
.cl_import
);
1066 up_read(&obd
->u
.cli
.cl_sem
);
1070 req
= ptlrpc_request_alloc_pack(imp
, &RQF_MDS_STATFS
,
1071 LUSTRE_MDS_VERSION
, MDS_STATFS
);
1077 ptlrpc_request_set_replen(req
);
1079 if (flags
& OBD_STATFS_NODELAY
) {
1080 /* procfs requests not want stay in wait for avoid deadlock */
1081 req
->rq_no_resend
= 1;
1082 req
->rq_no_delay
= 1;
1085 rc
= ptlrpc_queue_wait(req
);
1087 /* check connection error first */
1088 if (imp
->imp_connect_error
)
1089 rc
= imp
->imp_connect_error
;
1093 msfs
= req_capsule_server_get(&req
->rq_pill
, &RMF_OBD_STATFS
);
1101 ptlrpc_req_finished(req
);
1103 class_import_put(imp
);
1107 static int mdc_ioc_fid2path(struct obd_export
*exp
, struct getinfo_fid2path
*gf
)
1109 __u32 keylen
, vallen
;
1113 if (gf
->gf_pathlen
> PATH_MAX
)
1114 return -ENAMETOOLONG
;
1115 if (gf
->gf_pathlen
< 2)
1118 /* Key is KEY_FID2PATH + getinfo_fid2path description */
1119 keylen
= cfs_size_round(sizeof(KEY_FID2PATH
)) + sizeof(*gf
);
1120 key
= kzalloc(keylen
, GFP_NOFS
);
1123 memcpy(key
, KEY_FID2PATH
, sizeof(KEY_FID2PATH
));
1124 memcpy(key
+ cfs_size_round(sizeof(KEY_FID2PATH
)), gf
, sizeof(*gf
));
1126 CDEBUG(D_IOCTL
, "path get "DFID
" from %llu #%d\n",
1127 PFID(&gf
->gf_fid
), gf
->gf_recno
, gf
->gf_linkno
);
1129 if (!fid_is_sane(&gf
->gf_fid
)) {
1134 /* Val is struct getinfo_fid2path result plus path */
1135 vallen
= sizeof(*gf
) + gf
->gf_pathlen
;
1137 rc
= obd_get_info(NULL
, exp
, keylen
, key
, &vallen
, gf
, NULL
);
1138 if (rc
!= 0 && rc
!= -EREMOTE
)
1141 if (vallen
<= sizeof(*gf
)) {
1144 } else if (vallen
> sizeof(*gf
) + gf
->gf_pathlen
) {
1149 CDEBUG(D_IOCTL
, "path get "DFID
" from %llu #%d\n%s\n",
1150 PFID(&gf
->gf_fid
), gf
->gf_recno
, gf
->gf_linkno
, gf
->gf_path
);
1157 static int mdc_ioc_hsm_progress(struct obd_export
*exp
,
1158 struct hsm_progress_kernel
*hpk
)
1160 struct obd_import
*imp
= class_exp2cliimp(exp
);
1161 struct hsm_progress_kernel
*req_hpk
;
1162 struct ptlrpc_request
*req
;
1165 req
= ptlrpc_request_alloc_pack(imp
, &RQF_MDS_HSM_PROGRESS
,
1166 LUSTRE_MDS_VERSION
, MDS_HSM_PROGRESS
);
1172 mdc_pack_body(req
, NULL
, OBD_MD_FLRMTPERM
, 0, 0, 0);
1174 /* Copy hsm_progress struct */
1175 req_hpk
= req_capsule_client_get(&req
->rq_pill
, &RMF_MDS_HSM_PROGRESS
);
1182 req_hpk
->hpk_errval
= lustre_errno_hton(hpk
->hpk_errval
);
1184 ptlrpc_request_set_replen(req
);
1186 rc
= mdc_queue_wait(req
);
1188 ptlrpc_req_finished(req
);
1192 static int mdc_ioc_hsm_ct_register(struct obd_import
*imp
, __u32 archives
)
1194 __u32
*archive_mask
;
1195 struct ptlrpc_request
*req
;
1198 req
= ptlrpc_request_alloc_pack(imp
, &RQF_MDS_HSM_CT_REGISTER
,
1200 MDS_HSM_CT_REGISTER
);
1206 mdc_pack_body(req
, NULL
, OBD_MD_FLRMTPERM
, 0, 0, 0);
1208 /* Copy hsm_progress struct */
1209 archive_mask
= req_capsule_client_get(&req
->rq_pill
,
1210 &RMF_MDS_HSM_ARCHIVE
);
1211 if (!archive_mask
) {
1216 *archive_mask
= archives
;
1218 ptlrpc_request_set_replen(req
);
1220 rc
= mdc_queue_wait(req
);
1222 ptlrpc_req_finished(req
);
1226 static int mdc_ioc_hsm_current_action(struct obd_export
*exp
,
1227 struct md_op_data
*op_data
)
1229 struct hsm_current_action
*hca
= op_data
->op_data
;
1230 struct hsm_current_action
*req_hca
;
1231 struct ptlrpc_request
*req
;
1234 req
= ptlrpc_request_alloc(class_exp2cliimp(exp
),
1235 &RQF_MDS_HSM_ACTION
);
1239 rc
= ptlrpc_request_pack(req
, LUSTRE_MDS_VERSION
, MDS_HSM_ACTION
);
1241 ptlrpc_request_free(req
);
1245 mdc_pack_body(req
, &op_data
->op_fid1
, OBD_MD_FLRMTPERM
, 0,
1246 op_data
->op_suppgids
[0], 0);
1248 ptlrpc_request_set_replen(req
);
1250 rc
= mdc_queue_wait(req
);
1254 req_hca
= req_capsule_server_get(&req
->rq_pill
,
1255 &RMF_MDS_HSM_CURRENT_ACTION
);
1264 ptlrpc_req_finished(req
);
1268 static int mdc_ioc_hsm_ct_unregister(struct obd_import
*imp
)
1270 struct ptlrpc_request
*req
;
1273 req
= ptlrpc_request_alloc_pack(imp
, &RQF_MDS_HSM_CT_UNREGISTER
,
1275 MDS_HSM_CT_UNREGISTER
);
1281 mdc_pack_body(req
, NULL
, OBD_MD_FLRMTPERM
, 0, 0, 0);
1283 ptlrpc_request_set_replen(req
);
1285 rc
= mdc_queue_wait(req
);
1287 ptlrpc_req_finished(req
);
1291 static int mdc_ioc_hsm_state_get(struct obd_export
*exp
,
1292 struct md_op_data
*op_data
)
1294 struct hsm_user_state
*hus
= op_data
->op_data
;
1295 struct hsm_user_state
*req_hus
;
1296 struct ptlrpc_request
*req
;
1299 req
= ptlrpc_request_alloc(class_exp2cliimp(exp
),
1300 &RQF_MDS_HSM_STATE_GET
);
1304 rc
= ptlrpc_request_pack(req
, LUSTRE_MDS_VERSION
, MDS_HSM_STATE_GET
);
1306 ptlrpc_request_free(req
);
1310 mdc_pack_body(req
, &op_data
->op_fid1
, OBD_MD_FLRMTPERM
, 0,
1311 op_data
->op_suppgids
[0], 0);
1313 ptlrpc_request_set_replen(req
);
1315 rc
= mdc_queue_wait(req
);
1319 req_hus
= req_capsule_server_get(&req
->rq_pill
, &RMF_HSM_USER_STATE
);
1328 ptlrpc_req_finished(req
);
1332 static int mdc_ioc_hsm_state_set(struct obd_export
*exp
,
1333 struct md_op_data
*op_data
)
1335 struct hsm_state_set
*hss
= op_data
->op_data
;
1336 struct hsm_state_set
*req_hss
;
1337 struct ptlrpc_request
*req
;
1340 req
= ptlrpc_request_alloc(class_exp2cliimp(exp
),
1341 &RQF_MDS_HSM_STATE_SET
);
1345 rc
= ptlrpc_request_pack(req
, LUSTRE_MDS_VERSION
, MDS_HSM_STATE_SET
);
1347 ptlrpc_request_free(req
);
1351 mdc_pack_body(req
, &op_data
->op_fid1
, OBD_MD_FLRMTPERM
, 0,
1352 op_data
->op_suppgids
[0], 0);
1355 req_hss
= req_capsule_client_get(&req
->rq_pill
, &RMF_HSM_STATE_SET
);
1362 ptlrpc_request_set_replen(req
);
1364 rc
= mdc_queue_wait(req
);
1366 ptlrpc_req_finished(req
);
1370 static int mdc_ioc_hsm_request(struct obd_export
*exp
,
1371 struct hsm_user_request
*hur
)
1373 struct obd_import
*imp
= class_exp2cliimp(exp
);
1374 struct ptlrpc_request
*req
;
1375 struct hsm_request
*req_hr
;
1376 struct hsm_user_item
*req_hui
;
1380 req
= ptlrpc_request_alloc(imp
, &RQF_MDS_HSM_REQUEST
);
1386 req_capsule_set_size(&req
->rq_pill
, &RMF_MDS_HSM_USER_ITEM
, RCL_CLIENT
,
1387 hur
->hur_request
.hr_itemcount
1388 * sizeof(struct hsm_user_item
));
1389 req_capsule_set_size(&req
->rq_pill
, &RMF_GENERIC_DATA
, RCL_CLIENT
,
1390 hur
->hur_request
.hr_data_len
);
1392 rc
= ptlrpc_request_pack(req
, LUSTRE_MDS_VERSION
, MDS_HSM_REQUEST
);
1394 ptlrpc_request_free(req
);
1398 mdc_pack_body(req
, NULL
, OBD_MD_FLRMTPERM
, 0, 0, 0);
1400 /* Copy hsm_request struct */
1401 req_hr
= req_capsule_client_get(&req
->rq_pill
, &RMF_MDS_HSM_REQUEST
);
1406 *req_hr
= hur
->hur_request
;
1408 /* Copy hsm_user_item structs */
1409 req_hui
= req_capsule_client_get(&req
->rq_pill
, &RMF_MDS_HSM_USER_ITEM
);
1414 memcpy(req_hui
, hur
->hur_user_item
,
1415 hur
->hur_request
.hr_itemcount
* sizeof(struct hsm_user_item
));
1417 /* Copy opaque field */
1418 req_opaque
= req_capsule_client_get(&req
->rq_pill
, &RMF_GENERIC_DATA
);
1423 memcpy(req_opaque
, hur_data(hur
), hur
->hur_request
.hr_data_len
);
1425 ptlrpc_request_set_replen(req
);
1427 rc
= mdc_queue_wait(req
);
1429 ptlrpc_req_finished(req
);
1433 static struct kuc_hdr
*changelog_kuc_hdr(char *buf
, int len
, int flags
)
1435 struct kuc_hdr
*lh
= (struct kuc_hdr
*)buf
;
1437 LASSERT(len
<= KUC_CHANGELOG_MSG_MAXSIZE
);
1439 lh
->kuc_magic
= KUC_MAGIC
;
1440 lh
->kuc_transport
= KUC_TRANSPORT_CHANGELOG
;
1441 lh
->kuc_flags
= flags
;
1442 lh
->kuc_msgtype
= CL_RECORD
;
1443 lh
->kuc_msglen
= len
;
1447 #define D_CHANGELOG 0
1449 struct changelog_show
{
1454 struct obd_device
*cs_obd
;
1457 static int changelog_kkuc_cb(const struct lu_env
*env
, struct llog_handle
*llh
,
1458 struct llog_rec_hdr
*hdr
, void *data
)
1460 struct changelog_show
*cs
= data
;
1461 struct llog_changelog_rec
*rec
= (struct llog_changelog_rec
*)hdr
;
1465 if (rec
->cr_hdr
.lrh_type
!= CHANGELOG_REC
) {
1467 CERROR("%s: not a changelog rec %x/%d: rc = %d\n",
1468 cs
->cs_obd
->obd_name
, rec
->cr_hdr
.lrh_type
,
1469 rec
->cr
.cr_type
, rc
);
1473 if (rec
->cr
.cr_index
< cs
->cs_startrec
) {
1474 /* Skip entries earlier than what we are interested in */
1475 CDEBUG(D_CHANGELOG
, "rec=%llu start=%llu\n",
1476 rec
->cr
.cr_index
, cs
->cs_startrec
);
1480 CDEBUG(D_CHANGELOG
, "%llu %02d%-5s %llu 0x%x t="DFID
" p="DFID
1481 " %.*s\n", rec
->cr
.cr_index
, rec
->cr
.cr_type
,
1482 changelog_type2str(rec
->cr
.cr_type
), rec
->cr
.cr_time
,
1483 rec
->cr
.cr_flags
& CLF_FLAGMASK
,
1484 PFID(&rec
->cr
.cr_tfid
), PFID(&rec
->cr
.cr_pfid
),
1485 rec
->cr
.cr_namelen
, changelog_rec_name(&rec
->cr
));
1487 len
= sizeof(*lh
) + changelog_rec_size(&rec
->cr
) + rec
->cr
.cr_namelen
;
1489 /* Set up the message */
1490 lh
= changelog_kuc_hdr(cs
->cs_buf
, len
, cs
->cs_flags
);
1491 memcpy(lh
+ 1, &rec
->cr
, len
- sizeof(*lh
));
1493 rc
= libcfs_kkuc_msg_put(cs
->cs_fp
, lh
);
1494 CDEBUG(D_CHANGELOG
, "kucmsg fp %p len %d rc %d\n", cs
->cs_fp
, len
, rc
);
1499 static int mdc_changelog_send_thread(void *csdata
)
1501 struct changelog_show
*cs
= csdata
;
1502 struct llog_ctxt
*ctxt
= NULL
;
1503 struct llog_handle
*llh
= NULL
;
1504 struct kuc_hdr
*kuch
;
1507 CDEBUG(D_CHANGELOG
, "changelog to fp=%p start %llu\n",
1508 cs
->cs_fp
, cs
->cs_startrec
);
1510 cs
->cs_buf
= kzalloc(KUC_CHANGELOG_MSG_MAXSIZE
, GFP_NOFS
);
1516 /* Set up the remote catalog handle */
1517 ctxt
= llog_get_context(cs
->cs_obd
, LLOG_CHANGELOG_REPL_CTXT
);
1522 rc
= llog_open(NULL
, ctxt
, &llh
, NULL
, CHANGELOG_CATALOG
,
1525 CERROR("%s: fail to open changelog catalog: rc = %d\n",
1526 cs
->cs_obd
->obd_name
, rc
);
1529 rc
= llog_init_handle(NULL
, llh
, LLOG_F_IS_CAT
, NULL
);
1531 CERROR("llog_init_handle failed %d\n", rc
);
1535 rc
= llog_cat_process(NULL
, llh
, changelog_kkuc_cb
, cs
, 0, 0);
1537 /* Send EOF no matter what our result */
1538 kuch
= changelog_kuc_hdr(cs
->cs_buf
, sizeof(*kuch
), cs
->cs_flags
);
1540 kuch
->kuc_msgtype
= CL_EOF
;
1541 libcfs_kkuc_msg_put(cs
->cs_fp
, kuch
);
1547 llog_cat_close(NULL
, llh
);
1549 llog_ctxt_put(ctxt
);
1555 static int mdc_ioc_changelog_send(struct obd_device
*obd
,
1556 struct ioc_changelog
*icc
)
1558 struct changelog_show
*cs
;
1559 struct task_struct
*task
;
1562 /* Freed in mdc_changelog_send_thread */
1563 cs
= kzalloc(sizeof(*cs
), GFP_NOFS
);
1568 cs
->cs_startrec
= icc
->icc_recno
;
1569 /* matching fput in mdc_changelog_send_thread */
1570 cs
->cs_fp
= fget(icc
->icc_id
);
1571 cs
->cs_flags
= icc
->icc_flags
;
1574 * New thread because we should return to user app before
1575 * writing into our pipe
1577 task
= kthread_run(mdc_changelog_send_thread
, cs
,
1578 "mdc_clg_send_thread");
1581 CERROR("%s: can't start changelog thread: rc = %d\n",
1586 CDEBUG(D_CHANGELOG
, "%s: started changelog thread\n",
1590 CERROR("Failed to start changelog thread: %d\n", rc
);
1594 static int mdc_ioc_hsm_ct_start(struct obd_export
*exp
,
1595 struct lustre_kernelcomm
*lk
);
1597 static int mdc_quotacheck(struct obd_device
*unused
, struct obd_export
*exp
,
1598 struct obd_quotactl
*oqctl
)
1600 struct client_obd
*cli
= &exp
->exp_obd
->u
.cli
;
1601 struct ptlrpc_request
*req
;
1602 struct obd_quotactl
*body
;
1605 req
= ptlrpc_request_alloc_pack(class_exp2cliimp(exp
),
1606 &RQF_MDS_QUOTACHECK
, LUSTRE_MDS_VERSION
,
1611 body
= req_capsule_client_get(&req
->rq_pill
, &RMF_OBD_QUOTACTL
);
1614 ptlrpc_request_set_replen(req
);
1616 /* the next poll will find -ENODATA, that means quotacheck is
1619 cli
->cl_qchk_stat
= -ENODATA
;
1620 rc
= ptlrpc_queue_wait(req
);
1622 cli
->cl_qchk_stat
= rc
;
1623 ptlrpc_req_finished(req
);
1627 static int mdc_quota_poll_check(struct obd_export
*exp
,
1628 struct if_quotacheck
*qchk
)
1630 struct client_obd
*cli
= &exp
->exp_obd
->u
.cli
;
1633 qchk
->obd_uuid
= cli
->cl_target_uuid
;
1634 memcpy(qchk
->obd_type
, LUSTRE_MDS_NAME
, strlen(LUSTRE_MDS_NAME
));
1636 rc
= cli
->cl_qchk_stat
;
1637 /* the client is not the previous one */
1638 if (rc
== CL_NOT_QUOTACHECKED
)
1643 static int mdc_quotactl(struct obd_device
*unused
, struct obd_export
*exp
,
1644 struct obd_quotactl
*oqctl
)
1646 struct ptlrpc_request
*req
;
1647 struct obd_quotactl
*oqc
;
1650 req
= ptlrpc_request_alloc_pack(class_exp2cliimp(exp
),
1651 &RQF_MDS_QUOTACTL
, LUSTRE_MDS_VERSION
,
1656 oqc
= req_capsule_client_get(&req
->rq_pill
, &RMF_OBD_QUOTACTL
);
1659 ptlrpc_request_set_replen(req
);
1660 ptlrpc_at_set_req_timeout(req
);
1661 req
->rq_no_resend
= 1;
1663 rc
= ptlrpc_queue_wait(req
);
1665 CERROR("ptlrpc_queue_wait failed, rc: %d\n", rc
);
1667 if (req
->rq_repmsg
) {
1668 oqc
= req_capsule_server_get(&req
->rq_pill
, &RMF_OBD_QUOTACTL
);
1672 CERROR("Can't unpack obd_quotactl\n");
1676 CERROR("Can't unpack obd_quotactl\n");
1679 ptlrpc_req_finished(req
);
1684 static int mdc_ioc_swap_layouts(struct obd_export
*exp
,
1685 struct md_op_data
*op_data
)
1688 struct ptlrpc_request
*req
;
1690 struct mdc_swap_layouts
*msl
, *payload
;
1692 msl
= op_data
->op_data
;
1694 /* When the MDT will get the MDS_SWAP_LAYOUTS RPC the
1695 * first thing it will do is to cancel the 2 layout
1696 * locks hold by this client.
1697 * So the client must cancel its layout locks on the 2 fids
1698 * with the request RPC to avoid extra RPC round trips
1700 count
= mdc_resource_get_unused(exp
, &op_data
->op_fid1
, &cancels
,
1701 LCK_CR
, MDS_INODELOCK_LAYOUT
);
1702 count
+= mdc_resource_get_unused(exp
, &op_data
->op_fid2
, &cancels
,
1703 LCK_CR
, MDS_INODELOCK_LAYOUT
);
1705 req
= ptlrpc_request_alloc(class_exp2cliimp(exp
),
1706 &RQF_MDS_SWAP_LAYOUTS
);
1708 ldlm_lock_list_put(&cancels
, l_bl_ast
, count
);
1712 rc
= mdc_prep_elc_req(exp
, req
, MDS_SWAP_LAYOUTS
, &cancels
, count
);
1714 ptlrpc_request_free(req
);
1718 mdc_swap_layouts_pack(req
, op_data
);
1720 payload
= req_capsule_client_get(&req
->rq_pill
, &RMF_SWAP_LAYOUTS
);
1725 ptlrpc_request_set_replen(req
);
1727 rc
= ptlrpc_queue_wait(req
);
1729 ptlrpc_req_finished(req
);
1733 static int mdc_iocontrol(unsigned int cmd
, struct obd_export
*exp
, int len
,
1734 void *karg
, void __user
*uarg
)
1736 struct obd_device
*obd
= exp
->exp_obd
;
1737 struct obd_ioctl_data
*data
= karg
;
1738 struct obd_import
*imp
= obd
->u
.cli
.cl_import
;
1741 if (!try_module_get(THIS_MODULE
)) {
1742 CERROR("%s: cannot get module '%s'\n", obd
->obd_name
,
1743 module_name(THIS_MODULE
));
1747 case OBD_IOC_CHANGELOG_SEND
:
1748 rc
= mdc_ioc_changelog_send(obd
, karg
);
1750 case OBD_IOC_CHANGELOG_CLEAR
: {
1751 struct ioc_changelog
*icc
= karg
;
1752 struct changelog_setinfo cs
= {
1753 .cs_recno
= icc
->icc_recno
,
1754 .cs_id
= icc
->icc_id
1757 rc
= obd_set_info_async(NULL
, exp
, strlen(KEY_CHANGELOG_CLEAR
),
1758 KEY_CHANGELOG_CLEAR
, sizeof(cs
), &cs
,
1762 case OBD_IOC_FID2PATH
:
1763 rc
= mdc_ioc_fid2path(exp
, karg
);
1765 case LL_IOC_HSM_CT_START
:
1766 rc
= mdc_ioc_hsm_ct_start(exp
, karg
);
1767 /* ignore if it was already registered on this MDS. */
1771 case LL_IOC_HSM_PROGRESS
:
1772 rc
= mdc_ioc_hsm_progress(exp
, karg
);
1774 case LL_IOC_HSM_STATE_GET
:
1775 rc
= mdc_ioc_hsm_state_get(exp
, karg
);
1777 case LL_IOC_HSM_STATE_SET
:
1778 rc
= mdc_ioc_hsm_state_set(exp
, karg
);
1780 case LL_IOC_HSM_ACTION
:
1781 rc
= mdc_ioc_hsm_current_action(exp
, karg
);
1783 case LL_IOC_HSM_REQUEST
:
1784 rc
= mdc_ioc_hsm_request(exp
, karg
);
1786 case OBD_IOC_CLIENT_RECOVER
:
1787 rc
= ptlrpc_recover_import(imp
, data
->ioc_inlbuf1
, 0);
1792 case IOC_OSC_SET_ACTIVE
:
1793 rc
= ptlrpc_set_import_active(imp
, data
->ioc_offset
);
1795 case OBD_IOC_POLL_QUOTACHECK
:
1796 rc
= mdc_quota_poll_check(exp
, (struct if_quotacheck
*)karg
);
1798 case OBD_IOC_PING_TARGET
:
1799 rc
= ptlrpc_obd_ping(obd
);
1802 * Normally IOC_OBD_STATFS, OBD_IOC_QUOTACTL iocontrol are handled by
1803 * LMV instead of MDC. But when the cluster is upgraded from 1.8,
1804 * there'd be no LMV layer thus we might be called here. Eventually
1805 * this code should be removed.
1808 case IOC_OBD_STATFS
: {
1809 struct obd_statfs stat_buf
= {0};
1811 if (*((__u32
*) data
->ioc_inlbuf2
) != 0) {
1817 if (copy_to_user(data
->ioc_pbuf2
, obd2cli_tgt(obd
),
1818 min_t(size_t, data
->ioc_plen2
,
1819 sizeof(struct obd_uuid
)))) {
1824 rc
= mdc_statfs(NULL
, obd
->obd_self_export
, &stat_buf
,
1825 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS
),
1830 if (copy_to_user(data
->ioc_pbuf1
, &stat_buf
,
1831 min_t(size_t, data
->ioc_plen1
,
1832 sizeof(stat_buf
)))) {
1840 case OBD_IOC_QUOTACTL
: {
1841 struct if_quotactl
*qctl
= karg
;
1842 struct obd_quotactl
*oqctl
;
1844 oqctl
= kzalloc(sizeof(*oqctl
), GFP_NOFS
);
1850 QCTL_COPY(oqctl
, qctl
);
1851 rc
= obd_quotactl(exp
, oqctl
);
1853 QCTL_COPY(qctl
, oqctl
);
1854 qctl
->qc_valid
= QC_MDTIDX
;
1855 qctl
->obd_uuid
= obd
->u
.cli
.cl_target_uuid
;
1861 case LL_IOC_GET_CONNECT_FLAGS
:
1862 if (copy_to_user(uarg
, exp_connect_flags_ptr(exp
),
1863 sizeof(*exp_connect_flags_ptr(exp
)))) {
1870 case LL_IOC_LOV_SWAP_LAYOUTS
:
1871 rc
= mdc_ioc_swap_layouts(exp
, karg
);
1874 CERROR("unrecognised ioctl: cmd = %#x\n", cmd
);
1879 module_put(THIS_MODULE
);
1884 static int mdc_get_info_rpc(struct obd_export
*exp
,
1885 u32 keylen
, void *key
,
1886 int vallen
, void *val
)
1888 struct obd_import
*imp
= class_exp2cliimp(exp
);
1889 struct ptlrpc_request
*req
;
1893 req
= ptlrpc_request_alloc(imp
, &RQF_MDS_GET_INFO
);
1897 req_capsule_set_size(&req
->rq_pill
, &RMF_GETINFO_KEY
,
1898 RCL_CLIENT
, keylen
);
1899 req_capsule_set_size(&req
->rq_pill
, &RMF_GETINFO_VALLEN
,
1900 RCL_CLIENT
, sizeof(__u32
));
1902 rc
= ptlrpc_request_pack(req
, LUSTRE_MDS_VERSION
, MDS_GET_INFO
);
1904 ptlrpc_request_free(req
);
1908 tmp
= req_capsule_client_get(&req
->rq_pill
, &RMF_GETINFO_KEY
);
1909 memcpy(tmp
, key
, keylen
);
1910 tmp
= req_capsule_client_get(&req
->rq_pill
, &RMF_GETINFO_VALLEN
);
1911 memcpy(tmp
, &vallen
, sizeof(__u32
));
1913 req_capsule_set_size(&req
->rq_pill
, &RMF_GETINFO_VAL
,
1914 RCL_SERVER
, vallen
);
1915 ptlrpc_request_set_replen(req
);
1917 rc
= ptlrpc_queue_wait(req
);
1918 /* -EREMOTE means the get_info result is partial, and it needs to
1919 * continue on another MDT, see fid2path part in lmv_iocontrol
1921 if (rc
== 0 || rc
== -EREMOTE
) {
1922 tmp
= req_capsule_server_get(&req
->rq_pill
, &RMF_GETINFO_VAL
);
1923 memcpy(val
, tmp
, vallen
);
1924 if (ptlrpc_rep_need_swab(req
)) {
1925 if (KEY_IS(KEY_FID2PATH
))
1926 lustre_swab_fid2path(val
);
1929 ptlrpc_req_finished(req
);
1934 static void lustre_swab_hai(struct hsm_action_item
*h
)
1936 __swab32s(&h
->hai_len
);
1937 __swab32s(&h
->hai_action
);
1938 lustre_swab_lu_fid(&h
->hai_fid
);
1939 lustre_swab_lu_fid(&h
->hai_dfid
);
1940 __swab64s(&h
->hai_cookie
);
1941 __swab64s(&h
->hai_extent
.offset
);
1942 __swab64s(&h
->hai_extent
.length
);
1943 __swab64s(&h
->hai_gid
);
1946 static void lustre_swab_hal(struct hsm_action_list
*h
)
1948 struct hsm_action_item
*hai
;
1951 __swab32s(&h
->hal_version
);
1952 __swab32s(&h
->hal_count
);
1953 __swab32s(&h
->hal_archive_id
);
1954 __swab64s(&h
->hal_flags
);
1956 for (i
= 0; i
< h
->hal_count
; i
++, hai
= hai_next(hai
))
1957 lustre_swab_hai(hai
);
1960 static void lustre_swab_kuch(struct kuc_hdr
*l
)
1962 __swab16s(&l
->kuc_magic
);
1963 /* __u8 l->kuc_transport */
1964 __swab16s(&l
->kuc_msgtype
);
1965 __swab16s(&l
->kuc_msglen
);
1968 static int mdc_ioc_hsm_ct_start(struct obd_export
*exp
,
1969 struct lustre_kernelcomm
*lk
)
1971 struct obd_import
*imp
= class_exp2cliimp(exp
);
1972 __u32 archive
= lk
->lk_data
;
1975 if (lk
->lk_group
!= KUC_GRP_HSM
) {
1976 CERROR("Bad copytool group %d\n", lk
->lk_group
);
1980 CDEBUG(D_HSM
, "CT start r%d w%d u%d g%d f%#x\n", lk
->lk_rfd
, lk
->lk_wfd
,
1981 lk
->lk_uid
, lk
->lk_group
, lk
->lk_flags
);
1983 if (lk
->lk_flags
& LK_FLG_STOP
) {
1984 /* Unregister with the coordinator */
1985 rc
= mdc_ioc_hsm_ct_unregister(imp
);
1987 rc
= mdc_ioc_hsm_ct_register(imp
, archive
);
1994 * Send a message to any listening copytools
1995 * @param val KUC message (kuc_hdr + hsm_action_list)
1996 * @param len total length of message
1998 static int mdc_hsm_copytool_send(int len
, void *val
)
2000 struct kuc_hdr
*lh
= (struct kuc_hdr
*)val
;
2001 struct hsm_action_list
*hal
= (struct hsm_action_list
*)(lh
+ 1);
2003 if (len
< sizeof(*lh
) + sizeof(*hal
)) {
2004 CERROR("Short HSM message %d < %d\n", len
,
2005 (int) (sizeof(*lh
) + sizeof(*hal
)));
2008 if (lh
->kuc_magic
== __swab16(KUC_MAGIC
)) {
2009 lustre_swab_kuch(lh
);
2010 lustre_swab_hal(hal
);
2011 } else if (lh
->kuc_magic
!= KUC_MAGIC
) {
2012 CERROR("Bad magic %x!=%x\n", lh
->kuc_magic
, KUC_MAGIC
);
2017 "Received message mg=%x t=%d m=%d l=%d actions=%d on %s\n",
2018 lh
->kuc_magic
, lh
->kuc_transport
, lh
->kuc_msgtype
,
2019 lh
->kuc_msglen
, hal
->hal_count
, hal
->hal_fsname
);
2021 /* Broadcast to HSM listeners */
2022 return libcfs_kkuc_group_put(KUC_GRP_HSM
, lh
);
2026 * callback function passed to kuc for re-registering each HSM copytool
2027 * running on MDC, after MDT shutdown/recovery.
2028 * @param data copytool registration data
2029 * @param cb_arg callback argument (obd_import)
2031 static int mdc_hsm_ct_reregister(void *data
, void *cb_arg
)
2033 struct kkuc_ct_data
*kcd
= data
;
2034 struct obd_import
*imp
= (struct obd_import
*)cb_arg
;
2037 if (!kcd
|| kcd
->kcd_magic
!= KKUC_CT_DATA_MAGIC
)
2040 if (!obd_uuid_equals(&kcd
->kcd_uuid
, &imp
->imp_obd
->obd_uuid
))
2043 CDEBUG(D_HA
, "%s: recover copytool registration to MDT (archive=%#x)\n",
2044 imp
->imp_obd
->obd_name
, kcd
->kcd_archive
);
2045 rc
= mdc_ioc_hsm_ct_register(imp
, kcd
->kcd_archive
);
2047 /* ignore error if the copytool is already registered */
2048 return (rc
== -EEXIST
) ? 0 : rc
;
2051 static int mdc_set_info_async(const struct lu_env
*env
,
2052 struct obd_export
*exp
,
2053 u32 keylen
, void *key
,
2054 u32 vallen
, void *val
,
2055 struct ptlrpc_request_set
*set
)
2057 struct obd_import
*imp
= class_exp2cliimp(exp
);
2060 if (KEY_IS(KEY_READ_ONLY
)) {
2061 if (vallen
!= sizeof(int))
2064 spin_lock(&imp
->imp_lock
);
2065 if (*((int *)val
)) {
2066 imp
->imp_connect_flags_orig
|= OBD_CONNECT_RDONLY
;
2067 imp
->imp_connect_data
.ocd_connect_flags
|=
2070 imp
->imp_connect_flags_orig
&= ~OBD_CONNECT_RDONLY
;
2071 imp
->imp_connect_data
.ocd_connect_flags
&=
2072 ~OBD_CONNECT_RDONLY
;
2074 spin_unlock(&imp
->imp_lock
);
2076 rc
= do_set_info_async(imp
, MDS_SET_INFO
, LUSTRE_MDS_VERSION
,
2077 keylen
, key
, vallen
, val
, set
);
2080 if (KEY_IS(KEY_SPTLRPC_CONF
)) {
2081 sptlrpc_conf_client_adapt(exp
->exp_obd
);
2084 if (KEY_IS(KEY_FLUSH_CTX
)) {
2085 sptlrpc_import_flush_my_ctx(imp
);
2088 if (KEY_IS(KEY_CHANGELOG_CLEAR
)) {
2089 rc
= do_set_info_async(imp
, MDS_SET_INFO
, LUSTRE_MDS_VERSION
,
2090 keylen
, key
, vallen
, val
, set
);
2093 if (KEY_IS(KEY_HSM_COPYTOOL_SEND
)) {
2094 rc
= mdc_hsm_copytool_send(vallen
, val
);
2098 CERROR("Unknown key %s\n", (char *)key
);
2102 static int mdc_get_info(const struct lu_env
*env
, struct obd_export
*exp
,
2103 __u32 keylen
, void *key
, __u32
*vallen
, void *val
,
2104 struct lov_stripe_md
*lsm
)
2108 if (KEY_IS(KEY_MAX_EASIZE
)) {
2109 int mdsize
, *max_easize
;
2111 if (*vallen
!= sizeof(int))
2113 mdsize
= *(int *)val
;
2114 if (mdsize
> exp
->exp_obd
->u
.cli
.cl_max_mds_easize
)
2115 exp
->exp_obd
->u
.cli
.cl_max_mds_easize
= mdsize
;
2117 *max_easize
= exp
->exp_obd
->u
.cli
.cl_max_mds_easize
;
2119 } else if (KEY_IS(KEY_DEFAULT_EASIZE
)) {
2120 int *default_easize
;
2122 if (*vallen
!= sizeof(int))
2124 default_easize
= val
;
2125 *default_easize
= exp
->exp_obd
->u
.cli
.cl_default_mds_easize
;
2127 } else if (KEY_IS(KEY_CONN_DATA
)) {
2128 struct obd_import
*imp
= class_exp2cliimp(exp
);
2129 struct obd_connect_data
*data
= val
;
2131 if (*vallen
!= sizeof(*data
))
2134 *data
= imp
->imp_connect_data
;
2136 } else if (KEY_IS(KEY_TGT_COUNT
)) {
2141 rc
= mdc_get_info_rpc(exp
, keylen
, key
, *vallen
, val
);
2146 static int mdc_sync(struct obd_export
*exp
, const struct lu_fid
*fid
,
2147 struct ptlrpc_request
**request
)
2149 struct ptlrpc_request
*req
;
2153 req
= ptlrpc_request_alloc(class_exp2cliimp(exp
), &RQF_MDS_SYNC
);
2157 rc
= ptlrpc_request_pack(req
, LUSTRE_MDS_VERSION
, MDS_SYNC
);
2159 ptlrpc_request_free(req
);
2163 mdc_pack_body(req
, fid
, 0, 0, -1, 0);
2165 ptlrpc_request_set_replen(req
);
2167 rc
= ptlrpc_queue_wait(req
);
2169 ptlrpc_req_finished(req
);
2175 static int mdc_import_event(struct obd_device
*obd
, struct obd_import
*imp
,
2176 enum obd_import_event event
)
2180 LASSERT(imp
->imp_obd
== obd
);
2183 case IMP_EVENT_DISCON
: {
2185 /* XXX Pass event up to OBDs stack. used only for FLD now */
2186 rc
= obd_notify_observer(obd
, obd
, OBD_NOTIFY_DISCON
, NULL
);
2190 case IMP_EVENT_INACTIVE
: {
2191 struct client_obd
*cli
= &obd
->u
.cli
;
2193 * Flush current sequence to make client obtain new one
2194 * from server in case of disconnect/reconnect.
2197 seq_client_flush(cli
->cl_seq
);
2199 rc
= obd_notify_observer(obd
, obd
, OBD_NOTIFY_INACTIVE
, NULL
);
2202 case IMP_EVENT_INVALIDATE
: {
2203 struct ldlm_namespace
*ns
= obd
->obd_namespace
;
2205 ldlm_namespace_cleanup(ns
, LDLM_FL_LOCAL_ONLY
);
2209 case IMP_EVENT_ACTIVE
:
2210 rc
= obd_notify_observer(obd
, obd
, OBD_NOTIFY_ACTIVE
, NULL
);
2211 /* redo the kuc registration after reconnecting */
2213 /* re-register HSM agents */
2214 rc
= libcfs_kkuc_group_foreach(KUC_GRP_HSM
,
2215 mdc_hsm_ct_reregister
,
2219 rc
= obd_notify_observer(obd
, obd
, OBD_NOTIFY_OCD
, NULL
);
2221 case IMP_EVENT_DEACTIVATE
:
2222 case IMP_EVENT_ACTIVATE
:
2225 CERROR("Unknown import event %x\n", event
);
2231 int mdc_fid_alloc(struct obd_export
*exp
, struct lu_fid
*fid
,
2232 struct md_op_data
*op_data
)
2234 struct client_obd
*cli
= &exp
->exp_obd
->u
.cli
;
2235 struct lu_client_seq
*seq
= cli
->cl_seq
;
2237 return seq_client_alloc_fid(NULL
, seq
, fid
);
2240 static struct obd_uuid
*mdc_get_uuid(struct obd_export
*exp
)
2242 struct client_obd
*cli
= &exp
->exp_obd
->u
.cli
;
2244 return &cli
->cl_target_uuid
;
2248 * Determine whether the lock can be canceled before replaying it during
2249 * recovery, non zero value will be return if the lock can be canceled,
2250 * or zero returned for not
2252 static int mdc_cancel_for_recovery(struct ldlm_lock
*lock
)
2254 if (lock
->l_resource
->lr_type
!= LDLM_IBITS
)
2257 /* FIXME: if we ever get into a situation where there are too many
2258 * opened files with open locks on a single node, then we really
2259 * should replay these open locks to reget it
2261 if (lock
->l_policy_data
.l_inodebits
.bits
& MDS_INODELOCK_OPEN
)
2267 static int mdc_resource_inode_free(struct ldlm_resource
*res
)
2269 if (res
->lr_lvb_inode
)
2270 res
->lr_lvb_inode
= NULL
;
2275 static struct ldlm_valblock_ops inode_lvbo
= {
2276 .lvbo_free
= mdc_resource_inode_free
,
2279 static int mdc_llog_init(struct obd_device
*obd
)
2281 struct obd_llog_group
*olg
= &obd
->obd_olg
;
2282 struct llog_ctxt
*ctxt
;
2285 rc
= llog_setup(NULL
, obd
, olg
, LLOG_CHANGELOG_REPL_CTXT
, obd
,
2290 ctxt
= llog_group_get_ctxt(olg
, LLOG_CHANGELOG_REPL_CTXT
);
2291 llog_initiator_connect(ctxt
);
2292 llog_ctxt_put(ctxt
);
2297 static void mdc_llog_finish(struct obd_device
*obd
)
2299 struct llog_ctxt
*ctxt
;
2301 ctxt
= llog_get_context(obd
, LLOG_CHANGELOG_REPL_CTXT
);
2303 llog_cleanup(NULL
, ctxt
);
2306 static int mdc_setup(struct obd_device
*obd
, struct lustre_cfg
*cfg
)
2308 struct client_obd
*cli
= &obd
->u
.cli
;
2309 struct lprocfs_static_vars lvars
= { NULL
};
2312 cli
->cl_rpc_lock
= kzalloc(sizeof(*cli
->cl_rpc_lock
), GFP_NOFS
);
2313 if (!cli
->cl_rpc_lock
)
2315 mdc_init_rpc_lock(cli
->cl_rpc_lock
);
2319 cli
->cl_close_lock
= kzalloc(sizeof(*cli
->cl_close_lock
), GFP_NOFS
);
2320 if (!cli
->cl_close_lock
) {
2324 mdc_init_rpc_lock(cli
->cl_close_lock
);
2326 rc
= client_obd_setup(obd
, cfg
);
2328 goto err_close_lock
;
2329 lprocfs_mdc_init_vars(&lvars
);
2330 lprocfs_obd_setup(obd
, lvars
.obd_vars
, lvars
.sysfs_vars
);
2331 sptlrpc_lprocfs_cliobd_attach(obd
);
2332 ptlrpc_lprocfs_register_obd(obd
);
2334 ns_register_cancel(obd
->obd_namespace
, mdc_cancel_for_recovery
);
2336 obd
->obd_namespace
->ns_lvbo
= &inode_lvbo
;
2338 rc
= mdc_llog_init(obd
);
2341 CERROR("failed to setup llogging subsystems\n");
2347 kfree(cli
->cl_close_lock
);
2349 kfree(cli
->cl_rpc_lock
);
2354 /* Initialize the default and maximum LOV EA and cookie sizes. This allows
2355 * us to make MDS RPCs with large enough reply buffers to hold a default
2356 * sized EA and cookie without having to calculate this (via a call into the
2357 * LOV + OSCs) each time we make an RPC. The maximum size is also tracked
2358 * but not used to avoid wastefully vmalloc()'ing large reply buffers when
2359 * a large number of stripes is possible. If a larger reply buffer is
2360 * required it will be reallocated in the ptlrpc layer due to overflow.
2362 static int mdc_init_ea_size(struct obd_export
*exp
, int easize
,
2363 int def_easize
, int cookiesize
, int def_cookiesize
)
2365 struct obd_device
*obd
= exp
->exp_obd
;
2366 struct client_obd
*cli
= &obd
->u
.cli
;
2368 if (cli
->cl_max_mds_easize
< easize
)
2369 cli
->cl_max_mds_easize
= easize
;
2371 if (cli
->cl_default_mds_easize
< def_easize
)
2372 cli
->cl_default_mds_easize
= def_easize
;
2374 if (cli
->cl_max_mds_cookiesize
< cookiesize
)
2375 cli
->cl_max_mds_cookiesize
= cookiesize
;
2377 if (cli
->cl_default_mds_cookiesize
< def_cookiesize
)
2378 cli
->cl_default_mds_cookiesize
= def_cookiesize
;
2383 static int mdc_precleanup(struct obd_device
*obd
, enum obd_cleanup_stage stage
)
2386 case OBD_CLEANUP_EARLY
:
2388 case OBD_CLEANUP_EXPORTS
:
2389 /* Failsafe, ok if racy */
2390 if (obd
->obd_type
->typ_refcnt
<= 1)
2391 libcfs_kkuc_group_rem(0, KUC_GRP_HSM
);
2393 obd_cleanup_client_import(obd
);
2394 ptlrpc_lprocfs_unregister_obd(obd
);
2395 lprocfs_obd_cleanup(obd
);
2397 mdc_llog_finish(obd
);
2403 static int mdc_cleanup(struct obd_device
*obd
)
2405 struct client_obd
*cli
= &obd
->u
.cli
;
2407 kfree(cli
->cl_rpc_lock
);
2408 kfree(cli
->cl_close_lock
);
2412 return client_obd_cleanup(obd
);
2415 static int mdc_process_config(struct obd_device
*obd
, u32 len
, void *buf
)
2417 struct lustre_cfg
*lcfg
= buf
;
2418 struct lprocfs_static_vars lvars
= { NULL
};
2421 lprocfs_mdc_init_vars(&lvars
);
2422 switch (lcfg
->lcfg_command
) {
2424 rc
= class_process_proc_param(PARAM_MDC
, lvars
.obd_vars
,
2433 /* get remote permission for current user on fid */
2434 static int mdc_get_remote_perm(struct obd_export
*exp
, const struct lu_fid
*fid
,
2435 __u32 suppgid
, struct ptlrpc_request
**request
)
2437 struct ptlrpc_request
*req
;
2440 LASSERT(client_is_remote(exp
));
2443 req
= ptlrpc_request_alloc(class_exp2cliimp(exp
), &RQF_MDS_GETATTR
);
2447 rc
= ptlrpc_request_pack(req
, LUSTRE_MDS_VERSION
, MDS_GETATTR
);
2449 ptlrpc_request_free(req
);
2453 mdc_pack_body(req
, fid
, OBD_MD_FLRMTPERM
, 0, suppgid
, 0);
2455 req_capsule_set_size(&req
->rq_pill
, &RMF_ACL
, RCL_SERVER
,
2456 sizeof(struct mdt_remote_perm
));
2458 ptlrpc_request_set_replen(req
);
2460 rc
= ptlrpc_queue_wait(req
);
2462 ptlrpc_req_finished(req
);
2468 static struct obd_ops mdc_obd_ops
= {
2469 .owner
= THIS_MODULE
,
2471 .precleanup
= mdc_precleanup
,
2472 .cleanup
= mdc_cleanup
,
2473 .add_conn
= client_import_add_conn
,
2474 .del_conn
= client_import_del_conn
,
2475 .connect
= client_connect_import
,
2476 .disconnect
= client_disconnect_export
,
2477 .iocontrol
= mdc_iocontrol
,
2478 .set_info_async
= mdc_set_info_async
,
2479 .statfs
= mdc_statfs
,
2480 .fid_init
= client_fid_init
,
2481 .fid_fini
= client_fid_fini
,
2482 .fid_alloc
= mdc_fid_alloc
,
2483 .import_event
= mdc_import_event
,
2484 .get_info
= mdc_get_info
,
2485 .process_config
= mdc_process_config
,
2486 .get_uuid
= mdc_get_uuid
,
2487 .quotactl
= mdc_quotactl
,
2488 .quotacheck
= mdc_quotacheck
2491 static struct md_ops mdc_md_ops
= {
2492 .getstatus
= mdc_getstatus
,
2493 .null_inode
= mdc_null_inode
,
2494 .find_cbdata
= mdc_find_cbdata
,
2496 .create
= mdc_create
,
2497 .done_writing
= mdc_done_writing
,
2498 .enqueue
= mdc_enqueue
,
2499 .getattr
= mdc_getattr
,
2500 .getattr_name
= mdc_getattr_name
,
2501 .intent_lock
= mdc_intent_lock
,
2503 .is_subdir
= mdc_is_subdir
,
2504 .rename
= mdc_rename
,
2505 .setattr
= mdc_setattr
,
2506 .setxattr
= mdc_setxattr
,
2507 .getxattr
= mdc_getxattr
,
2509 .readpage
= mdc_readpage
,
2510 .unlink
= mdc_unlink
,
2511 .cancel_unused
= mdc_cancel_unused
,
2512 .init_ea_size
= mdc_init_ea_size
,
2513 .set_lock_data
= mdc_set_lock_data
,
2514 .lock_match
= mdc_lock_match
,
2515 .get_lustre_md
= mdc_get_lustre_md
,
2516 .free_lustre_md
= mdc_free_lustre_md
,
2517 .set_open_replay_data
= mdc_set_open_replay_data
,
2518 .clear_open_replay_data
= mdc_clear_open_replay_data
,
2519 .get_remote_perm
= mdc_get_remote_perm
,
2520 .intent_getattr_async
= mdc_intent_getattr_async
,
2521 .revalidate_lock
= mdc_revalidate_lock
2524 static int __init
mdc_init(void)
2526 struct lprocfs_static_vars lvars
= { NULL
};
2528 lprocfs_mdc_init_vars(&lvars
);
2530 return class_register_type(&mdc_obd_ops
, &mdc_md_ops
,
2531 LUSTRE_MDC_NAME
, NULL
);
2534 static void /*__exit*/ mdc_exit(void)
2536 class_unregister_type(LUSTRE_MDC_NAME
);
2539 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
2540 MODULE_DESCRIPTION("Lustre Metadata Client");
2541 MODULE_VERSION(LUSTRE_VERSION_STRING
);
2542 MODULE_LICENSE("GPL");
2544 module_init(mdc_init
);
2545 module_exit(mdc_exit
);