4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_LMV
39 #include <linux/slab.h>
40 #include <linux/module.h>
41 #include <linux/init.h>
42 #include <linux/slab.h>
43 #include <linux/pagemap.h>
45 #include <asm/div64.h>
46 #include <linux/seq_file.h>
47 #include <linux/namei.h>
49 #include <liblustre.h>
52 #include <lustre/lustre_idl.h>
53 #include <obd_support.h>
54 #include <lustre_lib.h>
55 #include <lustre_net.h>
56 #include <obd_class.h>
57 #include <lustre_lmv.h>
58 #include <lprocfs_status.h>
59 #include <cl_object.h>
61 #include <lustre_lite.h>
62 #include <lustre_fid.h>
63 #include "lmv_internal.h"
65 /* This hash is only for testing purpose */
66 static inline unsigned int
67 lmv_hash_all_chars(unsigned int count, const char *name, int namelen)
70 const unsigned char *p = (const unsigned char *)name;
72 while (--namelen >= 0)
80 static inline unsigned int
81 lmv_hash_fnv1a(unsigned int count, const char *name, int namelen)
85 hash = lustre_hash_fnv_1a_64(name, namelen);
92 int lmv_name_to_stripe_index(enum lmv_hash_type hashtype,
93 unsigned int max_mdt_index,
94 const char *name, int namelen)
99 if (max_mdt_index <= 1)
103 case LMV_HASH_TYPE_ALL_CHARS:
104 idx = lmv_hash_all_chars(max_mdt_index, name, namelen);
106 case LMV_HASH_TYPE_FNV_1A_64:
107 idx = lmv_hash_fnv1a(max_mdt_index, name, namelen);
109 /* LMV_HASH_TYPE_MIGRATION means the file is being migrated,
110 * and the file should be accessed by client, except for
111 * lookup(see lmv_intent_lookup), return -EACCES here */
112 case LMV_HASH_TYPE_MIGRATION:
113 CERROR("%.*s is being migrated: rc = %d\n", namelen,
117 CERROR("Unknown hash type 0x%x\n", hashtype);
121 CDEBUG(D_INFO, "name %.*s hash_type %d idx %d\n", namelen, name,
124 LASSERT(idx < max_mdt_index);
128 static void lmv_activate_target(struct lmv_obd *lmv,
129 struct lmv_tgt_desc *tgt,
132 if (tgt->ltd_active == activate)
135 tgt->ltd_active = activate;
136 lmv->desc.ld_active_tgt_count += (activate ? 1 : -1);
142 * -EINVAL : UUID can't be found in the LMV's target list
143 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
144 * -EBADF : The UUID is found, but the OBD of the wrong type (!)
146 static int lmv_set_mdc_active(struct lmv_obd *lmv,
147 const struct obd_uuid *uuid,
150 struct lmv_tgt_desc *tgt = NULL;
151 struct obd_device *obd;
156 CDEBUG(D_INFO, "Searching in lmv %p for uuid %s (activate=%d)\n",
157 lmv, uuid->uuid, activate);
159 spin_lock(&lmv->lmv_lock);
160 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
162 if (tgt == NULL || tgt->ltd_exp == NULL)
165 CDEBUG(D_INFO, "Target idx %d is %s conn "LPX64"\n", i,
166 tgt->ltd_uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
168 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
172 if (i == lmv->desc.ld_tgt_count)
173 GOTO(out_lmv_lock, rc = -EINVAL);
175 obd = class_exp2obd(tgt->ltd_exp);
177 GOTO(out_lmv_lock, rc = -ENOTCONN);
179 CDEBUG(D_INFO, "Found OBD %s=%s device %d (%p) type %s at LMV idx %d\n",
180 obd->obd_name, obd->obd_uuid.uuid, obd->obd_minor, obd,
181 obd->obd_type->typ_name, i);
182 LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0);
184 if (tgt->ltd_active == activate) {
185 CDEBUG(D_INFO, "OBD %p already %sactive!\n", obd,
186 activate ? "" : "in");
187 GOTO(out_lmv_lock, rc);
190 CDEBUG(D_INFO, "Marking OBD %p %sactive\n", obd,
191 activate ? "" : "in");
192 lmv_activate_target(lmv, tgt, activate);
196 spin_unlock(&lmv->lmv_lock);
200 struct obd_uuid *lmv_get_uuid(struct obd_export *exp)
202 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
203 struct lmv_tgt_desc *tgt = lmv->tgts[0];
205 return (tgt == NULL) ? NULL : obd_get_uuid(tgt->ltd_exp);
208 static int lmv_notify(struct obd_device *obd, struct obd_device *watched,
209 enum obd_notify_event ev, void *data)
211 struct obd_connect_data *conn_data;
212 struct lmv_obd *lmv = &obd->u.lmv;
213 struct obd_uuid *uuid;
217 if (strcmp(watched->obd_type->typ_name, LUSTRE_MDC_NAME)) {
218 CERROR("unexpected notification of %s %s!\n",
219 watched->obd_type->typ_name,
224 uuid = &watched->u.cli.cl_target_uuid;
225 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE) {
227 * Set MDC as active before notifying the observer, so the
228 * observer can use the MDC normally.
230 rc = lmv_set_mdc_active(lmv, uuid,
231 ev == OBD_NOTIFY_ACTIVE);
233 CERROR("%sactivation of %s failed: %d\n",
234 ev == OBD_NOTIFY_ACTIVE ? "" : "de",
238 } else if (ev == OBD_NOTIFY_OCD) {
239 conn_data = &watched->u.cli.cl_import->imp_connect_data;
241 * XXX: Make sure that ocd_connect_flags from all targets are
242 * the same. Otherwise one of MDTs runs wrong version or
243 * something like this. --umka
245 obd->obd_self_export->exp_connect_data = *conn_data;
248 else if (ev == OBD_NOTIFY_DISCON) {
250 * For disconnect event, flush fld cache for failout MDS case.
252 fld_client_flush(&lmv->lmv_fld);
256 * Pass the notification up the chain.
258 if (obd->obd_observer)
259 rc = obd_notify(obd->obd_observer, watched, ev, data);
265 * This is fake connect function. Its purpose is to initialize lmv and say
266 * caller that everything is okay. Real connection will be performed later.
268 static int lmv_connect(const struct lu_env *env,
269 struct obd_export **exp, struct obd_device *obd,
270 struct obd_uuid *cluuid, struct obd_connect_data *data,
274 struct proc_dir_entry *lmv_proc_dir;
276 struct lmv_obd *lmv = &obd->u.lmv;
277 struct lustre_handle conn = { 0 };
282 * We don't want to actually do the underlying connections more than
283 * once, so keep track.
286 if (lmv->refcount > 1) {
291 rc = class_connect(&conn, obd, cluuid);
293 CERROR("class_connection() returned %d\n", rc);
297 *exp = class_conn2export(&conn);
298 class_export_get(*exp);
302 lmv->cluuid = *cluuid;
305 lmv->conn_data = *data;
308 if (obd->obd_proc_private != NULL) {
309 lmv_proc_dir = obd->obd_proc_private;
311 lmv_proc_dir = lprocfs_seq_register("target_obds",
314 if (IS_ERR(lmv_proc_dir)) {
315 CERROR("could not register /proc/fs/lustre/%s/%s/target_obds.",
316 obd->obd_type->typ_name, obd->obd_name);
319 obd->obd_proc_private = lmv_proc_dir;
324 * All real clients should perform actual connection right away, because
325 * it is possible, that LMV will not have opportunity to connect targets
326 * and MDC stuff will be called directly, for instance while reading
327 * ../mdc/../kbytesfree procfs file, etc.
329 if (data != NULL && (data->ocd_connect_flags & OBD_CONNECT_REAL))
330 rc = lmv_check_connect(obd);
333 if (rc && lmv_proc_dir) {
334 lprocfs_remove(&lmv_proc_dir);
335 obd->obd_proc_private = NULL;
341 static void lmv_set_timeouts(struct obd_device *obd)
347 if (lmv->server_timeout == 0)
350 if (lmv->connected == 0)
353 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
354 struct lmv_tgt_desc *tgt = lmv->tgts[i];
356 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
359 obd_set_info_async(NULL, tgt->ltd_exp, sizeof(KEY_INTERMDS),
360 KEY_INTERMDS, 0, NULL, NULL);
364 static int lmv_init_ea_size(struct obd_export *exp, int easize,
365 int def_easize, int cookiesize)
367 struct obd_device *obd = exp->exp_obd;
368 struct lmv_obd *lmv = &obd->u.lmv;
374 if (lmv->max_easize < easize) {
375 lmv->max_easize = easize;
378 if (lmv->max_def_easize < def_easize) {
379 lmv->max_def_easize = def_easize;
382 if (lmv->max_cookiesize < cookiesize) {
383 lmv->max_cookiesize = cookiesize;
389 if (lmv->connected == 0)
392 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
393 struct lmv_tgt_desc *tgt = lmv->tgts[i];
395 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active) {
396 CWARN("%s: NULL export for %d\n", obd->obd_name, i);
400 rc = md_init_ea_size(tgt->ltd_exp, easize, def_easize,
403 CERROR("%s: obd_init_ea_size() failed on MDT target %d:"
404 " rc = %d.\n", obd->obd_name, i, rc);
411 #define MAX_STRING_SIZE 128
413 int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
416 struct proc_dir_entry *lmv_proc_dir;
418 struct lmv_obd *lmv = &obd->u.lmv;
419 struct obd_uuid *cluuid = &lmv->cluuid;
420 struct obd_uuid lmv_mdc_uuid = { "LMV_MDC_UUID" };
421 struct obd_device *mdc_obd;
422 struct obd_export *mdc_exp;
423 struct lu_fld_target target;
427 mdc_obd = class_find_client_obd(&tgt->ltd_uuid, LUSTRE_MDC_NAME,
430 CERROR("target %s not attached\n", tgt->ltd_uuid.uuid);
434 CDEBUG(D_CONFIG, "connect to %s(%s) - %s, %s FOR %s\n",
435 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
436 tgt->ltd_uuid.uuid, obd->obd_uuid.uuid,
439 if (!mdc_obd->obd_set_up) {
440 CERROR("target %s is not set up\n", tgt->ltd_uuid.uuid);
444 rc = obd_connect(NULL, &mdc_exp, mdc_obd, &lmv_mdc_uuid,
445 &lmv->conn_data, NULL);
447 CERROR("target %s connect error %d\n", tgt->ltd_uuid.uuid, rc);
452 * Init fid sequence client for this mdc and add new fld target.
454 rc = obd_fid_init(mdc_obd, mdc_exp, LUSTRE_SEQ_METADATA);
458 target.ft_srv = NULL;
459 target.ft_exp = mdc_exp;
460 target.ft_idx = tgt->ltd_idx;
462 fld_client_add_target(&lmv->lmv_fld, &target);
464 rc = obd_register_observer(mdc_obd, obd);
466 obd_disconnect(mdc_exp);
467 CERROR("target %s register_observer error %d\n",
468 tgt->ltd_uuid.uuid, rc);
472 if (obd->obd_observer) {
474 * Tell the observer about the new target.
476 rc = obd_notify(obd->obd_observer, mdc_exp->exp_obd,
478 (void *)(tgt - lmv->tgts[0]));
480 obd_disconnect(mdc_exp);
486 tgt->ltd_exp = mdc_exp;
487 lmv->desc.ld_active_tgt_count++;
489 md_init_ea_size(tgt->ltd_exp, lmv->max_easize,
490 lmv->max_def_easize, lmv->max_cookiesize);
492 CDEBUG(D_CONFIG, "Connected to %s(%s) successfully (%d)\n",
493 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
494 cfs_atomic_read(&obd->obd_refcount));
497 lmv_proc_dir = obd->obd_proc_private;
499 struct proc_dir_entry *mdc_symlink;
501 LASSERT(mdc_obd->obd_type != NULL);
502 LASSERT(mdc_obd->obd_type->typ_name != NULL);
503 mdc_symlink = lprocfs_add_symlink(mdc_obd->obd_name,
506 mdc_obd->obd_type->typ_name,
508 if (mdc_symlink == NULL) {
509 CERROR("Could not register LMV target "
510 "/proc/fs/lustre/%s/%s/target_obds/%s.",
511 obd->obd_type->typ_name, obd->obd_name,
513 lprocfs_remove(&lmv_proc_dir);
514 obd->obd_proc_private = NULL;
521 static void lmv_del_target(struct lmv_obd *lmv, int index)
523 if (lmv->tgts[index] == NULL)
526 OBD_FREE_PTR(lmv->tgts[index]);
527 lmv->tgts[index] = NULL;
531 static int lmv_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
532 __u32 index, int gen)
534 struct lmv_obd *lmv = &obd->u.lmv;
535 struct lmv_tgt_desc *tgt;
539 CDEBUG(D_CONFIG, "Target uuid: %s. index %d\n", uuidp->uuid, index);
543 if (lmv->desc.ld_tgt_count == 0) {
544 struct obd_device *mdc_obd;
546 mdc_obd = class_find_client_obd(uuidp, LUSTRE_MDC_NAME,
549 lmv_init_unlock(lmv);
550 CERROR("%s: Target %s not attached: rc = %d\n",
551 obd->obd_name, uuidp->uuid, -EINVAL);
556 if ((index < lmv->tgts_size) && (lmv->tgts[index] != NULL)) {
557 tgt = lmv->tgts[index];
558 CERROR("%s: UUID %s already assigned at LOV target index %d:"
559 " rc = %d\n", obd->obd_name,
560 obd_uuid2str(&tgt->ltd_uuid), index, -EEXIST);
561 lmv_init_unlock(lmv);
565 if (index >= lmv->tgts_size) {
566 /* We need to reallocate the lmv target array. */
567 struct lmv_tgt_desc **newtgts, **old = NULL;
571 while (newsize < index + 1)
572 newsize = newsize << 1;
573 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
574 if (newtgts == NULL) {
575 lmv_init_unlock(lmv);
579 if (lmv->tgts_size) {
580 memcpy(newtgts, lmv->tgts,
581 sizeof(*newtgts) * lmv->tgts_size);
583 oldsize = lmv->tgts_size;
587 lmv->tgts_size = newsize;
590 OBD_FREE(old, sizeof(*old) * oldsize);
592 CDEBUG(D_CONFIG, "tgts: %p size: %d\n", lmv->tgts,
598 lmv_init_unlock(lmv);
602 mutex_init(&tgt->ltd_fid_mutex);
603 tgt->ltd_idx = index;
604 tgt->ltd_uuid = *uuidp;
606 lmv->tgts[index] = tgt;
607 if (index >= lmv->desc.ld_tgt_count)
608 lmv->desc.ld_tgt_count = index + 1;
610 if (lmv->connected) {
611 rc = lmv_connect_mdc(obd, tgt);
613 spin_lock(&lmv->lmv_lock);
614 lmv->desc.ld_tgt_count--;
615 memset(tgt, 0, sizeof(*tgt));
616 spin_unlock(&lmv->lmv_lock);
618 int easize = sizeof(struct lmv_stripe_md) +
619 lmv->desc.ld_tgt_count *
620 sizeof(struct lu_fid);
621 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0);
625 lmv_init_unlock(lmv);
629 int lmv_check_connect(struct obd_device *obd)
631 struct lmv_obd *lmv = &obd->u.lmv;
632 struct lmv_tgt_desc *tgt;
642 if (lmv->connected) {
643 lmv_init_unlock(lmv);
647 if (lmv->desc.ld_tgt_count == 0) {
648 lmv_init_unlock(lmv);
649 CERROR("%s: no targets configured.\n", obd->obd_name);
653 LASSERT(lmv->tgts != NULL);
655 if (lmv->tgts[0] == NULL) {
656 lmv_init_unlock(lmv);
657 CERROR("%s: no target configured for index 0.\n",
662 CDEBUG(D_CONFIG, "Time to connect %s to %s\n",
663 lmv->cluuid.uuid, obd->obd_name);
665 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
669 rc = lmv_connect_mdc(obd, tgt);
674 lmv_set_timeouts(obd);
675 class_export_put(lmv->exp);
677 easize = lmv_mds_md_size(lmv->desc.ld_tgt_count, LMV_MAGIC);
678 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0);
679 lmv_init_unlock(lmv);
690 --lmv->desc.ld_active_tgt_count;
691 rc2 = obd_disconnect(tgt->ltd_exp);
693 CERROR("LMV target %s disconnect on "
694 "MDC idx %d: error %d\n",
695 tgt->ltd_uuid.uuid, i, rc2);
699 class_disconnect(lmv->exp);
700 lmv_init_unlock(lmv);
704 static int lmv_disconnect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
707 struct proc_dir_entry *lmv_proc_dir;
709 struct lmv_obd *lmv = &obd->u.lmv;
710 struct obd_device *mdc_obd;
714 LASSERT(tgt != NULL);
715 LASSERT(obd != NULL);
717 mdc_obd = class_exp2obd(tgt->ltd_exp);
720 mdc_obd->obd_force = obd->obd_force;
721 mdc_obd->obd_fail = obd->obd_fail;
722 mdc_obd->obd_no_recov = obd->obd_no_recov;
726 lmv_proc_dir = obd->obd_proc_private;
728 lprocfs_remove_proc_entry(mdc_obd->obd_name, lmv_proc_dir);
730 rc = obd_fid_fini(tgt->ltd_exp->exp_obd);
732 CERROR("Can't finanize fids factory\n");
734 CDEBUG(D_INFO, "Disconnected from %s(%s) successfully\n",
735 tgt->ltd_exp->exp_obd->obd_name,
736 tgt->ltd_exp->exp_obd->obd_uuid.uuid);
738 obd_register_observer(tgt->ltd_exp->exp_obd, NULL);
739 rc = obd_disconnect(tgt->ltd_exp);
741 if (tgt->ltd_active) {
742 CERROR("Target %s disconnect error %d\n",
743 tgt->ltd_uuid.uuid, rc);
747 lmv_activate_target(lmv, tgt, 0);
752 static int lmv_disconnect(struct obd_export *exp)
754 struct obd_device *obd = class_exp2obd(exp);
755 struct lmv_obd *lmv = &obd->u.lmv;
764 * Only disconnect the underlying layers on the final disconnect.
767 if (lmv->refcount != 0)
770 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
771 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
774 lmv_disconnect_mdc(obd, lmv->tgts[i]);
778 if (obd->obd_proc_private)
779 lprocfs_remove((struct proc_dir_entry **)&obd->obd_proc_private);
781 CERROR("/proc/fs/lustre/%s/%s/target_obds missing\n",
782 obd->obd_type->typ_name, obd->obd_name);
787 * This is the case when no real connection is established by
788 * lmv_check_connect().
791 class_export_put(exp);
792 rc = class_disconnect(exp);
793 if (lmv->refcount == 0)
798 static int lmv_fid2path(struct obd_export *exp, int len, void *karg, void *uarg)
800 struct obd_device *obddev = class_exp2obd(exp);
801 struct lmv_obd *lmv = &obddev->u.lmv;
802 struct getinfo_fid2path *gf;
803 struct lmv_tgt_desc *tgt;
804 struct getinfo_fid2path *remote_gf = NULL;
805 int remote_gf_size = 0;
808 gf = (struct getinfo_fid2path *)karg;
809 tgt = lmv_find_target(lmv, &gf->gf_fid);
811 RETURN(PTR_ERR(tgt));
814 rc = obd_iocontrol(OBD_IOC_FID2PATH, tgt->ltd_exp, len, gf, uarg);
815 if (rc != 0 && rc != -EREMOTE)
816 GOTO(out_fid2path, rc);
818 /* If remote_gf != NULL, it means just building the
819 * path on the remote MDT, copy this path segement to gf */
820 if (remote_gf != NULL) {
821 struct getinfo_fid2path *ori_gf;
824 ori_gf = (struct getinfo_fid2path *)karg;
825 if (strlen(ori_gf->gf_path) +
826 strlen(gf->gf_path) > ori_gf->gf_pathlen)
827 GOTO(out_fid2path, rc = -EOVERFLOW);
829 ptr = ori_gf->gf_path;
831 memmove(ptr + strlen(gf->gf_path) + 1, ptr,
832 strlen(ori_gf->gf_path));
834 strncpy(ptr, gf->gf_path, strlen(gf->gf_path));
835 ptr += strlen(gf->gf_path);
839 CDEBUG(D_INFO, "%s: get path %s "DFID" rec: "LPU64" ln: %u\n",
840 tgt->ltd_exp->exp_obd->obd_name,
841 gf->gf_path, PFID(&gf->gf_fid), gf->gf_recno,
845 GOTO(out_fid2path, rc);
847 /* sigh, has to go to another MDT to do path building further */
848 if (remote_gf == NULL) {
849 remote_gf_size = sizeof(*remote_gf) + PATH_MAX;
850 OBD_ALLOC(remote_gf, remote_gf_size);
851 if (remote_gf == NULL)
852 GOTO(out_fid2path, rc = -ENOMEM);
853 remote_gf->gf_pathlen = PATH_MAX;
856 if (!fid_is_sane(&gf->gf_fid)) {
857 CERROR("%s: invalid FID "DFID": rc = %d\n",
858 tgt->ltd_exp->exp_obd->obd_name,
859 PFID(&gf->gf_fid), -EINVAL);
860 GOTO(out_fid2path, rc = -EINVAL);
863 tgt = lmv_find_target(lmv, &gf->gf_fid);
865 GOTO(out_fid2path, rc = -EINVAL);
867 remote_gf->gf_fid = gf->gf_fid;
868 remote_gf->gf_recno = -1;
869 remote_gf->gf_linkno = -1;
870 memset(remote_gf->gf_path, 0, remote_gf->gf_pathlen);
872 goto repeat_fid2path;
875 if (remote_gf != NULL)
876 OBD_FREE(remote_gf, remote_gf_size);
880 static int lmv_hsm_req_count(struct lmv_obd *lmv,
881 const struct hsm_user_request *hur,
882 const struct lmv_tgt_desc *tgt_mds)
886 struct lmv_tgt_desc *curr_tgt;
888 /* count how many requests must be sent to the given target */
889 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
890 curr_tgt = lmv_find_target(lmv, &hur->hur_user_item[i].hui_fid);
891 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid))
897 static void lmv_hsm_req_build(struct lmv_obd *lmv,
898 struct hsm_user_request *hur_in,
899 const struct lmv_tgt_desc *tgt_mds,
900 struct hsm_user_request *hur_out)
903 struct lmv_tgt_desc *curr_tgt;
905 /* build the hsm_user_request for the given target */
906 hur_out->hur_request = hur_in->hur_request;
908 for (i = 0; i < hur_in->hur_request.hr_itemcount; i++) {
909 curr_tgt = lmv_find_target(lmv,
910 &hur_in->hur_user_item[i].hui_fid);
911 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid)) {
912 hur_out->hur_user_item[nr_out] =
913 hur_in->hur_user_item[i];
917 hur_out->hur_request.hr_itemcount = nr_out;
918 memcpy(hur_data(hur_out), hur_data(hur_in),
919 hur_in->hur_request.hr_data_len);
922 static int lmv_hsm_ct_unregister(struct lmv_obd *lmv, unsigned int cmd, int len,
923 struct lustre_kernelcomm *lk, void *uarg)
927 struct kkuc_ct_data *kcd = NULL;
930 /* unregister request (call from llapi_hsm_copytool_fini) */
931 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
932 struct lmv_tgt_desc *tgt = lmv->tgts[i];
934 if (tgt == NULL || tgt->ltd_exp == NULL)
936 /* best effort: try to clean as much as possible
937 * (continue on error) */
938 obd_iocontrol(cmd, tgt->ltd_exp, len, lk, uarg);
941 /* Whatever the result, remove copytool from kuc groups.
942 * Unreached coordinators will get EPIPE on next requests
943 * and will unregister automatically.
945 rc = libcfs_kkuc_group_rem(lk->lk_uid, lk->lk_group, (void **)&kcd);
952 static int lmv_hsm_ct_register(struct lmv_obd *lmv, unsigned int cmd, int len,
953 struct lustre_kernelcomm *lk, void *uarg)
958 bool any_set = false;
959 struct kkuc_ct_data *kcd;
962 /* All or nothing: try to register to all MDS.
963 * In case of failure, unregister from previous MDS,
964 * except if it because of inactive target. */
965 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
966 struct lmv_tgt_desc *tgt = lmv->tgts[i];
968 if (tgt == NULL || tgt->ltd_exp == NULL)
970 err = obd_iocontrol(cmd, tgt->ltd_exp, len, lk, uarg);
972 if (tgt->ltd_active) {
973 /* permanent error */
974 CERROR("%s: iocontrol MDC %s on MDT"
975 " idx %d cmd %x: err = %d\n",
976 class_exp2obd(lmv->exp)->obd_name,
977 tgt->ltd_uuid.uuid, i, cmd, err);
979 lk->lk_flags |= LK_FLG_STOP;
980 /* unregister from previous MDS */
981 for (j = 0; j < i; j++) {
983 if (tgt == NULL || tgt->ltd_exp == NULL)
985 obd_iocontrol(cmd, tgt->ltd_exp, len,
990 /* else: transient error.
991 * kuc will register to the missing MDT
999 /* no registration done: return error */
1002 /* at least one registration done, with no failure */
1003 filp = fget(lk->lk_wfd);
1012 kcd->kcd_magic = KKUC_CT_DATA_MAGIC;
1013 kcd->kcd_uuid = lmv->cluuid;
1014 kcd->kcd_archive = lk->lk_data;
1016 rc = libcfs_kkuc_group_add(filp, lk->lk_uid, lk->lk_group, kcd);
1029 static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
1030 int len, void *karg, void *uarg)
1032 struct obd_device *obddev = class_exp2obd(exp);
1033 struct lmv_obd *lmv = &obddev->u.lmv;
1034 struct lmv_tgt_desc *tgt = NULL;
1038 __u32 count = lmv->desc.ld_tgt_count;
1045 case IOC_OBD_STATFS: {
1046 struct obd_ioctl_data *data = karg;
1047 struct obd_device *mdc_obd;
1048 struct obd_statfs stat_buf = {0};
1051 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
1052 if ((index >= count))
1055 tgt = lmv->tgts[index];
1056 if (tgt == NULL || !tgt->ltd_active)
1059 mdc_obd = class_exp2obd(tgt->ltd_exp);
1064 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(mdc_obd),
1065 min((int) data->ioc_plen2,
1066 (int) sizeof(struct obd_uuid))))
1069 rc = obd_statfs(NULL, tgt->ltd_exp, &stat_buf,
1070 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1074 if (copy_to_user(data->ioc_pbuf1, &stat_buf,
1075 min((int) data->ioc_plen1,
1076 (int) sizeof(stat_buf))))
1080 case OBD_IOC_QUOTACTL: {
1081 struct if_quotactl *qctl = karg;
1082 struct obd_quotactl *oqctl;
1084 if (qctl->qc_valid == QC_MDTIDX) {
1085 if (count <= qctl->qc_idx)
1088 tgt = lmv->tgts[qctl->qc_idx];
1089 if (tgt == NULL || tgt->ltd_exp == NULL)
1091 } else if (qctl->qc_valid == QC_UUID) {
1092 for (i = 0; i < count; i++) {
1096 if (!obd_uuid_equals(&tgt->ltd_uuid,
1100 if (tgt->ltd_exp == NULL)
1112 LASSERT(tgt != NULL && tgt->ltd_exp != NULL);
1113 OBD_ALLOC_PTR(oqctl);
1117 QCTL_COPY(oqctl, qctl);
1118 rc = obd_quotactl(tgt->ltd_exp, oqctl);
1120 QCTL_COPY(qctl, oqctl);
1121 qctl->qc_valid = QC_MDTIDX;
1122 qctl->obd_uuid = tgt->ltd_uuid;
1124 OBD_FREE_PTR(oqctl);
1127 case OBD_IOC_CHANGELOG_SEND:
1128 case OBD_IOC_CHANGELOG_CLEAR: {
1129 struct ioc_changelog *icc = karg;
1131 if (icc->icc_mdtindex >= count)
1134 tgt = lmv->tgts[icc->icc_mdtindex];
1135 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
1137 rc = obd_iocontrol(cmd, tgt->ltd_exp, sizeof(*icc), icc, NULL);
1140 case LL_IOC_GET_CONNECT_FLAGS: {
1142 if (tgt == NULL || tgt->ltd_exp == NULL)
1144 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1147 case OBD_IOC_FID2PATH: {
1148 rc = lmv_fid2path(exp, len, karg, uarg);
1151 case LL_IOC_HSM_STATE_GET:
1152 case LL_IOC_HSM_STATE_SET:
1153 case LL_IOC_HSM_ACTION: {
1154 struct md_op_data *op_data = karg;
1156 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1158 RETURN(PTR_ERR(tgt));
1160 if (tgt->ltd_exp == NULL)
1163 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1166 case LL_IOC_HSM_PROGRESS: {
1167 const struct hsm_progress_kernel *hpk = karg;
1169 tgt = lmv_find_target(lmv, &hpk->hpk_fid);
1171 RETURN(PTR_ERR(tgt));
1172 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1175 case LL_IOC_HSM_REQUEST: {
1176 struct hsm_user_request *hur = karg;
1177 unsigned int reqcount = hur->hur_request.hr_itemcount;
1182 /* if the request is about a single fid
1183 * or if there is a single MDS, no need to split
1185 if (reqcount == 1 || count == 1) {
1186 tgt = lmv_find_target(lmv,
1187 &hur->hur_user_item[0].hui_fid);
1189 RETURN(PTR_ERR(tgt));
1190 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1192 /* split fid list to their respective MDS */
1193 for (i = 0; i < count; i++) {
1194 unsigned int nr, reqlen;
1196 struct hsm_user_request *req;
1199 if (tgt == NULL || tgt->ltd_exp == NULL)
1202 nr = lmv_hsm_req_count(lmv, hur, tgt);
1203 if (nr == 0) /* nothing for this MDS */
1206 /* build a request with fids for this MDS */
1207 reqlen = offsetof(typeof(*hur),
1209 + hur->hur_request.hr_data_len;
1210 OBD_ALLOC_LARGE(req, reqlen);
1214 lmv_hsm_req_build(lmv, hur, tgt, req);
1216 rc1 = obd_iocontrol(cmd, tgt->ltd_exp, reqlen,
1218 if (rc1 != 0 && rc == 0)
1220 OBD_FREE_LARGE(req, reqlen);
1225 case LL_IOC_LOV_SWAP_LAYOUTS: {
1226 struct md_op_data *op_data = karg;
1227 struct lmv_tgt_desc *tgt1, *tgt2;
1229 tgt1 = lmv_find_target(lmv, &op_data->op_fid1);
1231 RETURN(PTR_ERR(tgt1));
1233 tgt2 = lmv_find_target(lmv, &op_data->op_fid2);
1235 RETURN(PTR_ERR(tgt2));
1237 if ((tgt1->ltd_exp == NULL) || (tgt2->ltd_exp == NULL))
1240 /* only files on same MDT can have their layouts swapped */
1241 if (tgt1->ltd_idx != tgt2->ltd_idx)
1244 rc = obd_iocontrol(cmd, tgt1->ltd_exp, len, karg, uarg);
1247 case LL_IOC_HSM_CT_START: {
1248 struct lustre_kernelcomm *lk = karg;
1249 if (lk->lk_flags & LK_FLG_STOP)
1250 rc = lmv_hsm_ct_unregister(lmv, cmd, len, lk, uarg);
1252 rc = lmv_hsm_ct_register(lmv, cmd, len, lk, uarg);
1256 for (i = 0; i < count; i++) {
1257 struct obd_device *mdc_obd;
1261 if (tgt == NULL || tgt->ltd_exp == NULL)
1263 /* ll_umount_begin() sets force flag but for lmv, not
1264 * mdc. Let's pass it through */
1265 mdc_obd = class_exp2obd(tgt->ltd_exp);
1266 mdc_obd->obd_force = obddev->obd_force;
1267 err = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1268 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
1271 if (tgt->ltd_active) {
1272 CERROR("error: iocontrol MDC %s on MDT"
1273 " idx %d cmd %x: err = %d\n",
1274 tgt->ltd_uuid.uuid, i, cmd, err);
1288 static int lmv_all_chars_policy(int count, const char *name,
1299 static int lmv_nid_policy(struct lmv_obd *lmv)
1301 struct obd_import *imp;
1305 * XXX: To get nid we assume that underlying obd device is mdc.
1307 imp = class_exp2cliimp(lmv->tgts[0].ltd_exp);
1308 id = imp->imp_connection->c_self ^ (imp->imp_connection->c_self >> 32);
1309 return id % lmv->desc.ld_tgt_count;
1312 static int lmv_choose_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1313 placement_policy_t placement)
1315 switch (placement) {
1316 case PLACEMENT_CHAR_POLICY:
1317 return lmv_all_chars_policy(lmv->desc.ld_tgt_count,
1319 op_data->op_namelen);
1320 case PLACEMENT_NID_POLICY:
1321 return lmv_nid_policy(lmv);
1327 CERROR("Unsupported placement policy %x\n", placement);
1333 * This is _inode_ placement policy function (not name).
1335 static int lmv_placement_policy(struct obd_device *obd,
1336 struct md_op_data *op_data,
1339 struct lmv_obd *lmv = &obd->u.lmv;
1342 LASSERT(mds != NULL);
1344 if (lmv->desc.ld_tgt_count == 1) {
1350 * If stripe_offset is provided during setdirstripe
1351 * (setdirstripe -i xx), xx MDS will be choosen.
1353 if (op_data->op_cli_flags & CLI_SET_MEA && op_data->op_data != NULL) {
1354 struct lmv_user_md *lum;
1356 lum = op_data->op_data;
1358 if (lum->lum_stripe_offset != (__u32)-1) {
1359 *mds = lum->lum_stripe_offset;
1361 /* -1 means default, which will be in the same MDT with
1363 *mds = op_data->op_mds;
1364 lum->lum_stripe_offset = op_data->op_mds;
1367 /* Allocate new fid on target according to operation type and
1368 * parent home mds. */
1369 *mds = op_data->op_mds;
1375 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid,
1378 struct lmv_tgt_desc *tgt;
1382 tgt = lmv_get_target(lmv, mds);
1384 RETURN(PTR_ERR(tgt));
1387 * New seq alloc and FLD setup should be atomic. Otherwise we may find
1388 * on server that seq in new allocated fid is not yet known.
1390 mutex_lock(&tgt->ltd_fid_mutex);
1392 if (tgt->ltd_active == 0 || tgt->ltd_exp == NULL)
1393 GOTO(out, rc = -ENODEV);
1396 * Asking underlaying tgt layer to allocate new fid.
1398 rc = obd_fid_alloc(tgt->ltd_exp, fid, NULL);
1400 LASSERT(fid_is_sane(fid));
1406 mutex_unlock(&tgt->ltd_fid_mutex);
1410 int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
1411 struct md_op_data *op_data)
1413 struct obd_device *obd = class_exp2obd(exp);
1414 struct lmv_obd *lmv = &obd->u.lmv;
1419 LASSERT(op_data != NULL);
1420 LASSERT(fid != NULL);
1422 rc = lmv_placement_policy(obd, op_data, &mds);
1424 CERROR("Can't get target for allocating fid, "
1429 rc = __lmv_fid_alloc(lmv, fid, mds);
1431 CERROR("Can't alloc new fid, rc %d\n", rc);
1438 static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
1440 struct lmv_obd *lmv = &obd->u.lmv;
1441 struct lmv_desc *desc;
1445 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
1446 CERROR("LMV setup requires a descriptor\n");
1450 desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1);
1451 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
1452 CERROR("Lmv descriptor size wrong: %d > %d\n",
1453 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
1457 OBD_ALLOC(lmv->tgts, sizeof(*lmv->tgts) * 32);
1458 if (lmv->tgts == NULL)
1460 lmv->tgts_size = 32;
1462 obd_str2uuid(&lmv->desc.ld_uuid, desc->ld_uuid.uuid);
1463 lmv->desc.ld_tgt_count = 0;
1464 lmv->desc.ld_active_tgt_count = 0;
1465 lmv->max_cookiesize = 0;
1466 lmv->max_def_easize = 0;
1467 lmv->max_easize = 0;
1468 lmv->lmv_placement = PLACEMENT_CHAR_POLICY;
1470 spin_lock_init(&lmv->lmv_lock);
1471 mutex_init(&lmv->init_mutex);
1474 obd->obd_vars = lprocfs_lmv_obd_vars;
1475 lprocfs_seq_obd_setup(obd);
1476 lprocfs_alloc_md_stats(obd, 0);
1477 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
1478 0444, &lmv_proc_target_fops, obd);
1480 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
1483 rc = fld_client_init(&lmv->lmv_fld, obd->obd_name,
1484 LUSTRE_CLI_FLD_HASH_DHT);
1486 CERROR("Can't init FLD, err %d\n", rc);
1496 static int lmv_cleanup(struct obd_device *obd)
1498 struct lmv_obd *lmv = &obd->u.lmv;
1501 fld_client_fini(&lmv->lmv_fld);
1502 if (lmv->tgts != NULL) {
1504 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1505 if (lmv->tgts[i] == NULL)
1507 lmv_del_target(lmv, i);
1509 OBD_FREE(lmv->tgts, sizeof(*lmv->tgts) * lmv->tgts_size);
1515 static int lmv_process_config(struct obd_device *obd, obd_count len, void *buf)
1517 struct lustre_cfg *lcfg = buf;
1518 struct obd_uuid obd_uuid;
1524 switch (lcfg->lcfg_command) {
1526 /* modify_mdc_tgts add 0:lustre-clilmv 1:lustre-MDT0000_UUID
1527 * 2:0 3:1 4:lustre-MDT0000-mdc_UUID */
1528 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
1529 GOTO(out, rc = -EINVAL);
1531 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
1533 if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", &index) != 1)
1534 GOTO(out, rc = -EINVAL);
1535 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
1536 GOTO(out, rc = -EINVAL);
1537 rc = lmv_add_target(obd, &obd_uuid, index, gen);
1540 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1541 GOTO(out, rc = -EINVAL);
1547 static int lmv_statfs(const struct lu_env *env, struct obd_export *exp,
1548 struct obd_statfs *osfs, __u64 max_age, __u32 flags)
1550 struct obd_device *obd = class_exp2obd(exp);
1551 struct lmv_obd *lmv = &obd->u.lmv;
1552 struct obd_statfs *temp;
1557 rc = lmv_check_connect(obd);
1561 OBD_ALLOC(temp, sizeof(*temp));
1565 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1566 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1569 rc = obd_statfs(env, lmv->tgts[i]->ltd_exp, temp,
1572 CERROR("can't stat MDS #%d (%s), error %d\n", i,
1573 lmv->tgts[i]->ltd_exp->exp_obd->obd_name,
1575 GOTO(out_free_temp, rc);
1580 /* If the statfs is from mount, it will needs
1581 * retrieve necessary information from MDT0.
1582 * i.e. mount does not need the merged osfs
1584 * And also clients can be mounted as long as
1585 * MDT0 is in service*/
1586 if (flags & OBD_STATFS_FOR_MDT0)
1587 GOTO(out_free_temp, rc);
1589 osfs->os_bavail += temp->os_bavail;
1590 osfs->os_blocks += temp->os_blocks;
1591 osfs->os_ffree += temp->os_ffree;
1592 osfs->os_files += temp->os_files;
1598 OBD_FREE(temp, sizeof(*temp));
1602 static int lmv_getstatus(struct obd_export *exp,
1604 struct obd_capa **pc)
1606 struct obd_device *obd = exp->exp_obd;
1607 struct lmv_obd *lmv = &obd->u.lmv;
1611 rc = lmv_check_connect(obd);
1615 rc = md_getstatus(lmv->tgts[0]->ltd_exp, fid, pc);
1619 static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1620 struct obd_capa *oc, obd_valid valid, const char *name,
1621 const char *input, int input_size, int output_size,
1622 int flags, struct ptlrpc_request **request)
1624 struct obd_device *obd = exp->exp_obd;
1625 struct lmv_obd *lmv = &obd->u.lmv;
1626 struct lmv_tgt_desc *tgt;
1630 rc = lmv_check_connect(obd);
1634 tgt = lmv_find_target(lmv, fid);
1636 RETURN(PTR_ERR(tgt));
1638 rc = md_getxattr(tgt->ltd_exp, fid, oc, valid, name, input,
1639 input_size, output_size, flags, request);
1644 static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1645 struct obd_capa *oc, obd_valid valid, const char *name,
1646 const char *input, int input_size, int output_size,
1647 int flags, __u32 suppgid,
1648 struct ptlrpc_request **request)
1650 struct obd_device *obd = exp->exp_obd;
1651 struct lmv_obd *lmv = &obd->u.lmv;
1652 struct lmv_tgt_desc *tgt;
1656 rc = lmv_check_connect(obd);
1660 tgt = lmv_find_target(lmv, fid);
1662 RETURN(PTR_ERR(tgt));
1664 rc = md_setxattr(tgt->ltd_exp, fid, oc, valid, name, input,
1665 input_size, output_size, flags, suppgid,
1671 static int lmv_getattr(struct obd_export *exp, struct md_op_data *op_data,
1672 struct ptlrpc_request **request)
1674 struct obd_device *obd = exp->exp_obd;
1675 struct lmv_obd *lmv = &obd->u.lmv;
1676 struct lmv_tgt_desc *tgt;
1680 rc = lmv_check_connect(obd);
1684 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1686 RETURN(PTR_ERR(tgt));
1688 if (op_data->op_flags & MF_GET_MDT_IDX) {
1689 op_data->op_mds = tgt->ltd_idx;
1693 rc = md_getattr(tgt->ltd_exp, op_data, request);
1698 static int lmv_null_inode(struct obd_export *exp, const struct lu_fid *fid)
1700 struct obd_device *obd = exp->exp_obd;
1701 struct lmv_obd *lmv = &obd->u.lmv;
1706 rc = lmv_check_connect(obd);
1710 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1713 * With DNE every object can have two locks in different namespaces:
1714 * lookup lock in space of MDT storing direntry and update/open lock in
1715 * space of MDT storing inode.
1717 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1718 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1720 md_null_inode(lmv->tgts[i]->ltd_exp, fid);
1726 static int lmv_find_cbdata(struct obd_export *exp, const struct lu_fid *fid,
1727 ldlm_iterator_t it, void *data)
1729 struct obd_device *obd = exp->exp_obd;
1730 struct lmv_obd *lmv = &obd->u.lmv;
1735 rc = lmv_check_connect(obd);
1739 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1742 * With DNE every object can have two locks in different namespaces:
1743 * lookup lock in space of MDT storing direntry and update/open lock in
1744 * space of MDT storing inode.
1746 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1747 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1749 rc = md_find_cbdata(lmv->tgts[i]->ltd_exp, fid, it, data);
1758 static int lmv_close(struct obd_export *exp, struct md_op_data *op_data,
1759 struct md_open_data *mod, struct ptlrpc_request **request)
1761 struct obd_device *obd = exp->exp_obd;
1762 struct lmv_obd *lmv = &obd->u.lmv;
1763 struct lmv_tgt_desc *tgt;
1767 rc = lmv_check_connect(obd);
1771 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1773 RETURN(PTR_ERR(tgt));
1775 CDEBUG(D_INODE, "CLOSE "DFID"\n", PFID(&op_data->op_fid1));
1776 rc = md_close(tgt->ltd_exp, op_data, mod, request);
1781 * Choosing the MDT by name or FID in @op_data.
1782 * For non-striped directory, it will locate MDT by fid.
1783 * For striped-directory, it will locate MDT by name. And also
1784 * it will reset op_fid1 with the FID of the choosen stripe.
1786 struct lmv_tgt_desc *
1787 lmv_locate_target_for_name(struct lmv_obd *lmv, struct lmv_stripe_md *lsm,
1788 const char *name, int namelen, struct lu_fid *fid,
1791 struct lmv_tgt_desc *tgt;
1792 const struct lmv_oinfo *oinfo;
1794 oinfo = lsm_name_to_stripe_info(lsm, name, namelen);
1796 RETURN((void *)oinfo);
1797 *fid = oinfo->lmo_fid;
1798 *mds = oinfo->lmo_mds;
1799 tgt = lmv_get_target(lmv, *mds);
1801 CDEBUG(D_INFO, "locate on mds %u "DFID"\n", *mds, PFID(fid));
1806 *lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1809 struct lmv_stripe_md *lsm = op_data->op_mea1;
1810 struct lmv_tgt_desc *tgt;
1812 if (lsm == NULL || lsm->lsm_md_stripe_count <= 1 ||
1813 op_data->op_namelen == 0 ||
1814 lsm->lsm_md_magic == LMV_MAGIC_MIGRATE) {
1815 tgt = lmv_find_target(lmv, fid);
1819 op_data->op_mds = tgt->ltd_idx;
1823 return lmv_locate_target_for_name(lmv, lsm, op_data->op_name,
1824 op_data->op_namelen, fid,
1828 int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
1829 const void *data, int datalen, int mode, __u32 uid,
1830 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1831 struct ptlrpc_request **request)
1833 struct obd_device *obd = exp->exp_obd;
1834 struct lmv_obd *lmv = &obd->u.lmv;
1835 struct lmv_tgt_desc *tgt;
1839 rc = lmv_check_connect(obd);
1843 if (!lmv->desc.ld_active_tgt_count)
1846 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1848 RETURN(PTR_ERR(tgt));
1850 CDEBUG(D_INODE, "CREATE name '%.*s' on "DFID" -> mds #%x\n",
1851 op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1),
1854 rc = lmv_fid_alloc(exp, &op_data->op_fid2, op_data);
1858 /* Send the create request to the MDT where the object
1859 * will be located */
1860 tgt = lmv_find_target(lmv, &op_data->op_fid2);
1862 RETURN(PTR_ERR(tgt));
1864 op_data->op_mds = tgt->ltd_idx;
1866 CDEBUG(D_INODE, "CREATE obj "DFID" -> mds #%x\n",
1867 PFID(&op_data->op_fid2), op_data->op_mds);
1869 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1870 rc = md_create(tgt->ltd_exp, op_data, data, datalen, mode, uid, gid,
1871 cap_effective, rdev, request);
1873 if (*request == NULL)
1875 CDEBUG(D_INODE, "Created - "DFID"\n", PFID(&op_data->op_fid2));
1880 static int lmv_done_writing(struct obd_export *exp,
1881 struct md_op_data *op_data,
1882 struct md_open_data *mod)
1884 struct obd_device *obd = exp->exp_obd;
1885 struct lmv_obd *lmv = &obd->u.lmv;
1886 struct lmv_tgt_desc *tgt;
1890 rc = lmv_check_connect(obd);
1894 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1896 RETURN(PTR_ERR(tgt));
1898 rc = md_done_writing(tgt->ltd_exp, op_data, mod);
1903 lmv_enqueue_remote(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1904 struct lookup_intent *it, struct md_op_data *op_data,
1905 struct lustre_handle *lockh, void *lmm, int lmmsize,
1906 __u64 extra_lock_flags)
1908 struct ptlrpc_request *req = it->d.lustre.it_data;
1909 struct obd_device *obd = exp->exp_obd;
1910 struct lmv_obd *lmv = &obd->u.lmv;
1911 struct lustre_handle plock;
1912 struct lmv_tgt_desc *tgt;
1913 struct md_op_data *rdata;
1915 struct mdt_body *body;
1920 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1921 LASSERT(body != NULL);
1923 if (!(body->valid & OBD_MD_MDS))
1926 CDEBUG(D_INODE, "REMOTE_ENQUEUE '%s' on "DFID" -> "DFID"\n",
1927 LL_IT2STR(it), PFID(&op_data->op_fid1), PFID(&body->fid1));
1930 * We got LOOKUP lock, but we really need attrs.
1932 pmode = it->d.lustre.it_lock_mode;
1933 LASSERT(pmode != 0);
1934 memcpy(&plock, lockh, sizeof(plock));
1935 it->d.lustre.it_lock_mode = 0;
1936 it->d.lustre.it_data = NULL;
1939 ptlrpc_req_finished(req);
1941 tgt = lmv_find_target(lmv, &fid1);
1943 GOTO(out, rc = PTR_ERR(tgt));
1945 OBD_ALLOC_PTR(rdata);
1947 GOTO(out, rc = -ENOMEM);
1949 rdata->op_fid1 = fid1;
1950 rdata->op_bias = MDS_CROSS_REF;
1952 rc = md_enqueue(tgt->ltd_exp, einfo, it, rdata, lockh,
1953 lmm, lmmsize, NULL, extra_lock_flags);
1954 OBD_FREE_PTR(rdata);
1957 ldlm_lock_decref(&plock, pmode);
1962 lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1963 struct lookup_intent *it, struct md_op_data *op_data,
1964 struct lustre_handle *lockh, void *lmm, int lmmsize,
1965 struct ptlrpc_request **req, __u64 extra_lock_flags)
1967 struct obd_device *obd = exp->exp_obd;
1968 struct lmv_obd *lmv = &obd->u.lmv;
1969 struct lmv_tgt_desc *tgt;
1973 rc = lmv_check_connect(obd);
1977 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID"\n",
1978 LL_IT2STR(it), PFID(&op_data->op_fid1));
1980 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1982 RETURN(PTR_ERR(tgt));
1984 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID" -> mds #%d\n",
1985 LL_IT2STR(it), PFID(&op_data->op_fid1), tgt->ltd_idx);
1987 rc = md_enqueue(tgt->ltd_exp, einfo, it, op_data, lockh,
1988 lmm, lmmsize, req, extra_lock_flags);
1990 if (rc == 0 && it && it->it_op == IT_OPEN) {
1991 rc = lmv_enqueue_remote(exp, einfo, it, op_data, lockh,
1992 lmm, lmmsize, extra_lock_flags);
1998 lmv_getattr_name(struct obd_export *exp,struct md_op_data *op_data,
1999 struct ptlrpc_request **request)
2001 struct ptlrpc_request *req = NULL;
2002 struct obd_device *obd = exp->exp_obd;
2003 struct lmv_obd *lmv = &obd->u.lmv;
2004 struct lmv_tgt_desc *tgt;
2005 struct mdt_body *body;
2009 rc = lmv_check_connect(obd);
2013 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
2015 RETURN(PTR_ERR(tgt));
2017 CDEBUG(D_INODE, "GETATTR_NAME for %*s on "DFID" -> mds #%d\n",
2018 op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1),
2021 rc = md_getattr_name(tgt->ltd_exp, op_data, request);
2025 body = req_capsule_server_get(&(*request)->rq_pill,
2027 LASSERT(body != NULL);
2029 if (body->valid & OBD_MD_MDS) {
2030 struct lu_fid rid = body->fid1;
2031 CDEBUG(D_INODE, "Request attrs for "DFID"\n",
2034 tgt = lmv_find_target(lmv, &rid);
2036 ptlrpc_req_finished(*request);
2037 RETURN(PTR_ERR(tgt));
2040 op_data->op_fid1 = rid;
2041 op_data->op_valid |= OBD_MD_FLCROSSREF;
2042 op_data->op_namelen = 0;
2043 op_data->op_name = NULL;
2044 rc = md_getattr_name(tgt->ltd_exp, op_data, &req);
2045 ptlrpc_req_finished(*request);
2052 #define md_op_data_fid(op_data, fl) \
2053 (fl == MF_MDC_CANCEL_FID1 ? &op_data->op_fid1 : \
2054 fl == MF_MDC_CANCEL_FID2 ? &op_data->op_fid2 : \
2055 fl == MF_MDC_CANCEL_FID3 ? &op_data->op_fid3 : \
2056 fl == MF_MDC_CANCEL_FID4 ? &op_data->op_fid4 : \
2059 static int lmv_early_cancel(struct obd_export *exp, struct lmv_tgt_desc *tgt,
2060 struct md_op_data *op_data,
2061 int op_tgt, ldlm_mode_t mode, int bits, int flag)
2063 struct lu_fid *fid = md_op_data_fid(op_data, flag);
2064 struct obd_device *obd = exp->exp_obd;
2065 struct lmv_obd *lmv = &obd->u.lmv;
2066 ldlm_policy_data_t policy = {{ 0 }};
2070 if (!fid_is_sane(fid))
2074 tgt = lmv_find_target(lmv, fid);
2076 RETURN(PTR_ERR(tgt));
2079 if (tgt->ltd_idx != op_tgt) {
2080 CDEBUG(D_INODE, "EARLY_CANCEL on "DFID"\n", PFID(fid));
2081 policy.l_inodebits.bits = bits;
2082 rc = md_cancel_unused(tgt->ltd_exp, fid, &policy,
2083 mode, LCF_ASYNC, NULL);
2086 "EARLY_CANCEL skip operation target %d on "DFID"\n",
2088 op_data->op_flags |= flag;
2096 * llite passes fid of an target inode in op_data->op_fid1 and id of directory in
2099 static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
2100 struct ptlrpc_request **request)
2102 struct obd_device *obd = exp->exp_obd;
2103 struct lmv_obd *lmv = &obd->u.lmv;
2104 struct lmv_tgt_desc *tgt;
2108 rc = lmv_check_connect(obd);
2112 LASSERT(op_data->op_namelen != 0);
2114 CDEBUG(D_INODE, "LINK "DFID":%*s to "DFID"\n",
2115 PFID(&op_data->op_fid2), op_data->op_namelen,
2116 op_data->op_name, PFID(&op_data->op_fid1));
2118 op_data->op_fsuid = current_fsuid();
2119 op_data->op_fsgid = current_fsgid();
2120 op_data->op_cap = cfs_curproc_cap_pack();
2121 if (op_data->op_mea2 != NULL) {
2122 struct lmv_stripe_md *lsm = op_data->op_mea2;
2123 const struct lmv_oinfo *oinfo;
2125 oinfo = lsm_name_to_stripe_info(lsm, op_data->op_name,
2126 op_data->op_namelen);
2128 RETURN(PTR_ERR(oinfo));
2130 op_data->op_fid2 = oinfo->lmo_fid;
2133 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
2135 RETURN(PTR_ERR(tgt));
2138 * Cancel UPDATE lock on child (fid1).
2140 op_data->op_flags |= MF_MDC_CANCEL_FID2;
2141 rc = lmv_early_cancel(exp, NULL, op_data, tgt->ltd_idx, LCK_EX,
2142 MDS_INODELOCK_UPDATE, MF_MDC_CANCEL_FID1);
2146 rc = md_link(tgt->ltd_exp, op_data, request);
2151 static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
2152 const char *old, int oldlen, const char *new, int newlen,
2153 struct ptlrpc_request **request)
2155 struct obd_device *obd = exp->exp_obd;
2156 struct lmv_obd *lmv = &obd->u.lmv;
2157 struct lmv_tgt_desc *src_tgt;
2161 LASSERT(oldlen != 0);
2163 CDEBUG(D_INODE, "RENAME %.*s in "DFID":%d to %.*s in "DFID":%d\n",
2164 oldlen, old, PFID(&op_data->op_fid1),
2165 op_data->op_mea1 ? op_data->op_mea1->lsm_md_stripe_count : 0,
2166 newlen, new, PFID(&op_data->op_fid2),
2167 op_data->op_mea2 ? op_data->op_mea2->lsm_md_stripe_count : 0);
2169 rc = lmv_check_connect(obd);
2173 op_data->op_fsuid = current_fsuid();
2174 op_data->op_fsgid = current_fsgid();
2175 op_data->op_cap = cfs_curproc_cap_pack();
2176 if (op_data->op_cli_flags & CLI_MIGRATE) {
2177 LASSERTF(fid_is_sane(&op_data->op_fid3), "invalid FID "DFID"\n",
2178 PFID(&op_data->op_fid3));
2179 rc = lmv_fid_alloc(exp, &op_data->op_fid2, op_data);
2182 src_tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid3);
2184 if (op_data->op_mea1 != NULL) {
2185 struct lmv_stripe_md *lsm = op_data->op_mea1;
2187 src_tgt = lmv_locate_target_for_name(lmv, lsm, old,
2191 if (IS_ERR(src_tgt))
2192 RETURN(PTR_ERR(src_tgt));
2194 src_tgt = lmv_find_target(lmv, &op_data->op_fid1);
2195 if (IS_ERR(src_tgt))
2196 RETURN(PTR_ERR(src_tgt));
2198 op_data->op_mds = src_tgt->ltd_idx;
2201 if (op_data->op_mea2) {
2202 struct lmv_stripe_md *lsm = op_data->op_mea2;
2203 const struct lmv_oinfo *oinfo;
2205 oinfo = lsm_name_to_stripe_info(lsm, new, newlen);
2207 RETURN(PTR_ERR(oinfo));
2209 op_data->op_fid2 = oinfo->lmo_fid;
2212 if (IS_ERR(src_tgt))
2213 RETURN(PTR_ERR(src_tgt));
2216 * LOOKUP lock on src child (fid3) should also be cancelled for
2217 * src_tgt in mdc_rename.
2219 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2222 * Cancel UPDATE locks on tgt parent (fid2), tgt_tgt is its
2225 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
2226 LCK_EX, MDS_INODELOCK_UPDATE,
2227 MF_MDC_CANCEL_FID2);
2232 * Cancel LOOKUP locks on source child (fid3) for parent tgt_tgt.
2234 if (fid_is_sane(&op_data->op_fid3)) {
2235 struct lmv_tgt_desc *tgt;
2237 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2239 RETURN(PTR_ERR(tgt));
2241 /* Cancel LOOKUP lock on its parent */
2242 rc = lmv_early_cancel(exp, tgt, op_data, src_tgt->ltd_idx,
2243 LCK_EX, MDS_INODELOCK_LOOKUP,
2244 MF_MDC_CANCEL_FID3);
2248 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
2249 LCK_EX, MDS_INODELOCK_FULL,
2250 MF_MDC_CANCEL_FID3);
2256 * Cancel all the locks on tgt child (fid4).
2258 if (fid_is_sane(&op_data->op_fid4))
2259 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
2260 LCK_EX, MDS_INODELOCK_FULL,
2261 MF_MDC_CANCEL_FID4);
2263 CDEBUG(D_INODE, DFID":m%d to "DFID"\n", PFID(&op_data->op_fid1),
2264 op_data->op_mds, PFID(&op_data->op_fid2));
2266 rc = md_rename(src_tgt->ltd_exp, op_data, old, oldlen, new, newlen,
2272 static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
2273 void *ea, int ealen, void *ea2, int ea2len,
2274 struct ptlrpc_request **request,
2275 struct md_open_data **mod)
2277 struct obd_device *obd = exp->exp_obd;
2278 struct lmv_obd *lmv = &obd->u.lmv;
2279 struct lmv_tgt_desc *tgt;
2283 rc = lmv_check_connect(obd);
2287 CDEBUG(D_INODE, "SETATTR for "DFID", valid 0x%x\n",
2288 PFID(&op_data->op_fid1), op_data->op_attr.ia_valid);
2290 op_data->op_flags |= MF_MDC_CANCEL_FID1;
2291 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2293 RETURN(PTR_ERR(tgt));
2295 rc = md_setattr(tgt->ltd_exp, op_data, ea, ealen, ea2,
2296 ea2len, request, mod);
2301 static int lmv_fsync(struct obd_export *exp, const struct lu_fid *fid,
2302 struct obd_capa *oc, struct ptlrpc_request **request)
2304 struct obd_device *obd = exp->exp_obd;
2305 struct lmv_obd *lmv = &obd->u.lmv;
2306 struct lmv_tgt_desc *tgt;
2310 rc = lmv_check_connect(obd);
2314 tgt = lmv_find_target(lmv, fid);
2316 RETURN(PTR_ERR(tgt));
2318 rc = md_fsync(tgt->ltd_exp, fid, oc, request);
2323 * Adjust a set of pages, each page containing an array of lu_dirpages,
2324 * so that each page can be used as a single logical lu_dirpage.
2326 * A lu_dirpage is laid out as follows, where s = ldp_hash_start,
2327 * e = ldp_hash_end, f = ldp_flags, p = padding, and each "ent" is a
2328 * struct lu_dirent. It has size up to LU_PAGE_SIZE. The ldp_hash_end
2329 * value is used as a cookie to request the next lu_dirpage in a
2330 * directory listing that spans multiple pages (two in this example):
2333 * .|--------v------- -----.
2334 * |s|e|f|p|ent|ent| ... |ent|
2335 * '--|-------------- -----' Each CFS_PAGE contains a single
2336 * '------. lu_dirpage.
2337 * .---------v------- -----.
2338 * |s|e|f|p|ent| 0 | ... | 0 |
2339 * '----------------- -----'
2341 * However, on hosts where the native VM page size (PAGE_CACHE_SIZE) is
2342 * larger than LU_PAGE_SIZE, a single host page may contain multiple
2343 * lu_dirpages. After reading the lu_dirpages from the MDS, the
2344 * ldp_hash_end of the first lu_dirpage refers to the one immediately
2345 * after it in the same CFS_PAGE (arrows simplified for brevity, but
2346 * in general e0==s1, e1==s2, etc.):
2348 * .-------------------- -----.
2349 * |s0|e0|f0|p|ent|ent| ... |ent|
2350 * |---v---------------- -----|
2351 * |s1|e1|f1|p|ent|ent| ... |ent|
2352 * |---v---------------- -----| Here, each CFS_PAGE contains
2353 * ... multiple lu_dirpages.
2354 * |---v---------------- -----|
2355 * |s'|e'|f'|p|ent|ent| ... |ent|
2356 * '---|---------------- -----'
2358 * .----------------------------.
2361 * This structure is transformed into a single logical lu_dirpage as follows:
2363 * - Replace e0 with e' so the request for the next lu_dirpage gets the page
2364 * labeled 'next CFS_PAGE'.
2366 * - Copy the LDF_COLLIDE flag from f' to f0 to correctly reflect whether
2367 * a hash collision with the next page exists.
2369 * - Adjust the lde_reclen of the ending entry of each lu_dirpage to span
2370 * to the first entry of the next lu_dirpage.
2372 #if PAGE_CACHE_SIZE > LU_PAGE_SIZE
2373 static void lmv_adjust_dirpages(struct page **pages, int ncfspgs, int nlupgs)
2377 for (i = 0; i < ncfspgs; i++) {
2378 struct lu_dirpage *dp = kmap(pages[i]);
2379 struct lu_dirpage *first = dp;
2380 struct lu_dirent *end_dirent = NULL;
2381 struct lu_dirent *ent;
2382 __u64 hash_end = dp->ldp_hash_end;
2383 __u32 flags = dp->ldp_flags;
2385 while (--nlupgs > 0) {
2386 ent = lu_dirent_start(dp);
2387 for (end_dirent = ent; ent != NULL;
2388 end_dirent = ent, ent = lu_dirent_next(ent));
2390 /* Advance dp to next lu_dirpage. */
2391 dp = (struct lu_dirpage *)((char *)dp + LU_PAGE_SIZE);
2393 /* Check if we've reached the end of the CFS_PAGE. */
2394 if (!((unsigned long)dp & ~CFS_PAGE_MASK))
2397 /* Save the hash and flags of this lu_dirpage. */
2398 hash_end = dp->ldp_hash_end;
2399 flags = dp->ldp_flags;
2401 /* Check if lu_dirpage contains no entries. */
2405 /* Enlarge the end entry lde_reclen from 0 to
2406 * first entry of next lu_dirpage. */
2407 LASSERT(le16_to_cpu(end_dirent->lde_reclen) == 0);
2408 end_dirent->lde_reclen =
2409 cpu_to_le16((char *)(dp->ldp_entries) -
2410 (char *)end_dirent);
2413 first->ldp_hash_end = hash_end;
2414 first->ldp_flags &= ~cpu_to_le32(LDF_COLLIDE);
2415 first->ldp_flags |= flags & cpu_to_le32(LDF_COLLIDE);
2419 LASSERTF(nlupgs == 0, "left = %d", nlupgs);
2422 #define lmv_adjust_dirpages(pages, ncfspgs, nlupgs) do {} while (0)
2423 #endif /* PAGE_CACHE_SIZE > LU_PAGE_SIZE */
2425 #define NORMAL_MAX_STRIPES 4
2426 int lmv_read_entry(struct obd_export *exp, struct md_op_data *op_data,
2427 struct md_callback *cb_op, struct lu_dirent **ldp,
2428 struct page **ppage)
2430 struct obd_device *obd = exp->exp_obd;
2431 struct lmv_obd *lmv = &obd->u.lmv;
2432 struct lmv_stripe_md *lsm = op_data->op_mea1;
2433 struct lu_dirent *tmp_ents[NORMAL_MAX_STRIPES];
2434 struct lu_dirent **ents = NULL;
2438 struct page *min_page = NULL;
2443 rc = lmv_check_connect(obd);
2450 stripe_count = lsm->lsm_md_stripe_count;
2452 if (stripe_count > NORMAL_MAX_STRIPES) {
2453 OBD_ALLOC(ents, sizeof(ents[0]) * stripe_count);
2455 GOTO(out, rc = -ENOMEM);
2458 memset(ents, 0, sizeof(ents[0]) * stripe_count);
2461 min_hash = MDS_DIR_END_OFF;
2462 for (i = 0; i < stripe_count; i++) {
2463 struct lmv_tgt_desc *tgt;
2464 struct page *page = NULL;
2466 if (likely(lsm == NULL)) {
2467 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2469 GOTO(out, rc = PTR_ERR(tgt));
2470 LASSERT(op_data->op_data != NULL);
2472 tgt = lmv_get_target(lmv, lsm->lsm_md_oinfo[i].lmo_mds);
2474 GOTO(out, rc = PTR_ERR(tgt));
2475 op_data->op_fid1 = lsm->lsm_md_oinfo[i].lmo_fid;
2476 op_data->op_fid2 = lsm->lsm_md_oinfo[i].lmo_fid;
2477 op_data->op_stripe_offset = i;
2480 rc = md_read_entry(tgt->ltd_exp, op_data, cb_op, &ents[i],
2485 if (ents[i] != NULL &&
2486 le64_to_cpu(ents[i]->lde_hash) <= min_hash) {
2487 if (min_page != NULL)
2488 page_cache_release(min_page);
2490 min_hash = le64_to_cpu(ents[i]->lde_hash);
2495 if (min_hash != MDS_DIR_END_OFF)
2496 *ldp = ents[min_idx];
2500 if (stripe_count > NORMAL_MAX_STRIPES && ents != NULL)
2501 OBD_FREE(ents, sizeof(ents[0]) * stripe_count);
2503 if (rc != 0 && min_page != NULL) {
2505 page_cache_release(min_page);
2513 static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
2514 struct ptlrpc_request **request)
2516 struct obd_device *obd = exp->exp_obd;
2517 struct lmv_obd *lmv = &obd->u.lmv;
2518 struct lmv_tgt_desc *tgt = NULL;
2519 struct lmv_tgt_desc *parent_tgt = NULL;
2520 struct mdt_body *body;
2524 rc = lmv_check_connect(obd);
2528 /* Send unlink requests to the MDT where the child is located */
2529 if (likely(!fid_is_zero(&op_data->op_fid2))) {
2530 tgt = lmv_find_target(lmv, &op_data->op_fid2);
2532 RETURN(PTR_ERR(tgt));
2534 /* For striped dir, we need to locate the parent as well */
2535 if (op_data->op_mea1 != NULL &&
2536 op_data->op_mea1->lsm_md_stripe_count > 1) {
2537 struct lmv_tgt_desc *tmp;
2539 LASSERT(op_data->op_name != NULL &&
2540 op_data->op_namelen != 0);
2541 tmp = lmv_locate_target_for_name(lmv,
2544 op_data->op_namelen,
2548 RETURN(PTR_ERR(tmp));
2551 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
2553 RETURN(PTR_ERR(tgt));
2556 op_data->op_fsuid = current_fsuid();
2557 op_data->op_fsgid = current_fsgid();
2558 op_data->op_cap = cfs_curproc_cap_pack();
2561 * If child's fid is given, cancel unused locks for it if it is from
2562 * another export than parent.
2564 * LOOKUP lock for child (fid3) should also be cancelled on parent
2565 * tgt_tgt in mdc_unlink().
2567 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2570 * Cancel FULL locks on child (fid3).
2572 parent_tgt = lmv_find_target(lmv, &op_data->op_fid1);
2573 if (IS_ERR(parent_tgt))
2574 RETURN(PTR_ERR(parent_tgt));
2576 if (parent_tgt != tgt) {
2577 rc = lmv_early_cancel(exp, parent_tgt, op_data, tgt->ltd_idx,
2578 LCK_EX, MDS_INODELOCK_LOOKUP,
2579 MF_MDC_CANCEL_FID3);
2582 rc = lmv_early_cancel(exp, NULL, op_data, tgt->ltd_idx, LCK_EX,
2583 MDS_INODELOCK_FULL, MF_MDC_CANCEL_FID3);
2587 CDEBUG(D_INODE, "unlink with fid="DFID"/"DFID" -> mds #%d\n",
2588 PFID(&op_data->op_fid1), PFID(&op_data->op_fid2), tgt->ltd_idx);
2590 rc = md_unlink(tgt->ltd_exp, op_data, request);
2591 if (rc != 0 && rc != -EREMOTE)
2594 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
2598 /* Not cross-ref case, just get out of here. */
2599 if (likely(!(body->valid & OBD_MD_MDS)))
2602 CDEBUG(D_INODE, "%s: try unlink to another MDT for "DFID"\n",
2603 exp->exp_obd->obd_name, PFID(&body->fid1));
2605 /* This is a remote object, try remote MDT, Note: it may
2606 * try more than 1 time here, Considering following case
2607 * /mnt/lustre is root on MDT0, remote1 is on MDT1
2608 * 1. Initially A does not know where remote1 is, it send
2609 * unlink RPC to MDT0, MDT0 return -EREMOTE, it will
2610 * resend unlink RPC to MDT1 (retry 1st time).
2612 * 2. During the unlink RPC in flight,
2613 * client B mv /mnt/lustre/remote1 /mnt/lustre/remote2
2614 * and create new remote1, but on MDT0
2616 * 3. MDT1 get unlink RPC(from A), then do remote lock on
2617 * /mnt/lustre, then lookup get fid of remote1, and find
2618 * it is remote dir again, and replay -EREMOTE again.
2620 * 4. Then A will resend unlink RPC to MDT0. (retry 2nd times).
2622 * In theory, it might try unlimited time here, but it should
2623 * be very rare case. */
2624 op_data->op_fid2 = body->fid1;
2625 ptlrpc_req_finished(*request);
2631 static int lmv_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2633 struct lmv_obd *lmv = &obd->u.lmv;
2637 case OBD_CLEANUP_EARLY:
2638 /* XXX: here should be calling obd_precleanup() down to
2641 case OBD_CLEANUP_EXPORTS:
2642 fld_client_proc_fini(&lmv->lmv_fld);
2643 lprocfs_obd_cleanup(obd);
2644 lprocfs_free_md_stats(obd);
2652 static int lmv_get_info(const struct lu_env *env, struct obd_export *exp,
2653 __u32 keylen, void *key, __u32 *vallen, void *val,
2654 struct lov_stripe_md *lsm)
2656 struct obd_device *obd;
2657 struct lmv_obd *lmv;
2661 obd = class_exp2obd(exp);
2663 CDEBUG(D_IOCTL, "Invalid client cookie "LPX64"\n",
2664 exp->exp_handle.h_cookie);
2669 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
2672 rc = lmv_check_connect(obd);
2676 LASSERT(*vallen == sizeof(__u32));
2677 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2678 struct lmv_tgt_desc *tgt = lmv->tgts[i];
2680 * All tgts should be connected when this gets called.
2682 if (tgt == NULL || tgt->ltd_exp == NULL)
2685 if (!obd_get_info(env, tgt->ltd_exp, keylen, key,
2690 } else if (KEY_IS(KEY_MAX_EASIZE) || KEY_IS(KEY_CONN_DATA)) {
2691 rc = lmv_check_connect(obd);
2696 * Forwarding this request to first MDS, it should know LOV
2699 rc = obd_get_info(env, lmv->tgts[0]->ltd_exp, keylen, key,
2701 if (!rc && KEY_IS(KEY_CONN_DATA))
2702 exp->exp_connect_data = *(struct obd_connect_data *)val;
2704 } else if (KEY_IS(KEY_TGT_COUNT)) {
2705 *((int *)val) = lmv->desc.ld_tgt_count;
2709 CDEBUG(D_IOCTL, "Invalid key\n");
2713 int lmv_set_info_async(const struct lu_env *env, struct obd_export *exp,
2714 obd_count keylen, void *key, obd_count vallen,
2715 void *val, struct ptlrpc_request_set *set)
2717 struct lmv_tgt_desc *tgt = NULL;
2718 struct obd_device *obd;
2719 struct lmv_obd *lmv;
2723 obd = class_exp2obd(exp);
2725 CDEBUG(D_IOCTL, "Invalid client cookie "LPX64"\n",
2726 exp->exp_handle.h_cookie);
2731 if (KEY_IS(KEY_READ_ONLY) || KEY_IS(KEY_FLUSH_CTX)) {
2734 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2737 if (tgt == NULL || tgt->ltd_exp == NULL)
2740 err = obd_set_info_async(env, tgt->ltd_exp,
2741 keylen, key, vallen, val, set);
2752 static int lmv_pack_md_v1(const struct lmv_stripe_md *lsm,
2753 struct lmv_mds_md_v1 *lmm1)
2758 lmm1->lmv_magic = cpu_to_le32(lsm->lsm_md_magic);
2759 lmm1->lmv_stripe_count = cpu_to_le32(lsm->lsm_md_stripe_count);
2760 lmm1->lmv_master_mdt_index = cpu_to_le32(lsm->lsm_md_master_mdt_index);
2761 lmm1->lmv_hash_type = cpu_to_le32(lsm->lsm_md_hash_type);
2762 cplen = strlcpy(lmm1->lmv_pool_name, lsm->lsm_md_pool_name,
2763 sizeof(lmm1->lmv_pool_name));
2764 if (cplen >= sizeof(lmm1->lmv_pool_name))
2767 for (i = 0; i < lsm->lsm_md_stripe_count; i++)
2768 fid_cpu_to_le(&lmm1->lmv_stripe_fids[i],
2769 &lsm->lsm_md_oinfo[i].lmo_fid);
2773 int lmv_pack_md(union lmv_mds_md **lmmp, const struct lmv_stripe_md *lsm,
2777 bool allocated = false;
2781 LASSERT(lmmp != NULL);
2783 if (*lmmp != NULL && lsm == NULL) {
2786 stripe_count = lmv_mds_md_stripe_count_get(*lmmp);
2787 lmm_size = lmv_mds_md_size(stripe_count,
2788 le32_to_cpu((*lmmp)->lmv_magic));
2791 OBD_FREE(*lmmp, lmm_size);
2797 if (*lmmp == NULL && lsm == NULL) {
2798 lmm_size = lmv_mds_md_size(stripe_count, LMV_MAGIC);
2799 LASSERT(lmm_size > 0);
2800 OBD_ALLOC(*lmmp, lmm_size);
2803 lmv_mds_md_stripe_count_set(*lmmp, stripe_count);
2804 (*lmmp)->lmv_magic = cpu_to_le32(LMV_MAGIC);
2809 LASSERT(lsm != NULL);
2810 lmm_size = lmv_mds_md_size(lsm->lsm_md_stripe_count, lsm->lsm_md_magic);
2811 if (*lmmp == NULL) {
2812 OBD_ALLOC(*lmmp, lmm_size);
2818 switch (lsm->lsm_md_magic) {
2820 rc = lmv_pack_md_v1(lsm, &(*lmmp)->lmv_md_v1);
2827 if (rc != 0 && allocated) {
2828 OBD_FREE(*lmmp, lmm_size);
2834 EXPORT_SYMBOL(lmv_pack_md);
2836 static int lmv_unpack_md_v1(struct obd_export *exp, struct lmv_stripe_md *lsm,
2837 const struct lmv_mds_md_v1 *lmm1)
2839 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2846 lsm->lsm_md_magic = le32_to_cpu(lmm1->lmv_magic);
2847 lsm->lsm_md_stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
2848 lsm->lsm_md_master_mdt_index = le32_to_cpu(lmm1->lmv_master_mdt_index);
2849 lsm->lsm_md_hash_type = le32_to_cpu(lmm1->lmv_hash_type);
2850 lsm->lsm_md_layout_version = le32_to_cpu(lmm1->lmv_layout_version);
2851 cplen = strlcpy(lsm->lsm_md_pool_name, lmm1->lmv_pool_name,
2852 sizeof(lsm->lsm_md_pool_name));
2854 if (cplen >= sizeof(lsm->lsm_md_pool_name))
2857 CDEBUG(D_INFO, "unpack lsm count %d, master %d hash_type %d"
2858 "layout_version %d\n", lsm->lsm_md_stripe_count,
2859 lsm->lsm_md_master_mdt_index, lsm->lsm_md_hash_type,
2860 lsm->lsm_md_layout_version);
2862 stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
2863 for (i = 0; i < le32_to_cpu(stripe_count); i++) {
2864 fid_le_to_cpu(&lsm->lsm_md_oinfo[i].lmo_fid,
2865 &lmm1->lmv_stripe_fids[i]);
2866 rc = lmv_fld_lookup(lmv, &lsm->lsm_md_oinfo[i].lmo_fid,
2867 &lsm->lsm_md_oinfo[i].lmo_mds);
2870 CDEBUG(D_INFO, "unpack fid #%d "DFID"\n", i,
2871 PFID(&lsm->lsm_md_oinfo[i].lmo_fid));
2877 int lmv_unpack_md(struct obd_export *exp, struct lmv_stripe_md **lsmp,
2878 const union lmv_mds_md *lmm, int stripe_count)
2880 struct lmv_stripe_md *lsm;
2883 bool allocated = false;
2886 LASSERT(lsmp != NULL);
2890 if (lsm != NULL && lmm == NULL) {
2893 for (i = 1; i < lsm->lsm_md_stripe_count; i++) {
2894 if (lsm->lsm_md_oinfo[i].lmo_root != NULL)
2895 iput(lsm->lsm_md_oinfo[i].lmo_root);
2898 lsm_size = lmv_stripe_md_size(lsm->lsm_md_stripe_count);
2899 OBD_FREE(lsm, lsm_size);
2905 if (lsm == NULL && lmm == NULL) {
2906 lsm_size = lmv_stripe_md_size(stripe_count);
2907 OBD_ALLOC(lsm, lsm_size);
2910 lsm->lsm_md_stripe_count = stripe_count;
2916 if (le32_to_cpu(lmm->lmv_magic) != LMV_MAGIC_V1 &&
2917 le32_to_cpu(lmm->lmv_magic) != LMV_MAGIC_MIGRATE &&
2918 le32_to_cpu(lmm->lmv_magic) != LMV_USER_MAGIC) {
2919 CERROR("%s: invalid lmv magic %x: rc = %d\n",
2920 exp->exp_obd->obd_name, le32_to_cpu(lmm->lmv_magic),
2925 if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_V1 ||
2926 le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_MIGRATE)
2927 lsm_size = lmv_stripe_md_size(lmv_mds_md_stripe_count_get(lmm));
2930 * Unpack default dirstripe(lmv_user_md) to lmv_stripe_md,
2931 * stripecount should be 0 then.
2933 lsm_size = lmv_stripe_md_size(0);
2935 lsm_size = lmv_stripe_md_size(lmv_mds_md_stripe_count_get(lmm));
2937 OBD_ALLOC(lsm, lsm_size);
2944 switch (le32_to_cpu(lmm->lmv_magic)) {
2946 case LMV_MAGIC_MIGRATE:
2947 rc = lmv_unpack_md_v1(exp, lsm, &lmm->lmv_md_v1);
2950 CERROR("%s: unrecognized magic %x\n", exp->exp_obd->obd_name,
2951 le32_to_cpu(lmm->lmv_magic));
2956 if (rc != 0 && allocated) {
2957 OBD_FREE(lsm, lsm_size);
2964 int lmv_alloc_memmd(struct lmv_stripe_md **lsmp, int stripes)
2966 return lmv_unpack_md(NULL, lsmp, NULL, stripes);
2968 EXPORT_SYMBOL(lmv_alloc_memmd);
2970 void lmv_free_memmd(struct lmv_stripe_md *lsm)
2972 lmv_unpack_md(NULL, &lsm, NULL, 0);
2974 EXPORT_SYMBOL(lmv_free_memmd);
2976 int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
2977 struct lov_mds_md *lmm, int disk_len)
2979 return lmv_unpack_md(exp, (struct lmv_stripe_md **)lsmp,
2980 (union lmv_mds_md *)lmm, disk_len);
2983 int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
2984 struct lov_stripe_md *lsm)
2986 struct obd_device *obd = exp->exp_obd;
2987 struct lmv_obd *lmv_obd = &obd->u.lmv;
2988 const struct lmv_stripe_md *lmv = (struct lmv_stripe_md *)lsm;
2993 stripe_count = lmv->lsm_md_stripe_count;
2995 stripe_count = lmv_obd->desc.ld_tgt_count;
2997 return lmv_mds_md_size(stripe_count, LMV_MAGIC_V1);
3000 return lmv_pack_md((union lmv_mds_md **)lmmp, lmv, 0);
3003 static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
3004 ldlm_policy_data_t *policy, ldlm_mode_t mode,
3005 ldlm_cancel_flags_t flags, void *opaque)
3007 struct obd_device *obd = exp->exp_obd;
3008 struct lmv_obd *lmv = &obd->u.lmv;
3014 LASSERT(fid != NULL);
3016 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
3017 struct lmv_tgt_desc *tgt = lmv->tgts[i];
3019 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
3022 err = md_cancel_unused(tgt->ltd_exp, fid, policy, mode, flags,
3030 int lmv_set_lock_data(struct obd_export *exp, __u64 *lockh, void *data,
3033 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
3034 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3038 if (tgt == NULL || tgt->ltd_exp == NULL)
3040 rc = md_set_lock_data(tgt->ltd_exp, lockh, data, bits);
3044 ldlm_mode_t lmv_lock_match(struct obd_export *exp, __u64 flags,
3045 const struct lu_fid *fid, ldlm_type_t type,
3046 ldlm_policy_data_t *policy, ldlm_mode_t mode,
3047 struct lustre_handle *lockh)
3049 struct obd_device *obd = exp->exp_obd;
3050 struct lmv_obd *lmv = &obd->u.lmv;
3055 CDEBUG(D_INODE, "Lock match for "DFID"\n", PFID(fid));
3058 * With CMD every object can have two locks in different namespaces:
3059 * lookup lock in space of mds storing direntry and update/open lock in
3060 * space of mds storing inode. Thus we check all targets, not only that
3061 * one fid was created in.
3063 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
3064 struct lmv_tgt_desc *tgt = lmv->tgts[i];
3066 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
3069 rc = md_lock_match(tgt->ltd_exp, flags, fid, type, policy, mode,
3078 int lmv_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
3079 struct obd_export *dt_exp, struct obd_export *md_exp,
3080 struct lustre_md *md)
3082 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
3083 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3085 if (tgt == NULL || tgt->ltd_exp == NULL)
3088 return md_get_lustre_md(lmv->tgts[0]->ltd_exp, req, dt_exp, md_exp, md);
3091 int lmv_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
3093 struct obd_device *obd = exp->exp_obd;
3094 struct lmv_obd *lmv = &obd->u.lmv;
3095 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3098 if (md->lmv != NULL) {
3099 lmv_free_memmd(md->lmv);
3102 if (tgt == NULL || tgt->ltd_exp == NULL)
3104 RETURN(md_free_lustre_md(lmv->tgts[0]->ltd_exp, md));
3107 int lmv_set_open_replay_data(struct obd_export *exp,
3108 struct obd_client_handle *och,
3109 struct lookup_intent *it)
3111 struct obd_device *obd = exp->exp_obd;
3112 struct lmv_obd *lmv = &obd->u.lmv;
3113 struct lmv_tgt_desc *tgt;
3116 tgt = lmv_find_target(lmv, &och->och_fid);
3118 RETURN(PTR_ERR(tgt));
3120 RETURN(md_set_open_replay_data(tgt->ltd_exp, och, it));
3123 int lmv_clear_open_replay_data(struct obd_export *exp,
3124 struct obd_client_handle *och)
3126 struct obd_device *obd = exp->exp_obd;
3127 struct lmv_obd *lmv = &obd->u.lmv;
3128 struct lmv_tgt_desc *tgt;
3131 tgt = lmv_find_target(lmv, &och->och_fid);
3133 RETURN(PTR_ERR(tgt));
3135 RETURN(md_clear_open_replay_data(tgt->ltd_exp, och));
3138 static int lmv_get_remote_perm(struct obd_export *exp,
3139 const struct lu_fid *fid,
3140 struct obd_capa *oc, __u32 suppgid,
3141 struct ptlrpc_request **request)
3143 struct obd_device *obd = exp->exp_obd;
3144 struct lmv_obd *lmv = &obd->u.lmv;
3145 struct lmv_tgt_desc *tgt;
3149 rc = lmv_check_connect(obd);
3153 tgt = lmv_find_target(lmv, fid);
3155 RETURN(PTR_ERR(tgt));
3157 rc = md_get_remote_perm(tgt->ltd_exp, fid, oc, suppgid, request);
3161 static int lmv_renew_capa(struct obd_export *exp, struct obd_capa *oc,
3164 struct obd_device *obd = exp->exp_obd;
3165 struct lmv_obd *lmv = &obd->u.lmv;
3166 struct lmv_tgt_desc *tgt;
3170 rc = lmv_check_connect(obd);
3174 tgt = lmv_find_target(lmv, &oc->c_capa.lc_fid);
3176 RETURN(PTR_ERR(tgt));
3178 rc = md_renew_capa(tgt->ltd_exp, oc, cb);
3182 int lmv_unpack_capa(struct obd_export *exp, struct ptlrpc_request *req,
3183 const struct req_msg_field *field, struct obd_capa **oc)
3185 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
3186 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3188 if (tgt == NULL || tgt->ltd_exp == NULL)
3190 return md_unpack_capa(tgt->ltd_exp, req, field, oc);
3193 int lmv_intent_getattr_async(struct obd_export *exp,
3194 struct md_enqueue_info *minfo,
3195 struct ldlm_enqueue_info *einfo)
3197 struct md_op_data *op_data = &minfo->mi_data;
3198 struct obd_device *obd = exp->exp_obd;
3199 struct lmv_obd *lmv = &obd->u.lmv;
3200 struct lmv_tgt_desc *tgt = NULL;
3204 rc = lmv_check_connect(obd);
3208 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
3210 RETURN(PTR_ERR(tgt));
3212 rc = md_intent_getattr_async(tgt->ltd_exp, minfo, einfo);
3216 int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
3217 struct lu_fid *fid, __u64 *bits)
3219 struct obd_device *obd = exp->exp_obd;
3220 struct lmv_obd *lmv = &obd->u.lmv;
3221 struct lmv_tgt_desc *tgt;
3225 rc = lmv_check_connect(obd);
3229 tgt = lmv_find_target(lmv, fid);
3231 RETURN(PTR_ERR(tgt));
3233 rc = md_revalidate_lock(tgt->ltd_exp, it, fid, bits);
3238 * For lmv, only need to send request to master MDT, and the master MDT will
3239 * process with other slave MDTs. The only exception is Q_GETOQUOTA for which
3240 * we directly fetch data from the slave MDTs.
3242 int lmv_quotactl(struct obd_device *unused, struct obd_export *exp,
3243 struct obd_quotactl *oqctl)
3245 struct obd_device *obd = class_exp2obd(exp);
3246 struct lmv_obd *lmv = &obd->u.lmv;
3247 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3250 __u64 curspace, curinodes;
3254 tgt->ltd_exp == NULL ||
3256 lmv->desc.ld_tgt_count == 0) {
3257 CERROR("master lmv inactive\n");
3261 if (oqctl->qc_cmd != Q_GETOQUOTA) {
3262 rc = obd_quotactl(tgt->ltd_exp, oqctl);
3266 curspace = curinodes = 0;
3267 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
3271 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
3274 err = obd_quotactl(tgt->ltd_exp, oqctl);
3276 CERROR("getquota on mdt %d failed. %d\n", i, err);
3280 curspace += oqctl->qc_dqblk.dqb_curspace;
3281 curinodes += oqctl->qc_dqblk.dqb_curinodes;
3284 oqctl->qc_dqblk.dqb_curspace = curspace;
3285 oqctl->qc_dqblk.dqb_curinodes = curinodes;
3290 int lmv_quotacheck(struct obd_device *unused, struct obd_export *exp,
3291 struct obd_quotactl *oqctl)
3293 struct obd_device *obd = class_exp2obd(exp);
3294 struct lmv_obd *lmv = &obd->u.lmv;
3295 struct lmv_tgt_desc *tgt;
3300 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
3303 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active) {
3304 CERROR("lmv idx %d inactive\n", i);
3308 err = obd_quotacheck(tgt->ltd_exp, oqctl);
3316 int lmv_update_lsm_md(struct obd_export *exp, struct lmv_stripe_md *lsm,
3317 struct mdt_body *body, ldlm_blocking_callback cb_blocking)
3319 if (lsm->lsm_md_stripe_count <= 1)
3322 return lmv_revalidate_slaves(exp, body, lsm, cb_blocking, 0);
3325 int lmv_merge_attr(struct obd_export *exp, const struct lmv_stripe_md *lsm,
3326 struct cl_attr *attr)
3331 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
3332 struct inode *inode = lsm->lsm_md_oinfo[i].lmo_root;
3334 CDEBUG(D_INFO, ""DFID" size %llu, nlink %u, atime %lu ctime"
3335 "%lu, mtime %lu.\n", PFID(&lsm->lsm_md_oinfo[i].lmo_fid),
3336 i_size_read(inode), inode->i_nlink,
3337 LTIME_S(inode->i_atime), LTIME_S(inode->i_ctime),
3338 LTIME_S(inode->i_mtime));
3340 /* for slave stripe, it needs to subtract nlink for . and .. */
3342 attr->cat_nlink += inode->i_nlink - 2;
3344 attr->cat_nlink = inode->i_nlink;
3346 attr->cat_size += i_size_read(inode);
3348 if (attr->cat_atime < LTIME_S(inode->i_atime))
3349 attr->cat_atime = LTIME_S(inode->i_atime);
3351 if (attr->cat_ctime < LTIME_S(inode->i_ctime))
3352 attr->cat_ctime = LTIME_S(inode->i_ctime);
3354 if (attr->cat_mtime < LTIME_S(inode->i_mtime))
3355 attr->cat_mtime = LTIME_S(inode->i_mtime);
3361 struct obd_ops lmv_obd_ops = {
3362 .o_owner = THIS_MODULE,
3363 .o_setup = lmv_setup,
3364 .o_cleanup = lmv_cleanup,
3365 .o_precleanup = lmv_precleanup,
3366 .o_process_config = lmv_process_config,
3367 .o_connect = lmv_connect,
3368 .o_disconnect = lmv_disconnect,
3369 .o_statfs = lmv_statfs,
3370 .o_get_info = lmv_get_info,
3371 .o_set_info_async = lmv_set_info_async,
3372 .o_packmd = lmv_packmd,
3373 .o_unpackmd = lmv_unpackmd,
3374 .o_notify = lmv_notify,
3375 .o_get_uuid = lmv_get_uuid,
3376 .o_iocontrol = lmv_iocontrol,
3377 .o_quotacheck = lmv_quotacheck,
3378 .o_quotactl = lmv_quotactl
3381 struct md_ops lmv_md_ops = {
3382 .m_getstatus = lmv_getstatus,
3383 .m_null_inode = lmv_null_inode,
3384 .m_find_cbdata = lmv_find_cbdata,
3385 .m_close = lmv_close,
3386 .m_create = lmv_create,
3387 .m_done_writing = lmv_done_writing,
3388 .m_enqueue = lmv_enqueue,
3389 .m_getattr = lmv_getattr,
3390 .m_getxattr = lmv_getxattr,
3391 .m_getattr_name = lmv_getattr_name,
3392 .m_intent_lock = lmv_intent_lock,
3394 .m_rename = lmv_rename,
3395 .m_setattr = lmv_setattr,
3396 .m_setxattr = lmv_setxattr,
3397 .m_fsync = lmv_fsync,
3398 .m_read_entry = lmv_read_entry,
3399 .m_unlink = lmv_unlink,
3400 .m_init_ea_size = lmv_init_ea_size,
3401 .m_cancel_unused = lmv_cancel_unused,
3402 .m_set_lock_data = lmv_set_lock_data,
3403 .m_lock_match = lmv_lock_match,
3404 .m_get_lustre_md = lmv_get_lustre_md,
3405 .m_free_lustre_md = lmv_free_lustre_md,
3406 .m_update_lsm_md = lmv_update_lsm_md,
3407 .m_merge_attr = lmv_merge_attr,
3408 .m_set_open_replay_data = lmv_set_open_replay_data,
3409 .m_clear_open_replay_data = lmv_clear_open_replay_data,
3410 .m_renew_capa = lmv_renew_capa,
3411 .m_unpack_capa = lmv_unpack_capa,
3412 .m_get_remote_perm = lmv_get_remote_perm,
3413 .m_intent_getattr_async = lmv_intent_getattr_async,
3414 .m_revalidate_lock = lmv_revalidate_lock
3417 int __init lmv_init(void)
3419 return class_register_type(&lmv_obd_ops, &lmv_md_ops, NULL,
3420 #ifndef HAVE_ONLY_PROCFS_SEQ
3423 LUSTRE_LMV_NAME, NULL);
3427 static void lmv_exit(void)
3429 class_unregister_type(LUSTRE_LMV_NAME);
3432 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
3433 MODULE_DESCRIPTION("Lustre Logical Metadata Volume OBD driver");
3434 MODULE_LICENSE("GPL");
3436 module_init(lmv_init);
3437 module_exit(lmv_exit);