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, 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_LMV
38 #include <linux/slab.h>
39 #include <linux/module.h>
40 #include <linux/init.h>
41 #include <linux/slab.h>
42 #include <linux/pagemap.h>
44 #include <asm/div64.h>
45 #include <linux/seq_file.h>
46 #include <linux/namei.h>
48 #include <lustre/lustre_idl.h>
49 #include <obd_support.h>
50 #include <lustre_lib.h>
51 #include <lustre_net.h>
52 #include <obd_class.h>
53 #include <lprocfs_status.h>
54 #include <lustre_lite.h>
55 #include <lustre_fid.h>
56 #include "lmv_internal.h"
58 static void lmv_activate_target(struct lmv_obd *lmv,
59 struct lmv_tgt_desc *tgt,
62 if (tgt->ltd_active == activate)
65 tgt->ltd_active = activate;
66 lmv->desc.ld_active_tgt_count += (activate ? 1 : -1);
72 * -EINVAL : UUID can't be found in the LMV's target list
73 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
74 * -EBADF : The UUID is found, but the OBD of the wrong type (!)
76 static int lmv_set_mdc_active(struct lmv_obd *lmv, struct obd_uuid *uuid,
79 struct lmv_tgt_desc *uninitialized_var(tgt);
80 struct obd_device *obd;
85 CDEBUG(D_INFO, "Searching in lmv %p for uuid %s (activate=%d)\n",
86 lmv, uuid->uuid, activate);
88 spin_lock(&lmv->lmv_lock);
89 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
91 if (tgt == NULL || tgt->ltd_exp == NULL)
94 CDEBUG(D_INFO, "Target idx %d is %s conn "LPX64"\n", i,
95 tgt->ltd_uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
97 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
101 if (i == lmv->desc.ld_tgt_count)
102 GOTO(out_lmv_lock, rc = -EINVAL);
104 obd = class_exp2obd(tgt->ltd_exp);
106 GOTO(out_lmv_lock, rc = -ENOTCONN);
108 CDEBUG(D_INFO, "Found OBD %s=%s device %d (%p) type %s at LMV idx %d\n",
109 obd->obd_name, obd->obd_uuid.uuid, obd->obd_minor, obd,
110 obd->obd_type->typ_name, i);
111 LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0);
113 if (tgt->ltd_active == activate) {
114 CDEBUG(D_INFO, "OBD %p already %sactive!\n", obd,
115 activate ? "" : "in");
116 GOTO(out_lmv_lock, rc);
119 CDEBUG(D_INFO, "Marking OBD %p %sactive\n", obd,
120 activate ? "" : "in");
121 lmv_activate_target(lmv, tgt, activate);
125 spin_unlock(&lmv->lmv_lock);
129 struct obd_uuid *lmv_get_uuid(struct obd_export *exp)
131 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
133 return obd_get_uuid(lmv->tgts[0]->ltd_exp);
136 static int lmv_notify(struct obd_device *obd, struct obd_device *watched,
137 enum obd_notify_event ev, void *data)
139 struct obd_connect_data *conn_data;
140 struct lmv_obd *lmv = &obd->u.lmv;
141 struct obd_uuid *uuid;
145 if (strcmp(watched->obd_type->typ_name, LUSTRE_MDC_NAME)) {
146 CERROR("unexpected notification of %s %s!\n",
147 watched->obd_type->typ_name,
152 uuid = &watched->u.cli.cl_target_uuid;
153 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE) {
155 * Set MDC as active before notifying the observer, so the
156 * observer can use the MDC normally.
158 rc = lmv_set_mdc_active(lmv, uuid,
159 ev == OBD_NOTIFY_ACTIVE);
161 CERROR("%sactivation of %s failed: %d\n",
162 ev == OBD_NOTIFY_ACTIVE ? "" : "de",
166 } else if (ev == OBD_NOTIFY_OCD) {
167 conn_data = &watched->u.cli.cl_import->imp_connect_data;
169 * XXX: Make sure that ocd_connect_flags from all targets are
170 * the same. Otherwise one of MDTs runs wrong version or
171 * something like this. --umka
173 obd->obd_self_export->exp_connect_data = *conn_data;
176 else if (ev == OBD_NOTIFY_DISCON) {
178 * For disconnect event, flush fld cache for failout MDS case.
180 fld_client_flush(&lmv->lmv_fld);
184 * Pass the notification up the chain.
186 if (obd->obd_observer)
187 rc = obd_notify(obd->obd_observer, watched, ev, data);
193 * This is fake connect function. Its purpose is to initialize lmv and say
194 * caller that everything is okay. Real connection will be performed later.
196 static int lmv_connect(const struct lu_env *env,
197 struct obd_export **exp, struct obd_device *obd,
198 struct obd_uuid *cluuid, struct obd_connect_data *data,
201 struct proc_dir_entry *lmv_proc_dir;
202 struct lmv_obd *lmv = &obd->u.lmv;
203 struct lustre_handle conn = { 0 };
208 * We don't want to actually do the underlying connections more than
209 * once, so keep track.
212 if (lmv->refcount > 1) {
217 rc = class_connect(&conn, obd, cluuid);
219 CERROR("class_connection() returned %d\n", rc);
223 *exp = class_conn2export(&conn);
224 class_export_get(*exp);
228 lmv->cluuid = *cluuid;
231 lmv->conn_data = *data;
233 if (obd->obd_proc_private != NULL) {
234 lmv_proc_dir = obd->obd_proc_private;
236 lmv_proc_dir = lprocfs_register("target_obds", obd->obd_proc_entry,
238 if (IS_ERR(lmv_proc_dir)) {
239 CERROR("could not register /proc/fs/lustre/%s/%s/target_obds.",
240 obd->obd_type->typ_name, obd->obd_name);
243 obd->obd_proc_private = lmv_proc_dir;
247 * All real clients should perform actual connection right away, because
248 * it is possible, that LMV will not have opportunity to connect targets
249 * and MDC stuff will be called directly, for instance while reading
250 * ../mdc/../kbytesfree procfs file, etc.
252 if (data->ocd_connect_flags & OBD_CONNECT_REAL)
253 rc = lmv_check_connect(obd);
255 if (rc && lmv_proc_dir) {
256 lprocfs_remove(&lmv_proc_dir);
257 obd->obd_proc_private = NULL;
263 static void lmv_set_timeouts(struct obd_device *obd)
265 struct lmv_tgt_desc *tgt;
270 if (lmv->server_timeout == 0)
273 if (lmv->connected == 0)
276 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
278 if (tgt == NULL || tgt->ltd_exp == NULL || tgt->ltd_active == 0)
281 obd_set_info_async(NULL, tgt->ltd_exp, sizeof(KEY_INTERMDS),
282 KEY_INTERMDS, 0, NULL, NULL);
286 static int lmv_init_ea_size(struct obd_export *exp, int easize,
287 int def_easize, int cookiesize)
289 struct obd_device *obd = exp->exp_obd;
290 struct lmv_obd *lmv = &obd->u.lmv;
296 if (lmv->max_easize < easize) {
297 lmv->max_easize = easize;
300 if (lmv->max_def_easize < def_easize) {
301 lmv->max_def_easize = def_easize;
304 if (lmv->max_cookiesize < cookiesize) {
305 lmv->max_cookiesize = cookiesize;
311 if (lmv->connected == 0)
314 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
315 if (lmv->tgts[i] == NULL ||
316 lmv->tgts[i]->ltd_exp == NULL ||
317 lmv->tgts[i]->ltd_active == 0) {
318 CWARN("%s: NULL export for %d\n", obd->obd_name, i);
322 rc = md_init_ea_size(lmv->tgts[i]->ltd_exp, easize, def_easize,
325 CERROR("%s: obd_init_ea_size() failed on MDT target %d:"
326 " rc = %d.\n", obd->obd_name, i, rc);
333 #define MAX_STRING_SIZE 128
335 int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
337 struct proc_dir_entry *lmv_proc_dir;
338 struct lmv_obd *lmv = &obd->u.lmv;
339 struct obd_uuid *cluuid = &lmv->cluuid;
340 struct obd_uuid lmv_mdc_uuid = { "LMV_MDC_UUID" };
341 struct obd_device *mdc_obd;
342 struct obd_export *mdc_exp;
343 struct lu_fld_target target;
347 mdc_obd = class_find_client_obd(&tgt->ltd_uuid, LUSTRE_MDC_NAME,
350 CERROR("target %s not attached\n", tgt->ltd_uuid.uuid);
354 CDEBUG(D_CONFIG, "connect to %s(%s) - %s, %s FOR %s\n",
355 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
356 tgt->ltd_uuid.uuid, obd->obd_uuid.uuid,
359 if (!mdc_obd->obd_set_up) {
360 CERROR("target %s is not set up\n", tgt->ltd_uuid.uuid);
364 rc = obd_connect(NULL, &mdc_exp, mdc_obd, &lmv_mdc_uuid,
365 &lmv->conn_data, NULL);
367 CERROR("target %s connect error %d\n", tgt->ltd_uuid.uuid, rc);
372 * Init fid sequence client for this mdc and add new fld target.
374 rc = obd_fid_init(mdc_obd, mdc_exp, LUSTRE_SEQ_METADATA);
378 target.ft_srv = NULL;
379 target.ft_exp = mdc_exp;
380 target.ft_idx = tgt->ltd_idx;
382 fld_client_add_target(&lmv->lmv_fld, &target);
384 rc = obd_register_observer(mdc_obd, obd);
386 obd_disconnect(mdc_exp);
387 CERROR("target %s register_observer error %d\n",
388 tgt->ltd_uuid.uuid, rc);
392 if (obd->obd_observer) {
394 * Tell the observer about the new target.
396 rc = obd_notify(obd->obd_observer, mdc_exp->exp_obd,
398 (void *)(tgt - lmv->tgts[0]));
400 obd_disconnect(mdc_exp);
406 tgt->ltd_exp = mdc_exp;
407 lmv->desc.ld_active_tgt_count++;
409 md_init_ea_size(tgt->ltd_exp, lmv->max_easize,
410 lmv->max_def_easize, lmv->max_cookiesize);
412 CDEBUG(D_CONFIG, "Connected to %s(%s) successfully (%d)\n",
413 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
414 atomic_read(&obd->obd_refcount));
416 lmv_proc_dir = obd->obd_proc_private;
418 struct proc_dir_entry *mdc_symlink;
420 LASSERT(mdc_obd->obd_type != NULL);
421 LASSERT(mdc_obd->obd_type->typ_name != NULL);
422 mdc_symlink = lprocfs_add_symlink(mdc_obd->obd_name,
425 mdc_obd->obd_type->typ_name,
427 if (mdc_symlink == NULL) {
428 CERROR("Could not register LMV target "
429 "/proc/fs/lustre/%s/%s/target_obds/%s.",
430 obd->obd_type->typ_name, obd->obd_name,
432 lprocfs_remove(&lmv_proc_dir);
433 obd->obd_proc_private = NULL;
439 static void lmv_del_target(struct lmv_obd *lmv, int index)
441 if (lmv->tgts[index] == NULL)
444 OBD_FREE_PTR(lmv->tgts[index]);
445 lmv->tgts[index] = NULL;
449 static int lmv_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
450 __u32 index, int gen)
452 struct lmv_obd *lmv = &obd->u.lmv;
453 struct lmv_tgt_desc *tgt;
457 CDEBUG(D_CONFIG, "Target uuid: %s. index %d\n", uuidp->uuid, index);
461 if (lmv->desc.ld_tgt_count == 0) {
462 struct obd_device *mdc_obd;
464 mdc_obd = class_find_client_obd(uuidp, LUSTRE_MDC_NAME,
467 lmv_init_unlock(lmv);
468 CERROR("%s: Target %s not attached: rc = %d\n",
469 obd->obd_name, uuidp->uuid, -EINVAL);
474 if ((index < lmv->tgts_size) && (lmv->tgts[index] != NULL)) {
475 tgt = lmv->tgts[index];
476 CERROR("%s: UUID %s already assigned at LOV target index %d:"
477 " rc = %d\n", obd->obd_name,
478 obd_uuid2str(&tgt->ltd_uuid), index, -EEXIST);
479 lmv_init_unlock(lmv);
483 if (index >= lmv->tgts_size) {
484 /* We need to reallocate the lmv target array. */
485 struct lmv_tgt_desc **newtgts, **old = NULL;
489 while (newsize < index + 1)
490 newsize = newsize << 1;
491 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
492 if (newtgts == NULL) {
493 lmv_init_unlock(lmv);
497 if (lmv->tgts_size) {
498 memcpy(newtgts, lmv->tgts,
499 sizeof(*newtgts) * lmv->tgts_size);
501 oldsize = lmv->tgts_size;
505 lmv->tgts_size = newsize;
508 OBD_FREE(old, sizeof(*old) * oldsize);
510 CDEBUG(D_CONFIG, "tgts: %p size: %d\n", lmv->tgts,
516 lmv_init_unlock(lmv);
520 mutex_init(&tgt->ltd_fid_mutex);
521 tgt->ltd_idx = index;
522 tgt->ltd_uuid = *uuidp;
524 lmv->tgts[index] = tgt;
525 if (index >= lmv->desc.ld_tgt_count)
526 lmv->desc.ld_tgt_count = index + 1;
528 if (lmv->connected) {
529 rc = lmv_connect_mdc(obd, tgt);
531 spin_lock(&lmv->lmv_lock);
532 lmv->desc.ld_tgt_count--;
533 memset(tgt, 0, sizeof(*tgt));
534 spin_unlock(&lmv->lmv_lock);
536 int easize = sizeof(struct lmv_stripe_md) +
537 lmv->desc.ld_tgt_count *
538 sizeof(struct lu_fid);
539 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0);
543 lmv_init_unlock(lmv);
547 int lmv_check_connect(struct obd_device *obd)
549 struct lmv_obd *lmv = &obd->u.lmv;
550 struct lmv_tgt_desc *tgt;
560 if (lmv->connected) {
561 lmv_init_unlock(lmv);
565 if (lmv->desc.ld_tgt_count == 0) {
566 lmv_init_unlock(lmv);
567 CERROR("%s: no targets configured.\n", obd->obd_name);
571 CDEBUG(D_CONFIG, "Time to connect %s to %s\n",
572 lmv->cluuid.uuid, obd->obd_name);
574 LASSERT(lmv->tgts != NULL);
576 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
580 rc = lmv_connect_mdc(obd, tgt);
585 lmv_set_timeouts(obd);
586 class_export_put(lmv->exp);
588 easize = lmv_get_easize(lmv);
589 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0);
590 lmv_init_unlock(lmv);
601 --lmv->desc.ld_active_tgt_count;
602 rc2 = obd_disconnect(tgt->ltd_exp);
604 CERROR("LMV target %s disconnect on "
605 "MDC idx %d: error %d\n",
606 tgt->ltd_uuid.uuid, i, rc2);
610 class_disconnect(lmv->exp);
611 lmv_init_unlock(lmv);
615 static int lmv_disconnect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
617 struct proc_dir_entry *lmv_proc_dir;
618 struct lmv_obd *lmv = &obd->u.lmv;
619 struct obd_device *mdc_obd;
623 LASSERT(tgt != NULL);
624 LASSERT(obd != NULL);
626 mdc_obd = class_exp2obd(tgt->ltd_exp);
629 mdc_obd->obd_force = obd->obd_force;
630 mdc_obd->obd_fail = obd->obd_fail;
631 mdc_obd->obd_no_recov = obd->obd_no_recov;
634 lmv_proc_dir = obd->obd_proc_private;
636 lprocfs_remove_proc_entry(mdc_obd->obd_name, lmv_proc_dir);
638 rc = obd_fid_fini(tgt->ltd_exp->exp_obd);
640 CERROR("Can't finanize fids factory\n");
642 CDEBUG(D_INFO, "Disconnected from %s(%s) successfully\n",
643 tgt->ltd_exp->exp_obd->obd_name,
644 tgt->ltd_exp->exp_obd->obd_uuid.uuid);
646 obd_register_observer(tgt->ltd_exp->exp_obd, NULL);
647 rc = obd_disconnect(tgt->ltd_exp);
649 if (tgt->ltd_active) {
650 CERROR("Target %s disconnect error %d\n",
651 tgt->ltd_uuid.uuid, rc);
655 lmv_activate_target(lmv, tgt, 0);
660 static int lmv_disconnect(struct obd_export *exp)
662 struct obd_device *obd = class_exp2obd(exp);
663 struct lmv_obd *lmv = &obd->u.lmv;
672 * Only disconnect the underlying layers on the final disconnect.
675 if (lmv->refcount != 0)
678 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
679 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
682 lmv_disconnect_mdc(obd, lmv->tgts[i]);
685 if (obd->obd_proc_private)
686 lprocfs_remove((proc_dir_entry_t **)&obd->obd_proc_private);
688 CERROR("/proc/fs/lustre/%s/%s/target_obds missing\n",
689 obd->obd_type->typ_name, obd->obd_name);
693 * This is the case when no real connection is established by
694 * lmv_check_connect().
697 class_export_put(exp);
698 rc = class_disconnect(exp);
699 if (lmv->refcount == 0)
704 static int lmv_fid2path(struct obd_export *exp, int len, void *karg, void *uarg)
706 struct obd_device *obddev = class_exp2obd(exp);
707 struct lmv_obd *lmv = &obddev->u.lmv;
708 struct getinfo_fid2path *gf;
709 struct lmv_tgt_desc *tgt;
710 struct getinfo_fid2path *remote_gf = NULL;
711 int remote_gf_size = 0;
714 gf = (struct getinfo_fid2path *)karg;
715 tgt = lmv_find_target(lmv, &gf->gf_fid);
717 RETURN(PTR_ERR(tgt));
720 rc = obd_iocontrol(OBD_IOC_FID2PATH, tgt->ltd_exp, len, gf, uarg);
721 if (rc != 0 && rc != -EREMOTE)
722 GOTO(out_fid2path, rc);
724 /* If remote_gf != NULL, it means just building the
725 * path on the remote MDT, copy this path segement to gf */
726 if (remote_gf != NULL) {
727 struct getinfo_fid2path *ori_gf;
730 ori_gf = (struct getinfo_fid2path *)karg;
731 if (strlen(ori_gf->gf_path) +
732 strlen(gf->gf_path) > ori_gf->gf_pathlen)
733 GOTO(out_fid2path, rc = -EOVERFLOW);
735 ptr = ori_gf->gf_path;
737 memmove(ptr + strlen(gf->gf_path) + 1, ptr,
738 strlen(ori_gf->gf_path));
740 strncpy(ptr, gf->gf_path, strlen(gf->gf_path));
741 ptr += strlen(gf->gf_path);
745 CDEBUG(D_INFO, "%s: get path %s "DFID" rec: "LPU64" ln: %u\n",
746 tgt->ltd_exp->exp_obd->obd_name,
747 gf->gf_path, PFID(&gf->gf_fid), gf->gf_recno,
751 GOTO(out_fid2path, rc);
753 /* sigh, has to go to another MDT to do path building further */
754 if (remote_gf == NULL) {
755 remote_gf_size = sizeof(*remote_gf) + PATH_MAX;
756 OBD_ALLOC(remote_gf, remote_gf_size);
757 if (remote_gf == NULL)
758 GOTO(out_fid2path, rc = -ENOMEM);
759 remote_gf->gf_pathlen = PATH_MAX;
762 if (!fid_is_sane(&gf->gf_fid)) {
763 CERROR("%s: invalid FID "DFID": rc = %d\n",
764 tgt->ltd_exp->exp_obd->obd_name,
765 PFID(&gf->gf_fid), -EINVAL);
766 GOTO(out_fid2path, rc = -EINVAL);
769 tgt = lmv_find_target(lmv, &gf->gf_fid);
771 GOTO(out_fid2path, rc = -EINVAL);
773 remote_gf->gf_fid = gf->gf_fid;
774 remote_gf->gf_recno = -1;
775 remote_gf->gf_linkno = -1;
776 memset(remote_gf->gf_path, 0, remote_gf->gf_pathlen);
778 goto repeat_fid2path;
781 if (remote_gf != NULL)
782 OBD_FREE(remote_gf, remote_gf_size);
786 static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
787 int len, void *karg, void *uarg)
789 struct obd_device *obddev = class_exp2obd(exp);
790 struct lmv_obd *lmv = &obddev->u.lmv;
794 int count = lmv->desc.ld_tgt_count;
801 case IOC_OBD_STATFS: {
802 struct obd_ioctl_data *data = karg;
803 struct obd_device *mdc_obd;
804 struct obd_statfs stat_buf = {0};
807 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
808 if ((index >= count))
811 if (lmv->tgts[index] == NULL ||
812 lmv->tgts[index]->ltd_active == 0)
815 mdc_obd = class_exp2obd(lmv->tgts[index]->ltd_exp);
820 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(mdc_obd),
821 min((int) data->ioc_plen2,
822 (int) sizeof(struct obd_uuid))))
825 rc = obd_statfs(NULL, lmv->tgts[index]->ltd_exp, &stat_buf,
826 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
830 if (copy_to_user(data->ioc_pbuf1, &stat_buf,
831 min((int) data->ioc_plen1,
832 (int) sizeof(stat_buf))))
836 case OBD_IOC_QUOTACTL: {
837 struct if_quotactl *qctl = karg;
838 struct lmv_tgt_desc *tgt = NULL;
839 struct obd_quotactl *oqctl;
841 if (qctl->qc_valid == QC_MDTIDX) {
842 if (qctl->qc_idx < 0 || count <= qctl->qc_idx)
845 tgt = lmv->tgts[qctl->qc_idx];
846 if (tgt == NULL || tgt->ltd_exp == NULL)
848 } else if (qctl->qc_valid == QC_UUID) {
849 for (i = 0; i < count; i++) {
853 if (!obd_uuid_equals(&tgt->ltd_uuid,
857 if (tgt->ltd_exp == NULL)
869 LASSERT(tgt && tgt->ltd_exp);
870 OBD_ALLOC_PTR(oqctl);
874 QCTL_COPY(oqctl, qctl);
875 rc = obd_quotactl(tgt->ltd_exp, oqctl);
877 QCTL_COPY(qctl, oqctl);
878 qctl->qc_valid = QC_MDTIDX;
879 qctl->obd_uuid = tgt->ltd_uuid;
884 case OBD_IOC_CHANGELOG_SEND:
885 case OBD_IOC_CHANGELOG_CLEAR: {
886 struct ioc_changelog *icc = karg;
888 if (icc->icc_mdtindex >= count)
891 if (lmv->tgts[icc->icc_mdtindex] == NULL ||
892 lmv->tgts[icc->icc_mdtindex]->ltd_exp == NULL ||
893 lmv->tgts[icc->icc_mdtindex]->ltd_active == 0)
895 rc = obd_iocontrol(cmd, lmv->tgts[icc->icc_mdtindex]->ltd_exp,
896 sizeof(*icc), icc, NULL);
899 case LL_IOC_GET_CONNECT_FLAGS: {
900 if (lmv->tgts[0] == NULL)
902 rc = obd_iocontrol(cmd, lmv->tgts[0]->ltd_exp, len, karg, uarg);
905 case OBD_IOC_FID2PATH: {
906 rc = lmv_fid2path(exp, len, karg, uarg);
909 case LL_IOC_HSM_STATE_GET:
910 case LL_IOC_HSM_STATE_SET:
911 case LL_IOC_HSM_ACTION:
912 case LL_IOC_LOV_SWAP_LAYOUTS: {
913 struct md_op_data *op_data = karg;
914 struct lmv_tgt_desc *tgt1, *tgt2;
916 tgt1 = lmv_find_target(lmv, &op_data->op_fid1);
918 RETURN(PTR_ERR(tgt1));
920 tgt2 = lmv_find_target(lmv, &op_data->op_fid2);
922 RETURN(PTR_ERR(tgt2));
924 if ((tgt1->ltd_exp == NULL) || (tgt2->ltd_exp == NULL))
927 /* only files on same MDT can have their layouts swapped */
928 if (tgt1->ltd_idx != tgt2->ltd_idx)
931 rc = obd_iocontrol(cmd, tgt1->ltd_exp, len, karg, uarg);
935 for (i = 0; i < count; i++) {
936 struct obd_device *mdc_obd;
939 if (lmv->tgts[i] == NULL ||
940 lmv->tgts[i]->ltd_exp == NULL)
942 /* ll_umount_begin() sets force flag but for lmv, not
943 * mdc. Let's pass it through */
944 mdc_obd = class_exp2obd(lmv->tgts[i]->ltd_exp);
945 mdc_obd->obd_force = obddev->obd_force;
946 err = obd_iocontrol(cmd, lmv->tgts[i]->ltd_exp, len,
948 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
951 if (lmv->tgts[i]->ltd_active) {
952 CERROR("error: iocontrol MDC %s on MDT"
953 "idx %d cmd %x: err = %d\n",
954 lmv->tgts[i]->ltd_uuid.uuid,
969 static int lmv_all_chars_policy(int count, const char *name,
980 static int lmv_nid_policy(struct lmv_obd *lmv)
982 struct obd_import *imp;
986 * XXX: To get nid we assume that underlying obd device is mdc.
988 imp = class_exp2cliimp(lmv->tgts[0].ltd_exp);
989 id = imp->imp_connection->c_self ^ (imp->imp_connection->c_self >> 32);
990 return id % lmv->desc.ld_tgt_count;
993 static int lmv_choose_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
994 placement_policy_t placement)
997 case PLACEMENT_CHAR_POLICY:
998 return lmv_all_chars_policy(lmv->desc.ld_tgt_count,
1000 op_data->op_namelen);
1001 case PLACEMENT_NID_POLICY:
1002 return lmv_nid_policy(lmv);
1008 CERROR("Unsupported placement policy %x\n", placement);
1014 * This is _inode_ placement policy function (not name).
1016 static int lmv_placement_policy(struct obd_device *obd,
1017 struct md_op_data *op_data,
1020 struct lmv_obd *lmv = &obd->u.lmv;
1023 LASSERT(mds != NULL);
1025 if (lmv->desc.ld_tgt_count == 1) {
1031 * If stripe_offset is provided during setdirstripe
1032 * (setdirstripe -i xx), xx MDS will be choosen.
1034 if (op_data->op_cli_flags & CLI_SET_MEA) {
1035 struct lmv_user_md *lum;
1037 lum = (struct lmv_user_md *)op_data->op_data;
1038 if (lum->lum_type == LMV_STRIPE_TYPE &&
1039 lum->lum_stripe_offset != -1) {
1040 if (lum->lum_stripe_offset >= lmv->desc.ld_tgt_count) {
1041 CERROR("%s: Stripe_offset %d > MDT count %d:"
1042 " rc = %d\n", obd->obd_name,
1043 lum->lum_stripe_offset,
1044 lmv->desc.ld_tgt_count, -ERANGE);
1047 *mds = lum->lum_stripe_offset;
1052 /* Allocate new fid on target according to operation type and parent
1054 *mds = op_data->op_mds;
1058 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid,
1061 struct lmv_tgt_desc *tgt;
1065 tgt = lmv_get_target(lmv, mds);
1067 RETURN(PTR_ERR(tgt));
1070 * New seq alloc and FLD setup should be atomic. Otherwise we may find
1071 * on server that seq in new allocated fid is not yet known.
1073 mutex_lock(&tgt->ltd_fid_mutex);
1075 if (tgt->ltd_active == 0 || tgt->ltd_exp == NULL)
1076 GOTO(out, rc = -ENODEV);
1079 * Asking underlaying tgt layer to allocate new fid.
1081 rc = obd_fid_alloc(tgt->ltd_exp, fid, NULL);
1083 LASSERT(fid_is_sane(fid));
1089 mutex_unlock(&tgt->ltd_fid_mutex);
1093 int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
1094 struct md_op_data *op_data)
1096 struct obd_device *obd = class_exp2obd(exp);
1097 struct lmv_obd *lmv = &obd->u.lmv;
1102 LASSERT(op_data != NULL);
1103 LASSERT(fid != NULL);
1105 rc = lmv_placement_policy(obd, op_data, &mds);
1107 CERROR("Can't get target for allocating fid, "
1112 rc = __lmv_fid_alloc(lmv, fid, mds);
1114 CERROR("Can't alloc new fid, rc %d\n", rc);
1121 static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
1123 struct lmv_obd *lmv = &obd->u.lmv;
1124 struct lprocfs_static_vars lvars;
1125 struct lmv_desc *desc;
1129 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
1130 CERROR("LMV setup requires a descriptor\n");
1134 desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1);
1135 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
1136 CERROR("Lmv descriptor size wrong: %d > %d\n",
1137 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
1141 OBD_ALLOC(lmv->tgts, sizeof(*lmv->tgts) * 32);
1142 if (lmv->tgts == NULL)
1144 lmv->tgts_size = 32;
1146 obd_str2uuid(&lmv->desc.ld_uuid, desc->ld_uuid.uuid);
1147 lmv->desc.ld_tgt_count = 0;
1148 lmv->desc.ld_active_tgt_count = 0;
1149 lmv->max_cookiesize = 0;
1150 lmv->max_def_easize = 0;
1151 lmv->max_easize = 0;
1152 lmv->lmv_placement = PLACEMENT_CHAR_POLICY;
1154 spin_lock_init(&lmv->lmv_lock);
1155 mutex_init(&lmv->init_mutex);
1157 lprocfs_lmv_init_vars(&lvars);
1159 lprocfs_obd_setup(obd, lvars.obd_vars);
1162 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
1163 0444, &lmv_proc_target_fops, obd);
1165 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
1169 rc = fld_client_init(&lmv->lmv_fld, obd->obd_name,
1170 LUSTRE_CLI_FLD_HASH_DHT);
1172 CERROR("Can't init FLD, err %d\n", rc);
1182 static int lmv_cleanup(struct obd_device *obd)
1184 struct lmv_obd *lmv = &obd->u.lmv;
1187 fld_client_fini(&lmv->lmv_fld);
1188 if (lmv->tgts != NULL) {
1190 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1191 if (lmv->tgts[i] == NULL)
1193 lmv_del_target(lmv, i);
1195 OBD_FREE(lmv->tgts, sizeof(*lmv->tgts) * lmv->tgts_size);
1201 static int lmv_process_config(struct obd_device *obd, obd_count len, void *buf)
1203 struct lustre_cfg *lcfg = buf;
1204 struct obd_uuid obd_uuid;
1210 switch (lcfg->lcfg_command) {
1212 /* modify_mdc_tgts add 0:lustre-clilmv 1:lustre-MDT0000_UUID
1213 * 2:0 3:1 4:lustre-MDT0000-mdc_UUID */
1214 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
1215 GOTO(out, rc = -EINVAL);
1217 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
1219 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
1220 GOTO(out, rc = -EINVAL);
1221 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
1222 GOTO(out, rc = -EINVAL);
1223 rc = lmv_add_target(obd, &obd_uuid, index, gen);
1226 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1227 GOTO(out, rc = -EINVAL);
1233 static int lmv_statfs(const struct lu_env *env, struct obd_export *exp,
1234 struct obd_statfs *osfs, __u64 max_age, __u32 flags)
1236 struct obd_device *obd = class_exp2obd(exp);
1237 struct lmv_obd *lmv = &obd->u.lmv;
1238 struct obd_statfs *temp;
1243 rc = lmv_check_connect(obd);
1247 OBD_ALLOC(temp, sizeof(*temp));
1251 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1252 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1255 rc = obd_statfs(env, lmv->tgts[i]->ltd_exp, temp,
1258 CERROR("can't stat MDS #%d (%s), error %d\n", i,
1259 lmv->tgts[i]->ltd_exp->exp_obd->obd_name,
1261 GOTO(out_free_temp, rc);
1266 /* If the statfs is from mount, it will needs
1267 * retrieve necessary information from MDT0.
1268 * i.e. mount does not need the merged osfs
1270 * And also clients can be mounted as long as
1271 * MDT0 is in service*/
1272 if (flags & OBD_STATFS_FOR_MDT0)
1273 GOTO(out_free_temp, rc);
1275 osfs->os_bavail += temp->os_bavail;
1276 osfs->os_blocks += temp->os_blocks;
1277 osfs->os_ffree += temp->os_ffree;
1278 osfs->os_files += temp->os_files;
1284 OBD_FREE(temp, sizeof(*temp));
1288 static int lmv_getstatus(struct obd_export *exp,
1290 struct obd_capa **pc)
1292 struct obd_device *obd = exp->exp_obd;
1293 struct lmv_obd *lmv = &obd->u.lmv;
1297 rc = lmv_check_connect(obd);
1301 rc = md_getstatus(lmv->tgts[0]->ltd_exp, fid, pc);
1305 static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1306 struct obd_capa *oc, obd_valid valid, const char *name,
1307 const char *input, int input_size, int output_size,
1308 int flags, struct ptlrpc_request **request)
1310 struct obd_device *obd = exp->exp_obd;
1311 struct lmv_obd *lmv = &obd->u.lmv;
1312 struct lmv_tgt_desc *tgt;
1316 rc = lmv_check_connect(obd);
1320 tgt = lmv_find_target(lmv, fid);
1322 RETURN(PTR_ERR(tgt));
1324 rc = md_getxattr(tgt->ltd_exp, fid, oc, valid, name, input,
1325 input_size, output_size, flags, request);
1330 static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1331 struct obd_capa *oc, obd_valid valid, const char *name,
1332 const char *input, int input_size, int output_size,
1333 int flags, __u32 suppgid,
1334 struct ptlrpc_request **request)
1336 struct obd_device *obd = exp->exp_obd;
1337 struct lmv_obd *lmv = &obd->u.lmv;
1338 struct lmv_tgt_desc *tgt;
1342 rc = lmv_check_connect(obd);
1346 tgt = lmv_find_target(lmv, fid);
1348 RETURN(PTR_ERR(tgt));
1350 rc = md_setxattr(tgt->ltd_exp, fid, oc, valid, name, input,
1351 input_size, output_size, flags, suppgid,
1357 static int lmv_getattr(struct obd_export *exp, struct md_op_data *op_data,
1358 struct ptlrpc_request **request)
1360 struct obd_device *obd = exp->exp_obd;
1361 struct lmv_obd *lmv = &obd->u.lmv;
1362 struct lmv_tgt_desc *tgt;
1366 rc = lmv_check_connect(obd);
1370 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1372 RETURN(PTR_ERR(tgt));
1374 if (op_data->op_flags & MF_GET_MDT_IDX) {
1375 op_data->op_mds = tgt->ltd_idx;
1379 rc = md_getattr(tgt->ltd_exp, op_data, request);
1384 static int lmv_null_inode(struct obd_export *exp, const struct lu_fid *fid)
1386 struct obd_device *obd = exp->exp_obd;
1387 struct lmv_obd *lmv = &obd->u.lmv;
1392 rc = lmv_check_connect(obd);
1396 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1399 * With DNE every object can have two locks in different namespaces:
1400 * lookup lock in space of MDT storing direntry and update/open lock in
1401 * space of MDT storing inode.
1403 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1404 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1406 md_null_inode(lmv->tgts[i]->ltd_exp, fid);
1412 static int lmv_find_cbdata(struct obd_export *exp, const struct lu_fid *fid,
1413 ldlm_iterator_t it, void *data)
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 rc = md_find_cbdata(lmv->tgts[i]->ltd_exp, fid, it, data);
1444 static int lmv_close(struct obd_export *exp, struct md_op_data *op_data,
1445 struct md_open_data *mod, struct ptlrpc_request **request)
1447 struct obd_device *obd = exp->exp_obd;
1448 struct lmv_obd *lmv = &obd->u.lmv;
1449 struct lmv_tgt_desc *tgt;
1453 rc = lmv_check_connect(obd);
1457 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1459 RETURN(PTR_ERR(tgt));
1461 CDEBUG(D_INODE, "CLOSE "DFID"\n", PFID(&op_data->op_fid1));
1462 rc = md_close(tgt->ltd_exp, op_data, mod, request);
1467 *lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1470 struct lmv_tgt_desc *tgt;
1472 tgt = lmv_find_target(lmv, fid);
1476 op_data->op_mds = tgt->ltd_idx;
1481 int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
1482 const void *data, int datalen, int mode, __u32 uid,
1483 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1484 struct ptlrpc_request **request)
1486 struct obd_device *obd = exp->exp_obd;
1487 struct lmv_obd *lmv = &obd->u.lmv;
1488 struct lmv_tgt_desc *tgt;
1492 rc = lmv_check_connect(obd);
1496 if (!lmv->desc.ld_active_tgt_count)
1499 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1501 RETURN(PTR_ERR(tgt));
1503 rc = lmv_fid_alloc(exp, &op_data->op_fid2, op_data);
1507 CDEBUG(D_INODE, "CREATE '%*s' on "DFID" -> mds #%x\n",
1508 op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1),
1511 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1512 rc = md_create(tgt->ltd_exp, op_data, data, datalen, mode, uid, gid,
1513 cap_effective, rdev, request);
1516 if (*request == NULL)
1518 CDEBUG(D_INODE, "Created - "DFID"\n", PFID(&op_data->op_fid2));
1523 static int lmv_done_writing(struct obd_export *exp,
1524 struct md_op_data *op_data,
1525 struct md_open_data *mod)
1527 struct obd_device *obd = exp->exp_obd;
1528 struct lmv_obd *lmv = &obd->u.lmv;
1529 struct lmv_tgt_desc *tgt;
1533 rc = lmv_check_connect(obd);
1537 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1539 RETURN(PTR_ERR(tgt));
1541 rc = md_done_writing(tgt->ltd_exp, op_data, mod);
1546 lmv_enqueue_remote(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1547 struct lookup_intent *it, struct md_op_data *op_data,
1548 struct lustre_handle *lockh, void *lmm, int lmmsize,
1549 int extra_lock_flags)
1551 struct ptlrpc_request *req = it->d.lustre.it_data;
1552 struct obd_device *obd = exp->exp_obd;
1553 struct lmv_obd *lmv = &obd->u.lmv;
1554 struct lustre_handle plock;
1555 struct lmv_tgt_desc *tgt;
1556 struct md_op_data *rdata;
1558 struct mdt_body *body;
1563 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1564 LASSERT(body != NULL);
1566 if (!(body->valid & OBD_MD_MDS))
1569 CDEBUG(D_INODE, "REMOTE_ENQUEUE '%s' on "DFID" -> "DFID"\n",
1570 LL_IT2STR(it), PFID(&op_data->op_fid1), PFID(&body->fid1));
1573 * We got LOOKUP lock, but we really need attrs.
1575 pmode = it->d.lustre.it_lock_mode;
1576 LASSERT(pmode != 0);
1577 memcpy(&plock, lockh, sizeof(plock));
1578 it->d.lustre.it_lock_mode = 0;
1579 it->d.lustre.it_data = NULL;
1582 it->d.lustre.it_disposition &= ~DISP_ENQ_COMPLETE;
1583 ptlrpc_req_finished(req);
1585 tgt = lmv_find_target(lmv, &fid1);
1587 GOTO(out, rc = PTR_ERR(tgt));
1589 OBD_ALLOC_PTR(rdata);
1591 GOTO(out, rc = -ENOMEM);
1593 rdata->op_fid1 = fid1;
1594 rdata->op_bias = MDS_CROSS_REF;
1596 rc = md_enqueue(tgt->ltd_exp, einfo, it, rdata, lockh,
1597 lmm, lmmsize, NULL, extra_lock_flags);
1598 OBD_FREE_PTR(rdata);
1601 ldlm_lock_decref(&plock, pmode);
1606 lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1607 struct lookup_intent *it, struct md_op_data *op_data,
1608 struct lustre_handle *lockh, void *lmm, int lmmsize,
1609 struct ptlrpc_request **req, __u64 extra_lock_flags)
1611 struct obd_device *obd = exp->exp_obd;
1612 struct lmv_obd *lmv = &obd->u.lmv;
1613 struct lmv_tgt_desc *tgt;
1617 rc = lmv_check_connect(obd);
1621 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID"\n",
1622 LL_IT2STR(it), PFID(&op_data->op_fid1));
1624 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1626 RETURN(PTR_ERR(tgt));
1628 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID" -> mds #%d\n",
1629 LL_IT2STR(it), PFID(&op_data->op_fid1), tgt->ltd_idx);
1631 rc = md_enqueue(tgt->ltd_exp, einfo, it, op_data, lockh,
1632 lmm, lmmsize, req, extra_lock_flags);
1634 if (rc == 0 && it && it->it_op == IT_OPEN) {
1635 rc = lmv_enqueue_remote(exp, einfo, it, op_data, lockh,
1636 lmm, lmmsize, extra_lock_flags);
1642 lmv_getattr_name(struct obd_export *exp,struct md_op_data *op_data,
1643 struct ptlrpc_request **request)
1645 struct ptlrpc_request *req = NULL;
1646 struct obd_device *obd = exp->exp_obd;
1647 struct lmv_obd *lmv = &obd->u.lmv;
1648 struct lmv_tgt_desc *tgt;
1649 struct mdt_body *body;
1653 rc = lmv_check_connect(obd);
1657 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1659 RETURN(PTR_ERR(tgt));
1661 CDEBUG(D_INODE, "GETATTR_NAME for %*s on "DFID" -> mds #%d\n",
1662 op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1),
1665 rc = md_getattr_name(tgt->ltd_exp, op_data, request);
1669 body = req_capsule_server_get(&(*request)->rq_pill,
1671 LASSERT(body != NULL);
1673 if (body->valid & OBD_MD_MDS) {
1674 struct lu_fid rid = body->fid1;
1675 CDEBUG(D_INODE, "Request attrs for "DFID"\n",
1678 tgt = lmv_find_target(lmv, &rid);
1680 ptlrpc_req_finished(*request);
1681 RETURN(PTR_ERR(tgt));
1684 op_data->op_fid1 = rid;
1685 op_data->op_valid |= OBD_MD_FLCROSSREF;
1686 op_data->op_namelen = 0;
1687 op_data->op_name = NULL;
1688 rc = md_getattr_name(tgt->ltd_exp, op_data, &req);
1689 ptlrpc_req_finished(*request);
1696 #define md_op_data_fid(op_data, fl) \
1697 (fl == MF_MDC_CANCEL_FID1 ? &op_data->op_fid1 : \
1698 fl == MF_MDC_CANCEL_FID2 ? &op_data->op_fid2 : \
1699 fl == MF_MDC_CANCEL_FID3 ? &op_data->op_fid3 : \
1700 fl == MF_MDC_CANCEL_FID4 ? &op_data->op_fid4 : \
1703 static int lmv_early_cancel(struct obd_export *exp, struct md_op_data *op_data,
1704 int op_tgt, ldlm_mode_t mode, int bits, int flag)
1706 struct lu_fid *fid = md_op_data_fid(op_data, flag);
1707 struct obd_device *obd = exp->exp_obd;
1708 struct lmv_obd *lmv = &obd->u.lmv;
1709 struct lmv_tgt_desc *tgt;
1710 ldlm_policy_data_t policy = {{0}};
1714 if (!fid_is_sane(fid))
1717 tgt = lmv_find_target(lmv, fid);
1719 RETURN(PTR_ERR(tgt));
1721 if (tgt->ltd_idx != op_tgt) {
1722 CDEBUG(D_INODE, "EARLY_CANCEL on "DFID"\n", PFID(fid));
1723 policy.l_inodebits.bits = bits;
1724 rc = md_cancel_unused(tgt->ltd_exp, fid, &policy,
1725 mode, LCF_ASYNC, NULL);
1728 "EARLY_CANCEL skip operation target %d on "DFID"\n",
1730 op_data->op_flags |= flag;
1738 * llite passes fid of an target inode in op_data->op_fid1 and id of directory in
1741 static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
1742 struct ptlrpc_request **request)
1744 struct obd_device *obd = exp->exp_obd;
1745 struct lmv_obd *lmv = &obd->u.lmv;
1746 struct lmv_tgt_desc *tgt;
1750 rc = lmv_check_connect(obd);
1754 LASSERT(op_data->op_namelen != 0);
1756 CDEBUG(D_INODE, "LINK "DFID":%*s to "DFID"\n",
1757 PFID(&op_data->op_fid2), op_data->op_namelen,
1758 op_data->op_name, PFID(&op_data->op_fid1));
1760 op_data->op_fsuid = current_fsuid();
1761 op_data->op_fsgid = current_fsgid();
1762 op_data->op_cap = cfs_curproc_cap_pack();
1763 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
1765 RETURN(PTR_ERR(tgt));
1768 * Cancel UPDATE lock on child (fid1).
1770 op_data->op_flags |= MF_MDC_CANCEL_FID2;
1771 rc = lmv_early_cancel(exp, op_data, tgt->ltd_idx, LCK_EX,
1772 MDS_INODELOCK_UPDATE, MF_MDC_CANCEL_FID1);
1776 rc = md_link(tgt->ltd_exp, op_data, request);
1781 static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
1782 const char *old, int oldlen, const char *new, int newlen,
1783 struct ptlrpc_request **request)
1785 struct obd_device *obd = exp->exp_obd;
1786 struct lmv_obd *lmv = &obd->u.lmv;
1787 struct lmv_tgt_desc *src_tgt;
1788 struct lmv_tgt_desc *tgt_tgt;
1792 LASSERT(oldlen != 0);
1794 CDEBUG(D_INODE, "RENAME %*s in "DFID" to %*s in "DFID"\n",
1795 oldlen, old, PFID(&op_data->op_fid1),
1796 newlen, new, PFID(&op_data->op_fid2));
1798 rc = lmv_check_connect(obd);
1802 op_data->op_fsuid = current_fsuid();
1803 op_data->op_fsgid = current_fsgid();
1804 op_data->op_cap = cfs_curproc_cap_pack();
1805 src_tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1806 if (IS_ERR(src_tgt))
1807 RETURN(PTR_ERR(src_tgt));
1809 tgt_tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
1810 if (IS_ERR(tgt_tgt))
1811 RETURN(PTR_ERR(tgt_tgt));
1813 * LOOKUP lock on src child (fid3) should also be cancelled for
1814 * src_tgt in mdc_rename.
1816 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
1819 * Cancel UPDATE locks on tgt parent (fid2), tgt_tgt is its
1822 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
1823 LCK_EX, MDS_INODELOCK_UPDATE,
1824 MF_MDC_CANCEL_FID2);
1827 * Cancel LOOKUP locks on tgt child (fid4) for parent tgt_tgt.
1830 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
1831 LCK_EX, MDS_INODELOCK_LOOKUP,
1832 MF_MDC_CANCEL_FID4);
1836 * Cancel all the locks on tgt child (fid4).
1839 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
1840 LCK_EX, MDS_INODELOCK_FULL,
1841 MF_MDC_CANCEL_FID4);
1844 rc = md_rename(src_tgt->ltd_exp, op_data, old, oldlen,
1845 new, newlen, request);
1849 static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
1850 void *ea, int ealen, void *ea2, int ea2len,
1851 struct ptlrpc_request **request,
1852 struct md_open_data **mod)
1854 struct obd_device *obd = exp->exp_obd;
1855 struct lmv_obd *lmv = &obd->u.lmv;
1856 struct lmv_tgt_desc *tgt;
1860 rc = lmv_check_connect(obd);
1864 CDEBUG(D_INODE, "SETATTR for "DFID", valid 0x%x\n",
1865 PFID(&op_data->op_fid1), op_data->op_attr.ia_valid);
1867 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1868 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1870 RETURN(PTR_ERR(tgt));
1872 rc = md_setattr(tgt->ltd_exp, op_data, ea, ealen, ea2,
1873 ea2len, request, mod);
1878 static int lmv_sync(struct obd_export *exp, const struct lu_fid *fid,
1879 struct obd_capa *oc, struct ptlrpc_request **request)
1881 struct obd_device *obd = exp->exp_obd;
1882 struct lmv_obd *lmv = &obd->u.lmv;
1883 struct lmv_tgt_desc *tgt;
1887 rc = lmv_check_connect(obd);
1891 tgt = lmv_find_target(lmv, fid);
1893 RETURN(PTR_ERR(tgt));
1895 rc = md_sync(tgt->ltd_exp, fid, oc, request);
1900 * Adjust a set of pages, each page containing an array of lu_dirpages,
1901 * so that each page can be used as a single logical lu_dirpage.
1903 * A lu_dirpage is laid out as follows, where s = ldp_hash_start,
1904 * e = ldp_hash_end, f = ldp_flags, p = padding, and each "ent" is a
1905 * struct lu_dirent. It has size up to LU_PAGE_SIZE. The ldp_hash_end
1906 * value is used as a cookie to request the next lu_dirpage in a
1907 * directory listing that spans multiple pages (two in this example):
1910 * .|--------v------- -----.
1911 * |s|e|f|p|ent|ent| ... |ent|
1912 * '--|-------------- -----' Each CFS_PAGE contains a single
1913 * '------. lu_dirpage.
1914 * .---------v------- -----.
1915 * |s|e|f|p|ent| 0 | ... | 0 |
1916 * '----------------- -----'
1918 * However, on hosts where the native VM page size (PAGE_CACHE_SIZE) is
1919 * larger than LU_PAGE_SIZE, a single host page may contain multiple
1920 * lu_dirpages. After reading the lu_dirpages from the MDS, the
1921 * ldp_hash_end of the first lu_dirpage refers to the one immediately
1922 * after it in the same CFS_PAGE (arrows simplified for brevity, but
1923 * in general e0==s1, e1==s2, etc.):
1925 * .-------------------- -----.
1926 * |s0|e0|f0|p|ent|ent| ... |ent|
1927 * |---v---------------- -----|
1928 * |s1|e1|f1|p|ent|ent| ... |ent|
1929 * |---v---------------- -----| Here, each CFS_PAGE contains
1930 * ... multiple lu_dirpages.
1931 * |---v---------------- -----|
1932 * |s'|e'|f'|p|ent|ent| ... |ent|
1933 * '---|---------------- -----'
1935 * .----------------------------.
1938 * This structure is transformed into a single logical lu_dirpage as follows:
1940 * - Replace e0 with e' so the request for the next lu_dirpage gets the page
1941 * labeled 'next CFS_PAGE'.
1943 * - Copy the LDF_COLLIDE flag from f' to f0 to correctly reflect whether
1944 * a hash collision with the next page exists.
1946 * - Adjust the lde_reclen of the ending entry of each lu_dirpage to span
1947 * to the first entry of the next lu_dirpage.
1949 #if PAGE_CACHE_SIZE > LU_PAGE_SIZE
1950 static void lmv_adjust_dirpages(struct page **pages, int ncfspgs, int nlupgs)
1954 for (i = 0; i < ncfspgs; i++) {
1955 struct lu_dirpage *dp = kmap(pages[i]);
1956 struct lu_dirpage *first = dp;
1957 struct lu_dirent *end_dirent = NULL;
1958 struct lu_dirent *ent;
1959 __u64 hash_end = dp->ldp_hash_end;
1960 __u32 flags = dp->ldp_flags;
1962 for (; nlupgs > 1; nlupgs--) {
1963 ent = lu_dirent_start(dp);
1964 for (end_dirent = ent; ent != NULL;
1965 end_dirent = ent, ent = lu_dirent_next(ent));
1967 /* Advance dp to next lu_dirpage. */
1968 dp = (struct lu_dirpage *)((char *)dp + LU_PAGE_SIZE);
1970 /* Check if we've reached the end of the CFS_PAGE. */
1971 if (!((unsigned long)dp & ~CFS_PAGE_MASK))
1974 /* Save the hash and flags of this lu_dirpage. */
1975 hash_end = dp->ldp_hash_end;
1976 flags = dp->ldp_flags;
1978 /* Check if lu_dirpage contains no entries. */
1982 /* Enlarge the end entry lde_reclen from 0 to
1983 * first entry of next lu_dirpage. */
1984 LASSERT(le16_to_cpu(end_dirent->lde_reclen) == 0);
1985 end_dirent->lde_reclen =
1986 cpu_to_le16((char *)(dp->ldp_entries) -
1987 (char *)end_dirent);
1990 first->ldp_hash_end = hash_end;
1991 first->ldp_flags &= ~cpu_to_le32(LDF_COLLIDE);
1992 first->ldp_flags |= flags & cpu_to_le32(LDF_COLLIDE);
1998 #define lmv_adjust_dirpages(pages, ncfspgs, nlupgs) do {} while (0)
1999 #endif /* PAGE_CACHE_SIZE > LU_PAGE_SIZE */
2001 static int lmv_readpage(struct obd_export *exp, struct md_op_data *op_data,
2002 struct page **pages, struct ptlrpc_request **request)
2004 struct obd_device *obd = exp->exp_obd;
2005 struct lmv_obd *lmv = &obd->u.lmv;
2006 __u64 offset = op_data->op_offset;
2008 int ncfspgs; /* pages read in PAGE_CACHE_SIZE */
2009 int nlupgs; /* pages read in LU_PAGE_SIZE */
2010 struct lmv_tgt_desc *tgt;
2013 rc = lmv_check_connect(obd);
2017 CDEBUG(D_INODE, "READPAGE at "LPX64" from "DFID"\n",
2018 offset, PFID(&op_data->op_fid1));
2020 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2022 RETURN(PTR_ERR(tgt));
2024 rc = md_readpage(tgt->ltd_exp, op_data, pages, request);
2028 ncfspgs = ((*request)->rq_bulk->bd_nob_transferred + PAGE_CACHE_SIZE - 1)
2029 >> PAGE_CACHE_SHIFT;
2030 nlupgs = (*request)->rq_bulk->bd_nob_transferred >> LU_PAGE_SHIFT;
2031 LASSERT(!((*request)->rq_bulk->bd_nob_transferred & ~LU_PAGE_MASK));
2032 LASSERT(ncfspgs > 0 && ncfspgs <= op_data->op_npages);
2034 CDEBUG(D_INODE, "read %d(%d)/%d pages\n", ncfspgs, nlupgs,
2035 op_data->op_npages);
2037 lmv_adjust_dirpages(pages, ncfspgs, nlupgs);
2042 static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
2043 struct ptlrpc_request **request)
2045 struct obd_device *obd = exp->exp_obd;
2046 struct lmv_obd *lmv = &obd->u.lmv;
2047 struct lmv_tgt_desc *tgt = NULL;
2048 struct mdt_body *body;
2052 rc = lmv_check_connect(obd);
2056 /* Send unlink requests to the MDT where the child is located */
2057 if (likely(!fid_is_zero(&op_data->op_fid2)))
2058 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
2060 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
2062 RETURN(PTR_ERR(tgt));
2064 op_data->op_fsuid = current_fsuid();
2065 op_data->op_fsgid = current_fsgid();
2066 op_data->op_cap = cfs_curproc_cap_pack();
2069 * If child's fid is given, cancel unused locks for it if it is from
2070 * another export than parent.
2072 * LOOKUP lock for child (fid3) should also be cancelled on parent
2073 * tgt_tgt in mdc_unlink().
2075 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2078 * Cancel FULL locks on child (fid3).
2080 rc = lmv_early_cancel(exp, op_data, tgt->ltd_idx, LCK_EX,
2081 MDS_INODELOCK_FULL, MF_MDC_CANCEL_FID3);
2086 CDEBUG(D_INODE, "unlink with fid="DFID"/"DFID" -> mds #%d\n",
2087 PFID(&op_data->op_fid1), PFID(&op_data->op_fid2), tgt->ltd_idx);
2089 rc = md_unlink(tgt->ltd_exp, op_data, request);
2090 if (rc != 0 && rc != -EREMOTE)
2093 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
2097 /* Not cross-ref case, just get out of here. */
2098 if (likely(!(body->valid & OBD_MD_MDS)))
2101 CDEBUG(D_INODE, "%s: try unlink to another MDT for "DFID"\n",
2102 exp->exp_obd->obd_name, PFID(&body->fid1));
2104 /* This is a remote object, try remote MDT, Note: it may
2105 * try more than 1 time here, Considering following case
2106 * /mnt/lustre is root on MDT0, remote1 is on MDT1
2107 * 1. Initially A does not know where remote1 is, it send
2108 * unlink RPC to MDT0, MDT0 return -EREMOTE, it will
2109 * resend unlink RPC to MDT1 (retry 1st time).
2111 * 2. During the unlink RPC in flight,
2112 * client B mv /mnt/lustre/remote1 /mnt/lustre/remote2
2113 * and create new remote1, but on MDT0
2115 * 3. MDT1 get unlink RPC(from A), then do remote lock on
2116 * /mnt/lustre, then lookup get fid of remote1, and find
2117 * it is remote dir again, and replay -EREMOTE again.
2119 * 4. Then A will resend unlink RPC to MDT0. (retry 2nd times).
2121 * In theory, it might try unlimited time here, but it should
2122 * be very rare case. */
2123 op_data->op_fid2 = body->fid1;
2124 ptlrpc_req_finished(*request);
2130 static int lmv_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2132 struct lmv_obd *lmv = &obd->u.lmv;
2136 case OBD_CLEANUP_EARLY:
2137 /* XXX: here should be calling obd_precleanup() down to
2140 case OBD_CLEANUP_EXPORTS:
2141 fld_client_proc_fini(&lmv->lmv_fld);
2142 lprocfs_obd_cleanup(obd);
2150 static int lmv_get_info(const struct lu_env *env, struct obd_export *exp,
2151 __u32 keylen, void *key, __u32 *vallen, void *val,
2152 struct lov_stripe_md *lsm)
2154 struct obd_device *obd;
2155 struct lmv_obd *lmv;
2159 obd = class_exp2obd(exp);
2161 CDEBUG(D_IOCTL, "Invalid client cookie "LPX64"\n",
2162 exp->exp_handle.h_cookie);
2167 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
2168 struct lmv_tgt_desc *tgt;
2171 rc = lmv_check_connect(obd);
2175 LASSERT(*vallen == sizeof(__u32));
2176 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2179 * All tgts should be connected when this gets called.
2181 if (tgt == NULL || tgt->ltd_exp == NULL)
2184 if (!obd_get_info(env, tgt->ltd_exp, keylen, key,
2189 } else if (KEY_IS(KEY_MAX_EASIZE) || KEY_IS(KEY_CONN_DATA)) {
2190 rc = lmv_check_connect(obd);
2195 * Forwarding this request to first MDS, it should know LOV
2198 rc = obd_get_info(env, lmv->tgts[0]->ltd_exp, keylen, key,
2200 if (!rc && KEY_IS(KEY_CONN_DATA))
2201 exp->exp_connect_data = *(struct obd_connect_data *)val;
2203 } else if (KEY_IS(KEY_TGT_COUNT)) {
2204 *((int *)val) = lmv->desc.ld_tgt_count;
2208 CDEBUG(D_IOCTL, "Invalid key\n");
2212 int lmv_set_info_async(const struct lu_env *env, struct obd_export *exp,
2213 obd_count keylen, void *key, obd_count vallen,
2214 void *val, struct ptlrpc_request_set *set)
2216 struct lmv_tgt_desc *tgt;
2217 struct obd_device *obd;
2218 struct lmv_obd *lmv;
2222 obd = class_exp2obd(exp);
2224 CDEBUG(D_IOCTL, "Invalid client cookie "LPX64"\n",
2225 exp->exp_handle.h_cookie);
2230 if (KEY_IS(KEY_READ_ONLY) || KEY_IS(KEY_FLUSH_CTX)) {
2233 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2236 if (tgt == NULL || tgt->ltd_exp == NULL)
2239 err = obd_set_info_async(env, tgt->ltd_exp,
2240 keylen, key, vallen, val, set);
2251 int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
2252 struct lov_stripe_md *lsm)
2254 struct obd_device *obd = class_exp2obd(exp);
2255 struct lmv_obd *lmv = &obd->u.lmv;
2256 struct lmv_stripe_md *meap;
2257 struct lmv_stripe_md *lsmp;
2262 mea_size = lmv_get_easize(lmv);
2266 if (*lmmp && !lsm) {
2267 OBD_FREE_LARGE(*lmmp, mea_size);
2272 if (*lmmp == NULL) {
2273 OBD_ALLOC_LARGE(*lmmp, mea_size);
2281 lsmp = (struct lmv_stripe_md *)lsm;
2282 meap = (struct lmv_stripe_md *)*lmmp;
2284 if (lsmp->mea_magic != MEA_MAGIC_LAST_CHAR &&
2285 lsmp->mea_magic != MEA_MAGIC_ALL_CHARS)
2288 meap->mea_magic = cpu_to_le32(lsmp->mea_magic);
2289 meap->mea_count = cpu_to_le32(lsmp->mea_count);
2290 meap->mea_master = cpu_to_le32(lsmp->mea_master);
2292 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2293 meap->mea_ids[i] = lsmp->mea_ids[i];
2294 fid_cpu_to_le(&meap->mea_ids[i], &lsmp->mea_ids[i]);
2300 int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
2301 struct lov_mds_md *lmm, int lmm_size)
2303 struct obd_device *obd = class_exp2obd(exp);
2304 struct lmv_stripe_md **tmea = (struct lmv_stripe_md **)lsmp;
2305 struct lmv_stripe_md *mea = (struct lmv_stripe_md *)lmm;
2306 struct lmv_obd *lmv = &obd->u.lmv;
2312 mea_size = lmv_get_easize(lmv);
2316 if (*lsmp != NULL && lmm == NULL) {
2317 OBD_FREE_LARGE(*tmea, mea_size);
2322 LASSERT(mea_size == lmm_size);
2324 OBD_ALLOC_LARGE(*tmea, mea_size);
2331 if (mea->mea_magic == MEA_MAGIC_LAST_CHAR ||
2332 mea->mea_magic == MEA_MAGIC_ALL_CHARS ||
2333 mea->mea_magic == MEA_MAGIC_HASH_SEGMENT)
2335 magic = le32_to_cpu(mea->mea_magic);
2338 * Old mea is not handled here.
2340 CERROR("Old not supportable EA is found\n");
2344 (*tmea)->mea_magic = magic;
2345 (*tmea)->mea_count = le32_to_cpu(mea->mea_count);
2346 (*tmea)->mea_master = le32_to_cpu(mea->mea_master);
2348 for (i = 0; i < (*tmea)->mea_count; i++) {
2349 (*tmea)->mea_ids[i] = mea->mea_ids[i];
2350 fid_le_to_cpu(&(*tmea)->mea_ids[i], &(*tmea)->mea_ids[i]);
2355 static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
2356 ldlm_policy_data_t *policy, ldlm_mode_t mode,
2357 ldlm_cancel_flags_t flags, void *opaque)
2359 struct obd_device *obd = exp->exp_obd;
2360 struct lmv_obd *lmv = &obd->u.lmv;
2366 LASSERT(fid != NULL);
2368 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2369 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL ||
2370 lmv->tgts[i]->ltd_active == 0)
2373 err = md_cancel_unused(lmv->tgts[i]->ltd_exp, fid,
2374 policy, mode, flags, opaque);
2381 int lmv_set_lock_data(struct obd_export *exp, __u64 *lockh, void *data,
2384 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2388 rc = md_set_lock_data(lmv->tgts[0]->ltd_exp, lockh, data, bits);
2392 ldlm_mode_t lmv_lock_match(struct obd_export *exp, __u64 flags,
2393 const struct lu_fid *fid, ldlm_type_t type,
2394 ldlm_policy_data_t *policy, ldlm_mode_t mode,
2395 struct lustre_handle *lockh)
2397 struct obd_device *obd = exp->exp_obd;
2398 struct lmv_obd *lmv = &obd->u.lmv;
2403 CDEBUG(D_INODE, "Lock match for "DFID"\n", PFID(fid));
2406 * With CMD every object can have two locks in different namespaces:
2407 * lookup lock in space of mds storing direntry and update/open lock in
2408 * space of mds storing inode. Thus we check all targets, not only that
2409 * one fid was created in.
2411 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2412 if (lmv->tgts[i] == NULL ||
2413 lmv->tgts[i]->ltd_exp == NULL ||
2414 lmv->tgts[i]->ltd_active == 0)
2417 rc = md_lock_match(lmv->tgts[i]->ltd_exp, flags, fid,
2418 type, policy, mode, lockh);
2426 int lmv_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
2427 struct obd_export *dt_exp, struct obd_export *md_exp,
2428 struct lustre_md *md)
2430 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2432 return md_get_lustre_md(lmv->tgts[0]->ltd_exp, req, dt_exp, md_exp, md);
2435 int lmv_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
2437 struct obd_device *obd = exp->exp_obd;
2438 struct lmv_obd *lmv = &obd->u.lmv;
2442 obd_free_memmd(exp, (void *)&md->mea);
2443 RETURN(md_free_lustre_md(lmv->tgts[0]->ltd_exp, md));
2446 int lmv_set_open_replay_data(struct obd_export *exp,
2447 struct obd_client_handle *och,
2448 struct ptlrpc_request *open_req)
2450 struct obd_device *obd = exp->exp_obd;
2451 struct lmv_obd *lmv = &obd->u.lmv;
2452 struct lmv_tgt_desc *tgt;
2455 tgt = lmv_find_target(lmv, &och->och_fid);
2457 RETURN(PTR_ERR(tgt));
2459 RETURN(md_set_open_replay_data(tgt->ltd_exp, och, open_req));
2462 int lmv_clear_open_replay_data(struct obd_export *exp,
2463 struct obd_client_handle *och)
2465 struct obd_device *obd = exp->exp_obd;
2466 struct lmv_obd *lmv = &obd->u.lmv;
2467 struct lmv_tgt_desc *tgt;
2470 tgt = lmv_find_target(lmv, &och->och_fid);
2472 RETURN(PTR_ERR(tgt));
2474 RETURN(md_clear_open_replay_data(tgt->ltd_exp, och));
2477 static int lmv_get_remote_perm(struct obd_export *exp,
2478 const struct lu_fid *fid,
2479 struct obd_capa *oc, __u32 suppgid,
2480 struct ptlrpc_request **request)
2482 struct obd_device *obd = exp->exp_obd;
2483 struct lmv_obd *lmv = &obd->u.lmv;
2484 struct lmv_tgt_desc *tgt;
2488 rc = lmv_check_connect(obd);
2492 tgt = lmv_find_target(lmv, fid);
2494 RETURN(PTR_ERR(tgt));
2496 rc = md_get_remote_perm(tgt->ltd_exp, fid, oc, suppgid, request);
2500 static int lmv_renew_capa(struct obd_export *exp, struct obd_capa *oc,
2503 struct obd_device *obd = exp->exp_obd;
2504 struct lmv_obd *lmv = &obd->u.lmv;
2505 struct lmv_tgt_desc *tgt;
2509 rc = lmv_check_connect(obd);
2513 tgt = lmv_find_target(lmv, &oc->c_capa.lc_fid);
2515 RETURN(PTR_ERR(tgt));
2517 rc = md_renew_capa(tgt->ltd_exp, oc, cb);
2521 int lmv_unpack_capa(struct obd_export *exp, struct ptlrpc_request *req,
2522 const struct req_msg_field *field, struct obd_capa **oc)
2524 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2526 return md_unpack_capa(lmv->tgts[0]->ltd_exp, req, field, oc);
2529 int lmv_intent_getattr_async(struct obd_export *exp,
2530 struct md_enqueue_info *minfo,
2531 struct ldlm_enqueue_info *einfo)
2533 struct md_op_data *op_data = &minfo->mi_data;
2534 struct obd_device *obd = exp->exp_obd;
2535 struct lmv_obd *lmv = &obd->u.lmv;
2536 struct lmv_tgt_desc *tgt = NULL;
2540 rc = lmv_check_connect(obd);
2544 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2546 RETURN(PTR_ERR(tgt));
2548 rc = md_intent_getattr_async(tgt->ltd_exp, minfo, einfo);
2552 int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
2553 struct lu_fid *fid, __u64 *bits)
2555 struct obd_device *obd = exp->exp_obd;
2556 struct lmv_obd *lmv = &obd->u.lmv;
2557 struct lmv_tgt_desc *tgt;
2561 rc = lmv_check_connect(obd);
2565 tgt = lmv_find_target(lmv, fid);
2567 RETURN(PTR_ERR(tgt));
2569 rc = md_revalidate_lock(tgt->ltd_exp, it, fid, bits);
2574 * For lmv, only need to send request to master MDT, and the master MDT will
2575 * process with other slave MDTs. The only exception is Q_GETOQUOTA for which
2576 * we directly fetch data from the slave MDTs.
2578 int lmv_quotactl(struct obd_device *unused, struct obd_export *exp,
2579 struct obd_quotactl *oqctl)
2581 struct obd_device *obd = class_exp2obd(exp);
2582 struct lmv_obd *lmv = &obd->u.lmv;
2583 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2585 __u64 curspace, curinodes;
2588 if (!lmv->desc.ld_tgt_count || !tgt->ltd_active) {
2589 CERROR("master lmv inactive\n");
2593 if (oqctl->qc_cmd != Q_GETOQUOTA) {
2594 rc = obd_quotactl(tgt->ltd_exp, oqctl);
2598 curspace = curinodes = 0;
2599 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2603 if (tgt == NULL || tgt->ltd_exp == NULL || tgt->ltd_active == 0)
2605 if (!tgt->ltd_active) {
2606 CDEBUG(D_HA, "mdt %d is inactive.\n", i);
2610 err = obd_quotactl(tgt->ltd_exp, oqctl);
2612 CERROR("getquota on mdt %d failed. %d\n", i, err);
2616 curspace += oqctl->qc_dqblk.dqb_curspace;
2617 curinodes += oqctl->qc_dqblk.dqb_curinodes;
2620 oqctl->qc_dqblk.dqb_curspace = curspace;
2621 oqctl->qc_dqblk.dqb_curinodes = curinodes;
2626 int lmv_quotacheck(struct obd_device *unused, struct obd_export *exp,
2627 struct obd_quotactl *oqctl)
2629 struct obd_device *obd = class_exp2obd(exp);
2630 struct lmv_obd *lmv = &obd->u.lmv;
2631 struct lmv_tgt_desc *tgt;
2635 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2638 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active) {
2639 CERROR("lmv idx %d inactive\n", i);
2643 err = obd_quotacheck(tgt->ltd_exp, oqctl);
2651 struct obd_ops lmv_obd_ops = {
2652 .o_owner = THIS_MODULE,
2653 .o_setup = lmv_setup,
2654 .o_cleanup = lmv_cleanup,
2655 .o_precleanup = lmv_precleanup,
2656 .o_process_config = lmv_process_config,
2657 .o_connect = lmv_connect,
2658 .o_disconnect = lmv_disconnect,
2659 .o_statfs = lmv_statfs,
2660 .o_get_info = lmv_get_info,
2661 .o_set_info_async = lmv_set_info_async,
2662 .o_packmd = lmv_packmd,
2663 .o_unpackmd = lmv_unpackmd,
2664 .o_notify = lmv_notify,
2665 .o_get_uuid = lmv_get_uuid,
2666 .o_iocontrol = lmv_iocontrol,
2667 .o_quotacheck = lmv_quotacheck,
2668 .o_quotactl = lmv_quotactl
2671 struct md_ops lmv_md_ops = {
2672 .m_getstatus = lmv_getstatus,
2673 .m_null_inode = lmv_null_inode,
2674 .m_find_cbdata = lmv_find_cbdata,
2675 .m_close = lmv_close,
2676 .m_create = lmv_create,
2677 .m_done_writing = lmv_done_writing,
2678 .m_enqueue = lmv_enqueue,
2679 .m_getattr = lmv_getattr,
2680 .m_getxattr = lmv_getxattr,
2681 .m_getattr_name = lmv_getattr_name,
2682 .m_intent_lock = lmv_intent_lock,
2684 .m_rename = lmv_rename,
2685 .m_setattr = lmv_setattr,
2686 .m_setxattr = lmv_setxattr,
2688 .m_readpage = lmv_readpage,
2689 .m_unlink = lmv_unlink,
2690 .m_init_ea_size = lmv_init_ea_size,
2691 .m_cancel_unused = lmv_cancel_unused,
2692 .m_set_lock_data = lmv_set_lock_data,
2693 .m_lock_match = lmv_lock_match,
2694 .m_get_lustre_md = lmv_get_lustre_md,
2695 .m_free_lustre_md = lmv_free_lustre_md,
2696 .m_set_open_replay_data = lmv_set_open_replay_data,
2697 .m_clear_open_replay_data = lmv_clear_open_replay_data,
2698 .m_renew_capa = lmv_renew_capa,
2699 .m_unpack_capa = lmv_unpack_capa,
2700 .m_get_remote_perm = lmv_get_remote_perm,
2701 .m_intent_getattr_async = lmv_intent_getattr_async,
2702 .m_revalidate_lock = lmv_revalidate_lock
2705 int __init lmv_init(void)
2707 struct lprocfs_static_vars lvars;
2710 lprocfs_lmv_init_vars(&lvars);
2712 rc = class_register_type(&lmv_obd_ops, &lmv_md_ops,
2713 lvars.module_vars, LUSTRE_LMV_NAME, NULL);
2717 static void lmv_exit(void)
2719 class_unregister_type(LUSTRE_LMV_NAME);
2722 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2723 MODULE_DESCRIPTION("Lustre Logical Metadata Volume OBD driver");
2724 MODULE_LICENSE("GPL");
2726 module_init(lmv_init);
2727 module_exit(lmv_exit);