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, 2016, 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
34 #include <linux/slab.h>
35 #include <linux/module.h>
36 #include <linux/init.h>
37 #include <linux/user_namespace.h>
38 #ifdef HAVE_UIDGID_HEADER
39 # include <linux/uidgid.h>
41 #include <linux/slab.h>
42 #include <linux/pagemap.h>
44 #include <linux/math64.h>
45 #include <linux/seq_file.h>
46 #include <linux/namei.h>
48 #include <obd_support.h>
49 #include <lustre_lib.h>
50 #include <lustre_net.h>
51 #include <obd_class.h>
52 #include <lustre_lmv.h>
53 #include <lprocfs_status.h>
54 #include <cl_object.h>
55 #include <lustre_fid.h>
56 #include <uapi/linux/lustre/lustre_ioctl.h>
57 #include <lustre_kernelcomm.h>
58 #include "lmv_internal.h"
60 static int lmv_check_connect(struct obd_device *obd);
62 static void lmv_activate_target(struct lmv_obd *lmv,
63 struct lmv_tgt_desc *tgt,
66 if (tgt->ltd_active == activate)
69 tgt->ltd_active = activate;
70 lmv->desc.ld_active_tgt_count += (activate ? 1 : -1);
72 tgt->ltd_exp->exp_obd->obd_inactive = !activate;
78 * -EINVAL : UUID can't be found in the LMV's target list
79 * -ENOTCONN: The UUID is found, but the target connection is bad (!)
80 * -EBADF : The UUID is found, but the OBD of the wrong type (!)
82 static int lmv_set_mdc_active(struct lmv_obd *lmv,
83 const struct obd_uuid *uuid,
86 struct lmv_tgt_desc *tgt = NULL;
87 struct obd_device *obd;
92 CDEBUG(D_INFO, "Searching in lmv %p for uuid %s (activate=%d)\n",
93 lmv, uuid->uuid, activate);
95 spin_lock(&lmv->lmv_lock);
96 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
98 if (tgt == NULL || tgt->ltd_exp == NULL)
101 CDEBUG(D_INFO, "Target idx %d is %s conn %#llx\n", i,
102 tgt->ltd_uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
104 if (obd_uuid_equals(uuid, &tgt->ltd_uuid))
108 if (i == lmv->desc.ld_tgt_count)
109 GOTO(out_lmv_lock, rc = -EINVAL);
111 obd = class_exp2obd(tgt->ltd_exp);
113 GOTO(out_lmv_lock, rc = -ENOTCONN);
115 CDEBUG(D_INFO, "Found OBD %s=%s device %d (%p) type %s at LMV idx %d\n",
116 obd->obd_name, obd->obd_uuid.uuid, obd->obd_minor, obd,
117 obd->obd_type->typ_name, i);
118 LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0);
120 if (tgt->ltd_active == activate) {
121 CDEBUG(D_INFO, "OBD %p already %sactive!\n", obd,
122 activate ? "" : "in");
123 GOTO(out_lmv_lock, rc);
126 CDEBUG(D_INFO, "Marking OBD %p %sactive\n", obd,
127 activate ? "" : "in");
128 lmv_activate_target(lmv, tgt, activate);
132 spin_unlock(&lmv->lmv_lock);
136 struct obd_uuid *lmv_get_uuid(struct obd_export *exp)
138 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
139 struct lmv_tgt_desc *tgt = lmv->tgts[0];
141 return (tgt == NULL) ? NULL : obd_get_uuid(tgt->ltd_exp);
144 static int lmv_notify(struct obd_device *obd, struct obd_device *watched,
145 enum obd_notify_event ev)
147 struct obd_connect_data *conn_data;
148 struct lmv_obd *lmv = &obd->u.lmv;
149 struct obd_uuid *uuid;
153 if (strcmp(watched->obd_type->typ_name, LUSTRE_MDC_NAME)) {
154 CERROR("unexpected notification of %s %s!\n",
155 watched->obd_type->typ_name,
160 uuid = &watched->u.cli.cl_target_uuid;
161 if (ev == OBD_NOTIFY_ACTIVE || ev == OBD_NOTIFY_INACTIVE) {
163 * Set MDC as active before notifying the observer, so the
164 * observer can use the MDC normally.
166 rc = lmv_set_mdc_active(lmv, uuid,
167 ev == OBD_NOTIFY_ACTIVE);
169 CERROR("%sactivation of %s failed: %d\n",
170 ev == OBD_NOTIFY_ACTIVE ? "" : "de",
174 } else if (ev == OBD_NOTIFY_OCD) {
175 conn_data = &watched->u.cli.cl_import->imp_connect_data;
177 * XXX: Make sure that ocd_connect_flags from all targets are
178 * the same. Otherwise one of MDTs runs wrong version or
179 * something like this. --umka
181 obd->obd_self_export->exp_connect_data = *conn_data;
185 * Pass the notification up the chain.
187 if (obd->obd_observer)
188 rc = obd_notify(obd->obd_observer, watched, ev);
193 static int lmv_connect(const struct lu_env *env,
194 struct obd_export **pexp, struct obd_device *obd,
195 struct obd_uuid *cluuid, struct obd_connect_data *data,
198 struct lmv_obd *lmv = &obd->u.lmv;
199 struct lustre_handle conn = { 0 };
200 struct obd_export *exp;
204 rc = class_connect(&conn, obd, cluuid);
206 CERROR("class_connection() returned %d\n", rc);
210 exp = class_conn2export(&conn);
213 lmv->conn_data = *data;
215 if (lmv->targets_proc_entry == NULL) {
216 lmv->targets_proc_entry = lprocfs_register("target_obds",
219 if (IS_ERR(lmv->targets_proc_entry)) {
220 CERROR("%s: cannot register "
221 "/proc/fs/lustre/%s/%s/target_obds\n",
222 obd->obd_name, obd->obd_type->typ_name,
224 lmv->targets_proc_entry = NULL;
228 rc = lmv_check_connect(obd);
237 if (lmv->targets_proc_entry != NULL)
238 lprocfs_remove(&lmv->targets_proc_entry);
240 class_disconnect(exp);
245 static int lmv_init_ea_size(struct obd_export *exp, __u32 easize,
248 struct obd_device *obd = exp->exp_obd;
249 struct lmv_obd *lmv = &obd->u.lmv;
255 if (lmv->max_easize < easize) {
256 lmv->max_easize = easize;
259 if (lmv->max_def_easize < def_easize) {
260 lmv->max_def_easize = def_easize;
267 if (lmv->connected == 0)
270 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
271 struct lmv_tgt_desc *tgt = lmv->tgts[i];
273 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active) {
274 CWARN("%s: NULL export for %d\n", obd->obd_name, i);
278 rc = md_init_ea_size(tgt->ltd_exp, easize, def_easize);
280 CERROR("%s: obd_init_ea_size() failed on MDT target %d:"
281 " rc = %d\n", obd->obd_name, i, rc);
288 #define MAX_STRING_SIZE 128
290 int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
292 struct lmv_obd *lmv = &obd->u.lmv;
293 struct obd_device *mdc_obd;
294 struct obd_export *mdc_exp;
295 struct lu_fld_target target;
299 mdc_obd = class_find_client_obd(&tgt->ltd_uuid, LUSTRE_MDC_NAME,
302 CERROR("target %s not attached\n", tgt->ltd_uuid.uuid);
306 CDEBUG(D_CONFIG, "connect to %s(%s) - %s, %s\n",
307 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
308 tgt->ltd_uuid.uuid, obd->obd_uuid.uuid);
310 if (!mdc_obd->obd_set_up) {
311 CERROR("target %s is not set up\n", tgt->ltd_uuid.uuid);
315 rc = obd_connect(NULL, &mdc_exp, mdc_obd, &obd->obd_uuid,
316 &lmv->conn_data, NULL);
318 CERROR("target %s connect error %d\n", tgt->ltd_uuid.uuid, rc);
323 * Init fid sequence client for this mdc and add new fld target.
325 rc = obd_fid_init(mdc_obd, mdc_exp, LUSTRE_SEQ_METADATA);
329 target.ft_srv = NULL;
330 target.ft_exp = mdc_exp;
331 target.ft_idx = tgt->ltd_idx;
333 fld_client_add_target(&lmv->lmv_fld, &target);
335 rc = obd_register_observer(mdc_obd, obd);
337 obd_disconnect(mdc_exp);
338 CERROR("target %s register_observer error %d\n",
339 tgt->ltd_uuid.uuid, rc);
343 if (obd->obd_observer) {
345 * Tell the observer about the new target.
347 rc = obd_notify(obd->obd_observer, mdc_exp->exp_obd,
350 obd_disconnect(mdc_exp);
356 tgt->ltd_exp = mdc_exp;
357 lmv->desc.ld_active_tgt_count++;
359 md_init_ea_size(tgt->ltd_exp, lmv->max_easize, lmv->max_def_easize);
361 CDEBUG(D_CONFIG, "Connected to %s(%s) successfully (%d)\n",
362 mdc_obd->obd_name, mdc_obd->obd_uuid.uuid,
363 atomic_read(&obd->obd_refcount));
365 if (lmv->targets_proc_entry != NULL) {
366 struct proc_dir_entry *mdc_symlink;
368 LASSERT(mdc_obd->obd_type != NULL);
369 LASSERT(mdc_obd->obd_type->typ_name != NULL);
370 mdc_symlink = lprocfs_add_symlink(mdc_obd->obd_name,
371 lmv->targets_proc_entry,
373 mdc_obd->obd_type->typ_name,
375 if (mdc_symlink == NULL) {
376 CERROR("cannot register LMV target "
377 "/proc/fs/lustre/%s/%s/target_obds/%s\n",
378 obd->obd_type->typ_name, obd->obd_name,
385 static void lmv_del_target(struct lmv_obd *lmv, int index)
387 if (lmv->tgts[index] == NULL)
390 OBD_FREE_PTR(lmv->tgts[index]);
391 lmv->tgts[index] = NULL;
395 static int lmv_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
396 __u32 index, int gen)
398 struct obd_device *mdc_obd;
399 struct lmv_obd *lmv = &obd->u.lmv;
400 struct lmv_tgt_desc *tgt;
401 int orig_tgt_count = 0;
405 CDEBUG(D_CONFIG, "Target uuid: %s. index %d\n", uuidp->uuid, index);
406 mdc_obd = class_find_client_obd(uuidp, LUSTRE_MDC_NAME,
409 CERROR("%s: Target %s not attached: rc = %d\n",
410 obd->obd_name, uuidp->uuid, -EINVAL);
414 mutex_lock(&lmv->lmv_init_mutex);
415 if ((index < lmv->tgts_size) && (lmv->tgts[index] != NULL)) {
416 tgt = lmv->tgts[index];
417 CERROR("%s: UUID %s already assigned at LMV target index %d:"
418 " rc = %d\n", obd->obd_name,
419 obd_uuid2str(&tgt->ltd_uuid), index, -EEXIST);
420 mutex_unlock(&lmv->lmv_init_mutex);
424 if (index >= lmv->tgts_size) {
425 /* We need to reallocate the lmv target array. */
426 struct lmv_tgt_desc **newtgts, **old = NULL;
430 while (newsize < index + 1)
431 newsize = newsize << 1;
432 OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
433 if (newtgts == NULL) {
434 mutex_unlock(&lmv->lmv_init_mutex);
438 if (lmv->tgts_size) {
439 memcpy(newtgts, lmv->tgts,
440 sizeof(*newtgts) * lmv->tgts_size);
442 oldsize = lmv->tgts_size;
446 lmv->tgts_size = newsize;
449 OBD_FREE(old, sizeof(*old) * oldsize);
451 CDEBUG(D_CONFIG, "tgts: %p size: %d\n", lmv->tgts,
457 mutex_unlock(&lmv->lmv_init_mutex);
461 mutex_init(&tgt->ltd_fid_mutex);
462 tgt->ltd_idx = index;
463 tgt->ltd_uuid = *uuidp;
465 lmv->tgts[index] = tgt;
466 if (index >= lmv->desc.ld_tgt_count) {
467 orig_tgt_count = lmv->desc.ld_tgt_count;
468 lmv->desc.ld_tgt_count = index + 1;
471 if (lmv->connected == 0) {
472 /* lmv_check_connect() will connect this target. */
473 mutex_unlock(&lmv->lmv_init_mutex);
477 /* Otherwise let's connect it ourselves */
478 mutex_unlock(&lmv->lmv_init_mutex);
479 rc = lmv_connect_mdc(obd, tgt);
481 spin_lock(&lmv->lmv_lock);
482 if (lmv->desc.ld_tgt_count == index + 1)
483 lmv->desc.ld_tgt_count = orig_tgt_count;
484 memset(tgt, 0, sizeof(*tgt));
485 spin_unlock(&lmv->lmv_lock);
487 int easize = sizeof(struct lmv_stripe_md) +
488 lmv->desc.ld_tgt_count * sizeof(struct lu_fid);
489 lmv_init_ea_size(obd->obd_self_export, easize, 0);
495 static int lmv_check_connect(struct obd_device *obd)
497 struct lmv_obd *lmv = &obd->u.lmv;
498 struct lmv_tgt_desc *tgt;
507 mutex_lock(&lmv->lmv_init_mutex);
508 if (lmv->connected) {
509 mutex_unlock(&lmv->lmv_init_mutex);
513 if (lmv->desc.ld_tgt_count == 0) {
514 mutex_unlock(&lmv->lmv_init_mutex);
515 CERROR("%s: no targets configured.\n", obd->obd_name);
519 LASSERT(lmv->tgts != NULL);
521 if (lmv->tgts[0] == NULL) {
522 mutex_unlock(&lmv->lmv_init_mutex);
523 CERROR("%s: no target configured for index 0.\n",
528 CDEBUG(D_CONFIG, "Time to connect %s to %s\n",
529 obd->obd_uuid.uuid, obd->obd_name);
531 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
535 rc = lmv_connect_mdc(obd, tgt);
541 easize = lmv_mds_md_size(lmv->desc.ld_tgt_count, LMV_MAGIC);
542 lmv_init_ea_size(obd->obd_self_export, easize, 0);
543 mutex_unlock(&lmv->lmv_init_mutex);
554 --lmv->desc.ld_active_tgt_count;
555 rc2 = obd_disconnect(tgt->ltd_exp);
557 CERROR("LMV target %s disconnect on "
558 "MDC idx %d: error %d\n",
559 tgt->ltd_uuid.uuid, i, rc2);
564 mutex_unlock(&lmv->lmv_init_mutex);
569 static int lmv_disconnect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
571 struct lmv_obd *lmv = &obd->u.lmv;
572 struct obd_device *mdc_obd;
576 LASSERT(tgt != NULL);
577 LASSERT(obd != NULL);
579 mdc_obd = class_exp2obd(tgt->ltd_exp);
582 mdc_obd->obd_force = obd->obd_force;
583 mdc_obd->obd_fail = obd->obd_fail;
584 mdc_obd->obd_no_recov = obd->obd_no_recov;
586 if (lmv->targets_proc_entry != NULL)
587 lprocfs_remove_proc_entry(mdc_obd->obd_name,
588 lmv->targets_proc_entry);
591 rc = obd_fid_fini(tgt->ltd_exp->exp_obd);
593 CERROR("Can't finanize fids factory\n");
595 CDEBUG(D_INFO, "Disconnected from %s(%s) successfully\n",
596 tgt->ltd_exp->exp_obd->obd_name,
597 tgt->ltd_exp->exp_obd->obd_uuid.uuid);
599 obd_register_observer(tgt->ltd_exp->exp_obd, NULL);
600 rc = obd_disconnect(tgt->ltd_exp);
602 if (tgt->ltd_active) {
603 CERROR("Target %s disconnect error %d\n",
604 tgt->ltd_uuid.uuid, rc);
608 lmv_activate_target(lmv, tgt, 0);
613 static int lmv_disconnect(struct obd_export *exp)
615 struct obd_device *obd = class_exp2obd(exp);
616 struct lmv_obd *lmv = &obd->u.lmv;
624 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
625 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
628 lmv_disconnect_mdc(obd, lmv->tgts[i]);
631 if (lmv->targets_proc_entry != NULL)
632 lprocfs_remove(&lmv->targets_proc_entry);
634 CERROR("/proc/fs/lustre/%s/%s/target_obds missing\n",
635 obd->obd_type->typ_name, obd->obd_name);
639 * This is the case when no real connection is established by
640 * lmv_check_connect().
643 class_export_put(exp);
644 rc = class_disconnect(exp);
650 static int lmv_fid2path(struct obd_export *exp, int len, void *karg,
653 struct obd_device *obddev = class_exp2obd(exp);
654 struct lmv_obd *lmv = &obddev->u.lmv;
655 struct getinfo_fid2path *gf;
656 struct lmv_tgt_desc *tgt;
657 struct getinfo_fid2path *remote_gf = NULL;
658 struct lu_fid root_fid;
659 int remote_gf_size = 0;
663 tgt = lmv_find_target(lmv, &gf->gf_fid);
665 RETURN(PTR_ERR(tgt));
667 root_fid = *gf->gf_u.gf_root_fid;
668 LASSERT(fid_is_sane(&root_fid));
671 rc = obd_iocontrol(OBD_IOC_FID2PATH, tgt->ltd_exp, len, gf, uarg);
672 if (rc != 0 && rc != -EREMOTE)
673 GOTO(out_fid2path, rc);
675 /* If remote_gf != NULL, it means just building the
676 * path on the remote MDT, copy this path segement to gf */
677 if (remote_gf != NULL) {
678 struct getinfo_fid2path *ori_gf;
681 ori_gf = (struct getinfo_fid2path *)karg;
682 if (strlen(ori_gf->gf_u.gf_path) + 1 +
683 strlen(gf->gf_u.gf_path) + 1 > ori_gf->gf_pathlen)
684 GOTO(out_fid2path, rc = -EOVERFLOW);
686 ptr = ori_gf->gf_u.gf_path;
688 memmove(ptr + strlen(gf->gf_u.gf_path) + 1, ptr,
689 strlen(ori_gf->gf_u.gf_path));
691 strncpy(ptr, gf->gf_u.gf_path,
692 strlen(gf->gf_u.gf_path));
693 ptr += strlen(gf->gf_u.gf_path);
697 CDEBUG(D_INFO, "%s: get path %s "DFID" rec: %llu ln: %u\n",
698 tgt->ltd_exp->exp_obd->obd_name,
699 gf->gf_u.gf_path, PFID(&gf->gf_fid), gf->gf_recno,
703 GOTO(out_fid2path, rc);
705 /* sigh, has to go to another MDT to do path building further */
706 if (remote_gf == NULL) {
707 remote_gf_size = sizeof(*remote_gf) + PATH_MAX;
708 OBD_ALLOC(remote_gf, remote_gf_size);
709 if (remote_gf == NULL)
710 GOTO(out_fid2path, rc = -ENOMEM);
711 remote_gf->gf_pathlen = PATH_MAX;
714 if (!fid_is_sane(&gf->gf_fid)) {
715 CERROR("%s: invalid FID "DFID": rc = %d\n",
716 tgt->ltd_exp->exp_obd->obd_name,
717 PFID(&gf->gf_fid), -EINVAL);
718 GOTO(out_fid2path, rc = -EINVAL);
721 tgt = lmv_find_target(lmv, &gf->gf_fid);
723 GOTO(out_fid2path, rc = -EINVAL);
725 remote_gf->gf_fid = gf->gf_fid;
726 remote_gf->gf_recno = -1;
727 remote_gf->gf_linkno = -1;
728 memset(remote_gf->gf_u.gf_path, 0, remote_gf->gf_pathlen);
729 *remote_gf->gf_u.gf_root_fid = root_fid;
731 goto repeat_fid2path;
734 if (remote_gf != NULL)
735 OBD_FREE(remote_gf, remote_gf_size);
739 static int lmv_hsm_req_count(struct lmv_obd *lmv,
740 const struct hsm_user_request *hur,
741 const struct lmv_tgt_desc *tgt_mds)
745 struct lmv_tgt_desc *curr_tgt;
747 /* count how many requests must be sent to the given target */
748 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
749 curr_tgt = lmv_find_target(lmv, &hur->hur_user_item[i].hui_fid);
750 if (IS_ERR(curr_tgt))
751 RETURN(PTR_ERR(curr_tgt));
752 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid))
758 static int lmv_hsm_req_build(struct lmv_obd *lmv,
759 struct hsm_user_request *hur_in,
760 const struct lmv_tgt_desc *tgt_mds,
761 struct hsm_user_request *hur_out)
764 struct lmv_tgt_desc *curr_tgt;
766 /* build the hsm_user_request for the given target */
767 hur_out->hur_request = hur_in->hur_request;
769 for (i = 0; i < hur_in->hur_request.hr_itemcount; i++) {
770 curr_tgt = lmv_find_target(lmv,
771 &hur_in->hur_user_item[i].hui_fid);
772 if (IS_ERR(curr_tgt))
773 RETURN(PTR_ERR(curr_tgt));
774 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid)) {
775 hur_out->hur_user_item[nr_out] =
776 hur_in->hur_user_item[i];
780 hur_out->hur_request.hr_itemcount = nr_out;
781 memcpy(hur_data(hur_out), hur_data(hur_in),
782 hur_in->hur_request.hr_data_len);
787 static int lmv_hsm_ct_unregister(struct obd_device *obd, unsigned int cmd,
788 int len, struct lustre_kernelcomm *lk,
791 struct lmv_obd *lmv = &obd->u.lmv;
796 /* unregister request (call from llapi_hsm_copytool_fini) */
797 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
798 struct lmv_tgt_desc *tgt = lmv->tgts[i];
800 if (tgt == NULL || tgt->ltd_exp == NULL)
802 /* best effort: try to clean as much as possible
803 * (continue on error) */
804 obd_iocontrol(cmd, tgt->ltd_exp, len, lk, uarg);
807 /* Whatever the result, remove copytool from kuc groups.
808 * Unreached coordinators will get EPIPE on next requests
809 * and will unregister automatically.
811 rc = libcfs_kkuc_group_rem(&obd->obd_uuid, lk->lk_uid, lk->lk_group);
816 static int lmv_hsm_ct_register(struct obd_device *obd, unsigned int cmd,
817 int len, struct lustre_kernelcomm *lk,
820 struct lmv_obd *lmv = &obd->u.lmv;
824 bool any_set = false;
825 struct kkuc_ct_data kcd = {
826 .kcd_magic = KKUC_CT_DATA_MAGIC,
827 .kcd_archive = lk->lk_data,
832 filp = fget(lk->lk_wfd);
836 rc = libcfs_kkuc_group_add(filp, &obd->obd_uuid, lk->lk_uid,
837 lk->lk_group, &kcd, sizeof(kcd));
841 /* All or nothing: try to register to all MDS.
842 * In case of failure, unregister from previous MDS,
843 * except if it because of inactive target. */
844 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
845 struct lmv_tgt_desc *tgt = lmv->tgts[i];
847 if (tgt == NULL || tgt->ltd_exp == NULL)
850 err = obd_iocontrol(cmd, tgt->ltd_exp, len, lk, uarg);
852 if (tgt->ltd_active) {
853 /* permanent error */
854 CERROR("%s: iocontrol MDC %s on MDT"
855 " idx %d cmd %x: err = %d\n",
856 lmv2obd_dev(lmv)->obd_name,
857 tgt->ltd_uuid.uuid, i, cmd, err);
859 lk->lk_flags |= LK_FLG_STOP;
860 /* unregister from previous MDS */
861 for (j = 0; j < i; j++) {
863 if (tgt == NULL || tgt->ltd_exp == NULL)
865 obd_iocontrol(cmd, tgt->ltd_exp, len,
868 GOTO(err_kkuc_rem, rc);
870 /* else: transient error.
871 * kuc will register to the missing MDT
879 /* no registration done: return error */
880 GOTO(err_kkuc_rem, rc = -ENOTCONN);
885 libcfs_kkuc_group_rem(&obd->obd_uuid, lk->lk_uid, lk->lk_group);
895 static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
896 int len, void *karg, void __user *uarg)
898 struct obd_device *obddev = class_exp2obd(exp);
899 struct lmv_obd *lmv = &obddev->u.lmv;
900 struct lmv_tgt_desc *tgt = NULL;
904 __u32 count = lmv->desc.ld_tgt_count;
911 case IOC_OBD_STATFS: {
912 struct obd_ioctl_data *data = karg;
913 struct obd_device *mdc_obd;
914 struct obd_statfs stat_buf = {0};
917 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
918 if ((index >= count))
921 tgt = lmv->tgts[index];
922 if (tgt == NULL || !tgt->ltd_active)
925 mdc_obd = class_exp2obd(tgt->ltd_exp);
930 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(mdc_obd),
931 min((int) data->ioc_plen2,
932 (int) sizeof(struct obd_uuid))))
935 rc = obd_statfs(NULL, tgt->ltd_exp, &stat_buf,
936 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
940 if (copy_to_user(data->ioc_pbuf1, &stat_buf,
941 min((int) data->ioc_plen1,
942 (int) sizeof(stat_buf))))
946 case OBD_IOC_QUOTACTL: {
947 struct if_quotactl *qctl = karg;
948 struct obd_quotactl *oqctl;
950 if (qctl->qc_valid == QC_MDTIDX) {
951 if (count <= qctl->qc_idx)
954 tgt = lmv->tgts[qctl->qc_idx];
955 if (tgt == NULL || tgt->ltd_exp == NULL)
957 } else if (qctl->qc_valid == QC_UUID) {
958 for (i = 0; i < count; i++) {
962 if (!obd_uuid_equals(&tgt->ltd_uuid,
966 if (tgt->ltd_exp == NULL)
978 LASSERT(tgt != NULL && tgt->ltd_exp != NULL);
979 OBD_ALLOC_PTR(oqctl);
983 QCTL_COPY(oqctl, qctl);
984 rc = obd_quotactl(tgt->ltd_exp, oqctl);
986 QCTL_COPY(qctl, oqctl);
987 qctl->qc_valid = QC_MDTIDX;
988 qctl->obd_uuid = tgt->ltd_uuid;
993 case LL_IOC_GET_CONNECT_FLAGS: {
995 if (tgt == NULL || tgt->ltd_exp == NULL)
997 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1000 case LL_IOC_FID2MDTIDX: {
1001 struct lu_fid *fid = karg;
1004 rc = lmv_fld_lookup(lmv, fid, &mdt_index);
1008 /* Note: this is from llite(see ll_dir_ioctl()), @uarg does not
1009 * point to user space memory for FID2MDTIDX. */
1010 *(__u32 *)uarg = mdt_index;
1013 case OBD_IOC_FID2PATH: {
1014 rc = lmv_fid2path(exp, len, karg, uarg);
1017 case LL_IOC_HSM_STATE_GET:
1018 case LL_IOC_HSM_STATE_SET:
1019 case LL_IOC_HSM_ACTION: {
1020 struct md_op_data *op_data = karg;
1022 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1024 RETURN(PTR_ERR(tgt));
1026 if (tgt->ltd_exp == NULL)
1029 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1032 case LL_IOC_HSM_PROGRESS: {
1033 const struct hsm_progress_kernel *hpk = karg;
1035 tgt = lmv_find_target(lmv, &hpk->hpk_fid);
1037 RETURN(PTR_ERR(tgt));
1038 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1041 case LL_IOC_HSM_REQUEST: {
1042 struct hsm_user_request *hur = karg;
1043 unsigned int reqcount = hur->hur_request.hr_itemcount;
1048 /* if the request is about a single fid
1049 * or if there is a single MDS, no need to split
1051 if (reqcount == 1 || count == 1) {
1052 tgt = lmv_find_target(lmv,
1053 &hur->hur_user_item[0].hui_fid);
1055 RETURN(PTR_ERR(tgt));
1056 rc = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1058 /* split fid list to their respective MDS */
1059 for (i = 0; i < count; i++) {
1062 struct hsm_user_request *req;
1065 if (tgt == NULL || tgt->ltd_exp == NULL)
1068 nr = lmv_hsm_req_count(lmv, hur, tgt);
1071 if (nr == 0) /* nothing for this MDS */
1074 /* build a request with fids for this MDS */
1075 reqlen = offsetof(typeof(*hur),
1077 + hur->hur_request.hr_data_len;
1078 OBD_ALLOC_LARGE(req, reqlen);
1081 rc1 = lmv_hsm_req_build(lmv, hur, tgt, req);
1083 GOTO(hsm_req_err, rc1);
1084 rc1 = obd_iocontrol(cmd, tgt->ltd_exp, reqlen,
1087 if (rc1 != 0 && rc == 0)
1089 OBD_FREE_LARGE(req, reqlen);
1094 case LL_IOC_LOV_SWAP_LAYOUTS: {
1095 struct md_op_data *op_data = karg;
1096 struct lmv_tgt_desc *tgt1, *tgt2;
1098 tgt1 = lmv_find_target(lmv, &op_data->op_fid1);
1100 RETURN(PTR_ERR(tgt1));
1102 tgt2 = lmv_find_target(lmv, &op_data->op_fid2);
1104 RETURN(PTR_ERR(tgt2));
1106 if ((tgt1->ltd_exp == NULL) || (tgt2->ltd_exp == NULL))
1109 /* only files on same MDT can have their layouts swapped */
1110 if (tgt1->ltd_idx != tgt2->ltd_idx)
1113 rc = obd_iocontrol(cmd, tgt1->ltd_exp, len, karg, uarg);
1116 case LL_IOC_HSM_CT_START: {
1117 struct lustre_kernelcomm *lk = karg;
1118 if (lk->lk_flags & LK_FLG_STOP)
1119 rc = lmv_hsm_ct_unregister(obddev, cmd, len, lk, uarg);
1121 rc = lmv_hsm_ct_register(obddev, cmd, len, lk, uarg);
1125 for (i = 0; i < count; i++) {
1126 struct obd_device *mdc_obd;
1130 if (tgt == NULL || tgt->ltd_exp == NULL)
1132 /* ll_umount_begin() sets force flag but for lmv, not
1133 * mdc. Let's pass it through */
1134 mdc_obd = class_exp2obd(tgt->ltd_exp);
1135 mdc_obd->obd_force = obddev->obd_force;
1136 err = obd_iocontrol(cmd, tgt->ltd_exp, len, karg, uarg);
1138 if (tgt->ltd_active) {
1139 CERROR("error: iocontrol MDC %s on MDT"
1140 " idx %d cmd %x: err = %d\n",
1141 tgt->ltd_uuid.uuid, i, cmd, err);
1155 * This is _inode_ placement policy function (not name).
1157 static int lmv_placement_policy(struct obd_device *obd,
1158 struct md_op_data *op_data, u32 *mds)
1160 struct lmv_obd *lmv = &obd->u.lmv;
1161 struct lmv_user_md *lum;
1165 LASSERT(mds != NULL);
1167 if (lmv->desc.ld_tgt_count == 1) {
1172 lum = op_data->op_data;
1174 * 1. See if the stripe offset is specified by lum.
1175 * 2. Then check if there is default stripe offset.
1176 * 3. Finally choose MDS by name hash if the parent
1177 * is striped directory. (see lmv_locate_mds()). */
1178 if (op_data->op_cli_flags & CLI_SET_MEA && lum != NULL &&
1179 le32_to_cpu(lum->lum_stripe_offset) != (__u32)-1) {
1180 *mds = le32_to_cpu(lum->lum_stripe_offset);
1181 } else if (op_data->op_default_stripe_offset != (__u32)-1) {
1182 *mds = op_data->op_default_stripe_offset;
1183 op_data->op_mds = *mds;
1184 /* Correct the stripe offset in lum */
1186 lum->lum_stripe_offset = cpu_to_le32(*mds);
1188 *mds = op_data->op_mds;
1194 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid, u32 mds)
1196 struct lmv_tgt_desc *tgt;
1200 tgt = lmv_get_target(lmv, mds, NULL);
1202 RETURN(PTR_ERR(tgt));
1205 * New seq alloc and FLD setup should be atomic. Otherwise we may find
1206 * on server that seq in new allocated fid is not yet known.
1208 mutex_lock(&tgt->ltd_fid_mutex);
1210 if (tgt->ltd_active == 0 || tgt->ltd_exp == NULL)
1211 GOTO(out, rc = -ENODEV);
1214 * Asking underlying tgt layer to allocate new fid.
1216 rc = obd_fid_alloc(NULL, tgt->ltd_exp, fid, NULL);
1218 LASSERT(fid_is_sane(fid));
1224 mutex_unlock(&tgt->ltd_fid_mutex);
1228 int lmv_fid_alloc(const struct lu_env *env, struct obd_export *exp,
1229 struct lu_fid *fid, struct md_op_data *op_data)
1231 struct obd_device *obd = class_exp2obd(exp);
1232 struct lmv_obd *lmv = &obd->u.lmv;
1237 LASSERT(op_data != NULL);
1238 LASSERT(fid != NULL);
1240 rc = lmv_placement_policy(obd, op_data, &mds);
1242 CERROR("Can't get target for allocating fid, "
1247 rc = __lmv_fid_alloc(lmv, fid, mds);
1249 CERROR("Can't alloc new fid, rc %d\n", rc);
1256 static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
1258 struct lmv_obd *lmv = &obd->u.lmv;
1259 struct lmv_desc *desc;
1263 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
1264 CERROR("LMV setup requires a descriptor\n");
1268 desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1);
1269 if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) {
1270 CERROR("Lmv descriptor size wrong: %d > %d\n",
1271 (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1));
1275 lmv->tgts_size = 32U;
1276 OBD_ALLOC(lmv->tgts, sizeof(*lmv->tgts) * lmv->tgts_size);
1277 if (lmv->tgts == NULL)
1280 obd_str2uuid(&lmv->desc.ld_uuid, desc->ld_uuid.uuid);
1281 lmv->desc.ld_tgt_count = 0;
1282 lmv->desc.ld_active_tgt_count = 0;
1283 lmv->max_def_easize = 0;
1284 lmv->max_easize = 0;
1286 spin_lock_init(&lmv->lmv_lock);
1287 mutex_init(&lmv->lmv_init_mutex);
1289 #ifdef CONFIG_PROC_FS
1290 obd->obd_vars = lprocfs_lmv_obd_vars;
1291 lprocfs_obd_setup(obd, true);
1292 lprocfs_alloc_md_stats(obd, 0);
1293 rc = lprocfs_seq_create(obd->obd_proc_entry, "target_obd",
1294 0444, &lmv_proc_target_fops, obd);
1296 CWARN("%s: error adding LMV target_obd file: rc = %d\n",
1299 rc = fld_client_init(&lmv->lmv_fld, obd->obd_name,
1300 LUSTRE_CLI_FLD_HASH_DHT);
1302 CERROR("Can't init FLD, err %d\n", rc);
1312 static int lmv_cleanup(struct obd_device *obd)
1314 struct lmv_obd *lmv = &obd->u.lmv;
1317 fld_client_fini(&lmv->lmv_fld);
1318 if (lmv->tgts != NULL) {
1320 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1321 if (lmv->tgts[i] == NULL)
1323 lmv_del_target(lmv, i);
1325 OBD_FREE(lmv->tgts, sizeof(*lmv->tgts) * lmv->tgts_size);
1331 static int lmv_process_config(struct obd_device *obd, size_t len, void *buf)
1333 struct lustre_cfg *lcfg = buf;
1334 struct obd_uuid obd_uuid;
1340 switch (lcfg->lcfg_command) {
1342 /* modify_mdc_tgts add 0:lustre-clilmv 1:lustre-MDT0000_UUID
1343 * 2:0 3:1 4:lustre-MDT0000-mdc_UUID */
1344 if (LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(obd_uuid.uuid))
1345 GOTO(out, rc = -EINVAL);
1347 obd_str2uuid(&obd_uuid, lustre_cfg_buf(lcfg, 1));
1349 if (sscanf(lustre_cfg_buf(lcfg, 2), "%u", &index) != 1)
1350 GOTO(out, rc = -EINVAL);
1351 if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", &gen) != 1)
1352 GOTO(out, rc = -EINVAL);
1353 rc = lmv_add_target(obd, &obd_uuid, index, gen);
1356 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1357 GOTO(out, rc = -EINVAL);
1363 static int lmv_statfs(const struct lu_env *env, struct obd_export *exp,
1364 struct obd_statfs *osfs, __u64 max_age, __u32 flags)
1366 struct obd_device *obd = class_exp2obd(exp);
1367 struct lmv_obd *lmv = &obd->u.lmv;
1368 struct obd_statfs *temp;
1373 OBD_ALLOC(temp, sizeof(*temp));
1377 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1378 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1381 rc = obd_statfs(env, lmv->tgts[i]->ltd_exp, temp,
1384 CERROR("can't stat MDS #%d (%s), error %d\n", i,
1385 lmv->tgts[i]->ltd_exp->exp_obd->obd_name,
1387 GOTO(out_free_temp, rc);
1392 /* If the statfs is from mount, it will needs
1393 * retrieve necessary information from MDT0.
1394 * i.e. mount does not need the merged osfs
1396 * And also clients can be mounted as long as
1397 * MDT0 is in service*/
1398 if (flags & OBD_STATFS_FOR_MDT0)
1399 GOTO(out_free_temp, rc);
1401 osfs->os_bavail += temp->os_bavail;
1402 osfs->os_blocks += temp->os_blocks;
1403 osfs->os_ffree += temp->os_ffree;
1404 osfs->os_files += temp->os_files;
1410 OBD_FREE(temp, sizeof(*temp));
1414 static int lmv_get_root(struct obd_export *exp, const char *fileset,
1417 struct obd_device *obd = exp->exp_obd;
1418 struct lmv_obd *lmv = &obd->u.lmv;
1422 rc = md_get_root(lmv->tgts[0]->ltd_exp, fileset, fid);
1426 static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1427 u64 valid, const char *name,
1428 const char *input, int input_size, int output_size,
1429 int flags, struct ptlrpc_request **request)
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, valid, name, input,
1442 input_size, output_size, flags, request);
1447 static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1448 u64 valid, const char *name,
1449 const char *input, int input_size, int output_size,
1450 int flags, __u32 suppgid,
1451 struct ptlrpc_request **request)
1453 struct obd_device *obd = exp->exp_obd;
1454 struct lmv_obd *lmv = &obd->u.lmv;
1455 struct lmv_tgt_desc *tgt;
1459 tgt = lmv_find_target(lmv, fid);
1461 RETURN(PTR_ERR(tgt));
1463 rc = md_setxattr(tgt->ltd_exp, fid, valid, name, input,
1464 input_size, output_size, flags, suppgid,
1470 static int lmv_getattr(struct obd_export *exp, struct md_op_data *op_data,
1471 struct ptlrpc_request **request)
1473 struct obd_device *obd = exp->exp_obd;
1474 struct lmv_obd *lmv = &obd->u.lmv;
1475 struct lmv_tgt_desc *tgt;
1479 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1481 RETURN(PTR_ERR(tgt));
1483 if (op_data->op_flags & MF_GET_MDT_IDX) {
1484 op_data->op_mds = tgt->ltd_idx;
1488 rc = md_getattr(tgt->ltd_exp, op_data, request);
1493 static int lmv_null_inode(struct obd_export *exp, const struct lu_fid *fid)
1495 struct obd_device *obd = exp->exp_obd;
1496 struct lmv_obd *lmv = &obd->u.lmv;
1500 CDEBUG(D_INODE, "CBDATA for "DFID"\n", PFID(fid));
1503 * With DNE every object can have two locks in different namespaces:
1504 * lookup lock in space of MDT storing direntry and update/open lock in
1505 * space of MDT storing inode.
1507 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1508 if (lmv->tgts[i] == NULL || lmv->tgts[i]->ltd_exp == NULL)
1510 md_null_inode(lmv->tgts[i]->ltd_exp, fid);
1516 static int lmv_close(struct obd_export *exp, struct md_op_data *op_data,
1517 struct md_open_data *mod, struct ptlrpc_request **request)
1519 struct obd_device *obd = exp->exp_obd;
1520 struct lmv_obd *lmv = &obd->u.lmv;
1521 struct lmv_tgt_desc *tgt;
1525 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1527 RETURN(PTR_ERR(tgt));
1529 CDEBUG(D_INODE, "CLOSE "DFID"\n", PFID(&op_data->op_fid1));
1530 rc = md_close(tgt->ltd_exp, op_data, mod, request);
1535 * Choosing the MDT by name or FID in @op_data.
1536 * For non-striped directory, it will locate MDT by fid.
1537 * For striped-directory, it will locate MDT by name. And also
1538 * it will reset op_fid1 with the FID of the choosen stripe.
1540 struct lmv_tgt_desc *
1541 lmv_locate_target_for_name(struct lmv_obd *lmv, struct lmv_stripe_md *lsm,
1542 const char *name, int namelen, struct lu_fid *fid,
1545 struct lmv_tgt_desc *tgt;
1546 const struct lmv_oinfo *oinfo;
1548 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_NAME_HASH)) {
1549 if (cfs_fail_val >= lsm->lsm_md_stripe_count)
1550 RETURN(ERR_PTR(-EBADF));
1551 oinfo = &lsm->lsm_md_oinfo[cfs_fail_val];
1553 oinfo = lsm_name_to_stripe_info(lsm, name, namelen);
1555 RETURN(ERR_CAST(oinfo));
1559 *fid = oinfo->lmo_fid;
1561 *mds = oinfo->lmo_mds;
1563 tgt = lmv_get_target(lmv, oinfo->lmo_mds, NULL);
1565 CDEBUG(D_INFO, "locate on mds %u "DFID"\n", oinfo->lmo_mds,
1566 PFID(&oinfo->lmo_fid));
1571 * Locate mds by fid or name
1573 * For striped directory (lsm != NULL), it will locate the stripe
1574 * by name hash (see lsm_name_to_stripe_info()). Note: if the hash_type
1575 * is unknown, it will return -EBADFD, and lmv_intent_lookup might need
1576 * walk through all of stripes to locate the entry.
1578 * For normal direcotry, it will locate MDS by FID directly.
1579 * \param[in] lmv LMV device
1580 * \param[in] op_data client MD stack parameters, name, namelen
1582 * \param[in] fid object FID used to locate MDS.
1584 * retval pointer to the lmv_tgt_desc if succeed.
1585 * ERR_PTR(errno) if failed.
1587 struct lmv_tgt_desc*
1588 lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
1591 struct lmv_stripe_md *lsm = op_data->op_mea1;
1592 struct lmv_tgt_desc *tgt;
1594 /* During creating VOLATILE file, it should honor the mdt
1595 * index if the file under striped dir is being restored, see
1597 if (op_data->op_bias & MDS_CREATE_VOLATILE &&
1598 (int)op_data->op_mds != -1) {
1600 tgt = lmv_get_target(lmv, op_data->op_mds, NULL);
1605 /* refill the right parent fid */
1606 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1607 struct lmv_oinfo *oinfo;
1609 oinfo = &lsm->lsm_md_oinfo[i];
1610 if (oinfo->lmo_mds == op_data->op_mds) {
1611 *fid = oinfo->lmo_fid;
1616 if (i == lsm->lsm_md_stripe_count)
1617 *fid = lsm->lsm_md_oinfo[0].lmo_fid;
1623 if (lsm == NULL || op_data->op_namelen == 0) {
1624 tgt = lmv_find_target(lmv, fid);
1628 op_data->op_mds = tgt->ltd_idx;
1632 return lmv_locate_target_for_name(lmv, lsm, op_data->op_name,
1633 op_data->op_namelen, fid,
1637 int lmv_create(struct obd_export *exp, struct md_op_data *op_data,
1638 const void *data, size_t datalen, umode_t mode, uid_t uid,
1639 gid_t gid, cfs_cap_t cap_effective, __u64 rdev,
1640 struct ptlrpc_request **request)
1642 struct obd_device *obd = exp->exp_obd;
1643 struct lmv_obd *lmv = &obd->u.lmv;
1644 struct lmv_tgt_desc *tgt;
1648 if (!lmv->desc.ld_active_tgt_count)
1651 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1653 RETURN(PTR_ERR(tgt));
1655 CDEBUG(D_INODE, "CREATE name '%.*s' on "DFID" -> mds #%x\n",
1656 (int)op_data->op_namelen, op_data->op_name,
1657 PFID(&op_data->op_fid1), op_data->op_mds);
1659 rc = lmv_fid_alloc(NULL, exp, &op_data->op_fid2, op_data);
1662 if (exp_connect_flags(exp) & OBD_CONNECT_DIR_STRIPE) {
1663 /* Send the create request to the MDT where the object
1664 * will be located */
1665 tgt = lmv_find_target(lmv, &op_data->op_fid2);
1667 RETURN(PTR_ERR(tgt));
1669 op_data->op_mds = tgt->ltd_idx;
1671 CDEBUG(D_CONFIG, "Server doesn't support striped dirs\n");
1674 CDEBUG(D_INODE, "CREATE obj "DFID" -> mds #%x\n",
1675 PFID(&op_data->op_fid2), op_data->op_mds);
1677 op_data->op_flags |= MF_MDC_CANCEL_FID1;
1678 rc = md_create(tgt->ltd_exp, op_data, data, datalen, mode, uid, gid,
1679 cap_effective, rdev, request);
1681 if (*request == NULL)
1683 CDEBUG(D_INODE, "Created - "DFID"\n", PFID(&op_data->op_fid2));
1689 lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1690 const union ldlm_policy_data *policy, struct md_op_data *op_data,
1691 struct lustre_handle *lockh, __u64 extra_lock_flags)
1693 struct obd_device *obd = exp->exp_obd;
1694 struct lmv_obd *lmv = &obd->u.lmv;
1695 struct lmv_tgt_desc *tgt;
1699 CDEBUG(D_INODE, "ENQUEUE on "DFID"\n", PFID(&op_data->op_fid1));
1701 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1703 RETURN(PTR_ERR(tgt));
1705 CDEBUG(D_INODE, "ENQUEUE on "DFID" -> mds #%u\n",
1706 PFID(&op_data->op_fid1), tgt->ltd_idx);
1708 rc = md_enqueue(tgt->ltd_exp, einfo, policy, op_data, lockh,
1715 lmv_getattr_name(struct obd_export *exp,struct md_op_data *op_data,
1716 struct ptlrpc_request **preq)
1718 struct ptlrpc_request *req = NULL;
1719 struct obd_device *obd = exp->exp_obd;
1720 struct lmv_obd *lmv = &obd->u.lmv;
1721 struct lmv_tgt_desc *tgt;
1722 struct mdt_body *body;
1726 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
1728 RETURN(PTR_ERR(tgt));
1730 CDEBUG(D_INODE, "GETATTR_NAME for %*s on "DFID" -> mds #%d\n",
1731 (int)op_data->op_namelen, op_data->op_name,
1732 PFID(&op_data->op_fid1), tgt->ltd_idx);
1734 rc = md_getattr_name(tgt->ltd_exp, op_data, preq);
1738 body = req_capsule_server_get(&(*preq)->rq_pill, &RMF_MDT_BODY);
1739 LASSERT(body != NULL);
1741 if (body->mbo_valid & OBD_MD_MDS) {
1742 struct lu_fid rid = body->mbo_fid1;
1743 CDEBUG(D_INODE, "Request attrs for "DFID"\n",
1746 tgt = lmv_find_target(lmv, &rid);
1748 ptlrpc_req_finished(*preq);
1750 RETURN(PTR_ERR(tgt));
1753 op_data->op_fid1 = rid;
1754 op_data->op_valid |= OBD_MD_FLCROSSREF;
1755 op_data->op_namelen = 0;
1756 op_data->op_name = NULL;
1757 rc = md_getattr_name(tgt->ltd_exp, op_data, &req);
1758 ptlrpc_req_finished(*preq);
1765 #define md_op_data_fid(op_data, fl) \
1766 (fl == MF_MDC_CANCEL_FID1 ? &op_data->op_fid1 : \
1767 fl == MF_MDC_CANCEL_FID2 ? &op_data->op_fid2 : \
1768 fl == MF_MDC_CANCEL_FID3 ? &op_data->op_fid3 : \
1769 fl == MF_MDC_CANCEL_FID4 ? &op_data->op_fid4 : \
1772 static int lmv_early_cancel(struct obd_export *exp, struct lmv_tgt_desc *tgt,
1773 struct md_op_data *op_data, __u32 op_tgt,
1774 enum ldlm_mode mode, int bits, int flag)
1776 struct lu_fid *fid = md_op_data_fid(op_data, flag);
1777 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
1778 union ldlm_policy_data policy = { { 0 } };
1782 if (!fid_is_sane(fid))
1786 tgt = lmv_find_target(lmv, fid);
1788 RETURN(PTR_ERR(tgt));
1791 if (tgt->ltd_idx != op_tgt) {
1792 CDEBUG(D_INODE, "EARLY_CANCEL on "DFID"\n", PFID(fid));
1793 policy.l_inodebits.bits = bits;
1794 rc = md_cancel_unused(tgt->ltd_exp, fid, &policy,
1795 mode, LCF_ASYNC, NULL);
1798 "EARLY_CANCEL skip operation target %d on "DFID"\n",
1800 op_data->op_flags |= flag;
1808 * llite passes fid of an target inode in op_data->op_fid1 and id of directory in
1811 static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
1812 struct ptlrpc_request **request)
1814 struct obd_device *obd = exp->exp_obd;
1815 struct lmv_obd *lmv = &obd->u.lmv;
1816 struct lmv_tgt_desc *tgt;
1820 LASSERT(op_data->op_namelen != 0);
1822 CDEBUG(D_INODE, "LINK "DFID":%*s to "DFID"\n",
1823 PFID(&op_data->op_fid2), (int)op_data->op_namelen,
1824 op_data->op_name, PFID(&op_data->op_fid1));
1826 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
1827 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
1828 op_data->op_cap = cfs_curproc_cap_pack();
1829 if (op_data->op_mea2 != NULL) {
1830 struct lmv_stripe_md *lsm = op_data->op_mea2;
1831 const struct lmv_oinfo *oinfo;
1833 oinfo = lsm_name_to_stripe_info(lsm, op_data->op_name,
1834 op_data->op_namelen);
1836 RETURN(PTR_ERR(oinfo));
1838 op_data->op_fid2 = oinfo->lmo_fid;
1841 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
1843 RETURN(PTR_ERR(tgt));
1846 * Cancel UPDATE lock on child (fid1).
1848 op_data->op_flags |= MF_MDC_CANCEL_FID2;
1849 rc = lmv_early_cancel(exp, NULL, op_data, tgt->ltd_idx, LCK_EX,
1850 MDS_INODELOCK_UPDATE, MF_MDC_CANCEL_FID1);
1854 rc = md_link(tgt->ltd_exp, op_data, request);
1859 static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
1860 const char *old, size_t oldlen,
1861 const char *new, size_t newlen,
1862 struct ptlrpc_request **request)
1864 struct obd_device *obd = exp->exp_obd;
1865 struct lmv_obd *lmv = &obd->u.lmv;
1866 struct lmv_tgt_desc *src_tgt;
1867 struct lmv_tgt_desc *tgt_tgt;
1868 struct obd_export *target_exp;
1869 struct mdt_body *body;
1873 LASSERT(oldlen != 0);
1875 CDEBUG(D_INODE, "RENAME %.*s in "DFID":%d to %.*s in "DFID":%d\n",
1876 (int)oldlen, old, PFID(&op_data->op_fid1),
1877 op_data->op_mea1 ? op_data->op_mea1->lsm_md_stripe_count : 0,
1878 (int)newlen, new, PFID(&op_data->op_fid2),
1879 op_data->op_mea2 ? op_data->op_mea2->lsm_md_stripe_count : 0);
1881 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
1882 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
1883 op_data->op_cap = cfs_curproc_cap_pack();
1884 if (op_data->op_cli_flags & CLI_MIGRATE) {
1885 LASSERTF(fid_is_sane(&op_data->op_fid3), "invalid FID "DFID"\n",
1886 PFID(&op_data->op_fid3));
1888 if (op_data->op_mea1 != NULL) {
1889 struct lmv_stripe_md *lsm = op_data->op_mea1;
1890 struct lmv_tgt_desc *tmp;
1892 /* Fix the parent fid for striped dir */
1893 tmp = lmv_locate_target_for_name(lmv, lsm, old,
1898 RETURN(PTR_ERR(tmp));
1901 rc = lmv_fid_alloc(NULL, exp, &op_data->op_fid2, op_data);
1905 src_tgt = lmv_find_target(lmv, &op_data->op_fid3);
1906 if (IS_ERR(src_tgt))
1907 RETURN(PTR_ERR(src_tgt));
1909 target_exp = src_tgt->ltd_exp;
1911 if (op_data->op_mea1 != NULL) {
1912 struct lmv_stripe_md *lsm = op_data->op_mea1;
1914 src_tgt = lmv_locate_target_for_name(lmv, lsm, old,
1919 src_tgt = lmv_find_target(lmv, &op_data->op_fid1);
1921 if (IS_ERR(src_tgt))
1922 RETURN(PTR_ERR(src_tgt));
1925 if (op_data->op_mea2 != NULL) {
1926 struct lmv_stripe_md *lsm = op_data->op_mea2;
1928 tgt_tgt = lmv_locate_target_for_name(lmv, lsm, new,
1933 tgt_tgt = lmv_find_target(lmv, &op_data->op_fid2);
1936 if (IS_ERR(tgt_tgt))
1937 RETURN(PTR_ERR(tgt_tgt));
1939 target_exp = tgt_tgt->ltd_exp;
1943 * LOOKUP lock on src child (fid3) should also be cancelled for
1944 * src_tgt in mdc_rename.
1946 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
1949 * Cancel UPDATE locks on tgt parent (fid2), tgt_tgt is its
1952 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
1953 LCK_EX, MDS_INODELOCK_UPDATE,
1954 MF_MDC_CANCEL_FID2);
1959 * Cancel LOOKUP locks on source child (fid3) for parent tgt_tgt.
1961 if (fid_is_sane(&op_data->op_fid3)) {
1962 struct lmv_tgt_desc *tgt;
1964 tgt = lmv_find_target(lmv, &op_data->op_fid1);
1966 RETURN(PTR_ERR(tgt));
1968 /* Cancel LOOKUP lock on its parent */
1969 rc = lmv_early_cancel(exp, tgt, op_data, src_tgt->ltd_idx,
1970 LCK_EX, MDS_INODELOCK_LOOKUP,
1971 MF_MDC_CANCEL_FID3);
1975 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
1976 LCK_EX, MDS_INODELOCK_ELC,
1977 MF_MDC_CANCEL_FID3);
1984 * Cancel all the locks on tgt child (fid4).
1986 if (fid_is_sane(&op_data->op_fid4)) {
1987 struct lmv_tgt_desc *tgt;
1989 rc = lmv_early_cancel(exp, NULL, op_data, src_tgt->ltd_idx,
1990 LCK_EX, MDS_INODELOCK_ELC,
1991 MF_MDC_CANCEL_FID4);
1995 tgt = lmv_find_target(lmv, &op_data->op_fid4);
1997 RETURN(PTR_ERR(tgt));
1999 /* Since the target child might be destroyed, and it might
2000 * become orphan, and we can only check orphan on the local
2001 * MDT right now, so we send rename request to the MDT where
2002 * target child is located. If target child does not exist,
2003 * then it will send the request to the target parent */
2004 target_exp = tgt->ltd_exp;
2007 rc = md_rename(target_exp, op_data, old, oldlen, new, newlen,
2010 if (rc != 0 && rc != -EXDEV)
2013 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
2017 /* Not cross-ref case, just get out of here. */
2018 if (likely(!(body->mbo_valid & OBD_MD_MDS)))
2021 CDEBUG(D_INODE, "%s: try rename to another MDT for "DFID"\n",
2022 exp->exp_obd->obd_name, PFID(&body->mbo_fid1));
2024 op_data->op_fid4 = body->mbo_fid1;
2025 ptlrpc_req_finished(*request);
2030 static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
2031 void *ea, size_t ealen, struct ptlrpc_request **request)
2033 struct obd_device *obd = exp->exp_obd;
2034 struct lmv_obd *lmv = &obd->u.lmv;
2035 struct lmv_tgt_desc *tgt;
2039 CDEBUG(D_INODE, "SETATTR for "DFID", valid 0x%x\n",
2040 PFID(&op_data->op_fid1), op_data->op_attr.ia_valid);
2042 op_data->op_flags |= MF_MDC_CANCEL_FID1;
2043 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2045 RETURN(PTR_ERR(tgt));
2047 rc = md_setattr(tgt->ltd_exp, op_data, ea, ealen, request);
2052 static int lmv_fsync(struct obd_export *exp, const struct lu_fid *fid,
2053 struct ptlrpc_request **request)
2055 struct obd_device *obd = exp->exp_obd;
2056 struct lmv_obd *lmv = &obd->u.lmv;
2057 struct lmv_tgt_desc *tgt;
2061 tgt = lmv_find_target(lmv, fid);
2063 RETURN(PTR_ERR(tgt));
2065 rc = md_fsync(tgt->ltd_exp, fid, request);
2069 struct stripe_dirent {
2070 struct page *sd_page;
2071 struct lu_dirpage *sd_dp;
2072 struct lu_dirent *sd_ent;
2076 struct lmv_dir_ctxt {
2077 struct lmv_obd *ldc_lmv;
2078 struct md_op_data *ldc_op_data;
2079 struct md_callback *ldc_cb_op;
2082 struct stripe_dirent ldc_stripes[0];
2085 static inline void put_stripe_dirent(struct stripe_dirent *stripe)
2087 if (stripe->sd_page) {
2088 kunmap(stripe->sd_page);
2089 put_page(stripe->sd_page);
2090 stripe->sd_page = NULL;
2091 stripe->sd_ent = NULL;
2095 static inline void put_lmv_dir_ctxt(struct lmv_dir_ctxt *ctxt)
2099 for (i = 0; i < ctxt->ldc_count; i++)
2100 put_stripe_dirent(&ctxt->ldc_stripes[i]);
2103 static struct lu_dirent *stripe_dirent_next(struct lmv_dir_ctxt *ctxt,
2104 struct stripe_dirent *stripe,
2107 struct lu_dirent *ent = stripe->sd_ent;
2108 __u64 hash = ctxt->ldc_hash;
2113 LASSERT(stripe == &ctxt->ldc_stripes[stripe_index]);
2119 ent = lu_dirent_next(ent);
2122 end = le64_to_cpu(stripe->sd_dp->ldp_hash_end);
2123 LASSERTF(hash <= end, "hash %llx end %llx\n",
2125 if (end == MDS_DIR_END_OFF) {
2126 stripe->sd_ent = NULL;
2127 stripe->sd_eof = true;
2131 put_stripe_dirent(stripe);
2137 struct md_op_data *op_data = ctxt->ldc_op_data;
2138 struct lmv_oinfo *oinfo;
2139 struct lu_fid fid = op_data->op_fid1;
2140 struct inode *inode = op_data->op_data;
2141 struct lmv_tgt_desc *tgt;
2143 LASSERT(!stripe->sd_page);
2145 oinfo = &op_data->op_mea1->lsm_md_oinfo[stripe_index];
2146 tgt = lmv_get_target(ctxt->ldc_lmv, oinfo->lmo_mds, NULL);
2148 GOTO(out, rc = PTR_ERR(tgt));
2150 /* op_data will be shared by each stripe, so we need
2151 * reset these value for each stripe */
2152 op_data->op_fid1 = oinfo->lmo_fid;
2153 op_data->op_fid2 = oinfo->lmo_fid;
2154 op_data->op_data = oinfo->lmo_root;
2156 rc = md_read_page(tgt->ltd_exp, op_data, ctxt->ldc_cb_op, hash,
2159 op_data->op_fid1 = fid;
2160 op_data->op_fid2 = fid;
2161 op_data->op_data = inode;
2166 stripe->sd_dp = page_address(stripe->sd_page);
2167 ent = lu_dirent_start(stripe->sd_dp);
2170 for (; ent; ent = lu_dirent_next(ent)) {
2171 /* Skip dummy entry */
2172 if (le16_to_cpu(ent->lde_namelen) == 0)
2175 /* skip . and .. for other stripes */
2177 (strncmp(ent->lde_name, ".",
2178 le16_to_cpu(ent->lde_namelen)) == 0 ||
2179 strncmp(ent->lde_name, "..",
2180 le16_to_cpu(ent->lde_namelen)) == 0))
2183 if (le64_to_cpu(ent->lde_hash) >= hash)
2192 stripe->sd_ent = ent;
2193 /* treat error as eof, so dir can be partially accessed */
2195 put_stripe_dirent(stripe);
2196 stripe->sd_eof = true;
2197 LCONSOLE_WARN("dir "DFID" stripe %d readdir failed: %d, "
2198 "directory is partially accessed!\n",
2199 PFID(&ctxt->ldc_op_data->op_fid1), stripe_index,
2205 static int lmv_file_resync(struct obd_export *exp, struct md_op_data *data)
2207 struct obd_device *obd = exp->exp_obd;
2208 struct lmv_obd *lmv = &obd->u.lmv;
2209 struct lmv_tgt_desc *tgt;
2213 rc = lmv_check_connect(obd);
2217 tgt = lmv_find_target(lmv, &data->op_fid1);
2219 RETURN(PTR_ERR(tgt));
2221 data->op_flags |= MF_MDC_CANCEL_FID1;
2222 rc = md_file_resync(tgt->ltd_exp, data);
2227 * Get dirent with the closest hash for striped directory
2229 * This function will search the dir entry, whose hash value is the
2230 * closest(>=) to hash from all of sub-stripes, and it is only being called
2231 * for striped directory.
2233 * \param[in] ctxt dir read context
2235 * \retval dirent get the entry successfully
2236 * NULL does not get the entry, normally it means
2237 * it reaches the end of the directory, while read
2238 * stripe dirent error is ignored to allow partial
2241 static struct lu_dirent *lmv_dirent_next(struct lmv_dir_ctxt *ctxt)
2243 struct stripe_dirent *stripe;
2244 struct lu_dirent *ent = NULL;
2248 /* TODO: optimize with k-way merge sort */
2249 for (i = 0; i < ctxt->ldc_count; i++) {
2250 stripe = &ctxt->ldc_stripes[i];
2254 if (!stripe->sd_ent) {
2255 /* locate starting entry */
2256 stripe_dirent_next(ctxt, stripe, i);
2257 if (!stripe->sd_ent) {
2258 LASSERT(stripe->sd_eof);
2264 le64_to_cpu(ctxt->ldc_stripes[min].sd_ent->lde_hash) >
2265 le64_to_cpu(stripe->sd_ent->lde_hash)) {
2267 if (le64_to_cpu(stripe->sd_ent->lde_hash) ==
2274 stripe = &ctxt->ldc_stripes[min];
2275 ent = stripe->sd_ent;
2276 /* pop found dirent */
2277 stripe_dirent_next(ctxt, stripe, min);
2284 * Build dir entry page for striped directory
2286 * This function gets one entry by @offset from a striped directory. It will
2287 * read entries from all of stripes, and choose one closest to the required
2288 * offset(&offset). A few notes
2289 * 1. skip . and .. for non-zero stripes, because there can only have one .
2290 * and .. in a directory.
2291 * 2. op_data will be shared by all of stripes, instead of allocating new
2292 * one, so need to restore before reusing.
2294 * \param[in] exp obd export refer to LMV
2295 * \param[in] op_data hold those MD parameters of read_entry
2296 * \param[in] cb_op ldlm callback being used in enqueue in mdc_read_entry
2297 * \param[in] offset starting hash offset
2298 * \param[out] ppage the page holding the entry. Note: because the entry
2299 * will be accessed in upper layer, so we need hold the
2300 * page until the usages of entry is finished, see
2301 * ll_dir_entry_next.
2303 * retval =0 if get entry successfully
2304 * <0 cannot get entry
2306 static int lmv_striped_read_page(struct obd_export *exp,
2307 struct md_op_data *op_data,
2308 struct md_callback *cb_op,
2309 __u64 offset, struct page **ppage)
2311 struct page *page = NULL;
2312 struct lu_dirpage *dp;
2314 struct lu_dirent *ent;
2315 struct lu_dirent *last_ent;
2317 struct lmv_dir_ctxt *ctxt;
2318 struct lu_dirent *next = NULL;
2324 /* Allocate a page and read entries from all of stripes and fill
2325 * the page by hash order */
2326 page = alloc_page(GFP_KERNEL);
2330 /* Initialize the entry page */
2332 memset(dp, 0, sizeof(*dp));
2333 dp->ldp_hash_start = cpu_to_le64(offset);
2336 left_bytes = PAGE_SIZE - sizeof(*dp);
2340 /* initalize dir read context */
2341 stripe_count = op_data->op_mea1->lsm_md_stripe_count;
2342 OBD_ALLOC(ctxt, offsetof(typeof(*ctxt), ldc_stripes[stripe_count]));
2344 GOTO(free_page, rc = -ENOMEM);
2345 ctxt->ldc_lmv = &exp->exp_obd->u.lmv;
2346 ctxt->ldc_op_data = op_data;
2347 ctxt->ldc_cb_op = cb_op;
2348 ctxt->ldc_hash = offset;
2349 ctxt->ldc_count = stripe_count;
2352 next = lmv_dirent_next(ctxt);
2354 /* end of directory */
2356 ctxt->ldc_hash = MDS_DIR_END_OFF;
2359 ctxt->ldc_hash = le64_to_cpu(next->lde_hash);
2361 ent_size = le16_to_cpu(next->lde_reclen);
2363 /* the last entry lde_reclen is 0, but it might not be the last
2364 * one of this temporay dir page */
2366 ent_size = lu_dirent_calc_size(
2367 le16_to_cpu(next->lde_namelen),
2368 le32_to_cpu(next->lde_attrs));
2370 if (ent_size > left_bytes)
2373 memcpy(ent, next, ent_size);
2375 /* Replace . with master FID and Replace .. with the parent FID
2376 * of master object */
2377 if (strncmp(ent->lde_name, ".",
2378 le16_to_cpu(ent->lde_namelen)) == 0 &&
2379 le16_to_cpu(ent->lde_namelen) == 1)
2380 fid_cpu_to_le(&ent->lde_fid, &op_data->op_fid1);
2381 else if (strncmp(ent->lde_name, "..",
2382 le16_to_cpu(ent->lde_namelen)) == 0 &&
2383 le16_to_cpu(ent->lde_namelen) == 2)
2384 fid_cpu_to_le(&ent->lde_fid, &op_data->op_fid3);
2386 CDEBUG(D_INODE, "entry %.*s hash %#llx\n",
2387 le16_to_cpu(ent->lde_namelen), ent->lde_name,
2388 le64_to_cpu(ent->lde_hash));
2390 left_bytes -= ent_size;
2391 ent->lde_reclen = cpu_to_le16(ent_size);
2393 ent = (void *)ent + ent_size;
2396 last_ent->lde_reclen = 0;
2399 dp->ldp_flags |= LDF_EMPTY;
2400 else if (ctxt->ldc_hash == le64_to_cpu(last_ent->lde_hash))
2401 dp->ldp_flags |= LDF_COLLIDE;
2402 dp->ldp_flags = cpu_to_le32(dp->ldp_flags);
2403 dp->ldp_hash_end = cpu_to_le64(ctxt->ldc_hash);
2405 put_lmv_dir_ctxt(ctxt);
2406 OBD_FREE(ctxt, offsetof(typeof(*ctxt), ldc_stripes[stripe_count]));
2419 int lmv_read_page(struct obd_export *exp, struct md_op_data *op_data,
2420 struct md_callback *cb_op, __u64 offset,
2421 struct page **ppage)
2423 struct obd_device *obd = exp->exp_obd;
2424 struct lmv_obd *lmv = &obd->u.lmv;
2425 struct lmv_stripe_md *lsm = op_data->op_mea1;
2426 struct lmv_tgt_desc *tgt;
2430 if (unlikely(lsm != NULL)) {
2431 rc = lmv_striped_read_page(exp, op_data, cb_op, offset, ppage);
2435 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2437 RETURN(PTR_ERR(tgt));
2439 rc = md_read_page(tgt->ltd_exp, op_data, cb_op, offset, ppage);
2445 * Unlink a file/directory
2447 * Unlink a file or directory under the parent dir. The unlink request
2448 * usually will be sent to the MDT where the child is located, but if
2449 * the client does not have the child FID then request will be sent to the
2450 * MDT where the parent is located.
2452 * If the parent is a striped directory then it also needs to locate which
2453 * stripe the name of the child is located, and replace the parent FID
2454 * (@op->op_fid1) with the stripe FID. Note: if the stripe is unknown,
2455 * it will walk through all of sub-stripes until the child is being
2458 * \param[in] exp export refer to LMV
2459 * \param[in] op_data different parameters transferred beween client
2460 * MD stacks, name, namelen, FIDs etc.
2461 * op_fid1 is the parent FID, op_fid2 is the child
2463 * \param[out] request point to the request of unlink.
2465 * retval 0 if succeed
2466 * negative errno if failed.
2468 static int lmv_unlink(struct obd_export *exp, struct md_op_data *op_data,
2469 struct ptlrpc_request **request)
2471 struct obd_device *obd = exp->exp_obd;
2472 struct lmv_obd *lmv = &obd->u.lmv;
2473 struct lmv_tgt_desc *tgt = NULL;
2474 struct lmv_tgt_desc *parent_tgt = NULL;
2475 struct mdt_body *body;
2477 int stripe_index = 0;
2478 struct lmv_stripe_md *lsm = op_data->op_mea1;
2482 /* For striped dir, we need to locate the parent as well */
2484 struct lmv_tgt_desc *tmp;
2486 LASSERT(op_data->op_name != NULL &&
2487 op_data->op_namelen != 0);
2489 tmp = lmv_locate_target_for_name(lmv, lsm,
2491 op_data->op_namelen,
2495 /* return -EBADFD means unknown hash type, might
2496 * need try all sub-stripe here */
2497 if (IS_ERR(tmp) && PTR_ERR(tmp) != -EBADFD)
2498 RETURN(PTR_ERR(tmp));
2500 /* Note: both migrating dir and unknown hash dir need to
2501 * try all of sub-stripes, so we need start search the
2502 * name from stripe 0, but migrating dir is already handled
2503 * inside lmv_locate_target_for_name(), so we only check
2504 * unknown hash type directory here */
2505 if (!lmv_is_known_hash_type(lsm->lsm_md_hash_type)) {
2506 struct lmv_oinfo *oinfo;
2508 oinfo = &lsm->lsm_md_oinfo[stripe_index];
2510 op_data->op_fid1 = oinfo->lmo_fid;
2511 op_data->op_mds = oinfo->lmo_mds;
2516 /* Send unlink requests to the MDT where the child is located */
2517 if (likely(!fid_is_zero(&op_data->op_fid2)))
2518 tgt = lmv_find_target(lmv, &op_data->op_fid2);
2519 else if (lsm != NULL)
2520 tgt = lmv_get_target(lmv, op_data->op_mds, NULL);
2522 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
2525 RETURN(PTR_ERR(tgt));
2527 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
2528 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
2529 op_data->op_cap = cfs_curproc_cap_pack();
2532 * If child's fid is given, cancel unused locks for it if it is from
2533 * another export than parent.
2535 * LOOKUP lock for child (fid3) should also be cancelled on parent
2536 * tgt_tgt in mdc_unlink().
2538 op_data->op_flags |= MF_MDC_CANCEL_FID1 | MF_MDC_CANCEL_FID3;
2541 * Cancel FULL locks on child (fid3).
2543 parent_tgt = lmv_find_target(lmv, &op_data->op_fid1);
2544 if (IS_ERR(parent_tgt))
2545 RETURN(PTR_ERR(parent_tgt));
2547 if (parent_tgt != tgt) {
2548 rc = lmv_early_cancel(exp, parent_tgt, op_data, tgt->ltd_idx,
2549 LCK_EX, MDS_INODELOCK_LOOKUP,
2550 MF_MDC_CANCEL_FID3);
2553 rc = lmv_early_cancel(exp, NULL, op_data, tgt->ltd_idx, LCK_EX,
2554 MDS_INODELOCK_ELC, MF_MDC_CANCEL_FID3);
2558 CDEBUG(D_INODE, "unlink with fid="DFID"/"DFID" -> mds #%u\n",
2559 PFID(&op_data->op_fid1), PFID(&op_data->op_fid2), tgt->ltd_idx);
2561 rc = md_unlink(tgt->ltd_exp, op_data, request);
2562 if (rc != 0 && rc != -EREMOTE && rc != -ENOENT)
2565 /* Try next stripe if it is needed. */
2566 if (rc == -ENOENT && lsm != NULL && lmv_need_try_all_stripes(lsm)) {
2567 struct lmv_oinfo *oinfo;
2570 if (stripe_index >= lsm->lsm_md_stripe_count)
2573 oinfo = &lsm->lsm_md_oinfo[stripe_index];
2575 op_data->op_fid1 = oinfo->lmo_fid;
2576 op_data->op_mds = oinfo->lmo_mds;
2578 ptlrpc_req_finished(*request);
2581 goto try_next_stripe;
2584 body = req_capsule_server_get(&(*request)->rq_pill, &RMF_MDT_BODY);
2588 /* Not cross-ref case, just get out of here. */
2589 if (likely(!(body->mbo_valid & OBD_MD_MDS)))
2592 CDEBUG(D_INODE, "%s: try unlink to another MDT for "DFID"\n",
2593 exp->exp_obd->obd_name, PFID(&body->mbo_fid1));
2595 /* This is a remote object, try remote MDT, Note: it may
2596 * try more than 1 time here, Considering following case
2597 * /mnt/lustre is root on MDT0, remote1 is on MDT1
2598 * 1. Initially A does not know where remote1 is, it send
2599 * unlink RPC to MDT0, MDT0 return -EREMOTE, it will
2600 * resend unlink RPC to MDT1 (retry 1st time).
2602 * 2. During the unlink RPC in flight,
2603 * client B mv /mnt/lustre/remote1 /mnt/lustre/remote2
2604 * and create new remote1, but on MDT0
2606 * 3. MDT1 get unlink RPC(from A), then do remote lock on
2607 * /mnt/lustre, then lookup get fid of remote1, and find
2608 * it is remote dir again, and replay -EREMOTE again.
2610 * 4. Then A will resend unlink RPC to MDT0. (retry 2nd times).
2612 * In theory, it might try unlimited time here, but it should
2613 * be very rare case. */
2614 op_data->op_fid2 = body->mbo_fid1;
2615 ptlrpc_req_finished(*request);
2621 static int lmv_precleanup(struct obd_device *obd)
2624 libcfs_kkuc_group_rem(&obd->obd_uuid, 0, KUC_GRP_HSM);
2625 fld_client_proc_fini(&obd->u.lmv.lmv_fld);
2626 lprocfs_obd_cleanup(obd);
2627 lprocfs_free_md_stats(obd);
2632 * Get by key a value associated with a LMV device.
2634 * Dispatch request to lower-layer devices as needed.
2636 * \param[in] env execution environment for this thread
2637 * \param[in] exp export for the LMV device
2638 * \param[in] keylen length of key identifier
2639 * \param[in] key identifier of key to get value for
2640 * \param[in] vallen size of \a val
2641 * \param[out] val pointer to storage location for value
2642 * \param[in] lsm optional striping metadata of object
2644 * \retval 0 on success
2645 * \retval negative negated errno on failure
2647 static int lmv_get_info(const struct lu_env *env, struct obd_export *exp,
2648 __u32 keylen, void *key, __u32 *vallen, void *val)
2650 struct obd_device *obd;
2651 struct lmv_obd *lmv;
2655 obd = class_exp2obd(exp);
2657 CDEBUG(D_IOCTL, "Invalid client cookie %#llx\n",
2658 exp->exp_handle.h_cookie);
2663 if (keylen >= strlen("remote_flag") && !strcmp(key, "remote_flag")) {
2666 LASSERT(*vallen == sizeof(__u32));
2667 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2668 struct lmv_tgt_desc *tgt = lmv->tgts[i];
2670 * All tgts should be connected when this gets called.
2672 if (tgt == NULL || tgt->ltd_exp == NULL)
2675 if (!obd_get_info(env, tgt->ltd_exp, keylen, key,
2680 } else if (KEY_IS(KEY_MAX_EASIZE) ||
2681 KEY_IS(KEY_DEFAULT_EASIZE) ||
2682 KEY_IS(KEY_CONN_DATA)) {
2684 * Forwarding this request to first MDS, it should know LOV
2687 rc = obd_get_info(env, lmv->tgts[0]->ltd_exp, keylen, key,
2689 if (!rc && KEY_IS(KEY_CONN_DATA))
2690 exp->exp_connect_data = *(struct obd_connect_data *)val;
2692 } else if (KEY_IS(KEY_TGT_COUNT)) {
2693 *((int *)val) = lmv->desc.ld_tgt_count;
2697 CDEBUG(D_IOCTL, "Invalid key\n");
2702 * Asynchronously set by key a value associated with a LMV device.
2704 * Dispatch request to lower-layer devices as needed.
2706 * \param[in] env execution environment for this thread
2707 * \param[in] exp export for the LMV device
2708 * \param[in] keylen length of key identifier
2709 * \param[in] key identifier of key to store value for
2710 * \param[in] vallen size of value to store
2711 * \param[in] val pointer to data to be stored
2712 * \param[in] set optional list of related ptlrpc requests
2714 * \retval 0 on success
2715 * \retval negative negated errno on failure
2717 int lmv_set_info_async(const struct lu_env *env, struct obd_export *exp,
2718 __u32 keylen, void *key, __u32 vallen, void *val,
2719 struct ptlrpc_request_set *set)
2721 struct lmv_tgt_desc *tgt = NULL;
2722 struct obd_device *obd;
2723 struct lmv_obd *lmv;
2727 obd = class_exp2obd(exp);
2729 CDEBUG(D_IOCTL, "Invalid client cookie %#llx\n",
2730 exp->exp_handle.h_cookie);
2735 if (KEY_IS(KEY_READ_ONLY) || KEY_IS(KEY_FLUSH_CTX) ||
2736 KEY_IS(KEY_DEFAULT_EASIZE)) {
2739 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2742 if (tgt == NULL || tgt->ltd_exp == NULL)
2745 err = obd_set_info_async(env, tgt->ltd_exp,
2746 keylen, key, vallen, val, set);
2757 static int lmv_unpack_md_v1(struct obd_export *exp, struct lmv_stripe_md *lsm,
2758 const struct lmv_mds_md_v1 *lmm1)
2760 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2767 lsm->lsm_md_magic = le32_to_cpu(lmm1->lmv_magic);
2768 lsm->lsm_md_stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
2769 lsm->lsm_md_master_mdt_index = le32_to_cpu(lmm1->lmv_master_mdt_index);
2770 if (OBD_FAIL_CHECK(OBD_FAIL_UNKNOWN_LMV_STRIPE))
2771 lsm->lsm_md_hash_type = LMV_HASH_TYPE_UNKNOWN;
2773 lsm->lsm_md_hash_type = le32_to_cpu(lmm1->lmv_hash_type);
2774 lsm->lsm_md_layout_version = le32_to_cpu(lmm1->lmv_layout_version);
2775 cplen = strlcpy(lsm->lsm_md_pool_name, lmm1->lmv_pool_name,
2776 sizeof(lsm->lsm_md_pool_name));
2778 if (cplen >= sizeof(lsm->lsm_md_pool_name))
2781 CDEBUG(D_INFO, "unpack lsm count %d, master %d hash_type %d"
2782 "layout_version %d\n", lsm->lsm_md_stripe_count,
2783 lsm->lsm_md_master_mdt_index, lsm->lsm_md_hash_type,
2784 lsm->lsm_md_layout_version);
2786 stripe_count = le32_to_cpu(lmm1->lmv_stripe_count);
2787 for (i = 0; i < stripe_count; i++) {
2788 fid_le_to_cpu(&lsm->lsm_md_oinfo[i].lmo_fid,
2789 &lmm1->lmv_stripe_fids[i]);
2790 rc = lmv_fld_lookup(lmv, &lsm->lsm_md_oinfo[i].lmo_fid,
2791 &lsm->lsm_md_oinfo[i].lmo_mds);
2794 CDEBUG(D_INFO, "unpack fid #%d "DFID"\n", i,
2795 PFID(&lsm->lsm_md_oinfo[i].lmo_fid));
2801 static int lmv_unpackmd(struct obd_export *exp, struct lmv_stripe_md **lsmp,
2802 const union lmv_mds_md *lmm, size_t lmm_size)
2804 struct lmv_stripe_md *lsm;
2807 bool allocated = false;
2810 LASSERT(lsmp != NULL);
2814 if (lsm != NULL && lmm == NULL) {
2816 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
2817 /* For migrating inode, the master stripe and master
2818 * object will be the same, so do not need iput, see
2819 * ll_update_lsm_md */
2820 if (!(lsm->lsm_md_hash_type & LMV_HASH_FLAG_MIGRATION &&
2821 i == 0) && lsm->lsm_md_oinfo[i].lmo_root != NULL)
2822 iput(lsm->lsm_md_oinfo[i].lmo_root);
2824 lsm_size = lmv_stripe_md_size(lsm->lsm_md_stripe_count);
2825 OBD_FREE(lsm, lsm_size);
2830 if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_STRIPE)
2834 if (le32_to_cpu(lmm->lmv_magic) != LMV_MAGIC_V1 &&
2835 le32_to_cpu(lmm->lmv_magic) != LMV_USER_MAGIC) {
2836 CERROR("%s: invalid lmv magic %x: rc = %d\n",
2837 exp->exp_obd->obd_name, le32_to_cpu(lmm->lmv_magic),
2842 if (le32_to_cpu(lmm->lmv_magic) == LMV_MAGIC_V1)
2843 lsm_size = lmv_stripe_md_size(lmv_mds_md_stripe_count_get(lmm));
2846 * Unpack default dirstripe(lmv_user_md) to lmv_stripe_md,
2847 * stripecount should be 0 then.
2849 lsm_size = lmv_stripe_md_size(0);
2851 lsm_size = lmv_stripe_md_size(lmv_mds_md_stripe_count_get(lmm));
2853 OBD_ALLOC(lsm, lsm_size);
2860 switch (le32_to_cpu(lmm->lmv_magic)) {
2862 rc = lmv_unpack_md_v1(exp, lsm, &lmm->lmv_md_v1);
2865 CERROR("%s: unrecognized magic %x\n", exp->exp_obd->obd_name,
2866 le32_to_cpu(lmm->lmv_magic));
2871 if (rc != 0 && allocated) {
2872 OBD_FREE(lsm, lsm_size);
2879 void lmv_free_memmd(struct lmv_stripe_md *lsm)
2881 lmv_unpackmd(NULL, &lsm, NULL, 0);
2883 EXPORT_SYMBOL(lmv_free_memmd);
2885 static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
2886 union ldlm_policy_data *policy,
2887 enum ldlm_mode mode, enum ldlm_cancel_flags flags,
2890 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2895 LASSERT(fid != NULL);
2897 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2898 struct lmv_tgt_desc *tgt = lmv->tgts[i];
2901 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
2904 err = md_cancel_unused(tgt->ltd_exp, fid, policy, mode, flags,
2912 static int lmv_set_lock_data(struct obd_export *exp,
2913 const struct lustre_handle *lockh,
2914 void *data, __u64 *bits)
2916 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2917 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2921 if (tgt == NULL || tgt->ltd_exp == NULL)
2923 rc = md_set_lock_data(tgt->ltd_exp, lockh, data, bits);
2927 enum ldlm_mode lmv_lock_match(struct obd_export *exp, __u64 flags,
2928 const struct lu_fid *fid, enum ldlm_type type,
2929 union ldlm_policy_data *policy,
2930 enum ldlm_mode mode, struct lustre_handle *lockh)
2932 struct obd_device *obd = exp->exp_obd;
2933 struct lmv_obd *lmv = &obd->u.lmv;
2939 CDEBUG(D_INODE, "Lock match for "DFID"\n", PFID(fid));
2942 * With DNE every object can have two locks in different namespaces:
2943 * lookup lock in space of MDT storing direntry and update/open lock in
2944 * space of MDT storing inode. Try the MDT that the FID maps to first,
2945 * since this can be easily found, and only try others if that fails.
2947 for (i = 0, tgt = lmv_find_target_index(lmv, fid);
2948 i < lmv->desc.ld_tgt_count;
2949 i++, tgt = (tgt + 1) % lmv->desc.ld_tgt_count) {
2951 CDEBUG(D_HA, "%s: "DFID" is inaccessible: rc = %d\n",
2952 obd->obd_name, PFID(fid), tgt);
2956 if (lmv->tgts[tgt] == NULL ||
2957 lmv->tgts[tgt]->ltd_exp == NULL ||
2958 lmv->tgts[tgt]->ltd_active == 0)
2961 rc = md_lock_match(lmv->tgts[tgt]->ltd_exp, flags, fid,
2962 type, policy, mode, lockh);
2970 int lmv_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
2971 struct obd_export *dt_exp, struct obd_export *md_exp,
2972 struct lustre_md *md)
2974 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2975 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2977 if (tgt == NULL || tgt->ltd_exp == NULL)
2980 return md_get_lustre_md(lmv->tgts[0]->ltd_exp, req, dt_exp, md_exp, md);
2983 int lmv_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
2985 struct obd_device *obd = exp->exp_obd;
2986 struct lmv_obd *lmv = &obd->u.lmv;
2987 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2990 if (md->lmv != NULL) {
2991 lmv_free_memmd(md->lmv);
2994 if (tgt == NULL || tgt->ltd_exp == NULL)
2996 RETURN(md_free_lustre_md(lmv->tgts[0]->ltd_exp, md));
2999 int lmv_set_open_replay_data(struct obd_export *exp,
3000 struct obd_client_handle *och,
3001 struct lookup_intent *it)
3003 struct obd_device *obd = exp->exp_obd;
3004 struct lmv_obd *lmv = &obd->u.lmv;
3005 struct lmv_tgt_desc *tgt;
3008 tgt = lmv_find_target(lmv, &och->och_fid);
3010 RETURN(PTR_ERR(tgt));
3012 RETURN(md_set_open_replay_data(tgt->ltd_exp, och, it));
3015 int lmv_clear_open_replay_data(struct obd_export *exp,
3016 struct obd_client_handle *och)
3018 struct obd_device *obd = exp->exp_obd;
3019 struct lmv_obd *lmv = &obd->u.lmv;
3020 struct lmv_tgt_desc *tgt;
3023 tgt = lmv_find_target(lmv, &och->och_fid);
3025 RETURN(PTR_ERR(tgt));
3027 RETURN(md_clear_open_replay_data(tgt->ltd_exp, och));
3030 int lmv_intent_getattr_async(struct obd_export *exp,
3031 struct md_enqueue_info *minfo)
3033 struct md_op_data *op_data = &minfo->mi_data;
3034 struct obd_device *obd = exp->exp_obd;
3035 struct lmv_obd *lmv = &obd->u.lmv;
3036 struct lmv_tgt_desc *tgt = NULL;
3040 if (!fid_is_sane(&op_data->op_fid2))
3043 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
3045 RETURN(PTR_ERR(tgt));
3048 * no special handle for remote dir, which needs to fetch both LOOKUP
3049 * lock on parent, and then UPDATE lock on child MDT, which makes all
3050 * complicated because this is done async. So only LOOKUP lock is
3051 * fetched for remote dir, but considering remote dir is rare case,
3052 * and not supporting it in statahead won't cause any issue, just leave
3056 rc = md_intent_getattr_async(tgt->ltd_exp, minfo);
3060 int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
3061 struct lu_fid *fid, __u64 *bits)
3063 struct obd_device *obd = exp->exp_obd;
3064 struct lmv_obd *lmv = &obd->u.lmv;
3065 struct lmv_tgt_desc *tgt;
3069 tgt = lmv_find_target(lmv, fid);
3071 RETURN(PTR_ERR(tgt));
3073 rc = md_revalidate_lock(tgt->ltd_exp, it, fid, bits);
3077 int lmv_get_fid_from_lsm(struct obd_export *exp,
3078 const struct lmv_stripe_md *lsm,
3079 const char *name, int namelen, struct lu_fid *fid)
3081 const struct lmv_oinfo *oinfo;
3083 LASSERT(lsm != NULL);
3084 oinfo = lsm_name_to_stripe_info(lsm, name, namelen);
3086 return PTR_ERR(oinfo);
3088 *fid = oinfo->lmo_fid;
3094 * For lmv, only need to send request to master MDT, and the master MDT will
3095 * process with other slave MDTs. The only exception is Q_GETOQUOTA for which
3096 * we directly fetch data from the slave MDTs.
3098 int lmv_quotactl(struct obd_device *unused, struct obd_export *exp,
3099 struct obd_quotactl *oqctl)
3101 struct obd_device *obd = class_exp2obd(exp);
3102 struct lmv_obd *lmv = &obd->u.lmv;
3103 struct lmv_tgt_desc *tgt = lmv->tgts[0];
3106 __u64 curspace, curinodes;
3110 tgt->ltd_exp == NULL ||
3112 lmv->desc.ld_tgt_count == 0) {
3113 CERROR("master lmv inactive\n");
3117 if (oqctl->qc_cmd != Q_GETOQUOTA) {
3118 rc = obd_quotactl(tgt->ltd_exp, oqctl);
3122 curspace = curinodes = 0;
3123 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
3127 if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active)
3130 err = obd_quotactl(tgt->ltd_exp, oqctl);
3132 CERROR("getquota on mdt %d failed. %d\n", i, err);
3136 curspace += oqctl->qc_dqblk.dqb_curspace;
3137 curinodes += oqctl->qc_dqblk.dqb_curinodes;
3140 oqctl->qc_dqblk.dqb_curspace = curspace;
3141 oqctl->qc_dqblk.dqb_curinodes = curinodes;
3146 static int lmv_merge_attr(struct obd_export *exp,
3147 const struct lmv_stripe_md *lsm,
3148 struct cl_attr *attr,
3149 ldlm_blocking_callback cb_blocking)
3154 rc = lmv_revalidate_slaves(exp, lsm, cb_blocking, 0);
3158 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
3159 struct inode *inode = lsm->lsm_md_oinfo[i].lmo_root;
3161 CDEBUG(D_INFO, ""DFID" size %llu, blocks %llu nlink %u,"
3162 " atime %lu ctime %lu, mtime %lu.\n",
3163 PFID(&lsm->lsm_md_oinfo[i].lmo_fid),
3164 i_size_read(inode), (unsigned long long)inode->i_blocks,
3165 inode->i_nlink, LTIME_S(inode->i_atime),
3166 LTIME_S(inode->i_ctime), LTIME_S(inode->i_mtime));
3168 /* for slave stripe, it needs to subtract nlink for . and .. */
3170 attr->cat_nlink += inode->i_nlink - 2;
3172 attr->cat_nlink = inode->i_nlink;
3174 attr->cat_size += i_size_read(inode);
3175 attr->cat_blocks += inode->i_blocks;
3177 if (attr->cat_atime < LTIME_S(inode->i_atime))
3178 attr->cat_atime = LTIME_S(inode->i_atime);
3180 if (attr->cat_ctime < LTIME_S(inode->i_ctime))
3181 attr->cat_ctime = LTIME_S(inode->i_ctime);
3183 if (attr->cat_mtime < LTIME_S(inode->i_mtime))
3184 attr->cat_mtime = LTIME_S(inode->i_mtime);
3189 struct obd_ops lmv_obd_ops = {
3190 .o_owner = THIS_MODULE,
3191 .o_setup = lmv_setup,
3192 .o_cleanup = lmv_cleanup,
3193 .o_precleanup = lmv_precleanup,
3194 .o_process_config = lmv_process_config,
3195 .o_connect = lmv_connect,
3196 .o_disconnect = lmv_disconnect,
3197 .o_statfs = lmv_statfs,
3198 .o_get_info = lmv_get_info,
3199 .o_set_info_async = lmv_set_info_async,
3200 .o_notify = lmv_notify,
3201 .o_get_uuid = lmv_get_uuid,
3202 .o_iocontrol = lmv_iocontrol,
3203 .o_quotactl = lmv_quotactl
3206 struct md_ops lmv_md_ops = {
3207 .m_get_root = lmv_get_root,
3208 .m_null_inode = lmv_null_inode,
3209 .m_close = lmv_close,
3210 .m_create = lmv_create,
3211 .m_enqueue = lmv_enqueue,
3212 .m_getattr = lmv_getattr,
3213 .m_getxattr = lmv_getxattr,
3214 .m_getattr_name = lmv_getattr_name,
3215 .m_intent_lock = lmv_intent_lock,
3217 .m_rename = lmv_rename,
3218 .m_setattr = lmv_setattr,
3219 .m_setxattr = lmv_setxattr,
3220 .m_fsync = lmv_fsync,
3221 .m_file_resync = lmv_file_resync,
3222 .m_read_page = lmv_read_page,
3223 .m_unlink = lmv_unlink,
3224 .m_init_ea_size = lmv_init_ea_size,
3225 .m_cancel_unused = lmv_cancel_unused,
3226 .m_set_lock_data = lmv_set_lock_data,
3227 .m_lock_match = lmv_lock_match,
3228 .m_get_lustre_md = lmv_get_lustre_md,
3229 .m_free_lustre_md = lmv_free_lustre_md,
3230 .m_merge_attr = lmv_merge_attr,
3231 .m_set_open_replay_data = lmv_set_open_replay_data,
3232 .m_clear_open_replay_data = lmv_clear_open_replay_data,
3233 .m_intent_getattr_async = lmv_intent_getattr_async,
3234 .m_revalidate_lock = lmv_revalidate_lock,
3235 .m_get_fid_from_lsm = lmv_get_fid_from_lsm,
3236 .m_unpackmd = lmv_unpackmd,
3239 static int __init lmv_init(void)
3241 return class_register_type(&lmv_obd_ops, &lmv_md_ops, true, NULL,
3242 LUSTRE_LMV_NAME, NULL);
3245 static void __exit lmv_exit(void)
3247 class_unregister_type(LUSTRE_LMV_NAME);
3250 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
3251 MODULE_DESCRIPTION("Lustre Logical Metadata Volume");
3252 MODULE_VERSION(LUSTRE_VERSION_STRING);
3253 MODULE_LICENSE("GPL");
3255 module_init(lmv_init);
3256 module_exit(lmv_exit);