4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 #define DEBUG_SUBSYSTEM S_LMV
35 #include <linux/file.h>
36 #include <linux/module.h>
37 #include <linux/init.h>
38 #include <linux/user_namespace.h>
39 #ifdef HAVE_UIDGID_HEADER
40 # include <linux/uidgid.h>
42 #include <linux/slab.h>
43 #include <linux/pagemap.h>
45 #include <linux/math64.h>
46 #include <linux/seq_file.h>
47 #include <linux/namei.h>
49 #include <obd_support.h>
50 #include <lustre_lib.h>
51 #include <lustre_net.h>
52 #include <obd_class.h>
53 #include <lustre_lmv.h>
54 #include <lprocfs_status.h>
55 #include <cl_object.h>
56 #include <lustre_fid.h>
57 #include <uapi/linux/lustre/lustre_ioctl.h>
58 #include <lustre_kernelcomm.h>
59 #include "lmv_internal.h"
61 static int lmv_check_connect(struct obd_device *obd);
63 static void lmv_activate_target(struct lmv_obd *lmv,
64 struct lmv_tgt_desc *tgt,
67 if (tgt->ltd_active == activate)
70 tgt->ltd_active = activate;
71 lmv->desc.ld_active_tgt_count += (activate ? 1 : -1);
73 tgt->ltd_exp->exp_obd->obd_inactive = !activate;
79 * -EINVAL : UUID can't be found in the LMV's target list
80 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
81 * -EBADF : The UUID is found, but the OBD of the wrong type (!)
83 static int lmv_set_mdc_active(struct lmv_obd *lmv,
84 const struct obd_uuid *uuid,
87 struct lmv_tgt_desc *tgt = NULL;
88 struct obd_device *obd;
93 CDEBUG(D_INFO, "Searching in lmv %p for uuid %s (activate=%d)\n",
94 lmv, uuid->uuid, activate);
96 spin_lock(&lmv->lmv_lock);
97 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
99 if (tgt == NULL || tgt->ltd_exp == NULL)
102 CDEBUG(D_INFO, "Target idx %d is %s conn %#llx\n", i,
103 tgt->ltd_uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
105 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
109 if (i == lmv->desc.ld_tgt_count)
110 GOTO(out_lmv_lock, rc = -EINVAL);
112 obd = class_exp2obd(tgt->ltd_exp);
114 GOTO(out_lmv_lock, rc = -ENOTCONN);
116 CDEBUG(D_INFO, "Found OBD %s=%s device %d (%p) type %s at LMV idx %d\n",
117 obd->obd_name, obd->obd_uuid.uuid, obd->obd_minor, obd,
118 obd->obd_type->typ_name, i);
119 LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0);
121 if (tgt->ltd_active == activate) {
122 CDEBUG(D_INFO, "OBD %p already %sactive!\n", obd,
123 activate ? "" : "in");
124 GOTO(out_lmv_lock, rc);
127 CDEBUG(D_INFO, "Marking OBD %p %sactive\n", obd,
128 activate ? "" : "in");
129 lmv_activate_target(lmv, tgt, activate);
133 spin_unlock(&lmv->lmv_lock);
137 struct obd_uuid *lmv_get_uuid(struct obd_export *exp)
139 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
140 struct lmv_tgt_desc *tgt = lmv->tgts[0];
142 return (tgt == NULL) ? NULL : obd_get_uuid(tgt->ltd_exp);
145 static int lmv_notify(struct obd_device *obd, struct obd_device *watched,
146 enum obd_notify_event ev)
148 struct obd_connect_data *conn_data;
149 struct lmv_obd *lmv = &obd->u.lmv;
150 struct obd_uuid *uuid;
154 if (strcmp(watched->obd_type->typ_name, LUSTRE_MDC_NAME)) {
155 CERROR("unexpected notification of %s %s!\n",
156 watched->obd_type->typ_name,
161 uuid = &watched->u.cli.cl_target_uuid;
162 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE) {
164 * Set MDC as active before notifying the observer, so the
165 * observer can use the MDC normally.
167 rc = lmv_set_mdc_active(lmv, uuid,
168 ev == OBD_NOTIFY_ACTIVE);
170 CERROR("%sactivation of %s failed: %d\n",
171 ev == OBD_NOTIFY_ACTIVE ? "" : "de",
175 } else if (ev == OBD_NOTIFY_OCD) {
176 conn_data = &watched->u.cli.cl_import->imp_connect_data;
178 * XXX: Make sure that ocd_connect_flags from all targets are
179 * the same. Otherwise one of MDTs runs wrong version or
180 * something like this. --umka
182 obd->obd_self_export->exp_connect_data = *conn_data;
186 * Pass the notification up the chain.
188 if (obd->obd_observer)
189 rc = obd_notify(obd->obd_observer, watched, ev);
194 static int lmv_connect(const struct lu_env *env,
195 struct obd_export **pexp, struct obd_device *obd,
196 struct obd_uuid *cluuid, struct obd_connect_data *data,
199 struct lmv_obd *lmv = &obd->u.lmv;
200 struct lustre_handle conn = { 0 };
201 struct obd_export *exp;
205 rc = class_connect(&conn, obd, cluuid);
207 CERROR("class_connection() returned %d\n", rc);
211 exp = class_conn2export(&conn);
214 lmv->conn_data = *data;
216 if (lmv->targets_proc_entry == NULL) {
217 lmv->targets_proc_entry = lprocfs_register("target_obds",
220 if (IS_ERR(lmv->targets_proc_entry)) {
221 CERROR("%s: cannot register "
222 "/proc/fs/lustre/%s/%s/target_obds\n",
223 obd->obd_name, obd->obd_type->typ_name,
225 lmv->targets_proc_entry = NULL;
229 rc = lmv_check_connect(obd);
238 if (lmv->targets_proc_entry != NULL)
239 lprocfs_remove(&lmv->targets_proc_entry);
241 class_disconnect(exp);
246 static int lmv_init_ea_size(struct obd_export *exp, __u32 easize,
249 struct obd_device *obd = exp->exp_obd;
250 struct lmv_obd *lmv = &obd->u.lmv;
256 if (lmv->max_easize < easize) {
257 lmv->max_easize = easize;
260 if (lmv->max_def_easize < def_easize) {
261 lmv->max_def_easize = def_easize;
268 if (lmv->connected == 0)
271 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
272 struct lmv_tgt_desc *tgt = lmv->tgts[i];
274 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active) {
275 CWARN("%s: NULL export for %d\n", obd->obd_name, i);
279 rc = md_init_ea_size(tgt->ltd_exp, easize, def_easize);
281 CERROR("%s: obd_init_ea_size() failed on MDT target %d:"
282 " rc = %d\n", obd->obd_name, i, rc);
289 #define MAX_STRING_SIZE 128
291 int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
293 struct lmv_obd *lmv = &obd->u.lmv;
294 struct obd_device *mdc_obd;
295 struct obd_export *mdc_exp;
296 struct lu_fld_target target;
300 mdc_obd = class_find_client_obd(&tgt->ltd_uuid, LUSTRE_MDC_NAME,
303 CERROR("target %s not attached\n", tgt->ltd_uuid.uuid);
307 CDEBUG(D_CONFIG, "connect to %s(%s) - %s, %s\n",
308 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
309 tgt->ltd_uuid.uuid, obd->obd_uuid.uuid);
311 if (!mdc_obd->obd_set_up) {
312 CERROR("target %s is not set up\n", tgt->ltd_uuid.uuid);
316 rc = obd_connect(NULL, &mdc_exp, mdc_obd, &obd->obd_uuid,
317 &lmv->conn_data, NULL);
319 CERROR("target %s connect error %d\n", tgt->ltd_uuid.uuid, rc);
324 * Init fid sequence client for this mdc and add new fld target.
326 rc = obd_fid_init(mdc_obd, mdc_exp, LUSTRE_SEQ_METADATA);
330 target.ft_srv = NULL;
331 target.ft_exp = mdc_exp;
332 target.ft_idx = tgt->ltd_idx;
334 fld_client_add_target(&lmv->lmv_fld, &target);
336 rc = obd_register_observer(mdc_obd, obd);
338 obd_disconnect(mdc_exp);
339 CERROR("target %s register_observer error %d\n",
340 tgt->ltd_uuid.uuid, rc);
344 if (obd->obd_observer) {
346 * Tell the observer about the new target.
348 rc = obd_notify(obd->obd_observer, mdc_exp->exp_obd,
351 obd_disconnect(mdc_exp);
357 tgt->ltd_exp = mdc_exp;
358 lmv->desc.ld_active_tgt_count++;
360 md_init_ea_size(tgt->ltd_exp, lmv->max_easize, lmv->max_def_easize);
362 CDEBUG(D_CONFIG, "Connected to %s(%s) successfully (%d)\n",
363 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
364 atomic_read(&obd->obd_refcount));
366 if (lmv->targets_proc_entry != NULL) {
367 struct proc_dir_entry *mdc_symlink;
369 LASSERT(mdc_obd->obd_type != NULL);
370 LASSERT(mdc_obd->obd_type->typ_name != NULL);
371 mdc_symlink = lprocfs_add_symlink(mdc_obd->obd_name,
372 lmv->targets_proc_entry,
374 mdc_obd->obd_type->typ_name,
376 if (mdc_symlink == NULL) {
377 CERROR("cannot register LMV target "
378 "/proc/fs/lustre/%s/%s/target_obds/%s\n",
379 obd->obd_type->typ_name, obd->obd_name,
386 static void lmv_del_target(struct lmv_obd *lmv, int index)
388 if (lmv->tgts[index] == NULL)
391 OBD_FREE_PTR(lmv->tgts[index]);
392 lmv->tgts[index] = NULL;
396 static int lmv_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
397 __u32 index, int gen)
399 struct obd_device *mdc_obd;
400 struct lmv_obd *lmv = &obd->u.lmv;
401 struct lmv_tgt_desc *tgt;
402 int orig_tgt_count = 0;
406 CDEBUG(D_CONFIG, "Target uuid: %s. index %d\n", uuidp->uuid, index);
407 mdc_obd = class_find_client_obd(uuidp, LUSTRE_MDC_NAME,
410 CERROR("%s: Target %s not attached: rc = %d\n",
411 obd->obd_name, uuidp->uuid, -EINVAL);
415 mutex_lock(&lmv->lmv_init_mutex);
416 if ((index < lmv->tgts_size) && (lmv->tgts[index] != NULL)) {
417 tgt = lmv->tgts[index];
418 CERROR("%s: UUID %s already assigned at LMV target index %d:"
419 " rc = %d\n", obd->obd_name,
420 obd_uuid2str(&tgt->ltd_uuid), index, -EEXIST);
421 mutex_unlock(&lmv->lmv_init_mutex);
425 if (index >= lmv->tgts_size) {
426 /* We need to reallocate the lmv target array. */
427 struct lmv_tgt_desc **newtgts, **old = NULL;
431 while (newsize < index + 1)
432 newsize = newsize << 1;
433 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
434 if (newtgts == NULL) {
435 mutex_unlock(&lmv->lmv_init_mutex);
439 if (lmv->tgts_size) {
440 memcpy(newtgts, lmv->tgts,
441 sizeof(*newtgts) * lmv->tgts_size);
443 oldsize = lmv->tgts_size;
447 lmv->tgts_size = newsize;
450 OBD_FREE(old, sizeof(*old) * oldsize);
452 CDEBUG(D_CONFIG, "tgts: %p size: %d\n", lmv->tgts,
458 mutex_unlock(&lmv->lmv_init_mutex);
462 mutex_init(&tgt->ltd_fid_mutex);
463 tgt->ltd_idx = index;
464 tgt->ltd_uuid = *uuidp;
466 lmv->tgts[index] = tgt;
467 if (index >= lmv->desc.ld_tgt_count) {
468 orig_tgt_count = lmv->desc.ld_tgt_count;
469 lmv->desc.ld_tgt_count = index + 1;
472 if (lmv->connected == 0) {
473 /* lmv_check_connect() will connect this target. */
474 mutex_unlock(&lmv->lmv_init_mutex);
478 /* Otherwise let's connect it ourselves */
479 mutex_unlock(&lmv->lmv_init_mutex);
480 rc = lmv_connect_mdc(obd, tgt);
482 spin_lock(&lmv->lmv_lock);
483 if (lmv->desc.ld_tgt_count == index + 1)
484 lmv->desc.ld_tgt_count = orig_tgt_count;
485 memset(tgt, 0, sizeof(*tgt));
486 spin_unlock(&lmv->lmv_lock);
488 int easize = sizeof(struct lmv_stripe_md) +
489 lmv->desc.ld_tgt_count * sizeof(struct lu_fid);
490 lmv_init_ea_size(obd->obd_self_export, easize, 0);
496 static int lmv_check_connect(struct obd_device *obd)
498 struct lmv_obd *lmv = &obd->u.lmv;
499 struct lmv_tgt_desc *tgt;
508 mutex_lock(&lmv->lmv_init_mutex);
509 if (lmv->connected) {
510 mutex_unlock(&lmv->lmv_init_mutex);
514 if (lmv->desc.ld_tgt_count == 0) {
515 mutex_unlock(&lmv->lmv_init_mutex);
516 CERROR("%s: no targets configured.\n", obd->obd_name);
520 LASSERT(lmv->tgts != NULL);
522 if (lmv->tgts[0] == NULL) {
523 mutex_unlock(&lmv->lmv_init_mutex);
524 CERROR("%s: no target configured for index 0.\n",
529 CDEBUG(D_CONFIG, "Time to connect %s to %s\n",
530 obd->obd_uuid.uuid, obd->obd_name);
532 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
536 rc = lmv_connect_mdc(obd, tgt);
542 easize = lmv_mds_md_size(lmv->desc.ld_tgt_count, LMV_MAGIC);
543 lmv_init_ea_size(obd->obd_self_export, easize, 0);
544 mutex_unlock(&lmv->lmv_init_mutex);
555 --lmv->desc.ld_active_tgt_count;
556 rc2 = obd_disconnect(tgt->ltd_exp);
558 CERROR("LMV target %s disconnect on "
559 "MDC idx %d: error %d\n",
560 tgt->ltd_uuid.uuid, i, rc2);
565 mutex_unlock(&lmv->lmv_init_mutex);
570 static int lmv_disconnect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
572 struct lmv_obd *lmv = &obd->u.lmv;
573 struct obd_device *mdc_obd;
577 LASSERT(tgt != NULL);
578 LASSERT(obd != NULL);
580 mdc_obd = class_exp2obd(tgt->ltd_exp);
583 mdc_obd->obd_force = obd->obd_force;
584 mdc_obd->obd_fail = obd->obd_fail;
585 mdc_obd->obd_no_recov = obd->obd_no_recov;
587 if (lmv->targets_proc_entry != NULL)
588 lprocfs_remove_proc_entry(mdc_obd->obd_name,
589 lmv->targets_proc_entry);
592 rc = obd_fid_fini(tgt->ltd_exp->exp_obd);
594 CERROR("Can't finanize fids factory\n");
596 CDEBUG(D_INFO, "Disconnected from %s(%s) successfully\n",
597 tgt->ltd_exp->exp_obd->obd_name,
598 tgt->ltd_exp->exp_obd->obd_uuid.uuid);
600 obd_register_observer(tgt->ltd_exp->exp_obd, NULL);
601 rc = obd_disconnect(tgt->ltd_exp);
603 if (tgt->ltd_active) {
604 CERROR("Target %s disconnect error %d\n",
605 tgt->ltd_uuid.uuid, rc);
609 lmv_activate_target(lmv, tgt, 0);
614 static int lmv_disconnect(struct obd_export *exp)
616 struct obd_device *obd = class_exp2obd(exp);
617 struct lmv_obd *lmv = &obd->u.lmv;
625 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
626 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
629 lmv_disconnect_mdc(obd, lmv->tgts[i]);
632 if (lmv->targets_proc_entry != NULL)
633 lprocfs_remove(&lmv->targets_proc_entry);
635 CERROR("/proc/fs/lustre/%s/%s/target_obds missing\n",
636 obd->obd_type->typ_name, obd->obd_name);
640 * This is the case when no real connection is established by
641 * lmv_check_connect().
644 class_export_put(exp);
645 rc = class_disconnect(exp);
651 static int lmv_fid2path(struct obd_export *exp, int len, void *karg,
654 struct obd_device *obddev = class_exp2obd(exp);
655 struct lmv_obd *lmv = &obddev->u.lmv;
656 struct getinfo_fid2path *gf;
657 struct lmv_tgt_desc *tgt;
658 struct getinfo_fid2path *remote_gf = NULL;
659 struct lu_fid root_fid;
660 int remote_gf_size = 0;
664 tgt = lmv_find_target(lmv, &gf->gf_fid);
666 RETURN(PTR_ERR(tgt));
668 root_fid = *gf->gf_u.gf_root_fid;
669 LASSERT(fid_is_sane(&root_fid));
672 rc = obd_iocontrol(OBD_IOC_FID2PATH, tgt->ltd_exp, len, gf, uarg);
673 if (rc != 0 && rc != -EREMOTE)
674 GOTO(out_fid2path, rc);
676 /* If remote_gf != NULL, it means just building the
677 * path on the remote MDT, copy this path segement to gf */
678 if (remote_gf != NULL) {
679 struct getinfo_fid2path *ori_gf;
682 ori_gf = (struct getinfo_fid2path *)karg;
683 if (strlen(ori_gf->gf_u.gf_path) + 1 +
684 strlen(gf->gf_u.gf_path) + 1 > ori_gf->gf_pathlen)
685 GOTO(out_fid2path, rc = -EOVERFLOW);
687 ptr = ori_gf->gf_u.gf_path;
689 memmove(ptr + strlen(gf->gf_u.gf_path) + 1, ptr,
690 strlen(ori_gf->gf_u.gf_path));
692 strncpy(ptr, gf->gf_u.gf_path,
693 strlen(gf->gf_u.gf_path));
694 ptr += strlen(gf->gf_u.gf_path);
698 CDEBUG(D_INFO, "%s: get path %s "DFID" rec: %llu ln: %u\n",
699 tgt->ltd_exp->exp_obd->obd_name,
700 gf->gf_u.gf_path, PFID(&gf->gf_fid), gf->gf_recno,
704 GOTO(out_fid2path, rc);
706 /* sigh, has to go to another MDT to do path building further */
707 if (remote_gf == NULL) {
708 remote_gf_size = sizeof(*remote_gf) + PATH_MAX;
709 OBD_ALLOC(remote_gf, remote_gf_size);
710 if (remote_gf == NULL)
711 GOTO(out_fid2path, rc = -ENOMEM);
712 remote_gf->gf_pathlen = PATH_MAX;
715 if (!fid_is_sane(&gf->gf_fid)) {
716 CERROR("%s: invalid FID "DFID": rc = %d\n",
717 tgt->ltd_exp->exp_obd->obd_name,
718 PFID(&gf->gf_fid), -EINVAL);
719 GOTO(out_fid2path, rc = -EINVAL);
722 tgt = lmv_find_target(lmv, &gf->gf_fid);
724 GOTO(out_fid2path, rc = -EINVAL);
726 remote_gf->gf_fid = gf->gf_fid;
727 remote_gf->gf_recno = -1;
728 remote_gf->gf_linkno = -1;
729 memset(remote_gf->gf_u.gf_path, 0, remote_gf->gf_pathlen);
730 *remote_gf->gf_u.gf_root_fid = root_fid;
732 goto repeat_fid2path;
735 if (remote_gf != NULL)
736 OBD_FREE(remote_gf, remote_gf_size);
740 static int lmv_hsm_req_count(struct lmv_obd *lmv,
741 const struct hsm_user_request *hur,
742 const struct lmv_tgt_desc *tgt_mds)
746 struct lmv_tgt_desc *curr_tgt;
748 /* count how many requests must be sent to the given target */
749 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
750 curr_tgt = lmv_find_target(lmv, &hur->hur_user_item[i].hui_fid);
751 if (IS_ERR(curr_tgt))
752 RETURN(PTR_ERR(curr_tgt));
753 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid))
759 static int lmv_hsm_req_build(struct lmv_obd *lmv,
760 struct hsm_user_request *hur_in,
761 const struct lmv_tgt_desc *tgt_mds,
762 struct hsm_user_request *hur_out)
765 struct lmv_tgt_desc *curr_tgt;
767 /* build the hsm_user_request for the given target */
768 hur_out->hur_request = hur_in->hur_request;
770 for (i = 0; i < hur_in->hur_request.hr_itemcount; i++) {
771 curr_tgt = lmv_find_target(lmv,
772 &hur_in->hur_user_item[i].hui_fid);
773 if (IS_ERR(curr_tgt))
774 RETURN(PTR_ERR(curr_tgt));
775 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid)) {
776 hur_out->hur_user_item[nr_out] =
777 hur_in->hur_user_item[i];
781 hur_out->hur_request.hr_itemcount = nr_out;
782 memcpy(hur_data(hur_out), hur_data(hur_in),
783 hur_in->hur_request.hr_data_len);
788 static int lmv_hsm_ct_unregister(struct obd_device *obd, unsigned int cmd,
789 int len, struct lustre_kernelcomm *lk,
792 struct lmv_obd *lmv = &obd->u.lmv;
797 /* unregister request (call from llapi_hsm_copytool_fini) */
798 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
799 struct lmv_tgt_desc *tgt = lmv->tgts[i];
801 if (tgt == NULL || tgt->ltd_exp == NULL)
803 /* best effort: try to clean as much as possible
804 * (continue on error) */
805 obd_iocontrol(cmd, tgt->ltd_exp, len, lk, uarg);
808 /* Whatever the result, remove copytool from kuc groups.
809 * Unreached coordinators will get EPIPE on next requests
810 * and will unregister automatically.
812 rc = libcfs_kkuc_group_rem(&obd->obd_uuid, lk->lk_uid, lk->lk_group);
817 static int lmv_hsm_ct_register(struct obd_device *obd, unsigned int cmd,
818 int len, struct lustre_kernelcomm *lk,
821 struct lmv_obd *lmv = &obd->u.lmv;
825 bool any_set = false;
826 struct kkuc_ct_data kcd = {
827 .kcd_magic = KKUC_CT_DATA_MAGIC,
828 .kcd_archive = lk->lk_data,
833 filp = fget(lk->lk_wfd);
837 rc = libcfs_kkuc_group_add(filp, &obd->obd_uuid, lk->lk_uid,
838 lk->lk_group, &kcd, sizeof(kcd));
842 /* All or nothing: try to register to all MDS.
843 * In case of failure, unregister from previous MDS,
844 * except if it because of inactive target. */
845 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
846 struct lmv_tgt_desc *tgt = lmv->tgts[i];
848 if (tgt == NULL || tgt->ltd_exp == NULL)
851 err = obd_iocontrol(cmd, tgt->ltd_exp, len, lk, uarg);
853 if (tgt->ltd_active) {
854 /* permanent error */
855 CERROR("%s: iocontrol MDC %s on MDT"
856 " idx %d cmd %x: err = %d\n",
857 lmv2obd_dev(lmv)->obd_name,
858 tgt->ltd_uuid.uuid, i, cmd, err);
860 lk->lk_flags |= LK_FLG_STOP;
861 /* unregister from previous MDS */
862 for (j = 0; j < i; j++) {
864 if (tgt == NULL || tgt->ltd_exp == NULL)
866 obd_iocontrol(cmd, tgt->ltd_exp, len,
869 GOTO(err_kkuc_rem, rc);
871 /* else: transient error.
872 * kuc will register to the missing MDT
880 /* no registration done: return error */
881 GOTO(err_kkuc_rem, rc = -ENOTCONN);
886 libcfs_kkuc_group_rem(&obd->obd_uuid, lk->lk_uid, lk->lk_group);
896 static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
897 int len, void *karg, void __user *uarg)
899 struct obd_device *obddev = class_exp2obd(exp);
900 struct lmv_obd *lmv = &obddev->u.lmv;
901 struct lmv_tgt_desc *tgt = NULL;
905 __u32 count = lmv->desc.ld_tgt_count;
912 case IOC_OBD_STATFS: {
913 struct obd_ioctl_data *data = karg;
914 struct obd_device *mdc_obd;
915 struct obd_statfs stat_buf = {0};
918 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
919 if ((index >= count))
922 tgt = lmv->tgts[index];
923 if (tgt == NULL || !tgt->ltd_active)
926 mdc_obd = class_exp2obd(tgt->ltd_exp);
931 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(mdc_obd),
932 min((int) data->ioc_plen2,
933 (int) sizeof(struct obd_uuid))))
936 rc = obd_statfs(NULL, tgt->ltd_exp, &stat_buf,
937 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
941 if (copy_to_user(data->ioc_pbuf1, &stat_buf,
942 min((int) data->ioc_plen1,
943 (int) sizeof(stat_buf))))
947 case OBD_IOC_QUOTACTL: {
948 struct if_quotactl *qctl = karg;
949 struct obd_quotactl *oqctl;
951 if (qctl->qc_valid == QC_MDTIDX) {
952 if (count <= qctl->qc_idx)
955 tgt = lmv->tgts[qctl->qc_idx];
956 if (tgt == NULL || tgt->ltd_exp == NULL)
958 } else if (qctl->qc_valid == QC_UUID) {
959 for (i = 0; i < count; i++) {
963 if (!obd_uuid_equals(&tgt->ltd_uuid,
967 if (tgt->ltd_exp == NULL)
979 LASSERT(tgt != NULL && tgt->ltd_exp != NULL);
980 OBD_ALLOC_PTR(oqctl);
984 QCTL_COPY(oqctl, qctl);
985 rc = obd_quotactl(tgt->ltd_exp, oqctl);
987 QCTL_COPY(qctl, oqctl);
988 qctl->qc_valid = QC_MDTIDX;
989 qctl->obd_uuid = tgt->ltd_uuid;
994 case LL_IOC_GET_CONNECT_FLAGS: {
996 if (tgt == NULL || tgt->ltd_exp == NULL)
998 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1001 case LL_IOC_FID2MDTIDX: {
1002 struct lu_fid *fid = karg;
1005 rc = lmv_fld_lookup(lmv, fid, &mdt_index);
1009 /* Note: this is from llite(see ll_dir_ioctl()), @uarg does not
1010 * point to user space memory for FID2MDTIDX. */
1011 *(__u32 *)uarg = mdt_index;
1014 case OBD_IOC_FID2PATH: {
1015 rc = lmv_fid2path(exp, len, karg, uarg);
1018 case LL_IOC_HSM_STATE_GET:
1019 case LL_IOC_HSM_STATE_SET:
1020 case LL_IOC_HSM_ACTION: {
1021 struct md_op_data *op_data = karg;
1023 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1025 RETURN(PTR_ERR(tgt));
1027 if (tgt->ltd_exp == NULL)
1030 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1033 case LL_IOC_HSM_PROGRESS: {
1034 const struct hsm_progress_kernel *hpk = karg;
1036 tgt = lmv_find_target(lmv, &hpk->hpk_fid);
1038 RETURN(PTR_ERR(tgt));
1039 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1042 case LL_IOC_HSM_REQUEST: {
1043 struct hsm_user_request *hur = karg;
1044 unsigned int reqcount = hur->hur_request.hr_itemcount;
1049 /* if the request is about a single fid
1050 * or if there is a single MDS, no need to split
1052 if (reqcount == 1 || count == 1) {
1053 tgt = lmv_find_target(lmv,
1054 &hur->hur_user_item[0].hui_fid);
1056 RETURN(PTR_ERR(tgt));
1057 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1059 /* split fid list to their respective MDS */
1060 for (i = 0; i < count; i++) {
1063 struct hsm_user_request *req;
1066 if (tgt == NULL || tgt->ltd_exp == NULL)
1069 nr = lmv_hsm_req_count(lmv, hur, tgt);
1072 if (nr == 0) /* nothing for this MDS */
1075 /* build a request with fids for this MDS */
1076 reqlen = offsetof(typeof(*hur),
1078 + hur->hur_request.hr_data_len;
1079 OBD_ALLOC_LARGE(req, reqlen);
1082 rc1 = lmv_hsm_req_build(lmv, hur, tgt, req);
1084 GOTO(hsm_req_err, rc1);
1085 rc1 = obd_iocontrol(cmd, tgt->ltd_exp, reqlen,
1088 if (rc1 != 0 && rc == 0)
1090 OBD_FREE_LARGE(req, reqlen);
1095 case LL_IOC_LOV_SWAP_LAYOUTS: {
1096 struct md_op_data *op_data = karg;
1097 struct lmv_tgt_desc *tgt1, *tgt2;
1099 tgt1 = lmv_find_target(lmv, &op_data->op_fid1);
1101 RETURN(PTR_ERR(tgt1));
1103 tgt2 = lmv_find_target(lmv, &op_data->op_fid2);
1105 RETURN(PTR_ERR(tgt2));
1107 if ((tgt1->ltd_exp == NULL) || (tgt2->ltd_exp == NULL))
1110 /* only files on same MDT can have their layouts swapped */
1111 if (tgt1->ltd_idx != tgt2->ltd_idx)
1114 rc = obd_iocontrol(cmd, tgt1->ltd_exp, len, karg, uarg);
1117 case LL_IOC_HSM_CT_START: {
1118 struct lustre_kernelcomm *lk = karg;
1119 if (lk->lk_flags & LK_FLG_STOP)
1120 rc = lmv_hsm_ct_unregister(obddev, cmd, len, lk, uarg);
1122 rc = lmv_hsm_ct_register(obddev, cmd, len, lk, uarg);
1126 for (i = 0; i < count; i++) {
1127 struct obd_device *mdc_obd;
1131 if (tgt == NULL || tgt->ltd_exp == NULL)
1133 /* ll_umount_begin() sets force flag but for lmv, not
1134 * mdc. Let's pass it through */
1135 mdc_obd = class_exp2obd(tgt->ltd_exp);
1136 mdc_obd->obd_force = obddev->obd_force;
1137 err = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1139 if (tgt->ltd_active) {
1140 CERROR("error: iocontrol MDC %s on MDT"
1141 " idx %d cmd %x: err = %d\n",
1142 tgt->ltd_uuid.uuid, i, cmd, err);
1156 * This is _inode_ placement policy function (not name).
1158 static int lmv_placement_policy(struct obd_device *obd,
1159 struct md_op_data *op_data, u32 *mds)
1161 struct lmv_obd *lmv = &obd->u.lmv;
1162 struct lmv_user_md *lum;
1166 LASSERT(mds != NULL);
1168 if (lmv->desc.ld_tgt_count == 1) {
1173 lum = op_data->op_data;
1175 * 1. See if the stripe offset is specified by lum.
1176 * 2. Then check if there is default stripe offset.
1177 * 3. Finally choose MDS by name hash if the parent
1178 * is striped directory. (see lmv_locate_mds()). */
1179 if (op_data->op_cli_flags & CLI_SET_MEA && lum != NULL &&
1180 le32_to_cpu(lum->lum_stripe_offset) != (__u32)-1) {
1181 *mds = le32_to_cpu(lum->lum_stripe_offset);
1182 } else if (op_data->op_default_stripe_offset != (__u32)-1) {
1183 *mds = op_data->op_default_stripe_offset;
1184 op_data->op_mds = *mds;
1185 /* Correct the stripe offset in lum */
1187 lum->lum_stripe_offset = cpu_to_le32(*mds);
1189 *mds = op_data->op_mds;
1195 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid, u32 mds)
1197 struct lmv_tgt_desc *tgt;
1201 tgt = lmv_get_target(lmv, mds, NULL);
1203 RETURN(PTR_ERR(tgt));
1206 * New seq alloc and FLD setup should be atomic. Otherwise we may find
1207 * on server that seq in new allocated fid is not yet known.
1209 mutex_lock(&tgt->ltd_fid_mutex);
1211 if (tgt->ltd_active == 0 || tgt->ltd_exp == NULL)
1212 GOTO(out, rc = -ENODEV);
1215 * Asking underlying tgt layer to allocate new fid.
1217 rc = obd_fid_alloc(NULL, tgt->ltd_exp, fid, NULL);
1219 LASSERT(fid_is_sane(fid));
1225 mutex_unlock(&tgt->ltd_fid_mutex);
1229 int lmv_fid_alloc(const struct lu_env *env, struct obd_export *exp,
1230 struct lu_fid *fid, struct md_op_data *op_data)
1232 struct obd_device *obd = class_exp2obd(exp);
1233 struct lmv_obd *lmv = &obd->u.lmv;
1238 LASSERT(op_data != NULL);
1239 LASSERT(fid != NULL);
1241 rc = lmv_placement_policy(obd, op_data, &mds);
1243 CERROR("Can't get target for allocating fid, "
1248 rc = __lmv_fid_alloc(lmv, fid, mds);
1250 CERROR("Can't alloc new fid, rc %d\n", rc);
1257 static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
1259 struct lmv_obd *lmv = &obd->u.lmv;
1260 struct lmv_desc *desc;
1264 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
1265 CERROR("LMV setup requires a descriptor\n");
1269 desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1);
1270 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
1271 CERROR("Lmv descriptor size wrong: %d > %d\n",
1272 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
1276 lmv->tgts_size = 32U;
1277 OBD_ALLOC(lmv->tgts, sizeof(*lmv->tgts) * lmv->tgts_size);
1278 if (lmv->tgts == NULL)
1281 obd_str2uuid(&lmv->desc.ld_uuid, desc->ld_uuid.uuid);
1282 lmv->desc.ld_tgt_count = 0;
1283 lmv->desc.ld_active_tgt_count = 0;
1284 lmv->max_def_easize = 0;
1285 lmv->max_easize = 0;
1287 spin_lock_init(&lmv->lmv_lock);
1288 mutex_init(&lmv->lmv_init_mutex);
1290 #ifdef CONFIG_PROC_FS
1291 obd->obd_vars = lprocfs_lmv_obd_vars;
1292 lprocfs_obd_setup(obd, true);
1293 lprocfs_alloc_md_stats(obd, 0);
1294 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
1295 0444, &lmv_proc_target_fops, obd);
1297 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
1300 rc = fld_client_init(&lmv->lmv_fld, obd->obd_name,
1301 LUSTRE_CLI_FLD_HASH_DHT);
1303 CERROR("Can't init FLD, err %d\n", rc);
1313 static int lmv_cleanup(struct obd_device *obd)
1315 struct lmv_obd *lmv = &obd->u.lmv;
1318 fld_client_fini(&lmv->lmv_fld);
1319 if (lmv->tgts != NULL) {
1321 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1322 if (lmv->tgts[i] == NULL)
1324 lmv_del_target(lmv, i);
1326 OBD_FREE(lmv->tgts, sizeof(*lmv->tgts) * lmv->tgts_size);
1332 static int lmv_process_config(struct obd_device *obd, size_t len, void *buf)
1334 struct lustre_cfg *lcfg = buf;
1335 struct obd_uuid obd_uuid;
1341 switch (lcfg->lcfg_command) {
1343 /* modify_mdc_tgts add 0:lustre-clilmv 1:lustre-MDT0000_UUID
1344 * 2:0 3:1 4:lustre-MDT0000-mdc_UUID */
1345 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
1346 GOTO(out, rc = -EINVAL);
1348 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
1350 if (sscanf(lustre_cfg_buf(lcfg, 2), "%u", &index) != 1)
1351 GOTO(out, rc = -EINVAL);
1352 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
1353 GOTO(out, rc = -EINVAL);
1354 rc = lmv_add_target(obd, &obd_uuid, index, gen);
1357 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1358 GOTO(out, rc = -EINVAL);
1364 static int lmv_statfs(const struct lu_env *env, struct obd_export *exp,
1365 struct obd_statfs *osfs, time64_t max_age, __u32 flags)
1367 struct obd_device *obd = class_exp2obd(exp);
1368 struct lmv_obd *lmv = &obd->u.lmv;
1369 struct obd_statfs *temp;
1374 OBD_ALLOC(temp, sizeof(*temp));
1378 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1379 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1382 rc = obd_statfs(env, lmv->tgts[i]->ltd_exp, temp,
1385 CERROR("can't stat MDS #%d (%s), error %d\n", i,
1386 lmv->tgts[i]->ltd_exp->exp_obd->obd_name,
1388 GOTO(out_free_temp, rc);
1393 /* If the statfs is from mount, it will needs
1394 * retrieve necessary information from MDT0.
1395 * i.e. mount does not need the merged osfs
1397 * And also clients can be mounted as long as
1398 * MDT0 is in service*/
1399 if (flags & OBD_STATFS_FOR_MDT0)
1400 GOTO(out_free_temp, rc);
1402 osfs->os_bavail += temp->os_bavail;
1403 osfs->os_blocks += temp->os_blocks;
1404 osfs->os_ffree += temp->os_ffree;
1405 osfs->os_files += temp->os_files;
1411 OBD_FREE(temp, sizeof(*temp));
1415 static int lmv_get_root(struct obd_export *exp, const char *fileset,
1418 struct obd_device *obd = exp->exp_obd;
1419 struct lmv_obd *lmv = &obd->u.lmv;
1423 rc = md_get_root(lmv->tgts[0]->ltd_exp, fileset, fid);
1427 static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1428 u64 obd_md_valid, const char *name, size_t buf_size,
1429 struct ptlrpc_request **req)
1431 struct obd_device *obd = exp->exp_obd;
1432 struct lmv_obd *lmv = &obd->u.lmv;
1433 struct lmv_tgt_desc *tgt;
1437 tgt = lmv_find_target(lmv, fid);
1439 RETURN(PTR_ERR(tgt));
1441 rc = md_getxattr(tgt->ltd_exp, fid, obd_md_valid, name, buf_size, req);
1446 static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1447 u64 obd_md_valid, const char *name,
1448 const void *value, size_t value_size,
1449 unsigned int xattr_flags, u32 suppgid,
1450 struct ptlrpc_request **req)
1452 struct obd_device *obd = exp->exp_obd;
1453 struct lmv_obd *lmv = &obd->u.lmv;
1454 struct lmv_tgt_desc *tgt;
1458 tgt = lmv_find_target(lmv, fid);
1460 RETURN(PTR_ERR(tgt));
1462 rc = md_setxattr(tgt->ltd_exp, fid, obd_md_valid, name,
1463 value, value_size, xattr_flags, suppgid, req);
1468 static int lmv_getattr(struct obd_export *exp, struct md_op_data *op_data,
1469 struct ptlrpc_request **request)
1471 struct obd_device *obd = exp->exp_obd;
1472 struct lmv_obd *lmv = &obd->u.lmv;
1473 struct lmv_tgt_desc *tgt;
1477 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1479 RETURN(PTR_ERR(tgt));
1481 if (op_data->op_flags & MF_GET_MDT_IDX) {
1482 op_data->op_mds = tgt->ltd_idx;
1486 rc = md_getattr(tgt->ltd_exp, op_data, request);
1491 static int lmv_null_inode(struct obd_export *exp, const struct lu_fid *fid)
1493 struct obd_device *obd = exp->exp_obd;
1494 struct lmv_obd *lmv = &obd->u.lmv;
1498 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1501 * With DNE every object can have two locks in different namespaces:
1502 * lookup lock in space of MDT storing direntry and update/open lock in
1503 * space of MDT storing inode.
1505 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1506 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1508 md_null_inode(lmv->tgts[i]->ltd_exp, fid);
1514 static int lmv_close(struct obd_export *exp, struct md_op_data *op_data,
1515 struct md_open_data *mod, struct ptlrpc_request **request)
1517 struct obd_device *obd = exp->exp_obd;
1518 struct lmv_obd *lmv = &obd->u.lmv;
1519 struct lmv_tgt_desc *tgt;
1523 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1525 RETURN(PTR_ERR(tgt));
1527 CDEBUG(D_INODE, "CLOSE "DFID"\n", PFID(&op_data->op_fid1));
1528 rc = md_close(tgt->ltd_exp, op_data, mod, request);
1533 * Choosing the MDT by name or FID in @op_data.
1534 * For non-striped directory, it will locate MDT by fid.
1535 * For striped-directory, it will locate MDT by name. And also
1536 * it will reset op_fid1 with the FID of the choosen stripe.
1538 struct lmv_tgt_desc *
1539 lmv_locate_target_for_name(struct lmv_obd *lmv, struct lmv_stripe_md *lsm,
1540 const char *name, int namelen, struct lu_fid *fid,
1543 struct lmv_tgt_desc *tgt;
1544 const struct lmv_oinfo *oinfo;
1546 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_NAME_HASH)) {
1547 if (cfs_fail_val >= lsm->lsm_md_stripe_count)
1548 RETURN(ERR_PTR(-EBADF));
1549 oinfo = &lsm->lsm_md_oinfo[cfs_fail_val];
1551 oinfo = lsm_name_to_stripe_info(lsm, name, namelen);
1553 RETURN(ERR_CAST(oinfo));
1557 *fid = oinfo->lmo_fid;
1559 *mds = oinfo->lmo_mds;
1561 tgt = lmv_get_target(lmv, oinfo->lmo_mds, NULL);
1563 CDEBUG(D_INFO, "locate on mds %u "DFID"\n", oinfo->lmo_mds,
1564 PFID(&oinfo->lmo_fid));
1569 * Locate mds by fid or name
1571 * For striped directory (lsm != NULL), it will locate the stripe
1572 * by name hash (see lsm_name_to_stripe_info()). Note: if the hash_type
1573 * is unknown, it will return -EBADFD, and lmv_intent_lookup might need
1574 * walk through all of stripes to locate the entry.
1576 * For normal direcotry, it will locate MDS by FID directly.
1577 * \param[in] lmv LMV device
1578 * \param[in] op_data client MD stack parameters, name, namelen
1580 * \param[in] fid object FID used to locate MDS.
1582 * retval pointer to the lmv_tgt_desc if succeed.
1583 * ERR_PTR(errno) if failed.
1585 struct lmv_tgt_desc*
1586 lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1589 struct lmv_stripe_md *lsm = op_data->op_mea1;
1590 struct lmv_tgt_desc *tgt;
1592 /* During creating VOLATILE file, it should honor the mdt
1593 * index if the file under striped dir is being restored, see
1595 if (op_data->op_bias & MDS_CREATE_VOLATILE &&
1596 (int)op_data->op_mds != -1) {
1598 tgt = lmv_get_target(lmv, op_data->op_mds, NULL);
1603 /* refill the right parent fid */
1604 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1605 struct lmv_oinfo *oinfo;
1607 oinfo = &lsm->lsm_md_oinfo[i];
1608 if (oinfo->lmo_mds == op_data->op_mds) {
1609 *fid = oinfo->lmo_fid;
1614 if (i == lsm->lsm_md_stripe_count)
1615 *fid = lsm->lsm_md_oinfo[0].lmo_fid;
1621 if (lsm == NULL || op_data->op_namelen == 0) {
1622 tgt = lmv_find_target(lmv, fid);
1626 op_data->op_mds = tgt->ltd_idx;
1630 return lmv_locate_target_for_name(lmv, lsm, op_data->op_name,
1631 op_data->op_namelen, fid,
1635 int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
1636 const void *data, size_t datalen, umode_t mode, uid_t uid,
1637 gid_t gid, cfs_cap_t cap_effective, __u64 rdev,
1638 struct ptlrpc_request **request)
1640 struct obd_device *obd = exp->exp_obd;
1641 struct lmv_obd *lmv = &obd->u.lmv;
1642 struct lmv_tgt_desc *tgt;
1646 if (!lmv->desc.ld_active_tgt_count)
1649 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1651 RETURN(PTR_ERR(tgt));
1653 CDEBUG(D_INODE, "CREATE name '%.*s' on "DFID" -> mds #%x\n",
1654 (int)op_data->op_namelen, op_data->op_name,
1655 PFID(&op_data->op_fid1), op_data->op_mds);
1657 rc = lmv_fid_alloc(NULL, exp, &op_data->op_fid2, op_data);
1660 if (exp_connect_flags(exp) & OBD_CONNECT_DIR_STRIPE) {
1661 /* Send the create request to the MDT where the object
1662 * will be located */
1663 tgt = lmv_find_target(lmv, &op_data->op_fid2);
1665 RETURN(PTR_ERR(tgt));
1667 op_data->op_mds = tgt->ltd_idx;
1669 CDEBUG(D_CONFIG, "Server doesn't support striped dirs\n");
1672 CDEBUG(D_INODE, "CREATE obj "DFID" -> mds #%x\n",
1673 PFID(&op_data->op_fid2), op_data->op_mds);
1675 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1676 rc = md_create(tgt->ltd_exp, op_data, data, datalen, mode, uid, gid,
1677 cap_effective, rdev, request);
1679 if (*request == NULL)
1681 CDEBUG(D_INODE, "Created - "DFID"\n", PFID(&op_data->op_fid2));
1687 lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1688 const union ldlm_policy_data *policy, struct md_op_data *op_data,
1689 struct lustre_handle *lockh, __u64 extra_lock_flags)
1691 struct obd_device *obd = exp->exp_obd;
1692 struct lmv_obd *lmv = &obd->u.lmv;
1693 struct lmv_tgt_desc *tgt;
1697 CDEBUG(D_INODE, "ENQUEUE on "DFID"\n", PFID(&op_data->op_fid1));
1699 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1701 RETURN(PTR_ERR(tgt));
1703 CDEBUG(D_INODE, "ENQUEUE on "DFID" -> mds #%u\n",
1704 PFID(&op_data->op_fid1), tgt->ltd_idx);
1706 rc = md_enqueue(tgt->ltd_exp, einfo, policy, op_data, lockh,
1713 lmv_getattr_name(struct obd_export *exp,struct md_op_data *op_data,
1714 struct ptlrpc_request **preq)
1716 struct ptlrpc_request *req = NULL;
1717 struct obd_device *obd = exp->exp_obd;
1718 struct lmv_obd *lmv = &obd->u.lmv;
1719 struct lmv_tgt_desc *tgt;
1720 struct mdt_body *body;
1724 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1726 RETURN(PTR_ERR(tgt));
1728 CDEBUG(D_INODE, "GETATTR_NAME for %*s on "DFID" -> mds #%d\n",
1729 (int)op_data->op_namelen, op_data->op_name,
1730 PFID(&op_data->op_fid1), tgt->ltd_idx);
1732 rc = md_getattr_name(tgt->ltd_exp, op_data, preq);
1736 body = req_capsule_server_get(&(*preq)->rq_pill, &RMF_MDT_BODY);
1737 LASSERT(body != NULL);
1739 if (body->mbo_valid & OBD_MD_MDS) {
1740 struct lu_fid rid = body->mbo_fid1;
1741 CDEBUG(D_INODE, "Request attrs for "DFID"\n",
1744 tgt = lmv_find_target(lmv, &rid);
1746 ptlrpc_req_finished(*preq);
1748 RETURN(PTR_ERR(tgt));
1751 op_data->op_fid1 = rid;
1752 op_data->op_valid |= OBD_MD_FLCROSSREF;
1753 op_data->op_namelen = 0;
1754 op_data->op_name = NULL;
1755 rc = md_getattr_name(tgt->ltd_exp, op_data, &req);
1756 ptlrpc_req_finished(*preq);
1763 #define md_op_data_fid(op_data, fl) \
1764 (fl == MF_MDC_CANCEL_FID1 ? &op_data->op_fid1 : \
1765 fl == MF_MDC_CANCEL_FID2 ? &op_data->op_fid2 : \
1766 fl == MF_MDC_CANCEL_FID3 ? &op_data->op_fid3 : \
1767 fl == MF_MDC_CANCEL_FID4 ? &op_data->op_fid4 : \
1770 static int lmv_early_cancel(struct obd_export *exp, struct lmv_tgt_desc *tgt,
1771 struct md_op_data *op_data, __u32 op_tgt,
1772 enum ldlm_mode mode, int bits, int flag)
1774 struct lu_fid *fid = md_op_data_fid(op_data, flag);
1775 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
1776 union ldlm_policy_data policy = { { 0 } };
1780 if (!fid_is_sane(fid))
1784 tgt = lmv_find_target(lmv, fid);
1786 RETURN(PTR_ERR(tgt));
1789 if (tgt->ltd_idx != op_tgt) {
1790 CDEBUG(D_INODE, "EARLY_CANCEL on "DFID"\n", PFID(fid));
1791 policy.l_inodebits.bits = bits;
1792 rc = md_cancel_unused(tgt->ltd_exp, fid, &policy,
1793 mode, LCF_ASYNC, NULL);
1796 "EARLY_CANCEL skip operation target %d on "DFID"\n",
1798 op_data->op_flags |= flag;
1806 * llite passes fid of an target inode in op_data->op_fid1 and id of directory in
1809 static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
1810 struct ptlrpc_request **request)
1812 struct obd_device *obd = exp->exp_obd;
1813 struct lmv_obd *lmv = &obd->u.lmv;
1814 struct lmv_tgt_desc *tgt;
1818 LASSERT(op_data->op_namelen != 0);
1820 CDEBUG(D_INODE, "LINK "DFID":%*s to "DFID"\n",
1821 PFID(&op_data->op_fid2), (int)op_data->op_namelen,
1822 op_data->op_name, PFID(&op_data->op_fid1));
1824 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
1825 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
1826 op_data->op_cap = cfs_curproc_cap_pack();
1827 if (op_data->op_mea2 != NULL) {
1828 struct lmv_stripe_md *lsm = op_data->op_mea2;
1829 const struct lmv_oinfo *oinfo;
1831 oinfo = lsm_name_to_stripe_info(lsm, op_data->op_name,
1832 op_data->op_namelen);
1834 RETURN(PTR_ERR(oinfo));
1836 op_data->op_fid2 = oinfo->lmo_fid;
1839 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
1841 RETURN(PTR_ERR(tgt));
1844 * Cancel UPDATE lock on child (fid1).
1846 op_data->op_flags |= MF_MDC_CANCEL_FID2;
1847 rc = lmv_early_cancel(exp, NULL, op_data, tgt->ltd_idx, LCK_EX,
1848 MDS_INODELOCK_UPDATE, MF_MDC_CANCEL_FID1);
1852 rc = md_link(tgt->ltd_exp, op_data, request);
1857 static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
1858 const char *old, size_t oldlen,
1859 const char *new, size_t newlen,
1860 struct ptlrpc_request **request)
1862 struct obd_device *obd = exp->exp_obd;
1863 struct lmv_obd *lmv = &obd->u.lmv;
1864 struct lmv_tgt_desc *src_tgt;
1865 struct lmv_tgt_desc *tgt_tgt;
1866 struct obd_export *target_exp;
1867 struct mdt_body *body;
1871 LASSERT(oldlen != 0);
1873 CDEBUG(D_INODE, "RENAME %.*s in "DFID":%d to %.*s in "DFID":%d\n",
1874 (int)oldlen, old, PFID(&op_data->op_fid1),
1875 op_data->op_mea1 ? op_data->op_mea1->lsm_md_stripe_count : 0,
1876 (int)newlen, new, PFID(&op_data->op_fid2),
1877 op_data->op_mea2 ? op_data->op_mea2->lsm_md_stripe_count : 0);
1879 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
1880 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
1881 op_data->op_cap = cfs_curproc_cap_pack();
1882 if (op_data->op_cli_flags & CLI_MIGRATE) {
1883 LASSERTF(fid_is_sane(&op_data->op_fid3), "invalid FID "DFID"\n",
1884 PFID(&op_data->op_fid3));
1886 if (op_data->op_mea1 != NULL) {
1887 struct lmv_stripe_md *lsm = op_data->op_mea1;
1888 struct lmv_tgt_desc *tmp;
1890 /* Fix the parent fid for striped dir */
1891 tmp = lmv_locate_target_for_name(lmv, lsm, old,
1896 RETURN(PTR_ERR(tmp));
1899 rc = lmv_fid_alloc(NULL, exp, &op_data->op_fid2, op_data);
1903 src_tgt = lmv_find_target(lmv, &op_data->op_fid3);
1904 if (IS_ERR(src_tgt))
1905 RETURN(PTR_ERR(src_tgt));
1907 target_exp = src_tgt->ltd_exp;
1909 if (op_data->op_mea1 != NULL) {
1910 struct lmv_stripe_md *lsm = op_data->op_mea1;
1912 src_tgt = lmv_locate_target_for_name(lmv, lsm, old,
1917 src_tgt = lmv_find_target(lmv, &op_data->op_fid1);
1919 if (IS_ERR(src_tgt))
1920 RETURN(PTR_ERR(src_tgt));
1923 if (op_data->op_mea2 != NULL) {
1924 struct lmv_stripe_md *lsm = op_data->op_mea2;
1926 tgt_tgt = lmv_locate_target_for_name(lmv, lsm, new,
1931 tgt_tgt = lmv_find_target(lmv, &op_data->op_fid2);
1934 if (IS_ERR(tgt_tgt))
1935 RETURN(PTR_ERR(tgt_tgt));
1937 target_exp = tgt_tgt->ltd_exp;
1941 * LOOKUP lock on src child (fid3) should also be cancelled for
1942 * src_tgt in mdc_rename.
1944 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
1947 * Cancel UPDATE locks on tgt parent (fid2), tgt_tgt is its
1950 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
1951 LCK_EX, MDS_INODELOCK_UPDATE,
1952 MF_MDC_CANCEL_FID2);
1957 * Cancel LOOKUP locks on source child (fid3) for parent tgt_tgt.
1959 if (fid_is_sane(&op_data->op_fid3)) {
1960 struct lmv_tgt_desc *tgt;
1962 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1964 RETURN(PTR_ERR(tgt));
1966 /* Cancel LOOKUP lock on its parent */
1967 rc = lmv_early_cancel(exp, tgt, op_data, src_tgt->ltd_idx,
1968 LCK_EX, MDS_INODELOCK_LOOKUP,
1969 MF_MDC_CANCEL_FID3);
1973 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
1974 LCK_EX, MDS_INODELOCK_ELC,
1975 MF_MDC_CANCEL_FID3);
1982 * Cancel all the locks on tgt child (fid4).
1984 if (fid_is_sane(&op_data->op_fid4)) {
1985 struct lmv_tgt_desc *tgt;
1987 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
1988 LCK_EX, MDS_INODELOCK_ELC,
1989 MF_MDC_CANCEL_FID4);
1993 tgt = lmv_find_target(lmv, &op_data->op_fid4);
1995 RETURN(PTR_ERR(tgt));
1997 /* Since the target child might be destroyed, and it might
1998 * become orphan, and we can only check orphan on the local
1999 * MDT right now, so we send rename request to the MDT where
2000 * target child is located. If target child does not exist,
2001 * then it will send the request to the target parent */
2002 target_exp = tgt->ltd_exp;
2005 rc = md_rename(target_exp, op_data, old, oldlen, new, newlen,
2008 if (rc != 0 && rc != -EXDEV)
2011 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
2015 /* Not cross-ref case, just get out of here. */
2016 if (likely(!(body->mbo_valid & OBD_MD_MDS)))
2019 CDEBUG(D_INODE, "%s: try rename to another MDT for "DFID"\n",
2020 exp->exp_obd->obd_name, PFID(&body->mbo_fid1));
2022 op_data->op_fid4 = body->mbo_fid1;
2023 ptlrpc_req_finished(*request);
2028 static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
2029 void *ea, size_t ealen, struct ptlrpc_request **request)
2031 struct obd_device *obd = exp->exp_obd;
2032 struct lmv_obd *lmv = &obd->u.lmv;
2033 struct lmv_tgt_desc *tgt;
2037 CDEBUG(D_INODE, "SETATTR for "DFID", valid 0x%x\n",
2038 PFID(&op_data->op_fid1), op_data->op_attr.ia_valid);
2040 op_data->op_flags |= MF_MDC_CANCEL_FID1;
2041 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2043 RETURN(PTR_ERR(tgt));
2045 rc = md_setattr(tgt->ltd_exp, op_data, ea, ealen, request);
2050 static int lmv_fsync(struct obd_export *exp, const struct lu_fid *fid,
2051 struct ptlrpc_request **request)
2053 struct obd_device *obd = exp->exp_obd;
2054 struct lmv_obd *lmv = &obd->u.lmv;
2055 struct lmv_tgt_desc *tgt;
2059 tgt = lmv_find_target(lmv, fid);
2061 RETURN(PTR_ERR(tgt));
2063 rc = md_fsync(tgt->ltd_exp, fid, request);
2067 struct stripe_dirent {
2068 struct page *sd_page;
2069 struct lu_dirpage *sd_dp;
2070 struct lu_dirent *sd_ent;
2074 struct lmv_dir_ctxt {
2075 struct lmv_obd *ldc_lmv;
2076 struct md_op_data *ldc_op_data;
2077 struct md_callback *ldc_cb_op;
2080 struct stripe_dirent ldc_stripes[0];
2083 static inline void put_stripe_dirent(struct stripe_dirent *stripe)
2085 if (stripe->sd_page) {
2086 kunmap(stripe->sd_page);
2087 put_page(stripe->sd_page);
2088 stripe->sd_page = NULL;
2089 stripe->sd_ent = NULL;
2093 static inline void put_lmv_dir_ctxt(struct lmv_dir_ctxt *ctxt)
2097 for (i = 0; i < ctxt->ldc_count; i++)
2098 put_stripe_dirent(&ctxt->ldc_stripes[i]);
2101 static struct lu_dirent *stripe_dirent_next(struct lmv_dir_ctxt *ctxt,
2102 struct stripe_dirent *stripe,
2105 struct lu_dirent *ent = stripe->sd_ent;
2106 __u64 hash = ctxt->ldc_hash;
2111 LASSERT(stripe == &ctxt->ldc_stripes[stripe_index]);
2117 ent = lu_dirent_next(ent);
2120 end = le64_to_cpu(stripe->sd_dp->ldp_hash_end);
2121 LASSERTF(hash <= end, "hash %llx end %llx\n",
2123 if (end == MDS_DIR_END_OFF) {
2124 stripe->sd_ent = NULL;
2125 stripe->sd_eof = true;
2129 put_stripe_dirent(stripe);
2135 struct md_op_data *op_data = ctxt->ldc_op_data;
2136 struct lmv_oinfo *oinfo;
2137 struct lu_fid fid = op_data->op_fid1;
2138 struct inode *inode = op_data->op_data;
2139 struct lmv_tgt_desc *tgt;
2141 LASSERT(!stripe->sd_page);
2143 oinfo = &op_data->op_mea1->lsm_md_oinfo[stripe_index];
2144 tgt = lmv_get_target(ctxt->ldc_lmv, oinfo->lmo_mds, NULL);
2146 GOTO(out, rc = PTR_ERR(tgt));
2148 /* op_data will be shared by each stripe, so we need
2149 * reset these value for each stripe */
2150 op_data->op_fid1 = oinfo->lmo_fid;
2151 op_data->op_fid2 = oinfo->lmo_fid;
2152 op_data->op_data = oinfo->lmo_root;
2154 rc = md_read_page(tgt->ltd_exp, op_data, ctxt->ldc_cb_op, hash,
2157 op_data->op_fid1 = fid;
2158 op_data->op_fid2 = fid;
2159 op_data->op_data = inode;
2164 stripe->sd_dp = page_address(stripe->sd_page);
2165 ent = lu_dirent_start(stripe->sd_dp);
2168 for (; ent; ent = lu_dirent_next(ent)) {
2169 /* Skip dummy entry */
2170 if (le16_to_cpu(ent->lde_namelen) == 0)
2173 /* skip . and .. for other stripes */
2175 (strncmp(ent->lde_name, ".",
2176 le16_to_cpu(ent->lde_namelen)) == 0 ||
2177 strncmp(ent->lde_name, "..",
2178 le16_to_cpu(ent->lde_namelen)) == 0))
2181 if (le64_to_cpu(ent->lde_hash) >= hash)
2190 stripe->sd_ent = ent;
2191 /* treat error as eof, so dir can be partially accessed */
2193 put_stripe_dirent(stripe);
2194 stripe->sd_eof = true;
2195 LCONSOLE_WARN("dir "DFID" stripe %d readdir failed: %d, "
2196 "directory is partially accessed!\n",
2197 PFID(&ctxt->ldc_op_data->op_fid1), stripe_index,
2203 static int lmv_file_resync(struct obd_export *exp, struct md_op_data *data)
2205 struct obd_device *obd = exp->exp_obd;
2206 struct lmv_obd *lmv = &obd->u.lmv;
2207 struct lmv_tgt_desc *tgt;
2211 rc = lmv_check_connect(obd);
2215 tgt = lmv_find_target(lmv, &data->op_fid1);
2217 RETURN(PTR_ERR(tgt));
2219 data->op_flags |= MF_MDC_CANCEL_FID1;
2220 rc = md_file_resync(tgt->ltd_exp, data);
2225 * Get dirent with the closest hash for striped directory
2227 * This function will search the dir entry, whose hash value is the
2228 * closest(>=) to hash from all of sub-stripes, and it is only being called
2229 * for striped directory.
2231 * \param[in] ctxt dir read context
2233 * \retval dirent get the entry successfully
2234 * NULL does not get the entry, normally it means
2235 * it reaches the end of the directory, while read
2236 * stripe dirent error is ignored to allow partial
2239 static struct lu_dirent *lmv_dirent_next(struct lmv_dir_ctxt *ctxt)
2241 struct stripe_dirent *stripe;
2242 struct lu_dirent *ent = NULL;
2246 /* TODO: optimize with k-way merge sort */
2247 for (i = 0; i < ctxt->ldc_count; i++) {
2248 stripe = &ctxt->ldc_stripes[i];
2252 if (!stripe->sd_ent) {
2253 /* locate starting entry */
2254 stripe_dirent_next(ctxt, stripe, i);
2255 if (!stripe->sd_ent) {
2256 LASSERT(stripe->sd_eof);
2262 le64_to_cpu(ctxt->ldc_stripes[min].sd_ent->lde_hash) >
2263 le64_to_cpu(stripe->sd_ent->lde_hash)) {
2265 if (le64_to_cpu(stripe->sd_ent->lde_hash) ==
2272 stripe = &ctxt->ldc_stripes[min];
2273 ent = stripe->sd_ent;
2274 /* pop found dirent */
2275 stripe_dirent_next(ctxt, stripe, min);
2282 * Build dir entry page for striped directory
2284 * This function gets one entry by @offset from a striped directory. It will
2285 * read entries from all of stripes, and choose one closest to the required
2286 * offset(&offset). A few notes
2287 * 1. skip . and .. for non-zero stripes, because there can only have one .
2288 * and .. in a directory.
2289 * 2. op_data will be shared by all of stripes, instead of allocating new
2290 * one, so need to restore before reusing.
2292 * \param[in] exp obd export refer to LMV
2293 * \param[in] op_data hold those MD parameters of read_entry
2294 * \param[in] cb_op ldlm callback being used in enqueue in mdc_read_entry
2295 * \param[in] offset starting hash offset
2296 * \param[out] ppage the page holding the entry. Note: because the entry
2297 * will be accessed in upper layer, so we need hold the
2298 * page until the usages of entry is finished, see
2299 * ll_dir_entry_next.
2301 * retval =0 if get entry successfully
2302 * <0 cannot get entry
2304 static int lmv_striped_read_page(struct obd_export *exp,
2305 struct md_op_data *op_data,
2306 struct md_callback *cb_op,
2307 __u64 offset, struct page **ppage)
2309 struct page *page = NULL;
2310 struct lu_dirpage *dp;
2312 struct lu_dirent *ent;
2313 struct lu_dirent *last_ent;
2315 struct lmv_dir_ctxt *ctxt;
2316 struct lu_dirent *next = NULL;
2322 /* Allocate a page and read entries from all of stripes and fill
2323 * the page by hash order */
2324 page = alloc_page(GFP_KERNEL);
2328 /* Initialize the entry page */
2330 memset(dp, 0, sizeof(*dp));
2331 dp->ldp_hash_start = cpu_to_le64(offset);
2334 left_bytes = PAGE_SIZE - sizeof(*dp);
2338 /* initalize dir read context */
2339 stripe_count = op_data->op_mea1->lsm_md_stripe_count;
2340 OBD_ALLOC(ctxt, offsetof(typeof(*ctxt), ldc_stripes[stripe_count]));
2342 GOTO(free_page, rc = -ENOMEM);
2343 ctxt->ldc_lmv = &exp->exp_obd->u.lmv;
2344 ctxt->ldc_op_data = op_data;
2345 ctxt->ldc_cb_op = cb_op;
2346 ctxt->ldc_hash = offset;
2347 ctxt->ldc_count = stripe_count;
2350 next = lmv_dirent_next(ctxt);
2352 /* end of directory */
2354 ctxt->ldc_hash = MDS_DIR_END_OFF;
2357 ctxt->ldc_hash = le64_to_cpu(next->lde_hash);
2359 ent_size = le16_to_cpu(next->lde_reclen);
2361 /* the last entry lde_reclen is 0, but it might not be the last
2362 * one of this temporay dir page */
2364 ent_size = lu_dirent_calc_size(
2365 le16_to_cpu(next->lde_namelen),
2366 le32_to_cpu(next->lde_attrs));
2368 if (ent_size > left_bytes)
2371 memcpy(ent, next, ent_size);
2373 /* Replace . with master FID and Replace .. with the parent FID
2374 * of master object */
2375 if (strncmp(ent->lde_name, ".",
2376 le16_to_cpu(ent->lde_namelen)) == 0 &&
2377 le16_to_cpu(ent->lde_namelen) == 1)
2378 fid_cpu_to_le(&ent->lde_fid, &op_data->op_fid1);
2379 else if (strncmp(ent->lde_name, "..",
2380 le16_to_cpu(ent->lde_namelen)) == 0 &&
2381 le16_to_cpu(ent->lde_namelen) == 2)
2382 fid_cpu_to_le(&ent->lde_fid, &op_data->op_fid3);
2384 CDEBUG(D_INODE, "entry %.*s hash %#llx\n",
2385 le16_to_cpu(ent->lde_namelen), ent->lde_name,
2386 le64_to_cpu(ent->lde_hash));
2388 left_bytes -= ent_size;
2389 ent->lde_reclen = cpu_to_le16(ent_size);
2391 ent = (void *)ent + ent_size;
2394 last_ent->lde_reclen = 0;
2397 dp->ldp_flags |= LDF_EMPTY;
2398 else if (ctxt->ldc_hash == le64_to_cpu(last_ent->lde_hash))
2399 dp->ldp_flags |= LDF_COLLIDE;
2400 dp->ldp_flags = cpu_to_le32(dp->ldp_flags);
2401 dp->ldp_hash_end = cpu_to_le64(ctxt->ldc_hash);
2403 put_lmv_dir_ctxt(ctxt);
2404 OBD_FREE(ctxt, offsetof(typeof(*ctxt), ldc_stripes[stripe_count]));
2417 int lmv_read_page(struct obd_export *exp, struct md_op_data *op_data,
2418 struct md_callback *cb_op, __u64 offset,
2419 struct page **ppage)
2421 struct obd_device *obd = exp->exp_obd;
2422 struct lmv_obd *lmv = &obd->u.lmv;
2423 struct lmv_stripe_md *lsm = op_data->op_mea1;
2424 struct lmv_tgt_desc *tgt;
2428 if (unlikely(lsm != NULL)) {
2429 rc = lmv_striped_read_page(exp, op_data, cb_op, offset, ppage);
2433 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2435 RETURN(PTR_ERR(tgt));
2437 rc = md_read_page(tgt->ltd_exp, op_data, cb_op, offset, ppage);
2443 * Unlink a file/directory
2445 * Unlink a file or directory under the parent dir. The unlink request
2446 * usually will be sent to the MDT where the child is located, but if
2447 * the client does not have the child FID then request will be sent to the
2448 * MDT where the parent is located.
2450 * If the parent is a striped directory then it also needs to locate which
2451 * stripe the name of the child is located, and replace the parent FID
2452 * (@op->op_fid1) with the stripe FID. Note: if the stripe is unknown,
2453 * it will walk through all of sub-stripes until the child is being
2456 * \param[in] exp export refer to LMV
2457 * \param[in] op_data different parameters transferred beween client
2458 * MD stacks, name, namelen, FIDs etc.
2459 * op_fid1 is the parent FID, op_fid2 is the child
2461 * \param[out] request point to the request of unlink.
2463 * retval 0 if succeed
2464 * negative errno if failed.
2466 static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
2467 struct ptlrpc_request **request)
2469 struct obd_device *obd = exp->exp_obd;
2470 struct lmv_obd *lmv = &obd->u.lmv;
2471 struct lmv_tgt_desc *tgt = NULL;
2472 struct lmv_tgt_desc *parent_tgt = NULL;
2473 struct mdt_body *body;
2475 int stripe_index = 0;
2476 struct lmv_stripe_md *lsm = op_data->op_mea1;
2480 /* For striped dir, we need to locate the parent as well */
2482 struct lmv_tgt_desc *tmp;
2484 LASSERT(op_data->op_name != NULL &&
2485 op_data->op_namelen != 0);
2487 tmp = lmv_locate_target_for_name(lmv, lsm,
2489 op_data->op_namelen,
2493 /* return -EBADFD means unknown hash type, might
2494 * need try all sub-stripe here */
2495 if (IS_ERR(tmp) && PTR_ERR(tmp) != -EBADFD)
2496 RETURN(PTR_ERR(tmp));
2498 /* Note: both migrating dir and unknown hash dir need to
2499 * try all of sub-stripes, so we need start search the
2500 * name from stripe 0, but migrating dir is already handled
2501 * inside lmv_locate_target_for_name(), so we only check
2502 * unknown hash type directory here */
2503 if (!lmv_is_known_hash_type(lsm->lsm_md_hash_type)) {
2504 struct lmv_oinfo *oinfo;
2506 oinfo = &lsm->lsm_md_oinfo[stripe_index];
2508 op_data->op_fid1 = oinfo->lmo_fid;
2509 op_data->op_mds = oinfo->lmo_mds;
2514 /* Send unlink requests to the MDT where the child is located */
2515 if (likely(!fid_is_zero(&op_data->op_fid2)))
2516 tgt = lmv_find_target(lmv, &op_data->op_fid2);
2517 else if (lsm != NULL)
2518 tgt = lmv_get_target(lmv, op_data->op_mds, NULL);
2520 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
2523 RETURN(PTR_ERR(tgt));
2525 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
2526 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
2527 op_data->op_cap = cfs_curproc_cap_pack();
2530 * If child's fid is given, cancel unused locks for it if it is from
2531 * another export than parent.
2533 * LOOKUP lock for child (fid3) should also be cancelled on parent
2534 * tgt_tgt in mdc_unlink().
2536 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2539 * Cancel FULL locks on child (fid3).
2541 parent_tgt = lmv_find_target(lmv, &op_data->op_fid1);
2542 if (IS_ERR(parent_tgt))
2543 RETURN(PTR_ERR(parent_tgt));
2545 if (parent_tgt != tgt) {
2546 rc = lmv_early_cancel(exp, parent_tgt, op_data, tgt->ltd_idx,
2547 LCK_EX, MDS_INODELOCK_LOOKUP,
2548 MF_MDC_CANCEL_FID3);
2551 rc = lmv_early_cancel(exp, NULL, op_data, tgt->ltd_idx, LCK_EX,
2552 MDS_INODELOCK_ELC, MF_MDC_CANCEL_FID3);
2556 CDEBUG(D_INODE, "unlink with fid="DFID"/"DFID" -> mds #%u\n",
2557 PFID(&op_data->op_fid1), PFID(&op_data->op_fid2), tgt->ltd_idx);
2559 rc = md_unlink(tgt->ltd_exp, op_data, request);
2560 if (rc != 0 && rc != -EREMOTE && rc != -ENOENT)
2563 /* Try next stripe if it is needed. */
2564 if (rc == -ENOENT && lsm != NULL && lmv_need_try_all_stripes(lsm)) {
2565 struct lmv_oinfo *oinfo;
2568 if (stripe_index >= lsm->lsm_md_stripe_count)
2571 oinfo = &lsm->lsm_md_oinfo[stripe_index];
2573 op_data->op_fid1 = oinfo->lmo_fid;
2574 op_data->op_mds = oinfo->lmo_mds;
2576 ptlrpc_req_finished(*request);
2579 goto try_next_stripe;
2582 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
2586 /* Not cross-ref case, just get out of here. */
2587 if (likely(!(body->mbo_valid & OBD_MD_MDS)))
2590 CDEBUG(D_INODE, "%s: try unlink to another MDT for "DFID"\n",
2591 exp->exp_obd->obd_name, PFID(&body->mbo_fid1));
2593 /* This is a remote object, try remote MDT, Note: it may
2594 * try more than 1 time here, Considering following case
2595 * /mnt/lustre is root on MDT0, remote1 is on MDT1
2596 * 1. Initially A does not know where remote1 is, it send
2597 * unlink RPC to MDT0, MDT0 return -EREMOTE, it will
2598 * resend unlink RPC to MDT1 (retry 1st time).
2600 * 2. During the unlink RPC in flight,
2601 * client B mv /mnt/lustre/remote1 /mnt/lustre/remote2
2602 * and create new remote1, but on MDT0
2604 * 3. MDT1 get unlink RPC(from A), then do remote lock on
2605 * /mnt/lustre, then lookup get fid of remote1, and find
2606 * it is remote dir again, and replay -EREMOTE again.
2608 * 4. Then A will resend unlink RPC to MDT0. (retry 2nd times).
2610 * In theory, it might try unlimited time here, but it should
2611 * be very rare case. */
2612 op_data->op_fid2 = body->mbo_fid1;
2613 ptlrpc_req_finished(*request);
2619 static int lmv_precleanup(struct obd_device *obd)
2622 libcfs_kkuc_group_rem(&obd->obd_uuid, 0, KUC_GRP_HSM);
2623 fld_client_proc_fini(&obd->u.lmv.lmv_fld);
2624 lprocfs_obd_cleanup(obd);
2625 lprocfs_free_md_stats(obd);
2630 * Get by key a value associated with a LMV device.
2632 * Dispatch request to lower-layer devices as needed.
2634 * \param[in] env execution environment for this thread
2635 * \param[in] exp export for the LMV device
2636 * \param[in] keylen length of key identifier
2637 * \param[in] key identifier of key to get value for
2638 * \param[in] vallen size of \a val
2639 * \param[out] val pointer to storage location for value
2640 * \param[in] lsm optional striping metadata of object
2642 * \retval 0 on success
2643 * \retval negative negated errno on failure
2645 static int lmv_get_info(const struct lu_env *env, struct obd_export *exp,
2646 __u32 keylen, void *key, __u32 *vallen, void *val)
2648 struct obd_device *obd;
2649 struct lmv_obd *lmv;
2653 obd = class_exp2obd(exp);
2655 CDEBUG(D_IOCTL, "Invalid client cookie %#llx\n",
2656 exp->exp_handle.h_cookie);
2661 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
2664 LASSERT(*vallen == sizeof(__u32));
2665 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2666 struct lmv_tgt_desc *tgt = lmv->tgts[i];
2668 * All tgts should be connected when this gets called.
2670 if (tgt == NULL || tgt->ltd_exp == NULL)
2673 if (!obd_get_info(env, tgt->ltd_exp, keylen, key,
2678 } else if (KEY_IS(KEY_MAX_EASIZE) ||
2679 KEY_IS(KEY_DEFAULT_EASIZE) ||
2680 KEY_IS(KEY_CONN_DATA)) {
2682 * Forwarding this request to first MDS, it should know LOV
2685 rc = obd_get_info(env, lmv->tgts[0]->ltd_exp, keylen, key,
2687 if (!rc && KEY_IS(KEY_CONN_DATA))
2688 exp->exp_connect_data = *(struct obd_connect_data *)val;
2690 } else if (KEY_IS(KEY_TGT_COUNT)) {
2691 *((int *)val) = lmv->desc.ld_tgt_count;
2695 CDEBUG(D_IOCTL, "Invalid key\n");
2700 * Asynchronously set by key a value associated with a LMV device.
2702 * Dispatch request to lower-layer devices as needed.
2704 * \param[in] env execution environment for this thread
2705 * \param[in] exp export for the LMV device
2706 * \param[in] keylen length of key identifier
2707 * \param[in] key identifier of key to store value for
2708 * \param[in] vallen size of value to store
2709 * \param[in] val pointer to data to be stored
2710 * \param[in] set optional list of related ptlrpc requests
2712 * \retval 0 on success
2713 * \retval negative negated errno on failure
2715 int lmv_set_info_async(const struct lu_env *env, struct obd_export *exp,
2716 __u32 keylen, void *key, __u32 vallen, void *val,
2717 struct ptlrpc_request_set *set)
2719 struct lmv_tgt_desc *tgt = NULL;
2720 struct obd_device *obd;
2721 struct lmv_obd *lmv;
2725 obd = class_exp2obd(exp);
2727 CDEBUG(D_IOCTL, "Invalid client cookie %#llx\n",
2728 exp->exp_handle.h_cookie);
2733 if (KEY_IS(KEY_READ_ONLY) || KEY_IS(KEY_FLUSH_CTX) ||
2734 KEY_IS(KEY_DEFAULT_EASIZE)) {
2737 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2740 if (tgt == NULL || tgt->ltd_exp == NULL)
2743 err = obd_set_info_async(env, tgt->ltd_exp,
2744 keylen, key, vallen, val, set);
2755 static int lmv_unpack_md_v1(struct obd_export *exp, struct lmv_stripe_md *lsm,
2756 const struct lmv_mds_md_v1 *lmm1)
2758 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2765 lsm->lsm_md_magic = le32_to_cpu(lmm1->lmv_magic);
2766 lsm->lsm_md_stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
2767 lsm->lsm_md_master_mdt_index = le32_to_cpu(lmm1->lmv_master_mdt_index);
2768 if (OBD_FAIL_CHECK(OBD_FAIL_UNKNOWN_LMV_STRIPE))
2769 lsm->lsm_md_hash_type = LMV_HASH_TYPE_UNKNOWN;
2771 lsm->lsm_md_hash_type = le32_to_cpu(lmm1->lmv_hash_type);
2772 lsm->lsm_md_layout_version = le32_to_cpu(lmm1->lmv_layout_version);
2773 cplen = strlcpy(lsm->lsm_md_pool_name, lmm1->lmv_pool_name,
2774 sizeof(lsm->lsm_md_pool_name));
2776 if (cplen >= sizeof(lsm->lsm_md_pool_name))
2779 CDEBUG(D_INFO, "unpack lsm count %d, master %d hash_type %d"
2780 "layout_version %d\n", lsm->lsm_md_stripe_count,
2781 lsm->lsm_md_master_mdt_index, lsm->lsm_md_hash_type,
2782 lsm->lsm_md_layout_version);
2784 stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
2785 for (i = 0; i < stripe_count; i++) {
2786 fid_le_to_cpu(&lsm->lsm_md_oinfo[i].lmo_fid,
2787 &lmm1->lmv_stripe_fids[i]);
2788 rc = lmv_fld_lookup(lmv, &lsm->lsm_md_oinfo[i].lmo_fid,
2789 &lsm->lsm_md_oinfo[i].lmo_mds);
2792 CDEBUG(D_INFO, "unpack fid #%d "DFID"\n", i,
2793 PFID(&lsm->lsm_md_oinfo[i].lmo_fid));
2799 static int lmv_unpackmd(struct obd_export *exp, struct lmv_stripe_md **lsmp,
2800 const union lmv_mds_md *lmm, size_t lmm_size)
2802 struct lmv_stripe_md *lsm;
2805 bool allocated = false;
2808 LASSERT(lsmp != NULL);
2812 if (lsm != NULL && lmm == NULL) {
2814 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
2815 /* For migrating inode, the master stripe and master
2816 * object will be the same, so do not need iput, see
2817 * ll_update_lsm_md */
2818 if (!(lsm->lsm_md_hash_type & LMV_HASH_FLAG_MIGRATION &&
2819 i == 0) && lsm->lsm_md_oinfo[i].lmo_root != NULL)
2820 iput(lsm->lsm_md_oinfo[i].lmo_root);
2822 lsm_size = lmv_stripe_md_size(lsm->lsm_md_stripe_count);
2823 OBD_FREE(lsm, lsm_size);
2828 if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_STRIPE)
2832 if (le32_to_cpu(lmm->lmv_magic) != LMV_MAGIC_V1 &&
2833 le32_to_cpu(lmm->lmv_magic) != LMV_USER_MAGIC) {
2834 CERROR("%s: invalid lmv magic %x: rc = %d\n",
2835 exp->exp_obd->obd_name, le32_to_cpu(lmm->lmv_magic),
2840 if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_V1)
2841 lsm_size = lmv_stripe_md_size(lmv_mds_md_stripe_count_get(lmm));
2844 * Unpack default dirstripe(lmv_user_md) to lmv_stripe_md,
2845 * stripecount should be 0 then.
2847 lsm_size = lmv_stripe_md_size(0);
2849 lsm_size = lmv_stripe_md_size(lmv_mds_md_stripe_count_get(lmm));
2851 OBD_ALLOC(lsm, lsm_size);
2858 switch (le32_to_cpu(lmm->lmv_magic)) {
2860 rc = lmv_unpack_md_v1(exp, lsm, &lmm->lmv_md_v1);
2863 CERROR("%s: unrecognized magic %x\n", exp->exp_obd->obd_name,
2864 le32_to_cpu(lmm->lmv_magic));
2869 if (rc != 0 && allocated) {
2870 OBD_FREE(lsm, lsm_size);
2877 void lmv_free_memmd(struct lmv_stripe_md *lsm)
2879 lmv_unpackmd(NULL, &lsm, NULL, 0);
2881 EXPORT_SYMBOL(lmv_free_memmd);
2883 static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
2884 union ldlm_policy_data *policy,
2885 enum ldlm_mode mode, enum ldlm_cancel_flags flags,
2888 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2893 LASSERT(fid != NULL);
2895 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2896 struct lmv_tgt_desc *tgt = lmv->tgts[i];
2899 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
2902 err = md_cancel_unused(tgt->ltd_exp, fid, policy, mode, flags,
2910 static int lmv_set_lock_data(struct obd_export *exp,
2911 const struct lustre_handle *lockh,
2912 void *data, __u64 *bits)
2914 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2915 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2919 if (tgt == NULL || tgt->ltd_exp == NULL)
2921 rc = md_set_lock_data(tgt->ltd_exp, lockh, data, bits);
2925 enum ldlm_mode lmv_lock_match(struct obd_export *exp, __u64 flags,
2926 const struct lu_fid *fid, enum ldlm_type type,
2927 union ldlm_policy_data *policy,
2928 enum ldlm_mode mode, struct lustre_handle *lockh)
2930 struct obd_device *obd = exp->exp_obd;
2931 struct lmv_obd *lmv = &obd->u.lmv;
2937 CDEBUG(D_INODE, "Lock match for "DFID"\n", PFID(fid));
2940 * With DNE every object can have two locks in different namespaces:
2941 * lookup lock in space of MDT storing direntry and update/open lock in
2942 * space of MDT storing inode. Try the MDT that the FID maps to first,
2943 * since this can be easily found, and only try others if that fails.
2945 for (i = 0, tgt = lmv_find_target_index(lmv, fid);
2946 i < lmv->desc.ld_tgt_count;
2947 i++, tgt = (tgt + 1) % lmv->desc.ld_tgt_count) {
2949 CDEBUG(D_HA, "%s: "DFID" is inaccessible: rc = %d\n",
2950 obd->obd_name, PFID(fid), tgt);
2954 if (lmv->tgts[tgt] == NULL ||
2955 lmv->tgts[tgt]->ltd_exp == NULL ||
2956 lmv->tgts[tgt]->ltd_active == 0)
2959 rc = md_lock_match(lmv->tgts[tgt]->ltd_exp, flags, fid,
2960 type, policy, mode, lockh);
2968 int lmv_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
2969 struct obd_export *dt_exp, struct obd_export *md_exp,
2970 struct lustre_md *md)
2972 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2973 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2975 if (tgt == NULL || tgt->ltd_exp == NULL)
2978 return md_get_lustre_md(lmv->tgts[0]->ltd_exp, req, dt_exp, md_exp, md);
2981 int lmv_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
2983 struct obd_device *obd = exp->exp_obd;
2984 struct lmv_obd *lmv = &obd->u.lmv;
2985 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2988 if (md->lmv != NULL) {
2989 lmv_free_memmd(md->lmv);
2992 if (tgt == NULL || tgt->ltd_exp == NULL)
2994 RETURN(md_free_lustre_md(lmv->tgts[0]->ltd_exp, md));
2997 int lmv_set_open_replay_data(struct obd_export *exp,
2998 struct obd_client_handle *och,
2999 struct lookup_intent *it)
3001 struct obd_device *obd = exp->exp_obd;
3002 struct lmv_obd *lmv = &obd->u.lmv;
3003 struct lmv_tgt_desc *tgt;
3006 tgt = lmv_find_target(lmv, &och->och_fid);
3008 RETURN(PTR_ERR(tgt));
3010 RETURN(md_set_open_replay_data(tgt->ltd_exp, och, it));
3013 int lmv_clear_open_replay_data(struct obd_export *exp,
3014 struct obd_client_handle *och)
3016 struct obd_device *obd = exp->exp_obd;
3017 struct lmv_obd *lmv = &obd->u.lmv;
3018 struct lmv_tgt_desc *tgt;
3021 tgt = lmv_find_target(lmv, &och->och_fid);
3023 RETURN(PTR_ERR(tgt));
3025 RETURN(md_clear_open_replay_data(tgt->ltd_exp, och));
3028 int lmv_intent_getattr_async(struct obd_export *exp,
3029 struct md_enqueue_info *minfo)
3031 struct md_op_data *op_data = &minfo->mi_data;
3032 struct obd_device *obd = exp->exp_obd;
3033 struct lmv_obd *lmv = &obd->u.lmv;
3034 struct lmv_tgt_desc *tgt = NULL;
3038 if (!fid_is_sane(&op_data->op_fid2))
3041 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
3043 RETURN(PTR_ERR(tgt));
3046 * no special handle for remote dir, which needs to fetch both LOOKUP
3047 * lock on parent, and then UPDATE lock on child MDT, which makes all
3048 * complicated because this is done async. So only LOOKUP lock is
3049 * fetched for remote dir, but considering remote dir is rare case,
3050 * and not supporting it in statahead won't cause any issue, just leave
3054 rc = md_intent_getattr_async(tgt->ltd_exp, minfo);
3058 int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
3059 struct lu_fid *fid, __u64 *bits)
3061 struct obd_device *obd = exp->exp_obd;
3062 struct lmv_obd *lmv = &obd->u.lmv;
3063 struct lmv_tgt_desc *tgt;
3067 tgt = lmv_find_target(lmv, fid);
3069 RETURN(PTR_ERR(tgt));
3071 rc = md_revalidate_lock(tgt->ltd_exp, it, fid, bits);
3075 int lmv_get_fid_from_lsm(struct obd_export *exp,
3076 const struct lmv_stripe_md *lsm,
3077 const char *name, int namelen, struct lu_fid *fid)
3079 const struct lmv_oinfo *oinfo;
3081 LASSERT(lsm != NULL);
3082 oinfo = lsm_name_to_stripe_info(lsm, name, namelen);
3084 return PTR_ERR(oinfo);
3086 *fid = oinfo->lmo_fid;
3092 * For lmv, only need to send request to master MDT, and the master MDT will
3093 * process with other slave MDTs. The only exception is Q_GETOQUOTA for which
3094 * we directly fetch data from the slave MDTs.
3096 int lmv_quotactl(struct obd_device *unused, struct obd_export *exp,
3097 struct obd_quotactl *oqctl)
3099 struct obd_device *obd = class_exp2obd(exp);
3100 struct lmv_obd *lmv = &obd->u.lmv;
3101 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3104 __u64 curspace, curinodes;
3108 tgt->ltd_exp == NULL ||
3110 lmv->desc.ld_tgt_count == 0) {
3111 CERROR("master lmv inactive\n");
3115 if (oqctl->qc_cmd != Q_GETOQUOTA) {
3116 rc = obd_quotactl(tgt->ltd_exp, oqctl);
3120 curspace = curinodes = 0;
3121 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
3125 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
3128 err = obd_quotactl(tgt->ltd_exp, oqctl);
3130 CERROR("getquota on mdt %d failed. %d\n", i, err);
3134 curspace += oqctl->qc_dqblk.dqb_curspace;
3135 curinodes += oqctl->qc_dqblk.dqb_curinodes;
3138 oqctl->qc_dqblk.dqb_curspace = curspace;
3139 oqctl->qc_dqblk.dqb_curinodes = curinodes;
3144 static int lmv_merge_attr(struct obd_export *exp,
3145 const struct lmv_stripe_md *lsm,
3146 struct cl_attr *attr,
3147 ldlm_blocking_callback cb_blocking)
3152 rc = lmv_revalidate_slaves(exp, lsm, cb_blocking, 0);
3156 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
3157 struct inode *inode = lsm->lsm_md_oinfo[i].lmo_root;
3159 CDEBUG(D_INFO, ""DFID" size %llu, blocks %llu nlink %u,"
3160 " atime %lu ctime %lu, mtime %lu.\n",
3161 PFID(&lsm->lsm_md_oinfo[i].lmo_fid),
3162 i_size_read(inode), (unsigned long long)inode->i_blocks,
3163 inode->i_nlink, LTIME_S(inode->i_atime),
3164 LTIME_S(inode->i_ctime), LTIME_S(inode->i_mtime));
3166 /* for slave stripe, it needs to subtract nlink for . and .. */
3168 attr->cat_nlink += inode->i_nlink - 2;
3170 attr->cat_nlink = inode->i_nlink;
3172 attr->cat_size += i_size_read(inode);
3173 attr->cat_blocks += inode->i_blocks;
3175 if (attr->cat_atime < LTIME_S(inode->i_atime))
3176 attr->cat_atime = LTIME_S(inode->i_atime);
3178 if (attr->cat_ctime < LTIME_S(inode->i_ctime))
3179 attr->cat_ctime = LTIME_S(inode->i_ctime);
3181 if (attr->cat_mtime < LTIME_S(inode->i_mtime))
3182 attr->cat_mtime = LTIME_S(inode->i_mtime);
3187 struct obd_ops lmv_obd_ops = {
3188 .o_owner = THIS_MODULE,
3189 .o_setup = lmv_setup,
3190 .o_cleanup = lmv_cleanup,
3191 .o_precleanup = lmv_precleanup,
3192 .o_process_config = lmv_process_config,
3193 .o_connect = lmv_connect,
3194 .o_disconnect = lmv_disconnect,
3195 .o_statfs = lmv_statfs,
3196 .o_get_info = lmv_get_info,
3197 .o_set_info_async = lmv_set_info_async,
3198 .o_notify = lmv_notify,
3199 .o_get_uuid = lmv_get_uuid,
3200 .o_iocontrol = lmv_iocontrol,
3201 .o_quotactl = lmv_quotactl
3204 struct md_ops lmv_md_ops = {
3205 .m_get_root = lmv_get_root,
3206 .m_null_inode = lmv_null_inode,
3207 .m_close = lmv_close,
3208 .m_create = lmv_create,
3209 .m_enqueue = lmv_enqueue,
3210 .m_getattr = lmv_getattr,
3211 .m_getxattr = lmv_getxattr,
3212 .m_getattr_name = lmv_getattr_name,
3213 .m_intent_lock = lmv_intent_lock,
3215 .m_rename = lmv_rename,
3216 .m_setattr = lmv_setattr,
3217 .m_setxattr = lmv_setxattr,
3218 .m_fsync = lmv_fsync,
3219 .m_file_resync = lmv_file_resync,
3220 .m_read_page = lmv_read_page,
3221 .m_unlink = lmv_unlink,
3222 .m_init_ea_size = lmv_init_ea_size,
3223 .m_cancel_unused = lmv_cancel_unused,
3224 .m_set_lock_data = lmv_set_lock_data,
3225 .m_lock_match = lmv_lock_match,
3226 .m_get_lustre_md = lmv_get_lustre_md,
3227 .m_free_lustre_md = lmv_free_lustre_md,
3228 .m_merge_attr = lmv_merge_attr,
3229 .m_set_open_replay_data = lmv_set_open_replay_data,
3230 .m_clear_open_replay_data = lmv_clear_open_replay_data,
3231 .m_intent_getattr_async = lmv_intent_getattr_async,
3232 .m_revalidate_lock = lmv_revalidate_lock,
3233 .m_get_fid_from_lsm = lmv_get_fid_from_lsm,
3234 .m_unpackmd = lmv_unpackmd,
3237 static int __init lmv_init(void)
3239 return class_register_type(&lmv_obd_ops, &lmv_md_ops, true, NULL,
3240 LUSTRE_LMV_NAME, NULL);
3243 static void __exit lmv_exit(void)
3245 class_unregister_type(LUSTRE_LMV_NAME);
3248 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
3249 MODULE_DESCRIPTION("Lustre Logical Metadata Volume");
3250 MODULE_VERSION(LUSTRE_VERSION_STRING);
3251 MODULE_LICENSE("GPL");
3253 module_init(lmv_init);
3254 module_exit(lmv_exit);