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 CDEBUG(D_INFO, "name %.*s hash_type %d idx %d\n", namelen, name,
117 LASSERT(idx < max_mdt_index);
121 static void lmv_activate_target(struct lmv_obd *lmv,
122 struct lmv_tgt_desc *tgt,
125 if (tgt->ltd_active == activate)
128 tgt->ltd_active = activate;
129 lmv->desc.ld_active_tgt_count += (activate ? 1 : -1);
135 * -EINVAL : UUID can't be found in the LMV's target list
136 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
137 * -EBADF : The UUID is found, but the OBD of the wrong type (!)
139 static int lmv_set_mdc_active(struct lmv_obd *lmv,
140 const struct obd_uuid *uuid,
143 struct lmv_tgt_desc *tgt = NULL;
144 struct obd_device *obd;
149 CDEBUG(D_INFO, "Searching in lmv %p for uuid %s (activate=%d)\n",
150 lmv, uuid->uuid, activate);
152 spin_lock(&lmv->lmv_lock);
153 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
155 if (tgt == NULL || tgt->ltd_exp == NULL)
158 CDEBUG(D_INFO, "Target idx %d is %s conn "LPX64"\n", i,
159 tgt->ltd_uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
161 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
165 if (i == lmv->desc.ld_tgt_count)
166 GOTO(out_lmv_lock, rc = -EINVAL);
168 obd = class_exp2obd(tgt->ltd_exp);
170 GOTO(out_lmv_lock, rc = -ENOTCONN);
172 CDEBUG(D_INFO, "Found OBD %s=%s device %d (%p) type %s at LMV idx %d\n",
173 obd->obd_name, obd->obd_uuid.uuid, obd->obd_minor, obd,
174 obd->obd_type->typ_name, i);
175 LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0);
177 if (tgt->ltd_active == activate) {
178 CDEBUG(D_INFO, "OBD %p already %sactive!\n", obd,
179 activate ? "" : "in");
180 GOTO(out_lmv_lock, rc);
183 CDEBUG(D_INFO, "Marking OBD %p %sactive\n", obd,
184 activate ? "" : "in");
185 lmv_activate_target(lmv, tgt, activate);
189 spin_unlock(&lmv->lmv_lock);
193 struct obd_uuid *lmv_get_uuid(struct obd_export *exp)
195 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
196 struct lmv_tgt_desc *tgt = lmv->tgts[0];
198 return (tgt == NULL) ? NULL : obd_get_uuid(tgt->ltd_exp);
201 static int lmv_notify(struct obd_device *obd, struct obd_device *watched,
202 enum obd_notify_event ev, void *data)
204 struct obd_connect_data *conn_data;
205 struct lmv_obd *lmv = &obd->u.lmv;
206 struct obd_uuid *uuid;
210 if (strcmp(watched->obd_type->typ_name, LUSTRE_MDC_NAME)) {
211 CERROR("unexpected notification of %s %s!\n",
212 watched->obd_type->typ_name,
217 uuid = &watched->u.cli.cl_target_uuid;
218 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE) {
220 * Set MDC as active before notifying the observer, so the
221 * observer can use the MDC normally.
223 rc = lmv_set_mdc_active(lmv, uuid,
224 ev == OBD_NOTIFY_ACTIVE);
226 CERROR("%sactivation of %s failed: %d\n",
227 ev == OBD_NOTIFY_ACTIVE ? "" : "de",
231 } else if (ev == OBD_NOTIFY_OCD) {
232 conn_data = &watched->u.cli.cl_import->imp_connect_data;
234 * XXX: Make sure that ocd_connect_flags from all targets are
235 * the same. Otherwise one of MDTs runs wrong version or
236 * something like this. --umka
238 obd->obd_self_export->exp_connect_data = *conn_data;
241 else if (ev == OBD_NOTIFY_DISCON) {
243 * For disconnect event, flush fld cache for failout MDS case.
245 fld_client_flush(&lmv->lmv_fld);
249 * Pass the notification up the chain.
251 if (obd->obd_observer)
252 rc = obd_notify(obd->obd_observer, watched, ev, data);
258 * This is fake connect function. Its purpose is to initialize lmv and say
259 * caller that everything is okay. Real connection will be performed later.
261 static int lmv_connect(const struct lu_env *env,
262 struct obd_export **exp, struct obd_device *obd,
263 struct obd_uuid *cluuid, struct obd_connect_data *data,
267 struct proc_dir_entry *lmv_proc_dir;
269 struct lmv_obd *lmv = &obd->u.lmv;
270 struct lustre_handle conn = { 0 };
275 * We don't want to actually do the underlying connections more than
276 * once, so keep track.
279 if (lmv->refcount > 1) {
284 rc = class_connect(&conn, obd, cluuid);
286 CERROR("class_connection() returned %d\n", rc);
290 *exp = class_conn2export(&conn);
291 class_export_get(*exp);
295 lmv->cluuid = *cluuid;
298 lmv->conn_data = *data;
301 if (obd->obd_proc_private != NULL) {
302 lmv_proc_dir = obd->obd_proc_private;
304 lmv_proc_dir = lprocfs_seq_register("target_obds",
307 if (IS_ERR(lmv_proc_dir)) {
308 CERROR("could not register /proc/fs/lustre/%s/%s/target_obds.",
309 obd->obd_type->typ_name, obd->obd_name);
312 obd->obd_proc_private = lmv_proc_dir;
317 * All real clients should perform actual connection right away, because
318 * it is possible, that LMV will not have opportunity to connect targets
319 * and MDC stuff will be called directly, for instance while reading
320 * ../mdc/../kbytesfree procfs file, etc.
322 if (data != NULL && (data->ocd_connect_flags & OBD_CONNECT_REAL))
323 rc = lmv_check_connect(obd);
326 if (rc && lmv_proc_dir) {
327 lprocfs_remove(&lmv_proc_dir);
328 obd->obd_proc_private = NULL;
334 static void lmv_set_timeouts(struct obd_device *obd)
340 if (lmv->server_timeout == 0)
343 if (lmv->connected == 0)
346 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
347 struct lmv_tgt_desc *tgt = lmv->tgts[i];
349 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
352 obd_set_info_async(NULL, tgt->ltd_exp, sizeof(KEY_INTERMDS),
353 KEY_INTERMDS, 0, NULL, NULL);
357 static int lmv_init_ea_size(struct obd_export *exp, int easize,
358 int def_easize, int cookiesize)
360 struct obd_device *obd = exp->exp_obd;
361 struct lmv_obd *lmv = &obd->u.lmv;
367 if (lmv->max_easize < easize) {
368 lmv->max_easize = easize;
371 if (lmv->max_def_easize < def_easize) {
372 lmv->max_def_easize = def_easize;
375 if (lmv->max_cookiesize < cookiesize) {
376 lmv->max_cookiesize = cookiesize;
382 if (lmv->connected == 0)
385 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
386 struct lmv_tgt_desc *tgt = lmv->tgts[i];
388 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active) {
389 CWARN("%s: NULL export for %d\n", obd->obd_name, i);
393 rc = md_init_ea_size(tgt->ltd_exp, easize, def_easize,
396 CERROR("%s: obd_init_ea_size() failed on MDT target %d:"
397 " rc = %d.\n", obd->obd_name, i, rc);
404 #define MAX_STRING_SIZE 128
406 int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
409 struct proc_dir_entry *lmv_proc_dir;
411 struct lmv_obd *lmv = &obd->u.lmv;
412 struct obd_uuid *cluuid = &lmv->cluuid;
413 struct obd_uuid lmv_mdc_uuid = { "LMV_MDC_UUID" };
414 struct obd_device *mdc_obd;
415 struct obd_export *mdc_exp;
416 struct lu_fld_target target;
420 mdc_obd = class_find_client_obd(&tgt->ltd_uuid, LUSTRE_MDC_NAME,
423 CERROR("target %s not attached\n", tgt->ltd_uuid.uuid);
427 CDEBUG(D_CONFIG, "connect to %s(%s) - %s, %s FOR %s\n",
428 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
429 tgt->ltd_uuid.uuid, obd->obd_uuid.uuid,
432 if (!mdc_obd->obd_set_up) {
433 CERROR("target %s is not set up\n", tgt->ltd_uuid.uuid);
437 rc = obd_connect(NULL, &mdc_exp, mdc_obd, &lmv_mdc_uuid,
438 &lmv->conn_data, NULL);
440 CERROR("target %s connect error %d\n", tgt->ltd_uuid.uuid, rc);
445 * Init fid sequence client for this mdc and add new fld target.
447 rc = obd_fid_init(mdc_obd, mdc_exp, LUSTRE_SEQ_METADATA);
451 target.ft_srv = NULL;
452 target.ft_exp = mdc_exp;
453 target.ft_idx = tgt->ltd_idx;
455 fld_client_add_target(&lmv->lmv_fld, &target);
457 rc = obd_register_observer(mdc_obd, obd);
459 obd_disconnect(mdc_exp);
460 CERROR("target %s register_observer error %d\n",
461 tgt->ltd_uuid.uuid, rc);
465 if (obd->obd_observer) {
467 * Tell the observer about the new target.
469 rc = obd_notify(obd->obd_observer, mdc_exp->exp_obd,
471 (void *)(tgt - lmv->tgts[0]));
473 obd_disconnect(mdc_exp);
479 tgt->ltd_exp = mdc_exp;
480 lmv->desc.ld_active_tgt_count++;
482 md_init_ea_size(tgt->ltd_exp, lmv->max_easize,
483 lmv->max_def_easize, lmv->max_cookiesize);
485 CDEBUG(D_CONFIG, "Connected to %s(%s) successfully (%d)\n",
486 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
487 cfs_atomic_read(&obd->obd_refcount));
490 lmv_proc_dir = obd->obd_proc_private;
492 struct proc_dir_entry *mdc_symlink;
494 LASSERT(mdc_obd->obd_type != NULL);
495 LASSERT(mdc_obd->obd_type->typ_name != NULL);
496 mdc_symlink = lprocfs_add_symlink(mdc_obd->obd_name,
499 mdc_obd->obd_type->typ_name,
501 if (mdc_symlink == NULL) {
502 CERROR("Could not register LMV target "
503 "/proc/fs/lustre/%s/%s/target_obds/%s.",
504 obd->obd_type->typ_name, obd->obd_name,
506 lprocfs_remove(&lmv_proc_dir);
507 obd->obd_proc_private = NULL;
514 static void lmv_del_target(struct lmv_obd *lmv, int index)
516 if (lmv->tgts[index] == NULL)
519 OBD_FREE_PTR(lmv->tgts[index]);
520 lmv->tgts[index] = NULL;
524 static int lmv_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
525 __u32 index, int gen)
527 struct lmv_obd *lmv = &obd->u.lmv;
528 struct lmv_tgt_desc *tgt;
532 CDEBUG(D_CONFIG, "Target uuid: %s. index %d\n", uuidp->uuid, index);
536 if (lmv->desc.ld_tgt_count == 0) {
537 struct obd_device *mdc_obd;
539 mdc_obd = class_find_client_obd(uuidp, LUSTRE_MDC_NAME,
542 lmv_init_unlock(lmv);
543 CERROR("%s: Target %s not attached: rc = %d\n",
544 obd->obd_name, uuidp->uuid, -EINVAL);
549 if ((index < lmv->tgts_size) && (lmv->tgts[index] != NULL)) {
550 tgt = lmv->tgts[index];
551 CERROR("%s: UUID %s already assigned at LOV target index %d:"
552 " rc = %d\n", obd->obd_name,
553 obd_uuid2str(&tgt->ltd_uuid), index, -EEXIST);
554 lmv_init_unlock(lmv);
558 if (index >= lmv->tgts_size) {
559 /* We need to reallocate the lmv target array. */
560 struct lmv_tgt_desc **newtgts, **old = NULL;
564 while (newsize < index + 1)
565 newsize = newsize << 1;
566 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
567 if (newtgts == NULL) {
568 lmv_init_unlock(lmv);
572 if (lmv->tgts_size) {
573 memcpy(newtgts, lmv->tgts,
574 sizeof(*newtgts) * lmv->tgts_size);
576 oldsize = lmv->tgts_size;
580 lmv->tgts_size = newsize;
583 OBD_FREE(old, sizeof(*old) * oldsize);
585 CDEBUG(D_CONFIG, "tgts: %p size: %d\n", lmv->tgts,
591 lmv_init_unlock(lmv);
595 mutex_init(&tgt->ltd_fid_mutex);
596 tgt->ltd_idx = index;
597 tgt->ltd_uuid = *uuidp;
599 lmv->tgts[index] = tgt;
600 if (index >= lmv->desc.ld_tgt_count)
601 lmv->desc.ld_tgt_count = index + 1;
603 if (lmv->connected) {
604 rc = lmv_connect_mdc(obd, tgt);
606 spin_lock(&lmv->lmv_lock);
607 lmv->desc.ld_tgt_count--;
608 memset(tgt, 0, sizeof(*tgt));
609 spin_unlock(&lmv->lmv_lock);
611 int easize = sizeof(struct lmv_stripe_md) +
612 lmv->desc.ld_tgt_count *
613 sizeof(struct lu_fid);
614 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0);
618 lmv_init_unlock(lmv);
622 int lmv_check_connect(struct obd_device *obd)
624 struct lmv_obd *lmv = &obd->u.lmv;
625 struct lmv_tgt_desc *tgt;
635 if (lmv->connected) {
636 lmv_init_unlock(lmv);
640 if (lmv->desc.ld_tgt_count == 0) {
641 lmv_init_unlock(lmv);
642 CERROR("%s: no targets configured.\n", obd->obd_name);
646 LASSERT(lmv->tgts != NULL);
648 if (lmv->tgts[0] == NULL) {
649 lmv_init_unlock(lmv);
650 CERROR("%s: no target configured for index 0.\n",
655 CDEBUG(D_CONFIG, "Time to connect %s to %s\n",
656 lmv->cluuid.uuid, obd->obd_name);
658 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
662 rc = lmv_connect_mdc(obd, tgt);
667 lmv_set_timeouts(obd);
668 class_export_put(lmv->exp);
670 easize = lmv_mds_md_size(lmv->desc.ld_tgt_count, LMV_MAGIC);
671 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0);
672 lmv_init_unlock(lmv);
683 --lmv->desc.ld_active_tgt_count;
684 rc2 = obd_disconnect(tgt->ltd_exp);
686 CERROR("LMV target %s disconnect on "
687 "MDC idx %d: error %d\n",
688 tgt->ltd_uuid.uuid, i, rc2);
692 class_disconnect(lmv->exp);
693 lmv_init_unlock(lmv);
697 static int lmv_disconnect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
700 struct proc_dir_entry *lmv_proc_dir;
702 struct lmv_obd *lmv = &obd->u.lmv;
703 struct obd_device *mdc_obd;
707 LASSERT(tgt != NULL);
708 LASSERT(obd != NULL);
710 mdc_obd = class_exp2obd(tgt->ltd_exp);
713 mdc_obd->obd_force = obd->obd_force;
714 mdc_obd->obd_fail = obd->obd_fail;
715 mdc_obd->obd_no_recov = obd->obd_no_recov;
719 lmv_proc_dir = obd->obd_proc_private;
721 lprocfs_remove_proc_entry(mdc_obd->obd_name, lmv_proc_dir);
723 rc = obd_fid_fini(tgt->ltd_exp->exp_obd);
725 CERROR("Can't finanize fids factory\n");
727 CDEBUG(D_INFO, "Disconnected from %s(%s) successfully\n",
728 tgt->ltd_exp->exp_obd->obd_name,
729 tgt->ltd_exp->exp_obd->obd_uuid.uuid);
731 obd_register_observer(tgt->ltd_exp->exp_obd, NULL);
732 rc = obd_disconnect(tgt->ltd_exp);
734 if (tgt->ltd_active) {
735 CERROR("Target %s disconnect error %d\n",
736 tgt->ltd_uuid.uuid, rc);
740 lmv_activate_target(lmv, tgt, 0);
745 static int lmv_disconnect(struct obd_export *exp)
747 struct obd_device *obd = class_exp2obd(exp);
748 struct lmv_obd *lmv = &obd->u.lmv;
757 * Only disconnect the underlying layers on the final disconnect.
760 if (lmv->refcount != 0)
763 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
764 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
767 lmv_disconnect_mdc(obd, lmv->tgts[i]);
771 if (obd->obd_proc_private)
772 lprocfs_remove((struct proc_dir_entry **)&obd->obd_proc_private);
774 CERROR("/proc/fs/lustre/%s/%s/target_obds missing\n",
775 obd->obd_type->typ_name, obd->obd_name);
780 * This is the case when no real connection is established by
781 * lmv_check_connect().
784 class_export_put(exp);
785 rc = class_disconnect(exp);
786 if (lmv->refcount == 0)
791 static int lmv_fid2path(struct obd_export *exp, int len, void *karg, void *uarg)
793 struct obd_device *obddev = class_exp2obd(exp);
794 struct lmv_obd *lmv = &obddev->u.lmv;
795 struct getinfo_fid2path *gf;
796 struct lmv_tgt_desc *tgt;
797 struct getinfo_fid2path *remote_gf = NULL;
798 int remote_gf_size = 0;
801 gf = (struct getinfo_fid2path *)karg;
802 tgt = lmv_find_target(lmv, &gf->gf_fid);
804 RETURN(PTR_ERR(tgt));
807 rc = obd_iocontrol(OBD_IOC_FID2PATH, tgt->ltd_exp, len, gf, uarg);
808 if (rc != 0 && rc != -EREMOTE)
809 GOTO(out_fid2path, rc);
811 /* If remote_gf != NULL, it means just building the
812 * path on the remote MDT, copy this path segement to gf */
813 if (remote_gf != NULL) {
814 struct getinfo_fid2path *ori_gf;
817 ori_gf = (struct getinfo_fid2path *)karg;
818 if (strlen(ori_gf->gf_path) +
819 strlen(gf->gf_path) > ori_gf->gf_pathlen)
820 GOTO(out_fid2path, rc = -EOVERFLOW);
822 ptr = ori_gf->gf_path;
824 memmove(ptr + strlen(gf->gf_path) + 1, ptr,
825 strlen(ori_gf->gf_path));
827 strncpy(ptr, gf->gf_path, strlen(gf->gf_path));
828 ptr += strlen(gf->gf_path);
832 CDEBUG(D_INFO, "%s: get path %s "DFID" rec: "LPU64" ln: %u\n",
833 tgt->ltd_exp->exp_obd->obd_name,
834 gf->gf_path, PFID(&gf->gf_fid), gf->gf_recno,
838 GOTO(out_fid2path, rc);
840 /* sigh, has to go to another MDT to do path building further */
841 if (remote_gf == NULL) {
842 remote_gf_size = sizeof(*remote_gf) + PATH_MAX;
843 OBD_ALLOC(remote_gf, remote_gf_size);
844 if (remote_gf == NULL)
845 GOTO(out_fid2path, rc = -ENOMEM);
846 remote_gf->gf_pathlen = PATH_MAX;
849 if (!fid_is_sane(&gf->gf_fid)) {
850 CERROR("%s: invalid FID "DFID": rc = %d\n",
851 tgt->ltd_exp->exp_obd->obd_name,
852 PFID(&gf->gf_fid), -EINVAL);
853 GOTO(out_fid2path, rc = -EINVAL);
856 tgt = lmv_find_target(lmv, &gf->gf_fid);
858 GOTO(out_fid2path, rc = -EINVAL);
860 remote_gf->gf_fid = gf->gf_fid;
861 remote_gf->gf_recno = -1;
862 remote_gf->gf_linkno = -1;
863 memset(remote_gf->gf_path, 0, remote_gf->gf_pathlen);
865 goto repeat_fid2path;
868 if (remote_gf != NULL)
869 OBD_FREE(remote_gf, remote_gf_size);
873 static int lmv_hsm_req_count(struct lmv_obd *lmv,
874 const struct hsm_user_request *hur,
875 const struct lmv_tgt_desc *tgt_mds)
879 struct lmv_tgt_desc *curr_tgt;
881 /* count how many requests must be sent to the given target */
882 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
883 curr_tgt = lmv_find_target(lmv, &hur->hur_user_item[i].hui_fid);
884 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid))
890 static void lmv_hsm_req_build(struct lmv_obd *lmv,
891 struct hsm_user_request *hur_in,
892 const struct lmv_tgt_desc *tgt_mds,
893 struct hsm_user_request *hur_out)
896 struct lmv_tgt_desc *curr_tgt;
898 /* build the hsm_user_request for the given target */
899 hur_out->hur_request = hur_in->hur_request;
901 for (i = 0; i < hur_in->hur_request.hr_itemcount; i++) {
902 curr_tgt = lmv_find_target(lmv,
903 &hur_in->hur_user_item[i].hui_fid);
904 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid)) {
905 hur_out->hur_user_item[nr_out] =
906 hur_in->hur_user_item[i];
910 hur_out->hur_request.hr_itemcount = nr_out;
911 memcpy(hur_data(hur_out), hur_data(hur_in),
912 hur_in->hur_request.hr_data_len);
915 static int lmv_hsm_ct_unregister(struct lmv_obd *lmv, unsigned int cmd, int len,
916 struct lustre_kernelcomm *lk, void *uarg)
920 struct kkuc_ct_data *kcd = NULL;
923 /* unregister request (call from llapi_hsm_copytool_fini) */
924 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
925 struct lmv_tgt_desc *tgt = lmv->tgts[i];
927 if (tgt == NULL || tgt->ltd_exp == NULL)
929 /* best effort: try to clean as much as possible
930 * (continue on error) */
931 obd_iocontrol(cmd, tgt->ltd_exp, len, lk, uarg);
934 /* Whatever the result, remove copytool from kuc groups.
935 * Unreached coordinators will get EPIPE on next requests
936 * and will unregister automatically.
938 rc = libcfs_kkuc_group_rem(lk->lk_uid, lk->lk_group, (void **)&kcd);
945 static int lmv_hsm_ct_register(struct lmv_obd *lmv, unsigned int cmd, int len,
946 struct lustre_kernelcomm *lk, void *uarg)
951 bool any_set = false;
952 struct kkuc_ct_data *kcd;
955 /* All or nothing: try to register to all MDS.
956 * In case of failure, unregister from previous MDS,
957 * except if it because of inactive target. */
958 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
959 struct lmv_tgt_desc *tgt = lmv->tgts[i];
961 if (tgt == NULL || tgt->ltd_exp == NULL)
963 err = obd_iocontrol(cmd, tgt->ltd_exp, len, lk, uarg);
965 if (tgt->ltd_active) {
966 /* permanent error */
967 CERROR("%s: iocontrol MDC %s on MDT"
968 " idx %d cmd %x: err = %d\n",
969 class_exp2obd(lmv->exp)->obd_name,
970 tgt->ltd_uuid.uuid, i, cmd, err);
972 lk->lk_flags |= LK_FLG_STOP;
973 /* unregister from previous MDS */
974 for (j = 0; j < i; j++) {
976 if (tgt == NULL || tgt->ltd_exp == NULL)
978 obd_iocontrol(cmd, tgt->ltd_exp, len,
983 /* else: transient error.
984 * kuc will register to the missing MDT
992 /* no registration done: return error */
995 /* at least one registration done, with no failure */
996 filp = fget(lk->lk_wfd);
1005 kcd->kcd_magic = KKUC_CT_DATA_MAGIC;
1006 kcd->kcd_uuid = lmv->cluuid;
1007 kcd->kcd_archive = lk->lk_data;
1009 rc = libcfs_kkuc_group_add(filp, lk->lk_uid, lk->lk_group, kcd);
1022 static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
1023 int len, void *karg, void *uarg)
1025 struct obd_device *obddev = class_exp2obd(exp);
1026 struct lmv_obd *lmv = &obddev->u.lmv;
1027 struct lmv_tgt_desc *tgt = NULL;
1031 __u32 count = lmv->desc.ld_tgt_count;
1038 case IOC_OBD_STATFS: {
1039 struct obd_ioctl_data *data = karg;
1040 struct obd_device *mdc_obd;
1041 struct obd_statfs stat_buf = {0};
1044 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
1045 if ((index >= count))
1048 tgt = lmv->tgts[index];
1049 if (tgt == NULL || !tgt->ltd_active)
1052 mdc_obd = class_exp2obd(tgt->ltd_exp);
1057 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(mdc_obd),
1058 min((int) data->ioc_plen2,
1059 (int) sizeof(struct obd_uuid))))
1062 rc = obd_statfs(NULL, tgt->ltd_exp, &stat_buf,
1063 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1067 if (copy_to_user(data->ioc_pbuf1, &stat_buf,
1068 min((int) data->ioc_plen1,
1069 (int) sizeof(stat_buf))))
1073 case OBD_IOC_QUOTACTL: {
1074 struct if_quotactl *qctl = karg;
1075 struct obd_quotactl *oqctl;
1077 if (qctl->qc_valid == QC_MDTIDX) {
1078 if (count <= qctl->qc_idx)
1081 tgt = lmv->tgts[qctl->qc_idx];
1082 if (tgt == NULL || tgt->ltd_exp == NULL)
1084 } else if (qctl->qc_valid == QC_UUID) {
1085 for (i = 0; i < count; i++) {
1089 if (!obd_uuid_equals(&tgt->ltd_uuid,
1093 if (tgt->ltd_exp == NULL)
1105 LASSERT(tgt != NULL && tgt->ltd_exp != NULL);
1106 OBD_ALLOC_PTR(oqctl);
1110 QCTL_COPY(oqctl, qctl);
1111 rc = obd_quotactl(tgt->ltd_exp, oqctl);
1113 QCTL_COPY(qctl, oqctl);
1114 qctl->qc_valid = QC_MDTIDX;
1115 qctl->obd_uuid = tgt->ltd_uuid;
1117 OBD_FREE_PTR(oqctl);
1120 case OBD_IOC_CHANGELOG_SEND:
1121 case OBD_IOC_CHANGELOG_CLEAR: {
1122 struct ioc_changelog *icc = karg;
1124 if (icc->icc_mdtindex >= count)
1127 tgt = lmv->tgts[icc->icc_mdtindex];
1128 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
1130 rc = obd_iocontrol(cmd, tgt->ltd_exp, sizeof(*icc), icc, NULL);
1133 case LL_IOC_GET_CONNECT_FLAGS: {
1135 if (tgt == NULL || tgt->ltd_exp == NULL)
1137 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1140 case OBD_IOC_FID2PATH: {
1141 rc = lmv_fid2path(exp, len, karg, uarg);
1144 case LL_IOC_HSM_STATE_GET:
1145 case LL_IOC_HSM_STATE_SET:
1146 case LL_IOC_HSM_ACTION: {
1147 struct md_op_data *op_data = karg;
1149 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1151 RETURN(PTR_ERR(tgt));
1153 if (tgt->ltd_exp == NULL)
1156 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1159 case LL_IOC_HSM_PROGRESS: {
1160 const struct hsm_progress_kernel *hpk = karg;
1162 tgt = lmv_find_target(lmv, &hpk->hpk_fid);
1164 RETURN(PTR_ERR(tgt));
1165 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1168 case LL_IOC_HSM_REQUEST: {
1169 struct hsm_user_request *hur = karg;
1170 unsigned int reqcount = hur->hur_request.hr_itemcount;
1175 /* if the request is about a single fid
1176 * or if there is a single MDS, no need to split
1178 if (reqcount == 1 || count == 1) {
1179 tgt = lmv_find_target(lmv,
1180 &hur->hur_user_item[0].hui_fid);
1182 RETURN(PTR_ERR(tgt));
1183 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1185 /* split fid list to their respective MDS */
1186 for (i = 0; i < count; i++) {
1187 unsigned int nr, reqlen;
1189 struct hsm_user_request *req;
1192 if (tgt == NULL || tgt->ltd_exp == NULL)
1195 nr = lmv_hsm_req_count(lmv, hur, tgt);
1196 if (nr == 0) /* nothing for this MDS */
1199 /* build a request with fids for this MDS */
1200 reqlen = offsetof(typeof(*hur),
1202 + hur->hur_request.hr_data_len;
1203 OBD_ALLOC_LARGE(req, reqlen);
1207 lmv_hsm_req_build(lmv, hur, tgt, req);
1209 rc1 = obd_iocontrol(cmd, tgt->ltd_exp, reqlen,
1211 if (rc1 != 0 && rc == 0)
1213 OBD_FREE_LARGE(req, reqlen);
1218 case LL_IOC_LOV_SWAP_LAYOUTS: {
1219 struct md_op_data *op_data = karg;
1220 struct lmv_tgt_desc *tgt1, *tgt2;
1222 tgt1 = lmv_find_target(lmv, &op_data->op_fid1);
1224 RETURN(PTR_ERR(tgt1));
1226 tgt2 = lmv_find_target(lmv, &op_data->op_fid2);
1228 RETURN(PTR_ERR(tgt2));
1230 if ((tgt1->ltd_exp == NULL) || (tgt2->ltd_exp == NULL))
1233 /* only files on same MDT can have their layouts swapped */
1234 if (tgt1->ltd_idx != tgt2->ltd_idx)
1237 rc = obd_iocontrol(cmd, tgt1->ltd_exp, len, karg, uarg);
1240 case LL_IOC_HSM_CT_START: {
1241 struct lustre_kernelcomm *lk = karg;
1242 if (lk->lk_flags & LK_FLG_STOP)
1243 rc = lmv_hsm_ct_unregister(lmv, cmd, len, lk, uarg);
1245 rc = lmv_hsm_ct_register(lmv, cmd, len, lk, uarg);
1249 for (i = 0; i < count; i++) {
1250 struct obd_device *mdc_obd;
1254 if (tgt == NULL || tgt->ltd_exp == NULL)
1256 /* ll_umount_begin() sets force flag but for lmv, not
1257 * mdc. Let's pass it through */
1258 mdc_obd = class_exp2obd(tgt->ltd_exp);
1259 mdc_obd->obd_force = obddev->obd_force;
1260 err = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1261 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
1264 if (tgt->ltd_active) {
1265 CERROR("error: iocontrol MDC %s on MDT"
1266 " idx %d cmd %x: err = %d\n",
1267 tgt->ltd_uuid.uuid, i, cmd, err);
1281 static int lmv_all_chars_policy(int count, const char *name,
1292 static int lmv_nid_policy(struct lmv_obd *lmv)
1294 struct obd_import *imp;
1298 * XXX: To get nid we assume that underlying obd device is mdc.
1300 imp = class_exp2cliimp(lmv->tgts[0].ltd_exp);
1301 id = imp->imp_connection->c_self ^ (imp->imp_connection->c_self >> 32);
1302 return id % lmv->desc.ld_tgt_count;
1305 static int lmv_choose_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1306 placement_policy_t placement)
1308 switch (placement) {
1309 case PLACEMENT_CHAR_POLICY:
1310 return lmv_all_chars_policy(lmv->desc.ld_tgt_count,
1312 op_data->op_namelen);
1313 case PLACEMENT_NID_POLICY:
1314 return lmv_nid_policy(lmv);
1320 CERROR("Unsupported placement policy %x\n", placement);
1326 * This is _inode_ placement policy function (not name).
1328 static int lmv_placement_policy(struct obd_device *obd,
1329 struct md_op_data *op_data,
1332 struct lmv_obd *lmv = &obd->u.lmv;
1335 LASSERT(mds != NULL);
1337 if (lmv->desc.ld_tgt_count == 1) {
1343 * If stripe_offset is provided during setdirstripe
1344 * (setdirstripe -i xx), xx MDS will be choosen.
1346 if (op_data->op_cli_flags & CLI_SET_MEA && op_data->op_data != NULL) {
1347 struct lmv_user_md *lum;
1349 lum = op_data->op_data;
1351 if (lum->lum_stripe_offset != (__u32)-1) {
1352 *mds = lum->lum_stripe_offset;
1354 /* -1 means default, which will be in the same MDT with
1356 *mds = op_data->op_mds;
1357 lum->lum_stripe_offset = op_data->op_mds;
1360 /* Allocate new fid on target according to operation type and
1361 * parent home mds. */
1362 *mds = op_data->op_mds;
1368 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid,
1371 struct lmv_tgt_desc *tgt;
1375 tgt = lmv_get_target(lmv, mds);
1377 RETURN(PTR_ERR(tgt));
1380 * New seq alloc and FLD setup should be atomic. Otherwise we may find
1381 * on server that seq in new allocated fid is not yet known.
1383 mutex_lock(&tgt->ltd_fid_mutex);
1385 if (tgt->ltd_active == 0 || tgt->ltd_exp == NULL)
1386 GOTO(out, rc = -ENODEV);
1389 * Asking underlaying tgt layer to allocate new fid.
1391 rc = obd_fid_alloc(tgt->ltd_exp, fid, NULL);
1393 LASSERT(fid_is_sane(fid));
1399 mutex_unlock(&tgt->ltd_fid_mutex);
1403 int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
1404 struct md_op_data *op_data)
1406 struct obd_device *obd = class_exp2obd(exp);
1407 struct lmv_obd *lmv = &obd->u.lmv;
1412 LASSERT(op_data != NULL);
1413 LASSERT(fid != NULL);
1415 rc = lmv_placement_policy(obd, op_data, &mds);
1417 CERROR("Can't get target for allocating fid, "
1422 rc = __lmv_fid_alloc(lmv, fid, mds);
1424 CERROR("Can't alloc new fid, rc %d\n", rc);
1431 static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
1433 struct lmv_obd *lmv = &obd->u.lmv;
1434 struct lmv_desc *desc;
1438 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
1439 CERROR("LMV setup requires a descriptor\n");
1443 desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1);
1444 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
1445 CERROR("Lmv descriptor size wrong: %d > %d\n",
1446 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
1450 OBD_ALLOC(lmv->tgts, sizeof(*lmv->tgts) * 32);
1451 if (lmv->tgts == NULL)
1453 lmv->tgts_size = 32;
1455 obd_str2uuid(&lmv->desc.ld_uuid, desc->ld_uuid.uuid);
1456 lmv->desc.ld_tgt_count = 0;
1457 lmv->desc.ld_active_tgt_count = 0;
1458 lmv->max_cookiesize = 0;
1459 lmv->max_def_easize = 0;
1460 lmv->max_easize = 0;
1461 lmv->lmv_placement = PLACEMENT_CHAR_POLICY;
1463 spin_lock_init(&lmv->lmv_lock);
1464 mutex_init(&lmv->init_mutex);
1467 obd->obd_vars = lprocfs_lmv_obd_vars;
1468 lprocfs_seq_obd_setup(obd);
1469 lprocfs_alloc_md_stats(obd, 0);
1470 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
1471 0444, &lmv_proc_target_fops, obd);
1473 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
1476 rc = fld_client_init(&lmv->lmv_fld, obd->obd_name,
1477 LUSTRE_CLI_FLD_HASH_DHT);
1479 CERROR("Can't init FLD, err %d\n", rc);
1489 static int lmv_cleanup(struct obd_device *obd)
1491 struct lmv_obd *lmv = &obd->u.lmv;
1494 fld_client_fini(&lmv->lmv_fld);
1495 if (lmv->tgts != NULL) {
1497 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1498 if (lmv->tgts[i] == NULL)
1500 lmv_del_target(lmv, i);
1502 OBD_FREE(lmv->tgts, sizeof(*lmv->tgts) * lmv->tgts_size);
1508 static int lmv_process_config(struct obd_device *obd, obd_count len, void *buf)
1510 struct lustre_cfg *lcfg = buf;
1511 struct obd_uuid obd_uuid;
1517 switch (lcfg->lcfg_command) {
1519 /* modify_mdc_tgts add 0:lustre-clilmv 1:lustre-MDT0000_UUID
1520 * 2:0 3:1 4:lustre-MDT0000-mdc_UUID */
1521 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
1522 GOTO(out, rc = -EINVAL);
1524 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
1526 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
1527 GOTO(out, rc = -EINVAL);
1528 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
1529 GOTO(out, rc = -EINVAL);
1530 rc = lmv_add_target(obd, &obd_uuid, index, gen);
1533 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1534 GOTO(out, rc = -EINVAL);
1540 static int lmv_statfs(const struct lu_env *env, struct obd_export *exp,
1541 struct obd_statfs *osfs, __u64 max_age, __u32 flags)
1543 struct obd_device *obd = class_exp2obd(exp);
1544 struct lmv_obd *lmv = &obd->u.lmv;
1545 struct obd_statfs *temp;
1550 rc = lmv_check_connect(obd);
1554 OBD_ALLOC(temp, sizeof(*temp));
1558 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1559 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1562 rc = obd_statfs(env, lmv->tgts[i]->ltd_exp, temp,
1565 CERROR("can't stat MDS #%d (%s), error %d\n", i,
1566 lmv->tgts[i]->ltd_exp->exp_obd->obd_name,
1568 GOTO(out_free_temp, rc);
1573 /* If the statfs is from mount, it will needs
1574 * retrieve necessary information from MDT0.
1575 * i.e. mount does not need the merged osfs
1577 * And also clients can be mounted as long as
1578 * MDT0 is in service*/
1579 if (flags & OBD_STATFS_FOR_MDT0)
1580 GOTO(out_free_temp, rc);
1582 osfs->os_bavail += temp->os_bavail;
1583 osfs->os_blocks += temp->os_blocks;
1584 osfs->os_ffree += temp->os_ffree;
1585 osfs->os_files += temp->os_files;
1591 OBD_FREE(temp, sizeof(*temp));
1595 static int lmv_getstatus(struct obd_export *exp,
1597 struct obd_capa **pc)
1599 struct obd_device *obd = exp->exp_obd;
1600 struct lmv_obd *lmv = &obd->u.lmv;
1604 rc = lmv_check_connect(obd);
1608 rc = md_getstatus(lmv->tgts[0]->ltd_exp, fid, pc);
1612 static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1613 struct obd_capa *oc, obd_valid valid, const char *name,
1614 const char *input, int input_size, int output_size,
1615 int flags, struct ptlrpc_request **request)
1617 struct obd_device *obd = exp->exp_obd;
1618 struct lmv_obd *lmv = &obd->u.lmv;
1619 struct lmv_tgt_desc *tgt;
1623 rc = lmv_check_connect(obd);
1627 tgt = lmv_find_target(lmv, fid);
1629 RETURN(PTR_ERR(tgt));
1631 rc = md_getxattr(tgt->ltd_exp, fid, oc, valid, name, input,
1632 input_size, output_size, flags, request);
1637 static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1638 struct obd_capa *oc, obd_valid valid, const char *name,
1639 const char *input, int input_size, int output_size,
1640 int flags, __u32 suppgid,
1641 struct ptlrpc_request **request)
1643 struct obd_device *obd = exp->exp_obd;
1644 struct lmv_obd *lmv = &obd->u.lmv;
1645 struct lmv_tgt_desc *tgt;
1649 rc = lmv_check_connect(obd);
1653 tgt = lmv_find_target(lmv, fid);
1655 RETURN(PTR_ERR(tgt));
1657 rc = md_setxattr(tgt->ltd_exp, fid, oc, valid, name, input,
1658 input_size, output_size, flags, suppgid,
1664 static int lmv_getattr(struct obd_export *exp, struct md_op_data *op_data,
1665 struct ptlrpc_request **request)
1667 struct obd_device *obd = exp->exp_obd;
1668 struct lmv_obd *lmv = &obd->u.lmv;
1669 struct lmv_tgt_desc *tgt;
1673 rc = lmv_check_connect(obd);
1677 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1679 RETURN(PTR_ERR(tgt));
1681 if (op_data->op_flags & MF_GET_MDT_IDX) {
1682 op_data->op_mds = tgt->ltd_idx;
1686 rc = md_getattr(tgt->ltd_exp, op_data, request);
1691 static int lmv_null_inode(struct obd_export *exp, const struct lu_fid *fid)
1693 struct obd_device *obd = exp->exp_obd;
1694 struct lmv_obd *lmv = &obd->u.lmv;
1699 rc = lmv_check_connect(obd);
1703 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1706 * With DNE every object can have two locks in different namespaces:
1707 * lookup lock in space of MDT storing direntry and update/open lock in
1708 * space of MDT storing inode.
1710 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1711 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1713 md_null_inode(lmv->tgts[i]->ltd_exp, fid);
1719 static int lmv_find_cbdata(struct obd_export *exp, const struct lu_fid *fid,
1720 ldlm_iterator_t it, void *data)
1722 struct obd_device *obd = exp->exp_obd;
1723 struct lmv_obd *lmv = &obd->u.lmv;
1728 rc = lmv_check_connect(obd);
1732 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1735 * With DNE every object can have two locks in different namespaces:
1736 * lookup lock in space of MDT storing direntry and update/open lock in
1737 * space of MDT storing inode.
1739 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1740 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1742 rc = md_find_cbdata(lmv->tgts[i]->ltd_exp, fid, it, data);
1751 static int lmv_close(struct obd_export *exp, struct md_op_data *op_data,
1752 struct md_open_data *mod, struct ptlrpc_request **request)
1754 struct obd_device *obd = exp->exp_obd;
1755 struct lmv_obd *lmv = &obd->u.lmv;
1756 struct lmv_tgt_desc *tgt;
1760 rc = lmv_check_connect(obd);
1764 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1766 RETURN(PTR_ERR(tgt));
1768 CDEBUG(D_INODE, "CLOSE "DFID"\n", PFID(&op_data->op_fid1));
1769 rc = md_close(tgt->ltd_exp, op_data, mod, request);
1774 * Choosing the MDT by name or FID in @op_data.
1775 * For non-striped directory, it will locate MDT by fid.
1776 * For striped-directory, it will locate MDT by name. And also
1777 * it will reset op_fid1 with the FID of the choosen stripe.
1779 struct lmv_tgt_desc *
1780 lmv_locate_target_for_name(struct lmv_obd *lmv, struct lmv_stripe_md *lsm,
1781 const char *name, int namelen, struct lu_fid *fid,
1784 struct lmv_tgt_desc *tgt;
1785 const struct lmv_oinfo *oinfo;
1787 oinfo = lsm_name_to_stripe_info(lsm, name, namelen);
1788 *fid = oinfo->lmo_fid;
1789 *mds = oinfo->lmo_mds;
1790 tgt = lmv_get_target(lmv, *mds);
1792 CDEBUG(D_INFO, "locate on mds %u "DFID"\n", *mds, PFID(fid));
1797 *lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1800 struct lmv_stripe_md *lsm = op_data->op_mea1;
1801 struct lmv_tgt_desc *tgt;
1803 if (lsm == NULL || lsm->lsm_md_stripe_count <= 1 ||
1804 op_data->op_namelen == 0) {
1805 tgt = lmv_find_target(lmv, fid);
1809 op_data->op_mds = tgt->ltd_idx;
1813 return lmv_locate_target_for_name(lmv, lsm, op_data->op_name,
1814 op_data->op_namelen, fid,
1818 int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
1819 const void *data, int datalen, int mode, __u32 uid,
1820 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1821 struct ptlrpc_request **request)
1823 struct obd_device *obd = exp->exp_obd;
1824 struct lmv_obd *lmv = &obd->u.lmv;
1825 struct lmv_tgt_desc *tgt;
1829 rc = lmv_check_connect(obd);
1833 if (!lmv->desc.ld_active_tgt_count)
1836 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1838 RETURN(PTR_ERR(tgt));
1840 CDEBUG(D_INODE, "CREATE name '%.*s' on "DFID" -> mds #%x\n",
1841 op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1),
1844 rc = lmv_fid_alloc(exp, &op_data->op_fid2, op_data);
1848 /* Send the create request to the MDT where the object
1849 * will be located */
1850 tgt = lmv_find_target(lmv, &op_data->op_fid2);
1852 RETURN(PTR_ERR(tgt));
1854 op_data->op_mds = tgt->ltd_idx;
1856 CDEBUG(D_INODE, "CREATE obj "DFID" -> mds #%x\n",
1857 PFID(&op_data->op_fid2), op_data->op_mds);
1859 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1860 rc = md_create(tgt->ltd_exp, op_data, data, datalen, mode, uid, gid,
1861 cap_effective, rdev, request);
1863 if (*request == NULL)
1865 CDEBUG(D_INODE, "Created - "DFID"\n", PFID(&op_data->op_fid2));
1870 static int lmv_done_writing(struct obd_export *exp,
1871 struct md_op_data *op_data,
1872 struct md_open_data *mod)
1874 struct obd_device *obd = exp->exp_obd;
1875 struct lmv_obd *lmv = &obd->u.lmv;
1876 struct lmv_tgt_desc *tgt;
1880 rc = lmv_check_connect(obd);
1884 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1886 RETURN(PTR_ERR(tgt));
1888 rc = md_done_writing(tgt->ltd_exp, op_data, mod);
1893 lmv_enqueue_remote(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1894 struct lookup_intent *it, struct md_op_data *op_data,
1895 struct lustre_handle *lockh, void *lmm, int lmmsize,
1896 __u64 extra_lock_flags)
1898 struct ptlrpc_request *req = it->d.lustre.it_data;
1899 struct obd_device *obd = exp->exp_obd;
1900 struct lmv_obd *lmv = &obd->u.lmv;
1901 struct lustre_handle plock;
1902 struct lmv_tgt_desc *tgt;
1903 struct md_op_data *rdata;
1905 struct mdt_body *body;
1910 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1911 LASSERT(body != NULL);
1913 if (!(body->valid & OBD_MD_MDS))
1916 CDEBUG(D_INODE, "REMOTE_ENQUEUE '%s' on "DFID" -> "DFID"\n",
1917 LL_IT2STR(it), PFID(&op_data->op_fid1), PFID(&body->fid1));
1920 * We got LOOKUP lock, but we really need attrs.
1922 pmode = it->d.lustre.it_lock_mode;
1923 LASSERT(pmode != 0);
1924 memcpy(&plock, lockh, sizeof(plock));
1925 it->d.lustre.it_lock_mode = 0;
1926 it->d.lustre.it_data = NULL;
1929 ptlrpc_req_finished(req);
1931 tgt = lmv_find_target(lmv, &fid1);
1933 GOTO(out, rc = PTR_ERR(tgt));
1935 OBD_ALLOC_PTR(rdata);
1937 GOTO(out, rc = -ENOMEM);
1939 rdata->op_fid1 = fid1;
1940 rdata->op_bias = MDS_CROSS_REF;
1942 rc = md_enqueue(tgt->ltd_exp, einfo, it, rdata, lockh,
1943 lmm, lmmsize, NULL, extra_lock_flags);
1944 OBD_FREE_PTR(rdata);
1947 ldlm_lock_decref(&plock, pmode);
1952 lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1953 struct lookup_intent *it, struct md_op_data *op_data,
1954 struct lustre_handle *lockh, void *lmm, int lmmsize,
1955 struct ptlrpc_request **req, __u64 extra_lock_flags)
1957 struct obd_device *obd = exp->exp_obd;
1958 struct lmv_obd *lmv = &obd->u.lmv;
1959 struct lmv_tgt_desc *tgt;
1963 rc = lmv_check_connect(obd);
1967 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID"\n",
1968 LL_IT2STR(it), PFID(&op_data->op_fid1));
1970 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1972 RETURN(PTR_ERR(tgt));
1974 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID" -> mds #%d\n",
1975 LL_IT2STR(it), PFID(&op_data->op_fid1), tgt->ltd_idx);
1977 rc = md_enqueue(tgt->ltd_exp, einfo, it, op_data, lockh,
1978 lmm, lmmsize, req, extra_lock_flags);
1980 if (rc == 0 && it && it->it_op == IT_OPEN) {
1981 rc = lmv_enqueue_remote(exp, einfo, it, op_data, lockh,
1982 lmm, lmmsize, extra_lock_flags);
1988 lmv_getattr_name(struct obd_export *exp,struct md_op_data *op_data,
1989 struct ptlrpc_request **request)
1991 struct ptlrpc_request *req = NULL;
1992 struct obd_device *obd = exp->exp_obd;
1993 struct lmv_obd *lmv = &obd->u.lmv;
1994 struct lmv_tgt_desc *tgt;
1995 struct mdt_body *body;
1999 rc = lmv_check_connect(obd);
2003 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
2005 RETURN(PTR_ERR(tgt));
2007 CDEBUG(D_INODE, "GETATTR_NAME for %*s on "DFID" -> mds #%d\n",
2008 op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1),
2011 rc = md_getattr_name(tgt->ltd_exp, op_data, request);
2015 body = req_capsule_server_get(&(*request)->rq_pill,
2017 LASSERT(body != NULL);
2019 if (body->valid & OBD_MD_MDS) {
2020 struct lu_fid rid = body->fid1;
2021 CDEBUG(D_INODE, "Request attrs for "DFID"\n",
2024 tgt = lmv_find_target(lmv, &rid);
2026 ptlrpc_req_finished(*request);
2027 RETURN(PTR_ERR(tgt));
2030 op_data->op_fid1 = rid;
2031 op_data->op_valid |= OBD_MD_FLCROSSREF;
2032 op_data->op_namelen = 0;
2033 op_data->op_name = NULL;
2034 rc = md_getattr_name(tgt->ltd_exp, op_data, &req);
2035 ptlrpc_req_finished(*request);
2042 #define md_op_data_fid(op_data, fl) \
2043 (fl == MF_MDC_CANCEL_FID1 ? &op_data->op_fid1 : \
2044 fl == MF_MDC_CANCEL_FID2 ? &op_data->op_fid2 : \
2045 fl == MF_MDC_CANCEL_FID3 ? &op_data->op_fid3 : \
2046 fl == MF_MDC_CANCEL_FID4 ? &op_data->op_fid4 : \
2049 static int lmv_early_cancel(struct obd_export *exp, struct md_op_data *op_data,
2050 int op_tgt, ldlm_mode_t mode, int bits, int flag)
2052 struct lu_fid *fid = md_op_data_fid(op_data, flag);
2053 struct obd_device *obd = exp->exp_obd;
2054 struct lmv_obd *lmv = &obd->u.lmv;
2055 struct lmv_tgt_desc *tgt;
2056 ldlm_policy_data_t policy = {{0}};
2060 if (!fid_is_sane(fid))
2063 tgt = lmv_find_target(lmv, fid);
2065 RETURN(PTR_ERR(tgt));
2067 if (tgt->ltd_idx != op_tgt) {
2068 CDEBUG(D_INODE, "EARLY_CANCEL on "DFID"\n", PFID(fid));
2069 policy.l_inodebits.bits = bits;
2070 rc = md_cancel_unused(tgt->ltd_exp, fid, &policy,
2071 mode, LCF_ASYNC, NULL);
2074 "EARLY_CANCEL skip operation target %d on "DFID"\n",
2076 op_data->op_flags |= flag;
2084 * llite passes fid of an target inode in op_data->op_fid1 and id of directory in
2087 static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
2088 struct ptlrpc_request **request)
2090 struct obd_device *obd = exp->exp_obd;
2091 struct lmv_obd *lmv = &obd->u.lmv;
2092 struct lmv_tgt_desc *tgt;
2096 rc = lmv_check_connect(obd);
2100 LASSERT(op_data->op_namelen != 0);
2102 CDEBUG(D_INODE, "LINK "DFID":%*s to "DFID"\n",
2103 PFID(&op_data->op_fid2), op_data->op_namelen,
2104 op_data->op_name, PFID(&op_data->op_fid1));
2106 op_data->op_fsuid = current_fsuid();
2107 op_data->op_fsgid = current_fsgid();
2108 op_data->op_cap = cfs_curproc_cap_pack();
2109 if (op_data->op_mea2 != NULL) {
2110 struct lmv_stripe_md *lsm = op_data->op_mea2;
2111 const struct lmv_oinfo *oinfo;
2113 oinfo = lsm_name_to_stripe_info(lsm, op_data->op_name,
2114 op_data->op_namelen);
2115 op_data->op_fid2 = oinfo->lmo_fid;
2118 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
2120 RETURN(PTR_ERR(tgt));
2123 * Cancel UPDATE lock on child (fid1).
2125 op_data->op_flags |= MF_MDC_CANCEL_FID2;
2126 rc = lmv_early_cancel(exp, op_data, tgt->ltd_idx, LCK_EX,
2127 MDS_INODELOCK_UPDATE, MF_MDC_CANCEL_FID1);
2131 rc = md_link(tgt->ltd_exp, op_data, request);
2136 static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
2137 const char *old, int oldlen, const char *new, int newlen,
2138 struct ptlrpc_request **request)
2140 struct obd_device *obd = exp->exp_obd;
2141 struct lmv_obd *lmv = &obd->u.lmv;
2142 struct lmv_tgt_desc *src_tgt;
2146 LASSERT(oldlen != 0);
2148 CDEBUG(D_INODE, "RENAME %.*s in "DFID":%d to %.*s in "DFID":%d\n",
2149 oldlen, old, PFID(&op_data->op_fid1),
2150 op_data->op_mea1 ? op_data->op_mea1->lsm_md_stripe_count : 0,
2151 newlen, new, PFID(&op_data->op_fid2),
2152 op_data->op_mea2 ? op_data->op_mea2->lsm_md_stripe_count : 0);
2154 rc = lmv_check_connect(obd);
2158 op_data->op_fsuid = current_fsuid();
2159 op_data->op_fsgid = current_fsgid();
2160 op_data->op_cap = cfs_curproc_cap_pack();
2162 if (op_data->op_mea1 != NULL) {
2163 struct lmv_stripe_md *lsm = op_data->op_mea1;
2164 const struct lmv_oinfo *oinfo;
2166 oinfo = lsm_name_to_stripe_info(lsm, old, oldlen);
2167 op_data->op_fid1 = oinfo->lmo_fid;
2168 op_data->op_mds = oinfo->lmo_mds;
2169 src_tgt = lmv_get_target(lmv, op_data->op_mds);
2170 if (IS_ERR(src_tgt))
2171 RETURN(PTR_ERR(src_tgt));
2173 src_tgt = lmv_find_target(lmv, &op_data->op_fid1);
2174 if (IS_ERR(src_tgt))
2175 RETURN(PTR_ERR(src_tgt));
2177 op_data->op_mds = src_tgt->ltd_idx;
2180 if (op_data->op_mea2) {
2181 struct lmv_stripe_md *lsm = op_data->op_mea2;
2182 const struct lmv_oinfo *oinfo;
2184 oinfo = lsm_name_to_stripe_info(lsm, new, newlen);
2185 op_data->op_fid2 = oinfo->lmo_fid;
2189 * LOOKUP lock on src child (fid3) should also be cancelled for
2190 * src_tgt in mdc_rename.
2192 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2195 * Cancel UPDATE locks on tgt parent (fid2), tgt_tgt is its
2198 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
2199 LCK_EX, MDS_INODELOCK_UPDATE,
2200 MF_MDC_CANCEL_FID2);
2203 * Cancel LOOKUP locks on tgt child (fid4) for parent tgt_tgt.
2206 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
2207 LCK_EX, MDS_INODELOCK_LOOKUP,
2208 MF_MDC_CANCEL_FID4);
2212 * Cancel all the locks on tgt child (fid4).
2215 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
2216 LCK_EX, MDS_INODELOCK_FULL,
2217 MF_MDC_CANCEL_FID4);
2219 CDEBUG(D_INODE, DFID":m%d to "DFID"\n", PFID(&op_data->op_fid1),
2220 op_data->op_mds, PFID(&op_data->op_fid2));
2223 rc = md_rename(src_tgt->ltd_exp, op_data, old, oldlen,
2224 new, newlen, request);
2228 static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
2229 void *ea, int ealen, void *ea2, int ea2len,
2230 struct ptlrpc_request **request,
2231 struct md_open_data **mod)
2233 struct obd_device *obd = exp->exp_obd;
2234 struct lmv_obd *lmv = &obd->u.lmv;
2235 struct lmv_tgt_desc *tgt;
2239 rc = lmv_check_connect(obd);
2243 CDEBUG(D_INODE, "SETATTR for "DFID", valid 0x%x\n",
2244 PFID(&op_data->op_fid1), op_data->op_attr.ia_valid);
2246 op_data->op_flags |= MF_MDC_CANCEL_FID1;
2247 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2249 RETURN(PTR_ERR(tgt));
2251 rc = md_setattr(tgt->ltd_exp, op_data, ea, ealen, ea2,
2252 ea2len, request, mod);
2257 static int lmv_fsync(struct obd_export *exp, const struct lu_fid *fid,
2258 struct obd_capa *oc, struct ptlrpc_request **request)
2260 struct obd_device *obd = exp->exp_obd;
2261 struct lmv_obd *lmv = &obd->u.lmv;
2262 struct lmv_tgt_desc *tgt;
2266 rc = lmv_check_connect(obd);
2270 tgt = lmv_find_target(lmv, fid);
2272 RETURN(PTR_ERR(tgt));
2274 rc = md_fsync(tgt->ltd_exp, fid, oc, request);
2279 * Adjust a set of pages, each page containing an array of lu_dirpages,
2280 * so that each page can be used as a single logical lu_dirpage.
2282 * A lu_dirpage is laid out as follows, where s = ldp_hash_start,
2283 * e = ldp_hash_end, f = ldp_flags, p = padding, and each "ent" is a
2284 * struct lu_dirent. It has size up to LU_PAGE_SIZE. The ldp_hash_end
2285 * value is used as a cookie to request the next lu_dirpage in a
2286 * directory listing that spans multiple pages (two in this example):
2289 * .|--------v------- -----.
2290 * |s|e|f|p|ent|ent| ... |ent|
2291 * '--|-------------- -----' Each CFS_PAGE contains a single
2292 * '------. lu_dirpage.
2293 * .---------v------- -----.
2294 * |s|e|f|p|ent| 0 | ... | 0 |
2295 * '----------------- -----'
2297 * However, on hosts where the native VM page size (PAGE_CACHE_SIZE) is
2298 * larger than LU_PAGE_SIZE, a single host page may contain multiple
2299 * lu_dirpages. After reading the lu_dirpages from the MDS, the
2300 * ldp_hash_end of the first lu_dirpage refers to the one immediately
2301 * after it in the same CFS_PAGE (arrows simplified for brevity, but
2302 * in general e0==s1, e1==s2, etc.):
2304 * .-------------------- -----.
2305 * |s0|e0|f0|p|ent|ent| ... |ent|
2306 * |---v---------------- -----|
2307 * |s1|e1|f1|p|ent|ent| ... |ent|
2308 * |---v---------------- -----| Here, each CFS_PAGE contains
2309 * ... multiple lu_dirpages.
2310 * |---v---------------- -----|
2311 * |s'|e'|f'|p|ent|ent| ... |ent|
2312 * '---|---------------- -----'
2314 * .----------------------------.
2317 * This structure is transformed into a single logical lu_dirpage as follows:
2319 * - Replace e0 with e' so the request for the next lu_dirpage gets the page
2320 * labeled 'next CFS_PAGE'.
2322 * - Copy the LDF_COLLIDE flag from f' to f0 to correctly reflect whether
2323 * a hash collision with the next page exists.
2325 * - Adjust the lde_reclen of the ending entry of each lu_dirpage to span
2326 * to the first entry of the next lu_dirpage.
2328 #if PAGE_CACHE_SIZE > LU_PAGE_SIZE
2329 static void lmv_adjust_dirpages(struct page **pages, int ncfspgs, int nlupgs)
2333 for (i = 0; i < ncfspgs; i++) {
2334 struct lu_dirpage *dp = kmap(pages[i]);
2335 struct lu_dirpage *first = dp;
2336 struct lu_dirent *end_dirent = NULL;
2337 struct lu_dirent *ent;
2338 __u64 hash_end = dp->ldp_hash_end;
2339 __u32 flags = dp->ldp_flags;
2341 while (--nlupgs > 0) {
2342 ent = lu_dirent_start(dp);
2343 for (end_dirent = ent; ent != NULL;
2344 end_dirent = ent, ent = lu_dirent_next(ent));
2346 /* Advance dp to next lu_dirpage. */
2347 dp = (struct lu_dirpage *)((char *)dp + LU_PAGE_SIZE);
2349 /* Check if we've reached the end of the CFS_PAGE. */
2350 if (!((unsigned long)dp & ~CFS_PAGE_MASK))
2353 /* Save the hash and flags of this lu_dirpage. */
2354 hash_end = dp->ldp_hash_end;
2355 flags = dp->ldp_flags;
2357 /* Check if lu_dirpage contains no entries. */
2361 /* Enlarge the end entry lde_reclen from 0 to
2362 * first entry of next lu_dirpage. */
2363 LASSERT(le16_to_cpu(end_dirent->lde_reclen) == 0);
2364 end_dirent->lde_reclen =
2365 cpu_to_le16((char *)(dp->ldp_entries) -
2366 (char *)end_dirent);
2369 first->ldp_hash_end = hash_end;
2370 first->ldp_flags &= ~cpu_to_le32(LDF_COLLIDE);
2371 first->ldp_flags |= flags & cpu_to_le32(LDF_COLLIDE);
2375 LASSERTF(nlupgs == 0, "left = %d", nlupgs);
2378 #define lmv_adjust_dirpages(pages, ncfspgs, nlupgs) do {} while (0)
2379 #endif /* PAGE_CACHE_SIZE > LU_PAGE_SIZE */
2381 #define NORMAL_MAX_STRIPES 4
2382 int lmv_read_entry(struct obd_export *exp, struct md_op_data *op_data,
2383 struct md_callback *cb_op, struct lu_dirent **ldp,
2384 struct page **ppage)
2386 struct obd_device *obd = exp->exp_obd;
2387 struct lmv_obd *lmv = &obd->u.lmv;
2388 struct lmv_stripe_md *lsm = op_data->op_mea1;
2389 struct lu_dirent *tmp_ents[NORMAL_MAX_STRIPES];
2390 struct lu_dirent **ents = NULL;
2394 struct page *min_page = NULL;
2399 rc = lmv_check_connect(obd);
2406 stripe_count = lsm->lsm_md_stripe_count;
2408 if (stripe_count > NORMAL_MAX_STRIPES) {
2409 OBD_ALLOC(ents, sizeof(ents[0]) * stripe_count);
2411 GOTO(out, rc = -ENOMEM);
2414 memset(ents, 0, sizeof(ents[0]) * stripe_count);
2417 min_hash = MDS_DIR_END_OFF;
2418 for (i = 0; i < stripe_count; i++) {
2419 struct lmv_tgt_desc *tgt;
2420 struct page *page = NULL;
2422 if (likely(lsm == NULL)) {
2423 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2425 GOTO(out, rc = PTR_ERR(tgt));
2426 LASSERT(op_data->op_data != NULL);
2428 tgt = lmv_get_target(lmv, lsm->lsm_md_oinfo[i].lmo_mds);
2430 GOTO(out, rc = PTR_ERR(tgt));
2431 op_data->op_fid1 = lsm->lsm_md_oinfo[i].lmo_fid;
2432 op_data->op_fid2 = lsm->lsm_md_oinfo[i].lmo_fid;
2433 op_data->op_stripe_offset = i;
2436 rc = md_read_entry(tgt->ltd_exp, op_data, cb_op, &ents[i],
2441 if (ents[i] != NULL &&
2442 le64_to_cpu(ents[i]->lde_hash) <= min_hash) {
2443 if (min_page != NULL)
2444 page_cache_release(min_page);
2446 min_hash = le64_to_cpu(ents[i]->lde_hash);
2451 if (min_hash != MDS_DIR_END_OFF)
2452 *ldp = ents[min_idx];
2456 if (stripe_count > NORMAL_MAX_STRIPES && ents != NULL)
2457 OBD_FREE(ents, sizeof(ents[0]) * stripe_count);
2459 if (rc != 0 && min_page != NULL) {
2461 page_cache_release(min_page);
2469 static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
2470 struct ptlrpc_request **request)
2472 struct obd_device *obd = exp->exp_obd;
2473 struct lmv_obd *lmv = &obd->u.lmv;
2474 struct lmv_tgt_desc *tgt = NULL;
2475 struct mdt_body *body;
2479 rc = lmv_check_connect(obd);
2483 /* Send unlink requests to the MDT where the child is located */
2484 if (likely(!fid_is_zero(&op_data->op_fid2))) {
2485 tgt = lmv_find_target(lmv, &op_data->op_fid2);
2487 RETURN(PTR_ERR(tgt));
2489 /* For striped dir, we need to locate the parent as well */
2490 if (op_data->op_mea1 != NULL &&
2491 op_data->op_mea1->lsm_md_stripe_count > 1) {
2492 LASSERT(op_data->op_name != NULL &&
2493 op_data->op_namelen != 0);
2494 lmv_locate_target_for_name(lmv, op_data->op_mea1,
2496 op_data->op_namelen,
2501 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
2503 RETURN(PTR_ERR(tgt));
2506 op_data->op_fsuid = current_fsuid();
2507 op_data->op_fsgid = current_fsgid();
2508 op_data->op_cap = cfs_curproc_cap_pack();
2511 * If child's fid is given, cancel unused locks for it if it is from
2512 * another export than parent.
2514 * LOOKUP lock for child (fid3) should also be cancelled on parent
2515 * tgt_tgt in mdc_unlink().
2517 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2520 * Cancel FULL locks on child (fid3).
2522 rc = lmv_early_cancel(exp, op_data, tgt->ltd_idx, LCK_EX,
2523 MDS_INODELOCK_FULL, MF_MDC_CANCEL_FID3);
2528 CDEBUG(D_INODE, "unlink with fid="DFID"/"DFID" -> mds #%d\n",
2529 PFID(&op_data->op_fid1), PFID(&op_data->op_fid2), tgt->ltd_idx);
2531 rc = md_unlink(tgt->ltd_exp, op_data, request);
2532 if (rc != 0 && rc != -EREMOTE)
2535 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
2539 /* Not cross-ref case, just get out of here. */
2540 if (likely(!(body->valid & OBD_MD_MDS)))
2543 CDEBUG(D_INODE, "%s: try unlink to another MDT for "DFID"\n",
2544 exp->exp_obd->obd_name, PFID(&body->fid1));
2546 /* This is a remote object, try remote MDT, Note: it may
2547 * try more than 1 time here, Considering following case
2548 * /mnt/lustre is root on MDT0, remote1 is on MDT1
2549 * 1. Initially A does not know where remote1 is, it send
2550 * unlink RPC to MDT0, MDT0 return -EREMOTE, it will
2551 * resend unlink RPC to MDT1 (retry 1st time).
2553 * 2. During the unlink RPC in flight,
2554 * client B mv /mnt/lustre/remote1 /mnt/lustre/remote2
2555 * and create new remote1, but on MDT0
2557 * 3. MDT1 get unlink RPC(from A), then do remote lock on
2558 * /mnt/lustre, then lookup get fid of remote1, and find
2559 * it is remote dir again, and replay -EREMOTE again.
2561 * 4. Then A will resend unlink RPC to MDT0. (retry 2nd times).
2563 * In theory, it might try unlimited time here, but it should
2564 * be very rare case. */
2565 op_data->op_fid2 = body->fid1;
2566 ptlrpc_req_finished(*request);
2572 static int lmv_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2574 struct lmv_obd *lmv = &obd->u.lmv;
2578 case OBD_CLEANUP_EARLY:
2579 /* XXX: here should be calling obd_precleanup() down to
2582 case OBD_CLEANUP_EXPORTS:
2583 fld_client_proc_fini(&lmv->lmv_fld);
2584 lprocfs_obd_cleanup(obd);
2585 lprocfs_free_md_stats(obd);
2593 static int lmv_get_info(const struct lu_env *env, struct obd_export *exp,
2594 __u32 keylen, void *key, __u32 *vallen, void *val,
2595 struct lov_stripe_md *lsm)
2597 struct obd_device *obd;
2598 struct lmv_obd *lmv;
2602 obd = class_exp2obd(exp);
2604 CDEBUG(D_IOCTL, "Invalid client cookie "LPX64"\n",
2605 exp->exp_handle.h_cookie);
2610 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
2613 rc = lmv_check_connect(obd);
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) || KEY_IS(KEY_CONN_DATA)) {
2632 rc = lmv_check_connect(obd);
2637 * Forwarding this request to first MDS, it should know LOV
2640 rc = obd_get_info(env, lmv->tgts[0]->ltd_exp, keylen, key,
2642 if (!rc && KEY_IS(KEY_CONN_DATA))
2643 exp->exp_connect_data = *(struct obd_connect_data *)val;
2645 } else if (KEY_IS(KEY_TGT_COUNT)) {
2646 *((int *)val) = lmv->desc.ld_tgt_count;
2650 CDEBUG(D_IOCTL, "Invalid key\n");
2654 int lmv_set_info_async(const struct lu_env *env, struct obd_export *exp,
2655 obd_count keylen, void *key, obd_count vallen,
2656 void *val, struct ptlrpc_request_set *set)
2658 struct lmv_tgt_desc *tgt = NULL;
2659 struct obd_device *obd;
2660 struct lmv_obd *lmv;
2664 obd = class_exp2obd(exp);
2666 CDEBUG(D_IOCTL, "Invalid client cookie "LPX64"\n",
2667 exp->exp_handle.h_cookie);
2672 if (KEY_IS(KEY_READ_ONLY) || KEY_IS(KEY_FLUSH_CTX)) {
2675 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2678 if (tgt == NULL || tgt->ltd_exp == NULL)
2681 err = obd_set_info_async(env, tgt->ltd_exp,
2682 keylen, key, vallen, val, set);
2693 static int lmv_pack_md_v1(const struct lmv_stripe_md *lsm,
2694 struct lmv_mds_md_v1 *lmm1)
2699 lmm1->lmv_magic = cpu_to_le32(lsm->lsm_md_magic);
2700 lmm1->lmv_stripe_count = cpu_to_le32(lsm->lsm_md_stripe_count);
2701 lmm1->lmv_master_mdt_index = cpu_to_le32(lsm->lsm_md_master_mdt_index);
2702 lmm1->lmv_hash_type = cpu_to_le32(lsm->lsm_md_hash_type);
2703 cplen = strlcpy(lmm1->lmv_pool_name, lsm->lsm_md_pool_name,
2704 sizeof(lmm1->lmv_pool_name));
2705 if (cplen >= sizeof(lmm1->lmv_pool_name))
2708 for (i = 0; i < lsm->lsm_md_stripe_count; i++)
2709 fid_cpu_to_le(&lmm1->lmv_stripe_fids[i],
2710 &lsm->lsm_md_oinfo[i].lmo_fid);
2714 int lmv_pack_md(union lmv_mds_md **lmmp, const struct lmv_stripe_md *lsm,
2718 bool allocated = false;
2722 LASSERT(lmmp != NULL);
2724 if (*lmmp != NULL && lsm == NULL) {
2727 stripe_count = lmv_mds_md_stripe_count_get(*lmmp);
2728 lmm_size = lmv_mds_md_size(stripe_count,
2729 le32_to_cpu((*lmmp)->lmv_magic));
2732 OBD_FREE(*lmmp, lmm_size);
2738 if (*lmmp == NULL && lsm == NULL) {
2739 lmm_size = lmv_mds_md_size(stripe_count, LMV_MAGIC);
2740 LASSERT(lmm_size > 0);
2741 OBD_ALLOC(*lmmp, lmm_size);
2744 lmv_mds_md_stripe_count_set(*lmmp, stripe_count);
2745 (*lmmp)->lmv_magic = cpu_to_le32(LMV_MAGIC);
2750 LASSERT(lsm != NULL);
2751 lmm_size = lmv_mds_md_size(lsm->lsm_md_stripe_count, lsm->lsm_md_magic);
2752 if (*lmmp == NULL) {
2753 OBD_ALLOC(*lmmp, lmm_size);
2759 switch (lsm->lsm_md_magic) {
2761 rc = lmv_pack_md_v1(lsm, &(*lmmp)->lmv_md_v1);
2768 if (rc != 0 && allocated) {
2769 OBD_FREE(*lmmp, lmm_size);
2775 EXPORT_SYMBOL(lmv_pack_md);
2777 static int lmv_unpack_md_v1(struct obd_export *exp, struct lmv_stripe_md *lsm,
2778 const struct lmv_mds_md_v1 *lmm1)
2780 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2787 lsm->lsm_md_magic = le32_to_cpu(lmm1->lmv_magic);
2788 lsm->lsm_md_stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
2789 lsm->lsm_md_master_mdt_index = le32_to_cpu(lmm1->lmv_master_mdt_index);
2790 lsm->lsm_md_hash_type = le32_to_cpu(lmm1->lmv_hash_type);
2791 lsm->lsm_md_layout_version = le32_to_cpu(lmm1->lmv_layout_version);
2792 cplen = strlcpy(lsm->lsm_md_pool_name, lmm1->lmv_pool_name,
2793 sizeof(lsm->lsm_md_pool_name));
2795 if (cplen >= sizeof(lsm->lsm_md_pool_name))
2798 CDEBUG(D_INFO, "unpack lsm count %d, master %d hash_type %d"
2799 "layout_version %d\n", lsm->lsm_md_stripe_count,
2800 lsm->lsm_md_master_mdt_index, lsm->lsm_md_hash_type,
2801 lsm->lsm_md_layout_version);
2803 stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
2804 for (i = 0; i < le32_to_cpu(stripe_count); i++) {
2805 fid_le_to_cpu(&lsm->lsm_md_oinfo[i].lmo_fid,
2806 &lmm1->lmv_stripe_fids[i]);
2807 rc = lmv_fld_lookup(lmv, &lsm->lsm_md_oinfo[i].lmo_fid,
2808 &lsm->lsm_md_oinfo[i].lmo_mds);
2811 CDEBUG(D_INFO, "unpack fid #%d "DFID"\n", i,
2812 PFID(&lsm->lsm_md_oinfo[i].lmo_fid));
2818 int lmv_unpack_md(struct obd_export *exp, struct lmv_stripe_md **lsmp,
2819 const union lmv_mds_md *lmm, int stripe_count)
2821 struct lmv_stripe_md *lsm;
2824 bool allocated = false;
2827 LASSERT(lsmp != NULL);
2831 if (lsm != NULL && lmm == NULL) {
2834 for (i = 1; i < lsm->lsm_md_stripe_count; i++) {
2835 if (lsm->lsm_md_oinfo[i].lmo_root != NULL)
2836 iput(lsm->lsm_md_oinfo[i].lmo_root);
2839 lsm_size = lmv_stripe_md_size(lsm->lsm_md_stripe_count);
2840 OBD_FREE(lsm, lsm_size);
2846 if (lsm == NULL && lmm == NULL) {
2847 lsm_size = lmv_stripe_md_size(stripe_count);
2848 OBD_ALLOC(lsm, lsm_size);
2851 lsm->lsm_md_stripe_count = stripe_count;
2857 if (le32_to_cpu(lmm->lmv_magic) != LMV_MAGIC_V1) {
2858 CERROR("%s: invalid magic %x.\n", exp->exp_obd->obd_name,
2859 le32_to_cpu(lmm->lmv_magic));
2863 lsm_size = lmv_stripe_md_size(lmv_mds_md_stripe_count_get(lmm));
2865 OBD_ALLOC(lsm, lsm_size);
2872 switch (le32_to_cpu(lmm->lmv_magic)) {
2874 rc = lmv_unpack_md_v1(exp, lsm, &lmm->lmv_md_v1);
2877 CERROR("%s: unrecognized magic %x\n", exp->exp_obd->obd_name,
2878 le32_to_cpu(lmm->lmv_magic));
2883 if (rc != 0 && allocated) {
2884 OBD_FREE(lsm, lsm_size);
2891 int lmv_alloc_memmd(struct lmv_stripe_md **lsmp, int stripes)
2893 return lmv_unpack_md(NULL, lsmp, NULL, stripes);
2895 EXPORT_SYMBOL(lmv_alloc_memmd);
2897 void lmv_free_memmd(struct lmv_stripe_md *lsm)
2899 lmv_unpack_md(NULL, &lsm, NULL, 0);
2901 EXPORT_SYMBOL(lmv_free_memmd);
2903 int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
2904 struct lov_mds_md *lmm, int disk_len)
2906 return lmv_unpack_md(exp, (struct lmv_stripe_md **)lsmp,
2907 (union lmv_mds_md *)lmm, disk_len);
2910 int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
2911 struct lov_stripe_md *lsm)
2913 struct obd_device *obd = exp->exp_obd;
2914 struct lmv_obd *lmv_obd = &obd->u.lmv;
2915 const struct lmv_stripe_md *lmv = (struct lmv_stripe_md *)lsm;
2920 stripe_count = lmv->lsm_md_stripe_count;
2922 stripe_count = lmv_obd->desc.ld_tgt_count;
2924 return lmv_mds_md_size(stripe_count, LMV_MAGIC_V1);
2927 return lmv_pack_md((union lmv_mds_md **)lmmp, lmv, 0);
2930 static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
2931 ldlm_policy_data_t *policy, ldlm_mode_t mode,
2932 ldlm_cancel_flags_t flags, void *opaque)
2934 struct obd_device *obd = exp->exp_obd;
2935 struct lmv_obd *lmv = &obd->u.lmv;
2941 LASSERT(fid != NULL);
2943 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2944 struct lmv_tgt_desc *tgt = lmv->tgts[i];
2946 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
2949 err = md_cancel_unused(tgt->ltd_exp, fid, policy, mode, flags,
2957 int lmv_set_lock_data(struct obd_export *exp, __u64 *lockh, void *data,
2960 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2961 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2965 if (tgt == NULL || tgt->ltd_exp == NULL)
2967 rc = md_set_lock_data(tgt->ltd_exp, lockh, data, bits);
2971 ldlm_mode_t lmv_lock_match(struct obd_export *exp, __u64 flags,
2972 const struct lu_fid *fid, ldlm_type_t type,
2973 ldlm_policy_data_t *policy, ldlm_mode_t mode,
2974 struct lustre_handle *lockh)
2976 struct obd_device *obd = exp->exp_obd;
2977 struct lmv_obd *lmv = &obd->u.lmv;
2982 CDEBUG(D_INODE, "Lock match for "DFID"\n", PFID(fid));
2985 * With CMD every object can have two locks in different namespaces:
2986 * lookup lock in space of mds storing direntry and update/open lock in
2987 * space of mds storing inode. Thus we check all targets, not only that
2988 * one fid was created in.
2990 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2991 struct lmv_tgt_desc *tgt = lmv->tgts[i];
2993 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
2996 rc = md_lock_match(tgt->ltd_exp, flags, fid, type, policy, mode,
3005 int lmv_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
3006 struct obd_export *dt_exp, struct obd_export *md_exp,
3007 struct lustre_md *md)
3009 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
3010 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3012 if (tgt == NULL || tgt->ltd_exp == NULL)
3015 return md_get_lustre_md(lmv->tgts[0]->ltd_exp, req, dt_exp, md_exp, md);
3018 int lmv_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
3020 struct obd_device *obd = exp->exp_obd;
3021 struct lmv_obd *lmv = &obd->u.lmv;
3022 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3025 if (md->lmv != NULL) {
3026 lmv_free_memmd(md->lmv);
3029 if (tgt == NULL || tgt->ltd_exp == NULL)
3031 RETURN(md_free_lustre_md(lmv->tgts[0]->ltd_exp, md));
3034 int lmv_set_open_replay_data(struct obd_export *exp,
3035 struct obd_client_handle *och,
3036 struct lookup_intent *it)
3038 struct obd_device *obd = exp->exp_obd;
3039 struct lmv_obd *lmv = &obd->u.lmv;
3040 struct lmv_tgt_desc *tgt;
3043 tgt = lmv_find_target(lmv, &och->och_fid);
3045 RETURN(PTR_ERR(tgt));
3047 RETURN(md_set_open_replay_data(tgt->ltd_exp, och, it));
3050 int lmv_clear_open_replay_data(struct obd_export *exp,
3051 struct obd_client_handle *och)
3053 struct obd_device *obd = exp->exp_obd;
3054 struct lmv_obd *lmv = &obd->u.lmv;
3055 struct lmv_tgt_desc *tgt;
3058 tgt = lmv_find_target(lmv, &och->och_fid);
3060 RETURN(PTR_ERR(tgt));
3062 RETURN(md_clear_open_replay_data(tgt->ltd_exp, och));
3065 static int lmv_get_remote_perm(struct obd_export *exp,
3066 const struct lu_fid *fid,
3067 struct obd_capa *oc, __u32 suppgid,
3068 struct ptlrpc_request **request)
3070 struct obd_device *obd = exp->exp_obd;
3071 struct lmv_obd *lmv = &obd->u.lmv;
3072 struct lmv_tgt_desc *tgt;
3076 rc = lmv_check_connect(obd);
3080 tgt = lmv_find_target(lmv, fid);
3082 RETURN(PTR_ERR(tgt));
3084 rc = md_get_remote_perm(tgt->ltd_exp, fid, oc, suppgid, request);
3088 static int lmv_renew_capa(struct obd_export *exp, struct obd_capa *oc,
3091 struct obd_device *obd = exp->exp_obd;
3092 struct lmv_obd *lmv = &obd->u.lmv;
3093 struct lmv_tgt_desc *tgt;
3097 rc = lmv_check_connect(obd);
3101 tgt = lmv_find_target(lmv, &oc->c_capa.lc_fid);
3103 RETURN(PTR_ERR(tgt));
3105 rc = md_renew_capa(tgt->ltd_exp, oc, cb);
3109 int lmv_unpack_capa(struct obd_export *exp, struct ptlrpc_request *req,
3110 const struct req_msg_field *field, struct obd_capa **oc)
3112 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
3113 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3115 if (tgt == NULL || tgt->ltd_exp == NULL)
3117 return md_unpack_capa(tgt->ltd_exp, req, field, oc);
3120 int lmv_intent_getattr_async(struct obd_export *exp,
3121 struct md_enqueue_info *minfo,
3122 struct ldlm_enqueue_info *einfo)
3124 struct md_op_data *op_data = &minfo->mi_data;
3125 struct obd_device *obd = exp->exp_obd;
3126 struct lmv_obd *lmv = &obd->u.lmv;
3127 struct lmv_tgt_desc *tgt = NULL;
3131 rc = lmv_check_connect(obd);
3135 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
3137 RETURN(PTR_ERR(tgt));
3139 rc = md_intent_getattr_async(tgt->ltd_exp, minfo, einfo);
3143 int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
3144 struct lu_fid *fid, __u64 *bits)
3146 struct obd_device *obd = exp->exp_obd;
3147 struct lmv_obd *lmv = &obd->u.lmv;
3148 struct lmv_tgt_desc *tgt;
3152 rc = lmv_check_connect(obd);
3156 tgt = lmv_find_target(lmv, fid);
3158 RETURN(PTR_ERR(tgt));
3160 rc = md_revalidate_lock(tgt->ltd_exp, it, fid, bits);
3165 * For lmv, only need to send request to master MDT, and the master MDT will
3166 * process with other slave MDTs. The only exception is Q_GETOQUOTA for which
3167 * we directly fetch data from the slave MDTs.
3169 int lmv_quotactl(struct obd_device *unused, struct obd_export *exp,
3170 struct obd_quotactl *oqctl)
3172 struct obd_device *obd = class_exp2obd(exp);
3173 struct lmv_obd *lmv = &obd->u.lmv;
3174 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3177 __u64 curspace, curinodes;
3181 tgt->ltd_exp == NULL ||
3183 lmv->desc.ld_tgt_count == 0) {
3184 CERROR("master lmv inactive\n");
3188 if (oqctl->qc_cmd != Q_GETOQUOTA) {
3189 rc = obd_quotactl(tgt->ltd_exp, oqctl);
3193 curspace = curinodes = 0;
3194 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
3198 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
3201 err = obd_quotactl(tgt->ltd_exp, oqctl);
3203 CERROR("getquota on mdt %d failed. %d\n", i, err);
3207 curspace += oqctl->qc_dqblk.dqb_curspace;
3208 curinodes += oqctl->qc_dqblk.dqb_curinodes;
3211 oqctl->qc_dqblk.dqb_curspace = curspace;
3212 oqctl->qc_dqblk.dqb_curinodes = curinodes;
3217 int lmv_quotacheck(struct obd_device *unused, struct obd_export *exp,
3218 struct obd_quotactl *oqctl)
3220 struct obd_device *obd = class_exp2obd(exp);
3221 struct lmv_obd *lmv = &obd->u.lmv;
3222 struct lmv_tgt_desc *tgt;
3227 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
3230 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active) {
3231 CERROR("lmv idx %d inactive\n", i);
3235 err = obd_quotacheck(tgt->ltd_exp, oqctl);
3243 int lmv_update_lsm_md(struct obd_export *exp, struct lmv_stripe_md *lsm,
3244 struct mdt_body *body, ldlm_blocking_callback cb_blocking)
3246 if (lsm->lsm_md_stripe_count <= 1)
3249 return lmv_revalidate_slaves(exp, body, lsm, cb_blocking, 0);
3252 int lmv_merge_attr(struct obd_export *exp, const struct lmv_stripe_md *lsm,
3253 struct cl_attr *attr)
3258 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
3259 struct inode *inode = lsm->lsm_md_oinfo[i].lmo_root;
3261 CDEBUG(D_INFO, ""DFID" size %llu, nlink %u, atime %lu ctime"
3262 "%lu, mtime %lu.\n", PFID(&lsm->lsm_md_oinfo[i].lmo_fid),
3263 i_size_read(inode), inode->i_nlink,
3264 LTIME_S(inode->i_atime), LTIME_S(inode->i_ctime),
3265 LTIME_S(inode->i_mtime));
3267 /* for slave stripe, it needs to subtract nlink for . and .. */
3269 attr->cat_nlink += inode->i_nlink - 2;
3271 attr->cat_nlink = inode->i_nlink;
3273 attr->cat_size += i_size_read(inode);
3275 if (attr->cat_atime < LTIME_S(inode->i_atime))
3276 attr->cat_atime = LTIME_S(inode->i_atime);
3278 if (attr->cat_ctime < LTIME_S(inode->i_ctime))
3279 attr->cat_ctime = LTIME_S(inode->i_ctime);
3281 if (attr->cat_mtime < LTIME_S(inode->i_mtime))
3282 attr->cat_mtime = LTIME_S(inode->i_mtime);
3288 struct obd_ops lmv_obd_ops = {
3289 .o_owner = THIS_MODULE,
3290 .o_setup = lmv_setup,
3291 .o_cleanup = lmv_cleanup,
3292 .o_precleanup = lmv_precleanup,
3293 .o_process_config = lmv_process_config,
3294 .o_connect = lmv_connect,
3295 .o_disconnect = lmv_disconnect,
3296 .o_statfs = lmv_statfs,
3297 .o_get_info = lmv_get_info,
3298 .o_set_info_async = lmv_set_info_async,
3299 .o_packmd = lmv_packmd,
3300 .o_unpackmd = lmv_unpackmd,
3301 .o_notify = lmv_notify,
3302 .o_get_uuid = lmv_get_uuid,
3303 .o_iocontrol = lmv_iocontrol,
3304 .o_quotacheck = lmv_quotacheck,
3305 .o_quotactl = lmv_quotactl
3308 struct md_ops lmv_md_ops = {
3309 .m_getstatus = lmv_getstatus,
3310 .m_null_inode = lmv_null_inode,
3311 .m_find_cbdata = lmv_find_cbdata,
3312 .m_close = lmv_close,
3313 .m_create = lmv_create,
3314 .m_done_writing = lmv_done_writing,
3315 .m_enqueue = lmv_enqueue,
3316 .m_getattr = lmv_getattr,
3317 .m_getxattr = lmv_getxattr,
3318 .m_getattr_name = lmv_getattr_name,
3319 .m_intent_lock = lmv_intent_lock,
3321 .m_rename = lmv_rename,
3322 .m_setattr = lmv_setattr,
3323 .m_setxattr = lmv_setxattr,
3324 .m_fsync = lmv_fsync,
3325 .m_read_entry = lmv_read_entry,
3326 .m_unlink = lmv_unlink,
3327 .m_init_ea_size = lmv_init_ea_size,
3328 .m_cancel_unused = lmv_cancel_unused,
3329 .m_set_lock_data = lmv_set_lock_data,
3330 .m_lock_match = lmv_lock_match,
3331 .m_get_lustre_md = lmv_get_lustre_md,
3332 .m_free_lustre_md = lmv_free_lustre_md,
3333 .m_update_lsm_md = lmv_update_lsm_md,
3334 .m_merge_attr = lmv_merge_attr,
3335 .m_set_open_replay_data = lmv_set_open_replay_data,
3336 .m_clear_open_replay_data = lmv_clear_open_replay_data,
3337 .m_renew_capa = lmv_renew_capa,
3338 .m_unpack_capa = lmv_unpack_capa,
3339 .m_get_remote_perm = lmv_get_remote_perm,
3340 .m_intent_getattr_async = lmv_intent_getattr_async,
3341 .m_revalidate_lock = lmv_revalidate_lock
3344 int __init lmv_init(void)
3346 return class_register_type(&lmv_obd_ops, &lmv_md_ops, NULL,
3347 #ifndef HAVE_ONLY_PROCFS_SEQ
3350 LUSTRE_LMV_NAME, NULL);
3354 static void lmv_exit(void)
3356 class_unregister_type(LUSTRE_LMV_NAME);
3359 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
3360 MODULE_DESCRIPTION("Lustre Logical Metadata Volume OBD driver");
3361 MODULE_LICENSE("GPL");
3363 module_init(lmv_init);
3364 module_exit(lmv_exit);