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, 2015, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_LMV
38 #include <linux/slab.h>
39 #include <linux/module.h>
40 #include <linux/init.h>
41 #include <linux/user_namespace.h>
42 #ifdef HAVE_UIDGID_HEADER
43 # include <linux/uidgid.h>
45 #include <linux/slab.h>
46 #include <linux/pagemap.h>
48 #include <linux/math64.h>
49 #include <linux/seq_file.h>
50 #include <linux/namei.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>
60 #include <lustre_fid.h>
61 #include <lustre_ioctl.h>
62 #include <lustre_kernelcomm.h>
63 #include "lmv_internal.h"
65 static void lmv_activate_target(struct lmv_obd *lmv,
66 struct lmv_tgt_desc *tgt,
69 if (tgt->ltd_active == activate)
72 tgt->ltd_active = activate;
73 lmv->desc.ld_active_tgt_count += (activate ? 1 : -1);
75 tgt->ltd_exp->exp_obd->obd_inactive = !activate;
81 * -EINVAL : UUID can't be found in the LMV's target list
82 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
83 * -EBADF : The UUID is found, but the OBD of the wrong type (!)
85 static int lmv_set_mdc_active(struct lmv_obd *lmv,
86 const struct obd_uuid *uuid,
89 struct lmv_tgt_desc *tgt = NULL;
90 struct obd_device *obd;
95 CDEBUG(D_INFO, "Searching in lmv %p for uuid %s (activate=%d)\n",
96 lmv, uuid->uuid, activate);
98 spin_lock(&lmv->lmv_lock);
99 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
101 if (tgt == NULL || tgt->ltd_exp == NULL)
104 CDEBUG(D_INFO, "Target idx %d is %s conn "LPX64"\n", i,
105 tgt->ltd_uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
107 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
111 if (i == lmv->desc.ld_tgt_count)
112 GOTO(out_lmv_lock, rc = -EINVAL);
114 obd = class_exp2obd(tgt->ltd_exp);
116 GOTO(out_lmv_lock, rc = -ENOTCONN);
118 CDEBUG(D_INFO, "Found OBD %s=%s device %d (%p) type %s at LMV idx %d\n",
119 obd->obd_name, obd->obd_uuid.uuid, obd->obd_minor, obd,
120 obd->obd_type->typ_name, i);
121 LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0);
123 if (tgt->ltd_active == activate) {
124 CDEBUG(D_INFO, "OBD %p already %sactive!\n", obd,
125 activate ? "" : "in");
126 GOTO(out_lmv_lock, rc);
129 CDEBUG(D_INFO, "Marking OBD %p %sactive\n", obd,
130 activate ? "" : "in");
131 lmv_activate_target(lmv, tgt, activate);
135 spin_unlock(&lmv->lmv_lock);
139 struct obd_uuid *lmv_get_uuid(struct obd_export *exp)
141 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
142 struct lmv_tgt_desc *tgt = lmv->tgts[0];
144 return (tgt == NULL) ? NULL : obd_get_uuid(tgt->ltd_exp);
147 static int lmv_notify(struct obd_device *obd, struct obd_device *watched,
148 enum obd_notify_event ev, void *data)
150 struct obd_connect_data *conn_data;
151 struct lmv_obd *lmv = &obd->u.lmv;
152 struct obd_uuid *uuid;
156 if (strcmp(watched->obd_type->typ_name, LUSTRE_MDC_NAME)) {
157 CERROR("unexpected notification of %s %s!\n",
158 watched->obd_type->typ_name,
163 uuid = &watched->u.cli.cl_target_uuid;
164 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE) {
166 * Set MDC as active before notifying the observer, so the
167 * observer can use the MDC normally.
169 rc = lmv_set_mdc_active(lmv, uuid,
170 ev == OBD_NOTIFY_ACTIVE);
172 CERROR("%sactivation of %s failed: %d\n",
173 ev == OBD_NOTIFY_ACTIVE ? "" : "de",
177 } else if (ev == OBD_NOTIFY_OCD) {
178 conn_data = &watched->u.cli.cl_import->imp_connect_data;
180 * XXX: Make sure that ocd_connect_flags from all targets are
181 * the same. Otherwise one of MDTs runs wrong version or
182 * something like this. --umka
184 obd->obd_self_export->exp_connect_data = *conn_data;
188 * Pass the notification up the chain.
190 if (obd->obd_observer)
191 rc = obd_notify(obd->obd_observer, watched, ev, data);
197 * This is fake connect function. Its purpose is to initialize lmv and say
198 * caller that everything is okay. Real connection will be performed later.
200 static int lmv_connect(const struct lu_env *env,
201 struct obd_export **exp, struct obd_device *obd,
202 struct obd_uuid *cluuid, struct obd_connect_data *data,
205 struct lmv_obd *lmv = &obd->u.lmv;
206 struct lustre_handle conn = { 0 };
211 * We don't want to actually do the underlying connections more than
212 * once, so keep track.
215 if (lmv->refcount > 1) {
220 rc = class_connect(&conn, obd, cluuid);
222 CERROR("class_connection() returned %d\n", rc);
226 *exp = class_conn2export(&conn);
227 class_export_get(*exp);
231 lmv->cluuid = *cluuid;
234 lmv->conn_data = *data;
236 if (lmv->targets_proc_entry == NULL) {
237 lmv->targets_proc_entry = lprocfs_register("target_obds",
240 if (IS_ERR(lmv->targets_proc_entry)) {
241 CERROR("%s: cannot register "
242 "/proc/fs/lustre/%s/%s/target_obds\n",
243 obd->obd_name, obd->obd_type->typ_name,
245 lmv->targets_proc_entry = NULL;
250 * All real clients should perform actual connection right away, because
251 * it is possible, that LMV will not have opportunity to connect targets
252 * and MDC stuff will be called directly, for instance while reading
253 * ../mdc/../kbytesfree procfs file, etc.
255 if (data != NULL && (data->ocd_connect_flags & OBD_CONNECT_REAL))
256 rc = lmv_check_connect(obd);
258 if (rc && lmv->targets_proc_entry != NULL)
259 lprocfs_remove(&lmv->targets_proc_entry);
263 static int lmv_init_ea_size(struct obd_export *exp, __u32 easize,
266 struct obd_device *obd = exp->exp_obd;
267 struct lmv_obd *lmv = &obd->u.lmv;
273 if (lmv->max_easize < easize) {
274 lmv->max_easize = easize;
277 if (lmv->max_def_easize < def_easize) {
278 lmv->max_def_easize = def_easize;
285 if (lmv->connected == 0)
288 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
289 struct lmv_tgt_desc *tgt = lmv->tgts[i];
291 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active) {
292 CWARN("%s: NULL export for %d\n", obd->obd_name, i);
296 rc = md_init_ea_size(tgt->ltd_exp, easize, def_easize);
298 CERROR("%s: obd_init_ea_size() failed on MDT target %d:"
299 " rc = %d\n", obd->obd_name, i, rc);
306 #define MAX_STRING_SIZE 128
308 int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
310 struct lmv_obd *lmv = &obd->u.lmv;
311 struct obd_uuid *cluuid = &lmv->cluuid;
312 struct obd_uuid lmv_mdc_uuid = { "LMV_MDC_UUID" };
313 struct obd_device *mdc_obd;
314 struct obd_export *mdc_exp;
315 struct lu_fld_target target;
319 mdc_obd = class_find_client_obd(&tgt->ltd_uuid, LUSTRE_MDC_NAME,
322 CERROR("target %s not attached\n", tgt->ltd_uuid.uuid);
326 CDEBUG(D_CONFIG, "connect to %s(%s) - %s, %s FOR %s\n",
327 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
328 tgt->ltd_uuid.uuid, obd->obd_uuid.uuid,
331 if (!mdc_obd->obd_set_up) {
332 CERROR("target %s is not set up\n", tgt->ltd_uuid.uuid);
336 rc = obd_connect(NULL, &mdc_exp, mdc_obd, &lmv_mdc_uuid,
337 &lmv->conn_data, NULL);
339 CERROR("target %s connect error %d\n", tgt->ltd_uuid.uuid, rc);
344 * Init fid sequence client for this mdc and add new fld target.
346 rc = obd_fid_init(mdc_obd, mdc_exp, LUSTRE_SEQ_METADATA);
350 target.ft_srv = NULL;
351 target.ft_exp = mdc_exp;
352 target.ft_idx = tgt->ltd_idx;
354 fld_client_add_target(&lmv->lmv_fld, &target);
356 rc = obd_register_observer(mdc_obd, obd);
358 obd_disconnect(mdc_exp);
359 CERROR("target %s register_observer error %d\n",
360 tgt->ltd_uuid.uuid, rc);
364 if (obd->obd_observer) {
366 * Tell the observer about the new target.
368 rc = obd_notify(obd->obd_observer, mdc_exp->exp_obd,
370 (void *)(tgt - lmv->tgts[0]));
372 obd_disconnect(mdc_exp);
378 tgt->ltd_exp = mdc_exp;
379 lmv->desc.ld_active_tgt_count++;
381 md_init_ea_size(tgt->ltd_exp, lmv->max_easize, lmv->max_def_easize);
383 CDEBUG(D_CONFIG, "Connected to %s(%s) successfully (%d)\n",
384 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
385 atomic_read(&obd->obd_refcount));
387 if (lmv->targets_proc_entry != NULL) {
388 struct proc_dir_entry *mdc_symlink;
390 LASSERT(mdc_obd->obd_type != NULL);
391 LASSERT(mdc_obd->obd_type->typ_name != NULL);
392 mdc_symlink = lprocfs_add_symlink(mdc_obd->obd_name,
393 lmv->targets_proc_entry,
395 mdc_obd->obd_type->typ_name,
397 if (mdc_symlink == NULL) {
398 CERROR("cannot register LMV target "
399 "/proc/fs/lustre/%s/%s/target_obds/%s\n",
400 obd->obd_type->typ_name, obd->obd_name,
407 static void lmv_del_target(struct lmv_obd *lmv, int index)
409 if (lmv->tgts[index] == NULL)
412 OBD_FREE_PTR(lmv->tgts[index]);
413 lmv->tgts[index] = NULL;
417 static int lmv_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
418 __u32 index, int gen)
420 struct obd_device *mdc_obd;
421 struct lmv_obd *lmv = &obd->u.lmv;
422 struct lmv_tgt_desc *tgt;
423 int orig_tgt_count = 0;
427 CDEBUG(D_CONFIG, "Target uuid: %s. index %d\n", uuidp->uuid, index);
428 mdc_obd = class_find_client_obd(uuidp, LUSTRE_MDC_NAME,
431 CERROR("%s: Target %s not attached: rc = %d\n",
432 obd->obd_name, uuidp->uuid, -EINVAL);
436 mutex_lock(&lmv->lmv_init_mutex);
437 if ((index < lmv->tgts_size) && (lmv->tgts[index] != NULL)) {
438 tgt = lmv->tgts[index];
439 CERROR("%s: UUID %s already assigned at LOV target index %d:"
440 " rc = %d\n", obd->obd_name,
441 obd_uuid2str(&tgt->ltd_uuid), index, -EEXIST);
442 mutex_unlock(&lmv->lmv_init_mutex);
446 if (index >= lmv->tgts_size) {
447 /* We need to reallocate the lmv target array. */
448 struct lmv_tgt_desc **newtgts, **old = NULL;
452 while (newsize < index + 1)
453 newsize = newsize << 1;
454 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
455 if (newtgts == NULL) {
456 mutex_unlock(&lmv->lmv_init_mutex);
460 if (lmv->tgts_size) {
461 memcpy(newtgts, lmv->tgts,
462 sizeof(*newtgts) * lmv->tgts_size);
464 oldsize = lmv->tgts_size;
468 lmv->tgts_size = newsize;
471 OBD_FREE(old, sizeof(*old) * oldsize);
473 CDEBUG(D_CONFIG, "tgts: %p size: %d\n", lmv->tgts,
479 mutex_unlock(&lmv->lmv_init_mutex);
483 mutex_init(&tgt->ltd_fid_mutex);
484 tgt->ltd_idx = index;
485 tgt->ltd_uuid = *uuidp;
487 lmv->tgts[index] = tgt;
488 if (index >= lmv->desc.ld_tgt_count) {
489 orig_tgt_count = lmv->desc.ld_tgt_count;
490 lmv->desc.ld_tgt_count = index + 1;
493 if (lmv->connected == 0) {
494 /* lmv_check_connect() will connect this target. */
495 mutex_unlock(&lmv->lmv_init_mutex);
499 /* Otherwise let's connect it ourselves */
500 mutex_unlock(&lmv->lmv_init_mutex);
501 rc = lmv_connect_mdc(obd, tgt);
503 spin_lock(&lmv->lmv_lock);
504 if (lmv->desc.ld_tgt_count == index + 1)
505 lmv->desc.ld_tgt_count = orig_tgt_count;
506 memset(tgt, 0, sizeof(*tgt));
507 spin_unlock(&lmv->lmv_lock);
509 int easize = sizeof(struct lmv_stripe_md) +
510 lmv->desc.ld_tgt_count * sizeof(struct lu_fid);
511 lmv_init_ea_size(obd->obd_self_export, easize, 0);
517 int lmv_check_connect(struct obd_device *obd)
519 struct lmv_obd *lmv = &obd->u.lmv;
520 struct lmv_tgt_desc *tgt;
529 mutex_lock(&lmv->lmv_init_mutex);
530 if (lmv->connected) {
531 mutex_unlock(&lmv->lmv_init_mutex);
535 if (lmv->desc.ld_tgt_count == 0) {
536 mutex_unlock(&lmv->lmv_init_mutex);
537 CERROR("%s: no targets configured.\n", obd->obd_name);
541 LASSERT(lmv->tgts != NULL);
543 if (lmv->tgts[0] == NULL) {
544 mutex_unlock(&lmv->lmv_init_mutex);
545 CERROR("%s: no target configured for index 0.\n",
550 CDEBUG(D_CONFIG, "Time to connect %s to %s\n",
551 lmv->cluuid.uuid, obd->obd_name);
553 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
557 rc = lmv_connect_mdc(obd, tgt);
562 class_export_put(lmv->exp);
564 easize = lmv_mds_md_size(lmv->desc.ld_tgt_count, LMV_MAGIC);
565 lmv_init_ea_size(obd->obd_self_export, easize, 0);
566 mutex_unlock(&lmv->lmv_init_mutex);
577 --lmv->desc.ld_active_tgt_count;
578 rc2 = obd_disconnect(tgt->ltd_exp);
580 CERROR("LMV target %s disconnect on "
581 "MDC idx %d: error %d\n",
582 tgt->ltd_uuid.uuid, i, rc2);
586 class_disconnect(lmv->exp);
587 mutex_unlock(&lmv->lmv_init_mutex);
591 static int lmv_disconnect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
593 struct lmv_obd *lmv = &obd->u.lmv;
594 struct obd_device *mdc_obd;
598 LASSERT(tgt != NULL);
599 LASSERT(obd != NULL);
601 mdc_obd = class_exp2obd(tgt->ltd_exp);
604 mdc_obd->obd_force = obd->obd_force;
605 mdc_obd->obd_fail = obd->obd_fail;
606 mdc_obd->obd_no_recov = obd->obd_no_recov;
608 if (lmv->targets_proc_entry != NULL)
609 lprocfs_remove_proc_entry(mdc_obd->obd_name,
610 lmv->targets_proc_entry);
613 rc = obd_fid_fini(tgt->ltd_exp->exp_obd);
615 CERROR("Can't finanize fids factory\n");
617 CDEBUG(D_INFO, "Disconnected from %s(%s) successfully\n",
618 tgt->ltd_exp->exp_obd->obd_name,
619 tgt->ltd_exp->exp_obd->obd_uuid.uuid);
621 obd_register_observer(tgt->ltd_exp->exp_obd, NULL);
622 rc = obd_disconnect(tgt->ltd_exp);
624 if (tgt->ltd_active) {
625 CERROR("Target %s disconnect error %d\n",
626 tgt->ltd_uuid.uuid, rc);
630 lmv_activate_target(lmv, tgt, 0);
635 static int lmv_disconnect(struct obd_export *exp)
637 struct obd_device *obd = class_exp2obd(exp);
638 struct lmv_obd *lmv = &obd->u.lmv;
647 * Only disconnect the underlying layers on the final disconnect.
650 if (lmv->refcount != 0)
653 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
654 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
657 lmv_disconnect_mdc(obd, lmv->tgts[i]);
660 if (lmv->targets_proc_entry != NULL)
661 lprocfs_remove(&lmv->targets_proc_entry);
663 CERROR("/proc/fs/lustre/%s/%s/target_obds missing\n",
664 obd->obd_type->typ_name, obd->obd_name);
668 * This is the case when no real connection is established by
669 * lmv_check_connect().
672 class_export_put(exp);
673 rc = class_disconnect(exp);
674 if (lmv->refcount == 0)
679 static int lmv_fid2path(struct obd_export *exp, int len, void *karg,
682 struct obd_device *obddev = class_exp2obd(exp);
683 struct lmv_obd *lmv = &obddev->u.lmv;
684 struct getinfo_fid2path *gf;
685 struct lmv_tgt_desc *tgt;
686 struct getinfo_fid2path *remote_gf = NULL;
687 struct lu_fid root_fid;
688 int remote_gf_size = 0;
692 tgt = lmv_find_target(lmv, &gf->gf_fid);
694 RETURN(PTR_ERR(tgt));
696 root_fid = *gf->gf_u.gf_root_fid;
697 LASSERT(fid_is_sane(&root_fid));
700 rc = obd_iocontrol(OBD_IOC_FID2PATH, tgt->ltd_exp, len, gf, uarg);
701 if (rc != 0 && rc != -EREMOTE)
702 GOTO(out_fid2path, rc);
704 /* If remote_gf != NULL, it means just building the
705 * path on the remote MDT, copy this path segement to gf */
706 if (remote_gf != NULL) {
707 struct getinfo_fid2path *ori_gf;
710 ori_gf = (struct getinfo_fid2path *)karg;
711 if (strlen(ori_gf->gf_u.gf_path) +
712 strlen(gf->gf_u.gf_path) > ori_gf->gf_pathlen)
713 GOTO(out_fid2path, rc = -EOVERFLOW);
715 ptr = ori_gf->gf_u.gf_path;
717 memmove(ptr + strlen(gf->gf_u.gf_path) + 1, ptr,
718 strlen(ori_gf->gf_u.gf_path));
720 strncpy(ptr, gf->gf_u.gf_path,
721 strlen(gf->gf_u.gf_path));
722 ptr += strlen(gf->gf_u.gf_path);
726 CDEBUG(D_INFO, "%s: get path %s "DFID" rec: "LPU64" ln: %u\n",
727 tgt->ltd_exp->exp_obd->obd_name,
728 gf->gf_u.gf_path, PFID(&gf->gf_fid), gf->gf_recno,
732 GOTO(out_fid2path, rc);
734 /* sigh, has to go to another MDT to do path building further */
735 if (remote_gf == NULL) {
736 remote_gf_size = sizeof(*remote_gf) + PATH_MAX;
737 OBD_ALLOC(remote_gf, remote_gf_size);
738 if (remote_gf == NULL)
739 GOTO(out_fid2path, rc = -ENOMEM);
740 remote_gf->gf_pathlen = PATH_MAX;
743 if (!fid_is_sane(&gf->gf_fid)) {
744 CERROR("%s: invalid FID "DFID": rc = %d\n",
745 tgt->ltd_exp->exp_obd->obd_name,
746 PFID(&gf->gf_fid), -EINVAL);
747 GOTO(out_fid2path, rc = -EINVAL);
750 tgt = lmv_find_target(lmv, &gf->gf_fid);
752 GOTO(out_fid2path, rc = -EINVAL);
754 remote_gf->gf_fid = gf->gf_fid;
755 remote_gf->gf_recno = -1;
756 remote_gf->gf_linkno = -1;
757 memset(remote_gf->gf_u.gf_path, 0, remote_gf->gf_pathlen);
758 *remote_gf->gf_u.gf_root_fid = root_fid;
760 goto repeat_fid2path;
763 if (remote_gf != NULL)
764 OBD_FREE(remote_gf, remote_gf_size);
768 static int lmv_hsm_req_count(struct lmv_obd *lmv,
769 const struct hsm_user_request *hur,
770 const struct lmv_tgt_desc *tgt_mds)
774 struct lmv_tgt_desc *curr_tgt;
776 /* count how many requests must be sent to the given target */
777 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
778 curr_tgt = lmv_find_target(lmv, &hur->hur_user_item[i].hui_fid);
779 if (IS_ERR(curr_tgt))
780 RETURN(PTR_ERR(curr_tgt));
781 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid))
787 static int lmv_hsm_req_build(struct lmv_obd *lmv,
788 struct hsm_user_request *hur_in,
789 const struct lmv_tgt_desc *tgt_mds,
790 struct hsm_user_request *hur_out)
793 struct lmv_tgt_desc *curr_tgt;
795 /* build the hsm_user_request for the given target */
796 hur_out->hur_request = hur_in->hur_request;
798 for (i = 0; i < hur_in->hur_request.hr_itemcount; i++) {
799 curr_tgt = lmv_find_target(lmv,
800 &hur_in->hur_user_item[i].hui_fid);
801 if (IS_ERR(curr_tgt))
802 RETURN(PTR_ERR(curr_tgt));
803 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid)) {
804 hur_out->hur_user_item[nr_out] =
805 hur_in->hur_user_item[i];
809 hur_out->hur_request.hr_itemcount = nr_out;
810 memcpy(hur_data(hur_out), hur_data(hur_in),
811 hur_in->hur_request.hr_data_len);
816 static int lmv_hsm_ct_unregister(struct lmv_obd *lmv, unsigned int cmd, int len,
817 struct lustre_kernelcomm *lk,
824 /* unregister request (call from llapi_hsm_copytool_fini) */
825 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
826 struct lmv_tgt_desc *tgt = lmv->tgts[i];
828 if (tgt == NULL || tgt->ltd_exp == NULL)
830 /* best effort: try to clean as much as possible
831 * (continue on error) */
832 obd_iocontrol(cmd, tgt->ltd_exp, len, lk, uarg);
835 /* Whatever the result, remove copytool from kuc groups.
836 * Unreached coordinators will get EPIPE on next requests
837 * and will unregister automatically.
839 rc = libcfs_kkuc_group_rem(lk->lk_uid, lk->lk_group);
844 static int lmv_hsm_ct_register(struct lmv_obd *lmv, unsigned int cmd, int len,
845 struct lustre_kernelcomm *lk, __user void *uarg)
850 bool any_set = false;
851 struct kkuc_ct_data kcd = { 0 };
854 /* All or nothing: try to register to all MDS.
855 * In case of failure, unregister from previous MDS,
856 * except if it because of inactive target. */
857 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
858 struct lmv_tgt_desc *tgt = lmv->tgts[i];
860 if (tgt == NULL || tgt->ltd_exp == NULL)
862 err = obd_iocontrol(cmd, tgt->ltd_exp, len, lk, uarg);
864 if (tgt->ltd_active) {
865 /* permanent error */
866 CERROR("%s: iocontrol MDC %s on MDT"
867 " idx %d cmd %x: err = %d\n",
868 class_exp2obd(lmv->exp)->obd_name,
869 tgt->ltd_uuid.uuid, i, cmd, err);
871 lk->lk_flags |= LK_FLG_STOP;
872 /* unregister from previous MDS */
873 for (j = 0; j < i; j++) {
875 if (tgt == NULL || tgt->ltd_exp == NULL)
877 obd_iocontrol(cmd, tgt->ltd_exp, len,
882 /* else: transient error.
883 * kuc will register to the missing MDT
891 /* no registration done: return error */
894 /* at least one registration done, with no failure */
895 filp = fget(lk->lk_wfd);
899 kcd.kcd_magic = KKUC_CT_DATA_MAGIC;
900 kcd.kcd_uuid = lmv->cluuid;
901 kcd.kcd_archive = lk->lk_data;
903 rc = libcfs_kkuc_group_add(filp, lk->lk_uid, lk->lk_group,
914 static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
915 int len, void *karg, void __user *uarg)
917 struct obd_device *obddev = class_exp2obd(exp);
918 struct lmv_obd *lmv = &obddev->u.lmv;
919 struct lmv_tgt_desc *tgt = NULL;
923 __u32 count = lmv->desc.ld_tgt_count;
930 case IOC_OBD_STATFS: {
931 struct obd_ioctl_data *data = karg;
932 struct obd_device *mdc_obd;
933 struct obd_statfs stat_buf = {0};
936 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
937 if ((index >= count))
940 tgt = lmv->tgts[index];
941 if (tgt == NULL || !tgt->ltd_active)
944 mdc_obd = class_exp2obd(tgt->ltd_exp);
949 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(mdc_obd),
950 min((int) data->ioc_plen2,
951 (int) sizeof(struct obd_uuid))))
954 rc = obd_statfs(NULL, tgt->ltd_exp, &stat_buf,
955 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
959 if (copy_to_user(data->ioc_pbuf1, &stat_buf,
960 min((int) data->ioc_plen1,
961 (int) sizeof(stat_buf))))
965 case OBD_IOC_QUOTACTL: {
966 struct if_quotactl *qctl = karg;
967 struct obd_quotactl *oqctl;
969 if (qctl->qc_valid == QC_MDTIDX) {
970 if (count <= qctl->qc_idx)
973 tgt = lmv->tgts[qctl->qc_idx];
974 if (tgt == NULL || tgt->ltd_exp == NULL)
976 } else if (qctl->qc_valid == QC_UUID) {
977 for (i = 0; i < count; i++) {
981 if (!obd_uuid_equals(&tgt->ltd_uuid,
985 if (tgt->ltd_exp == NULL)
997 LASSERT(tgt != NULL && tgt->ltd_exp != NULL);
998 OBD_ALLOC_PTR(oqctl);
1002 QCTL_COPY(oqctl, qctl);
1003 rc = obd_quotactl(tgt->ltd_exp, oqctl);
1005 QCTL_COPY(qctl, oqctl);
1006 qctl->qc_valid = QC_MDTIDX;
1007 qctl->obd_uuid = tgt->ltd_uuid;
1009 OBD_FREE_PTR(oqctl);
1012 case OBD_IOC_CHANGELOG_SEND:
1013 case OBD_IOC_CHANGELOG_CLEAR: {
1014 struct ioc_changelog *icc = karg;
1016 if (icc->icc_mdtindex >= count)
1019 tgt = lmv->tgts[icc->icc_mdtindex];
1020 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
1022 rc = obd_iocontrol(cmd, tgt->ltd_exp, sizeof(*icc), icc, NULL);
1025 case LL_IOC_GET_CONNECT_FLAGS: {
1027 if (tgt == NULL || tgt->ltd_exp == NULL)
1029 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1032 case LL_IOC_FID2MDTIDX: {
1033 struct lu_fid *fid = karg;
1036 rc = lmv_fld_lookup(lmv, fid, &mdt_index);
1040 /* Note: this is from llite(see ll_dir_ioctl()), @uarg does not
1041 * point to user space memory for FID2MDTIDX. */
1042 *(__u32 *)uarg = mdt_index;
1045 case OBD_IOC_FID2PATH: {
1046 rc = lmv_fid2path(exp, len, karg, uarg);
1049 case LL_IOC_HSM_STATE_GET:
1050 case LL_IOC_HSM_STATE_SET:
1051 case LL_IOC_HSM_ACTION: {
1052 struct md_op_data *op_data = karg;
1054 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1056 RETURN(PTR_ERR(tgt));
1058 if (tgt->ltd_exp == NULL)
1061 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1064 case LL_IOC_HSM_PROGRESS: {
1065 const struct hsm_progress_kernel *hpk = karg;
1067 tgt = lmv_find_target(lmv, &hpk->hpk_fid);
1069 RETURN(PTR_ERR(tgt));
1070 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1073 case LL_IOC_HSM_REQUEST: {
1074 struct hsm_user_request *hur = karg;
1075 unsigned int reqcount = hur->hur_request.hr_itemcount;
1080 /* if the request is about a single fid
1081 * or if there is a single MDS, no need to split
1083 if (reqcount == 1 || count == 1) {
1084 tgt = lmv_find_target(lmv,
1085 &hur->hur_user_item[0].hui_fid);
1087 RETURN(PTR_ERR(tgt));
1088 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1090 /* split fid list to their respective MDS */
1091 for (i = 0; i < count; i++) {
1094 struct hsm_user_request *req;
1097 if (tgt == NULL || tgt->ltd_exp == NULL)
1100 nr = lmv_hsm_req_count(lmv, hur, tgt);
1103 if (nr == 0) /* nothing for this MDS */
1106 /* build a request with fids for this MDS */
1107 reqlen = offsetof(typeof(*hur),
1109 + hur->hur_request.hr_data_len;
1110 OBD_ALLOC_LARGE(req, reqlen);
1113 rc1 = lmv_hsm_req_build(lmv, hur, tgt, req);
1115 GOTO(hsm_req_err, rc1);
1116 rc1 = obd_iocontrol(cmd, tgt->ltd_exp, reqlen,
1119 if (rc1 != 0 && rc == 0)
1121 OBD_FREE_LARGE(req, reqlen);
1126 case LL_IOC_LOV_SWAP_LAYOUTS: {
1127 struct md_op_data *op_data = karg;
1128 struct lmv_tgt_desc *tgt1, *tgt2;
1130 tgt1 = lmv_find_target(lmv, &op_data->op_fid1);
1132 RETURN(PTR_ERR(tgt1));
1134 tgt2 = lmv_find_target(lmv, &op_data->op_fid2);
1136 RETURN(PTR_ERR(tgt2));
1138 if ((tgt1->ltd_exp == NULL) || (tgt2->ltd_exp == NULL))
1141 /* only files on same MDT can have their layouts swapped */
1142 if (tgt1->ltd_idx != tgt2->ltd_idx)
1145 rc = obd_iocontrol(cmd, tgt1->ltd_exp, len, karg, uarg);
1148 case LL_IOC_HSM_CT_START: {
1149 struct lustre_kernelcomm *lk = karg;
1150 if (lk->lk_flags & LK_FLG_STOP)
1151 rc = lmv_hsm_ct_unregister(lmv, cmd, len, lk, uarg);
1153 rc = lmv_hsm_ct_register(lmv, cmd, len, lk, uarg);
1157 for (i = 0; i < count; i++) {
1158 struct obd_device *mdc_obd;
1162 if (tgt == NULL || tgt->ltd_exp == NULL)
1164 /* ll_umount_begin() sets force flag but for lmv, not
1165 * mdc. Let's pass it through */
1166 mdc_obd = class_exp2obd(tgt->ltd_exp);
1167 mdc_obd->obd_force = obddev->obd_force;
1168 err = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1170 if (tgt->ltd_active) {
1171 CERROR("error: iocontrol MDC %s on MDT"
1172 " idx %d cmd %x: err = %d\n",
1173 tgt->ltd_uuid.uuid, i, cmd, err);
1187 * This is _inode_ placement policy function (not name).
1189 static int lmv_placement_policy(struct obd_device *obd,
1190 struct md_op_data *op_data, u32 *mds)
1192 struct lmv_obd *lmv = &obd->u.lmv;
1195 LASSERT(mds != NULL);
1197 if (lmv->desc.ld_tgt_count == 1) {
1202 if (op_data->op_default_stripe_offset != -1) {
1203 *mds = op_data->op_default_stripe_offset;
1208 * If stripe_offset is provided during setdirstripe
1209 * (setdirstripe -i xx), xx MDS will be choosen.
1211 if (op_data->op_cli_flags & CLI_SET_MEA && op_data->op_data != NULL) {
1212 struct lmv_user_md *lum;
1214 lum = op_data->op_data;
1216 if (le32_to_cpu(lum->lum_stripe_offset) != (__u32)-1) {
1217 *mds = le32_to_cpu(lum->lum_stripe_offset);
1219 /* -1 means default, which will be in the same MDT with
1221 *mds = op_data->op_mds;
1222 lum->lum_stripe_offset = cpu_to_le32(op_data->op_mds);
1225 /* Allocate new fid on target according to operation type and
1226 * parent home mds. */
1227 *mds = op_data->op_mds;
1233 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid, u32 mds)
1235 struct lmv_tgt_desc *tgt;
1239 tgt = lmv_get_target(lmv, mds, NULL);
1241 RETURN(PTR_ERR(tgt));
1244 * New seq alloc and FLD setup should be atomic. Otherwise we may find
1245 * on server that seq in new allocated fid is not yet known.
1247 mutex_lock(&tgt->ltd_fid_mutex);
1249 if (tgt->ltd_active == 0 || tgt->ltd_exp == NULL)
1250 GOTO(out, rc = -ENODEV);
1253 * Asking underlying tgt layer to allocate new fid.
1255 rc = obd_fid_alloc(NULL, tgt->ltd_exp, fid, NULL);
1257 LASSERT(fid_is_sane(fid));
1263 mutex_unlock(&tgt->ltd_fid_mutex);
1267 int lmv_fid_alloc(const struct lu_env *env, struct obd_export *exp,
1268 struct lu_fid *fid, struct md_op_data *op_data)
1270 struct obd_device *obd = class_exp2obd(exp);
1271 struct lmv_obd *lmv = &obd->u.lmv;
1276 LASSERT(op_data != NULL);
1277 LASSERT(fid != NULL);
1279 rc = lmv_placement_policy(obd, op_data, &mds);
1281 CERROR("Can't get target for allocating fid, "
1286 rc = __lmv_fid_alloc(lmv, fid, mds);
1288 CERROR("Can't alloc new fid, rc %d\n", rc);
1295 static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
1297 struct lmv_obd *lmv = &obd->u.lmv;
1298 struct lmv_desc *desc;
1302 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
1303 CERROR("LMV setup requires a descriptor\n");
1307 desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1);
1308 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
1309 CERROR("Lmv descriptor size wrong: %d > %d\n",
1310 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
1314 lmv->tgts_size = 32U;
1315 OBD_ALLOC(lmv->tgts, sizeof(*lmv->tgts) * lmv->tgts_size);
1316 if (lmv->tgts == NULL)
1319 obd_str2uuid(&lmv->desc.ld_uuid, desc->ld_uuid.uuid);
1320 lmv->desc.ld_tgt_count = 0;
1321 lmv->desc.ld_active_tgt_count = 0;
1322 lmv->max_def_easize = 0;
1323 lmv->max_easize = 0;
1325 spin_lock_init(&lmv->lmv_lock);
1326 mutex_init(&lmv->lmv_init_mutex);
1328 #ifdef CONFIG_PROC_FS
1329 obd->obd_vars = lprocfs_lmv_obd_vars;
1330 lprocfs_obd_setup(obd);
1331 lprocfs_alloc_md_stats(obd, 0);
1332 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
1333 0444, &lmv_proc_target_fops, obd);
1335 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
1338 rc = fld_client_init(&lmv->lmv_fld, obd->obd_name,
1339 LUSTRE_CLI_FLD_HASH_DHT);
1341 CERROR("Can't init FLD, err %d\n", rc);
1351 static int lmv_cleanup(struct obd_device *obd)
1353 struct lmv_obd *lmv = &obd->u.lmv;
1356 fld_client_fini(&lmv->lmv_fld);
1357 if (lmv->tgts != NULL) {
1359 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1360 if (lmv->tgts[i] == NULL)
1362 lmv_del_target(lmv, i);
1364 OBD_FREE(lmv->tgts, sizeof(*lmv->tgts) * lmv->tgts_size);
1370 static int lmv_process_config(struct obd_device *obd, size_t len, void *buf)
1372 struct lustre_cfg *lcfg = buf;
1373 struct obd_uuid obd_uuid;
1379 switch (lcfg->lcfg_command) {
1381 /* modify_mdc_tgts add 0:lustre-clilmv 1:lustre-MDT0000_UUID
1382 * 2:0 3:1 4:lustre-MDT0000-mdc_UUID */
1383 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
1384 GOTO(out, rc = -EINVAL);
1386 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
1388 if (sscanf(lustre_cfg_buf(lcfg, 2), "%u", &index) != 1)
1389 GOTO(out, rc = -EINVAL);
1390 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
1391 GOTO(out, rc = -EINVAL);
1392 rc = lmv_add_target(obd, &obd_uuid, index, gen);
1395 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1396 GOTO(out, rc = -EINVAL);
1402 static int lmv_statfs(const struct lu_env *env, struct obd_export *exp,
1403 struct obd_statfs *osfs, __u64 max_age, __u32 flags)
1405 struct obd_device *obd = class_exp2obd(exp);
1406 struct lmv_obd *lmv = &obd->u.lmv;
1407 struct obd_statfs *temp;
1412 rc = lmv_check_connect(obd);
1416 OBD_ALLOC(temp, sizeof(*temp));
1420 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1421 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1424 rc = obd_statfs(env, lmv->tgts[i]->ltd_exp, temp,
1427 CERROR("can't stat MDS #%d (%s), error %d\n", i,
1428 lmv->tgts[i]->ltd_exp->exp_obd->obd_name,
1430 GOTO(out_free_temp, rc);
1435 /* If the statfs is from mount, it will needs
1436 * retrieve necessary information from MDT0.
1437 * i.e. mount does not need the merged osfs
1439 * And also clients can be mounted as long as
1440 * MDT0 is in service*/
1441 if (flags & OBD_STATFS_FOR_MDT0)
1442 GOTO(out_free_temp, rc);
1444 osfs->os_bavail += temp->os_bavail;
1445 osfs->os_blocks += temp->os_blocks;
1446 osfs->os_ffree += temp->os_ffree;
1447 osfs->os_files += temp->os_files;
1453 OBD_FREE(temp, sizeof(*temp));
1457 static int lmv_get_root(struct obd_export *exp, const char *fileset,
1460 struct obd_device *obd = exp->exp_obd;
1461 struct lmv_obd *lmv = &obd->u.lmv;
1465 rc = lmv_check_connect(obd);
1469 rc = md_get_root(lmv->tgts[0]->ltd_exp, fileset, fid);
1473 static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1474 u64 valid, const char *name,
1475 const char *input, int input_size, int output_size,
1476 int flags, struct ptlrpc_request **request)
1478 struct obd_device *obd = exp->exp_obd;
1479 struct lmv_obd *lmv = &obd->u.lmv;
1480 struct lmv_tgt_desc *tgt;
1484 rc = lmv_check_connect(obd);
1488 tgt = lmv_find_target(lmv, fid);
1490 RETURN(PTR_ERR(tgt));
1492 rc = md_getxattr(tgt->ltd_exp, fid, valid, name, input,
1493 input_size, output_size, flags, request);
1498 static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1499 u64 valid, const char *name,
1500 const char *input, int input_size, int output_size,
1501 int flags, __u32 suppgid,
1502 struct ptlrpc_request **request)
1504 struct obd_device *obd = exp->exp_obd;
1505 struct lmv_obd *lmv = &obd->u.lmv;
1506 struct lmv_tgt_desc *tgt;
1510 rc = lmv_check_connect(obd);
1514 tgt = lmv_find_target(lmv, fid);
1516 RETURN(PTR_ERR(tgt));
1518 rc = md_setxattr(tgt->ltd_exp, fid, valid, name, input,
1519 input_size, output_size, flags, suppgid,
1525 static int lmv_getattr(struct obd_export *exp, struct md_op_data *op_data,
1526 struct ptlrpc_request **request)
1528 struct obd_device *obd = exp->exp_obd;
1529 struct lmv_obd *lmv = &obd->u.lmv;
1530 struct lmv_tgt_desc *tgt;
1534 rc = lmv_check_connect(obd);
1538 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1540 RETURN(PTR_ERR(tgt));
1542 if (op_data->op_flags & MF_GET_MDT_IDX) {
1543 op_data->op_mds = tgt->ltd_idx;
1547 rc = md_getattr(tgt->ltd_exp, op_data, request);
1552 static int lmv_null_inode(struct obd_export *exp, const struct lu_fid *fid)
1554 struct obd_device *obd = exp->exp_obd;
1555 struct lmv_obd *lmv = &obd->u.lmv;
1560 rc = lmv_check_connect(obd);
1564 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1567 * With DNE every object can have two locks in different namespaces:
1568 * lookup lock in space of MDT storing direntry and update/open lock in
1569 * space of MDT storing inode.
1571 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1572 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1574 md_null_inode(lmv->tgts[i]->ltd_exp, fid);
1580 static int lmv_close(struct obd_export *exp, struct md_op_data *op_data,
1581 struct md_open_data *mod, struct ptlrpc_request **request)
1583 struct obd_device *obd = exp->exp_obd;
1584 struct lmv_obd *lmv = &obd->u.lmv;
1585 struct lmv_tgt_desc *tgt;
1589 rc = lmv_check_connect(obd);
1593 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1595 RETURN(PTR_ERR(tgt));
1597 CDEBUG(D_INODE, "CLOSE "DFID"\n", PFID(&op_data->op_fid1));
1598 rc = md_close(tgt->ltd_exp, op_data, mod, request);
1603 * Choosing the MDT by name or FID in @op_data.
1604 * For non-striped directory, it will locate MDT by fid.
1605 * For striped-directory, it will locate MDT by name. And also
1606 * it will reset op_fid1 with the FID of the choosen stripe.
1608 struct lmv_tgt_desc *
1609 lmv_locate_target_for_name(struct lmv_obd *lmv, struct lmv_stripe_md *lsm,
1610 const char *name, int namelen, struct lu_fid *fid,
1613 struct lmv_tgt_desc *tgt;
1614 const struct lmv_oinfo *oinfo;
1616 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_NAME_HASH)) {
1617 if (cfs_fail_val >= lsm->lsm_md_stripe_count)
1618 RETURN(ERR_PTR(-EBADF));
1619 oinfo = &lsm->lsm_md_oinfo[cfs_fail_val];
1621 oinfo = lsm_name_to_stripe_info(lsm, name, namelen);
1623 RETURN(ERR_CAST(oinfo));
1627 *fid = oinfo->lmo_fid;
1629 *mds = oinfo->lmo_mds;
1631 tgt = lmv_get_target(lmv, oinfo->lmo_mds, NULL);
1633 CDEBUG(D_INFO, "locate on mds %u "DFID"\n", oinfo->lmo_mds,
1634 PFID(&oinfo->lmo_fid));
1639 * Locate mds by fid or name
1641 * For striped directory (lsm != NULL), it will locate the stripe
1642 * by name hash (see lsm_name_to_stripe_info()). Note: if the hash_type
1643 * is unknown, it will return -EBADFD, and lmv_intent_lookup might need
1644 * walk through all of stripes to locate the entry.
1646 * For normal direcotry, it will locate MDS by FID directly.
1647 * \param[in] lmv LMV device
1648 * \param[in] op_data client MD stack parameters, name, namelen
1650 * \param[in] fid object FID used to locate MDS.
1652 * retval pointer to the lmv_tgt_desc if succeed.
1653 * ERR_PTR(errno) if failed.
1655 struct lmv_tgt_desc*
1656 lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1659 struct lmv_stripe_md *lsm = op_data->op_mea1;
1660 struct lmv_tgt_desc *tgt;
1662 /* During creating VOLATILE file, it should honor the mdt
1663 * index if the file under striped dir is being restored, see
1665 if (op_data->op_bias & MDS_CREATE_VOLATILE &&
1666 (int)op_data->op_mds != -1) {
1668 tgt = lmv_get_target(lmv, op_data->op_mds, NULL);
1673 /* refill the right parent fid */
1674 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1675 struct lmv_oinfo *oinfo;
1677 oinfo = &lsm->lsm_md_oinfo[i];
1678 if (oinfo->lmo_mds == op_data->op_mds) {
1679 *fid = oinfo->lmo_fid;
1684 if (i == lsm->lsm_md_stripe_count)
1685 *fid = lsm->lsm_md_oinfo[0].lmo_fid;
1691 if (lsm == NULL || op_data->op_namelen == 0) {
1692 tgt = lmv_find_target(lmv, fid);
1696 op_data->op_mds = tgt->ltd_idx;
1700 return lmv_locate_target_for_name(lmv, lsm, op_data->op_name,
1701 op_data->op_namelen, fid,
1705 int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
1706 const void *data, size_t datalen, umode_t mode, uid_t uid,
1707 gid_t gid, cfs_cap_t cap_effective, __u64 rdev,
1708 struct ptlrpc_request **request)
1710 struct obd_device *obd = exp->exp_obd;
1711 struct lmv_obd *lmv = &obd->u.lmv;
1712 struct lmv_tgt_desc *tgt;
1716 rc = lmv_check_connect(obd);
1720 if (!lmv->desc.ld_active_tgt_count)
1723 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1725 RETURN(PTR_ERR(tgt));
1727 CDEBUG(D_INODE, "CREATE name '%.*s' on "DFID" -> mds #%x\n",
1728 (int)op_data->op_namelen, op_data->op_name,
1729 PFID(&op_data->op_fid1), op_data->op_mds);
1731 rc = lmv_fid_alloc(NULL, exp, &op_data->op_fid2, op_data);
1734 if (exp_connect_flags(exp) & OBD_CONNECT_DIR_STRIPE) {
1735 /* Send the create request to the MDT where the object
1736 * will be located */
1737 tgt = lmv_find_target(lmv, &op_data->op_fid2);
1739 RETURN(PTR_ERR(tgt));
1741 op_data->op_mds = tgt->ltd_idx;
1743 CDEBUG(D_CONFIG, "Server doesn't support striped dirs\n");
1746 CDEBUG(D_INODE, "CREATE obj "DFID" -> mds #%x\n",
1747 PFID(&op_data->op_fid2), op_data->op_mds);
1749 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1750 rc = md_create(tgt->ltd_exp, op_data, data, datalen, mode, uid, gid,
1751 cap_effective, rdev, request);
1753 if (*request == NULL)
1755 CDEBUG(D_INODE, "Created - "DFID"\n", PFID(&op_data->op_fid2));
1761 lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1762 const union ldlm_policy_data *policy,
1763 struct lookup_intent *it, struct md_op_data *op_data,
1764 struct lustre_handle *lockh, __u64 extra_lock_flags)
1766 struct obd_device *obd = exp->exp_obd;
1767 struct lmv_obd *lmv = &obd->u.lmv;
1768 struct lmv_tgt_desc *tgt;
1772 rc = lmv_check_connect(obd);
1776 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID"\n",
1777 LL_IT2STR(it), PFID(&op_data->op_fid1));
1779 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1781 RETURN(PTR_ERR(tgt));
1783 CDEBUG(D_INODE, "ENQUEUE '%s' on "DFID" -> mds #%u\n",
1784 LL_IT2STR(it), PFID(&op_data->op_fid1), tgt->ltd_idx);
1786 rc = md_enqueue(tgt->ltd_exp, einfo, policy, it, op_data, lockh,
1793 lmv_getattr_name(struct obd_export *exp,struct md_op_data *op_data,
1794 struct ptlrpc_request **preq)
1796 struct ptlrpc_request *req = NULL;
1797 struct obd_device *obd = exp->exp_obd;
1798 struct lmv_obd *lmv = &obd->u.lmv;
1799 struct lmv_tgt_desc *tgt;
1800 struct mdt_body *body;
1804 rc = lmv_check_connect(obd);
1808 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1810 RETURN(PTR_ERR(tgt));
1812 CDEBUG(D_INODE, "GETATTR_NAME for %*s on "DFID" -> mds #%d\n",
1813 (int)op_data->op_namelen, op_data->op_name,
1814 PFID(&op_data->op_fid1), tgt->ltd_idx);
1816 rc = md_getattr_name(tgt->ltd_exp, op_data, preq);
1820 body = req_capsule_server_get(&(*preq)->rq_pill, &RMF_MDT_BODY);
1821 LASSERT(body != NULL);
1823 if (body->mbo_valid & OBD_MD_MDS) {
1824 struct lu_fid rid = body->mbo_fid1;
1825 CDEBUG(D_INODE, "Request attrs for "DFID"\n",
1828 tgt = lmv_find_target(lmv, &rid);
1830 ptlrpc_req_finished(*preq);
1832 RETURN(PTR_ERR(tgt));
1835 op_data->op_fid1 = rid;
1836 op_data->op_valid |= OBD_MD_FLCROSSREF;
1837 op_data->op_namelen = 0;
1838 op_data->op_name = NULL;
1839 rc = md_getattr_name(tgt->ltd_exp, op_data, &req);
1840 ptlrpc_req_finished(*preq);
1847 #define md_op_data_fid(op_data, fl) \
1848 (fl == MF_MDC_CANCEL_FID1 ? &op_data->op_fid1 : \
1849 fl == MF_MDC_CANCEL_FID2 ? &op_data->op_fid2 : \
1850 fl == MF_MDC_CANCEL_FID3 ? &op_data->op_fid3 : \
1851 fl == MF_MDC_CANCEL_FID4 ? &op_data->op_fid4 : \
1854 static int lmv_early_cancel(struct obd_export *exp, struct lmv_tgt_desc *tgt,
1855 struct md_op_data *op_data, __u32 op_tgt,
1856 enum ldlm_mode mode, int bits, int flag)
1858 struct lu_fid *fid = md_op_data_fid(op_data, flag);
1859 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
1860 union ldlm_policy_data policy = { { 0 } };
1864 if (!fid_is_sane(fid))
1868 tgt = lmv_find_target(lmv, fid);
1870 RETURN(PTR_ERR(tgt));
1873 if (tgt->ltd_idx != op_tgt) {
1874 CDEBUG(D_INODE, "EARLY_CANCEL on "DFID"\n", PFID(fid));
1875 policy.l_inodebits.bits = bits;
1876 rc = md_cancel_unused(tgt->ltd_exp, fid, &policy,
1877 mode, LCF_ASYNC, NULL);
1880 "EARLY_CANCEL skip operation target %d on "DFID"\n",
1882 op_data->op_flags |= flag;
1890 * llite passes fid of an target inode in op_data->op_fid1 and id of directory in
1893 static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
1894 struct ptlrpc_request **request)
1896 struct obd_device *obd = exp->exp_obd;
1897 struct lmv_obd *lmv = &obd->u.lmv;
1898 struct lmv_tgt_desc *tgt;
1902 rc = lmv_check_connect(obd);
1906 LASSERT(op_data->op_namelen != 0);
1908 CDEBUG(D_INODE, "LINK "DFID":%*s to "DFID"\n",
1909 PFID(&op_data->op_fid2), (int)op_data->op_namelen,
1910 op_data->op_name, PFID(&op_data->op_fid1));
1912 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
1913 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
1914 op_data->op_cap = cfs_curproc_cap_pack();
1915 if (op_data->op_mea2 != NULL) {
1916 struct lmv_stripe_md *lsm = op_data->op_mea2;
1917 const struct lmv_oinfo *oinfo;
1919 oinfo = lsm_name_to_stripe_info(lsm, op_data->op_name,
1920 op_data->op_namelen);
1922 RETURN(PTR_ERR(oinfo));
1924 op_data->op_fid2 = oinfo->lmo_fid;
1927 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
1929 RETURN(PTR_ERR(tgt));
1932 * Cancel UPDATE lock on child (fid1).
1934 op_data->op_flags |= MF_MDC_CANCEL_FID2;
1935 rc = lmv_early_cancel(exp, NULL, op_data, tgt->ltd_idx, LCK_EX,
1936 MDS_INODELOCK_UPDATE, MF_MDC_CANCEL_FID1);
1940 rc = md_link(tgt->ltd_exp, op_data, request);
1945 static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
1946 const char *old, size_t oldlen,
1947 const char *new, size_t newlen,
1948 struct ptlrpc_request **request)
1950 struct obd_device *obd = exp->exp_obd;
1951 struct lmv_obd *lmv = &obd->u.lmv;
1952 struct lmv_tgt_desc *src_tgt;
1953 struct lmv_tgt_desc *tgt_tgt;
1954 struct obd_export *target_exp;
1955 struct mdt_body *body;
1959 LASSERT(oldlen != 0);
1961 CDEBUG(D_INODE, "RENAME %.*s in "DFID":%d to %.*s in "DFID":%d\n",
1962 (int)oldlen, old, PFID(&op_data->op_fid1),
1963 op_data->op_mea1 ? op_data->op_mea1->lsm_md_stripe_count : 0,
1964 (int)newlen, new, PFID(&op_data->op_fid2),
1965 op_data->op_mea2 ? op_data->op_mea2->lsm_md_stripe_count : 0);
1967 rc = lmv_check_connect(obd);
1971 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
1972 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
1973 op_data->op_cap = cfs_curproc_cap_pack();
1974 if (op_data->op_cli_flags & CLI_MIGRATE) {
1975 LASSERTF(fid_is_sane(&op_data->op_fid3), "invalid FID "DFID"\n",
1976 PFID(&op_data->op_fid3));
1978 if (op_data->op_mea1 != NULL) {
1979 struct lmv_stripe_md *lsm = op_data->op_mea1;
1980 struct lmv_tgt_desc *tmp;
1982 /* Fix the parent fid for striped dir */
1983 tmp = lmv_locate_target_for_name(lmv, lsm, old,
1988 RETURN(PTR_ERR(tmp));
1991 rc = lmv_fid_alloc(NULL, exp, &op_data->op_fid2, op_data);
1995 src_tgt = lmv_find_target(lmv, &op_data->op_fid3);
1996 if (IS_ERR(src_tgt))
1997 RETURN(PTR_ERR(src_tgt));
1999 target_exp = src_tgt->ltd_exp;
2001 if (op_data->op_mea1 != NULL) {
2002 struct lmv_stripe_md *lsm = op_data->op_mea1;
2004 src_tgt = lmv_locate_target_for_name(lmv, lsm, old,
2009 src_tgt = lmv_find_target(lmv, &op_data->op_fid1);
2011 if (IS_ERR(src_tgt))
2012 RETURN(PTR_ERR(src_tgt));
2015 if (op_data->op_mea2 != NULL) {
2016 struct lmv_stripe_md *lsm = op_data->op_mea2;
2018 tgt_tgt = lmv_locate_target_for_name(lmv, lsm, new,
2023 tgt_tgt = lmv_find_target(lmv, &op_data->op_fid2);
2026 if (IS_ERR(tgt_tgt))
2027 RETURN(PTR_ERR(tgt_tgt));
2029 target_exp = tgt_tgt->ltd_exp;
2033 * LOOKUP lock on src child (fid3) should also be cancelled for
2034 * src_tgt in mdc_rename.
2036 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2039 * Cancel UPDATE locks on tgt parent (fid2), tgt_tgt is its
2042 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
2043 LCK_EX, MDS_INODELOCK_UPDATE,
2044 MF_MDC_CANCEL_FID2);
2049 * Cancel LOOKUP locks on source child (fid3) for parent tgt_tgt.
2051 if (fid_is_sane(&op_data->op_fid3)) {
2052 struct lmv_tgt_desc *tgt;
2054 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2056 RETURN(PTR_ERR(tgt));
2058 /* Cancel LOOKUP lock on its parent */
2059 rc = lmv_early_cancel(exp, tgt, op_data, src_tgt->ltd_idx,
2060 LCK_EX, MDS_INODELOCK_LOOKUP,
2061 MF_MDC_CANCEL_FID3);
2065 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
2066 LCK_EX, MDS_INODELOCK_FULL,
2067 MF_MDC_CANCEL_FID3);
2074 * Cancel all the locks on tgt child (fid4).
2076 if (fid_is_sane(&op_data->op_fid4)) {
2077 struct lmv_tgt_desc *tgt;
2079 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
2080 LCK_EX, MDS_INODELOCK_FULL,
2081 MF_MDC_CANCEL_FID4);
2085 tgt = lmv_find_target(lmv, &op_data->op_fid4);
2087 RETURN(PTR_ERR(tgt));
2089 /* Since the target child might be destroyed, and it might
2090 * become orphan, and we can only check orphan on the local
2091 * MDT right now, so we send rename request to the MDT where
2092 * target child is located. If target child does not exist,
2093 * then it will send the request to the target parent */
2094 target_exp = tgt->ltd_exp;
2097 rc = md_rename(target_exp, op_data, old, oldlen, new, newlen,
2100 if (rc != 0 && rc != -EXDEV)
2103 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
2107 /* Not cross-ref case, just get out of here. */
2108 if (likely(!(body->mbo_valid & OBD_MD_MDS)))
2111 CDEBUG(D_INODE, "%s: try rename to another MDT for "DFID"\n",
2112 exp->exp_obd->obd_name, PFID(&body->mbo_fid1));
2114 op_data->op_fid4 = body->mbo_fid1;
2115 ptlrpc_req_finished(*request);
2120 static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
2121 void *ea, size_t ealen, struct ptlrpc_request **request)
2123 struct obd_device *obd = exp->exp_obd;
2124 struct lmv_obd *lmv = &obd->u.lmv;
2125 struct lmv_tgt_desc *tgt;
2129 rc = lmv_check_connect(obd);
2133 CDEBUG(D_INODE, "SETATTR for "DFID", valid 0x%x\n",
2134 PFID(&op_data->op_fid1), op_data->op_attr.ia_valid);
2136 op_data->op_flags |= MF_MDC_CANCEL_FID1;
2137 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2139 RETURN(PTR_ERR(tgt));
2141 rc = md_setattr(tgt->ltd_exp, op_data, ea, ealen, request);
2146 static int lmv_fsync(struct obd_export *exp, const struct lu_fid *fid,
2147 struct ptlrpc_request **request)
2149 struct obd_device *obd = exp->exp_obd;
2150 struct lmv_obd *lmv = &obd->u.lmv;
2151 struct lmv_tgt_desc *tgt;
2155 rc = lmv_check_connect(obd);
2159 tgt = lmv_find_target(lmv, fid);
2161 RETURN(PTR_ERR(tgt));
2163 rc = md_fsync(tgt->ltd_exp, fid, request);
2168 * Get current minimum entry from striped directory
2170 * This function will search the dir entry, whose hash value is the
2171 * closest(>=) to @hash_offset, from all of sub-stripes, and it is
2172 * only being called for striped directory.
2174 * \param[in] exp export of LMV
2175 * \param[in] op_data parameters transferred beween client MD stack
2176 * stripe_information will be included in this
2178 * \param[in] cb_op ldlm callback being used in enqueue in
2180 * \param[in] hash_offset the hash value, which is used to locate
2181 * minum(closet) dir entry
2182 * \param[in|out] stripe_offset the caller use this to indicate the stripe
2183 * index of last entry, so to avoid hash conflict
2184 * between stripes. It will also be used to
2185 * return the stripe index of current dir entry.
2186 * \param[in|out] entp the minum entry and it also is being used
2187 * to input the last dir entry to resolve the
2190 * \param[out] ppage the page which holds the minum entry
2192 * \retval = 0 get the entry successfully
2193 * negative errno (< 0) does not get the entry
2195 static int lmv_get_min_striped_entry(struct obd_export *exp,
2196 struct md_op_data *op_data,
2197 struct md_callback *cb_op,
2198 __u64 hash_offset, int *stripe_offset,
2199 struct lu_dirent **entp,
2200 struct page **ppage)
2202 struct obd_device *obd = exp->exp_obd;
2203 struct lmv_obd *lmv = &obd->u.lmv;
2204 struct lmv_stripe_md *lsm = op_data->op_mea1;
2205 struct lmv_tgt_desc *tgt;
2207 struct lu_dirent *min_ent = NULL;
2208 struct page *min_page = NULL;
2214 stripe_count = lsm->lsm_md_stripe_count;
2215 for (i = 0; i < stripe_count; i++) {
2216 struct lu_dirent *ent = NULL;
2217 struct page *page = NULL;
2218 struct lu_dirpage *dp;
2219 __u64 stripe_hash = hash_offset;
2221 tgt = lmv_get_target(lmv, lsm->lsm_md_oinfo[i].lmo_mds, NULL);
2223 GOTO(out, rc = PTR_ERR(tgt));
2225 /* op_data will be shared by each stripe, so we need
2226 * reset these value for each stripe */
2227 op_data->op_fid1 = lsm->lsm_md_oinfo[i].lmo_fid;
2228 op_data->op_fid2 = lsm->lsm_md_oinfo[i].lmo_fid;
2229 op_data->op_data = lsm->lsm_md_oinfo[i].lmo_root;
2231 rc = md_read_page(tgt->ltd_exp, op_data, cb_op, stripe_hash,
2236 dp = page_address(page);
2237 for (ent = lu_dirent_start(dp); ent != NULL;
2238 ent = lu_dirent_next(ent)) {
2239 /* Skip dummy entry */
2240 if (le16_to_cpu(ent->lde_namelen) == 0)
2243 if (le64_to_cpu(ent->lde_hash) < hash_offset)
2246 if (le64_to_cpu(ent->lde_hash) == hash_offset &&
2247 (*entp == ent || i < *stripe_offset))
2250 /* skip . and .. for other stripes */
2252 (strncmp(ent->lde_name, ".",
2253 le16_to_cpu(ent->lde_namelen)) == 0 ||
2254 strncmp(ent->lde_name, "..",
2255 le16_to_cpu(ent->lde_namelen)) == 0))
2261 stripe_hash = le64_to_cpu(dp->ldp_hash_end);
2264 page_cache_release(page);
2267 /* reach the end of current stripe, go to next stripe */
2268 if (stripe_hash == MDS_DIR_END_OFF)
2274 if (min_ent != NULL) {
2275 if (le64_to_cpu(min_ent->lde_hash) >
2276 le64_to_cpu(ent->lde_hash)) {
2279 page_cache_release(min_page);
2284 page_cache_release(page);
2295 if (*ppage != NULL) {
2297 page_cache_release(*ppage);
2299 *stripe_offset = min_idx;
2306 * Build dir entry page from a striped directory
2308 * This function gets one entry by @offset from a striped directory. It will
2309 * read entries from all of stripes, and choose one closest to the required
2310 * offset(&offset). A few notes
2311 * 1. skip . and .. for non-zero stripes, because there can only have one .
2312 * and .. in a directory.
2313 * 2. op_data will be shared by all of stripes, instead of allocating new
2314 * one, so need to restore before reusing.
2315 * 3. release the entry page if that is not being chosen.
2317 * \param[in] exp obd export refer to LMV
2318 * \param[in] op_data hold those MD parameters of read_entry
2319 * \param[in] cb_op ldlm callback being used in enqueue in mdc_read_entry
2320 * \param[out] ldp the entry being read
2321 * \param[out] ppage the page holding the entry. Note: because the entry
2322 * will be accessed in upper layer, so we need hold the
2323 * page until the usages of entry is finished, see
2324 * ll_dir_entry_next.
2326 * retval =0 if get entry successfully
2327 * <0 cannot get entry
2329 static int lmv_read_striped_page(struct obd_export *exp,
2330 struct md_op_data *op_data,
2331 struct md_callback *cb_op,
2332 __u64 offset, struct page **ppage)
2334 struct obd_device *obd = exp->exp_obd;
2335 struct lu_fid master_fid = op_data->op_fid1;
2336 struct inode *master_inode = op_data->op_data;
2337 __u64 hash_offset = offset;
2338 struct lu_dirpage *dp;
2339 struct page *min_ent_page = NULL;
2340 struct page *ent_page = NULL;
2341 struct lu_dirent *ent;
2344 struct lu_dirent *min_ent = NULL;
2345 struct lu_dirent *last_ent;
2350 rc = lmv_check_connect(obd);
2354 /* Allocate a page and read entries from all of stripes and fill
2355 * the page by hash order */
2356 ent_page = alloc_page(GFP_KERNEL);
2357 if (ent_page == NULL)
2360 /* Initialize the entry page */
2361 dp = kmap(ent_page);
2362 memset(dp, 0, sizeof(*dp));
2363 dp->ldp_hash_start = cpu_to_le64(offset);
2364 dp->ldp_flags |= LDF_COLLIDE;
2367 left_bytes = PAGE_CACHE_SIZE - sizeof(*dp);
2373 /* Find the minum entry from all sub-stripes */
2374 rc = lmv_get_min_striped_entry(exp, op_data, cb_op, hash_offset,
2380 /* If it can not get minum entry, it means it already reaches
2381 * the end of this directory */
2382 if (min_ent == NULL) {
2383 last_ent->lde_reclen = 0;
2384 hash_offset = MDS_DIR_END_OFF;
2388 ent_size = le16_to_cpu(min_ent->lde_reclen);
2390 /* the last entry lde_reclen is 0, but it might not
2391 * the end of this entry of this temporay entry */
2393 ent_size = lu_dirent_calc_size(
2394 le16_to_cpu(min_ent->lde_namelen),
2395 le32_to_cpu(min_ent->lde_attrs));
2396 if (ent_size > left_bytes) {
2397 last_ent->lde_reclen = cpu_to_le16(0);
2398 hash_offset = le64_to_cpu(min_ent->lde_hash);
2402 memcpy(ent, min_ent, ent_size);
2404 /* Replace . with master FID and Replace .. with the parent FID
2405 * of master object */
2406 if (strncmp(ent->lde_name, ".",
2407 le16_to_cpu(ent->lde_namelen)) == 0 &&
2408 le16_to_cpu(ent->lde_namelen) == 1)
2409 fid_cpu_to_le(&ent->lde_fid, &master_fid);
2410 else if (strncmp(ent->lde_name, "..",
2411 le16_to_cpu(ent->lde_namelen)) == 0 &&
2412 le16_to_cpu(ent->lde_namelen) == 2)
2413 fid_cpu_to_le(&ent->lde_fid, &op_data->op_fid3);
2415 left_bytes -= ent_size;
2416 ent->lde_reclen = cpu_to_le16(ent_size);
2418 ent = (void *)ent + ent_size;
2419 hash_offset = le64_to_cpu(min_ent->lde_hash);
2420 if (hash_offset == MDS_DIR_END_OFF) {
2421 last_ent->lde_reclen = 0;
2426 if (min_ent_page != NULL) {
2427 kunmap(min_ent_page);
2428 page_cache_release(min_ent_page);
2431 if (unlikely(rc != 0)) {
2432 __free_page(ent_page);
2436 dp->ldp_flags |= LDF_EMPTY;
2437 dp->ldp_flags = cpu_to_le32(dp->ldp_flags);
2438 dp->ldp_hash_end = cpu_to_le64(hash_offset);
2441 /* We do not want to allocate md_op_data during each
2442 * dir entry reading, so op_data will be shared by every stripe,
2443 * then we need to restore it back to original value before
2444 * return to the upper layer */
2445 op_data->op_fid1 = master_fid;
2446 op_data->op_fid2 = master_fid;
2447 op_data->op_data = master_inode;
2454 int lmv_read_page(struct obd_export *exp, struct md_op_data *op_data,
2455 struct md_callback *cb_op, __u64 offset,
2456 struct page **ppage)
2458 struct obd_device *obd = exp->exp_obd;
2459 struct lmv_obd *lmv = &obd->u.lmv;
2460 struct lmv_stripe_md *lsm = op_data->op_mea1;
2461 struct lmv_tgt_desc *tgt;
2465 rc = lmv_check_connect(obd);
2469 if (unlikely(lsm != NULL)) {
2470 rc = lmv_read_striped_page(exp, op_data, cb_op, offset, ppage);
2474 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2476 RETURN(PTR_ERR(tgt));
2478 rc = md_read_page(tgt->ltd_exp, op_data, cb_op, offset, ppage);
2484 * Unlink a file/directory
2486 * Unlink a file or directory under the parent dir. The unlink request
2487 * usually will be sent to the MDT where the child is located, but if
2488 * the client does not have the child FID then request will be sent to the
2489 * MDT where the parent is located.
2491 * If the parent is a striped directory then it also needs to locate which
2492 * stripe the name of the child is located, and replace the parent FID
2493 * (@op->op_fid1) with the stripe FID. Note: if the stripe is unknown,
2494 * it will walk through all of sub-stripes until the child is being
2497 * \param[in] exp export refer to LMV
2498 * \param[in] op_data different parameters transferred beween client
2499 * MD stacks, name, namelen, FIDs etc.
2500 * op_fid1 is the parent FID, op_fid2 is the child
2502 * \param[out] request point to the request of unlink.
2504 * retval 0 if succeed
2505 * negative errno if failed.
2507 static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
2508 struct ptlrpc_request **request)
2510 struct obd_device *obd = exp->exp_obd;
2511 struct lmv_obd *lmv = &obd->u.lmv;
2512 struct lmv_tgt_desc *tgt = NULL;
2513 struct lmv_tgt_desc *parent_tgt = NULL;
2514 struct mdt_body *body;
2516 int stripe_index = 0;
2517 struct lmv_stripe_md *lsm = op_data->op_mea1;
2520 rc = lmv_check_connect(obd);
2524 /* For striped dir, we need to locate the parent as well */
2526 struct lmv_tgt_desc *tmp;
2528 LASSERT(op_data->op_name != NULL &&
2529 op_data->op_namelen != 0);
2531 tmp = lmv_locate_target_for_name(lmv, lsm,
2533 op_data->op_namelen,
2537 /* return -EBADFD means unknown hash type, might
2538 * need try all sub-stripe here */
2539 if (IS_ERR(tmp) && PTR_ERR(tmp) != -EBADFD)
2540 RETURN(PTR_ERR(tmp));
2542 /* Note: both migrating dir and unknown hash dir need to
2543 * try all of sub-stripes, so we need start search the
2544 * name from stripe 0, but migrating dir is already handled
2545 * inside lmv_locate_target_for_name(), so we only check
2546 * unknown hash type directory here */
2547 if (!lmv_is_known_hash_type(lsm->lsm_md_hash_type)) {
2548 struct lmv_oinfo *oinfo;
2550 oinfo = &lsm->lsm_md_oinfo[stripe_index];
2552 op_data->op_fid1 = oinfo->lmo_fid;
2553 op_data->op_mds = oinfo->lmo_mds;
2558 /* Send unlink requests to the MDT where the child is located */
2559 if (likely(!fid_is_zero(&op_data->op_fid2)))
2560 tgt = lmv_find_target(lmv, &op_data->op_fid2);
2561 else if (lsm != NULL)
2562 tgt = lmv_get_target(lmv, op_data->op_mds, NULL);
2564 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
2567 RETURN(PTR_ERR(tgt));
2569 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
2570 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
2571 op_data->op_cap = cfs_curproc_cap_pack();
2574 * If child's fid is given, cancel unused locks for it if it is from
2575 * another export than parent.
2577 * LOOKUP lock for child (fid3) should also be cancelled on parent
2578 * tgt_tgt in mdc_unlink().
2580 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2583 * Cancel FULL locks on child (fid3).
2585 parent_tgt = lmv_find_target(lmv, &op_data->op_fid1);
2586 if (IS_ERR(parent_tgt))
2587 RETURN(PTR_ERR(parent_tgt));
2589 if (parent_tgt != tgt) {
2590 rc = lmv_early_cancel(exp, parent_tgt, op_data, tgt->ltd_idx,
2591 LCK_EX, MDS_INODELOCK_LOOKUP,
2592 MF_MDC_CANCEL_FID3);
2595 rc = lmv_early_cancel(exp, NULL, op_data, tgt->ltd_idx, LCK_EX,
2596 MDS_INODELOCK_FULL, MF_MDC_CANCEL_FID3);
2600 CDEBUG(D_INODE, "unlink with fid="DFID"/"DFID" -> mds #%u\n",
2601 PFID(&op_data->op_fid1), PFID(&op_data->op_fid2), tgt->ltd_idx);
2603 rc = md_unlink(tgt->ltd_exp, op_data, request);
2604 if (rc != 0 && rc != -EREMOTE && rc != -ENOENT)
2607 /* Try next stripe if it is needed. */
2608 if (rc == -ENOENT && lsm != NULL && lmv_need_try_all_stripes(lsm)) {
2609 struct lmv_oinfo *oinfo;
2612 if (stripe_index >= lsm->lsm_md_stripe_count)
2615 oinfo = &lsm->lsm_md_oinfo[stripe_index];
2617 op_data->op_fid1 = oinfo->lmo_fid;
2618 op_data->op_mds = oinfo->lmo_mds;
2620 ptlrpc_req_finished(*request);
2623 goto try_next_stripe;
2626 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
2630 /* Not cross-ref case, just get out of here. */
2631 if (likely(!(body->mbo_valid & OBD_MD_MDS)))
2634 CDEBUG(D_INODE, "%s: try unlink to another MDT for "DFID"\n",
2635 exp->exp_obd->obd_name, PFID(&body->mbo_fid1));
2637 /* This is a remote object, try remote MDT, Note: it may
2638 * try more than 1 time here, Considering following case
2639 * /mnt/lustre is root on MDT0, remote1 is on MDT1
2640 * 1. Initially A does not know where remote1 is, it send
2641 * unlink RPC to MDT0, MDT0 return -EREMOTE, it will
2642 * resend unlink RPC to MDT1 (retry 1st time).
2644 * 2. During the unlink RPC in flight,
2645 * client B mv /mnt/lustre/remote1 /mnt/lustre/remote2
2646 * and create new remote1, but on MDT0
2648 * 3. MDT1 get unlink RPC(from A), then do remote lock on
2649 * /mnt/lustre, then lookup get fid of remote1, and find
2650 * it is remote dir again, and replay -EREMOTE again.
2652 * 4. Then A will resend unlink RPC to MDT0. (retry 2nd times).
2654 * In theory, it might try unlimited time here, but it should
2655 * be very rare case. */
2656 op_data->op_fid2 = body->mbo_fid1;
2657 ptlrpc_req_finished(*request);
2663 static int lmv_precleanup(struct obd_device *obd)
2666 fld_client_proc_fini(&obd->u.lmv.lmv_fld);
2667 lprocfs_obd_cleanup(obd);
2668 lprocfs_free_md_stats(obd);
2673 * Get by key a value associated with a LMV device.
2675 * Dispatch request to lower-layer devices as needed.
2677 * \param[in] env execution environment for this thread
2678 * \param[in] exp export for the LMV device
2679 * \param[in] keylen length of key identifier
2680 * \param[in] key identifier of key to get value for
2681 * \param[in] vallen size of \a val
2682 * \param[out] val pointer to storage location for value
2683 * \param[in] lsm optional striping metadata of object
2685 * \retval 0 on success
2686 * \retval negative negated errno on failure
2688 static int lmv_get_info(const struct lu_env *env, struct obd_export *exp,
2689 __u32 keylen, void *key, __u32 *vallen, void *val)
2691 struct obd_device *obd;
2692 struct lmv_obd *lmv;
2696 obd = class_exp2obd(exp);
2698 CDEBUG(D_IOCTL, "Invalid client cookie "LPX64"\n",
2699 exp->exp_handle.h_cookie);
2704 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
2707 rc = lmv_check_connect(obd);
2711 LASSERT(*vallen == sizeof(__u32));
2712 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2713 struct lmv_tgt_desc *tgt = lmv->tgts[i];
2715 * All tgts should be connected when this gets called.
2717 if (tgt == NULL || tgt->ltd_exp == NULL)
2720 if (!obd_get_info(env, tgt->ltd_exp, keylen, key,
2725 } else if (KEY_IS(KEY_MAX_EASIZE) ||
2726 KEY_IS(KEY_DEFAULT_EASIZE) ||
2727 KEY_IS(KEY_CONN_DATA)) {
2728 rc = lmv_check_connect(obd);
2733 * Forwarding this request to first MDS, it should know LOV
2736 rc = obd_get_info(env, lmv->tgts[0]->ltd_exp, keylen, key,
2738 if (!rc && KEY_IS(KEY_CONN_DATA))
2739 exp->exp_connect_data = *(struct obd_connect_data *)val;
2741 } else if (KEY_IS(KEY_TGT_COUNT)) {
2742 *((int *)val) = lmv->desc.ld_tgt_count;
2746 CDEBUG(D_IOCTL, "Invalid key\n");
2751 * Asynchronously set by key a value associated with a LMV device.
2753 * Dispatch request to lower-layer devices as needed.
2755 * \param[in] env execution environment for this thread
2756 * \param[in] exp export for the LMV device
2757 * \param[in] keylen length of key identifier
2758 * \param[in] key identifier of key to store value for
2759 * \param[in] vallen size of value to store
2760 * \param[in] val pointer to data to be stored
2761 * \param[in] set optional list of related ptlrpc requests
2763 * \retval 0 on success
2764 * \retval negative negated errno on failure
2766 int lmv_set_info_async(const struct lu_env *env, struct obd_export *exp,
2767 __u32 keylen, void *key, __u32 vallen, void *val,
2768 struct ptlrpc_request_set *set)
2770 struct lmv_tgt_desc *tgt = NULL;
2771 struct obd_device *obd;
2772 struct lmv_obd *lmv;
2776 obd = class_exp2obd(exp);
2778 CDEBUG(D_IOCTL, "Invalid client cookie "LPX64"\n",
2779 exp->exp_handle.h_cookie);
2784 if (KEY_IS(KEY_READ_ONLY) || KEY_IS(KEY_FLUSH_CTX) ||
2785 KEY_IS(KEY_DEFAULT_EASIZE)) {
2788 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2791 if (tgt == NULL || tgt->ltd_exp == NULL)
2794 err = obd_set_info_async(env, tgt->ltd_exp,
2795 keylen, key, vallen, val, set);
2806 static int lmv_unpack_md_v1(struct obd_export *exp, struct lmv_stripe_md *lsm,
2807 const struct lmv_mds_md_v1 *lmm1)
2809 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2816 lsm->lsm_md_magic = le32_to_cpu(lmm1->lmv_magic);
2817 lsm->lsm_md_stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
2818 lsm->lsm_md_master_mdt_index = le32_to_cpu(lmm1->lmv_master_mdt_index);
2819 if (OBD_FAIL_CHECK(OBD_FAIL_UNKNOWN_LMV_STRIPE))
2820 lsm->lsm_md_hash_type = LMV_HASH_TYPE_UNKNOWN;
2822 lsm->lsm_md_hash_type = le32_to_cpu(lmm1->lmv_hash_type);
2823 lsm->lsm_md_layout_version = le32_to_cpu(lmm1->lmv_layout_version);
2824 cplen = strlcpy(lsm->lsm_md_pool_name, lmm1->lmv_pool_name,
2825 sizeof(lsm->lsm_md_pool_name));
2827 if (cplen >= sizeof(lsm->lsm_md_pool_name))
2830 CDEBUG(D_INFO, "unpack lsm count %d, master %d hash_type %d"
2831 "layout_version %d\n", lsm->lsm_md_stripe_count,
2832 lsm->lsm_md_master_mdt_index, lsm->lsm_md_hash_type,
2833 lsm->lsm_md_layout_version);
2835 stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
2836 for (i = 0; i < stripe_count; i++) {
2837 fid_le_to_cpu(&lsm->lsm_md_oinfo[i].lmo_fid,
2838 &lmm1->lmv_stripe_fids[i]);
2839 rc = lmv_fld_lookup(lmv, &lsm->lsm_md_oinfo[i].lmo_fid,
2840 &lsm->lsm_md_oinfo[i].lmo_mds);
2843 CDEBUG(D_INFO, "unpack fid #%d "DFID"\n", i,
2844 PFID(&lsm->lsm_md_oinfo[i].lmo_fid));
2850 static int lmv_unpackmd(struct obd_export *exp, struct lmv_stripe_md **lsmp,
2851 const union lmv_mds_md *lmm, size_t lmm_size)
2853 struct lmv_stripe_md *lsm;
2856 bool allocated = false;
2859 LASSERT(lsmp != NULL);
2863 if (lsm != NULL && lmm == NULL) {
2865 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
2866 /* For migrating inode, the master stripe and master
2867 * object will be the same, so do not need iput, see
2868 * ll_update_lsm_md */
2869 if (!(lsm->lsm_md_hash_type & LMV_HASH_FLAG_MIGRATION &&
2870 i == 0) && lsm->lsm_md_oinfo[i].lmo_root != NULL)
2871 iput(lsm->lsm_md_oinfo[i].lmo_root);
2873 lsm_size = lmv_stripe_md_size(lsm->lsm_md_stripe_count);
2874 OBD_FREE(lsm, lsm_size);
2879 if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_STRIPE)
2883 if (le32_to_cpu(lmm->lmv_magic) != LMV_MAGIC_V1 &&
2884 le32_to_cpu(lmm->lmv_magic) != LMV_USER_MAGIC) {
2885 CERROR("%s: invalid lmv magic %x: rc = %d\n",
2886 exp->exp_obd->obd_name, le32_to_cpu(lmm->lmv_magic),
2891 if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_V1)
2892 lsm_size = lmv_stripe_md_size(lmv_mds_md_stripe_count_get(lmm));
2895 * Unpack default dirstripe(lmv_user_md) to lmv_stripe_md,
2896 * stripecount should be 0 then.
2898 lsm_size = lmv_stripe_md_size(0);
2900 lsm_size = lmv_stripe_md_size(lmv_mds_md_stripe_count_get(lmm));
2902 OBD_ALLOC(lsm, lsm_size);
2909 switch (le32_to_cpu(lmm->lmv_magic)) {
2911 rc = lmv_unpack_md_v1(exp, lsm, &lmm->lmv_md_v1);
2914 CERROR("%s: unrecognized magic %x\n", exp->exp_obd->obd_name,
2915 le32_to_cpu(lmm->lmv_magic));
2920 if (rc != 0 && allocated) {
2921 OBD_FREE(lsm, lsm_size);
2928 void lmv_free_memmd(struct lmv_stripe_md *lsm)
2930 lmv_unpackmd(NULL, &lsm, NULL, 0);
2932 EXPORT_SYMBOL(lmv_free_memmd);
2934 static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
2935 union ldlm_policy_data *policy,
2936 enum ldlm_mode mode, enum ldlm_cancel_flags flags,
2939 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2944 LASSERT(fid != NULL);
2946 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2947 struct lmv_tgt_desc *tgt = lmv->tgts[i];
2950 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
2953 err = md_cancel_unused(tgt->ltd_exp, fid, policy, mode, flags,
2961 static int lmv_set_lock_data(struct obd_export *exp,
2962 const struct lustre_handle *lockh,
2963 void *data, __u64 *bits)
2965 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2966 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2970 if (tgt == NULL || tgt->ltd_exp == NULL)
2972 rc = md_set_lock_data(tgt->ltd_exp, lockh, data, bits);
2976 enum ldlm_mode lmv_lock_match(struct obd_export *exp, __u64 flags,
2977 const struct lu_fid *fid, enum ldlm_type type,
2978 union ldlm_policy_data *policy,
2979 enum ldlm_mode mode, struct lustre_handle *lockh)
2981 struct obd_device *obd = exp->exp_obd;
2982 struct lmv_obd *lmv = &obd->u.lmv;
2988 CDEBUG(D_INODE, "Lock match for "DFID"\n", PFID(fid));
2991 * With DNE every object can have two locks in different namespaces:
2992 * lookup lock in space of MDT storing direntry and update/open lock in
2993 * space of MDT storing inode. Try the MDT that the FID maps to first,
2994 * since this can be easily found, and only try others if that fails.
2996 for (i = 0, tgt = lmv_find_target_index(lmv, fid);
2997 i < lmv->desc.ld_tgt_count;
2998 i++, tgt = (tgt + 1) % lmv->desc.ld_tgt_count) {
3000 CDEBUG(D_HA, "%s: "DFID" is inaccessible: rc = %d\n",
3001 obd->obd_name, PFID(fid), tgt);
3005 if (lmv->tgts[tgt] == NULL ||
3006 lmv->tgts[tgt]->ltd_exp == NULL ||
3007 lmv->tgts[tgt]->ltd_active == 0)
3010 rc = md_lock_match(lmv->tgts[tgt]->ltd_exp, flags, fid,
3011 type, policy, mode, lockh);
3019 int lmv_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
3020 struct obd_export *dt_exp, struct obd_export *md_exp,
3021 struct lustre_md *md)
3023 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
3024 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3026 if (tgt == NULL || tgt->ltd_exp == NULL)
3029 return md_get_lustre_md(lmv->tgts[0]->ltd_exp, req, dt_exp, md_exp, md);
3032 int lmv_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
3034 struct obd_device *obd = exp->exp_obd;
3035 struct lmv_obd *lmv = &obd->u.lmv;
3036 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3039 if (md->lmv != NULL) {
3040 lmv_free_memmd(md->lmv);
3043 if (tgt == NULL || tgt->ltd_exp == NULL)
3045 RETURN(md_free_lustre_md(lmv->tgts[0]->ltd_exp, md));
3048 int lmv_set_open_replay_data(struct obd_export *exp,
3049 struct obd_client_handle *och,
3050 struct lookup_intent *it)
3052 struct obd_device *obd = exp->exp_obd;
3053 struct lmv_obd *lmv = &obd->u.lmv;
3054 struct lmv_tgt_desc *tgt;
3057 tgt = lmv_find_target(lmv, &och->och_fid);
3059 RETURN(PTR_ERR(tgt));
3061 RETURN(md_set_open_replay_data(tgt->ltd_exp, och, it));
3064 int lmv_clear_open_replay_data(struct obd_export *exp,
3065 struct obd_client_handle *och)
3067 struct obd_device *obd = exp->exp_obd;
3068 struct lmv_obd *lmv = &obd->u.lmv;
3069 struct lmv_tgt_desc *tgt;
3072 tgt = lmv_find_target(lmv, &och->och_fid);
3074 RETURN(PTR_ERR(tgt));
3076 RETURN(md_clear_open_replay_data(tgt->ltd_exp, och));
3079 int lmv_intent_getattr_async(struct obd_export *exp,
3080 struct md_enqueue_info *minfo)
3082 struct md_op_data *op_data = &minfo->mi_data;
3083 struct obd_device *obd = exp->exp_obd;
3084 struct lmv_obd *lmv = &obd->u.lmv;
3085 struct lmv_tgt_desc *ptgt = NULL;
3086 struct lmv_tgt_desc *ctgt = NULL;
3090 if (!fid_is_sane(&op_data->op_fid2))
3093 rc = lmv_check_connect(obd);
3097 ptgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
3099 RETURN(PTR_ERR(ptgt));
3101 ctgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
3103 RETURN(PTR_ERR(ctgt));
3106 * if child is on remote MDT, we need 2 async RPCs to fetch both LOOKUP
3107 * lock on parent, and UPDATE lock on child MDT, which makes all
3108 * complicated. Considering remote dir is rare case, and not supporting
3109 * it in statahead won't cause any issue, drop its support for now.
3114 rc = md_intent_getattr_async(ptgt->ltd_exp, minfo);
3118 int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
3119 struct lu_fid *fid, __u64 *bits)
3121 struct obd_device *obd = exp->exp_obd;
3122 struct lmv_obd *lmv = &obd->u.lmv;
3123 struct lmv_tgt_desc *tgt;
3127 rc = lmv_check_connect(obd);
3131 tgt = lmv_find_target(lmv, fid);
3133 RETURN(PTR_ERR(tgt));
3135 rc = md_revalidate_lock(tgt->ltd_exp, it, fid, bits);
3139 int lmv_get_fid_from_lsm(struct obd_export *exp,
3140 const struct lmv_stripe_md *lsm,
3141 const char *name, int namelen, struct lu_fid *fid)
3143 const struct lmv_oinfo *oinfo;
3145 LASSERT(lsm != NULL);
3146 oinfo = lsm_name_to_stripe_info(lsm, name, namelen);
3148 return PTR_ERR(oinfo);
3150 *fid = oinfo->lmo_fid;
3156 * For lmv, only need to send request to master MDT, and the master MDT will
3157 * process with other slave MDTs. The only exception is Q_GETOQUOTA for which
3158 * we directly fetch data from the slave MDTs.
3160 int lmv_quotactl(struct obd_device *unused, struct obd_export *exp,
3161 struct obd_quotactl *oqctl)
3163 struct obd_device *obd = class_exp2obd(exp);
3164 struct lmv_obd *lmv = &obd->u.lmv;
3165 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3168 __u64 curspace, curinodes;
3172 tgt->ltd_exp == NULL ||
3174 lmv->desc.ld_tgt_count == 0) {
3175 CERROR("master lmv inactive\n");
3179 if (oqctl->qc_cmd != Q_GETOQUOTA) {
3180 rc = obd_quotactl(tgt->ltd_exp, oqctl);
3184 curspace = curinodes = 0;
3185 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
3189 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
3192 err = obd_quotactl(tgt->ltd_exp, oqctl);
3194 CERROR("getquota on mdt %d failed. %d\n", i, err);
3198 curspace += oqctl->qc_dqblk.dqb_curspace;
3199 curinodes += oqctl->qc_dqblk.dqb_curinodes;
3202 oqctl->qc_dqblk.dqb_curspace = curspace;
3203 oqctl->qc_dqblk.dqb_curinodes = curinodes;
3208 static int lmv_merge_attr(struct obd_export *exp,
3209 const struct lmv_stripe_md *lsm,
3210 struct cl_attr *attr,
3211 ldlm_blocking_callback cb_blocking)
3216 rc = lmv_revalidate_slaves(exp, lsm, cb_blocking, 0);
3220 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
3221 struct inode *inode = lsm->lsm_md_oinfo[i].lmo_root;
3223 CDEBUG(D_INFO, ""DFID" size %llu, blocks %llu nlink %u,"
3224 " atime %lu ctime %lu, mtime %lu.\n",
3225 PFID(&lsm->lsm_md_oinfo[i].lmo_fid),
3226 i_size_read(inode), (unsigned long long)inode->i_blocks,
3227 inode->i_nlink, LTIME_S(inode->i_atime),
3228 LTIME_S(inode->i_ctime), LTIME_S(inode->i_mtime));
3230 /* for slave stripe, it needs to subtract nlink for . and .. */
3232 attr->cat_nlink += inode->i_nlink - 2;
3234 attr->cat_nlink = inode->i_nlink;
3236 attr->cat_size += i_size_read(inode);
3237 attr->cat_blocks += inode->i_blocks;
3239 if (attr->cat_atime < LTIME_S(inode->i_atime))
3240 attr->cat_atime = LTIME_S(inode->i_atime);
3242 if (attr->cat_ctime < LTIME_S(inode->i_ctime))
3243 attr->cat_ctime = LTIME_S(inode->i_ctime);
3245 if (attr->cat_mtime < LTIME_S(inode->i_mtime))
3246 attr->cat_mtime = LTIME_S(inode->i_mtime);
3251 struct obd_ops lmv_obd_ops = {
3252 .o_owner = THIS_MODULE,
3253 .o_setup = lmv_setup,
3254 .o_cleanup = lmv_cleanup,
3255 .o_precleanup = lmv_precleanup,
3256 .o_process_config = lmv_process_config,
3257 .o_connect = lmv_connect,
3258 .o_disconnect = lmv_disconnect,
3259 .o_statfs = lmv_statfs,
3260 .o_get_info = lmv_get_info,
3261 .o_set_info_async = lmv_set_info_async,
3262 .o_notify = lmv_notify,
3263 .o_get_uuid = lmv_get_uuid,
3264 .o_iocontrol = lmv_iocontrol,
3265 .o_quotactl = lmv_quotactl
3268 struct md_ops lmv_md_ops = {
3269 .m_get_root = lmv_get_root,
3270 .m_null_inode = lmv_null_inode,
3271 .m_close = lmv_close,
3272 .m_create = lmv_create,
3273 .m_enqueue = lmv_enqueue,
3274 .m_getattr = lmv_getattr,
3275 .m_getxattr = lmv_getxattr,
3276 .m_getattr_name = lmv_getattr_name,
3277 .m_intent_lock = lmv_intent_lock,
3279 .m_rename = lmv_rename,
3280 .m_setattr = lmv_setattr,
3281 .m_setxattr = lmv_setxattr,
3282 .m_fsync = lmv_fsync,
3283 .m_read_page = lmv_read_page,
3284 .m_unlink = lmv_unlink,
3285 .m_init_ea_size = lmv_init_ea_size,
3286 .m_cancel_unused = lmv_cancel_unused,
3287 .m_set_lock_data = lmv_set_lock_data,
3288 .m_lock_match = lmv_lock_match,
3289 .m_get_lustre_md = lmv_get_lustre_md,
3290 .m_free_lustre_md = lmv_free_lustre_md,
3291 .m_merge_attr = lmv_merge_attr,
3292 .m_set_open_replay_data = lmv_set_open_replay_data,
3293 .m_clear_open_replay_data = lmv_clear_open_replay_data,
3294 .m_intent_getattr_async = lmv_intent_getattr_async,
3295 .m_revalidate_lock = lmv_revalidate_lock,
3296 .m_get_fid_from_lsm = lmv_get_fid_from_lsm,
3297 .m_unpackmd = lmv_unpackmd,
3300 static int __init lmv_init(void)
3302 return class_register_type(&lmv_obd_ops, &lmv_md_ops, true, NULL,
3303 LUSTRE_LMV_NAME, NULL);
3306 static void __exit lmv_exit(void)
3308 class_unregister_type(LUSTRE_LMV_NAME);
3311 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
3312 MODULE_DESCRIPTION("Lustre Logical Metadata Volume");
3313 MODULE_VERSION(LUSTRE_VERSION_STRING);
3314 MODULE_LICENSE("GPL");
3316 module_init(lmv_init);
3317 module_exit(lmv_exit);