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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2015, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 #define DEBUG_SUBSYSTEM S_LMV
34 #include <linux/slab.h>
35 #include <linux/module.h>
36 #include <linux/init.h>
37 #include <linux/pagemap.h>
39 #include <asm/div64.h>
40 #include <linux/seq_file.h>
41 #include <linux/namei.h>
42 #include <linux/uaccess.h>
44 #include "../include/lustre/lustre_idl.h"
45 #include "../include/obd_support.h"
46 #include "../include/lustre_lib.h"
47 #include "../include/lustre_net.h"
48 #include "../include/obd_class.h"
49 #include "../include/lprocfs_status.h"
50 #include "../include/lustre_lite.h"
51 #include "../include/lustre_fid.h"
52 #include "../include/lustre_kernelcomm.h"
53 #include "lmv_internal.h"
55 static void lmv_activate_target(struct lmv_obd *lmv,
56 struct lmv_tgt_desc *tgt,
59 if (tgt->ltd_active == activate)
62 tgt->ltd_active = activate;
63 lmv->desc.ld_active_tgt_count += (activate ? 1 : -1);
69 * -EINVAL : UUID can't be found in the LMV's target list
70 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
71 * -EBADF : The UUID is found, but the OBD of the wrong type (!)
73 static int lmv_set_mdc_active(struct lmv_obd *lmv, struct obd_uuid *uuid,
76 struct lmv_tgt_desc *uninitialized_var(tgt);
77 struct obd_device *obd;
81 CDEBUG(D_INFO, "Searching in lmv %p for uuid %s (activate=%d)\n",
82 lmv, uuid->uuid, activate);
84 spin_lock(&lmv->lmv_lock);
85 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
87 if (!tgt || !tgt->ltd_exp)
90 CDEBUG(D_INFO, "Target idx %d is %s conn %#llx\n", i,
91 tgt->ltd_uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
93 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
97 if (i == lmv->desc.ld_tgt_count) {
102 obd = class_exp2obd(tgt->ltd_exp);
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");
119 CDEBUG(D_INFO, "Marking OBD %p %sactive\n", obd,
120 activate ? "" : "in");
121 lmv_activate_target(lmv, tgt, activate);
124 spin_unlock(&lmv->lmv_lock);
128 static struct obd_uuid *lmv_get_uuid(struct obd_export *exp)
130 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
131 struct lmv_tgt_desc *tgt = lmv->tgts[0];
133 return tgt ? obd_get_uuid(tgt->ltd_exp) : NULL;
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;
144 if (strcmp(watched->obd_type->typ_name, LUSTRE_MDC_NAME)) {
145 CERROR("unexpected notification of %s %s!\n",
146 watched->obd_type->typ_name,
151 uuid = &watched->u.cli.cl_target_uuid;
152 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE) {
154 * Set MDC as active before notifying the observer, so the
155 * observer can use the MDC normally.
157 rc = lmv_set_mdc_active(lmv, uuid,
158 ev == OBD_NOTIFY_ACTIVE);
160 CERROR("%sactivation of %s failed: %d\n",
161 ev == OBD_NOTIFY_ACTIVE ? "" : "de",
165 } else if (ev == OBD_NOTIFY_OCD) {
166 conn_data = &watched->u.cli.cl_import->imp_connect_data;
168 * XXX: Make sure that ocd_connect_flags from all targets are
169 * the same. Otherwise one of MDTs runs wrong version or
170 * something like this. --umka
172 obd->obd_self_export->exp_connect_data = *conn_data;
175 else if (ev == OBD_NOTIFY_DISCON) {
177 * For disconnect event, flush fld cache for failout MDS case.
179 fld_client_flush(&lmv->lmv_fld);
183 * Pass the notification up the chain.
185 if (obd->obd_observer)
186 rc = obd_notify(obd->obd_observer, watched, ev, data);
192 * This is fake connect function. Its purpose is to initialize lmv and say
193 * caller that everything is okay. Real connection will be performed later.
195 static int lmv_connect(const struct lu_env *env,
196 struct obd_export **exp, struct obd_device *obd,
197 struct obd_uuid *cluuid, struct obd_connect_data *data,
200 struct lmv_obd *lmv = &obd->u.lmv;
201 struct lustre_handle conn = { 0 };
205 * We don't want to actually do the underlying connections more than
206 * once, so keep track.
209 if (lmv->refcount > 1) {
214 rc = class_connect(&conn, obd, cluuid);
216 CERROR("class_connection() returned %d\n", rc);
220 *exp = class_conn2export(&conn);
221 class_export_get(*exp);
225 lmv->cluuid = *cluuid;
228 lmv->conn_data = *data;
230 lmv->lmv_tgts_kobj = kobject_create_and_add("target_obds",
233 * All real clients should perform actual connection right away, because
234 * it is possible, that LMV will not have opportunity to connect targets
235 * and MDC stuff will be called directly, for instance while reading
236 * ../mdc/../kbytesfree procfs file, etc.
238 if (data && data->ocd_connect_flags & OBD_CONNECT_REAL)
239 rc = lmv_check_connect(obd);
241 if (rc && lmv->lmv_tgts_kobj)
242 kobject_put(lmv->lmv_tgts_kobj);
247 static void lmv_set_timeouts(struct obd_device *obd)
253 if (lmv->server_timeout == 0)
256 if (lmv->connected == 0)
259 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
260 struct lmv_tgt_desc *tgt = lmv->tgts[i];
263 if (!tgt || !tgt->ltd_exp || !tgt->ltd_active)
266 obd_set_info_async(NULL, tgt->ltd_exp, sizeof(KEY_INTERMDS),
267 KEY_INTERMDS, 0, NULL, NULL);
271 static int lmv_init_ea_size(struct obd_export *exp, int easize,
272 int def_easize, int cookiesize, int def_cookiesize)
274 struct obd_device *obd = exp->exp_obd;
275 struct lmv_obd *lmv = &obd->u.lmv;
280 if (lmv->max_easize < easize) {
281 lmv->max_easize = easize;
284 if (lmv->max_def_easize < def_easize) {
285 lmv->max_def_easize = def_easize;
288 if (lmv->max_cookiesize < cookiesize) {
289 lmv->max_cookiesize = cookiesize;
292 if (lmv->max_def_cookiesize < def_cookiesize) {
293 lmv->max_def_cookiesize = def_cookiesize;
299 if (lmv->connected == 0)
302 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
303 struct lmv_tgt_desc *tgt = lmv->tgts[i];
305 if (!tgt || !tgt->ltd_exp || !tgt->ltd_active) {
306 CWARN("%s: NULL export for %d\n", obd->obd_name, i);
310 rc = md_init_ea_size(tgt->ltd_exp, easize, def_easize,
311 cookiesize, def_cookiesize);
313 CERROR("%s: obd_init_ea_size() failed on MDT target %d: rc = %d\n",
314 obd->obd_name, i, rc);
321 #define MAX_STRING_SIZE 128
323 static int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
325 struct lmv_obd *lmv = &obd->u.lmv;
326 struct obd_uuid *cluuid = &lmv->cluuid;
327 struct obd_uuid lmv_mdc_uuid = { "LMV_MDC_UUID" };
328 struct obd_device *mdc_obd;
329 struct obd_export *mdc_exp;
330 struct lu_fld_target target;
333 mdc_obd = class_find_client_obd(&tgt->ltd_uuid, LUSTRE_MDC_NAME,
336 CERROR("target %s not attached\n", tgt->ltd_uuid.uuid);
340 CDEBUG(D_CONFIG, "connect to %s(%s) - %s, %s FOR %s\n",
341 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
342 tgt->ltd_uuid.uuid, obd->obd_uuid.uuid, cluuid->uuid);
344 if (!mdc_obd->obd_set_up) {
345 CERROR("target %s is not set up\n", tgt->ltd_uuid.uuid);
349 rc = obd_connect(NULL, &mdc_exp, mdc_obd, &lmv_mdc_uuid,
350 &lmv->conn_data, NULL);
352 CERROR("target %s connect error %d\n", tgt->ltd_uuid.uuid, rc);
357 * Init fid sequence client for this mdc and add new fld target.
359 rc = obd_fid_init(mdc_obd, mdc_exp, LUSTRE_SEQ_METADATA);
363 target.ft_srv = NULL;
364 target.ft_exp = mdc_exp;
365 target.ft_idx = tgt->ltd_idx;
367 fld_client_add_target(&lmv->lmv_fld, &target);
369 rc = obd_register_observer(mdc_obd, obd);
371 obd_disconnect(mdc_exp);
372 CERROR("target %s register_observer error %d\n",
373 tgt->ltd_uuid.uuid, rc);
377 if (obd->obd_observer) {
379 * Tell the observer about the new target.
381 rc = obd_notify(obd->obd_observer, mdc_exp->exp_obd,
383 (void *)(tgt - lmv->tgts[0]));
385 obd_disconnect(mdc_exp);
391 tgt->ltd_exp = mdc_exp;
392 lmv->desc.ld_active_tgt_count++;
394 md_init_ea_size(tgt->ltd_exp, lmv->max_easize, lmv->max_def_easize,
395 lmv->max_cookiesize, lmv->max_def_cookiesize);
397 CDEBUG(D_CONFIG, "Connected to %s(%s) successfully (%d)\n",
398 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
399 atomic_read(&obd->obd_refcount));
401 if (lmv->lmv_tgts_kobj)
402 /* Even if we failed to create the link, that's fine */
403 rc = sysfs_create_link(lmv->lmv_tgts_kobj, &mdc_obd->obd_kobj,
408 static void lmv_del_target(struct lmv_obd *lmv, int index)
410 if (!lmv->tgts[index])
413 kfree(lmv->tgts[index]);
414 lmv->tgts[index] = NULL;
418 static int lmv_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
419 __u32 index, int gen)
421 struct lmv_obd *lmv = &obd->u.lmv;
422 struct lmv_tgt_desc *tgt;
425 CDEBUG(D_CONFIG, "Target uuid: %s. index %d\n", uuidp->uuid, index);
427 mutex_lock(&lmv->lmv_init_mutex);
429 if (lmv->desc.ld_tgt_count == 0) {
430 struct obd_device *mdc_obd;
432 mdc_obd = class_find_client_obd(uuidp, LUSTRE_MDC_NAME,
435 mutex_unlock(&lmv->lmv_init_mutex);
436 CERROR("%s: Target %s not attached: rc = %d\n",
437 obd->obd_name, uuidp->uuid, -EINVAL);
442 if ((index < lmv->tgts_size) && lmv->tgts[index]) {
443 tgt = lmv->tgts[index];
444 CERROR("%s: UUID %s already assigned at LOV target index %d: rc = %d\n",
446 obd_uuid2str(&tgt->ltd_uuid), index, -EEXIST);
447 mutex_unlock(&lmv->lmv_init_mutex);
451 if (index >= lmv->tgts_size) {
452 /* We need to reallocate the lmv target array. */
453 struct lmv_tgt_desc **newtgts, **old = NULL;
457 while (newsize < index + 1)
459 newtgts = kcalloc(newsize, sizeof(*newtgts), GFP_NOFS);
461 mutex_unlock(&lmv->lmv_init_mutex);
465 if (lmv->tgts_size) {
466 memcpy(newtgts, lmv->tgts,
467 sizeof(*newtgts) * lmv->tgts_size);
469 oldsize = lmv->tgts_size;
473 lmv->tgts_size = newsize;
477 CDEBUG(D_CONFIG, "tgts: %p size: %d\n", lmv->tgts,
481 tgt = kzalloc(sizeof(*tgt), GFP_NOFS);
483 mutex_unlock(&lmv->lmv_init_mutex);
487 mutex_init(&tgt->ltd_fid_mutex);
488 tgt->ltd_idx = index;
489 tgt->ltd_uuid = *uuidp;
491 lmv->tgts[index] = tgt;
492 if (index >= lmv->desc.ld_tgt_count)
493 lmv->desc.ld_tgt_count = index + 1;
495 if (lmv->connected) {
496 rc = lmv_connect_mdc(obd, tgt);
498 spin_lock(&lmv->lmv_lock);
499 lmv->desc.ld_tgt_count--;
500 memset(tgt, 0, sizeof(*tgt));
501 spin_unlock(&lmv->lmv_lock);
503 int easize = sizeof(struct lmv_stripe_md) +
504 lmv->desc.ld_tgt_count * sizeof(struct lu_fid);
505 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0, 0);
509 mutex_unlock(&lmv->lmv_init_mutex);
513 int lmv_check_connect(struct obd_device *obd)
515 struct lmv_obd *lmv = &obd->u.lmv;
516 struct lmv_tgt_desc *tgt;
524 mutex_lock(&lmv->lmv_init_mutex);
525 if (lmv->connected) {
526 mutex_unlock(&lmv->lmv_init_mutex);
530 if (lmv->desc.ld_tgt_count == 0) {
531 mutex_unlock(&lmv->lmv_init_mutex);
532 CERROR("%s: no targets configured.\n", obd->obd_name);
539 mutex_unlock(&lmv->lmv_init_mutex);
540 CERROR("%s: no target configured for index 0.\n",
545 CDEBUG(D_CONFIG, "Time to connect %s to %s\n",
546 lmv->cluuid.uuid, obd->obd_name);
548 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
552 rc = lmv_connect_mdc(obd, tgt);
557 lmv_set_timeouts(obd);
558 class_export_put(lmv->exp);
560 easize = lmv_get_easize(lmv);
561 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0, 0);
562 mutex_unlock(&lmv->lmv_init_mutex);
574 --lmv->desc.ld_active_tgt_count;
575 rc2 = obd_disconnect(tgt->ltd_exp);
577 CERROR("LMV target %s disconnect on MDC idx %d: error %d\n",
578 tgt->ltd_uuid.uuid, i, rc2);
582 class_disconnect(lmv->exp);
583 mutex_unlock(&lmv->lmv_init_mutex);
587 static int lmv_disconnect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
589 struct lmv_obd *lmv = &obd->u.lmv;
590 struct obd_device *mdc_obd;
593 mdc_obd = class_exp2obd(tgt->ltd_exp);
596 mdc_obd->obd_force = obd->obd_force;
597 mdc_obd->obd_fail = obd->obd_fail;
598 mdc_obd->obd_no_recov = obd->obd_no_recov;
600 if (lmv->lmv_tgts_kobj)
601 sysfs_remove_link(lmv->lmv_tgts_kobj,
605 rc = obd_fid_fini(tgt->ltd_exp->exp_obd);
607 CERROR("Can't finalize fids factory\n");
609 CDEBUG(D_INFO, "Disconnected from %s(%s) successfully\n",
610 tgt->ltd_exp->exp_obd->obd_name,
611 tgt->ltd_exp->exp_obd->obd_uuid.uuid);
613 obd_register_observer(tgt->ltd_exp->exp_obd, NULL);
614 rc = obd_disconnect(tgt->ltd_exp);
616 if (tgt->ltd_active) {
617 CERROR("Target %s disconnect error %d\n",
618 tgt->ltd_uuid.uuid, rc);
622 lmv_activate_target(lmv, tgt, 0);
627 static int lmv_disconnect(struct obd_export *exp)
629 struct obd_device *obd = class_exp2obd(exp);
630 struct lmv_obd *lmv = &obd->u.lmv;
638 * Only disconnect the underlying layers on the final disconnect.
641 if (lmv->refcount != 0)
644 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
645 if (!lmv->tgts[i] || !lmv->tgts[i]->ltd_exp)
648 lmv_disconnect_mdc(obd, lmv->tgts[i]);
651 if (lmv->lmv_tgts_kobj)
652 kobject_put(lmv->lmv_tgts_kobj);
656 * This is the case when no real connection is established by
657 * lmv_check_connect().
660 class_export_put(exp);
661 rc = class_disconnect(exp);
662 if (lmv->refcount == 0)
667 static int lmv_fid2path(struct obd_export *exp, int len, void *karg,
670 struct obd_device *obddev = class_exp2obd(exp);
671 struct lmv_obd *lmv = &obddev->u.lmv;
672 struct getinfo_fid2path *gf;
673 struct lmv_tgt_desc *tgt;
674 struct getinfo_fid2path *remote_gf = NULL;
675 int remote_gf_size = 0;
678 gf = (struct getinfo_fid2path *)karg;
679 tgt = lmv_find_target(lmv, &gf->gf_fid);
684 rc = obd_iocontrol(OBD_IOC_FID2PATH, tgt->ltd_exp, len, gf, uarg);
685 if (rc != 0 && rc != -EREMOTE)
688 /* If remote_gf != NULL, it means just building the
689 * path on the remote MDT, copy this path segment to gf
692 struct getinfo_fid2path *ori_gf;
695 ori_gf = (struct getinfo_fid2path *)karg;
696 if (strlen(ori_gf->gf_path) +
697 strlen(gf->gf_path) > ori_gf->gf_pathlen) {
702 ptr = ori_gf->gf_path;
704 memmove(ptr + strlen(gf->gf_path) + 1, ptr,
705 strlen(ori_gf->gf_path));
707 strncpy(ptr, gf->gf_path, strlen(gf->gf_path));
708 ptr += strlen(gf->gf_path);
712 CDEBUG(D_INFO, "%s: get path %s "DFID" rec: %llu ln: %u\n",
713 tgt->ltd_exp->exp_obd->obd_name,
714 gf->gf_path, PFID(&gf->gf_fid), gf->gf_recno,
720 /* sigh, has to go to another MDT to do path building further */
722 remote_gf_size = sizeof(*remote_gf) + PATH_MAX;
723 remote_gf = kzalloc(remote_gf_size, GFP_NOFS);
728 remote_gf->gf_pathlen = PATH_MAX;
731 if (!fid_is_sane(&gf->gf_fid)) {
732 CERROR("%s: invalid FID "DFID": rc = %d\n",
733 tgt->ltd_exp->exp_obd->obd_name,
734 PFID(&gf->gf_fid), -EINVAL);
739 tgt = lmv_find_target(lmv, &gf->gf_fid);
745 remote_gf->gf_fid = gf->gf_fid;
746 remote_gf->gf_recno = -1;
747 remote_gf->gf_linkno = -1;
748 memset(remote_gf->gf_path, 0, remote_gf->gf_pathlen);
750 goto repeat_fid2path;
757 static int lmv_hsm_req_count(struct lmv_obd *lmv,
758 const struct hsm_user_request *hur,
759 const struct lmv_tgt_desc *tgt_mds)
762 struct lmv_tgt_desc *curr_tgt;
764 /* count how many requests must be sent to the given target */
765 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
766 curr_tgt = lmv_find_target(lmv, &hur->hur_user_item[i].hui_fid);
767 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid))
773 static void lmv_hsm_req_build(struct lmv_obd *lmv,
774 struct hsm_user_request *hur_in,
775 const struct lmv_tgt_desc *tgt_mds,
776 struct hsm_user_request *hur_out)
779 struct lmv_tgt_desc *curr_tgt;
781 /* build the hsm_user_request for the given target */
782 hur_out->hur_request = hur_in->hur_request;
784 for (i = 0; i < hur_in->hur_request.hr_itemcount; i++) {
785 curr_tgt = lmv_find_target(lmv,
786 &hur_in->hur_user_item[i].hui_fid);
787 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid)) {
788 hur_out->hur_user_item[nr_out] =
789 hur_in->hur_user_item[i];
793 hur_out->hur_request.hr_itemcount = nr_out;
794 memcpy(hur_data(hur_out), hur_data(hur_in),
795 hur_in->hur_request.hr_data_len);
798 static int lmv_hsm_ct_unregister(struct lmv_obd *lmv, unsigned int cmd, int len,
799 struct lustre_kernelcomm *lk,
805 /* unregister request (call from llapi_hsm_copytool_fini) */
806 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
807 struct lmv_tgt_desc *tgt = lmv->tgts[i];
809 if (!tgt || !tgt->ltd_exp)
812 /* best effort: try to clean as much as possible
813 * (continue on error)
815 obd_iocontrol(cmd, lmv->tgts[i]->ltd_exp, len, lk, uarg);
818 /* Whatever the result, remove copytool from kuc groups.
819 * Unreached coordinators will get EPIPE on next requests
820 * and will unregister automatically.
822 rc = libcfs_kkuc_group_rem(lk->lk_uid, lk->lk_group);
827 static int lmv_hsm_ct_register(struct lmv_obd *lmv, unsigned int cmd, int len,
828 struct lustre_kernelcomm *lk, void __user *uarg)
833 bool any_set = false;
834 struct kkuc_ct_data kcd = { 0 };
836 /* All or nothing: try to register to all MDS.
837 * In case of failure, unregister from previous MDS,
838 * except if it because of inactive target.
840 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
841 struct lmv_tgt_desc *tgt = lmv->tgts[i];
843 if (!tgt || !tgt->ltd_exp)
846 err = obd_iocontrol(cmd, tgt->ltd_exp, len, lk, uarg);
848 if (tgt->ltd_active) {
849 /* permanent error */
850 CERROR("error: iocontrol MDC %s on MDTidx %d cmd %x: err = %d\n",
851 tgt->ltd_uuid.uuid, i, cmd, err);
853 lk->lk_flags |= LK_FLG_STOP;
854 /* unregister from previous MDS */
855 for (j = 0; j < i; j++) {
858 if (!tgt || !tgt->ltd_exp)
860 obd_iocontrol(cmd, tgt->ltd_exp, len,
865 /* else: transient error.
866 * kuc will register to the missing MDT when it is back
874 /* no registration done: return error */
877 /* at least one registration done, with no failure */
878 filp = fget(lk->lk_wfd);
882 kcd.kcd_magic = KKUC_CT_DATA_MAGIC;
883 kcd.kcd_uuid = lmv->cluuid;
884 kcd.kcd_archive = lk->lk_data;
886 rc = libcfs_kkuc_group_add(filp, lk->lk_uid, lk->lk_group,
896 static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
897 int len, void *karg, void __user *uarg)
899 struct obd_device *obddev = class_exp2obd(exp);
900 struct lmv_obd *lmv = &obddev->u.lmv;
901 struct lmv_tgt_desc *tgt = NULL;
905 int count = lmv->desc.ld_tgt_count;
911 case IOC_OBD_STATFS: {
912 struct obd_ioctl_data *data = karg;
913 struct obd_device *mdc_obd;
914 struct obd_statfs stat_buf = {0};
917 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
921 tgt = lmv->tgts[index];
922 if (!tgt || !tgt->ltd_active)
925 mdc_obd = class_exp2obd(tgt->ltd_exp);
930 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(mdc_obd),
931 min((int)data->ioc_plen2,
932 (int)sizeof(struct obd_uuid))))
935 rc = obd_statfs(NULL, tgt->ltd_exp, &stat_buf,
936 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
940 if (copy_to_user(data->ioc_pbuf1, &stat_buf,
941 min((int)data->ioc_plen1,
942 (int)sizeof(stat_buf))))
946 case OBD_IOC_QUOTACTL: {
947 struct if_quotactl *qctl = karg;
948 struct obd_quotactl *oqctl;
950 if (qctl->qc_valid == QC_MDTIDX) {
951 if (count <= qctl->qc_idx)
954 tgt = lmv->tgts[qctl->qc_idx];
955 if (!tgt || !tgt->ltd_exp)
957 } else if (qctl->qc_valid == QC_UUID) {
958 for (i = 0; i < count; i++) {
962 if (!obd_uuid_equals(&tgt->ltd_uuid,
978 LASSERT(tgt && tgt->ltd_exp);
979 oqctl = kzalloc(sizeof(*oqctl), GFP_NOFS);
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 tgt = lmv->tgts[icc->icc_mdtindex];
1001 if (!tgt || !tgt->ltd_exp || !tgt->ltd_active)
1003 rc = obd_iocontrol(cmd, tgt->ltd_exp, sizeof(*icc), icc, NULL);
1006 case LL_IOC_GET_CONNECT_FLAGS: {
1009 if (!tgt || !tgt->ltd_exp)
1011 rc = obd_iocontrol(cmd, tgt->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;
1023 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1025 return PTR_ERR(tgt);
1030 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1033 case LL_IOC_HSM_PROGRESS: {
1034 const struct hsm_progress_kernel *hpk = karg;
1036 tgt = lmv_find_target(lmv, &hpk->hpk_fid);
1038 return PTR_ERR(tgt);
1039 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1042 case LL_IOC_HSM_REQUEST: {
1043 struct hsm_user_request *hur = karg;
1044 unsigned int reqcount = hur->hur_request.hr_itemcount;
1049 /* if the request is about a single fid
1050 * or if there is a single MDS, no need to split
1053 if (reqcount == 1 || count == 1) {
1054 tgt = lmv_find_target(lmv,
1055 &hur->hur_user_item[0].hui_fid);
1057 return PTR_ERR(tgt);
1058 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1060 /* split fid list to their respective MDS */
1061 for (i = 0; i < count; i++) {
1062 unsigned int nr, reqlen;
1064 struct hsm_user_request *req;
1067 if (!tgt || !tgt->ltd_exp)
1070 nr = lmv_hsm_req_count(lmv, hur, tgt);
1071 if (nr == 0) /* nothing for this MDS */
1074 /* build a request with fids for this MDS */
1075 reqlen = offsetof(typeof(*hur),
1077 + hur->hur_request.hr_data_len;
1078 req = libcfs_kvzalloc(reqlen, GFP_NOFS);
1082 lmv_hsm_req_build(lmv, hur, tgt, req);
1084 rc1 = obd_iocontrol(cmd, tgt->ltd_exp, reqlen,
1086 if (rc1 != 0 && rc == 0)
1093 case LL_IOC_LOV_SWAP_LAYOUTS: {
1094 struct md_op_data *op_data = karg;
1095 struct lmv_tgt_desc *tgt1, *tgt2;
1097 tgt1 = lmv_find_target(lmv, &op_data->op_fid1);
1099 return PTR_ERR(tgt1);
1101 tgt2 = lmv_find_target(lmv, &op_data->op_fid2);
1103 return PTR_ERR(tgt2);
1105 if (!tgt1->ltd_exp || !tgt2->ltd_exp)
1108 /* only files on same MDT can have their layouts swapped */
1109 if (tgt1->ltd_idx != tgt2->ltd_idx)
1112 rc = obd_iocontrol(cmd, tgt1->ltd_exp, len, karg, uarg);
1115 case LL_IOC_HSM_CT_START: {
1116 struct lustre_kernelcomm *lk = karg;
1118 if (lk->lk_flags & LK_FLG_STOP)
1119 rc = lmv_hsm_ct_unregister(lmv, cmd, len, lk, uarg);
1121 rc = lmv_hsm_ct_register(lmv, cmd, len, lk, uarg);
1125 for (i = 0; i < count; i++) {
1126 struct obd_device *mdc_obd;
1130 if (!tgt || !tgt->ltd_exp)
1132 /* ll_umount_begin() sets force flag but for lmv, not
1133 * mdc. Let's pass it through
1135 mdc_obd = class_exp2obd(tgt->ltd_exp);
1136 mdc_obd->obd_force = obddev->obd_force;
1137 err = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1138 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
1141 if (tgt->ltd_active) {
1142 CERROR("error: iocontrol MDC %s on MDTidx %d cmd %x: err = %d\n",
1143 tgt->ltd_uuid.uuid, i, cmd, err);
1158 * This is _inode_ placement policy function (not name).
1160 static int lmv_placement_policy(struct obd_device *obd,
1161 struct md_op_data *op_data, u32 *mds)
1163 struct lmv_obd *lmv = &obd->u.lmv;
1167 if (lmv->desc.ld_tgt_count == 1) {
1173 * If stripe_offset is provided during setdirstripe
1174 * (setdirstripe -i xx), xx MDS will be chosen.
1176 if (op_data->op_cli_flags & CLI_SET_MEA) {
1177 struct lmv_user_md *lum;
1179 lum = (struct lmv_user_md *)op_data->op_data;
1180 if (lum->lum_type == LMV_STRIPE_TYPE &&
1181 lum->lum_stripe_offset != -1) {
1182 if (lum->lum_stripe_offset >= lmv->desc.ld_tgt_count) {
1183 CERROR("%s: Stripe_offset %d > MDT count %d: rc = %d\n",
1185 lum->lum_stripe_offset,
1186 lmv->desc.ld_tgt_count, -ERANGE);
1189 *mds = lum->lum_stripe_offset;
1194 /* Allocate new fid on target according to operation type and parent
1197 *mds = op_data->op_mds;
1201 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid, u32 mds)
1203 struct lmv_tgt_desc *tgt;
1206 tgt = lmv_get_target(lmv, mds);
1208 return PTR_ERR(tgt);
1211 * New seq alloc and FLD setup should be atomic. Otherwise we may find
1212 * on server that seq in new allocated fid is not yet known.
1214 mutex_lock(&tgt->ltd_fid_mutex);
1216 if (tgt->ltd_active == 0 || !tgt->ltd_exp) {
1222 * Asking underlaying tgt layer to allocate new fid.
1224 rc = obd_fid_alloc(tgt->ltd_exp, fid, NULL);
1226 LASSERT(fid_is_sane(fid));
1231 mutex_unlock(&tgt->ltd_fid_mutex);
1235 int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
1236 struct md_op_data *op_data)
1238 struct obd_device *obd = class_exp2obd(exp);
1239 struct lmv_obd *lmv = &obd->u.lmv;
1246 rc = lmv_placement_policy(obd, op_data, &mds);
1248 CERROR("Can't get target for allocating fid, rc %d\n",
1253 rc = __lmv_fid_alloc(lmv, fid, mds);
1255 CERROR("Can't alloc new fid, rc %d\n", rc);
1262 static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
1264 struct lmv_obd *lmv = &obd->u.lmv;
1265 struct lprocfs_static_vars lvars = { NULL };
1266 struct lmv_desc *desc;
1269 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
1270 CERROR("LMV setup requires a descriptor\n");
1274 desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1);
1275 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
1276 CERROR("Lmv descriptor size wrong: %d > %d\n",
1277 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
1281 lmv->tgts = kcalloc(32, sizeof(*lmv->tgts), GFP_NOFS);
1284 lmv->tgts_size = 32;
1286 obd_str2uuid(&lmv->desc.ld_uuid, desc->ld_uuid.uuid);
1287 lmv->desc.ld_tgt_count = 0;
1288 lmv->desc.ld_active_tgt_count = 0;
1289 lmv->max_cookiesize = 0;
1290 lmv->max_def_easize = 0;
1291 lmv->max_easize = 0;
1292 lmv->lmv_placement = PLACEMENT_CHAR_POLICY;
1294 spin_lock_init(&lmv->lmv_lock);
1295 mutex_init(&lmv->lmv_init_mutex);
1297 lprocfs_lmv_init_vars(&lvars);
1299 lprocfs_obd_setup(obd, lvars.obd_vars, lvars.sysfs_vars);
1300 rc = ldebugfs_seq_create(obd->obd_debugfs_entry, "target_obd",
1301 0444, &lmv_proc_target_fops, obd);
1303 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
1305 rc = fld_client_init(&lmv->lmv_fld, obd->obd_name,
1306 LUSTRE_CLI_FLD_HASH_DHT);
1308 CERROR("Can't init FLD, err %d\n", rc);
1318 static int lmv_cleanup(struct obd_device *obd)
1320 struct lmv_obd *lmv = &obd->u.lmv;
1322 fld_client_fini(&lmv->lmv_fld);
1326 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1329 lmv_del_target(lmv, i);
1337 static int lmv_process_config(struct obd_device *obd, u32 len, void *buf)
1339 struct lustre_cfg *lcfg = buf;
1340 struct obd_uuid obd_uuid;
1345 switch (lcfg->lcfg_command) {
1347 /* modify_mdc_tgts add 0:lustre-clilmv 1:lustre-MDT0000_UUID
1348 * 2:0 3:1 4:lustre-MDT0000-mdc_UUID
1350 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid)) {
1355 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
1357 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1) {
1361 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1) {
1365 rc = lmv_add_target(obd, &obd_uuid, index, gen);
1368 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1376 static int lmv_statfs(const struct lu_env *env, struct obd_export *exp,
1377 struct obd_statfs *osfs, __u64 max_age, __u32 flags)
1379 struct obd_device *obd = class_exp2obd(exp);
1380 struct lmv_obd *lmv = &obd->u.lmv;
1381 struct obd_statfs *temp;
1385 rc = lmv_check_connect(obd);
1389 temp = kzalloc(sizeof(*temp), GFP_NOFS);
1393 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1394 if (!lmv->tgts[i] || !lmv->tgts[i]->ltd_exp)
1397 rc = obd_statfs(env, lmv->tgts[i]->ltd_exp, temp,
1400 CERROR("can't stat MDS #%d (%s), error %d\n", i,
1401 lmv->tgts[i]->ltd_exp->exp_obd->obd_name,
1408 /* If the statfs is from mount, it will needs
1409 * retrieve necessary information from MDT0.
1410 * i.e. mount does not need the merged osfs
1412 * And also clients can be mounted as long as
1413 * MDT0 is in service
1415 if (flags & OBD_STATFS_FOR_MDT0)
1418 osfs->os_bavail += temp->os_bavail;
1419 osfs->os_blocks += temp->os_blocks;
1420 osfs->os_ffree += temp->os_ffree;
1421 osfs->os_files += temp->os_files;
1430 static int lmv_getstatus(struct obd_export *exp,
1433 struct obd_device *obd = exp->exp_obd;
1434 struct lmv_obd *lmv = &obd->u.lmv;
1437 rc = lmv_check_connect(obd);
1441 rc = md_getstatus(lmv->tgts[0]->ltd_exp, fid);
1445 static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1446 u64 valid, const char *name,
1447 const char *input, int input_size, int output_size,
1448 int flags, struct ptlrpc_request **request)
1450 struct obd_device *obd = exp->exp_obd;
1451 struct lmv_obd *lmv = &obd->u.lmv;
1452 struct lmv_tgt_desc *tgt;
1455 rc = lmv_check_connect(obd);
1459 tgt = lmv_find_target(lmv, fid);
1461 return PTR_ERR(tgt);
1463 rc = md_getxattr(tgt->ltd_exp, fid, valid, name, input,
1464 input_size, output_size, flags, request);
1469 static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1470 u64 valid, const char *name,
1471 const char *input, int input_size, int output_size,
1472 int flags, __u32 suppgid,
1473 struct ptlrpc_request **request)
1475 struct obd_device *obd = exp->exp_obd;
1476 struct lmv_obd *lmv = &obd->u.lmv;
1477 struct lmv_tgt_desc *tgt;
1480 rc = lmv_check_connect(obd);
1484 tgt = lmv_find_target(lmv, fid);
1486 return PTR_ERR(tgt);
1488 rc = md_setxattr(tgt->ltd_exp, fid, valid, name, input,
1489 input_size, output_size, flags, suppgid,
1495 static int lmv_getattr(struct obd_export *exp, struct md_op_data *op_data,
1496 struct ptlrpc_request **request)
1498 struct obd_device *obd = exp->exp_obd;
1499 struct lmv_obd *lmv = &obd->u.lmv;
1500 struct lmv_tgt_desc *tgt;
1503 rc = lmv_check_connect(obd);
1507 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1509 return PTR_ERR(tgt);
1511 if (op_data->op_flags & MF_GET_MDT_IDX) {
1512 op_data->op_mds = tgt->ltd_idx;
1516 rc = md_getattr(tgt->ltd_exp, op_data, request);
1521 static int lmv_null_inode(struct obd_export *exp, const struct lu_fid *fid)
1523 struct obd_device *obd = exp->exp_obd;
1524 struct lmv_obd *lmv = &obd->u.lmv;
1528 rc = lmv_check_connect(obd);
1532 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1535 * With DNE every object can have two locks in different namespaces:
1536 * lookup lock in space of MDT storing direntry and update/open lock in
1537 * space of MDT storing inode.
1539 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1540 if (!lmv->tgts[i] || !lmv->tgts[i]->ltd_exp)
1542 md_null_inode(lmv->tgts[i]->ltd_exp, fid);
1548 static int lmv_find_cbdata(struct obd_export *exp, const struct lu_fid *fid,
1549 ldlm_iterator_t it, void *data)
1551 struct obd_device *obd = exp->exp_obd;
1552 struct lmv_obd *lmv = &obd->u.lmv;
1556 rc = lmv_check_connect(obd);
1560 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1563 * With DNE every object can have two locks in different namespaces:
1564 * lookup lock in space of MDT storing direntry and update/open lock in
1565 * space of MDT storing inode.
1567 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1568 if (!lmv->tgts[i] || !lmv->tgts[i]->ltd_exp)
1570 rc = md_find_cbdata(lmv->tgts[i]->ltd_exp, fid, it, data);
1578 static int lmv_close(struct obd_export *exp, struct md_op_data *op_data,
1579 struct md_open_data *mod, struct ptlrpc_request **request)
1581 struct obd_device *obd = exp->exp_obd;
1582 struct lmv_obd *lmv = &obd->u.lmv;
1583 struct lmv_tgt_desc *tgt;
1586 rc = lmv_check_connect(obd);
1590 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1592 return PTR_ERR(tgt);
1594 CDEBUG(D_INODE, "CLOSE "DFID"\n", PFID(&op_data->op_fid1));
1595 rc = md_close(tgt->ltd_exp, op_data, mod, request);
1600 *lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1603 struct lmv_tgt_desc *tgt;
1605 tgt = lmv_find_target(lmv, fid);
1609 op_data->op_mds = tgt->ltd_idx;
1614 static int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
1615 const void *data, int datalen, int mode, __u32 uid,
1616 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1617 struct ptlrpc_request **request)
1619 struct obd_device *obd = exp->exp_obd;
1620 struct lmv_obd *lmv = &obd->u.lmv;
1621 struct lmv_tgt_desc *tgt;
1624 rc = lmv_check_connect(obd);
1628 if (!lmv->desc.ld_active_tgt_count)
1631 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1633 return PTR_ERR(tgt);
1635 rc = lmv_fid_alloc(exp, &op_data->op_fid2, op_data);
1639 CDEBUG(D_INODE, "CREATE '%*s' on "DFID" -> mds #%x\n",
1640 op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1),
1643 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1644 rc = md_create(tgt->ltd_exp, op_data, data, datalen, mode, uid, gid,
1645 cap_effective, rdev, request);
1650 CDEBUG(D_INODE, "Created - "DFID"\n", PFID(&op_data->op_fid2));
1655 static int lmv_done_writing(struct obd_export *exp,
1656 struct md_op_data *op_data,
1657 struct md_open_data *mod)
1659 struct obd_device *obd = exp->exp_obd;
1660 struct lmv_obd *lmv = &obd->u.lmv;
1661 struct lmv_tgt_desc *tgt;
1664 rc = lmv_check_connect(obd);
1668 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1670 return PTR_ERR(tgt);
1672 rc = md_done_writing(tgt->ltd_exp, op_data, mod);
1677 lmv_enqueue_remote(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1678 struct lookup_intent *it, struct md_op_data *op_data,
1679 struct lustre_handle *lockh, void *lmm, int lmmsize,
1680 __u64 extra_lock_flags)
1682 struct ptlrpc_request *req = it->it_request;
1683 struct obd_device *obd = exp->exp_obd;
1684 struct lmv_obd *lmv = &obd->u.lmv;
1685 struct lustre_handle plock;
1686 struct lmv_tgt_desc *tgt;
1687 struct md_op_data *rdata;
1689 struct mdt_body *body;
1693 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1695 if (!(body->valid & OBD_MD_MDS))
1698 CDEBUG(D_INODE, "REMOTE_ENQUEUE '%s' on "DFID" -> "DFID"\n",
1699 LL_IT2STR(it), PFID(&op_data->op_fid1), PFID(&body->fid1));
1702 * We got LOOKUP lock, but we really need attrs.
1704 pmode = it->it_lock_mode;
1705 LASSERT(pmode != 0);
1706 memcpy(&plock, lockh, sizeof(plock));
1707 it->it_lock_mode = 0;
1708 it->it_request = NULL;
1711 ptlrpc_req_finished(req);
1713 tgt = lmv_find_target(lmv, &fid1);
1719 rdata = kzalloc(sizeof(*rdata), GFP_NOFS);
1725 rdata->op_fid1 = fid1;
1726 rdata->op_bias = MDS_CROSS_REF;
1728 rc = md_enqueue(tgt->ltd_exp, einfo, it, rdata, lockh,
1729 lmm, lmmsize, NULL, extra_lock_flags);
1732 ldlm_lock_decref(&plock, pmode);
1737 lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1738 struct lookup_intent *it, struct md_op_data *op_data,
1739 struct lustre_handle *lockh, void *lmm, int lmmsize,
1740 struct ptlrpc_request **req, __u64 extra_lock_flags)
1742 struct obd_device *obd = exp->exp_obd;
1743 struct lmv_obd *lmv = &obd->u.lmv;
1744 struct lmv_tgt_desc *tgt;
1747 rc = lmv_check_connect(obd);
1751 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID"\n",
1752 LL_IT2STR(it), PFID(&op_data->op_fid1));
1754 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1756 return PTR_ERR(tgt);
1758 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID" -> mds #%d\n",
1759 LL_IT2STR(it), PFID(&op_data->op_fid1), tgt->ltd_idx);
1761 rc = md_enqueue(tgt->ltd_exp, einfo, it, op_data, lockh,
1762 lmm, lmmsize, req, extra_lock_flags);
1764 if (rc == 0 && it && it->it_op == IT_OPEN) {
1765 rc = lmv_enqueue_remote(exp, einfo, it, op_data, lockh,
1766 lmm, lmmsize, extra_lock_flags);
1772 lmv_getattr_name(struct obd_export *exp, struct md_op_data *op_data,
1773 struct ptlrpc_request **request)
1775 struct ptlrpc_request *req = NULL;
1776 struct obd_device *obd = exp->exp_obd;
1777 struct lmv_obd *lmv = &obd->u.lmv;
1778 struct lmv_tgt_desc *tgt;
1779 struct mdt_body *body;
1782 rc = lmv_check_connect(obd);
1786 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1788 return PTR_ERR(tgt);
1790 CDEBUG(D_INODE, "GETATTR_NAME for %*s on "DFID" -> mds #%d\n",
1791 op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1),
1794 rc = md_getattr_name(tgt->ltd_exp, op_data, request);
1798 body = req_capsule_server_get(&(*request)->rq_pill,
1801 if (body->valid & OBD_MD_MDS) {
1802 struct lu_fid rid = body->fid1;
1804 CDEBUG(D_INODE, "Request attrs for "DFID"\n",
1807 tgt = lmv_find_target(lmv, &rid);
1809 ptlrpc_req_finished(*request);
1810 return PTR_ERR(tgt);
1813 op_data->op_fid1 = rid;
1814 op_data->op_valid |= OBD_MD_FLCROSSREF;
1815 op_data->op_namelen = 0;
1816 op_data->op_name = NULL;
1817 rc = md_getattr_name(tgt->ltd_exp, op_data, &req);
1818 ptlrpc_req_finished(*request);
1825 #define md_op_data_fid(op_data, fl) \
1826 (fl == MF_MDC_CANCEL_FID1 ? &op_data->op_fid1 : \
1827 fl == MF_MDC_CANCEL_FID2 ? &op_data->op_fid2 : \
1828 fl == MF_MDC_CANCEL_FID3 ? &op_data->op_fid3 : \
1829 fl == MF_MDC_CANCEL_FID4 ? &op_data->op_fid4 : \
1832 static int lmv_early_cancel(struct obd_export *exp, struct md_op_data *op_data,
1833 int op_tgt, enum ldlm_mode mode, int bits,
1836 struct lu_fid *fid = md_op_data_fid(op_data, flag);
1837 struct obd_device *obd = exp->exp_obd;
1838 struct lmv_obd *lmv = &obd->u.lmv;
1839 struct lmv_tgt_desc *tgt;
1840 ldlm_policy_data_t policy = { {0} };
1843 if (!fid_is_sane(fid))
1846 tgt = lmv_find_target(lmv, fid);
1848 return PTR_ERR(tgt);
1850 if (tgt->ltd_idx != op_tgt) {
1851 CDEBUG(D_INODE, "EARLY_CANCEL on "DFID"\n", PFID(fid));
1852 policy.l_inodebits.bits = bits;
1853 rc = md_cancel_unused(tgt->ltd_exp, fid, &policy,
1854 mode, LCF_ASYNC, NULL);
1857 "EARLY_CANCEL skip operation target %d on "DFID"\n",
1859 op_data->op_flags |= flag;
1867 * llite passes fid of an target inode in op_data->op_fid1 and id of directory in
1870 static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
1871 struct ptlrpc_request **request)
1873 struct obd_device *obd = exp->exp_obd;
1874 struct lmv_obd *lmv = &obd->u.lmv;
1875 struct lmv_tgt_desc *tgt;
1878 rc = lmv_check_connect(obd);
1882 LASSERT(op_data->op_namelen != 0);
1884 CDEBUG(D_INODE, "LINK "DFID":%*s to "DFID"\n",
1885 PFID(&op_data->op_fid2), op_data->op_namelen,
1886 op_data->op_name, PFID(&op_data->op_fid1));
1888 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
1889 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
1890 op_data->op_cap = cfs_curproc_cap_pack();
1891 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
1893 return PTR_ERR(tgt);
1896 * Cancel UPDATE lock on child (fid1).
1898 op_data->op_flags |= MF_MDC_CANCEL_FID2;
1899 rc = lmv_early_cancel(exp, op_data, tgt->ltd_idx, LCK_EX,
1900 MDS_INODELOCK_UPDATE, MF_MDC_CANCEL_FID1);
1904 rc = md_link(tgt->ltd_exp, op_data, request);
1909 static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
1910 const char *old, int oldlen, const char *new, int newlen,
1911 struct ptlrpc_request **request)
1913 struct obd_device *obd = exp->exp_obd;
1914 struct lmv_obd *lmv = &obd->u.lmv;
1915 struct lmv_tgt_desc *src_tgt;
1916 struct lmv_tgt_desc *tgt_tgt;
1919 LASSERT(oldlen != 0);
1921 CDEBUG(D_INODE, "RENAME %*s in "DFID" to %*s in "DFID"\n",
1922 oldlen, old, PFID(&op_data->op_fid1),
1923 newlen, new, PFID(&op_data->op_fid2));
1925 rc = lmv_check_connect(obd);
1929 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
1930 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
1931 op_data->op_cap = cfs_curproc_cap_pack();
1932 src_tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1933 if (IS_ERR(src_tgt))
1934 return PTR_ERR(src_tgt);
1936 tgt_tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
1937 if (IS_ERR(tgt_tgt))
1938 return PTR_ERR(tgt_tgt);
1940 * LOOKUP lock on src child (fid3) should also be cancelled for
1941 * src_tgt in mdc_rename.
1943 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
1946 * Cancel UPDATE locks on tgt parent (fid2), tgt_tgt is its
1949 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
1950 LCK_EX, MDS_INODELOCK_UPDATE,
1951 MF_MDC_CANCEL_FID2);
1954 * Cancel LOOKUP locks on tgt child (fid4) for parent tgt_tgt.
1957 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
1958 LCK_EX, MDS_INODELOCK_LOOKUP,
1959 MF_MDC_CANCEL_FID4);
1963 * Cancel all the locks on tgt child (fid4).
1966 rc = lmv_early_cancel(exp, op_data, src_tgt->ltd_idx,
1967 LCK_EX, MDS_INODELOCK_FULL,
1968 MF_MDC_CANCEL_FID4);
1971 rc = md_rename(src_tgt->ltd_exp, op_data, old, oldlen,
1972 new, newlen, request);
1976 static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
1977 void *ea, int ealen, void *ea2, int ea2len,
1978 struct ptlrpc_request **request,
1979 struct md_open_data **mod)
1981 struct obd_device *obd = exp->exp_obd;
1982 struct lmv_obd *lmv = &obd->u.lmv;
1983 struct lmv_tgt_desc *tgt;
1986 rc = lmv_check_connect(obd);
1990 CDEBUG(D_INODE, "SETATTR for "DFID", valid 0x%x\n",
1991 PFID(&op_data->op_fid1), op_data->op_attr.ia_valid);
1993 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1994 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1996 return PTR_ERR(tgt);
1998 rc = md_setattr(tgt->ltd_exp, op_data, ea, ealen, ea2,
1999 ea2len, request, mod);
2004 static int lmv_sync(struct obd_export *exp, const struct lu_fid *fid,
2005 struct ptlrpc_request **request)
2007 struct obd_device *obd = exp->exp_obd;
2008 struct lmv_obd *lmv = &obd->u.lmv;
2009 struct lmv_tgt_desc *tgt;
2012 rc = lmv_check_connect(obd);
2016 tgt = lmv_find_target(lmv, fid);
2018 return PTR_ERR(tgt);
2020 rc = md_sync(tgt->ltd_exp, fid, request);
2025 * Adjust a set of pages, each page containing an array of lu_dirpages,
2026 * so that each page can be used as a single logical lu_dirpage.
2028 * A lu_dirpage is laid out as follows, where s = ldp_hash_start,
2029 * e = ldp_hash_end, f = ldp_flags, p = padding, and each "ent" is a
2030 * struct lu_dirent. It has size up to LU_PAGE_SIZE. The ldp_hash_end
2031 * value is used as a cookie to request the next lu_dirpage in a
2032 * directory listing that spans multiple pages (two in this example):
2035 * .|--------v------- -----.
2036 * |s|e|f|p|ent|ent| ... |ent|
2037 * '--|-------------- -----' Each CFS_PAGE contains a single
2038 * '------. lu_dirpage.
2039 * .---------v------- -----.
2040 * |s|e|f|p|ent| 0 | ... | 0 |
2041 * '----------------- -----'
2043 * However, on hosts where the native VM page size (PAGE_SIZE) is
2044 * larger than LU_PAGE_SIZE, a single host page may contain multiple
2045 * lu_dirpages. After reading the lu_dirpages from the MDS, the
2046 * ldp_hash_end of the first lu_dirpage refers to the one immediately
2047 * after it in the same CFS_PAGE (arrows simplified for brevity, but
2048 * in general e0==s1, e1==s2, etc.):
2050 * .-------------------- -----.
2051 * |s0|e0|f0|p|ent|ent| ... |ent|
2052 * |---v---------------- -----|
2053 * |s1|e1|f1|p|ent|ent| ... |ent|
2054 * |---v---------------- -----| Here, each CFS_PAGE contains
2055 * ... multiple lu_dirpages.
2056 * |---v---------------- -----|
2057 * |s'|e'|f'|p|ent|ent| ... |ent|
2058 * '---|---------------- -----'
2060 * .----------------------------.
2063 * This structure is transformed into a single logical lu_dirpage as follows:
2065 * - Replace e0 with e' so the request for the next lu_dirpage gets the page
2066 * labeled 'next CFS_PAGE'.
2068 * - Copy the LDF_COLLIDE flag from f' to f0 to correctly reflect whether
2069 * a hash collision with the next page exists.
2071 * - Adjust the lde_reclen of the ending entry of each lu_dirpage to span
2072 * to the first entry of the next lu_dirpage.
2074 #if PAGE_SIZE > LU_PAGE_SIZE
2075 static void lmv_adjust_dirpages(struct page **pages, int ncfspgs, int nlupgs)
2079 for (i = 0; i < ncfspgs; i++) {
2080 struct lu_dirpage *dp = kmap(pages[i]);
2081 struct lu_dirpage *first = dp;
2082 struct lu_dirent *end_dirent = NULL;
2083 struct lu_dirent *ent;
2084 __u64 hash_end = dp->ldp_hash_end;
2085 __u32 flags = dp->ldp_flags;
2087 while (--nlupgs > 0) {
2088 ent = lu_dirent_start(dp);
2089 for (end_dirent = ent; ent;
2090 end_dirent = ent, ent = lu_dirent_next(ent))
2093 /* Advance dp to next lu_dirpage. */
2094 dp = (struct lu_dirpage *)((char *)dp + LU_PAGE_SIZE);
2096 /* Check if we've reached the end of the CFS_PAGE. */
2097 if (!((unsigned long)dp & ~PAGE_MASK))
2100 /* Save the hash and flags of this lu_dirpage. */
2101 hash_end = dp->ldp_hash_end;
2102 flags = dp->ldp_flags;
2104 /* Check if lu_dirpage contains no entries. */
2108 /* Enlarge the end entry lde_reclen from 0 to
2109 * first entry of next lu_dirpage.
2111 LASSERT(le16_to_cpu(end_dirent->lde_reclen) == 0);
2112 end_dirent->lde_reclen =
2113 cpu_to_le16((char *)(dp->ldp_entries) -
2114 (char *)end_dirent);
2117 first->ldp_hash_end = hash_end;
2118 first->ldp_flags &= ~cpu_to_le32(LDF_COLLIDE);
2119 first->ldp_flags |= flags & cpu_to_le32(LDF_COLLIDE);
2123 LASSERTF(nlupgs == 0, "left = %d", nlupgs);
2126 #define lmv_adjust_dirpages(pages, ncfspgs, nlupgs) do {} while (0)
2127 #endif /* PAGE_SIZE > LU_PAGE_SIZE */
2129 static int lmv_readpage(struct obd_export *exp, struct md_op_data *op_data,
2130 struct page **pages, struct ptlrpc_request **request)
2132 struct obd_device *obd = exp->exp_obd;
2133 struct lmv_obd *lmv = &obd->u.lmv;
2134 __u64 offset = op_data->op_offset;
2136 int ncfspgs; /* pages read in PAGE_SIZE */
2137 int nlupgs; /* pages read in LU_PAGE_SIZE */
2138 struct lmv_tgt_desc *tgt;
2140 rc = lmv_check_connect(obd);
2144 CDEBUG(D_INODE, "READPAGE at %#llx from "DFID"\n",
2145 offset, PFID(&op_data->op_fid1));
2147 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2149 return PTR_ERR(tgt);
2151 rc = md_readpage(tgt->ltd_exp, op_data, pages, request);
2155 ncfspgs = ((*request)->rq_bulk->bd_nob_transferred + PAGE_SIZE - 1)
2157 nlupgs = (*request)->rq_bulk->bd_nob_transferred >> LU_PAGE_SHIFT;
2158 LASSERT(!((*request)->rq_bulk->bd_nob_transferred & ~LU_PAGE_MASK));
2159 LASSERT(ncfspgs > 0 && ncfspgs <= op_data->op_npages);
2161 CDEBUG(D_INODE, "read %d(%d)/%d pages\n", ncfspgs, nlupgs,
2162 op_data->op_npages);
2164 lmv_adjust_dirpages(pages, ncfspgs, nlupgs);
2169 static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
2170 struct ptlrpc_request **request)
2172 struct obd_device *obd = exp->exp_obd;
2173 struct lmv_obd *lmv = &obd->u.lmv;
2174 struct lmv_tgt_desc *tgt = NULL;
2175 struct mdt_body *body;
2178 rc = lmv_check_connect(obd);
2182 /* Send unlink requests to the MDT where the child is located */
2183 if (likely(!fid_is_zero(&op_data->op_fid2)))
2184 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
2186 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
2188 return PTR_ERR(tgt);
2190 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
2191 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
2192 op_data->op_cap = cfs_curproc_cap_pack();
2195 * If child's fid is given, cancel unused locks for it if it is from
2196 * another export than parent.
2198 * LOOKUP lock for child (fid3) should also be cancelled on parent
2199 * tgt_tgt in mdc_unlink().
2201 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2204 * Cancel FULL locks on child (fid3).
2206 rc = lmv_early_cancel(exp, op_data, tgt->ltd_idx, LCK_EX,
2207 MDS_INODELOCK_FULL, MF_MDC_CANCEL_FID3);
2212 CDEBUG(D_INODE, "unlink with fid="DFID"/"DFID" -> mds #%d\n",
2213 PFID(&op_data->op_fid1), PFID(&op_data->op_fid2), tgt->ltd_idx);
2215 rc = md_unlink(tgt->ltd_exp, op_data, request);
2216 if (rc != 0 && rc != -EREMOTE)
2219 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
2223 /* Not cross-ref case, just get out of here. */
2224 if (likely(!(body->valid & OBD_MD_MDS)))
2227 CDEBUG(D_INODE, "%s: try unlink to another MDT for "DFID"\n",
2228 exp->exp_obd->obd_name, PFID(&body->fid1));
2230 /* This is a remote object, try remote MDT, Note: it may
2231 * try more than 1 time here, Considering following case
2232 * /mnt/lustre is root on MDT0, remote1 is on MDT1
2233 * 1. Initially A does not know where remote1 is, it send
2234 * unlink RPC to MDT0, MDT0 return -EREMOTE, it will
2235 * resend unlink RPC to MDT1 (retry 1st time).
2237 * 2. During the unlink RPC in flight,
2238 * client B mv /mnt/lustre/remote1 /mnt/lustre/remote2
2239 * and create new remote1, but on MDT0
2241 * 3. MDT1 get unlink RPC(from A), then do remote lock on
2242 * /mnt/lustre, then lookup get fid of remote1, and find
2243 * it is remote dir again, and replay -EREMOTE again.
2245 * 4. Then A will resend unlink RPC to MDT0. (retry 2nd times).
2247 * In theory, it might try unlimited time here, but it should
2248 * be very rare case.
2250 op_data->op_fid2 = body->fid1;
2251 ptlrpc_req_finished(*request);
2257 static int lmv_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2259 struct lmv_obd *lmv = &obd->u.lmv;
2262 case OBD_CLEANUP_EARLY:
2263 /* XXX: here should be calling obd_precleanup() down to
2267 case OBD_CLEANUP_EXPORTS:
2268 fld_client_debugfs_fini(&lmv->lmv_fld);
2269 lprocfs_obd_cleanup(obd);
2277 static int lmv_get_info(const struct lu_env *env, struct obd_export *exp,
2278 __u32 keylen, void *key, __u32 *vallen, void *val,
2279 struct lov_stripe_md *lsm)
2281 struct obd_device *obd;
2282 struct lmv_obd *lmv;
2285 obd = class_exp2obd(exp);
2287 CDEBUG(D_IOCTL, "Invalid client cookie %#llx\n",
2288 exp->exp_handle.h_cookie);
2293 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
2296 rc = lmv_check_connect(obd);
2300 LASSERT(*vallen == sizeof(__u32));
2301 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2302 struct lmv_tgt_desc *tgt = lmv->tgts[i];
2305 * All tgts should be connected when this gets called.
2307 if (!tgt || !tgt->ltd_exp)
2310 if (!obd_get_info(env, tgt->ltd_exp, keylen, key,
2315 } else if (KEY_IS(KEY_MAX_EASIZE) ||
2316 KEY_IS(KEY_DEFAULT_EASIZE) ||
2317 KEY_IS(KEY_CONN_DATA)) {
2318 rc = lmv_check_connect(obd);
2323 * Forwarding this request to first MDS, it should know LOV
2326 rc = obd_get_info(env, lmv->tgts[0]->ltd_exp, keylen, key,
2328 if (!rc && KEY_IS(KEY_CONN_DATA))
2329 exp->exp_connect_data = *(struct obd_connect_data *)val;
2331 } else if (KEY_IS(KEY_TGT_COUNT)) {
2332 *((int *)val) = lmv->desc.ld_tgt_count;
2336 CDEBUG(D_IOCTL, "Invalid key\n");
2340 static int lmv_set_info_async(const struct lu_env *env, struct obd_export *exp,
2341 u32 keylen, void *key, u32 vallen,
2342 void *val, struct ptlrpc_request_set *set)
2344 struct lmv_tgt_desc *tgt;
2345 struct obd_device *obd;
2346 struct lmv_obd *lmv;
2349 obd = class_exp2obd(exp);
2351 CDEBUG(D_IOCTL, "Invalid client cookie %#llx\n",
2352 exp->exp_handle.h_cookie);
2357 if (KEY_IS(KEY_READ_ONLY) || KEY_IS(KEY_FLUSH_CTX)) {
2360 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2363 if (!tgt || !tgt->ltd_exp)
2366 err = obd_set_info_async(env, tgt->ltd_exp,
2367 keylen, key, vallen, val, set);
2378 static int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
2379 struct lov_stripe_md *lsm)
2381 struct obd_device *obd = class_exp2obd(exp);
2382 struct lmv_obd *lmv = &obd->u.lmv;
2383 struct lmv_stripe_md *meap;
2384 struct lmv_stripe_md *lsmp;
2388 mea_size = lmv_get_easize(lmv);
2392 if (*lmmp && !lsm) {
2399 *lmmp = libcfs_kvzalloc(mea_size, GFP_NOFS);
2407 lsmp = (struct lmv_stripe_md *)lsm;
2408 meap = (struct lmv_stripe_md *)*lmmp;
2410 if (lsmp->mea_magic != MEA_MAGIC_LAST_CHAR &&
2411 lsmp->mea_magic != MEA_MAGIC_ALL_CHARS)
2414 meap->mea_magic = cpu_to_le32(lsmp->mea_magic);
2415 meap->mea_count = cpu_to_le32(lsmp->mea_count);
2416 meap->mea_master = cpu_to_le32(lsmp->mea_master);
2418 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2419 meap->mea_ids[i] = lsmp->mea_ids[i];
2420 fid_cpu_to_le(&meap->mea_ids[i], &lsmp->mea_ids[i]);
2426 static int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
2427 struct lov_mds_md *lmm, int lmm_size)
2429 struct obd_device *obd = class_exp2obd(exp);
2430 struct lmv_stripe_md **tmea = (struct lmv_stripe_md **)lsmp;
2431 struct lmv_stripe_md *mea = (struct lmv_stripe_md *)lmm;
2432 struct lmv_obd *lmv = &obd->u.lmv;
2437 mea_size = lmv_get_easize(lmv);
2441 if (*lsmp && !lmm) {
2447 LASSERT(mea_size == lmm_size);
2449 *tmea = libcfs_kvzalloc(mea_size, GFP_NOFS);
2456 if (mea->mea_magic == MEA_MAGIC_LAST_CHAR ||
2457 mea->mea_magic == MEA_MAGIC_ALL_CHARS ||
2458 mea->mea_magic == MEA_MAGIC_HASH_SEGMENT) {
2459 magic = le32_to_cpu(mea->mea_magic);
2462 * Old mea is not handled here.
2464 CERROR("Old not supportable EA is found\n");
2468 (*tmea)->mea_magic = magic;
2469 (*tmea)->mea_count = le32_to_cpu(mea->mea_count);
2470 (*tmea)->mea_master = le32_to_cpu(mea->mea_master);
2472 for (i = 0; i < (*tmea)->mea_count; i++) {
2473 (*tmea)->mea_ids[i] = mea->mea_ids[i];
2474 fid_le_to_cpu(&(*tmea)->mea_ids[i], &(*tmea)->mea_ids[i]);
2479 static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
2480 ldlm_policy_data_t *policy, enum ldlm_mode mode,
2481 enum ldlm_cancel_flags flags, void *opaque)
2483 struct obd_device *obd = exp->exp_obd;
2484 struct lmv_obd *lmv = &obd->u.lmv;
2491 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2492 struct lmv_tgt_desc *tgt = lmv->tgts[i];
2494 if (!tgt || !tgt->ltd_exp || !tgt->ltd_active)
2497 err = md_cancel_unused(tgt->ltd_exp, fid, policy, mode, flags,
2505 static int lmv_set_lock_data(struct obd_export *exp, __u64 *lockh, void *data,
2508 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2509 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2512 if (!tgt || !tgt->ltd_exp)
2515 rc = md_set_lock_data(tgt->ltd_exp, lockh, data, bits);
2519 static enum ldlm_mode lmv_lock_match(struct obd_export *exp, __u64 flags,
2520 const struct lu_fid *fid,
2521 enum ldlm_type type,
2522 ldlm_policy_data_t *policy,
2523 enum ldlm_mode mode,
2524 struct lustre_handle *lockh)
2526 struct obd_device *obd = exp->exp_obd;
2527 struct lmv_obd *lmv = &obd->u.lmv;
2531 CDEBUG(D_INODE, "Lock match for "DFID"\n", PFID(fid));
2534 * With CMD every object can have two locks in different namespaces:
2535 * lookup lock in space of mds storing direntry and update/open lock in
2536 * space of mds storing inode. Thus we check all targets, not only that
2537 * one fid was created in.
2539 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2540 struct lmv_tgt_desc *tgt = lmv->tgts[i];
2542 if (!tgt || !tgt->ltd_exp || !tgt->ltd_active)
2545 rc = md_lock_match(tgt->ltd_exp, flags, fid, type, policy, mode,
2554 static int lmv_get_lustre_md(struct obd_export *exp,
2555 struct ptlrpc_request *req,
2556 struct obd_export *dt_exp,
2557 struct obd_export *md_exp,
2558 struct lustre_md *md)
2560 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2561 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2563 if (!tgt || !tgt->ltd_exp)
2565 return md_get_lustre_md(tgt->ltd_exp, req, dt_exp, md_exp, md);
2568 static int lmv_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
2570 struct obd_device *obd = exp->exp_obd;
2571 struct lmv_obd *lmv = &obd->u.lmv;
2572 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2575 obd_free_memmd(exp, (void *)&md->mea);
2576 if (!tgt || !tgt->ltd_exp)
2578 return md_free_lustre_md(tgt->ltd_exp, md);
2581 static int lmv_set_open_replay_data(struct obd_export *exp,
2582 struct obd_client_handle *och,
2583 struct lookup_intent *it)
2585 struct obd_device *obd = exp->exp_obd;
2586 struct lmv_obd *lmv = &obd->u.lmv;
2587 struct lmv_tgt_desc *tgt;
2589 tgt = lmv_find_target(lmv, &och->och_fid);
2591 return PTR_ERR(tgt);
2593 return md_set_open_replay_data(tgt->ltd_exp, och, it);
2596 static int lmv_clear_open_replay_data(struct obd_export *exp,
2597 struct obd_client_handle *och)
2599 struct obd_device *obd = exp->exp_obd;
2600 struct lmv_obd *lmv = &obd->u.lmv;
2601 struct lmv_tgt_desc *tgt;
2603 tgt = lmv_find_target(lmv, &och->och_fid);
2605 return PTR_ERR(tgt);
2607 return md_clear_open_replay_data(tgt->ltd_exp, och);
2610 static int lmv_intent_getattr_async(struct obd_export *exp,
2611 struct md_enqueue_info *minfo,
2612 struct ldlm_enqueue_info *einfo)
2614 struct md_op_data *op_data = &minfo->mi_data;
2615 struct obd_device *obd = exp->exp_obd;
2616 struct lmv_obd *lmv = &obd->u.lmv;
2617 struct lmv_tgt_desc *tgt = NULL;
2620 rc = lmv_check_connect(obd);
2624 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2626 return PTR_ERR(tgt);
2628 rc = md_intent_getattr_async(tgt->ltd_exp, minfo, einfo);
2632 static int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
2633 struct lu_fid *fid, __u64 *bits)
2635 struct obd_device *obd = exp->exp_obd;
2636 struct lmv_obd *lmv = &obd->u.lmv;
2637 struct lmv_tgt_desc *tgt;
2640 rc = lmv_check_connect(obd);
2644 tgt = lmv_find_target(lmv, fid);
2646 return PTR_ERR(tgt);
2648 rc = md_revalidate_lock(tgt->ltd_exp, it, fid, bits);
2653 * For lmv, only need to send request to master MDT, and the master MDT will
2654 * process with other slave MDTs. The only exception is Q_GETOQUOTA for which
2655 * we directly fetch data from the slave MDTs.
2657 static int lmv_quotactl(struct obd_device *unused, struct obd_export *exp,
2658 struct obd_quotactl *oqctl)
2660 struct obd_device *obd = class_exp2obd(exp);
2661 struct lmv_obd *lmv = &obd->u.lmv;
2662 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2664 __u64 curspace = 0, curinodes = 0;
2666 if (!tgt || !tgt->ltd_exp || !tgt->ltd_active ||
2667 !lmv->desc.ld_tgt_count) {
2668 CERROR("master lmv inactive\n");
2672 if (oqctl->qc_cmd != Q_GETOQUOTA) {
2673 rc = obd_quotactl(tgt->ltd_exp, oqctl);
2677 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2682 if (!tgt || !tgt->ltd_exp || !tgt->ltd_active)
2685 err = obd_quotactl(tgt->ltd_exp, oqctl);
2687 CERROR("getquota on mdt %d failed. %d\n", i, err);
2691 curspace += oqctl->qc_dqblk.dqb_curspace;
2692 curinodes += oqctl->qc_dqblk.dqb_curinodes;
2695 oqctl->qc_dqblk.dqb_curspace = curspace;
2696 oqctl->qc_dqblk.dqb_curinodes = curinodes;
2701 static int lmv_quotacheck(struct obd_device *unused, struct obd_export *exp,
2702 struct obd_quotactl *oqctl)
2704 struct obd_device *obd = class_exp2obd(exp);
2705 struct lmv_obd *lmv = &obd->u.lmv;
2706 struct lmv_tgt_desc *tgt;
2709 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2713 if (!tgt || !tgt->ltd_exp || !tgt->ltd_active) {
2714 CERROR("lmv idx %d inactive\n", i);
2718 err = obd_quotacheck(tgt->ltd_exp, oqctl);
2726 static struct obd_ops lmv_obd_ops = {
2727 .owner = THIS_MODULE,
2729 .cleanup = lmv_cleanup,
2730 .precleanup = lmv_precleanup,
2731 .process_config = lmv_process_config,
2732 .connect = lmv_connect,
2733 .disconnect = lmv_disconnect,
2734 .statfs = lmv_statfs,
2735 .get_info = lmv_get_info,
2736 .set_info_async = lmv_set_info_async,
2737 .packmd = lmv_packmd,
2738 .unpackmd = lmv_unpackmd,
2739 .notify = lmv_notify,
2740 .get_uuid = lmv_get_uuid,
2741 .iocontrol = lmv_iocontrol,
2742 .quotacheck = lmv_quotacheck,
2743 .quotactl = lmv_quotactl
2746 static struct md_ops lmv_md_ops = {
2747 .getstatus = lmv_getstatus,
2748 .null_inode = lmv_null_inode,
2749 .find_cbdata = lmv_find_cbdata,
2751 .create = lmv_create,
2752 .done_writing = lmv_done_writing,
2753 .enqueue = lmv_enqueue,
2754 .getattr = lmv_getattr,
2755 .getxattr = lmv_getxattr,
2756 .getattr_name = lmv_getattr_name,
2757 .intent_lock = lmv_intent_lock,
2759 .rename = lmv_rename,
2760 .setattr = lmv_setattr,
2761 .setxattr = lmv_setxattr,
2763 .readpage = lmv_readpage,
2764 .unlink = lmv_unlink,
2765 .init_ea_size = lmv_init_ea_size,
2766 .cancel_unused = lmv_cancel_unused,
2767 .set_lock_data = lmv_set_lock_data,
2768 .lock_match = lmv_lock_match,
2769 .get_lustre_md = lmv_get_lustre_md,
2770 .free_lustre_md = lmv_free_lustre_md,
2771 .set_open_replay_data = lmv_set_open_replay_data,
2772 .clear_open_replay_data = lmv_clear_open_replay_data,
2773 .intent_getattr_async = lmv_intent_getattr_async,
2774 .revalidate_lock = lmv_revalidate_lock
2777 static int __init lmv_init(void)
2779 struct lprocfs_static_vars lvars;
2782 lprocfs_lmv_init_vars(&lvars);
2784 rc = class_register_type(&lmv_obd_ops, &lmv_md_ops,
2785 LUSTRE_LMV_NAME, NULL);
2789 static void lmv_exit(void)
2791 class_unregister_type(LUSTRE_LMV_NAME);
2794 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
2795 MODULE_DESCRIPTION("Lustre Logical Metadata Volume");
2796 MODULE_VERSION(LUSTRE_VERSION_STRING);
2797 MODULE_LICENSE("GPL");
2799 module_init(lmv_init);
2800 module_exit(lmv_exit);