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 <lprocfs_status.h>
58 #include <lustre_lite.h>
59 #include <lustre_fid.h>
60 #include "lmv_internal.h"
62 static void lmv_activate_target(struct lmv_obd *lmv,
63 struct lmv_tgt_desc *tgt,
66 if (tgt->ltd_active == activate)
69 tgt->ltd_active = activate;
70 lmv->desc.ld_active_tgt_count += (activate ? 1 : -1);
76 * -EINVAL : UUID can't be found in the LMV's target list
77 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
78 * -EBADF : The UUID is found, but the OBD of the wrong type (!)
80 static int lmv_set_mdc_active(struct lmv_obd *lmv, struct obd_uuid *uuid,
83 struct lmv_tgt_desc *tgt;
84 struct obd_device *obd;
89 CDEBUG(D_INFO, "Searching in lmv %p for uuid %s (activate=%d)\n",
90 lmv, uuid->uuid, activate);
92 spin_lock(&lmv->lmv_lock);
93 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
95 if (tgt == NULL || tgt->ltd_exp == NULL)
98 CDEBUG(D_INFO, "Target idx %d is %s conn "LPX64"\n", i,
99 tgt->ltd_uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
101 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
105 if (i == lmv->desc.ld_tgt_count)
106 GOTO(out_lmv_lock, rc = -EINVAL);
108 obd = class_exp2obd(tgt->ltd_exp);
110 GOTO(out_lmv_lock, rc = -ENOTCONN);
112 CDEBUG(D_INFO, "Found OBD %s=%s device %d (%p) type %s at LMV idx %d\n",
113 obd->obd_name, obd->obd_uuid.uuid, obd->obd_minor, obd,
114 obd->obd_type->typ_name, i);
115 LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0);
117 if (tgt->ltd_active == activate) {
118 CDEBUG(D_INFO, "OBD %p already %sactive!\n", obd,
119 activate ? "" : "in");
120 GOTO(out_lmv_lock, rc);
123 CDEBUG(D_INFO, "Marking OBD %p %sactive\n", obd,
124 activate ? "" : "in");
125 lmv_activate_target(lmv, tgt, activate);
129 spin_unlock(&lmv->lmv_lock);
133 struct obd_uuid *lmv_get_uuid(struct obd_export *exp)
135 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
137 return obd_get_uuid(lmv->tgts[0]->ltd_exp);
140 static int lmv_notify(struct obd_device *obd, struct obd_device *watched,
141 enum obd_notify_event ev, void *data)
143 struct obd_connect_data *conn_data;
144 struct lmv_obd *lmv = &obd->u.lmv;
145 struct obd_uuid *uuid;
149 if (strcmp(watched->obd_type->typ_name, LUSTRE_MDC_NAME)) {
150 CERROR("unexpected notification of %s %s!\n",
151 watched->obd_type->typ_name,
156 uuid = &watched->u.cli.cl_target_uuid;
157 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE) {
159 * Set MDC as active before notifying the observer, so the
160 * observer can use the MDC normally.
162 rc = lmv_set_mdc_active(lmv, uuid,
163 ev == OBD_NOTIFY_ACTIVE);
165 CERROR("%sactivation of %s failed: %d\n",
166 ev == OBD_NOTIFY_ACTIVE ? "" : "de",
170 } else if (ev == OBD_NOTIFY_OCD) {
171 conn_data = &watched->u.cli.cl_import->imp_connect_data;
173 * XXX: Make sure that ocd_connect_flags from all targets are
174 * the same. Otherwise one of MDTs runs wrong version or
175 * something like this. --umka
177 obd->obd_self_export->exp_connect_data = *conn_data;
180 else if (ev == OBD_NOTIFY_DISCON) {
182 * For disconnect event, flush fld cache for failout MDS case.
184 fld_client_flush(&lmv->lmv_fld);
188 * Pass the notification up the chain.
190 if (obd->obd_observer)
191 rc = obd_notify(obd->obd_observer, watched, ev, data);
197 * This is fake connect function. Its purpose is to initialize lmv and say
198 * caller that everything is okay. Real connection will be performed later.
200 static int lmv_connect(const struct lu_env *env,
201 struct obd_export **exp, struct obd_device *obd,
202 struct obd_uuid *cluuid, struct obd_connect_data *data,
206 struct proc_dir_entry *lmv_proc_dir;
208 struct lmv_obd *lmv = &obd->u.lmv;
209 struct lustre_handle conn = { 0 };
214 * We don't want to actually do the underlying connections more than
215 * once, so keep track.
218 if (lmv->refcount > 1) {
223 rc = class_connect(&conn, obd, cluuid);
225 CERROR("class_connection() returned %d\n", rc);
229 *exp = class_conn2export(&conn);
230 class_export_get(*exp);
234 lmv->cluuid = *cluuid;
237 lmv->conn_data = *data;
240 lmv_proc_dir = lprocfs_register("target_obds", obd->obd_proc_entry,
242 if (IS_ERR(lmv_proc_dir)) {
243 CERROR("could not register /proc/fs/lustre/%s/%s/target_obds.",
244 obd->obd_type->typ_name, obd->obd_name);
250 * All real clients should perform actual connection right away, because
251 * it is possible, that LMV will not have opportunity to connect targets
252 * and MDC stuff will be called directly, for instance while reading
253 * ../mdc/../kbytesfree procfs file, etc.
255 if (data->ocd_connect_flags & OBD_CONNECT_REAL)
256 rc = lmv_check_connect(obd);
261 lprocfs_remove(&lmv_proc_dir);
268 static void lmv_set_timeouts(struct obd_device *obd)
270 struct lmv_tgt_desc *tgt;
275 if (lmv->server_timeout == 0)
278 if (lmv->connected == 0)
281 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
283 if (tgt == NULL || tgt->ltd_exp == NULL || tgt->ltd_active == 0)
286 obd_set_info_async(NULL, tgt->ltd_exp, sizeof(KEY_INTERMDS),
287 KEY_INTERMDS, 0, NULL, NULL);
291 static int lmv_init_ea_size(struct obd_export *exp, int easize,
292 int def_easize, int cookiesize)
294 struct obd_device *obd = exp->exp_obd;
295 struct lmv_obd *lmv = &obd->u.lmv;
301 if (lmv->max_easize < easize) {
302 lmv->max_easize = easize;
305 if (lmv->max_def_easize < def_easize) {
306 lmv->max_def_easize = def_easize;
309 if (lmv->max_cookiesize < cookiesize) {
310 lmv->max_cookiesize = cookiesize;
316 if (lmv->connected == 0)
319 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
320 if (lmv->tgts[i] == NULL ||
321 lmv->tgts[i]->ltd_exp == NULL ||
322 lmv->tgts[i]->ltd_active == 0) {
323 CWARN("%s: NULL export for %d\n", obd->obd_name, i);
327 rc = md_init_ea_size(lmv->tgts[i]->ltd_exp, easize, def_easize,
330 CERROR("%s: obd_init_ea_size() failed on MDT target %d:"
331 " rc = %d.\n", obd->obd_name, i, rc);
338 #define MAX_STRING_SIZE 128
340 int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
343 struct proc_dir_entry *lmv_proc_dir;
345 struct lmv_obd *lmv = &obd->u.lmv;
346 struct obd_uuid *cluuid = &lmv->cluuid;
347 struct obd_uuid lmv_mdc_uuid = { "LMV_MDC_UUID" };
348 struct obd_device *mdc_obd;
349 struct obd_export *mdc_exp;
350 struct lu_fld_target target;
354 mdc_obd = class_find_client_obd(&tgt->ltd_uuid, LUSTRE_MDC_NAME,
357 CERROR("target %s not attached\n", tgt->ltd_uuid.uuid);
361 CDEBUG(D_CONFIG, "connect to %s(%s) - %s, %s FOR %s\n",
362 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
363 tgt->ltd_uuid.uuid, obd->obd_uuid.uuid,
366 if (!mdc_obd->obd_set_up) {
367 CERROR("target %s is not set up\n", tgt->ltd_uuid.uuid);
371 rc = obd_connect(NULL, &mdc_exp, mdc_obd, &lmv_mdc_uuid,
372 &lmv->conn_data, NULL);
374 CERROR("target %s connect error %d\n", tgt->ltd_uuid.uuid, rc);
379 * Init fid sequence client for this mdc and add new fld target.
381 rc = obd_fid_init(mdc_obd, mdc_exp, LUSTRE_SEQ_METADATA);
385 target.ft_srv = NULL;
386 target.ft_exp = mdc_exp;
387 target.ft_idx = tgt->ltd_idx;
389 fld_client_add_target(&lmv->lmv_fld, &target);
391 rc = obd_register_observer(mdc_obd, obd);
393 obd_disconnect(mdc_exp);
394 CERROR("target %s register_observer error %d\n",
395 tgt->ltd_uuid.uuid, rc);
399 if (obd->obd_observer) {
401 * Tell the observer about the new target.
403 rc = obd_notify(obd->obd_observer, mdc_exp->exp_obd,
405 (void *)(tgt - lmv->tgts[0]));
407 obd_disconnect(mdc_exp);
413 tgt->ltd_exp = mdc_exp;
414 lmv->desc.ld_active_tgt_count++;
416 md_init_ea_size(tgt->ltd_exp, lmv->max_easize,
417 lmv->max_def_easize, lmv->max_cookiesize);
419 CDEBUG(D_CONFIG, "Connected to %s(%s) successfully (%d)\n",
420 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
421 cfs_atomic_read(&obd->obd_refcount));
424 lmv_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
426 struct proc_dir_entry *mdc_symlink;
428 LASSERT(mdc_obd->obd_type != NULL);
429 LASSERT(mdc_obd->obd_type->typ_name != NULL);
430 mdc_symlink = lprocfs_add_symlink(mdc_obd->obd_name,
433 mdc_obd->obd_type->typ_name,
435 if (mdc_symlink == NULL) {
436 CERROR("Could not register LMV target "
437 "/proc/fs/lustre/%s/%s/target_obds/%s.",
438 obd->obd_type->typ_name, obd->obd_name,
440 lprocfs_remove(&lmv_proc_dir);
448 static void lmv_del_target(struct lmv_obd *lmv, int index)
450 if (lmv->tgts[index] == NULL)
453 OBD_FREE_PTR(lmv->tgts[index]);
454 lmv->tgts[index] = NULL;
458 static int lmv_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
459 __u32 index, int gen)
461 struct lmv_obd *lmv = &obd->u.lmv;
462 struct lmv_tgt_desc *tgt;
466 CDEBUG(D_CONFIG, "Target uuid: %s. index %d\n", uuidp->uuid, index);
470 if (lmv->desc.ld_tgt_count == 0) {
471 struct obd_device *mdc_obd;
473 mdc_obd = class_find_client_obd(uuidp, LUSTRE_MDC_NAME,
476 lmv_init_unlock(lmv);
477 CERROR("%s: Target %s not attached: rc = %d\n",
478 obd->obd_name, uuidp->uuid, -EINVAL);
483 if ((index < lmv->tgts_size) && (lmv->tgts[index] != NULL)) {
484 tgt = lmv->tgts[index];
485 CERROR("%s: UUID %s already assigned at LOV target index %d:"
486 " rc = %d\n", obd->obd_name,
487 obd_uuid2str(&tgt->ltd_uuid), index, -EEXIST);
488 lmv_init_unlock(lmv);
492 if (index >= lmv->tgts_size) {
493 /* We need to reallocate the lmv target array. */
494 struct lmv_tgt_desc **newtgts, **old = NULL;
498 while (newsize < index + 1)
499 newsize = newsize << 1;
500 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
501 if (newtgts == NULL) {
502 lmv_init_unlock(lmv);
506 if (lmv->tgts_size) {
507 memcpy(newtgts, lmv->tgts,
508 sizeof(*newtgts) * lmv->tgts_size);
510 oldsize = lmv->tgts_size;
514 lmv->tgts_size = newsize;
517 OBD_FREE(old, sizeof(*old) * oldsize);
519 CDEBUG(D_CONFIG, "tgts: %p size: %d\n", lmv->tgts,
525 lmv_init_unlock(lmv);
529 mutex_init(&tgt->ltd_fid_mutex);
530 tgt->ltd_idx = index;
531 tgt->ltd_uuid = *uuidp;
533 lmv->tgts[index] = tgt;
534 if (index >= lmv->desc.ld_tgt_count)
535 lmv->desc.ld_tgt_count = index + 1;
537 if (lmv->connected) {
538 rc = lmv_connect_mdc(obd, tgt);
540 spin_lock(&lmv->lmv_lock);
541 lmv->desc.ld_tgt_count--;
542 memset(tgt, 0, sizeof(*tgt));
543 spin_unlock(&lmv->lmv_lock);
545 int easize = sizeof(struct lmv_stripe_md) +
546 lmv->desc.ld_tgt_count *
547 sizeof(struct lu_fid);
548 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0);
552 lmv_init_unlock(lmv);
556 int lmv_check_connect(struct obd_device *obd)
558 struct lmv_obd *lmv = &obd->u.lmv;
559 struct lmv_tgt_desc *tgt;
569 if (lmv->connected) {
570 lmv_init_unlock(lmv);
574 if (lmv->desc.ld_tgt_count == 0) {
575 lmv_init_unlock(lmv);
576 CERROR("%s: no targets configured.\n", obd->obd_name);
580 CDEBUG(D_CONFIG, "Time to connect %s to %s\n",
581 lmv->cluuid.uuid, obd->obd_name);
583 LASSERT(lmv->tgts != NULL);
585 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
589 rc = lmv_connect_mdc(obd, tgt);
594 lmv_set_timeouts(obd);
595 class_export_put(lmv->exp);
597 easize = lmv_get_easize(lmv);
598 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0);
599 lmv_init_unlock(lmv);
610 --lmv->desc.ld_active_tgt_count;
611 rc2 = obd_disconnect(tgt->ltd_exp);
613 CERROR("LMV target %s disconnect on "
614 "MDC idx %d: error %d\n",
615 tgt->ltd_uuid.uuid, i, rc2);
619 class_disconnect(lmv->exp);
620 lmv_init_unlock(lmv);
624 static int lmv_disconnect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
627 struct proc_dir_entry *lmv_proc_dir;
629 struct lmv_obd *lmv = &obd->u.lmv;
630 struct obd_device *mdc_obd;
634 LASSERT(tgt != NULL);
635 LASSERT(obd != NULL);
637 mdc_obd = class_exp2obd(tgt->ltd_exp);
640 mdc_obd->obd_force = obd->obd_force;
641 mdc_obd->obd_fail = obd->obd_fail;
642 mdc_obd->obd_no_recov = obd->obd_no_recov;
646 lmv_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
648 struct proc_dir_entry *mdc_symlink;
650 mdc_symlink = lprocfs_srch(lmv_proc_dir, mdc_obd->obd_name);
652 lprocfs_remove(&mdc_symlink);
654 CERROR("/proc/fs/lustre/%s/%s/target_obds/%s missing\n",
655 obd->obd_type->typ_name, obd->obd_name,
660 rc = obd_fid_fini(tgt->ltd_exp->exp_obd);
662 CERROR("Can't finanize fids factory\n");
664 CDEBUG(D_INFO, "Disconnected from %s(%s) successfully\n",
665 tgt->ltd_exp->exp_obd->obd_name,
666 tgt->ltd_exp->exp_obd->obd_uuid.uuid);
668 obd_register_observer(tgt->ltd_exp->exp_obd, NULL);
669 rc = obd_disconnect(tgt->ltd_exp);
671 if (tgt->ltd_active) {
672 CERROR("Target %s disconnect error %d\n",
673 tgt->ltd_uuid.uuid, rc);
677 lmv_activate_target(lmv, tgt, 0);
682 static int lmv_disconnect(struct obd_export *exp)
684 struct obd_device *obd = class_exp2obd(exp);
686 struct proc_dir_entry *lmv_proc_dir;
688 struct lmv_obd *lmv = &obd->u.lmv;
697 * Only disconnect the underlying layers on the final disconnect.
700 if (lmv->refcount != 0)
703 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
704 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
707 lmv_disconnect_mdc(obd, lmv->tgts[i]);
711 lmv_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
713 lprocfs_remove(&lmv_proc_dir);
715 CERROR("/proc/fs/lustre/%s/%s/target_obds missing\n",
716 obd->obd_type->typ_name, obd->obd_name);
722 * This is the case when no real connection is established by
723 * lmv_check_connect().
726 class_export_put(exp);
727 rc = class_disconnect(exp);
728 if (lmv->refcount == 0)
733 static int lmv_fid2path(struct obd_export *exp, int len, void *karg, void *uarg)
735 struct obd_device *obddev = class_exp2obd(exp);
736 struct lmv_obd *lmv = &obddev->u.lmv;
737 struct getinfo_fid2path *gf;
738 struct lmv_tgt_desc *tgt;
739 struct getinfo_fid2path *remote_gf = NULL;
740 int remote_gf_size = 0;
743 gf = (struct getinfo_fid2path *)karg;
744 tgt = lmv_find_target(lmv, &gf->gf_fid);
746 RETURN(PTR_ERR(tgt));
749 rc = obd_iocontrol(OBD_IOC_FID2PATH, tgt->ltd_exp, len, gf, uarg);
750 if (rc != 0 && rc != -EREMOTE)
751 GOTO(out_fid2path, rc);
753 /* If remote_gf != NULL, it means just building the
754 * path on the remote MDT, copy this path segement to gf */
755 if (remote_gf != NULL) {
756 struct getinfo_fid2path *ori_gf;
759 ori_gf = (struct getinfo_fid2path *)karg;
760 if (strlen(ori_gf->gf_path) +
761 strlen(gf->gf_path) > ori_gf->gf_pathlen)
762 GOTO(out_fid2path, rc = -EOVERFLOW);
764 ptr = ori_gf->gf_path;
766 memmove(ptr + strlen(gf->gf_path) + 1, ptr,
767 strlen(ori_gf->gf_path));
769 strncpy(ptr, gf->gf_path, strlen(gf->gf_path));
770 ptr += strlen(gf->gf_path);
774 CDEBUG(D_INFO, "%s: get path %s "DFID" rec: "LPU64" ln: %u\n",
775 tgt->ltd_exp->exp_obd->obd_name,
776 gf->gf_path, PFID(&gf->gf_fid), gf->gf_recno,
780 GOTO(out_fid2path, rc);
782 /* sigh, has to go to another MDT to do path building further */
783 if (remote_gf == NULL) {
784 remote_gf_size = sizeof(*remote_gf) + PATH_MAX;
785 OBD_ALLOC(remote_gf, remote_gf_size);
786 if (remote_gf == NULL)
787 GOTO(out_fid2path, rc = -ENOMEM);
788 remote_gf->gf_pathlen = PATH_MAX;
791 if (!fid_is_sane(&gf->gf_fid)) {
792 CERROR("%s: invalid FID "DFID": rc = %d\n",
793 tgt->ltd_exp->exp_obd->obd_name,
794 PFID(&gf->gf_fid), -EINVAL);
795 GOTO(out_fid2path, rc = -EINVAL);
798 tgt = lmv_find_target(lmv, &gf->gf_fid);
800 GOTO(out_fid2path, rc = -EINVAL);
802 remote_gf->gf_fid = gf->gf_fid;
803 remote_gf->gf_recno = -1;
804 remote_gf->gf_linkno = -1;
805 memset(remote_gf->gf_path, 0, remote_gf->gf_pathlen);
807 goto repeat_fid2path;
810 if (remote_gf != NULL)
811 OBD_FREE(remote_gf, remote_gf_size);
815 static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
816 int len, void *karg, void *uarg)
818 struct obd_device *obddev = class_exp2obd(exp);
819 struct lmv_obd *lmv = &obddev->u.lmv;
823 int count = lmv->desc.ld_tgt_count;
830 case IOC_OBD_STATFS: {
831 struct obd_ioctl_data *data = karg;
832 struct obd_device *mdc_obd;
833 struct obd_statfs stat_buf = {0};
836 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
837 if ((index >= count))
840 if (lmv->tgts[index] == NULL ||
841 lmv->tgts[index]->ltd_active == 0)
844 mdc_obd = class_exp2obd(lmv->tgts[index]->ltd_exp);
849 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(mdc_obd),
850 min((int) data->ioc_plen2,
851 (int) sizeof(struct obd_uuid))))
854 rc = obd_statfs(NULL, lmv->tgts[index]->ltd_exp, &stat_buf,
855 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
859 if (copy_to_user(data->ioc_pbuf1, &stat_buf,
860 min((int) data->ioc_plen1,
861 (int) sizeof(stat_buf))))
865 case OBD_IOC_QUOTACTL: {
866 struct if_quotactl *qctl = karg;
867 struct lmv_tgt_desc *tgt = NULL;
868 struct obd_quotactl *oqctl;
870 if (qctl->qc_valid == QC_MDTIDX) {
871 if (qctl->qc_idx < 0 || count <= qctl->qc_idx)
874 tgt = lmv->tgts[qctl->qc_idx];
875 if (tgt == NULL || tgt->ltd_exp == NULL)
877 } else if (qctl->qc_valid == QC_UUID) {
878 for (i = 0; i < count; i++) {
882 if (!obd_uuid_equals(&tgt->ltd_uuid,
886 if (tgt->ltd_exp == NULL)
898 LASSERT(tgt && tgt->ltd_exp);
899 OBD_ALLOC_PTR(oqctl);
903 QCTL_COPY(oqctl, qctl);
904 rc = obd_quotactl(tgt->ltd_exp, oqctl);
906 QCTL_COPY(qctl, oqctl);
907 qctl->qc_valid = QC_MDTIDX;
908 qctl->obd_uuid = tgt->ltd_uuid;
913 case OBD_IOC_CHANGELOG_SEND:
914 case OBD_IOC_CHANGELOG_CLEAR: {
915 struct ioc_changelog *icc = karg;
917 if (icc->icc_mdtindex >= count)
920 if (lmv->tgts[icc->icc_mdtindex] == NULL ||
921 lmv->tgts[icc->icc_mdtindex]->ltd_exp == NULL ||
922 lmv->tgts[icc->icc_mdtindex]->ltd_active == 0)
924 rc = obd_iocontrol(cmd, lmv->tgts[icc->icc_mdtindex]->ltd_exp,
925 sizeof(*icc), icc, NULL);
928 case LL_IOC_GET_CONNECT_FLAGS: {
929 if (lmv->tgts[0] == NULL)
931 rc = obd_iocontrol(cmd, lmv->tgts[0]->ltd_exp, len, karg, uarg);
934 case OBD_IOC_FID2PATH: {
935 rc = lmv_fid2path(exp, len, karg, uarg);
938 case LL_IOC_HSM_STATE_GET:
939 case LL_IOC_HSM_STATE_SET:
940 case LL_IOC_HSM_ACTION:
941 case LL_IOC_LOV_SWAP_LAYOUTS: {
942 struct md_op_data *op_data = karg;
943 struct lmv_tgt_desc *tgt1, *tgt2;
945 tgt1 = lmv_find_target(lmv, &op_data->op_fid1);
947 RETURN(PTR_ERR(tgt1));
949 tgt2 = lmv_find_target(lmv, &op_data->op_fid2);
951 RETURN(PTR_ERR(tgt2));
953 if ((tgt1->ltd_exp == NULL) || (tgt2->ltd_exp == NULL))
956 /* only files on same MDT can have their layouts swapped */
957 if (tgt1->ltd_idx != tgt2->ltd_idx)
960 rc = obd_iocontrol(cmd, tgt1->ltd_exp, len, karg, uarg);
964 for (i = 0; i < count; i++) {
965 struct obd_device *mdc_obd;
968 if (lmv->tgts[i] == NULL ||
969 lmv->tgts[i]->ltd_exp == NULL)
971 /* ll_umount_begin() sets force flag but for lmv, not
972 * mdc. Let's pass it through */
973 mdc_obd = class_exp2obd(lmv->tgts[i]->ltd_exp);
974 mdc_obd->obd_force = obddev->obd_force;
975 err = obd_iocontrol(cmd, lmv->tgts[i]->ltd_exp, len,
977 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
980 if (lmv->tgts[i]->ltd_active) {
981 CERROR("error: iocontrol MDC %s on MDT"
982 "idx %d cmd %x: err = %d\n",
983 lmv->tgts[i]->ltd_uuid.uuid,
998 static int lmv_all_chars_policy(int count, const char *name,
1009 static int lmv_nid_policy(struct lmv_obd *lmv)
1011 struct obd_import *imp;
1015 * XXX: To get nid we assume that underlying obd device is mdc.
1017 imp = class_exp2cliimp(lmv->tgts[0].ltd_exp);
1018 id = imp->imp_connection->c_self ^ (imp->imp_connection->c_self >> 32);
1019 return id % lmv->desc.ld_tgt_count;
1022 static int lmv_choose_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1023 placement_policy_t placement)
1025 switch (placement) {
1026 case PLACEMENT_CHAR_POLICY:
1027 return lmv_all_chars_policy(lmv->desc.ld_tgt_count,
1029 op_data->op_namelen);
1030 case PLACEMENT_NID_POLICY:
1031 return lmv_nid_policy(lmv);
1037 CERROR("Unsupported placement policy %x\n", placement);
1043 * This is _inode_ placement policy function (not name).
1045 static int lmv_placement_policy(struct obd_device *obd,
1046 struct md_op_data *op_data,
1049 struct lmv_obd *lmv = &obd->u.lmv;
1052 LASSERT(mds != NULL);
1054 if (lmv->desc.ld_tgt_count == 1) {
1060 * If stripe_offset is provided during setdirstripe
1061 * (setdirstripe -i xx), xx MDS will be choosen.
1063 if (op_data->op_cli_flags & CLI_SET_MEA) {
1064 struct lmv_user_md *lum;
1066 lum = (struct lmv_user_md *)op_data->op_data;
1067 if (lum->lum_type == LMV_STRIPE_TYPE &&
1068 lum->lum_stripe_offset != -1) {
1069 if (lum->lum_stripe_offset >= lmv->desc.ld_tgt_count) {
1070 CERROR("%s: Stripe_offset %d > MDT count %d:"
1071 " rc = %d\n", obd->obd_name,
1072 lum->lum_stripe_offset,
1073 lmv->desc.ld_tgt_count, -ERANGE);
1076 *mds = lum->lum_stripe_offset;
1081 /* Allocate new fid on target according to operation type and parent
1083 *mds = op_data->op_mds;
1087 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid,
1090 struct lmv_tgt_desc *tgt;
1094 tgt = lmv_get_target(lmv, mds);
1096 RETURN(PTR_ERR(tgt));
1099 * New seq alloc and FLD setup should be atomic. Otherwise we may find
1100 * on server that seq in new allocated fid is not yet known.
1102 mutex_lock(&tgt->ltd_fid_mutex);
1104 if (tgt->ltd_active == 0 || tgt->ltd_exp == NULL)
1105 GOTO(out, rc = -ENODEV);
1108 * Asking underlaying tgt layer to allocate new fid.
1110 rc = obd_fid_alloc(tgt->ltd_exp, fid, NULL);
1112 LASSERT(fid_is_sane(fid));
1118 mutex_unlock(&tgt->ltd_fid_mutex);
1122 int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
1123 struct md_op_data *op_data)
1125 struct obd_device *obd = class_exp2obd(exp);
1126 struct lmv_obd *lmv = &obd->u.lmv;
1131 LASSERT(op_data != NULL);
1132 LASSERT(fid != NULL);
1134 rc = lmv_placement_policy(obd, op_data, &mds);
1136 CERROR("Can't get target for allocating fid, "
1141 rc = __lmv_fid_alloc(lmv, fid, mds);
1143 CERROR("Can't alloc new fid, rc %d\n", rc);
1150 static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
1152 struct lmv_obd *lmv = &obd->u.lmv;
1153 struct lprocfs_static_vars lvars;
1154 struct lmv_desc *desc;
1158 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
1159 CERROR("LMV setup requires a descriptor\n");
1163 desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1);
1164 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
1165 CERROR("Lmv descriptor size wrong: %d > %d\n",
1166 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
1170 OBD_ALLOC(lmv->tgts, sizeof(*lmv->tgts) * 32);
1171 if (lmv->tgts == NULL)
1173 lmv->tgts_size = 32;
1175 obd_str2uuid(&lmv->desc.ld_uuid, desc->ld_uuid.uuid);
1176 lmv->desc.ld_tgt_count = 0;
1177 lmv->desc.ld_active_tgt_count = 0;
1178 lmv->max_cookiesize = 0;
1179 lmv->max_def_easize = 0;
1180 lmv->max_easize = 0;
1181 lmv->lmv_placement = PLACEMENT_CHAR_POLICY;
1183 spin_lock_init(&lmv->lmv_lock);
1184 mutex_init(&lmv->init_mutex);
1186 lprocfs_lmv_init_vars(&lvars);
1188 lprocfs_obd_setup(obd, lvars.obd_vars);
1191 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
1192 0444, &lmv_proc_target_fops, obd);
1194 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
1198 rc = fld_client_init(&lmv->lmv_fld, obd->obd_name,
1199 LUSTRE_CLI_FLD_HASH_DHT);
1201 CERROR("Can't init FLD, err %d\n", rc);
1211 static int lmv_cleanup(struct obd_device *obd)
1213 struct lmv_obd *lmv = &obd->u.lmv;
1216 fld_client_fini(&lmv->lmv_fld);
1217 if (lmv->tgts != NULL) {
1219 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1220 if (lmv->tgts[i] == NULL)
1222 lmv_del_target(lmv, i);
1224 OBD_FREE(lmv->tgts, sizeof(*lmv->tgts) * lmv->tgts_size);
1230 static int lmv_process_config(struct obd_device *obd, obd_count len, void *buf)
1232 struct lustre_cfg *lcfg = buf;
1233 struct obd_uuid obd_uuid;
1239 switch (lcfg->lcfg_command) {
1241 /* modify_mdc_tgts add 0:lustre-clilmv 1:lustre-MDT0000_UUID
1242 * 2:0 3:1 4:lustre-MDT0000-mdc_UUID */
1243 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
1244 GOTO(out, rc = -EINVAL);
1246 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
1248 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
1249 GOTO(out, rc = -EINVAL);
1250 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
1251 GOTO(out, rc = -EINVAL);
1252 rc = lmv_add_target(obd, &obd_uuid, index, gen);
1255 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1256 GOTO(out, rc = -EINVAL);
1262 static int lmv_statfs(const struct lu_env *env, struct obd_export *exp,
1263 struct obd_statfs *osfs, __u64 max_age, __u32 flags)
1265 struct obd_device *obd = class_exp2obd(exp);
1266 struct lmv_obd *lmv = &obd->u.lmv;
1267 struct obd_statfs *temp;
1272 rc = lmv_check_connect(obd);
1276 OBD_ALLOC(temp, sizeof(*temp));
1280 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1281 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1284 rc = obd_statfs(env, lmv->tgts[i]->ltd_exp, temp,
1287 CERROR("can't stat MDS #%d (%s), error %d\n", i,
1288 lmv->tgts[i]->ltd_exp->exp_obd->obd_name,
1290 GOTO(out_free_temp, rc);
1295 /* If the statfs is from mount, it will needs
1296 * retrieve necessary information from MDT0.
1297 * i.e. mount does not need the merged osfs
1299 * And also clients can be mounted as long as
1300 * MDT0 is in service*/
1301 if (flags & OBD_STATFS_FOR_MDT0)
1302 GOTO(out_free_temp, rc);
1304 osfs->os_bavail += temp->os_bavail;
1305 osfs->os_blocks += temp->os_blocks;
1306 osfs->os_ffree += temp->os_ffree;
1307 osfs->os_files += temp->os_files;
1313 OBD_FREE(temp, sizeof(*temp));
1317 static int lmv_getstatus(struct obd_export *exp,
1319 struct obd_capa **pc)
1321 struct obd_device *obd = exp->exp_obd;
1322 struct lmv_obd *lmv = &obd->u.lmv;
1326 rc = lmv_check_connect(obd);
1330 rc = md_getstatus(lmv->tgts[0]->ltd_exp, fid, pc);
1334 static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1335 struct obd_capa *oc, obd_valid valid, const char *name,
1336 const char *input, int input_size, int output_size,
1337 int flags, struct ptlrpc_request **request)
1339 struct obd_device *obd = exp->exp_obd;
1340 struct lmv_obd *lmv = &obd->u.lmv;
1341 struct lmv_tgt_desc *tgt;
1345 rc = lmv_check_connect(obd);
1349 tgt = lmv_find_target(lmv, fid);
1351 RETURN(PTR_ERR(tgt));
1353 rc = md_getxattr(tgt->ltd_exp, fid, oc, valid, name, input,
1354 input_size, output_size, flags, request);
1359 static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1360 struct obd_capa *oc, obd_valid valid, const char *name,
1361 const char *input, int input_size, int output_size,
1362 int flags, __u32 suppgid,
1363 struct ptlrpc_request **request)
1365 struct obd_device *obd = exp->exp_obd;
1366 struct lmv_obd *lmv = &obd->u.lmv;
1367 struct lmv_tgt_desc *tgt;
1371 rc = lmv_check_connect(obd);
1375 tgt = lmv_find_target(lmv, fid);
1377 RETURN(PTR_ERR(tgt));
1379 rc = md_setxattr(tgt->ltd_exp, fid, oc, valid, name, input,
1380 input_size, output_size, flags, suppgid,
1386 static int lmv_getattr(struct obd_export *exp, struct md_op_data *op_data,
1387 struct ptlrpc_request **request)
1389 struct obd_device *obd = exp->exp_obd;
1390 struct lmv_obd *lmv = &obd->u.lmv;
1391 struct lmv_tgt_desc *tgt;
1395 rc = lmv_check_connect(obd);
1399 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1401 RETURN(PTR_ERR(tgt));
1403 if (op_data->op_flags & MF_GET_MDT_IDX) {
1404 op_data->op_mds = tgt->ltd_idx;
1408 rc = md_getattr(tgt->ltd_exp, op_data, request);
1413 static int lmv_null_inode(struct obd_export *exp, const struct lu_fid *fid)
1415 struct obd_device *obd = exp->exp_obd;
1416 struct lmv_obd *lmv = &obd->u.lmv;
1421 rc = lmv_check_connect(obd);
1425 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1428 * With DNE every object can have two locks in different namespaces:
1429 * lookup lock in space of MDT storing direntry and update/open lock in
1430 * space of MDT storing inode.
1432 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1433 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1435 md_null_inode(lmv->tgts[i]->ltd_exp, fid);
1441 static int lmv_find_cbdata(struct obd_export *exp, const struct lu_fid *fid,
1442 ldlm_iterator_t it, void *data)
1444 struct obd_device *obd = exp->exp_obd;
1445 struct lmv_obd *lmv = &obd->u.lmv;
1450 rc = lmv_check_connect(obd);
1454 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1457 * With DNE every object can have two locks in different namespaces:
1458 * lookup lock in space of MDT storing direntry and update/open lock in
1459 * space of MDT storing inode.
1461 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1462 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1464 rc = md_find_cbdata(lmv->tgts[i]->ltd_exp, fid, it, data);
1473 static int lmv_close(struct obd_export *exp, struct md_op_data *op_data,
1474 struct md_open_data *mod, struct ptlrpc_request **request)
1476 struct obd_device *obd = exp->exp_obd;
1477 struct lmv_obd *lmv = &obd->u.lmv;
1478 struct lmv_tgt_desc *tgt;
1482 rc = lmv_check_connect(obd);
1486 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1488 RETURN(PTR_ERR(tgt));
1490 CDEBUG(D_INODE, "CLOSE "DFID"\n", PFID(&op_data->op_fid1));
1491 rc = md_close(tgt->ltd_exp, op_data, mod, request);
1496 *lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1499 struct lmv_tgt_desc *tgt;
1501 tgt = lmv_find_target(lmv, fid);
1505 op_data->op_mds = tgt->ltd_idx;
1510 int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
1511 const void *data, int datalen, int mode, __u32 uid,
1512 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1513 struct ptlrpc_request **request)
1515 struct obd_device *obd = exp->exp_obd;
1516 struct lmv_obd *lmv = &obd->u.lmv;
1517 struct lmv_tgt_desc *tgt;
1521 rc = lmv_check_connect(obd);
1525 if (!lmv->desc.ld_active_tgt_count)
1528 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1530 RETURN(PTR_ERR(tgt));
1532 rc = lmv_fid_alloc(exp, &op_data->op_fid2, op_data);
1536 CDEBUG(D_INODE, "CREATE '%*s' on "DFID" -> mds #%x\n",
1537 op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1),
1540 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1541 rc = md_create(tgt->ltd_exp, op_data, data, datalen, mode, uid, gid,
1542 cap_effective, rdev, request);
1545 if (*request == NULL)
1547 CDEBUG(D_INODE, "Created - "DFID"\n", PFID(&op_data->op_fid2));
1552 static int lmv_done_writing(struct obd_export *exp,
1553 struct md_op_data *op_data,
1554 struct md_open_data *mod)
1556 struct obd_device *obd = exp->exp_obd;
1557 struct lmv_obd *lmv = &obd->u.lmv;
1558 struct lmv_tgt_desc *tgt;
1562 rc = lmv_check_connect(obd);
1566 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1568 RETURN(PTR_ERR(tgt));
1570 rc = md_done_writing(tgt->ltd_exp, op_data, mod);
1575 lmv_enqueue_remote(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1576 struct lookup_intent *it, struct md_op_data *op_data,
1577 struct lustre_handle *lockh, void *lmm, int lmmsize,
1578 int extra_lock_flags)
1580 struct ptlrpc_request *req = it->d.lustre.it_data;
1581 struct obd_device *obd = exp->exp_obd;
1582 struct lmv_obd *lmv = &obd->u.lmv;
1583 struct lustre_handle plock;
1584 struct lmv_tgt_desc *tgt;
1585 struct md_op_data *rdata;
1587 struct mdt_body *body;
1592 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1593 LASSERT(body != NULL);
1595 if (!(body->valid & OBD_MD_MDS))
1598 CDEBUG(D_INODE, "REMOTE_ENQUEUE '%s' on "DFID" -> "DFID"\n",
1599 LL_IT2STR(it), PFID(&op_data->op_fid1), PFID(&body->fid1));
1602 * We got LOOKUP lock, but we really need attrs.
1604 pmode = it->d.lustre.it_lock_mode;
1605 LASSERT(pmode != 0);
1606 memcpy(&plock, lockh, sizeof(plock));
1607 it->d.lustre.it_lock_mode = 0;
1608 it->d.lustre.it_data = NULL;
1611 it->d.lustre.it_disposition &= ~DISP_ENQ_COMPLETE;
1612 ptlrpc_req_finished(req);
1614 tgt = lmv_find_target(lmv, &fid1);
1616 GOTO(out, rc = PTR_ERR(tgt));
1618 OBD_ALLOC_PTR(rdata);
1620 GOTO(out, rc = -ENOMEM);
1622 rdata->op_fid1 = fid1;
1623 rdata->op_bias = MDS_CROSS_REF;
1625 rc = md_enqueue(tgt->ltd_exp, einfo, it, rdata, lockh,
1626 lmm, lmmsize, NULL, extra_lock_flags);
1627 OBD_FREE_PTR(rdata);
1630 ldlm_lock_decref(&plock, pmode);
1635 lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1636 struct lookup_intent *it, struct md_op_data *op_data,
1637 struct lustre_handle *lockh, void *lmm, int lmmsize,
1638 struct ptlrpc_request **req, __u64 extra_lock_flags)
1640 struct obd_device *obd = exp->exp_obd;
1641 struct lmv_obd *lmv = &obd->u.lmv;
1642 struct lmv_tgt_desc *tgt;
1646 rc = lmv_check_connect(obd);
1650 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID"\n",
1651 LL_IT2STR(it), PFID(&op_data->op_fid1));
1653 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1655 RETURN(PTR_ERR(tgt));
1657 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID" -> mds #%d\n",
1658 LL_IT2STR(it), PFID(&op_data->op_fid1), tgt->ltd_idx);
1660 rc = md_enqueue(tgt->ltd_exp, einfo, it, op_data, lockh,
1661 lmm, lmmsize, req, extra_lock_flags);
1663 if (rc == 0 && it && it->it_op == IT_OPEN) {
1664 rc = lmv_enqueue_remote(exp, einfo, it, op_data, lockh,
1665 lmm, lmmsize, extra_lock_flags);
1671 lmv_getattr_name(struct obd_export *exp,struct md_op_data *op_data,
1672 struct ptlrpc_request **request)
1674 struct ptlrpc_request *req = NULL;
1675 struct obd_device *obd = exp->exp_obd;
1676 struct lmv_obd *lmv = &obd->u.lmv;
1677 struct lmv_tgt_desc *tgt;
1678 struct mdt_body *body;
1682 rc = lmv_check_connect(obd);
1686 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1688 RETURN(PTR_ERR(tgt));
1690 CDEBUG(D_INODE, "GETATTR_NAME for %*s on "DFID" -> mds #%d\n",
1691 op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1),
1694 rc = md_getattr_name(tgt->ltd_exp, op_data, request);
1698 body = req_capsule_server_get(&(*request)->rq_pill,
1700 LASSERT(body != NULL);
1702 if (body->valid & OBD_MD_MDS) {
1703 struct lu_fid rid = body->fid1;
1704 CDEBUG(D_INODE, "Request attrs for "DFID"\n",
1707 tgt = lmv_find_target(lmv, &rid);
1709 ptlrpc_req_finished(*request);
1710 RETURN(PTR_ERR(tgt));
1713 op_data->op_fid1 = rid;
1714 op_data->op_valid |= OBD_MD_FLCROSSREF;
1715 op_data->op_namelen = 0;
1716 op_data->op_name = NULL;
1717 rc = md_getattr_name(tgt->ltd_exp, op_data, &req);
1718 ptlrpc_req_finished(*request);
1725 #define md_op_data_fid(op_data, fl) \
1726 (fl == MF_MDC_CANCEL_FID1 ? &op_data->op_fid1 : \
1727 fl == MF_MDC_CANCEL_FID2 ? &op_data->op_fid2 : \
1728 fl == MF_MDC_CANCEL_FID3 ? &op_data->op_fid3 : \
1729 fl == MF_MDC_CANCEL_FID4 ? &op_data->op_fid4 : \
1732 static int lmv_early_cancel(struct obd_export *exp, struct md_op_data *op_data,
1733 int op_tgt, ldlm_mode_t mode, int bits, int flag)
1735 struct lu_fid *fid = md_op_data_fid(op_data, flag);
1736 struct obd_device *obd = exp->exp_obd;
1737 struct lmv_obd *lmv = &obd->u.lmv;
1738 struct lmv_tgt_desc *tgt;
1739 ldlm_policy_data_t policy = {{0}};
1743 if (!fid_is_sane(fid))
1746 tgt = lmv_find_target(lmv, fid);
1748 RETURN(PTR_ERR(tgt));
1750 if (tgt->ltd_idx != op_tgt) {
1751 CDEBUG(D_INODE, "EARLY_CANCEL on "DFID"\n", PFID(fid));
1752 policy.l_inodebits.bits = bits;
1753 rc = md_cancel_unused(tgt->ltd_exp, fid, &policy,
1754 mode, LCF_ASYNC, NULL);
1757 "EARLY_CANCEL skip operation target %d on "DFID"\n",
1759 op_data->op_flags |= flag;
1767 * llite passes fid of an target inode in op_data->op_fid1 and id of directory in
1770 static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
1771 struct ptlrpc_request **request)
1773 struct obd_device *obd = exp->exp_obd;
1774 struct lmv_obd *lmv = &obd->u.lmv;
1775 struct lmv_tgt_desc *tgt;
1779 rc = lmv_check_connect(obd);
1783 LASSERT(op_data->op_namelen != 0);
1785 CDEBUG(D_INODE, "LINK "DFID":%*s to "DFID"\n",
1786 PFID(&op_data->op_fid2), op_data->op_namelen,
1787 op_data->op_name, PFID(&op_data->op_fid1));
1789 op_data->op_fsuid = cfs_curproc_fsuid();
1790 op_data->op_fsgid = cfs_curproc_fsgid();
1791 op_data->op_cap = cfs_curproc_cap_pack();
1792 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
1794 RETURN(PTR_ERR(tgt));
1797 * Cancel UPDATE lock on child (fid1).
1799 op_data->op_flags |= MF_MDC_CANCEL_FID2;
1800 rc = lmv_early_cancel(exp, op_data, tgt->ltd_idx, LCK_EX,
1801 MDS_INODELOCK_UPDATE, MF_MDC_CANCEL_FID1);
1805 rc = md_link(tgt->ltd_exp, op_data, request);
1810 static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
1811 const char *old, int oldlen, const char *new, int newlen,
1812 struct ptlrpc_request **request)
1814 struct obd_device *obd = exp->exp_obd;
1815 struct lmv_obd *lmv = &obd->u.lmv;
1816 struct lmv_tgt_desc *src_tgt;
1817 struct lmv_tgt_desc *tgt_tgt;
1821 LASSERT(oldlen != 0);
1823 CDEBUG(D_INODE, "RENAME %*s in "DFID" to %*s in "DFID"\n",
1824 oldlen, old, PFID(&op_data->op_fid1),
1825 newlen, new, PFID(&op_data->op_fid2));
1827 rc = lmv_check_connect(obd);
1831 op_data->op_fsuid = cfs_curproc_fsuid();
1832 op_data->op_fsgid = cfs_curproc_fsgid();
1833 op_data->op_cap = cfs_curproc_cap_pack();
1834 src_tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1835 if (IS_ERR(src_tgt))
1836 RETURN(PTR_ERR(src_tgt));
1838 tgt_tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
1839 if (IS_ERR(tgt_tgt))
1840 RETURN(PTR_ERR(tgt_tgt));
1842 * LOOKUP lock on src child (fid3) should also be cancelled for
1843 * src_tgt in mdc_rename.
1845 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
1848 * Cancel UPDATE locks on tgt parent (fid2), tgt_tgt is its
1851 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
1852 LCK_EX, MDS_INODELOCK_UPDATE,
1853 MF_MDC_CANCEL_FID2);
1856 * Cancel LOOKUP locks on tgt child (fid4) for parent tgt_tgt.
1859 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
1860 LCK_EX, MDS_INODELOCK_LOOKUP,
1861 MF_MDC_CANCEL_FID4);
1865 * Cancel all the locks on tgt child (fid4).
1868 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
1869 LCK_EX, MDS_INODELOCK_FULL,
1870 MF_MDC_CANCEL_FID4);
1873 rc = md_rename(src_tgt->ltd_exp, op_data, old, oldlen,
1874 new, newlen, request);
1878 static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
1879 void *ea, int ealen, void *ea2, int ea2len,
1880 struct ptlrpc_request **request,
1881 struct md_open_data **mod)
1883 struct obd_device *obd = exp->exp_obd;
1884 struct lmv_obd *lmv = &obd->u.lmv;
1885 struct lmv_tgt_desc *tgt;
1889 rc = lmv_check_connect(obd);
1893 CDEBUG(D_INODE, "SETATTR for "DFID", valid 0x%x\n",
1894 PFID(&op_data->op_fid1), op_data->op_attr.ia_valid);
1896 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1897 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1899 RETURN(PTR_ERR(tgt));
1901 rc = md_setattr(tgt->ltd_exp, op_data, ea, ealen, ea2,
1902 ea2len, request, mod);
1907 static int lmv_sync(struct obd_export *exp, const struct lu_fid *fid,
1908 struct obd_capa *oc, struct ptlrpc_request **request)
1910 struct obd_device *obd = exp->exp_obd;
1911 struct lmv_obd *lmv = &obd->u.lmv;
1912 struct lmv_tgt_desc *tgt;
1916 rc = lmv_check_connect(obd);
1920 tgt = lmv_find_target(lmv, fid);
1922 RETURN(PTR_ERR(tgt));
1924 rc = md_sync(tgt->ltd_exp, fid, oc, request);
1929 * Adjust a set of pages, each page containing an array of lu_dirpages,
1930 * so that each page can be used as a single logical lu_dirpage.
1932 * A lu_dirpage is laid out as follows, where s = ldp_hash_start,
1933 * e = ldp_hash_end, f = ldp_flags, p = padding, and each "ent" is a
1934 * struct lu_dirent. It has size up to LU_PAGE_SIZE. The ldp_hash_end
1935 * value is used as a cookie to request the next lu_dirpage in a
1936 * directory listing that spans multiple pages (two in this example):
1939 * .|--------v------- -----.
1940 * |s|e|f|p|ent|ent| ... |ent|
1941 * '--|-------------- -----' Each CFS_PAGE contains a single
1942 * '------. lu_dirpage.
1943 * .---------v------- -----.
1944 * |s|e|f|p|ent| 0 | ... | 0 |
1945 * '----------------- -----'
1947 * However, on hosts where the native VM page size (PAGE_CACHE_SIZE) is
1948 * larger than LU_PAGE_SIZE, a single host page may contain multiple
1949 * lu_dirpages. After reading the lu_dirpages from the MDS, the
1950 * ldp_hash_end of the first lu_dirpage refers to the one immediately
1951 * after it in the same CFS_PAGE (arrows simplified for brevity, but
1952 * in general e0==s1, e1==s2, etc.):
1954 * .-------------------- -----.
1955 * |s0|e0|f0|p|ent|ent| ... |ent|
1956 * |---v---------------- -----|
1957 * |s1|e1|f1|p|ent|ent| ... |ent|
1958 * |---v---------------- -----| Here, each CFS_PAGE contains
1959 * ... multiple lu_dirpages.
1960 * |---v---------------- -----|
1961 * |s'|e'|f'|p|ent|ent| ... |ent|
1962 * '---|---------------- -----'
1964 * .----------------------------.
1967 * This structure is transformed into a single logical lu_dirpage as follows:
1969 * - Replace e0 with e' so the request for the next lu_dirpage gets the page
1970 * labeled 'next CFS_PAGE'.
1972 * - Copy the LDF_COLLIDE flag from f' to f0 to correctly reflect whether
1973 * a hash collision with the next page exists.
1975 * - Adjust the lde_reclen of the ending entry of each lu_dirpage to span
1976 * to the first entry of the next lu_dirpage.
1978 #if PAGE_CACHE_SIZE > LU_PAGE_SIZE
1979 static void lmv_adjust_dirpages(struct page **pages, int ncfspgs, int nlupgs)
1983 for (i = 0; i < ncfspgs; i++) {
1984 struct lu_dirpage *dp = kmap(pages[i]);
1985 struct lu_dirpage *first = dp;
1986 struct lu_dirent *end_dirent = NULL;
1987 struct lu_dirent *ent;
1988 __u64 hash_end = dp->ldp_hash_end;
1989 __u32 flags = dp->ldp_flags;
1991 for (; nlupgs > 1; nlupgs--) {
1992 ent = lu_dirent_start(dp);
1993 for (end_dirent = ent; ent != NULL;
1994 end_dirent = ent, ent = lu_dirent_next(ent));
1996 /* Advance dp to next lu_dirpage. */
1997 dp = (struct lu_dirpage *)((char *)dp + LU_PAGE_SIZE);
1999 /* Check if we've reached the end of the CFS_PAGE. */
2000 if (!((unsigned long)dp & ~CFS_PAGE_MASK))
2003 /* Save the hash and flags of this lu_dirpage. */
2004 hash_end = dp->ldp_hash_end;
2005 flags = dp->ldp_flags;
2007 /* Check if lu_dirpage contains no entries. */
2011 /* Enlarge the end entry lde_reclen from 0 to
2012 * first entry of next lu_dirpage. */
2013 LASSERT(le16_to_cpu(end_dirent->lde_reclen) == 0);
2014 end_dirent->lde_reclen =
2015 cpu_to_le16((char *)(dp->ldp_entries) -
2016 (char *)end_dirent);
2019 first->ldp_hash_end = hash_end;
2020 first->ldp_flags &= ~cpu_to_le32(LDF_COLLIDE);
2021 first->ldp_flags |= flags & cpu_to_le32(LDF_COLLIDE);
2027 #define lmv_adjust_dirpages(pages, ncfspgs, nlupgs) do {} while (0)
2028 #endif /* PAGE_CACHE_SIZE > LU_PAGE_SIZE */
2030 static int lmv_readpage(struct obd_export *exp, struct md_op_data *op_data,
2031 struct page **pages, struct ptlrpc_request **request)
2033 struct obd_device *obd = exp->exp_obd;
2034 struct lmv_obd *lmv = &obd->u.lmv;
2035 __u64 offset = op_data->op_offset;
2037 int ncfspgs; /* pages read in PAGE_CACHE_SIZE */
2038 int nlupgs; /* pages read in LU_PAGE_SIZE */
2039 struct lmv_tgt_desc *tgt;
2042 rc = lmv_check_connect(obd);
2046 CDEBUG(D_INODE, "READPAGE at "LPX64" from "DFID"\n",
2047 offset, PFID(&op_data->op_fid1));
2049 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2051 RETURN(PTR_ERR(tgt));
2053 rc = md_readpage(tgt->ltd_exp, op_data, pages, request);
2057 ncfspgs = ((*request)->rq_bulk->bd_nob_transferred +
2058 PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
2059 nlupgs = (*request)->rq_bulk->bd_nob_transferred >> LU_PAGE_SHIFT;
2060 LASSERT(!((*request)->rq_bulk->bd_nob_transferred & ~LU_PAGE_MASK));
2061 LASSERT(ncfspgs > 0 && ncfspgs <= op_data->op_npages);
2063 CDEBUG(D_INODE, "read %d(%d)/%d pages\n", ncfspgs, nlupgs,
2064 op_data->op_npages);
2066 lmv_adjust_dirpages(pages, ncfspgs, nlupgs);
2071 static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
2072 struct ptlrpc_request **request)
2074 struct obd_device *obd = exp->exp_obd;
2075 struct lmv_obd *lmv = &obd->u.lmv;
2076 struct lmv_tgt_desc *tgt = NULL;
2077 struct mdt_body *body;
2081 rc = lmv_check_connect(obd);
2085 /* Send unlink requests to the MDT where the child is located */
2086 if (likely(!fid_is_zero(&op_data->op_fid2)))
2087 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
2089 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
2091 RETURN(PTR_ERR(tgt));
2093 op_data->op_fsuid = cfs_curproc_fsuid();
2094 op_data->op_fsgid = cfs_curproc_fsgid();
2095 op_data->op_cap = cfs_curproc_cap_pack();
2098 * If child's fid is given, cancel unused locks for it if it is from
2099 * another export than parent.
2101 * LOOKUP lock for child (fid3) should also be cancelled on parent
2102 * tgt_tgt in mdc_unlink().
2104 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2107 * Cancel FULL locks on child (fid3).
2109 rc = lmv_early_cancel(exp, op_data, tgt->ltd_idx, LCK_EX,
2110 MDS_INODELOCK_FULL, MF_MDC_CANCEL_FID3);
2115 CDEBUG(D_INODE, "unlink with fid="DFID"/"DFID" -> mds #%d\n",
2116 PFID(&op_data->op_fid1), PFID(&op_data->op_fid2), tgt->ltd_idx);
2118 rc = md_unlink(tgt->ltd_exp, op_data, request);
2119 if (rc != 0 && rc != -EREMOTE)
2122 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
2126 /* Not cross-ref case, just get out of here. */
2127 if (likely(!(body->valid & OBD_MD_MDS)))
2130 CDEBUG(D_INODE, "%s: try unlink to another MDT for "DFID"\n",
2131 exp->exp_obd->obd_name, PFID(&body->fid1));
2133 /* This is a remote object, try remote MDT, Note: it may
2134 * try more than 1 time here, Considering following case
2135 * /mnt/lustre is root on MDT0, remote1 is on MDT1
2136 * 1. Initially A does not know where remote1 is, it send
2137 * unlink RPC to MDT0, MDT0 return -EREMOTE, it will
2138 * resend unlink RPC to MDT1 (retry 1st time).
2140 * 2. During the unlink RPC in flight,
2141 * client B mv /mnt/lustre/remote1 /mnt/lustre/remote2
2142 * and create new remote1, but on MDT0
2144 * 3. MDT1 get unlink RPC(from A), then do remote lock on
2145 * /mnt/lustre, then lookup get fid of remote1, and find
2146 * it is remote dir again, and replay -EREMOTE again.
2148 * 4. Then A will resend unlink RPC to MDT0. (retry 2nd times).
2150 * In theory, it might try unlimited time here, but it should
2151 * be very rare case. */
2152 op_data->op_fid2 = body->fid1;
2153 ptlrpc_req_finished(*request);
2159 static int lmv_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2161 struct lmv_obd *lmv = &obd->u.lmv;
2165 case OBD_CLEANUP_EARLY:
2166 /* XXX: here should be calling obd_precleanup() down to
2169 case OBD_CLEANUP_EXPORTS:
2170 fld_client_proc_fini(&lmv->lmv_fld);
2171 lprocfs_obd_cleanup(obd);
2179 static int lmv_get_info(const struct lu_env *env, struct obd_export *exp,
2180 __u32 keylen, void *key, __u32 *vallen, void *val,
2181 struct lov_stripe_md *lsm)
2183 struct obd_device *obd;
2184 struct lmv_obd *lmv;
2188 obd = class_exp2obd(exp);
2190 CDEBUG(D_IOCTL, "Invalid client cookie "LPX64"\n",
2191 exp->exp_handle.h_cookie);
2196 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
2197 struct lmv_tgt_desc *tgt;
2200 rc = lmv_check_connect(obd);
2204 LASSERT(*vallen == sizeof(__u32));
2205 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2208 * All tgts should be connected when this gets called.
2210 if (tgt == NULL || tgt->ltd_exp == NULL)
2213 if (!obd_get_info(env, tgt->ltd_exp, keylen, key,
2218 } else if (KEY_IS(KEY_MAX_EASIZE) || KEY_IS(KEY_CONN_DATA)) {
2219 rc = lmv_check_connect(obd);
2224 * Forwarding this request to first MDS, it should know LOV
2227 rc = obd_get_info(env, lmv->tgts[0]->ltd_exp, keylen, key,
2229 if (!rc && KEY_IS(KEY_CONN_DATA))
2230 exp->exp_connect_data = *(struct obd_connect_data *)val;
2232 } else if (KEY_IS(KEY_TGT_COUNT)) {
2233 *((int *)val) = lmv->desc.ld_tgt_count;
2237 CDEBUG(D_IOCTL, "Invalid key\n");
2241 int lmv_set_info_async(const struct lu_env *env, struct obd_export *exp,
2242 obd_count keylen, void *key, obd_count vallen,
2243 void *val, struct ptlrpc_request_set *set)
2245 struct lmv_tgt_desc *tgt;
2246 struct obd_device *obd;
2247 struct lmv_obd *lmv;
2251 obd = class_exp2obd(exp);
2253 CDEBUG(D_IOCTL, "Invalid client cookie "LPX64"\n",
2254 exp->exp_handle.h_cookie);
2259 if (KEY_IS(KEY_READ_ONLY) || KEY_IS(KEY_FLUSH_CTX)) {
2262 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2265 if (tgt == NULL || tgt->ltd_exp == NULL)
2268 err = obd_set_info_async(env, tgt->ltd_exp,
2269 keylen, key, vallen, val, set);
2280 int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
2281 struct lov_stripe_md *lsm)
2283 struct obd_device *obd = class_exp2obd(exp);
2284 struct lmv_obd *lmv = &obd->u.lmv;
2285 struct lmv_stripe_md *meap;
2286 struct lmv_stripe_md *lsmp;
2291 mea_size = lmv_get_easize(lmv);
2295 if (*lmmp && !lsm) {
2296 OBD_FREE_LARGE(*lmmp, mea_size);
2301 if (*lmmp == NULL) {
2302 OBD_ALLOC_LARGE(*lmmp, mea_size);
2310 lsmp = (struct lmv_stripe_md *)lsm;
2311 meap = (struct lmv_stripe_md *)*lmmp;
2313 if (lsmp->mea_magic != MEA_MAGIC_LAST_CHAR &&
2314 lsmp->mea_magic != MEA_MAGIC_ALL_CHARS)
2317 meap->mea_magic = cpu_to_le32(lsmp->mea_magic);
2318 meap->mea_count = cpu_to_le32(lsmp->mea_count);
2319 meap->mea_master = cpu_to_le32(lsmp->mea_master);
2321 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2322 meap->mea_ids[i] = lsmp->mea_ids[i];
2323 fid_cpu_to_le(&meap->mea_ids[i], &lsmp->mea_ids[i]);
2329 int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
2330 struct lov_mds_md *lmm, int lmm_size)
2332 struct obd_device *obd = class_exp2obd(exp);
2333 struct lmv_stripe_md **tmea = (struct lmv_stripe_md **)lsmp;
2334 struct lmv_stripe_md *mea = (struct lmv_stripe_md *)lmm;
2335 struct lmv_obd *lmv = &obd->u.lmv;
2341 mea_size = lmv_get_easize(lmv);
2345 if (*lsmp != NULL && lmm == NULL) {
2346 OBD_FREE_LARGE(*tmea, mea_size);
2351 LASSERT(mea_size == lmm_size);
2353 OBD_ALLOC_LARGE(*tmea, mea_size);
2360 if (mea->mea_magic == MEA_MAGIC_LAST_CHAR ||
2361 mea->mea_magic == MEA_MAGIC_ALL_CHARS ||
2362 mea->mea_magic == MEA_MAGIC_HASH_SEGMENT)
2364 magic = le32_to_cpu(mea->mea_magic);
2367 * Old mea is not handled here.
2369 CERROR("Old not supportable EA is found\n");
2373 (*tmea)->mea_magic = magic;
2374 (*tmea)->mea_count = le32_to_cpu(mea->mea_count);
2375 (*tmea)->mea_master = le32_to_cpu(mea->mea_master);
2377 for (i = 0; i < (*tmea)->mea_count; i++) {
2378 (*tmea)->mea_ids[i] = mea->mea_ids[i];
2379 fid_le_to_cpu(&(*tmea)->mea_ids[i], &(*tmea)->mea_ids[i]);
2384 static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
2385 ldlm_policy_data_t *policy, ldlm_mode_t mode,
2386 ldlm_cancel_flags_t flags, void *opaque)
2388 struct obd_device *obd = exp->exp_obd;
2389 struct lmv_obd *lmv = &obd->u.lmv;
2395 LASSERT(fid != NULL);
2397 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2398 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL ||
2399 lmv->tgts[i]->ltd_active == 0)
2402 err = md_cancel_unused(lmv->tgts[i]->ltd_exp, fid,
2403 policy, mode, flags, opaque);
2410 int lmv_set_lock_data(struct obd_export *exp, __u64 *lockh, void *data,
2413 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2417 rc = md_set_lock_data(lmv->tgts[0]->ltd_exp, lockh, data, bits);
2421 ldlm_mode_t lmv_lock_match(struct obd_export *exp, __u64 flags,
2422 const struct lu_fid *fid, ldlm_type_t type,
2423 ldlm_policy_data_t *policy, ldlm_mode_t mode,
2424 struct lustre_handle *lockh)
2426 struct obd_device *obd = exp->exp_obd;
2427 struct lmv_obd *lmv = &obd->u.lmv;
2432 CDEBUG(D_INODE, "Lock match for "DFID"\n", PFID(fid));
2435 * With CMD every object can have two locks in different namespaces:
2436 * lookup lock in space of mds storing direntry and update/open lock in
2437 * space of mds storing inode. Thus we check all targets, not only that
2438 * one fid was created in.
2440 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2441 if (lmv->tgts[i] == NULL ||
2442 lmv->tgts[i]->ltd_exp == NULL ||
2443 lmv->tgts[i]->ltd_active == 0)
2446 rc = md_lock_match(lmv->tgts[i]->ltd_exp, flags, fid,
2447 type, policy, mode, lockh);
2455 int lmv_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
2456 struct obd_export *dt_exp, struct obd_export *md_exp,
2457 struct lustre_md *md)
2459 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2461 return md_get_lustre_md(lmv->tgts[0]->ltd_exp, req, dt_exp, md_exp, md);
2464 int lmv_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
2466 struct obd_device *obd = exp->exp_obd;
2467 struct lmv_obd *lmv = &obd->u.lmv;
2471 obd_free_memmd(exp, (void *)&md->mea);
2472 RETURN(md_free_lustre_md(lmv->tgts[0]->ltd_exp, md));
2475 int lmv_set_open_replay_data(struct obd_export *exp,
2476 struct obd_client_handle *och,
2477 struct ptlrpc_request *open_req)
2479 struct obd_device *obd = exp->exp_obd;
2480 struct lmv_obd *lmv = &obd->u.lmv;
2481 struct lmv_tgt_desc *tgt;
2484 tgt = lmv_find_target(lmv, &och->och_fid);
2486 RETURN(PTR_ERR(tgt));
2488 RETURN(md_set_open_replay_data(tgt->ltd_exp, och, open_req));
2491 int lmv_clear_open_replay_data(struct obd_export *exp,
2492 struct obd_client_handle *och)
2494 struct obd_device *obd = exp->exp_obd;
2495 struct lmv_obd *lmv = &obd->u.lmv;
2496 struct lmv_tgt_desc *tgt;
2499 tgt = lmv_find_target(lmv, &och->och_fid);
2501 RETURN(PTR_ERR(tgt));
2503 RETURN(md_clear_open_replay_data(tgt->ltd_exp, och));
2506 static int lmv_get_remote_perm(struct obd_export *exp,
2507 const struct lu_fid *fid,
2508 struct obd_capa *oc, __u32 suppgid,
2509 struct ptlrpc_request **request)
2511 struct obd_device *obd = exp->exp_obd;
2512 struct lmv_obd *lmv = &obd->u.lmv;
2513 struct lmv_tgt_desc *tgt;
2517 rc = lmv_check_connect(obd);
2521 tgt = lmv_find_target(lmv, fid);
2523 RETURN(PTR_ERR(tgt));
2525 rc = md_get_remote_perm(tgt->ltd_exp, fid, oc, suppgid, request);
2529 static int lmv_renew_capa(struct obd_export *exp, struct obd_capa *oc,
2532 struct obd_device *obd = exp->exp_obd;
2533 struct lmv_obd *lmv = &obd->u.lmv;
2534 struct lmv_tgt_desc *tgt;
2538 rc = lmv_check_connect(obd);
2542 tgt = lmv_find_target(lmv, &oc->c_capa.lc_fid);
2544 RETURN(PTR_ERR(tgt));
2546 rc = md_renew_capa(tgt->ltd_exp, oc, cb);
2550 int lmv_unpack_capa(struct obd_export *exp, struct ptlrpc_request *req,
2551 const struct req_msg_field *field, struct obd_capa **oc)
2553 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2555 return md_unpack_capa(lmv->tgts[0]->ltd_exp, req, field, oc);
2558 int lmv_intent_getattr_async(struct obd_export *exp,
2559 struct md_enqueue_info *minfo,
2560 struct ldlm_enqueue_info *einfo)
2562 struct md_op_data *op_data = &minfo->mi_data;
2563 struct obd_device *obd = exp->exp_obd;
2564 struct lmv_obd *lmv = &obd->u.lmv;
2565 struct lmv_tgt_desc *tgt = NULL;
2569 rc = lmv_check_connect(obd);
2573 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2575 RETURN(PTR_ERR(tgt));
2577 rc = md_intent_getattr_async(tgt->ltd_exp, minfo, einfo);
2581 int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
2582 struct lu_fid *fid, __u64 *bits)
2584 struct obd_device *obd = exp->exp_obd;
2585 struct lmv_obd *lmv = &obd->u.lmv;
2586 struct lmv_tgt_desc *tgt;
2590 rc = lmv_check_connect(obd);
2594 tgt = lmv_find_target(lmv, fid);
2596 RETURN(PTR_ERR(tgt));
2598 rc = md_revalidate_lock(tgt->ltd_exp, it, fid, bits);
2603 * For lmv, only need to send request to master MDT, and the master MDT will
2604 * process with other slave MDTs. The only exception is Q_GETOQUOTA for which
2605 * we directly fetch data from the slave MDTs.
2607 int lmv_quotactl(struct obd_device *unused, struct obd_export *exp,
2608 struct obd_quotactl *oqctl)
2610 struct obd_device *obd = class_exp2obd(exp);
2611 struct lmv_obd *lmv = &obd->u.lmv;
2612 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2614 __u64 curspace, curinodes;
2617 if (!lmv->desc.ld_tgt_count || !tgt->ltd_active) {
2618 CERROR("master lmv inactive\n");
2622 if (oqctl->qc_cmd != Q_GETOQUOTA) {
2623 rc = obd_quotactl(tgt->ltd_exp, oqctl);
2627 curspace = curinodes = 0;
2628 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2632 if (tgt == NULL || tgt->ltd_exp == NULL || tgt->ltd_active == 0)
2634 if (!tgt->ltd_active) {
2635 CDEBUG(D_HA, "mdt %d is inactive.\n", i);
2639 err = obd_quotactl(tgt->ltd_exp, oqctl);
2641 CERROR("getquota on mdt %d failed. %d\n", i, err);
2645 curspace += oqctl->qc_dqblk.dqb_curspace;
2646 curinodes += oqctl->qc_dqblk.dqb_curinodes;
2649 oqctl->qc_dqblk.dqb_curspace = curspace;
2650 oqctl->qc_dqblk.dqb_curinodes = curinodes;
2655 int lmv_quotacheck(struct obd_device *unused, struct obd_export *exp,
2656 struct obd_quotactl *oqctl)
2658 struct obd_device *obd = class_exp2obd(exp);
2659 struct lmv_obd *lmv = &obd->u.lmv;
2660 struct lmv_tgt_desc *tgt;
2664 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2667 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active) {
2668 CERROR("lmv idx %d inactive\n", i);
2672 err = obd_quotacheck(tgt->ltd_exp, oqctl);
2680 struct obd_ops lmv_obd_ops = {
2681 .o_owner = THIS_MODULE,
2682 .o_setup = lmv_setup,
2683 .o_cleanup = lmv_cleanup,
2684 .o_precleanup = lmv_precleanup,
2685 .o_process_config = lmv_process_config,
2686 .o_connect = lmv_connect,
2687 .o_disconnect = lmv_disconnect,
2688 .o_statfs = lmv_statfs,
2689 .o_get_info = lmv_get_info,
2690 .o_set_info_async = lmv_set_info_async,
2691 .o_packmd = lmv_packmd,
2692 .o_unpackmd = lmv_unpackmd,
2693 .o_notify = lmv_notify,
2694 .o_get_uuid = lmv_get_uuid,
2695 .o_iocontrol = lmv_iocontrol,
2696 .o_quotacheck = lmv_quotacheck,
2697 .o_quotactl = lmv_quotactl
2700 struct md_ops lmv_md_ops = {
2701 .m_getstatus = lmv_getstatus,
2702 .m_null_inode = lmv_null_inode,
2703 .m_find_cbdata = lmv_find_cbdata,
2704 .m_close = lmv_close,
2705 .m_create = lmv_create,
2706 .m_done_writing = lmv_done_writing,
2707 .m_enqueue = lmv_enqueue,
2708 .m_getattr = lmv_getattr,
2709 .m_getxattr = lmv_getxattr,
2710 .m_getattr_name = lmv_getattr_name,
2711 .m_intent_lock = lmv_intent_lock,
2713 .m_rename = lmv_rename,
2714 .m_setattr = lmv_setattr,
2715 .m_setxattr = lmv_setxattr,
2717 .m_readpage = lmv_readpage,
2718 .m_unlink = lmv_unlink,
2719 .m_init_ea_size = lmv_init_ea_size,
2720 .m_cancel_unused = lmv_cancel_unused,
2721 .m_set_lock_data = lmv_set_lock_data,
2722 .m_lock_match = lmv_lock_match,
2723 .m_get_lustre_md = lmv_get_lustre_md,
2724 .m_free_lustre_md = lmv_free_lustre_md,
2725 .m_set_open_replay_data = lmv_set_open_replay_data,
2726 .m_clear_open_replay_data = lmv_clear_open_replay_data,
2727 .m_renew_capa = lmv_renew_capa,
2728 .m_unpack_capa = lmv_unpack_capa,
2729 .m_get_remote_perm = lmv_get_remote_perm,
2730 .m_intent_getattr_async = lmv_intent_getattr_async,
2731 .m_revalidate_lock = lmv_revalidate_lock
2734 int __init lmv_init(void)
2736 struct lprocfs_static_vars lvars;
2739 lprocfs_lmv_init_vars(&lvars);
2741 rc = class_register_type(&lmv_obd_ops, &lmv_md_ops,
2742 lvars.module_vars, LUSTRE_LMV_NAME, NULL);
2747 static void lmv_exit(void)
2749 class_unregister_type(LUSTRE_LMV_NAME);
2752 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2753 MODULE_DESCRIPTION("Lustre Logical Metadata Volume OBD driver");
2754 MODULE_LICENSE("GPL");
2756 module_init(lmv_init);
2757 module_exit(lmv_exit);