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/pagemap.h>
43 #include <asm/div64.h>
44 #include <linux/seq_file.h>
45 #include <linux/namei.h>
46 #include <asm/uaccess.h>
48 #include "../include/lustre/lustre_idl.h"
49 #include "../include/obd_support.h"
50 #include "../include/lustre_lib.h"
51 #include "../include/lustre_net.h"
52 #include "../include/obd_class.h"
53 #include "../include/lprocfs_status.h"
54 #include "../include/lustre_lite.h"
55 #include "../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;
84 CDEBUG(D_INFO, "Searching in lmv %p for uuid %s (activate=%d)\n",
85 lmv, uuid->uuid, activate);
87 spin_lock(&lmv->lmv_lock);
88 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
90 if (tgt == NULL || tgt->ltd_exp == NULL)
93 CDEBUG(D_INFO, "Target idx %d is %s conn %#llx\n", i,
94 tgt->ltd_uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
96 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
100 if (i == lmv->desc.ld_tgt_count)
101 GOTO(out_lmv_lock, rc = -EINVAL);
103 obd = class_exp2obd(tgt->ltd_exp);
105 GOTO(out_lmv_lock, rc = -ENOTCONN);
107 CDEBUG(D_INFO, "Found OBD %s=%s device %d (%p) type %s at LMV idx %d\n",
108 obd->obd_name, obd->obd_uuid.uuid, obd->obd_minor, obd,
109 obd->obd_type->typ_name, i);
110 LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0);
112 if (tgt->ltd_active == activate) {
113 CDEBUG(D_INFO, "OBD %p already %sactive!\n", obd,
114 activate ? "" : "in");
115 GOTO(out_lmv_lock, rc);
118 CDEBUG(D_INFO, "Marking OBD %p %sactive\n", obd,
119 activate ? "" : "in");
120 lmv_activate_target(lmv, tgt, activate);
123 spin_unlock(&lmv->lmv_lock);
127 struct obd_uuid *lmv_get_uuid(struct obd_export *exp)
129 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
131 return obd_get_uuid(lmv->tgts[0]->ltd_exp);
134 static int lmv_notify(struct obd_device *obd, struct obd_device *watched,
135 enum obd_notify_event ev, void *data)
137 struct obd_connect_data *conn_data;
138 struct lmv_obd *lmv = &obd->u.lmv;
139 struct obd_uuid *uuid;
142 if (strcmp(watched->obd_type->typ_name, LUSTRE_MDC_NAME)) {
143 CERROR("unexpected notification of %s %s!\n",
144 watched->obd_type->typ_name,
149 uuid = &watched->u.cli.cl_target_uuid;
150 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE) {
152 * Set MDC as active before notifying the observer, so the
153 * observer can use the MDC normally.
155 rc = lmv_set_mdc_active(lmv, uuid,
156 ev == OBD_NOTIFY_ACTIVE);
158 CERROR("%sactivation of %s failed: %d\n",
159 ev == OBD_NOTIFY_ACTIVE ? "" : "de",
163 } else if (ev == OBD_NOTIFY_OCD) {
164 conn_data = &watched->u.cli.cl_import->imp_connect_data;
166 * XXX: Make sure that ocd_connect_flags from all targets are
167 * the same. Otherwise one of MDTs runs wrong version or
168 * something like this. --umka
170 obd->obd_self_export->exp_connect_data = *conn_data;
173 else if (ev == OBD_NOTIFY_DISCON) {
175 * For disconnect event, flush fld cache for failout MDS case.
177 fld_client_flush(&lmv->lmv_fld);
181 * Pass the notification up the chain.
183 if (obd->obd_observer)
184 rc = obd_notify(obd->obd_observer, watched, ev, data);
190 * This is fake connect function. Its purpose is to initialize lmv and say
191 * caller that everything is okay. Real connection will be performed later.
193 static int lmv_connect(const struct lu_env *env,
194 struct obd_export **exp, struct obd_device *obd,
195 struct obd_uuid *cluuid, struct obd_connect_data *data,
198 struct proc_dir_entry *lmv_proc_dir;
199 struct lmv_obd *lmv = &obd->u.lmv;
200 struct lustre_handle conn = { 0 };
204 * We don't want to actually do the underlying connections more than
205 * once, so keep track.
208 if (lmv->refcount > 1) {
213 rc = class_connect(&conn, obd, cluuid);
215 CERROR("class_connection() returned %d\n", rc);
219 *exp = class_conn2export(&conn);
220 class_export_get(*exp);
224 lmv->cluuid = *cluuid;
227 lmv->conn_data = *data;
229 if (obd->obd_proc_private != NULL) {
230 lmv_proc_dir = obd->obd_proc_private;
232 lmv_proc_dir = lprocfs_register("target_obds", obd->obd_proc_entry,
234 if (IS_ERR(lmv_proc_dir)) {
235 CERROR("could not register /proc/fs/lustre/%s/%s/target_obds.",
236 obd->obd_type->typ_name, obd->obd_name);
239 obd->obd_proc_private = lmv_proc_dir;
243 * All real clients should perform actual connection right away, because
244 * it is possible, that LMV will not have opportunity to connect targets
245 * and MDC stuff will be called directly, for instance while reading
246 * ../mdc/../kbytesfree procfs file, etc.
248 if (data->ocd_connect_flags & OBD_CONNECT_REAL)
249 rc = lmv_check_connect(obd);
251 if (rc && lmv_proc_dir) {
252 lprocfs_remove(&lmv_proc_dir);
253 obd->obd_proc_private = NULL;
259 static void lmv_set_timeouts(struct obd_device *obd)
261 struct lmv_tgt_desc *tgt;
266 if (lmv->server_timeout == 0)
269 if (lmv->connected == 0)
272 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
274 if (tgt == NULL || tgt->ltd_exp == NULL || tgt->ltd_active == 0)
277 obd_set_info_async(NULL, tgt->ltd_exp, sizeof(KEY_INTERMDS),
278 KEY_INTERMDS, 0, NULL, NULL);
282 static int lmv_init_ea_size(struct obd_export *exp, int easize,
283 int def_easize, int cookiesize, int def_cookiesize)
285 struct obd_device *obd = exp->exp_obd;
286 struct lmv_obd *lmv = &obd->u.lmv;
291 if (lmv->max_easize < easize) {
292 lmv->max_easize = easize;
295 if (lmv->max_def_easize < def_easize) {
296 lmv->max_def_easize = def_easize;
299 if (lmv->max_cookiesize < cookiesize) {
300 lmv->max_cookiesize = cookiesize;
303 if (lmv->max_def_cookiesize < def_cookiesize) {
304 lmv->max_def_cookiesize = def_cookiesize;
310 if (lmv->connected == 0)
313 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
314 if (lmv->tgts[i] == NULL ||
315 lmv->tgts[i]->ltd_exp == NULL ||
316 lmv->tgts[i]->ltd_active == 0) {
317 CWARN("%s: NULL export for %d\n", obd->obd_name, i);
321 rc = md_init_ea_size(lmv->tgts[i]->ltd_exp, easize, def_easize,
322 cookiesize, def_cookiesize);
324 CERROR("%s: obd_init_ea_size() failed on MDT target %d:"
325 " rc = %d.\n", obd->obd_name, i, rc);
332 #define MAX_STRING_SIZE 128
334 int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
336 struct proc_dir_entry *lmv_proc_dir;
337 struct lmv_obd *lmv = &obd->u.lmv;
338 struct obd_uuid *cluuid = &lmv->cluuid;
339 struct obd_uuid lmv_mdc_uuid = { "LMV_MDC_UUID" };
340 struct obd_device *mdc_obd;
341 struct obd_export *mdc_exp;
342 struct lu_fld_target target;
345 mdc_obd = class_find_client_obd(&tgt->ltd_uuid, LUSTRE_MDC_NAME,
348 CERROR("target %s not attached\n", tgt->ltd_uuid.uuid);
352 CDEBUG(D_CONFIG, "connect to %s(%s) - %s, %s FOR %s\n",
353 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
354 tgt->ltd_uuid.uuid, obd->obd_uuid.uuid,
357 if (!mdc_obd->obd_set_up) {
358 CERROR("target %s is not set up\n", tgt->ltd_uuid.uuid);
362 rc = obd_connect(NULL, &mdc_exp, mdc_obd, &lmv_mdc_uuid,
363 &lmv->conn_data, NULL);
365 CERROR("target %s connect error %d\n", tgt->ltd_uuid.uuid, rc);
370 * Init fid sequence client for this mdc and add new fld target.
372 rc = obd_fid_init(mdc_obd, mdc_exp, LUSTRE_SEQ_METADATA);
376 target.ft_srv = NULL;
377 target.ft_exp = mdc_exp;
378 target.ft_idx = tgt->ltd_idx;
380 fld_client_add_target(&lmv->lmv_fld, &target);
382 rc = obd_register_observer(mdc_obd, obd);
384 obd_disconnect(mdc_exp);
385 CERROR("target %s register_observer error %d\n",
386 tgt->ltd_uuid.uuid, rc);
390 if (obd->obd_observer) {
392 * Tell the observer about the new target.
394 rc = obd_notify(obd->obd_observer, mdc_exp->exp_obd,
396 (void *)(tgt - lmv->tgts[0]));
398 obd_disconnect(mdc_exp);
404 tgt->ltd_exp = mdc_exp;
405 lmv->desc.ld_active_tgt_count++;
407 md_init_ea_size(tgt->ltd_exp, lmv->max_easize, lmv->max_def_easize,
408 lmv->max_cookiesize, lmv->max_def_cookiesize);
410 CDEBUG(D_CONFIG, "Connected to %s(%s) successfully (%d)\n",
411 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
412 atomic_read(&obd->obd_refcount));
414 lmv_proc_dir = obd->obd_proc_private;
416 struct proc_dir_entry *mdc_symlink;
418 LASSERT(mdc_obd->obd_type != NULL);
419 LASSERT(mdc_obd->obd_type->typ_name != NULL);
420 mdc_symlink = lprocfs_add_symlink(mdc_obd->obd_name,
423 mdc_obd->obd_type->typ_name,
425 if (mdc_symlink == NULL) {
426 CERROR("Could not register LMV target "
427 "/proc/fs/lustre/%s/%s/target_obds/%s.",
428 obd->obd_type->typ_name, obd->obd_name,
430 lprocfs_remove(&lmv_proc_dir);
431 obd->obd_proc_private = NULL;
437 static void lmv_del_target(struct lmv_obd *lmv, int index)
439 if (lmv->tgts[index] == NULL)
442 OBD_FREE_PTR(lmv->tgts[index]);
443 lmv->tgts[index] = NULL;
447 static int lmv_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
448 __u32 index, int gen)
450 struct lmv_obd *lmv = &obd->u.lmv;
451 struct lmv_tgt_desc *tgt;
454 CDEBUG(D_CONFIG, "Target uuid: %s. index %d\n", uuidp->uuid, index);
458 if (lmv->desc.ld_tgt_count == 0) {
459 struct obd_device *mdc_obd;
461 mdc_obd = class_find_client_obd(uuidp, LUSTRE_MDC_NAME,
464 lmv_init_unlock(lmv);
465 CERROR("%s: Target %s not attached: rc = %d\n",
466 obd->obd_name, uuidp->uuid, -EINVAL);
471 if ((index < lmv->tgts_size) && (lmv->tgts[index] != NULL)) {
472 tgt = lmv->tgts[index];
473 CERROR("%s: UUID %s already assigned at LOV target index %d:"
474 " rc = %d\n", obd->obd_name,
475 obd_uuid2str(&tgt->ltd_uuid), index, -EEXIST);
476 lmv_init_unlock(lmv);
480 if (index >= lmv->tgts_size) {
481 /* We need to reallocate the lmv target array. */
482 struct lmv_tgt_desc **newtgts, **old = NULL;
486 while (newsize < index + 1)
487 newsize = newsize << 1;
488 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
489 if (newtgts == NULL) {
490 lmv_init_unlock(lmv);
494 if (lmv->tgts_size) {
495 memcpy(newtgts, lmv->tgts,
496 sizeof(*newtgts) * lmv->tgts_size);
498 oldsize = lmv->tgts_size;
502 lmv->tgts_size = newsize;
505 OBD_FREE(old, sizeof(*old) * oldsize);
507 CDEBUG(D_CONFIG, "tgts: %p size: %d\n", lmv->tgts,
513 lmv_init_unlock(lmv);
517 mutex_init(&tgt->ltd_fid_mutex);
518 tgt->ltd_idx = index;
519 tgt->ltd_uuid = *uuidp;
521 lmv->tgts[index] = tgt;
522 if (index >= lmv->desc.ld_tgt_count)
523 lmv->desc.ld_tgt_count = index + 1;
525 if (lmv->connected) {
526 rc = lmv_connect_mdc(obd, tgt);
528 spin_lock(&lmv->lmv_lock);
529 lmv->desc.ld_tgt_count--;
530 memset(tgt, 0, sizeof(*tgt));
531 spin_unlock(&lmv->lmv_lock);
533 int easize = sizeof(struct lmv_stripe_md) +
534 lmv->desc.ld_tgt_count * sizeof(struct lu_fid);
535 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0, 0);
539 lmv_init_unlock(lmv);
543 int lmv_check_connect(struct obd_device *obd)
545 struct lmv_obd *lmv = &obd->u.lmv;
546 struct lmv_tgt_desc *tgt;
555 if (lmv->connected) {
556 lmv_init_unlock(lmv);
560 if (lmv->desc.ld_tgt_count == 0) {
561 lmv_init_unlock(lmv);
562 CERROR("%s: no targets configured.\n", obd->obd_name);
566 CDEBUG(D_CONFIG, "Time to connect %s to %s\n",
567 lmv->cluuid.uuid, obd->obd_name);
569 LASSERT(lmv->tgts != NULL);
571 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
575 rc = lmv_connect_mdc(obd, tgt);
580 lmv_set_timeouts(obd);
581 class_export_put(lmv->exp);
583 easize = lmv_get_easize(lmv);
584 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0, 0);
585 lmv_init_unlock(lmv);
596 --lmv->desc.ld_active_tgt_count;
597 rc2 = obd_disconnect(tgt->ltd_exp);
599 CERROR("LMV target %s disconnect on "
600 "MDC idx %d: error %d\n",
601 tgt->ltd_uuid.uuid, i, rc2);
605 class_disconnect(lmv->exp);
606 lmv_init_unlock(lmv);
610 static int lmv_disconnect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
612 struct proc_dir_entry *lmv_proc_dir;
613 struct lmv_obd *lmv = &obd->u.lmv;
614 struct obd_device *mdc_obd;
617 LASSERT(tgt != NULL);
618 LASSERT(obd != NULL);
620 mdc_obd = class_exp2obd(tgt->ltd_exp);
623 mdc_obd->obd_force = obd->obd_force;
624 mdc_obd->obd_fail = obd->obd_fail;
625 mdc_obd->obd_no_recov = obd->obd_no_recov;
628 lmv_proc_dir = obd->obd_proc_private;
630 lprocfs_remove_proc_entry(mdc_obd->obd_name, lmv_proc_dir);
632 rc = obd_fid_fini(tgt->ltd_exp->exp_obd);
634 CERROR("Can't finalize fids factory\n");
636 CDEBUG(D_INFO, "Disconnected from %s(%s) successfully\n",
637 tgt->ltd_exp->exp_obd->obd_name,
638 tgt->ltd_exp->exp_obd->obd_uuid.uuid);
640 obd_register_observer(tgt->ltd_exp->exp_obd, NULL);
641 rc = obd_disconnect(tgt->ltd_exp);
643 if (tgt->ltd_active) {
644 CERROR("Target %s disconnect error %d\n",
645 tgt->ltd_uuid.uuid, rc);
649 lmv_activate_target(lmv, tgt, 0);
654 static int lmv_disconnect(struct obd_export *exp)
656 struct obd_device *obd = class_exp2obd(exp);
657 struct lmv_obd *lmv = &obd->u.lmv;
665 * Only disconnect the underlying layers on the final disconnect.
668 if (lmv->refcount != 0)
671 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
672 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
675 lmv_disconnect_mdc(obd, lmv->tgts[i]);
678 if (obd->obd_proc_private)
679 lprocfs_remove((struct proc_dir_entry **)&obd->obd_proc_private);
681 CERROR("/proc/fs/lustre/%s/%s/target_obds missing\n",
682 obd->obd_type->typ_name, obd->obd_name);
686 * This is the case when no real connection is established by
687 * lmv_check_connect().
690 class_export_put(exp);
691 rc = class_disconnect(exp);
692 if (lmv->refcount == 0)
697 static int lmv_fid2path(struct obd_export *exp, int len, void *karg, void *uarg)
699 struct obd_device *obddev = class_exp2obd(exp);
700 struct lmv_obd *lmv = &obddev->u.lmv;
701 struct getinfo_fid2path *gf;
702 struct lmv_tgt_desc *tgt;
703 struct getinfo_fid2path *remote_gf = NULL;
704 int remote_gf_size = 0;
707 gf = (struct getinfo_fid2path *)karg;
708 tgt = lmv_find_target(lmv, &gf->gf_fid);
713 rc = obd_iocontrol(OBD_IOC_FID2PATH, tgt->ltd_exp, len, gf, uarg);
714 if (rc != 0 && rc != -EREMOTE)
715 GOTO(out_fid2path, rc);
717 /* If remote_gf != NULL, it means just building the
718 * path on the remote MDT, copy this path segment to gf */
719 if (remote_gf != NULL) {
720 struct getinfo_fid2path *ori_gf;
723 ori_gf = (struct getinfo_fid2path *)karg;
724 if (strlen(ori_gf->gf_path) +
725 strlen(gf->gf_path) > ori_gf->gf_pathlen)
726 GOTO(out_fid2path, rc = -EOVERFLOW);
728 ptr = ori_gf->gf_path;
730 memmove(ptr + strlen(gf->gf_path) + 1, ptr,
731 strlen(ori_gf->gf_path));
733 strncpy(ptr, gf->gf_path, strlen(gf->gf_path));
734 ptr += strlen(gf->gf_path);
738 CDEBUG(D_INFO, "%s: get path %s "DFID" rec: %llu ln: %u\n",
739 tgt->ltd_exp->exp_obd->obd_name,
740 gf->gf_path, PFID(&gf->gf_fid), gf->gf_recno,
744 GOTO(out_fid2path, rc);
746 /* sigh, has to go to another MDT to do path building further */
747 if (remote_gf == NULL) {
748 remote_gf_size = sizeof(*remote_gf) + PATH_MAX;
749 OBD_ALLOC(remote_gf, remote_gf_size);
750 if (remote_gf == NULL)
751 GOTO(out_fid2path, rc = -ENOMEM);
752 remote_gf->gf_pathlen = PATH_MAX;
755 if (!fid_is_sane(&gf->gf_fid)) {
756 CERROR("%s: invalid FID "DFID": rc = %d\n",
757 tgt->ltd_exp->exp_obd->obd_name,
758 PFID(&gf->gf_fid), -EINVAL);
759 GOTO(out_fid2path, rc = -EINVAL);
762 tgt = lmv_find_target(lmv, &gf->gf_fid);
764 GOTO(out_fid2path, rc = -EINVAL);
766 remote_gf->gf_fid = gf->gf_fid;
767 remote_gf->gf_recno = -1;
768 remote_gf->gf_linkno = -1;
769 memset(remote_gf->gf_path, 0, remote_gf->gf_pathlen);
771 goto repeat_fid2path;
774 if (remote_gf != NULL)
775 OBD_FREE(remote_gf, remote_gf_size);
779 static int lmv_hsm_req_count(struct lmv_obd *lmv,
780 const struct hsm_user_request *hur,
781 const struct lmv_tgt_desc *tgt_mds)
784 struct lmv_tgt_desc *curr_tgt;
786 /* count how many requests must be sent to the given target */
787 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
788 curr_tgt = lmv_find_target(lmv, &hur->hur_user_item[i].hui_fid);
789 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid))
795 static void lmv_hsm_req_build(struct lmv_obd *lmv,
796 struct hsm_user_request *hur_in,
797 const struct lmv_tgt_desc *tgt_mds,
798 struct hsm_user_request *hur_out)
801 struct lmv_tgt_desc *curr_tgt;
803 /* build the hsm_user_request for the given target */
804 hur_out->hur_request = hur_in->hur_request;
806 for (i = 0; i < hur_in->hur_request.hr_itemcount; i++) {
807 curr_tgt = lmv_find_target(lmv,
808 &hur_in->hur_user_item[i].hui_fid);
809 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid)) {
810 hur_out->hur_user_item[nr_out] =
811 hur_in->hur_user_item[i];
815 hur_out->hur_request.hr_itemcount = nr_out;
816 memcpy(hur_data(hur_out), hur_data(hur_in),
817 hur_in->hur_request.hr_data_len);
820 static int lmv_hsm_ct_unregister(struct lmv_obd *lmv, unsigned int cmd, int len,
821 struct lustre_kernelcomm *lk, void *uarg)
825 /* unregister request (call from llapi_hsm_copytool_fini) */
826 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
827 /* best effort: try to clean as much as possible
828 * (continue on error) */
829 obd_iocontrol(cmd, lmv->tgts[i]->ltd_exp, len, lk, uarg);
832 /* Whatever the result, remove copytool from kuc groups.
833 * Unreached coordinators will get EPIPE on next requests
834 * and will unregister automatically.
836 rc = libcfs_kkuc_group_rem(lk->lk_uid, lk->lk_group);
840 static int lmv_hsm_ct_register(struct lmv_obd *lmv, unsigned int cmd, int len,
841 struct lustre_kernelcomm *lk, void *uarg)
846 bool any_set = false;
848 /* All or nothing: try to register to all MDS.
849 * In case of failure, unregister from previous MDS,
850 * except if it because of inactive target. */
851 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
852 err = obd_iocontrol(cmd, lmv->tgts[i]->ltd_exp,
855 if (lmv->tgts[i]->ltd_active) {
856 /* permanent error */
857 CERROR("error: iocontrol MDC %s on MDT"
858 "idx %d cmd %x: err = %d\n",
859 lmv->tgts[i]->ltd_uuid.uuid,
862 lk->lk_flags |= LK_FLG_STOP;
863 /* unregister from previous MDS */
864 for (j = 0; j < i; j++)
866 lmv->tgts[j]->ltd_exp,
870 /* else: transient error.
871 * kuc will register to the missing MDT
879 /* no registration done: return error */
882 /* at least one registration done, with no failure */
883 filp = fget(lk->lk_wfd);
887 rc = libcfs_kkuc_group_add(filp, lk->lk_uid, lk->lk_group, lk->lk_data);
888 if (rc != 0 && filp != NULL)
896 static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
897 int len, void *karg, void *uarg)
899 struct obd_device *obddev = class_exp2obd(exp);
900 struct lmv_obd *lmv = &obddev->u.lmv;
904 int count = lmv->desc.ld_tgt_count;
910 case IOC_OBD_STATFS: {
911 struct obd_ioctl_data *data = karg;
912 struct obd_device *mdc_obd;
913 struct obd_statfs stat_buf = {0};
916 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
917 if ((index >= count))
920 if (lmv->tgts[index] == NULL ||
921 lmv->tgts[index]->ltd_active == 0)
924 mdc_obd = class_exp2obd(lmv->tgts[index]->ltd_exp);
929 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(mdc_obd),
930 min((int) data->ioc_plen2,
931 (int) sizeof(struct obd_uuid))))
934 rc = obd_statfs(NULL, lmv->tgts[index]->ltd_exp, &stat_buf,
935 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
939 if (copy_to_user(data->ioc_pbuf1, &stat_buf,
940 min((int) data->ioc_plen1,
941 (int) sizeof(stat_buf))))
945 case OBD_IOC_QUOTACTL: {
946 struct if_quotactl *qctl = karg;
947 struct lmv_tgt_desc *tgt = NULL;
948 struct obd_quotactl *oqctl;
950 if (qctl->qc_valid == QC_MDTIDX) {
951 if (qctl->qc_idx < 0 || count <= qctl->qc_idx)
954 tgt = lmv->tgts[qctl->qc_idx];
955 if (tgt == NULL || tgt->ltd_exp == NULL)
957 } else if (qctl->qc_valid == QC_UUID) {
958 for (i = 0; i < count; i++) {
962 if (!obd_uuid_equals(&tgt->ltd_uuid,
966 if (tgt->ltd_exp == NULL)
978 LASSERT(tgt && tgt->ltd_exp);
979 OBD_ALLOC_PTR(oqctl);
983 QCTL_COPY(oqctl, qctl);
984 rc = obd_quotactl(tgt->ltd_exp, oqctl);
986 QCTL_COPY(qctl, oqctl);
987 qctl->qc_valid = QC_MDTIDX;
988 qctl->obd_uuid = tgt->ltd_uuid;
993 case OBD_IOC_CHANGELOG_SEND:
994 case OBD_IOC_CHANGELOG_CLEAR: {
995 struct ioc_changelog *icc = karg;
997 if (icc->icc_mdtindex >= count)
1000 if (lmv->tgts[icc->icc_mdtindex] == NULL ||
1001 lmv->tgts[icc->icc_mdtindex]->ltd_exp == NULL ||
1002 lmv->tgts[icc->icc_mdtindex]->ltd_active == 0)
1004 rc = obd_iocontrol(cmd, lmv->tgts[icc->icc_mdtindex]->ltd_exp,
1005 sizeof(*icc), icc, NULL);
1008 case LL_IOC_GET_CONNECT_FLAGS: {
1009 if (lmv->tgts[0] == NULL)
1011 rc = obd_iocontrol(cmd, lmv->tgts[0]->ltd_exp, len, karg, uarg);
1014 case OBD_IOC_FID2PATH: {
1015 rc = lmv_fid2path(exp, len, karg, uarg);
1018 case LL_IOC_HSM_STATE_GET:
1019 case LL_IOC_HSM_STATE_SET:
1020 case LL_IOC_HSM_ACTION: {
1021 struct md_op_data *op_data = karg;
1022 struct lmv_tgt_desc *tgt;
1024 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1026 return PTR_ERR(tgt);
1028 if (tgt->ltd_exp == NULL)
1031 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1034 case LL_IOC_HSM_PROGRESS: {
1035 const struct hsm_progress_kernel *hpk = karg;
1036 struct lmv_tgt_desc *tgt;
1038 tgt = lmv_find_target(lmv, &hpk->hpk_fid);
1040 return PTR_ERR(tgt);
1041 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1044 case LL_IOC_HSM_REQUEST: {
1045 struct hsm_user_request *hur = karg;
1046 struct lmv_tgt_desc *tgt;
1047 unsigned int reqcount = hur->hur_request.hr_itemcount;
1052 /* if the request is about a single fid
1053 * or if there is a single MDS, no need to split
1055 if (reqcount == 1 || count == 1) {
1056 tgt = lmv_find_target(lmv,
1057 &hur->hur_user_item[0].hui_fid);
1059 return PTR_ERR(tgt);
1060 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1062 /* split fid list to their respective MDS */
1063 for (i = 0; i < count; i++) {
1064 unsigned int nr, reqlen;
1066 struct hsm_user_request *req;
1068 nr = lmv_hsm_req_count(lmv, hur, lmv->tgts[i]);
1069 if (nr == 0) /* nothing for this MDS */
1072 /* build a request with fids for this MDS */
1073 reqlen = offsetof(typeof(*hur),
1075 + hur->hur_request.hr_data_len;
1076 OBD_ALLOC_LARGE(req, reqlen);
1080 lmv_hsm_req_build(lmv, hur, lmv->tgts[i], req);
1082 rc1 = obd_iocontrol(cmd, lmv->tgts[i]->ltd_exp,
1084 if (rc1 != 0 && rc == 0)
1086 OBD_FREE_LARGE(req, reqlen);
1091 case LL_IOC_LOV_SWAP_LAYOUTS: {
1092 struct md_op_data *op_data = karg;
1093 struct lmv_tgt_desc *tgt1, *tgt2;
1095 tgt1 = lmv_find_target(lmv, &op_data->op_fid1);
1097 return PTR_ERR(tgt1);
1099 tgt2 = lmv_find_target(lmv, &op_data->op_fid2);
1101 return PTR_ERR(tgt2);
1103 if ((tgt1->ltd_exp == NULL) || (tgt2->ltd_exp == NULL))
1106 /* only files on same MDT can have their layouts swapped */
1107 if (tgt1->ltd_idx != tgt2->ltd_idx)
1110 rc = obd_iocontrol(cmd, tgt1->ltd_exp, len, karg, uarg);
1113 case LL_IOC_HSM_CT_START: {
1114 struct lustre_kernelcomm *lk = karg;
1115 if (lk->lk_flags & LK_FLG_STOP)
1116 rc = lmv_hsm_ct_unregister(lmv, cmd, len, lk, uarg);
1118 rc = lmv_hsm_ct_register(lmv, cmd, len, lk, uarg);
1122 for (i = 0; i < count; i++) {
1123 struct obd_device *mdc_obd;
1126 if (lmv->tgts[i] == NULL ||
1127 lmv->tgts[i]->ltd_exp == NULL)
1129 /* ll_umount_begin() sets force flag but for lmv, not
1130 * mdc. Let's pass it through */
1131 mdc_obd = class_exp2obd(lmv->tgts[i]->ltd_exp);
1132 mdc_obd->obd_force = obddev->obd_force;
1133 err = obd_iocontrol(cmd, lmv->tgts[i]->ltd_exp, len,
1135 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
1138 if (lmv->tgts[i]->ltd_active) {
1139 CERROR("error: iocontrol MDC %s on MDT"
1140 "idx %d cmd %x: err = %d\n",
1141 lmv->tgts[i]->ltd_uuid.uuid,
1156 static int lmv_all_chars_policy(int count, const char *name,
1167 static int lmv_nid_policy(struct lmv_obd *lmv)
1169 struct obd_import *imp;
1173 * XXX: To get nid we assume that underlying obd device is mdc.
1175 imp = class_exp2cliimp(lmv->tgts[0].ltd_exp);
1176 id = imp->imp_connection->c_self ^ (imp->imp_connection->c_self >> 32);
1177 return id % lmv->desc.ld_tgt_count;
1180 static int lmv_choose_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1181 placement_policy_t placement)
1183 switch (placement) {
1184 case PLACEMENT_CHAR_POLICY:
1185 return lmv_all_chars_policy(lmv->desc.ld_tgt_count,
1187 op_data->op_namelen);
1188 case PLACEMENT_NID_POLICY:
1189 return lmv_nid_policy(lmv);
1195 CERROR("Unsupported placement policy %x\n", placement);
1201 * This is _inode_ placement policy function (not name).
1203 static int lmv_placement_policy(struct obd_device *obd,
1204 struct md_op_data *op_data, u32 *mds)
1206 struct lmv_obd *lmv = &obd->u.lmv;
1208 LASSERT(mds != NULL);
1210 if (lmv->desc.ld_tgt_count == 1) {
1216 * If stripe_offset is provided during setdirstripe
1217 * (setdirstripe -i xx), xx MDS will be chosen.
1219 if (op_data->op_cli_flags & CLI_SET_MEA) {
1220 struct lmv_user_md *lum;
1222 lum = (struct lmv_user_md *)op_data->op_data;
1223 if (lum->lum_type == LMV_STRIPE_TYPE &&
1224 lum->lum_stripe_offset != -1) {
1225 if (lum->lum_stripe_offset >= lmv->desc.ld_tgt_count) {
1226 CERROR("%s: Stripe_offset %d > MDT count %d:"
1227 " rc = %d\n", obd->obd_name,
1228 lum->lum_stripe_offset,
1229 lmv->desc.ld_tgt_count, -ERANGE);
1232 *mds = lum->lum_stripe_offset;
1237 /* Allocate new fid on target according to operation type and parent
1239 *mds = op_data->op_mds;
1243 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid, u32 mds)
1245 struct lmv_tgt_desc *tgt;
1248 tgt = lmv_get_target(lmv, mds);
1250 return PTR_ERR(tgt);
1253 * New seq alloc and FLD setup should be atomic. Otherwise we may find
1254 * on server that seq in new allocated fid is not yet known.
1256 mutex_lock(&tgt->ltd_fid_mutex);
1258 if (tgt->ltd_active == 0 || tgt->ltd_exp == NULL)
1259 GOTO(out, rc = -ENODEV);
1262 * Asking underlaying tgt layer to allocate new fid.
1264 rc = obd_fid_alloc(tgt->ltd_exp, fid, NULL);
1266 LASSERT(fid_is_sane(fid));
1271 mutex_unlock(&tgt->ltd_fid_mutex);
1275 int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
1276 struct md_op_data *op_data)
1278 struct obd_device *obd = class_exp2obd(exp);
1279 struct lmv_obd *lmv = &obd->u.lmv;
1283 LASSERT(op_data != NULL);
1284 LASSERT(fid != NULL);
1286 rc = lmv_placement_policy(obd, op_data, &mds);
1288 CERROR("Can't get target for allocating fid, "
1293 rc = __lmv_fid_alloc(lmv, fid, mds);
1295 CERROR("Can't alloc new fid, rc %d\n", rc);
1302 static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
1304 struct lmv_obd *lmv = &obd->u.lmv;
1305 struct lprocfs_static_vars lvars;
1306 struct lmv_desc *desc;
1309 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
1310 CERROR("LMV setup requires a descriptor\n");
1314 desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1);
1315 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
1316 CERROR("Lmv descriptor size wrong: %d > %d\n",
1317 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
1321 OBD_ALLOC(lmv->tgts, sizeof(*lmv->tgts) * 32);
1322 if (lmv->tgts == NULL)
1324 lmv->tgts_size = 32;
1326 obd_str2uuid(&lmv->desc.ld_uuid, desc->ld_uuid.uuid);
1327 lmv->desc.ld_tgt_count = 0;
1328 lmv->desc.ld_active_tgt_count = 0;
1329 lmv->max_cookiesize = 0;
1330 lmv->max_def_easize = 0;
1331 lmv->max_easize = 0;
1332 lmv->lmv_placement = PLACEMENT_CHAR_POLICY;
1334 spin_lock_init(&lmv->lmv_lock);
1335 mutex_init(&lmv->init_mutex);
1337 lprocfs_lmv_init_vars(&lvars);
1339 lprocfs_obd_setup(obd, lvars.obd_vars);
1340 #if defined (CONFIG_PROC_FS)
1342 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
1343 0444, &lmv_proc_target_fops, obd);
1345 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
1349 rc = fld_client_init(&lmv->lmv_fld, obd->obd_name,
1350 LUSTRE_CLI_FLD_HASH_DHT);
1352 CERROR("Can't init FLD, err %d\n", rc);
1362 static int lmv_cleanup(struct obd_device *obd)
1364 struct lmv_obd *lmv = &obd->u.lmv;
1366 fld_client_fini(&lmv->lmv_fld);
1367 if (lmv->tgts != NULL) {
1369 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1370 if (lmv->tgts[i] == NULL)
1372 lmv_del_target(lmv, i);
1374 OBD_FREE(lmv->tgts, sizeof(*lmv->tgts) * lmv->tgts_size);
1380 static int lmv_process_config(struct obd_device *obd, u32 len, void *buf)
1382 struct lustre_cfg *lcfg = buf;
1383 struct obd_uuid obd_uuid;
1388 switch (lcfg->lcfg_command) {
1390 /* modify_mdc_tgts add 0:lustre-clilmv 1:lustre-MDT0000_UUID
1391 * 2:0 3:1 4:lustre-MDT0000-mdc_UUID */
1392 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
1393 GOTO(out, rc = -EINVAL);
1395 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
1397 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
1398 GOTO(out, rc = -EINVAL);
1399 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
1400 GOTO(out, rc = -EINVAL);
1401 rc = lmv_add_target(obd, &obd_uuid, index, gen);
1404 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1405 GOTO(out, rc = -EINVAL);
1411 static int lmv_statfs(const struct lu_env *env, struct obd_export *exp,
1412 struct obd_statfs *osfs, __u64 max_age, __u32 flags)
1414 struct obd_device *obd = class_exp2obd(exp);
1415 struct lmv_obd *lmv = &obd->u.lmv;
1416 struct obd_statfs *temp;
1420 rc = lmv_check_connect(obd);
1424 OBD_ALLOC(temp, sizeof(*temp));
1428 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1429 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1432 rc = obd_statfs(env, lmv->tgts[i]->ltd_exp, temp,
1435 CERROR("can't stat MDS #%d (%s), error %d\n", i,
1436 lmv->tgts[i]->ltd_exp->exp_obd->obd_name,
1438 GOTO(out_free_temp, rc);
1443 /* If the statfs is from mount, it will needs
1444 * retrieve necessary information from MDT0.
1445 * i.e. mount does not need the merged osfs
1447 * And also clients can be mounted as long as
1448 * MDT0 is in service*/
1449 if (flags & OBD_STATFS_FOR_MDT0)
1450 GOTO(out_free_temp, rc);
1452 osfs->os_bavail += temp->os_bavail;
1453 osfs->os_blocks += temp->os_blocks;
1454 osfs->os_ffree += temp->os_ffree;
1455 osfs->os_files += temp->os_files;
1460 OBD_FREE(temp, sizeof(*temp));
1464 static int lmv_getstatus(struct obd_export *exp,
1466 struct obd_capa **pc)
1468 struct obd_device *obd = exp->exp_obd;
1469 struct lmv_obd *lmv = &obd->u.lmv;
1472 rc = lmv_check_connect(obd);
1476 rc = md_getstatus(lmv->tgts[0]->ltd_exp, fid, pc);
1480 static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1481 struct obd_capa *oc, u64 valid, const char *name,
1482 const char *input, int input_size, int output_size,
1483 int flags, struct ptlrpc_request **request)
1485 struct obd_device *obd = exp->exp_obd;
1486 struct lmv_obd *lmv = &obd->u.lmv;
1487 struct lmv_tgt_desc *tgt;
1490 rc = lmv_check_connect(obd);
1494 tgt = lmv_find_target(lmv, fid);
1496 return PTR_ERR(tgt);
1498 rc = md_getxattr(tgt->ltd_exp, fid, oc, valid, name, input,
1499 input_size, output_size, flags, request);
1504 static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1505 struct obd_capa *oc, u64 valid, const char *name,
1506 const char *input, int input_size, int output_size,
1507 int flags, __u32 suppgid,
1508 struct ptlrpc_request **request)
1510 struct obd_device *obd = exp->exp_obd;
1511 struct lmv_obd *lmv = &obd->u.lmv;
1512 struct lmv_tgt_desc *tgt;
1515 rc = lmv_check_connect(obd);
1519 tgt = lmv_find_target(lmv, fid);
1521 return PTR_ERR(tgt);
1523 rc = md_setxattr(tgt->ltd_exp, fid, oc, valid, name, input,
1524 input_size, output_size, flags, suppgid,
1530 static int lmv_getattr(struct obd_export *exp, struct md_op_data *op_data,
1531 struct ptlrpc_request **request)
1533 struct obd_device *obd = exp->exp_obd;
1534 struct lmv_obd *lmv = &obd->u.lmv;
1535 struct lmv_tgt_desc *tgt;
1538 rc = lmv_check_connect(obd);
1542 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1544 return PTR_ERR(tgt);
1546 if (op_data->op_flags & MF_GET_MDT_IDX) {
1547 op_data->op_mds = tgt->ltd_idx;
1551 rc = md_getattr(tgt->ltd_exp, op_data, request);
1556 static int lmv_null_inode(struct obd_export *exp, const struct lu_fid *fid)
1558 struct obd_device *obd = exp->exp_obd;
1559 struct lmv_obd *lmv = &obd->u.lmv;
1563 rc = lmv_check_connect(obd);
1567 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1570 * With DNE every object can have two locks in different namespaces:
1571 * lookup lock in space of MDT storing direntry and update/open lock in
1572 * space of MDT storing inode.
1574 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1575 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1577 md_null_inode(lmv->tgts[i]->ltd_exp, fid);
1583 static int lmv_find_cbdata(struct obd_export *exp, const struct lu_fid *fid,
1584 ldlm_iterator_t it, void *data)
1586 struct obd_device *obd = exp->exp_obd;
1587 struct lmv_obd *lmv = &obd->u.lmv;
1591 rc = lmv_check_connect(obd);
1595 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1598 * With DNE every object can have two locks in different namespaces:
1599 * lookup lock in space of MDT storing direntry and update/open lock in
1600 * space of MDT storing inode.
1602 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1603 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1605 rc = md_find_cbdata(lmv->tgts[i]->ltd_exp, fid, it, data);
1614 static int lmv_close(struct obd_export *exp, struct md_op_data *op_data,
1615 struct md_open_data *mod, struct ptlrpc_request **request)
1617 struct obd_device *obd = exp->exp_obd;
1618 struct lmv_obd *lmv = &obd->u.lmv;
1619 struct lmv_tgt_desc *tgt;
1622 rc = lmv_check_connect(obd);
1626 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1628 return PTR_ERR(tgt);
1630 CDEBUG(D_INODE, "CLOSE "DFID"\n", PFID(&op_data->op_fid1));
1631 rc = md_close(tgt->ltd_exp, op_data, mod, request);
1636 *lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1639 struct lmv_tgt_desc *tgt;
1641 tgt = lmv_find_target(lmv, fid);
1645 op_data->op_mds = tgt->ltd_idx;
1650 int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
1651 const void *data, int datalen, int mode, __u32 uid,
1652 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1653 struct ptlrpc_request **request)
1655 struct obd_device *obd = exp->exp_obd;
1656 struct lmv_obd *lmv = &obd->u.lmv;
1657 struct lmv_tgt_desc *tgt;
1660 rc = lmv_check_connect(obd);
1664 if (!lmv->desc.ld_active_tgt_count)
1667 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1669 return PTR_ERR(tgt);
1671 rc = lmv_fid_alloc(exp, &op_data->op_fid2, op_data);
1675 CDEBUG(D_INODE, "CREATE '%*s' on "DFID" -> mds #%x\n",
1676 op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1),
1679 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1680 rc = md_create(tgt->ltd_exp, op_data, data, datalen, mode, uid, gid,
1681 cap_effective, rdev, request);
1684 if (*request == NULL)
1686 CDEBUG(D_INODE, "Created - "DFID"\n", PFID(&op_data->op_fid2));
1691 static int lmv_done_writing(struct obd_export *exp,
1692 struct md_op_data *op_data,
1693 struct md_open_data *mod)
1695 struct obd_device *obd = exp->exp_obd;
1696 struct lmv_obd *lmv = &obd->u.lmv;
1697 struct lmv_tgt_desc *tgt;
1700 rc = lmv_check_connect(obd);
1704 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1706 return PTR_ERR(tgt);
1708 rc = md_done_writing(tgt->ltd_exp, op_data, mod);
1713 lmv_enqueue_remote(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1714 struct lookup_intent *it, struct md_op_data *op_data,
1715 struct lustre_handle *lockh, void *lmm, int lmmsize,
1716 __u64 extra_lock_flags)
1718 struct ptlrpc_request *req = it->d.lustre.it_data;
1719 struct obd_device *obd = exp->exp_obd;
1720 struct lmv_obd *lmv = &obd->u.lmv;
1721 struct lustre_handle plock;
1722 struct lmv_tgt_desc *tgt;
1723 struct md_op_data *rdata;
1725 struct mdt_body *body;
1729 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1730 LASSERT(body != NULL);
1732 if (!(body->valid & OBD_MD_MDS))
1735 CDEBUG(D_INODE, "REMOTE_ENQUEUE '%s' on "DFID" -> "DFID"\n",
1736 LL_IT2STR(it), PFID(&op_data->op_fid1), PFID(&body->fid1));
1739 * We got LOOKUP lock, but we really need attrs.
1741 pmode = it->d.lustre.it_lock_mode;
1742 LASSERT(pmode != 0);
1743 memcpy(&plock, lockh, sizeof(plock));
1744 it->d.lustre.it_lock_mode = 0;
1745 it->d.lustre.it_data = NULL;
1748 ptlrpc_req_finished(req);
1750 tgt = lmv_find_target(lmv, &fid1);
1752 GOTO(out, rc = PTR_ERR(tgt));
1754 OBD_ALLOC_PTR(rdata);
1756 GOTO(out, rc = -ENOMEM);
1758 rdata->op_fid1 = fid1;
1759 rdata->op_bias = MDS_CROSS_REF;
1761 rc = md_enqueue(tgt->ltd_exp, einfo, it, rdata, lockh,
1762 lmm, lmmsize, NULL, extra_lock_flags);
1763 OBD_FREE_PTR(rdata);
1765 ldlm_lock_decref(&plock, pmode);
1770 lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1771 struct lookup_intent *it, struct md_op_data *op_data,
1772 struct lustre_handle *lockh, void *lmm, int lmmsize,
1773 struct ptlrpc_request **req, __u64 extra_lock_flags)
1775 struct obd_device *obd = exp->exp_obd;
1776 struct lmv_obd *lmv = &obd->u.lmv;
1777 struct lmv_tgt_desc *tgt;
1780 rc = lmv_check_connect(obd);
1784 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID"\n",
1785 LL_IT2STR(it), PFID(&op_data->op_fid1));
1787 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1789 return PTR_ERR(tgt);
1791 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID" -> mds #%d\n",
1792 LL_IT2STR(it), PFID(&op_data->op_fid1), tgt->ltd_idx);
1794 rc = md_enqueue(tgt->ltd_exp, einfo, it, op_data, lockh,
1795 lmm, lmmsize, req, extra_lock_flags);
1797 if (rc == 0 && it && it->it_op == IT_OPEN) {
1798 rc = lmv_enqueue_remote(exp, einfo, it, op_data, lockh,
1799 lmm, lmmsize, extra_lock_flags);
1805 lmv_getattr_name(struct obd_export *exp, struct md_op_data *op_data,
1806 struct ptlrpc_request **request)
1808 struct ptlrpc_request *req = NULL;
1809 struct obd_device *obd = exp->exp_obd;
1810 struct lmv_obd *lmv = &obd->u.lmv;
1811 struct lmv_tgt_desc *tgt;
1812 struct mdt_body *body;
1815 rc = lmv_check_connect(obd);
1819 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1821 return PTR_ERR(tgt);
1823 CDEBUG(D_INODE, "GETATTR_NAME for %*s on "DFID" -> mds #%d\n",
1824 op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1),
1827 rc = md_getattr_name(tgt->ltd_exp, op_data, request);
1831 body = req_capsule_server_get(&(*request)->rq_pill,
1833 LASSERT(body != NULL);
1835 if (body->valid & OBD_MD_MDS) {
1836 struct lu_fid rid = body->fid1;
1837 CDEBUG(D_INODE, "Request attrs for "DFID"\n",
1840 tgt = lmv_find_target(lmv, &rid);
1842 ptlrpc_req_finished(*request);
1843 return PTR_ERR(tgt);
1846 op_data->op_fid1 = rid;
1847 op_data->op_valid |= OBD_MD_FLCROSSREF;
1848 op_data->op_namelen = 0;
1849 op_data->op_name = NULL;
1850 rc = md_getattr_name(tgt->ltd_exp, op_data, &req);
1851 ptlrpc_req_finished(*request);
1858 #define md_op_data_fid(op_data, fl) \
1859 (fl == MF_MDC_CANCEL_FID1 ? &op_data->op_fid1 : \
1860 fl == MF_MDC_CANCEL_FID2 ? &op_data->op_fid2 : \
1861 fl == MF_MDC_CANCEL_FID3 ? &op_data->op_fid3 : \
1862 fl == MF_MDC_CANCEL_FID4 ? &op_data->op_fid4 : \
1865 static int lmv_early_cancel(struct obd_export *exp, struct md_op_data *op_data,
1866 int op_tgt, ldlm_mode_t mode, int bits, int flag)
1868 struct lu_fid *fid = md_op_data_fid(op_data, flag);
1869 struct obd_device *obd = exp->exp_obd;
1870 struct lmv_obd *lmv = &obd->u.lmv;
1871 struct lmv_tgt_desc *tgt;
1872 ldlm_policy_data_t policy = {{0}};
1875 if (!fid_is_sane(fid))
1878 tgt = lmv_find_target(lmv, fid);
1880 return PTR_ERR(tgt);
1882 if (tgt->ltd_idx != op_tgt) {
1883 CDEBUG(D_INODE, "EARLY_CANCEL on "DFID"\n", PFID(fid));
1884 policy.l_inodebits.bits = bits;
1885 rc = md_cancel_unused(tgt->ltd_exp, fid, &policy,
1886 mode, LCF_ASYNC, NULL);
1889 "EARLY_CANCEL skip operation target %d on "DFID"\n",
1891 op_data->op_flags |= flag;
1899 * llite passes fid of an target inode in op_data->op_fid1 and id of directory in
1902 static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
1903 struct ptlrpc_request **request)
1905 struct obd_device *obd = exp->exp_obd;
1906 struct lmv_obd *lmv = &obd->u.lmv;
1907 struct lmv_tgt_desc *tgt;
1910 rc = lmv_check_connect(obd);
1914 LASSERT(op_data->op_namelen != 0);
1916 CDEBUG(D_INODE, "LINK "DFID":%*s to "DFID"\n",
1917 PFID(&op_data->op_fid2), op_data->op_namelen,
1918 op_data->op_name, PFID(&op_data->op_fid1));
1920 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
1921 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
1922 op_data->op_cap = cfs_curproc_cap_pack();
1923 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
1925 return PTR_ERR(tgt);
1928 * Cancel UPDATE lock on child (fid1).
1930 op_data->op_flags |= MF_MDC_CANCEL_FID2;
1931 rc = lmv_early_cancel(exp, op_data, tgt->ltd_idx, LCK_EX,
1932 MDS_INODELOCK_UPDATE, MF_MDC_CANCEL_FID1);
1936 rc = md_link(tgt->ltd_exp, op_data, request);
1941 static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
1942 const char *old, int oldlen, const char *new, int newlen,
1943 struct ptlrpc_request **request)
1945 struct obd_device *obd = exp->exp_obd;
1946 struct lmv_obd *lmv = &obd->u.lmv;
1947 struct lmv_tgt_desc *src_tgt;
1948 struct lmv_tgt_desc *tgt_tgt;
1951 LASSERT(oldlen != 0);
1953 CDEBUG(D_INODE, "RENAME %*s in "DFID" to %*s in "DFID"\n",
1954 oldlen, old, PFID(&op_data->op_fid1),
1955 newlen, new, PFID(&op_data->op_fid2));
1957 rc = lmv_check_connect(obd);
1961 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
1962 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
1963 op_data->op_cap = cfs_curproc_cap_pack();
1964 src_tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1965 if (IS_ERR(src_tgt))
1966 return PTR_ERR(src_tgt);
1968 tgt_tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
1969 if (IS_ERR(tgt_tgt))
1970 return PTR_ERR(tgt_tgt);
1972 * LOOKUP lock on src child (fid3) should also be cancelled for
1973 * src_tgt in mdc_rename.
1975 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
1978 * Cancel UPDATE locks on tgt parent (fid2), tgt_tgt is its
1981 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
1982 LCK_EX, MDS_INODELOCK_UPDATE,
1983 MF_MDC_CANCEL_FID2);
1986 * Cancel LOOKUP locks on tgt child (fid4) for parent tgt_tgt.
1989 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
1990 LCK_EX, MDS_INODELOCK_LOOKUP,
1991 MF_MDC_CANCEL_FID4);
1995 * Cancel all the locks on tgt child (fid4).
1998 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
1999 LCK_EX, MDS_INODELOCK_FULL,
2000 MF_MDC_CANCEL_FID4);
2003 rc = md_rename(src_tgt->ltd_exp, op_data, old, oldlen,
2004 new, newlen, request);
2008 static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
2009 void *ea, int ealen, void *ea2, int ea2len,
2010 struct ptlrpc_request **request,
2011 struct md_open_data **mod)
2013 struct obd_device *obd = exp->exp_obd;
2014 struct lmv_obd *lmv = &obd->u.lmv;
2015 struct lmv_tgt_desc *tgt;
2018 rc = lmv_check_connect(obd);
2022 CDEBUG(D_INODE, "SETATTR for "DFID", valid 0x%x\n",
2023 PFID(&op_data->op_fid1), op_data->op_attr.ia_valid);
2025 op_data->op_flags |= MF_MDC_CANCEL_FID1;
2026 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2028 return PTR_ERR(tgt);
2030 rc = md_setattr(tgt->ltd_exp, op_data, ea, ealen, ea2,
2031 ea2len, request, mod);
2036 static int lmv_sync(struct obd_export *exp, const struct lu_fid *fid,
2037 struct obd_capa *oc, struct ptlrpc_request **request)
2039 struct obd_device *obd = exp->exp_obd;
2040 struct lmv_obd *lmv = &obd->u.lmv;
2041 struct lmv_tgt_desc *tgt;
2044 rc = lmv_check_connect(obd);
2048 tgt = lmv_find_target(lmv, fid);
2050 return PTR_ERR(tgt);
2052 rc = md_sync(tgt->ltd_exp, fid, oc, request);
2057 * Adjust a set of pages, each page containing an array of lu_dirpages,
2058 * so that each page can be used as a single logical lu_dirpage.
2060 * A lu_dirpage is laid out as follows, where s = ldp_hash_start,
2061 * e = ldp_hash_end, f = ldp_flags, p = padding, and each "ent" is a
2062 * struct lu_dirent. It has size up to LU_PAGE_SIZE. The ldp_hash_end
2063 * value is used as a cookie to request the next lu_dirpage in a
2064 * directory listing that spans multiple pages (two in this example):
2067 * .|--------v------- -----.
2068 * |s|e|f|p|ent|ent| ... |ent|
2069 * '--|-------------- -----' Each CFS_PAGE contains a single
2070 * '------. lu_dirpage.
2071 * .---------v------- -----.
2072 * |s|e|f|p|ent| 0 | ... | 0 |
2073 * '----------------- -----'
2075 * However, on hosts where the native VM page size (PAGE_CACHE_SIZE) is
2076 * larger than LU_PAGE_SIZE, a single host page may contain multiple
2077 * lu_dirpages. After reading the lu_dirpages from the MDS, the
2078 * ldp_hash_end of the first lu_dirpage refers to the one immediately
2079 * after it in the same CFS_PAGE (arrows simplified for brevity, but
2080 * in general e0==s1, e1==s2, etc.):
2082 * .-------------------- -----.
2083 * |s0|e0|f0|p|ent|ent| ... |ent|
2084 * |---v---------------- -----|
2085 * |s1|e1|f1|p|ent|ent| ... |ent|
2086 * |---v---------------- -----| Here, each CFS_PAGE contains
2087 * ... multiple lu_dirpages.
2088 * |---v---------------- -----|
2089 * |s'|e'|f'|p|ent|ent| ... |ent|
2090 * '---|---------------- -----'
2092 * .----------------------------.
2095 * This structure is transformed into a single logical lu_dirpage as follows:
2097 * - Replace e0 with e' so the request for the next lu_dirpage gets the page
2098 * labeled 'next CFS_PAGE'.
2100 * - Copy the LDF_COLLIDE flag from f' to f0 to correctly reflect whether
2101 * a hash collision with the next page exists.
2103 * - Adjust the lde_reclen of the ending entry of each lu_dirpage to span
2104 * to the first entry of the next lu_dirpage.
2106 #if PAGE_CACHE_SIZE > LU_PAGE_SIZE
2107 static void lmv_adjust_dirpages(struct page **pages, int ncfspgs, int nlupgs)
2111 for (i = 0; i < ncfspgs; i++) {
2112 struct lu_dirpage *dp = kmap(pages[i]);
2113 struct lu_dirpage *first = dp;
2114 struct lu_dirent *end_dirent = NULL;
2115 struct lu_dirent *ent;
2116 __u64 hash_end = dp->ldp_hash_end;
2117 __u32 flags = dp->ldp_flags;
2119 while (--nlupgs > 0) {
2120 ent = lu_dirent_start(dp);
2121 for (end_dirent = ent; ent != NULL;
2122 end_dirent = ent, ent = lu_dirent_next(ent));
2124 /* Advance dp to next lu_dirpage. */
2125 dp = (struct lu_dirpage *)((char *)dp + LU_PAGE_SIZE);
2127 /* Check if we've reached the end of the CFS_PAGE. */
2128 if (!((unsigned long)dp & ~CFS_PAGE_MASK))
2131 /* Save the hash and flags of this lu_dirpage. */
2132 hash_end = dp->ldp_hash_end;
2133 flags = dp->ldp_flags;
2135 /* Check if lu_dirpage contains no entries. */
2139 /* Enlarge the end entry lde_reclen from 0 to
2140 * first entry of next lu_dirpage. */
2141 LASSERT(le16_to_cpu(end_dirent->lde_reclen) == 0);
2142 end_dirent->lde_reclen =
2143 cpu_to_le16((char *)(dp->ldp_entries) -
2144 (char *)end_dirent);
2147 first->ldp_hash_end = hash_end;
2148 first->ldp_flags &= ~cpu_to_le32(LDF_COLLIDE);
2149 first->ldp_flags |= flags & cpu_to_le32(LDF_COLLIDE);
2153 LASSERTF(nlupgs == 0, "left = %d", nlupgs);
2156 #define lmv_adjust_dirpages(pages, ncfspgs, nlupgs) do {} while (0)
2157 #endif /* PAGE_CACHE_SIZE > LU_PAGE_SIZE */
2159 static int lmv_readpage(struct obd_export *exp, struct md_op_data *op_data,
2160 struct page **pages, struct ptlrpc_request **request)
2162 struct obd_device *obd = exp->exp_obd;
2163 struct lmv_obd *lmv = &obd->u.lmv;
2164 __u64 offset = op_data->op_offset;
2166 int ncfspgs; /* pages read in PAGE_CACHE_SIZE */
2167 int nlupgs; /* pages read in LU_PAGE_SIZE */
2168 struct lmv_tgt_desc *tgt;
2170 rc = lmv_check_connect(obd);
2174 CDEBUG(D_INODE, "READPAGE at %#llx from "DFID"\n",
2175 offset, PFID(&op_data->op_fid1));
2177 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2179 return PTR_ERR(tgt);
2181 rc = md_readpage(tgt->ltd_exp, op_data, pages, request);
2185 ncfspgs = ((*request)->rq_bulk->bd_nob_transferred + PAGE_CACHE_SIZE - 1)
2186 >> PAGE_CACHE_SHIFT;
2187 nlupgs = (*request)->rq_bulk->bd_nob_transferred >> LU_PAGE_SHIFT;
2188 LASSERT(!((*request)->rq_bulk->bd_nob_transferred & ~LU_PAGE_MASK));
2189 LASSERT(ncfspgs > 0 && ncfspgs <= op_data->op_npages);
2191 CDEBUG(D_INODE, "read %d(%d)/%d pages\n", ncfspgs, nlupgs,
2192 op_data->op_npages);
2194 lmv_adjust_dirpages(pages, ncfspgs, nlupgs);
2199 static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
2200 struct ptlrpc_request **request)
2202 struct obd_device *obd = exp->exp_obd;
2203 struct lmv_obd *lmv = &obd->u.lmv;
2204 struct lmv_tgt_desc *tgt = NULL;
2205 struct mdt_body *body;
2208 rc = lmv_check_connect(obd);
2212 /* Send unlink requests to the MDT where the child is located */
2213 if (likely(!fid_is_zero(&op_data->op_fid2)))
2214 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
2216 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
2218 return PTR_ERR(tgt);
2220 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
2221 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
2222 op_data->op_cap = cfs_curproc_cap_pack();
2225 * If child's fid is given, cancel unused locks for it if it is from
2226 * another export than parent.
2228 * LOOKUP lock for child (fid3) should also be cancelled on parent
2229 * tgt_tgt in mdc_unlink().
2231 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2234 * Cancel FULL locks on child (fid3).
2236 rc = lmv_early_cancel(exp, op_data, tgt->ltd_idx, LCK_EX,
2237 MDS_INODELOCK_FULL, MF_MDC_CANCEL_FID3);
2242 CDEBUG(D_INODE, "unlink with fid="DFID"/"DFID" -> mds #%d\n",
2243 PFID(&op_data->op_fid1), PFID(&op_data->op_fid2), tgt->ltd_idx);
2245 rc = md_unlink(tgt->ltd_exp, op_data, request);
2246 if (rc != 0 && rc != -EREMOTE)
2249 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
2253 /* Not cross-ref case, just get out of here. */
2254 if (likely(!(body->valid & OBD_MD_MDS)))
2257 CDEBUG(D_INODE, "%s: try unlink to another MDT for "DFID"\n",
2258 exp->exp_obd->obd_name, PFID(&body->fid1));
2260 /* This is a remote object, try remote MDT, Note: it may
2261 * try more than 1 time here, Considering following case
2262 * /mnt/lustre is root on MDT0, remote1 is on MDT1
2263 * 1. Initially A does not know where remote1 is, it send
2264 * unlink RPC to MDT0, MDT0 return -EREMOTE, it will
2265 * resend unlink RPC to MDT1 (retry 1st time).
2267 * 2. During the unlink RPC in flight,
2268 * client B mv /mnt/lustre/remote1 /mnt/lustre/remote2
2269 * and create new remote1, but on MDT0
2271 * 3. MDT1 get unlink RPC(from A), then do remote lock on
2272 * /mnt/lustre, then lookup get fid of remote1, and find
2273 * it is remote dir again, and replay -EREMOTE again.
2275 * 4. Then A will resend unlink RPC to MDT0. (retry 2nd times).
2277 * In theory, it might try unlimited time here, but it should
2278 * be very rare case. */
2279 op_data->op_fid2 = body->fid1;
2280 ptlrpc_req_finished(*request);
2286 static int lmv_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2288 struct lmv_obd *lmv = &obd->u.lmv;
2292 case OBD_CLEANUP_EARLY:
2293 /* XXX: here should be calling obd_precleanup() down to
2296 case OBD_CLEANUP_EXPORTS:
2297 fld_client_proc_fini(&lmv->lmv_fld);
2298 lprocfs_obd_cleanup(obd);
2306 static int lmv_get_info(const struct lu_env *env, struct obd_export *exp,
2307 __u32 keylen, void *key, __u32 *vallen, void *val,
2308 struct lov_stripe_md *lsm)
2310 struct obd_device *obd;
2311 struct lmv_obd *lmv;
2314 obd = class_exp2obd(exp);
2316 CDEBUG(D_IOCTL, "Invalid client cookie %#llx\n",
2317 exp->exp_handle.h_cookie);
2322 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
2323 struct lmv_tgt_desc *tgt;
2326 rc = lmv_check_connect(obd);
2330 LASSERT(*vallen == sizeof(__u32));
2331 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2334 * All tgts should be connected when this gets called.
2336 if (tgt == NULL || tgt->ltd_exp == NULL)
2339 if (!obd_get_info(env, tgt->ltd_exp, keylen, key,
2344 } else if (KEY_IS(KEY_MAX_EASIZE) ||
2345 KEY_IS(KEY_DEFAULT_EASIZE) ||
2346 KEY_IS(KEY_MAX_COOKIESIZE) ||
2347 KEY_IS(KEY_DEFAULT_COOKIESIZE) ||
2348 KEY_IS(KEY_CONN_DATA)) {
2349 rc = lmv_check_connect(obd);
2354 * Forwarding this request to first MDS, it should know LOV
2357 rc = obd_get_info(env, lmv->tgts[0]->ltd_exp, keylen, key,
2359 if (!rc && KEY_IS(KEY_CONN_DATA))
2360 exp->exp_connect_data = *(struct obd_connect_data *)val;
2362 } else if (KEY_IS(KEY_TGT_COUNT)) {
2363 *((int *)val) = lmv->desc.ld_tgt_count;
2367 CDEBUG(D_IOCTL, "Invalid key\n");
2371 int lmv_set_info_async(const struct lu_env *env, struct obd_export *exp,
2372 u32 keylen, void *key, u32 vallen,
2373 void *val, struct ptlrpc_request_set *set)
2375 struct lmv_tgt_desc *tgt;
2376 struct obd_device *obd;
2377 struct lmv_obd *lmv;
2380 obd = class_exp2obd(exp);
2382 CDEBUG(D_IOCTL, "Invalid client cookie %#llx\n",
2383 exp->exp_handle.h_cookie);
2388 if (KEY_IS(KEY_READ_ONLY) || KEY_IS(KEY_FLUSH_CTX)) {
2391 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2394 if (tgt == NULL || tgt->ltd_exp == NULL)
2397 err = obd_set_info_async(env, tgt->ltd_exp,
2398 keylen, key, vallen, val, set);
2409 int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
2410 struct lov_stripe_md *lsm)
2412 struct obd_device *obd = class_exp2obd(exp);
2413 struct lmv_obd *lmv = &obd->u.lmv;
2414 struct lmv_stripe_md *meap;
2415 struct lmv_stripe_md *lsmp;
2419 mea_size = lmv_get_easize(lmv);
2423 if (*lmmp && !lsm) {
2424 OBD_FREE_LARGE(*lmmp, mea_size);
2429 if (*lmmp == NULL) {
2430 OBD_ALLOC_LARGE(*lmmp, mea_size);
2438 lsmp = (struct lmv_stripe_md *)lsm;
2439 meap = (struct lmv_stripe_md *)*lmmp;
2441 if (lsmp->mea_magic != MEA_MAGIC_LAST_CHAR &&
2442 lsmp->mea_magic != MEA_MAGIC_ALL_CHARS)
2445 meap->mea_magic = cpu_to_le32(lsmp->mea_magic);
2446 meap->mea_count = cpu_to_le32(lsmp->mea_count);
2447 meap->mea_master = cpu_to_le32(lsmp->mea_master);
2449 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2450 meap->mea_ids[i] = lsmp->mea_ids[i];
2451 fid_cpu_to_le(&meap->mea_ids[i], &lsmp->mea_ids[i]);
2457 int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
2458 struct lov_mds_md *lmm, int lmm_size)
2460 struct obd_device *obd = class_exp2obd(exp);
2461 struct lmv_stripe_md **tmea = (struct lmv_stripe_md **)lsmp;
2462 struct lmv_stripe_md *mea = (struct lmv_stripe_md *)lmm;
2463 struct lmv_obd *lmv = &obd->u.lmv;
2468 mea_size = lmv_get_easize(lmv);
2472 if (*lsmp != NULL && lmm == NULL) {
2473 OBD_FREE_LARGE(*tmea, mea_size);
2478 LASSERT(mea_size == lmm_size);
2480 OBD_ALLOC_LARGE(*tmea, mea_size);
2487 if (mea->mea_magic == MEA_MAGIC_LAST_CHAR ||
2488 mea->mea_magic == MEA_MAGIC_ALL_CHARS ||
2489 mea->mea_magic == MEA_MAGIC_HASH_SEGMENT) {
2490 magic = le32_to_cpu(mea->mea_magic);
2493 * Old mea is not handled here.
2495 CERROR("Old not supportable EA is found\n");
2499 (*tmea)->mea_magic = magic;
2500 (*tmea)->mea_count = le32_to_cpu(mea->mea_count);
2501 (*tmea)->mea_master = le32_to_cpu(mea->mea_master);
2503 for (i = 0; i < (*tmea)->mea_count; i++) {
2504 (*tmea)->mea_ids[i] = mea->mea_ids[i];
2505 fid_le_to_cpu(&(*tmea)->mea_ids[i], &(*tmea)->mea_ids[i]);
2510 static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
2511 ldlm_policy_data_t *policy, ldlm_mode_t mode,
2512 ldlm_cancel_flags_t flags, void *opaque)
2514 struct obd_device *obd = exp->exp_obd;
2515 struct lmv_obd *lmv = &obd->u.lmv;
2520 LASSERT(fid != NULL);
2522 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2523 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL ||
2524 lmv->tgts[i]->ltd_active == 0)
2527 err = md_cancel_unused(lmv->tgts[i]->ltd_exp, fid,
2528 policy, mode, flags, opaque);
2535 int lmv_set_lock_data(struct obd_export *exp, __u64 *lockh, void *data,
2538 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2541 rc = md_set_lock_data(lmv->tgts[0]->ltd_exp, lockh, data, bits);
2545 ldlm_mode_t lmv_lock_match(struct obd_export *exp, __u64 flags,
2546 const struct lu_fid *fid, ldlm_type_t type,
2547 ldlm_policy_data_t *policy, ldlm_mode_t mode,
2548 struct lustre_handle *lockh)
2550 struct obd_device *obd = exp->exp_obd;
2551 struct lmv_obd *lmv = &obd->u.lmv;
2555 CDEBUG(D_INODE, "Lock match for "DFID"\n", PFID(fid));
2558 * With CMD every object can have two locks in different namespaces:
2559 * lookup lock in space of mds storing direntry and update/open lock in
2560 * space of mds storing inode. Thus we check all targets, not only that
2561 * one fid was created in.
2563 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2564 if (lmv->tgts[i] == NULL ||
2565 lmv->tgts[i]->ltd_exp == NULL ||
2566 lmv->tgts[i]->ltd_active == 0)
2569 rc = md_lock_match(lmv->tgts[i]->ltd_exp, flags, fid,
2570 type, policy, mode, lockh);
2578 int lmv_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
2579 struct obd_export *dt_exp, struct obd_export *md_exp,
2580 struct lustre_md *md)
2582 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2584 return md_get_lustre_md(lmv->tgts[0]->ltd_exp, req, dt_exp, md_exp, md);
2587 int lmv_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
2589 struct obd_device *obd = exp->exp_obd;
2590 struct lmv_obd *lmv = &obd->u.lmv;
2593 obd_free_memmd(exp, (void *)&md->mea);
2594 return md_free_lustre_md(lmv->tgts[0]->ltd_exp, md);
2597 int lmv_set_open_replay_data(struct obd_export *exp,
2598 struct obd_client_handle *och,
2599 struct lookup_intent *it)
2601 struct obd_device *obd = exp->exp_obd;
2602 struct lmv_obd *lmv = &obd->u.lmv;
2603 struct lmv_tgt_desc *tgt;
2605 tgt = lmv_find_target(lmv, &och->och_fid);
2607 return PTR_ERR(tgt);
2609 return md_set_open_replay_data(tgt->ltd_exp, och, it);
2612 int lmv_clear_open_replay_data(struct obd_export *exp,
2613 struct obd_client_handle *och)
2615 struct obd_device *obd = exp->exp_obd;
2616 struct lmv_obd *lmv = &obd->u.lmv;
2617 struct lmv_tgt_desc *tgt;
2619 tgt = lmv_find_target(lmv, &och->och_fid);
2621 return PTR_ERR(tgt);
2623 return md_clear_open_replay_data(tgt->ltd_exp, och);
2626 static int lmv_get_remote_perm(struct obd_export *exp,
2627 const struct lu_fid *fid,
2628 struct obd_capa *oc, __u32 suppgid,
2629 struct ptlrpc_request **request)
2631 struct obd_device *obd = exp->exp_obd;
2632 struct lmv_obd *lmv = &obd->u.lmv;
2633 struct lmv_tgt_desc *tgt;
2636 rc = lmv_check_connect(obd);
2640 tgt = lmv_find_target(lmv, fid);
2642 return PTR_ERR(tgt);
2644 rc = md_get_remote_perm(tgt->ltd_exp, fid, oc, suppgid, request);
2648 static int lmv_renew_capa(struct obd_export *exp, struct obd_capa *oc,
2651 struct obd_device *obd = exp->exp_obd;
2652 struct lmv_obd *lmv = &obd->u.lmv;
2653 struct lmv_tgt_desc *tgt;
2656 rc = lmv_check_connect(obd);
2660 tgt = lmv_find_target(lmv, &oc->c_capa.lc_fid);
2662 return PTR_ERR(tgt);
2664 rc = md_renew_capa(tgt->ltd_exp, oc, cb);
2668 int lmv_unpack_capa(struct obd_export *exp, struct ptlrpc_request *req,
2669 const struct req_msg_field *field, struct obd_capa **oc)
2671 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2673 return md_unpack_capa(lmv->tgts[0]->ltd_exp, req, field, oc);
2676 int lmv_intent_getattr_async(struct obd_export *exp,
2677 struct md_enqueue_info *minfo,
2678 struct ldlm_enqueue_info *einfo)
2680 struct md_op_data *op_data = &minfo->mi_data;
2681 struct obd_device *obd = exp->exp_obd;
2682 struct lmv_obd *lmv = &obd->u.lmv;
2683 struct lmv_tgt_desc *tgt = NULL;
2686 rc = lmv_check_connect(obd);
2690 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2692 return PTR_ERR(tgt);
2694 rc = md_intent_getattr_async(tgt->ltd_exp, minfo, einfo);
2698 int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
2699 struct lu_fid *fid, __u64 *bits)
2701 struct obd_device *obd = exp->exp_obd;
2702 struct lmv_obd *lmv = &obd->u.lmv;
2703 struct lmv_tgt_desc *tgt;
2706 rc = lmv_check_connect(obd);
2710 tgt = lmv_find_target(lmv, fid);
2712 return PTR_ERR(tgt);
2714 rc = md_revalidate_lock(tgt->ltd_exp, it, fid, bits);
2719 * For lmv, only need to send request to master MDT, and the master MDT will
2720 * process with other slave MDTs. The only exception is Q_GETOQUOTA for which
2721 * we directly fetch data from the slave MDTs.
2723 int lmv_quotactl(struct obd_device *unused, struct obd_export *exp,
2724 struct obd_quotactl *oqctl)
2726 struct obd_device *obd = class_exp2obd(exp);
2727 struct lmv_obd *lmv = &obd->u.lmv;
2728 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2730 __u64 curspace, curinodes;
2732 if (!lmv->desc.ld_tgt_count || !tgt->ltd_active) {
2733 CERROR("master lmv inactive\n");
2737 if (oqctl->qc_cmd != Q_GETOQUOTA) {
2738 rc = obd_quotactl(tgt->ltd_exp, oqctl);
2742 curspace = curinodes = 0;
2743 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2747 if (tgt == NULL || tgt->ltd_exp == NULL || tgt->ltd_active == 0)
2749 if (!tgt->ltd_active) {
2750 CDEBUG(D_HA, "mdt %d is inactive.\n", i);
2754 err = obd_quotactl(tgt->ltd_exp, oqctl);
2756 CERROR("getquota on mdt %d failed. %d\n", i, err);
2760 curspace += oqctl->qc_dqblk.dqb_curspace;
2761 curinodes += oqctl->qc_dqblk.dqb_curinodes;
2764 oqctl->qc_dqblk.dqb_curspace = curspace;
2765 oqctl->qc_dqblk.dqb_curinodes = curinodes;
2770 int lmv_quotacheck(struct obd_device *unused, struct obd_export *exp,
2771 struct obd_quotactl *oqctl)
2773 struct obd_device *obd = class_exp2obd(exp);
2774 struct lmv_obd *lmv = &obd->u.lmv;
2775 struct lmv_tgt_desc *tgt;
2778 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2781 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active) {
2782 CERROR("lmv idx %d inactive\n", i);
2786 err = obd_quotacheck(tgt->ltd_exp, oqctl);
2794 struct obd_ops lmv_obd_ops = {
2795 .o_owner = THIS_MODULE,
2796 .o_setup = lmv_setup,
2797 .o_cleanup = lmv_cleanup,
2798 .o_precleanup = lmv_precleanup,
2799 .o_process_config = lmv_process_config,
2800 .o_connect = lmv_connect,
2801 .o_disconnect = lmv_disconnect,
2802 .o_statfs = lmv_statfs,
2803 .o_get_info = lmv_get_info,
2804 .o_set_info_async = lmv_set_info_async,
2805 .o_packmd = lmv_packmd,
2806 .o_unpackmd = lmv_unpackmd,
2807 .o_notify = lmv_notify,
2808 .o_get_uuid = lmv_get_uuid,
2809 .o_iocontrol = lmv_iocontrol,
2810 .o_quotacheck = lmv_quotacheck,
2811 .o_quotactl = lmv_quotactl
2814 struct md_ops lmv_md_ops = {
2815 .m_getstatus = lmv_getstatus,
2816 .m_null_inode = lmv_null_inode,
2817 .m_find_cbdata = lmv_find_cbdata,
2818 .m_close = lmv_close,
2819 .m_create = lmv_create,
2820 .m_done_writing = lmv_done_writing,
2821 .m_enqueue = lmv_enqueue,
2822 .m_getattr = lmv_getattr,
2823 .m_getxattr = lmv_getxattr,
2824 .m_getattr_name = lmv_getattr_name,
2825 .m_intent_lock = lmv_intent_lock,
2827 .m_rename = lmv_rename,
2828 .m_setattr = lmv_setattr,
2829 .m_setxattr = lmv_setxattr,
2831 .m_readpage = lmv_readpage,
2832 .m_unlink = lmv_unlink,
2833 .m_init_ea_size = lmv_init_ea_size,
2834 .m_cancel_unused = lmv_cancel_unused,
2835 .m_set_lock_data = lmv_set_lock_data,
2836 .m_lock_match = lmv_lock_match,
2837 .m_get_lustre_md = lmv_get_lustre_md,
2838 .m_free_lustre_md = lmv_free_lustre_md,
2839 .m_set_open_replay_data = lmv_set_open_replay_data,
2840 .m_clear_open_replay_data = lmv_clear_open_replay_data,
2841 .m_renew_capa = lmv_renew_capa,
2842 .m_unpack_capa = lmv_unpack_capa,
2843 .m_get_remote_perm = lmv_get_remote_perm,
2844 .m_intent_getattr_async = lmv_intent_getattr_async,
2845 .m_revalidate_lock = lmv_revalidate_lock
2848 int __init lmv_init(void)
2850 struct lprocfs_static_vars lvars;
2853 lprocfs_lmv_init_vars(&lvars);
2855 rc = class_register_type(&lmv_obd_ops, &lmv_md_ops,
2856 lvars.module_vars, LUSTRE_LMV_NAME, NULL);
2860 static void lmv_exit(void)
2862 class_unregister_type(LUSTRE_LMV_NAME);
2865 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2866 MODULE_DESCRIPTION("Lustre Logical Metadata Volume OBD driver");
2867 MODULE_LICENSE("GPL");
2869 module_init(lmv_init);
2870 module_exit(lmv_exit);