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 <linux/math64.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 <lustre_ioctl.h>
64 #include "lmv_internal.h"
66 /* This hash is only for testing purpose */
67 static inline unsigned int
68 lmv_hash_all_chars(unsigned int count, const char *name, int namelen)
71 const unsigned char *p = (const unsigned char *)name;
73 while (--namelen >= 0)
81 static inline unsigned int
82 lmv_hash_fnv1a(unsigned int count, const char *name, int namelen)
86 hash = lustre_hash_fnv_1a_64(name, namelen);
93 int lmv_name_to_stripe_index(__u32 lmv_hash_type, unsigned int stripe_count,
94 const char *name, int namelen)
97 __u32 hash_type = lmv_hash_type & LMV_HASH_TYPE_MASK;
100 if (stripe_count <= 1)
103 /* for migrating object, always start from 0 stripe */
104 if (lmv_hash_type & LMV_HASH_FLAG_MIGRATION)
108 case LMV_HASH_TYPE_ALL_CHARS:
109 idx = lmv_hash_all_chars(stripe_count, name, namelen);
111 case LMV_HASH_TYPE_FNV_1A_64:
112 idx = lmv_hash_fnv1a(stripe_count, name, namelen);
115 CERROR("Unknown hash type 0x%x\n", hash_type);
119 CDEBUG(D_INFO, "name %.*s hash_type %d idx %d\n", namelen, name,
125 static void lmv_activate_target(struct lmv_obd *lmv,
126 struct lmv_tgt_desc *tgt,
129 if (tgt->ltd_active == activate)
132 tgt->ltd_active = activate;
133 lmv->desc.ld_active_tgt_count += (activate ? 1 : -1);
139 * -EINVAL : UUID can't be found in the LMV's target list
140 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
141 * -EBADF : The UUID is found, but the OBD of the wrong type (!)
143 static int lmv_set_mdc_active(struct lmv_obd *lmv,
144 const struct obd_uuid *uuid,
147 struct lmv_tgt_desc *tgt = NULL;
148 struct obd_device *obd;
153 CDEBUG(D_INFO, "Searching in lmv %p for uuid %s (activate=%d)\n",
154 lmv, uuid->uuid, activate);
156 spin_lock(&lmv->lmv_lock);
157 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
159 if (tgt == NULL || tgt->ltd_exp == NULL)
162 CDEBUG(D_INFO, "Target idx %d is %s conn "LPX64"\n", i,
163 tgt->ltd_uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
165 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
169 if (i == lmv->desc.ld_tgt_count)
170 GOTO(out_lmv_lock, rc = -EINVAL);
172 obd = class_exp2obd(tgt->ltd_exp);
174 GOTO(out_lmv_lock, rc = -ENOTCONN);
176 CDEBUG(D_INFO, "Found OBD %s=%s device %d (%p) type %s at LMV idx %d\n",
177 obd->obd_name, obd->obd_uuid.uuid, obd->obd_minor, obd,
178 obd->obd_type->typ_name, i);
179 LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0);
181 if (tgt->ltd_active == activate) {
182 CDEBUG(D_INFO, "OBD %p already %sactive!\n", obd,
183 activate ? "" : "in");
184 GOTO(out_lmv_lock, rc);
187 CDEBUG(D_INFO, "Marking OBD %p %sactive\n", obd,
188 activate ? "" : "in");
189 lmv_activate_target(lmv, tgt, activate);
193 spin_unlock(&lmv->lmv_lock);
197 struct obd_uuid *lmv_get_uuid(struct obd_export *exp)
199 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
200 struct lmv_tgt_desc *tgt = lmv->tgts[0];
202 return (tgt == NULL) ? NULL : obd_get_uuid(tgt->ltd_exp);
205 static int lmv_notify(struct obd_device *obd, struct obd_device *watched,
206 enum obd_notify_event ev, void *data)
208 struct obd_connect_data *conn_data;
209 struct lmv_obd *lmv = &obd->u.lmv;
210 struct obd_uuid *uuid;
214 if (strcmp(watched->obd_type->typ_name, LUSTRE_MDC_NAME)) {
215 CERROR("unexpected notification of %s %s!\n",
216 watched->obd_type->typ_name,
221 uuid = &watched->u.cli.cl_target_uuid;
222 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE) {
224 * Set MDC as active before notifying the observer, so the
225 * observer can use the MDC normally.
227 rc = lmv_set_mdc_active(lmv, uuid,
228 ev == OBD_NOTIFY_ACTIVE);
230 CERROR("%sactivation of %s failed: %d\n",
231 ev == OBD_NOTIFY_ACTIVE ? "" : "de",
235 } else if (ev == OBD_NOTIFY_OCD) {
236 conn_data = &watched->u.cli.cl_import->imp_connect_data;
238 * XXX: Make sure that ocd_connect_flags from all targets are
239 * the same. Otherwise one of MDTs runs wrong version or
240 * something like this. --umka
242 obd->obd_self_export->exp_connect_data = *conn_data;
245 else if (ev == OBD_NOTIFY_DISCON) {
247 * For disconnect event, flush fld cache for failout MDS case.
249 fld_client_flush(&lmv->lmv_fld);
253 * Pass the notification up the chain.
255 if (obd->obd_observer)
256 rc = obd_notify(obd->obd_observer, watched, ev, data);
262 * This is fake connect function. Its purpose is to initialize lmv and say
263 * caller that everything is okay. Real connection will be performed later.
265 static int lmv_connect(const struct lu_env *env,
266 struct obd_export **exp, struct obd_device *obd,
267 struct obd_uuid *cluuid, struct obd_connect_data *data,
270 struct lmv_obd *lmv = &obd->u.lmv;
271 struct lustre_handle conn = { 0 };
276 * We don't want to actually do the underlying connections more than
277 * once, so keep track.
280 if (lmv->refcount > 1) {
285 rc = class_connect(&conn, obd, cluuid);
287 CERROR("class_connection() returned %d\n", rc);
291 *exp = class_conn2export(&conn);
292 class_export_get(*exp);
296 lmv->cluuid = *cluuid;
299 lmv->conn_data = *data;
301 if (lmv->targets_proc_entry == NULL) {
302 lmv->targets_proc_entry = lprocfs_seq_register("target_obds",
305 if (IS_ERR(lmv->targets_proc_entry)) {
306 CERROR("could not register /proc/fs/lustre/%s/%s/target_obds.",
307 obd->obd_type->typ_name, obd->obd_name);
308 lmv->targets_proc_entry = NULL;
313 * All real clients should perform actual connection right away, because
314 * it is possible, that LMV will not have opportunity to connect targets
315 * and MDC stuff will be called directly, for instance while reading
316 * ../mdc/../kbytesfree procfs file, etc.
318 if (data != NULL && (data->ocd_connect_flags & OBD_CONNECT_REAL))
319 rc = lmv_check_connect(obd);
321 if (rc && lmv->targets_proc_entry != NULL)
322 lprocfs_remove(&lmv->targets_proc_entry);
326 static void lmv_set_timeouts(struct obd_device *obd)
332 if (lmv->server_timeout == 0)
335 if (lmv->connected == 0)
338 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
339 struct lmv_tgt_desc *tgt = lmv->tgts[i];
341 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
344 obd_set_info_async(NULL, tgt->ltd_exp, sizeof(KEY_INTERMDS),
345 KEY_INTERMDS, 0, NULL, NULL);
349 static int lmv_init_ea_size(struct obd_export *exp, int easize,
350 int def_easize, int cookiesize, int def_cookiesize)
352 struct obd_device *obd = exp->exp_obd;
353 struct lmv_obd *lmv = &obd->u.lmv;
359 if (lmv->max_easize < easize) {
360 lmv->max_easize = easize;
363 if (lmv->max_def_easize < def_easize) {
364 lmv->max_def_easize = def_easize;
367 if (lmv->max_cookiesize < cookiesize) {
368 lmv->max_cookiesize = cookiesize;
371 if (lmv->max_def_cookiesize < def_cookiesize) {
372 lmv->max_def_cookiesize = def_cookiesize;
378 if (lmv->connected == 0)
381 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
382 struct lmv_tgt_desc *tgt = lmv->tgts[i];
384 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active) {
385 CWARN("%s: NULL export for %d\n", obd->obd_name, i);
389 rc = md_init_ea_size(tgt->ltd_exp, easize, def_easize,
390 cookiesize, def_cookiesize);
392 CERROR("%s: obd_init_ea_size() failed on MDT target %d:"
393 " rc = %d.\n", obd->obd_name, i, rc);
400 #define MAX_STRING_SIZE 128
402 int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
404 struct lmv_obd *lmv = &obd->u.lmv;
405 struct obd_uuid *cluuid = &lmv->cluuid;
406 struct obd_uuid lmv_mdc_uuid = { "LMV_MDC_UUID" };
407 struct obd_device *mdc_obd;
408 struct obd_export *mdc_exp;
409 struct lu_fld_target target;
413 mdc_obd = class_find_client_obd(&tgt->ltd_uuid, LUSTRE_MDC_NAME,
416 CERROR("target %s not attached\n", tgt->ltd_uuid.uuid);
420 CDEBUG(D_CONFIG, "connect to %s(%s) - %s, %s FOR %s\n",
421 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
422 tgt->ltd_uuid.uuid, obd->obd_uuid.uuid,
425 if (!mdc_obd->obd_set_up) {
426 CERROR("target %s is not set up\n", tgt->ltd_uuid.uuid);
430 rc = obd_connect(NULL, &mdc_exp, mdc_obd, &lmv_mdc_uuid,
431 &lmv->conn_data, NULL);
433 CERROR("target %s connect error %d\n", tgt->ltd_uuid.uuid, rc);
438 * Init fid sequence client for this mdc and add new fld target.
440 rc = obd_fid_init(mdc_obd, mdc_exp, LUSTRE_SEQ_METADATA);
444 target.ft_srv = NULL;
445 target.ft_exp = mdc_exp;
446 target.ft_idx = tgt->ltd_idx;
448 fld_client_add_target(&lmv->lmv_fld, &target);
450 rc = obd_register_observer(mdc_obd, obd);
452 obd_disconnect(mdc_exp);
453 CERROR("target %s register_observer error %d\n",
454 tgt->ltd_uuid.uuid, rc);
458 if (obd->obd_observer) {
460 * Tell the observer about the new target.
462 rc = obd_notify(obd->obd_observer, mdc_exp->exp_obd,
464 (void *)(tgt - lmv->tgts[0]));
466 obd_disconnect(mdc_exp);
472 tgt->ltd_exp = mdc_exp;
473 lmv->desc.ld_active_tgt_count++;
475 md_init_ea_size(tgt->ltd_exp, lmv->max_easize, lmv->max_def_easize,
476 lmv->max_cookiesize, lmv->max_def_cookiesize);
478 CDEBUG(D_CONFIG, "Connected to %s(%s) successfully (%d)\n",
479 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
480 atomic_read(&obd->obd_refcount));
482 if (lmv->targets_proc_entry != NULL) {
483 struct proc_dir_entry *mdc_symlink;
485 LASSERT(mdc_obd->obd_type != NULL);
486 LASSERT(mdc_obd->obd_type->typ_name != NULL);
487 mdc_symlink = lprocfs_add_symlink(mdc_obd->obd_name,
488 lmv->targets_proc_entry,
490 mdc_obd->obd_type->typ_name,
492 if (mdc_symlink == NULL) {
493 CERROR("Could not register LMV target "
494 "/proc/fs/lustre/%s/%s/target_obds/%s.",
495 obd->obd_type->typ_name, obd->obd_name,
502 static void lmv_del_target(struct lmv_obd *lmv, int index)
504 if (lmv->tgts[index] == NULL)
507 OBD_FREE_PTR(lmv->tgts[index]);
508 lmv->tgts[index] = NULL;
512 static int lmv_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
513 __u32 index, int gen)
515 struct lmv_obd *lmv = &obd->u.lmv;
516 struct lmv_tgt_desc *tgt;
520 CDEBUG(D_CONFIG, "Target uuid: %s. index %d\n", uuidp->uuid, index);
524 if (lmv->desc.ld_tgt_count == 0) {
525 struct obd_device *mdc_obd;
527 mdc_obd = class_find_client_obd(uuidp, LUSTRE_MDC_NAME,
530 lmv_init_unlock(lmv);
531 CERROR("%s: Target %s not attached: rc = %d\n",
532 obd->obd_name, uuidp->uuid, -EINVAL);
537 if ((index < lmv->tgts_size) && (lmv->tgts[index] != NULL)) {
538 tgt = lmv->tgts[index];
539 CERROR("%s: UUID %s already assigned at LOV target index %d:"
540 " rc = %d\n", obd->obd_name,
541 obd_uuid2str(&tgt->ltd_uuid), index, -EEXIST);
542 lmv_init_unlock(lmv);
546 if (index >= lmv->tgts_size) {
547 /* We need to reallocate the lmv target array. */
548 struct lmv_tgt_desc **newtgts, **old = NULL;
552 while (newsize < index + 1)
553 newsize = newsize << 1;
554 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
555 if (newtgts == NULL) {
556 lmv_init_unlock(lmv);
560 if (lmv->tgts_size) {
561 memcpy(newtgts, lmv->tgts,
562 sizeof(*newtgts) * lmv->tgts_size);
564 oldsize = lmv->tgts_size;
568 lmv->tgts_size = newsize;
571 OBD_FREE(old, sizeof(*old) * oldsize);
573 CDEBUG(D_CONFIG, "tgts: %p size: %d\n", lmv->tgts,
579 lmv_init_unlock(lmv);
583 mutex_init(&tgt->ltd_fid_mutex);
584 tgt->ltd_idx = index;
585 tgt->ltd_uuid = *uuidp;
587 lmv->tgts[index] = tgt;
588 if (index >= lmv->desc.ld_tgt_count)
589 lmv->desc.ld_tgt_count = index + 1;
591 if (lmv->connected) {
592 rc = lmv_connect_mdc(obd, tgt);
594 spin_lock(&lmv->lmv_lock);
595 lmv->desc.ld_tgt_count--;
596 memset(tgt, 0, sizeof(*tgt));
597 spin_unlock(&lmv->lmv_lock);
599 int easize = sizeof(struct lmv_stripe_md) +
600 lmv->desc.ld_tgt_count * sizeof(struct lu_fid);
601 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0, 0);
605 lmv_init_unlock(lmv);
609 int lmv_check_connect(struct obd_device *obd)
611 struct lmv_obd *lmv = &obd->u.lmv;
612 struct lmv_tgt_desc *tgt;
622 if (lmv->connected) {
623 lmv_init_unlock(lmv);
627 if (lmv->desc.ld_tgt_count == 0) {
628 lmv_init_unlock(lmv);
629 CERROR("%s: no targets configured.\n", obd->obd_name);
633 LASSERT(lmv->tgts != NULL);
635 if (lmv->tgts[0] == NULL) {
636 lmv_init_unlock(lmv);
637 CERROR("%s: no target configured for index 0.\n",
642 CDEBUG(D_CONFIG, "Time to connect %s to %s\n",
643 lmv->cluuid.uuid, obd->obd_name);
645 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
649 rc = lmv_connect_mdc(obd, tgt);
654 lmv_set_timeouts(obd);
655 class_export_put(lmv->exp);
657 easize = lmv_mds_md_size(lmv->desc.ld_tgt_count, LMV_MAGIC);
658 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0, 0);
659 lmv_init_unlock(lmv);
670 --lmv->desc.ld_active_tgt_count;
671 rc2 = obd_disconnect(tgt->ltd_exp);
673 CERROR("LMV target %s disconnect on "
674 "MDC idx %d: error %d\n",
675 tgt->ltd_uuid.uuid, i, rc2);
679 class_disconnect(lmv->exp);
680 lmv_init_unlock(lmv);
684 static int lmv_disconnect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
686 struct lmv_obd *lmv = &obd->u.lmv;
687 struct obd_device *mdc_obd;
691 LASSERT(tgt != NULL);
692 LASSERT(obd != NULL);
694 mdc_obd = class_exp2obd(tgt->ltd_exp);
697 mdc_obd->obd_force = obd->obd_force;
698 mdc_obd->obd_fail = obd->obd_fail;
699 mdc_obd->obd_no_recov = obd->obd_no_recov;
702 if (lmv->targets_proc_entry != NULL)
703 lprocfs_remove_proc_entry(mdc_obd->obd_name,
704 lmv->targets_proc_entry);
706 rc = obd_fid_fini(tgt->ltd_exp->exp_obd);
708 CERROR("Can't finanize fids factory\n");
710 CDEBUG(D_INFO, "Disconnected from %s(%s) successfully\n",
711 tgt->ltd_exp->exp_obd->obd_name,
712 tgt->ltd_exp->exp_obd->obd_uuid.uuid);
714 obd_register_observer(tgt->ltd_exp->exp_obd, NULL);
715 rc = obd_disconnect(tgt->ltd_exp);
717 if (tgt->ltd_active) {
718 CERROR("Target %s disconnect error %d\n",
719 tgt->ltd_uuid.uuid, rc);
723 lmv_activate_target(lmv, tgt, 0);
728 static int lmv_disconnect(struct obd_export *exp)
730 struct obd_device *obd = class_exp2obd(exp);
731 struct lmv_obd *lmv = &obd->u.lmv;
740 * Only disconnect the underlying layers on the final disconnect.
743 if (lmv->refcount != 0)
746 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
747 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
750 lmv_disconnect_mdc(obd, lmv->tgts[i]);
753 if (lmv->targets_proc_entry != NULL)
754 lprocfs_remove(&lmv->targets_proc_entry);
756 CERROR("/proc/fs/lustre/%s/%s/target_obds missing\n",
757 obd->obd_type->typ_name, obd->obd_name);
761 * This is the case when no real connection is established by
762 * lmv_check_connect().
765 class_export_put(exp);
766 rc = class_disconnect(exp);
767 if (lmv->refcount == 0)
772 static int lmv_fid2path(struct obd_export *exp, int len, void *karg, void *uarg)
774 struct obd_device *obddev = class_exp2obd(exp);
775 struct lmv_obd *lmv = &obddev->u.lmv;
776 struct getinfo_fid2path *gf;
777 struct lmv_tgt_desc *tgt;
778 struct getinfo_fid2path *remote_gf = NULL;
779 int remote_gf_size = 0;
782 gf = (struct getinfo_fid2path *)karg;
783 tgt = lmv_find_target(lmv, &gf->gf_fid);
785 RETURN(PTR_ERR(tgt));
788 rc = obd_iocontrol(OBD_IOC_FID2PATH, tgt->ltd_exp, len, gf, uarg);
789 if (rc != 0 && rc != -EREMOTE)
790 GOTO(out_fid2path, rc);
792 /* If remote_gf != NULL, it means just building the
793 * path on the remote MDT, copy this path segement to gf */
794 if (remote_gf != NULL) {
795 struct getinfo_fid2path *ori_gf;
798 ori_gf = (struct getinfo_fid2path *)karg;
799 if (strlen(ori_gf->gf_path) +
800 strlen(gf->gf_path) > ori_gf->gf_pathlen)
801 GOTO(out_fid2path, rc = -EOVERFLOW);
803 ptr = ori_gf->gf_path;
805 memmove(ptr + strlen(gf->gf_path) + 1, ptr,
806 strlen(ori_gf->gf_path));
808 strncpy(ptr, gf->gf_path, strlen(gf->gf_path));
809 ptr += strlen(gf->gf_path);
813 CDEBUG(D_INFO, "%s: get path %s "DFID" rec: "LPU64" ln: %u\n",
814 tgt->ltd_exp->exp_obd->obd_name,
815 gf->gf_path, PFID(&gf->gf_fid), gf->gf_recno,
819 GOTO(out_fid2path, rc);
821 /* sigh, has to go to another MDT to do path building further */
822 if (remote_gf == NULL) {
823 remote_gf_size = sizeof(*remote_gf) + PATH_MAX;
824 OBD_ALLOC(remote_gf, remote_gf_size);
825 if (remote_gf == NULL)
826 GOTO(out_fid2path, rc = -ENOMEM);
827 remote_gf->gf_pathlen = PATH_MAX;
830 if (!fid_is_sane(&gf->gf_fid)) {
831 CERROR("%s: invalid FID "DFID": rc = %d\n",
832 tgt->ltd_exp->exp_obd->obd_name,
833 PFID(&gf->gf_fid), -EINVAL);
834 GOTO(out_fid2path, rc = -EINVAL);
837 tgt = lmv_find_target(lmv, &gf->gf_fid);
839 GOTO(out_fid2path, rc = -EINVAL);
841 remote_gf->gf_fid = gf->gf_fid;
842 remote_gf->gf_recno = -1;
843 remote_gf->gf_linkno = -1;
844 memset(remote_gf->gf_path, 0, remote_gf->gf_pathlen);
846 goto repeat_fid2path;
849 if (remote_gf != NULL)
850 OBD_FREE(remote_gf, remote_gf_size);
854 static int lmv_hsm_req_count(struct lmv_obd *lmv,
855 const struct hsm_user_request *hur,
856 const struct lmv_tgt_desc *tgt_mds)
860 struct lmv_tgt_desc *curr_tgt;
862 /* count how many requests must be sent to the given target */
863 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
864 curr_tgt = lmv_find_target(lmv, &hur->hur_user_item[i].hui_fid);
865 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid))
871 static void lmv_hsm_req_build(struct lmv_obd *lmv,
872 struct hsm_user_request *hur_in,
873 const struct lmv_tgt_desc *tgt_mds,
874 struct hsm_user_request *hur_out)
877 struct lmv_tgt_desc *curr_tgt;
879 /* build the hsm_user_request for the given target */
880 hur_out->hur_request = hur_in->hur_request;
882 for (i = 0; i < hur_in->hur_request.hr_itemcount; i++) {
883 curr_tgt = lmv_find_target(lmv,
884 &hur_in->hur_user_item[i].hui_fid);
885 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid)) {
886 hur_out->hur_user_item[nr_out] =
887 hur_in->hur_user_item[i];
891 hur_out->hur_request.hr_itemcount = nr_out;
892 memcpy(hur_data(hur_out), hur_data(hur_in),
893 hur_in->hur_request.hr_data_len);
896 static int lmv_hsm_ct_unregister(struct lmv_obd *lmv, unsigned int cmd, int len,
897 struct lustre_kernelcomm *lk, void *uarg)
901 struct kkuc_ct_data *kcd = NULL;
904 /* unregister request (call from llapi_hsm_copytool_fini) */
905 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
906 struct lmv_tgt_desc *tgt = lmv->tgts[i];
908 if (tgt == NULL || tgt->ltd_exp == NULL)
910 /* best effort: try to clean as much as possible
911 * (continue on error) */
912 obd_iocontrol(cmd, tgt->ltd_exp, len, lk, uarg);
915 /* Whatever the result, remove copytool from kuc groups.
916 * Unreached coordinators will get EPIPE on next requests
917 * and will unregister automatically.
919 rc = libcfs_kkuc_group_rem(lk->lk_uid, lk->lk_group, (void **)&kcd);
926 static int lmv_hsm_ct_register(struct lmv_obd *lmv, unsigned int cmd, int len,
927 struct lustre_kernelcomm *lk, void *uarg)
932 bool any_set = false;
933 struct kkuc_ct_data *kcd;
936 /* All or nothing: try to register to all MDS.
937 * In case of failure, unregister from previous MDS,
938 * except if it because of inactive target. */
939 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
940 struct lmv_tgt_desc *tgt = lmv->tgts[i];
942 if (tgt == NULL || tgt->ltd_exp == NULL)
944 err = obd_iocontrol(cmd, tgt->ltd_exp, len, lk, uarg);
946 if (tgt->ltd_active) {
947 /* permanent error */
948 CERROR("%s: iocontrol MDC %s on MDT"
949 " idx %d cmd %x: err = %d\n",
950 class_exp2obd(lmv->exp)->obd_name,
951 tgt->ltd_uuid.uuid, i, cmd, err);
953 lk->lk_flags |= LK_FLG_STOP;
954 /* unregister from previous MDS */
955 for (j = 0; j < i; j++) {
957 if (tgt == NULL || tgt->ltd_exp == NULL)
959 obd_iocontrol(cmd, tgt->ltd_exp, len,
964 /* else: transient error.
965 * kuc will register to the missing MDT
973 /* no registration done: return error */
976 /* at least one registration done, with no failure */
977 filp = fget(lk->lk_wfd);
986 kcd->kcd_magic = KKUC_CT_DATA_MAGIC;
987 kcd->kcd_uuid = lmv->cluuid;
988 kcd->kcd_archive = lk->lk_data;
990 rc = libcfs_kkuc_group_add(filp, lk->lk_uid, lk->lk_group, kcd);
1003 static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
1004 int len, void *karg, void *uarg)
1006 struct obd_device *obddev = class_exp2obd(exp);
1007 struct lmv_obd *lmv = &obddev->u.lmv;
1008 struct lmv_tgt_desc *tgt = NULL;
1012 __u32 count = lmv->desc.ld_tgt_count;
1019 case IOC_OBD_STATFS: {
1020 struct obd_ioctl_data *data = karg;
1021 struct obd_device *mdc_obd;
1022 struct obd_statfs stat_buf = {0};
1025 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
1026 if ((index >= count))
1029 tgt = lmv->tgts[index];
1030 if (tgt == NULL || !tgt->ltd_active)
1033 mdc_obd = class_exp2obd(tgt->ltd_exp);
1038 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(mdc_obd),
1039 min((int) data->ioc_plen2,
1040 (int) sizeof(struct obd_uuid))))
1043 rc = obd_statfs(NULL, tgt->ltd_exp, &stat_buf,
1044 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1048 if (copy_to_user(data->ioc_pbuf1, &stat_buf,
1049 min((int) data->ioc_plen1,
1050 (int) sizeof(stat_buf))))
1054 case OBD_IOC_QUOTACTL: {
1055 struct if_quotactl *qctl = karg;
1056 struct obd_quotactl *oqctl;
1058 if (qctl->qc_valid == QC_MDTIDX) {
1059 if (count <= qctl->qc_idx)
1062 tgt = lmv->tgts[qctl->qc_idx];
1063 if (tgt == NULL || tgt->ltd_exp == NULL)
1065 } else if (qctl->qc_valid == QC_UUID) {
1066 for (i = 0; i < count; i++) {
1070 if (!obd_uuid_equals(&tgt->ltd_uuid,
1074 if (tgt->ltd_exp == NULL)
1086 LASSERT(tgt != NULL && tgt->ltd_exp != NULL);
1087 OBD_ALLOC_PTR(oqctl);
1091 QCTL_COPY(oqctl, qctl);
1092 rc = obd_quotactl(tgt->ltd_exp, oqctl);
1094 QCTL_COPY(qctl, oqctl);
1095 qctl->qc_valid = QC_MDTIDX;
1096 qctl->obd_uuid = tgt->ltd_uuid;
1098 OBD_FREE_PTR(oqctl);
1101 case OBD_IOC_CHANGELOG_SEND:
1102 case OBD_IOC_CHANGELOG_CLEAR: {
1103 struct ioc_changelog *icc = karg;
1105 if (icc->icc_mdtindex >= count)
1108 tgt = lmv->tgts[icc->icc_mdtindex];
1109 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
1111 rc = obd_iocontrol(cmd, tgt->ltd_exp, sizeof(*icc), icc, NULL);
1114 case LL_IOC_GET_CONNECT_FLAGS: {
1116 if (tgt == NULL || tgt->ltd_exp == NULL)
1118 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1121 case OBD_IOC_FID2PATH: {
1122 rc = lmv_fid2path(exp, len, karg, uarg);
1125 case LL_IOC_HSM_STATE_GET:
1126 case LL_IOC_HSM_STATE_SET:
1127 case LL_IOC_HSM_ACTION: {
1128 struct md_op_data *op_data = karg;
1130 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1132 RETURN(PTR_ERR(tgt));
1134 if (tgt->ltd_exp == NULL)
1137 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1140 case LL_IOC_HSM_PROGRESS: {
1141 const struct hsm_progress_kernel *hpk = karg;
1143 tgt = lmv_find_target(lmv, &hpk->hpk_fid);
1145 RETURN(PTR_ERR(tgt));
1146 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1149 case LL_IOC_HSM_REQUEST: {
1150 struct hsm_user_request *hur = karg;
1151 unsigned int reqcount = hur->hur_request.hr_itemcount;
1156 /* if the request is about a single fid
1157 * or if there is a single MDS, no need to split
1159 if (reqcount == 1 || count == 1) {
1160 tgt = lmv_find_target(lmv,
1161 &hur->hur_user_item[0].hui_fid);
1163 RETURN(PTR_ERR(tgt));
1164 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1166 /* split fid list to their respective MDS */
1167 for (i = 0; i < count; i++) {
1168 unsigned int nr, reqlen;
1170 struct hsm_user_request *req;
1173 if (tgt == NULL || tgt->ltd_exp == NULL)
1176 nr = lmv_hsm_req_count(lmv, hur, tgt);
1177 if (nr == 0) /* nothing for this MDS */
1180 /* build a request with fids for this MDS */
1181 reqlen = offsetof(typeof(*hur),
1183 + hur->hur_request.hr_data_len;
1184 OBD_ALLOC_LARGE(req, reqlen);
1188 lmv_hsm_req_build(lmv, hur, tgt, req);
1190 rc1 = obd_iocontrol(cmd, tgt->ltd_exp, reqlen,
1192 if (rc1 != 0 && rc == 0)
1194 OBD_FREE_LARGE(req, reqlen);
1199 case LL_IOC_LOV_SWAP_LAYOUTS: {
1200 struct md_op_data *op_data = karg;
1201 struct lmv_tgt_desc *tgt1, *tgt2;
1203 tgt1 = lmv_find_target(lmv, &op_data->op_fid1);
1205 RETURN(PTR_ERR(tgt1));
1207 tgt2 = lmv_find_target(lmv, &op_data->op_fid2);
1209 RETURN(PTR_ERR(tgt2));
1211 if ((tgt1->ltd_exp == NULL) || (tgt2->ltd_exp == NULL))
1214 /* only files on same MDT can have their layouts swapped */
1215 if (tgt1->ltd_idx != tgt2->ltd_idx)
1218 rc = obd_iocontrol(cmd, tgt1->ltd_exp, len, karg, uarg);
1221 case LL_IOC_HSM_CT_START: {
1222 struct lustre_kernelcomm *lk = karg;
1223 if (lk->lk_flags & LK_FLG_STOP)
1224 rc = lmv_hsm_ct_unregister(lmv, cmd, len, lk, uarg);
1226 rc = lmv_hsm_ct_register(lmv, cmd, len, lk, uarg);
1230 for (i = 0; i < count; i++) {
1231 struct obd_device *mdc_obd;
1235 if (tgt == NULL || tgt->ltd_exp == NULL)
1237 /* ll_umount_begin() sets force flag but for lmv, not
1238 * mdc. Let's pass it through */
1239 mdc_obd = class_exp2obd(tgt->ltd_exp);
1240 mdc_obd->obd_force = obddev->obd_force;
1241 err = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1242 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
1245 if (tgt->ltd_active) {
1246 CERROR("error: iocontrol MDC %s on MDT"
1247 " idx %d cmd %x: err = %d\n",
1248 tgt->ltd_uuid.uuid, i, cmd, err);
1262 static int lmv_all_chars_policy(int count, const char *name,
1273 static int lmv_nid_policy(struct lmv_obd *lmv)
1275 struct obd_import *imp;
1279 * XXX: To get nid we assume that underlying obd device is mdc.
1281 imp = class_exp2cliimp(lmv->tgts[0].ltd_exp);
1282 id = imp->imp_connection->c_self ^ (imp->imp_connection->c_self >> 32);
1283 return id % lmv->desc.ld_tgt_count;
1286 static int lmv_choose_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1287 placement_policy_t placement)
1289 switch (placement) {
1290 case PLACEMENT_CHAR_POLICY:
1291 return lmv_all_chars_policy(lmv->desc.ld_tgt_count,
1293 op_data->op_namelen);
1294 case PLACEMENT_NID_POLICY:
1295 return lmv_nid_policy(lmv);
1301 CERROR("Unsupported placement policy %x\n", placement);
1307 * This is _inode_ placement policy function (not name).
1309 static int lmv_placement_policy(struct obd_device *obd,
1310 struct md_op_data *op_data,
1313 struct lmv_obd *lmv = &obd->u.lmv;
1316 LASSERT(mds != NULL);
1318 if (lmv->desc.ld_tgt_count == 1) {
1324 * If stripe_offset is provided during setdirstripe
1325 * (setdirstripe -i xx), xx MDS will be choosen.
1327 if (op_data->op_cli_flags & CLI_SET_MEA && op_data->op_data != NULL) {
1328 struct lmv_user_md *lum;
1330 lum = op_data->op_data;
1332 if (le32_to_cpu(lum->lum_stripe_offset) != (__u32)-1) {
1333 *mds = le32_to_cpu(lum->lum_stripe_offset);
1335 /* -1 means default, which will be in the same MDT with
1337 *mds = op_data->op_mds;
1338 lum->lum_stripe_offset = cpu_to_le32(op_data->op_mds);
1341 /* Allocate new fid on target according to operation type and
1342 * parent home mds. */
1343 *mds = op_data->op_mds;
1349 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid,
1352 struct lmv_tgt_desc *tgt;
1356 tgt = lmv_get_target(lmv, mds);
1358 RETURN(PTR_ERR(tgt));
1361 * New seq alloc and FLD setup should be atomic. Otherwise we may find
1362 * on server that seq in new allocated fid is not yet known.
1364 mutex_lock(&tgt->ltd_fid_mutex);
1366 if (tgt->ltd_active == 0 || tgt->ltd_exp == NULL)
1367 GOTO(out, rc = -ENODEV);
1370 * Asking underlying tgt layer to allocate new fid.
1372 rc = obd_fid_alloc(NULL, tgt->ltd_exp, fid, NULL);
1374 LASSERT(fid_is_sane(fid));
1380 mutex_unlock(&tgt->ltd_fid_mutex);
1384 int lmv_fid_alloc(const struct lu_env *env, struct obd_export *exp,
1385 struct lu_fid *fid, struct md_op_data *op_data)
1387 struct obd_device *obd = class_exp2obd(exp);
1388 struct lmv_obd *lmv = &obd->u.lmv;
1393 LASSERT(op_data != NULL);
1394 LASSERT(fid != NULL);
1396 rc = lmv_placement_policy(obd, op_data, &mds);
1398 CERROR("Can't get target for allocating fid, "
1403 rc = __lmv_fid_alloc(lmv, fid, mds);
1405 CERROR("Can't alloc new fid, rc %d\n", rc);
1412 static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
1414 struct lmv_obd *lmv = &obd->u.lmv;
1415 struct lmv_desc *desc;
1419 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
1420 CERROR("LMV setup requires a descriptor\n");
1424 desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1);
1425 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
1426 CERROR("Lmv descriptor size wrong: %d > %d\n",
1427 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
1431 OBD_ALLOC(lmv->tgts, sizeof(*lmv->tgts) * 32);
1432 if (lmv->tgts == NULL)
1434 lmv->tgts_size = 32;
1436 obd_str2uuid(&lmv->desc.ld_uuid, desc->ld_uuid.uuid);
1437 lmv->desc.ld_tgt_count = 0;
1438 lmv->desc.ld_active_tgt_count = 0;
1439 lmv->max_cookiesize = 0;
1440 lmv->max_def_easize = 0;
1441 lmv->max_easize = 0;
1442 lmv->lmv_placement = PLACEMENT_CHAR_POLICY;
1444 spin_lock_init(&lmv->lmv_lock);
1445 mutex_init(&lmv->init_mutex);
1448 obd->obd_vars = lprocfs_lmv_obd_vars;
1449 lprocfs_seq_obd_setup(obd);
1450 lprocfs_alloc_md_stats(obd, 0);
1451 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
1452 0444, &lmv_proc_target_fops, obd);
1454 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
1457 rc = fld_client_init(&lmv->lmv_fld, obd->obd_name,
1458 LUSTRE_CLI_FLD_HASH_DHT);
1460 CERROR("Can't init FLD, err %d\n", rc);
1470 static int lmv_cleanup(struct obd_device *obd)
1472 struct lmv_obd *lmv = &obd->u.lmv;
1475 fld_client_fini(&lmv->lmv_fld);
1476 if (lmv->tgts != NULL) {
1478 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1479 if (lmv->tgts[i] == NULL)
1481 lmv_del_target(lmv, i);
1483 OBD_FREE(lmv->tgts, sizeof(*lmv->tgts) * lmv->tgts_size);
1489 static int lmv_process_config(struct obd_device *obd, obd_count len, void *buf)
1491 struct lustre_cfg *lcfg = buf;
1492 struct obd_uuid obd_uuid;
1498 switch (lcfg->lcfg_command) {
1500 /* modify_mdc_tgts add 0:lustre-clilmv 1:lustre-MDT0000_UUID
1501 * 2:0 3:1 4:lustre-MDT0000-mdc_UUID */
1502 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
1503 GOTO(out, rc = -EINVAL);
1505 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
1507 if (sscanf(lustre_cfg_buf(lcfg, 2), "%u", &index) != 1)
1508 GOTO(out, rc = -EINVAL);
1509 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
1510 GOTO(out, rc = -EINVAL);
1511 rc = lmv_add_target(obd, &obd_uuid, index, gen);
1514 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1515 GOTO(out, rc = -EINVAL);
1521 static int lmv_statfs(const struct lu_env *env, struct obd_export *exp,
1522 struct obd_statfs *osfs, __u64 max_age, __u32 flags)
1524 struct obd_device *obd = class_exp2obd(exp);
1525 struct lmv_obd *lmv = &obd->u.lmv;
1526 struct obd_statfs *temp;
1531 rc = lmv_check_connect(obd);
1535 OBD_ALLOC(temp, sizeof(*temp));
1539 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1540 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1543 rc = obd_statfs(env, lmv->tgts[i]->ltd_exp, temp,
1546 CERROR("can't stat MDS #%d (%s), error %d\n", i,
1547 lmv->tgts[i]->ltd_exp->exp_obd->obd_name,
1549 GOTO(out_free_temp, rc);
1554 /* If the statfs is from mount, it will needs
1555 * retrieve necessary information from MDT0.
1556 * i.e. mount does not need the merged osfs
1558 * And also clients can be mounted as long as
1559 * MDT0 is in service*/
1560 if (flags & OBD_STATFS_FOR_MDT0)
1561 GOTO(out_free_temp, rc);
1563 osfs->os_bavail += temp->os_bavail;
1564 osfs->os_blocks += temp->os_blocks;
1565 osfs->os_ffree += temp->os_ffree;
1566 osfs->os_files += temp->os_files;
1572 OBD_FREE(temp, sizeof(*temp));
1576 static int lmv_getstatus(struct obd_export *exp,
1578 struct obd_capa **pc)
1580 struct obd_device *obd = exp->exp_obd;
1581 struct lmv_obd *lmv = &obd->u.lmv;
1585 rc = lmv_check_connect(obd);
1589 rc = md_getstatus(lmv->tgts[0]->ltd_exp, fid, pc);
1593 static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1594 struct obd_capa *oc, obd_valid valid, const char *name,
1595 const char *input, int input_size, int output_size,
1596 int flags, struct ptlrpc_request **request)
1598 struct obd_device *obd = exp->exp_obd;
1599 struct lmv_obd *lmv = &obd->u.lmv;
1600 struct lmv_tgt_desc *tgt;
1604 rc = lmv_check_connect(obd);
1608 tgt = lmv_find_target(lmv, fid);
1610 RETURN(PTR_ERR(tgt));
1612 rc = md_getxattr(tgt->ltd_exp, fid, oc, valid, name, input,
1613 input_size, output_size, flags, request);
1618 static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1619 struct obd_capa *oc, obd_valid valid, const char *name,
1620 const char *input, int input_size, int output_size,
1621 int flags, __u32 suppgid,
1622 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_setxattr(tgt->ltd_exp, fid, oc, valid, name, input,
1639 input_size, output_size, flags, suppgid,
1645 static int lmv_getattr(struct obd_export *exp, struct md_op_data *op_data,
1646 struct ptlrpc_request **request)
1648 struct obd_device *obd = exp->exp_obd;
1649 struct lmv_obd *lmv = &obd->u.lmv;
1650 struct lmv_tgt_desc *tgt;
1654 rc = lmv_check_connect(obd);
1658 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1660 RETURN(PTR_ERR(tgt));
1662 if (op_data->op_flags & MF_GET_MDT_IDX) {
1663 op_data->op_mds = tgt->ltd_idx;
1667 rc = md_getattr(tgt->ltd_exp, op_data, request);
1672 static int lmv_null_inode(struct obd_export *exp, const struct lu_fid *fid)
1674 struct obd_device *obd = exp->exp_obd;
1675 struct lmv_obd *lmv = &obd->u.lmv;
1680 rc = lmv_check_connect(obd);
1684 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1687 * With DNE every object can have two locks in different namespaces:
1688 * lookup lock in space of MDT storing direntry and update/open lock in
1689 * space of MDT storing inode.
1691 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1692 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1694 md_null_inode(lmv->tgts[i]->ltd_exp, fid);
1700 static int lmv_find_cbdata(struct obd_export *exp, const struct lu_fid *fid,
1701 ldlm_iterator_t it, void *data)
1703 struct obd_device *obd = exp->exp_obd;
1704 struct lmv_obd *lmv = &obd->u.lmv;
1709 rc = lmv_check_connect(obd);
1713 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1716 * With DNE every object can have two locks in different namespaces:
1717 * lookup lock in space of MDT storing direntry and update/open lock in
1718 * space of MDT storing inode.
1720 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1721 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1723 rc = md_find_cbdata(lmv->tgts[i]->ltd_exp, fid, it, data);
1732 static int lmv_close(struct obd_export *exp, struct md_op_data *op_data,
1733 struct md_open_data *mod, struct ptlrpc_request **request)
1735 struct obd_device *obd = exp->exp_obd;
1736 struct lmv_obd *lmv = &obd->u.lmv;
1737 struct lmv_tgt_desc *tgt;
1741 rc = lmv_check_connect(obd);
1745 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1747 RETURN(PTR_ERR(tgt));
1749 CDEBUG(D_INODE, "CLOSE "DFID"\n", PFID(&op_data->op_fid1));
1750 rc = md_close(tgt->ltd_exp, op_data, mod, request);
1755 * Choosing the MDT by name or FID in @op_data.
1756 * For non-striped directory, it will locate MDT by fid.
1757 * For striped-directory, it will locate MDT by name. And also
1758 * it will reset op_fid1 with the FID of the choosen stripe.
1760 struct lmv_tgt_desc *
1761 lmv_locate_target_for_name(struct lmv_obd *lmv, struct lmv_stripe_md *lsm,
1762 const char *name, int namelen, struct lu_fid *fid,
1765 struct lmv_tgt_desc *tgt;
1766 const struct lmv_oinfo *oinfo;
1768 oinfo = lsm_name_to_stripe_info(lsm, name, namelen);
1770 RETURN((void *)oinfo);
1771 *fid = oinfo->lmo_fid;
1772 *mds = oinfo->lmo_mds;
1773 tgt = lmv_get_target(lmv, *mds);
1775 CDEBUG(D_INFO, "locate on mds %u "DFID"\n", *mds, PFID(fid));
1780 *lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1783 struct lmv_stripe_md *lsm = op_data->op_mea1;
1784 struct lmv_tgt_desc *tgt;
1786 if (lsm == NULL || op_data->op_namelen == 0) {
1787 tgt = lmv_find_target(lmv, fid);
1791 op_data->op_mds = tgt->ltd_idx;
1795 return lmv_locate_target_for_name(lmv, lsm, op_data->op_name,
1796 op_data->op_namelen, fid,
1800 int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
1801 const void *data, int datalen, int mode, __u32 uid,
1802 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1803 struct ptlrpc_request **request)
1805 struct obd_device *obd = exp->exp_obd;
1806 struct lmv_obd *lmv = &obd->u.lmv;
1807 struct lmv_tgt_desc *tgt;
1811 rc = lmv_check_connect(obd);
1815 if (!lmv->desc.ld_active_tgt_count)
1818 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1820 RETURN(PTR_ERR(tgt));
1822 CDEBUG(D_INODE, "CREATE name '%.*s' on "DFID" -> mds #%x\n",
1823 op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1),
1826 rc = lmv_fid_alloc(NULL, exp, &op_data->op_fid2, op_data);
1830 /* Send the create request to the MDT where the object
1831 * will be located */
1832 tgt = lmv_find_target(lmv, &op_data->op_fid2);
1834 RETURN(PTR_ERR(tgt));
1836 op_data->op_mds = tgt->ltd_idx;
1838 CDEBUG(D_INODE, "CREATE obj "DFID" -> mds #%x\n",
1839 PFID(&op_data->op_fid2), op_data->op_mds);
1841 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1842 rc = md_create(tgt->ltd_exp, op_data, data, datalen, mode, uid, gid,
1843 cap_effective, rdev, request);
1845 if (*request == NULL)
1847 CDEBUG(D_INODE, "Created - "DFID"\n", PFID(&op_data->op_fid2));
1852 static int lmv_done_writing(struct obd_export *exp,
1853 struct md_op_data *op_data,
1854 struct md_open_data *mod)
1856 struct obd_device *obd = exp->exp_obd;
1857 struct lmv_obd *lmv = &obd->u.lmv;
1858 struct lmv_tgt_desc *tgt;
1862 rc = lmv_check_connect(obd);
1866 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1868 RETURN(PTR_ERR(tgt));
1870 rc = md_done_writing(tgt->ltd_exp, op_data, mod);
1875 lmv_enqueue_remote(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1876 struct lookup_intent *it, struct md_op_data *op_data,
1877 struct lustre_handle *lockh, void *lmm, int lmmsize,
1878 __u64 extra_lock_flags)
1880 struct ptlrpc_request *req = it->d.lustre.it_data;
1881 struct obd_device *obd = exp->exp_obd;
1882 struct lmv_obd *lmv = &obd->u.lmv;
1883 struct lustre_handle plock;
1884 struct lmv_tgt_desc *tgt;
1885 struct md_op_data *rdata;
1887 struct mdt_body *body;
1892 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1893 LASSERT(body != NULL);
1895 if (!(body->valid & OBD_MD_MDS))
1898 CDEBUG(D_INODE, "REMOTE_ENQUEUE '%s' on "DFID" -> "DFID"\n",
1899 LL_IT2STR(it), PFID(&op_data->op_fid1), PFID(&body->fid1));
1902 * We got LOOKUP lock, but we really need attrs.
1904 pmode = it->d.lustre.it_lock_mode;
1905 LASSERT(pmode != 0);
1906 memcpy(&plock, lockh, sizeof(plock));
1907 it->d.lustre.it_lock_mode = 0;
1908 it->d.lustre.it_data = NULL;
1911 ptlrpc_req_finished(req);
1913 tgt = lmv_find_target(lmv, &fid1);
1915 GOTO(out, rc = PTR_ERR(tgt));
1917 OBD_ALLOC_PTR(rdata);
1919 GOTO(out, rc = -ENOMEM);
1921 rdata->op_fid1 = fid1;
1922 rdata->op_bias = MDS_CROSS_REF;
1924 rc = md_enqueue(tgt->ltd_exp, einfo, it, rdata, lockh,
1925 lmm, lmmsize, NULL, extra_lock_flags);
1926 OBD_FREE_PTR(rdata);
1929 ldlm_lock_decref(&plock, pmode);
1934 lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1935 struct lookup_intent *it, struct md_op_data *op_data,
1936 struct lustre_handle *lockh, void *lmm, int lmmsize,
1937 struct ptlrpc_request **req, __u64 extra_lock_flags)
1939 struct obd_device *obd = exp->exp_obd;
1940 struct lmv_obd *lmv = &obd->u.lmv;
1941 struct lmv_tgt_desc *tgt;
1945 rc = lmv_check_connect(obd);
1949 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID"\n",
1950 LL_IT2STR(it), PFID(&op_data->op_fid1));
1952 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1954 RETURN(PTR_ERR(tgt));
1956 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID" -> mds #%d\n",
1957 LL_IT2STR(it), PFID(&op_data->op_fid1), tgt->ltd_idx);
1959 rc = md_enqueue(tgt->ltd_exp, einfo, it, op_data, lockh,
1960 lmm, lmmsize, req, extra_lock_flags);
1962 if (rc == 0 && it && it->it_op == IT_OPEN) {
1963 rc = lmv_enqueue_remote(exp, einfo, it, op_data, lockh,
1964 lmm, lmmsize, extra_lock_flags);
1970 lmv_getattr_name(struct obd_export *exp,struct md_op_data *op_data,
1971 struct ptlrpc_request **preq)
1973 struct ptlrpc_request *req = NULL;
1974 struct obd_device *obd = exp->exp_obd;
1975 struct lmv_obd *lmv = &obd->u.lmv;
1976 struct lmv_tgt_desc *tgt;
1977 struct mdt_body *body;
1981 rc = lmv_check_connect(obd);
1985 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1987 RETURN(PTR_ERR(tgt));
1989 CDEBUG(D_INODE, "GETATTR_NAME for %*s on "DFID" -> mds #%d\n",
1990 op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1),
1993 rc = md_getattr_name(tgt->ltd_exp, op_data, preq);
1997 body = req_capsule_server_get(&(*preq)->rq_pill, &RMF_MDT_BODY);
1998 LASSERT(body != NULL);
2000 if (body->valid & OBD_MD_MDS) {
2001 struct lu_fid rid = body->fid1;
2002 CDEBUG(D_INODE, "Request attrs for "DFID"\n",
2005 tgt = lmv_find_target(lmv, &rid);
2007 ptlrpc_req_finished(*preq);
2009 RETURN(PTR_ERR(tgt));
2012 op_data->op_fid1 = rid;
2013 op_data->op_valid |= OBD_MD_FLCROSSREF;
2014 op_data->op_namelen = 0;
2015 op_data->op_name = NULL;
2016 rc = md_getattr_name(tgt->ltd_exp, op_data, &req);
2017 ptlrpc_req_finished(*preq);
2024 #define md_op_data_fid(op_data, fl) \
2025 (fl == MF_MDC_CANCEL_FID1 ? &op_data->op_fid1 : \
2026 fl == MF_MDC_CANCEL_FID2 ? &op_data->op_fid2 : \
2027 fl == MF_MDC_CANCEL_FID3 ? &op_data->op_fid3 : \
2028 fl == MF_MDC_CANCEL_FID4 ? &op_data->op_fid4 : \
2031 static int lmv_early_cancel(struct obd_export *exp, struct lmv_tgt_desc *tgt,
2032 struct md_op_data *op_data,
2033 int op_tgt, ldlm_mode_t mode, int bits, int flag)
2035 struct lu_fid *fid = md_op_data_fid(op_data, flag);
2036 struct obd_device *obd = exp->exp_obd;
2037 struct lmv_obd *lmv = &obd->u.lmv;
2038 ldlm_policy_data_t policy = {{ 0 }};
2042 if (!fid_is_sane(fid))
2046 tgt = lmv_find_target(lmv, fid);
2048 RETURN(PTR_ERR(tgt));
2051 if (tgt->ltd_idx != op_tgt) {
2052 CDEBUG(D_INODE, "EARLY_CANCEL on "DFID"\n", PFID(fid));
2053 policy.l_inodebits.bits = bits;
2054 rc = md_cancel_unused(tgt->ltd_exp, fid, &policy,
2055 mode, LCF_ASYNC, NULL);
2058 "EARLY_CANCEL skip operation target %d on "DFID"\n",
2060 op_data->op_flags |= flag;
2068 * llite passes fid of an target inode in op_data->op_fid1 and id of directory in
2071 static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
2072 struct ptlrpc_request **request)
2074 struct obd_device *obd = exp->exp_obd;
2075 struct lmv_obd *lmv = &obd->u.lmv;
2076 struct lmv_tgt_desc *tgt;
2080 rc = lmv_check_connect(obd);
2084 LASSERT(op_data->op_namelen != 0);
2086 CDEBUG(D_INODE, "LINK "DFID":%*s to "DFID"\n",
2087 PFID(&op_data->op_fid2), op_data->op_namelen,
2088 op_data->op_name, PFID(&op_data->op_fid1));
2090 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
2091 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
2092 op_data->op_cap = cfs_curproc_cap_pack();
2093 if (op_data->op_mea2 != NULL) {
2094 struct lmv_stripe_md *lsm = op_data->op_mea2;
2095 const struct lmv_oinfo *oinfo;
2097 oinfo = lsm_name_to_stripe_info(lsm, op_data->op_name,
2098 op_data->op_namelen);
2100 RETURN(PTR_ERR(oinfo));
2102 op_data->op_fid2 = oinfo->lmo_fid;
2105 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
2107 RETURN(PTR_ERR(tgt));
2110 * Cancel UPDATE lock on child (fid1).
2112 op_data->op_flags |= MF_MDC_CANCEL_FID2;
2113 rc = lmv_early_cancel(exp, NULL, op_data, tgt->ltd_idx, LCK_EX,
2114 MDS_INODELOCK_UPDATE, MF_MDC_CANCEL_FID1);
2118 rc = md_link(tgt->ltd_exp, op_data, request);
2123 static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
2124 const char *old, int oldlen, const char *new, int newlen,
2125 struct ptlrpc_request **request)
2127 struct obd_device *obd = exp->exp_obd;
2128 struct lmv_obd *lmv = &obd->u.lmv;
2129 struct lmv_tgt_desc *src_tgt;
2133 LASSERT(oldlen != 0);
2135 CDEBUG(D_INODE, "RENAME %.*s in "DFID":%d to %.*s in "DFID":%d\n",
2136 oldlen, old, PFID(&op_data->op_fid1),
2137 op_data->op_mea1 ? op_data->op_mea1->lsm_md_stripe_count : 0,
2138 newlen, new, PFID(&op_data->op_fid2),
2139 op_data->op_mea2 ? op_data->op_mea2->lsm_md_stripe_count : 0);
2141 rc = lmv_check_connect(obd);
2145 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
2146 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
2147 op_data->op_cap = cfs_curproc_cap_pack();
2148 if (op_data->op_cli_flags & CLI_MIGRATE) {
2149 LASSERTF(fid_is_sane(&op_data->op_fid3), "invalid FID "DFID"\n",
2150 PFID(&op_data->op_fid3));
2151 rc = lmv_fid_alloc(NULL, exp, &op_data->op_fid2, op_data);
2154 src_tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid3);
2156 if (op_data->op_mea1 != NULL) {
2157 struct lmv_stripe_md *lsm = op_data->op_mea1;
2159 src_tgt = lmv_locate_target_for_name(lmv, lsm, old,
2163 if (IS_ERR(src_tgt))
2164 RETURN(PTR_ERR(src_tgt));
2166 src_tgt = lmv_find_target(lmv, &op_data->op_fid1);
2167 if (IS_ERR(src_tgt))
2168 RETURN(PTR_ERR(src_tgt));
2170 op_data->op_mds = src_tgt->ltd_idx;
2173 if (op_data->op_mea2) {
2174 struct lmv_stripe_md *lsm = op_data->op_mea2;
2175 const struct lmv_oinfo *oinfo;
2177 oinfo = lsm_name_to_stripe_info(lsm, new, newlen);
2179 RETURN(PTR_ERR(oinfo));
2181 op_data->op_fid2 = oinfo->lmo_fid;
2184 if (IS_ERR(src_tgt))
2185 RETURN(PTR_ERR(src_tgt));
2188 * LOOKUP lock on src child (fid3) should also be cancelled for
2189 * src_tgt in mdc_rename.
2191 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2194 * Cancel UPDATE locks on tgt parent (fid2), tgt_tgt is its
2197 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
2198 LCK_EX, MDS_INODELOCK_UPDATE,
2199 MF_MDC_CANCEL_FID2);
2204 * Cancel LOOKUP locks on source child (fid3) for parent tgt_tgt.
2206 if (fid_is_sane(&op_data->op_fid3)) {
2207 struct lmv_tgt_desc *tgt;
2209 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2211 RETURN(PTR_ERR(tgt));
2213 /* Cancel LOOKUP lock on its parent */
2214 rc = lmv_early_cancel(exp, tgt, op_data, src_tgt->ltd_idx,
2215 LCK_EX, MDS_INODELOCK_LOOKUP,
2216 MF_MDC_CANCEL_FID3);
2220 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
2221 LCK_EX, MDS_INODELOCK_FULL,
2222 MF_MDC_CANCEL_FID3);
2228 * Cancel all the locks on tgt child (fid4).
2230 if (fid_is_sane(&op_data->op_fid4))
2231 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
2232 LCK_EX, MDS_INODELOCK_FULL,
2233 MF_MDC_CANCEL_FID4);
2235 CDEBUG(D_INODE, DFID":m%d to "DFID"\n", PFID(&op_data->op_fid1),
2236 op_data->op_mds, PFID(&op_data->op_fid2));
2238 rc = md_rename(src_tgt->ltd_exp, op_data, old, oldlen, new, newlen,
2244 static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
2245 void *ea, int ealen, void *ea2, int ea2len,
2246 struct ptlrpc_request **request,
2247 struct md_open_data **mod)
2249 struct obd_device *obd = exp->exp_obd;
2250 struct lmv_obd *lmv = &obd->u.lmv;
2251 struct lmv_tgt_desc *tgt;
2255 rc = lmv_check_connect(obd);
2259 CDEBUG(D_INODE, "SETATTR for "DFID", valid 0x%x\n",
2260 PFID(&op_data->op_fid1), op_data->op_attr.ia_valid);
2262 op_data->op_flags |= MF_MDC_CANCEL_FID1;
2263 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2265 RETURN(PTR_ERR(tgt));
2267 rc = md_setattr(tgt->ltd_exp, op_data, ea, ealen, ea2,
2268 ea2len, request, mod);
2273 static int lmv_fsync(struct obd_export *exp, const struct lu_fid *fid,
2274 struct obd_capa *oc, struct ptlrpc_request **request)
2276 struct obd_device *obd = exp->exp_obd;
2277 struct lmv_obd *lmv = &obd->u.lmv;
2278 struct lmv_tgt_desc *tgt;
2282 rc = lmv_check_connect(obd);
2286 tgt = lmv_find_target(lmv, fid);
2288 RETURN(PTR_ERR(tgt));
2290 rc = md_fsync(tgt->ltd_exp, fid, oc, request);
2295 * Adjust a set of pages, each page containing an array of lu_dirpages,
2296 * so that each page can be used as a single logical lu_dirpage.
2298 * A lu_dirpage is laid out as follows, where s = ldp_hash_start,
2299 * e = ldp_hash_end, f = ldp_flags, p = padding, and each "ent" is a
2300 * struct lu_dirent. It has size up to LU_PAGE_SIZE. The ldp_hash_end
2301 * value is used as a cookie to request the next lu_dirpage in a
2302 * directory listing that spans multiple pages (two in this example):
2305 * .|--------v------- -----.
2306 * |s|e|f|p|ent|ent| ... |ent|
2307 * '--|-------------- -----' Each CFS_PAGE contains a single
2308 * '------. lu_dirpage.
2309 * .---------v------- -----.
2310 * |s|e|f|p|ent| 0 | ... | 0 |
2311 * '----------------- -----'
2313 * However, on hosts where the native VM page size (PAGE_CACHE_SIZE) is
2314 * larger than LU_PAGE_SIZE, a single host page may contain multiple
2315 * lu_dirpages. After reading the lu_dirpages from the MDS, the
2316 * ldp_hash_end of the first lu_dirpage refers to the one immediately
2317 * after it in the same CFS_PAGE (arrows simplified for brevity, but
2318 * in general e0==s1, e1==s2, etc.):
2320 * .-------------------- -----.
2321 * |s0|e0|f0|p|ent|ent| ... |ent|
2322 * |---v---------------- -----|
2323 * |s1|e1|f1|p|ent|ent| ... |ent|
2324 * |---v---------------- -----| Here, each CFS_PAGE contains
2325 * ... multiple lu_dirpages.
2326 * |---v---------------- -----|
2327 * |s'|e'|f'|p|ent|ent| ... |ent|
2328 * '---|---------------- -----'
2330 * .----------------------------.
2333 * This structure is transformed into a single logical lu_dirpage as follows:
2335 * - Replace e0 with e' so the request for the next lu_dirpage gets the page
2336 * labeled 'next CFS_PAGE'.
2338 * - Copy the LDF_COLLIDE flag from f' to f0 to correctly reflect whether
2339 * a hash collision with the next page exists.
2341 * - Adjust the lde_reclen of the ending entry of each lu_dirpage to span
2342 * to the first entry of the next lu_dirpage.
2344 #if PAGE_CACHE_SIZE > LU_PAGE_SIZE
2345 static void lmv_adjust_dirpages(struct page **pages, int ncfspgs, int nlupgs)
2349 for (i = 0; i < ncfspgs; i++) {
2350 struct lu_dirpage *dp = kmap(pages[i]);
2351 struct lu_dirpage *first = dp;
2352 struct lu_dirent *end_dirent = NULL;
2353 struct lu_dirent *ent;
2354 __u64 hash_end = dp->ldp_hash_end;
2355 __u32 flags = dp->ldp_flags;
2357 while (--nlupgs > 0) {
2358 ent = lu_dirent_start(dp);
2359 for (end_dirent = ent; ent != NULL;
2360 end_dirent = ent, ent = lu_dirent_next(ent));
2362 /* Advance dp to next lu_dirpage. */
2363 dp = (struct lu_dirpage *)((char *)dp + LU_PAGE_SIZE);
2365 /* Check if we've reached the end of the CFS_PAGE. */
2366 if (!((unsigned long)dp & ~CFS_PAGE_MASK))
2369 /* Save the hash and flags of this lu_dirpage. */
2370 hash_end = dp->ldp_hash_end;
2371 flags = dp->ldp_flags;
2373 /* Check if lu_dirpage contains no entries. */
2377 /* Enlarge the end entry lde_reclen from 0 to
2378 * first entry of next lu_dirpage. */
2379 LASSERT(le16_to_cpu(end_dirent->lde_reclen) == 0);
2380 end_dirent->lde_reclen =
2381 cpu_to_le16((char *)(dp->ldp_entries) -
2382 (char *)end_dirent);
2385 first->ldp_hash_end = hash_end;
2386 first->ldp_flags &= ~cpu_to_le32(LDF_COLLIDE);
2387 first->ldp_flags |= flags & cpu_to_le32(LDF_COLLIDE);
2391 LASSERTF(nlupgs == 0, "left = %d", nlupgs);
2394 #define lmv_adjust_dirpages(pages, ncfspgs, nlupgs) do {} while (0)
2395 #endif /* PAGE_CACHE_SIZE > LU_PAGE_SIZE */
2397 #define NORMAL_MAX_STRIPES 4
2398 int lmv_read_entry(struct obd_export *exp, struct md_op_data *op_data,
2399 struct md_callback *cb_op, struct lu_dirent **ldp,
2400 struct page **ppage)
2402 struct obd_device *obd = exp->exp_obd;
2403 struct lmv_obd *lmv = &obd->u.lmv;
2404 struct lmv_stripe_md *lsm = op_data->op_mea1;
2405 struct lu_dirent *tmp_ents[NORMAL_MAX_STRIPES];
2406 struct lu_dirent **ents = NULL;
2410 struct page *min_page = NULL;
2415 rc = lmv_check_connect(obd);
2422 stripe_count = lsm->lsm_md_stripe_count;
2424 if (stripe_count > NORMAL_MAX_STRIPES) {
2425 OBD_ALLOC(ents, sizeof(ents[0]) * stripe_count);
2427 GOTO(out, rc = -ENOMEM);
2430 memset(ents, 0, sizeof(ents[0]) * stripe_count);
2433 min_hash = MDS_DIR_END_OFF;
2434 for (i = 0; i < stripe_count; i++) {
2435 struct lmv_tgt_desc *tgt;
2436 struct page *page = NULL;
2438 if (likely(lsm == NULL)) {
2439 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2441 GOTO(out, rc = PTR_ERR(tgt));
2442 LASSERT(op_data->op_data != NULL);
2444 tgt = lmv_get_target(lmv, lsm->lsm_md_oinfo[i].lmo_mds);
2446 GOTO(out, rc = PTR_ERR(tgt));
2447 op_data->op_fid1 = lsm->lsm_md_oinfo[i].lmo_fid;
2448 op_data->op_fid2 = lsm->lsm_md_oinfo[i].lmo_fid;
2449 op_data->op_stripe_offset = i;
2452 rc = md_read_entry(tgt->ltd_exp, op_data, cb_op, &ents[i],
2457 if (ents[i] != NULL &&
2458 le64_to_cpu(ents[i]->lde_hash) <= min_hash) {
2459 if (min_page != NULL)
2460 page_cache_release(min_page);
2462 min_hash = le64_to_cpu(ents[i]->lde_hash);
2467 if (min_hash != MDS_DIR_END_OFF)
2468 *ldp = ents[min_idx];
2472 if (stripe_count > NORMAL_MAX_STRIPES && ents != NULL)
2473 OBD_FREE(ents, sizeof(ents[0]) * stripe_count);
2475 if (rc != 0 && min_page != NULL) {
2477 page_cache_release(min_page);
2485 static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
2486 struct ptlrpc_request **request)
2488 struct obd_device *obd = exp->exp_obd;
2489 struct lmv_obd *lmv = &obd->u.lmv;
2490 struct lmv_tgt_desc *tgt = NULL;
2491 struct lmv_tgt_desc *parent_tgt = NULL;
2492 struct mdt_body *body;
2496 rc = lmv_check_connect(obd);
2500 /* Send unlink requests to the MDT where the child is located */
2501 if (likely(!fid_is_zero(&op_data->op_fid2))) {
2502 tgt = lmv_find_target(lmv, &op_data->op_fid2);
2504 RETURN(PTR_ERR(tgt));
2506 /* For striped dir, we need to locate the parent as well */
2507 if (op_data->op_mea1 != NULL) {
2508 struct lmv_tgt_desc *tmp;
2510 LASSERT(op_data->op_name != NULL &&
2511 op_data->op_namelen != 0);
2512 tmp = lmv_locate_target_for_name(lmv,
2515 op_data->op_namelen,
2519 RETURN(PTR_ERR(tmp));
2522 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
2524 RETURN(PTR_ERR(tgt));
2527 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
2528 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
2529 op_data->op_cap = cfs_curproc_cap_pack();
2532 * If child's fid is given, cancel unused locks for it if it is from
2533 * another export than parent.
2535 * LOOKUP lock for child (fid3) should also be cancelled on parent
2536 * tgt_tgt in mdc_unlink().
2538 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2541 * Cancel FULL locks on child (fid3).
2543 parent_tgt = lmv_find_target(lmv, &op_data->op_fid1);
2544 if (IS_ERR(parent_tgt))
2545 RETURN(PTR_ERR(parent_tgt));
2547 if (parent_tgt != tgt) {
2548 rc = lmv_early_cancel(exp, parent_tgt, op_data, tgt->ltd_idx,
2549 LCK_EX, MDS_INODELOCK_LOOKUP,
2550 MF_MDC_CANCEL_FID3);
2553 rc = lmv_early_cancel(exp, NULL, op_data, tgt->ltd_idx, LCK_EX,
2554 MDS_INODELOCK_FULL, MF_MDC_CANCEL_FID3);
2558 CDEBUG(D_INODE, "unlink with fid="DFID"/"DFID" -> mds #%d\n",
2559 PFID(&op_data->op_fid1), PFID(&op_data->op_fid2), tgt->ltd_idx);
2561 rc = md_unlink(tgt->ltd_exp, op_data, request);
2562 if (rc != 0 && rc != -EREMOTE)
2565 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
2569 /* Not cross-ref case, just get out of here. */
2570 if (likely(!(body->valid & OBD_MD_MDS)))
2573 CDEBUG(D_INODE, "%s: try unlink to another MDT for "DFID"\n",
2574 exp->exp_obd->obd_name, PFID(&body->fid1));
2576 /* This is a remote object, try remote MDT, Note: it may
2577 * try more than 1 time here, Considering following case
2578 * /mnt/lustre is root on MDT0, remote1 is on MDT1
2579 * 1. Initially A does not know where remote1 is, it send
2580 * unlink RPC to MDT0, MDT0 return -EREMOTE, it will
2581 * resend unlink RPC to MDT1 (retry 1st time).
2583 * 2. During the unlink RPC in flight,
2584 * client B mv /mnt/lustre/remote1 /mnt/lustre/remote2
2585 * and create new remote1, but on MDT0
2587 * 3. MDT1 get unlink RPC(from A), then do remote lock on
2588 * /mnt/lustre, then lookup get fid of remote1, and find
2589 * it is remote dir again, and replay -EREMOTE again.
2591 * 4. Then A will resend unlink RPC to MDT0. (retry 2nd times).
2593 * In theory, it might try unlimited time here, but it should
2594 * be very rare case. */
2595 op_data->op_fid2 = body->fid1;
2596 ptlrpc_req_finished(*request);
2602 static int lmv_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2604 struct lmv_obd *lmv = &obd->u.lmv;
2608 case OBD_CLEANUP_EARLY:
2609 /* XXX: here should be calling obd_precleanup() down to
2612 case OBD_CLEANUP_EXPORTS:
2613 fld_client_proc_fini(&lmv->lmv_fld);
2614 lprocfs_obd_cleanup(obd);
2615 lprocfs_free_md_stats(obd);
2623 static int lmv_get_info(const struct lu_env *env, struct obd_export *exp,
2624 __u32 keylen, void *key, __u32 *vallen, void *val,
2625 struct lov_stripe_md *lsm)
2627 struct obd_device *obd;
2628 struct lmv_obd *lmv;
2632 obd = class_exp2obd(exp);
2634 CDEBUG(D_IOCTL, "Invalid client cookie "LPX64"\n",
2635 exp->exp_handle.h_cookie);
2640 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
2643 rc = lmv_check_connect(obd);
2647 LASSERT(*vallen == sizeof(__u32));
2648 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2649 struct lmv_tgt_desc *tgt = lmv->tgts[i];
2651 * All tgts should be connected when this gets called.
2653 if (tgt == NULL || tgt->ltd_exp == NULL)
2656 if (!obd_get_info(env, tgt->ltd_exp, keylen, key,
2661 } else if (KEY_IS(KEY_MAX_EASIZE) ||
2662 KEY_IS(KEY_DEFAULT_EASIZE) ||
2663 KEY_IS(KEY_MAX_COOKIESIZE) ||
2664 KEY_IS(KEY_DEFAULT_COOKIESIZE) ||
2665 KEY_IS(KEY_CONN_DATA)) {
2666 rc = lmv_check_connect(obd);
2671 * Forwarding this request to first MDS, it should know LOV
2674 rc = obd_get_info(env, lmv->tgts[0]->ltd_exp, keylen, key,
2676 if (!rc && KEY_IS(KEY_CONN_DATA))
2677 exp->exp_connect_data = *(struct obd_connect_data *)val;
2679 } else if (KEY_IS(KEY_TGT_COUNT)) {
2680 *((int *)val) = lmv->desc.ld_tgt_count;
2684 CDEBUG(D_IOCTL, "Invalid key\n");
2688 int lmv_set_info_async(const struct lu_env *env, struct obd_export *exp,
2689 obd_count keylen, void *key, obd_count vallen,
2690 void *val, struct ptlrpc_request_set *set)
2692 struct lmv_tgt_desc *tgt = NULL;
2693 struct obd_device *obd;
2694 struct lmv_obd *lmv;
2698 obd = class_exp2obd(exp);
2700 CDEBUG(D_IOCTL, "Invalid client cookie "LPX64"\n",
2701 exp->exp_handle.h_cookie);
2706 if (KEY_IS(KEY_READ_ONLY) || KEY_IS(KEY_FLUSH_CTX)) {
2709 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2712 if (tgt == NULL || tgt->ltd_exp == NULL)
2715 err = obd_set_info_async(env, tgt->ltd_exp,
2716 keylen, key, vallen, val, set);
2727 static int lmv_pack_md_v1(const struct lmv_stripe_md *lsm,
2728 struct lmv_mds_md_v1 *lmm1)
2733 lmm1->lmv_magic = cpu_to_le32(lsm->lsm_md_magic);
2734 lmm1->lmv_stripe_count = cpu_to_le32(lsm->lsm_md_stripe_count);
2735 lmm1->lmv_master_mdt_index = cpu_to_le32(lsm->lsm_md_master_mdt_index);
2736 lmm1->lmv_hash_type = cpu_to_le32(lsm->lsm_md_hash_type);
2737 cplen = strlcpy(lmm1->lmv_pool_name, lsm->lsm_md_pool_name,
2738 sizeof(lmm1->lmv_pool_name));
2739 if (cplen >= sizeof(lmm1->lmv_pool_name))
2742 for (i = 0; i < lsm->lsm_md_stripe_count; i++)
2743 fid_cpu_to_le(&lmm1->lmv_stripe_fids[i],
2744 &lsm->lsm_md_oinfo[i].lmo_fid);
2748 int lmv_pack_md(union lmv_mds_md **lmmp, const struct lmv_stripe_md *lsm,
2752 bool allocated = false;
2756 LASSERT(lmmp != NULL);
2758 if (*lmmp != NULL && lsm == NULL) {
2761 stripe_count = lmv_mds_md_stripe_count_get(*lmmp);
2762 lmm_size = lmv_mds_md_size(stripe_count,
2763 le32_to_cpu((*lmmp)->lmv_magic));
2766 OBD_FREE(*lmmp, lmm_size);
2772 if (*lmmp == NULL && lsm == NULL) {
2773 lmm_size = lmv_mds_md_size(stripe_count, LMV_MAGIC);
2774 LASSERT(lmm_size > 0);
2775 OBD_ALLOC(*lmmp, lmm_size);
2778 lmv_mds_md_stripe_count_set(*lmmp, stripe_count);
2779 (*lmmp)->lmv_magic = cpu_to_le32(LMV_MAGIC);
2784 LASSERT(lsm != NULL);
2785 lmm_size = lmv_mds_md_size(lsm->lsm_md_stripe_count, lsm->lsm_md_magic);
2786 if (*lmmp == NULL) {
2787 OBD_ALLOC(*lmmp, lmm_size);
2793 switch (lsm->lsm_md_magic) {
2795 rc = lmv_pack_md_v1(lsm, &(*lmmp)->lmv_md_v1);
2802 if (rc != 0 && allocated) {
2803 OBD_FREE(*lmmp, lmm_size);
2809 EXPORT_SYMBOL(lmv_pack_md);
2811 static int lmv_unpack_md_v1(struct obd_export *exp, struct lmv_stripe_md *lsm,
2812 const struct lmv_mds_md_v1 *lmm1)
2814 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2821 lsm->lsm_md_magic = le32_to_cpu(lmm1->lmv_magic);
2822 lsm->lsm_md_stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
2823 lsm->lsm_md_master_mdt_index = le32_to_cpu(lmm1->lmv_master_mdt_index);
2824 lsm->lsm_md_hash_type = le32_to_cpu(lmm1->lmv_hash_type);
2825 lsm->lsm_md_layout_version = le32_to_cpu(lmm1->lmv_layout_version);
2826 fid_le_to_cpu(&lsm->lsm_md_master_fid, &lmm1->lmv_master_fid);
2827 cplen = strlcpy(lsm->lsm_md_pool_name, lmm1->lmv_pool_name,
2828 sizeof(lsm->lsm_md_pool_name));
2830 if (!fid_is_sane(&lsm->lsm_md_master_fid))
2833 if (cplen >= sizeof(lsm->lsm_md_pool_name))
2836 CDEBUG(D_INFO, "unpack lsm count %d, master %d hash_type %d"
2837 "layout_version %d\n", lsm->lsm_md_stripe_count,
2838 lsm->lsm_md_master_mdt_index, lsm->lsm_md_hash_type,
2839 lsm->lsm_md_layout_version);
2841 stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
2842 for (i = 0; i < le32_to_cpu(stripe_count); i++) {
2843 fid_le_to_cpu(&lsm->lsm_md_oinfo[i].lmo_fid,
2844 &lmm1->lmv_stripe_fids[i]);
2845 rc = lmv_fld_lookup(lmv, &lsm->lsm_md_oinfo[i].lmo_fid,
2846 &lsm->lsm_md_oinfo[i].lmo_mds);
2849 CDEBUG(D_INFO, "unpack fid #%d "DFID"\n", i,
2850 PFID(&lsm->lsm_md_oinfo[i].lmo_fid));
2856 int lmv_unpack_md(struct obd_export *exp, struct lmv_stripe_md **lsmp,
2857 const union lmv_mds_md *lmm, int stripe_count)
2859 struct lmv_stripe_md *lsm;
2862 bool allocated = false;
2865 LASSERT(lsmp != NULL);
2869 if (lsm != NULL && lmm == NULL) {
2872 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
2873 /* For migrating inode, the master stripe and master
2874 * object will be the same, so do not need iput, see
2875 * ll_update_lsm_md */
2876 if (!(lsm->lsm_md_hash_type & LMV_HASH_FLAG_MIGRATION &&
2877 i == 0) && lsm->lsm_md_oinfo[i].lmo_root != NULL)
2878 iput(lsm->lsm_md_oinfo[i].lmo_root);
2881 lsm_size = lmv_stripe_md_size(lsm->lsm_md_stripe_count);
2882 OBD_FREE(lsm, lsm_size);
2888 if (lsm == NULL && lmm == NULL) {
2889 lsm_size = lmv_stripe_md_size(stripe_count);
2890 OBD_ALLOC(lsm, lsm_size);
2893 lsm->lsm_md_stripe_count = stripe_count;
2899 if (le32_to_cpu(lmm->lmv_magic) != LMV_MAGIC_V1 &&
2900 le32_to_cpu(lmm->lmv_magic) != LMV_USER_MAGIC) {
2901 CERROR("%s: invalid lmv magic %x: rc = %d\n",
2902 exp->exp_obd->obd_name, le32_to_cpu(lmm->lmv_magic),
2907 if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_V1)
2908 lsm_size = lmv_stripe_md_size(lmv_mds_md_stripe_count_get(lmm));
2911 * Unpack default dirstripe(lmv_user_md) to lmv_stripe_md,
2912 * stripecount should be 0 then.
2914 lsm_size = lmv_stripe_md_size(0);
2916 lsm_size = lmv_stripe_md_size(lmv_mds_md_stripe_count_get(lmm));
2918 OBD_ALLOC(lsm, lsm_size);
2925 switch (le32_to_cpu(lmm->lmv_magic)) {
2927 rc = lmv_unpack_md_v1(exp, lsm, &lmm->lmv_md_v1);
2930 CERROR("%s: unrecognized magic %x\n", exp->exp_obd->obd_name,
2931 le32_to_cpu(lmm->lmv_magic));
2936 if (rc != 0 && allocated) {
2937 OBD_FREE(lsm, lsm_size);
2944 int lmv_alloc_memmd(struct lmv_stripe_md **lsmp, int stripes)
2946 return lmv_unpack_md(NULL, lsmp, NULL, stripes);
2948 EXPORT_SYMBOL(lmv_alloc_memmd);
2950 void lmv_free_memmd(struct lmv_stripe_md *lsm)
2952 lmv_unpack_md(NULL, &lsm, NULL, 0);
2954 EXPORT_SYMBOL(lmv_free_memmd);
2956 int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
2957 struct lov_mds_md *lmm, int disk_len)
2959 return lmv_unpack_md(exp, (struct lmv_stripe_md **)lsmp,
2960 (union lmv_mds_md *)lmm, disk_len);
2963 int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
2964 struct lov_stripe_md *lsm)
2966 struct obd_device *obd = exp->exp_obd;
2967 struct lmv_obd *lmv_obd = &obd->u.lmv;
2968 const struct lmv_stripe_md *lmv = (struct lmv_stripe_md *)lsm;
2973 stripe_count = lmv->lsm_md_stripe_count;
2975 stripe_count = lmv_obd->desc.ld_tgt_count;
2977 return lmv_mds_md_size(stripe_count, LMV_MAGIC_V1);
2980 return lmv_pack_md((union lmv_mds_md **)lmmp, lmv, 0);
2983 static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
2984 ldlm_policy_data_t *policy, ldlm_mode_t mode,
2985 ldlm_cancel_flags_t flags, void *opaque)
2987 struct obd_device *obd = exp->exp_obd;
2988 struct lmv_obd *lmv = &obd->u.lmv;
2994 LASSERT(fid != NULL);
2996 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2997 struct lmv_tgt_desc *tgt = lmv->tgts[i];
2999 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
3002 err = md_cancel_unused(tgt->ltd_exp, fid, policy, mode, flags,
3010 int lmv_set_lock_data(struct obd_export *exp, __u64 *lockh, void *data,
3013 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
3014 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3018 if (tgt == NULL || tgt->ltd_exp == NULL)
3020 rc = md_set_lock_data(tgt->ltd_exp, lockh, data, bits);
3024 ldlm_mode_t lmv_lock_match(struct obd_export *exp, __u64 flags,
3025 const struct lu_fid *fid, ldlm_type_t type,
3026 ldlm_policy_data_t *policy, ldlm_mode_t mode,
3027 struct lustre_handle *lockh)
3029 struct obd_device *obd = exp->exp_obd;
3030 struct lmv_obd *lmv = &obd->u.lmv;
3035 CDEBUG(D_INODE, "Lock match for "DFID"\n", PFID(fid));
3038 * With CMD every object can have two locks in different namespaces:
3039 * lookup lock in space of mds storing direntry and update/open lock in
3040 * space of mds storing inode. Thus we check all targets, not only that
3041 * one fid was created in.
3043 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
3044 struct lmv_tgt_desc *tgt = lmv->tgts[i];
3046 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
3049 rc = md_lock_match(tgt->ltd_exp, flags, fid, type, policy, mode,
3058 int lmv_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
3059 struct obd_export *dt_exp, struct obd_export *md_exp,
3060 struct lustre_md *md)
3062 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
3063 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3065 if (tgt == NULL || tgt->ltd_exp == NULL)
3068 return md_get_lustre_md(lmv->tgts[0]->ltd_exp, req, dt_exp, md_exp, md);
3071 int lmv_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
3073 struct obd_device *obd = exp->exp_obd;
3074 struct lmv_obd *lmv = &obd->u.lmv;
3075 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3078 if (md->lmv != NULL) {
3079 lmv_free_memmd(md->lmv);
3082 if (tgt == NULL || tgt->ltd_exp == NULL)
3084 RETURN(md_free_lustre_md(lmv->tgts[0]->ltd_exp, md));
3087 int lmv_set_open_replay_data(struct obd_export *exp,
3088 struct obd_client_handle *och,
3089 struct lookup_intent *it)
3091 struct obd_device *obd = exp->exp_obd;
3092 struct lmv_obd *lmv = &obd->u.lmv;
3093 struct lmv_tgt_desc *tgt;
3096 tgt = lmv_find_target(lmv, &och->och_fid);
3098 RETURN(PTR_ERR(tgt));
3100 RETURN(md_set_open_replay_data(tgt->ltd_exp, och, it));
3103 int lmv_clear_open_replay_data(struct obd_export *exp,
3104 struct obd_client_handle *och)
3106 struct obd_device *obd = exp->exp_obd;
3107 struct lmv_obd *lmv = &obd->u.lmv;
3108 struct lmv_tgt_desc *tgt;
3111 tgt = lmv_find_target(lmv, &och->och_fid);
3113 RETURN(PTR_ERR(tgt));
3115 RETURN(md_clear_open_replay_data(tgt->ltd_exp, och));
3118 static int lmv_get_remote_perm(struct obd_export *exp,
3119 const struct lu_fid *fid,
3120 struct obd_capa *oc, __u32 suppgid,
3121 struct ptlrpc_request **request)
3123 struct obd_device *obd = exp->exp_obd;
3124 struct lmv_obd *lmv = &obd->u.lmv;
3125 struct lmv_tgt_desc *tgt;
3129 rc = lmv_check_connect(obd);
3133 tgt = lmv_find_target(lmv, fid);
3135 RETURN(PTR_ERR(tgt));
3137 rc = md_get_remote_perm(tgt->ltd_exp, fid, oc, suppgid, request);
3141 static int lmv_renew_capa(struct obd_export *exp, struct obd_capa *oc,
3144 struct obd_device *obd = exp->exp_obd;
3145 struct lmv_obd *lmv = &obd->u.lmv;
3146 struct lmv_tgt_desc *tgt;
3150 rc = lmv_check_connect(obd);
3154 tgt = lmv_find_target(lmv, &oc->c_capa.lc_fid);
3156 RETURN(PTR_ERR(tgt));
3158 rc = md_renew_capa(tgt->ltd_exp, oc, cb);
3162 int lmv_unpack_capa(struct obd_export *exp, struct ptlrpc_request *req,
3163 const struct req_msg_field *field, struct obd_capa **oc)
3165 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
3166 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3168 if (tgt == NULL || tgt->ltd_exp == NULL)
3170 return md_unpack_capa(tgt->ltd_exp, req, field, oc);
3173 int lmv_intent_getattr_async(struct obd_export *exp,
3174 struct md_enqueue_info *minfo,
3175 struct ldlm_enqueue_info *einfo)
3177 struct md_op_data *op_data = &minfo->mi_data;
3178 struct obd_device *obd = exp->exp_obd;
3179 struct lmv_obd *lmv = &obd->u.lmv;
3180 struct lmv_tgt_desc *tgt = NULL;
3184 rc = lmv_check_connect(obd);
3188 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
3190 RETURN(PTR_ERR(tgt));
3192 rc = md_intent_getattr_async(tgt->ltd_exp, minfo, einfo);
3196 int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
3197 struct lu_fid *fid, __u64 *bits)
3199 struct obd_device *obd = exp->exp_obd;
3200 struct lmv_obd *lmv = &obd->u.lmv;
3201 struct lmv_tgt_desc *tgt;
3205 rc = lmv_check_connect(obd);
3209 tgt = lmv_find_target(lmv, fid);
3211 RETURN(PTR_ERR(tgt));
3213 rc = md_revalidate_lock(tgt->ltd_exp, it, fid, bits);
3218 * For lmv, only need to send request to master MDT, and the master MDT will
3219 * process with other slave MDTs. The only exception is Q_GETOQUOTA for which
3220 * we directly fetch data from the slave MDTs.
3222 int lmv_quotactl(struct obd_device *unused, struct obd_export *exp,
3223 struct obd_quotactl *oqctl)
3225 struct obd_device *obd = class_exp2obd(exp);
3226 struct lmv_obd *lmv = &obd->u.lmv;
3227 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3230 __u64 curspace, curinodes;
3234 tgt->ltd_exp == NULL ||
3236 lmv->desc.ld_tgt_count == 0) {
3237 CERROR("master lmv inactive\n");
3241 if (oqctl->qc_cmd != Q_GETOQUOTA) {
3242 rc = obd_quotactl(tgt->ltd_exp, oqctl);
3246 curspace = curinodes = 0;
3247 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
3251 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
3254 err = obd_quotactl(tgt->ltd_exp, oqctl);
3256 CERROR("getquota on mdt %d failed. %d\n", i, err);
3260 curspace += oqctl->qc_dqblk.dqb_curspace;
3261 curinodes += oqctl->qc_dqblk.dqb_curinodes;
3264 oqctl->qc_dqblk.dqb_curspace = curspace;
3265 oqctl->qc_dqblk.dqb_curinodes = curinodes;
3270 int lmv_quotacheck(struct obd_device *unused, struct obd_export *exp,
3271 struct obd_quotactl *oqctl)
3273 struct obd_device *obd = class_exp2obd(exp);
3274 struct lmv_obd *lmv = &obd->u.lmv;
3275 struct lmv_tgt_desc *tgt;
3280 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
3283 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active) {
3284 CERROR("lmv idx %d inactive\n", i);
3288 err = obd_quotacheck(tgt->ltd_exp, oqctl);
3296 int lmv_update_lsm_md(struct obd_export *exp, struct lmv_stripe_md *lsm,
3297 struct mdt_body *body, ldlm_blocking_callback cb_blocking)
3299 return lmv_revalidate_slaves(exp, body, lsm, cb_blocking, 0);
3302 int lmv_merge_attr(struct obd_export *exp, const struct lmv_stripe_md *lsm,
3303 struct cl_attr *attr)
3308 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
3309 struct inode *inode = lsm->lsm_md_oinfo[i].lmo_root;
3311 CDEBUG(D_INFO, ""DFID" size %llu, nlink %u, atime %lu ctime"
3312 "%lu, mtime %lu.\n", PFID(&lsm->lsm_md_oinfo[i].lmo_fid),
3313 i_size_read(inode), inode->i_nlink,
3314 LTIME_S(inode->i_atime), LTIME_S(inode->i_ctime),
3315 LTIME_S(inode->i_mtime));
3317 /* for slave stripe, it needs to subtract nlink for . and .. */
3319 attr->cat_nlink += inode->i_nlink - 2;
3321 attr->cat_nlink = inode->i_nlink;
3323 attr->cat_size += i_size_read(inode);
3325 if (attr->cat_atime < LTIME_S(inode->i_atime))
3326 attr->cat_atime = LTIME_S(inode->i_atime);
3328 if (attr->cat_ctime < LTIME_S(inode->i_ctime))
3329 attr->cat_ctime = LTIME_S(inode->i_ctime);
3331 if (attr->cat_mtime < LTIME_S(inode->i_mtime))
3332 attr->cat_mtime = LTIME_S(inode->i_mtime);
3338 struct obd_ops lmv_obd_ops = {
3339 .o_owner = THIS_MODULE,
3340 .o_setup = lmv_setup,
3341 .o_cleanup = lmv_cleanup,
3342 .o_precleanup = lmv_precleanup,
3343 .o_process_config = lmv_process_config,
3344 .o_connect = lmv_connect,
3345 .o_disconnect = lmv_disconnect,
3346 .o_statfs = lmv_statfs,
3347 .o_get_info = lmv_get_info,
3348 .o_set_info_async = lmv_set_info_async,
3349 .o_packmd = lmv_packmd,
3350 .o_unpackmd = lmv_unpackmd,
3351 .o_notify = lmv_notify,
3352 .o_get_uuid = lmv_get_uuid,
3353 .o_iocontrol = lmv_iocontrol,
3354 .o_quotacheck = lmv_quotacheck,
3355 .o_quotactl = lmv_quotactl
3358 struct md_ops lmv_md_ops = {
3359 .m_getstatus = lmv_getstatus,
3360 .m_null_inode = lmv_null_inode,
3361 .m_find_cbdata = lmv_find_cbdata,
3362 .m_close = lmv_close,
3363 .m_create = lmv_create,
3364 .m_done_writing = lmv_done_writing,
3365 .m_enqueue = lmv_enqueue,
3366 .m_getattr = lmv_getattr,
3367 .m_getxattr = lmv_getxattr,
3368 .m_getattr_name = lmv_getattr_name,
3369 .m_intent_lock = lmv_intent_lock,
3371 .m_rename = lmv_rename,
3372 .m_setattr = lmv_setattr,
3373 .m_setxattr = lmv_setxattr,
3374 .m_fsync = lmv_fsync,
3375 .m_read_entry = lmv_read_entry,
3376 .m_unlink = lmv_unlink,
3377 .m_init_ea_size = lmv_init_ea_size,
3378 .m_cancel_unused = lmv_cancel_unused,
3379 .m_set_lock_data = lmv_set_lock_data,
3380 .m_lock_match = lmv_lock_match,
3381 .m_get_lustre_md = lmv_get_lustre_md,
3382 .m_free_lustre_md = lmv_free_lustre_md,
3383 .m_update_lsm_md = lmv_update_lsm_md,
3384 .m_merge_attr = lmv_merge_attr,
3385 .m_set_open_replay_data = lmv_set_open_replay_data,
3386 .m_clear_open_replay_data = lmv_clear_open_replay_data,
3387 .m_renew_capa = lmv_renew_capa,
3388 .m_unpack_capa = lmv_unpack_capa,
3389 .m_get_remote_perm = lmv_get_remote_perm,
3390 .m_intent_getattr_async = lmv_intent_getattr_async,
3391 .m_revalidate_lock = lmv_revalidate_lock
3394 int __init lmv_init(void)
3396 return class_register_type(&lmv_obd_ops, &lmv_md_ops, true, NULL,
3397 #ifndef HAVE_ONLY_PROCFS_SEQ
3400 LUSTRE_LMV_NAME, NULL);
3404 static void lmv_exit(void)
3406 class_unregister_type(LUSTRE_LMV_NAME);
3409 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
3410 MODULE_DESCRIPTION("Lustre Logical Metadata Volume OBD driver");
3411 MODULE_LICENSE("GPL");
3413 module_init(lmv_init);
3414 module_exit(lmv_exit);