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, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_LMV
39 #include <linux/slab.h>
40 #include <linux/module.h>
41 #include <linux/init.h>
42 #include <linux/slab.h>
43 #include <linux/pagemap.h>
45 #include <asm/div64.h>
46 #include <linux/seq_file.h>
47 #include <linux/namei.h>
49 #include <liblustre.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>
61 #include <lustre_lite.h>
62 #include <lustre_fid.h>
63 #include "lmv_internal.h"
65 /* This hash is only for testing purpose */
66 static inline unsigned int
67 lmv_hash_all_chars(unsigned int count, const char *name, int namelen)
70 const unsigned char *p = (const unsigned char *)name;
72 while (--namelen >= 0)
80 static inline unsigned int
81 lmv_hash_fnv1a(unsigned int count, const char *name, int namelen)
85 hash = lustre_hash_fnv_1a_64(name, namelen);
92 int lmv_name_to_stripe_index(enum lmv_hash_type hashtype,
93 unsigned int max_mdt_index,
94 const char *name, int namelen)
99 if (max_mdt_index <= 1)
103 case LMV_HASH_TYPE_ALL_CHARS:
104 idx = lmv_hash_all_chars(max_mdt_index, name, namelen);
106 case LMV_HASH_TYPE_FNV_1A_64:
107 idx = lmv_hash_fnv1a(max_mdt_index, name, namelen);
110 CERROR("Unknown hash type 0x%x\n", hashtype);
114 LASSERT(idx < max_mdt_index);
118 static void lmv_activate_target(struct lmv_obd *lmv,
119 struct lmv_tgt_desc *tgt,
122 if (tgt->ltd_active == activate)
125 tgt->ltd_active = activate;
126 lmv->desc.ld_active_tgt_count += (activate ? 1 : -1);
132 * -EINVAL : UUID can't be found in the LMV's target list
133 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
134 * -EBADF : The UUID is found, but the OBD of the wrong type (!)
136 static int lmv_set_mdc_active(struct lmv_obd *lmv,
137 const struct obd_uuid *uuid,
140 struct lmv_tgt_desc *tgt = NULL;
141 struct obd_device *obd;
146 CDEBUG(D_INFO, "Searching in lmv %p for uuid %s (activate=%d)\n",
147 lmv, uuid->uuid, activate);
149 spin_lock(&lmv->lmv_lock);
150 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
152 if (tgt == NULL || tgt->ltd_exp == NULL)
155 CDEBUG(D_INFO, "Target idx %d is %s conn "LPX64"\n", i,
156 tgt->ltd_uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
158 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
162 if (i == lmv->desc.ld_tgt_count)
163 GOTO(out_lmv_lock, rc = -EINVAL);
165 obd = class_exp2obd(tgt->ltd_exp);
167 GOTO(out_lmv_lock, rc = -ENOTCONN);
169 CDEBUG(D_INFO, "Found OBD %s=%s device %d (%p) type %s at LMV idx %d\n",
170 obd->obd_name, obd->obd_uuid.uuid, obd->obd_minor, obd,
171 obd->obd_type->typ_name, i);
172 LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0);
174 if (tgt->ltd_active == activate) {
175 CDEBUG(D_INFO, "OBD %p already %sactive!\n", obd,
176 activate ? "" : "in");
177 GOTO(out_lmv_lock, rc);
180 CDEBUG(D_INFO, "Marking OBD %p %sactive\n", obd,
181 activate ? "" : "in");
182 lmv_activate_target(lmv, tgt, activate);
186 spin_unlock(&lmv->lmv_lock);
190 struct obd_uuid *lmv_get_uuid(struct obd_export *exp)
192 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
193 struct lmv_tgt_desc *tgt = lmv->tgts[0];
195 return (tgt == NULL) ? NULL : obd_get_uuid(tgt->ltd_exp);
198 static int lmv_notify(struct obd_device *obd, struct obd_device *watched,
199 enum obd_notify_event ev, void *data)
201 struct obd_connect_data *conn_data;
202 struct lmv_obd *lmv = &obd->u.lmv;
203 struct obd_uuid *uuid;
207 if (strcmp(watched->obd_type->typ_name, LUSTRE_MDC_NAME)) {
208 CERROR("unexpected notification of %s %s!\n",
209 watched->obd_type->typ_name,
214 uuid = &watched->u.cli.cl_target_uuid;
215 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE) {
217 * Set MDC as active before notifying the observer, so the
218 * observer can use the MDC normally.
220 rc = lmv_set_mdc_active(lmv, uuid,
221 ev == OBD_NOTIFY_ACTIVE);
223 CERROR("%sactivation of %s failed: %d\n",
224 ev == OBD_NOTIFY_ACTIVE ? "" : "de",
228 } else if (ev == OBD_NOTIFY_OCD) {
229 conn_data = &watched->u.cli.cl_import->imp_connect_data;
231 * XXX: Make sure that ocd_connect_flags from all targets are
232 * the same. Otherwise one of MDTs runs wrong version or
233 * something like this. --umka
235 obd->obd_self_export->exp_connect_data = *conn_data;
238 else if (ev == OBD_NOTIFY_DISCON) {
240 * For disconnect event, flush fld cache for failout MDS case.
242 fld_client_flush(&lmv->lmv_fld);
246 * Pass the notification up the chain.
248 if (obd->obd_observer)
249 rc = obd_notify(obd->obd_observer, watched, ev, data);
255 * This is fake connect function. Its purpose is to initialize lmv and say
256 * caller that everything is okay. Real connection will be performed later.
258 static int lmv_connect(const struct lu_env *env,
259 struct obd_export **exp, struct obd_device *obd,
260 struct obd_uuid *cluuid, struct obd_connect_data *data,
264 struct proc_dir_entry *lmv_proc_dir;
266 struct lmv_obd *lmv = &obd->u.lmv;
267 struct lustre_handle conn = { 0 };
272 * We don't want to actually do the underlying connections more than
273 * once, so keep track.
276 if (lmv->refcount > 1) {
281 rc = class_connect(&conn, obd, cluuid);
283 CERROR("class_connection() returned %d\n", rc);
287 *exp = class_conn2export(&conn);
288 class_export_get(*exp);
292 lmv->cluuid = *cluuid;
295 lmv->conn_data = *data;
298 if (obd->obd_proc_private != NULL) {
299 lmv_proc_dir = obd->obd_proc_private;
301 lmv_proc_dir = lprocfs_seq_register("target_obds",
304 if (IS_ERR(lmv_proc_dir)) {
305 CERROR("could not register /proc/fs/lustre/%s/%s/target_obds.",
306 obd->obd_type->typ_name, obd->obd_name);
309 obd->obd_proc_private = lmv_proc_dir;
314 * All real clients should perform actual connection right away, because
315 * it is possible, that LMV will not have opportunity to connect targets
316 * and MDC stuff will be called directly, for instance while reading
317 * ../mdc/../kbytesfree procfs file, etc.
319 if (data != NULL && (data->ocd_connect_flags & OBD_CONNECT_REAL))
320 rc = lmv_check_connect(obd);
323 if (rc && lmv_proc_dir) {
324 lprocfs_remove(&lmv_proc_dir);
325 obd->obd_proc_private = NULL;
331 static void lmv_set_timeouts(struct obd_device *obd)
337 if (lmv->server_timeout == 0)
340 if (lmv->connected == 0)
343 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
344 struct lmv_tgt_desc *tgt = lmv->tgts[i];
346 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
349 obd_set_info_async(NULL, tgt->ltd_exp, sizeof(KEY_INTERMDS),
350 KEY_INTERMDS, 0, NULL, NULL);
354 static int lmv_init_ea_size(struct obd_export *exp, int easize,
355 int def_easize, int cookiesize)
357 struct obd_device *obd = exp->exp_obd;
358 struct lmv_obd *lmv = &obd->u.lmv;
364 if (lmv->max_easize < easize) {
365 lmv->max_easize = easize;
368 if (lmv->max_def_easize < def_easize) {
369 lmv->max_def_easize = def_easize;
372 if (lmv->max_cookiesize < cookiesize) {
373 lmv->max_cookiesize = cookiesize;
379 if (lmv->connected == 0)
382 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
383 struct lmv_tgt_desc *tgt = lmv->tgts[i];
385 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active) {
386 CWARN("%s: NULL export for %d\n", obd->obd_name, i);
390 rc = md_init_ea_size(tgt->ltd_exp, easize, def_easize,
393 CERROR("%s: obd_init_ea_size() failed on MDT target %d:"
394 " rc = %d.\n", obd->obd_name, i, rc);
401 #define MAX_STRING_SIZE 128
403 int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
406 struct proc_dir_entry *lmv_proc_dir;
408 struct lmv_obd *lmv = &obd->u.lmv;
409 struct obd_uuid *cluuid = &lmv->cluuid;
410 struct obd_uuid lmv_mdc_uuid = { "LMV_MDC_UUID" };
411 struct obd_device *mdc_obd;
412 struct obd_export *mdc_exp;
413 struct lu_fld_target target;
417 mdc_obd = class_find_client_obd(&tgt->ltd_uuid, LUSTRE_MDC_NAME,
420 CERROR("target %s not attached\n", tgt->ltd_uuid.uuid);
424 CDEBUG(D_CONFIG, "connect to %s(%s) - %s, %s FOR %s\n",
425 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
426 tgt->ltd_uuid.uuid, obd->obd_uuid.uuid,
429 if (!mdc_obd->obd_set_up) {
430 CERROR("target %s is not set up\n", tgt->ltd_uuid.uuid);
434 rc = obd_connect(NULL, &mdc_exp, mdc_obd, &lmv_mdc_uuid,
435 &lmv->conn_data, NULL);
437 CERROR("target %s connect error %d\n", tgt->ltd_uuid.uuid, rc);
442 * Init fid sequence client for this mdc and add new fld target.
444 rc = obd_fid_init(mdc_obd, mdc_exp, LUSTRE_SEQ_METADATA);
448 target.ft_srv = NULL;
449 target.ft_exp = mdc_exp;
450 target.ft_idx = tgt->ltd_idx;
452 fld_client_add_target(&lmv->lmv_fld, &target);
454 rc = obd_register_observer(mdc_obd, obd);
456 obd_disconnect(mdc_exp);
457 CERROR("target %s register_observer error %d\n",
458 tgt->ltd_uuid.uuid, rc);
462 if (obd->obd_observer) {
464 * Tell the observer about the new target.
466 rc = obd_notify(obd->obd_observer, mdc_exp->exp_obd,
468 (void *)(tgt - lmv->tgts[0]));
470 obd_disconnect(mdc_exp);
476 tgt->ltd_exp = mdc_exp;
477 lmv->desc.ld_active_tgt_count++;
479 md_init_ea_size(tgt->ltd_exp, lmv->max_easize,
480 lmv->max_def_easize, lmv->max_cookiesize);
482 CDEBUG(D_CONFIG, "Connected to %s(%s) successfully (%d)\n",
483 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
484 cfs_atomic_read(&obd->obd_refcount));
487 lmv_proc_dir = obd->obd_proc_private;
489 struct proc_dir_entry *mdc_symlink;
491 LASSERT(mdc_obd->obd_type != NULL);
492 LASSERT(mdc_obd->obd_type->typ_name != NULL);
493 mdc_symlink = lprocfs_add_symlink(mdc_obd->obd_name,
496 mdc_obd->obd_type->typ_name,
498 if (mdc_symlink == NULL) {
499 CERROR("Could not register LMV target "
500 "/proc/fs/lustre/%s/%s/target_obds/%s.",
501 obd->obd_type->typ_name, obd->obd_name,
503 lprocfs_remove(&lmv_proc_dir);
504 obd->obd_proc_private = NULL;
511 static void lmv_del_target(struct lmv_obd *lmv, int index)
513 if (lmv->tgts[index] == NULL)
516 OBD_FREE_PTR(lmv->tgts[index]);
517 lmv->tgts[index] = NULL;
521 static int lmv_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
522 __u32 index, int gen)
524 struct lmv_obd *lmv = &obd->u.lmv;
525 struct lmv_tgt_desc *tgt;
529 CDEBUG(D_CONFIG, "Target uuid: %s. index %d\n", uuidp->uuid, index);
533 if (lmv->desc.ld_tgt_count == 0) {
534 struct obd_device *mdc_obd;
536 mdc_obd = class_find_client_obd(uuidp, LUSTRE_MDC_NAME,
539 lmv_init_unlock(lmv);
540 CERROR("%s: Target %s not attached: rc = %d\n",
541 obd->obd_name, uuidp->uuid, -EINVAL);
546 if ((index < lmv->tgts_size) && (lmv->tgts[index] != NULL)) {
547 tgt = lmv->tgts[index];
548 CERROR("%s: UUID %s already assigned at LOV target index %d:"
549 " rc = %d\n", obd->obd_name,
550 obd_uuid2str(&tgt->ltd_uuid), index, -EEXIST);
551 lmv_init_unlock(lmv);
555 if (index >= lmv->tgts_size) {
556 /* We need to reallocate the lmv target array. */
557 struct lmv_tgt_desc **newtgts, **old = NULL;
561 while (newsize < index + 1)
562 newsize = newsize << 1;
563 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
564 if (newtgts == NULL) {
565 lmv_init_unlock(lmv);
569 if (lmv->tgts_size) {
570 memcpy(newtgts, lmv->tgts,
571 sizeof(*newtgts) * lmv->tgts_size);
573 oldsize = lmv->tgts_size;
577 lmv->tgts_size = newsize;
580 OBD_FREE(old, sizeof(*old) * oldsize);
582 CDEBUG(D_CONFIG, "tgts: %p size: %d\n", lmv->tgts,
588 lmv_init_unlock(lmv);
592 mutex_init(&tgt->ltd_fid_mutex);
593 tgt->ltd_idx = index;
594 tgt->ltd_uuid = *uuidp;
596 lmv->tgts[index] = tgt;
597 if (index >= lmv->desc.ld_tgt_count)
598 lmv->desc.ld_tgt_count = index + 1;
600 if (lmv->connected) {
601 rc = lmv_connect_mdc(obd, tgt);
603 spin_lock(&lmv->lmv_lock);
604 lmv->desc.ld_tgt_count--;
605 memset(tgt, 0, sizeof(*tgt));
606 spin_unlock(&lmv->lmv_lock);
608 int easize = sizeof(struct lmv_stripe_md) +
609 lmv->desc.ld_tgt_count *
610 sizeof(struct lu_fid);
611 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0);
615 lmv_init_unlock(lmv);
619 int lmv_check_connect(struct obd_device *obd)
621 struct lmv_obd *lmv = &obd->u.lmv;
622 struct lmv_tgt_desc *tgt;
632 if (lmv->connected) {
633 lmv_init_unlock(lmv);
637 if (lmv->desc.ld_tgt_count == 0) {
638 lmv_init_unlock(lmv);
639 CERROR("%s: no targets configured.\n", obd->obd_name);
643 LASSERT(lmv->tgts != NULL);
645 if (lmv->tgts[0] == NULL) {
646 lmv_init_unlock(lmv);
647 CERROR("%s: no target configured for index 0.\n",
652 CDEBUG(D_CONFIG, "Time to connect %s to %s\n",
653 lmv->cluuid.uuid, obd->obd_name);
655 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
659 rc = lmv_connect_mdc(obd, tgt);
664 lmv_set_timeouts(obd);
665 class_export_put(lmv->exp);
667 easize = lmv_mds_md_size(lmv->desc.ld_tgt_count, LMV_MAGIC);
668 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0);
669 lmv_init_unlock(lmv);
680 --lmv->desc.ld_active_tgt_count;
681 rc2 = obd_disconnect(tgt->ltd_exp);
683 CERROR("LMV target %s disconnect on "
684 "MDC idx %d: error %d\n",
685 tgt->ltd_uuid.uuid, i, rc2);
689 class_disconnect(lmv->exp);
690 lmv_init_unlock(lmv);
694 static int lmv_disconnect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
697 struct proc_dir_entry *lmv_proc_dir;
699 struct lmv_obd *lmv = &obd->u.lmv;
700 struct obd_device *mdc_obd;
704 LASSERT(tgt != NULL);
705 LASSERT(obd != NULL);
707 mdc_obd = class_exp2obd(tgt->ltd_exp);
710 mdc_obd->obd_force = obd->obd_force;
711 mdc_obd->obd_fail = obd->obd_fail;
712 mdc_obd->obd_no_recov = obd->obd_no_recov;
716 lmv_proc_dir = obd->obd_proc_private;
718 lprocfs_remove_proc_entry(mdc_obd->obd_name, lmv_proc_dir);
720 rc = obd_fid_fini(tgt->ltd_exp->exp_obd);
722 CERROR("Can't finanize fids factory\n");
724 CDEBUG(D_INFO, "Disconnected from %s(%s) successfully\n",
725 tgt->ltd_exp->exp_obd->obd_name,
726 tgt->ltd_exp->exp_obd->obd_uuid.uuid);
728 obd_register_observer(tgt->ltd_exp->exp_obd, NULL);
729 rc = obd_disconnect(tgt->ltd_exp);
731 if (tgt->ltd_active) {
732 CERROR("Target %s disconnect error %d\n",
733 tgt->ltd_uuid.uuid, rc);
737 lmv_activate_target(lmv, tgt, 0);
742 static int lmv_disconnect(struct obd_export *exp)
744 struct obd_device *obd = class_exp2obd(exp);
745 struct lmv_obd *lmv = &obd->u.lmv;
754 * Only disconnect the underlying layers on the final disconnect.
757 if (lmv->refcount != 0)
760 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
761 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
764 lmv_disconnect_mdc(obd, lmv->tgts[i]);
768 if (obd->obd_proc_private)
769 lprocfs_remove((struct proc_dir_entry **)&obd->obd_proc_private);
771 CERROR("/proc/fs/lustre/%s/%s/target_obds missing\n",
772 obd->obd_type->typ_name, obd->obd_name);
777 * This is the case when no real connection is established by
778 * lmv_check_connect().
781 class_export_put(exp);
782 rc = class_disconnect(exp);
783 if (lmv->refcount == 0)
788 static int lmv_fid2path(struct obd_export *exp, int len, void *karg, void *uarg)
790 struct obd_device *obddev = class_exp2obd(exp);
791 struct lmv_obd *lmv = &obddev->u.lmv;
792 struct getinfo_fid2path *gf;
793 struct lmv_tgt_desc *tgt;
794 struct getinfo_fid2path *remote_gf = NULL;
795 int remote_gf_size = 0;
798 gf = (struct getinfo_fid2path *)karg;
799 tgt = lmv_find_target(lmv, &gf->gf_fid);
801 RETURN(PTR_ERR(tgt));
804 rc = obd_iocontrol(OBD_IOC_FID2PATH, tgt->ltd_exp, len, gf, uarg);
805 if (rc != 0 && rc != -EREMOTE)
806 GOTO(out_fid2path, rc);
808 /* If remote_gf != NULL, it means just building the
809 * path on the remote MDT, copy this path segement to gf */
810 if (remote_gf != NULL) {
811 struct getinfo_fid2path *ori_gf;
814 ori_gf = (struct getinfo_fid2path *)karg;
815 if (strlen(ori_gf->gf_path) +
816 strlen(gf->gf_path) > ori_gf->gf_pathlen)
817 GOTO(out_fid2path, rc = -EOVERFLOW);
819 ptr = ori_gf->gf_path;
821 memmove(ptr + strlen(gf->gf_path) + 1, ptr,
822 strlen(ori_gf->gf_path));
824 strncpy(ptr, gf->gf_path, strlen(gf->gf_path));
825 ptr += strlen(gf->gf_path);
829 CDEBUG(D_INFO, "%s: get path %s "DFID" rec: "LPU64" ln: %u\n",
830 tgt->ltd_exp->exp_obd->obd_name,
831 gf->gf_path, PFID(&gf->gf_fid), gf->gf_recno,
835 GOTO(out_fid2path, rc);
837 /* sigh, has to go to another MDT to do path building further */
838 if (remote_gf == NULL) {
839 remote_gf_size = sizeof(*remote_gf) + PATH_MAX;
840 OBD_ALLOC(remote_gf, remote_gf_size);
841 if (remote_gf == NULL)
842 GOTO(out_fid2path, rc = -ENOMEM);
843 remote_gf->gf_pathlen = PATH_MAX;
846 if (!fid_is_sane(&gf->gf_fid)) {
847 CERROR("%s: invalid FID "DFID": rc = %d\n",
848 tgt->ltd_exp->exp_obd->obd_name,
849 PFID(&gf->gf_fid), -EINVAL);
850 GOTO(out_fid2path, rc = -EINVAL);
853 tgt = lmv_find_target(lmv, &gf->gf_fid);
855 GOTO(out_fid2path, rc = -EINVAL);
857 remote_gf->gf_fid = gf->gf_fid;
858 remote_gf->gf_recno = -1;
859 remote_gf->gf_linkno = -1;
860 memset(remote_gf->gf_path, 0, remote_gf->gf_pathlen);
862 goto repeat_fid2path;
865 if (remote_gf != NULL)
866 OBD_FREE(remote_gf, remote_gf_size);
870 static int lmv_hsm_req_count(struct lmv_obd *lmv,
871 const struct hsm_user_request *hur,
872 const struct lmv_tgt_desc *tgt_mds)
876 struct lmv_tgt_desc *curr_tgt;
878 /* count how many requests must be sent to the given target */
879 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
880 curr_tgt = lmv_find_target(lmv, &hur->hur_user_item[i].hui_fid);
881 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid))
887 static void lmv_hsm_req_build(struct lmv_obd *lmv,
888 struct hsm_user_request *hur_in,
889 const struct lmv_tgt_desc *tgt_mds,
890 struct hsm_user_request *hur_out)
893 struct lmv_tgt_desc *curr_tgt;
895 /* build the hsm_user_request for the given target */
896 hur_out->hur_request = hur_in->hur_request;
898 for (i = 0; i < hur_in->hur_request.hr_itemcount; i++) {
899 curr_tgt = lmv_find_target(lmv,
900 &hur_in->hur_user_item[i].hui_fid);
901 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid)) {
902 hur_out->hur_user_item[nr_out] =
903 hur_in->hur_user_item[i];
907 hur_out->hur_request.hr_itemcount = nr_out;
908 memcpy(hur_data(hur_out), hur_data(hur_in),
909 hur_in->hur_request.hr_data_len);
912 static int lmv_hsm_ct_unregister(struct lmv_obd *lmv, unsigned int cmd, int len,
913 struct lustre_kernelcomm *lk, void *uarg)
917 struct kkuc_ct_data *kcd = NULL;
920 /* unregister request (call from llapi_hsm_copytool_fini) */
921 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
922 struct lmv_tgt_desc *tgt = lmv->tgts[i];
924 if (tgt == NULL || tgt->ltd_exp == NULL)
926 /* best effort: try to clean as much as possible
927 * (continue on error) */
928 obd_iocontrol(cmd, tgt->ltd_exp, len, lk, uarg);
931 /* Whatever the result, remove copytool from kuc groups.
932 * Unreached coordinators will get EPIPE on next requests
933 * and will unregister automatically.
935 rc = libcfs_kkuc_group_rem(lk->lk_uid, lk->lk_group, (void **)&kcd);
942 static int lmv_hsm_ct_register(struct lmv_obd *lmv, unsigned int cmd, int len,
943 struct lustre_kernelcomm *lk, void *uarg)
948 bool any_set = false;
949 struct kkuc_ct_data *kcd;
952 /* All or nothing: try to register to all MDS.
953 * In case of failure, unregister from previous MDS,
954 * except if it because of inactive target. */
955 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
956 struct lmv_tgt_desc *tgt = lmv->tgts[i];
958 if (tgt == NULL || tgt->ltd_exp == NULL)
960 err = obd_iocontrol(cmd, tgt->ltd_exp, len, lk, uarg);
962 if (tgt->ltd_active) {
963 /* permanent error */
964 CERROR("%s: iocontrol MDC %s on MDT"
965 " idx %d cmd %x: err = %d\n",
966 class_exp2obd(lmv->exp)->obd_name,
967 tgt->ltd_uuid.uuid, i, cmd, err);
969 lk->lk_flags |= LK_FLG_STOP;
970 /* unregister from previous MDS */
971 for (j = 0; j < i; j++) {
973 if (tgt == NULL || tgt->ltd_exp == NULL)
975 obd_iocontrol(cmd, tgt->ltd_exp, len,
980 /* else: transient error.
981 * kuc will register to the missing MDT
989 /* no registration done: return error */
992 /* at least one registration done, with no failure */
993 filp = fget(lk->lk_wfd);
1002 kcd->kcd_magic = KKUC_CT_DATA_MAGIC;
1003 kcd->kcd_uuid = lmv->cluuid;
1004 kcd->kcd_archive = lk->lk_data;
1006 rc = libcfs_kkuc_group_add(filp, lk->lk_uid, lk->lk_group, kcd);
1019 static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
1020 int len, void *karg, void *uarg)
1022 struct obd_device *obddev = class_exp2obd(exp);
1023 struct lmv_obd *lmv = &obddev->u.lmv;
1024 struct lmv_tgt_desc *tgt = NULL;
1028 __u32 count = lmv->desc.ld_tgt_count;
1035 case IOC_OBD_STATFS: {
1036 struct obd_ioctl_data *data = karg;
1037 struct obd_device *mdc_obd;
1038 struct obd_statfs stat_buf = {0};
1041 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
1042 if ((index >= count))
1045 tgt = lmv->tgts[index];
1046 if (tgt == NULL || !tgt->ltd_active)
1049 mdc_obd = class_exp2obd(tgt->ltd_exp);
1054 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(mdc_obd),
1055 min((int) data->ioc_plen2,
1056 (int) sizeof(struct obd_uuid))))
1059 rc = obd_statfs(NULL, tgt->ltd_exp, &stat_buf,
1060 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1064 if (copy_to_user(data->ioc_pbuf1, &stat_buf,
1065 min((int) data->ioc_plen1,
1066 (int) sizeof(stat_buf))))
1070 case OBD_IOC_QUOTACTL: {
1071 struct if_quotactl *qctl = karg;
1072 struct obd_quotactl *oqctl;
1074 if (qctl->qc_valid == QC_MDTIDX) {
1075 if (count <= qctl->qc_idx)
1078 tgt = lmv->tgts[qctl->qc_idx];
1079 if (tgt == NULL || tgt->ltd_exp == NULL)
1081 } else if (qctl->qc_valid == QC_UUID) {
1082 for (i = 0; i < count; i++) {
1086 if (!obd_uuid_equals(&tgt->ltd_uuid,
1090 if (tgt->ltd_exp == NULL)
1102 LASSERT(tgt != NULL && tgt->ltd_exp != NULL);
1103 OBD_ALLOC_PTR(oqctl);
1107 QCTL_COPY(oqctl, qctl);
1108 rc = obd_quotactl(tgt->ltd_exp, oqctl);
1110 QCTL_COPY(qctl, oqctl);
1111 qctl->qc_valid = QC_MDTIDX;
1112 qctl->obd_uuid = tgt->ltd_uuid;
1114 OBD_FREE_PTR(oqctl);
1117 case OBD_IOC_CHANGELOG_SEND:
1118 case OBD_IOC_CHANGELOG_CLEAR: {
1119 struct ioc_changelog *icc = karg;
1121 if (icc->icc_mdtindex >= count)
1124 tgt = lmv->tgts[icc->icc_mdtindex];
1125 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
1127 rc = obd_iocontrol(cmd, tgt->ltd_exp, sizeof(*icc), icc, NULL);
1130 case LL_IOC_GET_CONNECT_FLAGS: {
1132 if (tgt == NULL || tgt->ltd_exp == NULL)
1134 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1137 case OBD_IOC_FID2PATH: {
1138 rc = lmv_fid2path(exp, len, karg, uarg);
1141 case LL_IOC_HSM_STATE_GET:
1142 case LL_IOC_HSM_STATE_SET:
1143 case LL_IOC_HSM_ACTION: {
1144 struct md_op_data *op_data = karg;
1146 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1148 RETURN(PTR_ERR(tgt));
1150 if (tgt->ltd_exp == NULL)
1153 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1156 case LL_IOC_HSM_PROGRESS: {
1157 const struct hsm_progress_kernel *hpk = karg;
1159 tgt = lmv_find_target(lmv, &hpk->hpk_fid);
1161 RETURN(PTR_ERR(tgt));
1162 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1165 case LL_IOC_HSM_REQUEST: {
1166 struct hsm_user_request *hur = karg;
1167 unsigned int reqcount = hur->hur_request.hr_itemcount;
1172 /* if the request is about a single fid
1173 * or if there is a single MDS, no need to split
1175 if (reqcount == 1 || count == 1) {
1176 tgt = lmv_find_target(lmv,
1177 &hur->hur_user_item[0].hui_fid);
1179 RETURN(PTR_ERR(tgt));
1180 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1182 /* split fid list to their respective MDS */
1183 for (i = 0; i < count; i++) {
1184 unsigned int nr, reqlen;
1186 struct hsm_user_request *req;
1189 if (tgt == NULL || tgt->ltd_exp == NULL)
1192 nr = lmv_hsm_req_count(lmv, hur, tgt);
1193 if (nr == 0) /* nothing for this MDS */
1196 /* build a request with fids for this MDS */
1197 reqlen = offsetof(typeof(*hur),
1199 + hur->hur_request.hr_data_len;
1200 OBD_ALLOC_LARGE(req, reqlen);
1204 lmv_hsm_req_build(lmv, hur, tgt, req);
1206 rc1 = obd_iocontrol(cmd, tgt->ltd_exp, reqlen,
1208 if (rc1 != 0 && rc == 0)
1210 OBD_FREE_LARGE(req, reqlen);
1215 case LL_IOC_LOV_SWAP_LAYOUTS: {
1216 struct md_op_data *op_data = karg;
1217 struct lmv_tgt_desc *tgt1, *tgt2;
1219 tgt1 = lmv_find_target(lmv, &op_data->op_fid1);
1221 RETURN(PTR_ERR(tgt1));
1223 tgt2 = lmv_find_target(lmv, &op_data->op_fid2);
1225 RETURN(PTR_ERR(tgt2));
1227 if ((tgt1->ltd_exp == NULL) || (tgt2->ltd_exp == NULL))
1230 /* only files on same MDT can have their layouts swapped */
1231 if (tgt1->ltd_idx != tgt2->ltd_idx)
1234 rc = obd_iocontrol(cmd, tgt1->ltd_exp, len, karg, uarg);
1237 case LL_IOC_HSM_CT_START: {
1238 struct lustre_kernelcomm *lk = karg;
1239 if (lk->lk_flags & LK_FLG_STOP)
1240 rc = lmv_hsm_ct_unregister(lmv, cmd, len, lk, uarg);
1242 rc = lmv_hsm_ct_register(lmv, cmd, len, lk, uarg);
1246 for (i = 0; i < count; i++) {
1247 struct obd_device *mdc_obd;
1251 if (tgt == NULL || tgt->ltd_exp == NULL)
1253 /* ll_umount_begin() sets force flag but for lmv, not
1254 * mdc. Let's pass it through */
1255 mdc_obd = class_exp2obd(tgt->ltd_exp);
1256 mdc_obd->obd_force = obddev->obd_force;
1257 err = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1258 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
1261 if (tgt->ltd_active) {
1262 CERROR("error: iocontrol MDC %s on MDT"
1263 " idx %d cmd %x: err = %d\n",
1264 tgt->ltd_uuid.uuid, i, cmd, err);
1278 static int lmv_all_chars_policy(int count, const char *name,
1289 static int lmv_nid_policy(struct lmv_obd *lmv)
1291 struct obd_import *imp;
1295 * XXX: To get nid we assume that underlying obd device is mdc.
1297 imp = class_exp2cliimp(lmv->tgts[0].ltd_exp);
1298 id = imp->imp_connection->c_self ^ (imp->imp_connection->c_self >> 32);
1299 return id % lmv->desc.ld_tgt_count;
1302 static int lmv_choose_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1303 placement_policy_t placement)
1305 switch (placement) {
1306 case PLACEMENT_CHAR_POLICY:
1307 return lmv_all_chars_policy(lmv->desc.ld_tgt_count,
1309 op_data->op_namelen);
1310 case PLACEMENT_NID_POLICY:
1311 return lmv_nid_policy(lmv);
1317 CERROR("Unsupported placement policy %x\n", placement);
1323 * This is _inode_ placement policy function (not name).
1325 static int lmv_placement_policy(struct obd_device *obd,
1326 struct md_op_data *op_data,
1329 struct lmv_obd *lmv = &obd->u.lmv;
1332 LASSERT(mds != NULL);
1334 if (lmv->desc.ld_tgt_count == 1) {
1340 * If stripe_offset is provided during setdirstripe
1341 * (setdirstripe -i xx), xx MDS will be choosen.
1343 if (op_data->op_cli_flags & CLI_SET_MEA && op_data->op_data != NULL) {
1344 struct lmv_user_md *lum;
1346 lum = op_data->op_data;
1347 *mds = lum->lum_stripe_offset;
1349 /* Allocate new fid on target according to operation type and
1350 * parent home mds. */
1351 *mds = op_data->op_mds;
1357 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid,
1360 struct lmv_tgt_desc *tgt;
1364 tgt = lmv_get_target(lmv, mds);
1366 RETURN(PTR_ERR(tgt));
1369 * New seq alloc and FLD setup should be atomic. Otherwise we may find
1370 * on server that seq in new allocated fid is not yet known.
1372 mutex_lock(&tgt->ltd_fid_mutex);
1374 if (tgt->ltd_active == 0 || tgt->ltd_exp == NULL)
1375 GOTO(out, rc = -ENODEV);
1378 * Asking underlaying tgt layer to allocate new fid.
1380 rc = obd_fid_alloc(tgt->ltd_exp, fid, NULL);
1382 LASSERT(fid_is_sane(fid));
1388 mutex_unlock(&tgt->ltd_fid_mutex);
1392 int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
1393 struct md_op_data *op_data)
1395 struct obd_device *obd = class_exp2obd(exp);
1396 struct lmv_obd *lmv = &obd->u.lmv;
1401 LASSERT(op_data != NULL);
1402 LASSERT(fid != NULL);
1404 rc = lmv_placement_policy(obd, op_data, &mds);
1406 CERROR("Can't get target for allocating fid, "
1411 rc = __lmv_fid_alloc(lmv, fid, mds);
1413 CERROR("Can't alloc new fid, rc %d\n", rc);
1420 static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
1422 struct lmv_obd *lmv = &obd->u.lmv;
1423 struct lmv_desc *desc;
1427 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
1428 CERROR("LMV setup requires a descriptor\n");
1432 desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1);
1433 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
1434 CERROR("Lmv descriptor size wrong: %d > %d\n",
1435 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
1439 OBD_ALLOC(lmv->tgts, sizeof(*lmv->tgts) * 32);
1440 if (lmv->tgts == NULL)
1442 lmv->tgts_size = 32;
1444 obd_str2uuid(&lmv->desc.ld_uuid, desc->ld_uuid.uuid);
1445 lmv->desc.ld_tgt_count = 0;
1446 lmv->desc.ld_active_tgt_count = 0;
1447 lmv->max_cookiesize = 0;
1448 lmv->max_def_easize = 0;
1449 lmv->max_easize = 0;
1450 lmv->lmv_placement = PLACEMENT_CHAR_POLICY;
1452 spin_lock_init(&lmv->lmv_lock);
1453 mutex_init(&lmv->init_mutex);
1456 obd->obd_vars = lprocfs_lmv_obd_vars;
1457 lprocfs_seq_obd_setup(obd);
1458 lprocfs_alloc_md_stats(obd, 0);
1459 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
1460 0444, &lmv_proc_target_fops, obd);
1462 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
1465 rc = fld_client_init(&lmv->lmv_fld, obd->obd_name,
1466 LUSTRE_CLI_FLD_HASH_DHT);
1468 CERROR("Can't init FLD, err %d\n", rc);
1478 static int lmv_cleanup(struct obd_device *obd)
1480 struct lmv_obd *lmv = &obd->u.lmv;
1483 fld_client_fini(&lmv->lmv_fld);
1484 if (lmv->tgts != NULL) {
1486 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1487 if (lmv->tgts[i] == NULL)
1489 lmv_del_target(lmv, i);
1491 OBD_FREE(lmv->tgts, sizeof(*lmv->tgts) * lmv->tgts_size);
1497 static int lmv_process_config(struct obd_device *obd, obd_count len, void *buf)
1499 struct lustre_cfg *lcfg = buf;
1500 struct obd_uuid obd_uuid;
1506 switch (lcfg->lcfg_command) {
1508 /* modify_mdc_tgts add 0:lustre-clilmv 1:lustre-MDT0000_UUID
1509 * 2:0 3:1 4:lustre-MDT0000-mdc_UUID */
1510 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
1511 GOTO(out, rc = -EINVAL);
1513 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
1515 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
1516 GOTO(out, rc = -EINVAL);
1517 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
1518 GOTO(out, rc = -EINVAL);
1519 rc = lmv_add_target(obd, &obd_uuid, index, gen);
1522 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1523 GOTO(out, rc = -EINVAL);
1529 static int lmv_statfs(const struct lu_env *env, struct obd_export *exp,
1530 struct obd_statfs *osfs, __u64 max_age, __u32 flags)
1532 struct obd_device *obd = class_exp2obd(exp);
1533 struct lmv_obd *lmv = &obd->u.lmv;
1534 struct obd_statfs *temp;
1539 rc = lmv_check_connect(obd);
1543 OBD_ALLOC(temp, sizeof(*temp));
1547 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1548 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1551 rc = obd_statfs(env, lmv->tgts[i]->ltd_exp, temp,
1554 CERROR("can't stat MDS #%d (%s), error %d\n", i,
1555 lmv->tgts[i]->ltd_exp->exp_obd->obd_name,
1557 GOTO(out_free_temp, rc);
1562 /* If the statfs is from mount, it will needs
1563 * retrieve necessary information from MDT0.
1564 * i.e. mount does not need the merged osfs
1566 * And also clients can be mounted as long as
1567 * MDT0 is in service*/
1568 if (flags & OBD_STATFS_FOR_MDT0)
1569 GOTO(out_free_temp, rc);
1571 osfs->os_bavail += temp->os_bavail;
1572 osfs->os_blocks += temp->os_blocks;
1573 osfs->os_ffree += temp->os_ffree;
1574 osfs->os_files += temp->os_files;
1580 OBD_FREE(temp, sizeof(*temp));
1584 static int lmv_getstatus(struct obd_export *exp,
1586 struct obd_capa **pc)
1588 struct obd_device *obd = exp->exp_obd;
1589 struct lmv_obd *lmv = &obd->u.lmv;
1593 rc = lmv_check_connect(obd);
1597 rc = md_getstatus(lmv->tgts[0]->ltd_exp, fid, pc);
1601 static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1602 struct obd_capa *oc, obd_valid valid, const char *name,
1603 const char *input, int input_size, int output_size,
1604 int flags, struct ptlrpc_request **request)
1606 struct obd_device *obd = exp->exp_obd;
1607 struct lmv_obd *lmv = &obd->u.lmv;
1608 struct lmv_tgt_desc *tgt;
1612 rc = lmv_check_connect(obd);
1616 tgt = lmv_find_target(lmv, fid);
1618 RETURN(PTR_ERR(tgt));
1620 rc = md_getxattr(tgt->ltd_exp, fid, oc, valid, name, input,
1621 input_size, output_size, flags, request);
1626 static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1627 struct obd_capa *oc, obd_valid valid, const char *name,
1628 const char *input, int input_size, int output_size,
1629 int flags, __u32 suppgid,
1630 struct ptlrpc_request **request)
1632 struct obd_device *obd = exp->exp_obd;
1633 struct lmv_obd *lmv = &obd->u.lmv;
1634 struct lmv_tgt_desc *tgt;
1638 rc = lmv_check_connect(obd);
1642 tgt = lmv_find_target(lmv, fid);
1644 RETURN(PTR_ERR(tgt));
1646 rc = md_setxattr(tgt->ltd_exp, fid, oc, valid, name, input,
1647 input_size, output_size, flags, suppgid,
1653 static int lmv_getattr(struct obd_export *exp, struct md_op_data *op_data,
1654 struct ptlrpc_request **request)
1656 struct obd_device *obd = exp->exp_obd;
1657 struct lmv_obd *lmv = &obd->u.lmv;
1658 struct lmv_tgt_desc *tgt;
1662 rc = lmv_check_connect(obd);
1666 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1668 RETURN(PTR_ERR(tgt));
1670 if (op_data->op_flags & MF_GET_MDT_IDX) {
1671 op_data->op_mds = tgt->ltd_idx;
1675 rc = md_getattr(tgt->ltd_exp, op_data, request);
1680 static int lmv_null_inode(struct obd_export *exp, const struct lu_fid *fid)
1682 struct obd_device *obd = exp->exp_obd;
1683 struct lmv_obd *lmv = &obd->u.lmv;
1688 rc = lmv_check_connect(obd);
1692 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1695 * With DNE every object can have two locks in different namespaces:
1696 * lookup lock in space of MDT storing direntry and update/open lock in
1697 * space of MDT storing inode.
1699 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1700 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1702 md_null_inode(lmv->tgts[i]->ltd_exp, fid);
1708 static int lmv_find_cbdata(struct obd_export *exp, const struct lu_fid *fid,
1709 ldlm_iterator_t it, void *data)
1711 struct obd_device *obd = exp->exp_obd;
1712 struct lmv_obd *lmv = &obd->u.lmv;
1717 rc = lmv_check_connect(obd);
1721 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1724 * With DNE every object can have two locks in different namespaces:
1725 * lookup lock in space of MDT storing direntry and update/open lock in
1726 * space of MDT storing inode.
1728 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1729 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1731 rc = md_find_cbdata(lmv->tgts[i]->ltd_exp, fid, it, data);
1740 static int lmv_close(struct obd_export *exp, struct md_op_data *op_data,
1741 struct md_open_data *mod, struct ptlrpc_request **request)
1743 struct obd_device *obd = exp->exp_obd;
1744 struct lmv_obd *lmv = &obd->u.lmv;
1745 struct lmv_tgt_desc *tgt;
1749 rc = lmv_check_connect(obd);
1753 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1755 RETURN(PTR_ERR(tgt));
1757 CDEBUG(D_INODE, "CLOSE "DFID"\n", PFID(&op_data->op_fid1));
1758 rc = md_close(tgt->ltd_exp, op_data, mod, request);
1763 * Choosing the MDT by name or FID in @op_data.
1764 * For non-striped directory, it will locate MDT by fid.
1765 * For striped-directory, it will locate MDT by name. And also
1766 * it will reset op_fid1 with the FID of the choosen stripe.
1769 *lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1772 struct lmv_stripe_md *lsm = op_data->op_mea1;
1773 struct lmv_tgt_desc *tgt;
1774 const struct lmv_oinfo *oinfo;
1776 if (lsm == NULL || lsm->lsm_md_stripe_count <= 1 ||
1777 op_data->op_namelen == 0) {
1778 tgt = lmv_find_target(lmv, fid);
1782 op_data->op_mds = tgt->ltd_idx;
1786 oinfo = lsm_name_to_stripe_info(lsm, op_data->op_name,
1787 op_data->op_namelen);
1788 *fid = oinfo->lmo_fid;
1789 op_data->op_mds = oinfo->lmo_mds;
1790 tgt = lmv_get_target(lmv, op_data->op_mds);
1792 CDEBUG(D_INFO, "locate on mds %u\n", op_data->op_mds);
1797 int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
1798 const void *data, int datalen, int mode, __u32 uid,
1799 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1800 struct ptlrpc_request **request)
1802 struct obd_device *obd = exp->exp_obd;
1803 struct lmv_obd *lmv = &obd->u.lmv;
1804 struct lmv_tgt_desc *tgt;
1808 rc = lmv_check_connect(obd);
1812 if (!lmv->desc.ld_active_tgt_count)
1815 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1817 RETURN(PTR_ERR(tgt));
1819 CDEBUG(D_INODE, "CREATE name '%.*s' on "DFID" -> mds #%x\n",
1820 op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1),
1823 rc = lmv_fid_alloc(exp, &op_data->op_fid2, op_data);
1827 /* Send the create request to the MDT where the object
1828 * will be located */
1829 tgt = lmv_find_target(lmv, &op_data->op_fid2);
1831 RETURN(PTR_ERR(tgt));
1833 op_data->op_mds = tgt->ltd_idx;
1835 CDEBUG(D_INODE, "CREATE obj "DFID" -> mds #%x\n",
1836 PFID(&op_data->op_fid2), op_data->op_mds);
1838 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1839 rc = md_create(tgt->ltd_exp, op_data, data, datalen, mode, uid, gid,
1840 cap_effective, rdev, request);
1842 if (*request == NULL)
1844 CDEBUG(D_INODE, "Created - "DFID"\n", PFID(&op_data->op_fid2));
1849 static int lmv_done_writing(struct obd_export *exp,
1850 struct md_op_data *op_data,
1851 struct md_open_data *mod)
1853 struct obd_device *obd = exp->exp_obd;
1854 struct lmv_obd *lmv = &obd->u.lmv;
1855 struct lmv_tgt_desc *tgt;
1859 rc = lmv_check_connect(obd);
1863 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1865 RETURN(PTR_ERR(tgt));
1867 rc = md_done_writing(tgt->ltd_exp, op_data, mod);
1872 lmv_enqueue_remote(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1873 struct lookup_intent *it, struct md_op_data *op_data,
1874 struct lustre_handle *lockh, void *lmm, int lmmsize,
1875 __u64 extra_lock_flags)
1877 struct ptlrpc_request *req = it->d.lustre.it_data;
1878 struct obd_device *obd = exp->exp_obd;
1879 struct lmv_obd *lmv = &obd->u.lmv;
1880 struct lustre_handle plock;
1881 struct lmv_tgt_desc *tgt;
1882 struct md_op_data *rdata;
1884 struct mdt_body *body;
1889 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1890 LASSERT(body != NULL);
1892 if (!(body->valid & OBD_MD_MDS))
1895 CDEBUG(D_INODE, "REMOTE_ENQUEUE '%s' on "DFID" -> "DFID"\n",
1896 LL_IT2STR(it), PFID(&op_data->op_fid1), PFID(&body->fid1));
1899 * We got LOOKUP lock, but we really need attrs.
1901 pmode = it->d.lustre.it_lock_mode;
1902 LASSERT(pmode != 0);
1903 memcpy(&plock, lockh, sizeof(plock));
1904 it->d.lustre.it_lock_mode = 0;
1905 it->d.lustre.it_data = NULL;
1908 ptlrpc_req_finished(req);
1910 tgt = lmv_find_target(lmv, &fid1);
1912 GOTO(out, rc = PTR_ERR(tgt));
1914 OBD_ALLOC_PTR(rdata);
1916 GOTO(out, rc = -ENOMEM);
1918 rdata->op_fid1 = fid1;
1919 rdata->op_bias = MDS_CROSS_REF;
1921 rc = md_enqueue(tgt->ltd_exp, einfo, it, rdata, lockh,
1922 lmm, lmmsize, NULL, extra_lock_flags);
1923 OBD_FREE_PTR(rdata);
1926 ldlm_lock_decref(&plock, pmode);
1931 lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1932 struct lookup_intent *it, struct md_op_data *op_data,
1933 struct lustre_handle *lockh, void *lmm, int lmmsize,
1934 struct ptlrpc_request **req, __u64 extra_lock_flags)
1936 struct obd_device *obd = exp->exp_obd;
1937 struct lmv_obd *lmv = &obd->u.lmv;
1938 struct lmv_tgt_desc *tgt;
1942 rc = lmv_check_connect(obd);
1946 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID"\n",
1947 LL_IT2STR(it), PFID(&op_data->op_fid1));
1949 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1951 RETURN(PTR_ERR(tgt));
1953 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID" -> mds #%d\n",
1954 LL_IT2STR(it), PFID(&op_data->op_fid1), tgt->ltd_idx);
1956 rc = md_enqueue(tgt->ltd_exp, einfo, it, op_data, lockh,
1957 lmm, lmmsize, req, extra_lock_flags);
1959 if (rc == 0 && it && it->it_op == IT_OPEN) {
1960 rc = lmv_enqueue_remote(exp, einfo, it, op_data, lockh,
1961 lmm, lmmsize, extra_lock_flags);
1967 lmv_getattr_name(struct obd_export *exp,struct md_op_data *op_data,
1968 struct ptlrpc_request **request)
1970 struct ptlrpc_request *req = NULL;
1971 struct obd_device *obd = exp->exp_obd;
1972 struct lmv_obd *lmv = &obd->u.lmv;
1973 struct lmv_tgt_desc *tgt;
1974 struct mdt_body *body;
1978 rc = lmv_check_connect(obd);
1982 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1984 RETURN(PTR_ERR(tgt));
1986 CDEBUG(D_INODE, "GETATTR_NAME for %*s on "DFID" -> mds #%d\n",
1987 op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1),
1990 rc = md_getattr_name(tgt->ltd_exp, op_data, request);
1994 body = req_capsule_server_get(&(*request)->rq_pill,
1996 LASSERT(body != NULL);
1998 if (body->valid & OBD_MD_MDS) {
1999 struct lu_fid rid = body->fid1;
2000 CDEBUG(D_INODE, "Request attrs for "DFID"\n",
2003 tgt = lmv_find_target(lmv, &rid);
2005 ptlrpc_req_finished(*request);
2006 RETURN(PTR_ERR(tgt));
2009 op_data->op_fid1 = rid;
2010 op_data->op_valid |= OBD_MD_FLCROSSREF;
2011 op_data->op_namelen = 0;
2012 op_data->op_name = NULL;
2013 rc = md_getattr_name(tgt->ltd_exp, op_data, &req);
2014 ptlrpc_req_finished(*request);
2021 #define md_op_data_fid(op_data, fl) \
2022 (fl == MF_MDC_CANCEL_FID1 ? &op_data->op_fid1 : \
2023 fl == MF_MDC_CANCEL_FID2 ? &op_data->op_fid2 : \
2024 fl == MF_MDC_CANCEL_FID3 ? &op_data->op_fid3 : \
2025 fl == MF_MDC_CANCEL_FID4 ? &op_data->op_fid4 : \
2028 static int lmv_early_cancel(struct obd_export *exp, struct md_op_data *op_data,
2029 int op_tgt, ldlm_mode_t mode, int bits, int flag)
2031 struct lu_fid *fid = md_op_data_fid(op_data, flag);
2032 struct obd_device *obd = exp->exp_obd;
2033 struct lmv_obd *lmv = &obd->u.lmv;
2034 struct lmv_tgt_desc *tgt;
2035 ldlm_policy_data_t policy = {{0}};
2039 if (!fid_is_sane(fid))
2042 tgt = lmv_find_target(lmv, fid);
2044 RETURN(PTR_ERR(tgt));
2046 if (tgt->ltd_idx != op_tgt) {
2047 CDEBUG(D_INODE, "EARLY_CANCEL on "DFID"\n", PFID(fid));
2048 policy.l_inodebits.bits = bits;
2049 rc = md_cancel_unused(tgt->ltd_exp, fid, &policy,
2050 mode, LCF_ASYNC, NULL);
2053 "EARLY_CANCEL skip operation target %d on "DFID"\n",
2055 op_data->op_flags |= flag;
2063 * llite passes fid of an target inode in op_data->op_fid1 and id of directory in
2066 static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
2067 struct ptlrpc_request **request)
2069 struct obd_device *obd = exp->exp_obd;
2070 struct lmv_obd *lmv = &obd->u.lmv;
2071 struct lmv_tgt_desc *tgt;
2075 rc = lmv_check_connect(obd);
2079 LASSERT(op_data->op_namelen != 0);
2081 CDEBUG(D_INODE, "LINK "DFID":%*s to "DFID"\n",
2082 PFID(&op_data->op_fid2), op_data->op_namelen,
2083 op_data->op_name, PFID(&op_data->op_fid1));
2085 op_data->op_fsuid = current_fsuid();
2086 op_data->op_fsgid = current_fsgid();
2087 op_data->op_cap = cfs_curproc_cap_pack();
2088 if (op_data->op_mea2 != NULL) {
2089 struct lmv_stripe_md *lsm = op_data->op_mea2;
2090 const struct lmv_oinfo *oinfo;
2092 oinfo = lsm_name_to_stripe_info(lsm, op_data->op_name,
2093 op_data->op_namelen);
2094 op_data->op_fid2 = oinfo->lmo_fid;
2097 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
2099 RETURN(PTR_ERR(tgt));
2102 * Cancel UPDATE lock on child (fid1).
2104 op_data->op_flags |= MF_MDC_CANCEL_FID2;
2105 rc = lmv_early_cancel(exp, op_data, tgt->ltd_idx, LCK_EX,
2106 MDS_INODELOCK_UPDATE, MF_MDC_CANCEL_FID1);
2110 rc = md_link(tgt->ltd_exp, op_data, request);
2115 static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
2116 const char *old, int oldlen, const char *new, int newlen,
2117 struct ptlrpc_request **request)
2119 struct obd_device *obd = exp->exp_obd;
2120 struct lmv_obd *lmv = &obd->u.lmv;
2121 struct lmv_tgt_desc *src_tgt;
2125 LASSERT(oldlen != 0);
2127 CDEBUG(D_INODE, "RENAME %.*s in "DFID":%d to %.*s in "DFID":%d\n",
2128 oldlen, old, PFID(&op_data->op_fid1),
2129 op_data->op_mea1 ? op_data->op_mea1->lsm_md_stripe_count : 0,
2130 newlen, new, PFID(&op_data->op_fid2),
2131 op_data->op_mea2 ? op_data->op_mea2->lsm_md_stripe_count : 0);
2133 rc = lmv_check_connect(obd);
2137 op_data->op_fsuid = current_fsuid();
2138 op_data->op_fsgid = current_fsgid();
2139 op_data->op_cap = cfs_curproc_cap_pack();
2141 if (op_data->op_mea1 != NULL) {
2142 struct lmv_stripe_md *lsm = op_data->op_mea1;
2143 const struct lmv_oinfo *oinfo;
2145 oinfo = lsm_name_to_stripe_info(lsm, old, oldlen);
2146 op_data->op_fid1 = oinfo->lmo_fid;
2147 op_data->op_mds = oinfo->lmo_mds;
2148 src_tgt = lmv_get_target(lmv, op_data->op_mds);
2149 if (IS_ERR(src_tgt))
2150 RETURN(PTR_ERR(src_tgt));
2152 src_tgt = lmv_find_target(lmv, &op_data->op_fid1);
2153 if (IS_ERR(src_tgt))
2154 RETURN(PTR_ERR(src_tgt));
2156 op_data->op_mds = src_tgt->ltd_idx;
2159 if (op_data->op_mea2) {
2160 struct lmv_stripe_md *lsm = op_data->op_mea2;
2161 const struct lmv_oinfo *oinfo;
2163 oinfo = lsm_name_to_stripe_info(lsm, new, newlen);
2164 op_data->op_fid2 = oinfo->lmo_fid;
2168 * LOOKUP lock on src child (fid3) should also be cancelled for
2169 * src_tgt in mdc_rename.
2171 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2174 * Cancel UPDATE locks on tgt parent (fid2), tgt_tgt is its
2177 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
2178 LCK_EX, MDS_INODELOCK_UPDATE,
2179 MF_MDC_CANCEL_FID2);
2182 * Cancel LOOKUP locks on tgt child (fid4) for parent tgt_tgt.
2185 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
2186 LCK_EX, MDS_INODELOCK_LOOKUP,
2187 MF_MDC_CANCEL_FID4);
2191 * Cancel all the locks on tgt child (fid4).
2194 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
2195 LCK_EX, MDS_INODELOCK_FULL,
2196 MF_MDC_CANCEL_FID4);
2199 rc = md_rename(src_tgt->ltd_exp, op_data, old, oldlen,
2200 new, newlen, request);
2204 static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
2205 void *ea, int ealen, void *ea2, int ea2len,
2206 struct ptlrpc_request **request,
2207 struct md_open_data **mod)
2209 struct obd_device *obd = exp->exp_obd;
2210 struct lmv_obd *lmv = &obd->u.lmv;
2211 struct lmv_tgt_desc *tgt;
2215 rc = lmv_check_connect(obd);
2219 CDEBUG(D_INODE, "SETATTR for "DFID", valid 0x%x\n",
2220 PFID(&op_data->op_fid1), op_data->op_attr.ia_valid);
2222 op_data->op_flags |= MF_MDC_CANCEL_FID1;
2223 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2225 RETURN(PTR_ERR(tgt));
2227 rc = md_setattr(tgt->ltd_exp, op_data, ea, ealen, ea2,
2228 ea2len, request, mod);
2233 static int lmv_fsync(struct obd_export *exp, const struct lu_fid *fid,
2234 struct obd_capa *oc, struct ptlrpc_request **request)
2236 struct obd_device *obd = exp->exp_obd;
2237 struct lmv_obd *lmv = &obd->u.lmv;
2238 struct lmv_tgt_desc *tgt;
2242 rc = lmv_check_connect(obd);
2246 tgt = lmv_find_target(lmv, fid);
2248 RETURN(PTR_ERR(tgt));
2250 rc = md_fsync(tgt->ltd_exp, fid, oc, request);
2255 * Adjust a set of pages, each page containing an array of lu_dirpages,
2256 * so that each page can be used as a single logical lu_dirpage.
2258 * A lu_dirpage is laid out as follows, where s = ldp_hash_start,
2259 * e = ldp_hash_end, f = ldp_flags, p = padding, and each "ent" is a
2260 * struct lu_dirent. It has size up to LU_PAGE_SIZE. The ldp_hash_end
2261 * value is used as a cookie to request the next lu_dirpage in a
2262 * directory listing that spans multiple pages (two in this example):
2265 * .|--------v------- -----.
2266 * |s|e|f|p|ent|ent| ... |ent|
2267 * '--|-------------- -----' Each CFS_PAGE contains a single
2268 * '------. lu_dirpage.
2269 * .---------v------- -----.
2270 * |s|e|f|p|ent| 0 | ... | 0 |
2271 * '----------------- -----'
2273 * However, on hosts where the native VM page size (PAGE_CACHE_SIZE) is
2274 * larger than LU_PAGE_SIZE, a single host page may contain multiple
2275 * lu_dirpages. After reading the lu_dirpages from the MDS, the
2276 * ldp_hash_end of the first lu_dirpage refers to the one immediately
2277 * after it in the same CFS_PAGE (arrows simplified for brevity, but
2278 * in general e0==s1, e1==s2, etc.):
2280 * .-------------------- -----.
2281 * |s0|e0|f0|p|ent|ent| ... |ent|
2282 * |---v---------------- -----|
2283 * |s1|e1|f1|p|ent|ent| ... |ent|
2284 * |---v---------------- -----| Here, each CFS_PAGE contains
2285 * ... multiple lu_dirpages.
2286 * |---v---------------- -----|
2287 * |s'|e'|f'|p|ent|ent| ... |ent|
2288 * '---|---------------- -----'
2290 * .----------------------------.
2293 * This structure is transformed into a single logical lu_dirpage as follows:
2295 * - Replace e0 with e' so the request for the next lu_dirpage gets the page
2296 * labeled 'next CFS_PAGE'.
2298 * - Copy the LDF_COLLIDE flag from f' to f0 to correctly reflect whether
2299 * a hash collision with the next page exists.
2301 * - Adjust the lde_reclen of the ending entry of each lu_dirpage to span
2302 * to the first entry of the next lu_dirpage.
2304 #if PAGE_CACHE_SIZE > LU_PAGE_SIZE
2305 static void lmv_adjust_dirpages(struct page **pages, int ncfspgs, int nlupgs)
2309 for (i = 0; i < ncfspgs; i++) {
2310 struct lu_dirpage *dp = kmap(pages[i]);
2311 struct lu_dirpage *first = dp;
2312 struct lu_dirent *end_dirent = NULL;
2313 struct lu_dirent *ent;
2314 __u64 hash_end = dp->ldp_hash_end;
2315 __u32 flags = dp->ldp_flags;
2317 while (--nlupgs > 0) {
2318 ent = lu_dirent_start(dp);
2319 for (end_dirent = ent; ent != NULL;
2320 end_dirent = ent, ent = lu_dirent_next(ent));
2322 /* Advance dp to next lu_dirpage. */
2323 dp = (struct lu_dirpage *)((char *)dp + LU_PAGE_SIZE);
2325 /* Check if we've reached the end of the CFS_PAGE. */
2326 if (!((unsigned long)dp & ~CFS_PAGE_MASK))
2329 /* Save the hash and flags of this lu_dirpage. */
2330 hash_end = dp->ldp_hash_end;
2331 flags = dp->ldp_flags;
2333 /* Check if lu_dirpage contains no entries. */
2337 /* Enlarge the end entry lde_reclen from 0 to
2338 * first entry of next lu_dirpage. */
2339 LASSERT(le16_to_cpu(end_dirent->lde_reclen) == 0);
2340 end_dirent->lde_reclen =
2341 cpu_to_le16((char *)(dp->ldp_entries) -
2342 (char *)end_dirent);
2345 first->ldp_hash_end = hash_end;
2346 first->ldp_flags &= ~cpu_to_le32(LDF_COLLIDE);
2347 first->ldp_flags |= flags & cpu_to_le32(LDF_COLLIDE);
2351 LASSERTF(nlupgs == 0, "left = %d", nlupgs);
2354 #define lmv_adjust_dirpages(pages, ncfspgs, nlupgs) do {} while (0)
2355 #endif /* PAGE_CACHE_SIZE > LU_PAGE_SIZE */
2357 #define NORMAL_MAX_STRIPES 4
2358 int lmv_read_entry(struct obd_export *exp, struct md_op_data *op_data,
2359 struct md_callback *cb_op, struct lu_dirent **ldp,
2360 struct page **ppage)
2362 struct obd_device *obd = exp->exp_obd;
2363 struct lmv_obd *lmv = &obd->u.lmv;
2364 struct lmv_stripe_md *lsm = op_data->op_mea1;
2365 struct lu_dirent *tmp_ents[NORMAL_MAX_STRIPES];
2366 struct lu_dirent **ents = NULL;
2370 struct page *min_page = NULL;
2375 rc = lmv_check_connect(obd);
2382 stripe_count = lsm->lsm_md_stripe_count;
2384 if (stripe_count > NORMAL_MAX_STRIPES) {
2385 OBD_ALLOC(ents, sizeof(ents[0]) * stripe_count);
2387 GOTO(out, rc = -ENOMEM);
2390 memset(ents, 0, sizeof(ents[0]) * stripe_count);
2393 min_hash = MDS_DIR_END_OFF;
2394 for (i = 0; i < stripe_count; i++) {
2395 struct lmv_tgt_desc *tgt;
2396 struct page *page = NULL;
2398 if (likely(lsm == NULL)) {
2399 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2401 GOTO(out, rc = PTR_ERR(tgt));
2402 LASSERT(op_data->op_data != NULL);
2404 tgt = lmv_get_target(lmv, lsm->lsm_md_oinfo[i].lmo_mds);
2406 GOTO(out, rc = PTR_ERR(tgt));
2407 op_data->op_fid1 = lsm->lsm_md_oinfo[i].lmo_fid;
2408 op_data->op_fid2 = lsm->lsm_md_oinfo[i].lmo_fid;
2409 op_data->op_stripe_offset = i;
2412 rc = md_read_entry(tgt->ltd_exp, op_data, cb_op, &ents[i],
2417 if (ents[i] != NULL &&
2418 le64_to_cpu(ents[i]->lde_hash) <= min_hash) {
2419 if (min_page != NULL)
2420 page_cache_release(min_page);
2422 min_hash = le64_to_cpu(ents[i]->lde_hash);
2427 if (min_hash != MDS_DIR_END_OFF)
2428 *ldp = ents[min_idx];
2432 if (stripe_count > NORMAL_MAX_STRIPES && ents != NULL)
2433 OBD_FREE(ents, sizeof(ents[0]) * stripe_count);
2435 if (rc != 0 && min_page != NULL) {
2437 page_cache_release(min_page);
2445 static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
2446 struct ptlrpc_request **request)
2448 struct obd_device *obd = exp->exp_obd;
2449 struct lmv_obd *lmv = &obd->u.lmv;
2450 struct lmv_tgt_desc *tgt = NULL;
2451 struct mdt_body *body;
2455 rc = lmv_check_connect(obd);
2459 /* Send unlink requests to the MDT where the child is located */
2460 if (likely(!fid_is_zero(&op_data->op_fid2)))
2461 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
2463 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
2465 RETURN(PTR_ERR(tgt));
2467 op_data->op_fsuid = current_fsuid();
2468 op_data->op_fsgid = current_fsgid();
2469 op_data->op_cap = cfs_curproc_cap_pack();
2472 * If child's fid is given, cancel unused locks for it if it is from
2473 * another export than parent.
2475 * LOOKUP lock for child (fid3) should also be cancelled on parent
2476 * tgt_tgt in mdc_unlink().
2478 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2481 * Cancel FULL locks on child (fid3).
2483 rc = lmv_early_cancel(exp, op_data, tgt->ltd_idx, LCK_EX,
2484 MDS_INODELOCK_FULL, MF_MDC_CANCEL_FID3);
2489 CDEBUG(D_INODE, "unlink with fid="DFID"/"DFID" -> mds #%d\n",
2490 PFID(&op_data->op_fid1), PFID(&op_data->op_fid2), tgt->ltd_idx);
2492 rc = md_unlink(tgt->ltd_exp, op_data, request);
2493 if (rc != 0 && rc != -EREMOTE)
2496 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
2500 /* Not cross-ref case, just get out of here. */
2501 if (likely(!(body->valid & OBD_MD_MDS)))
2504 CDEBUG(D_INODE, "%s: try unlink to another MDT for "DFID"\n",
2505 exp->exp_obd->obd_name, PFID(&body->fid1));
2507 /* This is a remote object, try remote MDT, Note: it may
2508 * try more than 1 time here, Considering following case
2509 * /mnt/lustre is root on MDT0, remote1 is on MDT1
2510 * 1. Initially A does not know where remote1 is, it send
2511 * unlink RPC to MDT0, MDT0 return -EREMOTE, it will
2512 * resend unlink RPC to MDT1 (retry 1st time).
2514 * 2. During the unlink RPC in flight,
2515 * client B mv /mnt/lustre/remote1 /mnt/lustre/remote2
2516 * and create new remote1, but on MDT0
2518 * 3. MDT1 get unlink RPC(from A), then do remote lock on
2519 * /mnt/lustre, then lookup get fid of remote1, and find
2520 * it is remote dir again, and replay -EREMOTE again.
2522 * 4. Then A will resend unlink RPC to MDT0. (retry 2nd times).
2524 * In theory, it might try unlimited time here, but it should
2525 * be very rare case. */
2526 op_data->op_fid2 = body->fid1;
2527 ptlrpc_req_finished(*request);
2533 static int lmv_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2535 struct lmv_obd *lmv = &obd->u.lmv;
2539 case OBD_CLEANUP_EARLY:
2540 /* XXX: here should be calling obd_precleanup() down to
2543 case OBD_CLEANUP_EXPORTS:
2544 fld_client_proc_fini(&lmv->lmv_fld);
2545 lprocfs_obd_cleanup(obd);
2546 lprocfs_free_md_stats(obd);
2554 static int lmv_get_info(const struct lu_env *env, struct obd_export *exp,
2555 __u32 keylen, void *key, __u32 *vallen, void *val,
2556 struct lov_stripe_md *lsm)
2558 struct obd_device *obd;
2559 struct lmv_obd *lmv;
2563 obd = class_exp2obd(exp);
2565 CDEBUG(D_IOCTL, "Invalid client cookie "LPX64"\n",
2566 exp->exp_handle.h_cookie);
2571 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
2574 rc = lmv_check_connect(obd);
2578 LASSERT(*vallen == sizeof(__u32));
2579 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2580 struct lmv_tgt_desc *tgt = lmv->tgts[i];
2582 * All tgts should be connected when this gets called.
2584 if (tgt == NULL || tgt->ltd_exp == NULL)
2587 if (!obd_get_info(env, tgt->ltd_exp, keylen, key,
2592 } else if (KEY_IS(KEY_MAX_EASIZE) || KEY_IS(KEY_CONN_DATA)) {
2593 rc = lmv_check_connect(obd);
2598 * Forwarding this request to first MDS, it should know LOV
2601 rc = obd_get_info(env, lmv->tgts[0]->ltd_exp, keylen, key,
2603 if (!rc && KEY_IS(KEY_CONN_DATA))
2604 exp->exp_connect_data = *(struct obd_connect_data *)val;
2606 } else if (KEY_IS(KEY_TGT_COUNT)) {
2607 *((int *)val) = lmv->desc.ld_tgt_count;
2611 CDEBUG(D_IOCTL, "Invalid key\n");
2615 int lmv_set_info_async(const struct lu_env *env, struct obd_export *exp,
2616 obd_count keylen, void *key, obd_count vallen,
2617 void *val, struct ptlrpc_request_set *set)
2619 struct lmv_tgt_desc *tgt = NULL;
2620 struct obd_device *obd;
2621 struct lmv_obd *lmv;
2625 obd = class_exp2obd(exp);
2627 CDEBUG(D_IOCTL, "Invalid client cookie "LPX64"\n",
2628 exp->exp_handle.h_cookie);
2633 if (KEY_IS(KEY_READ_ONLY) || KEY_IS(KEY_FLUSH_CTX)) {
2636 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2639 if (tgt == NULL || tgt->ltd_exp == NULL)
2642 err = obd_set_info_async(env, tgt->ltd_exp,
2643 keylen, key, vallen, val, set);
2654 static int lmv_pack_md_v1(const struct lmv_stripe_md *lsm,
2655 struct lmv_mds_md_v1 *lmm1)
2660 lmm1->lmv_magic = cpu_to_le32(lsm->lsm_md_magic);
2661 lmm1->lmv_stripe_count = cpu_to_le32(lsm->lsm_md_stripe_count);
2662 lmm1->lmv_master_mdt_index = cpu_to_le32(lsm->lsm_md_master_mdt_index);
2663 lmm1->lmv_hash_type = cpu_to_le32(lsm->lsm_md_hash_type);
2664 cplen = strlcpy(lmm1->lmv_pool_name, lsm->lsm_md_pool_name,
2665 sizeof(lmm1->lmv_pool_name));
2666 if (cplen >= sizeof(lmm1->lmv_pool_name))
2669 for (i = 0; i < lsm->lsm_md_stripe_count; i++)
2670 fid_cpu_to_le(&lmm1->lmv_stripe_fids[i],
2671 &lsm->lsm_md_oinfo[i].lmo_fid);
2675 int lmv_pack_md(union lmv_mds_md **lmmp, const struct lmv_stripe_md *lsm,
2679 bool allocated = false;
2683 LASSERT(lmmp != NULL);
2685 if (*lmmp != NULL && lsm == NULL) {
2688 stripe_count = lmv_mds_md_stripe_count_get(*lmmp);
2689 lmm_size = lmv_mds_md_size(stripe_count,
2690 le32_to_cpu((*lmmp)->lmv_magic));
2693 OBD_FREE(*lmmp, lmm_size);
2699 if (*lmmp == NULL && lsm == NULL) {
2700 lmm_size = lmv_mds_md_size(stripe_count, LMV_MAGIC);
2701 LASSERT(lmm_size > 0);
2702 OBD_ALLOC(*lmmp, lmm_size);
2705 lmv_mds_md_stripe_count_set(*lmmp, stripe_count);
2706 (*lmmp)->lmv_magic = cpu_to_le32(LMV_MAGIC);
2711 LASSERT(lsm != NULL);
2712 lmm_size = lmv_mds_md_size(lsm->lsm_md_stripe_count, lsm->lsm_md_magic);
2713 if (*lmmp == NULL) {
2714 OBD_ALLOC(*lmmp, lmm_size);
2720 switch (lsm->lsm_md_magic) {
2722 rc = lmv_pack_md_v1(lsm, &(*lmmp)->lmv_md_v1);
2729 if (rc != 0 && allocated) {
2730 OBD_FREE(*lmmp, lmm_size);
2736 EXPORT_SYMBOL(lmv_pack_md);
2738 static int lmv_unpack_md_v1(struct obd_export *exp, struct lmv_stripe_md *lsm,
2739 const struct lmv_mds_md_v1 *lmm1)
2741 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2748 lsm->lsm_md_magic = le32_to_cpu(lmm1->lmv_magic);
2749 lsm->lsm_md_stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
2750 lsm->lsm_md_master_mdt_index = le32_to_cpu(lmm1->lmv_master_mdt_index);
2751 lsm->lsm_md_hash_type = le32_to_cpu(lmm1->lmv_hash_type);
2752 lsm->lsm_md_layout_version = le32_to_cpu(lmm1->lmv_layout_version);
2753 cplen = strlcpy(lsm->lsm_md_pool_name, lmm1->lmv_pool_name,
2754 sizeof(lsm->lsm_md_pool_name));
2756 if (cplen >= sizeof(lsm->lsm_md_pool_name))
2759 CDEBUG(D_INFO, "unpack lsm count %d, master %d hash_type %d"
2760 "layout_version %d\n", lsm->lsm_md_stripe_count,
2761 lsm->lsm_md_master_mdt_index, lsm->lsm_md_hash_type,
2762 lsm->lsm_md_layout_version);
2764 stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
2765 for (i = 0; i < le32_to_cpu(stripe_count); i++) {
2766 fid_le_to_cpu(&lsm->lsm_md_oinfo[i].lmo_fid,
2767 &lmm1->lmv_stripe_fids[i]);
2768 rc = lmv_fld_lookup(lmv, &lsm->lsm_md_oinfo[i].lmo_fid,
2769 &lsm->lsm_md_oinfo[i].lmo_mds);
2772 CDEBUG(D_INFO, "unpack fid #%d "DFID"\n", i,
2773 PFID(&lsm->lsm_md_oinfo[i].lmo_fid));
2779 int lmv_unpack_md(struct obd_export *exp, struct lmv_stripe_md **lsmp,
2780 const union lmv_mds_md *lmm, int stripe_count)
2782 struct lmv_stripe_md *lsm;
2785 bool allocated = false;
2788 LASSERT(lsmp != NULL);
2792 if (lsm != NULL && lmm == NULL) {
2795 for (i = 1; i < lsm->lsm_md_stripe_count; i++) {
2796 if (lsm->lsm_md_oinfo[i].lmo_root != NULL)
2797 iput(lsm->lsm_md_oinfo[i].lmo_root);
2800 lsm_size = lmv_stripe_md_size(lsm->lsm_md_stripe_count);
2801 OBD_FREE(lsm, lsm_size);
2807 if (lsm == NULL && lmm == NULL) {
2808 lsm_size = lmv_stripe_md_size(stripe_count);
2809 OBD_ALLOC(lsm, lsm_size);
2812 lsm->lsm_md_stripe_count = stripe_count;
2818 if (le32_to_cpu(lmm->lmv_magic) != LMV_MAGIC_V1) {
2819 CERROR("%s: invalid magic %x.\n", exp->exp_obd->obd_name,
2820 le32_to_cpu(lmm->lmv_magic));
2824 lsm_size = lmv_stripe_md_size(lmv_mds_md_stripe_count_get(lmm));
2826 OBD_ALLOC(lsm, lsm_size);
2833 switch (le32_to_cpu(lmm->lmv_magic)) {
2835 rc = lmv_unpack_md_v1(exp, lsm, &lmm->lmv_md_v1);
2838 CERROR("%s: unrecognized magic %x\n", exp->exp_obd->obd_name,
2839 le32_to_cpu(lmm->lmv_magic));
2844 if (rc != 0 && allocated) {
2845 OBD_FREE(lsm, lsm_size);
2852 int lmv_alloc_memmd(struct lmv_stripe_md **lsmp, int stripes)
2854 return lmv_unpack_md(NULL, lsmp, NULL, stripes);
2856 EXPORT_SYMBOL(lmv_alloc_memmd);
2858 void lmv_free_memmd(struct lmv_stripe_md *lsm)
2860 lmv_unpack_md(NULL, &lsm, NULL, 0);
2862 EXPORT_SYMBOL(lmv_free_memmd);
2864 int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
2865 struct lov_mds_md *lmm, int disk_len)
2867 return lmv_unpack_md(exp, (struct lmv_stripe_md **)lsmp,
2868 (union lmv_mds_md *)lmm, disk_len);
2871 int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
2872 struct lov_stripe_md *lsm)
2874 struct obd_device *obd = exp->exp_obd;
2875 struct lmv_obd *lmv_obd = &obd->u.lmv;
2876 const struct lmv_stripe_md *lmv = (struct lmv_stripe_md *)lsm;
2881 stripe_count = lmv->lsm_md_stripe_count;
2883 stripe_count = lmv_obd->desc.ld_tgt_count;
2885 return lmv_mds_md_size(stripe_count, LMV_MAGIC_V1);
2888 return lmv_pack_md((union lmv_mds_md **)lmmp, lmv, 0);
2891 static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
2892 ldlm_policy_data_t *policy, ldlm_mode_t mode,
2893 ldlm_cancel_flags_t flags, void *opaque)
2895 struct obd_device *obd = exp->exp_obd;
2896 struct lmv_obd *lmv = &obd->u.lmv;
2902 LASSERT(fid != NULL);
2904 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2905 struct lmv_tgt_desc *tgt = lmv->tgts[i];
2907 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
2910 err = md_cancel_unused(tgt->ltd_exp, fid, policy, mode, flags,
2918 int lmv_set_lock_data(struct obd_export *exp, __u64 *lockh, void *data,
2921 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2922 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2926 if (tgt == NULL || tgt->ltd_exp == NULL)
2928 rc = md_set_lock_data(tgt->ltd_exp, lockh, data, bits);
2932 ldlm_mode_t lmv_lock_match(struct obd_export *exp, __u64 flags,
2933 const struct lu_fid *fid, ldlm_type_t type,
2934 ldlm_policy_data_t *policy, ldlm_mode_t mode,
2935 struct lustre_handle *lockh)
2937 struct obd_device *obd = exp->exp_obd;
2938 struct lmv_obd *lmv = &obd->u.lmv;
2943 CDEBUG(D_INODE, "Lock match for "DFID"\n", PFID(fid));
2946 * With CMD every object can have two locks in different namespaces:
2947 * lookup lock in space of mds storing direntry and update/open lock in
2948 * space of mds storing inode. Thus we check all targets, not only that
2949 * one fid was created in.
2951 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2952 struct lmv_tgt_desc *tgt = lmv->tgts[i];
2954 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
2957 rc = md_lock_match(tgt->ltd_exp, flags, fid, type, policy, mode,
2966 int lmv_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
2967 struct obd_export *dt_exp, struct obd_export *md_exp,
2968 struct lustre_md *md)
2970 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2971 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2973 if (tgt == NULL || tgt->ltd_exp == NULL)
2976 return md_get_lustre_md(lmv->tgts[0]->ltd_exp, req, dt_exp, md_exp, md);
2979 int lmv_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
2981 struct obd_device *obd = exp->exp_obd;
2982 struct lmv_obd *lmv = &obd->u.lmv;
2983 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2986 if (md->lmv != NULL)
2987 lmv_free_memmd(md->lmv);
2988 if (tgt == NULL || tgt->ltd_exp == NULL)
2990 RETURN(md_free_lustre_md(lmv->tgts[0]->ltd_exp, md));
2993 int lmv_set_open_replay_data(struct obd_export *exp,
2994 struct obd_client_handle *och,
2995 struct lookup_intent *it)
2997 struct obd_device *obd = exp->exp_obd;
2998 struct lmv_obd *lmv = &obd->u.lmv;
2999 struct lmv_tgt_desc *tgt;
3002 tgt = lmv_find_target(lmv, &och->och_fid);
3004 RETURN(PTR_ERR(tgt));
3006 RETURN(md_set_open_replay_data(tgt->ltd_exp, och, it));
3009 int lmv_clear_open_replay_data(struct obd_export *exp,
3010 struct obd_client_handle *och)
3012 struct obd_device *obd = exp->exp_obd;
3013 struct lmv_obd *lmv = &obd->u.lmv;
3014 struct lmv_tgt_desc *tgt;
3017 tgt = lmv_find_target(lmv, &och->och_fid);
3019 RETURN(PTR_ERR(tgt));
3021 RETURN(md_clear_open_replay_data(tgt->ltd_exp, och));
3024 static int lmv_get_remote_perm(struct obd_export *exp,
3025 const struct lu_fid *fid,
3026 struct obd_capa *oc, __u32 suppgid,
3027 struct ptlrpc_request **request)
3029 struct obd_device *obd = exp->exp_obd;
3030 struct lmv_obd *lmv = &obd->u.lmv;
3031 struct lmv_tgt_desc *tgt;
3035 rc = lmv_check_connect(obd);
3039 tgt = lmv_find_target(lmv, fid);
3041 RETURN(PTR_ERR(tgt));
3043 rc = md_get_remote_perm(tgt->ltd_exp, fid, oc, suppgid, request);
3047 static int lmv_renew_capa(struct obd_export *exp, struct obd_capa *oc,
3050 struct obd_device *obd = exp->exp_obd;
3051 struct lmv_obd *lmv = &obd->u.lmv;
3052 struct lmv_tgt_desc *tgt;
3056 rc = lmv_check_connect(obd);
3060 tgt = lmv_find_target(lmv, &oc->c_capa.lc_fid);
3062 RETURN(PTR_ERR(tgt));
3064 rc = md_renew_capa(tgt->ltd_exp, oc, cb);
3068 int lmv_unpack_capa(struct obd_export *exp, struct ptlrpc_request *req,
3069 const struct req_msg_field *field, struct obd_capa **oc)
3071 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
3072 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3074 if (tgt == NULL || tgt->ltd_exp == NULL)
3076 return md_unpack_capa(tgt->ltd_exp, req, field, oc);
3079 int lmv_intent_getattr_async(struct obd_export *exp,
3080 struct md_enqueue_info *minfo,
3081 struct ldlm_enqueue_info *einfo)
3083 struct md_op_data *op_data = &minfo->mi_data;
3084 struct obd_device *obd = exp->exp_obd;
3085 struct lmv_obd *lmv = &obd->u.lmv;
3086 struct lmv_tgt_desc *tgt = NULL;
3090 rc = lmv_check_connect(obd);
3094 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
3096 RETURN(PTR_ERR(tgt));
3098 rc = md_intent_getattr_async(tgt->ltd_exp, minfo, einfo);
3102 int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
3103 struct lu_fid *fid, __u64 *bits)
3105 struct obd_device *obd = exp->exp_obd;
3106 struct lmv_obd *lmv = &obd->u.lmv;
3107 struct lmv_tgt_desc *tgt;
3111 rc = lmv_check_connect(obd);
3115 tgt = lmv_find_target(lmv, fid);
3117 RETURN(PTR_ERR(tgt));
3119 rc = md_revalidate_lock(tgt->ltd_exp, it, fid, bits);
3124 * For lmv, only need to send request to master MDT, and the master MDT will
3125 * process with other slave MDTs. The only exception is Q_GETOQUOTA for which
3126 * we directly fetch data from the slave MDTs.
3128 int lmv_quotactl(struct obd_device *unused, struct obd_export *exp,
3129 struct obd_quotactl *oqctl)
3131 struct obd_device *obd = class_exp2obd(exp);
3132 struct lmv_obd *lmv = &obd->u.lmv;
3133 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3136 __u64 curspace, curinodes;
3140 tgt->ltd_exp == NULL ||
3142 lmv->desc.ld_tgt_count == 0) {
3143 CERROR("master lmv inactive\n");
3147 if (oqctl->qc_cmd != Q_GETOQUOTA) {
3148 rc = obd_quotactl(tgt->ltd_exp, oqctl);
3152 curspace = curinodes = 0;
3153 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
3157 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
3160 err = obd_quotactl(tgt->ltd_exp, oqctl);
3162 CERROR("getquota on mdt %d failed. %d\n", i, err);
3166 curspace += oqctl->qc_dqblk.dqb_curspace;
3167 curinodes += oqctl->qc_dqblk.dqb_curinodes;
3170 oqctl->qc_dqblk.dqb_curspace = curspace;
3171 oqctl->qc_dqblk.dqb_curinodes = curinodes;
3176 int lmv_quotacheck(struct obd_device *unused, struct obd_export *exp,
3177 struct obd_quotactl *oqctl)
3179 struct obd_device *obd = class_exp2obd(exp);
3180 struct lmv_obd *lmv = &obd->u.lmv;
3181 struct lmv_tgt_desc *tgt;
3186 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
3189 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active) {
3190 CERROR("lmv idx %d inactive\n", i);
3194 err = obd_quotacheck(tgt->ltd_exp, oqctl);
3202 int lmv_update_lsm_md(struct obd_export *exp, struct lmv_stripe_md *lsm,
3203 struct mdt_body *body, ldlm_blocking_callback cb_blocking)
3205 if (lsm->lsm_md_stripe_count <= 1)
3208 return lmv_revalidate_slaves(exp, body, lsm, cb_blocking, 0);
3211 int lmv_merge_attr(struct obd_export *exp, const struct lmv_stripe_md *lsm,
3212 struct cl_attr *attr)
3217 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
3218 struct inode *inode = lsm->lsm_md_oinfo[i].lmo_root;
3220 CDEBUG(D_INFO, ""DFID" size %llu, nlink %u, atime %lu ctime"
3221 "%lu, mtime %lu.\n", PFID(&lsm->lsm_md_oinfo[i].lmo_fid),
3222 i_size_read(inode), inode->i_nlink,
3223 LTIME_S(inode->i_atime), LTIME_S(inode->i_ctime),
3224 LTIME_S(inode->i_mtime));
3226 /* for slave stripe, it needs to subtract nlink for . and .. */
3228 attr->cat_nlink += inode->i_nlink - 2;
3230 attr->cat_nlink = inode->i_nlink;
3232 attr->cat_size += i_size_read(inode);
3234 if (attr->cat_atime < LTIME_S(inode->i_atime))
3235 attr->cat_atime = LTIME_S(inode->i_atime);
3237 if (attr->cat_ctime < LTIME_S(inode->i_ctime))
3238 attr->cat_ctime = LTIME_S(inode->i_ctime);
3240 if (attr->cat_mtime < LTIME_S(inode->i_mtime))
3241 attr->cat_mtime = LTIME_S(inode->i_mtime);
3247 struct obd_ops lmv_obd_ops = {
3248 .o_owner = THIS_MODULE,
3249 .o_setup = lmv_setup,
3250 .o_cleanup = lmv_cleanup,
3251 .o_precleanup = lmv_precleanup,
3252 .o_process_config = lmv_process_config,
3253 .o_connect = lmv_connect,
3254 .o_disconnect = lmv_disconnect,
3255 .o_statfs = lmv_statfs,
3256 .o_get_info = lmv_get_info,
3257 .o_set_info_async = lmv_set_info_async,
3258 .o_packmd = lmv_packmd,
3259 .o_unpackmd = lmv_unpackmd,
3260 .o_notify = lmv_notify,
3261 .o_get_uuid = lmv_get_uuid,
3262 .o_iocontrol = lmv_iocontrol,
3263 .o_quotacheck = lmv_quotacheck,
3264 .o_quotactl = lmv_quotactl
3267 struct md_ops lmv_md_ops = {
3268 .m_getstatus = lmv_getstatus,
3269 .m_null_inode = lmv_null_inode,
3270 .m_find_cbdata = lmv_find_cbdata,
3271 .m_close = lmv_close,
3272 .m_create = lmv_create,
3273 .m_done_writing = lmv_done_writing,
3274 .m_enqueue = lmv_enqueue,
3275 .m_getattr = lmv_getattr,
3276 .m_getxattr = lmv_getxattr,
3277 .m_getattr_name = lmv_getattr_name,
3278 .m_intent_lock = lmv_intent_lock,
3280 .m_rename = lmv_rename,
3281 .m_setattr = lmv_setattr,
3282 .m_setxattr = lmv_setxattr,
3283 .m_fsync = lmv_fsync,
3284 .m_read_entry = lmv_read_entry,
3285 .m_unlink = lmv_unlink,
3286 .m_init_ea_size = lmv_init_ea_size,
3287 .m_cancel_unused = lmv_cancel_unused,
3288 .m_set_lock_data = lmv_set_lock_data,
3289 .m_lock_match = lmv_lock_match,
3290 .m_get_lustre_md = lmv_get_lustre_md,
3291 .m_free_lustre_md = lmv_free_lustre_md,
3292 .m_update_lsm_md = lmv_update_lsm_md,
3293 .m_merge_attr = lmv_merge_attr,
3294 .m_set_open_replay_data = lmv_set_open_replay_data,
3295 .m_clear_open_replay_data = lmv_clear_open_replay_data,
3296 .m_renew_capa = lmv_renew_capa,
3297 .m_unpack_capa = lmv_unpack_capa,
3298 .m_get_remote_perm = lmv_get_remote_perm,
3299 .m_intent_getattr_async = lmv_intent_getattr_async,
3300 .m_revalidate_lock = lmv_revalidate_lock
3303 int __init lmv_init(void)
3305 return class_register_type(&lmv_obd_ops, &lmv_md_ops, NULL,
3306 #ifndef HAVE_ONLY_PROCFS_SEQ
3309 LUSTRE_LMV_NAME, NULL);
3313 static void lmv_exit(void)
3315 class_unregister_type(LUSTRE_LMV_NAME);
3318 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
3319 MODULE_DESCRIPTION("Lustre Logical Metadata Volume OBD driver");
3320 MODULE_LICENSE("GPL");
3322 module_init(lmv_init);
3323 module_exit(lmv_exit);