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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 #define DEBUG_SUBSYSTEM S_LMV
34 #include <linux/slab.h>
35 #include <linux/module.h>
36 #include <linux/init.h>
37 #include <linux/user_namespace.h>
38 #ifdef HAVE_UIDGID_HEADER
39 # include <linux/uidgid.h>
41 #include <linux/slab.h>
42 #include <linux/pagemap.h>
44 #include <linux/math64.h>
45 #include <linux/seq_file.h>
46 #include <linux/namei.h>
48 #include <lustre/lustre_idl.h>
49 #include <obd_support.h>
50 #include <lustre_lib.h>
51 #include <lustre_net.h>
52 #include <obd_class.h>
53 #include <lustre_lmv.h>
54 #include <lprocfs_status.h>
55 #include <cl_object.h>
56 #include <lustre_fid.h>
57 #include <lustre_ioctl.h>
58 #include <lustre_kernelcomm.h>
59 #include "lmv_internal.h"
61 static int lmv_check_connect(struct obd_device *obd);
63 static void lmv_activate_target(struct lmv_obd *lmv,
64 struct lmv_tgt_desc *tgt,
67 if (tgt->ltd_active == activate)
70 tgt->ltd_active = activate;
71 lmv->desc.ld_active_tgt_count += (activate ? 1 : -1);
73 tgt->ltd_exp->exp_obd->obd_inactive = !activate;
79 * -EINVAL : UUID can't be found in the LMV's target list
80 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
81 * -EBADF : The UUID is found, but the OBD of the wrong type (!)
83 static int lmv_set_mdc_active(struct lmv_obd *lmv,
84 const struct obd_uuid *uuid,
87 struct lmv_tgt_desc *tgt = NULL;
88 struct obd_device *obd;
93 CDEBUG(D_INFO, "Searching in lmv %p for uuid %s (activate=%d)\n",
94 lmv, uuid->uuid, activate);
96 spin_lock(&lmv->lmv_lock);
97 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
99 if (tgt == NULL || tgt->ltd_exp == NULL)
102 CDEBUG(D_INFO, "Target idx %d is %s conn %#llx\n", i,
103 tgt->ltd_uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
105 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
109 if (i == lmv->desc.ld_tgt_count)
110 GOTO(out_lmv_lock, rc = -EINVAL);
112 obd = class_exp2obd(tgt->ltd_exp);
114 GOTO(out_lmv_lock, rc = -ENOTCONN);
116 CDEBUG(D_INFO, "Found OBD %s=%s device %d (%p) type %s at LMV idx %d\n",
117 obd->obd_name, obd->obd_uuid.uuid, obd->obd_minor, obd,
118 obd->obd_type->typ_name, i);
119 LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0);
121 if (tgt->ltd_active == activate) {
122 CDEBUG(D_INFO, "OBD %p already %sactive!\n", obd,
123 activate ? "" : "in");
124 GOTO(out_lmv_lock, rc);
127 CDEBUG(D_INFO, "Marking OBD %p %sactive\n", obd,
128 activate ? "" : "in");
129 lmv_activate_target(lmv, tgt, activate);
133 spin_unlock(&lmv->lmv_lock);
137 struct obd_uuid *lmv_get_uuid(struct obd_export *exp)
139 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
140 struct lmv_tgt_desc *tgt = lmv->tgts[0];
142 return (tgt == NULL) ? NULL : obd_get_uuid(tgt->ltd_exp);
145 static int lmv_notify(struct obd_device *obd, struct obd_device *watched,
146 enum obd_notify_event ev, void *data)
148 struct obd_connect_data *conn_data;
149 struct lmv_obd *lmv = &obd->u.lmv;
150 struct obd_uuid *uuid;
154 if (strcmp(watched->obd_type->typ_name, LUSTRE_MDC_NAME)) {
155 CERROR("unexpected notification of %s %s!\n",
156 watched->obd_type->typ_name,
161 uuid = &watched->u.cli.cl_target_uuid;
162 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE) {
164 * Set MDC as active before notifying the observer, so the
165 * observer can use the MDC normally.
167 rc = lmv_set_mdc_active(lmv, uuid,
168 ev == OBD_NOTIFY_ACTIVE);
170 CERROR("%sactivation of %s failed: %d\n",
171 ev == OBD_NOTIFY_ACTIVE ? "" : "de",
175 } else if (ev == OBD_NOTIFY_OCD) {
176 conn_data = &watched->u.cli.cl_import->imp_connect_data;
178 * XXX: Make sure that ocd_connect_flags from all targets are
179 * the same. Otherwise one of MDTs runs wrong version or
180 * something like this. --umka
182 obd->obd_self_export->exp_connect_data = *conn_data;
186 * Pass the notification up the chain.
188 if (obd->obd_observer)
189 rc = obd_notify(obd->obd_observer, watched, ev, data);
194 static int lmv_connect(const struct lu_env *env,
195 struct obd_export **pexp, struct obd_device *obd,
196 struct obd_uuid *cluuid, struct obd_connect_data *data,
199 struct lmv_obd *lmv = &obd->u.lmv;
200 struct lustre_handle conn = { 0 };
201 struct obd_export *exp;
205 rc = class_connect(&conn, obd, cluuid);
207 CERROR("class_connection() returned %d\n", rc);
211 exp = class_conn2export(&conn);
214 lmv->cluuid = *cluuid;
215 lmv->conn_data = *data;
217 if (lmv->targets_proc_entry == NULL) {
218 lmv->targets_proc_entry = lprocfs_register("target_obds",
221 if (IS_ERR(lmv->targets_proc_entry)) {
222 CERROR("%s: cannot register "
223 "/proc/fs/lustre/%s/%s/target_obds\n",
224 obd->obd_name, obd->obd_type->typ_name,
226 lmv->targets_proc_entry = NULL;
230 rc = lmv_check_connect(obd);
239 if (lmv->targets_proc_entry != NULL)
240 lprocfs_remove(&lmv->targets_proc_entry);
242 class_disconnect(exp);
247 static int lmv_init_ea_size(struct obd_export *exp, __u32 easize,
250 struct obd_device *obd = exp->exp_obd;
251 struct lmv_obd *lmv = &obd->u.lmv;
257 if (lmv->max_easize < easize) {
258 lmv->max_easize = easize;
261 if (lmv->max_def_easize < def_easize) {
262 lmv->max_def_easize = def_easize;
269 if (lmv->connected == 0)
272 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
273 struct lmv_tgt_desc *tgt = lmv->tgts[i];
275 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active) {
276 CWARN("%s: NULL export for %d\n", obd->obd_name, i);
280 rc = md_init_ea_size(tgt->ltd_exp, easize, def_easize);
282 CERROR("%s: obd_init_ea_size() failed on MDT target %d:"
283 " rc = %d\n", obd->obd_name, i, rc);
290 #define MAX_STRING_SIZE 128
292 int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
294 struct lmv_obd *lmv = &obd->u.lmv;
295 struct obd_uuid *cluuid = &lmv->cluuid;
296 struct obd_uuid lmv_mdc_uuid = { "LMV_MDC_UUID" };
297 struct obd_device *mdc_obd;
298 struct obd_export *mdc_exp;
299 struct lu_fld_target target;
303 mdc_obd = class_find_client_obd(&tgt->ltd_uuid, LUSTRE_MDC_NAME,
306 CERROR("target %s not attached\n", tgt->ltd_uuid.uuid);
310 CDEBUG(D_CONFIG, "connect to %s(%s) - %s, %s FOR %s\n",
311 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
312 tgt->ltd_uuid.uuid, obd->obd_uuid.uuid,
315 if (!mdc_obd->obd_set_up) {
316 CERROR("target %s is not set up\n", tgt->ltd_uuid.uuid);
320 rc = obd_connect(NULL, &mdc_exp, mdc_obd, &lmv_mdc_uuid,
321 &lmv->conn_data, NULL);
323 CERROR("target %s connect error %d\n", tgt->ltd_uuid.uuid, rc);
328 * Init fid sequence client for this mdc and add new fld target.
330 rc = obd_fid_init(mdc_obd, mdc_exp, LUSTRE_SEQ_METADATA);
334 target.ft_srv = NULL;
335 target.ft_exp = mdc_exp;
336 target.ft_idx = tgt->ltd_idx;
338 fld_client_add_target(&lmv->lmv_fld, &target);
340 rc = obd_register_observer(mdc_obd, obd);
342 obd_disconnect(mdc_exp);
343 CERROR("target %s register_observer error %d\n",
344 tgt->ltd_uuid.uuid, rc);
348 if (obd->obd_observer) {
350 * Tell the observer about the new target.
352 rc = obd_notify(obd->obd_observer, mdc_exp->exp_obd,
354 (void *)(tgt - lmv->tgts[0]));
356 obd_disconnect(mdc_exp);
362 tgt->ltd_exp = mdc_exp;
363 lmv->desc.ld_active_tgt_count++;
365 md_init_ea_size(tgt->ltd_exp, lmv->max_easize, lmv->max_def_easize);
367 CDEBUG(D_CONFIG, "Connected to %s(%s) successfully (%d)\n",
368 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
369 atomic_read(&obd->obd_refcount));
371 if (lmv->targets_proc_entry != NULL) {
372 struct proc_dir_entry *mdc_symlink;
374 LASSERT(mdc_obd->obd_type != NULL);
375 LASSERT(mdc_obd->obd_type->typ_name != NULL);
376 mdc_symlink = lprocfs_add_symlink(mdc_obd->obd_name,
377 lmv->targets_proc_entry,
379 mdc_obd->obd_type->typ_name,
381 if (mdc_symlink == NULL) {
382 CERROR("cannot register LMV target "
383 "/proc/fs/lustre/%s/%s/target_obds/%s\n",
384 obd->obd_type->typ_name, obd->obd_name,
391 static void lmv_del_target(struct lmv_obd *lmv, int index)
393 if (lmv->tgts[index] == NULL)
396 OBD_FREE_PTR(lmv->tgts[index]);
397 lmv->tgts[index] = NULL;
401 static int lmv_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
402 __u32 index, int gen)
404 struct obd_device *mdc_obd;
405 struct lmv_obd *lmv = &obd->u.lmv;
406 struct lmv_tgt_desc *tgt;
407 int orig_tgt_count = 0;
411 CDEBUG(D_CONFIG, "Target uuid: %s. index %d\n", uuidp->uuid, index);
412 mdc_obd = class_find_client_obd(uuidp, LUSTRE_MDC_NAME,
415 CERROR("%s: Target %s not attached: rc = %d\n",
416 obd->obd_name, uuidp->uuid, -EINVAL);
420 mutex_lock(&lmv->lmv_init_mutex);
421 if ((index < lmv->tgts_size) && (lmv->tgts[index] != NULL)) {
422 tgt = lmv->tgts[index];
423 CERROR("%s: UUID %s already assigned at LOV target index %d:"
424 " rc = %d\n", obd->obd_name,
425 obd_uuid2str(&tgt->ltd_uuid), index, -EEXIST);
426 mutex_unlock(&lmv->lmv_init_mutex);
430 if (index >= lmv->tgts_size) {
431 /* We need to reallocate the lmv target array. */
432 struct lmv_tgt_desc **newtgts, **old = NULL;
436 while (newsize < index + 1)
437 newsize = newsize << 1;
438 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
439 if (newtgts == NULL) {
440 mutex_unlock(&lmv->lmv_init_mutex);
444 if (lmv->tgts_size) {
445 memcpy(newtgts, lmv->tgts,
446 sizeof(*newtgts) * lmv->tgts_size);
448 oldsize = lmv->tgts_size;
452 lmv->tgts_size = newsize;
455 OBD_FREE(old, sizeof(*old) * oldsize);
457 CDEBUG(D_CONFIG, "tgts: %p size: %d\n", lmv->tgts,
463 mutex_unlock(&lmv->lmv_init_mutex);
467 mutex_init(&tgt->ltd_fid_mutex);
468 tgt->ltd_idx = index;
469 tgt->ltd_uuid = *uuidp;
471 lmv->tgts[index] = tgt;
472 if (index >= lmv->desc.ld_tgt_count) {
473 orig_tgt_count = lmv->desc.ld_tgt_count;
474 lmv->desc.ld_tgt_count = index + 1;
477 if (lmv->connected == 0) {
478 /* lmv_check_connect() will connect this target. */
479 mutex_unlock(&lmv->lmv_init_mutex);
483 /* Otherwise let's connect it ourselves */
484 mutex_unlock(&lmv->lmv_init_mutex);
485 rc = lmv_connect_mdc(obd, tgt);
487 spin_lock(&lmv->lmv_lock);
488 if (lmv->desc.ld_tgt_count == index + 1)
489 lmv->desc.ld_tgt_count = orig_tgt_count;
490 memset(tgt, 0, sizeof(*tgt));
491 spin_unlock(&lmv->lmv_lock);
493 int easize = sizeof(struct lmv_stripe_md) +
494 lmv->desc.ld_tgt_count * sizeof(struct lu_fid);
495 lmv_init_ea_size(obd->obd_self_export, easize, 0);
501 static int lmv_check_connect(struct obd_device *obd)
503 struct lmv_obd *lmv = &obd->u.lmv;
504 struct lmv_tgt_desc *tgt;
513 mutex_lock(&lmv->lmv_init_mutex);
514 if (lmv->connected) {
515 mutex_unlock(&lmv->lmv_init_mutex);
519 if (lmv->desc.ld_tgt_count == 0) {
520 mutex_unlock(&lmv->lmv_init_mutex);
521 CERROR("%s: no targets configured.\n", obd->obd_name);
525 LASSERT(lmv->tgts != NULL);
527 if (lmv->tgts[0] == NULL) {
528 mutex_unlock(&lmv->lmv_init_mutex);
529 CERROR("%s: no target configured for index 0.\n",
534 CDEBUG(D_CONFIG, "Time to connect %s to %s\n",
535 lmv->cluuid.uuid, obd->obd_name);
537 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
541 rc = lmv_connect_mdc(obd, tgt);
547 easize = lmv_mds_md_size(lmv->desc.ld_tgt_count, LMV_MAGIC);
548 lmv_init_ea_size(obd->obd_self_export, easize, 0);
549 mutex_unlock(&lmv->lmv_init_mutex);
560 --lmv->desc.ld_active_tgt_count;
561 rc2 = obd_disconnect(tgt->ltd_exp);
563 CERROR("LMV target %s disconnect on "
564 "MDC idx %d: error %d\n",
565 tgt->ltd_uuid.uuid, i, rc2);
570 mutex_unlock(&lmv->lmv_init_mutex);
575 static int lmv_disconnect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
577 struct lmv_obd *lmv = &obd->u.lmv;
578 struct obd_device *mdc_obd;
582 LASSERT(tgt != NULL);
583 LASSERT(obd != NULL);
585 mdc_obd = class_exp2obd(tgt->ltd_exp);
588 mdc_obd->obd_force = obd->obd_force;
589 mdc_obd->obd_fail = obd->obd_fail;
590 mdc_obd->obd_no_recov = obd->obd_no_recov;
592 if (lmv->targets_proc_entry != NULL)
593 lprocfs_remove_proc_entry(mdc_obd->obd_name,
594 lmv->targets_proc_entry);
597 rc = obd_fid_fini(tgt->ltd_exp->exp_obd);
599 CERROR("Can't finanize fids factory\n");
601 CDEBUG(D_INFO, "Disconnected from %s(%s) successfully\n",
602 tgt->ltd_exp->exp_obd->obd_name,
603 tgt->ltd_exp->exp_obd->obd_uuid.uuid);
605 obd_register_observer(tgt->ltd_exp->exp_obd, NULL);
606 rc = obd_disconnect(tgt->ltd_exp);
608 if (tgt->ltd_active) {
609 CERROR("Target %s disconnect error %d\n",
610 tgt->ltd_uuid.uuid, rc);
614 lmv_activate_target(lmv, tgt, 0);
619 static int lmv_disconnect(struct obd_export *exp)
621 struct obd_device *obd = class_exp2obd(exp);
622 struct lmv_obd *lmv = &obd->u.lmv;
630 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
631 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
634 lmv_disconnect_mdc(obd, lmv->tgts[i]);
637 if (lmv->targets_proc_entry != NULL)
638 lprocfs_remove(&lmv->targets_proc_entry);
640 CERROR("/proc/fs/lustre/%s/%s/target_obds missing\n",
641 obd->obd_type->typ_name, obd->obd_name);
645 * This is the case when no real connection is established by
646 * lmv_check_connect().
649 class_export_put(exp);
650 rc = class_disconnect(exp);
656 static int lmv_fid2path(struct obd_export *exp, int len, void *karg,
659 struct obd_device *obddev = class_exp2obd(exp);
660 struct lmv_obd *lmv = &obddev->u.lmv;
661 struct getinfo_fid2path *gf;
662 struct lmv_tgt_desc *tgt;
663 struct getinfo_fid2path *remote_gf = NULL;
664 struct lu_fid root_fid;
665 int remote_gf_size = 0;
669 tgt = lmv_find_target(lmv, &gf->gf_fid);
671 RETURN(PTR_ERR(tgt));
673 root_fid = *gf->gf_u.gf_root_fid;
674 LASSERT(fid_is_sane(&root_fid));
677 rc = obd_iocontrol(OBD_IOC_FID2PATH, tgt->ltd_exp, len, gf, uarg);
678 if (rc != 0 && rc != -EREMOTE)
679 GOTO(out_fid2path, rc);
681 /* If remote_gf != NULL, it means just building the
682 * path on the remote MDT, copy this path segement to gf */
683 if (remote_gf != NULL) {
684 struct getinfo_fid2path *ori_gf;
687 ori_gf = (struct getinfo_fid2path *)karg;
688 if (strlen(ori_gf->gf_u.gf_path) +
689 strlen(gf->gf_u.gf_path) > ori_gf->gf_pathlen)
690 GOTO(out_fid2path, rc = -EOVERFLOW);
692 ptr = ori_gf->gf_u.gf_path;
694 memmove(ptr + strlen(gf->gf_u.gf_path) + 1, ptr,
695 strlen(ori_gf->gf_u.gf_path));
697 strncpy(ptr, gf->gf_u.gf_path,
698 strlen(gf->gf_u.gf_path));
699 ptr += strlen(gf->gf_u.gf_path);
703 CDEBUG(D_INFO, "%s: get path %s "DFID" rec: %llu ln: %u\n",
704 tgt->ltd_exp->exp_obd->obd_name,
705 gf->gf_u.gf_path, PFID(&gf->gf_fid), gf->gf_recno,
709 GOTO(out_fid2path, rc);
711 /* sigh, has to go to another MDT to do path building further */
712 if (remote_gf == NULL) {
713 remote_gf_size = sizeof(*remote_gf) + PATH_MAX;
714 OBD_ALLOC(remote_gf, remote_gf_size);
715 if (remote_gf == NULL)
716 GOTO(out_fid2path, rc = -ENOMEM);
717 remote_gf->gf_pathlen = PATH_MAX;
720 if (!fid_is_sane(&gf->gf_fid)) {
721 CERROR("%s: invalid FID "DFID": rc = %d\n",
722 tgt->ltd_exp->exp_obd->obd_name,
723 PFID(&gf->gf_fid), -EINVAL);
724 GOTO(out_fid2path, rc = -EINVAL);
727 tgt = lmv_find_target(lmv, &gf->gf_fid);
729 GOTO(out_fid2path, rc = -EINVAL);
731 remote_gf->gf_fid = gf->gf_fid;
732 remote_gf->gf_recno = -1;
733 remote_gf->gf_linkno = -1;
734 memset(remote_gf->gf_u.gf_path, 0, remote_gf->gf_pathlen);
735 *remote_gf->gf_u.gf_root_fid = root_fid;
737 goto repeat_fid2path;
740 if (remote_gf != NULL)
741 OBD_FREE(remote_gf, remote_gf_size);
745 static int lmv_hsm_req_count(struct lmv_obd *lmv,
746 const struct hsm_user_request *hur,
747 const struct lmv_tgt_desc *tgt_mds)
751 struct lmv_tgt_desc *curr_tgt;
753 /* count how many requests must be sent to the given target */
754 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
755 curr_tgt = lmv_find_target(lmv, &hur->hur_user_item[i].hui_fid);
756 if (IS_ERR(curr_tgt))
757 RETURN(PTR_ERR(curr_tgt));
758 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid))
764 static int lmv_hsm_req_build(struct lmv_obd *lmv,
765 struct hsm_user_request *hur_in,
766 const struct lmv_tgt_desc *tgt_mds,
767 struct hsm_user_request *hur_out)
770 struct lmv_tgt_desc *curr_tgt;
772 /* build the hsm_user_request for the given target */
773 hur_out->hur_request = hur_in->hur_request;
775 for (i = 0; i < hur_in->hur_request.hr_itemcount; i++) {
776 curr_tgt = lmv_find_target(lmv,
777 &hur_in->hur_user_item[i].hui_fid);
778 if (IS_ERR(curr_tgt))
779 RETURN(PTR_ERR(curr_tgt));
780 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid)) {
781 hur_out->hur_user_item[nr_out] =
782 hur_in->hur_user_item[i];
786 hur_out->hur_request.hr_itemcount = nr_out;
787 memcpy(hur_data(hur_out), hur_data(hur_in),
788 hur_in->hur_request.hr_data_len);
793 static int lmv_hsm_ct_unregister(struct lmv_obd *lmv, unsigned int cmd, int len,
794 struct lustre_kernelcomm *lk,
801 /* unregister request (call from llapi_hsm_copytool_fini) */
802 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
803 struct lmv_tgt_desc *tgt = lmv->tgts[i];
805 if (tgt == NULL || tgt->ltd_exp == NULL)
807 /* best effort: try to clean as much as possible
808 * (continue on error) */
809 obd_iocontrol(cmd, tgt->ltd_exp, len, lk, uarg);
812 /* Whatever the result, remove copytool from kuc groups.
813 * Unreached coordinators will get EPIPE on next requests
814 * and will unregister automatically.
816 rc = libcfs_kkuc_group_rem(lk->lk_uid, lk->lk_group);
821 static int lmv_hsm_ct_register(struct lmv_obd *lmv, unsigned int cmd, int len,
822 struct lustre_kernelcomm *lk, __user void *uarg)
827 bool any_set = false;
828 struct kkuc_ct_data kcd = { 0 };
831 /* All or nothing: try to register to all MDS.
832 * In case of failure, unregister from previous MDS,
833 * except if it because of inactive target. */
834 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
835 struct lmv_tgt_desc *tgt = lmv->tgts[i];
837 if (tgt == NULL || tgt->ltd_exp == NULL)
839 err = obd_iocontrol(cmd, tgt->ltd_exp, len, lk, uarg);
841 if (tgt->ltd_active) {
842 /* permanent error */
843 CERROR("%s: iocontrol MDC %s on MDT"
844 " idx %d cmd %x: err = %d\n",
845 lmv2obd_dev(lmv)->obd_name,
846 tgt->ltd_uuid.uuid, i, cmd, err);
848 lk->lk_flags |= LK_FLG_STOP;
849 /* unregister from previous MDS */
850 for (j = 0; j < i; j++) {
852 if (tgt == NULL || tgt->ltd_exp == NULL)
854 obd_iocontrol(cmd, tgt->ltd_exp, len,
859 /* else: transient error.
860 * kuc will register to the missing MDT
868 /* no registration done: return error */
871 /* at least one registration done, with no failure */
872 filp = fget(lk->lk_wfd);
876 kcd.kcd_magic = KKUC_CT_DATA_MAGIC;
877 kcd.kcd_uuid = lmv->cluuid;
878 kcd.kcd_archive = lk->lk_data;
880 rc = libcfs_kkuc_group_add(filp, lk->lk_uid, lk->lk_group,
891 static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
892 int len, void *karg, void __user *uarg)
894 struct obd_device *obddev = class_exp2obd(exp);
895 struct lmv_obd *lmv = &obddev->u.lmv;
896 struct lmv_tgt_desc *tgt = NULL;
900 __u32 count = lmv->desc.ld_tgt_count;
907 case IOC_OBD_STATFS: {
908 struct obd_ioctl_data *data = karg;
909 struct obd_device *mdc_obd;
910 struct obd_statfs stat_buf = {0};
913 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
914 if ((index >= count))
917 tgt = lmv->tgts[index];
918 if (tgt == NULL || !tgt->ltd_active)
921 mdc_obd = class_exp2obd(tgt->ltd_exp);
926 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(mdc_obd),
927 min((int) data->ioc_plen2,
928 (int) sizeof(struct obd_uuid))))
931 rc = obd_statfs(NULL, tgt->ltd_exp, &stat_buf,
932 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
936 if (copy_to_user(data->ioc_pbuf1, &stat_buf,
937 min((int) data->ioc_plen1,
938 (int) sizeof(stat_buf))))
942 case OBD_IOC_QUOTACTL: {
943 struct if_quotactl *qctl = karg;
944 struct obd_quotactl *oqctl;
946 if (qctl->qc_valid == QC_MDTIDX) {
947 if (count <= qctl->qc_idx)
950 tgt = lmv->tgts[qctl->qc_idx];
951 if (tgt == NULL || tgt->ltd_exp == NULL)
953 } else if (qctl->qc_valid == QC_UUID) {
954 for (i = 0; i < count; i++) {
958 if (!obd_uuid_equals(&tgt->ltd_uuid,
962 if (tgt->ltd_exp == NULL)
974 LASSERT(tgt != NULL && tgt->ltd_exp != NULL);
975 OBD_ALLOC_PTR(oqctl);
979 QCTL_COPY(oqctl, qctl);
980 rc = obd_quotactl(tgt->ltd_exp, oqctl);
982 QCTL_COPY(qctl, oqctl);
983 qctl->qc_valid = QC_MDTIDX;
984 qctl->obd_uuid = tgt->ltd_uuid;
989 case OBD_IOC_CHANGELOG_SEND:
990 case OBD_IOC_CHANGELOG_CLEAR: {
991 struct ioc_changelog *icc = karg;
993 if (icc->icc_mdtindex >= count)
996 tgt = lmv->tgts[icc->icc_mdtindex];
997 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
999 rc = obd_iocontrol(cmd, tgt->ltd_exp, sizeof(*icc), icc, NULL);
1002 case LL_IOC_GET_CONNECT_FLAGS: {
1004 if (tgt == NULL || tgt->ltd_exp == NULL)
1006 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1009 case LL_IOC_FID2MDTIDX: {
1010 struct lu_fid *fid = karg;
1013 rc = lmv_fld_lookup(lmv, fid, &mdt_index);
1017 /* Note: this is from llite(see ll_dir_ioctl()), @uarg does not
1018 * point to user space memory for FID2MDTIDX. */
1019 *(__u32 *)uarg = mdt_index;
1022 case OBD_IOC_FID2PATH: {
1023 rc = lmv_fid2path(exp, len, karg, uarg);
1026 case LL_IOC_HSM_STATE_GET:
1027 case LL_IOC_HSM_STATE_SET:
1028 case LL_IOC_HSM_ACTION: {
1029 struct md_op_data *op_data = karg;
1031 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1033 RETURN(PTR_ERR(tgt));
1035 if (tgt->ltd_exp == NULL)
1038 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1041 case LL_IOC_HSM_PROGRESS: {
1042 const struct hsm_progress_kernel *hpk = karg;
1044 tgt = lmv_find_target(lmv, &hpk->hpk_fid);
1046 RETURN(PTR_ERR(tgt));
1047 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1050 case LL_IOC_HSM_REQUEST: {
1051 struct hsm_user_request *hur = karg;
1052 unsigned int reqcount = hur->hur_request.hr_itemcount;
1057 /* if the request is about a single fid
1058 * or if there is a single MDS, no need to split
1060 if (reqcount == 1 || count == 1) {
1061 tgt = lmv_find_target(lmv,
1062 &hur->hur_user_item[0].hui_fid);
1064 RETURN(PTR_ERR(tgt));
1065 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1067 /* split fid list to their respective MDS */
1068 for (i = 0; i < count; i++) {
1071 struct hsm_user_request *req;
1074 if (tgt == NULL || tgt->ltd_exp == NULL)
1077 nr = lmv_hsm_req_count(lmv, hur, tgt);
1080 if (nr == 0) /* nothing for this MDS */
1083 /* build a request with fids for this MDS */
1084 reqlen = offsetof(typeof(*hur),
1086 + hur->hur_request.hr_data_len;
1087 OBD_ALLOC_LARGE(req, reqlen);
1090 rc1 = lmv_hsm_req_build(lmv, hur, tgt, req);
1092 GOTO(hsm_req_err, rc1);
1093 rc1 = obd_iocontrol(cmd, tgt->ltd_exp, reqlen,
1096 if (rc1 != 0 && rc == 0)
1098 OBD_FREE_LARGE(req, reqlen);
1103 case LL_IOC_LOV_SWAP_LAYOUTS: {
1104 struct md_op_data *op_data = karg;
1105 struct lmv_tgt_desc *tgt1, *tgt2;
1107 tgt1 = lmv_find_target(lmv, &op_data->op_fid1);
1109 RETURN(PTR_ERR(tgt1));
1111 tgt2 = lmv_find_target(lmv, &op_data->op_fid2);
1113 RETURN(PTR_ERR(tgt2));
1115 if ((tgt1->ltd_exp == NULL) || (tgt2->ltd_exp == NULL))
1118 /* only files on same MDT can have their layouts swapped */
1119 if (tgt1->ltd_idx != tgt2->ltd_idx)
1122 rc = obd_iocontrol(cmd, tgt1->ltd_exp, len, karg, uarg);
1125 case LL_IOC_HSM_CT_START: {
1126 struct lustre_kernelcomm *lk = karg;
1127 if (lk->lk_flags & LK_FLG_STOP)
1128 rc = lmv_hsm_ct_unregister(lmv, cmd, len, lk, uarg);
1130 rc = lmv_hsm_ct_register(lmv, cmd, len, lk, uarg);
1134 for (i = 0; i < count; i++) {
1135 struct obd_device *mdc_obd;
1139 if (tgt == NULL || tgt->ltd_exp == NULL)
1141 /* ll_umount_begin() sets force flag but for lmv, not
1142 * mdc. Let's pass it through */
1143 mdc_obd = class_exp2obd(tgt->ltd_exp);
1144 mdc_obd->obd_force = obddev->obd_force;
1145 err = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1147 if (tgt->ltd_active) {
1148 CERROR("error: iocontrol MDC %s on MDT"
1149 " idx %d cmd %x: err = %d\n",
1150 tgt->ltd_uuid.uuid, i, cmd, err);
1164 * This is _inode_ placement policy function (not name).
1166 static int lmv_placement_policy(struct obd_device *obd,
1167 struct md_op_data *op_data, u32 *mds)
1169 struct lmv_obd *lmv = &obd->u.lmv;
1170 struct lmv_user_md *lum;
1174 LASSERT(mds != NULL);
1176 if (lmv->desc.ld_tgt_count == 1) {
1181 lum = op_data->op_data;
1183 * 1. See if the stripe offset is specified by lum.
1184 * 2. Then check if there is default stripe offset.
1185 * 3. Finally choose MDS by name hash if the parent
1186 * is striped directory. (see lmv_locate_mds()). */
1187 if (op_data->op_cli_flags & CLI_SET_MEA && lum != NULL &&
1188 le32_to_cpu(lum->lum_stripe_offset) != (__u32)-1) {
1189 *mds = le32_to_cpu(lum->lum_stripe_offset);
1190 } else if (op_data->op_default_stripe_offset != (__u32)-1) {
1191 *mds = op_data->op_default_stripe_offset;
1192 op_data->op_mds = *mds;
1193 /* Correct the stripe offset in lum */
1195 lum->lum_stripe_offset = cpu_to_le32(*mds);
1197 *mds = op_data->op_mds;
1203 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid, u32 mds)
1205 struct lmv_tgt_desc *tgt;
1209 tgt = lmv_get_target(lmv, mds, NULL);
1211 RETURN(PTR_ERR(tgt));
1214 * New seq alloc and FLD setup should be atomic. Otherwise we may find
1215 * on server that seq in new allocated fid is not yet known.
1217 mutex_lock(&tgt->ltd_fid_mutex);
1219 if (tgt->ltd_active == 0 || tgt->ltd_exp == NULL)
1220 GOTO(out, rc = -ENODEV);
1223 * Asking underlying tgt layer to allocate new fid.
1225 rc = obd_fid_alloc(NULL, tgt->ltd_exp, fid, NULL);
1227 LASSERT(fid_is_sane(fid));
1233 mutex_unlock(&tgt->ltd_fid_mutex);
1237 int lmv_fid_alloc(const struct lu_env *env, struct obd_export *exp,
1238 struct lu_fid *fid, struct md_op_data *op_data)
1240 struct obd_device *obd = class_exp2obd(exp);
1241 struct lmv_obd *lmv = &obd->u.lmv;
1246 LASSERT(op_data != NULL);
1247 LASSERT(fid != NULL);
1249 rc = lmv_placement_policy(obd, op_data, &mds);
1251 CERROR("Can't get target for allocating fid, "
1256 rc = __lmv_fid_alloc(lmv, fid, mds);
1258 CERROR("Can't alloc new fid, rc %d\n", rc);
1265 static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
1267 struct lmv_obd *lmv = &obd->u.lmv;
1268 struct lmv_desc *desc;
1272 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
1273 CERROR("LMV setup requires a descriptor\n");
1277 desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1);
1278 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
1279 CERROR("Lmv descriptor size wrong: %d > %d\n",
1280 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
1284 lmv->tgts_size = 32U;
1285 OBD_ALLOC(lmv->tgts, sizeof(*lmv->tgts) * lmv->tgts_size);
1286 if (lmv->tgts == NULL)
1289 obd_str2uuid(&lmv->desc.ld_uuid, desc->ld_uuid.uuid);
1290 lmv->desc.ld_tgt_count = 0;
1291 lmv->desc.ld_active_tgt_count = 0;
1292 lmv->max_def_easize = 0;
1293 lmv->max_easize = 0;
1295 spin_lock_init(&lmv->lmv_lock);
1296 mutex_init(&lmv->lmv_init_mutex);
1298 #ifdef CONFIG_PROC_FS
1299 obd->obd_vars = lprocfs_lmv_obd_vars;
1300 lprocfs_obd_setup(obd);
1301 lprocfs_alloc_md_stats(obd, 0);
1302 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
1303 0444, &lmv_proc_target_fops, obd);
1305 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
1308 rc = fld_client_init(&lmv->lmv_fld, obd->obd_name,
1309 LUSTRE_CLI_FLD_HASH_DHT);
1311 CERROR("Can't init FLD, err %d\n", rc);
1321 static int lmv_cleanup(struct obd_device *obd)
1323 struct lmv_obd *lmv = &obd->u.lmv;
1326 fld_client_fini(&lmv->lmv_fld);
1327 if (lmv->tgts != NULL) {
1329 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1330 if (lmv->tgts[i] == NULL)
1332 lmv_del_target(lmv, i);
1334 OBD_FREE(lmv->tgts, sizeof(*lmv->tgts) * lmv->tgts_size);
1340 static int lmv_process_config(struct obd_device *obd, size_t len, void *buf)
1342 struct lustre_cfg *lcfg = buf;
1343 struct obd_uuid obd_uuid;
1349 switch (lcfg->lcfg_command) {
1351 /* modify_mdc_tgts add 0:lustre-clilmv 1:lustre-MDT0000_UUID
1352 * 2:0 3:1 4:lustre-MDT0000-mdc_UUID */
1353 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
1354 GOTO(out, rc = -EINVAL);
1356 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
1358 if (sscanf(lustre_cfg_buf(lcfg, 2), "%u", &index) != 1)
1359 GOTO(out, rc = -EINVAL);
1360 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
1361 GOTO(out, rc = -EINVAL);
1362 rc = lmv_add_target(obd, &obd_uuid, index, gen);
1365 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1366 GOTO(out, rc = -EINVAL);
1372 static int lmv_statfs(const struct lu_env *env, struct obd_export *exp,
1373 struct obd_statfs *osfs, __u64 max_age, __u32 flags)
1375 struct obd_device *obd = class_exp2obd(exp);
1376 struct lmv_obd *lmv = &obd->u.lmv;
1377 struct obd_statfs *temp;
1382 OBD_ALLOC(temp, sizeof(*temp));
1386 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1387 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1390 rc = obd_statfs(env, lmv->tgts[i]->ltd_exp, temp,
1393 CERROR("can't stat MDS #%d (%s), error %d\n", i,
1394 lmv->tgts[i]->ltd_exp->exp_obd->obd_name,
1396 GOTO(out_free_temp, rc);
1401 /* If the statfs is from mount, it will needs
1402 * retrieve necessary information from MDT0.
1403 * i.e. mount does not need the merged osfs
1405 * And also clients can be mounted as long as
1406 * MDT0 is in service*/
1407 if (flags & OBD_STATFS_FOR_MDT0)
1408 GOTO(out_free_temp, rc);
1410 osfs->os_bavail += temp->os_bavail;
1411 osfs->os_blocks += temp->os_blocks;
1412 osfs->os_ffree += temp->os_ffree;
1413 osfs->os_files += temp->os_files;
1419 OBD_FREE(temp, sizeof(*temp));
1423 static int lmv_get_root(struct obd_export *exp, const char *fileset,
1426 struct obd_device *obd = exp->exp_obd;
1427 struct lmv_obd *lmv = &obd->u.lmv;
1431 rc = md_get_root(lmv->tgts[0]->ltd_exp, fileset, fid);
1435 static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1436 u64 valid, const char *name,
1437 const char *input, int input_size, int output_size,
1438 int flags, struct ptlrpc_request **request)
1440 struct obd_device *obd = exp->exp_obd;
1441 struct lmv_obd *lmv = &obd->u.lmv;
1442 struct lmv_tgt_desc *tgt;
1446 tgt = lmv_find_target(lmv, fid);
1448 RETURN(PTR_ERR(tgt));
1450 rc = md_getxattr(tgt->ltd_exp, fid, valid, name, input,
1451 input_size, output_size, flags, request);
1456 static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1457 u64 valid, const char *name,
1458 const char *input, int input_size, int output_size,
1459 int flags, __u32 suppgid,
1460 struct ptlrpc_request **request)
1462 struct obd_device *obd = exp->exp_obd;
1463 struct lmv_obd *lmv = &obd->u.lmv;
1464 struct lmv_tgt_desc *tgt;
1468 tgt = lmv_find_target(lmv, fid);
1470 RETURN(PTR_ERR(tgt));
1472 rc = md_setxattr(tgt->ltd_exp, fid, valid, name, input,
1473 input_size, output_size, flags, suppgid,
1479 static int lmv_getattr(struct obd_export *exp, struct md_op_data *op_data,
1480 struct ptlrpc_request **request)
1482 struct obd_device *obd = exp->exp_obd;
1483 struct lmv_obd *lmv = &obd->u.lmv;
1484 struct lmv_tgt_desc *tgt;
1488 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1490 RETURN(PTR_ERR(tgt));
1492 if (op_data->op_flags & MF_GET_MDT_IDX) {
1493 op_data->op_mds = tgt->ltd_idx;
1497 rc = md_getattr(tgt->ltd_exp, op_data, request);
1502 static int lmv_null_inode(struct obd_export *exp, const struct lu_fid *fid)
1504 struct obd_device *obd = exp->exp_obd;
1505 struct lmv_obd *lmv = &obd->u.lmv;
1509 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1512 * With DNE every object can have two locks in different namespaces:
1513 * lookup lock in space of MDT storing direntry and update/open lock in
1514 * space of MDT storing inode.
1516 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1517 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1519 md_null_inode(lmv->tgts[i]->ltd_exp, fid);
1525 static int lmv_close(struct obd_export *exp, struct md_op_data *op_data,
1526 struct md_open_data *mod, struct ptlrpc_request **request)
1528 struct obd_device *obd = exp->exp_obd;
1529 struct lmv_obd *lmv = &obd->u.lmv;
1530 struct lmv_tgt_desc *tgt;
1534 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1536 RETURN(PTR_ERR(tgt));
1538 CDEBUG(D_INODE, "CLOSE "DFID"\n", PFID(&op_data->op_fid1));
1539 rc = md_close(tgt->ltd_exp, op_data, mod, request);
1544 * Choosing the MDT by name or FID in @op_data.
1545 * For non-striped directory, it will locate MDT by fid.
1546 * For striped-directory, it will locate MDT by name. And also
1547 * it will reset op_fid1 with the FID of the choosen stripe.
1549 struct lmv_tgt_desc *
1550 lmv_locate_target_for_name(struct lmv_obd *lmv, struct lmv_stripe_md *lsm,
1551 const char *name, int namelen, struct lu_fid *fid,
1554 struct lmv_tgt_desc *tgt;
1555 const struct lmv_oinfo *oinfo;
1557 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_NAME_HASH)) {
1558 if (cfs_fail_val >= lsm->lsm_md_stripe_count)
1559 RETURN(ERR_PTR(-EBADF));
1560 oinfo = &lsm->lsm_md_oinfo[cfs_fail_val];
1562 oinfo = lsm_name_to_stripe_info(lsm, name, namelen);
1564 RETURN(ERR_CAST(oinfo));
1568 *fid = oinfo->lmo_fid;
1570 *mds = oinfo->lmo_mds;
1572 tgt = lmv_get_target(lmv, oinfo->lmo_mds, NULL);
1574 CDEBUG(D_INFO, "locate on mds %u "DFID"\n", oinfo->lmo_mds,
1575 PFID(&oinfo->lmo_fid));
1580 * Locate mds by fid or name
1582 * For striped directory (lsm != NULL), it will locate the stripe
1583 * by name hash (see lsm_name_to_stripe_info()). Note: if the hash_type
1584 * is unknown, it will return -EBADFD, and lmv_intent_lookup might need
1585 * walk through all of stripes to locate the entry.
1587 * For normal direcotry, it will locate MDS by FID directly.
1588 * \param[in] lmv LMV device
1589 * \param[in] op_data client MD stack parameters, name, namelen
1591 * \param[in] fid object FID used to locate MDS.
1593 * retval pointer to the lmv_tgt_desc if succeed.
1594 * ERR_PTR(errno) if failed.
1596 struct lmv_tgt_desc*
1597 lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1600 struct lmv_stripe_md *lsm = op_data->op_mea1;
1601 struct lmv_tgt_desc *tgt;
1603 /* During creating VOLATILE file, it should honor the mdt
1604 * index if the file under striped dir is being restored, see
1606 if (op_data->op_bias & MDS_CREATE_VOLATILE &&
1607 (int)op_data->op_mds != -1) {
1609 tgt = lmv_get_target(lmv, op_data->op_mds, NULL);
1614 /* refill the right parent fid */
1615 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1616 struct lmv_oinfo *oinfo;
1618 oinfo = &lsm->lsm_md_oinfo[i];
1619 if (oinfo->lmo_mds == op_data->op_mds) {
1620 *fid = oinfo->lmo_fid;
1625 if (i == lsm->lsm_md_stripe_count)
1626 *fid = lsm->lsm_md_oinfo[0].lmo_fid;
1632 if (lsm == NULL || op_data->op_namelen == 0) {
1633 tgt = lmv_find_target(lmv, fid);
1637 op_data->op_mds = tgt->ltd_idx;
1641 return lmv_locate_target_for_name(lmv, lsm, op_data->op_name,
1642 op_data->op_namelen, fid,
1646 int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
1647 const void *data, size_t datalen, umode_t mode, uid_t uid,
1648 gid_t gid, cfs_cap_t cap_effective, __u64 rdev,
1649 struct ptlrpc_request **request)
1651 struct obd_device *obd = exp->exp_obd;
1652 struct lmv_obd *lmv = &obd->u.lmv;
1653 struct lmv_tgt_desc *tgt;
1657 if (!lmv->desc.ld_active_tgt_count)
1660 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1662 RETURN(PTR_ERR(tgt));
1664 CDEBUG(D_INODE, "CREATE name '%.*s' on "DFID" -> mds #%x\n",
1665 (int)op_data->op_namelen, op_data->op_name,
1666 PFID(&op_data->op_fid1), op_data->op_mds);
1668 rc = lmv_fid_alloc(NULL, exp, &op_data->op_fid2, op_data);
1671 if (exp_connect_flags(exp) & OBD_CONNECT_DIR_STRIPE) {
1672 /* Send the create request to the MDT where the object
1673 * will be located */
1674 tgt = lmv_find_target(lmv, &op_data->op_fid2);
1676 RETURN(PTR_ERR(tgt));
1678 op_data->op_mds = tgt->ltd_idx;
1680 CDEBUG(D_CONFIG, "Server doesn't support striped dirs\n");
1683 CDEBUG(D_INODE, "CREATE obj "DFID" -> mds #%x\n",
1684 PFID(&op_data->op_fid2), op_data->op_mds);
1686 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1687 rc = md_create(tgt->ltd_exp, op_data, data, datalen, mode, uid, gid,
1688 cap_effective, rdev, request);
1690 if (*request == NULL)
1692 CDEBUG(D_INODE, "Created - "DFID"\n", PFID(&op_data->op_fid2));
1698 lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1699 const union ldlm_policy_data *policy, struct md_op_data *op_data,
1700 struct lustre_handle *lockh, __u64 extra_lock_flags)
1702 struct obd_device *obd = exp->exp_obd;
1703 struct lmv_obd *lmv = &obd->u.lmv;
1704 struct lmv_tgt_desc *tgt;
1708 CDEBUG(D_INODE, "ENQUEUE on "DFID"\n", PFID(&op_data->op_fid1));
1710 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1712 RETURN(PTR_ERR(tgt));
1714 CDEBUG(D_INODE, "ENQUEUE on "DFID" -> mds #%u\n",
1715 PFID(&op_data->op_fid1), tgt->ltd_idx);
1717 rc = md_enqueue(tgt->ltd_exp, einfo, policy, op_data, lockh,
1724 lmv_getattr_name(struct obd_export *exp,struct md_op_data *op_data,
1725 struct ptlrpc_request **preq)
1727 struct ptlrpc_request *req = NULL;
1728 struct obd_device *obd = exp->exp_obd;
1729 struct lmv_obd *lmv = &obd->u.lmv;
1730 struct lmv_tgt_desc *tgt;
1731 struct mdt_body *body;
1735 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1737 RETURN(PTR_ERR(tgt));
1739 CDEBUG(D_INODE, "GETATTR_NAME for %*s on "DFID" -> mds #%d\n",
1740 (int)op_data->op_namelen, op_data->op_name,
1741 PFID(&op_data->op_fid1), tgt->ltd_idx);
1743 rc = md_getattr_name(tgt->ltd_exp, op_data, preq);
1747 body = req_capsule_server_get(&(*preq)->rq_pill, &RMF_MDT_BODY);
1748 LASSERT(body != NULL);
1750 if (body->mbo_valid & OBD_MD_MDS) {
1751 struct lu_fid rid = body->mbo_fid1;
1752 CDEBUG(D_INODE, "Request attrs for "DFID"\n",
1755 tgt = lmv_find_target(lmv, &rid);
1757 ptlrpc_req_finished(*preq);
1759 RETURN(PTR_ERR(tgt));
1762 op_data->op_fid1 = rid;
1763 op_data->op_valid |= OBD_MD_FLCROSSREF;
1764 op_data->op_namelen = 0;
1765 op_data->op_name = NULL;
1766 rc = md_getattr_name(tgt->ltd_exp, op_data, &req);
1767 ptlrpc_req_finished(*preq);
1774 #define md_op_data_fid(op_data, fl) \
1775 (fl == MF_MDC_CANCEL_FID1 ? &op_data->op_fid1 : \
1776 fl == MF_MDC_CANCEL_FID2 ? &op_data->op_fid2 : \
1777 fl == MF_MDC_CANCEL_FID3 ? &op_data->op_fid3 : \
1778 fl == MF_MDC_CANCEL_FID4 ? &op_data->op_fid4 : \
1781 static int lmv_early_cancel(struct obd_export *exp, struct lmv_tgt_desc *tgt,
1782 struct md_op_data *op_data, __u32 op_tgt,
1783 enum ldlm_mode mode, int bits, int flag)
1785 struct lu_fid *fid = md_op_data_fid(op_data, flag);
1786 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
1787 union ldlm_policy_data policy = { { 0 } };
1791 if (!fid_is_sane(fid))
1795 tgt = lmv_find_target(lmv, fid);
1797 RETURN(PTR_ERR(tgt));
1800 if (tgt->ltd_idx != op_tgt) {
1801 CDEBUG(D_INODE, "EARLY_CANCEL on "DFID"\n", PFID(fid));
1802 policy.l_inodebits.bits = bits;
1803 rc = md_cancel_unused(tgt->ltd_exp, fid, &policy,
1804 mode, LCF_ASYNC, NULL);
1807 "EARLY_CANCEL skip operation target %d on "DFID"\n",
1809 op_data->op_flags |= flag;
1817 * llite passes fid of an target inode in op_data->op_fid1 and id of directory in
1820 static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
1821 struct ptlrpc_request **request)
1823 struct obd_device *obd = exp->exp_obd;
1824 struct lmv_obd *lmv = &obd->u.lmv;
1825 struct lmv_tgt_desc *tgt;
1829 LASSERT(op_data->op_namelen != 0);
1831 CDEBUG(D_INODE, "LINK "DFID":%*s to "DFID"\n",
1832 PFID(&op_data->op_fid2), (int)op_data->op_namelen,
1833 op_data->op_name, PFID(&op_data->op_fid1));
1835 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
1836 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
1837 op_data->op_cap = cfs_curproc_cap_pack();
1838 if (op_data->op_mea2 != NULL) {
1839 struct lmv_stripe_md *lsm = op_data->op_mea2;
1840 const struct lmv_oinfo *oinfo;
1842 oinfo = lsm_name_to_stripe_info(lsm, op_data->op_name,
1843 op_data->op_namelen);
1845 RETURN(PTR_ERR(oinfo));
1847 op_data->op_fid2 = oinfo->lmo_fid;
1850 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
1852 RETURN(PTR_ERR(tgt));
1855 * Cancel UPDATE lock on child (fid1).
1857 op_data->op_flags |= MF_MDC_CANCEL_FID2;
1858 rc = lmv_early_cancel(exp, NULL, op_data, tgt->ltd_idx, LCK_EX,
1859 MDS_INODELOCK_UPDATE, MF_MDC_CANCEL_FID1);
1863 rc = md_link(tgt->ltd_exp, op_data, request);
1868 static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
1869 const char *old, size_t oldlen,
1870 const char *new, size_t newlen,
1871 struct ptlrpc_request **request)
1873 struct obd_device *obd = exp->exp_obd;
1874 struct lmv_obd *lmv = &obd->u.lmv;
1875 struct lmv_tgt_desc *src_tgt;
1876 struct lmv_tgt_desc *tgt_tgt;
1877 struct obd_export *target_exp;
1878 struct mdt_body *body;
1882 LASSERT(oldlen != 0);
1884 CDEBUG(D_INODE, "RENAME %.*s in "DFID":%d to %.*s in "DFID":%d\n",
1885 (int)oldlen, old, PFID(&op_data->op_fid1),
1886 op_data->op_mea1 ? op_data->op_mea1->lsm_md_stripe_count : 0,
1887 (int)newlen, new, PFID(&op_data->op_fid2),
1888 op_data->op_mea2 ? op_data->op_mea2->lsm_md_stripe_count : 0);
1890 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
1891 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
1892 op_data->op_cap = cfs_curproc_cap_pack();
1893 if (op_data->op_cli_flags & CLI_MIGRATE) {
1894 LASSERTF(fid_is_sane(&op_data->op_fid3), "invalid FID "DFID"\n",
1895 PFID(&op_data->op_fid3));
1897 if (op_data->op_mea1 != NULL) {
1898 struct lmv_stripe_md *lsm = op_data->op_mea1;
1899 struct lmv_tgt_desc *tmp;
1901 /* Fix the parent fid for striped dir */
1902 tmp = lmv_locate_target_for_name(lmv, lsm, old,
1907 RETURN(PTR_ERR(tmp));
1910 rc = lmv_fid_alloc(NULL, exp, &op_data->op_fid2, op_data);
1914 src_tgt = lmv_find_target(lmv, &op_data->op_fid3);
1915 if (IS_ERR(src_tgt))
1916 RETURN(PTR_ERR(src_tgt));
1918 target_exp = src_tgt->ltd_exp;
1920 if (op_data->op_mea1 != NULL) {
1921 struct lmv_stripe_md *lsm = op_data->op_mea1;
1923 src_tgt = lmv_locate_target_for_name(lmv, lsm, old,
1928 src_tgt = lmv_find_target(lmv, &op_data->op_fid1);
1930 if (IS_ERR(src_tgt))
1931 RETURN(PTR_ERR(src_tgt));
1934 if (op_data->op_mea2 != NULL) {
1935 struct lmv_stripe_md *lsm = op_data->op_mea2;
1937 tgt_tgt = lmv_locate_target_for_name(lmv, lsm, new,
1942 tgt_tgt = lmv_find_target(lmv, &op_data->op_fid2);
1945 if (IS_ERR(tgt_tgt))
1946 RETURN(PTR_ERR(tgt_tgt));
1948 target_exp = tgt_tgt->ltd_exp;
1952 * LOOKUP lock on src child (fid3) should also be cancelled for
1953 * src_tgt in mdc_rename.
1955 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
1958 * Cancel UPDATE locks on tgt parent (fid2), tgt_tgt is its
1961 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
1962 LCK_EX, MDS_INODELOCK_UPDATE,
1963 MF_MDC_CANCEL_FID2);
1968 * Cancel LOOKUP locks on source child (fid3) for parent tgt_tgt.
1970 if (fid_is_sane(&op_data->op_fid3)) {
1971 struct lmv_tgt_desc *tgt;
1973 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1975 RETURN(PTR_ERR(tgt));
1977 /* Cancel LOOKUP lock on its parent */
1978 rc = lmv_early_cancel(exp, tgt, op_data, src_tgt->ltd_idx,
1979 LCK_EX, MDS_INODELOCK_LOOKUP,
1980 MF_MDC_CANCEL_FID3);
1984 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
1985 LCK_EX, MDS_INODELOCK_FULL,
1986 MF_MDC_CANCEL_FID3);
1993 * Cancel all the locks on tgt child (fid4).
1995 if (fid_is_sane(&op_data->op_fid4)) {
1996 struct lmv_tgt_desc *tgt;
1998 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
1999 LCK_EX, MDS_INODELOCK_FULL,
2000 MF_MDC_CANCEL_FID4);
2004 tgt = lmv_find_target(lmv, &op_data->op_fid4);
2006 RETURN(PTR_ERR(tgt));
2008 /* Since the target child might be destroyed, and it might
2009 * become orphan, and we can only check orphan on the local
2010 * MDT right now, so we send rename request to the MDT where
2011 * target child is located. If target child does not exist,
2012 * then it will send the request to the target parent */
2013 target_exp = tgt->ltd_exp;
2016 rc = md_rename(target_exp, op_data, old, oldlen, new, newlen,
2019 if (rc != 0 && rc != -EXDEV)
2022 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
2026 /* Not cross-ref case, just get out of here. */
2027 if (likely(!(body->mbo_valid & OBD_MD_MDS)))
2030 CDEBUG(D_INODE, "%s: try rename to another MDT for "DFID"\n",
2031 exp->exp_obd->obd_name, PFID(&body->mbo_fid1));
2033 op_data->op_fid4 = body->mbo_fid1;
2034 ptlrpc_req_finished(*request);
2039 static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
2040 void *ea, size_t ealen, struct ptlrpc_request **request)
2042 struct obd_device *obd = exp->exp_obd;
2043 struct lmv_obd *lmv = &obd->u.lmv;
2044 struct lmv_tgt_desc *tgt;
2048 CDEBUG(D_INODE, "SETATTR for "DFID", valid 0x%x\n",
2049 PFID(&op_data->op_fid1), op_data->op_attr.ia_valid);
2051 op_data->op_flags |= MF_MDC_CANCEL_FID1;
2052 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2054 RETURN(PTR_ERR(tgt));
2056 rc = md_setattr(tgt->ltd_exp, op_data, ea, ealen, request);
2061 static int lmv_fsync(struct obd_export *exp, const struct lu_fid *fid,
2062 struct ptlrpc_request **request)
2064 struct obd_device *obd = exp->exp_obd;
2065 struct lmv_obd *lmv = &obd->u.lmv;
2066 struct lmv_tgt_desc *tgt;
2070 tgt = lmv_find_target(lmv, fid);
2072 RETURN(PTR_ERR(tgt));
2074 rc = md_fsync(tgt->ltd_exp, fid, request);
2079 * Get current minimum entry from striped directory
2081 * This function will search the dir entry, whose hash value is the
2082 * closest(>=) to @hash_offset, from all of sub-stripes, and it is
2083 * only being called for striped directory.
2085 * \param[in] exp export of LMV
2086 * \param[in] op_data parameters transferred beween client MD stack
2087 * stripe_information will be included in this
2089 * \param[in] cb_op ldlm callback being used in enqueue in
2091 * \param[in] hash_offset the hash value, which is used to locate
2092 * minum(closet) dir entry
2093 * \param[in|out] stripe_offset the caller use this to indicate the stripe
2094 * index of last entry, so to avoid hash conflict
2095 * between stripes. It will also be used to
2096 * return the stripe index of current dir entry.
2097 * \param[in|out] entp the minum entry and it also is being used
2098 * to input the last dir entry to resolve the
2101 * \param[out] ppage the page which holds the minum entry
2103 * \retval = 0 get the entry successfully
2104 * negative errno (< 0) does not get the entry
2106 static int lmv_get_min_striped_entry(struct obd_export *exp,
2107 struct md_op_data *op_data,
2108 struct md_callback *cb_op,
2109 __u64 hash_offset, int *stripe_offset,
2110 struct lu_dirent **entp,
2111 struct page **ppage)
2113 struct obd_device *obd = exp->exp_obd;
2114 struct lmv_obd *lmv = &obd->u.lmv;
2115 struct lmv_stripe_md *lsm = op_data->op_mea1;
2116 struct lmv_tgt_desc *tgt;
2118 struct lu_dirent *min_ent = NULL;
2119 struct page *min_page = NULL;
2125 stripe_count = lsm->lsm_md_stripe_count;
2126 for (i = 0; i < stripe_count; i++) {
2127 struct lu_dirent *ent = NULL;
2128 struct page *page = NULL;
2129 struct lu_dirpage *dp;
2130 __u64 stripe_hash = hash_offset;
2132 tgt = lmv_get_target(lmv, lsm->lsm_md_oinfo[i].lmo_mds, NULL);
2134 GOTO(out, rc = PTR_ERR(tgt));
2136 /* op_data will be shared by each stripe, so we need
2137 * reset these value for each stripe */
2138 op_data->op_fid1 = lsm->lsm_md_oinfo[i].lmo_fid;
2139 op_data->op_fid2 = lsm->lsm_md_oinfo[i].lmo_fid;
2140 op_data->op_data = lsm->lsm_md_oinfo[i].lmo_root;
2142 rc = md_read_page(tgt->ltd_exp, op_data, cb_op, stripe_hash,
2147 dp = page_address(page);
2148 for (ent = lu_dirent_start(dp); ent != NULL;
2149 ent = lu_dirent_next(ent)) {
2150 /* Skip dummy entry */
2151 if (le16_to_cpu(ent->lde_namelen) == 0)
2154 if (le64_to_cpu(ent->lde_hash) < hash_offset)
2157 if (le64_to_cpu(ent->lde_hash) == hash_offset &&
2158 (*entp == ent || i < *stripe_offset))
2161 /* skip . and .. for other stripes */
2163 (strncmp(ent->lde_name, ".",
2164 le16_to_cpu(ent->lde_namelen)) == 0 ||
2165 strncmp(ent->lde_name, "..",
2166 le16_to_cpu(ent->lde_namelen)) == 0))
2172 stripe_hash = le64_to_cpu(dp->ldp_hash_end);
2178 /* reach the end of current stripe, go to next stripe */
2179 if (stripe_hash == MDS_DIR_END_OFF)
2185 if (min_ent != NULL) {
2186 if (le64_to_cpu(min_ent->lde_hash) >
2187 le64_to_cpu(ent->lde_hash)) {
2206 if (*ppage != NULL) {
2210 *stripe_offset = min_idx;
2217 * Build dir entry page from a striped directory
2219 * This function gets one entry by @offset from a striped directory. It will
2220 * read entries from all of stripes, and choose one closest to the required
2221 * offset(&offset). A few notes
2222 * 1. skip . and .. for non-zero stripes, because there can only have one .
2223 * and .. in a directory.
2224 * 2. op_data will be shared by all of stripes, instead of allocating new
2225 * one, so need to restore before reusing.
2226 * 3. release the entry page if that is not being chosen.
2228 * \param[in] exp obd export refer to LMV
2229 * \param[in] op_data hold those MD parameters of read_entry
2230 * \param[in] cb_op ldlm callback being used in enqueue in mdc_read_entry
2231 * \param[out] ldp the entry being read
2232 * \param[out] ppage the page holding the entry. Note: because the entry
2233 * will be accessed in upper layer, so we need hold the
2234 * page until the usages of entry is finished, see
2235 * ll_dir_entry_next.
2237 * retval =0 if get entry successfully
2238 * <0 cannot get entry
2240 static int lmv_read_striped_page(struct obd_export *exp,
2241 struct md_op_data *op_data,
2242 struct md_callback *cb_op,
2243 __u64 offset, struct page **ppage)
2245 struct lu_fid master_fid = op_data->op_fid1;
2246 struct inode *master_inode = op_data->op_data;
2247 __u64 hash_offset = offset;
2248 struct lu_dirpage *dp;
2249 struct page *min_ent_page = NULL;
2250 struct page *ent_page = NULL;
2251 struct lu_dirent *ent;
2254 struct lu_dirent *min_ent = NULL;
2255 struct lu_dirent *last_ent;
2260 /* Allocate a page and read entries from all of stripes and fill
2261 * the page by hash order */
2262 ent_page = alloc_page(GFP_KERNEL);
2263 if (ent_page == NULL)
2266 /* Initialize the entry page */
2267 dp = kmap(ent_page);
2268 memset(dp, 0, sizeof(*dp));
2269 dp->ldp_hash_start = cpu_to_le64(offset);
2270 dp->ldp_flags |= LDF_COLLIDE;
2273 left_bytes = PAGE_SIZE - sizeof(*dp);
2279 /* Find the minum entry from all sub-stripes */
2280 rc = lmv_get_min_striped_entry(exp, op_data, cb_op, hash_offset,
2286 /* If it can not get minum entry, it means it already reaches
2287 * the end of this directory */
2288 if (min_ent == NULL) {
2289 last_ent->lde_reclen = 0;
2290 hash_offset = MDS_DIR_END_OFF;
2294 ent_size = le16_to_cpu(min_ent->lde_reclen);
2296 /* the last entry lde_reclen is 0, but it might not
2297 * the end of this entry of this temporay entry */
2299 ent_size = lu_dirent_calc_size(
2300 le16_to_cpu(min_ent->lde_namelen),
2301 le32_to_cpu(min_ent->lde_attrs));
2302 if (ent_size > left_bytes) {
2303 last_ent->lde_reclen = cpu_to_le16(0);
2304 hash_offset = le64_to_cpu(min_ent->lde_hash);
2308 memcpy(ent, min_ent, ent_size);
2310 /* Replace . with master FID and Replace .. with the parent FID
2311 * of master object */
2312 if (strncmp(ent->lde_name, ".",
2313 le16_to_cpu(ent->lde_namelen)) == 0 &&
2314 le16_to_cpu(ent->lde_namelen) == 1)
2315 fid_cpu_to_le(&ent->lde_fid, &master_fid);
2316 else if (strncmp(ent->lde_name, "..",
2317 le16_to_cpu(ent->lde_namelen)) == 0 &&
2318 le16_to_cpu(ent->lde_namelen) == 2)
2319 fid_cpu_to_le(&ent->lde_fid, &op_data->op_fid3);
2321 left_bytes -= ent_size;
2322 ent->lde_reclen = cpu_to_le16(ent_size);
2324 ent = (void *)ent + ent_size;
2325 hash_offset = le64_to_cpu(min_ent->lde_hash);
2326 if (hash_offset == MDS_DIR_END_OFF) {
2327 last_ent->lde_reclen = 0;
2332 if (min_ent_page != NULL) {
2333 kunmap(min_ent_page);
2334 put_page(min_ent_page);
2337 if (unlikely(rc != 0)) {
2338 __free_page(ent_page);
2342 dp->ldp_flags |= LDF_EMPTY;
2343 dp->ldp_flags = cpu_to_le32(dp->ldp_flags);
2344 dp->ldp_hash_end = cpu_to_le64(hash_offset);
2347 /* We do not want to allocate md_op_data during each
2348 * dir entry reading, so op_data will be shared by every stripe,
2349 * then we need to restore it back to original value before
2350 * return to the upper layer */
2351 op_data->op_fid1 = master_fid;
2352 op_data->op_fid2 = master_fid;
2353 op_data->op_data = master_inode;
2360 int lmv_read_page(struct obd_export *exp, struct md_op_data *op_data,
2361 struct md_callback *cb_op, __u64 offset,
2362 struct page **ppage)
2364 struct obd_device *obd = exp->exp_obd;
2365 struct lmv_obd *lmv = &obd->u.lmv;
2366 struct lmv_stripe_md *lsm = op_data->op_mea1;
2367 struct lmv_tgt_desc *tgt;
2371 if (unlikely(lsm != NULL)) {
2372 rc = lmv_read_striped_page(exp, op_data, cb_op, offset, ppage);
2376 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2378 RETURN(PTR_ERR(tgt));
2380 rc = md_read_page(tgt->ltd_exp, op_data, cb_op, offset, ppage);
2386 * Unlink a file/directory
2388 * Unlink a file or directory under the parent dir. The unlink request
2389 * usually will be sent to the MDT where the child is located, but if
2390 * the client does not have the child FID then request will be sent to the
2391 * MDT where the parent is located.
2393 * If the parent is a striped directory then it also needs to locate which
2394 * stripe the name of the child is located, and replace the parent FID
2395 * (@op->op_fid1) with the stripe FID. Note: if the stripe is unknown,
2396 * it will walk through all of sub-stripes until the child is being
2399 * \param[in] exp export refer to LMV
2400 * \param[in] op_data different parameters transferred beween client
2401 * MD stacks, name, namelen, FIDs etc.
2402 * op_fid1 is the parent FID, op_fid2 is the child
2404 * \param[out] request point to the request of unlink.
2406 * retval 0 if succeed
2407 * negative errno if failed.
2409 static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
2410 struct ptlrpc_request **request)
2412 struct obd_device *obd = exp->exp_obd;
2413 struct lmv_obd *lmv = &obd->u.lmv;
2414 struct lmv_tgt_desc *tgt = NULL;
2415 struct lmv_tgt_desc *parent_tgt = NULL;
2416 struct mdt_body *body;
2418 int stripe_index = 0;
2419 struct lmv_stripe_md *lsm = op_data->op_mea1;
2423 /* For striped dir, we need to locate the parent as well */
2425 struct lmv_tgt_desc *tmp;
2427 LASSERT(op_data->op_name != NULL &&
2428 op_data->op_namelen != 0);
2430 tmp = lmv_locate_target_for_name(lmv, lsm,
2432 op_data->op_namelen,
2436 /* return -EBADFD means unknown hash type, might
2437 * need try all sub-stripe here */
2438 if (IS_ERR(tmp) && PTR_ERR(tmp) != -EBADFD)
2439 RETURN(PTR_ERR(tmp));
2441 /* Note: both migrating dir and unknown hash dir need to
2442 * try all of sub-stripes, so we need start search the
2443 * name from stripe 0, but migrating dir is already handled
2444 * inside lmv_locate_target_for_name(), so we only check
2445 * unknown hash type directory here */
2446 if (!lmv_is_known_hash_type(lsm->lsm_md_hash_type)) {
2447 struct lmv_oinfo *oinfo;
2449 oinfo = &lsm->lsm_md_oinfo[stripe_index];
2451 op_data->op_fid1 = oinfo->lmo_fid;
2452 op_data->op_mds = oinfo->lmo_mds;
2457 /* Send unlink requests to the MDT where the child is located */
2458 if (likely(!fid_is_zero(&op_data->op_fid2)))
2459 tgt = lmv_find_target(lmv, &op_data->op_fid2);
2460 else if (lsm != NULL)
2461 tgt = lmv_get_target(lmv, op_data->op_mds, NULL);
2463 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
2466 RETURN(PTR_ERR(tgt));
2468 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
2469 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
2470 op_data->op_cap = cfs_curproc_cap_pack();
2473 * If child's fid is given, cancel unused locks for it if it is from
2474 * another export than parent.
2476 * LOOKUP lock for child (fid3) should also be cancelled on parent
2477 * tgt_tgt in mdc_unlink().
2479 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2482 * Cancel FULL locks on child (fid3).
2484 parent_tgt = lmv_find_target(lmv, &op_data->op_fid1);
2485 if (IS_ERR(parent_tgt))
2486 RETURN(PTR_ERR(parent_tgt));
2488 if (parent_tgt != tgt) {
2489 rc = lmv_early_cancel(exp, parent_tgt, op_data, tgt->ltd_idx,
2490 LCK_EX, MDS_INODELOCK_LOOKUP,
2491 MF_MDC_CANCEL_FID3);
2494 rc = lmv_early_cancel(exp, NULL, op_data, tgt->ltd_idx, LCK_EX,
2495 MDS_INODELOCK_FULL, MF_MDC_CANCEL_FID3);
2499 CDEBUG(D_INODE, "unlink with fid="DFID"/"DFID" -> mds #%u\n",
2500 PFID(&op_data->op_fid1), PFID(&op_data->op_fid2), tgt->ltd_idx);
2502 rc = md_unlink(tgt->ltd_exp, op_data, request);
2503 if (rc != 0 && rc != -EREMOTE && rc != -ENOENT)
2506 /* Try next stripe if it is needed. */
2507 if (rc == -ENOENT && lsm != NULL && lmv_need_try_all_stripes(lsm)) {
2508 struct lmv_oinfo *oinfo;
2511 if (stripe_index >= lsm->lsm_md_stripe_count)
2514 oinfo = &lsm->lsm_md_oinfo[stripe_index];
2516 op_data->op_fid1 = oinfo->lmo_fid;
2517 op_data->op_mds = oinfo->lmo_mds;
2519 ptlrpc_req_finished(*request);
2522 goto try_next_stripe;
2525 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
2529 /* Not cross-ref case, just get out of here. */
2530 if (likely(!(body->mbo_valid & OBD_MD_MDS)))
2533 CDEBUG(D_INODE, "%s: try unlink to another MDT for "DFID"\n",
2534 exp->exp_obd->obd_name, PFID(&body->mbo_fid1));
2536 /* This is a remote object, try remote MDT, Note: it may
2537 * try more than 1 time here, Considering following case
2538 * /mnt/lustre is root on MDT0, remote1 is on MDT1
2539 * 1. Initially A does not know where remote1 is, it send
2540 * unlink RPC to MDT0, MDT0 return -EREMOTE, it will
2541 * resend unlink RPC to MDT1 (retry 1st time).
2543 * 2. During the unlink RPC in flight,
2544 * client B mv /mnt/lustre/remote1 /mnt/lustre/remote2
2545 * and create new remote1, but on MDT0
2547 * 3. MDT1 get unlink RPC(from A), then do remote lock on
2548 * /mnt/lustre, then lookup get fid of remote1, and find
2549 * it is remote dir again, and replay -EREMOTE again.
2551 * 4. Then A will resend unlink RPC to MDT0. (retry 2nd times).
2553 * In theory, it might try unlimited time here, but it should
2554 * be very rare case. */
2555 op_data->op_fid2 = body->mbo_fid1;
2556 ptlrpc_req_finished(*request);
2562 static int lmv_precleanup(struct obd_device *obd)
2565 fld_client_proc_fini(&obd->u.lmv.lmv_fld);
2566 lprocfs_obd_cleanup(obd);
2567 lprocfs_free_md_stats(obd);
2572 * Get by key a value associated with a LMV device.
2574 * Dispatch request to lower-layer devices as needed.
2576 * \param[in] env execution environment for this thread
2577 * \param[in] exp export for the LMV device
2578 * \param[in] keylen length of key identifier
2579 * \param[in] key identifier of key to get value for
2580 * \param[in] vallen size of \a val
2581 * \param[out] val pointer to storage location for value
2582 * \param[in] lsm optional striping metadata of object
2584 * \retval 0 on success
2585 * \retval negative negated errno on failure
2587 static int lmv_get_info(const struct lu_env *env, struct obd_export *exp,
2588 __u32 keylen, void *key, __u32 *vallen, void *val)
2590 struct obd_device *obd;
2591 struct lmv_obd *lmv;
2595 obd = class_exp2obd(exp);
2597 CDEBUG(D_IOCTL, "Invalid client cookie %#llx\n",
2598 exp->exp_handle.h_cookie);
2603 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
2606 LASSERT(*vallen == sizeof(__u32));
2607 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2608 struct lmv_tgt_desc *tgt = lmv->tgts[i];
2610 * All tgts should be connected when this gets called.
2612 if (tgt == NULL || tgt->ltd_exp == NULL)
2615 if (!obd_get_info(env, tgt->ltd_exp, keylen, key,
2620 } else if (KEY_IS(KEY_MAX_EASIZE) ||
2621 KEY_IS(KEY_DEFAULT_EASIZE) ||
2622 KEY_IS(KEY_CONN_DATA)) {
2624 * Forwarding this request to first MDS, it should know LOV
2627 rc = obd_get_info(env, lmv->tgts[0]->ltd_exp, keylen, key,
2629 if (!rc && KEY_IS(KEY_CONN_DATA))
2630 exp->exp_connect_data = *(struct obd_connect_data *)val;
2632 } else if (KEY_IS(KEY_TGT_COUNT)) {
2633 *((int *)val) = lmv->desc.ld_tgt_count;
2637 CDEBUG(D_IOCTL, "Invalid key\n");
2642 * Asynchronously set by key a value associated with a LMV device.
2644 * Dispatch request to lower-layer devices as needed.
2646 * \param[in] env execution environment for this thread
2647 * \param[in] exp export for the LMV device
2648 * \param[in] keylen length of key identifier
2649 * \param[in] key identifier of key to store value for
2650 * \param[in] vallen size of value to store
2651 * \param[in] val pointer to data to be stored
2652 * \param[in] set optional list of related ptlrpc requests
2654 * \retval 0 on success
2655 * \retval negative negated errno on failure
2657 int lmv_set_info_async(const struct lu_env *env, struct obd_export *exp,
2658 __u32 keylen, void *key, __u32 vallen, void *val,
2659 struct ptlrpc_request_set *set)
2661 struct lmv_tgt_desc *tgt = NULL;
2662 struct obd_device *obd;
2663 struct lmv_obd *lmv;
2667 obd = class_exp2obd(exp);
2669 CDEBUG(D_IOCTL, "Invalid client cookie %#llx\n",
2670 exp->exp_handle.h_cookie);
2675 if (KEY_IS(KEY_READ_ONLY) || KEY_IS(KEY_FLUSH_CTX) ||
2676 KEY_IS(KEY_DEFAULT_EASIZE)) {
2679 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2682 if (tgt == NULL || tgt->ltd_exp == NULL)
2685 err = obd_set_info_async(env, tgt->ltd_exp,
2686 keylen, key, vallen, val, set);
2697 static int lmv_unpack_md_v1(struct obd_export *exp, struct lmv_stripe_md *lsm,
2698 const struct lmv_mds_md_v1 *lmm1)
2700 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2707 lsm->lsm_md_magic = le32_to_cpu(lmm1->lmv_magic);
2708 lsm->lsm_md_stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
2709 lsm->lsm_md_master_mdt_index = le32_to_cpu(lmm1->lmv_master_mdt_index);
2710 if (OBD_FAIL_CHECK(OBD_FAIL_UNKNOWN_LMV_STRIPE))
2711 lsm->lsm_md_hash_type = LMV_HASH_TYPE_UNKNOWN;
2713 lsm->lsm_md_hash_type = le32_to_cpu(lmm1->lmv_hash_type);
2714 lsm->lsm_md_layout_version = le32_to_cpu(lmm1->lmv_layout_version);
2715 cplen = strlcpy(lsm->lsm_md_pool_name, lmm1->lmv_pool_name,
2716 sizeof(lsm->lsm_md_pool_name));
2718 if (cplen >= sizeof(lsm->lsm_md_pool_name))
2721 CDEBUG(D_INFO, "unpack lsm count %d, master %d hash_type %d"
2722 "layout_version %d\n", lsm->lsm_md_stripe_count,
2723 lsm->lsm_md_master_mdt_index, lsm->lsm_md_hash_type,
2724 lsm->lsm_md_layout_version);
2726 stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
2727 for (i = 0; i < stripe_count; i++) {
2728 fid_le_to_cpu(&lsm->lsm_md_oinfo[i].lmo_fid,
2729 &lmm1->lmv_stripe_fids[i]);
2730 rc = lmv_fld_lookup(lmv, &lsm->lsm_md_oinfo[i].lmo_fid,
2731 &lsm->lsm_md_oinfo[i].lmo_mds);
2734 CDEBUG(D_INFO, "unpack fid #%d "DFID"\n", i,
2735 PFID(&lsm->lsm_md_oinfo[i].lmo_fid));
2741 static int lmv_unpackmd(struct obd_export *exp, struct lmv_stripe_md **lsmp,
2742 const union lmv_mds_md *lmm, size_t lmm_size)
2744 struct lmv_stripe_md *lsm;
2747 bool allocated = false;
2750 LASSERT(lsmp != NULL);
2754 if (lsm != NULL && lmm == NULL) {
2756 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
2757 /* For migrating inode, the master stripe and master
2758 * object will be the same, so do not need iput, see
2759 * ll_update_lsm_md */
2760 if (!(lsm->lsm_md_hash_type & LMV_HASH_FLAG_MIGRATION &&
2761 i == 0) && lsm->lsm_md_oinfo[i].lmo_root != NULL)
2762 iput(lsm->lsm_md_oinfo[i].lmo_root);
2764 lsm_size = lmv_stripe_md_size(lsm->lsm_md_stripe_count);
2765 OBD_FREE(lsm, lsm_size);
2770 if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_STRIPE)
2774 if (le32_to_cpu(lmm->lmv_magic) != LMV_MAGIC_V1 &&
2775 le32_to_cpu(lmm->lmv_magic) != LMV_USER_MAGIC) {
2776 CERROR("%s: invalid lmv magic %x: rc = %d\n",
2777 exp->exp_obd->obd_name, le32_to_cpu(lmm->lmv_magic),
2782 if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_V1)
2783 lsm_size = lmv_stripe_md_size(lmv_mds_md_stripe_count_get(lmm));
2786 * Unpack default dirstripe(lmv_user_md) to lmv_stripe_md,
2787 * stripecount should be 0 then.
2789 lsm_size = lmv_stripe_md_size(0);
2791 lsm_size = lmv_stripe_md_size(lmv_mds_md_stripe_count_get(lmm));
2793 OBD_ALLOC(lsm, lsm_size);
2800 switch (le32_to_cpu(lmm->lmv_magic)) {
2802 rc = lmv_unpack_md_v1(exp, lsm, &lmm->lmv_md_v1);
2805 CERROR("%s: unrecognized magic %x\n", exp->exp_obd->obd_name,
2806 le32_to_cpu(lmm->lmv_magic));
2811 if (rc != 0 && allocated) {
2812 OBD_FREE(lsm, lsm_size);
2819 void lmv_free_memmd(struct lmv_stripe_md *lsm)
2821 lmv_unpackmd(NULL, &lsm, NULL, 0);
2823 EXPORT_SYMBOL(lmv_free_memmd);
2825 static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
2826 union ldlm_policy_data *policy,
2827 enum ldlm_mode mode, enum ldlm_cancel_flags flags,
2830 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2835 LASSERT(fid != NULL);
2837 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2838 struct lmv_tgt_desc *tgt = lmv->tgts[i];
2841 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
2844 err = md_cancel_unused(tgt->ltd_exp, fid, policy, mode, flags,
2852 static int lmv_set_lock_data(struct obd_export *exp,
2853 const struct lustre_handle *lockh,
2854 void *data, __u64 *bits)
2856 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2857 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2861 if (tgt == NULL || tgt->ltd_exp == NULL)
2863 rc = md_set_lock_data(tgt->ltd_exp, lockh, data, bits);
2867 enum ldlm_mode lmv_lock_match(struct obd_export *exp, __u64 flags,
2868 const struct lu_fid *fid, enum ldlm_type type,
2869 union ldlm_policy_data *policy,
2870 enum ldlm_mode mode, struct lustre_handle *lockh)
2872 struct obd_device *obd = exp->exp_obd;
2873 struct lmv_obd *lmv = &obd->u.lmv;
2879 CDEBUG(D_INODE, "Lock match for "DFID"\n", PFID(fid));
2882 * With DNE every object can have two locks in different namespaces:
2883 * lookup lock in space of MDT storing direntry and update/open lock in
2884 * space of MDT storing inode. Try the MDT that the FID maps to first,
2885 * since this can be easily found, and only try others if that fails.
2887 for (i = 0, tgt = lmv_find_target_index(lmv, fid);
2888 i < lmv->desc.ld_tgt_count;
2889 i++, tgt = (tgt + 1) % lmv->desc.ld_tgt_count) {
2891 CDEBUG(D_HA, "%s: "DFID" is inaccessible: rc = %d\n",
2892 obd->obd_name, PFID(fid), tgt);
2896 if (lmv->tgts[tgt] == NULL ||
2897 lmv->tgts[tgt]->ltd_exp == NULL ||
2898 lmv->tgts[tgt]->ltd_active == 0)
2901 rc = md_lock_match(lmv->tgts[tgt]->ltd_exp, flags, fid,
2902 type, policy, mode, lockh);
2910 int lmv_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
2911 struct obd_export *dt_exp, struct obd_export *md_exp,
2912 struct lustre_md *md)
2914 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2915 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2917 if (tgt == NULL || tgt->ltd_exp == NULL)
2920 return md_get_lustre_md(lmv->tgts[0]->ltd_exp, req, dt_exp, md_exp, md);
2923 int lmv_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
2925 struct obd_device *obd = exp->exp_obd;
2926 struct lmv_obd *lmv = &obd->u.lmv;
2927 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2930 if (md->lmv != NULL) {
2931 lmv_free_memmd(md->lmv);
2934 if (tgt == NULL || tgt->ltd_exp == NULL)
2936 RETURN(md_free_lustre_md(lmv->tgts[0]->ltd_exp, md));
2939 int lmv_set_open_replay_data(struct obd_export *exp,
2940 struct obd_client_handle *och,
2941 struct lookup_intent *it)
2943 struct obd_device *obd = exp->exp_obd;
2944 struct lmv_obd *lmv = &obd->u.lmv;
2945 struct lmv_tgt_desc *tgt;
2948 tgt = lmv_find_target(lmv, &och->och_fid);
2950 RETURN(PTR_ERR(tgt));
2952 RETURN(md_set_open_replay_data(tgt->ltd_exp, och, it));
2955 int lmv_clear_open_replay_data(struct obd_export *exp,
2956 struct obd_client_handle *och)
2958 struct obd_device *obd = exp->exp_obd;
2959 struct lmv_obd *lmv = &obd->u.lmv;
2960 struct lmv_tgt_desc *tgt;
2963 tgt = lmv_find_target(lmv, &och->och_fid);
2965 RETURN(PTR_ERR(tgt));
2967 RETURN(md_clear_open_replay_data(tgt->ltd_exp, och));
2970 int lmv_intent_getattr_async(struct obd_export *exp,
2971 struct md_enqueue_info *minfo)
2973 struct md_op_data *op_data = &minfo->mi_data;
2974 struct obd_device *obd = exp->exp_obd;
2975 struct lmv_obd *lmv = &obd->u.lmv;
2976 struct lmv_tgt_desc *ptgt = NULL;
2977 struct lmv_tgt_desc *ctgt = NULL;
2981 if (!fid_is_sane(&op_data->op_fid2))
2984 ptgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
2986 RETURN(PTR_ERR(ptgt));
2988 ctgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
2990 RETURN(PTR_ERR(ctgt));
2993 * if child is on remote MDT, we need 2 async RPCs to fetch both LOOKUP
2994 * lock on parent, and UPDATE lock on child MDT, which makes all
2995 * complicated. Considering remote dir is rare case, and not supporting
2996 * it in statahead won't cause any issue, drop its support for now.
3001 rc = md_intent_getattr_async(ptgt->ltd_exp, minfo);
3005 int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
3006 struct lu_fid *fid, __u64 *bits)
3008 struct obd_device *obd = exp->exp_obd;
3009 struct lmv_obd *lmv = &obd->u.lmv;
3010 struct lmv_tgt_desc *tgt;
3014 tgt = lmv_find_target(lmv, fid);
3016 RETURN(PTR_ERR(tgt));
3018 rc = md_revalidate_lock(tgt->ltd_exp, it, fid, bits);
3022 int lmv_get_fid_from_lsm(struct obd_export *exp,
3023 const struct lmv_stripe_md *lsm,
3024 const char *name, int namelen, struct lu_fid *fid)
3026 const struct lmv_oinfo *oinfo;
3028 LASSERT(lsm != NULL);
3029 oinfo = lsm_name_to_stripe_info(lsm, name, namelen);
3031 return PTR_ERR(oinfo);
3033 *fid = oinfo->lmo_fid;
3039 * For lmv, only need to send request to master MDT, and the master MDT will
3040 * process with other slave MDTs. The only exception is Q_GETOQUOTA for which
3041 * we directly fetch data from the slave MDTs.
3043 int lmv_quotactl(struct obd_device *unused, struct obd_export *exp,
3044 struct obd_quotactl *oqctl)
3046 struct obd_device *obd = class_exp2obd(exp);
3047 struct lmv_obd *lmv = &obd->u.lmv;
3048 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3051 __u64 curspace, curinodes;
3055 tgt->ltd_exp == NULL ||
3057 lmv->desc.ld_tgt_count == 0) {
3058 CERROR("master lmv inactive\n");
3062 if (oqctl->qc_cmd != Q_GETOQUOTA) {
3063 rc = obd_quotactl(tgt->ltd_exp, oqctl);
3067 curspace = curinodes = 0;
3068 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
3072 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
3075 err = obd_quotactl(tgt->ltd_exp, oqctl);
3077 CERROR("getquota on mdt %d failed. %d\n", i, err);
3081 curspace += oqctl->qc_dqblk.dqb_curspace;
3082 curinodes += oqctl->qc_dqblk.dqb_curinodes;
3085 oqctl->qc_dqblk.dqb_curspace = curspace;
3086 oqctl->qc_dqblk.dqb_curinodes = curinodes;
3091 static int lmv_merge_attr(struct obd_export *exp,
3092 const struct lmv_stripe_md *lsm,
3093 struct cl_attr *attr,
3094 ldlm_blocking_callback cb_blocking)
3099 rc = lmv_revalidate_slaves(exp, lsm, cb_blocking, 0);
3103 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
3104 struct inode *inode = lsm->lsm_md_oinfo[i].lmo_root;
3106 CDEBUG(D_INFO, ""DFID" size %llu, blocks %llu nlink %u,"
3107 " atime %lu ctime %lu, mtime %lu.\n",
3108 PFID(&lsm->lsm_md_oinfo[i].lmo_fid),
3109 i_size_read(inode), (unsigned long long)inode->i_blocks,
3110 inode->i_nlink, LTIME_S(inode->i_atime),
3111 LTIME_S(inode->i_ctime), LTIME_S(inode->i_mtime));
3113 /* for slave stripe, it needs to subtract nlink for . and .. */
3115 attr->cat_nlink += inode->i_nlink - 2;
3117 attr->cat_nlink = inode->i_nlink;
3119 attr->cat_size += i_size_read(inode);
3120 attr->cat_blocks += inode->i_blocks;
3122 if (attr->cat_atime < LTIME_S(inode->i_atime))
3123 attr->cat_atime = LTIME_S(inode->i_atime);
3125 if (attr->cat_ctime < LTIME_S(inode->i_ctime))
3126 attr->cat_ctime = LTIME_S(inode->i_ctime);
3128 if (attr->cat_mtime < LTIME_S(inode->i_mtime))
3129 attr->cat_mtime = LTIME_S(inode->i_mtime);
3134 struct obd_ops lmv_obd_ops = {
3135 .o_owner = THIS_MODULE,
3136 .o_setup = lmv_setup,
3137 .o_cleanup = lmv_cleanup,
3138 .o_precleanup = lmv_precleanup,
3139 .o_process_config = lmv_process_config,
3140 .o_connect = lmv_connect,
3141 .o_disconnect = lmv_disconnect,
3142 .o_statfs = lmv_statfs,
3143 .o_get_info = lmv_get_info,
3144 .o_set_info_async = lmv_set_info_async,
3145 .o_notify = lmv_notify,
3146 .o_get_uuid = lmv_get_uuid,
3147 .o_iocontrol = lmv_iocontrol,
3148 .o_quotactl = lmv_quotactl
3151 struct md_ops lmv_md_ops = {
3152 .m_get_root = lmv_get_root,
3153 .m_null_inode = lmv_null_inode,
3154 .m_close = lmv_close,
3155 .m_create = lmv_create,
3156 .m_enqueue = lmv_enqueue,
3157 .m_getattr = lmv_getattr,
3158 .m_getxattr = lmv_getxattr,
3159 .m_getattr_name = lmv_getattr_name,
3160 .m_intent_lock = lmv_intent_lock,
3162 .m_rename = lmv_rename,
3163 .m_setattr = lmv_setattr,
3164 .m_setxattr = lmv_setxattr,
3165 .m_fsync = lmv_fsync,
3166 .m_read_page = lmv_read_page,
3167 .m_unlink = lmv_unlink,
3168 .m_init_ea_size = lmv_init_ea_size,
3169 .m_cancel_unused = lmv_cancel_unused,
3170 .m_set_lock_data = lmv_set_lock_data,
3171 .m_lock_match = lmv_lock_match,
3172 .m_get_lustre_md = lmv_get_lustre_md,
3173 .m_free_lustre_md = lmv_free_lustre_md,
3174 .m_merge_attr = lmv_merge_attr,
3175 .m_set_open_replay_data = lmv_set_open_replay_data,
3176 .m_clear_open_replay_data = lmv_clear_open_replay_data,
3177 .m_intent_getattr_async = lmv_intent_getattr_async,
3178 .m_revalidate_lock = lmv_revalidate_lock,
3179 .m_get_fid_from_lsm = lmv_get_fid_from_lsm,
3180 .m_unpackmd = lmv_unpackmd,
3183 static int __init lmv_init(void)
3185 return class_register_type(&lmv_obd_ops, &lmv_md_ops, true, NULL,
3186 LUSTRE_LMV_NAME, NULL);
3189 static void __exit lmv_exit(void)
3191 class_unregister_type(LUSTRE_LMV_NAME);
3194 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
3195 MODULE_DESCRIPTION("Lustre Logical Metadata Volume");
3196 MODULE_VERSION(LUSTRE_VERSION_STRING);
3197 MODULE_LICENSE("GPL");
3199 module_init(lmv_init);
3200 module_exit(lmv_exit);