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) 2004, 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_LMV
38 #include <linux/slab.h>
39 #include <linux/module.h>
40 #include <linux/init.h>
41 #include <linux/user_namespace.h>
42 #ifdef HAVE_UIDGID_HEADER
43 # include <linux/uidgid.h>
45 #include <linux/slab.h>
46 #include <linux/pagemap.h>
48 #include <linux/math64.h>
49 #include <linux/seq_file.h>
50 #include <linux/namei.h>
52 #include <lustre/lustre_idl.h>
53 #include <obd_support.h>
54 #include <lustre_lib.h>
55 #include <lustre_net.h>
56 #include <obd_class.h>
57 #include <lustre_lmv.h>
58 #include <lprocfs_status.h>
59 #include <cl_object.h>
60 #include <lustre_fid.h>
61 #include <lustre_ioctl.h>
62 #include <lustre_kernelcomm.h>
63 #include "lmv_internal.h"
65 static int lmv_check_connect(struct obd_device *obd);
67 static void lmv_activate_target(struct lmv_obd *lmv,
68 struct lmv_tgt_desc *tgt,
71 if (tgt->ltd_active == activate)
74 tgt->ltd_active = activate;
75 lmv->desc.ld_active_tgt_count += (activate ? 1 : -1);
77 tgt->ltd_exp->exp_obd->obd_inactive = !activate;
83 * -EINVAL : UUID can't be found in the LMV's target list
84 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
85 * -EBADF : The UUID is found, but the OBD of the wrong type (!)
87 static int lmv_set_mdc_active(struct lmv_obd *lmv,
88 const struct obd_uuid *uuid,
91 struct lmv_tgt_desc *tgt = NULL;
92 struct obd_device *obd;
97 CDEBUG(D_INFO, "Searching in lmv %p for uuid %s (activate=%d)\n",
98 lmv, uuid->uuid, activate);
100 spin_lock(&lmv->lmv_lock);
101 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
103 if (tgt == NULL || tgt->ltd_exp == NULL)
106 CDEBUG(D_INFO, "Target idx %d is %s conn %#llx\n", i,
107 tgt->ltd_uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
109 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
113 if (i == lmv->desc.ld_tgt_count)
114 GOTO(out_lmv_lock, rc = -EINVAL);
116 obd = class_exp2obd(tgt->ltd_exp);
118 GOTO(out_lmv_lock, rc = -ENOTCONN);
120 CDEBUG(D_INFO, "Found OBD %s=%s device %d (%p) type %s at LMV idx %d\n",
121 obd->obd_name, obd->obd_uuid.uuid, obd->obd_minor, obd,
122 obd->obd_type->typ_name, i);
123 LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0);
125 if (tgt->ltd_active == activate) {
126 CDEBUG(D_INFO, "OBD %p already %sactive!\n", obd,
127 activate ? "" : "in");
128 GOTO(out_lmv_lock, rc);
131 CDEBUG(D_INFO, "Marking OBD %p %sactive\n", obd,
132 activate ? "" : "in");
133 lmv_activate_target(lmv, tgt, activate);
137 spin_unlock(&lmv->lmv_lock);
141 struct obd_uuid *lmv_get_uuid(struct obd_export *exp)
143 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
144 struct lmv_tgt_desc *tgt = lmv->tgts[0];
146 return (tgt == NULL) ? NULL : obd_get_uuid(tgt->ltd_exp);
149 static int lmv_notify(struct obd_device *obd, struct obd_device *watched,
150 enum obd_notify_event ev, void *data)
152 struct obd_connect_data *conn_data;
153 struct lmv_obd *lmv = &obd->u.lmv;
154 struct obd_uuid *uuid;
158 if (strcmp(watched->obd_type->typ_name, LUSTRE_MDC_NAME)) {
159 CERROR("unexpected notification of %s %s!\n",
160 watched->obd_type->typ_name,
165 uuid = &watched->u.cli.cl_target_uuid;
166 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE) {
168 * Set MDC as active before notifying the observer, so the
169 * observer can use the MDC normally.
171 rc = lmv_set_mdc_active(lmv, uuid,
172 ev == OBD_NOTIFY_ACTIVE);
174 CERROR("%sactivation of %s failed: %d\n",
175 ev == OBD_NOTIFY_ACTIVE ? "" : "de",
179 } else if (ev == OBD_NOTIFY_OCD) {
180 conn_data = &watched->u.cli.cl_import->imp_connect_data;
182 * XXX: Make sure that ocd_connect_flags from all targets are
183 * the same. Otherwise one of MDTs runs wrong version or
184 * something like this. --umka
186 obd->obd_self_export->exp_connect_data = *conn_data;
190 * Pass the notification up the chain.
192 if (obd->obd_observer)
193 rc = obd_notify(obd->obd_observer, watched, ev, data);
198 static int lmv_connect(const struct lu_env *env,
199 struct obd_export **pexp, struct obd_device *obd,
200 struct obd_uuid *cluuid, struct obd_connect_data *data,
203 struct lmv_obd *lmv = &obd->u.lmv;
204 struct lustre_handle conn = { 0 };
205 struct obd_export *exp;
209 rc = class_connect(&conn, obd, cluuid);
211 CERROR("class_connection() returned %d\n", rc);
215 exp = class_conn2export(&conn);
218 lmv->cluuid = *cluuid;
219 lmv->conn_data = *data;
221 if (lmv->targets_proc_entry == NULL) {
222 lmv->targets_proc_entry = lprocfs_register("target_obds",
225 if (IS_ERR(lmv->targets_proc_entry)) {
226 CERROR("%s: cannot register "
227 "/proc/fs/lustre/%s/%s/target_obds\n",
228 obd->obd_name, obd->obd_type->typ_name,
230 lmv->targets_proc_entry = NULL;
234 rc = lmv_check_connect(obd);
243 if (lmv->targets_proc_entry != NULL)
244 lprocfs_remove(&lmv->targets_proc_entry);
246 class_disconnect(exp);
251 static int lmv_init_ea_size(struct obd_export *exp, __u32 easize,
254 struct obd_device *obd = exp->exp_obd;
255 struct lmv_obd *lmv = &obd->u.lmv;
261 if (lmv->max_easize < easize) {
262 lmv->max_easize = easize;
265 if (lmv->max_def_easize < def_easize) {
266 lmv->max_def_easize = def_easize;
273 if (lmv->connected == 0)
276 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
277 struct lmv_tgt_desc *tgt = lmv->tgts[i];
279 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active) {
280 CWARN("%s: NULL export for %d\n", obd->obd_name, i);
284 rc = md_init_ea_size(tgt->ltd_exp, easize, def_easize);
286 CERROR("%s: obd_init_ea_size() failed on MDT target %d:"
287 " rc = %d\n", obd->obd_name, i, rc);
294 #define MAX_STRING_SIZE 128
296 int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
298 struct lmv_obd *lmv = &obd->u.lmv;
299 struct obd_uuid *cluuid = &lmv->cluuid;
300 struct obd_uuid lmv_mdc_uuid = { "LMV_MDC_UUID" };
301 struct obd_device *mdc_obd;
302 struct obd_export *mdc_exp;
303 struct lu_fld_target target;
307 mdc_obd = class_find_client_obd(&tgt->ltd_uuid, LUSTRE_MDC_NAME,
310 CERROR("target %s not attached\n", tgt->ltd_uuid.uuid);
314 CDEBUG(D_CONFIG, "connect to %s(%s) - %s, %s FOR %s\n",
315 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
316 tgt->ltd_uuid.uuid, obd->obd_uuid.uuid,
319 if (!mdc_obd->obd_set_up) {
320 CERROR("target %s is not set up\n", tgt->ltd_uuid.uuid);
324 rc = obd_connect(NULL, &mdc_exp, mdc_obd, &lmv_mdc_uuid,
325 &lmv->conn_data, NULL);
327 CERROR("target %s connect error %d\n", tgt->ltd_uuid.uuid, rc);
332 * Init fid sequence client for this mdc and add new fld target.
334 rc = obd_fid_init(mdc_obd, mdc_exp, LUSTRE_SEQ_METADATA);
338 target.ft_srv = NULL;
339 target.ft_exp = mdc_exp;
340 target.ft_idx = tgt->ltd_idx;
342 fld_client_add_target(&lmv->lmv_fld, &target);
344 rc = obd_register_observer(mdc_obd, obd);
346 obd_disconnect(mdc_exp);
347 CERROR("target %s register_observer error %d\n",
348 tgt->ltd_uuid.uuid, rc);
352 if (obd->obd_observer) {
354 * Tell the observer about the new target.
356 rc = obd_notify(obd->obd_observer, mdc_exp->exp_obd,
358 (void *)(tgt - lmv->tgts[0]));
360 obd_disconnect(mdc_exp);
366 tgt->ltd_exp = mdc_exp;
367 lmv->desc.ld_active_tgt_count++;
369 md_init_ea_size(tgt->ltd_exp, lmv->max_easize, lmv->max_def_easize);
371 CDEBUG(D_CONFIG, "Connected to %s(%s) successfully (%d)\n",
372 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
373 atomic_read(&obd->obd_refcount));
375 if (lmv->targets_proc_entry != NULL) {
376 struct proc_dir_entry *mdc_symlink;
378 LASSERT(mdc_obd->obd_type != NULL);
379 LASSERT(mdc_obd->obd_type->typ_name != NULL);
380 mdc_symlink = lprocfs_add_symlink(mdc_obd->obd_name,
381 lmv->targets_proc_entry,
383 mdc_obd->obd_type->typ_name,
385 if (mdc_symlink == NULL) {
386 CERROR("cannot register LMV target "
387 "/proc/fs/lustre/%s/%s/target_obds/%s\n",
388 obd->obd_type->typ_name, obd->obd_name,
395 static void lmv_del_target(struct lmv_obd *lmv, int index)
397 if (lmv->tgts[index] == NULL)
400 OBD_FREE_PTR(lmv->tgts[index]);
401 lmv->tgts[index] = NULL;
405 static int lmv_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
406 __u32 index, int gen)
408 struct obd_device *mdc_obd;
409 struct lmv_obd *lmv = &obd->u.lmv;
410 struct lmv_tgt_desc *tgt;
411 int orig_tgt_count = 0;
415 CDEBUG(D_CONFIG, "Target uuid: %s. index %d\n", uuidp->uuid, index);
416 mdc_obd = class_find_client_obd(uuidp, LUSTRE_MDC_NAME,
419 CERROR("%s: Target %s not attached: rc = %d\n",
420 obd->obd_name, uuidp->uuid, -EINVAL);
424 mutex_lock(&lmv->lmv_init_mutex);
425 if ((index < lmv->tgts_size) && (lmv->tgts[index] != NULL)) {
426 tgt = lmv->tgts[index];
427 CERROR("%s: UUID %s already assigned at LOV target index %d:"
428 " rc = %d\n", obd->obd_name,
429 obd_uuid2str(&tgt->ltd_uuid), index, -EEXIST);
430 mutex_unlock(&lmv->lmv_init_mutex);
434 if (index >= lmv->tgts_size) {
435 /* We need to reallocate the lmv target array. */
436 struct lmv_tgt_desc **newtgts, **old = NULL;
440 while (newsize < index + 1)
441 newsize = newsize << 1;
442 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
443 if (newtgts == NULL) {
444 mutex_unlock(&lmv->lmv_init_mutex);
448 if (lmv->tgts_size) {
449 memcpy(newtgts, lmv->tgts,
450 sizeof(*newtgts) * lmv->tgts_size);
452 oldsize = lmv->tgts_size;
456 lmv->tgts_size = newsize;
459 OBD_FREE(old, sizeof(*old) * oldsize);
461 CDEBUG(D_CONFIG, "tgts: %p size: %d\n", lmv->tgts,
467 mutex_unlock(&lmv->lmv_init_mutex);
471 mutex_init(&tgt->ltd_fid_mutex);
472 tgt->ltd_idx = index;
473 tgt->ltd_uuid = *uuidp;
475 lmv->tgts[index] = tgt;
476 if (index >= lmv->desc.ld_tgt_count) {
477 orig_tgt_count = lmv->desc.ld_tgt_count;
478 lmv->desc.ld_tgt_count = index + 1;
481 if (lmv->connected == 0) {
482 /* lmv_check_connect() will connect this target. */
483 mutex_unlock(&lmv->lmv_init_mutex);
487 /* Otherwise let's connect it ourselves */
488 mutex_unlock(&lmv->lmv_init_mutex);
489 rc = lmv_connect_mdc(obd, tgt);
491 spin_lock(&lmv->lmv_lock);
492 if (lmv->desc.ld_tgt_count == index + 1)
493 lmv->desc.ld_tgt_count = orig_tgt_count;
494 memset(tgt, 0, sizeof(*tgt));
495 spin_unlock(&lmv->lmv_lock);
497 int easize = sizeof(struct lmv_stripe_md) +
498 lmv->desc.ld_tgt_count * sizeof(struct lu_fid);
499 lmv_init_ea_size(obd->obd_self_export, easize, 0);
505 static int lmv_check_connect(struct obd_device *obd)
507 struct lmv_obd *lmv = &obd->u.lmv;
508 struct lmv_tgt_desc *tgt;
517 mutex_lock(&lmv->lmv_init_mutex);
518 if (lmv->connected) {
519 mutex_unlock(&lmv->lmv_init_mutex);
523 if (lmv->desc.ld_tgt_count == 0) {
524 mutex_unlock(&lmv->lmv_init_mutex);
525 CERROR("%s: no targets configured.\n", obd->obd_name);
529 LASSERT(lmv->tgts != NULL);
531 if (lmv->tgts[0] == NULL) {
532 mutex_unlock(&lmv->lmv_init_mutex);
533 CERROR("%s: no target configured for index 0.\n",
538 CDEBUG(D_CONFIG, "Time to connect %s to %s\n",
539 lmv->cluuid.uuid, obd->obd_name);
541 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
545 rc = lmv_connect_mdc(obd, tgt);
551 easize = lmv_mds_md_size(lmv->desc.ld_tgt_count, LMV_MAGIC);
552 lmv_init_ea_size(obd->obd_self_export, easize, 0);
553 mutex_unlock(&lmv->lmv_init_mutex);
564 --lmv->desc.ld_active_tgt_count;
565 rc2 = obd_disconnect(tgt->ltd_exp);
567 CERROR("LMV target %s disconnect on "
568 "MDC idx %d: error %d\n",
569 tgt->ltd_uuid.uuid, i, rc2);
574 mutex_unlock(&lmv->lmv_init_mutex);
579 static int lmv_disconnect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
581 struct lmv_obd *lmv = &obd->u.lmv;
582 struct obd_device *mdc_obd;
586 LASSERT(tgt != NULL);
587 LASSERT(obd != NULL);
589 mdc_obd = class_exp2obd(tgt->ltd_exp);
592 mdc_obd->obd_force = obd->obd_force;
593 mdc_obd->obd_fail = obd->obd_fail;
594 mdc_obd->obd_no_recov = obd->obd_no_recov;
596 if (lmv->targets_proc_entry != NULL)
597 lprocfs_remove_proc_entry(mdc_obd->obd_name,
598 lmv->targets_proc_entry);
601 rc = obd_fid_fini(tgt->ltd_exp->exp_obd);
603 CERROR("Can't finanize fids factory\n");
605 CDEBUG(D_INFO, "Disconnected from %s(%s) successfully\n",
606 tgt->ltd_exp->exp_obd->obd_name,
607 tgt->ltd_exp->exp_obd->obd_uuid.uuid);
609 obd_register_observer(tgt->ltd_exp->exp_obd, NULL);
610 rc = obd_disconnect(tgt->ltd_exp);
612 if (tgt->ltd_active) {
613 CERROR("Target %s disconnect error %d\n",
614 tgt->ltd_uuid.uuid, rc);
618 lmv_activate_target(lmv, tgt, 0);
623 static int lmv_disconnect(struct obd_export *exp)
625 struct obd_device *obd = class_exp2obd(exp);
626 struct lmv_obd *lmv = &obd->u.lmv;
634 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
635 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
638 lmv_disconnect_mdc(obd, lmv->tgts[i]);
641 if (lmv->targets_proc_entry != NULL)
642 lprocfs_remove(&lmv->targets_proc_entry);
644 CERROR("/proc/fs/lustre/%s/%s/target_obds missing\n",
645 obd->obd_type->typ_name, obd->obd_name);
649 * This is the case when no real connection is established by
650 * lmv_check_connect().
653 class_export_put(exp);
654 rc = class_disconnect(exp);
660 static int lmv_fid2path(struct obd_export *exp, int len, void *karg,
663 struct obd_device *obddev = class_exp2obd(exp);
664 struct lmv_obd *lmv = &obddev->u.lmv;
665 struct getinfo_fid2path *gf;
666 struct lmv_tgt_desc *tgt;
667 struct getinfo_fid2path *remote_gf = NULL;
668 struct lu_fid root_fid;
669 int remote_gf_size = 0;
673 tgt = lmv_find_target(lmv, &gf->gf_fid);
675 RETURN(PTR_ERR(tgt));
677 root_fid = *gf->gf_u.gf_root_fid;
678 LASSERT(fid_is_sane(&root_fid));
681 rc = obd_iocontrol(OBD_IOC_FID2PATH, tgt->ltd_exp, len, gf, uarg);
682 if (rc != 0 && rc != -EREMOTE)
683 GOTO(out_fid2path, rc);
685 /* If remote_gf != NULL, it means just building the
686 * path on the remote MDT, copy this path segement to gf */
687 if (remote_gf != NULL) {
688 struct getinfo_fid2path *ori_gf;
691 ori_gf = (struct getinfo_fid2path *)karg;
692 if (strlen(ori_gf->gf_u.gf_path) +
693 strlen(gf->gf_u.gf_path) > ori_gf->gf_pathlen)
694 GOTO(out_fid2path, rc = -EOVERFLOW);
696 ptr = ori_gf->gf_u.gf_path;
698 memmove(ptr + strlen(gf->gf_u.gf_path) + 1, ptr,
699 strlen(ori_gf->gf_u.gf_path));
701 strncpy(ptr, gf->gf_u.gf_path,
702 strlen(gf->gf_u.gf_path));
703 ptr += strlen(gf->gf_u.gf_path);
707 CDEBUG(D_INFO, "%s: get path %s "DFID" rec: %llu ln: %u\n",
708 tgt->ltd_exp->exp_obd->obd_name,
709 gf->gf_u.gf_path, PFID(&gf->gf_fid), gf->gf_recno,
713 GOTO(out_fid2path, rc);
715 /* sigh, has to go to another MDT to do path building further */
716 if (remote_gf == NULL) {
717 remote_gf_size = sizeof(*remote_gf) + PATH_MAX;
718 OBD_ALLOC(remote_gf, remote_gf_size);
719 if (remote_gf == NULL)
720 GOTO(out_fid2path, rc = -ENOMEM);
721 remote_gf->gf_pathlen = PATH_MAX;
724 if (!fid_is_sane(&gf->gf_fid)) {
725 CERROR("%s: invalid FID "DFID": rc = %d\n",
726 tgt->ltd_exp->exp_obd->obd_name,
727 PFID(&gf->gf_fid), -EINVAL);
728 GOTO(out_fid2path, rc = -EINVAL);
731 tgt = lmv_find_target(lmv, &gf->gf_fid);
733 GOTO(out_fid2path, rc = -EINVAL);
735 remote_gf->gf_fid = gf->gf_fid;
736 remote_gf->gf_recno = -1;
737 remote_gf->gf_linkno = -1;
738 memset(remote_gf->gf_u.gf_path, 0, remote_gf->gf_pathlen);
739 *remote_gf->gf_u.gf_root_fid = root_fid;
741 goto repeat_fid2path;
744 if (remote_gf != NULL)
745 OBD_FREE(remote_gf, remote_gf_size);
749 static int lmv_hsm_req_count(struct lmv_obd *lmv,
750 const struct hsm_user_request *hur,
751 const struct lmv_tgt_desc *tgt_mds)
755 struct lmv_tgt_desc *curr_tgt;
757 /* count how many requests must be sent to the given target */
758 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
759 curr_tgt = lmv_find_target(lmv, &hur->hur_user_item[i].hui_fid);
760 if (IS_ERR(curr_tgt))
761 RETURN(PTR_ERR(curr_tgt));
762 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid))
768 static int lmv_hsm_req_build(struct lmv_obd *lmv,
769 struct hsm_user_request *hur_in,
770 const struct lmv_tgt_desc *tgt_mds,
771 struct hsm_user_request *hur_out)
774 struct lmv_tgt_desc *curr_tgt;
776 /* build the hsm_user_request for the given target */
777 hur_out->hur_request = hur_in->hur_request;
779 for (i = 0; i < hur_in->hur_request.hr_itemcount; i++) {
780 curr_tgt = lmv_find_target(lmv,
781 &hur_in->hur_user_item[i].hui_fid);
782 if (IS_ERR(curr_tgt))
783 RETURN(PTR_ERR(curr_tgt));
784 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid)) {
785 hur_out->hur_user_item[nr_out] =
786 hur_in->hur_user_item[i];
790 hur_out->hur_request.hr_itemcount = nr_out;
791 memcpy(hur_data(hur_out), hur_data(hur_in),
792 hur_in->hur_request.hr_data_len);
797 static int lmv_hsm_ct_unregister(struct lmv_obd *lmv, unsigned int cmd, int len,
798 struct lustre_kernelcomm *lk,
805 /* unregister request (call from llapi_hsm_copytool_fini) */
806 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
807 struct lmv_tgt_desc *tgt = lmv->tgts[i];
809 if (tgt == NULL || tgt->ltd_exp == NULL)
811 /* best effort: try to clean as much as possible
812 * (continue on error) */
813 obd_iocontrol(cmd, tgt->ltd_exp, len, lk, uarg);
816 /* Whatever the result, remove copytool from kuc groups.
817 * Unreached coordinators will get EPIPE on next requests
818 * and will unregister automatically.
820 rc = libcfs_kkuc_group_rem(lk->lk_uid, lk->lk_group);
825 static int lmv_hsm_ct_register(struct lmv_obd *lmv, unsigned int cmd, int len,
826 struct lustre_kernelcomm *lk, __user void *uarg)
831 bool any_set = false;
832 struct kkuc_ct_data kcd = { 0 };
835 /* All or nothing: try to register to all MDS.
836 * In case of failure, unregister from previous MDS,
837 * except if it because of inactive target. */
838 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
839 struct lmv_tgt_desc *tgt = lmv->tgts[i];
841 if (tgt == NULL || tgt->ltd_exp == NULL)
843 err = obd_iocontrol(cmd, tgt->ltd_exp, len, lk, uarg);
845 if (tgt->ltd_active) {
846 /* permanent error */
847 CERROR("%s: iocontrol MDC %s on MDT"
848 " idx %d cmd %x: err = %d\n",
849 lmv2obd_dev(lmv)->obd_name,
850 tgt->ltd_uuid.uuid, i, cmd, err);
852 lk->lk_flags |= LK_FLG_STOP;
853 /* unregister from previous MDS */
854 for (j = 0; j < i; j++) {
856 if (tgt == NULL || tgt->ltd_exp == NULL)
858 obd_iocontrol(cmd, tgt->ltd_exp, len,
863 /* else: transient error.
864 * kuc will register to the missing MDT
872 /* no registration done: return error */
875 /* at least one registration done, with no failure */
876 filp = fget(lk->lk_wfd);
880 kcd.kcd_magic = KKUC_CT_DATA_MAGIC;
881 kcd.kcd_uuid = lmv->cluuid;
882 kcd.kcd_archive = lk->lk_data;
884 rc = libcfs_kkuc_group_add(filp, lk->lk_uid, lk->lk_group,
895 static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
896 int len, void *karg, void __user *uarg)
898 struct obd_device *obddev = class_exp2obd(exp);
899 struct lmv_obd *lmv = &obddev->u.lmv;
900 struct lmv_tgt_desc *tgt = NULL;
904 __u32 count = lmv->desc.ld_tgt_count;
911 case IOC_OBD_STATFS: {
912 struct obd_ioctl_data *data = karg;
913 struct obd_device *mdc_obd;
914 struct obd_statfs stat_buf = {0};
917 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
918 if ((index >= count))
921 tgt = lmv->tgts[index];
922 if (tgt == NULL || !tgt->ltd_active)
925 mdc_obd = class_exp2obd(tgt->ltd_exp);
930 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(mdc_obd),
931 min((int) data->ioc_plen2,
932 (int) sizeof(struct obd_uuid))))
935 rc = obd_statfs(NULL, tgt->ltd_exp, &stat_buf,
936 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
940 if (copy_to_user(data->ioc_pbuf1, &stat_buf,
941 min((int) data->ioc_plen1,
942 (int) sizeof(stat_buf))))
946 case OBD_IOC_QUOTACTL: {
947 struct if_quotactl *qctl = karg;
948 struct obd_quotactl *oqctl;
950 if (qctl->qc_valid == QC_MDTIDX) {
951 if (count <= qctl->qc_idx)
954 tgt = lmv->tgts[qctl->qc_idx];
955 if (tgt == NULL || tgt->ltd_exp == NULL)
957 } else if (qctl->qc_valid == QC_UUID) {
958 for (i = 0; i < count; i++) {
962 if (!obd_uuid_equals(&tgt->ltd_uuid,
966 if (tgt->ltd_exp == NULL)
978 LASSERT(tgt != NULL && tgt->ltd_exp != NULL);
979 OBD_ALLOC_PTR(oqctl);
983 QCTL_COPY(oqctl, qctl);
984 rc = obd_quotactl(tgt->ltd_exp, oqctl);
986 QCTL_COPY(qctl, oqctl);
987 qctl->qc_valid = QC_MDTIDX;
988 qctl->obd_uuid = tgt->ltd_uuid;
993 case OBD_IOC_CHANGELOG_SEND:
994 case OBD_IOC_CHANGELOG_CLEAR: {
995 struct ioc_changelog *icc = karg;
997 if (icc->icc_mdtindex >= count)
1000 tgt = lmv->tgts[icc->icc_mdtindex];
1001 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
1003 rc = obd_iocontrol(cmd, tgt->ltd_exp, sizeof(*icc), icc, NULL);
1006 case LL_IOC_GET_CONNECT_FLAGS: {
1008 if (tgt == NULL || tgt->ltd_exp == NULL)
1010 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1013 case LL_IOC_FID2MDTIDX: {
1014 struct lu_fid *fid = karg;
1017 rc = lmv_fld_lookup(lmv, fid, &mdt_index);
1021 /* Note: this is from llite(see ll_dir_ioctl()), @uarg does not
1022 * point to user space memory for FID2MDTIDX. */
1023 *(__u32 *)uarg = mdt_index;
1026 case OBD_IOC_FID2PATH: {
1027 rc = lmv_fid2path(exp, len, karg, uarg);
1030 case LL_IOC_HSM_STATE_GET:
1031 case LL_IOC_HSM_STATE_SET:
1032 case LL_IOC_HSM_ACTION: {
1033 struct md_op_data *op_data = karg;
1035 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1037 RETURN(PTR_ERR(tgt));
1039 if (tgt->ltd_exp == NULL)
1042 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1045 case LL_IOC_HSM_PROGRESS: {
1046 const struct hsm_progress_kernel *hpk = karg;
1048 tgt = lmv_find_target(lmv, &hpk->hpk_fid);
1050 RETURN(PTR_ERR(tgt));
1051 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1054 case LL_IOC_HSM_REQUEST: {
1055 struct hsm_user_request *hur = karg;
1056 unsigned int reqcount = hur->hur_request.hr_itemcount;
1061 /* if the request is about a single fid
1062 * or if there is a single MDS, no need to split
1064 if (reqcount == 1 || count == 1) {
1065 tgt = lmv_find_target(lmv,
1066 &hur->hur_user_item[0].hui_fid);
1068 RETURN(PTR_ERR(tgt));
1069 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1071 /* split fid list to their respective MDS */
1072 for (i = 0; i < count; i++) {
1075 struct hsm_user_request *req;
1078 if (tgt == NULL || tgt->ltd_exp == NULL)
1081 nr = lmv_hsm_req_count(lmv, hur, tgt);
1084 if (nr == 0) /* nothing for this MDS */
1087 /* build a request with fids for this MDS */
1088 reqlen = offsetof(typeof(*hur),
1090 + hur->hur_request.hr_data_len;
1091 OBD_ALLOC_LARGE(req, reqlen);
1094 rc1 = lmv_hsm_req_build(lmv, hur, tgt, req);
1096 GOTO(hsm_req_err, rc1);
1097 rc1 = obd_iocontrol(cmd, tgt->ltd_exp, reqlen,
1100 if (rc1 != 0 && rc == 0)
1102 OBD_FREE_LARGE(req, reqlen);
1107 case LL_IOC_LOV_SWAP_LAYOUTS: {
1108 struct md_op_data *op_data = karg;
1109 struct lmv_tgt_desc *tgt1, *tgt2;
1111 tgt1 = lmv_find_target(lmv, &op_data->op_fid1);
1113 RETURN(PTR_ERR(tgt1));
1115 tgt2 = lmv_find_target(lmv, &op_data->op_fid2);
1117 RETURN(PTR_ERR(tgt2));
1119 if ((tgt1->ltd_exp == NULL) || (tgt2->ltd_exp == NULL))
1122 /* only files on same MDT can have their layouts swapped */
1123 if (tgt1->ltd_idx != tgt2->ltd_idx)
1126 rc = obd_iocontrol(cmd, tgt1->ltd_exp, len, karg, uarg);
1129 case LL_IOC_HSM_CT_START: {
1130 struct lustre_kernelcomm *lk = karg;
1131 if (lk->lk_flags & LK_FLG_STOP)
1132 rc = lmv_hsm_ct_unregister(lmv, cmd, len, lk, uarg);
1134 rc = lmv_hsm_ct_register(lmv, cmd, len, lk, uarg);
1138 for (i = 0; i < count; i++) {
1139 struct obd_device *mdc_obd;
1143 if (tgt == NULL || tgt->ltd_exp == NULL)
1145 /* ll_umount_begin() sets force flag but for lmv, not
1146 * mdc. Let's pass it through */
1147 mdc_obd = class_exp2obd(tgt->ltd_exp);
1148 mdc_obd->obd_force = obddev->obd_force;
1149 err = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1151 if (tgt->ltd_active) {
1152 CERROR("error: iocontrol MDC %s on MDT"
1153 " idx %d cmd %x: err = %d\n",
1154 tgt->ltd_uuid.uuid, i, cmd, err);
1168 * This is _inode_ placement policy function (not name).
1170 static int lmv_placement_policy(struct obd_device *obd,
1171 struct md_op_data *op_data, u32 *mds)
1173 struct lmv_obd *lmv = &obd->u.lmv;
1176 LASSERT(mds != NULL);
1178 if (lmv->desc.ld_tgt_count == 1) {
1183 if (op_data->op_default_stripe_offset != -1) {
1184 *mds = op_data->op_default_stripe_offset;
1189 * If stripe_offset is provided during setdirstripe
1190 * (setdirstripe -i xx), xx MDS will be choosen.
1192 if (op_data->op_cli_flags & CLI_SET_MEA && op_data->op_data != NULL) {
1193 struct lmv_user_md *lum;
1195 lum = op_data->op_data;
1197 if (le32_to_cpu(lum->lum_stripe_offset) != (__u32)-1) {
1198 *mds = le32_to_cpu(lum->lum_stripe_offset);
1200 /* -1 means default, which will be in the same MDT with
1202 *mds = op_data->op_mds;
1203 lum->lum_stripe_offset = cpu_to_le32(op_data->op_mds);
1206 /* Allocate new fid on target according to operation type and
1207 * parent home mds. */
1208 *mds = op_data->op_mds;
1214 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid, u32 mds)
1216 struct lmv_tgt_desc *tgt;
1220 tgt = lmv_get_target(lmv, mds, NULL);
1222 RETURN(PTR_ERR(tgt));
1225 * New seq alloc and FLD setup should be atomic. Otherwise we may find
1226 * on server that seq in new allocated fid is not yet known.
1228 mutex_lock(&tgt->ltd_fid_mutex);
1230 if (tgt->ltd_active == 0 || tgt->ltd_exp == NULL)
1231 GOTO(out, rc = -ENODEV);
1234 * Asking underlying tgt layer to allocate new fid.
1236 rc = obd_fid_alloc(NULL, tgt->ltd_exp, fid, NULL);
1238 LASSERT(fid_is_sane(fid));
1244 mutex_unlock(&tgt->ltd_fid_mutex);
1248 int lmv_fid_alloc(const struct lu_env *env, struct obd_export *exp,
1249 struct lu_fid *fid, struct md_op_data *op_data)
1251 struct obd_device *obd = class_exp2obd(exp);
1252 struct lmv_obd *lmv = &obd->u.lmv;
1257 LASSERT(op_data != NULL);
1258 LASSERT(fid != NULL);
1260 rc = lmv_placement_policy(obd, op_data, &mds);
1262 CERROR("Can't get target for allocating fid, "
1267 rc = __lmv_fid_alloc(lmv, fid, mds);
1269 CERROR("Can't alloc new fid, rc %d\n", rc);
1276 static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
1278 struct lmv_obd *lmv = &obd->u.lmv;
1279 struct lmv_desc *desc;
1283 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
1284 CERROR("LMV setup requires a descriptor\n");
1288 desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1);
1289 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
1290 CERROR("Lmv descriptor size wrong: %d > %d\n",
1291 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
1295 lmv->tgts_size = 32U;
1296 OBD_ALLOC(lmv->tgts, sizeof(*lmv->tgts) * lmv->tgts_size);
1297 if (lmv->tgts == NULL)
1300 obd_str2uuid(&lmv->desc.ld_uuid, desc->ld_uuid.uuid);
1301 lmv->desc.ld_tgt_count = 0;
1302 lmv->desc.ld_active_tgt_count = 0;
1303 lmv->max_def_easize = 0;
1304 lmv->max_easize = 0;
1306 spin_lock_init(&lmv->lmv_lock);
1307 mutex_init(&lmv->lmv_init_mutex);
1309 #ifdef CONFIG_PROC_FS
1310 obd->obd_vars = lprocfs_lmv_obd_vars;
1311 lprocfs_obd_setup(obd);
1312 lprocfs_alloc_md_stats(obd, 0);
1313 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
1314 0444, &lmv_proc_target_fops, obd);
1316 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
1319 rc = fld_client_init(&lmv->lmv_fld, obd->obd_name,
1320 LUSTRE_CLI_FLD_HASH_DHT);
1322 CERROR("Can't init FLD, err %d\n", rc);
1332 static int lmv_cleanup(struct obd_device *obd)
1334 struct lmv_obd *lmv = &obd->u.lmv;
1337 fld_client_fini(&lmv->lmv_fld);
1338 if (lmv->tgts != NULL) {
1340 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1341 if (lmv->tgts[i] == NULL)
1343 lmv_del_target(lmv, i);
1345 OBD_FREE(lmv->tgts, sizeof(*lmv->tgts) * lmv->tgts_size);
1351 static int lmv_process_config(struct obd_device *obd, size_t len, void *buf)
1353 struct lustre_cfg *lcfg = buf;
1354 struct obd_uuid obd_uuid;
1360 switch (lcfg->lcfg_command) {
1362 /* modify_mdc_tgts add 0:lustre-clilmv 1:lustre-MDT0000_UUID
1363 * 2:0 3:1 4:lustre-MDT0000-mdc_UUID */
1364 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
1365 GOTO(out, rc = -EINVAL);
1367 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
1369 if (sscanf(lustre_cfg_buf(lcfg, 2), "%u", &index) != 1)
1370 GOTO(out, rc = -EINVAL);
1371 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
1372 GOTO(out, rc = -EINVAL);
1373 rc = lmv_add_target(obd, &obd_uuid, index, gen);
1376 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1377 GOTO(out, rc = -EINVAL);
1383 static int lmv_statfs(const struct lu_env *env, struct obd_export *exp,
1384 struct obd_statfs *osfs, __u64 max_age, __u32 flags)
1386 struct obd_device *obd = class_exp2obd(exp);
1387 struct lmv_obd *lmv = &obd->u.lmv;
1388 struct obd_statfs *temp;
1393 OBD_ALLOC(temp, sizeof(*temp));
1397 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1398 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1401 rc = obd_statfs(env, lmv->tgts[i]->ltd_exp, temp,
1404 CERROR("can't stat MDS #%d (%s), error %d\n", i,
1405 lmv->tgts[i]->ltd_exp->exp_obd->obd_name,
1407 GOTO(out_free_temp, rc);
1412 /* If the statfs is from mount, it will needs
1413 * retrieve necessary information from MDT0.
1414 * i.e. mount does not need the merged osfs
1416 * And also clients can be mounted as long as
1417 * MDT0 is in service*/
1418 if (flags & OBD_STATFS_FOR_MDT0)
1419 GOTO(out_free_temp, rc);
1421 osfs->os_bavail += temp->os_bavail;
1422 osfs->os_blocks += temp->os_blocks;
1423 osfs->os_ffree += temp->os_ffree;
1424 osfs->os_files += temp->os_files;
1430 OBD_FREE(temp, sizeof(*temp));
1434 static int lmv_get_root(struct obd_export *exp, const char *fileset,
1437 struct obd_device *obd = exp->exp_obd;
1438 struct lmv_obd *lmv = &obd->u.lmv;
1442 rc = md_get_root(lmv->tgts[0]->ltd_exp, fileset, fid);
1446 static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1447 u64 valid, const char *name,
1448 const char *input, int input_size, int output_size,
1449 int flags, struct ptlrpc_request **request)
1451 struct obd_device *obd = exp->exp_obd;
1452 struct lmv_obd *lmv = &obd->u.lmv;
1453 struct lmv_tgt_desc *tgt;
1457 tgt = lmv_find_target(lmv, fid);
1459 RETURN(PTR_ERR(tgt));
1461 rc = md_getxattr(tgt->ltd_exp, fid, valid, name, input,
1462 input_size, output_size, flags, request);
1467 static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1468 u64 valid, const char *name,
1469 const char *input, int input_size, int output_size,
1470 int flags, __u32 suppgid,
1471 struct ptlrpc_request **request)
1473 struct obd_device *obd = exp->exp_obd;
1474 struct lmv_obd *lmv = &obd->u.lmv;
1475 struct lmv_tgt_desc *tgt;
1479 tgt = lmv_find_target(lmv, fid);
1481 RETURN(PTR_ERR(tgt));
1483 rc = md_setxattr(tgt->ltd_exp, fid, valid, name, input,
1484 input_size, output_size, flags, suppgid,
1490 static int lmv_getattr(struct obd_export *exp, struct md_op_data *op_data,
1491 struct ptlrpc_request **request)
1493 struct obd_device *obd = exp->exp_obd;
1494 struct lmv_obd *lmv = &obd->u.lmv;
1495 struct lmv_tgt_desc *tgt;
1499 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1501 RETURN(PTR_ERR(tgt));
1503 if (op_data->op_flags & MF_GET_MDT_IDX) {
1504 op_data->op_mds = tgt->ltd_idx;
1508 rc = md_getattr(tgt->ltd_exp, op_data, request);
1513 static int lmv_null_inode(struct obd_export *exp, const struct lu_fid *fid)
1515 struct obd_device *obd = exp->exp_obd;
1516 struct lmv_obd *lmv = &obd->u.lmv;
1520 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1523 * With DNE every object can have two locks in different namespaces:
1524 * lookup lock in space of MDT storing direntry and update/open lock in
1525 * space of MDT storing inode.
1527 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1528 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1530 md_null_inode(lmv->tgts[i]->ltd_exp, fid);
1536 static int lmv_close(struct obd_export *exp, struct md_op_data *op_data,
1537 struct md_open_data *mod, struct ptlrpc_request **request)
1539 struct obd_device *obd = exp->exp_obd;
1540 struct lmv_obd *lmv = &obd->u.lmv;
1541 struct lmv_tgt_desc *tgt;
1545 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1547 RETURN(PTR_ERR(tgt));
1549 CDEBUG(D_INODE, "CLOSE "DFID"\n", PFID(&op_data->op_fid1));
1550 rc = md_close(tgt->ltd_exp, op_data, mod, request);
1555 * Choosing the MDT by name or FID in @op_data.
1556 * For non-striped directory, it will locate MDT by fid.
1557 * For striped-directory, it will locate MDT by name. And also
1558 * it will reset op_fid1 with the FID of the choosen stripe.
1560 struct lmv_tgt_desc *
1561 lmv_locate_target_for_name(struct lmv_obd *lmv, struct lmv_stripe_md *lsm,
1562 const char *name, int namelen, struct lu_fid *fid,
1565 struct lmv_tgt_desc *tgt;
1566 const struct lmv_oinfo *oinfo;
1568 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_NAME_HASH)) {
1569 if (cfs_fail_val >= lsm->lsm_md_stripe_count)
1570 RETURN(ERR_PTR(-EBADF));
1571 oinfo = &lsm->lsm_md_oinfo[cfs_fail_val];
1573 oinfo = lsm_name_to_stripe_info(lsm, name, namelen);
1575 RETURN(ERR_CAST(oinfo));
1579 *fid = oinfo->lmo_fid;
1581 *mds = oinfo->lmo_mds;
1583 tgt = lmv_get_target(lmv, oinfo->lmo_mds, NULL);
1585 CDEBUG(D_INFO, "locate on mds %u "DFID"\n", oinfo->lmo_mds,
1586 PFID(&oinfo->lmo_fid));
1591 * Locate mds by fid or name
1593 * For striped directory (lsm != NULL), it will locate the stripe
1594 * by name hash (see lsm_name_to_stripe_info()). Note: if the hash_type
1595 * is unknown, it will return -EBADFD, and lmv_intent_lookup might need
1596 * walk through all of stripes to locate the entry.
1598 * For normal direcotry, it will locate MDS by FID directly.
1599 * \param[in] lmv LMV device
1600 * \param[in] op_data client MD stack parameters, name, namelen
1602 * \param[in] fid object FID used to locate MDS.
1604 * retval pointer to the lmv_tgt_desc if succeed.
1605 * ERR_PTR(errno) if failed.
1607 struct lmv_tgt_desc*
1608 lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1611 struct lmv_stripe_md *lsm = op_data->op_mea1;
1612 struct lmv_tgt_desc *tgt;
1614 /* During creating VOLATILE file, it should honor the mdt
1615 * index if the file under striped dir is being restored, see
1617 if (op_data->op_bias & MDS_CREATE_VOLATILE &&
1618 (int)op_data->op_mds != -1) {
1620 tgt = lmv_get_target(lmv, op_data->op_mds, NULL);
1625 /* refill the right parent fid */
1626 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1627 struct lmv_oinfo *oinfo;
1629 oinfo = &lsm->lsm_md_oinfo[i];
1630 if (oinfo->lmo_mds == op_data->op_mds) {
1631 *fid = oinfo->lmo_fid;
1636 if (i == lsm->lsm_md_stripe_count)
1637 *fid = lsm->lsm_md_oinfo[0].lmo_fid;
1643 if (lsm == NULL || op_data->op_namelen == 0) {
1644 tgt = lmv_find_target(lmv, fid);
1648 op_data->op_mds = tgt->ltd_idx;
1652 return lmv_locate_target_for_name(lmv, lsm, op_data->op_name,
1653 op_data->op_namelen, fid,
1657 int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
1658 const void *data, size_t datalen, umode_t mode, uid_t uid,
1659 gid_t gid, cfs_cap_t cap_effective, __u64 rdev,
1660 struct ptlrpc_request **request)
1662 struct obd_device *obd = exp->exp_obd;
1663 struct lmv_obd *lmv = &obd->u.lmv;
1664 struct lmv_tgt_desc *tgt;
1668 if (!lmv->desc.ld_active_tgt_count)
1671 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1673 RETURN(PTR_ERR(tgt));
1675 CDEBUG(D_INODE, "CREATE name '%.*s' on "DFID" -> mds #%x\n",
1676 (int)op_data->op_namelen, op_data->op_name,
1677 PFID(&op_data->op_fid1), op_data->op_mds);
1679 rc = lmv_fid_alloc(NULL, exp, &op_data->op_fid2, op_data);
1682 if (exp_connect_flags(exp) & OBD_CONNECT_DIR_STRIPE) {
1683 /* Send the create request to the MDT where the object
1684 * will be located */
1685 tgt = lmv_find_target(lmv, &op_data->op_fid2);
1687 RETURN(PTR_ERR(tgt));
1689 op_data->op_mds = tgt->ltd_idx;
1691 CDEBUG(D_CONFIG, "Server doesn't support striped dirs\n");
1694 CDEBUG(D_INODE, "CREATE obj "DFID" -> mds #%x\n",
1695 PFID(&op_data->op_fid2), op_data->op_mds);
1697 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1698 rc = md_create(tgt->ltd_exp, op_data, data, datalen, mode, uid, gid,
1699 cap_effective, rdev, request);
1701 if (*request == NULL)
1703 CDEBUG(D_INODE, "Created - "DFID"\n", PFID(&op_data->op_fid2));
1709 lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1710 const union ldlm_policy_data *policy, struct md_op_data *op_data,
1711 struct lustre_handle *lockh, __u64 extra_lock_flags)
1713 struct obd_device *obd = exp->exp_obd;
1714 struct lmv_obd *lmv = &obd->u.lmv;
1715 struct lmv_tgt_desc *tgt;
1719 CDEBUG(D_INODE, "ENQUEUE on "DFID"\n", PFID(&op_data->op_fid1));
1721 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1723 RETURN(PTR_ERR(tgt));
1725 CDEBUG(D_INODE, "ENQUEUE on "DFID" -> mds #%u\n",
1726 PFID(&op_data->op_fid1), tgt->ltd_idx);
1728 rc = md_enqueue(tgt->ltd_exp, einfo, policy, op_data, lockh,
1735 lmv_getattr_name(struct obd_export *exp,struct md_op_data *op_data,
1736 struct ptlrpc_request **preq)
1738 struct ptlrpc_request *req = NULL;
1739 struct obd_device *obd = exp->exp_obd;
1740 struct lmv_obd *lmv = &obd->u.lmv;
1741 struct lmv_tgt_desc *tgt;
1742 struct mdt_body *body;
1746 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1748 RETURN(PTR_ERR(tgt));
1750 CDEBUG(D_INODE, "GETATTR_NAME for %*s on "DFID" -> mds #%d\n",
1751 (int)op_data->op_namelen, op_data->op_name,
1752 PFID(&op_data->op_fid1), tgt->ltd_idx);
1754 rc = md_getattr_name(tgt->ltd_exp, op_data, preq);
1758 body = req_capsule_server_get(&(*preq)->rq_pill, &RMF_MDT_BODY);
1759 LASSERT(body != NULL);
1761 if (body->mbo_valid & OBD_MD_MDS) {
1762 struct lu_fid rid = body->mbo_fid1;
1763 CDEBUG(D_INODE, "Request attrs for "DFID"\n",
1766 tgt = lmv_find_target(lmv, &rid);
1768 ptlrpc_req_finished(*preq);
1770 RETURN(PTR_ERR(tgt));
1773 op_data->op_fid1 = rid;
1774 op_data->op_valid |= OBD_MD_FLCROSSREF;
1775 op_data->op_namelen = 0;
1776 op_data->op_name = NULL;
1777 rc = md_getattr_name(tgt->ltd_exp, op_data, &req);
1778 ptlrpc_req_finished(*preq);
1785 #define md_op_data_fid(op_data, fl) \
1786 (fl == MF_MDC_CANCEL_FID1 ? &op_data->op_fid1 : \
1787 fl == MF_MDC_CANCEL_FID2 ? &op_data->op_fid2 : \
1788 fl == MF_MDC_CANCEL_FID3 ? &op_data->op_fid3 : \
1789 fl == MF_MDC_CANCEL_FID4 ? &op_data->op_fid4 : \
1792 static int lmv_early_cancel(struct obd_export *exp, struct lmv_tgt_desc *tgt,
1793 struct md_op_data *op_data, __u32 op_tgt,
1794 enum ldlm_mode mode, int bits, int flag)
1796 struct lu_fid *fid = md_op_data_fid(op_data, flag);
1797 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
1798 union ldlm_policy_data policy = { { 0 } };
1802 if (!fid_is_sane(fid))
1806 tgt = lmv_find_target(lmv, fid);
1808 RETURN(PTR_ERR(tgt));
1811 if (tgt->ltd_idx != op_tgt) {
1812 CDEBUG(D_INODE, "EARLY_CANCEL on "DFID"\n", PFID(fid));
1813 policy.l_inodebits.bits = bits;
1814 rc = md_cancel_unused(tgt->ltd_exp, fid, &policy,
1815 mode, LCF_ASYNC, NULL);
1818 "EARLY_CANCEL skip operation target %d on "DFID"\n",
1820 op_data->op_flags |= flag;
1828 * llite passes fid of an target inode in op_data->op_fid1 and id of directory in
1831 static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
1832 struct ptlrpc_request **request)
1834 struct obd_device *obd = exp->exp_obd;
1835 struct lmv_obd *lmv = &obd->u.lmv;
1836 struct lmv_tgt_desc *tgt;
1840 LASSERT(op_data->op_namelen != 0);
1842 CDEBUG(D_INODE, "LINK "DFID":%*s to "DFID"\n",
1843 PFID(&op_data->op_fid2), (int)op_data->op_namelen,
1844 op_data->op_name, PFID(&op_data->op_fid1));
1846 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
1847 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
1848 op_data->op_cap = cfs_curproc_cap_pack();
1849 if (op_data->op_mea2 != NULL) {
1850 struct lmv_stripe_md *lsm = op_data->op_mea2;
1851 const struct lmv_oinfo *oinfo;
1853 oinfo = lsm_name_to_stripe_info(lsm, op_data->op_name,
1854 op_data->op_namelen);
1856 RETURN(PTR_ERR(oinfo));
1858 op_data->op_fid2 = oinfo->lmo_fid;
1861 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
1863 RETURN(PTR_ERR(tgt));
1866 * Cancel UPDATE lock on child (fid1).
1868 op_data->op_flags |= MF_MDC_CANCEL_FID2;
1869 rc = lmv_early_cancel(exp, NULL, op_data, tgt->ltd_idx, LCK_EX,
1870 MDS_INODELOCK_UPDATE, MF_MDC_CANCEL_FID1);
1874 rc = md_link(tgt->ltd_exp, op_data, request);
1879 static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
1880 const char *old, size_t oldlen,
1881 const char *new, size_t newlen,
1882 struct ptlrpc_request **request)
1884 struct obd_device *obd = exp->exp_obd;
1885 struct lmv_obd *lmv = &obd->u.lmv;
1886 struct lmv_tgt_desc *src_tgt;
1887 struct lmv_tgt_desc *tgt_tgt;
1888 struct obd_export *target_exp;
1889 struct mdt_body *body;
1893 LASSERT(oldlen != 0);
1895 CDEBUG(D_INODE, "RENAME %.*s in "DFID":%d to %.*s in "DFID":%d\n",
1896 (int)oldlen, old, PFID(&op_data->op_fid1),
1897 op_data->op_mea1 ? op_data->op_mea1->lsm_md_stripe_count : 0,
1898 (int)newlen, new, PFID(&op_data->op_fid2),
1899 op_data->op_mea2 ? op_data->op_mea2->lsm_md_stripe_count : 0);
1901 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
1902 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
1903 op_data->op_cap = cfs_curproc_cap_pack();
1904 if (op_data->op_cli_flags & CLI_MIGRATE) {
1905 LASSERTF(fid_is_sane(&op_data->op_fid3), "invalid FID "DFID"\n",
1906 PFID(&op_data->op_fid3));
1908 if (op_data->op_mea1 != NULL) {
1909 struct lmv_stripe_md *lsm = op_data->op_mea1;
1910 struct lmv_tgt_desc *tmp;
1912 /* Fix the parent fid for striped dir */
1913 tmp = lmv_locate_target_for_name(lmv, lsm, old,
1918 RETURN(PTR_ERR(tmp));
1921 rc = lmv_fid_alloc(NULL, exp, &op_data->op_fid2, op_data);
1925 src_tgt = lmv_find_target(lmv, &op_data->op_fid3);
1926 if (IS_ERR(src_tgt))
1927 RETURN(PTR_ERR(src_tgt));
1929 target_exp = src_tgt->ltd_exp;
1931 if (op_data->op_mea1 != NULL) {
1932 struct lmv_stripe_md *lsm = op_data->op_mea1;
1934 src_tgt = lmv_locate_target_for_name(lmv, lsm, old,
1939 src_tgt = lmv_find_target(lmv, &op_data->op_fid1);
1941 if (IS_ERR(src_tgt))
1942 RETURN(PTR_ERR(src_tgt));
1945 if (op_data->op_mea2 != NULL) {
1946 struct lmv_stripe_md *lsm = op_data->op_mea2;
1948 tgt_tgt = lmv_locate_target_for_name(lmv, lsm, new,
1953 tgt_tgt = lmv_find_target(lmv, &op_data->op_fid2);
1956 if (IS_ERR(tgt_tgt))
1957 RETURN(PTR_ERR(tgt_tgt));
1959 target_exp = tgt_tgt->ltd_exp;
1963 * LOOKUP lock on src child (fid3) should also be cancelled for
1964 * src_tgt in mdc_rename.
1966 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
1969 * Cancel UPDATE locks on tgt parent (fid2), tgt_tgt is its
1972 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
1973 LCK_EX, MDS_INODELOCK_UPDATE,
1974 MF_MDC_CANCEL_FID2);
1979 * Cancel LOOKUP locks on source child (fid3) for parent tgt_tgt.
1981 if (fid_is_sane(&op_data->op_fid3)) {
1982 struct lmv_tgt_desc *tgt;
1984 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1986 RETURN(PTR_ERR(tgt));
1988 /* Cancel LOOKUP lock on its parent */
1989 rc = lmv_early_cancel(exp, tgt, op_data, src_tgt->ltd_idx,
1990 LCK_EX, MDS_INODELOCK_LOOKUP,
1991 MF_MDC_CANCEL_FID3);
1995 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
1996 LCK_EX, MDS_INODELOCK_FULL,
1997 MF_MDC_CANCEL_FID3);
2004 * Cancel all the locks on tgt child (fid4).
2006 if (fid_is_sane(&op_data->op_fid4)) {
2007 struct lmv_tgt_desc *tgt;
2009 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
2010 LCK_EX, MDS_INODELOCK_FULL,
2011 MF_MDC_CANCEL_FID4);
2015 tgt = lmv_find_target(lmv, &op_data->op_fid4);
2017 RETURN(PTR_ERR(tgt));
2019 /* Since the target child might be destroyed, and it might
2020 * become orphan, and we can only check orphan on the local
2021 * MDT right now, so we send rename request to the MDT where
2022 * target child is located. If target child does not exist,
2023 * then it will send the request to the target parent */
2024 target_exp = tgt->ltd_exp;
2027 rc = md_rename(target_exp, op_data, old, oldlen, new, newlen,
2030 if (rc != 0 && rc != -EXDEV)
2033 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
2037 /* Not cross-ref case, just get out of here. */
2038 if (likely(!(body->mbo_valid & OBD_MD_MDS)))
2041 CDEBUG(D_INODE, "%s: try rename to another MDT for "DFID"\n",
2042 exp->exp_obd->obd_name, PFID(&body->mbo_fid1));
2044 op_data->op_fid4 = body->mbo_fid1;
2045 ptlrpc_req_finished(*request);
2050 static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
2051 void *ea, size_t ealen, struct ptlrpc_request **request)
2053 struct obd_device *obd = exp->exp_obd;
2054 struct lmv_obd *lmv = &obd->u.lmv;
2055 struct lmv_tgt_desc *tgt;
2059 CDEBUG(D_INODE, "SETATTR for "DFID", valid 0x%x\n",
2060 PFID(&op_data->op_fid1), op_data->op_attr.ia_valid);
2062 op_data->op_flags |= MF_MDC_CANCEL_FID1;
2063 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2065 RETURN(PTR_ERR(tgt));
2067 rc = md_setattr(tgt->ltd_exp, op_data, ea, ealen, request);
2072 static int lmv_fsync(struct obd_export *exp, const struct lu_fid *fid,
2073 struct ptlrpc_request **request)
2075 struct obd_device *obd = exp->exp_obd;
2076 struct lmv_obd *lmv = &obd->u.lmv;
2077 struct lmv_tgt_desc *tgt;
2081 tgt = lmv_find_target(lmv, fid);
2083 RETURN(PTR_ERR(tgt));
2085 rc = md_fsync(tgt->ltd_exp, fid, request);
2090 * Get current minimum entry from striped directory
2092 * This function will search the dir entry, whose hash value is the
2093 * closest(>=) to @hash_offset, from all of sub-stripes, and it is
2094 * only being called for striped directory.
2096 * \param[in] exp export of LMV
2097 * \param[in] op_data parameters transferred beween client MD stack
2098 * stripe_information will be included in this
2100 * \param[in] cb_op ldlm callback being used in enqueue in
2102 * \param[in] hash_offset the hash value, which is used to locate
2103 * minum(closet) dir entry
2104 * \param[in|out] stripe_offset the caller use this to indicate the stripe
2105 * index of last entry, so to avoid hash conflict
2106 * between stripes. It will also be used to
2107 * return the stripe index of current dir entry.
2108 * \param[in|out] entp the minum entry and it also is being used
2109 * to input the last dir entry to resolve the
2112 * \param[out] ppage the page which holds the minum entry
2114 * \retval = 0 get the entry successfully
2115 * negative errno (< 0) does not get the entry
2117 static int lmv_get_min_striped_entry(struct obd_export *exp,
2118 struct md_op_data *op_data,
2119 struct md_callback *cb_op,
2120 __u64 hash_offset, int *stripe_offset,
2121 struct lu_dirent **entp,
2122 struct page **ppage)
2124 struct obd_device *obd = exp->exp_obd;
2125 struct lmv_obd *lmv = &obd->u.lmv;
2126 struct lmv_stripe_md *lsm = op_data->op_mea1;
2127 struct lmv_tgt_desc *tgt;
2129 struct lu_dirent *min_ent = NULL;
2130 struct page *min_page = NULL;
2136 stripe_count = lsm->lsm_md_stripe_count;
2137 for (i = 0; i < stripe_count; i++) {
2138 struct lu_dirent *ent = NULL;
2139 struct page *page = NULL;
2140 struct lu_dirpage *dp;
2141 __u64 stripe_hash = hash_offset;
2143 tgt = lmv_get_target(lmv, lsm->lsm_md_oinfo[i].lmo_mds, NULL);
2145 GOTO(out, rc = PTR_ERR(tgt));
2147 /* op_data will be shared by each stripe, so we need
2148 * reset these value for each stripe */
2149 op_data->op_fid1 = lsm->lsm_md_oinfo[i].lmo_fid;
2150 op_data->op_fid2 = lsm->lsm_md_oinfo[i].lmo_fid;
2151 op_data->op_data = lsm->lsm_md_oinfo[i].lmo_root;
2153 rc = md_read_page(tgt->ltd_exp, op_data, cb_op, stripe_hash,
2158 dp = page_address(page);
2159 for (ent = lu_dirent_start(dp); ent != NULL;
2160 ent = lu_dirent_next(ent)) {
2161 /* Skip dummy entry */
2162 if (le16_to_cpu(ent->lde_namelen) == 0)
2165 if (le64_to_cpu(ent->lde_hash) < hash_offset)
2168 if (le64_to_cpu(ent->lde_hash) == hash_offset &&
2169 (*entp == ent || i < *stripe_offset))
2172 /* skip . and .. for other stripes */
2174 (strncmp(ent->lde_name, ".",
2175 le16_to_cpu(ent->lde_namelen)) == 0 ||
2176 strncmp(ent->lde_name, "..",
2177 le16_to_cpu(ent->lde_namelen)) == 0))
2183 stripe_hash = le64_to_cpu(dp->ldp_hash_end);
2189 /* reach the end of current stripe, go to next stripe */
2190 if (stripe_hash == MDS_DIR_END_OFF)
2196 if (min_ent != NULL) {
2197 if (le64_to_cpu(min_ent->lde_hash) >
2198 le64_to_cpu(ent->lde_hash)) {
2217 if (*ppage != NULL) {
2221 *stripe_offset = min_idx;
2228 * Build dir entry page from a striped directory
2230 * This function gets one entry by @offset from a striped directory. It will
2231 * read entries from all of stripes, and choose one closest to the required
2232 * offset(&offset). A few notes
2233 * 1. skip . and .. for non-zero stripes, because there can only have one .
2234 * and .. in a directory.
2235 * 2. op_data will be shared by all of stripes, instead of allocating new
2236 * one, so need to restore before reusing.
2237 * 3. release the entry page if that is not being chosen.
2239 * \param[in] exp obd export refer to LMV
2240 * \param[in] op_data hold those MD parameters of read_entry
2241 * \param[in] cb_op ldlm callback being used in enqueue in mdc_read_entry
2242 * \param[out] ldp the entry being read
2243 * \param[out] ppage the page holding the entry. Note: because the entry
2244 * will be accessed in upper layer, so we need hold the
2245 * page until the usages of entry is finished, see
2246 * ll_dir_entry_next.
2248 * retval =0 if get entry successfully
2249 * <0 cannot get entry
2251 static int lmv_read_striped_page(struct obd_export *exp,
2252 struct md_op_data *op_data,
2253 struct md_callback *cb_op,
2254 __u64 offset, struct page **ppage)
2256 struct lu_fid master_fid = op_data->op_fid1;
2257 struct inode *master_inode = op_data->op_data;
2258 __u64 hash_offset = offset;
2259 struct lu_dirpage *dp;
2260 struct page *min_ent_page = NULL;
2261 struct page *ent_page = NULL;
2262 struct lu_dirent *ent;
2265 struct lu_dirent *min_ent = NULL;
2266 struct lu_dirent *last_ent;
2271 /* Allocate a page and read entries from all of stripes and fill
2272 * the page by hash order */
2273 ent_page = alloc_page(GFP_KERNEL);
2274 if (ent_page == NULL)
2277 /* Initialize the entry page */
2278 dp = kmap(ent_page);
2279 memset(dp, 0, sizeof(*dp));
2280 dp->ldp_hash_start = cpu_to_le64(offset);
2281 dp->ldp_flags |= LDF_COLLIDE;
2284 left_bytes = PAGE_SIZE - sizeof(*dp);
2290 /* Find the minum entry from all sub-stripes */
2291 rc = lmv_get_min_striped_entry(exp, op_data, cb_op, hash_offset,
2297 /* If it can not get minum entry, it means it already reaches
2298 * the end of this directory */
2299 if (min_ent == NULL) {
2300 last_ent->lde_reclen = 0;
2301 hash_offset = MDS_DIR_END_OFF;
2305 ent_size = le16_to_cpu(min_ent->lde_reclen);
2307 /* the last entry lde_reclen is 0, but it might not
2308 * the end of this entry of this temporay entry */
2310 ent_size = lu_dirent_calc_size(
2311 le16_to_cpu(min_ent->lde_namelen),
2312 le32_to_cpu(min_ent->lde_attrs));
2313 if (ent_size > left_bytes) {
2314 last_ent->lde_reclen = cpu_to_le16(0);
2315 hash_offset = le64_to_cpu(min_ent->lde_hash);
2319 memcpy(ent, min_ent, ent_size);
2321 /* Replace . with master FID and Replace .. with the parent FID
2322 * of master object */
2323 if (strncmp(ent->lde_name, ".",
2324 le16_to_cpu(ent->lde_namelen)) == 0 &&
2325 le16_to_cpu(ent->lde_namelen) == 1)
2326 fid_cpu_to_le(&ent->lde_fid, &master_fid);
2327 else if (strncmp(ent->lde_name, "..",
2328 le16_to_cpu(ent->lde_namelen)) == 0 &&
2329 le16_to_cpu(ent->lde_namelen) == 2)
2330 fid_cpu_to_le(&ent->lde_fid, &op_data->op_fid3);
2332 left_bytes -= ent_size;
2333 ent->lde_reclen = cpu_to_le16(ent_size);
2335 ent = (void *)ent + ent_size;
2336 hash_offset = le64_to_cpu(min_ent->lde_hash);
2337 if (hash_offset == MDS_DIR_END_OFF) {
2338 last_ent->lde_reclen = 0;
2343 if (min_ent_page != NULL) {
2344 kunmap(min_ent_page);
2345 put_page(min_ent_page);
2348 if (unlikely(rc != 0)) {
2349 __free_page(ent_page);
2353 dp->ldp_flags |= LDF_EMPTY;
2354 dp->ldp_flags = cpu_to_le32(dp->ldp_flags);
2355 dp->ldp_hash_end = cpu_to_le64(hash_offset);
2358 /* We do not want to allocate md_op_data during each
2359 * dir entry reading, so op_data will be shared by every stripe,
2360 * then we need to restore it back to original value before
2361 * return to the upper layer */
2362 op_data->op_fid1 = master_fid;
2363 op_data->op_fid2 = master_fid;
2364 op_data->op_data = master_inode;
2371 int lmv_read_page(struct obd_export *exp, struct md_op_data *op_data,
2372 struct md_callback *cb_op, __u64 offset,
2373 struct page **ppage)
2375 struct obd_device *obd = exp->exp_obd;
2376 struct lmv_obd *lmv = &obd->u.lmv;
2377 struct lmv_stripe_md *lsm = op_data->op_mea1;
2378 struct lmv_tgt_desc *tgt;
2382 if (unlikely(lsm != NULL)) {
2383 rc = lmv_read_striped_page(exp, op_data, cb_op, offset, ppage);
2387 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2389 RETURN(PTR_ERR(tgt));
2391 rc = md_read_page(tgt->ltd_exp, op_data, cb_op, offset, ppage);
2397 * Unlink a file/directory
2399 * Unlink a file or directory under the parent dir. The unlink request
2400 * usually will be sent to the MDT where the child is located, but if
2401 * the client does not have the child FID then request will be sent to the
2402 * MDT where the parent is located.
2404 * If the parent is a striped directory then it also needs to locate which
2405 * stripe the name of the child is located, and replace the parent FID
2406 * (@op->op_fid1) with the stripe FID. Note: if the stripe is unknown,
2407 * it will walk through all of sub-stripes until the child is being
2410 * \param[in] exp export refer to LMV
2411 * \param[in] op_data different parameters transferred beween client
2412 * MD stacks, name, namelen, FIDs etc.
2413 * op_fid1 is the parent FID, op_fid2 is the child
2415 * \param[out] request point to the request of unlink.
2417 * retval 0 if succeed
2418 * negative errno if failed.
2420 static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
2421 struct ptlrpc_request **request)
2423 struct obd_device *obd = exp->exp_obd;
2424 struct lmv_obd *lmv = &obd->u.lmv;
2425 struct lmv_tgt_desc *tgt = NULL;
2426 struct lmv_tgt_desc *parent_tgt = NULL;
2427 struct mdt_body *body;
2429 int stripe_index = 0;
2430 struct lmv_stripe_md *lsm = op_data->op_mea1;
2434 /* For striped dir, we need to locate the parent as well */
2436 struct lmv_tgt_desc *tmp;
2438 LASSERT(op_data->op_name != NULL &&
2439 op_data->op_namelen != 0);
2441 tmp = lmv_locate_target_for_name(lmv, lsm,
2443 op_data->op_namelen,
2447 /* return -EBADFD means unknown hash type, might
2448 * need try all sub-stripe here */
2449 if (IS_ERR(tmp) && PTR_ERR(tmp) != -EBADFD)
2450 RETURN(PTR_ERR(tmp));
2452 /* Note: both migrating dir and unknown hash dir need to
2453 * try all of sub-stripes, so we need start search the
2454 * name from stripe 0, but migrating dir is already handled
2455 * inside lmv_locate_target_for_name(), so we only check
2456 * unknown hash type directory here */
2457 if (!lmv_is_known_hash_type(lsm->lsm_md_hash_type)) {
2458 struct lmv_oinfo *oinfo;
2460 oinfo = &lsm->lsm_md_oinfo[stripe_index];
2462 op_data->op_fid1 = oinfo->lmo_fid;
2463 op_data->op_mds = oinfo->lmo_mds;
2468 /* Send unlink requests to the MDT where the child is located */
2469 if (likely(!fid_is_zero(&op_data->op_fid2)))
2470 tgt = lmv_find_target(lmv, &op_data->op_fid2);
2471 else if (lsm != NULL)
2472 tgt = lmv_get_target(lmv, op_data->op_mds, NULL);
2474 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
2477 RETURN(PTR_ERR(tgt));
2479 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
2480 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
2481 op_data->op_cap = cfs_curproc_cap_pack();
2484 * If child's fid is given, cancel unused locks for it if it is from
2485 * another export than parent.
2487 * LOOKUP lock for child (fid3) should also be cancelled on parent
2488 * tgt_tgt in mdc_unlink().
2490 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2493 * Cancel FULL locks on child (fid3).
2495 parent_tgt = lmv_find_target(lmv, &op_data->op_fid1);
2496 if (IS_ERR(parent_tgt))
2497 RETURN(PTR_ERR(parent_tgt));
2499 if (parent_tgt != tgt) {
2500 rc = lmv_early_cancel(exp, parent_tgt, op_data, tgt->ltd_idx,
2501 LCK_EX, MDS_INODELOCK_LOOKUP,
2502 MF_MDC_CANCEL_FID3);
2505 rc = lmv_early_cancel(exp, NULL, op_data, tgt->ltd_idx, LCK_EX,
2506 MDS_INODELOCK_FULL, MF_MDC_CANCEL_FID3);
2510 CDEBUG(D_INODE, "unlink with fid="DFID"/"DFID" -> mds #%u\n",
2511 PFID(&op_data->op_fid1), PFID(&op_data->op_fid2), tgt->ltd_idx);
2513 rc = md_unlink(tgt->ltd_exp, op_data, request);
2514 if (rc != 0 && rc != -EREMOTE && rc != -ENOENT)
2517 /* Try next stripe if it is needed. */
2518 if (rc == -ENOENT && lsm != NULL && lmv_need_try_all_stripes(lsm)) {
2519 struct lmv_oinfo *oinfo;
2522 if (stripe_index >= lsm->lsm_md_stripe_count)
2525 oinfo = &lsm->lsm_md_oinfo[stripe_index];
2527 op_data->op_fid1 = oinfo->lmo_fid;
2528 op_data->op_mds = oinfo->lmo_mds;
2530 ptlrpc_req_finished(*request);
2533 goto try_next_stripe;
2536 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
2540 /* Not cross-ref case, just get out of here. */
2541 if (likely(!(body->mbo_valid & OBD_MD_MDS)))
2544 CDEBUG(D_INODE, "%s: try unlink to another MDT for "DFID"\n",
2545 exp->exp_obd->obd_name, PFID(&body->mbo_fid1));
2547 /* This is a remote object, try remote MDT, Note: it may
2548 * try more than 1 time here, Considering following case
2549 * /mnt/lustre is root on MDT0, remote1 is on MDT1
2550 * 1. Initially A does not know where remote1 is, it send
2551 * unlink RPC to MDT0, MDT0 return -EREMOTE, it will
2552 * resend unlink RPC to MDT1 (retry 1st time).
2554 * 2. During the unlink RPC in flight,
2555 * client B mv /mnt/lustre/remote1 /mnt/lustre/remote2
2556 * and create new remote1, but on MDT0
2558 * 3. MDT1 get unlink RPC(from A), then do remote lock on
2559 * /mnt/lustre, then lookup get fid of remote1, and find
2560 * it is remote dir again, and replay -EREMOTE again.
2562 * 4. Then A will resend unlink RPC to MDT0. (retry 2nd times).
2564 * In theory, it might try unlimited time here, but it should
2565 * be very rare case. */
2566 op_data->op_fid2 = body->mbo_fid1;
2567 ptlrpc_req_finished(*request);
2573 static int lmv_precleanup(struct obd_device *obd)
2576 fld_client_proc_fini(&obd->u.lmv.lmv_fld);
2577 lprocfs_obd_cleanup(obd);
2578 lprocfs_free_md_stats(obd);
2583 * Get by key a value associated with a LMV device.
2585 * Dispatch request to lower-layer devices as needed.
2587 * \param[in] env execution environment for this thread
2588 * \param[in] exp export for the LMV device
2589 * \param[in] keylen length of key identifier
2590 * \param[in] key identifier of key to get value for
2591 * \param[in] vallen size of \a val
2592 * \param[out] val pointer to storage location for value
2593 * \param[in] lsm optional striping metadata of object
2595 * \retval 0 on success
2596 * \retval negative negated errno on failure
2598 static int lmv_get_info(const struct lu_env *env, struct obd_export *exp,
2599 __u32 keylen, void *key, __u32 *vallen, void *val)
2601 struct obd_device *obd;
2602 struct lmv_obd *lmv;
2606 obd = class_exp2obd(exp);
2608 CDEBUG(D_IOCTL, "Invalid client cookie %#llx\n",
2609 exp->exp_handle.h_cookie);
2614 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
2617 LASSERT(*vallen == sizeof(__u32));
2618 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2619 struct lmv_tgt_desc *tgt = lmv->tgts[i];
2621 * All tgts should be connected when this gets called.
2623 if (tgt == NULL || tgt->ltd_exp == NULL)
2626 if (!obd_get_info(env, tgt->ltd_exp, keylen, key,
2631 } else if (KEY_IS(KEY_MAX_EASIZE) ||
2632 KEY_IS(KEY_DEFAULT_EASIZE) ||
2633 KEY_IS(KEY_CONN_DATA)) {
2635 * Forwarding this request to first MDS, it should know LOV
2638 rc = obd_get_info(env, lmv->tgts[0]->ltd_exp, keylen, key,
2640 if (!rc && KEY_IS(KEY_CONN_DATA))
2641 exp->exp_connect_data = *(struct obd_connect_data *)val;
2643 } else if (KEY_IS(KEY_TGT_COUNT)) {
2644 *((int *)val) = lmv->desc.ld_tgt_count;
2648 CDEBUG(D_IOCTL, "Invalid key\n");
2653 * Asynchronously set by key a value associated with a LMV device.
2655 * Dispatch request to lower-layer devices as needed.
2657 * \param[in] env execution environment for this thread
2658 * \param[in] exp export for the LMV device
2659 * \param[in] keylen length of key identifier
2660 * \param[in] key identifier of key to store value for
2661 * \param[in] vallen size of value to store
2662 * \param[in] val pointer to data to be stored
2663 * \param[in] set optional list of related ptlrpc requests
2665 * \retval 0 on success
2666 * \retval negative negated errno on failure
2668 int lmv_set_info_async(const struct lu_env *env, struct obd_export *exp,
2669 __u32 keylen, void *key, __u32 vallen, void *val,
2670 struct ptlrpc_request_set *set)
2672 struct lmv_tgt_desc *tgt = NULL;
2673 struct obd_device *obd;
2674 struct lmv_obd *lmv;
2678 obd = class_exp2obd(exp);
2680 CDEBUG(D_IOCTL, "Invalid client cookie %#llx\n",
2681 exp->exp_handle.h_cookie);
2686 if (KEY_IS(KEY_READ_ONLY) || KEY_IS(KEY_FLUSH_CTX) ||
2687 KEY_IS(KEY_DEFAULT_EASIZE)) {
2690 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2693 if (tgt == NULL || tgt->ltd_exp == NULL)
2696 err = obd_set_info_async(env, tgt->ltd_exp,
2697 keylen, key, vallen, val, set);
2708 static int lmv_unpack_md_v1(struct obd_export *exp, struct lmv_stripe_md *lsm,
2709 const struct lmv_mds_md_v1 *lmm1)
2711 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2718 lsm->lsm_md_magic = le32_to_cpu(lmm1->lmv_magic);
2719 lsm->lsm_md_stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
2720 lsm->lsm_md_master_mdt_index = le32_to_cpu(lmm1->lmv_master_mdt_index);
2721 if (OBD_FAIL_CHECK(OBD_FAIL_UNKNOWN_LMV_STRIPE))
2722 lsm->lsm_md_hash_type = LMV_HASH_TYPE_UNKNOWN;
2724 lsm->lsm_md_hash_type = le32_to_cpu(lmm1->lmv_hash_type);
2725 lsm->lsm_md_layout_version = le32_to_cpu(lmm1->lmv_layout_version);
2726 cplen = strlcpy(lsm->lsm_md_pool_name, lmm1->lmv_pool_name,
2727 sizeof(lsm->lsm_md_pool_name));
2729 if (cplen >= sizeof(lsm->lsm_md_pool_name))
2732 CDEBUG(D_INFO, "unpack lsm count %d, master %d hash_type %d"
2733 "layout_version %d\n", lsm->lsm_md_stripe_count,
2734 lsm->lsm_md_master_mdt_index, lsm->lsm_md_hash_type,
2735 lsm->lsm_md_layout_version);
2737 stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
2738 for (i = 0; i < stripe_count; i++) {
2739 fid_le_to_cpu(&lsm->lsm_md_oinfo[i].lmo_fid,
2740 &lmm1->lmv_stripe_fids[i]);
2741 rc = lmv_fld_lookup(lmv, &lsm->lsm_md_oinfo[i].lmo_fid,
2742 &lsm->lsm_md_oinfo[i].lmo_mds);
2745 CDEBUG(D_INFO, "unpack fid #%d "DFID"\n", i,
2746 PFID(&lsm->lsm_md_oinfo[i].lmo_fid));
2752 static int lmv_unpackmd(struct obd_export *exp, struct lmv_stripe_md **lsmp,
2753 const union lmv_mds_md *lmm, size_t lmm_size)
2755 struct lmv_stripe_md *lsm;
2758 bool allocated = false;
2761 LASSERT(lsmp != NULL);
2765 if (lsm != NULL && lmm == NULL) {
2767 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
2768 /* For migrating inode, the master stripe and master
2769 * object will be the same, so do not need iput, see
2770 * ll_update_lsm_md */
2771 if (!(lsm->lsm_md_hash_type & LMV_HASH_FLAG_MIGRATION &&
2772 i == 0) && lsm->lsm_md_oinfo[i].lmo_root != NULL)
2773 iput(lsm->lsm_md_oinfo[i].lmo_root);
2775 lsm_size = lmv_stripe_md_size(lsm->lsm_md_stripe_count);
2776 OBD_FREE(lsm, lsm_size);
2781 if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_STRIPE)
2785 if (le32_to_cpu(lmm->lmv_magic) != LMV_MAGIC_V1 &&
2786 le32_to_cpu(lmm->lmv_magic) != LMV_USER_MAGIC) {
2787 CERROR("%s: invalid lmv magic %x: rc = %d\n",
2788 exp->exp_obd->obd_name, le32_to_cpu(lmm->lmv_magic),
2793 if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_V1)
2794 lsm_size = lmv_stripe_md_size(lmv_mds_md_stripe_count_get(lmm));
2797 * Unpack default dirstripe(lmv_user_md) to lmv_stripe_md,
2798 * stripecount should be 0 then.
2800 lsm_size = lmv_stripe_md_size(0);
2802 lsm_size = lmv_stripe_md_size(lmv_mds_md_stripe_count_get(lmm));
2804 OBD_ALLOC(lsm, lsm_size);
2811 switch (le32_to_cpu(lmm->lmv_magic)) {
2813 rc = lmv_unpack_md_v1(exp, lsm, &lmm->lmv_md_v1);
2816 CERROR("%s: unrecognized magic %x\n", exp->exp_obd->obd_name,
2817 le32_to_cpu(lmm->lmv_magic));
2822 if (rc != 0 && allocated) {
2823 OBD_FREE(lsm, lsm_size);
2830 void lmv_free_memmd(struct lmv_stripe_md *lsm)
2832 lmv_unpackmd(NULL, &lsm, NULL, 0);
2834 EXPORT_SYMBOL(lmv_free_memmd);
2836 static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
2837 union ldlm_policy_data *policy,
2838 enum ldlm_mode mode, enum ldlm_cancel_flags flags,
2841 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2846 LASSERT(fid != NULL);
2848 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2849 struct lmv_tgt_desc *tgt = lmv->tgts[i];
2852 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
2855 err = md_cancel_unused(tgt->ltd_exp, fid, policy, mode, flags,
2863 static int lmv_set_lock_data(struct obd_export *exp,
2864 const struct lustre_handle *lockh,
2865 void *data, __u64 *bits)
2867 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2868 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2872 if (tgt == NULL || tgt->ltd_exp == NULL)
2874 rc = md_set_lock_data(tgt->ltd_exp, lockh, data, bits);
2878 enum ldlm_mode lmv_lock_match(struct obd_export *exp, __u64 flags,
2879 const struct lu_fid *fid, enum ldlm_type type,
2880 union ldlm_policy_data *policy,
2881 enum ldlm_mode mode, struct lustre_handle *lockh)
2883 struct obd_device *obd = exp->exp_obd;
2884 struct lmv_obd *lmv = &obd->u.lmv;
2890 CDEBUG(D_INODE, "Lock match for "DFID"\n", PFID(fid));
2893 * With DNE every object can have two locks in different namespaces:
2894 * lookup lock in space of MDT storing direntry and update/open lock in
2895 * space of MDT storing inode. Try the MDT that the FID maps to first,
2896 * since this can be easily found, and only try others if that fails.
2898 for (i = 0, tgt = lmv_find_target_index(lmv, fid);
2899 i < lmv->desc.ld_tgt_count;
2900 i++, tgt = (tgt + 1) % lmv->desc.ld_tgt_count) {
2902 CDEBUG(D_HA, "%s: "DFID" is inaccessible: rc = %d\n",
2903 obd->obd_name, PFID(fid), tgt);
2907 if (lmv->tgts[tgt] == NULL ||
2908 lmv->tgts[tgt]->ltd_exp == NULL ||
2909 lmv->tgts[tgt]->ltd_active == 0)
2912 rc = md_lock_match(lmv->tgts[tgt]->ltd_exp, flags, fid,
2913 type, policy, mode, lockh);
2921 int lmv_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
2922 struct obd_export *dt_exp, struct obd_export *md_exp,
2923 struct lustre_md *md)
2925 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2926 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2928 if (tgt == NULL || tgt->ltd_exp == NULL)
2931 return md_get_lustre_md(lmv->tgts[0]->ltd_exp, req, dt_exp, md_exp, md);
2934 int lmv_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
2936 struct obd_device *obd = exp->exp_obd;
2937 struct lmv_obd *lmv = &obd->u.lmv;
2938 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2941 if (md->lmv != NULL) {
2942 lmv_free_memmd(md->lmv);
2945 if (tgt == NULL || tgt->ltd_exp == NULL)
2947 RETURN(md_free_lustre_md(lmv->tgts[0]->ltd_exp, md));
2950 int lmv_set_open_replay_data(struct obd_export *exp,
2951 struct obd_client_handle *och,
2952 struct lookup_intent *it)
2954 struct obd_device *obd = exp->exp_obd;
2955 struct lmv_obd *lmv = &obd->u.lmv;
2956 struct lmv_tgt_desc *tgt;
2959 tgt = lmv_find_target(lmv, &och->och_fid);
2961 RETURN(PTR_ERR(tgt));
2963 RETURN(md_set_open_replay_data(tgt->ltd_exp, och, it));
2966 int lmv_clear_open_replay_data(struct obd_export *exp,
2967 struct obd_client_handle *och)
2969 struct obd_device *obd = exp->exp_obd;
2970 struct lmv_obd *lmv = &obd->u.lmv;
2971 struct lmv_tgt_desc *tgt;
2974 tgt = lmv_find_target(lmv, &och->och_fid);
2976 RETURN(PTR_ERR(tgt));
2978 RETURN(md_clear_open_replay_data(tgt->ltd_exp, och));
2981 int lmv_intent_getattr_async(struct obd_export *exp,
2982 struct md_enqueue_info *minfo)
2984 struct md_op_data *op_data = &minfo->mi_data;
2985 struct obd_device *obd = exp->exp_obd;
2986 struct lmv_obd *lmv = &obd->u.lmv;
2987 struct lmv_tgt_desc *ptgt = NULL;
2988 struct lmv_tgt_desc *ctgt = NULL;
2992 if (!fid_is_sane(&op_data->op_fid2))
2995 ptgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
2997 RETURN(PTR_ERR(ptgt));
2999 ctgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
3001 RETURN(PTR_ERR(ctgt));
3004 * if child is on remote MDT, we need 2 async RPCs to fetch both LOOKUP
3005 * lock on parent, and UPDATE lock on child MDT, which makes all
3006 * complicated. Considering remote dir is rare case, and not supporting
3007 * it in statahead won't cause any issue, drop its support for now.
3012 rc = md_intent_getattr_async(ptgt->ltd_exp, minfo);
3016 int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
3017 struct lu_fid *fid, __u64 *bits)
3019 struct obd_device *obd = exp->exp_obd;
3020 struct lmv_obd *lmv = &obd->u.lmv;
3021 struct lmv_tgt_desc *tgt;
3025 tgt = lmv_find_target(lmv, fid);
3027 RETURN(PTR_ERR(tgt));
3029 rc = md_revalidate_lock(tgt->ltd_exp, it, fid, bits);
3033 int lmv_get_fid_from_lsm(struct obd_export *exp,
3034 const struct lmv_stripe_md *lsm,
3035 const char *name, int namelen, struct lu_fid *fid)
3037 const struct lmv_oinfo *oinfo;
3039 LASSERT(lsm != NULL);
3040 oinfo = lsm_name_to_stripe_info(lsm, name, namelen);
3042 return PTR_ERR(oinfo);
3044 *fid = oinfo->lmo_fid;
3050 * For lmv, only need to send request to master MDT, and the master MDT will
3051 * process with other slave MDTs. The only exception is Q_GETOQUOTA for which
3052 * we directly fetch data from the slave MDTs.
3054 int lmv_quotactl(struct obd_device *unused, struct obd_export *exp,
3055 struct obd_quotactl *oqctl)
3057 struct obd_device *obd = class_exp2obd(exp);
3058 struct lmv_obd *lmv = &obd->u.lmv;
3059 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3062 __u64 curspace, curinodes;
3066 tgt->ltd_exp == NULL ||
3068 lmv->desc.ld_tgt_count == 0) {
3069 CERROR("master lmv inactive\n");
3073 if (oqctl->qc_cmd != Q_GETOQUOTA) {
3074 rc = obd_quotactl(tgt->ltd_exp, oqctl);
3078 curspace = curinodes = 0;
3079 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
3083 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
3086 err = obd_quotactl(tgt->ltd_exp, oqctl);
3088 CERROR("getquota on mdt %d failed. %d\n", i, err);
3092 curspace += oqctl->qc_dqblk.dqb_curspace;
3093 curinodes += oqctl->qc_dqblk.dqb_curinodes;
3096 oqctl->qc_dqblk.dqb_curspace = curspace;
3097 oqctl->qc_dqblk.dqb_curinodes = curinodes;
3102 static int lmv_merge_attr(struct obd_export *exp,
3103 const struct lmv_stripe_md *lsm,
3104 struct cl_attr *attr,
3105 ldlm_blocking_callback cb_blocking)
3110 rc = lmv_revalidate_slaves(exp, lsm, cb_blocking, 0);
3114 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
3115 struct inode *inode = lsm->lsm_md_oinfo[i].lmo_root;
3117 CDEBUG(D_INFO, ""DFID" size %llu, blocks %llu nlink %u,"
3118 " atime %lu ctime %lu, mtime %lu.\n",
3119 PFID(&lsm->lsm_md_oinfo[i].lmo_fid),
3120 i_size_read(inode), (unsigned long long)inode->i_blocks,
3121 inode->i_nlink, LTIME_S(inode->i_atime),
3122 LTIME_S(inode->i_ctime), LTIME_S(inode->i_mtime));
3124 /* for slave stripe, it needs to subtract nlink for . and .. */
3126 attr->cat_nlink += inode->i_nlink - 2;
3128 attr->cat_nlink = inode->i_nlink;
3130 attr->cat_size += i_size_read(inode);
3131 attr->cat_blocks += inode->i_blocks;
3133 if (attr->cat_atime < LTIME_S(inode->i_atime))
3134 attr->cat_atime = LTIME_S(inode->i_atime);
3136 if (attr->cat_ctime < LTIME_S(inode->i_ctime))
3137 attr->cat_ctime = LTIME_S(inode->i_ctime);
3139 if (attr->cat_mtime < LTIME_S(inode->i_mtime))
3140 attr->cat_mtime = LTIME_S(inode->i_mtime);
3145 struct obd_ops lmv_obd_ops = {
3146 .o_owner = THIS_MODULE,
3147 .o_setup = lmv_setup,
3148 .o_cleanup = lmv_cleanup,
3149 .o_precleanup = lmv_precleanup,
3150 .o_process_config = lmv_process_config,
3151 .o_connect = lmv_connect,
3152 .o_disconnect = lmv_disconnect,
3153 .o_statfs = lmv_statfs,
3154 .o_get_info = lmv_get_info,
3155 .o_set_info_async = lmv_set_info_async,
3156 .o_notify = lmv_notify,
3157 .o_get_uuid = lmv_get_uuid,
3158 .o_iocontrol = lmv_iocontrol,
3159 .o_quotactl = lmv_quotactl
3162 struct md_ops lmv_md_ops = {
3163 .m_get_root = lmv_get_root,
3164 .m_null_inode = lmv_null_inode,
3165 .m_close = lmv_close,
3166 .m_create = lmv_create,
3167 .m_enqueue = lmv_enqueue,
3168 .m_getattr = lmv_getattr,
3169 .m_getxattr = lmv_getxattr,
3170 .m_getattr_name = lmv_getattr_name,
3171 .m_intent_lock = lmv_intent_lock,
3173 .m_rename = lmv_rename,
3174 .m_setattr = lmv_setattr,
3175 .m_setxattr = lmv_setxattr,
3176 .m_fsync = lmv_fsync,
3177 .m_read_page = lmv_read_page,
3178 .m_unlink = lmv_unlink,
3179 .m_init_ea_size = lmv_init_ea_size,
3180 .m_cancel_unused = lmv_cancel_unused,
3181 .m_set_lock_data = lmv_set_lock_data,
3182 .m_lock_match = lmv_lock_match,
3183 .m_get_lustre_md = lmv_get_lustre_md,
3184 .m_free_lustre_md = lmv_free_lustre_md,
3185 .m_merge_attr = lmv_merge_attr,
3186 .m_set_open_replay_data = lmv_set_open_replay_data,
3187 .m_clear_open_replay_data = lmv_clear_open_replay_data,
3188 .m_intent_getattr_async = lmv_intent_getattr_async,
3189 .m_revalidate_lock = lmv_revalidate_lock,
3190 .m_get_fid_from_lsm = lmv_get_fid_from_lsm,
3191 .m_unpackmd = lmv_unpackmd,
3194 static int __init lmv_init(void)
3196 return class_register_type(&lmv_obd_ops, &lmv_md_ops, true, NULL,
3197 LUSTRE_LMV_NAME, NULL);
3200 static void __exit lmv_exit(void)
3202 class_unregister_type(LUSTRE_LMV_NAME);
3205 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
3206 MODULE_DESCRIPTION("Lustre Logical Metadata Volume");
3207 MODULE_VERSION(LUSTRE_VERSION_STRING);
3208 MODULE_LICENSE("GPL");
3210 module_init(lmv_init);
3211 module_exit(lmv_exit);