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, int def_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;
386 if (lmv->max_def_cookiesize < def_cookiesize) {
387 lmv->max_def_cookiesize = def_cookiesize;
393 if (lmv->connected == 0)
396 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
397 struct lmv_tgt_desc *tgt = lmv->tgts[i];
399 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active) {
400 CWARN("%s: NULL export for %d\n", obd->obd_name, i);
404 rc = md_init_ea_size(tgt->ltd_exp, easize, def_easize,
405 cookiesize, def_cookiesize);
407 CERROR("%s: obd_init_ea_size() failed on MDT target %d:"
408 " rc = %d.\n", obd->obd_name, i, rc);
415 #define MAX_STRING_SIZE 128
417 int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
420 struct proc_dir_entry *lmv_proc_dir;
422 struct lmv_obd *lmv = &obd->u.lmv;
423 struct obd_uuid *cluuid = &lmv->cluuid;
424 struct obd_uuid lmv_mdc_uuid = { "LMV_MDC_UUID" };
425 struct obd_device *mdc_obd;
426 struct obd_export *mdc_exp;
427 struct lu_fld_target target;
431 mdc_obd = class_find_client_obd(&tgt->ltd_uuid, LUSTRE_MDC_NAME,
434 CERROR("target %s not attached\n", tgt->ltd_uuid.uuid);
438 CDEBUG(D_CONFIG, "connect to %s(%s) - %s, %s FOR %s\n",
439 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
440 tgt->ltd_uuid.uuid, obd->obd_uuid.uuid,
443 if (!mdc_obd->obd_set_up) {
444 CERROR("target %s is not set up\n", tgt->ltd_uuid.uuid);
448 rc = obd_connect(NULL, &mdc_exp, mdc_obd, &lmv_mdc_uuid,
449 &lmv->conn_data, NULL);
451 CERROR("target %s connect error %d\n", tgt->ltd_uuid.uuid, rc);
456 * Init fid sequence client for this mdc and add new fld target.
458 rc = obd_fid_init(mdc_obd, mdc_exp, LUSTRE_SEQ_METADATA);
462 target.ft_srv = NULL;
463 target.ft_exp = mdc_exp;
464 target.ft_idx = tgt->ltd_idx;
466 fld_client_add_target(&lmv->lmv_fld, &target);
468 rc = obd_register_observer(mdc_obd, obd);
470 obd_disconnect(mdc_exp);
471 CERROR("target %s register_observer error %d\n",
472 tgt->ltd_uuid.uuid, rc);
476 if (obd->obd_observer) {
478 * Tell the observer about the new target.
480 rc = obd_notify(obd->obd_observer, mdc_exp->exp_obd,
482 (void *)(tgt - lmv->tgts[0]));
484 obd_disconnect(mdc_exp);
490 tgt->ltd_exp = mdc_exp;
491 lmv->desc.ld_active_tgt_count++;
493 md_init_ea_size(tgt->ltd_exp, lmv->max_easize, lmv->max_def_easize,
494 lmv->max_cookiesize, lmv->max_def_cookiesize);
496 CDEBUG(D_CONFIG, "Connected to %s(%s) successfully (%d)\n",
497 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
498 atomic_read(&obd->obd_refcount));
501 lmv_proc_dir = obd->obd_proc_private;
503 struct proc_dir_entry *mdc_symlink;
505 LASSERT(mdc_obd->obd_type != NULL);
506 LASSERT(mdc_obd->obd_type->typ_name != NULL);
507 mdc_symlink = lprocfs_add_symlink(mdc_obd->obd_name,
510 mdc_obd->obd_type->typ_name,
512 if (mdc_symlink == NULL) {
513 CERROR("Could not register LMV target "
514 "/proc/fs/lustre/%s/%s/target_obds/%s.",
515 obd->obd_type->typ_name, obd->obd_name,
517 lprocfs_remove(&lmv_proc_dir);
518 obd->obd_proc_private = NULL;
525 static void lmv_del_target(struct lmv_obd *lmv, int index)
527 if (lmv->tgts[index] == NULL)
530 OBD_FREE_PTR(lmv->tgts[index]);
531 lmv->tgts[index] = NULL;
535 static int lmv_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
536 __u32 index, int gen)
538 struct lmv_obd *lmv = &obd->u.lmv;
539 struct lmv_tgt_desc *tgt;
543 CDEBUG(D_CONFIG, "Target uuid: %s. index %d\n", uuidp->uuid, index);
547 if (lmv->desc.ld_tgt_count == 0) {
548 struct obd_device *mdc_obd;
550 mdc_obd = class_find_client_obd(uuidp, LUSTRE_MDC_NAME,
553 lmv_init_unlock(lmv);
554 CERROR("%s: Target %s not attached: rc = %d\n",
555 obd->obd_name, uuidp->uuid, -EINVAL);
560 if ((index < lmv->tgts_size) && (lmv->tgts[index] != NULL)) {
561 tgt = lmv->tgts[index];
562 CERROR("%s: UUID %s already assigned at LOV target index %d:"
563 " rc = %d\n", obd->obd_name,
564 obd_uuid2str(&tgt->ltd_uuid), index, -EEXIST);
565 lmv_init_unlock(lmv);
569 if (index >= lmv->tgts_size) {
570 /* We need to reallocate the lmv target array. */
571 struct lmv_tgt_desc **newtgts, **old = NULL;
575 while (newsize < index + 1)
576 newsize = newsize << 1;
577 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
578 if (newtgts == NULL) {
579 lmv_init_unlock(lmv);
583 if (lmv->tgts_size) {
584 memcpy(newtgts, lmv->tgts,
585 sizeof(*newtgts) * lmv->tgts_size);
587 oldsize = lmv->tgts_size;
591 lmv->tgts_size = newsize;
594 OBD_FREE(old, sizeof(*old) * oldsize);
596 CDEBUG(D_CONFIG, "tgts: %p size: %d\n", lmv->tgts,
602 lmv_init_unlock(lmv);
606 mutex_init(&tgt->ltd_fid_mutex);
607 tgt->ltd_idx = index;
608 tgt->ltd_uuid = *uuidp;
610 lmv->tgts[index] = tgt;
611 if (index >= lmv->desc.ld_tgt_count)
612 lmv->desc.ld_tgt_count = index + 1;
614 if (lmv->connected) {
615 rc = lmv_connect_mdc(obd, tgt);
617 spin_lock(&lmv->lmv_lock);
618 lmv->desc.ld_tgt_count--;
619 memset(tgt, 0, sizeof(*tgt));
620 spin_unlock(&lmv->lmv_lock);
622 int easize = sizeof(struct lmv_stripe_md) +
623 lmv->desc.ld_tgt_count * sizeof(struct lu_fid);
624 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0, 0);
628 lmv_init_unlock(lmv);
632 int lmv_check_connect(struct obd_device *obd)
634 struct lmv_obd *lmv = &obd->u.lmv;
635 struct lmv_tgt_desc *tgt;
645 if (lmv->connected) {
646 lmv_init_unlock(lmv);
650 if (lmv->desc.ld_tgt_count == 0) {
651 lmv_init_unlock(lmv);
652 CERROR("%s: no targets configured.\n", obd->obd_name);
656 LASSERT(lmv->tgts != NULL);
658 if (lmv->tgts[0] == NULL) {
659 lmv_init_unlock(lmv);
660 CERROR("%s: no target configured for index 0.\n",
665 CDEBUG(D_CONFIG, "Time to connect %s to %s\n",
666 lmv->cluuid.uuid, obd->obd_name);
668 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
672 rc = lmv_connect_mdc(obd, tgt);
677 lmv_set_timeouts(obd);
678 class_export_put(lmv->exp);
680 easize = lmv_mds_md_size(lmv->desc.ld_tgt_count, LMV_MAGIC);
681 lmv_init_ea_size(obd->obd_self_export, easize, 0, 0, 0);
682 lmv_init_unlock(lmv);
693 --lmv->desc.ld_active_tgt_count;
694 rc2 = obd_disconnect(tgt->ltd_exp);
696 CERROR("LMV target %s disconnect on "
697 "MDC idx %d: error %d\n",
698 tgt->ltd_uuid.uuid, i, rc2);
702 class_disconnect(lmv->exp);
703 lmv_init_unlock(lmv);
707 static int lmv_disconnect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
710 struct proc_dir_entry *lmv_proc_dir;
712 struct lmv_obd *lmv = &obd->u.lmv;
713 struct obd_device *mdc_obd;
717 LASSERT(tgt != NULL);
718 LASSERT(obd != NULL);
720 mdc_obd = class_exp2obd(tgt->ltd_exp);
723 mdc_obd->obd_force = obd->obd_force;
724 mdc_obd->obd_fail = obd->obd_fail;
725 mdc_obd->obd_no_recov = obd->obd_no_recov;
729 lmv_proc_dir = obd->obd_proc_private;
731 lprocfs_remove_proc_entry(mdc_obd->obd_name, lmv_proc_dir);
733 rc = obd_fid_fini(tgt->ltd_exp->exp_obd);
735 CERROR("Can't finanize fids factory\n");
737 CDEBUG(D_INFO, "Disconnected from %s(%s) successfully\n",
738 tgt->ltd_exp->exp_obd->obd_name,
739 tgt->ltd_exp->exp_obd->obd_uuid.uuid);
741 obd_register_observer(tgt->ltd_exp->exp_obd, NULL);
742 rc = obd_disconnect(tgt->ltd_exp);
744 if (tgt->ltd_active) {
745 CERROR("Target %s disconnect error %d\n",
746 tgt->ltd_uuid.uuid, rc);
750 lmv_activate_target(lmv, tgt, 0);
755 static int lmv_disconnect(struct obd_export *exp)
757 struct obd_device *obd = class_exp2obd(exp);
758 struct lmv_obd *lmv = &obd->u.lmv;
767 * Only disconnect the underlying layers on the final disconnect.
770 if (lmv->refcount != 0)
773 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
774 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
777 lmv_disconnect_mdc(obd, lmv->tgts[i]);
781 if (obd->obd_proc_private)
782 lprocfs_remove((struct proc_dir_entry **)&obd->obd_proc_private);
784 CERROR("/proc/fs/lustre/%s/%s/target_obds missing\n",
785 obd->obd_type->typ_name, obd->obd_name);
790 * This is the case when no real connection is established by
791 * lmv_check_connect().
794 class_export_put(exp);
795 rc = class_disconnect(exp);
796 if (lmv->refcount == 0)
801 static int lmv_fid2path(struct obd_export *exp, int len, void *karg, void *uarg)
803 struct obd_device *obddev = class_exp2obd(exp);
804 struct lmv_obd *lmv = &obddev->u.lmv;
805 struct getinfo_fid2path *gf;
806 struct lmv_tgt_desc *tgt;
807 struct getinfo_fid2path *remote_gf = NULL;
808 int remote_gf_size = 0;
811 gf = (struct getinfo_fid2path *)karg;
812 tgt = lmv_find_target(lmv, &gf->gf_fid);
814 RETURN(PTR_ERR(tgt));
817 rc = obd_iocontrol(OBD_IOC_FID2PATH, tgt->ltd_exp, len, gf, uarg);
818 if (rc != 0 && rc != -EREMOTE)
819 GOTO(out_fid2path, rc);
821 /* If remote_gf != NULL, it means just building the
822 * path on the remote MDT, copy this path segement to gf */
823 if (remote_gf != NULL) {
824 struct getinfo_fid2path *ori_gf;
827 ori_gf = (struct getinfo_fid2path *)karg;
828 if (strlen(ori_gf->gf_path) +
829 strlen(gf->gf_path) > ori_gf->gf_pathlen)
830 GOTO(out_fid2path, rc = -EOVERFLOW);
832 ptr = ori_gf->gf_path;
834 memmove(ptr + strlen(gf->gf_path) + 1, ptr,
835 strlen(ori_gf->gf_path));
837 strncpy(ptr, gf->gf_path, strlen(gf->gf_path));
838 ptr += strlen(gf->gf_path);
842 CDEBUG(D_INFO, "%s: get path %s "DFID" rec: "LPU64" ln: %u\n",
843 tgt->ltd_exp->exp_obd->obd_name,
844 gf->gf_path, PFID(&gf->gf_fid), gf->gf_recno,
848 GOTO(out_fid2path, rc);
850 /* sigh, has to go to another MDT to do path building further */
851 if (remote_gf == NULL) {
852 remote_gf_size = sizeof(*remote_gf) + PATH_MAX;
853 OBD_ALLOC(remote_gf, remote_gf_size);
854 if (remote_gf == NULL)
855 GOTO(out_fid2path, rc = -ENOMEM);
856 remote_gf->gf_pathlen = PATH_MAX;
859 if (!fid_is_sane(&gf->gf_fid)) {
860 CERROR("%s: invalid FID "DFID": rc = %d\n",
861 tgt->ltd_exp->exp_obd->obd_name,
862 PFID(&gf->gf_fid), -EINVAL);
863 GOTO(out_fid2path, rc = -EINVAL);
866 tgt = lmv_find_target(lmv, &gf->gf_fid);
868 GOTO(out_fid2path, rc = -EINVAL);
870 remote_gf->gf_fid = gf->gf_fid;
871 remote_gf->gf_recno = -1;
872 remote_gf->gf_linkno = -1;
873 memset(remote_gf->gf_path, 0, remote_gf->gf_pathlen);
875 goto repeat_fid2path;
878 if (remote_gf != NULL)
879 OBD_FREE(remote_gf, remote_gf_size);
883 static int lmv_hsm_req_count(struct lmv_obd *lmv,
884 const struct hsm_user_request *hur,
885 const struct lmv_tgt_desc *tgt_mds)
889 struct lmv_tgt_desc *curr_tgt;
891 /* count how many requests must be sent to the given target */
892 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
893 curr_tgt = lmv_find_target(lmv, &hur->hur_user_item[i].hui_fid);
894 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid))
900 static void lmv_hsm_req_build(struct lmv_obd *lmv,
901 struct hsm_user_request *hur_in,
902 const struct lmv_tgt_desc *tgt_mds,
903 struct hsm_user_request *hur_out)
906 struct lmv_tgt_desc *curr_tgt;
908 /* build the hsm_user_request for the given target */
909 hur_out->hur_request = hur_in->hur_request;
911 for (i = 0; i < hur_in->hur_request.hr_itemcount; i++) {
912 curr_tgt = lmv_find_target(lmv,
913 &hur_in->hur_user_item[i].hui_fid);
914 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid)) {
915 hur_out->hur_user_item[nr_out] =
916 hur_in->hur_user_item[i];
920 hur_out->hur_request.hr_itemcount = nr_out;
921 memcpy(hur_data(hur_out), hur_data(hur_in),
922 hur_in->hur_request.hr_data_len);
925 static int lmv_hsm_ct_unregister(struct lmv_obd *lmv, unsigned int cmd, int len,
926 struct lustre_kernelcomm *lk, void *uarg)
930 struct kkuc_ct_data *kcd = NULL;
933 /* unregister request (call from llapi_hsm_copytool_fini) */
934 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
935 struct lmv_tgt_desc *tgt = lmv->tgts[i];
937 if (tgt == NULL || tgt->ltd_exp == NULL)
939 /* best effort: try to clean as much as possible
940 * (continue on error) */
941 obd_iocontrol(cmd, tgt->ltd_exp, len, lk, uarg);
944 /* Whatever the result, remove copytool from kuc groups.
945 * Unreached coordinators will get EPIPE on next requests
946 * and will unregister automatically.
948 rc = libcfs_kkuc_group_rem(lk->lk_uid, lk->lk_group, (void **)&kcd);
955 static int lmv_hsm_ct_register(struct lmv_obd *lmv, unsigned int cmd, int len,
956 struct lustre_kernelcomm *lk, void *uarg)
961 bool any_set = false;
962 struct kkuc_ct_data *kcd;
965 /* All or nothing: try to register to all MDS.
966 * In case of failure, unregister from previous MDS,
967 * except if it because of inactive target. */
968 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
969 struct lmv_tgt_desc *tgt = lmv->tgts[i];
971 if (tgt == NULL || tgt->ltd_exp == NULL)
973 err = obd_iocontrol(cmd, tgt->ltd_exp, len, lk, uarg);
975 if (tgt->ltd_active) {
976 /* permanent error */
977 CERROR("%s: iocontrol MDC %s on MDT"
978 " idx %d cmd %x: err = %d\n",
979 class_exp2obd(lmv->exp)->obd_name,
980 tgt->ltd_uuid.uuid, i, cmd, err);
982 lk->lk_flags |= LK_FLG_STOP;
983 /* unregister from previous MDS */
984 for (j = 0; j < i; j++) {
986 if (tgt == NULL || tgt->ltd_exp == NULL)
988 obd_iocontrol(cmd, tgt->ltd_exp, len,
993 /* else: transient error.
994 * kuc will register to the missing MDT
1002 /* no registration done: return error */
1005 /* at least one registration done, with no failure */
1006 filp = fget(lk->lk_wfd);
1015 kcd->kcd_magic = KKUC_CT_DATA_MAGIC;
1016 kcd->kcd_uuid = lmv->cluuid;
1017 kcd->kcd_archive = lk->lk_data;
1019 rc = libcfs_kkuc_group_add(filp, lk->lk_uid, lk->lk_group, kcd);
1032 static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
1033 int len, void *karg, void *uarg)
1035 struct obd_device *obddev = class_exp2obd(exp);
1036 struct lmv_obd *lmv = &obddev->u.lmv;
1037 struct lmv_tgt_desc *tgt = NULL;
1041 __u32 count = lmv->desc.ld_tgt_count;
1048 case IOC_OBD_STATFS: {
1049 struct obd_ioctl_data *data = karg;
1050 struct obd_device *mdc_obd;
1051 struct obd_statfs stat_buf = {0};
1054 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
1055 if ((index >= count))
1058 tgt = lmv->tgts[index];
1059 if (tgt == NULL || !tgt->ltd_active)
1062 mdc_obd = class_exp2obd(tgt->ltd_exp);
1067 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(mdc_obd),
1068 min((int) data->ioc_plen2,
1069 (int) sizeof(struct obd_uuid))))
1072 rc = obd_statfs(NULL, tgt->ltd_exp, &stat_buf,
1073 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1077 if (copy_to_user(data->ioc_pbuf1, &stat_buf,
1078 min((int) data->ioc_plen1,
1079 (int) sizeof(stat_buf))))
1083 case OBD_IOC_QUOTACTL: {
1084 struct if_quotactl *qctl = karg;
1085 struct obd_quotactl *oqctl;
1087 if (qctl->qc_valid == QC_MDTIDX) {
1088 if (count <= qctl->qc_idx)
1091 tgt = lmv->tgts[qctl->qc_idx];
1092 if (tgt == NULL || tgt->ltd_exp == NULL)
1094 } else if (qctl->qc_valid == QC_UUID) {
1095 for (i = 0; i < count; i++) {
1099 if (!obd_uuid_equals(&tgt->ltd_uuid,
1103 if (tgt->ltd_exp == NULL)
1115 LASSERT(tgt != NULL && tgt->ltd_exp != NULL);
1116 OBD_ALLOC_PTR(oqctl);
1120 QCTL_COPY(oqctl, qctl);
1121 rc = obd_quotactl(tgt->ltd_exp, oqctl);
1123 QCTL_COPY(qctl, oqctl);
1124 qctl->qc_valid = QC_MDTIDX;
1125 qctl->obd_uuid = tgt->ltd_uuid;
1127 OBD_FREE_PTR(oqctl);
1130 case OBD_IOC_CHANGELOG_SEND:
1131 case OBD_IOC_CHANGELOG_CLEAR: {
1132 struct ioc_changelog *icc = karg;
1134 if (icc->icc_mdtindex >= count)
1137 tgt = lmv->tgts[icc->icc_mdtindex];
1138 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
1140 rc = obd_iocontrol(cmd, tgt->ltd_exp, sizeof(*icc), icc, NULL);
1143 case LL_IOC_GET_CONNECT_FLAGS: {
1145 if (tgt == NULL || tgt->ltd_exp == NULL)
1147 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1150 case OBD_IOC_FID2PATH: {
1151 rc = lmv_fid2path(exp, len, karg, uarg);
1154 case LL_IOC_HSM_STATE_GET:
1155 case LL_IOC_HSM_STATE_SET:
1156 case LL_IOC_HSM_ACTION: {
1157 struct md_op_data *op_data = karg;
1159 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1161 RETURN(PTR_ERR(tgt));
1163 if (tgt->ltd_exp == NULL)
1166 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1169 case LL_IOC_HSM_PROGRESS: {
1170 const struct hsm_progress_kernel *hpk = karg;
1172 tgt = lmv_find_target(lmv, &hpk->hpk_fid);
1174 RETURN(PTR_ERR(tgt));
1175 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1178 case LL_IOC_HSM_REQUEST: {
1179 struct hsm_user_request *hur = karg;
1180 unsigned int reqcount = hur->hur_request.hr_itemcount;
1185 /* if the request is about a single fid
1186 * or if there is a single MDS, no need to split
1188 if (reqcount == 1 || count == 1) {
1189 tgt = lmv_find_target(lmv,
1190 &hur->hur_user_item[0].hui_fid);
1192 RETURN(PTR_ERR(tgt));
1193 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1195 /* split fid list to their respective MDS */
1196 for (i = 0; i < count; i++) {
1197 unsigned int nr, reqlen;
1199 struct hsm_user_request *req;
1202 if (tgt == NULL || tgt->ltd_exp == NULL)
1205 nr = lmv_hsm_req_count(lmv, hur, tgt);
1206 if (nr == 0) /* nothing for this MDS */
1209 /* build a request with fids for this MDS */
1210 reqlen = offsetof(typeof(*hur),
1212 + hur->hur_request.hr_data_len;
1213 OBD_ALLOC_LARGE(req, reqlen);
1217 lmv_hsm_req_build(lmv, hur, tgt, req);
1219 rc1 = obd_iocontrol(cmd, tgt->ltd_exp, reqlen,
1221 if (rc1 != 0 && rc == 0)
1223 OBD_FREE_LARGE(req, reqlen);
1228 case LL_IOC_LOV_SWAP_LAYOUTS: {
1229 struct md_op_data *op_data = karg;
1230 struct lmv_tgt_desc *tgt1, *tgt2;
1232 tgt1 = lmv_find_target(lmv, &op_data->op_fid1);
1234 RETURN(PTR_ERR(tgt1));
1236 tgt2 = lmv_find_target(lmv, &op_data->op_fid2);
1238 RETURN(PTR_ERR(tgt2));
1240 if ((tgt1->ltd_exp == NULL) || (tgt2->ltd_exp == NULL))
1243 /* only files on same MDT can have their layouts swapped */
1244 if (tgt1->ltd_idx != tgt2->ltd_idx)
1247 rc = obd_iocontrol(cmd, tgt1->ltd_exp, len, karg, uarg);
1250 case LL_IOC_HSM_CT_START: {
1251 struct lustre_kernelcomm *lk = karg;
1252 if (lk->lk_flags & LK_FLG_STOP)
1253 rc = lmv_hsm_ct_unregister(lmv, cmd, len, lk, uarg);
1255 rc = lmv_hsm_ct_register(lmv, cmd, len, lk, uarg);
1259 for (i = 0; i < count; i++) {
1260 struct obd_device *mdc_obd;
1264 if (tgt == NULL || tgt->ltd_exp == NULL)
1266 /* ll_umount_begin() sets force flag but for lmv, not
1267 * mdc. Let's pass it through */
1268 mdc_obd = class_exp2obd(tgt->ltd_exp);
1269 mdc_obd->obd_force = obddev->obd_force;
1270 err = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1271 if (err == -ENODATA && cmd == OBD_IOC_POLL_QUOTACHECK) {
1274 if (tgt->ltd_active) {
1275 CERROR("error: iocontrol MDC %s on MDT"
1276 " idx %d cmd %x: err = %d\n",
1277 tgt->ltd_uuid.uuid, i, cmd, err);
1291 static int lmv_all_chars_policy(int count, const char *name,
1302 static int lmv_nid_policy(struct lmv_obd *lmv)
1304 struct obd_import *imp;
1308 * XXX: To get nid we assume that underlying obd device is mdc.
1310 imp = class_exp2cliimp(lmv->tgts[0].ltd_exp);
1311 id = imp->imp_connection->c_self ^ (imp->imp_connection->c_self >> 32);
1312 return id % lmv->desc.ld_tgt_count;
1315 static int lmv_choose_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1316 placement_policy_t placement)
1318 switch (placement) {
1319 case PLACEMENT_CHAR_POLICY:
1320 return lmv_all_chars_policy(lmv->desc.ld_tgt_count,
1322 op_data->op_namelen);
1323 case PLACEMENT_NID_POLICY:
1324 return lmv_nid_policy(lmv);
1330 CERROR("Unsupported placement policy %x\n", placement);
1336 * This is _inode_ placement policy function (not name).
1338 static int lmv_placement_policy(struct obd_device *obd,
1339 struct md_op_data *op_data,
1342 struct lmv_obd *lmv = &obd->u.lmv;
1345 LASSERT(mds != NULL);
1347 if (lmv->desc.ld_tgt_count == 1) {
1353 * If stripe_offset is provided during setdirstripe
1354 * (setdirstripe -i xx), xx MDS will be choosen.
1356 if (op_data->op_cli_flags & CLI_SET_MEA && op_data->op_data != NULL) {
1357 struct lmv_user_md *lum;
1359 lum = op_data->op_data;
1361 if (le32_to_cpu(lum->lum_stripe_offset) != (__u32)-1) {
1362 *mds = le32_to_cpu(lum->lum_stripe_offset);
1364 /* -1 means default, which will be in the same MDT with
1366 *mds = op_data->op_mds;
1367 lum->lum_stripe_offset = cpu_to_le32(op_data->op_mds);
1370 /* Allocate new fid on target according to operation type and
1371 * parent home mds. */
1372 *mds = op_data->op_mds;
1378 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid,
1381 struct lmv_tgt_desc *tgt;
1385 tgt = lmv_get_target(lmv, mds);
1387 RETURN(PTR_ERR(tgt));
1390 * New seq alloc and FLD setup should be atomic. Otherwise we may find
1391 * on server that seq in new allocated fid is not yet known.
1393 mutex_lock(&tgt->ltd_fid_mutex);
1395 if (tgt->ltd_active == 0 || tgt->ltd_exp == NULL)
1396 GOTO(out, rc = -ENODEV);
1399 * Asking underlaying tgt layer to allocate new fid.
1401 rc = obd_fid_alloc(tgt->ltd_exp, fid, NULL);
1403 LASSERT(fid_is_sane(fid));
1409 mutex_unlock(&tgt->ltd_fid_mutex);
1413 int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
1414 struct md_op_data *op_data)
1416 struct obd_device *obd = class_exp2obd(exp);
1417 struct lmv_obd *lmv = &obd->u.lmv;
1422 LASSERT(op_data != NULL);
1423 LASSERT(fid != NULL);
1425 rc = lmv_placement_policy(obd, op_data, &mds);
1427 CERROR("Can't get target for allocating fid, "
1432 rc = __lmv_fid_alloc(lmv, fid, mds);
1434 CERROR("Can't alloc new fid, rc %d\n", rc);
1441 static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
1443 struct lmv_obd *lmv = &obd->u.lmv;
1444 struct lmv_desc *desc;
1448 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
1449 CERROR("LMV setup requires a descriptor\n");
1453 desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1);
1454 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
1455 CERROR("Lmv descriptor size wrong: %d > %d\n",
1456 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
1460 OBD_ALLOC(lmv->tgts, sizeof(*lmv->tgts) * 32);
1461 if (lmv->tgts == NULL)
1463 lmv->tgts_size = 32;
1465 obd_str2uuid(&lmv->desc.ld_uuid, desc->ld_uuid.uuid);
1466 lmv->desc.ld_tgt_count = 0;
1467 lmv->desc.ld_active_tgt_count = 0;
1468 lmv->max_cookiesize = 0;
1469 lmv->max_def_easize = 0;
1470 lmv->max_easize = 0;
1471 lmv->lmv_placement = PLACEMENT_CHAR_POLICY;
1473 spin_lock_init(&lmv->lmv_lock);
1474 mutex_init(&lmv->init_mutex);
1477 obd->obd_vars = lprocfs_lmv_obd_vars;
1478 lprocfs_seq_obd_setup(obd);
1479 lprocfs_alloc_md_stats(obd, 0);
1480 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
1481 0444, &lmv_proc_target_fops, obd);
1483 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
1486 rc = fld_client_init(&lmv->lmv_fld, obd->obd_name,
1487 LUSTRE_CLI_FLD_HASH_DHT);
1489 CERROR("Can't init FLD, err %d\n", rc);
1499 static int lmv_cleanup(struct obd_device *obd)
1501 struct lmv_obd *lmv = &obd->u.lmv;
1504 fld_client_fini(&lmv->lmv_fld);
1505 if (lmv->tgts != NULL) {
1507 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1508 if (lmv->tgts[i] == NULL)
1510 lmv_del_target(lmv, i);
1512 OBD_FREE(lmv->tgts, sizeof(*lmv->tgts) * lmv->tgts_size);
1518 static int lmv_process_config(struct obd_device *obd, obd_count len, void *buf)
1520 struct lustre_cfg *lcfg = buf;
1521 struct obd_uuid obd_uuid;
1527 switch (lcfg->lcfg_command) {
1529 /* modify_mdc_tgts add 0:lustre-clilmv 1:lustre-MDT0000_UUID
1530 * 2:0 3:1 4:lustre-MDT0000-mdc_UUID */
1531 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
1532 GOTO(out, rc = -EINVAL);
1534 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
1536 if (sscanf(lustre_cfg_buf(lcfg, 2), "%u", &index) != 1)
1537 GOTO(out, rc = -EINVAL);
1538 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
1539 GOTO(out, rc = -EINVAL);
1540 rc = lmv_add_target(obd, &obd_uuid, index, gen);
1543 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1544 GOTO(out, rc = -EINVAL);
1550 static int lmv_statfs(const struct lu_env *env, struct obd_export *exp,
1551 struct obd_statfs *osfs, __u64 max_age, __u32 flags)
1553 struct obd_device *obd = class_exp2obd(exp);
1554 struct lmv_obd *lmv = &obd->u.lmv;
1555 struct obd_statfs *temp;
1560 rc = lmv_check_connect(obd);
1564 OBD_ALLOC(temp, sizeof(*temp));
1568 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1569 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1572 rc = obd_statfs(env, lmv->tgts[i]->ltd_exp, temp,
1575 CERROR("can't stat MDS #%d (%s), error %d\n", i,
1576 lmv->tgts[i]->ltd_exp->exp_obd->obd_name,
1578 GOTO(out_free_temp, rc);
1583 /* If the statfs is from mount, it will needs
1584 * retrieve necessary information from MDT0.
1585 * i.e. mount does not need the merged osfs
1587 * And also clients can be mounted as long as
1588 * MDT0 is in service*/
1589 if (flags & OBD_STATFS_FOR_MDT0)
1590 GOTO(out_free_temp, rc);
1592 osfs->os_bavail += temp->os_bavail;
1593 osfs->os_blocks += temp->os_blocks;
1594 osfs->os_ffree += temp->os_ffree;
1595 osfs->os_files += temp->os_files;
1601 OBD_FREE(temp, sizeof(*temp));
1605 static int lmv_getstatus(struct obd_export *exp,
1607 struct obd_capa **pc)
1609 struct obd_device *obd = exp->exp_obd;
1610 struct lmv_obd *lmv = &obd->u.lmv;
1614 rc = lmv_check_connect(obd);
1618 rc = md_getstatus(lmv->tgts[0]->ltd_exp, fid, pc);
1622 static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1623 struct obd_capa *oc, obd_valid valid, const char *name,
1624 const char *input, int input_size, int output_size,
1625 int flags, struct ptlrpc_request **request)
1627 struct obd_device *obd = exp->exp_obd;
1628 struct lmv_obd *lmv = &obd->u.lmv;
1629 struct lmv_tgt_desc *tgt;
1633 rc = lmv_check_connect(obd);
1637 tgt = lmv_find_target(lmv, fid);
1639 RETURN(PTR_ERR(tgt));
1641 rc = md_getxattr(tgt->ltd_exp, fid, oc, valid, name, input,
1642 input_size, output_size, flags, request);
1647 static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1648 struct obd_capa *oc, obd_valid valid, const char *name,
1649 const char *input, int input_size, int output_size,
1650 int flags, __u32 suppgid,
1651 struct ptlrpc_request **request)
1653 struct obd_device *obd = exp->exp_obd;
1654 struct lmv_obd *lmv = &obd->u.lmv;
1655 struct lmv_tgt_desc *tgt;
1659 rc = lmv_check_connect(obd);
1663 tgt = lmv_find_target(lmv, fid);
1665 RETURN(PTR_ERR(tgt));
1667 rc = md_setxattr(tgt->ltd_exp, fid, oc, valid, name, input,
1668 input_size, output_size, flags, suppgid,
1674 static int lmv_getattr(struct obd_export *exp, struct md_op_data *op_data,
1675 struct ptlrpc_request **request)
1677 struct obd_device *obd = exp->exp_obd;
1678 struct lmv_obd *lmv = &obd->u.lmv;
1679 struct lmv_tgt_desc *tgt;
1683 rc = lmv_check_connect(obd);
1687 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1689 RETURN(PTR_ERR(tgt));
1691 if (op_data->op_flags & MF_GET_MDT_IDX) {
1692 op_data->op_mds = tgt->ltd_idx;
1696 rc = md_getattr(tgt->ltd_exp, op_data, request);
1701 static int lmv_null_inode(struct obd_export *exp, const struct lu_fid *fid)
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 md_null_inode(lmv->tgts[i]->ltd_exp, fid);
1729 static int lmv_find_cbdata(struct obd_export *exp, const struct lu_fid *fid,
1730 ldlm_iterator_t it, void *data)
1732 struct obd_device *obd = exp->exp_obd;
1733 struct lmv_obd *lmv = &obd->u.lmv;
1738 rc = lmv_check_connect(obd);
1742 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1745 * With DNE every object can have two locks in different namespaces:
1746 * lookup lock in space of MDT storing direntry and update/open lock in
1747 * space of MDT storing inode.
1749 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1750 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1752 rc = md_find_cbdata(lmv->tgts[i]->ltd_exp, fid, it, data);
1761 static int lmv_close(struct obd_export *exp, struct md_op_data *op_data,
1762 struct md_open_data *mod, struct ptlrpc_request **request)
1764 struct obd_device *obd = exp->exp_obd;
1765 struct lmv_obd *lmv = &obd->u.lmv;
1766 struct lmv_tgt_desc *tgt;
1770 rc = lmv_check_connect(obd);
1774 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1776 RETURN(PTR_ERR(tgt));
1778 CDEBUG(D_INODE, "CLOSE "DFID"\n", PFID(&op_data->op_fid1));
1779 rc = md_close(tgt->ltd_exp, op_data, mod, request);
1784 * Choosing the MDT by name or FID in @op_data.
1785 * For non-striped directory, it will locate MDT by fid.
1786 * For striped-directory, it will locate MDT by name. And also
1787 * it will reset op_fid1 with the FID of the choosen stripe.
1789 struct lmv_tgt_desc *
1790 lmv_locate_target_for_name(struct lmv_obd *lmv, struct lmv_stripe_md *lsm,
1791 const char *name, int namelen, struct lu_fid *fid,
1794 struct lmv_tgt_desc *tgt;
1795 const struct lmv_oinfo *oinfo;
1797 oinfo = lsm_name_to_stripe_info(lsm, name, namelen);
1799 RETURN((void *)oinfo);
1800 *fid = oinfo->lmo_fid;
1801 *mds = oinfo->lmo_mds;
1802 tgt = lmv_get_target(lmv, *mds);
1804 CDEBUG(D_INFO, "locate on mds %u "DFID"\n", *mds, PFID(fid));
1809 *lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1812 struct lmv_stripe_md *lsm = op_data->op_mea1;
1813 struct lmv_tgt_desc *tgt;
1815 if (lsm == NULL || lsm->lsm_md_stripe_count <= 1 ||
1816 op_data->op_namelen == 0 ||
1817 lsm->lsm_md_magic == LMV_MAGIC_MIGRATE) {
1818 tgt = lmv_find_target(lmv, fid);
1822 op_data->op_mds = tgt->ltd_idx;
1826 return lmv_locate_target_for_name(lmv, lsm, op_data->op_name,
1827 op_data->op_namelen, fid,
1831 int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
1832 const void *data, int datalen, int mode, __u32 uid,
1833 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1834 struct ptlrpc_request **request)
1836 struct obd_device *obd = exp->exp_obd;
1837 struct lmv_obd *lmv = &obd->u.lmv;
1838 struct lmv_tgt_desc *tgt;
1842 rc = lmv_check_connect(obd);
1846 if (!lmv->desc.ld_active_tgt_count)
1849 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1851 RETURN(PTR_ERR(tgt));
1853 CDEBUG(D_INODE, "CREATE name '%.*s' on "DFID" -> mds #%x\n",
1854 op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1),
1857 rc = lmv_fid_alloc(exp, &op_data->op_fid2, op_data);
1861 /* Send the create request to the MDT where the object
1862 * will be located */
1863 tgt = lmv_find_target(lmv, &op_data->op_fid2);
1865 RETURN(PTR_ERR(tgt));
1867 op_data->op_mds = tgt->ltd_idx;
1869 CDEBUG(D_INODE, "CREATE obj "DFID" -> mds #%x\n",
1870 PFID(&op_data->op_fid2), op_data->op_mds);
1872 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1873 rc = md_create(tgt->ltd_exp, op_data, data, datalen, mode, uid, gid,
1874 cap_effective, rdev, request);
1876 if (*request == NULL)
1878 CDEBUG(D_INODE, "Created - "DFID"\n", PFID(&op_data->op_fid2));
1883 static int lmv_done_writing(struct obd_export *exp,
1884 struct md_op_data *op_data,
1885 struct md_open_data *mod)
1887 struct obd_device *obd = exp->exp_obd;
1888 struct lmv_obd *lmv = &obd->u.lmv;
1889 struct lmv_tgt_desc *tgt;
1893 rc = lmv_check_connect(obd);
1897 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1899 RETURN(PTR_ERR(tgt));
1901 rc = md_done_writing(tgt->ltd_exp, op_data, mod);
1906 lmv_enqueue_remote(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1907 struct lookup_intent *it, struct md_op_data *op_data,
1908 struct lustre_handle *lockh, void *lmm, int lmmsize,
1909 __u64 extra_lock_flags)
1911 struct ptlrpc_request *req = it->d.lustre.it_data;
1912 struct obd_device *obd = exp->exp_obd;
1913 struct lmv_obd *lmv = &obd->u.lmv;
1914 struct lustre_handle plock;
1915 struct lmv_tgt_desc *tgt;
1916 struct md_op_data *rdata;
1918 struct mdt_body *body;
1923 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1924 LASSERT(body != NULL);
1926 if (!(body->valid & OBD_MD_MDS))
1929 CDEBUG(D_INODE, "REMOTE_ENQUEUE '%s' on "DFID" -> "DFID"\n",
1930 LL_IT2STR(it), PFID(&op_data->op_fid1), PFID(&body->fid1));
1933 * We got LOOKUP lock, but we really need attrs.
1935 pmode = it->d.lustre.it_lock_mode;
1936 LASSERT(pmode != 0);
1937 memcpy(&plock, lockh, sizeof(plock));
1938 it->d.lustre.it_lock_mode = 0;
1939 it->d.lustre.it_data = NULL;
1942 ptlrpc_req_finished(req);
1944 tgt = lmv_find_target(lmv, &fid1);
1946 GOTO(out, rc = PTR_ERR(tgt));
1948 OBD_ALLOC_PTR(rdata);
1950 GOTO(out, rc = -ENOMEM);
1952 rdata->op_fid1 = fid1;
1953 rdata->op_bias = MDS_CROSS_REF;
1955 rc = md_enqueue(tgt->ltd_exp, einfo, it, rdata, lockh,
1956 lmm, lmmsize, NULL, extra_lock_flags);
1957 OBD_FREE_PTR(rdata);
1960 ldlm_lock_decref(&plock, pmode);
1965 lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1966 struct lookup_intent *it, struct md_op_data *op_data,
1967 struct lustre_handle *lockh, void *lmm, int lmmsize,
1968 struct ptlrpc_request **req, __u64 extra_lock_flags)
1970 struct obd_device *obd = exp->exp_obd;
1971 struct lmv_obd *lmv = &obd->u.lmv;
1972 struct lmv_tgt_desc *tgt;
1976 rc = lmv_check_connect(obd);
1980 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID"\n",
1981 LL_IT2STR(it), PFID(&op_data->op_fid1));
1983 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1985 RETURN(PTR_ERR(tgt));
1987 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID" -> mds #%d\n",
1988 LL_IT2STR(it), PFID(&op_data->op_fid1), tgt->ltd_idx);
1990 rc = md_enqueue(tgt->ltd_exp, einfo, it, op_data, lockh,
1991 lmm, lmmsize, req, extra_lock_flags);
1993 if (rc == 0 && it && it->it_op == IT_OPEN) {
1994 rc = lmv_enqueue_remote(exp, einfo, it, op_data, lockh,
1995 lmm, lmmsize, extra_lock_flags);
2001 lmv_getattr_name(struct obd_export *exp,struct md_op_data *op_data,
2002 struct ptlrpc_request **request)
2004 struct ptlrpc_request *req = NULL;
2005 struct obd_device *obd = exp->exp_obd;
2006 struct lmv_obd *lmv = &obd->u.lmv;
2007 struct lmv_tgt_desc *tgt;
2008 struct mdt_body *body;
2012 rc = lmv_check_connect(obd);
2016 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
2018 RETURN(PTR_ERR(tgt));
2020 CDEBUG(D_INODE, "GETATTR_NAME for %*s on "DFID" -> mds #%d\n",
2021 op_data->op_namelen, op_data->op_name, PFID(&op_data->op_fid1),
2024 rc = md_getattr_name(tgt->ltd_exp, op_data, request);
2028 body = req_capsule_server_get(&(*request)->rq_pill,
2030 LASSERT(body != NULL);
2032 if (body->valid & OBD_MD_MDS) {
2033 struct lu_fid rid = body->fid1;
2034 CDEBUG(D_INODE, "Request attrs for "DFID"\n",
2037 tgt = lmv_find_target(lmv, &rid);
2039 ptlrpc_req_finished(*request);
2040 RETURN(PTR_ERR(tgt));
2043 op_data->op_fid1 = rid;
2044 op_data->op_valid |= OBD_MD_FLCROSSREF;
2045 op_data->op_namelen = 0;
2046 op_data->op_name = NULL;
2047 rc = md_getattr_name(tgt->ltd_exp, op_data, &req);
2048 ptlrpc_req_finished(*request);
2055 #define md_op_data_fid(op_data, fl) \
2056 (fl == MF_MDC_CANCEL_FID1 ? &op_data->op_fid1 : \
2057 fl == MF_MDC_CANCEL_FID2 ? &op_data->op_fid2 : \
2058 fl == MF_MDC_CANCEL_FID3 ? &op_data->op_fid3 : \
2059 fl == MF_MDC_CANCEL_FID4 ? &op_data->op_fid4 : \
2062 static int lmv_early_cancel(struct obd_export *exp, struct lmv_tgt_desc *tgt,
2063 struct md_op_data *op_data,
2064 int op_tgt, ldlm_mode_t mode, int bits, int flag)
2066 struct lu_fid *fid = md_op_data_fid(op_data, flag);
2067 struct obd_device *obd = exp->exp_obd;
2068 struct lmv_obd *lmv = &obd->u.lmv;
2069 ldlm_policy_data_t policy = {{ 0 }};
2073 if (!fid_is_sane(fid))
2077 tgt = lmv_find_target(lmv, fid);
2079 RETURN(PTR_ERR(tgt));
2082 if (tgt->ltd_idx != op_tgt) {
2083 CDEBUG(D_INODE, "EARLY_CANCEL on "DFID"\n", PFID(fid));
2084 policy.l_inodebits.bits = bits;
2085 rc = md_cancel_unused(tgt->ltd_exp, fid, &policy,
2086 mode, LCF_ASYNC, NULL);
2089 "EARLY_CANCEL skip operation target %d on "DFID"\n",
2091 op_data->op_flags |= flag;
2099 * llite passes fid of an target inode in op_data->op_fid1 and id of directory in
2102 static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
2103 struct ptlrpc_request **request)
2105 struct obd_device *obd = exp->exp_obd;
2106 struct lmv_obd *lmv = &obd->u.lmv;
2107 struct lmv_tgt_desc *tgt;
2111 rc = lmv_check_connect(obd);
2115 LASSERT(op_data->op_namelen != 0);
2117 CDEBUG(D_INODE, "LINK "DFID":%*s to "DFID"\n",
2118 PFID(&op_data->op_fid2), op_data->op_namelen,
2119 op_data->op_name, PFID(&op_data->op_fid1));
2121 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
2122 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
2123 op_data->op_cap = cfs_curproc_cap_pack();
2124 if (op_data->op_mea2 != NULL) {
2125 struct lmv_stripe_md *lsm = op_data->op_mea2;
2126 const struct lmv_oinfo *oinfo;
2128 oinfo = lsm_name_to_stripe_info(lsm, op_data->op_name,
2129 op_data->op_namelen);
2131 RETURN(PTR_ERR(oinfo));
2133 op_data->op_fid2 = oinfo->lmo_fid;
2136 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
2138 RETURN(PTR_ERR(tgt));
2141 * Cancel UPDATE lock on child (fid1).
2143 op_data->op_flags |= MF_MDC_CANCEL_FID2;
2144 rc = lmv_early_cancel(exp, NULL, op_data, tgt->ltd_idx, LCK_EX,
2145 MDS_INODELOCK_UPDATE, MF_MDC_CANCEL_FID1);
2149 rc = md_link(tgt->ltd_exp, op_data, request);
2154 static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
2155 const char *old, int oldlen, const char *new, int newlen,
2156 struct ptlrpc_request **request)
2158 struct obd_device *obd = exp->exp_obd;
2159 struct lmv_obd *lmv = &obd->u.lmv;
2160 struct lmv_tgt_desc *src_tgt;
2164 LASSERT(oldlen != 0);
2166 CDEBUG(D_INODE, "RENAME %.*s in "DFID":%d to %.*s in "DFID":%d\n",
2167 oldlen, old, PFID(&op_data->op_fid1),
2168 op_data->op_mea1 ? op_data->op_mea1->lsm_md_stripe_count : 0,
2169 newlen, new, PFID(&op_data->op_fid2),
2170 op_data->op_mea2 ? op_data->op_mea2->lsm_md_stripe_count : 0);
2172 rc = lmv_check_connect(obd);
2176 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
2177 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
2178 op_data->op_cap = cfs_curproc_cap_pack();
2179 if (op_data->op_cli_flags & CLI_MIGRATE) {
2180 LASSERTF(fid_is_sane(&op_data->op_fid3), "invalid FID "DFID"\n",
2181 PFID(&op_data->op_fid3));
2182 rc = lmv_fid_alloc(exp, &op_data->op_fid2, op_data);
2185 src_tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid3);
2187 if (op_data->op_mea1 != NULL) {
2188 struct lmv_stripe_md *lsm = op_data->op_mea1;
2190 src_tgt = lmv_locate_target_for_name(lmv, lsm, old,
2194 if (IS_ERR(src_tgt))
2195 RETURN(PTR_ERR(src_tgt));
2197 src_tgt = lmv_find_target(lmv, &op_data->op_fid1);
2198 if (IS_ERR(src_tgt))
2199 RETURN(PTR_ERR(src_tgt));
2201 op_data->op_mds = src_tgt->ltd_idx;
2204 if (op_data->op_mea2) {
2205 struct lmv_stripe_md *lsm = op_data->op_mea2;
2206 const struct lmv_oinfo *oinfo;
2208 oinfo = lsm_name_to_stripe_info(lsm, new, newlen);
2210 RETURN(PTR_ERR(oinfo));
2212 op_data->op_fid2 = oinfo->lmo_fid;
2215 if (IS_ERR(src_tgt))
2216 RETURN(PTR_ERR(src_tgt));
2219 * LOOKUP lock on src child (fid3) should also be cancelled for
2220 * src_tgt in mdc_rename.
2222 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2225 * Cancel UPDATE locks on tgt parent (fid2), tgt_tgt is its
2228 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
2229 LCK_EX, MDS_INODELOCK_UPDATE,
2230 MF_MDC_CANCEL_FID2);
2235 * Cancel LOOKUP locks on source child (fid3) for parent tgt_tgt.
2237 if (fid_is_sane(&op_data->op_fid3)) {
2238 struct lmv_tgt_desc *tgt;
2240 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2242 RETURN(PTR_ERR(tgt));
2244 /* Cancel LOOKUP lock on its parent */
2245 rc = lmv_early_cancel(exp, tgt, op_data, src_tgt->ltd_idx,
2246 LCK_EX, MDS_INODELOCK_LOOKUP,
2247 MF_MDC_CANCEL_FID3);
2251 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
2252 LCK_EX, MDS_INODELOCK_FULL,
2253 MF_MDC_CANCEL_FID3);
2259 * Cancel all the locks on tgt child (fid4).
2261 if (fid_is_sane(&op_data->op_fid4))
2262 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
2263 LCK_EX, MDS_INODELOCK_FULL,
2264 MF_MDC_CANCEL_FID4);
2266 CDEBUG(D_INODE, DFID":m%d to "DFID"\n", PFID(&op_data->op_fid1),
2267 op_data->op_mds, PFID(&op_data->op_fid2));
2269 rc = md_rename(src_tgt->ltd_exp, op_data, old, oldlen, new, newlen,
2275 static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
2276 void *ea, int ealen, void *ea2, int ea2len,
2277 struct ptlrpc_request **request,
2278 struct md_open_data **mod)
2280 struct obd_device *obd = exp->exp_obd;
2281 struct lmv_obd *lmv = &obd->u.lmv;
2282 struct lmv_tgt_desc *tgt;
2286 rc = lmv_check_connect(obd);
2290 CDEBUG(D_INODE, "SETATTR for "DFID", valid 0x%x\n",
2291 PFID(&op_data->op_fid1), op_data->op_attr.ia_valid);
2293 op_data->op_flags |= MF_MDC_CANCEL_FID1;
2294 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2296 RETURN(PTR_ERR(tgt));
2298 rc = md_setattr(tgt->ltd_exp, op_data, ea, ealen, ea2,
2299 ea2len, request, mod);
2304 static int lmv_fsync(struct obd_export *exp, const struct lu_fid *fid,
2305 struct obd_capa *oc, struct ptlrpc_request **request)
2307 struct obd_device *obd = exp->exp_obd;
2308 struct lmv_obd *lmv = &obd->u.lmv;
2309 struct lmv_tgt_desc *tgt;
2313 rc = lmv_check_connect(obd);
2317 tgt = lmv_find_target(lmv, fid);
2319 RETURN(PTR_ERR(tgt));
2321 rc = md_fsync(tgt->ltd_exp, fid, oc, request);
2326 * Adjust a set of pages, each page containing an array of lu_dirpages,
2327 * so that each page can be used as a single logical lu_dirpage.
2329 * A lu_dirpage is laid out as follows, where s = ldp_hash_start,
2330 * e = ldp_hash_end, f = ldp_flags, p = padding, and each "ent" is a
2331 * struct lu_dirent. It has size up to LU_PAGE_SIZE. The ldp_hash_end
2332 * value is used as a cookie to request the next lu_dirpage in a
2333 * directory listing that spans multiple pages (two in this example):
2336 * .|--------v------- -----.
2337 * |s|e|f|p|ent|ent| ... |ent|
2338 * '--|-------------- -----' Each CFS_PAGE contains a single
2339 * '------. lu_dirpage.
2340 * .---------v------- -----.
2341 * |s|e|f|p|ent| 0 | ... | 0 |
2342 * '----------------- -----'
2344 * However, on hosts where the native VM page size (PAGE_CACHE_SIZE) is
2345 * larger than LU_PAGE_SIZE, a single host page may contain multiple
2346 * lu_dirpages. After reading the lu_dirpages from the MDS, the
2347 * ldp_hash_end of the first lu_dirpage refers to the one immediately
2348 * after it in the same CFS_PAGE (arrows simplified for brevity, but
2349 * in general e0==s1, e1==s2, etc.):
2351 * .-------------------- -----.
2352 * |s0|e0|f0|p|ent|ent| ... |ent|
2353 * |---v---------------- -----|
2354 * |s1|e1|f1|p|ent|ent| ... |ent|
2355 * |---v---------------- -----| Here, each CFS_PAGE contains
2356 * ... multiple lu_dirpages.
2357 * |---v---------------- -----|
2358 * |s'|e'|f'|p|ent|ent| ... |ent|
2359 * '---|---------------- -----'
2361 * .----------------------------.
2364 * This structure is transformed into a single logical lu_dirpage as follows:
2366 * - Replace e0 with e' so the request for the next lu_dirpage gets the page
2367 * labeled 'next CFS_PAGE'.
2369 * - Copy the LDF_COLLIDE flag from f' to f0 to correctly reflect whether
2370 * a hash collision with the next page exists.
2372 * - Adjust the lde_reclen of the ending entry of each lu_dirpage to span
2373 * to the first entry of the next lu_dirpage.
2375 #if PAGE_CACHE_SIZE > LU_PAGE_SIZE
2376 static void lmv_adjust_dirpages(struct page **pages, int ncfspgs, int nlupgs)
2380 for (i = 0; i < ncfspgs; i++) {
2381 struct lu_dirpage *dp = kmap(pages[i]);
2382 struct lu_dirpage *first = dp;
2383 struct lu_dirent *end_dirent = NULL;
2384 struct lu_dirent *ent;
2385 __u64 hash_end = dp->ldp_hash_end;
2386 __u32 flags = dp->ldp_flags;
2388 while (--nlupgs > 0) {
2389 ent = lu_dirent_start(dp);
2390 for (end_dirent = ent; ent != NULL;
2391 end_dirent = ent, ent = lu_dirent_next(ent));
2393 /* Advance dp to next lu_dirpage. */
2394 dp = (struct lu_dirpage *)((char *)dp + LU_PAGE_SIZE);
2396 /* Check if we've reached the end of the CFS_PAGE. */
2397 if (!((unsigned long)dp & ~CFS_PAGE_MASK))
2400 /* Save the hash and flags of this lu_dirpage. */
2401 hash_end = dp->ldp_hash_end;
2402 flags = dp->ldp_flags;
2404 /* Check if lu_dirpage contains no entries. */
2408 /* Enlarge the end entry lde_reclen from 0 to
2409 * first entry of next lu_dirpage. */
2410 LASSERT(le16_to_cpu(end_dirent->lde_reclen) == 0);
2411 end_dirent->lde_reclen =
2412 cpu_to_le16((char *)(dp->ldp_entries) -
2413 (char *)end_dirent);
2416 first->ldp_hash_end = hash_end;
2417 first->ldp_flags &= ~cpu_to_le32(LDF_COLLIDE);
2418 first->ldp_flags |= flags & cpu_to_le32(LDF_COLLIDE);
2422 LASSERTF(nlupgs == 0, "left = %d", nlupgs);
2425 #define lmv_adjust_dirpages(pages, ncfspgs, nlupgs) do {} while (0)
2426 #endif /* PAGE_CACHE_SIZE > LU_PAGE_SIZE */
2428 #define NORMAL_MAX_STRIPES 4
2429 int lmv_read_entry(struct obd_export *exp, struct md_op_data *op_data,
2430 struct md_callback *cb_op, struct lu_dirent **ldp,
2431 struct page **ppage)
2433 struct obd_device *obd = exp->exp_obd;
2434 struct lmv_obd *lmv = &obd->u.lmv;
2435 struct lmv_stripe_md *lsm = op_data->op_mea1;
2436 struct lu_dirent *tmp_ents[NORMAL_MAX_STRIPES];
2437 struct lu_dirent **ents = NULL;
2441 struct page *min_page = NULL;
2446 rc = lmv_check_connect(obd);
2453 stripe_count = lsm->lsm_md_stripe_count;
2455 if (stripe_count > NORMAL_MAX_STRIPES) {
2456 OBD_ALLOC(ents, sizeof(ents[0]) * stripe_count);
2458 GOTO(out, rc = -ENOMEM);
2461 memset(ents, 0, sizeof(ents[0]) * stripe_count);
2464 min_hash = MDS_DIR_END_OFF;
2465 for (i = 0; i < stripe_count; i++) {
2466 struct lmv_tgt_desc *tgt;
2467 struct page *page = NULL;
2469 if (likely(lsm == NULL)) {
2470 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2472 GOTO(out, rc = PTR_ERR(tgt));
2473 LASSERT(op_data->op_data != NULL);
2475 tgt = lmv_get_target(lmv, lsm->lsm_md_oinfo[i].lmo_mds);
2477 GOTO(out, rc = PTR_ERR(tgt));
2478 op_data->op_fid1 = lsm->lsm_md_oinfo[i].lmo_fid;
2479 op_data->op_fid2 = lsm->lsm_md_oinfo[i].lmo_fid;
2480 op_data->op_stripe_offset = i;
2483 rc = md_read_entry(tgt->ltd_exp, op_data, cb_op, &ents[i],
2488 if (ents[i] != NULL &&
2489 le64_to_cpu(ents[i]->lde_hash) <= min_hash) {
2490 if (min_page != NULL)
2491 page_cache_release(min_page);
2493 min_hash = le64_to_cpu(ents[i]->lde_hash);
2498 if (min_hash != MDS_DIR_END_OFF)
2499 *ldp = ents[min_idx];
2503 if (stripe_count > NORMAL_MAX_STRIPES && ents != NULL)
2504 OBD_FREE(ents, sizeof(ents[0]) * stripe_count);
2506 if (rc != 0 && min_page != NULL) {
2508 page_cache_release(min_page);
2516 static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
2517 struct ptlrpc_request **request)
2519 struct obd_device *obd = exp->exp_obd;
2520 struct lmv_obd *lmv = &obd->u.lmv;
2521 struct lmv_tgt_desc *tgt = NULL;
2522 struct lmv_tgt_desc *parent_tgt = NULL;
2523 struct mdt_body *body;
2527 rc = lmv_check_connect(obd);
2531 /* Send unlink requests to the MDT where the child is located */
2532 if (likely(!fid_is_zero(&op_data->op_fid2))) {
2533 tgt = lmv_find_target(lmv, &op_data->op_fid2);
2535 RETURN(PTR_ERR(tgt));
2537 /* For striped dir, we need to locate the parent as well */
2538 if (op_data->op_mea1 != NULL &&
2539 op_data->op_mea1->lsm_md_stripe_count > 1) {
2540 struct lmv_tgt_desc *tmp;
2542 LASSERT(op_data->op_name != NULL &&
2543 op_data->op_namelen != 0);
2544 tmp = lmv_locate_target_for_name(lmv,
2547 op_data->op_namelen,
2551 RETURN(PTR_ERR(tmp));
2554 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
2556 RETURN(PTR_ERR(tgt));
2559 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
2560 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
2561 op_data->op_cap = cfs_curproc_cap_pack();
2564 * If child's fid is given, cancel unused locks for it if it is from
2565 * another export than parent.
2567 * LOOKUP lock for child (fid3) should also be cancelled on parent
2568 * tgt_tgt in mdc_unlink().
2570 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2573 * Cancel FULL locks on child (fid3).
2575 parent_tgt = lmv_find_target(lmv, &op_data->op_fid1);
2576 if (IS_ERR(parent_tgt))
2577 RETURN(PTR_ERR(parent_tgt));
2579 if (parent_tgt != tgt) {
2580 rc = lmv_early_cancel(exp, parent_tgt, op_data, tgt->ltd_idx,
2581 LCK_EX, MDS_INODELOCK_LOOKUP,
2582 MF_MDC_CANCEL_FID3);
2585 rc = lmv_early_cancel(exp, NULL, op_data, tgt->ltd_idx, LCK_EX,
2586 MDS_INODELOCK_FULL, MF_MDC_CANCEL_FID3);
2590 CDEBUG(D_INODE, "unlink with fid="DFID"/"DFID" -> mds #%d\n",
2591 PFID(&op_data->op_fid1), PFID(&op_data->op_fid2), tgt->ltd_idx);
2593 rc = md_unlink(tgt->ltd_exp, op_data, request);
2594 if (rc != 0 && rc != -EREMOTE)
2597 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
2601 /* Not cross-ref case, just get out of here. */
2602 if (likely(!(body->valid & OBD_MD_MDS)))
2605 CDEBUG(D_INODE, "%s: try unlink to another MDT for "DFID"\n",
2606 exp->exp_obd->obd_name, PFID(&body->fid1));
2608 /* This is a remote object, try remote MDT, Note: it may
2609 * try more than 1 time here, Considering following case
2610 * /mnt/lustre is root on MDT0, remote1 is on MDT1
2611 * 1. Initially A does not know where remote1 is, it send
2612 * unlink RPC to MDT0, MDT0 return -EREMOTE, it will
2613 * resend unlink RPC to MDT1 (retry 1st time).
2615 * 2. During the unlink RPC in flight,
2616 * client B mv /mnt/lustre/remote1 /mnt/lustre/remote2
2617 * and create new remote1, but on MDT0
2619 * 3. MDT1 get unlink RPC(from A), then do remote lock on
2620 * /mnt/lustre, then lookup get fid of remote1, and find
2621 * it is remote dir again, and replay -EREMOTE again.
2623 * 4. Then A will resend unlink RPC to MDT0. (retry 2nd times).
2625 * In theory, it might try unlimited time here, but it should
2626 * be very rare case. */
2627 op_data->op_fid2 = body->fid1;
2628 ptlrpc_req_finished(*request);
2634 static int lmv_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2636 struct lmv_obd *lmv = &obd->u.lmv;
2640 case OBD_CLEANUP_EARLY:
2641 /* XXX: here should be calling obd_precleanup() down to
2644 case OBD_CLEANUP_EXPORTS:
2645 fld_client_proc_fini(&lmv->lmv_fld);
2646 lprocfs_obd_cleanup(obd);
2647 lprocfs_free_md_stats(obd);
2655 static int lmv_get_info(const struct lu_env *env, struct obd_export *exp,
2656 __u32 keylen, void *key, __u32 *vallen, void *val,
2657 struct lov_stripe_md *lsm)
2659 struct obd_device *obd;
2660 struct lmv_obd *lmv;
2664 obd = class_exp2obd(exp);
2666 CDEBUG(D_IOCTL, "Invalid client cookie "LPX64"\n",
2667 exp->exp_handle.h_cookie);
2672 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
2675 rc = lmv_check_connect(obd);
2679 LASSERT(*vallen == sizeof(__u32));
2680 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2681 struct lmv_tgt_desc *tgt = lmv->tgts[i];
2683 * All tgts should be connected when this gets called.
2685 if (tgt == NULL || tgt->ltd_exp == NULL)
2688 if (!obd_get_info(env, tgt->ltd_exp, keylen, key,
2693 } else if (KEY_IS(KEY_MAX_EASIZE) ||
2694 KEY_IS(KEY_DEFAULT_EASIZE) ||
2695 KEY_IS(KEY_MAX_COOKIESIZE) ||
2696 KEY_IS(KEY_DEFAULT_COOKIESIZE) ||
2697 KEY_IS(KEY_CONN_DATA)) {
2698 rc = lmv_check_connect(obd);
2703 * Forwarding this request to first MDS, it should know LOV
2706 rc = obd_get_info(env, lmv->tgts[0]->ltd_exp, keylen, key,
2708 if (!rc && KEY_IS(KEY_CONN_DATA))
2709 exp->exp_connect_data = *(struct obd_connect_data *)val;
2711 } else if (KEY_IS(KEY_TGT_COUNT)) {
2712 *((int *)val) = lmv->desc.ld_tgt_count;
2716 CDEBUG(D_IOCTL, "Invalid key\n");
2720 int lmv_set_info_async(const struct lu_env *env, struct obd_export *exp,
2721 obd_count keylen, void *key, obd_count vallen,
2722 void *val, struct ptlrpc_request_set *set)
2724 struct lmv_tgt_desc *tgt = NULL;
2725 struct obd_device *obd;
2726 struct lmv_obd *lmv;
2730 obd = class_exp2obd(exp);
2732 CDEBUG(D_IOCTL, "Invalid client cookie "LPX64"\n",
2733 exp->exp_handle.h_cookie);
2738 if (KEY_IS(KEY_READ_ONLY) || KEY_IS(KEY_FLUSH_CTX)) {
2741 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2744 if (tgt == NULL || tgt->ltd_exp == NULL)
2747 err = obd_set_info_async(env, tgt->ltd_exp,
2748 keylen, key, vallen, val, set);
2759 static int lmv_pack_md_v1(const struct lmv_stripe_md *lsm,
2760 struct lmv_mds_md_v1 *lmm1)
2765 lmm1->lmv_magic = cpu_to_le32(lsm->lsm_md_magic);
2766 lmm1->lmv_stripe_count = cpu_to_le32(lsm->lsm_md_stripe_count);
2767 lmm1->lmv_master_mdt_index = cpu_to_le32(lsm->lsm_md_master_mdt_index);
2768 lmm1->lmv_hash_type = cpu_to_le32(lsm->lsm_md_hash_type);
2769 cplen = strlcpy(lmm1->lmv_pool_name, lsm->lsm_md_pool_name,
2770 sizeof(lmm1->lmv_pool_name));
2771 if (cplen >= sizeof(lmm1->lmv_pool_name))
2774 for (i = 0; i < lsm->lsm_md_stripe_count; i++)
2775 fid_cpu_to_le(&lmm1->lmv_stripe_fids[i],
2776 &lsm->lsm_md_oinfo[i].lmo_fid);
2780 int lmv_pack_md(union lmv_mds_md **lmmp, const struct lmv_stripe_md *lsm,
2784 bool allocated = false;
2788 LASSERT(lmmp != NULL);
2790 if (*lmmp != NULL && lsm == NULL) {
2793 stripe_count = lmv_mds_md_stripe_count_get(*lmmp);
2794 lmm_size = lmv_mds_md_size(stripe_count,
2795 le32_to_cpu((*lmmp)->lmv_magic));
2798 OBD_FREE(*lmmp, lmm_size);
2804 if (*lmmp == NULL && lsm == NULL) {
2805 lmm_size = lmv_mds_md_size(stripe_count, LMV_MAGIC);
2806 LASSERT(lmm_size > 0);
2807 OBD_ALLOC(*lmmp, lmm_size);
2810 lmv_mds_md_stripe_count_set(*lmmp, stripe_count);
2811 (*lmmp)->lmv_magic = cpu_to_le32(LMV_MAGIC);
2816 LASSERT(lsm != NULL);
2817 lmm_size = lmv_mds_md_size(lsm->lsm_md_stripe_count, lsm->lsm_md_magic);
2818 if (*lmmp == NULL) {
2819 OBD_ALLOC(*lmmp, lmm_size);
2825 switch (lsm->lsm_md_magic) {
2827 rc = lmv_pack_md_v1(lsm, &(*lmmp)->lmv_md_v1);
2834 if (rc != 0 && allocated) {
2835 OBD_FREE(*lmmp, lmm_size);
2841 EXPORT_SYMBOL(lmv_pack_md);
2843 static int lmv_unpack_md_v1(struct obd_export *exp, struct lmv_stripe_md *lsm,
2844 const struct lmv_mds_md_v1 *lmm1)
2846 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2853 lsm->lsm_md_magic = le32_to_cpu(lmm1->lmv_magic);
2854 lsm->lsm_md_stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
2855 lsm->lsm_md_master_mdt_index = le32_to_cpu(lmm1->lmv_master_mdt_index);
2856 lsm->lsm_md_hash_type = le32_to_cpu(lmm1->lmv_hash_type);
2857 lsm->lsm_md_layout_version = le32_to_cpu(lmm1->lmv_layout_version);
2858 cplen = strlcpy(lsm->lsm_md_pool_name, lmm1->lmv_pool_name,
2859 sizeof(lsm->lsm_md_pool_name));
2861 if (cplen >= sizeof(lsm->lsm_md_pool_name))
2864 CDEBUG(D_INFO, "unpack lsm count %d, master %d hash_type %d"
2865 "layout_version %d\n", lsm->lsm_md_stripe_count,
2866 lsm->lsm_md_master_mdt_index, lsm->lsm_md_hash_type,
2867 lsm->lsm_md_layout_version);
2869 stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
2870 for (i = 0; i < le32_to_cpu(stripe_count); i++) {
2871 fid_le_to_cpu(&lsm->lsm_md_oinfo[i].lmo_fid,
2872 &lmm1->lmv_stripe_fids[i]);
2873 rc = lmv_fld_lookup(lmv, &lsm->lsm_md_oinfo[i].lmo_fid,
2874 &lsm->lsm_md_oinfo[i].lmo_mds);
2877 CDEBUG(D_INFO, "unpack fid #%d "DFID"\n", i,
2878 PFID(&lsm->lsm_md_oinfo[i].lmo_fid));
2884 int lmv_unpack_md(struct obd_export *exp, struct lmv_stripe_md **lsmp,
2885 const union lmv_mds_md *lmm, int stripe_count)
2887 struct lmv_stripe_md *lsm;
2890 bool allocated = false;
2893 LASSERT(lsmp != NULL);
2897 if (lsm != NULL && lmm == NULL) {
2900 for (i = 1; i < lsm->lsm_md_stripe_count; i++) {
2901 if (lsm->lsm_md_oinfo[i].lmo_root != NULL)
2902 iput(lsm->lsm_md_oinfo[i].lmo_root);
2905 lsm_size = lmv_stripe_md_size(lsm->lsm_md_stripe_count);
2906 OBD_FREE(lsm, lsm_size);
2912 if (lsm == NULL && lmm == NULL) {
2913 lsm_size = lmv_stripe_md_size(stripe_count);
2914 OBD_ALLOC(lsm, lsm_size);
2917 lsm->lsm_md_stripe_count = stripe_count;
2923 if (le32_to_cpu(lmm->lmv_magic) != LMV_MAGIC_V1 &&
2924 le32_to_cpu(lmm->lmv_magic) != LMV_MAGIC_MIGRATE &&
2925 le32_to_cpu(lmm->lmv_magic) != LMV_USER_MAGIC) {
2926 CERROR("%s: invalid lmv magic %x: rc = %d\n",
2927 exp->exp_obd->obd_name, le32_to_cpu(lmm->lmv_magic),
2932 if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_V1 ||
2933 le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_MIGRATE)
2934 lsm_size = lmv_stripe_md_size(lmv_mds_md_stripe_count_get(lmm));
2937 * Unpack default dirstripe(lmv_user_md) to lmv_stripe_md,
2938 * stripecount should be 0 then.
2940 lsm_size = lmv_stripe_md_size(0);
2942 lsm_size = lmv_stripe_md_size(lmv_mds_md_stripe_count_get(lmm));
2944 OBD_ALLOC(lsm, lsm_size);
2951 switch (le32_to_cpu(lmm->lmv_magic)) {
2953 case LMV_MAGIC_MIGRATE:
2954 rc = lmv_unpack_md_v1(exp, lsm, &lmm->lmv_md_v1);
2957 CERROR("%s: unrecognized magic %x\n", exp->exp_obd->obd_name,
2958 le32_to_cpu(lmm->lmv_magic));
2963 if (rc != 0 && allocated) {
2964 OBD_FREE(lsm, lsm_size);
2971 int lmv_alloc_memmd(struct lmv_stripe_md **lsmp, int stripes)
2973 return lmv_unpack_md(NULL, lsmp, NULL, stripes);
2975 EXPORT_SYMBOL(lmv_alloc_memmd);
2977 void lmv_free_memmd(struct lmv_stripe_md *lsm)
2979 lmv_unpack_md(NULL, &lsm, NULL, 0);
2981 EXPORT_SYMBOL(lmv_free_memmd);
2983 int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
2984 struct lov_mds_md *lmm, int disk_len)
2986 return lmv_unpack_md(exp, (struct lmv_stripe_md **)lsmp,
2987 (union lmv_mds_md *)lmm, disk_len);
2990 int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
2991 struct lov_stripe_md *lsm)
2993 struct obd_device *obd = exp->exp_obd;
2994 struct lmv_obd *lmv_obd = &obd->u.lmv;
2995 const struct lmv_stripe_md *lmv = (struct lmv_stripe_md *)lsm;
3000 stripe_count = lmv->lsm_md_stripe_count;
3002 stripe_count = lmv_obd->desc.ld_tgt_count;
3004 return lmv_mds_md_size(stripe_count, LMV_MAGIC_V1);
3007 return lmv_pack_md((union lmv_mds_md **)lmmp, lmv, 0);
3010 static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
3011 ldlm_policy_data_t *policy, ldlm_mode_t mode,
3012 ldlm_cancel_flags_t flags, void *opaque)
3014 struct obd_device *obd = exp->exp_obd;
3015 struct lmv_obd *lmv = &obd->u.lmv;
3021 LASSERT(fid != NULL);
3023 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
3024 struct lmv_tgt_desc *tgt = lmv->tgts[i];
3026 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
3029 err = md_cancel_unused(tgt->ltd_exp, fid, policy, mode, flags,
3037 int lmv_set_lock_data(struct obd_export *exp, __u64 *lockh, void *data,
3040 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
3041 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3045 if (tgt == NULL || tgt->ltd_exp == NULL)
3047 rc = md_set_lock_data(tgt->ltd_exp, lockh, data, bits);
3051 ldlm_mode_t lmv_lock_match(struct obd_export *exp, __u64 flags,
3052 const struct lu_fid *fid, ldlm_type_t type,
3053 ldlm_policy_data_t *policy, ldlm_mode_t mode,
3054 struct lustre_handle *lockh)
3056 struct obd_device *obd = exp->exp_obd;
3057 struct lmv_obd *lmv = &obd->u.lmv;
3062 CDEBUG(D_INODE, "Lock match for "DFID"\n", PFID(fid));
3065 * With CMD every object can have two locks in different namespaces:
3066 * lookup lock in space of mds storing direntry and update/open lock in
3067 * space of mds storing inode. Thus we check all targets, not only that
3068 * one fid was created in.
3070 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
3071 struct lmv_tgt_desc *tgt = lmv->tgts[i];
3073 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
3076 rc = md_lock_match(tgt->ltd_exp, flags, fid, type, policy, mode,
3085 int lmv_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
3086 struct obd_export *dt_exp, struct obd_export *md_exp,
3087 struct lustre_md *md)
3089 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
3090 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3092 if (tgt == NULL || tgt->ltd_exp == NULL)
3095 return md_get_lustre_md(lmv->tgts[0]->ltd_exp, req, dt_exp, md_exp, md);
3098 int lmv_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
3100 struct obd_device *obd = exp->exp_obd;
3101 struct lmv_obd *lmv = &obd->u.lmv;
3102 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3105 if (md->lmv != NULL) {
3106 lmv_free_memmd(md->lmv);
3109 if (tgt == NULL || tgt->ltd_exp == NULL)
3111 RETURN(md_free_lustre_md(lmv->tgts[0]->ltd_exp, md));
3114 int lmv_set_open_replay_data(struct obd_export *exp,
3115 struct obd_client_handle *och,
3116 struct lookup_intent *it)
3118 struct obd_device *obd = exp->exp_obd;
3119 struct lmv_obd *lmv = &obd->u.lmv;
3120 struct lmv_tgt_desc *tgt;
3123 tgt = lmv_find_target(lmv, &och->och_fid);
3125 RETURN(PTR_ERR(tgt));
3127 RETURN(md_set_open_replay_data(tgt->ltd_exp, och, it));
3130 int lmv_clear_open_replay_data(struct obd_export *exp,
3131 struct obd_client_handle *och)
3133 struct obd_device *obd = exp->exp_obd;
3134 struct lmv_obd *lmv = &obd->u.lmv;
3135 struct lmv_tgt_desc *tgt;
3138 tgt = lmv_find_target(lmv, &och->och_fid);
3140 RETURN(PTR_ERR(tgt));
3142 RETURN(md_clear_open_replay_data(tgt->ltd_exp, och));
3145 static int lmv_get_remote_perm(struct obd_export *exp,
3146 const struct lu_fid *fid,
3147 struct obd_capa *oc, __u32 suppgid,
3148 struct ptlrpc_request **request)
3150 struct obd_device *obd = exp->exp_obd;
3151 struct lmv_obd *lmv = &obd->u.lmv;
3152 struct lmv_tgt_desc *tgt;
3156 rc = lmv_check_connect(obd);
3160 tgt = lmv_find_target(lmv, fid);
3162 RETURN(PTR_ERR(tgt));
3164 rc = md_get_remote_perm(tgt->ltd_exp, fid, oc, suppgid, request);
3168 static int lmv_renew_capa(struct obd_export *exp, struct obd_capa *oc,
3171 struct obd_device *obd = exp->exp_obd;
3172 struct lmv_obd *lmv = &obd->u.lmv;
3173 struct lmv_tgt_desc *tgt;
3177 rc = lmv_check_connect(obd);
3181 tgt = lmv_find_target(lmv, &oc->c_capa.lc_fid);
3183 RETURN(PTR_ERR(tgt));
3185 rc = md_renew_capa(tgt->ltd_exp, oc, cb);
3189 int lmv_unpack_capa(struct obd_export *exp, struct ptlrpc_request *req,
3190 const struct req_msg_field *field, struct obd_capa **oc)
3192 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
3193 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3195 if (tgt == NULL || tgt->ltd_exp == NULL)
3197 return md_unpack_capa(tgt->ltd_exp, req, field, oc);
3200 int lmv_intent_getattr_async(struct obd_export *exp,
3201 struct md_enqueue_info *minfo,
3202 struct ldlm_enqueue_info *einfo)
3204 struct md_op_data *op_data = &minfo->mi_data;
3205 struct obd_device *obd = exp->exp_obd;
3206 struct lmv_obd *lmv = &obd->u.lmv;
3207 struct lmv_tgt_desc *tgt = NULL;
3211 rc = lmv_check_connect(obd);
3215 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
3217 RETURN(PTR_ERR(tgt));
3219 rc = md_intent_getattr_async(tgt->ltd_exp, minfo, einfo);
3223 int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
3224 struct lu_fid *fid, __u64 *bits)
3226 struct obd_device *obd = exp->exp_obd;
3227 struct lmv_obd *lmv = &obd->u.lmv;
3228 struct lmv_tgt_desc *tgt;
3232 rc = lmv_check_connect(obd);
3236 tgt = lmv_find_target(lmv, fid);
3238 RETURN(PTR_ERR(tgt));
3240 rc = md_revalidate_lock(tgt->ltd_exp, it, fid, bits);
3245 * For lmv, only need to send request to master MDT, and the master MDT will
3246 * process with other slave MDTs. The only exception is Q_GETOQUOTA for which
3247 * we directly fetch data from the slave MDTs.
3249 int lmv_quotactl(struct obd_device *unused, struct obd_export *exp,
3250 struct obd_quotactl *oqctl)
3252 struct obd_device *obd = class_exp2obd(exp);
3253 struct lmv_obd *lmv = &obd->u.lmv;
3254 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3257 __u64 curspace, curinodes;
3261 tgt->ltd_exp == NULL ||
3263 lmv->desc.ld_tgt_count == 0) {
3264 CERROR("master lmv inactive\n");
3268 if (oqctl->qc_cmd != Q_GETOQUOTA) {
3269 rc = obd_quotactl(tgt->ltd_exp, oqctl);
3273 curspace = curinodes = 0;
3274 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
3278 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
3281 err = obd_quotactl(tgt->ltd_exp, oqctl);
3283 CERROR("getquota on mdt %d failed. %d\n", i, err);
3287 curspace += oqctl->qc_dqblk.dqb_curspace;
3288 curinodes += oqctl->qc_dqblk.dqb_curinodes;
3291 oqctl->qc_dqblk.dqb_curspace = curspace;
3292 oqctl->qc_dqblk.dqb_curinodes = curinodes;
3297 int lmv_quotacheck(struct obd_device *unused, struct obd_export *exp,
3298 struct obd_quotactl *oqctl)
3300 struct obd_device *obd = class_exp2obd(exp);
3301 struct lmv_obd *lmv = &obd->u.lmv;
3302 struct lmv_tgt_desc *tgt;
3307 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
3310 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active) {
3311 CERROR("lmv idx %d inactive\n", i);
3315 err = obd_quotacheck(tgt->ltd_exp, oqctl);
3323 int lmv_update_lsm_md(struct obd_export *exp, struct lmv_stripe_md *lsm,
3324 struct mdt_body *body, ldlm_blocking_callback cb_blocking)
3326 if (lsm->lsm_md_stripe_count <= 1)
3329 return lmv_revalidate_slaves(exp, body, lsm, cb_blocking, 0);
3332 int lmv_merge_attr(struct obd_export *exp, const struct lmv_stripe_md *lsm,
3333 struct cl_attr *attr)
3338 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
3339 struct inode *inode = lsm->lsm_md_oinfo[i].lmo_root;
3341 CDEBUG(D_INFO, ""DFID" size %llu, nlink %u, atime %lu ctime"
3342 "%lu, mtime %lu.\n", PFID(&lsm->lsm_md_oinfo[i].lmo_fid),
3343 i_size_read(inode), inode->i_nlink,
3344 LTIME_S(inode->i_atime), LTIME_S(inode->i_ctime),
3345 LTIME_S(inode->i_mtime));
3347 /* for slave stripe, it needs to subtract nlink for . and .. */
3349 attr->cat_nlink += inode->i_nlink - 2;
3351 attr->cat_nlink = inode->i_nlink;
3353 attr->cat_size += i_size_read(inode);
3355 if (attr->cat_atime < LTIME_S(inode->i_atime))
3356 attr->cat_atime = LTIME_S(inode->i_atime);
3358 if (attr->cat_ctime < LTIME_S(inode->i_ctime))
3359 attr->cat_ctime = LTIME_S(inode->i_ctime);
3361 if (attr->cat_mtime < LTIME_S(inode->i_mtime))
3362 attr->cat_mtime = LTIME_S(inode->i_mtime);
3368 struct obd_ops lmv_obd_ops = {
3369 .o_owner = THIS_MODULE,
3370 .o_setup = lmv_setup,
3371 .o_cleanup = lmv_cleanup,
3372 .o_precleanup = lmv_precleanup,
3373 .o_process_config = lmv_process_config,
3374 .o_connect = lmv_connect,
3375 .o_disconnect = lmv_disconnect,
3376 .o_statfs = lmv_statfs,
3377 .o_get_info = lmv_get_info,
3378 .o_set_info_async = lmv_set_info_async,
3379 .o_packmd = lmv_packmd,
3380 .o_unpackmd = lmv_unpackmd,
3381 .o_notify = lmv_notify,
3382 .o_get_uuid = lmv_get_uuid,
3383 .o_iocontrol = lmv_iocontrol,
3384 .o_quotacheck = lmv_quotacheck,
3385 .o_quotactl = lmv_quotactl
3388 struct md_ops lmv_md_ops = {
3389 .m_getstatus = lmv_getstatus,
3390 .m_null_inode = lmv_null_inode,
3391 .m_find_cbdata = lmv_find_cbdata,
3392 .m_close = lmv_close,
3393 .m_create = lmv_create,
3394 .m_done_writing = lmv_done_writing,
3395 .m_enqueue = lmv_enqueue,
3396 .m_getattr = lmv_getattr,
3397 .m_getxattr = lmv_getxattr,
3398 .m_getattr_name = lmv_getattr_name,
3399 .m_intent_lock = lmv_intent_lock,
3401 .m_rename = lmv_rename,
3402 .m_setattr = lmv_setattr,
3403 .m_setxattr = lmv_setxattr,
3404 .m_fsync = lmv_fsync,
3405 .m_read_entry = lmv_read_entry,
3406 .m_unlink = lmv_unlink,
3407 .m_init_ea_size = lmv_init_ea_size,
3408 .m_cancel_unused = lmv_cancel_unused,
3409 .m_set_lock_data = lmv_set_lock_data,
3410 .m_lock_match = lmv_lock_match,
3411 .m_get_lustre_md = lmv_get_lustre_md,
3412 .m_free_lustre_md = lmv_free_lustre_md,
3413 .m_update_lsm_md = lmv_update_lsm_md,
3414 .m_merge_attr = lmv_merge_attr,
3415 .m_set_open_replay_data = lmv_set_open_replay_data,
3416 .m_clear_open_replay_data = lmv_clear_open_replay_data,
3417 .m_renew_capa = lmv_renew_capa,
3418 .m_unpack_capa = lmv_unpack_capa,
3419 .m_get_remote_perm = lmv_get_remote_perm,
3420 .m_intent_getattr_async = lmv_intent_getattr_async,
3421 .m_revalidate_lock = lmv_revalidate_lock
3424 int __init lmv_init(void)
3426 return class_register_type(&lmv_obd_ops, &lmv_md_ops, NULL,
3427 #ifndef HAVE_ONLY_PROCFS_SEQ
3430 LUSTRE_LMV_NAME, NULL);
3434 static void lmv_exit(void)
3436 class_unregister_type(LUSTRE_LMV_NAME);
3439 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
3440 MODULE_DESCRIPTION("Lustre Logical Metadata Volume OBD driver");
3441 MODULE_LICENSE("GPL");
3443 module_init(lmv_init);
3444 module_exit(lmv_exit);